Skip to content

Commit 0ea788b

Browse files
binbinwu1wenlingz
authored andcommitted
dm: passthru: remove the use of assert()
Remove the use of assert() in passthrough driver. Tracked-On: #3252 Signed-off-by: Binbin Wu <binbin.wu@intel.com> Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
1 parent efccdd2 commit 0ea788b

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

devicemodel/hw/pci/passthrough.c

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@
7171

7272
extern uint64_t audio_nhlt_len;
7373

74-
/* TODO: Add support for IO BAR of PTDev */
75-
static int iofd = -1;
76-
7774
/* reference count for libpciaccess init/deinit */
7875
static int pciaccess_ref_cnt;
7976
static pthread_mutex_t ref_cnt_mtx = PTHREAD_MUTEX_INITIALIZER;
@@ -404,8 +401,6 @@ init_msix_table(struct vmctx *ctx, struct passthru_dev *ptdev, uint64_t base)
404401
uint16_t virt_bdf = PCI_BDF(dev->bus, dev->slot, dev->func);
405402
struct ic_ptdev_irq ptirq;
406403

407-
assert(ptdev_msix_table_bar(ptdev) >= 0 && ptdev_msix_pba_bar(ptdev) >= 0);
408-
409404
b = ptdev->sel.bus;
410405
s = ptdev->sel.dev;
411406
f = ptdev->sel.func;
@@ -626,7 +621,11 @@ cfginitbar(struct vmctx *ctx, struct passthru_dev *ptdev)
626621
*/
627622
if (bartype == PCIBAR_MEM64) {
628623
i++;
629-
assert(i <= PCI_BARMAX);
624+
if (i > PCI_BARMAX) {
625+
warnx("BAR count out of range\n");
626+
return -1;
627+
}
628+
630629
ptdev->bar[i].type = PCIBAR_MEMHI64;
631630
}
632631
}
@@ -1073,21 +1072,14 @@ passthru_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, int baridx,
10731072
uint64_t offset, int size, uint64_t value)
10741073
{
10751074
struct passthru_dev *ptdev;
1076-
struct iodev_pio_req pio;
10771075

10781076
ptdev = dev->arg;
10791077

10801078
if (baridx == ptdev_msix_table_bar(ptdev)) {
10811079
msix_table_write(ptdev, offset, size, value);
10821080
} else {
1083-
assert(dev->bar[baridx].type == PCIBAR_IO);
1084-
bzero(&pio, sizeof(struct iodev_pio_req));
1085-
pio.access = IODEV_PIO_WRITE;
1086-
pio.port = ptdev->bar[baridx].addr + offset;
1087-
pio.width = size;
1088-
pio.val = value;
1089-
1090-
(void)ioctl(iofd, IODEV_PIO, &pio);
1081+
/* TODO: Add support for IO BAR of PTDev */
1082+
warnx("Passthru: PIO write not supported, ignored\n");
10911083
}
10921084
}
10931085

@@ -1096,24 +1088,16 @@ passthru_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, int baridx,
10961088
uint64_t offset, int size)
10971089
{
10981090
struct passthru_dev *ptdev;
1099-
struct iodev_pio_req pio;
11001091
uint64_t val;
11011092

11021093
ptdev = dev->arg;
11031094

11041095
if (baridx == ptdev_msix_table_bar(ptdev)) {
11051096
val = msix_table_read(ptdev, offset, size);
11061097
} else {
1107-
assert(dev->bar[baridx].type == PCIBAR_IO);
1108-
bzero(&pio, sizeof(struct iodev_pio_req));
1109-
pio.access = IODEV_PIO_READ;
1110-
pio.port = ptdev->bar[baridx].addr + offset;
1111-
pio.width = size;
1112-
pio.val = 0;
1113-
1114-
(void)ioctl(iofd, IODEV_PIO, &pio);
1115-
1116-
val = pio.val;
1098+
/* TODO: Add support for IO BAR of PTDev */
1099+
warnx("Passthru: PIO read not supported\n");
1100+
val = (uint64_t)(-1);
11171101
}
11181102

11191103
return val;

0 commit comments

Comments
 (0)