fsp_common.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <errno.h>
  9. #include <rtc.h>
  10. #include <asm/acpi_s3.h>
  11. #include <asm/cmos_layout.h>
  12. #include <asm/early_cmos.h>
  13. #include <asm/io.h>
  14. #include <asm/mrccache.h>
  15. #include <asm/post.h>
  16. #include <asm/processor.h>
  17. #include <asm/fsp/fsp_support.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. int checkcpu(void)
  20. {
  21. return 0;
  22. }
  23. int print_cpuinfo(void)
  24. {
  25. post_code(POST_CPU_INFO);
  26. return default_print_cpuinfo();
  27. }
  28. int fsp_init_phase_pci(void)
  29. {
  30. u32 status;
  31. /* call into FspNotify */
  32. debug("Calling into FSP (notify phase INIT_PHASE_PCI): ");
  33. status = fsp_notify(NULL, INIT_PHASE_PCI);
  34. if (status)
  35. debug("fail, error code %x\n", status);
  36. else
  37. debug("OK\n");
  38. return status ? -EPERM : 0;
  39. }
  40. void board_final_cleanup(void)
  41. {
  42. u32 status;
  43. /* call into FspNotify */
  44. debug("Calling into FSP (notify phase INIT_PHASE_BOOT): ");
  45. status = fsp_notify(NULL, INIT_PHASE_BOOT);
  46. if (status)
  47. debug("fail, error code %x\n", status);
  48. else
  49. debug("OK\n");
  50. return;
  51. }
  52. static __maybe_unused void *fsp_prepare_mrc_cache(void)
  53. {
  54. struct mrc_data_container *cache;
  55. struct mrc_region entry;
  56. int ret;
  57. ret = mrccache_get_region(NULL, &entry);
  58. if (ret)
  59. return NULL;
  60. cache = mrccache_find_current(&entry);
  61. if (!cache)
  62. return NULL;
  63. debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__,
  64. cache->data, cache->data_size, cache->checksum);
  65. return cache->data;
  66. }
  67. #ifdef CONFIG_HAVE_ACPI_RESUME
  68. int fsp_save_s3_stack(void)
  69. {
  70. struct udevice *dev;
  71. int ret;
  72. if (gd->arch.prev_sleep_state == ACPI_S3)
  73. return 0;
  74. ret = uclass_get_device(UCLASS_RTC, 0, &dev);
  75. if (ret) {
  76. debug("Cannot find RTC: err=%d\n", ret);
  77. return -ENODEV;
  78. }
  79. /* Save the stack address to CMOS */
  80. ret = rtc_write32(dev, CMOS_FSP_STACK_ADDR, gd->start_addr_sp);
  81. if (ret) {
  82. debug("Save stack address to CMOS: err=%d\n", ret);
  83. return -EIO;
  84. }
  85. return 0;
  86. }
  87. #endif
  88. int arch_fsp_init(void)
  89. {
  90. void *nvs;
  91. int stack = CONFIG_FSP_TEMP_RAM_ADDR;
  92. int boot_mode = BOOT_FULL_CONFIG;
  93. #ifdef CONFIG_HAVE_ACPI_RESUME
  94. int prev_sleep_state = chipset_prev_sleep_state();
  95. gd->arch.prev_sleep_state = prev_sleep_state;
  96. #endif
  97. if (!gd->arch.hob_list) {
  98. #ifdef CONFIG_ENABLE_MRC_CACHE
  99. nvs = fsp_prepare_mrc_cache();
  100. #else
  101. nvs = NULL;
  102. #endif
  103. #ifdef CONFIG_HAVE_ACPI_RESUME
  104. if (prev_sleep_state == ACPI_S3) {
  105. if (nvs == NULL) {
  106. /* If waking from S3 and no cache then */
  107. debug("No MRC cache found in S3 resume path\n");
  108. post_code(POST_RESUME_FAILURE);
  109. /* Clear Sleep Type */
  110. chipset_clear_sleep_state();
  111. /* Reboot */
  112. debug("Rebooting..\n");
  113. reset_cpu(0);
  114. /* Should not reach here.. */
  115. panic("Reboot System");
  116. }
  117. /*
  118. * DM is not avaiable yet at this point, hence call
  119. * CMOS access library which does not depend on DM.
  120. */
  121. stack = cmos_read32(CMOS_FSP_STACK_ADDR);
  122. boot_mode = BOOT_ON_S3_RESUME;
  123. }
  124. #endif
  125. /*
  126. * The first time we enter here, call fsp_init().
  127. * Note the execution does not return to this function,
  128. * instead it jumps to fsp_continue().
  129. */
  130. fsp_init(stack, boot_mode, nvs);
  131. } else {
  132. /*
  133. * The second time we enter here, adjust the size of malloc()
  134. * pool before relocation. Given gd->malloc_base was adjusted
  135. * after the call to board_init_f_init_reserve() in arch/x86/
  136. * cpu/start.S, we should fix up gd->malloc_limit here.
  137. */
  138. gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
  139. }
  140. return 0;
  141. }