1 /*-------------------------------------------------------------
4 cache.h -- Cache interface
7 Michael Wiedenbauer (shagkur)
8 Dave Murphy (WinterMute)
10 This software is provided 'as-is', without any express or implied
11 warranty. In no event will the authors be held liable for any
12 damages arising from the use of this software.
14 Permission is granted to anyone to use this software for any
15 purpose, including commercial applications, and to alter it and
16 redistribute it freely, subject to the following restrictions:
18 1. The origin of this software must not be misrepresented; you
19 must not claim that you wrote the original software. If you use
20 this software in a product, an acknowledgment in the product
21 documentation would be appreciated but is not required.
23 2. Altered source versions must be plainly marked as such, and
24 must not be misrepresented as being the original software.
26 3. This notice may not be removed or altered from any source
30 -------------------------------------------------------------*/
37 \brief Cache subsystem
43 #define LC_BASEPREFIX 0xe000
44 #define LC_BASE (LC_BASEPREFIX<<16)
48 #endif /* __cplusplus */
53 * \brief Enable L1 d-cache
61 * \fn void DCDisable()
62 * \brief Disable L1 d-cache
71 * \brief Current contents of the L1 d-cache are locked down and will not be cast out.
73 * Hits are still serviced, but misses go straight to L2 or 60x bus. Most cache operations, such as DCFlushRange(), will still execute regardless of whether the cache is frozen.<br>
74 * <b><i>NOTE:</i></b> In PowerPC architecture jargon, this feature is referred to as "locking" the data cache. We use the word "freeze" to distinguish it from the locked cache and DMA features.
82 * \fn void DCUnfreeze()
83 * \brief Undoes actions of DCFreeze().
85 * Old cache blocks will now be cast out on subsequent L1 misses.<br>
86 * <b><i>NOTE:</i></b> In PowerPC architecture jargon, this feature is referred to as "locking" the data cache. We use the word "freeze" to distinguish it from the locked cache and DMA features.
94 * \fn void DCFlashInvalidate()
95 * \brief Invalidate L1 d-cache.
97 * An invalidate operation is issued that marks the state of each data cache block as invalid without writing back modified cache blocks to memory.<br>
98 * Cache access is blocked during this time.Bus accesses to the cache are signaled as a miss during invalidate-all operations.
102 void DCFlashInvalidate();
106 * \fn void DCInvalidateRange(void *startaddress,u32 len)
107 * \brief Invalidates a given range of the d-cache.
109 * If any part of the range hits in the d-cache, the corresponding block will be invalidated.
111 * \param[in] startaddress pointer to the startaddress of the memory range to invalidate. <b><i>NOTE:</i></b> Has to be aligned on a 32byte boundery
112 * \param[in] len length of the range to invalidate. <b><i>NOTE:</i></b> Should be a multiple of 32
116 void DCInvalidateRange(void *startaddress
,u32 len
);
120 * \fn void DCFlushRange(void *startaddress,u32 len)
121 * \brief Flushes a given range.
123 * If any part of the range hits in the d-cache the corresponding block will be flushed to main memory and invalidated.<br>
124 * <b><i>NOTE:</i></b> This function invokes a "sync" after flushing the range. This means the function will stall until the CPU knows that the data has been writen to main memory
126 * \param[in] startaddress pointer to the startaddress of the memory range to flush. <b><i>NOTE:</i></b> Has to be aligned on a 32byte boundery
127 * \param[in] len length of range to be flushed. <b><i>NOTE:</i></b> Should be a multiple of 32
131 void DCFlushRange(void *startaddress
,u32 len
);
134 * \fn void DCStoreRange(void *startaddress,u32 len)
135 * \brief Ensures a range of memory is updated with any modified data in the cache.
137 * <b><i>NOTE:</i></b> This function invokes a "sync" after storing the range. This means the function will stall until the CPU knows that the data has been writen to main memory
139 * \param[in] startaddress pointer to the startaddress of the memory range to store. <b><i>NOTE:</i></b> Has to be aligned on a 32byte boundery
140 * \param[in] len length of the range to store. <b><i>NOTE:</i></b> Should be a multiple of 32
144 void DCStoreRange(void *startaddress
,u32 len
);
148 * \fn void DCFlushRangeNoSync(void *startaddress,u32 len)
149 * \brief Flushes a given range.
151 * If any part of the range hits in the d-cache the corresponding block will be flushed to main memory and invalidated.<br>
152 * <b><i>NOTE:</i></b> This routine does not perform a "sync" to ensure that the range has been flushed to memory. That is, the cache blocks are sent to the bus interface unit for storage to main memory, but by the time this function returns, you are not guaranteed that the blocks have been written to memory.
154 * \param[in] startaddress pointer to the startaddress of the memory range to flush. <b><i>NOTE:</i></b> Has to be aligned on a 32byte boundery
155 * \param[in] len length of range to be flushed. <b><i>NOTE:</i></b> Should be a multiple of 32
159 void DCFlushRangeNoSync(void *startaddress
,u32 len
);
163 * \fn void DCStoreRangeNoSync(void *startaddress,u32 len)
164 * \brief Ensures a range of memory is updated with any modified data in the cache.
166 * <b><i>NOTE:</i></b> This routine does not perform a "sync" to ensure that the range has been flushed to memory. That is, the cache blocks are sent to the bus interface unit for storage to main memory, but by the time this function returns, you are not guaranteed that the blocks have been written to memory
168 * \param[in] startaddress pointer to the startaddress of the memory range to store. <b><i>NOTE:</i></b> Has to be aligned on a 32byte boundery
169 * \param[in] len length of the range to store. <b><i>NOTE:</i></b> Should be a multiple of 32
173 void DCStoreRangeNoSync(void *startaddress
,u32 len
);
177 * \fn void DCZeroRange(void *startaddress,u32 len)
178 * \brief Loads a range of memory into cache and zeroes all the cache lines.
180 * \param[in] startaddress pointer to the startaddress of the memory range to load/zero. <b><i>NOTE:</i></b> Has to be aligned on a 32byte boundery
181 * \param[in] len length of the range to load/zero. <b><i>NOTE:</i></b> Should be a multiple of 32
185 void DCZeroRange(void *startaddress
,u32 len
);
189 * \fn void DCTouchRange(void *startaddress,u32 len)
190 * \brief Loads a range of memory into cache.
192 * \param[in] startaddress pointer to the startaddress of the memory range to load. <b><i>NOTE:</i></b> Has to be aligned on a 32byte boundery
193 * \param[in] len length of the range to load. <b><i>NOTE:</i></b> Should be a multiple of 32
197 void DCTouchRange(void *startaddress
,u32 len
);
202 * \brief Performs an instruction cache synchronization.
204 * This ensures that all instructions preceding this instruction have completed before this instruction completes.
212 * \fn void ICFlashInvalidate()
213 * \brief Invalidate the L1 i-cache.
215 * An invalidate operation is issued that marks the state of each instruction cache block as invalid without writing back modified cache blocks to memory.<br>
216 * Cache access is blocked during this time. Bus accesses to the cache are signaled as a miss during invalidate-all operations.
220 void ICFlashInvalidate();
224 * \fn void ICEnable()
225 * \brief Enable L1 i-cache
233 * \fn void ICDisable()
234 * \brief Disable L1 i-cache
242 * \fn void ICFreeze()
243 * \brief Current contents of the L1 i-cache are locked down and will not be cast out.
245 * Hits are still serviced, but misses go straight to L2 or 60x bus.<br>
246 * <b><i>NOTE:</i></b> In PowerPC architecture jargon, this feature is referred to as "locking" the data cache. We use the word "freeze" to distinguish it from the locked cache and DMA features.
254 * \fn void ICUnfreeze()
255 * \brief Undoes actions of ICFreeze().
257 * Old cache blocks will now be cast out on subsequent L1 misses.<br>
258 * <b><i>NOTE:</i></b> In PowerPC architecture jargon, this feature is referred to as "locking" the data cache. We use the word "freeze" to distinguish it from the locked cache and DMA features.
266 * \fn void ICBlockInvalidate(void *startaddress)
267 * \brief Invalidates a block in the i-cache.
269 * If the block hits in the i-cache, the corresponding block will be invalidated.
271 * \param[in] startaddress pointer to the startaddress of the memory block to invalidate. <b><i>NOTE:</i></b> Has to be aligned on a 32byte boundery
275 void ICBlockInvalidate(void *startaddress
);
279 * \fn void ICInvalidateRange(void *startaddress,u32 len)
280 * \brief Invalidate a range in the L1 i-cache.
282 * If any part of the range hits in the i-cache, the corresponding block will be invalidated.
284 * \param[in] startaddress pointer to the startaddress of the memory range to invalidate. <b><i>NOTE:</i></b> Has to be aligned on a 32byte boundery
285 * \param[in] len length of the range to invalidate. <b><i>NOTE:</i></b> Should be a multiple of 32
289 void ICInvalidateRange(void *startaddress
,u32 len
);
293 void LCLoadBlocks(void *,void *,u32
);
294 void LCStoreBlocks(void *,void *,u32
);
295 u32
LCLoadData(void *,void *,u32
);
296 u32
LCStoreData(void *,void *,u32
);
298 u32
LCQueueWait(u32
);
300 void LCAlloc(void *,u32
);
301 void LCAllocNoInvalidate(void *,u32
);
302 void LCAllocOneTag(BOOL
,void *);
303 void LCAllocTags(BOOL
,void *,u32
);
305 #define LCGetBase() ((void*)LC_BASE)
308 #endif /* __cplusplus */