Add GPIO controller in ACPI DSDT table. It can be used
for device hotplug.

Signed-off-by: Shannon Zhao <zhaoshengl...@huawei.com>
---
 hw/arm/virt-acpi-build.c         |   21 +++++++++++++++++++++
 hw/arm/virt.c                    |    2 ++
 include/hw/arm/virt-acpi-build.h |    2 ++
 3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index bfbddbe..4f26551 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -176,6 +176,26 @@ static void acpi_dsdt_add_virtio(Aml *scope, const hwaddr 
*mmio_addrs,
     }
 }
 
+static void acpi_dsdt_add_gpio(Aml *scope, const hwaddr *gpio_addrs,
+                                           const int *gpio_irq)
+{
+    Aml *dev, *crs;
+
+    dev = aml_device("GPO0");
+    aml_append(dev, aml_name_decl("_HID", aml_string("LNRO0009")));
+    aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
+    aml_append(dev, aml_name_decl("_UID", aml_int(0)));
+
+    crs = aml_resource_template();
+    aml_append(crs,
+               aml_memory32_fixed(gpio_addrs[0], gpio_addrs[1], 0x01));
+    aml_append(crs,
+               aml_interrupt(0x01, *gpio_irq + 32));
+    aml_append(dev, aml_name_decl("_CRS", crs));
+
+    aml_append(scope, dev);
+}
+
 /* RSDP */
 static GArray *
 build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
@@ -343,6 +363,7 @@ build_dsdt(Aml *table_data, GArray *linker, VirtGuestInfo 
*guest_info)
     acpi_dsdt_add_flash(scope, info->flash_addr);
     acpi_dsdt_add_virtio(scope, info->virtio_mmio_addr,
              info->virtio_mmio_irq, info->virtio_mmio_num);
+    acpi_dsdt_add_gpio(scope, info->gpio_addr, info->gpio_irq);
 
     aml_append(dsdt, scope);
     aml_append(table_data, dsdt);
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 43c0260..f689bc3 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -159,6 +159,8 @@ static const struct acpi_dsdt_info dsdt_info = {
     .virtio_mmio_addr = &a15memmap[VIRT_MMIO].base,
     .virtio_mmio_irq = &a15irqmap[VIRT_MMIO],
     .virtio_mmio_num = NUM_VIRTIO_TRANSPORTS,
+    .gpio_addr = &a15memmap[VIRT_GPIO].base,
+    .gpio_irq = &a15irqmap[VIRT_GPIO],
     .rtc_addr = &a15memmap[VIRT_RTC].base,
     .rtc_irq = &a15irqmap[VIRT_RTC],
     .flash_addr = &a15memmap[VIRT_FLASH].base,
diff --git a/include/hw/arm/virt-acpi-build.h b/include/hw/arm/virt-acpi-build.h
index 451edc9..de8d4c6 100644
--- a/include/hw/arm/virt-acpi-build.h
+++ b/include/hw/arm/virt-acpi-build.h
@@ -47,6 +47,8 @@ struct acpi_dsdt_info {
     const hwaddr *virtio_mmio_addr;
     const int *virtio_mmio_irq;
     int virtio_mmio_num;
+    const hwaddr *gpio_addr;
+    const int *gpio_irq;
     const hwaddr *rtc_addr;
     const int *rtc_irq;
     const hwaddr *flash_addr;
-- 
1.7.1



Reply via email to