From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <40f29a795f59d3646fed7e4a44be8b30.axp-list@archive.invalid> X-Archive-Original-Message-ID: <199705020016.UAA00790@alpha0.estabrook.org> Date: Thu, 01 May 1997 20:16:52 +0500 From: jestabro@amt.tay1.dec.com Subject: Re: PCI mapping question In-Reply-To: <199705012208.AAA01982@batman.ag1.mpi-sb.mpg.de> >>> Hein Roehrig said: > > I got rather confused trying to understand how I access PCI memory > from kernel resp. user mode. > > Say, I have a 32-bit PCI address. How do I get the corresponding > physical address that I can use for ioremap resp. mmap on /dev/mem ? For user space access to PCI bus memory via "mmap", you need to use the LIBC routine "unsigned long _bus_base(void)"; add the PCI bus address to the value returned by that (unsigned long!!!), and pass that along to "mmap" as the physical address. The Alphas have (a minimum of) 34 bits of physical address space; part of that (called DENSE memory space) maps to PCI bus memory. User memory mapped to PCI bus DENSE space *MUST* be accessed on natural boundaries of 4 (int) and 8 (long) bytes *ONLY*, otherwise you get unaligned access traps (harmless except to performance) at least, bus hangs at worst. If you want to access in smaller chunks (byte and short), refer to the Alpha Architecture manual (available as PS or PDF on the Digital Semiconductor website) about SPARSE memory space. There's another LIBC routine, "unsigned long _bus_base_sparse(void)" that helps the user to "mmap" such as well. For examples of both usages, refer to XFree86 3.2 sources in the "os-support/linux/" and "common_hw/" areas under programs/Xserver/hw/xfree86/. > For the LCA, bus_to_virt substracts 1G from the bus address -- thats > weird, if it is meant to translate PCI addresses to virtual addresses, > esp. since bios32.c layouts the PCI bus to start at 16M... Obviously, > I must be missing something!? Not quite... "virt_to_bus()" converts a kernel virtual address into an address a DMA-capable device can use to access host memory from off the PCI/ISA bus. For example, a SCSI driver would use "virt_to_bus()" to get an address that the controller could use at which to put a block off disk into memory. "bus_to_virt()" is usually used only by drivers whose controllers pass back an address they (the controller) used to put something into host memory, and now the driver needs to get at that data directly. The Alpha hardware (typically) has "DMA windows" on the PCI bus; these are (1 or more) ranges of PCI addresses which allow direct access off the bus into host memory. Usually, the range of PCI addresses from 1Gb to 2Gb-1 is setup to correspond to host memory addresses 0 to 1Gb-1. Thus, "virt_to_bus()" takes a kernel virtual host memory address (usually :-), and converts it to physical, then adds the DMA window "base". The final address, when presented by a peripheral controller (like SCSI or Ethernet) onto the PCI bus, will trigger access to the desired host memory. Note that the final address is *not* directly usable by the kernel. Enough? :-) --Jay++ ------------------------------------------------------------------------------- American Non Sequitur Society: we don't make sense, but we do like pizza... Jay A Estabrook Alpha Migration Tools - LINUX Project Digital Equipment Corp. (508) 952-4202 or (DTN) 227-4202 151 Taylor Street - TAY1-2 enet: jestabro@amt.tay1.dec.com Littleton, MA 01460-1407 decnet: tallis::jestabro ------------------------------------------------------------------------------- -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com