1 | The following changes since commit fd87be1dada5672f877e03c2ca8504458292c479: | 1 | The following changes since commit a5ba0a7e4e150d1350a041f0d0ef9ca6c8d7c307: |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'accel-20240426' of https://github.com/philmd/qemu into staging (2024-04-26 15:28:13 -0700) | 3 | Merge tag 'pull-aspeed-20241211' of https://github.com/legoater/qemu into staging (2024-12-11 15:16:47 +0000) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.com/gaosong/qemu.git tags/pull-loongarch-20240428 | 7 | https://gitlab.com/bibo-mao/qemu.git pull-loongarch-20241213 |
8 | 8 | ||
9 | for you to fetch changes up to f3c05d222dc9ed3cd10383302ce51ab6cee06a97: | 9 | for you to fetch changes up to 78aa256571aa06f32001bd80635a1858187c609b: |
10 | 10 | ||
11 | hw/loongarch: Add cells missing from rtc node (2024-04-28 16:56:05 +0800) | 11 | hw/intc/loongarch_pch: Code cleanup about loongarch_pch_pic (2024-12-13 14:39:39 +0800) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Add boot LoongArch elf kernel with FDT | 14 | pull-loongarch-20241213 |
15 | 15 | ||
16 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
17 | Song Gao (17): | 17 | Bibo Mao (8): |
18 | hw/loongarch: Move boot functions to boot.c | 18 | include: Add loongarch_pic_common header file |
19 | hw/loongarch: Add load initrd | 19 | include: Move struct LoongArchPCHPIC to loongarch_pic_common header file |
20 | hw/loongarch: Add slave cpu boot_code | 20 | hw/intc/loongarch_pch: Merge instance_init() into realize() |
21 | hw/loongarch: Add init_cmdline | 21 | hw/intc/loongarch_pch: Rename LoongArchPCHPIC with LoongArchPICCommonState |
22 | hw/loongarch: Init efi_system_table | 22 | hw/intc/loongarch_pch: Move some functions to file loongarch_pic_common |
23 | hw/loongarch: Init efi_boot_memmap table | 23 | hw/intc/loongarch_pch: Inherit from loongarch_pic_common |
24 | hw/loongarch: Init efi_initrd table | 24 | hw/intc/loongarch_pch: Add pre_save and post_load interfaces |
25 | hw/loongarch: Init efi_fdt table | 25 | hw/intc/loongarch_pch: Code cleanup about loongarch_pch_pic |
26 | hw/loongarch: Fix fdt memory node wrong 'reg' | ||
27 | hw/loongarch: fdt adds cpu interrupt controller node | ||
28 | hw/loongarch: fdt adds Extend I/O Interrupt Controller | ||
29 | hw/loongarch: fdt adds pch_pic Controller | ||
30 | hw/loongarch: fdt adds pch_msi Controller | ||
31 | hw/loongarch: fdt adds pcie irq_map node | ||
32 | hw/loongarch: fdt remove unused irqchip node | ||
33 | hw/loongarch: Add cells missing from uart node | ||
34 | hw/loongarch: Add cells missing from rtc node | ||
35 | 26 | ||
36 | hw/loongarch/boot.c | 337 ++++++++++++++++++++++++++++++++++ | 27 | hw/intc/loongarch_pch_pic.c | 106 +++++++++++---------------------- |
37 | hw/loongarch/meson.build | 1 + | 28 | hw/intc/loongarch_pic_common.c | 97 ++++++++++++++++++++++++++++++ |
38 | hw/loongarch/virt.c | 365 +++++++++++++++++++++---------------- | 29 | hw/intc/meson.build | 2 +- |
39 | include/hw/intc/loongarch_extioi.h | 1 + | 30 | hw/loongarch/virt.c | 2 +- |
40 | include/hw/loongarch/boot.h | 109 +++++++++++ | 31 | include/hw/intc/loongarch_pch_pic.h | 70 +++++----------------- |
41 | include/hw/loongarch/virt.h | 16 ++ | 32 | include/hw/intc/loongarch_pic_common.h | 82 +++++++++++++++++++++++++ |
42 | include/hw/pci-host/ls7a.h | 2 + | 33 | 6 files changed, 230 insertions(+), 129 deletions(-) |
43 | target/loongarch/cpu.h | 2 + | 34 | create mode 100644 hw/intc/loongarch_pic_common.c |
44 | 8 files changed, 671 insertions(+), 162 deletions(-) | 35 | create mode 100644 include/hw/intc/loongarch_pic_common.h |
45 | create mode 100644 hw/loongarch/boot.c | ||
46 | create mode 100644 include/hw/loongarch/boot.h | diff view generated by jsdifflib |
1 | rtc node need interrupts and interrupt-parent cells. | 1 | Add common header file hw/intc/loongarch_pic_common.h, and move |
---|---|---|---|
2 | some macro definition from hw/intc/loongarch_pch_pic.h to the common | ||
3 | header file. | ||
2 | 4 | ||
3 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | Message-Id: <20240426091551.2397867-18-gaosong@loongson.cn> | ||
6 | --- | 7 | --- |
7 | hw/loongarch/virt.c | 12 +++++++++--- | 8 | include/hw/intc/loongarch_pch_pic.h | 36 +++------------------- |
8 | 1 file changed, 9 insertions(+), 3 deletions(-) | 9 | include/hw/intc/loongarch_pic_common.h | 42 ++++++++++++++++++++++++++ |
10 | 2 files changed, 47 insertions(+), 31 deletions(-) | ||
11 | create mode 100644 include/hw/intc/loongarch_pic_common.h | ||
9 | 12 | ||
10 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 13 | diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h |
11 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/hw/loongarch/virt.c | 15 | --- a/include/hw/intc/loongarch_pch_pic.h |
13 | +++ b/hw/loongarch/virt.c | 16 | +++ b/include/hw/intc/loongarch_pch_pic.h |
14 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_flash_node(LoongArchMachineState *lams) | 17 | @@ -XXX,XX +XXX,XX @@ |
15 | g_free(nodename); | 18 | * Copyright (c) 2021 Loongson Technology Corporation Limited |
16 | } | 19 | */ |
17 | 20 | ||
18 | -static void fdt_add_rtc_node(LoongArchMachineState *lams) | 21 | -#include "hw/sysbus.h" |
19 | +static void fdt_add_rtc_node(LoongArchMachineState *lams, | 22 | +#ifndef HW_LOONGARCH_PCH_PIC_H |
20 | + uint32_t *pch_pic_phandle) | 23 | +#define HW_LOONGARCH_PCH_PIC_H |
21 | { | 24 | + |
22 | char *nodename; | 25 | +#include "hw/intc/loongarch_pic_common.h" |
23 | hwaddr base = VIRT_RTC_REG_BASE; | 26 | |
24 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_rtc_node(LoongArchMachineState *lams) | 27 | #define TYPE_LOONGARCH_PCH_PIC "loongarch_pch_pic" |
25 | 28 | #define PCH_PIC_NAME(name) TYPE_LOONGARCH_PCH_PIC#name | |
26 | nodename = g_strdup_printf("/rtc@%" PRIx64, base); | 29 | OBJECT_DECLARE_SIMPLE_TYPE(LoongArchPCHPIC, LOONGARCH_PCH_PIC) |
27 | qemu_fdt_add_subnode(ms->fdt, nodename); | 30 | |
28 | - qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", "loongson,ls7a-rtc"); | 31 | -#define PCH_PIC_INT_ID_VAL 0x7000000UL |
29 | + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", | 32 | -#define PCH_PIC_INT_ID_VER 0x1UL |
30 | + "loongson,ls7a-rtc"); | 33 | - |
31 | qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size); | 34 | -#define PCH_PIC_INT_ID_LO 0x00 |
32 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts", | 35 | -#define PCH_PIC_INT_ID_HI 0x04 |
33 | + VIRT_RTC_IRQ - VIRT_GSI_BASE , 0x4); | 36 | -#define PCH_PIC_INT_MASK_LO 0x20 |
34 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent", | 37 | -#define PCH_PIC_INT_MASK_HI 0x24 |
35 | + *pch_pic_phandle); | 38 | -#define PCH_PIC_HTMSI_EN_LO 0x40 |
36 | g_free(nodename); | 39 | -#define PCH_PIC_HTMSI_EN_HI 0x44 |
37 | } | 40 | -#define PCH_PIC_INT_EDGE_LO 0x60 |
38 | 41 | -#define PCH_PIC_INT_EDGE_HI 0x64 | |
39 | @@ -XXX,XX +XXX,XX @@ static void loongarch_devices_init(DeviceState *pch_pic, | 42 | -#define PCH_PIC_INT_CLEAR_LO 0x80 |
40 | sysbus_create_simple("ls7a_rtc", VIRT_RTC_REG_BASE, | 43 | -#define PCH_PIC_INT_CLEAR_HI 0x84 |
41 | qdev_get_gpio_in(pch_pic, | 44 | -#define PCH_PIC_AUTO_CTRL0_LO 0xc0 |
42 | VIRT_RTC_IRQ - VIRT_GSI_BASE)); | 45 | -#define PCH_PIC_AUTO_CTRL0_HI 0xc4 |
43 | - fdt_add_rtc_node(lams); | 46 | -#define PCH_PIC_AUTO_CTRL1_LO 0xe0 |
44 | + fdt_add_rtc_node(lams, pch_pic_phandle); | 47 | -#define PCH_PIC_AUTO_CTRL1_HI 0xe4 |
45 | 48 | -#define PCH_PIC_ROUTE_ENTRY_OFFSET 0x100 | |
46 | /* acpi ged */ | 49 | -#define PCH_PIC_ROUTE_ENTRY_END 0x13f |
47 | lams->acpi_ged = create_acpi_ged(pch_pic, lams); | 50 | -#define PCH_PIC_HTMSI_VEC_OFFSET 0x200 |
51 | -#define PCH_PIC_HTMSI_VEC_END 0x23f | ||
52 | -#define PCH_PIC_INT_STATUS_LO 0x3a0 | ||
53 | -#define PCH_PIC_INT_STATUS_HI 0x3a4 | ||
54 | -#define PCH_PIC_INT_POL_LO 0x3e0 | ||
55 | -#define PCH_PIC_INT_POL_HI 0x3e4 | ||
56 | - | ||
57 | -#define STATUS_LO_START 0 | ||
58 | -#define STATUS_HI_START 0x4 | ||
59 | -#define POL_LO_START 0x40 | ||
60 | -#define POL_HI_START 0x44 | ||
61 | struct LoongArchPCHPIC { | ||
62 | SysBusDevice parent_obj; | ||
63 | qemu_irq parent_irq[64]; | ||
64 | @@ -XXX,XX +XXX,XX @@ struct LoongArchPCHPIC { | ||
65 | MemoryRegion iomem8; | ||
66 | unsigned int irq_num; | ||
67 | }; | ||
68 | +#endif /* HW_LOONGARCH_PCH_PIC_H */ | ||
69 | diff --git a/include/hw/intc/loongarch_pic_common.h b/include/hw/intc/loongarch_pic_common.h | ||
70 | new file mode 100644 | ||
71 | index XXXXXXX..XXXXXXX | ||
72 | --- /dev/null | ||
73 | +++ b/include/hw/intc/loongarch_pic_common.h | ||
74 | @@ -XXX,XX +XXX,XX @@ | ||
75 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
76 | +/* | ||
77 | + * LoongArch 7A1000 I/O interrupt controller definitions | ||
78 | + * Copyright (c) 2024 Loongson Technology Corporation Limited | ||
79 | + */ | ||
80 | + | ||
81 | +#ifndef HW_LOONGARCH_PIC_COMMON_H | ||
82 | +#define HW_LOONGARCH_PIC_COMMON_H | ||
83 | + | ||
84 | +#include "hw/pci-host/ls7a.h" | ||
85 | +#include "hw/sysbus.h" | ||
86 | + | ||
87 | +#define PCH_PIC_INT_ID_VAL 0x7000000UL | ||
88 | +#define PCH_PIC_INT_ID_VER 0x1UL | ||
89 | +#define PCH_PIC_INT_ID_LO 0x00 | ||
90 | +#define PCH_PIC_INT_ID_HI 0x04 | ||
91 | +#define PCH_PIC_INT_MASK_LO 0x20 | ||
92 | +#define PCH_PIC_INT_MASK_HI 0x24 | ||
93 | +#define PCH_PIC_HTMSI_EN_LO 0x40 | ||
94 | +#define PCH_PIC_HTMSI_EN_HI 0x44 | ||
95 | +#define PCH_PIC_INT_EDGE_LO 0x60 | ||
96 | +#define PCH_PIC_INT_EDGE_HI 0x64 | ||
97 | +#define PCH_PIC_INT_CLEAR_LO 0x80 | ||
98 | +#define PCH_PIC_INT_CLEAR_HI 0x84 | ||
99 | +#define PCH_PIC_AUTO_CTRL0_LO 0xc0 | ||
100 | +#define PCH_PIC_AUTO_CTRL0_HI 0xc4 | ||
101 | +#define PCH_PIC_AUTO_CTRL1_LO 0xe0 | ||
102 | +#define PCH_PIC_AUTO_CTRL1_HI 0xe4 | ||
103 | +#define PCH_PIC_ROUTE_ENTRY_OFFSET 0x100 | ||
104 | +#define PCH_PIC_ROUTE_ENTRY_END 0x13f | ||
105 | +#define PCH_PIC_HTMSI_VEC_OFFSET 0x200 | ||
106 | +#define PCH_PIC_HTMSI_VEC_END 0x23f | ||
107 | +#define PCH_PIC_INT_STATUS_LO 0x3a0 | ||
108 | +#define PCH_PIC_INT_STATUS_HI 0x3a4 | ||
109 | +#define PCH_PIC_INT_POL_LO 0x3e0 | ||
110 | +#define PCH_PIC_INT_POL_HI 0x3e4 | ||
111 | + | ||
112 | +#define STATUS_LO_START 0 | ||
113 | +#define STATUS_HI_START 0x4 | ||
114 | +#define POL_LO_START 0x40 | ||
115 | +#define POL_HI_START 0x44 | ||
116 | +#endif /* HW_LOONGARCH_PIC_COMMON_H */ | ||
48 | -- | 117 | -- |
49 | 2.25.1 | 118 | 2.43.5 | diff view generated by jsdifflib |
1 | uart node need interrupts and interrupt-parent cells. | 1 | Move structure LoongArchPCHPIC from header file loongarch_pch_pic.h |
---|---|---|---|
2 | to file loongarch_pic_common.h, and rename structure name with | ||
3 | LoongArchPICCommonState. | ||
2 | 4 | ||
3 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | Message-Id: <20240426091551.2397867-17-gaosong@loongson.cn> | ||
6 | --- | 7 | --- |
7 | hw/loongarch/virt.c | 9 +++++++-- | 8 | include/hw/intc/loongarch_pch_pic.h | 27 +------------------------ |
8 | 1 file changed, 7 insertions(+), 2 deletions(-) | 9 | include/hw/intc/loongarch_pic_common.h | 28 ++++++++++++++++++++++++++ |
10 | 2 files changed, 29 insertions(+), 26 deletions(-) | ||
9 | 11 | ||
10 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 12 | diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h |
11 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/hw/loongarch/virt.c | 14 | --- a/include/hw/intc/loongarch_pch_pic.h |
13 | +++ b/hw/loongarch/virt.c | 15 | +++ b/include/hw/intc/loongarch_pch_pic.h |
14 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_rtc_node(LoongArchMachineState *lams) | 16 | @@ -XXX,XX +XXX,XX @@ |
15 | g_free(nodename); | 17 | |
16 | } | 18 | #include "hw/intc/loongarch_pic_common.h" |
17 | 19 | ||
18 | -static void fdt_add_uart_node(LoongArchMachineState *lams) | 20 | +#define LoongArchPCHPIC LoongArchPICCommonState |
19 | +static void fdt_add_uart_node(LoongArchMachineState *lams, | 21 | #define TYPE_LOONGARCH_PCH_PIC "loongarch_pch_pic" |
20 | + uint32_t *pch_pic_phandle) | 22 | #define PCH_PIC_NAME(name) TYPE_LOONGARCH_PCH_PIC#name |
21 | { | 23 | OBJECT_DECLARE_SIMPLE_TYPE(LoongArchPCHPIC, LOONGARCH_PCH_PIC) |
22 | char *nodename; | 24 | |
23 | hwaddr base = VIRT_UART_BASE; | 25 | -struct LoongArchPCHPIC { |
24 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_uart_node(LoongArchMachineState *lams) | 26 | - SysBusDevice parent_obj; |
25 | qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0x0, base, 0x0, size); | 27 | - qemu_irq parent_irq[64]; |
26 | qemu_fdt_setprop_cell(ms->fdt, nodename, "clock-frequency", 100000000); | 28 | - uint64_t int_mask; /*0x020 interrupt mask register*/ |
27 | qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", nodename); | 29 | - uint64_t htmsi_en; /*0x040 1=msi*/ |
28 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts", | 30 | - uint64_t intedge; /*0x060 edge=1 level =0*/ |
29 | + VIRT_UART_IRQ - VIRT_GSI_BASE, 0x4); | 31 | - uint64_t intclr; /*0x080 for clean edge int,set 1 clean,set 0 is noused*/ |
30 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent", | 32 | - uint64_t auto_crtl0; /*0x0c0*/ |
31 | + *pch_pic_phandle); | 33 | - uint64_t auto_crtl1; /*0x0e0*/ |
32 | g_free(nodename); | 34 | - uint64_t last_intirr; /* edge detection */ |
33 | } | 35 | - uint64_t intirr; /* 0x380 interrupt request register */ |
34 | 36 | - uint64_t intisr; /* 0x3a0 interrupt service register */ | |
35 | @@ -XXX,XX +XXX,XX @@ static void loongarch_devices_init(DeviceState *pch_pic, | 37 | - /* |
36 | qdev_get_gpio_in(pch_pic, | 38 | - * 0x3e0 interrupt level polarity selection |
37 | VIRT_UART_IRQ - VIRT_GSI_BASE), | 39 | - * register 0 for high level trigger |
38 | 115200, serial_hd(0), DEVICE_LITTLE_ENDIAN); | 40 | - */ |
39 | - fdt_add_uart_node(lams); | 41 | - uint64_t int_polarity; |
40 | + fdt_add_uart_node(lams, pch_pic_phandle); | 42 | - |
41 | 43 | - uint8_t route_entry[64]; /*0x100 - 0x138*/ | |
42 | /* Network init */ | 44 | - uint8_t htmsi_vector[64]; /*0x200 - 0x238*/ |
43 | pci_init_nic_devices(pci_bus, mc->default_nic); | 45 | - |
46 | - MemoryRegion iomem32_low; | ||
47 | - MemoryRegion iomem32_high; | ||
48 | - MemoryRegion iomem8; | ||
49 | - unsigned int irq_num; | ||
50 | -}; | ||
51 | #endif /* HW_LOONGARCH_PCH_PIC_H */ | ||
52 | diff --git a/include/hw/intc/loongarch_pic_common.h b/include/hw/intc/loongarch_pic_common.h | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/include/hw/intc/loongarch_pic_common.h | ||
55 | +++ b/include/hw/intc/loongarch_pic_common.h | ||
56 | @@ -XXX,XX +XXX,XX @@ | ||
57 | #define STATUS_HI_START 0x4 | ||
58 | #define POL_LO_START 0x40 | ||
59 | #define POL_HI_START 0x44 | ||
60 | + | ||
61 | +struct LoongArchPICCommonState { | ||
62 | + SysBusDevice parent_obj; | ||
63 | + | ||
64 | + qemu_irq parent_irq[64]; | ||
65 | + uint64_t int_mask; /* 0x020 interrupt mask register */ | ||
66 | + uint64_t htmsi_en; /* 0x040 1=msi */ | ||
67 | + uint64_t intedge; /* 0x060 edge=1 level=0 */ | ||
68 | + uint64_t intclr; /* 0x080 clean edge int, set 1 clean, 0 noused */ | ||
69 | + uint64_t auto_crtl0; /* 0x0c0 */ | ||
70 | + uint64_t auto_crtl1; /* 0x0e0 */ | ||
71 | + uint64_t last_intirr; /* edge detection */ | ||
72 | + uint64_t intirr; /* 0x380 interrupt request register */ | ||
73 | + uint64_t intisr; /* 0x3a0 interrupt service register */ | ||
74 | + /* | ||
75 | + * 0x3e0 interrupt level polarity selection | ||
76 | + * register 0 for high level trigger | ||
77 | + */ | ||
78 | + uint64_t int_polarity; | ||
79 | + | ||
80 | + uint8_t route_entry[64]; /* 0x100 - 0x138 */ | ||
81 | + uint8_t htmsi_vector[64]; /* 0x200 - 0x238 */ | ||
82 | + | ||
83 | + MemoryRegion iomem32_low; | ||
84 | + MemoryRegion iomem32_high; | ||
85 | + MemoryRegion iomem8; | ||
86 | + unsigned int irq_num; | ||
87 | +}; | ||
88 | #endif /* HW_LOONGARCH_PIC_COMMON_H */ | ||
44 | -- | 89 | -- |
45 | 2.25.1 | 90 | 2.43.5 | diff view generated by jsdifflib |
1 | This patch removes the unused fdt irqchip node. | 1 | Memory region is created in instance_init(), merge it into function |
---|---|---|---|
2 | realize(). There is no special class_init() for loongarch_pch object. | ||
2 | 3 | ||
3 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 5 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | Message-Id: <20240426091551.2397867-16-gaosong@loongson.cn> | ||
6 | --- | 6 | --- |
7 | hw/loongarch/virt.c | 31 +------------------------------ | 7 | hw/intc/loongarch_pch_pic.c | 15 ++++----------- |
8 | 1 file changed, 1 insertion(+), 30 deletions(-) | 8 | 1 file changed, 4 insertions(+), 11 deletions(-) |
9 | 9 | ||
10 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 10 | diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c |
11 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/hw/loongarch/virt.c | 12 | --- a/hw/intc/loongarch_pch_pic.c |
13 | +++ b/hw/loongarch/virt.c | 13 | +++ b/hw/intc/loongarch_pch_pic.c |
14 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_pcie_node(const LoongArchMachineState *lams, | 14 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d) |
15 | g_free(nodename); | 15 | static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) |
16 | } | 16 | { |
17 | 17 | LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev); | |
18 | -static void fdt_add_irqchip_node(LoongArchMachineState *lams) | 18 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); |
19 | -{ | 19 | |
20 | - MachineState *ms = MACHINE(lams); | 20 | if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { |
21 | - char *nodename; | 21 | error_setg(errp, "Invalid 'pic_irq_num'"); |
22 | - uint32_t irqchip_phandle; | 22 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) |
23 | - | 23 | |
24 | - irqchip_phandle = qemu_fdt_alloc_phandle(ms->fdt); | 24 | qdev_init_gpio_out(dev, s->parent_irq, s->irq_num); |
25 | - qemu_fdt_setprop_cell(ms->fdt, "/", "interrupt-parent", irqchip_phandle); | 25 | qdev_init_gpio_in(dev, pch_pic_irq_handler, s->irq_num); |
26 | - | ||
27 | - nodename = g_strdup_printf("/intc@%lx", VIRT_IOAPIC_REG_BASE); | ||
28 | - qemu_fdt_add_subnode(ms->fdt, nodename); | ||
29 | - qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 3); | ||
30 | - qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0); | ||
31 | - qemu_fdt_setprop_cell(ms->fdt, nodename, "#address-cells", 0x2); | ||
32 | - qemu_fdt_setprop_cell(ms->fdt, nodename, "#size-cells", 0x2); | ||
33 | - qemu_fdt_setprop(ms->fdt, nodename, "ranges", NULL, 0); | ||
34 | - | ||
35 | - qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", | ||
36 | - "loongarch,ls7a"); | ||
37 | - | ||
38 | - qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", | ||
39 | - 2, VIRT_IOAPIC_REG_BASE, | ||
40 | - 2, PCH_PIC_ROUTE_ENTRY_OFFSET); | ||
41 | - | ||
42 | - qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", irqchip_phandle); | ||
43 | - g_free(nodename); | ||
44 | -} | 26 | -} |
45 | - | 27 | - |
46 | static void fdt_add_memory_node(MachineState *ms, | 28 | -static void loongarch_pch_pic_init(Object *obj) |
47 | uint64_t base, uint64_t size, int node_id) | 29 | -{ |
48 | { | 30 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(obj); |
49 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | 31 | - SysBusDevice *sbd = SYS_BUS_DEVICE(obj); |
50 | 32 | - | |
51 | /* Initialize the IO interrupt subsystem */ | 33 | - memory_region_init_io(&s->iomem32_low, obj, |
52 | loongarch_irq_init(lams); | 34 | + memory_region_init_io(&s->iomem32_low, OBJECT(dev), |
53 | - fdt_add_irqchip_node(lams); | 35 | &loongarch_pch_pic_reg32_low_ops, |
54 | - platform_bus_add_all_fdt_nodes(machine->fdt, "/intc", | 36 | s, PCH_PIC_NAME(.reg32_part1), 0x100); |
55 | + platform_bus_add_all_fdt_nodes(machine->fdt, "/platic", | 37 | - memory_region_init_io(&s->iomem8, obj, &loongarch_pch_pic_reg8_ops, |
56 | VIRT_PLATFORM_BUS_BASEADDRESS, | 38 | + memory_region_init_io(&s->iomem8, OBJECT(dev), &loongarch_pch_pic_reg8_ops, |
57 | VIRT_PLATFORM_BUS_SIZE, | 39 | s, PCH_PIC_NAME(.reg8), 0x2a0); |
58 | VIRT_PLATFORM_BUS_IRQ); | 40 | - memory_region_init_io(&s->iomem32_high, obj, |
41 | + memory_region_init_io(&s->iomem32_high, OBJECT(dev), | ||
42 | &loongarch_pch_pic_reg32_high_ops, | ||
43 | s, PCH_PIC_NAME(.reg32_part2), 0xc60); | ||
44 | sysbus_init_mmio(sbd, &s->iomem32_low); | ||
45 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo loongarch_pch_pic_info = { | ||
46 | .name = TYPE_LOONGARCH_PCH_PIC, | ||
47 | .parent = TYPE_SYS_BUS_DEVICE, | ||
48 | .instance_size = sizeof(LoongArchPCHPIC), | ||
49 | - .instance_init = loongarch_pch_pic_init, | ||
50 | .class_init = loongarch_pch_pic_class_init, | ||
51 | }; | ||
52 | |||
59 | -- | 53 | -- |
60 | 2.25.1 | 54 | 2.43.5 | diff view generated by jsdifflib |
1 | This patch adds pcie irq_map node for FDT. | 1 | With pic vmstate, rename structure name vmstate_loongarch_pch_pic with |
---|---|---|---|
2 | vmstate_loongarch_pic_common, and with pic property rename | ||
3 | loongarch_pch_pic_properties with loongarch_pic_common_properties. | ||
2 | 4 | ||
3 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | Message-Id: <20240426091551.2397867-15-gaosong@loongson.cn> | ||
6 | --- | 7 | --- |
7 | hw/loongarch/virt.c | 73 ++++++++++++++++++++++++++++++++++++++++++--- | 8 | hw/intc/loongarch_pch_pic.c | 52 +++++++++++++++++++++++-------------- |
8 | 1 file changed, 69 insertions(+), 4 deletions(-) | 9 | 1 file changed, 32 insertions(+), 20 deletions(-) |
9 | 10 | ||
10 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 11 | diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c |
11 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/hw/loongarch/virt.c | 13 | --- a/hw/intc/loongarch_pch_pic.c |
13 | +++ b/hw/loongarch/virt.c | 14 | +++ b/hw/intc/loongarch_pch_pic.c |
14 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_fw_cfg_node(const LoongArchMachineState *lams) | 15 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d) |
15 | g_free(nodename); | 16 | s->int_polarity = 0x0; |
16 | } | 17 | } |
17 | 18 | ||
18 | -static void fdt_add_pcie_node(const LoongArchMachineState *lams) | 19 | +static void loongarch_pic_common_realize(DeviceState *dev, Error **errp) |
19 | +static void fdt_add_pcie_irq_map_node(const LoongArchMachineState *lams, | ||
20 | + char *nodename, | ||
21 | + uint32_t *pch_pic_phandle) | ||
22 | +{ | 20 | +{ |
23 | + int pin, dev; | 21 | + LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev); |
24 | + uint32_t irq_map_stride = 0; | ||
25 | + uint32_t full_irq_map[GPEX_NUM_IRQS *GPEX_NUM_IRQS * 10] = {}; | ||
26 | + uint32_t *irq_map = full_irq_map; | ||
27 | + const MachineState *ms = MACHINE(lams); | ||
28 | + | 22 | + |
29 | + /* This code creates a standard swizzle of interrupts such that | 23 | + if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { |
30 | + * each device's first interrupt is based on it's PCI_SLOT number. | 24 | + error_setg(errp, "Invalid 'pic_irq_num'"); |
31 | + * (See pci_swizzle_map_irq_fn()) | 25 | + return; |
32 | + * | ||
33 | + * We only need one entry per interrupt in the table (not one per | ||
34 | + * possible slot) seeing the interrupt-map-mask will allow the table | ||
35 | + * to wrap to any number of devices. | ||
36 | + */ | ||
37 | + | ||
38 | + for (dev = 0; dev < GPEX_NUM_IRQS; dev++) { | ||
39 | + int devfn = dev * 0x8; | ||
40 | + | ||
41 | + for (pin = 0; pin < GPEX_NUM_IRQS; pin++) { | ||
42 | + int irq_nr = 16 + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_IRQS); | ||
43 | + int i = 0; | ||
44 | + | ||
45 | + /* Fill PCI address cells */ | ||
46 | + irq_map[i] = cpu_to_be32(devfn << 8); | ||
47 | + i += 3; | ||
48 | + | ||
49 | + /* Fill PCI Interrupt cells */ | ||
50 | + irq_map[i] = cpu_to_be32(pin + 1); | ||
51 | + i += 1; | ||
52 | + | ||
53 | + /* Fill interrupt controller phandle and cells */ | ||
54 | + irq_map[i++] = cpu_to_be32(*pch_pic_phandle); | ||
55 | + irq_map[i++] = cpu_to_be32(irq_nr); | ||
56 | + | ||
57 | + if (!irq_map_stride) { | ||
58 | + irq_map_stride = i; | ||
59 | + } | ||
60 | + irq_map += irq_map_stride; | ||
61 | + } | ||
62 | + } | 26 | + } |
63 | + | ||
64 | + | ||
65 | + qemu_fdt_setprop(ms->fdt, nodename, "interrupt-map", full_irq_map, | ||
66 | + GPEX_NUM_IRQS * GPEX_NUM_IRQS * | ||
67 | + irq_map_stride * sizeof(uint32_t)); | ||
68 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupt-map-mask", | ||
69 | + 0x1800, 0, 0, 0x7); | ||
70 | +} | 27 | +} |
71 | + | 28 | + |
72 | +static void fdt_add_pcie_node(const LoongArchMachineState *lams, | 29 | static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) |
73 | + uint32_t *pch_pic_phandle, | ||
74 | + uint32_t *pch_msi_phandle) | ||
75 | { | 30 | { |
76 | char *nodename; | 31 | LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev); |
77 | hwaddr base_mmio = VIRT_PCI_MEM_BASE; | 32 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); |
78 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_pcie_node(const LoongArchMachineState *lams) | 33 | + Error *local_err = NULL; |
79 | 2, base_pio, 2, size_pio, | 34 | |
80 | 1, FDT_PCI_RANGE_MMIO, 2, base_mmio, | 35 | - if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { |
81 | 2, base_mmio, 2, size_mmio); | 36 | - error_setg(errp, "Invalid 'pic_irq_num'"); |
82 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "msi-map", | 37 | + loongarch_pic_common_realize(dev, &local_err); |
83 | + 0, *pch_msi_phandle, 0, 0x10000); | 38 | + if (local_err) { |
84 | + | 39 | + error_propagate(errp, local_err); |
85 | + fdt_add_pcie_irq_map_node(lams, nodename, pch_pic_phandle); | 40 | return; |
86 | + | 41 | } |
87 | g_free(nodename); | 42 | |
43 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) | ||
44 | |||
88 | } | 45 | } |
89 | 46 | ||
90 | @@ -XXX,XX +XXX,XX @@ static DeviceState *create_platform_bus(DeviceState *pch_pic) | 47 | -static Property loongarch_pch_pic_properties[] = { |
91 | return dev; | 48 | - DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPCHPIC, irq_num, 0), |
49 | +static Property loongarch_pic_common_properties[] = { | ||
50 | + DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPICCommonState, irq_num, 0), | ||
51 | DEFINE_PROP_END_OF_LIST(), | ||
52 | }; | ||
53 | |||
54 | -static const VMStateDescription vmstate_loongarch_pch_pic = { | ||
55 | - .name = TYPE_LOONGARCH_PCH_PIC, | ||
56 | +static const VMStateDescription vmstate_loongarch_pic_common = { | ||
57 | + .name = "loongarch_pch_pic", | ||
58 | .version_id = 1, | ||
59 | .minimum_version_id = 1, | ||
60 | .fields = (const VMStateField[]) { | ||
61 | - VMSTATE_UINT64(int_mask, LoongArchPCHPIC), | ||
62 | - VMSTATE_UINT64(htmsi_en, LoongArchPCHPIC), | ||
63 | - VMSTATE_UINT64(intedge, LoongArchPCHPIC), | ||
64 | - VMSTATE_UINT64(intclr, LoongArchPCHPIC), | ||
65 | - VMSTATE_UINT64(auto_crtl0, LoongArchPCHPIC), | ||
66 | - VMSTATE_UINT64(auto_crtl1, LoongArchPCHPIC), | ||
67 | - VMSTATE_UINT8_ARRAY(route_entry, LoongArchPCHPIC, 64), | ||
68 | - VMSTATE_UINT8_ARRAY(htmsi_vector, LoongArchPCHPIC, 64), | ||
69 | - VMSTATE_UINT64(last_intirr, LoongArchPCHPIC), | ||
70 | - VMSTATE_UINT64(intirr, LoongArchPCHPIC), | ||
71 | - VMSTATE_UINT64(intisr, LoongArchPCHPIC), | ||
72 | - VMSTATE_UINT64(int_polarity, LoongArchPCHPIC), | ||
73 | + VMSTATE_UINT64(int_mask, LoongArchPICCommonState), | ||
74 | + VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState), | ||
75 | + VMSTATE_UINT64(intedge, LoongArchPICCommonState), | ||
76 | + VMSTATE_UINT64(intclr, LoongArchPICCommonState), | ||
77 | + VMSTATE_UINT64(auto_crtl0, LoongArchPICCommonState), | ||
78 | + VMSTATE_UINT64(auto_crtl1, LoongArchPICCommonState), | ||
79 | + VMSTATE_UINT8_ARRAY(route_entry, LoongArchPICCommonState, 64), | ||
80 | + VMSTATE_UINT8_ARRAY(htmsi_vector, LoongArchPICCommonState, 64), | ||
81 | + VMSTATE_UINT64(last_intirr, LoongArchPICCommonState), | ||
82 | + VMSTATE_UINT64(intirr, LoongArchPICCommonState), | ||
83 | + VMSTATE_UINT64(intisr, LoongArchPICCommonState), | ||
84 | + VMSTATE_UINT64(int_polarity, LoongArchPICCommonState), | ||
85 | VMSTATE_END_OF_LIST() | ||
86 | } | ||
87 | }; | ||
88 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_class_init(ObjectClass *klass, void *data) | ||
89 | |||
90 | dc->realize = loongarch_pch_pic_realize; | ||
91 | device_class_set_legacy_reset(dc, loongarch_pch_pic_reset); | ||
92 | - dc->vmsd = &vmstate_loongarch_pch_pic; | ||
93 | - device_class_set_props(dc, loongarch_pch_pic_properties); | ||
94 | + dc->vmsd = &vmstate_loongarch_pic_common; | ||
95 | + device_class_set_props(dc, loongarch_pic_common_properties); | ||
92 | } | 96 | } |
93 | 97 | ||
94 | -static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState *lams) | 98 | static const TypeInfo loongarch_pch_pic_info = { |
95 | +static void loongarch_devices_init(DeviceState *pch_pic, | ||
96 | + LoongArchMachineState *lams, | ||
97 | + uint32_t *pch_pic_phandle, | ||
98 | + uint32_t *pch_msi_phandle) | ||
99 | { | ||
100 | MachineClass *mc = MACHINE_GET_CLASS(lams); | ||
101 | DeviceState *gpex_dev; | ||
102 | @@ -XXX,XX +XXX,XX @@ static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState * | ||
103 | gpex_set_irq_num(GPEX_HOST(gpex_dev), i, 16 + i); | ||
104 | } | ||
105 | |||
106 | + /* Add pcie node */ | ||
107 | + fdt_add_pcie_node(lams, pch_pic_phandle, pch_msi_phandle); | ||
108 | + | ||
109 | serial_mm_init(get_system_memory(), VIRT_UART_BASE, 0, | ||
110 | qdev_get_gpio_in(pch_pic, | ||
111 | VIRT_UART_IRQ - VIRT_GSI_BASE), | ||
112 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
113 | /* Add PCH MSI node */ | ||
114 | fdt_add_pch_msi_node(lams, &eiointc_phandle, &pch_msi_phandle); | ||
115 | |||
116 | - loongarch_devices_init(pch_pic, lams); | ||
117 | + loongarch_devices_init(pch_pic, lams, &pch_pic_phandle, &pch_msi_phandle); | ||
118 | } | ||
119 | |||
120 | static void loongarch_firmware_init(LoongArchMachineState *lams) | ||
121 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | ||
122 | lams->powerdown_notifier.notify = virt_powerdown_req; | ||
123 | qemu_register_powerdown_notifier(&lams->powerdown_notifier); | ||
124 | |||
125 | - fdt_add_pcie_node(lams); | ||
126 | /* | ||
127 | * Since lowmem region starts from 0 and Linux kernel legacy start address | ||
128 | * at 2 MiB, FDT base address is located at 1 MiB to avoid NULL pointer | ||
129 | -- | 99 | -- |
130 | 2.25.1 | 100 | 2.43.5 | diff view generated by jsdifflib |
1 | Move some boot functions to boot.c and struct | 1 | Move some common functions to file loongarch_pic_common.c, the common |
---|---|---|---|
2 | loongarch_boot_info into struct LoongArchMachineState. | 2 | functions include loongarch_pic_common_realize(), property structure |
3 | loongarch_pic_common_properties and vmstate structure | ||
4 | vmstate_loongarch_pic_common. | ||
3 | 5 | ||
4 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 6 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
5 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 7 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
6 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
7 | Message-Id: <20240426091551.2397867-2-gaosong@loongson.cn> | ||
8 | --- | 8 | --- |
9 | hw/loongarch/boot.c | 128 ++++++++++++++++++++++++++++++++++++ | 9 | hw/intc/loongarch_pch_pic.c | 37 +----------------------------- |
10 | hw/loongarch/meson.build | 1 + | 10 | hw/intc/loongarch_pic_common.c | 41 ++++++++++++++++++++++++++++++++++ |
11 | hw/loongarch/virt.c | 121 +++------------------------------- | 11 | 2 files changed, 42 insertions(+), 36 deletions(-) |
12 | include/hw/loongarch/boot.h | 21 ++++++ | 12 | create mode 100644 hw/intc/loongarch_pic_common.c |
13 | include/hw/loongarch/virt.h | 2 + | ||
14 | 5 files changed, 160 insertions(+), 113 deletions(-) | ||
15 | create mode 100644 hw/loongarch/boot.c | ||
16 | create mode 100644 include/hw/loongarch/boot.h | ||
17 | 13 | ||
18 | diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c | 14 | diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c |
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/intc/loongarch_pch_pic.c | ||
17 | +++ b/hw/intc/loongarch_pch_pic.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d) | ||
19 | s->int_polarity = 0x0; | ||
20 | } | ||
21 | |||
22 | -static void loongarch_pic_common_realize(DeviceState *dev, Error **errp) | ||
23 | -{ | ||
24 | - LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev); | ||
25 | - | ||
26 | - if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { | ||
27 | - error_setg(errp, "Invalid 'pic_irq_num'"); | ||
28 | - return; | ||
29 | - } | ||
30 | -} | ||
31 | - | ||
32 | +#include "loongarch_pic_common.c" | ||
33 | static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) | ||
34 | { | ||
35 | LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev); | ||
36 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) | ||
37 | |||
38 | } | ||
39 | |||
40 | -static Property loongarch_pic_common_properties[] = { | ||
41 | - DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPICCommonState, irq_num, 0), | ||
42 | - DEFINE_PROP_END_OF_LIST(), | ||
43 | -}; | ||
44 | - | ||
45 | -static const VMStateDescription vmstate_loongarch_pic_common = { | ||
46 | - .name = "loongarch_pch_pic", | ||
47 | - .version_id = 1, | ||
48 | - .minimum_version_id = 1, | ||
49 | - .fields = (const VMStateField[]) { | ||
50 | - VMSTATE_UINT64(int_mask, LoongArchPICCommonState), | ||
51 | - VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState), | ||
52 | - VMSTATE_UINT64(intedge, LoongArchPICCommonState), | ||
53 | - VMSTATE_UINT64(intclr, LoongArchPICCommonState), | ||
54 | - VMSTATE_UINT64(auto_crtl0, LoongArchPICCommonState), | ||
55 | - VMSTATE_UINT64(auto_crtl1, LoongArchPICCommonState), | ||
56 | - VMSTATE_UINT8_ARRAY(route_entry, LoongArchPICCommonState, 64), | ||
57 | - VMSTATE_UINT8_ARRAY(htmsi_vector, LoongArchPICCommonState, 64), | ||
58 | - VMSTATE_UINT64(last_intirr, LoongArchPICCommonState), | ||
59 | - VMSTATE_UINT64(intirr, LoongArchPICCommonState), | ||
60 | - VMSTATE_UINT64(intisr, LoongArchPICCommonState), | ||
61 | - VMSTATE_UINT64(int_polarity, LoongArchPICCommonState), | ||
62 | - VMSTATE_END_OF_LIST() | ||
63 | - } | ||
64 | -}; | ||
65 | - | ||
66 | static void loongarch_pch_pic_class_init(ObjectClass *klass, void *data) | ||
67 | { | ||
68 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
69 | diff --git a/hw/intc/loongarch_pic_common.c b/hw/intc/loongarch_pic_common.c | ||
19 | new file mode 100644 | 70 | new file mode 100644 |
20 | index XXXXXXX..XXXXXXX | 71 | index XXXXXXX..XXXXXXX |
21 | --- /dev/null | 72 | --- /dev/null |
22 | +++ b/hw/loongarch/boot.c | 73 | +++ b/hw/intc/loongarch_pic_common.c |
23 | @@ -XXX,XX +XXX,XX @@ | 74 | @@ -XXX,XX +XXX,XX @@ |
24 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ | 75 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
25 | +/* | 76 | +/* |
26 | + * LoongArch boot helper functions. | 77 | + * QEMU Loongson 7A1000 I/O interrupt controller. |
27 | + * | 78 | + * Copyright (C) 2024 Loongson Technology Corporation Limited |
28 | + * Copyright (c) 2023 Loongson Technology Corporation Limited | ||
29 | + */ | 79 | + */ |
30 | + | 80 | + |
31 | +#include "qemu/osdep.h" | 81 | +static void loongarch_pic_common_realize(DeviceState *dev, Error **errp) |
32 | +#include "qemu/units.h" | 82 | +{ |
33 | +#include "target/loongarch/cpu.h" | 83 | + LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev); |
34 | +#include "hw/loongarch/virt.h" | ||
35 | +#include "hw/loader.h" | ||
36 | +#include "elf.h" | ||
37 | +#include "qemu/error-report.h" | ||
38 | +#include "sysemu/reset.h" | ||
39 | +#include "sysemu/qtest.h" | ||
40 | + | 84 | + |
41 | +static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr) | 85 | + if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { |
42 | +{ | 86 | + error_setg(errp, "Invalid 'pic_irq_num'"); |
43 | + return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS); | 87 | + return; |
44 | +} | ||
45 | + | ||
46 | +static int64_t load_kernel_info(struct loongarch_boot_info *info) | ||
47 | +{ | ||
48 | + uint64_t kernel_entry, kernel_low, kernel_high; | ||
49 | + ssize_t kernel_size; | ||
50 | + | ||
51 | + kernel_size = load_elf(info->kernel_filename, NULL, | ||
52 | + cpu_loongarch_virt_to_phys, NULL, | ||
53 | + &kernel_entry, &kernel_low, | ||
54 | + &kernel_high, NULL, 0, | ||
55 | + EM_LOONGARCH, 1, 0); | ||
56 | + | ||
57 | + if (kernel_size < 0) { | ||
58 | + error_report("could not load kernel '%s': %s", | ||
59 | + info->kernel_filename, | ||
60 | + load_elf_strerror(kernel_size)); | ||
61 | + exit(1); | ||
62 | + } | ||
63 | + return kernel_entry; | ||
64 | +} | ||
65 | + | ||
66 | +static void reset_load_elf(void *opaque) | ||
67 | +{ | ||
68 | + LoongArchCPU *cpu = opaque; | ||
69 | + CPULoongArchState *env = &cpu->env; | ||
70 | + | ||
71 | + cpu_reset(CPU(cpu)); | ||
72 | + if (env->load_elf) { | ||
73 | + cpu_set_pc(CPU(cpu), env->elf_address); | ||
74 | + } | 88 | + } |
75 | +} | 89 | +} |
76 | + | 90 | + |
77 | +static void fw_cfg_add_kernel_info(struct loongarch_boot_info *info, | 91 | +static Property loongarch_pic_common_properties[] = { |
78 | + FWCfgState *fw_cfg) | 92 | + DEFINE_PROP_UINT32("pch_pic_irq_num", LoongArchPICCommonState, irq_num, 0), |
79 | +{ | 93 | + DEFINE_PROP_END_OF_LIST(), |
80 | + /* | ||
81 | + * Expose the kernel, the command line, and the initrd in fw_cfg. | ||
82 | + * We don't process them here at all, it's all left to the | ||
83 | + * firmware. | ||
84 | + */ | ||
85 | + load_image_to_fw_cfg(fw_cfg, | ||
86 | + FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA, | ||
87 | + info->kernel_filename, | ||
88 | + false); | ||
89 | + | ||
90 | + if (info->initrd_filename) { | ||
91 | + load_image_to_fw_cfg(fw_cfg, | ||
92 | + FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA, | ||
93 | + info->initrd_filename, false); | ||
94 | + } | ||
95 | + | ||
96 | + if (info->kernel_cmdline) { | ||
97 | + fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, | ||
98 | + strlen(info->kernel_cmdline) + 1); | ||
99 | + fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, | ||
100 | + info->kernel_cmdline); | ||
101 | + } | ||
102 | +} | ||
103 | + | ||
104 | +static void loongarch_firmware_boot(LoongArchMachineState *lams, | ||
105 | + struct loongarch_boot_info *info) | ||
106 | +{ | ||
107 | + fw_cfg_add_kernel_info(info, lams->fw_cfg); | ||
108 | +} | ||
109 | + | ||
110 | +static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info) | ||
111 | +{ | ||
112 | + int64_t kernel_addr = 0; | ||
113 | + LoongArchCPU *lacpu; | ||
114 | + CPUState *cs; | ||
115 | + | ||
116 | + if (info->kernel_filename) { | ||
117 | + kernel_addr = load_kernel_info(info); | ||
118 | + } else { | ||
119 | + if(!qtest_enabled()) { | ||
120 | + error_report("Need kernel filename\n"); | ||
121 | + exit(1); | ||
122 | + } | ||
123 | + } | ||
124 | + | ||
125 | + CPU_FOREACH(cs) { | ||
126 | + lacpu = LOONGARCH_CPU(cs); | ||
127 | + lacpu->env.load_elf = true; | ||
128 | + lacpu->env.elf_address = kernel_addr; | ||
129 | + } | ||
130 | +} | ||
131 | + | ||
132 | +void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info) | ||
133 | +{ | ||
134 | + LoongArchMachineState *lams = LOONGARCH_MACHINE(ms); | ||
135 | + int i; | ||
136 | + | ||
137 | + /* register reset function */ | ||
138 | + for (i = 0; i < ms->smp.cpus; i++) { | ||
139 | + qemu_register_reset(reset_load_elf, LOONGARCH_CPU(qemu_get_cpu(i))); | ||
140 | + } | ||
141 | + | ||
142 | + info->kernel_filename = ms->kernel_filename; | ||
143 | + info->kernel_cmdline = ms->kernel_cmdline; | ||
144 | + info->initrd_filename = ms->initrd_filename; | ||
145 | + | ||
146 | + if (lams->bios_loaded) { | ||
147 | + loongarch_firmware_boot(lams, info); | ||
148 | + } else { | ||
149 | + loongarch_direct_kernel_boot(info); | ||
150 | + } | ||
151 | +} | ||
152 | diff --git a/hw/loongarch/meson.build b/hw/loongarch/meson.build | ||
153 | index XXXXXXX..XXXXXXX 100644 | ||
154 | --- a/hw/loongarch/meson.build | ||
155 | +++ b/hw/loongarch/meson.build | ||
156 | @@ -XXX,XX +XXX,XX @@ | ||
157 | loongarch_ss = ss.source_set() | ||
158 | loongarch_ss.add(files( | ||
159 | 'fw_cfg.c', | ||
160 | + 'boot.c', | ||
161 | )) | ||
162 | loongarch_ss.add(when: 'CONFIG_LOONGARCH_VIRT', if_true: [files('virt.c'), fdt]) | ||
163 | loongarch_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-build.c')) | ||
164 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
165 | index XXXXXXX..XXXXXXX 100644 | ||
166 | --- a/hw/loongarch/virt.c | ||
167 | +++ b/hw/loongarch/virt.c | ||
168 | @@ -XXX,XX +XXX,XX @@ | ||
169 | #include "hw/block/flash.h" | ||
170 | #include "qemu/error-report.h" | ||
171 | |||
172 | - | ||
173 | -struct loaderparams { | ||
174 | - uint64_t ram_size; | ||
175 | - const char *kernel_filename; | ||
176 | - const char *kernel_cmdline; | ||
177 | - const char *initrd_filename; | ||
178 | -}; | ||
179 | - | ||
180 | static PFlashCFI01 *virt_flash_create1(LoongArchMachineState *lams, | ||
181 | const char *name, | ||
182 | const char *alias_prop_name) | ||
183 | @@ -XXX,XX +XXX,XX @@ static void memmap_add_entry(uint64_t address, uint64_t length, uint32_t type) | ||
184 | memmap_entries++; | ||
185 | } | ||
186 | |||
187 | -static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr) | ||
188 | -{ | ||
189 | - return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS); | ||
190 | -} | ||
191 | - | ||
192 | -static int64_t load_kernel_info(const struct loaderparams *loaderparams) | ||
193 | -{ | ||
194 | - uint64_t kernel_entry, kernel_low, kernel_high; | ||
195 | - ssize_t kernel_size; | ||
196 | - | ||
197 | - kernel_size = load_elf(loaderparams->kernel_filename, NULL, | ||
198 | - cpu_loongarch_virt_to_phys, NULL, | ||
199 | - &kernel_entry, &kernel_low, | ||
200 | - &kernel_high, NULL, 0, | ||
201 | - EM_LOONGARCH, 1, 0); | ||
202 | - | ||
203 | - if (kernel_size < 0) { | ||
204 | - error_report("could not load kernel '%s': %s", | ||
205 | - loaderparams->kernel_filename, | ||
206 | - load_elf_strerror(kernel_size)); | ||
207 | - exit(1); | ||
208 | - } | ||
209 | - return kernel_entry; | ||
210 | -} | ||
211 | - | ||
212 | static DeviceState *create_acpi_ged(DeviceState *pch_pic, LoongArchMachineState *lams) | ||
213 | { | ||
214 | DeviceState *dev; | ||
215 | @@ -XXX,XX +XXX,XX @@ static void loongarch_firmware_init(LoongArchMachineState *lams) | ||
216 | } | ||
217 | } | ||
218 | |||
219 | -static void reset_load_elf(void *opaque) | ||
220 | -{ | ||
221 | - LoongArchCPU *cpu = opaque; | ||
222 | - CPULoongArchState *env = &cpu->env; | ||
223 | - | ||
224 | - cpu_reset(CPU(cpu)); | ||
225 | - if (env->load_elf) { | ||
226 | - cpu_set_pc(CPU(cpu), env->elf_address); | ||
227 | - } | ||
228 | -} | ||
229 | - | ||
230 | -static void fw_cfg_add_kernel_info(const struct loaderparams *loaderparams, | ||
231 | - FWCfgState *fw_cfg) | ||
232 | -{ | ||
233 | - /* | ||
234 | - * Expose the kernel, the command line, and the initrd in fw_cfg. | ||
235 | - * We don't process them here at all, it's all left to the | ||
236 | - * firmware. | ||
237 | - */ | ||
238 | - load_image_to_fw_cfg(fw_cfg, | ||
239 | - FW_CFG_KERNEL_SIZE, FW_CFG_KERNEL_DATA, | ||
240 | - loaderparams->kernel_filename, | ||
241 | - false); | ||
242 | - | ||
243 | - if (loaderparams->initrd_filename) { | ||
244 | - load_image_to_fw_cfg(fw_cfg, | ||
245 | - FW_CFG_INITRD_SIZE, FW_CFG_INITRD_DATA, | ||
246 | - loaderparams->initrd_filename, false); | ||
247 | - } | ||
248 | - | ||
249 | - if (loaderparams->kernel_cmdline) { | ||
250 | - fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, | ||
251 | - strlen(loaderparams->kernel_cmdline) + 1); | ||
252 | - fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, | ||
253 | - loaderparams->kernel_cmdline); | ||
254 | - } | ||
255 | -} | ||
256 | - | ||
257 | -static void loongarch_firmware_boot(LoongArchMachineState *lams, | ||
258 | - const struct loaderparams *loaderparams) | ||
259 | -{ | ||
260 | - fw_cfg_add_kernel_info(loaderparams, lams->fw_cfg); | ||
261 | -} | ||
262 | - | ||
263 | -static void loongarch_direct_kernel_boot(LoongArchMachineState *lams, | ||
264 | - const struct loaderparams *loaderparams) | ||
265 | -{ | ||
266 | - MachineState *machine = MACHINE(lams); | ||
267 | - int64_t kernel_addr = 0; | ||
268 | - LoongArchCPU *lacpu; | ||
269 | - int i; | ||
270 | - | ||
271 | - kernel_addr = load_kernel_info(loaderparams); | ||
272 | - if (!machine->firmware) { | ||
273 | - for (i = 0; i < machine->smp.cpus; i++) { | ||
274 | - lacpu = LOONGARCH_CPU(qemu_get_cpu(i)); | ||
275 | - lacpu->env.load_elf = true; | ||
276 | - lacpu->env.elf_address = kernel_addr; | ||
277 | - } | ||
278 | - } | ||
279 | -} | ||
280 | |||
281 | static void loongarch_qemu_write(void *opaque, hwaddr addr, | ||
282 | uint64_t val, unsigned size) | ||
283 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | ||
284 | MachineClass *mc = MACHINE_GET_CLASS(machine); | ||
285 | CPUState *cpu; | ||
286 | char *ramName = NULL; | ||
287 | - struct loaderparams loaderparams = { }; | ||
288 | |||
289 | if (!cpu_model) { | ||
290 | cpu_model = LOONGARCH_CPU_TYPE_NAME("la464"); | ||
291 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | ||
292 | sizeof(struct memmap_entry) * (memmap_entries)); | ||
293 | } | ||
294 | fdt_add_fw_cfg_node(lams); | ||
295 | - loaderparams.ram_size = ram_size; | ||
296 | - loaderparams.kernel_filename = machine->kernel_filename; | ||
297 | - loaderparams.kernel_cmdline = machine->kernel_cmdline; | ||
298 | - loaderparams.initrd_filename = machine->initrd_filename; | ||
299 | - /* load the kernel. */ | ||
300 | - if (loaderparams.kernel_filename) { | ||
301 | - if (lams->bios_loaded) { | ||
302 | - loongarch_firmware_boot(lams, &loaderparams); | ||
303 | - } else { | ||
304 | - loongarch_direct_kernel_boot(lams, &loaderparams); | ||
305 | - } | ||
306 | - } | ||
307 | fdt_add_flash_node(lams); | ||
308 | - /* register reset function */ | ||
309 | - for (i = 0; i < machine->smp.cpus; i++) { | ||
310 | - lacpu = LOONGARCH_CPU(qemu_get_cpu(i)); | ||
311 | - qemu_register_reset(reset_load_elf, lacpu); | ||
312 | - } | ||
313 | + | ||
314 | /* Initialize the IO interrupt subsystem */ | ||
315 | loongarch_irq_init(lams); | ||
316 | fdt_add_irqchip_node(lams); | ||
317 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | ||
318 | */ | ||
319 | fdt_base = 1 * MiB; | ||
320 | qemu_fdt_dumpdtb(machine->fdt, lams->fdt_size); | ||
321 | - rom_add_blob_fixed("fdt", machine->fdt, lams->fdt_size, fdt_base); | ||
322 | + rom_add_blob_fixed_as("fdt", machine->fdt, lams->fdt_size, fdt_base, | ||
323 | + &address_space_memory); | ||
324 | + qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, | ||
325 | + rom_ptr_for_as(&address_space_memory, fdt_base, lams->fdt_size)); | ||
326 | + | ||
327 | + lams->bootinfo.ram_size = ram_size; | ||
328 | + loongarch_load_kernel(machine, &lams->bootinfo); | ||
329 | } | ||
330 | |||
331 | bool loongarch_is_acpi_enabled(LoongArchMachineState *lams) | ||
332 | diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h | ||
333 | new file mode 100644 | ||
334 | index XXXXXXX..XXXXXXX | ||
335 | --- /dev/null | ||
336 | +++ b/include/hw/loongarch/boot.h | ||
337 | @@ -XXX,XX +XXX,XX @@ | ||
338 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
339 | +/* | ||
340 | + * Definitions for LoongArch boot. | ||
341 | + * | ||
342 | + * Copyright (C) 2023 Loongson Technology Corporation Limited | ||
343 | + */ | ||
344 | + | ||
345 | +#ifndef HW_LOONGARCH_BOOT_H | ||
346 | +#define HW_LOONGARCH_BOOT_H | ||
347 | + | ||
348 | +struct loongarch_boot_info { | ||
349 | + uint64_t ram_size; | ||
350 | + const char *kernel_filename; | ||
351 | + const char *kernel_cmdline; | ||
352 | + const char *initrd_filename; | ||
353 | + uint64_t a0, a1, a2; | ||
354 | +}; | 94 | +}; |
355 | + | 95 | + |
356 | +void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info); | 96 | +static const VMStateDescription vmstate_loongarch_pic_common = { |
357 | + | 97 | + .name = "loongarch_pch_pic", |
358 | +#endif /* HW_LOONGARCH_BOOT_H */ | 98 | + .version_id = 1, |
359 | diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h | 99 | + .minimum_version_id = 1, |
360 | index XXXXXXX..XXXXXXX 100644 | 100 | + .fields = (const VMStateField[]) { |
361 | --- a/include/hw/loongarch/virt.h | 101 | + VMSTATE_UINT64(int_mask, LoongArchPICCommonState), |
362 | +++ b/include/hw/loongarch/virt.h | 102 | + VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState), |
363 | @@ -XXX,XX +XXX,XX @@ | 103 | + VMSTATE_UINT64(intedge, LoongArchPICCommonState), |
364 | #include "qemu/queue.h" | 104 | + VMSTATE_UINT64(intclr, LoongArchPICCommonState), |
365 | #include "hw/intc/loongarch_ipi.h" | 105 | + VMSTATE_UINT64(auto_crtl0, LoongArchPICCommonState), |
366 | #include "hw/block/flash.h" | 106 | + VMSTATE_UINT64(auto_crtl1, LoongArchPICCommonState), |
367 | +#include "hw/loongarch/boot.h" | 107 | + VMSTATE_UINT8_ARRAY(route_entry, LoongArchPICCommonState, 64), |
368 | 108 | + VMSTATE_UINT8_ARRAY(htmsi_vector, LoongArchPICCommonState, 64), | |
369 | #define LOONGARCH_MAX_CPUS 256 | 109 | + VMSTATE_UINT64(last_intirr, LoongArchPICCommonState), |
370 | 110 | + VMSTATE_UINT64(intirr, LoongArchPICCommonState), | |
371 | @@ -XXX,XX +XXX,XX @@ struct LoongArchMachineState { | 111 | + VMSTATE_UINT64(intisr, LoongArchPICCommonState), |
372 | MemoryRegion system_iocsr; | 112 | + VMSTATE_UINT64(int_polarity, LoongArchPICCommonState), |
373 | MemoryRegion iocsr_mem; | 113 | + VMSTATE_END_OF_LIST() |
374 | AddressSpace as_iocsr; | 114 | + } |
375 | + struct loongarch_boot_info bootinfo; | 115 | +}; |
376 | }; | ||
377 | |||
378 | #define TYPE_LOONGARCH_MACHINE MACHINE_TYPE_NAME("virt") | ||
379 | -- | 116 | -- |
380 | 2.25.1 | 117 | 2.43.5 |
381 | |||
382 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | we load initrd ramdisk after kernel_high address | ||
2 | 1 | ||
3 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
5 | Message-Id: <20240426091551.2397867-3-gaosong@loongson.cn> | ||
6 | --- | ||
7 | hw/loongarch/boot.c | 29 ++++++++++++++++++++++++++++- | ||
8 | 1 file changed, 28 insertions(+), 1 deletion(-) | ||
9 | |||
10 | diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/hw/loongarch/boot.c | ||
13 | +++ b/hw/loongarch/boot.c | ||
14 | @@ -XXX,XX +XXX,XX @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr) | ||
15 | |||
16 | static int64_t load_kernel_info(struct loongarch_boot_info *info) | ||
17 | { | ||
18 | - uint64_t kernel_entry, kernel_low, kernel_high; | ||
19 | + uint64_t kernel_entry, kernel_low, kernel_high, initrd_size; | ||
20 | + ram_addr_t initrd_offset; | ||
21 | ssize_t kernel_size; | ||
22 | |||
23 | kernel_size = load_elf(info->kernel_filename, NULL, | ||
24 | @@ -XXX,XX +XXX,XX @@ static int64_t load_kernel_info(struct loongarch_boot_info *info) | ||
25 | load_elf_strerror(kernel_size)); | ||
26 | exit(1); | ||
27 | } | ||
28 | + | ||
29 | + if (info->initrd_filename) { | ||
30 | + initrd_size = get_image_size(info->initrd_filename); | ||
31 | + if (initrd_size > 0) { | ||
32 | + initrd_offset = ROUND_UP(kernel_high + 4 * kernel_size, 64 * KiB); | ||
33 | + | ||
34 | + if (initrd_offset + initrd_size > info->ram_size) { | ||
35 | + error_report("memory too small for initial ram disk '%s'", | ||
36 | + info->initrd_filename); | ||
37 | + exit(1); | ||
38 | + } | ||
39 | + | ||
40 | + initrd_size = load_image_targphys(info->initrd_filename, initrd_offset, | ||
41 | + info->ram_size - initrd_offset); | ||
42 | + } | ||
43 | + | ||
44 | + if (initrd_size == (target_ulong)-1) { | ||
45 | + error_report("could not load initial ram disk '%s'", | ||
46 | + info->initrd_filename); | ||
47 | + exit(1); | ||
48 | + } | ||
49 | + } else { | ||
50 | + error_report("Need initrd!"); | ||
51 | + exit(1); | ||
52 | + } | ||
53 | + | ||
54 | return kernel_entry; | ||
55 | } | ||
56 | |||
57 | -- | ||
58 | 2.25.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Load the slave CPU boot code at pflash0 and set | ||
2 | the slave CPU elf_address to VIRT_FLASH0_BASE. | ||
3 | 1 | ||
4 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
5 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
6 | Message-Id: <20240426091551.2397867-4-gaosong@loongson.cn> | ||
7 | --- | ||
8 | hw/loongarch/boot.c | 62 ++++++++++++++++++++++++++++++++++++++++++++- | ||
9 | 1 file changed, 61 insertions(+), 1 deletion(-) | ||
10 | |||
11 | diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/hw/loongarch/boot.c | ||
14 | +++ b/hw/loongarch/boot.c | ||
15 | @@ -XXX,XX +XXX,XX @@ | ||
16 | #include "sysemu/reset.h" | ||
17 | #include "sysemu/qtest.h" | ||
18 | |||
19 | +static const unsigned int slave_boot_code[] = { | ||
20 | + /* Configure reset ebase. */ | ||
21 | + 0x0400302c, /* csrwr $t0, LOONGARCH_CSR_EENTRY */ | ||
22 | + | ||
23 | + /* Disable interrupt. */ | ||
24 | + 0x0380100c, /* ori $t0, $zero,0x4 */ | ||
25 | + 0x04000180, /* csrxchg $zero, $t0, LOONGARCH_CSR_CRMD */ | ||
26 | + | ||
27 | + /* Clear mailbox. */ | ||
28 | + 0x1400002d, /* lu12i.w $t1, 1(0x1) */ | ||
29 | + 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */ | ||
30 | + 0x06481da0, /* iocsrwr.d $zero, $t1 */ | ||
31 | + | ||
32 | + /* Enable IPI interrupt. */ | ||
33 | + 0x1400002c, /* lu12i.w $t0, 1(0x1) */ | ||
34 | + 0x0400118c, /* csrxchg $t0, $t0, LOONGARCH_CSR_ECFG */ | ||
35 | + 0x02fffc0c, /* addi.d $t0, $r0,-1(0xfff) */ | ||
36 | + 0x1400002d, /* lu12i.w $t1, 1(0x1) */ | ||
37 | + 0x038011ad, /* ori $t1, $t1, CORE_EN_OFF */ | ||
38 | + 0x064819ac, /* iocsrwr.w $t0, $t1 */ | ||
39 | + 0x1400002d, /* lu12i.w $t1, 1(0x1) */ | ||
40 | + 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */ | ||
41 | + | ||
42 | + /* Wait for wakeup <.L11>: */ | ||
43 | + 0x06488000, /* idle 0x0 */ | ||
44 | + 0x03400000, /* andi $zero, $zero, 0x0 */ | ||
45 | + 0x064809ac, /* iocsrrd.w $t0, $t1 */ | ||
46 | + 0x43fff59f, /* beqz $t0, -12(0x7ffff4) # 48 <.L11> */ | ||
47 | + | ||
48 | + /* Read and clear IPI interrupt. */ | ||
49 | + 0x1400002d, /* lu12i.w $t1, 1(0x1) */ | ||
50 | + 0x064809ac, /* iocsrrd.w $t0, $t1 */ | ||
51 | + 0x1400002d, /* lu12i.w $t1, 1(0x1) */ | ||
52 | + 0x038031ad, /* ori $t1, $t1, CORE_CLEAR_OFF */ | ||
53 | + 0x064819ac, /* iocsrwr.w $t0, $t1 */ | ||
54 | + | ||
55 | + /* Disable IPI interrupt. */ | ||
56 | + 0x1400002c, /* lu12i.w $t0, 1(0x1) */ | ||
57 | + 0x04001180, /* csrxchg $zero, $t0, LOONGARCH_CSR_ECFG */ | ||
58 | + | ||
59 | + /* Read mail buf and jump to specified entry */ | ||
60 | + 0x1400002d, /* lu12i.w $t1, 1(0x1) */ | ||
61 | + 0x038081ad, /* ori $t1, $t1, CORE_BUF_20 */ | ||
62 | + 0x06480dac, /* iocsrrd.d $t0, $t1 */ | ||
63 | + 0x00150181, /* move $ra, $t0 */ | ||
64 | + 0x4c000020, /* jirl $zero, $ra,0 */ | ||
65 | +}; | ||
66 | + | ||
67 | static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr) | ||
68 | { | ||
69 | return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS); | ||
70 | @@ -XXX,XX +XXX,XX @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info) | ||
71 | } | ||
72 | } | ||
73 | |||
74 | + /* Load slave boot code at pflash0 . */ | ||
75 | + void *boot_code = g_malloc0(VIRT_FLASH0_SIZE); | ||
76 | + memcpy(boot_code, &slave_boot_code, sizeof(slave_boot_code)); | ||
77 | + rom_add_blob_fixed("boot_code", boot_code, VIRT_FLASH0_SIZE, VIRT_FLASH0_BASE); | ||
78 | + | ||
79 | CPU_FOREACH(cs) { | ||
80 | lacpu = LOONGARCH_CPU(cs); | ||
81 | lacpu->env.load_elf = true; | ||
82 | - lacpu->env.elf_address = kernel_addr; | ||
83 | + if (cs == first_cpu) { | ||
84 | + lacpu->env.elf_address = kernel_addr; | ||
85 | + } else { | ||
86 | + lacpu->env.elf_address = VIRT_FLASH0_BASE; | ||
87 | + } | ||
88 | + lacpu->env.boot_info = info; | ||
89 | } | ||
90 | + | ||
91 | + g_free(boot_code); | ||
92 | } | ||
93 | |||
94 | void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info) | ||
95 | -- | ||
96 | 2.25.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Add init_cmline and set boot_info->a0, a1 | ||
2 | 1 | ||
3 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
5 | Message-Id: <20240426091551.2397867-5-gaosong@loongson.cn> | ||
6 | --- | ||
7 | hw/loongarch/boot.c | 30 ++++++++++++++++++++++++++++++ | ||
8 | include/hw/loongarch/virt.h | 2 ++ | ||
9 | target/loongarch/cpu.h | 2 ++ | ||
10 | 3 files changed, 34 insertions(+) | ||
11 | |||
12 | diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/hw/loongarch/boot.c | ||
15 | +++ b/hw/loongarch/boot.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static const unsigned int slave_boot_code[] = { | ||
17 | 0x4c000020, /* jirl $zero, $ra,0 */ | ||
18 | }; | ||
19 | |||
20 | +static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start) | ||
21 | +{ | ||
22 | + hwaddr cmdline_addr = (hwaddr)p - (hwaddr)start; | ||
23 | + | ||
24 | + info->a0 = 1; | ||
25 | + info->a1 = cmdline_addr; | ||
26 | + | ||
27 | + memcpy(p, info->kernel_cmdline, COMMAND_LINE_SIZE); | ||
28 | +} | ||
29 | + | ||
30 | static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr) | ||
31 | { | ||
32 | return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS); | ||
33 | @@ -XXX,XX +XXX,XX @@ static void reset_load_elf(void *opaque) | ||
34 | |||
35 | cpu_reset(CPU(cpu)); | ||
36 | if (env->load_elf) { | ||
37 | + if (cpu == LOONGARCH_CPU(first_cpu)) { | ||
38 | + env->gpr[4] = env->boot_info->a0; | ||
39 | + env->gpr[5] = env->boot_info->a1; | ||
40 | + } | ||
41 | cpu_set_pc(CPU(cpu), env->elf_address); | ||
42 | } | ||
43 | } | ||
44 | @@ -XXX,XX +XXX,XX @@ static void loongarch_firmware_boot(LoongArchMachineState *lams, | ||
45 | fw_cfg_add_kernel_info(info, lams->fw_cfg); | ||
46 | } | ||
47 | |||
48 | +static void init_boot_rom(struct loongarch_boot_info *info, void *p) | ||
49 | +{ | ||
50 | + void *start = p; | ||
51 | + | ||
52 | + init_cmdline(info, p, start); | ||
53 | + p += COMMAND_LINE_SIZE; | ||
54 | +} | ||
55 | + | ||
56 | static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info) | ||
57 | { | ||
58 | + void *p, *bp; | ||
59 | int64_t kernel_addr = 0; | ||
60 | LoongArchCPU *lacpu; | ||
61 | CPUState *cs; | ||
62 | @@ -XXX,XX +XXX,XX @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info) | ||
63 | } | ||
64 | } | ||
65 | |||
66 | + /* Load cmdline and system tables at [0 - 1 MiB] */ | ||
67 | + p = g_malloc0(1 * MiB); | ||
68 | + bp = p; | ||
69 | + init_boot_rom(info, p); | ||
70 | + rom_add_blob_fixed_as("boot_info", bp, 1 * MiB, 0, &address_space_memory); | ||
71 | + | ||
72 | /* Load slave boot code at pflash0 . */ | ||
73 | void *boot_code = g_malloc0(VIRT_FLASH0_SIZE); | ||
74 | memcpy(boot_code, &slave_boot_code, sizeof(slave_boot_code)); | ||
75 | @@ -XXX,XX +XXX,XX @@ static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info) | ||
76 | } | ||
77 | |||
78 | g_free(boot_code); | ||
79 | + g_free(bp); | ||
80 | } | ||
81 | |||
82 | void loongarch_load_kernel(MachineState *ms, struct loongarch_boot_info *info) | ||
83 | diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/include/hw/loongarch/virt.h | ||
86 | +++ b/include/hw/loongarch/virt.h | ||
87 | @@ -XXX,XX +XXX,XX @@ | ||
88 | #define VIRT_GED_MEM_ADDR (VIRT_GED_EVT_ADDR + ACPI_GED_EVT_SEL_LEN) | ||
89 | #define VIRT_GED_REG_ADDR (VIRT_GED_MEM_ADDR + MEMORY_HOTPLUG_IO_LEN) | ||
90 | |||
91 | +#define COMMAND_LINE_SIZE 512 | ||
92 | + | ||
93 | struct LoongArchMachineState { | ||
94 | /*< private >*/ | ||
95 | MachineState parent_obj; | ||
96 | diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/target/loongarch/cpu.h | ||
99 | +++ b/target/loongarch/cpu.h | ||
100 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState { | ||
101 | uint32_t mp_state; | ||
102 | /* Store ipistate to access from this struct */ | ||
103 | DeviceState *ipistate; | ||
104 | + | ||
105 | + struct loongarch_boot_info *boot_info; | ||
106 | #endif | ||
107 | } CPULoongArchState; | ||
108 | |||
109 | -- | ||
110 | 2.25.1 | diff view generated by jsdifflib |
1 | Add init_systab and set boot_info->a2 | 1 | Set TYPE_LOONGARCH_PIC inherit from TYPE_LOONGARCH_PIC_COMMON object, |
---|---|---|---|
2 | it shares vmsate and property of TYPE_LOONGARCH_PIC_COMMON, and has | ||
3 | its own realize() function. | ||
2 | 4 | ||
3 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | Message-Id: <20240426091551.2397867-6-gaosong@loongson.cn> | ||
6 | --- | 7 | --- |
7 | hw/loongarch/boot.c | 22 +++++++++++++++++ | 8 | hw/intc/loongarch_pch_pic.c | 38 ++++++++++++-------------- |
8 | include/hw/loongarch/boot.h | 48 +++++++++++++++++++++++++++++++++++++ | 9 | hw/intc/loongarch_pic_common.c | 32 +++++++++++++++++++++- |
9 | 2 files changed, 70 insertions(+) | 10 | hw/intc/meson.build | 2 +- |
11 | include/hw/intc/loongarch_pch_pic.h | 21 +++++++++++--- | ||
12 | include/hw/intc/loongarch_pic_common.h | 10 +++++++ | ||
13 | 5 files changed, 77 insertions(+), 26 deletions(-) | ||
10 | 14 | ||
11 | diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c | 15 | diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c |
12 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/hw/loongarch/boot.c | 17 | --- a/hw/intc/loongarch_pch_pic.c |
14 | +++ b/hw/loongarch/boot.c | 18 | +++ b/hw/intc/loongarch_pch_pic.c |
15 | @@ -XXX,XX +XXX,XX @@ static const unsigned int slave_boot_code[] = { | 19 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_reset(DeviceState *d) |
16 | 0x4c000020, /* jirl $zero, $ra,0 */ | 20 | s->int_polarity = 0x0; |
21 | } | ||
22 | |||
23 | -#include "loongarch_pic_common.c" | ||
24 | -static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) | ||
25 | +static void loongarch_pic_realize(DeviceState *dev, Error **errp) | ||
26 | { | ||
27 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(dev); | ||
28 | - SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
29 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(dev); | ||
30 | + LoongarchPICClass *lpc = LOONGARCH_PIC_GET_CLASS(dev); | ||
31 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
32 | Error *local_err = NULL; | ||
33 | |||
34 | - loongarch_pic_common_realize(dev, &local_err); | ||
35 | + lpc->parent_realize(dev, &local_err); | ||
36 | if (local_err) { | ||
37 | error_propagate(errp, local_err); | ||
38 | return; | ||
39 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_realize(DeviceState *dev, Error **errp) | ||
40 | |||
41 | } | ||
42 | |||
43 | -static void loongarch_pch_pic_class_init(ObjectClass *klass, void *data) | ||
44 | +static void loongarch_pic_class_init(ObjectClass *klass, void *data) | ||
45 | { | ||
46 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
47 | + LoongarchPICClass *lpc = LOONGARCH_PIC_CLASS(klass); | ||
48 | |||
49 | - dc->realize = loongarch_pch_pic_realize; | ||
50 | device_class_set_legacy_reset(dc, loongarch_pch_pic_reset); | ||
51 | - dc->vmsd = &vmstate_loongarch_pic_common; | ||
52 | - device_class_set_props(dc, loongarch_pic_common_properties); | ||
53 | + device_class_set_parent_realize(dc, loongarch_pic_realize, | ||
54 | + &lpc->parent_realize); | ||
55 | } | ||
56 | |||
57 | -static const TypeInfo loongarch_pch_pic_info = { | ||
58 | - .name = TYPE_LOONGARCH_PCH_PIC, | ||
59 | - .parent = TYPE_SYS_BUS_DEVICE, | ||
60 | - .instance_size = sizeof(LoongArchPCHPIC), | ||
61 | - .class_init = loongarch_pch_pic_class_init, | ||
62 | +static const TypeInfo loongarch_pic_types[] = { | ||
63 | + { | ||
64 | + .name = TYPE_LOONGARCH_PIC, | ||
65 | + .parent = TYPE_LOONGARCH_PIC_COMMON, | ||
66 | + .instance_size = sizeof(LoongarchPICState), | ||
67 | + .class_size = sizeof(LoongarchPICClass), | ||
68 | + .class_init = loongarch_pic_class_init, | ||
69 | + } | ||
17 | }; | 70 | }; |
18 | 71 | ||
19 | +static void init_systab(struct loongarch_boot_info *info, void *p, void *start) | 72 | -static void loongarch_pch_pic_register_types(void) |
73 | -{ | ||
74 | - type_register_static(&loongarch_pch_pic_info); | ||
75 | -} | ||
76 | - | ||
77 | -type_init(loongarch_pch_pic_register_types) | ||
78 | +DEFINE_TYPES(loongarch_pic_types) | ||
79 | diff --git a/hw/intc/loongarch_pic_common.c b/hw/intc/loongarch_pic_common.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/hw/intc/loongarch_pic_common.c | ||
82 | +++ b/hw/intc/loongarch_pic_common.c | ||
83 | @@ -XXX,XX +XXX,XX @@ | ||
84 | * Copyright (C) 2024 Loongson Technology Corporation Limited | ||
85 | */ | ||
86 | |||
87 | +#include "qemu/osdep.h" | ||
88 | +#include "qapi/error.h" | ||
89 | +#include "hw/intc/loongarch_pic_common.h" | ||
90 | +#include "hw/qdev-properties.h" | ||
91 | +#include "migration/vmstate.h" | ||
92 | + | ||
93 | static void loongarch_pic_common_realize(DeviceState *dev, Error **errp) | ||
94 | { | ||
95 | - LoongArchPICCommonState *s = LOONGARCH_PCH_PIC(dev); | ||
96 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(dev); | ||
97 | |||
98 | if (!s->irq_num || s->irq_num > VIRT_PCH_PIC_IRQ_NUM) { | ||
99 | error_setg(errp, "Invalid 'pic_irq_num'"); | ||
100 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongarch_pic_common = { | ||
101 | VMSTATE_END_OF_LIST() | ||
102 | } | ||
103 | }; | ||
104 | + | ||
105 | +static void loongarch_pic_common_class_init(ObjectClass *klass, void *data) | ||
20 | +{ | 106 | +{ |
21 | + struct efi_system_table *systab = p; | 107 | + DeviceClass *dc = DEVICE_CLASS(klass); |
108 | + LoongArchPICCommonClass *lpcc = LOONGARCH_PIC_COMMON_CLASS(klass); | ||
22 | + | 109 | + |
23 | + info->a2 = (uint64_t)p - (uint64_t)start; | 110 | + device_class_set_parent_realize(dc, loongarch_pic_common_realize, |
24 | + | 111 | + &lpcc->parent_realize); |
25 | + systab->hdr.signature = EFI_SYSTEM_TABLE_SIGNATURE; | 112 | + device_class_set_props(dc, loongarch_pic_common_properties); |
26 | + systab->hdr.revision = EFI_SPECIFICATION_VERSION; | 113 | + dc->vmsd = &vmstate_loongarch_pic_common; |
27 | + systab->hdr.revision = sizeof(struct efi_system_table), | ||
28 | + systab->fw_revision = FW_VERSION << 16 | FW_PATCHLEVEL << 8; | ||
29 | + systab->runtime = 0; | ||
30 | + systab->boottime = 0; | ||
31 | + systab->nr_tables = 0; | ||
32 | + | ||
33 | + p += ROUND_UP(sizeof(struct efi_system_table), 64 * KiB); | ||
34 | + | ||
35 | + systab->tables = p; | ||
36 | +} | 114 | +} |
37 | + | 115 | + |
38 | static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start) | 116 | +static const TypeInfo loongarch_pic_common_types[] = { |
39 | { | 117 | + { |
40 | hwaddr cmdline_addr = (hwaddr)p - (hwaddr)start; | 118 | + .name = TYPE_LOONGARCH_PIC_COMMON, |
41 | @@ -XXX,XX +XXX,XX @@ static void reset_load_elf(void *opaque) | 119 | + .parent = TYPE_SYS_BUS_DEVICE, |
42 | if (cpu == LOONGARCH_CPU(first_cpu)) { | 120 | + .instance_size = sizeof(LoongArchPICCommonState), |
43 | env->gpr[4] = env->boot_info->a0; | 121 | + .class_size = sizeof(LoongArchPICCommonClass), |
44 | env->gpr[5] = env->boot_info->a1; | 122 | + .class_init = loongarch_pic_common_class_init, |
45 | + env->gpr[6] = env->boot_info->a2; | 123 | + .abstract = true, |
46 | } | 124 | + } |
47 | cpu_set_pc(CPU(cpu), env->elf_address); | ||
48 | } | ||
49 | @@ -XXX,XX +XXX,XX @@ static void init_boot_rom(struct loongarch_boot_info *info, void *p) | ||
50 | |||
51 | init_cmdline(info, p, start); | ||
52 | p += COMMAND_LINE_SIZE; | ||
53 | + | ||
54 | + init_systab(info, p, start); | ||
55 | } | ||
56 | |||
57 | static void loongarch_direct_kernel_boot(struct loongarch_boot_info *info) | ||
58 | diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/include/hw/loongarch/boot.h | ||
61 | +++ b/include/hw/loongarch/boot.h | ||
62 | @@ -XXX,XX +XXX,XX @@ | ||
63 | #ifndef HW_LOONGARCH_BOOT_H | ||
64 | #define HW_LOONGARCH_BOOT_H | ||
65 | |||
66 | +/* UEFI 2.10 */ | ||
67 | +#define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249 | ||
68 | +#define EFI_2_100_SYSTEM_TABLE_REVISION ((2<<16) | (100)) | ||
69 | +#define EFI_SPECIFICATION_VERSION EFI_SYSTEM_TABLE_REVISION | ||
70 | +#define EFI_SYSTEM_TABLE_REVISION EFI_2_100_SYSTEM_TABLE_REVISION | ||
71 | + | ||
72 | +#define FW_VERSION 0x1 | ||
73 | +#define FW_PATCHLEVEL 0x0 | ||
74 | + | ||
75 | +typedef struct { | ||
76 | + uint8_t b[16]; | ||
77 | +} efi_guid_t QEMU_ALIGNED(8); | ||
78 | + | ||
79 | +struct efi_config_table { | ||
80 | + efi_guid_t guid; | ||
81 | + uint64_t *ptr; | ||
82 | + const char name[16]; | ||
83 | +}; | 125 | +}; |
84 | + | 126 | + |
85 | +typedef struct { | 127 | +DEFINE_TYPES(loongarch_pic_common_types) |
86 | + uint64_t signature; | 128 | diff --git a/hw/intc/meson.build b/hw/intc/meson.build |
87 | + uint32_t revision; | 129 | index XXXXXXX..XXXXXXX 100644 |
88 | + uint32_t headersize; | 130 | --- a/hw/intc/meson.build |
89 | + uint32_t crc32; | 131 | +++ b/hw/intc/meson.build |
90 | + uint32_t reserved; | 132 | @@ -XXX,XX +XXX,XX @@ specific_ss.add(when: 'CONFIG_M68K_IRQC', if_true: files('m68k_irqc.c')) |
91 | +} efi_table_hdr_t; | 133 | specific_ss.add(when: 'CONFIG_LOONGSON_IPI_COMMON', if_true: files('loongson_ipi_common.c')) |
134 | specific_ss.add(when: 'CONFIG_LOONGSON_IPI', if_true: files('loongson_ipi.c')) | ||
135 | specific_ss.add(when: 'CONFIG_LOONGARCH_IPI', if_true: files('loongarch_ipi.c')) | ||
136 | -specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c')) | ||
137 | +specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_PIC', if_true: files('loongarch_pch_pic.c', 'loongarch_pic_common.c')) | ||
138 | specific_ss.add(when: 'CONFIG_LOONGARCH_PCH_MSI', if_true: files('loongarch_pch_msi.c')) | ||
139 | specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch_extioi.c')) | ||
140 | diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h | ||
141 | index XXXXXXX..XXXXXXX 100644 | ||
142 | --- a/include/hw/intc/loongarch_pch_pic.h | ||
143 | +++ b/include/hw/intc/loongarch_pch_pic.h | ||
144 | @@ -XXX,XX +XXX,XX @@ | ||
145 | |||
146 | #include "hw/intc/loongarch_pic_common.h" | ||
147 | |||
148 | -#define LoongArchPCHPIC LoongArchPICCommonState | ||
149 | -#define TYPE_LOONGARCH_PCH_PIC "loongarch_pch_pic" | ||
150 | -#define PCH_PIC_NAME(name) TYPE_LOONGARCH_PCH_PIC#name | ||
151 | -OBJECT_DECLARE_SIMPLE_TYPE(LoongArchPCHPIC, LOONGARCH_PCH_PIC) | ||
152 | +#define TYPE_LOONGARCH_PIC "loongarch_pic" | ||
153 | +#define PCH_PIC_NAME(name) TYPE_LOONGARCH_PIC#name | ||
154 | +OBJECT_DECLARE_TYPE(LoongarchPICState, LoongarchPICClass, LOONGARCH_PIC) | ||
92 | + | 155 | + |
93 | +struct efi_configuration_table { | 156 | +struct LoongarchPICState { |
94 | + efi_guid_t guid; | 157 | + LoongArchPICCommonState parent_obj; |
95 | + void *table; | ||
96 | +}; | 158 | +}; |
97 | + | 159 | + |
98 | +struct efi_system_table { | 160 | +struct LoongarchPICClass { |
99 | + efi_table_hdr_t hdr; | 161 | + LoongArchPICCommonClass parent_class; |
100 | + uint64_t fw_vendor; /* physical addr of CHAR16 vendor string */ | 162 | + |
101 | + uint32_t fw_revision; | 163 | + DeviceRealize parent_realize; |
102 | + uint64_t con_in_handle; | ||
103 | + uint64_t *con_in; | ||
104 | + uint64_t con_out_handle; | ||
105 | + uint64_t *con_out; | ||
106 | + uint64_t stderr_handle; | ||
107 | + uint64_t stderr_placeholder; | ||
108 | + uint64_t *runtime; | ||
109 | + uint64_t *boottime; | ||
110 | + uint64_t nr_tables; | ||
111 | + struct efi_configuration_table *tables; | ||
112 | +}; | 164 | +}; |
113 | + | 165 | + |
114 | struct loongarch_boot_info { | 166 | +#define TYPE_LOONGARCH_PCH_PIC TYPE_LOONGARCH_PIC |
115 | uint64_t ram_size; | 167 | +typedef struct LoongArchPICCommonState LoongArchPCHPIC; |
116 | const char *kernel_filename; | 168 | +#define LOONGARCH_PCH_PIC(obj) ((struct LoongArchPICCommonState *)(obj)) |
169 | |||
170 | #endif /* HW_LOONGARCH_PCH_PIC_H */ | ||
171 | diff --git a/include/hw/intc/loongarch_pic_common.h b/include/hw/intc/loongarch_pic_common.h | ||
172 | index XXXXXXX..XXXXXXX 100644 | ||
173 | --- a/include/hw/intc/loongarch_pic_common.h | ||
174 | +++ b/include/hw/intc/loongarch_pic_common.h | ||
175 | @@ -XXX,XX +XXX,XX @@ | ||
176 | #define POL_LO_START 0x40 | ||
177 | #define POL_HI_START 0x44 | ||
178 | |||
179 | +#define TYPE_LOONGARCH_PIC_COMMON "loongarch_pic_common" | ||
180 | +OBJECT_DECLARE_TYPE(LoongArchPICCommonState, | ||
181 | + LoongArchPICCommonClass, LOONGARCH_PIC_COMMON) | ||
182 | + | ||
183 | struct LoongArchPICCommonState { | ||
184 | SysBusDevice parent_obj; | ||
185 | |||
186 | @@ -XXX,XX +XXX,XX @@ struct LoongArchPICCommonState { | ||
187 | MemoryRegion iomem8; | ||
188 | unsigned int irq_num; | ||
189 | }; | ||
190 | + | ||
191 | +struct LoongArchPICCommonClass { | ||
192 | + SysBusDeviceClass parent_class; | ||
193 | + | ||
194 | + DeviceRealize parent_realize; | ||
195 | +}; | ||
196 | #endif /* HW_LOONGARCH_PIC_COMMON_H */ | ||
117 | -- | 197 | -- |
118 | 2.25.1 | 198 | 2.43.5 | diff view generated by jsdifflib |
1 | The efi_system_table adds a efi_boot_memmap configuration table. | 1 | Add vmstate pre_save and post_load interfaces, which can be used |
---|---|---|---|
2 | by pic kvm driver in future. | ||
2 | 3 | ||
3 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 5 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | Message-Id: <20240426091551.2397867-7-gaosong@loongson.cn> | ||
6 | --- | 6 | --- |
7 | hw/loongarch/boot.c | 40 +++++++++++++++++++++++++++++++++++++ | 7 | hw/intc/loongarch_pic_common.c | 26 ++++++++++++++++++++++++++ |
8 | hw/loongarch/virt.c | 11 ++-------- | 8 | include/hw/intc/loongarch_pic_common.h | 2 ++ |
9 | include/hw/loongarch/boot.h | 27 +++++++++++++++++++++++++ | 9 | 2 files changed, 28 insertions(+) |
10 | include/hw/loongarch/virt.h | 10 ++++++++++ | ||
11 | 4 files changed, 79 insertions(+), 9 deletions(-) | ||
12 | 10 | ||
13 | diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c | 11 | diff --git a/hw/intc/loongarch_pic_common.c b/hw/intc/loongarch_pic_common.c |
14 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/loongarch/boot.c | 13 | --- a/hw/intc/loongarch_pic_common.c |
16 | +++ b/hw/loongarch/boot.c | 14 | +++ b/hw/intc/loongarch_pic_common.c |
17 | @@ -XXX,XX +XXX,XX @@ static const unsigned int slave_boot_code[] = { | 15 | @@ -XXX,XX +XXX,XX @@ |
18 | 0x4c000020, /* jirl $zero, $ra,0 */ | 16 | #include "hw/qdev-properties.h" |
19 | }; | 17 | #include "migration/vmstate.h" |
20 | 18 | ||
21 | +static inline void *guidcpy(void *dst, const void *src) | 19 | +static int loongarch_pic_pre_save(void *opaque) |
22 | +{ | 20 | +{ |
23 | + return memcpy(dst, src, sizeof(efi_guid_t)); | 21 | + LoongArchPICCommonState *s = (LoongArchPICCommonState *)opaque; |
22 | + LoongArchPICCommonClass *lpcc = LOONGARCH_PIC_COMMON_GET_CLASS(s); | ||
23 | + | ||
24 | + if (lpcc->pre_save) { | ||
25 | + return lpcc->pre_save(s); | ||
26 | + } | ||
27 | + | ||
28 | + return 0; | ||
24 | +} | 29 | +} |
25 | + | 30 | + |
26 | +static void init_efi_boot_memmap(struct efi_system_table *systab, | 31 | +static int loongarch_pic_post_load(void *opaque, int version_id) |
27 | + void *p, void *start) | ||
28 | +{ | 32 | +{ |
29 | + unsigned i; | 33 | + LoongArchPICCommonState *s = (LoongArchPICCommonState *)opaque; |
30 | + struct efi_boot_memmap *boot_memmap = p; | 34 | + LoongArchPICCommonClass *lpcc = LOONGARCH_PIC_COMMON_GET_CLASS(s); |
31 | + efi_guid_t tbl_guid = LINUX_EFI_BOOT_MEMMAP_GUID; | ||
32 | + | 35 | + |
33 | + /* efi_configuration_table 1 */ | 36 | + if (lpcc->post_load) { |
34 | + guidcpy(&systab->tables[0].guid, &tbl_guid); | 37 | + return lpcc->post_load(s, version_id); |
35 | + systab->tables[0].table = (struct efi_configuration_table *)(p - start); | 38 | + } |
36 | + systab->nr_tables = 1; | ||
37 | + | 39 | + |
38 | + boot_memmap->desc_size = sizeof(efi_memory_desc_t); | 40 | + return 0; |
39 | + boot_memmap->desc_ver = 1; | ||
40 | + boot_memmap->map_size = 0; | ||
41 | + | ||
42 | + efi_memory_desc_t *map = p + sizeof(struct efi_boot_memmap); | ||
43 | + for (i = 0; i < memmap_entries; i++) { | ||
44 | + map = (void *)boot_memmap + sizeof(*map); | ||
45 | + map[i].type = memmap_table[i].type; | ||
46 | + map[i].phys_addr = ROUND_UP(memmap_table[i].address, 64 * KiB); | ||
47 | + map[i].num_pages = ROUND_DOWN(memmap_table[i].address + | ||
48 | + memmap_table[i].length - map[i].phys_addr, 64 * KiB); | ||
49 | + p += sizeof(efi_memory_desc_t); | ||
50 | + } | ||
51 | +} | 41 | +} |
52 | + | 42 | + |
53 | static void init_systab(struct loongarch_boot_info *info, void *p, void *start) | 43 | static void loongarch_pic_common_realize(DeviceState *dev, Error **errp) |
54 | { | 44 | { |
55 | + void *bp_tables_start; | 45 | LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(dev); |
56 | struct efi_system_table *systab = p; | 46 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_loongarch_pic_common = { |
57 | 47 | .name = "loongarch_pch_pic", | |
58 | info->a2 = (uint64_t)p - (uint64_t)start; | 48 | .version_id = 1, |
59 | @@ -XXX,XX +XXX,XX @@ static void init_systab(struct loongarch_boot_info *info, void *p, void *start) | 49 | .minimum_version_id = 1, |
60 | p += ROUND_UP(sizeof(struct efi_system_table), 64 * KiB); | 50 | + .pre_save = loongarch_pic_pre_save, |
61 | 51 | + .post_load = loongarch_pic_post_load, | |
62 | systab->tables = p; | 52 | .fields = (const VMStateField[]) { |
63 | + bp_tables_start = p; | 53 | VMSTATE_UINT64(int_mask, LoongArchPICCommonState), |
64 | + | 54 | VMSTATE_UINT64(htmsi_en, LoongArchPICCommonState), |
65 | + init_efi_boot_memmap(systab, p, start); | 55 | diff --git a/include/hw/intc/loongarch_pic_common.h b/include/hw/intc/loongarch_pic_common.h |
66 | + p += ROUND_UP(sizeof(struct efi_boot_memmap) + | ||
67 | + sizeof(efi_memory_desc_t) * memmap_entries, 64 * KiB); | ||
68 | + | ||
69 | + systab->tables = (struct efi_configuration_table *)(bp_tables_start - start); | ||
70 | } | ||
71 | |||
72 | static void init_cmdline(struct loongarch_boot_info *info, void *p, void *start) | ||
73 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | 56 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/hw/loongarch/virt.c | 57 | --- a/include/hw/intc/loongarch_pic_common.h |
76 | +++ b/hw/loongarch/virt.c | 58 | +++ b/include/hw/intc/loongarch_pic_common.h |
77 | @@ -XXX,XX +XXX,XX @@ static void virt_powerdown_req(Notifier *notifier, void *opaque) | 59 | @@ -XXX,XX +XXX,XX @@ struct LoongArchPICCommonClass { |
78 | acpi_send_event(s->acpi_ged, ACPI_POWER_DOWN_STATUS); | 60 | SysBusDeviceClass parent_class; |
79 | } | 61 | |
80 | 62 | DeviceRealize parent_realize; | |
81 | -struct memmap_entry { | 63 | + int (*pre_save)(LoongArchPICCommonState *s); |
82 | - uint64_t address; | 64 | + int (*post_load)(LoongArchPICCommonState *s, int version_id); |
83 | - uint64_t length; | ||
84 | - uint32_t type; | ||
85 | - uint32_t reserved; | ||
86 | -}; | ||
87 | - | ||
88 | -static struct memmap_entry *memmap_table; | ||
89 | -static unsigned memmap_entries; | ||
90 | +struct memmap_entry *memmap_table; | ||
91 | +unsigned memmap_entries; | ||
92 | |||
93 | static void memmap_add_entry(uint64_t address, uint64_t length, uint32_t type) | ||
94 | { | ||
95 | diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h | ||
96 | index XXXXXXX..XXXXXXX 100644 | ||
97 | --- a/include/hw/loongarch/boot.h | ||
98 | +++ b/include/hw/loongarch/boot.h | ||
99 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
100 | uint8_t b[16]; | ||
101 | } efi_guid_t QEMU_ALIGNED(8); | ||
102 | |||
103 | +#define EFI_GUID(a, b, c, d...) (efi_guid_t){ { \ | ||
104 | + (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \ | ||
105 | + (b) & 0xff, ((b) >> 8) & 0xff, \ | ||
106 | + (c) & 0xff, ((c) >> 8) & 0xff, d } } | ||
107 | + | ||
108 | +#define LINUX_EFI_BOOT_MEMMAP_GUID \ | ||
109 | + EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, \ | ||
110 | + 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4) | ||
111 | + | ||
112 | struct efi_config_table { | ||
113 | efi_guid_t guid; | ||
114 | uint64_t *ptr; | ||
115 | @@ -XXX,XX +XXX,XX @@ struct efi_system_table { | ||
116 | struct efi_configuration_table *tables; | ||
117 | }; | 65 | }; |
118 | 66 | #endif /* HW_LOONGARCH_PIC_COMMON_H */ | |
119 | +typedef struct { | ||
120 | + uint32_t type; | ||
121 | + uint32_t pad; | ||
122 | + uint64_t phys_addr; | ||
123 | + uint64_t virt_addr; | ||
124 | + uint64_t num_pages; | ||
125 | + uint64_t attribute; | ||
126 | +} efi_memory_desc_t; | ||
127 | + | ||
128 | +struct efi_boot_memmap { | ||
129 | + uint64_t map_size; | ||
130 | + uint64_t desc_size; | ||
131 | + uint32_t desc_ver; | ||
132 | + uint64_t map_key; | ||
133 | + uint64_t buff_size; | ||
134 | + efi_memory_desc_t map[32]; | ||
135 | +}; | ||
136 | + | ||
137 | struct loongarch_boot_info { | ||
138 | uint64_t ram_size; | ||
139 | const char *kernel_filename; | ||
140 | diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h | ||
141 | index XXXXXXX..XXXXXXX 100644 | ||
142 | --- a/include/hw/loongarch/virt.h | ||
143 | +++ b/include/hw/loongarch/virt.h | ||
144 | @@ -XXX,XX +XXX,XX @@ | ||
145 | |||
146 | #define COMMAND_LINE_SIZE 512 | ||
147 | |||
148 | +extern struct memmap_entry *memmap_table; | ||
149 | +extern unsigned memmap_entries; | ||
150 | + | ||
151 | +struct memmap_entry { | ||
152 | + uint64_t address; | ||
153 | + uint64_t length; | ||
154 | + uint32_t type; | ||
155 | + uint32_t reserved; | ||
156 | +}; | ||
157 | + | ||
158 | struct LoongArchMachineState { | ||
159 | /*< private >*/ | ||
160 | MachineState parent_obj; | ||
161 | -- | 67 | -- |
162 | 2.25.1 | 68 | 2.43.5 | diff view generated by jsdifflib |
1 | fdt adds pch msi controller, we use 'loongson,pch-msi-1.0'. | 1 | Remove definition about LoongArchPCHPIC and LOONGARCH_PCH_PIC, and |
---|---|---|---|
2 | replace them with LoongArchPICCommonState and LOONGARCH_PIC_COMMON | ||
3 | separately. Also remove unnecessary header files. | ||
2 | 4 | ||
3 | See: | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongson-pch-msi.c | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | https://lore.kernel.org/r/20200528152757.1028711-6-jiaxun.yang@flygoat.com | 7 | --- |
8 | hw/intc/loongarch_pch_pic.c | 24 ++++++++++-------------- | ||
9 | hw/loongarch/virt.c | 2 +- | ||
10 | include/hw/intc/loongarch_pch_pic.h | 4 ---- | ||
11 | 3 files changed, 11 insertions(+), 19 deletions(-) | ||
6 | 12 | ||
7 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 13 | diff --git a/hw/intc/loongarch_pch_pic.c b/hw/intc/loongarch_pch_pic.c |
8 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 14 | index XXXXXXX..XXXXXXX 100644 |
9 | Message-Id: <20240426091551.2397867-14-gaosong@loongson.cn> | 15 | --- a/hw/intc/loongarch_pch_pic.c |
10 | --- | 16 | +++ b/hw/intc/loongarch_pch_pic.c |
11 | hw/loongarch/virt.c | 33 ++++++++++++++++++++++++++++++++- | 17 | @@ -XXX,XX +XXX,XX @@ |
12 | include/hw/pci-host/ls7a.h | 1 + | 18 | |
13 | 2 files changed, 33 insertions(+), 1 deletion(-) | 19 | #include "qemu/osdep.h" |
14 | 20 | #include "qemu/bitops.h" | |
21 | -#include "hw/sysbus.h" | ||
22 | -#include "hw/loongarch/virt.h" | ||
23 | -#include "hw/pci-host/ls7a.h" | ||
24 | #include "hw/irq.h" | ||
25 | #include "hw/intc/loongarch_pch_pic.h" | ||
26 | -#include "hw/qdev-properties.h" | ||
27 | -#include "migration/vmstate.h" | ||
28 | #include "trace.h" | ||
29 | #include "qapi/error.h" | ||
30 | |||
31 | -static void pch_pic_update_irq(LoongArchPCHPIC *s, uint64_t mask, int level) | ||
32 | +static void pch_pic_update_irq(LoongArchPICCommonState *s, uint64_t mask, | ||
33 | + int level) | ||
34 | { | ||
35 | uint64_t val; | ||
36 | int irq; | ||
37 | @@ -XXX,XX +XXX,XX @@ static void pch_pic_update_irq(LoongArchPCHPIC *s, uint64_t mask, int level) | ||
38 | |||
39 | static void pch_pic_irq_handler(void *opaque, int irq, int level) | ||
40 | { | ||
41 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque); | ||
42 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque); | ||
43 | uint64_t mask = 1ULL << irq; | ||
44 | |||
45 | assert(irq < s->irq_num); | ||
46 | @@ -XXX,XX +XXX,XX @@ static void pch_pic_irq_handler(void *opaque, int irq, int level) | ||
47 | static uint64_t loongarch_pch_pic_low_readw(void *opaque, hwaddr addr, | ||
48 | unsigned size) | ||
49 | { | ||
50 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque); | ||
51 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque); | ||
52 | uint64_t val = 0; | ||
53 | uint32_t offset = addr & 0xfff; | ||
54 | |||
55 | @@ -XXX,XX +XXX,XX @@ static uint64_t get_writew_val(uint64_t value, uint32_t target, bool hi) | ||
56 | static void loongarch_pch_pic_low_writew(void *opaque, hwaddr addr, | ||
57 | uint64_t value, unsigned size) | ||
58 | { | ||
59 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque); | ||
60 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque); | ||
61 | uint32_t offset, old_valid, data = (uint32_t)value; | ||
62 | uint64_t old, int_mask; | ||
63 | offset = addr & 0xfff; | ||
64 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_low_writew(void *opaque, hwaddr addr, | ||
65 | static uint64_t loongarch_pch_pic_high_readw(void *opaque, hwaddr addr, | ||
66 | unsigned size) | ||
67 | { | ||
68 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque); | ||
69 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque); | ||
70 | uint64_t val = 0; | ||
71 | uint32_t offset = addr & 0xfff; | ||
72 | |||
73 | @@ -XXX,XX +XXX,XX @@ static uint64_t loongarch_pch_pic_high_readw(void *opaque, hwaddr addr, | ||
74 | static void loongarch_pch_pic_high_writew(void *opaque, hwaddr addr, | ||
75 | uint64_t value, unsigned size) | ||
76 | { | ||
77 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque); | ||
78 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque); | ||
79 | uint32_t offset, data = (uint32_t)value; | ||
80 | offset = addr & 0xfff; | ||
81 | |||
82 | @@ -XXX,XX +XXX,XX @@ static void loongarch_pch_pic_high_writew(void *opaque, hwaddr addr, | ||
83 | static uint64_t loongarch_pch_pic_readb(void *opaque, hwaddr addr, | ||
84 | unsigned size) | ||
85 | { | ||
86 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque); | ||
87 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque); | ||
88 | uint64_t val = 0; | ||
89 | uint32_t offset = (addr & 0xfff) + PCH_PIC_ROUTE_ENTRY_OFFSET; | ||
90 | int64_t offset_tmp; | ||
91 | @@ -XXX,XX +XXX,XX @@ static uint64_t loongarch_pch_pic_readb(void *opaque, hwaddr addr, | ||
92 | static void loongarch_pch_pic_writeb(void *opaque, hwaddr addr, | ||
93 | uint64_t data, unsigned size) | ||
94 | { | ||
95 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(opaque); | ||
96 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(opaque); | ||
97 | int32_t offset_tmp; | ||
98 | uint32_t offset = (addr & 0xfff) + PCH_PIC_ROUTE_ENTRY_OFFSET; | ||
99 | |||
100 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps loongarch_pch_pic_reg8_ops = { | ||
101 | |||
102 | static void loongarch_pch_pic_reset(DeviceState *d) | ||
103 | { | ||
104 | - LoongArchPCHPIC *s = LOONGARCH_PCH_PIC(d); | ||
105 | + LoongArchPICCommonState *s = LOONGARCH_PIC_COMMON(d); | ||
106 | int i; | ||
107 | |||
108 | s->int_mask = -1; | ||
15 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 109 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c |
16 | index XXXXXXX..XXXXXXX 100644 | 110 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/loongarch/virt.c | 111 | --- a/hw/loongarch/virt.c |
18 | +++ b/hw/loongarch/virt.c | 112 | +++ b/hw/loongarch/virt.c |
19 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_pch_pic_node(LoongArchMachineState *lams, | 113 | @@ -XXX,XX +XXX,XX @@ static void virt_irq_init(LoongArchVirtMachineState *lvms) |
20 | g_free(nodename); | 114 | /* Add Extend I/O Interrupt Controller node */ |
21 | } | 115 | fdt_add_eiointc_node(lvms, &cpuintc_phandle, &eiointc_phandle); |
22 | 116 | ||
23 | +static void fdt_add_pch_msi_node(LoongArchMachineState *lams, | 117 | - pch_pic = qdev_new(TYPE_LOONGARCH_PCH_PIC); |
24 | + uint32_t *eiointc_phandle, | 118 | + pch_pic = qdev_new(TYPE_LOONGARCH_PIC); |
25 | + uint32_t *pch_msi_phandle) | 119 | num = VIRT_PCH_PIC_IRQ_NUM; |
26 | +{ | 120 | qdev_prop_set_uint32(pch_pic, "pch_pic_irq_num", num); |
27 | + MachineState *ms = MACHINE(lams); | 121 | d = SYS_BUS_DEVICE(pch_pic); |
28 | + char *nodename; | 122 | diff --git a/include/hw/intc/loongarch_pch_pic.h b/include/hw/intc/loongarch_pch_pic.h |
29 | + hwaddr pch_msi_base = VIRT_PCH_MSI_ADDR_LOW; | ||
30 | + hwaddr pch_msi_size = VIRT_PCH_MSI_SIZE; | ||
31 | + | ||
32 | + *pch_msi_phandle = qemu_fdt_alloc_phandle(ms->fdt); | ||
33 | + nodename = g_strdup_printf("/msi@%" PRIx64, pch_msi_base); | ||
34 | + qemu_fdt_add_subnode(ms->fdt, nodename); | ||
35 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *pch_msi_phandle); | ||
36 | + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", | ||
37 | + "loongson,pch-msi-1.0"); | ||
38 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", | ||
39 | + 0, pch_msi_base, | ||
40 | + 0, pch_msi_size); | ||
41 | + qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0); | ||
42 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent", | ||
43 | + *eiointc_phandle); | ||
44 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,msi-base-vec", | ||
45 | + VIRT_PCH_PIC_IRQ_NUM); | ||
46 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,msi-num-vecs", | ||
47 | + EXTIOI_IRQS - VIRT_PCH_PIC_IRQ_NUM); | ||
48 | + g_free(nodename); | ||
49 | +} | ||
50 | + | ||
51 | static void fdt_add_flash_node(LoongArchMachineState *lams) | ||
52 | { | ||
53 | MachineState *ms = MACHINE(lams); | ||
54 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
55 | CPULoongArchState *env; | ||
56 | CPUState *cpu_state; | ||
57 | int cpu, pin, i, start, num; | ||
58 | - uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle; | ||
59 | + uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle, pch_msi_phandle; | ||
60 | |||
61 | /* | ||
62 | * The connection of interrupts: | ||
63 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
64 | qdev_get_gpio_in(extioi, i + start)); | ||
65 | } | ||
66 | |||
67 | + /* Add PCH MSI node */ | ||
68 | + fdt_add_pch_msi_node(lams, &eiointc_phandle, &pch_msi_phandle); | ||
69 | + | ||
70 | loongarch_devices_init(pch_pic, lams); | ||
71 | } | ||
72 | |||
73 | diff --git a/include/hw/pci-host/ls7a.h b/include/hw/pci-host/ls7a.h | ||
74 | index XXXXXXX..XXXXXXX 100644 | 123 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/include/hw/pci-host/ls7a.h | 124 | --- a/include/hw/intc/loongarch_pch_pic.h |
76 | +++ b/include/hw/pci-host/ls7a.h | 125 | +++ b/include/hw/intc/loongarch_pch_pic.h |
77 | @@ -XXX,XX +XXX,XX @@ | 126 | @@ -XXX,XX +XXX,XX @@ struct LoongarchPICClass { |
78 | #define VIRT_IOAPIC_REG_BASE (VIRT_PCH_REG_BASE) | 127 | DeviceRealize parent_realize; |
79 | #define VIRT_PCH_MSI_ADDR_LOW 0x2FF00000UL | 128 | }; |
80 | #define VIRT_PCH_REG_SIZE 0x400 | 129 | |
81 | +#define VIRT_PCH_MSI_SIZE 0x8 | 130 | -#define TYPE_LOONGARCH_PCH_PIC TYPE_LOONGARCH_PIC |
82 | 131 | -typedef struct LoongArchPICCommonState LoongArchPCHPIC; | |
83 | /* | 132 | -#define LOONGARCH_PCH_PIC(obj) ((struct LoongArchPICCommonState *)(obj)) |
84 | * GSI_BASE is hard-coded with 64 in linux kernel, else kernel fails to boot | 133 | - |
134 | #endif /* HW_LOONGARCH_PCH_PIC_H */ | ||
85 | -- | 135 | -- |
86 | 2.25.1 | 136 | 2.43.5 | diff view generated by jsdifflib |
1 | fdt adds Extend I/O Interrupt Controller, | 1 | Add common header file include/hw/intc/loongarch_extioi_common.h, and |
---|---|---|---|
2 | we use 'loongson,ls2k2000-eiointc'. | 2 | move some macro definition from include/hw/intc/loongarch_extioi.h to |
3 | the common header file. | ||
3 | 4 | ||
4 | See: | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
5 | https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongson-eiointc.c | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
6 | https://lore.kernel.org/r/764e02d924094580ac0f1d15535f4b98308705c6.1683279769.git.zhoubinbin@loongson.cn | 7 | --- |
8 | include/hw/intc/loongarch_extioi.h | 50 +------------------ | ||
9 | include/hw/intc/loongarch_extioi_common.h | 58 +++++++++++++++++++++++ | ||
10 | 2 files changed, 59 insertions(+), 49 deletions(-) | ||
11 | create mode 100644 include/hw/intc/loongarch_extioi_common.h | ||
7 | 12 | ||
8 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
9 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
10 | Message-Id: <20240426091551.2397867-12-gaosong@loongson.cn> | ||
11 | --- | ||
12 | hw/loongarch/virt.c | 30 +++++++++++++++++++++++++++++- | ||
13 | include/hw/intc/loongarch_extioi.h | 1 + | ||
14 | 2 files changed, 30 insertions(+), 1 deletion(-) | ||
15 | |||
16 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/loongarch/virt.c | ||
19 | +++ b/hw/loongarch/virt.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_cpuic_node(LoongArchMachineState *lams, | ||
21 | g_free(nodename); | ||
22 | } | ||
23 | |||
24 | +static void fdt_add_eiointc_node(LoongArchMachineState *lams, | ||
25 | + uint32_t *cpuintc_phandle, | ||
26 | + uint32_t *eiointc_phandle) | ||
27 | +{ | ||
28 | + MachineState *ms = MACHINE(lams); | ||
29 | + char *nodename; | ||
30 | + hwaddr extioi_base = APIC_BASE; | ||
31 | + hwaddr extioi_size = EXTIOI_SIZE; | ||
32 | + | ||
33 | + *eiointc_phandle = qemu_fdt_alloc_phandle(ms->fdt); | ||
34 | + nodename = g_strdup_printf("/eiointc@%" PRIx64, extioi_base); | ||
35 | + qemu_fdt_add_subnode(ms->fdt, nodename); | ||
36 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *eiointc_phandle); | ||
37 | + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", | ||
38 | + "loongson,ls2k2000-eiointc"); | ||
39 | + qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0); | ||
40 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1); | ||
41 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent", | ||
42 | + *cpuintc_phandle); | ||
43 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupts", 3); | ||
44 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0x0, | ||
45 | + extioi_base, 0x0, extioi_size); | ||
46 | + g_free(nodename); | ||
47 | +} | ||
48 | + | ||
49 | static void fdt_add_flash_node(LoongArchMachineState *lams) | ||
50 | { | ||
51 | MachineState *ms = MACHINE(lams); | ||
52 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
53 | CPULoongArchState *env; | ||
54 | CPUState *cpu_state; | ||
55 | int cpu, pin, i, start, num; | ||
56 | - uint32_t cpuintc_phandle; | ||
57 | + uint32_t cpuintc_phandle, eiointc_phandle; | ||
58 | |||
59 | /* | ||
60 | * The connection of interrupts: | ||
61 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
62 | } | ||
63 | } | ||
64 | |||
65 | + /* Add Extend I/O Interrupt Controller node */ | ||
66 | + fdt_add_eiointc_node(lams, &cpuintc_phandle, &eiointc_phandle); | ||
67 | + | ||
68 | pch_pic = qdev_new(TYPE_LOONGARCH_PCH_PIC); | ||
69 | num = VIRT_PCH_PIC_IRQ_NUM; | ||
70 | qdev_prop_set_uint32(pch_pic, "pch_pic_irq_num", num); | ||
71 | diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h | 13 | diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h |
72 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
73 | --- a/include/hw/intc/loongarch_extioi.h | 15 | --- a/include/hw/intc/loongarch_extioi.h |
74 | +++ b/include/hw/intc/loongarch_extioi.h | 16 | +++ b/include/hw/intc/loongarch_extioi.h |
75 | @@ -XXX,XX +XXX,XX @@ | 17 | @@ -XXX,XX +XXX,XX @@ |
76 | #define EXTIOI_COREISR_END (0xB20 - APIC_OFFSET) | 18 | * Copyright (C) 2021 Loongson Technology Corporation Limited |
77 | #define EXTIOI_COREMAP_START (0xC00 - APIC_OFFSET) | 19 | */ |
78 | #define EXTIOI_COREMAP_END (0xD00 - APIC_OFFSET) | 20 | |
79 | +#define EXTIOI_SIZE 0x800 | 21 | -#include "hw/sysbus.h" |
22 | -#include "hw/loongarch/virt.h" | ||
23 | - | ||
24 | #ifndef LOONGARCH_EXTIOI_H | ||
25 | #define LOONGARCH_EXTIOI_H | ||
26 | |||
27 | -#define LS3A_INTC_IP 8 | ||
28 | -#define EXTIOI_IRQS (256) | ||
29 | -#define EXTIOI_IRQS_BITMAP_SIZE (256 / 8) | ||
30 | -/* irq from EXTIOI is routed to no more than 4 cpus */ | ||
31 | -#define EXTIOI_CPUS (4) | ||
32 | -/* map to ipnum per 32 irqs */ | ||
33 | -#define EXTIOI_IRQS_IPMAP_SIZE (256 / 32) | ||
34 | -#define EXTIOI_IRQS_COREMAP_SIZE 256 | ||
35 | -#define EXTIOI_IRQS_NODETYPE_COUNT 16 | ||
36 | -#define EXTIOI_IRQS_GROUP_COUNT 8 | ||
37 | - | ||
38 | -#define APIC_OFFSET 0x400 | ||
39 | -#define APIC_BASE (0x1000ULL + APIC_OFFSET) | ||
40 | - | ||
41 | -#define EXTIOI_NODETYPE_START (0x4a0 - APIC_OFFSET) | ||
42 | -#define EXTIOI_NODETYPE_END (0x4c0 - APIC_OFFSET) | ||
43 | -#define EXTIOI_IPMAP_START (0x4c0 - APIC_OFFSET) | ||
44 | -#define EXTIOI_IPMAP_END (0x4c8 - APIC_OFFSET) | ||
45 | -#define EXTIOI_ENABLE_START (0x600 - APIC_OFFSET) | ||
46 | -#define EXTIOI_ENABLE_END (0x620 - APIC_OFFSET) | ||
47 | -#define EXTIOI_BOUNCE_START (0x680 - APIC_OFFSET) | ||
48 | -#define EXTIOI_BOUNCE_END (0x6a0 - APIC_OFFSET) | ||
49 | -#define EXTIOI_ISR_START (0x700 - APIC_OFFSET) | ||
50 | -#define EXTIOI_ISR_END (0x720 - APIC_OFFSET) | ||
51 | -#define EXTIOI_COREISR_START (0x800 - APIC_OFFSET) | ||
52 | -#define EXTIOI_COREISR_END (0xB20 - APIC_OFFSET) | ||
53 | -#define EXTIOI_COREMAP_START (0xC00 - APIC_OFFSET) | ||
54 | -#define EXTIOI_COREMAP_END (0xD00 - APIC_OFFSET) | ||
55 | -#define EXTIOI_SIZE 0x800 | ||
56 | - | ||
57 | -#define EXTIOI_VIRT_BASE (0x40000000) | ||
58 | -#define EXTIOI_VIRT_SIZE (0x1000) | ||
59 | -#define EXTIOI_VIRT_FEATURES (0x0) | ||
60 | -#define EXTIOI_HAS_VIRT_EXTENSION (0) | ||
61 | -#define EXTIOI_HAS_ENABLE_OPTION (1) | ||
62 | -#define EXTIOI_HAS_INT_ENCODE (2) | ||
63 | -#define EXTIOI_HAS_CPU_ENCODE (3) | ||
64 | -#define EXTIOI_VIRT_HAS_FEATURES (BIT(EXTIOI_HAS_VIRT_EXTENSION) \ | ||
65 | - | BIT(EXTIOI_HAS_ENABLE_OPTION) \ | ||
66 | - | BIT(EXTIOI_HAS_CPU_ENCODE)) | ||
67 | -#define EXTIOI_VIRT_CONFIG (0x4) | ||
68 | -#define EXTIOI_ENABLE (1) | ||
69 | -#define EXTIOI_ENABLE_INT_ENCODE (2) | ||
70 | -#define EXTIOI_ENABLE_CPU_ENCODE (3) | ||
71 | -#define EXTIOI_VIRT_COREMAP_START (0x40) | ||
72 | -#define EXTIOI_VIRT_COREMAP_END (0x240) | ||
73 | +#include "hw/intc/loongarch_extioi_common.h" | ||
80 | 74 | ||
81 | typedef struct ExtIOICore { | 75 | typedef struct ExtIOICore { |
82 | uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT]; | 76 | uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT]; |
77 | diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h | ||
78 | new file mode 100644 | ||
79 | index XXXXXXX..XXXXXXX | ||
80 | --- /dev/null | ||
81 | +++ b/include/hw/intc/loongarch_extioi_common.h | ||
82 | @@ -XXX,XX +XXX,XX @@ | ||
83 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
84 | +/* | ||
85 | + * LoongArch 3A5000 ext interrupt controller definitions | ||
86 | + * Copyright (C) 2024 Loongson Technology Corporation Limited | ||
87 | + */ | ||
88 | + | ||
89 | +#ifndef LOONGARCH_EXTIOI_COMMON_H | ||
90 | +#define LOONGARCH_EXTIOI_COMMON_H | ||
91 | + | ||
92 | +#include "hw/sysbus.h" | ||
93 | +#include "hw/loongarch/virt.h" | ||
94 | + | ||
95 | +#define LS3A_INTC_IP 8 | ||
96 | +#define EXTIOI_IRQS (256) | ||
97 | +#define EXTIOI_IRQS_BITMAP_SIZE (256 / 8) | ||
98 | +/* irq from EXTIOI is routed to no more than 4 cpus */ | ||
99 | +#define EXTIOI_CPUS (4) | ||
100 | +/* map to ipnum per 32 irqs */ | ||
101 | +#define EXTIOI_IRQS_IPMAP_SIZE (256 / 32) | ||
102 | +#define EXTIOI_IRQS_COREMAP_SIZE 256 | ||
103 | +#define EXTIOI_IRQS_NODETYPE_COUNT 16 | ||
104 | +#define EXTIOI_IRQS_GROUP_COUNT 8 | ||
105 | + | ||
106 | +#define APIC_OFFSET 0x400 | ||
107 | +#define APIC_BASE (0x1000ULL + APIC_OFFSET) | ||
108 | +#define EXTIOI_NODETYPE_START (0x4a0 - APIC_OFFSET) | ||
109 | +#define EXTIOI_NODETYPE_END (0x4c0 - APIC_OFFSET) | ||
110 | +#define EXTIOI_IPMAP_START (0x4c0 - APIC_OFFSET) | ||
111 | +#define EXTIOI_IPMAP_END (0x4c8 - APIC_OFFSET) | ||
112 | +#define EXTIOI_ENABLE_START (0x600 - APIC_OFFSET) | ||
113 | +#define EXTIOI_ENABLE_END (0x620 - APIC_OFFSET) | ||
114 | +#define EXTIOI_BOUNCE_START (0x680 - APIC_OFFSET) | ||
115 | +#define EXTIOI_BOUNCE_END (0x6a0 - APIC_OFFSET) | ||
116 | +#define EXTIOI_ISR_START (0x700 - APIC_OFFSET) | ||
117 | +#define EXTIOI_ISR_END (0x720 - APIC_OFFSET) | ||
118 | +#define EXTIOI_COREISR_START (0x800 - APIC_OFFSET) | ||
119 | +#define EXTIOI_COREISR_END (0xB20 - APIC_OFFSET) | ||
120 | +#define EXTIOI_COREMAP_START (0xC00 - APIC_OFFSET) | ||
121 | +#define EXTIOI_COREMAP_END (0xD00 - APIC_OFFSET) | ||
122 | +#define EXTIOI_SIZE 0x800 | ||
123 | + | ||
124 | +#define EXTIOI_VIRT_BASE (0x40000000) | ||
125 | +#define EXTIOI_VIRT_SIZE (0x1000) | ||
126 | +#define EXTIOI_VIRT_FEATURES (0x0) | ||
127 | +#define EXTIOI_HAS_VIRT_EXTENSION (0) | ||
128 | +#define EXTIOI_HAS_ENABLE_OPTION (1) | ||
129 | +#define EXTIOI_HAS_INT_ENCODE (2) | ||
130 | +#define EXTIOI_HAS_CPU_ENCODE (3) | ||
131 | +#define EXTIOI_VIRT_HAS_FEATURES (BIT(EXTIOI_HAS_VIRT_EXTENSION) \ | ||
132 | + | BIT(EXTIOI_HAS_ENABLE_OPTION) \ | ||
133 | + | BIT(EXTIOI_HAS_CPU_ENCODE)) | ||
134 | +#define EXTIOI_VIRT_CONFIG (0x4) | ||
135 | +#define EXTIOI_ENABLE (1) | ||
136 | +#define EXTIOI_ENABLE_INT_ENCODE (2) | ||
137 | +#define EXTIOI_ENABLE_CPU_ENCODE (3) | ||
138 | +#define EXTIOI_VIRT_COREMAP_START (0x40) | ||
139 | +#define EXTIOI_VIRT_COREMAP_END (0x240) | ||
140 | +#endif /* LOONGARCH_EXTIOI_H */ | ||
83 | -- | 141 | -- |
84 | 2.25.1 | 142 | 2.43.5 | diff view generated by jsdifflib |
1 | fdt adds pch pic controller, we use 'loongson,pch-pic-1.0' | 1 | Move definiton of structure LoongArchExtIOI from header file loongarch_extioi.h |
---|---|---|---|
2 | to file loongarch_extioi_common.h. | ||
2 | 3 | ||
3 | See: | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongson-pch-pic.c | 5 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | https://lore.kernel.org/r/20200528152757.1028711-4-jiaxun.yang@flygoat.com | 6 | --- |
7 | include/hw/intc/loongarch_extioi.h | 26 ---------------------- | ||
8 | include/hw/intc/loongarch_extioi_common.h | 27 +++++++++++++++++++++++ | ||
9 | 2 files changed, 27 insertions(+), 26 deletions(-) | ||
6 | 10 | ||
7 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 11 | diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h |
8 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
9 | Message-Id: <20240426091551.2397867-13-gaosong@loongson.cn> | ||
10 | --- | ||
11 | hw/loongarch/virt.c | 30 +++++++++++++++++++++++++++++- | ||
12 | include/hw/pci-host/ls7a.h | 1 + | ||
13 | 2 files changed, 30 insertions(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/loongarch/virt.c | 13 | --- a/include/hw/intc/loongarch_extioi.h |
18 | +++ b/hw/loongarch/virt.c | 14 | +++ b/include/hw/intc/loongarch_extioi.h |
19 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_eiointc_node(LoongArchMachineState *lams, | 15 | @@ -XXX,XX +XXX,XX @@ |
20 | g_free(nodename); | 16 | |
21 | } | 17 | #include "hw/intc/loongarch_extioi_common.h" |
22 | 18 | ||
23 | +static void fdt_add_pch_pic_node(LoongArchMachineState *lams, | 19 | -typedef struct ExtIOICore { |
24 | + uint32_t *eiointc_phandle, | 20 | - uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT]; |
25 | + uint32_t *pch_pic_phandle) | 21 | - DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS); |
26 | +{ | 22 | - qemu_irq parent_irq[LS3A_INTC_IP]; |
27 | + MachineState *ms = MACHINE(lams); | 23 | -} ExtIOICore; |
28 | + char *nodename; | 24 | - |
29 | + hwaddr pch_pic_base = VIRT_PCH_REG_BASE; | 25 | #define TYPE_LOONGARCH_EXTIOI "loongarch.extioi" |
30 | + hwaddr pch_pic_size = VIRT_PCH_REG_SIZE; | 26 | OBJECT_DECLARE_SIMPLE_TYPE(LoongArchExtIOI, LOONGARCH_EXTIOI) |
27 | -struct LoongArchExtIOI { | ||
28 | - SysBusDevice parent_obj; | ||
29 | - uint32_t num_cpu; | ||
30 | - uint32_t features; | ||
31 | - uint32_t status; | ||
32 | - /* hardware state */ | ||
33 | - uint32_t nodetype[EXTIOI_IRQS_NODETYPE_COUNT / 2]; | ||
34 | - uint32_t bounce[EXTIOI_IRQS_GROUP_COUNT]; | ||
35 | - uint32_t isr[EXTIOI_IRQS / 32]; | ||
36 | - uint32_t enable[EXTIOI_IRQS / 32]; | ||
37 | - uint32_t ipmap[EXTIOI_IRQS_IPMAP_SIZE / 4]; | ||
38 | - uint32_t coremap[EXTIOI_IRQS / 4]; | ||
39 | - uint32_t sw_pending[EXTIOI_IRQS / 32]; | ||
40 | - uint8_t sw_ipmap[EXTIOI_IRQS_IPMAP_SIZE]; | ||
41 | - uint8_t sw_coremap[EXTIOI_IRQS]; | ||
42 | - qemu_irq irq[EXTIOI_IRQS]; | ||
43 | - ExtIOICore *cpu; | ||
44 | - MemoryRegion extioi_system_mem; | ||
45 | - MemoryRegion virt_extend; | ||
46 | -}; | ||
47 | #endif /* LOONGARCH_EXTIOI_H */ | ||
48 | diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/include/hw/intc/loongarch_extioi_common.h | ||
51 | +++ b/include/hw/intc/loongarch_extioi_common.h | ||
52 | @@ -XXX,XX +XXX,XX @@ | ||
53 | #define EXTIOI_ENABLE_CPU_ENCODE (3) | ||
54 | #define EXTIOI_VIRT_COREMAP_START (0x40) | ||
55 | #define EXTIOI_VIRT_COREMAP_END (0x240) | ||
31 | + | 56 | + |
32 | + *pch_pic_phandle = qemu_fdt_alloc_phandle(ms->fdt); | 57 | +typedef struct ExtIOICore { |
33 | + nodename = g_strdup_printf("/platic@%" PRIx64, pch_pic_base); | 58 | + uint32_t coreisr[EXTIOI_IRQS_GROUP_COUNT]; |
34 | + qemu_fdt_add_subnode(ms->fdt, nodename); | 59 | + DECLARE_BITMAP(sw_isr[LS3A_INTC_IP], EXTIOI_IRQS); |
35 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *pch_pic_phandle); | 60 | + qemu_irq parent_irq[LS3A_INTC_IP]; |
36 | + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", | 61 | +} ExtIOICore; |
37 | + "loongson,pch-pic-1.0"); | ||
38 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0, | ||
39 | + pch_pic_base, 0, pch_pic_size); | ||
40 | + qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0); | ||
41 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 2); | ||
42 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent", | ||
43 | + *eiointc_phandle); | ||
44 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "loongson,pic-base-vec", 0); | ||
45 | + g_free(nodename); | ||
46 | +} | ||
47 | + | 62 | + |
48 | static void fdt_add_flash_node(LoongArchMachineState *lams) | 63 | +struct LoongArchExtIOI { |
49 | { | 64 | + SysBusDevice parent_obj; |
50 | MachineState *ms = MACHINE(lams); | 65 | + uint32_t num_cpu; |
51 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | 66 | + uint32_t features; |
52 | CPULoongArchState *env; | 67 | + uint32_t status; |
53 | CPUState *cpu_state; | 68 | + /* hardware state */ |
54 | int cpu, pin, i, start, num; | 69 | + uint32_t nodetype[EXTIOI_IRQS_NODETYPE_COUNT / 2]; |
55 | - uint32_t cpuintc_phandle, eiointc_phandle; | 70 | + uint32_t bounce[EXTIOI_IRQS_GROUP_COUNT]; |
56 | + uint32_t cpuintc_phandle, eiointc_phandle, pch_pic_phandle; | 71 | + uint32_t isr[EXTIOI_IRQS / 32]; |
57 | 72 | + uint32_t enable[EXTIOI_IRQS / 32]; | |
58 | /* | 73 | + uint32_t ipmap[EXTIOI_IRQS_IPMAP_SIZE / 4]; |
59 | * The connection of interrupts: | 74 | + uint32_t coremap[EXTIOI_IRQS / 4]; |
60 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | 75 | + uint32_t sw_pending[EXTIOI_IRQS / 32]; |
61 | qdev_connect_gpio_out(DEVICE(d), i, qdev_get_gpio_in(extioi, i)); | 76 | + uint8_t sw_ipmap[EXTIOI_IRQS_IPMAP_SIZE]; |
62 | } | 77 | + uint8_t sw_coremap[EXTIOI_IRQS]; |
63 | 78 | + qemu_irq irq[EXTIOI_IRQS]; | |
64 | + /* Add PCH PIC node */ | 79 | + ExtIOICore *cpu; |
65 | + fdt_add_pch_pic_node(lams, &eiointc_phandle, &pch_pic_phandle); | 80 | + MemoryRegion extioi_system_mem; |
66 | + | 81 | + MemoryRegion virt_extend; |
67 | pch_msi = qdev_new(TYPE_LOONGARCH_PCH_MSI); | 82 | +}; |
68 | start = num; | 83 | #endif /* LOONGARCH_EXTIOI_H */ |
69 | num = EXTIOI_IRQS - start; | ||
70 | diff --git a/include/hw/pci-host/ls7a.h b/include/hw/pci-host/ls7a.h | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/include/hw/pci-host/ls7a.h | ||
73 | +++ b/include/hw/pci-host/ls7a.h | ||
74 | @@ -XXX,XX +XXX,XX @@ | ||
75 | #define VIRT_PCH_REG_BASE 0x10000000UL | ||
76 | #define VIRT_IOAPIC_REG_BASE (VIRT_PCH_REG_BASE) | ||
77 | #define VIRT_PCH_MSI_ADDR_LOW 0x2FF00000UL | ||
78 | +#define VIRT_PCH_REG_SIZE 0x400 | ||
79 | |||
80 | /* | ||
81 | * GSI_BASE is hard-coded with 64 in linux kernel, else kernel fails to boot | ||
82 | -- | 84 | -- |
83 | 2.25.1 | 85 | 2.43.5 | diff view generated by jsdifflib |
1 | The efi_system_table adds a efi_initrd configuration table. | 1 | Rename structure LoongArchExtIOI with LoongArchExtIOICommonState, |
---|---|---|---|
2 | since it is defined in file loongarch_extioi_common.h | ||
2 | 3 | ||
3 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 4 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 5 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | Message-Id: <20240426091551.2397867-8-gaosong@loongson.cn> | ||
6 | --- | 6 | --- |
7 | hw/loongarch/boot.c | 23 +++++++++++++++++++++-- | 7 | include/hw/intc/loongarch_extioi.h | 1 + |
8 | include/hw/loongarch/boot.h | 9 +++++++++ | 8 | include/hw/intc/loongarch_extioi_common.h | 2 +- |
9 | 2 files changed, 30 insertions(+), 2 deletions(-) | 9 | 2 files changed, 2 insertions(+), 1 deletion(-) |
10 | 10 | ||
11 | diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c | 11 | diff --git a/include/hw/intc/loongarch_extioi.h b/include/hw/intc/loongarch_extioi.h |
12 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/hw/loongarch/boot.c | 13 | --- a/include/hw/intc/loongarch_extioi.h |
14 | +++ b/hw/loongarch/boot.c | 14 | +++ b/include/hw/intc/loongarch_extioi.h |
15 | @@ -XXX,XX +XXX,XX @@ | 15 | @@ -XXX,XX +XXX,XX @@ |
16 | #include "sysemu/reset.h" | 16 | |
17 | #include "sysemu/qtest.h" | 17 | #include "hw/intc/loongarch_extioi_common.h" |
18 | 18 | ||
19 | +ram_addr_t initrd_offset; | 19 | +#define LoongArchExtIOI LoongArchExtIOICommonState |
20 | +uint64_t initrd_size; | 20 | #define TYPE_LOONGARCH_EXTIOI "loongarch.extioi" |
21 | + | 21 | OBJECT_DECLARE_SIMPLE_TYPE(LoongArchExtIOI, LOONGARCH_EXTIOI) |
22 | static const unsigned int slave_boot_code[] = { | 22 | #endif /* LOONGARCH_EXTIOI_H */ |
23 | /* Configure reset ebase. */ | 23 | diff --git a/include/hw/intc/loongarch_extioi_common.h b/include/hw/intc/loongarch_extioi_common.h |
24 | 0x0400302c, /* csrwr $t0, LOONGARCH_CSR_EENTRY */ | ||
25 | @@ -XXX,XX +XXX,XX @@ static void init_efi_boot_memmap(struct efi_system_table *systab, | ||
26 | } | ||
27 | } | ||
28 | |||
29 | +static void init_efi_initrd_table(struct efi_system_table *systab, | ||
30 | + void *p, void *start) | ||
31 | +{ | ||
32 | + efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID; | ||
33 | + struct efi_initrd *initrd_table = p; | ||
34 | + | ||
35 | + /* efi_configuration_table 2 */ | ||
36 | + guidcpy(&systab->tables[1].guid, &tbl_guid); | ||
37 | + systab->tables[1].table = (struct efi_configuration_table *)(p - start); | ||
38 | + systab->nr_tables = 2; | ||
39 | + | ||
40 | + initrd_table->base = initrd_offset; | ||
41 | + initrd_table->size = initrd_size; | ||
42 | +} | ||
43 | + | ||
44 | static void init_systab(struct loongarch_boot_info *info, void *p, void *start) | ||
45 | { | ||
46 | void *bp_tables_start; | ||
47 | @@ -XXX,XX +XXX,XX @@ static void init_systab(struct loongarch_boot_info *info, void *p, void *start) | ||
48 | init_efi_boot_memmap(systab, p, start); | ||
49 | p += ROUND_UP(sizeof(struct efi_boot_memmap) + | ||
50 | sizeof(efi_memory_desc_t) * memmap_entries, 64 * KiB); | ||
51 | + init_efi_initrd_table(systab, p, start); | ||
52 | + p += ROUND_UP(sizeof(struct efi_initrd), 64 * KiB); | ||
53 | |||
54 | systab->tables = (struct efi_configuration_table *)(bp_tables_start - start); | ||
55 | } | ||
56 | @@ -XXX,XX +XXX,XX @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr) | ||
57 | |||
58 | static int64_t load_kernel_info(struct loongarch_boot_info *info) | ||
59 | { | ||
60 | - uint64_t kernel_entry, kernel_low, kernel_high, initrd_size; | ||
61 | - ram_addr_t initrd_offset; | ||
62 | + uint64_t kernel_entry, kernel_low, kernel_high; | ||
63 | ssize_t kernel_size; | ||
64 | |||
65 | kernel_size = load_elf(info->kernel_filename, NULL, | ||
66 | diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h | ||
67 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
68 | --- a/include/hw/loongarch/boot.h | 25 | --- a/include/hw/intc/loongarch_extioi_common.h |
69 | +++ b/include/hw/loongarch/boot.h | 26 | +++ b/include/hw/intc/loongarch_extioi_common.h |
70 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 27 | @@ -XXX,XX +XXX,XX @@ typedef struct ExtIOICore { |
71 | EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, \ | 28 | qemu_irq parent_irq[LS3A_INTC_IP]; |
72 | 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4) | 29 | } ExtIOICore; |
73 | 30 | ||
74 | +#define LINUX_EFI_INITRD_MEDIA_GUID \ | 31 | -struct LoongArchExtIOI { |
75 | + EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, \ | 32 | +struct LoongArchExtIOICommonState { |
76 | + 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68) | 33 | SysBusDevice parent_obj; |
77 | + | 34 | uint32_t num_cpu; |
78 | struct efi_config_table { | 35 | uint32_t features; |
79 | efi_guid_t guid; | ||
80 | uint64_t *ptr; | ||
81 | @@ -XXX,XX +XXX,XX @@ struct efi_boot_memmap { | ||
82 | efi_memory_desc_t map[32]; | ||
83 | }; | ||
84 | |||
85 | +struct efi_initrd { | ||
86 | + uint64_t base; | ||
87 | + uint64_t size; | ||
88 | +}; | ||
89 | + | ||
90 | struct loongarch_boot_info { | ||
91 | uint64_t ram_size; | ||
92 | const char *kernel_filename; | ||
93 | -- | 36 | -- |
94 | 2.25.1 | 37 | 2.43.5 | diff view generated by jsdifflib |
1 | The efi_system_table adds a efi_fdt configuration table. | 1 | With some structure such as vmstate and property, rename LoongArchExtIOI |
---|---|---|---|
2 | with LoongArchExtIOICommonState, these common structure will be moved | ||
3 | to common file. | ||
2 | 4 | ||
3 | Signed-off-by: Song Gao <gaosong@loongson.cn> | 5 | Signed-off-by: Bibo Mao <maobibo@loongson.cn> |
4 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | 6 | Reviewed-by: Song Gao <gaosong@loongson.cn> |
5 | Message-Id: <20240426091551.2397867-9-gaosong@loongson.cn> | ||
6 | --- | 7 | --- |
7 | hw/loongarch/boot.c | 11 +++++++++++ | 8 | hw/intc/loongarch_extioi.c | 41 +++++++++++++++++++++++--------------- |
8 | hw/loongarch/virt.c | 6 ++---- | 9 | 1 file changed, 25 insertions(+), 16 deletions(-) |
9 | include/hw/loongarch/boot.h | 4 ++++ | ||
10 | include/hw/loongarch/virt.h | 2 ++ | ||
11 | 4 files changed, 19 insertions(+), 4 deletions(-) | ||
12 | 10 | ||
13 | diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c | 11 | diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c |
14 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/loongarch/boot.c | 13 | --- a/hw/intc/loongarch_extioi.c |
16 | +++ b/hw/loongarch/boot.c | 14 | +++ b/hw/intc/loongarch_extioi.c |
17 | @@ -XXX,XX +XXX,XX @@ static void init_efi_initrd_table(struct efi_system_table *systab, | 15 | @@ -XXX,XX +XXX,XX @@ static int vmstate_extioi_post_load(void *opaque, int version_id) |
18 | initrd_table->size = initrd_size; | 16 | return 0; |
19 | } | 17 | } |
20 | 18 | ||
21 | +static void init_efi_fdt_table(struct efi_system_table *systab) | 19 | +static int loongarch_extioi_common_post_load(void *opaque, int version_id) |
22 | +{ | 20 | +{ |
23 | + efi_guid_t tbl_guid = DEVICE_TREE_GUID; | 21 | + return vmstate_extioi_post_load(opaque, version_id); |
24 | + | ||
25 | + /* efi_configuration_table 3 */ | ||
26 | + guidcpy(&systab->tables[2].guid, &tbl_guid); | ||
27 | + systab->tables[2].table = (void *)FDT_BASE; | ||
28 | + systab->nr_tables = 3; | ||
29 | +} | 22 | +} |
30 | + | 23 | + |
31 | static void init_systab(struct loongarch_boot_info *info, void *p, void *start) | 24 | static const VMStateDescription vmstate_extioi_core = { |
32 | { | 25 | .name = "extioi-core", |
33 | void *bp_tables_start; | 26 | .version_id = 1, |
34 | @@ -XXX,XX +XXX,XX @@ static void init_systab(struct loongarch_boot_info *info, void *p, void *start) | 27 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_extioi_core = { |
35 | sizeof(efi_memory_desc_t) * memmap_entries, 64 * KiB); | 28 | }; |
36 | init_efi_initrd_table(systab, p, start); | 29 | |
37 | p += ROUND_UP(sizeof(struct efi_initrd), 64 * KiB); | 30 | static const VMStateDescription vmstate_loongarch_extioi = { |
38 | + init_efi_fdt_table(systab); | 31 | - .name = TYPE_LOONGARCH_EXTIOI, |
39 | 32 | + .name = "loongarch.extioi", | |
40 | systab->tables = (struct efi_configuration_table *)(bp_tables_start - start); | 33 | .version_id = 3, |
41 | } | 34 | .minimum_version_id = 3, |
42 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | 35 | - .post_load = vmstate_extioi_post_load, |
43 | index XXXXXXX..XXXXXXX 100644 | 36 | + .post_load = loongarch_extioi_common_post_load, |
44 | --- a/hw/loongarch/virt.c | 37 | .fields = (const VMStateField[]) { |
45 | +++ b/hw/loongarch/virt.c | 38 | - VMSTATE_UINT32_ARRAY(bounce, LoongArchExtIOI, EXTIOI_IRQS_GROUP_COUNT), |
46 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | 39 | - VMSTATE_UINT32_ARRAY(nodetype, LoongArchExtIOI, |
47 | int nb_numa_nodes = machine->numa_state->num_nodes; | 40 | + VMSTATE_UINT32_ARRAY(bounce, LoongArchExtIOICommonState, |
48 | NodeInfo *numa_info = machine->numa_state->nodes; | 41 | + EXTIOI_IRQS_GROUP_COUNT), |
49 | int i; | 42 | + VMSTATE_UINT32_ARRAY(nodetype, LoongArchExtIOICommonState, |
50 | - hwaddr fdt_base; | 43 | EXTIOI_IRQS_NODETYPE_COUNT / 2), |
51 | const CPUArchIdList *possible_cpus; | 44 | - VMSTATE_UINT32_ARRAY(enable, LoongArchExtIOI, EXTIOI_IRQS / 32), |
52 | MachineClass *mc = MACHINE_GET_CLASS(machine); | 45 | - VMSTATE_UINT32_ARRAY(isr, LoongArchExtIOI, EXTIOI_IRQS / 32), |
53 | CPUState *cpu; | 46 | - VMSTATE_UINT32_ARRAY(ipmap, LoongArchExtIOI, EXTIOI_IRQS_IPMAP_SIZE / 4), |
54 | @@ -XXX,XX +XXX,XX @@ static void loongarch_init(MachineState *machine) | 47 | - VMSTATE_UINT32_ARRAY(coremap, LoongArchExtIOI, EXTIOI_IRQS / 4), |
55 | * Put the FDT into the memory map as a ROM image: this will ensure | 48 | - |
56 | * the FDT is copied again upon reset, even if addr points into RAM. | 49 | - VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, LoongArchExtIOI, num_cpu, |
57 | */ | 50 | - vmstate_extioi_core, ExtIOICore), |
58 | - fdt_base = 1 * MiB; | 51 | - VMSTATE_UINT32(features, LoongArchExtIOI), |
59 | qemu_fdt_dumpdtb(machine->fdt, lams->fdt_size); | 52 | - VMSTATE_UINT32(status, LoongArchExtIOI), |
60 | - rom_add_blob_fixed_as("fdt", machine->fdt, lams->fdt_size, fdt_base, | 53 | + VMSTATE_UINT32_ARRAY(enable, LoongArchExtIOICommonState, |
61 | + rom_add_blob_fixed_as("fdt", machine->fdt, lams->fdt_size, FDT_BASE, | 54 | + EXTIOI_IRQS / 32), |
62 | &address_space_memory); | 55 | + VMSTATE_UINT32_ARRAY(isr, LoongArchExtIOICommonState, |
63 | qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, | 56 | + EXTIOI_IRQS / 32), |
64 | - rom_ptr_for_as(&address_space_memory, fdt_base, lams->fdt_size)); | 57 | + VMSTATE_UINT32_ARRAY(ipmap, LoongArchExtIOICommonState, |
65 | + rom_ptr_for_as(&address_space_memory, FDT_BASE, lams->fdt_size)); | 58 | + EXTIOI_IRQS_IPMAP_SIZE / 4), |
66 | 59 | + VMSTATE_UINT32_ARRAY(coremap, LoongArchExtIOICommonState, | |
67 | lams->bootinfo.ram_size = ram_size; | 60 | + EXTIOI_IRQS / 4), |
68 | loongarch_load_kernel(machine, &lams->bootinfo); | 61 | + VMSTATE_STRUCT_VARRAY_POINTER_UINT32(cpu, LoongArchExtIOICommonState, |
69 | diff --git a/include/hw/loongarch/boot.h b/include/hw/loongarch/boot.h | 62 | + num_cpu, vmstate_extioi_core, ExtIOICore), |
70 | index XXXXXXX..XXXXXXX 100644 | 63 | + VMSTATE_UINT32(features, LoongArchExtIOICommonState), |
71 | --- a/include/hw/loongarch/boot.h | 64 | + VMSTATE_UINT32(status, LoongArchExtIOICommonState), |
72 | +++ b/include/hw/loongarch/boot.h | 65 | VMSTATE_END_OF_LIST() |
73 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 66 | } |
74 | EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, \ | 67 | }; |
75 | 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68) | 68 | |
76 | 69 | static Property extioi_properties[] = { | |
77 | +#define DEVICE_TREE_GUID \ | 70 | - DEFINE_PROP_UINT32("num-cpu", LoongArchExtIOI, num_cpu, 1), |
78 | + EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, \ | 71 | - DEFINE_PROP_BIT("has-virtualization-extension", LoongArchExtIOI, features, |
79 | + 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0) | 72 | - EXTIOI_HAS_VIRT_EXTENSION, 0), |
80 | + | 73 | + DEFINE_PROP_UINT32("num-cpu", LoongArchExtIOICommonState, num_cpu, 1), |
81 | struct efi_config_table { | 74 | + DEFINE_PROP_BIT("has-virtualization-extension", LoongArchExtIOICommonState, |
82 | efi_guid_t guid; | 75 | + features, EXTIOI_HAS_VIRT_EXTENSION, 0), |
83 | uint64_t *ptr; | 76 | DEFINE_PROP_END_OF_LIST(), |
84 | diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h | 77 | }; |
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/include/hw/loongarch/virt.h | ||
87 | +++ b/include/hw/loongarch/virt.h | ||
88 | @@ -XXX,XX +XXX,XX @@ | ||
89 | |||
90 | #define COMMAND_LINE_SIZE 512 | ||
91 | |||
92 | +#define FDT_BASE 0x100000 | ||
93 | + | ||
94 | extern struct memmap_entry *memmap_table; | ||
95 | extern unsigned memmap_entries; | ||
96 | 78 | ||
97 | -- | 79 | -- |
98 | 2.25.1 | 80 | 2.43.5 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | The right fdt memory node like [1], not [2] | ||
2 | 1 | ||
3 | [1] | ||
4 | memory@0 { | ||
5 | device_type = "memory"; | ||
6 | reg = <0x00 0x00 0x00 0x10000000>; | ||
7 | }; | ||
8 | [2] | ||
9 | memory@0 { | ||
10 | device_type = "memory"; | ||
11 | reg = <0x02 0x00 0x02 0x10000000>; | ||
12 | }; | ||
13 | |||
14 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
15 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
16 | Message-Id: <20240426091551.2397867-10-gaosong@loongson.cn> | ||
17 | --- | ||
18 | hw/loongarch/virt.c | 2 +- | ||
19 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
20 | |||
21 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/hw/loongarch/virt.c | ||
24 | +++ b/hw/loongarch/virt.c | ||
25 | @@ -XXX,XX +XXX,XX @@ static void fdt_add_memory_node(MachineState *ms, | ||
26 | char *nodename = g_strdup_printf("/memory@%" PRIx64, base); | ||
27 | |||
28 | qemu_fdt_add_subnode(ms->fdt, nodename); | ||
29 | - qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 2, base, 2, size); | ||
30 | + qemu_fdt_setprop_cells(ms->fdt, nodename, "reg", 0, base, 0, size); | ||
31 | qemu_fdt_setprop_string(ms->fdt, nodename, "device_type", "memory"); | ||
32 | |||
33 | if (ms->numa_state && ms->numa_state->num_nodes) { | ||
34 | -- | ||
35 | 2.25.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | fdt adds cpu interrupt controller node, | ||
2 | we use 'loongson,cpu-interrupt-controller'. | ||
3 | 1 | ||
4 | See: | ||
5 | https://github.com/torvalds/linux/blob/v6.7/drivers/irqchip/irq-loongarch-cpu.c | ||
6 | https://lore.kernel.org/r/20221114113824.1880-2-liupeibao@loongson.cn | ||
7 | |||
8 | Signed-off-by: Song Gao <gaosong@loongson.cn> | ||
9 | Reviewed-by: Bibo Mao <maobibo@loongson.cn> | ||
10 | Message-Id: <20240426091551.2397867-11-gaosong@loongson.cn> | ||
11 | --- | ||
12 | hw/loongarch/virt.c | 21 +++++++++++++++++++++ | ||
13 | 1 file changed, 21 insertions(+) | ||
14 | |||
15 | diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/loongarch/virt.c | ||
18 | +++ b/hw/loongarch/virt.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void virt_flash_map(LoongArchMachineState *lams, | ||
20 | virt_flash_map1(flash1, VIRT_FLASH1_BASE, VIRT_FLASH1_SIZE, sysmem); | ||
21 | } | ||
22 | |||
23 | +static void fdt_add_cpuic_node(LoongArchMachineState *lams, | ||
24 | + uint32_t *cpuintc_phandle) | ||
25 | +{ | ||
26 | + MachineState *ms = MACHINE(lams); | ||
27 | + char *nodename; | ||
28 | + | ||
29 | + *cpuintc_phandle = qemu_fdt_alloc_phandle(ms->fdt); | ||
30 | + nodename = g_strdup_printf("/cpuic"); | ||
31 | + qemu_fdt_add_subnode(ms->fdt, nodename); | ||
32 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "phandle", *cpuintc_phandle); | ||
33 | + qemu_fdt_setprop_string(ms->fdt, nodename, "compatible", | ||
34 | + "loongson,cpu-interrupt-controller"); | ||
35 | + qemu_fdt_setprop(ms->fdt, nodename, "interrupt-controller", NULL, 0); | ||
36 | + qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1); | ||
37 | + g_free(nodename); | ||
38 | +} | ||
39 | + | ||
40 | static void fdt_add_flash_node(LoongArchMachineState *lams) | ||
41 | { | ||
42 | MachineState *ms = MACHINE(lams); | ||
43 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
44 | CPULoongArchState *env; | ||
45 | CPUState *cpu_state; | ||
46 | int cpu, pin, i, start, num; | ||
47 | + uint32_t cpuintc_phandle; | ||
48 | |||
49 | /* | ||
50 | * The connection of interrupts: | ||
51 | @@ -XXX,XX +XXX,XX @@ static void loongarch_irq_init(LoongArchMachineState *lams) | ||
52 | memory_region_add_subregion(&lams->system_iocsr, MAIL_SEND_ADDR, | ||
53 | sysbus_mmio_get_region(SYS_BUS_DEVICE(ipi), 1)); | ||
54 | |||
55 | + /* Add cpu interrupt-controller */ | ||
56 | + fdt_add_cpuic_node(lams, &cpuintc_phandle); | ||
57 | + | ||
58 | for (cpu = 0; cpu < ms->smp.cpus; cpu++) { | ||
59 | cpu_state = qemu_get_cpu(cpu); | ||
60 | cpudev = DEVICE(cpu_state); | ||
61 | -- | ||
62 | 2.25.1 | diff view generated by jsdifflib |