cpu.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * Copyright (c) 2014 Google, Inc
  3. * (C) Copyright 2008
  4. * Graeme Russ, graeme.russ@gmail.com.
  5. *
  6. * Some portions from coreboot src/mainboard/google/link/romstage.c
  7. * and src/cpu/intel/model_206ax/bootblock.c
  8. * Copyright (C) 2007-2010 coresystems GmbH
  9. * Copyright (C) 2011 Google Inc.
  10. *
  11. * SPDX-License-Identifier: GPL-2.0
  12. */
  13. #include <common.h>
  14. #include <dm.h>
  15. #include <errno.h>
  16. #include <fdtdec.h>
  17. #include <pch.h>
  18. #include <asm/cpu.h>
  19. #include <asm/io.h>
  20. #include <asm/lapic.h>
  21. #include <asm/msr.h>
  22. #include <asm/mtrr.h>
  23. #include <asm/pci.h>
  24. #include <asm/post.h>
  25. #include <asm/processor.h>
  26. #include <asm/arch/model_206ax.h>
  27. #include <asm/arch/microcode.h>
  28. #include <asm/arch/pch.h>
  29. #include <asm/arch/sandybridge.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. static int set_flex_ratio_to_tdp_nominal(void)
  32. {
  33. msr_t flex_ratio, msr;
  34. u8 nominal_ratio;
  35. /* Minimum CPU revision for configurable TDP support */
  36. if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
  37. return -EINVAL;
  38. /* Check for Flex Ratio support */
  39. flex_ratio = msr_read(MSR_FLEX_RATIO);
  40. if (!(flex_ratio.lo & FLEX_RATIO_EN))
  41. return -EINVAL;
  42. /* Check for >0 configurable TDPs */
  43. msr = msr_read(MSR_PLATFORM_INFO);
  44. if (((msr.hi >> 1) & 3) == 0)
  45. return -EINVAL;
  46. /* Use nominal TDP ratio for flex ratio */
  47. msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
  48. nominal_ratio = msr.lo & 0xff;
  49. /* See if flex ratio is already set to nominal TDP ratio */
  50. if (((flex_ratio.lo >> 8) & 0xff) == nominal_ratio)
  51. return 0;
  52. /* Set flex ratio to nominal TDP ratio */
  53. flex_ratio.lo &= ~0xff00;
  54. flex_ratio.lo |= nominal_ratio << 8;
  55. flex_ratio.lo |= FLEX_RATIO_LOCK;
  56. msr_write(MSR_FLEX_RATIO, flex_ratio);
  57. /* Set flex ratio in soft reset data register bits 11:6 */
  58. clrsetbits_le32(RCB_REG(SOFT_RESET_DATA), 0x3f << 6,
  59. (nominal_ratio & 0x3f) << 6);
  60. /* Set soft reset control to use register value */
  61. setbits_le32(RCB_REG(SOFT_RESET_CTRL), 1);
  62. /* Issue warm reset, will be "CPU only" due to soft reset data */
  63. outb(0x0, PORT_RESET);
  64. outb(SYS_RST | RST_CPU, PORT_RESET);
  65. cpu_hlt();
  66. /* Not reached */
  67. return -EINVAL;
  68. }
  69. int arch_cpu_init(void)
  70. {
  71. post_code(POST_CPU_INIT);
  72. return x86_cpu_init_f();
  73. }
  74. int arch_cpu_init_dm(void)
  75. {
  76. struct pci_controller *hose;
  77. struct udevice *bus, *dev;
  78. int ret;
  79. post_code(0x70);
  80. ret = uclass_get_device(UCLASS_PCI, 0, &bus);
  81. post_code(0x71);
  82. if (ret)
  83. return ret;
  84. post_code(0x72);
  85. hose = dev_get_uclass_priv(bus);
  86. /* TODO(sjg@chromium.org): Get rid of gd->hose */
  87. gd->hose = hose;
  88. ret = uclass_first_device(UCLASS_LPC, &dev);
  89. if (!dev)
  90. return -ENODEV;
  91. /*
  92. * We should do as little as possible before the serial console is
  93. * up. Perhaps this should move to later. Our next lot of init
  94. * happens in print_cpuinfo() when we have a console
  95. */
  96. ret = set_flex_ratio_to_tdp_nominal();
  97. if (ret)
  98. return ret;
  99. return 0;
  100. }
  101. #define PCH_EHCI0_TEMP_BAR0 0xe8000000
  102. #define PCH_EHCI1_TEMP_BAR0 0xe8000400
  103. #define PCH_XHCI_TEMP_BAR0 0xe8001000
  104. /*
  105. * Setup USB controller MMIO BAR to prevent the reference code from
  106. * resetting the controller.
  107. *
  108. * The BAR will be re-assigned during device enumeration so these are only
  109. * temporary.
  110. *
  111. * This is used to speed up the resume path.
  112. */
  113. static void enable_usb_bar(void)
  114. {
  115. pci_dev_t usb0 = PCH_EHCI1_DEV;
  116. pci_dev_t usb1 = PCH_EHCI2_DEV;
  117. pci_dev_t usb3 = PCH_XHCI_DEV;
  118. u32 cmd;
  119. /* USB Controller 1 */
  120. x86_pci_write_config32(usb0, PCI_BASE_ADDRESS_0,
  121. PCH_EHCI0_TEMP_BAR0);
  122. cmd = x86_pci_read_config32(usb0, PCI_COMMAND);
  123. cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  124. x86_pci_write_config32(usb0, PCI_COMMAND, cmd);
  125. /* USB Controller 1 */
  126. x86_pci_write_config32(usb1, PCI_BASE_ADDRESS_0,
  127. PCH_EHCI1_TEMP_BAR0);
  128. cmd = x86_pci_read_config32(usb1, PCI_COMMAND);
  129. cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  130. x86_pci_write_config32(usb1, PCI_COMMAND, cmd);
  131. /* USB3 Controller */
  132. x86_pci_write_config32(usb3, PCI_BASE_ADDRESS_0,
  133. PCH_XHCI_TEMP_BAR0);
  134. cmd = x86_pci_read_config32(usb3, PCI_COMMAND);
  135. cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  136. x86_pci_write_config32(usb3, PCI_COMMAND, cmd);
  137. }
  138. static int report_bist_failure(void)
  139. {
  140. if (gd->arch.bist != 0) {
  141. post_code(POST_BIST_FAILURE);
  142. printf("BIST failed: %08x\n", gd->arch.bist);
  143. return -EFAULT;
  144. }
  145. return 0;
  146. }
  147. int print_cpuinfo(void)
  148. {
  149. enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE;
  150. char processor_name[CPU_MAX_NAME_LEN];
  151. struct udevice *dev, *lpc;
  152. const char *name;
  153. uint32_t pm1_cnt;
  154. uint16_t pm1_sts;
  155. int ret;
  156. /* Halt if there was a built in self test failure */
  157. ret = report_bist_failure();
  158. if (ret)
  159. return ret;
  160. enable_lapic();
  161. ret = microcode_update_intel();
  162. if (ret)
  163. return ret;
  164. /* Enable upper 128bytes of CMOS */
  165. writel(1 << 2, RCB_REG(RC));
  166. /* TODO: cmos_post_init() */
  167. if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) {
  168. debug("soft reset detected\n");
  169. boot_mode = PEI_BOOT_SOFT_RESET;
  170. /* System is not happy after keyboard reset... */
  171. debug("Issuing CF9 warm reset\n");
  172. reset_cpu(0);
  173. }
  174. /* Early chipset init required before RAM init can work */
  175. uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
  176. ret = uclass_first_device(UCLASS_LPC, &lpc);
  177. if (ret)
  178. return ret;
  179. if (!dev)
  180. return -ENODEV;
  181. /* Cause the SATA device to do its early init */
  182. uclass_first_device(UCLASS_DISK, &dev);
  183. /* Check PM1_STS[15] to see if we are waking from Sx */
  184. pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
  185. /* Read PM1_CNT[12:10] to determine which Sx state */
  186. pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
  187. if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
  188. debug("Resume from S3 detected, but disabled.\n");
  189. } else {
  190. /*
  191. * TODO: An indication of life might be possible here (e.g.
  192. * keyboard light)
  193. */
  194. }
  195. post_code(POST_EARLY_INIT);
  196. /* Enable SPD ROMs and DDR-III DRAM */
  197. ret = uclass_first_device(UCLASS_I2C, &dev);
  198. if (ret)
  199. return ret;
  200. if (!dev)
  201. return -ENODEV;
  202. /* Prepare USB controller early in S3 resume */
  203. if (boot_mode == PEI_BOOT_RESUME)
  204. enable_usb_bar();
  205. gd->arch.pei_boot_mode = boot_mode;
  206. /* Print processor name */
  207. name = cpu_get_name(processor_name);
  208. printf("CPU: %s\n", name);
  209. post_code(POST_CPU_INFO);
  210. return 0;
  211. }
  212. void board_debug_uart_init(void)
  213. {
  214. /* This enables the debug UART */
  215. pci_x86_write_config(NULL, PCH_LPC_DEV, LPC_EN, COMA_LPC_EN,
  216. PCI_SIZE_16);
  217. }