1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <regex.h>
#include <devfsadm.h>
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <limits.h>
#include <sys/mkdev.h>
#include <bsm/devalloc.h>
extern int system_labeled;
static int node_name(di_minor_t minor, di_node_t node);
static int ddi_other(di_minor_t minor, di_node_t node);
static int diskette(di_minor_t minor, di_node_t node);
static int ecpp_create(di_minor_t minor, di_node_t node);
static int mc_node(di_minor_t minor, di_node_t node);
static int ddi_cardreader(di_minor_t minor, di_node_t node);
static int starcat_sbbc_node(di_minor_t minor, di_node_t node);
static int wrsm(di_minor_t minor, di_node_t node);
static int lom(di_minor_t minor, di_node_t node);
static int ntwdt_create(di_minor_t minor, di_node_t node);
static devfsadm_create_t misc_cbt[] = {
{ "other", "ddi_other", NULL,
TYPE_EXACT, ILEVEL_0, ddi_other
},
{ "memory-controller", "ddi_mem_ctrl", NULL,
TYPE_EXACT, ILEVEL_0, mc_node
},
{ "pseudo", "ddi_pseudo", "sbbc",
TYPE_EXACT | DRV_EXACT, ILEVEL_1, starcat_sbbc_node
},
{ "disk", "ddi_block:diskette", NULL,
TYPE_EXACT, ILEVEL_1, diskette
},
{ "printer", "ddi_printer", NULL,
TYPE_EXACT, ILEVEL_1, ecpp_create
},
{ "card-reader", "ddi_smartcard_reader", NULL,
TYPE_EXACT, ILEVEL_0, ddi_cardreader
},
{ "pseudo", "(^ddi_pseudo$)|(^ddi_ctl:devctl$)", "wrsm",
TYPE_RE | DRV_EXACT, ILEVEL_0, wrsm,
},
{ "network", "ddi_net", "wrsmd",
TYPE_EXACT | DRV_EXACT, ILEVEL_0, node_name,
},
{ "pseudo", "ddi_pseudo", "lw8",
TYPE_EXACT | DRV_EXACT, ILEVEL_0, lom
},
{ "pseudo", "ddi_pseudo", "ntwdt",
TYPE_EXACT | DRV_EXACT, ILEVEL_0, ntwdt_create
},
};
DEVFSADM_CREATE_INIT_V0(misc_cbt);
/* Smart Card Reader device link */
#define CARDREADER_LINK "^scmi2c[0-9]+$"
/* Rules for removing links */
static devfsadm_remove_t sparc_remove_cbt[] = {
{ "card-reader", CARDREADER_LINK, RM_PRE | RM_ALWAYS,
ILEVEL_0, devfsadm_rm_all }
};
DEVFSADM_REMOVE_INIT_V0(sparc_remove_cbt);
/*
* Handles minor node type "ddi_other"
* type=ddi_other;name=SUNW,pmc pmc
* type=ddi_other;name=SUNW,mic mic\M0
*/
static int
ddi_other(di_minor_t minor, di_node_t node)
{
char path[PATH_MAX + 1];
char *nn = di_node_name(node);
char *mn = di_minor_name(minor);
if (strcmp(nn, "SUNW,pmc") == 0) {
(void) devfsadm_mklink("pcm", node, minor, 0);
} else if (strcmp(nn, "SUNW,mic") == 0) {
(void) strcpy(path, "mic");
(void) strcat(path, mn);
(void) devfsadm_mklink(path, node, minor, 0);
}
return (DEVFSADM_CONTINUE);
}
/*
* This function is called for diskette nodes
*/
static int
diskette(di_minor_t minor, di_node_t node)
{
int flags = 0;
char *mn = di_minor_name(minor);
if (system_labeled)
flags = DA_ADD|DA_FLOPPY;
if (strcmp(mn, "c") == 0) {
(void) devfsadm_mklink("diskette", node, minor, flags);
(void) devfsadm_mklink("diskette0", node, minor, flags);
} else if (strcmp(mn, "c,raw") == 0) {
(void) devfsadm_mklink("rdiskette", node, minor, flags);
(void) devfsadm_mklink("rdiskette0", node, minor, flags);
}
return (DEVFSADM_CONTINUE);
}
/*
* Handles links of the form:
* type=ddi_pseudo;name=xyz \D
*/
static int
node_name(di_minor_t minor, di_node_t node)
{
(void) devfsadm_mklink(di_node_name(node), node, minor, 0);
return (DEVFSADM_CONTINUE);
}
/*
* Handles links of the form:
* type=ddi_printer;name=ecpp ecpp\N0
*/
static int
ecpp_create(di_minor_t minor, di_node_t node)
{
char *buf;
char path[PATH_MAX + 1];
devfsadm_enumerate_t rules[1] = {"^ecpp([0-9]+)$", 1, MATCH_ALL};
if (strcmp(di_driver_name(node), "ecpp") != 0) {
return (DEVFSADM_CONTINUE);
}
if ((buf = di_devfs_path(node)) == NULL) {
return (DEVFSADM_CONTINUE);
}
(void) snprintf(path, sizeof (path), "%s:%s",
buf, di_minor_name(minor));
di_devfs_path_free(buf);
if (devfsadm_enumerate_int(path, 0, &buf, rules, 1)) {
return (DEVFSADM_CONTINUE);
}
(void) snprintf(path, sizeof (path), "ecpp%s", buf);
free(buf);
(void) devfsadm_mklink(path, node, minor, 0);
return (DEVFSADM_CONTINUE);
}
/* Rules for memory controller */
static devfsadm_enumerate_t mc_rules[1] =
{"^mc$/^mc([0-9]+)$", 1, MATCH_ALL};
static int
mc_node(di_minor_t minor, di_node_t node)
{
char path[PATH_MAX], l_path[PATH_MAX], *buf, *devfspath;
char *minor_nm;
minor_nm = di_minor_name(minor);
if (minor_nm == NULL) {
return (DEVFSADM_CONTINUE);
}
devfspath = di_devfs_path(node);
(void) strcpy(path, devfspath);
(void) strcat(path, ":");
(void) strcat(path, minor_nm);
di_devfs_path_free(devfspath);
/* build the physical path from the components */
if (devfsadm_enumerate_int(path, 0, &buf, mc_rules, 1)) {
return (DEVFSADM_CONTINUE);
}
(void) strcpy(l_path, "mc/mc");
(void) strcat(l_path, buf);
free(buf);
(void) devfsadm_mklink(l_path, node, minor, 0);
return (DEVFSADM_CONTINUE);
}
/*
* This function is called for Smartcard card reader nodes
* Handles minor node type "ddi_smartcard_reader"
* type=ddi_smartcard_reader;name=card-reader scmi2c\N0
* Calls enumerate to assign logical card-reader id and then
* devfsadm_mklink to make the link.
*/
static int
ddi_cardreader(di_minor_t minor, di_node_t node)
{
char p_path[PATH_MAX +1], l_path[PATH_MAX +1];
char *buf;
char *ptr;
char *nn, *mn;
devfsadm_enumerate_t rules[1] = {"^scmi2c([0-9]+)$", 1, MATCH_ALL};
nn = di_node_name(node);
if (strcmp(nn, "card-reader")) {
return (DEVFSADM_CONTINUE);
}
if (NULL == (ptr = di_devfs_path(node))) {
return (DEVFSADM_CONTINUE);
}
(void) strcpy(p_path, ptr);
(void) strcat(p_path, ":");
mn = di_minor_name(minor);
(void) strcat(p_path, mn);
di_devfs_path_free(ptr);
if (devfsadm_enumerate_int(p_path, 0, &buf, rules, 1)) {
return (DEVFSADM_CONTINUE);
}
(void) snprintf(l_path, sizeof (l_path), "scmi2c%s", buf);
free(buf);
(void) devfsadm_mklink(l_path, node, minor, 0);
return (DEVFSADM_CONTINUE);
}
/*
* Starcat sbbc node. We only really care about generating a /dev
* link for the lone sbbc on the SC (as opposed to the potentially
* numerous sbbcs on the domain), so only operate on instance 0.
*/
static int
starcat_sbbc_node(di_minor_t minor, di_node_t node)
{
char *mn;
if (di_instance(node) == 0) {
mn = di_minor_name(minor);
(void) devfsadm_mklink(mn, node, minor, 0);
}
return (DEVFSADM_CONTINUE);
}
int
wrsm(di_minor_t minor, di_node_t node)
{
const char *node_name = di_node_name(node);
const char *minor_name = di_minor_name(minor);
char path[PATH_MAX + 1];
if (minor_name == NULL || node_name == NULL) {
return (DEVFSADM_CONTINUE);
}
if (strcmp(minor_name, "admin") == 0) {
/* admin pseudo device */
(void) snprintf(path, sizeof (path), "%s%s", node_name,
minor_name);
} else if (strcmp(minor_name, "ctrl") == 0) {
/* controller pseudo device */
dev_t dev = di_minor_devt(minor);
minor_t dev_minor = minor(dev);
(void) snprintf(path, sizeof (path), "%s%u", node_name,
(uint_t)dev_minor);
} else {
/*
* For hardware devices, the devlink must be
* /dev/<node_name><portid>. devpath is of the format
* ".../<node_name>@<portid>,0". Need to extract the
* <portid> for use in bulding devlink.
*/
char devpath[PATH_MAX + 1];
char *devfs_path;
int i;
devfs_path = di_devfs_path(node);
if (devfs_path == NULL) {
return (DEVFSADM_CONTINUE);
}
(void) strcpy(devpath, devfs_path);
di_devfs_path_free(devfs_path);
for (i = strlen(devpath); devpath[i] != '@' && i > 0; i--) {
if (devpath[i] == ',') {
devpath[i] = 0;
}
}
if (i == 0) {
return (DEVFSADM_CONTINUE);
}
(void) snprintf(path, sizeof (path), "wci%s", &devpath[i+1]);
}
(void) devfsadm_mklink(path, node, minor, 0);
return (DEVFSADM_CONTINUE);
}
/*
* Creates /dev/lom nodes for Platform Specific lom driver
*/
static int
lom(di_minor_t minor, di_node_t node)
{
(void) devfsadm_mklink("lom", node, minor, 0);
return (DEVFSADM_CONTINUE);
}
/*
* Creates /dev/ntwdt nodes for Platform Specific ntwdt driver
*/
static int
ntwdt_create(di_minor_t minor, di_node_t node)
{
(void) devfsadm_mklink("ntwdt", node, minor, 0);
return (DEVFSADM_CONTINUE);
}
|