12 #ifndef __METAL_IO__H__ 13 #define __METAL_IO__H__ 19 #include <metal/assert.h> 20 #include <metal/compiler.h> 21 #include <metal/atomic.h> 22 #include <metal/sys.h> 23 #include <metal/cpu.h> 33 #define NO_ATOMIC_64_SUPPORT 95 unsigned page_shift,
unsigned int mem_flags,
106 memset(io, 0,
sizeof(*io));
130 ? (uint8_t *)io->
virt + offset
140 static inline unsigned long 143 size_t offset = (uint8_t *)virt - (uint8_t *)io->
virt;
158 sizeof(offset) * CHAR_BIT ?
160 return (io->
physmap != NULL && offset <= io->size
171 static inline unsigned long 174 unsigned long offset =
181 }
while (offset < io->size);
220 static inline uint64_t
227 return (*io->
ops.
read)(io, offset, order, width);
236 #ifndef NO_ATOMIC_64_SUPPORT 260 (*io->
ops.
write)(io, offset, value, order, width);
269 #ifndef NO_ATOMIC_64_SUPPORT 277 #define metal_io_read8_explicit(_io, _ofs, _order) \ 278 metal_io_read((_io), (_ofs), (_order), 1) 279 #define metal_io_read8(_io, _ofs) \ 280 metal_io_read((_io), (_ofs), memory_order_seq_cst, 1) 281 #define metal_io_write8_explicit(_io, _ofs, _val, _order) \ 282 metal_io_write((_io), (_ofs), (_val), (_order), 1) 283 #define metal_io_write8(_io, _ofs, _val) \ 284 metal_io_write((_io), (_ofs), (_val), memory_order_seq_cst, 1) 286 #define metal_io_read16_explicit(_io, _ofs, _order) \ 287 metal_io_read((_io), (_ofs), (_order), 2) 288 #define metal_io_read16(_io, _ofs) \ 289 metal_io_read((_io), (_ofs), memory_order_seq_cst, 2) 290 #define metal_io_write16_explicit(_io, _ofs, _val, _order) \ 291 metal_io_write((_io), (_ofs), (_val), (_order), 2) 292 #define metal_io_write16(_io, _ofs, _val) \ 293 metal_io_write((_io), (_ofs), (_val), memory_order_seq_cst, 2) 295 #define metal_io_read32_explicit(_io, _ofs, _order) \ 296 metal_io_read((_io), (_ofs), (_order), 4) 297 #define metal_io_read32(_io, _ofs) \ 298 metal_io_read((_io), (_ofs), memory_order_seq_cst, 4) 299 #define metal_io_write32_explicit(_io, _ofs, _val, _order) \ 300 metal_io_write((_io), (_ofs), (_val), (_order), 4) 301 #define metal_io_write32(_io, _ofs, _val) \ 302 metal_io_write((_io), (_ofs), (_val), memory_order_seq_cst, 4) 304 #define metal_io_read64_explicit(_io, _ofs, _order) \ 305 metal_io_read((_io), (_ofs), (_order), 8) 306 #define metal_io_read64(_io, _ofs) \ 307 metal_io_read((_io), (_ofs), memory_order_seq_cst, 8) 308 #define metal_io_write64_explicit(_io, _ofs, _val, _order) \ 309 metal_io_write((_io), (_ofs), (_val), (_order), 8) 310 #define metal_io_write64(_io, _ofs, _val) \ 311 metal_io_write((_io), (_ofs), (_val), memory_order_seq_cst, 8) 344 unsigned char value,
int len);
346 #include <metal/system/@PROJECT_SYSTEM@/io.h> static size_t metal_io_region_size(struct metal_io_region *io)
Get size of I/O region.
Definition: io.h:115
static metal_phys_addr_t metal_io_phys(struct metal_io_region *io, unsigned long offset)
Get physical address for a given offset into the I/O region.
Definition: io.h:155
unsigned short atomic_ushort
Definition: atomic.h:23
static void * metal_io_virt(struct metal_io_region *io, unsigned long offset)
Get virtual address for a given offset into the I/O region.
Definition: io.h:127
int metal_io_block_write(struct metal_io_region *io, unsigned long offset, const void *restrict src, int len)
Write a block into an I/O region.
Definition: io.c:70
static metal_phys_addr_t metal_io_virt_to_phys(struct metal_io_region *io, void *virt)
Convert a virtual address to physical address.
Definition: io.h:205
static void * metal_io_phys_to_virt(struct metal_io_region *io, metal_phys_addr_t phys)
Convert a physical address to virtual address.
Definition: io.h:192
#define METAL_BAD_OFFSET
Definition: sys.h:35
static unsigned long metal_io_phys_to_offset(struct metal_io_region *io, metal_phys_addr_t phys)
Convert a physical address to offset within I/O region.
Definition: io.h:172
#define atomic_store_explicit(OBJ, VAL, MO)
Definition: atomic.h:57
#define METAL_BAD_VA
Definition: sys.h:41
int metal_io_block_read(struct metal_io_region *io, unsigned long offset, void *restrict dst, int len)
Read a block from an I/O region.
Definition: io.c:33
memory_order
Definition: atomic.h:34
#define atomic_load_explicit(OBJ, MO)
Definition: atomic.h:61
static void metal_io_write(struct metal_io_region *io, unsigned long offset, uint64_t value, memory_order order, int width)
Write a value into an I/O region.
Definition: io.h:255
void metal_io_init(struct metal_io_region *io, void *virt, const metal_phys_addr_t *physmap, size_t size, unsigned page_shift, unsigned int mem_flags, const struct metal_io_ops *ops)
Open a libmetal I/O region.
Definition: io.c:12
unsigned char atomic_uchar
Definition: atomic.h:21
int metal_io_block_set(struct metal_io_region *io, unsigned long offset, unsigned char value, int len)
fill a block of an I/O region.
Definition: io.c:107
unsigned long atomic_ulong
Definition: atomic.h:27
#define metal_assert(cond)
Assertion macro.
Definition: assert.h:21
static void metal_io_finish(struct metal_io_region *io)
Close a libmetal shared memory segment.
Definition: io.h:102
#define restrict
Definition: compiler.h:19
#define METAL_BAD_PHYS
Definition: sys.h:38
static uint64_t metal_io_read(struct metal_io_region *io, unsigned long offset, memory_order order, int width)
Read a value from an I/O region.
Definition: io.h:221
unsigned long long atomic_ullong
Definition: atomic.h:29
unsigned int atomic_uint
Definition: atomic.h:25
static unsigned long metal_io_virt_to_offset(struct metal_io_region *io, void *virt)
Convert a virtual address to offset within I/O region.
Definition: io.h:141
unsigned long metal_phys_addr_t
Definition: sys.h:29