Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Gabe Black | ef5a5b0 | 2011-11-29 18:05:07 +0000 | [diff] [blame] | 2 | /* |
3 | * Copyright (c) 2011 The Chromium OS Authors. | ||||
4 | * (C) Copyright 2008 | ||||
5 | * Graeme Russ, graeme.russ@gmail.com. | ||||
Gabe Black | ef5a5b0 | 2011-11-29 18:05:07 +0000 | [diff] [blame] | 6 | */ |
7 | |||||
8 | #include <common.h> | ||||
Simon Glass | 30c7c43 | 2019-11-14 12:57:34 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | 91caa3b | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 10 | #include <event.h> |
Bin Meng | f2653e8 | 2015-06-03 09:20:05 +0800 | [diff] [blame] | 11 | #include <fdtdec.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Bin Meng | ceeee8f | 2018-08-10 02:39:33 -0700 | [diff] [blame] | 13 | #include <usb.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Stefan Reinauer | 300081a | 2012-12-03 13:58:12 +0000 | [diff] [blame] | 15 | #include <asm/io.h> |
Bin Meng | 65cdd9b | 2015-06-03 09:20:02 +0800 | [diff] [blame] | 16 | #include <asm/msr.h> |
Simon Glass | aff2523 | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 17 | #include <asm/mtrr.h> |
Simon Glass | e35b649 | 2021-03-15 18:00:18 +1300 | [diff] [blame] | 18 | #include <asm/cb_sysinfo.h> |
Vadim Bendebury | 6dbe0cc | 2012-10-23 18:04:33 +0000 | [diff] [blame] | 19 | #include <asm/arch/timestamp.h> |
Simon Glass | 7de8bd0 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 20 | #include <dm/ofnode.h> |
Gabe Black | ef5a5b0 | 2011-11-29 18:05:07 +0000 | [diff] [blame] | 21 | |
Simon Glass | 8b37c76 | 2014-11-06 13:20:06 -0700 | [diff] [blame] | 22 | int arch_cpu_init(void) |
Gabe Black | 63f559c | 2011-12-05 12:09:22 +0000 | [diff] [blame] | 23 | { |
Simon Glass | 2c6b979 | 2023-09-19 21:00:04 -0600 | [diff] [blame] | 24 | 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 Glass | 8b37c76 | 2014-11-06 13:20:06 -0700 | [diff] [blame] | 32 | if (ret != 0) { |
Gabe Black | 63f559c | 2011-12-05 12:09:22 +0000 | [diff] [blame] | 33 | printf("Failed to parse coreboot tables.\n"); |
Simon Glass | 8b37c76 | 2014-11-06 13:20:06 -0700 | [diff] [blame] | 34 | return ret; |
35 | } | ||||
Vadim Bendebury | 6dbe0cc | 2012-10-23 18:04:33 +0000 | [diff] [blame] | 36 | |
37 | timestamp_init(); | ||||
38 | |||||
Simon Glass | 2c6b979 | 2023-09-19 21:00:04 -0600 | [diff] [blame] | 39 | return 0; |
Gabe Black | 63f559c | 2011-12-05 12:09:22 +0000 | [diff] [blame] | 40 | } |
41 | |||||
Simon Glass | 76d1d02 | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 42 | int checkcpu(void) |
43 | { | ||||
44 | return 0; | ||||
45 | } | ||||
46 | |||||
Simon Glass | 727c1a9 | 2014-11-10 18:00:26 -0700 | [diff] [blame] | 47 | int print_cpuinfo(void) |
48 | { | ||||
49 | return default_print_cpuinfo(); | ||||
50 | } | ||||
51 | |||||
Simon Glass | 4021ee6 | 2020-07-16 21:22:38 -0600 | [diff] [blame] | 52 | static void board_final_init(void) |
Stefan Reinauer | 17de114 | 2012-12-02 04:49:53 +0000 | [diff] [blame] | 53 | { |
Bin Meng | 65cdd9b | 2015-06-03 09:20:02 +0800 | [diff] [blame] | 54 | /* |
55 | * Un-cache the ROM so the kernel has one | ||||
Stefan Reinauer | 17de114 | 2012-12-02 04:49:53 +0000 | [diff] [blame] | 56 | * more MTRR available. |
Duncan Laurie | 488b8b2 | 2012-12-03 13:59:00 +0000 | [diff] [blame] | 57 | * |
58 | * Coreboot should have assigned this to the | ||||
59 | * top available variable MTRR. | ||||
Stefan Reinauer | 17de114 | 2012-12-02 04:49:53 +0000 | [diff] [blame] | 60 | */ |
Simon Glass | aff2523 | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 61 | 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 Laurie | 488b8b2 | 2012-12-03 13:59:00 +0000 | [diff] [blame] | 63 | |
64 | /* Make sure this MTRR is the correct Write-Protected type */ | ||||
Simon Glass | aff2523 | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 65 | if (top_type == MTRR_TYPE_WRPROT) { |
66 | struct mtrr_state state; | ||||
67 | |||||
Simon Glass | 590cee8 | 2018-10-01 12:22:37 -0600 | [diff] [blame] | 68 | mtrr_open(&state, true); |
Simon Glass | aff2523 | 2015-01-01 16:18:07 -0700 | [diff] [blame] | 69 | wrmsrl(MTRR_PHYS_BASE_MSR(top_mtrr), 0); |
70 | wrmsrl(MTRR_PHYS_MASK_MSR(top_mtrr), 0); | ||||
Simon Glass | 590cee8 | 2018-10-01 12:22:37 -0600 | [diff] [blame] | 71 | mtrr_close(&state, true); |
Duncan Laurie | 488b8b2 | 2012-12-03 13:59:00 +0000 | [diff] [blame] | 72 | } |
Stefan Reinauer | 17de114 | 2012-12-02 04:49:53 +0000 | [diff] [blame] | 73 | |
Simon Glass | 7de8bd0 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 74 | if (!ofnode_conf_read_bool("u-boot,no-apm-finalize")) { |
Bin Meng | f2653e8 | 2015-06-03 09:20:05 +0800 | [diff] [blame] | 75 | /* |
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 Reinauer | 17de114 | 2012-12-02 04:49:53 +0000 | [diff] [blame] | 82 | } |
Simon Glass | c78a62a | 2013-04-17 16:13:34 +0000 | [diff] [blame] | 83 | |
Simon Glass | 91caa3b | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 84 | static int last_stage_init(void) |
Bin Meng | 1e2f7b9 | 2016-05-11 07:44:56 -0700 | [diff] [blame] | 85 | { |
Simon Glass | 91caa3b | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 86 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
87 | return 0; | ||||
88 | |||||
Bin Meng | ceeee8f | 2018-08-10 02:39:33 -0700 | [diff] [blame] | 89 | /* start usb so that usb keyboard can be used as input device */ |
Simon Glass | 91b614e | 2023-02-05 17:55:28 -0700 | [diff] [blame] | 90 | if (IS_ENABLED(CONFIG_USB_KEYBOARD)) |
Thomas RIENOESSL | f86bd76 | 2018-11-29 20:07:12 -0800 | [diff] [blame] | 91 | usb_init(); |
Bin Meng | ceeee8f | 2018-08-10 02:39:33 -0700 | [diff] [blame] | 92 | |
Simon Glass | 4021ee6 | 2020-07-16 21:22:38 -0600 | [diff] [blame] | 93 | board_final_init(); |
Bin Meng | 1e2f7b9 | 2016-05-11 07:44:56 -0700 | [diff] [blame] | 94 | |
95 | return 0; | ||||
96 | } | ||||
Simon Glass | 91caa3b | 2023-08-21 21:17:01 -0600 | [diff] [blame] | 97 | EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init); |