cpu.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2016 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <asm/cpu_common.h>
  10. #include <asm/intel_regs.h>
  11. #include <asm/lapic.h>
  12. #include <asm/lpc_common.h>
  13. #include <asm/msr.h>
  14. #include <asm/mtrr.h>
  15. #include <asm/post.h>
  16. #include <asm/microcode.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. static int report_bist_failure(void)
  19. {
  20. if (gd->arch.bist != 0) {
  21. post_code(POST_BIST_FAILURE);
  22. printf("BIST failed: %08x\n", gd->arch.bist);
  23. return -EFAULT;
  24. }
  25. return 0;
  26. }
  27. int cpu_common_init(void)
  28. {
  29. struct udevice *dev, *lpc;
  30. int ret;
  31. /* Halt if there was a built in self test failure */
  32. ret = report_bist_failure();
  33. if (ret)
  34. return ret;
  35. enable_lapic();
  36. ret = microcode_update_intel();
  37. if (ret && ret != -EEXIST)
  38. return ret;
  39. /* Enable upper 128bytes of CMOS */
  40. writel(1 << 2, RCB_REG(RC));
  41. /* Early chipset init required before RAM init can work */
  42. uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
  43. ret = uclass_first_device(UCLASS_LPC, &lpc);
  44. if (ret)
  45. return ret;
  46. if (!lpc)
  47. return -ENODEV;
  48. /* Cause the SATA device to do its early init */
  49. uclass_first_device(UCLASS_DISK, &dev);
  50. return 0;
  51. }
  52. int cpu_set_flex_ratio_to_tdp_nominal(void)
  53. {
  54. msr_t flex_ratio, msr;
  55. u8 nominal_ratio;
  56. /* Check for Flex Ratio support */
  57. flex_ratio = msr_read(MSR_FLEX_RATIO);
  58. if (!(flex_ratio.lo & FLEX_RATIO_EN))
  59. return -EINVAL;
  60. /* Check for >0 configurable TDPs */
  61. msr = msr_read(MSR_PLATFORM_INFO);
  62. if (((msr.hi >> 1) & 3) == 0)
  63. return -EINVAL;
  64. /* Use nominal TDP ratio for flex ratio */
  65. msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
  66. nominal_ratio = msr.lo & 0xff;
  67. /* See if flex ratio is already set to nominal TDP ratio */
  68. if (((flex_ratio.lo >> 8) & 0xff) == nominal_ratio)
  69. return 0;
  70. /* Set flex ratio to nominal TDP ratio */
  71. flex_ratio.lo &= ~0xff00;
  72. flex_ratio.lo |= nominal_ratio << 8;
  73. flex_ratio.lo |= FLEX_RATIO_LOCK;
  74. msr_write(MSR_FLEX_RATIO, flex_ratio);
  75. /* Set flex ratio in soft reset data register bits 11:6 */
  76. clrsetbits_le32(RCB_REG(SOFT_RESET_DATA), 0x3f << 6,
  77. (nominal_ratio & 0x3f) << 6);
  78. debug("CPU: Soft reset to set up flex ratio\n");
  79. /* Set soft reset control to use register value */
  80. setbits_le32(RCB_REG(SOFT_RESET_CTRL), 1);
  81. /* Issue warm reset, will be "CPU only" due to soft reset data */
  82. outb(0x0, PORT_RESET);
  83. outb(SYS_RST | RST_CPU, PORT_RESET);
  84. cpu_hlt();
  85. /* Not reached */
  86. return -EINVAL;
  87. }