Re: ioremap(), bus_to_virt() and PCI devices on different Linux archi

Peter Desnoyers (pjd@fred001.dynip.com)
Thu, 28 Oct 1999 21:26:03 -0400


Pete Zaitcev wrote:
>
> > I don't know the correct and universal way on all linux architecture to map
> > PCI memory. Some drivers
> > in the kernel use ioremap, other use bus_to_virt() ...
>
> I smell a poor wording or understanding here.
> Typically "PCI memory" means a memory located in a PCI board.
> Memory located on the other side of a north bridge is a
> "normal" or "CPU" memory.
>

I've got a related question - how do you portably mmap() PCI memory space?
I know that some people will argue this is a contradiction in terms, but with
the right limitations (e.g. only 32-bit access) and a conforming PCI
implementation (non of this non-cache-coherent nonsense) it should be
doable.

As an example, here's my 2.2 x86 code:

...
pci_read_config_dword(dev->pci_dev, PCI_BASE_ADDRESS_2,
&dev->bus_addrs[2]);
...

my_mmap(struct file *filp, struct vm_area_struct *vma) {
...
addr = (unsigned long)(dev->bus_addrs[2] + x);
// make sure the page is non cacheable
mod_pgprot.pgprot = (vma->vm_page_prot.pgprot | _PAGE_PCD);
if (remap_page_range(vma->vm_start, addr, DOORBELL_SIZE, mod_pgprot))
return -EAGAIN;

My belief is that remap_page_range always takes a host physical address, and
so this works because PCI addresses are mapped directly into CPU physical
addresses on x86. However, this would suggest that you could fix this code
on alpha by adding 'addr = virt_to_phys(bus_to_virt(addr))', but you can't.

I currently have a really gross hack someone gave me for alpha:

#define BASE2PHYS(a) __pa(dense_mem(a)+((a)&0xffffffffUL))
addr = BASE2PHYS(dev->bus_addrs[2] + x);

(actually, as I type this I'm wondering if the problem is that I'm using
pci_read_config_dword instead of pci_dev->base_address[2]...)

-- 
............................................................................
 Peter Desnoyers 
 162 Pleasant St.         (617) 661-1979          pjd@fred.cambridge.ma.us
 Cambridge, Mass. 02139   (978) 461-0402 (work)   pjd@giga-net.com 

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/