1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
4  */
5 
6 #include <common.h>
7 #include <asm/cb_sysinfo.h>
8 #include <asm/global_data.h>
9 #include <init.h>
10 #include <smbios.h>
11 
board_early_init_r(void)12 int board_early_init_r(void)
13 {
14 	/*
15 	 * Make sure PCI bus is enumerated so that peripherals on the PCI bus
16 	 * can be discovered by their drivers
17 	 */
18 	pci_init();
19 
20 	return 0;
21 }
22 
23 #ifdef CONFIG_SMBIOS_PARSER
show_board_info(void)24 int show_board_info(void)
25 {
26 	const struct smbios_entry *smbios = smbios_entry(lib_sysinfo.smbios_start, lib_sysinfo.smbios_size);
27 
28 	if (!smbios)
29 		goto fallback;
30 
31 	const struct smbios_header *bios = smbios_header(smbios, SMBIOS_BIOS_INFORMATION);
32 	const struct smbios_header *system = smbios_header(smbios, SMBIOS_SYSTEM_INFORMATION);
33 	const struct smbios_type0 *t0 = (struct smbios_type0 *)bios;
34 	const struct smbios_type1 *t1 = (struct smbios_type1 *)system;
35 
36 	if (!t0 || !t1)
37 		goto fallback;
38 
39 	const char *bios_ver = smbios_string(bios, t0->bios_ver);
40 	const char *model = smbios_string(system, t1->product_name);
41 	const char *manufacturer = smbios_string(system, t1->manufacturer);
42 
43 	if (!model || !manufacturer || !bios_ver)
44 		goto fallback;
45 
46 	printf("Vendor: %s\n", manufacturer);
47 	printf("Model: %s\n", model);
48 	printf("BIOS Version: %s\n", bios_ver);
49 
50 	return 0;
51 
52 fallback:
53 #ifdef CONFIG_OF_CONTROL
54 	DECLARE_GLOBAL_DATA_PTR;
55 
56 	model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
57 
58 	if (model)
59 		printf("Model: %s\n", model);
60 #endif
61 
62 	return checkboard();
63 }
64 #endif
65