Annotation of kernel/bsd/dev/ppc/drvUSBCMD/usbcmd.m, revision 1.1.1.2

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: /*********
                     26: 
                     27: usbcmd.m
                     28: This is a preliminary driver for the CMD PCI USB card on my
                     29: PowerSurge 8500.
                     30: 
                     31:        Common USB terms:  TD is Transfer Descriptor, ED is Endpoint Descriptor.
                     32: * Naga Pappireddi 12-17-98 Radar bug# 2293217   Cleanup of code in GetErrataBits function to read the registry properties
                     33: *                           this cleanup took care of LED problem on Yosemite 
                     34: 
                     35: *********/
                     36: 
                     37: 
                     38: #import <kern/clock.h>
                     39: #import <machdep/ppc/interrupts.h>
                     40: #import <kernserv/prototypes.h>
                     41: #import <kernserv/clock_timer.h>
                     42: #import <kernserv/ns_timer.h>
                     43: #import <sys/time.h>
                     44: #import <sys/callout.h>
                     45: #import <machdep/ppc/proc_reg.h>
                     46: #import <driverkit/generalFuncs.h>
                     47: #import <driverkit/kernelDriver.h>
                     48: #import <driverkit/interruptMsg.h>
                     49: #import <driverkit/ppc/IODBDMA.h>  //for ReadSwap32() only
                     50: #import <driverkit/align.h>  //for IOAlign() only
                     51: #import "usbcmd.h"
                     52: 
