These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / SLOF / include / ppc970 / cache.h
1 /******************************************************************************
2  * Copyright (c) 2004, 2008 IBM Corporation
3  * All rights reserved.
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
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12
13 #ifndef __CACHE_H
14 #define __CACHE_H
15
16 #include <cpu.h>
17 #include <stdint.h>
18
19 #define cache_inhibited_access(type,name)                       \
20         static inline type ci_read_##name(type * addr)          \
21         {                                                       \
22                 type val;                                       \
23                 set_ci();                                       \
24                 val = *addr;                                    \
25                 clr_ci();                                       \
26                 return val;                                     \
27         }                                                       \
28         static inline void ci_write_##name(type * addr, type data)      \
29         {                                                       \
30                 set_ci();                                       \
31                 *addr = data;                                   \
32                 clr_ci();                                       \
33         }
34
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)
39
40 #define _FWOVERLAP(s, d, size) ((d >= s) && ((type_u)d < ((type_u)s + size)))
41
42 // 3.1
43 #define _FWMOVE(s, d, size, t)  \
44         { t *s1=(t *)s, *d1=(t *)d; \
45                 while (size > 0) { *d1++ = *s1++; size -= sizeof(t); } }
46
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); } \
50 }
51
52
53 #define _MOVE(s, d, size, t) if _FWOVERLAP(s, d, size) _BWMOVE(s, d, size, t) else  _FWMOVE(s, d, size, t)
54
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; \
61         }
62
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); } \
67                 CLR_CI; \
68 }
69
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); } \
73                 CLR_CI; \
74 }
75
76 #define _RMOVE(s, d, size, t) if _FWOVERLAP(s, d, size) _BWRMOVE(s, d, size, t) else  _FWRMOVE(s, d, size, t)
77
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; \
84         }
85
86 /* main RAM to IO memory move */
87 #define FAST_MRMOVE_TYPED(s, d, size, t)        \
88 { \
89         t *s1 = (s), *d1 = (d); \
90         register t tmp; \
91         while (size > 0) { \
92                 tmp = *s1++; SET_CI; *d1++ = tmp; CLR_CI; size -= sizeof(t); \
93         } \
94 }
95
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; \
102         }
103
104 /* fill IO memory with pattern */
105 #define FAST_RFILL_TYPED(dst, size, pat, t) \
106 { \
107         t *d1 = (dst); \
108         register t tmp = 0; \
109         int i = sizeof(t); \
110         while (i-- > 0) { \
111                 tmp <<= 8; tmp |= pat & 0xff; \
112         } \
113         SET_CI; \
114         while (size > 0) { \
115                 *d1++ = tmp; size -= sizeof(t); \
116         } \
117         CLR_CI; \
118 }
119
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; \
126         }
127
128 #endif