From fcb418cd567febb310749e37507679e4f2703e56 Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 6 Nov 2018 22:57:12 +0800 Subject: pvpanic: move pvpanic to misc as common driver Move pvpanic.c from drivers/platform/x86 to drivers/misc. Following patches will use pvpanic device in arm64. Reviewed-by: Andy Shevchenko Acked-by: Mark Rutland Signed-off-by: Peng Hao Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 drivers/misc/pvpanic.c (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c new file mode 100644 index 000000000000..fd86daba7ffd --- /dev/null +++ b/drivers/misc/pvpanic.c @@ -0,0 +1,124 @@ +/* + * pvpanic.c - pvpanic Device Support + * + * Copyright (C) 2013 Fujitsu. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include + +MODULE_AUTHOR("Hu Tao "); +MODULE_DESCRIPTION("pvpanic device driver"); +MODULE_LICENSE("GPL"); + +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); + +#define PVPANIC_PANICKED (1 << 0) + +static u16 port; + +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 void +pvpanic_send_event(unsigned int event) +{ + outb(event, port); +} + +static int +pvpanic_panic_notify(struct notifier_block *nb, unsigned long code, + void *unused) +{ + pvpanic_send_event(PVPANIC_PANICKED); + return NOTIFY_DONE; +} + +static struct notifier_block pvpanic_panic_nb = { + .notifier_call = pvpanic_panic_notify, + .priority = 1, /* let this called before broken drm_fb_helper */ +}; + + +static acpi_status +pvpanic_walk_resources(struct acpi_resource *res, void *context) +{ + switch (res->type) { + case ACPI_RESOURCE_TYPE_END_TAG: + return AE_OK; + + case ACPI_RESOURCE_TYPE_IO: + port = res->data.io.minimum; + return AE_OK; + + default: + return AE_ERROR; + } +} + +static int pvpanic_add(struct acpi_device *device) +{ + int ret; + + ret = acpi_bus_get_status(device); + if (ret < 0) + return ret; + + if (!device->status.enabled || !device->status.functional) + return -ENODEV; + + acpi_walk_resources(device->handle, METHOD_NAME__CRS, + pvpanic_walk_resources, NULL); + + if (!port) + return -ENODEV; + + atomic_notifier_chain_register(&panic_notifier_list, + &pvpanic_panic_nb); + + return 0; +} + +static int pvpanic_remove(struct acpi_device *device) +{ + + atomic_notifier_chain_unregister(&panic_notifier_list, + &pvpanic_panic_nb); + return 0; +} + +module_acpi_driver(pvpanic_driver); -- cgit v1.2.2 From d2ae1717f3f6b1bd86cd05d0443169b645445d62 Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 6 Nov 2018 22:57:13 +0800 Subject: misc/pvpanic: simplify the code using acpi_dev_resource_io Use acpi_dev_resource_io API. Suggested-by: Andy Shevchenko Reviewed-by: Andy Shevchenko Acked-by: Mark Rutland Signed-off-by: Peng Hao Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index fd86daba7ffd..49c59e1d299d 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -77,17 +77,14 @@ static struct notifier_block pvpanic_panic_nb = { static acpi_status pvpanic_walk_resources(struct acpi_resource *res, void *context) { - switch (res->type) { - case ACPI_RESOURCE_TYPE_END_TAG: - return AE_OK; + struct resource r; - case ACPI_RESOURCE_TYPE_IO: - port = res->data.io.minimum; + if (acpi_dev_resource_io(res, &r)) { + port = r.start; return AE_OK; - - default: - return AE_ERROR; } + + return AE_ERROR; } static int pvpanic_add(struct acpi_device *device) -- cgit v1.2.2 From 725eba2928ada8d0fe6bafb984e37576851edc91 Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 6 Nov 2018 22:57:14 +0800 Subject: misc/pvpanic: add MMIO support On some architectures (e.g. arm64), it's preferable to use MMIO, since this can be used standalone. Add MMIO support to the pvpanic driver. Suggested-by: Andy Shevchenko [Use acpi_dev_resource_memory API. - Andy] Reviewed-by: Andy Shevchenko Acked-by: Mark Rutland Signed-off-by: Peng Hao Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index 49c59e1d299d..a46701c22b35 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -26,6 +26,8 @@ #include #include +static void __iomem *base; + MODULE_AUTHOR("Hu Tao "); MODULE_DESCRIPTION("pvpanic device driver"); MODULE_LICENSE("GPL"); @@ -41,8 +43,6 @@ MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids); #define PVPANIC_PANICKED (1 << 0) -static u16 port; - static struct acpi_driver pvpanic_driver = { .name = "pvpanic", .class = "QEMU", @@ -57,7 +57,7 @@ static struct acpi_driver pvpanic_driver = { static void pvpanic_send_event(unsigned int event) { - outb(event, port); + iowrite8(event, base); } static int @@ -80,7 +80,10 @@ pvpanic_walk_resources(struct acpi_resource *res, void *context) struct resource r; if (acpi_dev_resource_io(res, &r)) { - port = r.start; + base = ioport_map(r.start, resource_size(&r)); + return AE_OK; + } else if (acpi_dev_resource_memory(res, &r)) { + base = ioremap(r.start, resource_size(&r)); return AE_OK; } @@ -101,7 +104,7 @@ static int pvpanic_add(struct acpi_device *device) acpi_walk_resources(device->handle, METHOD_NAME__CRS, pvpanic_walk_resources, NULL); - if (!port) + if (!base) return -ENODEV; atomic_notifier_chain_register(&panic_notifier_list, @@ -115,6 +118,8 @@ static int pvpanic_remove(struct acpi_device *device) atomic_notifier_chain_unregister(&panic_notifier_list, &pvpanic_panic_nb); + iounmap(base); + return 0; } -- cgit v1.2.2 From 46f934c9a12fc565fe2ae82c709162fa002a2998 Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 6 Nov 2018 22:57:16 +0800 Subject: misc/pvpanic: add support to get pvpanic device info FDT By default, when ACPI tables and FDT coexist for ARM64, current kernel takes precedence over FDT to get device information. Virt machine in qemu provides both FDT and ACPI table. Increases the way to get information through FDT. Acked-by: Mark Rutland Signed-off-by: Peng Hao Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index a46701c22b35..fef76b5d5f0c 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -2,6 +2,7 @@ * pvpanic.c - pvpanic Device Support * * Copyright (C) 2013 Fujitsu. + * Copyright (C) 2018 ZTE. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,6 +23,9 @@ #include #include +#include +#include +#include #include #include #include @@ -123,4 +127,62 @@ static int pvpanic_remove(struct acpi_device *device) return 0; } -module_acpi_driver(pvpanic_driver); +static int pvpanic_mmio_probe(struct platform_device *pdev) +{ + struct resource *mem; + + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!mem) + return -EINVAL; + + base = devm_ioremap_resource(&pdev->dev, mem); + if (base == NULL) + return -EFAULT; + + atomic_notifier_chain_register(&panic_notifier_list, + &pvpanic_panic_nb); + + return 0; +} + +static int pvpanic_mmio_remove(struct platform_device *pdev) +{ + + atomic_notifier_chain_unregister(&panic_notifier_list, + &pvpanic_panic_nb); + + return 0; +} + +static const struct of_device_id pvpanic_mmio_match[] = { + { .compatible = "qemu,pvpanic-mmio", }, + {} +}; + +static struct platform_driver pvpanic_mmio_driver = { + .driver = { + .name = "pvpanic-mmio", + .of_match_table = pvpanic_mmio_match, + }, + .probe = pvpanic_mmio_probe, + .remove = pvpanic_mmio_remove, +}; + +static int __init pvpanic_mmio_init(void) +{ + if (acpi_disabled) + return platform_driver_register(&pvpanic_mmio_driver); + else + return acpi_bus_register_driver(&pvpanic_driver); +} + +static void __exit pvpanic_mmio_exit(void) +{ + if (acpi_disabled) + platform_driver_unregister(&pvpanic_mmio_driver); + else + acpi_bus_unregister_driver(&pvpanic_driver); +} + +module_init(pvpanic_mmio_init); +module_exit(pvpanic_mmio_exit); -- cgit v1.2.2 From a8b71d2735791f09788a13dda928f690a417c14a Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 6 Nov 2018 22:57:17 +0800 Subject: misc/pvpanic : grouping ACPI related stuff Grouping ACPI related stuff and make preparation to break the ACPI dependency w/o any functional change. Reviewed-by: Andy Shevchenko Signed-off-by: Peng Hao Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index fef76b5d5f0c..eabb53d077c5 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -32,32 +32,12 @@ static void __iomem *base; +#define PVPANIC_PANICKED (1 << 0) + MODULE_AUTHOR("Hu Tao "); MODULE_DESCRIPTION("pvpanic device driver"); MODULE_LICENSE("GPL"); -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); - -#define PVPANIC_PANICKED (1 << 0) - -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 void pvpanic_send_event(unsigned int event) { @@ -77,6 +57,25 @@ static struct notifier_block pvpanic_panic_nb = { .priority = 1, /* let this called before broken drm_fb_helper */ }; +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) -- cgit v1.2.2 From 77703e0b0326a1fb06b5cb5b468a633472c5a8e9 Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 6 Nov 2018 22:57:18 +0800 Subject: misc/pvpanic : break dependency on ACPI The pvpanic driver is available for architectures that do not support ACPI.So break the dependency. Reviewed-by: Andy Shevchenko Signed-off-by: Peng Hao Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index eabb53d077c5..aab06b890bb6 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -57,6 +57,7 @@ static struct notifier_block pvpanic_panic_nb = { .priority = 1, /* let this called before broken drm_fb_helper */ }; +#ifdef CONFIG_ACPI static int pvpanic_add(struct acpi_device *device); static int pvpanic_remove(struct acpi_device *device); @@ -126,6 +127,24 @@ static int pvpanic_remove(struct acpi_device *device) return 0; } +static int pvpanic_register_acpi_driver(void) +{ + return acpi_bus_register_driver(&pvpanic_driver); +} + +static void pvpanic_unregister_acpi_driver(void) +{ + acpi_bus_unregister_driver(&pvpanic_driver); +} +#else +static int pvpanic_register_acpi_driver(void) +{ + return -ENODEV; +} + +static void pvpanic_unregister_acpi_driver(void) {} +#endif + static int pvpanic_mmio_probe(struct platform_device *pdev) { struct resource *mem; @@ -172,7 +191,7 @@ static int __init pvpanic_mmio_init(void) if (acpi_disabled) return platform_driver_register(&pvpanic_mmio_driver); else - return acpi_bus_register_driver(&pvpanic_driver); + return pvpanic_register_acpi_driver(); } static void __exit pvpanic_mmio_exit(void) @@ -180,7 +199,7 @@ static void __exit pvpanic_mmio_exit(void) if (acpi_disabled) platform_driver_unregister(&pvpanic_mmio_driver); else - acpi_bus_unregister_driver(&pvpanic_driver); + pvpanic_unregister_acpi_driver(); } module_init(pvpanic_mmio_init); -- cgit v1.2.2 From bfebd5c222ddfce70dde0c2e18f6859f33891db3 Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 6 Nov 2018 22:57:19 +0800 Subject: misc/pvpanic: remove unnecessary header file Remove unnecessary header file init.h. Reviewed-by: Andy Shevchenko Acked-by: Mark Rutland Signed-off-by: Peng Hao Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index aab06b890bb6..b9402d9fea15 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include -- cgit v1.2.2 From 8eeffed038b92ff811364bf91acab4b2e6a47e7e Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 6 Nov 2018 22:57:20 +0800 Subject: misc/pvpanic: change header file sort style Make header files alphabetical order. Signed-off-by: Peng Hao Reviewed-by: Andy Shevchenko Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index b9402d9fea15..3bfa0f5484d0 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -21,13 +21,13 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include #include #include #include -#include static void __iomem *base; -- cgit v1.2.2 From 7247932c7df2619d719175fc76327480c7259e80 Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 6 Nov 2018 22:57:21 +0800 Subject: misc/pvpanic: convert to SPDX license tags Updates license to use SPDX-License-Identifier instead of verbose license text. Reviewed-by: Andy Shevchenko Acked-by: Mark Rutland Signed-off-by: Peng Hao Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index 3bfa0f5484d0..47854f3c9f46 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -1,22 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0+ /* - * pvpanic.c - pvpanic Device Support + * Pvpanic Device Support * * Copyright (C) 2013 Fujitsu. * Copyright (C) 2018 ZTE. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt -- cgit v1.2.2 From 78ef4193bbb97d17853f64a7975aa971d625c478 Mon Sep 17 00:00:00 2001 From: Peng Hao Date: Tue, 6 Nov 2018 22:57:22 +0800 Subject: misc/pvpanic: remove a redundant comma Remove a redundant comma in pvpanic_device_ids. Reviewed-by: Andy Shevchenko Acked-by: Mark Rutland Signed-off-by: Peng Hao Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index 47854f3c9f46..01241ec6a5cd 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -49,7 +49,7 @@ static int pvpanic_remove(struct acpi_device *device); static const struct acpi_device_id pvpanic_device_ids[] = { { "QEMU0001", 0 }, - { "", 0 }, + { "", 0 } }; MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids); -- cgit v1.2.2 From 97a64ba77db12e3f33680fc2540453c35b3681f7 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 26 Nov 2018 11:12:29 +0300 Subject: misc/pvpanic: fix a NULL vs IS_ERR() check The devm_ioremap_resource() function doesn't return NULL, it returns error pointers. Fixes: 46f934c9a12f ("misc/pvpanic: add support to get pvpanic device info FDT") Signed-off-by: Dan Carpenter Signed-off-by: Greg Kroah-Hartman --- drivers/misc/pvpanic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/misc/pvpanic.c') diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c index 01241ec6a5cd..595ac065b401 100644 --- a/drivers/misc/pvpanic.c +++ b/drivers/misc/pvpanic.c @@ -140,8 +140,8 @@ static int pvpanic_mmio_probe(struct platform_device *pdev) return -EINVAL; base = devm_ioremap_resource(&pdev->dev, mem); - if (base == NULL) - return -EFAULT; + if (IS_ERR(base)) + return PTR_ERR(base); atomic_notifier_chain_register(&panic_notifier_list, &pvpanic_panic_nb); -- cgit v1.2.2