reference drivers

Michael Honeyfield michael at endace.com
Thu Oct 13 13:03:59 PDT 2005


John Baldwin wrote:

>>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?
>
>  
>

Yes, I have d_mmap in cdevsw, as per below:

static struct cdevsw foo_cdevsw = {
    .d_open =    foo_open,
    .d_close =    foo_close,
    .d_read =    foo_read,
    .d_write =    foo_write,
    .d_mmap =    foo_mmap,
    .d_strategy =     NULL,
    .d_dump =     NULL,
    .d_version =     D_VERSION,
    .d_flags =    D_NEEDGIANT,
    .d_name =    "foo"
};

I do have debugging statements inside each function, so I can see from 
dmesg what is happening, or atleast, get a better idea. I use this for 
debugging:

DPRINTF("foo mmap!\n");

The above is inside each function, with it defined as

#define DPRINTF(format, args...)    printf(format , ## args);

Since my driver is only in its absolutly early stages of development, it 
very closely resembles the driver given in the url in my first email, 
the only changes are some additional debugging out and my function 
definitions.

I could post those if you think it could help.

Regards

-- 
Michael Honeyfield
TECHNICAL SUPPORT
____________________________________________________

Endace Technology

michael at endace.com
http://www.endace.com



More information about the freebsd-drivers mailing list