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 | |
Carl-Daniel Hailfinger | 00003ae | 2009-09-22 00:09:41 +0000 | [diff] [blame] | 28 | /* The only consumer of the return value of get_pbus() is ops_pci_bus(). |
| 29 | * ops_pci_bus() can handle being passed NULL and auto-picks working ops. |
| 30 | */ |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 31 | static struct bus *get_pbus(device_t dev) |
| 32 | { |
Stefan Reinauer | 4d933dd | 2009-07-21 21:36:41 +0000 | [diff] [blame] | 33 | struct bus *pbus = NULL; |
Rudolf Marek | 3a8565a | 2009-03-26 21:45:26 +0000 | [diff] [blame] | 34 | |
| 35 | if (!dev) |
Carl-Daniel Hailfinger | 87e7050 | 2009-06-05 11:41:51 +0000 | [diff] [blame] | 36 | die("get_pbus: dev is NULL!\n"); |
Stefan Reinauer | 4d933dd | 2009-07-21 21:36:41 +0000 | [diff] [blame] | 37 | else |
| 38 | pbus = dev->bus; |
Rudolf Marek | 3a8565a | 2009-03-26 21:45:26 +0000 | [diff] [blame] | 39 | |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 40 | while(pbus && pbus->dev && !ops_pci_bus(pbus)) { |
Carl-Daniel Hailfinger | bba113e | 2009-03-05 19:33:12 +0000 | [diff] [blame] | 41 | if (pbus == pbus->dev->bus) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 42 | printk(BIOS_ALERT, "%s in endless loop looking for a parent " |
Stefan Reinauer | 4d933dd | 2009-07-21 21:36:41 +0000 | [diff] [blame] | 43 | "bus with ops_pci_bus for %s, breaking out.\n", |
Carl-Daniel Hailfinger | bba113e | 2009-03-05 19:33:12 +0000 | [diff] [blame] | 44 | __func__, dev_path(dev)); |
| 45 | break; |
| 46 | } |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 47 | pbus = pbus->dev->bus; |
| 48 | } |
| 49 | if (!pbus || !pbus->dev || !pbus->dev->ops || !pbus->dev->ops->ops_pci_bus) { |
Carl-Daniel Hailfinger | 00003ae | 2009-09-22 00:09:41 +0000 | [diff] [blame] | 50 | /* This can happen before the device tree is set up completely. */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 51 | //printk(BIOS_EMERG, "%s: Cannot find pci bus operations.\n", dev_path(dev)); |
Carl-Daniel Hailfinger | 00003ae | 2009-09-22 00:09:41 +0000 | [diff] [blame] | 52 | pbus = NULL; |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 53 | } |
| 54 | return pbus; |
| 55 | } |
| 56 | |
| 57 | uint8_t pci_read_config8(device_t dev, unsigned where) |
| 58 | { |
| 59 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 60 | 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] | 61 | } |
| 62 | |
| 63 | uint16_t pci_read_config16(device_t dev, unsigned where) |
| 64 | { |
| 65 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 66 | 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] | 67 | } |
| 68 | |
| 69 | uint32_t pci_read_config32(device_t dev, unsigned where) |
| 70 | { |
| 71 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 72 | 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] | 73 | } |
| 74 | |
| 75 | void pci_write_config8(device_t dev, unsigned where, uint8_t val) |
| 76 | { |
| 77 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 78 | 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] | 79 | } |
| 80 | |
| 81 | void pci_write_config16(device_t dev, unsigned where, uint16_t val) |
| 82 | { |
| 83 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 84 | 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] | 85 | } |
| 86 | |
| 87 | void pci_write_config32(device_t dev, unsigned where, uint32_t val) |
| 88 | { |
| 89 | struct bus *pbus = get_pbus(dev); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 90 | 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] | 91 | } |
Stefan Reinauer | 43b29cf | 2009-03-06 19:11:52 +0000 | [diff] [blame] | 92 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 93 | #if CONFIG_MMCONF_SUPPORT |
Stefan Reinauer | 43b29cf | 2009-03-06 19:11:52 +0000 | [diff] [blame] | 94 | uint8_t pci_mmio_read_config8(device_t dev, unsigned where) |
| 95 | { |
| 96 | struct bus *pbus = get_pbus(dev); |
| 97 | return pci_ops_mmconf.read8(pbus, dev->bus->secondary, dev->path.pci.devfn, where); |
| 98 | } |
| 99 | |
| 100 | uint16_t pci_mmio_read_config16(device_t dev, unsigned where) |
| 101 | { |
| 102 | struct bus *pbus = get_pbus(dev); |
| 103 | return pci_ops_mmconf.read16(pbus, dev->bus->secondary, dev->path.pci.devfn, where); |
| 104 | } |
| 105 | |
| 106 | uint32_t pci_mmio_read_config32(device_t dev, unsigned where) |
| 107 | { |
| 108 | struct bus *pbus = get_pbus(dev); |
| 109 | return pci_ops_mmconf.read32(pbus, dev->bus->secondary, dev->path.pci.devfn, where); |
| 110 | } |
| 111 | |
| 112 | void pci_mmio_write_config8(device_t dev, unsigned where, uint8_t val) |
| 113 | { |
| 114 | struct bus *pbus = get_pbus(dev); |
| 115 | pci_ops_mmconf.write8(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val); |
| 116 | } |
| 117 | |
| 118 | void pci_mmio_write_config16(device_t dev, unsigned where, uint16_t val) |
| 119 | { |
| 120 | struct bus *pbus = get_pbus(dev); |
| 121 | pci_ops_mmconf.write16(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val); |
| 122 | } |
| 123 | |
| 124 | void pci_mmio_write_config32(device_t dev, unsigned where, uint32_t val) |
| 125 | { |
| 126 | struct bus *pbus = get_pbus(dev); |
| 127 | pci_ops_mmconf.write32(pbus, dev->bus->secondary, dev->path.pci.devfn, where, val); |
| 128 | } |
| 129 | #endif |