blob: da43d66e95d7dc18b456f9023ecc762b167193a0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Gabe Blackef5a5b02011-11-29 18:05:07 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
4 * (C) Copyright 2008
5 * Graeme Russ, graeme.russ@gmail.com.
Gabe Blackef5a5b02011-11-29 18:05:07 +00006 */
7
8#include <common.h>
Simon Glass30c7c432019-11-14 12:57:34 -07009#include <cpu_func.h>
Simon Glass91caa3b2023-08-21 21:17:01 -060010#include <event.h>
Bin Mengf2653e82015-06-03 09:20:05 +080011#include <fdtdec.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Bin Mengceeee8f2018-08-10 02:39:33 -070013#include <usb.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Stefan Reinauer300081a2012-12-03 13:58:12 +000015#include <asm/io.h>
Bin Meng65cdd9b2015-06-03 09:20:02 +080016#include <asm/msr.h>
Simon Glassaff25232015-01-01 16:18:07 -070017#include <asm/mtrr.h>
Simon Glasse35b6492021-03-15 18:00:18 +130018#include <asm/cb_sysinfo.h>
Vadim Bendebury6dbe0cc2012-10-23 18:04:33 +000019#include <asm/arch/timestamp.h>
Simon Glass7de8bd02021-08-07 07:24:01 -060020#include <dm/ofnode.h>
Gabe Blackef5a5b02011-11-29 18:05:07 +000021
Simon Glass8b37c762014-11-06 13:20:06 -070022int arch_cpu_init(void)
Gabe Black63f559c2011-12-05 12:09:22 +000023{
Simon Glass2c6b9792023-09-19 21:00:04 -060024 int ret;
25
26 ret = IS_ENABLED(CONFIG_X86_RUN_64BIT) ? x86_cpu_reinit_f() :
27 x86_cpu_init_f();
28 if (ret)
29 return ret;
30
31 ret = get_coreboot_info(&lib_sysinfo);
Simon Glass8b37c762014-11-06 13:20:06 -070032 if (ret != 0) {
Gabe Black63f559c2011-12-05 12:09:22 +000033 printf("Failed to parse coreboot tables.\n");
Simon Glass8b37c762014-11-06 13:20:06 -070034 return ret;
35 }
Vadim Bendebury6dbe0cc2012-10-23 18:04:33 +000036
37 timestamp_init();
38
Simon Glass2c6b9792023-09-19 21:00:04 -060039 return 0;
Gabe Black63f559c2011-12-05 12:09:22 +000040}
41
Simon Glass76d1d022017-03-28 10:27:30 -060042int checkcpu(void)
43{
44 return 0;
45}
46
Simon Glass727c1a92014-11-10 18:00:26 -070047int print_cpuinfo(void)
48{
49 return default_print_cpuinfo();
50}
51
Simon Glass4021ee62020-07-16 21:22:38 -060052static void board_final_init(void)
Stefan Reinauer17de1142012-12-02 04:49:53 +000053{
Bin Meng65cdd9b2015-06-03 09:20:02 +080054 /*
55 * Un-cache the ROM so the kernel has one
Stefan Reinauer17de1142012-12-02 04:49:53 +000056 * more MTRR available.
Duncan Laurie488b8b22012-12-03 13:59:00 +000057 *
58 * Coreboot should have assigned this to the
59 * top available variable MTRR.
Stefan Reinauer17de1142012-12-02 04:49:53 +000060 */
Simon Glassaff25232015-01-01 16:18:07 -070061 u8 top_mtrr = (native_read_msr(MTRR_CAP_MSR) & 0xff) - 1;
62 u8 top_type = native_read_msr(MTRR_PHYS_BASE_MSR(top_mtrr)) & 0xff;
Duncan Laurie488b8b22012-12-03 13:59:00 +000063
64 /* Make sure this MTRR is the correct Write-Protected type */
Simon Glassaff25232015-01-01 16:18:07 -070065 if (top_type == MTRR_TYPE_WRPROT) {
66 struct mtrr_state state;
67
Simon Glass590cee82018-10-01 12:22:37 -060068 mtrr_open(&state, true);
Simon Glassaff25232015-01-01 16:18:07 -070069 wrmsrl(MTRR_PHYS_BASE_MSR(top_mtrr), 0);
70 wrmsrl(MTRR_PHYS_MASK_MSR(top_mtrr), 0);
Simon Glass590cee82018-10-01 12:22:37 -060071 mtrr_close(&state, true);
Duncan Laurie488b8b22012-12-03 13:59:00 +000072 }
Stefan Reinauer17de1142012-12-02 04:49:53 +000073
Simon Glass7de8bd02021-08-07 07:24:01 -060074 if (!ofnode_conf_read_bool("u-boot,no-apm-finalize")) {
Bin Mengf2653e82015-06-03 09:20:05 +080075 /*
76 * Issue SMI to coreboot to lock down ME and registers
77 * when allowed via device tree
78 */
79 printf("Finalizing coreboot\n");
80 outb(0xcb, 0xb2);
81 }
Stefan Reinauer17de1142012-12-02 04:49:53 +000082}
Simon Glassc78a62a2013-04-17 16:13:34 +000083
Simon Glass91caa3b2023-08-21 21:17:01 -060084static int last_stage_init(void)
Bin Meng1e2f7b92016-05-11 07:44:56 -070085{
Simon Glass91caa3b2023-08-21 21:17:01 -060086 if (IS_ENABLED(CONFIG_SPL_BUILD))
87 return 0;
88
Bin Mengceeee8f2018-08-10 02:39:33 -070089 /* start usb so that usb keyboard can be used as input device */
Simon Glass91b614e2023-02-05 17:55:28 -070090 if (IS_ENABLED(CONFIG_USB_KEYBOARD))
Thomas RIENOESSLf86bd762018-11-29 20:07:12 -080091 usb_init();
Bin Mengceeee8f2018-08-10 02:39:33 -070092
Simon Glass4021ee62020-07-16 21:22:38 -060093 board_final_init();
Bin Meng1e2f7b92016-05-11 07:44:56 -070094
95 return 0;
96}
Simon Glass91caa3b2023-08-21 21:17:01 -060097EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init);