From: Jim Barrett <barrett@ial3.jsc.nasa.gov>
Subject: HELP!  Trying to config kernel for VME device
Organization: Lockheed Engineering & Sciences Co.
X-Useragent: Nuntius v1.1
Date: Thu, 1 Oct 1992 19:22:56 GMT

Greetings, O wize ones ;^) ... 

I'm trying to install a VME device in a 4D/35, and am having trouble.
I want to access this device through a user process using mmap(2).  
I believe the problem is in my configuration of the kernel, but I'm 
not sure.  I hope some guru reading this can provide a few pointers.  

The kernel I've made runs fine as long as I don't try to access the
board.  My program can open /dev/mmem and mmap the resulting file
descriptor, but it drops core whenever it tries to access through the
pointer that mmap returns.  Stepping through the program with dbx
causes kernel panics (& crashes) whenever VME access is attempted.  

Now for the details:  

The device lives in VME's short address space (A16) and has 32 bytes
of registers.  I set the board's address to VME 0x6000, based on
information in /usr/sysgen/system.  This file says that VME A16 
addresses 6000-7FFF and C000-FFFF have been reserved for customer use. 
So I chose 0x6000.  The board is also set for non-supervisor access. 
	
I also modified /usr/sysgen/master.d/mem.  Referring to
/usr/sysgen/system again, it says that an IP12 CPU's VME address is
mapped into Kernel Addresses like so:  

    System          Kernel Address          VME Address     Modifier
    ======          ==============          ===========     ========
    'IP4/6/12'      0xbd000000-0xbd00ffff   0x0-0xffff      0x2d (s)
    'IP4/6/12'      0xbd100000-0xbd10ffff   0x0-0xffff      0x29 (np)

(hinv says the 4D/35 contains "1 36 MHZ IP12 Processor")

Because the board is configured for non-supervisor access (np?), and
that the board lives at VME 0x6000, I figured that the board's kernel
address is  0xbd100000 + 0x6000 = 0xbd106000.  So, I made an entry in
the mmmap_addrs[] array in /usr/sysgen/master.d/mem.   Here's a copy
of it (my additions are marked):

	struct map mmmap_addrs[] = {
	#if IP4 || IP5 || IP17
	    { NBPP, SOUND_DAT_ADDR, },  /* sound chip and friends */
	#endif
	#if IP12
==>     { 32, 0xbd106000 }, /* takin' a stab at a/d board installation
*/
==> 		/* 32 is the # of bytes of registers that the board has */
	    { 0x20000, PHYS_TO_K1(HPC1MEMORY), },   /* DSP, etc. */
	    /* HPC registers, in particular HPC1MISCSR */
	    { NBPP, PHYS_TO_K1(HPC_0_ID_ADDR    ), },
	#endif
	#if IP5 || IP17
	    { 0x80000, LOGRAM_ADDR, },  /* ECC logging RAM */
	    { NBPP, IOTIMER_ADDR, },    /* free running timer on IO3 */
	#endif
	    { 0, 0 } ,  /* NULL ENTRY TERMINATES THIS LIST! */
	};

After making this entry I ran lboot, copied the new kernel to
/unix.install, and rebooted.  Then I ran my program, which invokes
the following function:  

	#include <stdio.h>
	#include <fcntl.h>
	#include <sys/mman.h>
	
	void
	Init_Board(void)
	{
	    int  fd;
	    extern vmic3111  *board_ctl;  
	
	    fd = open("/dev/mmem", O_RDWR);
	    if (fd < 0)
	        Err("could not open /dev/mmem (errno %d)", errno);
	
	    board_ctl = mmap(0, 32, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd,
	        0xbd106000);
	    if (board_ctl == 0)
	        Err("could not mmap the a/d board (errno %d)", errno);
	
	    printf("board_ctl == 0x%08X\n", board_ctl);
	    board_ctl->csr.fail_led = 1;
	}

The printf produces "board_ctl == 0x00600000" every time I run the
program.   My program drops core on the "board_ctl->csr.fail_led = 1"
statement.   Attempting to read from the board also causes core
dumps.  


Well, if you read thru all that and are still with me :-), do
you have any idea what might be wrong?  Ideas, anyone?  


AtDhVaAnNkCsE,

Jim
--
Jim Barrett                               barrett@ial3.jsc.nasa.gov
"This has been a test of the Opinion Broadcast System.  If this had
been an actual opinion you would have received instructions on where
to go and what to do.  This is only a test."