harrier.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * arch/ppc/syslib/harrier.c
  3. *
  4. * Motorola MCG Harrier northbridge/memory controller support
  5. *
  6. * Author: Dale Farnsworth
  7. * dale.farnsworth@mvista.com
  8. *
  9. * 2001 (c) MontaVista, Software, Inc. This file is licensed under
  10. * the terms of the GNU General Public License version 2. This program
  11. * is licensed "as is" without any warranty of any kind, whether express
  12. * or implied.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/pci.h>
  17. #include <linux/harrier_defs.h>
  18. #include <asm/byteorder.h>
  19. #include <asm/io.h>
  20. #include <asm/irq.h>
  21. #include <asm/pci.h>
  22. #include <asm/pci-bridge.h>
  23. #include <asm/open_pic.h>
  24. #include <asm/harrier.h>
  25. /* define defaults for inbound windows */
  26. #define HARRIER_ITAT_DEFAULT (HARRIER_ITAT_ENA | \
  27. HARRIER_ITAT_MEM | \
  28. HARRIER_ITAT_WPE | \
  29. HARRIER_ITAT_GBL)
  30. #define HARRIER_MPAT_DEFAULT (HARRIER_ITAT_ENA | \
  31. HARRIER_ITAT_MEM | \
  32. HARRIER_ITAT_WPE | \
  33. HARRIER_ITAT_GBL)
  34. /*
  35. * Initialize the inbound window size on a non-monarch harrier.
  36. */
  37. void __init harrier_setup_nonmonarch(uint ppc_reg_base, uint in0_size)
  38. {
  39. u16 temps;
  40. u32 temp;
  41. if (in0_size > HARRIER_ITSZ_2GB) {
  42. printk
  43. ("harrier_setup_nonmonarch: Invalid window size code %d\n",
  44. in0_size);
  45. return;
  46. }
  47. /* Clear the PCI memory enable bit. If we don't, then when the
  48. * inbound windows are enabled below, the corresponding BARs will be
  49. * "live" and start answering to PCI memory reads from their default
  50. * addresses (0x0), which overlap with system RAM.
  51. */
  52. temps = in_le16((u16 *) (ppc_reg_base +
  53. HARRIER_XCSR_CONFIG(PCI_COMMAND)));
  54. temps &= ~(PCI_COMMAND_MEMORY);
  55. out_le16((u16 *) (ppc_reg_base + HARRIER_XCSR_CONFIG(PCI_COMMAND)),
  56. temps);
  57. /* Setup a non-prefetchable inbound window */
  58. out_le32((u32 *) (ppc_reg_base +
  59. HARRIER_XCSR_CONFIG(HARRIER_ITSZ0_OFF)), in0_size);
  60. temp = in_le32((u32 *) (ppc_reg_base +
  61. HARRIER_XCSR_CONFIG(HARRIER_ITAT0_OFF)));
  62. temp &= ~HARRIER_ITAT_PRE;
  63. temp |= HARRIER_ITAT_DEFAULT;
  64. out_le32((u32 *) (ppc_reg_base +
  65. HARRIER_XCSR_CONFIG(HARRIER_ITAT0_OFF)), temp);
  66. /* Enable the message passing block */
  67. temp = in_le32((u32 *) (ppc_reg_base +
  68. HARRIER_XCSR_CONFIG(HARRIER_MPAT_OFF)));
  69. temp |= HARRIER_MPAT_DEFAULT;
  70. out_le32((u32 *) (ppc_reg_base +
  71. HARRIER_XCSR_CONFIG(HARRIER_MPAT_OFF)), temp);
  72. }
  73. void __init harrier_release_eready(uint ppc_reg_base)
  74. {
  75. ulong temp;
  76. /*
  77. * Set EREADY to allow the line to be pulled up after everyone is
  78. * ready.
  79. */
  80. temp = in_be32((uint *) (ppc_reg_base + HARRIER_MISC_CSR_OFF));
  81. temp |= HARRIER_EREADY;
  82. out_be32((uint *) (ppc_reg_base + HARRIER_MISC_CSR_OFF), temp);
  83. }
  84. void __init harrier_wait_eready(uint ppc_reg_base)
  85. {
  86. ulong temp;
  87. /*
  88. * Poll the ERDYS line until it goes high to indicate that all
  89. * non-monarch PrPMCs are ready for bus enumeration (or that there are
  90. * no PrPMCs present).
  91. */
  92. /* FIXME: Add a timeout of some kind to prevent endless waits. */
  93. do {
  94. temp = in_be32((uint *) (ppc_reg_base + HARRIER_MISC_CSR_OFF));
  95. } while (!(temp & HARRIER_ERDYS));
  96. }
  97. /*
  98. * Initialize the Motorola MCG Harrier host bridge.
  99. *
  100. * This means setting up the PPC bus to PCI memory and I/O space mappings,
  101. * setting the PCI memory space address of the MPIC (mapped straight
  102. * through), and ioremap'ing the mpic registers.
  103. * 'OpenPIC_Addr' will be set correctly by this routine.
  104. * This routine will not change the PCI_CONFIG_ADDR or PCI_CONFIG_DATA
  105. * addresses and assumes that the mapping of PCI memory space back to system
  106. * memory is set up correctly by PPCBug.
  107. */
  108. int __init
  109. harrier_init(struct pci_controller *hose,
  110. uint ppc_reg_base,
  111. ulong processor_pci_mem_start,
  112. ulong processor_pci_mem_end,
  113. ulong processor_pci_io_start,
  114. ulong processor_pci_io_end, ulong processor_mpic_base)
  115. {
  116. uint addr, offset;
  117. /*
  118. * Some sanity checks...
  119. */
  120. if (((processor_pci_mem_start & 0xffff0000) != processor_pci_mem_start)
  121. || ((processor_pci_io_start & 0xffff0000) !=
  122. processor_pci_io_start)) {
  123. printk("harrier_init: %s\n",
  124. "PPC to PCI mappings must start on 64 KB boundaries");
  125. return -1;
  126. }
  127. if (((processor_pci_mem_end & 0x0000ffff) != 0x0000ffff) ||
  128. ((processor_pci_io_end & 0x0000ffff) != 0x0000ffff)) {
  129. printk("harrier_init: PPC to PCI mappings %s\n",
  130. "must end just before a 64 KB boundaries");
  131. return -1;
  132. }
  133. if (((processor_pci_mem_end - processor_pci_mem_start) !=
  134. (hose->mem_space.end - hose->mem_space.start)) ||
  135. ((processor_pci_io_end - processor_pci_io_start) !=
  136. (hose->io_space.end - hose->io_space.start))) {
  137. printk("harrier_init: %s\n",
  138. "PPC and PCI memory or I/O space sizes don't match");
  139. return -1;
  140. }
  141. if ((processor_mpic_base & 0xfffc0000) != processor_mpic_base) {
  142. printk("harrier_init: %s\n",
  143. "MPIC address must start on 256 KB boundary");
  144. return -1;
  145. }
  146. if ((pci_dram_offset & 0xffff0000) != pci_dram_offset) {
  147. printk("harrier_init: %s\n",
  148. "pci_dram_offset must be multiple of 64 KB");
  149. return -1;
  150. }
  151. /*
  152. * Program the OTAD/OTOF registers to set up the PCI Mem & I/O
  153. * space mappings. These are the mappings going from the processor to
  154. * the PCI bus.
  155. *
  156. * Note: Don't need to 'AND' start/end addresses with 0xffff0000
  157. * because sanity check above ensures that they are properly
  158. * aligned.
  159. */
  160. /* Set up PPC->PCI Mem mapping */
  161. addr = processor_pci_mem_start | (processor_pci_mem_end >> 16);
  162. #ifdef CONFIG_HARRIER_STORE_GATHERING
  163. offset = (hose->mem_space.start - processor_pci_mem_start) | 0x9a;
  164. #else
  165. offset = (hose->mem_space.start - processor_pci_mem_start) | 0x92;
  166. #endif
  167. out_be32((uint *) (ppc_reg_base + HARRIER_OTAD0_OFF), addr);
  168. out_be32((uint *) (ppc_reg_base + HARRIER_OTOF0_OFF), offset);
  169. /* Set up PPC->PCI I/O mapping -- Contiguous I/O space */
  170. addr = processor_pci_io_start | (processor_pci_io_end >> 16);
  171. offset = (hose->io_space.start - processor_pci_io_start) | 0x80;
  172. out_be32((uint *) (ppc_reg_base + HARRIER_OTAD1_OFF), addr);
  173. out_be32((uint *) (ppc_reg_base + HARRIER_OTOF1_OFF), offset);
  174. /* Enable MPIC */
  175. OpenPIC_Addr = (void *)processor_mpic_base;
  176. addr = (processor_mpic_base >> 16) | 1;
  177. out_be16((ushort *) (ppc_reg_base + HARRIER_MBAR_OFF), addr);
  178. out_8((u_char *) (ppc_reg_base + HARRIER_MPIC_CSR_OFF),
  179. HARRIER_MPIC_OPI_ENABLE);
  180. return 0;
  181. }
  182. /*
  183. * Find the amount of RAM present.
  184. * This assumes that PPCBug has initialized the memory controller (SMC)
  185. * on the Harrier correctly (i.e., it does no sanity checking).
  186. * It also assumes that the memory base registers are set to configure the
  187. * memory as contigous starting with "RAM A BASE", "RAM B BASE", etc.
  188. * however, RAM base registers can be skipped (e.g. A, B, C are set,
  189. * D is skipped but E is set is okay).
  190. */
  191. #define MB (1024*1024UL)
  192. static uint harrier_size_table[] __initdata = {
  193. 0 * MB, /* 0 ==> 0 MB */
  194. 32 * MB, /* 1 ==> 32 MB */
  195. 64 * MB, /* 2 ==> 64 MB */
  196. 64 * MB, /* 3 ==> 64 MB */
  197. 128 * MB, /* 4 ==> 128 MB */
  198. 128 * MB, /* 5 ==> 128 MB */
  199. 128 * MB, /* 6 ==> 128 MB */
  200. 256 * MB, /* 7 ==> 256 MB */
  201. 256 * MB, /* 8 ==> 256 MB */
  202. 256 * MB, /* 9 ==> 256 MB */
  203. 512 * MB, /* a ==> 512 MB */
  204. 512 * MB, /* b ==> 512 MB */
  205. 512 * MB, /* c ==> 512 MB */
  206. 1024 * MB, /* d ==> 1024 MB */
  207. 1024 * MB, /* e ==> 1024 MB */
  208. 2048 * MB, /* f ==> 2048 MB */
  209. };
  210. /*
  211. * *** WARNING: You MUST have a BAT set up to map in the XCSR regs ***
  212. *
  213. * Read the memory controller's registers to determine the amount of system
  214. * memory. Assumes that the memory controller registers are already mapped
  215. * into virtual memory--too early to use ioremap().
  216. */
  217. unsigned long __init harrier_get_mem_size(uint xcsr_base)
  218. {
  219. ulong last_addr;
  220. int i;
  221. uint vend_dev_id;
  222. uint *size_table;
  223. uint val;
  224. uint *csrp;
  225. uint size;
  226. int size_table_entries;
  227. vend_dev_id = in_be32((uint *) xcsr_base + PCI_VENDOR_ID);
  228. if (((vend_dev_id & 0xffff0000) >> 16) != PCI_VENDOR_ID_MOTOROLA) {
  229. printk("harrier_get_mem_size: %s (0x%x)\n",
  230. "Not a Motorola Memory Controller", vend_dev_id);
  231. return 0;
  232. }
  233. vend_dev_id &= 0x0000ffff;
  234. if (vend_dev_id == PCI_DEVICE_ID_MOTOROLA_HARRIER) {
  235. size_table = harrier_size_table;
  236. size_table_entries = sizeof(harrier_size_table) /
  237. sizeof(harrier_size_table[0]);
  238. } else {
  239. printk("harrier_get_mem_size: %s (0x%x)\n",
  240. "Not a Harrier", vend_dev_id);
  241. return 0;
  242. }
  243. last_addr = 0;
  244. csrp = (uint *) (xcsr_base + HARRIER_SDBA_OFF);
  245. for (i = 0; i < 8; i++) {
  246. val = in_be32(csrp++);
  247. if (val & 0x100) { /* If enabled */
  248. size = val >> HARRIER_SDB_SIZE_SHIFT;
  249. size &= HARRIER_SDB_SIZE_MASK;
  250. if (size >= size_table_entries) {
  251. break; /* Register not set correctly */
  252. }
  253. size = size_table[size];
  254. val &= ~(size - 1);
  255. val += size;
  256. if (val > last_addr) {
  257. last_addr = val;
  258. }
  259. }
  260. }
  261. return last_addr;
  262. }