coreboot.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2011 The Chromium OS Authors.
  4. * (C) Copyright 2008
  5. * Graeme Russ, graeme.russ@gmail.com.
  6. */
  7. #include <common.h>
  8. #include <cpu_func.h>
  9. #include <fdtdec.h>
  10. #include <init.h>
  11. #include <usb.h>
  12. #include <asm/global_data.h>
  13. #include <asm/io.h>
  14. #include <asm/msr.h>
  15. #include <asm/mtrr.h>
  16. #include <asm/cb_sysinfo.h>
  17. #include <asm/arch/timestamp.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. int arch_cpu_init(void)
  20. {
  21. int ret = get_coreboot_info(&lib_sysinfo);
  22. if (ret != 0) {
  23. printf("Failed to parse coreboot tables.\n");
  24. return ret;
  25. }
  26. timestamp_init();
  27. return IS_ENABLED(CONFIG_X86_RUN_64BIT) ? x86_cpu_reinit_f() :
  28. x86_cpu_init_f();
  29. }
  30. int checkcpu(void)
  31. {
  32. return 0;
  33. }
  34. int print_cpuinfo(void)
  35. {
  36. return default_print_cpuinfo();
  37. }
  38. static void board_final_init(void)
  39. {
  40. /*
  41. * Un-cache the ROM so the kernel has one
  42. * more MTRR available.
  43. *
  44. * Coreboot should have assigned this to the
  45. * top available variable MTRR.
  46. */
  47. u8 top_mtrr = (native_read_msr(MTRR_CAP_MSR) & 0xff) - 1;
  48. u8 top_type = native_read_msr(MTRR_PHYS_BASE_MSR(top_mtrr)) & 0xff;
  49. /* Make sure this MTRR is the correct Write-Protected type */
  50. if (top_type == MTRR_TYPE_WRPROT) {
  51. struct mtrr_state state;
  52. mtrr_open(&state, true);
  53. wrmsrl(MTRR_PHYS_BASE_MSR(top_mtrr), 0);
  54. wrmsrl(MTRR_PHYS_MASK_MSR(top_mtrr), 0);
  55. mtrr_close(&state, true);
  56. }
  57. if (!fdtdec_get_config_bool(gd->fdt_blob, "u-boot,no-apm-finalize")) {
  58. /*
  59. * Issue SMI to coreboot to lock down ME and registers
  60. * when allowed via device tree
  61. */
  62. printf("Finalizing coreboot\n");
  63. outb(0xcb, 0xb2);
  64. }
  65. }
  66. int last_stage_init(void)
  67. {
  68. /* start usb so that usb keyboard can be used as input device */
  69. if (CONFIG_IS_ENABLED(USB_KEYBOARD))
  70. usb_init();
  71. board_final_init();
  72. return 0;
  73. }