public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jesse Barnes <jbarnes@engr.sgi.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: Jon Smirl <jonsmirl@yahoo.com>,
	lkml <linux-kernel@vger.kernel.org>,
	linux-pci@atrey.karlin.mff.cuni.cz
Subject: Re: Exposing ROM's though sysfs
Date: Fri, 30 Jul 2004 10:57:12 -0700	[thread overview]
Message-ID: <200407301057.12445.jbarnes@engr.sgi.com> (raw)
In-Reply-To: <20040730182410.A12171@infradead.org>

[-- Attachment #1: Type: text/plain, Size: 926 bytes --]

On Friday, July 30, 2004 10:24 am, Christoph Hellwig wrote:
> On Fri, Jul 30, 2004 at 10:10:29AM -0700, Jesse Barnes wrote:
> > +	unsigned long start = dev->resource[PCI_ROM_RESOURCE].start;
> > +	int size = dev->resource[PCI_ROM_RESOURCE].end -
> > +		dev->resource[PCI_ROM_RESOURCE].start;
>
> pci_resource_start and pci_resource_len please.
>
> > +		.name = "rom",
> > +		.mode = S_IRUGO | S_IWUSR,
>
> do we really want it world readable if a read messes with pci config
> space?
>
> > +	if (pdev->resource[PCI_ROM_RESOURCE].start) {
> > +		pci_rom_attr.size = pdev->resource[PCI_ROM_RESOURCE].end -
> > +			pdev->resource[PCI_ROM_RESOURCE].start;
>
> as above.

Oops, forgot about those macros.  Fixed.  I've also fixed the perms, RO by 
root.

willy brings up a good point though, we may want to disable the rom file 
entirely after its been read, since it can be a source of trouble.  Here's 
the latest patch.

Jesse


[-- Attachment #2: pci-sysfs-rom-2.patch --]
[-- Type: text/plain, Size: 2464 bytes --]

===== drivers/pci/pci-sysfs.c 1.10 vs edited =====
--- 1.10/drivers/pci/pci-sysfs.c	2004-06-04 06:23:04 -07:00
+++ edited/drivers/pci/pci-sysfs.c	2004-07-30 10:54:06 -07:00
@@ -164,6 +164,73 @@
 	return count;
 }
 
+static void
+pci_enable_rom(struct pci_dev *dev)
+{
+	pci_write_config_dword(dev, PCI_ROM_ADDRESS, PCI_ROM_ADDRESS_ENABLE);
+}
+
+static void
+pci_disable_rom(struct pci_dev *dev)
+{
+	pci_write_config_dword(dev, PCI_ROM_ADDRESS, ~PCI_ROM_ADDRESS_ENABLE);
+}
+
+static ssize_t
+pci_read_rom(struct kobject *kobj, char *buf, loff_t off, size_t count)
+{
+	struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
+	loff_t init_off = off;
+	unsigned long start = pci_resource_start(dev, PCI_ROM_RESOURCE);
+	int size = pci_resource_len(dev, PCI_ROM_RESOURCE);
+	u32 l;
+
+	if (off > size)
+		return 0;
+	if (off + count > size) {
+		size -= off;
+		count = size;
+	} else {
+		size = count;
+	}
+
+	/* Enable ROM space decodes and do the reads */
+	pci_enable_rom(dev);
+
+	while (off & 3) {
+		unsigned char val;
+		val = readb(start + off);
+		buf[off - init_off] = val;
+		off++;
+		if (--size == 0)
+			break;
+	}
+
+	while (size > 3) {
+		unsigned int val;
+		val = readl(start + off);
+		buf[off - init_off] = val & 0xff;
+		buf[off - init_off + 1] = (val >> 8) & 0xff;
+		buf[off - init_off + 2] = (val >> 16) & 0xff;
+		buf[off - init_off + 3] = (val >> 24) & 0xff;
+		off += 4;
+		size -= 4;
+	}
+
+	while (size > 0) {
+		unsigned char val;
+		val = readb(start + off);
+		buf[off - init_off] = val;
+		off++;
+		--size;
+	}
+
+	/* Disable again before continuing */
+	pci_disable_rom(dev);
+
+	return count;
+}
+
 static struct bin_attribute pci_config_attr = {
 	.attr =	{
 		.name = "config",
@@ -186,12 +253,27 @@
 	.write = pci_write_config,
 };
 
+static struct bin_attribute pci_rom_attr = {
+	.attr =	{
+		.name = "rom",
+		.mode = S_IRUSR,
+		.owner = THIS_MODULE,
+	},
+	.read = pci_read_rom,
+};
+
 void pci_create_sysfs_dev_files (struct pci_dev *pdev)
 {
 	if (pdev->cfg_size < 4096)
 		sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr);
 	else
 		sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr);
+
+	/* If the device has a ROM, map it */
+	if (pdev->resource[PCI_ROM_RESOURCE].start) {
+		pci_rom_attr.size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
+		sysfs_create_bin_file(&pdev->dev.kobj, &pci_rom_attr);
+	}
 
 	/* add platform-specific attributes */
 	pcibios_add_platform_entries(pdev);

  reply	other threads:[~2004-07-30 18:02 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-30 16:53 Exposing ROM's though sysfs Jon Smirl
2004-07-30 17:10 ` Jesse Barnes
2004-07-30 17:19   ` Jesse Barnes
2004-07-30 17:24   ` Christoph Hellwig
2004-07-30 17:57     ` Jesse Barnes [this message]
2004-07-30 18:06       ` Jesse Barnes
2004-07-30 18:12       ` Matthew Wilcox
2004-07-30 18:12         ` Jesse Barnes
2004-07-30 18:20           ` Martin Mares
2004-07-30 18:49           ` Jesse Barnes
2004-07-30 19:55             ` Greg KH
2004-07-30 20:05               ` Jon Smirl
2004-07-30 20:16               ` Jesse Barnes
2004-07-30 20:29                 ` Greg KH
2004-07-30 18:59         ` Jon Smirl
2004-07-30 19:04           ` Matthew Wilcox
2004-07-30 19:30             ` Jon Smirl
2004-07-30 19:35               ` Martin Mares
2004-07-30 19:39                 ` Jon Smirl
2004-07-30 19:46                   ` Martin Mares
2004-07-30 20:03                     ` Jon Smirl
2004-07-30 20:10                       ` Martin Mares
2004-07-30 20:13                         ` Martin Mares
2004-07-30 20:25                           ` Jesse Barnes
2004-07-30 20:32                         ` Jon Smirl
2004-07-30 20:41                           ` Martin Mares
2004-07-30 20:49                             ` Jesse Barnes
2004-07-30 20:54                               ` Martin Mares
2004-07-30 21:00                                 ` Jesse Barnes
2004-07-30 21:07                               ` Jon Smirl
2004-07-30 21:12                                 ` Jesse Barnes
2004-07-30 19:47               ` Vojtech Pavlik
2004-07-30 22:18             ` Thomas Bogendoerfer
2004-07-30 22:39         ` Alan Cox
2004-07-30 19:25   ` Jon Smirl
2004-07-30 19:35     ` Vojtech Pavlik
2004-07-30 19:41       ` Jon Smirl
2004-07-30 19:48         ` Vojtech Pavlik
2004-07-30 20:20           ` Jesse Barnes
2004-07-30 22:41             ` Alan Cox
     [not found] <1091207136.2762.181.camel@rohan.arnor.net>
2004-07-30 17:24 ` Jon Smirl
2004-07-30 19:14   ` Vojtech Pavlik
2004-07-30 20:26     ` Jesse Barnes
2004-07-30 22:36       ` Alan Cox
2004-08-03 21:41         ` Benjamin Herrenschmidt
2004-08-04  0:55           ` Jesse Barnes
2004-08-04  0:59             ` Benjamin Herrenschmidt
2004-08-04  1:37               ` Jon Smirl
2004-08-04  1:57                 ` Benjamin Herrenschmidt
2004-08-04  2:16                   ` Jesse Barnes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200407301057.12445.jbarnes@engr.sgi.com \
    --to=jbarnes@engr.sgi.com \
    --cc=hch@infradead.org \
    --cc=jonsmirl@yahoo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@atrey.karlin.mff.cuni.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox