summaryrefslogtreecommitdiffstats
path: root/meta-xilinx-virtualization
diff options
context:
space:
mode:
Diffstat (limited to 'meta-xilinx-virtualization')
-rw-r--r--meta-xilinx-virtualization/COPYING.MIT17
-rw-r--r--meta-xilinx-virtualization/README.md154
-rw-r--r--meta-xilinx-virtualization/conf/layer.conf23
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-native_%.bbappend1
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-system-native_%.bbappend1
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-tpm.inc4
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xen_8.1.inc20
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-arm-xenpvh-Introduce-virtio-pci-support.patch353
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-xen_arm-Create-virtio-mmio-devices-during-initializa.patch116
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0002-xen_arm-Initialize-RAM-and-add-hi-low-memory-regions.patch124
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0003-Xen-Fix-xen_set_irq-and-xendevicemodel_set_irq_level.patch55
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0004-xen-when-unplugging-emulated-devices-skip-virtio-dev.patch70
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0005-softmmu-physmem-Split-ram_block_add.patch117
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0006-xen-add-pseudo-RAM-region-for-grant-mappings.patch153
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0007-softmmu-let-qemu_map_ram_ptr-use-qemu_ram_ptr_length.patch117
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0008-xen-let-xen_ram_addr_from_mapcache-return-1-in-case-.patch49
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0009-memory-add-MemoryRegion-map-and-unmap-callbacks.patch155
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0010-xen-add-map-and-unmap-callbacks-for-grant-region.patch262
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0011-hw-arm-Add-grant-mapping.patch30
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-native_%.bbappend1
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-system-native_%.bbappend1
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx_2024%.bbappend5
-rw-r--r--meta-xilinx-virtualization/recipes-devtools/qemu/qemu_8.1%.bbappend5
-rw-r--r--meta-xilinx-virtualization/recipes-extended/xen/files/0001-menuconfig-mconf-cfg-Allow-specification-of-ncurses-location.patch57
-rw-r--r--meta-xilinx-virtualization/recipes-extended/xen/files/0001-python-pygrub-pass-DISTUTILS-xen-4.15.patch73
-rw-r--r--meta-xilinx-virtualization/recipes-extended/xen/files/0001-python-pygrub-pass-DISTUTILS-xen-4.18.patch43
-rw-r--r--meta-xilinx-virtualization/recipes-extended/xen/files/xen-flask-race-fix.patch54
-rw-r--r--meta-xilinx-virtualization/recipes-extended/xen/xen-tools-xilinx.inc25
-rw-r--r--meta-xilinx-virtualization/recipes-extended/xen/xen-tools_4.18.bbappend2
-rw-r--r--meta-xilinx-virtualization/recipes-extended/xen/xen-xilinx_4.18.inc12
-rw-r--r--meta-xilinx-virtualization/recipes-extended/xen/xen_4.18.bbappend20
-rw-r--r--meta-xilinx-virtualization/recipes-graphics/xorg-xserver/xserver-xorg_%.bbappend8
32 files changed, 2127 insertions, 0 deletions
diff --git a/meta-xilinx-virtualization/COPYING.MIT b/meta-xilinx-virtualization/COPYING.MIT
new file mode 100644
index 00000000..fb950dc6
--- /dev/null
+++ b/meta-xilinx-virtualization/COPYING.MIT
@@ -0,0 +1,17 @@
1Permission is hereby granted, free of charge, to any person obtaining a copy
2of this software and associated documentation files (the "Software"), to deal
3in the Software without restriction, including without limitation the rights
4to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5copies of the Software, and to permit persons to whom the Software is
6furnished to do so, subject to the following conditions:
7
8The above copyright notice and this permission notice shall be included in
9all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17THE SOFTWARE.
diff --git a/meta-xilinx-virtualization/README.md b/meta-xilinx-virtualization/README.md
new file mode 100644
index 00000000..5b66ea38
--- /dev/null
+++ b/meta-xilinx-virtualization/README.md
@@ -0,0 +1,154 @@
1# meta-xilinx-vendor
2
3This layer enables AMD Xilinx Xen configurations and features for ZynqMP and
4Versal devices and also provides related metadata.
5
6## Xen Build Instructions
7
8The Yocto Project setup for AMD Xilinx Xen configurations workflow is as follows.
9Be sure to read everything below.
10
111. Follow [Building Instructions](../README.building.md) upto step 2.
12
132. Clone the meta-security repository.
14
15```
16$ git clone -b <release-branch> https://git.yoctoproject.org/meta-security
17```
18
193. Continue [Building Instructions](../README.building.md) from step 4.
20
21> **Note:**
22> * For System Device Tree(SDT) workflow see [SDT Building Instructions](../meta-xilinx-standalone-experimental/README.md)
23
244. Add meta-xilinx-virtualization layer to bblayers.conf as shown below.
25
26```
27$ bitbake-layers add-layer ./<path-to-layer>/meta-xilinx/meta-xilinx-virtualization
28```
29
305. The following variables needs to be added to the end of the conf/local.conf file.
31
32```
33# Xen variables
34BOOTMODE = "xen"
35ENABLE_XEN_UBOOT_SCR = "1"
36ENABLE_XEN_DTSI = "1"
37ENABLE_XEN_QEMU_DTSI = "1"
38
39# Default Xen Serial Console is serial0, if you are using serial1 then set as show below.
40XEN_SERIAL_CONSOLES = "serial1"
41
42# Variables for Xen JTAG or SD INITRD boot modes but this is not required for SD WIC image.
43IMAGE_FSTYPES += "cpio.gz"
44RAMDISK_IMAGE = "rootfs.cpio.gz"
45
46# Variables for Xen SD WIC image boot flow.
47IMAGE_FSTYPES += "wic"
48WKS_FILES = "xilinx-default-sd.wks"
49
50DISTRO_FEATURES:append = " multiarch security tpm virtualization vmsep xen"
51
52IMAGE_FEATURES += "ssh-server-openssh"
53
54DISTRO_FEATURES:append = " systemd"
55VIRTUAL-RUNTIME_init_manager = "systemd"
56DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
57
58IMAGE_INSTALL:append = " \
59 kernel-module-xen-blkback \
60 kernel-module-xen-gntalloc \
61 kernel-module-xen-gntdev \
62 kernel-module-xen-netback \
63 kernel-module-xen-wdt \
64 xen \
65 xen-tools \
66 xen-tools-xenstat \
67 ${@bb.utils.contains('DISTRO_FEATURES', 'vmsep', 'qemu-aarch64 qemu-keymaps', 'qemu', d)} \
68 "
69```
70
716. Continue [Building Instructions](../README.building.md) from step 5.
72
73## Xen Boot Instructions
74
75> **Note:**
76> * This README provides instructions for Xen Dom0 only.
77
781. Follow [Booting Instructions](../README.booting.md) upto step 2.
79
802. Verify Xen Dom0 is up and running on QEMU or target as shown below.
81
82```
83Poky (Yocto Project Reference Distro) 4.1.4 zynqmp-generic hvc0
84
85zynqmp-generic login: root
86root@zynqmp-generic:~# xl list
87Name ID Mem VCPUs State Time(s)
88Domain-0 0 1500 1 r----- 123.5
89root@zynqmp-generic:~# xl info
90host : zynqmp-generic
91release : 6.1.0-xilinx-v2024.1
92version : #1 SMP Thu Dec 21 07:00:11 UTC 2023
93machine : aarch64
94nr_cpus : 4
95max_cpu_id : 3
96nr_nodes : 1
97cores_per_socket : 1
98threads_per_core : 1
99cpu_mhz : 99.990
100hw_caps : 00000000:00000000:00000000:00000000:00000000:00000000:00000000:00000000
101virt_caps : hvm hvm_directio hap iommu_hap_pt_share vpmu gnttab-v1
102total_memory : 4095
103free_memory : 2529
104sharing_freed_memory : 0
105sharing_used_memory : 0
106outstanding_claims : 0
107free_cpus : 0
108xen_major : 4
109xen_minor : 17
110xen_extra : .0
111xen_version : 4.17.0
112xen_caps : xen-3.0-aarch64 xen-3.0-armv7l
113xen_scheduler : credit2
114xen_pagesize : 4096
115platform_params : virt_start=0x200000
116xen_changeset : Tue Dec 12 10:08:40 2023 +0100 git:38eebc6e5c-dirty
117xen_commandline : console=dtuart dtuart=serial0 dom0_mem=1500M dom0_max_vcpus=1 bootscrub=0 vwfi=native
118cc_compiler : aarch64-poky-linux-gcc (GCC) 12.2.0
119cc_compile_by : santraju
120cc_compile_domain :
121cc_compile_date : 2023-12-12
122build_id : 5e2952e1dd06c52a2a09ada7476333c48d88a285
123xend_config_format : 4
124root@zynqmp-generic:~#
125```
126
127## Dependencies
128
129This layer depends on:
130
131 URI: https://git.yoctoproject.org/poky
132 layers: meta, meta-poky
133 branch: langdale
134
135 URI: https://git.openembedded.org/meta-openembedded
136 layers: meta-oe, meta-python, meta-filesystems, meta-networking.
137 branch: langdale
138
139 URI:
140 https://git.yoctoproject.org/meta-xilinx (official version)
141 https://github.com/Xilinx/meta-xilinx (development and amd xilinx release)
142 layers: meta-xilinx-core, meta-xilinx-standalone
143 branch: langdale or amd xilinx release version (e.g. rel-v2024.1)
144
145 URI: https://git.yoctoproject.org/meta-virtualization
146 branch: langdale
147
148 URI: https://git.yoctoproject.org/meta-security
149 layers: meta-tpm
150 branch: langdale
151
152## References
153
154* https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/18842530/Xen+Hypervisor
diff --git a/meta-xilinx-virtualization/conf/layer.conf b/meta-xilinx-virtualization/conf/layer.conf
new file mode 100644
index 00000000..29506eab
--- /dev/null
+++ b/meta-xilinx-virtualization/conf/layer.conf
@@ -0,0 +1,23 @@
1# We have a conf and classes directory, add to BBPATH
2BBPATH .= ":${LAYERDIR}"
3
4# We have packages directories, add to BBFILES
5BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
6 ${LAYERDIR}/recipes-*/*/*.bbappend"
7
8BBFILE_COLLECTIONS += "xilinx-virtualization"
9BBFILE_PATTERN_xilinx-virtualization = "^${LAYERDIR}/"
10BBFILE_PRIORITY_xilinx-virtualization = "5"
11
12LAYERDEPENDS_xilinx-virtualization = "\
13 xilinx \
14 virtualization-layer \
15 security \
16 tpm-layer \
17 "
18
19LAYERSERIES_COMPAT_xilinx-virtualization = "scarthgap"
20
21XILINX_XEN_VERSION[v2024.1] = "4.18+stable-xilinx+git%"
22PREFERRED_VERSION_xen ?= "${@d.getVarFlag('XILINX_XEN_VERSION', d.getVar('XILINX_RELEASE_VERSION')) or '4.18+stable-xilinx+git%'}"
23PREFERRED_VERSION_xen-tools ?= "${@d.getVarFlag('XILINX_XEN_VERSION', d.getVar('XILINX_RELEASE_VERSION')) or '4.18+stable-xilinx+git%'}"
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-native_%.bbappend b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-native_%.bbappend
new file mode 100644
index 00000000..e84844cf
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-native_%.bbappend
@@ -0,0 +1 @@
require qemu-tpm.inc
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-system-native_%.bbappend b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-system-native_%.bbappend
new file mode 100644
index 00000000..e84844cf
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-system-native_%.bbappend
@@ -0,0 +1 @@
require qemu-tpm.inc
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-tpm.inc b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-tpm.inc
new file mode 100644
index 00000000..a582b035
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-tpm.inc
@@ -0,0 +1,4 @@
1PACKAGECONFIG:append = "${@bb.utils.contains('DISTRO_FEATURES', 'tpm', ' tpm', '', d)}"
2
3PACKAGECONFIG[tpm] = "--enable-tpm,--disable-tpm,,swtpm libtpm"
4
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xen_8.1.inc b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xen_8.1.inc
new file mode 100644
index 00000000..c674dc1a
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xen_8.1.inc
@@ -0,0 +1,20 @@
1# Xen-4.18 specific changes are only applicable on the target
2SRC_URI_XEN = ""
3SRC_URI_XEN:class-target = " \
4 file://0001-xen_arm-Create-virtio-mmio-devices-during-initializa.patch \
5 file://0002-xen_arm-Initialize-RAM-and-add-hi-low-memory-regions.patch \
6 file://0003-Xen-Fix-xen_set_irq-and-xendevicemodel_set_irq_level.patch \
7 file://0004-xen-when-unplugging-emulated-devices-skip-virtio-dev.patch \
8 file://0005-softmmu-physmem-Split-ram_block_add.patch \
9 file://0006-xen-add-pseudo-RAM-region-for-grant-mappings.patch \
10 file://0007-softmmu-let-qemu_map_ram_ptr-use-qemu_ram_ptr_length.patch \
11 file://0008-xen-let-xen_ram_addr_from_mapcache-return-1-in-case-.patch \
12 file://0009-memory-add-MemoryRegion-map-and-unmap-callbacks.patch \
13 file://0010-xen-add-map-and-unmap-callbacks-for-grant-region.patch \
14 file://0011-hw-arm-Add-grant-mapping.patch \
15 file://0001-arm-xenpvh-Introduce-virtio-pci-support.patch \
16 "
17
18FILESEXTRAPATHS:prepend:class-target := "${THISDIR}/qemu-xilinx-8.1:"
19
20SRC_URI .= "${@bb.utils.contains('DISTRO_FEATURES', 'xen', '${SRC_URI_XEN}', '', d)}"
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-arm-xenpvh-Introduce-virtio-pci-support.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-arm-xenpvh-Introduce-virtio-pci-support.patch
new file mode 100644
index 00000000..6e3b40f7
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-arm-xenpvh-Introduce-virtio-pci-support.patch
@@ -0,0 +1,353 @@
1From 3104d411ee36487ea409ba5a1b474989326f70f2 Mon Sep 17 00:00:00 2001
2From: Vikram Garhwal <vikram.garhwal@amd.com>
3Date: Wed, 15 Nov 2023 14:19:31 -0800
4Subject: [PATCH] arm: xenpvh: Introduce virtio-pci support
5
6The bridge is needed for virtio-pci support, as QEMU can emulate the
7whole bridge with any virtio-pci devices connected to it.
8
9NOTE: A few xen-hvm-common.c and xen_native.h changes are cherry-picked from
10EPAM QEMU patches for xen-arm. This was done to keep least diff with upstream.
11
12Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
13Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
14Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
15---
16 hw/arm/xen_arm.c | 271 ++++++++++++++++++++++++++++++++++++
17 include/hw/xen/xen_native.h | 3 +
18 2 files changed, 274 insertions(+)
19
20diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
21index 1587e2a43b..a7c5b20777 100644
22--- a/hw/arm/xen_arm.c
23+++ b/hw/arm/xen_arm.c
24@@ -34,6 +34,7 @@
25 #include "hw/xen/xen-hvm-common.h"
26 #include "sysemu/tpm.h"
27 #include "hw/xen/arch_hvm.h"
28+#include "hw/pci-host/gpex.h"
29
30 #define TYPE_XEN_ARM MACHINE_TYPE_NAME("xenpvh")
31 OBJECT_DECLARE_SIMPLE_TYPE(XenArmState, XEN_ARM)
32@@ -57,6 +58,9 @@ struct XenArmState {
33
34 struct {
35 uint64_t tpm_base_addr;
36+ MemMapEntry pcie_mmio;
37+ MemMapEntry pcie_ecam;
38+ MemMapEntry pcie_mmio_high;
39 } cfg;
40 };
41
42@@ -132,6 +136,80 @@ static void xen_init_ram(MachineState *machine)
43 ram_grants = *xen_init_grant_ram();
44 }
45
46+static bool xen_validate_pcie_config(XenArmState *xam)
47+{
48+ if (xam->cfg.pcie_ecam.base == 0 &&
49+ xam->cfg.pcie_ecam.size == 0 &&
50+ xam->cfg.pcie_mmio.base == 0 &&
51+ xam->cfg.pcie_mmio.size == 0 &&
52+ xam->cfg.pcie_mmio_high.base == 0 &&
53+ xam->cfg.pcie_mmio_high.size == 0) {
54+ /* It's okay, user just don't want PCIe brige */
55+ return false;
56+ }
57+
58+ if (xam->cfg.pcie_ecam.base == 0 ||
59+ xam->cfg.pcie_ecam.size == 0 ||
60+ xam->cfg.pcie_mmio.base == 0 ||
61+ xam->cfg.pcie_mmio.size == 0 ||
62+ xam->cfg.pcie_mmio_high.base == 0 ||
63+ xam->cfg.pcie_mmio_high.size == 0) {
64+ /* User provided some PCIe options, but not all of them */
65+ error_printf("Incomplete PCIe bridge configuration\n");
66+ exit(1);
67+ }
68+
69+ return true;
70+}
71+
72+static void xen_create_pcie(XenArmState *xam)
73+{
74+ MemoryRegion *mmio_alias, *mmio_alias_high, *mmio_reg;
75+ MemoryRegion *ecam_alias, *ecam_reg;
76+ DeviceState *dev;
77+ int i;
78+
79+ dev = qdev_new(TYPE_GPEX_HOST);
80+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
81+
82+ /* Map ECAM space */
83+ ecam_alias = g_new0(MemoryRegion, 1);
84+ ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
85+ memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam",
86+ ecam_reg, 0, xam->cfg.pcie_ecam.size);
87+ memory_region_add_subregion(get_system_memory(), xam->cfg.pcie_ecam.base,
88+ ecam_alias);
89+
90+ /* Map the MMIO space */
91+ mmio_alias = g_new0(MemoryRegion, 1);
92+ mmio_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1);
93+ memory_region_init_alias(mmio_alias, OBJECT(dev), "pcie-mmio",
94+ mmio_reg,
95+ xam->cfg.pcie_mmio.base,
96+ xam->cfg.pcie_mmio.size);
97+ memory_region_add_subregion(get_system_memory(), xam->cfg.pcie_mmio.base,
98+ mmio_alias);
99+
100+ /* Map the MMIO_HIGH space */
101+ mmio_alias_high = g_new0(MemoryRegion, 1);
102+ memory_region_init_alias(mmio_alias_high, OBJECT(dev), "pcie-mmio-high",
103+ mmio_reg,
104+ xam->cfg.pcie_mmio_high.base,
105+ xam->cfg.pcie_mmio_high.size);
106+ memory_region_add_subregion(get_system_memory(),
107+ xam->cfg.pcie_mmio_high.base,
108+ mmio_alias_high);
109+
110+ /* Legacy PCI interrupts (#INTA - #INTD) */
111+ for (i = 0; i < GPEX_NUM_IRQS; i++) {
112+ qemu_irq irq = qemu_allocate_irq(xen_set_irq, NULL,
113+ GUEST_VIRTIO_PCI_SPI_FIRST + i);
114+
115+ sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq);
116+ gpex_set_irq_num(GPEX_HOST(dev), i, GUEST_VIRTIO_PCI_SPI_FIRST + i);
117+ }
118+}
119+
120 void arch_handle_ioreq(XenIOState *state, ioreq_t *req)
121 {
122 hw_error("Invalid ioreq type 0x%x\n", req->type);
123@@ -193,6 +271,13 @@ static void xen_arm_init(MachineState *machine)
124
125 xen_create_virtio_mmio_devices(xam);
126
127+ if (xen_validate_pcie_config(xam)) {
128+ xen_create_pcie(xam);
129+ } else {
130+ DPRINTF("PCIe host bridge is not configured,"
131+ " only virtio-mmio can be used\n");
132+ }
133+
134 #ifdef CONFIG_TPM
135 if (xam->cfg.tpm_base_addr) {
136 xen_enable_tpm(xam);
137@@ -228,6 +313,150 @@ static void xen_arm_set_tpm_base_addr(Object *obj, Visitor *v,
138 }
139 #endif
140
141+static void xen_arm_get_pcie_ecam_base_addr(Object *obj, Visitor *v,
142+ const char *name, void *opaque,
143+ Error **errp)
144+{
145+ XenArmState *xam = XEN_ARM(obj);
146+ uint64_t value = xam->cfg.pcie_ecam.base;
147+
148+ visit_type_uint64(v, name, &value, errp);
149+}
150+
151+static void xen_arm_set_pcie_ecam_base_addr(Object *obj, Visitor *v,
152+ const char *name, void *opaque,
153+ Error **errp)
154+{
155+ XenArmState *xam = XEN_ARM(obj);
156+ uint64_t value;
157+
158+ if (!visit_type_uint64(v, name, &value, errp)) {
159+ return;
160+ }
161+
162+ xam->cfg.pcie_ecam.base = value;
163+}
164+
165+static void xen_arm_get_pcie_ecam_size(Object *obj, Visitor *v,
166+ const char *name, void *opaque,
167+ Error **errp)
168+{
169+ XenArmState *xam = XEN_ARM(obj);
170+ uint64_t value = xam->cfg.pcie_ecam.size;
171+
172+ visit_type_uint64(v, name, &value, errp);
173+}
174+
175+static void xen_arm_set_pcie_ecam_size(Object *obj, Visitor *v,
176+ const char *name, void *opaque,
177+ Error **errp)
178+{
179+ XenArmState *xam = XEN_ARM(obj);
180+ uint64_t value;
181+
182+ if (!visit_type_uint64(v, name, &value, errp)) {
183+ return;
184+ }
185+
186+ xam->cfg.pcie_ecam.size = value;
187+}
188+
189+static void xen_arm_get_pcie_mmio_base_addr(Object *obj, Visitor *v,
190+ const char *name, void *opaque,
191+ Error **errp)
192+{
193+ XenArmState *xam = XEN_ARM(obj);
194+ uint64_t value = xam->cfg.pcie_mmio.base;
195+
196+ visit_type_uint64(v, name, &value, errp);
197+}
198+
199+static void xen_arm_set_pcie_mmio_base_addr(Object *obj, Visitor *v,
200+ const char *name, void *opaque,
201+ Error **errp)
202+{
203+ XenArmState *xam = XEN_ARM(obj);
204+ uint64_t value;
205+
206+ if (!visit_type_uint64(v, name, &value, errp)) {
207+ return;
208+ }
209+
210+ xam->cfg.pcie_mmio.base = value;
211+}
212+
213+static void xen_arm_get_pcie_mmio_size(Object *obj, Visitor *v,
214+ const char *name, void *opaque,
215+ Error **errp)
216+{
217+ XenArmState *xam = XEN_ARM(obj);
218+ uint64_t value = xam->cfg.pcie_mmio.size;
219+
220+ visit_type_uint64(v, name, &value, errp);
221+}
222+
223+static void xen_arm_set_pcie_mmio_size(Object *obj, Visitor *v,
224+ const char *name, void *opaque,
225+ Error **errp)
226+{
227+ XenArmState *xam = XEN_ARM(obj);
228+ uint64_t value;
229+
230+ if (!visit_type_uint64(v, name, &value, errp)) {
231+ return;
232+ }
233+
234+ xam->cfg.pcie_mmio.size = value;
235+}
236+
237+static void xen_arm_get_pcie_prefetch_base_addr(Object *obj, Visitor *v,
238+ const char *name, void *opaque,
239+ Error **errp)
240+{
241+ XenArmState *xam = XEN_ARM(obj);
242+ uint64_t value = xam->cfg.pcie_mmio_high.base;
243+
244+ visit_type_uint64(v, name, &value, errp);
245+}
246+
247+static void xen_arm_set_pcie_prefetch_base_addr(Object *obj, Visitor *v,
248+ const char *name, void *opaque,
249+ Error **errp)
250+{
251+ XenArmState *xam = XEN_ARM(obj);
252+ uint64_t value;
253+
254+ if (!visit_type_uint64(v, name, &value, errp)) {
255+ return;
256+ }
257+
258+ xam->cfg.pcie_mmio_high.base = value;
259+}
260+
261+static void xen_arm_get_pcie_prefetch_size(Object *obj, Visitor *v,
262+ const char *name, void *opaque,
263+ Error **errp)
264+{
265+ XenArmState *xam = XEN_ARM(obj);
266+ uint64_t value = xam->cfg.pcie_mmio_high.size;
267+
268+ visit_type_uint64(v, name, &value, errp);
269+}
270+
271+static void xen_arm_set_pcie_prefetch_size(Object *obj, Visitor *v,
272+ const char *name, void *opaque,
273+ Error **errp)
274+{
275+ XenArmState *xam = XEN_ARM(obj);
276+ uint64_t value;
277+
278+ if (!visit_type_uint64(v, name, &value, errp)) {
279+ return;
280+ }
281+
282+ xam->cfg.pcie_mmio_high.size = value;
283+}
284+
285 static void xen_arm_machine_class_init(ObjectClass *oc, void *data)
286 {
287
288@@ -249,6 +478,48 @@ static void xen_arm_machine_class_init(ObjectClass *oc, void *data)
289
290 machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
291 #endif
292+
293+ object_class_property_add(oc, "pci-ecam-base-addr", "uint64_t",
294+ xen_arm_get_pcie_ecam_base_addr,
295+ xen_arm_set_pcie_ecam_base_addr,
296+ NULL, NULL);
297+ object_class_property_set_description(oc, "pci-ecam-base-addr",
298+ "Set Base address for PCI ECAM.");
299+
300+ object_class_property_add(oc, "pci-ecam-size", "uint64_t",
301+ xen_arm_get_pcie_ecam_size,
302+ xen_arm_set_pcie_ecam_size,
303+ NULL, NULL);
304+ object_class_property_set_description(oc, "pci-ecam-size",
305+ "Set Size for PCI ECAM.");
306+
307+ object_class_property_add(oc, "pci-mmio-base-addr", "uint64_t",
308+ xen_arm_get_pcie_mmio_base_addr,
309+ xen_arm_set_pcie_mmio_base_addr,
310+ NULL, NULL);
311+ object_class_property_set_description(oc, "pci-mmio-base-addr",
312+ "Set Base address for PCI MMIO.");
313+
314+ object_class_property_add(oc, "pci-mmio-size", "uint64_t",
315+ xen_arm_get_pcie_mmio_size,
316+ xen_arm_set_pcie_mmio_size,
317+ NULL, NULL);
318+ object_class_property_set_description(oc, "pci-mmio-size",
319+ "Set size for PCI MMIO.");
320+
321+ object_class_property_add(oc, "pci-prefetch-base-addr", "uint64_t",
322+ xen_arm_get_pcie_prefetch_base_addr,
323+ xen_arm_set_pcie_prefetch_base_addr,
324+ NULL, NULL);
325+ object_class_property_set_description(oc, "pci-prefetch-base-addr",
326+ "Set Prefetch Base address for PCI.");
327+
328+ object_class_property_add(oc, "pci-prefetch-size", "uint64_t",
329+ xen_arm_get_pcie_prefetch_size,
330+ xen_arm_set_pcie_prefetch_size,
331+ NULL, NULL);
332+ object_class_property_set_description(oc, "pci-prefetch-size",
333+ "Set Prefetch size for PCI.");
334 }
335
336 static const TypeInfo xen_arm_machine_type = {
337diff --git a/include/hw/xen/xen_native.h b/include/hw/xen/xen_native.h
338index 6f09c48823..1e81189a27 100644
339--- a/include/hw/xen/xen_native.h
340+++ b/include/hw/xen/xen_native.h
341@@ -539,6 +539,9 @@ static inline int xendevicemodel_set_irq_level(xendevicemodel_handle *dmod,
342 #define GUEST_VIRTIO_MMIO_SPI_LAST 43
343 #endif
344
345+#define GUEST_VIRTIO_PCI_SPI_FIRST 44
346+#define GUEST_VIRTIO_PCI_SPI_LAST 48
347+
348 #if defined(__i386__) || defined(__x86_64__)
349 #define GUEST_RAM_BANKS 2
350 #define GUEST_RAM0_BASE 0x40000000ULL /* 3GB of low RAM @ 1GB */
351--
3522.30.2
353
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-xen_arm-Create-virtio-mmio-devices-during-initializa.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-xen_arm-Create-virtio-mmio-devices-during-initializa.patch
new file mode 100644
index 00000000..1757e9e2
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0001-xen_arm-Create-virtio-mmio-devices-during-initializa.patch
@@ -0,0 +1,116 @@
1From b9291457ca2eb4340c71d2eed08fde83916c9fa4 Mon Sep 17 00:00:00 2001
2From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
3Date: Tue, 29 Aug 2023 21:35:17 -0700
4Subject: [PATCH 01/11] xen_arm: Create virtio-mmio devices during
5 initialization
6
7In order to use virtio backends we need to allocate virtio-mmio
8parameters (irq and base) and register corresponding buses.
9
10Use the constants defined in public header arch-arm.h to be
11aligned with the toolstack. So the number of current supported
12virtio-mmio devices is 10.
13
14For the interrupts triggering use already existing on Arm
15device-model hypercall.
16
17The toolstack should then insert the same amount of device nodes
18into guest device-tree.
19
20Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
21Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
22Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
23Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
24---
25 hw/arm/xen_arm.c | 35 +++++++++++++++++++++++++++++++++++
26 include/hw/xen/xen_native.h | 16 ++++++++++++++++
27 2 files changed, 51 insertions(+)
28
29diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
30index 1d3e6d481a..7393b37355 100644
31--- a/hw/arm/xen_arm.c
32+++ b/hw/arm/xen_arm.c
33@@ -26,6 +26,7 @@
34 #include "qapi/qapi-commands-migration.h"
35 #include "qapi/visitor.h"
36 #include "hw/boards.h"
37+#include "hw/irq.h"
38 #include "hw/sysbus.h"
39 #include "sysemu/block-backend.h"
40 #include "sysemu/tpm_backend.h"
41@@ -59,6 +60,38 @@ struct XenArmState {
42 } cfg;
43 };
44
45+/*
46+ * VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen
47+ * repository.
48+ *
49+ * Origin: git://xenbits.xen.org/xen.git 2128143c114c
50+ */
51+#define VIRTIO_MMIO_DEV_SIZE 0x200
52+
53+#define NR_VIRTIO_MMIO_DEVICES \
54+ (GUEST_VIRTIO_MMIO_SPI_LAST - GUEST_VIRTIO_MMIO_SPI_FIRST)
55+
56+static void xen_set_irq(void *opaque, int irq, int level)
57+{
58+ xendevicemodel_set_irq_level(xen_dmod, xen_domid, irq, level);
59+}
60+
61+static void xen_create_virtio_mmio_devices(XenArmState *xam)
62+{
63+ int i;
64+
65+ for (i = 0; i < NR_VIRTIO_MMIO_DEVICES; i++) {
66+ hwaddr base = GUEST_VIRTIO_MMIO_BASE + i * VIRTIO_MMIO_DEV_SIZE;
67+ qemu_irq irq = qemu_allocate_irq(xen_set_irq, NULL,
68+ GUEST_VIRTIO_MMIO_SPI_FIRST + i);
69+
70+ sysbus_create_simple("virtio-mmio", base, irq);
71+
72+ DPRINTF("Created virtio-mmio device %d: irq %d base 0x%lx\n",
73+ i, GUEST_VIRTIO_MMIO_SPI_FIRST + i, base);
74+ }
75+}
76+
77 void arch_handle_ioreq(XenIOState *state, ioreq_t *req)
78 {
79 hw_error("Invalid ioreq type 0x%x\n", req->type);
80@@ -110,6 +143,8 @@ static void xen_arm_init(MachineState *machine)
81
82 xen_register_ioreq(xam->state, machine->smp.cpus, &xen_memory_listener);
83
84+ xen_create_virtio_mmio_devices(xam);
85+
86 #ifdef CONFIG_TPM
87 if (xam->cfg.tpm_base_addr) {
88 xen_enable_tpm(xam);
89diff --git a/include/hw/xen/xen_native.h b/include/hw/xen/xen_native.h
90index 4dce905fde..a4b1aa9e5d 100644
91--- a/include/hw/xen/xen_native.h
92+++ b/include/hw/xen/xen_native.h
93@@ -523,4 +523,20 @@ static inline int xen_set_ioreq_server_state(domid_t dom,
94 enable);
95 }
96
97+#if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41500
98+static inline int xendevicemodel_set_irq_level(xendevicemodel_handle *dmod,
99+ domid_t domid, uint32_t irq,
100+ unsigned int level)
101+{
102+ return 0;
103+}
104+#endif
105+
106+#if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41700
107+#define GUEST_VIRTIO_MMIO_BASE xen_mk_ullong(0x02000000)
108+#define GUEST_VIRTIO_MMIO_SIZE xen_mk_ullong(0x00100000)
109+#define GUEST_VIRTIO_MMIO_SPI_FIRST 33
110+#define GUEST_VIRTIO_MMIO_SPI_LAST 43
111+#endif
112+
113 #endif /* QEMU_HW_XEN_NATIVE_H */
114--
1152.39.2
116
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0002-xen_arm-Initialize-RAM-and-add-hi-low-memory-regions.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0002-xen_arm-Initialize-RAM-and-add-hi-low-memory-regions.patch
new file mode 100644
index 00000000..f88db620
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0002-xen_arm-Initialize-RAM-and-add-hi-low-memory-regions.patch
@@ -0,0 +1,124 @@
1From 70a74795c5071bf591e6e557b7c8c492ead0e675 Mon Sep 17 00:00:00 2001
2From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
3Date: Tue, 29 Aug 2023 21:35:18 -0700
4Subject: [PATCH 02/11] xen_arm: Initialize RAM and add hi/low memory regions
5
6In order to use virtio backends we need to initialize RAM for the
7xen-mapcache (which is responsible for mapping guest memory using foreign
8mapping) to work. Calculate and add hi/low memory regions based on
9machine->ram_size.
10
11Use the constants defined in public header arch-arm.h to be aligned with the xen
12toolstack.
13
14While using this machine, the toolstack should then pass real ram_size using
15"-m" arg. If "-m" is not given, create a QEMU machine without IOREQ and other
16emulated devices like TPM and VIRTIO. This is done to keep this QEMU machine
17usable for /etc/init.d/xencommons.
18
19Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
20Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
21Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
22Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
23---
24 hw/arm/xen_arm.c | 45 +++++++++++++++++++++++++++++++++++++
25 include/hw/xen/xen_native.h | 8 +++++++
26 2 files changed, 53 insertions(+)
27
28diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
29index 7393b37355..f83b983ec5 100644
30--- a/hw/arm/xen_arm.c
31+++ b/hw/arm/xen_arm.c
32@@ -60,6 +60,8 @@ struct XenArmState {
33 } cfg;
34 };
35
36+static MemoryRegion ram_lo, ram_hi;
37+
38 /*
39 * VIRTIO_MMIO_DEV_SIZE is imported from tools/libs/light/libxl_arm.c under Xen
40 * repository.
41@@ -92,6 +94,39 @@ static void xen_create_virtio_mmio_devices(XenArmState *xam)
42 }
43 }
44
45+static void xen_init_ram(MachineState *machine)
46+{
47+ MemoryRegion *sysmem = get_system_memory();
48+ ram_addr_t block_len, ram_size[GUEST_RAM_BANKS];
49+
50+ if (machine->ram_size <= GUEST_RAM0_SIZE) {
51+ ram_size[0] = machine->ram_size;
52+ ram_size[1] = 0;
53+ block_len = GUEST_RAM0_BASE + ram_size[0];
54+ } else {
55+ ram_size[0] = GUEST_RAM0_SIZE;
56+ ram_size[1] = machine->ram_size - GUEST_RAM0_SIZE;
57+ block_len = GUEST_RAM1_BASE + ram_size[1];
58+ }
59+
60+ memory_region_init_ram(&ram_memory, NULL, "xen.ram", block_len,
61+ &error_fatal);
62+
63+ memory_region_init_alias(&ram_lo, NULL, "xen.ram.lo", &ram_memory,
64+ GUEST_RAM0_BASE, ram_size[0]);
65+ memory_region_add_subregion(sysmem, GUEST_RAM0_BASE, &ram_lo);
66+ DPRINTF("Initialized region xen.ram.lo: base 0x%llx size 0x%lx\n",
67+ GUEST_RAM0_BASE, ram_size[0]);
68+
69+ if (ram_size[1] > 0) {
70+ memory_region_init_alias(&ram_hi, NULL, "xen.ram.hi", &ram_memory,
71+ GUEST_RAM1_BASE, ram_size[1]);
72+ memory_region_add_subregion(sysmem, GUEST_RAM1_BASE, &ram_hi);
73+ DPRINTF("Initialized region xen.ram.hi: base 0x%llx size 0x%lx\n",
74+ GUEST_RAM1_BASE, ram_size[1]);
75+ }
76+}
77+
78 void arch_handle_ioreq(XenIOState *state, ioreq_t *req)
79 {
80 hw_error("Invalid ioreq type 0x%x\n", req->type);
81@@ -141,6 +176,14 @@ static void xen_arm_init(MachineState *machine)
82
83 xam->state = g_new0(XenIOState, 1);
84
85+ if (machine->ram_size == 0) {
86+ DPRINTF("ram_size not specified. QEMU machine started without IOREQ"
87+ "(no emulated devices including Virtio)\n");
88+ return;
89+ }
90+
91+ xen_init_ram(machine);
92+
93 xen_register_ioreq(xam->state, machine->smp.cpus, &xen_memory_listener);
94
95 xen_create_virtio_mmio_devices(xam);
96@@ -188,6 +231,8 @@ static void xen_arm_machine_class_init(ObjectClass *oc, void *data)
97 mc->init = xen_arm_init;
98 mc->max_cpus = 1;
99 mc->default_machine_opts = "accel=xen";
100+ /* Set explicitly here to make sure that real ram_size is passed */
101+ mc->default_ram_size = 0;
102
103 #ifdef CONFIG_TPM
104 object_class_property_add(oc, "tpm-base-addr", "uint64_t",
105diff --git a/include/hw/xen/xen_native.h b/include/hw/xen/xen_native.h
106index a4b1aa9e5d..5d2718261f 100644
107--- a/include/hw/xen/xen_native.h
108+++ b/include/hw/xen/xen_native.h
109@@ -539,4 +539,12 @@ static inline int xendevicemodel_set_irq_level(xendevicemodel_handle *dmod,
110 #define GUEST_VIRTIO_MMIO_SPI_LAST 43
111 #endif
112
113+#if defined(__i386__) || defined(__x86_64__)
114+#define GUEST_RAM_BANKS 2
115+#define GUEST_RAM0_BASE 0x40000000ULL /* 3GB of low RAM @ 1GB */
116+#define GUEST_RAM0_SIZE 0xc0000000ULL
117+#define GUEST_RAM1_BASE 0x0200000000ULL /* 1016GB of RAM @ 8GB */
118+#define GUEST_RAM1_SIZE 0xfe00000000ULL
119+#endif
120+
121 #endif /* QEMU_HW_XEN_NATIVE_H */
122--
1232.39.2
124
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0003-Xen-Fix-xen_set_irq-and-xendevicemodel_set_irq_level.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0003-Xen-Fix-xen_set_irq-and-xendevicemodel_set_irq_level.patch
new file mode 100644
index 00000000..c6945d54
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0003-Xen-Fix-xen_set_irq-and-xendevicemodel_set_irq_level.patch
@@ -0,0 +1,55 @@
1From 14b9dbd7f0261ae7a36bef251924ba211beef17a Mon Sep 17 00:00:00 2001
2From: Vikram Garhwal <vikram.garhwal@amd.com>
3Date: Wed, 1 Nov 2023 14:07:23 -0700
4Subject: [PATCH 03/11] Xen: Fix xen_set_irq() and
5 xendevicemodel_set_irq_level()
6
7Remove '=' from 'if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41500'.
8Because xendevicemodel_set_irq_level() was introduced in 4.15 version.
9
10Also, update xendevicemodel_set_irq_level() to return -1 for older versions.
11
12Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
13Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
14---
15 hw/arm/xen_arm.c | 4 +++-
16 include/hw/xen/xen_native.h | 4 ++--
17 2 files changed, 5 insertions(+), 3 deletions(-)
18
19diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
20index f83b983ec5..a5631529d0 100644
21--- a/hw/arm/xen_arm.c
22+++ b/hw/arm/xen_arm.c
23@@ -75,7 +75,9 @@ static MemoryRegion ram_lo, ram_hi;
24
25 static void xen_set_irq(void *opaque, int irq, int level)
26 {
27- xendevicemodel_set_irq_level(xen_dmod, xen_domid, irq, level);
28+ if (xendevicemodel_set_irq_level(xen_dmod, xen_domid, irq, level)) {
29+ error_report("xendevicemodel_set_irq_level failed");
30+ }
31 }
32
33 static void xen_create_virtio_mmio_devices(XenArmState *xam)
34diff --git a/include/hw/xen/xen_native.h b/include/hw/xen/xen_native.h
35index 5d2718261f..6f09c48823 100644
36--- a/include/hw/xen/xen_native.h
37+++ b/include/hw/xen/xen_native.h
38@@ -523,12 +523,12 @@ static inline int xen_set_ioreq_server_state(domid_t dom,
39 enable);
40 }
41
42-#if CONFIG_XEN_CTRL_INTERFACE_VERSION <= 41500
43+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41500
44 static inline int xendevicemodel_set_irq_level(xendevicemodel_handle *dmod,
45 domid_t domid, uint32_t irq,
46 unsigned int level)
47 {
48- return 0;
49+ return -1;
50 }
51 #endif
52
53--
542.39.2
55
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0004-xen-when-unplugging-emulated-devices-skip-virtio-dev.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0004-xen-when-unplugging-emulated-devices-skip-virtio-dev.patch
new file mode 100644
index 00000000..da2f042b
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0004-xen-when-unplugging-emulated-devices-skip-virtio-dev.patch
@@ -0,0 +1,70 @@
1From 02507086b3ad9beb9c669aae54fcb4857cd61ef8 Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Tue, 16 Mar 2021 14:00:33 +0100
4Subject: [PATCH 04/11] xen: when unplugging emulated devices skip virtio
5 devices
6
7Virtio devices should never be unplugged at boot time, as they are
8similar to pci passthrough devices.
9
10Signed-off-by: Juergen Gross <jgross@suse.com>
11Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
12---
13 docs/system/i386/xen.rst | 3 ---
14 hw/i386/xen/xen_platform.c | 10 ++++++++--
15 2 files changed, 8 insertions(+), 5 deletions(-)
16
17diff --git a/docs/system/i386/xen.rst b/docs/system/i386/xen.rst
18index f06765e88c..b86d57af6e 100644
19--- a/docs/system/i386/xen.rst
20+++ b/docs/system/i386/xen.rst
21@@ -52,9 +52,6 @@ It is necessary to use the pc machine type, as the q35 machine uses AHCI instead
22 of legacy IDE, and AHCI disks are not unplugged through the Xen PV unplug
23 mechanism.
24
25-VirtIO devices can also be used; Linux guests may need to be dissuaded from
26-umplugging them by adding 'xen_emul_unplug=never' on their command line.
27-
28 Properties
29 ----------
30
31diff --git a/hw/i386/xen/xen_platform.c b/hw/i386/xen/xen_platform.c
32index 17457ff3de..0187b73eeb 100644
33--- a/hw/i386/xen/xen_platform.c
34+++ b/hw/i386/xen/xen_platform.c
35@@ -28,6 +28,7 @@
36 #include "hw/ide/pci.h"
37 #include "hw/pci/pci.h"
38 #include "migration/vmstate.h"
39+#include "hw/virtio/virtio-bus.h"
40 #include "net/net.h"
41 #include "trace.h"
42 #include "sysemu/xen.h"
43@@ -129,10 +130,11 @@ static bool pci_device_is_passthrough(PCIDevice *d)
44
45 static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
46 {
47- /* We have to ignore passthrough devices */
48+ /* We have to ignore passthrough devices and virtio devices. */
49 if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
50 PCI_CLASS_NETWORK_ETHERNET
51- && !pci_device_is_passthrough(d)) {
52+ && !pci_device_is_passthrough(d)
53+ && !qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) {
54 object_unparent(OBJECT(d));
55 }
56 }
57@@ -208,6 +210,10 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *opaque)
58 /* We have to ignore passthrough devices */
59 if (pci_device_is_passthrough(d))
60 return;
61+ /* Ignore virtio devices */
62+ if (qdev_get_child_bus(&d->qdev, TYPE_VIRTIO_BUS)) {
63+ return;
64+ }
65
66 switch (pci_get_word(d->config + PCI_CLASS_DEVICE)) {
67 case PCI_CLASS_STORAGE_IDE:
68--
692.39.2
70
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0005-softmmu-physmem-Split-ram_block_add.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0005-softmmu-physmem-Split-ram_block_add.patch
new file mode 100644
index 00000000..3c39dd19
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0005-softmmu-physmem-Split-ram_block_add.patch
@@ -0,0 +1,117 @@
1From d4774a0e5e1ebed605c5d49e81433fd371d0b680 Mon Sep 17 00:00:00 2001
2From: Vikram Garhwal <vikram.garhwal@amd.com>
3Date: Tue, 17 Oct 2023 20:22:26 +0000
4Subject: [PATCH 05/11] softmmu: physmem: Split ram_block_add()
5
6Extract ram block list update to a new function ram_block_add_list(). This is
7done to support grant mappings which adds a memory region for granted memory and
8updates the ram_block list.
9
10Signed-off-by: Juergen Gross <jgross@suse.com>
11Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
12Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
13---
14 include/exec/ram_addr.h | 1 +
15 softmmu/physmem.c | 62 ++++++++++++++++++++++++++---------------
16 2 files changed, 40 insertions(+), 23 deletions(-)
17
18diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
19index 9f2e3893f5..76fa360463 100644
20--- a/include/exec/ram_addr.h
21+++ b/include/exec/ram_addr.h
22@@ -139,6 +139,7 @@ void qemu_ram_free(RAMBlock *block);
23 int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp);
24
25 void qemu_ram_msync(RAMBlock *block, ram_addr_t start, ram_addr_t length);
26+void ram_block_add_list(RAMBlock *new_block);
27
28 /* Clear whole block of mem */
29 static inline void qemu_ram_block_writeback(RAMBlock *block)
30diff --git a/softmmu/physmem.c b/softmmu/physmem.c
31index 3df73542e1..f73629733e 100644
32--- a/softmmu/physmem.c
33+++ b/softmmu/physmem.c
34@@ -1786,12 +1786,47 @@ static void dirty_memory_extend(ram_addr_t old_ram_size,
35 }
36 }
37
38+static void ram_block_add_list_locked(RAMBlock *new_block)
39+ {
40+ RAMBlock *block;
41+ RAMBlock *last_block = NULL;
42+
43+ /*
44+ * Keep the list sorted from biggest to smallest block. Unlike QTAILQ,
45+ * QLIST (which has an RCU-friendly variant) does not have insertion at
46+ * tail, so save the last element in last_block.
47+ */
48+ RAMBLOCK_FOREACH(block) {
49+ last_block = block;
50+ if (block->max_length < new_block->max_length) {
51+ break;
52+ }
53+ }
54+ if (block) {
55+ QLIST_INSERT_BEFORE_RCU(block, new_block, next);
56+ } else if (last_block) {
57+ QLIST_INSERT_AFTER_RCU(last_block, new_block, next);
58+ } else { /* list is empty */
59+ QLIST_INSERT_HEAD_RCU(&ram_list.blocks, new_block, next);
60+ }
61+ ram_list.mru_block = NULL;
62+
63+ /* Write list before version */
64+ smp_wmb();
65+ ram_list.version++;
66+}
67+
68+void ram_block_add_list(RAMBlock *new_block)
69+{
70+ qemu_mutex_lock_ramlist();
71+ ram_block_add_list_locked(new_block);
72+ qemu_mutex_unlock_ramlist();
73+}
74+
75 static void ram_block_add(RAMBlock *new_block, Error **errp)
76 {
77 const bool noreserve = qemu_ram_is_noreserve(new_block);
78 const bool shared = qemu_ram_is_shared(new_block);
79- RAMBlock *block;
80- RAMBlock *last_block = NULL;
81 ram_addr_t old_ram_size, new_ram_size;
82 Error *err = NULL;
83
84@@ -1829,28 +1864,9 @@ static void ram_block_add(RAMBlock *new_block, Error **errp)
85 if (new_ram_size > old_ram_size) {
86 dirty_memory_extend(old_ram_size, new_ram_size);
87 }
88- /* Keep the list sorted from biggest to smallest block. Unlike QTAILQ,
89- * QLIST (which has an RCU-friendly variant) does not have insertion at
90- * tail, so save the last element in last_block.
91- */
92- RAMBLOCK_FOREACH(block) {
93- last_block = block;
94- if (block->max_length < new_block->max_length) {
95- break;
96- }
97- }
98- if (block) {
99- QLIST_INSERT_BEFORE_RCU(block, new_block, next);
100- } else if (last_block) {
101- QLIST_INSERT_AFTER_RCU(last_block, new_block, next);
102- } else { /* list is empty */
103- QLIST_INSERT_HEAD_RCU(&ram_list.blocks, new_block, next);
104- }
105- ram_list.mru_block = NULL;
106+
107+ ram_block_add_list_locked(new_block);
108
109- /* Write list before version */
110- smp_wmb();
111- ram_list.version++;
112 qemu_mutex_unlock_ramlist();
113
114 cpu_physical_memory_set_dirty_range(new_block->offset,
115--
1162.39.2
117
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0006-xen-add-pseudo-RAM-region-for-grant-mappings.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0006-xen-add-pseudo-RAM-region-for-grant-mappings.patch
new file mode 100644
index 00000000..a43748fe
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0006-xen-add-pseudo-RAM-region-for-grant-mappings.patch
@@ -0,0 +1,153 @@
1From 637d10471fef76a7ab0e8f5631ea3c85ff5ce9db Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Thu, 20 May 2021 11:19:58 +0200
4Subject: [PATCH 06/11] xen: add pseudo RAM region for grant mappings
5
6Add a memory region which can be used to automatically map granted
7memory. It is starting at 0x8000000000000000ULL in order to be able to
8distinguish it from normal RAM.
9
10For this reason the xen.ram memory region is expanded, which has no
11further impact as it is used just as a container of the real RAM
12regions and now the grant region.
13
14Signed-off-by: Juergen Gross <jgross@suse.com>
15Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
16Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
17---
18 hw/i386/xen/xen-hvm.c | 3 +++
19 hw/xen/xen-hvm-common.c | 4 ++--
20 hw/xen/xen-mapcache.c | 27 +++++++++++++++++++++++++++
21 include/hw/xen/xen-hvm-common.h | 2 ++
22 include/hw/xen/xen_pvdev.h | 3 +++
23 include/sysemu/xen-mapcache.h | 3 +++
24 6 files changed, 40 insertions(+), 2 deletions(-)
25
26diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
27index f42621e674..67a55558a6 100644
28--- a/hw/i386/xen/xen-hvm.c
29+++ b/hw/i386/xen/xen-hvm.c
30@@ -172,6 +172,9 @@ static void xen_ram_init(PCMachineState *pcms,
31 x86ms->above_4g_mem_size);
32 memory_region_add_subregion(sysmem, 0x100000000ULL, &ram_hi);
33 }
34+
35+ /* Add grant mappings as a pseudo RAM region. */
36+ ram_grants = *xen_init_grant_ram();
37 }
38
39 static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size)
40diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c
41index 565dc39c8f..b7255977a5 100644
42--- a/hw/xen/xen-hvm-common.c
43+++ b/hw/xen/xen-hvm-common.c
44@@ -9,7 +9,7 @@
45 #include "hw/boards.h"
46 #include "hw/xen/arch_hvm.h"
47
48-MemoryRegion ram_memory;
49+MemoryRegion ram_memory, ram_grants;
50
51 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr,
52 Error **errp)
53@@ -26,7 +26,7 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr,
54 return;
55 }
56
57- if (mr == &ram_memory) {
58+ if (mr == &ram_memory || mr == &ram_grants) {
59 return;
60 }
61
62diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c
63index f7d974677d..8115c44c00 100644
64--- a/hw/xen/xen-mapcache.c
65+++ b/hw/xen/xen-mapcache.c
66@@ -14,7 +14,9 @@
67
68 #include <sys/resource.h>
69
70+#include "hw/xen/xen-hvm-common.h"
71 #include "hw/xen/xen_native.h"
72+#include "hw/xen/xen_pvdev.h"
73 #include "qemu/bitmap.h"
74
75 #include "sysemu/runstate.h"
76@@ -597,3 +599,28 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr,
77 mapcache_unlock();
78 return p;
79 }
80+
81+MemoryRegion *xen_init_grant_ram(void)
82+{
83+ RAMBlock *block;
84+
85+ memory_region_init(&ram_grants, NULL, "xen.grants",
86+ XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE);
87+ block = g_malloc0(sizeof(*block));
88+ block->mr = &ram_grants;
89+ block->used_length = XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE;
90+ block->max_length = XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE;
91+ block->fd = -1;
92+ block->page_size = XC_PAGE_SIZE;
93+ block->host = (void *)XEN_GRANT_ADDR_OFF;
94+ block->offset = XEN_GRANT_ADDR_OFF;
95+ block->flags = RAM_PREALLOC;
96+ ram_grants.ram_block = block;
97+ ram_grants.ram = true;
98+ ram_grants.terminates = true;
99+ ram_block_add_list(block);
100+ memory_region_add_subregion(get_system_memory(), XEN_GRANT_ADDR_OFF,
101+ &ram_grants);
102+
103+ return &ram_grants;
104+}
105diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-common.h
106index 4e9904f1a6..0d300ba898 100644
107--- a/include/hw/xen/xen-hvm-common.h
108+++ b/include/hw/xen/xen-hvm-common.h
109@@ -17,6 +17,8 @@
110 #include <xen/hvm/ioreq.h>
111
112 extern MemoryRegion ram_memory;
113+
114+extern MemoryRegion ram_grants;
115 extern MemoryListener xen_io_listener;
116 extern DeviceListener xen_device_listener;
117
118diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h
119index ddad4b9f36..0f1b5edfa9 100644
120--- a/include/hw/xen/xen_pvdev.h
121+++ b/include/hw/xen/xen_pvdev.h
122@@ -80,4 +80,7 @@ int xen_pv_send_notify(struct XenLegacyDevice *xendev);
123 void xen_pv_printf(struct XenLegacyDevice *xendev, int msg_level,
124 const char *fmt, ...) G_GNUC_PRINTF(3, 4);
125
126+#define XEN_GRANT_ADDR_OFF 0x8000000000000000ULL
127+#define XEN_MAX_VIRTIO_GRANTS 65536
128+
129 #endif /* QEMU_HW_XEN_PVDEV_H */
130diff --git a/include/sysemu/xen-mapcache.h b/include/sysemu/xen-mapcache.h
131index c8e7c2f6cf..f4bedb1c11 100644
132--- a/include/sysemu/xen-mapcache.h
133+++ b/include/sysemu/xen-mapcache.h
134@@ -10,6 +10,7 @@
135 #define XEN_MAPCACHE_H
136
137 #include "exec/cpu-common.h"
138+#include "exec/ram_addr.h"
139
140 typedef hwaddr (*phys_offset_to_gaddr_t)(hwaddr phys_offset,
141 ram_addr_t size);
142@@ -25,6 +26,8 @@ void xen_invalidate_map_cache(void);
143 uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr,
144 hwaddr new_phys_addr,
145 hwaddr size);
146+MemoryRegion *xen_init_grant_ram(void);
147+
148 #else
149
150 static inline void xen_map_cache_init(phys_offset_to_gaddr_t f,
151--
1522.39.2
153
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0007-softmmu-let-qemu_map_ram_ptr-use-qemu_ram_ptr_length.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0007-softmmu-let-qemu_map_ram_ptr-use-qemu_ram_ptr_length.patch
new file mode 100644
index 00000000..ee400e2c
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0007-softmmu-let-qemu_map_ram_ptr-use-qemu_ram_ptr_length.patch
@@ -0,0 +1,117 @@
1From 82139e7e4bdcf5ca51b2ac90c63e4af699e3eb6f Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Thu, 20 May 2021 11:54:48 +0200
4Subject: [PATCH 07/11] softmmu: let qemu_map_ram_ptr() use
5 qemu_ram_ptr_length()
6
7qemu_map_ram_ptr() and qemu_ram_ptr_length() share quite some code, so
8modify qemu_ram_ptr_length() a little bit and use it for
9qemu_map_ram_ptr(), too.
10
11Signed-off-by: Juergen Gross <jgross@suse.com>
12Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
13Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
14---
15 softmmu/physmem.c | 58 +++++++++++++++++++----------------------------
16 1 file changed, 23 insertions(+), 35 deletions(-)
17
18diff --git a/softmmu/physmem.c b/softmmu/physmem.c
19index f73629733e..a934e44fe7 100644
20--- a/softmmu/physmem.c
21+++ b/softmmu/physmem.c
22@@ -2123,38 +2123,8 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
23 }
24 #endif /* !_WIN32 */
25
26-/* Return a host pointer to ram allocated with qemu_ram_alloc.
27- * This should not be used for general purpose DMA. Use address_space_map
28- * or address_space_rw instead. For local memory (e.g. video ram) that the
29- * device owns, use memory_region_get_ram_ptr.
30- *
31- * Called within RCU critical section.
32- */
33-void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr)
34-{
35- RAMBlock *block = ram_block;
36-
37- if (block == NULL) {
38- block = qemu_get_ram_block(addr);
39- addr -= block->offset;
40- }
41-
42- if (xen_enabled() && block->host == NULL) {
43- /* We need to check if the requested address is in the RAM
44- * because we don't want to map the entire memory in QEMU.
45- * In that case just map until the end of the page.
46- */
47- if (block->offset == 0) {
48- return xen_map_cache(addr, 0, 0, false);
49- }
50-
51- block->host = xen_map_cache(block->offset, block->max_length, 1, false);
52- }
53- return ramblock_ptr(block, addr);
54-}
55-
56-/* Return a host pointer to guest's ram. Similar to qemu_map_ram_ptr
57- * but takes a size argument.
58+/*
59+ * Return a host pointer to guest's ram.
60 *
61 * Called within RCU critical section.
62 */
63@@ -2162,7 +2132,9 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr,
64 hwaddr *size, bool lock)
65 {
66 RAMBlock *block = ram_block;
67- if (*size == 0) {
68+ hwaddr len = 0;
69+
70+ if (size && *size == 0) {
71 return NULL;
72 }
73
74@@ -2170,7 +2142,10 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr,
75 block = qemu_get_ram_block(addr);
76 addr -= block->offset;
77 }
78- *size = MIN(*size, block->max_length - addr);
79+ if (size) {
80+ *size = MIN(*size, block->max_length - addr);
81+ len = *size;
82+ }
83
84 if (xen_enabled() && block->host == NULL) {
85 /* We need to check if the requested address is in the RAM
86@@ -2178,7 +2153,7 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr,
87 * In that case just map the requested area.
88 */
89 if (block->offset == 0) {
90- return xen_map_cache(addr, *size, lock, lock);
91+ return xen_map_cache(addr, len, lock, lock);
92 }
93
94 block->host = xen_map_cache(block->offset, block->max_length, 1, lock);
95@@ -2187,6 +2162,19 @@ static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr,
96 return ramblock_ptr(block, addr);
97 }
98
99+/*
100+ * Return a host pointer to ram allocated with qemu_ram_alloc.
101+ * This should not be used for general purpose DMA. Use address_space_map
102+ * or address_space_rw instead. For local memory (e.g. video ram) that the
103+ * device owns, use memory_region_get_ram_ptr.
104+ *
105+ * Called within RCU critical section.
106+ */
107+void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr)
108+{
109+ return qemu_ram_ptr_length(ram_block, addr, NULL, false);
110+}
111+
112 /* Return the offset of a hostpointer within a ramblock */
113 ram_addr_t qemu_ram_block_host_offset(RAMBlock *rb, void *host)
114 {
115--
1162.39.2
117
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0008-xen-let-xen_ram_addr_from_mapcache-return-1-in-case-.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0008-xen-let-xen_ram_addr_from_mapcache-return-1-in-case-.patch
new file mode 100644
index 00000000..c1e9abd9
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0008-xen-let-xen_ram_addr_from_mapcache-return-1-in-case-.patch
@@ -0,0 +1,49 @@
1From 857bcafe8beb5a0cd78c070f432108049661a56d Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Thu, 20 May 2021 13:31:32 +0200
4Subject: [PATCH 08/11] xen: let xen_ram_addr_from_mapcache() return -1 in case
5 of not found entry
6
7Today xen_ram_addr_from_mapcache() will either abort() or return 0 in
8case it can't find a matching entry for a pointer value. Both cases
9are bad, so change that to return an invalid address instead.
10
11Signed-off-by: Juergen Gross <jgross@suse.com>
12Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
13---
14 hw/xen/xen-mapcache.c | 12 +++---------
15 1 file changed, 3 insertions(+), 9 deletions(-)
16
17diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c
18index 8115c44c00..8a61c7dde6 100644
19--- a/hw/xen/xen-mapcache.c
20+++ b/hw/xen/xen-mapcache.c
21@@ -404,13 +404,8 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
22 }
23 }
24 if (!found) {
25- fprintf(stderr, "%s, could not find %p\n", __func__, ptr);
26- QTAILQ_FOREACH(reventry, &mapcache->locked_entries, next) {
27- DPRINTF(" "HWADDR_FMT_plx" -> %p is present\n", reventry->paddr_index,
28- reventry->vaddr_req);
29- }
30- abort();
31- return 0;
32+ mapcache_unlock();
33+ return RAM_ADDR_INVALID;
34 }
35
36 entry = &mapcache->entry[paddr_index % mapcache->nr_buckets];
37@@ -418,8 +413,7 @@ ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
38 entry = entry->next;
39 }
40 if (!entry) {
41- DPRINTF("Trying to find address %p that is not in the mapcache!\n", ptr);
42- raddr = 0;
43+ raddr = RAM_ADDR_INVALID;
44 } else {
45 raddr = (reventry->paddr_index << MCACHE_BUCKET_SHIFT) +
46 ((unsigned long) ptr - (unsigned long) entry->vaddr_base);
47--
482.39.2
49
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0009-memory-add-MemoryRegion-map-and-unmap-callbacks.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0009-memory-add-MemoryRegion-map-and-unmap-callbacks.patch
new file mode 100644
index 00000000..fa18ef16
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0009-memory-add-MemoryRegion-map-and-unmap-callbacks.patch
@@ -0,0 +1,155 @@
1From 364a11be6274336ec9b0f06f3272f964d27c9349 Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Thu, 27 May 2021 15:27:55 +0200
4Subject: [PATCH 09/11] memory: add MemoryRegion map and unmap callbacks
5
6In order to support mapping and unmapping guest memory dynamically to
7and from qemu during address_space_[un]map() operations add the map()
8and unmap() callbacks to MemoryRegionOps.
9
10Those will be used e.g. for Xen grant mappings when performing guest
11I/Os.
12
13Signed-off-by: Juergen Gross <jgross@suse.com>
14Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
15---
16 include/exec/memory.h | 21 ++++++++++++++++++
17 softmmu/physmem.c | 50 +++++++++++++++++++++++++++++++++----------
18 2 files changed, 60 insertions(+), 11 deletions(-)
19
20diff --git a/include/exec/memory.h b/include/exec/memory.h
21index 68284428f8..55414417ab 100644
22--- a/include/exec/memory.h
23+++ b/include/exec/memory.h
24@@ -274,6 +274,27 @@ struct MemoryRegionOps {
25 unsigned size,
26 MemTxAttrs attrs);
27
28+ /*
29+ * Dynamically create mapping. @addr is the guest address to map; @plen
30+ * is the pointer to the usable length of the buffer.
31+ * @mr contents can be changed in case a new memory region is created for
32+ * the mapping.
33+ * Returns the buffer address for accessing the data.
34+ */
35+ void *(*map)(MemoryRegion **mr,
36+ hwaddr addr,
37+ hwaddr *plen,
38+ bool is_write,
39+ MemTxAttrs attrs);
40+
41+ /* Unmap an area obtained via map() before. */
42+ void (*unmap)(MemoryRegion *mr,
43+ void *buffer,
44+ ram_addr_t addr,
45+ hwaddr len,
46+ bool is_write,
47+ hwaddr access_len);
48+
49 enum device_endian endianness;
50 /* Guest-visible constraints: */
51 struct {
52diff --git a/softmmu/physmem.c b/softmmu/physmem.c
53index a934e44fe7..a1e2030424 100644
54--- a/softmmu/physmem.c
55+++ b/softmmu/physmem.c
56@@ -3070,6 +3070,7 @@ void *address_space_map(AddressSpace *as,
57 hwaddr len = *plen;
58 hwaddr l, xlat;
59 MemoryRegion *mr;
60+ void *ptr = NULL;
61 FlatView *fv;
62
63 if (len == 0) {
64@@ -3103,12 +3104,20 @@ void *address_space_map(AddressSpace *as,
65 return bounce.buffer;
66 }
67
68-
69 memory_region_ref(mr);
70+
71+ if (mr->ops && mr->ops->map) {
72+ ptr = mr->ops->map(&mr, addr, plen, is_write, attrs);
73+ }
74+
75 *plen = flatview_extend_translation(fv, addr, len, mr, xlat,
76 l, is_write, attrs);
77 fuzz_dma_read_cb(addr, *plen, mr);
78- return qemu_ram_ptr_length(mr->ram_block, xlat, plen, true);
79+ if (ptr == NULL) {
80+ ptr = qemu_ram_ptr_length(mr->ram_block, xlat, plen, true);
81+ }
82+
83+ return ptr;
84 }
85
86 /* Unmaps a memory region previously mapped by address_space_map().
87@@ -3124,11 +3133,16 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
88
89 mr = memory_region_from_host(buffer, &addr1);
90 assert(mr != NULL);
91- if (is_write) {
92- invalidate_and_set_dirty(mr, addr1, access_len);
93- }
94- if (xen_enabled()) {
95- xen_invalidate_map_cache_entry(buffer);
96+
97+ if (mr->ops && mr->ops->unmap) {
98+ mr->ops->unmap(mr, buffer, addr1, len, is_write, access_len);
99+ } else {
100+ if (is_write) {
101+ invalidate_and_set_dirty(mr, addr1, access_len);
102+ }
103+ if (xen_enabled()) {
104+ xen_invalidate_map_cache_entry(buffer);
105+ }
106 }
107 memory_region_unref(mr);
108 return;
109@@ -3201,10 +3215,18 @@ int64_t address_space_cache_init(MemoryRegionCache *cache,
110 * doing this if we found actual RAM, which behaves the same
111 * regardless of attributes; so UNSPECIFIED is fine.
112 */
113+ if (mr->ops && mr->ops->map) {
114+ cache->ptr = mr->ops->map(&mr, addr, &l, is_write,
115+ MEMTXATTRS_UNSPECIFIED);
116+ }
117+
118 l = flatview_extend_translation(cache->fv, addr, len, mr,
119 cache->xlat, l, is_write,
120 MEMTXATTRS_UNSPECIFIED);
121- cache->ptr = qemu_ram_ptr_length(mr->ram_block, cache->xlat, &l, true);
122+ if (!cache->ptr) {
123+ cache->ptr = qemu_ram_ptr_length(mr->ram_block, cache->xlat, &l,
124+ true);
125+ }
126 } else {
127 cache->ptr = NULL;
128 }
129@@ -3226,14 +3248,20 @@ void address_space_cache_invalidate(MemoryRegionCache *cache,
130
131 void address_space_cache_destroy(MemoryRegionCache *cache)
132 {
133- if (!cache->mrs.mr) {
134+ MemoryRegion *mr = cache->mrs.mr;
135+
136+ if (!mr) {
137 return;
138 }
139
140- if (xen_enabled()) {
141+ if (mr->ops && mr->ops->unmap) {
142+ mr->ops->unmap(mr, cache->ptr, cache->xlat, cache->len,
143+ cache->is_write, cache->len);
144+ } else if (xen_enabled()) {
145 xen_invalidate_map_cache_entry(cache->ptr);
146 }
147- memory_region_unref(cache->mrs.mr);
148+
149+ memory_region_unref(mr);
150 flatview_unref(cache->fv);
151 cache->mrs.mr = NULL;
152 cache->fv = NULL;
153--
1542.39.2
155
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0010-xen-add-map-and-unmap-callbacks-for-grant-region.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0010-xen-add-map-and-unmap-callbacks-for-grant-region.patch
new file mode 100644
index 00000000..48dcf7d7
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0010-xen-add-map-and-unmap-callbacks-for-grant-region.patch
@@ -0,0 +1,262 @@
1From 90496d4c71e3b9334aebca118661bf72631ed0f0 Mon Sep 17 00:00:00 2001
2From: Juergen Gross <jgross@suse.com>
3Date: Fri, 26 Aug 2022 13:57:06 +0200
4Subject: [PATCH 10/11] xen: add map and unmap callbacks for grant region
5
6Add the callbacks for mapping/unmapping guest memory via grants to the
7special grant memory region.
8
9Signed-off-by: Juergen Gross <jgross@suse.com>
10Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
11---
12 hw/xen/xen-mapcache.c | 176 +++++++++++++++++++++++++++++++++++++++++-
13 softmmu/physmem.c | 11 ++-
14 2 files changed, 182 insertions(+), 5 deletions(-)
15
16diff --git a/hw/xen/xen-mapcache.c b/hw/xen/xen-mapcache.c
17index 8a61c7dde6..e071328fc5 100644
18--- a/hw/xen/xen-mapcache.c
19+++ b/hw/xen/xen-mapcache.c
20@@ -9,6 +9,8 @@
21 */
22
23 #include "qemu/osdep.h"
24+#include "qemu/queue.h"
25+#include "qemu/thread.h"
26 #include "qemu/units.h"
27 #include "qemu/error-report.h"
28
29@@ -23,6 +25,8 @@
30 #include "sysemu/xen-mapcache.h"
31 #include "trace.h"
32
33+#include <xenevtchn.h>
34+#include <xengnttab.h>
35
36 //#define MAPCACHE_DEBUG
37
38@@ -385,7 +389,7 @@ uint8_t *xen_map_cache(hwaddr phys_addr, hwaddr size,
39 return p;
40 }
41
42-ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
43+static ram_addr_t xen_ram_addr_from_mapcache_try(void *ptr)
44 {
45 MapCacheEntry *entry = NULL;
46 MapCacheRev *reventry;
47@@ -594,10 +598,179 @@ uint8_t *xen_replace_cache_entry(hwaddr old_phys_addr,
48 return p;
49 }
50
51+struct XENMappedGrantRegion {
52+ void *addr;
53+ unsigned int pages;
54+ unsigned int refs;
55+ unsigned int prot;
56+ uint32_t idx;
57+ QLIST_ENTRY(XENMappedGrantRegion) list;
58+};
59+
60+static xengnttab_handle *xen_region_gnttabdev;
61+static QLIST_HEAD(GrantRegionList, XENMappedGrantRegion) xen_grant_mappings =
62+ QLIST_HEAD_INITIALIZER(xen_grant_mappings);
63+static QemuMutex xen_map_mutex;
64+
65+static void *xen_map_grant_dyn(MemoryRegion **mr, hwaddr addr, hwaddr *plen,
66+ bool is_write, MemTxAttrs attrs)
67+{
68+ unsigned int page_off = addr & (XC_PAGE_SIZE - 1);
69+ unsigned int i;
70+ unsigned int total_grants = 0;
71+ unsigned int nrefs = (page_off + *plen + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT;
72+ uint32_t ref = (addr - XEN_GRANT_ADDR_OFF) >> XC_PAGE_SHIFT;
73+ uint32_t *refs = NULL;
74+ unsigned int prot = PROT_READ;
75+ struct XENMappedGrantRegion *mgr = NULL;
76+
77+ if (is_write) {
78+ prot |= PROT_WRITE;
79+ }
80+
81+ qemu_mutex_lock(&xen_map_mutex);
82+
83+ QLIST_FOREACH(mgr, &xen_grant_mappings, list) {
84+ if (mgr->idx == ref &&
85+ mgr->pages == nrefs &&
86+ (mgr->prot & prot) == prot) {
87+ break;
88+ }
89+
90+ total_grants += mgr->pages;
91+ }
92+
93+ if (!mgr) {
94+ if (nrefs + total_grants >= XEN_MAX_VIRTIO_GRANTS) {
95+ qemu_mutex_unlock(&xen_map_mutex);
96+ return NULL;
97+ }
98+
99+ mgr = g_new(struct XENMappedGrantRegion, 1);
100+
101+ if (nrefs == 1) {
102+ refs = &ref;
103+ } else {
104+ refs = g_new(uint32_t, nrefs);
105+ for (i = 0; i < nrefs; i++) {
106+ refs[i] = ref + i;
107+ }
108+ }
109+ mgr->addr = xengnttab_map_domain_grant_refs(xen_region_gnttabdev, nrefs,
110+ xen_domid, refs, prot);
111+ if (mgr->addr) {
112+ mgr->pages = nrefs;
113+ mgr->refs = 1;
114+ mgr->prot = prot;
115+ mgr->idx = ref;
116+
117+ QLIST_INSERT_HEAD(&xen_grant_mappings, mgr, list);
118+ } else {
119+ g_free(mgr);
120+ mgr = NULL;
121+ }
122+ } else {
123+ mgr->refs++;
124+ }
125+
126+ qemu_mutex_unlock(&xen_map_mutex);
127+
128+ if (nrefs > 1) {
129+ g_free(refs);
130+ }
131+
132+ return mgr ? mgr->addr + page_off : NULL;
133+}
134+
135+static void xen_unmap_grant_dyn(MemoryRegion *mr, void *buffer, ram_addr_t addr,
136+ hwaddr len, bool is_write, hwaddr access_len)
137+{
138+ unsigned int page_off = (unsigned long)buffer & (XC_PAGE_SIZE - 1);
139+ unsigned int nrefs = (page_off + len + XC_PAGE_SIZE - 1) >> XC_PAGE_SHIFT;
140+ unsigned int prot = PROT_READ;
141+ struct XENMappedGrantRegion *mgr = NULL;
142+
143+ if (is_write) {
144+ prot |= PROT_WRITE;
145+ }
146+
147+ qemu_mutex_lock(&xen_map_mutex);
148+
149+ QLIST_FOREACH(mgr, &xen_grant_mappings, list) {
150+ if (mgr->addr == buffer - page_off &&
151+ mgr->pages == nrefs &&
152+ (mgr->prot & prot) == prot) {
153+ break;
154+ }
155+ }
156+ if (mgr) {
157+ mgr->refs--;
158+ if (!mgr->refs) {
159+ xengnttab_unmap(xen_region_gnttabdev, mgr->addr, nrefs);
160+
161+ QLIST_REMOVE(mgr, list);
162+ g_free(mgr);
163+ }
164+ } else {
165+ error_report("xen_unmap_grant_dyn() trying to unmap unknown buffer");
166+ }
167+
168+ qemu_mutex_unlock(&xen_map_mutex);
169+}
170+
171+static ram_addr_t xen_ram_addr_from_grant_cache(void *ptr)
172+{
173+ unsigned int page_off = (unsigned long)ptr & (XC_PAGE_SIZE - 1);
174+ struct XENMappedGrantRegion *mgr = NULL;
175+ ram_addr_t raddr = RAM_ADDR_INVALID;
176+
177+ qemu_mutex_lock(&xen_map_mutex);
178+
179+ QLIST_FOREACH(mgr, &xen_grant_mappings, list) {
180+ if (mgr->addr == ptr - page_off) {
181+ break;
182+ }
183+ }
184+
185+ if (mgr) {
186+ raddr = (mgr->idx << XC_PAGE_SHIFT) + page_off + XEN_GRANT_ADDR_OFF;
187+ }
188+
189+ qemu_mutex_unlock(&xen_map_mutex);
190+
191+ return raddr;
192+}
193+
194+ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
195+{
196+ ram_addr_t raddr;
197+
198+ raddr = xen_ram_addr_from_mapcache_try(ptr);
199+ if (raddr == RAM_ADDR_INVALID) {
200+ raddr = xen_ram_addr_from_grant_cache(ptr);
201+ }
202+
203+ return raddr;
204+}
205+
206+static const struct MemoryRegionOps xen_grant_mr_ops = {
207+ .map = xen_map_grant_dyn,
208+ .unmap = xen_unmap_grant_dyn,
209+ .endianness = DEVICE_LITTLE_ENDIAN,
210+};
211+
212 MemoryRegion *xen_init_grant_ram(void)
213 {
214 RAMBlock *block;
215
216+ qemu_mutex_init(&xen_map_mutex);
217+
218+ xen_region_gnttabdev = xengnttab_open(NULL, 0);
219+ if (xen_region_gnttabdev == NULL) {
220+ fprintf(stderr, "can't open gnttab device\n");
221+ return NULL;
222+ }
223+
224 memory_region_init(&ram_grants, NULL, "xen.grants",
225 XEN_MAX_VIRTIO_GRANTS * XC_PAGE_SIZE);
226 block = g_malloc0(sizeof(*block));
227@@ -612,6 +785,7 @@ MemoryRegion *xen_init_grant_ram(void)
228 ram_grants.ram_block = block;
229 ram_grants.ram = true;
230 ram_grants.terminates = true;
231+ ram_grants.ops = &xen_grant_mr_ops;
232 ram_block_add_list(block);
233 memory_region_add_subregion(get_system_memory(), XEN_GRANT_ADDR_OFF,
234 &ram_grants);
235diff --git a/softmmu/physmem.c b/softmmu/physmem.c
236index a1e2030424..e1057304f1 100644
237--- a/softmmu/physmem.c
238+++ b/softmmu/physmem.c
239@@ -2210,13 +2210,16 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,
240
241 if (xen_enabled()) {
242 ram_addr_t ram_addr;
243+
244 RCU_READ_LOCK_GUARD();
245 ram_addr = xen_ram_addr_from_mapcache(ptr);
246- block = qemu_get_ram_block(ram_addr);
247- if (block) {
248- *offset = ram_addr - block->offset;
249+ if (ram_addr != RAM_ADDR_INVALID) {
250+ block = qemu_get_ram_block(ram_addr);
251+ if (block) {
252+ *offset = ram_addr - block->offset;
253+ }
254+ return block;
255 }
256- return block;
257 }
258
259 RCU_READ_LOCK_GUARD();
260--
2612.39.2
262
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0011-hw-arm-Add-grant-mapping.patch b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0011-hw-arm-Add-grant-mapping.patch
new file mode 100644
index 00000000..fb5450e6
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-8.1/0011-hw-arm-Add-grant-mapping.patch
@@ -0,0 +1,30 @@
1From b1eaba758a9000061fc53a934c348d6ef8dcdf64 Mon Sep 17 00:00:00 2001
2From: Vikram Garhwal <vikram.garhwal@amd.com>
3Date: Tue, 31 Jan 2023 21:46:43 +0000
4Subject: [PATCH 11/11] hw: arm: Add grant mapping.
5
6Enable grant ram mapping support for Xenpvh machine on ARM.
7
8Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
9Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
10---
11 hw/arm/xen_arm.c | 3 +++
12 1 file changed, 3 insertions(+)
13
14diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c
15index a5631529d0..1587e2a43b 100644
16--- a/hw/arm/xen_arm.c
17+++ b/hw/arm/xen_arm.c
18@@ -127,6 +127,9 @@ static void xen_init_ram(MachineState *machine)
19 DPRINTF("Initialized region xen.ram.hi: base 0x%llx size 0x%lx\n",
20 GUEST_RAM1_BASE, ram_size[1]);
21 }
22+
23+ DPRINTF("init grant ram mapping for XEN\n");
24+ ram_grants = *xen_init_grant_ram();
25 }
26
27 void arch_handle_ioreq(XenIOState *state, ioreq_t *req)
28--
292.39.2
30
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-native_%.bbappend b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-native_%.bbappend
new file mode 100644
index 00000000..e84844cf
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-native_%.bbappend
@@ -0,0 +1 @@
require qemu-tpm.inc
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-system-native_%.bbappend b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-system-native_%.bbappend
new file mode 100644
index 00000000..e84844cf
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx-system-native_%.bbappend
@@ -0,0 +1 @@
require qemu-tpm.inc
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx_2024%.bbappend b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx_2024%.bbappend
new file mode 100644
index 00000000..2f8e55aa
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu-xilinx_2024%.bbappend
@@ -0,0 +1,5 @@
1require qemu-tpm.inc
2require qemu-xen_8.1.inc
3
4# We do not want QEMU, on the target to be configured with OpenGL
5PACKAGECONFIG:remove:class-target:petalinux = "virglrenderer epoxy gtk+"
diff --git a/meta-xilinx-virtualization/recipes-devtools/qemu/qemu_8.1%.bbappend b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu_8.1%.bbappend
new file mode 100644
index 00000000..95b1902b
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-devtools/qemu/qemu_8.1%.bbappend
@@ -0,0 +1,5 @@
1require qemu-tpm.inc
2require qemu-xen_8.1.inc
3
4# We do not want QEMU, on the target to be configured with OpenGL
5PACKAGECONFIG:remove:class-target = "virglrenderer epoxy gtk+"
diff --git a/meta-xilinx-virtualization/recipes-extended/xen/files/0001-menuconfig-mconf-cfg-Allow-specification-of-ncurses-location.patch b/meta-xilinx-virtualization/recipes-extended/xen/files/0001-menuconfig-mconf-cfg-Allow-specification-of-ncurses-location.patch
new file mode 100644
index 00000000..135860ab
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-extended/xen/files/0001-menuconfig-mconf-cfg-Allow-specification-of-ncurses-location.patch
@@ -0,0 +1,57 @@
1From b300c18ab899b3c899e5405c96c20a32e51d77c8 Mon Sep 17 00:00:00 2001
2From: Bruce Ashfield <bruce.ashfield@windriver.com>
3Date: Mon, 2 Jul 2018 23:10:28 -0400
4Subject: [PATCH] xen: Fix menuconfig and add support for config fragments and
5
6Upstream-Status: Xen: Inappropriate [oe specific, cross compile issue]
7Upstream-Status: Kernel: Pending
8Signed-off-by: Diego Sueiro <diego.sueiro@arm.com>
9commit e6972e689a980ab28637e94e48c77eeace6abde5
10
11 xen/kconfig,menuconfig,mconf-cfg: Allow specification of ncurses location
12
13 In some cross build environments such as the Yocto Project build
14 environment it provides an ncurses library that is compiled
15 differently than the host's version. This causes display corruption
16 problems when the host's curses includes are used instead of the
17 includes from the provided compiler are overridden. There is a second
18 case where there is no curses libraries at all on the host system and
19 menuconfig will just fail entirely.
20
21 The solution is simply to allow an override variable in
22 check-lxdialog.sh for environments such as the Yocto Project. Adding
23 a CROSS_CURSES_LIB and CROSS_CURSES_INC solves the issue and allowing
24 compiling and linking against the right headers and libraries.
25
26 Change-Id: Ibe8dfafc90655e3be2671dbbb0cb7f5631fc4d44
27 Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
28 cc: Michal Marek <mmarek@suse.cz>
29 cc: linux-kbuild@vger.kernel.org
30 Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
31
32---
33 xen/tools/kconfig/mconf-cfg.sh | 8 ++++++++
34 1 file changed, 8 insertions(+)
35 mode change 100755 => 100644 xen/tools/kconfig/mconf-cfg.sh
36
37diff --git a/xen/tools/kconfig/mconf-cfg.sh b/xen/tools/kconfig/mconf-cfg.sh
38old mode 100755
39new mode 100644
40index c812872d7f..56eb4fc79f
41--- a/xen/tools/kconfig/mconf-cfg.sh
42+++ b/xen/tools/kconfig/mconf-cfg.sh
43@@ -4,6 +4,14 @@
44 PKG="ncursesw"
45 PKG2="ncurses"
46
47+if [ "$CROSS_CURSES_LIB" != "" ]; then
48+ echo libs=\'$CROSS_CURSES_LIB\'
49+ if [ x"$CROSS_CURSES_INC" != x ]; then
50+ echo cflags=\'$CROSS_CURSES_INC\'
51+ fi
52+ exit 0
53+fi
54+
55 if [ -n "$(command -v pkg-config)" ]; then
56 if pkg-config --exists $PKG; then
57 echo cflags=\"$(pkg-config --cflags $PKG)\"
diff --git a/meta-xilinx-virtualization/recipes-extended/xen/files/0001-python-pygrub-pass-DISTUTILS-xen-4.15.patch b/meta-xilinx-virtualization/recipes-extended/xen/files/0001-python-pygrub-pass-DISTUTILS-xen-4.15.patch
new file mode 100644
index 00000000..35cd9a81
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-extended/xen/files/0001-python-pygrub-pass-DISTUTILS-xen-4.15.patch
@@ -0,0 +1,73 @@
1From 6db88791d923167f160afbcadeffad84a4cbdbc5 Mon Sep 17 00:00:00 2001
2Message-Id: <6db88791d923167f160afbcadeffad84a4cbdbc5.1612262706.git.bertrand.marquis@arm.com>
3From: Maciej Pijanowski <maciej.pijanowski@3mdeb.com>
4Date: Fri, 19 Oct 2018 11:01:37 +0200
5Subject: [PATCH] python,pygrub: pass DISTUTILS env vars as setup.py args
6
7Upstream-Status: Xen: Inappropriate [oe specific, python install issues]
8
9Allow to respect the target install dir (PYTHON_SITEPACKAGES_DIR)
10as well as other parameters set by the OpenEmbedded build system.
11This is especially useful when the target libdir is not the default one
12(/usr/lib), but for example /usr/lib64.
13
14Signed-off-by: Maciej Pijanowski <maciej.pijanowski@3mdeb.com>
15
16Forward-ported to Xen 4.12.0
17Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
18
19Modified to support pygrub installation with python 3
20Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
21
22Forward-ported to Xen 4.14.0
23Signed-off-by: Christopher Clark <christopher.clark6@baesystems.com>
24
25Forward-ported to Xen 4.15.0
26Signed-off-by: Bertrand Marquis <bertrand.marquis@arm.com>
27
28---
29 tools/pygrub/Makefile | 7 +++++--
30 tools/python/Makefile | 2 +-
31 2 files changed, 6 insertions(+), 3 deletions(-)
32
33diff --git a/tools/pygrub/Makefile b/tools/pygrub/Makefile
34index 37b2146214..ffb9270065 100644
35--- a/tools/pygrub/Makefile
36+++ b/tools/pygrub/Makefile
37@@ -10,7 +10,7 @@ INSTALL_LOG = build/installed_files.txt
38 all: build
39 .PHONY: build
40 build:
41- CC="$(CC)" CFLAGS="$(PY_CFLAGS)" LDSHARED="$(CC)" LDFLAGS="$(PY_LDFLAGS)" $(PYTHON) setup.py build
42+ CC="$(CC)" CFLAGS="$(PY_CFLAGS)" LDSHARED="$(CC)" LDFLAGS="$(PY_LDFLAGS)" $(PYTHON) setup.py build $(DISTUTILS_BUILD_ARGS)
43
44 .PHONY: install
45 install: all
46@@ -18,7 +18,10 @@ install: all
47 CC="$(CC)" CFLAGS="$(PY_CFLAGS)" LDSHARED="$(CC)" \
48 LDFLAGS="$(PY_LDFLAGS)" $(PYTHON) setup.py install \
49 --record $(INSTALL_LOG) $(PYTHON_PREFIX_ARG) \
50- --root="$(DESTDIR)" --install-scripts=$(LIBEXEC_BIN) --force
51+ --root="$(DESTDIR)" --install-scripts=$(LIBEXEC_BIN) --force \
52+ $(DISTUTILS_INSTALL_ARGS)
53+ rm -f $(DESTDIR)/$(LIBEXEC_BIN)/pygrub
54+ $(INSTALL_PYTHON_PROG) src/pygrub $(DESTDIR)/$(LIBEXEC_BIN)/pygrub
55 set -e; if [ $(bindir) != $(LIBEXEC_BIN) -a \
56 "`readlink -f $(DESTDIR)/$(bindir)`" != \
57 "`readlink -f $(LIBEXEC_BIN)`" ]; then \
58diff --git a/tools/python/Makefile b/tools/python/Makefile
59index cc76423647..5cb11ae453 100644
60--- a/tools/python/Makefile
61+++ b/tools/python/Makefile
62@@ -12,7 +12,7 @@ setup.py = CC="$(CC)" CFLAGS="$(PY_CFLAGS)" LDSHARED="$(CC)" LDFLAGS="$(PY_LDFLA
63 SHLIB_libxenctrl="$(SHLIB_libxenctrl)" \
64 SHLIB_libxenguest="$(SHLIB_libxenguest)" \
65 SHLIB_libxenstore="$(SHLIB_libxenstore)" \
66- $(PYTHON) setup.py
67+ $(PYTHON) setup.py $(DISTUTILS_BUILD_ARGS)
68
69 .PHONY: build
70 build:
71--
722.17.1
73
diff --git a/meta-xilinx-virtualization/recipes-extended/xen/files/0001-python-pygrub-pass-DISTUTILS-xen-4.18.patch b/meta-xilinx-virtualization/recipes-extended/xen/files/0001-python-pygrub-pass-DISTUTILS-xen-4.18.patch
new file mode 100644
index 00000000..7ac1a399
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-extended/xen/files/0001-python-pygrub-pass-DISTUTILS-xen-4.18.patch
@@ -0,0 +1,43 @@
1Upstream-Status: Pending
2
3diff --git a/tools/pygrub/Makefile b/tools/pygrub/Makefile
4index 4963bc89c6..c1c05eb421 100644
5--- a/tools/pygrub/Makefile
6+++ b/tools/pygrub/Makefile
7@@ -13,14 +13,14 @@ setup.py = CC="$(CC)" CFLAGS="$(PY_CFLAGS)" LDSHARED="$(CC)" LDFLAGS="$(PY_LDFLA
8 all: build
9 .PHONY: build
10 build:
11- $(setup.py) build
12+ $(setup.py) build $(DISTUTILS_BUILD_ARGS)
13
14 .PHONY: install
15 install: all
16 $(INSTALL_DIR) $(DESTDIR)/$(bindir)
17 $(INSTALL_DIR) $(DESTDIR)/$(LIBEXEC_BIN)
18 $(setup.py) install --record $(INSTALL_LOG) $(PYTHON_PREFIX_ARG) \
19- --root="$(DESTDIR)" --force
20+ --root="$(DESTDIR)" --force $(DISTUTILS_INSTALL_ARGS)
21 $(INSTALL_PYTHON_PROG) src/pygrub $(DESTDIR)/$(LIBEXEC_BIN)/pygrub
22 set -e; if [ $(bindir) != $(LIBEXEC_BIN) -a \
23 "`readlink -f $(DESTDIR)/$(bindir)`" != \
24diff --git a/tools/python/Makefile b/tools/python/Makefile
25index 437431c48e..0a99c2067e 100644
26--- a/tools/python/Makefile
27+++ b/tools/python/Makefile
28@@ -16,13 +16,13 @@ setup.py = CC="$(CC)" CFLAGS="$(PY_CFLAGS)" LDSHARED="$(CC)" LDFLAGS="$(PY_LDFLA
29
30 .PHONY: build
31 build:
32- $(setup.py) build
33+ $(setup.py) build $(DISTUTILS_BUILD_ARGS)
34
35 .PHONY: install
36 install:
37 $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)
38 $(setup.py) install --record $(INSTALL_LOG) $(PYTHON_PREFIX_ARG) \
39- --root="$(DESTDIR)" --force
40+ --root="$(DESTDIR)" --force $(DISTUTILS_INSTALL_ARGS)
41 $(INSTALL_PYTHON_PROG) scripts/convert-legacy-stream $(DESTDIR)$(LIBEXEC_BIN)
42 $(INSTALL_PYTHON_PROG) scripts/verify-stream-v2 $(DESTDIR)$(LIBEXEC_BIN)
43
diff --git a/meta-xilinx-virtualization/recipes-extended/xen/files/xen-flask-race-fix.patch b/meta-xilinx-virtualization/recipes-extended/xen/files/xen-flask-race-fix.patch
new file mode 100644
index 00000000..fa2a82ff
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-extended/xen/files/xen-flask-race-fix.patch
@@ -0,0 +1,54 @@
1From mboxrd@z Thu Jan 1 00:00:00 1970
2From: Anthony PERARD <anthony.perard@citrix.com>
3Subject: [XEN PATCH] build: fix building flask headers before descending in flask/ss/
4Date: Fri, 20 Jan 2023 13:36:26 +0000
5Message-ID: <20230120133626.55680-1-anthony.perard@citrix.com>
6X-Mailer: git-send-email 2.30.2
7MIME-Version: 1.0
8Content-Transfer-Encoding: 8bit
9Content-Type: text/plain
10
11Unfortunatly, adding prerequisite to "$(obj)/ss/built_in.o" doesn't
12work because we have "$(obj)/%/built_in.o: $(obj)/% ;" in Rules.mk.
13So, make is allow to try to build objects in "xsm/flask/ss/" before
14generating the headers.
15
16Adding a prerequisite on "$(obj)/ss" instead will fix the issue has
17that the target used to run make in this subdirectory.
18
19Unfortunatly, that target is also used when running `make clean`, so
20we need to ignore it in this case. $(MAKECMDGOALS) can't be used in
21this case as it is empty, but we can guess which operation is done by
22looking at the list of loaded makefiles.
23
24Upstream-Status: backport [https://lore.kernel.org/xen-devel/20230120133626.55680-1-anthony.perard@citrix.com/T/#u]
25
26Fixes: 7a3bcd2babcc ("build: build everything from the root dir, use obj=$subdir")
27Reported-by: "Daniel P. Smith" <dpsmith@apertussolutions.com>
28Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
29---
30 xen/xsm/flask/Makefile | 6 +++++-
31 1 file changed, 5 insertions(+), 1 deletion(-)
32
33diff --git a/xen/xsm/flask/Makefile b/xen/xsm/flask/Makefile
34index d25312f4fa..2d24346ee3 100644
35--- a/xen/xsm/flask/Makefile
36+++ b/xen/xsm/flask/Makefile
37@@ -16,7 +16,11 @@ FLASK_H_FILES := flask.h class_to_string.h initial_sid_to_string.h
38 AV_H_FILES := av_perm_to_string.h av_permissions.h
39 ALL_H_FILES := $(addprefix include/,$(FLASK_H_FILES) $(AV_H_FILES))
40
41-$(addprefix $(obj)/,$(obj-y)) $(obj)/ss/built_in.o: $(addprefix $(obj)/,$(ALL_H_FILES))
42+# Adding prerequisite to descending into ss/ folder only when not running `make
43+# clean`.
44+ifeq ($(filter %/Makefile.clean,$(MAKEFILE_LIST)),)
45+$(addprefix $(obj)/,$(obj-y)) $(obj)/ss: $(addprefix $(obj)/,$(ALL_H_FILES))
46+endif
47 extra-y += $(ALL_H_FILES)
48
49 mkflask := $(srcdir)/policy/mkflask.sh
50--
51Anthony PERARD
52
53
54
diff --git a/meta-xilinx-virtualization/recipes-extended/xen/xen-tools-xilinx.inc b/meta-xilinx-virtualization/recipes-extended/xen/xen-tools-xilinx.inc
new file mode 100644
index 00000000..e7bc8d7e
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-extended/xen/xen-tools-xilinx.inc
@@ -0,0 +1,25 @@
1# Only include the sysvinit scripts if sysvinit is enabled.
2do_install:append () {
3 if [ -e ${D}/usr/lib/xen/bin/pygrub ]; then
4 sed -i -e '1c#!/usr/bin/env python3' ${D}/usr/lib/xen/bin/pygrub
5 fi
6
7 if [ "${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'sysvinit', '', d)}" != 'sysvinit' ]; then
8 rm -f ${D}/etc/init.d/xendomains
9 rm -f ${D}/etc/init.d/xencommons
10 rm -f ${D}/etc/init.d/xendriverdomain
11 rm -f ${D}/etc/init.d/xen-watchdog
12 fi
13}
14
15# If we're in a hybrid configuration, we want to stop the system from
16# running any Xen sysvinit scripts
17# This has a side effect of, on a hybrid system, if the init manager is
18# sysvinit, the user will need to manually enable Xen.
19INHIBIT_UPDATERCD_BBCLASS = "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', '1', '', d)}"
20
21FILES:${PN} += " \
22 ${libdir}/xen/bin/init-dom0less \
23 ${libdir}/xen/bin/get_overlay \
24 ${libdir}/xen/bin/get_overlay.sh \
25 "
diff --git a/meta-xilinx-virtualization/recipes-extended/xen/xen-tools_4.18.bbappend b/meta-xilinx-virtualization/recipes-extended/xen/xen-tools_4.18.bbappend
new file mode 100644
index 00000000..86702979
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-extended/xen/xen-tools_4.18.bbappend
@@ -0,0 +1,2 @@
1require xen-xilinx_4.18.inc
2require xen-tools-xilinx.inc
diff --git a/meta-xilinx-virtualization/recipes-extended/xen/xen-xilinx_4.18.inc b/meta-xilinx-virtualization/recipes-extended/xen/xen-xilinx_4.18.inc
new file mode 100644
index 00000000..7c573f73
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-extended/xen/xen-xilinx_4.18.inc
@@ -0,0 +1,12 @@
1SRCREV = "a4754372819eb69acb658fc013ad35c4d55bf9a5"
2XEN_URI = "git://github.com/Xilinx/xen.git;protocol=https"
3XEN_BRANCH = "xlnx_rebase_4.18"
4
5PV .= "-xilinx+git${SRCPV}"
6
7DEFAULT_PREFERENCE = "+1"
8
9SRC_URI = " \
10 ${XEN_URI};branch=${XEN_BRANCH} \
11 file://0001-python-pygrub-pass-DISTUTILS-xen-4.18.patch \
12 "
diff --git a/meta-xilinx-virtualization/recipes-extended/xen/xen_4.18.bbappend b/meta-xilinx-virtualization/recipes-extended/xen/xen_4.18.bbappend
new file mode 100644
index 00000000..e2c75566
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-extended/xen/xen_4.18.bbappend
@@ -0,0 +1,20 @@
1require xen-xilinx_4.18.inc
2
3FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
4
5RDEPENDS:${PN}-efi += "bash python3"
6
7do_deploy:append() {
8 # Mimic older behavior for compatibility
9 if [ -f ${DEPLOYDIR}/xen-${MACHINE} ]; then
10 ln -s xen-${MACHINE} ${DEPLOYDIR}/xen
11 fi
12
13 if [ -f ${DEPLOYDIR}/xen-${MACHINE}.gz ]; then
14 ln -s xen-${MACHINE}.gz ${DEPLOYDIR}/xen.gz
15 fi
16
17 if [ -f ${DEPLOYDIR}/xen-${MACHINE}.efi ]; then
18 ln -s xen-${MACHINE}.efi ${DEPLOYDIR}/xen.efi
19 fi
20}
diff --git a/meta-xilinx-virtualization/recipes-graphics/xorg-xserver/xserver-xorg_%.bbappend b/meta-xilinx-virtualization/recipes-graphics/xorg-xserver/xserver-xorg_%.bbappend
new file mode 100644
index 00000000..298b1dc8
--- /dev/null
+++ b/meta-xilinx-virtualization/recipes-graphics/xorg-xserver/xserver-xorg_%.bbappend
@@ -0,0 +1,8 @@
1# See meta-virtualization recipes-graphics/xorg-xserver/xserver-xorg_xen.inc
2
3# We want the configuration to remain optimized, if a user wants the removal
4# behavior, then they can set one of the below using 'glamor' as in the
5# xserver-xorg_xen.inc file.
6XEN_REMOVED_OPENGL_PKGCONFIGS:zynqmp ?= ""
7XEN_REMOVED_OPENGL_PKGCONFIGS:versal ?= ""
8