Re: [PATCH v4 1/3] MIPS: Loongson: Get host bridge information
From: Jiaxun Yang
Date: Fri Apr 03 2020 - 05:39:14 EST
ä 2020å4æ3æ GMT+08:00 äå5:29:49, Tiezhu Yang <yangtiezhu@xxxxxxxxxxx> åå:
>Read the address of host bridge configuration space to get the vendor
>ID
>and device ID of host bridge, and then we can distinguish various types
>of host bridge such as LS7A or RS780E.
I'm a little bit uncomfortable about this kind of hack.
Wish Loongson will establish a elegant boot proctol in future.
For this patch,
Reviewed-by: Jiaxun Yang <jiaxun.yang@xxxxxxxxxxx>
>
>Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
>---
>
>v3:
> - Modify the macro definition HOST_BRIDGE_CONFIG_ADDR and
> add comment to make it easy to read.
> - Use PCI_VENDOR_ID_LOONGSON in pci_ids.h instead of 0x0014
>
> PCI_VENDOR_ID_LOONGSON depends on the mainline tree's commit:
>https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9acb9fe18d86
>
>v4:
> - Use LS7A instead of Loongson 7A1000 in the description
> - Use LS7A or ls7a instead of LS7A1000 or ls7a1000 in the code
>
> arch/mips/include/asm/mach-loongson64/boot_param.h | 6 ++++++
>arch/mips/loongson64/env.c | 18
>++++++++++++++++++
> 2 files changed, 24 insertions(+)
>
>diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h
>b/arch/mips/include/asm/mach-loongson64/boot_param.h
>index 2ed483e..fc9f14b 100644
>--- a/arch/mips/include/asm/mach-loongson64/boot_param.h
>+++ b/arch/mips/include/asm/mach-loongson64/boot_param.h
>@@ -192,6 +192,11 @@ struct boot_params {
> struct efi_reset_system_t reset_system;
> };
>
>+enum loongson_bridge_type {
>+ RS780E = 1,
>+ LS7A = 2
>+};
>+
> struct loongson_system_configuration {
> u32 nr_cpus;
> u32 nr_nodes;
>@@ -200,6 +205,7 @@ struct loongson_system_configuration {
> u16 boot_cpu_id;
> u16 reserved_cpus_mask;
> enum loongson_cpu_type cputype;
>+ enum loongson_bridge_type bridgetype;
> u64 ht_control_base;
> u64 pci_mem_start_addr;
> u64 pci_mem_end_addr;
>diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c
>index 2554ef1..71f4aaf 100644
>--- a/arch/mips/loongson64/env.c
>+++ b/arch/mips/loongson64/env.c
>@@ -14,12 +14,15 @@
> * Author: Wu Zhangjin, wuzhangjin@xxxxxxxxx
> */
> #include <linux/export.h>
>+#include <linux/pci_ids.h>
> #include <asm/bootinfo.h>
> #include <loongson.h>
> #include <boot_param.h>
> #include <builtin_dtbs.h>
> #include <workarounds.h>
>
>+#define HOST_BRIDGE_CONFIG_ADDR ((void __iomem *)TO_UNCAC(0x1a000000))
>+
> u32 cpu_clock_freq;
> EXPORT_SYMBOL(cpu_clock_freq);
> struct efi_memory_map_loongson *loongson_memmap;
>@@ -43,6 +46,8 @@ void __init prom_init_env(void)
> struct system_loongson *esys;
> struct efi_cpuinfo_loongson *ecpu;
> struct irq_source_routing_table *eirq_source;
>+ u32 id;
>+ u16 vendor, device;
>
> /* firmware arguments are initialized in head.S */
> boot_p = (struct boot_params *)fw_arg2;
>@@ -178,4 +183,17 @@ void __init prom_init_env(void)
> memcpy(loongson_sysconf.sensors, esys->sensors,
> sizeof(struct sensor_device) * loongson_sysconf.nr_sensors);
> pr_info("CpuClock = %u\n", cpu_clock_freq);
>+
>+ /* Read the ID of PCI host bridge to detect bridge type */
>+ id = readl(HOST_BRIDGE_CONFIG_ADDR);
>+ vendor = id & 0xffff;
>+ device = (id >> 16) & 0xffff;
>+
>+ if (vendor == PCI_VENDOR_ID_LOONGSON && device == 0x7a00) {
>+ pr_info("The bridge chip is LS7A\n");
>+ loongson_sysconf.bridgetype = LS7A;
>+ } else {
>+ pr_info("The bridge chip is RS780E or SR5690\n");
>+ loongson_sysconf.bridgetype = RS780E;
>+ }
> }
--
Jiaxun Yang