Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/arch/loongarch/kernel/env.c
49231 views
1
// SPDX-License-Identifier: GPL-2.0
2
/*
3
* Author: Huacai Chen <[email protected]>
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
cpu_clock_freq = 200 * 1000 * 1000;
76
77
if (IS_ERR(clk)) {
78
pr_warn("No valid CPU clock freq, assume 200MHz.\n");
79
return -ENODEV;
80
}
81
82
cpu_clock_freq = clk_get_rate(clk);
83
clk_put(clk);
84
85
return 0;
86
}
87
late_initcall(fdt_cpu_clk_init);
88
89
static ssize_t boardinfo_show(struct kobject *kobj,
90
struct kobj_attribute *attr, char *buf)
91
{
92
return sysfs_emit(buf,
93
"BIOS Information\n"
94
"Vendor\t\t\t: %s\n"
95
"Version\t\t\t: %s\n"
96
"ROM Size\t\t: %d KB\n"
97
"Release Date\t\t: %s\n\n"
98
"Board Information\n"
99
"Manufacturer\t\t: %s\n"
100
"Board Name\t\t: %s\n"
101
"Family\t\t\t: LOONGSON64\n\n",
102
b_info.bios_vendor, b_info.bios_version,
103
b_info.bios_size, b_info.bios_release_date,
104
b_info.board_vendor, b_info.board_name);
105
}
106
107
static struct kobj_attribute boardinfo_attr = __ATTR(boardinfo, 0444,
108
boardinfo_show, NULL);
109
110
static int __init boardinfo_init(void)
111
{
112
struct kobject *loongson_kobj;
113
114
loongson_kobj = kobject_create_and_add("loongson", firmware_kobj);
115
if (!loongson_kobj)
116
return -ENOMEM;
117
118
return sysfs_create_file(loongson_kobj, &boardinfo_attr.attr);
119
}
120
late_initcall(boardinfo_init);
121
122