harrier.c 8.7 KB

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