Annotation of XNU/iokit/Drivers/platform/drvAppleKeyLargo/KeyLargo.cpp, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: /*
                     23:  * Copyright (c) 1999 Apple Computer, Inc.  All rights reserved.
                     24:  *
                     25:  *  DRI: Josh de Cesare
                     26:  *
                     27:  */
                     28: 
                     29: #include <ppc/proc_reg.h>
                     30: 
                     31: #include <IOKit/IOLib.h>
                     32: #include <IOKit/IODeviceTreeSupport.h>
                     33: #include <IOKit/IODeviceMemory.h>
                     34: 
                     35: #include "KeyLargo.h"
                     36: 
                     37: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                     38: 
                     39: #define super AppleMacIO
                     40: 
                     41: OSDefineMetaClassAndStructors(KeyLargo, AppleMacIO);
                     42: 
                     43: bool KeyLargo::start(IOService *provider)
                     44: {
                     45:   // Call MacIO's start.
                     46:   if (!super::start(provider))
                     47:     return false;
                     48:   
                     49:   // Make nubs for the children.
                     50:   publishBelow(provider);
                     51:   
                     52:   // get the base address of KeyLargo.
                     53:   keyLargoBaseAddress = fMemory->getVirtualAddress();
                     54:   
                     55:   registerService();
                     56:     
                     57:   return true;
                     58: }
                     59: 
                     60: 
                     61: long long KeyLargo::syncTimeBase(void)
                     62: {
                     63:   long          cnt;
                     64:   unsigned long gtLow, gtHigh, gtHigh2;
                     65:   unsigned long tbLow, tbHigh;
                     66:   long long     tmp, diffTicks, ratioLow, ratioHigh;
                     67:   
                     68:   ratioLow = (24907667ULL << 32) / kKeyLargoGTimerFreq;
                     69:   ratioHigh = ratioLow >> 32;
                     70:   ratioLow &= 0xFFFFFFFFULL;
                     71:   
                     72:   // Save the old time base.
                     73:   diffTicks = ((long long)mftbu() << 32) | mftb();
                     74:   
                     75:   // Do the sync twice to make sure it is cached.
                     76:   for (cnt = 0; cnt < 2; cnt++) {
                     77:     // Read the Global Counter.
                     78:     do {
                     79:       gtHigh  = readRegUInt32(kKeyLargoCounterHiOffset);
                     80:       gtLow   = readRegUInt32(kKeyLargoCounterLoOffset);
                     81:       gtHigh2 = readRegUInt32(kKeyLargoCounterHiOffset);
                     82:     } while (gtHigh != gtHigh2);
                     83:     
                     84:     tmp = gtHigh * ratioLow + gtLow * ratioHigh +
                     85:       ((gtLow * ratioLow + 0x80000000UL) >> 32);
                     86:     tbHigh = gtHigh * ratioHigh + (tmp >> 32);
                     87:     tbLow = tmp & 0xFFFFFFFFULL;
                     88:     
                     89:     mttb(tbLow);
                     90:     mttbu(tbHigh);
                     91:   }
                     92:   
                     93:   diffTicks = (((long long)tbHigh << 32) | tbLow) - diffTicks;
                     94:   
                     95:   return diffTicks;
                     96: }
                     97: 
                     98: UInt8 KeyLargo::readRegUInt8(unsigned long offest)
                     99: {
                    100:   return *(UInt8 *)(keyLargoBaseAddress + offest);
                    101: }
                    102: 
                    103: void KeyLargo::writeRegUInt8(unsigned long offest, UInt8 data)
                    104: {
                    105:   *(UInt8 *)(keyLargoBaseAddress + offest) = data;
                    106:   eieio();
                    107: }
                    108: 
                    109: UInt32 KeyLargo::readRegUInt32(unsigned long offest)
                    110: {
                    111:   return lwbrx(keyLargoBaseAddress + offest);
                    112: }
                    113: 
                    114: void KeyLargo::writeRegUInt32(unsigned long offest, UInt32 data)
                    115: {
                    116:   stwbrx(data, keyLargoBaseAddress + offest);
                    117:   eieio();
                    118: }

unix.superglobalmegacorp.com

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