Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Single MMIO region macros

Macros

#define DEVICE_MMIO_RAM   mm_reg_t _mmio
 
#define DEVICE_MMIO_RAM_PTR(device)   (mm_reg_t *)((device)->data)
 
#define DEVICE_MMIO_ROM   struct z_device_mmio_rom _mmio
 Declare storage for MMIO data within a device's config struct. More...
 
#define DEVICE_MMIO_ROM_PTR(dev)    ((struct z_device_mmio_rom *)((dev)->config))
 
#define DEVICE_MMIO_ROM_INIT(node_id)    ._mmio = Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
 Initialize a DEVICE_MMIO_ROM member. More...
 
#define DEVICE_MMIO_MAP(dev, flags)
 Map MMIO memory into the address space. More...
 
#define DEVICE_MMIO_GET(dev)   (*DEVICE_MMIO_RAM_PTR(dev))
 Obtain the MMIO address for a device. More...
 

Detailed Description

For drivers which need to manage just one MMIO region, the most common case.

Macro Definition Documentation

◆ DEVICE_MMIO_GET

#define DEVICE_MMIO_GET (   dev)    (*DEVICE_MMIO_RAM_PTR(dev))

#include <include/sys/device_mmio.h>

Obtain the MMIO address for a device.

For most microcontrollers MMIO addresses can be fixed values known at build time, and we can store this in device->config, residing in ROM.

However, some devices can only know their MMIO addresses at runtime, because they need to be memory-mapped into the address space, enumerated from PCI, or both.

This macro returns the linear address of the driver's MMIO region. This is for drivers which have exactly one MMIO region. A call must have been made to device_map() in the driver init function.

Parameters
devDevice object
Returns
mm_reg_t linear address of the MMIO region

◆ DEVICE_MMIO_MAP

#define DEVICE_MMIO_MAP (   dev,
  flags 
)

#include <include/sys/device_mmio.h>

Value:
DEVICE_MMIO_ROM_PTR(dev)->phys_addr, \
DEVICE_MMIO_ROM_PTR(dev)->size, \
(flags))
#define DEVICE_MMIO_ROM_PTR(dev)
Definition: device_mmio.h:219
#define DEVICE_MMIO_RAM_PTR(device)
Definition: device_mmio.h:175
static __boot_func void device_map(mm_reg_t *virt_addr, uintptr_t phys_addr, size_t size, uint32_t flags)
Definition: device_mmio.h:86
flags
Definition: http_parser.h:131

Map MMIO memory into the address space.

This is not intended for PCIe devices; these must be probed at runtime and you will want to make a device_map() call directly, using DEVICE_MMIO_RAM_PTR() as the target virtual address location.

The flags argument is currently used for caching mode, which should be one of the DEVICE_CACHE_* macros. Unused bits are reserved for future expansion.

Parameters
devDevice object instance
flagscache mode flags

◆ DEVICE_MMIO_RAM

#define DEVICE_MMIO_RAM   mm_reg_t _mmio

#include <include/sys/device_mmio.h>

Declare storage for MMIO information within a device's dev_data struct.

This gets accessed by the DEVICE_MMIO_MAP() and DEVICE_MMIO_GET() macros.

Depending on configuration, no memory may be reserved at all. This must be the first member of the data struct.

There must be a corresponding DEVICE_MMIO_ROM in config_info if the physical address is known at build time, but may be omitted if not (such as with PCIe)

Example for a driver named "foo":

struct foo_driver_data { DEVICE_MMIO_RAM; int wibble; ... }

No build-time initialization of this memory is necessary; it will be set up in the init function by DEVICE_MMIO_MAP().

A pointer to this memory may be obtained with DEVICE_MMIO_RAM_PTR().

◆ DEVICE_MMIO_RAM_PTR

#define DEVICE_MMIO_RAM_PTR (   device)    (mm_reg_t *)((device)->data)

#include <include/sys/device_mmio.h>

Return a pointer to the RAM-based storage area for a device's MMIO address.

This is useful for the target MMIO address location when using device_map() directly.

Parameters
devicedevice node_id object
Return values
mm_reg_tpointer to storage location

◆ DEVICE_MMIO_ROM

#define DEVICE_MMIO_ROM   struct z_device_mmio_rom _mmio

#include <include/sys/device_mmio.h>

Declare storage for MMIO data within a device's config struct.

This gets accessed by DEVICE_MMIO_MAP() and DEVICE_MMIO_GET() macros.

What gets stored here varies considerably by configuration. This must be the first member of the config struct. There must be a corresponding DEVICE_MMIO_RAM in data.

This storage is not used if the device is PCIe and may be omitted.

This should be initialized at build time with information from DTS using DEVICE_MMIO_ROM_INIT().

A pointer to this memory may be obtained with DEVICE_MMIO_ROM_PTR().

Example for a driver named "foo":

struct foo_config { DEVICE_MMIO_ROM; int baz; ... }

See also
DEVICE_MMIO_ROM_INIT()

◆ DEVICE_MMIO_ROM_INIT

#define DEVICE_MMIO_ROM_INIT (   node_id)     ._mmio = Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)

#include <include/sys/device_mmio.h>

Initialize a DEVICE_MMIO_ROM member.

Initialize MMIO-related information within a specific instance of a device config struct, using information from DTS.

Example for a driver belonging to the "foo" subsystem:

struct foo_config my_config = { DEVICE_MMIO_ROM_INIT(DT_DRV_INST(...)), .baz = 2; ... }

See also
DEVICE_MMIO_ROM()
Parameters
node_idDTS node_id

◆ DEVICE_MMIO_ROM_PTR

#define DEVICE_MMIO_ROM_PTR (   dev)     ((struct z_device_mmio_rom *)((dev)->config))

#include <include/sys/device_mmio.h>

Return a pointer to the ROM-based storage area for a device's MMIO information. This macro will not work properly if the ROM storage was omitted from the config struct declaration, and should not be used in this case.

Parameters
devdevice instance object
Return values
structdevice_mmio_rom * pointer to storage location