diff mbox series

[v2,3/4,RESEND] MIPS: Loongson64: Add /proc/boardinfo

Message ID 1602373674-4579-4-git-send-email-yangtiezhu@loongson.cn (mailing list archive)
State Superseded
Headers show
Series Avoid build error, clean up numa.c and add /proc/boardinfo | expand

Commit Message

Tiezhu Yang Oct. 10, 2020, 11:47 p.m. UTC
Add /proc/boardinfo to get mainboard and BIOS info easily on the Loongson
platform, this is useful to point out the current used mainboard type and
BIOS version when there exists problems related with hardware or firmware.

E.g. with this patch:

[loongson@linux ~]$ cat /proc/boardinfo
Board Info
Manufacturer            : LEMOTE
Board Name              : LEMOTE-LS3A4000-7A1000-1w-V01-pc
Family                  : LOONGSON3

BIOS Info
Vendor                  : Kunlun
Version                 : Kunlun-A1901-V4.1.3-20200414093938
ROM Size                : 4 KB
Release Date            : 2020-04-14

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---

v2: no changes

 arch/mips/include/asm/mach-loongson64/boot_param.h |  4 +++
 arch/mips/loongson64/Makefile                      |  2 +-
 arch/mips/loongson64/boardinfo.c                   | 40 ++++++++++++++++++++++
 arch/mips/loongson64/env.c                         | 10 ++++++
 4 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/loongson64/boardinfo.c

Comments

Thomas Bogendoerfer Oct. 12, 2020, 10:38 a.m. UTC | #1
On Sun, Oct 11, 2020 at 07:47:53AM +0800, Tiezhu Yang wrote:
> Add /proc/boardinfo to get mainboard and BIOS info easily on the Loongson
> platform, this is useful to point out the current used mainboard type and
> BIOS version when there exists problems related with hardware or firmware.
> 
> E.g. with this patch:
> 
> [loongson@linux ~]$ cat /proc/boardinfo
> Board Info
> Manufacturer            : LEMOTE
> Board Name              : LEMOTE-LS3A4000-7A1000-1w-V01-pc
> Family                  : LOONGSON3
> 
> BIOS Info
> Vendor                  : Kunlun
> Version                 : Kunlun-A1901-V4.1.3-20200414093938
> ROM Size                : 4 KB
> Release Date            : 2020-04-14

Why does Loongson64 need this extra file no other architecture or MIPS
platform need ? Do others provide this information via a different method ?
If yes, why can't Loongson64 do the same ?

Thomas.
Tiezhu Yang Oct. 12, 2020, 12:02 p.m. UTC | #2
On 10/12/2020 06:38 PM, Thomas Bogendoerfer wrote:
> On Sun, Oct 11, 2020 at 07:47:53AM +0800, Tiezhu Yang wrote:
>> Add /proc/boardinfo to get mainboard and BIOS info easily on the Loongson
>> platform, this is useful to point out the current used mainboard type and
>> BIOS version when there exists problems related with hardware or firmware.
>>
>> E.g. with this patch:
>>
>> [loongson@linux ~]$ cat /proc/boardinfo
>> Board Info
>> Manufacturer            : LEMOTE
>> Board Name              : LEMOTE-LS3A4000-7A1000-1w-V01-pc
>> Family                  : LOONGSON3
>>
>> BIOS Info
>> Vendor                  : Kunlun
>> Version                 : Kunlun-A1901-V4.1.3-20200414093938
>> ROM Size                : 4 KB
>> Release Date            : 2020-04-14
> Why does Loongson64 need this extra file no other architecture or MIPS
> platform need ? Do others provide this information via a different method ?
> If yes, why can't Loongson64 do the same ?

Hi Thomas,

This is related with the implementation of firmware.

Using dmidecode command can get the similar info if there exists SMBIOS
in firmware, but the fact is there is no SMBIOS on some machines, we can
see nothing when execute dmidecode, like this:

[root@linux loongson]# dmidecode
# dmidecode 2.12
# No SMBIOS nor DMI entry point found, sorry.

The following three structures are already defined in the interface
specification about firmware and kernel on the Loongson platform,
this is common requirement and specific for Loongson64, so add a
new boardinfo.c file in arch/mips/loongson64.

