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