From nobody Wed Feb 8 21:13:28 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 4PBt5R5Cq2z3pL0y for ; Wed, 8 Feb 2023 21:13:31 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PBt5R0HZsz3p75 for ; Wed, 8 Feb 2023 21:13:31 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-wm1-f50.google.com with SMTP id az4-20020a05600c600400b003dff767a1f1so86834wmb.2 for ; Wed, 08 Feb 2023 13:13:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZG9pwPOxuVFMBjMWOGwHmHShVUUy+PsprH7hhW0UaxQ=; b=f/GHkmtLbx383t6/HepiAL91YCaAb5X42udtAvrjd+LwOeA6w8KsnypEm426gR0HPq WsXc2vgNCmFDVeDB5OQNmGJpNRGO5ZwXjLDHBbak1+9d3VDbgwsgm2OQMnM6kzjpAhFG /PnT+iA9ucQ/8J9wEWS+6HFWTzxNv350sAjLhKg1mYTpKsIcxAyV8rW3gqeLUEYHujDg nD2Ks4kUcnFXpShG+V3ag7nSR9SvO6jFkW74AdtAyiEtd078+KEmp653lMA8n1Bgt1HE Aa29Dt8HybGvlQ0M8VTqFZayuK/ra0q2YFLg1FZzw6ujVe0LdaotgvRnq0LrvipcJwFH Yazw== X-Gm-Message-State: AO0yUKUrfYjCH/2/cU08chOS/6flPP8jFZjtErCY/lUwBZrX+MR/76jH A1W4fZUrWGyqj1k03ukTBsAzcQ== X-Google-Smtp-Source: AK7set/oQ658hK2825ue2W1ozzXoaO6uNdsavKnh9uIJaIEYu1ciwvahvO7OXH12EPP/uKSDG6wr+Q== X-Received: by 2002:a05:600c:80f:b0:3d2:2d2a:d581 with SMTP id k15-20020a05600c080f00b003d22d2ad581mr7768960wmp.30.1675890809754; Wed, 08 Feb 2023 13:13:29 -0800 (PST) Received: from smtpclient.apple (global-5-143.n-2.net.cam.ac.uk. [131.111.5.143]) by smtp.gmail.com with ESMTPSA id j37-20020a05600c1c2500b003daf6e3bc2fsm7199646wms.1.2023.02.08.13.13.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Feb 2023 13:13:29 -0800 (PST) Content-Type: text/plain; charset=utf-8 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 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: git: e6cf1a0826c9 - main - physmem: add ram0 pseudo-driver From: Jessica Clarke In-Reply-To: Date: Wed, 8 Feb 2023 21:13:28 +0000 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <505D72C8-1F67-46C8-A6EF-39392841FBF5@freebsd.org> References: <202302082052.318KqOE6052473@gitrepo.freebsd.org> <26339898-C02C-42D4-916A-2B6AD2562B02@freebsd.org> To: Mitchell Horne X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Rspamd-Queue-Id: 4PBt5R0HZsz3p75 X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On 8 Feb 2023, at 21:06, Mitchell Horne wrote: >=20 > On 2/8/23 16:55, Jessica Clarke wrote: >> On 8 Feb 2023, at 20:52, Mitchell Horne wrote: >>>=20 >>> The branch main has been updated by mhorne: >>>=20 >>> URL: = https://cgit.FreeBSD.org/src/commit/?id=3De6cf1a0826c9d7f229e41224ec7b7835= 01636528 >>>=20 >>> commit e6cf1a0826c9d7f229e41224ec7b783501636528 >>> Author: Mitchell Horne >>> AuthorDate: 2021-05-27 14:27:40 +0000 >>> Commit: Mitchell Horne >>> CommitDate: 2023-02-08 20:50:46 +0000 >>>=20 >>> physmem: add ram0 pseudo-driver >>>=20 >>> Its purpose is to reserve all I/O space belonging to physical = memory >> If it=E2=80=99s RAM then it=E2=80=99s not I/O, and if it=E2=80=99s = I/O then it=E2=80=99s not RAM? >> Jess >=20 > 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? The commit message just doesn=E2=80=99t make sense to me, it switches = between talking about I/O space and memory (same applies to the comments in the code). Is this reserving I/O parts of the address space so SYS_RES_MEMORY doesn=E2=80=99t include them (which doesn=E2=80=99t = *belong* to physical memory, just resides in the same address space), reserving FDT/ACPI-reserved actual RAM memory regions so SYS_RES_MEMORY doesn=E2=80=99= t include them (which isn=E2=80=99t I/O space), or both? Currently it = reads to me as describing part of one and part of the other, but neither fully. Jess >>> 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. >>>=20 >>> If needed, the device can be disabled with = hint.ram.0.disabled=3D"1" in >>> /boot/device.hints. >>>=20 >>> 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(-) >>>=20 >>> 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$"); >>>=20 >>> #include >>> #include >>> +#include >>> #include >>> +#include >>> #include >>>=20 >>> #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 =3D atop(phys_avail[nextidx - 1]); >>> } >>> -#endif >>>=20 >>> #ifdef DDB >>> #include >>> @@ -536,3 +539,98 @@ DB_SHOW_COMMAND_FLAGS(physmem, db_show_physmem, = DB_CMD_MEMSAFE) >>> } >>>=20 >>> #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) =3D=3D 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 =3D 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 =3D 0; avail_list[i + 1] !=3D 0; i +=3D 2) { >>> + start =3D avail_list[i]; >>> + end =3D 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) =3D=3D NULL) >>> + panic("ram_attach: resource %d failed to = attach", rid); >>> + rid++; >>> + } >>> + >>> + /* Now, reserve the excluded memory regions. */ >>> + for (i =3D 0, hwp =3D exregions; i < excnt; i++, hwp++) { >>> + start =3D hwp->addr; >>> + end =3D 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) =3D=3D NULL) { >>> + if (bootverbose) >>> + device_printf(dev, "failed to reserve = region\n"); >>> + continue; >>> + } >>> + rid++; >>> + } >>> + >>> + return (0); >>> +} >>> + >>> +static device_method_t ram_methods[] =3D { >>> + /* 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 */