async net init (dhewg)
[libogc.git] / libogc / cache.c
blobaa84a9d0e8d04e7aad5af65b074494485e4771f6
1 /*-------------------------------------------------------------
3 cache.c -- Cache interface
5 Copyright (C) 2004
6 Michael Wiedenbauer (shagkur)
7 Dave Murphy (WinterMute)
9 This software is provided 'as-is', without any express or implied
10 warranty. In no event will the authors be held liable for any
11 damages arising from the use of this software.
13 Permission is granted to anyone to use this software for any
14 purpose, including commercial applications, and to alter it and
15 redistribute it freely, subject to the following restrictions:
17 1. The origin of this software must not be misrepresented; you
18 must not claim that you wrote the original software. If you use
19 this software in a product, an acknowledgment in the product
20 documentation would be appreciated but is not required.
22 2. Altered source versions must be plainly marked as such, and
23 must not be misrepresented as being the original software.
25 3. This notice may not be removed or altered from any source
26 distribution.
28 -------------------------------------------------------------*/
31 #include <asm.h>
32 #include <processor.h>
33 #include "cache.h"
35 #define _SHIFTL(v, s, w) \
36 ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s)))
37 #define _SHIFTR(v, s, w) \
38 ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1)))
40 extern void __LCEnable();
42 void LCEnable()
44 u32 level;
46 _CPU_ISR_Disable(level);
47 __LCEnable();
48 _CPU_ISR_Restore(level);
51 u32 LCLoadData(void *dstAddr,void *srcAddr,u32 nCount)
53 u32 cnt,blocks;
55 if((s32)nCount<=0) return 0;
57 cnt = (nCount+31)>>5;
58 blocks = (cnt+127)>>7;
59 while(cnt) {
60 if(cnt<0x80) {
61 LCLoadBlocks(dstAddr,srcAddr,cnt);
62 cnt = 0;
63 break;
65 LCLoadBlocks(dstAddr,srcAddr,0);
66 cnt -= 128;
67 dstAddr += 4096;
68 srcAddr += 4096;
70 return blocks;
73 u32 LCStoreData(void *dstAddr,void *srcAddr,u32 nCount)
75 u32 cnt,blocks;
77 if((s32)nCount<=0) return 0;
79 cnt = (nCount+31)>>5;
80 blocks = (cnt+127)>>7;
81 while(cnt) {
82 if(cnt<0x80) {
83 LCStoreBlocks(dstAddr,srcAddr,cnt);
84 cnt = 0;
85 break;
87 LCStoreBlocks(dstAddr,srcAddr,0);
88 cnt -= 128;
89 dstAddr += 4096;
90 srcAddr += 4096;
92 return blocks;
95 u32 LCQueueLength()
97 u32 hid2 = mfspr(920);
98 return _SHIFTR(hid2,4,4);
101 u32 LCQueueWait(u32 len)
103 len++;
104 while(_SHIFTR(mfspr(920),4,4)>=len);
105 return len;
108 void LCFlushQueue()
110 mtspr(922,0);
111 mtspr(923,1);
112 ppcsync();
115 void LCAlloc(void *addr,u32 bytes)
117 u32 level,cnt,hid2;
119 cnt = bytes>>5;
120 hid2 = mfspr(920);
121 if(!(hid2&0x10000000)) {
122 _CPU_ISR_Disable(level);
123 __LCEnable();
124 _CPU_ISR_Restore(level);
126 LCAllocTags(TRUE,addr,cnt);
129 void LCAllocNoInvalidate(void *addr,u32 bytes)
131 u32 level,cnt,hid2;
133 cnt = bytes>>5;
134 hid2 = mfspr(920);
135 if(!(hid2&0x10000000)) {
136 _CPU_ISR_Disable(level);
137 __LCEnable();
138 _CPU_ISR_Restore(level);
140 LCAllocTags(FALSE,addr,cnt);