1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2013-2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef MMIO_H
9 #define MMIO_H
10 
11 #include <stdint.h>
12 
mmio_write_8(uintptr_t addr,uint8_t value)13 static inline void mmio_write_8(uintptr_t addr, uint8_t value)
14 {
15     *(volatile uint8_t *)addr = value;
16 }
17 
mmio_read_8(uintptr_t addr)18 static inline uint8_t mmio_read_8(uintptr_t addr)
19 {
20     return *(volatile uint8_t *)addr;
21 }
22 
mmio_write_16(uintptr_t addr,uint16_t value)23 static inline void mmio_write_16(uintptr_t addr, uint16_t value)
24 {
25     *(volatile uint16_t *)addr = value;
26 }
27 
mmio_read_16(uintptr_t addr)28 static inline uint16_t mmio_read_16(uintptr_t addr)
29 {
30     return *(volatile uint16_t *)addr;
31 }
32 
mmio_clrsetbits_16(uintptr_t addr,uint16_t clear,uint16_t set)33 static inline void mmio_clrsetbits_16(
34     uintptr_t addr,
35     uint16_t clear,
36     uint16_t set)
37 {
38     mmio_write_16(addr, (mmio_read_16(addr) & ~clear) | set);
39 }
40 
mmio_write_32(uintptr_t addr,uint32_t value)41 static inline void mmio_write_32(uintptr_t addr, uint32_t value)
42 {
43     *(volatile uint32_t *)addr = value;
44 }
45 
mmio_read_32(uintptr_t addr)46 static inline uint32_t mmio_read_32(uintptr_t addr)
47 {
48     return *(volatile uint32_t *)addr;
49 }
50 
mmio_write_64(uintptr_t addr,uint64_t value)51 static inline void mmio_write_64(uintptr_t addr, uint64_t value)
52 {
53     *(volatile uint64_t *)addr = value;
54 }
55 
mmio_read_64(uintptr_t addr)56 static inline uint64_t mmio_read_64(uintptr_t addr)
57 {
58     return *(volatile uint64_t *)addr;
59 }
60 
mmio_clrbits_32(uintptr_t addr,uint32_t clear)61 static inline void mmio_clrbits_32(uintptr_t addr, uint32_t clear)
62 {
63     mmio_write_32(addr, mmio_read_32(addr) & ~clear);
64 }
65 
mmio_setbits_32(uintptr_t addr,uint32_t set)66 static inline void mmio_setbits_32(uintptr_t addr, uint32_t set)
67 {
68     mmio_write_32(addr, mmio_read_32(addr) | set);
69 }
70 
mmio_clrsetbits_32(uintptr_t addr,uint32_t clear,uint32_t set)71 static inline void mmio_clrsetbits_32(
72     uintptr_t addr,
73     uint32_t clear,
74     uint32_t set)
75 {
76     mmio_write_32(addr, (mmio_read_32(addr) & ~clear) | set);
77 }
78 
79 #endif /* MMIO_H */
80