]> err.no Git - linux-2.6/blobdiff - drivers/pci/pci-sysfs.c
[PATCH] 8139cp: add ethtool eeprom support
[linux-2.6] / drivers / pci / pci-sysfs.c
index 965a5934623a30b19740308c7d31a5bd954bd322..bc405c035ce34b4ae00d54a61286782e31416125 100644 (file)
@@ -43,6 +43,29 @@ pci_config_attr(subsystem_vendor, "0x%04x\n");
 pci_config_attr(subsystem_device, "0x%04x\n");
 pci_config_attr(class, "0x%06x\n");
 pci_config_attr(irq, "%u\n");
+pci_config_attr(is_enabled, "%u\n");
+
+static ssize_t broken_parity_status_show(struct device *dev,
+                                        struct device_attribute *attr,
+                                        char *buf)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       return sprintf (buf, "%u\n", pdev->broken_parity_status);
+}
+
+static ssize_t broken_parity_status_store(struct device *dev,
+                                         struct device_attribute *attr,
+                                         const char *buf, size_t count)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       ssize_t consumed = -EINVAL;
+
+       if ((count > 0) && (*buf == '0' || *buf == '1')) {
+               pdev->broken_parity_status = *buf == '1' ? 1 : 0;
+               consumed = count;
+       }
+       return consumed;
+}
 
 static ssize_t local_cpus_show(struct device *dev,
                        struct device_attribute *attr, char *buf)
@@ -90,6 +113,25 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
                       (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8),
                       (u8)(pci_dev->class));
 }
+static ssize_t
+is_enabled_store(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+
+       /* this can crash the machine when done on the "wrong" device */
+       if (!capable(CAP_SYS_ADMIN))
+               return count;
+
+       if (*buf == '0')
+               pci_disable_device(pdev);
+
+       if (*buf == '1')
+               pci_enable_device(pdev);
+
+       return count;
+}
+
 
 struct device_attribute pci_dev_attrs[] = {
        __ATTR_RO(resource),
@@ -101,6 +143,9 @@ struct device_attribute pci_dev_attrs[] = {
        __ATTR_RO(irq),
        __ATTR_RO(local_cpus),
        __ATTR_RO(modalias),
+       __ATTR(enable, 0600, is_enabled_show, is_enabled_store),
+       __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
+               broken_parity_status_show,broken_parity_status_store),
        __ATTR_NULL,
 };
 
@@ -501,9 +546,8 @@ int pci_create_sysfs_dev_files (struct pci_dev *pdev)
        if (pci_resource_len(pdev, PCI_ROM_RESOURCE)) {
                struct bin_attribute *rom_attr;
                
-               rom_attr = kmalloc(sizeof(*rom_attr), GFP_ATOMIC);
+               rom_attr = kzalloc(sizeof(*rom_attr), GFP_ATOMIC);
                if (rom_attr) {
-                       memset(rom_attr, 0x00, sizeof(*rom_attr));
                        pdev->rom_attr = rom_attr;
                        rom_attr->size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
                        rom_attr->attr.name = "rom";