15#ifndef ZEPHYR_INCLUDE_SYS_DEVICE_MMIO_H
16#define ZEPHYR_INCLUDE_SYS_DEVICE_MMIO_H
36#if defined(CONFIG_MMU) || defined(CONFIG_PCIE) || defined(CONFIG_EXTERNAL_ADDRESS_TRANSLATION)
37#define DEVICE_MMIO_IS_IN_RAM
40#if defined(CONFIG_EXTERNAL_ADDRESS_TRANSLATION)
50#ifdef DEVICE_MMIO_IS_IN_RAM
55struct z_device_mmio_rom {
63#define Z_DEVICE_MMIO_ROM_INITIALIZER(node_id) \
65 .phys_addr = DT_REG_ADDR(node_id), \
66 .size = DT_REG_SIZE(node_id) \
69#define Z_DEVICE_MMIO_NAMED_ROM_INITIALIZER(name, node_id) \
71 .phys_addr = DT_REG_ADDR_BY_NAME(node_id, name), \
72 .size = DT_REG_SIZE_BY_NAME(node_id, name) \
103 z_phys_map((
uint8_t **)virt_addr, phys_addr, size,
108#ifdef CONFIG_EXTERNAL_ADDRESS_TRANSLATION
111 *virt_addr = phys_addr;
119struct z_device_mmio_rom {
124#define Z_DEVICE_MMIO_ROM_INITIALIZER(node_id) \
126 .addr = (mm_reg_t)DT_REG_ADDR_U64(node_id) \
129#define Z_DEVICE_MMIO_NAMED_ROM_INITIALIZER(name, node_id) \
131 .addr = (mm_reg_t)DT_REG_ADDR_BY_NAME_U64(node_id, name) \
175#ifdef DEVICE_MMIO_IS_IN_RAM
176#define DEVICE_MMIO_RAM mm_reg_t _mmio
178#define DEVICE_MMIO_RAM
181#ifdef DEVICE_MMIO_IS_IN_RAM
192#define DEVICE_MMIO_RAM_PTR(device) (mm_reg_t *)((device)->data)
221#define DEVICE_MMIO_ROM struct z_device_mmio_rom _mmio
232#define DEVICE_MMIO_ROM_PTR(dev) \
233 ((struct z_device_mmio_rom *)((dev)->config))
253#define DEVICE_MMIO_ROM_INIT(node_id) \
254 ._mmio = Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
272#ifdef DEVICE_MMIO_IS_IN_RAM
273#define DEVICE_MMIO_MAP(dev, flags) \
274 device_map(DEVICE_MMIO_RAM_PTR(dev), \
275 DEVICE_MMIO_ROM_PTR(dev)->phys_addr, \
276 DEVICE_MMIO_ROM_PTR(dev)->size, \
279#define DEVICE_MMIO_MAP(dev, flags) do { } while (false)
301#ifdef DEVICE_MMIO_IS_IN_RAM
302#define DEVICE_MMIO_GET(dev) (*DEVICE_MMIO_RAM_PTR(dev))
304#define DEVICE_MMIO_GET(dev) (DEVICE_MMIO_ROM_PTR(dev)->addr)
348#ifdef DEVICE_MMIO_IS_IN_RAM
349#define DEVICE_MMIO_NAMED_RAM(name) mm_reg_t name
351#define DEVICE_MMIO_NAMED_RAM(name)
354#ifdef DEVICE_MMIO_IS_IN_RAM
365#define DEVICE_MMIO_NAMED_RAM_PTR(dev, name) \
366 (&(DEV_DATA(dev)->name))
400#define DEVICE_MMIO_NAMED_ROM(name) struct z_device_mmio_rom name
414#define DEVICE_MMIO_NAMED_ROM_PTR(dev, name) (&(DEV_CFG(dev)->name))
438#define DEVICE_MMIO_NAMED_ROM_INIT(name, node_id) \
439 .name = Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
479#define DEVICE_MMIO_NAMED_ROM_INIT_BY_NAME(name, node_id) \
480 .name = Z_DEVICE_MMIO_NAMED_ROM_INITIALIZER(name, node_id)
508#ifdef DEVICE_MMIO_IS_IN_RAM
509#define DEVICE_MMIO_NAMED_MAP(dev, name, flags) \
510 device_map(DEVICE_MMIO_NAMED_RAM_PTR((dev), name), \
511 (DEVICE_MMIO_NAMED_ROM_PTR((dev), name)->phys_addr), \
512 (DEVICE_MMIO_NAMED_ROM_PTR((dev), name)->size), \
515#define DEVICE_MMIO_NAMED_MAP(dev, name, flags) do { } while (false)
539#ifdef DEVICE_MMIO_IS_IN_RAM
540#define DEVICE_MMIO_NAMED_GET(dev, name) \
541 (*DEVICE_MMIO_NAMED_RAM_PTR((dev), name))
543#define DEVICE_MMIO_NAMED_GET(dev, name) \
544 ((DEVICE_MMIO_NAMED_ROM_PTR((dev), name))->addr)
566 #define Z_TOPLEVEL_ROM_NAME(name) _CONCAT(z_mmio_rom__, name)
567 #define Z_TOPLEVEL_RAM_NAME(name) _CONCAT(z_mmio_ram__, name)
584#ifdef DEVICE_MMIO_IS_IN_RAM
585#define DEVICE_MMIO_TOPLEVEL(name, node_id) \
587 mm_reg_t Z_TOPLEVEL_RAM_NAME(name); \
589 const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
590 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
592#define DEVICE_MMIO_TOPLEVEL(name, node_id) \
594 const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
595 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
612#ifdef DEVICE_MMIO_IS_IN_RAM
613#define DEVICE_MMIO_TOPLEVEL_DECLARE(name) \
614 extern mm_reg_t Z_TOPLEVEL_RAM_NAME(name); \
615 extern const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name)
617#define DEVICE_MMIO_TOPLEVEL_DECLARE(name) \
618 extern const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name)
635#ifdef DEVICE_MMIO_IS_IN_RAM
636#define DEVICE_MMIO_TOPLEVEL_STATIC(name, node_id) \
638 static mm_reg_t Z_TOPLEVEL_RAM_NAME(name); \
640 static const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
641 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
643#define DEVICE_MMIO_TOPLEVEL_STATIC(name, node_id) \
645 static const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
646 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
649#ifdef DEVICE_MMIO_IS_IN_RAM
657#define DEVICE_MMIO_TOPLEVEL_RAM_PTR(name) &Z_TOPLEVEL_RAM_NAME(name)
666#define DEVICE_MMIO_TOPLEVEL_ROM_PTR(name) &Z_TOPLEVEL_ROM_NAME(name)
689#ifdef DEVICE_MMIO_IS_IN_RAM
690#define DEVICE_MMIO_TOPLEVEL_MAP(name, flags) \
691 device_map(&Z_TOPLEVEL_RAM_NAME(name), \
692 Z_TOPLEVEL_ROM_NAME(name).phys_addr, \
693 Z_TOPLEVEL_ROM_NAME(name).size, flags)
695#define DEVICE_MMIO_TOPLEVEL_MAP(name, flags) do { } while (false)
708#ifdef DEVICE_MMIO_IS_IN_RAM
709#define DEVICE_MMIO_TOPLEVEL_GET(name) \
710 ((mm_reg_t)Z_TOPLEVEL_RAM_NAME(name))
712#define DEVICE_MMIO_TOPLEVEL_GET(name) \
713 ((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:96
int sys_mm_drv_page_phys_get(void *virt, uintptr_t *phys)
Get the mapped physical memory address from virtual address.
#define K_MEM_PERM_RW
Region will have read/write access (and not read-only)
Definition: mem_manage.h:50
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.