On Fri, Oct 01, 2021 at 08:21:06PM +0530, Ajay Garg wrote: > Hi All. > > I have a SD/MMC reader over PCI, which displays the following (amongst > others) when we do "lspci -vv" : > > ######################################################### > Region 0: Memory at e2c20000 (32-bit, non-prefetchable) [size=512] > ######################################################### > > Above shows that e2c20000 is the physical (base-)address of BAR0. > > Now, in the device driver, I do the following : > > ######################################################## > ..... > struct pci_dev *ptr; > void __iomem *bar0_ptr; > ...... > > ...... > pci_request_region(ptr, 0, "ajay_sd_mmc_BAR0_region"); > bar0_ptr = pci_iomap(ptr, 0, pci_resource_len(ptr, 0)); > > printk("Base virtual-address = [%p]\n", bar0_ptr); > printk("Base physical-address = [%p]\n", virt_to_phys(bar0_ptr)); > printk("Base bus-address = [%p]\n", virt_to_bus(bar0_ptr)); > > I have removed error-checking, but I confirm that pci_request_region() > and pci_iomap calls are successful. > > Now, in the 3 printk's, none of the value is printed as e2c20000. > I was expecting that the 2nd result, of virt_to_phys() translation, > would be equal to the base-address of BAR0 register, as reported by > lspci. > > > What am I missing? > Will be grateful for pointers. The CPU address isn't always the same as the PCI address. For example, some memory resources are added via pci_add_resource_offset(), so the windows the host sees will be different than the ones the devices use.