Annotation of driverkit/libDriver/Kernel/EventIO.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: /*     Copyright (c) 1992 NeXT Computer, Inc.  All rights reserved. 
                     25:  *
                     26:  * EventIO.m - Event System MiG interface for driver control and status.
                     27:  *
                     28:  * HISTORY
                     29:  * 2-April-92    Mike Paquette at NeXT 
                     30:  *      Created. 
                     31:  */
                     32: 
                     33: #import <objc/objc.h>
                     34: #import <driverkit/generalFuncs.h>
                     35: #import <driverkit/kernelDriver.h>
                     36: #import <bsd/dev/evio.h>
                     37: 
                     38: #import <kernserv/queue.h>
                     39: #import <bsd/dev/machine/ev_private.h> /* Per-machine configuration info */
                     40: #import <driverkit/EventDriver.h>
                     41: 
                     42: /*
                     43:  * Event Status services.
                     44:  *
                     45:  *     These functions invoke the normal Get and Set Parameter methods
                     46:  *     from an interface that does not require root access to use.  The
                     47:  *     Event Status subsystem is used by all apps that wish to modify
                     48:  *     or query system state maintained by the Event Status driver.
                     49:  *
                     50:  *     Items handled by this driver include key maps, key repeat rate,
                     51:  *     wait cursor behavior, mouse handedness and acceleration, screen
                     52:  *     brightness and autodim behavior, and much more.  We don't want apps
                     53:  *     which manipulate these things to run setuid as root.  (Think of the
                     54:  *     havoc that a setuid root version of BackSpace could cause...)
                     55:  */
                     56: IOReturn EvGetParameterInt(
                     57:        port_t dev_port,
                     58:        IOObjectNumber unit,
                     59:        IOParameterName parameterName,
                     60:        unsigned int maxCount,                  // 0 means "as much as
                     61:                                                //    possible"
                     62:        unsigned int *parameterArray,           // data returned here
                     63:        unsigned int *returnedCount)            // size returned here
                     64: {
                     65:        id instance;
                     66:        IOReturn rtn;
                     67:        unsigned count = maxCount;
                     68:        
                     69:        *returnedCount = maxCount;
                     70:        instance = [EventDriver instance];
                     71:        if(instance == nil)
                     72:                return IO_R_NOT_ATTACHED;
                     73:        rtn = [instance    getIntValues : parameterArray
                     74:                           forParameter:parameterName
                     75:                           count : &count];
                     76:        if(rtn == IO_R_SUCCESS) {
                     77:                *returnedCount = count;
                     78:        }
                     79:        return rtn;
                     80: 
                     81: }
                     82: 
                     83: IOReturn EvGetParameterChar(
                     84:        port_t dev_port,
                     85:        IOObjectNumber unit,
                     86:        IOParameterName parameterName,
                     87:        unsigned int maxCount,                  // 0 means "as much as
                     88:                                                //    possible"
                     89:        unsigned char *parameterArray,          // data returned here
                     90:        unsigned int *returnedCount)            // size returned here
                     91: {
                     92:        id instance;
                     93:        IOReturn rtn;
                     94:        unsigned count = maxCount;
                     95:        
                     96:        *returnedCount = maxCount;
                     97:        instance = [EventDriver instance];
                     98:        if(instance == nil)
                     99:                return IO_R_NOT_ATTACHED;
                    100:        rtn = [instance    getCharValues : parameterArray
                    101:                           forParameter:parameterName
                    102:                           count : &count];
                    103:        if(rtn == IO_R_SUCCESS) {
                    104:                *returnedCount = count;
                    105:        }
                    106:        return rtn;
                    107: 
                    108: }
                    109: 
                    110: IOReturn EvSetParameterInt(
                    111:        port_t dev_port,
                    112:        IOObjectNumber unit,
                    113:        IOParameterName parameterName,
                    114:        unsigned int *parameterArray,
                    115:        unsigned int count)                     // size of parameterArray
                    116: {
                    117:        id instance;
                    118: 
                    119:        instance = [EventDriver instance];
                    120:        if(instance == nil)
                    121:                return IO_R_NOT_ATTACHED;
                    122:        if (   strncmp( parameterName, EV_PREFIX, (sizeof EV_PREFIX) - 1 ) == 0
                    123:            && [instance ev_port] != dev_port )
                    124:                return IO_R_PRIVILEGE;
                    125:        return [instance    setIntValues : parameterArray
                    126:                           forParameter:parameterName
                    127:                           count : count];
                    128: }
                    129: 
                    130: 
                    131: IOReturn EvSetParameterChar(
                    132:        port_t dev_port,
                    133:        IOObjectNumber unit,
                    134:        IOParameterName parameterName,
                    135:        unsigned char *parameterArray,
                    136:        unsigned int count)                     // size of parameterArray
                    137: {
                    138:        id instance;
                    139: 
                    140:        instance = [EventDriver instance];
                    141:        if(instance == nil)
                    142:                return IO_R_NOT_ATTACHED;
                    143:        if (   strncmp( parameterName, EV_PREFIX, (sizeof EV_PREFIX) - 1 ) == 0
                    144:            && [instance ev_port] != dev_port )
                    145:                return IO_R_PRIVILEGE;
                    146:        return [instance    setCharValues : parameterArray
                    147:                           forParameter:parameterName
                    148:                           count : count];
                    149: }
                    150: 
                    151: /*
                    152:  * Event services.
                    153:  *
                    154:  *     These functions are invoked by a privileged port which can be
                    155:  *     obtained only by root.  The functions exist primarily to pass
                    156:  *     send rights on frame buffer ports out to the WindowServer, and
                    157:  *     to control specialized operations of the Event Driver including
                    158:  *     setting up the shared memory area.
                    159:  */
                    160: IOReturn EvOpen(
                    161:        port_t  dev_port,
                    162:        port_t  event_port )
                    163: {
                    164:        return [[EventDriver instance]  evOpen:dev_port token:event_port];
                    165: }
                    166: 
                    167: IOReturn EvClose(
                    168:        port_t  dev_port,
                    169:        port_t  event_port )
                    170: {
                    171:        return [[EventDriver instance]  evClose:dev_port token:event_port];
                    172: }
                    173: 
                    174: IOReturn EvSetSpecialKeyPort(
                    175:        port_t  dev_port,
                    176:        int     special_key,
                    177:        port_t  key_port )
                    178: {
                    179:        return [[EventDriver instance]  setSpecialKeyPort:dev_port
                    180:                                        keyFlavor: special_key
                    181:                                        keyPort:key_port];
                    182: }
                    183: 
                    184: /*
                    185:  *     FIXME: These routines only work from within the kernel.
                    186:  */
                    187: #ifdef KERNEL
                    188: IOReturn EvMapEventShmem(
                    189:        port_t dev_port,        // Only ev_port allowed
                    190:        port_t event_port,
                    191:        port_t task,            // Task to map shared memory into
                    192:        vm_size_t size,         // Size of shared memory area in bytes
                    193:        vm_offset_t *addr )     // Returned address of shared memory
                    194: {
                    195:        return [[EventDriver instance]  mapEventShmem:event_port
                    196:                                        task:task
                    197:                                        size:size
                    198:                                        at:addr];
                    199: }
                    200: 
                    201: IOReturn EvFrameBufferDevicePort(
                    202:        port_t dev_port,
                    203:        port_t event_port,
                    204:        IOString name,
                    205:        IOString class,
                    206:        port_t *nameDevicePort )
                    207: {
                    208:     return [[EventDriver instance]  evFrameBufferDevicePort:event_port
                    209:                                    unitName:name
                    210:                                    unitClass:class
                    211:                                    unitPort:nameDevicePort];
                    212: }
                    213: 
                    214: /*
                    215:  * Additional kernel API to drivers using the Event Driver
                    216:  */
                    217:  int
                    218: EventCoalesceDisplayCmd( int cmd, int oldcmd )
                    219: {
                    220:        static const char coalesce[4][4] = {
                    221:            /* nop */  {EVNOP,  EVHIDE, EVSHOW, EVMOVE},
                    222:            /* hide */ {EVHIDE, EVHIDE, EVNOP,  EVSHOW},
                    223:            /* show */ {EVSHOW, EVNOP,  EVSHOW, EVSHOW},
                    224:            /* move */ {EVMOVE, EVHIDE, EVSHOW, EVMOVE}
                    225:        };
                    226:        if ( cmd < EVLEVEL )    // coalesce EVNOP thru EVMOVE only
                    227:            cmd = coalesce[oldcmd & 3][cmd & 3];
                    228:        return cmd;
                    229: }
                    230: 
                    231: #endif /* KERNEL */
                    232: 

unix.superglobalmegacorp.com

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