From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,3410b34506f92360 X-Google-Attributes: gid1164f8,public X-Google-Thread: fee84,3410b34506f92360 X-Google-Attributes: gidfee84,public From: Fred Kleinsorge Subject: Re: PCI Sparse Address Space Date: 1996/09/18 Message-ID: <323FBAD3.6254501@star.enet.dec.com> X-Deja-AN: 181365690 references: <51k83t$c70@mashie.cs.umd.edu> content-type: text/plain; charset=us-ascii organization: OpenVMS Engineering mime-version: 1.0 newsgroups: comp.unix.osf.osf1,comp.sys.dec x-mailer: Mozilla 2.02b1 (X11; I; DEC 3000 - M700 ) Jeff Hollingsworth wrote: > > Does anyone know how to generate "sparse space" addresses on a DEC Alpha? > > The situation is that I have a PCI board that I map into an application's > address space. The mapping seems to work fine, but the board is getting > mapped as a "sparse" address space. This seems to be a trick to let > the Alpha processors generate byte and word requests to hardware (rather than > the 64 bit requests the Alpha wants to generate). The problem I am having is > how do I generate the appropriate addresses to read word y at a location x > bytes from that start of the mapped area? If anyone knows how this works (or > better yet has macros to generate addresses), please send me mail. > Generally speaking, you don't want to do this. Your code will be both platform and chip specific. Operating system code, including device drivers, use O/S calls that are vectored for the correct semantics. The reason I say this is that partial word I/O is implemented in a number of ways on different platforms. The TurboChannel machines use a asymetric mechanism that allows byte writes, but not byte reads. The DEC2000 (aka Jensen, aka AXP150) uses a sparse space with a different address "swizzle" than the rest of the current generation of machines. And the next generation of machines will have a flat byte addressable I/O space (that is, no more dense/sparse). Having said that. If you are willing to deal with the fact that this code will have transportability issues... Here is the current sparse space on machines other than the AXP150 and Turbochannel systems. Sparse space is implemented by permuting the address to allow the offset into a doubleword, and the size of the access to be placed into the address bits. This is done by shifting the virtual address left 5 places. The length of the transfer is 0 = byte, 1 = short, 2 = tri-byte, and 3 = doubleword. This is shifted by 3 and or'ed into the address. This is the "swizzled" address. The low order of the address looks like: +-+-+-+-+-+-+-+-+ |x|B|B|L|L|0|0|0| +-+-+-+-+-+-+-+-+ with BB being the byte offset into the doubleword, and LL being the length of the I/O. Note that some combinations aren't legal or useful, like a tribyte I/O with a offset more than 1. Now. In addition, the data for the transfer needs to be swizzled, or "byte laned". This is simply taking the offset (the BB above) and using this to shift the data left by (BB * 8) bits. So, sparse space has a "stride" of 32 bytes of virtual address space between each physical byte of memory. In the end you wind up writing a couple macros: extern unsigned long CSR_ADDRESS; // This would get the mapped base address #define swizzleShift 5 #define ioLong (3 << 3) #define SWIZZLE_ADDRESS(a) (a << swizzleShift) #define SWIZZLE_DATA(d,a) (((int)(d)) << ((((unsigned long)(a)) & 3) * 8)) #define UNSWIZZLE_DATA(d,a) (((int)(d)) >> (((unsigned long)(a)) & 3) * 8)) #define ADDRESS_BYTE(a) (unsigned int *)((unsigned long) CSR_ADDRESS + \ (unsigned long) SWIZZLE_ADDRESS(a)) #define ADDRESS_DW(a) (unsigned int *)((unsigned long) CSR_ADDRESS + \ (unsigned long) SWIZZLE_ADDRESS(a) + ioLong) #define outp(a, d) { \ volatile unsigned int *rP; \ rP = ADDRESS_BYTE(a); \ MB(); \ *rP = SWIZZLE_DATA(d & 0xFF, a);\ } You should be able to figure out the rest from here. Reading is the inverse of writing. The MB() (memory barrier) prevents the write from collapsing in the write buffer (that is, if you try to write the same location twice in succession, without the MB() it is probable that the first write will be thrown out). If you know that you are not writing to the same address within say, the last 6 writes - then you don't need the memory barrier - OR if you don't care that some of the writes will be thrown out - i.e. frame buffer writes typically only care about the final value, but CSR writes usually need all writes to actually happen. Note that the mapped virtual address is already "swizzled" as it were, so you are swizzling the offset (the "a" argument in the macros) and adding to the base to get the effective address. Good luck... cause if you get it wrong, you will machine check the system if the address is in PCI address space. And when you get a machine with a flat byte addressable space, it will also not work, and likely will machine check (since you will get a completely bogus address if you try and swizzle things). I tell people to try *not* to do this by mapping I/O space into a usermode application (like the X server - which is why I know how to do this), and to instead write a device driver and use the O/S callbacks instead. _Fred