From nobody Mon Apr 17 17:03:59 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 4Q0YL734ZKz44vSV; Mon, 17 Apr 2023 17:03:59 +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 4Q0YL72NGWz49FC; Mon, 17 Apr 2023 17:03:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681751039; 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=Pg2NuqjPwQs9JKD5qu4e2vNnomRstteH12ZJMpU3OEg=; b=gjfs9rlkdMFL0cBVtianGZfayw/aLDEBBniG6i7uNnoEnIsIm6cc9fSGIweemTR9XFAbjV hKy++khgj0MgiNfgZfizvGSVRCjtma1xxJ2lIMLzo4iKVM/cmz6Q2WPjmWdhtLNknBlOgh pdM7dS8yakmnj5wUWU8FRWFeWgGLzdpjFD8vIM6fifXVwKZXVaS/hkO9QqdrKe3482gWmW epKtmAEcwQYgBQkXZ3/x0JAk8r8W0RyEMYO6tdzvpmrU4IV5dQ3F3ChLaCavTGF3Ghqy4/ pLDLG1eM31Q1SXrXqWk9UzKDKz0im8vI6PI7dP2dtj3FvtjqR2QBCnq1L0WX/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681751039; 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=Pg2NuqjPwQs9JKD5qu4e2vNnomRstteH12ZJMpU3OEg=; b=WMZVBtLTurSsd9TeVbrQbcZMITjXgOipg5nm9xIyi6aj1DOzqRsGlZbfP3SDPybQOqxavg t3Pq/e/zNMsG+ID+bjfrWTTKoh5xYeMaXP/8f431qL27mjGTrz//AX8wjmCJg+ucXQa2c1 /yyreSRZZ10NO1PjzCy5wthVCuSGaBXy2OBoLbF2ijWoQDU+se5FvH4dIqR1+lemAnNewr 9mfVVCw2MV2qMummJQv/7DgowiJtpSH6LnR/G35azl7PuhzramHQ5RCNhbIIZedsNJHwJn p7OsGm/z9hCNMgCup413c3cHixr7tUNLNeYKsG0eVX49A2xWR10xGMI4MdTBUQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1681751039; a=rsa-sha256; cv=none; b=Z420b2UrFyM5ktFl+Z1KK2Yr4Of0DQRocxkfQ9NMhRZty16KFTcsHZTAQMGHeft9Jf+pdy dMI/uOsU12rSrPB3/EHsAsDOjsuSfmgYSfqEmzpoZHrPVVFbmQUWtCF4ByBgEBQnAHHtzQ a0L4g/oe3v7OewVmRH/pumxbGrLCp6Bpea031zFCuWrLQwVvrwisfQkSinP02Li63V6A2W 7yS7X5IlbYf+VRDvhDtaeMTMgxBszOO2NlN0B5J38mHHpfV6PKL79dXlFOKQSTjbyeBTxu lrK92AnqXeY3MtqUazMgYpHdXnLnsuNqYwx3jBjEHMpIz8BaR66uNYXbwEd50A== 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 4Q0YL71MlGzcyx; Mon, 17 Apr 2023 17:03:59 +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 33HH3xPb002508; Mon, 17 Apr 2023 17:03:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33HH3x4j002507; Mon, 17 Apr 2023 17:03:59 GMT (envelope-from git) Date: Mon, 17 Apr 2023 17:03:59 GMT Message-Id: <202304171703.33HH3x4j002507@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 5cdaedd8cc6a - stable/13 - physmem: add ram0 pseudo-driver 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 5cdaedd8cc6a628a7c4c62e6f415b21f2e842235 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=5cdaedd8cc6a628a7c4c62e6f415b21f2e842235 commit 5cdaedd8cc6a628a7c4c62e6f415b21f2e842235 Author: Mitchell Horne AuthorDate: 2021-05-27 14:27:40 +0000 Commit: Mitchell Horne CommitDate: 2023-04-17 16:02:56 +0000 physmem: add ram0 pseudo-driver Its purpose is to reserve all I/O space belonging to physical memory from nexus, preventing it from being handed out by bus_alloc_resource() to callers such as xenpv_alloc_physmem(), which looks for the first available free range it can get. This mimics the existing pseudo-driver on x86. If needed, the device can be disabled with hint.ram.0.disabled="1" in /boot/device.hints. Reviewed by: imp MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D32343 (cherry picked from commit e6cf1a0826c9d7f229e41224ec7b783501636528) --- sys/kern/subr_physmem.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/sys/kern/subr_physmem.c b/sys/kern/subr_physmem.c index 450b891cb8a1..959394e06d4b 100644 --- a/sys/kern/subr_physmem.c +++ b/sys/kern/subr_physmem.c @@ -40,7 +40,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include +#include #include #ifdef _KERNEL @@ -49,7 +51,9 @@ __FBSDID("$FreeBSD$"); #include #include #include + #include +#include #else #include #include @@ -525,7 +529,6 @@ physmem_init_kernel_globals(void) panic("No memory entries in phys_avail"); Maxmem = atop(phys_avail[nextidx - 1]); } -#endif #ifdef DDB #include @@ -537,3 +540,98 @@ DB_SHOW_COMMAND(physmem, db_show_physmem) } #endif /* DDB */ + +/* + * ram pseudo driver - this reserves I/O space resources corresponding to physical + * memory regions. + */ + +static void +ram_identify(driver_t *driver, device_t parent) +{ + + if (resource_disabled("ram", 0)) + return; + if (BUS_ADD_CHILD(parent, 0, "ram", 0) == NULL) + panic("ram_identify"); +} + +static int +ram_probe(device_t dev) +{ + + device_quiet(dev); + device_set_desc(dev, "System RAM"); + return (BUS_PROBE_SPECIFIC); +} + +static int +ram_attach(device_t dev) +{ + vm_paddr_t avail_list[PHYS_AVAIL_COUNT]; + rman_res_t start, end; + struct region *hwp; + int rid, i; + + rid = 0; + + /* Get the avail list. */ + bzero(avail_list, sizeof(avail_list)); + regions_to_avail(avail_list, EXFLAG_NOALLOC | EXFLAG_NODUMP, + PHYS_AVAIL_COUNT, 0, NULL, NULL); + + /* Reserve all memory regions. */ + for (i = 0; avail_list[i + 1] != 0; i += 2) { + start = avail_list[i]; + end = avail_list[i + 1]; + + if (bootverbose) + device_printf(dev, + "reserving memory region: %jx-%jx\n", + (uintmax_t)start, (uintmax_t)end); + + if (bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, end, + end - start, 0) == NULL) + panic("ram_attach: resource %d failed to attach", rid); + rid++; + } + + /* Now, reserve the excluded memory regions. */ + for (i = 0, hwp = exregions; i < excnt; i++, hwp++) { + start = hwp->addr; + end = hwp->addr + hwp->size; + + if (bootverbose) + device_printf(dev, + "reserving excluded region: %jx-%jx\n", + (uintmax_t)start, (uintmax_t)(end - 1)); + + /* + * Best-effort attempt to reserve the range. This may fail, as + * sometimes the excluded ranges provided by the device tree + * will cover or overlap some I/O range. + */ + if (bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, end, + end - start, 0) == NULL) { + if (bootverbose) + device_printf(dev, "failed to reserve region\n"); + continue; + } + rid++; + } + + return (0); +} + +static device_method_t ram_methods[] = { + /* Device interface */ + DEVMETHOD(device_identify, ram_identify), + DEVMETHOD(device_probe, ram_probe), + DEVMETHOD(device_attach, ram_attach), + + DEVMETHOD_END +}; + +DEFINE_CLASS_0(ram, ram_driver, ram_methods, /* no softc */ 1); +DRIVER_MODULE(ram, nexus, ram_driver, 0, 0); +#endif /* _KERNEL */