arch/mips/include/asm/mach-loongson64/boot_param.h
struct interface_info {
     u16 vers; /* version of the specificition */
     u16 size;
     u8  flag;
     char description[64];
} __packed;

struct board_devices {
     char name[64];    /* hold the device name */
     u32 num_resources; /* number of device_resource */
     /* for each device's resource */
     struct resource_loongson resource[MAX_RESOURCE_NUMBER];
     /* arch specific additions */
     struct archdev_data archdata;
};

struct loongson_special_attribute {
     u16 vers;     /* version of this special */
     char special_name[64]; /* special_atribute_name */
     u32 loongson_special_type; /* type of special device */
     /* for each device's resource */
     struct resource_loongson resource[MAX_RESOURCE_NUMBER];
};

Thanks,
Tiezhu

>
> Thomas.
>
Jiaxun Yang Oct. 13, 2020, 12:15 a.m. UTC | #3
于 2020年10月12日 GMT+08:00 下午8:02:25, Tiezhu Yang <yangtiezhu@loongson.cn> 写到:
>On 10/12/2020 06:38 PM, Thomas Bogendoerfer wrote:
>> On Sun, Oct 11, 2020 at 07:47:53AM +0800, Tiezhu Yang wrote:
>>> Add /proc/boardinfo to get mainboard and BIOS info easily on the Loongson
>>> platform, this is useful to point out the current used mainboard type and
>>> BIOS version when there exists problems related with hardware or firmware.
>>>
>>> E.g. with this patch:
>>>
>>> [loongson@linux ~]$ cat /proc/boardinfo
>>> Board Info
>>> Manufacturer            : LEMOTE
>>> Board Name              : LEMOTE-LS3A4000-7A1000-1w-V01-pc
>>> Family                  : LOONGSON3
>>>
>>> BIOS Info
>>> Vendor                  : Kunlun
>>> Version                 : Kunlun-A1901-V4.1.3-20200414093938
>>> ROM Size                : 4 KB
>>> Release Date            : 2020-04-14
>> Why does Loongson64 need this extra file no other architecture or MIPS
>> platform need ? Do others provide this information via a different method ?
>> If yes, why can't Loongson64 do the same ?
>
>Hi Thomas,
>
>This is related with the implementation of firmware.
>
>Using dmidecode command can get the similar info if there exists SMBIOS
>in firmware, but the fact is there is no SMBIOS on some machines, we can
>see nothing when execute dmidecode, like this:
>
>[root@linux loongson]# dmidecode
># dmidecode 2.12
># No SMBIOS nor DMI entry point found, sorry.
>
>The following three structures are already defined in the interface
>specification about firmware and kernel on the Loongson platform,
>this is common requirement and specific for Loongson64, so add a
>new boardinfo.c file in arch/mips/loongson64.
>
>arch/mips/include/asm/mach-loongson64/boot_param.h
>struct interface_info {
>     u16 vers; /* version of the specificition */
>     u16 size;
>     u8  flag;
>     char description[64];
>} __packed;
>
>struct board_devices {
>     char name[64];    /* hold the device name */
>     u32 num_resources; /* number of device_resource */
>     /* for each device's resource */
>     struct resource_loongson resource[MAX_RESOURCE_NUMBER];
>     /* arch specific additions */
>     struct archdev_data archdata;
>};
>
>struct loongson_special_attribute {
>     u16 vers;     /* version of this special */
>     char special_name[64]; /* special_atribute_name */
>     u32 loongson_special_type; /* type of special device */
>     /* for each device's resource */
>     struct resource_loongson resource[MAX_RESOURCE_NUMBER];
>};

Hi Tiezhu,

Through I don't think touching top level of proc would be a good idea. It's all about API consistency.

If you intend to provide user an interface then I guess /sys/firmware/lefi
like what DMI did or somewhere less critical is better.

There is no guarantee that Loongson64 device would come with LEFI,
although it's mandatory for now.

Thanks.

- Jiaxun

