Add qemu 2.4.0
[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 sizeof(type_l):    _MOVE(s, d, size, type_l); break; \
59                 case sizeof(type_w):    _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 sizeof(type_l):    _RMOVE(s, d, size, type_l); break; \
82                 case sizeof(type_w):    _RMOVE(s, d, size, type_w); break; \
83                 default:                _RMOVE(s, d, size, type_c); break; \
84         }
85
86 #endif