Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need help translating kvm/vbox/qemu/ect PCI registration to RVVM #157

Closed
ZLangJIT opened this issue Oct 20, 2024 · 8 comments
Closed

need help translating kvm/vbox/qemu/ect PCI registration to RVVM #157

ZLangJIT opened this issue Oct 20, 2024 · 8 comments

Comments

@ZLangJIT
Copy link

im struggling to figure out how i might implement a very basic virtio-pci device in rvvm for virtio-over-pci transport based kernel drivers

the virtio spec does not appear to specify exactly how to do such, and qemu appears to use a pci virtio-pci device which manages sub virtio devices (all virtio devices plug into virtio-pci itself which virtio-pci itself plugs into pci) however the spec also does not clarify such as it appears to only talk about virtio-pci devices such as the ones that plug into qemu's virtio-pci

and i am not sure how to begin porting the qemu's virtio-pci over to rvvm as both use quite a different pci interface

@ZLangJIT ZLangJIT changed the title virtio-pci device minimal virtio-over-pci device implementation Oct 20, 2024
@ZLangJIT
Copy link
Author

ZLangJIT commented Oct 20, 2024

hmm i think i may have found one that more closely resembles rvvm in comparison to qemu

unfortunately github complains the repository has not yet been indexed (so we cannot search globally for symbols)

https://github.com/matthias-prangl/VirtualBox6/blob/2db58873a4141dd42b3f7d34dbd713dca2fa1984/src/VBox/Devices/VirtIO/Virtio.cpp#L832-#L905

however we do have an indexable mirror

https://github.com/mirror/vbox/blob/master/src/VBox/Devices/VirtIO/VirtioCore.h

along with a gpu device https://github.com/mirror/vbox/blob/master/src/VBox/Devices/EFI/Firmware/OvmfPkg/VirtioGpuDxe/Commands.c

@ZLangJIT
Copy link
Author

ZLangJIT commented Oct 20, 2024

unfortunately it seems almost every "virtio-pci" device uses a different interface for registering with the PCI itself

https://github.com/isclouder/microv/blob/2992853ddc8cc1328ec2dca8f621ef8c09560807/virtio-pci.c#L253

https://github.com/sysprog21/riscv-emu/blob/7cc6525934fc8983c67b81868c78610f3ad3797b/virtio.c#L220

https://github.com/mhhf/jslinux-truebit/blob/fbd09ab2a7f3a59a010f1ad44b22434ca6d8e88f/src/virtio.c#L220

https://github.com/mirror/vbox/blob/master/src/VBox/Devices/VirtIO/VirtioCore.cpp#L2822

meanwhile RVVM's pci interface is almost entirely different

typedef struct {
    uint16_t vendor_id;
    uint16_t device_id;
    uint16_t class_code;
    uint8_t  prog_if;
    uint8_t  rev;
    uint8_t  irq_pin;
    rvvm_mmio_dev_t bar[PCI_FUNC_BARS];
} pci_func_desc_t;

@ZLangJIT ZLangJIT changed the title minimal virtio-over-pci device implementation need help translating kvm/vbox/qemu/ect PCI registration to RVVM Oct 20, 2024
@ZLangJIT
Copy link
Author

@ZLangJIT
Copy link
Author

ZLangJIT commented Oct 21, 2024

OK i found one

RVVM contains a Realtek NIC network card that attaches VIA PCI https://github.com/LekKit/RVVM/blob/staging/src/devices/rtl8169.c#L481

and likewise qemu also contains a Realtek NIC network card that attaches VIA PCI https://github.com/qemu/qemu/blob/master/hw/net/rtl8139.c#L3359

all other devices which are in both RVVM and QEMU either connect via the PCI in qemu but the MMIO in RVVM or vice versa or are passthrough in QEMU

so the Realtek network card is the ONLY device in which BOTH RVVM and QEMU connect via PCI

@LekKit
Copy link
Owner

LekKit commented Oct 21, 2024

Please have a look at NVMe device example:

pci_dev_desc_t nvme_desc = {

It should be fairly straightforward to use, PCI only defines a device identification mechanism (Device/Vendor IDs, device class). The actual device BARs are simply MMIO regions, so all the usual RVVM API conventions apply in the same way (MMIO read/write callbacks, mappings, alignment, etc from the doc)

@LekKit
Copy link
Owner

LekKit commented Oct 21, 2024

I also want to ask you to stop opening more issues because it is very confusing to navigate them, and some questions you asked lately are not easily understandable.

@LekKit
Copy link
Owner

LekKit commented Oct 23, 2024

PCI Device class codes explanation: https://admin.pci-ids.ucw.cz/read/PD/
PCI Vendor/Device ID listing: https://admin.pci-ids.ucw.cz/read/PC/

Dump PCI device address / class code / vendor & device ID / revision:

lspci -n

image

Remove -n argument to see decoded device model names (From the PCI ID repository mentioned above)

@ZLangJIT
Copy link
Author

ZLangJIT commented Oct 28, 2024

I also want to ask you to stop opening more issues because it is very confusing to navigate them, and some questions you asked lately are not easily understandable.

sorry, ill keep to #149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants