Subject: Re: is mmap on /dev/mem broken on sparc64?
To: None <port-sparc64@netbsd.org, current-users@netbsd.org>
From: Eduardo Horvath <eeh@NetBSD.org>
List: port-sparc64
Date: 03/13/2005 17:31:57
On Sat, Mar 12, 2005 at 04:57:00PM -0500, Sean Davis wrote:
> Okay, I've tried about a million variations on this code... no luck with any
> of them. Basically, I'm trying to mmap a specific region of memory with the
> eventual goal of getting a ROM dump from an Adaptec 2940UW. But that is not
> the problem. The problem is, even after I've gotten the offset of the card
> ROM from pci_conf_read, I can't mmap() /dev/mem. I'm running at securelevel
> 1, which, according to the init manpage, means I should be able to mmap it
> read-only. But, all mmap calls are giving me EINVAL. The code follows:

You can't do that on sparc64.  That functionality has been explicitly
disabled to prevent userland from causing possible kernel hangs or panics.

And here's why:

The coherency domain for all sparc64 machines is the E$ which handles ECC
generation and checking.  That is memory space.  Other areas must not
use the E$ and are considered I/O space.  Special bits must be set in 
the TLB entries to indicate whether to go through the E$ or bypass it.
If you get this wrong, accessing memory will generate some rather 
nasty asynchronous memory errors that are painful to recover from.  
/dev/mem therefore only allows you to map in areas it knows go through
the E$, which essentially limits it to DRAM.  

If you want to access PCI memory space you need to go through some
sort of PCI device driver that knows what bits, such as cacheabiliy
and endianness, need to be set to map it in correctly.

Eduardo