Make pvpanic acpi driver as seperate file and modify code 
in order to adapt the framework.

Signed-off-by: Peng Hao <peng.h...@zte.com.cn>
---
 drivers/misc/pvpanic/Kconfig        |  9 +++++
 drivers/misc/pvpanic/Makefile       |  1 +
 drivers/misc/pvpanic/pvpanic-acpi.c | 77 +++++++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+)
 create mode 100644 drivers/misc/pvpanic/pvpanic-acpi.c

diff --git a/drivers/misc/pvpanic/Kconfig b/drivers/misc/pvpanic/Kconfig
index 3e612c6..d274130 100644
--- a/drivers/misc/pvpanic/Kconfig
+++ b/drivers/misc/pvpanic/Kconfig
@@ -5,3 +5,12 @@ config PVPANIC
          This driver provides support for the pvpanic device.  pvpanic is
          a paravirtualized device provided by QEMU; it lets a virtual machine
          (guest) communicate panic events to the host.
+
+if PVPANIC
+
+config PVPANIC_ACPI
+       tristate "pvpanic acpi driver"
+       depends on ACPI
+       default PVPANIC
+
+endif
diff --git a/drivers/misc/pvpanic/Makefile b/drivers/misc/pvpanic/Makefile
index 6394224..c5b73ca 100644
--- a/drivers/misc/pvpanic/Makefile
+++ b/drivers/misc/pvpanic/Makefile
@@ -3,3 +3,4 @@
 # Copyright (c) 2018 ZTE Ltd.
 
 obj-$(CONFIG_PVPANIC)            += pvpanic.o
+obj-$(CONFIG_PVPANIC_ACPI)      += pvpanic-acpi.o
diff --git a/drivers/misc/pvpanic/pvpanic-acpi.c 
b/drivers/misc/pvpanic/pvpanic-acpi.c
new file mode 100644
index 0000000..a6153fa
--- /dev/null
+++ b/drivers/misc/pvpanic/pvpanic-acpi.c
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  pvpanic acpi driver.
+ *
+ *  Copyright (C) 2019 ZTE Ltd.
+ *  Author: Peng Hao
+ */
+#include <linux/acpi.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include "pvpanic.h"
+
+static int pvpanic_add(struct acpi_device *device);
+static int pvpanic_remove(struct acpi_device *device);
+
+static const struct acpi_device_id pvpanic_device_ids[] = {
+       { "QEMU0001", 0 },
+       { "", 0 }
+};
+MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
+
+static struct acpi_driver pvpanic_driver = {
+       .name =         "pvpanic",
+       .class =        "QEMU",
+       .ids =          pvpanic_device_ids,
+       .ops =          {
+                               .add =          pvpanic_add,
+                               .remove =       pvpanic_remove,
+                       },
+       .owner =        THIS_MODULE,
+};
+
+static acpi_status
+pvpanic_walk_resources(struct acpi_resource *res, void *context)
+{
+       struct resource r;
+       int ret = 0;
+       struct device *dev = context;
+
+       memset(&r, 0, sizeof(r));
+       if (acpi_dev_resource_io(res, &r) || acpi_dev_resource_memory(res, &r))
+               ret = pvpanic_add_device(dev, &r);
+
+       if (!ret)
+               return AE_OK;
+
+       return AE_ERROR;
+}
+static int pvpanic_add(struct acpi_device *device)
+{
+       int ret;
+       acpi_status status;
+
+       ret = acpi_bus_get_status(device);
+       if (ret < 0)
+               return ret;
+
+       if (!device->status.enabled || !device->status.functional)
+               return -ENODEV;
+
+       status = acpi_walk_resources(device->handle, METHOD_NAME__CRS,
+                                    pvpanic_walk_resources, &device->dev);
+
+       if (ACPI_FAILURE(status))
+               return -ENODEV;
+
+       return 0;
+}
+
+static int pvpanic_remove(struct acpi_device *device)
+{
+       pvpanic_remove_device();
+       return 0;
+}
+
+module_acpi_driver(pvpanic_driver);
-- 
1.8.3.1

Reply via email to