From nobody Wed Apr 06 17:46:09 2022 X-Original-To: dev-commits-src-branches@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 34EEE1AA63E7; Wed, 6 Apr 2022 17:46:10 +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 4KYX4K6hwtz3DHD; Wed, 6 Apr 2022 17:46:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649267170; 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=KzjSw1kVwwtxxNtFZ86jWqmtBpBacCrJO+wt2gRgmjs=; b=W+Rq80z6/sekSqy6g2ocLq53X/wgTXk8ZHiHte073kFVhrCSpq5M8+xMvcehjPIBD7Hj2d ZCcmCkO8+XJemBCGoaH2jt0hbfZFiAme9UsB3fVi236STiwcICusX9wmvoGhOhgYg8x+ea VvV1MMAnu2rUSWlfyjjBvCHwl5itj7NHxYCHBwMm/uAOihwbseyyiDj3q00e0YJWV6VIra jN7ofXVnMWKbwiaAa7p7q4d2NHU90YN39AH0g8iLjl8fJsJaK9/GMhkhKEwEipTS58RjQ1 Bth1B2n6nIwgCu0w17wVQxn+vD5/vR3rGrB5sZ4WouutL5U51B9BEr8RYSEFug== 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 2BD291F96B; Wed, 6 Apr 2022 17:46:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 236Hk9DM022711; Wed, 6 Apr 2022 17:46:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 236Hk9qI022710; Wed, 6 Apr 2022 17:46:09 GMT (envelope-from git) Date: Wed, 6 Apr 2022 17:46:09 GMT Message-Id: <202204061746.236Hk9qI022710@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 20f0a3ac5be4 - releng/13.1 - linuxkpi: Move pci_request_region and _lkpi_pci_iomap into .c List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.1 X-Git-Reftype: branch X-Git-Commit: 20f0a3ac5be415581e449335576c40090cac76cb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649267170; 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=KzjSw1kVwwtxxNtFZ86jWqmtBpBacCrJO+wt2gRgmjs=; b=oYN0mxHDMmB0OEIMPXfLmLNb7tQ2+VmYcx1yHLD2f+ZfXh0K2jVTaUvzIrAg5FgZJMezVv jhL+H1YTQlrYguVkslDwfkoDUpYIen+DhO1vs/OY442/AQWKNMIXZUoxAVlkoL0DMyWVmX eFa0o8CX439Xy5ScskHtRT+PS8AOA6iL32QrxXtIbo2HLXLRiQYEpWWK8gnTVu7Li/qThv bEbqw24sqEr6N+c4Xa4vGh1Ro8RwLGCZaoZxDiePKzRgm1wVeqsfli3GFLKIIs14eaH+XK /JDceKJ4yobXYW/Z9oz86hvkwu/tDWsHx6Cf0E/NRGxrWSG9w2F4mqfKoffQbA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649267170; a=rsa-sha256; cv=none; b=jnKqKlDStFAkZas2ZVcnOMXa6BypuVbeqK54hOGcCY/4Pcrnvcd2QiNbfNgxFDxw9c88Ek WO2/f5wmOALy75iZzzBlHhI07CK2aGequK7sG1xS0B9RSHYvlkeexAEKBQXMpU7vpHfe8K 47FWzFhdq7DdVWPI7imyDwnbPo3auq0I/dAk+EnNOn7Q1sIfQbeamavdIWW80oI8INuX3l n6AQSD8/kWObLeyTmLbIhUNiz+8E491KjN4qtd3Eb3v7An8vUFdGbnrayIOTUsC1o//i+5 YBfSQrTX/vkUoMP4UNhsQ8vRtakB6r7g/3QaO1yZp+RYRssCq2PRn2LeMa7HPA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.1 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=20f0a3ac5be415581e449335576c40090cac76cb commit 20f0a3ac5be415581e449335576c40090cac76cb Author: Warner Losh AuthorDate: 2022-04-05 05:06:14 +0000 Commit: Warner Losh CommitDate: 2022-04-06 17:45:34 +0000 linuxkpi: Move pci_request_region and _lkpi_pci_iomap into .c Both pci_request_region and _lkpi_pci_iomap encode the size of struct pci_mmio_region into their code. Move from .h to .c files to move that knowledge from the client drivers into the linuxkpi module. Approved by: re@ (gjb) Sponsored by: Netflix Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D34773 (cherry picked from commit 1cdb25340f8ee5dd145b0dc370cbab1bd7bdca65) (cherry picked from commit 4859994c42950600b57e9d2259bd027562eefbe3) --- sys/compat/linuxkpi/common/include/linux/pci.h | 88 ++------------------------ sys/compat/linuxkpi/common/src/linux_pci.c | 84 ++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 84 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index f655c8f5ccdf..5e4cc1901973 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -338,10 +338,13 @@ struct pcim_iomap_devres { struct resource *res_table[PCIR_MAX_BAR_0 + 1]; }; +int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name); + /* Internal helper function(s). */ struct pci_dev *lkpinew_pci_dev(device_t); struct pci_devres *lkpi_pci_devres_get_alloc(struct pci_dev *pdev); void lkpi_pci_devres_release(struct device *, void *); +struct resource *_lkpi_pci_iomap(struct pci_dev *pdev, int bar, int mmio_size); void lkpi_pcim_iomap_table_release(struct device *, void *); static inline int @@ -553,50 +556,6 @@ lkpi_pci_devres_find(struct pci_dev *pdev) return (lkpi_pci_devres_get_alloc(pdev)); } -static inline int -pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) -{ - struct resource *res; - struct pci_devres *dr; - struct pci_mmio_region *mmio; - int rid; - int type; - - type = pci_resource_type(pdev, bar); - if (type < 0) - return (-ENODEV); - rid = PCIR_BAR(bar); - res = bus_alloc_resource_any(pdev->dev.bsddev, type, &rid, - RF_ACTIVE|RF_SHAREABLE); - if (res == NULL) { - device_printf(pdev->dev.bsddev, "%s: failed to alloc " - "bar %d type %d rid %d\n", - __func__, bar, type, PCIR_BAR(bar)); - return (-ENODEV); - } - - /* - * It seems there is an implicit devres tracking on these if the device - * is managed; otherwise the resources are not automatiaclly freed on - * FreeBSD/LinuxKPI tough they should be/are expected to be by Linux - * drivers. - */ - dr = lkpi_pci_devres_find(pdev); - if (dr != NULL) { - dr->region_mask |= (1 << bar); - dr->region_table[bar] = res; - } - - /* Even if the device is not managed we need to track it for iomap. */ - mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO); - mmio->rid = PCIR_BAR(bar); - mmio->type = type; - mmio->res = res; - TAILQ_INSERT_TAIL(&pdev->mmio, mmio, next); - - return (0); -} - static inline void pci_release_region(struct pci_dev *pdev, int bar) { @@ -970,48 +929,9 @@ static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn) { return -ENODEV; } -static inline void pci_disable_sriov(struct pci_dev *dev) -{ -} -static inline struct resource * -_lkpi_pci_iomap(struct pci_dev *pdev, int bar, int mmio_size __unused) +static inline void pci_disable_sriov(struct pci_dev *dev) { - struct pci_mmio_region *mmio, *p; - int type; - - type = pci_resource_type(pdev, bar); - if (type < 0) { - device_printf(pdev->dev.bsddev, "%s: bar %d type %d\n", - __func__, bar, type); - return (NULL); - } - - /* - * Check for duplicate mappings. - * This can happen if a driver calls pci_request_region() first. - */ - TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) { - if (mmio->type == type && mmio->rid == PCIR_BAR(bar)) { - return (mmio->res); - } - } - - mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO); - mmio->rid = PCIR_BAR(bar); - mmio->type = type; - mmio->res = bus_alloc_resource_any(pdev->dev.bsddev, mmio->type, - &mmio->rid, RF_ACTIVE|RF_SHAREABLE); - if (mmio->res == NULL) { - device_printf(pdev->dev.bsddev, "%s: failed to alloc " - "bar %d type %d rid %d\n", - __func__, bar, type, PCIR_BAR(bar)); - free(mmio, M_DEVBUF); - return (NULL); - } - TAILQ_INSERT_TAIL(&pdev->mmio, mmio, next); - - return (mmio->res); } static inline void * diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index b396b512e176..fb976346c198 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -747,6 +747,90 @@ pci_resource_len(struct pci_dev *pdev, int bar) return (rle->count); } +int +pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) +{ + struct resource *res; + struct pci_devres *dr; + struct pci_mmio_region *mmio; + int rid; + int type; + + type = pci_resource_type(pdev, bar); + if (type < 0) + return (-ENODEV); + rid = PCIR_BAR(bar); + res = bus_alloc_resource_any(pdev->dev.bsddev, type, &rid, + RF_ACTIVE|RF_SHAREABLE); + if (res == NULL) { + device_printf(pdev->dev.bsddev, "%s: failed to alloc " + "bar %d type %d rid %d\n", + __func__, bar, type, PCIR_BAR(bar)); + return (-ENODEV); + } + + /* + * It seems there is an implicit devres tracking on these if the device + * is managed; otherwise the resources are not automatiaclly freed on + * FreeBSD/LinuxKPI tough they should be/are expected to be by Linux + * drivers. + */ + dr = lkpi_pci_devres_find(pdev); + if (dr != NULL) { + dr->region_mask |= (1 << bar); + dr->region_table[bar] = res; + } + + /* Even if the device is not managed we need to track it for iomap. */ + mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO); + mmio->rid = PCIR_BAR(bar); + mmio->type = type; + mmio->res = res; + TAILQ_INSERT_TAIL(&pdev->mmio, mmio, next); + + return (0); +} + +struct resource * +_lkpi_pci_iomap(struct pci_dev *pdev, int bar, int mmio_size __unused) +{ + struct pci_mmio_region *mmio, *p; + int type; + + type = pci_resource_type(pdev, bar); + if (type < 0) { + device_printf(pdev->dev.bsddev, "%s: bar %d type %d\n", + __func__, bar, type); + return (NULL); + } + + /* + * Check for duplicate mappings. + * This can happen if a driver calls pci_request_region() first. + */ + TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) { + if (mmio->type == type && mmio->rid == PCIR_BAR(bar)) { + return (mmio->res); + } + } + + mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO); + mmio->rid = PCIR_BAR(bar); + mmio->type = type; + mmio->res = bus_alloc_resource_any(pdev->dev.bsddev, mmio->type, + &mmio->rid, RF_ACTIVE|RF_SHAREABLE); + if (mmio->res == NULL) { + device_printf(pdev->dev.bsddev, "%s: failed to alloc " + "bar %d type %d rid %d\n", + __func__, bar, type, PCIR_BAR(bar)); + free(mmio, M_DEVBUF); + return (NULL); + } + TAILQ_INSERT_TAIL(&pdev->mmio, mmio, next); + + return (mmio->res); +} + int linux_pci_register_drm_driver(struct pci_driver *pdrv) {