misc-spruce.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * arch/ppc/boot/spruce/misc.c
  3. *
  4. * Misc. bootloader code for IBM Spruce reference platform
  5. *
  6. * Authors: Johnnie Peters <jpeters@mvista.com>
  7. * Matt Porter <mporter@mvista.com>
  8. *
  9. * Derived from arch/ppc/boot/prep/misc.c
  10. *
  11. * 2000-2001 (c) MontaVista, Software, Inc. This file is licensed under
  12. * the terms of the GNU General Public License version 2. This program
  13. * is licensed "as is" without any warranty of any kind, whether express
  14. * or implied.
  15. */
  16. #include <linux/types.h>
  17. #include <linux/config.h>
  18. #include <linux/pci.h>
  19. #include <asm/bootinfo.h>
  20. extern unsigned long decompress_kernel(unsigned long load_addr, int num_words,
  21. unsigned long cksum);
  22. /* Define some important locations of the Spruce. */
  23. #define SPRUCE_PCI_CONFIG_ADDR 0xfec00000
  24. #define SPRUCE_PCI_CONFIG_DATA 0xfec00004
  25. /* PCI configuration space access routines. */
  26. unsigned int *pci_config_address = (unsigned int *)SPRUCE_PCI_CONFIG_ADDR;
  27. unsigned char *pci_config_data = (unsigned char *)SPRUCE_PCI_CONFIG_DATA;
  28. void cpc700_pcibios_read_config_byte(unsigned char bus, unsigned char dev_fn,
  29. unsigned char offset, unsigned char *val)
  30. {
  31. out_le32(pci_config_address,
  32. (((bus & 0xff)<<16) | (dev_fn<<8) | (offset&0xfc) | 0x80000000));
  33. *val= (in_le32((unsigned *)pci_config_data) >> (8 * (offset & 3))) & 0xff;
  34. }
  35. void cpc700_pcibios_write_config_byte(unsigned char bus, unsigned char dev_fn,
  36. unsigned char offset, unsigned char val)
  37. {
  38. out_le32(pci_config_address,
  39. (((bus & 0xff)<<16) | (dev_fn<<8) | (offset&0xfc) | 0x80000000));
  40. out_8(pci_config_data + (offset&3), val);
  41. }
  42. void cpc700_pcibios_read_config_word(unsigned char bus, unsigned char dev_fn,
  43. unsigned char offset, unsigned short *val)
  44. {
  45. out_le32(pci_config_address,
  46. (((bus & 0xff)<<16) | (dev_fn<<8) | (offset&0xfc) | 0x80000000));
  47. *val= in_le16((unsigned short *)(pci_config_data + (offset&3)));
  48. }
  49. void cpc700_pcibios_write_config_word(unsigned char bus, unsigned char dev_fn,
  50. unsigned char offset, unsigned short val)
  51. {
  52. out_le32(pci_config_address,
  53. (((bus & 0xff)<<16) | (dev_fn<<8) | (offset&0xfc) | 0x80000000));
  54. out_le16((unsigned short *)(pci_config_data + (offset&3)), val);
  55. }
  56. void cpc700_pcibios_read_config_dword(unsigned char bus, unsigned char dev_fn,
  57. unsigned char offset, unsigned int *val)
  58. {
  59. out_le32(pci_config_address,
  60. (((bus & 0xff)<<16) | (dev_fn<<8) | (offset&0xfc) | 0x80000000));
  61. *val= in_le32((unsigned *)pci_config_data);
  62. }
  63. void cpc700_pcibios_write_config_dword(unsigned char bus, unsigned char dev_fn,
  64. unsigned char offset, unsigned int val)
  65. {
  66. out_le32(pci_config_address,
  67. (((bus & 0xff)<<16) | (dev_fn<<8) | (offset&0xfc) | 0x80000000));
  68. out_le32((unsigned *)pci_config_data, val);
  69. }
  70. #define PCNET32_WIO_RDP 0x10
  71. #define PCNET32_WIO_RAP 0x12
  72. #define PCNET32_WIO_RESET 0x14
  73. #define PCNET32_DWIO_RDP 0x10
  74. #define PCNET32_DWIO_RAP 0x14
  75. #define PCNET32_DWIO_RESET 0x18
  76. /* Processor interface config register access */
  77. #define PIFCFGADDR 0xff500000
  78. #define PIFCFGDATA 0xff500004
  79. #define PLBMIFOPT 0x18 /* PLB Master Interface Options */
  80. #define MEM_MBEN 0x24
  81. #define MEM_TYPE 0x28
  82. #define MEM_B1SA 0x3c
  83. #define MEM_B1EA 0x5c
  84. #define MEM_B2SA 0x40
  85. #define MEM_B2EA 0x60
  86. unsigned long
  87. get_mem_size(void)
  88. {
  89. int loop;
  90. unsigned long mem_size = 0;
  91. unsigned long mem_mben;
  92. unsigned long mem_type;
  93. unsigned long mem_start;
  94. unsigned long mem_end;
  95. volatile int *mem_addr = (int *)0xff500008;
  96. volatile int *mem_data = (int *)0xff50000c;
  97. /* Get the size of memory from the memory controller. */
  98. *mem_addr = MEM_MBEN;
  99. asm("sync");
  100. mem_mben = *mem_data;
  101. asm("sync");
  102. for(loop = 0; loop < 1000; loop++);
  103. *mem_addr = MEM_TYPE;
  104. asm("sync");
  105. mem_type = *mem_data;
  106. asm("sync");
  107. for(loop = 0; loop < 1000; loop++);
  108. *mem_addr = MEM_TYPE;
  109. /* Confirm bank 1 has DRAM memory */
  110. if ((mem_mben & 0x40000000) &&
  111. ((mem_type & 0x30000000) == 0x10000000)) {
  112. *mem_addr = MEM_B1SA;
  113. asm("sync");
  114. mem_start = *mem_data;
  115. asm("sync");
  116. for(loop = 0; loop < 1000; loop++);
  117. *mem_addr = MEM_B1EA;
  118. asm("sync");
  119. mem_end = *mem_data;
  120. asm("sync");
  121. for(loop = 0; loop < 1000; loop++);
  122. mem_size = mem_end - mem_start + 0x100000;
  123. }
  124. /* Confirm bank 2 has DRAM memory */
  125. if ((mem_mben & 0x20000000) &&
  126. ((mem_type & 0xc000000) == 0x4000000)) {
  127. *mem_addr = MEM_B2SA;
  128. asm("sync");
  129. mem_start = *mem_data;
  130. asm("sync");
  131. for(loop = 0; loop < 1000; loop++);
  132. *mem_addr = MEM_B2EA;
  133. asm("sync");
  134. mem_end = *mem_data;
  135. asm("sync");
  136. for(loop = 0; loop < 1000; loop++);
  137. mem_size += mem_end - mem_start + 0x100000;
  138. }
  139. return mem_size;
  140. }
  141. unsigned long
  142. load_kernel(unsigned long load_addr, int num_words, unsigned long cksum,
  143. void *ign1, void *ign2)
  144. {
  145. int csr0;
  146. int csr_id;
  147. int pci_devfn;
  148. int found_multi = 0;
  149. unsigned short vendor;
  150. unsigned short device;
  151. unsigned short command;
  152. unsigned char header_type;
  153. unsigned int bar0;
  154. volatile int *pif_addr = (int *)0xff500000;
  155. volatile int *pif_data = (int *)0xff500004;
  156. /*
  157. * Gah, these firmware guys need to learn that hardware
  158. * byte swapping is evil! Disable all hardware byte
  159. * swapping so it doesn't hurt anyone.
  160. */
  161. *pif_addr = PLBMIFOPT;
  162. asm("sync");
  163. *pif_data = 0x00000000;
  164. asm("sync");
  165. /* Search out and turn off the PcNet ethernet boot device. */
  166. for (pci_devfn = 1; pci_devfn < 0xff; pci_devfn++) {
  167. if (PCI_FUNC(pci_devfn) && !found_multi)
  168. continue;
  169. cpc700_pcibios_read_config_byte(0, pci_devfn,
  170. PCI_HEADER_TYPE, &header_type);
  171. if (!PCI_FUNC(pci_devfn))
  172. found_multi = header_type & 0x80;
  173. cpc700_pcibios_read_config_word(0, pci_devfn, PCI_VENDOR_ID,
  174. &vendor);
  175. if (vendor != 0xffff) {
  176. cpc700_pcibios_read_config_word(0, pci_devfn,
  177. PCI_DEVICE_ID, &device);
  178. /* If this PCI device is the Lance PCNet board then turn it off */
  179. if ((vendor == PCI_VENDOR_ID_AMD) &&
  180. (device == PCI_DEVICE_ID_AMD_LANCE)) {
  181. /* Turn on I/O Space on the board. */
  182. cpc700_pcibios_read_config_word(0, pci_devfn,
  183. PCI_COMMAND, &command);
  184. command |= 0x1;
  185. cpc700_pcibios_write_config_word(0, pci_devfn,
  186. PCI_COMMAND, command);
  187. /* Get the I/O space address */
  188. cpc700_pcibios_read_config_dword(0, pci_devfn,
  189. PCI_BASE_ADDRESS_0, &bar0);
  190. bar0 &= 0xfffffffe;
  191. /* Reset the PCNet Board */
  192. inl (bar0+PCNET32_DWIO_RESET);
  193. inw (bar0+PCNET32_WIO_RESET);
  194. /* First do a work oriented read of csr0. If the value is
  195. * 4 then this is the correct mode to access the board.
  196. * If not try a double word ortiented read.
  197. */
  198. outw(0, bar0 + PCNET32_WIO_RAP);
  199. csr0 = inw(bar0 + PCNET32_WIO_RDP);
  200. if (csr0 == 4) {
  201. /* Check the Chip id register */
  202. outw(88, bar0 + PCNET32_WIO_RAP);
  203. csr_id = inw(bar0 + PCNET32_WIO_RDP);
  204. if (csr_id) {
  205. /* This is the valid mode - set the stop bit */
  206. outw(0, bar0 + PCNET32_WIO_RAP);
  207. outw(csr0, bar0 + PCNET32_WIO_RDP);
  208. }
  209. } else {
  210. outl(0, bar0 + PCNET32_DWIO_RAP);
  211. csr0 = inl(bar0 + PCNET32_DWIO_RDP);
  212. if (csr0 == 4) {
  213. /* Check the Chip id register */
  214. outl(88, bar0 + PCNET32_WIO_RAP);
  215. csr_id = inl(bar0 + PCNET32_WIO_RDP);
  216. if (csr_id) {
  217. /* This is the valid mode - set the stop bit*/
  218. outl(0, bar0 + PCNET32_WIO_RAP);
  219. outl(csr0, bar0 + PCNET32_WIO_RDP);
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. return decompress_kernel(load_addr, num_words, cksum);
  227. }