|
|
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: * 16 Feb 1998 suurballe Created. ! 24: */ ! 25: ! 26: #include <IOKit/IOLib.h> ! 27: #include "AppleNVRAM.h" ! 28: ! 29: ! 30: #define super IONVRAMController ! 31: OSDefineMetaClassAndStructors(AppleNVRAM, IONVRAMController) ! 32: ! 33: ! 34: // ********************************************************************************** ! 35: // start ! 36: // ! 37: // ********************************************************************************** ! 38: bool AppleNVRAM::start ( IOService * nub ) ! 39: { ! 40: IOItemCount numRanges; ! 41: IOMemoryMap * map; ! 42: ! 43: nvram_kind = NVRAM_NONE; ! 44: nvram_data = NULL; ! 45: nvram_port = NULL; ! 46: ! 47: numRanges = nub->getDeviceMemoryCount( ); ! 48: ! 49: if ( numRanges == 1 ) { ! 50: nvram_kind = NVRAM_IOMEM; ! 51: if( 0 == (map = nub->mapDeviceMemoryWithIndex( 0 )) ) { ! 52: return false; ! 53: } ! 54: nvram_data = (unsigned char *)map->getVirtualAddress(); ! 55: return super::start( nub ); ! 56: } ! 57: if ( numRanges == 2 ) { ! 58: nvram_kind = NVRAM_PORT; ! 59: if( 0 == (map = nub->mapDeviceMemoryWithIndex( 0 )) ) { ! 60: return false; ! 61: } ! 62: nvram_port = (unsigned char *)map->getVirtualAddress(); ! 63: if( 0 == (map = nub->mapDeviceMemoryWithIndex( 1 )) ) { ! 64: return false; ! 65: } ! 66: nvram_data = (unsigned char *)map->getVirtualAddress(); ! 67: return super::start( nub ); ! 68: } ! 69: return false; ! 70: } ! 71: ! 72: ! 73: ! 74: // ********************************************************************************** ! 75: // openNVRAM ! 76: // ! 77: // ! 78: // ********************************************************************************** ! 79: IOReturn AppleNVRAM::openNVRAM ( void ) ! 80: { ! 81: if (nvram_kind == NVRAM_NONE) { ! 82: return (kNoNVRAM); ! 83: } ! 84: return kNoError; ! 85: } ! 86: ! 87: // ********************************************************************************** ! 88: // readNVRAM ! 89: // ! 90: // The NVRAM driver is calling to read part of the NVRAM. ! 91: // ! 92: // ********************************************************************************** ! 93: IOReturn AppleNVRAM::readNVRAM ( UInt32 Offset, IOByteCount * Length, UInt8 * Buffer ) ! 94: { ! 95: IOByteCount i; ! 96: UInt8 * client_buffer = Buffer; ! 97: UInt32 our_offset = Offset; ! 98: ! 99: if (nvram_kind == NVRAM_NONE) { ! 100: return (kNoNVRAM); ! 101: } ! 102: ! 103: if ( (Buffer == NULL) || ! 104: (*Length == 0) || ! 105: (*Length > 8192) || ! 106: (Offset > 8192) || ! 107: ((*Length + Offset) > 8192) ) { ! 108: return kParameterError; ! 109: } ! 110: ! 111: switch (nvram_kind) { ! 112: case NVRAM_IOMEM: ! 113: for (i = 0; i < *Length; i++,our_offset++) { ! 114: *client_buffer++ = nvram_data[our_offset << 4]; ! 115: eieio(); ! 116: } ! 117: break; ! 118: ! 119: case NVRAM_PORT: ! 120: for (i = 0; i < *Length; i++,our_offset++) { ! 121: *nvram_port = our_offset >> 5; ! 122: eieio(); ! 123: *client_buffer++ = nvram_data[(our_offset & 0x1f) << 4]; ! 124: eieio(); ! 125: } ! 126: break; ! 127: } ! 128: ! 129: return kNoError; ! 130: } ! 131: ! 132: ! 133: // ********************************************************************************** ! 134: // writeNVRAM ! 135: // ! 136: // The NVRAM driver is calling to write part of the NVRAM. We translate this into ! 137: // single-byte PMU commands and enqueue them to our command queue. ! 138: // ! 139: // ********************************************************************************** ! 140: IOReturn AppleNVRAM::writeNVRAM ( UInt32 Offset, IOByteCount * Length, UInt8 * Buffer ) ! 141: { ! 142: IOByteCount i; ! 143: UInt32 our_offset = Offset; ! 144: UInt8 * client_buffer = Buffer; ! 145: ! 146: if (nvram_kind == NVRAM_NONE) { ! 147: return (kNoNVRAM); ! 148: } ! 149: ! 150: if ( (Buffer == NULL) || ! 151: (*Length == 0) || ! 152: (*Length > 8192) || ! 153: (Offset > 8192) || ! 154: ((*Length + Offset) > 8192) ) { ! 155: return kParameterError; ! 156: } ! 157: ! 158: switch (nvram_kind) { ! 159: case NVRAM_IOMEM: ! 160: for (i = 0; i < *Length; i++,our_offset++) { ! 161: nvram_data[our_offset << 4] = *client_buffer++; ! 162: eieio(); ! 163: } ! 164: break; ! 165: ! 166: case NVRAM_PORT: ! 167: for (i = 0; i < *Length; i++, our_offset++) { ! 168: *nvram_port = our_offset >> 5; ! 169: eieio(); ! 170: nvram_data[(our_offset & 0x1f) << 4] = *client_buffer++; ! 171: eieio(); ! 172: } ! 173: break; ! 174: } ! 175: return kNoError; ! 176: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.