XenevaOS
Loading...
Searching...
No Matches
Classes | Macros
iosys-map.h File Reference
#include <linux/compiler_types.h>
#include <linux/io.h>
#include <linux/string.h>
Include dependency graph for iosys-map.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  iosys_map
 

Macros

#define IOSYS_MAP_INIT_VADDR(vaddr_)
 
#define IOSYS_MAP_INIT_VADDR_IOMEM(vaddr_iomem_)
 
#define IOSYS_MAP_INIT_OFFSET(map_, offset_)
 
#define __iosys_map_rd_io_u64_case(val_, vaddr_iomem_)    u64: memcpy_fromio(&(val_), vaddr_iomem_, sizeof(u64))
 
#define __iosys_map_wr_io_u64_case(val_, vaddr_iomem_)    u64: memcpy_toio(vaddr_iomem_, &(val_), sizeof(u64))
 
#define __iosys_map_rd_io(val__, vaddr_iomem__, type__)
 
#define __iosys_map_rd_sys(val__, vaddr__, type__)    val__ = READ_ONCE(*(type__ *)(vaddr__))
 
#define __iosys_map_wr_io(val__, vaddr_iomem__, type__)
 
#define __iosys_map_wr_sys(val__, vaddr__, type__)    WRITE_ONCE(*(type__ *)(vaddr__), val__)
 
#define iosys_map_rd(map__, offset__, type__)
 
#define iosys_map_wr(map__, offset__, type__, val__)
 
#define iosys_map_rd_field(map__, struct_offset__, struct_type__, field__)
 
#define iosys_map_wr_field(map__, struct_offset__, struct_type__, field__, val__)
 

Macro Definition Documentation

◆ __iosys_map_rd_io

#define __iosys_map_rd_io (   val__,
  vaddr_iomem__,
  type__ 
)
Value:
_Generic(val__, \
u8: val__ = readb(vaddr_iomem__), \
u16: val__ = readw(vaddr_iomem__), \
u32: val__ = readl(vaddr_iomem__), \
__iosys_map_rd_io_u64_case(val__, vaddr_iomem__))
#define __iosys_map_rd_io_u64_case(val_, vaddr_iomem_)
Definition iosys-map.h:351
#define readb(addr)
Definition kernel.h:352
#define readw(addr)
Definition kernel.h:353
uint8_t u8
Definition kernel.h:14
uint16_t u16
Definition kernel.h:15
#define readl(addr)
Definition kernel.h:354
uint32_t u32
Definition kernel.h:16

◆ __iosys_map_rd_io_u64_case

#define __iosys_map_rd_io_u64_case (   val_,
  vaddr_iomem_ 
)     u64: memcpy_fromio(&(val_), vaddr_iomem_, sizeof(u64))

◆ __iosys_map_rd_sys

#define __iosys_map_rd_sys (   val__,
  vaddr__,
  type__ 
)     val__ = READ_ONCE(*(type__ *)(vaddr__))

◆ __iosys_map_wr_io

#define __iosys_map_wr_io (   val__,
  vaddr_iomem__,
  type__ 
)
Value:
_Generic(val__, \
u8: writeb(val__, vaddr_iomem__), \
u16: writew(val__, vaddr_iomem__), \
u32: writel(val__, vaddr_iomem__), \
__iosys_map_wr_io_u64_case(val__, vaddr_iomem__))
#define __iosys_map_wr_io_u64_case(val_, vaddr_iomem_)
Definition iosys-map.h:353
#define writew(v, addr)
Definition kernel.h:356
#define writeb(v, addr)
Definition kernel.h:355
#define writel(v, addr)
Definition kernel.h:357

◆ __iosys_map_wr_io_u64_case

#define __iosys_map_wr_io_u64_case (   val_,
  vaddr_iomem_ 
)     u64: memcpy_toio(vaddr_iomem_, &(val_), sizeof(u64))

◆ __iosys_map_wr_sys

#define __iosys_map_wr_sys (   val__,
  vaddr__,
  type__ 
)     WRITE_ONCE(*(type__ *)(vaddr__), val__)

◆ IOSYS_MAP_INIT_OFFSET

#define IOSYS_MAP_INIT_OFFSET (   map_,
  offset_ 
)
Value:
({ \
struct iosys_map copy_ = *map_; \
iosys_map_incr(&copy_, offset_); \
copy_; \
})
Definition iosys-map.h:109

IOSYS_MAP_INIT_OFFSET - Initializes struct iosys_map from another iosys_map @map_: The dma-buf mapping structure to copy from @offset_: Offset to add to the other mapping

