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,41 +40,42 @@ | ||
40 | #define PCI_DEVICES_MAX 64 | 40 | #define PCI_DEVICES_MAX 64 |
41 | #define PCI_IRQ_WORDS ((PCI_DEVICES_MAX + 31) / 32) | 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 | target_phys_addr_t pci_mem_base; | 52 | target_phys_addr_t pci_mem_base; |
50 | static int pci_irq_index; | 53 | static int pci_irq_index; |
51 | static uint32_t pci_irq_levels[4][PCI_IRQ_WORDS]; | 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 | /* -1 for devfn means auto assign */ | 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 | PCIConfigReadFunc *config_read, | 68 | PCIConfigReadFunc *config_read, |
57 | PCIConfigWriteFunc *config_write) | 69 | PCIConfigWriteFunc *config_write) |
58 | { | 70 | { |
59 | - PCIBridge *s = &pci_bridge[0]; | ||
60 | - PCIDevice *pci_dev, **bus; | 71 | + PCIDevice *pci_dev; |
61 | 72 | ||
62 | if (pci_irq_index >= PCI_DEVICES_MAX) | 73 | if (pci_irq_index >= PCI_DEVICES_MAX) |
63 | return NULL; | 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 | if (devfn < 0) { | 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 | goto found; | 79 | goto found; |
79 | } | 80 | } |
80 | return NULL; | 81 | return NULL; |
@@ -83,7 +84,7 @@ PCIDevice *pci_register_device(const char *name, int instance_size, | @@ -83,7 +84,7 @@ PCIDevice *pci_register_device(const char *name, int instance_size, | ||
83 | pci_dev = qemu_mallocz(instance_size); | 84 | pci_dev = qemu_mallocz(instance_size); |
84 | if (!pci_dev) | 85 | if (!pci_dev) |
85 | return NULL; | 86 | return NULL; |
86 | - pci_dev->bus_num = bus_num; | 87 | + pci_dev->bus = bus; |
87 | pci_dev->devfn = devfn; | 88 | pci_dev->devfn = devfn; |
88 | pstrcpy(pci_dev->name, sizeof(pci_dev->name), name); | 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,7 +95,7 @@ PCIDevice *pci_register_device(const char *name, int instance_size, | ||
94 | pci_dev->config_read = config_read; | 95 | pci_dev->config_read = config_read; |
95 | pci_dev->config_write = config_write; | 96 | pci_dev->config_write = config_write; |
96 | pci_dev->irq_index = pci_irq_index++; | 97 | pci_dev->irq_index = pci_irq_index++; |
97 | - bus[devfn] = pci_dev; | 98 | + bus->devices[devfn] = pci_dev; |
98 | return pci_dev; | 99 | return pci_dev; |
99 | } | 100 | } |
100 | 101 | ||
@@ -115,13 +116,13 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num, | @@ -115,13 +116,13 @@ void pci_register_io_region(PCIDevice *pci_dev, int region_num, | ||
115 | 116 | ||
116 | static void pci_addr_writel(void* opaque, uint32_t addr, uint32_t val) | 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 | s->config_reg = val; | 120 | s->config_reg = val; |
120 | } | 121 | } |
121 | 122 | ||
122 | static uint32_t pci_addr_readl(void* opaque, uint32_t addr) | 123 | static uint32_t pci_addr_readl(void* opaque, uint32_t addr) |
123 | { | 124 | { |
124 | - PCIBridge *s = opaque; | 125 | + PCIBus *s = opaque; |
125 | return s->config_reg; | 126 | return s->config_reg; |
126 | } | 127 | } |
127 | 128 | ||
@@ -321,9 +322,9 @@ void pci_default_write_config(PCIDevice *d, | @@ -321,9 +322,9 @@ void pci_default_write_config(PCIDevice *d, | ||
321 | static void pci_data_write(void *opaque, uint32_t addr, | 322 | static void pci_data_write(void *opaque, uint32_t addr, |
322 | uint32_t val, int len) | 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 | #if defined(DEBUG_PCI) && 0 | 329 | #if defined(DEBUG_PCI) && 0 |
329 | printf("pci_data_write: addr=%08x val=%08x len=%d\n", | 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,10 +336,10 @@ static void pci_data_write(void *opaque, uint32_t addr, | ||
335 | if ((s->config_reg & 0x3) != 0) { | 336 | if ((s->config_reg & 0x3) != 0) { |
336 | return; | 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 | return; | 341 | return; |
341 | - pci_dev = bus[(s->config_reg >> 8) & 0xff]; | 342 | + pci_dev = s->devices[(s->config_reg >> 8) & 0xff]; |
342 | if (!pci_dev) | 343 | if (!pci_dev) |
343 | return; | 344 | return; |
344 | config_addr = (s->config_reg & 0xfc) | (addr & 3); | 345 | config_addr = (s->config_reg & 0xfc) | (addr & 3); |
@@ -352,19 +353,19 @@ static void pci_data_write(void *opaque, uint32_t addr, | @@ -352,19 +353,19 @@ static void pci_data_write(void *opaque, uint32_t addr, | ||
352 | static uint32_t pci_data_read(void *opaque, uint32_t addr, | 353 | static uint32_t pci_data_read(void *opaque, uint32_t addr, |
353 | int len) | 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 | uint32_t val; | 359 | uint32_t val; |
359 | 360 | ||
360 | if (!(s->config_reg & (1 << 31))) | 361 | if (!(s->config_reg & (1 << 31))) |
361 | goto fail; | 362 | goto fail; |
362 | if ((s->config_reg & 0x3) != 0) | 363 | if ((s->config_reg & 0x3) != 0) |
363 | goto fail; | 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 | goto fail; | 367 | goto fail; |
367 | - pci_dev = bus[(s->config_reg >> 8) & 0xff]; | 368 | + pci_dev = s->devices[(s->config_reg >> 8) & 0xff]; |
368 | if (!pci_dev) { | 369 | if (!pci_dev) { |
369 | fail: | 370 | fail: |
370 | switch(len) { | 371 | switch(len) { |
@@ -427,11 +428,16 @@ static uint32_t pci_data_readl(void* opaque, uint32_t addr) | @@ -427,11 +428,16 @@ static uint32_t pci_data_readl(void* opaque, uint32_t addr) | ||
427 | 428 | ||
428 | /* i440FX PCI bridge */ | 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 | PCIDevice *d; | 436 | PCIDevice *d; |
434 | 437 | ||
438 | + s = pci_register_bus(); | ||
439 | + s->set_irq = piix3_set_irq; | ||
440 | + | ||
435 | register_ioport_write(0xcf8, 4, 4, pci_addr_writel, s); | 441 | register_ioport_write(0xcf8, 4, 4, pci_addr_writel, s); |
436 | register_ioport_read(0xcf8, 4, 4, pci_addr_readl, s); | 442 | register_ioport_read(0xcf8, 4, 4, pci_addr_readl, s); |
437 | 443 | ||
@@ -442,7 +448,7 @@ void i440fx_init(void) | @@ -442,7 +448,7 @@ void i440fx_init(void) | ||
442 | register_ioport_read(0xcfc, 4, 2, pci_data_readw, s); | 448 | register_ioport_read(0xcfc, 4, 2, pci_data_readw, s); |
443 | register_ioport_read(0xcfc, 4, 4, pci_data_readl, s); | 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 | NULL, NULL); | 452 | NULL, NULL); |
447 | 453 | ||
448 | d->config[0x00] = 0x86; // vendor_id | 454 | d->config[0x00] = 0x86; // vendor_id |
@@ -453,6 +459,7 @@ void i440fx_init(void) | @@ -453,6 +459,7 @@ void i440fx_init(void) | ||
453 | d->config[0x0a] = 0x00; // class_sub = host2pci | 459 | d->config[0x0a] = 0x00; // class_sub = host2pci |
454 | d->config[0x0b] = 0x06; // class_base = PCI_bridge | 460 | d->config[0x0b] = 0x06; // class_base = PCI_bridge |
455 | d->config[0x0e] = 0x00; // header_type | 461 | d->config[0x0e] = 0x00; // header_type |
462 | + return s; | ||
456 | } | 463 | } |
457 | 464 | ||
458 | /* PIIX3 PCI to ISA bridge */ | 465 | /* PIIX3 PCI to ISA bridge */ |
@@ -463,6 +470,52 @@ typedef struct PIIX3State { | @@ -463,6 +470,52 @@ typedef struct PIIX3State { | ||
463 | 470 | ||
464 | PIIX3State *piix3_state; | 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 | static void piix3_reset(PIIX3State *d) | 519 | static void piix3_reset(PIIX3State *d) |
467 | { | 520 | { |
468 | uint8_t *pci_conf = d->dev.config; | 521 | uint8_t *pci_conf = d->dev.config; |
@@ -498,14 +551,13 @@ static void piix3_reset(PIIX3State *d) | @@ -498,14 +551,13 @@ static void piix3_reset(PIIX3State *d) | ||
498 | pci_conf[0xae] = 0x00; | 551 | pci_conf[0xae] = 0x00; |
499 | } | 552 | } |
500 | 553 | ||
501 | -void piix3_init(void) | 554 | +void piix3_init(PCIBus *bus) |
502 | { | 555 | { |
503 | PIIX3State *d; | 556 | PIIX3State *d; |
504 | uint8_t *pci_conf; | 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 | piix3_state = d; | 561 | piix3_state = d; |
510 | pci_conf = d->dev.config; | 562 | pci_conf = d->dev.config; |
511 | 563 | ||
@@ -522,7 +574,7 @@ void piix3_init(void) | @@ -522,7 +574,7 @@ void piix3_init(void) | ||
522 | 574 | ||
523 | /* PREP pci init */ | 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 | int devfn, i; | 579 | int devfn, i; |
528 | 580 | ||
@@ -536,14 +588,14 @@ static inline void set_config(PCIBridge *s, target_phys_addr_t addr) | @@ -536,14 +588,14 @@ static inline void set_config(PCIBridge *s, target_phys_addr_t addr) | ||
536 | 588 | ||
537 | static void PPC_PCIIO_writeb (void *opaque, target_phys_addr_t addr, uint32_t val) | 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 | set_config(s, addr); | 592 | set_config(s, addr); |
541 | pci_data_write(s, addr, val, 1); | 593 | pci_data_write(s, addr, val, 1); |
542 | } | 594 | } |
543 | 595 | ||
544 | static void PPC_PCIIO_writew (void *opaque, target_phys_addr_t addr, uint32_t val) | 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 | set_config(s, addr); | 599 | set_config(s, addr); |
548 | #ifdef TARGET_WORDS_BIGENDIAN | 600 | #ifdef TARGET_WORDS_BIGENDIAN |
549 | val = bswap16(val); | 601 | val = bswap16(val); |
@@ -553,7 +605,7 @@ static void PPC_PCIIO_writew (void *opaque, target_phys_addr_t addr, uint32_t va | @@ -553,7 +605,7 @@ static void PPC_PCIIO_writew (void *opaque, target_phys_addr_t addr, uint32_t va | ||
553 | 605 | ||
554 | static void PPC_PCIIO_writel (void *opaque, target_phys_addr_t addr, uint32_t val) | 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 | set_config(s, addr); | 609 | set_config(s, addr); |
558 | #ifdef TARGET_WORDS_BIGENDIAN | 610 | #ifdef TARGET_WORDS_BIGENDIAN |
559 | val = bswap32(val); | 611 | val = bswap32(val); |
@@ -563,7 +615,7 @@ static void PPC_PCIIO_writel (void *opaque, target_phys_addr_t addr, uint32_t va | @@ -563,7 +615,7 @@ static void PPC_PCIIO_writel (void *opaque, target_phys_addr_t addr, uint32_t va | ||
563 | 615 | ||
564 | static uint32_t PPC_PCIIO_readb (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 619 | uint32_t val; |
568 | set_config(s, addr); | 620 | set_config(s, addr); |
569 | val = pci_data_read(s, addr, 1); | 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,7 +624,7 @@ static uint32_t PPC_PCIIO_readb (void *opaque, target_phys_addr_t addr) | ||
572 | 624 | ||
573 | static uint32_t PPC_PCIIO_readw (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 628 | uint32_t val; |
577 | set_config(s, addr); | 629 | set_config(s, addr); |
578 | val = pci_data_read(s, addr, 2); | 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,7 +636,7 @@ static uint32_t PPC_PCIIO_readw (void *opaque, target_phys_addr_t addr) | ||
584 | 636 | ||
585 | static uint32_t PPC_PCIIO_readl (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 640 | uint32_t val; |
589 | set_config(s, addr); | 641 | set_config(s, addr); |
590 | val = pci_data_read(s, addr, 4); | 642 | val = pci_data_read(s, addr, 4); |
@@ -606,17 +658,27 @@ static CPUReadMemoryFunc *PPC_PCIIO_read[] = { | @@ -606,17 +658,27 @@ static CPUReadMemoryFunc *PPC_PCIIO_read[] = { | ||
606 | &PPC_PCIIO_readl, | 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 | PCIDevice *d; | 671 | PCIDevice *d; |
613 | int PPC_io_memory; | 672 | int PPC_io_memory; |
614 | 673 | ||
674 | + s = pci_register_bus(); | ||
675 | + s->set_irq = prep_set_irq; | ||
676 | + | ||
615 | PPC_io_memory = cpu_register_io_memory(0, PPC_PCIIO_read, | 677 | PPC_io_memory = cpu_register_io_memory(0, PPC_PCIIO_read, |
616 | PPC_PCIIO_write, s); | 678 | PPC_PCIIO_write, s); |
617 | cpu_register_physical_memory(0x80800000, 0x00400000, PPC_io_memory); | 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 | NULL, NULL); | 682 | NULL, NULL); |
621 | 683 | ||
622 | /* XXX: put correct IDs */ | 684 | /* XXX: put correct IDs */ |
@@ -628,16 +690,18 @@ void pci_prep_init(void) | @@ -628,16 +690,18 @@ void pci_prep_init(void) | ||
628 | d->config[0x0a] = 0x04; // class_sub = pci2pci | 690 | d->config[0x0a] = 0x04; // class_sub = pci2pci |
629 | d->config[0x0b] = 0x06; // class_base = PCI_bridge | 691 | d->config[0x0b] = 0x06; // class_base = PCI_bridge |
630 | d->config[0x0e] = 0x01; // header_type | 692 | d->config[0x0e] = 0x01; // header_type |
693 | + return s; | ||
631 | } | 694 | } |
632 | 695 | ||
633 | 696 | ||
634 | /* pmac pci init */ | 697 | /* pmac pci init */ |
635 | 698 | ||
699 | +#if 0 | ||
636 | /* Grackle PCI host */ | 700 | /* Grackle PCI host */ |
637 | static void pci_grackle_config_writel (void *opaque, target_phys_addr_t addr, | 701 | static void pci_grackle_config_writel (void *opaque, target_phys_addr_t addr, |
638 | uint32_t val) | 702 | uint32_t val) |
639 | { | 703 | { |
640 | - PCIBridge *s = opaque; | 704 | + PCIBus *s = opaque; |
641 | #ifdef TARGET_WORDS_BIGENDIAN | 705 | #ifdef TARGET_WORDS_BIGENDIAN |
642 | val = bswap32(val); | 706 | val = bswap32(val); |
643 | #endif | 707 | #endif |
@@ -646,7 +710,7 @@ static void pci_grackle_config_writel (void *opaque, target_phys_addr_t addr, | @@ -646,7 +710,7 @@ static void pci_grackle_config_writel (void *opaque, target_phys_addr_t addr, | ||
646 | 710 | ||
647 | static uint32_t pci_grackle_config_readl (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 714 | uint32_t val; |
651 | 715 | ||
652 | val = s->config_reg; | 716 | val = s->config_reg; |
@@ -671,14 +735,14 @@ static CPUReadMemoryFunc *pci_grackle_config_read[] = { | @@ -671,14 +735,14 @@ static CPUReadMemoryFunc *pci_grackle_config_read[] = { | ||
671 | static void pci_grackle_writeb (void *opaque, target_phys_addr_t addr, | 735 | static void pci_grackle_writeb (void *opaque, target_phys_addr_t addr, |
672 | uint32_t val) | 736 | uint32_t val) |
673 | { | 737 | { |
674 | - PCIBridge *s = opaque; | 738 | + PCIBus *s = opaque; |
675 | pci_data_write(s, addr, val, 1); | 739 | pci_data_write(s, addr, val, 1); |
676 | } | 740 | } |
677 | 741 | ||
678 | static void pci_grackle_writew (void *opaque, target_phys_addr_t addr, | 742 | static void pci_grackle_writew (void *opaque, target_phys_addr_t addr, |
679 | uint32_t val) | 743 | uint32_t val) |
680 | { | 744 | { |
681 | - PCIBridge *s = opaque; | 745 | + PCIBus *s = opaque; |
682 | #ifdef TARGET_WORDS_BIGENDIAN | 746 | #ifdef TARGET_WORDS_BIGENDIAN |
683 | val = bswap16(val); | 747 | val = bswap16(val); |
684 | #endif | 748 | #endif |
@@ -688,7 +752,7 @@ static void pci_grackle_writew (void *opaque, target_phys_addr_t addr, | @@ -688,7 +752,7 @@ static void pci_grackle_writew (void *opaque, target_phys_addr_t addr, | ||
688 | static void pci_grackle_writel (void *opaque, target_phys_addr_t addr, | 752 | static void pci_grackle_writel (void *opaque, target_phys_addr_t addr, |
689 | uint32_t val) | 753 | uint32_t val) |
690 | { | 754 | { |
691 | - PCIBridge *s = opaque; | 755 | + PCIBus *s = opaque; |
692 | #ifdef TARGET_WORDS_BIGENDIAN | 756 | #ifdef TARGET_WORDS_BIGENDIAN |
693 | val = bswap32(val); | 757 | val = bswap32(val); |
694 | #endif | 758 | #endif |
@@ -697,7 +761,7 @@ static void pci_grackle_writel (void *opaque, target_phys_addr_t addr, | @@ -697,7 +761,7 @@ static void pci_grackle_writel (void *opaque, target_phys_addr_t addr, | ||
697 | 761 | ||
698 | static uint32_t pci_grackle_readb (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 765 | uint32_t val; |
702 | val = pci_data_read(s, addr, 1); | 766 | val = pci_data_read(s, addr, 1); |
703 | return val; | 767 | return val; |
@@ -705,7 +769,7 @@ static uint32_t pci_grackle_readb (void *opaque, target_phys_addr_t addr) | @@ -705,7 +769,7 @@ static uint32_t pci_grackle_readb (void *opaque, target_phys_addr_t addr) | ||
705 | 769 | ||
706 | static uint32_t pci_grackle_readw (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 773 | uint32_t val; |
710 | val = pci_data_read(s, addr, 2); | 774 | val = pci_data_read(s, addr, 2); |
711 | #ifdef TARGET_WORDS_BIGENDIAN | 775 | #ifdef TARGET_WORDS_BIGENDIAN |
@@ -716,7 +780,7 @@ static uint32_t pci_grackle_readw (void *opaque, target_phys_addr_t addr) | @@ -716,7 +780,7 @@ static uint32_t pci_grackle_readw (void *opaque, target_phys_addr_t addr) | ||
716 | 780 | ||
717 | static uint32_t pci_grackle_readl (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 784 | uint32_t val; |
721 | 785 | ||
722 | val = pci_data_read(s, addr, 4); | 786 | val = pci_data_read(s, addr, 4); |
@@ -737,12 +801,13 @@ static CPUReadMemoryFunc *pci_grackle_read[] = { | @@ -737,12 +801,13 @@ static CPUReadMemoryFunc *pci_grackle_read[] = { | ||
737 | &pci_grackle_readw, | 801 | &pci_grackle_readw, |
738 | &pci_grackle_readl, | 802 | &pci_grackle_readl, |
739 | }; | 803 | }; |
804 | +#endif | ||
740 | 805 | ||
741 | /* Uninorth PCI host (for all Mac99 and newer machines */ | 806 | /* Uninorth PCI host (for all Mac99 and newer machines */ |
742 | static void pci_unin_main_config_writel (void *opaque, target_phys_addr_t addr, | 807 | static void pci_unin_main_config_writel (void *opaque, target_phys_addr_t addr, |
743 | uint32_t val) | 808 | uint32_t val) |
744 | { | 809 | { |
745 | - PCIBridge *s = opaque; | 810 | + PCIBus *s = opaque; |
746 | int i; | 811 | int i; |
747 | 812 | ||
748 | #ifdef TARGET_WORDS_BIGENDIAN | 813 | #ifdef TARGET_WORDS_BIGENDIAN |
@@ -763,7 +828,7 @@ static void pci_unin_main_config_writel (void *opaque, target_phys_addr_t addr, | @@ -763,7 +828,7 @@ static void pci_unin_main_config_writel (void *opaque, target_phys_addr_t addr, | ||
763 | static uint32_t pci_unin_main_config_readl (void *opaque, | 828 | static uint32_t pci_unin_main_config_readl (void *opaque, |
764 | target_phys_addr_t addr) | 829 | target_phys_addr_t addr) |
765 | { | 830 | { |
766 | - PCIBridge *s = opaque; | 831 | + PCIBus *s = opaque; |
767 | uint32_t val; | 832 | uint32_t val; |
768 | int devfn; | 833 | int devfn; |
769 | 834 | ||
@@ -791,14 +856,14 @@ static CPUReadMemoryFunc *pci_unin_main_config_read[] = { | @@ -791,14 +856,14 @@ static CPUReadMemoryFunc *pci_unin_main_config_read[] = { | ||
791 | static void pci_unin_main_writeb (void *opaque, target_phys_addr_t addr, | 856 | static void pci_unin_main_writeb (void *opaque, target_phys_addr_t addr, |
792 | uint32_t val) | 857 | uint32_t val) |
793 | { | 858 | { |
794 | - PCIBridge *s = opaque; | 859 | + PCIBus *s = opaque; |
795 | pci_data_write(s, addr & 7, val, 1); | 860 | pci_data_write(s, addr & 7, val, 1); |
796 | } | 861 | } |
797 | 862 | ||
798 | static void pci_unin_main_writew (void *opaque, target_phys_addr_t addr, | 863 | static void pci_unin_main_writew (void *opaque, target_phys_addr_t addr, |
799 | uint32_t val) | 864 | uint32_t val) |
800 | { | 865 | { |
801 | - PCIBridge *s = opaque; | 866 | + PCIBus *s = opaque; |
802 | #ifdef TARGET_WORDS_BIGENDIAN | 867 | #ifdef TARGET_WORDS_BIGENDIAN |
803 | val = bswap16(val); | 868 | val = bswap16(val); |
804 | #endif | 869 | #endif |
@@ -808,7 +873,7 @@ static void pci_unin_main_writew (void *opaque, target_phys_addr_t addr, | @@ -808,7 +873,7 @@ static void pci_unin_main_writew (void *opaque, target_phys_addr_t addr, | ||
808 | static void pci_unin_main_writel (void *opaque, target_phys_addr_t addr, | 873 | static void pci_unin_main_writel (void *opaque, target_phys_addr_t addr, |
809 | uint32_t val) | 874 | uint32_t val) |
810 | { | 875 | { |
811 | - PCIBridge *s = opaque; | 876 | + PCIBus *s = opaque; |
812 | #ifdef TARGET_WORDS_BIGENDIAN | 877 | #ifdef TARGET_WORDS_BIGENDIAN |
813 | val = bswap32(val); | 878 | val = bswap32(val); |
814 | #endif | 879 | #endif |
@@ -817,7 +882,7 @@ static void pci_unin_main_writel (void *opaque, target_phys_addr_t addr, | @@ -817,7 +882,7 @@ static void pci_unin_main_writel (void *opaque, target_phys_addr_t addr, | ||
817 | 882 | ||
818 | static uint32_t pci_unin_main_readb (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 886 | uint32_t val; |
822 | 887 | ||
823 | val = pci_data_read(s, addr & 7, 1); | 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,7 +892,7 @@ static uint32_t pci_unin_main_readb (void *opaque, target_phys_addr_t addr) | ||
827 | 892 | ||
828 | static uint32_t pci_unin_main_readw (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 896 | uint32_t val; |
832 | 897 | ||
833 | val = pci_data_read(s, addr & 7, 2); | 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,7 +905,7 @@ static uint32_t pci_unin_main_readw (void *opaque, target_phys_addr_t addr) | ||
840 | 905 | ||
841 | static uint32_t pci_unin_main_readl (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 909 | uint32_t val; |
845 | 910 | ||
846 | val = pci_data_read(s, addr, 4); | 911 | val = pci_data_read(s, addr, 4); |
@@ -863,10 +928,12 @@ static CPUReadMemoryFunc *pci_unin_main_read[] = { | @@ -863,10 +928,12 @@ static CPUReadMemoryFunc *pci_unin_main_read[] = { | ||
863 | &pci_unin_main_readl, | 928 | &pci_unin_main_readl, |
864 | }; | 929 | }; |
865 | 930 | ||
931 | +#if 0 | ||
932 | + | ||
866 | static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr, | 933 | static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr, |
867 | uint32_t val) | 934 | uint32_t val) |
868 | { | 935 | { |
869 | - PCIBridge *s = opaque; | 936 | + PCIBus *s = opaque; |
870 | 937 | ||
871 | #ifdef TARGET_WORDS_BIGENDIAN | 938 | #ifdef TARGET_WORDS_BIGENDIAN |
872 | val = bswap32(val); | 939 | val = bswap32(val); |
@@ -877,7 +944,7 @@ static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr, | @@ -877,7 +944,7 @@ static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr, | ||
877 | static uint32_t pci_unin_config_readl (void *opaque, | 944 | static uint32_t pci_unin_config_readl (void *opaque, |
878 | target_phys_addr_t addr) | 945 | target_phys_addr_t addr) |
879 | { | 946 | { |
880 | - PCIBridge *s = opaque; | 947 | + PCIBus *s = opaque; |
881 | uint32_t val; | 948 | uint32_t val; |
882 | 949 | ||
883 | val = (s->config_reg | 0x00000001) & ~0x80000000; | 950 | val = (s->config_reg | 0x00000001) & ~0x80000000; |
@@ -903,14 +970,14 @@ static CPUReadMemoryFunc *pci_unin_config_read[] = { | @@ -903,14 +970,14 @@ static CPUReadMemoryFunc *pci_unin_config_read[] = { | ||
903 | static void pci_unin_writeb (void *opaque, target_phys_addr_t addr, | 970 | static void pci_unin_writeb (void *opaque, target_phys_addr_t addr, |
904 | uint32_t val) | 971 | uint32_t val) |
905 | { | 972 | { |
906 | - PCIBridge *s = opaque; | 973 | + PCIBus *s = opaque; |
907 | pci_data_write(s, addr & 3, val, 1); | 974 | pci_data_write(s, addr & 3, val, 1); |
908 | } | 975 | } |
909 | 976 | ||
910 | static void pci_unin_writew (void *opaque, target_phys_addr_t addr, | 977 | static void pci_unin_writew (void *opaque, target_phys_addr_t addr, |
911 | uint32_t val) | 978 | uint32_t val) |
912 | { | 979 | { |
913 | - PCIBridge *s = opaque; | 980 | + PCIBus *s = opaque; |
914 | #ifdef TARGET_WORDS_BIGENDIAN | 981 | #ifdef TARGET_WORDS_BIGENDIAN |
915 | val = bswap16(val); | 982 | val = bswap16(val); |
916 | #endif | 983 | #endif |
@@ -920,7 +987,7 @@ static void pci_unin_writew (void *opaque, target_phys_addr_t addr, | @@ -920,7 +987,7 @@ static void pci_unin_writew (void *opaque, target_phys_addr_t addr, | ||
920 | static void pci_unin_writel (void *opaque, target_phys_addr_t addr, | 987 | static void pci_unin_writel (void *opaque, target_phys_addr_t addr, |
921 | uint32_t val) | 988 | uint32_t val) |
922 | { | 989 | { |
923 | - PCIBridge *s = opaque; | 990 | + PCIBus *s = opaque; |
924 | #ifdef TARGET_WORDS_BIGENDIAN | 991 | #ifdef TARGET_WORDS_BIGENDIAN |
925 | val = bswap32(val); | 992 | val = bswap32(val); |
926 | #endif | 993 | #endif |
@@ -929,7 +996,7 @@ static void pci_unin_writel (void *opaque, target_phys_addr_t addr, | @@ -929,7 +996,7 @@ static void pci_unin_writel (void *opaque, target_phys_addr_t addr, | ||
929 | 996 | ||
930 | static uint32_t pci_unin_readb (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 1000 | uint32_t val; |
934 | 1001 | ||
935 | val = pci_data_read(s, addr & 3, 1); | 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,7 +1006,7 @@ static uint32_t pci_unin_readb (void *opaque, target_phys_addr_t addr) | ||
939 | 1006 | ||
940 | static uint32_t pci_unin_readw (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 1010 | uint32_t val; |
944 | 1011 | ||
945 | val = pci_data_read(s, addr & 3, 2); | 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,7 +1019,7 @@ static uint32_t pci_unin_readw (void *opaque, target_phys_addr_t addr) | ||
952 | 1019 | ||
953 | static uint32_t pci_unin_readl (void *opaque, target_phys_addr_t addr) | 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 | uint32_t val; | 1023 | uint32_t val; |
957 | 1024 | ||
958 | val = pci_data_read(s, addr & 3, 4); | 1025 | val = pci_data_read(s, addr & 3, 4); |
@@ -974,25 +1041,45 @@ static CPUReadMemoryFunc *pci_unin_read[] = { | @@ -974,25 +1041,45 @@ static CPUReadMemoryFunc *pci_unin_read[] = { | ||
974 | &pci_unin_readw, | 1041 | &pci_unin_readw, |
975 | &pci_unin_readl, | 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 | PCIDevice *d; | 1066 | PCIDevice *d; |
982 | int pci_mem_config, pci_mem_data; | 1067 | int pci_mem_config, pci_mem_data; |
983 | 1068 | ||
984 | /* Use values found on a real PowerMac */ | 1069 | /* Use values found on a real PowerMac */ |
985 | /* Uninorth main bus */ | 1070 | /* Uninorth main bus */ |
986 | - s = &pci_bridge[0]; | 1071 | + s = pci_register_bus(); |
1072 | + s->set_irq = pmac_set_irq; | ||
1073 | + | ||
987 | pci_mem_config = cpu_register_io_memory(0, pci_unin_main_config_read, | 1074 | pci_mem_config = cpu_register_io_memory(0, pci_unin_main_config_read, |
988 | pci_unin_main_config_write, s); | 1075 | pci_unin_main_config_write, s); |
989 | pci_mem_data = cpu_register_io_memory(0, pci_unin_main_read, | 1076 | pci_mem_data = cpu_register_io_memory(0, pci_unin_main_read, |
990 | pci_unin_main_write, s); | 1077 | pci_unin_main_write, s); |
991 | cpu_register_physical_memory(0xf2800000, 0x1000, pci_mem_config); | 1078 | cpu_register_physical_memory(0xf2800000, 0x1000, pci_mem_config); |
992 | cpu_register_physical_memory(0xf2c00000, 0x1000, pci_mem_data); | 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 | d->config[0x00] = 0x6b; // vendor_id : Apple | 1083 | d->config[0x00] = 0x6b; // vendor_id : Apple |
997 | d->config[0x01] = 0x10; | 1084 | d->config[0x01] = 0x10; |
998 | d->config[0x02] = 0x1F; // device_id | 1085 | d->config[0x02] = 0x1F; // device_id |
@@ -1113,63 +1200,18 @@ void pci_pmac_init(void) | @@ -1113,63 +1200,18 @@ void pci_pmac_init(void) | ||
1113 | d->config[0x26] = 0x00; // prefetchable_memory_limit | 1200 | d->config[0x26] = 0x00; // prefetchable_memory_limit |
1114 | d->config[0x27] = 0x85; | 1201 | d->config[0x27] = 0x85; |
1115 | #endif | 1202 | #endif |
1203 | + return s; | ||
1116 | } | 1204 | } |
1117 | 1205 | ||
1118 | /***********************************************************/ | 1206 | /***********************************************************/ |
1119 | /* generic PCI irq support */ | 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 | /* 0 <= irq_num <= 3. level must be 0 or 1 */ | 1209 | /* 0 <= irq_num <= 3. level must be 0 or 1 */ |
1132 | -#ifdef TARGET_PPC | ||
1133 | void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level) | 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 | /* monitor info on PCI */ | 1217 | /* monitor info on PCI */ |
@@ -1180,7 +1222,7 @@ static void pci_info_device(PCIDevice *d) | @@ -1180,7 +1222,7 @@ static void pci_info_device(PCIDevice *d) | ||
1180 | PCIIORegion *r; | 1222 | PCIIORegion *r; |
1181 | 1223 | ||
1182 | printf(" Bus %2d, device %3d, function %d:\n", | 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 | class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE))); | 1226 | class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE))); |
1185 | printf(" "); | 1227 | printf(" "); |
1186 | switch(class) { | 1228 | switch(class) { |
@@ -1221,17 +1263,15 @@ static void pci_info_device(PCIDevice *d) | @@ -1221,17 +1263,15 @@ static void pci_info_device(PCIDevice *d) | ||
1221 | 1263 | ||
1222 | void pci_info(void) | 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,7 +1279,7 @@ void pci_info(void) | ||
1239 | /***********************************************************/ | 1279 | /***********************************************************/ |
1240 | /* XXX: the following should be moved to the PC BIOS */ | 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 | return cpu_inb(cpu_single_env, addr); | 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,70 +1289,70 @@ static void isa_outb(uint32_t val, uint32_t addr) | ||
1249 | cpu_outb(cpu_single_env, addr, val); | 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 | return cpu_inw(cpu_single_env, addr); | 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 | cpu_outw(cpu_single_env, addr, val); | 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 | return cpu_inl(cpu_single_env, addr); | 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 | cpu_outl(cpu_single_env, addr, val); | 1309 | cpu_outl(cpu_single_env, addr, val); |
1270 | } | 1310 | } |
1271 | 1311 | ||
1272 | static void pci_config_writel(PCIDevice *d, uint32_t addr, uint32_t val) | 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 | (d->devfn << 8) | addr; | 1316 | (d->devfn << 8) | addr; |
1277 | pci_data_write(s, 0, val, 4); | 1317 | pci_data_write(s, 0, val, 4); |
1278 | } | 1318 | } |
1279 | 1319 | ||
1280 | static void pci_config_writew(PCIDevice *d, uint32_t addr, uint32_t val) | 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 | (d->devfn << 8) | (addr & ~3); | 1324 | (d->devfn << 8) | (addr & ~3); |
1285 | pci_data_write(s, addr & 3, val, 2); | 1325 | pci_data_write(s, addr & 3, val, 2); |
1286 | } | 1326 | } |
1287 | 1327 | ||
1288 | static void pci_config_writeb(PCIDevice *d, uint32_t addr, uint32_t val) | 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 | (d->devfn << 8) | (addr & ~3); | 1332 | (d->devfn << 8) | (addr & ~3); |
1293 | pci_data_write(s, addr & 3, val, 1); | 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 | (d->devfn << 8) | addr; | 1340 | (d->devfn << 8) | addr; |
1301 | return pci_data_read(s, 0, 4); | 1341 | return pci_data_read(s, 0, 4); |
1302 | } | 1342 | } |
1303 | 1343 | ||
1304 | static uint32_t pci_config_readw(PCIDevice *d, uint32_t addr) | 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 | (d->devfn << 8) | (addr & ~3); | 1348 | (d->devfn << 8) | (addr & ~3); |
1309 | return pci_data_read(s, addr & 3, 2); | 1349 | return pci_data_read(s, addr & 3, 2); |
1310 | } | 1350 | } |
1311 | 1351 | ||
1312 | static uint32_t pci_config_readb(PCIDevice *d, uint32_t addr) | 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 | (d->devfn << 8) | (addr & ~3); | 1356 | (d->devfn << 8) | (addr & ~3); |
1317 | return pci_data_read(s, addr & 3, 1); | 1357 | return pci_data_read(s, addr & 3, 1); |
1318 | } | 1358 | } |
@@ -1432,9 +1472,9 @@ static void pci_bios_init_device(PCIDevice *d) | @@ -1432,9 +1472,9 @@ static void pci_bios_init_device(PCIDevice *d) | ||
1432 | */ | 1472 | */ |
1433 | void pci_bios_init(void) | 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 | uint8_t elcr[2]; | 1478 | uint8_t elcr[2]; |
1439 | 1479 | ||
1440 | pci_bios_io_addr = 0xc000; | 1480 | pci_bios_io_addr = 0xc000; |
@@ -1453,57 +1493,12 @@ void pci_bios_init(void) | @@ -1453,57 +1493,12 @@ void pci_bios_init(void) | ||
1453 | isa_outb(elcr[0], 0x4d0); | 1493 | isa_outb(elcr[0], 0x4d0); |
1454 | isa_outb(elcr[1], 0x4d1); | 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 | } |