Skip to content

Commit

Permalink
misc/pvpanic: split-up generic and platform dependent code
Browse files Browse the repository at this point in the history
Split-up generic and platform dependent code in order to be able to re-use
generic event handling code in pvpanic PCI device driver in the next patch.

The code from pvpanic.c was split in two new files:
- pvpanic-common.c: generic code that handles pvpanic events
- mmio.c: platform/bus dependent code

Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
  • Loading branch information
mcarabas authored and intel-lab-lkp committed Feb 12, 2021
1 parent 2ab38c1 commit 17d14b4
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 44 deletions.
9 changes: 1 addition & 8 deletions drivers/misc/Kconfig
Expand Up @@ -448,14 +448,6 @@ config MISC_RTSX
tristate
default MISC_RTSX_PCI || MISC_RTSX_USB

config PVPANIC
tristate "pvpanic device support"
depends on HAS_IOMEM && (ACPI || OF)
help
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.

config HISI_HIKEY_USB
tristate "USB GPIO Hub on HiSilicon Hikey 960/970 Platform"
depends on (OF && GPIOLIB) || COMPILE_TEST
Expand All @@ -481,4 +473,5 @@ source "drivers/misc/ocxl/Kconfig"
source "drivers/misc/cardreader/Kconfig"
source "drivers/misc/habanalabs/Kconfig"
source "drivers/misc/uacce/Kconfig"
source "drivers/misc/pvpanic/Kconfig"
endmenu
2 changes: 1 addition & 1 deletion drivers/misc/Makefile
Expand Up @@ -52,7 +52,7 @@ obj-$(CONFIG_CXL_BASE) += cxl/
obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o
obj-$(CONFIG_OCXL) += ocxl/
obj-y += cardreader/
obj-$(CONFIG_PVPANIC) += pvpanic.o
obj-$(CONFIG_PVPANIC) += pvpanic/
obj-$(CONFIG_HABANA_AI) += habanalabs/
obj-$(CONFIG_UACCE) += uacce/
obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o
Expand Down
12 changes: 12 additions & 0 deletions drivers/misc/pvpanic/Kconfig
@@ -0,0 +1,12 @@
config PVPANIC
bool "pvpanic device support"
help
This option enables pvpanic device driver.

config PVPANIC_MMIO
tristate "pvpanic MMIO device support"
depends on HAS_IOMEM && (ACPI || OF) && PVPANIC
help
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.
2 changes: 2 additions & 0 deletions drivers/misc/pvpanic/Makefile
@@ -0,0 +1,2 @@
obj-$(CONFIG_PVPANIC_MMIO) += pvpanic-mmio.o
pvpanic-mmio-objs := pvpanic-common.o mmio.o
42 changes: 7 additions & 35 deletions drivers/misc/pvpanic.c → drivers/misc/pvpanic/mmio.c
@@ -1,12 +1,11 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Pvpanic Device Support
* Pvpanic MMIO Device Support
*
* Copyright (C) 2013 Fujitsu.
* Copyright (C) 2018 ZTE.
*/

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
* Copyright (C) 2021 Oracle.
*/

#include <linux/io.h>
#include <linux/kernel.h>
Expand All @@ -17,42 +16,17 @@
#include <linux/types.h>

#include <uapi/misc/pvpanic.h>

static void __iomem *base;
#include "pvpanic.h"

MODULE_AUTHOR("Hu Tao <hutao@cn.fujitsu.com>");
MODULE_DESCRIPTION("pvpanic device driver");
MODULE_LICENSE("GPL");

static void
pvpanic_send_event(unsigned int event)
{
iowrite8(event, base);
}

static int
pvpanic_panic_notify(struct notifier_block *nb, unsigned long code,
void *unused)
{
unsigned int event = PVPANIC_PANICKED;

if (kexec_crash_loaded())
event = PVPANIC_CRASH_LOADED;

pvpanic_send_event(event);

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 int pvpanic_mmio_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct resource *res;
void __iomem *base;

res = platform_get_mem_or_io(pdev, 0);
if (!res)
Expand All @@ -73,17 +47,15 @@ static int pvpanic_mmio_probe(struct platform_device *pdev)
return -EINVAL;
}

atomic_notifier_chain_register(&panic_notifier_list,
&pvpanic_panic_nb);
pvpanic_probe(base);

return 0;
}

static int pvpanic_mmio_remove(struct platform_device *pdev)
{

atomic_notifier_chain_unregister(&panic_notifier_list,
&pvpanic_panic_nb);
pvpanic_remove();

return 0;
}
Expand Down
60 changes: 60 additions & 0 deletions drivers/misc/pvpanic/pvpanic-common.c
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Pvpanic Device Support
*
* Copyright (C) 2013 Fujitsu.
* Copyright (C) 2018 ZTE.
* Copyright (C) 2021 Oracle.
*/

#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/kexec.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/types.h>

#include <uapi/misc/pvpanic.h>

static void __iomem *base;

static void
pvpanic_send_event(unsigned int event)
{
iowrite8(event, base);
}

static int
pvpanic_panic_notify(struct notifier_block *nb, unsigned long code,
void *unused)
{
unsigned int event = PVPANIC_PANICKED;

if (kexec_crash_loaded())
event = PVPANIC_CRASH_LOADED;

pvpanic_send_event(event);

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 */
};

void pvpanic_probe(void __iomem *pbase)
{
base = pbase;
atomic_notifier_chain_register(&panic_notifier_list,
&pvpanic_panic_nb);
}

void pvpanic_remove(void)
{

atomic_notifier_chain_unregister(&panic_notifier_list,
&pvpanic_panic_nb);
base = NULL;
}
10 changes: 10 additions & 0 deletions drivers/misc/pvpanic/pvpanic.h
@@ -0,0 +1,10 @@
#ifndef PVPANIC_H_
#define PVPANIC_H_


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

void pvpanic_probe(void __iomem *base);
void pvpanic_remove(void);

#endif /* PVPANIC_H_ */

0 comments on commit 17d14b4

Please sign in to comment.