OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [include/] [asm-m68knommu/] [io_hw_swap.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
#ifndef _M68K_IO_HW_SWAP_H
2
#define _M68K_IO_HW_SWAP_H
3
 
4
/*
5
 * swap functions are sometimes needed to interface little-endian hardware
6
 */
7
static inline unsigned short _swapw(volatile unsigned short v)
8
{
9
    return ((v << 8) | (v >> 8));
10
}
11
 
12
static inline unsigned int _swapl(volatile unsigned long v)
13
{
14
    return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
15
}
16
 
17
/*
18
 * readX/writeX() are used to access memory mapped devices. On some
19
 * architectures the memory mapped IO stuff needs to be accessed
20
 * differently. On the m68k architecture, we just read/write the
21
 * memory location directly.
22
 */
23
/* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
24
 * two accesses to memory, which may be undesireable for some devices.
25
 */
26
#define readb(addr) \
27
    ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
28
#define readw(addr) \
29
    ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
30
#define readl(addr) \
31
    ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
32
 
33
#define writeb(b,addr) ((*(volatile unsigned char *) (addr)) = (b))
34
#define writew(b,addr) ((*(volatile unsigned short *) (addr)) = (b))
35
#define writel(b,addr) ((*(volatile unsigned int *) (addr)) = (b))
36
 
37
/* There is no difference between I/O and memory on 68k, these are the same */
38
#define inb(addr) \
39
    ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
40
#define inw(addr) \
41
    ({ unsigned short __v = (*(volatile unsigned short *) (addr)); \
42
       _swapw(__v); })
43
#define inl(addr) \
44
    ({ unsigned int __v = (*(volatile unsigned int *) (addr)); _swapl(__v); })
45
 
46
#define outb(b,addr) ((*(volatile unsigned char *) (addr)) = (b))
47
#define outw(b,addr) ((*(volatile unsigned short *) (addr)) = (_swapw(b)))
48
#define outl(b,addr) ((*(volatile unsigned int *) (addr)) = (_swapl(b)))
49
 
50
/* FIXME: these need to be optimized.  Watch out for byte swapping, they
51
 * are used mostly for Intel devices... */
52
#define outsw(addr,buf,len) \
53
    ({ unsigned short * __e = (unsigned short *)(buf) + (len); \
54
       unsigned short * __p = (unsigned short *)(buf); \
55
       while (__p < __e) { \
56
          *(volatile unsigned short *)(addr) = *__p++;\
57
       } \
58
     })
59
 
60
#define insw(addr,buf,len) \
61
    ({ unsigned short * __e = (unsigned short *)(buf) + (len); \
62
       unsigned short * __p = (unsigned short *)(buf); \
63
       while (__p < __e) { \
64
          *(__p++) = *(volatile unsigned short *)(addr); \
65
       } \
66
     })
67
 
68
 
69
static inline unsigned char get_user_byte_io(const char * addr)
70
{
71
        register unsigned char _v;
72
 
73
        __asm__ __volatile__ ("moveb %1,%0":"=dm" (_v):"m" (*addr));
74
        return _v;
75
}
76
#define inb_p(addr) get_user_byte_io((char *)(addr))
77
 
78
static inline void put_user_byte_io(char val,char *addr)
79
{
80
        __asm__ __volatile__ ("moveb %0,%1"
81
                              : /* no outputs */
82
                              :"idm" (val),"m" (*addr)
83
                              : "memory");
84
}
85
#define outb_p(x,addr) put_user_byte_io((x),(char *)(addr))
86
 
87
/*
88
 * Change virtual addresses to physical addresses and vv.
89
 * These are trivial on the 1:1 Linux/i386 mapping (but if we ever
90
 * make the kernel segment mapped at 0, we need to do translation
91
 * on the i386 as well)
92
 */
93
extern unsigned long mm_vtop(unsigned long addr);
94
extern unsigned long mm_ptov(unsigned long addr);
95
 
96
extern inline unsigned long virt_to_phys(volatile void * address)
97
{
98
        return (unsigned long) mm_vtop((unsigned long)address);
99
}
100
 
101
extern inline void * phys_to_virt(unsigned long address)
102
{
103
        return (void *) mm_ptov(address);
104
}
105
 
106
/*
107
 * IO bus memory addresses are also 1:1 with the physical address
108
 */
109
#define virt_to_bus virt_to_phys
110
#define bus_to_virt phys_to_virt
111
 
112
 
113
#endif /* _M68K_IO_HW_SWAP_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.