From 1bfc2be0ce96f05536764d6ac230d596aefd8dfa Mon Sep 17 00:00:00 2001 From: Changyuan Lyu Date: Fri, 29 Dec 2023 17:37:28 -0800 Subject: [PATCH] lspci: add VirtIO SharedMemory capability support This patch adds the support for VirtIO share memory capability [1]. A shared memory region is defined in a `struct virtio_pci_cap64` where the highest 32 bits of `offset` and `size` are appened to the original `struct virtio_pci_cap`. With this patch, a VirtIO PMEM device (ID 27) shows like the following: ``` 00:02.0 Class ffff: Device 1af4:105b (rev 01) Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+ Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- SERR- --- ls-caps-vendor.c | 25 +++++++++++++++++++++---- tests/cap-vendor-virtio | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/ls-caps-vendor.c b/ls-caps-vendor.c index 83ff761..a69ddd6 100644 --- a/ls-caps-vendor.c +++ b/ls-caps-vendor.c @@ -19,6 +19,10 @@ show_vendor_caps_virtio(struct device *d, int where, int cap) int length = BITS(cap, 0, 8); int type = BITS(cap, 8, 8); char *tname; + u32 offset; + u32 size; + u32 offset_hi; + u32 size_hi; if (length < 16) return 0; @@ -39,6 +43,9 @@ show_vendor_caps_virtio(struct device *d, int where, int cap) case 4: tname = "DeviceCfg"; break; + case 8: + tname = "SharedMemory"; + break; default: tname = ""; break; @@ -49,10 +56,20 @@ show_vendor_caps_virtio(struct device *d, int where, int cap) if (verbose < 2) return 1; - printf("\t\tBAR=%d offset=%08x size=%08x", - get_conf_byte(d, where + 4), - get_conf_long(d, where + 8), - get_conf_long(d, where + 12)); + offset = get_conf_long(d, where + 8); + size = get_conf_long(d, where + 12); + if (type != 8) + printf("\t\tBAR=%d offset=%08x size=%08x", + get_conf_byte(d, where + 4), offset, size); + else { + offset_hi = get_conf_long(d, where + 16); + size_hi = get_conf_long(d, where + 20); + printf("\t\tBAR=%d offset=%016lx size=%016lx id=%d", + get_conf_byte(d, where + 4), + (u64) offset | (u64) offset_hi << 32, + (u64) size | (u64) size_hi << 32, + get_conf_byte(d, where + 5)); + } if (type == 2 && length >= 20) printf(" multiplier=%08x", get_conf_long(d, where+16)); diff --git a/tests/cap-vendor-virtio b/tests/cap-vendor-virtio index 2d04831..adaebf8 100644 --- a/tests/cap-vendor-virtio +++ b/tests/cap-vendor-virtio @@ -39,3 +39,39 @@ d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 +00:04.0 Mass storage controller: Red Hat, Inc. Virtio file system (rev 01) + Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+ + Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- SERR-