2 * This file is part of the coreboot project.
4 * Copyright (C) 2004 Linux Networx
5 * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
6 * Copyright (C) 2009 coresystems GmbH
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <console/console.h>
23 #include <arch/pciconf.h>
24 #include <device/pci.h>
25 #include <device/pci_ids.h>
26 #include <device/pci_ops.h>
28 static struct bus *get_pbus(device_t dev)
30 struct bus *pbus = NULL;
33 die("get_pbus: dev is NULL!\n");
37 while(pbus && pbus->dev && !ops_pci_bus(pbus)) {
38 if (pbus == pbus->dev->bus) {
39 printk_alert("%s in endless loop looking for a parent "
40 "bus with ops_pci_bus for %s, breaking out.\n",
41 __func__, dev_path(dev));
44 pbus = pbus->dev->bus;
46 if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_pci_bus) {
47 printk_emerg("%s: Cannot find pci bus operations.\n", dev_path(dev));
53 uint8_t pci_read_config8(device_t dev, unsigned where)
55 struct bus *pbus = get_pbus(dev);
56 return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
59 uint16_t pci_read_config16(device_t dev, unsigned where)
61 struct bus *pbus = get_pbus(dev);
62 return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
65 uint32_t pci_read_config32(device_t dev, unsigned where)
67 struct bus *pbus = get_pbus(dev);
68 return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
71 void pci_write_config8(device_t dev, unsigned where, uint8_t val)
73 struct bus *pbus = get_pbus(dev);
74 ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
77 void pci_write_config16(device_t dev, unsigned where, uint16_t val)
79 struct bus *pbus = get_pbus(dev);
80 ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
83 void pci_write_config32(device_t dev, unsigned where, uint32_t val)
85 struct bus *pbus = get_pbus(dev);
86 ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
89 #if CONFIG_MMCONF_SUPPORT
90 uint8_t pci_mmio_read_config8(device_t dev, unsigned where)
92 struct bus *pbus = get_pbus(dev);
93 return pci_ops_mmconf.read8(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
96 uint16_t pci_mmio_read_config16(device_t dev, unsigned where)
98 struct bus *pbus = get_pbus(dev);
99 return pci_ops_mmconf.read16(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
102 uint32_t pci_mmio_read_config32(device_t dev, unsigned where)
104 struct bus *pbus = get_pbus(dev);
105 return pci_ops_mmconf.read32(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
108 void pci_mmio_write_config8(device_t dev, unsigned where, uint8_t val)
110 struct bus *pbus = get_pbus(dev);
111 pci_ops_mmconf.write8(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
114 void pci_mmio_write_config16(device_t dev, unsigned where, uint16_t val)
116 struct bus *pbus = get_pbus(dev);
117 pci_ops_mmconf.write16(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
120 void pci_mmio_write_config32(device_t dev, unsigned where, uint32_t val)
122 struct bus *pbus = get_pbus(dev);
123 pci_ops_mmconf.write32(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);