Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SPDX-License-Identifier: GPL-2.0
- /*
- * Firmware security data kernel module
- *
- * Copyright (C) 2020 Daniel Gutson <[email protected]>
- * Copyright (C) 2020 Eclypsium Inc.
- */
- #include <linux/kobject.h>
- #include <linux/sysfs.h>
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/list.h>
- #include <linux/slab.h>
- #include <linux/device.h>
- #include <linux/pci.h>
- static ssize_t howareyou_show(struct class *class, struct class_attribute *attr,
- char *buf)
- {
- return sprintf(buf, "%s\n", "How are you?");
- }
- static CLASS_ATTR_RO(howareyou);
- static struct class my_class = {
- .name = "my-class",
- .owner = THIS_MODULE,
- };
- struct device* child_device;
- static int mypci_probe(struct pci_dev *pdev,
- const struct pci_device_id *id)
- {
- int ret;
- ret = pcim_enable_device(pdev);
- if (ret)
- return ret;
- ret = class_register(&my_class);
- if (ret < 0)
- return ret;
- pr_info("DFG: Recognized. DID: %lx\n", (unsigned long int)id->driver_data);
- pr_info("DFG: device DID: %lx\n", (unsigned long int)pdev->device);
- ret = class_create_file(&my_class, &class_attr_howareyou);
- if (ret != 0)
- {
- pr_err("DFG class create file error: %d\n", ret);
- class_unregister(&my_class);
- return ret;
- }
- child_device = device_create(&my_class, &pdev->dev, MKDEV(0, 0), NULL, "child");
- if (child_device == NULL)
- {
- pr_err("DFG error child device NULL");
- }
- return ret;
- }
- static void mypci_remove(struct pci_dev *pdev)
- {
- /* I tried enabling and disabling this
- if (child_device != NULL)
- {
- put_device(child_device);
- device_unregister(child_device);
- }
- */
- class_remove_file(&my_class, &class_attr_howareyou);
- class_unregister(&my_class);
- }
- static const struct pci_device_id my_dids[] = {
- { PCI_VDEVICE(INTEL, 0xa30e), (unsigned long)0xa30e },
- { PCI_VDEVICE(INTEL, 0xa324), (unsigned long)0xa324 },
- { },
- };
- MODULE_DEVICE_TABLE(pci, my_dids);
- static struct pci_driver my_pci_driver = {
- .name = "dfg-pci",
- .id_table = my_dids,
- .probe = mypci_probe,
- .remove = mypci_remove,
- };
- module_pci_driver(my_pci_driver);
- MODULE_LICENSE("GPL v2");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement