diff mbox series

[v4,1/3] MIPS: Loongson: Get host bridge information

Message ID 1585906191-26037-2-git-send-email-yangtiezhu@loongson.cn (mailing list archive)
State Accepted
Headers show
Series Add basic support for LS7A bridge chip | expand

Commit Message

Tiezhu Yang April 3, 2020, 9:29 a.m. UTC
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.

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

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(+)

Comments

Jiaxun Yang April 3, 2020, 9:38 a.m. UTC | #1
于 2020年4月3日 GMT+08:00 下午5:29:49, Tiezhu Yang <yangtiezhu@loongson.cn> 写到:
>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@flygoat.com>

>
>Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>---
>
>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@gmail.com
>  */
> #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;
>+	}
> }
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 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@gmail.com
  */
 #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;
+	}
 }