Software APIs
abs_mmio.h
Go to the documentation of this file.
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_BASE_ABS_MMIO_H_
6 #define OPENTITAN_SW_DEVICE_LIB_BASE_ABS_MMIO_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /**
18  * @file
19  * @brief Absolute Memory-mapped IO functions, for volatile access.
20  *
21  * Memory-mapped IO functions, which map to volatile accesses. Use this module
22  * for register operations in ROM and ROM Extension production libraries.
23  *
24  * Compiling translation units that pull in this header with `-DMOCK_ABS_MMIO`
25  * will disable the definitions of `abs_mmio_read` and `abs_mmio_write`. These
26  * symbols can then be defined by a test harness to allow for instrumentation of
27  * MMIO accesses.
28  */
29 
30 #ifdef OT_PLATFORM_RV32
31 
32 /**
33  * Reads uint8_t from MMIO `addr`.
34  *
35  * @param addr the address to read from.
36  * @return the read value.
37  */
39 inline uint8_t abs_mmio_read8(uint32_t addr) {
40  return *((volatile uint8_t *)addr);
41 }
42 
43 /**
44  * Writes uint8_t to the MMIO `addr`.
45  *
46  * @param addr the address to write to.
47  * @param value the value to write.
48  */
49 inline void abs_mmio_write8(uint32_t addr, uint8_t value) {
50  *((volatile uint8_t *)addr) = value;
51 }
52 
53 /**
54  * Writes uint8_t to the MMIO `addr` via
55  * two subsequent write operations.
56  *
57  * @param addr the address to write to.
58  * @param value the value to write.
59  */
60 inline void abs_mmio_write8_shadowed(uint32_t addr, uint8_t value) {
61  *((volatile uint8_t *)addr) = value;
62  *((volatile uint8_t *)addr) = value;
63 }
64 
65 /**
66  * Reads an aligned uint32_t from MMIO `addr`.
67  *
68  * @param addr the address to read from.
69  * @return the read value.
70  */
72 inline uint32_t abs_mmio_read32(uint32_t addr) {
73  return *((volatile uint32_t *)addr);
74 }
75 
76 /**
77  * Writes an aligned uint32_t to the MMIO `addr`.
78  *
79  * @param addr the address to write to.
80  * @param value the value to write.
81  */
82 inline void abs_mmio_write32(uint32_t addr, uint32_t value) {
83  *((volatile uint32_t *)addr) = value;
84 }
85 
86 /**
87  * Writes an aligned uint32_t to the MMIO `addr` via
88  * two subsequent write operations.
89  *
90  * @param addr the address to write to.
91  * @param value the value to write.
92  */
93 inline void abs_mmio_write32_shadowed(uint32_t addr, uint32_t value) {
94  *((volatile uint32_t *)addr) = value;
95  *((volatile uint32_t *)addr) = value;
96 }
97 
98 #else // OT_PLATFORM_RV32
99 
100 extern uint8_t abs_mmio_read8(uint32_t addr);
101 extern void abs_mmio_write8(uint32_t addr, uint8_t value);
102 extern void abs_mmio_write8_shadowed(uint32_t addr, uint8_t value);
103 extern uint32_t abs_mmio_read32(uint32_t addr);
104 extern void abs_mmio_write32(uint32_t addr, uint32_t value);
105 extern void abs_mmio_write32_shadowed(uint32_t addr, uint32_t value);
106 
107 #endif // OT_PLATFORM_RV32
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif // OPENTITAN_SW_DEVICE_LIB_BASE_ABS_MMIO_H_