From nobody Wed Feb 08 21:06:17 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 4PBsx64tk1z3pK53; Wed, 8 Feb 2023 21:06:18 +0000 (UTC) (envelope-from mhorne@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (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 "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PBsx64LXsz3kjS; Wed, 8 Feb 2023 21:06:18 +0000 (UTC) (envelope-from mhorne@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675890378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p75L6uADwx3qbqOKQOsyUlEJ7JeCMkiCoD2Y/1J4Pz8=; b=vNP/7wSdP1PYNHefjkPBpHqROb4fbXvpPaAZLz8up6Tidz395LLNrneFwPWuWfAsaYZZn7 ur6XMXlpKaskDoPQCtAm/8pMmGNN/akEgRK24LBZVExEVx8E7JOYtqABG28zShtu4Xu3Xy lChLSOeS1FXv0bxqrOKNm0ZV8UL04NZ6xxIlLAHh5jaEW5SxftolobNenprWH6hRV4E1fv P7kKpxFv/YTgXr3n6uMMozXcsmFfctwMqGYQdKxPm4p1ZHyC+rlX59hnitJHoB96+hO+iK zNvqJWoqH8ZulLsI/9ZJvOirn9UtoEwFFSeLIW6IhSIRNheVqc/oCUSJeef8+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675890378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p75L6uADwx3qbqOKQOsyUlEJ7JeCMkiCoD2Y/1J4Pz8=; b=nZoI/6AHSglewkkjpNc/XynHi7Vv+acQPjz7xuskM7gdUh9MYFzwpSzNdpK/Sopmd6RVf0 HfcH1eTfG89eOl211oiP/S0Smiyi3A5lA58SmCOV365cazlmYbx+mG0/qtmEuhCyhjlFns hCgIMIvtFG5Ut7d+bT3PVs8TGJOto7fFUFqSstgb2PpbOkPdaYJEykHzxCaEWEF+zoEae4 liCM2+PLDnfeZHETtpjaBMEtgQvGwnNpum6luXn+Kn87IaqayyqWJp56Xx2KAD02sHjBgA pYc2jI7o1EttnmBvEgn1ZiqGyhPRVPTY4jUiaAKp5kriPbZGwP2XuiJ2GO/LfQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675890378; a=rsa-sha256; cv=none; b=qkoQoXjhfyH3ETscH59JWlRRu6NBjHLFv5wvt58eAXdv1lVP8jWg5j+ur2xupIvFN7fxHU ip1vcLVYm+6Uqwh/vLywkVasd7uKJIVo7oNuvDUqCPgSb2pi78cK/dSyPyff9vNAjbqEI+ DPsM5cA1rywGKMk6WVc+sUjbP+i7DsmDUfEueos0RWlY2WthVid9uL88VAVftmwv1k06ov gfcGp5gxT4IJdGobhBSWEuU8ba/4Bk5iK+Oc3zstvstdAtwWgM4yv+uhCyiOL3GW9CCVf9 QA7d3VTrPuj91SnS8b6GdeVDXJ+U8yzVhbJCSkKa9t1n8zv28cOCB0gEnna1lw== Received: from [192.168.1.151] (host-173-212-76-127.public.eastlink.ca [173.212.76.127]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mhorne) by smtp.freebsd.org (Postfix) with ESMTPSA id 4PBsx61FyCz12QZ; Wed, 8 Feb 2023 21:06:18 +0000 (UTC) (envelope-from mhorne@freebsd.org) Message-ID: Date: Wed, 8 Feb 2023 17:06:17 -0400 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 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: git: e6cf1a0826c9 - main - physmem: add ram0 pseudo-driver Content-Language: en-CA To: Jessica Clarke Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" References: <202302082052.318KqOE6052473@gitrepo.freebsd.org> <26339898-C02C-42D4-916A-2B6AD2562B02@freebsd.org> From: Mitchell Horne In-Reply-To: <26339898-C02C-42D4-916A-2B6AD2562B02@freebsd.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ThisMailContainsUnwantedMimeParts: N On 2/8/23 16:55, Jessica Clarke wrote: > On 8 Feb 2023, at 20:52, Mitchell Horne wrote: >> >> 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 > > If it’s RAM then it’s not I/O, and if it’s I/O then it’s not RAM? > > Jess > Yes, they are distinct. And yet, they share an address space. So this is to assist in the SYS_RES_MEMORY resource bookkeeping. Did I misuse some terminology, or what is your actual question? >> 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 */ >