From nobody Wed Mar 15 15:44:44 2023 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 4PcF7w3wqTz3yg92; Wed, 15 Mar 2023 15:44:44 +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 4PcF7w3TCcz4Ym7; Wed, 15 Mar 2023 15:44:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678895084; 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=1hX+B+f5A90jmgOF3vZh8soFKtxHkZ3vchgronl/d2s=; b=X7Sg/LPahIHe0qqxVt9Gye68Nh0G4uERfGfzzwd8LShGlqb8DJLfZ0BMhS7rGIMW/HwkGS ga8BkLj8a1FaZRSJwpcFs6RsCgRlRpNgJyktEu4tfuJuI9AOFu4SaxKtxl3+f0d1FhdNDN EFkhJU1Y4uzWm8UGcjMHl1jzjgPuDyiMAn8yN6+QDrHwpaXFiDg1cvETvM+9Ed6CYGkORh 9Yt6tSgDPJKMKflCxrKHLuJhR1n7ZaGDZLRFOWrYoW+o3xHtMLcS+OSICUV20mHX5/GPUQ oO3i5onyPoelipT7czB2n7aHs5g6UZc1Ww3cgM+xaNl4clghdJ+f5o8dX2oEYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678895084; 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=1hX+B+f5A90jmgOF3vZh8soFKtxHkZ3vchgronl/d2s=; b=xenAUZF5LqMmKSRRnEURmj79Pmo6dtnWJIsoZsZMufMdwKTE7dQfKMF20pF565tzg/qwK5 og/fFZLqJ6SEBwSKITQFbKQiWHuJsnMs6MD4yBV6Fc9r+lbDHftv5Cv0dQtkdzoQRxS+QV DxUqxhjZqBz6f0EWK/wKbd4GKmEvIqwah7R/xaw2n2tAQAVjUA6fBPE8Z3CIfy31e7BEY6 gEN/yHQsVzCJUhcTL9k5guqTid93QcOZmcQQsUgjySf1sWwarardTblfT0mkF5x9T3P9eI v6FZl6XC9iTL0a+NVB5IczcJnA8U7yW17cYwAqaIlJeli2pZCXKTUXH0mVFqlA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678895084; a=rsa-sha256; cv=none; b=yKTj7lzX8HDIIHeTDypHuZx+vjalAp0adhXP6Vnsc8Mu8kD4tUQq8KEQ1iY+Tc84aC/ssz YHpa3KidXKnNKN2re7sSOT6oX/d8XGy03ugO+cGVSLx7ZnRf//wvmMtxR7OJ/wa9PeNyWx /cT1fiNMziZpOV4kicIuUVCr/vvG30eJhQEnWdbpnAvzPdiPEr35nvrWq3PJbPMud8gDse ljwTAvW5Hk1kX2M8ZGlgLMq+aDZ5t01H1CM+xDTEGJPmTY/Q0im+VAfoJraZsFBfjHDbe1 C9/q2LUzhYpHmHMDPYLoMKimRdKX6u9cSv+fHdo1F/gTK+PPNdXOEXBSk7myaQ== 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 4PcF7w2XZxz1M7n; Wed, 15 Mar 2023 15:44:44 +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 32FFii7n058098; Wed, 15 Mar 2023 15:44:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32FFiipn058097; Wed, 15 Mar 2023 15:44:44 GMT (envelope-from git) Date: Wed, 15 Mar 2023 15:44:44 GMT Message-Id: <202303151544.32FFiipn058097@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 8937bd37d07c - main - arm64: limit EFI excluded regions to physical memory types 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8937bd37d07c5c75995e01457aec00fb0a05c462 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=8937bd37d07c5c75995e01457aec00fb0a05c462 commit 8937bd37d07c5c75995e01457aec00fb0a05c462 Author: Mitchell Horne AuthorDate: 2023-03-15 15:26:57 +0000 Commit: Mitchell Horne CommitDate: 2023-03-15 15:28:35 +0000 arm64: limit EFI excluded regions to physical memory types Consolidate add_efi_map_entry() and exclude_efi_map_entry() into a single function, handle_efi_map_entry(), so that the exact set of entry types handled is the same in the addition or exclusion cases. Before, exclude_efi_map_entry() had a 'default' case that would exclude all entry types that were not listed explicitly in the switch statement. Logically, we do not need to exclude a range that could not possibly be added to physmem, and we do not need to exclude bus ranges that are not physical memory, for example EFI_MD_TYPE_IOMEM. Since physmem's ram0 device will reserve bus memory resources for its owned ranges, this was preventing attachment of the watchdog device on the RPI4B. For some reason its region of memory-mapped I/O appeared in the EFI memory map (with the aforementioned EFI_MD_TYPE_IOMEM type). This change fixes the attachment issue, as we prevent the physmem API from messing with this range of bus space. PR: 270044 Reported by: karels, Mark Millard Reviewed by: andrew, karels, imp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39003 --- sys/arm64/arm64/machdep.c | 71 ++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c index a076bd0a046a..0659602a9ded 100644 --- a/sys/arm64/arm64/machdep.c +++ b/sys/arm64/arm64/machdep.c @@ -455,36 +455,25 @@ foreach_efi_map_entry(struct efi_map_header *efihdr, efi_map_entry_cb cb, void * } } +/* + * Handle the EFI memory map list. + * + * We will make two passes at this, the first (exclude == false) to populate + * physmem with valid physical memory ranges from recognized map entry types. + * In the second pass we will exclude memory ranges from physmem which must not + * be used for general allocations, either because they are used by runtime + * firmware or otherwise reserved. + * + * Adding the runtime-reserved memory ranges to physmem and excluding them + * later ensures that they are included in the DMAP, but excluded from + * phys_avail[]. + * + * Entry types not explicitly listed here are ignored and not mapped. + */ static void -exclude_efi_map_entry(struct efi_md *p, void *argp __unused) -{ - - switch (p->md_type) { - case EFI_MD_TYPE_CODE: - case EFI_MD_TYPE_DATA: - case EFI_MD_TYPE_BS_CODE: - case EFI_MD_TYPE_BS_DATA: - case EFI_MD_TYPE_FREE: - /* - * We're allowed to use any entry with these types. - */ - break; - default: - physmem_exclude_region(p->md_phys, p->md_pages * EFI_PAGE_SIZE, - EXFLAG_NOALLOC); - } -} - -static void -exclude_efi_map_entries(struct efi_map_header *efihdr) -{ - - foreach_efi_map_entry(efihdr, exclude_efi_map_entry, NULL); -} - -static void -add_efi_map_entry(struct efi_md *p, void *argp __unused) +handle_efi_map_entry(struct efi_md *p, void *argp) { + bool exclude = *(bool *)argp; switch (p->md_type) { case EFI_MD_TYPE_RECLAIM: @@ -496,7 +485,7 @@ add_efi_map_entry(struct efi_md *p, void *argp __unused) /* * Some UEFI implementations put the system table in the * runtime code section. Include it in the DMAP, but will - * be excluded from phys_avail later. + * be excluded from phys_avail. */ case EFI_MD_TYPE_RT_DATA: /* @@ -504,6 +493,12 @@ add_efi_map_entry(struct efi_md *p, void *argp __unused) * region is created to stop it from being added * to phys_avail. */ + if (exclude) { + physmem_exclude_region(p->md_phys, + p->md_pages * EFI_PAGE_SIZE, EXFLAG_NOALLOC); + break; + } + /* FALLTHROUGH */ case EFI_MD_TYPE_CODE: case EFI_MD_TYPE_DATA: case EFI_MD_TYPE_BS_CODE: @@ -512,8 +507,12 @@ add_efi_map_entry(struct efi_md *p, void *argp __unused) /* * We're allowed to use any entry with these types. */ - physmem_hardware_region(p->md_phys, - p->md_pages * EFI_PAGE_SIZE); + if (!exclude) + physmem_hardware_region(p->md_phys, + p->md_pages * EFI_PAGE_SIZE); + break; + default: + /* Other types shall not be handled by physmem. */ break; } } @@ -521,7 +520,15 @@ add_efi_map_entry(struct efi_md *p, void *argp __unused) static void add_efi_map_entries(struct efi_map_header *efihdr) { - foreach_efi_map_entry(efihdr, add_efi_map_entry, NULL); + bool exclude = false; + foreach_efi_map_entry(efihdr, handle_efi_map_entry, &exclude); +} + +static void +exclude_efi_map_entries(struct efi_map_header *efihdr) +{ + bool exclude = true; + foreach_efi_map_entry(efihdr, handle_efi_map_entry, &exclude); } static void