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