tsi108_pci.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #ifdef CONFIG_OF_FLAT_TREE
  33. #include <ft_build.h>
  34. #endif
  35. struct pci_controller local_hose;
  36. void tsi108_clear_pci_error (void)
  37. {
  38. u32 err_stat, err_addr, pci_stat;
  39. /*
  40. * Quietly clear errors signalled as result of PCI/X configuration read
  41. * requests.
  42. */
  43. /* Read PB Error Log Registers */
  44. err_stat = *(volatile u32 *)(CFG_TSI108_CSR_BASE +
  45. TSI108_PB_REG_OFFSET + PB_ERRCS);
  46. err_addr = *(volatile u32 *)(CFG_TSI108_CSR_BASE +
  47. TSI108_PB_REG_OFFSET + PB_AERR);
  48. if (err_stat & PB_ERRCS_ES) {
  49. /* Clear PCI/X bus errors if applicable */
  50. if ((err_addr & 0xFF000000) == CFG_PCI_CFG_BASE) {
  51. /* Clear error flag */
  52. *(u32 *) (CFG_TSI108_CSR_BASE +
  53. TSI108_PB_REG_OFFSET + PB_ERRCS) =
  54. PB_ERRCS_ES;
  55. /* Clear read error reported in PB_ISR */
  56. *(u32 *) (CFG_TSI108_CSR_BASE +
  57. TSI108_PB_REG_OFFSET + PB_ISR) =
  58. PB_ISR_PBS_RD_ERR;
  59. /* Clear errors reported by PCI CSR (Normally Master Abort) */
  60. pci_stat = *(volatile u32 *)(CFG_TSI108_CSR_BASE +
  61. TSI108_PCI_REG_OFFSET +
  62. PCI_CSR);
  63. *(volatile u32 *)(CFG_TSI108_CSR_BASE +
  64. TSI108_PCI_REG_OFFSET + PCI_CSR) =
  65. pci_stat;
  66. *(volatile u32 *)(CFG_TSI108_CSR_BASE +
  67. TSI108_PCI_REG_OFFSET +
  68. PCI_IRP_STAT) = PCI_IRP_STAT_P_CSR;
  69. }
  70. }
  71. return;
  72. }
  73. unsigned int __get_pci_config_dword (u32 addr)
  74. {
  75. unsigned int retval;
  76. __asm__ __volatile__ (" lwbrx %0,0,%1\n"
  77. "1: eieio\n"
  78. "2:\n"
  79. ".section .fixup,\"ax\"\n"
  80. "3: li %0,-1\n"
  81. " b 2b\n"
  82. ".section __ex_table,\"a\"\n"
  83. " .align 2\n"
  84. " .long 1b,3b\n"
  85. ".text":"=r"(retval):"r"(addr));
  86. return (retval);
  87. }
  88. static int tsi108_read_config_dword (struct pci_controller *hose,
  89. pci_dev_t dev, int offset, u32 * value)
  90. {
  91. dev &= (CFG_PCI_CFG_SIZE - 1);
  92. dev |= (CFG_PCI_CFG_BASE | (offset & 0xfc));
  93. *value = __get_pci_config_dword(dev);
  94. if (0xFFFFFFFF == *value)
  95. tsi108_clear_pci_error ();
  96. return 0;
  97. }
  98. static int tsi108_write_config_dword (struct pci_controller *hose,
  99. pci_dev_t dev, int offset, u32 value)
  100. {
  101. dev &= (CFG_PCI_CFG_SIZE - 1);
  102. dev |= (CFG_PCI_CFG_BASE | (offset & 0xfc));
  103. out_le32 ((volatile unsigned *)dev, value);
  104. return 0;
  105. }
  106. void pci_init_board (void)
  107. {
  108. struct pci_controller *hose = (struct pci_controller *)&local_hose;
  109. hose->first_busno = 0;
  110. hose->last_busno = 0xff;
  111. pci_set_region (hose->regions + 0,
  112. CFG_PCI_MEMORY_BUS,
  113. CFG_PCI_MEMORY_PHYS,
  114. CFG_PCI_MEMORY_SIZE, PCI_REGION_MEM | PCI_REGION_MEMORY);
  115. /* PCI memory space */
  116. pci_set_region (hose->regions + 1,
  117. CFG_PCI_MEM_BUS,
  118. CFG_PCI_MEM_PHYS, CFG_PCI_MEM_SIZE, PCI_REGION_MEM);
  119. /* PCI I/O space */
  120. pci_set_region (hose->regions + 2,
  121. CFG_PCI_IO_BUS,
  122. CFG_PCI_IO_PHYS, CFG_PCI_IO_SIZE, PCI_REGION_IO);
  123. hose->region_count = 3;
  124. pci_set_ops (hose,
  125. pci_hose_read_config_byte_via_dword,
  126. pci_hose_read_config_word_via_dword,
  127. tsi108_read_config_dword,
  128. pci_hose_write_config_byte_via_dword,
  129. pci_hose_write_config_word_via_dword,
  130. tsi108_write_config_dword);
  131. pci_register_hose (hose);
  132. hose->last_busno = pci_hose_scan (hose);
  133. debug ("Done PCI initialization\n");
  134. return;
  135. }
  136. #ifdef CONFIG_OF_FLAT_TREE
  137. void
  138. ft_pci_setup (void *blob, bd_t *bd)
  139. {
  140. u32 *p;
  141. int len;
  142. p = (u32 *)ft_get_prop (blob, "/" OF_TSI "/pci@1000/bus-range", &len);
  143. if (p != NULL) {
  144. p[0] = local_hose.first_busno;
  145. p[1] = local_hose.last_busno;
  146. }
  147. }
  148. #endif
  149. #endif /* CONFIG_TSI108_PCI */