xref: /onnv-gate/usr/src/uts/common/sys/dacf_impl.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_DACF_IMPL_H
28*0Sstevel@tonic-gate #define	_DACF_IMPL_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate /*
33*0Sstevel@tonic-gate  * Implementation-Private definitions for Device autoconfiguration (dacf)
34*0Sstevel@tonic-gate  */
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #ifdef	__cplusplus
37*0Sstevel@tonic-gate extern "C" {
38*0Sstevel@tonic-gate #endif
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #include <sys/types.h>
41*0Sstevel@tonic-gate #include <sys/dacf.h>
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate typedef struct dacf_module {
44*0Sstevel@tonic-gate 	char *dm_name;			/* module name */
45*0Sstevel@tonic-gate 	krwlock_t dm_lock;		/* module lock */
46*0Sstevel@tonic-gate 	int dm_loaded;			/* whether dm_opsets is valid */
47*0Sstevel@tonic-gate 	dacf_opset_t *dm_opsets;	/* null-terminated array of op-sets */
48*0Sstevel@tonic-gate } dacf_module_t;
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate 
51*0Sstevel@tonic-gate #define	DACF_RULE_HASHSIZE	8
52*0Sstevel@tonic-gate #define	DACF_MODULE_HASHSIZE	8
53*0Sstevel@tonic-gate #define	DACF_INFO_HASHSIZE	16
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate /*
56*0Sstevel@tonic-gate  * Flags to dacf_process_rsrvs
57*0Sstevel@tonic-gate  */
58*0Sstevel@tonic-gate #define	DACF_PROC_INVOKE	0x0001
59*0Sstevel@tonic-gate #define	DACF_PROC_RELE		0x0002
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate typedef enum dacf_devspec {
62*0Sstevel@tonic-gate 	DACF_DS_ERROR = -1,		/* error state */
63*0Sstevel@tonic-gate 	DACF_DS_MIN_NT = 1,		/* match minor node-type */
64*0Sstevel@tonic-gate 	DACF_DS_DRV_MNAME = 2,		/* match driver minor name */
65*0Sstevel@tonic-gate 	DACF_DS_DEV_PATH = 3		/* match device path */
66*0Sstevel@tonic-gate } dacf_devspec_t;
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate #define	DACF_NUM_DEVSPECS 3
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate typedef struct dacf_arg {
71*0Sstevel@tonic-gate 	char *arg_name;			/* operation argument name */
72*0Sstevel@tonic-gate 	char *arg_val;			/* operation argument value */
73*0Sstevel@tonic-gate 	struct dacf_arg *arg_next;	/* next arg in chain */
74*0Sstevel@tonic-gate } dacf_arg_t;
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate typedef struct dacf_rule {
77*0Sstevel@tonic-gate 	char *r_devspec_data;		/* the dev-spec data to match against */
78*0Sstevel@tonic-gate 	char *r_module;			/* module implementing the operation */
79*0Sstevel@tonic-gate 	char *r_opset;			/* opset in module that impls. op */
80*0Sstevel@tonic-gate 	dacf_opid_t r_opid;		/* operation id for this rule */
81*0Sstevel@tonic-gate 	uint_t r_opts;			/* reserved for options */
82*0Sstevel@tonic-gate 	uint_t r_refs;			/* reference count */
83*0Sstevel@tonic-gate 	dacf_arg_t *r_args;		/* linked list of operation arguments */
84*0Sstevel@tonic-gate } dacf_rule_t;
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate typedef struct dacf_rsrvlist {
87*0Sstevel@tonic-gate 	dacf_rule_t *rsrv_rule;		/* the rule being reserved for later */
88*0Sstevel@tonic-gate 	dacf_infohdl_t rsrv_ihdl;
89*0Sstevel@tonic-gate 	int rsrv_result;		/* retval of the last invoke */
90*0Sstevel@tonic-gate 	struct dacf_rsrvlist *rsrv_next;
91*0Sstevel@tonic-gate } dacf_rsrvlist_t;
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate #ifdef _KERNEL
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate extern kmutex_t dacf_lock;
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate int dacf_module_register(char *, struct dacfsw *);
98*0Sstevel@tonic-gate int dacf_module_unregister(char *);
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate int dacf_arg_insert(dacf_arg_t **, char *, char *);
101*0Sstevel@tonic-gate void dacf_arglist_delete(dacf_arg_t **);
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate void dacf_init(void);
104*0Sstevel@tonic-gate int read_dacf_binding_file(char *);
105*0Sstevel@tonic-gate void dacf_clear_rules(void);
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate dacf_devspec_t dacf_get_devspec(char *);
108*0Sstevel@tonic-gate const char *dacf_devspec_to_str(dacf_devspec_t);
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate dacf_opid_t dacf_get_op(char *);
111*0Sstevel@tonic-gate const char *dacf_opid_to_str(dacf_opid_t);
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate int dacf_getopt(char *, uint_t *);
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate int dacf_rule_insert(dacf_devspec_t, char *, char *, char *,
116*0Sstevel@tonic-gate     dacf_opid_t, uint_t, dacf_arg_t *);
117*0Sstevel@tonic-gate void dacf_rule_hold(dacf_rule_t *);
118*0Sstevel@tonic-gate void dacf_rule_rele(dacf_rule_t *);
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate struct ddi_minor_data;
121*0Sstevel@tonic-gate void dacf_rsrv_make(dacf_rsrvlist_t *, dacf_rule_t *, void *,
122*0Sstevel@tonic-gate     dacf_rsrvlist_t **);
123*0Sstevel@tonic-gate void dacf_process_rsrvs(dacf_rsrvlist_t **, dacf_opid_t, int);
124*0Sstevel@tonic-gate void dacf_clr_rsrvs(dev_info_t *, dacf_opid_t);
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate dacf_rule_t *dacf_match(dacf_opid_t, dacf_devspec_t, void *);
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate /*
129*0Sstevel@tonic-gate  * Failure codes from dacf_op_invoke, assigned to dacf_rsrvlist_t.rsrv_result
130*0Sstevel@tonic-gate  */
131*0Sstevel@tonic-gate #define	DACF_ERR_MOD_NOTFOUND		-1
132*0Sstevel@tonic-gate #define	DACF_ERR_OPSET_NOTFOUND		-2
133*0Sstevel@tonic-gate #define	DACF_ERR_OP_NOTFOUND		-3
134*0Sstevel@tonic-gate #define	DACF_ERR_OP_FAILED		-4
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate int dacf_op_invoke(dacf_rule_t *, dacf_infohdl_t, int);
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate /*
139*0Sstevel@tonic-gate  * Debugging support
140*0Sstevel@tonic-gate  */
141*0Sstevel@tonic-gate #define	DACF_DBG_MSGS		0x00000001
142*0Sstevel@tonic-gate #define	DACF_DBG_DEVI		0x00000002
143*0Sstevel@tonic-gate 
144*0Sstevel@tonic-gate extern int dacfdebug;
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate /*
148*0Sstevel@tonic-gate  * dacf client support: definitions pertaining to the various kernel hooks
149*0Sstevel@tonic-gate  * that utilize the dacf framework
150*0Sstevel@tonic-gate  */
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate void dacfc_match_create_minor(char *, char *, dev_info_t *,
153*0Sstevel@tonic-gate     struct ddi_minor_data *, int);
154*0Sstevel@tonic-gate 
155*0Sstevel@tonic-gate int dacfc_postattach(dev_info_t *);
156*0Sstevel@tonic-gate int dacfc_predetach(dev_info_t *);
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate #endif /* _KERNEL */
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate #ifdef __cplusplus
161*0Sstevel@tonic-gate }
162*0Sstevel@tonic-gate #endif
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate #endif /* _DACF_IMPL_H */
165