From nobody Wed Feb 8 20:52:24 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 4PBsd50GL3z3pHXn; Wed, 8 Feb 2023 20:52:25 +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 4PBsd46ykwz3RGD; Wed, 8 Feb 2023 20:52:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675889545; 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=w+VtGVYfgisFvibOwfm/R1V/hfl6ui6D2+i9JPwrI+c=; b=E+i9gKNfgiOGeuWZKfF10y4EXgh4jagKxVCdRuIqO5syNgkQjwwUMEVa487N61db6fSaae VIpwwXNhicov8LZnIl9Pf0WtdEVrVdwXNOeLHcwbw7Zg26Zbp3aaZ/XokvIP8HXhkpuVPL VpVlCXEYeYhXq3apvBBuDVY4uo2ZhgC4wJpB/IoAa7KhGie82Kg5kM19EBdpHF/dOOQp4x 6IoukR08U4q5kJh/mtW7ezi9vQH7cydEcTqhQEa6FQVIeM9mRUN7LePvdRTQhKEp4nwpX5 PVqQZA7fSlTjMztGoHR2M/DMcftX8oIoAKh8xdenU4aBQPUKse5yeHpzlcYRYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675889545; 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=w+VtGVYfgisFvibOwfm/R1V/hfl6ui6D2+i9JPwrI+c=; b=gfPpqjQfmP39d5Drnlw4dRhzvjnxciv6Zj0PACuxBQXbskOK8f+YWH1qoJFspF0o4UON6i JZxmVikSgm9aWcnup4CwylSlsPUGOk4EQn5hiaJ0HlCGCojY9EYDsA7ZbCAvIR+e0o+Xxn Jo7RSA37AxWRsOUGIpfaQa6Bs1b//fMj4zLOeiX7TnO3wsAEr8S7GH8kXXFc0tcvE5nRWw VQ9nU7wUW8GV1Wc5hjS0zHhUNRTDfDc1KsQZkKnXGHxt/pLZhxbTB0N6XlIOkQAMxCxeAR kOpI0vePzS4ju9w5M6CTxpeDdzbdOJZ26y7F+UWpmdDdiv7VUJjUEp26Rj3GwA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675889545; a=rsa-sha256; cv=none; b=ssW6wYlvaQzmeTvG8LI2V6hEhJcyhrP4qES8iuMBUekg8wNEMjxs53sf8ClM1Zwu8XF4jR IUsMyyCntEetkGLFdLqjsyo3gO/Hb6mzoEc9M9BKEjZNOYNgNU2HfgvnLOgJWWPVly4b9k 5HfXWX7F3ns9lxz8lZ1j5ToD6dGFISSHTNnx2ZecfZmVFPkdpywZWEexG3nj2+71/+oCp1 3832PspYeWJvteyIV18yTkSz/saw3dRLepQVdDC1xPHHN7RkGfHNCJmzZksht4VdagjZ8a cHun1WUKMF2VB/7NMHYZ0JNLdWH+cCiY2dKa2nLONojSegWu1hDRpOhssoQUQg== 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 4PBsd4619Rz19qG; Wed, 8 Feb 2023 20:52:24 +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 318KqOoZ052474; Wed, 8 Feb 2023 20:52:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 318KqOE6052473; Wed, 8 Feb 2023 20:52:24 GMT (envelope-from git) Date: Wed, 8 Feb 2023 20:52:24 GMT Message-Id: <202302082052.318KqOE6052473@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: e6cf1a0826c9 - main - physmem: add ram0 pseudo-driver 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: e6cf1a0826c9d7f229e41224ec7b783501636528 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=e6cf1a0826c9d7f229e41224ec7b783501636528 commit e6cf1a0826c9d7f229e41224ec7b783501636528 Author: Mitchell Horne AuthorDate: 2021-05-27 14:27:40 +0000 Commit: Mitchell Horne CommitDate: 2023-02-08 20:50:46 +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 --- 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 498ad2440f40..bb6af5a580aa 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 @@ -524,7 +528,6 @@ physmem_init_kernel_globals(void) panic("No memory entries in phys_avail"); Maxmem = atop(phys_avail[nextidx - 1]); } -#endif #ifdef DDB #include @@ -536,3 +539,98 @@ DB_SHOW_COMMAND_FLAGS(physmem, db_show_physmem, DB_CMD_MEMSAFE) } #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 */