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