From owner-svn-src-head@freebsd.org Tue Jul 28 16:08:16 2020 Return-Path: Delivered-To: svn-src-head@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 E23E836DECE; Tue, 28 Jul 2020 16:08:16 +0000 (UTC) (envelope-from br@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BGM685gSGz4ZFy; Tue, 28 Jul 2020 16:08:16 +0000 (UTC) (envelope-from br@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 A69D6119A2; Tue, 28 Jul 2020 16:08:16 +0000 (UTC) (envelope-from br@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06SG8GdZ027555; Tue, 28 Jul 2020 16:08:16 GMT (envelope-from br@FreeBSD.org) Received: (from br@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06SG8FgP027547; Tue, 28 Jul 2020 16:08:15 GMT (envelope-from br@FreeBSD.org) Message-Id: <202007281608.06SG8FgP027547@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: br set sender to br@FreeBSD.org using -f From: Ruslan Bukin Date: Tue, 28 Jul 2020 16:08:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363650 - in head/sys: dev/iommu dev/ntb/ntb_hw x86/include x86/iommu x86/x86 X-SVN-Group: head X-SVN-Commit-Author: br X-SVN-Commit-Paths: in head/sys: dev/iommu dev/ntb/ntb_hw x86/include x86/iommu x86/x86 X-SVN-Commit-Revision: 363650 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2020 16:08:16 -0000 Author: br Date: Tue Jul 28 16:08:14 2020 New Revision: 363650 URL: https://svnweb.freebsd.org/changeset/base/363650 Log: o Move the buswide_ctxs bitmap to iommu_unit and rename related functions. o Rename bus_dma_dmar_load_ident() as well. Reviewed by: kib Sponsored by: DARPA/AFRL Differential Revision: https://reviews.freebsd.org/D25852 Modified: head/sys/dev/iommu/busdma_iommu.c head/sys/dev/iommu/iommu.h head/sys/dev/ntb/ntb_hw/ntb_hw_intel.c head/sys/dev/ntb/ntb_hw/ntb_hw_plx.c head/sys/x86/include/bus_dma.h head/sys/x86/iommu/intel_ctx.c head/sys/x86/iommu/intel_dmar.h head/sys/x86/iommu/intel_drv.c head/sys/x86/x86/busdma_machdep.c Modified: head/sys/dev/iommu/busdma_iommu.c ============================================================================== --- head/sys/dev/iommu/busdma_iommu.c Tue Jul 28 15:26:19 2020 (r363649) +++ head/sys/dev/iommu/busdma_iommu.c Tue Jul 28 16:08:14 2020 (r363650) @@ -299,7 +299,7 @@ acpi_iommu_get_dma_tag(device_t dev, device_t child) } bool -bus_dma_dmar_set_buswide(device_t dev) +bus_dma_iommu_set_buswide(device_t dev) { struct iommu_unit *unit; device_t parent; @@ -317,12 +317,12 @@ bus_dma_dmar_set_buswide(device_t dev) if (slot != 0 || func != 0) { if (bootverbose) { device_printf(dev, - "dmar%d pci%d:%d:%d requested buswide busdma\n", + "iommu%d pci%d:%d:%d requested buswide busdma\n", unit->unit, busno, slot, func); } return (false); } - dmar_set_buswide_ctx(unit, busno); + iommu_set_buswide_ctx(unit, busno); return (true); } @@ -987,7 +987,7 @@ iommu_fini_busdma(struct iommu_unit *unit) } int -bus_dma_dmar_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map1, +bus_dma_iommu_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map1, vm_paddr_t start, vm_size_t length, int flags) { struct bus_dma_tag_common *tc; Modified: head/sys/dev/iommu/iommu.h ============================================================================== --- head/sys/dev/iommu/iommu.h Tue Jul 28 15:26:19 2020 (r363649) +++ head/sys/dev/iommu/iommu.h Tue Jul 28 16:08:14 2020 (r363650) @@ -34,12 +34,14 @@ #ifndef _SYS_IOMMU_H_ #define _SYS_IOMMU_H_ +#include #include #include #include #include -#include +#include + /* Host or physical memory address, after translation. */ typedef uint64_t iommu_haddr_t; /* Guest or bus address, before translation. */ @@ -96,6 +98,14 @@ struct iommu_unit { struct task dmamap_load_task; TAILQ_HEAD(, bus_dmamap_iommu) delayed_maps; struct taskqueue *delayed_taskqueue; + + /* + * Bitmap of buses for which context must ignore slot:func, + * duplicating the page table pointer into all context table + * entries. This is a client-controlled quirk to support some + * NTBs. + */ + uint32_t buswide_ctxs[(PCI_BUSMAX + 1) / NBBY / sizeof(uint32_t)]; }; /* Modified: head/sys/dev/ntb/ntb_hw/ntb_hw_intel.c ============================================================================== --- head/sys/dev/ntb/ntb_hw/ntb_hw_intel.c Tue Jul 28 15:26:19 2020 (r363649) +++ head/sys/dev/ntb/ntb_hw/ntb_hw_intel.c Tue Jul 28 16:08:14 2020 (r363650) @@ -811,7 +811,7 @@ intel_ntb_map_pci_bars(struct ntb_softc *ntb) device_printf(ntb->device, "Unable to create BAR0 map\n"); return (ENOMEM); } - if (bus_dma_dmar_load_ident(ntb->bar0_dma_tag, ntb->bar0_dma_map, + if (bus_dma_iommu_load_ident(ntb->bar0_dma_tag, ntb->bar0_dma_map, bar->pbase, bar->size, 0)) { device_printf(ntb->device, "Unable to load BAR0 map\n"); return (ENOMEM); Modified: head/sys/dev/ntb/ntb_hw/ntb_hw_plx.c ============================================================================== --- head/sys/dev/ntb/ntb_hw/ntb_hw_plx.c Tue Jul 28 15:26:19 2020 (r363649) +++ head/sys/dev/ntb/ntb_hw/ntb_hw_plx.c Tue Jul 28 16:08:14 2020 (r363650) @@ -343,7 +343,7 @@ ntb_plx_attach(device_t dev) * The device occupies whole bus. In translated TLP slot field * keeps LUT index (original bus/slot), function is passed through. */ - bus_dma_dmar_set_buswide(dev); + bus_dma_iommu_set_buswide(dev); /* Identify chip port we are connected to. */ val = bus_read_4(sc->conf_res, 0x360); Modified: head/sys/x86/include/bus_dma.h ============================================================================== --- head/sys/x86/include/bus_dma.h Tue Jul 28 15:26:19 2020 (r363649) +++ head/sys/x86/include/bus_dma.h Tue Jul 28 16:08:14 2020 (r363650) @@ -192,8 +192,8 @@ _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t } #ifdef _KERNEL -bool bus_dma_dmar_set_buswide(device_t dev); -int bus_dma_dmar_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map, +bool bus_dma_iommu_set_buswide(device_t dev); +int bus_dma_iommu_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t start, vm_size_t length, int flags); #endif Modified: head/sys/x86/iommu/intel_ctx.c ============================================================================== --- head/sys/x86/iommu/intel_ctx.c Tue Jul 28 15:26:19 2020 (r363649) +++ head/sys/x86/iommu/intel_ctx.c Tue Jul 28 16:08:14 2020 (r363650) @@ -196,7 +196,7 @@ ctx_id_entry_init(struct dmar_ctx *ctx, dmar_ctx_entry IOMMU_PGF_NOALLOC); } - if (dmar_is_buswide_ctx(unit, busno)) { + if (iommu_is_buswide_ctx((struct iommu_unit *)unit, busno)) { MPASS(!move); for (i = 0; i <= PCI_BUSMAX; i++) { ctx_id_entry_init_one(&ctxp[i], domain, ctx_root); @@ -464,6 +464,7 @@ dmar_get_ctx_for_dev1(struct dmar_unit *dmar, device_t { struct dmar_domain *domain, *domain1; struct dmar_ctx *ctx, *ctx1; + struct iommu_unit *unit; dmar_ctx_entry_t *ctxp; struct sf_buf *sf; int bus, slot, func, error; @@ -480,9 +481,10 @@ dmar_get_ctx_for_dev1(struct dmar_unit *dmar, device_t } enable = false; TD_PREP_PINNED_ASSERT; + unit = (struct iommu_unit *)dmar; DMAR_LOCK(dmar); - KASSERT(!dmar_is_buswide_ctx(dmar, bus) || (slot == 0 && func == 0), - ("dmar%d pci%d:%d:%d get_ctx for buswide", dmar->iommu.unit, bus, + KASSERT(!iommu_is_buswide_ctx(unit, bus) || (slot == 0 && func == 0), + ("iommu%d pci%d:%d:%d get_ctx for buswide", dmar->iommu.unit, bus, slot, func)); ctx = dmar_find_ctx_locked(dmar, rid); error = 0; Modified: head/sys/x86/iommu/intel_dmar.h ============================================================================== --- head/sys/x86/iommu/intel_dmar.h Tue Jul 28 15:26:19 2020 (r363649) +++ head/sys/x86/iommu/intel_dmar.h Tue Jul 28 16:08:14 2020 (r363650) @@ -167,15 +167,6 @@ struct dmar_unit { struct iommu_map_entries_tailq tlb_flush_entries; struct task qi_task; struct taskqueue *qi_taskqueue; - - /* - * Bitmap of buses for which context must ignore slot:func, - * duplicating the page table pointer into all context table - * entries. This is a client-controlled quirk to support some - * NTBs. - */ - uint32_t buswide_ctxs[(PCI_BUSMAX + 1) / NBBY / sizeof(uint32_t)]; - }; #define DMAR_LOCK(dmar) mtx_lock(&(dmar)->iommu.lock) @@ -290,8 +281,8 @@ void dmar_quirks_pre_use(struct iommu_unit *dmar); int dmar_init_irt(struct dmar_unit *unit); void dmar_fini_irt(struct dmar_unit *unit); -void dmar_set_buswide_ctx(struct iommu_unit *unit, u_int busno); -bool dmar_is_buswide_ctx(struct dmar_unit *unit, u_int busno); +void iommu_set_buswide_ctx(struct iommu_unit *unit, u_int busno); +bool iommu_is_buswide_ctx(struct iommu_unit *unit, u_int busno); extern iommu_haddr_t dmar_high; extern int haw; Modified: head/sys/x86/iommu/intel_drv.c ============================================================================== --- head/sys/x86/iommu/intel_drv.c Tue Jul 28 15:26:19 2020 (r363649) +++ head/sys/x86/iommu/intel_drv.c Tue Jul 28 16:08:14 2020 (r363650) @@ -593,21 +593,18 @@ DRIVER_MODULE(dmar, acpi, dmar_driver, dmar_devclass, MODULE_DEPEND(dmar, acpi, 1, 1, 1); void -dmar_set_buswide_ctx(struct iommu_unit *unit, u_int busno) +iommu_set_buswide_ctx(struct iommu_unit *unit, u_int busno) { - struct dmar_unit *dmar; - dmar = (struct dmar_unit *)unit; - MPASS(busno <= PCI_BUSMAX); - DMAR_LOCK(dmar); - dmar->buswide_ctxs[busno / NBBY / sizeof(uint32_t)] |= + IOMMU_LOCK(unit); + unit->buswide_ctxs[busno / NBBY / sizeof(uint32_t)] |= 1 << (busno % (NBBY * sizeof(uint32_t))); - DMAR_UNLOCK(dmar); + IOMMU_UNLOCK(unit); } bool -dmar_is_buswide_ctx(struct dmar_unit *unit, u_int busno) +iommu_is_buswide_ctx(struct iommu_unit *unit, u_int busno) { MPASS(busno <= PCI_BUSMAX); Modified: head/sys/x86/x86/busdma_machdep.c ============================================================================== --- head/sys/x86/x86/busdma_machdep.c Tue Jul 28 15:26:19 2020 (r363649) +++ head/sys/x86/x86/busdma_machdep.c Tue Jul 28 16:08:14 2020 (r363650) @@ -301,13 +301,13 @@ bus_dma_tag_destroy(bus_dma_tag_t dmat) #ifndef ACPI_DMAR bool -bus_dma_dmar_set_buswide(device_t dev) +bus_dma_iommu_set_buswide(device_t dev) { return (false); } int -bus_dma_dmar_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map, +bus_dma_iommu_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t start, vm_size_t length, int flags) { return (0);