From: jjg@pt.com (John Grana)
Subject: Re: S-Bus device driver  question
Organization: Performance Technologies, Incorporated
Date: Tue, 18 Aug 1992 11:46:01 GMT

In article <MISHA.92Aug12193338@espresso.ai.mit.edu> misha@ai.mit.edu (Mike Bolotski) writes:
>
>Forwarded for a friend at the AI Lab:
>
>--------
>
>	I'm trying to write a simple device driver for a memory mapped
>sbus-peripheral.  I am trying to understand how the device specific xxmmap
>fits in with relation to mmap and unmap.  Particularly, I don't understand
>why there is no xxunmap routine.
>
Andrea,

	The driver specific xxmmap routine is called to provide range
checking (i.e. is the user request in the address range of the device) and
for Page Table Entry (PTE) information for the kernel. The kernel
takes this PTE info and maps the page into user virtual address space.
This point is important for your next question/issue:

>
>	My peripheral has a potentially large address space (e.g. the
>entire 25 bits provided on early S-Busses).  Experience has shown that I
>cannot simply map the entire region once since that requires too much space
>in the kernel and hence panics/crashes the machine.  So, I understand that
>I need to map and unmap regions as I need access to them.  Ok, I have
>written an xxmmap routing, which I understand will be called once by mmap
>for each page that needs allocating.  My user program then calls mmap and
>munmap.  However, after running for a while, the machine panics and crashes
>do to insufficient space in some kernel map table.

So far so good. Yup, the kernel will call your driver xxmmap routine many
times (once per "pagesize" of the user request).

>
>	In my xx_mmap routine, I am using map_regs to map the sbus physical
>address into a kernel address and hat_getkpfnum to get an address to return
>to the user program.  This generally seems to have the desired effect.
>However, I note that there is an unmap_regs routine, which one might want
>called to release mappings.  However, since there is no xx_munmap routine,
>I don't seem to have a hook which allows me to umap_regs when the user
>level program does a munmap.

Since the kernel just needs the physical page frame information, you
dont have to map the request virtually yourself. Actually, you are
mapping the request into kernel virtual space... Anways, just return
the page frame information... (phys address page (btop) or'ed with page type
(PGT_OBIO))
something like this:

	{
		check boundrys...

		get SBus physical base address (from dev_info structure)
		add in users offset into your SBus physical base...

		and return:

		return(PGT_OBIO | btop(SBusPhysAddr));
	}

This should allow pretty large mappings... we have never had a problem
mapping in pretty large chunks - up to 28 MB. You also get the benefit
of not using up page table entries - I suspect that is the reason for
the panics. Let the kernel worry about it!

Good Luck
John Grana
jjg@pt.com

-- 
___________________________________________________________________________
|John Grana, Performance Technologies Incorporated		jjg@pt.com|
|315 Science Parkway, Rochester, New York 14620           uupsi!ptsys1!jjg|
|Phone: (716) 256-0200   Fax: (716) 256-0791                              |