Linux Audio

Check our new training course

Loading...
v6.2
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 *  Pvpanic PCI Device Support
  4 *
  5 *  Copyright (C) 2021 Oracle.
  6 */
  7
  8#include <linux/kernel.h>
  9#include <linux/module.h>
 10#include <linux/pci.h>
 11#include <linux/types.h>
 12#include <linux/slab.h>
 13
 14#include <uapi/misc/pvpanic.h>
 15
 16#include "pvpanic.h"
 17
 18#define PCI_VENDOR_ID_REDHAT             0x1b36
 19#define PCI_DEVICE_ID_REDHAT_PVPANIC     0x0011
 20
 21MODULE_AUTHOR("Mihai Carabas <mihai.carabas@oracle.com>");
 22MODULE_DESCRIPTION("pvpanic device driver");
 23MODULE_LICENSE("GPL");
 24
 25static ssize_t capability_show(struct device *dev, struct device_attribute *attr, char *buf)
 
 
 
 
 
 
 26{
 27	struct pvpanic_instance *pi = dev_get_drvdata(dev);
 28
 29	return sysfs_emit(buf, "%x\n", pi->capability);
 30}
 31static DEVICE_ATTR_RO(capability);
 32
 33static ssize_t events_show(struct device *dev, struct device_attribute *attr, char *buf)
 34{
 35	struct pvpanic_instance *pi = dev_get_drvdata(dev);
 36
 37	return sysfs_emit(buf, "%x\n", pi->events);
 38}
 39
 40static ssize_t events_store(struct device *dev, struct device_attribute *attr,
 41			    const char *buf, size_t count)
 42{
 43	struct pvpanic_instance *pi = dev_get_drvdata(dev);
 44	unsigned int tmp;
 45	int err;
 46
 47	err = kstrtouint(buf, 16, &tmp);
 48	if (err)
 49		return err;
 50
 51	if ((tmp & pi->capability) != tmp)
 52		return -EINVAL;
 53
 54	pi->events = tmp;
 55
 56	return count;
 57}
 58static DEVICE_ATTR_RW(events);
 59
 60static struct attribute *pvpanic_pci_dev_attrs[] = {
 61	&dev_attr_capability.attr,
 62	&dev_attr_events.attr,
 63	NULL
 64};
 65ATTRIBUTE_GROUPS(pvpanic_pci_dev);
 66
 67static int pvpanic_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 68{
 69	struct pvpanic_instance *pi;
 70	void __iomem *base;
 71	int ret;
 72
 73	ret = pcim_enable_device(pdev);
 74	if (ret < 0)
 75		return ret;
 76
 77	base = pcim_iomap(pdev, 0, 0);
 78	if (!base)
 79		return -ENOMEM;
 80
 81	pi = devm_kmalloc(&pdev->dev, sizeof(*pi), GFP_KERNEL);
 82	if (!pi)
 83		return -ENOMEM;
 84
 85	pi->base = base;
 86	pi->capability = PVPANIC_PANICKED | PVPANIC_CRASH_LOADED;
 87
 88	/* initlize capability by RDPT */
 89	pi->capability &= ioread8(base);
 90	pi->events = pi->capability;
 91
 92	return devm_pvpanic_probe(&pdev->dev, pi);
 93}
 94
 95static const struct pci_device_id pvpanic_pci_id_tbl[]  = {
 96	{ PCI_DEVICE(PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_PVPANIC)},
 97	{}
 98};
 99MODULE_DEVICE_TABLE(pci, pvpanic_pci_id_tbl);
100
101static struct pci_driver pvpanic_pci_driver = {
102	.name =         "pvpanic-pci",
103	.id_table =     pvpanic_pci_id_tbl,
104	.probe =        pvpanic_pci_probe,
105	.driver = {
106		.dev_groups = pvpanic_pci_dev_groups,
107	},
108};
 
 
 
