env.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. struct device_node *root;
  37. int cpu, ret;
  38. char *model;
  39. /* Parsing cpuname from DTS model property */
  40. root = of_find_node_by_path("/");
  41. ret = of_property_read_string(root, "model", (const char **)&model);
  42. of_node_put(root);
  43. if (ret == 0)
  44. loongson_sysconf.cpuname = strsep(&model, " ");
  45. if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loongson", 8)) {
  46. for (cpu = 0; cpu < NR_CPUS; cpu++)
  47. __cpu_full_name[cpu] = loongson_sysconf.cpuname;
  48. }
  49. return 0;
  50. }
  51. arch_initcall(init_cpu_fullname);
  52. static int __init fdt_cpu_clk_init(void)
  53. {
  54. struct clk *clk;
  55. struct device_node *np;
  56. np = of_get_cpu_node(0, NULL);
  57. if (!np)
  58. return -ENODEV;
  59. clk = of_clk_get(np, 0);
  60. if (IS_ERR(clk))
  61. return -ENODEV;
  62. cpu_clock_freq = clk_get_rate(clk);
  63. clk_put(clk);
  64. return 0;
  65. }
  66. late_initcall(fdt_cpu_clk_init);
  67. static ssize_t boardinfo_show(struct kobject *kobj,
  68. struct kobj_attribute *attr, char *buf)
  69. {
  70. return sprintf(buf,
  71. "BIOS Information\n"
  72. "Vendor\t\t\t: %s\n"
  73. "Version\t\t\t: %s\n"
  74. "ROM Size\t\t: %d KB\n"
  75. "Release Date\t\t: %s\n\n"
  76. "Board Information\n"
  77. "Manufacturer\t\t: %s\n"
  78. "Board Name\t\t: %s\n"
  79. "Family\t\t\t: LOONGSON64\n\n",
  80. b_info.bios_vendor, b_info.bios_version,
  81. b_info.bios_size, b_info.bios_release_date,
  82. b_info.board_vendor, b_info.board_name);
  83. }
  84. static struct kobj_attribute boardinfo_attr = __ATTR(boardinfo, 0444,
  85. boardinfo_show, NULL);
  86. static int __init boardinfo_init(void)
  87. {
  88. struct kobject *loongson_kobj;
  89. loongson_kobj = kobject_create_and_add("loongson", firmware_kobj);
  90. return sysfs_create_file(loongson_kobj, &boardinfo_attr.attr);
  91. }
  92. late_initcall(boardinfo_init);