pvpanic-mmio.c 1.7 KB

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