1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  Pvpanic MMIO Device Support
4  *
5  *  Copyright (C) 2013 Fujitsu.
6  *  Copyright (C) 2018 ZTE.
7  *  Copyright (C) 2021 Oracle.
8  */
9 
10 #include <linux/io.h>
11 #include <linux/kernel.h>
12 #include <linux/kexec.h>
13 #include <linux/mod_devicetable.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
16 #include <linux/types.h>
17 #include <linux/slab.h>
18 
19 #include <uapi/misc/pvpanic.h>
20 
21 #include "pvpanic.h"
22 
23 MODULE_AUTHOR("Hu Tao <hutao@cn.fujitsu.com>");
24 MODULE_DESCRIPTION("pvpanic-mmio device driver");
25 MODULE_LICENSE("GPL");
26 
pvpanic_mmio_probe(struct platform_device * pdev)27 static int pvpanic_mmio_probe(struct platform_device *pdev)
28 {
29 	struct device *dev = &pdev->dev;
30 	struct resource *res;
31 	void __iomem *base;
32 
33 	res = platform_get_mem_or_io(pdev, 0);
34 	if (!res)
35 		return -EINVAL;
36 
37 	switch (resource_type(res)) {
38 	case IORESOURCE_IO:
39 		base = devm_ioport_map(dev, res->start, resource_size(res));
40 		if (!base)
41 			return -ENOMEM;
42 		break;
43 	case IORESOURCE_MEM:
44 		base = devm_ioremap_resource(dev, res);
45 		if (IS_ERR(base))
46 			return PTR_ERR(base);
47 		break;
48 	default:
49 		return -EINVAL;
50 	}
51 
52 	return devm_pvpanic_probe(dev, base);
53 }
54 
55 static const struct of_device_id pvpanic_mmio_match[] = {
56 	{ .compatible = "qemu,pvpanic-mmio", },
57 	{}
58 };
59 MODULE_DEVICE_TABLE(of, pvpanic_mmio_match);
60 
61 static const struct acpi_device_id pvpanic_device_ids[] = {
62 	{ "QEMU0001", 0 },
63 	{ "", 0 }
64 };
65 MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
66 
67 static struct platform_driver pvpanic_mmio_driver = {
68 	.driver = {
69 		.name = "pvpanic-mmio",
70 		.of_match_table = pvpanic_mmio_match,
71 		.acpi_match_table = pvpanic_device_ids,
72 		.dev_groups = pvpanic_dev_groups,
73 	},
74 	.probe = pvpanic_mmio_probe,
75 };
76 module_platform_driver(pvpanic_mmio_driver);
77