Return 0 for empty body register function normally.
Signed-off-by: Peng Hao <[email protected]>
---
v4 --> v5 : resolve kbuild issue: handle all typo "drvier/driver"
in funtion name.
v3 --> v4 : use pcim* function instead of pci* function.
handle typo "drvier/driver" in funtion name.
v2 --> v3 : resolve kbuild issue : a uninitialized variable in some path.
v2 --> v1 : resolve kbuild issue : arch=sh don't support pci, adjust
CONFIG_PCI macro.
v1 : QEMU community requires additional PCI devices to simulate PVPANIC devices
so that some architectures can not occupy precious less than 4G of memory
space.
drivers/misc/pvpanic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c
index 3150dc2..f84ed30 100644
--- a/drivers/misc/pvpanic.c
+++ b/drivers/misc/pvpanic.c
@@ -125,7 +125,7 @@ static void pvpanic_unregister_acpi_driver(void)
#else
static int pvpanic_register_acpi_driver(void)
{
- return -ENODEV;
+ return 0;
}
static void pvpanic_unregister_acpi_driver(void) {}
--
1.8.3.1
Support pvpanic as a pci device in guest kernel.
Suggested-by: Andy Shevchenko <[email protected]>
[Use pcim_* API. - Andy]
Signed-off-by: Peng Hao <[email protected]>
---
drivers/misc/pvpanic.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 70 insertions(+), 2 deletions(-)
diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c
index f84ed30..c30bf62 100644
--- a/drivers/misc/pvpanic.c
+++ b/drivers/misc/pvpanic.c
@@ -13,9 +13,12 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
+#include <linux/pci.h>
#include <linux/platform_device.h>
#include <linux/types.h>
+#define PCI_VENDOR_ID_REDHAT 0x1b36
+#define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0101
static void __iomem *base;
#define PVPANIC_PANICKED (1 << 0)
@@ -172,12 +175,76 @@ static int pvpanic_mmio_remove(struct platform_device *pdev)
.remove = pvpanic_mmio_remove,
};
+#ifdef CONFIG_PCI
+static const struct pci_device_id pvpanic_pci_id_tbl[] = {
+ { PCI_DEVICE(PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_PVPANIC),},
+ {}
+};
+
+static int pvpanic_pci_probe(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
+{
+ int ret;
+
+ ret = pcim_enable_device(pdev);
+ if (ret < 0)
+ return ret;
+
+ ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
+ if (ret)
+ return ret;
+
+ base = pcim_iomap_table(pdev)[0];
+
+ atomic_notifier_chain_register(&panic_notifier_list,
+ &pvpanic_panic_nb);
+ return 0;
+}
+
+static void pvpanic_pci_remove(struct pci_dev *pdev)
+{
+ atomic_notifier_chain_unregister(&panic_notifier_list,
+ &pvpanic_panic_nb);
+}
+
+static struct pci_driver pvpanic_pci_driver = {
+ .name = "pvpanic-pci",
+ .id_table = pvpanic_pci_id_tbl,
+ .probe = pvpanic_pci_probe,
+ .remove = pvpanic_pci_remove,
+};
+
+static int pvpanic_register_pci_driver(void)
+{
+ return pci_register_driver(&pvpanic_pci_driver);
+}
+
+static void pvpanic_unregister_pci_driver(void)
+{
+ pci_unregister_driver(&pvpanic_pci_driver);
+}
+#else
+static int pvpanic_register_pci_driver(void)
+{
+ return 0;
+}
+
+static void pvpanic_unregister_pci_driver(void) {}
+#endif
+
static int __init pvpanic_mmio_init(void)
{
+ int r1, r2;
+
if (acpi_disabled)
- return platform_driver_register(&pvpanic_mmio_driver);
+ r1 = platform_driver_register(&pvpanic_mmio_driver);
+ else
+ r1 = pvpanic_register_acpi_driver();
+ r2 = pvpanic_register_pci_driver();
+ if (r1 && r2) /* all drivers register failed */
+ return 1;
else
- return pvpanic_register_acpi_driver();
+ return 0;
}
static void __exit pvpanic_mmio_exit(void)
@@ -186,6 +253,7 @@ static void __exit pvpanic_mmio_exit(void)
platform_driver_unregister(&pvpanic_mmio_driver);
else
pvpanic_unregister_acpi_driver();
+ pvpanic_unregister_pci_driver();
}
module_init(pvpanic_mmio_init);
--
1.8.3.1
Add PCI dependency for pvpanic in Kconfig.
Signed-off-by: Peng Hao <[email protected]>
---
drivers/misc/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index f417b06..5ff8ca4 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -515,7 +515,7 @@ config MISC_RTSX
config PVPANIC
tristate "pvpanic device support"
- depends on HAS_IOMEM && (ACPI || OF)
+ depends on HAS_IOMEM && (ACPI || OF || PCI)
help
This driver provides support for the pvpanic device. pvpanic is
a paravirtualized device provided by QEMU; it lets a virtual machine
--
1.8.3.1
On Thu, Dec 20, 2018 at 6:57 AM Peng Hao <[email protected]> wrote:
>
> Support pvpanic as a pci device in guest kernel.
>
After my vacation followed by holidays I hardly remember what I suggested.
Looking to this code I would recommend to split it in a way how it's
done for ChipIdea USB driver, for example.
(drivers/usb/chipidea if I'm not mistaken)
> Suggested-by: Andy Shevchenko <[email protected]>
> [Use pcim_* API. - Andy]
> Signed-off-by: Peng Hao <[email protected]>
> ---
> drivers/misc/pvpanic.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 70 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c
> index f84ed30..c30bf62 100644
> --- a/drivers/misc/pvpanic.c
> +++ b/drivers/misc/pvpanic.c
> @@ -13,9 +13,12 @@
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/of_address.h>
> +#include <linux/pci.h>
> #include <linux/platform_device.h>
> #include <linux/types.h>
>
> +#define PCI_VENDOR_ID_REDHAT 0x1b36
> +#define PCI_DEVICE_ID_REDHAT_PVPANIC 0x0101
> static void __iomem *base;
>
> #define PVPANIC_PANICKED (1 << 0)
> @@ -172,12 +175,76 @@ static int pvpanic_mmio_remove(struct platform_device *pdev)
> .remove = pvpanic_mmio_remove,
> };
>
> +#ifdef CONFIG_PCI
> +static const struct pci_device_id pvpanic_pci_id_tbl[] = {
> + { PCI_DEVICE(PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_PVPANIC),},
> + {}
> +};
> +
> +static int pvpanic_pci_probe(struct pci_dev *pdev,
> + const struct pci_device_id *ent)
> +{
> + int ret;
> +
> + ret = pcim_enable_device(pdev);
> + if (ret < 0)
> + return ret;
> +
> + ret = pcim_iomap_regions(pdev, 1 << 0, pci_name(pdev));
> + if (ret)
> + return ret;
> +
> + base = pcim_iomap_table(pdev)[0];
> +
> + atomic_notifier_chain_register(&panic_notifier_list,
> + &pvpanic_panic_nb);
> + return 0;
> +}
> +
> +static void pvpanic_pci_remove(struct pci_dev *pdev)
> +{
> + atomic_notifier_chain_unregister(&panic_notifier_list,
> + &pvpanic_panic_nb);
> +}
> +
> +static struct pci_driver pvpanic_pci_driver = {
> + .name = "pvpanic-pci",
> + .id_table = pvpanic_pci_id_tbl,
> + .probe = pvpanic_pci_probe,
> + .remove = pvpanic_pci_remove,
> +};
> +
> +static int pvpanic_register_pci_driver(void)
> +{
> + return pci_register_driver(&pvpanic_pci_driver);
> +}
> +
> +static void pvpanic_unregister_pci_driver(void)
> +{
> + pci_unregister_driver(&pvpanic_pci_driver);
> +}
> +#else
> +static int pvpanic_register_pci_driver(void)
> +{
> + return 0;
> +}
> +
> +static void pvpanic_unregister_pci_driver(void) {}
> +#endif
> +
> static int __init pvpanic_mmio_init(void)
> {
> + int r1, r2;
> +
> if (acpi_disabled)
> - return platform_driver_register(&pvpanic_mmio_driver);
> + r1 = platform_driver_register(&pvpanic_mmio_driver);
> + else
> + r1 = pvpanic_register_acpi_driver();
> + r2 = pvpanic_register_pci_driver();
> + if (r1 && r2) /* all drivers register failed */
> + return 1;
> else
> - return pvpanic_register_acpi_driver();
> + return 0;
> }
>
> static void __exit pvpanic_mmio_exit(void)
> @@ -186,6 +253,7 @@ static void __exit pvpanic_mmio_exit(void)
> platform_driver_unregister(&pvpanic_mmio_driver);
> else
> pvpanic_unregister_acpi_driver();
> + pvpanic_unregister_pci_driver();
> }
>
> module_init(pvpanic_mmio_init);
> --
> 1.8.3.1
>
--
With Best Regards,
Andy Shevchenko
On Thu, Dec 20, 2018 at 01:14:46PM +0800, Peng Hao wrote:
> Return 0 for empty body register function normally.
>
> Signed-off-by: Peng Hao <[email protected]>
> ---
> v4 --> v5 : resolve kbuild issue: handle all typo "drvier/driver"
> in funtion name.
>
> v3 --> v4 : use pcim* function instead of pci* function.
> handle typo "drvier/driver" in funtion name.
>
> v2 --> v3 : resolve kbuild issue : a uninitialized variable in some path.
>
> v2 --> v1 : resolve kbuild issue : arch=sh don't support pci, adjust
> CONFIG_PCI macro.
>
> v1 : QEMU community requires additional PCI devices to simulate PVPANIC devices
> so that some architectures can not occupy precious less than 4G of memory
> space.
>
> drivers/misc/pvpanic.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/misc/pvpanic.c b/drivers/misc/pvpanic.c
> index 3150dc2..f84ed30 100644
> --- a/drivers/misc/pvpanic.c
> +++ b/drivers/misc/pvpanic.c
> @@ -125,7 +125,7 @@ static void pvpanic_unregister_acpi_driver(void)
> #else
> static int pvpanic_register_acpi_driver(void)
> {
> - return -ENODEV;
> + return 0;
No, you want -ENODEV as this can only happen if acpi is enabled, and you
are on an kernel without acpi.
But, that can not happen, as if CONFIG_ACPI is not set, then
acpi_disabled is always set to 1, and then this can never be called.
So I don't see why this needs to be changed at all.
thanks,
greg k-h