linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Add a "enable" sysfs attribute to the pci devices to allow userspace (Xorg) to enable devices without doing foul direct access
@ 2006-04-29  8:46 Arjan van de Ven
  2006-04-29  8:51 ` Andrew Morton
  2006-05-02 16:38 ` Jon Smirl
  0 siblings, 2 replies; 75+ messages in thread
From: Arjan van de Ven @ 2006-04-29  8:46 UTC (permalink / raw)
  To: greg; +Cc: linux-pci, linux-kernel, airlied, pjones, akpm

This patch adds an "enable" sysfs attribute to each PCI device. When read it
shows the "enabled-ness" of the device, but you can write a "0" into it to
disable a device, and a "1" to enable it.

This later is needed for X and other cases where userspace wants to enable
the BARs on a device (typical example: to run the video bios on a secundary
head). Right now X does all this "by hand" via bitbanging, that's just evil.
This allows X to no longer do that but to just let the kernel do this.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
CC: Peter Jones <pjones@redhat.com>
CC: Dave Airlie <airlied@linux.ie>
---
 drivers/pci/pci-sysfs.c |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Index: linux-2.6.17-rc2-enable/drivers/pci/pci-sysfs.c
===================================================================
--- linux-2.6.17-rc2-enable.orig/drivers/pci/pci-sysfs.c
+++ linux-2.6.17-rc2-enable/drivers/pci/pci-sysfs.c
@@ -43,6 +43,7 @@ pci_config_attr(subsystem_vendor, "0x%04
 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 local_cpus_show(struct device *dev,
 			struct device_attribute *attr, char *buf)
@@ -90,6 +91,28 @@ static ssize_t modalias_show(struct devi
 		       (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);
+
+	if (!pdev)
+		return 1;
+
+	/* this can crash the machine when done on the "wrong" device */
+	if (!capable(CAP_SYS_ADMIN))
+		return 1;
+
+	if (*buf == '0')
+		pci_disable_device(pdev);
+
+	if (*buf == '1')
+		pci_enable_device(pdev);
+
+	return 1;
+}
+
 
 struct device_attribute pci_dev_attrs[] = {
 	__ATTR_RO(resource),
@@ -101,6 +124,7 @@ 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_NULL,
 };
 


^ permalink raw reply	[flat|nested] 75+ messages in thread

end of thread, other threads:[~2006-05-15  2:11 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-29  8:46 Add a "enable" sysfs attribute to the pci devices to allow userspace (Xorg) to enable devices without doing foul direct access Arjan van de Ven
2006-04-29  8:51 ` Andrew Morton
2006-04-29  8:59   ` Arjan van de Ven
2006-04-29  9:04     ` Dave Airlie
2006-05-02 16:14       ` Bjorn Helgaas
2006-05-02 16:21         ` Greg KH
2006-05-02 16:51           ` Jesse Barnes
2006-05-04 19:09       ` Bjorn Helgaas
2006-05-04 19:11         ` Arjan van de Ven
2006-05-04 19:26           ` Bjorn Helgaas
2006-05-04 19:42             ` Matthew Garrett
2006-05-04 20:40               ` Jon Smirl
2006-05-04 21:05                 ` Peter Jones
2006-05-04 21:17                   ` Martin Mares
2006-05-04 21:29                     ` Peter Jones
2006-05-04 21:37                       ` Martin Mares
2006-05-04 21:38                       ` Jon Smirl
2006-05-04 23:22                         ` Peter Jones
2006-05-05 19:20                           ` Ian Romanick
2006-05-05 20:14                             ` Jon Smirl
2006-05-05 20:26                               ` Greg KH
2006-05-05 20:35                                 ` Jon Smirl
2006-05-05 20:43                                   ` Jon Smirl
2006-05-05 21:10                                     ` Greg KH
2006-05-05 21:06                                   ` Greg KH
2006-05-05 21:15                                     ` Jon Smirl
2006-05-05 22:27                                       ` Greg KH
2006-05-06  0:05                                         ` Jon Smirl
2006-05-06  1:57                                           ` Dave Airlie
2006-05-06  3:39                                             ` Jon Smirl
2006-05-06 12:42                                               ` Krzysztof Halasa
2006-05-06 13:08                                                 ` Jon Smirl
2006-05-06 18:10                                                   ` Krzysztof Halasa
2006-05-06 18:24                                                     ` Jon Smirl
2006-05-06 23:16                                                       ` Krzysztof Halasa
2006-05-07  5:56                                                         ` Kyle Moffett
2006-05-07 12:05                                                           ` Krzysztof Halasa
2006-05-07 19:07                                                             ` Kyle Moffett
2006-05-08  0:03                                                               ` Krzysztof Halasa
2006-05-07 13:12                                             ` Pavel Machek
2006-05-08 14:26                                               ` Kyle Moffett
2006-05-08 14:54                                                 ` Arjan van de Ven
2006-05-08  4:06                                           ` Dave Airlie
2006-05-08  5:27                                             ` Jon Smirl
2006-05-07  8:54                                 ` Adam Belay
2006-05-14  0:29                       ` Benjamin Herrenschmidt
2006-05-14  0:56                         ` Jon Smirl
2006-05-14 23:57                           ` Benjamin Herrenschmidt
2006-05-15  0:14                             ` Jon Smirl
2006-05-14  0:57                         ` Patrick McFarland
2006-05-14  1:11                           ` Jon Smirl
2006-05-04 21:18                   ` Jon Smirl
2006-05-04 21:38                     ` Peter Jones
2006-05-04 21:48                       ` Jon Smirl
2006-05-04 21:57                         ` Peter Jones
2006-05-04 22:05                           ` Jon Smirl
2006-05-04 19:49             ` Arjan van de Ven
2006-05-15  2:10     ` Eric W. Biederman
2006-05-02 16:38 ` Jon Smirl
2006-05-02 16:45   ` Arjan van de Ven
2006-05-02 16:59     ` Jon Smirl
2006-05-02 17:00       ` Arjan van de Ven
2006-05-02 17:13         ` Jon Smirl
2006-05-02 18:27           ` Arjan van de Ven
2006-05-02 19:00             ` Jon Smirl
2006-05-02 19:29               ` Peter Jones
2006-05-02 21:40               ` Dave Airlie
2006-05-02 21:52                 ` Jon Smirl
2006-05-02 23:36                   ` Dave Airlie
2006-05-03  0:19                   ` Matthew Wilcox
2006-05-03  0:26                     ` Valdis.Kletnieks
2006-05-03  1:24                     ` Jon Smirl
2006-05-03  1:30                       ` Dave Airlie
2006-05-03  6:02                   ` Arjan van de Ven
2006-05-03 13:23                     ` Jon Smirl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).