cpu.c 4.8 KB

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