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)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <console/console.h>
22 #include <arch/pciconf.h>
23 #include <device/pci.h>
24 #include <device/pci_ids.h>
25 #include <device/pci_ops.h>
27 static struct bus *get_pbus(device_t dev)
29 struct bus *pbus = dev->bus;
30 while(pbus && pbus->dev && !ops_pci_bus(pbus)) {
31 pbus = pbus->dev->bus;
33 if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_pci_bus) {
34 printk_alert("%s Cannot find pci bus operations", dev_path(dev));
41 uint8_t pci_read_config8(device_t dev, unsigned where)
43 struct bus *pbus = get_pbus(dev);
44 return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
47 uint16_t pci_read_config16(device_t dev, unsigned where)
49 struct bus *pbus = get_pbus(dev);
50 return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
53 uint32_t pci_read_config32(device_t dev, unsigned where)
55 struct bus *pbus = get_pbus(dev);
56 return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
59 void pci_write_config8(device_t dev, unsigned where, uint8_t val)
61 struct bus *pbus = get_pbus(dev);
62 ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
65 void pci_write_config16(device_t dev, unsigned where, uint16_t val)
67 struct bus *pbus = get_pbus(dev);
68 ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
71 void pci_write_config32(device_t dev, unsigned where, uint32_t val)
73 struct bus *pbus = get_pbus(dev);
74 ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);