tsi108_pci.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * (C) Copyright 2004 Tundra Semiconductor Corp.
  3. * Alex Bounine <alexandreb@tundra.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * PCI initialisation for the Tsi108 EMU board.
  9. */
  10. #include <config.h>
  11. #include <common.h>
  12. #include <pci.h>
  13. #include <asm/io.h>
  14. #include <tsi108.h>
  15. #if defined(CONFIG_OF_LIBFDT)
  16. #include <libfdt.h>
  17. #include <fdt_support.h>
  18. #endif
  19. struct pci_controller local_hose;
  20. void tsi108_clear_pci_error (void)
  21. {
  22. u32 err_stat, err_addr, pci_stat;
  23. /*
  24. * Quietly clear errors signalled as result of PCI/X configuration read
  25. * requests.
  26. */
  27. /* Read PB Error Log Registers */
  28. err_stat = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE +
  29. TSI108_PB_REG_OFFSET + PB_ERRCS);
  30. err_addr = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE +
  31. TSI108_PB_REG_OFFSET + PB_AERR);
  32. if (err_stat & PB_ERRCS_ES) {
  33. /* Clear PCI/X bus errors if applicable */
  34. if ((err_addr & 0xFF000000) == CONFIG_SYS_PCI_CFG_BASE) {
  35. /* Clear error flag */
  36. *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE +
  37. TSI108_PB_REG_OFFSET + PB_ERRCS) =
  38. PB_ERRCS_ES;
  39. /* Clear read error reported in PB_ISR */
  40. *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE +
  41. TSI108_PB_REG_OFFSET + PB_ISR) =
  42. PB_ISR_PBS_RD_ERR;
  43. /* Clear errors reported by PCI CSR (Normally Master Abort) */
  44. pci_stat = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE +
  45. TSI108_PCI_REG_OFFSET +
  46. PCI_CSR);
  47. *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE +
  48. TSI108_PCI_REG_OFFSET + PCI_CSR) =
  49. pci_stat;
  50. *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE +
  51. TSI108_PCI_REG_OFFSET +
  52. PCI_IRP_STAT) = PCI_IRP_STAT_P_CSR;
  53. }
  54. }
  55. return;
  56. }
  57. unsigned int __get_pci_config_dword (u32 addr)
  58. {
  59. unsigned int retval;
  60. __asm__ __volatile__ (" lwbrx %0,0,%1\n"
  61. "1: eieio\n"
  62. "2:\n"
  63. ".section .fixup,\"ax\"\n"
  64. "3: li %0,-1\n"
  65. " b 2b\n"
  66. ".section __ex_table,\"a\"\n"
  67. " .align 2\n"
  68. " .long 1b,3b\n"
  69. ".section .text.__get_pci_config_dword"
  70. : "=r"(retval) : "r"(addr));
  71. return (retval);
  72. }
  73. static int tsi108_read_config_dword (struct pci_controller *hose,
  74. pci_dev_t dev, int offset, u32 * value)
  75. {
  76. dev &= (CONFIG_SYS_PCI_CFG_SIZE - 1);
  77. dev |= (CONFIG_SYS_PCI_CFG_BASE | (offset & 0xfc));
  78. *value = __get_pci_config_dword(dev);
  79. if (0xFFFFFFFF == *value)
  80. tsi108_clear_pci_error ();
  81. return 0;
  82. }
  83. static int tsi108_write_config_dword (struct pci_controller *hose,
  84. pci_dev_t dev, int offset, u32 value)
  85. {
  86. dev &= (CONFIG_SYS_PCI_CFG_SIZE - 1);
  87. dev |= (CONFIG_SYS_PCI_CFG_BASE | (offset & 0xfc));
  88. out_le32 ((volatile unsigned *)dev, value);
  89. return 0;
  90. }
  91. void pci_init_board (void)
  92. {
  93. struct pci_controller *hose = (struct pci_controller *)&local_hose;
  94. hose->first_busno = 0;
  95. hose->last_busno = 0xff;
  96. pci_set_region (hose->regions + 0,
  97. CONFIG_SYS_PCI_MEMORY_BUS,
  98. CONFIG_SYS_PCI_MEMORY_PHYS,
  99. CONFIG_SYS_PCI_MEMORY_SIZE, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
  100. /* PCI memory space */
  101. pci_set_region (hose->regions + 1,
  102. CONFIG_SYS_PCI_MEM_BUS,
  103. CONFIG_SYS_PCI_MEM_PHYS, CONFIG_SYS_PCI_MEM_SIZE, PCI_REGION_MEM);
  104. /* PCI I/O space */
  105. pci_set_region (hose->regions + 2,
  106. CONFIG_SYS_PCI_IO_BUS,
  107. CONFIG_SYS_PCI_IO_PHYS, CONFIG_SYS_PCI_IO_SIZE, PCI_REGION_IO);
  108. hose->region_count = 3;
  109. pci_set_ops (hose,
  110. pci_hose_read_config_byte_via_dword,
  111. pci_hose_read_config_word_via_dword,
  112. tsi108_read_config_dword,
  113. pci_hose_write_config_byte_via_dword,
  114. pci_hose_write_config_word_via_dword,
  115. tsi108_write_config_dword);
  116. pci_register_hose (hose);
  117. hose->last_busno = pci_hose_scan (hose);
  118. debug ("Done PCI initialization\n");
  119. return;
  120. }
  121. #if defined(CONFIG_OF_LIBFDT)
  122. void ft_pci_setup(void *blob, bd_t *bd)
  123. {
  124. int nodeoffset;
  125. int tmp[2];
  126. const char *path;
  127. nodeoffset = fdt_path_offset(blob, "/aliases");
  128. if (nodeoffset >= 0) {
  129. path = fdt_getprop(blob, nodeoffset, "pci", NULL);
  130. if (path) {
  131. tmp[0] = cpu_to_be32(local_hose.first_busno);
  132. tmp[1] = cpu_to_be32(local_hose.last_busno);
  133. do_fixup_by_path(blob, path, "bus-range",
  134. &tmp, sizeof(tmp), 1);
  135. }
  136. }
  137. }
  138. #endif /* CONFIG_OF_LIBFDT */