Add explicit license headers to all files in src/device.
[coreboot.git] / src / devices / pci_ops.c
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2004 Linux Networx
5  * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
6  *
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.
10  *
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.
15  *
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
19  */
20
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>
26
27 static struct bus *get_pbus(device_t dev)
28 {
29         struct bus *pbus = dev->bus;
30         while(pbus && pbus->dev && !ops_pci_bus(pbus)) {
31                 pbus = pbus->dev->bus;
32         }
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));
35                 die("");
36                 for(;;);
37         }
38         return pbus;
39 }
40
41 uint8_t pci_read_config8(device_t dev, unsigned where)
42 {
43         struct bus *pbus = get_pbus(dev);
44         return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
45 }
46
47 uint16_t pci_read_config16(device_t dev, unsigned where)
48 {
49         struct bus *pbus = get_pbus(dev);
50         return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
51 }
52
53 uint32_t pci_read_config32(device_t dev, unsigned where)
54 {
55         struct bus *pbus = get_pbus(dev);
56         return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where);
57 }
58
59 void pci_write_config8(device_t dev, unsigned where, uint8_t val)
60 {
61         struct bus *pbus = get_pbus(dev);
62         ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
63 }
64
65 void pci_write_config16(device_t dev, unsigned where, uint16_t val)
66 {
67         struct bus *pbus = get_pbus(dev);
68         ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
69 }
70
71 void pci_write_config32(device_t dev, unsigned where, uint32_t val)
72 {
73         struct bus *pbus = get_pbus(dev);
74         ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary, dev->path.u.pci.devfn, where, val);
75 }