All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiaojuan Yang <yangxiaojuan@loongson.cn>
To: qemu-devel@nongnu.org
Cc: mark.cave-ayland@ilande.co.uk, richard.henderson@linaro.org,
	gaosong@loongson.cn
Subject: [PATCH v1 38/43] hw/loongarch: Add some devices support for 3A5000.
Date: Fri, 15 Apr 2022 17:40:53 +0800	[thread overview]
Message-ID: <20220415094058.3584233-39-yangxiaojuan@loongson.cn> (raw)
In-Reply-To: <20220415094058.3584233-1-yangxiaojuan@loongson.cn>

1.Add uart,virtio-net,vga and usb for 3A5000.
2.Add irq set and map for the pci host. Non pci device
use irq 0-16, pci device use 16-64.
3.Add some unimplented device to emulate guest unused
memory space.

Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 hw/loongarch/Kconfig       |  7 ++++
 hw/loongarch/loongson3.c   | 77 ++++++++++++++++++++++++++++++++++++++
 include/hw/pci-host/ls7a.h |  8 ++++
 3 files changed, 92 insertions(+)

diff --git a/hw/loongarch/Kconfig b/hw/loongarch/Kconfig
index f779087416..8552ff4bee 100644
--- a/hw/loongarch/Kconfig
+++ b/hw/loongarch/Kconfig
@@ -2,6 +2,13 @@ config LOONGARCH_VIRT
     bool
     select PCI
     select PCI_EXPRESS_GENERIC_BRIDGE
+    imply VGA_PCI
+    imply VIRTIO_VGA
+    imply PCI_DEVICES
+    select ISA_BUS
+    select SERIAL
+    select SERIAL_ISA
+    select VIRTIO_PCI
     select LOONGARCH_IPI
     select LOONGARCH_PCH_PIC
     select LOONGARCH_PCH_MSI
diff --git a/hw/loongarch/loongson3.c b/hw/loongarch/loongson3.c
index 16f0d9e7df..057208811c 100644
--- a/hw/loongarch/loongson3.c
+++ b/hw/loongarch/loongson3.c
@@ -10,20 +10,95 @@
 #include "qemu/datadir.h"
 #include "qapi/error.h"
 #include "hw/boards.h"
+#include "hw/char/serial.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/qtest.h"
 #include "sysemu/runstate.h"
 #include "sysemu/reset.h"
 #include "sysemu/rtc.h"
+#include "hw/irq.h"
+#include "net/net.h"
 #include "hw/loongarch/loongarch.h"
 #include "hw/intc/loongarch_ipi.h"
 #include "hw/intc/loongarch_extioi.h"
 #include "hw/intc/loongarch_pch_pic.h"
 #include "hw/intc/loongarch_pch_msi.h"
 #include "hw/pci-host/ls7a.h"
+#include "hw/pci-host/gpex.h"
+#include "hw/misc/unimp.h"
 
 #include "target/loongarch/cpu.h"
 
