From nobody Fri Sep 23 14:46:45 2022 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 4MYwGT2RBcz4dBKY; Fri, 23 Sep 2022 14:56:49 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from fry.fubar.geek.nz (fry.fubar.geek.nz [139.59.165.16]) by mx1.freebsd.org (Postfix) with ESMTP id 4MYwGS2RGQz4Fdy; Fri, 23 Sep 2022 14:56:48 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from smtpclient.apple (cpc91214-cmbg18-2-0-cust234.5-4.cable.virginm.net [81.102.75.235]) by fry.fubar.geek.nz (Postfix) with ESMTPSA id 05E754E659; Fri, 23 Sep 2022 14:46:45 +0000 (UTC) From: Andrew Turner Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_D48D8010-9C1C-4854-8E75-50154E0EED7B" 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 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: git: e13c6a6fca71 - main - Teach the GICv3 driver about a vgic child Date: Fri, 23 Sep 2022 15:46:45 +0100 In-Reply-To: <1C9075B5-7757-467D-AE61-33AB45DEBB2D@freebsd.org> Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" To: Jessica Clarke References: <202209211000.28LA00ck091449@gitrepo.freebsd.org> <1C9075B5-7757-467D-AE61-33AB45DEBB2D@freebsd.org> X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Rspamd-Queue-Id: 4MYwGS2RGQz4Fdy X-Spamd-Bar: + Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=softfail (mx1.freebsd.org: 139.59.165.16 is neither permitted nor denied by domain of andrew@FreeBSD.org) smtp.mailfrom=andrew@FreeBSD.org X-Spamd-Result: default: False [1.00 / 15.00]; VIOLATED_DIRECT_SPF(3.50)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; RCVD_NO_TLS_LAST(0.10)[]; R_DKIM_NA(0.00)[]; ASN(0.00)[asn:14061, ipnet:139.59.160.0/20, country:US]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; MLMMJ_DEST(0.00)[dev-commits-src-all@FreeBSD.org,dev-commits-src-main@FreeBSD.org]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; GREYLIST(0.00)[pass,body]; FROM_HAS_DN(0.00)[]; FREEFALL_USER(0.00)[andrew]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; RCPT_COUNT_THREE(0.00)[4]; DMARC_NA(0.00)[freebsd.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N --Apple-Mail=_D48D8010-9C1C-4854-8E75-50154E0EED7B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 21 Sep 2022, at 15:10, Jessica Clarke wrote: >=20 > On 21 Sept 2022, at 11:00, Andrew Turner > wrote: >>=20 >> The branch main has been updated by andrew: >>=20 >> URL: = https://cgit.FreeBSD.org/src/commit/?id=3De13c6a6fca7177fb9143ce629c2e33b3= 5b6c4219 >>=20 >> commit e13c6a6fca7177fb9143ce629c2e33b35b6c4219 >> Author: Andrew Turner >> AuthorDate: 2022-09-14 16:29:29 +0000 >> Commit: Andrew Turner >> CommitDate: 2022-09-21 09:59:13 +0000 >>=20 >> Teach the GICv3 driver about a vgic child >>=20 >> This will be used by bhyve to attach a virtual GIC driver. >>=20 >> Sponsored by: Innovate UK >> Sponsored by: The FreeBSD Foundation >> Differential Revision: https://reviews.freebsd.org/D36590 >> --- >> sys/arm/arm/gic_common.h | 2 ++ >> sys/arm64/arm64/gic_v3.c | 7 +++++++ >> sys/arm64/arm64/gic_v3_acpi.c | 36 = ++++++++++++++++++++++++++++++++++-- >> sys/arm64/arm64/gic_v3_fdt.c | 23 ++++++++++++++++++++++- >> sys/arm64/arm64/gic_v3_var.h | 1 + >> 5 files changed, 66 insertions(+), 3 deletions(-) >>=20 >> diff --git a/sys/arm/arm/gic_common.h b/sys/arm/arm/gic_common.h >> index 9e8fb19300ca..42ec44bb7fab 100644 >> --- a/sys/arm/arm/gic_common.h >> +++ b/sys/arm/arm/gic_common.h >> @@ -33,6 +33,7 @@ >>=20 >> #define GIC_IVAR_HW_REV 500 >> #define GIC_IVAR_BUS 501 >> +#define GIC_IVAR_VGIC 502 >>=20 >> /* GIC_IVAR_BUS values */ >> #define GIC_BUS_UNKNOWN 0 >> @@ -42,6 +43,7 @@ >>=20 >> __BUS_ACCESSOR(gic, hw_rev, GIC, HW_REV, u_int); >> __BUS_ACCESSOR(gic, bus, GIC, BUS, u_int); >> +__BUS_ACCESSOR(gic, vgic, GIC, VGIC, u_int); >>=20 >> /* Software Generated Interrupts */ >> #define GIC_FIRST_SGI 0 /* Irqs 0-15 are = SGIs/IPIs. */ >> diff --git a/sys/arm64/arm64/gic_v3.c b/sys/arm64/arm64/gic_v3.c >> index 27f41c58fe92..b4678d95fee5 100644 >> --- a/sys/arm64/arm64/gic_v3.c >> +++ b/sys/arm64/arm64/gic_v3.c >> @@ -456,6 +456,7 @@ static int >> gic_v3_read_ivar(device_t dev, device_t child, int which, uintptr_t = *result) >> { >> struct gic_v3_softc *sc; >> + struct gic_v3_devinfo *di; >>=20 >> sc =3D device_get_softc(dev); >>=20 >> @@ -481,6 +482,12 @@ gic_v3_read_ivar(device_t dev, device_t child, = int which, uintptr_t *result) >> ("gic_v3_read_ivar: Invalid bus type %u", = sc->gic_bus)); >> *result =3D sc->gic_bus; >> return (0); >> + case GIC_IVAR_VGIC: >> + di =3D device_get_ivars(child); >> + if (di =3D=3D NULL) >> + return (EINVAL); >> + *result =3D di->is_vgic; >> + return (0); >> } >>=20 >> return (ENOENT); >> diff --git a/sys/arm64/arm64/gic_v3_acpi.c = b/sys/arm64/arm64/gic_v3_acpi.c >> index cbe4d5989ec2..cc24b7824ff1 100644 >> --- a/sys/arm64/arm64/gic_v3_acpi.c >> +++ b/sys/arm64/arm64/gic_v3_acpi.c >> @@ -48,6 +48,9 @@ __FBSDID("$FreeBSD$"); >> #include "gic_v3_reg.h" >> #include "gic_v3_var.h" >>=20 >> +#define GICV3_PRIV_VGIC 0x80000000 >> +#define GICV3_PRIV_FLAGS 0x80000000 >> + >> struct gic_v3_acpi_devinfo { >> struct gic_v3_devinfo di_gic_dinfo; >> struct resource_list di_rl; >> @@ -86,6 +89,7 @@ struct madt_table_data { >> ACPI_MADT_GENERIC_DISTRIBUTOR *dist; >> int count; >> bool rdist_use_gicc; >> + bool have_vgic; >> }; >>=20 >> static void >> @@ -152,6 +156,8 @@ rdist_map(ACPI_SUBTABLE_HEADER *entry, void *arg) >> BUS_SET_RESOURCE(madt_data->parent, madt_data->dev, >> SYS_RES_MEMORY, madt_data->count, = intr->GicrBaseAddress, >> count); >> + if (intr->VgicInterrupt =3D=3D 0) >> + madt_data->have_vgic =3D false; >>=20 >> default: >> break; >> @@ -164,6 +170,7 @@ gic_v3_acpi_identify(driver_t *driver, device_t = parent) >> struct madt_table_data madt_data; >> ACPI_TABLE_MADT *madt; >> vm_paddr_t physaddr; >> + uintptr_t private; >> device_t dev; >>=20 >> physaddr =3D acpi_find_table(ACPI_SIG_MADT); >> @@ -210,6 +217,7 @@ gic_v3_acpi_identify(driver_t *driver, device_t = parent) >>=20 >> madt_data.dev =3D dev; >> madt_data.rdist_use_gicc =3D false; >> + madt_data.have_vgic =3D true; >> acpi_walk_subtables(madt + 1, (char *)madt + = madt->Header.Length, >> rdist_map, &madt_data); >> if (madt_data.count =3D=3D 0) { >> @@ -222,7 +230,12 @@ gic_v3_acpi_identify(driver_t *driver, device_t = parent) >> rdist_map, &madt_data); >> } >>=20 >> - acpi_set_private(dev, (void = *)(uintptr_t)madt_data.dist->Version); >> + private =3D madt_data.dist->Version; >> + /* Flag that the VGIC is in use */ >> + if (madt_data.have_vgic) >> + private |=3D GICV3_PRIV_VGIC; >> + >> + acpi_set_private(dev, (void *)private); >>=20 >> out: >> acpi_unmap_table(madt); >> @@ -232,7 +245,7 @@ static int >> gic_v3_acpi_probe(device_t dev) >> { >>=20 >> - switch((uintptr_t)acpi_get_private(dev)) { >> + switch((uintptr_t)acpi_get_private(dev) & ~GICV3_PRIV_FLAGS) { >> case ACPI_MADT_GIC_VERSION_V3: >> case ACPI_MADT_GIC_VERSION_V4: >> break; >> @@ -390,9 +403,14 @@ gic_v3_add_children(ACPI_SUBTABLE_HEADER *entry, = void *arg) >> static void >> gic_v3_acpi_bus_attach(device_t dev) >> { >> + struct gic_v3_acpi_devinfo *di; >> + struct gic_v3_softc *sc; >> ACPI_TABLE_MADT *madt; >> + device_t child; >> vm_paddr_t physaddr; >>=20 >> + sc =3D device_get_softc(dev); >> + >> physaddr =3D acpi_find_table(ACPI_SIG_MADT); >> if (physaddr =3D=3D 0) >> return; >> @@ -405,6 +423,20 @@ gic_v3_acpi_bus_attach(device_t dev) >>=20 >> acpi_walk_subtables(madt + 1, (char *)madt + = madt->Header.Length, >> gic_v3_add_children, dev); >> + /* Add the vgic child if needed */ >> + if (((uintptr_t)acpi_get_private(dev) & GICV3_PRIV_FLAGS) !=3D = 0) { >> + child =3D device_add_child(dev, "vgic", -1); >=20 > Do we have anything to attach to this, or is this just creating > children that will never do anything? This will be used by Bhyve to attach a virtual gic driver so we can use = standard methods to handle interacting with the hardware. Andrew --Apple-Mail=_D48D8010-9C1C-4854-8E75-50154E0EED7B Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii

On 21 Sep 2022, at 15:10, Jessica Clarke <jrtc27@freebsd.org> = wrote:

On 21 Sept 2022, at 11:00, Andrew Turner <andrew@FreeBSD.org> wrote:

The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=3De13c6a6fca7177fb9143c= e629c2e33b35b6c4219

commit = e13c6a6fca7177fb9143ce629c2e33b35b6c4219
Author: =     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: = 2022-09-14 16:29:29 +0000
Commit: =     Andrew Turner <andrew@FreeBSD.org>
CommitDate: = 2022-09-21 09:59:13 +0000

  Teach = the GICv3 driver about a vgic child

  This will be used by bhyve to attach a virtual = GIC driver.

  Sponsored by: =   Innovate UK
  Sponsored by: =   The FreeBSD Foundation
  Differential = Revision: https://reviews.freebsd.org/D36590
---
sys/arm/arm/gic_common.h      | =  2 ++
sys/arm64/arm64/gic_v3.c =      |  7 +++++++
sys/arm64/arm64/gic_v3_acpi.c | 36 = ++++++++++++++++++++++++++++++++++--
sys/arm64/arm64/gic_v3_fdt.c  | 23 = ++++++++++++++++++++++-
sys/arm64/arm64/gic_v3_var.h =  |  1 +
5 files changed, 66 insertions(+), 3 = deletions(-)

diff --git = a/sys/arm/arm/gic_common.h b/sys/arm/arm/gic_common.h
index = 9e8fb19300ca..42ec44bb7fab 100644
--- = a/sys/arm/arm/gic_common.h
+++ = b/sys/arm/arm/gic_common.h
@@ -33,6 +33,7 @@

#define GIC_IVAR_HW_REV 500
#define GIC_IVAR_BUS 501
+#define = GIC_IVAR_VGIC 502

/* GIC_IVAR_BUS values = */
#define GIC_BUS_UNKNOWN 0
@@ -42,6 +43,7 @@

__BUS_ACCESSOR(gic, hw_rev, GIC, HW_REV, u_int);
__BUS_ACCESSOR(gic, bus, GIC, BUS, u_int);
+__BUS_ACCESSOR(gic, vgic, GIC, VGIC, u_int);
/* Software Generated Interrupts */
#define = GIC_FIRST_SGI  0 /* Irqs = 0-15 are SGIs/IPIs. */
diff --git = a/sys/arm64/arm64/gic_v3.c b/sys/arm64/arm64/gic_v3.c
index = 27f41c58fe92..b4678d95fee5 100644
--- = a/sys/arm64/arm64/gic_v3.c
+++ = b/sys/arm64/arm64/gic_v3.c
@@ -456,6 +456,7 @@ static = int
gic_v3_read_ivar(device_t dev, device_t child, int = which, uintptr_t *result)
{
struct = gic_v3_softc *sc;
+ struct gic_v3_devinfo *di;

sc =3D device_get_softc(dev);

@@ -481,6 +482,12 @@ gic_v3_read_ivar(device_t = dev, device_t child, int which, uintptr_t *result)
    ("gic_v3_re= ad_ivar: Invalid bus type %u", sc->gic_bus));
*result =3D= sc->gic_bus;
return (0);
+ case = GIC_IVAR_VGIC:
+ di =3D = device_get_ivars(child);
+ if (di =3D=3D NULL)
+ = = = return (EINVAL);
+ *result =3D di->is_vgic;
+ = = return (0);
}