109module_pci_driver(pvpanic_pci_driver);
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 *  Pvpanic PCI Device Support
  4 *
  5 *  Copyright (C) 2021 Oracle.
  6 */
  7
  8#include <linux/kernel.h>
  9#include <linux/module.h>
 10#include <linux/pci.h>
 11#include <linux/types.h>
 12#include <linux/slab.h>
 13
 14#include <uapi/misc/pvpanic.h>
 15
 16#include "pvpanic.h"
 17
 18#define PCI_VENDOR_ID_REDHAT             0x1b36
 19#define PCI_DEVICE_ID_REDHAT_PVPANIC     0x0011
 20
 21MODULE_AUTHOR("Mihai Carabas <mihai.carabas@oracle.com>");
 22MODULE_DESCRIPTION("pvpanic device driver ");
 23MODULE_LICENSE("GPL");
 24
 25static const struct pci_device_id pvpanic_pci_id_tbl[]  = {
 26	{ PCI_DEVICE(PCI_VENDOR_ID_REDHAT, PCI_DEVICE_ID_REDHAT_PVPANIC)},
 27	{}
 28};
 29
 30static ssize_t capability_show(struct device *dev,
 31			       struct device_attribute *attr, char *buf)
 32{
 33	struct pvpanic_instance *pi = dev_get_drvdata(dev);
 34
 35	return sysfs_emit(buf, "%x\n", pi->capability);
 36}
 37static DEVICE_ATTR_RO(capability);
 38
 39static ssize_t events_show(struct device *dev,  struct device_attribute *attr, char *buf)
 40{
 41	struct pvpanic_instance *pi = dev_get_drvdata(dev);
 42
 43	return sysfs_emit(buf, "%x\n", pi->events);
 44}
 45
 46static ssize_t events_store(struct device *dev,  struct device_attribute *attr,
 47			    const char *buf, size_t count)
 48{
 49	struct pvpanic_instance *pi = dev_get_drvdata(dev);
 50	unsigned int tmp;
 51	int err;
 52
 53	err = kstrtouint(buf, 16, &tmp);
 54	if (err)
 55		return err;
 56
 57	if ((tmp & pi->capability) != tmp)
 58		return -EINVAL;
 59
 60	pi->events = tmp;
 61
 62	return count;
 63}
 64static DEVICE_ATTR_RW(events);
 65
 66static struct attribute *pvpanic_pci_dev_attrs[] = {
 67	&dev_attr_capability.attr,
 68	&dev_attr_events.attr,
 69	NULL
 70};
 71ATTRIBUTE_GROUPS(pvpanic_pci_dev);
 72
 73static int pvpanic_pci_probe(struct pci_dev *pdev,
 74			     const struct pci_device_id *ent)
 75{
 76	struct pvpanic_instance *pi;
 77	void __iomem *base;
 78	int ret;
 79
 80	ret = pcim_enable_device(pdev);
 81	if (ret < 0)
 82		return ret;
 83
 84	base = pcim_iomap(pdev, 0, 0);
 85	if (!base)
 86		return -ENOMEM;
 87
 88	pi = devm_kmalloc(&pdev->dev, sizeof(*pi), GFP_KERNEL);
 89	if (!pi)
 90		return -ENOMEM;
 91
 92	pi->base = base;
 93	pi->capability = PVPANIC_PANICKED | PVPANIC_CRASH_LOADED;
 94
 95	/* initlize capability by RDPT */
 96	pi->capability &= ioread8(base);
 97	pi->events = pi->capability;
 98
 99	return devm_pvpanic_probe(&pdev->dev, pi);
100}
101
 
 
 
 
 
 
102static struct pci_driver pvpanic_pci_driver = {
103	.name =         "pvpanic-pci",
104	.id_table =     pvpanic_pci_id_tbl,
105	.probe =        pvpanic_pci_probe,
106	.driver = {
107		.dev_groups = pvpanic_pci_dev_groups,
108	},
109};
110
111MODULE_DEVICE_TABLE(pci, pvpanic_pci_id_tbl);
112
113module_pci_driver(pvpanic_pci_driver);