Annotation of driverkit/libDriver/pcmcia/IOPCMCIADirectDevice.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) 1994 NeXT Computer, Inc.
                     26:  *
                     27:  * PCMCIA direct device implementation.
                     28:  *
                     29:  * HISTORY
                     30:  *
                     31:  * 17 May 1994 Curtis Galloway at NeXT
                     32:  *     Created.
                     33:  *
                     34:  *
                     35:  */
                     36: 
                     37: #define KERNEL_PRIVATE 1
                     38: 
                     39: #import <driverkit/i386/IOPCMCIADirectDevice.h>
                     40: #import <driverkit/IODirectDevicePrivate.h>
                     41: 
                     42: #import <driverkit/KernDeviceDescription.h>
                     43: #import <driverkit/i386/PCMCIAKernBus.h>
                     44: #import <driverkit/KernBusMemory.h>
                     45: #import <driverkit/KernDevice.h>
                     46: #import <driverkit/KernDeviceDescription.h>
                     47: #import <driverkit/i386/PCMCIAPool.h>
                     48: 
                     49: #define ATTRIBUTE_MAPPING_KEY  "PCMCIA_DEVICE_ATTR_MAPPING"
                     50: 
                     51: @implementation IODirectDevice(IOPCMCIADirectDevice)
                     52: 
                     53: - (IOReturn) mapAttributeMemoryTo:(vm_address_t *) destAddr
                     54:                        findSpace:(BOOL) findSpace
                     55: {
                     56:        struct _eisa_private            *private = _busPrivate;
                     57:        id                              mapping, mappingList;
                     58:        id                              resource;
                     59:        id                              socketElement;
                     60:        id                              memWindowElement, memWindow;
                     61:        id                              windowList;
                     62:        Range                           memRange;
                     63:        id                              thePCMCIABus;
                     64:                                        
                     65:        thePCMCIABus = [KernBus lookupBusInstanceWithName:"PCMCIA" busId:0];
                     66:        
                     67:        if ([_deviceDescriptionDelegate
                     68:            resourcesForKey:ATTRIBUTE_MAPPING_KEY]) {
                     69:                return IO_R_BUSY;
                     70:        }
                     71:        /* Get memory window */
                     72:        socketElement = [[_deviceDescriptionDelegate
                     73:            resourcesForKey:PCMCIA_SOCKET_LIST] objectAt:0];
                     74:        if (socketElement == nil)
                     75:                return IO_R_RESOURCE;
                     76:        memWindowElement = [thePCMCIABus allocMemoryWindowForSocket:
                     77:            [socketElement object]];
                     78:        if (memWindowElement == nil)
                     79:                return IO_R_RESOURCE;
                     80:        windowList = [_deviceDescriptionDelegate
                     81:            resourcesForKey:PCMCIA_WINDOW_LIST];
                     82:        
                     83:        resource = [thePCMCIABus memoryRangeResource];
                     84:        
                     85:        if (findSpace)
                     86:                mapping =
                     87:                    [resource mapInTarget:current_task_EXTERNAL()
                     88:                              cache:NO];
                     89:        else
                     90:                mapping =
                     91:                    [resource mapToAddress:*destAddr
                     92:                              inTarget:current_task_EXTERNAL()
                     93:                              cache:NO];
                     94: 
                     95:        if (mapping == nil) {
                     96:                [memWindowElement free];
                     97:                return IO_R_NO_MEMORY;
                     98:        }
                     99:                
                    100:        *destAddr = [mapping address];
                    101: 
                    102:        mappingList = [[List alloc] initCount:1];
                    103:        [mappingList addObject:mapping];
                    104:        [_deviceDescriptionDelegate
                    105:            setResources:mappingList forKey:ATTRIBUTE_MAPPING_KEY];
                    106: 
                    107:        memWindow = [memWindowElement object];
                    108:        memRange = [resource range];
                    109:        [memWindow setEnabled:NO];
                    110:        [memWindow setMemoryInterface:YES];
                    111:        [memWindow setAttributeMemory:YES];
                    112:        [memWindow setMapWithSize:memRange.length
                    113:                systemAddress:memRange.base cardAddress:0];
                    114:        [memWindow setEnabled:YES];
                    115:        [[memWindow socket] setMemoryInterface:YES];
                    116: 
                    117:        [windowList addObject:memWindowElement];
                    118: 
                    119:        return IO_R_SUCCESS;
                    120: }
                    121: 
                    122: - (void) unmapAttributeMemory
                    123: {
                    124:        struct _eisa_private            *private = _busPrivate;
                    125:        id                              windowList;
                    126:        int                             i;
                    127: 
                    128:        if ([_deviceDescriptionDelegate
                    129:            resourcesForKey:ATTRIBUTE_MAPPING_KEY] == nil)
                    130:                return;
                    131: 
                    132:        /* Find the memory window */
                    133:        windowList = [_deviceDescriptionDelegate
                    134:            resourcesForKey:PCMCIA_WINDOW_LIST];
                    135:        
                    136:        for (i=0; i < [windowList count]; i++) {
                    137:            id window, windowElement;
                    138:            
                    139:            windowElement = [windowList objectAt:i];
                    140:            window = [windowElement object];
                    141:            if ([window memoryInterface] && [window attributeMemory]) {
                    142:                /* Right now there is only one attribute memory window allowed,
                    143:                 * so assume this is the right one.
                    144:                 */
                    145:                [window setAttributeMemory:NO];
                    146:                [window setEnabled:NO];
                    147:                [[window socket] setMemoryInterface:NO];
                    148:                [windowList removeObject:windowElement];
                    149:                [windowElement free];
                    150:                break;
                    151:            }
                    152:        }
                    153:        
                    154:        /* This will free the mapping */
                    155:        [_deviceDescriptionDelegate
                    156:            removeResourcesForKey:ATTRIBUTE_MAPPING_KEY];
                    157: }
                    158: 
                    159: @end
                    160: 

unix.superglobalmegacorp.com

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