summaryrefslogtreecommitdiff
path: root/usr/src/man/man9f/ddi_devid_compare.9f
blob: 085d455a8d4cb1cd6d1e5d4029942ed9f620b393 (plain)
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
'\" te
.\"  Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
.\" 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]
.TH DDI_DEVID_COMPARE 9F "May 21, 2009"
.SH NAME
ddi_devid_compare, ddi_devid_free, ddi_devid_init, ddi_devid_register,
ddi_devid_sizeof, ddi_devid_str_decode, ddi_devid_str_encode,
ddi_devid_str_free, ddi_devid_get, ddi_devid_unregister, ddi_devid_valid \-
kernel interfaces for device ids
.SH SYNOPSIS
.LP
.nf
\fBint\fR \fBddi_devid_compare\fR(\fBddi_devid_t\fR \fIdevid1\fR, \fBddi_devid_t\fR \fIdevid2\fR);
.fi

.LP
.nf
\fBsize_t\fR \fBddi_devid_sizeof\fR(\fBddi_devid_t\fR \fIdevid\fR);
.fi

.LP
.nf
\fBint\fR \fBddi_devid_init\fR(\fBdev_info_t *\fR\fIdip\fR, \fBushort_t\fR \fIdevid_type\fR,
     \fBushort_t\fR \fInbytes\fR, \fBvoid *\fR\fIid\fR, \fBddi_devid_t *\fR\fIretdevid\fR);
.fi

.LP
.nf
\fBvoid\fR \fBddi_devid_free\fR(\fBddi_devid_t\fR \fIdevid\fR);
.fi

.LP
.nf
\fBint\fR \fBddi_devid_register\fR(\fBdev_info_t *\fR\fIdip\fR, \fBddi_devid_t\fR \fIdevid\fR);
.fi

.LP
.nf
\fBint\fR \fBddi_devid_str_decode\fR(\fBchar *\fR\fIdevidstr\fR, \fBddi_devid_t *\fR\fIretdevid\fR,
     \fBchar **\fR\fIretminor_name\fR);
.fi

.LP
.nf
\fBint\fR \fBddi_devid_str_encode\fR(\fBddi_devid_t\fR \fIdevid\fR, \fBchar *\fR\fIminor_name\fR);
.fi

.LP
.nf
\fBint\fR \fBddi_devid_str_free\fR(\fBchar *\fR\fIdevidstr\fR);
.fi

.LP
.nf
\fBint\fR \fBddi_devid_get\fR(\fBdev_info_t *\fR\fIdip\fR, \fBddi_devid_t *\fR\fIretdevid\fR);
.fi

.LP
.nf
\fBvoid\fR \fBddi_devid_unregister\fR(\fBdev_info_t *\fR\fIdip\fR);
.fi

.LP
.nf
\fBint\fR \fBddi_devid_valid\fR(\fBddi_devid_t\fR \fIdevid\fR);
.fi

.SH PARAMETERS
.sp
.ne 2
.na
\fB\fIdevid\fR\fR
.ad
.RS 14n
The device id address.
.RE

.sp
.ne 2
.na
\fB\fIdevidstr\fR\fR
.ad
.RS 14n
The \fIdevid\fR and \fIminor_name\fR represented as a string.
.RE

.sp
.ne 2
.na
\fB\fIdevid1\fR\fR
.ad
.RS 14n
The first of two device id addresses to be compared calling
\fBddi_devid_compare()\fR.
.RE

.sp
.ne 2
.na
\fB\fIdevid2\fR\fR
.ad
.RS 14n
The second of two device id addresses to be compared calling
\fBddi_devid_compare()\fR.
.RE

.sp
.ne 2
.na
\fB\fIdip\fR\fR
.ad
.RS 14n
A \fBdev_info\fR pointer, which identifies the device.
.RE

.sp
.ne 2
.na
\fB\fIdevid_type\fR\fR
.ad
.RS 14n
The following device id types may be accepted by the \fBddi_devid_init()\fR
function:
.sp
.ne 2
.na
\fB\fBDEVID_SCSI3_WWN\fR\fR
.ad
.RS 21n
World Wide Name associated with SCSI-3 devices.
.RE

.sp
.ne 2
.na
\fB\fBDEVID_SCSI_SERIAL\fR\fR
.ad
.RS 21n
Vendor \fBID\fRand serial number associated with a SCSI device. Note: This may
only be used if known to be unique; otherwise a fabricated device id must be
used.
.RE

.sp
.ne 2
.na
\fB\fBDEVID_ENCAP\fR\fR
.ad
.RS 21n
Device \fBID\fR of another device. This is for layered device driver usage.
.RE

.sp
.ne 2
.na
\fB\fBDEVID_FAB\fR\fR
.ad
.RS 21n
Fabricated device \fBID\fR.
.RE

.RE

.sp
.ne 2
.na
\fB\fIminor_name\fR\fR
.ad
.RS 17n
The minor name to be encoded.
.RE

