-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MIPS: KVM: Add kvm support for Loongson-3 (Guest Side)
Signed-off-by: Huacai Chen <chenhc@lemote.com>
- Loading branch information
1 parent
2af5398
commit f31b7c1
Showing
14 changed files
with
361 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
dtb-$(CONFIG_CPU_LOONGSON3) += loongson3_ls2h.dtb loongson3_ls7a.dtb loongson3_rs780.dtb | ||
dtb-$(CONFIG_CPU_LOONGSON3) += loongson3_ls2h.dtb loongson3_ls7a.dtb loongson3_rs780.dtb loongson3_virtual.dtb | ||
|
||
obj-y += $(patsubst %.dtb, %.dtb.o, $(dtb-y)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/dts-v1/; | ||
#include "loongson3.dtsi" | ||
/ { | ||
model = "loongson,generic"; | ||
compatible = "loongson,loongson3"; | ||
#address-cells = <2>; | ||
#size-cells = <2>; | ||
|
||
memory { | ||
name = "memory"; | ||
device_type = "memory"; | ||
}; | ||
|
||
cpuic: interrupt-controller { | ||
compatible = "mti,cpu-interrupt-controller"; | ||
interrupt-controller; | ||
#interrupt-cells = <1>; | ||
}; | ||
|
||
platic: interrupt-controller@3ff01400 { | ||
compatible = "loongson,liointc-1.0"; | ||
interrupt-controller; | ||
#interrupt-cells = <1>; | ||
interrupts = <3>; | ||
interrupt-parent = <&cpuic>; | ||
}; | ||
|
||
platform { | ||
compatible = "loongson,nbus", "simple-bus"; | ||
#address-cells = <1>; | ||
#size-cells = <1>; | ||
ranges = <0x00000000 0x0 0x00000000 0x20000000>; | ||
|
||
rtc0: rtc@10081000 { | ||
compatible = "google,goldfish-rtc"; | ||
reg = <0x10081000 0x1000>; | ||
interrupts = <17>; | ||
interrupt-parent = <&platic>; | ||
}; | ||
}; | ||
|
||
hypervisor { | ||
compatible = "linux,kvm"; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Copyright (C) 2020, Huacai Chen <chenhc@lemote.com> | ||
* Copyright (C) 2020, Jiaxun Yang <jiaxun.yang@flygoat.com> | ||
* Loongson Local IO Interrupt Controller support | ||
*/ | ||
|
||
#include <linux/interrupt.h> | ||
#include <linux/irqchip.h> | ||
#include <linux/module.h> | ||
#include <irq.h> | ||
#include <loongson.h> | ||
#include <loongson-pch.h> | ||
|
||
#define VIRT_LIOINTC_BASE NR_IRQS_LEGACY | ||
#define LOONGSON_INT_STATUS LOONGSON3_REG32(LOONGSON3_REG_BASE, LOONGSON_INT_ROUTER_OFFSET + 0x20) | ||
|
||
static DEFINE_RAW_SPINLOCK(pch_irq_lock); | ||
|
||
static void mask_pch_irq(struct irq_data *d) | ||
{ | ||
int irq_nr; | ||
|
||
raw_spin_lock(&pch_irq_lock); | ||
irq_nr = d->irq - VIRT_LIOINTC_BASE; | ||
LOONGSON_INT_ROUTER_INTENCLR = (1 << irq_nr); | ||
raw_spin_unlock(&pch_irq_lock); | ||
} | ||
|
||
static void unmask_pch_irq(struct irq_data *d) | ||
{ | ||
int irq_nr; | ||
|
||
raw_spin_lock(&pch_irq_lock); | ||
irq_nr = d->irq - VIRT_LIOINTC_BASE; | ||
LOONGSON_INT_ROUTER_INTENSET = (1 << irq_nr); | ||
raw_spin_unlock(&pch_irq_lock); | ||
} | ||
|
||
static struct irq_chip pch_irq_chip = { | ||
.name = "Loongson", | ||
.irq_mask = mask_pch_irq, | ||
.irq_unmask = unmask_pch_irq, | ||
.irq_set_affinity = plat_set_irq_affinity, | ||
.flags = IRQCHIP_MASK_ON_SUSPEND, | ||
}; | ||
|
||
void virtio_irq_dispatch(void) | ||
{ | ||
u32 pending; | ||
|
||
pending = LOONGSON_INT_STATUS; | ||
|
||
if (!pending) | ||
spurious_interrupt(); | ||
|
||
while (pending) { | ||
int irq = __ffs(pending); | ||
|
||
do_IRQ(VIRT_LIOINTC_BASE + irq); | ||
pending &= ~BIT(irq); | ||
} | ||
} | ||
|
||
static struct irqaction cascade_irqaction = { | ||
.handler = no_action, | ||
.flags = IRQF_NO_SUSPEND, | ||
.name = "cascade", | ||
}; | ||
|
||
void virtio_init_irq(void) | ||
{ | ||
int i; | ||
|
||
LOONGSON_INT_ROUTER_INTENCLR = 0xffffffff; | ||
|
||
/* Route UART int to cpu Core0 INT0 */ | ||
LOONGSON_INT_ROUTER_ENTRY(0) = | ||
LOONGSON_INT_COREx_INTy(loongson_sysconf.boot_cpu_id, 0); | ||
|
||
/* Route others to Core0 INT1 (IP3) */ | ||
for (i = 1; i < 32; i++) | ||
LOONGSON_INT_ROUTER_ENTRY(i) = | ||
LOONGSON_INT_COREx_INTy(loongson_sysconf.boot_cpu_id, 1); | ||
|
||
setup_irq(VIRT_LIOINTC_BASE, &cascade_irqaction); | ||
} | ||
|
||
int __init liointc_of_init(struct device_node *node, struct device_node *parent) | ||
{ | ||
int i = 0; | ||
|
||
irq_alloc_descs(-1, VIRT_LIOINTC_BASE, 32, 0); | ||
irq_domain_add_legacy(node, 32, VIRT_LIOINTC_BASE, | ||
VIRT_LIOINTC_BASE, &irq_domain_simple_ops, NULL); | ||
|
||
for (i = VIRT_LIOINTC_BASE; i < VIRT_LIOINTC_BASE + 32; i++) { | ||
irq_set_noprobe(i); | ||
irq_set_chip_and_handler(i, &pch_irq_chip, handle_level_irq); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
IRQCHIP_DECLARE(loongson_liointc_1_0, "loongson,liointc-1.0", liointc_of_init); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (C) 2013, Loongson Technology Corporation Limited, Inc. | ||
* | ||
* This program is free software; you can distribute it and/or modify it | ||
* under the terms of the GNU General Public License (Version 2) as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* for more details. | ||
* | ||
*/ | ||
#include <linux/init.h> | ||
#include <asm/io.h> | ||
#include <pci.h> | ||
#include <boot_param.h> | ||
#include <loongson-pch.h> | ||
|
||
#include <linux/i2c.h> | ||
#include <linux/serial_8250.h> | ||
#include <linux/platform_device.h> | ||
|
||
void pci_no_msi(void); | ||
|
||
static void virtio_early_config(void) | ||
{ | ||
pci_no_msi(); | ||
} | ||
|
||
static struct resource pci_mem_resource = { | ||
.name = "pci memory space", | ||
.flags = IORESOURCE_MEM, | ||
}; | ||
|
||
static struct resource pci_io_resource = { | ||
.name = "pci io space", | ||
.flags = IORESOURCE_IO, | ||
}; | ||
|
||
static struct pci_controller virtio_pci_controller = { | ||
.pci_ops = &virtio_pci_ops, | ||
.io_resource = &pci_io_resource, | ||
.mem_resource = &pci_mem_resource, | ||
.mem_offset = 0x00000000UL, | ||
.io_offset = 0x00000000UL, | ||
}; | ||
|
||
static void __init virtio_arch_initcall(void) | ||
{ | ||
pci_mem_resource.start = loongson_sysconf.pci_mem_start_addr; | ||
pci_mem_resource.end = loongson_sysconf.pci_mem_end_addr; | ||
pci_io_resource.start = LOONGSON_PCI_IO_START; | ||
pci_io_resource.end = 0x3ffff; | ||
ioport_resource.end = 0xfffff; | ||
virtio_pci_controller.io_map_base = mips_io_port_base; | ||
register_pci_controller(&virtio_pci_controller); | ||
} | ||
|
||
static void __init virtio_device_initcall(void) | ||
{ | ||
} | ||
|
||
struct platform_controller_hub virtual_pch = { | ||
.type = VIRTUAL, | ||
.pcidev_max_funcs = 7, | ||
.early_config = virtio_early_config, | ||
.init_irq = virtio_init_irq, | ||
.irq_dispatch = virtio_irq_dispatch, | ||
.pch_arch_initcall = virtio_arch_initcall, | ||
.pch_device_initcall = virtio_device_initcall, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.