Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * PCI Bus Services, see include/linux/pci.h for further explanation. |
| 3 | * |
| 4 | * Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter, |
| 5 | * David Mosberger-Tang |
| 6 | * |
| 7 | * Copyright 1997 -- 1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz> |
| 8 | * |
| 9 | * Copyright 2003 -- Eric Biederman <ebiederman@lnxi.com> |
| 10 | */ |
| 11 | |
| 12 | #include <console/console.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <stdint.h> |
| 15 | #include <bitops.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 16 | #include <string.h> |
Ronald G. Minnich | 6dd6c685 | 2003-10-02 00:08:42 +0000 | [diff] [blame] | 17 | #include <arch/io.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 21 | #include <part/hard_reset.h> |
Eric Biederman | 30e143a | 2003-09-01 23:45:32 +0000 | [diff] [blame] | 22 | #include <part/fallback_boot.h> |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 23 | #include <delay.h> |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 24 | #if CONFIG_HYPERTRANSPORT_PLUGIN_SUPPORT == 1 |
| 25 | #include <device/hypertransport.h> |
| 26 | #endif |
| 27 | #if CONFIG_PCIX_PLUGIN_SUPPORT == 1 |
| 28 | #include <device/pcix.h> |
| 29 | #endif |
| 30 | #if CONFIG_PCIEXP_PLUGIN_SUPPORT == 1 |
| 31 | #include <device/pciexp.h> |
| 32 | #endif |
| 33 | #if CONFGI_AGP_PLUGIN_SUPPORT == 1 |
| 34 | #include <device/agp.h> |
| 35 | #endif |
| 36 | #if CONFIG_CARDBUS_PLUGIN_SUPPORT == 1 |
| 37 | #include <device/cardbus.h> |
| 38 | #endif |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 39 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 40 | uint8_t pci_moving_config8(struct device *dev, unsigned reg) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 41 | { |
| 42 | uint8_t value, ones, zeroes; |
| 43 | value = pci_read_config8(dev, reg); |
| 44 | |
| 45 | pci_write_config8(dev, reg, 0xff); |
| 46 | ones = pci_read_config8(dev, reg); |
| 47 | |
| 48 | pci_write_config8(dev, reg, 0x00); |
| 49 | zeroes = pci_read_config8(dev, reg); |
| 50 | |
| 51 | pci_write_config8(dev, reg, value); |
| 52 | |
| 53 | return ones ^ zeroes; |
| 54 | } |
Li-Ta Lo | 9a5b496 | 2004-12-23 21:48:01 +0000 | [diff] [blame] | 55 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 56 | uint16_t pci_moving_config16(struct device *dev, unsigned reg) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 57 | { |
| 58 | uint16_t value, ones, zeroes; |
| 59 | value = pci_read_config16(dev, reg); |
| 60 | |
| 61 | pci_write_config16(dev, reg, 0xffff); |
| 62 | ones = pci_read_config16(dev, reg); |
| 63 | |
| 64 | pci_write_config16(dev, reg, 0x0000); |
| 65 | zeroes = pci_read_config16(dev, reg); |
| 66 | |
| 67 | pci_write_config16(dev, reg, value); |
| 68 | |
| 69 | return ones ^ zeroes; |
| 70 | } |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 71 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 72 | uint32_t pci_moving_config32(struct device *dev, unsigned reg) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 73 | { |
| 74 | uint32_t value, ones, zeroes; |
| 75 | value = pci_read_config32(dev, reg); |
| 76 | |
| 77 | pci_write_config32(dev, reg, 0xffffffff); |
| 78 | ones = pci_read_config32(dev, reg); |
| 79 | |
| 80 | pci_write_config32(dev, reg, 0x00000000); |
| 81 | zeroes = pci_read_config32(dev, reg); |
| 82 | |
| 83 | pci_write_config32(dev, reg, value); |
| 84 | |
| 85 | return ones ^ zeroes; |
| 86 | } |
| 87 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 88 | unsigned pci_find_next_capability(device_t dev, unsigned cap, unsigned last) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 89 | { |
| 90 | unsigned pos; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 91 | unsigned status; |
| 92 | unsigned reps = 48; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 93 | pos = 0; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 94 | status = pci_read_config16(dev, PCI_STATUS); |
| 95 | if (!(status & PCI_STATUS_CAP_LIST)) { |
| 96 | return 0; |
| 97 | } |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 98 | switch(dev->hdr_type & 0x7f) { |
| 99 | case PCI_HEADER_TYPE_NORMAL: |
| 100 | case PCI_HEADER_TYPE_BRIDGE: |
| 101 | pos = PCI_CAPABILITY_LIST; |
| 102 | break; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 103 | case PCI_HEADER_TYPE_CARDBUS: |
| 104 | pos = PCI_CB_CAPABILITY_LIST; |
| 105 | break; |
| 106 | default: |
| 107 | return 0; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 108 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 109 | pos = pci_read_config8(dev, pos); |
| 110 | while(reps-- && (pos >= 0x40)) { /* loop through the linked list */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 111 | int this_cap; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 112 | pos &= ~3; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 113 | this_cap = pci_read_config8(dev, pos + PCI_CAP_LIST_ID); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 114 | printk_spew("Capability: 0x%02x @ 0x%02x\n", cap, pos); |
| 115 | if (this_cap == 0xff) { |
| 116 | break; |
| 117 | } |
| 118 | if (!last && (this_cap == cap)) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 119 | return pos; |
| 120 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 121 | if (last == pos) { |
| 122 | last = 0; |
| 123 | } |
| 124 | pos = pci_read_config8(dev, pos + PCI_CAP_LIST_NEXT); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 125 | } |
| 126 | return 0; |
| 127 | } |
| 128 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 129 | unsigned pci_find_capability(device_t dev, unsigned cap) |
| 130 | { |
| 131 | return pci_find_next_capability(dev, cap, 0); |
| 132 | |
| 133 | } |
| 134 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 135 | /** Given a device and register, read the size of the BAR for that register. |
| 136 | * @param dev Pointer to the device structure |
| 137 | * @param resource Pointer to the resource structure |
| 138 | * @param index Address of the pci configuration register |
| 139 | */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 140 | struct resource *pci_get_resource(struct device *dev, unsigned long index) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 141 | { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 142 | struct resource *resource; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 143 | unsigned long value, attr; |
| 144 | resource_t moving, limit; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 145 | |
| 146 | /* Initialize the resources to nothing */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 147 | resource = new_resource(dev, index); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 148 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 149 | /* Get the initial value */ |
| 150 | value = pci_read_config32(dev, index); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 151 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 152 | /* See which bits move */ |
| 153 | moving = pci_moving_config32(dev, index); |
Li-Ta Lo | 9a5b496 | 2004-12-23 21:48:01 +0000 | [diff] [blame] | 154 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 155 | /* Initialize attr to the bits that do not move */ |
| 156 | attr = value & ~moving; |
| 157 | |
| 158 | /* If it is a 64bit resource look at the high half as well */ |
| 159 | if (((attr & PCI_BASE_ADDRESS_SPACE_IO) == 0) && |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 160 | ((attr & PCI_BASE_ADDRESS_MEM_LIMIT_MASK) == PCI_BASE_ADDRESS_MEM_LIMIT_64)) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 161 | { |
| 162 | /* Find the high bits that move */ |
| 163 | moving |= ((resource_t)pci_moving_config32(dev, index + 4)) << 32; |
| 164 | } |
| 165 | /* Find the resource constraints. |
| 166 | * |
| 167 | * Start by finding the bits that move. From there: |
| 168 | * - Size is the least significant bit of the bits that move. |
| 169 | * - Limit is all of the bits that move plus all of the lower bits. |
| 170 | * See PCI Spec 6.2.5.1 ... |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 171 | */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 172 | limit = 0; |
| 173 | if (moving) { |
| 174 | resource->size = 1; |
| 175 | resource->align = resource->gran = 0; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 176 | while(!(moving & resource->size)) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 177 | resource->size <<= 1; |
| 178 | resource->align += 1; |
| 179 | resource->gran += 1; |
| 180 | } |
| 181 | resource->limit = limit = moving | (resource->size - 1); |
| 182 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 183 | /* |
| 184 | * some broken hardware has read-only registers that do not |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 185 | * really size correctly. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 186 | * Example: the acer m7229 has BARs 1-4 normally read-only. |
| 187 | * so BAR1 at offset 0x10 reads 0x1f1. If you size that register |
| 188 | * by writing 0xffffffff to it, it will read back as 0x1f1 -- a |
| 189 | * violation of the spec. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 190 | * We catch this case and ignore it by observing which bits move, |
| 191 | * This also catches the common case unimplemented registers |
| 192 | * that always read back as 0. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 193 | */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 194 | if (moving == 0) { |
| 195 | if (value != 0) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 196 | printk_debug( |
| 197 | "%s register %02x(%08x), read-only ignoring it\n", |
| 198 | dev_path(dev), index, value); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 199 | } |
| 200 | resource->flags = 0; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 201 | } |
| 202 | else if (attr & PCI_BASE_ADDRESS_SPACE_IO) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 203 | /* An I/O mapped base address */ |
| 204 | attr &= PCI_BASE_ADDRESS_IO_ATTR_MASK; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 205 | resource->flags |= IORESOURCE_IO; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 206 | /* I don't want to deal with 32bit I/O resources */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 207 | resource->limit = 0xffff; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 208 | } |
| 209 | else { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 210 | /* A Memory mapped base address */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 211 | attr &= PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 212 | resource->flags |= IORESOURCE_MEM; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 213 | if (attr & PCI_BASE_ADDRESS_MEM_PREFETCH) { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 214 | resource->flags |= IORESOURCE_PREFETCH; |
| 215 | } |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 216 | attr &= PCI_BASE_ADDRESS_MEM_LIMIT_MASK; |
| 217 | if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_32) { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 218 | /* 32bit limit */ |
| 219 | resource->limit = 0xffffffffUL; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 220 | } |
| 221 | else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_1M) { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 222 | /* 1MB limit */ |
| 223 | resource->limit = 0x000fffffUL; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 224 | } |
| 225 | else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_64) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 226 | /* 64bit limit */ |
| 227 | resource->limit = 0xffffffffffffffffULL; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 228 | resource->flags |= IORESOURCE_PCI64; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 229 | } |
| 230 | else { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 231 | /* Invalid value */ |
| 232 | resource->flags = 0; |
| 233 | } |
| 234 | } |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 235 | /* Don't let the limit exceed which bits can move */ |
| 236 | if (resource->limit > limit) { |
| 237 | resource->limit = limit; |
| 238 | } |
| 239 | #if 0 |
| 240 | if (resource->flags) { |
| 241 | printk_debug("%s %02x ->", |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 242 | dev_path(dev), resource->index); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 243 | printk_debug(" value: 0x%08Lx zeroes: 0x%08Lx ones: 0x%08Lx attr: %08lx\n", |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 244 | value, zeroes, ones, attr); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 245 | printk_debug( |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 246 | "%s %02x -> size: 0x%08Lx max: 0x%08Lx %s\n ", |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 247 | dev_path(dev), |
| 248 | resource->index, |
| 249 | resource->size, resource->limit, |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 250 | resource_type(resource)); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 251 | } |
| 252 | #endif |
| 253 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 254 | return resource; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 257 | static void pci_get_rom_resource(struct device *dev, unsigned long index) |
Li-Ta Lo | 9a5b496 | 2004-12-23 21:48:01 +0000 | [diff] [blame] | 258 | { |
| 259 | struct resource *resource; |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 260 | unsigned long value; |
Li-Ta Lo | 9a5b496 | 2004-12-23 21:48:01 +0000 | [diff] [blame] | 261 | resource_t moving, limit; |
| 262 | |
Li-Ta Lo | bec039c | 2005-01-19 23:19:26 +0000 | [diff] [blame] | 263 | if ((dev->on_mainboard) && (dev->rom_address == 0)) { |
| 264 | //skip it if rom_address is not set in MB Config.lb |
Yinghai Lu | bcde161 | 2005-01-14 05:34:09 +0000 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | |
Li-Ta Lo | 9a5b496 | 2004-12-23 21:48:01 +0000 | [diff] [blame] | 268 | /* Initialize the resources to nothing */ |
| 269 | resource = new_resource(dev, index); |
| 270 | |
| 271 | /* Get the initial value */ |
| 272 | value = pci_read_config32(dev, index); |
| 273 | |
| 274 | /* See which bits move */ |
| 275 | moving = pci_moving_config32(dev, index); |
| 276 | /* clear the Enable bit */ |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 277 | moving = moving & ~PCI_ROM_ADDRESS_ENABLE; |
Li-Ta Lo | 9a5b496 | 2004-12-23 21:48:01 +0000 | [diff] [blame] | 278 | |
| 279 | /* Find the resource constraints. |
| 280 | * |
| 281 | * Start by finding the bits that move. From there: |
| 282 | * - Size is the least significant bit of the bits that move. |
| 283 | * - Limit is all of the bits that move plus all of the lower bits. |
| 284 | * See PCI Spec 6.2.5.1 ... |
| 285 | */ |
| 286 | limit = 0; |
| 287 | |
| 288 | if (moving) { |
| 289 | resource->size = 1; |
| 290 | resource->align = resource->gran = 0; |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 291 | while (!(moving & resource->size)) { |
Li-Ta Lo | 9a5b496 | 2004-12-23 21:48:01 +0000 | [diff] [blame] | 292 | resource->size <<= 1; |
| 293 | resource->align += 1; |
| 294 | resource->gran += 1; |
| 295 | } |
| 296 | resource->limit = limit = moving | (resource->size - 1); |
Li-Ta Lo | 9a5b496 | 2004-12-23 21:48:01 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | if (moving == 0) { |
| 300 | if (value != 0) { |
| 301 | printk_debug("%s register %02x(%08x), read-only ignoring it\n", |
| 302 | dev_path(dev), index, value); |
| 303 | } |
| 304 | resource->flags = 0; |
| 305 | } else { |
| 306 | resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY; |
| 307 | } |
Yinghai Lu | c7870ac | 2005-01-13 19:14:52 +0000 | [diff] [blame] | 308 | |
| 309 | /* for on board device with embedded ROM image, the ROM image is at |
| 310 | * fixed address specified in the Config.lb, the dev->rom_address is |
| 311 | * inited by driver_pci_onboard_ops::enable_dev() */ |
Yinghai Lu | bcde161 | 2005-01-14 05:34:09 +0000 | [diff] [blame] | 312 | if ((dev->on_mainboard) && (dev->rom_address != 0)) { |
Yinghai Lu | c7870ac | 2005-01-13 19:14:52 +0000 | [diff] [blame] | 313 | resource->base = dev->rom_address; |
| 314 | resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY | |
| 315 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 316 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 317 | |
| 318 | compact_resources(dev); |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 319 | } |
Li-Ta Lo | 9a5b496 | 2004-12-23 21:48:01 +0000 | [diff] [blame] | 320 | |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 321 | /** Read the base address registers for a given device. |
| 322 | * @param dev Pointer to the dev structure |
| 323 | * @param howmany How many registers to read (6 for device, 2 for bridge) |
| 324 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 325 | static void pci_read_bases(struct device *dev, unsigned int howmany) |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 326 | { |
| 327 | unsigned long index; |
| 328 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 329 | for(index = PCI_BASE_ADDRESS_0; (index < PCI_BASE_ADDRESS_0 + (howmany << 2)); ) { |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 330 | struct resource *resource; |
| 331 | resource = pci_get_resource(dev, index); |
| 332 | index += (resource->flags & IORESOURCE_PCI64)?8:4; |
| 333 | } |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 334 | |
| 335 | compact_resources(dev); |
Li-Ta Lo | 9a5b496 | 2004-12-23 21:48:01 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 338 | static void pci_set_resource(struct device *dev, struct resource *resource); |
| 339 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 340 | static void pci_record_bridge_resource( |
| 341 | struct device *dev, resource_t moving, |
| 342 | unsigned index, unsigned long mask, unsigned long type) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 343 | { |
| 344 | /* Initiliaze the constraints on the current bus */ |
| 345 | struct resource *resource; |
| 346 | resource = 0; |
| 347 | if (moving) { |
| 348 | unsigned long gran; |
| 349 | resource_t step; |
| 350 | resource = new_resource(dev, index); |
| 351 | resource->size = 0; |
| 352 | gran = 0; |
| 353 | step = 1; |
| 354 | while((moving & step) == 0) { |
| 355 | gran += 1; |
| 356 | step <<= 1; |
| 357 | } |
| 358 | resource->gran = gran; |
| 359 | resource->align = gran; |
| 360 | resource->limit = moving | (step - 1); |
| 361 | resource->flags = type | IORESOURCE_PCI_BRIDGE; |
| 362 | compute_allocate_resource(&dev->link[0], resource, mask, type); |
| 363 | /* If there is nothing behind the resource, |
| 364 | * clear it and forget it. |
| 365 | */ |
| 366 | if (resource->size == 0) { |
| 367 | resource->base = moving; |
| 368 | resource->flags |= IORESOURCE_ASSIGNED; |
| 369 | resource->flags &= ~IORESOURCE_STORED; |
| 370 | pci_set_resource(dev, resource); |
| 371 | resource->flags = 0; |
| 372 | } |
| 373 | } |
| 374 | return; |
| 375 | } |
| 376 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 377 | static void pci_bridge_read_bases(struct device *dev) |
| 378 | { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 379 | resource_t moving_base, moving_limit, moving; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 380 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 381 | /* See if the bridge I/O resources are implemented */ |
| 382 | moving_base = ((uint32_t)pci_moving_config8(dev, PCI_IO_BASE)) << 8; |
| 383 | moving_base |= ((uint32_t)pci_moving_config16(dev, PCI_IO_BASE_UPPER16)) << 16; |
| 384 | |
| 385 | moving_limit = ((uint32_t)pci_moving_config8(dev, PCI_IO_LIMIT)) << 8; |
| 386 | moving_limit |= ((uint32_t)pci_moving_config16(dev, PCI_IO_LIMIT_UPPER16)) << 16; |
| 387 | |
| 388 | moving = moving_base & moving_limit; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 389 | |
| 390 | /* Initialize the io space constraints on the current bus */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 391 | pci_record_bridge_resource( |
| 392 | dev, moving, PCI_IO_BASE, |
| 393 | IORESOURCE_IO, IORESOURCE_IO); |
| 394 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 395 | |
| 396 | /* See if the bridge prefmem resources are implemented */ |
| 397 | moving_base = ((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_BASE)) << 16; |
| 398 | moving_base |= ((resource_t)pci_moving_config32(dev, PCI_PREF_BASE_UPPER32)) << 32; |
| 399 | |
| 400 | moving_limit = ((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_LIMIT)) << 16; |
| 401 | moving_limit |= ((resource_t)pci_moving_config32(dev, PCI_PREF_LIMIT_UPPER32)) << 32; |
| 402 | |
| 403 | moving = moving_base & moving_limit; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 404 | /* Initiliaze the prefetchable memory constraints on the current bus */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 405 | pci_record_bridge_resource( |
| 406 | dev, moving, PCI_PREF_MEMORY_BASE, |
| 407 | IORESOURCE_MEM | IORESOURCE_PREFETCH, |
| 408 | IORESOURCE_MEM | IORESOURCE_PREFETCH); |
| 409 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 410 | |
| 411 | /* See if the bridge mem resources are implemented */ |
| 412 | moving_base = ((uint32_t)pci_moving_config16(dev, PCI_MEMORY_BASE)) << 16; |
| 413 | moving_limit = ((uint32_t)pci_moving_config16(dev, PCI_MEMORY_LIMIT)) << 16; |
| 414 | |
| 415 | moving = moving_base & moving_limit; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 416 | |
| 417 | /* Initialize the memory resources on the current bus */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 418 | pci_record_bridge_resource( |
| 419 | dev, moving, PCI_MEMORY_BASE, |
| 420 | IORESOURCE_MEM | IORESOURCE_PREFETCH, |
| 421 | IORESOURCE_MEM); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 422 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 423 | compact_resources(dev); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 426 | void pci_dev_read_resources(struct device *dev) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 427 | { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 428 | pci_read_bases(dev, 6); |
| 429 | pci_get_rom_resource(dev, PCI_ROM_ADDRESS); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 432 | void pci_bus_read_resources(struct device *dev) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 433 | { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 434 | pci_bridge_read_bases(dev); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 435 | pci_read_bases(dev, 2); |
| 436 | pci_get_rom_resource(dev, PCI_ROM_ADDRESS1); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 439 | static void pci_set_resource(struct device *dev, struct resource *resource) |
| 440 | { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 441 | resource_t base, end; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 442 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 443 | /* Make certain the resource has actually been set */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 444 | if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 445 | printk_err("ERROR: %s %02x %s size: 0x%010Lx not assigned\n", |
| 446 | dev_path(dev), resource->index, |
| 447 | resource_type(resource), |
| 448 | resource->size); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 449 | return; |
| 450 | } |
| 451 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 452 | /* If I have already stored this resource don't worry about it */ |
| 453 | if (resource->flags & IORESOURCE_STORED) { |
| 454 | return; |
| 455 | } |
| 456 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 457 | /* If the resources is substractive don't worry about it */ |
| 458 | if (resource->flags & IORESOURCE_SUBTRACTIVE) { |
| 459 | return; |
| 460 | } |
| 461 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 462 | /* Only handle PCI memory and IO resources for now */ |
| 463 | if (!(resource->flags & (IORESOURCE_MEM |IORESOURCE_IO))) |
| 464 | return; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 465 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 466 | /* Enable the resources in the command register */ |
| 467 | if (resource->size) { |
| 468 | if (resource->flags & IORESOURCE_MEM) { |
| 469 | dev->command |= PCI_COMMAND_MEMORY; |
| 470 | } |
| 471 | if (resource->flags & IORESOURCE_IO) { |
| 472 | dev->command |= PCI_COMMAND_IO; |
| 473 | } |
| 474 | if (resource->flags & IORESOURCE_PCI_BRIDGE) { |
| 475 | dev->command |= PCI_COMMAND_MASTER; |
| 476 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 477 | } |
| 478 | /* Get the base address */ |
| 479 | base = resource->base; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 480 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 481 | /* Get the end */ |
| 482 | end = resource_end(resource); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 483 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 484 | /* Now store the resource */ |
| 485 | resource->flags |= IORESOURCE_STORED; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 486 | if (!(resource->flags & IORESOURCE_PCI_BRIDGE)) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 487 | unsigned long base_lo, base_hi; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 488 | /* |
| 489 | * some chipsets allow us to set/clear the IO bit. |
| 490 | * (e.g. VIA 82c686a.) So set it to be safe) |
| 491 | */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 492 | base_lo = base & 0xffffffff; |
| 493 | base_hi = (base >> 32) & 0xffffffff; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 494 | if (resource->flags & IORESOURCE_IO) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 495 | base_lo |= PCI_BASE_ADDRESS_SPACE_IO; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 496 | } |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 497 | pci_write_config32(dev, resource->index, base_lo); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 498 | if (resource->flags & IORESOURCE_PCI64) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 499 | pci_write_config32(dev, resource->index + 4, base_hi); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 500 | } |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 501 | } |
| 502 | else if (resource->index == PCI_IO_BASE) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 503 | /* set the IO ranges */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 504 | compute_allocate_resource(&dev->link[0], resource, |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 505 | IORESOURCE_IO, IORESOURCE_IO); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 506 | pci_write_config8(dev, PCI_IO_BASE, base >> 8); |
| 507 | pci_write_config16(dev, PCI_IO_BASE_UPPER16, base >> 16); |
| 508 | pci_write_config8(dev, PCI_IO_LIMIT, end >> 8); |
| 509 | pci_write_config16(dev, PCI_IO_LIMIT_UPPER16, end >> 16); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 510 | } |
| 511 | else if (resource->index == PCI_MEMORY_BASE) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 512 | /* set the memory range */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 513 | compute_allocate_resource(&dev->link[0], resource, |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 514 | IORESOURCE_MEM | IORESOURCE_PREFETCH, |
| 515 | IORESOURCE_MEM); |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 516 | pci_write_config16(dev, PCI_MEMORY_BASE, base >> 16); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 517 | pci_write_config16(dev, PCI_MEMORY_LIMIT, end >> 16); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 518 | } |
| 519 | else if (resource->index == PCI_PREF_MEMORY_BASE) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 520 | /* set the prefetchable memory range */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 521 | compute_allocate_resource(&dev->link[0], resource, |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 522 | IORESOURCE_MEM | IORESOURCE_PREFETCH, |
| 523 | IORESOURCE_MEM | IORESOURCE_PREFETCH); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 524 | pci_write_config16(dev, PCI_PREF_MEMORY_BASE, base >> 16); |
| 525 | pci_write_config32(dev, PCI_PREF_BASE_UPPER32, base >> 32); |
| 526 | pci_write_config16(dev, PCI_PREF_MEMORY_LIMIT, end >> 16); |
| 527 | pci_write_config32(dev, PCI_PREF_LIMIT_UPPER32, end >> 32); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 528 | } |
| 529 | else { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 530 | /* Don't let me think I stored the resource */ |
| 531 | resource->flags &= ~IORESOURCE_STORED; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 532 | printk_err("ERROR: invalid resource->index %x\n", |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 533 | resource->index); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 534 | } |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 535 | report_resource_stored(dev, resource, ""); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 536 | return; |
| 537 | } |
| 538 | |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 539 | void pci_dev_set_resources(struct device *dev) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 540 | { |
| 541 | struct resource *resource, *last; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 542 | unsigned link; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 543 | uint8_t line; |
| 544 | |
| 545 | last = &dev->resource[dev->resources]; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 546 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 547 | for(resource = &dev->resource[0]; resource < last; resource++) { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 548 | pci_set_resource(dev, resource); |
| 549 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 550 | for(link = 0; link < dev->links; link++) { |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 551 | struct bus *bus; |
| 552 | bus = &dev->link[link]; |
| 553 | if (bus->children) { |
| 554 | assign_resources(bus); |
| 555 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | /* set a default latency timer */ |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 559 | pci_write_config8(dev, PCI_LATENCY_TIMER, 0x40); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 560 | |
| 561 | /* set a default secondary latency timer */ |
| 562 | if ((dev->hdr_type & 0x7f) == PCI_HEADER_TYPE_BRIDGE) { |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 563 | pci_write_config8(dev, PCI_SEC_LATENCY_TIMER, 0x40); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /* zero the irq settings */ |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 567 | line = pci_read_config8(dev, PCI_INTERRUPT_PIN); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 568 | if (line) { |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 569 | pci_write_config8(dev, PCI_INTERRUPT_LINE, 0); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 570 | } |
| 571 | /* set the cache line size, so far 64 bytes is good for everyone */ |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 572 | pci_write_config8(dev, PCI_CACHE_LINE_SIZE, 64 >> 2); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 575 | void pci_dev_enable_resources(struct device *dev) |
| 576 | { |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 577 | const struct pci_operations *ops; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 578 | uint16_t command; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 579 | |
| 580 | /* Set the subsystem vendor and device id for mainboard devices */ |
| 581 | ops = ops_pci(dev); |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 582 | if (dev->on_mainboard && ops && ops->set_subsystem) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 583 | printk_debug("%s subsystem <- %02x/%02x\n", |
| 584 | dev_path(dev), |
| 585 | MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, |
| 586 | MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); |
| 587 | ops->set_subsystem(dev, |
| 588 | MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, |
| 589 | MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); |
| 590 | } |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 591 | command = pci_read_config16(dev, PCI_COMMAND); |
| 592 | command |= dev->command; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 593 | command |= (PCI_COMMAND_PARITY + PCI_COMMAND_SERR); /* error check */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 594 | printk_debug("%s cmd <- %02x\n", dev_path(dev), command); |
| 595 | pci_write_config16(dev, PCI_COMMAND, command); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | void pci_bus_enable_resources(struct device *dev) |
| 599 | { |
| 600 | uint16_t ctrl; |
Li-Ta Lo | 515f6c7 | 2005-01-11 22:48:54 +0000 | [diff] [blame] | 601 | /* enable IO in command register if there is VGA card |
| 602 | * connected with (even it does not claim IO resource) */ |
| 603 | if (dev->link[0].bridge_ctrl & PCI_BRIDGE_CTL_VGA) |
| 604 | dev->command |= PCI_COMMAND_IO; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 605 | ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL); |
| 606 | ctrl |= dev->link[0].bridge_ctrl; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 607 | ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR); /* error check */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 608 | printk_debug("%s bridge ctrl <- %04x\n", dev_path(dev), ctrl); |
| 609 | pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl); |
| 610 | |
| 611 | pci_dev_enable_resources(dev); |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 612 | |
| 613 | enable_childrens_resources(dev); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 616 | void pci_bus_reset(struct bus *bus) |
| 617 | { |
| 618 | unsigned ctl; |
| 619 | ctl = pci_read_config16(bus->dev, PCI_BRIDGE_CONTROL); |
| 620 | ctl |= PCI_BRIDGE_CTL_BUS_RESET; |
| 621 | pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, ctl); |
| 622 | mdelay(10); |
| 623 | ctl &= ~PCI_BRIDGE_CTL_BUS_RESET; |
| 624 | pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, ctl); |
| 625 | delay(1); |
| 626 | } |
| 627 | |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 628 | void pci_dev_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 629 | { |
| 630 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 631 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 632 | } |
| 633 | |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 634 | void pci_dev_init(struct device *dev) |
| 635 | { |
Roman Kononov | 778a42b | 2007-04-06 18:34:39 +0000 | [diff] [blame^] | 636 | #if CONFIG_CONSOLE_VGA == 1 |
| 637 | extern int vga_inited; |
| 638 | #endif |
| 639 | #if CONFIG_PCI_ROM_RUN == 1 || CONFIG_CONSOLE_VGA == 1 |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 640 | struct rom_header *rom, *ram; |
| 641 | |
Roman Kononov | 778a42b | 2007-04-06 18:34:39 +0000 | [diff] [blame^] | 642 | #if CONFIG_PCI_ROM_RUN != 1 |
| 643 | /* We want to execute VGA option ROMs when CONFIG_CONSOLE_VGA |
| 644 | * is set but CONFIG_PCI_ROM_RUN is not. In this case we skip |
| 645 | * all other option ROM types. |
| 646 | */ |
| 647 | if (dev->class!=PCI_CLASS_DISPLAY_VGA) |
| 648 | return; |
| 649 | #endif |
| 650 | |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 651 | rom = pci_rom_probe(dev); |
| 652 | if (rom == NULL) |
| 653 | return; |
Roman Kononov | 778a42b | 2007-04-06 18:34:39 +0000 | [diff] [blame^] | 654 | |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 655 | ram = pci_rom_load(dev, rom); |
Yinghai Lu | 9e4faef | 2005-01-14 22:04:49 +0000 | [diff] [blame] | 656 | if (ram == NULL) |
| 657 | return; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 658 | |
| 659 | run_bios(dev, ram); |
Roman Kononov | 778a42b | 2007-04-06 18:34:39 +0000 | [diff] [blame^] | 660 | |
| 661 | #if CONFIG_CONSOLE_VGA == 1 |
| 662 | /* vga_inited is a trigger of the VGA console code. |
| 663 | * |
| 664 | * Only set it if we enabled VGA console, and if we |
| 665 | * just initialized a VGA card. |
| 666 | */ |
| 667 | vga_inited|=dev->class==PCI_CLASS_DISPLAY_VGA; |
| 668 | #endif |
Yinghai Lu | 9e4faef | 2005-01-14 22:04:49 +0000 | [diff] [blame] | 669 | #endif |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 670 | } |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 671 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 672 | /** Default device operation for PCI devices */ |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 673 | static struct pci_operations pci_dev_ops_pci = { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 674 | .set_subsystem = pci_dev_set_subsystem, |
| 675 | }; |
| 676 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 677 | struct device_operations default_pci_ops_dev = { |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 678 | .read_resources = pci_dev_read_resources, |
| 679 | .set_resources = pci_dev_set_resources, |
| 680 | .enable_resources = pci_dev_enable_resources, |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 681 | .init = pci_dev_init, |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 682 | .scan_bus = 0, |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 683 | .enable = 0, |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 684 | .ops_pci = &pci_dev_ops_pci, |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 685 | }; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 686 | |
| 687 | /** Default device operations for PCI bridges */ |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 688 | static struct pci_operations pci_bus_ops_pci = { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 689 | .set_subsystem = 0, |
| 690 | }; |
Li-Ta Lo | 883b879 | 2005-01-10 23:16:22 +0000 | [diff] [blame] | 691 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 692 | struct device_operations default_pci_ops_bus = { |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 693 | .read_resources = pci_bus_read_resources, |
| 694 | .set_resources = pci_dev_set_resources, |
| 695 | .enable_resources = pci_bus_enable_resources, |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 696 | .init = 0, |
| 697 | .scan_bus = pci_scan_bridge, |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 698 | .enable = 0, |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 699 | .reset_bus = pci_bus_reset, |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 700 | .ops_pci = &pci_bus_ops_pci, |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 701 | }; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 702 | |
| 703 | /** |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 704 | * @brief Detect the type of downstream bridge |
| 705 | * |
| 706 | * This function is a heuristic to detect which type |
| 707 | * of bus is downstream of a pci to pci bridge. This |
| 708 | * functions by looking for various capability blocks |
| 709 | * to figure out the type of downstream bridge. PCI-X |
| 710 | * PCI-E, and Hypertransport all seem to have appropriate |
| 711 | * capabilities. |
| 712 | * |
| 713 | * When only a PCI-Express capability is found the type |
| 714 | * is examined to see which type of bridge we have. |
| 715 | * |
| 716 | * @param dev |
| 717 | * |
| 718 | * @return appropriate bridge operations |
| 719 | */ |
| 720 | static struct device_operations *get_pci_bridge_ops(device_t dev) |
| 721 | { |
| 722 | unsigned pos; |
| 723 | |
| 724 | #if CONFIG_PCIX_PLUGIN_SUPPORT == 1 |
| 725 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); |
| 726 | if (pos) { |
| 727 | printk_debug("%s subbordinate bus PCI-X\n", dev_path(dev)); |
| 728 | return &default_pcix_ops_bus; |
| 729 | } |
| 730 | #endif |
| 731 | #if CONFIG_AGP_PLUGIN_SUPPORT == 1 |
| 732 | /* How do I detect an PCI to AGP bridge? */ |
| 733 | #endif |
| 734 | #if CONFIG_HYPERTRANSPORT_PLUGIN_SUPPORT == 1 |
| 735 | pos = 0; |
| 736 | while((pos = pci_find_next_capability(dev, PCI_CAP_ID_HT, pos))) { |
| 737 | unsigned flags; |
| 738 | flags = pci_read_config16(dev, pos + PCI_CAP_FLAGS); |
| 739 | if ((flags >> 13) == 1) { |
| 740 | /* Host or Secondary Interface */ |
| 741 | printk_debug("%s subbordinate bus Hypertransport\n", |
| 742 | dev_path(dev)); |
| 743 | return &default_ht_ops_bus; |
| 744 | } |
| 745 | } |
| 746 | #endif |
| 747 | #if CONFIG_PCIEXP_PLUGIN_SUPPORT == 1 |
| 748 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIE); |
| 749 | if (pos) { |
| 750 | unsigned flags; |
| 751 | flags = pci_read_config16(dev, pos + PCI_EXP_FLAGS); |
| 752 | switch((flags & PCI_EXP_FLAGS_TYPE) >> 4) { |
| 753 | case PCI_EXP_TYPE_ROOT_PORT: |
| 754 | case PCI_EXP_TYPE_UPSTREAM: |
| 755 | case PCI_EXP_TYPE_DOWNSTREAM: |
| 756 | printk_debug("%s subbordinate bus PCI Express\n", |
| 757 | dev_path(dev)); |
| 758 | return &default_pciexp_ops_bus; |
| 759 | case PCI_EXP_TYPE_PCI_BRIDGE: |
| 760 | printk_debug("%s subbordinate PCI\n", |
| 761 | dev_path(dev)); |
| 762 | return &default_pci_ops_bus; |
| 763 | default: |
| 764 | break; |
| 765 | } |
| 766 | } |
| 767 | #endif |
| 768 | return &default_pci_ops_bus; |
| 769 | } |
| 770 | |
| 771 | /** |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 772 | * @brief Set up PCI device operation |
| 773 | * |
| 774 | * |
| 775 | * @param dev |
| 776 | * |
| 777 | * @see pci_drivers |
| 778 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 779 | static void set_pci_ops(struct device *dev) |
| 780 | { |
| 781 | struct pci_driver *driver; |
| 782 | if (dev->ops) { |
| 783 | return; |
| 784 | } |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 785 | |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 786 | /* Look through the list of setup drivers and find one for |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 787 | * this pci device |
| 788 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 789 | for(driver = &pci_drivers[0]; driver != &epci_drivers[0]; driver++) { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 790 | if ((driver->vendor == dev->vendor) && |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 791 | (driver->device == dev->device)) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 792 | { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 793 | dev->ops = driver->ops; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 794 | printk_spew("%s [%04x/%04x] %sops\n", |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 795 | dev_path(dev), |
| 796 | driver->vendor, driver->device, |
| 797 | (driver->ops->scan_bus?"bus ":"")); |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 798 | return; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 799 | } |
| 800 | } |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 801 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 802 | /* If I don't have a specific driver use the default operations */ |
| 803 | switch(dev->hdr_type & 0x7f) { /* header type */ |
| 804 | case PCI_HEADER_TYPE_NORMAL: /* standard header */ |
| 805 | if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) |
| 806 | goto bad; |
| 807 | dev->ops = &default_pci_ops_dev; |
| 808 | break; |
| 809 | case PCI_HEADER_TYPE_BRIDGE: |
| 810 | if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI) |
| 811 | goto bad; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 812 | dev->ops = get_pci_bridge_ops(dev); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 813 | break; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 814 | #if CONFIG_CARDBUS_PLUGIN_SUPPORT == 1 |
| 815 | case PCI_HEADER_TYPE_CARDBUS: |
| 816 | dev->ops = &default_cardbus_ops_bus; |
| 817 | break; |
| 818 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 819 | default: |
| 820 | bad: |
Li-Ta Lo | 69c5a90 | 2004-04-29 20:08:54 +0000 | [diff] [blame] | 821 | if (dev->enabled) { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 822 | printk_err("%s [%04x/%04x/%06x] has unknown header " |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 823 | "type %02x, ignoring.\n", |
| 824 | dev_path(dev), |
| 825 | dev->vendor, dev->device, |
| 826 | dev->class >> 8, dev->hdr_type); |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 827 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 828 | } |
| 829 | return; |
| 830 | } |
| 831 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 832 | |
| 833 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 834 | /** |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 835 | * @brief See if we have already allocated a device structure for a given devfn. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 836 | * |
| 837 | * Given a linked list of PCI device structures and a devfn number, find the |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 838 | * device structure correspond to the devfn, if present. This function also |
| 839 | * removes the device structure from the linked list. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 840 | * |
| 841 | * @param list the device structure list |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 842 | * @param devfn a device/function number |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 843 | * |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 844 | * @return pointer to the device structure found or null of we have not |
| 845 | * allocated a device for this devfn yet. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 846 | */ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 847 | static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 848 | { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 849 | struct device *dev; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 850 | dev = 0; |
| 851 | for(; *list; list = &(*list)->sibling) { |
Eric Biederman | ad1b35a | 2003-10-14 02:36:51 +0000 | [diff] [blame] | 852 | if ((*list)->path.type != DEVICE_PATH_PCI) { |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 853 | printk_err("child %s not a pci device\n", |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 854 | dev_path(*list)); |
Eric Biederman | ad1b35a | 2003-10-14 02:36:51 +0000 | [diff] [blame] | 855 | continue; |
| 856 | } |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 857 | if ((*list)->path.u.pci.devfn == devfn) { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 858 | /* Unlink from the list */ |
| 859 | dev = *list; |
| 860 | *list = (*list)->sibling; |
| 861 | dev->sibling = 0; |
| 862 | break; |
| 863 | } |
| 864 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 865 | /* Just like alloc_dev add the device to the list of device on the bus. |
| 866 | * When the list of devices was formed we removed all of the parents |
| 867 | * children, and now we are interleaving static and dynamic devices in |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 868 | * order on the bus. |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 869 | */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 870 | if (dev) { |
| 871 | device_t child; |
| 872 | /* Find the last child of our parent */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 873 | for(child = dev->bus->children; child && child->sibling; ) { |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 874 | child = child->sibling; |
| 875 | } |
| 876 | /* Place the device on the list of children of it's parent. */ |
| 877 | if (child) { |
| 878 | child->sibling = dev; |
| 879 | } else { |
| 880 | dev->bus->children = dev; |
| 881 | } |
| 882 | } |
| 883 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 884 | return dev; |
| 885 | } |
| 886 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 887 | /** |
| 888 | * @brief Scan a PCI bus. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 889 | * |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 890 | * Determine the existence of a given PCI device. |
| 891 | * |
| 892 | * @param bus pointer to the bus structure |
| 893 | * @param devfn to look at |
| 894 | * |
| 895 | * @return The device structure for hte device (if found) |
| 896 | * or the NULL if no device is found. |
| 897 | */ |
| 898 | device_t pci_probe_dev(device_t dev, struct bus *bus, unsigned devfn) |
| 899 | { |
| 900 | uint32_t id, class; |
| 901 | uint8_t hdr_type; |
| 902 | |
| 903 | /* Detect if a device is present */ |
| 904 | if (!dev) { |
| 905 | struct device dummy; |
| 906 | dummy.bus = bus; |
| 907 | dummy.path.type = DEVICE_PATH_PCI; |
| 908 | dummy.path.u.pci.devfn = devfn; |
| 909 | id = pci_read_config32(&dummy, PCI_VENDOR_ID); |
| 910 | /* Have we found somthing? |
| 911 | * Some broken boards return 0 if a slot is empty. |
| 912 | */ |
| 913 | if ( (id == 0xffffffff) || (id == 0x00000000) || |
| 914 | (id == 0x0000ffff) || (id == 0xffff0000)) |
| 915 | { |
| 916 | printk_spew("PCI: devfn 0x%x, bad id 0x%x\n", devfn, id); |
| 917 | return NULL; |
| 918 | } |
| 919 | dev = alloc_dev(bus, &dummy.path); |
| 920 | } |
| 921 | else { |
| 922 | /* Enable/disable the device. Once we have |
| 923 | * found the device specific operations this |
| 924 | * operations we will disable the device with |
| 925 | * those as well. |
| 926 | * |
| 927 | * This is geared toward devices that have subfunctions |
| 928 | * that do not show up by default. |
| 929 | * |
| 930 | * If a device is a stuff option on the motherboard |
| 931 | * it may be absent and enable_dev must cope. |
| 932 | * |
| 933 | */ |
| 934 | /* Run the magice enable sequence for the device */ |
| 935 | if (dev->chip_ops && dev->chip_ops->enable_dev) { |
| 936 | dev->chip_ops->enable_dev(dev); |
| 937 | } |
| 938 | /* Now read the vendor and device id */ |
| 939 | id = pci_read_config32(dev, PCI_VENDOR_ID); |
| 940 | |
| 941 | |
| 942 | /* If the device does not have a pci id disable it. |
| 943 | * Possibly this is because we have already disabled |
| 944 | * the device. But this also handles optional devices |
| 945 | * that may not always show up. |
| 946 | */ |
| 947 | /* If the chain is fully enumerated quit */ |
| 948 | if ( (id == 0xffffffff) || (id == 0x00000000) || |
| 949 | (id == 0x0000ffff) || (id == 0xffff0000)) |
| 950 | { |
| 951 | if (dev->enabled) { |
| 952 | printk_info("Disabling static device: %s\n", |
| 953 | dev_path(dev)); |
| 954 | dev->enabled = 0; |
| 955 | } |
| 956 | return dev; |
| 957 | } |
| 958 | } |
| 959 | /* Read the rest of the pci configuration information */ |
| 960 | hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE); |
| 961 | class = pci_read_config32(dev, PCI_CLASS_REVISION); |
| 962 | |
| 963 | /* Store the interesting information in the device structure */ |
| 964 | dev->vendor = id & 0xffff; |
| 965 | dev->device = (id >> 16) & 0xffff; |
| 966 | dev->hdr_type = hdr_type; |
| 967 | /* class code, the upper 3 bytes of PCI_CLASS_REVISION */ |
| 968 | dev->class = class >> 8; |
| 969 | |
| 970 | |
| 971 | /* Architectural/System devices always need to |
| 972 | * be bus masters. |
| 973 | */ |
| 974 | if ((dev->class >> 16) == PCI_BASE_CLASS_SYSTEM) { |
| 975 | dev->command |= PCI_COMMAND_MASTER; |
| 976 | } |
| 977 | /* Look at the vendor and device id, or at least the |
| 978 | * header type and class and figure out which set of |
| 979 | * configuration methods to use. Unless we already |
| 980 | * have some pci ops. |
| 981 | */ |
| 982 | set_pci_ops(dev); |
| 983 | |
| 984 | /* Now run the magic enable/disable sequence for the device */ |
| 985 | if (dev->ops && dev->ops->enable) { |
| 986 | dev->ops->enable(dev); |
| 987 | } |
| 988 | |
| 989 | |
| 990 | /* Display the device and error if we don't have some pci operations |
| 991 | * for it. |
| 992 | */ |
| 993 | printk_debug("%s [%04x/%04x] %s%s\n", |
| 994 | dev_path(dev), |
| 995 | dev->vendor, dev->device, |
| 996 | dev->enabled?"enabled": "disabled", |
| 997 | dev->ops?"" : " No operations" |
| 998 | ); |
| 999 | |
| 1000 | return dev; |
| 1001 | } |
| 1002 | |
| 1003 | /** |
| 1004 | * @brief Scan a PCI bus. |
| 1005 | * |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1006 | * Determine the existence of devices and bridges on a PCI bus. If there are |
| 1007 | * bridges on the bus, recursively scan the buses behind the bridges. |
| 1008 | * |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1009 | * This function is the default scan_bus() method for the root device |
| 1010 | * 'dev_root'. |
| 1011 | * |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1012 | * @param bus pointer to the bus structure |
| 1013 | * @param min_devfn minimum devfn to look at in the scan usually 0x00 |
| 1014 | * @param max_devfn maximum devfn to look at in the scan usually 0xff |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1015 | * @param max current bus number |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1016 | * |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1017 | * @return The maximum bus number found, after scanning all subordinate busses |
| 1018 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1019 | unsigned int pci_scan_bus(struct bus *bus, |
| 1020 | unsigned min_devfn, unsigned max_devfn, |
| 1021 | unsigned int max) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1022 | { |
| 1023 | unsigned int devfn; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1024 | device_t old_devices; |
| 1025 | device_t child; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1026 | |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 1027 | #if PCI_BUS_SEGN_BITS |
| 1028 | printk_debug("PCI: pci_scan_bus for bus %04x:%02x\n", bus->secondary >> 8, bus->secondary & 0xff); |
| 1029 | #else |
| 1030 | printk_debug("PCI: pci_scan_bus for bus %02x\n", bus->secondary); |
| 1031 | #endif |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1032 | |
| 1033 | old_devices = bus->children; |
| 1034 | bus->children = 0; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1035 | |
| 1036 | post_code(0x24); |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 1037 | /* probe all devices/functions on this bus with some optimization for |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1038 | * non-existence and single funcion devices |
| 1039 | */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1040 | for (devfn = min_devfn; devfn <= max_devfn; devfn++) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1041 | device_t dev; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1042 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 1043 | /* First thing setup the device structure */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1044 | dev = pci_scan_get_dev(&old_devices, devfn); |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 1045 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1046 | /* See if a device is present and setup the device |
| 1047 | * structure. |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 1048 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1049 | dev = pci_probe_dev(dev, bus, devfn); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 1050 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1051 | /* if this is not a multi function device, |
| 1052 | * or the device is not present don't waste |
| 1053 | * time probing another function. |
| 1054 | * Skip to next device. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1055 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1056 | if ((PCI_FUNC(devfn) == 0x00) && |
| 1057 | (!dev || (dev->enabled && ((dev->hdr_type & 0x80) != 0x80)))) |
| 1058 | { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1059 | devfn += 0x07; |
| 1060 | } |
| 1061 | } |
| 1062 | post_code(0x25); |
| 1063 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1064 | /* Die if any leftover Static devices are are found. |
| 1065 | * There's probably a problem in the Config.lb. |
| 1066 | */ |
| 1067 | if(old_devices) { |
| 1068 | device_t left; |
| 1069 | for(left = old_devices; left; left = left->sibling) { |
Ronald G. Minnich | e800b91 | 2006-01-17 21:12:03 +0000 | [diff] [blame] | 1070 | printk_err("%s\n", dev_path(left)); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1071 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 1072 | die("PCI: Left over static devices. Check your Config.lb\n"); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1075 | /* For all children that implement scan_bus (i.e. bridges) |
| 1076 | * scan the bus behind that child. |
| 1077 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1078 | for(child = bus->children; child; child = child->sibling) { |
| 1079 | max = scan_bus(child, max); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1080 | } |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1081 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1082 | /* |
| 1083 | * We've scanned the bus and so we know all about what's on |
| 1084 | * the other side of any bridges that may be on this bus plus |
| 1085 | * any devices. |
| 1086 | * |
| 1087 | * Return how far we've got finding sub-buses. |
| 1088 | */ |
Yinghai Lu | 5f9624d | 2006-10-04 22:56:21 +0000 | [diff] [blame] | 1089 | printk_debug("PCI: pci_scan_bus returning with max=%03x\n", max); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1090 | post_code(0x55); |
| 1091 | return max; |
| 1092 | } |
| 1093 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1094 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1095 | /** |
| 1096 | * @brief Scan a PCI bridge and the buses behind the bridge. |
| 1097 | * |
| 1098 | * Determine the existence of buses behind the bridge. Set up the bridge |
| 1099 | * according to the result of the scan. |
| 1100 | * |
| 1101 | * This function is the default scan_bus() method for PCI bridge devices. |
| 1102 | * |
| 1103 | * @param dev pointer to the bridge device |
| 1104 | * @param max the highest bus number assgined up to now |
| 1105 | * |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1106 | * @return The maximum bus number found, after scanning all subordinate busses |
| 1107 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1108 | unsigned int do_pci_scan_bridge(struct device *dev, unsigned int max, |
| 1109 | unsigned int (*do_scan_bus)(struct bus *bus, |
| 1110 | unsigned min_devfn, unsigned max_devfn, unsigned int max)) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1111 | { |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1112 | struct bus *bus; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1113 | uint32_t buses; |
| 1114 | uint16_t cr; |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 1115 | |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 1116 | printk_spew("%s for %s\n", __func__, dev_path(dev)); |
| 1117 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1118 | bus = &dev->link[0]; |
Eric Biederman | a9e632c | 2004-11-18 22:38:08 +0000 | [diff] [blame] | 1119 | bus->dev = dev; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1120 | dev->links = 1; |
| 1121 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1122 | /* Set up the primary, secondary and subordinate bus numbers. We have |
| 1123 | * no idea how many buses are behind this bridge yet, so we set the |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1124 | * subordinate bus number to 0xff for the moment. |
| 1125 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1126 | bus->secondary = ++max; |
| 1127 | bus->subordinate = 0xff; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1128 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1129 | /* Clear all status bits and turn off memory, I/O and master enables. */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1130 | cr = pci_read_config16(dev, PCI_COMMAND); |
| 1131 | pci_write_config16(dev, PCI_COMMAND, 0x0000); |
| 1132 | pci_write_config16(dev, PCI_STATUS, 0xffff); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1133 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1134 | /* |
| 1135 | * Read the existing primary/secondary/subordinate bus |
| 1136 | * number configuration. |
| 1137 | */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1138 | buses = pci_read_config32(dev, PCI_PRIMARY_BUS); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1139 | |
| 1140 | /* Configure the bus numbers for this bridge: the configuration |
| 1141 | * transactions will not be propagated by the bridge if it is not |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1142 | * correctly configured. |
| 1143 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1144 | buses &= 0xff000000; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1145 | buses |= (((unsigned int) (dev->bus->secondary) << 0) | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1146 | ((unsigned int) (bus->secondary) << 8) | |
| 1147 | ((unsigned int) (bus->subordinate) << 16)); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1148 | pci_write_config32(dev, PCI_PRIMARY_BUS, buses); |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 1149 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1150 | /* Now we can scan all subordinate buses |
| 1151 | * i.e. the bus behind the bridge. |
| 1152 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1153 | max = do_scan_bus(bus, 0x00, 0xff, max); |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 1154 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1155 | /* We know the number of buses behind this bridge. Set the subordinate |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1156 | * bus number to its real value. |
| 1157 | */ |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1158 | bus->subordinate = max; |
| 1159 | buses = (buses & 0xff00ffff) | |
| 1160 | ((unsigned int) (bus->subordinate) << 16); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 1161 | pci_write_config32(dev, PCI_PRIMARY_BUS, buses); |
| 1162 | pci_write_config16(dev, PCI_COMMAND, cr); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1163 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1164 | printk_spew("%s returns max %d\n", __func__, max); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1165 | return max; |
| 1166 | } |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1167 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1168 | /** |
| 1169 | * @brief Scan a PCI bridge and the buses behind the bridge. |
| 1170 | * |
| 1171 | * Determine the existence of buses behind the bridge. Set up the bridge |
| 1172 | * according to the result of the scan. |
| 1173 | * |
| 1174 | * This function is the default scan_bus() method for PCI bridge devices. |
| 1175 | * |
| 1176 | * @param dev pointer to the bridge device |
| 1177 | * @param max the highest bus number assgined up to now |
| 1178 | * |
| 1179 | * @return The maximum bus number found, after scanning all subordinate busses |
| 1180 | */ |
| 1181 | unsigned int pci_scan_bridge(struct device *dev, unsigned int max) |
| 1182 | { |
| 1183 | return do_pci_scan_bridge(dev, max, pci_scan_bus); |
| 1184 | } |
| 1185 | |
Ronald G. Minnich | 6dd6c685 | 2003-10-02 00:08:42 +0000 | [diff] [blame] | 1186 | /* |
| 1187 | Tell the EISA int controller this int must be level triggered |
| 1188 | THIS IS A KLUDGE -- sorry, this needs to get cleaned up. |
| 1189 | */ |
Ronald G. Minnich | 88fb1a6 | 2006-06-22 04:37:27 +0000 | [diff] [blame] | 1190 | void pci_level_irq(unsigned char intNum) |
Ronald G. Minnich | 6dd6c685 | 2003-10-02 00:08:42 +0000 | [diff] [blame] | 1191 | { |
Ronald G. Minnich | cb3f498 | 2003-10-02 18:16:07 +0000 | [diff] [blame] | 1192 | unsigned short intBits = inb(0x4d0) | (((unsigned) inb(0x4d1)) << 8); |
Ronald G. Minnich | 6dd6c685 | 2003-10-02 00:08:42 +0000 | [diff] [blame] | 1193 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1194 | printk_spew("%s: current ints are 0x%x\n", __func__, intBits); |
Ronald G. Minnich | 6dd6c685 | 2003-10-02 00:08:42 +0000 | [diff] [blame] | 1195 | intBits |= (1 << intNum); |
| 1196 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1197 | printk_spew("%s: try to set ints 0x%x\n", __func__, intBits); |
Ronald G. Minnich | cb3f498 | 2003-10-02 18:16:07 +0000 | [diff] [blame] | 1198 | |
Ronald G. Minnich | 6dd6c685 | 2003-10-02 00:08:42 +0000 | [diff] [blame] | 1199 | // Write new values |
| 1200 | outb((unsigned char) intBits, 0x4d0); |
| 1201 | outb((unsigned char) (intBits >> 8), 0x4d1); |
Ronald G. Minnich | cb3f498 | 2003-10-02 18:16:07 +0000 | [diff] [blame] | 1202 | |
Ronald G. Minnich | b56ef07 | 2003-10-15 20:05:11 +0000 | [diff] [blame] | 1203 | /* this seems like an error but is not ... */ |
Ronald G. Minnich | 02fa3b2 | 2004-10-06 17:33:54 +0000 | [diff] [blame] | 1204 | #if 1 |
Ronald G. Minnich | 2cf779d | 2006-09-18 22:50:51 +0000 | [diff] [blame] | 1205 | if (inb(0x4d0) != (intBits & 0xff)) { |
Ronald G. Minnich | cb3f498 | 2003-10-02 18:16:07 +0000 | [diff] [blame] | 1206 | printk_err("%s: lower order bits are wrong: want 0x%x, got 0x%x\n", |
Ronald G. Minnich | 2cf779d | 2006-09-18 22:50:51 +0000 | [diff] [blame] | 1207 | __func__, intBits &0xff, inb(0x4d0)); |
Ronald G. Minnich | cb3f498 | 2003-10-02 18:16:07 +0000 | [diff] [blame] | 1208 | } |
Ronald G. Minnich | 2cf779d | 2006-09-18 22:50:51 +0000 | [diff] [blame] | 1209 | if (inb(0x4d1) != ((intBits >> 8) & 0xff)) { |
Ronald G. Minnich | cb3f498 | 2003-10-02 18:16:07 +0000 | [diff] [blame] | 1210 | printk_err("%s: lower order bits are wrong: want 0x%x, got 0x%x\n", |
Ronald G. Minnich | 2cf779d | 2006-09-18 22:50:51 +0000 | [diff] [blame] | 1211 | __func__, (intBits>>8) &0xff, inb(0x4d1)); |
Ronald G. Minnich | cb3f498 | 2003-10-02 18:16:07 +0000 | [diff] [blame] | 1212 | } |
Ronald G. Minnich | b56ef07 | 2003-10-15 20:05:11 +0000 | [diff] [blame] | 1213 | #endif |
Ronald G. Minnich | 6dd6c685 | 2003-10-02 00:08:42 +0000 | [diff] [blame] | 1214 | } |
| 1215 | |
Ronald G. Minnich | 6dd6c685 | 2003-10-02 00:08:42 +0000 | [diff] [blame] | 1216 | /* |
| 1217 | This function assigns IRQs for all functions contained within |
| 1218 | the indicated device address. If the device does not exist or does |
| 1219 | not require interrupts then this function has no effect. |
| 1220 | |
| 1221 | This function should be called for each PCI slot in your system. |
| 1222 | |
| 1223 | pIntAtoD is an array of IRQ #s that are assigned to PINTA through PINTD of |
| 1224 | this slot. |
| 1225 | The particular irq #s that are passed in depend on the routing inside |
| 1226 | your southbridge and on your motherboard. |
| 1227 | |
| 1228 | -kevinh@ispiri.com |
| 1229 | */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1230 | void pci_assign_irqs(unsigned bus, unsigned slot, |
| 1231 | const unsigned char pIntAtoD[4]) |
Ronald G. Minnich | 6dd6c685 | 2003-10-02 00:08:42 +0000 | [diff] [blame] | 1232 | { |
| 1233 | unsigned functNum; |
| 1234 | device_t pdev; |
| 1235 | unsigned char line; |
| 1236 | unsigned char irq; |
| 1237 | unsigned char readback; |
| 1238 | |
| 1239 | /* Each slot may contain up to eight functions */ |
| 1240 | for (functNum = 0; functNum < 8; functNum++) { |
| 1241 | pdev = dev_find_slot(bus, (slot << 3) + functNum); |
| 1242 | |
| 1243 | if (pdev) { |
| 1244 | line = pci_read_config8(pdev, PCI_INTERRUPT_PIN); |
| 1245 | |
| 1246 | // PCI spec says all other values are reserved |
| 1247 | if ((line >= 1) && (line <= 4)) { |
| 1248 | irq = pIntAtoD[line - 1]; |
| 1249 | |
| 1250 | printk_debug("Assigning IRQ %d to %d:%x.%d\n", \ |
| 1251 | irq, bus, slot, functNum); |
| 1252 | |
| 1253 | pci_write_config8(pdev, PCI_INTERRUPT_LINE,\ |
| 1254 | pIntAtoD[line - 1]); |
| 1255 | |
| 1256 | readback = pci_read_config8(pdev, PCI_INTERRUPT_LINE); |
| 1257 | printk_debug(" Readback = %d\n", readback); |
| 1258 | |
| 1259 | // Change to level triggered |
| 1260 | pci_level_irq(pIntAtoD[line - 1]); |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | } |