Nick Reilly
|
Re: dev_attach parameters
|
Nick Reilly
05/01/2019 10:17 AM
post119688
|
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.
|
|
|