+static void loongarch_devices_init(DeviceState *pch_pic)
+{
+    DeviceState *gpex_dev;
+    SysBusDevice *d;
+    PCIBus *pci_bus;
+    MemoryRegion *ecam_alias, *ecam_reg, *pio_alias, *pio_reg;
+    MemoryRegion *mmio_alias, *mmio_reg;
+    int i;
+
+    gpex_dev = qdev_new(TYPE_GPEX_HOST);
+    d = SYS_BUS_DEVICE(gpex_dev);
+    sysbus_realize_and_unref(d, &error_fatal);
+    pci_bus = PCI_HOST_BRIDGE(gpex_dev)->bus;
+
+    /* Map only part size_ecam bytes of ECAM space */
+    ecam_alias = g_new0(MemoryRegion, 1);
+    ecam_reg = sysbus_mmio_get_region(d, 0);
+    memory_region_init_alias(ecam_alias, OBJECT(gpex_dev), "pcie-ecam",
+                             ecam_reg, 0, LS_PCIECFG_SIZE);
+    memory_region_add_subregion(get_system_memory(), LS_PCIECFG_BASE,
+                                ecam_alias);
+
+    /* Map PCI mem space */
+    mmio_alias = g_new0(MemoryRegion, 1);
+    mmio_reg = sysbus_mmio_get_region(d, 1);
+    memory_region_init_alias(mmio_alias, OBJECT(gpex_dev), "pcie-mmio",
+                             mmio_reg, LS7A_PCI_MEM_BASE, LS7A_PCI_MEM_SIZE);
+    memory_region_add_subregion(get_system_memory(), LS7A_PCI_MEM_BASE,
+                                mmio_alias);
+
+    /* Map PCI IO port space. */
+    pio_alias = g_new0(MemoryRegion, 1);
+    pio_reg = sysbus_mmio_get_region(d, 2);
+    memory_region_init_alias(pio_alias, OBJECT(gpex_dev), "pcie-io", pio_reg,
+                             LS7A_PCI_IO_OFFSET, LS7A_PCI_IO_SIZE);
+    memory_region_add_subregion(get_system_memory(), LS7A_PCI_IO_BASE,
+                                pio_alias);
+
+    for (i = 0; i < GPEX_NUM_IRQS; i++) {
+        sysbus_connect_irq(d, i,
+                           qdev_get_gpio_in(pch_pic, 16 + i));
+        gpex_set_irq_num(GPEX_HOST(gpex_dev), i, 16 + i);
+    }
+
+    serial_mm_init(get_system_memory(), LS7A_UART_BASE, 0,
+                   qdev_get_gpio_in(pch_pic,
+                                    LS7A_UART_IRQ - PCH_PIC_IRQ_OFFSET),
+                   115200, serial_hd(0), DEVICE_LITTLE_ENDIAN);
+
+    /* Network init */
+    for (i = 0; i < nb_nics; i++) {
+        NICInfo *nd = &nd_table[i];
+
+        if (!nd->model) {
+            nd->model = g_strdup("virtio");
+        }
+
+        pci_nic_init_nofail(nd, pci_bus, nd->model, NULL);
+    }
+
+    /* VGA setup */
+    pci_vga_init(pci_bus);
+
+    /*
+     * There are some invalid guest memory access.
+     * Create some unimplemented devices to emulate this.
+     */
+    create_unimplemented_device("pci-dma-cfg", 0x1001041c, 0x4);
+}
+
 static void loongarch_irq_init(LoongArchMachineState *lams)
 {
     MachineState *ms = MACHINE(lams);
@@ -121,6 +196,8 @@ static void loongarch_irq_init(LoongArchMachineState *lams)
         sysbus_connect_irq(d, i,
                            qdev_get_gpio_in(extioi, i + PCH_MSI_IRQ_START));
     }
+
+    loongarch_devices_init(pch_pic);
 }
 
 static void loongarch_init(MachineState *machine)
diff --git a/include/hw/pci-host/ls7a.h b/include/hw/pci-host/ls7a.h
index bf80e99ce1..f57417b096 100644
--- a/include/hw/pci-host/ls7a.h
+++ b/include/hw/pci-host/ls7a.h
@@ -15,6 +15,12 @@
 #include "qemu/range.h"
 #include "qom/object.h"
 
+#define LS7A_PCI_IO_OFFSET      0x4000
+#define LS_PCIECFG_BASE         0x20000000
+#define LS_PCIECFG_SIZE         0x08000000
+#define LS7A_PCI_IO_BASE        0x18004000UL
+#define LS7A_PCI_IO_SIZE        0xC000
+
 #define LS7A_PCH_REG_BASE       0x10000000UL
 #define LS7A_IOAPIC_REG_BASE    (LS7A_PCH_REG_BASE)
 #define LS7A_PCH_MSI_ADDR_LOW   0x2FF00000UL
@@ -27,4 +33,6 @@
 #define PCH_PIC_IRQ_OFFSET      64
 #define LS7A_DEVICE_IRQS        16
 #define LS7A_PCI_IRQS           48
+#define LS7A_UART_IRQ           (PCH_PIC_IRQ_OFFSET + 2)
+#define LS7A_UART_BASE          0x1fe001e0
 #endif
-- 
2.31.1



  parent reply	other threads:[~2022-04-15 10:22 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15  9:40 [PATCH v1 00/43] Add LoongArch softmmu support Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 01/43] target/loongarch: Add README Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 02/43] target/loongarch: Add core definition Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 03/43] target/loongarch: Add main translation routines Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 04/43] target/loongarch: Add fixed point arithmetic instruction translation Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 05/43] target/loongarch: Add fixed point shift " Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 06/43] target/loongarch: Add fixed point bit " Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 07/43] target/loongarch: Add fixed point load/store " Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 08/43] target/loongarch: Add fixed point atomic " Xiaojuan Yang
