2

I want to do I/O on my PCIe device.I am running Ubuntu 16.0.4 LTS with linux kernel 4.4.0

The output of lspci -v command is:

06:00.0 Unclassified device [00ff]: Device 1aa1:2000 (rev 01)
    Subsystem: Device 1aa1:2000
    Physical Slot: 1-4
    Flags: bus master, fast devsel, latency 0, IRQ 16
    Memory at f1008000 (32-bit, non-prefetchable) [size=8K]
    Memory at ee000000 (32-bit, non-prefetchable) [size=32M]
    Memory at f100a000 (32-bit, non-prefetchable) [size=4K]
    Memory at f0000000 (32-bit, non-prefetchable) [size=16M]
    Memory at f1000000 (32-bit, non-prefetchable) [size=32K]
    Capabilities: <access denied>
    Kernel driver in use: my_pci
    Kernel modules: my_pci

Clearly, PCI addresses are 32-bit.

I want to know how to use ioread32/iowrite32 functions to read/write into the BAR addresses. unsigned char __iomem *mem types on my machine would be 64-bit and if I use the following say :

ioread32(mem + some_offset);

The expression mem + some_offset would be 64-bit and result into crash.

How would I do the I/O ?

Monku
  • 2,440
  • 4
  • 33
  • 57
  • 2
    Bars can'y be just written into, they need to be mapped to virtual memory. the driver normally does it just after initialization. you need to write to that address + the offset. – stdcall Aug 03 '16 at 07:41
  • @stdcall I know and that's how the things are implemented in source code. But my question is slightly different- My host machine is running 64-bit Ubuntu with kernel 4.4.0. Looking at my `lspci -v` output, we can see that the PCI bar addresses are 32-bit. So I was wondering/doubtful that the argument to `ioread32` being 64-bit address would result in undefined behaviour. – Monku Aug 03 '16 at 17:01
  • Ah. Got it. Got an answer for you. – stdcall Aug 03 '16 at 18:01
  • Is there a kernel command to enable 64 bit BAR? – David Jonsson Jul 18 '22 at 12:41

1 Answers1

1

The PCI devices you're working with works using 32bit addressing mode. when your PC enumerates the BARs and writes the physical address onto the BAR. it writes a masked values, only the lower 32 bit of the 64 bit (in host address space) Print the physical address the OS/BIOS has assigned to this BAR on the driver and compare it.

besides, this is a physical address, so you can't iowrite to it anyway.

So I don't really understand your goal.

stdcall
  • 27,613
  • 18
  • 81
  • 125