From nobody Fri May 17 02:41:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1587632773; cv=none; d=zohomail.com; s=zohoarc; b=UYxg6dSo5Ig9V7Sp00qUOTK70kC+VLsFH58ZsFqkUfzgdiLFfrgu2DnNPlR2VgJLAk0Gk4fXzXJu24CBsHO29cgiXPfe3FDQ256LUNrjPad74syLVeMMhZSpQt7btgLHVB4EEPZ16jZXdqKOuks/uZpINgWZLTWwhUCHFsJNzdw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587632773; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=r/fhSjRqs+Ys5sprbZ/8oJ7RI28IVckcHXOWtxh8yWA=; b=Sjy36oW0OsMAzqWg4W+YKGBop1pohgD4OkGWd/Z1D2YaJmsuDHjUfYb9IImGD0GH8NiTSLozha6wO5eWL3xDmPuBOI08jGwl8VIiB712oR9Uex9PeDRThARs2s0mDe/5wC1tyCqtRzckjwdG1blTPuU9TvRtd2ocqeQxZC7CWXk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587632773459717.0756216171269; Thu, 23 Apr 2020 02:06:13 -0700 (PDT) Received: from localhost ([::1]:39314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXoB-0006Tc-QL for importer@patchew.org; Thu, 23 Apr 2020 05:06:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36070) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXjd-0000kv-Np for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRXjb-0001DG-A0 for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:29 -0400 Received: from andre.telenet-ops.be ([2a02:1800:120:4::f00:15]:34532) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jRXja-0001Bg-2N for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:26 -0400 Received: from ramsan ([IPv6:2a02:1810:ac12:ed60:89cc:efc7:85ce:4669]) by andre.telenet-ops.be with bizsmtp id W91L2200i1RvcFS0191LLp; Thu, 23 Apr 2020 11:01:21 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXjU-0006kB-Al; Thu, 23 Apr 2020 11:01:20 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1jRXjU-0002vU-8q; Thu, 23 Apr 2020 11:01:20 +0200 From: Geert Uytterhoeven To: Peter Maydell , Paolo Bonzini , Alexander Graf , Linus Walleij , Bartosz Golaszewski , Magnus Damm Subject: [PATCH QEMU v2 1/5] ARM: PL061: Move TYPE_PL061 to hw/gpio/pl061.h Date: Thu, 23 Apr 2020 11:01:14 +0200 Message-Id: <20200423090118.11199-2-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200423090118.11199-1-geert+renesas@glider.be> References: <20200423090118.11199-1-geert+renesas@glider.be> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a02:1800:120:4::f00:15; envelope-from=geert@linux-m68k.org; helo=andre.telenet-ops.be X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a02:1800:120:4::f00:15 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, qemu-arm@nongnu.org, qemu-devel@nongnu.org, Geert Uytterhoeven Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move the definition of TYPE_PL061 to a new header file, so it can be used outside the driver. Signed-off-by: Geert Uytterhoeven Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v2: - New. --- MAINTAINERS | 1 + hw/gpio/pl061.c | 2 +- include/hw/gpio/pl061.h | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 include/hw/gpio/pl061.h diff --git a/MAINTAINERS b/MAINTAINERS index 8cbc1fac2bfcec86..e760f65270d29d5d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -538,6 +538,7 @@ F: hw/dma/pl080.c F: include/hw/dma/pl080.h F: hw/dma/pl330.c F: hw/gpio/pl061.c +F: include/hw/gpio/pl061.h F: hw/input/pl050.c F: hw/intc/pl190.c F: hw/sd/pl181.c diff --git a/hw/gpio/pl061.c b/hw/gpio/pl061.c index 2a828260bdb0b946..e776c09e474216ef 100644 --- a/hw/gpio/pl061.c +++ b/hw/gpio/pl061.c @@ -9,6 +9,7 @@ */ =20 #include "qemu/osdep.h" +#include "hw/gpio/pl061.h" #include "hw/irq.h" #include "hw/sysbus.h" #include "migration/vmstate.h" @@ -33,7 +34,6 @@ static const uint8_t pl061_id[12] =3D static const uint8_t pl061_id_luminary[12] =3D { 0x00, 0x00, 0x00, 0x00, 0x61, 0x00, 0x18, 0x01, 0x0d, 0xf0, 0x05, 0xb1= }; =20 -#define TYPE_PL061 "pl061" #define PL061(obj) OBJECT_CHECK(PL061State, (obj), TYPE_PL061) =20 typedef struct PL061State { diff --git a/include/hw/gpio/pl061.h b/include/hw/gpio/pl061.h new file mode 100644 index 0000000000000000..78cc40c52679dc4e --- /dev/null +++ b/include/hw/gpio/pl061.h @@ -0,0 +1,16 @@ +/* + * Arm PrimeCell PL061 General Purpose IO with additional Luminary Micro + * Stellaris bits. + * + * Copyright (c) 2007 CodeSourcery. + * Written by Paul Brook + * + * This code is licensed under the GPL. + */ + +#ifndef PL061_GPIO_H +#define PL061_GPIO_H + +#define TYPE_PL061 "pl061" + +#endif /* PL061_GPIO_H */ --=20 2.17.1 From nobody Fri May 17 02:41:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1587632832; cv=none; d=zohomail.com; s=zohoarc; b=Qd63n4ZqL3R/v1v2ZrrOWOikJe+68MfkpAqgEIJRGsXZNZr7y/3z4YTlF9g9FVl5/TVLe/MwMPNvQZwG9vde0YsH5xGuaSYSIubLYqF6dyuGPqLjQdx5tdllKpSxH4aZfNMDNT1QjNsqANh3RnIJdDF+wNY1USoGCIHYV9TIUR0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587632832; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=gQPourwy+wV4VFITxOhJ666uE3wNjxV0i241sx+iekM=; b=TZFjqrSl/U+wmvzvH4zAPAUwA2ejsEx5EdSVu8cyR/sWUifI4/tdkm9G8J+vUj+858l7r/zdfZoSvU4PuWGBAZEQYTAgeDwKbqc1BSqCbxXtZoyT4+6bbYZPJMaZdWinCUqcPSzgMbD8XgzaRHBtvgYj7s8ry8zQvefX8+AtD9k= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587632832356446.7069457800591; Thu, 23 Apr 2020 02:07:12 -0700 (PDT) Received: from localhost ([::1]:39332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXp9-0008Ev-3c for importer@patchew.org; Thu, 23 Apr 2020 05:07:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36132) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXjr-00010h-Hm for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRXjb-0001DS-HX for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:43 -0400 Received: from xavier.telenet-ops.be ([2a02:1800:120:4::f00:14]:36680) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jRXja-0001BW-2D for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:26 -0400 Received: from ramsan ([IPv6:2a02:1810:ac12:ed60:89cc:efc7:85ce:4669]) by xavier.telenet-ops.be with bizsmtp id W91L2200P1RvcFS0191LFD; Thu, 23 Apr 2020 11:01:21 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXjU-0006k9-Al; Thu, 23 Apr 2020 11:01:20 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1jRXjU-0002vW-9V; Thu, 23 Apr 2020 11:01:20 +0200 From: Geert Uytterhoeven To: Peter Maydell , Paolo Bonzini , Alexander Graf , Linus Walleij , Bartosz Golaszewski , Magnus Damm Subject: [PATCH QEMU v2 2/5] ARM: PL061: Extract pl061_create_fdt() Date: Thu, 23 Apr 2020 11:01:15 +0200 Message-Id: <20200423090118.11199-3-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200423090118.11199-1-geert+renesas@glider.be> References: <20200423090118.11199-1-geert+renesas@glider.be> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a02:1800:120:4::f00:14; envelope-from=geert@linux-m68k.org; helo=xavier.telenet-ops.be X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a02:1800:120:4::f00:14 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, qemu-arm@nongnu.org, qemu-devel@nongnu.org, Geert Uytterhoeven Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Move the code to create the DT node for the PL061 GPIO controller from hw/arm/virt.c to the PL061 driver, so it can be reused. While at it, make the created node comply with the PL061 Device Tree bindings: - Use generic node name "gpio" instead of "pl061", - Add missing "#interrupt-cells" and "interrupt-controller" properties. Signed-off-by: Geert Uytterhoeven --- v2: - New. --- hw/arm/virt.c | 20 +++----------------- hw/gpio/pl061.c | 42 +++++++++++++++++++++++++++++++++++++++++ include/hw/gpio/pl061.h | 7 +++++++ 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 7dc96abf72cf2b9a..c88c8850fbe00bdb 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -40,6 +40,7 @@ #include "hw/arm/primecell.h" #include "hw/arm/virt.h" #include "hw/block/flash.h" +#include "hw/gpio/pl061.h" #include "hw/vfio/vfio-calxeda-xgmac.h" #include "hw/vfio/vfio-amd-xgbe.h" #include "hw/display/ramfb.h" @@ -807,30 +808,16 @@ static void virt_powerdown_req(Notifier *n, void *opa= que) =20 static void create_gpio(const VirtMachineState *vms) { - char *nodename; DeviceState *pl061_dev; hwaddr base =3D vms->memmap[VIRT_GPIO].base; hwaddr size =3D vms->memmap[VIRT_GPIO].size; int irq =3D vms->irqmap[VIRT_GPIO]; - const char compat[] =3D "arm,pl061\0arm,primecell"; =20 pl061_dev =3D sysbus_create_simple("pl061", base, qdev_get_gpio_in(vms->gic, irq)); =20 - uint32_t phandle =3D qemu_fdt_alloc_phandle(vms->fdt); - nodename =3D g_strdup_printf("/pl061@%" PRIx64, base); - qemu_fdt_add_subnode(vms->fdt, nodename); - qemu_fdt_setprop_sized_cells(vms->fdt, nodename, "reg", - 2, base, 2, size); - qemu_fdt_setprop(vms->fdt, nodename, "compatible", compat, sizeof(comp= at)); - qemu_fdt_setprop_cell(vms->fdt, nodename, "#gpio-cells", 2); - qemu_fdt_setprop(vms->fdt, nodename, "gpio-controller", NULL, 0); - qemu_fdt_setprop_cells(vms->fdt, nodename, "interrupts", - GIC_FDT_IRQ_TYPE_SPI, irq, - GIC_FDT_IRQ_FLAGS_LEVEL_HI); - qemu_fdt_setprop_cell(vms->fdt, nodename, "clocks", vms->clock_phandle= ); - qemu_fdt_setprop_string(vms->fdt, nodename, "clock-names", "apb_pclk"); - qemu_fdt_setprop_cell(vms->fdt, nodename, "phandle", phandle); + uint32_t phandle =3D pl061_create_fdt(vms->fdt, "", 2, base, size, irq, + vms->clock_phandle); =20 gpio_key_dev =3D sysbus_create_simple("gpio-key", -1, qdev_get_gpio_in(pl061_dev, 3)); @@ -846,7 +833,6 @@ static void create_gpio(const VirtMachineState *vms) KEY_POWER); qemu_fdt_setprop_cells(vms->fdt, "/gpio-keys/poweroff", "gpios", phandle, 3, 0); - g_free(nodename); } =20 static void create_virtio_devices(const VirtMachineState *vms) diff --git a/hw/gpio/pl061.c b/hw/gpio/pl061.c index e776c09e474216ef..74ba733a8a5e8ca5 100644 --- a/hw/gpio/pl061.c +++ b/hw/gpio/pl061.c @@ -9,12 +9,14 @@ */ =20 #include "qemu/osdep.h" +#include "hw/arm/fdt.h" #include "hw/gpio/pl061.h" #include "hw/irq.h" #include "hw/sysbus.h" #include "migration/vmstate.h" #include "qemu/log.h" #include "qemu/module.h" +#include "sysemu/device_tree.h" =20 //#define DEBUG_PL061 1 =20 @@ -397,3 +399,43 @@ static void pl061_register_types(void) } =20 type_init(pl061_register_types) + +/* + * pl061_create_fdt: Create a DT node for a PL061 GPIO controller + * @fdt: device tree blob + * @parent: name of the parent node + * @n_cells: value of #address-cells and #size-cells + * @base: base address of the controller's register block + * @size: size of the controller's register block + * @irq: interrupt number + * @clock: phandle of the apb-pclk clock + * + * Return value: a phandle referring to the created DT node. + * + * See the DT Binding Documentation in the Linux kernel source tree: + * Documentation/devicetree/bindings/gpio/pl061-gpio.yaml + */ +uint32_t pl061_create_fdt(void *fdt, const char *parent, unsigned int n_ce= lls, + hwaddr base, hwaddr size, int irq, uint32_t cloc= k) +{ + char *nodename =3D g_strdup_printf("%s/gpio@%" PRIx64, parent, base); + static const char compat[] =3D "arm,pl061\0arm,primecell"; + uint32_t phandle =3D qemu_fdt_alloc_phandle(fdt); + + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_sized_cells(fdt, nodename, "reg", n_cells, base, n_ce= lls, + size); + qemu_fdt_setprop(fdt, nodename, "compatible", compat, sizeof(compat)); + qemu_fdt_setprop_cell(fdt, nodename, "#gpio-cells", 2); + qemu_fdt_setprop(fdt, nodename, "gpio-controller", NULL, 0); + qemu_fdt_setprop_cell(fdt, nodename, "#interrupt-cells", 2); + qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0); + qemu_fdt_setprop_cells(fdt, nodename, "interrupts", GIC_FDT_IRQ_TYPE_S= PI, + irq, GIC_FDT_IRQ_FLAGS_LEVEL_HI); + qemu_fdt_setprop_cell(fdt, nodename, "clocks", clock); + qemu_fdt_setprop_string(fdt, nodename, "clock-names", "apb_pclk"); + qemu_fdt_setprop_cell(fdt, nodename, "phandle", phandle); + g_free(nodename); + + return phandle; +} diff --git a/include/hw/gpio/pl061.h b/include/hw/gpio/pl061.h index 78cc40c52679dc4e..f98c6e24e0e68662 100644 --- a/include/hw/gpio/pl061.h +++ b/include/hw/gpio/pl061.h @@ -11,6 +11,13 @@ #ifndef PL061_GPIO_H #define PL061_GPIO_H =20 +#include + +#include "exec/hwaddr.h" + #define TYPE_PL061 "pl061" =20 +uint32_t pl061_create_fdt(void *fdt, const char *parent, unsigned int n_ce= lls, + hwaddr addr, hwaddr size, int irq, uint32_t cloc= k); + #endif /* PL061_GPIO_H */ --=20 2.17.1 From nobody Fri May 17 02:41:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1587632629; cv=none; d=zohomail.com; s=zohoarc; b=c4oXqxPCgBZobv7jG+Udy62z8b5Jjls5Q2DcKvM2H0+mACPI31KTJThbCC/mFJKJbyj81MYfml0uvniJcyqe2bOCsEr2hetGa/Pr/VOhmsfDNhTQaQ6zx+LaKw8Au7IkmyzF9aINZnXoOBu+ZMpkPRT5BpcxFZVhnz0+77/+O68= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587632629; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=N75Xm6uSO9WPL2LR9nnGf4nT74j78kOne0Ev0KPa4xo=; b=FqT5jIPrBnj1qbbSLSVkOngObVXOcDkLMMVbqunUeJ4/zZ7wxqkSaB99/vinsx98cgGH3qBlnrwCzKC8DSKn5xZmTwuf+x7HmjBPooxCA7a0zM5qadRu/uiJA6tIakbxhAWiF9Y0PdjGvog6j30GscbN9N1JAFyTrpTlC3rBMms= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587632629506734.6473403629196; Thu, 23 Apr 2020 02:03:49 -0700 (PDT) Received: from localhost ([::1]:39254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXls-00032K-79 for importer@patchew.org; Thu, 23 Apr 2020 05:03:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36066) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXjd-0000kL-CY for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRXjb-0001DC-9r for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:28 -0400 Received: from andre.telenet-ops.be ([2a02:1800:120:4::f00:15]:34546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jRXja-0001Bi-2O for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:26 -0400 Received: from ramsan ([IPv6:2a02:1810:ac12:ed60:89cc:efc7:85ce:4669]) by andre.telenet-ops.be with bizsmtp id W91L2200g1RvcFS0191LLo; Thu, 23 Apr 2020 11:01:21 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXjU-0006kC-BF; Thu, 23 Apr 2020 11:01:20 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1jRXjU-0002vY-AD; Thu, 23 Apr 2020 11:01:20 +0200 From: Geert Uytterhoeven To: Peter Maydell , Paolo Bonzini , Alexander Graf , Linus Walleij , Bartosz Golaszewski , Magnus Damm Subject: [PATCH QEMU v2 3/5] Add a GPIO backend using libgpiod Date: Thu, 23 Apr 2020 11:01:16 +0200 Message-Id: <20200423090118.11199-4-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200423090118.11199-1-geert+renesas@glider.be> References: <20200423090118.11199-1-geert+renesas@glider.be> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a02:1800:120:4::f00:15; envelope-from=geert@linux-m68k.org; helo=andre.telenet-ops.be X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a02:1800:120:4::f00:15 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, qemu-arm@nongnu.org, qemu-devel@nongnu.org, Geert Uytterhoeven Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a GPIO controller backend, to connect virtual GPIOs on the guest to physical GPIOs on the host. This allows the guest to control any external device connected to the physical GPIOs. Features and limitations: - The backend uses libgpiod on Linux, - For now only GPIO outputs are supported, - The number of GPIO lines mapped is limited to the number of GPIO lines available on the virtual GPIO controller. Future work: - GPIO inputs, - GPIO line configuration, - Optimizations for controlling multiple GPIO lines at once, - ... Signed-off-by: Geert Uytterhoeven --- v2: - Drop vgpios and gpios parameters, and map the full gpiochip instead, - Replace hardcoded PL061 instance by multiple dynamic instances, registered through qemu_gpiodev_add(). --- MAINTAINERS | 6 +++ backends/Makefile.objs | 2 + backends/gpiodev.c | 94 ++++++++++++++++++++++++++++++++++++++++ configure | 28 ++++++++++++ include/sysemu/gpiodev.h | 12 +++++ 5 files changed, 142 insertions(+) create mode 100644 backends/gpiodev.c create mode 100644 include/sysemu/gpiodev.h diff --git a/MAINTAINERS b/MAINTAINERS index e760f65270d29d5d..a70af47430083d14 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -607,6 +607,12 @@ F: include/hw/arm/digic.h F: hw/*/digic* F: include/hw/*/digic* =20 +GPIO device backend +M: Geert Uytterhoeven +S: Supported +F: backends/gpiodev.c +F: include/sysemu/gpiodev.h + Goldfish RTC M: Anup Patel M: Alistair Francis diff --git a/backends/Makefile.objs b/backends/Makefile.objs index 28a847cd571d96ed..ee658e797454119a 100644 --- a/backends/Makefile.objs +++ b/backends/Makefile.objs @@ -21,3 +21,5 @@ common-obj-$(CONFIG_LINUX) +=3D hostmem-memfd.o common-obj-$(CONFIG_GIO) +=3D dbus-vmstate.o dbus-vmstate.o-cflags =3D $(GIO_CFLAGS) dbus-vmstate.o-libs =3D $(GIO_LIBS) + +common-obj-$(CONFIG_GPIODEV) +=3D gpiodev.o diff --git a/backends/gpiodev.c b/backends/gpiodev.c new file mode 100644 index 0000000000000000..df1bd0113c7b2985 --- /dev/null +++ b/backends/gpiodev.c @@ -0,0 +1,94 @@ +/* + * QEMU GPIO Backend + * + * Copyright (C) 2018-2020 Glider bv + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include + +#include "qemu/osdep.h" +#include "qemu/config-file.h" +#include "qemu/cutils.h" +#include "qemu/error-report.h" +#include "qemu/module.h" +#include "qemu/option.h" +#include "qapi/error.h" + +#include "sysemu/gpiodev.h" + +#include "hw/irq.h" +#include "hw/qdev-core.h" + +static void gpiodev_irq_handler(void *opaque, int n, int level) +{ + struct gpiod_line *line =3D opaque; + int status; + + status =3D gpiod_line_set_value(line, level); + if (status < 0) { + struct gpiod_chip *chip =3D gpiod_line_get_chip(line); + + error_report("%s/%s: Cannot set GPIO line %u: %s", + gpiod_chip_name(chip), gpiod_chip_label(chip), + gpiod_line_offset(line), strerror(errno)); + } +} + +static int gpiodev_map_line(DeviceState *dev, struct gpiod_chip *chip, + unsigned int gpio, Error **errp) +{ + struct gpiod_line *line; + qemu_irq irq; + int status; + + line =3D gpiod_chip_get_line(chip, gpio); + if (!line) { + error_setg(errp, "Cannot obtain GPIO line %u: %s", gpio, + strerror(errno)); + return -1; + } + + status =3D gpiod_line_request_output(line, "qemu", 0); + if (status < 0) { + error_setg(errp, "Cannot request GPIO line %u for output: %s", gpi= o, + strerror(errno)); + return status; + } + + irq =3D qemu_allocate_irq(gpiodev_irq_handler, line, 0); + qdev_connect_gpio_out(dev, gpio, irq); + return 0; +} + +void qemu_gpiodev_add(DeviceState *dev, const char *name, unsigned int max= gpio, + Error **errp) +{ + struct gpiod_chip *chip; + unsigned int i, n; + int status; + + chip =3D gpiod_chip_open_lookup(name); + if (!chip) { + error_setg(errp, "Cannot open GPIO chip %s: %s", name, + strerror(errno)); + return; + } + + n =3D gpiod_chip_num_lines(chip); + if (n > maxgpio) { + warn_report("Last %u GPIO line(s) will not be mapped", n - maxgpio= ); + n =3D maxgpio; + } + + for (i =3D 0; i < n; i++) { + status =3D gpiodev_map_line(dev, chip, i, errp); + if (status < 0) { + return; + } + } + + info_report("Mapped %u GPIO lines", n); +} diff --git a/configure b/configure index 23b5e93752b6a259..8b133402ef727c8e 100755 --- a/configure +++ b/configure @@ -509,6 +509,7 @@ libpmem=3D"" default_devices=3D"yes" plugins=3D"no" fuzzing=3D"no" +gpio=3D"" =20 supported_cpu=3D"no" supported_os=3D"no" @@ -1601,6 +1602,10 @@ for opt do ;; --gdb=3D*) gdb_bin=3D"$optarg" ;; + --disable-gpio) gpio=3D"no" + ;; + --enable-gpio) gpio=3D"yes" + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1894,6 +1899,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: debug-mutex mutex debugging support libpmem libpmem support xkbcommon xkbcommon support + gpio gpio support =20 NOTE: The object files are built at the place where configure is launched EOF @@ -6250,6 +6256,23 @@ case "$slirp" in ;; esac =20 +########################################## +# check for libgpiod + +if test "$gpio" !=3D "no"; then + if $pkg_config --exists "libgpiod"; then + gpio=3D"yes" + libgpiod_libs=3D$($pkg_config --libs libgpiod) + libgpiod_cflags=3D$($pkg_config --cflags libgpiod) + libs_softmmu=3D"$libs_softmmu $libgpiod_libs" + QEMU_CFLAGS=3D"$QEMU_CFLAGS $libgpiod_cflags" + else + if test "$gpio" =3D "yes" ; then + feature_not_found "gpio" "Install libgpiod" + fi + gpio=3D"no" + fi +fi =20 ########################################## # End of CC checks @@ -6733,6 +6756,7 @@ echo "default devices $default_devices" echo "plugin support $plugins" echo "fuzzing support $fuzzing" echo "gdb $gdb_bin" +echo "gpio support $gpio" =20 if test "$supported_cpu" =3D "no"; then echo @@ -7614,6 +7638,10 @@ if test -n "$gdb_bin" ; then echo "HAVE_GDB_BIN=3D$gdb_bin" >> $config_host_mak fi =20 +if test "$gpio" =3D "yes" ; then + echo "CONFIG_GPIODEV=3Dy" >> $config_host_mak +fi + if test "$tcg_interpreter" =3D "yes"; then QEMU_INCLUDES=3D"-iquote \$(SRC_PATH)/tcg/tci $QEMU_INCLUDES" elif test "$ARCH" =3D "sparc64" ; then diff --git a/include/sysemu/gpiodev.h b/include/sysemu/gpiodev.h new file mode 100644 index 0000000000000000..bedd141001245207 --- /dev/null +++ b/include/sysemu/gpiodev.h @@ -0,0 +1,12 @@ +/* + * QEMU GPIO Backend + * + * Copyright (C) 2018-2020 Glider bv + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/typedefs.h" + +void qemu_gpiodev_add(DeviceState *dev, const char *name, unsigned int max= gpio, + Error **errp); --=20 2.17.1 From nobody Fri May 17 02:41:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1587632624; cv=none; d=zohomail.com; s=zohoarc; b=EcxcdnCBTsZxe0XWx8ubMjTRuZ6SvxDy3Hv2I2/Qt+wCrtpOzIphJ+jCLb+kChEgmoJdgG1l6QpfHe8Z5Vy2JBgVHLf+Lb0WnBRQNyAraVmq2l0xSno6lrboAbPIzwPsP+oLD3fGkpKI+l59eIt0wyxsedXIoQ8BIKU6K9R5K0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587632624; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=t9pARQGfSAp5z8JAKQmS55fNB8zhgGo9pMNRX16e/qo=; b=J61I0WxLVL5Mh+MeKYkGFcOJVItT9YA6lZEo/kavdPTo7p3yGJMh/fUZyo3c2iI9Oug/9kFjzuEjxyzY6paerTPJsmlKZQ3cFsRTpSieEWptaO1rdUDBR9lrXTYwxcU1XiLXb+OGbQPgLCGHo0XX8eBH9KJPqEzuFXy+vpThL0E= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587632624730847.3796304744398; Thu, 23 Apr 2020 02:03:44 -0700 (PDT) Received: from localhost ([::1]:39252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXln-0002sF-DH for importer@patchew.org; Thu, 23 Apr 2020 05:03:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36076) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXje-0000lt-CL for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRXjb-0001Dl-Ep for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:30 -0400 Received: from xavier.telenet-ops.be ([2a02:1800:120:4::f00:14]:36688) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jRXja-0001BX-2J for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:26 -0400 Received: from ramsan ([IPv6:2a02:1810:ac12:ed60:89cc:efc7:85ce:4669]) by xavier.telenet-ops.be with bizsmtp id W91L2200R1RvcFS0191LFF; Thu, 23 Apr 2020 11:01:21 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXjU-0006kH-Bt; Thu, 23 Apr 2020 11:01:20 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1jRXjU-0002vd-Aq; Thu, 23 Apr 2020 11:01:20 +0200 From: Geert Uytterhoeven To: Peter Maydell , Paolo Bonzini , Alexander Graf , Linus Walleij , Bartosz Golaszewski , Magnus Damm Subject: [PATCH QEMU v2 4/5] ARM: PL061: Add gpiodev support Date: Thu, 23 Apr 2020 11:01:17 +0200 Message-Id: <20200423090118.11199-5-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200423090118.11199-1-geert+renesas@glider.be> References: <20200423090118.11199-1-geert+renesas@glider.be> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a02:1800:120:4::f00:14; envelope-from=geert@linux-m68k.org; helo=xavier.telenet-ops.be X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a02:1800:120:4::f00:14 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, qemu-arm@nongnu.org, qemu-devel@nongnu.org, Geert Uytterhoeven Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make the PL061 GPIO controller user-creatable, and allow the user to tie a newly created instance to a gpiochip on the host. To create a new GPIO controller, the QEMU command line must be augmented with: -device pl061,host=3D with the name or label of the gpiochip on the host. Signed-off-by: Geert Uytterhoeven --- v2: - New. --- hw/gpio/pl061.c | 35 +++++++++++++++++++++++++++++++++++ qemu-options.hx | 9 +++++++++ 2 files changed, 44 insertions(+) diff --git a/hw/gpio/pl061.c b/hw/gpio/pl061.c index 74ba733a8a5e8ca5..98204f9a586ae8c8 100644 --- a/hw/gpio/pl061.c +++ b/hw/gpio/pl061.c @@ -12,11 +12,14 @@ #include "hw/arm/fdt.h" #include "hw/gpio/pl061.h" #include "hw/irq.h" +#include "hw/qdev-properties.h" #include "hw/sysbus.h" #include "migration/vmstate.h" +#include "qapi/error.h" #include "qemu/log.h" #include "qemu/module.h" #include "sysemu/device_tree.h" +#include "sysemu/gpiodev.h" =20 //#define DEBUG_PL061 1 =20 @@ -41,6 +44,9 @@ static const uint8_t pl061_id_luminary[12] =3D typedef struct PL061State { SysBusDevice parent_obj; =20 +#ifdef CONFIG_GPIODEV + char *host; +#endif MemoryRegion iomem; uint32_t locked; uint32_t data; @@ -370,10 +376,39 @@ static void pl061_init(Object *obj) qdev_init_gpio_out(dev, s->out, 8); } =20 +#ifdef CONFIG_GPIODEV +static Property pl061_properties[] =3D { + DEFINE_PROP_STRING("host", PL061State, host), + DEFINE_PROP_END_OF_LIST(), +}; + +static void pl061_realize(DeviceState *dev, Error **errp) +{ + PL061State *s =3D PL061(dev); + + if (!dev->opts) { + /* Not created by user */ + return; + } + + if (!s->host) { + error_setg(errp, "'host' property is required"); + return; + } + + qemu_gpiodev_add(dev, s->host, 8, errp); +} +#endif /* CONFIG_GPIODEV */ + static void pl061_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); =20 +#ifdef CONFIG_GPIODEV + device_class_set_props(dc, pl061_properties); + dc->realize =3D pl061_realize; + dc->user_creatable =3D true; +#endif dc->vmsd =3D &vmstate_pl061; dc->reset =3D &pl061_reset; } diff --git a/qemu-options.hx b/qemu-options.hx index 292d4e7c0cef6097..182de7fb63923b38 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -875,6 +875,15 @@ SRST ``-device isa-ipmi-bt,bmc=3Did[,ioport=3Dval][,irq=3Dval]`` Like the KCS interface, but defines a BT interface. The default port is 0xe4 and the default interrupt is 5. + +#ifdef CONFIG_GPIODEV +``-device pl061,host=3Dgpiochip`` + Add a PL061 GPIO controller, and map its virtual GPIO lines to a GPIO + controller on the host. + + ``host=3Dgpiochip`` + The name or label of the GPIO controller on the host. +#endif ERST =20 DEF("name", HAS_ARG, QEMU_OPTION_name, --=20 2.17.1 From nobody Fri May 17 02:41:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1587632777; cv=none; d=zohomail.com; s=zohoarc; b=WLjHRHauQctcVe8/iANvSF712A5UeZjerGbCpcSzvGuDLgakWRM6qMqKBwVkqxfYJFPzqVz8A8zdkYCgCG1A2vJfBFL3JKfILSZCEBsVKc0waHNUR16ax9MLrbwiccjaqI5Jn+UzKrlgh0B7TxmbC1+Md0Nj4qaLkln6hXi0FLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587632777; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=mSN8CqaWGulUWPy7sCHIK3mbryqXLzsI81tPn3icqkQ=; b=ND5z5vDf5q4QzLa35j6Wpx/MXghKq3tnJFgMn/7nYQZ5zuO8WPxGCkNt3qP23lY7xY6QrHszvhWq/r97ucUV6qy4lQ6f3rd10PWQE8MWJvgZWIdDsu521RN9D0QbSDxfgb/QcuEz5dxxpo4mNLUNzK17n8kKXKbo2ZyJID8BRn4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587632777896735.0481530877773; Thu, 23 Apr 2020 02:06:17 -0700 (PDT) Received: from localhost ([::1]:39316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXoG-0006aF-B5 for importer@patchew.org; Thu, 23 Apr 2020 05:06:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36102) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXjh-0000qD-46 for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jRXjb-0001E1-HM for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:32 -0400 Received: from andre.telenet-ops.be ([2a02:1800:120:4::f00:15]:34528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jRXja-0001Bd-5S for qemu-devel@nongnu.org; Thu, 23 Apr 2020 05:01:26 -0400 Received: from ramsan ([IPv6:2a02:1810:ac12:ed60:89cc:efc7:85ce:4669]) by andre.telenet-ops.be with bizsmtp id W91L2200k1RvcFS0191LLq; Thu, 23 Apr 2020 11:01:21 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1jRXjU-0006kJ-Cn; Thu, 23 Apr 2020 11:01:20 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1jRXjU-0002vg-BT; Thu, 23 Apr 2020 11:01:20 +0200 From: Geert Uytterhoeven To: Peter Maydell , Paolo Bonzini , Alexander Graf , Linus Walleij , Bartosz Golaszewski , Magnus Damm Subject: [PATCH QEMU v2 5/5] hw/arm/virt: Add dynamic PL061 GPIO support Date: Thu, 23 Apr 2020 11:01:18 +0200 Message-Id: <20200423090118.11199-6-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200423090118.11199-1-geert+renesas@glider.be> References: <20200423090118.11199-1-geert+renesas@glider.be> Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a02:1800:120:4::f00:15; envelope-from=geert@linux-m68k.org; helo=andre.telenet-ops.be X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2a02:1800:120:4::f00:15 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, qemu-arm@nongnu.org, qemu-devel@nongnu.org, Geert Uytterhoeven Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add support for dynamically instantiating PL061 GPIO controller instances in ARM virt. Device tree nodes are created dynamically. Signed-off-by: Geert Uytterhoeven --- v2: - New. --- hw/arm/sysbus-fdt.c | 18 ++++++++++++++++++ hw/arm/virt.c | 1 + 2 files changed, 19 insertions(+) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index 6b6906f4cfc36198..493583218d176d0a 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -32,6 +32,7 @@ #include "sysemu/device_tree.h" #include "sysemu/tpm.h" #include "hw/platform-bus.h" +#include "hw/gpio/pl061.h" #include "hw/vfio/vfio-platform.h" #include "hw/vfio/vfio-calxeda-xgmac.h" #include "hw/vfio/vfio-amd-xgbe.h" @@ -468,6 +469,22 @@ static int add_tpm_tis_fdt_node(SysBusDevice *sbdev, v= oid *opaque) return 0; } =20 +/* + * add_pl061_node: Create a DT node for a PL061 GPIO controller + */ +static int add_pl061_node(SysBusDevice *sbdev, void *opaque) +{ + PlatformBusFDTData *data =3D opaque; + PlatformBusDevice *pbus =3D data->pbus; + void *fdt =3D data->fdt; + + pl061_create_fdt(fdt, data->pbus_node_name, 1, + platform_bus_get_mmio_addr(pbus, sbdev, 0), 0x1000, + platform_bus_get_irqn(pbus, sbdev, 0) + data->irq_sta= rt, + qemu_fdt_get_phandle(fdt, "/apb-pclk")); + return 0; +} + static int no_fdt_node(SysBusDevice *sbdev, void *opaque) { return 0; @@ -489,6 +506,7 @@ static const BindingEntry bindings[] =3D { VFIO_PLATFORM_BINDING("amd,xgbe-seattle-v1a", add_amd_xgbe_fdt_node), #endif TYPE_BINDING(TYPE_TPM_TIS_SYSBUS, add_tpm_tis_fdt_node), + TYPE_BINDING(TYPE_PL061, add_pl061_node), TYPE_BINDING(TYPE_RAMFB_DEVICE, no_fdt_node), TYPE_BINDING("", NULL), /* last element */ }; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index c88c8850fbe00bdb..191594db09422d54 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2178,6 +2178,7 @@ static void virt_machine_class_init(ObjectClass *oc, = void *data) machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_PLATFORM); machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS); + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_PL061); mc->block_default_type =3D IF_VIRTIO; mc->no_cdrom =3D 1; mc->pci_allow_0_address =3D true; --=20 2.17.1