xref: /openbmc/linux/arch/loongarch/kernel/env.c (revision f1288bdb)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Author: Huacai Chen <chenhuacai@loongson.cn>
4  *
5  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
6  */
7 #include <linux/acpi.h>
8 #include <linux/efi.h>
9 #include <linux/export.h>
10 #include <linux/memblock.h>
11 #include <linux/of_fdt.h>
12 #include <asm/early_ioremap.h>
13 #include <asm/bootinfo.h>
14 #include <asm/loongson.h>
15 
16 u64 efi_system_table;
17 struct loongson_system_configuration loongson_sysconf;
18 EXPORT_SYMBOL(loongson_sysconf);
19 
20 void __init init_environ(void)
21 {
22 	int efi_boot = fw_arg0;
23 	struct efi_memory_map_data data;
24 	void *fdt_ptr = early_memremap_ro(fw_arg1, SZ_64K);
25 
26 	if (efi_boot)
27 		set_bit(EFI_BOOT, &efi.flags);
28 	else
29 		clear_bit(EFI_BOOT, &efi.flags);
30 
31 	early_init_dt_scan(fdt_ptr);
32 	early_init_fdt_reserve_self();
33 	efi_system_table = efi_get_fdt_params(&data);
34 
35 	efi_memmap_init_early(&data);
36 	memblock_reserve(data.phys_map & PAGE_MASK,
37 			 PAGE_ALIGN(data.size + (data.phys_map & ~PAGE_MASK)));
38 }
39 
40 static int __init init_cpu_fullname(void)
41 {
42 	int cpu;
43 
44 	if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loongson", 8)) {
45 		for (cpu = 0; cpu < NR_CPUS; cpu++)
46 			__cpu_full_name[cpu] = loongson_sysconf.cpuname;
47 	}
48 	return 0;
49 }
50 arch_initcall(init_cpu_fullname);
51 
52 static ssize_t boardinfo_show(struct kobject *kobj,
53 			      struct kobj_attribute *attr, char *buf)
54 {
55 	return sprintf(buf,
56 		"BIOS Information\n"
57 		"Vendor\t\t\t: %s\n"
58 		"Version\t\t\t: %s\n"
59 		"ROM Size\t\t: %d KB\n"
60 		"Release Date\t\t: %s\n\n"
61 		"Board Information\n"
62 		"Manufacturer\t\t: %s\n"
63 		"Board Name\t\t: %s\n"
64 		"Family\t\t\t: LOONGSON64\n\n",
65 		b_info.bios_vendor, b_info.bios_version,
66 		b_info.bios_size, b_info.bios_release_date,
67 		b_info.board_vendor, b_info.board_name);
68 }
69 
70 static struct kobj_attribute boardinfo_attr = __ATTR(boardinfo, 0444,
71 						     boardinfo_show, NULL);
72 
73 static int __init boardinfo_init(void)
74 {
75 	struct kobject *loongson_kobj;
76 
77 	loongson_kobj = kobject_create_and_add("loongson", firmware_kobj);
78 
79 	return sysfs_create_file(loongson_kobj, &boardinfo_attr.attr);
80 }
81 late_initcall(boardinfo_init);
82