arm-virt: refactor gpios creation
No functional change. Just refactor code to better support secure and normal world gpios. Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> Reviewed-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
c97377652d
commit
e61bde40dd
|
@ -820,17 +820,43 @@ 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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#address-cells", 1);
|
||||||
|
|
||||||
|
qemu_fdt_add_subnode(vms->fdt, "/gpio-keys/poweroff");
|
||||||
|
qemu_fdt_setprop_string(vms->fdt, "/gpio-keys/poweroff",
|
||||||
|
"label", "GPIO Key Poweroff");
|
||||||
|
qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys/poweroff", "linux,code",
|
||||||
|
KEY_POWER);
|
||||||
|
qemu_fdt_setprop_cells(vms->fdt, "/gpio-keys/poweroff",
|
||||||
|
"gpios", phandle, 3, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void create_gpio_devices(const VirtMachineState *vms, int gpio,
|
||||||
|
MemoryRegion *mem)
|
||||||
{
|
{
|
||||||
char *nodename;
|
char *nodename;
|
||||||
DeviceState *pl061_dev;
|
DeviceState *pl061_dev;
|
||||||
hwaddr base = vms->memmap[VIRT_GPIO].base;
|
hwaddr base = vms->memmap[gpio].base;
|
||||||
hwaddr size = vms->memmap[VIRT_GPIO].size;
|
hwaddr size = vms->memmap[gpio].size;
|
||||||
int irq = vms->irqmap[VIRT_GPIO];
|
int irq = vms->irqmap[gpio];
|
||||||
const char compat[] = "arm,pl061\0arm,primecell";
|
const char compat[] = "arm,pl061\0arm,primecell";
|
||||||
|
SysBusDevice *s;
|
||||||
|
|
||||||
pl061_dev = sysbus_create_simple("pl061", base,
|
pl061_dev = qdev_new("pl061");
|
||||||
qdev_get_gpio_in(vms->gic, irq));
|
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);
|
uint32_t phandle = qemu_fdt_alloc_phandle(vms->fdt);
|
||||||
nodename = g_strdup_printf("/pl061@%" PRIx64, base);
|
nodename = g_strdup_printf("/pl061@%" PRIx64, base);
|
||||||
|
@ -847,21 +873,10 @@ static void create_gpio(const VirtMachineState *vms)
|
||||||
qemu_fdt_setprop_string(vms->fdt, nodename, "clock-names", "apb_pclk");
|
qemu_fdt_setprop_string(vms->fdt, nodename, "clock-names", "apb_pclk");
|
||||||
qemu_fdt_setprop_cell(vms->fdt, nodename, "phandle", phandle);
|
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);
|
|
||||||
qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys", "#address-cells", 1);
|
|
||||||
|
|
||||||
qemu_fdt_add_subnode(vms->fdt, "/gpio-keys/poweroff");
|
|
||||||
qemu_fdt_setprop_string(vms->fdt, "/gpio-keys/poweroff",
|
|
||||||
"label", "GPIO Key Poweroff");
|
|
||||||
qemu_fdt_setprop_cell(vms->fdt, "/gpio-keys/poweroff", "linux,code",
|
|
||||||
KEY_POWER);
|
|
||||||
qemu_fdt_setprop_cells(vms->fdt, "/gpio-keys/poweroff",
|
|
||||||
"gpios", phandle, 3, 0);
|
|
||||||
g_free(nodename);
|
g_free(nodename);
|
||||||
|
|
||||||
|
/* Child gpio devices */
|
||||||
|
create_gpio_keys(vms, pl061_dev, phandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_virtio_devices(const VirtMachineState *vms)
|
static void create_virtio_devices(const VirtMachineState *vms)
|
||||||
|
@ -1990,7 +2005,7 @@ static void machvirt_init(MachineState *machine)
|
||||||
if (has_ged && aarch64 && firmware_loaded && virt_is_acpi_enabled(vms)) {
|
if (has_ged && aarch64 && firmware_loaded && virt_is_acpi_enabled(vms)) {
|
||||||
vms->acpi_dev = create_acpi_ged(vms);
|
vms->acpi_dev = create_acpi_ged(vms);
|
||||||
} else {
|
} else {
|
||||||
create_gpio(vms);
|
create_gpio_devices(vms, VIRT_GPIO, sysmem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* connect powerdown request */
|
/* connect powerdown request */
|
||||||
|
|
Loading…
Reference in a new issue