pci.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * Copyright (C) 2003 Motorola Inc.
  4. * Xianghua Xiao (x.xiao@motorola.com)
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. /*
  25. * PCI Configuration space access support for MPC8220 PCI Bridge
  26. */
  27. #include <common.h>
  28. #include <mpc8220.h>
  29. #include <pci.h>
  30. #include <asm/io.h>
  31. #if defined(CONFIG_PCI)
  32. /* System RAM mapped over PCI */
  33. #define CONFIG_PCI_SYS_MEM_BUS CFG_SDRAM_BASE
  34. #define CONFIG_PCI_SYS_MEM_PHYS CFG_SDRAM_BASE
  35. #define CONFIG_PCI_SYS_MEM_SIZE (1024 * 1024 * 1024)
  36. #define cfg_read(val, addr, type, op) *val = op((type)(addr));
  37. #define cfg_write(val, addr, type, op) op((type *)(addr), (val));
  38. #define PCI_OP(rw, size, type, op, mask) \
  39. int mpc8220_pci_##rw##_config_##size(struct pci_controller *hose, \
  40. pci_dev_t dev, int offset, type val) \
  41. { \
  42. u32 addr = 0; \
  43. u16 cfg_type = 0; \
  44. addr = ((offset & 0xfc) | cfg_type | (dev) | 0x80000000); \
  45. out_be32(hose->cfg_addr, addr); \
  46. __asm__ __volatile__("sync"); \
  47. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  48. out_be32(hose->cfg_addr, addr & 0x7fffffff); \
  49. __asm__ __volatile__("sync"); \
  50. return 0; \
  51. }
  52. PCI_OP(read, byte, u8 *, in_8, 3)
  53. PCI_OP(read, word, u16 *, in_le16, 2)
  54. PCI_OP(write, byte, u8, out_8, 3)
  55. PCI_OP(write, word, u16, out_le16, 2)
  56. PCI_OP(write, dword, u32, out_le32, 0)
  57. int mpc8220_pci_read_config_dword(struct pci_controller *hose, pci_dev_t dev,
  58. int offset, u32 *val)
  59. {
  60. u32 addr;
  61. u32 tmpv;
  62. u32 mask = 2; /* word access */
  63. /* Read lower 16 bits */
  64. addr = ((offset & 0xfc) | (dev) | 0x80000000);
  65. out_be32(hose->cfg_addr, addr);
  66. __asm__ __volatile__("sync");
  67. *val = (u32) in_le16((u16 *) (hose->cfg_data + (offset & mask)));
  68. out_be32(hose->cfg_addr, addr & 0x7fffffff);
  69. __asm__ __volatile__("sync");
  70. /* Read upper 16 bits */
  71. offset += 2;
  72. addr = ((offset & 0xfc) | 1 | (dev) | 0x80000000);
  73. out_be32(hose->cfg_addr, addr);
  74. __asm__ __volatile__("sync");
  75. tmpv = (u32) in_le16((u16 *) (hose->cfg_data + (offset & mask)));
  76. out_be32(hose->cfg_addr, addr & 0x7fffffff);
  77. __asm__ __volatile__("sync");
  78. /* combine results into dword value */
  79. *val = (tmpv << 16) | *val;
  80. return 0;
  81. }
  82. void
  83. pci_mpc8220_init(struct pci_controller *hose)
  84. {
  85. u32 win0, win1, win2;
  86. volatile mpc8220_xcpci_t *xcpci =
  87. (volatile mpc8220_xcpci_t *) MMAP_XCPCI;
  88. volatile pcfg8220_t *portcfg = (volatile pcfg8220_t *) MMAP_PCFG;
  89. win0 = (u32) CONFIG_PCI_MEM_PHYS;
  90. win1 = (u32) CONFIG_PCI_IO_PHYS;
  91. win2 = (u32) CONFIG_PCI_CFG_PHYS;
  92. /* Assert PCI reset */
  93. out_be32 (&xcpci->glb_stat_ctl, PCI_GLB_STAT_CTRL_PR);
  94. /* Disable prefetching but read-multiples will still prefetch */
  95. out_be32 (&xcpci->target_ctrl, 0x00000000);
  96. /* Initiator windows */
  97. out_be32 (&xcpci->init_win0, (win0 >> 16) | win0 | 0x003f0000);
  98. out_be32 (&xcpci->init_win1, ((win1 >> 16) | win1 ));
  99. out_be32 (&xcpci->init_win2, ((win2 >> 16) | win2 ));
  100. out_be32 (&xcpci->init_win_cfg,
  101. PCI_INIT_WIN_CFG_WIN0_CTRL_EN |
  102. PCI_INIT_WIN_CFG_WIN1_CTRL_EN | PCI_INIT_WIN_CFG_WIN1_CTRL_IO |
  103. PCI_INIT_WIN_CFG_WIN2_CTRL_EN | PCI_INIT_WIN_CFG_WIN2_CTRL_IO);
  104. out_be32 (&xcpci->init_ctrl, 0x00000000);
  105. /* Enable bus master and mem access */
  106. out_be32 (&xcpci->stat_cmd_reg, PCI_STAT_CMD_B | PCI_STAT_CMD_M);
  107. /* Cache line size and master latency */
  108. out_be32 (&xcpci->bist_htyp_lat_cshl, (0xf8 << PCI_CFG1_LT_SHIFT));
  109. out_be32 (&xcpci->base0, PCI_BASE_ADDR_REG0); /* 256MB - MBAR space */
  110. out_be32 (&xcpci->base1, PCI_BASE_ADDR_REG1); /* 1GB - SDRAM space */
  111. out_be32 (&xcpci->target_bar0,
  112. PCI_TARGET_BASE_ADDR_REG0 | PCI_TARGET_BASE_ADDR_EN);
  113. out_be32 (&xcpci->target_bar1,
  114. PCI_TARGET_BASE_ADDR_REG1 | PCI_TARGET_BASE_ADDR_EN);
  115. /* Deassert reset bit */
  116. out_be32 (&xcpci->glb_stat_ctl, 0x00000000);
  117. /* Enable PCI bus master support */
  118. /* Set PCIGNT1, PCIREQ1, PCIREQ0/PCIGNTIN, PCIGNT0/PCIREQOUT,
  119. PCIREQ2, PCIGNT2 */
  120. out_be32((volatile u32 *)&portcfg->pcfg3,
  121. (in_be32((volatile u32 *)&portcfg->pcfg3) & 0xFC3FCE7F));
  122. out_be32((volatile u32 *)&portcfg->pcfg3,
  123. (in_be32((volatile u32 *)&portcfg->pcfg3) | 0x01400180));
  124. hose->first_busno = 0;
  125. hose->last_busno = 0xff;
  126. pci_set_region(hose->regions + 0,
  127. CONFIG_PCI_MEM_BUS,
  128. CONFIG_PCI_MEM_PHYS,
  129. CONFIG_PCI_MEM_SIZE,
  130. PCI_REGION_MEM);
  131. pci_set_region(hose->regions + 1,
  132. CONFIG_PCI_IO_BUS,
  133. CONFIG_PCI_IO_PHYS,
  134. CONFIG_PCI_IO_SIZE,
  135. PCI_REGION_IO);
  136. pci_set_region(hose->regions + 2,
  137. CONFIG_PCI_SYS_MEM_BUS,
  138. CONFIG_PCI_SYS_MEM_PHYS,
  139. CONFIG_PCI_SYS_MEM_SIZE,
  140. PCI_REGION_MEM | PCI_REGION_MEMORY);
  141. hose->region_count = 3;
  142. hose->cfg_addr = &(xcpci->cfg_adr);
  143. hose->cfg_data = CONFIG_PCI_CFG_BUS;
  144. pci_set_ops(hose,
  145. mpc8220_pci_read_config_byte,
  146. mpc8220_pci_read_config_word,
  147. mpc8220_pci_read_config_dword,
  148. mpc8220_pci_write_config_byte,
  149. mpc8220_pci_write_config_word,
  150. mpc8220_pci_write_config_dword);
  151. /* Hose scan */
  152. pci_register_hose(hose);
  153. hose->last_busno = pci_hose_scan(hose);
  154. out_be32 (&xcpci->base0, PCI_BASE_ADDR_REG0); /* 256MB - MBAR space */
  155. out_be32 (&xcpci->base1, PCI_BASE_ADDR_REG1); /* 1GB - SDRAM space */
  156. }
  157. #endif /* CONFIG_PCI */