]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvAppleNVRAM/AppleNVRAM.cpp
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <IOKit/IOLib.h>
25 #include "AppleNVRAM.h"
28 #define super IONVRAMController
29 OSDefineMetaClassAndStructors(AppleNVRAM
, IONVRAMController
);
32 // ****************************************************************************
35 // ****************************************************************************
36 bool AppleNVRAM::start(IOService
*provider
)
38 IOItemCount numRanges
;
41 numRanges
= provider
->getDeviceMemoryCount();
44 _nvramType
= kNVRAMTypeIOMem
;
46 // Get the address of the data register.
47 map
= provider
->mapDeviceMemoryWithIndex(0);
48 if (map
== 0) return false;
49 _nvramData
= (UInt8
*)map
->getVirtualAddress();
51 } else if (numRanges
== 2) {
52 _nvramType
= kNVRAMTypePort
;
54 // Get the address of the port register.
55 map
= provider
->mapDeviceMemoryWithIndex(0);
56 if (map
== 0) return false;
57 _nvramPort
= (UInt8
*)map
->getVirtualAddress();
59 // Get the address of the data register.
60 map
= provider
->mapDeviceMemoryWithIndex(1);
61 if (map
== 0) return false;
62 _nvramData
= (UInt8
*)map
->getVirtualAddress();
68 return super::start(provider
);
71 // ****************************************************************************
74 // Read data from the NVRAM and return it in buffer.
76 // ****************************************************************************
77 IOReturn
AppleNVRAM::read(IOByteCount offset
, UInt8
*buffer
,
82 if ((buffer
== 0) || (length
<= 0) || (offset
< 0) ||
83 (offset
+ length
> kNVRAMImageSize
))
84 return kIOReturnBadArgument
;
87 case kNVRAMTypeIOMem
:
88 for (cnt
= 0; cnt
< length
; cnt
++) {
89 buffer
[cnt
] = _nvramData
[(offset
+ cnt
) << 4];
94 for (cnt
= 0; cnt
< length
; cnt
++) {
95 *_nvramPort
= (offset
+ length
) >> 5;
97 buffer
[cnt
] = _nvramData
[((offset
+ length
) & 0x1F) << 4];
102 return kIOReturnNotReady
;
105 return kIOReturnSuccess
;
109 // ****************************************************************************
112 // Write data from buffer into NVRAM.
114 // ****************************************************************************
115 IOReturn
AppleNVRAM::write(IOByteCount offset
, UInt8
*buffer
,
120 if ((buffer
== 0) || (length
<= 0) || (offset
< 0) ||
121 (offset
+ length
> kNVRAMImageSize
))
122 return kIOReturnBadArgument
;
124 switch (_nvramType
) {
125 case kNVRAMTypeIOMem
:
126 for (cnt
= 0; cnt
< length
; cnt
++) {
127 _nvramData
[(offset
+ cnt
) << 4] = buffer
[cnt
];
133 for (cnt
= 0; cnt
< length
; cnt
++) {
134 *_nvramPort
= (offset
+ length
) >> 5;
136 _nvramData
[((offset
+ length
) & 0x1F) << 4] = buffer
[cnt
];
142 return kIOReturnNotReady
;
145 return kIOReturnSuccess
;