]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOADBBus/IOADBController.cpp
14cafcc48981e4474e681ba14127c7d966332eea
[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
155 if ( ! (theFlags & IOPMPowerOn) ) {
156 busProbed = false;
157 for ( i = 1; i < ADB_DEVICE_COUNT; i++ ) {
158 if( adbDevices[ i ] != NULL ) {
159 if ( adbDevices[ i ]->nub ) {
160 adbDevices[ i ]->nub->terminate(kIOServiceRequired);
161 adbDevices[ i ]->nub->release();
162 }
163 IOFree( adbDevices[ i ], sizeof (ADBDeviceControl));
164 adbDevices[ i ] = NULL;
165 }
166 }
167 }
168 return IOPMAckImplied;
169 }
170
171 //*********************************************************************************
172 // powerStateDidChangeTo
173 //
174 // We are notified here of power changes in the root domain
175 //
176 // If power is has been brought up, then the system is waking from sleep.
177 // We re-probe the bus
178 //*********************************************************************************
179 IOReturn IOADBController::powerStateDidChangeTo ( IOPMPowerFlags theFlags, unsigned long, IOService*)
180 {
181 if ( theFlags & IOPMPowerOn ) {
182 if ( ! busProbed ) {
183 thread_call_enter(probeThread);
184 busProbed = true;
185 return kTenSeconds;
186 }
187 }
188 return IOPMAckImplied;
189 }
190
191
192 void doProbe ( thread_call_param_t arg, thread_call_param_t)
193 {
194 ((IOADBController *)arg)->probeBus();
195 ((IOADBController *)arg)->rootDomain->acknowledgePowerChange((IOService *)arg);
196 }
197
198
199 // **********************************************************************************
200 // probeAddress
201 //
202 // **********************************************************************************
203 bool IOADBController::probeAddress ( IOADBAddress addr )
204 {
205 IOReturn err;
206 ADBDeviceControl * deviceInfo;
207 UInt16 value;
208 IOByteCount length;
209
210 length = 2;
211 err = readFromDevice(addr,3,(UInt8 *)&value,&length);
212
213 if (err == ADB_RET_OK) {
214 if( NULL == (deviceInfo = adbDevices[ addr ])) {
215
216 deviceInfo = (ADBDeviceControl *)IOMalloc(sizeof(ADBDeviceControl));
217 bzero(deviceInfo, sizeof(ADBDeviceControl));
218
219 adbDevices[ addr ] = deviceInfo;
220 deviceInfo->defaultAddress = addr;
221 deviceInfo->handlerID = deviceInfo->defaultHandlerID = (value & 0xff);
222 }
223 deviceInfo->address = addr;
224 }
225 return( (err == ADB_RET_OK));
226 }
227
228
229 // **********************************************************************************
230 // firstBit
231 //
232 // **********************************************************************************
233 unsigned int IOADBController::firstBit ( unsigned int mask )
234 {
235 int bit = 15;
236
237 while( 0 == (mask & (1 << bit))) {
238 bit--;
239 }
240 return(bit);
241 }
242
243
244 // **********************************************************************************
245 // moveDeviceFrom
246 //
247 // **********************************************************************************
248 bool IOADBController::moveDeviceFrom ( IOADBAddress from, IOADBAddress to, bool check )
249 {
250 IOReturn err;
251 UInt16 value;
252 IOByteCount length;
253 bool moved;
254
255 length = 2;
256 value = ((to << 8) | ADB_DEVCMD_CHANGE_ID);
257
258 err = writeToDevice(from,3,(UInt8 *)&value,&length);
259
260 adbDevices[ to ] = adbDevices[ from ];
261
262 moved = probeAddress(to);
263
264 if( moved || (!check)) {
265 adbDevices[ from ] = NULL;
266 }
267 else {
268 adbDevices[ to ] = NULL;
269 }
270
271 return moved;
272 }
273
274
275 // **********************************************************************************
276 // probeBus
277 //
278 // **********************************************************************************
279 IOReturn IOADBController::probeBus ( void )
280 {
281 int i;
282 UInt32 unresolvedAddrs;
283 UInt32 freeAddrs;
284 IOADBAddress freeNum, devNum;
285 IOADBDevice * newDev;
286 OSDictionary * newProps;
287 char nameStr[ 10 ];
288 const OSNumber * object;
289 const OSSymbol * key;
290
291 /* Waits one second for the trackpads to be up */
292
293 IOSleep(1500);
294
295 /* Kill the auto poll until a new dev id's have been setup */
296
297 setAutoPollEnable(false);
298
299 /*
300 * Send a ADB bus reset - reply is sent after bus has reset,
301 * so there is no need to wait for the reset to complete.
302 */
303
304 resetBus();
305
306 /* Waits one second for the trackpads to be up */
307
308 IOSleep(1500);
309
310 /*
311 * Okay, now attempt reassign the
312 * bus
313 */
314
315 unresolvedAddrs = 0;
316 freeAddrs = 0xfffe;
317
318 /* Skip 0 -- it's special! */
319 for (i = 1; i < ADB_DEVICE_COUNT; i++) {
320 if( probeAddress(i) ) {
321 unresolvedAddrs |= ( 1 << i );
322 freeAddrs &= ~( 1 << i );
323 }
324 }
325
326 /* Now attempt to reassign the addresses */
327 while( unresolvedAddrs) {
328 if( !freeAddrs) {
329 panic("ADB: Cannot find a free ADB slot for reassignment!");
330 }
331
332 freeNum = firstBit(freeAddrs);
333 devNum = firstBit(unresolvedAddrs);
334
335 if( !moveDeviceFrom(devNum, freeNum, true) ) {
336
337 /* It didn't move.. bad! */
338 IOLog("WARNING : ADB DEVICE %d having problems "
339 "probing!\n", devNum);
340 }
341 else {
342 if( probeAddress(devNum) ) {
343 /* Found another device at the address, leave
344 * the first device moved to one side and set up
345 * newly found device for probing
346 */
347 freeAddrs &= ~( 1 << freeNum );
348
349 devNum = 0;
350
351 }
352 else {
353 /* no more at this address, good !*/
354 /* Move it back.. */
355 moveDeviceFrom(freeNum,devNum,false);
356 }
357 }
358 if(devNum) {
359 unresolvedAddrs &= ~( 1 << devNum );
360 }
361 }
362
363 IOLog("ADB present:%lx\n", (freeAddrs ^ 0xfffe));
364
365 setAutoPollList(freeAddrs ^ 0xfffe);
366
367 setAutoPollPeriod(11111);
368
369 setAutoPollEnable(true);
370
371 // publish the nubs
372 for ( i = 1; i < ADB_DEVICE_COUNT; i++ ) {
373 if( 0 == adbDevices[ i ] ) {
374 continue;
375 }
376 newDev = new IOADBDevice; // make a nub
377 if ( newDev == NULL ) {
378 continue;
379 }
380 adbDevices[ i ]->nub = newDev; // keep a pointer to it
381
382 newProps = OSDictionary::withCapacity( 10 ); // create a property table for it
383 if ( newProps == NULL ) {
384 newDev->free();
385 continue;
386 }
387
388 key = OSSymbol::withCString(ADBaddressProperty); // make key/object for address
389 if ( key == NULL ) {
390 newDev->free();
391 newProps->free();
392 continue;
393 }
394
395 object = OSNumber::withNumber((unsigned long long)adbDevices[i]->address,8);
396 if ( object == NULL ) {
397 key->release();
398 newDev->free();
399 newProps->free();
400 continue;
401 }
402 newProps->setObject(key, (OSObject *)object); // put it in newProps
403 key->release();
404 object->release();
405
406 key = OSSymbol::withCString(ADBhandlerIDProperty); // make key/object for handlerID
407 if ( key == NULL ) {
408 newDev->free();
409 newProps->free();
410 continue;
411 }
412 object = OSNumber::withNumber((unsigned long long)adbDevices[i]->handlerID,8);
413 if ( object == NULL ) {
414 key->release();
415 newDev->free();
416 newProps->free();
417 continue;
418 }
419 newProps->setObject(key, (OSObject *)object); // put it in newProps
420 key->release();
421 object->release();
422
423 key = OSSymbol::withCString(ADBdefAddressProperty); // make key/object for default addr
424 if ( key == NULL ) {
425 newDev->free();
426 newProps->free();
427 continue;
428 }
429 object = OSNumber::withNumber((unsigned long long)adbDevices[i]->defaultAddress,8);
430 if ( object == NULL ) {
431 key->release();
432 newDev->free();
433 newProps->free();
434 continue;
435 }
436 newProps->setObject(key, (OSObject *)object); // put it in newProps
437 key->release();
438 object->release();
439
440 key = OSSymbol::withCString(ADBdefHandlerProperty); // make key/object for default h id
441 if ( key == NULL ) {
442 newDev->free();
443 newProps->free();
444 continue;
445 }
446 object = OSNumber::withNumber((unsigned long long)adbDevices[i]->defaultHandlerID,8);
447 if ( object == NULL ) {
448 key->release();
449 newDev->free();
450 newProps->free();
451 continue;
452 }
453 newProps->setObject(key, (OSObject *)object); // put it in newProps
454 key->release();
455 object->release();
456
457 if ( ! newDev->init(newProps,adbDevices[i]) ) { // give it to our new nub
458 kprintf("adb nub init failed\n");
459 newDev->release();
460 continue;
461 }
462
463 sprintf(nameStr,"%x-%02x",adbDevices[i]->defaultAddress,adbDevices[i]->handlerID);
464 newDev->setName(nameStr);
465 sprintf(nameStr, "%x", adbDevices[i]->defaultAddress);
466 newDev->setLocation(nameStr);
467
468 newProps->release(); // we're done with it
469 if ( !newDev->attach(this) ) {
470 kprintf("adb nub attach failed\n");
471 newDev->release();
472 continue;
473 }
474 newDev->registerService();
475 newDev->start(this);
476 } // repeat loop
477 return kIOReturnSuccess;
478 }
479
480
481 // **********************************************************************************
482 // autopollHandler
483 //
484 // **********************************************************************************
485 void autopollHandler ( IOService * us, UInt8 adbCommand, IOByteCount length, UInt8 * data )
486 {
487 ((IOADBController *)us)->packet(data,length,adbCommand);
488 }
489
490
491 // **********************************************************************************
492 // packet
493 //
494 // **********************************************************************************
495 void IOADBController::packet ( UInt8 * data, IOByteCount length, UInt8 adbCommand )
496 {
497 ADBDeviceControl * deviceInfo;
498
499 deviceInfo = adbDevices[ adbCommand >> 4 ];
500 if( deviceInfo != NULL ) {
501 if( deviceInfo->owner != NULL ) {
502 deviceInfo->handler(deviceInfo->owner, adbCommand, length, data);
503 }
504 }
505 else {
506 // new device arrival?
507 // IOLog("IOADBBus: new device @%x\n", address);
508 }
509 }
510
511
512 // **********************************************************************************
513 // matchDevice
514 //
515 // **********************************************************************************
516 bool IOADBController::matchNubWithPropertyTable( IOService * device, OSDictionary * propTable )
517 {
518 bool matched = false;
519 const char * keys;
520 ADBDeviceControl * deviceInfo = (ADBDeviceControl *)(((IOADBDevice *)device)->busRef());
521 OSObject * X;
522
523 do {
524 X = propTable->getObject("ADB Match");
525 if( !X ) {
526 break;
527 }
528 keys = ((OSString *)X)->getCStringNoCopy();
529 if( *keys == '*' ) {
530 keys++;
531 }
532 else {
533 if( deviceInfo->defaultAddress != strtol(keys, &keys, 16)) {
534 break;
535 }
536 }
537 if( *keys++ == '-' ) {
538 if( deviceInfo->defaultHandlerID != strtol(keys, &keys, 16)) {
539 break;
540 }
541 }
542 matched = true;
543
544 } while ( false );
545 return matched;
546 }
547
548
549 /////// nub -> bus
550
551 // **********************************************************************************
552 // setOwner
553 //
554 // **********************************************************************************
555 IOReturn IOADBController::setOwner ( void * device, IOService * client, ADB_callback_func handler )
556 {
557 ADBDeviceControl * deviceInfo = (ADBDeviceControl *)device;
558
559 deviceInfo->owner = client;
560 deviceInfo->handler = handler;
561 return kIOReturnSuccess;
562 }
563
564
565 // **********************************************************************************
566 // clearOwner
567 //
568 // **********************************************************************************
569 IOReturn IOADBController::clearOwner ( void * device )
570 {
571 ADBDeviceControl * deviceInfo = (ADBDeviceControl *)device;
572 kprintf("IOADBController::clearOwner\n");
573
574 deviceInfo->owner = NULL;
575 deviceInfo->handler = NULL;
576 return kIOReturnSuccess;
577 }
578
579
580 // **********************************************************************************
581 // claimDevice
582 //
583 // Called by the user client
584 // **********************************************************************************
585 IOReturn IOADBController::claimDevice (unsigned long ADBaddress, IOService * client, ADB_callback_func handler )
586 {
587 if ( claimed_devices[ADBaddress] == true ) { // is this address already claimed by the user?
588 return kIOReturnExclusiveAccess; // yes
589 }
590 if ( adbDevices[ADBaddress] == NULL ) { // no, is there a device at that address?
591 return kIOReturnNoDevice; // no
592 }
593 if (adbDevices[ADBaddress]->handler != NULL ) { // yes, is it already owned by the kernel?
594 return kIOReturnExclusiveAccess; // yes
595 }
596 claimed_devices[ADBaddress] = true; // no, user can have it
597 return kIOReturnSuccess;
598 }
599
600
601 // **********************************************************************************
602 // releaseDevice
603 //
604 // Called by the user client
605 // **********************************************************************************
606 IOReturn IOADBController::releaseDevice (unsigned long ADBaddress )
607 {
608 if ( claimed_devices[ADBaddress] == false ) {
609 return kIOReturnBadArgument;
610 }
611
612 claimed_devices[ADBaddress] = false;
613
614 return kIOReturnSuccess;
615 }
616
617
618 // **********************************************************************************
619 // readDeviceForUser
620 //
621 // Called by the user client
622 // **********************************************************************************
623 IOReturn IOADBController::readDeviceForUser (unsigned long address, unsigned long adbRegister,
624 UInt8 * data, IOByteCount * length)
625 {
626 if ( claimed_devices[address] == false ) {
627 return kIOReturnBadArgument;
628 }
629
630 return (readFromDevice((IOADBAddress)address,(IOADBRegister)adbRegister,data,length));
631 }
632
633
634 // **********************************************************************************
635 // writeDeviceForUser
636 //
637 // Called by the user client
638 // **********************************************************************************
639 IOReturn IOADBController::writeDeviceForUser (unsigned long address, unsigned long adbRegister,
640 UInt8 * data, IOByteCount * length)
641 {
642 if ( claimed_devices[address] == false ) {
643 return kIOReturnBadArgument;
644 }
645
646 return (writeToDevice((IOADBAddress)address,(IOADBRegister)adbRegister,data,length));
647 }
648
649
650 // **********************************************************************************
651 // address
652 //
653 // **********************************************************************************
654 IOADBAddress IOADBController::address ( ADBDeviceControl * busRef )
655 {
656 return busRef->address;
657 }
658
659
660 // **********************************************************************************
661 // defaultAddress
662 //
663 // **********************************************************************************
664 IOADBAddress IOADBController::defaultAddress ( ADBDeviceControl * busRef )
665 {
666 return busRef->defaultAddress;
667 }
668
669
670 // **********************************************************************************
671 // handlerID
672 //
673 // **********************************************************************************
674 UInt8 IOADBController::handlerID ( ADBDeviceControl * busRef )
675 {
676 return busRef->handlerID;
677 }
678
679
680 // **********************************************************************************
681 // defaultHandlerID
682 //
683 // **********************************************************************************
684 UInt8 IOADBController::defaultHandlerID ( ADBDeviceControl * busRef )
685 {
686 return busRef->defaultHandlerID;
687 }
688
689
690 // **********************************************************************************
691 // flush
692 //
693 // **********************************************************************************
694 IOReturn IOADBController::flush ( ADBDeviceControl * busRef )
695 {
696 return(flushDevice(busRef->address));
697 }
698
699
700 // **********************************************************************************
701 // readRegister
702 //
703 // **********************************************************************************
704 IOReturn IOADBController::readRegister ( ADBDeviceControl * busRef, IOADBRegister adbRegister,
705 UInt8 * data, IOByteCount * length )
706 {
707 return readFromDevice(busRef->address,adbRegister,data,length);
708 }
709
710
711 // **********************************************************************************
712 // writeRegister
713 //
714 // **********************************************************************************
715 IOReturn IOADBController::writeRegister ( ADBDeviceControl * busRef, IOADBRegister adbRegister,
716 UInt8 * data, IOByteCount * length )
717 {
718 return writeToDevice(busRef->address,adbRegister,data,length);
719 }
720
721
722 // **********************************************************************************
723 // setHandlerID
724 //
725 // **********************************************************************************
726 IOReturn IOADBController::setHandlerID ( ADBDeviceControl * deviceInfo, UInt8 handlerID )
727 {
728 IOReturn err;
729 UInt16 value;
730 IOByteCount length;
731 IOADBAddress addr = deviceInfo->address;
732
733 length = 2;
734 err = readFromDevice(addr,3,(UInt8 *)&value,&length);
735
736 if ( err ) {
737 return err;
738 }
739
740 value = (value & 0xf000) | handlerID | (addr << 8);
741 length = sizeof(value);
742 err = writeToDevice(addr,3,(UInt8 *)&value,&length);
743
744 length = sizeof(value);
745 err = readFromDevice(addr,3,(UInt8 *)&value,&length);
746
747 if ( err == kIOReturnSuccess ) {
748 deviceInfo->handlerID = value & 0xff;
749 }
750
751 if ( deviceInfo->handlerID == handlerID ) {
752 err = kIOReturnSuccess;
753 }
754 else {
755 err = kIOReturnNoResources;
756 }
757
758 return err;
759 }
760
761
762 // **********************************************************************************
763 // getURLComponentUnit
764 //
765 // **********************************************************************************
766 int IOADBController::getURLComponentUnit ( IOService * device, char * path, int maxLen )
767 {
768 ADBDeviceControl * deviceInfo = (ADBDeviceControl *)((IOADBDevice *)device)->busRef();
769
770 if( maxLen > 1 ) {
771 sprintf( path, "%x", deviceInfo->address );
772 return(1);
773 }
774 else {
775 return(0);
776 }
777 }
778
779
780 // **********************************************************************************
781 // newUserClient
782 //
783 // **********************************************************************************
784 IOReturn IOADBController::newUserClient( task_t owningTask, void * /* security_id */, UInt32 type, IOUserClient ** handler )
785 {
786 IOReturn err = kIOReturnSuccess;
787 IOADBControllerUserClient * client;
788
789 client = IOADBControllerUserClient::withTask(owningTask);
790
791 if( !client || (false == client->attach( this )) ||
792 (false == client->start( this )) ) {
793 if(client) {
794 client->detach( this );
795 client->release();
796 client = NULL;
797 }
798 err = kIOReturnNoMemory;
799 }
800 *handler = client;
801 return err;
802 }