|
|
#include <sys/confmgr.h> #include <sys/ddi.h>int cm_getval(cm_args_t *args);
cm_n of zero
and continuing with incremented cm_n until
cm_getval returns an ENOENT.
If ENOSPC or success is returned,
cm_vallen will be updated
with the actual length of the stored value.
cm_getval( ) must be called as part of a read/write transaction, between calls to cm_begin_trans(D3) and cm_end_trans(D3).
``Autoconfiguration'' in HDK Technical Reference
1 int xxconfig( .....) {
2 ...
3 cm_args_t cmargs;
4 RAMDDEVEXT *devext = (RAMDDEVEXT *)idata;
5 switch (func) {
6 case CFG_ADD:
7 devext = kmem_alloc(sizeof(*devext), KM_NOSLEEP);
8 if (devext == NULL)
9 {
10 rc = ENOMEM;
11 cmn_err(CE_NOTE, "kmem_alloc failed");
12 break;
13 }
14 cm_begin_trans(key, RM_READ);
15 cmargs.cm_key = key;
16 cmargs.cm_param = CM_IOADDR;
17 cmargs.cm_val = &devext->ioaddr;
18 cmargs.cm_vallen = sizeof(devext->ioaddr);
19 cmargs.cm_n = 0;
20 rc = cm_getval(&cmargs);
21 if (rc !=0 )
22 {
23 cm_end_trans(key);
24 break;
25 }
26 *(void **)idata = devext;
27 cm_end_trans(key);
28 ...
cmargs.cm_val is the buffer for this value
and cmargs.cm_vallen is the length of this buffer.
Any of the parameters documented on the
cm_params(D5)
manual page can be accessed in the same way.
cmargs.cm_n effectively terminates access to the resource database.
Line 20 then calls cm_getval( ), to retrieve the entry from the resource manager database, with the populated cm_args structure as an argument. The values to be retrieved are the ones that have been set up in the cm_args structure.
If the call to cm_getval( ) fails, the transaction is ended with a call to the cm_end_trans(D3) function. This code is simplified; a real driver should test for the various error conditions that are documented on the cm_getval( ) manual page and perhaps take additional actions.