2022-04-15 22:46   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 09/43] target/loongarch: Add fixed point extra " Xiaojuan Yang
2022-04-15 22:56   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 10/43] target/loongarch: Add floating point arithmetic " Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 11/43] target/loongarch: Add floating point comparison " Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 12/43] target/loongarch: Add floating point conversion " Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 13/43] target/loongarch: Add floating point move " Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 14/43] target/loongarch: Add floating point load/store " Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 15/43] target/loongarch: Add branch " Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 16/43] target/loongarch: Add disassembler Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 17/43] target/loongarch: Add target build suport Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 18/43] target/loongarch: Add system emulation introduction Xiaojuan Yang
2022-04-15 23:25   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 19/43] target/loongarch: Add CSRs definition Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 20/43] target/loongarch: Add basic vmstate description of CPU Xiaojuan Yang
2022-04-15 23:29   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 21/43] target/loongarch: Implement qmp_query_cpu_definitions() Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 22/43] target/loongarch: Add MMU support for LoongArch CPU Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 23/43] target/loongarch: Add LoongArch interrupt and exception handle Xiaojuan Yang
2022-04-16  0:13   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 24/43] target/loongarch: Add constant timer support Xiaojuan Yang
2022-04-16  0:17   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 25/43] target/loongarch: Add LoongArch CSR instruction Xiaojuan Yang
2022-04-16  1:04   ` Richard Henderson
2022-04-18 12:38     ` yangxiaojuan
2022-04-18 14:34       ` Richard Henderson
2022-04-19  7:33     ` yangxiaojuan
2022-04-19 17:05       ` Richard Henderson
2022-04-21  9:15         ` yangxiaojuan
2022-04-21 15:59           ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 26/43] target/loongarch: Add LoongArch IOCSR instruction Xiaojuan Yang
2022-04-16  2:26   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 27/43] target/loongarch: Add TLB instruction support Xiaojuan Yang
2022-04-16  3:38   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 28/43] target/loongarch: Add other core instructions support Xiaojuan Yang
2022-04-16  3:49   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 29/43] target/loongarch: Add timer related " Xiaojuan Yang
2022-04-17 18:48   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 30/43] target/loongarch: Add gdb support Xiaojuan Yang
2022-04-17 19:02   ` Richard Henderson
2022-04-17 19:08   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 31/43] hw/loongarch: Add support loongson3 virt machine type Xiaojuan Yang
2022-04-17 22:28   ` Richard Henderson
2022-04-17 22:55   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 32/43] hw/loongarch: Add LoongArch ipi interrupt support(IPI) Xiaojuan Yang
2022-04-18  0:24   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 33/43] hw/intc: Add LoongArch ls7a interrupt controller support(PCH-PIC) Xiaojuan Yang
2022-04-18  3:15   ` Richard Henderson
2022-04-18  9:14     ` yangxiaojuan
2022-04-18 14:39       ` Richard Henderson
2022-04-19  7:27         ` yangxiaojuan
2022-04-19 17:14           ` Richard Henderson
2022-04-21  3:10             ` yangxiaojuan
2022-04-15  9:40 ` [PATCH v1 34/43] hw/intc: Add LoongArch ls7a msi interrupt controller support(PCH-MSI) Xiaojuan Yang
2022-04-18  3:39   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 35/43] hw/intc: Add LoongArch extioi interrupt controller(EIOINTC) Xiaojuan Yang
2022-04-18  3:48   ` Richard Henderson
2022-04-18  8:57     ` Mark Cave-Ayland
2022-04-19  1:50       ` yangxiaojuan
2022-04-19 11:10         ` Mark Cave-Ayland
2022-04-15  9:40 ` [PATCH v1 36/43] hw/loongarch: Add irq hierarchy for the system Xiaojuan Yang
2022-04-18 14:44   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 37/43] Enable common virtio pci support for LoongArch Xiaojuan Yang
2022-04-15  9:40 ` Xiaojuan Yang [this message]
2022-04-15  9:40 ` [PATCH v1 39/43] hw/loongarch: Add LoongArch ls7a rtc device support Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 40/43] hw/loongarch: Add LoongArch boot code and load elf function Xiaojuan Yang
2022-04-18 15:11   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 41/43] hw/loongarch: Add LoongArch ls7a acpi device support Xiaojuan Yang
2022-04-15  9:40 ` [PATCH v1 42/43] tests/tcg/loongarch64: Add hello/memory test in loongarch64 system Xiaojuan Yang
2022-04-18 15:25   ` Richard Henderson
2022-04-15  9:40 ` [PATCH v1 43/43] target/loongarch: 'make check-tcg' support Xiaojuan Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220415094058.3584233-39-yangxiaojuan@loongson.cn \
    --to=yangxiaojuan@loongson.cn \
    --cc=gaosong@loongson.cn \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.