From nobody Sat Feb 17 21:32:56 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TchqD4TD6z59lCD; Sat, 17 Feb 2024 21:32:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TchqD24CJz4hB9; Sat, 17 Feb 2024 21:32:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L6aXO084mYL3nzMTby251zvlswP9DBMxhCnb35yVkJY=; b=pz902aJsvCr+OoSJmfVugy1+MOnsIbCB2g3XoFAR6AIzbIcP2SSayEyugeLecu3ozpzH1k iur05oMGDNY3nunAj9bxLrs3KD8EKyaooUYTknspoWwvZHKQdDbMQRMpiwEtGIjdbANTYM nmikjjRJzFFusCkT7W3OFuq/wgb3yf0SKLq9CETU5l9rVhS2s089Oty7wo5xJUmaRvNzE7 klquRW/+cJrGoXYKBjJfp2qJGtxIwC+URmOIDr4AA54uz+1dX9WbeSM4gzg5LCJeI8EY20 Vy/SEU1QMUfGleS911aIFCfUSXUcA8SFPOCIO6aw5gmF3DxgzXPXS5c8joFJeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708205576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L6aXO084mYL3nzMTby251zvlswP9DBMxhCnb35yVkJY=; b=HfWCtNZdfLb1C4IbFsWvFkUwl5eiAv+ckAdQjzUch/mTP/voUZJNVkvlFlSrdkJbiUA0w2 1YB8bDU1XWFVFlCMsXWReQTHZq56vE+Du/Qp5gZ99vhbzVma0BEwymm2KfAcKquay3MPVx /u0tOwzTCLXb0ATXqrxmB0M30mb5r8X8aHr8KAr5sMj3t0GaOLs/DjfxUVY60r5kh2Qrmd vjwZ3bp48yLzFvSq+rRh6kbiocsifXLkUZoKPmEcsgUf/5yoA3Gb4BLcoRv8Fws81XgV5d zZvHE5+0msKBqGMP6O3gJ+D/6PtNS95qWgKA3+PbUuAzrgznv4pzQFLgu3A2gw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708205576; a=rsa-sha256; cv=none; b=BZVRBWfNunifuw6nA1pcgUo5rDUzbgms8XJYVJ2etPgPLEK1KNYMBZTQCs86JLDBov7vnK IRzBQeVCEyqRM7tobp0H8Dnk7jIRoEMHbwFORPXL3SgsLC9ePKFUXwSafv0WzC6QI79Eoh uLxiIRVVbheLZfLC6BUy7XRYTx9izyTGPiiDaLO5CGVZ+hWby+qt1yixoENUo78eBRp6qW CEUL6uSv/4hRPPxIABGgJu5tETIHHNDpI88bONxZ8jxJmRjKaq5Vug6S6tUA4b4wwVEwfu xD/0KTtB4Rd5ilOjJPwago3llFVbNQ6XtMzaRHX9rGj8SXKcibsR0j5QCmyidg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TchqD1B5zzPMF; Sat, 17 Feb 2024 21:32:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41HLWuUY020622; Sat, 17 Feb 2024 21:32:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41HLWuY6020619; Sat, 17 Feb 2024 21:32:56 GMT (envelope-from git) Date: Sat, 17 Feb 2024 21:32:56 GMT Message-Id: <202402172132.41HLWuY6020619@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: 11b0824a80d6 - stable/14 - LinuxKPI: Add linux/iosys-map.h header List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 11b0824a80d6fe7d2746b490c1fddfa99d3d4bea Auto-Submitted: auto-generated The branch stable/14 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=11b0824a80d6fe7d2746b490c1fddfa99d3d4bea commit 11b0824a80d6fe7d2746b490c1fddfa99d3d4bea Author: Vladimir Kondratyev AuthorDate: 2023-12-24 08:19:58 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-02-17 20:58:37 +0000 LinuxKPI: Add linux/iosys-map.h header Sponsored by: Serenity Cyber Security, LLC Obtained from: OpenBSD MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D42799 (cherry picked from commit f8ab2f5bae1d4e4e13f95f4738c9bb49fcda6261) --- .../linuxkpi/common/include/linux/iosys-map.h | 161 +++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/iosys-map.h b/sys/compat/linuxkpi/common/include/linux/iosys-map.h new file mode 100644 index 000000000000..66c442b8668f --- /dev/null +++ b/sys/compat/linuxkpi/common/include/linux/iosys-map.h @@ -0,0 +1,161 @@ +/* Public domain. */ + +#ifndef _LINUXKPI_LINUX_IOSYS_MAP_H +#define _LINUXKPI_LINUX_IOSYS_MAP_H + +#include +#include + +struct iosys_map { + union { + void *vaddr_iomem; + void *vaddr; + }; + bool is_iomem; +#ifdef __OpenBSD__ + bus_space_handle_t bsh; + bus_size_t size; +#endif +}; + +#define IOSYS_MAP_INIT_OFFSET(_ism_src_p, _off) ({ \ + struct iosys_map ism_dst = *(_ism_src_p); \ + iosys_map_incr(&ism_dst, _off); \ + ism_dst; \ +}) + +static inline void +iosys_map_incr(struct iosys_map *ism, size_t n) +{ + if (ism->is_iomem) + ism->vaddr_iomem += n; + else + ism->vaddr += n; +} + +static inline void +iosys_map_memcpy_to(struct iosys_map *ism, size_t off, const void *src, + size_t len) +{ + if (ism->is_iomem) + memcpy_toio(ism->vaddr_iomem + off, src, len); + else + memcpy(ism->vaddr + off, src, len); +} + +static inline bool +iosys_map_is_null(const struct iosys_map *ism) +{ + if (ism->is_iomem) + return (ism->vaddr_iomem == NULL); + else + return (ism->vaddr == NULL); +} + +static inline bool +iosys_map_is_set(const struct iosys_map *ism) +{ + if (ism->is_iomem) + return (ism->vaddr_iomem != NULL); + else + return (ism->vaddr != NULL); +} + +static inline bool +iosys_map_is_equal(const struct iosys_map *ism_a, + const struct iosys_map *ism_b) +{ + if (ism_a->is_iomem != ism_b->is_iomem) + return (false); + + if (ism_a->is_iomem) + return (ism_a->vaddr_iomem == ism_b->vaddr_iomem); + else + return (ism_a->vaddr == ism_b->vaddr); +} + +static inline void +iosys_map_clear(struct iosys_map *ism) +{ + if (ism->is_iomem) { + ism->vaddr_iomem = NULL; + ism->is_iomem = false; + } else { + ism->vaddr = NULL; + } +} + +static inline void +iosys_map_set_vaddr_iomem(struct iosys_map *ism, void *addr) +{ + ism->vaddr_iomem = addr; + ism->is_iomem = true; +} + +static inline void +iosys_map_set_vaddr(struct iosys_map *ism, void *addr) +{ + ism->vaddr = addr; + ism->is_iomem = false; +} + +static inline void +iosys_map_memset(struct iosys_map *ism, size_t off, int value, size_t len) +{ + if (ism->is_iomem) + memset_io(ism->vaddr_iomem + off, value, len); + else + memset(ism->vaddr + off, value, len); +} + +#ifdef __LP64__ +#define _iosys_map_readq(_addr) readq(_addr) +#define _iosys_map_writeq(_val, _addr) writeq(_val, _addr) +#else +#define _iosys_map_readq(_addr) ({ \ + uint64_t val; \ + memcpy_fromio(&val, _addr, sizeof(uint64_t)); \ + val; \ +}) +#define _iosys_map_writeq(_val, _addr) \ + memcpy_toio(_addr, &(_val), sizeof(uint64_t)) +#endif + +#define iosys_map_rd(_ism, _off, _type) ({ \ + _type val; \ + if ((_ism)->is_iomem) { \ + void *addr = (_ism)->vaddr_iomem + (_off); \ + val = _Generic(val, \ + uint8_t : readb(addr), \ + uint16_t: readw(addr), \ + uint32_t: readl(addr), \ + uint64_t: _iosys_map_readq(addr)); \ + } else \ + val = READ_ONCE(*(_type *)((_ism)->vaddr + (_off))); \ + val; \ +}) +#define iosys_map_wr(_ism, _off, _type, _val) ({ \ + _type val = (_val); \ + if ((_ism)->is_iomem) { \ + void *addr = (_ism)->vaddr_iomem + (_off); \ + _Generic(val, \ + uint8_t : writeb(val, addr), \ + uint16_t: writew(val, addr), \ + uint32_t: writel(val, addr), \ + uint64_t: _iosys_map_writeq(val, addr)); \ + } else \ + WRITE_ONCE(*(_type *)((_ism)->vaddr + (_off)), val); \ +}) + +#define iosys_map_rd_field(_ism, _off, _type, _field) ({ \ + _type *s; \ + iosys_map_rd(_ism, (_off) + offsetof(_type, _field), \ + __typeof(s->_field)); \ +}) +#define iosys_map_wr_field(_ism, _off, _type, _field, _val) ({ \ + _type *s; \ + iosys_map_wr(_ism, (_off) + offsetof(_type, _field), \ + __typeof(s->_field), _val); \ +}) + +#endif