cpu.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2014 Google, Inc
  4. * (C) Copyright 2008
  5. * Graeme Russ, graeme.russ@gmail.com.
  6. *
  7. * Some portions from coreboot src/mainboard/google/link/romstage.c
  8. * and src/cpu/intel/model_206ax/bootblock.c
  9. * Copyright (C) 2007-2010 coresystems GmbH
  10. * Copyright (C) 2011 Google Inc.
  11. */
  12. #include <common.h>
  13. #include <dm.h>
  14. #include <errno.h>
  15. #include <fdtdec.h>
  16. #include <pch.h>
  17. #include <asm/cpu.h>
  18. #include <asm/cpu_common.h>
  19. #include <asm/intel_regs.h>
  20. #include <asm/io.h>
  21. #include <asm/lapic.h>
  22. #include <asm/lpc_common.h>
  23. #include <asm/microcode.h>
  24. #include <asm/msr.h>
  25. #include <asm/mtrr.h>
  26. #include <asm/pci.h>
  27. #include <asm/post.h>
  28. #include <asm/processor.h>
  29. #include <asm/arch/model_206ax.h>
  30. #include <asm/arch/pch.h>
  31. #include <asm/arch/sandybridge.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. static int set_flex_ratio_to_tdp_nominal(void)
  34. {
  35. /* Minimum CPU revision for configurable TDP support */
  36. if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
  37. return -EINVAL;
  38. return cpu_set_flex_ratio_to_tdp_nominal();
  39. }
  40. int arch_cpu_init(void)
  41. {
  42. post_code(POST_CPU_INIT);
  43. return x86_cpu_init_f();
  44. }
  45. int arch_cpu_init_dm(void)
  46. {
  47. struct pci_controller *hose;
  48. struct udevice *bus, *dev;
  49. int ret;
  50. post_code(0x70);
  51. ret = uclass_get_device(UCLASS_PCI, 0, &bus);
  52. post_code(0x71);
  53. if (ret)
  54. return ret;
  55. post_code(0x72);
  56. hose = dev_get_uclass_priv(bus);
  57. /* TODO(sjg@chromium.org): Get rid of gd->hose */
  58. gd->hose = hose;
  59. ret = uclass_first_device_err(UCLASS_LPC, &dev);
  60. if (ret)
  61. return ret;
  62. /*
  63. * We should do as little as possible before the serial console is
  64. * up. Perhaps this should move to later. Our next lot of init
  65. * happens in checkcpu() when we have a console
  66. */
  67. ret = set_flex_ratio_to_tdp_nominal();
  68. if (ret)
  69. return ret;
  70. return 0;
  71. }
  72. #define PCH_EHCI0_TEMP_BAR0 0xe8000000
  73. #define PCH_EHCI1_TEMP_BAR0 0xe8000400
  74. #define PCH_XHCI_TEMP_BAR0 0xe8001000
  75. /*
  76. * Setup USB controller MMIO BAR to prevent the reference code from
  77. * resetting the controller.
  78. *
  79. * The BAR will be re-assigned during device enumeration so these are only
  80. * temporary.
  81. *
  82. * This is used to speed up the resume path.
  83. */
  84. static void enable_usb_bar(struct udevice *bus)
  85. {
  86. pci_dev_t usb0 = PCH_EHCI1_DEV;
  87. pci_dev_t usb1 = PCH_EHCI2_DEV;
  88. pci_dev_t usb3 = PCH_XHCI_DEV;
  89. ulong cmd;
  90. /* USB Controller 1 */
  91. pci_bus_write_config(bus, usb0, PCI_BASE_ADDRESS_0,
  92. PCH_EHCI0_TEMP_BAR0, PCI_SIZE_32);
  93. pci_bus_read_config(bus, usb0, PCI_COMMAND, &cmd, PCI_SIZE_32);
  94. cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  95. pci_bus_write_config(bus, usb0, PCI_COMMAND, cmd, PCI_SIZE_32);
  96. /* USB Controller 2 */
  97. pci_bus_write_config(bus, usb1, PCI_BASE_ADDRESS_0,
  98. PCH_EHCI1_TEMP_BAR0, PCI_SIZE_32);
  99. pci_bus_read_config(bus, usb1, PCI_COMMAND, &cmd, PCI_SIZE_32);
  100. cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  101. pci_bus_write_config(bus, usb1, PCI_COMMAND, cmd, PCI_SIZE_32);
  102. /* USB3 Controller 1 */
  103. pci_bus_write_config(bus, usb3, PCI_BASE_ADDRESS_0,
  104. PCH_XHCI_TEMP_BAR0, PCI_SIZE_32);
  105. pci_bus_read_config(bus, usb3, PCI_COMMAND, &cmd, PCI_SIZE_32);
  106. cmd |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  107. pci_bus_write_config(bus, usb3, PCI_COMMAND, cmd, PCI_SIZE_32);
  108. }
  109. int checkcpu(void)
  110. {
  111. enum pei_boot_mode_t boot_mode = PEI_BOOT_NONE;
  112. struct udevice *dev, *lpc;
  113. uint32_t pm1_cnt;
  114. uint16_t pm1_sts;
  115. int ret;
  116. /* TODO: cmos_post_init() */
  117. if (readl(MCHBAR_REG(SSKPD)) == 0xCAFE) {
  118. debug("soft reset detected\n");
  119. boot_mode = PEI_BOOT_SOFT_RESET;
  120. /* System is not happy after keyboard reset... */
  121. debug("Issuing CF9 warm reset\n");
  122. reset_cpu(0);
  123. }
  124. ret = cpu_common_init();
  125. if (ret) {
  126. debug("%s: cpu_common_init() failed\n", __func__);
  127. return ret;
  128. }
  129. /* Check PM1_STS[15] to see if we are waking from Sx */
  130. pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
  131. /* Read PM1_CNT[12:10] to determine which Sx state */
  132. pm1_cnt = inl(DEFAULT_PMBASE + PM1_CNT);
  133. if ((pm1_sts & WAK_STS) && ((pm1_cnt >> 10) & 7) == 5) {
  134. debug("Resume from S3 detected, but disabled.\n");
  135. } else {
  136. /*
  137. * TODO: An indication of life might be possible here (e.g.
  138. * keyboard light)
  139. */
  140. }
  141. post_code(POST_EARLY_INIT);
  142. /* Enable SPD ROMs and DDR-III DRAM */
  143. ret = uclass_first_device_err(UCLASS_I2C, &dev);
  144. if (ret) {
  145. debug("%s: Failed to get I2C (ret=%d)\n", __func__, ret);
  146. return ret;
  147. }
  148. /* Prepare USB controller early in S3 resume */
  149. if (boot_mode == PEI_BOOT_RESUME) {
  150. uclass_first_device(UCLASS_LPC, &lpc);
  151. enable_usb_bar(pci_get_controller(lpc->parent));
  152. }
  153. gd->arch.pei_boot_mode = boot_mode;
  154. return 0;
  155. }
  156. int print_cpuinfo(void)
  157. {
  158. char processor_name[CPU_MAX_NAME_LEN];
  159. const char *name;
  160. /* Print processor name */
  161. name = cpu_get_name(processor_name);
  162. printf("CPU: %s\n", name);
  163. post_code(POST_CPU_INFO);
  164. return 0;
  165. }
  166. void board_debug_uart_init(void)
  167. {
  168. /* This enables the debug UART */
  169. pci_x86_write_config(NULL, PCH_LPC_DEV, LPC_EN, COMA_LPC_EN,
  170. PCI_SIZE_16);
  171. }