Skip to content

Commit 39c1485

Browse files
chenhuacaitsbogend
authored andcommitted
MIPS: KVM: Add kvm guest support for Loongson-3
Loongson-3 KVM guest is based on virtio, it use liointc as its interrupt controller and use GPEX as the pci controller. Signed-off-by: Huacai Chen <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent a84a334 commit 39c1485

File tree

7 files changed

+125
-3
lines changed

7 files changed

+125
-3
lines changed

arch/mips/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ config MACH_LOONGSON64
478478
select COMMON_CLK
479479
select USE_OF
480480
select BUILTIN_DTB
481+
select PCI_HOST_GENERIC
481482
help
482483
This enables the support of Loongson-2/3 family of machines.
483484

arch/mips/boot/dts/loongson/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ dtb-$(CONFIG_MACH_LOONGSON64) += loongson64c_4core_ls7a.dtb
33
dtb-$(CONFIG_MACH_LOONGSON64) += loongson64c_4core_rs780e.dtb
44
dtb-$(CONFIG_MACH_LOONGSON64) += loongson64c_8core_rs780e.dtb
55
dtb-$(CONFIG_MACH_LOONGSON64) += loongson64g_4core_ls7a.dtb
6+
dtb-$(CONFIG_MACH_LOONGSON64) += loongson64v_4core_virtio.dtb
67

78
obj-$(CONFIG_BUILTIN_DTB) += $(addsuffix .o, $(dtb-y))
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <dt-bindings/interrupt-controller/irq.h>
4+
5+
/dts-v1/;
6+
/ {
7+
compatible = "loongson,loongson64v-4core-virtio";
8+
#address-cells = <2>;
9+
#size-cells = <2>;
10+
11+
cpuintc: interrupt-controller {
12+
#address-cells = <0>;
13+
#interrupt-cells = <1>;
14+
interrupt-controller;
15+
compatible = "mti,cpu-interrupt-controller";
16+
};
17+
18+
package0: bus@1fe00000 {
19+
compatible = "simple-bus";
20+
#address-cells = <2>;
21+
#size-cells = <1>;
22+
ranges = <0 0x1fe00000 0 0x1fe00000 0x100000
23+
0 0x3ff00000 0 0x3ff00000 0x100000
24+
0xefd 0xfb000000 0xefd 0xfb000000 0x10000000>;
25+
26+
liointc: interrupt-controller@3ff01400 {
27+
compatible = "loongson,liointc-1.0";
28+
reg = <0 0x3ff01400 0x64>;
29+
30+
interrupt-controller;
31+
#interrupt-cells = <2>;
32+
33+
interrupt-parent = <&cpuintc>;
34+
interrupts = <2>, <3>;
35+
interrupt-names = "int0", "int1";
36+
37+
loongson,parent_int_map = <0x00000001>, /* int0 */
38+
<0xfffffffe>, /* int1 */
39+
<0x00000000>, /* int2 */
40+
<0x00000000>; /* int3 */
41+
42+
};
43+
44+
cpu_uart0: serial@1fe001e0 {
45+
compatible = "ns16550a";
46+
reg = <0 0x1fe001e0 0x8>;
47+
clock-frequency = <33000000>;
48+
interrupt-parent = <&liointc>;
49+
interrupts = <0 IRQ_TYPE_LEVEL_HIGH>;
50+
no-loopback-test;
51+
};
52+
};
53+
54+
bus@10000000 {
55+
compatible = "simple-bus";
56+
#address-cells = <2>;
57+
#size-cells = <2>;
58+
ranges = <0 0x10000000 0 0x10000000 0 0x10000000 /* PIO & CONF & APB */
59+
0 0x40000000 0 0x40000000 0 0x40000000>; /* PCI MEM */
60+
61+
rtc0: rtc@10081000 {
62+
compatible = "google,goldfish-rtc";
63+
reg = <0 0x10081000 0 0x1000>;
64+
interrupts = <1 IRQ_TYPE_LEVEL_HIGH>;
65+
interrupt-parent = <&liointc>;
66+
};
67+
68+
pci@1a000000 {
69+
compatible = "pci-host-ecam-generic";
70+
device_type = "pci";
71+
#address-cells = <3>;
72+
#size-cells = <2>;
73+
#interrupt-cells = <1>;
74+
75+
bus-range = <0x0 0x1f>;
76+
reg = <0 0x1a000000 0 0x02000000>;
77+
78+
ranges = <0x01000000 0x0 0x00004000 0x0 0x18004000 0x0 0x0000c000>,
79+
<0x02000000 0x0 0x40000000 0x0 0x40000000 0x0 0x40000000>;
80+
81+
interrupt-map = <
82+
0x0000 0x0 0x0 0x1 &liointc 0x2 IRQ_TYPE_LEVEL_HIGH
83+
0x0800 0x0 0x0 0x1 &liointc 0x3 IRQ_TYPE_LEVEL_HIGH
84+
0x1000 0x0 0x0 0x1 &liointc 0x4 IRQ_TYPE_LEVEL_HIGH
85+
0x1800 0x0 0x0 0x1 &liointc 0x5 IRQ_TYPE_LEVEL_HIGH
86+
>;
87+
88+
interrupt-map-mask = <0x1800 0x0 0x0 0x7>;
89+
};
90+
91+
isa {
92+
compatible = "isa";
93+
#address-cells = <2>;
94+
#size-cells = <1>;
95+
ranges = <1 0 0 0x18000000 0x4000>;
96+
};
97+
};
98+
99+
hypervisor {
100+
compatible = "linux,kvm";
101+
};
102+
};

arch/mips/include/asm/mach-loongson64/boot_param.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ struct boot_params {
194194

195195
enum loongson_bridge_type {
196196
LS7A = 1,
197-
RS780E = 2
197+
RS780E = 2,
198+
VIRTUAL = 3
198199
};
199200

200201
struct loongson_system_configuration {
@@ -230,5 +231,6 @@ extern struct loongson_system_configuration loongson_sysconf;
230231
extern u32 node_id_offset;
231232
extern void ls7a_early_config(void);
232233
extern void rs780e_early_config(void);
234+
extern void virtual_early_config(void);
233235

234236
#endif

arch/mips/include/asm/mach-loongson64/builtin_dtbs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ extern u32 __dtb_loongson64c_4core_ls7a_begin[];
1212
extern u32 __dtb_loongson64c_4core_rs780e_begin[];
1313
extern u32 __dtb_loongson64c_8core_rs780e_begin[];
1414
extern u32 __dtb_loongson64g_4core_ls7a_begin[];
15+
extern u32 __dtb_loongson64v_4core_virtio_begin[];
1516
#endif

arch/mips/loongson64/env.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,24 @@ void __init prom_init_env(void)
167167
vendor = id & 0xffff;
168168
device = (id >> 16) & 0xffff;
169169

170-
if (vendor == PCI_VENDOR_ID_LOONGSON && device == 0x7a00) {
170+
switch (vendor) {
171+
case PCI_VENDOR_ID_LOONGSON:
171172
pr_info("The bridge chip is LS7A\n");
172173
loongson_sysconf.bridgetype = LS7A;
173174
loongson_sysconf.early_config = ls7a_early_config;
174-
} else {
175+
break;
176+
case PCI_VENDOR_ID_AMD:
177+
case PCI_VENDOR_ID_ATI:
175178
pr_info("The bridge chip is RS780E or SR5690\n");
176179
loongson_sysconf.bridgetype = RS780E;
177180
loongson_sysconf.early_config = rs780e_early_config;
181+
break;
182+
default:
183+
pr_info("The bridge chip is VIRTUAL\n");
184+
loongson_sysconf.bridgetype = VIRTUAL;
185+
loongson_sysconf.early_config = virtual_early_config;
186+
loongson_fdt_blob = __dtb_loongson64v_4core_virtio_begin;
187+
break;
178188
}
179189

180190
if ((read_c0_prid() & PRID_IMP_MASK) == PRID_IMP_LOONGSON_64C) {

arch/mips/loongson64/init.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ void rs780e_early_config(void)
4242
node_id_offset = 37;
4343
}
4444

45+
void virtual_early_config(void)
46+
{
47+
node_id_offset = 44;
48+
}
49+
4550
void __init prom_init(void)
4651
{
4752
fw_init_cmdline();

0 commit comments

Comments
 (0)