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 
init_cache_f_r(void)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 - in that case the MTRRs are already set
25 	 *	up
26 	 * booting with FSPv1 - MTRRs are already set up
27 	 * booting with FSPv2 - MTRRs must be set here
28 	 * booting from coreboot - in this case there is no SPL, so we set up
29 	 *	the MTRRs here
30 	 * Note: if there is an SPL, then it has already set up MTRRs so we
31 	 *	don't need to do that here
32 	 */
33 	do_mtrr &= !IS_ENABLED(CONFIG_SPL) &&
34 		!IS_ENABLED(CONFIG_FSP_VERSION1) &&
35 		!IS_ENABLED(CONFIG_SYS_SLIMBOOTLOADER);
36 
37 	if (do_mtrr) {
38 		ret = mtrr_commit(false);
39 		/*
40 		 * If MTRR MSR is not implemented by the processor, just ignore
41 		 * it
42 		 */
43 		if (ret && ret != -ENOSYS)
44 			return ret;
45 	}
46 
47 	/* Initialise the CPU cache(s) */
48 	return init_cache();
49 }
50