tsi108_pci.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * (C) Copyright 2004 Tundra Semiconductor Corp.
  3. * Alex Bounine <alexandreb@tundra.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * PCI initialisation for the Tsi108 EMU board.
  25. */
  26. #include <config.h>
  27. #ifdef CONFIG_TSI108_PCI
  28. #include <common.h>
  29. #include <pci.h>
  30. #include <asm/io.h>
  31. #include <tsi108.h>
  32. struct pci_controller local_hose;
  33. void tsi108_clear_pci_error (void)
  34. {
  35. u32 err_stat, err_addr, pci_stat;
  36. /*
  37. * Quietly clear errors signalled as result of PCI/X configuration read
  38. * requests.
  39. */
  40. /* Read PB Error Log Registers */
  41. err_stat = *(volatile u32 *)(CFG_TSI108_CSR_BASE +
  42. TSI108_PB_REG_OFFSET + PB_ERRCS);
  43. err_addr = *(volatile u32 *)(CFG_TSI108_CSR_BASE +
  44. TSI108_PB_REG_OFFSET + PB_AERR);
  45. if (err_stat & PB_ERRCS_ES) {
  46. /* Clear PCI/X bus errors if applicable */
  47. if ((err_addr & 0xFF000000) == CFG_PCI_CFG_BASE) {
  48. /* Clear error flag */
  49. *(u32 *) (CFG_TSI108_CSR_BASE +
  50. TSI108_PB_REG_OFFSET + PB_ERRCS) =
  51. PB_ERRCS_ES;
  52. /* Clear read error reported in PB_ISR */
  53. *(u32 *) (CFG_TSI108_CSR_BASE +
  54. TSI108_PB_REG_OFFSET + PB_ISR) =
  55. PB_ISR_PBS_RD_ERR;
  56. /* Clear errors reported by PCI CSR (Normally Master Abort) */
  57. pci_stat = *(volatile u32 *)(CFG_TSI108_CSR_BASE +
  58. TSI108_PCI_REG_OFFSET +
  59. PCI_CSR);
  60. *(volatile u32 *)(CFG_TSI108_CSR_BASE +
  61. TSI108_PCI_REG_OFFSET + PCI_CSR) =
  62. pci_stat;
  63. *(volatile u32 *)(CFG_TSI108_CSR_BASE +
  64. TSI108_PCI_REG_OFFSET +
  65. PCI_IRP_STAT) = PCI_IRP_STAT_P_CSR;
  66. }
  67. }
  68. return;
  69. }
  70. unsigned int __get_pci_config_dword (u32 addr)
  71. {
  72. unsigned int retval;
  73. __asm__ __volatile__ (" lwbrx %0,0,%1\n"
  74. "1: eieio\n"
  75. "2:\n"
  76. ".section .fixup,\"ax\"\n"
  77. "3: li %0,-1\n"
  78. " b 2b\n"
  79. ".section __ex_table,\"a\"\n"
  80. " .align 2\n"
  81. " .long 1b,3b\n"
  82. ".text":"=r"(retval):"r"(addr));
  83. return (retval);
  84. }
  85. static int tsi108_read_config_dword (struct pci_controller *hose,
  86. pci_dev_t dev, int offset, u32 * value)
  87. {
  88. dev &= (CFG_PCI_CFG_SIZE - 1);
  89. dev |= (CFG_PCI_CFG_BASE | (offset & 0xfc));
  90. *value = __get_pci_config_dword(dev);
  91. if (0xFFFFFFFF == *value)
  92. tsi108_clear_pci_error ();
  93. return 0;
  94. }
  95. static int tsi108_write_config_dword (struct pci_controller *hose,
  96. pci_dev_t dev, int offset, u32 value)
  97. {
  98. dev &= (CFG_PCI_CFG_SIZE - 1);
  99. dev |= (CFG_PCI_CFG_BASE | (offset & 0xfc));
  100. out_le32 ((volatile unsigned *)dev, value);
  101. return 0;
  102. }
  103. void pci_init_board (void)
  104. {
  105. struct pci_controller *hose = (struct pci_controller *)&local_hose;
  106. hose->first_busno = 0;
  107. hose->last_busno = 0xff;
  108. pci_set_region (hose->regions + 0,
  109. CFG_PCI_MEMORY_BUS,
  110. CFG_PCI_MEMORY_PHYS,
  111. CFG_PCI_MEMORY_SIZE, PCI_REGION_MEM | PCI_REGION_MEMORY);
  112. /* PCI memory space */
  113. pci_set_region (hose->regions + 1,
  114. CFG_PCI_MEM_BUS,
  115. CFG_PCI_MEM_PHYS, CFG_PCI_MEM_SIZE, PCI_REGION_MEM);
  116. /* PCI I/O space */
  117. pci_set_region (hose->regions + 2,
  118. CFG_PCI_IO_BUS,
  119. CFG_PCI_IO_PHYS, CFG_PCI_IO_SIZE, PCI_REGION_IO);
  120. hose->region_count = 3;
  121. pci_set_ops (hose,
  122. pci_hose_read_config_byte_via_dword,
  123. pci_hose_read_config_word_via_dword,
  124. tsi108_read_config_dword,
  125. pci_hose_write_config_byte_via_dword,
  126. pci_hose_write_config_word_via_dword,
  127. tsi108_write_config_dword);
  128. pci_register_hose (hose);
  129. hose->last_busno = pci_hose_scan (hose);
  130. debug ("Done PCI initialization\n");
  131. return;
  132. }
  133. #ifdef CONFIG_OF_FLAT_TREE
  134. void
  135. ft_pci_setup (void *blob, bd_t *bd)
  136. {
  137. u32 *p;
  138. int len;
  139. p = (u32 *)ft_get_prop (blob, "/" OF_TSI "/pci@1000/bus-range", &len);
  140. if (p != NULL) {
  141. p[0] = local_hose.first_busno;
  142. p[1] = local_hose.last_busno;
  143. }
  144. }
  145. #endif
  146. #endif /* CONFIG_TSI108_PCI */