From nobody Thu Oct 24 02:46:09 2024 X-Original-To: dev-commits-src-all@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 4XYqzk0Pd2z5ZyFS; Thu, 24 Oct 2024 02: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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XYqzj6hVhz46yP; Thu, 24 Oct 2024 02: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=1729737969; 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=ujPj4JbH13fgplFjJkp4Wu/xtt51fYqBV3qU3TerC3s=; b=f0lZ+muL6bWC31WWeGBoVkOII2g90Pr5WHh6pj9asqcoJTF6+5Swg5ooDkq5MLLsb+MWDs tpIj/XSLr+nbF+BrwCCYuziE42qO0Ua1mMC62mg11jUl0rxlfgxgB0+GNbj5bGIY3IPLPE TrK9wITQVrKJ4iYUABsqvGKmAtZLUaTSIWz3+YoweJHeSMT5dphACgPktJJqvCT03lL1AX 4xWzjisBA3ssCp0Np93JLmme+mlGpV8HaL2pTVq964EQzzto/9SWOJzmWD0LH7wC3ZKl2I rZqQ6Q7duB/wJyNNSRjRRnAEmJQAFSYaBr0hY7NbP+qR6H44gKg4CMf61ZADvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729737969; 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=ujPj4JbH13fgplFjJkp4Wu/xtt51fYqBV3qU3TerC3s=; b=QzSySLSIJiwULjskwy666e+NKSEvvW45RkhSa5GL2XJ5ZhmrOMIT7raw07nPKoUXos662k bE0lOWIK63QetDKOzyIyv9Ce3Wf5HfhFAGaYrPUKU5/ctuuc2bSidFJImLxK2y27xyiKjn oY45Z5aU/5WnIobpD9w6hXADjiquF0ERfalhvcEeHcEkd4h7bMCgVlQCBbP0rzdgBLhFRV 2iYVYX6mdBZwyLEci0x5ubWO6HS5lUm54HyJbOSZT06R6Migitl3nwUD6NV4w1MxtUCqOe T1DlPdPB1QE6odBMmoSAJvWofKb/vtyJ1A6ITLke9hCw46kknPyusYnpy2Uc/w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729737969; a=rsa-sha256; cv=none; b=gXLtqkerJh5s/xQi69e7M3LvI+DTQD48UKDJdSx0z9SMT/ZHqd/mMsMZaEM41mdXCmBgYU +DKdmaKMVhwBJysOR+KIv5MMjQ5FnO47x1H7xflNGui1iuCgUhID3DJutJapOJtyXmR8E3 eSb97gWObtOp/o5siYMHQaMz+xqHat9Wf4dHKBRQQsW0bBpEynyj2W6uco4D+jbUW89Y1G MQmCOHuzq16Lx53f6WEdPcejZBmbTZxVzzDwkOEXL9qXQGtWx5ePWvSjcLKSGsqr61Q/GS JXem+bheNZkTcPbl7XWQdhlyXIMc5btcSVCzxBtzSeLBLiaxqRqpcNh+fZLx0g== 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 4XYqzj6Hs5zPSX; Thu, 24 Oct 2024 02:46:09 +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 49O2k9If086229; Thu, 24 Oct 2024 02:46:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49O2k9K4086226; Thu, 24 Oct 2024 02:46:09 GMT (envelope-from git) Date: Thu, 24 Oct 2024 02:46:09 GMT Message-Id: <202410240246.49O2k9K4086226@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: ec8d60f0d9b7 - stable/14 - devices: report iommu data for the device in the dev. sysctl tree List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/14 X-Git-Reftype: branch X-Git-Commit: ec8d60f0d9b762880482e39f567db552c152d3a2 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=ec8d60f0d9b762880482e39f567db552c152d3a2 commit ec8d60f0d9b762880482e39f567db552c152d3a2 Author: Konstantin Belousov AuthorDate: 2024-10-12 22:54:33 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-24 02:44:40 +0000 devices: report iommu data for the device in the dev. sysctl tree (cherry picked from commit b08d332da035e11bfc9373f2d08244cb3e10cda4) --- 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 9e6973f6174c..b87652fd32e8 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 eecff0c7c03e..5d5336591ea6 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -889,6 +889,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);