Skip to contentSkip to conversation

Failed to access the BAR MMIO space of PCI device

Question zhengfei 2 participants 5 messages Apr 7, 2013 – Apr 12, 2013 PCI

lore
Share & tools
lore

zhengfei

author
#0 lore raw

Hi,

I'm writing a driver for a SR-IOV device on the PCI bus. My architecture is a 64-bit X86 of intel Sandy bridge.

In my device driver, I want to configure the device to transfer data to/from X86.I get the the device BAR MMIO base address with the command "lspci -s 04:00.03 -xxx" in the guest os(kvm).
But after I ioremap() that MMIO base address,I failed to access the BAR MMIO space in the guest os(kvm).

Is there a function which show mapping between the real PCI address stored in the BAR and the emulated address stored in the BAR?

Thanks.

zhengfei

#1 lore raw
Quoted 5 lines · zhengfei

Hi,

I'm writing a driver for a SR-IOV device on the PCI bus. My architecture is a 64-bit X86 of intel Sandy bridge.

Quoted 8 lines

In my device driver, I want to configure the device to transfer data to/from X86.I get the the device BAR MMIO base address with the command "lspci -s 04:00.03 -xxx" in the guest os(kvm).
But after I ioremap() that MMIO base address,I failed to access the BAR MMIO space in the guest os(kvm).

Is there a function which show mapping between the real PCI address stored in the BAR and the emulated address stored in the BAR?

Is this a userspace driver or a kernel driver? I can't figure out why you would use lspci to get a static BAR address, then use ioremap() to map it. If it's a kernel driver, the sequence you want is something like:

pci_enable_device
pci_request_selected_regions
pci_iomap

Thanks,
Alex

author
#2 lore raw
Quoted 5 lines · Alex Williamson <alex.williamson <at> redhat.com> writes:
Quoted 3 lines · zhengfei

Hi,

I'm writing a driver for a SR-IOV device on the PCI bus. My architecture

is

Quoted 3 lines
Quoted 3 lines

a 64-bit X86 of intel Sandy bridge.

In my device driver, I want to configure the device to transfer data

to/from

Quoted 1 line
Quoted 1 line

X86.I get the the device BAR MMIO base address with the command "lspci -

s

Quoted 2 lines
Quoted 2 lines

04:00.03 -xxx" in the guest os(kvm).
But after I ioremap() that MMIO base address,I failed to access the BAR

MMIO

Quoted 3 lines
Quoted 3 lines

space in the guest os(kvm).

Is there a function which show mapping between the real PCI address

stored in

Quoted 7 lines
Quoted 1 line

the BAR and the emulated address stored in the BAR?

Is this a userspace driver or a kernel driver? I can't figure out why you would use lspci to get a static BAR address, then use ioremap() to map it. If it's a kernel driver, the sequence you want is something like:

Quoted 8 lines

pci_enable_device
pci_request_selected_regions
pci_iomap

Thanks,
Alex

It is a userspace driver on guest os.To be simply,I got the BAR0 address(gpa) on guest os,but I failed to access real BAR0 MMIO address space of the device with the gpa.So what can I do next? and in which source code file,could I find the procedure of mapping the real BAR address space(hpa) to gpa?

Thanks

#3 lore raw
Quoted 37 lines · zhengfei
Quoted 5 lines · Alex Williamson <alex.williamson <at> redhat.com> writes:
Quoted 3 lines · zhengfei

Hi,

I'm writing a driver for a SR-IOV device on the PCI bus. My architecture

is

Quoted 3 lines
Quoted 3 lines

a 64-bit X86 of intel Sandy bridge.

In my device driver, I want to configure the device to transfer data

to/from

Quoted 1 line
Quoted 1 line

X86.I get the the device BAR MMIO base address with the command "lspci -

s

Quoted 2 lines
Quoted 2 lines

04:00.03 -xxx" in the guest os(kvm).
But after I ioremap() that MMIO base address,I failed to access the BAR

MMIO

Quoted 3 lines
Quoted 3 lines

space in the guest os(kvm).

Is there a function which show mapping between the real PCI address

stored in

Quoted 7 lines
Quoted 1 line

the BAR and the emulated address stored in the BAR?

Is this a userspace driver or a kernel driver? I can't figure out why you would use lspci to get a static BAR address, then use ioremap() to map it. If it's a kernel driver, the sequence you want is something like:

Quoted 8 lines

pci_enable_device
pci_request_selected_regions
pci_iomap

Thanks,
Alex

Quoted 5 lines

It is a userspace driver on guest os.To be simply,I got the BAR0 address(gpa) on guest os,but I failed to access real BAR0 MMIO address space of the device with the gpa.So what can I do next? and in which source code file,could I find the procedure of mapping the real BAR address space(hpa) to gpa?

The guest doesn't have access to the hpa, nor should it need it. To map BAR0 from guest userspace
mmap /sys/bus/pci/devices/xxxx:xx:xx.x/resource0. Thanks,

Alex

author
#4 lore raw
Quoted 9 lines · Alex Williamson <alex.williamson <at> redhat.com> writes:
Quoted 7 lines · zhengfei
Quoted 5 lines · Alex Williamson <alex.williamson <at> redhat.com> writes:
Quoted 3 lines · zhengfei

Hi,

I'm writing a driver for a SR-IOV device on the PCI bus. My

architecture

Quoted 6 lines
Quoted 6 lines

is

Quoted 3 lines
Quoted 3 lines

a 64-bit X86 of intel Sandy bridge.

In my device driver, I want to configure the device to transfer data

to/from

Quoted 1 line
Quoted 1 line

X86.I get the the device BAR MMIO base address with the command

"lspci -

Quoted 3 lines
Quoted 3 lines

s

Quoted 2 lines
Quoted 2 lines

04:00.03 -xxx" in the guest os(kvm).
But after I ioremap() that MMIO base address,I failed to access the

BAR

Quoted 10 lines
Quoted 10 lines

MMIO

Quoted 3 lines
Quoted 3 lines

space in the guest os(kvm).

Is there a function which show mapping between the real PCI address

stored in

Quoted 2 lines
Quoted 1 line

the BAR and the emulated address stored in the BAR?

It is a userspace driver on guest os.To be simply,I got the BAR0 address(gpa) on guest os,but I failed to access real BAR0 MMIO address

space

Quoted 1 line
Quoted 1 line

of the device with the gpa.So what can I do next? and in which source

code

Quoted 1 line
Quoted 1 line

file,could I find the procedure of mapping the real BAR address

space(hpa)

Quoted 9 lines
Quoted 1 line

to gpa?

The guest doesn't have access to the hpa, nor should it need it. To map BAR0 from guest userspace
mmap /sys/bus/pci/devices/xxxx:xx:xx.x/resource0. Thanks,

Alex

Yes,I have followed your advice above,but the problem still exists.I doubt the address may not be correct gotten by "mmap /sys/bus/pci/devices/xxxx:xx:xx.x/resource0",what can I do next to debug? so I want to learn ,how do the guest userspace mapping to host BAR0 address space.

zhengfei,
Thanks