summaryrefslogtreecommitdiffstats
path: root/drivers/misc/pvpanic/pvpanic.c
blob: a9605f90c5347096db2f30b524d11c17fe90bfdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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);