pci.c 3.8 KB

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