|
|
7a902c |
diff --git a/src/linux_sysfs.c b/src/linux_sysfs.c
|
|
|
7a902c |
index 8c3cf67..2ea78c1 100644
|
|
|
7a902c |
--- a/src/linux_sysfs.c
|
|
|
7a902c |
+++ b/src/linux_sysfs.c
|
|
|
7a902c |
@@ -227,6 +227,7 @@ pci_device_linux_sysfs_probe( struct pci_device * dev )
|
|
|
7a902c |
pciaddr_t bytes;
|
|
|
7a902c |
unsigned i;
|
|
|
7a902c |
int err;
|
|
|
7a902c |
+ struct stat st;
|
|
|
7a902c |
|
|
|
7a902c |
|
|
|
7a902c |
err = pci_device_linux_sysfs_read( dev, config, 0, 256, & bytes );
|
|
|
7a902c |
@@ -293,11 +294,28 @@ pci_device_linux_sysfs_probe( struct pci_device * dev )
|
|
|
7a902c |
flags = strtoull( next, & next, 16 );
|
|
|
7a902c |
if ( low_addr != 0 ) {
|
|
|
7a902c |
priv->rom_base = low_addr;
|
|
|
7a902c |
- dev->rom_size = (high_addr - low_addr) + 1;
|
|
|
7a902c |
}
|
|
|
7a902c |
}
|
|
|
7a902c |
}
|
|
|
7a902c |
|
|
|
7a902c |
+ snprintf( name, 255, "%s/%04x:%02x:%02x.%1u/rom",
|
|
|
7a902c |
+ SYS_BUS_PCI,
|
|
|
7a902c |
+ dev->domain,
|
|
|
7a902c |
+ dev->bus,
|
|
|
7a902c |
+ dev->dev,
|
|
|
7a902c |
+ dev->func );
|
|
|
7a902c |
+
|
|
|
7a902c |
+ fd = open( name, O_RDWR );
|
|
|
7a902c |
+ if ( fd == -1 ) {
|
|
|
7a902c |
+ dev->rom_size = 0x10000;
|
|
|
7a902c |
+ } else if ( fstat( fd, & st ) == -1 ) {
|
|
|
7a902c |
+ close( fd );
|
|
|
7a902c |
+ dev->rom_size = 0x10000;
|
|
|
7a902c |
+ } else {
|
|
|
7a902c |
+ close( fd );
|
|
|
7a902c |
+ dev->rom_size = st.st_size == 0 ? 0x10000 : st.st_size;
|
|
|
7a902c |
+ }
|
|
|
7a902c |
+
|
|
|
7a902c |
return err;
|
|
|
7a902c |
}
|
|
|
7a902c |
|
|
|
7a902c |
@@ -309,7 +327,6 @@ pci_device_linux_sysfs_read_rom( struct pci_device * dev, void * buffer )
|
|
|
7a902c |
int fd;
|
|
|
7a902c |
struct stat st;
|
|
|
7a902c |
int err = 0;
|
|
|
7a902c |
- size_t rom_size;
|
|
|
7a902c |
size_t total_bytes;
|
|
|
7a902c |
|
|
|
7a902c |
|
|
|
7a902c |
@@ -334,10 +351,6 @@ pci_device_linux_sysfs_read_rom( struct pci_device * dev, void * buffer )
|
|
|
7a902c |
return errno;
|
|
|
7a902c |
}
|
|
|
7a902c |
|
|
|
7a902c |
- rom_size = st.st_size;
|
|
|
7a902c |
- if ( rom_size == 0 )
|
|
|
7a902c |
- rom_size = 0x10000;
|
|
|
7a902c |
-
|
|
|
7a902c |
/* This is a quirky thing on Linux. Even though the ROM and the file
|
|
|
7a902c |
* for the ROM in sysfs are read-only, the string "1" must be written to
|
|
|
7a902c |
* the file to enable the ROM. After the data has been read, "0" must be
|
|
|
7a902c |
@@ -346,9 +359,9 @@ pci_device_linux_sysfs_read_rom( struct pci_device * dev, void * buffer )
|
|
|
7a902c |
write( fd, "1", 1 );
|
|
|
7a902c |
lseek( fd, 0, SEEK_SET );
|
|
|
7a902c |
|
|
|
7a902c |
- for ( total_bytes = 0 ; total_bytes < rom_size ; /* empty */ ) {
|
|
|
7a902c |
+ for ( total_bytes = 0 ; total_bytes < dev->rom_size ; /* empty */ ) {
|
|
|
7a902c |
const int bytes = read( fd, (char *) buffer + total_bytes,
|
|
|
7a902c |
- rom_size - total_bytes );
|
|
|
7a902c |
+ dev->rom_size - total_bytes );
|
|
|
7a902c |
if ( bytes == -1 ) {
|
|
|
7a902c |
err = errno;
|
|
|
7a902c |
break;
|