xref: /linux/arch/loongarch/kernel/env.c (revision 22c55fb9eb92395d999b8404d73e58540d11bdd8)
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/clk.h>
9 #include <linux/efi.h>
10 #include <linux/export.h>
11 #include <linux/memblock.h>
12 #include <linux/of_clk.h>
13 #include <asm/early_ioremap.h>
14 #include <asm/bootinfo.h>
15 #include <asm/loongson.h>
16 #include <asm/setup.h>
17 #include <asm/time.h>
18 
19 u64 efi_system_table;
20 struct loongson_system_configuration loongson_sysconf;
21 EXPORT_SYMBOL(loongson_sysconf);
22 
23 void __init init_environ(void)
24 {
25 	int efi_boot = fw_arg0;
26 	char *cmdline = early_memremap_ro(fw_arg1, COMMAND_LINE_SIZE);
27 
28 	if (efi_boot)
29 		set_bit(EFI_BOOT, &efi.flags);
30 	else
31 		clear_bit(EFI_BOOT, &efi.flags);
32 
33 	strscpy(boot_command_line, cmdline, COMMAND_LINE_SIZE);
34 	strscpy(init_command_line, cmdline, COMMAND_LINE_SIZE);
35 	early_memunmap(cmdline, COMMAND_LINE_SIZE);
36 
37 	efi_system_table = fw_arg2;
38 }
39 
40 static int __init init_cpu_fullname(void)
41 {
42 	int cpu, ret;
43 	char *cpuname;
44 	const char *model;
45 	struct device_node *root;
46 
47 	/* Parsing cpuname from DTS model property */
48 	root = of_find_node_by_path("/");
49 	ret = of_property_read_string(root, "model", &model);
50 	if (ret == 0) {
51 		cpuname = kstrdup(model, GFP_KERNEL);
52 		loongson_sysconf.cpuname = strsep(&cpuname, " ");
53 	}
54 	of_node_put(root);
55 
56 	if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loongson", 8)) {
57 		for (cpu = 0; cpu < NR_CPUS; cpu++)
58 			__cpu_full_name[cpu] = loongson_sysconf.cpuname;
59 	}
60 	return 0;
61 }
62 arch_initcall(init_cpu_fullname);
63 
64 static int __init fdt_cpu_clk_init(void)
65 {
66 	struct clk *clk;
67 	struct device_node *np;
68 
69 	np = of_get_cpu_node(0, NULL);
70 	if (!np)
71 		return -ENODEV;
72 
73 	clk = of_clk_get(np, 0);
74 	of_node_put(np);
75 
76 	if (IS_ERR(clk))
77 		return -ENODEV;
78 
79 	cpu_clock_freq = clk_get_rate(clk);
80 	clk_put(clk);
81 
82 	return 0;
83 }
84 late_initcall(fdt_cpu_clk_init);
85 
86 static ssize_t boardinfo_show(struct kobject *kobj,
87 			      struct kobj_attribute *attr, char *buf)
88 {
89 	return sprintf(buf,
90 		"BIOS Information\n"
91 		"Vendor\t\t\t: %s\n"
92 		"Version\t\t\t: %s\n"
93 		"ROM Size\t\t: %d KB\n"
94 		"Release Date\t\t: %s\n\n"
95 		"Board Information\n"
96 		"Manufacturer\t\t: %s\n"
97 		"Board Name\t\t: %s\n"
98 		"Family\t\t\t: LOONGSON64\n\n",
99 		b_info.bios_vendor, b_info.bios_version,
100 		b_info.bios_size, b_info.bios_release_date,
101 		b_info.board_vendor, b_info.board_name);
102 }
103 
104 static struct kobj_attribute boardinfo_attr = __ATTR(boardinfo, 0444,
105 						     boardinfo_show, NULL);
106 
107 static int __init boardinfo_init(void)
108 {
109 	struct kobject *loongson_kobj;
110 
111 	loongson_kobj = kobject_create_and_add("loongson", firmware_kobj);
112 
113 	return sysfs_create_file(loongson_kobj, &boardinfo_attr.attr);
114 }
115 late_initcall(boardinfo_init);
116