Benjamin Walsh | 334c14e | 2015-09-18 16:36:57 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Wind River Systems, Inc. |
| 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 | #ifndef _cache__h_ |
| 18 | #define _cache__h_ |
| 19 | |
Anas Nashif | ea8c6aad | 2016-12-23 07:32:56 -0500 | [diff] [blame^] | 20 | #include <kernel.h> |
Benjamin Walsh | 334c14e | 2015-09-18 16:36:57 -0400 | [diff] [blame] | 21 | |
Peter Mitsis | a0e4568 | 2016-01-22 12:38:49 -0500 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Benjamin Walsh | 334c14e | 2015-09-18 16:36:57 -0400 | [diff] [blame] | 26 | #define _sys_cache_flush_sig(x) void (x)(vaddr_t virt, size_t size) |
| 27 | |
Benjamin Walsh | 7b526e2 | 2015-10-30 17:04:00 -0400 | [diff] [blame] | 28 | #if defined(CONFIG_CACHE_FLUSHING) |
| 29 | |
Benjamin Walsh | 334c14e | 2015-09-18 16:36:57 -0400 | [diff] [blame] | 30 | #if defined(CONFIG_ARCH_CACHE_FLUSH_DETECT) |
| 31 | typedef _sys_cache_flush_sig(_sys_cache_flush_t); |
| 32 | extern _sys_cache_flush_t *sys_cache_flush; |
| 33 | #else |
| 34 | extern _sys_cache_flush_sig(sys_cache_flush); |
| 35 | #endif |
Benjamin Walsh | 7b526e2 | 2015-10-30 17:04:00 -0400 | [diff] [blame] | 36 | |
| 37 | #else |
| 38 | |
| 39 | /* |
| 40 | * Provide NOP APIs for systems that do not have caches. |
| 41 | * |
| 42 | * An example is the Cortex-M chips. However, the functions are provided so |
| 43 | * that code that need to manipulate caches can be written in an |
| 44 | * architecture-agnostic manner. The functions do nothing. The cache line size |
| 45 | * value is always 0. |
| 46 | */ |
| 47 | |
| 48 | static inline _sys_cache_flush_sig(sys_cache_flush) |
| 49 | { |
| 50 | ARG_UNUSED(virt); |
| 51 | ARG_UNUSED(size); |
| 52 | |
| 53 | /* do nothing */ |
| 54 | } |
| 55 | |
Benjamin Walsh | 334c14e | 2015-09-18 16:36:57 -0400 | [diff] [blame] | 56 | #endif /* CACHE_FLUSHING */ |
| 57 | |
| 58 | #if defined(CONFIG_CACHE_LINE_SIZE_DETECT) |
| 59 | extern size_t sys_cache_line_size; |
Benjamin Walsh | 7b526e2 | 2015-10-30 17:04:00 -0400 | [diff] [blame] | 60 | #elif defined(CONFIG_CACHE_LINE_SIZE) |
Benjamin Walsh | 334c14e | 2015-09-18 16:36:57 -0400 | [diff] [blame] | 61 | #define sys_cache_line_size CONFIG_CACHE_LINE_SIZE |
Benjamin Walsh | 7b526e2 | 2015-10-30 17:04:00 -0400 | [diff] [blame] | 62 | #else |
| 63 | #define sys_cache_line_size 0 |
Benjamin Walsh | 334c14e | 2015-09-18 16:36:57 -0400 | [diff] [blame] | 64 | #endif |
| 65 | |
Peter Mitsis | a0e4568 | 2016-01-22 12:38:49 -0500 | [diff] [blame] | 66 | #ifdef __cplusplus |
| 67 | } |
| 68 | #endif |
| 69 | |
Benjamin Walsh | 334c14e | 2015-09-18 16:36:57 -0400 | [diff] [blame] | 70 | #endif /* _cache__h_ */ |