From nobody Wed Apr 10 05:28:59 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 4VDrwX0mmtz5GrSG; Wed, 10 Apr 2024 05:29:00 +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 4VDrwW6rpVz4ct9; Wed, 10 Apr 2024 05:28:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712726940; 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=Bc+YGKSWrjjSB9vaaJPRzpL3msSx7XlTaNxkz7EHGC0=; b=X4dt/B0zO4CsL3cy88IfkVj2F8yEe9XcwTMdgibpXAfY7b/V+5O5Z1e9kZ3z4gZHX6gsHw uJmjUiZKnyQC9sgeTB6Tutatq4g5IypaVjmDCUqT7t9zL7keheWgdODr28gQ5mBdUZXtDS UGaF+MrkLb3PXCO8j/JL8eMFA8LDvGR0/feMgLxKTXWGS8bwgTp1Q6mx6u5opBEeaPWAe9 CUuxZetA0RbPxoojszC8xKKocvlq4yyF/cQHTV9oNxfiIq+58sUE8fZs49BHyRdD6xHyW3 dQ+ffWu1VrrwN8xfSX66R2FVUu4FuEBQPtHfI/qpl96H/0QehPfapr1f0yhX8w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712726940; a=rsa-sha256; cv=none; b=Wq2pzl+jxxrfo9uV/igx2Rn1XbokFTBDzEZ+52xwUfq1VQXx6ioMh2brDw8L1wUOaqhhzq MjVlM3otjeoc8iZZcOzhy/Man3xSXLVra1j/eNhV6MsCx6nXzBRYZ19WL1KCmQqAZCAX3f xD0JzkFSugbotslX/ebu7yWIuIoMP4AcPpAqzEhIJqdNmFuqXR7Iq21P8eS03MZXC/wY3r eqHmAKFJSo/6x60AWVLL5TpbBOYXRUn2lppIJ0uCqXJ0bybyTZitiSApg376oHOemkEmlb 1JlOJGkw1lm2x0OsY7vlJuadxqvE+qSbD58Q8XnBJ51Y+mxHMwp/9GIdy1hLpA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712726940; 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=Bc+YGKSWrjjSB9vaaJPRzpL3msSx7XlTaNxkz7EHGC0=; b=BRNGKCcnk6PoVGSDx0J9Yx+jRR9+tnk07laZOWWSxue5YpRV8MA9wHxUokwrmkK5fnQiTD y8eptLG0XB5YpBN572wb/H6hgcT+INuHzcf6hFnhpMtcoC7Dkec6wZw6sU97bEVTY+vCjz DLDaVdh3uAJxbHZmSVKYgq/X5vvRrl0Ui7kDIRtFSAimnHEIfj7BKQvSSWeKLBkgtxHLqk s3DSs8RrWcf4p6bNowdt7LfDgSOmO7+2PPQrtWuzlw4ETw+MwUhNS7EXYGEzDKK1TIfimb 4g9xUu//IU7KTpvtFoePKt8mqKGkngQvG+teLRd1+yP9J6c9issGKTD5hLxqDg== 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 4VDrwW6TBJzQGC; Wed, 10 Apr 2024 05:28:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43A5Sxd4092251; Wed, 10 Apr 2024 05:28:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43A5SxwJ092248; Wed, 10 Apr 2024 05:28:59 GMT (envelope-from git) Date: Wed, 10 Apr 2024 05:28:59 GMT Message-Id: <202404100528.43A5SxwJ092248@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: 1e6db7be6921 - main - pciconf(8): dump AMD IOMMU Base Capability 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: Sender: dev-commits-src-all+owner@freebsd.org X-BeenThere: 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/main X-Git-Reftype: branch X-Git-Commit: 1e6db7be692198acfa7f02dea83aa9aa1dfce273 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=1e6db7be692198acfa7f02dea83aa9aa1dfce273 commit 1e6db7be692198acfa7f02dea83aa9aa1dfce273 Author: Konstantin Belousov AuthorDate: 2024-04-09 22:13:59 +0000 Commit: Konstantin Belousov CommitDate: 2024-04-10 05:28:24 +0000 pciconf(8): dump AMD IOMMU Base Capability Reviewed by: emaste Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D44732 --- usr.sbin/pciconf/cap.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/usr.sbin/pciconf/cap.c b/usr.sbin/pciconf/cap.c index 8595bff3d3d7..e252926ab9be 100644 --- a/usr.sbin/pciconf/cap.c +++ b/usr.sbin/pciconf/cap.c @@ -376,6 +376,118 @@ cap_subvendor(int fd, struct pci_conf *p, uint8_t ptr) printf("PCI Bridge subvendor=0x%04x subdevice=0x%04x", ssvid, ssid); } +static const char * +cap_secdev_amdiommu_decode_vasize(uint32_t misc0) +{ + switch (misc0 & PCIM_AMDIOMMU_MISC0_VASIZE_MASK) { + case PCIM_AMDIOMMU_MISC0_VASIZE_32: + return ("32bit"); + case PCIM_AMDIOMMU_MISC0_VASIZE_40: + return ("40bit"); + case PCIM_AMDIOMMU_MISC0_VASIZE_48: + return ("48bit"); + case PCIM_AMDIOMMU_MISC0_VASIZE_64: + return ("64bit"); + default: + return ("unknown"); + } +} + +static const char * +cap_secdev_amdiommu_decode_pasize(uint32_t misc0) +{ + switch (misc0 & PCIM_AMDIOMMU_MISC0_PASIZE_MASK) { + case PCIM_AMDIOMMU_MISC0_PASIZE_40: + return ("40bit"); + case PCIM_AMDIOMMU_MISC0_PASIZE_48: + return ("48bit"); + case PCIM_AMDIOMMU_MISC0_PASIZE_52: + return ("52bit"); + default: + return ("unknown"); + } +} + +static const char * +cap_secdev_amdiommu_decode_gvasize(uint32_t misc0) +{ + switch (misc0 & PCIM_AMDIOMMU_MISC0_GVASIZE_MASK) { + case PCIM_AMDIOMMU_MISC0_GVASIZE_48: + return ("48bit"); + case PCIM_AMDIOMMU_MISC0_GVASIZE_57: + return ("57bit"); + default: + return ("unknown"); + } +} + +static void +cap_secdev(int fd, struct pci_conf *p, uint8_t ptr) +{ + uint32_t cap_h; + uint32_t cap_type, cap_rev; + uint32_t base_low, base_high; + uint32_t range; + uint32_t misc0, misc1; + const char *delim; + + cap_h = read_config(fd, &p->pc_sel, ptr + PCIR_AMDIOMMU_CAP_HEADER, 4); + cap_type = cap_h & PCIM_AMDIOMMU_CAP_TYPE_MASK; + cap_rev = cap_h & PCIM_AMDIOMMU_CAP_REV_MASK; + if (cap_type != PCIM_AMDIOMMU_CAP_TYPE_VAL || + cap_rev != PCIM_AMDIOMMU_CAP_REV_VAL) { + printf("Secure Device Type=0x%1x Rev=0x%02x\n", + cap_type >> 16, cap_rev >> 19); + return; + } + base_low = read_config(fd, &p->pc_sel, ptr + PCIR_AMDIOMMU_BASE_LOW, + 4); + base_high = read_config(fd, &p->pc_sel, ptr + PCIR_AMDIOMMU_BASE_HIGH, + 4); + printf("AMD IOMMU Base Capability Base=%#018jx/%sabled", + (uintmax_t)(base_low & PCIM_AMDIOMMU_BASE_LOW_ADDRM) + + ((uintmax_t)base_high << 32), + (base_low & PCIM_AMDIOMMU_BASE_LOW_EN) != 0 ? "En" : "Dis"); + + delim = "\n\t\t"; +#define PRINTCAP(bit, name) \ + if ((cap_h & PCIM_AMDIOMMU_CAP_ ##bit) != 0) { \ + printf("%s%s", delim, #name); \ + delim = ","; \ + } + PRINTCAP(CAPEXT, CapExt); + PRINTCAP(EFR, EFRSup); + PRINTCAP(NPCACHE, NpCache); + PRINTCAP(HTTUN, HtTunnel); + PRINTCAP(IOTLB, IotlbSup); +#undef PRINTCAP + + range = read_config(fd, &p->pc_sel, ptr + PCIR_AMDIOMMU_RANGE, 4); + printf("\n\t\tUnitId=%d", range & PCIM_AMDIOMMU_RANGE_UNITID_MASK); + if ((range & PCIM_AMDIOMMU_RANGE_RNGVALID) != 0) { + printf(" BusNum=%#06x FirstDev=%#06x LastDev=%#06x", + (range & PCIM_AMDIOMMU_RANGE_BUSNUM_MASK) >> 8, + (range & PCIM_AMDIOMMU_RANGE_FIRSTDEV_MASK) >> 16, + (range & PCIM_AMDIOMMU_RANGE_LASTDEV_MASK) >> 24); + } + + misc0 = read_config(fd, &p->pc_sel, ptr + PCIR_AMDIOMMU_MISC0, 4); + printf("\n\t\tMsiNum=%d MsiNumPPR=%d HtAtsResv=%d", + misc0 & PCIM_AMDIOMMU_MISC0_MSINUM_MASK, + (misc0 & PCIM_AMDIOMMU_MISC0_MSINUMPPR_MASK) >> 27, + (misc0 & PCIM_AMDIOMMU_MISC0_HTATSRESV) != 0); + if ((cap_h & PCIM_AMDIOMMU_CAP_CAPEXT) != 0) { + misc1 = read_config(fd, &p->pc_sel, + ptr + PCIR_AMDIOMMU_MISC1, 4); + printf(" MsiNumGA=%d", + misc1 & PCIM_AMDIOMMU_MISC1_MSINUMGA_MASK); + } + printf("\n\t\tVAsize=%s PAsize=%s GVAsize=%s", + cap_secdev_amdiommu_decode_vasize(misc0), + cap_secdev_amdiommu_decode_pasize(misc0), + cap_secdev_amdiommu_decode_gvasize(misc0)); +} + #define MAX_PAYLOAD(field) (128 << (field)) static const char * @@ -813,6 +925,9 @@ list_caps(int fd, struct pci_conf *p, int level) case PCIY_SUBVENDOR: cap_subvendor(fd, p, ptr); break; + case PCIY_SECDEV: + cap_secdev(fd, p, ptr); + break; case PCIY_EXPRESS: express = 1; cap_express(fd, p, ptr);