]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/x86/cpu/intel_common/mrc.c
01b6e866b5b71e5c130e220a2b1305ad39ea1362
2 * Copyright (c) 2016 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0
12 #include <asm/intel_regs.h>
13 #include <asm/mrc_common.h>
14 #include <asm/pch_common.h>
16 #include <asm/arch/me.h>
17 #include <asm/report_platform.h>
19 static const char *const ecc_decoder
[] = {
26 ulong
mrc_common_board_get_usable_ram_top(ulong total_size
)
28 struct memory_info
*info
= &gd
->arch
.meminfo
;
29 uintptr_t dest_addr
= 0;
30 struct memory_area
*largest
= NULL
;
33 /* Find largest area of memory below 4GB */
35 for (i
= 0; i
< info
->num_areas
; i
++) {
36 struct memory_area
*area
= &info
->area
[i
];
38 if (area
->start
>= 1ULL << 32)
40 if (!largest
|| area
->size
> largest
->size
)
44 /* If no suitable area was found, return an error. */
46 if (!largest
|| largest
->size
< (2 << 20))
47 panic("No available memory found for relocation");
49 dest_addr
= largest
->start
+ largest
->size
;
51 return (ulong
)dest_addr
;
54 void mrc_common_dram_init_banksize(void)
56 struct memory_info
*info
= &gd
->arch
.meminfo
;
60 for (i
= 0, num_banks
= 0; i
< info
->num_areas
; i
++) {
61 struct memory_area
*area
= &info
->area
[i
];
63 if (area
->start
>= 1ULL << 32)
65 gd
->bd
->bi_dram
[num_banks
].start
= area
->start
;
66 gd
->bd
->bi_dram
[num_banks
].size
= area
->size
;
71 int mrc_add_memory_area(struct memory_info
*info
, uint64_t start
,
74 struct memory_area
*ptr
;
76 if (info
->num_areas
== CONFIG_NR_DRAM_BANKS
)
79 ptr
= &info
->area
[info
->num_areas
];
81 ptr
->size
= end
- start
;
82 info
->total_memory
+= ptr
->size
;
83 if (ptr
->start
< (1ULL << 32))
84 info
->total_32bit_memory
+= ptr
->size
;
85 debug("%d: memory %llx size %llx, total now %llx / %llx\n",
86 info
->num_areas
, ptr
->start
, ptr
->size
,
87 info
->total_32bit_memory
, info
->total_memory
);
94 * Dump in the log memory controller configuration as read from the memory
95 * controller registers.
97 void report_memory_config(void)
99 u32 addr_decoder_common
, addr_decode_ch
[2];
102 addr_decoder_common
= readl(MCHBAR_REG(0x5000));
103 addr_decode_ch
[0] = readl(MCHBAR_REG(0x5004));
104 addr_decode_ch
[1] = readl(MCHBAR_REG(0x5008));
106 debug("memcfg DDR3 clock %d MHz\n",
107 (readl(MCHBAR_REG(0x5e04)) * 13333 * 2 + 50) / 100);
108 debug("memcfg channel assignment: A: %d, B % d, C % d\n",
109 addr_decoder_common
& 3,
110 (addr_decoder_common
>> 2) & 3,
111 (addr_decoder_common
>> 4) & 3);
113 for (i
= 0; i
< ARRAY_SIZE(addr_decode_ch
); i
++) {
114 u32 ch_conf
= addr_decode_ch
[i
];
115 debug("memcfg channel[%d] config (%8.8x):\n", i
, ch_conf
);
116 debug(" ECC %s\n", ecc_decoder
[(ch_conf
>> 24) & 3]);
117 debug(" enhanced interleave mode %s\n",
118 ((ch_conf
>> 22) & 1) ? "on" : "off");
119 debug(" rank interleave %s\n",
120 ((ch_conf
>> 21) & 1) ? "on" : "off");
121 debug(" DIMMA %d MB width x%d %s rank%s\n",
122 ((ch_conf
>> 0) & 0xff) * 256,
123 ((ch_conf
>> 19) & 1) ? 16 : 8,
124 ((ch_conf
>> 17) & 1) ? "dual" : "single",
125 ((ch_conf
>> 16) & 1) ? "" : ", selected");
126 debug(" DIMMB %d MB width x%d %s rank%s\n",
127 ((ch_conf
>> 8) & 0xff) * 256,
128 ((ch_conf
>> 20) & 1) ? 16 : 8,
129 ((ch_conf
>> 18) & 1) ? "dual" : "single",
130 ((ch_conf
>> 16) & 1) ? ", selected" : "");
134 int mrc_locate_spd(struct udevice
*dev
, int size
, const void **spd_datap
)
136 const void *blob
= gd
->fdt_blob
;
138 struct gpio_desc desc
[4];
143 ret
= gpio_request_list_by_name(dev
, "board-id-gpios", desc
,
144 ARRAY_SIZE(desc
), GPIOD_IS_IN
);
146 debug("%s: gpio ret=%d\n", __func__
, ret
);
149 spd_index
= dm_gpio_get_values_as_int(desc
, ret
);
150 debug("spd index %d\n", spd_index
);
152 node
= fdt_first_subnode(blob
, dev
->of_offset
);
155 for (spd_node
= fdt_first_subnode(blob
, node
);
157 spd_node
= fdt_next_subnode(blob
, spd_node
)) {
160 if (fdtdec_get_int(blob
, spd_node
, "reg", -1) != spd_index
)
162 *spd_datap
= fdt_getprop(blob
, spd_node
, "data", &len
);
164 printf("Missing SPD data\n");
168 debug("Using SDRAM SPD data for '%s'\n",
169 fdt_get_name(blob
, spd_node
, NULL
));
173 printf("No SPD data found for index %d\n", spd_index
);
177 asmlinkage
void sdram_console_tx_byte(unsigned char byte
)
185 * Find the PEI executable in the ROM and execute it.
187 * @me_dev: Management Engine device
188 * @pei_data: configuration data for UEFI PEI reference code
190 static int sdram_initialise(struct udevice
*dev
, struct udevice
*me_dev
,
191 void *pei_data
, bool use_asm_linkage
)
196 report_platform_info(dev
);
197 debug("Starting UEFI PEI System Agent\n");
199 debug("PEI data at %p:\n", pei_data
);
201 data
= (char *)CONFIG_X86_MRC_ADDR
;
206 debug("Calling MRC at %p\n", data
);
207 post_code(POST_PRE_MRC
);
208 start
= get_timer(0);
209 if (use_asm_linkage
) {
210 asmlinkage
int (*func
)(void *);
212 func
= (asmlinkage
int (*)(void *))data
;
217 func
= (int (*)(void *))data
;
224 printf("PEI version mismatch.\n");
227 printf("Invalid memory frequency.\n");
230 printf("MRC returned %x.\n", rv
);
232 printf("Nonzero MRC return value.\n");
235 debug("MRC execution time %lu ms\n", get_timer(start
));
237 printf("UEFI PEI System Agent not found.\n");
241 version
= readl(MCHBAR_REG(MCHBAR_PEI_VERSION
));
242 debug("System Agent Version %d.%d.%d Build %d\n",
243 version
>> 24 , (version
>> 16) & 0xff,
244 (version
>> 8) & 0xff, version
& 0xff);
247 /* mrc.bin reconfigures USB, so reinit it to have debug */
248 early_usbdebug_init();
254 int mrc_common_init(struct udevice
*dev
, void *pei_data
, bool use_asm_linkage
)
256 struct udevice
*me_dev
;
259 ret
= syscon_get_by_driver_data(X86_SYSCON_ME
, &me_dev
);
263 ret
= sdram_initialise(dev
, me_dev
, pei_data
, use_asm_linkage
);
267 post_code(POST_DRAM
);
268 report_memory_config();