early_me.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * From Coreboot src/southbridge/intel/bd82x6x/early_me.c
  4. *
  5. * Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <sysreset.h>
  11. #include <asm/pci.h>
  12. #include <asm/cpu.h>
  13. #include <asm/processor.h>
  14. #include <asm/arch/me.h>
  15. #include <asm/arch/pch.h>
  16. #include <asm/io.h>
  17. static const char *const me_ack_values[] = {
  18. [ME_HFS_ACK_NO_DID] = "No DID Ack received",
  19. [ME_HFS_ACK_RESET] = "Non-power cycle reset",
  20. [ME_HFS_ACK_PWR_CYCLE] = "Power cycle reset",
  21. [ME_HFS_ACK_S3] = "Go to S3",
  22. [ME_HFS_ACK_S4] = "Go to S4",
  23. [ME_HFS_ACK_S5] = "Go to S5",
  24. [ME_HFS_ACK_GBL_RESET] = "Global Reset",
  25. [ME_HFS_ACK_CONTINUE] = "Continue to boot"
  26. };
  27. int intel_early_me_init(struct udevice *me_dev)
  28. {
  29. int count;
  30. struct me_uma uma;
  31. struct me_hfs hfs;
  32. debug("Intel ME early init\n");
  33. /* Wait for ME UMA SIZE VALID bit to be set */
  34. for (count = ME_RETRY; count > 0; --count) {
  35. pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA);
  36. if (uma.valid)
  37. break;
  38. udelay(ME_DELAY);
  39. }
  40. if (!count) {
  41. printf("ERROR: ME is not ready!\n");
  42. return -EBUSY;
  43. }
  44. /* Check for valid firmware */
  45. pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
  46. if (hfs.fpt_bad) {
  47. printf("WARNING: ME has bad firmware\n");
  48. return -EBADF;
  49. }
  50. debug("Intel ME firmware is ready\n");
  51. return 0;
  52. }
  53. int intel_early_me_uma_size(struct udevice *me_dev)
  54. {
  55. struct me_uma uma;
  56. pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA);
  57. if (uma.valid) {
  58. debug("ME: Requested %uMB UMA\n", uma.size);
  59. return uma.size;
  60. }
  61. debug("ME: Invalid UMA size\n");
  62. return -EINVAL;
  63. }
  64. static inline void set_global_reset(struct udevice *dev, int enable)
  65. {
  66. u32 etr3;
  67. dm_pci_read_config32(dev, ETR3, &etr3);
  68. /* Clear CF9 Without Resume Well Reset Enable */
  69. etr3 &= ~ETR3_CWORWRE;
  70. /* CF9GR indicates a Global Reset */
  71. if (enable)
  72. etr3 |= ETR3_CF9GR;
  73. else
  74. etr3 &= ~ETR3_CF9GR;
  75. dm_pci_write_config32(dev, ETR3, etr3);
  76. }
  77. int intel_early_me_init_done(struct udevice *dev, struct udevice *me_dev,
  78. uint status)
  79. {
  80. int count;
  81. u32 mebase_l, mebase_h;
  82. struct me_hfs hfs;
  83. struct me_did did = {
  84. .init_done = ME_INIT_DONE,
  85. .status = status
  86. };
  87. /* MEBASE from MESEG_BASE[35:20] */
  88. dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_L, &mebase_l);
  89. dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_H, &mebase_h);
  90. mebase_h &= 0xf;
  91. did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
  92. /* Send message to ME */
  93. debug("ME: Sending Init Done with status: %d, UMA base: 0x%04x\n",
  94. status, did.uma_base);
  95. pci_write_dword_ptr(me_dev, &did, PCI_ME_H_GS);
  96. /* Must wait for ME acknowledgement */
  97. for (count = ME_RETRY; count > 0; --count) {
  98. pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
  99. if (hfs.bios_msg_ack)
  100. break;
  101. udelay(ME_DELAY);
  102. }
  103. if (!count) {
  104. printf("ERROR: ME failed to respond\n");
  105. return -ETIMEDOUT;
  106. }
  107. /* Return the requested BIOS action */
  108. debug("ME: Requested BIOS Action: %s\n", me_ack_values[hfs.ack_data]);
  109. /* Check status after acknowledgement */
  110. intel_me_status(me_dev);
  111. switch (hfs.ack_data) {
  112. case ME_HFS_ACK_CONTINUE:
  113. /* Continue to boot */
  114. return 0;
  115. case ME_HFS_ACK_RESET:
  116. /* Non-power cycle reset */
  117. set_global_reset(dev, 0);
  118. sysreset_walk_halt(SYSRESET_COLD);
  119. break;
  120. case ME_HFS_ACK_PWR_CYCLE:
  121. /* Power cycle reset */
  122. set_global_reset(dev, 0);
  123. sysreset_walk_halt(SYSRESET_COLD);
  124. break;
  125. case ME_HFS_ACK_GBL_RESET:
  126. /* Global reset */
  127. set_global_reset(dev, 1);
  128. sysreset_walk_halt(SYSRESET_COLD);
  129. break;
  130. case ME_HFS_ACK_S3:
  131. case ME_HFS_ACK_S4:
  132. case ME_HFS_ACK_S5:
  133. break;
  134. }
  135. return -EINVAL;
  136. }
  137. static const struct udevice_id ivybridge_syscon_ids[] = {
  138. { .compatible = "intel,me", .data = X86_SYSCON_ME },
  139. { }
  140. };
  141. U_BOOT_DRIVER(syscon_intel_me) = {
  142. .name = "intel_me_syscon",
  143. .id = UCLASS_SYSCON,
  144. .of_match = ivybridge_syscon_ids,
  145. };