36 #ifndef __METAL_IO__H__ 37 #define __METAL_IO__H__ 43 #include "metal/compiler.h" 44 #include "metal/atomic.h" 45 #include "metal/sys.h" 74 const void *restrict src,
113 unsigned page_shift,
unsigned int mem_flags,
116 const struct metal_io_ops nops = {NULL, NULL, NULL, NULL, NULL, NULL};
121 io->
page_mask = (1UL << page_shift) - 1UL;
123 io->
ops = ops ? *ops : nops;
134 memset(io, 0,
sizeof(*io));
158 ? (uint8_t *)io->
virt + offset
168 static inline unsigned long 171 size_t offset = (uint8_t *)virt - (uint8_t *)io->
virt;
185 unsigned long page = offset >> io->
page_shift;
186 return (io->
physmap != NULL && offset <= io->size
198 static inline unsigned long 201 unsigned long offset =
208 }
while (offset < io->size);
247 static inline uint64_t
253 return (*io->
ops.
read)(io, offset, order, width);
285 (*io->
ops.
write)(io, offset, value, order, width);
300 #define metal_io_read8_explicit(_io, _ofs, _order) \ 301 metal_io_read((_io), (_ofs), (_order), 1) 302 #define metal_io_read8(_io, _ofs) \ 303 metal_io_read((_io), (_ofs), memory_order_seq_cst, 1) 304 #define metal_io_write8_explicit(_io, _ofs, _val, _order) \ 305 metal_io_write((_io), (_ofs), (_val), (_order), 1) 306 #define metal_io_write8(_io, _ofs, _val) \ 307 metal_io_write((_io), (_ofs), (_val), memory_order_seq_cst, 1) 309 #define metal_io_read16_explicit(_io, _ofs, _order) \ 310 metal_io_read((_io), (_ofs), (_order), 2) 311 #define metal_io_read16(_io, _ofs) \ 312 metal_io_read((_io), (_ofs), memory_order_seq_cst, 2) 313 #define metal_io_write16_explicit(_io, _ofs, _val, _order) \ 314 metal_io_write((_io), (_ofs), (_val), (_order), 2) 315 #define metal_io_write16(_io, _ofs, _val) \ 316 metal_io_write((_io), (_ofs), (_val), memory_order_seq_cst, 2) 318 #define metal_io_read32_explicit(_io, _ofs, _order) \ 319 metal_io_read((_io), (_ofs), (_order), 4) 320 #define metal_io_read32(_io, _ofs) \ 321 metal_io_read((_io), (_ofs), memory_order_seq_cst, 4) 322 #define metal_io_write32_explicit(_io, _ofs, _val, _order) \ 323 metal_io_write((_io), (_ofs), (_val), (_order), 4) 324 #define metal_io_write32(_io, _ofs, _val) \ 325 metal_io_write((_io), (_ofs), (_val), memory_order_seq_cst, 4) 327 #define metal_io_read64_explicit(_io, _ofs, _order) \ 328 metal_io_read((_io), (_ofs), (_order), 8) 329 #define metal_io_read64(_io, _ofs) \ 330 metal_io_read((_io), (_ofs), memory_order_seq_cst, 8) 331 #define metal_io_write64_explicit(_io, _ofs, _val, _order) \ 332 metal_io_write((_io), (_ofs), (_val), (_order), 8) 333 #define metal_io_write64(_io, _ofs, _val) \ 334 metal_io_write((_io), (_ofs), (_val), memory_order_seq_cst, 8) 345 void *restrict dst,
int len);
356 const void *restrict src,
int len);
367 unsigned char value,
int len);
static size_t metal_io_region_size(struct metal_io_region *io)
Get size of I/O region.
Definition: io.h:143
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:183
unsigned short atomic_ushort
Definition: atomic.h:47
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:155
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:232
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:219
#define METAL_BAD_OFFSET
Definition: sys.h:59
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:199
#define atomic_store_explicit(OBJ, VAL, MO)
Definition: atomic.h:81
#define METAL_BAD_VA
Definition: sys.h:65
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:34
memory_order
Definition: atomic.h:58
#define atomic_load_explicit(OBJ, MO)
Definition: atomic.h:85
static 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.h:111
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:280
unsigned char atomic_uchar
Definition: atomic.h:45
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:106
unsigned long atomic_ulong
Definition: atomic.h:51
static void metal_io_finish(struct metal_io_region *io)
Close a libmetal shared memory segment.
Definition: io.h:130
#define METAL_BAD_PHYS
Definition: sys.h:62
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:248
unsigned long long atomic_ullong
Definition: atomic.h:53
unsigned int atomic_uint
Definition: atomic.h:49
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:169
unsigned long metal_phys_addr_t
Definition: sys.h:53