From nobody Tue Apr 16 20:13:34 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 4VJwGQ6BjSz5H0tC; Tue, 16 Apr 2024 20:13:34 +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 4VJwGQ4NfCz4vhn; Tue, 16 Apr 2024 20:13:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713298414; 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=nNMJc2liAT5R0CuxrGTTvBO0Q7yt262k1K9Wp9iQO+8=; b=Eg5MMQDRhclTy/3iLIEJderdLk+I9FKATwAffTFKT8grDo23PNsnPrz5dx5eipL7Y+PFoQ FMRt5CpEhQv48ZnLDxizGycZg10MMbvnNgyvbA1IKMN439vhBozq5RjQlqFDXZ1ss0qII5 UiH+Ua/XpgBS2/9D74uTwcZKtWzptZdotCJ6v1+twjwRRz+/GcEYtmqAV14PfXL+nHT3u5 fbHBufeXpR9rHp3xAXtyvJ/jzQbfnuF3/aOx3lxEYyBeZ3XMrGmZsXa3PjdxCLKGVamD21 eW9Kl/H8AXRxXLPqGSB4X4AkWClBMDkE9XX31X/qCae1L9aKOq9DxJ8Vaf/mhw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713298414; a=rsa-sha256; cv=none; b=QstFzK7ETAYFj90eGHQMAiVJOIKdwp3HqNnOjrW03E6C2j4Am6Ga/6wjs7dxILvGznmoCk 5iA1sQt0XhyynU4YoNsFNoazHsKKUy05h2zWop2a6YfX0heDhhtKIiZQJ2FC0OiII8iRiV vqWXDluZNp0GYy4qiHceAU8eRjLHiehuvrQSCffdfJUpXNmA29eYC3U622/96Nh7h5CntE 6yJtOCX8qxnuQX+nORXrnGO45iGKhDEf29UYdFoleGKodKKa3lIezymY0h5O787KXstcJr 7S1dMVfT8jrQaGyhUc9NYC7aHj2LWqnakBVw//nMXyaKgwUgFDsJacB157IBIg== 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=1713298414; 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=nNMJc2liAT5R0CuxrGTTvBO0Q7yt262k1K9Wp9iQO+8=; b=rXZ0FCBVGuDlaSvoLKAFXWpt3kpmmvdO2bUvXHYcHooMcx8b61Z3s7C+ZZa8YGNG5kL24x hCWXmBEtoWEA6RmZFpi835ro/H+ayd26qa1tlaQUfR0pl4L20NCUM/GBA+VnpxyMljTOsj XzxCrIaqoFFTgN/P/aMIjmjvS5ddlNDz3tcrqlJuCrWDyvBLjPvvDBFOTM/tp0Dto4Xdah 43A8zlEzh+UY/5UXBLe56pSFVfEM6ynnTYvJPIJTpftKcrahPwoRr+QNuEbS7BK/vLlQow lOe3zIx1smhhbVzbwtaUI6AdYty4EnTG9r+XfuHmYhd2aUfsclVh2SZYnrdjpw== 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 4VJwGQ3zWtzxWb; Tue, 16 Apr 2024 20:13:34 +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 43GKDYiU039900; Tue, 16 Apr 2024 20:13:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43GKDYl7039897; Tue, 16 Apr 2024 20:13:34 GMT (envelope-from git) Date: Tue, 16 Apr 2024 20:13:34 GMT Message-Id: <202404162013.43GKDYl7039897@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 0bca0de6b676 - stable/14 - kboot: Print UEFI memory map 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: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 0bca0de6b676e952a8871a51b8e6880f8f3a5af8 Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=0bca0de6b676e952a8871a51b8e6880f8f3a5af8 commit 0bca0de6b676e952a8871a51b8e6880f8f3a5af8 Author: Warner Losh AuthorDate: 2024-03-11 20:15:34 +0000 Commit: Warner Losh CommitDate: 2024-04-16 19:54:29 +0000 kboot: Print UEFI memory map If we can read the UEFI memory map, go ahead and print the memory map. While the kernel prints this with bootverbose, having it at this stage is useful for debugging other problems. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D44287 (cherry picked from commit a9cd3b675e243648aa681bc6ce1bf3e788be88c8) --- stand/kboot/kboot/arch/aarch64/load_addr.c | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/stand/kboot/kboot/arch/aarch64/load_addr.c b/stand/kboot/kboot/arch/aarch64/load_addr.c index 4cbbd5192f5b..8ea3516a5cff 100644 --- a/stand/kboot/kboot/arch/aarch64/load_addr.c +++ b/stand/kboot/kboot/arch/aarch64/load_addr.c @@ -23,6 +23,87 @@ uint32_t efi_map_size; vm_paddr_t efi_map_phys_src; /* From DTB */ vm_paddr_t efi_map_phys_dst; /* From our memory map metadata module */ +typedef void (*efi_map_entry_cb)(struct efi_md *, void *argp); + +static void +foreach_efi_map_entry(struct efi_map_header *efihdr, efi_map_entry_cb cb, void *argp) +{ + struct efi_md *map, *p; + size_t efisz; + int ndesc, i; + + /* + * Memory map data provided by UEFI via the GetMemoryMap + * Boot Services API. + */ + efisz = (sizeof(struct efi_map_header) + 0xf) & ~0xf; + map = (struct efi_md *)((uint8_t *)efihdr + efisz); + + if (efihdr->descriptor_size == 0) + return; + ndesc = efihdr->memory_size / efihdr->descriptor_size; + + for (i = 0, p = map; i < ndesc; i++, + p = efi_next_descriptor(p, efihdr->descriptor_size)) { + cb(p, argp); + } +} + +static void +print_efi_map_entry(struct efi_md *p, void *argp __unused) +{ + const char *type; + static const char *types[] = { + "Reserved", + "LoaderCode", + "LoaderData", + "BootServicesCode", + "BootServicesData", + "RuntimeServicesCode", + "RuntimeServicesData", + "ConventionalMemory", + "UnusableMemory", + "ACPIReclaimMemory", + "ACPIMemoryNVS", + "MemoryMappedIO", + "MemoryMappedIOPortSpace", + "PalCode", + "PersistentMemory" + }; + + if (p->md_type < nitems(types)) + type = types[p->md_type]; + else + type = ""; + printf("%23s %012lx %012lx %08lx ", type, p->md_phys, + p->md_virt, p->md_pages); + if (p->md_attr & EFI_MD_ATTR_UC) + printf("UC "); + if (p->md_attr & EFI_MD_ATTR_WC) + printf("WC "); + if (p->md_attr & EFI_MD_ATTR_WT) + printf("WT "); + if (p->md_attr & EFI_MD_ATTR_WB) + printf("WB "); + if (p->md_attr & EFI_MD_ATTR_UCE) + printf("UCE "); + if (p->md_attr & EFI_MD_ATTR_WP) + printf("WP "); + if (p->md_attr & EFI_MD_ATTR_RP) + printf("RP "); + if (p->md_attr & EFI_MD_ATTR_XP) + printf("XP "); + if (p->md_attr & EFI_MD_ATTR_NV) + printf("NV "); + if (p->md_attr & EFI_MD_ATTR_MORE_RELIABLE) + printf("MORE_RELIABLE "); + if (p->md_attr & EFI_MD_ATTR_RO) + printf("RO "); + if (p->md_attr & EFI_MD_ATTR_RT) + printf("RUNTIME"); + printf("\n"); +} + static bool do_memory_from_fdt(int fd) { @@ -130,6 +211,10 @@ do_memory_from_fdt(int fd) printf("Read UEFI mem map from physmem\n"); efi_map_phys_src = 0; /* Mark MODINFOMD_EFI_MAP as valid */ close(fd2); + printf("UEFI MAP:\n"); + printf("%23s %12s %12s %8s %4s\n", + "Type", "Physical", "Virtual", "#Pages", "Attr"); + foreach_efi_map_entry(efihdr, print_efi_map_entry, NULL); return true; /* OK, we really have the memory map */ no_read: