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