.sp
.ne 2
.na
\fB\fInbytes\fR\fR
.ad
.RS 17n
The length in bytes of device \fBID\fR.
.RE

.sp
.ne 2
.na
\fB\fIretdevid\fR\fR
.ad
.RS 17n
The return address of the device \fBID\fR.
.RE

.sp
.ne 2
.na
\fB\fIretminor_name\fR\fR
.ad
.RS 17n
The return address of a minor name. Free string with
\fBddi_devid_str_free()\fR.
.RE

.SH INTERFACE LEVEL
.sp
.LP
Solaris DDI specific (Solaris DDI).
.SH DESCRIPTION
.sp
.LP
The following routines are used to provide unique identifiers, device
\fBID\fRs, for devices. Specifically, kernel modules use these interfaces to
identify and locate devices, independent of the device's physical connection or
its logical device name or number.
.sp
.LP
\fBddi_devid_compare()\fR compares two device \fBID\fRs byte-by-byte and
determines both equality and sort order.
.sp
.LP
\fBddi_devid_sizeof()\fR returns the number of bytes allocated for the passed
in device \fBID\fR (\fIdevid\fR).
.sp
.LP
\fBddi_devid_init()\fR allocates memory and initializes the opaque device
\fBID\fR structure. This function does not store the \fIdevid\fR. If the device
id is not derived from the device's firmware, it is the driver's responsibility
to store the \fIdevid\fR on some reliable store. When a \fIdevid_type\fR of
either \fBDEVID_SCSI3_WWN,\fR \fBDEVID_SCSI_SERIAL\fR, or \fBDEVID_ENCAP\fR is
accepted, an array of bytes (\fIid\fR) must be passed in (\fInbytes\fR).
.sp
.LP
When the \fIdevid_type\fR \fBDEVID_FAB\fR is used, the array of bytes
(\fIid\fR) must be \fBNULL\fR and the length (\fInbytes\fR) must be zero. The
fabricated device ids, \fBDEVID_FAB\fR will be initialized with the machine's
host id and a timestamp.
.sp
.LP
Drivers must free the memory allocated by this function, using the
\fBddi_devid_free()\fR function.
.sp
.LP
\fBddi_devid_free()\fR frees the memory allocated for the returned \fIdevid\fR
by the \fBddi_devid_init()\fR and \fBdevid_str_decode()\fR functions.
.sp
.LP
\fBddi_devid_register()\fR registers the device \fBID\fR address (\fIdevid\fR)
with the \fBDDI\fR framework, associating it with the \fBdev_info\fR passed in
(\fIdip\fR). The drivers must register device \fBID\fRs at attach time. See
\fBattach\fR(9E).
.sp
.LP
\fBddi_devid_unregister()\fR removes the device \fBID\fR address from the
\fBdev_info\fR passed in (\fIdip\fR). Drivers must use this function to
unregister the device \fBID\fR when devices are being detached. This function
does not free the space allocated for the device \fBID\fR. The driver must free
the space allocated for the device \fBID\fR, using the \fBddi_devid_free()\fR
function. See \fBdetach\fR(9E).
.sp
.LP
\fBddi_devid_valid()\fR validates the device \fBID\fR (\fIdevid\fR) passed in.
The driver must use this function to validate any fabricated device \fBID\fR
that has been stored on a device.
.sp
.LP
The \fBddi_devid_get()\fR function returns a pointer to the device ID structure
through \fIretdevid\fR if there is already a registered device ID associated
with the \fBdev_info\fR node. A driver can use this interface to check and get
the device ID associated with the \fBdev_info\fR node. It returns
\fBDDI_FAILURE\fR if no device ID is registered for the node.
.sp
.LP
The \fBddi_devid_get()\fR function allocates memory for the opaque device ID
structure and initializes it with the associated device ID and returns the
pointer to it. The driver must free the memory allocated by this function using
the \fBddi_devid_free()\fR function.
.sp
.LP
The \fBddi_devid_str_encode()\fR function encodes a \fIdevid\fR and minor_name
into a null-terminated ASCII string, returning a pointer to that string. If
both a \fIdevid\fR and a \fIminor_name\fR are non-null, then a slash (\fB/\fR)
is used to separate the \fIdevid\fR from the \fIminor_name\fR in the encoded
string. If \fIminor_name\fR is null, then only the \fIdevid\fR is encoded. If
the \fIdevid\fR is null, then the special string \fBid0\fR is returned. Note
that you cannot compare the returned string against another string with
\fBstrcmp()\fR to determine \fIdevid\fR equality. The returned string must be
freed by calling \fBdevid_str_free()\fR.
.sp
.LP
The \fBddi_devid_str_decode()\fR function takes a string previously produced by
the \fBdevid_str_encode\fR(3DEVID) or \fBddi_devid_str_encode()\fR function and
decodes the contained device ID and minor_name, allocating and returning
pointers to the extracted parts through the \fIretdevid\fR and
\fIretminor_name\fR arguments. If the special \fIdevidstr\fR \fBid0\fR was
specified then the returned device ID and minor name will both be null. A
non-null returned \fIdevid\fR must be freed by the caller through the
\fBddi_devid_free()\fR function. A non-null returned minor name must be freed
by calling \fBddi_devid_str_free()\fR.
.sp
.LP
The \fBddi_devid_str_free()\fR function is used to free all strings returned by
the \fBddi_devid\fR functions (the \fBddi_devid_str_encode()\fR function return
value and the returned \fIretminor_name\fR argument).
.SH RETURN VALUES
.sp
.LP
\fBddi_devid_init()\fR returns the following values:
.sp
.ne 2
.na
\fB \fR
.ad
.RS 5n
.sp
.ne 2
.na
\fB\fBDDI_SUCCESS\fR\fR
.ad
.RS 15n
Success.
.RE

