| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include <acpi/acpi.h> |
| 9 |
#include <assert.h> |
| 10 |
#include <cbmem.h> |
| 11 |
#include <device/pci_ops.h> |
| 12 |
#include <bootmode.h> |
| 13 |
#include <console/console.h> |
| 14 |
#include <cpu/cpu.h> |
| 15 |
#include <stdlib.h> |
| 16 |
#include <string.h> |
| 17 |
#include <delay.h> |
| 18 |
#include <device/cardbus.h> |
| 19 |
#include <device/device.h> |
| 20 |
#include <device/pci.h> |
| 21 |
#include <device/pci_ids.h> |
| 22 |
#include <device/pcix.h> |
| 23 |
#include <device/pciexp.h> |
| 24 |
#include <lib.h> |
| 25 |
#include <pc80/i8259.h> |
| 26 |
#include <security/vboot/vbnv.h> |
| 27 |
#include <timestamp.h> |
| 28 |
#include <types.h> |
| 29 |
|
| 30 |
u8 pci_moving_config8(struct device *dev, unsigned int reg) |
| 31 |
{ |
| 32 |
u8 value, ones, zeroes; |
| 33 |
|
| 34 |
value = pci_read_config8(dev, reg); |
| 35 |
|
| 36 |
pci_write_config8(dev, reg, 0xff); |
| 37 |
ones = pci_read_config8(dev, reg); |
| 38 |
|
| 39 |
pci_write_config8(dev, reg, 0x00); |
| 40 |
zeroes = pci_read_config8(dev, reg); |
| 41 |
|
| 42 |
pci_write_config8(dev, reg, value); |
| 43 |
|
| 44 |
return ones ^ zeroes; |
| 45 |
} |
| 46 |
|
| 47 |
u16 pci_moving_config16(struct device *dev, unsigned int reg) |
| 48 |
{ |
| 49 |
u16 value, ones, zeroes; |
| 50 |
|
| 51 |
value = pci_read_config16(dev, reg); |
| 52 |
|
| 53 |
pci_write_config16(dev, reg, 0xffff); |
| 54 |
ones = pci_read_config16(dev, reg); |
| 55 |
|
| 56 |
pci_write_config16(dev, reg, 0x0000); |
| 57 |
zeroes = pci_read_config16(dev, reg); |
| 58 |
|
| 59 |
pci_write_config16(dev, reg, value); |
| 60 |
|
| 61 |
return ones ^ zeroes; |
| 62 |
} |
| 63 |
|
| 64 |
u32 pci_moving_config32(struct device *dev, unsigned int reg) |
| 65 |
{ |
| 66 |
u32 value, ones, zeroes; |
| 67 |
|
| 68 |
value = pci_read_config32(dev, reg); |
| 69 |
|
| 70 |
pci_write_config32(dev, reg, 0xffffffff); |
| 71 |
ones = pci_read_config32(dev, reg); |
| 72 |
|
| 73 |
pci_write_config32(dev, reg, 0x00000000); |
| 74 |
zeroes = pci_read_config32(dev, reg); |
| 75 |
|
| 76 |
pci_write_config32(dev, reg, value); |
| 77 |
|
| 78 |
return ones ^ zeroes; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
struct resource *pci_get_resource(struct device *dev, unsigned long index) |
| 89 |
{ |
| 90 |
struct resource *resource; |
| 91 |
unsigned long value, attr; |
| 92 |
resource_t moving, limit; |
| 93 |
|
| 94 |
|
| 95 |
resource = new_resource(dev, index); |
| 96 |
|
| 97 |
|
| 98 |
value = pci_read_config32(dev, index); |
| 99 |
|
| 100 |
|
| 101 |
moving = pci_moving_config32(dev, index); |
| 102 |
|
| 103 |
|
| 104 |
attr = value & ~moving; |
| 105 |
|
| 106 |
|
| 107 |
if (((attr & PCI_BASE_ADDRESS_SPACE_IO) == 0) && |
| 108 |
((attr & PCI_BASE_ADDRESS_MEM_LIMIT_MASK) == |
| 109 |
PCI_BASE_ADDRESS_MEM_LIMIT_64)) { |
| 110 |
|
| 111 |
moving |= |
| 112 |
((resource_t)pci_moving_config32(dev, index + 4)) << 32; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
limit = 0; |
| 122 |
if (moving) { |
| 123 |
resource->size = 1; |
| 124 |
resource->align = resource->gran = 0; |
| 125 |
while (!(moving & resource->size)) { |
| 126 |
resource->size <<= 1; |
| 127 |
resource->align += 1; |
| 128 |
resource->gran += 1; |
| 129 |
} |
| 130 |
resource->limit = limit = moving | (resource->size - 1); |
| 131 |
|
| 132 |
if (pci_base_address_is_memory_space(attr)) { |
| 133 |
|
| 134 |
if (resource->align < 12) |
| 135 |
resource->align = 12; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
if (moving == 0) { |
| 154 |
if (value != 0) { |
| 155 |
printk(BIOS_DEBUG, "%s register %02lx(%08lx), read-only ignoring it\n", |
| 156 |
dev_path(dev), index, value); |
| 157 |
} |
| 158 |
resource->flags = 0; |
| 159 |
} else if (attr & PCI_BASE_ADDRESS_SPACE_IO) { |
| 160 |
|
| 161 |
resource->flags |= IORESOURCE_IO; |
| 162 |
|
| 163 |
resource->limit = 0xffff; |
| 164 |
} else { |
| 165 |
|
| 166 |
attr &= PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
| 167 |
resource->flags |= IORESOURCE_MEM; |
| 168 |
if (attr & PCI_BASE_ADDRESS_MEM_PREFETCH) { |
| 169 |
resource->flags |= IORESOURCE_PREFETCH; |
| 170 |
if (CONFIG(PCIEXP_HOTPLUG_PREFETCH_MEM_ABOVE_4G) |
| 171 |
&& dev_path_hotplug(dev)) |
| 172 |
resource->flags |= IORESOURCE_ABOVE_4G; |
| 173 |
} |
| 174 |
attr &= PCI_BASE_ADDRESS_MEM_LIMIT_MASK; |
| 175 |
if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_32) { |
| 176 |
|
| 177 |
resource->limit = 0xffffffffUL; |
| 178 |
} else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_1M) { |
| 179 |
|
| 180 |
resource->limit = 0x000fffffUL; |
| 181 |
} else if (attr == PCI_BASE_ADDRESS_MEM_LIMIT_64) { |
| 182 |
|
| 183 |
resource->limit = 0xffffffffffffffffULL; |
| 184 |
resource->flags |= IORESOURCE_PCI64; |
| 185 |
} else { |
| 186 |
|
| 187 |
printk(BIOS_ERR, "Broken BAR with value %lx\n", attr); |
| 188 |
printk(BIOS_ERR, " on dev %s at index %02lx\n", |
| 189 |
dev_path(dev), index); |
| 190 |
resource->flags = 0; |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
if (resource->limit > limit) |
| 196 |
resource->limit = limit; |
| 197 |
|
| 198 |
return resource; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
static void pci_get_rom_resource(struct device *dev, unsigned long index) |
| 208 |
{ |
| 209 |
struct resource *resource; |
| 210 |
unsigned long value; |
| 211 |
resource_t moving; |
| 212 |
|
| 213 |
|
| 214 |
resource = new_resource(dev, index); |
| 215 |
|
| 216 |
|
| 217 |
value = pci_read_config32(dev, index); |
| 218 |
|
| 219 |
|
| 220 |
moving = pci_moving_config32(dev, index); |
| 221 |
|
| 222 |
|
| 223 |
moving = moving & ~PCI_ROM_ADDRESS_ENABLE; |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
if (moving) { |
| 232 |
resource->size = 1; |
| 233 |
resource->align = resource->gran = 0; |
| 234 |
while (!(moving & resource->size)) { |
| 235 |
resource->size <<= 1; |
| 236 |
resource->align += 1; |
| 237 |
resource->gran += 1; |
| 238 |
} |
| 239 |
resource->limit = moving | (resource->size - 1); |
| 240 |
resource->flags |= IORESOURCE_MEM | IORESOURCE_READONLY; |
| 241 |
} else { |
| 242 |
if (value != 0) { |
| 243 |
printk(BIOS_DEBUG, "%s register %02lx(%08lx), read-only ignoring it\n", |
| 244 |
dev_path(dev), index, value); |
| 245 |
} |
| 246 |
resource->flags = 0; |
| 247 |
} |
| 248 |
compact_resources(dev); |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
size_t pci_msix_table_size(struct device *dev) |
| 258 |
{ |
| 259 |
const size_t pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
| 260 |
if (!pos) |
| 261 |
return 0; |
| 262 |
|
| 263 |
const u16 control = pci_read_config16(dev, pos + PCI_MSIX_FLAGS); |
| 264 |
return (control & PCI_MSIX_FLAGS_QSIZE) + 1; |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
int pci_msix_table_bar(struct device *dev, u32 *offset, u8 *idx) |
| 277 |
{ |
| 278 |
const size_t pos = pci_find_capability(dev, PCI_CAP_ID_MSIX); |
| 279 |
if (!pos || !offset || !idx) |
| 280 |
return 1; |
| 281 |
|
| 282 |
*offset = pci_read_config32(dev, pos + PCI_MSIX_TABLE); |
| 283 |
*idx = (u8)(*offset & PCI_MSIX_PBA_BIR); |
| 284 |
*offset &= PCI_MSIX_PBA_OFFSET; |
| 285 |
|
| 286 |
return 0; |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
struct msix_entry *pci_msix_get_table(struct device *dev) |
| 297 |
{ |
| 298 |
struct resource *res; |
| 299 |
u32 offset; |
| 300 |
u8 idx; |
| 301 |
|
| 302 |
if (pci_msix_table_bar(dev, &offset, &idx)) |
| 303 |
return NULL; |
| 304 |
|
| 305 |
if (idx > 5) |
| 306 |
return NULL; |
| 307 |
|
| 308 |
res = probe_resource(dev, idx * 4 + PCI_BASE_ADDRESS_0); |
| 309 |
if (!res || !res->base || offset >= res->size) |
| 310 |
return NULL; |
| 311 |
|
| 312 |
if ((res->flags & IORESOURCE_PCI64) && |
| 313 |
(uintptr_t)res->base != res->base) |
| 314 |
return NULL; |
| 315 |
|
| 316 |
return (struct msix_entry *)((uintptr_t)res->base + offset); |
| 317 |
} |
| 318 |
|
| 319 |
static unsigned int get_rebar_offset(const struct device *dev, unsigned long index) |
| 320 |
{ |
| 321 |
uint32_t offset = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_RESIZABLE_BAR, 0); |
| 322 |
if (!offset) |
| 323 |
return 0; |
| 324 |
|
| 325 |
|
| 326 |
const unsigned int find_bar_idx = (index - PCI_BASE_ADDRESS_0) / |
| 327 |
sizeof(uint32_t); |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
const uint32_t rebar_ctrl0 = pci_read_config32(dev, offset + PCI_REBAR_CTRL_OFFSET); |
| 332 |
const unsigned int nbars = (rebar_ctrl0 & PCI_REBAR_CTRL_NBARS_MASK) >> |
| 333 |
PCI_REBAR_CTRL_NBARS_SHIFT; |
| 334 |
|
| 335 |
for (unsigned int i = 0; i < nbars; i++, offset += sizeof(uint64_t)) { |
| 336 |
const uint32_t rebar_ctrl = pci_read_config32( |
| 337 |
dev, offset + PCI_REBAR_CTRL_OFFSET); |
| 338 |
const uint32_t bar_idx = rebar_ctrl & PCI_REBAR_CTRL_IDX_MASK; |
| 339 |
if (bar_idx == find_bar_idx) |
| 340 |
return offset; |
| 341 |
} |
| 342 |
|
| 343 |
return 0; |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
static uint64_t get_rebar_sizes_mask(const struct device *dev, |
| 348 |
unsigned long index) |
| 349 |
{ |
| 350 |
uint64_t size_mask = 0ULL; |
| 351 |
const uint32_t offset = get_rebar_offset(dev, index); |
| 352 |
if (!offset) |
| 353 |
return 0; |
| 354 |
|
| 355 |
|
| 356 |
const uint32_t cap = pci_read_config32(dev, offset + PCI_REBAR_CAP_OFFSET); |
| 357 |
|
| 358 |
size_mask |= ((cap & PCI_REBAR_CAP_SIZE_MASK) >> 4); |
| 359 |
|
| 360 |
|
| 361 |
const uint64_t ctrl = pci_read_config32(dev, offset + PCI_REBAR_CTRL_OFFSET); |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
size_mask |= ((ctrl & PCI_REBAR_CTRL_SIZE_MASK) << 12); |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
return size_mask << 20; |
| 370 |
} |
| 371 |
|
| 372 |
static void pci_store_rebar_size(const struct device *dev, |
| 373 |
const struct resource *resource) |
| 374 |
{ |
| 375 |
const unsigned int num_bits = __fls64(resource->size); |
| 376 |
const uint32_t offset = get_rebar_offset(dev, resource->index); |
| 377 |
if (!offset) |
| 378 |
return; |
| 379 |
|
| 380 |
pci_update_config32(dev, offset + PCI_REBAR_CTRL_OFFSET, |
| 381 |
~PCI_REBAR_CTRL_SIZE_MASK, |
| 382 |
num_bits << PCI_REBAR_CTRL_SIZE_SHIFT); |
| 383 |
} |
| 384 |
|
| 385 |
static void configure_adjustable_base(const struct device *dev, |
| 386 |
unsigned long index, |
| 387 |
struct resource *res) |
| 388 |
{ |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
const uint64_t size_mask = get_rebar_sizes_mask(dev, index); |
| 407 |
if (!size_mask) |
| 408 |
return; |
| 409 |
|
| 410 |
int max_requested_bits = __fls64(size_mask); |
| 411 |
if (max_requested_bits > CONFIG_PCIEXP_DEFAULT_MAX_RESIZABLE_BAR_BITS) { |
| 412 |
printk(BIOS_WARNING, "Device %s requests a BAR with" |
| 413 |
" %u bits of address space, which coreboot is not" |
| 414 |
" configured to hand out, truncating to %u bits\n", |
| 415 |
dev_path(dev), max_requested_bits, |
| 416 |
CONFIG_PCIEXP_DEFAULT_MAX_RESIZABLE_BAR_BITS); |
| 417 |
max_requested_bits = CONFIG_PCIEXP_DEFAULT_MAX_RESIZABLE_BAR_BITS; |
| 418 |
} |
| 419 |
|
| 420 |
if (!(res->flags & IORESOURCE_PCI64) && max_requested_bits > 32) { |
| 421 |
printk(BIOS_ERR, "Resizable BAR requested" |
| 422 |
" above 32 bits, but PCI function reported a" |
| 423 |
" 32-bit BAR."); |
| 424 |
return; |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
res->size = 1ULL << max_requested_bits; |
| 429 |
res->align = max_requested_bits; |
| 430 |
res->gran = max_requested_bits; |
| 431 |
res->limit = (res->flags & IORESOURCE_PCI64) ? UINT64_MAX : UINT32_MAX; |
| 432 |
res->flags |= (res->flags & IORESOURCE_PCI64) ? |
| 433 |
IORESOURCE_PCIE_RESIZABLE_BAR | IORESOURCE_ABOVE_4G : |
| 434 |
IORESOURCE_PCIE_RESIZABLE_BAR; |
| 435 |
|
| 436 |
printk(BIOS_INFO, "%s: Adjusting resource index %lu: base: %llx size: %llx " |
| 437 |
"align: %d gran: %d limit: %llx\n", |
| 438 |
dev_path(dev), res->index, res->base, res->size, |
| 439 |
res->align, res->gran, res->limit); |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
static void pci_read_bases(struct device *dev, unsigned int howmany) |
| 449 |
{ |
| 450 |
unsigned long index; |
| 451 |
|
| 452 |
for (index = PCI_BASE_ADDRESS_0; |
| 453 |
(index < PCI_BASE_ADDRESS_0 + (howmany << 2));) { |
| 454 |
struct resource *resource; |
| 455 |
resource = pci_get_resource(dev, index); |
| 456 |
|
| 457 |
const bool is_pcie = pci_find_capability(dev, PCI_CAP_ID_PCIE) != 0; |
| 458 |
if (CONFIG(PCIEXP_SUPPORT_RESIZABLE_BARS) && is_pcie) |
| 459 |
configure_adjustable_base(dev, index, resource); |
| 460 |
|
| 461 |
index += (resource->flags & IORESOURCE_PCI64) ? 8 : 4; |
| 462 |
} |
| 463 |
|
| 464 |
compact_resources(dev); |
| 465 |
} |
| 466 |
|
| 467 |
static void pci_record_bridge_resource(struct device *dev, resource_t moving, |
| 468 |
unsigned int index, unsigned long type) |
| 469 |
{ |
| 470 |
struct resource *resource; |
| 471 |
unsigned long gran; |
| 472 |
resource_t step; |
| 473 |
|
| 474 |
resource = NULL; |
| 475 |
|
| 476 |
if (!moving) |
| 477 |
return; |
| 478 |
|
| 479 |
|
| 480 |
resource = new_resource(dev, index); |
| 481 |
resource->size = 0; |
| 482 |
gran = 0; |
| 483 |
step = 1; |
| 484 |
while ((moving & step) == 0) { |
| 485 |
gran += 1; |
| 486 |
step <<= 1; |
| 487 |
} |
| 488 |
resource->gran = gran; |
| 489 |
resource->align = gran; |
| 490 |
resource->limit = moving | (step - 1); |
| 491 |
resource->flags = type | IORESOURCE_PCI_BRIDGE | |
| 492 |
IORESOURCE_BRIDGE; |
| 493 |
} |
| 494 |
|
| 495 |
static void pci_bridge_read_bases(struct device *dev) |
| 496 |
{ |
| 497 |
resource_t moving_base, moving_limit, moving; |
| 498 |
|
| 499 |
|
| 500 |
moving_base = ((u32)pci_moving_config8(dev, PCI_IO_BASE)) << 8; |
| 501 |
moving_base |= |
| 502 |
((u32)pci_moving_config16(dev, PCI_IO_BASE_UPPER16)) << 16; |
| 503 |
|
| 504 |
moving_limit = ((u32)pci_moving_config8(dev, PCI_IO_LIMIT)) << 8; |
| 505 |
moving_limit |= |
| 506 |
((u32)pci_moving_config16(dev, PCI_IO_LIMIT_UPPER16)) << 16; |
| 507 |
|
| 508 |
moving = moving_base & moving_limit; |
| 509 |
|
| 510 |
|
| 511 |
pci_record_bridge_resource(dev, moving, PCI_IO_BASE, IORESOURCE_IO); |
| 512 |
|
| 513 |
|
| 514 |
moving_base = |
| 515 |
((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_BASE)) << 16; |
| 516 |
moving_base |= |
| 517 |
((resource_t)pci_moving_config32(dev, PCI_PREF_BASE_UPPER32)) << 32; |
| 518 |
|
| 519 |
moving_limit = |
| 520 |
((resource_t)pci_moving_config16(dev, PCI_PREF_MEMORY_LIMIT)) << 16; |
| 521 |
moving_limit |= |
| 522 |
((resource_t)pci_moving_config32(dev, PCI_PREF_LIMIT_UPPER32)) << 32; |
| 523 |
|
| 524 |
moving = moving_base & moving_limit; |
| 525 |
|
| 526 |
pci_record_bridge_resource(dev, moving, PCI_PREF_MEMORY_BASE, |
| 527 |
IORESOURCE_MEM | IORESOURCE_PREFETCH); |
| 528 |
|
| 529 |
|
| 530 |
moving_base = ((u32)pci_moving_config16(dev, PCI_MEMORY_BASE)) << 16; |
| 531 |
moving_limit = ((u32)pci_moving_config16(dev, PCI_MEMORY_LIMIT)) << 16; |
| 532 |
|
| 533 |
moving = moving_base & moving_limit; |
| 534 |
|
| 535 |
|
| 536 |
pci_record_bridge_resource(dev, moving, PCI_MEMORY_BASE, |
| 537 |
IORESOURCE_MEM); |
| 538 |
|
| 539 |
compact_resources(dev); |
| 540 |
} |
| 541 |
|
| 542 |
void pci_dev_read_resources(struct device *dev) |
| 543 |
{ |
| 544 |
pci_read_bases(dev, 6); |
| 545 |
pci_get_rom_resource(dev, PCI_ROM_ADDRESS); |
| 546 |
|
| 547 |
#if CONFIG(PCIEXP_PLUGIN_SUPPORT) |
| 548 |
|
| 549 |
pciexp_dev_read_resources(dev); |
| 550 |
#endif |
| 551 |
} |
| 552 |
|
| 553 |
void pci_bus_read_resources(struct device *dev) |
| 554 |
{ |
| 555 |
pci_bridge_read_bases(dev); |
| 556 |
pci_read_bases(dev, 2); |
| 557 |
pci_get_rom_resource(dev, PCI_ROM_ADDRESS1); |
| 558 |
} |
| 559 |
|
| 560 |
void pci_domain_read_resources(struct device *dev) |
| 561 |
{ |
| 562 |
struct resource *res; |
| 563 |
|
| 564 |
|
| 565 |
res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
| 566 |
res->limit = 0xffffUL; |
| 567 |
res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 568 |
IORESOURCE_ASSIGNED; |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
| 578 |
res->base = cbmem_top(); |
| 579 |
res->limit = CONFIG_DOMAIN_RESOURCE_32BIT_LIMIT - 1; |
| 580 |
res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 581 |
IORESOURCE_ASSIGNED; |
| 582 |
|
| 583 |
|
| 584 |
res = new_resource(dev, IOINDEX_SUBTRACTIVE(2, 0)); |
| 585 |
res->base = 4ULL * GiB; |
| 586 |
res->limit = (1ULL << soc_phys_address_size()) - 1; |
| 587 |
res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 588 |
IORESOURCE_ASSIGNED; |
| 589 |
} |
| 590 |
|
| 591 |
void pci_domain_set_resources(struct device *dev) |
| 592 |
{ |
| 593 |
assign_resources(dev->downstream); |
| 594 |
} |
| 595 |
|
| 596 |
static void pci_store_resource(const struct device *const dev, |
| 597 |
const struct resource *const resource) |
| 598 |
{ |
| 599 |
unsigned long base_lo, base_hi; |
| 600 |
|
| 601 |
base_lo = resource->base & 0xffffffff; |
| 602 |
base_hi = (resource->base >> 32) & 0xffffffff; |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
if (resource->flags & IORESOURCE_IO) |
| 609 |
base_lo |= PCI_BASE_ADDRESS_SPACE_IO; |
| 610 |
|
| 611 |
pci_write_config32(dev, resource->index, base_lo); |
| 612 |
if (resource->flags & IORESOURCE_PCI64) |
| 613 |
pci_write_config32(dev, resource->index + 4, base_hi); |
| 614 |
} |
| 615 |
|
| 616 |
static void pci_store_bridge_resource(const struct device *const dev, |
| 617 |
struct resource *const resource) |
| 618 |
{ |
| 619 |
resource_t base, end; |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
if (resource->size == 0) { |
| 627 |
base = resource->limit; |
| 628 |
end = resource->limit - (1 << resource->gran); |
| 629 |
resource->base = base; |
| 630 |
} else { |
| 631 |
base = resource->base; |
| 632 |
end = resource_end(resource); |
| 633 |
} |
| 634 |
|
| 635 |
if (resource->index == PCI_IO_BASE) { |
| 636 |
|
| 637 |
pci_write_config8(dev, PCI_IO_BASE, base >> 8); |
| 638 |
pci_write_config16(dev, PCI_IO_BASE_UPPER16, base >> 16); |
| 639 |
pci_write_config8(dev, PCI_IO_LIMIT, end >> 8); |
| 640 |
pci_write_config16(dev, PCI_IO_LIMIT_UPPER16, end >> 16); |
| 641 |
} else if (resource->index == PCI_MEMORY_BASE) { |
| 642 |
|
| 643 |
pci_write_config16(dev, PCI_MEMORY_BASE, base >> 16); |
| 644 |
pci_write_config16(dev, PCI_MEMORY_LIMIT, end >> 16); |
| 645 |
} else if (resource->index == PCI_PREF_MEMORY_BASE) { |
| 646 |
|
| 647 |
pci_write_config16(dev, PCI_PREF_MEMORY_BASE, base >> 16); |
| 648 |
pci_write_config32(dev, PCI_PREF_BASE_UPPER32, base >> 32); |
| 649 |
pci_write_config16(dev, PCI_PREF_MEMORY_LIMIT, end >> 16); |
| 650 |
pci_write_config32(dev, PCI_PREF_LIMIT_UPPER32, end >> 32); |
| 651 |
} else { |
| 652 |
|
| 653 |
resource->flags &= ~IORESOURCE_STORED; |
| 654 |
printk(BIOS_ERR, "invalid resource->index %lx\n", resource->index); |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
static void pci_set_resource(struct device *dev, struct resource *resource) |
| 659 |
{ |
| 660 |
|
| 661 |
if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
| 662 |
if (resource->flags & IORESOURCE_BRIDGE) { |
| 663 |
|
| 664 |
|
| 665 |
resource->size = 0; |
| 666 |
} else { |
| 667 |
printk(BIOS_ERR, "%s %02lx %s size: 0x%010llx not assigned\n", |
| 668 |
dev_path(dev), resource->index, |
| 669 |
resource_type(resource), resource->size); |
| 670 |
return; |
| 671 |
} |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
if (resource->flags & IORESOURCE_FIXED) |
| 676 |
return; |
| 677 |
|
| 678 |
|
| 679 |
if (resource->flags & IORESOURCE_STORED) |
| 680 |
return; |
| 681 |
|
| 682 |
|
| 683 |
if (resource->flags & IORESOURCE_SUBTRACTIVE) |
| 684 |
return; |
| 685 |
|
| 686 |
|
| 687 |
if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO))) |
| 688 |
return; |
| 689 |
|
| 690 |
|
| 691 |
if (resource->size) { |
| 692 |
if (resource->flags & IORESOURCE_MEM) |
| 693 |
dev->command |= PCI_COMMAND_MEMORY; |
| 694 |
if (resource->flags & IORESOURCE_IO) |
| 695 |
dev->command |= PCI_COMMAND_IO; |
| 696 |
if (resource->flags & IORESOURCE_PCI_BRIDGE && |
| 697 |
CONFIG(PCI_SET_BUS_MASTER_PCI_BRIDGES)) |
| 698 |
dev->command |= PCI_COMMAND_MASTER; |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
resource->flags |= IORESOURCE_STORED; |
| 703 |
|
| 704 |
if (!(resource->flags & IORESOURCE_PCI_BRIDGE)) { |
| 705 |
if (CONFIG(PCIEXP_SUPPORT_RESIZABLE_BARS) && |
| 706 |
(resource->flags & IORESOURCE_PCIE_RESIZABLE_BAR)) |
| 707 |
pci_store_rebar_size(dev, resource); |
| 708 |
|
| 709 |
pci_store_resource(dev, resource); |
| 710 |
|
| 711 |
} else { |
| 712 |
pci_store_bridge_resource(dev, resource); |
| 713 |
} |
| 714 |
|
| 715 |
report_resource_stored(dev, resource, ""); |
| 716 |
} |
| 717 |
|
| 718 |
void pci_dev_set_resources(struct device *dev) |
| 719 |
{ |
| 720 |
struct resource *res; |
| 721 |
u8 line; |
| 722 |
|
| 723 |
for (res = dev->resource_list; res; res = res->next) |
| 724 |
pci_set_resource(dev, res); |
| 725 |
|
| 726 |
if (dev->downstream && dev->downstream->children) |
| 727 |
assign_resources(dev->downstream); |
| 728 |
|
| 729 |
|
| 730 |
pci_write_config8(dev, PCI_LATENCY_TIMER, 0x40); |
| 731 |
|
| 732 |
|
| 733 |
if ((dev->hdr_type & 0x7f) == PCI_HEADER_TYPE_BRIDGE) |
| 734 |
pci_write_config8(dev, PCI_SEC_LATENCY_TIMER, 0x40); |
| 735 |
|
| 736 |
|
| 737 |
line = pci_read_config8(dev, PCI_INTERRUPT_PIN); |
| 738 |
if (line) |
| 739 |
pci_write_config8(dev, PCI_INTERRUPT_LINE, 0); |
| 740 |
|
| 741 |
|
| 742 |
pci_write_config8(dev, PCI_CACHE_LINE_SIZE, 64 >> 2); |
| 743 |
} |
| 744 |
|
| 745 |
void pci_dev_enable_resources(struct device *dev) |
| 746 |
{ |
| 747 |
const struct pci_operations *ops = NULL; |
| 748 |
u16 command; |
| 749 |
|
| 750 |
|
| 751 |
if (dev->ops) |
| 752 |
ops = dev->ops->ops_pci; |
| 753 |
if (dev->on_mainboard && ops && ops->set_subsystem) { |
| 754 |
if (CONFIG_SUBSYSTEM_VENDOR_ID) |
| 755 |
dev->subsystem_vendor = CONFIG_SUBSYSTEM_VENDOR_ID; |
| 756 |
else if (!dev->subsystem_vendor) |
| 757 |
dev->subsystem_vendor = pci_read_config16(dev, |
| 758 |
PCI_VENDOR_ID); |
| 759 |
if (CONFIG_SUBSYSTEM_DEVICE_ID) |
| 760 |
dev->subsystem_device = CONFIG_SUBSYSTEM_DEVICE_ID; |
| 761 |
else if (!dev->subsystem_device) |
| 762 |
dev->subsystem_device = pci_read_config16(dev, |
| 763 |
PCI_DEVICE_ID); |
| 764 |
|
| 765 |
printk(BIOS_DEBUG, "%s subsystem <- %04x/%04x\n", |
| 766 |
dev_path(dev), dev->subsystem_vendor, |
| 767 |
dev->subsystem_device); |
| 768 |
ops->set_subsystem(dev, dev->subsystem_vendor, |
| 769 |
dev->subsystem_device); |
| 770 |
} |
| 771 |
command = pci_read_config16(dev, PCI_COMMAND); |
| 772 |
command |= dev->command; |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
printk(BIOS_DEBUG, "%s cmd <- %02x\n", dev_path(dev), command); |
| 779 |
pci_write_config16(dev, PCI_COMMAND, command); |
| 780 |
} |
| 781 |
|
| 782 |
void pci_bus_enable_resources(struct device *dev) |
| 783 |
{ |
| 784 |
u16 ctrl; |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
if (dev->downstream->bridge_ctrl & PCI_BRIDGE_CTL_VGA) |
| 791 |
dev->command |= PCI_COMMAND_IO; |
| 792 |
ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL); |
| 793 |
ctrl |= dev->downstream->bridge_ctrl; |
| 794 |
ctrl |= (PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR); |
| 795 |
printk(BIOS_DEBUG, "%s bridge ctrl <- %04x\n", dev_path(dev), ctrl); |
| 796 |
pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl); |
| 797 |
|
| 798 |
pci_dev_enable_resources(dev); |
| 799 |
} |
| 800 |
|
| 801 |
void pci_bus_reset(struct bus *bus) |
| 802 |
{ |
| 803 |
u16 ctl; |
| 804 |
|
| 805 |
ctl = pci_read_config16(bus->dev, PCI_BRIDGE_CONTROL); |
| 806 |
ctl |= PCI_BRIDGE_CTL_BUS_RESET; |
| 807 |
pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, ctl); |
| 808 |
mdelay(10); |
| 809 |
|
| 810 |
ctl &= ~PCI_BRIDGE_CTL_BUS_RESET; |
| 811 |
pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, ctl); |
| 812 |
delay(1); |
| 813 |
} |
| 814 |
|
| 815 |
void pci_dev_set_subsystem(struct device *dev, unsigned int vendor, |
| 816 |
unsigned int device) |
| 817 |
{ |
| 818 |
uint8_t offset; |
| 819 |
|
| 820 |
|
| 821 |
switch (dev->hdr_type & 0x7f) { |
| 822 |
case PCI_HEADER_TYPE_NORMAL: |
| 823 |
offset = PCI_SUBSYSTEM_VENDOR_ID; |
| 824 |
break; |
| 825 |
case PCI_HEADER_TYPE_BRIDGE: |
| 826 |
offset = pci_find_capability(dev, PCI_CAP_ID_SSVID); |
| 827 |
if (!offset) |
| 828 |
return; |
| 829 |
offset += 4; |
| 830 |
break; |
| 831 |
case PCI_HEADER_TYPE_CARDBUS: |
| 832 |
offset = PCI_CB_SUBSYSTEM_VENDOR_ID; |
| 833 |
break; |
| 834 |
default: |
| 835 |
return; |
| 836 |
} |
| 837 |
|
| 838 |
if (!vendor || !device) { |
| 839 |
pci_write_config32(dev, offset, |
| 840 |
pci_read_config32(dev, PCI_VENDOR_ID)); |
| 841 |
} else { |
| 842 |
pci_write_config32(dev, offset, |
| 843 |
((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 844 |
} |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
void pci_dev_init(struct device *dev) |
| 849 |
{ |
| 850 |
if (CONFIG(VGA_ROM_RUN)) |
| 851 |
pci_rom_run(dev); |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
struct pci_operations pci_dev_ops_pci = { |
| 856 |
.set_subsystem = pci_dev_set_subsystem, |
| 857 |
}; |
| 858 |
|
| 859 |
struct device_operations default_pci_ops_dev = { |
| 860 |
.read_resources = pci_dev_read_resources, |
| 861 |
.set_resources = pci_dev_set_resources, |
| 862 |
.enable_resources = pci_dev_enable_resources, |
| 863 |
#if CONFIG(HAVE_ACPI_TABLES) |
| 864 |
.write_acpi_tables = pci_rom_write_acpi_tables, |
| 865 |
.acpi_fill_ssdt = pci_rom_ssdt, |
| 866 |
#endif |
| 867 |
.init = pci_dev_init, |
| 868 |
.ops_pci = &pci_dev_ops_pci, |
| 869 |
}; |
| 870 |
|
| 871 |
|
| 872 |
struct device_operations default_pci_ops_bus = { |
| 873 |
.read_resources = pci_bus_read_resources, |
| 874 |
.set_resources = pci_dev_set_resources, |
| 875 |
.enable_resources = pci_bus_enable_resources, |
| 876 |
.scan_bus = pci_scan_bridge, |
| 877 |
.reset_bus = pci_bus_reset, |
| 878 |
}; |
| 879 |
|
| 880 |
|
| 881 |
static struct device_operations default_hidden_pci_ops_dev = { |
| 882 |
.read_resources = noop_read_resources, |
| 883 |
.set_resources = noop_set_resources, |
| 884 |
.scan_bus = scan_static_bus, |
| 885 |
}; |
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
static void pci_bridge_vga_compat(struct bus *const bus) |
| 901 |
{ |
| 902 |
uint16_t bridge_ctrl; |
| 903 |
|
| 904 |
bridge_ctrl = pci_read_config16(bus->dev, PCI_BRIDGE_CONTROL); |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
bridge_ctrl &= ~PCI_BRIDGE_CTL_VGA; |
| 909 |
pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, bridge_ctrl); |
| 910 |
|
| 911 |
|
| 912 |
bus->no_vga16 |= bus->dev->upstream->no_vga16; |
| 913 |
if (bus->no_vga16) |
| 914 |
return; |
| 915 |
|
| 916 |
|
| 917 |
bridge_ctrl |= PCI_BRIDGE_CTL_VGA16; |
| 918 |
pci_write_config16(bus->dev, PCI_BRIDGE_CONTROL, bridge_ctrl); |
| 919 |
bridge_ctrl = pci_read_config16(bus->dev, PCI_BRIDGE_CONTROL); |
| 920 |
|
| 921 |
bus->no_vga16 = !(bridge_ctrl & PCI_BRIDGE_CTL_VGA16); |
| 922 |
} |
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
static struct device_operations *get_pci_bridge_ops(struct device *dev) |
| 939 |
{ |
| 940 |
#if CONFIG(PCIX_PLUGIN_SUPPORT) |
| 941 |
unsigned int pcixpos; |
| 942 |
pcixpos = pci_find_capability(dev, PCI_CAP_ID_PCIX); |
| 943 |
if (pcixpos) { |
| 944 |
printk(BIOS_DEBUG, "%s subordinate bus PCI-X\n", dev_path(dev)); |
| 945 |
return &default_pcix_ops_bus; |
| 946 |
} |
| 947 |
#endif |
| 948 |
#if CONFIG(PCIEXP_PLUGIN_SUPPORT) |
| 949 |
unsigned int pciexpos; |
| 950 |
pciexpos = pci_find_capability(dev, PCI_CAP_ID_PCIE); |
| 951 |
if (pciexpos) { |
| 952 |
u16 flags; |
| 953 |
flags = pci_read_config16(dev, pciexpos + PCI_EXP_FLAGS); |
| 954 |
switch ((flags & PCI_EXP_FLAGS_TYPE) >> 4) { |
| 955 |
case PCI_EXP_TYPE_ROOT_PORT: |
| 956 |
case PCI_EXP_TYPE_UPSTREAM: |
| 957 |
case PCI_EXP_TYPE_DOWNSTREAM: |
| 958 |
printk(BIOS_DEBUG, "%s subordinate bus PCI Express\n", |
| 959 |
dev_path(dev)); |
| 960 |
if (CONFIG(PCIEXP_HOTPLUG)) { |
| 961 |
u16 sltcap; |
| 962 |
sltcap = pci_read_config16(dev, pciexpos + PCI_EXP_SLTCAP); |
| 963 |
if (sltcap & PCI_EXP_SLTCAP_HPC) { |
| 964 |
printk(BIOS_DEBUG, "%s hot-plug capable\n", |
| 965 |
dev_path(dev)); |
| 966 |
return &default_pciexp_hotplug_ops_bus; |
| 967 |
} |
| 968 |
} |
| 969 |
return &default_pciexp_ops_bus; |
| 970 |
case PCI_EXP_TYPE_PCI_BRIDGE: |
| 971 |
printk(BIOS_DEBUG, "%s subordinate PCI\n", |
| 972 |
dev_path(dev)); |
| 973 |
return &default_pci_ops_bus; |
| 974 |
default: |
| 975 |
break; |
| 976 |
} |
| 977 |
} |
| 978 |
#endif |
| 979 |
return &default_pci_ops_bus; |
| 980 |
} |
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
static int device_id_match(struct pci_driver *driver, unsigned short device_id) |
| 992 |
{ |
| 993 |
if (driver->devices) { |
| 994 |
unsigned short check_id; |
| 995 |
const unsigned short *device_list = driver->devices; |
| 996 |
while ((check_id = *device_list++) != 0) |
| 997 |
if (check_id == device_id) |
| 998 |
return 1; |
| 999 |
} |
| 1000 |
|
| 1001 |
return (driver->device == device_id); |
| 1002 |
} |
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
static void set_pci_ops(struct device *dev) |
| 1014 |
{ |
| 1015 |
struct pci_driver *driver; |
| 1016 |
|
| 1017 |
if (dev->ops) |
| 1018 |
return; |
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
for (driver = &_pci_drivers[0]; driver != &_epci_drivers[0]; driver++) { |
| 1025 |
if ((driver->vendor == dev->vendor) && |
| 1026 |
device_id_match(driver, dev->device)) { |
| 1027 |
dev->ops = (struct device_operations *)driver->ops; |
| 1028 |
break; |
| 1029 |
} |
| 1030 |
} |
| 1031 |
|
| 1032 |
if (dev->ops) { |
| 1033 |
printk(BIOS_SPEW, "%s [%04x/%04x] %sops\n", dev_path(dev), |
| 1034 |
driver->vendor, driver->device, (driver->ops->scan_bus ? "bus " : "")); |
| 1035 |
return; |
| 1036 |
} |
| 1037 |
|
| 1038 |
|
| 1039 |
switch (dev->hdr_type & 0x7f) { |
| 1040 |
case PCI_HEADER_TYPE_NORMAL: |
| 1041 |
if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) |
| 1042 |
goto bad; |
| 1043 |
dev->ops = &default_pci_ops_dev; |
| 1044 |
break; |
| 1045 |
case PCI_HEADER_TYPE_BRIDGE: |
| 1046 |
if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI) |
| 1047 |
goto bad; |
| 1048 |
dev->ops = get_pci_bridge_ops(dev); |
| 1049 |
break; |
| 1050 |
#if CONFIG(CARDBUS_PLUGIN_SUPPORT) |
| 1051 |
case PCI_HEADER_TYPE_CARDBUS: |
| 1052 |
dev->ops = &default_cardbus_ops_bus; |
| 1053 |
break; |
| 1054 |
#endif |
| 1055 |
default: |
| 1056 |
bad: |
| 1057 |
if (dev->enabled) { |
| 1058 |
printk(BIOS_ERR, |
| 1059 |
"%s [%04x/%04x/%06x] has unknown header type %02x, ignoring.\n", |
| 1060 |
dev_path(dev), dev->vendor, dev->device, |
| 1061 |
dev->class >> 8, dev->hdr_type); |
| 1062 |
} |
| 1063 |
} |
| 1064 |
} |
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
static struct device *pci_scan_get_dev(struct bus *bus, unsigned int devfn) |
| 1079 |
{ |
| 1080 |
struct device *dev, **prev; |
| 1081 |
|
| 1082 |
prev = &bus->children; |
| 1083 |
for (dev = bus->children; dev; dev = dev->sibling) { |
| 1084 |
if (dev->path.type == DEVICE_PATH_PCI && dev->path.pci.devfn == devfn) { |
| 1085 |
|
| 1086 |
*prev = dev->sibling; |
| 1087 |
dev->sibling = NULL; |
| 1088 |
break; |
| 1089 |
} |
| 1090 |
prev = &dev->sibling; |
| 1091 |
} |
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
if (dev) { |
| 1100 |
struct device *child; |
| 1101 |
|
| 1102 |
|
| 1103 |
for (child = bus->children; child && child->sibling;) |
| 1104 |
child = child->sibling; |
| 1105 |
|
| 1106 |
|
| 1107 |
if (child) |
| 1108 |
child->sibling = dev; |
| 1109 |
else |
| 1110 |
bus->children = dev; |
| 1111 |
} |
| 1112 |
|
| 1113 |
return dev; |
| 1114 |
} |
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
struct device *pci_probe_dev(struct device *dev, struct bus *bus, |
| 1128 |
unsigned int devfn) |
| 1129 |
{ |
| 1130 |
u32 id, class; |
| 1131 |
u8 hdr_type; |
| 1132 |
|
| 1133 |
|
| 1134 |
if (!dev) { |
| 1135 |
struct device dummy; |
| 1136 |
|
| 1137 |
dummy.upstream = bus; |
| 1138 |
dummy.path.type = DEVICE_PATH_PCI; |
| 1139 |
dummy.path.pci.devfn = devfn; |
| 1140 |
|
| 1141 |
id = pci_read_config32(&dummy, PCI_VENDOR_ID); |
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
if (id == 0xffffffff) |
| 1147 |
return NULL; |
| 1148 |
|
| 1149 |
if ((id == 0x00000000) || (id == 0x0000ffff) || |
| 1150 |
(id == 0xffff0000)) { |
| 1151 |
printk(BIOS_SPEW, "%s, bad id 0x%x\n", |
| 1152 |
dev_path(&dummy), id); |
| 1153 |
return NULL; |
| 1154 |
} |
| 1155 |
dev = alloc_dev(bus, &dummy.path); |
| 1156 |
} else { |
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
if (dev->chip_ops && dev->chip_ops->enable_dev) |
| 1170 |
dev->chip_ops->enable_dev(dev); |
| 1171 |
|
| 1172 |
|
| 1173 |
id = pci_read_config32(dev, PCI_VENDOR_ID); |
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
if ((id == 0xffffffff) || (id == 0x00000000) || |
| 1183 |
(id == 0x0000ffff) || (id == 0xffff0000)) { |
| 1184 |
if (dev->enabled) { |
| 1185 |
printk(BIOS_INFO, |
| 1186 |
"PCI: Static device %s not found, disabling it.\n", |
| 1187 |
dev_path(dev)); |
| 1188 |
dev->enabled = 0; |
| 1189 |
} |
| 1190 |
return dev; |
| 1191 |
} |
| 1192 |
} |
| 1193 |
|
| 1194 |
|
| 1195 |
hdr_type = pci_read_config8(dev, PCI_HEADER_TYPE); |
| 1196 |
class = pci_read_config32(dev, PCI_CLASS_REVISION); |
| 1197 |
|
| 1198 |
|
| 1199 |
dev->vendor = id & 0xffff; |
| 1200 |
dev->device = (id >> 16) & 0xffff; |
| 1201 |
dev->hdr_type = hdr_type; |
| 1202 |
|
| 1203 |
|
| 1204 |
dev->class = class >> 8; |
| 1205 |
|
| 1206 |
|
| 1207 |
if ((dev->class >> 16) == PCI_BASE_CLASS_SYSTEM && |
| 1208 |
CONFIG(PCI_ALLOW_BUS_MASTER_ANY_DEVICE)) |
| 1209 |
dev->command |= PCI_COMMAND_MASTER; |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
set_pci_ops(dev); |
| 1217 |
|
| 1218 |
|
| 1219 |
if (dev->ops && dev->ops->enable) |
| 1220 |
dev->ops->enable(dev); |
| 1221 |
|
| 1222 |
|
| 1223 |
printk(BIOS_DEBUG, "%s [%04x/%04x] %s%s\n", dev_path(dev), |
| 1224 |
dev->vendor, dev->device, dev->enabled ? "enabled" : "disabled", |
| 1225 |
dev->ops ? "" : " No operations"); |
| 1226 |
|
| 1227 |
return dev; |
| 1228 |
} |
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
unsigned int pci_match_simple_dev(struct device *dev, pci_devfn_t sdev) |
| 1238 |
{ |
| 1239 |
return dev->upstream->secondary == PCI_DEV2BUS(sdev) && |
| 1240 |
dev->upstream->segment_group == PCI_DEV2SEG(sdev) && |
| 1241 |
dev->path.pci.devfn == PCI_DEV2DEVFN(sdev); |
| 1242 |
} |
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
uint16_t pci_find_cap_recursive(const struct device *dev, uint16_t cap) |
| 1254 |
{ |
| 1255 |
assert(dev->upstream); |
| 1256 |
uint16_t pos = pci_find_capability(dev, cap); |
| 1257 |
const struct device *bridge = dev->upstream->dev; |
| 1258 |
while (bridge && (bridge->path.type == DEVICE_PATH_PCI)) { |
| 1259 |
assert(bridge->upstream); |
| 1260 |
if (!pci_find_capability(bridge, cap)) |
| 1261 |
return 0; |
| 1262 |
bridge = bridge->upstream->dev; |
| 1263 |
} |
| 1264 |
return pos; |
| 1265 |
} |
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
bool pci_has_pme_pin(const struct device *dev) |
| 1275 |
{ |
| 1276 |
const uint16_t cap = pci_find_capability(dev, PCI_CAP_ID_PM); |
| 1277 |
if (!cap) |
| 1278 |
return false; |
| 1279 |
|
| 1280 |
const uint16_t pmecap = pci_read_config16(dev, cap + PCI_PM_PMC); |
| 1281 |
|
| 1282 |
return !!(pmecap & PCI_PM_CAP_PME); |
| 1283 |
} |
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
static void pci_scan_hidden_device(struct device *dev) |
| 1303 |
{ |
| 1304 |
if (dev->chip_ops && dev->chip_ops->enable_dev) |
| 1305 |
dev->chip_ops->enable_dev(dev); |
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
if (dev->ops == NULL) |
| 1315 |
dev->ops = &default_hidden_pci_ops_dev; |
| 1316 |
|
| 1317 |
if (dev->ops->enable) |
| 1318 |
dev->ops->enable(dev); |
| 1319 |
|
| 1320 |
|
| 1321 |
printk(BIOS_DEBUG, "%s [0000/%04x] hidden%s\n", dev_path(dev), |
| 1322 |
dev->device, dev->ops ? "" : " No operations"); |
| 1323 |
} |
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
static bool pci_bus_only_one_child(struct bus *bus) |
| 1333 |
{ |
| 1334 |
struct device *bridge = bus->dev; |
| 1335 |
u16 pcie_pos, pcie_flags_reg; |
| 1336 |
int pcie_type; |
| 1337 |
|
| 1338 |
if (!bridge) |
| 1339 |
return false; |
| 1340 |
|
| 1341 |
if (bridge->path.type != DEVICE_PATH_PCI) |
| 1342 |
return false; |
| 1343 |
|
| 1344 |
pcie_pos = pci_find_capability(bridge, PCI_CAP_ID_PCIE); |
| 1345 |
if (!pcie_pos) |
| 1346 |
return false; |
| 1347 |
|
| 1348 |
pcie_flags_reg = pci_read_config16(bridge, pcie_pos + PCI_EXP_FLAGS); |
| 1349 |
|
| 1350 |
pcie_type = (pcie_flags_reg & PCI_EXP_FLAGS_TYPE) >> 4; |
| 1351 |
|
| 1352 |
return pciexp_is_downstream_port(pcie_type); |
| 1353 |
} |
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
void pci_scan_bus(struct bus *bus, unsigned int min_devfn, |
| 1366 |
unsigned int max_devfn) |
| 1367 |
{ |
| 1368 |
unsigned int devfn; |
| 1369 |
struct device *dev, **prev; |
| 1370 |
int once = 0; |
| 1371 |
|
| 1372 |
printk(BIOS_DEBUG, "PCI: %s for segment group %02x bus %02x\n", __func__, |
| 1373 |
bus->segment_group, bus->secondary); |
| 1374 |
|
| 1375 |
|
| 1376 |
if (max_devfn > 0xff) { |
| 1377 |
printk(BIOS_ERR, "PCI: %s limits devfn %x - devfn %x\n", |
| 1378 |
__func__, min_devfn, max_devfn); |
| 1379 |
printk(BIOS_ERR, "PCI: %s upper limit too big. Using 0xff.\n", __func__); |
| 1380 |
max_devfn=0xff; |
| 1381 |
} |
| 1382 |
|
| 1383 |
post_code(POSTCODE_ENTER_PCI_SCAN_BUS); |
| 1384 |
|
| 1385 |
if (pci_bus_only_one_child(bus)) |
| 1386 |
max_devfn = MIN(max_devfn, 0x07); |
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
for (devfn = min_devfn; devfn <= max_devfn; devfn++) { |
| 1393 |
if (CONFIG(MINIMAL_PCI_SCANNING)) { |
| 1394 |
dev = pcidev_path_behind(bus, devfn); |
| 1395 |
if (!dev || !dev->mandatory) |
| 1396 |
continue; |
| 1397 |
} |
| 1398 |
|
| 1399 |
|
| 1400 |
dev = pci_scan_get_dev(bus, devfn); |
| 1401 |
|
| 1402 |
|
| 1403 |
if (dev && dev->hidden) { |
| 1404 |
pci_scan_hidden_device(dev); |
| 1405 |
|
| 1406 |
|
| 1407 |
continue; |
| 1408 |
} |
| 1409 |
|
| 1410 |
|
| 1411 |
dev = pci_probe_dev(dev, bus, devfn); |
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
if ((PCI_FUNC(devfn) == 0x00) && (!dev |
| 1419 |
|| (dev->enabled && ((dev->hdr_type & 0x80) != 0x80)))) { |
| 1420 |
devfn += 0x07; |
| 1421 |
} |
| 1422 |
} |
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
prev = &bus->children; |
| 1430 |
for (dev = bus->children; dev; dev = dev->sibling) { |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
if (dev->path.type != DEVICE_PATH_PCI) { |
| 1436 |
enable_static_device(dev); |
| 1437 |
continue; |
| 1438 |
} |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
if (dev->vendor != 0 || dev->hidden) { |
| 1446 |
prev = &dev->sibling; |
| 1447 |
continue; |
| 1448 |
} |
| 1449 |
|
| 1450 |
|
| 1451 |
*prev = dev->sibling; |
| 1452 |
|
| 1453 |
if (!once++) |
| 1454 |
printk(BIOS_WARNING, "PCI: Leftover static devices:\n"); |
| 1455 |
printk(BIOS_WARNING, "%s\n", dev_path(dev)); |
| 1456 |
} |
| 1457 |
|
| 1458 |
if (once) |
| 1459 |
printk(BIOS_WARNING, "PCI: Check your devicetree.cb.\n"); |
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
scan_bridges(bus); |
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
post_code(POSTCODE_EXIT_PCI_SCAN_BUS); |
| 1474 |
} |
| 1475 |
|
| 1476 |
typedef enum { |
| 1477 |
PCI_ROUTE_CLOSE, |
| 1478 |
PCI_ROUTE_SCAN, |
| 1479 |
PCI_ROUTE_FINAL, |
| 1480 |
} scan_state; |
| 1481 |
|
| 1482 |
static void pci_bridge_route(struct bus *link, scan_state state) |
| 1483 |
{ |
| 1484 |
struct device *dev = link->dev; |
| 1485 |
struct bus *parent = dev->upstream; |
| 1486 |
uint8_t primary, secondary, subordinate; |
| 1487 |
|
| 1488 |
if (state == PCI_ROUTE_SCAN) { |
| 1489 |
link->secondary = parent->subordinate + 1; |
| 1490 |
link->subordinate = link->secondary + dev->hotplug_buses; |
| 1491 |
link->max_subordinate = parent->max_subordinate |
| 1492 |
? parent->max_subordinate |
| 1493 |
: (PCI_BUSES_PER_SEGMENT_GROUP - 1); |
| 1494 |
link->segment_group = parent->segment_group; |
| 1495 |
} |
| 1496 |
|
| 1497 |
if (link->secondary > link->max_subordinate) |
| 1498 |
die("%s: No more busses available!\n", __func__); |
| 1499 |
|
| 1500 |
|
| 1501 |
if (link->subordinate > link->max_subordinate) { |
| 1502 |
printk(BIOS_WARNING, "%s: Limiting subordinate busses\n", __func__); |
| 1503 |
link->subordinate = link->max_subordinate; |
| 1504 |
} |
| 1505 |
|
| 1506 |
if (state == PCI_ROUTE_CLOSE) { |
| 1507 |
primary = 0; |
| 1508 |
secondary = 0xff; |
| 1509 |
subordinate = 0xfe; |
| 1510 |
} else if (state == PCI_ROUTE_SCAN) { |
| 1511 |
primary = parent->secondary; |
| 1512 |
secondary = link->secondary; |
| 1513 |
subordinate = link->max_subordinate; |
| 1514 |
} else if (state == PCI_ROUTE_FINAL) { |
| 1515 |
primary = parent->secondary; |
| 1516 |
secondary = link->secondary; |
| 1517 |
subordinate = link->subordinate; |
| 1518 |
} else { |
| 1519 |
return; |
| 1520 |
} |
| 1521 |
|
| 1522 |
if (state == PCI_ROUTE_SCAN) { |
| 1523 |
|
| 1524 |
link->bridge_cmd = pci_read_config16(dev, PCI_COMMAND); |
| 1525 |
pci_write_config16(dev, PCI_COMMAND, 0x0000); |
| 1526 |
pci_write_config16(dev, PCI_STATUS, 0xffff); |
| 1527 |
} |
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
pci_write_config8(dev, PCI_PRIMARY_BUS, primary); |
| 1535 |
pci_write_config8(dev, PCI_SECONDARY_BUS, secondary); |
| 1536 |
pci_write_config8(dev, PCI_SUBORDINATE_BUS, subordinate); |
| 1537 |
|
| 1538 |
if (state == PCI_ROUTE_FINAL) { |
| 1539 |
pci_write_config16(dev, PCI_COMMAND, link->bridge_cmd); |
| 1540 |
parent->subordinate = link->subordinate; |
| 1541 |
} |
| 1542 |
} |
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
void do_pci_scan_bridge(struct device *dev, |
| 1556 |
void (*do_scan_bus) (struct bus * bus, |
| 1557 |
unsigned int min_devfn, |
| 1558 |
unsigned int max_devfn)) |
| 1559 |
{ |
| 1560 |
struct bus *bus; |
| 1561 |
|
| 1562 |
printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(dev)); |
| 1563 |
|
| 1564 |
if (dev->downstream == NULL) { |
| 1565 |
struct bus *link; |
| 1566 |
link = malloc(sizeof(*link)); |
| 1567 |
if (link == NULL) |
| 1568 |
die("Couldn't allocate a link!\n"); |
| 1569 |
memset(link, 0, sizeof(*link)); |
| 1570 |
link->dev = dev; |
| 1571 |
dev->downstream = link; |
| 1572 |
} |
| 1573 |
|
| 1574 |
bus = dev->downstream; |
| 1575 |
|
| 1576 |
pci_bridge_vga_compat(bus); |
| 1577 |
|
| 1578 |
pci_bridge_route(bus, PCI_ROUTE_SCAN); |
| 1579 |
|
| 1580 |
do_scan_bus(bus, 0x00, 0xff); |
| 1581 |
|
| 1582 |
pci_bridge_route(bus, PCI_ROUTE_FINAL); |
| 1583 |
} |
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
void pci_scan_bridge(struct device *dev) |
| 1596 |
{ |
| 1597 |
do_pci_scan_bridge(dev, pci_scan_bus); |
| 1598 |
} |
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
void pci_host_bridge_scan_bus(struct device *dev) |
| 1608 |
{ |
| 1609 |
struct bus *link = dev->downstream; |
| 1610 |
pci_scan_bus(link, PCI_DEVFN(0, 0), 0xff); |
| 1611 |
} |
| 1612 |
|
| 1613 |
void pci_dev_disable_bus_master(const struct device *dev) |
| 1614 |
{ |
| 1615 |
pci_update_config16(dev, PCI_COMMAND, ~PCI_COMMAND_MASTER, 0x0); |
| 1616 |
} |
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
const char *pin_to_str(int pin) |
| 1626 |
{ |
| 1627 |
const char *str[5] = { |
| 1628 |
"NO PIN", |
| 1629 |
"PIN A", |
| 1630 |
"PIN B", |
| 1631 |
"PIN C", |
| 1632 |
"PIN D", |
| 1633 |
}; |
| 1634 |
|
| 1635 |
if (pin >= 0 && pin <= 4) |
| 1636 |
return str[pin]; |
| 1637 |
else |
| 1638 |
return "Invalid PIN, not 0 - 4"; |
| 1639 |
} |
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
static int swizzle_irq_pins(struct device *dev, struct device **parent_bridge) |
| 1659 |
{ |
| 1660 |
struct device *parent; |
| 1661 |
struct device *child; |
| 1662 |
uint8_t parent_bus = 0; |
| 1663 |
uint16_t parent_devfn = 0; |
| 1664 |
uint16_t child_devfn = 0; |
| 1665 |
uint8_t swizzled_pin = 0; |
| 1666 |
|
| 1667 |
|
| 1668 |
swizzled_pin = pci_read_config8(dev, PCI_INTERRUPT_PIN) - 1; |
| 1669 |
|
| 1670 |
|
| 1671 |
child = dev; |
| 1672 |
for (parent = child->upstream->dev; parent; parent = parent->upstream->dev) { |
| 1673 |
parent_bus = parent->upstream->secondary; |
| 1674 |
parent_devfn = parent->path.pci.devfn; |
| 1675 |
child_devfn = child->path.pci.devfn; |
| 1676 |
|
| 1677 |
|
| 1678 |
swizzled_pin = (PCI_SLOT(child_devfn) + swizzled_pin) % 4; |
| 1679 |
printk(BIOS_SPEW, "\tWith INT_PIN swizzled to %s\n" |
| 1680 |
"\tAttached to bridge device %01X:%02Xh.%02Xh\n", |
| 1681 |
pin_to_str(swizzled_pin + 1), parent_bus, |
| 1682 |
PCI_SLOT(parent_devfn), PCI_FUNC(parent_devfn)); |
| 1683 |
|
| 1684 |
|
| 1685 |
if (parent_bus > 0) { |
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
child = parent; |
| 1691 |
continue; |
| 1692 |
} else { |
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
*parent_bridge = parent; |
| 1698 |
break; |
| 1699 |
} |
| 1700 |
} |
| 1701 |
|
| 1702 |
|
| 1703 |
return swizzled_pin + 1; |
| 1704 |
} |
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
int get_pci_irq_pins(struct device *dev, struct device **parent_bdg) |
| 1727 |
{ |
| 1728 |
uint8_t bus = 0; |
| 1729 |
uint16_t devfn = 0; |
| 1730 |
uint8_t int_pin = 0; |
| 1731 |
uint8_t target_pin = 0; |
| 1732 |
|
| 1733 |
|
| 1734 |
if (!(dev->enabled && (dev->path.type == DEVICE_PATH_PCI))) |
| 1735 |
return -1; |
| 1736 |
|
| 1737 |
bus = dev->upstream->secondary; |
| 1738 |
devfn = dev->path.pci.devfn; |
| 1739 |
|
| 1740 |
|
| 1741 |
int_pin = pci_read_config8(dev, PCI_INTERRUPT_PIN); |
| 1742 |
if (int_pin < 1 || int_pin > 4) |
| 1743 |
return -1; |
| 1744 |
|
| 1745 |
printk(BIOS_SPEW, "PCI IRQ: Found device %01X:%02X.%02X using %s\n", |
| 1746 |
bus, PCI_SLOT(devfn), PCI_FUNC(devfn), pin_to_str(int_pin)); |
| 1747 |
|
| 1748 |
|
| 1749 |
if (bus) { |
| 1750 |
|
| 1751 |
target_pin = swizzle_irq_pins(dev, parent_bdg); |
| 1752 |
|
| 1753 |
|
| 1754 |
if (parent_bdg == NULL) { |
| 1755 |
printk(BIOS_WARNING, "Could not find parent bridge for this device!\n"); |
| 1756 |
return -2; |
| 1757 |
} |
| 1758 |
} else { |
| 1759 |
target_pin = int_pin; |
| 1760 |
*parent_bdg = dev; |
| 1761 |
} |
| 1762 |
|
| 1763 |
|
| 1764 |
return target_pin; |
| 1765 |
} |
| 1766 |
|
| 1767 |
#if CONFIG(PC80_SYSTEM) |
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
void pci_assign_irqs(struct device *dev, const unsigned char pIntAtoD[4]) |
| 1783 |
{ |
| 1784 |
u8 slot, line, irq; |
| 1785 |
|
| 1786 |
|
| 1787 |
slot = dev->path.pci.devfn >> 3; |
| 1788 |
|
| 1789 |
for (; dev ; dev = dev->sibling) { |
| 1790 |
if (dev->path.pci.devfn >> 3 != slot) |
| 1791 |
break; |
| 1792 |
|
| 1793 |
line = pci_read_config8(dev, PCI_INTERRUPT_PIN); |
| 1794 |
|
| 1795 |
|
| 1796 |
if ((line < 1) || (line > 4)) |
| 1797 |
continue; |
| 1798 |
|
| 1799 |
irq = pIntAtoD[line - 1]; |
| 1800 |
|
| 1801 |
printk(BIOS_DEBUG, "Assigning IRQ %d to %s\n", irq, dev_path(dev)); |
| 1802 |
|
| 1803 |
pci_write_config8(dev, PCI_INTERRUPT_LINE, irq); |
| 1804 |
|
| 1805 |
|
| 1806 |
i8259_configure_irq_trigger(irq, IRQ_LEVEL_TRIGGERED); |
| 1807 |
} |
| 1808 |
} |
| 1809 |
#endif |