blob: 880d2c51284e91d2cd1d626b44ca120c1151e8d7 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
7#ifndef __MMIO_H__
8#define __MMIO_H__
9
Achin Gupta4f6ad662013-10-25 09:08:21 +010010#include <stdint.h>
11
Andrew Thoelkeaf9dd822014-06-24 14:18:35 +010012static inline void mmio_write_8(uintptr_t addr, uint8_t value)
13{
14 *(volatile uint8_t*)addr = value;
15}
Harry Liebelafd1ec72014-04-01 19:19:22 +010016
Andrew Thoelkeaf9dd822014-06-24 14:18:35 +010017static inline uint8_t mmio_read_8(uintptr_t addr)
18{
19 return *(volatile uint8_t*)addr;
20}
21
developera310c4f2015-07-31 13:48:22 +080022static inline void mmio_write_16(uintptr_t addr, uint16_t value)
23{
24 *(volatile uint16_t*)addr = value;
25}
26
27static inline uint16_t mmio_read_16(uintptr_t addr)
28{
29 return *(volatile uint16_t*)addr;
30}
31
Andrew Thoelkeaf9dd822014-06-24 14:18:35 +010032static inline void mmio_write_32(uintptr_t addr, uint32_t value)
33{
34 *(volatile uint32_t*)addr = value;
35}
36
37static inline uint32_t mmio_read_32(uintptr_t addr)
38{
39 return *(volatile uint32_t*)addr;
40}
41
42static inline void mmio_write_64(uintptr_t addr, uint64_t value)
43{
44 *(volatile uint64_t*)addr = value;
45}
Achin Gupta4f6ad662013-10-25 09:08:21 +010046
Andrew Thoelkeaf9dd822014-06-24 14:18:35 +010047static inline uint64_t mmio_read_64(uintptr_t addr)
48{
49 return *(volatile uint64_t*)addr;
50}
Harry Liebeleaec5902013-12-12 13:00:29 +000051
developera310c4f2015-07-31 13:48:22 +080052static inline void mmio_clrbits_32(uintptr_t addr, uint32_t clear)
53{
54 mmio_write_32(addr, mmio_read_32(addr) & ~clear);
55}
56
57static inline void mmio_setbits_32(uintptr_t addr, uint32_t set)
58{
59 mmio_write_32(addr, mmio_read_32(addr) | set);
60}
61
62static inline void mmio_clrsetbits_32(uintptr_t addr,
63 uint32_t clear,
64 uint32_t set)
65{
66 mmio_write_32(addr, (mmio_read_32(addr) & ~clear) | set);
67}
68
Achin Gupta4f6ad662013-10-25 09:08:21 +010069#endif /* __MMIO_H__ */