>
>Thanks,
>Tiezhu
>
>>
>> Thomas.
>>
Tiezhu Yang Oct. 13, 2020, 4:36 a.m. UTC | #4
On 10/13/2020 08:15 AM, Jiaxun Yang wrote:
>
> 于 2020年10月12日 GMT+08:00 下午8:02:25, Tiezhu Yang <yangtiezhu@loongson.cn> 写到:
>> On 10/12/2020 06:38 PM, Thomas Bogendoerfer wrote:
>>> On Sun, Oct 11, 2020 at 07:47:53AM +0800, Tiezhu Yang wrote:
>>>> Add /proc/boardinfo to get mainboard and BIOS info easily on the Loongson
>>>> platform, this is useful to point out the current used mainboard type and
>>>> BIOS version when there exists problems related with hardware or firmware.
>>>>
>>>> E.g. with this patch:
>>>>
>>>> [loongson@linux ~]$ cat /proc/boardinfo
>>>> Board Info
>>>> Manufacturer            : LEMOTE
>>>> Board Name              : LEMOTE-LS3A4000-7A1000-1w-V01-pc
>>>> Family                  : LOONGSON3
>>>>
>>>> BIOS Info
>>>> Vendor                  : Kunlun
>>>> Version                 : Kunlun-A1901-V4.1.3-20200414093938
>>>> ROM Size                : 4 KB
>>>> Release Date            : 2020-04-14
>>> Why does Loongson64 need this extra file no other architecture or MIPS
>>> platform need ? Do others provide this information via a different method ?
>>> If yes, why can't Loongson64 do the same ?
>> Hi Thomas,
>>
>> This is related with the implementation of firmware.
>>
>> Using dmidecode command can get the similar info if there exists SMBIOS
>> in firmware, but the fact is there is no SMBIOS on some machines, we can
>> see nothing when execute dmidecode, like this:
>>
>> [root@linux loongson]# dmidecode
>> # dmidecode 2.12
>> # No SMBIOS nor DMI entry point found, sorry.
>>
>> The following three structures are already defined in the interface
>> specification about firmware and kernel on the Loongson platform,
>> this is common requirement and specific for Loongson64, so add a
>> new boardinfo.c file in arch/mips/loongson64.
>>
>> arch/mips/include/asm/mach-loongson64/boot_param.h
>> struct interface_info {
>>      u16 vers; /* version of the specificition */
>>      u16 size;
>>      u8  flag;
>>      char description[64];
>> } __packed;
>>
>> struct board_devices {
>>      char name[64];    /* hold the device name */
>>      u32 num_resources; /* number of device_resource */
>>      /* for each device's resource */
>>      struct resource_loongson resource[MAX_RESOURCE_NUMBER];
>>      /* arch specific additions */
>>      struct archdev_data archdata;
>> };
>>
>> struct loongson_special_attribute {
>>      u16 vers;     /* version of this special */
>>      char special_name[64]; /* special_atribute_name */
>>      u32 loongson_special_type; /* type of special device */
>>      /* for each device's resource */
>>      struct resource_loongson resource[MAX_RESOURCE_NUMBER];
>> };
> Hi Tiezhu,
>
> Through I don't think touching top level of proc would be a good idea. It's all about API consistency.
>
> If you intend to provide user an interface then I guess /sys/firmware/lefi
> like what DMI did or somewhere less critical is better.
>
> There is no guarantee that Loongson64 device would come with LEFI,
> although it's mandatory for now.

Hi Jiaxun,

Thank you very much.

Let us add /sys/firmware/lefi/boardinfo, I will do it and then send a 
new patch.

Thanks,
Tiezhu

>
> Thanks.
>
> - Jiaxun
>
>> Thanks,
>> Tiezhu
>>
>>> Thomas.
>>>
diff mbox series

Patch

diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h
index afc92b7..4592841 100644
--- a/arch/mips/include/asm/mach-loongson64/boot_param.h
+++ b/arch/mips/include/asm/mach-loongson64/boot_param.h
@@ -228,6 +228,10 @@  struct loongson_system_configuration {
 extern struct efi_memory_map_loongson *loongson_memmap;
 extern struct loongson_system_configuration loongson_sysconf;
 
+extern struct board_devices *eboard;
+extern struct interface_info *einter;
+extern struct loongson_special_attribute *especial;
+
 extern u32 node_id_offset;
 extern void ls7a_early_config(void);
 extern void rs780e_early_config(void);
diff --git a/arch/mips/loongson64/Makefile b/arch/mips/loongson64/Makefile
index 39c06f5..bc77b5a 100644
--- a/arch/mips/loongson64/Makefile
+++ b/arch/mips/loongson64/Makefile
@@ -3,7 +3,7 @@ 
 # Makefile for Loongson-3 family machines
 #
 obj-$(CONFIG_MACH_LOONGSON64) += cop2-ex.o platform.o dma.o \
-				setup.o init.o env.o time.o reset.o \
+				setup.o init.o env.o time.o reset.o boardinfo.o\
 
 obj-$(CONFIG_SMP)	+= smp.o
 obj-$(CONFIG_NUMA)	+= numa.o
diff --git a/arch/mips/loongson64/boardinfo.c b/arch/mips/loongson64/boardinfo.c
new file mode 100644
index 0000000..2e8086b
--- /dev/null
+++ b/arch/mips/loongson64/boardinfo.c
@@ -0,0 +1,40 @@ 
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/fs.h>
+#include <linux/init.h>
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include <linux/module.h>
+#include <boot_param.h>
+
+static int loongson_boardinfo_proc_show(struct seq_file *m, void *v)
+{
+	char board_manufacturer[64] = {0};
+	char *tmp_board_manufacturer = board_manufacturer;
+	char bios_vendor[64] = {0};
+	char *tmp_bios_vendor = bios_vendor;
+
+	strcpy(board_manufacturer, eboard->name);
+	strcpy(bios_vendor, einter->description);
+
+	seq_puts(m, "Board Info\n");
+	seq_printf(m, "Manufacturer\t\t: %s\n", strsep(&tmp_board_manufacturer, "-"));
+	seq_printf(m, "Board Name\t\t: %s\n", eboard->name);
+	seq_puts(m, "Family\t\t\t: LOONGSON3\n");
+	seq_puts(m, "\n");
+
+	seq_puts(m, "BIOS Info\n");
+	seq_printf(m, "Vendor\t\t\t: %s\n", strsep(&tmp_bios_vendor, "-"));
+	seq_printf(m, "Version\t\t\t: %s\n", einter->description);
+	seq_printf(m, "ROM Size\t\t: %d KB\n", einter->size);
+	seq_printf(m, "Release Date\t\t: %s\n", especial->special_name);
+
+	return 0;
+}
+
+static int __init proc_boardinfo_init(void)
+{
+	proc_create_single("boardinfo", 0, NULL, loongson_boardinfo_proc_show);
+	return 0;
+}
+
+module_init(proc_boardinfo_init);
diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c
index 134cb8e..51a5d05 100644
--- a/arch/mips/loongson64/env.c
+++ b/arch/mips/loongson64/env.c
@@ -28,6 +28,10 @@  EXPORT_SYMBOL(cpu_clock_freq);
 struct efi_memory_map_loongson *loongson_memmap;
 struct loongson_system_configuration loongson_sysconf;
 
+struct board_devices *eboard;
+struct interface_info *einter;
+struct loongson_special_attribute *especial;
+
 u64 loongson_chipcfg[MAX_PACKAGES] = {0xffffffffbfc00180};
 u64 loongson_chiptemp[MAX_PACKAGES];
 u64 loongson_freqctrl[MAX_PACKAGES];
@@ -57,6 +61,12 @@  void __init prom_init_env(void)
 		((u64)loongson_p + loongson_p->system_offset);
 	ecpu = (struct efi_cpuinfo_loongson *)
 		((u64)loongson_p + loongson_p->cpu_offset);
+	eboard = (struct board_devices *)
+		((u64)loongson_p + loongson_p->boarddev_table_offset);
+	einter = (struct interface_info *)
+		((u64)loongson_p + loongson_p->interface_offset);
+	especial = (struct loongson_special_attribute *)
+		((u64)loongson_p + loongson_p->special_offset);
 	eirq_source = (struct irq_source_routing_table *)
 		((u64)loongson_p + loongson_p->irq_offset);
 	loongson_memmap = (struct efi_memory_map_loongson *)