2018-11-06 17:57:21 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-05-08 07:15:32 +04:00
|
|
|
/*
|
2021-03-24 17:49:14 +03:00
|
|
|
* Pvpanic MMIO Device Support
|
2013-05-08 07:15:32 +04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Fujitsu.
|
2018-11-06 17:57:16 +03:00
|
|
|
* Copyright (C) 2018 ZTE.
|
2021-03-24 17:49:14 +03:00
|
|
|
* Copyright (C) 2021 Oracle.
|
2013-05-08 07:15:32 +04:00
|
|
|
*/
|
|
|
|
|
2020-12-09 23:36:41 +03:00
|
|
|
#include <linux/io.h>
|
2013-05-08 07:15:32 +04:00
|
|
|
#include <linux/kernel.h>
|
2020-01-02 05:35:13 +03:00
|
|
|
#include <linux/kexec.h>
|
2020-12-09 23:36:42 +03:00
|
|
|
#include <linux/mod_devicetable.h>
|
2013-05-08 07:15:32 +04:00
|
|
|
#include <linux/module.h>
|
2018-11-06 17:57:16 +03:00
|
|
|
#include <linux/platform_device.h>
|
2013-05-08 07:15:32 +04:00
|
|
|
#include <linux/types.h>
|
2021-03-24 17:49:15 +03:00
|
|
|
#include <linux/slab.h>
|
2020-12-09 23:36:42 +03:00
|
|
|
|
2020-01-02 05:35:12 +03:00
|
|
|
#include <uapi/misc/pvpanic.h>
|
2013-05-08 07:15:32 +04:00
|
|
|
|
2021-03-24 17:49:14 +03:00
|
|
|
#include "pvpanic.h"
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Hu Tao <hutao@cn.fujitsu.com>");
|
|
|
|
MODULE_DESCRIPTION("pvpanic-mmio device driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2021-01-10 14:53:57 +03:00
|
|
|
static ssize_t capability_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
2021-03-24 17:49:15 +03:00
|
|
|
struct pvpanic_instance *pi = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
return sysfs_emit(buf, "%x\n", pi->capability);
|
2021-01-10 14:53:57 +03:00
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(capability);
|
|
|
|
|
2021-01-10 14:53:58 +03:00
|
|
|
static ssize_t events_show(struct device *dev, struct device_attribute *attr, char *buf)
|
|
|
|
{
|
2021-03-24 17:49:15 +03:00
|
|
|
struct pvpanic_instance *pi = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
return sysfs_emit(buf, "%x\n", pi->events);
|
2021-01-10 14:53:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t events_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
2021-03-24 17:49:15 +03:00
|
|
|
struct pvpanic_instance *pi = dev_get_drvdata(dev);
|
2021-01-10 14:53:58 +03:00
|
|
|
unsigned int tmp;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = kstrtouint(buf, 16, &tmp);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2021-03-24 17:49:15 +03:00
|
|
|
if ((tmp & pi->capability) != tmp)
|
2021-01-10 14:53:58 +03:00
|
|
|
return -EINVAL;
|
|
|
|
|
2021-03-24 17:49:15 +03:00
|
|
|
pi->events = tmp;
|
2021-03-24 17:49:14 +03:00
|
|
|
|
2021-01-10 14:53:58 +03:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RW(events);
|
|
|
|
|
2021-03-24 17:49:14 +03:00
|
|
|
static struct attribute *pvpanic_mmio_dev_attrs[] = {
|
2021-01-10 14:53:57 +03:00
|
|
|
&dev_attr_capability.attr,
|
2021-01-10 14:53:58 +03:00
|
|
|
&dev_attr_events.attr,
|
2021-01-10 14:53:57 +03:00
|
|
|
NULL
|
|
|
|
};
|
2021-03-24 17:49:14 +03:00
|
|
|
ATTRIBUTE_GROUPS(pvpanic_mmio_dev);
|
2013-05-08 07:15:32 +04:00
|
|
|
|
2018-11-06 17:57:16 +03:00
|
|
|
static int pvpanic_mmio_probe(struct platform_device *pdev)
|
|
|
|
{
|
2020-12-09 23:36:41 +03:00
|
|
|
struct device *dev = &pdev->dev;
|
2021-03-24 17:49:15 +03:00
|
|
|
struct pvpanic_instance *pi;
|
2020-12-09 23:36:41 +03:00
|
|
|
struct resource *res;
|
2021-03-24 17:49:15 +03:00
|
|
|
void __iomem *base;
|
2020-12-09 23:36:41 +03:00
|
|
|
|
|
|
|
res = platform_get_mem_or_io(pdev, 0);
|
2020-12-28 21:43:13 +03:00
|
|
|
if (!res)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
switch (resource_type(res)) {
|
|
|
|
case IORESOURCE_IO:
|
2020-12-09 23:36:41 +03:00
|
|
|
base = devm_ioport_map(dev, res->start, resource_size(res));
|
2020-12-28 21:43:13 +03:00
|
|
|
if (!base)
|
|
|
|
return -ENOMEM;
|
|
|
|
break;
|
|
|
|
case IORESOURCE_MEM:
|
2020-12-09 23:36:41 +03:00
|
|
|
base = devm_ioremap_resource(dev, res);
|
2020-12-28 21:43:13 +03:00
|
|
|
if (IS_ERR(base))
|
|
|
|
return PTR_ERR(base);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-11-06 17:57:16 +03:00
|
|
|
|
2021-03-24 17:49:15 +03:00
|
|
|
pi = kmalloc(sizeof(*pi), GFP_ATOMIC);
|
|
|
|
if (!pi)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pi->base = base;
|
|
|
|
pi->capability = PVPANIC_PANICKED | PVPANIC_CRASH_LOADED;
|
|
|
|
|
2021-01-10 14:53:57 +03:00
|
|
|
/* initlize capability by RDPT */
|
2021-03-24 17:49:15 +03:00
|
|
|
pi->capability &= ioread8(base);
|
|
|
|
pi->events = pi->capability;
|
2021-01-10 14:53:57 +03:00
|
|
|
|
2021-03-24 17:49:15 +03:00
|
|
|
dev_set_drvdata(dev, pi);
|
2018-11-06 17:57:16 +03:00
|
|
|
|
2021-03-24 17:49:15 +03:00
|
|
|
return pvpanic_probe(pi);
|
2018-11-06 17:57:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pvpanic_mmio_remove(struct platform_device *pdev)
|
|
|
|
{
|
2021-03-24 17:49:15 +03:00
|
|
|
struct pvpanic_instance *pi = dev_get_drvdata(&pdev->dev);
|
2018-11-06 17:57:16 +03:00
|
|
|
|
2021-03-24 17:49:15 +03:00
|
|
|
pvpanic_remove(pi);
|
|
|
|
kfree(pi);
|
2018-11-06 17:57:16 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id pvpanic_mmio_match[] = {
|
|
|
|
{ .compatible = "qemu,pvpanic-mmio", },
|
|
|
|
{}
|
|
|
|
};
|
2021-02-18 15:31:16 +03:00
|
|
|
MODULE_DEVICE_TABLE(of, pvpanic_mmio_match);
|
2018-11-06 17:57:16 +03:00
|
|
|
|
2020-12-09 23:36:41 +03:00
|
|
|
static const struct acpi_device_id pvpanic_device_ids[] = {
|
|
|
|
{ "QEMU0001", 0 },
|
|
|
|
{ "", 0 }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, pvpanic_device_ids);
|
|
|
|
|
2018-11-06 17:57:16 +03:00
|
|
|
static struct platform_driver pvpanic_mmio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "pvpanic-mmio",
|
|
|
|
.of_match_table = pvpanic_mmio_match,
|
2020-12-09 23:36:41 +03:00
|
|
|
.acpi_match_table = pvpanic_device_ids,
|
2021-03-24 17:49:14 +03:00
|
|
|
.dev_groups = pvpanic_mmio_dev_groups,
|
2018-11-06 17:57:16 +03:00
|
|
|
},
|
|
|
|
.probe = pvpanic_mmio_probe,
|
|
|
|
.remove = pvpanic_mmio_remove,
|
|
|
|
};
|
2020-12-09 23:36:41 +03:00
|
|
|
module_platform_driver(pvpanic_mmio_driver);
|