diff options
author | Mihai Carabas <mihai.carabas@oracle.com> | 2021-03-24 16:49:14 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2021-03-28 14:56:13 +0200 |
commit | 6861d27cf590d20a95b5d0724ac3768583b62947 (patch) | |
tree | 33c3d873167453a2df3bf824e6a252da8ea5dabe /drivers/misc/pvpanic/pvpanic.c | |
parent | 6880149e5a78962a055720981d37e5069f296ef7 (diff) | |
download | linux-6861d27cf590d20a95b5d0724ac3768583b62947.tar.bz2 |
misc/pvpanic: split-up generic and platform dependent code
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 patches.
The code from pvpanic.c was split in two new files:
- pvpanic.c: generic code that handles pvpanic events
- pvpanic-mmio.c: platform/bus dependent code
Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com>
Link: https://lore.kernel.org/r/1616597356-20696-2-git-send-email-mihai.carabas@oracle.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/pvpanic/pvpanic.c')
-rw-r--r-- | drivers/misc/pvpanic/pvpanic.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/drivers/misc/pvpanic/pvpanic.c b/drivers/misc/pvpanic/pvpanic.c new file mode 100644 index 000000000000..a9605f90c534 --- /dev/null +++ b/drivers/misc/pvpanic/pvpanic.c @@ -0,0 +1,81 @@ +// 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> + +#include "pvpanic.h" + +MODULE_AUTHOR("Mihai Carabas <mihai.carabas@oracle.com>"); +MODULE_DESCRIPTION("pvpanic device driver "); +MODULE_LICENSE("GPL"); + +static void __iomem *base; +static unsigned int capability; +static unsigned int events; + +static void +pvpanic_send_event(unsigned int event) +{ + if (event & capability & events) + 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, unsigned int dev_cap) +{ + base = pbase; + capability = dev_cap; + events = capability; + + if (capability) + atomic_notifier_chain_register(&panic_notifier_list, + &pvpanic_panic_nb); +} +EXPORT_SYMBOL_GPL(pvpanic_probe); + +void pvpanic_remove(void) +{ + if (capability) + atomic_notifier_chain_unregister(&panic_notifier_list, + &pvpanic_panic_nb); + base = NULL; +} +EXPORT_SYMBOL_GPL(pvpanic_remove); + +void pvpanic_set_events(unsigned int dev_events) +{ + events = dev_events; +} +EXPORT_SYMBOL_GPL(pvpanic_set_events); |