misc-prep.c 5.9 KB

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