A quick question about the Command register

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all. I've inserted the patch I want to ask about below. It's supposed to be an updated version of the patch that produces sensible errors if people try to read a ROM incorrectly. The problem seems to be with the line that says:

if(! res->flags & IORESOURCE_MEM) {

Now since that line was written by me, it's no doubt wrong. What it's supposed to be testing for is whether the Memory Space bit in the Command register is set, and run the code inside the if statement if it's NOT set. Would you expect the code that I wrote to do that?

I should state that this code is designed to catch the case where a "1" hasn't been echoed into the file called "enable" yet. It is possible that res->flags might not be initialised properly? If that's the case, how do I check for enabled-ness?

	Thanks,


diff -uprN linux-2.6.27/drivers/pci/pci-sysfs.c linux-2.6.27/drivers/pci/pci-sysfs.c
--- linux-2.6.27/drivers/pci/pci-sysfs.c	2008-10-10 09:13:53.000000000 +1100
+++ linux-2.6.27/drivers/pci/pci-sysfs.c	2009-01-13 12:17:13.000000000 +1100
@@ -663,11 +663,19 @@ pci_write_rom(struct kobject *kobj, stru
 	      char *buf, loff_t off, size_t count)
 {
 	struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
+	struct resource *res = &pdev->resource[PCI_ROM_RESOURCE];

 	if ((off ==  0) && (*buf == '0') && (count == 2))
 		pdev->rom_attr_enabled = 0;
-	else
+	else {
 		pdev->rom_attr_enabled = 1;
+		if(! res->flags & IORESOURCE_MEM) {
+			printk(KERN_INFO " %s: suggest echoing 1 into "
+				"/sys/bus/pci/<deviceID>/enable\n", __FUNCTION__);
+			printk(KERN_INFO " %s: to enable device before trying to "
+				"do rom reading\n", __FUNCTION__);
+		}
+	}

 	return count;
 }
@@ -694,8 +702,8 @@ pci_read_rom(struct kobject *kobj, struc
 		return -EINVAL;

 	rom = pci_map_rom(pdev, &size);	/* size starts out as PCI window size */
-	if (!rom)
-		return 0;
+	if (!rom || !size)
+		return -EIO;

 	if (off >= size)
 		count = 0;
diff -uprN linux-2.6.27/drivers/pci/rom.c linux-2.6.27/drivers/pci/rom.c
--- linux-2.6.27/drivers/pci/rom.c	2008-10-10 09:13:53.000000000 +1100
+++ linux-2.6.27/drivers/pci/rom.c	2009-01-13 11:55:06.000000000 +1100
@@ -72,8 +72,10 @@ size_t pci_get_rom_size(void __iomem *ro
 	do {
 		void __iomem *pds;
 		/* Standard PCI ROMs start out with these bytes 55 AA */
-		if (readb(image) != 0x55)
+		if (readb(image) != 0x55) {
+			printk(KERN_INFO " %s: Invalid ROM contents\n", __FUNCTION__);
 			break;
+		}
 		if (readb(image + 1) != 0xAA)
 			break;
 		/* get the PCI data structure and check its signature */


---------------------------------------------------------------------
| Name: Tim Nelson                 | Because the Creator is,        |
| E-mail: wayland@xxxxxxxxxxxxx    | I am                           |
---------------------------------------------------------------------

----BEGIN GEEK CODE BLOCK----
Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y-
-----END GEEK CODE BLOCK-----

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux