From nobody Fri Feb 03 15:50:38 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 4P7g9B3qPbz3kRnm; Fri, 3 Feb 2023 15:50:38 +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 4P7g9B2Rxqz3Hdm; Fri, 3 Feb 2023 15:50:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675439438; 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=qHz8SsT1z7qGZPJ0vELUZQlNcnzVc888hcLBUgi4a0U=; b=o++BdjR7m1OaG5QR25MUQVesWnInkiBOlJh/mUXQJGYdUWL09aZChkyf+7QTRwov5m8ucX eQN+8DH/7s6D2/ynAGI0jHWEEuVfLncqybd03Rz/PirY8yhHIjHOw1z+81aWLC7ndF46wa apoBf+x1SK8zwzcg5R6nRUi8w0aihNH2RwTF++AZCD0rGOfs/QjQtRt/H0qfI92jnGJMz6 4IND5OS6Bvxt+k9Bbhnz1hGRO75loT3DeMc89iwn+JglbSjdaykZA3DFihJo5qFBeL6iej yxQQJhdxk3eBtaqwWtI7nh6zCFRFp/Lq2f/eRUwPxdzBlp0e2l2B7ZItS0pg0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675439438; 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=qHz8SsT1z7qGZPJ0vELUZQlNcnzVc888hcLBUgi4a0U=; b=b7z1pukZqg6xmTt4MP84nHSg1MNTErGh7s7q8GTgy96AcrN2Gh7OQ5wy4NKqqe5nMmHv15 uPvE8xk1NFMWU9wWCl4WA/1JlMWScYTJS43D/FIHSliReabYUE8TuVXVwG9/K0AhSV6anS Q4VpimAPgTobPUzcj6WRsMUS/LhArV4YjgFWmJxXN1ewB0RdFBujXxTqK39xrIdEFdRAIX VIXcuTuAGTCH37H5L2RFjZnbwyWMwDYTKHRVSn8hNb9EoKTH7Mjr37cEtROdxdNUYZSvPN rp8Nx3VYmOnckOIO10VT8abJ3zyO76G+fnMybx4bUR4XeB7npUxAmuALD6AMug== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675439438; a=rsa-sha256; cv=none; b=HfDCto/0DjJip87y4vXxCx7PXcg8o87YgqC2i/SYbSPT8Q9mlaf0e7YgT7gYHg0MhGuxE5 pJngDPEXzfN++kyOfApiCfZfjFCGxXLKFVDoJdHlcQ8iguPoD1+7PFX6zOnb6p81vsE0aD vFgGFgCItFjVJJINEh/tydjC8wqM8NBmWelaYtGXAc43OPKyoXodv5EYOsYcRuecQd/lrN Sk+f6SXTobjiNl2mYW9/MZ3diM7ZY1eJZjl51PENM5DBNpkL6NTcwmW7TpB4kQIFhcAL84 ekcPk034SG4JsuIvFgBbfkKVzrhb8uvrsvho34TPSwyg5i+A2yOydV8AAjQbQg== 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 4P7g9B1VsgzgB3; Fri, 3 Feb 2023 15:50:38 +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 313Foc5a022981; Fri, 3 Feb 2023 15:50:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313FocGj022980; Fri, 3 Feb 2023 15:50:38 GMT (envelope-from git) Date: Fri, 3 Feb 2023 15:50:38 GMT Message-Id: <202302031550.313FocGj022980@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: 81fbd74a4b59 - main - kboot: space_avail -- how much space exists from 'start' to end of segment 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: 81fbd74a4b598c52957b491896ec839316ceeec3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=81fbd74a4b598c52957b491896ec839316ceeec3 commit 81fbd74a4b598c52957b491896ec839316ceeec3 Author: Warner Losh AuthorDate: 2023-02-03 15:38:22 +0000 Commit: Warner Losh CommitDate: 2023-02-03 15:41:39 +0000 kboot: space_avail -- how much space exists from 'start' to end of segment Sponsored by: Netflix Reviewed by: tsoome Differential Revision: https://reviews.freebsd.org/D38313 --- stand/kboot/kboot.h | 1 + stand/kboot/seg.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/stand/kboot/kboot.h b/stand/kboot/kboot.h index dcf1487ce404..4a8fe497339e 100644 --- a/stand/kboot/kboot.h +++ b/stand/kboot/kboot.h @@ -44,6 +44,7 @@ void remove_avail(uint64_t start, uint64_t end, uint64_t type); uint64_t first_avail(uint64_t align, uint64_t min_size, uint64_t type); void print_avail(void); bool populate_avail_from_iomem(void); +uint64_t space_avail(uint64_t start); /* util.c */ bool file2str(const char *fn, char *buffer, size_t buflen); diff --git a/stand/kboot/seg.c b/stand/kboot/seg.c index 8cf3b833c9d1..947aa0a2a7a3 100644 --- a/stand/kboot/seg.c +++ b/stand/kboot/seg.c @@ -344,3 +344,22 @@ out: close(fd); return true; } + +/* + * Return the amount of space available in the segment that @start@ lives in, + * from @start@ to the end of the segment. + */ +uint64_t +space_avail(uint64_t start) +{ + for (int i = 0; i < nr_seg; i++) { + if (start >= segs[i].start && start <= segs[i].end) + return segs[i].end - start; + } + + /* + * Properly used, we should never get here. Unsure if this should be a + * panic or not. + */ + return 0; +}