I am new to the GPU OS kernelspace world.
I would like to access GPU memory as a PCI device through its memory exposed on the BAR using for exmaple dev_alloc () which is allocating memory and returns an address to this address.
void *addr;
addr = dev_alloc ()
//check that the allocated address is in the device bar range
if(In_bar_range(virt_to_phy(addr))) {
WRITE_ONCE(addr[0], 0);
READ_ONCE(addr[0]);
}
I also tried mapping using pci_iomap as follows
void* __iomap map;
u32 val;
map=pci_iomap(pci_dev,0,8);
iowrite8(0, map);
val=ioread8(map);
dev_info(&dev " value = %ud ", val);
Trying to read from the values fails. It does not return 0. It returns a garbage value. I do not know whether there is a problem in addressing translation (IO_MMU) or if I am missing some kind of synchronization between the CPU and the GPU or if it is another problem?