1
v3 -> v4:
2
- based on 'cxl/cxl-host: Support creation of a new CXL Host Bridge'[1]
3
- Align base addresses of CXL relevant Windows
4
- Remove redundant header files
5
6
v2 -> v3:
7
- create a new host bridge type: TYPE_SBSA_CXL_HOST
8
- CXL exclusive ECAM, PIO, MMIO32 & MMIO64 space in sbsa-ref
9
- combine all cxl infrastructure creating into one function
10
11
v1 -> v2:
12
- provide CXL exclusive MMIO32 & MMIO64 space
13
- hard coded two cxl root ports
14
1
RFC because
15
RFC because
2
- Many contents are ported from Jonathan' patch on qemu virt design
16
- Many contents are ported from Jonathan' patch on qemu virt design
3
17
4
- Bring plenty of PCDs values and modifying the original PCIE values
18
- Less experience and not particularly confident in sbsa-ref address space design
19
so this might be stupidly broken in a way I've not considered.
5
20
6
- Less experience and not particularly confident in ACPI area so this might be
21
Background
7
stupidly broken in a way I've not considered.
22
==========
23
Currently the base CXL support for arm platforms is only on Jonathan's patches[2]
24
which have not yet merged into upstream. SBSA-REF can be more like a real machine,
25
thus my initial purpose is to support the simplest cxl VH topology on sbsa-ref to
26
verify the basic cxl function usage, therefore, some real machine could refer the
27
cxl running result on sbsa-ref.
8
28
9
Currently the base CXL support for arm platforms is only on Jonathan's patches[1] which
29
This series leverages Jonathan's patches to design [SBSA_CXL_CHBCR] and
10
have not yet merged into upstream. SBSA-REF can be more like a real machine, thus the
30
[SBSA_CXL_FIXED_WINDOW] spaces for sbsa-ref layout.
11
support of cxl could be meaningful.
12
31
13
Regard to the burden of edk2 firmware, I try to build a static CEDT table and add acpi0016,
32
Regard to the burden of edk2 firmware, I try to build a static CEDT table and add
14
acpi0017 objects on DSDT at the initial development phase[2][3]. Hence it doesn't need to
33
acpi0016, acpi0017 and other cxl relevant contents into acpi tables[3][4]. Hence it
15
communicate cxl contents via DT to edk2.
34
doesn't need to communicate cxl contents via DT to edk2.
16
35
17
This series leverages Jonathan's patches[1] to design [SBSA_CXL_HOST] and [SBSA_CXL_FIXED_WINDOW]
36
CXL HOST design
18
spaces for sbsa-ref layout.
37
===============
38
In previous version, the pxb-cxl-host with any cxl root ports and cxl endpoint devices
39
would occupy the BDF number of the original pcie domain resulting in the max available
40
pcie devices on sbsa-ref would decrease, which seems to bring a series of trouble. With
41
this patch[1], sbsa-ref could use the new cxl host bridge type (TYPE_CXL_HOST) to
42
avoid above problem.
19
43
20
For [SBSA_CXL_HOST], new memory layout places 1M space for 16 host bridge register regions
44
For [SBSA_CXL_CHBCR], this creates a default cxl host bridge (0001:00) with two cxl root
21
in the sbsa-ref memmap. In addition, this only creates a default pxb-cxl (bus_nr=0xfe) bridge
45
ports on sbsa-ref, and the new memory layout places 64K space for one hard coded cxl host
22
with one cxl-rp on sbsa-ref, so only one cxl device could be added by user on this cxl Bus.
46
bridge register regions in the sbsa-ref memmap. It means for now only two cxl type3
23
With the 'create_pxb_cxl', users don't need to input '-device pxb-cxl' and '-device cxl-rp'
47
devices could be added on the cxl host, but personally it could satisfy my initial purpose
24
parameters.
48
mentioned above.
25
49
26
For [SBSA_CXL_FIXED_WINDOW], this extends 1TB space from the hole above RAM Memory [SBSA_MEM]
50
And the memory layout provides separate space windows for the cxl host bridge in the
27
for CXL Fixed Memory Window. 0xA0000000000 is chosen as the base address of this space because
51
sbsa-ref memmap:
28
of 3 reasons:
52
- 64K CXL Host Bridge Component Registers (CHBCR)
53
- 64K CXL_PIO
54
- 128M CXL_MMIO
55
- 256M CXL_ECAM
56
- 4G CXL_MMIO_HIGH
29
57
58
CXL FIXED WINDOW design
59
=======================
60
For [SBSA_CXL_FIXED_WINDOW], in order to provide CFMWs on sbsa-ref, this extends 1TB
61
space from the hole above RAM Memory [SBSA_MEM] for CXL Fixed Memory Window.
62
- 1T CXL_FIXED_WINDOW
63
64
0xA0000000000 is chosen as the base address of this space because of 3 reasons:
30
1) It is more suitable to choose a static address instead of that
65
1) It is more suitable to choose a static address instead of that
31
implementation in virt, since a dynamic address space layout of
66
implementation in virt, since a dynamic address space layout of
32
sbsa-ref is not appropriate for its original purpose as a reference
67
sbsa-ref is not appropriate for its original purpose as a reference
33
platform.
68
platform.
34
69
...
...
37
It is satisfied the requirements of memory hotplug in linux kernel.
72
It is satisfied the requirements of memory hotplug in linux kernel.
38
73
39
3) The start pfn of CFMW should exceed the reserved_pfn_range for
74
3) The start pfn of CFMW should exceed the reserved_pfn_range for
40
onlined numa node.
75
onlined numa node.
41
76
42
Based on 'cxl_fmws_link_targets', this adds a new function
77
Usage of cxl on sbsa-ref
43
'sbsa_cxl_fmws_link_targets' for binding cfmws.target with the default
78
========================
44
pxb-cxl-bus on sbsa-ref.
79
With the 'create_cxl' and 'create_cxl_fixed_window', users don't need to input
45
80
'-device pxb-cxl' , '-device cxl-rp' and '-M cxl-fmw' parameters.
46
In addition, this also adds 'create_cxl_fixed_window_region' which
47
based on 'machine_set_cfmw' to support creating a static cfmw region on
48
sbsa-ref, so users don't need to input '-M cxl-fmw' parameter.
49
81
50
Thus, to run sbsa-ref with a cxl device could use:
82
Thus, to run sbsa-ref with a cxl device could use:
51
qemu-system-aarch64 \
83
qemu-system-aarch64 \
52
-machine sbsa-ref \
53
-cpu cortex-a57 \
54
-smp 4 \
55
-m 4G \
56
-object memory-backend-ram,size=2G,id=mem0 \
57
-numa node,nodeid=0,cpus=0-1,memdev=mem0 \
58
-object memory-backend-ram,size=2G,id=mem1 \
59
-numa node,nodeid=1,cpus=2-3,memdev=mem1 \
60
-object memory-backend-file,id=mem2,mem-path=/tmp/mem2,size=256M,share=true \
84
-object memory-backend-file,id=mem2,mem-path=/tmp/mem2,size=256M,share=true \
61
-device cxl-type3,bus=cxl.0,volatile-memdev=mem2,id=cxl-mem1 \
85
-device cxl-type3,bus=cxl.0,volatile-memdev=mem2,id=cxl-mem1 \
62
-hda ubuntu.ext4 \
86
63
-pflash SBSA_FLASH0.fd \
87
Incompatibility problem
64
-pflash SBSA_FLASH1.fd \
88
=======================
89
Although the new cxl host bridge has been separated from the original pcie host, the
90
incompatibility problem of "-device qemu-xhci" is not resolved. Because the new device
91
to plug by qemu command would be enumerated at the largest domain(0001), for example,
92
if we add "-device qemu-xhci" to boot sbsa-ref with cxl, the lspci would show:
93
94
root@ubuntu-jammy-arm64:~# lspci
95
0000:00:00.0 Host bridge: Red Hat, Inc. QEMU PCIe Host bridge
96
0000:00:01.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
97
0000:00:02.0 Display controller: Device 1234:1111 (rev 02)
98
0001:00:00.0 PCI bridge: Intel Corporation Device 7075
99
0001:00:01.0 PCI bridge: Intel Corporation Device 7075
100
0001:00:02.0 USB controller: Red Hat, Inc. QEMU XHCI Host Controller (rev 01)
101
0001:01:00.0 CXL: Intel Corporation Device 0d93 (rev 01)
102
103
root@ubuntu-jammy-arm64:~# lspci -tv
104
-+-[0001:00]-+-00.0-[01]----00.0 Intel Corporation Device 0d93
105
| +-01.0-[02]--
106
| \-02.0 Red Hat, Inc. QEMU XHCI Host Controller
107
\-[0000:00]-+-00.0 Red Hat, Inc. QEMU PCIe Host bridge
108
+-01.0 Intel Corporation 82574L Gigabit Network Connection
109
\-02.0 Device 1234:1111
110
111
Hence we should add "bus=pcie.0" when we want to plug some devices on the original
112
pcie bus, for example:
113
-device qemu-xhci,bus=pcie.0 \
114
or
115
-device nvme,serial=deadbeef,bus=pcie.0,drive=hdd \
116
-drive file=../disk/hdd.qcow2,format=qcow2,id=hdd,if=none \
117
118
So the result is:
119
root@ubuntu-jammy-arm64:~# lspci
120
0000:00:00.0 Host bridge: Red Hat, Inc. QEMU PCIe Host bridge
121
0000:00:01.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
122
0000:00:02.0 Display controller: Device 1234:1111 (rev 02)
123
0000:00:03.0 USB controller: Red Hat, Inc. QEMU XHCI Host Controller (rev 01)
124
0001:00:00.0 PCI bridge: Intel Corporation Device 7075
125
0001:00:01.0 PCI bridge: Intel Corporation Device 7075
126
0001:01:00.0 CXL: Intel Corporation Device 0d93 (rev 01)
127
128
root@ubuntu-jammy-arm64:~# lspci -tv
129
-+-[0001:00]-+-00.0-[01]----00.0 Intel Corporation Device 0d93
130
| \-01.0-[02]--
131
\-[0000:00]-+-00.0 Red Hat, Inc. QEMU PCIe Host bridge
132
+-01.0 Intel Corporation 82574L Gigabit Network Connection
133
+-02.0 Device 1234:1111
134
\-03.0 Red Hat, Inc. QEMU XHCI Host Controller
135
136
I am looking for suggestions on if there are better ways to do it.
65
137
66
This series patches are here to hopefully some comments to guide me!
138
This series patches are here to hopefully some comments to guide me!
67
139
68
Link:
140
Link:
69
[1]: https://lore.kernel.org/linux-cxl/20220616141950.23374-1-Jonathan.Cameron@huawei.com/
141
[1]: https://lists.nongnu.org/archive/html/qemu-arm/2024-12/msg00350.html
70
[2]: https://edk2.groups.io/g/devel/topic/rfc_patch_0_1/108173029
142
[2]: https://lore.kernel.org/linux-cxl/20220616141950.23374-1-Jonathan.Cameron@huawei.com/
71
[3]: https://edk2.groups.io/g/devel/topic/rfc_patch_edk2_platforms/108173682
143
[3]: https://edk2.groups.io/g/devel/message/120851
144
[4]: https://edk2.groups.io/g/devel/topic/rfc_patch_edk2_platforms_v4/110023229
72
145
73
Yuquan Wang (2):
146
Yuquan Wang (1):
74
hw/arm/sbsa-ref: Enable CXL Host Bridge by pxb-cxl
147
hw/arm/sbsa-ref: Support CXL Host Bridge & CFMW
75
hw/arm/sbsa-ref: Support CXL Fixed Memory Window
76
148
77
hw/arm/sbsa-ref.c | 127 +++++++++++++++++++++++++++-
149
docs/system/arm/sbsa.rst | 4 ++
78
hw/cxl/cxl-host-stubs.c | 1 +
150
hw/arm/sbsa-ref.c | 135 ++++++++++++++++++++++++++++++++++++++-
79
hw/cxl/cxl-host.c | 2 +-
151
2 files changed, 138 insertions(+), 1 deletion(-)
80
hw/pci-bridge/pci_expander_bridge.c | 1 -
81
include/hw/cxl/cxl_host.h | 1 +
82
include/hw/pci/pci_bridge.h | 1 +
83
6 files changed, 128 insertions(+), 5 deletions(-)
84
152
85
--
153
--
86
2.34.1
154
2.34.1
diff view generated by jsdifflib
1
The memory layout places 1M space for 16 host bridge register regions
1
This creates a specific cxl host bridge (0001:00) with two cxl
2
in the sbsa-ref memmap. In addition, this creates a default pxb-cxl
2
root ports on sbsa-ref. And the memory layout provides separate
3
(bus_nr=0xfe) bridge with one cxl-rp on sbsa-ref.
3
space windows for the cxl host bridge in the sbsa-ref memmap:
4
5
- 64K CXL Host Bridge Component Registers (CHBCR)
6
- 64K CXL_PIO
7
- 128M CXL_MMIO
8
- 256M CXL_ECAM
9
- 4G CXL_MMIO_HIGH
10
11
To provide CFMWs on sbsa-ref, this extends 1TB space from the
12
hole above RAM Memory [SBSA_MEM] for CXL Fixed Memory Window:
13
14
- 1T CXL_FIXED_WINDOW
4
15
5
Signed-off-by: Yuquan Wang <wangyuquan1236@phytium.com.cn>
16
Signed-off-by: Yuquan Wang <wangyuquan1236@phytium.com.cn>
6
---
17
---
7
hw/arm/sbsa-ref.c | 54 ++++++++++++++++++++++++++++++++++++++++++++---
18
docs/system/arm/sbsa.rst | 4 ++
8
1 file changed, 51 insertions(+), 3 deletions(-)
19
hw/arm/sbsa-ref.c | 135 ++++++++++++++++++++++++++++++++++++++-
9
20
2 files changed, 138 insertions(+), 1 deletion(-)
21
22
diff --git a/docs/system/arm/sbsa.rst b/docs/system/arm/sbsa.rst
23
index XXXXXXX..XXXXXXX 100644
24
--- a/docs/system/arm/sbsa.rst
25
+++ b/docs/system/arm/sbsa.rst
26
@@ -XXX,XX +XXX,XX @@ The ``sbsa-ref`` board supports:
27
- E1000E ethernet card on PCIe bus
28
- Bochs display adapter on PCIe bus
29
- A generic SBSA watchdog device
30
+ - CXL host bridge and CXL fixed memory window
31
32
33
Board to firmware interface
34
@@ -XXX,XX +XXX,XX @@ Platform version changes:
35
36
0.4
37
CPU topology information is present in devicetree.
38
+
39
+0.5
40
+ CXL host bridge and CXL fixed memory window are supported.
10
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
41
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
11
index XXXXXXX..XXXXXXX 100644
42
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/arm/sbsa-ref.c
43
--- a/hw/arm/sbsa-ref.c
13
+++ b/hw/arm/sbsa-ref.c
44
+++ b/hw/arm/sbsa-ref.c
14
@@ -XXX,XX +XXX,XX @@
45
@@ -XXX,XX +XXX,XX @@
46
#include "hw/arm/smmuv3.h"
47
#include "hw/block/flash.h"
48
#include "hw/boards.h"
49
+#include "hw/cxl/cxl.h"
50
+#include "hw/cxl/cxl_host.h"
51
#include "hw/ide/ide-bus.h"
52
#include "hw/ide/ahci-sysbus.h"
15
#include "hw/intc/arm_gicv3_common.h"
53
#include "hw/intc/arm_gicv3_common.h"
16
#include "hw/intc/arm_gicv3_its_common.h"
54
#include "hw/intc/arm_gicv3_its_common.h"
17
#include "hw/loader.h"
55
#include "hw/loader.h"
18
+#include "hw/pci/pci_bridge.h"
56
+#include "hw/pci/pcie_port.h"
19
+#include "hw/pci/pci_bus.h"
20
#include "hw/pci-host/gpex.h"
57
#include "hw/pci-host/gpex.h"
21
+#include "hw/pci-bridge/pci_expander_bridge.h"
22
#include "hw/qdev-properties.h"
58
#include "hw/qdev-properties.h"
23
#include "hw/usb.h"
59
#include "hw/usb.h"
24
#include "hw/usb/xhci.h"
25
@@ -XXX,XX +XXX,XX @@
26
#include "qom/object.h"
27
#include "target/arm/cpu-qom.h"
28
#include "target/arm/gtimer.h"
29
+#include "hw/cxl/cxl.h"
30
+#include "hw/cxl/cxl_host.h"
31
32
#define RAMLIMIT_GB 8192
33
#define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB)
34
@@ -XXX,XX +XXX,XX @@ enum {
60
@@ -XXX,XX +XXX,XX @@ enum {
35
SBSA_SECURE_MEM,
61
SBSA_SECURE_MEM,
36
SBSA_AHCI,
62
SBSA_AHCI,
37
SBSA_XHCI,
63
SBSA_XHCI,
38
+ SBSA_CXL_HOST,
64
+ SBSA_CXL,
39
};
65
+ SBSA_CXL_CHBCR,
66
+ SBSA_CXL_MMIO,
67
+ SBSA_CXL_MMIO_HIGH,
68
+ SBSA_CXL_PIO,
69
+ SBSA_CXL_ECAM,
70
+ SBSA_CXL_FIXED_WINDOW,
71
};
40
72
41
struct SBSAMachineState {
73
struct SBSAMachineState {
42
@@ -XXX,XX +XXX,XX @@ struct SBSAMachineState {
74
@@ -XXX,XX +XXX,XX @@ struct SBSAMachineState {
43
int psci_conduit;
75
int psci_conduit;
44
DeviceState *gic;
76
DeviceState *gic;
45
PFlashCFI01 *flash[2];
77
PFlashCFI01 *flash[2];
46
+ CXLState cxl_devices_state;
78
+ CXLState cxl_devices_state;
47
+ PCIBus *bus;
79
};
48
+ PCIBus *cxlbus;
49
};
50
80
51
#define TYPE_SBSA_MACHINE MACHINE_TYPE_NAME("sbsa-ref")
81
#define TYPE_SBSA_MACHINE MACHINE_TYPE_NAME("sbsa-ref")
52
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = {
82
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = {
53
/* Space here reserved for more SMMUs */
83
/* Space here reserved for more SMMUs */
54
[SBSA_AHCI] = { 0x60100000, 0x00010000 },
84
[SBSA_AHCI] = { 0x60100000, 0x00010000 },
55
[SBSA_XHCI] = { 0x60110000, 0x00010000 },
85
[SBSA_XHCI] = { 0x60110000, 0x00010000 },
56
+ /* 1M CXL Host Bridge Registers space (64KiB * 16) */
86
+ /* 64K CXL Host Bridge Registers space */
57
+ [SBSA_CXL_HOST] = { 0x60120000, 0x00100000 },
87
+ [SBSA_CXL_CHBCR] = { 0x60200000, 0x00010000 },
88
+ /* 64K CXL PIO space */
89
+ [SBSA_CXL_PIO] = { 0x60300000, 0x00010000 },
90
+ /* 128M CXL 32-bit MMIO space */
91
+ [SBSA_CXL_MMIO] = { 0x60400000, 0x08000000 },
92
+ /* 256M CXL ECAM space */
93
+ [SBSA_CXL_ECAM] = { 0x68500000, 0x10000000 },
58
/* Space here reserved for other devices */
94
/* Space here reserved for other devices */
59
[SBSA_PCIE_PIO] = { 0x7fff0000, 0x00010000 },
95
[SBSA_PCIE_PIO] = { 0x7fff0000, 0x00010000 },
60
/* 32-bit address PCIE MMIO space */
96
/* 32-bit address PCIE MMIO space */
97
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = {
98
/* ~1TB PCIE MMIO space (4GB to 1024GB boundary) */
99
[SBSA_PCIE_MMIO_HIGH] = { 0x100000000ULL, 0xFF00000000ULL },
100
[SBSA_MEM] = { 0x10000000000ULL, RAMLIMIT_BYTES },
101
+ /* 4G CXL 64-bit MMIO space */
102
+ [SBSA_CXL_MMIO_HIGH] = { 0x90000000000ULL, 0x100000000ULL },
103
+ /* 1TB CXL FIXED WINDOW space */
104
+ [SBSA_CXL_FIXED_WINDOW] = { 0xA0000000000ULL, 0x10000000000ULL },
105
};
106
107
static const int sbsa_ref_irqmap[] = {
108
@@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = {
109
[SBSA_XHCI] = 11,
110
[SBSA_SMMU] = 12, /* ... to 15 */
111
[SBSA_GWDT_WS0] = 16,
112
+ [SBSA_CXL] = 17, /* ... to 20 */
113
};
114
115
static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
116
@@ -XXX,XX +XXX,XX @@ static void create_fdt(SBSAMachineState *sms)
117
* fw compatibility.
118
*/
119
qemu_fdt_setprop_cell(fdt, "/", "machine-version-major", 0);
120
- qemu_fdt_setprop_cell(fdt, "/", "machine-version-minor", 4);
121
+ qemu_fdt_setprop_cell(fdt, "/", "machine-version-minor", 5);
122
123
if (ms->numa_state->have_numa_distance) {
124
int size = nb_numa_nodes * nb_numa_nodes * 3 * sizeof(uint32_t);
61
@@ -XXX,XX +XXX,XX @@ static void create_smmu(const SBSAMachineState *sms, PCIBus *bus)
125
@@ -XXX,XX +XXX,XX @@ static void create_smmu(const SBSAMachineState *sms, PCIBus *bus)
62
}
126
}
63
}
127
}
64
128
65
+static void create_pxb_cxl(SBSAMachineState *sms)
129
+static void create_cxl_fixed_window(SBSAMachineState *sms,
130
+ MemoryRegion *mem, CXLHostBridge *host)
66
+{
131
+{
67
+ CXLHost *host;
132
+ PCIBus *cxlbus = PCI_HOST_BRIDGE(host)->bus;
133
+ char *cxl_host = object_get_canonical_path(OBJECT(cxlbus));
134
+ hwaddr base = sbsa_ref_memmap[SBSA_CXL_FIXED_WINDOW].base;
135
+ GList *it;
136
+ strList host_target = { NULL, cxl_host };
137
+ CXLFixedMemoryWindowOptions sbsa_ref_cfmwoptions = {
138
+ .size = 1 * TiB,
139
+ .has_interleave_granularity = false,
140
+ .targets = &host_target,
141
+ };
142
+ CXLFixedWindow *fw;
143
+
144
+ cxl_fixed_memory_window_config(&sms->cxl_devices_state,
145
+ &sbsa_ref_cfmwoptions, &error_fatal);
146
+
147
+ it = sms->cxl_devices_state.fixed_windows;
148
+ fw = it->data;
149
+ fw->base = base;
150
+ fw->target_chb[0] = host;
151
+
152
+ memory_region_init_io(&fw->mr, OBJECT(sms), &cfmws_ops, fw,
153
+ "cxl-fixed-memory-region", fw->size);
154
+
155
+ memory_region_add_subregion(mem, fw->base, &fw->mr);
156
+}
157
+
158
+static void create_cxl(SBSAMachineState *sms)
159
+{
160
+ hwaddr base_pio = sbsa_ref_memmap[SBSA_CXL_PIO].base;
161
+ int irq = sbsa_ref_irqmap[SBSA_CXL];
162
+ MemoryRegion *mmio_alias, *mmio_alias_high, *mmio_reg;
163
+ MemoryRegion *ecam_alias, *ecam_reg;
164
+ MemoryRegion *sysmem = get_system_memory();
165
+ MemoryRegion *chbcr = &sms->cxl_devices_state.host_mr;
166
+ DeviceState *dev;
167
+ CXLHostBridge *host;
68
+ PCIHostState *cxl;
168
+ PCIHostState *cxl;
69
+
169
+ PCIDevice *cxlrp;
170
+ PCIEPort *p;
171
+ PCIESlot *s;
172
+ int i;
173
+
174
+ dev = qdev_new(TYPE_CXL_HOST);
175
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
70
+ sms->cxl_devices_state.is_enabled = true;
176
+ sms->cxl_devices_state.is_enabled = true;
71
+
177
+
72
+ DeviceState *qdev;
178
+ /* Map CXL ECAM space */
73
+ qdev = qdev_new(TYPE_PXB_CXL_DEV);
179
+ ecam_alias = g_new0(MemoryRegion, 1);
74
+ qdev_prop_set_uint32(qdev, "bus_nr", 0xfe);
180
+ ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1);
75
+
181
+ memory_region_init_alias(ecam_alias, OBJECT(dev), "cxl-ecam",
76
+ PCIDevice *dev = PCI_DEVICE(qdev);
182
+ ecam_reg, 0, sbsa_ref_memmap[SBSA_CXL_ECAM].size);
77
+ pci_realize_and_unref(dev, sms->bus, &error_fatal);
183
+ memory_region_add_subregion(get_system_memory(),
78
+
184
+ sbsa_ref_memmap[SBSA_CXL_ECAM].base, ecam_alias);
79
+ host = PXB_CXL_DEV(dev)->cxl_host_bridge;
185
+
80
+ cxl = PCI_HOST_BRIDGE(host);
186
+ /* Map CXL MMIO space */
81
+ sms->cxlbus = cxl->bus;
187
+ mmio_alias = g_new0(MemoryRegion, 1);
82
+ pci_create_simple(sms->cxlbus, -1, "cxl-rp");
188
+ mmio_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 2);
189
+ memory_region_init_alias(mmio_alias, OBJECT(dev), "cxl-mmio",
190
+ mmio_reg, sbsa_ref_memmap[SBSA_CXL_MMIO].base,
191
+ sbsa_ref_memmap[SBSA_CXL_MMIO].size);
192
+ memory_region_add_subregion(get_system_memory(),
193
+ sbsa_ref_memmap[SBSA_CXL_MMIO].base, mmio_alias);
194
+
195
+ /* Map CXL MMIO_HIGH space */
196
+ mmio_alias_high = g_new0(MemoryRegion, 1);
197
+ memory_region_init_alias(mmio_alias_high, OBJECT(dev), "cxl-mmio-high",
198
+ mmio_reg, sbsa_ref_memmap[SBSA_CXL_MMIO_HIGH].base,
199
+ sbsa_ref_memmap[SBSA_CXL_MMIO_HIGH].size);
200
+ memory_region_add_subregion(get_system_memory(),
201
+ sbsa_ref_memmap[SBSA_CXL_MMIO_HIGH].base, mmio_alias_high);
202
+
203
+ /* Map CXL IO port space */
204
+ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 3, base_pio);
205
+
206
+ for (i = 0; i < CXL_HOST_NUM_IRQS; i++) {
207
+ sysbus_connect_irq(SYS_BUS_DEVICE(dev), i,
208
+ qdev_get_gpio_in(sms->gic, irq + i));
209
+ cxl_host_set_irq_num(CXL_HOST(dev), i, irq + i);
210
+ }
211
+
212
+ /* Map CXL CHBCR space */
213
+ memory_region_init(chbcr, OBJECT(sms), "cxl_host_reg",
214
+ sbsa_ref_memmap[SBSA_CXL_CHBCR].size);
215
+ memory_region_add_subregion(sysmem, sbsa_ref_memmap[SBSA_CXL_CHBCR].base,
216
+ chbcr);
217
+
218
+ cxl = PCI_HOST_BRIDGE(dev);
219
+
220
+ /* Connect two cxl root ports */
221
+ for (i = 0; i < 2; i++) {
222
+ cxlrp = pci_new(-1, "cxl-rp");
223
+ p = PCIE_PORT(cxlrp);
224
+ s = PCIE_SLOT(cxlrp);
225
+ p->port = i;
226
+ s->slot = i;
227
+ pci_realize_and_unref(cxlrp, cxl->bus, &error_fatal);
228
+ }
229
+
230
+ host = CXL_HOST(dev);
231
+ cxl_host_hook_up_registers(&sms->cxl_devices_state, host, &error_fatal);
232
+
233
+ create_cxl_fixed_window(sms, sysmem, host);
83
+}
234
+}
84
+
235
+
85
static void create_pcie(SBSAMachineState *sms)
236
static void create_pcie(SBSAMachineState *sms)
86
{
237
{
87
hwaddr base_ecam = sbsa_ref_memmap[SBSA_PCIE_ECAM].base;
238
hwaddr base_ecam = sbsa_ref_memmap[SBSA_PCIE_ECAM].base;
88
@@ -XXX,XX +XXX,XX @@ static void create_pcie(SBSAMachineState *sms)
89
}
90
91
pci = PCI_HOST_BRIDGE(dev);
92
+ sms->bus = pci->bus;
93
+
94
+ pci_init_nic_devices(sms->bus, mc->default_nic);
95
96
- pci_init_nic_devices(pci->bus, mc->default_nic);
97
+ pci_create_simple(sms->bus, -1, "bochs-display");
98
99
- pci_create_simple(pci->bus, -1, "bochs-display");
100
+ create_smmu(sms, sms->bus);
101
102
- create_smmu(sms, pci->bus);
103
+ create_pxb_cxl(sms);
104
+}
105
+
106
+static void create_cxl_host_reg_region(SBSAMachineState *sms)
107
+{
108
+ MemoryRegion *sysmem = get_system_memory();
109
+ MemoryRegion *mr = &sms->cxl_devices_state.host_mr;
110
+
111
+ memory_region_init(mr, OBJECT(sms), "cxl_host_reg",
112
+ sbsa_ref_memmap[SBSA_CXL_HOST].size);
113
+ memory_region_add_subregion(sysmem, sbsa_ref_memmap[SBSA_CXL_HOST].base, mr);
114
}
115
116
static void *sbsa_ref_dtb(const struct arm_boot_info *binfo, int *fdt_size)
117
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine)
239
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine)
118
240
119
create_pcie(sms);
241
create_pcie(sms);
120
242
121
+ create_cxl_host_reg_region(sms);
243
+ create_cxl(sms);
122
+
123
+ cxl_hook_up_pxb_registers(sms->bus, &sms->cxl_devices_state, &error_fatal);
124
+
244
+
125
create_secure_ec(secure_sysmem);
245
create_secure_ec(secure_sysmem);
126
246
127
sms->bootinfo.ram_size = machine->ram_size;
247
sms->bootinfo.ram_size = machine->ram_size;
128
--
248
--
129
2.34.1
249
2.34.1
diff view generated by jsdifflib
Deleted patch
1
In order to provide CFMWs on sbsa-ref, this extends 1TB space
2
from the hole above RAM Memory [SBSA_MEM] for CXL Fixed Memory
3
Window. 0xA0000000000 is chosen as the base address of this
4
space because of 3 reasons:
5
1
6
1) It is more suitable to choose a static address instead of that
7
implementation in virt, since a dynamic address space layout of
8
sbsa-ref is not appropriate for its original purpose as a reference
9
platform.
10
11
2) The Hotplug Memory address range should in the range of maximum
12
addressable range of sbsa-ref platform(0x10000000000-0x80ffffffffff).
13
It is satisfied the requirements of memory hotplug in linux kernel.
14
15
3) The start pfn of CFMW should exceed the reserved_pfn_range for
16
onlined numa node.
17
18
Based on 'cxl_fmws_link_targets', this adds a new function
19
'sbsa_cxl_fmws_link_targets' for binding cfmws.target with the default
20
pxb-cxl-bus on sbsa-ref.
21
22
In addition, this also adds 'create_cxl_fixed_window_region' which
23
based on 'machine_set_cfmw' to support creating a static cfmw region on
24
sbsa-ref.
25
26
Thus, to run sbsa-ref with a cxl device could use:
27
qemu-system-aarch64 \
28
-machine sbsa-ref \
29
-cpu cortex-a57 \
30
-smp 4 \
31
-m 4G \
32
-object memory-backend-ram,size=2G,id=mem0 \
33
-numa node,nodeid=0,cpus=0-1,memdev=mem0 \
34
-object memory-backend-ram,size=2G,id=mem1 \
35
-numa node,nodeid=1,cpus=2-3,memdev=mem1 \
36
-object memory-backend-file,id=mem2,mem-path=/tmp/mem2,size=256M,share=true \
37
-device cxl-type3,bus=cxl.0,volatile-memdev=mem2,id=cxl-mem1 \
38
-hda ubuntu.ext4 \
39
-pflash SBSA_FLASH0.fd \
40
-pflash SBSA_FLASH1.fd \
41
42
I'm not sure if the new space layout would bring a series of bad
43
influence, this patch is here to hopefully some comments to guide me!
44
45
Signed-off-by: Yuquan Wang <wangyuquan1236@phytium.com.cn>
46
---
47
hw/arm/sbsa-ref.c | 73 +++++++++++++++++++++++++++++
48
hw/cxl/cxl-host-stubs.c | 1 +
49
hw/cxl/cxl-host.c | 2 +-
50
hw/pci-bridge/pci_expander_bridge.c | 1 -
51
include/hw/cxl/cxl_host.h | 1 +
52
include/hw/pci/pci_bridge.h | 1 +
53
6 files changed, 77 insertions(+), 2 deletions(-)
54
55
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
56
index XXXXXXX..XXXXXXX 100644
57
--- a/hw/arm/sbsa-ref.c
58
+++ b/hw/arm/sbsa-ref.c
59
@@ -XXX,XX +XXX,XX @@ enum {
60
SBSA_AHCI,
61
SBSA_XHCI,
62
SBSA_CXL_HOST,
63
+ SBSA_CXL_FIXED_WINDOW,
64
};
65
66
struct SBSAMachineState {
67
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = {
68
/* ~1TB PCIE MMIO space (4GB to 1024GB boundary) */
69
[SBSA_PCIE_MMIO_HIGH] = { 0x100000000ULL, 0xFF00000000ULL },
70
[SBSA_MEM] = { 0x10000000000ULL, RAMLIMIT_BYTES },
71
+ /* 1TB CXL FIXED WINDOW space */
72
+ [SBSA_CXL_FIXED_WINDOW] = { 0xA0000000000ULL, 0x10000000000ULL },
73
};
74
75
static const int sbsa_ref_irqmap[] = {
76
@@ -XXX,XX +XXX,XX @@ static void create_cxl_host_reg_region(SBSAMachineState *sms)
77
memory_region_add_subregion(sysmem, sbsa_ref_memmap[SBSA_CXL_HOST].base, mr);
78
}
79
80
+static void create_cxl_fixed_window_region(SBSAMachineState *sms, MemoryRegion *mem)
81
+{
82
+ char cxl_host[] = "pxb-cxl-bus.0";
83
+ CXLFixedMemoryWindowOptionsList *list;
84
+ hwaddr base, end;
85
+ GList *it;
86
+ strList host_target = { NULL, cxl_host };
87
+ CXLFixedMemoryWindowOptions sbsa_ref_cfmwoptions = {
88
+ .size = 1 * TiB,
89
+ .has_interleave_granularity = false,
90
+ .targets = &host_target,
91
+ };
92
+ CXLFixedMemoryWindowOptionsList sbsa_ref_cfmwlist = { NULL, &sbsa_ref_cfmwoptions };
93
+
94
+ for (list = &sbsa_ref_cfmwlist; list; list = list->next) {
95
+ cxl_fixed_memory_window_config(&sms->cxl_devices_state, list->value, &error_fatal);
96
+ }
97
+
98
+ base = sbsa_ref_memmap[SBSA_CXL_FIXED_WINDOW].base;
99
+ end = base + sbsa_ref_memmap[SBSA_CXL_FIXED_WINDOW].size;
100
+
101
+ for (it = sms->cxl_devices_state.fixed_windows; it; it = it->next) {
102
+ CXLFixedWindow *fw = it->data;
103
+ if (base + fw->size > end) {
104
+ error_report("CFMWS does not fit under PA limit");
105
+ exit(EXIT_FAILURE);
106
+ }
107
+
108
+ fw->base = base;
109
+ memory_region_init_io(&fw->mr, OBJECT(sms), &cfmws_ops, fw,
110
+ "cxl-fixed-memory-region", fw->size);
111
+
112
+ memory_region_add_subregion(mem, fw->base, &fw->mr);
113
+ base += fw->size;
114
+ }
115
+}
116
+
117
+static void sbsa_cxl_fmws_link_targets(SBSAMachineState *sms,
118
+ CXLState *cxl_state, Error **errp)
119
+{
120
+ PXBCXLDev *pxb = PXB_CXL_DEV(pci_bridge_get_device(sms->cxlbus));
121
+ if (cxl_state && cxl_state->fixed_windows) {
122
+ GList *it;
123
+
124
+ for (it = cxl_state->fixed_windows; it; it = it->next) {
125
+ CXLFixedWindow *fw = it->data;
126
+ int i;
127
+
128
+ for (i = 0; i < fw->num_targets; i++) {
129
+ Object *o;
130
+ bool ambig;
131
+
132
+ o = object_resolve_path_type(fw->targets[i],
133
+ TYPE_PXB_CXL_BUS,
134
+ &ambig);
135
+ if (!o) {
136
+ error_setg(errp, "Could not resolve CXLFM target %s",
137
+ fw->targets[i]);
138
+ return;
139
+ }
140
+ fw->target_hbs[i] = pxb;
141
+ }
142
+ }
143
+ }
144
+}
145
+
146
static void *sbsa_ref_dtb(const struct arm_boot_info *binfo, int *fdt_size)
147
{
148
const SBSAMachineState *board = container_of(binfo, SBSAMachineState,
149
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine)
150
151
create_cxl_host_reg_region(sms);
152
153
+ create_cxl_fixed_window_region(sms, sysmem);
154
+
155
cxl_hook_up_pxb_registers(sms->bus, &sms->cxl_devices_state, &error_fatal);
156
157
+ sbsa_cxl_fmws_link_targets(sms, &sms->cxl_devices_state, &error_fatal);
158
+
159
create_secure_ec(secure_sysmem);
160
161
sms->bootinfo.ram_size = machine->ram_size;
162
diff --git a/hw/cxl/cxl-host-stubs.c b/hw/cxl/cxl-host-stubs.c
163
index XXXXXXX..XXXXXXX 100644
164
--- a/hw/cxl/cxl-host-stubs.c
165
+++ b/hw/cxl/cxl-host-stubs.c
166
@@ -XXX,XX +XXX,XX @@
167
void cxl_fmws_link_targets(CXLState *stat, Error **errp) {};
168
void cxl_machine_init(Object *obj, CXLState *state) {};
169
void cxl_hook_up_pxb_registers(PCIBus *bus, CXLState *state, Error **errp) {};
170
+void cxl_fixed_memory_window_config(CXLState *cxl_state, CXLFixedMemoryWindowOptions *object, Error **errp) {};
171
172
const MemoryRegionOps cfmws_ops;
173
diff --git a/hw/cxl/cxl-host.c b/hw/cxl/cxl-host.c
174
index XXXXXXX..XXXXXXX 100644
175
--- a/hw/cxl/cxl-host.c
176
+++ b/hw/cxl/cxl-host.c
177
@@ -XXX,XX +XXX,XX @@
178
#include "hw/pci/pcie_port.h"
179
#include "hw/pci-bridge/pci_expander_bridge.h"
180
181
-static void cxl_fixed_memory_window_config(CXLState *cxl_state,
182
+void cxl_fixed_memory_window_config(CXLState *cxl_state,
183
CXLFixedMemoryWindowOptions *object,
184
Error **errp)
185
{
186
diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expander_bridge.c
187
index XXXXXXX..XXXXXXX 100644
188
--- a/hw/pci-bridge/pci_expander_bridge.c
189
+++ b/hw/pci-bridge/pci_expander_bridge.c
190
@@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(PXBBus, PXB_BUS,
191
DECLARE_INSTANCE_CHECKER(PXBBus, PXB_PCIE_BUS,
192
TYPE_PXB_PCIE_BUS)
193
194
-#define TYPE_PXB_CXL_BUS "pxb-cxl-bus"
195
DECLARE_INSTANCE_CHECKER(PXBBus, PXB_CXL_BUS,
196
TYPE_PXB_CXL_BUS)
197
198
diff --git a/include/hw/cxl/cxl_host.h b/include/hw/cxl/cxl_host.h
199
index XXXXXXX..XXXXXXX 100644
200
--- a/include/hw/cxl/cxl_host.h
201
+++ b/include/hw/cxl/cxl_host.h
202
@@ -XXX,XX +XXX,XX @@
203
void cxl_machine_init(Object *obj, CXLState *state);
204
void cxl_fmws_link_targets(CXLState *stat, Error **errp);
205
void cxl_hook_up_pxb_registers(PCIBus *bus, CXLState *state, Error **errp);
206
+void cxl_fixed_memory_window_config(CXLState *cxl_state, CXLFixedMemoryWindowOptions *object, Error **errp);
207
208
extern const MemoryRegionOps cfmws_ops;
209
210
diff --git a/include/hw/pci/pci_bridge.h b/include/hw/pci/pci_bridge.h
211
index XXXXXXX..XXXXXXX 100644
212
--- a/include/hw/pci/pci_bridge.h
213
+++ b/include/hw/pci/pci_bridge.h
214
@@ -XXX,XX +XXX,XX @@ typedef struct PXBPCIEDev {
215
PXBDev parent_obj;
216
} PXBPCIEDev;
217
218
+#define TYPE_PXB_CXL_BUS "pxb-cxl-bus"
219
#define TYPE_PXB_DEV "pxb"
220
OBJECT_DECLARE_SIMPLE_TYPE(PXBDev, PXB_DEV)
221
222
--
223
2.34.1
diff view generated by jsdifflib