hawk_common.c 9.1 KB

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