1#if __ppc__ 2/* 3 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 4 * 5 * @APPLE_LICENSE_HEADER_START@ 6 * 7 * This file contains Original Code and/or Modifications of Original Code 8 * as defined in and that are subject to the Apple Public Source License 9 * Version 2.0 (the 'License'). You may not use this file except in 10 * compliance with the License. Please obtain a copy of the License at 11 * http://www.opensource.apple.com/apsl/ and read it before using this 12 * 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, QUIET ENJOYMENT OR NON-INFRINGEMENT. 19 * Please see the License for the specific language governing rights and 20 * limitations under the License. 21 * 22 * @APPLE_LICENSE_HEADER_END@ 23 */ 24 25#include <Kernel/IOKit/adb/IOADBLib.h> 26 27#define arrayCnt(var) (sizeof(var) / sizeof(var[0])) 28 29//************************************************************************************************************* 30// IOPMFindADBController 31// 32//************************************************************************************************************* 33io_connect_t IOPMFindADBController( mach_port_t master_device_port ) 34{ 35io_connect_t fb; 36kern_return_t kr; 37io_iterator_t enumer; 38io_connect_t obj = NULL; 39 40kr = IORegistryCreateIterator( master_device_port, kIOServicePlane, TRUE, &enumer); 41 42if ( kIOReturnSuccess == kr ) { 43 while( (obj = IOIteratorNext( enumer ))) { 44 if( IOObjectConformsTo( obj, "IOADBController" )) { 45 break; 46 } 47 IOObjectRelease( obj ); 48 } 49} 50kr = IORegistryDisposeEnumerator(enumer); 51 52if( obj ) { 53 kr = IOServiceOpen( obj,mach_task_self(), 0, &fb); 54 if ( kr == kIOReturnSuccess ) { 55 return fb; 56 } 57} 58return 0; 59} 60 61 62//************************************************************************************************************* 63// IOPMClaimADBDevice 64// 65//************************************************************************************************************* 66IOReturn IOPMClaimADBDevice ( io_connect_t fb, UInt32 ADBaddress ) 67{ 68 uint64_t address = ADBaddress; 69 70 if (0 < ADBaddress && ADBaddress <= 15) 71 return IOConnectCallScalarMethod(fb, kADBClaimDevice, 72 &address, 1, NULL, NULL); 73 else 74 return kIOReturnBadArgument; 75} 76 77 78//************************************************************************************************************* 79// IOPMReleaseADBDevice 80// 81//************************************************************************************************************* 82IOReturn IOPMReleaseADBDevice ( io_connect_t fb, UInt32 ADBaddress ) 83{ 84 uint64_t address = ADBaddress; 85 86 if (0 < ADBaddress && ADBaddress <= 15) 87 return IOConnectCallScalarMethod(fb, kADBReleaseDevice, 88 &address, 1, NULL, NULL); 89 else 90 return kIOReturnBadArgument; 91} 92 93 94//************************************************************************************************************* 95// IOPMReadADBDevice 96// 97//************************************************************************************************************* 98IOReturn 99IOPMReadADBDevice ( io_connect_t fb, UInt32 ADBaddress, UInt32 ADBregister, 100 unsigned char * buffer, UInt32 * length ) 101{ 102 if ( (ADBaddress > 15) || (ADBaddress == 0) || (ADBregister > 3) ) { 103 return kIOReturnBadArgument; 104 } 105 106 uint64_t input[] = { ADBaddress, ADBregister }; 107 size_t bufLen = 8; 108 kern_return_t rtn = IOConnectCallMethod(fb, kADBReadDevice, 109 input, arrayCnt(input), // In Scalar 110 NULL, 0, // In Struct 111 NULL, NULL, // Out Scalar 112 buffer, &bufLen); // Out Struct 113 *length = (UInt32) bufLen; 114 return rtn; 115} 116 117 118//************************************************************************************************************* 119// IOPMWriteADBDevice 120// 121//************************************************************************************************************* 122// XXX rob: wtf Used to pass the &length rather than length 123IOReturn 124IOPMWriteADBDevice ( io_connect_t fb, 125 unsigned long ADBaddress, unsigned long ADBregister, 126 unsigned char * buffer, unsigned long length) 127{ 128 if ( (ADBaddress > 15) || (ADBaddress == 0) || (ADBregister > 3) ) 129 return kIOReturnBadArgument; 130 131 uint64_t input[] = 132 { ADBaddress, ADBregister, (uintptr_t) buffer, length }; 133 return IOConnectCallMethod(fb, kADBWriteDevice, 134 input, arrayCnt(input), NULL, 0, // In 135 NULL, NULL, NULL, NULL); // Out 136} 137 138#endif // __ppc__ 139