From nobody Sun Jul 21 13:14:57 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 4WRkR60qy3z5RVSP; Sun, 21 Jul 2024 13:14:58 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WRkR5495Lz4S1x; Sun, 21 Jul 2024 13:14:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721567697; 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=HwcVFe2j9os/JX6RlnSKEFxXk903YYF4VAlhyQTXAEc=; b=jBpHwCYbRY8QmImSM/3M/xE3GsEeQtQcXyYWH4ATwK+oE6vS/SAvXLaXwPYyG/vzLEonlL 5VSlR7j2rmDQ+Edza75bS8p7VbDqQd0cnZUXgkgpifeEH0iOBklyrDWqQBG+6VgpL3a7kV DyQHsFewn8PJ/Gc8Uc4U1K1aUy1DFUJap980A0q1Bn9ddru8F2nEkhta2A2Zq+UDa63hKM 7dKQFQGiit4WENHIoQbDZbTcu8OOp2dmYIaMIxIOdf21O3IPRAf+U37Z5i86T9wRnjBfxc ccsyd7lRj04CG1eDoHUJIlAGrqVAUhMJXof+Gw+H0KQ26T0V0MmTarHdyrpDFw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721567697; a=rsa-sha256; cv=none; b=uOOGhGoR7yN4GOdRtquX1kOzgMWPuingptCD7GGAxjS7RXnmtzZJp8Ghavl++x9FJ/9pB6 Z4mpXI02IP5z6i+AIimX8dzf23oYqEYmaOD92m/WiWC99kR4mHIIRMY52AD2YUMS5qnetv lPQrdhNyFCUm9TSsrSK1YsdhoVhT1wY0/vz8C3LoRbRBgtdHQotS/LRnb88pbm2B6LHppj Q5gejMojU83NqB6StU6QtydjcsDQzzTG89J0GP1LsNIHKYc55qdgdY/9KY/UUBK4QE0uZK FgXhqjm1D6zZDLVrRbjN4fVS+JlgF2j9a9+Ok6oyFGi/9tWaGnoxBGQRD15f7Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721567697; 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=HwcVFe2j9os/JX6RlnSKEFxXk903YYF4VAlhyQTXAEc=; b=MCcsaDcBrL0uOKXun6p+tmyu7WGDNyAEWx5kNq4oxJIVzpvyb9i23vRxh9Pqh0rZsA5eJt fxlrIkeeaurDw5pShjjSfCfiRGQc4y78nQ0WRF9HyaldQ8DFfKHOOfZXqvsFqMFoHkxoGG 3t3p5Ouih8c4beZZLuaPzrWVQRuP6UWYDopzkL9xFN16STCB4bwa5g+vRlQcfHMi4MkG9b qQvCmeuXXIU43emA3hDL1199OL574wKNSucDsTfof0taYdpgbxPv3SDIaz9kZ6ZCSr6EcU l/Fidj3+m2fzRbqT2WVaPwRc7TvVyrTj4Zm5oIhlxvhNRZaGELOn0pX25Yo16g== 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 4WRkR53Qmnz12Bm; Sun, 21 Jul 2024 13:14:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46LDEvNf023402; Sun, 21 Jul 2024 13:14:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46LDEv9l023399; Sun, 21 Jul 2024 13:14:57 GMT (envelope-from git) Date: Sun, 21 Jul 2024 13:14:57 GMT Message-Id: <202407211314.46LDEv9l023399@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: fcc350c375f7 - main - LinuxKPI: Add pci_iomap_range function 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/main X-Git-Reftype: branch X-Git-Commit: fcc350c375f776318d0da8021109631492ab9261 Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=fcc350c375f776318d0da8021109631492ab9261 commit fcc350c375f776318d0da8021109631492ab9261 Author: Vladimir Kondratyev AuthorDate: 2024-07-21 13:10:25 +0000 Commit: Vladimir Kondratyev CommitDate: 2024-07-21 13:10:25 +0000 LinuxKPI: Add pci_iomap_range function pci_iomap_range creates a virtual mapping cookie for a PCI BAR. As compared with pci_iomap it got extra offset parameter. Sponsored by: Serenity CyberSecurity, LLC MFC after: 1 week Reviewed by: manu, bz Differential Revision: https://reviews.freebsd.org/D45904 --- sys/compat/linuxkpi/common/include/linux/pci.h | 4 ++++ sys/compat/linuxkpi/common/src/linux_pci.c | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index 9c6a52aab83f..9457599d31d3 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -362,6 +362,8 @@ bool pci_device_is_present(struct pci_dev *pdev); int linuxkpi_pcim_enable_device(struct pci_dev *pdev); void __iomem **linuxkpi_pcim_iomap_table(struct pci_dev *pdev); +void *linuxkpi_pci_iomap_range(struct pci_dev *pdev, int mmio_bar, + unsigned long mmio_off, unsigned long mmio_size); void *linuxkpi_pci_iomap(struct pci_dev *pdev, int mmio_bar, int mmio_size); void linuxkpi_pci_iounmap(struct pci_dev *pdev, void *res); int linuxkpi_pcim_iomap_regions(struct pci_dev *pdev, uint32_t mask, @@ -774,6 +776,8 @@ static inline void pci_disable_sriov(struct pci_dev *dev) { } +#define pci_iomap_range(pdev, mmio_bar, mmio_off, mmio_size) \ + linuxkpi_pci_iomap_range(pdev, mmio_bar, mmio_off, mmio_size) #define pci_iomap(pdev, mmio_bar, mmio_size) \ linuxkpi_pci_iomap(pdev, mmio_bar, mmio_size) #define pci_iounmap(pdev, res) linuxkpi_pci_iounmap(pdev, res) diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index 51a3b0b2ebe1..3287a8a15ff5 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -755,7 +755,8 @@ _lkpi_pci_iomap(struct pci_dev *pdev, int bar, int mmio_size __unused) } void * -linuxkpi_pci_iomap(struct pci_dev *pdev, int mmio_bar, int mmio_size) +linuxkpi_pci_iomap_range(struct pci_dev *pdev, int mmio_bar, + unsigned long mmio_off, unsigned long mmio_size) { struct resource *res; @@ -765,7 +766,14 @@ linuxkpi_pci_iomap(struct pci_dev *pdev, int mmio_bar, int mmio_size) /* This is a FreeBSD extension so we can use bus_*(). */ if (pdev->want_iomap_res) return (res); - return ((void *)rman_get_bushandle(res)); + MPASS(mmio_off < rman_get_size(res)); + return ((void *)(rman_get_bushandle(res) + mmio_off)); +} + +void * +linuxkpi_pci_iomap(struct pci_dev *pdev, int mmio_bar, int mmio_size) +{ + return (linuxkpi_pci_iomap_range(pdev, mmio_bar, 0, mmio_size)); } void @@ -774,7 +782,9 @@ linuxkpi_pci_iounmap(struct pci_dev *pdev, void *res) struct pci_mmio_region *mmio, *p; TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) { - if (res != (void *)rman_get_bushandle(mmio->res)) + if ((bus_space_handle_t)res < rman_get_bushandle(mmio->res) || + (bus_space_handle_t)res >= rman_get_bushandle(mmio->res) + + rman_get_size(mmio->res)) continue; bus_release_resource(pdev->dev.bsddev, mmio->type, mmio->rid, mmio->res);