]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvAppleNVRAM/AppleNVRAM.cpp
b7855b79eb422e0dec5765cd249273cab38fcf71
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 #include <IOKit/IOLib.h>
27 #include "AppleNVRAM.h"
30 #define super IONVRAMController
31 OSDefineMetaClassAndStructors(AppleNVRAM
, IONVRAMController
);
34 // ****************************************************************************
37 // ****************************************************************************
38 bool AppleNVRAM::start(IOService
*provider
)
40 IOItemCount numRanges
;
43 numRanges
= provider
->getDeviceMemoryCount();
46 _nvramType
= kNVRAMTypeIOMem
;
48 // Get the address of the data register.
49 map
= provider
->mapDeviceMemoryWithIndex(0);
50 if (map
== 0) return false;
51 _nvramData
= (UInt8
*)map
->getVirtualAddress();
53 } else if (numRanges
== 2) {
54 _nvramType
= kNVRAMTypePort
;
56 // Get the address of the port register.
57 map
= provider
->mapDeviceMemoryWithIndex(0);
58 if (map
== 0) return false;
59 _nvramPort
= (UInt8
*)map
->getVirtualAddress();
61 // Get the address of the data register.
62 map
= provider
->mapDeviceMemoryWithIndex(1);
63 if (map
== 0) return false;
64 _nvramData
= (UInt8
*)map
->getVirtualAddress();
70 return super::start(provider
);
73 // ****************************************************************************
76 // Read data from the NVRAM and return it in buffer.
78 // ****************************************************************************
79 IOReturn
AppleNVRAM::read(IOByteCount offset
, UInt8
*buffer
,
84 if ((buffer
== 0) || (length
<= 0) || (offset
< 0) ||
85 (offset
+ length
> kNVRAMImageSize
))
86 return kIOReturnBadArgument
;
89 case kNVRAMTypeIOMem
:
90 for (cnt
= 0; cnt
< length
; cnt
++) {
91 buffer
[cnt
] = _nvramData
[(offset
+ cnt
) << 4];
96 for (cnt
= 0; cnt
< length
; cnt
++) {
97 *_nvramPort
= (offset
+ length
) >> 5;
99 buffer
[cnt
] = _nvramData
[((offset
+ length
) & 0x1F) << 4];
104 return kIOReturnNotReady
;
107 return kIOReturnSuccess
;
111 // ****************************************************************************
114 // Write data from buffer into NVRAM.
116 // ****************************************************************************
117 IOReturn
AppleNVRAM::write(IOByteCount offset
, UInt8
*buffer
,
122 if ((buffer
== 0) || (length
<= 0) || (offset
< 0) ||
123 (offset
+ length
> kNVRAMImageSize
))
124 return kIOReturnBadArgument
;
126 switch (_nvramType
) {
127 case kNVRAMTypeIOMem
:
128 for (cnt
= 0; cnt
< length
; cnt
++) {
129 _nvramData
[(offset
+ cnt
) << 4] = buffer
[cnt
];
135 for (cnt
= 0; cnt
< length
; cnt
++) {
136 *_nvramPort
= (offset
+ length
) >> 5;
138 _nvramData
[((offset
+ length
) & 0x1F) << 4] = buffer
[cnt
];
144 return kIOReturnNotReady
;
147 return kIOReturnSuccess
;