misc/pvpanic: probe multiple instances
Create the mecahism that allows multiple pvpanic instances to call pvpanic_probe and receive panic events. A global list will retain all the mapped addresses where to write panic events. Signed-off-by: Mihai Carabas <mihai.carabas@oracle.com> Link: https://lore.kernel.org/r/1616597356-20696-3-git-send-email-mihai.carabas@oracle.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Родитель
6861d27cf5
Коммит
b3c0f87746
|
@ -14,6 +14,7 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
#include <linux/slab.h>
|
||||||
|
|
||||||
#include <uapi/misc/pvpanic.h>
|
#include <uapi/misc/pvpanic.h>
|
||||||
|
|
||||||
|
@ -23,25 +24,26 @@ MODULE_AUTHOR("Hu Tao <hutao@cn.fujitsu.com>");
|
||||||
MODULE_DESCRIPTION("pvpanic-mmio device driver");
|
MODULE_DESCRIPTION("pvpanic-mmio device driver");
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
|
|
||||||
static void __iomem *base;
|
|
||||||
static unsigned int capability = PVPANIC_PANICKED | PVPANIC_CRASH_LOADED;
|
|
||||||
static unsigned int events;
|
|
||||||
|
|
||||||
static ssize_t capability_show(struct device *dev,
|
static ssize_t capability_show(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
return sysfs_emit(buf, "%x\n", capability);
|
struct pvpanic_instance *pi = dev_get_drvdata(dev);
|
||||||
|
|
||||||
|
return sysfs_emit(buf, "%x\n", pi->capability);
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RO(capability);
|
static DEVICE_ATTR_RO(capability);
|
||||||
|
|
||||||
static ssize_t events_show(struct device *dev, struct device_attribute *attr, char *buf)
|
static ssize_t events_show(struct device *dev, struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
return sysfs_emit(buf, "%x\n", events);
|
struct pvpanic_instance *pi = dev_get_drvdata(dev);
|
||||||
|
|
||||||
|
return sysfs_emit(buf, "%x\n", pi->events);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t events_store(struct device *dev, struct device_attribute *attr,
|
static ssize_t events_store(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
|
struct pvpanic_instance *pi = dev_get_drvdata(dev);
|
||||||
unsigned int tmp;
|
unsigned int tmp;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -49,15 +51,12 @@ static ssize_t events_store(struct device *dev, struct device_attribute *attr,
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if ((tmp & capability) != tmp)
|
if ((tmp & pi->capability) != tmp)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
events = tmp;
|
pi->events = tmp;
|
||||||
|
|
||||||
pvpanic_set_events(events);
|
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
|
||||||
}
|
}
|
||||||
static DEVICE_ATTR_RW(events);
|
static DEVICE_ATTR_RW(events);
|
||||||
|
|
||||||
|
@ -71,7 +70,9 @@ ATTRIBUTE_GROUPS(pvpanic_mmio_dev);
|
||||||
static int pvpanic_mmio_probe(struct platform_device *pdev)
|
static int pvpanic_mmio_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
|
struct pvpanic_instance *pi;
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
|
void __iomem *base;
|
||||||
|
|
||||||
res = platform_get_mem_or_io(pdev, 0);
|
res = platform_get_mem_or_io(pdev, 0);
|
||||||
if (!res)
|
if (!res)
|
||||||
|
@ -92,19 +93,28 @@ static int pvpanic_mmio_probe(struct platform_device *pdev)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pi = kmalloc(sizeof(*pi), GFP_ATOMIC);
|
||||||
|
if (!pi)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
pi->base = base;
|
||||||
|
pi->capability = PVPANIC_PANICKED | PVPANIC_CRASH_LOADED;
|
||||||
|
|
||||||
/* initlize capability by RDPT */
|
/* initlize capability by RDPT */
|
||||||
capability &= ioread8(base);
|
pi->capability &= ioread8(base);
|
||||||
events = capability;
|
pi->events = pi->capability;
|
||||||
|
|
||||||
pvpanic_probe(base, capability);
|
dev_set_drvdata(dev, pi);
|
||||||
|
|
||||||
return 0;
|
return pvpanic_probe(pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pvpanic_mmio_remove(struct platform_device *pdev)
|
static int pvpanic_mmio_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
struct pvpanic_instance *pi = dev_get_drvdata(&pdev->dev);
|
||||||
|
|
||||||
pvpanic_remove();
|
pvpanic_remove(pi);
|
||||||
|
kfree(pi);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
#include <linux/cdev.h>
|
||||||
|
#include <linux/list.h>
|
||||||
|
|
||||||
#include <uapi/misc/pvpanic.h>
|
#include <uapi/misc/pvpanic.h>
|
||||||
|
|
||||||
|
@ -23,15 +25,20 @@ MODULE_AUTHOR("Mihai Carabas <mihai.carabas@oracle.com>");
|
||||||
MODULE_DESCRIPTION("pvpanic device driver ");
|
MODULE_DESCRIPTION("pvpanic device driver ");
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
|
|
||||||
static void __iomem *base;
|
struct list_head pvpanic_list;
|
||||||
static unsigned int capability;
|
spinlock_t pvpanic_lock;
|
||||||
static unsigned int events;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pvpanic_send_event(unsigned int event)
|
pvpanic_send_event(unsigned int event)
|
||||||
{
|
{
|
||||||
if (event & capability & events)
|
struct pvpanic_instance *pi_cur;
|
||||||
iowrite8(event, base);
|
|
||||||
|
spin_lock(&pvpanic_lock);
|
||||||
|
list_for_each_entry(pi_cur, &pvpanic_list, list) {
|
||||||
|
if (event & pi_cur->capability & pi_cur->events)
|
||||||
|
iowrite8(event, pi_cur->base);
|
||||||
|
}
|
||||||
|
spin_unlock(&pvpanic_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -53,29 +60,54 @@ static struct notifier_block pvpanic_panic_nb = {
|
||||||
.priority = 1, /* let this called before broken drm_fb_helper */
|
.priority = 1, /* let this called before broken drm_fb_helper */
|
||||||
};
|
};
|
||||||
|
|
||||||
void pvpanic_probe(void __iomem *pbase, unsigned int dev_cap)
|
int pvpanic_probe(struct pvpanic_instance *pi)
|
||||||
{
|
{
|
||||||
base = pbase;
|
if (!pi || !pi->base)
|
||||||
capability = dev_cap;
|
return -EINVAL;
|
||||||
events = capability;
|
|
||||||
|
|
||||||
if (capability)
|
spin_lock(&pvpanic_lock);
|
||||||
atomic_notifier_chain_register(&panic_notifier_list,
|
list_add(&pi->list, &pvpanic_list);
|
||||||
&pvpanic_panic_nb);
|
spin_unlock(&pvpanic_lock);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(pvpanic_probe);
|
EXPORT_SYMBOL_GPL(pvpanic_probe);
|
||||||
|
|
||||||
void pvpanic_remove(void)
|
void pvpanic_remove(struct pvpanic_instance *pi)
|
||||||
{
|
{
|
||||||
if (capability)
|
struct pvpanic_instance *pi_cur, *pi_next;
|
||||||
atomic_notifier_chain_unregister(&panic_notifier_list,
|
|
||||||
&pvpanic_panic_nb);
|
if (!pi)
|
||||||
base = NULL;
|
return;
|
||||||
|
|
||||||
|
spin_lock(&pvpanic_lock);
|
||||||
|
list_for_each_entry_safe(pi_cur, pi_next, &pvpanic_list, list) {
|
||||||
|
if (pi_cur == pi) {
|
||||||
|
list_del(&pi_cur->list);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
spin_unlock(&pvpanic_lock);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(pvpanic_remove);
|
EXPORT_SYMBOL_GPL(pvpanic_remove);
|
||||||
|
|
||||||
void pvpanic_set_events(unsigned int dev_events)
|
static int pvpanic_init(void)
|
||||||
{
|
{
|
||||||
events = dev_events;
|
INIT_LIST_HEAD(&pvpanic_list);
|
||||||
|
spin_lock_init(&pvpanic_lock);
|
||||||
|
|
||||||
|
atomic_notifier_chain_register(&panic_notifier_list,
|
||||||
|
&pvpanic_panic_nb);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(pvpanic_set_events);
|
|
||||||
|
static void pvpanic_exit(void)
|
||||||
|
{
|
||||||
|
atomic_notifier_chain_unregister(&panic_notifier_list,
|
||||||
|
&pvpanic_panic_nb);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module_init(pvpanic_init);
|
||||||
|
module_exit(pvpanic_exit);
|
||||||
|
|
|
@ -8,8 +8,14 @@
|
||||||
#ifndef PVPANIC_H_
|
#ifndef PVPANIC_H_
|
||||||
#define PVPANIC_H_
|
#define PVPANIC_H_
|
||||||
|
|
||||||
void pvpanic_probe(void __iomem *base, unsigned int dev_cap);
|
struct pvpanic_instance {
|
||||||
void pvpanic_remove(void);
|
void __iomem *base;
|
||||||
void pvpanic_set_events(unsigned int dev_events);
|
unsigned int capability;
|
||||||
|
unsigned int events;
|
||||||
|
struct list_head list;
|
||||||
|
};
|
||||||
|
|
||||||
|
int pvpanic_probe(struct pvpanic_instance *pi);
|
||||||
|
void pvpanic_remove(struct pvpanic_instance *pi);
|
||||||
|
|
||||||
#endif /* PVPANIC_H_ */
|
#endif /* PVPANIC_H_ */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче