From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: gaosong@loongson.cn, jiaxun.yang@flygoat.com,
qemu-devel@nongnu.org, thomas@t-8ch.de, xry111@xry111.site,
maobibo@loongson.cn
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH] hw/loongarch: virt: support up to 4 serial ports
Date: Fri, 6 Sep 2024 06:49:07 +0200 [thread overview]
Message-ID: <20240906044944.2427297-1-Jason@zx2c4.com> (raw)
In-Reply-To: <ZtqJuTTR0wdcVXdz@zx2c4.com>
In order to support additional channels of communication using
`-serial`, add several serial ports, up to the standard 4 generally
supported by the 8250 driver.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
hw/loongarch/virt.c | 24 ++++++++++++++----------
include/hw/pci-host/ls7a.h | 9 +++++----
2 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 4151fc5e0c..155678b684 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -319,10 +319,10 @@ static void fdt_add_ged_reset(LoongArchVirtMachineState *lvms)
}
static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
- uint32_t *pch_pic_phandle)
+ uint32_t *pch_pic_phandle, hwaddr base,
+ int irq, bool chosen)
{
char *nodename;
- hwaddr base = VIRT_UART_BASE;
hwaddr size = VIRT_UART_SIZE;
MachineState *ms = MACHINE(lvms);
@@ -331,9 +331,9 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", "ns16550a");
qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0x0, base, 0x0, size);
qemu_fdt_setprop_cell(ms->fdt, nodename, "clock-frequency", 100000000);
- qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", nodename);
- qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
- VIRT_UART_IRQ - VIRT_GSI_BASE, 0x4);
+ if (chosen)
+ qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", nodename);
+ qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts", irq, 0x4);
qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
*pch_pic_phandle);
g_free(nodename);
@@ -750,11 +750,15 @@ static void virt_devices_init(DeviceState *pch_pic,
/* Add pcie node */
fdt_add_pcie_node(lvms, pch_pic_phandle, pch_msi_phandle);
- serial_mm_init(get_system_memory(), VIRT_UART_BASE, 0,
- qdev_get_gpio_in(pch_pic,
- VIRT_UART_IRQ - VIRT_GSI_BASE),
- 115200, serial_hd(0), DEVICE_LITTLE_ENDIAN);
- fdt_add_uart_node(lvms, pch_pic_phandle);
+ for (i = 0; i < VIRT_UART_COUNT; ++i) {
+ hwaddr base = VIRT_UART_BASE + i * VIRT_UART_SIZE;
+ int irq = VIRT_UART_IRQ + i - VIRT_GSI_BASE;
+ serial_mm_init(get_system_memory(), base, 0,
+ qdev_get_gpio_in(pch_pic, irq),
+ 115200, serial_hd(VIRT_UART_COUNT - 1 - i),
+ DEVICE_LITTLE_ENDIAN);
+ fdt_add_uart_node(lvms, pch_pic_phandle, base, irq, i == 0);
+ }
/* Network init */
pci_init_nic_devices(pci_bus, mc->default_nic);
diff --git a/include/hw/pci-host/ls7a.h b/include/hw/pci-host/ls7a.h
index cd7c9ec7bc..79d4ea8501 100644
--- a/include/hw/pci-host/ls7a.h
+++ b/include/hw/pci-host/ls7a.h
@@ -36,17 +36,18 @@
#define VIRT_PCH_PIC_IRQ_NUM 32
#define VIRT_GSI_BASE 64
#define VIRT_DEVICE_IRQS 16
+#define VIRT_UART_COUNT 4
#define VIRT_UART_IRQ (VIRT_GSI_BASE + 2)
#define VIRT_UART_BASE 0x1fe001e0
-#define VIRT_UART_SIZE 0X100
-#define VIRT_RTC_IRQ (VIRT_GSI_BASE + 3)
+#define VIRT_UART_SIZE 0x100
+#define VIRT_RTC_IRQ (VIRT_GSI_BASE + 6)
#define VIRT_MISC_REG_BASE (VIRT_PCH_REG_BASE + 0x00080000)
#define VIRT_RTC_REG_BASE (VIRT_MISC_REG_BASE + 0x00050100)
#define VIRT_RTC_LEN 0x100
-#define VIRT_SCI_IRQ (VIRT_GSI_BASE + 4)
+#define VIRT_SCI_IRQ (VIRT_GSI_BASE + 7)
#define VIRT_PLATFORM_BUS_BASEADDRESS 0x16000000
#define VIRT_PLATFORM_BUS_SIZE 0x2000000
#define VIRT_PLATFORM_BUS_NUM_IRQS 2
-#define VIRT_PLATFORM_BUS_IRQ (VIRT_GSI_BASE + 5)
+#define VIRT_PLATFORM_BUS_IRQ (VIRT_GSI_BASE + 8)
#endif
--
2.46.0
next prev parent reply other threads:[~2024-09-06 4:50 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1738d60a-df3a-4102-b1da-d16a29b6e06a@t-8ch.de>
2023-10-10 1:12 ` qemu direct kernel boot on LoongArch maobibo
2024-09-05 3:12 ` Jason A. Donenfeld
2024-09-05 3:45 ` maobibo
2024-09-05 4:04 ` Jason A. Donenfeld
2024-09-05 5:25 ` Thomas Weißschuh
2024-09-05 6:11 ` maobibo
2024-09-05 14:54 ` Jason A. Donenfeld
2024-09-05 15:49 ` Jason A. Donenfeld
2024-09-06 1:09 ` maobibo
2024-09-05 14:53 ` Jason A. Donenfeld
2024-09-05 15:05 ` Thomas Weißschuh
2024-09-05 15:07 ` Jason A. Donenfeld
2024-09-05 15:16 ` Thomas Weißschuh
2024-09-05 15:18 ` Jason A. Donenfeld
2024-09-05 16:03 ` Thomas Weißschuh
2024-09-06 1:14 ` maobibo
2024-09-06 4:04 ` Jason A. Donenfeld
2024-09-06 4:48 ` Jason A. Donenfeld
2024-09-06 4:49 ` Jason A. Donenfeld [this message]
2024-09-06 8:34 ` [PATCH] hw/loongarch: virt: support up to 4 serial ports maobibo
2024-09-06 14:30 ` Jason A. Donenfeld
2024-09-06 14:31 ` [PATCH v2] " Jason A. Donenfeld
2024-09-07 3:37 ` maobibo
2024-09-07 14:44 ` Jason A. Donenfeld
2024-09-07 14:57 ` Jason A. Donenfeld
2024-09-07 14:34 ` [PATCH v3] " Jason A. Donenfeld
2024-09-09 1:22 ` maobibo
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=20240906044944.2427297-1-Jason@zx2c4.com \
--to=jason@zx2c4.com \
--cc=gaosong@loongson.cn \
--cc=jiaxun.yang@flygoat.com \
--cc=maobibo@loongson.cn \
--cc=qemu-devel@nongnu.org \
--cc=thomas@t-8ch.de \
--cc=xry111@xry111.site \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).