Jon Smirl
2003-08-19 20:00:25 UTC
I needed to enable a PCI ROM and read a few things
from it, and then disable it again. It might be worth
adding a standard PCI API in 2.6 for this.
Here's the code I used...
static void * __init aty128_map_ROM(struct pci_dev
*dev, const struct aty128fb_par
*par)
{
void *rom;
struct resource *r =
&dev->resource[PCI_ROM_RESOURCE];
/* assign address if it doesn't have one */
if (r->start == 0)
pci_assign_resource(dev,
PCI_ROM_RESOURCE);
/* enable if needed */
if (!(r->flags & PCI_ROM_ADDRESS_ENABLE)) {
pci_write_config_dword(dev,
dev->rom_base_reg, r->start |
PCI_ROM_ADDRESS_ENABLE);
r->flags |= PCI_ROM_ADDRESS_ENABLE;
}
rom = ioremap(r->start, r->end - r->start + 1);
if (!rom) {
printk(KERN_ERR "aty128fb: ROM failed to map\n");
return NULL;
}
/* Very simple test to make sure it appeared */
if (readb(rom) != 0x55) {
printk(KERN_ERR "aty128fb: Invalid ROM
signature %x should be 0x55\n",
readb(rom));
aty128_unmap_ROM(dev, rom);
return NULL;
}
return rom;
}
static void __init aty128_unmap_ROM(struct pci_dev
*dev,
void * rom)
{
/* leave it disabled and unassigned */
struct resource *r =
&dev->resource[PCI_ROM_RESOURCE];
iounmap(rom);
r->flags &= ~PCI_ROM_ADDRESS_ENABLE;
r->end -= r->start;
r->start = 0;
/* This will disable and set address to unassigned
*/
pci_write_config_dword(dev, dev->rom_base_reg, 0);
release_resource(r);
}
=====
Jon Smirl
***@yahoo.com
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
from it, and then disable it again. It might be worth
adding a standard PCI API in 2.6 for this.
Here's the code I used...
static void * __init aty128_map_ROM(struct pci_dev
*dev, const struct aty128fb_par
*par)
{
void *rom;
struct resource *r =
&dev->resource[PCI_ROM_RESOURCE];
/* assign address if it doesn't have one */
if (r->start == 0)
pci_assign_resource(dev,
PCI_ROM_RESOURCE);
/* enable if needed */
if (!(r->flags & PCI_ROM_ADDRESS_ENABLE)) {
pci_write_config_dword(dev,
dev->rom_base_reg, r->start |
PCI_ROM_ADDRESS_ENABLE);
r->flags |= PCI_ROM_ADDRESS_ENABLE;
}
rom = ioremap(r->start, r->end - r->start + 1);
if (!rom) {
printk(KERN_ERR "aty128fb: ROM failed to map\n");
return NULL;
}
/* Very simple test to make sure it appeared */
if (readb(rom) != 0x55) {
printk(KERN_ERR "aty128fb: Invalid ROM
signature %x should be 0x55\n",
readb(rom));
aty128_unmap_ROM(dev, rom);
return NULL;
}
return rom;
}
static void __init aty128_unmap_ROM(struct pci_dev
*dev,
void * rom)
{
/* leave it disabled and unassigned */
struct resource *r =
&dev->resource[PCI_ROM_RESOURCE];
iounmap(rom);
r->flags &= ~PCI_ROM_ADDRESS_ENABLE;
r->end -= r->start;
r->start = 0;
/* This will disable and set address to unassigned
*/
pci_write_config_dword(dev, dev->rom_base_reg, 0);
release_resource(r);
}
=====
Jon Smirl
***@yahoo.com
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/