Initializes a new iosys_map struct based on another passed as argument. It does a shallow copy of the struct so it's possible to update the back storage without changing where the original map points to. It is the equivalent of doing:

.. code-block:: c

iosys_map map = other_map; iosys_map_incr(&map, &offset);

Example usage:

.. code-block:: c

void foo(struct device *dev, struct iosys_map *base_map) { ... struct iosys_map map = IOSYS_MAP_INIT_OFFSET(base_map, FIELD_OFFSET); ... }

The advantage of using the initializer over just increasing the offset with iosys_map_incr() like above is that the new map will always point to the right place of the buffer during its scope. It reduces the risk of updating the wrong part of the buffer and having no compiler warning about that. If the assignment to IOSYS_MAP_INIT_OFFSET() is forgotten, the compiler can warn about the use of uninitialized variable.

◆ IOSYS_MAP_INIT_VADDR

#define IOSYS_MAP_INIT_VADDR (   vaddr_)
Value:
{ \
.vaddr = (vaddr_), \
.is_iomem = false, \
}

IOSYS_MAP_INIT_VADDR - Initializes struct iosys_map to an address in system memory @vaddr_: A system-memory address

◆ IOSYS_MAP_INIT_VADDR_IOMEM

#define IOSYS_MAP_INIT_VADDR_IOMEM (   vaddr_iomem_)
Value:
{ \
.vaddr_iomem = (vaddr_iomem_), \
.is_iomem = true, \
}

IOSYS_MAP_INIT_VADDR_IOMEM - Initializes struct iosys_map to an address in I/O memory @vaddr_iomem_: An I/O-memory address

◆ iosys_map_rd

#define iosys_map_rd (   map__,
  offset__,
  type__ 
)
Value:
({ \
type__ val_; \
if ((map__)->is_iomem) { \
__iosys_map_rd_io(val_, (map__)->vaddr_iomem + (offset__), type__); \
} else { \
__iosys_map_rd_sys(val_, (map__)->vaddr + (offset__), type__); \
} \
val_; \
})

iosys_map_rd - Read a C-type value from the iosys_map

@map__: The iosys_map structure @offset__: The offset from which to read @type__: Type of the value being read

Read a C type value (u8, u16, u32 and u64) from iosys_map. For other types or if pointer may be unaligned (and problematic for the architecture supported), use iosys_map_memcpy_from().

Returns: The value read from the mapping.

◆ iosys_map_rd_field

#define iosys_map_rd_field (   map__,
  struct_offset__,
  struct_type__,
  field__ 
)
Value:
({ \
struct_type__ *s_; \
iosys_map_rd(map__, struct_offset__ + offsetof(struct_type__, field__), \
typeof(s_->field__)); \
})
#define offsetof(type, member)
Definition kernel.h:177

◆ iosys_map_wr

#define iosys_map_wr (   map__,
  offset__,
  type__,
  val__ 
)
Value:
({ \
type__ val_ = (val__); \
if ((map__)->is_iomem) { \
__iosys_map_wr_io(val_, (map__)->vaddr_iomem + (offset__), type__); \
} else { \
__iosys_map_wr_sys(val_, (map__)->vaddr + (offset__), type__); \
} \
})

iosys_map_wr - Write a C-type value to the iosys_map

@map__: The iosys_map structure @offset__: The offset from the mapping to write to @type__: Type of the value being written @val__: Value to write

Write a C type value (u8, u16, u32 and u64) to the iosys_map. For other types or if pointer may be unaligned (and problematic for the architecture supported), use iosys_map_memcpy_to()

◆ iosys_map_wr_field

#define iosys_map_wr_field (   map__,
  struct_offset__,
  struct_type__,
  field__,
  val__ 
)
Value:
({ \
struct_type__ *s_; \
iosys_map_wr(map__, struct_offset__ + offsetof(struct_type__, field__), \
typeof(s_->field__), val__); \
})

iosys_map_wr_field - Write to a member of a struct in the iosys_map

@map__: The iosys_map structure @struct_offset__: Offset from the beginning of the map, where the struct is located @struct_type__: The struct describing the layout of the mapping @field__: Member of the struct to read @val__: Value to write

Write a value to the iosys_map considering its layout is described by a C struct starting at @struct_offset__. The field offset and size is calculated and the @val__ is written. If the field access would incur in un-aligned access, then either iosys_map_memcpy_to() needs to be used or the architecture must support it. Refer to iosys_map_rd_field() for expected usage and memory layout.