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