|
|
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: * userDriver.m.
26: * sample user driver. Exec'd by Config.
27: */
28:
29: #import "userDriver.h"
30: #import <driverkit/IODeviceDescription.h>
31: #import <libc.h>
32: #import <mach/mach_error.h>
33: #import <driverkit/driverServer.h>
34: #import <driverkit/userConfigServer.h>
35: #import <driverkit/generalFuncs.h>
36: #import <servers/netname.h>
37:
38: int main(int argc, char **argv)
39: {
40: IOConfigReturn crtn;
41: kern_return_t krtn;
42: port_t driverSigPort;
43: port_t devPorts[NUM_DEVICES];
44: port_t driverPort;
45: int i;
46: id deviceDescription;
47: int numPorts;
48: port_t configPort;
49:
50: IOLog("driver %s: starting\n", argv[0], 2,3,4,5);
51:
52: port_allocate(task_self(), &driverPort);
53: krtn = netname_look_up(name_server_port,
54: "", // hostname
55: CONFIG_SERVER_NAME,
56: &configPort);
57: if(krtn) {
58: IOLog("%s: can't find %s: %s\n",
59: argv[0], CONFIG_SERVER_NAME, mach_error_string(krtn),
60: 4,5);
61: exit(1);
62: }
63: if(crtn = IOGetDevicePorts(NUM_DEVICES,
64: "userDriver",
65: devPorts,
66: &numPorts,
67: &driverSigPort) != IO_CNF_SUCCESS) {
68: IOLog("IOGetDevicePorts() returned %d\n", crtn);
69: exit(1);
70: }
71:
72: /*
73: * Register with Config.
74: */
75: crtn = IORegisterDriver(configPort,
76: driverSigPort,
77: driverPort);
78: if(crtn) {
79: IOLog("%s: IORegisterDriver: crtn = %d\n",
80: argv[0], crtn, 3,4,5);
81: exit(1);
82: }
83:
84: /*
85: * Start up a driver instance for each dev_port.
86: */
87: for(i=0; i<NUM_DEVICES; i++) {
88: deviceDescription = [IODeviceDescription new];
89: [deviceDescription setDevicePort:devPorts[i]];
90: [MyDevice probe:deviceDescription];
91: }
92:
93: /*
94: * Sleep until killed.
95: */
96: while(1)
97: sleep(1);
98: exit(0);
99: }
100:
101: #if 0
102: /*
103: * Look up all of our devPorts. Returns # of ports found.
104: */
105: static int getDevrPort(port_t *devPorts,
106: int maxDevices,
107: const char *driverName)
108: {
109: int i;
110: name_array_t serviceNames;
111: unsigned int serviceCount;
112: name_array_t serverNames;
113: unsigned int serverCount;
114: bool_array_t serviceActive;
115: unsigned int serviceActiveCount;
116: kern_return_t krtn;
117: int portIndex = 0;
118:
119: krtn = bootstrap_info(bootstrap_port,
120: &serviceNames,
121: &serviceCount,
122: &serverNames,
123: &serverCount,
124: &serviceActive,
125: &serviceActiveCount);
126: if (krtn != BOOTSTRAP_SUCCESS) {
127: IOLog("%s: bootstrap_info: %s",
128: driverName, mach_error_string(krtn), 3,4,5);
129: return(PORT_NULL);
130: }
131:
132: /*
133: * Search for devr_XXXX_XXXX. Later - versions and dev_index via
134: * dev_port_to_type().
135: */
136: IOLog("%s: serviceCount %d\n", driverName, serviceCount, 3,4,5);
137: for (i = 0; i < serviceCount; i++) {
138: #ifdef notdef
139: IOLog("%s: serviceName %s\n", driverName, serviceNames[i],
140: 4,5);
141: #endif notdef
142: if(strncmp(serviceNames[i],
143: "dev_port_", strlen("dev_port_")) == 0) {
144: IOLog("%s: port %s found\n",
145: driverName, serviceNames[i], 3,4,5);
146:
147: /*
148: * Get the devPort.
149: */
150: krtn = bootstrap_look_up(bootstrap_port,
151: serviceNames[i],
152: &devPorts[portIndex]);
153: if(krtn) {
154: IOLog("%s: bootstrap_look_up: %s",
155: driverName, mach_error_string(krtn),
156: 3,4,5);
157: return(0);
158: }
159: else {
160: if(++portIndex > maxDevices) {
161: IOLog("%s: maxDevices exceeded\n",
162: driverName, 2,3,4,5);
163: return(portIndex);
164: }
165: }
166: }
167: }
168: IOLog("%s: %d devPorts found\n", driverName, portIndex, 3,4,5);
169: return(portIndex);
170: }
171:
172: #endif 0
173:
174: /*
175: * Simple driver class.
176: */
177: @implementation MyDevice
178:
179: static int unitNum;
180:
181: + (BOOL)probe : deviceDescription
182: {
183: MyDevice *myId;
184: IOString devName;
185:
186: myId = [self alloc];
187: [myId setDeviceDescription:deviceDescription];
188: [myId setUnit:unitNum];
189: sprintf(devName, "MyDevice%d", unitNum++);
190: [myId setName:devName];
191: [myId setDeviceKind:"Example Driver"];
192: [myId setLocation:NULL];
193: [myId MyDeviceInit];
194: return YES;
195: }
196: /*
197: * Device-specific initialization.
198: */
199: - MyDeviceInit
200: {
201: IOLog("MyDeviceInit: unit %d\n", [self unit], 2,3,4,5);
202:
203: /*
204: * ...initialization code here.
205: */
206: return self;
207: }
208:
209:
210: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.