|
From: | Shaked Matzner |
Subject: | simple example of pci driver with dma |
Date: | Thu, 29 Oct 2020 09:18:25 +0000 |
Hey All, So I'm trying to learn how pci devices and drivers work using the edu device and an educational driver, and It seems
like the pci_dma_write function fails to actually write the information from the the dma buffer into the allocated address in the ram. Here is How I testsed it: 1.I've initialized the first byte of the dma buff to be 0x12 in the realize function of the edu:
In the driver I've defined a struct save both the major and the destination address allocated through the dma cohherent:
allocated it on the probe function and commanded the device to read 4 bytes:
iowrite32(DMA_BASE, mmio + IO_DMA_SRC);
iowrite32((u32)dma_handle_to, mmio + IO_DMA_DST);
iowrite32(SIZE, mmio + IO_DMA_CNT);
iowrite32(DMA_CMD | DMA_FROM_DEV | DMA_IRQ, mmio + IO_DMA_CMD);
I've changed a little bit the interrtupt and added a print to check the value I just read: static irqreturn_t irq_handler(int irq, void *dev)
however the value I get is still 255(0xff) and not 18(0x12) probably I've missed something but when the interrupt is called the transfer to the RAM address should be completed, however
it seems like the dma_write_buffer function from the device does not perform any transfer. What Am I missing? when I debugged the dma_coherent_alloc I saw it uses direct acccess(without iommu), however when the dma_pci_write
is called it tries to access the memory via iommu and get's an error code(MEMTX_DECODE_ERROR) from memory.c 's memory_region_dispatch_write. Since memory_region_access_valid returns false on it's first condition(also under memory.c I am now in a deadlock, since even this simple example doesn’t seem to work, any idea what happens, or any suggestions
for an alternative simple device with a simple driver which I can learn from will be great.
Technical details: edu_device: https://github.com/qemu/qemu/blob/master/hw/misc/edu.c original
edu_driver: https://github.com/cirosantilli/linux-kernel-module-cheat/blob/master/kernel_modules/qemu_edu.c I
run this on an x86-64 qemu machine with the following configuration:
(where $repo_location is the path to my build dir)
Thanks, Shaked Matzner The contents of this email message and any attachments are intended solely for the addressee(s) and may contain confidential and/or privileged information and may be legally protected from disclosure. If you are not the intended recipient of this message or their agent, or if this message has been addressed to you in error, please immediately alert the sender by reply email and then delete this message and any attachments. If you are not the intended recipient, you are hereby notified that any use, dissemination, copying, or storage of this message or its attachments is strictly prohibited. |
[Prev in Thread] | Current Thread | [Next in Thread] |