1 | /* |
---|
2 | * RTEMS Monitor "object" support. |
---|
3 | * |
---|
4 | * Used to traverse object lists and print them out. |
---|
5 | * An object can be an RTEMS object (chain based stuff) or |
---|
6 | * a "misc" object such as a device driver. |
---|
7 | * |
---|
8 | * Each object has its own file in this directory (eg: extension.c) |
---|
9 | * That file provides routines to convert a "native" structure |
---|
10 | * to its canonical form, print a canonical structure, etc. |
---|
11 | * |
---|
12 | * TODO: |
---|
13 | * should allow for non-numeric id's??? |
---|
14 | * |
---|
15 | * $Id$ |
---|
16 | */ |
---|
17 | |
---|
18 | #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ |
---|
19 | #include <rtems.h> |
---|
20 | #include "monitor.h" |
---|
21 | |
---|
22 | #include <stdio.h> |
---|
23 | #include <stdlib.h> /* strtoul() */ |
---|
24 | #include <string.h> /* memcpy() */ |
---|
25 | |
---|
26 | #include <monitor.h> |
---|
27 | |
---|
28 | #define NUMELEMS(arr) (sizeof(arr) / sizeof(arr[0])) |
---|
29 | |
---|
30 | /* |
---|
31 | * add: |
---|
32 | * next |
---|
33 | */ |
---|
34 | |
---|
35 | rtems_monitor_object_info_t rtems_monitor_object_info[] = |
---|
36 | { |
---|
37 | { RTEMS_MONITOR_OBJECT_CONFIG, |
---|
38 | (void *) 0, |
---|
39 | sizeof(rtems_monitor_config_t), |
---|
40 | (rtems_monitor_object_next_fn) rtems_monitor_config_next, |
---|
41 | (rtems_monitor_object_canonical_fn) rtems_monitor_config_canonical, |
---|
42 | (rtems_monitor_object_dump_header_fn) rtems_monitor_config_dump_header, |
---|
43 | (rtems_monitor_object_dump_fn) rtems_monitor_config_dump, |
---|
44 | }, |
---|
45 | { RTEMS_MONITOR_OBJECT_MPCI, |
---|
46 | (void *) 0, |
---|
47 | sizeof(rtems_monitor_mpci_t), |
---|
48 | (rtems_monitor_object_next_fn) rtems_monitor_mpci_next, |
---|
49 | (rtems_monitor_object_canonical_fn) rtems_monitor_mpci_canonical, |
---|
50 | (rtems_monitor_object_dump_header_fn) rtems_monitor_mpci_dump_header, |
---|
51 | (rtems_monitor_object_dump_fn) rtems_monitor_mpci_dump, |
---|
52 | }, |
---|
53 | { RTEMS_MONITOR_OBJECT_INIT_TASK, |
---|
54 | (void *) 0, |
---|
55 | sizeof(rtems_monitor_init_task_t), |
---|
56 | (rtems_monitor_object_next_fn) rtems_monitor_init_task_next, |
---|
57 | (rtems_monitor_object_canonical_fn) rtems_monitor_init_task_canonical, |
---|
58 | (rtems_monitor_object_dump_header_fn) rtems_monitor_init_task_dump_header, |
---|
59 | (rtems_monitor_object_dump_fn) rtems_monitor_init_task_dump, |
---|
60 | }, |
---|
61 | { RTEMS_MONITOR_OBJECT_TASK, |
---|
62 | (void *) &_RTEMS_tasks_Information, |
---|
63 | sizeof(rtems_monitor_task_t), |
---|
64 | (rtems_monitor_object_next_fn) rtems_monitor_manager_next, |
---|
65 | (rtems_monitor_object_canonical_fn) rtems_monitor_task_canonical, |
---|
66 | (rtems_monitor_object_dump_header_fn) rtems_monitor_task_dump_header, |
---|
67 | (rtems_monitor_object_dump_fn) rtems_monitor_task_dump, |
---|
68 | }, |
---|
69 | { RTEMS_MONITOR_OBJECT_QUEUE, |
---|
70 | (void *) &_Message_queue_Information, |
---|
71 | sizeof(rtems_monitor_queue_t), |
---|
72 | (rtems_monitor_object_next_fn) rtems_monitor_manager_next, |
---|
73 | (rtems_monitor_object_canonical_fn) rtems_monitor_queue_canonical, |
---|
74 | (rtems_monitor_object_dump_header_fn) rtems_monitor_queue_dump_header, |
---|
75 | (rtems_monitor_object_dump_fn) rtems_monitor_queue_dump, |
---|
76 | }, |
---|
77 | { RTEMS_MONITOR_OBJECT_EXTENSION, |
---|
78 | (void *) &_Extension_Information, |
---|
79 | sizeof(rtems_monitor_extension_t), |
---|
80 | (rtems_monitor_object_next_fn) rtems_monitor_manager_next, |
---|
81 | (rtems_monitor_object_canonical_fn) rtems_monitor_extension_canonical, |
---|
82 | (rtems_monitor_object_dump_header_fn) rtems_monitor_extension_dump_header, |
---|
83 | (rtems_monitor_object_dump_fn) rtems_monitor_extension_dump, |
---|
84 | }, |
---|
85 | { RTEMS_MONITOR_OBJECT_DRIVER, |
---|
86 | (void *) 0, |
---|
87 | sizeof(rtems_monitor_driver_t), |
---|
88 | (rtems_monitor_object_next_fn) rtems_monitor_driver_next, |
---|
89 | (rtems_monitor_object_canonical_fn) rtems_monitor_driver_canonical, |
---|
90 | (rtems_monitor_object_dump_header_fn) rtems_monitor_driver_dump_header, |
---|
91 | (rtems_monitor_object_dump_fn) rtems_monitor_driver_dump, |
---|
92 | }, |
---|
93 | { RTEMS_MONITOR_OBJECT_DNAME, |
---|
94 | /* XXX now that the driver name table is allocated from the */ |
---|
95 | /* XXX Workspace, this does not work */ |
---|
96 | (void *) 0, |
---|
97 | /* (void *) _IO_Driver_name_table, */ |
---|
98 | sizeof(rtems_monitor_dname_t), |
---|
99 | (rtems_monitor_object_next_fn) rtems_monitor_dname_next, |
---|
100 | (rtems_monitor_object_canonical_fn) rtems_monitor_dname_canonical, |
---|
101 | (rtems_monitor_object_dump_header_fn) rtems_monitor_dname_dump_header, |
---|
102 | (rtems_monitor_object_dump_fn) rtems_monitor_dname_dump, |
---|
103 | }, |
---|
104 | }; |
---|
105 | |
---|
106 | /* |
---|
107 | * Allow id's to be specified without the node number or |
---|
108 | * type for convenience. |
---|
109 | */ |
---|
110 | |
---|
111 | rtems_id |
---|
112 | rtems_monitor_id_fixup( |
---|
113 | rtems_id id, |
---|
114 | unsigned32 default_node, |
---|
115 | rtems_monitor_object_type_t type |
---|
116 | ) |
---|
117 | { |
---|
118 | unsigned32 node; |
---|
119 | |
---|
120 | node = rtems_get_node(id); |
---|
121 | if (node == 0) |
---|
122 | { |
---|
123 | if (rtems_get_class(id) != OBJECTS_NO_CLASS) |
---|
124 | type = rtems_get_class(id); |
---|
125 | |
---|
126 | id = _Objects_Build_id(type, default_node, rtems_get_index(id)); |
---|
127 | } |
---|
128 | return id; |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | rtems_monitor_object_info_t * |
---|
133 | rtems_monitor_object_lookup( |
---|
134 | rtems_monitor_object_type_t type |
---|
135 | ) |
---|
136 | { |
---|
137 | rtems_monitor_object_info_t *p; |
---|
138 | for (p = &rtems_monitor_object_info[0]; |
---|
139 | p < &rtems_monitor_object_info[NUMELEMS(rtems_monitor_object_info)]; |
---|
140 | p++) |
---|
141 | { |
---|
142 | if (p->type == type) |
---|
143 | return p; |
---|
144 | } |
---|
145 | return 0; |
---|
146 | } |
---|
147 | |
---|
148 | rtems_id |
---|
149 | rtems_monitor_object_canonical_next_remote( |
---|
150 | rtems_monitor_object_type_t type, |
---|
151 | rtems_id id, |
---|
152 | void *canonical |
---|
153 | ) |
---|
154 | { |
---|
155 | rtems_id next_id; |
---|
156 | rtems_status_code status; |
---|
157 | rtems_monitor_server_request_t request; |
---|
158 | rtems_monitor_server_response_t response; |
---|
159 | |
---|
160 | /* |
---|
161 | * Send request |
---|
162 | */ |
---|
163 | |
---|
164 | request.command = RTEMS_MONITOR_SERVER_CANONICAL; |
---|
165 | request.argument0 = (unsigned32) type; |
---|
166 | request.argument1 = (unsigned32) id; |
---|
167 | |
---|
168 | status = rtems_monitor_server_request(rtems_get_node(id), &request, &response); |
---|
169 | if (status != RTEMS_SUCCESSFUL) |
---|
170 | goto failed; |
---|
171 | |
---|
172 | /* |
---|
173 | * process response |
---|
174 | */ |
---|
175 | |
---|
176 | next_id = (rtems_id) response.result0; |
---|
177 | if (next_id != RTEMS_OBJECT_ID_FINAL) |
---|
178 | (void) memcpy(canonical, &response.payload, response.result1); |
---|
179 | |
---|
180 | return next_id; |
---|
181 | |
---|
182 | failed: |
---|
183 | return RTEMS_OBJECT_ID_FINAL; |
---|
184 | |
---|
185 | } |
---|
186 | |
---|
187 | |
---|
188 | rtems_id |
---|
189 | rtems_monitor_object_canonical_next( |
---|
190 | rtems_monitor_object_info_t *info, |
---|
191 | rtems_id id, |
---|
192 | void *canonical |
---|
193 | ) |
---|
194 | { |
---|
195 | rtems_id next_id; |
---|
196 | void *raw_item; |
---|
197 | |
---|
198 | if ( ! _Objects_Is_local_id(id)) |
---|
199 | next_id = rtems_monitor_object_canonical_next_remote(info->type, |
---|
200 | id, |
---|
201 | canonical); |
---|
202 | else |
---|
203 | { |
---|
204 | next_id = id; |
---|
205 | |
---|
206 | raw_item = (void *) info->next(info->object_information, |
---|
207 | canonical, |
---|
208 | &next_id); |
---|
209 | |
---|
210 | if (raw_item) |
---|
211 | { |
---|
212 | info->canonical(canonical, raw_item); |
---|
213 | _Thread_Enable_dispatch(); |
---|
214 | } |
---|
215 | } |
---|
216 | return next_id; |
---|
217 | } |
---|
218 | |
---|
219 | |
---|
220 | /* |
---|
221 | * this is routine server invokes locally to get the type |
---|
222 | */ |
---|
223 | |
---|
224 | rtems_id |
---|
225 | rtems_monitor_object_canonical_get( |
---|
226 | rtems_monitor_object_type_t type, |
---|
227 | rtems_id id, |
---|
228 | void *canonical, |
---|
229 | unsigned32 *size_p |
---|
230 | ) |
---|
231 | { |
---|
232 | rtems_monitor_object_info_t *info; |
---|
233 | rtems_id next_id; |
---|
234 | |
---|
235 | *size_p = 0; |
---|
236 | |
---|
237 | info = rtems_monitor_object_lookup(type); |
---|
238 | |
---|
239 | if (info == 0) |
---|
240 | return RTEMS_OBJECT_ID_FINAL; |
---|
241 | |
---|
242 | next_id = rtems_monitor_object_canonical_next(info, id, canonical); |
---|
243 | *size_p = info->size; |
---|
244 | |
---|
245 | return next_id; |
---|
246 | } |
---|
247 | |
---|
248 | |
---|
249 | void |
---|
250 | rtems_monitor_object_dump_1( |
---|
251 | rtems_monitor_object_info_t *info, |
---|
252 | rtems_id id, |
---|
253 | boolean verbose |
---|
254 | ) |
---|
255 | { |
---|
256 | rtems_id next_id; |
---|
257 | rtems_monitor_union_t canonical; |
---|
258 | |
---|
259 | if ((next_id = rtems_monitor_object_canonical_next( |
---|
260 | info, |
---|
261 | id, |
---|
262 | &canonical)) != RTEMS_OBJECT_ID_FINAL) |
---|
263 | { |
---|
264 | /* |
---|
265 | * If the one we actually got is the one we wanted, then |
---|
266 | * print it out. |
---|
267 | * For ones that have an id field, this works fine, |
---|
268 | * for all others, always dump it out. |
---|
269 | * |
---|
270 | * HACK: the way we determine whether there is an id is a hack. |
---|
271 | * |
---|
272 | * by the way: the reason we try to not have an id, is that some |
---|
273 | * of the canonical structures are almost too big for shared |
---|
274 | * memory driver (eg: mpci) |
---|
275 | */ |
---|
276 | |
---|
277 | if ((info->next != rtems_monitor_manager_next) || |
---|
278 | (id == canonical.generic.id)) |
---|
279 | info->dump(&canonical, verbose); |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | void |
---|
284 | rtems_monitor_object_dump_all( |
---|
285 | rtems_monitor_object_info_t *info, |
---|
286 | boolean verbose |
---|
287 | ) |
---|
288 | { |
---|
289 | rtems_id next_id; |
---|
290 | rtems_monitor_union_t canonical; |
---|
291 | |
---|
292 | next_id = RTEMS_OBJECT_ID_INITIAL(info->type, rtems_monitor_default_node); |
---|
293 | |
---|
294 | while ((next_id = rtems_monitor_object_canonical_next( |
---|
295 | info, |
---|
296 | next_id, |
---|
297 | &canonical)) != RTEMS_OBJECT_ID_FINAL) |
---|
298 | { |
---|
299 | info->dump(&canonical, verbose); |
---|
300 | } |
---|
301 | } |
---|
302 | |
---|
303 | void |
---|
304 | rtems_monitor_object_cmd( |
---|
305 | int argc, |
---|
306 | char **argv, |
---|
307 | unsigned32 command_arg, |
---|
308 | boolean verbose |
---|
309 | ) |
---|
310 | { |
---|
311 | int arg; |
---|
312 | rtems_monitor_object_info_t *info = 0; |
---|
313 | rtems_monitor_object_type_t type = (rtems_monitor_object_type_t) command_arg; |
---|
314 | |
---|
315 | /* what is the default type? */ |
---|
316 | type = (rtems_monitor_object_type_t) command_arg; |
---|
317 | |
---|
318 | if (argc == 1) |
---|
319 | { |
---|
320 | if (type == RTEMS_MONITOR_OBJECT_INVALID) |
---|
321 | { |
---|
322 | printf("A type must be specified to \"dump all\"\n"); |
---|
323 | goto done; |
---|
324 | } |
---|
325 | |
---|
326 | info = rtems_monitor_object_lookup(type); |
---|
327 | if (info == 0) |
---|
328 | goto not_found; |
---|
329 | |
---|
330 | if (info->dump_header) |
---|
331 | info->dump_header(verbose); |
---|
332 | rtems_monitor_object_dump_all(info, verbose); |
---|
333 | } |
---|
334 | else |
---|
335 | { |
---|
336 | unsigned32 default_node = rtems_monitor_default_node; |
---|
337 | rtems_monitor_object_type_t last_type = RTEMS_MONITOR_OBJECT_INVALID; |
---|
338 | rtems_id id; |
---|
339 | |
---|
340 | for (arg=1; argv[arg]; arg++) |
---|
341 | { |
---|
342 | id = (rtems_id) strtoul(argv[arg], 0, 16); |
---|
343 | id = rtems_monitor_id_fixup(id, default_node, type); |
---|
344 | type = (rtems_monitor_object_type_t) rtems_get_class(id); |
---|
345 | |
---|
346 | /* |
---|
347 | * Allow the item type to change in the middle |
---|
348 | * of the command. If the type changes, then |
---|
349 | * just dump out a new header and keep on going. |
---|
350 | */ |
---|
351 | if (type != last_type) |
---|
352 | { |
---|
353 | info = rtems_monitor_object_lookup(type); |
---|
354 | if (info == 0) |
---|
355 | goto not_found; |
---|
356 | |
---|
357 | if (info->dump_header) |
---|
358 | info->dump_header(verbose); |
---|
359 | } |
---|
360 | |
---|
361 | if (info == 0) |
---|
362 | { |
---|
363 | not_found: printf("Invalid or unsupported type %d\n", type); |
---|
364 | goto done; |
---|
365 | } |
---|
366 | |
---|
367 | rtems_monitor_object_dump_1(info, id, verbose); |
---|
368 | |
---|
369 | default_node = rtems_get_node(id); |
---|
370 | |
---|
371 | last_type = type; |
---|
372 | } |
---|
373 | } |
---|
374 | done: |
---|
375 | return; |
---|
376 | } |
---|