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>
29 * The only consumer of the return value of get_pbus() is ops_pci_bus().
30 * ops_pci_bus() can handle being passed NULL and auto-picks working ops.
32 static struct bus *get_pbus(device_t dev)
34 struct bus *pbus = NULL;
37 die("get_pbus: dev is NULL!\n");
41 while (pbus && pbus->dev && !ops_pci_bus(pbus)) {
42 if (pbus == pbus->dev->bus) {
43 printk(BIOS_ALERT, "%s in endless loop looking for a "
44 "parent bus with ops_pci_bus for %s, breaking "
45 "out.\n", __func__, dev_path(dev));
48 pbus = pbus->dev->bus;
51 if (!pbus || !pbus->dev || !pbus->dev->ops
52 || !pbus->dev->ops->ops_pci_bus) {
53 /* This can happen before the device tree is fully set up. */
55 // printk(BIOS_EMERG, "%s: Cannot find PCI bus operations.\n",
64 u8 pci_read_config8(device_t dev, unsigned int where)
66 struct bus *pbus = get_pbus(dev);
67 return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary,
68 dev->path.pci.devfn, where);
71 u16 pci_read_config16(device_t dev, unsigned int where)
73 struct bus *pbus = get_pbus(dev);
74 return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary,
75 dev->path.pci.devfn, where);
78 u32 pci_read_config32(device_t dev, unsigned int where)
80 struct bus *pbus = get_pbus(dev);
81 return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary,
82 dev->path.pci.devfn, where);
85 void pci_write_config8(device_t dev, unsigned int where, u8 val)
87 struct bus *pbus = get_pbus(dev);
88 ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary,
89 dev->path.pci.devfn, where, val);
92 void pci_write_config16(device_t dev, unsigned int where, u16 val)
94 struct bus *pbus = get_pbus(dev);
95 ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary,
96 dev->path.pci.devfn, where, val);
99 void pci_write_config32(device_t dev, unsigned int where, u32 val)
101 struct bus *pbus = get_pbus(dev);
102 ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary,
103 dev->path.pci.devfn, where, val);
106 #if CONFIG_MMCONF_SUPPORT
107 u8 pci_mmio_read_config8(device_t dev, unsigned int where)
109 struct bus *pbus = get_pbus(dev);
110 return pci_ops_mmconf.read8(pbus, dev->bus->secondary,
111 dev->path.pci.devfn, where);
114 u16 pci_mmio_read_config16(device_t dev, unsigned int where)
116 struct bus *pbus = get_pbus(dev);
117 return pci_ops_mmconf.read16(pbus, dev->bus->secondary,
118 dev->path.pci.devfn, where);
121 u32 pci_mmio_read_config32(device_t dev, unsigned int where)
123 struct bus *pbus = get_pbus(dev);
124 return pci_ops_mmconf.read32(pbus, dev->bus->secondary,
125 dev->path.pci.devfn, where);
128 void pci_mmio_write_config8(device_t dev, unsigned int where, u8 val)
130 struct bus *pbus = get_pbus(dev);
131 pci_ops_mmconf.write8(pbus, dev->bus->secondary, dev->path.pci.devfn,
135 void pci_mmio_write_config16(device_t dev, unsigned int where, u16 val)
137 struct bus *pbus = get_pbus(dev);
138 pci_ops_mmconf.write16(pbus, dev->bus->secondary, dev->path.pci.devfn,
142 void pci_mmio_write_config32(device_t dev, unsigned int where, u32 val)
144 struct bus *pbus = get_pbus(dev);
145 pci_ops_mmconf.write32(pbus, dev->bus->secondary, dev->path.pci.devfn,