Annotation of driverkit/libDriver/pci/IOPCIDeviceDescription.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) 1994 NeXT Computer, Inc.
        !            26:  *
        !            27:  * PCI device description class.
        !            28:  *
        !            29:  * HISTORY
        !            30:  *
        !            31:  * 19 Aug 1994 Dean Reece at NeXT
        !            32:  *     Complete re-write (it was just a placeholder)
        !            33:  *
        !            34:  * 19 Jul 1994 Curtis Galloway at NeXT
        !            35:  *     Created.
        !            36:  */
        !            37:  
        !            38: #define KERNEL_PRIVATE 1
        !            39: 
        !            40: #import <driverkit/KernDeviceDescription.h>
        !            41: #import <driverkit/i386/IOPCIDeviceDescription.h>
        !            42: #import <driverkit/i386/IOPCIDeviceDescriptionPrivate.h>
        !            43: #import <driverkit/i386/PCIKernBus.h>
        !            44: #import <driverkit/IODeviceDescriptionPrivate.h>
        !            45: #import <driverkit/i386/directDevice.h>
        !            46: 
        !            47: struct _pci_private {
        !            48:     BOOL               valid;
        !            49:     unsigned char      devNum, funNum, busNum;
        !            50: };
        !            51: 
        !            52: @implementation IOPCIDeviceDescription(Private)
        !            53: 
        !            54: /*
        !            55:  * Here we init the PCI device description by calling thePCIBus to
        !            56:  * decode our configTable and extract the bits necessary to determine
        !            57:  * the PCI address.  If the thePCIBus object is absent or claims no
        !            58:  * PCI bus, then we just set valid to NO.
        !            59:  *
        !            60:  * XXX Implementation Note:  It seems odd that thePCIBus object handles
        !            61:  * parsing the configTable, rather than doing it here.  This division
        !            62:  * of functionality was choosen to allow easy replacement; thePCIBus is
        !            63:  * a loadable driver, but IOPCIDeviceDescription is statically linked
        !            64:  * into the kernel.  If/when the driverkit stuff gets moved to a loadable
        !            65:  * module, [thePCIBus configAddress] should be moved here.
        !            66:  */
        !            67: - _initWithDelegate:delegate
        !            68: {
        !            69:     struct _pci_private *private;
        !            70:     id thePCIBus = [KernBus lookupBusInstanceWithName:"PCI" busId:0];
        !            71: 
        !            72:     [super _initWithDelegate:delegate];
        !            73: 
        !            74:     _pci_private = (void *)IOMalloc(sizeof(struct _pci_private));
        !            75:     private = (struct _pci_private *)_pci_private;
        !            76: 
        !            77:     private->valid =  ( (thePCIBus != nil) &&
        !            78:        ([thePCIBus isPCIPresent] == YES) &&
        !            79:        ([thePCIBus configAddress: delegate
        !            80:                           device: &(private->devNum)
        !            81:                         function: &(private->funNum)
        !            82:                              bus: &(private->busNum)] == IO_R_SUCCESS)
        !            83:             );
        !            84:     return self;       
        !            85: }
        !            86: 
        !            87: @end
        !            88: 
        !            89: @implementation IOPCIDeviceDescription
        !            90: 
        !            91: - free
        !            92: {
        !            93:     struct _pci_private *private = (struct _pci_private *)_pci_private;
        !            94: 
        !            95:     IOFree(private, sizeof(struct _pci_private));
        !            96:     return [super free];
        !            97: }
        !            98: 
        !            99: /*
        !           100:  * getPCIdevice is the whole purpose for this object.  This method allows
        !           101:  * callers to get the PCI config address of the PCI device associated
        !           102:  * with this device description.  If all goes well, the three params are
        !           103:  * filled in and IO_R_SUCCESS is returned.  There are a variety of reasons
        !           104:  * that the address couldn't be known, in which case an appropriate code is
        !           105:  * returned and the parameters are left untouched.  It is acceptable for any
        !           106:  * of the parameter pointers to be NULL.
        !           107:  */
        !           108: - (IOReturn) getPCIdevice: (unsigned char *) devNum
        !           109:                 function: (unsigned char *) funNum
        !           110:                      bus: (unsigned char *) busNum
        !           111: {
        !           112:     struct _pci_private *private = (struct _pci_private *)_pci_private;
        !           113: 
        !           114:     if (private->valid) {
        !           115:        if (devNum) *devNum = private->devNum;
        !           116:        if (funNum) *funNum = private->funNum;
        !           117:        if (busNum) *busNum = private->busNum;
        !           118:        return IO_R_SUCCESS;
        !           119:     }
        !           120:     return IO_R_NO_DEVICE;
        !           121: }
        !           122: 
        !           123: - property_IODeviceType:(char *)types length:(unsigned int *)maxLen
        !           124: {
        !           125:     [super property_IODeviceType:types length:maxLen];
        !           126:     strcat( types, " "IOTypePCI);
        !           127:     return( self);
        !           128: }
        !           129: 
        !           130: - property_IOSlotName:(char *)name length:(unsigned int *)maxLen
        !           131: {
        !           132:     struct _pci_private *private = (struct _pci_private *)_pci_private;
        !           133: 
        !           134:     if (private->valid) {
        !           135:        sprintf( name, "Dev=%d Func=%d Bus=%d",
        !           136:             private->devNum, private->funNum, private->busNum );
        !           137:        return self;
        !           138:     }
        !           139:     return nil;
        !           140: }
        !           141: 
        !           142: @end

unix.superglobalmegacorp.com

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