How to access pci device from another device

453 views Asked by At

I'm creating new PCI device in qemu that is part DMA and part NVMe controller.

And I need to get the physical address of the NVMe device, from within my new device to use dma_memory_read(...)

Is there a function to get new device address?

Is there other function that I can use without physical address?

Is there another way to do it, through pointers?

1

There are 1 answers

0
Peter Maydell On

Generally the best question to ask when trying to figure out how to model devices in QEMU is "what does the real hardware do?".

For real PCI devices, the only way they can access other devices elsewhere in the system is if they do DMA accesses, which they do using PCI addresses (which are usually about the same thing as physical addresses on x86, but not necessarily so on other architectures). In QEMU we model this by having APIs for PCI devices to do DMA accesses (pci_dma_*()).

On the other hand, if you have a PCI card that is itself implementing an NVMe controller (or another kind of controller, like a SCSI disk controller), the answer is that the disks are plugged directly into the controller, which then can talk to them with no physical addresses involved at all. In QEMU we model this by having a concept of controller devices possibly having a "bus" which the disks are plugged into.

How does the real hardware talk between the PCI device and the NVMe ? Generally the answer is not "weird backdoor mechanism" and so you shouldn't be looking for an API in QEMU that corresponds to "weird backdoor mechanism".