mmio.h 1.5 KB

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