misc-prep.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * arch/ppc/boot/simple/misc-prep.c
  3. *
  4. * Maintainer: Tom Rini <trini@kernel.crashing.org>
  5. *
  6. * In the past: Gary Thomas, Cort Dougan <cort@cs.nmt.edu>
  7. */
  8. #include <linux/config.h>
  9. #include <linux/pci_ids.h>
  10. #include <linux/types.h>
  11. #include <asm/residual.h>
  12. #include <asm/string.h>
  13. #include <asm/byteorder.h>
  14. #include "mpc10x.h"
  15. #include "of1275.h"
  16. #include "nonstdio.h"
  17. extern int keyb_present; /* keyboard controller is present by default */
  18. RESIDUAL hold_resid_buf;
  19. RESIDUAL *hold_residual = &hold_resid_buf;
  20. static void *OFW_interface; /* Pointer to OF, if available. */
  21. #ifdef CONFIG_VGA_CONSOLE
  22. char *vidmem = (char *)0xC00B8000;
  23. int lines = 25, cols = 80;
  24. int orig_x, orig_y = 24;
  25. #endif /* CONFIG_VGA_CONSOLE */
  26. extern int CRT_tstc(void);
  27. extern int vga_init(unsigned char *ISA_mem);
  28. extern void gunzip(void *, int, unsigned char *, int *);
  29. extern unsigned long serial_init(int chan, void *ignored);
  30. extern void serial_fixups(void);
  31. extern struct bi_record *decompress_kernel(unsigned long load_addr,
  32. int num_words, unsigned long cksum);
  33. extern void disable_6xx_mmu(void);
  34. extern unsigned long mpc10x_get_mem_size(void);
  35. static void
  36. writel(unsigned int val, unsigned int address)
  37. {
  38. /* Ensure I/O operations complete */
  39. __asm__ volatile("eieio");
  40. *(unsigned int *)address = cpu_to_le32(val);
  41. }
  42. #define PCI_CFG_ADDR(dev,off) ((0x80<<24) | (dev<<8) | (off&0xfc))
  43. #define PCI_CFG_DATA(off) (MPC10X_MAPA_CNFG_DATA+(off&3))
  44. static void
  45. pci_read_config_32(unsigned char devfn,
  46. unsigned char offset,
  47. unsigned int *val)
  48. {
  49. /* Ensure I/O operations complete */
  50. __asm__ volatile("eieio");
  51. *(unsigned int *)PCI_CFG_ADDR(devfn,offset) =
  52. cpu_to_le32(MPC10X_MAPA_CNFG_ADDR);
  53. /* Ensure I/O operations complete */
  54. __asm__ volatile("eieio");
  55. *val = le32_to_cpu(*(unsigned int *)PCI_CFG_DATA(offset));
  56. return;
  57. }
  58. #ifdef CONFIG_VGA_CONSOLE
  59. void
  60. scroll(void)
  61. {
  62. int i;
  63. memcpy ( vidmem, vidmem + cols * 2, ( lines - 1 ) * cols * 2 );
  64. for ( i = ( lines - 1 ) * cols * 2; i < lines * cols * 2; i += 2 )
  65. vidmem[i] = ' ';
  66. }
  67. #endif /* CONFIG_VGA_CONSOLE */
  68. unsigned long
  69. load_kernel(unsigned long load_addr, int num_words, unsigned long cksum,
  70. RESIDUAL *residual, void *OFW)
  71. {
  72. int start_multi = 0;
  73. unsigned int pci_viddid, pci_did, tulip_pci_base, tulip_base;
  74. /* If we have Open Firmware, initialise it immediately */
  75. if (OFW) {
  76. OFW_interface = OFW;
  77. ofinit(OFW_interface);
  78. }
  79. board_isa_init();
  80. #if defined(CONFIG_VGA_CONSOLE)
  81. vga_init((unsigned char *)0xC0000000);
  82. #endif /* CONFIG_VGA_CONSOLE */
  83. if (residual) {
  84. /* Is this Motorola PPCBug? */
  85. if ((1 & residual->VitalProductData.FirmwareSupports) &&
  86. (1 == residual->VitalProductData.FirmwareSupplier)) {
  87. unsigned char base_mod;
  88. unsigned char board_type = inb(0x801) & 0xF0;
  89. /*
  90. * Reset the onboard 21x4x Ethernet
  91. * Motorola Ethernet is at IDSEL 14 (devfn 0x70)
  92. */
  93. pci_read_config_32(0x70, 0x00, &pci_viddid);
  94. pci_did = (pci_viddid & 0xffff0000) >> 16;
  95. /* Be sure we've really found a 21x4x chip */
  96. if (((pci_viddid & 0xffff) == PCI_VENDOR_ID_DEC) &&
  97. ((pci_did == PCI_DEVICE_ID_DEC_TULIP_FAST) ||
  98. (pci_did == PCI_DEVICE_ID_DEC_TULIP) ||
  99. (pci_did == PCI_DEVICE_ID_DEC_TULIP_PLUS) ||
  100. (pci_did == PCI_DEVICE_ID_DEC_21142))) {
  101. pci_read_config_32(0x70,
  102. 0x10,
  103. &tulip_pci_base);
  104. /* Get the physical base address */
  105. tulip_base =
  106. (tulip_pci_base & ~0x03UL) + 0x80000000;
  107. /* Strobe the 21x4x reset bit in CSR0 */
  108. writel(0x1, tulip_base);
  109. }
  110. /* If this is genesis 2 board then check for no
  111. * keyboard controller and more than one processor.
  112. */
  113. if (board_type == 0xe0) {
  114. base_mod = inb(0x803);
  115. /* if a MVME2300/2400 or a Sitka then no keyboard */
  116. if((base_mod == 0xFA) || (base_mod == 0xF9) ||
  117. (base_mod == 0xE1)) {
  118. keyb_present = 0; /* no keyboard */
  119. }
  120. }
  121. /* If this is a multiprocessor system then
  122. * park the other processor so that the
  123. * kernel knows where to find them.
  124. */
  125. if (residual->MaxNumCpus > 1)
  126. start_multi = 1;
  127. }
  128. memcpy(hold_residual,residual,sizeof(RESIDUAL));
  129. }
  130. /* Call decompress_kernel */
  131. decompress_kernel(load_addr, num_words, cksum);
  132. if (start_multi) {
  133. residual->VitalProductData.SmpIar = (unsigned long)0xc0;
  134. residual->Cpus[1].CpuState = CPU_GOOD;
  135. hold_residual->VitalProductData.Reserved5 = 0xdeadbeef;
  136. }
  137. /* Now go and clear out the BATs and ensure that our MSR is
  138. * correct .*/
  139. disable_6xx_mmu();
  140. /* Make r3 be a pointer to the residual data. */
  141. return (unsigned long)hold_residual;
  142. }
  143. unsigned long
  144. get_mem_size(void)
  145. {
  146. unsigned int pci_viddid, pci_did;
  147. /* First, figure out what kind of host bridge we are on. If it's
  148. * an MPC10x, we can ask it directly how much memory it has.
  149. * Otherwise, see if the residual data has anything. This isn't
  150. * the best way, but it can be the only way. If there's nothing,
  151. * assume 32MB. -- Tom.
  152. */
  153. /* See what our host bridge is. */
  154. pci_read_config_32(0x00, 0x00, &pci_viddid);
  155. pci_did = (pci_viddid & 0xffff0000) >> 16;
  156. /* See if we are on an MPC10x. */
  157. if (((pci_viddid & 0xffff) == PCI_VENDOR_ID_MOTOROLA)
  158. && ((pci_did == PCI_DEVICE_ID_MOTOROLA_MPC105)
  159. || (pci_did == PCI_DEVICE_ID_MOTOROLA_MPC106)
  160. || (pci_did == PCI_DEVICE_ID_MOTOROLA_MPC107)))
  161. return mpc10x_get_mem_size();
  162. /* If it's not, see if we have anything in the residual data. */
  163. else if (hold_residual && hold_residual->TotalMemory)
  164. return hold_residual->TotalMemory;
  165. else if (OFW_interface) {
  166. /*
  167. * This is a 'best guess' check. We want to make sure
  168. * we don't try this on a PReP box without OF
  169. * -- Cort
  170. */
  171. while (OFW_interface)
  172. {
  173. phandle dev_handle;
  174. int mem_info[2];
  175. /* get handle to memory description */
  176. if (!(dev_handle = finddevice("/memory@0")))
  177. break;
  178. /* get the info */
  179. if (getprop(dev_handle, "reg", mem_info,
  180. sizeof(mem_info)) != 8)
  181. break;
  182. return mem_info[1];
  183. }
  184. }
  185. /* Fall back to hard-coding 32MB. */
  186. return 32*1024*1024;
  187. }