xref: /linux/arch/loongarch/kernel/env.c (revision 908fc4c2)
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 u64 loongson_chipcfg[MAX_PACKAGES];
21 u64 loongson_chiptemp[MAX_PACKAGES];
22 u64 loongson_freqctrl[MAX_PACKAGES];
23 unsigned long long smp_group[MAX_PACKAGES];
24 
25 static void __init register_addrs_set(u64 *registers, const u64 addr, int num)
26 {
27 	u64 i;
28 
29 	for (i = 0; i < num; i++) {
30 		*registers = (i << 44) | addr;
31 		registers++;
32 	}
33 }
34 
35 void __init init_environ(void)
36 {
37 	int efi_boot = fw_arg0;
38 	struct efi_memory_map_data data;
39 	void *fdt_ptr = early_memremap_ro(fw_arg1, SZ_64K);
40 
41 	if (efi_boot)
42 		set_bit(EFI_BOOT, &efi.flags);
43 	else
44 		clear_bit(EFI_BOOT, &efi.flags);
45 
46 	early_init_dt_scan(fdt_ptr);
47 	early_init_fdt_reserve_self();
48 	efi_system_table = efi_get_fdt_params(&data);
49 
50 	efi_memmap_init_early(&data);
51 	memblock_reserve(data.phys_map & PAGE_MASK,
52 			 PAGE_ALIGN(data.size + (data.phys_map & ~PAGE_MASK)));
53 
54 	register_addrs_set(smp_group, TO_UNCACHE(0x1fe01000), 16);
55 	register_addrs_set(loongson_chipcfg, TO_UNCACHE(0x1fe00180), 16);
56 	register_addrs_set(loongson_chiptemp, TO_UNCACHE(0x1fe0019c), 16);
57 	register_addrs_set(loongson_freqctrl, TO_UNCACHE(0x1fe001d0), 16);
58 }
59 
60 static int __init init_cpu_fullname(void)
61 {
62 	int cpu;
63 
64 	if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loongson", 8)) {
65 		for (cpu = 0; cpu < NR_CPUS; cpu++)
66 			__cpu_full_name[cpu] = loongson_sysconf.cpuname;
67 	}
68 	return 0;
69 }
70 arch_initcall(init_cpu_fullname);
71 
72 static ssize_t boardinfo_show(struct kobject *kobj,
73 			      struct kobj_attribute *attr, char *buf)
74 {
75 	return sprintf(buf,
76 		"BIOS Information\n"
77 		"Vendor\t\t\t: %s\n"
78 		"Version\t\t\t: %s\n"
79 		"ROM Size\t\t: %d KB\n"
80 		"Release Date\t\t: %s\n\n"
81 		"Board Information\n"
82 		"Manufacturer\t\t: %s\n"
83 		"Board Name\t\t: %s\n"
84 		"Family\t\t\t: LOONGSON64\n\n",
85 		b_info.bios_vendor, b_info.bios_version,
86 		b_info.bios_size, b_info.bios_release_date,
87 		b_info.board_vendor, b_info.board_name);
88 }
89 
90 static struct kobj_attribute boardinfo_attr = __ATTR(boardinfo, 0444,
91 						     boardinfo_show, NULL);
92 
93 static int __init boardinfo_init(void)
94 {
95 	struct kobject *loongson_kobj;
96 
97 	loongson_kobj = kobject_create_and_add("loongson", firmware_kobj);
98 
99 	return sysfs_create_file(loongson_kobj, &boardinfo_attr.attr);
100 }
101 late_initcall(boardinfo_init);
102