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