misc-prep.c 5.8 KB

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