Annotation of kernel/bsd/dev/ppc/PPCMouse.m, revision 1.1.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) 1992 NeXT Computer, Inc.  All rights reserved. 
                     26:  *
                     27:  * PPCMouse.m - PPC mouse driver.
                     28:  * 
                     29:  *
                     30:  * HISTORY
                     31:  * 14-Aug-92    Joe Pasqua at NeXT
                     32:  *      Created. 
                     33:  * 08-Feb-94   
                     34:  *     Modified for hppa (PS2)
                     35:  * 11-April-97   Simon Douglas
                     36:  *      Munged into ADB version. Doesn't depend on PPCKeyboard.
                     37:  */
                     38:  
                     39: // TO DO:
                     40: //   Make this an indirect client of ADB. ADB should probe to create multiple
                     41: //   event sources.
                     42: // Notes:
                     43: // * To find things that need to be fixed, search for FIX, to find questions
                     44: //   to be resolved, search for ASK, to find stuff that still needs to be
                     45: //   done, search for TO DO.
                     46: //
                     47: 
                     48: #define MACH_USER_API  1
                     49: #undef KERNEL_PRIVATE
                     50: 
                     51: #import <driverkit/driverServer.h>
                     52: #import <driverkit/generalFuncs.h>
                     53: #import <driverkit/interruptMsg.h>
                     54: #import <mach/mach_interface.h>
                     55: #import <bsd/dev/ppc/PPCMouse.h>
                     56: #import <bsd/dev/ppc/PCPointerDefs.h>
                     57: #import <bsd/dev/ppc/PPCKeyboard.h>
                     58: #import <bsd/dev/ppc/PPCKeyboardPriv.h>
                     59: #import <driverkit/ppc/directDevice.h>
                     60: #import <driverkit/ppc/driverTypes.h>
                     61: 
                     62: #include <mach_kdb.h>
                     63: #include <mach/mach_types.h>
                     64: #include <sys/tty.h>
                     65: #include <sys/conf.h>
                     66: #include <machdep/ppc/mach_param.h>
                     67: #include <machine/machspl.h>
                     68: #import <kern/thread_call.h>
                     69: 
                     70: #include "busses.h"
                     71: #include "adb.h"
                     72: #import  <bsd/dev/ppc/IOADBBus.h>
                     73: 
                     74: int set_handler(int device, int handler);
                     75: 
                     76: static PointerEvent event;
                     77: 
                     78: PPCMouse *_my_Mouse;
                     79: 
                     80: extern unsigned int wserver_on;
                     81: 
                     82: /* Forward declarations */
                     83: static void mouse_intr();
                     84: 
                     85: #define msg_printf printf
                     86: 
                     87: 
                     88: @implementation PPCMouse
                     89: 
                     90: static id  adb_driver;// pointer to adb indirect driver
                     91: 
                     92: + (BOOL)probe:(IODeviceDescription *)deviceDescription
                     93: {
                     94:   BOOL return_code;
                     95: 
                     96:   adb_driver = [deviceDescription directDevice];
                     97: 
                     98:   return_code = [super probe: deviceDescription];
                     99: 
                    100:   return return_code;
                    101: }
                    102: 
                    103: + (IODeviceStyle) deviceStyle
                    104: {
                    105:   return IO_IndirectDevice;
                    106: }
                    107: 
                    108: static Protocol *protocols[] = {
                    109:       @protocol(ADBprotocol),
                    110:       nil
                    111: };
                    112: 
                    113: + (Protocol **)requiredProtocols
                    114: {
                    115:       return protocols;
                    116: }
                    117: 
                    118: //
                    119: // BEGIN:      Implementation of internal support methods
                    120: //
                    121: 
                    122: void mouse_adbhandler(int number, unsigned char *buffer, int count, void * ssp);
                    123: 
                    124: struct ADBDeviceData
                    125: {
                    126:     unsigned int       type;
                    127:     unsigned int       resolution;
                    128:     unsigned int       buttonCount;
                    129: };
                    130: typedef struct ADBDeviceData ADBDeviceData;
                    131: static ADBDeviceData deviceInfo[ADB_DEVICE_COUNT];
                    132: 
                    133: boolean_t   mouse_initted = FALSE;
                    134: 
                    135: - (void) mouseInit
                    136: {
                    137:     int i, ret;
                    138:     IOADBDeviceInfo  table[IO_ADB_MAX_DEVICE];
                    139:     unsigned char    buffer[8];
                    140:     int              length;
                    141: 
                    142:     resolution = 200;                                          // what event source sees
                    143:     [adb_driver adb_register_handler:ADB_DEV_MOUSE :mouse_adbhandler];
                    144: 
                    145:     [adb_driver GetTable:table :&i];
                    146: 
                    147:     for (i = 0; i < ADB_DEVICE_COUNT; i++) {
                    148: 
                    149:        int thisDeviceResolution, thisDeviceType, thisButtonCount;
                    150: 
                    151:         if ((table[i].flags & ADB_FLAGS_PRESENT) == 0)
                    152:             continue;
                    153:        if (table[i].originalAddress != ADB_DEV_MOUSE)
                    154:             continue;
                    155: 
                    156:        thisDeviceType = 2;
                    157:        thisDeviceResolution = 200;
                    158:        thisButtonCount = 1;
                    159: 
                    160:        ret = set_handler(i, 4);
                    161:        if( ret == ADB_RET_OK) {
                    162:            adb_request_t   readreg;
                    163: 
                    164:            thisDeviceType = 4;
                    165:        
                    166:            [adb_driver readADBDeviceRegister:i :1 :buffer :&length];
                    167:            if ( length == 8 ) {
                    168:              thisDeviceResolution = (buffer[4] << 8) | buffer[5];
                    169:              thisButtonCount = buffer[7];
                    170:            }
                    171:        } else {
                    172:            ret = set_handler(i, 2);
                    173:            if( ret != ADB_RET_OK) {
                    174:                thisDeviceType = 1;
                    175:                thisDeviceResolution = 100;
                    176:            }
                    177:        }
                    178:        deviceInfo[ i ].type            = thisDeviceType;
                    179:        deviceInfo[ i ].resolution      = thisDeviceResolution;
                    180:        deviceInfo[ i ].buttonCount     = thisButtonCount;
                    181:    }
                    182: }
                    183: 
                    184: 
                    185: static void mouse_intr()
                    186: {
                    187:        [_my_Mouse interruptHandler];
                    188: }
                    189: 
                    190: void 
                    191: mouse_adbhandler(int number, unsigned char *buffer, int count, void * ssp)
                    192: {
                    193:     int i;
                    194: 
                    195:     /* If window server is not up no further processing is needed */
                    196:     if (wserver_on == 0) return;
                    197: 
                    198:     if ( buffer[0] & 0x80 ) event.b0 = TRUE;
                    199:     else event.b0 = FALSE;
                    200:     if ( buffer[1] & 0x80 ) event.b1 = TRUE;
                    201:     else event.b1 = FALSE;
                    202:     event.b2 = TRUE;
                    203:     event.b3 = TRUE;
                    204:     event.dx = buffer[1] & 0x7F;
                    205:     event.dy = buffer[0] & 0x7F;
                    206:     if ( count > 2 ) {                           // 3 or 4-button mouse
                    207:       if ( buffer[2] & 0x80 ) event.b2 = TRUE;
                    208:       else event.b2 = FALSE;
                    209:       if ( buffer[2] & 0x08 ) event.b3 = TRUE;
                    210:       else event.b3 = FALSE;
                    211:                                // get higher order bits from subsequent bytes
                    212:       for ( i = 2; i < count; i++ ) {
                    213:          event.dy = event.dy + ((buffer[i] & 0x70) << ((3*i)-3));
                    214:          event.dx = event.dx + ((buffer[i] & 0x07) << ((3*i)+1));
                    215:       }
                    216:     }
                    217:                                // sign-extend
                    218:     if ( event.dx & (1 << (count*3)) ) event.dx -= 1 << ((count*3)+1);
                    219:     if ( event.dy & (1 << (count*3)) ) event.dy -= 1 << ((count*3)+1);
                    220:    
                    221:     event.buttonCount = deviceInfo[ number ].buttonCount;
                    222:     
                    223: #if    DRVRKITINTS
                    224:        IOSendInterrupt(identity, state, IO_DEVICE_INTERRUPT_MSG);
                    225: #else
                    226:        thread_call_func((thread_call_func_t)mouse_intr,0, TRUE);
                    227: #endif DRVRKITINTS
                    228: 
                    229: }
                    230: 
                    231: - (BOOL)mouseInit:deviceDescription
                    232: // Description:        Initialize the mouse object.
                    233: {
                    234:     if( mouse_initted == FALSE)
                    235:     {
                    236:        mouse_initted = TRUE;
                    237:     
                    238:        [self setDeviceKind:"PPCMouse"];
                    239:     
                    240: #ifdef DRVRKITINTS
                    241:        [self enableAllInterrupts];
                    242: #endif DRVRKITINTS
                    243:     
                    244:        [self mouseInit];
                    245:        
                    246:        _my_Mouse = self;
                    247:     }
                    248: 
                    249: 
                    250:     return YES;        
                    251: }
                    252: 
                    253: int
                    254: set_handler(int device, int handler)
                    255: {
                    256:       unsigned long   retval;
                    257:       unsigned char   value[8];
                    258:       int             length;
                    259: 
                    260:       retval = [adb_driver readADBDeviceRegister:device :3 :value :&length];
                    261: 
                    262:       if (retval != ADB_RET_OK)
                    263:        return retval;
                    264: 
                    265:       value[0] &= 0xF0;
                    266:       value[1] = handler;
                    267: 
                    268:       retval = [adb_driver writeADBDeviceRegister:device :3 :value :length];
                    269: 
                    270:       if (retval != ADB_RET_OK)
                    271:        return retval;
                    272: 
                    273:       retval = [adb_driver readADBDeviceRegister:device :3 :value :&length];
                    274: 
                    275:       if (retval != ADB_RET_OK)
                    276:        return retval;
                    277: 
                    278:       if (value[1] != handler)
                    279:        retval = ADB_RET_UNEXPECTED_RESULT;
                    280: 
                    281:       return( retval );
                    282: }
                    283: 
                    284: 
                    285: //
                    286: // END:                Implementation of internal support methods
                    287: //
                    288: 
                    289: //
                    290: // BEGIN:      Implementation of EXPORTED methods
                    291: //
                    292: - free
                    293: {
                    294:     return [super free];
                    295: }
                    296: 
                    297: 
                    298: - (BOOL) getHandler:(IOPPCInterruptHandler *)handler
                    299:               level:(unsigned int *) ipl
                    300:           argument:(unsigned int *) arg
                    301:        forInterrupt:(unsigned int) localInterrupt
                    302: {
                    303: #ifdef DRVRKITINTS
                    304:     *handler = PPCMouseIntHandler;
                    305:     *ipl = 3;
                    306:     *arg = 0xdeadbeef;
                    307:     return YES;
                    308: #endif DRVRKITINTS
                    309:    return NO;
                    310: }
                    311: 
                    312: 
                    313: - (void)interruptHandler
                    314: {
                    315:     IOGetTimestamp(&event.timeStamp);
                    316:     if (target != nil)
                    317:     {
                    318:        [target dispatchPointerEvent:&event];
                    319:     }
                    320: }
                    321: 
                    322: 
                    323: - (int)getResolution
                    324: {
                    325:     return resolution;
                    326: }
                    327: //
                    328: // END:                Implementation of EXPORTED methods
                    329: //
                    330: @end

unix.superglobalmegacorp.com

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