From nobody Thu Oct 17 14:32:16 2024 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 4XTqzj2Rl6z5Z4YR; Thu, 17 Oct 2024 14:32:17 +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 4XTqzh6NnFz51Qk; Thu, 17 Oct 2024 14:32:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729175536; 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=UD9mlJJn8p04wb1bBbq74bARwd61v4nS0OQBUVb5IXo=; b=UE70wRswzhSsuWvKa9jOSVBNw3PfoshKRhrnJTtJH6y65RsPNcSgCEXjnsC4O56hzDwDn3 4cd6uqQ0Qig6wldoWmrRH0/TSqIIACGG5uEGPw6iODKr3RLcSFPK7GicgNapWLNeL0PUnP kfrAEda2g3mWNyrqt4PN6LS5S2quQoilkaa7lij1r1xce6wsUa+Qpd39X1MaB+FPGU3SDg fqqAOB9Iz1jtr108KaiL/V1sYBcnAG7PvRQTnkzsRLMQ/xzF5hYlKoAL3X+0Ao0Ye1L4Me 3kzzTNJ5aIlmdMJFnkw70DkeV27YPOtMftPfRwJYau7FitnGi70QWE+98XOfng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729175536; 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=UD9mlJJn8p04wb1bBbq74bARwd61v4nS0OQBUVb5IXo=; b=ZWsiMJjcO1i012IDIv4LT0XCRui3xGz034dNDrOUqFjAlmeiTwMzdWvSag8X+o3aD7OEIS VFCqVhxoy/nkdrbqeNrAETPdawIAA+XnXJcI1re1axKyGx4p3Qfv3irjPO4j3wUtb9mWR4 CtefnuvO91cW9rx8qyn62XUSwmCm//IvSUJBkz5MPRavHKsQeioESaQdQcutUdONkN7S2P UurVk1ABEOT2LpDReav5P/jtosLN9tJNeM2KJDYssxdj7dKxhuBii7eZBS8t/ge9tWfTac XSPosYvhoqvzBEkP9RwcKFecc1Z6uGj8NfuddJrMX6vjNVYcMA8DNf/QrI7sQQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729175536; a=rsa-sha256; cv=none; b=CPvGzOLp6hF+gNOxOs35rll0AWDJ/WuGMHEQLimRrSPQHfkQ3VCGiu4OLTeo6PoQlI2n+s 1HtwPv2ut/yjSIcjWUecB04HBqN6HsYuFlYderauupx/6JJg93Itg0Kqwo5y/HvuMYnR+v mvBnnQ1KwYTcPvqhqrKHaJ6HzpjffcWwkpZadM3HxuTluJzRGFliyWRH4PeeCD9fueeHZv KyrGW6ghD2HeaNOCcKH8uhXduT2VtDsB+y4+yGxFQaQRULRDWEPRACc6ip/v4Df1VGkW2M jqF+KO8YHTvOdhqteh96loixlWsOzyJi655dHxxSdpez0CKNeSmv3mmLIy9Nuw== 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 4XTqzh5RSXztXl; Thu, 17 Oct 2024 14:32:16 +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 49HEWGUX027327; Thu, 17 Oct 2024 14:32:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49HEWGEA027305; Thu, 17 Oct 2024 14:32:16 GMT (envelope-from git) Date: Thu, 17 Oct 2024 14:32:16 GMT Message-Id: <202410171432.49HEWGEA027305@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: b08d332da035 - main - devices: report iommu data for the device in the dev. sysctl tree List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b08d332da035e11bfc9373f2d08244cb3e10cda4 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=b08d332da035e11bfc9373f2d08244cb3e10cda4 commit b08d332da035e11bfc9373f2d08244cb3e10cda4 Author: Konstantin Belousov AuthorDate: 2024-10-12 22:54:33 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-17 14:31:50 +0000 devices: report iommu data for the device in the dev. sysctl tree Show the iommu unit' device name/unit which translates the device' requests, if any, as parsed out from the BIOS tables. Also show the rid value for the device. Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47098 --- sys/kern/subr_bus.c | 28 ++++++++++++++++++++++++++++ sys/sys/bus.h | 1 + sys/x86/iommu/intel_drv.c | 19 ++++++++++++++++--- sys/x86/iommu/iommu_utils.c | 13 +++++++++++++ sys/x86/iommu/x86_iommu.h | 1 + 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 26c476e9fef6..70e5e22854f3 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -29,6 +29,7 @@ #include #include "opt_bus.h" #include "opt_ddb.h" +#include "opt_iommu.h" #include #include @@ -60,6 +61,8 @@ #include #include +#include + #include SYSCTL_NODE(_hw, OID_AUTO, bus, CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, @@ -261,6 +264,7 @@ enum { DEVICE_SYSCTL_LOCATION, DEVICE_SYSCTL_PNPINFO, DEVICE_SYSCTL_PARENT, + DEVICE_SYSCTL_IOMMU, }; static int @@ -268,7 +272,10 @@ device_sysctl_handler(SYSCTL_HANDLER_ARGS) { struct sbuf sb; device_t dev = (device_t)arg1; + device_t iommu; int error; + uint16_t rid; + const char *c; sbuf_new_for_sysctl(&sb, NULL, 1024, req); sbuf_clear_flags(&sb, SBUF_INCLUDENUL); @@ -289,6 +296,22 @@ device_sysctl_handler(SYSCTL_HANDLER_ARGS) case DEVICE_SYSCTL_PARENT: sbuf_cat(&sb, dev->parent ? dev->parent->nameunit : ""); break; + case DEVICE_SYSCTL_IOMMU: + iommu = NULL; + error = device_get_prop(dev, DEV_PROP_NAME_IOMMU, + (void **)&iommu); + c = ""; + if (error == 0 && iommu != NULL) { + sbuf_printf(&sb, "unit=%s", device_get_nameunit(iommu)); + c = " "; + } + rid = 0; +#ifdef IOMMU + iommu_get_requester(dev, &rid); +#endif + if (rid != 0) + sbuf_printf(&sb, "%srid=%#x", c, rid); + break; default: error = EINVAL; goto out; @@ -338,6 +361,11 @@ device_sysctl_init(device_t dev) CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, DEVICE_SYSCTL_PARENT, device_sysctl_handler, "A", "parent device"); + SYSCTL_ADD_PROC(&dev->sysctl_ctx, SYSCTL_CHILDREN(dev->sysctl_tree), + OID_AUTO, "%iommu", + CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, + dev, DEVICE_SYSCTL_IOMMU, device_sysctl_handler, "A", + "iommu unit handling the device requests"); if (bus_get_domain(dev, &domain) == 0) SYSCTL_ADD_INT(&dev->sysctl_ctx, SYSCTL_CHILDREN(dev->sysctl_tree), OID_AUTO, "%domain", diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 49c5d62cebce..4f34990cd10f 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -924,6 +924,7 @@ device_location_cache_t *dev_wired_cache_init(void); void dev_wired_cache_fini(device_location_cache_t *dcp); bool dev_wired_cache_match(device_location_cache_t *dcp, device_t dev, const char *at); +#define DEV_PROP_NAME_IOMMU "iommu-unit" typedef void (*device_prop_dtr_t)(device_t dev, const char *name, void *val, void *dtr_ctx); int device_set_prop(device_t dev, const char *name, void *val, diff --git a/sys/x86/iommu/intel_drv.c b/sys/x86/iommu/intel_drv.c index ebc77879480b..f4a1ec06b721 100644 --- a/sys/x86/iommu/intel_drv.c +++ b/sys/x86/iommu/intel_drv.c @@ -757,6 +757,7 @@ dmar_find(device_t dev, bool verbose) dmar_print_path(dev_busno, dev_path_len, dev_path); printf("\n"); } + iommu_device_set_iommu_prop(dev, unit->iommu.dev); return (unit); } @@ -826,16 +827,28 @@ dmar_find_nonpci(u_int id, u_int entry_type, uint16_t *rid) struct dmar_unit * dmar_find_hpet(device_t dev, uint16_t *rid) { + struct dmar_unit *unit; - return (dmar_find_nonpci(hpet_get_uid(dev), ACPI_DMAR_SCOPE_TYPE_HPET, - rid)); + unit = dmar_find_nonpci(hpet_get_uid(dev), ACPI_DMAR_SCOPE_TYPE_HPET, + rid); + if (unit != NULL) + iommu_device_set_iommu_prop(dev, unit->iommu.dev); + return (unit); } struct dmar_unit * dmar_find_ioapic(u_int apic_id, uint16_t *rid) { + struct dmar_unit *unit; + device_t apic_dev; - return (dmar_find_nonpci(apic_id, ACPI_DMAR_SCOPE_TYPE_IOAPIC, rid)); + unit = dmar_find_nonpci(apic_id, ACPI_DMAR_SCOPE_TYPE_IOAPIC, rid); + if (unit != NULL) { + apic_dev = ioapic_get_dev(apic_id); + if (apic_dev != NULL) + iommu_device_set_iommu_prop(apic_dev, unit->iommu.dev); + } + return (unit); } struct rmrr_iter_args { diff --git a/sys/x86/iommu/iommu_utils.c b/sys/x86/iommu/iommu_utils.c index 259c87403b07..479e8637ee8e 100644 --- a/sys/x86/iommu/iommu_utils.c +++ b/sys/x86/iommu/iommu_utils.c @@ -758,6 +758,19 @@ pglvl_page_size(int total_pglvl, int lvl) return (pg_sz[rlvl]); } +void +iommu_device_set_iommu_prop(device_t dev, device_t iommu) +{ + device_t iommu_dev; + int error; + + bus_topo_lock(); + error = device_get_prop(dev, DEV_PROP_NAME_IOMMU, (void **)&iommu_dev); + if (error == ENOENT) + device_set_prop(dev, DEV_PROP_NAME_IOMMU, iommu, NULL, NULL); + bus_topo_unlock(); +} + #ifdef DDB #include #include diff --git a/sys/x86/iommu/x86_iommu.h b/sys/x86/iommu/x86_iommu.h index 92ac993e7c9c..eb4a9907a5d6 100644 --- a/sys/x86/iommu/x86_iommu.h +++ b/sys/x86/iommu/x86_iommu.h @@ -188,6 +188,7 @@ int iommu_alloc_irq(struct iommu_unit *unit, int idx); void iommu_release_intr(struct iommu_unit *unit, int idx); void iommu_device_tag_init(struct iommu_ctx *ctx, device_t dev); +void iommu_device_set_iommu_prop(device_t dev, device_t iommu); int pglvl_pgtbl_pte_off(int pglvl, iommu_gaddr_t base, int lvl); vm_pindex_t pglvl_pgtbl_get_pindex(int pglvl, iommu_gaddr_t base, int lvl);