From nobody Mon May 01 21:28:50 2023 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 4Q9GYG4m6yz492Fy; Mon, 1 May 2023 21:28:50 +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 4Q9GYG41kBz3kBG; Mon, 1 May 2023 21:28:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682976530; 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=GJle0ds6veaoHgMWOkq7iPt4o8Cwp+HFRnBvp1EXkfw=; b=P6F6GUeg//tJoI8Vk4sX+THbVav/jRyV+hOXr7i1L1myKi2kKhfgPgfpjcpN7bFUjSaAXr /V18/fO0hoiwLkFfhqdeg62VViYJReGNXtj7H34D6jtZ1W+xh/t0eBq3jFtp4joPZbIELc vOADy949CBMREbFTXs3rDC8rqGgMOukVQQRp3RXYz7/4dSUmMuC+FJKf0UXGNCyvZbczEs Lj351gI7s67EiqeGY0tBcjslvYL4WlpjNvkjJyd3ZKsRU8Rtqvx0AHMrnWId0ueJrcL5iN q71+tGbPm5SB+qKbAk9yB/cqDI4X71C+ccpmBGdpRL5JnXIk3u8vnH8T9MXchw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682976530; 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=GJle0ds6veaoHgMWOkq7iPt4o8Cwp+HFRnBvp1EXkfw=; b=TxK7eDOjO21wG62vWefOpX0SqJNTriwfctiPA1ZGb+ZZxDWU6BfwWp/Dv1gJ4lZ9HTkmJX G/DrXfnqoDUpYVRbcj473OYEKW5PtmbtGjx/AIhSYTiq3BlT6msm7WBPrUFP17vwzXzIp9 Wv5GMynZyHR77RfJALyetfPE0UIdqGBLuXCbESE6WqvnGN3TDcVHXHMeQODxwmntRDGkEU tOddq6EDaGbHXvEK1NzO35as9db1Pajfx1xseqoZdklnKDnWZIcgZQvbjhT0tZB5F0Kgpd a5L8yKb6KlcDxyH2KvE9vhrACaLN1LDTu5g0RR81TqDLIPr+PDbMoXMJpingTA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682976530; a=rsa-sha256; cv=none; b=a5WVMdinTHmR67U4FRFbd42Ap4B+mpuiEfgP5sEWo5UvqegN+/s8j3FHoavIEF0hgIgPM/ DENarxo2bzzycGpuHSmk+mB/G2MvNZPUrVRNNVgsN1gqFJ1K/4313onKklNQT6Byerhb8t acM9W8Kf90fX/jHxZstlQVk8xwNzSy/AqtOLcvwxcosqCSc2n8uktMvy8k4v3sb2et5gO6 v6g+3vpi0aglOCFAs9HyTQyWAMIdqF8B8XzwBNVTXzKuoTRhDWwWXbIIv0mjvR74SBkCkn k4rzrSyRtq4/l5iNUIqLlIxfMFEwooOwq+lIXj/wk1hxYF7MdPI8rDg0EvZb/g== 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 4Q9GYG36fczMKL; Mon, 1 May 2023 21:28:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 341LSojk085920; Mon, 1 May 2023 21:28:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 341LSono085919; Mon, 1 May 2023 21:28:50 GMT (envelope-from git) Date: Mon, 1 May 2023 21:28:50 GMT Message-Id: <202305012128.341LSono085919@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: a083d0867635 - main - kboot: Add smbios support 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: owner-dev-commits-src-all@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: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a083d086763594a7072b11fd9ef0553c6466da34 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a083d086763594a7072b11fd9ef0553c6466da34 commit a083d086763594a7072b11fd9ef0553c6466da34 Author: Warner Losh AuthorDate: 2023-05-01 21:12:29 +0000 Commit: Warner Losh CommitDate: 2023-05-01 21:12:29 +0000 kboot: Add smbios support Add support for getting smbios from /sys/firmware/efi/systab, if any. Add ptov mapping that uses mmap on /dev/mem to do the mapping with 64k pages (usually we only need 1 or two mappings). Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D39792 --- stand/kboot/main.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/stand/kboot/main.c b/stand/kboot/main.c index ecf96cc73d4d..c8c49067bcc7 100644 --- a/stand/kboot/main.c +++ b/stand/kboot/main.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include "host_syscall.h" #include "kboot.h" #include "stand.h" +#include struct arch_switch archsw; extern void *_end; @@ -195,6 +196,107 @@ has_acpi(void) return rsdp != 0; } +/* + * SMBIOS support. We map the physical memory address we get into a VA in this + * address space with mmap with 64k pages. Once we're done, we cleanup any + * mappings we made. + */ + +#define MAX_MAP 10 +#define PAGE (64<<10) + +static struct mapping +{ + uintptr_t pa; + caddr_t va; +} map[MAX_MAP]; +static int smbios_fd; +static int nmap; + +caddr_t ptov(uintptr_t pa) +{ + caddr_t va; + uintptr_t pa2; + struct mapping *m = map; + + pa2 = rounddown(pa, PAGE); + for (int i = 0; i < nmap; i++, m++) { + if (m->pa == pa2) { + return (m->va + pa - m->pa); + } + } + if (nmap == MAX_MAP) + panic("Too many maps for smbios"); + + /* + * host_mmap returns small negative numbers on errors, can't return an + * error here, so we have to panic. The Linux wrapper will set errno + * based on this and then return HOST_MAP_FAILED. Since we're calling + * the raw system call we have to do that ourselves. + */ + va = host_mmap(0, PAGE, HOST_PROT_READ, HOST_MAP_SHARED, smbios_fd, pa2); + if ((intptr_t)va < 0 && (intptr_t)va >= -511) + panic("smbios mmap offset %#jx failed", (uintmax_t)pa2); + m = &map[nmap++]; + m->pa = pa2; + m->va = va; + return (m->va + pa - m->pa); +} + +static void +smbios_cleanup(void) +{ + for (int i = 0; i < nmap; i++) { + host_munmap(map[i].va, PAGE); + } +} + +static vm_offset_t +kboot_find_smbios(void) +{ + char buffer[512 + 1]; + char *walker, *ep; + + if (!file2str("/sys/firmware/efi/systab", buffer, sizeof(buffer))) + return (0); /* Not an EFI system */ + ep = buffer + strlen(buffer); + walker = buffer; + while (walker <= ep) { + if (strncmp("SMBIOS3=", walker, 8) == 0) + return((vm_offset_t)strtoull(walker + 8, NULL, 0)); + if (strncmp("SMBIOS=", walker, 7) == 0) + return((vm_offset_t)strtoull(walker + 7, NULL, 0)); + walker += strcspn(walker, "\n") + 1; + } + return (0); +} + +static void +find_smbios(void) +{ + char buf[40]; + uintptr_t pa; + caddr_t va; + + pa = kboot_find_smbios(); + printf("SMBIOS at %#jx\n", (uintmax_t)pa); + if (pa == 0) + return; + + snprintf(buf, sizeof(buf), "%#jx", (uintmax_t)pa); + setenv("hint.smbios.0.mem", buf, 1); + smbios_fd = host_open("/dev/mem", O_RDONLY, 0); + if (smbios_fd < 0) { + printf("Can't open /dev/mem to read smbios\n"); + return; + } + va = ptov(pa); + printf("Start of smbios at pa %p va %p\n", (void *)pa, va); + smbios_detect(va); + smbios_cleanup(); + host_close(smbios_fd); +} + static void parse_file(const char *fn) { @@ -300,6 +402,8 @@ main(int argc, const char **argv) */ find_acpi(); + find_smbios(); + interact(); /* doesn't return */ return (0); @@ -531,5 +635,6 @@ command_fdt(int argc, char *argv[]) return (command_fdt_internal(argc, argv)); } - + COMMAND_SET(fdt, "fdt", "flattened device tree handling", command_fdt); +