cpu.c 5.1 KB

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