]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOADBBus/IOADBController.cpp
xnu-344.23.tar.gz
[apple/xnu.git] / iokit / Families / IOADBBus / IOADBController.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991
24 * All Rights Reserved
25 *
26 * Permission to use, copy, modify, and distribute this software and
27 * its documentation for any purpose and without fee is hereby granted,
28 * provided that the above copyright notice appears in all copies and
29 * that both the copyright notice and this permission notice appear in
30 * supporting documentation.
31 *
32 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
33 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
34 * FOR A PARTICULAR PURPOSE.
35 *
36 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
37 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
38 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
39 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
40 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41 *
42 */
43 /*
44 * Copyright 1996 1995 by Apple Computer, Inc. 1997 1996 1995 1994 1993 1992 1991
45 * All Rights Reserved
46 *
47 * Permission to use, copy, modify, and distribute this software and
48 * its documentation for any purpose and without fee is hereby granted,
49 * provided that the above copyright notice appears in all copies and
50 * that both the copyright notice and this permission notice appear in
51 * supporting documentation.
52 *
53 * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
54 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
55 * FOR A PARTICULAR PURPOSE.
56 *
57 * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
58 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
59 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
60 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
61 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
62 */
63 /*
64 * MKLINUX-1.0DR2
65 */
66 /*
67 * 18 June 1998 sdouglas Start IOKit version.
68 * 16 Nov 1998 suurballe Port to c++
69 */
70
71
72 #include <mach/mach_types.h>
73
74 #include "IOADBControllerUserClient.h"
75 #include <IOKit/adb/IOADBController.h>
76 #include <IOKit/adb/IOADBDevice.h>
77 #include <libkern/c++/OSSymbol.h>
78 #include <libkern/c++/OSNumber.h>
79 #include <IOKit/IOLib.h>
80 #include <IOKit/pwr_mgt/RootDomain.h>
81 #include "IOADBBusPriv.h"
82
83 bool ADBhasRoot( OSObject *, void *, IOService * );
84 void doProbe ( thread_call_param_t, thread_call_param_t);
85
86 #define kTenSeconds 10000000
87
88 #define super IOADBBus
89
90 OSDefineMetaClass(IOADBController,IOADBBus)
91 OSDefineAbstractStructors(IOADBController,IOADBBus)
92
93
94 // **********************************************************************************
95 // start
96 //
97 // **********************************************************************************
98 bool IOADBController::start ( IOService * nub )
99 {
100 if( !super::start(nub)) {
101 return false;
102 }
103 probeBus();
104
105 rootDomain = NULL;
106 busProbed = true;
107
108 // creates the probe thread for when we wake up:
109 probeThread = thread_call_allocate((thread_call_func_t)doProbe, (thread_call_param_t)this);
110 if (probeThread == NULL) {
111 IOLog("IOADBController::start fails to call thread_call_allocate \n");
112 return false;
113 }
114
115 addNotification( gIOPublishNotification,serviceMatching("IOPMrootDomain"), // look for the Root Domain
116 (IOServiceNotificationHandler)ADBhasRoot, this, 0 );
117
118 return true;
119 }
120
121
122
123
124
125 // **********************************************************************************
126 // ADBhasRoot
127 //
128 // The Root Power Domain has registered.
129 // Register as an interested driver so we find out when the system is
130 // going to sleep and waking up.
131 // **********************************************************************************
132 bool ADBhasRoot( OSObject * us, void *, IOService * yourDevice )
133 {
134 if ( yourDevice != NULL ) {
135 ((IOADBController *)us)->rootDomain = (IOPMrootDomain *)yourDevice;
136 ((IOADBController *)us)->rootDomain->registerInterestedDriver((IOService *) us);
137 }
138 return true;
139 }
140
141
142 //*********************************************************************************
143 // powerStateWillChangeTo
144 //
145 // We are notified here of power changes in the root domain.
146 //
147 // If power is going down in the root domain, then the system is going to
148 // sleep, and we tear down the ADB stack.
149 //*********************************************************************************
150
151 IOReturn IOADBController::powerStateWillChangeTo ( IOPMPowerFlags theFlags, unsigned long, IOService*)
152 {
153 int i;
154 if ( ! (theFlags & kIOPMPowerOn) && ! (theFlags & kIOPMDoze) ) {
155 busProbed = false;
156 for ( i = 1; i < ADB_DEVICE_COUNT; i++ ) {
157 if( adbDevices[ i ] != NULL ) {
158 if ( adbDevices[ i ]->nub ) {
159 adbDevices[ i ]->nub->terminate(kIOServiceRequired | kIOServiceSynchronous);
160 adbDevices[ i ]->nub->release();
161 }
162 IOFree( adbDevices[ i ], sizeof (ADBDeviceControl));
163 adbDevices[ i ] = NULL;
164 }
165 }
166 }
167 return IOPMAckImplied;
168 }
169
170 //*********************************************************************************
171 // powerStateDidChangeTo
172 //
173 // We are notified here of power changes in the root domain
174 //
175 // If power is has been brought up, then the system is waking from sleep.
176 // We re-probe the bus
177 //*********************************************************************************
178 IOReturn IOADBController::powerStateDidChangeTo ( IOPMPowerFlags theFlags, unsigned long, IOService*)
179 {
180 if ( (theFlags & kIOPMPowerOn) || (theFlags & kIOPMDoze) ) {
181 if ( ! busProbed ) {
182 thread_call_enter(probeThread);
183 busProbed = true;
184 return kTenSeconds;
185 }
186 }
187 return IOPMAckImplied;
188 }
189
190
191 void doProbe ( thread_call_param_t arg, thread_call_param_t)
192 {
193 ((IOADBController *)arg)->probeBus();
194 ((IOADBController *)arg)->rootDomain->acknowledgePowerChange((IOService *)arg);
195 }
196
197
198 // **********************************************************************************
199 // probeAddress
200 //
201 // **********************************************************************************
202 bool IOADBController::probeAddress ( IOADBAddress addr )
203 {
204 IOReturn err;
205 ADBDeviceControl * deviceInfo;
206 UInt16 value;
207 IOByteCount length;
208
209 length = 2;
210 err = readFromDevice(addr,3,(UInt8 *)&value,&length);
211
212 if (err == ADB_RET_OK) {
213 if( NULL == (deviceInfo = adbDevices[ addr ])) {
214
215 deviceInfo = (ADBDeviceControl *)IOMalloc(sizeof(ADBDeviceControl));
216 bzero(deviceInfo, sizeof(ADBDeviceControl));
217
218 adbDevices[ addr ] = deviceInfo;
219 deviceInfo->defaultAddress = addr;
220 deviceInfo->handlerID = deviceInfo->defaultHandlerID = (value & 0xff);
221 }
222 deviceInfo->address = addr;
223 }
224 return( (err == ADB_RET_OK));
225 }
226
227
228 // **********************************************************************************
229 // firstBit
230 //
231 // **********************************************************************************
232 unsigned int IOADBController::firstBit ( unsigned int mask )
233 {
234 int bit = 15;
235
236 while( 0 == (mask & (1 << bit))) {
237 bit--;
238 }
239 return(bit);
240 }
241
242
243 // **********************************************************************************
244 // moveDeviceFrom
245 //
246 // **********************************************************************************
247 bool IOADBController::moveDeviceFrom ( IOADBAddress from, IOADBAddress to, bool check )
248 {
249 IOReturn err;
250 UInt16 value;
251 IOByteCount length;
252 bool moved;
253
254 length = 2;
255 value = ((to << 8) | ADB_DEVCMD_CHANGE_ID);
256
257 err = writeToDevice(from,3,(UInt8 *)&value,&length);
258
259 adbDevices[ to ] = adbDevices[ from ];
260
261 moved = probeAddress(to);
262
263 if( moved || (!check)) {
264 adbDevices[ from ] = NULL;
265 }
266 else {
267 adbDevices[ to ] = NULL;
268 }
269
270 return moved;
271 }
272
273
274 // **********************************************************************************
275 // probeBus
276 //
277 // **********************************************************************************
278 IOReturn IOADBController::probeBus ( void )
279 {
280 int i;
281 UInt32 unresolvedAddrs;
282 UInt32 freeAddrs;
283 IOADBAddress freeNum, devNum;
284 IOADBDevice * newDev;
285 OSDictionary * newProps;
286 char nameStr[ 10 ];
287 const OSNumber * object;
288 const OSSymbol * key;
289
290 /* Kill the auto poll until a new dev id's have been setup */
291 setAutoPollEnable(false);
292
293 /*
294 * Send a ADB bus reset - reply is sent after bus has reset,
295 * so there is no need to wait for the reset to complete.
296 */
297
298 resetBus();
299
300 /*
301 * Okay, now attempt reassign the
302 * bus
303 */
304
305 unresolvedAddrs = 0;
306 freeAddrs = 0xfffe;
307
308 /* Skip 0 -- it's special! */
309 for (i = 1; i < ADB_DEVICE_COUNT; i++) {
310 if( probeAddress(i) ) {
311 unresolvedAddrs |= ( 1 << i );
312 freeAddrs &= ~( 1 << i );
313 }
314 }
315
316 /* Now attempt to reassign the addresses */
317 while( unresolvedAddrs) {
318 if( !freeAddrs) {
319 panic("ADB: Cannot find a free ADB slot for reassignment!");
320 }
321
322 freeNum = firstBit(freeAddrs);
323 devNum = firstBit(unresolvedAddrs);
324
325 if( !moveDeviceFrom(devNum, freeNum, true) ) {
326
327 /* It didn't move.. bad! */
328 IOLog("WARNING : ADB DEVICE %d having problems "
329 "probing!\n", devNum);
330 }
331 else {
332 if( probeAddress(devNum) ) {
333 /* Found another device at the address, leave
334 * the first device moved to one side and set up
335 * newly found device for probing
336 */
337 freeAddrs &= ~( 1 << freeNum );
338
339 devNum = 0;
340
341 }
342 else {
343 /* no more at this address, good !*/
344 /* Move it back.. */
345 moveDeviceFrom(freeNum,devNum,false);
346 }
347 }
348 if(devNum) {
349 unresolvedAddrs &= ~( 1 << devNum );
350 }
351 }
352
353 IOLog("ADB present:%lx\n", (freeAddrs ^ 0xfffe));
354
355 setAutoPollList(freeAddrs ^ 0xfffe);
356
357 setAutoPollPeriod(11111);
358
359 setAutoPollEnable(true);
360
361 // publish the nubs
362 for ( i = 1; i < ADB_DEVICE_COUNT; i++ ) {
363 if( 0 == adbDevices[ i ] ) {
364 continue;
365 }
366 newDev = new IOADBDevice; // make a nub
367 if ( newDev == NULL ) {
368 continue;
369 }
370 adbDevices[ i ]->nub = newDev; // keep a pointer to it
371
372 newProps = OSDictionary::withCapacity( 10 ); // create a property table for it
373 if ( newProps == NULL ) {
374 newDev->free();
375 continue;
376 }
377
378 key = OSSymbol::withCString(ADBaddressProperty); // make key/object for address
379 if ( key == NULL ) {
380 newDev->free();
381 newProps->free();
382 continue;
383 }
384
385 object = OSNumber::withNumber((unsigned long long)adbDevices[i]->address,8);
386 if ( object == NULL ) {
387 key->release();
388 newDev->free();
389 newProps->free();
390 continue;
391 }
392 newProps->setObject(key, (OSObject *)object); // put it in newProps
393 key->release();
394 object->release();
395
396 key = OSSymbol::withCString(ADBhandlerIDProperty); // make key/object for handlerID
397 if ( key == NULL ) {
398 newDev->free();
399 newProps->free();
400 continue;
401 }
402 object = OSNumber::withNumber((unsigned long long)adbDevices[i]->handlerID,8);
403 if ( object == NULL ) {
404 key->release();
405 newDev->free();
406 newProps->free();
407 continue;
408 }
409 newProps->setObject(key, (OSObject *)object); // put it in newProps
410 key->release();
411 object->release();
412
413 key = OSSymbol::withCString(ADBdefAddressProperty); // make key/object for default addr
414 if ( key == NULL ) {
415 newDev->free();
416 newProps->free();
417 continue;
418 }
419 object = OSNumber::withNumber((unsigned long long)adbDevices[i]->defaultAddress,8);
420 if ( object == NULL ) {
421 key->release();
422 newDev->free();
423 newProps->free();
424 continue;
425 }
426 newProps->setObject(key, (OSObject *)object); // put it in newProps
427 key->release();
428 object->release();
429
430 key = OSSymbol::withCString(ADBdefHandlerProperty); // make key/object for default h id
431 if ( key == NULL ) {
432 newDev->free();
433 newProps->free();
434 continue;
435 }
436 object = OSNumber::withNumber((unsigned long long)adbDevices[i]->defaultHandlerID,8);
437 if ( object == NULL ) {
438 key->release();
439 newDev->free();
440 newProps->free();
441 continue;
442 }
443 newProps->setObject(key, (OSObject *)object); // put it in newProps
444 key->release();
445 object->release();
446
447 if ( ! newDev->init(newProps,adbDevices[i]) ) { // give it to our new nub
448 kprintf("adb nub init failed\n");
449 newDev->release();
450 continue;
451 }
452
453 sprintf(nameStr,"%x-%02x",adbDevices[i]->defaultAddress,adbDevices[i]->handlerID);
454 newDev->setName(nameStr);
455 sprintf(nameStr, "%x", adbDevices[i]->defaultAddress);
456 newDev->setLocation(nameStr);
457
458 newProps->release(); // we're done with it
459 if ( !newDev->attach(this) ) {
460 kprintf("adb nub attach failed\n");
461 newDev->release();
462 continue;
463 }
464 newDev->start(this);
465 newDev->registerService();
466 newDev->waitQuiet();
467 } // repeat loop
468 return kIOReturnSuccess;
469 }
470
471
472 // **********************************************************************************
473 // autopollHandler
474 //
475 // **********************************************************************************
476 void autopollHandler ( IOService * us, UInt8 adbCommand, IOByteCount length, UInt8 * data )
477 {
478 ((IOADBController *)us)->packet(data,length,adbCommand);
479 }
480
481
482 // **********************************************************************************
483 // packet
484 //
485 // **********************************************************************************
486 void IOADBController::packet ( UInt8 * data, IOByteCount length, UInt8 adbCommand )
487 {
488 ADBDeviceControl * deviceInfo;
489
490 deviceInfo = adbDevices[ adbCommand >> 4 ];
491 if( deviceInfo != NULL ) {
492 if( deviceInfo->owner != NULL ) {
493 deviceInfo->handler(deviceInfo->owner, adbCommand, length, data);
494 }
495 }
496 else {
497 // new device arrival?
498 // IOLog("IOADBBus: new device @%x\n", address);
499 }
500 }
501
502
503 // **********************************************************************************
504 // matchDevice
505 //
506 // **********************************************************************************
507 bool IOADBController::matchNubWithPropertyTable( IOService * device, OSDictionary * propTable )
508 {
509 bool matched = false;
510 const char * keys;
511 ADBDeviceControl * deviceInfo = (ADBDeviceControl *)(((IOADBDevice *)device)->busRef());
512 OSObject * X;
513
514 do {
515 X = propTable->getObject("ADB Match");
516 if( !X ) {
517 break;
518 }
519 keys = ((OSString *)X)->getCStringNoCopy();
520 if( *keys == '*' ) {
521 keys++;
522 }
523 else {
524 if( deviceInfo->defaultAddress != strtol(keys, (char **) &keys, 16)) {
525 break;
526 }
527 }
528 if( *keys++ == '-' ) {
529 if( deviceInfo->defaultHandlerID != strtol(keys, (char **) &keys, 16)) {
530 break;
531 }
532 }
533 matched = true;
534
535 } while ( false );
536 return matched;
537 }
538
539
540 /////// nub -> bus
541
542 // **********************************************************************************
543 // setOwner
544 //
545 // **********************************************************************************
546 IOReturn IOADBController::setOwner ( void * device, IOService * client, ADB_callback_func handler )
547 {
548 ADBDeviceControl * deviceInfo = (ADBDeviceControl *)device;
549
550 deviceInfo->handler = handler;
551 deviceInfo->owner = client;
552 return kIOReturnSuccess;
553 }
554
555
556 // **********************************************************************************
557 // clearOwner
558 //
559 // **********************************************************************************
560 IOReturn IOADBController::clearOwner ( void * device )
561 {
562 ADBDeviceControl * deviceInfo = (ADBDeviceControl *)device;
563 kprintf("IOADBController::clearOwner\n");
564
565 deviceInfo->owner = NULL;
566 deviceInfo->handler = NULL;
567 return kIOReturnSuccess;
568 }
569
570
571 // **********************************************************************************
572 // claimDevice
573 //
574 // Called by the user client
575 // **********************************************************************************
576 IOReturn IOADBController::claimDevice (unsigned long ADBaddress, IOService * client, ADB_callback_func handler )
577 {
578 if ( claimed_devices[ADBaddress] == true ) { // is this address already claimed by the user?
579 return kIOReturnExclusiveAccess; // yes
580 }
581 if ( adbDevices[ADBaddress] == NULL ) { // no, is there a device at that address?
582 return kIOReturnNoDevice; // no
583 }
584 if (adbDevices[ADBaddress]->handler != NULL ) { // yes, is it already owned by the kernel?
585 return kIOReturnExclusiveAccess; // yes
586 }
587 claimed_devices[ADBaddress] = true; // no, user can have it
588 return kIOReturnSuccess;
589 }
590
591
592 // **********************************************************************************
593 // releaseDevice
594 //
595 // Called by the user client
596 // **********************************************************************************
597 IOReturn IOADBController::releaseDevice (unsigned long ADBaddress )
598 {
599 if ( claimed_devices[ADBaddress] == false ) {
600 return kIOReturnBadArgument;
601 }
602
603 claimed_devices[ADBaddress] = false;
604
605 return kIOReturnSuccess;
606 }
607
608
609 // **********************************************************************************
610 // readDeviceForUser
611 //
612 // Called by the user client
613 // **********************************************************************************
614 IOReturn IOADBController::readDeviceForUser (unsigned long address, unsigned long adbRegister,
615 UInt8 * data, IOByteCount * length)
616 {
617 if ( claimed_devices[address] == false ) {
618 return kIOReturnBadArgument;
619 }
620
621 return (readFromDevice((IOADBAddress)address,(IOADBRegister)adbRegister,data,length));
622 }
623
624
625 // **********************************************************************************
626 // writeDeviceForUser
627 //
628 // Called by the user client
629 // **********************************************************************************
630 IOReturn IOADBController::writeDeviceForUser (unsigned long address, unsigned long adbRegister,
631 UInt8 * data, IOByteCount * length)
632 {
633 if ( claimed_devices[address] == false ) {
634 return kIOReturnBadArgument;
635 }
636
637 return (writeToDevice((IOADBAddress)address,(IOADBRegister)adbRegister,data,length));
638 }
639
640
641 // **********************************************************************************
642 // address
643 //
644 // **********************************************************************************
645 IOADBAddress IOADBController::address ( ADBDeviceControl * busRef )
646 {
647 return busRef->address;
648 }
649
650
651 // **********************************************************************************
652 // defaultAddress
653 //
654 // **********************************************************************************
655 IOADBAddress IOADBController::defaultAddress ( ADBDeviceControl * busRef )
656 {
657 return busRef->defaultAddress;
658 }
659
660
661 // **********************************************************************************
662 // handlerID
663 //
664 // **********************************************************************************
665 UInt8 IOADBController::handlerID ( ADBDeviceControl * busRef )
666 {
667 return busRef->handlerID;
668 }
669
670
671 // **********************************************************************************
672 // defaultHandlerID
673 //
674 // **********************************************************************************
675 UInt8 IOADBController::defaultHandlerID ( ADBDeviceControl * busRef )
676 {
677 return busRef->defaultHandlerID;
678 }
679
680
681 // **********************************************************************************
682 // cancelAllIO
683 //
684 // **********************************************************************************
685 IOReturn IOADBController::cancelAllIO ( void )
686 {
687 return kIOReturnSuccess;
688 }
689
690
691 // **********************************************************************************
692 // flush
693 //
694 // **********************************************************************************
695 IOReturn IOADBController::flush ( ADBDeviceControl * busRef )
696 {
697 return(flushDevice(busRef->address));
698 }
699
700
701 // **********************************************************************************
702 // readRegister
703 //
704 // **********************************************************************************
705 IOReturn IOADBController::readRegister ( ADBDeviceControl * busRef, IOADBRegister adbRegister,
706 UInt8 * data, IOByteCount * length )
707 {
708 return readFromDevice(busRef->address,adbRegister,data,length);
709 }
710
711
712 // **********************************************************************************
713 // writeRegister
714 //
715 // **********************************************************************************
716 IOReturn IOADBController::writeRegister ( ADBDeviceControl * busRef, IOADBRegister adbRegister,
717 UInt8 * data, IOByteCount * length )
718 {
719 return writeToDevice(busRef->address,adbRegister,data,length);
720 }
721
722
723 // **********************************************************************************
724 // setHandlerID
725 //
726 // **********************************************************************************
727 IOReturn IOADBController::setHandlerID ( ADBDeviceControl * deviceInfo, UInt8 handlerID )
728 {
729 IOReturn err;
730 UInt16 value;
731 IOByteCount length;
732 IOADBAddress addr = deviceInfo->address;
733
734 length = 2;
735 err = readFromDevice(addr,3,(UInt8 *)&value,&length);
736
737 if ( err ) {
738 return err;
739 }
740
741 value = (value & 0xf000) | handlerID | (addr << 8);
742 length = sizeof(value);
743 err = writeToDevice(addr,3,(UInt8 *)&value,&length);
744
745 length = sizeof(value);
746 err = readFromDevice(addr,3,(UInt8 *)&value,&length);
747
748 if ( err == kIOReturnSuccess ) {
749 deviceInfo->handlerID = value & 0xff;
750 }
751
752 if ( deviceInfo->handlerID == handlerID ) {
753 err = kIOReturnSuccess;
754 }
755 else {
756 err = kIOReturnNoResources;
757 }
758
759 return err;
760 }
761
762
763 // **********************************************************************************
764 // getURLComponentUnit
765 //
766 // **********************************************************************************
767 int IOADBController::getURLComponentUnit ( IOService * device, char * path, int maxLen )
768 {
769 ADBDeviceControl * deviceInfo = (ADBDeviceControl *)((IOADBDevice *)device)->busRef();
770
771 if( maxLen > 1 ) {
772 sprintf( path, "%x", deviceInfo->address );
773 return(1);
774 }
775 else {
776 return(0);
777 }
778 }
779
780
781 // **********************************************************************************
782 // newUserClient
783 //
784 // **********************************************************************************
785 IOReturn IOADBController::newUserClient( task_t owningTask, void * /* security_id */, UInt32 type, IOUserClient ** handler )
786 {
787 IOReturn err = kIOReturnSuccess;
788 IOADBControllerUserClient * client;
789
790 client = IOADBControllerUserClient::withTask(owningTask);
791
792 if( !client || (false == client->attach( this )) ||
793 (false == client->start( this )) ) {
794 if(client) {
795 client->detach( this );
796 client->release();
797 client = NULL;
798 }
799 err = kIOReturnNoMemory;
800 }
801 *handler = client;
802 return err;
803 }