head64.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * prepare to run common code
  3. *
  4. * Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
  5. */
  6. #include <linux/init.h>
  7. #include <linux/linkage.h>
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/string.h>
  11. #include <linux/percpu.h>
  12. #include <linux/start_kernel.h>
  13. #include <linux/io.h>
  14. #include <asm/processor.h>
  15. #include <asm/proto.h>
  16. #include <asm/smp.h>
  17. #include <asm/setup.h>
  18. #include <asm/desc.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/tlbflush.h>
  21. #include <asm/sections.h>
  22. #include <asm/kdebug.h>
  23. #include <asm/e820.h>
  24. #include <asm/bios_ebda.h>
  25. /* boot cpu pda */
  26. static struct x8664_pda _boot_cpu_pda __read_mostly;
  27. #ifdef CONFIG_SMP
  28. #ifdef CONFIG_DEBUG_PER_CPU_MAPS
  29. /*
  30. * We install an empty cpu_pda pointer table to trap references before
  31. * the actual cpu_pda pointer table is created in setup_cpu_pda_map().
  32. */
  33. static struct x8664_pda *__cpu_pda[NR_CPUS] __initdata;
  34. #else
  35. static struct x8664_pda *__cpu_pda[1] __read_mostly;
  36. #endif
  37. #else /* !CONFIG_SMP (NR_CPUS will be 1) */
  38. static struct x8664_pda *__cpu_pda[NR_CPUS] __read_mostly;
  39. #endif
  40. static void __init zap_identity_mappings(void)
  41. {
  42. pgd_t *pgd = pgd_offset_k(0UL);
  43. pgd_clear(pgd);
  44. __flush_tlb_all();
  45. }
  46. /* Don't add a printk in there. printk relies on the PDA which is not initialized
  47. yet. */
  48. static void __init clear_bss(void)
  49. {
  50. memset(__bss_start, 0,
  51. (unsigned long) __bss_stop - (unsigned long) __bss_start);
  52. }
  53. static void __init copy_bootdata(char *real_mode_data)
  54. {
  55. char * command_line;
  56. memcpy(&boot_params, real_mode_data, sizeof boot_params);
  57. if (boot_params.hdr.cmd_line_ptr) {
  58. command_line = __va(boot_params.hdr.cmd_line_ptr);
  59. memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
  60. }
  61. }
  62. #define BIOS_LOWMEM_KILOBYTES 0x413
  63. /*
  64. * The BIOS places the EBDA/XBDA at the top of conventional
  65. * memory, and usually decreases the reported amount of
  66. * conventional memory (int 0x12) too. This also contains a
  67. * workaround for Dell systems that neglect to reserve EBDA.
  68. * The same workaround also avoids a problem with the AMD768MPX
  69. * chipset: reserve a page before VGA to prevent PCI prefetch
  70. * into it (errata #56). Usually the page is reserved anyways,
  71. * unless you have no PS/2 mouse plugged in.
  72. */
  73. static void __init reserve_ebda_region(void)
  74. {
  75. unsigned int lowmem, ebda_addr;
  76. /* To determine the position of the EBDA and the */
  77. /* end of conventional memory, we need to look at */
  78. /* the BIOS data area. In a paravirtual environment */
  79. /* that area is absent. We'll just have to assume */
  80. /* that the paravirt case can handle memory setup */
  81. /* correctly, without our help. */
  82. if (paravirt_enabled())
  83. return;
  84. /* end of low (conventional) memory */
  85. lowmem = *(unsigned short *)__va(BIOS_LOWMEM_KILOBYTES);
  86. lowmem <<= 10;
  87. /* start of EBDA area */
  88. ebda_addr = get_bios_ebda();
  89. /* Fixup: bios puts an EBDA in the top 64K segment */
  90. /* of conventional memory, but does not adjust lowmem. */
  91. if ((lowmem - ebda_addr) <= 0x10000)
  92. lowmem = ebda_addr;
  93. /* Fixup: bios does not report an EBDA at all. */
  94. /* Some old Dells seem to need 4k anyhow (bugzilla 2990) */
  95. if ((ebda_addr == 0) && (lowmem >= 0x9f000))
  96. lowmem = 0x9f000;
  97. /* Paranoia: should never happen, but... */
  98. if ((lowmem == 0) || (lowmem >= 0x100000))
  99. lowmem = 0x9f000;
  100. /* reserve all memory between lowmem and the 1MB mark */
  101. reserve_early(lowmem, 0x100000, "BIOS reserved");
  102. }
  103. static void __init reserve_setup_data(void)
  104. {
  105. struct setup_data *data;
  106. unsigned long pa_data;
  107. char buf[32];
  108. if (boot_params.hdr.version < 0x0209)
  109. return;
  110. pa_data = boot_params.hdr.setup_data;
  111. while (pa_data) {
  112. data = early_ioremap(pa_data, sizeof(*data));
  113. sprintf(buf, "setup data %x", data->type);
  114. reserve_early(pa_data, pa_data+sizeof(*data)+data->len, buf);
  115. pa_data = data->next;
  116. early_iounmap(data, sizeof(*data));
  117. }
  118. }
  119. void __init x86_64_start_kernel(char * real_mode_data)
  120. {
  121. int i;
  122. /*
  123. * Build-time sanity checks on the kernel image and module
  124. * area mappings. (these are purely build-time and produce no code)
  125. */
  126. BUILD_BUG_ON(MODULES_VADDR < KERNEL_IMAGE_START);
  127. BUILD_BUG_ON(MODULES_VADDR-KERNEL_IMAGE_START < KERNEL_IMAGE_SIZE);
  128. BUILD_BUG_ON(MODULES_LEN + KERNEL_IMAGE_SIZE > 2*PUD_SIZE);
  129. BUILD_BUG_ON((KERNEL_IMAGE_START & ~PMD_MASK) != 0);
  130. BUILD_BUG_ON((MODULES_VADDR & ~PMD_MASK) != 0);
  131. BUILD_BUG_ON(!(MODULES_VADDR > __START_KERNEL));
  132. BUILD_BUG_ON(!(((MODULES_END - 1) & PGDIR_MASK) ==
  133. (__START_KERNEL & PGDIR_MASK)));
  134. /* clear bss before set_intr_gate with early_idt_handler */
  135. clear_bss();
  136. /* Make NULL pointers segfault */
  137. zap_identity_mappings();
  138. /* Cleanup the over mapped high alias */
  139. cleanup_highmap();
  140. for (i = 0; i < NUM_EXCEPTION_VECTORS; i++) {
  141. #ifdef CONFIG_EARLY_PRINTK
  142. set_intr_gate(i, &early_idt_handlers[i]);
  143. #else
  144. set_intr_gate(i, early_idt_handler);
  145. #endif
  146. }
  147. load_idt((const struct desc_ptr *)&idt_descr);
  148. early_printk("Kernel alive\n");
  149. _cpu_pda = __cpu_pda;
  150. cpu_pda(0) = &_boot_cpu_pda;
  151. pda_init(0);
  152. early_printk("Kernel really alive\n");
  153. copy_bootdata(__va(real_mode_data));
  154. reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
  155. #ifdef CONFIG_BLK_DEV_INITRD
  156. /* Reserve INITRD */
  157. if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
  158. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  159. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  160. unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
  161. reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
  162. }
  163. #endif
  164. reserve_ebda_region();
  165. reserve_setup_data();
  166. /*
  167. * At this point everything still needed from the boot loader
  168. * or BIOS or kernel text should be early reserved or marked not
  169. * RAM in e820. All other memory is free game.
  170. */
  171. start_kernel();
  172. }