From nobody Sun Oct 11 13:51:32 2026 X-Original-To: dev-commits-src-main@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 4j2hpX5hlMz6vrRv for ; Sun, 11 Oct 2026 13:51:32 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4j2hpX4fgQz4nsX for ; Sun, 11 Oct 2026 13:51:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791726692; 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=s2cEmi8KjSyrxCvCTMOK/Vew90Yg56sPipQHomtBMsU=; b=PMPWxLoNaCH+9o7HK4hnOiznViJC4guC2a9TgQBFt13ay9Moul+1nO1e0xLx03hiyWgQjs Pn2KL/HwCglNwRcncgsa0rXDM62O82AgTsudBLNkKPfb39b9z4MGZiU2JF0Gx8MAkCWqpC 2RFf8+m7LZXy9MZroboXnveO2/l/9zxN7DSG9cQ2JivjbvElL/XQyevxavXBUI9/UFsm/C O9yTLQyq3itEGJ7snYJkmhHrMebcnYujblBmNjVxrKLp5J+vBqZG7zVrlHG0TWPTawry6Z 6YYpP5ZRhrQ0ijLBkc1IMsSOetvF9kxNifZodnnbNpfkzw/Uy+AtfC+9M9CBzQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1791726692; b=kg4EX3rZ3JZNzke0pI8ECZMAKlONJh7XG0wDj+2/0iEQkHusgr1MlWIeMgCvniVue8w7B1 AohzJtZ18W1dRFr84Dz6U4UiytJeHIFUsprAWLoHP+09a7MNF62FgkcXXZ+d24JwoItafd CVAgya/DL+CNOwXBB1LzzePDGiI98u+NJY5t2DYCtngNG1vfrWWw+AZz7/bKWHmxzaWbXx 94GLlzQAHjnrr/+VtBJPCNmYz7GrGnZsadmjYoQtsDdXfjZ9aFVx4cJXDq8W8Un0ClI4RO 2Bfmd4mmdmLAV099orS2g2VJgf1vhRkGbH8fzNYNaa66x2TEQdCeircY2++Kcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1791726692; 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=s2cEmi8KjSyrxCvCTMOK/Vew90Yg56sPipQHomtBMsU=; b=fHu3Frd1PmvX8bsM1+IJ3RLhMagQTiSOkXxQYpH0/9bjukiBfnoyuXZGDy2C3sDhoiwnT6 luqpvxE8EjYt0f6qJUoags58IRN1QU2JQt+dSA8wt8J+5ivBYkoPonAk1oPbo4SCMCd3r1 mdF4ieVpvM/ALJq8anN5dhUP7hVp8X3yzPxifSZCzr04qTUAMDVV4F/RWIF2YRxlp1n77p bgWd2tJ58OxgcZhJlRh8CG6K6FKUL6uBHQkyW+QrxVH07OflSEDCsxyd3fzQ8WzIy8xlez Hg+2infWOOYrOahIg87hNvioeMQumjYhhksSlROTVdOoZ09pTT5JfWBfqNiPhw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j2hpX3gZhzl6f for ; Sun, 11 Oct 2026 13:51:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 36b5d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sun, 11 Oct 2026 13:51:32 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bjoern A. Zeeb Subject: git: e2bef7e30aa7 - main - LinuxKPI: pci: make internal variables file local List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: Commit messages for the main branch of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e2bef7e30aa74ed3d46a5ce5d171993e9e2c14b8 Auto-Submitted: auto-generated Date: Sun, 11 Oct 2026 13:51:32 +0000 Message-Id: <6acb9464.36b5d.2dbe9c15@gitrepo.freebsd.org> The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=e2bef7e30aa74ed3d46a5ce5d171993e9e2c14b8 commit e2bef7e30aa74ed3d46a5ce5d171993e9e2c14b8 Author: Bjoern A. Zeeb AuthorDate: 2026-06-03 04:32:45 +0000 Commit: Bjoern A. Zeeb CommitDate: 2026-10-11 13:51:03 +0000 LinuxKPI: pci: make internal variables file local The only reason the internal lists and lock are shared seems to be because the SYSINIT code was in linux_compat.c. Migrate the three variables (pci_drivers, pci_devices, and pci_lock) to linux_pci.c and make them file local. While doing so adjust a few things: (a) mark the various sections of the linux_pci.c file as we add new SYSINIT code to the middle of the file. The file currently really contains three parts. (b) rename the variables by adding a lkpi_ prefix indicating that they are part of our internal code and not part of the public KPI, and to clearly distinguish them from any native PCI code upon which we call as well. (c) factor the locking code out into macros as we have often done in various parts of the kernel to make the lock itself more opaque. No functional changes intended. Sponsored by: The FreBSD Foundation MFC after: 3 days Reviewed by: emaste, dumbbell (before rebase) Differential Revision: https://reviews.freebsd.org/D57432 --- sys/compat/linuxkpi/common/include/linux/pci.h | 4 -- sys/compat/linuxkpi/common/src/linux_compat.c | 7 -- sys/compat/linuxkpi/common/src/linux_pci.c | 96 ++++++++++++++++++-------- 3 files changed, 68 insertions(+), 39 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/pci.h b/sys/compat/linuxkpi/common/include/linux/pci.h index 3c90e3d9ea9e..b46bb99612c8 100644 --- a/sys/compat/linuxkpi/common/include/linux/pci.h +++ b/sys/compat/linuxkpi/common/include/linux/pci.h @@ -295,10 +295,6 @@ struct pci_bus { int number; }; -extern struct list_head pci_drivers; -extern struct list_head pci_devices; -extern spinlock_t pci_lock; - #define __devexit_p(x) x #define module_pci_driver(_drv) \ diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index 24655eb0341d..08c7cfdac8ed 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -159,9 +159,6 @@ static cpumask_t *static_single_cpu_mask_lcs; struct kobject linux_class_root; struct device linux_root_device; struct class linux_class_misc; -struct list_head pci_drivers; -struct list_head pci_devices; -spinlock_t pci_lock; struct uts_namespace init_uts_ns; unsigned long linux_timer_hz_mask; @@ -2969,9 +2966,6 @@ linux_compat_init(void *arg) linux_root_device.bsddev = root_bus; linux_class_misc.name = "misc"; class_register(&linux_class_misc); - INIT_LIST_HEAD(&pci_drivers); - INIT_LIST_HEAD(&pci_devices); - spin_lock_init(&pci_lock); init_waitqueue_head(&linux_bit_waitq); init_waitqueue_head(&linux_var_waitq); @@ -3082,7 +3076,6 @@ linux_compat_uninit(void *arg) free(__cpu_data, M_KMALLOC); #endif - spin_lock_destroy(&pci_lock); rw_destroy(&linux_vma_lock); } SYSUNINIT(linux_compat, SI_SUB_DRIVERS, SI_ORDER_SECOND, linux_compat_uninit, NULL); diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index 2c442b3d8f77..6b598eb82d76 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -29,12 +29,10 @@ */ /* - * We have two ways to create a pci_dev (pdev): - * (1) coming from the device_attach DEVMETHOD, and - * (2) from manual creation via lkpinew_pci_dev(), in which case - * we have no driver (pdev->pdrv). - * - * Only devices from (1) end up on our LinuxKPI global pci_devices list. + * This file contains multiple parts: + * (1) PCI + * (2) DMA + * (3) Backlight */ #include @@ -85,6 +83,17 @@ #include "backlight_if.h" #include "pcib_if.h" +/* -------------------------------------------------------------------------- */ +/* + * For PCI: + * we have two ways to create a pci_dev (pdev): + * (1) coming from the device_attach DEVMETHOD, and + * (2) from manual creation via lkpinew_pci_dev(), in which case + * we have no driver (pdev->pdrv). + * + * Only devices from (1) end up on our LinuxKPI global lkpi_pci_devices list. + */ + /* Undef the linux function macro defined in linux/pci.h */ #undef pci_get_class @@ -110,6 +119,15 @@ static int linux_backlight_update_status(device_t dev, struct backlight_props *p static int linux_backlight_get_info(device_t dev, struct backlight_info *info); static void lkpi_pcim_iomap_table_release(struct device *, void *); +static struct list_head lkpi_pci_drivers; +static struct list_head lkpi_pci_devices; +static spinlock_t lkpi_pci_lock; + +#define LKPI_PCI_LOCK_INIT() spin_lock_init(&lkpi_pci_lock) +#define LKPI_PCI_LOCK_DESTROY() spin_lock_destroy(&lkpi_pci_lock) +#define LKPI_PCI_LOCK() spin_lock(&lkpi_pci_lock) +#define LKPI_PCI_UNLOCK() spin_unlock(&lkpi_pci_lock) + static device_method_t pci_methods[] = { DEVMETHOD(device_probe, linux_pci_probe), DEVMETHOD(device_attach, linux_pci_attach), @@ -299,20 +317,20 @@ linux_pci_find(device_t dev, const struct pci_device_id **idp) subvendor = pci_get_subvendor(dev); subdevice = pci_get_subdevice(dev); - spin_lock(&pci_lock); - list_for_each_entry(pdrv, &pci_drivers, node) { + LKPI_PCI_LOCK(); + list_for_each_entry(pdrv, &lkpi_pci_drivers, node) { for (id = pdrv->id_table; id->vendor != 0; id++) { if (vendor == id->vendor && (PCI_ANY_ID == id->device || device == id->device) && (PCI_ANY_ID == id->subvendor || subvendor == id->subvendor) && (PCI_ANY_ID == id->subdevice || subdevice == id->subdevice)) { *idp = id; - spin_unlock(&pci_lock); + LKPI_PCI_UNLOCK(); return (pdrv); } } } - spin_unlock(&pci_lock); + LKPI_PCI_UNLOCK(); return (NULL); } @@ -323,8 +341,8 @@ lkpi_pci_get_device(uint32_t vendor, uint32_t device, struct pci_dev *odev) odev0 = odev; found = NULL; - spin_lock(&pci_lock); - list_for_each_entry(pdev, &pci_devices, links) { + LKPI_PCI_LOCK(); + list_for_each_entry(pdev, &lkpi_pci_devices, links) { /* Walk until we find odev. */ if (odev != NULL) { if (pdev == odev) @@ -339,7 +357,7 @@ lkpi_pci_get_device(uint32_t vendor, uint32_t device, struct pci_dev *odev) } } pci_dev_get(found); - spin_unlock(&pci_lock); + LKPI_PCI_UNLOCK(); pci_dev_put(odev0); return (found); @@ -429,9 +447,9 @@ lkpi_pci_dev_release(struct device *dev) /* Clear the hierarchy recursively to root. */ lkpi_pci_dev_bus_release(pdev); - spin_lock(&pci_lock); + LKPI_PCI_LOCK(); list_del(&pdev->links); - spin_unlock(&pci_lock); + LKPI_PCI_UNLOCK(); linux_pdev_dma_uninit(pdev); @@ -723,9 +741,9 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv, if (error) goto out_err; - spin_lock(&pci_lock); - list_add(&pdev->links, &pci_devices); - spin_unlock(&pci_lock); + LKPI_PCI_LOCK(); + list_add(&pdev->links, &lkpi_pci_devices); + LKPI_PCI_UNLOCK(); /* * Create the hierarchy now as we cannot on demand later. @@ -1251,9 +1269,9 @@ _linux_pci_register_driver(struct pci_driver *pdrv, devclass_t dc) int error; linux_set_current(curthread); - spin_lock(&pci_lock); - list_add(&pdrv->node, &pci_drivers); - spin_unlock(&pci_lock); + LKPI_PCI_LOCK(); + list_add(&pdrv->node, &lkpi_pci_drivers); + LKPI_PCI_UNLOCK(); if (pdrv->bsddriver.name == NULL) pdrv->bsddriver.name = pdrv->name; pdrv->bsddriver.methods = pci_methods; @@ -1297,15 +1315,15 @@ lkpi_pci_find_irq_dev(unsigned int irq) struct device *found; found = NULL; - spin_lock(&pci_lock); - list_for_each_entry(pdev, &pci_devices, links) { + LKPI_PCI_LOCK(); + list_for_each_entry(pdev, &lkpi_pci_devices, links) { if (irq == pdev->dev.irq || (irq >= pdev->dev.irq_start && irq < pdev->dev.irq_end)) { found = &pdev->dev; break; } } - spin_unlock(&pci_lock); + LKPI_PCI_UNLOCK(); return (found); } @@ -1497,9 +1515,9 @@ linux_pci_unregister_driver(struct pci_driver *pdrv) bus = devclass_find(pdrv->isdrm ? "vgapci" : "pci"); - spin_lock(&pci_lock); + LKPI_PCI_LOCK(); list_del(&pdrv->node); - spin_unlock(&pci_lock); + LKPI_PCI_UNLOCK(); bus_topo_lock(); if (bus != NULL) devclass_delete_driver(bus, &pdrv->bsddriver); @@ -1513,9 +1531,9 @@ linux_pci_unregister_drm_driver(struct pci_driver *pdrv) bus = devclass_find("vgapci"); - spin_lock(&pci_lock); + LKPI_PCI_LOCK(); list_del(&pdrv->node); - spin_unlock(&pci_lock); + LKPI_PCI_UNLOCK(); bus_topo_lock(); if (bus != NULL) devclass_delete_driver(bus, &pdrv->bsddriver); @@ -1708,6 +1726,25 @@ linuxkpi_pci_unmap_rom(struct pci_dev *pdev, void *rom) vga_pci_unmap_bios(device_get_parent(dev), rom); } +static void +lkpi_pci_init(void *arg __unused) +{ + INIT_LIST_HEAD(&lkpi_pci_drivers); + INIT_LIST_HEAD(&lkpi_pci_devices); + LKPI_PCI_LOCK_INIT(); +} +SYSINIT(lkpi_pci_init, SI_SUB_DRIVERS, SI_ORDER_SECOND, lkpi_pci_init, NULL); + +static void +lkpi_pci_uninit(void *arg __unused) +{ + LKPI_PCI_LOCK_DESTROY(); +} +SYSUNINIT(lkpi_pci_uninit, SI_SUB_DRIVERS, SI_ORDER_SECOND, lkpi_pci_uninit, NULL); + +/* -------------------------------------------------------------------------- */ +/* DMA */ + CTASSERT(sizeof(dma_addr_t) <= sizeof(uint64_t)); struct linux_dma_obj { @@ -2397,6 +2434,9 @@ linux_dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t dma_addr) uma_zfree_arg(pool->pool_zone, obj, pool); } +/* -------------------------------------------------------------------------- */ +/* Backlight. */ + static int linux_backlight_get_status(device_t dev, struct backlight_props *props) {