Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - dev_attach parameters: (4 Items)
   
dev_attach parameters  
Can someone provide a definitive description of the parameters taken by dev_attach()?

There are several posts in this forum that have asked this question going back to 2009 but no clear answer that I can 
find.

In particular, what does dev_attach() do with the 5th, 6th parameters? What are the expected values and how/when are 
they updated by dev_attach(). 

How is the 7th parameter used?

Thanks,
John
Re: dev_attach parameters  
Hi John,
Here's the function signature:
int
dev_attach(char *drvr, char *options, struct cfattach *ca,
    void *cfat_arg, int *single, struct device **devp,
    int (*print)(void *, const char *))


drvr is a string that is used for the interface name e.g. "sc" ends up creating an interface "sc0" by default.

options is the options string that was passed to the driver - this is parsed by dev_attach() looking for "name", "lan" 
and "unit" options which will override the the default naming of the interface. "lan" and "unit" are identical in 
meaning and will override the number appended to the interface naming rather than it just being a sequential number of 
all the ones of that type. "name" overrides the "drvr" string.

ca is the structure formed by the CFATTACH_DECL() macro which specifies the size of the device structure and the attach 
and detach functions.

cfat_arg is the attach arg - comes through to the driver attach function as parameter 3

single isn't really used, if the "lan" or "unit" option is in the options string then it gets set to 1, but that's it.

devp is used in two ways. First of all if it is set to non-NULL on entry then it specifies the parent device that this 
device is a child of. I don't recall a driver ever actually using this - there is a check on removal that the device 
being removed is not the parent of any remaining devices. All drivers I have seen set it to NULL to specify that there 
is no parent. Secondly it is set as a pointer to the dev structure that is also passed to the attach function as 
parameter 2 so is a way of retrieving the device structure after the call to dev_attach - again I don't recall any 
driver using this. I have seen a bugs where this was not initialised and luckily pointed to NULL until a code change was
 made when it pointed to a random value and caused the driver to crash, so please set it to NULL!

print I've never seen used, always set to NULL. dev_attach() actually does:
if (print != NULL)
		(*print)(cfat_arg, NULL);
so I suppose you could use it for debugging.

Regards,
Nick.
Re: dev_attach parameters  
Hi Nick,

Thanks - exactly what I was after!

Regards,
John
Re: dev_attach parameters  
I'll add this information to the docs.