xref: /linux/drivers/misc/pvpanic/pvpanic-mmio.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
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/device.h>
11 #include <linux/err.h>
12 #include <linux/io.h>
13 #include <linux/ioport.h>
14 #include <linux/kexec.h>
15 #include <linux/mod_devicetable.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/types.h>
19 
20 #include "pvpanic.h"
21 
22 MODULE_AUTHOR("Hu Tao <hutao@cn.fujitsu.com>");
23 MODULE_DESCRIPTION("pvpanic-mmio device driver");
24 MODULE_LICENSE("GPL");
25 
26 static int pvpanic_mmio_probe(struct platform_device *pdev)
27 {
28 	struct device *dev = &pdev->dev;
29 	struct resource *res;
30 	void __iomem *base;
31 
32 	res = platform_get_mem_or_io(pdev, 0);
33 	if (!res)
34 		return -EINVAL;
35 
36 	switch (resource_type(res)) {
37 	case IORESOURCE_IO:
38 		base = devm_ioport_map(dev, res->start, resource_size(res));
39 		if (!base)
40 			return -ENOMEM;
41 		break;
42 	case IORESOURCE_MEM:
43 		base = devm_ioremap_resource(dev, res);
44 		if (IS_ERR(base))
45 			return PTR_ERR(base);
46 		break;
47 	default:
48 		return -EINVAL;
49 	}
50 
51 	return devm_pvpanic_probe(dev, base);
52 }
53 
54 static const struct of_device_id pvpanic_mmio_match[] = {
55 	{ .compatible = "qemu,pvpanic-mmio", },
56 	{}
57 };
58 MODULE_DEVICE_TABLE(of, pvpanic_mmio_match);
59 
60 static const struct acpi_device_id pvpanic_device_ids[] = {
61 	{ "QEMU0001", 0 },
62 	{ "", 0 }
63 };
64 MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
65 
66 static struct platform_driver pvpanic_mmio_driver = {
67 	.driver = {
68 		.name = "pvpanic-mmio",
69 		.of_match_table = pvpanic_mmio_match,
70 		.acpi_match_table = pvpanic_device_ids,
71 		.dev_groups = pvpanic_dev_groups,
72 	},
73 	.probe = pvpanic_mmio_probe,
74 };
75 module_platform_driver(pvpanic_mmio_driver);
76