fsp_common.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 <errno.h>
  8. #include <asm/acpi_s3.h>
  9. #include <asm/io.h>
  10. #include <asm/mrccache.h>
  11. #include <asm/post.h>
  12. #include <asm/processor.h>
  13. #include <asm/fsp/fsp_support.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. int checkcpu(void)
  16. {
  17. return 0;
  18. }
  19. int print_cpuinfo(void)
  20. {
  21. post_code(POST_CPU_INFO);
  22. return default_print_cpuinfo();
  23. }
  24. int fsp_init_phase_pci(void)
  25. {
  26. u32 status;
  27. /* call into FspNotify */
  28. debug("Calling into FSP (notify phase INIT_PHASE_PCI): ");
  29. status = fsp_notify(NULL, INIT_PHASE_PCI);
  30. if (status)
  31. debug("fail, error code %x\n", status);
  32. else
  33. debug("OK\n");
  34. return status ? -EPERM : 0;
  35. }
  36. void board_final_cleanup(void)
  37. {
  38. u32 status;
  39. /* call into FspNotify */
  40. debug("Calling into FSP (notify phase INIT_PHASE_BOOT): ");
  41. status = fsp_notify(NULL, INIT_PHASE_BOOT);
  42. if (status)
  43. debug("fail, error code %x\n", status);
  44. else
  45. debug("OK\n");
  46. return;
  47. }
  48. static __maybe_unused void *fsp_prepare_mrc_cache(void)
  49. {
  50. struct mrc_data_container *cache;
  51. struct mrc_region entry;
  52. int ret;
  53. ret = mrccache_get_region(NULL, &entry);
  54. if (ret)
  55. return NULL;
  56. cache = mrccache_find_current(&entry);
  57. if (!cache)
  58. return NULL;
  59. debug("%s: mrc cache at %p, size %x checksum %04x\n", __func__,
  60. cache->data, cache->data_size, cache->checksum);
  61. return cache->data;
  62. }
  63. int arch_fsp_init(void)
  64. {
  65. void *nvs;
  66. int boot_mode = BOOT_FULL_CONFIG;
  67. #ifdef CONFIG_HAVE_ACPI_RESUME
  68. int prev_sleep_state = chipset_prev_sleep_state();
  69. gd->arch.prev_sleep_state = prev_sleep_state;
  70. #endif
  71. if (!gd->arch.hob_list) {
  72. #ifdef CONFIG_ENABLE_MRC_CACHE
  73. nvs = fsp_prepare_mrc_cache();
  74. #else
  75. nvs = NULL;
  76. #endif
  77. #ifdef CONFIG_HAVE_ACPI_RESUME
  78. if (prev_sleep_state == ACPI_S3) {
  79. if (nvs == NULL) {
  80. /* If waking from S3 and no cache then */
  81. debug("No MRC cache found in S3 resume path\n");
  82. post_code(POST_RESUME_FAILURE);
  83. /* Clear Sleep Type */
  84. chipset_clear_sleep_state();
  85. /* Reboot */
  86. debug("Rebooting..\n");
  87. reset_cpu(0);
  88. /* Should not reach here.. */
  89. panic("Reboot System");
  90. }
  91. boot_mode = BOOT_ON_S3_RESUME;
  92. }
  93. #endif
  94. /*
  95. * The first time we enter here, call fsp_init().
  96. * Note the execution does not return to this function,
  97. * instead it jumps to fsp_continue().
  98. */
  99. fsp_init(CONFIG_FSP_TEMP_RAM_ADDR, boot_mode, nvs);
  100. } else {
  101. /*
  102. * The second time we enter here, adjust the size of malloc()
  103. * pool before relocation. Given gd->malloc_base was adjusted
  104. * after the call to board_init_f_init_reserve() in arch/x86/
  105. * cpu/start.S, we should fix up gd->malloc_limit here.
  106. */
  107. gd->malloc_limit += CONFIG_FSP_SYS_MALLOC_F_LEN;
  108. }
  109. return 0;
  110. }