Annotation of kernel/bsd/dev/ppc/IOADBBus.m, revision 1.1

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: /* Copyright (c) 1997 Apple Computer, Inc.  All rights reserved.
        !            26:  *
        !            27:  * IOADBBus.m - This file contains the definition of the
        !            28:  * IOADBBus Class, which is an indirect driver designed to
        !            29:  * communicate with devices on the ADB bus.
        !            30:  *
        !            31:  * Note: this API is very preliminary and is expected to change drastically
        !            32:  * in future releases, caveat emptor.  In the future it will probably be based
        !            33:  * on some extension to the PortDevices protocol.
        !            34:  *
        !            35:  * define FAKE_ADB_DRIVER to true if you do not want to actually talk to the
        !            36:  * adb driver in the kernel, but rather talk to fake devices implemented here
        !            37:  *
        !            38:  *
        !            39:  * HISTORY
        !            40:  *  1997-12-19    Brent Schorsch (schorsch) created IOADBDevice.m
        !            41:  *  1998-01-19    Dave Suurballe transformed into IOADBBus.m
        !            42:  */
        !            43: 
        !            44: // DS2 #import <driverkit/ppc/IOADBDevice.h>
        !            45: #import <kernserv/prototypes.h>
        !            46: #import "busses.h"             // DS2
        !            47: #import <dev/ppc/adb.h>
        !            48: // DS2 #import <dev/ppc/adb_io.h>
        !            49: #import "IOADBBus.h"           // DS2
        !            50: #import "drvPMU/pmu.h"         // DS2
        !            51: 
        !            52: // DS2...
        !            53: 
        !            54: typedef struct privDataStruct
        !            55: {
        !            56: id             mDriver_p;         // pointer to Cuda or PMU driver
        !            57: } PrivDataT;
        !            58: 
        !            59: #define PrivDataSize (sizeof(PrivDataT))
        !            60: // ...DS2
        !            61: 
        !            62: #define mDriver (((PrivDataT *) _priv)->mDriver_p)
        !            63: 
        !            64: 
        !            65: extern void kprintf (const char * format, ...);
        !            66: extern void InitializeADB(void);
        !            67: extern int adb_flush(int);
        !            68: extern int adb_readreg2(int, int, unsigned char *, int *);
        !            69: extern int adb_writereg2(int, int, unsigned char *, int);
        !            70: 
        !            71: /* DS2...
        !            72: typedef struct privDataStruct
        !            73: {
        !            74: 
        !            75:     IOADBDeviceInfo mADBInfo_p;        //
        !            76: 
        !            77: #if FAKE_ADB_DRIVER
        !            78:     unsigned char mReg_p[4][IO_ADB_MAX_PACKET];
        !            79:     int mRegLen_p[4];
        !            80: #endif    
        !            81: } PrivDataT;
        !            82: #define PrivDataSize (sizeof(PrivDataT))
        !            83: 
        !            84: #define mADBInfo (((PrivDataT *) _priv)->mADBInfo_p)
        !            85: 
        !            86: #if FAKE_ADB_DRIVER
        !            87: #define mReg (((PrivDataT *) _priv)->mReg_p)
        !            88: #define mRegLen (((PrivDataT *) _priv)->mRegLen_p)
        !            89: #endif    
        !            90: 
        !            91: typedef struct _adbDeviceTableInfo
        !            92: {
        !            93:     IOADBDeviceInfo info;
        !            94:     IOADBDevice * object;
        !            95: } IOADBDeviceTableInfo;
        !            96: 
        !            97: static BOOL initialized = NO;
        !            98: static IOADBDeviceTableInfo gDeviceTable [IO_ADB_MAX_DEVICE*4];
        !            99: static int gDeviceCount;
        !           100: ...DS2 */
        !           101: 
        !           102: extern id              PMUdriver;                      // in adb.m  DS2
        !           103: extern adb_device_t    adb_devices[ADB_DEVICE_COUNT];  // in adb.m  DS2
        !           104: 
        !           105: /* FROM kernel/.../adb.c */
        !           106: #if !FAKE_ADB_DRIVER 
        !           107: extern boolean_t       adb_initted;
        !           108: extern int                     adb_count;
        !           109: 
        !           110: extern adb_device_t            adb_devices[];
        !           111: #endif
        !           112: /* END from kernel/.../adb.c */
        !           113: 
        !           114: // DS2 static IOReturn initalize (PrivDataT *_priv);
        !           115: 
        !           116: @implementation IOADBBus
        !           117: 
        !           118: // Class methods
        !           119: 
        !           120: // DS2...
        !           121: + (BOOL) probe: (id) deviceDescription
        !           122: {
        !           123: id dev;
        !           124: extern int kdp_flag;
        !           125: 
        !           126: if ( (dev = [ self alloc ]) == nil ) {
        !           127:        return NO;
        !           128:        }
        !           129: 
        !           130: if ([dev initFromDeviceDescription:deviceDescription] == nil) {
        !           131:        return NO;
        !           132:        }
        !           133: 
        !           134: [super init];
        !           135: 
        !           136: [dev setDeviceKind:"ADBBus"];
        !           137: [dev setLocation:NULL];
        !           138: [dev setName:"ADBBus"];
        !           139: [dev registerDevice];
        !           140: 
        !           141: if (kdp_flag & 1)
        !           142: {
        !           143:        call_kdp();
        !           144: }
        !           145: 
        !           146: return YES;
        !           147: }
        !           148: 
        !           149: 
        !           150: - initFromDeviceDescription:(IODeviceDescription *)deviceDescription
        !           151: {
        !           152:     _priv = NXZoneCalloc([self zone], 1, PrivDataSize);
        !           153: 
        !           154:     if (!_priv) {
        !           155:         return [super free];
        !           156:        }
        !           157: 
        !           158:     mDriver = [deviceDescription directDevice];
        !           159:     PMUdriver = mDriver;
        !           160:     InitializeADB();           // initialize adb and probe bus
        !           161: 
        !           162:     return self;
        !           163: }
        !           164: 
        !           165: + (IODeviceStyle) deviceStyle
        !           166: {
        !           167: return IO_IndirectDevice;
        !           168: }
        !           169: 
        !           170: static Protocol *protocols[] = {
        !           171:     @protocol(ADBservice),
        !           172:     nil
        !           173: };
        !           174: 
        !           175: + (Protocol **)requiredProtocols
        !           176: {
        !           177:     return protocols;
        !           178: }
        !           179: 
        !           180: // ...DS2
        !           181: 
        !           182: /*
        !           183:  * Call this method with an array that is IO_ADB_MAX_DEVICE long.
        !           184:  */
        !           185: - (IOReturn) GetTable: (IOADBDeviceInfo *) table
        !           186:                     : (int *) lenP
        !           187: {
        !           188:     IOReturn           status = IO_R_SUCCESS;
        !           189:     int                        index;
        !           190: 
        !           191: /* DS2...
        !           192:     initalize (_priv);
        !           193: 
        !           194:     *lenP = gDeviceCount;
        !           195: 
        !           196:     for (index = 0; index < gDeviceCount; index++)
        !           197:        table[index] = gDeviceTable.info;
        !           198: ...DS2 */
        !           199: 
        !           200: // DS2...
        !           201:     *lenP = IO_ADB_MAX_DEVICE;
        !           202: 
        !           203: for (index = 0; index < IO_ADB_MAX_DEVICE; index++) {
        !           204:        [self getADBInfo:index:&table[index]];
        !           205:        }
        !           206: // ...DS2
        !           207: 
        !           208:     return status;
        !           209: }
        !           210: 
        !           211: /* DS2...
        !           212: - initForDevice: (long) uniqueID
        !           213:               : (IOReturn *) result;
        !           214: {
        !           215:     int index;
        !           216: 
        !           217:     initalize (_priv);
        !           218: 
        !           219:     [super init];
        !           220: 
        !           221:     _priv = NXZoneCalloc([self zone], 1, PrivDataSize);
        !           222:     if (!_priv)
        !           223:     {
        !           224:        *result = IO_R_NO_MEMORY;
        !           225:         return [super free];
        !           226:     }
        !           227: 
        !           228:     for (index = 0; index < gDeviceCount; index++)
        !           229:        {
        !           230:         if (gDeviceTable[index].info.uniqueID == uniqueID)
        !           231:             break;
        !           232:        }
        !           233: 
        !           234:     if (index >= gDeviceCount)
        !           235:        {
        !           236:         *result = IO_R_NO_DEVICE;
        !           237:         return [self free];
        !           238:        }
        !           239: 
        !           240:     ASSERT (gDeviceTable[index].info.uniqueID == uniqueID);
        !           241: 
        !           242:     if (gDeviceTable[index].object != NULL)
        !           243:         {
        !           244:         *result = IO_R_PRIVILEGE;
        !           245:         return [self free];
        !           246:         }
        !           247: 
        !           248:     gDeviceTable[index].object = self;
        !           249: 
        !           250:     mADBInfo = gDeviceTable[index].info;
        !           251: 
        !           252: #if FAKE_ADB_DRIVER
        !           253:     mRegLen[0] = 0;
        !           254:     mRegLen[1] = 0;
        !           255:     mRegLen[2] = 0;
        !           256:     mRegLen[3] = 0;
        !           257: #endif
        !           258: 
        !           259:     *result = IO_R_SUCCESS;
        !           260:     return self;
        !           261: }
        !           262:  ...DS2 */
        !           263: 
        !           264: - free
        !           265: {
        !           266:     if (_priv)
        !           267:     {
        !           268:        NXZoneFree([self zone], _priv);
        !           269:        _priv = NULL;
        !           270:     }
        !           271: 
        !           272:     return [super free];
        !           273: }
        !           274: 
        !           275: - (IOReturn) getADBInfo: (int) whichDevice                     // DS2
        !           276:                       : (IOADBDeviceInfo *) deviceInfo
        !           277: {
        !           278: // DS2    deviceInfo = mADBInfo;
        !           279: 
        !           280: deviceInfo->originalAddress = adb_devices[whichDevice].a_dev_type;
        !           281: deviceInfo->address = adb_devices[whichDevice].a_addr;
        !           282: deviceInfo->originalHandlerID = adb_devices[whichDevice].a_dev_orighandler;
        !           283: deviceInfo->handlerID = adb_devices[whichDevice].a_dev_handler;
        !           284: deviceInfo->uniqueID = 0;
        !           285: deviceInfo->flags = adb_devices[whichDevice].a_flags;
        !           286: 
        !           287: return IO_R_SUCCESS;
        !           288: }
        !           289: 
        !           290: - (IOReturn) flushADBDevice: (int) whichDevice                 // DS2
        !           291: {
        !           292:     IOReturn   status = IO_R_SUCCESS;
        !           293: 
        !           294: /* DS2...
        !           295: #if !FAKE_ADB_DRIVER
        !           296:     adb_request_t   flush;
        !           297: 
        !           298:     adb_init_request(&flush);
        !           299:     ADB_BUILD_CMD2(&flush, ADB_PACKET_ADB, (ADB_ADBCMD_FLUSH_ADB | mADBInfo.address << 4));
        !           300:     adb_send(&flush, TRUE);
        !           301: 
        !           302:     status = flush.a_result;
        !           303: #endif
        !           304: ...DS2 */
        !           305: 
        !           306: adb_flush(whichDevice);                                                // DS2
        !           307: return status;
        !           308: }
        !           309: 
        !           310: /*
        !           311:  * Note, the buffers must be IO_ADM_MAX_PACKET long.
        !           312:  */
        !           313: - (IOReturn) readADBDeviceRegister: (int) whichDevice          // DS2
        !           314:                                  : (int) whichRegister
        !           315:                                  : (unsigned char *) buffer
        !           316:                                  : (int *) length;
        !           317: {
        !           318:     IOReturn   status = IO_R_SUCCESS;
        !           319:     
        !           320: /* DS2...
        !           321: #if FAKE_ADB_DRIVER
        !           322:     *length = mRegLen[whichRegister];
        !           323:     memcpy (buffer, mReg[whichRegister], mRegLen[whichRegister]);
        !           324: #else
        !           325:     adb_request_t   readreg;
        !           326: 
        !           327:     adb_init_request(&readreg);
        !           328:     ADB_BUILD_CMD2(&readreg, ADB_PACKET_ADB,
        !           329:                    (ADB_ADBCMD_READ_ADB | mADBInfo.address << 4 | whichRegister));
        !           330: 
        !           331:     adb_send(&readreg, TRUE);
        !           332: 
        !           333:     *length = readreg.a_reply.a_bcount;
        !           334:     memcpy (buffer, readreg.a_reply.a_buffer, length);
        !           335: 
        !           336:     status = readreg.a_result;
        !           337: #endif
        !           338: 
        !           339: ...DS2 */
        !           340: 
        !           341: adb_readreg2(whichDevice, whichRegister, buffer, length);              // DS2
        !           342: return status;
        !           343: }
        !           344: 
        !           345: - (IOReturn) writeADBDeviceRegister: (int) whichDevice                 // DS2
        !           346:                                   : (int) whichRegister
        !           347:                                   : (unsigned char *) buffer
        !           348:                                   : (int) length;
        !           349: {
        !           350:     IOReturn   status = IO_R_SUCCESS;
        !           351:     
        !           352: /* DS2...
        !           353: #if FAKE_ADB_DRIVER
        !           354:     mRegLen[whichRegister] = length;
        !           355:     memcpy (mReg[whichRegister], buffer, length);
        !           356: #else
        !           357:     adb_request_t   writereg;
        !           358: 
        !           359:     if (length > IO_ADB_MAX_PACKET) length = IO_ADB_MAX_PACKET;
        !           360: 
        !           361:     adb_init_request(&writereg);
        !           362:     ADB_BUILD_CMD2_BUFFER(&writereg, ADB_PACKET_ADB,
        !           363:                    (ADB_ADBCMD_WRITE_ADB | mADBInfo.address << 4 | whichRegister),
        !           364:                    length, buffer);
        !           365: 
        !           366:     adb_send(&writereg, TRUE);
        !           367: 
        !           368:     status = writereg.a_result;
        !           369: #endif
        !           370: 
        !           371: ...DS2 */
        !           372: 
        !           373: adb_writereg2(whichDevice, whichRegister, buffer, length);     // DS2
        !           374: return status;
        !           375: }
        !           376: 
        !           377: /* The state functions below are not currently implemented */
        !           378: /*
        !           379:  * Set the state for the port device.
        !           380:  */
        !           381: - (IOReturn) setState: (int) whichDevice                       // DS2
        !           382:                     : (IOADBDeviceState) state
        !           383:                     : (IOADBDeviceState) mask;
        !           384: {
        !           385:     return IO_R_UNSUPPORTED;
        !           386: }
        !           387: 
        !           388: /*
        !           389:  * Get the state for the port device.
        !           390:  */
        !           391: - (IOADBDeviceState) getState: (int) whichDevice               // DS2
        !           392: {
        !           393:     return IO_R_UNSUPPORTED;
        !           394: }
        !           395: 
        !           396: // DS2...
        !           397: - (IOReturn) adb_register_handler: (int) type          // DS2
        !           398:                                 : (autopoll_callback) handler
        !           399: {
        !           400: //kprintf("[IOADBBus adb_register_handler: %08x handler: %08x]\n",
        !           401: //     type, handler);
        !           402: 
        !           403:   adb_register_handler(type, handler);
        !           404:   return IO_R_SUCCESS;
        !           405: }
        !           406: // ...DS2
        !           407: /*
        !           408:  * Wait for the atleast one of the state bits defined in mask to be equal
        !           409:  * to the value defined in state.
        !           410:  * Check on entry then sleep until necessary.
        !           411:  */
        !           412: - (IOReturn) watchState: (int) whichDevice             // DS2
        !           413:                       : (IOADBDeviceState *) state
        !           414:                        : (IOADBDeviceState) mask
        !           415: {
        !           416: 
        !           417: return IO_R_UNSUPPORTED;
        !           418: }
        !           419: 
        !           420: 
        !           421: @end
        !           422: 
        !           423: /* DS2...
        !           424: static IOReturn initalize (PrivDataT *_priv)
        !           425: {
        !           426:     IOReturn   status = IO_R_SUCCESS;
        !           427: 
        !           428:     if (initialized)
        !           429:     {
        !           430:         if (gDeviceCount != adb_count)
        !           431:         {
        !           432:             IOLog ("Error! adb seems to have been reset, IOADBDevice is invalid!");
        !           433:             return IO_R_INTERNAL;
        !           434:        }
        !           435: 
        !           436:         return IO_R_SUCCESS;
        !           437:     }
        !           438: 
        !           439:     // build the table
        !           440: #if FAKE_ADB_DRIVER
        !           441:     gDeviceCount = 1;
        !           442:     gDeviceTable[0].info.originalAddress = 3;
        !           443:     gDeviceTable[0].info.address = 3;
        !           444:     gDeviceTable[0].info.originalHandlerID = 1;
        !           445:     gDeviceTable[0].info.handlerID = 4;
        !           446:     gDeviceTable[0].info.uniqueID = 1;
        !           447:     gDeviceTable[0].info.flags = kIOADBDeviceAvailable;
        !           448: 
        !           449:     gDeviceTable[0].object = NULL;
        !           450: 
        !           451: #else
        !           452:     int                        index;
        !           453:     int                        address;
        !           454:     adb_device_t       *adbDevice;
        !           455: 
        !           456:     if (!adb_initted) return IO_R_NOT_OPEN;
        !           457: 
        !           458:     gDeviceCount = adb_count;
        !           459:     address = 0;
        !           460: 
        !           461:     for (index = 0; index < gDeviceCount && address < IO_ADB_MAX_DEVICE; index++)
        !           462:     {
        !           463:         // scan thru adb addresses, looking for once that is present
        !           464:         while ((adb_devices[address].a_flags & ADB_FLAGS_PRESENT) == 0)
        !           465:             address++;
        !           466: 
        !           467:         if (address >= IO_ADB_MAX_DEVICE)
        !           468:             IOLog ("IOADBDevice->initialize error: adb devices count mismatch");
        !           469: 
        !           470:         gDeviceTable[index].info.originalAddress = adb_devices[address].a_dev_type;
        !           471:         gDeviceTable[index].info.address = adb_devices[address].a_addr; // (== address)
        !           472:         gDeviceTable[index].info.originalHandlerID = adb_devices[address].a_dev_orighandler;
        !           473:         gDeviceTable[index].info.handlerID = adb_devices[address].a_dev_handler;
        !           474:         gDeviceTable[index].info.uniqueID = index + 1;
        !           475:         gDeviceTable[index].info.flags = 0;
        !           476: 
        !           477:         // if the device is not registered, and not unresolved, they we can access it
        !           478:        if ((adb_devices[address].a_flags & ADB_FLAGS_REGISTERED) == 0) &&
        !           479:             (adb_devices[address].a_flags & ADB_FLAGS_UNRESOLVED) == 0))
        !           480:             gDeviceTable[index].info.flags |= kIOADBDeviceAvailable;
        !           481: 
        !           482:         gDeviceTable[index].object = NULL;
        !           483:     }
        !           484: #endif
        !           485:     
        !           486:     initialized = YES;
        !           487: 
        !           488:     return status;
        !           489: }
        !           490: 
        !           491: ...DS2 */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.