xref: /aosp_15_r20/system/chre/platform/tinysys/platform_cache_management.cc (revision 84e339476a462649f82315436d70fd732297a399)
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "FreeRTOS.h"
18 
19 #include "chre/platform/shared/nanoapp_loader.h"
20 #include "chre/platform/shared/platform_cache_management.h"
21 
22 #include "dma_api.h"
23 
24 namespace chre {
25 
wipeSystemCaches(uintptr_t address,uint32_t span)26 void wipeSystemCaches(uintptr_t address, uint32_t span) {
27   if (span == 0) return;
28 
29   auto aligned_addr = NanoappLoader::roundDownToAlign(address, CACHE_LINE_SIZE);
30   auto aligned_span = (span + CACHE_LINE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1);
31   LOGV("Invalidate cache at 0x%lx for %u", aligned_addr, aligned_span);
32 
33   // Flush D cache first for updating binary to heap memory
34   mrv_dcache_flush_multi_addr(aligned_addr, aligned_span);
35   // Invalid I cache for fetch instructions
36   mrv_icache_invalid_multi_addr(aligned_addr, aligned_span);
37 }
38 
39 }  // namespace chre