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
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.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 #include <libdevinfo.h>
32 #include <sys/sunddi.h>
33 #include <sys/types.h>
34 #include <sys/scsi/conf/autoconf.h>
36 #include "libdiskmgt.h"
37 #include "disks_private.h"
39 static descriptor_t
**get_assoc_buses(descriptor_t
*desc
, int *errp
);
40 static descriptor_t
**get_assoc_controllers(descriptor_t
*desc
, int *errp
);
43 bus_get_assoc_descriptors(descriptor_t
*desc
, dm_desc_type_t type
, int *errp
)
47 return (get_assoc_buses(desc
, errp
));
49 return (get_assoc_controllers(desc
, errp
));
57 bus_get_attributes(descriptor_t
*dp
, int *errp
)
62 if (nvlist_alloc(&attrs
, NVATTRS
, 0) != 0) {
69 if (nvlist_add_string(attrs
, DM_BTYPE
, bp
->btype
) != 0) {
76 if (nvlist_add_uint32(attrs
, DM_CLOCK
, bp
->freq
) != 0) {
83 if (bp
->pname
!= NULL
) {
84 if (nvlist_add_string(attrs
, DM_PNAME
, bp
->pname
) != 0) {
96 bus_get_descriptor_by_name(char *name
, int *errp
)
100 descriptor_t
*bus
= NULL
;
102 buses
= cache_get_descriptors(DM_BUS
, errp
);
107 for (i
= 0; buses
[i
]; i
++) {
108 if (libdiskmgt_str_eq(name
, buses
[i
]->p
.bus
->name
)) {
111 /* clean up the unused descriptors */
112 cache_free_descriptor(buses
[i
]);
126 bus_get_descriptors(int filter
[], int *errp
)
128 return (cache_get_descriptors(DM_BUS
, errp
));
132 bus_get_name(descriptor_t
*desc
)
134 return (desc
->p
.bus
->name
);
139 bus_get_stats(descriptor_t
*dp
, int stat_type
, int *errp
)
141 /* There are no stat types defined for controllers */
147 bus_make_descriptors()
152 bp
= cache_get_buslist();
154 cache_load_desc(DM_BUS
, bp
, NULL
, NULL
, &error
);
164 static descriptor_t
**
165 get_assoc_buses(descriptor_t
*desc
, int *errp
)
169 descriptor_t
**allbuses
;
170 descriptor_t
**buses
;
178 allbuses
= cache_get_descriptors(DM_BUS
, errp
);
183 /* Count how many we have (we overcount, but thats ok). */
184 for (cnt
= 0; allbuses
[cnt
]; cnt
++);
186 /* make the snapshot */
187 buses
= (descriptor_t
**)calloc(cnt
+ 1, sizeof (descriptor_t
*));
190 cache_free_descriptors(allbuses
);
195 * Get this buses parent bus and get the buses that I am the parent of.
198 for (i
= 0; allbuses
[i
]; i
++) {
199 if (libdiskmgt_str_eq(name
, allbuses
[i
]->p
.bus
->pname
)) {
200 buses
[pos
++] = allbuses
[i
];
201 } else if (bp
->pname
!= NULL
&&
202 libdiskmgt_str_eq(bp
->pname
, allbuses
[i
]->p
.bus
->name
)) {
204 buses
[pos
++] = allbuses
[i
];
206 /* clean up the unused descriptor */
207 cache_free_descriptor(allbuses
[i
]);
218 static descriptor_t
**
219 get_assoc_controllers(descriptor_t
*desc
, int *errp
)
222 descriptor_t
**controllers
;
228 /* Count how many we have. */
229 for (cnt
= 0; bp
->controllers
[cnt
]; cnt
++);
231 /* make the snapshot */
232 controllers
= (descriptor_t
**)calloc(cnt
+ 1, sizeof (descriptor_t
*));
233 if (controllers
== NULL
) {
238 for (i
= 0; bp
->controllers
[i
]; i
++) {
239 controllers
[i
] = cache_get_desc(DM_CONTROLLER
, bp
->controllers
[i
],
242 cache_free_descriptors(controllers
);
246 controllers
[i
] = NULL
;
249 return (controllers
);