pci.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*-----------------------------------------------------------------------------+
  2. |
  3. | This source code has been made available to you by IBM on an AS-IS
  4. | basis. Anyone receiving this source is licensed under IBM
  5. | copyrights to use it in any way he or she deems fit, including
  6. | copying it, modifying it, compiling it, and redistributing it either
  7. | with or without modifications. No license under IBM patents or
  8. | patent applications is to be implied by the copyright license.
  9. |
  10. | Any user of this software should understand that IBM cannot provide
  11. | technical support for this software and will not be responsible for
  12. | any consequences resulting from the use of this software.
  13. |
  14. | Any person who transfers this source code or any derivative work
  15. | must include the IBM copyright notice, this paragraph, and the
  16. | preceding two paragraphs in the transferred software.
  17. |
  18. | COPYRIGHT I B M CORPORATION 1995
  19. | LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
  20. +-----------------------------------------------------------------------------*/
  21. /*
  22. * Adapted for PIP405 03.07.01
  23. * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
  24. *
  25. * TODO: Clean-up
  26. */
  27. #include <common.h>
  28. #include <pci.h>
  29. #include "isa.h"
  30. #ifdef CONFIG_405GP
  31. #ifdef CONFIG_PCI
  32. DECLARE_GLOBAL_DATA_PTR;
  33. #include "piix4_pci.h"
  34. #include "pci_parts.h"
  35. void pci_pip405_write_regs(struct pci_controller *hose, pci_dev_t dev,
  36. struct pci_config_table *entry)
  37. {
  38. struct pci_pip405_config_entry *table;
  39. int i;
  40. table = (struct pci_pip405_config_entry*) entry->priv[0];
  41. for (i=0; table[i].width; i++)
  42. {
  43. #ifdef DEBUG
  44. printf("Reg 0x%02X Value 0x%08lX Width %02d written\n",
  45. table[i].index, table[i].val, table[i].width);
  46. #endif
  47. switch(table[i].width)
  48. {
  49. case 1: pci_hose_write_config_byte(hose, dev, table[i].index, table[i].val); break;
  50. case 2: pci_hose_write_config_word(hose, dev, table[i].index, table[i].val); break;
  51. case 4: pci_hose_write_config_dword(hose, dev, table[i].index, table[i].val); break;
  52. }
  53. }
  54. }
  55. static void pci_pip405_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  56. {
  57. unsigned char int_line = 0xff;
  58. unsigned char pin;
  59. /*
  60. * Write pci interrupt line register
  61. */
  62. if(PCI_DEV(dev)==0) /* Device0 = PPC405 -> skip */
  63. return;
  64. pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &pin);
  65. if ((pin == 0) || (pin > 4))
  66. return;
  67. int_line = ((PCI_DEV(dev) + (pin-1) + 10) % 4) + 28;
  68. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
  69. #ifdef DEBUG
  70. printf("Fixup IRQ: dev %d (%x) int line %d 0x%x\n",
  71. PCI_DEV(dev),dev,int_line,int_line);
  72. #endif
  73. }
  74. extern void pci_405gp_init(struct pci_controller *hose);
  75. static struct pci_controller hose = {
  76. config_table: pci_pip405_config_table,
  77. fixup_irq: pci_pip405_fixup_irq,
  78. };
  79. static void reloc_pci_cfg_table(struct pci_config_table *table)
  80. {
  81. unsigned long addr;
  82. for (; table && table->vendor; table++) {
  83. addr = (ulong) (table->config_device) + gd->reloc_off;
  84. #ifdef DEBUG
  85. printf ("device \"%d\": 0x%08lx => 0x%08lx\n",
  86. table->device, (ulong) (table->config_device), addr);
  87. #endif
  88. table->config_device =
  89. (void (*)(struct pci_controller* hose, pci_dev_t dev,
  90. struct pci_config_table *))addr;
  91. table->priv[0]+=gd->reloc_off;
  92. }
  93. }
  94. void pci_init_board(void)
  95. {
  96. /*we want the ptrs to RAM not flash (ie don't use init list)*/
  97. hose.fixup_irq = pci_pip405_fixup_irq;
  98. hose.config_table = pci_pip405_config_table;
  99. reloc_pci_cfg_table(hose.config_table);
  100. #ifdef DEBUG
  101. printf("Init PCI: fixup_irq=%p config_table=%p hose=%p\n",pci_pip405_fixup_irq,pci_pip405_config_table,hose);
  102. #endif
  103. pci_405gp_init(&hose);
  104. }
  105. #endif /* CONFIG_PCI */
  106. #endif /* CONFIG_405GP */