blob: ed984f89bd100c67793a942847f5812cc38f967d [file] [log] [blame]
Uwe Hermannb80dbf02007-04-22 19:08:13 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermannb80dbf02007-04-22 19:08:13 +00003 *
4 * Copyright (C) 2004 Linux Networx
5 * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
Stefan Reinauer43b29cf2009-03-06 19:11:52 +00006 * Copyright (C) 2009 coresystems GmbH
Uwe Hermannb80dbf02007-04-22 19:08:13 +00007 *
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.
11 *
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.
16 *
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
20 */
21
Eric Biedermana9e632c2004-11-18 22:38:08 +000022#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>
27
28static struct bus *get_pbus(device_t dev)
29{
Rudolf Marek3a8565a2009-03-26 21:45:26 +000030 struct bus *pbus;
31
32 if (!dev)
Carl-Daniel Hailfinger87e70502009-06-05 11:41:51 +000033 die("get_pbus: dev is NULL!\n");
Rudolf Marek3a8565a2009-03-26 21:45:26 +000034
35 pbus = dev->bus;
36
Eric Biedermana9e632c2004-11-18 22:38:08 +000037 while(pbus && pbus->dev && !ops_pci_bus(pbus)) {
Carl-Daniel Hailfingerbba113e2009-03-05 19:33:12 +000038 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));
42 break;
43 }
Eric Biedermana9e632c2004-11-18 22:38:08 +000044 pbus = pbus->dev->bus;
45 }
46 if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_pci_bus) {
Carl-Daniel Hailfinger87e70502009-06-05 11:41:51 +000047 printk_emerg("%s Cannot find pci bus operations\n", dev_path(dev));
Eric Biedermana9e632c2004-11-18 22:38:08 +000048 die("");
Eric Biedermana9e632c2004-11-18 22:38:08 +000049 }
50 return pbus;
51}
52
53uint8_t pci_read_config8(device_t dev, unsigned where)
54{
55 struct bus *pbus = get_pbus(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +000056 return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
Eric Biedermana9e632c2004-11-18 22:38:08 +000057}
58
59uint16_t pci_read_config16(device_t dev, unsigned where)
60{
61 struct bus *pbus = get_pbus(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +000062 return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
Eric Biedermana9e632c2004-11-18 22:38:08 +000063}
64
65uint32_t pci_read_config32(device_t dev, unsigned where)
66{
67 struct bus *pbus = get_pbus(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +000068 return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
Eric Biedermana9e632c2004-11-18 22:38:08 +000069}
70
71void pci_write_config8(device_t dev, unsigned where, uint8_t val)
72{
73 struct bus *pbus = get_pbus(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +000074 ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
Eric Biedermana9e632c2004-11-18 22:38:08 +000075}
76
77void pci_write_config16(device_t dev, unsigned where, uint16_t val)
78{
79 struct bus *pbus = get_pbus(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +000080 ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
Eric Biedermana9e632c2004-11-18 22:38:08 +000081}
82
83void pci_write_config32(device_t dev, unsigned where, uint32_t val)
84{
85 struct bus *pbus = get_pbus(dev);
Stefan Reinauer2b34db82009-02-28 20:10:20 +000086 ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
Eric Biedermana9e632c2004-11-18 22:38:08 +000087}
Stefan Reinauer43b29cf2009-03-06 19:11:52 +000088
89#if MMCONF_SUPPORT
90uint8_t pci_mmio_read_config8(device_t dev, unsigned where)
91{
92 struct bus *pbus = get_pbus(dev);
93 return pci_ops_mmconf.read8(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
94}
95
96uint16_t pci_mmio_read_config16(device_t dev, unsigned where)
97{
98 struct bus *pbus = get_pbus(dev);
99 return pci_ops_mmconf.read16(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
100}
101
102uint32_t pci_mmio_read_config32(device_t dev, unsigned where)
103{
104 struct bus *pbus = get_pbus(dev);
105 return pci_ops_mmconf.read32(pbus, dev->bus->secondary, dev->path.pci.devfn, where);
106}
107
108void pci_mmio_write_config8(device_t dev, unsigned where, uint8_t val)
109{
110 struct bus *pbus = get_pbus(dev);
111 pci_ops_mmconf.write8(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
112}
113
114void pci_mmio_write_config16(device_t dev, unsigned where, uint16_t val)
115{
116 struct bus *pbus = get_pbus(dev);
117 pci_ops_mmconf.write16(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
118}
119
120void pci_mmio_write_config32(device_t dev, unsigned where, uint32_t val)
121{
122 struct bus *pbus = get_pbus(dev);
123 pci_ops_mmconf.write32(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val);
124}
125#endif