coreboot.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/tables.h>
  18. #include <asm/arch/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 print_cpuinfo(void)
  36. {
  37. return default_print_cpuinfo();
  38. }
  39. int last_stage_init(void)
  40. {
  41. if (gd->flags & GD_FLG_COLD_BOOT)
  42. timestamp_add_to_bootstage();
  43. return 0;
  44. }
  45. #ifndef CONFIG_SYS_NO_FLASH
  46. ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
  47. {
  48. return 0;
  49. }
  50. #endif
  51. int board_eth_init(bd_t *bis)
  52. {
  53. return pci_eth_init(bis);
  54. }
  55. #define MTRR_TYPE_WP 5
  56. #define MTRRcap_MSR 0xfe
  57. #define MTRRphysBase_MSR(reg) (0x200 + 2 * (reg))
  58. #define MTRRphysMask_MSR(reg) (0x200 + 2 * (reg) + 1)
  59. void board_final_cleanup(void)
  60. {
  61. /* Un-cache the ROM so the kernel has one
  62. * more MTRR available.
  63. *
  64. * Coreboot should have assigned this to the
  65. * top available variable MTRR.
  66. */
  67. u8 top_mtrr = (native_read_msr(MTRRcap_MSR) & 0xff) - 1;
  68. u8 top_type = native_read_msr(MTRRphysBase_MSR(top_mtrr)) & 0xff;
  69. /* Make sure this MTRR is the correct Write-Protected type */
  70. if (top_type == MTRR_TYPE_WP) {
  71. disable_caches();
  72. wrmsrl(MTRRphysBase_MSR(top_mtrr), 0);
  73. wrmsrl(MTRRphysMask_MSR(top_mtrr), 0);
  74. enable_caches();
  75. }
  76. /* Issue SMI to Coreboot to lock down ME and registers */
  77. printf("Finalizing Coreboot\n");
  78. outb(0xcb, 0xb2);
  79. }
  80. void panic_puts(const char *str)
  81. {
  82. NS16550_t port = (NS16550_t)0x3f8;
  83. NS16550_init(port, 1);
  84. while (*str)
  85. NS16550_putc(port, *str++);
  86. }