coreboot.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * (C) Copyright 2008
  4. * Graeme Russ, graeme.russ@gmail.com.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <asm/u-boot-x86.h>
  10. #include <flash.h>
  11. #include <netdev.h>
  12. #include <ns16550.h>
  13. #include <asm/msr.h>
  14. #include <asm/cache.h>
  15. #include <asm/cpu.h>
  16. #include <asm/io.h>
  17. #include <asm/arch-coreboot/tables.h>
  18. #include <asm/arch-coreboot/sysinfo.h>
  19. #include <asm/arch/timestamp.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. int arch_cpu_init(void)
  22. {
  23. int ret = get_coreboot_info(&lib_sysinfo);
  24. if (ret != 0) {
  25. printf("Failed to parse coreboot tables.\n");
  26. return ret;
  27. }
  28. timestamp_init();
  29. return x86_cpu_init_f();
  30. }
  31. int board_early_init_f(void)
  32. {
  33. return 0;
  34. }
  35. int board_early_init_r(void)
  36. {
  37. /* CPU Speed to 100MHz */
  38. gd->cpu_clk = 100000000;
  39. /* Crystal is 33.000MHz */
  40. gd->bus_clk = 33000000;
  41. return 0;
  42. }
  43. void show_boot_progress(int val)
  44. {
  45. #if MIN_PORT80_KCLOCKS_DELAY
  46. /*
  47. * Scale the time counter reading to avoid using 64 bit arithmetics.
  48. * Can't use get_timer() here becuase it could be not yet
  49. * initialized or even implemented.
  50. */
  51. if (!gd->arch.tsc_prev) {
  52. gd->arch.tsc_base_kclocks = rdtsc() / 1000;
  53. gd->arch.tsc_prev = 0;
  54. } else {
  55. uint32_t now;
  56. do {
  57. now = rdtsc() / 1000 - gd->arch.tsc_base_kclocks;
  58. } while (now < (gd->arch.tsc_prev + MIN_PORT80_KCLOCKS_DELAY));
  59. gd->arch.tsc_prev = now;
  60. }
  61. #endif
  62. outb(val, 0x80);
  63. }
  64. int print_cpuinfo(void)
  65. {
  66. return default_print_cpuinfo();
  67. }
  68. int last_stage_init(void)
  69. {
  70. if (gd->flags & GD_FLG_COLD_BOOT)
  71. timestamp_add_to_bootstage();
  72. return 0;
  73. }
  74. #ifndef CONFIG_SYS_NO_FLASH
  75. ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
  76. {
  77. return 0;
  78. }
  79. #endif
  80. int board_eth_init(bd_t *bis)
  81. {
  82. return pci_eth_init(bis);
  83. }
  84. #define MTRR_TYPE_WP 5
  85. #define MTRRcap_MSR 0xfe
  86. #define MTRRphysBase_MSR(reg) (0x200 + 2 * (reg))
  87. #define MTRRphysMask_MSR(reg) (0x200 + 2 * (reg) + 1)
  88. void board_final_cleanup(void)
  89. {
  90. /* Un-cache the ROM so the kernel has one
  91. * more MTRR available.
  92. *
  93. * Coreboot should have assigned this to the
  94. * top available variable MTRR.
  95. */
  96. u8 top_mtrr = (native_read_msr(MTRRcap_MSR) & 0xff) - 1;
  97. u8 top_type = native_read_msr(MTRRphysBase_MSR(top_mtrr)) & 0xff;
  98. /* Make sure this MTRR is the correct Write-Protected type */
  99. if (top_type == MTRR_TYPE_WP) {
  100. disable_caches();
  101. wrmsrl(MTRRphysBase_MSR(top_mtrr), 0);
  102. wrmsrl(MTRRphysMask_MSR(top_mtrr), 0);
  103. enable_caches();
  104. }
  105. /* Issue SMI to Coreboot to lock down ME and registers */
  106. printf("Finalizing Coreboot\n");
  107. outb(0xcb, 0xb2);
  108. }
  109. void panic_puts(const char *str)
  110. {
  111. NS16550_t port = (NS16550_t)0x3f8;
  112. NS16550_init(port, 1);
  113. while (*str)
  114. NS16550_putc(port, *str++);
  115. }