.sp
.ne 2
.na
\fB\fBDDI_FAILURE\fR\fR
.ad
.RS 15n
Out of memory. An invalid \fIdevid_type\fR was passed in.
.RE

.RE

.sp
.LP
\fBddi_devid_valid()\fR returns the following values:
.sp
.ne 2
.na
\fB \fR
.ad
.RS 5n
.sp
.ne 2
.na
\fB\fBDDI_SUCCESS\fR\fR
.ad
.RS 15n
Valid device \fBID\fR.
.RE

.sp
.ne 2
.na
\fB\fBDDI_FAILURE\fR\fR
.ad
.RS 15n
Invalid device \fBID\fR.
.RE

.RE

.sp
.LP
\fBddi_devid_register()\fR returns the following values:
.sp
.ne 2
.na
\fB \fR
.ad
.RS 5n
.sp
.ne 2
.na
\fB\fBDDI_SUCCESS\fR\fR
.ad
.RS 15n
Success.
.RE

.sp
.ne 2
.na
\fB\fBDDI_FAILURE\fR\fR
.ad
.RS 15n
Failure. The device \fBID\fR is already registered or the device \fBID\fR is
invalid.
.RE

.RE

.sp
.LP
\fBddi_devid_valid()\fR returns the following values:
.sp
.ne 2
.na
\fB \fR
.ad
.RS 5n
.sp
.ne 2
.na
\fB\fBDDI_SUCCESS\fR\fR
.ad
.RS 15n
Valid device \fBID\fR.
.RE

.sp
.ne 2
.na
\fB\fBDDI_FAILURE\fR\fR
.ad
.RS 15n
Invalid device \fBID\fR.
.RE

.RE

.sp
.LP
\fBddi_devid_get()\fR returns the following values:
.sp
.ne 2
.na
\fB \fR
.ad
.RS 5n
.sp
.ne 2
.na
\fB\fBDDI_SUCCESS\fR\fR
.ad
.RS 15n
Device \fBID\fR is present and a pointer to it is returned in \fIretdevid\fR.
.RE

.sp
.ne 2
.na
\fB\fBDDI_FAILURE\fR\fR
.ad
.RS 15n
No device \fBID\fR is defined for this \fBdev_info\fR node.
.RE

.RE

.sp
.LP
\fBddi_devid_compare()\fR returns the following values:
.sp
.ne 2
.na
\fB \fR
.ad
.RS 5n
.sp
.ne 2
.na
\fB\fB\(mi1\fR\fR
.ad
.RS 9n
The first device ID is less than the second device ID.
.RE

.sp
.ne 2
.na
\fB\fB0\fR\fR
.ad
.RS 9n
The first device ID is equal to the second device ID.
.RE

.sp
.ne 2
.na
\fB\fB1\fR\fR
.ad
.RS 9n
The first device ID is greater than the second device ID.
.RE

.RE

.sp
.LP
\fBddi_devid_sizeof()\fR returns the size of the \fIdevid\fR in bytes. If
called with a null, then the number of bytes that must be allocated and
initialized to determine the size of a complete device ID is returned.
.sp
.LP
\fBddi_devid_str_encode()\fR returns a value of null to indicate failure.
Failure can be caused by attempting to encode an invalid \fIdevid\fR. If the
return value is non-null then the caller must free the returned string by using
the \fBdevid_str_free()\fR function.
.sp
.LP
\fBddi_devid_str_decode()\fR returns the following values:
.sp
.ne 2
.na
\fB \fR
.ad
.RS 5n
.sp
.ne 2
.na
\fB\fBDDI_SUCCESS\fR\fR
.ad
.RS 15n
Success.
.RE

.sp
.ne 2
.na
\fB\fBDDI_FAILURE\fR\fR
.ad
.RS 15n
Failure; the \fIdevidstr\fR string was not valid.
.RE

.RE

.SH CONTEXT
.sp
.LP
These functions can be called from a user or kernel context.
.SH SEE ALSO
.sp
.LP
\fBdevid_get\fR(3DEVID), , \fBlibdevid\fR(3LIB), \fBattributes\fR(5),
\fBattach\fR(9E), \fBdetach\fR(9E), \fBkmem_free\fR(9F)
.sp
.LP
\fIWriting Device Drivers\fR