]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/platform/drvAppleNVRAM/AppleNVRAM.cpp
27b69da0e4bcb7e75fc7e206a1bc434cc74c1592
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 #include <IOKit/IOLib.h>
24 #include "AppleNVRAM.h"
27 #define super IONVRAMController
28 OSDefineMetaClassAndStructors(AppleNVRAM
, IONVRAMController
);
31 // ****************************************************************************
34 // ****************************************************************************
35 bool AppleNVRAM::start(IOService
*provider
)
37 IOItemCount numRanges
;
40 numRanges
= provider
->getDeviceMemoryCount();
43 _nvramType
= kNVRAMTypeIOMem
;
45 // Get the address of the data register.
46 map
= provider
->mapDeviceMemoryWithIndex(0);
47 if (map
== 0) return false;
48 _nvramData
= (UInt8
*)map
->getVirtualAddress();
50 } else if (numRanges
== 2) {
51 _nvramType
= kNVRAMTypePort
;
53 // Get the address of the port register.
54 map
= provider
->mapDeviceMemoryWithIndex(0);
55 if (map
== 0) return false;
56 _nvramPort
= (UInt8
*)map
->getVirtualAddress();
58 // Get the address of the data register.
59 map
= provider
->mapDeviceMemoryWithIndex(1);
60 if (map
== 0) return false;
61 _nvramData
= (UInt8
*)map
->getVirtualAddress();
67 return super::start(provider
);
70 // ****************************************************************************
73 // Read data from the NVRAM and return it in buffer.
75 // ****************************************************************************
76 IOReturn
AppleNVRAM::read(IOByteCount offset
, UInt8
*buffer
,
81 if ((buffer
== 0) || (length
<= 0) || (offset
< 0) ||
82 (offset
+ length
> kNVRAMImageSize
))
83 return kIOReturnBadArgument
;
86 case kNVRAMTypeIOMem
:
87 for (cnt
= 0; cnt
< length
; cnt
++) {
88 buffer
[cnt
] = _nvramData
[(offset
+ cnt
) << 4];
93 for (cnt
= 0; cnt
< length
; cnt
++) {
94 *_nvramPort
= (offset
+ length
) >> 5;
96 buffer
[cnt
] = _nvramData
[((offset
+ length
) & 0x1F) << 4];
101 return kIOReturnNotReady
;
104 return kIOReturnSuccess
;
108 // ****************************************************************************
111 // Write data from buffer into NVRAM.
113 // ****************************************************************************
114 IOReturn
AppleNVRAM::write(IOByteCount offset
, UInt8
*buffer
,
119 if ((buffer
== 0) || (length
<= 0) || (offset
< 0) ||
120 (offset
+ length
> kNVRAMImageSize
))
121 return kIOReturnBadArgument
;
123 switch (_nvramType
) {
124 case kNVRAMTypeIOMem
:
125 for (cnt
= 0; cnt
< length
; cnt
++) {
126 _nvramData
[(offset
+ cnt
) << 4] = buffer
[cnt
];
132 for (cnt
= 0; cnt
< length
; cnt
++) {
133 *_nvramPort
= (offset
+ length
) >> 5;
135 _nvramData
[((offset
+ length
) & 0x1F) << 4] = buffer
[cnt
];
141 return kIOReturnNotReady
;
144 return kIOReturnSuccess
;