tsi108_pci.c 4.8 KB

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