|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /*
25: * IOConfigTable test. Assumes the presence of driver bundles and a
26: * system bundle in the usual place (currently in /usr/Devices).
27: * Dumps contents of IOConfigTable instances to stdout.
28: */
29:
30: #import <driverkit/IOConfigTable.h>
31: #import <objc/List.h>
32: #import <libc.h>
33:
34: #define TEST_DRIVER_BUNDLE 1
35:
36: typedef enum {All, One, System} Mode;
37:
38: static int reportAll();
39: static int reportOne(const char *driverName, int unitNum);
40: static int reportSystem(int verbose);
41: static int dumpConfigInfo (IOConfigTable *configTable, const char **keys);
42:
43: static char *driverKeys[] = {
44: "Driver Name",
45: "Instance",
46: "Type",
47: "Version",
48: "DMA Channels",
49: "IRQ Levels",
50: "I/O Ports",
51: "Memory Maps",
52: NULL
53: };
54:
55: static char *systemKeys[] = {
56: "Source",
57: "Version",
58: "Machine Name",
59: "Boot Drivers",
60: "Active Drivers",
61: NULL
62: };
63:
64: static char *verboseSystemKeys[] = {
65: "Driver Path",
66: "Bus Type",
67: "Kernel",
68: "Device",
69: "Memory",
70: "Root Device",
71: "Uses FPU",
72: "Memory Used",
73: "User Mode",
74: "Kernel Flags",
75: NULL
76: };
77:
78:
79: static void usage(char **argv) {
80: printf("Usage: \n");
81: printf("\t%s a(ll) -- displays all drivers\n",
82: argv[0]);
83: printf("\t%s d=driverName [unit] -- display one driver\n", argv[0]);
84: printf("\t%s s(ystem) [v] -- display system config "
85: "(verbose)\n", argv[0]);
86: exit(1);
87: }
88:
89: int main(int argc, char **argv)
90: {
91: int verbose = 0;
92: Mode mode;
93: char *driverName;
94: int unitNum;
95:
96: if(argc < 2) {
97: usage(argv);
98: }
99: switch(argv[1][0]) {
100: case 'a':
101: mode = All;
102: break;
103:
104: case 'd':
105: mode = One;
106: driverName = &argv[1][2];
107: switch(argc) {
108: case 2:
109: unitNum = -1; // means 'all instances'
110: break;
111: case 3:
112: unitNum = atoi(argv[2]);
113: break;
114: default:
115: usage(argv);
116: }
117: break;
118:
119: case 's':
120: switch(argc) {
121: case 2:
122: break;
123: case 3:
124: if(argv[2][0] == 'v') {
125: verbose = 1;
126: }
127: else {
128: usage(argv);
129: }
130: break;
131: default:
132: usage(argv);
133: }
134: mode = System;
135: break;
136: default:
137: usage(argv);
138: }
139:
140: switch(mode) {
141: case All:
142: return reportAll();
143: case One:
144: return reportOne(driverName, unitNum);
145: case System:
146: return reportSystem(verbose);
147: }
148: return 0;
149: }
150:
151: static int reportAll()
152: {
153: List *list = [IOConfigTable tablesForInstalledDrivers];
154: int index;
155: IOConfigTable *driverConfig;
156:
157: if(list == nil) {
158: printf("installedDrivers returned nil\n");
159: return 1;
160: }
161: printf("Config Table info (all devices):\n");
162: for(index=0; ; index++) {
163: driverConfig = [list objectAt:index];
164: if(driverConfig == nil) {
165: break;
166: }
167: dumpConfigInfo(driverConfig, driverKeys);
168: printf("\n");
169: }
170: printf("%d Drivers found\n", index);
171: [list free];
172: return 0;
173: }
174:
175: static int doReportOne(const char *driverName, int unitNum)
176: {
177: IOConfigTable *driverConfig;
178: driverConfig = [IOConfigTable newForDriver:driverName unit:unitNum];
179: if(driverConfig == nil) {
180: return 1;
181: }
182: printf("Config Table for %s unit %d\n", driverName, unitNum);
183: dumpConfigInfo(driverConfig, driverKeys);
184:
185: #if TEST_DRIVER_BUNDLE
186: /*
187: * Test -driverBundle...
188: */
189: {
190: id bundle;
191: const char *dir;
192:
193: bundle = [driverConfig driverBundle];
194: if(bundle == nil) {
195: printf("driverBundle returned nil\n");
196: return 1;
197: }
198: dir = [bundle directory];
199: printf(" bundle dir = %s\n", dir);
200: [bundle free];
201: }
202: #endif TEST_DRIVER_BUNDLE
203:
204: [driverConfig free];
205: return 0;
206: }
207:
208: static int reportOne(const char *driverName, int unitNum)
209: {
210: BOOL foundOne;
211:
212: if(unitNum >= 0) {
213: if(doReportOne(driverName, unitNum)) {
214: printf("Driver config table for %s unit %d "
215: "not found\n", driverName, unitNum);
216: return 1;
217: }
218: else {
219: return 0;
220: }
221: }
222: else {
223: foundOne = NO;
224:
225: for(unitNum=0; ; unitNum++) {
226: if(doReportOne(driverName, unitNum)) {
227: if(foundOne) {
228: /*
229: * Normal termination.
230: */
231: return 0;
232: }
233: else {
234: printf("Driver config tables for %s not found\n",
235: driverName);
236: return 1;
237: }
238: }
239: else {
240: foundOne = YES;
241: }
242: }
243: }
244: }
245:
246: static int reportSystem(int verbose)
247: {
248: IOConfigTable *systemConfig;
249:
250: systemConfig = [IOConfigTable newFromSystemConfig];
251: if(systemConfig == nil) {
252: printf("System Config Table not found\n");
253: return 1;
254: }
255: printf("System config table:\n");
256: dumpConfigInfo(systemConfig, systemKeys);
257: if(verbose) {
258: dumpConfigInfo(systemConfig, verboseSystemKeys);
259: }
260: [systemConfig free];
261: return 0;
262: }
263:
264: static int dumpConfigInfo (IOConfigTable *configTable, const char **keys)
265: {
266: const char *value;
267: const char **key;
268:
269: for(key=keys; *key; key++) {
270: value = [configTable valueForStringKey:*key];
271: if(value) {
272: printf(" %s = %s\n", *key, value);
273: }
274: }
275: return 0;
276: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.