hawk_common.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * Common Motorola PowerPlus Platform--really Falcon/Raven or HAWK.
  3. *
  4. * Author: Mark A. Greer
  5. * mgreer@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 <asm/byteorder.h>
  16. #include <asm/io.h>
  17. #include <asm/irq.h>
  18. #include <asm/pci.h>
  19. #include <asm/pci-bridge.h>
  20. #include <asm/open_pic.h>
  21. #include <asm/hawk.h>
  22. /*
  23. * The Falcon/Raven and HAWK has 4 sets of registers:
  24. * 1) PPC Registers which define the mappings from PPC bus to PCI bus,
  25. * etc.
  26. * 2) PCI Registers which define the mappings from PCI bus to PPC bus and the
  27. * MPIC base address.
  28. * 3) MPIC registers.
  29. * 4) System Memory Controller (SMC) registers.
  30. */
  31. /*
  32. * Initialize the Motorola MCG Raven or HAWK host bridge.
  33. *
  34. * This means setting up the PPC bus to PCI memory and I/O space mappings,
  35. * setting the PCI memory space address of the MPIC (mapped straight
  36. * through), and ioremap'ing the mpic registers.
  37. * This routine will set the PCI_CONFIG_ADDR or PCI_CONFIG_DATA
  38. * addresses based on the PCI I/O address that is passed in.
  39. * 'OpenPIC_Addr' will be set correctly by this routine.
  40. */
  41. int __init
  42. hawk_init(struct pci_controller *hose,
  43. uint ppc_reg_base,
  44. ulong processor_pci_mem_start,
  45. ulong processor_pci_mem_end,
  46. ulong processor_pci_io_start,
  47. ulong processor_pci_io_end,
  48. ulong processor_mpic_base)
  49. {
  50. uint addr, offset;
  51. /*
  52. * Some sanity checks...
  53. */
  54. if (((processor_pci_mem_start&0xffff0000) != processor_pci_mem_start) ||
  55. ((processor_pci_io_start &0xffff0000) != processor_pci_io_start)) {
  56. printk("hawk_init: %s\n",
  57. "PPC to PCI mappings must start on 64 KB boundaries");
  58. return -1;
  59. }
  60. if (((processor_pci_mem_end &0x0000ffff) != 0x0000ffff) ||
  61. ((processor_pci_io_end &0x0000ffff) != 0x0000ffff)) {
  62. printk("hawk_init: PPC to PCI mappings %s\n",
  63. "must end just before a 64 KB boundaries");
  64. return -1;
  65. }
  66. if (((processor_pci_mem_end - processor_pci_mem_start) !=
  67. (hose->mem_space.end - hose->mem_space.start)) ||
  68. ((processor_pci_io_end - processor_pci_io_start) !=
  69. (hose->io_space.end - hose->io_space.start))) {
  70. printk("hawk_init: %s\n",
  71. "PPC and PCI memory or I/O space sizes don't match");
  72. return -1;
  73. }
  74. if ((processor_mpic_base & 0xfffc0000) != processor_mpic_base) {
  75. printk("hawk_init: %s\n",
  76. "MPIC address must start on 256 MB boundary");
  77. return -1;
  78. }
  79. if ((pci_dram_offset & 0xffff0000) != pci_dram_offset) {
  80. printk("hawk_init: %s\n",
  81. "pci_dram_offset must be multiple of 64 KB");
  82. return -1;
  83. }
  84. /*
  85. * Disable previous PPC->PCI mappings.
  86. */
  87. out_be32((uint *)(ppc_reg_base + HAWK_PPC_XSOFF0_OFF), 0x00000000);
  88. out_be32((uint *)(ppc_reg_base + HAWK_PPC_XSOFF1_OFF), 0x00000000);
  89. out_be32((uint *)(ppc_reg_base + HAWK_PPC_XSOFF2_OFF), 0x00000000);
  90. out_be32((uint *)(ppc_reg_base + HAWK_PPC_XSOFF3_OFF), 0x00000000);
  91. /*
  92. * Program the XSADD/XSOFF registers to set up the PCI Mem & I/O
  93. * space mappings. These are the mappings going from the processor to
  94. * the PCI bus.
  95. *
  96. * Note: Don't need to 'AND' start/end addresses with 0xffff0000
  97. * because sanity check above ensures that they are properly
  98. * aligned.
  99. */
  100. /* Set up PPC->PCI Mem mapping */
  101. addr = processor_pci_mem_start | (processor_pci_mem_end >> 16);
  102. offset = (hose->mem_space.start - processor_pci_mem_start) | 0xd2;
  103. out_be32((uint *)(ppc_reg_base + HAWK_PPC_XSADD0_OFF), addr);
  104. out_be32((uint *)(ppc_reg_base + HAWK_PPC_XSOFF0_OFF), offset);
  105. /* Set up PPC->MPIC mapping on the bridge */
  106. addr = processor_mpic_base |
  107. (((processor_mpic_base + HAWK_MPIC_SIZE) >> 16) - 1);
  108. /* No write posting for this PCI Mem space */
  109. offset = (hose->mem_space.start - processor_pci_mem_start) | 0xc2;
  110. out_be32((uint *)(ppc_reg_base + HAWK_PPC_XSADD1_OFF), addr);
  111. out_be32((uint *)(ppc_reg_base + HAWK_PPC_XSOFF1_OFF), offset);
  112. /* Set up PPC->PCI I/O mapping -- Contiguous I/O space */
  113. addr = processor_pci_io_start | (processor_pci_io_end >> 16);
  114. offset = (hose->io_space.start - processor_pci_io_start) | 0xc0;
  115. out_be32((uint *)(ppc_reg_base + HAWK_PPC_XSADD3_OFF), addr);
  116. out_be32((uint *)(ppc_reg_base + HAWK_PPC_XSOFF3_OFF), offset);
  117. hose->io_base_virt = (void *)ioremap(processor_pci_io_start,
  118. (processor_pci_io_end - processor_pci_io_start + 1));
  119. /*
  120. * Set up the indirect method of accessing PCI config space.
  121. * The PCI config addr/data pair based on start addr of PCI I/O space.
  122. */
  123. setup_indirect_pci(hose,
  124. processor_pci_io_start + HAWK_PCI_CONFIG_ADDR_OFF,
  125. processor_pci_io_start + HAWK_PCI_CONFIG_DATA_OFF);
  126. /*
  127. * Disable previous PCI->PPC mappings.
  128. */
  129. /* XXXX Put in mappings from PCI bus to processor bus XXXX */
  130. /*
  131. * Disable MPIC response to PCI I/O space (BAR 0).
  132. * Make MPIC respond to PCI Mem space at specified address.
  133. * (BAR 1).
  134. */
  135. early_write_config_dword(hose,
  136. 0,
  137. PCI_DEVFN(0,0),
  138. PCI_BASE_ADDRESS_0,
  139. 0x00000000 | 0x1);
  140. early_write_config_dword(hose,
  141. 0,
  142. PCI_DEVFN(0,0),
  143. PCI_BASE_ADDRESS_1,
  144. (processor_mpic_base -
  145. processor_pci_mem_start +
  146. hose->mem_space.start) | 0x0);
  147. /* Map MPIC into vitual memory */
  148. OpenPIC_Addr = ioremap(processor_mpic_base, HAWK_MPIC_SIZE);
  149. return 0;
  150. }
  151. /*
  152. * Find the amount of RAM present.
  153. * This assumes that PPCBug has initialized the memory controller (SMC)
  154. * on the Falcon/HAWK correctly (i.e., it does no sanity checking).
  155. * It also assumes that the memory base registers are set to configure the
  156. * memory as contigous starting with "RAM A BASE", "RAM B BASE", etc.
  157. * however, RAM base registers can be skipped (e.g. A, B, C are set,
  158. * D is skipped but E is set is okay).
  159. */
  160. #define MB (1024*1024)
  161. static uint reg_offset_table[] __initdata = {
  162. HAWK_SMC_RAM_A_SIZE_REG_OFF,
  163. HAWK_SMC_RAM_B_SIZE_REG_OFF,
  164. HAWK_SMC_RAM_C_SIZE_REG_OFF,
  165. HAWK_SMC_RAM_D_SIZE_REG_OFF,
  166. HAWK_SMC_RAM_E_SIZE_REG_OFF,
  167. HAWK_SMC_RAM_F_SIZE_REG_OFF,
  168. HAWK_SMC_RAM_G_SIZE_REG_OFF,
  169. HAWK_SMC_RAM_H_SIZE_REG_OFF
  170. };
  171. static uint falcon_size_table[] __initdata = {
  172. 0 * MB, /* 0 ==> 0 MB */
  173. 16 * MB, /* 1 ==> 16 MB */
  174. 32 * MB, /* 2 ==> 32 MB */
  175. 64 * MB, /* 3 ==> 64 MB */
  176. 128 * MB, /* 4 ==> 128 MB */
  177. 256 * MB, /* 5 ==> 256 MB */
  178. 1024 * MB, /* 6 ==> 1024 MB (1 GB) */
  179. };
  180. static uint hawk_size_table[] __initdata = {
  181. 0 * MB, /* 0 ==> 0 MB */
  182. 32 * MB, /* 1 ==> 32 MB */
  183. 64 * MB, /* 2 ==> 64 MB */
  184. 64 * MB, /* 3 ==> 64 MB */
  185. 128 * MB, /* 4 ==> 128 MB */
  186. 128 * MB, /* 5 ==> 128 MB */
  187. 128 * MB, /* 6 ==> 128 MB */
  188. 256 * MB, /* 7 ==> 256 MB */
  189. 256 * MB, /* 8 ==> 256 MB */
  190. 512 * MB, /* 9 ==> 512 MB */
  191. };
  192. /*
  193. * *** WARNING: You MUST have a BAT set up to map in the SMC regs ***
  194. *
  195. * Read the memory controller's registers to determine the amount of system
  196. * memory. Assumes that the memory controller registers are already mapped
  197. * into virtual memory--too early to use ioremap().
  198. */
  199. unsigned long __init
  200. hawk_get_mem_size(uint smc_base)
  201. {
  202. unsigned long total;
  203. int i, size_table_entries, reg_limit;
  204. uint vend_dev_id;
  205. uint *size_table;
  206. u_char val;
  207. vend_dev_id = in_be32((uint *)smc_base + PCI_VENDOR_ID);
  208. if (((vend_dev_id & 0xffff0000) >> 16) != PCI_VENDOR_ID_MOTOROLA) {
  209. printk("hawk_get_mem_size: %s (0x%x)\n",
  210. "Not a Motorola Memory Controller", vend_dev_id);
  211. return 0;
  212. }
  213. vend_dev_id &= 0x0000ffff;
  214. if (vend_dev_id == PCI_DEVICE_ID_MOTOROLA_FALCON) {
  215. size_table = falcon_size_table;
  216. size_table_entries = sizeof(falcon_size_table) /
  217. sizeof(falcon_size_table[0]);
  218. reg_limit = FALCON_SMC_REG_COUNT;
  219. }
  220. else if (vend_dev_id == PCI_DEVICE_ID_MOTOROLA_HAWK) {
  221. size_table = hawk_size_table;
  222. size_table_entries = sizeof(hawk_size_table) /
  223. sizeof(hawk_size_table[0]);
  224. reg_limit = HAWK_SMC_REG_COUNT;
  225. }
  226. else {
  227. printk("hawk_get_mem_size: %s (0x%x)\n",
  228. "Not a Falcon or HAWK", vend_dev_id);
  229. return 0;
  230. }
  231. total = 0;
  232. /* Check every reg because PPCBug may skip some */
  233. for (i=0; i<reg_limit; i++) {
  234. val = in_8((u_char *)(smc_base + reg_offset_table[i]));
  235. if (val & 0x80) { /* If enabled */
  236. val &= 0x0f;
  237. /* Don't go past end of size_table */
  238. if (val < size_table_entries) {
  239. total += size_table[val];
  240. }
  241. else { /* Register not set correctly */
  242. break;
  243. }
  244. }
  245. }
  246. return total;
  247. }
  248. int __init
  249. hawk_mpic_init(unsigned int pci_mem_offset)
  250. {
  251. unsigned short devid;
  252. unsigned int pci_membase;
  253. /* Check the first PCI device to see if it is a Raven or Hawk. */
  254. early_read_config_word(0, 0, 0, PCI_DEVICE_ID, &devid);
  255. switch (devid) {
  256. case PCI_DEVICE_ID_MOTOROLA_RAVEN:
  257. case PCI_DEVICE_ID_MOTOROLA_HAWK:
  258. break;
  259. default:
  260. OpenPIC_Addr = NULL;
  261. return 1;
  262. }
  263. /* Read the memory base register. */
  264. early_read_config_dword(0, 0, 0, PCI_BASE_ADDRESS_1, &pci_membase);
  265. if (pci_membase == 0) {
  266. OpenPIC_Addr = NULL;
  267. return 1;
  268. }
  269. /* Map the MPIC registers to virtual memory. */
  270. OpenPIC_Addr = ioremap(pci_membase + pci_mem_offset, 0x22000);
  271. return 0;
  272. }