From: jsg Date: Thu, 28 Mar 2024 05:38:36 +0000 (+0000) Subject: add more iosys_map interfaces used by inteldrm guc code X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=be5961cd091db7a69bfc4ccd00bc2a01c2f19097;p=openbsd add more iosys_map interfaces used by inteldrm guc code based in part on FreeBSD changes --- diff --git a/sys/dev/pci/drm/include/linux/iosys-map.h b/sys/dev/pci/drm/include/linux/iosys-map.h index 4639769b850..1c07f18dca1 100644 --- a/sys/dev/pci/drm/include/linux/iosys-map.h +++ b/sys/dev/pci/drm/include/linux/iosys-map.h @@ -35,6 +35,15 @@ iosys_map_memcpy_to(struct iosys_map *ism, size_t off, const void *src, memcpy(ism->vaddr + off, src, len); } +static inline void +iosys_map_memset(struct iosys_map *ism, size_t off, int c, size_t len) +{ + if (ism->is_iomem) + memset_io(ism->vaddr_iomem + off, c, len); + else + memset(ism->vaddr + off, c, len); +} + static inline bool iosys_map_is_null(const struct iosys_map *ism) { @@ -78,4 +87,53 @@ iosys_map_set_vaddr(struct iosys_map *ism, void *addr) ism->is_iomem = false; } +static inline struct iosys_map +IOSYS_MAP_INIT_OFFSET(struct iosys_map *ism, size_t off) +{ + struct iosys_map nism = *ism; + iosys_map_incr(&nism, off); + return nism; +} + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112 + +#define iosys_map_rd(_ism, _o, _t) ({ \ + _t v; \ + if ((_ism)->is_iomem) { \ + void *addr = (_ism)->vaddr_iomem + (_o); \ + v = _Generic(v, \ + uint8_t : ioread8(addr), \ + uint16_t: ioread16(addr), \ + uint32_t: ioread32(addr), \ + uint64_t: ioread64(addr)); \ + } else \ + v = READ_ONCE(*(_t *)((_ism)->vaddr + (_o))); \ + v; \ +}) + +#define iosys_map_wr(_ism, _o, _t, _v) ({ \ + _t v = (_v); \ + if ((_ism)->is_iomem) { \ + void *addr = (_ism)->vaddr_iomem + (_o); \ + _Generic(v, \ + uint8_t : iowrite8(v, addr), \ + uint16_t: iowrite16(v, addr), \ + uint32_t: iowrite32(v, addr), \ + uint64_t: iowrite64(v, addr)); \ + } else \ + WRITE_ONCE(*(_t *)((_ism)->vaddr + (_o)), v); \ +}) + +#define iosys_map_rd_field(_ism, _o, _t, _f) ({ \ + _t *t; \ + iosys_map_rd(_ism, _o + offsetof(_t, _f), __typeof(t->_f)); \ +}) + +#define iosys_map_wr_field(_ism, _o, _t, _f, _v) ({ \ + _t *t; \ + iosys_map_wr(_ism, _o + offsetof(_t, _f), __typeof(t->_f), _v); \ +}) + +#endif /* C11 */ + #endif