1 /******************************************************************************
2 * Copyright (c) 2004, 2008 IBM Corporation
4 * This program and the accompanying materials
5 * are made available under the terms of the BSD License
6 * which accompanies this distribution, and is available at
7 * http://www.opensource.org/licenses/bsd-license.php
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
19 #define cache_inhibited_access(type,name) \
20 static inline type ci_read_##name(type * addr) \
28 static inline void ci_write_##name(type * addr, type data) \
35 cache_inhibited_access(uint8_t, 8)
36 cache_inhibited_access(uint16_t, 16)
37 cache_inhibited_access(uint32_t, 32)
38 cache_inhibited_access(uint64_t, 64)
40 #define _FWOVERLAP(s, d, size) ((d >= s) && ((type_u)d < ((type_u)s + size)))
43 #define _FWMOVE(s, d, size, t) \
44 { t *s1=(t *)s, *d1=(t *)d; \
45 while (size > 0) { *d1++ = *s1++; size -= sizeof(t); } }
47 #define _BWMOVE(s, d, size, t) { \
48 t *s1=(t *)((char *)s+size), *d1=(t *)((char *)d+size); \
49 while (size > 0) { *--d1 = *--s1; size -= sizeof(t); } \
53 #define _MOVE(s, d, size, t) if _FWOVERLAP(s, d, size) _BWMOVE(s, d, size, t) else _FWMOVE(s, d, size, t)
55 #define _FASTMOVE(s, d, size) \
56 switch (((type_u)s | (type_u)d | size) & (sizeof(type_u)-1)) { \
57 case 0: _MOVE(s, d, size, type_u); break; \
58 case 4: _MOVE(s, d, size, type_l); break; \
59 case 2: case 6: _MOVE(s, d, size, type_w); break; \
60 default: _MOVE(s, d, size, type_c); break; \
63 // Device IO block data helpers
64 #define _FWRMOVE(s, d, size, t) \
65 { t *s1=(t *)s, *d1=(t *)d; SET_CI; \
66 while (size > 0) { *d1++ = *s1++; size -= sizeof(t); } \
70 #define _BWRMOVE(s, d, size, t) { \
71 t *s1=(t *)((char *)s+size), *d1=(t *)((char *)d+size); SET_CI; \
72 while (size > 0) { *--d1 = *--s1; size -= sizeof(t); } \
76 #define _RMOVE(s, d, size, t) if _FWOVERLAP(s, d, size) _BWRMOVE(s, d, size, t) else _FWRMOVE(s, d, size, t)
78 #define _FASTRMOVE(s, d, size) \
79 switch (((type_u)s | (type_u)d | size) & (sizeof(type_u)-1)) { \
80 case 0: _RMOVE(s, d, size, type_u); break; \
81 case 4: _RMOVE(s, d, size, type_l); break; \
82 case 2: case 6: _RMOVE(s, d, size, type_w); break; \
83 default: _RMOVE(s, d, size, type_c); break; \
86 /* main RAM to IO memory move */
87 #define FAST_MRMOVE_TYPED(s, d, size, t) \
89 t *s1 = (s), *d1 = (d); \
92 tmp = *s1++; SET_CI; *d1++ = tmp; CLR_CI; size -= sizeof(t); \
96 #define FAST_MRMOVE(s, d, size) \
97 switch (((type_u)(s) | (type_u)(d) | (size)) & (sizeof(type_u)-1)) { \
98 case 0: FAST_MRMOVE_TYPED(s, d, size, type_u); break; \
99 case 4: FAST_MRMOVE_TYPED(s, d, size, type_l); break; \
100 case 2: case 6: FAST_MRMOVE_TYPED(s, d, size, type_w); break; \
101 default: FAST_MRMOVE_TYPED(s, d, size, type_c); break; \
104 /* fill IO memory with pattern */
105 #define FAST_RFILL_TYPED(dst, size, pat, t) \
108 register t tmp = 0; \
111 tmp <<= 8; tmp |= pat & 0xff; \
115 *d1++ = tmp; size -= sizeof(t); \
120 #define FAST_RFILL(dst, size, pat) \
121 switch (((type_u)dst | size) & (sizeof(type_u)-1)) { \
122 case 0: FAST_RFILL_TYPED(dst, size, pat, type_u); break; \
123 case 4: FAST_RFILL_TYPED(dst, size, pat, type_l); break; \
124 case 2: case 6: FAST_RFILL_TYPED(dst, size, pat, type_w); break; \
125 default: FAST_RFILL_TYPED(dst, size, pat, type_c); break; \