Skip to content

Commit 2a09d5e

Browse files
michael1schmidtcfriedt
authored andcommitted
drivers: virt_ivshmem: Allow multiple instances of ivShMem devices.
- Supporting multiple instances of ivShMem virtual devices. - Introduces DT based configuration for ivShMem devices. - Add DTS overlay file to test new multiple ivshmem instance capability. - Enable BDF unspecified device initialization. (limited to one instance. An improved version of pcie_bdf_lookup() will come soon that fixes this limitation) - Make PCIE DTS file macros available for a proper ivshmem device properties parsing. Sample for dts file: pcie0 { label = "PCIE_0"; #address-cells = <1>; #size-cells = <1>; compatible = "intel,pcie"; ranges; ivshmem0: ivshmem@800 { compatible = "qemu,ivshmem"; reg = <PCIE_BDF_NONE PCIE_ID(0x1af4,0x1110)>; label = "IVSHMEM"; status = "okay"; }; }; Signed-off-by: Michael Schmidt <[email protected]>
1 parent ad4e993 commit 2a09d5e

File tree

4 files changed

+63
-11
lines changed

4 files changed

+63
-11
lines changed

drivers/virtualization/virt_ivshmem.c

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#define DT_DRV_COMPAT qemu_ivshmem
8+
79
#define LOG_LEVEL CONFIG_IVSHMEM_LOG_LEVEL
810
#include <logging/log.h>
911
LOG_MODULE_REGISTER(ivshmem);
@@ -223,25 +225,42 @@ static const struct ivshmem_driver_api ivshmem_api = {
223225
static int ivshmem_init(const struct device *dev)
224226
{
225227
struct ivshmem *data = dev->data;
228+
static bool bdf_lookup_done;
226229

227-
data->bdf = pcie_bdf_lookup(PCIE_ID(IVSHMEM_VENDOR_ID,
228-
IVSHMEM_DEVICE_ID));
229-
if (data->bdf == PCIE_BDF_NONE) {
230-
LOG_WRN("ivshmem device not found");
230+
if ((data->bdf == PCIE_BDF_NONE) && bdf_lookup_done) {
231+
LOG_ERR("One instance of ivshmem with pcie_bdf_lookup() already initialized.\n"
232+
"Using more than one with PCIE_BDF_NONE parameter might conflict\n"
233+
"with already initialized instances.");
231234
return -ENOTSUP;
232235
}
233-
236+
if ((data->bdf == PCIE_BDF_NONE) && !bdf_lookup_done) {
237+
if (data->dev_ven_id) {
238+
data->bdf = pcie_bdf_lookup(data->dev_ven_id);
239+
} else {
240+
data->bdf = pcie_bdf_lookup(PCIE_ID(IVSHMEM_VENDOR_ID, IVSHMEM_DEVICE_ID));
241+
}
242+
if (data->bdf == PCIE_BDF_NONE) {
243+
LOG_WRN("ivshmem device not found");
244+
return -ENOTSUP;
245+
}
246+
}
234247
LOG_DBG("ivshmem found at bdf 0x%x", data->bdf);
248+
bdf_lookup_done = true;
235249

236250
if (!ivshmem_configure(dev)) {
237251
return -EIO;
238252
}
239-
240253
return 0;
241254
}
242255

243-
static struct ivshmem ivshmem_data;
244-
245-
DEVICE_DEFINE(ivshmem, CONFIG_IVSHMEM_DEV_NAME,
246-
ivshmem_init, NULL, &ivshmem_data, NULL,
247-
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &ivshmem_api);
256+
#define IVSHMEM_DEVICE_INIT(n) \
257+
static struct ivshmem ivshmem_data_##n = { \
258+
.bdf = DT_INST_REG_ADDR_BY_IDX(n, 0), \
259+
.dev_ven_id = DT_INST_REG_SIZE_BY_IDX(n, 0) \
260+
}; \
261+
DEVICE_DT_INST_DEFINE(n, &ivshmem_init, NULL, \
262+
&ivshmem_data_##n, NULL, \
263+
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
264+
&ivshmem_api);
265+
266+
DT_INST_FOREACH_STATUS_OKAY(IVSHMEM_DEVICE_INIT)

drivers/virtualization/virt_ivshmem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct ivshmem_param {
2525
struct ivshmem {
2626
DEVICE_MMIO_RAM;
2727
pcie_bdf_t bdf;
28+
uint32_t dev_ven_id;
2829
uintptr_t shmem;
2930
size_t size;
3031
#ifdef CONFIG_IVSHMEM_DOORBELL
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2021 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: ivShMem device properties
5+
6+
compatible: "qemu,ivshmem"
7+
8+
include: base.yaml
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <dt-bindings/pcie/pcie.h>
7+
8+
/ {
9+
pcie0 {
10+
label = "PCIE_0";
11+
#address-cells = <1>;
12+
#size-cells = <1>;
13+
compatible = "intel,pcie";
14+
ranges;
15+
16+
ivshmem0: ivshmem@800 {
17+
compatible = "qemu,ivshmem";
18+
19+
reg = <PCIE_BDF_NONE PCIE_ID(0x1af4,0x1110)>;
20+
label = "IVSHMEM";
21+
status = "okay";
22+
};
23+
};
24+
};

0 commit comments

Comments
 (0)