From nobody Fri Feb 03 15:50:41 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 4P7g9G0fWQz3kRny; Fri, 3 Feb 2023 15:50:42 +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 4P7g9F5cSZz3HnT; Fri, 3 Feb 2023 15:50:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675439441; 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=sNwYqQu7FCOWWLtCT4ayzszSoKMyBqLRcMxKApUcUxk=; b=TKIDlPf/9bXwZJVO4s5IGlzPGVMF0ITmvsXj4wL+Xw6KUsUgRndQBex5Mc368GWRKw2XrN ZF+Y2+8MxnjGXQzNTKWyXkC97tc0s5ObcpLn/U05wCxa7PmJ4B0F1XE/vMFB2L1gM1NFms jpxwFymlZoZBwyOe8D/eOOHwZdC0C2ogz+1E8hh2zdH/xGlE7cUYy1E58DdEobjMpwcb/O Movk6Ajp9gjvPMw9a09EtGbNU87gn8fN5BkkVIJos8ckqLmCp0Pk3kDoGQH/1PAEx8czPZ v0fBIDnY/pvcSB4zsIW3/6CqKNfVB5BHMUH5NXiHgyU71I7W38RCjUKb5eCgfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675439441; 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=sNwYqQu7FCOWWLtCT4ayzszSoKMyBqLRcMxKApUcUxk=; b=Pa6nPYTvrsJRPpZBqLx+7j4FB618B9Rs5QXlNm4JIKoV+YS/VH4aF2l9EwjrckXBYdkRvO E5mfImEtuDmocQFhee4GezKSp7lKv3V0rq2CMawPn2VbjisV8LTFQvzpw7VqVQLaB/dxJ9 RbD1fAtWlkGIX/OVi7mpnywU4f4rmZm0lW+gHUNBaF/L5o08XghjK7tG3VDoFv4Sd0U9mv XUwugnbt8HyhbP0thn7xOz2n/g5acD24CS+O5uvnKl2XoGxhhhONbODeKU5e+qLwsQZh6S 2LdKWS0dicijt5OceiSPP4EekLiYTrnhVB1UsD4LYaei71qMWdxRu/R3B+9puw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675439441; a=rsa-sha256; cv=none; b=Yhdk2p/E5ltmJtawv4x2oG02FldxAOE5HVldz/0xo4Bx4dp0Rtf5rNijvi2XRRORN/UpGh KpBcCzxOzmahwr6fje7Mi62G1ujzA0VgBW0XHyYv+gzGYSi67ZM9wiTBI0UCiawzyULWh0 K6XsnQYZqKLLhp5Np5ri4FNf0EsJkIXLWZUCiP0Djf8dss72ZisVwoXbCywBSXPWVLRi0r Ip349Gk6vYL56msV592hmQvg/uPsADBQcygNuxL/pxZhW20VF/QnOd2fSirjEonnttDqXd mcAYbtCUUYDZx0VhwHmScc/io7z5VSP2VJ63ddzKOAjDtYDu15Evn3kO334h1Q== 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 4P7g9F4kQqzgQm; Fri, 3 Feb 2023 15:50:41 +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 313FofRF023062; Fri, 3 Feb 2023 15:50:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313Fofl1023061; Fri, 3 Feb 2023 15:50:41 GMT (envelope-from git) Date: Fri, 3 Feb 2023 15:50:41 GMT Message-Id: <202302031550.313Fofl1023061@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: a967cd4db2af - main - kboot: Update amd64 to use enumerate_memory_arch() 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: a967cd4db2aff9c03adfead4b981a3659e75daf4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a967cd4db2aff9c03adfead4b981a3659e75daf4 commit a967cd4db2aff9c03adfead4b981a3659e75daf4 Author: Warner Losh AuthorDate: 2023-02-03 15:39:06 +0000 Commit: Warner Losh CommitDate: 2023-02-03 15:41:39 +0000 kboot: Update amd64 to use enumerate_memory_arch() Move memory enumeration to the enumerate_memory_arch(), tweak the code a bit to make that fit into that framework. Also fix a bug in the name of the end location. The old code never found memory (though amd64 doesn't yet work, this lead to using fallback addresses that were good enough for QEMU...). Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D38250 --- stand/kboot/arch/amd64/load_addr.c | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/stand/kboot/arch/amd64/load_addr.c b/stand/kboot/arch/amd64/load_addr.c index fccd17cf8d51..528b4dba6758 100644 --- a/stand/kboot/arch/amd64/load_addr.c +++ b/stand/kboot/arch/amd64/load_addr.c @@ -24,21 +24,16 @@ */ #include -#include +#include +#include #include "stand.h" #include "host_syscall.h" #include "kboot.h" +#include "bootstrap.h" /* Refactor when we do arm64 */ -struct memory_segments -{ - uint64_t start; - uint64_t end; - uint64_t type; -}; - enum types { system_ram = 1, acpi_tables, @@ -68,6 +63,9 @@ struct kv #define MEMMAP "/sys/firmware/memmap" +static struct memory_segments segs[64]; /* make dynamic later */ +static int nr_seg; + static bool str2type(struct kv *kv, const char *buf, uint64_t *value) { @@ -82,19 +80,18 @@ str2type(struct kv *kv, const char *buf, uint64_t *value) return false; } -static int -read_memmap(struct memory_segments *segs, int maxseg) +bool +enumerate_memory_arch(void) { int n; char name[MAXPATHLEN]; char buf[80]; - n = 0; - do { + for (n = 0; n < nitems(segs); n++) { snprintf(name, sizeof(name), "%s/%d/start", MEMMAP, n); if (!file2u64(name, &segs[n].start)) break; - snprintf(name, sizeof(name), "%s/%d/length", MEMMAP, n); + snprintf(name, sizeof(name), "%s/%d/end", MEMMAP, n); if (!file2u64(name, &segs[n].end)) break; snprintf(name, sizeof(name), "%s/%d/type", MEMMAP, n); @@ -102,10 +99,11 @@ read_memmap(struct memory_segments *segs, int maxseg) break; if (!str2type(str2type_kv, buf, &segs[n].type)) break; - n++; - } while (n < maxseg); + } + + nr_seg = n; - return n; + return true; } #define BAD_SEG ~0ULL @@ -118,6 +116,11 @@ find_ram(struct memory_segments *segs, int nr_seg, uint64_t minpa, uint64_t alig { uint64_t start; + printf("minpa %#jx align %#jx sz %#jx maxpa %#jx\n", + (uintmax_t)minpa, + (uintmax_t)align, + (uintmax_t)sz, + (uintmax_t)maxpa); /* XXX assume segs are sorted in numeric order -- assumed not ensured */ for (int i = 0; i < nr_seg; i++) { if (segs[i].type != system_ram || @@ -143,20 +146,17 @@ uint64_t kboot_get_phys_load_segment(void) { static uint64_t base_seg = BAD_SEG; - struct memory_segments segs[32]; - int nr_seg; if (base_seg != BAD_SEG) return (base_seg); - nr_seg = read_memmap(segs, nitems(segs)); if (nr_seg > 0) base_seg = find_ram(segs, nr_seg, 2ULL << 20, 2ULL << 20, 64ULL << 20, 4ULL << 30); if (base_seg == BAD_SEG) { /* XXX Should fall back to using /proc/iomem maybe? */ /* XXX PUNT UNTIL I NEED SOMETHING BETTER */ - base_seg = 42ULL * (1 << 20); /* Jam it in at the odd-ball address of 42MB so it stands out */ + base_seg = 300ULL * (1 << 20); } return (base_seg); }