= return (ENOENT);
diff --git = a/sys/arm64/arm64/gic_v3_acpi.c b/sys/arm64/arm64/gic_v3_acpi.c
index cbe4d5989ec2..cc24b7824ff1 100644
--- = a/sys/arm64/arm64/gic_v3_acpi.c
+++ = b/sys/arm64/arm64/gic_v3_acpi.c
@@ -48,6 +48,9 @@ = __FBSDID("$FreeBSD$");
#include "gic_v3_reg.h"
#include "gic_v3_var.h"

+#define GICV3_PRIV_VGIC 0x80000000
+#define GICV3_PRIV_FLAGS 0x80000000
+
struct gic_v3_acpi_devinfo {
struct = gic_v3_devinfo di_gic_dinfo;
struct resource_list di_rl;
@@ -86,6 +89,7 @@ struct madt_table_data {
= ACPI_MADT_GENERIC_DISTRIBUTOR *dist;
int = count;
bool rdist_use_gicc;
+ bool = have_vgic;
};

static void
@@ -152,6 +156,8 @@ rdist_map(ACPI_SUBTABLE_HEADER *entry, = void *arg)
= BUS_SET_RESOURCE(madt_data->parent, madt_data->dev,
= =     SYS_RES_MEM= ORY, madt_data->count, intr->GicrBaseAddress,
    count);
+ = = if (intr->VgicInterrupt =3D=3D 0)
+ = madt_data->have_vgic =3D false;

= default:
break;
@@ -164,6 = +170,7 @@ gic_v3_acpi_identify(driver_t *driver, device_t parent)
= struct madt_table_data madt_data;
= ACPI_TABLE_MADT *madt;
vm_paddr_t physaddr;
+ = uintptr_t private;
device_t dev;

= physaddr =3D acpi_find_table(ACPI_SIG_MADT);
@@ = -210,6 +217,7 @@ gic_v3_acpi_identify(driver_t *driver, device_t = parent)

madt_data.dev =3D dev;
= madt_data.rdist_use_gicc =3D false;
+ = madt_data.have_vgic =3D true;
= acpi_walk_subtables(madt + 1, (char *)madt + = madt->Header.Length,
    rdist_map, = &madt_data);
if (madt_data.count =3D=3D 0) = {
@@ -222,7 +230,12 @@ gic_v3_acpi_identify(driver_t = *driver, device_t parent)
    rdist_map, = &madt_data);
}

