Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | /* * Copyright (c) 2015, Wind River Systems, Inc. * Copyright (c) 2017, Oticon A/S * * SPDX-License-Identifier: Apache-2.0 */ /* "Arch" bit manipulation functions in non-arch-specific C code (uses some * gcc builtins) */ #ifndef ZEPHYR_INCLUDE_ARCH_ARM64_SYS_IO_H_ #define ZEPHYR_INCLUDE_ARCH_ARM64_SYS_IO_H_ #ifndef _ASMLANGUAGE #include <zephyr/types.h> #include <sys/sys_io.h> #ifdef __cplusplus extern "C" { #endif /* Memory mapped registers I/O functions */ /* * We need to use explicit assembler instruction there, because with classic * "volatile pointer" approach compiler might generate instruction with * immediate value like * * str w4, [x1], #4 * * Such instructions produce invalid syndrome in HSR register, so hypervisor * can't emulate MMIO when it traps memory access. */ static ALWAYS_INLINE uint8_t sys_read8(mem_addr_t addr) { uint8_t val; __asm__ volatile("ldrb %w0, [%1]" : "=r" (val) : "r" (addr)); __DMB(); return val; } static ALWAYS_INLINE void sys_write8(uint8_t data, mem_addr_t addr) { __DMB(); __asm__ volatile("strb %w0, [%1]" : : "r" (data), "r" (addr)); } static ALWAYS_INLINE uint16_t sys_read16(mem_addr_t addr) { uint16_t val; __asm__ volatile("ldrh %w0, [%1]" : "=r" (val) : "r" (addr)); __DMB(); return val; } static ALWAYS_INLINE void sys_write16(uint16_t data, mem_addr_t addr) { __DMB(); __asm__ volatile("strh %w0, [%1]" : : "r" (data), "r" (addr)); } static ALWAYS_INLINE uint32_t sys_read32(mem_addr_t addr) { uint32_t val; __asm__ volatile("ldr %w0, [%1]" : "=r" (val) : "r" (addr)); __DMB(); return val; } static ALWAYS_INLINE void sys_write32(uint32_t data, mem_addr_t addr) { __DMB(); __asm__ volatile("str %w0, [%1]" : : "r" (data), "r" (addr)); } static ALWAYS_INLINE uint64_t sys_read64(mem_addr_t addr) { uint64_t val; __asm__ volatile("ldr %x0, [%1]" : "=r" (val) : "r" (addr)); __DMB(); return val; } static ALWAYS_INLINE void sys_write64(uint64_t data, mem_addr_t addr) { __DMB(); __asm__ volatile("str %x0, [%1]" : : "r" (data), "r" (addr)); } #ifdef __cplusplus } #endif #endif /* _ASMLANGUAGE */ #endif /* ZEPHYR_INCLUDE_ARCH_ARM64_SYS_IO_H_ */ |