fsp_common.c 3.5 KB

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