From: Maxim Uvarov <maxim.uvarov@linaro.org>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, drjones@redhat.com,
Maxim Uvarov <maxim.uvarov@linaro.org>,
Jose.Marinho@arm.com, f4bug@amsat.org,
tf-a@lists.trustedfirmware.org
Subject: [PATCHv6 3/3] arm-virt: combine code for secure and non secure pl061
Date: Thu, 14 Jan 2021 17:50:32 +0300 [thread overview]
Message-ID: <20210114145032.8457-4-maxim.uvarov@linaro.org> (raw)
In-Reply-To: <20210114145032.8457-1-maxim.uvarov@linaro.org>
Combine code for secure and non secure pl061 (gpio) with
refining fdt creation.
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
hw/arm/virt.c | 122 ++++++++++++++++++++++++++++++++++----------------
1 file changed, 83 insertions(+), 39 deletions(-)
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 6f3ec15985..5317f32e3a 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -821,35 +821,13 @@ static void virt_powerdown_req(Notifier *n, void *opaque)
}
}
-static void create_gpio(const VirtMachineState *vms)
+static void create_gpio_keys(const VirtMachineState *vms,
+ DeviceState *pl061_dev,
+ uint32_t phandle)
{
- char *nodename;
- DeviceState *pl061_dev;
- hwaddr base = vms->memmap[VIRT_GPIO].base;
- hwaddr size = vms->memmap[VIRT_GPIO].size;
- int irq = vms->irqmap[VIRT_GPIO];
- const char compat[] = "arm,pl061\0arm,primecell";
-
- pl061_dev = sysbus_create_simple("pl061", base,
- qdev_get_gpio_in(vms->gic, irq));
-
- uint32_t phandle = qemu_fdt_alloc_phandle(vms->fdt);
- nodename = 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(compat));
- 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);
-
gpio_key_dev = sysbus_create_simple("gpio-key", -1,
qdev_get_gpio_in(pl061_dev, 3));
+
qemu_fdt_add_subnode(vms->fdt, "/gpio-keys");
qemu_fdt_setprop_string(vms->fdt, "/gpio-keys", "compatible", "gpio-keys");
qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#size-cells", 0);
@@ -862,24 +840,16 @@ 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);
}
#define ATF_GPIO_POWEROFF 3
#define ATF_GPIO_REBOOT 4
-static void create_gpio_secure(const VirtMachineState *vms, MemoryRegion *mem)
+static void create_gpio_pwr(const VirtMachineState *vms,
+ DeviceState *pl061_dev,
+ uint32_t phandle)
{
DeviceState *gpio_pwr_dev;
- SysBusDevice *s;
- hwaddr base = vms->memmap[VIRT_SECURE_GPIO].base;
- DeviceState *pl061_dev;
-
- /* Secure pl061 */
- pl061_dev = qdev_new("pl061");
- s = SYS_BUS_DEVICE(pl061_dev);
- sysbus_realize_and_unref(s, &error_fatal);
- memory_region_add_subregion(mem, base, sysbus_mmio_get_region(s, 0));
/* gpio-pwr */
gpio_pwr_dev = sysbus_create_simple("gpio-pwr", -1, NULL);
@@ -889,8 +859,82 @@ static void create_gpio_secure(const VirtMachineState *vms, MemoryRegion *mem)
qdev_get_gpio_in_named(gpio_pwr_dev, "reset", 0));
qdev_connect_gpio_out(pl061_dev, ATF_GPIO_REBOOT,
qdev_get_gpio_in_named(gpio_pwr_dev, "shutdown", 0));
+
+ qemu_fdt_add_subnode(vms->fdt, "/gpio-pwr");
+ qemu_fdt_setprop_string(vms->fdt, "/gpio-pwr", "compatible", "gpio-pwr");
+ qemu_fdt_setprop_cell(vms->fdt, "/gpio-pwr", "#size-cells", 0);
+ qemu_fdt_setprop_cell(vms->fdt, "/gpio-pwr", "#address-cells", 1);
+
+ qemu_fdt_add_subnode(vms->fdt, "/gpio-pwr/poweroff");
+ qemu_fdt_setprop_string(vms->fdt, "/gpio-pwr/poweroff",
+ "label", "GPIO PWR Poweroff");
+ qemu_fdt_setprop_cell(vms->fdt, "/gpio-pwr/poweroff", "code",
+ ATF_GPIO_POWEROFF);
+ qemu_fdt_setprop_cells(vms->fdt, "/gpio-pwr/poweroff",
+ "gpios", phandle, 3, 0);
+
+ qemu_fdt_add_subnode(vms->fdt, "/gpio-pwr/reboot");
+ qemu_fdt_setprop_string(vms->fdt, "/gpio-pwr/reboot",
+ "label", "GPIO PWR Reboot");
+ qemu_fdt_setprop_cell(vms->fdt, "/gpio-pwr/reboot", "code",
+ ATF_GPIO_REBOOT);
+ qemu_fdt_setprop_cells(vms->fdt, "/gpio-pwr/reboot",
+ "gpios", phandle, 3, 0);
+}
+
+static void create_gpio_devices(const VirtMachineState *vms, int gpio,
+ MemoryRegion *mem)
+{
+ char *nodename;
+ DeviceState *pl061_dev;
+ hwaddr base = vms->memmap[gpio].base;
+ hwaddr size = vms->memmap[gpio].size;
+ int irq = vms->irqmap[gpio];
+ const char compat[] = "arm,pl061\0arm,primecell";
+ SysBusDevice *s;
+
+ pl061_dev = qdev_new("pl061");
+ s = SYS_BUS_DEVICE(pl061_dev);
+ sysbus_realize_and_unref(s, &error_fatal);
+ memory_region_add_subregion(mem, base, sysbus_mmio_get_region(s, 0));
+ sysbus_connect_irq(s, 0, qdev_get_gpio_in(vms->gic, irq));
+
+ uint32_t phandle = qemu_fdt_alloc_phandle(vms->fdt);
+ nodename = 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(compat));
+ 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);
+
+ if (gpio == VIRT_GPIO) {
+ qemu_fdt_setprop_string(vms->fdt, "/chosen", "stdout-path", nodename);
+ } else {
+ /* Mark as not usable by the normal world */
+ qemu_fdt_setprop_string(vms->fdt, nodename, "status", "disabled");
+ qemu_fdt_setprop_string(vms->fdt, nodename, "secure-status", "okay");
+
+ qemu_fdt_setprop_string(vms->fdt, "/secure-chosen", "stdout-path",
+ nodename);
+ }
+ g_free(nodename);
+
+ /* Child gpio devices */
+ if (gpio == VIRT_GPIO) {
+ create_gpio_keys(vms, pl061_dev, phandle);
+ } else {
+ create_gpio_pwr(vms, pl061_dev, phandle);
+ }
}
+
static void create_virtio_devices(const VirtMachineState *vms)
{
int i;
@@ -2017,11 +2061,11 @@ static void machvirt_init(MachineState *machine)
if (has_ged && aarch64 && firmware_loaded && virt_is_acpi_enabled(vms)) {
vms->acpi_dev = create_acpi_ged(vms);
} else {
- create_gpio(vms);
+ create_gpio_devices(vms, VIRT_GPIO, sysmem);
}
if (vms->secure && !vmc->no_secure_gpio) {
- create_gpio_secure(vms, secure_sysmem);
+ create_gpio_devices(vms, VIRT_SECURE_GPIO, secure_sysmem);
}
/* connect powerdown request */
--
2.17.1
next prev parent reply other threads:[~2021-01-14 14:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-14 14:50 [PATCHv6 0/3] arm-virt: add secure pl061 for reset/power down Maxim Uvarov
2021-01-14 14:50 ` [PATCHv6 1/3] hw: gpio: implement gpio-pwr driver for qemu reset/poweroff Maxim Uvarov
2021-01-14 14:50 ` [PATCHv6 2/3] arm-virt: add secure pl061 for reset/power down Maxim Uvarov
2021-01-14 14:50 ` Maxim Uvarov [this message]
2021-01-14 16:03 ` [PATCHv6 0/3] " Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210114145032.8457-4-maxim.uvarov@linaro.org \
--to=maxim.uvarov@linaro.org \
--cc=Jose.Marinho@arm.com \
--cc=drjones@redhat.com \
--cc=f4bug@amsat.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=tf-a@lists.trustedfirmware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).