1cba4b180SAneesh VDisabling I-cache: 2cba4b180SAneesh V- Set CONFIG_SYS_ICACHE_OFF 3cba4b180SAneesh V 4cba4b180SAneesh VDisabling D-cache: 5cba4b180SAneesh V- Set CONFIG_SYS_DCACHE_OFF 6cba4b180SAneesh V 7cba4b180SAneesh VEnabling I-cache: 8cba4b180SAneesh V- Make sure CONFIG_SYS_ICACHE_OFF is not set and call icache_enable(). 9cba4b180SAneesh V 10cba4b180SAneesh VEnabling D-cache: 11cba4b180SAneesh V- Make sure CONFIG_SYS_DCACHE_OFF is not set and call dcache_enable(). 12cba4b180SAneesh V 13cba4b180SAneesh VEnabling Caches at System Startup: 14cba4b180SAneesh V- Implement enable_caches() for your platform and enable the I-cache and 15cba4b180SAneesh V D-cache from this function. This function is called immediately 16cba4b180SAneesh V after relocation. 17cba4b180SAneesh V 18cba4b180SAneesh VGuidelines for Working with D-cache: 19cba4b180SAneesh V 20cba4b180SAneesh VMemory to Peripheral DMA: 21cba4b180SAneesh V- Flush the buffer after the MPU writes the data and before the DMA is 22cba4b180SAneesh V initiated. 23cba4b180SAneesh V 24cba4b180SAneesh VPeripheral to Memory DMA: 25cba4b180SAneesh V- Invalidate the buffer before starting the DMA. In case there are any dirty 26cba4b180SAneesh V lines from the DMA buffer in the cache, subsequent cache-line replacements 27cba4b180SAneesh V may corrupt the buffer in memory while the DMA is still going on. Cache-line 28cba4b180SAneesh V replacement can happen if the CPU tries to bring some other memory locations 29cba4b180SAneesh V into the cache while the DMA is going on. 30cba4b180SAneesh V- Invalidate the buffer after the DMA is complete and before the MPU reads 31cba4b180SAneesh V it. This may be needed in addition to the invalidation before the DMA 32cba4b180SAneesh V mentioned above, because in some processors memory contents can spontaneously 33cba4b180SAneesh V come to the cache due to speculative memory access by the CPU. If this 34cba4b180SAneesh V happens with the DMA buffer while DMA is going on we have a coherency problem. 35cba4b180SAneesh V 36cba4b180SAneesh VBuffer Requirements: 37cba4b180SAneesh V- Any buffer that is invalidated(that is, typically the peripheral to 38cba4b180SAneesh V memory DMA buffer) should be aligned to cache-line boundary both at 39cba4b180SAneesh V at the beginning and at the end of the buffer. 40cba4b180SAneesh V- If the buffer is not cache-line aligned invalidation will be restricted 41cba4b180SAneesh V to the aligned part. That is, one cache-line at the respective boundary 42cba4b180SAneesh V may be left out while doing invalidation. 4346a6d51cSAnton staaf- A suitable buffer can be alloced on the stack using the 4446a6d51cSAnton staaf ALLOC_CACHE_ALIGN_BUFFER macro. 45cba4b180SAneesh V 46cba4b180SAneesh VCleanup Before Linux: 47cba4b180SAneesh V- cleanup_before_linux() should flush the D-cache, invalidate I-cache, and 48cba4b180SAneesh V disable MMU and caches. 49cba4b180SAneesh V- The following sequence is advisable while disabling d-cache: 50*421044b1SMichal Simek 1. dcache_disable() - flushes and disables d-cache 51cba4b180SAneesh V 2. invalidate_dcache_all() - invalid any entry that came to the cache 52cba4b180SAneesh V in the short period after the cache was flushed but before the 53cba4b180SAneesh V cache got disabled. 54