- = acpi_set_private(dev, (void = *)(uintptr_t)madt_data.dist->Version);
+ private =3D= madt_data.dist->Version;
+ /* Flag that the VGIC is in use = */
+ if (madt_data.have_vgic)
+ private = |=3D GICV3_PRIV_VGIC;
+
+ = acpi_set_private(dev, (void *)private);

out:
acpi_unmap_table(madt);
@@ -232,7 +245,7 @@ static int
gic_v3_acpi_probe(device_t dev)
{

- = switch((uintptr_t)acpi_get_private(dev)) {
+ = switch((uintptr_t)acpi_get_private(dev) & ~GICV3_PRIV_FLAGS) = {
case ACPI_MADT_GIC_VERSION_V3:
case = ACPI_MADT_GIC_VERSION_V4:
break;
@@ -390,9 = +403,14 @@ gic_v3_add_children(ACPI_SUBTABLE_HEADER *entry, void = *arg)
static void
gic_v3_acpi_bus_attach(device_t dev)
{
+ = struct gic_v3_acpi_devinfo *di;
+ struct = gic_v3_softc *sc;
ACPI_TABLE_MADT *madt;
+ = device_t child;
vm_paddr_t physaddr;

+ sc =3D device_get_softc(dev);
+
physaddr =3D = acpi_find_table(ACPI_SIG_MADT);
if = (physaddr =3D=3D 0)
return;
@@ -405,6 = +423,20 @@ gic_v3_acpi_bus_attach(device_t dev)

= acpi_walk_subtables(madt + 1, (char *)madt + = madt->Header.Length,
    gic_v3_add_= children, dev);
+ /* Add the vgic child if needed = */
+ if (((uintptr_t)acpi_get_private(dev) & = GICV3_PRIV_FLAGS) !=3D 0) {
+ child =3D device_add_child(dev, = "vgic", -1);

Do we have anything to attach to this, or is this just = creating
children that = will never do anything?

This will be used by Bhyve to attach a virtual gic = driver so we can use standard methods to handle interacting with the = hardware.

Andrew

= --Apple-Mail=_D48D8010-9C1C-4854-8E75-50154E0EED7B--