cpu.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * (C) Copyright 2008-2011
  3. * Graeme Russ, <graeme.russ@gmail.com>
  4. *
  5. * (C) Copyright 2002
  6. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  7. *
  8. * (C) Copyright 2002
  9. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  10. * Marius Groeger <mgroeger@sysgo.de>
  11. *
  12. * (C) Copyright 2002
  13. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  14. * Alex Zuepke <azu@sysgo.de>
  15. *
  16. * Part of this file is adapted from coreboot
  17. * src/arch/x86/lib/cpu.c
  18. *
  19. * SPDX-License-Identifier: GPL-2.0+
  20. */
  21. #include <common.h>
  22. #include <command.h>
  23. #include <dm.h>
  24. #include <errno.h>
  25. #include <malloc.h>
  26. #include <syscon.h>
  27. #include <asm/acpi_s3.h>
  28. #include <asm/control_regs.h>
  29. #include <asm/coreboot_tables.h>
  30. #include <asm/cpu.h>
  31. #include <asm/lapic.h>
  32. #include <asm/microcode.h>
  33. #include <asm/mp.h>
  34. #include <asm/mrccache.h>
  35. #include <asm/msr.h>
  36. #include <asm/mtrr.h>
  37. #include <asm/post.h>
  38. #include <asm/processor.h>
  39. #include <asm/processor-flags.h>
  40. #include <asm/interrupt.h>
  41. #include <asm/tables.h>
  42. #include <linux/compiler.h>
  43. DECLARE_GLOBAL_DATA_PTR;
  44. static const char *const x86_vendor_name[] = {
  45. [X86_VENDOR_INTEL] = "Intel",
  46. [X86_VENDOR_CYRIX] = "Cyrix",
  47. [X86_VENDOR_AMD] = "AMD",
  48. [X86_VENDOR_UMC] = "UMC",
  49. [X86_VENDOR_NEXGEN] = "NexGen",
  50. [X86_VENDOR_CENTAUR] = "Centaur",
  51. [X86_VENDOR_RISE] = "Rise",
  52. [X86_VENDOR_TRANSMETA] = "Transmeta",
  53. [X86_VENDOR_NSC] = "NSC",
  54. [X86_VENDOR_SIS] = "SiS",
  55. };
  56. int __weak x86_cleanup_before_linux(void)
  57. {
  58. #ifdef CONFIG_BOOTSTAGE_STASH
  59. bootstage_stash((void *)CONFIG_BOOTSTAGE_STASH_ADDR,
  60. CONFIG_BOOTSTAGE_STASH_SIZE);
  61. #endif
  62. return 0;
  63. }
  64. int x86_init_cache(void)
  65. {
  66. enable_caches();
  67. return 0;
  68. }
  69. int init_cache(void) __attribute__((weak, alias("x86_init_cache")));
  70. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  71. {
  72. printf("resetting ...\n");
  73. /* wait 50 ms */
  74. udelay(50000);
  75. disable_interrupts();
  76. reset_cpu(0);
  77. /*NOTREACHED*/
  78. return 0;
  79. }
  80. void flush_cache(unsigned long dummy1, unsigned long dummy2)
  81. {
  82. asm("wbinvd\n");
  83. }
  84. __weak void reset_cpu(ulong addr)
  85. {
  86. /* Do a hard reset through the chipset's reset control register */
  87. outb(SYS_RST | RST_CPU, IO_PORT_RESET);
  88. for (;;)
  89. cpu_hlt();
  90. }
  91. void x86_full_reset(void)
  92. {
  93. outb(FULL_RST | SYS_RST | RST_CPU, IO_PORT_RESET);
  94. }
  95. /* Define these functions to allow ehch-hcd to function */
  96. void flush_dcache_range(unsigned long start, unsigned long stop)
  97. {
  98. }
  99. void invalidate_dcache_range(unsigned long start, unsigned long stop)
  100. {
  101. }
  102. void dcache_enable(void)
  103. {
  104. enable_caches();
  105. }
  106. void dcache_disable(void)
  107. {
  108. disable_caches();
  109. }
  110. void icache_enable(void)
  111. {
  112. }
  113. void icache_disable(void)
  114. {
  115. }
  116. int icache_status(void)
  117. {
  118. return 1;
  119. }
  120. const char *cpu_vendor_name(int vendor)
  121. {
  122. const char *name;
  123. name = "<invalid cpu vendor>";
  124. if ((vendor < (ARRAY_SIZE(x86_vendor_name))) &&
  125. (x86_vendor_name[vendor] != 0))
  126. name = x86_vendor_name[vendor];
  127. return name;
  128. }
  129. char *cpu_get_name(char *name)
  130. {
  131. unsigned int *name_as_ints = (unsigned int *)name;
  132. struct cpuid_result regs;
  133. char *ptr;
  134. int i;
  135. /* This bit adds up to 48 bytes */
  136. for (i = 0; i < 3; i++) {
  137. regs = cpuid(0x80000002 + i);
  138. name_as_ints[i * 4 + 0] = regs.eax;
  139. name_as_ints[i * 4 + 1] = regs.ebx;
  140. name_as_ints[i * 4 + 2] = regs.ecx;
  141. name_as_ints[i * 4 + 3] = regs.edx;
  142. }
  143. name[CPU_MAX_NAME_LEN - 1] = '\0';
  144. /* Skip leading spaces. */
  145. ptr = name;
  146. while (*ptr == ' ')
  147. ptr++;
  148. return ptr;
  149. }
  150. int default_print_cpuinfo(void)
  151. {
  152. printf("CPU: %s, vendor %s, device %xh\n",
  153. cpu_has_64bit() ? "x86_64" : "x86",
  154. cpu_vendor_name(gd->arch.x86_vendor), gd->arch.x86_device);
  155. #ifdef CONFIG_HAVE_ACPI_RESUME
  156. debug("ACPI previous sleep state: %s\n",
  157. acpi_ss_string(gd->arch.prev_sleep_state));
  158. #endif
  159. return 0;
  160. }
  161. void show_boot_progress(int val)
  162. {
  163. outb(val, POST_PORT);
  164. }
  165. #ifndef CONFIG_SYS_COREBOOT
  166. /*
  167. * Implement a weak default function for boards that optionally
  168. * need to clean up the system before jumping to the kernel.
  169. */
  170. __weak void board_final_cleanup(void)
  171. {
  172. }
  173. int last_stage_init(void)
  174. {
  175. write_tables();
  176. board_final_cleanup();
  177. return 0;
  178. }
  179. #endif
  180. static int x86_init_cpus(void)
  181. {
  182. #ifdef CONFIG_SMP
  183. debug("Init additional CPUs\n");
  184. x86_mp_init();
  185. #else
  186. struct udevice *dev;
  187. /*
  188. * This causes the cpu-x86 driver to be probed.
  189. * We don't check return value here as we want to allow boards
  190. * which have not been converted to use cpu uclass driver to boot.
  191. */
  192. uclass_first_device(UCLASS_CPU, &dev);
  193. #endif
  194. return 0;
  195. }
  196. int cpu_init_r(void)
  197. {
  198. struct udevice *dev;
  199. int ret;
  200. if (!ll_boot_init())
  201. return 0;
  202. ret = x86_init_cpus();
  203. if (ret)
  204. return ret;
  205. /*
  206. * Set up the northbridge, PCH and LPC if available. Note that these
  207. * may have had some limited pre-relocation init if they were probed
  208. * before relocation, but this is post relocation.
  209. */
  210. uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
  211. uclass_first_device(UCLASS_PCH, &dev);
  212. uclass_first_device(UCLASS_LPC, &dev);
  213. /* Set up pin control if available */
  214. ret = syscon_get_by_driver_data(X86_SYSCON_PINCONF, &dev);
  215. debug("%s, pinctrl=%p, ret=%d\n", __func__, dev, ret);
  216. return 0;
  217. }
  218. #ifndef CONFIG_EFI_STUB
  219. int reserve_arch(void)
  220. {
  221. #ifdef CONFIG_ENABLE_MRC_CACHE
  222. mrccache_reserve();
  223. #endif
  224. #ifdef CONFIG_SEABIOS
  225. high_table_reserve();
  226. #endif
  227. return 0;
  228. }
  229. #endif