File Index
Files and directories
Sign in
FILE

env.c

File preview with syntax highlighting.

linux-6.19.14/arch/loongarch/kernel/env.c C
  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
 19u64 efi_system_table;
 20struct loongson_system_configuration loongson_sysconf;
 21EXPORT_SYMBOL(loongson_sysconf);
 22
 23void __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
 40static int __init init_cpu_fullname(void)
 41{
 42	int cpu, ret;
 43	char *cpuname;
 44	const char *model;
 45
 46	/* Parsing cpuname from DTS model property */
 47	ret = of_property_read_string(of_root, "model", &model);
 48	if (ret == 0) {
 49		cpuname = kstrdup(model, GFP_KERNEL);
 50		if (!cpuname)
 51			return -ENOMEM;
 52		loongson_sysconf.cpuname = strsep(&cpuname, " ");
 53	}
 54
 55	if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loongson", 8)) {
 56		for (cpu = 0; cpu < NR_CPUS; cpu++)
 57			__cpu_full_name[cpu] = loongson_sysconf.cpuname;
 58	}
 59	return 0;
 60}
 61arch_initcall(init_cpu_fullname);
 62
 63static int __init fdt_cpu_clk_init(void)
 64{
 65	struct clk *clk;
 66	struct device_node *np;
 67
 68	np = of_get_cpu_node(0, NULL);
 69	if (!np)
 70		return -ENODEV;
 71
 72	clk = of_clk_get(np, 0);
 73	of_node_put(np);
 74	cpu_clock_freq = 200 * 1000 * 1000;
 75
 76	if (IS_ERR(clk)) {
 77		pr_warn("No valid CPU clock freq, assume 200MHz.\n");
 78		return -ENODEV;
 79	}
 80
 81	cpu_clock_freq = clk_get_rate(clk);
 82	clk_put(clk);
 83
 84	return 0;
 85}
 86late_initcall(fdt_cpu_clk_init);
 87
 88static ssize_t boardinfo_show(struct kobject *kobj,
 89			      struct kobj_attribute *attr, char *buf)
 90{
 91	return sysfs_emit(buf,
 92		"BIOS Information\n"
 93		"Vendor\t\t\t: %s\n"
 94		"Version\t\t\t: %s\n"
 95		"ROM Size\t\t: %d KB\n"
 96		"Release Date\t\t: %s\n\n"
 97		"Board Information\n"
 98		"Manufacturer\t\t: %s\n"
 99		"Board Name\t\t: %s\n"
100		"Family\t\t\t: LOONGSON64\n\n",
101		b_info.bios_vendor, b_info.bios_version,
102		b_info.bios_size, b_info.bios_release_date,
103		b_info.board_vendor, b_info.board_name);
104}
105
106static struct kobj_attribute boardinfo_attr = __ATTR(boardinfo, 0444,
107						     boardinfo_show, NULL);
108
109static int __init boardinfo_init(void)
110{
111	struct kobject *loongson_kobj;
112
113	loongson_kobj = kobject_create_and_add("loongson", firmware_kobj);
114	if (!loongson_kobj)
115		return -ENOMEM;
116
117	return sysfs_create_file(loongson_kobj, &boardinfo_attr.attr);
118}
119late_initcall(boardinfo_init);
~/ Read-only file preview.