env.c 2.7 KB

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