6#ifndef ZEPHYR_INCLUDE_SYS_DEVICE_MMIO_H
7#define ZEPHYR_INCLUDE_SYS_DEVICE_MMIO_H
37#if defined(CONFIG_MMU) || defined(CONFIG_PCIE) || defined(CONFIG_EXTERNAL_ADDRESS_TRANSLATION)
38#define DEVICE_MMIO_IS_IN_RAM
41#if defined(CONFIG_EXTERNAL_ADDRESS_TRANSLATION)
51#ifdef DEVICE_MMIO_IS_IN_RAM
56struct z_device_mmio_rom {
64#define Z_DEVICE_MMIO_ROM_INITIALIZER(node_id) \
66 .phys_addr = DT_REG_ADDR(node_id), \
67 .size = DT_REG_SIZE(node_id) \
70#define Z_DEVICE_MMIO_NAMED_ROM_INITIALIZER(name, node_id) \
72 .phys_addr = DT_REG_ADDR_BY_NAME(node_id, name), \
73 .size = DT_REG_SIZE_BY_NAME(node_id, name) \
109#ifdef CONFIG_EXTERNAL_ADDRESS_TRANSLATION
112 *virt_addr = phys_addr;
120struct z_device_mmio_rom {
125#define Z_DEVICE_MMIO_ROM_INITIALIZER(node_id) \
127 .addr = (mm_reg_t)DT_REG_ADDR_U64(node_id) \
130#define Z_DEVICE_MMIO_NAMED_ROM_INITIALIZER(name, node_id) \
132 .addr = (mm_reg_t)DT_REG_ADDR_BY_NAME_U64(node_id, name) \
180#ifdef DEVICE_MMIO_IS_IN_RAM
181#define DEVICE_MMIO_RAM mm_reg_t _mmio
183#define DEVICE_MMIO_RAM
186#ifdef DEVICE_MMIO_IS_IN_RAM
197#define DEVICE_MMIO_RAM_PTR(device) (mm_reg_t *)((device)->data)
230#define DEVICE_MMIO_ROM struct z_device_mmio_rom _mmio
241#define DEVICE_MMIO_ROM_PTR(dev) \
242 ((struct z_device_mmio_rom *)((dev)->config))
266#define DEVICE_MMIO_ROM_INIT(node_id) \
267 ._mmio = Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
285#ifdef DEVICE_MMIO_IS_IN_RAM
286#define DEVICE_MMIO_MAP(dev, flags) \
287 device_map(DEVICE_MMIO_RAM_PTR(dev), \
288 DEVICE_MMIO_ROM_PTR(dev)->phys_addr, \
289 DEVICE_MMIO_ROM_PTR(dev)->size, \
292#define DEVICE_MMIO_MAP(dev, flags) do { } while (false)
314#ifdef DEVICE_MMIO_IS_IN_RAM
315#define DEVICE_MMIO_GET(dev) (*DEVICE_MMIO_RAM_PTR(dev))
317#define DEVICE_MMIO_GET(dev) (DEVICE_MMIO_ROM_PTR(dev)->addr)
365#ifdef DEVICE_MMIO_IS_IN_RAM
366#define DEVICE_MMIO_NAMED_RAM(name) mm_reg_t name
368#define DEVICE_MMIO_NAMED_RAM(name)
371#ifdef DEVICE_MMIO_IS_IN_RAM
382#define DEVICE_MMIO_NAMED_RAM_PTR(dev, name) \
383 (&(DEV_DATA(dev)->name))
421#define DEVICE_MMIO_NAMED_ROM(name) struct z_device_mmio_rom name
435#define DEVICE_MMIO_NAMED_ROM_PTR(dev, name) (&(DEV_CFG(dev)->name))
463#define DEVICE_MMIO_NAMED_ROM_INIT(name, node_id) \
464 .name = Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
504#define DEVICE_MMIO_NAMED_ROM_INIT_BY_NAME(name, node_id) \
505 .name = Z_DEVICE_MMIO_NAMED_ROM_INITIALIZER(name, node_id)
533#ifdef DEVICE_MMIO_IS_IN_RAM
534#define DEVICE_MMIO_NAMED_MAP(dev, name, flags) \
535 device_map(DEVICE_MMIO_NAMED_RAM_PTR((dev), name), \
536 (DEVICE_MMIO_NAMED_ROM_PTR((dev), name)->phys_addr), \
537 (DEVICE_MMIO_NAMED_ROM_PTR((dev), name)->size), \
540#define DEVICE_MMIO_NAMED_MAP(dev, name, flags) do { } while (false)
564#ifdef DEVICE_MMIO_IS_IN_RAM
565#define DEVICE_MMIO_NAMED_GET(dev, name) \
566 (*DEVICE_MMIO_NAMED_RAM_PTR((dev), name))
568#define DEVICE_MMIO_NAMED_GET(dev, name) \
569 ((DEVICE_MMIO_NAMED_ROM_PTR((dev), name))->addr)
591 #define Z_TOPLEVEL_ROM_NAME(name) _CONCAT(z_mmio_rom__, name)
592 #define Z_TOPLEVEL_RAM_NAME(name) _CONCAT(z_mmio_ram__, name)
609#ifdef DEVICE_MMIO_IS_IN_RAM
610#define DEVICE_MMIO_TOPLEVEL(name, node_id) \
612 mm_reg_t Z_TOPLEVEL_RAM_NAME(name); \
614 const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
615 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
617#define DEVICE_MMIO_TOPLEVEL(name, node_id) \
619 const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
620 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
637#ifdef DEVICE_MMIO_IS_IN_RAM
638#define DEVICE_MMIO_TOPLEVEL_DECLARE(name) \
639 extern mm_reg_t Z_TOPLEVEL_RAM_NAME(name); \
640 extern const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name)
642#define DEVICE_MMIO_TOPLEVEL_DECLARE(name) \
643 extern const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name)
660#ifdef DEVICE_MMIO_IS_IN_RAM
661#define DEVICE_MMIO_TOPLEVEL_STATIC(name, node_id) \
663 static mm_reg_t Z_TOPLEVEL_RAM_NAME(name); \
665 static const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
666 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
668#define DEVICE_MMIO_TOPLEVEL_STATIC(name, node_id) \
670 static const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
671 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
674#ifdef DEVICE_MMIO_IS_IN_RAM
682#define DEVICE_MMIO_TOPLEVEL_RAM_PTR(name) &Z_TOPLEVEL_RAM_NAME(name)
691#define DEVICE_MMIO_TOPLEVEL_ROM_PTR(name) &Z_TOPLEVEL_ROM_NAME(name)
714#ifdef DEVICE_MMIO_IS_IN_RAM
715#define DEVICE_MMIO_TOPLEVEL_MAP(name, flags) \
716 device_map(&Z_TOPLEVEL_RAM_NAME(name), \
717 Z_TOPLEVEL_ROM_NAME(name).phys_addr, \
718 Z_TOPLEVEL_ROM_NAME(name).size, (flags))
720#define DEVICE_MMIO_TOPLEVEL_MAP(name, flags) do { } while (false)
733#ifdef DEVICE_MMIO_IS_IN_RAM
734#define DEVICE_MMIO_TOPLEVEL_GET(name) \
735 ((mm_reg_t)Z_TOPLEVEL_RAM_NAME(name))
737#define DEVICE_MMIO_TOPLEVEL_GET(name) \
738 ((mm_reg_t)Z_TOPLEVEL_ROM_NAME(name).addr)
static __boot_func void device_map(mm_reg_t *virt_addr, uintptr_t phys_addr, size_t size, uint32_t flags)
Set linear address for device MMIO access.
Definition: device_mmio.h:97
#define K_MEM_PERM_RW
Region will have read/write access (and not read-only)
Definition: mm.h:61
void k_mem_map_phys_bare(uint8_t **virt_ptr, uintptr_t phys, size_t size, uint32_t flags)
Map a physical memory region into the kernel's virtual address space.
int sys_mm_drv_page_phys_get(void *virt, uintptr_t *phys)
Get the mapped physical memory address from virtual address.
flags
Definition: parser.h:96
Definitions of various linker Sections.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition: stdint.h:105
uintptr_t mm_reg_t
Definition: sys_io.h:20
Memory Management Driver APIs.