Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2004 Linux Networx |
| 5 | * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx) |
Stefan Reinauer | 43b29cf | 2009-03-06 19:11:52 +0000 | [diff] [blame] | 6 | * Copyright (C) 2009 coresystems GmbH |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 7 | * |
| 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 Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 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> |
| 27 | |
| 28 | static struct bus *get_pbus(device_t dev) |
| 29 | { |
Rudolf Marek | 3a8565a | 2009-03-26 21:45:26 +0000 | [diff] [blame] | 30 | struct bus *pbus; |
| 31 | |
| 32 | if (!dev) |
| 33 | printk_alert("get_pbus: dev is NULL!\n"); |
| 34 | |
| 35 | pbus = dev->bus; |
| 36 | |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 37 | while(pbus && pbus->dev && !ops_pci_bus(pbus)) { |
Carl-Daniel Hailfinger | bba113e | 2009-03-05 19:33:12 +0000 | [diff] [blame] | 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)); |
| 42 | break; |
| 43 | } |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 44 | pbus = pbus->dev->bus; |
| 45 | } |
| 46 | if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_pci_bus) { |
| 47 | printk_alert("%s Cannot find pci bus operations", dev_path(dev)); |
| 48 | die(""); |
| 49 | for(;;); |
| 50 | } |
| 51 | return pbus; |
| 52 | } |
| 53 | |
| 54 | uint8_t pci_read_config8(device_t dev, unsigned where) |
| 55 | { |
| 56 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 57 | return ops_pci_bus(pbus)->read8(pbus, dev->bus->secondary, dev->path.pci.devfn, where); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | uint16_t pci_read_config16(device_t dev, unsigned where) |
| 61 | { |
| 62 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 63 | return ops_pci_bus(pbus)->read16(pbus, dev->bus->secondary, dev->path.pci.devfn, where); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | uint32_t pci_read_config32(device_t dev, unsigned where) |
| 67 | { |
| 68 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 69 | return ops_pci_bus(pbus)->read32(pbus, dev->bus->secondary, dev->path.pci.devfn, where); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void pci_write_config8(device_t dev, unsigned where, uint8_t val) |
| 73 | { |
| 74 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 75 | ops_pci_bus(pbus)->write8(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void pci_write_config16(device_t dev, unsigned where, uint16_t val) |
| 79 | { |
| 80 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 81 | ops_pci_bus(pbus)->write16(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void pci_write_config32(device_t dev, unsigned where, uint32_t val) |
| 85 | { |
| 86 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 87 | ops_pci_bus(pbus)->write32(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val); |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 88 | } |
Stefan Reinauer | 43b29cf | 2009-03-06 19:11:52 +0000 | [diff] [blame] | 89 | |
| 90 | #if MMCONF_SUPPORT |
| 91 | uint8_t pci_mmio_read_config8(device_t dev, unsigned where) |
| 92 | { |
| 93 | struct bus *pbus = get_pbus(dev); |
| 94 | return pci_ops_mmconf.read8(pbus, dev->bus->secondary, dev->path.pci.devfn, where); |
| 95 | } |
| 96 | |
| 97 | uint16_t pci_mmio_read_config16(device_t dev, unsigned where) |
| 98 | { |
| 99 | struct bus *pbus = get_pbus(dev); |
| 100 | return pci_ops_mmconf.read16(pbus, dev->bus->secondary, dev->path.pci.devfn, where); |
| 101 | } |
| 102 | |
| 103 | uint32_t pci_mmio_read_config32(device_t dev, unsigned where) |
| 104 | { |
| 105 | struct bus *pbus = get_pbus(dev); |
| 106 | return pci_ops_mmconf.read32(pbus, dev->bus->secondary, dev->path.pci.devfn, where); |
| 107 | } |
| 108 | |
| 109 | void pci_mmio_write_config8(device_t dev, unsigned where, uint8_t val) |
| 110 | { |
| 111 | struct bus *pbus = get_pbus(dev); |
| 112 | pci_ops_mmconf.write8(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val); |
| 113 | } |
| 114 | |
| 115 | void pci_mmio_write_config16(device_t dev, unsigned where, uint16_t val) |
| 116 | { |
| 117 | struct bus *pbus = get_pbus(dev); |
| 118 | pci_ops_mmconf.write16(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val); |
| 119 | } |
| 120 | |
| 121 | void pci_mmio_write_config32(device_t dev, unsigned where, uint32_t val) |
| 122 | { |
| 123 | struct bus *pbus = get_pbus(dev); |
| 124 | pci_ops_mmconf.write32(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val); |
| 125 | } |
| 126 | #endif |