1.1.1.2 ! root       53: extern unsigned char usb_2_adb_keymap[];  // 3/19/99 Canadian changes
1.1       root       54: extern id ApplePMUId;  //in adb.m (remove this when adb becomes an indirect driver)(q8q)
                     55: extern id usb_UIM_object; //in bsd/dev/ppc/EventSrcPCKeyboard.m
                     56: extern unsigned int usb_kbd_vendor_id, usb_kbd_product_id; //in uslExpert.c  
                     57: 
                     58: int     OHCIUIMInitialize(unsigned long ioBase);
                     59: void pollRootHubSim(void);
                     60: IOThreadFunc usb_thread(void *);
                     61: void IOSync(void)
                     62: {
                     63: eieio();
                     64: }
                     65: extern OHCIUIMDataPtr                          pOHCIUIMData;
                     66: extern void kprintf(const char *, ...);
                     67: extern void bcopy(void *, void *, int);
                     68: extern void usb_intr(int intr, void *ssp, void *dev);
                     69: #define printf usb_donone 
                     70: #define kprintf usb_donone
                     71: void usb_donone(char *x,...);
                     72: 
                     73: 
                     74: //OSStatus OHCIUIMInterruptHandler (InterruptSetMember member, void *refCon, UInt32 interruptCount);
                     75: extern int kdp_flag;
                     76: int usb_port_configured[2] = {0,0};
                     77: 
                     78: IOPropertyTable *usb_propTable;
                     79: IOPCIDevice *devUsb;
                     80: AppleUSBCMD *selfUsb;
                     81: int  cmd_pci_errata;  //global needed to fix errata for Caps Lock LED support
                     82: 
                     83: unsigned int
                     84: usb_swap_word(unsigned int  input)
                     85: {
                     86:     int lo, hi;  
                     87: 
                     88:     lo = 0x00ff & input;
                     89:     lo = lo << 8;       
                     90:     hi = input >> 8;
                     91:     return (hi | lo);     
                     92: }
                     93: 
                     94: void enable_intr()
                     95: {
                     96:     [selfUsb enableAllInterrupts];
                     97: }
                     98:      
                     99: void ReadConfigVal(UInt32 ctl, UInt32 *val)
                    100: {
                    101:     [devUsb configReadLong:ctl value:val];
                    102: }
                    103:        
                    104: void WriteConfigVal(UInt32 ctl, UInt32 val)
                    105: {
                    106:     [devUsb configWriteLong:ctl value:val];
                    107: }
                    108: 
                    109: @implementation AppleUSBCMD
                    110: 
                    111: // **********************************************************************************
                    112: // probe
                    113: //
                    114: // 
                    115: //
                    116: // **********************************************************************************
                    117: + (Boolean) probe : deviceDescription
                    118: {
                    119:   id dev;
                    120: //kdp_flag=2;
                    121: kprintf("usb probe\n");
                    122:     usb_propTable = [deviceDescription propertyTable]; /* For use with RegistryPropertyGet */
                    123: 
                    124:        if ( (dev = [ self alloc ]) == nil ) {
                    125:                return NO;
                    126:        }
                    127: 
                    128:        if ([dev initFromDeviceDescription:deviceDescription] == nil) {
                    129:                return NO;
                    130:        }
                    131:        
                    132:     usb_UIM_object = dev;
                    133: 
                    134: kprintf("naga:Successful probe of USB\n");
                    135:        return YES;
                    136: }
                    137: 
                    138: 
                    139: // **********************************************************************************
                    140: // initFromDeviceDescription
                    141: //
                    142: // 
                    143: //- initFromDeviceDescription:(IODeviceDescription *)deviceDescription
                    144: //- initFromDeviceDescription:(IOPCIDevice *)deviceDescription
                    145: //
                    146: // **********************************************************************************
                    147: - initFromDeviceDescription:(IODeviceDescription *) devDesc 
                    148: {
                    149:        IORange *       ioRange;
                    150:        int                     numRanges;
                    151:         int irq;
                    152:        unsigned long           PCICommandReg;
                    153:        IOPCIDevice *deviceDescription = (IOPCIDevice *)devDesc;
                    154:        char    *tbuf;
                    155: 
                    156: 
                    157:         devUsb = (IOPCIDevice *)devDesc;
                    158:         selfUsb=self;
                    159:        if ( [super initFromDeviceDescription:deviceDescription] == nil ) 
                    160:         {
                    161:                [self free];
                    162:                return nil;
                    163:        }
                    164: 
                    165:        [self setDeviceKind:"USB-CMD Subsystem"];
                    166:        [self setLocation:NULL];
                    167:        [self setName:"USBCMD"];  
                    168: 
                    169:        tbuf = [devDesc nodeName];
                    170: //CMD card is "pci1095,670"  
                    171:        cmd_pci_errata = 0;
                    172:        if (!strcmp(tbuf, "pci1095,670")) //if match Open Firmware string
                    173:        {
                    174:                cmd_pci_errata = 1;
                    175:        }
                    176: 
                    177: 
                    178:        ioRange = [deviceDescription memoryRangeList];
                    179:        //ioRange->start is 0x80800000 for my PCI USB card
                    180:        kprintf("USB Start of mem is %x\n", ioRange->start);
                    181: 
                    182:         numRanges = [deviceDescription numMemoryRanges];
                    183:        kprintf("USB numRanges is %d\n", numRanges);
                    184:     // This causes crash [self isPCIPresent];
                    185: 
                    186:        if (numRanges < 1 )
                    187:        {
                    188:           IOLog( "USB-CMD: Incorrect deviceDescription - 1\n\r");
                    189:           return nil;
                    190:        }
                    191:        ioBase = 0;
                    192:        [self mapMemoryRange: 0 to:(vm_address_t *)&ioBase findSpace:YES cache:IO_CacheOff];
                    193:        kprintf("USB ioBase is %x\n", ioBase); //Should be 3519000 on PowerSurge (Heathrow)
                    194: 
                    195:     /*
                    196:      * BUS MASTER, MEM I/O Space, MEM WR & INV
                    197:      */
                    198: 
                    199:     [deviceDescription configWriteLong:0x04 value:0x16];
                    200: #ifdef OMIT
                    201:     [deviceDescription configReadLong:0x04 value:&PCICommandReg];
                    202:     PCICommandReg |= (4 | 1);  // Master & Memory
                    203:     PCICommandReg &= ~2;       // Not I/O
                    204:     [deviceDescription configWriteLong:0x04 value:PCICommandReg];
                    205: #endif
                    206: 
                    207: OHCIUIMInitialize( ioBase);
                    208: USBServicesInitialise(nil);
                    209: 
                    210: if ([self startIOThread] != IO_R_SUCCESS)
                    211: {       
                    212:     [self free];
                    213:     kprintf("USB thread error \n");
                    214:     return nil;
                    215: }
                    216:  port = IOConvertPort([self interruptPort],IO_KernelIOTask,IO_Kernel);
                    217:        kprintf("USB port is %x\n", port);
                    218:        [self registerDevice];
                    219:         irq = [devDesc interrupt];
                    220:         {
                    221:              IOThread tid;
                    222:              tid = IOForkThread(usb_thread, (void *)0);
                    223:         }
                    224:        return self;
                    225: }
                    226: 
                    227: // **********************************************************************************
                    228: // free
                    229: //
                    230: // 
                    231: //
                    232: // **********************************************************************************
                    233: - free
                    234: {
                    235:        return [ super free ];
                    236: }
                    237: 
                    238: 
                    239: 
                    240: - (void)interruptOccurred
                    241: {
                    242: void dump_regs(UInt32 *);
                    243: extern int usb_iodone;
                    244: void wait_usbio();
                    245: void print_usbDesc();
                    246: OHCIUIMInterruptHandler (0, NULL , 0);
                    247: [self enableAllInterrupts];
                    248: }
                    249: 
                    250: 
                    251: //New method added 12/22/98 by A.W. to support international USB keyboards
                    252: //NOTE: ADB keyboard keymaps are in /System/Library/Keyboards/*.keyboard
                    253: // Apple Extended Keyboard, North American version has ID of 16+2 = 18
                    254: - (unsigned int) getADBKeyboardID
                    255: {
                    256: //kprintf("USB: in usbcmd.m, vendor is %x, product is %x\n", usb_kbd_vendor_id, usb_kbd_product_id);
                    257: 
                    258:        if (usb_kbd_vendor_id == 0x05ac)  //Apple Corp. vendor ID
                    259:        {
                    260:                switch (usb_kbd_product_id)
                    261:                {
                    262:                        case 0x0201: //North American iMac keyboard
                    263:                                return 18;
                    264:                        case 0x0203: //38=Japanese.  34 is adjustable JIS
                    265:                                return 34;
                    266:                        case 0x0202: //Arabic
1.1.1.2 ! root      267:                                //3/19/99 A.W. last-minute changes for Canadian keyboard
        !           268:                                //Swap two ISO keys around
        !           269:                                usb_2_adb_keymap[0x35] = 0x0a;  //Cosmo key18 swaps with key74, 0a is ADB keycode
        !           270:                                usb_2_adb_keymap[0x64] = 0x32; 
1.1       root      271:                                return 21; //21 is Apple ISO Extended Keyboard
                    272:                        default:
                    273:                                return 18;
                    274:                }
                    275:        }
                    276: 
                    277:        if (usb_kbd_vendor_id == 0x045e)  //Microsoft ID
                    278:        {
                    279:                if (usb_kbd_product_id == 0x000b)       //Natural USB+PS/2 keyboard
                    280:                        return 18;
                    281:        }       
                    282:        //By default return Apple Extended ADB Keyboard ID
                    283:        return 18;
                    284: }
                    285: 
                    286: 
                    287: @end
                    288: 
                    289: IOThreadFunc usb_thread(void *ignore)
                    290: {
                    291:    extern void Get_Config_Info(void);
                    292:    extern void usbAddBus(void);
                    293:    extern char ports_connected[2];
                    294:    extern USBIdleTask(void);
                    295: 
                    296:    kprintf("Usb Thread Started\n");
                    297:    usbAddBus();
                    298: kprintf("***************    usbAddBus complete\n");
                    299:    for(;;)
                    300:    {
                    301:        USBIdleTask();
                    302: 
                    303:        IOSleep(1);   // Milliseconds 
                    304:    }
                    305: }
                    306: /*  Moved this function from ohciuim.c to here 
                    307: * Naga Pappireddi 12-17-98 Radar bug# 2293217   Cleanup of code in GetErrataBits function to read the registry properties
                    308: *                           this cleanup took care of LED problem on Yosemite
                    309: */
                    310: 
                    311: OSStatus RegistryPropertyGet(const RegEntryID *entryID, const RegPropertyName *propertyName, void *propertyValue, RegPropertyValueSize *propertySize)
                    312: {   
                    313: void *prop_value;
                    314: 
                    315: prop_value = (void *)propertyValue;
                    316: [usb_propTable getProperty:propertyName flags:0 value:(void **) &prop_value length:propertySize];
                    317: 
                    318: return 0;       
                    319: }
                    320: 

unix.superglobalmegacorp.com

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