Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __MMIO_H__ |
| 8 | #define __MMIO_H__ |
| 9 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 10 | #include <stdint.h> |
| 11 | |
Andrew Thoelke | af9dd82 | 2014-06-24 14:18:35 +0100 | [diff] [blame] | 12 | static inline void mmio_write_8(uintptr_t addr, uint8_t value) |
| 13 | { |
| 14 | *(volatile uint8_t*)addr = value; |
| 15 | } |
Harry Liebel | afd1ec7 | 2014-04-01 19:19:22 +0100 | [diff] [blame] | 16 | |
Andrew Thoelke | af9dd82 | 2014-06-24 14:18:35 +0100 | [diff] [blame] | 17 | static inline uint8_t mmio_read_8(uintptr_t addr) |
| 18 | { |
| 19 | return *(volatile uint8_t*)addr; |
| 20 | } |
| 21 | |
developer | a310c4f | 2015-07-31 13:48:22 +0800 | [diff] [blame] | 22 | static inline void mmio_write_16(uintptr_t addr, uint16_t value) |
| 23 | { |
| 24 | *(volatile uint16_t*)addr = value; |
| 25 | } |
| 26 | |
| 27 | static inline uint16_t mmio_read_16(uintptr_t addr) |
| 28 | { |
| 29 | return *(volatile uint16_t*)addr; |
| 30 | } |
| 31 | |
Konstantin Porotchkin | ff5e1e8 | 2018-10-07 17:42:56 +0300 | [diff] [blame] | 32 | static inline void mmio_clrsetbits_16(uintptr_t addr, |
| 33 | uint16_t clear, |
| 34 | uint16_t set) |
| 35 | { |
| 36 | mmio_write_16(addr, (mmio_read_16(addr) & ~clear) | set); |
| 37 | } |
| 38 | |
Andrew Thoelke | af9dd82 | 2014-06-24 14:18:35 +0100 | [diff] [blame] | 39 | static inline void mmio_write_32(uintptr_t addr, uint32_t value) |
| 40 | { |
| 41 | *(volatile uint32_t*)addr = value; |
| 42 | } |
| 43 | |
| 44 | static inline uint32_t mmio_read_32(uintptr_t addr) |
| 45 | { |
| 46 | return *(volatile uint32_t*)addr; |
| 47 | } |
| 48 | |
| 49 | static inline void mmio_write_64(uintptr_t addr, uint64_t value) |
| 50 | { |
| 51 | *(volatile uint64_t*)addr = value; |
| 52 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 53 | |
Andrew Thoelke | af9dd82 | 2014-06-24 14:18:35 +0100 | [diff] [blame] | 54 | static inline uint64_t mmio_read_64(uintptr_t addr) |
| 55 | { |
| 56 | return *(volatile uint64_t*)addr; |
| 57 | } |
Harry Liebel | eaec590 | 2013-12-12 13:00:29 +0000 | [diff] [blame] | 58 | |
developer | a310c4f | 2015-07-31 13:48:22 +0800 | [diff] [blame] | 59 | static inline void mmio_clrbits_32(uintptr_t addr, uint32_t clear) |
| 60 | { |
| 61 | mmio_write_32(addr, mmio_read_32(addr) & ~clear); |
| 62 | } |
| 63 | |
| 64 | static inline void mmio_setbits_32(uintptr_t addr, uint32_t set) |
| 65 | { |
| 66 | mmio_write_32(addr, mmio_read_32(addr) | set); |
| 67 | } |
| 68 | |
| 69 | static inline void mmio_clrsetbits_32(uintptr_t addr, |
| 70 | uint32_t clear, |
| 71 | uint32_t set) |
| 72 | { |
| 73 | mmio_write_32(addr, (mmio_read_32(addr) & ~clear) | set); |
| 74 | } |
| 75 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 76 | #endif /* __MMIO_H__ */ |