From nobody Mon Mar 11 21:23:26 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 4TtqWg2kPrz5Dl1p; Mon, 11 Mar 2024 21:23:27 +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 4TtqWg0xkJz41Rl; Mon, 11 Mar 2024 21:23:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710192207; 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=0CrnF2pZB9OXXxtH+RonzgxUyHyxr5nFevjih+fwfV8=; b=ebF4fJOXpnG9FdOwaBpjIqudm7DXbhUTfpXcp/VtBRZtOnCzrEmraVdSVxS1aaq4BC8Mml tQGEojyXdqF1IYyN8uduFHWr+6EYSXQ+6HPVBkcx6QE8+aFAHyGnUrS7ihsob5MoIOfbSY lq96rpv4i0hwC49nY4JXGNHQWfxQcsMUlOxpIsfIT4tzn+IHYTZRal3MgDtlkEsKZFeWqH vwgtTf1WKXAWgViZfJgneS8xw8H1/Xe2ZG/vhMNE6GrSTH/CFI4RWa2J/MZlc6L2i/vbW7 844lpA3SQMr0FFJ1B1oE2OSgrNxMviVmVC+zeC+n/CKsccbORXp7sfZ3/sRfsA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710192207; a=rsa-sha256; cv=none; b=BTlr1tywjROT+cegLVEr7dh5XDq8j1R9Nv5OpDGWFODMOSxmwTXa+mcayEzYhbJnKRbvd6 1ONr4KUmvtjm4FMOAmV56XIG5EfpmyJSFdpZHe6FlVzI1sdYD40oacpruR/FHzI13vuU59 BLqTyWtAErRNwe6aa1rUepiXeNHBXhwmpnqkw+nRy8bw/u96hZWYRZy0fDiJ9JCt3gNk5u X1Pa8QgSdCmN2lb++nhDoB+jlVhRPesFrYz/vITfMFwxfSCHFD3uSez983KXVBfvlXP1Ow di6mRF/Q14vboIjhLRURVO5MP15x1QtCj2oqpTLadPl69smcSRhIrdG3323vHg== 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=1710192207; 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=0CrnF2pZB9OXXxtH+RonzgxUyHyxr5nFevjih+fwfV8=; b=ZbAiuFHL9RkgjkXBXq5emHiZXvpBqBDhw2YPYfaPL4448rjLJF7MJCJqNgT11y5VLTFzPX kHncmQLW7zLq3VHyGpRBYYq4VJwu2OZ74BWA685xPuL7FFxt0hJsF7yUPMQmsalma7wVt3 IysTrvy7ywBbJj3DL8DSW7oXWFueh2/mrdAySX5veBaTvUeGnXxiPJwIj44sMbn36dvOF8 jDU4lsA1cIXvkvxfi+utK94qcZfCINKEdTiBcW6dtlKClNXje+QqoGdZruiy36TjSQDmsw 9boBs5wrBZbbnV6BIIc5f2BKSWbKzKpREClaTsIo0Y913CYdn/3HhUUznrVKnw== 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 4TtqWg0Xwwzlqm; Mon, 11 Mar 2024 21:23:27 +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 42BLNQwc025620; Mon, 11 Mar 2024 21:23:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42BLNQKo025617; Mon, 11 Mar 2024 21:23:26 GMT (envelope-from git) Date: Mon, 11 Mar 2024 21:23:26 GMT Message-Id: <202403112123.42BLNQKo025617@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: a9cd3b675e24 - main - kboot: Print UEFI memory map 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: a9cd3b675e243648aa681bc6ce1bf3e788be88c8 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a9cd3b675e243648aa681bc6ce1bf3e788be88c8 commit a9cd3b675e243648aa681bc6ce1bf3e788be88c8 Author: Warner Losh AuthorDate: 2024-03-11 20:15:34 +0000 Commit: Warner Losh CommitDate: 2024-03-11 21:21:52 +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 --- 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: