From nobody Wed Sep 21 14:10:13 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 4MXgKj1SNcz4cZbj for ; Wed, 21 Sep 2022 14:10:17 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 4MXgKh3hFjz4MvH for ; Wed, 21 Sep 2022 14:10:16 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: by mail-wr1-f46.google.com with SMTP id n10so10032363wrw.12 for ; Wed, 21 Sep 2022 07:10:16 -0700 (PDT) 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; bh=yo6UwbjDgKv5BjNihv7M9yzfm/KB7vrxVs5LqE7TEjI=; b=GR7vy47T6wjTBeTz3zkiiesAUVRg6234QHF7mHnbLw4xCl26RfFh4SZxqvfRj3sKNo YnnL4TptpUzgzOZAiZS2MGiPu0R+4hQ5HD7+pBrKZEGXrw7e1M+AIGUpfJqFBTbNF41W 9iQ5nxY88KRZ+rCN5nxkyvI+w328XNME3JNeGN4bCcybHPTuAJj/Ypn1wLl+TdUPHmRr B+348my9+XAgoqkFiqbHb73zws6aggtqzGb0o0jX60lgAer2SBgJYi3hwCmqZJ9iXOmW y5rkWcdkY1ECOwU+hxApEIkIEcueS6t+ZnxnxsncSGqRApc94bw87P0CFEMX8Qnr5CBe zF/A== X-Gm-Message-State: ACrzQf0NmIgkqDMblO965tKzmw1zL3PcEMa0Ft/6f+a5wP1Rqj8MdOTF aYlTtBwx1tWuCMUvtq37GcHJeQ== X-Google-Smtp-Source: AMsMyM50K8F4EcHEXSv9U4dtdSrmMCt3CpL/HuDot1XAMuQLuYHRQ44dtpGt1ihC5hXLbKgcnqrfPQ== X-Received: by 2002:adf:fb8d:0:b0:225:4d57:17a6 with SMTP id a13-20020adffb8d000000b002254d5717a6mr17502170wrr.251.1663769414780; Wed, 21 Sep 2022 07:10:14 -0700 (PDT) Received: from smtpclient.apple (global-5-141.n-2.net.cam.ac.uk. [131.111.5.141]) by smtp.gmail.com with ESMTPSA id bn27-20020a056000061b00b0022762b0e2a2sm2997977wrb.6.2022.09.21.07.10.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Sep 2022 07:10:14 -0700 (PDT) Content-Type: text/plain; charset=us-ascii 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.80.82.1.1\)) Subject: Re: git: e13c6a6fca71 - main - Teach the GICv3 driver about a vgic child From: Jessica Clarke In-Reply-To: <202209211000.28LA00ck091449@gitrepo.freebsd.org> Date: Wed, 21 Sep 2022 15:10:13 +0100 Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <1C9075B5-7757-467D-AE61-33AB45DEBB2D@freebsd.org> References: <202209211000.28LA00ck091449@gitrepo.freebsd.org> To: Andrew Turner X-Mailer: Apple Mail (2.3696.80.82.1.1) X-Rspamd-Queue-Id: 4MXgKh3hFjz4MvH X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of jrtc27@jrtc27.com designates 209.85.221.46 as permitted sender) smtp.mailfrom=jrtc27@jrtc27.com X-Spamd-Result: default: False [-2.47 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.97)[-0.974]; MV_CASE(0.50)[]; FORGED_SENDER(0.30)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17:c]; MIME_GOOD(-0.10)[text/plain]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-all@freebsd.org]; TO_DN_EQ_ADDR_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DMARC_NA(0.00)[freebsd.org]; RCVD_IN_DNSWL_NONE(0.00)[209.85.221.46:from]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FREEFALL_USER(0.00)[jrtc27]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[jrtc27@freebsd.org,jrtc27@jrtc27.com]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; R_DKIM_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.221.46:from] X-ThisMailContainsUnwantedMimeParts: N 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); Do we have anything to attach to this, or is this just creating children that will never do anything? > + if (child =3D=3D NULL) { > + device_printf(dev, "Could not add vgic = child\n"); > + } else { > + di =3D malloc(sizeof(*di), M_GIC_V3, M_WAITOK | = M_ZERO); > + resource_list_init(&di->di_rl); > + di->di_gic_dinfo.gic_domain =3D -1; > + di->di_gic_dinfo.is_vgic =3D 1; > + sc->gic_nchildren++; > + device_set_ivars(child, di); > + } > + } >=20 > acpi_unmap_table(madt); >=20 > diff --git a/sys/arm64/arm64/gic_v3_fdt.c = b/sys/arm64/arm64/gic_v3_fdt.c > index 0478bdc2962f..0ca362dc4aea 100644 > --- a/sys/arm64/arm64/gic_v3_fdt.c > +++ b/sys/arm64/arm64/gic_v3_fdt.c > @@ -212,9 +212,10 @@ static int > gic_v3_fdt_print_child(device_t bus, device_t child) > { > struct gic_v3_ofw_devinfo *di =3D device_get_ivars(child); > - struct resource_list *rl =3D &di->di_rl; > + struct resource_list *rl; > int retval =3D 0; >=20 > + rl =3D &di->di_rl; > retval +=3D bus_print_child_header(bus, child); > retval +=3D resource_list_print_type(rl, "mem", SYS_RES_MEMORY, = "%#jx"); > retval +=3D bus_print_child_footer(bus, child); > @@ -228,6 +229,8 @@ gic_v3_ofw_get_devinfo(device_t bus __unused, = device_t child) > struct gic_v3_ofw_devinfo *di; >=20 > di =3D device_get_ivars(child); > + if (di->di_gic_dinfo.is_vgic) > + return (NULL); > return (&di->di_dinfo); > } >=20 > @@ -352,5 +355,23 @@ gic_v3_ofw_bus_attach(device_t dev) > } > } >=20 > + /* > + * If there is a vgic maintanance interupt add a virtual gic s/interupt/interrupt/ Maybe also capitalise (V)GIC. > + * child so we can use this in the vmm module for bhyve. > + */ > + if (OF_hasprop(parent, "interrupts")) { > + child =3D device_add_child(dev, "vgic", -1); > + if (child =3D=3D NULL) { > + device_printf(dev, "Could not add vgic = child\n"); > + } else { > + di =3D malloc(sizeof(*di), M_GIC_V3, M_WAITOK | = M_ZERO); > + resource_list_init(&di->di_rl); > + di->di_gic_dinfo.gic_domain =3D -1; > + di->di_gic_dinfo.is_vgic =3D 1; > + device_set_ivars(child, di); > + sc->gic_nchildren++; These two lines are unnecessarily swapped compared with the ACPI version. > + } > + } > + > return (bus_generic_attach(dev)); > } > diff --git a/sys/arm64/arm64/gic_v3_var.h = b/sys/arm64/arm64/gic_v3_var.h > index 7722a48cb456..b66fe6c57bb2 100644 > --- a/sys/arm64/arm64/gic_v3_var.h > +++ b/sys/arm64/arm64/gic_v3_var.h > @@ -89,6 +89,7 @@ struct gic_v3_softc { > struct gic_v3_devinfo { > int gic_domain; > int msi_xref; > + int is_vgic; bool?.. Jess > }; >=20 > #define GIC_INTR_ISRC(sc, irq) (&sc->gic_irqs[irq].gi_isrc)