xref: /illumos-gate/usr/src/uts/common/sys/dacf_impl.h (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
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 /*
31  * Implementation-Private definitions for Device autoconfiguration (dacf)
32  */
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #include <sys/types.h>
39 #include <sys/dacf.h>
40 
41 typedef struct dacf_module {
42 	char *dm_name;			/* module name */
43 	krwlock_t dm_lock;		/* module lock */
44 	int dm_loaded;			/* whether dm_opsets is valid */
45 	dacf_opset_t *dm_opsets;	/* null-terminated array of op-sets */
46 } dacf_module_t;
47 
48 
49 #define	DACF_RULE_HASHSIZE	8
50 #define	DACF_MODULE_HASHSIZE	8
51 #define	DACF_INFO_HASHSIZE	16
52 
53 /*
54  * Flags to dacf_process_rsrvs
55  */
56 #define	DACF_PROC_INVOKE	0x0001
57 #define	DACF_PROC_RELE		0x0002
58 
59 typedef enum dacf_devspec {
60 	DACF_DS_ERROR = -1,		/* error state */
61 	DACF_DS_MIN_NT = 1,		/* match minor node-type */
62 	DACF_DS_DRV_MNAME = 2,		/* match driver minor name */
63 	DACF_DS_DEV_PATH = 3		/* match device path */
64 } dacf_devspec_t;
65 
66 #define	DACF_NUM_DEVSPECS 3
67 
68 typedef struct dacf_arg {
69 	char *arg_name;			/* operation argument name */
70 	char *arg_val;			/* operation argument value */
71 	struct dacf_arg *arg_next;	/* next arg in chain */
72 } dacf_arg_t;
73 
74 typedef struct dacf_rule {
75 	char *r_devspec_data;		/* the dev-spec data to match against */
76 	char *r_module;			/* module implementing the operation */
77 	char *r_opset;			/* opset in module that impls. op */
78 	dacf_opid_t r_opid;		/* operation id for this rule */
79 	uint_t r_opts;			/* reserved for options */
80 	uint_t r_refs;			/* reference count */
81 	dacf_arg_t *r_args;		/* linked list of operation arguments */
82 } dacf_rule_t;
83 
84 typedef struct dacf_rsrvlist {
85 	dacf_rule_t *rsrv_rule;		/* the rule being reserved for later */
86 	dacf_infohdl_t rsrv_ihdl;
87 	int rsrv_result;		/* retval of the last invoke */
88 	struct dacf_rsrvlist *rsrv_next;
89 } dacf_rsrvlist_t;
90 
91 #ifdef _KERNEL
92 
93 extern kmutex_t dacf_lock;
94 
95 int dacf_module_register(char *, struct dacfsw *);
96 int dacf_module_unregister(char *);
97 
98 int dacf_arg_insert(dacf_arg_t **, char *, char *);
99 void dacf_arglist_delete(dacf_arg_t **);
100 
101 void dacf_init(void);
102 int read_dacf_binding_file(char *);
103 void dacf_clear_rules(void);
104 
105 dacf_devspec_t dacf_get_devspec(char *);
106 const char *dacf_devspec_to_str(dacf_devspec_t);
107 
108 dacf_opid_t dacf_get_op(char *);
109 const char *dacf_opid_to_str(dacf_opid_t);
110 
111 int dacf_getopt(char *, uint_t *);
112 
113 int dacf_rule_insert(dacf_devspec_t, char *, char *, char *,
114     dacf_opid_t, uint_t, dacf_arg_t *);
115 void dacf_rule_hold(dacf_rule_t *);
116 void dacf_rule_rele(dacf_rule_t *);
117 
118 struct ddi_minor_data;
119 void dacf_rsrv_make(dacf_rsrvlist_t *, dacf_rule_t *, void *,
120     dacf_rsrvlist_t **);
121 void dacf_process_rsrvs(dacf_rsrvlist_t **, dacf_opid_t, int);
122 void dacf_clr_rsrvs(dev_info_t *, dacf_opid_t);
123 
124 dacf_rule_t *dacf_match(dacf_opid_t, dacf_devspec_t, const void *);
125 
126 /*
127  * Failure codes from dacf_op_invoke, assigned to dacf_rsrvlist_t.rsrv_result
128  */
129 #define	DACF_ERR_MOD_NOTFOUND		-1
130 #define	DACF_ERR_OPSET_NOTFOUND		-2
131 #define	DACF_ERR_OP_NOTFOUND		-3
132 #define	DACF_ERR_OP_FAILED		-4
133 
134 int dacf_op_invoke(dacf_rule_t *, dacf_infohdl_t, int);
135 
136 /*
137  * Debugging support
138  */
139 #define	DACF_DBG_MSGS		0x00000001
140 #define	DACF_DBG_DEVI		0x00000002
141 
142 extern int dacfdebug;
143 
144 
145 /*
146  * dacf client support: definitions pertaining to the various kernel hooks
147  * that utilize the dacf framework
148  */
149 
150 void dacfc_match_create_minor(const char *, const char *, dev_info_t *,
151     struct ddi_minor_data *, int);
152 
153 int dacfc_postattach(dev_info_t *);
154 int dacfc_predetach(dev_info_t *);
155 
156 #endif /* _KERNEL */
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif /* _DACF_IMPL_H */
163