*BSD News Article 12595


Return to BSD News archive

Newsgroups: comp.os.386bsd.questions
Path: sserve!manuel.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!netsys!pagesat!spssig.spss.com!news.oc.com!utacfd.uta.edu!rwsys!sneaky!gordon
From: gordon@sneaky.lonestar.org (Gordon Burditt)
Subject: device drivers and memory-mapped I/O
Message-ID: <C3MqoF.6J3@sneaky.lonestar.org>
Organization: Gordon Burditt
Date: Tue, 9 Mar 1993 16:19:20 GMT
Lines: 39

I'm trying to write a device driver for a board which uses memory-mapped
I/O.  This ought to be easy, but it's turning out to be complicated.
I wish I understood the vm system more.  In the xxxprobe() routine, I need to:

1.  Allocate 64k of physical address space, on a 64k boundary.  It's
going to be used for dual-ported memory for an I/O board.  This
is NOT in the "I/O hole" (0x0a0000-0x0fffff), but more likely out
in the 15 meg region (0xf00000).  Currently I'm doing this manually
in the config file with the "iomem" parameter.  I think it may have to 
stay that way, as I see no way of automatically determining conflicts.  
(Yes, I know how to handle the offset between what's specified in "iomem" 
and what the driver gets assuming the address is in the "I/O hole".  It's
using the correct address.)  The board needs to be told where to appear 
in the physical address space before I can figure out if it's there or 
not.  There are potentially 4 of these devices.

2. Allocate 64k of kernel address space, NOT memory.  This needs to
be on a page boundary.

3.  Map address space in (1) to dual-ported memory in (2).

4.  Arrange that (3) is accomplished so that the kernel will not
reallocate, swap, page, cache, or otherwise mess with this memory.

(1) I've done with the config file.  (2) I'm trying to do following
the pattern of kmem_alloc() but without forcing allocation of 
physical memory.  I seem to be getting a reasonable kernel virtual
address.  (3) I seem to be able to do with pmap_map(), enough
so that the routine can access the memory and tell whether the board
is there or not.  (4) seems to be a problem, as the system locks up 
before it goes fully multi-user.  (Even if I take the board out ...)  
I'm hardly even trying to USE the board yet.  All of the driver routines 
but xxxprobe() are dummy.

What's the proper BSD way to do this?  I also need to give back the
address space and undo the mapping if there's no board there.

					Gordon L. Burditt
					sneaky.lonestar.org!gordon