Prepare v2023.10
[platform/kernel/u-boot.git] / arch / x86 / lib / init_helpers.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2011
4  * Graeme Russ, <graeme.russ@gmail.com>
5  */
6
7 #include <common.h>
8 #include <init.h>
9 #include <asm/global_data.h>
10 #include <linux/errno.h>
11 #include <asm/mtrr.h>
12
13 DECLARE_GLOBAL_DATA_PTR;
14
15 int init_cache_f_r(void)
16 {
17         bool do_mtrr = CONFIG_IS_ENABLED(X86_32BIT_INIT) ||
18                  IS_ENABLED(CONFIG_FSP_VERSION2);
19         int ret;
20
21         /*
22          * Supported configurations:
23          *
24          * booting from slimbootloader - MTRRs are already set up
25          * booting with FSPv1 - MTRRs are already set up
26          * booting with FSPv2 - MTRRs must be set here
27          * booting from coreboot - in this case there is no SPL, so we set up
28          *      the MTRRs here
29          * Note: if there is an SPL, then it has already set up MTRRs so we
30          *      don't need to do that here
31          */
32         do_mtrr &= !IS_ENABLED(CONFIG_FSP_VERSION1) &&
33                 !IS_ENABLED(CONFIG_SYS_SLIMBOOTLOADER);
34
35         if (do_mtrr) {
36                 ret = mtrr_commit(false);
37                 /*
38                  * If MTRR MSR is not implemented by the processor, just ignore
39                  * it
40                  */
41                 if (ret && ret != -ENOSYS)
42                         return ret;
43         }
44
45         /* Initialise the CPU cache(s) */
46         return init_cache();
47 }