reference drivers

John Baldwin jhb at freebsd.org
Thu Oct 13 08:32:21 PDT 2005


On Wednesday 12 October 2005 05:04 pm, Michael Honeyfield wrote:
> John Baldwin wrote:
> >On Sunday 09 October 2005 04:55 pm, Michael Honeyfield wrote:
> >>Hello all,
> >>
> >>I have been working on a small project that involes writting a drver for
> >>FreeBSD. I have used this link as my reference for my driver:
> >>
> >>http://www.ben.com/minipci/driver.php
> >>
> >>Now, after my modifications, I can load the kernel module fine. However,
> >>the mmap function is not even called. Is the mmap function used inside
> >>this diver the correct way map registers from kernel space to user space?
> >
> >Yes.  It should be called when an application does an mmap() on an fd
> > returned by open()'ing the file in /dev.
>
> Ok, good to know I am on the right path.
>
> Where is a good place to look if the foo_mmap() is not actually called?
>
> I use this routine as a test for mapping a register into user space:
>
>   fd = open( "/dev/bar0", O_RDWR );
>   reg = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
>   if( reg == MAP_FAILED) {
>     fprintf( stderr, "can't mmap bar!\n" );
>     exit(1);
>   }
>
> the code takes an arg, and the register I am selecting is there. The
> above code snippet works on Linux.

You need to make sure d_mmap in your cdevsw is mapped to your mmap function.  
How do you know that your mmap routine is not being called?  Did you add a 
printf or some such?  Did you do so before any error checking that would 
cause an early return from the function?

-- 
John Baldwin <jhb at FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org


More information about the freebsd-drivers mailing list