From 60157612f54e0726085a94d8648be0e5aabcc62b Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Thu, 31 Oct 2024 11:44:55 +0800 Subject: [PATCH 01/26] config: arm64: add D3000 root cell configuration file Signed-off-by: Huaizhi Wen --- src/jailhouse/configs/arm64/d3000.c | 321 ++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) create mode 100644 src/jailhouse/configs/arm64/d3000.c diff --git a/src/jailhouse/configs/arm64/d3000.c b/src/jailhouse/configs/arm64/d3000.c new file mode 100644 index 0000000..b649ab7 --- /dev/null +++ b/src/jailhouse/configs/arm64/d3000.c @@ -0,0 +1,321 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Configuration for Phytium D3000 + * Copyright (c) 2024 Phytium Technology Co., Ltd + * + * Authors: + * Huaizhi Wen + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include +#include + +struct { + struct jailhouse_system header; + __u64 cpus[1]; + struct jailhouse_memory mem_regions[30]; + struct jailhouse_irqchip irqchips[1]; +} __attribute__((packed)) config = { + .header = { + .signature = JAILHOUSE_SYSTEM_SIGNATURE, + .revision = JAILHOUSE_CONFIG_REVISION, + .flags = JAILHOUSE_SYS_VIRTUAL_DEBUG_CONSOLE, + .hypervisor_memory = { + .phys_start = 0xb0000000, + .size = 0x01000000, + }, + .debug_console = { + .address = 0x28009000, + .size = 0x1000, + .type = JAILHOUSE_CON_TYPE_PL011, + .flags = JAILHOUSE_CON_ACCESS_MMIO | + JAILHOUSE_CON_REGDIST_4, + }, + .platform_info = { + .pci_mmconfig_base = 0x40000000, + .pci_mmconfig_end_bus = 0xff, + .pci_is_virtual = 0, + .pci_domain = 0, + + .arm = { + .gic_version = 3, + .gicd_base = 0x36800000, /* GICD */ + .gicr_base = 0x36860000, /* GICR */ + .maintenance_irq = 25, + }, + }, + .root_cell = { + .name = "d3000", + + .cpu_set_size = sizeof(config.cpus), + .num_memory_regions = ARRAY_SIZE(config.mem_regions), + .num_irqchips = ARRAY_SIZE(config.irqchips), + + .vpci_irq_base = 100, + }, + }, + + .cpus = { + 0xff, + }, + + .mem_regions = { + /* Main memory 0 */ + { + .phys_start = 0x80000000, + .virt_start = 0x80000000, + .size = 0x80000000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_EXECUTE, + }, + /* Main memory 1 */ + { + .phys_start = 0x2000000000, + .virt_start = 0x2000000000, + .size = 0x2000000000, //Maximum support 128G + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_EXECUTE, + }, + /* mmc0 */ + { + .phys_start = 0x28000000, + .virt_start = 0x28000000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* hda */ + { + .phys_start = 0x28002000, + .virt_start = 0x28002000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* qspi */ + { + .phys_start = 0x28004000, + .virt_start = 0x28004000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* i2s0 */ + { + .phys_start = 0x28005000, + .virt_start = 0x28005000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* can0 */ + { + .phys_start = 0x28006000, + .virt_start = 0x28006000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* can1 */ + { + .phys_start = 0x28007000, + .virt_start = 0x28007000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* uart 0-3 */ + { + .phys_start = 0x28008000, + .virt_start = 0x28008000, + .size = 0x4000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* i2c0 */ + { + .phys_start = 0x2800c000, + .virt_start = 0x2800c000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* i2c1 */ + { + .phys_start = 0x2800d000, + .virt_start = 0x2800d000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* i2c2 */ + { + .phys_start = 0x28021000, + .virt_start = 0x28021000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* gpio 0-3 */ + { + .phys_start = 0x2800e000, + .virt_start = 0x2800e000, + .size = 0x4000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* spi 0-1 */ + { + .phys_start = 0x28012000, + .virt_start = 0x28012000, + .size = 0x2000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* watchdog0 0-1 */ + { + .phys_start = 0x28014000, + .virt_start = 0x28014000, + .size = 0x4000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* i3c 0-1 */ + { + .phys_start = 0x28018000, + .virt_start = 0x28018000, + .size = 0x2000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* pwm 0-1 */ + { + .phys_start = 0x2801a000, + .virt_start = 0x2801a000, + .size = 0x2000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* tacho 0-3 */ + { + .phys_start = 0x2801c000, + .virt_start = 0x2801c000, + .size = 0x4000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* sce0 */ + { + .phys_start = 0x36cc0000, + .virt_start = 0x36cc0000, + .size = 0x4000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* phytmac 0-1 */ + { + .phys_start = 0x36ce0000, + .virt_start = 0x36ce0000, + .size = 0x4000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* sata0 */ + { + .phys_start = 0x36ce5000, + .virt_start = 0x36ce5000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* lpc */ + { + .phys_start = 0x20000000, + .virt_start = 0x20000000, + .size = 0x100, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* mbox */ + { + .phys_start = 0x36d00000, + .virt_start = 0x36d00000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* sram */ + { + .phys_start = 0x36d04000, + .virt_start = 0x36d04000, + .size = 0x2000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* mio */ + { + .phys_start = 0x28022000, + .virt_start = 0x28022000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* GIC ITS */ + { + .phys_start = 0x36840000, + .virt_start = 0x36840000, + .size = 0x20000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* PCIe ECAM */ + { + .phys_start = 0x40000000, + .virt_start = 0x40000000, + .size = 0x10000000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* PCIe IO */ + { + .phys_start = 0x50000000, + .virt_start = 0x50000000, + .size = 0x8000000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* PCIe Mem32 */ + { + .phys_start = 0x58000000, + .virt_start = 0x58000000, + .size = 0x28000000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + /* PCIe Mem64 */ + { + .phys_start = 0x1000000000, + .virt_start = 0x1000000000, + .size = 0x1000000000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_IO, + }, + }, + + .irqchips = { + /* GIC */ + { + .address = 0x36800000, + .pin_base = 32, + .pin_bitmap = { + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, + }, + }, + }, + +}; + -- Gitee From a33824ed948ceaa9ad9ae882a356ad77fd170de9 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Thu, 31 Oct 2024 11:49:27 +0800 Subject: [PATCH 02/26] config: arm64: add non root cell linux configurations for D3000, including: 1. non root cell configuration file 2. dts for Guest Os Signed-off-by: Huaizhi Wen --- .../configs/arm64/d3000-linux-demo.c | 92 ++++++++++ .../configs/arm64/dts/inmate-d3000.dts | 168 ++++++++++++++++++ 2 files changed, 260 insertions(+) create mode 100644 src/jailhouse/configs/arm64/d3000-linux-demo.c create mode 100644 src/jailhouse/configs/arm64/dts/inmate-d3000.dts diff --git a/src/jailhouse/configs/arm64/d3000-linux-demo.c b/src/jailhouse/configs/arm64/d3000-linux-demo.c new file mode 100644 index 0000000..a57e44f --- /dev/null +++ b/src/jailhouse/configs/arm64/d3000-linux-demo.c @@ -0,0 +1,92 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Configuration for Phytium D3000 + * Copyright (c) 2024 Phytium Technology Co., Ltd + * + * Authors: + * Huaizhi Wen + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include +#include + +struct { + struct jailhouse_cell_desc cell; + __u64 cpus[1]; + struct jailhouse_memory mem_regions[4]; + struct jailhouse_irqchip irqchips[1]; +} __attribute__((packed)) config = { + .cell = { + .signature = JAILHOUSE_CELL_DESC_SIGNATURE, + .revision = JAILHOUSE_CONFIG_REVISION, + .name = "linux-demo", + .flags = JAILHOUSE_CELL_PASSIVE_COMMREG | JAILHOUSE_CON_REGDIST_4, + + .cpu_set_size = sizeof(config.cpus), + .num_memory_regions = ARRAY_SIZE(config.mem_regions), + .num_irqchips = ARRAY_SIZE(config.irqchips), + + .cpu_reset_address = 0x0, + + .console = { + .address = 0x28009000, + .type = JAILHOUSE_CON_TYPE_PL011, + .flags = JAILHOUSE_CON_ACCESS_MMIO | JAILHOUSE_CON_REGDIST_4, + }, + }, + + .cpus = { + 0x1, + }, + + .mem_regions = { + /* UART 1 */ + { + .phys_start = 0x28009000, + .virt_start = 0x28009000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, + }, + + /* RAM: for linux-loader space */ + { + .phys_start = 0x2000000000, + .virt_start = 0, + .size = 0x800000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, + }, + + /* RAM */ + { + .phys_start = 0x2000080000, + .virt_start = 0x2000080000, + .size = 0x40000000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_DMA | JAILHOUSE_MEM_LOADABLE, + }, + + /* Communication Region */ + { + .virt_start = 0x80000000, + .size = 0x00001000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_COMM_REGION, + }, + }, + + .irqchips = { + /* GIC */ { + .address = 0x36800000, + .pin_base = 32, + .pin_bitmap = { + 0, + 0, + 1 << (104 - 96), + 0, + }, + }, + }, +}; + diff --git a/src/jailhouse/configs/arm64/dts/inmate-d3000.dts b/src/jailhouse/configs/arm64/dts/inmate-d3000.dts new file mode 100644 index 0000000..fe466b9 --- /dev/null +++ b/src/jailhouse/configs/arm64/dts/inmate-d3000.dts @@ -0,0 +1,168 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Configuration for phytium d3000 chip linux demo, + * corresponding to configs/arm64/d3000-linux-demo.c. + * + * Copyright (c) Phytium Technology Co., Ltd. + * + * Authors: + * Huaizhi Wen + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +/dts-v1/; + +/memreserve/ 0x0000000080000000 0x0000000000010000; +/ { + compatible = "phytium,pd2308"; + interrupt-parent = <0x01>; + #address-cells = <0x02>; + #size-cells = <0x02>; + model = "Pd2308 DEMO"; + + hypervisor { + compatible = "jailhouse,cell"; + }; + + aliases { + serial1 = "/soc/uart@28009000"; + }; + + chosen { + stdout-path = "serial1:115200n8"; + }; + + psci { + compatible = "arm,psci-1.0\0arm,psci-0.2\0arm,psci"; + method = "smc"; + cpu_suspend = <0xc4000001>; + cpu_off = <0x84000002>; + cpu_on = <0xc4000003>; + sys_poweroff = <0x84000008>; + sys_reset = <0x84000009>; + }; + + cpus { + #address-cells = <0x02>; + #size-cells = <0x00>; + + cpu@0 { + device_type = "cpu"; + compatible = "arm,armv8"; + reg = <0x00 0x00>; + enable-method = "psci"; + numa-node-id = <0x00>; + }; + }; + + interrupt-controller@36800000 { + compatible = "arm,gic-v3"; + #interrupt-cells = <0x03>; + #address-cells = <0x02>; + #size-cells = <0x02>; + ranges; + interrupt-controller; + reg = <0x00 0x36800000 0x00 0x20000 0x00 0x36860000 0x00 0x100000>; + interrupts = <0x01 0x09 0x04>; + phandle = <0x01>; + }; + + timer { + compatible = "arm,armv8-timer"; + interrupts = <0x01 0x0d 0x08 0x01 0x0e 0x08 0x01 0x0b 0x08 0x01 0x0a 0x08>; + clock-frequency = <0x2faf080>; + }; + + pmu { + compatible = "arm,armv8-pmuv3"; + interrupts = <0x01 0x07 0x08>; + }; + + clocks { + #address-cells = <0x02>; + #size-cells = <0x02>; + ranges; + + clk250mhz { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0xee6b280>; + phandle = <0x0d>; + }; + + clk48mhz { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x2dc6c00>; + phandle = <0x09>; + }; + + clk50mhz { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x2faf080>; + phandle = <0x0a>; + }; + + sysclk_100mhz: clk100mhz { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x5f5e100>; + phandle = <0x0c>; + }; + + clk200mhz { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0xbebc200>; + phandle = <0x10>; + }; + + clk600mhz { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x23c34600>; + phandle = <0x11>; + }; + + clk1200mhz { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x47868c00>; + phandle = <0x08>; + }; + + clk300mhz { + compatible = "fixed-clock"; + #clock-cells = <0x00>; + clock-frequency = <0x11e1a300>; + phandle = <0x0b>; + }; + }; + + soc { + compatible = "simple-bus"; + #address-cells = <0x02>; + #size-cells = <0x02>; + ranges; + + uart@28009000 { + compatible = "arm,pl011\0arm,primecell"; + reg = <0x00 0x28009000 0x00 0x1000>; + baud = <0x1c200>; + reg-shift = <0x02>; + reg-io-width = <0x04>; + interrupts = <0x00 0x48 0x04>; + clocks = <&sysclk_100mhz &sysclk_100mhz>; + clock-names = "uartclk\0apb_pclk"; + status = "ok"; + phandle = <0x19>; + }; + + }; + +}; + -- Gitee From 99551576811835984ecfe70c5fb11c9b30e5bb51 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Mon, 11 Nov 2024 17:37:07 +0800 Subject: [PATCH 03/26] configs: arm64: D3000 add non root cell configuration for bare running Signed-off-by: Huaizhi Wen --- .../configs/arm64/d3000-inmate-demo.c | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/jailhouse/configs/arm64/d3000-inmate-demo.c diff --git a/src/jailhouse/configs/arm64/d3000-inmate-demo.c b/src/jailhouse/configs/arm64/d3000-inmate-demo.c new file mode 100644 index 0000000..be65e2d --- /dev/null +++ b/src/jailhouse/configs/arm64/d3000-inmate-demo.c @@ -0,0 +1,84 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Configuration for Phytium D3000 + * Copyright (c) 2024 Phytium Technology Co., Ltd + * + * Authors: + * Huaizhi Wen + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include +#include + +struct { + struct jailhouse_cell_desc cell; + __u64 cpus[1]; + struct jailhouse_memory mem_regions[3]; + struct jailhouse_irqchip irqchips[1]; +} __attribute__((packed)) config = { + .cell = { + .signature = JAILHOUSE_CELL_DESC_SIGNATURE, + .revision = JAILHOUSE_CONFIG_REVISION, + .name = "inmate-demo", + .flags = JAILHOUSE_CELL_PASSIVE_COMMREG | JAILHOUSE_CELL_VIRTUAL_CONSOLE_PERMITTED, + + .cpu_set_size = sizeof(config.cpus), + .num_memory_regions = ARRAY_SIZE(config.mem_regions), + .num_irqchips = ARRAY_SIZE(config.irqchips), + + .console = { + .address = 0x28009000, + .type = JAILHOUSE_CON_TYPE_PL011, + .flags = JAILHOUSE_CON_ACCESS_MMIO | JAILHOUSE_CON_REGDIST_4, + }, + }, + + .cpus = { + 0x1, + }, + + .irqchips = { + /* GIC */ { + .address = 0x36800000, + .pin_base = 32, + .pin_bitmap = { + 0, + 0, + 1 << (104 - 96), + 0, + }, + }, + }, + + .mem_regions = { + + /* UART 1 */ + { + .phys_start = 0x28009000, + .virt_start = 0x28009000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, + }, + + /* RAM */ + { + .phys_start = 0x2000000000, + .virt_start = 0, + .size = 0x01000000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, + }, + + /* communication region */ + { + .virt_start = 0x80000000, + .size = 0x00001000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_COMM_REGION, + }, + }, + +}; + -- Gitee From f01d70ad0237f36fdfd3716bf1ba0cca6ef410eb Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Thu, 14 Nov 2024 10:40:04 +0800 Subject: [PATCH 04/26] configs: arm64: add pcie function for D3000 root cell configuration Signed-off-by: Huaizhi Wen --- src/jailhouse/configs/arm64/d3000.c | 124 ++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/src/jailhouse/configs/arm64/d3000.c b/src/jailhouse/configs/arm64/d3000.c index b649ab7..e9a8716 100644 --- a/src/jailhouse/configs/arm64/d3000.c +++ b/src/jailhouse/configs/arm64/d3000.c @@ -19,6 +19,8 @@ struct { __u64 cpus[1]; struct jailhouse_memory mem_regions[30]; struct jailhouse_irqchip irqchips[1]; + struct jailhouse_pci_device pci_devices[2]; + struct jailhouse_pci_capability pci_caps[14]; } __attribute__((packed)) config = { .header = { .signature = JAILHOUSE_SYSTEM_SIGNATURE, @@ -54,6 +56,8 @@ struct { .cpu_set_size = sizeof(config.cpus), .num_memory_regions = ARRAY_SIZE(config.mem_regions), .num_irqchips = ARRAY_SIZE(config.irqchips), + .num_pci_devices = ARRAY_SIZE(config.pci_devices), + .num_pci_caps = ARRAY_SIZE(config.pci_caps), .vpci_irq_base = 100, }, @@ -317,5 +321,125 @@ struct { }, }, + .pci_devices = { + + /* PCI bridge @00:02.0 */ + { + .type = JAILHOUSE_PCI_TYPE_BRIDGE, + .domain = 0x0000, + .bdf = 0x0010, + .caps_start = 0, + .num_caps = 8, + }, + + /* Intel e1000e @03:00.0 */ + { + .type = JAILHOUSE_PCI_TYPE_DEVICE, + .domain = 0x0000, + .bdf = 0x0300, + .bar_mask = { + 0xfffe0000, 0xfffe0000, 0xffffffe0, + 0xffffc000, 0x00000000, 0x00000000, + }, + + .caps_start = 8, + .num_caps = 6, + .num_msi_vectors = 1, + .msi_64bits = 1, + .num_msix_vectors = 5, + .msix_region_size = 0x4000, + .msix_address = 0x587e0000, + }, + }, + + .pci_caps = { + /* PCI bridge @00:02.0 [0-7] */ + { + .id = PCI_CAP_ID_PM, /* Power Management Capability */ + .start = 0x40, + .len = 8, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_CAP_ID_EXP, /* PCI Express Capability */ + .start = 0x70, + .len = 60, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_ERR, /* Advanced Error Reporting Capability */ + .start = 0x100, + .len = 60, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_SECPCI, /* Secondary PCI Express Extended Capability */ + .start = 0x148, + .len = 28, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_ACS, /* Access Control Services */ + .start = 0x1c8, + .len = 16, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_L1SS, /* L1 PM Substates capability */ + .start = 0x1d4, + .len = 16, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_VNDR, /* Vendor-Specific Capability */ + .start = 0x1e4, + .len = 8, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_VNDR, /* Vendor-Specific Capability */ + .start = 0x2e4, + .len = 8, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + /* Intel e1000e @03:00.0 [8-13] */ + { + .id = PCI_CAP_ID_PM, /* Power Management Capability */ + .start = 0xc8, + .len = 8, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_CAP_ID_MSI, /* MSI Capability Structure */ + .start = 0xd0, + .len = 14, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_CAP_ID_MSIX, /* MSI-X Capability */ + .start = 0xa0, + .len = 12, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_CAP_ID_EXP, /* PCI Express Capability */ + .start = 0xe0, + .len = 60, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_ERR, /* Advanced Error Reporting Capability */ + .start = 0x100, + .len = 60, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_DSN, /* Device Serial Number Capability */ + .start = 0x140, + .len = 12, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + } + }; -- Gitee From 15dc8782f50694c2fbdecc17f8e4f81ae21c8c12 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Thu, 14 Nov 2024 10:47:29 +0800 Subject: [PATCH 05/26] configs: arm64: add pcie function for D3000 non root cell configuration Signed-off-by: Huaizhi Wen --- .../configs/arm64/d3000-linux-demo.c | 144 +++++++++++++++++- 1 file changed, 142 insertions(+), 2 deletions(-) diff --git a/src/jailhouse/configs/arm64/d3000-linux-demo.c b/src/jailhouse/configs/arm64/d3000-linux-demo.c index a57e44f..d20533d 100644 --- a/src/jailhouse/configs/arm64/d3000-linux-demo.c +++ b/src/jailhouse/configs/arm64/d3000-linux-demo.c @@ -17,8 +17,10 @@ struct { struct jailhouse_cell_desc cell; __u64 cpus[1]; - struct jailhouse_memory mem_regions[4]; + struct jailhouse_memory mem_regions[6]; struct jailhouse_irqchip irqchips[1]; + struct jailhouse_pci_device pci_devices[2]; + struct jailhouse_pci_capability pci_caps[14]; } __attribute__((packed)) config = { .cell = { .signature = JAILHOUSE_CELL_DESC_SIGNATURE, @@ -29,6 +31,8 @@ struct { .cpu_set_size = sizeof(config.cpus), .num_memory_regions = ARRAY_SIZE(config.mem_regions), .num_irqchips = ARRAY_SIZE(config.irqchips), + .num_pci_devices = ARRAY_SIZE(config.pci_devices), + .num_pci_caps = ARRAY_SIZE(config.pci_caps), .cpu_reset_address = 0x0, @@ -74,6 +78,22 @@ struct { .size = 0x00001000, .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_COMM_REGION, }, + + /* PCI bridge @00:02.0 BAR0 */ + { + .phys_start = 0x58600000, + .virt_start = 0x58600000, + .size = 0x00100000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE, + }, + + /* e1000e BAR0 */ + { + .phys_start = 0x587c0000, + .virt_start = 0x587c0000, + .size = 0x00020000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE, + }, }, .irqchips = { @@ -81,12 +101,132 @@ struct { .address = 0x36800000, .pin_base = 32, .pin_bitmap = { - 0, + 1 << (36 - 32) | 1 << (37 - 32) | 1 << (38 - 32) | 1 << (39 - 32), 0, 1 << (104 - 96), 0, }, }, }, + + .pci_devices = { + + /* PCI bridge @00:02.0 */ + { + .type = JAILHOUSE_PCI_TYPE_BRIDGE, + .domain = 0x0000, + .bdf = 0x0010, + .caps_start = 0, + .num_caps = 8, + }, + + /* Intel e1000e @03:00.0 */ + { + .type = JAILHOUSE_PCI_TYPE_DEVICE, + .domain = 0x0000, + .bdf = 0x0300, + .bar_mask = { + 0xfffe0000, 0xfffe0000, 0xffffffe0, + 0xffffc000, 0x00000000, 0x00000000, + }, + + .caps_start = 8, + .num_caps = 6, + .num_msi_vectors = 1, + .msi_64bits = 1, + .num_msix_vectors = 5, + .msix_region_size = 0x4000, + .msix_address = 0x587e0000, + }, + }, + + .pci_caps = { + /* PCI bridge @00:02.0 [0-7] */ + { + .id = PCI_CAP_ID_PM, /* Power Management Capability */ + .start = 0x40, + .len = 8, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_CAP_ID_EXP, /* PCI Express Capability */ + .start = 0x70, + .len = 60, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_ERR, /* Advanced Error Reporting Capability */ + .start = 0x100, + .len = 60, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_SECPCI, /* Secondary PCI Express Extended Capability */ + .start = 0x148, + .len = 28, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_ACS, /* Access Control Services */ + .start = 0x1c8, + .len = 16, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_L1SS, /* L1 PM Substates capability */ + .start = 0x1d4, + .len = 16, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_VNDR, /* Vendor-Specific Capability */ + .start = 0x1e4, + .len = 8, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_VNDR, /* Vendor-Specific Capability */ + .start = 0x2e4, + .len = 8, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + /* Intel e1000e @03:00.0 [8-13] */ + { + .id = PCI_CAP_ID_PM, /* Power Management Capability */ + .start = 0xc8, + .len = 8, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_CAP_ID_MSI, /* MSI Capability Structure */ + .start = 0xd0, + .len = 14, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_CAP_ID_MSIX, /* MSI-X Capability */ + .start = 0xa0, + .len = 12, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_CAP_ID_EXP, /* PCI Express Capability */ + .start = 0xe0, + .len = 60, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_ERR, /* Advanced Error Reporting Capability */ + .start = 0x100, + .len = 60, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + { + .id = PCI_EXT_CAP_ID_DSN, /* Device Serial Number Capability */ + .start = 0x140, + .len = 12, + .flags = JAILHOUSE_PCICAPS_WRITE, + }, + } }; -- Gitee From 8bd9c6848be130e159fd9c586f7ca9f5432b54d1 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Thu, 14 Nov 2024 11:04:15 +0800 Subject: [PATCH 06/26] configs: arm64/dts: inmate-d3000.dts add pcie device tree node for D3000 linux demo Signed-off-by: Huaizhi Wen --- .../configs/arm64/dts/inmate-d3000.dts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/jailhouse/configs/arm64/dts/inmate-d3000.dts b/src/jailhouse/configs/arm64/dts/inmate-d3000.dts index fe466b9..6a79ec0 100644 --- a/src/jailhouse/configs/arm64/dts/inmate-d3000.dts +++ b/src/jailhouse/configs/arm64/dts/inmate-d3000.dts @@ -33,6 +33,7 @@ chosen { stdout-path = "serial1:115200n8"; + linux,pci-probe-only = <1>; }; psci { @@ -162,6 +163,24 @@ phandle = <0x19>; }; + pcie@40000000 { + compatible = "pci-host-ecam-generic"; + device_type = "pci"; + #address-cells = <0x03>; + #size-cells = <0x02>; + #interrupt-cells = <0x01>; + reg = <0x00 0x40000000 0x00 0x10000000>; + msi-parent = <0x03>; + bus-range = <0x00 0xff>; + interrupt-map-mask = <0x00 0x00 0x00 0x07>; + interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0x00 0x00 0x04 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0x00 0x00 0x05 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0x00 0x00 0x06 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0x00 0x00 0x07 0x04>; + ranges = <0x1000000 0x00 0x00 0x00 0x50000000 0x00 0xf00000 0x2000000 0x00 0x58000000 0x00 0x58000000 0x00 0x28000000 0x3000000 0x10 0x00 0x10 0x00 0x10 0x00>; + dma-ranges = <0x43000000 0x00 0x00 0x00 0x00 0x1000 0x00>; + io-upper = <0x50005000>; + dma-coherent; + phandle = <0x36>; + }; + }; }; -- Gitee From 02e7bdb789006d98914e0c1d1ecc24a54fff1904 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Fri, 29 Nov 2024 10:44:18 +0800 Subject: [PATCH 07/26] config: arm64: add shared memory and ivshmem device for D3000 root cell Signed-off-by: Huaizhi Wen --- src/jailhouse/configs/arm64/d3000.c | 48 ++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/jailhouse/configs/arm64/d3000.c b/src/jailhouse/configs/arm64/d3000.c index e9a8716..ed95a0c 100644 --- a/src/jailhouse/configs/arm64/d3000.c +++ b/src/jailhouse/configs/arm64/d3000.c @@ -17,9 +17,9 @@ struct { struct jailhouse_system header; __u64 cpus[1]; - struct jailhouse_memory mem_regions[30]; + struct jailhouse_memory mem_regions[35]; struct jailhouse_irqchip irqchips[1]; - struct jailhouse_pci_device pci_devices[2]; + struct jailhouse_pci_device pci_devices[3]; struct jailhouse_pci_capability pci_caps[14]; } __attribute__((packed)) config = { .header = { @@ -59,7 +59,7 @@ struct { .num_pci_devices = ARRAY_SIZE(config.pci_devices), .num_pci_caps = ARRAY_SIZE(config.pci_caps), - .vpci_irq_base = 100, + .vpci_irq_base = 92-32, }, }, @@ -68,6 +68,37 @@ struct { }, .mem_regions = { + /* IVSHMEM shared memory regions */ + { + .phys_start = 0xb1000000, + .virt_start = 0xb1000000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ, + }, + { + .phys_start = 0xb1001000, + .virt_start = 0xb1001000, + .size = 0x9000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE, + }, + { + .phys_start = 0xb100a000, + .virt_start = 0xb100a000, + .size = 0x2000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE, + }, + { + .phys_start = 0xb100c000, + .virt_start = 0xb100c000, + .size = 0x2000, + .flags = JAILHOUSE_MEM_READ, + }, + { + .phys_start = 0xb100e000, + .virt_start = 0xb100e000, + .size = 0x2000, + .flags = JAILHOUSE_MEM_READ, + }, /* Main memory 0 */ { .phys_start = 0x80000000, @@ -322,7 +353,16 @@ struct { }, .pci_devices = { - + { + .type = JAILHOUSE_PCI_TYPE_IVSHMEM, + .domain = 1, + .bdf = 0 << 3, + .bar_mask = JAILHOUSE_IVSHMEM_BAR_MASK_INTX, + .shmem_regions_start = 0, + .shmem_dev_id = 0, + .shmem_peers = 3, + .shmem_protocol = JAILHOUSE_SHMEM_PROTO_UNDEFINED, + }, /* PCI bridge @00:02.0 */ { .type = JAILHOUSE_PCI_TYPE_BRIDGE, -- Gitee From 9975ed6e2bba05bde93bc700f2d5f71f73702f85 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Fri, 29 Nov 2024 11:00:13 +0800 Subject: [PATCH 08/26] config: arm64: add cell configuration for D3000 ivshmem demo Signed-off-by: Huaizhi Wen --- .../configs/arm64/d3000-ivshmem-demo.c | 132 ++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/jailhouse/configs/arm64/d3000-ivshmem-demo.c diff --git a/src/jailhouse/configs/arm64/d3000-ivshmem-demo.c b/src/jailhouse/configs/arm64/d3000-ivshmem-demo.c new file mode 100644 index 0000000..39c7e1a --- /dev/null +++ b/src/jailhouse/configs/arm64/d3000-ivshmem-demo.c @@ -0,0 +1,132 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Configuration for Phytium D3000 + * Copyright (c) 2024 Phytium Technology Co., Ltd + * + * Authors: + * Huaizhi Wen + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include +#include + +struct { + struct jailhouse_cell_desc cell; + __u64 cpus[1]; + struct jailhouse_memory mem_regions[8]; + struct jailhouse_irqchip irqchips[1]; + struct jailhouse_pci_device pci_devices[1]; +} __attribute__((packed)) config = { + .cell = { + .signature = JAILHOUSE_CELL_DESC_SIGNATURE, + .revision = JAILHOUSE_CONFIG_REVISION, + .name = "ivshmem-demo", + .flags = JAILHOUSE_CELL_PASSIVE_COMMREG | JAILHOUSE_CELL_VIRTUAL_CONSOLE_PERMITTED, + + .cpu_set_size = sizeof(config.cpus), + .num_memory_regions = ARRAY_SIZE(config.mem_regions), + .num_irqchips = ARRAY_SIZE(config.irqchips), + .num_pci_devices = ARRAY_SIZE(config.pci_devices), + + .vpci_irq_base = 93-32, + + .console = { + .address = 0x28009000, + .type = JAILHOUSE_CON_TYPE_PL011, + .flags = JAILHOUSE_CON_ACCESS_MMIO | JAILHOUSE_CON_REGDIST_4, + }, + }, + + .cpus = { + 0x1, + }, + + .irqchips = { + /* GIC */ { + .address = 0x36800000, + .pin_base = 32, + .pin_bitmap = { + 0, + 1 << (93 - 64), + 0, + 0, + }, + }, + }, + + .mem_regions = { + /* IVSHMEM shared memory regions */ + { + .phys_start = 0xb1000000, + .virt_start = 0xb1000000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_ROOTSHARED, + }, + { + .phys_start = 0xb1001000, + .virt_start = 0xb1001000, + .size = 0x9000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_ROOTSHARED, + }, + { + .phys_start = 0xb100a000, + .virt_start = 0xb100a000, + .size = 0x2000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_ROOTSHARED, + }, + { + .phys_start = 0xb100c000, + .virt_start = 0xb100c000, + .size = 0x2000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | + JAILHOUSE_MEM_ROOTSHARED, + }, + { + .phys_start = 0xb100e000, + .virt_start = 0xb100e000, + .size = 0x2000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_ROOTSHARED, + }, + /* UART 1 */ + { + .phys_start = 0x28009000, + .virt_start = 0x28009000, + .size = 0x1000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, + }, + + /* RAM */ + { + .phys_start = 0x2000000000, + .virt_start = 0, + .size = 0x01000000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_EXECUTE | JAILHOUSE_MEM_LOADABLE, + }, + + /* communication region */ + { + .virt_start = 0x80000000, + .size = 0x00001000, + .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_COMM_REGION, + }, + }, + + .pci_devices = { + { + .type = JAILHOUSE_PCI_TYPE_IVSHMEM, + .domain = 1, + .bdf = 0x0 << 3, + .bar_mask = JAILHOUSE_IVSHMEM_BAR_MASK_INTX, + .shmem_regions_start = 0, + .shmem_dev_id = 1, + .shmem_peers = 3, + .shmem_protocol = JAILHOUSE_SHMEM_PROTO_UNDEFINED, + }, + }, +}; + -- Gitee From 13c77674ef8ee9a09fc05e8550254823800bb429 Mon Sep 17 00:00:00 2001 From: Yang Shaojun Date: Fri, 6 Dec 2024 16:55:14 +0800 Subject: [PATCH 09/26] configs: arm64/dts: fix some compiling warnings of device tree Signed-off-by: Yang Shaojun --- src/jailhouse/configs/arm64/dts/inmate-d2000.dts | 8 ++++---- src/jailhouse/configs/arm64/dts/inmate-d3000.dts | 1 - src/jailhouse/configs/arm64/dts/inmate-ft2004.dts | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/jailhouse/configs/arm64/dts/inmate-d2000.dts b/src/jailhouse/configs/arm64/dts/inmate-d2000.dts index 71365f2..3f1a667 100644 --- a/src/jailhouse/configs/arm64/dts/inmate-d2000.dts +++ b/src/jailhouse/configs/arm64/dts/inmate-d2000.dts @@ -120,21 +120,21 @@ #size-cells = <0x02>; ranges; - clk250mhz { + clk250mhz: clk250mhz { compatible = "fixed-clock"; #clock-cells = <0x00>; clock-frequency = <0xee6b280>; phandle = <0x05>; }; - clk48mhz { + clk48mhz: clk48mhz { compatible = "fixed-clock"; #clock-cells = <0x00>; clock-frequency = <0x2dc6c00>; phandle = <0x03>; }; - clk600mhz { + clk600mhz: clk600mhz { compatible = "fixed-clock"; #clock-cells = <0x00>; clock-frequency = <0x23c34600>; @@ -156,7 +156,7 @@ reg-shift = <0x02>; reg-io-width = <0x04>; interrupts = <0x00 0x07 0x04>; - clocks = <0x03 0x03>; + clocks = <&clk48mhz &clk48mhz>; clock-names = "uartclk\0apb_pclk"; status = "ok"; }; diff --git a/src/jailhouse/configs/arm64/dts/inmate-d3000.dts b/src/jailhouse/configs/arm64/dts/inmate-d3000.dts index 6a79ec0..9d7d438 100644 --- a/src/jailhouse/configs/arm64/dts/inmate-d3000.dts +++ b/src/jailhouse/configs/arm64/dts/inmate-d3000.dts @@ -170,7 +170,6 @@ #size-cells = <0x02>; #interrupt-cells = <0x01>; reg = <0x00 0x40000000 0x00 0x10000000>; - msi-parent = <0x03>; bus-range = <0x00 0xff>; interrupt-map-mask = <0x00 0x00 0x00 0x07>; interrupt-map = <0x00 0x00 0x00 0x01 0x01 0x00 0x00 0x00 0x04 0x04 0x00 0x00 0x00 0x02 0x01 0x00 0x00 0x00 0x05 0x04 0x00 0x00 0x00 0x03 0x01 0x00 0x00 0x00 0x06 0x04 0x00 0x00 0x00 0x04 0x01 0x00 0x00 0x00 0x07 0x04>; diff --git a/src/jailhouse/configs/arm64/dts/inmate-ft2004.dts b/src/jailhouse/configs/arm64/dts/inmate-ft2004.dts index 99fd9e0..737b08f 100644 --- a/src/jailhouse/configs/arm64/dts/inmate-ft2004.dts +++ b/src/jailhouse/configs/arm64/dts/inmate-ft2004.dts @@ -104,21 +104,21 @@ #size-cells = <0x02>; ranges; - clk250mhz { + clk250mhz: clk250mhz { compatible = "fixed-clock"; #clock-cells = <0x00>; clock-frequency = <0xee6b280>; phandle = <0x06>; }; - clk48mhz { + clk48mhz: clk48mhz { compatible = "fixed-clock"; #clock-cells = <0x00>; clock-frequency = <0x2dc6c00>; phandle = <0x03>; }; - clk600mhz { + clk600mhz: clk600mhz { compatible = "fixed-clock"; #clock-cells = <0x00>; clock-frequency = <0x23c34600>; @@ -140,7 +140,7 @@ reg-shift = <0x02>; reg-io-width = <0x04>; interrupts = <0x00 0x07 0x04>; - clocks = <0x03 0x03>; + clocks = <&clk48mhz &clk48mhz>; clock-names = "uartclk\0apb_pclk"; status = "okay"; }; -- Gitee From 7a63a8a07b5588bc4653feb7d0c0b60bdd8536ea Mon Sep 17 00:00:00 2001 From: Yang Shaojun Date: Fri, 6 Dec 2024 15:33:02 +0800 Subject: [PATCH 10/26] hypervisor: arm64: map more data block to l2 bootstrap page table In the case of more than 64 cores, more memory is required to complete initialization, i.e. the stage before the runtime page table is established. So here we add a few more chunk mappings. Signed-off-by: Yang Shaojun --- src/jailhouse/hypervisor/arch/arm64/entry.S | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/jailhouse/hypervisor/arch/arm64/entry.S b/src/jailhouse/hypervisor/arch/arm64/entry.S index a9cabf7..95f965b 100644 --- a/src/jailhouse/hypervisor/arch/arm64/entry.S +++ b/src/jailhouse/hypervisor/arch/arm64/entry.S @@ -241,6 +241,17 @@ init_bootstrap_pt: get_index x3, x15, 2 set_block_dev bootstrap_pt_l2_hyp_uart, x3, x14, 2 + mov x3, x13 + mov x4, x12 + mov x1, #3 +1: + add x3, x3, #0x200000 + add x4, x4, #0x200000 + get_index x2, x3, 2 + set_block bootstrap_pt_l2_hyp_uart, x2, x4, 2 + subs x1, x1, #1 + b.ne 1b + adrp x0, bootstrap_pt_l0 mov x1, PAGE_SIZE * 4 mov x2, DCACHE_INVALIDATE_ASM -- Gitee From 6b80de879b3c4962a27cb947165e49c8599d030c Mon Sep 17 00:00:00 2001 From: Yang Shaojun Date: Tue, 3 Dec 2024 08:00:26 +0000 Subject: [PATCH 11/26] hypervisor: arm64: add support for multi-mmio-regions in gic-v3 redistributor Arm GIC-v3 Redistributor(GICR) are per-cpu designed and are memory-mapped. In the case of more than 64 cores, these mmio-regions may be discontinuous, i.e., there are multiple GICR mmio-regions. So here implement this feature. Signed-off-by: Yang Shaojun --- .../hypervisor/arch/arm-common/control.c | 6 +- .../hypervisor/arch/arm-common/gic-v3.c | 64 ++++++++++++------- .../arch/arm-common/asm/jailhouse_hypercall.h | 4 +- src/jailhouse/include/jailhouse/cell-config.h | 7 +- src/jailhouse/inmates/lib/arm-common/gic-v3.c | 43 ++++++++----- 5 files changed, 81 insertions(+), 43 deletions(-) diff --git a/src/jailhouse/hypervisor/arch/arm-common/control.c b/src/jailhouse/hypervisor/arch/arm-common/control.c index 9fc4276..1cbc227 100644 --- a/src/jailhouse/hypervisor/arch/arm-common/control.c +++ b/src/jailhouse/hypervisor/arch/arm-common/control.c @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -170,7 +171,10 @@ void arch_cell_reset(struct cell *cell) comm_region->gic_version = system_config->platform_info.arm.gic_version; comm_region->gicd_base = system_config->platform_info.arm.gicd_base; comm_region->gicc_base = system_config->platform_info.arm.gicc_base; - comm_region->gicr_base = system_config->platform_info.arm.gicr_base; + memcpy(comm_region->gicr_base, system_config->platform_info.arm.gicr_regions, sizeof(u64) * JAILHOUSE_MAX_GICR_REGIONS); + comm_region->num_gicr_regions = system_config->platform_info.arm.num_gicr_regions; + if (!comm_region->num_gicr_regions) + comm_region->num_gicr_regions = 1; comm_region->vpci_irq_base = cell->config->vpci_irq_base; /* diff --git a/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c b/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c index 731d7f4..5580528 100644 --- a/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c +++ b/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -38,7 +39,8 @@ static unsigned int gic_num_priority_bits; static unsigned int last_gicr; static u32 gic_version; -static void *gicr_base; +static u32 num_gicr_regions; +static void *gicr_base[JAILHOUSE_MAX_GICR_REGIONS]; static u64 gicv3_read_lr(unsigned int reg) { @@ -126,6 +128,7 @@ static int gicv3_init(void) { unsigned long redist_size = GIC_V3_REDIST_SIZE; unsigned int gicr_size; + u32 i; /* Probe the GICD version */ gic_version = GICD_PIDR2_ARCH(mmio_read32(gicd_base + GICDv3_PIDR2)); @@ -148,10 +151,19 @@ static int gicv3_init(void) redist_size = GIC_V4_REDIST_SIZE; gicr_size = redist_size * (last_gicr + 1); - gicr_base = paging_map_device( - system_config->platform_info.arm.gicr_base, gicr_size); - if (!gicr_base) - return -ENOMEM; + + num_gicr_regions = system_config->platform_info.arm.num_gicr_regions; + if (!num_gicr_regions) + num_gicr_regions = 1; + + //gicr_base = page_alloc(&mem_pool, PAGES(num_gicr_regions * sizeof(u64))); + //void page_free(struct page_pool *pool, void *page, unsigned int num) + + for (i = 0; i < num_gicr_regions; i++) { + gicr_base[i] = paging_map_device(system_config->platform_info.arm.gicr_regions[i], gicr_size); + if (!gicr_base[i]) + return trace_error(-ENOMEM); + } return 0; } @@ -197,14 +209,14 @@ static void gicv3_cpu_reset(struct per_cpu *cpu_data) static int gicv3_cpu_init(struct per_cpu *cpu_data) { unsigned int mnt_irq = system_config->platform_info.arm.maintenance_irq; - unsigned long redist_addr = system_config->platform_info.arm.gicr_base; + unsigned long redist_addr; unsigned long redist_size = GIC_V3_REDIST_SIZE; - void *redist_base = gicr_base; + void *redist_base; unsigned long gicr_ispendr; unsigned int n; void *gicr; u64 typer, mpidr; - u32 pidr, aff; + u32 pidr, aff, i; u32 cell_icc_ctlr, cell_icc_pmr, cell_icc_igrpen1; u32 ich_vtr; u32 ich_vmcr; @@ -219,22 +231,28 @@ static int gicv3_cpu_init(struct per_cpu *cpu_data) MPIDR_AFFINITY_LEVEL(mpidr, 0)); /* Find redistributor */ - do { - pidr = mmio_read32(redist_base + GICR_PIDR2); - if (GICR_PIDR2_ARCH(pidr) != gic_version) - break; - - typer = mmio_read64(redist_base + GICR_TYPER); - if ((typer >> 32) == aff) { - cpu_data->public.gicr.base = redist_base; - cpu_data->public.gicr.phys_addr = redist_addr; - break; - } + for (i = 0; i < num_gicr_regions; i++) { + redist_base = gicr_base[i]; + redist_addr = system_config->platform_info.arm.gicr_regions[i]; + + do { + pidr = mmio_read32(redist_base + GICR_PIDR2); + if (GICR_PIDR2_ARCH(pidr) != gic_version) + break; + + typer = mmio_read64(redist_base + GICR_TYPER); + if ((typer >> 32) == aff) { + cpu_data->public.gicr.base = redist_base; + cpu_data->public.gicr.phys_addr = redist_addr; + goto found; + } - redist_base += redist_size; - redist_addr += redist_size; - } while (!(typer & GICR_TYPER_Last)); + redist_base += redist_size; + redist_addr += redist_size; + } while (!(typer & GICR_TYPER_Last)); + } +found: if (!cpu_data->public.gicr.base) { printk("GIC: No redist found for CPU%d\n", cpu_data->public.cpu_id); @@ -249,7 +267,7 @@ static int gicv3_cpu_init(struct per_cpu *cpu_data) return 0; /* Ensure all IPIs and the maintenance PPI are enabled. */ - gicr = redist_base + GICR_SGI_BASE; + gicr = cpu_data->public.gicr.base + GICR_SGI_BASE; mmio_write32(gicr + GICR_ISENABLER, 0x0000ffff | (1 << mnt_irq)); /* diff --git a/src/jailhouse/include/arch/arm-common/asm/jailhouse_hypercall.h b/src/jailhouse/include/arch/arm-common/asm/jailhouse_hypercall.h index 3988fd7..f0115a0 100644 --- a/src/jailhouse/include/arch/arm-common/asm/jailhouse_hypercall.h +++ b/src/jailhouse/include/arch/arm-common/asm/jailhouse_hypercall.h @@ -46,6 +46,7 @@ #define JAILHOUSE_CPU_STAT_VMEXITS_SMCCC JAILHOUSE_GENERIC_CPU_STATS + 4 #ifndef __ASSEMBLY__ +#include struct jailhouse_comm_region { COMM_REGION_GENERIC_HEADER; @@ -53,7 +54,8 @@ struct jailhouse_comm_region { __u8 padding[7]; __u64 gicd_base; __u64 gicc_base; - __u64 gicr_base; + __u32 num_gicr_regions; + __u64 gicr_base[JAILHOUSE_MAX_GICR_REGIONS]; __u32 vpci_irq_base; } __attribute__((packed)); diff --git a/src/jailhouse/include/jailhouse/cell-config.h b/src/jailhouse/include/jailhouse/cell-config.h index 6b54e34..26f6474 100644 --- a/src/jailhouse/include/jailhouse/cell-config.h +++ b/src/jailhouse/include/jailhouse/cell-config.h @@ -255,6 +255,7 @@ struct jailhouse_pci_capability { #define JAILHOUSE_APIC_MODE_X2APIC 2 #define JAILHOUSE_MAX_IOMMU_UNITS 8 +#define JAILHOUSE_MAX_GICR_REGIONS 16 #define JAILHOUSE_IOMMU_AMD 1 #define JAILHOUSE_IOMMU_INTEL 2 @@ -350,7 +351,11 @@ struct jailhouse_system { u64 gicc_base; u64 gich_base; u64 gicv_base; - u64 gicr_base; + u32 num_gicr_regions; + union { + u64 gicr_base; + u64 gicr_regions[JAILHOUSE_MAX_GICR_REGIONS]; + }; } __attribute__((packed)) arm; } __attribute__((packed)); } __attribute__((packed)) platform_info; diff --git a/src/jailhouse/inmates/lib/arm-common/gic-v3.c b/src/jailhouse/inmates/lib/arm-common/gic-v3.c index cd202a4..6eed813 100644 --- a/src/jailhouse/inmates/lib/arm-common/gic-v3.c +++ b/src/jailhouse/inmates/lib/arm-common/gic-v3.c @@ -68,12 +68,16 @@ static int gic_v3_init(void) void *gicr = NULL; u64 typer; u32 pidr, aff; + u32 i, num_gicr_regions; - redist_addr = (void*)(unsigned long)comm_region->gicr_base; + num_gicr_regions = comm_region->num_gicr_regions; gicd_v3_base = (void*)(unsigned long)comm_region->gicd_base; map_range(gicd_v3_base, PAGE_SIZE, MAP_UNCACHED); - map_range(redist_addr, PAGE_SIZE, MAP_UNCACHED); + for (i = 0; i < num_gicr_regions; i++) { + redist_addr = (void *)(unsigned long)comm_region->gicr_base[i]; + map_range(redist_addr, PAGE_SIZE, MAP_UNCACHED); + } arm_read_sysreg(MPIDR, mpidr); mpidr &= MPIDR_CPUID_MASK; @@ -83,21 +87,26 @@ static int gic_v3_init(void) MPIDR_AFFINITY_LEVEL(mpidr, 0)); /* Find redistributor */ - do { - pidr = mmio_read32(redist_addr + GICR_PIDR2); - if (GICR_PIDR2_ARCH(pidr) != 3) - break; - - typer = mmio_read32(redist_addr + GICR_TYPER); - typer |= (u64)mmio_read32(redist_addr + GICR_TYPER + 4) << 32; - if ((typer >> 32) == aff) { - gicr = redist_addr; - break; - } - - redist_addr += 0x20000; - } while (!(typer & GICR_TYPER_Last)); - + for (i = 0; i < num_gicr_regions; i++) { + redist_addr = (void*)(unsigned long)comm_region->gicr_base[i]; + + do { + pidr = mmio_read32(redist_addr + GICR_PIDR2); + if (GICR_PIDR2_ARCH(pidr) != 3) + break; + + typer = mmio_read32(redist_addr + GICR_TYPER); + typer |= (u64)mmio_read32(redist_addr + GICR_TYPER + 4) << 32; + if ((typer >> 32) == aff) { + gicr = redist_addr; + goto found; + } + + redist_addr += 0x20000; + } while (!(typer & GICR_TYPER_Last)); + } + +found: if (!gicr) return -1; -- Gitee From 574cf51e2c3457337015d629595bd06bdca2cb70 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Tue, 31 Dec 2024 11:33:38 +0800 Subject: [PATCH 12/26] configs: arm64: update rtos_64 configurations for D2000 and FT-2004/4 Signed-off-by: Huaizhi Wen --- src/jailhouse/configs/arm64/d2000-inmate-rtos64.c | 8 ++++---- src/jailhouse/configs/arm64/ft2004-inmate-rtos64.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/jailhouse/configs/arm64/d2000-inmate-rtos64.c b/src/jailhouse/configs/arm64/d2000-inmate-rtos64.c index dd8519d..62f207a 100644 --- a/src/jailhouse/configs/arm64/d2000-inmate-rtos64.c +++ b/src/jailhouse/configs/arm64/d2000-inmate-rtos64.c @@ -33,7 +33,7 @@ struct { .num_irqchips = ARRAY_SIZE(config.irqchips), .console = { - .address = 0x28000000, + .address = 0x28001000, .type = JAILHOUSE_CON_TYPE_PL011, .flags = JAILHOUSE_CON_ACCESS_MMIO | JAILHOUSE_CON_REGDIST_4, @@ -49,7 +49,7 @@ struct { .address = 0x29a00000, .pin_base = 32, .pin_bitmap = { - 1 << (38 -32), + 1 << (39 -32), 1 << (81 - 64), 0, 0, @@ -59,8 +59,8 @@ struct { .mem_regions = { /* UART */{ - .phys_start = 0x28000000, - .virt_start = 0x28000000, + .phys_start = 0x28001000, + .virt_start = 0x28001000, .size = 0x1000, .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, diff --git a/src/jailhouse/configs/arm64/ft2004-inmate-rtos64.c b/src/jailhouse/configs/arm64/ft2004-inmate-rtos64.c index af5ccd5..88a58c6 100644 --- a/src/jailhouse/configs/arm64/ft2004-inmate-rtos64.c +++ b/src/jailhouse/configs/arm64/ft2004-inmate-rtos64.c @@ -33,7 +33,7 @@ struct { .num_irqchips = ARRAY_SIZE(config.irqchips), .console = { - .address = 0x28000000, + .address = 0x28001000, .type = JAILHOUSE_CON_TYPE_PL011, .flags = JAILHOUSE_CON_ACCESS_MMIO | JAILHOUSE_CON_REGDIST_4, @@ -49,7 +49,7 @@ struct { .address = 0x29900000, .pin_base = 32, .pin_bitmap = { - 1 << (38 -32), + 1 << (39 -32), 1 << (81 - 64), 0, 0, @@ -59,8 +59,8 @@ struct { .mem_regions = { /* UART */{ - .phys_start = 0x28000000, - .virt_start = 0x28000000, + .phys_start = 0x28001000, + .virt_start = 0x28001000, .size = 0x1000, .flags = JAILHOUSE_MEM_READ | JAILHOUSE_MEM_WRITE | JAILHOUSE_MEM_IO | JAILHOUSE_MEM_ROOTSHARED, -- Gitee From 2b12e6e875bd403dd57b7fa9e2196aef068cab3e Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Mon, 17 Feb 2025 14:32:51 +0800 Subject: [PATCH 13/26] hypervisor: arm64: add support for multi-pcie-controller on S5000C64 The native jailhouse currently only supports one PCIe controller, while on the s5000c, each die has a PCIe controller. So here implement this feature. Signed-off-by: Huaizhi Wen --- src/jailhouse/driver/pci.c | 5 + .../hypervisor/arch/arm-common/pci.c | 2 +- src/jailhouse/hypervisor/control.c | 10 +- .../hypervisor/include/jailhouse/pci.h | 6 +- src/jailhouse/hypervisor/pci.c | 125 ++++++++++++------ src/jailhouse/include/jailhouse/cell-config.h | 16 ++- src/jailhouse/include/jailhouse/hypercall.h | 3 +- 7 files changed, 113 insertions(+), 54 deletions(-) diff --git a/src/jailhouse/driver/pci.c b/src/jailhouse/driver/pci.c index da51647..0aecd05 100644 --- a/src/jailhouse/driver/pci.c +++ b/src/jailhouse/driver/pci.c @@ -507,6 +507,11 @@ static void destroy_vpci_of_overlay(void) void jailhouse_pci_virtual_root_devices_add(struct jailhouse_system *config) { + if (config->platform_info.pci_is_virtual && config->platform_info.num_pcie_units) { + pr_warn("jailhouse: We only support virtual PCIe on a single PCIe region mode\n"); + return; + } + if (config->platform_info.pci_is_virtual && !create_vpci_of_overlay(config)) { pr_warn("jailhouse: failed to add virtual host controller\n"); diff --git a/src/jailhouse/hypervisor/arch/arm-common/pci.c b/src/jailhouse/hypervisor/arch/arm-common/pci.c index 8daccee..652abcf 100644 --- a/src/jailhouse/hypervisor/arch/arm-common/pci.c +++ b/src/jailhouse/hypervisor/arch/arm-common/pci.c @@ -49,7 +49,7 @@ int arch_pci_update_msi(struct pci_device *device, * platforms. */ for (n = 1; n < (info->msi_64bits ? 4 : 3); n++) - pci_write_config(info->bdf, cap->start + n * 4, + pci_write_config(device, cap->start + n * 4, device->msi_registers.raw[n], 4); return 0; diff --git a/src/jailhouse/hypervisor/control.c b/src/jailhouse/hypervisor/control.c index 2214406..64db756 100644 --- a/src/jailhouse/hypervisor/control.c +++ b/src/jailhouse/hypervisor/control.c @@ -661,8 +661,14 @@ static int cell_start(struct per_cpu *cpu_data, unsigned long id) if (CELL_FLAGS_VIRTUAL_CONSOLE_ACTIVE(cell->config->flags)) comm_region->flags |= JAILHOUSE_COMM_FLAG_DBG_PUTC_ACTIVE; comm_region->console = cell->config->console; - comm_region->pci_mmconfig_base = - system_config->platform_info.pci_mmconfig_base; + + if (!system_config->platform_info.num_pcie_units) { + comm_region->pci_mmconfig_base = system_config->platform_info.pci_mmconfig_base; + } else { + for (n = 0; n < system_config->platform_info.num_pcie_units; n++) { + comm_region->pci_mmconfig_bases[n] = system_config->platform_info.pci_mmconfig_bases[n]; + } + } pci_cell_reset(cell); arch_cell_reset(cell); diff --git a/src/jailhouse/hypervisor/include/jailhouse/pci.h b/src/jailhouse/hypervisor/include/jailhouse/pci.h index ee530c0..46b1f17 100644 --- a/src/jailhouse/hypervisor/include/jailhouse/pci.h +++ b/src/jailhouse/hypervisor/include/jailhouse/pci.h @@ -143,10 +143,10 @@ struct pci_device { union pci_msix_vector msix_vector_array[PCI_EMBEDDED_MSIX_VECTS]; }; -u32 pci_read_config(u16 bdf, u16 address, unsigned int size); -void pci_write_config(u16 bdf, u16 address, u32 value, unsigned int size); +u32 pci_read_config(struct pci_device *device, u16 address, unsigned int size); +void pci_write_config(struct pci_device *device, u16 address, u32 value, unsigned int size); -struct pci_device *pci_get_assigned_device(const struct cell *cell, u16 bdf); +struct pci_device *pci_get_assigned_device(const struct cell *cell, u16 bdf, u16 domain); enum pci_access pci_cfg_read_moderate(struct pci_device *device, u16 address, unsigned int size, u32 *value); diff --git a/src/jailhouse/hypervisor/pci.c b/src/jailhouse/hypervisor/pci.c index 13d986a..08bc104 100644 --- a/src/jailhouse/hypervisor/pci.c +++ b/src/jailhouse/hypervisor/pci.c @@ -71,18 +71,19 @@ static const struct pci_cfg_control bridge_write[PCI_CONFIG_HEADER_SIZE] = { [0x3c/4] = {PCI_CONFIG_ALLOW, 0xffff00ff}, /* Int Line, Bridge Ctrl */ }; -static void *pci_space; -static u64 mmcfg_start, mmcfg_size; -static u8 end_bus; +static void *pci_space[JAILHOUSE_MAX_PCIE_UNITS]; +static u64 mmcfg_start[JAILHOUSE_MAX_PCIE_UNITS], mmcfg_size[JAILHOUSE_MAX_PCIE_UNITS]; +static u8 end_bus[JAILHOUSE_MAX_PCIE_UNITS]; +static u16 domains[JAILHOUSE_MAX_PCIE_UNITS]; static unsigned int pci_mmio_count_regions(struct cell *cell) { const struct jailhouse_pci_device *dev_infos = jailhouse_cell_pci_devices(cell->config); unsigned int n, regions = 0; + u32 pcie_units = system_config->platform_info.num_pcie_units; - if (system_config->platform_info.pci_mmconfig_base) - regions++; + regions += pcie_units ? pcie_units : 1; for (n = 0; n < cell->config->num_pci_devices; n++) if (dev_infos[n].type == JAILHOUSE_PCI_TYPE_IVSHMEM) @@ -93,14 +94,15 @@ static unsigned int pci_mmio_count_regions(struct cell *cell) return regions; } -static void *pci_get_device_mmcfg_base(u16 bdf) +static void *pci_get_device_mmcfg_base(struct pci_device *device) { - return pci_space + ((unsigned long)bdf << 12); + return pci_space[device->info->mmconfig_id] + + ((unsigned long)device->info->bdf << 12); } /** * Read from PCI config space. - * @param bdf 16-bit bus/device/function ID of target. + * @param device pci device. * @param address Config space access address. * @param size Access size (1, 2 or 4 bytes). * @@ -108,11 +110,13 @@ static void *pci_get_device_mmcfg_base(u16 bdf) * * @see pci_write_config */ -u32 pci_read_config(u16 bdf, u16 address, unsigned int size) +u32 pci_read_config(struct pci_device *device, u16 address, unsigned int size) { - void *mmcfg_addr = pci_get_device_mmcfg_base(bdf) + address; + void *mmcfg_addr = pci_get_device_mmcfg_base(device) + address; + unsigned int mmcfg_id = device->info->mmconfig_id; + u16 bdf = device->info->bdf; - if (!pci_space || PCI_BUS(bdf) > end_bus) + if (!pci_space[mmcfg_id] || PCI_BUS(bdf) > end_bus[mmcfg_id]) return arch_pci_read_config(bdf, address, size); if (size == 1) @@ -125,18 +129,20 @@ u32 pci_read_config(u16 bdf, u16 address, unsigned int size) /** * Write to PCI config space. - * @param bdf 16-bit bus/device/function ID of target. + * @param device pci device. * @param address Config space access address. * @param value Value to be written. * @param size Access size (1, 2 or 4 bytes). * * @see pci_read_config */ -void pci_write_config(u16 bdf, u16 address, u32 value, unsigned int size) +void pci_write_config(struct pci_device *device, u16 address, u32 value, unsigned int size) { - void *mmcfg_addr = pci_get_device_mmcfg_base(bdf) + address; + void *mmcfg_addr = pci_get_device_mmcfg_base(device) + address; + unsigned int mmcfg_id = device->info->mmconfig_id; + u16 bdf = device->info->bdf; - if (!pci_space || PCI_BUS(bdf) > end_bus) + if (!pci_space[mmcfg_id] || PCI_BUS(bdf) > end_bus[mmcfg_id]) return arch_pci_write_config(bdf, address, value, size); if (size == 1) @@ -151,10 +157,12 @@ void pci_write_config(u16 bdf, u16 address, u32 value, unsigned int size) * Look up device owned by a cell. * @param[in] cell Owning cell. * @param bdf 16-bit bus/device/function ID. + * @param domain domain ID of PCI device * * @return Pointer to owned PCI device or NULL. */ -struct pci_device *pci_get_assigned_device(const struct cell *cell, u16 bdf) +struct pci_device *pci_get_assigned_device(const struct cell *cell, u16 bdf, + u16 domain) { const struct jailhouse_pci_device *dev_info = jailhouse_cell_pci_devices(cell->config); @@ -163,7 +171,7 @@ struct pci_device *pci_get_assigned_device(const struct cell *cell, u16 bdf) /* We iterate over the static device information to increase cache * locality. */ for (n = 0; n < cell->config->num_pci_devices; n++) - if (dev_info[n].bdf == bdf) + if (dev_info[n].bdf == bdf && dev_info[n].domain == domain) return cell->pci_devices[n].cell ? &cell->pci_devices[n] : NULL; @@ -409,6 +417,7 @@ invalid_access: static enum mmio_result pci_mmconfig_access_handler(void *arg, struct mmio_access *mmio) { + u16* cur_domain = arg; u32 reg_addr = mmio->address & 0xfff; u16 bdf = mmio->address >> 12; struct pci_device *device; @@ -419,7 +428,7 @@ static enum mmio_result pci_mmconfig_access_handler(void *arg, if (mmio->size > 4) goto invalid_access; - device = pci_get_assigned_device(this_cell(), bdf); + device = pci_get_assigned_device(this_cell(), bdf, *cur_domain); if (mmio->is_write) { result = pci_cfg_write_moderate(device, reg_addr, mmio->size, @@ -433,7 +442,7 @@ static enum mmio_result pci_mmconfig_access_handler(void *arg, mmio->value = val; } if (result == PCI_ACCESS_PERFORM) - mmio_perform_access(pci_space, mmio); + mmio_perform_access(pci_space[device->info->mmconfig_id], mmio); return MMIO_HANDLED; @@ -442,9 +451,9 @@ invalid_access: "reg: 0x%x, size: %d\n", PCI_BDF_PARAMS(bdf), reg_addr, mmio->size); return MMIO_ERROR; - } + /** * Retrieve number of enabled MSI vector of a device. * @param device The device to be examined. @@ -460,12 +469,11 @@ unsigned int pci_enabled_msi_vectors(struct pci_device *device) static void pci_save_msi(struct pci_device *device, const struct jailhouse_pci_capability *cap) { - u16 bdf = device->info->bdf; unsigned int n; for (n = 0; n < (device->info->msi_64bits ? 4 : 3); n++) device->msi_registers.raw[n] = - pci_read_config(bdf, cap->start + n * 4, 4); + pci_read_config(device, cap->start + n * 4, 4); } static void pci_restore_msi(struct pci_device *device, @@ -474,7 +482,7 @@ static void pci_restore_msi(struct pci_device *device, unsigned int n; for (n = 1; n < (device->info->msi_64bits ? 4 : 3); n++) - pci_write_config(device->info->bdf, cap->start + n * 4, + pci_write_config(device, cap->start + n * 4, device->msi_registers.raw[n], 4); } @@ -486,7 +494,7 @@ static void pci_suppress_msix(struct pci_device *device, if (suppressed) regs.fmask = 1; - pci_write_config(device->info->bdf, cap->start, regs.raw, 4); + pci_write_config(device, cap->start, regs.raw, 4); } static void pci_save_msix(struct pci_device *device, @@ -495,7 +503,7 @@ static void pci_save_msix(struct pci_device *device, unsigned int n, r; device->msix_registers.raw = - pci_read_config(device->info->bdf, cap->start, 4); + pci_read_config(device, cap->start, 4); for (n = 0; n < device->info->num_msix_vectors; n++) for (r = 0; r < 4; r++) @@ -558,12 +566,12 @@ void pci_reset_device(struct pci_device *device) } /* Make sure we can reach the MSI-X registers. */ - pci_write_config(device->info->bdf, PCI_CFG_COMMAND, PCI_CMD_MEM, 2); + pci_write_config(device, PCI_CFG_COMMAND, PCI_CMD_MEM, 2); for_each_pci_cap(cap, device, n) { if (cap->id == PCI_CAP_ID_MSI || cap->id == PCI_CAP_ID_MSIX) /* Disable MSI/MSI-X by clearing the control word. */ - pci_write_config(device->info->bdf, cap->start+2, 0, 2); + pci_write_config(device, cap->start+2, 0, 2); if (cap->id == PCI_CAP_ID_MSIX) /* Mask each MSI-X vector also physically. */ for (n = 0; n < device->info->num_msix_vectors; n++) @@ -578,11 +586,11 @@ static int pci_add_physical_device(struct cell *cell, struct pci_device *device) unsigned int n, pages, size = device->info->msix_region_size; int err; - printk("Adding PCI device %02x:%02x.%x to cell \"%s\"\n", + printk("Adding PCI device %04x:%02x:%02x.%x to cell \"%s\"\n", device->info->domain, PCI_BDF_PARAMS(device->info->bdf), cell->config->name); for (n = 0; n < PCI_NUM_BARS; n ++) - device->bar[n] = pci_read_config(device->info->bdf, + device->bar[n] = pci_read_config(device, PCI_CFG_BAR + n * 4, 4); err = arch_pci_add_physical_device(cell, device); @@ -629,7 +637,7 @@ static void pci_remove_physical_device(struct pci_device *device) { struct cell *cell = device->cell; - printk("Removing PCI device %02x:%02x.%x from cell \"%s\"\n", + printk("Removing PCI device %04x:%02x:%02x.%x from cell \"%s\"\n", device->info->domain, PCI_BDF_PARAMS(device->info->bdf), cell->config->name); pci_reset_device(device); @@ -669,12 +677,20 @@ static int pci_cell_init(struct cell *cell) jailhouse_cell_pci_devices(cell->config); const struct jailhouse_pci_capability *cap; struct pci_device *device, *root_device; - unsigned int ndev, ncap; + unsigned int ndev, ncap, n; int err; - if (mmcfg_start != 0) - mmio_region_register(cell, mmcfg_start, mmcfg_size, - pci_mmconfig_access_handler, NULL); + if (!system_config->platform_info.num_pcie_units) { + if (mmcfg_start[0] != 0) + mmio_region_register(cell, mmcfg_start[0], mmcfg_size[0], + pci_mmconfig_access_handler, &domains[0]); + } else { + for (n = 0; n < system_config->platform_info.num_pcie_units; n++) { + if (mmcfg_start[n] != 0) + mmio_region_register(cell, mmcfg_start[n], mmcfg_size[n], + pci_mmconfig_access_handler, &domains[n]); + } + } if (cell->config->num_pci_devices == 0) return 0; @@ -703,7 +719,7 @@ static int pci_cell_init(struct cell *cell) } root_device = pci_get_assigned_device(&root_cell, - dev_infos[ndev].bdf); + dev_infos[ndev].bdf, dev_infos[ndev].domain); if (root_device) pci_remove_physical_device(root_device); @@ -844,14 +860,35 @@ error: */ static int pci_init(void) { - mmcfg_start = system_config->platform_info.pci_mmconfig_base; - end_bus = system_config->platform_info.pci_mmconfig_end_bus; - mmcfg_size = (end_bus + 1) * 256 * 4096; - - if (mmcfg_start != 0 && !system_config->platform_info.pci_is_virtual) { - pci_space = paging_map_device(mmcfg_start, mmcfg_size); - if (!pci_space) - return -ENOMEM; + u16 n; + u32 num_pcie = system_config->platform_info.num_pcie_units; + + if (!num_pcie) { + domains[0] = 0; + mmcfg_start[0] = system_config->platform_info.pci_mmconfig_base; + end_bus[0] = system_config->platform_info.pci_mmconfig_end_bus; + mmcfg_size[0] = (end_bus[0] + 1) * 256 * 4096; + } else { + for (n = 0; n < num_pcie; n++) { + domains[n] = n; + mmcfg_start[n] = system_config->platform_info.pci_mmconfig_bases[n]; + end_bus[n] = system_config->platform_info.pci_mmconfig_end_buses[n]; + mmcfg_size[n] = (end_bus[n] + 1) * 256 * 4096; + } + } + + if (!num_pcie) + num_pcie = 1; + + for (n = 0; n < num_pcie; n++) { + if (0 == n && system_config->platform_info.pci_is_virtual) + break; + + if (mmcfg_start[n] != 0) { + pci_space[n] = paging_map_device(mmcfg_start[n], mmcfg_size[n]); + if (!pci_space[n]) + return -ENOMEM; + } } return pci_cell_init(&root_cell); @@ -880,7 +917,7 @@ static void pci_shutdown(void) pci_restore_msix(device, cap); if (device->cell != &root_cell) - pci_write_config(device->info->bdf, PCI_CFG_COMMAND, + pci_write_config(device, PCI_CFG_COMMAND, PCI_CMD_INTX_OFF, 2); } } diff --git a/src/jailhouse/include/jailhouse/cell-config.h b/src/jailhouse/include/jailhouse/cell-config.h index 26f6474..946ebd4 100644 --- a/src/jailhouse/include/jailhouse/cell-config.h +++ b/src/jailhouse/include/jailhouse/cell-config.h @@ -174,7 +174,7 @@ struct jailhouse_irqchip { __u64 address; __u32 id; __u32 pin_base; - __u32 pin_bitmap[4]; + __u32 pin_bitmap[22]; } __attribute__((packed)); #define JAILHOUSE_PCI_TYPE_DEVICE 0x01 @@ -205,6 +205,8 @@ struct jailhouse_pci_device { __u16 num_msix_vectors; __u16 msix_region_size; __u64 msix_address; + /** ID of pci config space (pci_mmconfig_bases[mmconfig_id]) */ + __u16 mmconfig_id; /** First memory region index of shared memory device. */ __u32 shmem_regions_start; /** ID of shared memory device (0..shmem_peers-1). */ @@ -256,6 +258,7 @@ struct jailhouse_pci_capability { #define JAILHOUSE_MAX_IOMMU_UNITS 8 #define JAILHOUSE_MAX_GICR_REGIONS 16 +#define JAILHOUSE_MAX_PCIE_UNITS 8 #define JAILHOUSE_IOMMU_AMD 1 #define JAILHOUSE_IOMMU_INTEL 2 @@ -329,8 +332,15 @@ struct jailhouse_system { struct jailhouse_memory hypervisor_memory; struct jailhouse_console debug_console; struct { - __u64 pci_mmconfig_base; - __u8 pci_mmconfig_end_bus; + union { + __u64 pci_mmconfig_base; + __u64 pci_mmconfig_bases[JAILHOUSE_MAX_PCIE_UNITS]; + }; + union { + __u8 pci_mmconfig_end_bus; + __u8 pci_mmconfig_end_buses[JAILHOUSE_MAX_PCIE_UNITS]; + }; + __u32 num_pcie_units; __u8 pci_is_virtual; __u16 pci_domain; struct jailhouse_iommu iommu_units[JAILHOUSE_MAX_IOMMU_UNITS]; diff --git a/src/jailhouse/include/jailhouse/hypercall.h b/src/jailhouse/include/jailhouse/hypercall.h index 07574d3..5a29574 100644 --- a/src/jailhouse/include/jailhouse/hypercall.h +++ b/src/jailhouse/include/jailhouse/hypercall.h @@ -121,7 +121,8 @@ /** Debug console that may be accessed by the inmate. */ \ struct jailhouse_console console; \ /** Base address of PCI memory mapped config. */ \ - __u64 pci_mmconfig_base; + __u64 pci_mmconfig_base; \ + __u64 pci_mmconfig_bases[JAILHOUSE_MAX_PCIE_UNITS]; #include -- Gitee From d6fad26af1854f1c013eb2b0204ce73b6049bac4 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Mon, 17 Feb 2025 15:08:39 +0800 Subject: [PATCH 14/26] configs: arm64: change the domain ID of IVSHMEM device to 0 After the commit 818b0fd, we only support domain ID 0 for ivshmem PCI devices. It is sufficient to distinguish IVSHMEM devices by different bdf numbers. Signed-off-by: Huaizhi Wen --- src/jailhouse/configs/arm64/d2000-ivshmem-demo.c | 2 +- src/jailhouse/configs/arm64/d2000-linux-demo.c | 2 +- src/jailhouse/configs/arm64/d2000.c | 2 +- src/jailhouse/configs/arm64/d3000-ivshmem-demo.c | 2 +- src/jailhouse/configs/arm64/d3000.c | 2 +- src/jailhouse/configs/arm64/e2000q-ivshmem-demo.c | 2 +- src/jailhouse/configs/arm64/e2000q-linux-demo.c | 2 +- src/jailhouse/configs/arm64/e2000q.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/jailhouse/configs/arm64/d2000-ivshmem-demo.c b/src/jailhouse/configs/arm64/d2000-ivshmem-demo.c index 28a610a..51c67e7 100644 --- a/src/jailhouse/configs/arm64/d2000-ivshmem-demo.c +++ b/src/jailhouse/configs/arm64/d2000-ivshmem-demo.c @@ -120,7 +120,7 @@ struct { .pci_devices = { { .type = JAILHOUSE_PCI_TYPE_IVSHMEM, - .domain = 1, + .domain = 0, .bdf = 0x0e << 3, .bar_mask = JAILHOUSE_IVSHMEM_BAR_MASK_INTX, .shmem_regions_start = 0, diff --git a/src/jailhouse/configs/arm64/d2000-linux-demo.c b/src/jailhouse/configs/arm64/d2000-linux-demo.c index 8d64fcc..466bde9 100644 --- a/src/jailhouse/configs/arm64/d2000-linux-demo.c +++ b/src/jailhouse/configs/arm64/d2000-linux-demo.c @@ -163,7 +163,7 @@ struct { .pci_devices = { { .type = JAILHOUSE_PCI_TYPE_IVSHMEM, - .domain = 1, + .domain = 0, .bdf = 0 << 3, .bar_mask = JAILHOUSE_IVSHMEM_BAR_MASK_INTX, .shmem_regions_start = 0, diff --git a/src/jailhouse/configs/arm64/d2000.c b/src/jailhouse/configs/arm64/d2000.c index 41bfa57..74c8350 100644 --- a/src/jailhouse/configs/arm64/d2000.c +++ b/src/jailhouse/configs/arm64/d2000.c @@ -312,7 +312,7 @@ struct { .pci_devices = { { .type = JAILHOUSE_PCI_TYPE_IVSHMEM, - .domain = 1, + .domain = 0, .bdf = 0 << 3, .bar_mask = JAILHOUSE_IVSHMEM_BAR_MASK_INTX, .shmem_regions_start = 0, diff --git a/src/jailhouse/configs/arm64/d3000-ivshmem-demo.c b/src/jailhouse/configs/arm64/d3000-ivshmem-demo.c index 39c7e1a..40a29a5 100644 --- a/src/jailhouse/configs/arm64/d3000-ivshmem-demo.c +++ b/src/jailhouse/configs/arm64/d3000-ivshmem-demo.c @@ -119,7 +119,7 @@ struct { .pci_devices = { { .type = JAILHOUSE_PCI_TYPE_IVSHMEM, - .domain = 1, + .domain = 0, .bdf = 0x0 << 3, .bar_mask = JAILHOUSE_IVSHMEM_BAR_MASK_INTX, .shmem_regions_start = 0, diff --git a/src/jailhouse/configs/arm64/d3000.c b/src/jailhouse/configs/arm64/d3000.c index ed95a0c..c711603 100644 --- a/src/jailhouse/configs/arm64/d3000.c +++ b/src/jailhouse/configs/arm64/d3000.c @@ -355,7 +355,7 @@ struct { .pci_devices = { { .type = JAILHOUSE_PCI_TYPE_IVSHMEM, - .domain = 1, + .domain = 0, .bdf = 0 << 3, .bar_mask = JAILHOUSE_IVSHMEM_BAR_MASK_INTX, .shmem_regions_start = 0, diff --git a/src/jailhouse/configs/arm64/e2000q-ivshmem-demo.c b/src/jailhouse/configs/arm64/e2000q-ivshmem-demo.c index c3658a0..74c3196 100644 --- a/src/jailhouse/configs/arm64/e2000q-ivshmem-demo.c +++ b/src/jailhouse/configs/arm64/e2000q-ivshmem-demo.c @@ -117,7 +117,7 @@ struct { .pci_devices = { { .type = JAILHOUSE_PCI_TYPE_IVSHMEM, - .domain = 1, + .domain = 0, .bdf = 0 << 3, .bar_mask = JAILHOUSE_IVSHMEM_BAR_MASK_INTX, .shmem_regions_start = 0, diff --git a/src/jailhouse/configs/arm64/e2000q-linux-demo.c b/src/jailhouse/configs/arm64/e2000q-linux-demo.c index 12e7843..81e3755 100644 --- a/src/jailhouse/configs/arm64/e2000q-linux-demo.c +++ b/src/jailhouse/configs/arm64/e2000q-linux-demo.c @@ -119,7 +119,7 @@ struct { .pci_devices = { { .type = JAILHOUSE_PCI_TYPE_IVSHMEM, - .domain = 1, + .domain = 0, .bdf = 0 << 3, .bar_mask = JAILHOUSE_IVSHMEM_BAR_MASK_INTX, .shmem_regions_start = 0, diff --git a/src/jailhouse/configs/arm64/e2000q.c b/src/jailhouse/configs/arm64/e2000q.c index 47dcc3a..aa9fb4c 100644 --- a/src/jailhouse/configs/arm64/e2000q.c +++ b/src/jailhouse/configs/arm64/e2000q.c @@ -687,7 +687,7 @@ struct { .pci_devices = { { .type = JAILHOUSE_PCI_TYPE_IVSHMEM, - .domain = 1, + .domain = 0, .bdf = 0 << 3, .bar_mask = JAILHOUSE_IVSHMEM_BAR_MASK_INTX, .shmem_regions_start = 0, -- Gitee From 263a005f2f806c6131a381867a13fbe6167549d3 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Tue, 11 Feb 2025 08:35:52 +0000 Subject: [PATCH 15/26] scripts: gen_version_h: fix the building error fatal: No tags can describe '7c80882965c632e1123cba4fd1d13d1114f12965'. Try --always, or create some tags Signed-off-by: Huaizhi Wen --- src/jailhouse/scripts/gen_version_h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jailhouse/scripts/gen_version_h b/src/jailhouse/scripts/gen_version_h index 2ce0eff..b04865d 100755 --- a/src/jailhouse/scripts/gen_version_h +++ b/src/jailhouse/scripts/gen_version_h @@ -19,7 +19,7 @@ cd "$1" > /dev/null if ! git rev-parse 2>/dev/null; then version="`cat VERSION`" else - describe="`git describe --long --dirty --match "v[0-9].[0-9]*"`" + describe="`git describe --long --dirty --match "v[0-9].[0-9]*" --always`" version="`echo $describe | sed -e 's/\([^-]*\)-\(.*\)/\1 (\2)/'`" fi -- Gitee From 274f5bb91fe3cfdd6cae0bbceacf168fcd5cd4ed Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sun, 2 Jan 2022 12:55:20 +0100 Subject: [PATCH 16/26] core, inmates: Add own stdarg.h The kernel stops using the system headers with 5.16, and so should we. Just add two simple headers that map va_* to __builtin_va_*. Signed-off-by: Jan Kiszka --- .../hypervisor/include/jailhouse/stdarg.h | 17 ++++++++ src/jailhouse/hypervisor/printk.c | 4 +- src/jailhouse/inmates/lib/include/stdarg.h | 43 +++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/jailhouse/hypervisor/include/jailhouse/stdarg.h create mode 100644 src/jailhouse/inmates/lib/include/stdarg.h diff --git a/src/jailhouse/hypervisor/include/jailhouse/stdarg.h b/src/jailhouse/hypervisor/include/jailhouse/stdarg.h new file mode 100644 index 0000000..7c8633d --- /dev/null +++ b/src/jailhouse/hypervisor/include/jailhouse/stdarg.h @@ -0,0 +1,17 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Copyright (c) Siemens AG, 2022 + * + * Authors: + * Jan Kiszka + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +typedef __builtin_va_list va_list; + +#define va_start(ap, last) __builtin_va_start(ap, last) +#define va_arg(ap, type) __builtin_va_arg(ap, type) +#define va_end(ap) __builtin_va_end(ap) diff --git a/src/jailhouse/hypervisor/printk.c b/src/jailhouse/hypervisor/printk.c index 1b3027b..d2ca6eb 100644 --- a/src/jailhouse/hypervisor/printk.c +++ b/src/jailhouse/hypervisor/printk.c @@ -1,7 +1,7 @@ /* * Jailhouse, a Linux-based partitioning hypervisor * - * Copyright (c) Siemens AG, 2013-2019 + * Copyright (c) Siemens AG, 2013-2022 * * Authors: * Jan Kiszka @@ -10,10 +10,10 @@ * the COPYING file in the top-level directory. */ -#include #include #include #include +#include #include #include diff --git a/src/jailhouse/inmates/lib/include/stdarg.h b/src/jailhouse/inmates/lib/include/stdarg.h new file mode 100644 index 0000000..21e5885 --- /dev/null +++ b/src/jailhouse/inmates/lib/include/stdarg.h @@ -0,0 +1,43 @@ +/* + * Jailhouse, a Linux-based partitioning hypervisor + * + * Copyright (c) Siemens AG, 2022 + * + * Authors: + * Jan Kiszka + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Alternatively, you can use or redistribute this file under the following + * BSD license: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +typedef __builtin_va_list va_list; + +#define va_start(ap, last) __builtin_va_start(ap, last) +#define va_arg(ap, type) __builtin_va_arg(ap, type) +#define va_end(ap) __builtin_va_end(ap) -- Gitee From a360da3c4dec5ba90e593b8259fb0c885e4cf563 Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Wed, 27 Apr 2022 20:18:42 +0200 Subject: [PATCH 17/26] driver: sysfs: Add compatibility for default_groups Since Linux commit cdb4f26a63c3 ("kobject: kobj_type: remove default_attrs"), the deprecated kobj member default_attrs is gone. It is replaced by default_groups. Add a compatibility layer to support older, as well as latest kernel versions. Signed-off-by: Ralf Ramsauer Signed-off-by: Jan Kiszka --- src/jailhouse/driver/sysfs.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/jailhouse/driver/sysfs.c b/src/jailhouse/driver/sysfs.c index a604afa..a5a0283 100644 --- a/src/jailhouse/driver/sysfs.c +++ b/src/jailhouse/driver/sysfs.c @@ -59,6 +59,14 @@ static const struct sysfs_ops cell_sysfs_ops = { }; #define kobj_sysfs_ops cell_sysfs_ops #endif /* < 3.14 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,2,0) +#define COMPAT_ATTRIBUTE_GROUPS(x) /* not used */ +#define DEFAULT_GROUPS(x) .default_attrs = x##_attrs +#else +#define COMPAT_ATTRIBUTE_GROUPS(x) ATTRIBUTE_GROUPS(x) +#define DEFAULT_GROUPS(x) .default_groups = x##_groups +#endif /* < 5.2 */ /* End of compatibility section - remove as version become obsolete */ static struct kobject *cells_dir; @@ -180,10 +188,11 @@ static struct attribute *cell_stats_attrs[] = { #endif NULL }; +COMPAT_ATTRIBUTE_GROUPS(cell_stats); static struct kobj_type cell_stats_type = { .sysfs_ops = &kobj_sysfs_ops, - .default_attrs = cell_stats_attrs, + DEFAULT_GROUPS(cell_stats), }; static struct attribute *cpu_stats_attrs[] = { @@ -212,10 +221,11 @@ static struct attribute *cpu_stats_attrs[] = { #endif NULL }; +COMPAT_ATTRIBUTE_GROUPS(cpu_stats); static struct kobj_type cell_cpu_type = { .sysfs_ops = &kobj_sysfs_ops, - .default_attrs = cpu_stats_attrs, + DEFAULT_GROUPS(cpu_stats), }; static int print_cpumask(char *buf, size_t size, cpumask_t *mask, bool as_list) @@ -342,11 +352,12 @@ static struct attribute *cell_attrs[] = { &cell_cpus_failed_list_attr.attr, NULL, }; +COMPAT_ATTRIBUTE_GROUPS(cell); static struct kobj_type cell_type = { .release = jailhouse_cell_kobj_release, .sysfs_ops = &kobj_sysfs_ops, - .default_attrs = cell_attrs, + DEFAULT_GROUPS(cell), }; static struct cell_cpu *find_cell_cpu(struct cell *cell, unsigned int cpu) -- Gitee From b94625b514781cb96d1ef0353ae130323cc1ff48 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Sun, 23 Jan 2022 14:37:31 +0100 Subject: [PATCH 18/26] inmates: arm: Add missing FORCE prerequisite Missed in b5a39e1746dc. Signed-off-by: Jan Kiszka --- src/jailhouse/inmates/lib/arm/Makefile.lib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jailhouse/inmates/lib/arm/Makefile.lib b/src/jailhouse/inmates/lib/arm/Makefile.lib index 2ea037c..5df2632 100644 --- a/src/jailhouse/inmates/lib/arm/Makefile.lib +++ b/src/jailhouse/inmates/lib/arm/Makefile.lib @@ -58,8 +58,8 @@ endef .SECONDEXPANSION: $(obj)/%-linked.o: $(INMATES_LIB)/inmate.lds $$(addprefix $$(obj)/,$$($$*-y)) \ - $(INMATES_LIB)/lib.a + $(INMATES_LIB)/lib.a FORCE $(call if_changed,ld) -$(obj)/%.bin: $(obj)/%-linked.o +$(obj)/%.bin: $(obj)/%-linked.o FORCE $(call if_changed,objcopy) -- Gitee From 775303502c8d2c96fbfd6b5569e62c6fff10d453 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Thu, 30 Sep 2021 09:03:19 +0200 Subject: [PATCH 19/26] Makefile/Kbuild: Fix "FORCE prerequisite is missing" warning With Linux kernel has a change that "kbuild: warn if FORCE is missing for if_changed(_dep,_rule) and filechk", so add FORCE in Makefile/Kbuild to avoid build warning. Signed-off-by: Peng Fan Signed-off-by: Jan Kiszka --- src/jailhouse/Kbuild | 4 ++-- src/jailhouse/configs/Makefile | 2 +- src/jailhouse/hypervisor/Makefile | 6 +++--- src/jailhouse/hypervisor/arch/x86/Kbuild | 6 +++--- src/jailhouse/inmates/lib/arm64/Makefile.lib | 4 ++-- src/jailhouse/inmates/lib/x86/Makefile | 4 ++-- src/jailhouse/inmates/lib/x86/Makefile.lib | 4 ++-- src/jailhouse/tools/Makefile | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/jailhouse/Kbuild b/src/jailhouse/Kbuild index b76a8dd..2863c12 100644 --- a/src/jailhouse/Kbuild +++ b/src/jailhouse/Kbuild @@ -46,12 +46,12 @@ $(GEN_VERSION_H): $(src)/Makefile FORCE quiet_cmd_gen_pci_defs = GEN $@ define cmd_gen_pci_defs - $^ $(src)/include/jailhouse/pci_defs.h > $@ + $< $(src)/include/jailhouse/pci_defs.h > $@ endef GEN_PCI_DEFS_PY := $(obj)/pyjailhouse/pci_defs.py -$(GEN_PCI_DEFS_PY): $(src)/scripts/gen_pci_defs.sh +$(GEN_PCI_DEFS_PY): $(src)/scripts/gen_pci_defs.sh FORCE $(call if_changed,gen_pci_defs) subdir-y := hypervisor configs inmates tools diff --git a/src/jailhouse/configs/Makefile b/src/jailhouse/configs/Makefile index 74b35f0..327043b 100644 --- a/src/jailhouse/configs/Makefile +++ b/src/jailhouse/configs/Makefile @@ -38,5 +38,5 @@ targets += $(DTS:.dts=.dtb) # prevent deleting intermediate files which would cause rebuilds .SECONDARY: $(addprefix $(obj)/,$(CONFIGS:.c=.o)) -$(obj)/%.cell: $(obj)/%.o +$(obj)/%.cell: $(obj)/%.o FORCE $(call if_changed,objcopy) diff --git a/src/jailhouse/hypervisor/Makefile b/src/jailhouse/hypervisor/Makefile index 3807e60..8ae4e33 100644 --- a/src/jailhouse/hypervisor/Makefile +++ b/src/jailhouse/hypervisor/Makefile @@ -80,7 +80,7 @@ ASM_DEFINES_H := arch/$(SRCARCH)/include/generated/asm/asm-defines.h targets := $(ASM_DEFINES_H) arch/$(SRCARCH)/asm-defines.s -$(obj)/arch/$(SRCARCH)/asm-defines.s: $(src)/arch/$(SRCARCH)/asm-defines.c +$(obj)/arch/$(SRCARCH)/asm-defines.s: $(src)/arch/$(SRCARCH)/asm-defines.c FORCE $(call if_changed_dep,cc_s_c) $(obj)/$(ASM_DEFINES_H): $(obj)/arch/$(SRCARCH)/asm-defines.s @@ -110,13 +110,13 @@ HYPERVISOR$(1)_OBJS = $$(addprefix $$(obj)/,$$(hypervisor$(1)-y)) LDFLAGS_hypervisor$(1).o := --whole-archive -T targets += hypervisor$(1).o -$$(obj)/hypervisor$(1).o: $$(src)/hypervisor.lds $$(HYPERVISOR$(1)_OBJS) +$$(obj)/hypervisor$(1).o: $$(src)/hypervisor.lds $$(HYPERVISOR$(1)_OBJS) FORCE $$(call if_changed,ld) OBJCOPYFLAGS_jailhouse$(1).bin := -O binary -R .eh_frame targets += jailhouse$(1).bin -$$(obj)/jailhouse$(1).bin: $$(obj)/hypervisor$(1).o +$$(obj)/jailhouse$(1).bin: $$(obj)/hypervisor$(1).o FORCE $$(call if_changed,objcopy) endef diff --git a/src/jailhouse/hypervisor/arch/x86/Kbuild b/src/jailhouse/hypervisor/arch/x86/Kbuild index a6badca..7a42adb 100644 --- a/src/jailhouse/hypervisor/arch/x86/Kbuild +++ b/src/jailhouse/hypervisor/arch/x86/Kbuild @@ -40,10 +40,10 @@ intel-objs := vmx.o vtd.o vmx-vmexit.o $(common-objs-y) cat.o targets += $(amd-objs) $(intel-objs) quiet_cmd_link_archive = AR $@ -cmd_link_archive = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $^ +cmd_link_archive = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(filter-out FORCE,$^) -$(obj)/lib-amd.a: $(addprefix $(obj)/,$(amd-objs)) +$(obj)/lib-amd.a: $(addprefix $(obj)/,$(amd-objs)) FORCE $(call if_changed,link_archive) -$(obj)/lib-intel.a: $(addprefix $(obj)/,$(intel-objs)) +$(obj)/lib-intel.a: $(addprefix $(obj)/,$(intel-objs)) FORCE $(call if_changed,link_archive) diff --git a/src/jailhouse/inmates/lib/arm64/Makefile.lib b/src/jailhouse/inmates/lib/arm64/Makefile.lib index 2ea037c..5df2632 100644 --- a/src/jailhouse/inmates/lib/arm64/Makefile.lib +++ b/src/jailhouse/inmates/lib/arm64/Makefile.lib @@ -58,8 +58,8 @@ endef .SECONDEXPANSION: $(obj)/%-linked.o: $(INMATES_LIB)/inmate.lds $$(addprefix $$(obj)/,$$($$*-y)) \ - $(INMATES_LIB)/lib.a + $(INMATES_LIB)/lib.a FORCE $(call if_changed,ld) -$(obj)/%.bin: $(obj)/%-linked.o +$(obj)/%.bin: $(obj)/%-linked.o FORCE $(call if_changed,objcopy) diff --git a/src/jailhouse/inmates/lib/x86/Makefile b/src/jailhouse/inmates/lib/x86/Makefile index 35f0416..06a84ec 100644 --- a/src/jailhouse/inmates/lib/x86/Makefile +++ b/src/jailhouse/inmates/lib/x86/Makefile @@ -51,9 +51,9 @@ lib-y := $(TARGETS) $(TARGETS_64_ONLY) lib32-y := $(TARGETS:.o=-32.o) $(TARGETS_32_ONLY) quiet_cmd_link_archive32 = AR $@ -cmd_link_archive32 = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $^ +cmd_link_archive32 = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(filter-out FORCE,$^) -$(obj)/lib32.a: $(addprefix $(obj)/,$(lib32-y)) +$(obj)/lib32.a: $(addprefix $(obj)/,$(lib32-y)) FORCE $(call if_changed,link_archive32) targets += $(lib32-y) diff --git a/src/jailhouse/inmates/lib/x86/Makefile.lib b/src/jailhouse/inmates/lib/x86/Makefile.lib index 872b7ce..b574856 100644 --- a/src/jailhouse/inmates/lib/x86/Makefile.lib +++ b/src/jailhouse/inmates/lib/x86/Makefile.lib @@ -57,10 +57,10 @@ endef # obj/NAME-linked.o: ... obj/$(NAME-y) lib/lib[32].a .SECONDEXPANSION: $(obj)/%-linked.o: $(INMATES_LIB)/inmate.lds $$(addprefix $$(obj)/,$$($$*-y)) \ - $(INMATES_LIB)/$$(if $$($$*_32),lib32.a,lib.a) + $(INMATES_LIB)/$$(if $$($$*_32),lib32.a,lib.a) FORCE $(call if_changed,ld) -$(obj)/%.bin: $(obj)/%-linked.o +$(obj)/%.bin: $(obj)/%-linked.o FORCE $(call if_changed,objcopy) # 32-bit (i386) support diff --git a/src/jailhouse/tools/Makefile b/src/jailhouse/tools/Makefile index 6258536..d513ad1 100644 --- a/src/jailhouse/tools/Makefile +++ b/src/jailhouse/tools/Makefile @@ -111,7 +111,7 @@ define cmd_gen_man sed 's/$${VERSION}/$(shell cat $(src)/../VERSION)/g' $< > $@ endef -$(obj)/%: $(obj)/%.o +$(obj)/%: $(obj)/%.o FORCE $(call if_changed,ld) CFLAGS_jailhouse-gcov-extract.o := -I$(src)/../hypervisor/include \ @@ -122,13 +122,13 @@ LDFLAGS_jailhouse-gcov-extract := -lgcov -fprofile-arcs targets += jailhouse-gcov-extract.o always-y += jailhouse-gcov-extract -$(obj)/jailhouse-config-collect: $(src)/jailhouse-config-create $(src)/jailhouse-config-collect.tmpl +$(obj)/jailhouse-config-collect: $(src)/jailhouse-config-create $(src)/jailhouse-config-collect.tmpl FORCE $(call if_changed,gen_collect) targets += $(MAN8_PAGES) always-y += $(MAN8_PAGES) -$(obj)/%.8: $(src)/%.8.in +$(obj)/%.8: $(src)/%.8.in FORCE $(call if_changed,gen_man) install-bin: $(BINARIES) $(DESTDIR)$(sbindir) -- Gitee From 94b85f25ba08464739936171c29ac3807d6ad269 Mon Sep 17 00:00:00 2001 From: Alice Guo Date: Tue, 19 Sep 2023 08:27:47 +0000 Subject: [PATCH 20/26] LF-10135 driver: update the use of of_overlay_fdt_apply() When the kernel version >= 6.6.0, of_overlay_fdt_apply() has a parameter named base that is a pointer for the target node to apply overlay. Update the use of of_overlay_fdt_apply() to adapt to its change. Signed-off-by: Alice Guo Reviewed-by: Peng Fan --- src/jailhouse/driver/pci.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/jailhouse/driver/pci.c b/src/jailhouse/driver/pci.c index 0aecd05..0a8f39d 100644 --- a/src/jailhouse/driver/pci.c +++ b/src/jailhouse/driver/pci.c @@ -331,7 +331,12 @@ static bool create_vpci_of_overlay(struct jailhouse_system *config) gic_phandle = gic->phandle; of_node_put(gic); - +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,6,0) + if (of_overlay_fdt_apply(__dtb_vpci_template_begin, + __dtb_vpci_template_end - __dtb_vpci_template_begin, + &overlay_id, NULL) < 0) + return false; +#else /* < 6.6.0 */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0) if (of_overlay_fdt_apply(__dtb_vpci_template_begin, __dtb_vpci_template_end - __dtb_vpci_template_begin, @@ -353,6 +358,7 @@ static bool create_vpci_of_overlay(struct jailhouse_system *config) if (of_overlay_apply(overlay, &overlay_id) < 0) goto out_compat; #endif /* < 4.17 */ +#endif /* < 6.6.0 */ of_changeset_init(&overlay_changeset); -- Gitee From 2e69740ba2a038d97fa6351a4830c554f14d19f8 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Wed, 12 Jan 2022 07:38:53 +0100 Subject: [PATCH 21/26] configs: arm64: Fix dtc warnings from recent kernels Resolves jailhouse/configs/arm64/dts/inmate-pine64-plus.dts:81.37-87.4: Warning (unit_address_format): /interrupt-controller@01c81000: unit name should not have leading 0s jailhouse/configs/arm64/dts/inmate-pine64-plus.dts:89.24-96.4: Warning (unit_address_format): /serial@01c28000: unit name should not have leading 0s jailhouse/configs/arm64/dts/inmate-pine64-plus.dts:98.15-113.4: Warning (unit_address_format): /pci@02000000: unit name should not have leading 0s Signed-off-by: Jan Kiszka --- src/jailhouse/configs/arm64/dts/inmate-pine64-plus.dts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jailhouse/configs/arm64/dts/inmate-pine64-plus.dts b/src/jailhouse/configs/arm64/dts/inmate-pine64-plus.dts index 0f980c9..6d0a12d 100644 --- a/src/jailhouse/configs/arm64/dts/inmate-pine64-plus.dts +++ b/src/jailhouse/configs/arm64/dts/inmate-pine64-plus.dts @@ -78,7 +78,7 @@ }; }; - gic: interrupt-controller@01c81000 { + gic: interrupt-controller@1c81000 { compatible = "arm,gic-400"; reg = <0x01c81000 0x1000>, <0x01c82000 0x2000>; @@ -86,7 +86,7 @@ #interrupt-cells = <3>; }; - uart: serial@01c28000 { + uart: serial@1c28000 { compatible = "snps,dw-apb-uart"; reg = <0x01c28000 0x400>; interrupts = ; @@ -95,7 +95,7 @@ clock-frequency = <24000000>; }; - pci@02000000 { + pci@2000000 { compatible = "pci-host-ecam-generic"; device_type = "pci"; bus-range = <0 0>; -- Gitee From ecaf21a02bfbf89c1f7e0b067f32d79d708e327e Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Tue, 4 Mar 2025 07:00:21 +0000 Subject: [PATCH 22/26] driver: update jailhouse_ioremap to be compatible with the 6.6.12 Linux kernel Because the implementation of the interface function ioremap_page_range has changed in the 6.6.12 kernel, the executable attribute has been removed when mapping to the kernel virtual address space. When enabling the root cell, the kernel will hang and report the following error: "Unable to handle kernel execute from non-executable memory at virtual address ffff800087004000" So, fix it. Signed-off-by: Huaizhi Wen --- src/jailhouse/driver/main.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/jailhouse/driver/main.c b/src/jailhouse/driver/main.c index def7842..ce58488 100644 --- a/src/jailhouse/driver/main.c +++ b/src/jailhouse/driver/main.c @@ -80,6 +80,12 @@ #define JAILHOUSE_FW_NAME "jailhouse.bin" #endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,6,0) +typedef int (*vmap_range_noflush_t)(unsigned long, unsigned long, + phys_addr_t, pgprot_t, unsigned int); +static vmap_range_noflush_t vmap_range_noflush_sym = NULL; +#endif + MODULE_DESCRIPTION("Management driver for Jailhouse partitioning hypervisor"); MODULE_LICENSE("GPL"); #ifdef CONFIG_X86 @@ -212,10 +218,14 @@ static typeof(__get_vm_area_caller) *__get_vm_area_caller_sym; __builtin_return_address(0)) #endif +#define JAILHOUSE_PAGE_SHIFT 12 +#define flush_cache_vmap(start,end) do { } while (0) + void *jailhouse_ioremap(phys_addr_t phys, unsigned long virt, unsigned long size) { struct vm_struct *vma; + int err; size = PAGE_ALIGN(size); if (virt) @@ -228,9 +238,18 @@ void *jailhouse_ioremap(phys_addr_t phys, unsigned long virt, return NULL; vma->phys_addr = phys; - if (ioremap_page_range_sym((unsigned long)vma->addr, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,6,0) + err = vmap_range_noflush_sym((unsigned long)vma->addr, + (unsigned long)vma->addr + size, phys, PAGE_KERNEL_EXEC, + JAILHOUSE_PAGE_SHIFT); + flush_cache_vmap((unsigned long)vma->addr, (unsigned long)vma->addr + size); +#else + err = ioremap_page_range_sym((unsigned long)vma->addr, (unsigned long)vma->addr + size, phys, - PAGE_KERNEL_EXEC)) { + PAGE_KERNEL_EXEC); +#endif + + if (err) { vunmap(vma->addr); return NULL; } @@ -978,6 +997,14 @@ static int __init jailhouse_init(void) RESOLVE_EXTERNAL_SYMBOL(__hyp_stub_vectors); #endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,6,0) + vmap_range_noflush_sym = (vmap_range_noflush_t)kallsyms_lookup_name("vmap_range_noflush"); + if (!vmap_range_noflush_sym) { + pr_err("vmap_range_noflush not found\n"); + return -ENOENT; + } +#endif + jailhouse_dev = root_device_register("jailhouse"); if (IS_ERR(jailhouse_dev)) return PTR_ERR(jailhouse_dev); -- Gitee From 60dff328989b6d2ca22f1e6cc2150dfa6fffa11a Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Thu, 30 Sep 2021 09:07:03 +0200 Subject: [PATCH 23/26] arm: gic-v3: clear SGI GICR active flag With Linux Kernel 5.15 commit 6abbd6988971a ("irqchip/gic, gic-v3: Make SGIs use handle_percpu_devid_irq()"), the on_each_cpu IPI_CALL_FUNC interrupt active flag will not be cleared until interrupt handler finish. Without Jailhouse hypervisor enabled, everything is ok, but when enabling jailhouse, HCR_EL2.[FMO | IMO] is set, that means NS-EL1 is actually accessing ICV_DIR_EL1 when eoi_irq after enter_hypervisor return. It not able to deactive the interrupt that is actually a phyiscal irq which in active state. To ARM64, the IPI_CALL_FUNC is using SGI 1 which is same value as jailhouse SGI_EVENT. Then the following `jailhouse cell create` will hang the system, because the previous 'SGI_EVENT' is in active state and not deactivated, so the current SGI_EVENT issued not able to interrupt the target cpu core. To resolve this issue, let's clear the active bit of SGI_EVENT and SGI_INJECT before back to Linux. Tested on NXP i.MX8MP-EVK Signed-off-by: Peng Fan [Jan: tune inline comment] Signed-off-by: Jan Kiszka --- src/jailhouse/hypervisor/arch/arm-common/gic-v3.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c b/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c index 5580528..dcbd37b 100644 --- a/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c +++ b/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c @@ -212,7 +212,7 @@ static int gicv3_cpu_init(struct per_cpu *cpu_data) unsigned long redist_addr; unsigned long redist_size = GIC_V3_REDIST_SIZE; void *redist_base; - unsigned long gicr_ispendr; + unsigned long gicr_ispendr, gicr_isacter; unsigned int n; void *gicr; u64 typer, mpidr; @@ -309,6 +309,10 @@ found: /* After this, the cells access the virtual interface of the GIC. */ arm_write_sysreg(ICH_HCR_EL2, ICH_HCR_EN); + /* Deactivate all active SGIs */ + gicr_isacter = mmio_read32(gicr + GICR_ISACTIVER); + mmio_write32(gicr + GICR_ICACTIVER, gicr_isacter & 0xffff); + /* Forward any pending physical SGIs to the virtual queue. */ gicr_ispendr = mmio_read32(gicr + GICR_ISPENDR); for (n = 0; n < 16; n++) { -- Gitee From 32e5a4f94346b816f11162e1f556bf78843bcc1a Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Wed, 19 Apr 2023 13:10:14 +0800 Subject: [PATCH 24/26] gic-v3: set SGI pending when it is active when need to inject a new SGI The interrupt state will be pending->active after IAR has been read, however if a new SGI is injected, we should not bypass it, otherwise SGI will lose. Signed-off-by: Peng Fan (cherry picked from commit ac960fcbcb5f5fa4d6de04f994a19ad7c9b9cf30) --- src/jailhouse/hypervisor/arch/arm-common/gic-v3.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c b/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c index dcbd37b..361bf7f 100644 --- a/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c +++ b/src/jailhouse/hypervisor/arch/arm-common/gic-v3.c @@ -582,8 +582,16 @@ static int gicv3_inject_irq(u16 irq_id, u16 sender) * A strict phys->virt id mapping is used for SPIs, so this test * should be sufficient. */ - if ((u32)lr == irq_id) + if ((u32)lr == irq_id) { + /* if interrupt is active set pending bit. */ + if ((lr & ICH_LR_PENDACTIVE) == ICH_LR_ACTIVE) { + lr |= ICH_LR_GROUP_BIT; + lr |= ICH_LR_PENDING; + gicv3_write_lr(n, lr); + return 0; + } return -EEXIST; + } } if (free_lr == -1) -- Gitee From 19ceae551acde139b00472e7d8c290e984b99d04 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Fri, 14 Mar 2025 03:34:19 +0000 Subject: [PATCH 25/26] driver: Makefile: We only compile uio_ivshmem.ko when kernel versions >= 5.10.209 Signed-off-by: Huaizhi Wen --- src/jailhouse/driver/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/jailhouse/driver/Makefile b/src/jailhouse/driver/Makefile index 03e7ab2..9a3d275 100644 --- a/src/jailhouse/driver/Makefile +++ b/src/jailhouse/driver/Makefile @@ -11,8 +11,14 @@ # the COPYING file in the top-level directory. # +KERNEL_VERSION = $(shell uname -r | awk -F. '{ printf("%d%03d%03d\n", $$1, $$2, $$3); }') +TARGET_VERSION = 5010209 + obj-m := jailhouse.o -obj-m += uio_ivshmem.o + +ifeq ($(shell [ $(KERNEL_VERSION) -ge $(TARGET_VERSION) ] && echo 1),1) + obj-m += uio_ivshmem.o +endif ccflags-y := -I$(src)/../hypervisor/arch/$(SRCARCH)/include \ -I$(src)/../hypervisor/include \ -- Gitee From 1581a8ceaaa1f0a4ec6ea95b6dca3ba5f4e62ba5 Mon Sep 17 00:00:00 2001 From: Huaizhi Wen Date: Fri, 21 Mar 2025 17:32:37 +0800 Subject: [PATCH 26/26] doc: update the Readme.md Signed-off-by: Huaizhi Wen --- Readme.md | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/Readme.md b/Readme.md index f3000f6..d5cab99 100755 --- a/Readme.md +++ b/Readme.md @@ -2,22 +2,29 @@ Jailhouse是一个基于Linux的分区虚拟机管理器,一旦激活就完全控制硬件。Jailhouse使用被称为cell的方式来配置CPU等硬件的虚拟化特性,cell是系统硬件资源的描述,使用C语言语法来描述。Cell分为root cell和non-root cell,root cell接管系统硬件资源,只有一个;non-root cell可以有多个,并且从root cell中获取系统资源,可独占或与root cell共享。 -Jailhouse编译完成后,生成文件分为三部分:第一部分,Jailhouse驱动和hypervisor固件,这部分提供用户态接口并初始化hypervisor;第二部分,cell和guest镜像,cell是镜像运行所需的系统资源的描述;guest镜像运行在cell之上,包括裸机,RTOS和Linux内核镜像等;第三部分,用户态工具,通过这些工具加载cell,运行镜像,查看Jailhouse状态等。 +Jailhouse编译完成后,生成文件分为三部分:第一部分,Jailhouse驱动和hypervisor固件,这部分提供用户态接口并初始化hypervisor;第二部分,cell和guest镜像,cell是镜像运行所需的系统资源的描述;guest镜像运行在cell之中,包括裸机,RTOS和Linux内核镜像等;第三部分,用户态工具,通过这些工具加载cell,运行镜像,查看Jailhouse状态等。 +Phytium-Jailhouse针对飞腾系列芯片做了深度适配以及功能扩展。目前已经适配的芯片包括:E2000Q、D2000、FT-2000/4、D3000以及S5000C,但目前Jailhouse的代码中不包含S5000C相关的cell配置文件,如有需要,请咨询:linan1284@phytium.com.cn。 + +目前Phytium-Jailhouse支持在non-root cell中运行裸跑程序、RTOS以及Linux系统。需要说明的是,本文档中涉及的裸机测试程序是由Phytium-Jailhouse提供,并非来自phytium-standalone-sdk中的裸机例程。 + +关于Phytium-Jailhouse更多详细信息请阅读《Jailhouse使用手册》,文档位于: + + https://gitee.com/phytium_embedded/phytium-embedded-docs/tree/master/linux # 2 编译 -(1)通过gitee或是正式技术支持渠道获取内核源码,需要注意内核版本和目标机器环境运行的内核版本应保持一致,且当前phytium jailhouse支持的内核版本与phytium开源内核Phytium-Linux-Kernel一致(即Linux-kernel 4.19 和 5.10 版本),请选择使用phytium开源内核进行调测。 +(1)通过gitee或是正式技术支持渠道获取内核源码,需要注意内核版本和目标机器环境运行的内核版本应保持一致,且当前phytium jailhouse支持的内核版本与phytium开源内核Phytium-Linux-Kernel一致(即Linux-kernel 4.19、5.10 以及 6.6 版本),请选择使用phytium开源内核进行调测。 内核源码获取命令: $ git clone https://gitee.com/phytium_embedded/phytium-linux-kernel.git -内核源码中D2000和FT-2000/4的设备树文件未开源,如有需要请联系飞腾嵌入式软件部获取。 +内核源码中D2000、FT-2000/4、D3000的设备树文件未开源,如有需要请咨询:linan1284@phytium.com.cn -(2)编译内核源码,例如在E2000上,在内核源码路径下执行make phytium_defconfig,然后执行make编译内核镜像。编译内核源码的具体步骤请参考Phytium-Linux-Kernel wiki部分,链接如下: +(2)编译内核源码,在内核源码路径下执行make phytium_defconfig,然后执行make编译内核镜像。编译内核源码的具体步骤请参考Phytium-Linux-Kernel wiki部分,链接如下: - https://gitee.com/phytium_embedded/phytium-linux-kernel/wikis/%E5%8D%95%E7%8B%AC%E7%BC%96%E8%AF%91Linux%20Kernel + https://gitee.com/phytium_embedded/phytium-linux-kernel/wikis/Home (3)如果是在x86环境下编译,需要额外配置好aarch64交叉编译环境,详情请参考Phytium-Linux-Kernel wiki部分。 @@ -39,7 +46,7 @@ Jailhouse编译完成后,生成文件分为三部分:第一部分,Jailhous # 3 安装与卸载 -在执行Jalhouse命令前,需要先加载jailhouse驱动模块。如果后续涉及到重新编译Jailhouse生成新的文件,则需要卸载后重新加载模块。 +在执行Jailhouse命令前,需要先加载Jailhouse驱动模块。如果后续涉及到重新编译Jailhouse生成新的文件,则需要卸载后重新加载模块。 (1)如果是在目标机上编译,那么可直接在phytium-jailhouse/src/jailhouse/下执行: @@ -62,15 +69,19 @@ Jailhouse编译完成后,生成文件分为三部分:第一部分,Jailhous # 4 运行 -目前在飞腾FT-2000/4、D2000和E2000上运行如下示例,本文档中测试所使用的内核版本为4.19。使用5.10内核时,需要在内核启动参数里添加内存限制:mem = 1G,否则Jailhouse将会报错。根文件系统为Ubuntu 20.04,如有需要,可联系飞腾嵌入式软件部获取。 +本节测试在没有特殊说明的情况下,所使用的内核版本为4.19。使用5.10和6.6内核时,需要在内核启动参数里添加内存限制:mem = 1G,否则Jailhouse将会报错。根文件系统为Ubuntu 20.04,关于如何制作根文件系统以及系统启动方法请参考phytium-linux-buildroot 中的README.md文档: + + https://gitee.com/phytium_embedded/phytium-linux-buildroot + +另外,D3000和S5000C上使用Jailhouse,宿主机Linux内核需要关闭VHE功能:5.10内核下通过内核配置CONFIG_ARM64_VHE关闭VHE,6.6内核下通过添加内核参数:kvm-arm.mode=nvhe关闭VHE。 -此章节的测试实例中加载jailhouse驱动模块命令已省略,模块的安装与卸载请参考第3章节,且为了节省篇幅,本章节中测试命令若涉及到文件(包括cell文件、bin文件等),应该在命令中加入文件完整绝对路径或相对路径,例如命令 +此章节的测试实例中加载jailhouse驱动模块命令已省略,模块的安装与卸载请参考第3章节,且为了节省篇幅,本章节中测试命令若涉及到文件(包括cell文件、bin文件等),应该在命令中加入文件完整绝对路径或相对路径,例如命令: # jailhouse enable d2000.cell; 实际上应该在命令中指定文件“d2000.cell”的路径,否则会报错找不到相关文件。 -另外,我们的配置文件均针对FT-2000/4、D2000/E2000飞腾demo测试板进行配置并测试,若测试单板不一样,那么对应的配置文件需跟当前测试的单板保持一致。 +另外,我们的配置文件均针对FT-2000/4、D2000、E2000以及D3000飞腾demo测试板进行配置并测试,若测试单板不一样,那么对应的配置文件需跟当前测试的单板保持一致。 ## 4.1 设备树保留内存节点 @@ -90,7 +101,7 @@ Jailhouse需要保留部分内存空间,在设备树中添加如下节点, ## 4.2 裸机程序 -裸跑测试适用的平台包括:E2000Q、D2000、以及FT-2000/4,下面在FT-2000/4和D2000上进行演示。 +裸跑测试适用的平台包括:E2000Q、D2000、FT-2000/4、D3000以及S5000C,下面在FT-2000/4、D2000以及E2000Q上进行演示。 ### 4.2.1 FT-2000/4测试 @@ -130,6 +141,8 @@ D2000和FT-2000/4板卡命令序列一致,首先加载jailhouse驱动模块, ### 4.2.3 E2000Q测试 #### 4.2.3.1 IVSHMEM测试 +注意:本小节测试中root cell需要的Linux内核版本为5.10或6.6内核。 + 首先在root cell 配置文件e2000q.c中定义CONFIG_IVSHMEM_TEST宏,打开ivshmem测试相关的配置,然后重新编译jailhouse: ![输入图片说明](pic/E2000Q_IVSHMEM_1.png) @@ -156,6 +169,8 @@ D2000和FT-2000/4板卡命令序列一致,首先加载jailhouse驱动模块, ## 4.3 RTOS +RTOS测试适用的平台包括:E2000Q、D2000、以及FT-2000/4。关于如何编译Jailhouse non root cell 所使用的RTOS镜像,请阅读《Jailhouse使用手册》相关的章节。 + ### 4.3.1 FT-2000/4测试 RTOS的运行需要根据系统特性来适配,目前已经可以运行FreeRTOS和VxWorks,运行32位和64位的系统需要使用不同的inmate文件,32位VxWorks运行序列和效果如下图所示: @@ -242,7 +257,11 @@ D2000支持FreeRTOS和VxWorks, FreeRTOS支持64位,VxWorks支持32位和64位 ## 4.4 Linux -与之前的测试不一样,运行non-root Linux除了加载Jailhouse驱动和root cell外,还需要提供内核镜像,设备树和根文件系统(目前为Ramdisk),还需要设定合适的启动参数,其中用于non-root Linux的设备树和cell配置需要保持一致。 +与之前的测试不一样,运行non-root Linux除了加载Jailhouse驱动和root cell外,还需要提供内核镜像,设备树和根文件系统(目前为initramfs),还需要设定合适的启动参数,其中用于non-root Linux的设备树和cell配置需要保持一致。 + +关于如何准备Linux镜像以及initramfs,请阅读《Jailhouse使用手册》相关的章节。 + +Linux测试适用的平台包括:E2000Q、D2000、FT-2000/4、D3000以及S5000C,下面以FT-2000/4、E2000Q、D2000为例进行演示。 ### 4.4.1 FT-2000/4测试 @@ -563,11 +582,10 @@ KVM实时内核测试结果: 根据上面的测试结果可知:相比KVM虚拟化,Jailhouse虚拟化的实时性更好。 - # 6 其他 -如有需要,可联系飞腾嵌入式软件部,联系邮箱: +如有需要,可联系飞腾嵌入式软件部,联系邮箱: + wenhuaizhi2026@phytium.com.cn huyuming1672@phytium.com.cn yangshaojun@phytium.com.cn - wenhuaizhi2026@phytium.com.cn \ No newline at end of file -- Gitee