From owner-svn-src-all@freebsd.org Thu May 7 17:00:52 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 30FBC2DE388; Thu, 7 May 2020 17:00:52 +0000 (UTC) (envelope-from manu@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49J08h0c3zz4Q4F; Thu, 7 May 2020 17:00:52 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0EA171C455; Thu, 7 May 2020 17:00:52 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 047H0pab034344; Thu, 7 May 2020 17:00:51 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 047H0pEl034066; Thu, 7 May 2020 17:00:51 GMT (envelope-from manu@FreeBSD.org) Message-Id: <202005071700.047H0pEl034066@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Thu, 7 May 2020 17:00:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360787 - in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: head X-SVN-Commit-Author: manu X-SVN-Commit-Paths: in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Commit-Revision: 360787 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 May 2020 17:00:52 -0000 Author: manu Date: Thu May 7 17:00:51 2020 New Revision: 360787 URL: https://svnweb.freebsd.org/changeset/base/360787 Log: linuxkpi: Add pci_iomap and pci_iounmap Those function are use to map/unmap io region of a pci device. Different resource can be mapped depending on the bar so use a tailq to store them all. Sponsored-by: The FreeBSD Foundation Reviewed by: emaste, hselasky Differential Revision: https://reviews.freebsd.org/D24696 Modified: head/sys/compat/linuxkpi/common/include/linux/pci.h head/sys/compat/linuxkpi/common/src/linux_pci.c Modified: head/sys/compat/linuxkpi/common/include/linux/pci.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/pci.h Thu May 7 16:56:18 2020 (r360786) +++ head/sys/compat/linuxkpi/common/include/linux/pci.h Thu May 7 17:00:51 2020 (r360787) @@ -222,6 +222,13 @@ extern spinlock_t pci_lock; #define __devexit_p(x) x +struct pci_mmio_region { + TAILQ_ENTRY(pci_mmio_region) next; + struct resource *res; + int rid; + int type; +}; + struct pci_dev { struct device dev; struct list_head links; @@ -236,6 +243,8 @@ struct pci_dev { uint32_t class; uint8_t revision; bool msi_enabled; + + TAILQ_HEAD(, pci_mmio_region) mmio; }; static inline struct resource_list_entry * @@ -657,6 +666,41 @@ static inline int pci_enable_sriov(struct pci_dev *dev } static inline void pci_disable_sriov(struct pci_dev *dev) { +} + +static inline void * +pci_iomap(struct pci_dev *dev, int mmio_bar, int mmio_size __unused) +{ + struct pci_mmio_region *mmio; + + mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO); + mmio->rid = PCIR_BAR(mmio_bar); + mmio->type = pci_resource_type(dev, mmio_bar); + mmio->res = bus_alloc_resource_any(dev->dev.bsddev, mmio->type, + &mmio->rid, RF_ACTIVE); + if (mmio->res == NULL) { + free(mmio, M_DEVBUF); + return (NULL); + } + TAILQ_INSERT_TAIL(&dev->mmio, mmio, next); + + return ((void *)rman_get_bushandle(mmio->res)); +} + +static inline void +pci_iounmap(struct pci_dev *dev, void *res) +{ + struct pci_mmio_region *mmio, *p; + + TAILQ_FOREACH_SAFE(mmio, &dev->mmio, next, p) { + if (res != (void *)rman_get_bushandle(mmio->res)) + continue; + bus_release_resource(dev->dev.bsddev, + mmio->type, mmio->rid, mmio->res); + TAILQ_REMOVE(&dev->mmio, mmio, next); + free(mmio, M_DEVBUF); + return; + } } #define DEFINE_PCI_DEVICE_TABLE(_table) \ Modified: head/sys/compat/linuxkpi/common/src/linux_pci.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_pci.c Thu May 7 16:56:18 2020 (r360786) +++ head/sys/compat/linuxkpi/common/src/linux_pci.c Thu May 7 17:00:51 2020 (r360787) @@ -271,6 +271,7 @@ linux_pci_attach_device(device_t dev, struct pci_drive if (error) goto out_dma_init; + TAILQ_INIT(&pdev->mmio); pbus = malloc(sizeof(*pbus), M_DEVBUF, M_WAITOK | M_ZERO); pbus->self = pdev; pbus->number = pci_get_bus(dev);