coreboot.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/io.h>
  16. #include <asm/arch-coreboot/tables.h>
  17. #include <asm/arch-coreboot/sysinfo.h>
  18. #include <asm/arch/timestamp.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. /*
  21. * Miscellaneous platform dependent initializations
  22. */
  23. int cpu_init_f(void)
  24. {
  25. int ret = get_coreboot_info(&lib_sysinfo);
  26. if (ret != 0)
  27. printf("Failed to parse coreboot tables.\n");
  28. timestamp_init();
  29. return ret;
  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 last_stage_init(void)
  65. {
  66. if (gd->flags & GD_FLG_COLD_BOOT)
  67. timestamp_add_to_bootstage();
  68. return 0;
  69. }
  70. #ifndef CONFIG_SYS_NO_FLASH
  71. ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
  72. {
  73. return 0;
  74. }
  75. #endif
  76. int board_eth_init(bd_t *bis)
  77. {
  78. return pci_eth_init(bis);
  79. }
  80. #define MTRR_TYPE_WP 5
  81. #define MTRRcap_MSR 0xfe
  82. #define MTRRphysBase_MSR(reg) (0x200 + 2 * (reg))
  83. #define MTRRphysMask_MSR(reg) (0x200 + 2 * (reg) + 1)
  84. int board_final_cleanup(void)
  85. {
  86. /* Un-cache the ROM so the kernel has one
  87. * more MTRR available.
  88. *
  89. * Coreboot should have assigned this to the
  90. * top available variable MTRR.
  91. */
  92. u8 top_mtrr = (native_read_msr(MTRRcap_MSR) & 0xff) - 1;
  93. u8 top_type = native_read_msr(MTRRphysBase_MSR(top_mtrr)) & 0xff;
  94. /* Make sure this MTRR is the correct Write-Protected type */
  95. if (top_type == MTRR_TYPE_WP) {
  96. disable_caches();
  97. wrmsrl(MTRRphysBase_MSR(top_mtrr), 0);
  98. wrmsrl(MTRRphysMask_MSR(top_mtrr), 0);
  99. enable_caches();
  100. }
  101. /* Issue SMI to Coreboot to lock down ME and registers */
  102. printf("Finalizing Coreboot\n");
  103. outb(0xcb, 0xb2);
  104. return 0;
  105. }
  106. void panic_puts(const char *str)
  107. {
  108. NS16550_t port = (NS16550_t)0x3f8;
  109. NS16550_init(port, 1);
  110. while (*str)
  111. NS16550_putc(port, *str++);
  112. }