Commit 30468f786c127fc027d84c0aec6155e3e59475bb
1 parent
46e50e9d
added PCI bus - added IRQ support for PowerPC bridges - suppressed PREP PCI bios init
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@962 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
210 additions
and
215 deletions
hw/pci.c
| ... | ... | @@ -40,41 +40,42 @@ |
| 40 | 40 | #define PCI_DEVICES_MAX 64 |
| 41 | 41 | #define PCI_IRQ_WORDS ((PCI_DEVICES_MAX + 31) / 32) |
| 42 | 42 | |
| 43 | -typedef struct PCIBridge { | |
| 44 | - uint32_t config_reg; | |
| 45 | - PCIDevice **pci_bus[256]; | |
| 46 | -} PCIBridge; | |
| 43 | +struct PCIBus { | |
| 44 | + int bus_num; | |
| 45 | + int devfn_min; | |
| 46 | + void (*set_irq)(PCIDevice *pci_dev, int irq_num, int level); | |
| 47 | + uint32_t config_reg; /* XXX: suppress */ | |
| 48 | + openpic_t *openpic; /* XXX: suppress */ | |
| 49 | + PCIDevice *devices[256]; | |
| 50 | +}; | |
| 47 | 51 | |
| 48 | -static PCIBridge pci_bridge[3]; | |
| 49 | 52 | target_phys_addr_t pci_mem_base; |
| 50 | 53 | static int pci_irq_index; |
| 51 | 54 | static uint32_t pci_irq_levels[4][PCI_IRQ_WORDS]; |
| 55 | +static PCIBus *first_bus; | |
| 56 | + | |
| 57 | +static PCIBus *pci_register_bus(void) | |
| 58 | +{ | |
| 59 | + PCIBus *bus; | |
| 60 | + bus = qemu_mallocz(sizeof(PCIBus)); | |
| 61 | + first_bus = bus; | |
| 62 | + return bus; | |
| 63 | +} | |
| 52 | 64 | |
| 53 | 65 | /* -1 for devfn means auto assign */ |
| 54 | -PCIDevice *pci_register_device(const char *name, int instance_size, | |
| 55 | - int bus_num, int devfn, | |
| 66 | +PCIDevice *pci_register_device(PCIBus *bus, const char *name, | |
| 67 | + int instance_size, int devfn, | |
| 56 | 68 | PCIConfigReadFunc *config_read, |
| 57 | 69 | PCIConfigWriteFunc *config_write) |
| 58 | 70 | { |
| 59 | - PCIBridge *s = &pci_bridge[0]; | |
| 60 | - PCIDevice *pci_dev, **bus; | |
| 71 | + PCIDevice *pci_dev; | |
| 61 | 72 | |
| 62 | 73 | if (pci_irq_index >= PCI_DEVICES_MAX) |
| 63 | 74 | return NULL; |
| 64 | 75 | |
| 65 | - if (!s->pci_bus[bus_num]) { | |
| 66 | - s->pci_bus[bus_num] = qemu_mallocz(256 * sizeof(PCIDevice *)); | |
| 67 | - if (!s->pci_bus[bus_num]) | |
| 68 | - return NULL; | |
| 69 | - } | |
| 70 | - bus = s->pci_bus[bus_num]; | |
| 71 | 76 | if (devfn < 0) { |
| 72 | - for(devfn = 0 ; devfn < 256; devfn += 8) { | |
| 73 | -#ifdef TARGET_PPC | |
| 74 | - if ((devfn >> 3) < 11) | |
| 75 | - continue; | |
| 76 | -#endif | |
| 77 | - if (!bus[devfn]) | |
| 77 | + for(devfn = bus->devfn_min ; devfn < 256; devfn += 8) { | |
| 78 | + if (!bus->devices[devfn]) | |
| 78 | 79 | goto found; |
| 79 | 80 | } |
| 80 | 81 | return NULL; |
| ... | ... | @@ -83,7 +84,7 @@ PCIDevice *pci_register_device(const char *name, int instance_size, |
| 83 | 84 | pci_dev = qemu_mallocz(instance_size); |
| 84 | 85 | if (!pci_dev) |
| 85 | 86 | return NULL; |
| 86 | - pci_dev->bus_num = bus_num; | |
| 87 | + pci_dev->bus = bus; | |
| 87 | 88 | pci_dev->devfn = devfn; |
| 88 | 89 | pstrcpy(pci_dev->name, sizeof(pci_dev->name), name); |
| 89 | 90 | |
| ... | ... | @@ -94,7 +95,7 @@ PCIDevice *pci_register_device(const char *name, int instance_size, |
| 94 | 95 | pci_dev->config_read = config_read; |
| 95 | 96 | pci_dev->config_write = config_write; |
| 96 | 97 | pci_dev->irq_index = pci_irq_index++; |
| 97 | - bus[devfn] = pci_dev; | |
| 98 | + bus->devices[devfn] = pci_dev; | |
| 98 | 99 | return pci_dev; |
| 99 | 100 | } |
| 100 | 101 | |
| ... | ... | @@ -115,13 +116,13 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num, |
| 115 | 116 | |
| 116 | 117 | static void pci_addr_writel(void* opaque, uint32_t addr, uint32_t val) |
| 117 | 118 | { |
| 118 | - PCIBridge *s = opaque; | |
| 119 | + PCIBus *s = opaque; | |
| 119 | 120 | s->config_reg = val; |
| 120 | 121 | } |
| 121 | 122 | |
| 122 | 123 | static uint32_t pci_addr_readl(void* opaque, uint32_t addr) |
| 123 | 124 | { |
| 124 | - PCIBridge *s = opaque; | |
| 125 | + PCIBus *s = opaque; | |
| 125 | 126 | return s->config_reg; |
| 126 | 127 | } |
| 127 | 128 | |
| ... | ... | @@ -321,9 +322,9 @@ void pci_default_write_config(PCIDevice *d, |
| 321 | 322 | static void pci_data_write(void *opaque, uint32_t addr, |
| 322 | 323 | uint32_t val, int len) |
| 323 | 324 | { |
| 324 | - PCIBridge *s = opaque; | |
| 325 | - PCIDevice **bus, *pci_dev; | |
| 326 | - int config_addr; | |
| 325 | + PCIBus *s = opaque; | |
| 326 | + PCIDevice *pci_dev; | |
| 327 | + int config_addr, bus_num; | |
| 327 | 328 | |
| 328 | 329 | #if defined(DEBUG_PCI) && 0 |
| 329 | 330 | printf("pci_data_write: addr=%08x val=%08x len=%d\n", |
| ... | ... | @@ -335,10 +336,10 @@ static void pci_data_write(void *opaque, uint32_t addr, |
| 335 | 336 | if ((s->config_reg & 0x3) != 0) { |
| 336 | 337 | return; |
| 337 | 338 | } |
| 338 | - bus = s->pci_bus[(s->config_reg >> 16) & 0xff]; | |
| 339 | - if (!bus) | |
| 339 | + bus_num = (s->config_reg >> 16) & 0xff; | |
| 340 | + if (bus_num != 0) | |
| 340 | 341 | return; |
| 341 | - pci_dev = bus[(s->config_reg >> 8) & 0xff]; | |
| 342 | + pci_dev = s->devices[(s->config_reg >> 8) & 0xff]; | |
| 342 | 343 | if (!pci_dev) |
| 343 | 344 | return; |
| 344 | 345 | config_addr = (s->config_reg & 0xfc) | (addr & 3); |
| ... | ... | @@ -352,19 +353,19 @@ static void pci_data_write(void *opaque, uint32_t addr, |
| 352 | 353 | static uint32_t pci_data_read(void *opaque, uint32_t addr, |
| 353 | 354 | int len) |
| 354 | 355 | { |
| 355 | - PCIBridge *s = opaque; | |
| 356 | - PCIDevice **bus, *pci_dev; | |
| 357 | - int config_addr; | |
| 356 | + PCIBus *s = opaque; | |
| 357 | + PCIDevice *pci_dev; | |
| 358 | + int config_addr, bus_num; | |
| 358 | 359 | uint32_t val; |
| 359 | 360 | |
| 360 | 361 | if (!(s->config_reg & (1 << 31))) |
| 361 | 362 | goto fail; |
| 362 | 363 | if ((s->config_reg & 0x3) != 0) |
| 363 | 364 | goto fail; |
| 364 | - bus = s->pci_bus[(s->config_reg >> 16) & 0xff]; | |
| 365 | - if (!bus) | |
| 365 | + bus_num = (s->config_reg >> 16) & 0xff; | |
| 366 | + if (bus_num != 0) | |
| 366 | 367 | goto fail; |
| 367 | - pci_dev = bus[(s->config_reg >> 8) & 0xff]; | |
| 368 | + pci_dev = s->devices[(s->config_reg >> 8) & 0xff]; | |
| 368 | 369 | if (!pci_dev) { |
| 369 | 370 | fail: |
| 370 | 371 | switch(len) { |
| ... | ... | @@ -427,11 +428,16 @@ static uint32_t pci_data_readl(void* opaque, uint32_t addr) |
| 427 | 428 | |
| 428 | 429 | /* i440FX PCI bridge */ |
| 429 | 430 | |
| 430 | -void i440fx_init(void) | |
| 431 | +static void piix3_set_irq(PCIDevice *pci_dev, int irq_num, int level); | |
| 432 | + | |
| 433 | +PCIBus *i440fx_init(void) | |
| 431 | 434 | { |
| 432 | - PCIBridge *s = &pci_bridge[0]; | |
| 435 | + PCIBus *s; | |
| 433 | 436 | PCIDevice *d; |
| 434 | 437 | |
| 438 | + s = pci_register_bus(); | |
| 439 | + s->set_irq = piix3_set_irq; | |
| 440 | + | |
| 435 | 441 | register_ioport_write(0xcf8, 4, 4, pci_addr_writel, s); |
| 436 | 442 | register_ioport_read(0xcf8, 4, 4, pci_addr_readl, s); |
| 437 | 443 | |
| ... | ... | @@ -442,7 +448,7 @@ void i440fx_init(void) |
| 442 | 448 | register_ioport_read(0xcfc, 4, 2, pci_data_readw, s); |
| 443 | 449 | register_ioport_read(0xcfc, 4, 4, pci_data_readl, s); |
| 444 | 450 | |
| 445 | - d = pci_register_device("i440FX", sizeof(PCIDevice), 0, 0, | |
| 451 | + d = pci_register_device(s, "i440FX", sizeof(PCIDevice), 0, | |
| 446 | 452 | NULL, NULL); |
| 447 | 453 | |
| 448 | 454 | d->config[0x00] = 0x86; // vendor_id |
| ... | ... | @@ -453,6 +459,7 @@ void i440fx_init(void) |
| 453 | 459 | d->config[0x0a] = 0x00; // class_sub = host2pci |
| 454 | 460 | d->config[0x0b] = 0x06; // class_base = PCI_bridge |
| 455 | 461 | d->config[0x0e] = 0x00; // header_type |
| 462 | + return s; | |
| 456 | 463 | } |
| 457 | 464 | |
| 458 | 465 | /* PIIX3 PCI to ISA bridge */ |
| ... | ... | @@ -463,6 +470,52 @@ typedef struct PIIX3State { |
| 463 | 470 | |
| 464 | 471 | PIIX3State *piix3_state; |
| 465 | 472 | |
| 473 | +/* return the global irq number corresponding to a given device irq | |
| 474 | + pin. We could also use the bus number to have a more precise | |
| 475 | + mapping. */ | |
| 476 | +static inline int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num) | |
| 477 | +{ | |
| 478 | + int slot_addend; | |
| 479 | + slot_addend = (pci_dev->devfn >> 3); | |
| 480 | + return (irq_num + slot_addend) & 3; | |
| 481 | +} | |
| 482 | + | |
| 483 | +static void piix3_set_irq(PCIDevice *pci_dev, int irq_num, int level) | |
| 484 | +{ | |
| 485 | + int irq_index, shift, pic_irq, pic_level; | |
| 486 | + uint32_t *p; | |
| 487 | + | |
| 488 | + irq_num = pci_slot_get_pirq(pci_dev, irq_num); | |
| 489 | + irq_index = pci_dev->irq_index; | |
| 490 | + p = &pci_irq_levels[irq_num][irq_index >> 5]; | |
| 491 | + shift = (irq_index & 0x1f); | |
| 492 | + *p = (*p & ~(1 << shift)) | (level << shift); | |
| 493 | + | |
| 494 | + /* now we change the pic irq level according to the piix irq mappings */ | |
| 495 | + pic_irq = piix3_state->dev.config[0x60 + irq_num]; | |
| 496 | + if (pic_irq < 16) { | |
| 497 | + /* the pic level is the logical OR of all the PCI irqs mapped | |
| 498 | + to it */ | |
| 499 | + pic_level = 0; | |
| 500 | +#if (PCI_IRQ_WORDS == 2) | |
| 501 | + pic_level = ((pci_irq_levels[irq_num][0] | | |
| 502 | + pci_irq_levels[irq_num][1]) != 0); | |
| 503 | +#else | |
| 504 | + { | |
| 505 | + int i; | |
| 506 | + pic_level = 0; | |
| 507 | + for(i = 0; i < PCI_IRQ_WORDS; i++) { | |
| 508 | + if (pci_irq_levels[irq_num][i]) { | |
| 509 | + pic_level = 1; | |
| 510 | + break; | |
| 511 | + } | |
| 512 | + } | |
| 513 | + } | |
| 514 | +#endif | |
| 515 | + pic_set_irq(pic_irq, pic_level); | |
| 516 | + } | |
| 517 | +} | |
| 518 | + | |
| 466 | 519 | static void piix3_reset(PIIX3State *d) |
| 467 | 520 | { |
| 468 | 521 | uint8_t *pci_conf = d->dev.config; |
| ... | ... | @@ -498,14 +551,13 @@ static void piix3_reset(PIIX3State *d) |
| 498 | 551 | pci_conf[0xae] = 0x00; |
| 499 | 552 | } |
| 500 | 553 | |
| 501 | -void piix3_init(void) | |
| 554 | +void piix3_init(PCIBus *bus) | |
| 502 | 555 | { |
| 503 | 556 | PIIX3State *d; |
| 504 | 557 | uint8_t *pci_conf; |
| 505 | 558 | |
| 506 | - d = (PIIX3State *)pci_register_device("PIIX3", sizeof(PIIX3State), | |
| 507 | - 0, -1, | |
| 508 | - NULL, NULL); | |
| 559 | + d = (PIIX3State *)pci_register_device(bus, "PIIX3", sizeof(PIIX3State), | |
| 560 | + -1, NULL, NULL); | |
| 509 | 561 | piix3_state = d; |
| 510 | 562 | pci_conf = d->dev.config; |
| 511 | 563 | |
| ... | ... | @@ -522,7 +574,7 @@ void piix3_init(void) |
| 522 | 574 | |
| 523 | 575 | /* PREP pci init */ |
| 524 | 576 | |
| 525 | -static inline void set_config(PCIBridge *s, target_phys_addr_t addr) | |
| 577 | +static inline void set_config(PCIBus *s, target_phys_addr_t addr) | |
| 526 | 578 | { |
| 527 | 579 | int devfn, i; |
| 528 | 580 | |
| ... | ... | @@ -536,14 +588,14 @@ static inline void set_config(PCIBridge *s, target_phys_addr_t addr) |
| 536 | 588 | |
| 537 | 589 | static void PPC_PCIIO_writeb (void *opaque, target_phys_addr_t addr, uint32_t val) |
| 538 | 590 | { |
| 539 | - PCIBridge *s = opaque; | |
| 591 | + PCIBus *s = opaque; | |
| 540 | 592 | set_config(s, addr); |
| 541 | 593 | pci_data_write(s, addr, val, 1); |
| 542 | 594 | } |
| 543 | 595 | |
| 544 | 596 | static void PPC_PCIIO_writew (void *opaque, target_phys_addr_t addr, uint32_t val) |
| 545 | 597 | { |
| 546 | - PCIBridge *s = opaque; | |
| 598 | + PCIBus *s = opaque; | |
| 547 | 599 | set_config(s, addr); |
| 548 | 600 | #ifdef TARGET_WORDS_BIGENDIAN |
| 549 | 601 | val = bswap16(val); |
| ... | ... | @@ -553,7 +605,7 @@ static void PPC_PCIIO_writew (void *opaque, target_phys_addr_t addr, uint32_t va |
| 553 | 605 | |
| 554 | 606 | static void PPC_PCIIO_writel (void *opaque, target_phys_addr_t addr, uint32_t val) |
| 555 | 607 | { |
| 556 | - PCIBridge *s = opaque; | |
| 608 | + PCIBus *s = opaque; | |
| 557 | 609 | set_config(s, addr); |
| 558 | 610 | #ifdef TARGET_WORDS_BIGENDIAN |
| 559 | 611 | val = bswap32(val); |
| ... | ... | @@ -563,7 +615,7 @@ static void PPC_PCIIO_writel (void *opaque, target_phys_addr_t addr, uint32_t va |
| 563 | 615 | |
| 564 | 616 | static uint32_t PPC_PCIIO_readb (void *opaque, target_phys_addr_t addr) |
| 565 | 617 | { |
| 566 | - PCIBridge *s = opaque; | |
| 618 | + PCIBus *s = opaque; | |
| 567 | 619 | uint32_t val; |
| 568 | 620 | set_config(s, addr); |
| 569 | 621 | val = pci_data_read(s, addr, 1); |
| ... | ... | @@ -572,7 +624,7 @@ static uint32_t PPC_PCIIO_readb (void *opaque, target_phys_addr_t addr) |
| 572 | 624 | |
| 573 | 625 | static uint32_t PPC_PCIIO_readw (void *opaque, target_phys_addr_t addr) |
| 574 | 626 | { |
| 575 | - PCIBridge *s = opaque; | |
| 627 | + PCIBus *s = opaque; | |
| 576 | 628 | uint32_t val; |
| 577 | 629 | set_config(s, addr); |
| 578 | 630 | val = pci_data_read(s, addr, 2); |
| ... | ... | @@ -584,7 +636,7 @@ static uint32_t PPC_PCIIO_readw (void *opaque, target_phys_addr_t addr) |
| 584 | 636 | |
| 585 | 637 | static uint32_t PPC_PCIIO_readl (void *opaque, target_phys_addr_t addr) |
| 586 | 638 | { |
| 587 | - PCIBridge *s = opaque; | |
| 639 | + PCIBus *s = opaque; | |
| 588 | 640 | uint32_t val; |
| 589 | 641 | set_config(s, addr); |
| 590 | 642 | val = pci_data_read(s, addr, 4); |
| ... | ... | @@ -606,17 +658,27 @@ static CPUReadMemoryFunc *PPC_PCIIO_read[] = { |
| 606 | 658 | &PPC_PCIIO_readl, |
| 607 | 659 | }; |
| 608 | 660 | |
| 609 | -void pci_prep_init(void) | |
| 661 | +static void prep_set_irq(PCIDevice *d, int irq_num, int level) | |
| 662 | +{ | |
| 663 | + /* XXX: we do not simulate the hardware - we rely on the BIOS to | |
| 664 | + set correctly for irq line field */ | |
| 665 | + pic_set_irq(d->config[PCI_INTERRUPT_LINE], level); | |
| 666 | +} | |
| 667 | + | |
| 668 | +PCIBus *pci_prep_init(void) | |
| 610 | 669 | { |
| 611 | - PCIBridge *s = &pci_bridge[0]; | |
| 670 | + PCIBus *s; | |
| 612 | 671 | PCIDevice *d; |
| 613 | 672 | int PPC_io_memory; |
| 614 | 673 | |
| 674 | + s = pci_register_bus(); | |
| 675 | + s->set_irq = prep_set_irq; | |
| 676 | + | |
| 615 | 677 | PPC_io_memory = cpu_register_io_memory(0, PPC_PCIIO_read, |
| 616 | 678 | PPC_PCIIO_write, s); |
| 617 | 679 | cpu_register_physical_memory(0x80800000, 0x00400000, PPC_io_memory); |
| 618 | 680 | |
| 619 | - d = pci_register_device("PREP PCI Bridge", sizeof(PCIDevice), 0, 0, | |
| 681 | + d = pci_register_device(s, "PREP PCI Bridge", sizeof(PCIDevice), 0, | |
| 620 | 682 | NULL, NULL); |
| 621 | 683 | |
| 622 | 684 | /* XXX: put correct IDs */ |
| ... | ... | @@ -628,16 +690,18 @@ void pci_prep_init(void) |
| 628 | 690 | d->config[0x0a] = 0x04; // class_sub = pci2pci |
| 629 | 691 | d->config[0x0b] = 0x06; // class_base = PCI_bridge |
| 630 | 692 | d->config[0x0e] = 0x01; // header_type |
| 693 | + return s; | |
| 631 | 694 | } |
| 632 | 695 | |
| 633 | 696 | |
| 634 | 697 | /* pmac pci init */ |
| 635 | 698 | |
| 699 | +#if 0 | |
| 636 | 700 | /* Grackle PCI host */ |
| 637 | 701 | static void pci_grackle_config_writel (void *opaque, target_phys_addr_t addr, |
| 638 | 702 | uint32_t val) |
| 639 | 703 | { |
| 640 | - PCIBridge *s = opaque; | |
| 704 | + PCIBus *s = opaque; | |
| 641 | 705 | #ifdef TARGET_WORDS_BIGENDIAN |
| 642 | 706 | val = bswap32(val); |
| 643 | 707 | #endif |
| ... | ... | @@ -646,7 +710,7 @@ static void pci_grackle_config_writel (void *opaque, target_phys_addr_t addr, |
| 646 | 710 | |
| 647 | 711 | static uint32_t pci_grackle_config_readl (void *opaque, target_phys_addr_t addr) |
| 648 | 712 | { |
| 649 | - PCIBridge *s = opaque; | |
| 713 | + PCIBus *s = opaque; | |
| 650 | 714 | uint32_t val; |
| 651 | 715 | |
| 652 | 716 | val = s->config_reg; |
| ... | ... | @@ -671,14 +735,14 @@ static CPUReadMemoryFunc *pci_grackle_config_read[] = { |
| 671 | 735 | static void pci_grackle_writeb (void *opaque, target_phys_addr_t addr, |
| 672 | 736 | uint32_t val) |
| 673 | 737 | { |
| 674 | - PCIBridge *s = opaque; | |
| 738 | + PCIBus *s = opaque; | |
| 675 | 739 | pci_data_write(s, addr, val, 1); |
| 676 | 740 | } |
| 677 | 741 | |
| 678 | 742 | static void pci_grackle_writew (void *opaque, target_phys_addr_t addr, |
| 679 | 743 | uint32_t val) |
| 680 | 744 | { |
| 681 | - PCIBridge *s = opaque; | |
| 745 | + PCIBus *s = opaque; | |
| 682 | 746 | #ifdef TARGET_WORDS_BIGENDIAN |
| 683 | 747 | val = bswap16(val); |
| 684 | 748 | #endif |
| ... | ... | @@ -688,7 +752,7 @@ static void pci_grackle_writew (void *opaque, target_phys_addr_t addr, |
| 688 | 752 | static void pci_grackle_writel (void *opaque, target_phys_addr_t addr, |
| 689 | 753 | uint32_t val) |
| 690 | 754 | { |
| 691 | - PCIBridge *s = opaque; | |
| 755 | + PCIBus *s = opaque; | |
| 692 | 756 | #ifdef TARGET_WORDS_BIGENDIAN |
| 693 | 757 | val = bswap32(val); |
| 694 | 758 | #endif |
| ... | ... | @@ -697,7 +761,7 @@ static void pci_grackle_writel (void *opaque, target_phys_addr_t addr, |
| 697 | 761 | |
| 698 | 762 | static uint32_t pci_grackle_readb (void *opaque, target_phys_addr_t addr) |
| 699 | 763 | { |
| 700 | - PCIBridge *s = opaque; | |
| 764 | + PCIBus *s = opaque; | |
| 701 | 765 | uint32_t val; |
| 702 | 766 | val = pci_data_read(s, addr, 1); |
| 703 | 767 | return val; |
| ... | ... | @@ -705,7 +769,7 @@ static uint32_t pci_grackle_readb (void *opaque, target_phys_addr_t addr) |
| 705 | 769 | |
| 706 | 770 | static uint32_t pci_grackle_readw (void *opaque, target_phys_addr_t addr) |
| 707 | 771 | { |
| 708 | - PCIBridge *s = opaque; | |
| 772 | + PCIBus *s = opaque; | |
| 709 | 773 | uint32_t val; |
| 710 | 774 | val = pci_data_read(s, addr, 2); |
| 711 | 775 | #ifdef TARGET_WORDS_BIGENDIAN |
| ... | ... | @@ -716,7 +780,7 @@ static uint32_t pci_grackle_readw (void *opaque, target_phys_addr_t addr) |
| 716 | 780 | |
| 717 | 781 | static uint32_t pci_grackle_readl (void *opaque, target_phys_addr_t addr) |
| 718 | 782 | { |
| 719 | - PCIBridge *s = opaque; | |
| 783 | + PCIBus *s = opaque; | |
| 720 | 784 | uint32_t val; |
| 721 | 785 | |
| 722 | 786 | val = pci_data_read(s, addr, 4); |
| ... | ... | @@ -737,12 +801,13 @@ static CPUReadMemoryFunc *pci_grackle_read[] = { |
| 737 | 801 | &pci_grackle_readw, |
| 738 | 802 | &pci_grackle_readl, |
| 739 | 803 | }; |
| 804 | +#endif | |
| 740 | 805 | |
| 741 | 806 | /* Uninorth PCI host (for all Mac99 and newer machines */ |
| 742 | 807 | static void pci_unin_main_config_writel (void *opaque, target_phys_addr_t addr, |
| 743 | 808 | uint32_t val) |
| 744 | 809 | { |
| 745 | - PCIBridge *s = opaque; | |
| 810 | + PCIBus *s = opaque; | |
| 746 | 811 | int i; |
| 747 | 812 | |
| 748 | 813 | #ifdef TARGET_WORDS_BIGENDIAN |
| ... | ... | @@ -763,7 +828,7 @@ static void pci_unin_main_config_writel (void *opaque, target_phys_addr_t addr, |
| 763 | 828 | static uint32_t pci_unin_main_config_readl (void *opaque, |
| 764 | 829 | target_phys_addr_t addr) |
| 765 | 830 | { |
| 766 | - PCIBridge *s = opaque; | |
| 831 | + PCIBus *s = opaque; | |
| 767 | 832 | uint32_t val; |
| 768 | 833 | int devfn; |
| 769 | 834 | |
| ... | ... | @@ -791,14 +856,14 @@ static CPUReadMemoryFunc *pci_unin_main_config_read[] = { |
| 791 | 856 | static void pci_unin_main_writeb (void *opaque, target_phys_addr_t addr, |
| 792 | 857 | uint32_t val) |
| 793 | 858 | { |
| 794 | - PCIBridge *s = opaque; | |
| 859 | + PCIBus *s = opaque; | |
| 795 | 860 | pci_data_write(s, addr & 7, val, 1); |
| 796 | 861 | } |
| 797 | 862 | |
| 798 | 863 | static void pci_unin_main_writew (void *opaque, target_phys_addr_t addr, |
| 799 | 864 | uint32_t val) |
| 800 | 865 | { |
| 801 | - PCIBridge *s = opaque; | |
| 866 | + PCIBus *s = opaque; | |
| 802 | 867 | #ifdef TARGET_WORDS_BIGENDIAN |
| 803 | 868 | val = bswap16(val); |
| 804 | 869 | #endif |
| ... | ... | @@ -808,7 +873,7 @@ static void pci_unin_main_writew (void *opaque, target_phys_addr_t addr, |
| 808 | 873 | static void pci_unin_main_writel (void *opaque, target_phys_addr_t addr, |
| 809 | 874 | uint32_t val) |
| 810 | 875 | { |
| 811 | - PCIBridge *s = opaque; | |
| 876 | + PCIBus *s = opaque; | |
| 812 | 877 | #ifdef TARGET_WORDS_BIGENDIAN |
| 813 | 878 | val = bswap32(val); |
| 814 | 879 | #endif |
| ... | ... | @@ -817,7 +882,7 @@ static void pci_unin_main_writel (void *opaque, target_phys_addr_t addr, |
| 817 | 882 | |
| 818 | 883 | static uint32_t pci_unin_main_readb (void *opaque, target_phys_addr_t addr) |
| 819 | 884 | { |
| 820 | - PCIBridge *s = opaque; | |
| 885 | + PCIBus *s = opaque; | |
| 821 | 886 | uint32_t val; |
| 822 | 887 | |
| 823 | 888 | val = pci_data_read(s, addr & 7, 1); |
| ... | ... | @@ -827,7 +892,7 @@ static uint32_t pci_unin_main_readb (void *opaque, target_phys_addr_t addr) |
| 827 | 892 | |
| 828 | 893 | static uint32_t pci_unin_main_readw (void *opaque, target_phys_addr_t addr) |
| 829 | 894 | { |
| 830 | - PCIBridge *s = opaque; | |
| 895 | + PCIBus *s = opaque; | |
| 831 | 896 | uint32_t val; |
| 832 | 897 | |
| 833 | 898 | val = pci_data_read(s, addr & 7, 2); |
| ... | ... | @@ -840,7 +905,7 @@ static uint32_t pci_unin_main_readw (void *opaque, target_phys_addr_t addr) |
| 840 | 905 | |
| 841 | 906 | static uint32_t pci_unin_main_readl (void *opaque, target_phys_addr_t addr) |
| 842 | 907 | { |
| 843 | - PCIBridge *s = opaque; | |
| 908 | + PCIBus *s = opaque; | |
| 844 | 909 | uint32_t val; |
| 845 | 910 | |
| 846 | 911 | val = pci_data_read(s, addr, 4); |
| ... | ... | @@ -863,10 +928,12 @@ static CPUReadMemoryFunc *pci_unin_main_read[] = { |
| 863 | 928 | &pci_unin_main_readl, |
| 864 | 929 | }; |
| 865 | 930 | |
| 931 | +#if 0 | |
| 932 | + | |
| 866 | 933 | static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr, |
| 867 | 934 | uint32_t val) |
| 868 | 935 | { |
| 869 | - PCIBridge *s = opaque; | |
| 936 | + PCIBus *s = opaque; | |
| 870 | 937 | |
| 871 | 938 | #ifdef TARGET_WORDS_BIGENDIAN |
| 872 | 939 | val = bswap32(val); |
| ... | ... | @@ -877,7 +944,7 @@ static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr, |
| 877 | 944 | static uint32_t pci_unin_config_readl (void *opaque, |
| 878 | 945 | target_phys_addr_t addr) |
| 879 | 946 | { |
| 880 | - PCIBridge *s = opaque; | |
| 947 | + PCIBus *s = opaque; | |
| 881 | 948 | uint32_t val; |
| 882 | 949 | |
| 883 | 950 | val = (s->config_reg | 0x00000001) & ~0x80000000; |
| ... | ... | @@ -903,14 +970,14 @@ static CPUReadMemoryFunc *pci_unin_config_read[] = { |
| 903 | 970 | static void pci_unin_writeb (void *opaque, target_phys_addr_t addr, |
| 904 | 971 | uint32_t val) |
| 905 | 972 | { |
| 906 | - PCIBridge *s = opaque; | |
| 973 | + PCIBus *s = opaque; | |
| 907 | 974 | pci_data_write(s, addr & 3, val, 1); |
| 908 | 975 | } |
| 909 | 976 | |
| 910 | 977 | static void pci_unin_writew (void *opaque, target_phys_addr_t addr, |
| 911 | 978 | uint32_t val) |
| 912 | 979 | { |
| 913 | - PCIBridge *s = opaque; | |
| 980 | + PCIBus *s = opaque; | |
| 914 | 981 | #ifdef TARGET_WORDS_BIGENDIAN |
| 915 | 982 | val = bswap16(val); |
| 916 | 983 | #endif |
| ... | ... | @@ -920,7 +987,7 @@ static void pci_unin_writew (void *opaque, target_phys_addr_t addr, |
| 920 | 987 | static void pci_unin_writel (void *opaque, target_phys_addr_t addr, |
| 921 | 988 | uint32_t val) |
| 922 | 989 | { |
| 923 | - PCIBridge *s = opaque; | |
| 990 | + PCIBus *s = opaque; | |
| 924 | 991 | #ifdef TARGET_WORDS_BIGENDIAN |
| 925 | 992 | val = bswap32(val); |
| 926 | 993 | #endif |
| ... | ... | @@ -929,7 +996,7 @@ static void pci_unin_writel (void *opaque, target_phys_addr_t addr, |
| 929 | 996 | |
| 930 | 997 | static uint32_t pci_unin_readb (void *opaque, target_phys_addr_t addr) |
| 931 | 998 | { |
| 932 | - PCIBridge *s = opaque; | |
| 999 | + PCIBus *s = opaque; | |
| 933 | 1000 | uint32_t val; |
| 934 | 1001 | |
| 935 | 1002 | val = pci_data_read(s, addr & 3, 1); |
| ... | ... | @@ -939,7 +1006,7 @@ static uint32_t pci_unin_readb (void *opaque, target_phys_addr_t addr) |
| 939 | 1006 | |
| 940 | 1007 | static uint32_t pci_unin_readw (void *opaque, target_phys_addr_t addr) |
| 941 | 1008 | { |
| 942 | - PCIBridge *s = opaque; | |
| 1009 | + PCIBus *s = opaque; | |
| 943 | 1010 | uint32_t val; |
| 944 | 1011 | |
| 945 | 1012 | val = pci_data_read(s, addr & 3, 2); |
| ... | ... | @@ -952,7 +1019,7 @@ static uint32_t pci_unin_readw (void *opaque, target_phys_addr_t addr) |
| 952 | 1019 | |
| 953 | 1020 | static uint32_t pci_unin_readl (void *opaque, target_phys_addr_t addr) |
| 954 | 1021 | { |
| 955 | - PCIBridge *s = opaque; | |
| 1022 | + PCIBus *s = opaque; | |
| 956 | 1023 | uint32_t val; |
| 957 | 1024 | |
| 958 | 1025 | val = pci_data_read(s, addr & 3, 4); |
| ... | ... | @@ -974,25 +1041,45 @@ static CPUReadMemoryFunc *pci_unin_read[] = { |
| 974 | 1041 | &pci_unin_readw, |
| 975 | 1042 | &pci_unin_readl, |
| 976 | 1043 | }; |
| 1044 | +#endif | |
| 1045 | + | |
| 1046 | +static void pmac_set_irq(PCIDevice *d, int irq_num, int level) | |
| 1047 | +{ | |
| 1048 | + openpic_t *openpic; | |
| 1049 | + /* XXX: we do not simulate the hardware - we rely on the BIOS to | |
| 1050 | + set correctly for irq line field */ | |
| 1051 | + openpic = d->bus->openpic; | |
| 1052 | +#ifdef TARGET_PPC | |
| 1053 | + if (openpic) | |
| 1054 | + openpic_set_irq(openpic, d->config[PCI_INTERRUPT_LINE], level); | |
| 1055 | +#endif | |
| 1056 | +} | |
| 1057 | + | |
| 1058 | +void pci_pmac_set_openpic(PCIBus *bus, openpic_t *openpic) | |
| 1059 | +{ | |
| 1060 | + bus->openpic = openpic; | |
| 1061 | +} | |
| 977 | 1062 | |
| 978 | -void pci_pmac_init(void) | |
| 1063 | +PCIBus *pci_pmac_init(void) | |
| 979 | 1064 | { |
| 980 | - PCIBridge *s; | |
| 1065 | + PCIBus *s; | |
| 981 | 1066 | PCIDevice *d; |
| 982 | 1067 | int pci_mem_config, pci_mem_data; |
| 983 | 1068 | |
| 984 | 1069 | /* Use values found on a real PowerMac */ |
| 985 | 1070 | /* Uninorth main bus */ |
| 986 | - s = &pci_bridge[0]; | |
| 1071 | + s = pci_register_bus(); | |
| 1072 | + s->set_irq = pmac_set_irq; | |
| 1073 | + | |
| 987 | 1074 | pci_mem_config = cpu_register_io_memory(0, pci_unin_main_config_read, |
| 988 | 1075 | pci_unin_main_config_write, s); |
| 989 | 1076 | pci_mem_data = cpu_register_io_memory(0, pci_unin_main_read, |
| 990 | 1077 | pci_unin_main_write, s); |
| 991 | 1078 | cpu_register_physical_memory(0xf2800000, 0x1000, pci_mem_config); |
| 992 | 1079 | cpu_register_physical_memory(0xf2c00000, 0x1000, pci_mem_data); |
| 993 | - | |
| 994 | - d = pci_register_device("Uni-north main", sizeof(PCIDevice), 0, 11 << 3, | |
| 995 | - NULL, NULL); | |
| 1080 | + s->devfn_min = 11 << 3; | |
| 1081 | + d = pci_register_device(s, "Uni-north main", sizeof(PCIDevice), | |
| 1082 | + 11 << 3, NULL, NULL); | |
| 996 | 1083 | d->config[0x00] = 0x6b; // vendor_id : Apple |
| 997 | 1084 | d->config[0x01] = 0x10; |
| 998 | 1085 | d->config[0x02] = 0x1F; // device_id |
| ... | ... | @@ -1113,63 +1200,18 @@ void pci_pmac_init(void) |
| 1113 | 1200 | d->config[0x26] = 0x00; // prefetchable_memory_limit |
| 1114 | 1201 | d->config[0x27] = 0x85; |
| 1115 | 1202 | #endif |
| 1203 | + return s; | |
| 1116 | 1204 | } |
| 1117 | 1205 | |
| 1118 | 1206 | /***********************************************************/ |
| 1119 | 1207 | /* generic PCI irq support */ |
| 1120 | 1208 | |
| 1121 | -/* return the global irq number corresponding to a given device irq | |
| 1122 | - pin. We could also use the bus number to have a more precise | |
| 1123 | - mapping. */ | |
| 1124 | -static inline int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num) | |
| 1125 | -{ | |
| 1126 | - int slot_addend; | |
| 1127 | - slot_addend = (pci_dev->devfn >> 3); | |
| 1128 | - return (irq_num + slot_addend) & 3; | |
| 1129 | -} | |
| 1130 | - | |
| 1131 | 1209 | /* 0 <= irq_num <= 3. level must be 0 or 1 */ |
| 1132 | -#ifdef TARGET_PPC | |
| 1133 | 1210 | void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level) |
| 1134 | 1211 | { |
| 1212 | + PCIBus *bus = pci_dev->bus; | |
| 1213 | + bus->set_irq(pci_dev, irq_num, level); | |
| 1135 | 1214 | } |
| 1136 | -#else | |
| 1137 | -void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level) | |
| 1138 | -{ | |
| 1139 | - int irq_index, shift, pic_irq, pic_level; | |
| 1140 | - uint32_t *p; | |
| 1141 | - | |
| 1142 | - irq_num = pci_slot_get_pirq(pci_dev, irq_num); | |
| 1143 | - irq_index = pci_dev->irq_index; | |
| 1144 | - p = &pci_irq_levels[irq_num][irq_index >> 5]; | |
| 1145 | - shift = (irq_index & 0x1f); | |
| 1146 | - *p = (*p & ~(1 << shift)) | (level << shift); | |
| 1147 | - | |
| 1148 | - /* now we change the pic irq level according to the piix irq mappings */ | |
| 1149 | - pic_irq = piix3_state->dev.config[0x60 + irq_num]; | |
| 1150 | - if (pic_irq < 16) { | |
| 1151 | - /* the pic level is the logical OR of all the PCI irqs mapped | |
| 1152 | - to it */ | |
| 1153 | - pic_level = 0; | |
| 1154 | -#if (PCI_IRQ_WORDS == 2) | |
| 1155 | - pic_level = ((pci_irq_levels[irq_num][0] | | |
| 1156 | - pci_irq_levels[irq_num][1]) != 0); | |
| 1157 | -#else | |
| 1158 | - { | |
| 1159 | - int i; | |
| 1160 | - pic_level = 0; | |
| 1161 | - for(i = 0; i < PCI_IRQ_WORDS; i++) { | |
| 1162 | - if (pci_irq_levels[irq_num][i]) { | |
| 1163 | - pic_level = 1; | |
| 1164 | - break; | |
| 1165 | - } | |
| 1166 | - } | |
| 1167 | - } | |
| 1168 | -#endif | |
| 1169 | - pic_set_irq(pic_irq, pic_level); | |
| 1170 | - } | |
| 1171 | -} | |
| 1172 | -#endif | |
| 1173 | 1215 | |
| 1174 | 1216 | /***********************************************************/ |
| 1175 | 1217 | /* monitor info on PCI */ |
| ... | ... | @@ -1180,7 +1222,7 @@ static void pci_info_device(PCIDevice *d) |
| 1180 | 1222 | PCIIORegion *r; |
| 1181 | 1223 | |
| 1182 | 1224 | printf(" Bus %2d, device %3d, function %d:\n", |
| 1183 | - d->bus_num, d->devfn >> 3, d->devfn & 7); | |
| 1225 | + d->bus->bus_num, d->devfn >> 3, d->devfn & 7); | |
| 1184 | 1226 | class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE))); |
| 1185 | 1227 | printf(" "); |
| 1186 | 1228 | switch(class) { |
| ... | ... | @@ -1221,17 +1263,15 @@ static void pci_info_device(PCIDevice *d) |
| 1221 | 1263 | |
| 1222 | 1264 | void pci_info(void) |
| 1223 | 1265 | { |
| 1224 | - PCIBridge *s = &pci_bridge[0]; | |
| 1225 | - PCIDevice **bus; | |
| 1226 | - int bus_num, devfn; | |
| 1266 | + PCIBus *bus = first_bus; | |
| 1267 | + PCIDevice *d; | |
| 1268 | + int devfn; | |
| 1227 | 1269 | |
| 1228 | - for(bus_num = 0; bus_num < 256; bus_num++) { | |
| 1229 | - bus = s->pci_bus[bus_num]; | |
| 1230 | - if (bus) { | |
| 1231 | - for(devfn = 0; devfn < 256; devfn++) { | |
| 1232 | - if (bus[devfn]) | |
| 1233 | - pci_info_device(bus[devfn]); | |
| 1234 | - } | |
| 1270 | + if (bus) { | |
| 1271 | + for(devfn = 0; devfn < 256; devfn++) { | |
| 1272 | + d = bus->devices[devfn]; | |
| 1273 | + if (d) | |
| 1274 | + pci_info_device(d); | |
| 1235 | 1275 | } |
| 1236 | 1276 | } |
| 1237 | 1277 | } |
| ... | ... | @@ -1239,7 +1279,7 @@ void pci_info(void) |
| 1239 | 1279 | /***********************************************************/ |
| 1240 | 1280 | /* XXX: the following should be moved to the PC BIOS */ |
| 1241 | 1281 | |
| 1242 | -static uint32_t isa_inb(uint32_t addr) | |
| 1282 | +static __attribute__((unused)) uint32_t isa_inb(uint32_t addr) | |
| 1243 | 1283 | { |
| 1244 | 1284 | return cpu_inb(cpu_single_env, addr); |
| 1245 | 1285 | } |
| ... | ... | @@ -1249,70 +1289,70 @@ static void isa_outb(uint32_t val, uint32_t addr) |
| 1249 | 1289 | cpu_outb(cpu_single_env, addr, val); |
| 1250 | 1290 | } |
| 1251 | 1291 | |
| 1252 | -static uint32_t isa_inw(uint32_t addr) | |
| 1292 | +static __attribute__((unused)) uint32_t isa_inw(uint32_t addr) | |
| 1253 | 1293 | { |
| 1254 | 1294 | return cpu_inw(cpu_single_env, addr); |
| 1255 | 1295 | } |
| 1256 | 1296 | |
| 1257 | -static void isa_outw(uint32_t val, uint32_t addr) | |
| 1297 | +static __attribute__((unused)) void isa_outw(uint32_t val, uint32_t addr) | |
| 1258 | 1298 | { |
| 1259 | 1299 | cpu_outw(cpu_single_env, addr, val); |
| 1260 | 1300 | } |
| 1261 | 1301 | |
| 1262 | -static uint32_t isa_inl(uint32_t addr) | |
| 1302 | +static __attribute__((unused)) uint32_t isa_inl(uint32_t addr) | |
| 1263 | 1303 | { |
| 1264 | 1304 | return cpu_inl(cpu_single_env, addr); |
| 1265 | 1305 | } |
| 1266 | 1306 | |
| 1267 | -static void isa_outl(uint32_t val, uint32_t addr) | |
| 1307 | +static __attribute__((unused)) void isa_outl(uint32_t val, uint32_t addr) | |
| 1268 | 1308 | { |
| 1269 | 1309 | cpu_outl(cpu_single_env, addr, val); |
| 1270 | 1310 | } |
| 1271 | 1311 | |
| 1272 | 1312 | static void pci_config_writel(PCIDevice *d, uint32_t addr, uint32_t val) |
| 1273 | 1313 | { |
| 1274 | - PCIBridge *s = &pci_bridge[0]; | |
| 1275 | - s->config_reg = 0x80000000 | (d->bus_num << 16) | | |
| 1314 | + PCIBus *s = d->bus; | |
| 1315 | + s->config_reg = 0x80000000 | (s->bus_num << 16) | | |
| 1276 | 1316 | (d->devfn << 8) | addr; |
| 1277 | 1317 | pci_data_write(s, 0, val, 4); |
| 1278 | 1318 | } |
| 1279 | 1319 | |
| 1280 | 1320 | static void pci_config_writew(PCIDevice *d, uint32_t addr, uint32_t val) |
| 1281 | 1321 | { |
| 1282 | - PCIBridge *s = &pci_bridge[0]; | |
| 1283 | - s->config_reg = 0x80000000 | (d->bus_num << 16) | | |
| 1322 | + PCIBus *s = d->bus; | |
| 1323 | + s->config_reg = 0x80000000 | (s->bus_num << 16) | | |
| 1284 | 1324 | (d->devfn << 8) | (addr & ~3); |
| 1285 | 1325 | pci_data_write(s, addr & 3, val, 2); |
| 1286 | 1326 | } |
| 1287 | 1327 | |
| 1288 | 1328 | static void pci_config_writeb(PCIDevice *d, uint32_t addr, uint32_t val) |
| 1289 | 1329 | { |
| 1290 | - PCIBridge *s = &pci_bridge[0]; | |
| 1291 | - s->config_reg = 0x80000000 | (d->bus_num << 16) | | |
| 1330 | + PCIBus *s = d->bus; | |
| 1331 | + s->config_reg = 0x80000000 | (s->bus_num << 16) | | |
| 1292 | 1332 | (d->devfn << 8) | (addr & ~3); |
| 1293 | 1333 | pci_data_write(s, addr & 3, val, 1); |
| 1294 | 1334 | } |
| 1295 | 1335 | |
| 1296 | -static uint32_t pci_config_readl(PCIDevice *d, uint32_t addr) | |
| 1336 | +static __attribute__((unused)) uint32_t pci_config_readl(PCIDevice *d, uint32_t addr) | |
| 1297 | 1337 | { |
| 1298 | - PCIBridge *s = &pci_bridge[0]; | |
| 1299 | - s->config_reg = 0x80000000 | (d->bus_num << 16) | | |
| 1338 | + PCIBus *s = d->bus; | |
| 1339 | + s->config_reg = 0x80000000 | (s->bus_num << 16) | | |
| 1300 | 1340 | (d->devfn << 8) | addr; |
| 1301 | 1341 | return pci_data_read(s, 0, 4); |
| 1302 | 1342 | } |
| 1303 | 1343 | |
| 1304 | 1344 | static uint32_t pci_config_readw(PCIDevice *d, uint32_t addr) |
| 1305 | 1345 | { |
| 1306 | - PCIBridge *s = &pci_bridge[0]; | |
| 1307 | - s->config_reg = 0x80000000 | (d->bus_num << 16) | | |
| 1346 | + PCIBus *s = d->bus; | |
| 1347 | + s->config_reg = 0x80000000 | (s->bus_num << 16) | | |
| 1308 | 1348 | (d->devfn << 8) | (addr & ~3); |
| 1309 | 1349 | return pci_data_read(s, addr & 3, 2); |
| 1310 | 1350 | } |
| 1311 | 1351 | |
| 1312 | 1352 | static uint32_t pci_config_readb(PCIDevice *d, uint32_t addr) |
| 1313 | 1353 | { |
| 1314 | - PCIBridge *s = &pci_bridge[0]; | |
| 1315 | - s->config_reg = 0x80000000 | (d->bus_num << 16) | | |
| 1354 | + PCIBus *s = d->bus; | |
| 1355 | + s->config_reg = 0x80000000 | (s->bus_num << 16) | | |
| 1316 | 1356 | (d->devfn << 8) | (addr & ~3); |
| 1317 | 1357 | return pci_data_read(s, addr & 3, 1); |
| 1318 | 1358 | } |
| ... | ... | @@ -1432,9 +1472,9 @@ static void pci_bios_init_device(PCIDevice *d) |
| 1432 | 1472 | */ |
| 1433 | 1473 | void pci_bios_init(void) |
| 1434 | 1474 | { |
| 1435 | - PCIBridge *s = &pci_bridge[0]; | |
| 1436 | - PCIDevice **bus; | |
| 1437 | - int bus_num, devfn, i, irq; | |
| 1475 | + PCIBus *bus; | |
| 1476 | + PCIDevice *d; | |
| 1477 | + int devfn, i, irq; | |
| 1438 | 1478 | uint8_t elcr[2]; |
| 1439 | 1479 | |
| 1440 | 1480 | pci_bios_io_addr = 0xc000; |
| ... | ... | @@ -1453,57 +1493,12 @@ void pci_bios_init(void) |
| 1453 | 1493 | isa_outb(elcr[0], 0x4d0); |
| 1454 | 1494 | isa_outb(elcr[1], 0x4d1); |
| 1455 | 1495 | |
| 1456 | - for(bus_num = 0; bus_num < 256; bus_num++) { | |
| 1457 | - bus = s->pci_bus[bus_num]; | |
| 1458 | - if (bus) { | |
| 1459 | - for(devfn = 0; devfn < 256; devfn++) { | |
| 1460 | - if (bus[devfn]) | |
| 1461 | - pci_bios_init_device(bus[devfn]); | |
| 1462 | - } | |
| 1463 | - } | |
| 1464 | - } | |
| 1465 | -} | |
| 1466 | - | |
| 1467 | -/* | |
| 1468 | - * This function initializes the PCI devices as a normal PCI BIOS | |
| 1469 | - * would do. It is provided just in case the BIOS has no support for | |
| 1470 | - * PCI. | |
| 1471 | - */ | |
| 1472 | -void pci_ppc_bios_init(void) | |
| 1473 | -{ | |
| 1474 | - PCIBridge *s = &pci_bridge[0]; | |
| 1475 | - PCIDevice **bus; | |
| 1476 | - int bus_num, devfn; | |
| 1477 | -#if 0 | |
| 1478 | - int i, irq; | |
| 1479 | - uint8_t elcr[2]; | |
| 1480 | -#endif | |
| 1481 | - | |
| 1482 | - pci_bios_io_addr = 0xc000; | |
| 1483 | - pci_bios_mem_addr = 0xc0000000; | |
| 1484 | - | |
| 1485 | -#if 0 | |
| 1486 | - /* activate IRQ mappings */ | |
| 1487 | - elcr[0] = 0x00; | |
| 1488 | - elcr[1] = 0x00; | |
| 1489 | - for(i = 0; i < 4; i++) { | |
| 1490 | - irq = pci_irqs[i]; | |
| 1491 | - /* set to trigger level */ | |
| 1492 | - elcr[irq >> 3] |= (1 << (irq & 7)); | |
| 1493 | - /* activate irq remapping in PIIX */ | |
| 1494 | - pci_config_writeb((PCIDevice *)piix3_state, 0x60 + i, irq); | |
| 1495 | - } | |
| 1496 | - isa_outb(elcr[0], 0x4d0); | |
| 1497 | - isa_outb(elcr[1], 0x4d1); | |
| 1498 | -#endif | |
| 1499 | - | |
| 1500 | - for(bus_num = 0; bus_num < 256; bus_num++) { | |
| 1501 | - bus = s->pci_bus[bus_num]; | |
| 1502 | - if (bus) { | |
| 1503 | - for(devfn = 0; devfn < 256; devfn++) { | |
| 1504 | - if (bus[devfn]) | |
| 1505 | - pci_bios_init_device(bus[devfn]); | |
| 1506 | - } | |
| 1496 | + bus = first_bus; | |
| 1497 | + if (bus) { | |
| 1498 | + for(devfn = 0; devfn < 256; devfn++) { | |
| 1499 | + d = bus->devices[devfn]; | |
| 1500 | + if (d) | |
| 1501 | + pci_bios_init_device(d); | |
| 1507 | 1502 | } |
| 1508 | 1503 | } |
| 1509 | 1504 | } | ... | ... |