summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
authorEric Biederman <ebiederm@xmission.com>2003-06-12 19:23:51 +0000
committerEric Biederman <ebiederm@xmission.com>2003-06-12 19:23:51 +0000
commit7a5416af9574095c6df28fb8192fe4c063afa8da (patch)
tree66cc3bb27f8319255ebab48ba774d584693d4c22 /src/arch
parent540ae01cd341de75f5eb57906699ca24667d71cc (diff)
downloadcoreboot-7a5416af9574095c6df28fb8192fe4c063afa8da.tar.xz
- Modify the freebios tree so the pci config space api is mostly in sync between
code that runs without ram and code that runs with ram. git-svn-id: svn://svn.coreboot.org/coreboot/trunk@869 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/i386/include/arch/romcc_io.h51
-rw-r--r--src/arch/i386/lib/pci_ops.c163
2 files changed, 79 insertions, 135 deletions
diff --git a/src/arch/i386/include/arch/romcc_io.h b/src/arch/i386/include/arch/romcc_io.h
index 677133f2a9..7d3d50e39c 100644
--- a/src/arch/i386/include/arch/romcc_io.h
+++ b/src/arch/i386/include/arch/romcc_io.h
@@ -61,56 +61,6 @@ static void wrmsr(unsigned long index, msr_t msr)
#define PCI_ID(VENDOR_ID, DEVICE_ID) \
((((DEVICE_ID) & 0xFFFF) << 16) | ((VENDOR_ID) & 0xFFFF))
-#if 0
-static unsigned char pci_read_config8(unsigned addr)
-{
- outl(0x80000000 | (addr & ~3), 0xCF8);
- return inb(0xCFC + (addr & 3));
-}
-
-static unsigned short pci_read_config16(unsigned addr)
-{
- outl(0x80000000 | (addr & ~3), 0xCF8);
- return inw(0xCFC + (addr & 2));
-}
-
-static unsigned int pci_read_config32(unsigned addr)
-{
- outl(0x80000000 | (addr & ~3), 0xCF8);
- return inl(0xCFC);
-}
-
-static void pci_write_config8(unsigned addr, unsigned char value)
-{
- outl(0x80000000 | (addr & ~3), 0xCF8);
- outb(value, 0xCFC + (addr & 3));
-}
-
-static void pci_write_config16(unsigned addr, unsigned short value)
-{
- outl(0x80000000 | (addr & ~3), 0xCF8);
- outw(value, 0xCFC + (addr & 2));
-}
-
-static void pci_write_config32(unsigned addr, unsigned int value)
-{
- outl(0x80000000 | (addr & ~3), 0xCF8);
- outl(value, 0xCFC);
-}
-
-static unsigned pci_locate_device(unsigned pci_id, unsigned addr)
-{
- addr &= ~0xff;
- for(; addr <= PCI_ADDR(255, 31, 7, 0); addr += PCI_ADDR(0,0,1,0)) {
- unsigned int id;
- id = pci_read_config32(addr);
- if (id == pci_id) {
- return addr;
- }
- }
- return ~0U;
-}
-#else
typedef unsigned device_t;
static unsigned char pci_read_config8(device_t dev, unsigned where)
@@ -174,4 +124,3 @@ static device_t pci_locate_device(unsigned pci_id, device_t dev)
return PCI_DEV_INVALID;
}
-#endif
diff --git a/src/arch/i386/lib/pci_ops.c b/src/arch/i386/lib/pci_ops.c
index 7ea40ba738..6924efdc0c 100644
--- a/src/arch/i386/lib/pci_ops.c
+++ b/src/arch/i386/lib/pci_ops.c
@@ -7,12 +7,12 @@
static const struct pci_ops *conf;
struct pci_ops {
- int (*read_byte) (uint8_t bus, int devfn, int where, uint8_t * val);
- int (*read_word) (uint8_t bus, int devfn, int where, uint16_t * val);
- int (*read_dword) (uint8_t bus, int devfn, int where, uint32_t * val);
- int (*write_byte) (uint8_t bus, int devfn, int where, uint8_t val);
- int (*write_word) (uint8_t bus, int devfn, int where, uint16_t val);
- int (*write_dword) (uint8_t bus, int devfn, int where, uint32_t val);
+ uint8_t (*read8) (uint8_t bus, int devfn, int where);
+ uint16_t (*read16) (uint8_t bus, int devfn, int where);
+ uint32_t (*read32) (uint8_t bus, int devfn, int where);
+ void (*write8) (uint8_t bus, int devfn, int where, uint8_t val);
+ void (*write16) (uint8_t bus, int devfn, int where, uint16_t val);
+ void (*write32) (uint8_t bus, int devfn, int where, uint32_t val);
};
/*
@@ -26,58 +26,52 @@ struct pci_ops {
#define CONFIG_CMD(bus,devfn, where) (0x80000000 | (bus << 16) | (devfn << 8) | (where & ~3))
-static int pci_conf1_read_config_byte(unsigned char bus, int devfn, int where, uint8_t * value)
+static uint8_t pci_conf1_read_config8(unsigned char bus, int devfn, int where)
{
outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
- *value = inb(0xCFC + (where & 3));
- return 0;
+ return inb(0xCFC + (where & 3));
}
-static int pci_conf1_read_config_word(unsigned char bus, int devfn, int where, uint16_t * value)
+static uint16_t pci_conf1_read_config16(unsigned char bus, int devfn, int where)
{
outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
- *value = inw(0xCFC + (where & 2));
- return 0;
+ return inw(0xCFC + (where & 2));
}
-static int pci_conf1_read_config_dword(unsigned char bus, int devfn, int where, uint32_t * value)
+static uint32_t pci_conf1_read_config32(unsigned char bus, int devfn, int where)
{
outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
- *value = inl(0xCFC);
- return 0;
+ return inl(0xCFC);
}
-static int pci_conf1_write_config_byte(unsigned char bus, int devfn, int where, uint8_t value)
+static void pci_conf1_write_config8(unsigned char bus, int devfn, int where, uint8_t value)
{
outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
outb(value, 0xCFC + (where & 3));
- return 0;
}
-static int pci_conf1_write_config_word(unsigned char bus, int devfn, int where, uint16_t value)
+static void pci_conf1_write_config16(unsigned char bus, int devfn, int where, uint16_t value)
{
outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
outw(value, 0xCFC + (where & 2));
- return 0;
}
-static int pci_conf1_write_config_dword(unsigned char bus, int devfn, int where, uint32_t value)
+static void pci_conf1_write_config32(unsigned char bus, int devfn, int where, uint32_t value)
{
outl(CONFIG_CMD(bus, devfn, where), 0xCF8);
outl(value, 0xCFC);
- return 0;
}
#undef CONFIG_CMD
static const struct pci_ops pci_direct_conf1 =
{
- pci_conf1_read_config_byte,
- pci_conf1_read_config_word,
- pci_conf1_read_config_dword,
- pci_conf1_write_config_byte,
- pci_conf1_write_config_word,
- pci_conf1_write_config_dword
+ .read8 = pci_conf1_read_config8,
+ .read16 = pci_conf1_read_config16,
+ .read32 = pci_conf1_read_config32,
+ .write8 = pci_conf1_write_config8,
+ .write16 = pci_conf1_write_config16,
+ .write32 = pci_conf1_write_config32,
};
/*
@@ -86,54 +80,54 @@ static const struct pci_ops pci_direct_conf1 =
#define IOADDR(devfn, where) ((0xC000 | ((devfn & 0x78) << 5)) + where)
#define FUNC(devfn) (((devfn & 7) << 1) | 0xf0)
-#define SET(bus,devfn) if (devfn & 0x80) return -1;outb(FUNC(devfn), 0xCF8); outb(bus, 0xCFA);
+#define SET(bus,devfn) outb(FUNC(devfn), 0xCF8); outb(bus, 0xCFA);
-static int pci_conf2_read_config_byte(unsigned char bus, int devfn, int where, uint8_t * value)
+static uint8_t pci_conf2_read_config8(unsigned char bus, int devfn, int where)
{
+ uint8_t value;
SET(bus, devfn);
- *value = inb(IOADDR(devfn, where));
+ value = inb(IOADDR(devfn, where));
outb(0, 0xCF8);
- return 0;
+ return value;
}
-static int pci_conf2_read_config_word(unsigned char bus, int devfn, int where, uint16_t * value)
+static uint16_t pci_conf2_read_config16(unsigned char bus, int devfn, int where)
{
+ uint16_t value;
SET(bus, devfn);
- *value = inw(IOADDR(devfn, where));
+ value = inw(IOADDR(devfn, where));
outb(0, 0xCF8);
- return 0;
+ return value;
}
-static int pci_conf2_read_config_dword(unsigned char bus, int devfn, int where, uint32_t * value)
+static uint32_t pci_conf2_read_config32(unsigned char bus, int devfn, int where)
{
+ uint32_t value;
SET(bus, devfn);
- *value = inl(IOADDR(devfn, where));
+ value = inl(IOADDR(devfn, where));
outb(0, 0xCF8);
- return 0;
+ return value;
}
-static int pci_conf2_write_config_byte(unsigned char bus, int devfn, int where, uint8_t value)
+static void pci_conf2_write_config8(unsigned char bus, int devfn, int where, uint8_t value)
{
SET(bus, devfn);
outb(value, IOADDR(devfn, where));
outb(0, 0xCF8);
- return 0;
}
-static int pci_conf2_write_config_word(unsigned char bus, int devfn, int where, uint16_t value)
+static void pci_conf2_write_config16(unsigned char bus, int devfn, int where, uint16_t value)
{
SET(bus, devfn);
outw(value, IOADDR(devfn, where));
outb(0, 0xCF8);
- return 0;
}
-static int pci_conf2_write_config_dword(unsigned char bus, int devfn, int where, uint32_t value)
+static void pci_conf2_write_config32(unsigned char bus, int devfn, int where, uint32_t value)
{
SET(bus, devfn);
outl(value, IOADDR(devfn, where));
outb(0, 0xCF8);
- return 0;
}
#undef SET
@@ -142,12 +136,12 @@ static int pci_conf2_write_config_dword(unsigned char bus, int devfn, int where,
static const struct pci_ops pci_direct_conf2 =
{
- pci_conf2_read_config_byte,
- pci_conf2_read_config_word,
- pci_conf2_read_config_dword,
- pci_conf2_write_config_byte,
- pci_conf2_write_config_word,
- pci_conf2_write_config_dword
+ .read8 = pci_conf2_read_config8,
+ .read16 = pci_conf2_read_config16,
+ .read32 = pci_conf2_read_config32,
+ .write8 = pci_conf2_write_config8,
+ .write16 = pci_conf2_write_config16,
+ .write32 = pci_conf2_write_config32,
};
/*
@@ -162,7 +156,7 @@ static const struct pci_ops pci_direct_conf2 =
*/
static int pci_sanity_check(const struct pci_ops *o)
{
- uint16_t x;
+ uint16_t class, vendor;
uint8_t bus;
int devfn;
#define PCI_CLASS_BRIDGE_HOST 0x0600
@@ -171,12 +165,15 @@ static int pci_sanity_check(const struct pci_ops *o)
#define PCI_VENDOR_ID_INTEL 0x8086
#define PCI_VENDOR_ID_MOTOROLA 0x1057
- for (bus = 0, devfn = 0; devfn < 0x100; devfn++)
- if ((!o->read_word(bus, devfn, PCI_CLASS_DEVICE, &x) &&
- (x == PCI_CLASS_BRIDGE_HOST || x == PCI_CLASS_DISPLAY_VGA)) ||
- (!o->read_word(bus, devfn, PCI_VENDOR_ID, &x) &&
- (x == PCI_VENDOR_ID_INTEL || x == PCI_VENDOR_ID_COMPAQ || x == PCI_VENDOR_ID_MOTOROLA)))
+ for (bus = 0, devfn = 0; devfn < 0x100; devfn++) {
+ class = o->read16(bus, devfn, PCI_CLASS_DEVICE);
+ vendor = o->read16(bus, devfn, PCI_VENDOR_ID);
+ if (((class == PCI_CLASS_BRIDGE_HOST) || (class == PCI_CLASS_DISPLAY_VGA)) ||
+ ((vendor == PCI_VENDOR_ID_INTEL) || (vendor == PCI_VENDOR_ID_COMPAQ) ||
+ (vendor == PCI_VENDOR_ID_MOTOROLA))) {
return 1;
+ }
+ }
printk_err("PCI: Sanity check failed\n");
return 0;
}
@@ -220,54 +217,52 @@ static const struct pci_ops *pci_check_direct(void)
return 0;
}
-int pci_read_config_byte(struct device *dev, uint8_t where, uint8_t * val)
+uint8_t pci_read_config8(device_t dev, unsigned where)
{
- int res;
- res = conf->read_byte(dev->bus->secondary, dev->devfn, where, val);
- printk_spew("Read config byte bus %d,devfn 0x%x,reg 0x%x,val 0x%x,res 0x%x\n",
- dev->bus->secondary, dev->devfn, where, *val, res);
- return res;
-
-
+ uint8_t value;
+ value = conf->read8(dev->bus->secondary, dev->devfn, where);
+ printk_spew("Read config 8 bus %d,devfn 0x%x,reg 0x%x,val 0x%x\n",
+ dev->bus->secondary, dev->devfn, where, value);
+ return value;
}
-int pci_read_config_word(struct device *dev, uint8_t where, uint16_t * val)
+uint16_t pci_read_config16(device_t dev, unsigned where)
{
- int res;
- res = conf->read_word(dev->bus->secondary, dev->devfn, where, val);
- printk_spew( "Read config word bus %d,devfn 0x%x,reg 0x%x,val 0x%x,res 0x%x\n",
- dev->bus->secondary, dev->devfn, where, *val, res);
- return res;
+ uint16_t value;
+ value = conf->read16(dev->bus->secondary, dev->devfn, where);
+ printk_spew( "Read config 16 bus %d,devfn 0x%x,reg 0x%x,val 0x%x\n",
+ dev->bus->secondary, dev->devfn, where, value);
+ return value;
}
-int pci_read_config_dword(struct device *dev, uint8_t where, uint32_t * val)
+uint32_t pci_read_config32(device_t dev, unsigned where)
{
- int res;
- res = conf->read_dword(dev->bus->secondary, dev->devfn, where, val);
- printk_spew( "Read config dword bus %d,devfn 0x%x,reg 0x%x,val 0x%x,res 0x%x\n",
- dev->bus->secondary, dev->devfn, where, *val, res);
- return res;
+ uint32_t value;
+ value = conf->read32(dev->bus->secondary, dev->devfn, where);
+ printk_spew( "Read config 32 bus %d,devfn 0x%x,reg 0x%x,val 0x%x\n",
+ dev->bus->secondary, dev->devfn, where, *val);
+ return value;
}
-int pci_write_config_byte(struct device *dev, uint8_t where, uint8_t val)
+void pci_write_config8(device_t dev, unsigned where, uint8_t val)
{
- printk_spew( "Write config byte bus %d, devfn 0x%x, reg 0x%x, val 0x%x\n",
+ printk_spew( "Write config 8 bus %d, devfn 0x%x, reg 0x%x, val 0x%x\n",
dev->bus->secondary, dev->devfn, where, val);
- return conf->write_byte(dev->bus->secondary, dev->devfn, where, val);
+ conf->write8(dev->bus->secondary, dev->devfn, where, val);
}
-int pci_write_config_word(struct device *dev, uint8_t where, uint16_t val)
+void pci_write_config16(device_t dev, unsigned where, uint16_t val)
{
- printk_spew( "Write config word bus %d, devfn 0x%x, reg 0x%x, val 0x%x\n",
+ printk_spew( "Write config 16 bus %d, devfn 0x%x, reg 0x%x, val 0x%x\n",
dev->bus->secondary, dev->devfn, where, val);
- return conf->write_word(dev->bus->secondary, dev->devfn, where, val);
+ conf->write16(dev->bus->secondary, dev->devfn, where, val);
}
-int pci_write_config_dword(struct device *dev, uint8_t where, uint32_t val)
+void pci_write_config32(device_t dev, unsigned where, uint32_t val)
{
- printk_spew( "Write config dword bus %d, devfn 0x%x, reg 0x%x, val 0x%x\n",
+ printk_spew( "Write config 32 bus %d, devfn 0x%x, reg 0x%x, val 0x%x\n",
dev->bus->secondary, dev->devfn, where, val);
- return conf->write_dword(dev->bus->secondary, dev->devfn, where, val);
+ conf->write32(dev->bus->secondary, dev->devfn, where, val);
}
/** Set the method to be used for PCI, type I or type II