Subject: Re: Any way to get virtual addr from pci_mapreg_map()?
To: Chris G. Demetriou <>
From: Dave Huang <>
List: tech-kern
Date: 08/12/1997 17:32:31
On Tue, 12 Aug 1997, Chris G. Demetriou wrote:
> "so, fix it."  That is not portable code.  Device memory may not be
> mapped linearly, and indeed on many systems _is not_ mapped inearly.

Okay, done, I think :) Well, almost... see below...

> Do you know off-hand whether the mapping registers say that the region
> is prefetchable or not?  (I'm just wondering for my own curiosity; it
> doesn't affect anything i've said here.)

How can I tell? Is this the PCI_MAPREG_MEM_CACHEABLE bit from pcireg.h? If
so, no, it's not set on my 53c875 (ASUS SC875 card).

So, I've got everything using the bus_space_* stuff, and it seems to be
working just fine... except I tried using bus_space_write_multi_4 to
copy the microcode over to the card, and it made my machine reboot. So,
I'm currently using bus_space_write_4 in a loop, which works okay.

I think it's a gcc optimizer bug, but I'm not sure... it looks like gcc
isn't paying attention to the list of registers that are used by the
__asm() code in bus_space_write_multi_4. The following demonstrates the
bug when compiled with -O or -O2:

#include <sys/time.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <machine/bus.h>

struct z {
  bus_space_handle_t h;
  bus_space_tag_t t;
  char *p;

void bla(struct z *p)
    bus_space_write_1 (p->t, p->h, 2, 3);

    bus_space_write_multi_4(p->t, p->h, 0, p->p, 1);

cc -S -O generates:

        movl (%ebx),%eax
        movl 8(%ebx),%esi
        movl $1,%ecx

                                ;                       1:      lodsl           
                        ;                               movl %eax,(%eax)        
                        ;                               loop 1b

notice how gcc decides to use eax as the destination pointer, ignoring
that the lodsl has put its own stuff in eax.

Removing the bus_space_write_1 line makes the code work again.

This is on an i386, btw... feel free to redirect replies to port-i386 or
wherever it's most appropriate :)
Name: Dave Huang     |   Mammal, mammal / their names are called /
INet:   |   they raise a paw / the bat, the cat /
FurryMUCK: Dahan     |   dolphin and dog / koala bear and hog -- TMBG
Dahan: Hani G Y+C 21 Y++ L+++ W- C++ T++ A+ E+ S++ V++ F- Q+++ P+ B+ PA+ PL++