2 * Copyright (c) 1998-2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (c) 2007-2012 Apple Inc. All rights reserved.
5 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. The rights granted to you under the License
11 * may not be used to create, or enable the creation or redistribution of,
12 * unlawful or unlicensed copies of an Apple operating system, or to
13 * circumvent, violate, or enable the circumvention or violation of, any
14 * terms of an Apple operating system software license agreement.
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this file.
19 * The Original Code and all software distributed under the License are
20 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
21 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
22 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
24 * Please see the License for the specific language governing rights and
25 * limitations under the License.
27 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #include <IOKit/IOLib.h>
31 #include <IOKit/IONVRAM.h>
32 #include <IOKit/IOPlatformExpert.h>
33 #include <IOKit/IOUserClient.h>
34 #include <IOKit/IOKitKeys.h>
35 #include <IOKit/IOKitKeysPrivate.h>
36 #include <kern/debug.h>
37 #include <pexpert/pexpert.h>
41 #include <security/mac.h>
42 #include <security/mac_framework.h>
46 #define super IOService
48 #define kIONVRAMPrivilege kIOClientPrivilegeAdministrator
49 //#define kIONVRAMPrivilege kIOClientPrivilegeLocalUser
51 OSDefineMetaClassAndStructors(IODTNVRAM
, IOService
);
53 bool IODTNVRAM::init(IORegistryEntry
*old
, const IORegistryPlane
*plane
)
57 if (!super::init(old
, plane
)) return false;
59 dict
= OSDictionary::withCapacity(1);
60 if (dict
== 0) return false;
61 setPropertyTable(dict
);
63 _nvramImage
= IONew(UInt8
, kIODTNVRAMImageSize
);
64 if (_nvramImage
== 0) return false;
66 _nvramPartitionOffsets
= OSDictionary::withCapacity(1);
67 if (_nvramPartitionOffsets
== 0) return false;
69 _nvramPartitionLengths
= OSDictionary::withCapacity(1);
70 if (_nvramPartitionLengths
== 0) return false;
72 _registryPropertiesKey
= OSSymbol::withCStringNoCopy("aapl,pci");
73 if (_registryPropertiesKey
== 0) return false;
75 // <rdar://problem/9529235> race condition possible between
76 // IODTNVRAM and IONVRAMController (restore loses boot-args)
82 void IODTNVRAM::initProxyData(void)
84 IORegistryEntry
*entry
;
85 const char *key
= "nvram-proxy-data";
90 entry
= IORegistryEntry::fromPath("/chosen", gIODTPlane
);
92 prop
= entry
->getProperty(key
);
94 data
= OSDynamicCast(OSData
, prop
);
96 bytes
= data
->getBytesNoCopy();
97 if ((bytes
!= 0) && (data
->getLength() <= kIODTNVRAMImageSize
)) {
98 bcopy(bytes
, _nvramImage
, data
->getLength());
104 entry
->removeProperty(key
);
109 void IODTNVRAM::registerNVRAMController(IONVRAMController
*nvram
)
111 if (_nvramController
!= 0) return;
113 _nvramController
= nvram
;
115 // <rdar://problem/9529235> race condition possible between
116 // IODTNVRAM and IONVRAMController (restore loses boot-args)
118 _nvramController
->read(0, _nvramImage
, kIODTNVRAMImageSize
);
125 void IODTNVRAM::initNVRAMImage(void)
127 char partitionID
[18];
128 UInt32 partitionOffset
, partitionLength
;
129 UInt32 freePartitionOffset
, freePartitionSize
;
130 UInt32 currentLength
, currentOffset
= 0;
131 OSNumber
*partitionOffsetNumber
, *partitionLengthNumber
;
133 // Find the offsets for the OF, XPRAM, NameRegistry and PanicInfo partitions.
134 _ofPartitionOffset
= 0xFFFFFFFF;
135 _piPartitionOffset
= 0xFFFFFFFF;
136 freePartitionOffset
= 0xFFFFFFFF;
137 freePartitionSize
= 0;
139 // Look through the partitions to find the OF, MacOS partitions.
140 while (currentOffset
< kIODTNVRAMImageSize
) {
141 currentLength
= ((UInt16
*)(_nvramImage
+ currentOffset
))[1] * 16;
143 if (currentLength
< 16) break;
144 partitionOffset
= currentOffset
+ 16;
145 partitionLength
= currentLength
- 16;
146 if ((partitionOffset
+ partitionLength
) > kIODTNVRAMImageSize
) break;
148 if (strncmp((const char *)_nvramImage
+ currentOffset
+ 4,
149 kIODTNVRAMOFPartitionName
, 12) == 0) {
150 _ofPartitionOffset
= partitionOffset
;
151 _ofPartitionSize
= partitionLength
;
152 } else if (strncmp((const char *)_nvramImage
+ currentOffset
+ 4,
153 kIODTNVRAMXPRAMPartitionName
, 12) == 0) {
154 } else if (strncmp((const char *)_nvramImage
+ currentOffset
+ 4,
155 kIODTNVRAMPanicInfoPartitonName
, 12) == 0) {
156 _piPartitionOffset
= partitionOffset
;
157 _piPartitionSize
= partitionLength
;
158 } else if (strncmp((const char *)_nvramImage
+ currentOffset
+ 4,
159 kIODTNVRAMFreePartitionName
, 12) == 0) {
160 freePartitionOffset
= currentOffset
;
161 freePartitionSize
= currentLength
;
163 // Construct the partition ID from the signature and name.
164 snprintf(partitionID
, sizeof(partitionID
), "0x%02x,",
165 *(UInt8
*)(_nvramImage
+ currentOffset
));
166 strncpy(partitionID
+ 5,
167 (const char *)(_nvramImage
+ currentOffset
+ 4), 12);
168 partitionID
[17] = '\0';
170 partitionOffsetNumber
= OSNumber::withNumber(partitionOffset
, 32);
171 partitionLengthNumber
= OSNumber::withNumber(partitionLength
, 32);
173 // Save the partition offset and length
174 _nvramPartitionOffsets
->setObject(partitionID
, partitionOffsetNumber
);
175 _nvramPartitionLengths
->setObject(partitionID
, partitionLengthNumber
);
177 partitionOffsetNumber
->release();
178 partitionLengthNumber
->release();
180 currentOffset
+= currentLength
;
183 if (_ofPartitionOffset
!= 0xFFFFFFFF)
184 _ofImage
= _nvramImage
+ _ofPartitionOffset
;
186 if (_piPartitionOffset
== 0xFFFFFFFF) {
187 if (freePartitionSize
> 0x20) {
188 // Set the signature to 0xa1.
189 _nvramImage
[freePartitionOffset
] = 0xa1;
190 // Set the checksum to 0.
191 _nvramImage
[freePartitionOffset
+ 1] = 0;
192 // Set the name for the Panic Info partition.
193 strncpy((char *)(_nvramImage
+ freePartitionOffset
+ 4),
194 kIODTNVRAMPanicInfoPartitonName
, 12);
196 // Calculate the partition offset and size.
197 _piPartitionOffset
= freePartitionOffset
+ 0x10;
198 _piPartitionSize
= 0x800;
199 if (_piPartitionSize
+ 0x20 > freePartitionSize
)
200 _piPartitionSize
= freePartitionSize
- 0x20;
202 _piImage
= _nvramImage
+ _piPartitionOffset
;
204 // Zero the new partition.
205 bzero(_piImage
, _piPartitionSize
);
207 // Set the partition size.
208 *(UInt16
*)(_nvramImage
+ freePartitionOffset
+ 2) =
209 (_piPartitionSize
/ 0x10) + 1;
211 // Set the partition checksum.
212 _nvramImage
[freePartitionOffset
+ 1] =
213 calculatePartitionChecksum(_nvramImage
+ freePartitionOffset
);
215 // Calculate the free partition offset and size.
216 freePartitionOffset
+= _piPartitionSize
+ 0x10;
217 freePartitionSize
-= _piPartitionSize
+ 0x10;
219 // Set the signature to 0x7f.
220 _nvramImage
[freePartitionOffset
] = 0x7f;
221 // Set the checksum to 0.
222 _nvramImage
[freePartitionOffset
+ 1] = 0;
223 // Set the name for the free partition.
224 strncpy((char *)(_nvramImage
+ freePartitionOffset
+ 4),
225 kIODTNVRAMFreePartitionName
, 12);
226 // Set the partition size.
227 *(UInt16
*)(_nvramImage
+ freePartitionOffset
+ 2) =
228 freePartitionSize
/ 0x10;
229 // Set the partition checksum.
230 _nvramImage
[freePartitionOffset
+ 1] =
231 calculatePartitionChecksum(_nvramImage
+ freePartitionOffset
);
233 if (_nvramController
!= 0) {
234 _nvramController
->write(0, _nvramImage
, kIODTNVRAMImageSize
);
238 _piImage
= _nvramImage
+ _piPartitionOffset
;
242 _freshInterval
= TRUE
; // we will allow sync() even before the first 15 minutes have passed.
247 void IODTNVRAM::syncInternal(bool rateLimit
)
249 // Don't try to perform controller operations if none has been registered.
250 if (_nvramController
== 0) return;
252 // Rate limit requests to sync. Drivers that need this rate limiting will
253 // shadow the data and only write to flash when they get a sync call
254 if (rateLimit
&& !safeToSync()) return;
256 _nvramController
->sync();
259 void IODTNVRAM::sync(void)
264 bool IODTNVRAM::serializeProperties(OSSerialize
*s
) const
266 bool result
, hasPrivilege
;
270 OSCollectionIterator
*iter
= 0;
272 // Verify permissions.
273 hasPrivilege
= (kIOReturnSuccess
== IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege
));
276 /* No nvram. Return an empty dictionary. */
277 dict
= OSDictionary::withCapacity(1);
278 if (dict
== 0) return false;
281 dict
= OSDictionary::withDictionary(_ofDict
);
282 IOLockUnlock(_ofLock
);
283 if (dict
== 0) return false;
285 /* Copy properties with client privilege. */
286 iter
= OSCollectionIterator::withCollection(dict
);
292 key
= OSDynamicCast(OSSymbol
, iter
->getNextObject());
295 variablePerm
= getOFVariablePerm(key
);
296 if ((hasPrivilege
|| (variablePerm
!= kOFVariablePermRootOnly
)) &&
297 ( ! (variablePerm
== kOFVariablePermKernelOnly
&& current_task() != kernel_task
) )
299 && (current_task() == kernel_task
|| mac_iokit_check_nvram_get(kauth_cred_get(), key
->getCStringNoCopy()) == 0)
303 dict
->removeObject(key
);
309 result
= dict
->serialize(s
);
312 if (iter
!= 0) iter
->release();
317 OSObject
*IODTNVRAM::copyProperty(const OSSymbol
*aKey
) const
323 if (_ofDict
== 0) return 0;
325 // Verify permissions.
326 variablePerm
= getOFVariablePerm(aKey
);
327 result
= IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege
);
328 if (result
!= kIOReturnSuccess
) {
329 if (variablePerm
== kOFVariablePermRootOnly
) return 0;
331 if (variablePerm
== kOFVariablePermKernelOnly
&& current_task() != kernel_task
) return 0;
334 if (current_task() != kernel_task
&&
335 mac_iokit_check_nvram_get(kauth_cred_get(), aKey
->getCStringNoCopy()) != 0)
340 theObject
= _ofDict
->getObject(aKey
);
341 if (theObject
) theObject
->retain();
342 IOLockUnlock(_ofLock
);
347 OSObject
*IODTNVRAM::copyProperty(const char *aKey
) const
349 const OSSymbol
*keySymbol
;
350 OSObject
*theObject
= 0;
352 keySymbol
= OSSymbol::withCString(aKey
);
353 if (keySymbol
!= 0) {
354 theObject
= copyProperty(keySymbol
);
355 keySymbol
->release();
361 OSObject
*IODTNVRAM::getProperty(const OSSymbol
*aKey
) const
365 theObject
= copyProperty(aKey
);
366 if (theObject
) theObject
->release();
371 OSObject
*IODTNVRAM::getProperty(const char *aKey
) const
375 theObject
= copyProperty(aKey
);
376 if (theObject
) theObject
->release();
381 bool IODTNVRAM::setProperty(const OSSymbol
*aKey
, OSObject
*anObject
)
384 UInt32 propType
, propPerm
;
386 OSObject
*propObject
= 0;
388 if (_ofDict
== 0) return false;
390 // Verify permissions.
391 propPerm
= getOFVariablePerm(aKey
);
392 result
= IOUserClient::clientHasPrivilege(current_task(), kIONVRAMPrivilege
);
393 if (result
!= kIOReturnSuccess
) {
394 if (propPerm
!= kOFVariablePermUserWrite
) return false;
396 if (propPerm
== kOFVariablePermKernelOnly
&& current_task() != kernel_task
) return 0;
398 // Don't allow change of 'aapl,panic-info'.
399 if (aKey
->isEqualTo(kIODTNVRAMPanicInfoKey
)) return false;
402 if (current_task() != kernel_task
&&
403 mac_iokit_check_nvram_set(kauth_cred_get(), aKey
->getCStringNoCopy(), anObject
) != 0)
407 // Make sure the object is of the correct type.
408 propType
= getOFVariableType(aKey
);
410 case kOFVariableTypeBoolean
:
411 propObject
= OSDynamicCast(OSBoolean
, anObject
);
414 case kOFVariableTypeNumber
:
415 propObject
= OSDynamicCast(OSNumber
, anObject
);
418 case kOFVariableTypeString
:
419 propObject
= OSDynamicCast(OSString
, anObject
);
422 case kOFVariableTypeData
:
423 propObject
= OSDynamicCast(OSData
, anObject
);
424 if (propObject
== 0) {
425 tmpString
= OSDynamicCast(OSString
, anObject
);
426 if (tmpString
!= 0) {
427 propObject
= OSData::withBytes(tmpString
->getCStringNoCopy(),
428 tmpString
->getLength());
434 if (propObject
== 0) return false;
437 result
= _ofDict
->setObject(aKey
, propObject
);
438 IOLockUnlock(_ofLock
);
447 void IODTNVRAM::removeProperty(const OSSymbol
*aKey
)
452 if (_ofDict
== 0) return;
454 // Verify permissions.
455 propPerm
= getOFVariablePerm(aKey
);
456 result
= IOUserClient::clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator
);
457 if (result
!= kIOReturnSuccess
) {
458 if (propPerm
!= kOFVariablePermUserWrite
) return;
460 if (propPerm
== kOFVariablePermKernelOnly
&& current_task() != kernel_task
) return;
462 // Don't allow change of 'aapl,panic-info'.
463 if (aKey
->isEqualTo(kIODTNVRAMPanicInfoKey
)) return;
466 if (current_task() != kernel_task
&&
467 mac_iokit_check_nvram_delete(kauth_cred_get(), aKey
->getCStringNoCopy()) != 0)
471 // If the object exists, remove it from the dictionary.
474 result
= _ofDict
->getObject(aKey
) != 0;
476 _ofDict
->removeObject(aKey
);
478 IOLockUnlock(_ofLock
);
485 IOReturn
IODTNVRAM::setProperties(OSObject
*properties
)
490 const OSString
*tmpStr
;
492 OSCollectionIterator
*iter
;
494 dict
= OSDynamicCast(OSDictionary
, properties
);
495 if (dict
== 0) return kIOReturnBadArgument
;
497 iter
= OSCollectionIterator::withCollection(dict
);
498 if (iter
== 0) return kIOReturnBadArgument
;
501 key
= OSDynamicCast(OSSymbol
, iter
->getNextObject());
504 object
= dict
->getObject(key
);
505 if (object
== 0) continue;
507 if (key
->isEqualTo(kIONVRAMDeletePropertyKey
)) {
508 tmpStr
= OSDynamicCast(OSString
, object
);
510 key
= OSSymbol::withString(tmpStr
);
517 } else if(key
->isEqualTo(kIONVRAMSyncNowPropertyKey
) || key
->isEqualTo(kIONVRAMForceSyncNowPropertyKey
)) {
518 tmpStr
= OSDynamicCast(OSString
, object
);
523 // We still want to throttle NVRAM commit rate for SyncNow. ForceSyncNow is provided as a really big hammer.
525 syncInternal(key
->isEqualTo(kIONVRAMSyncNowPropertyKey
));
532 result
= setProperty(key
, object
);
539 if (result
) return kIOReturnSuccess
;
540 else return kIOReturnError
;
543 IOReturn
IODTNVRAM::readXPRAM(IOByteCount offset
, UInt8
*buffer
,
546 return kIOReturnUnsupported
;
549 IOReturn
IODTNVRAM::writeXPRAM(IOByteCount offset
, UInt8
*buffer
,
552 return kIOReturnUnsupported
;
555 IOReturn
IODTNVRAM::readNVRAMProperty(IORegistryEntry
*entry
,
556 const OSSymbol
**name
,
561 err
= readNVRAMPropertyType1(entry
, name
, value
);
566 IOReturn
IODTNVRAM::writeNVRAMProperty(IORegistryEntry
*entry
,
567 const OSSymbol
*name
,
572 err
= writeNVRAMPropertyType1(entry
, name
, value
);
577 OSDictionary
*IODTNVRAM::getNVRAMPartitions(void)
579 return _nvramPartitionLengths
;
582 IOReturn
IODTNVRAM::readNVRAMPartition(const OSSymbol
*partitionID
,
583 IOByteCount offset
, UInt8
*buffer
,
586 OSNumber
*partitionOffsetNumber
, *partitionLengthNumber
;
587 UInt32 partitionOffset
, partitionLength
, end
;
589 partitionOffsetNumber
=
590 (OSNumber
*)_nvramPartitionOffsets
->getObject(partitionID
);
591 partitionLengthNumber
=
592 (OSNumber
*)_nvramPartitionLengths
->getObject(partitionID
);
594 if ((partitionOffsetNumber
== 0) || (partitionLengthNumber
== 0))
595 return kIOReturnNotFound
;
597 partitionOffset
= partitionOffsetNumber
->unsigned32BitValue();
598 partitionLength
= partitionLengthNumber
->unsigned32BitValue();
600 if (os_add_overflow(offset
, length
, &end
)) return kIOReturnBadArgument
;
601 if ((buffer
== 0) || (length
== 0) || (end
> partitionLength
))
602 return kIOReturnBadArgument
;
604 bcopy(_nvramImage
+ partitionOffset
+ offset
, buffer
, length
);
606 return kIOReturnSuccess
;
609 IOReturn
IODTNVRAM::writeNVRAMPartition(const OSSymbol
*partitionID
,
610 IOByteCount offset
, UInt8
*buffer
,
613 OSNumber
*partitionOffsetNumber
, *partitionLengthNumber
;
614 UInt32 partitionOffset
, partitionLength
, end
;
616 partitionOffsetNumber
=
617 (OSNumber
*)_nvramPartitionOffsets
->getObject(partitionID
);
618 partitionLengthNumber
=
619 (OSNumber
*)_nvramPartitionLengths
->getObject(partitionID
);
621 if ((partitionOffsetNumber
== 0) || (partitionLengthNumber
== 0))
622 return kIOReturnNotFound
;
624 partitionOffset
= partitionOffsetNumber
->unsigned32BitValue();
625 partitionLength
= partitionLengthNumber
->unsigned32BitValue();
627 if (os_add_overflow(offset
, length
, &end
)) return kIOReturnBadArgument
;
628 if ((buffer
== 0) || (length
== 0) || (end
> partitionLength
))
629 return kIOReturnBadArgument
;
631 bcopy(buffer
, _nvramImage
+ partitionOffset
+ offset
, length
);
633 if (_nvramController
!= 0) {
634 _nvramController
->write(0, _nvramImage
, kIODTNVRAMImageSize
);
637 return kIOReturnSuccess
;
640 IOByteCount
IODTNVRAM::savePanicInfo(UInt8
*buffer
, IOByteCount length
)
642 if ((_piImage
== 0) || (length
<= 0)) return 0;
644 if (length
> (_piPartitionSize
- 4))
645 length
= _piPartitionSize
- 4;
647 // Save the Panic Info.
648 bcopy(buffer
, _piImage
+ 4, length
);
650 // Save the Panic Info length.
651 *(UInt32
*)_piImage
= length
;
653 if (_nvramController
!= 0) {
654 _nvramController
->write(0, _nvramImage
, kIODTNVRAMImageSize
);
657 * This prevents OF variables from being committed if the system has panicked
659 _systemPaniced
= true;
660 /* The call to sync() forces the NVRAM controller to write the panic info
661 * partition to NVRAM.
670 UInt8
IODTNVRAM::calculatePartitionChecksum(UInt8
*partitionHeader
)
672 UInt8 cnt
, isum
, csum
= 0;
674 for (cnt
= 0; cnt
< 0x10; cnt
++) {
675 isum
= csum
+ partitionHeader
[cnt
];
676 if (isum
< csum
) isum
++;
683 IOReturn
IODTNVRAM::initOFVariables(void)
686 UInt8
*propName
, *propData
;
687 UInt32 propNameLength
, propDataLength
;
688 const OSSymbol
*propSymbol
;
689 OSObject
*propObject
;
691 if (_ofImage
== 0) return kIOReturnNotReady
;
693 _ofDict
= OSDictionary::withCapacity(1);
694 _ofLock
= IOLockAlloc();
695 if (!_ofDict
|| !_ofLock
) return kIOReturnNoMemory
;
698 while (cnt
< _ofPartitionSize
) {
699 // Break if there is no name.
700 if (_ofImage
[cnt
] == '\0') break;
702 // Find the length of the name.
703 propName
= _ofImage
+ cnt
;
704 for (propNameLength
= 0; (cnt
+ propNameLength
) < _ofPartitionSize
;
706 if (_ofImage
[cnt
+ propNameLength
] == '=') break;
709 // Break if the name goes past the end of the partition.
710 if ((cnt
+ propNameLength
) >= _ofPartitionSize
) break;
711 cnt
+= propNameLength
+ 1;
713 propData
= _ofImage
+ cnt
;
714 for (propDataLength
= 0; (cnt
+ propDataLength
) < _ofPartitionSize
;
716 if (_ofImage
[cnt
+ propDataLength
] == '\0') break;
719 // Break if the data goes past the end of the partition.
720 if ((cnt
+ propDataLength
) >= _ofPartitionSize
) break;
721 cnt
+= propDataLength
+ 1;
723 if (convertPropToObject(propName
, propNameLength
,
724 propData
, propDataLength
,
725 &propSymbol
, &propObject
)) {
726 _ofDict
->setObject(propSymbol
, propObject
);
727 propSymbol
->release();
728 propObject
->release();
732 // Create the boot-args property if it is not in the dictionary.
733 if (_ofDict
->getObject("boot-args") == 0) {
734 propObject
= OSString::withCStringNoCopy("");
735 if (propObject
!= 0) {
736 _ofDict
->setObject("boot-args", propObject
);
737 propObject
->release();
742 propDataLength
= *(UInt32
*)_piImage
;
743 if ((propDataLength
!= 0) && (propDataLength
<= (_piPartitionSize
- 4))) {
744 propObject
= OSData::withBytes(_piImage
+ 4, propDataLength
);
745 _ofDict
->setObject(kIODTNVRAMPanicInfoKey
, propObject
);
746 propObject
->release();
748 // Clear the length from _piImage and mark dirty.
749 *(UInt32
*)_piImage
= 0;
750 if (_nvramController
!= 0) {
751 _nvramController
->write(0, _nvramImage
, kIODTNVRAMImageSize
);
756 return kIOReturnSuccess
;
759 IOReturn
IODTNVRAM::syncOFVariables(void)
762 UInt32 length
, maxLength
;
763 UInt8
*buffer
, *tmpBuffer
;
764 const OSSymbol
*tmpSymbol
;
766 OSCollectionIterator
*iter
;
768 if ((_ofImage
== 0) || (_ofDict
== 0) || _systemPaniced
) return kIOReturnNotReady
;
770 buffer
= tmpBuffer
= IONew(UInt8
, _ofPartitionSize
);
771 if (buffer
== 0) return kIOReturnNoMemory
;
772 bzero(buffer
, _ofPartitionSize
);
775 maxLength
= _ofPartitionSize
;
778 iter
= OSCollectionIterator::withCollection(_ofDict
);
779 if (iter
== 0) ok
= false;
782 tmpSymbol
= OSDynamicCast(OSSymbol
, iter
->getNextObject());
783 if (tmpSymbol
== 0) break;
785 // Don't save 'aapl,panic-info'.
786 if (tmpSymbol
->isEqualTo(kIODTNVRAMPanicInfoKey
)) continue;
788 tmpObject
= _ofDict
->getObject(tmpSymbol
);
791 ok
= convertObjectToProp(tmpBuffer
, &length
, tmpSymbol
, tmpObject
);
798 IOLockUnlock(_ofLock
);
801 bcopy(buffer
, _ofImage
, _ofPartitionSize
);
804 IODelete(buffer
, UInt8
, _ofPartitionSize
);
806 if (!ok
) return kIOReturnBadArgument
;
808 if (_nvramController
!= 0) {
809 _nvramController
->write(0, _nvramImage
, kIODTNVRAMImageSize
);
812 return kIOReturnSuccess
;
816 const char *variableName
;
819 SInt32 variableOffset
;
821 typedef struct OFVariable OFVariable
;
824 kOWVariableOffsetNumber
= 8,
825 kOWVariableOffsetString
= 17
829 OFVariable gOFVariables
[] = {
830 {"little-endian?", kOFVariableTypeBoolean
, kOFVariablePermUserRead
, 0},
831 {"real-mode?", kOFVariableTypeBoolean
, kOFVariablePermUserRead
, 1},
832 {"auto-boot?", kOFVariableTypeBoolean
, kOFVariablePermUserRead
, 2},
833 {"diag-switch?", kOFVariableTypeBoolean
, kOFVariablePermUserRead
, 3},
834 {"fcode-debug?", kOFVariableTypeBoolean
, kOFVariablePermUserRead
, 4},
835 {"oem-banner?", kOFVariableTypeBoolean
, kOFVariablePermUserRead
, 5},
836 {"oem-logo?", kOFVariableTypeBoolean
, kOFVariablePermUserRead
, 6},
837 {"use-nvramrc?", kOFVariableTypeBoolean
, kOFVariablePermUserRead
, 7},
838 {"use-generic?", kOFVariableTypeBoolean
, kOFVariablePermUserRead
, -1},
839 {"default-mac-address?", kOFVariableTypeBoolean
, kOFVariablePermUserRead
,-1},
840 {"real-base", kOFVariableTypeNumber
, kOFVariablePermUserRead
, 8},
841 {"real-size", kOFVariableTypeNumber
, kOFVariablePermUserRead
, 9},
842 {"virt-base", kOFVariableTypeNumber
, kOFVariablePermUserRead
, 10},
843 {"virt-size", kOFVariableTypeNumber
, kOFVariablePermUserRead
, 11},
844 {"load-base", kOFVariableTypeNumber
, kOFVariablePermUserRead
, 12},
845 {"pci-probe-list", kOFVariableTypeNumber
, kOFVariablePermUserRead
, 13},
846 {"pci-probe-mask", kOFVariableTypeNumber
, kOFVariablePermUserRead
, -1},
847 {"screen-#columns", kOFVariableTypeNumber
, kOFVariablePermUserRead
, 14},
848 {"screen-#rows", kOFVariableTypeNumber
, kOFVariablePermUserRead
, 15},
849 {"selftest-#megs", kOFVariableTypeNumber
, kOFVariablePermUserRead
, 16},
850 {"boot-device", kOFVariableTypeString
, kOFVariablePermUserRead
, 17},
851 {"boot-file", kOFVariableTypeString
, kOFVariablePermUserRead
, 18},
852 {"boot-screen", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
853 {"console-screen", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
854 {"diag-device", kOFVariableTypeString
, kOFVariablePermUserRead
, 19},
855 {"diag-file", kOFVariableTypeString
, kOFVariablePermUserRead
, 20},
856 {"input-device", kOFVariableTypeString
, kOFVariablePermUserRead
, 21},
857 {"output-device", kOFVariableTypeString
, kOFVariablePermUserRead
, 22},
858 {"input-device-1", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
859 {"output-device-1", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
860 {"mouse-device", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
861 {"oem-banner", kOFVariableTypeString
, kOFVariablePermUserRead
, 23},
862 {"oem-logo", kOFVariableTypeString
, kOFVariablePermUserRead
, 24},
863 {"nvramrc", kOFVariableTypeString
, kOFVariablePermUserRead
, 25},
864 {"boot-command", kOFVariableTypeString
, kOFVariablePermUserRead
, 26},
865 {"default-client-ip", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
866 {"default-server-ip", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
867 {"default-gateway-ip", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
868 {"default-subnet-mask", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
869 {"default-router-ip", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
870 {"boot-script", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
871 {"boot-args", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
872 {"aapl,pci", kOFVariableTypeData
, kOFVariablePermRootOnly
, -1},
873 {"security-mode", kOFVariableTypeString
, kOFVariablePermUserRead
, -1},
874 {"security-password", kOFVariableTypeData
, kOFVariablePermRootOnly
, -1},
875 {"boot-image", kOFVariableTypeData
, kOFVariablePermUserWrite
, -1},
876 {"com.apple.System.fp-state", kOFVariableTypeData
, kOFVariablePermKernelOnly
, -1},
878 {"backlight-level", kOFVariableTypeData
, kOFVariablePermUserWrite
, -1},
879 {"com.apple.System.sep.art", kOFVariableTypeData
, kOFVariablePermKernelOnly
, -1},
880 {"com.apple.System.boot-nonce", kOFVariableTypeString
, kOFVariablePermKernelOnly
, -1},
881 {"darkboot", kOFVariableTypeBoolean
, kOFVariablePermUserWrite
, -1},
882 {"acc-mb-ld-lifetime", kOFVariableTypeNumber
, kOFVariablePermKernelOnly
, -1},
883 {"acc-cm-override-charger-count", kOFVariableTypeNumber
, kOFVariablePermKernelOnly
, -1},
884 {"acc-cm-override-count", kOFVariableTypeNumber
, kOFVariablePermKernelOnly
, -1},
885 {"enter-tdm-mode", kOFVariableTypeBoolean
, kOFVariablePermUserWrite
, -1},
887 {0, kOFVariableTypeData
, kOFVariablePermUserRead
, -1}
890 UInt32
IODTNVRAM::getOFVariableType(const OSSymbol
*propSymbol
) const
892 const OFVariable
*ofVar
;
894 ofVar
= gOFVariables
;
896 if ((ofVar
->variableName
== 0) ||
897 propSymbol
->isEqualTo(ofVar
->variableName
)) break;
901 return ofVar
->variableType
;
904 UInt32
IODTNVRAM::getOFVariablePerm(const OSSymbol
*propSymbol
) const
906 const OFVariable
*ofVar
;
908 ofVar
= gOFVariables
;
910 if ((ofVar
->variableName
== 0) ||
911 propSymbol
->isEqualTo(ofVar
->variableName
)) break;
915 return ofVar
->variablePerm
;
918 bool IODTNVRAM::getOWVariableInfo(UInt32 variableNumber
, const OSSymbol
**propSymbol
,
919 UInt32
*propType
, UInt32
*propOffset
)
921 const OFVariable
*ofVar
;
923 ofVar
= gOFVariables
;
925 if (ofVar
->variableName
== 0) return false;
927 if (ofVar
->variableOffset
== (SInt32
) variableNumber
) break;
932 *propSymbol
= OSSymbol::withCStringNoCopy(ofVar
->variableName
);
933 *propType
= ofVar
->variableType
;
936 case kOFVariableTypeBoolean
:
937 *propOffset
= 1 << (31 - variableNumber
);
940 case kOFVariableTypeNumber
:
941 *propOffset
= variableNumber
- kOWVariableOffsetNumber
;
944 case kOFVariableTypeString
:
945 *propOffset
= variableNumber
- kOWVariableOffsetString
;
952 bool IODTNVRAM::convertPropToObject(UInt8
*propName
, UInt32 propNameLength
,
953 UInt8
*propData
, UInt32 propDataLength
,
954 const OSSymbol
**propSymbol
,
955 OSObject
**propObject
)
958 const OSSymbol
*tmpSymbol
;
963 // Create the symbol.
964 propName
[propNameLength
] = '\0';
965 tmpSymbol
= OSSymbol::withCString((const char *)propName
);
966 propName
[propNameLength
] = '=';
967 if (tmpSymbol
== 0) {
971 propType
= getOFVariableType(tmpSymbol
);
973 // Create the object.
976 case kOFVariableTypeBoolean
:
977 if (!strncmp("true", (const char *)propData
, propDataLength
)) {
978 tmpObject
= kOSBooleanTrue
;
979 } else if (!strncmp("false", (const char *)propData
, propDataLength
)) {
980 tmpObject
= kOSBooleanFalse
;
984 case kOFVariableTypeNumber
:
985 tmpNumber
= OSNumber::withNumber(strtol((const char *)propData
, 0, 0), 32);
986 if (tmpNumber
!= 0) tmpObject
= tmpNumber
;
989 case kOFVariableTypeString
:
990 tmpString
= OSString::withCString((const char *)propData
);
991 if (tmpString
!= 0) tmpObject
= tmpString
;
994 case kOFVariableTypeData
:
995 tmpObject
= unescapeBytesToData(propData
, propDataLength
);
999 if (tmpObject
== 0) {
1000 tmpSymbol
->release();
1004 *propSymbol
= tmpSymbol
;
1005 *propObject
= tmpObject
;
1010 bool IODTNVRAM::convertObjectToProp(UInt8
*buffer
, UInt32
*length
,
1011 const OSSymbol
*propSymbol
, OSObject
*propObject
)
1013 const UInt8
*propName
;
1014 UInt32 propNameLength
, propDataLength
, remaining
;
1015 UInt32 propType
, tmpValue
;
1016 OSBoolean
*tmpBoolean
= 0;
1017 OSNumber
*tmpNumber
= 0;
1018 OSString
*tmpString
= 0;
1019 OSData
*tmpData
= 0;
1021 propName
= (const UInt8
*)propSymbol
->getCStringNoCopy();
1022 propNameLength
= propSymbol
->getLength();
1023 propType
= getOFVariableType(propSymbol
);
1025 // Get the size of the data.
1026 propDataLength
= 0xFFFFFFFF;
1028 case kOFVariableTypeBoolean
:
1029 tmpBoolean
= OSDynamicCast(OSBoolean
, propObject
);
1030 if (tmpBoolean
!= 0) propDataLength
= 5;
1033 case kOFVariableTypeNumber
:
1034 tmpNumber
= OSDynamicCast(OSNumber
, propObject
);
1035 if (tmpNumber
!= 0) propDataLength
= 10;
1038 case kOFVariableTypeString
:
1039 tmpString
= OSDynamicCast(OSString
, propObject
);
1040 if (tmpString
!= 0) propDataLength
= tmpString
->getLength();
1043 case kOFVariableTypeData
:
1044 tmpData
= OSDynamicCast(OSData
, propObject
);
1046 tmpData
= escapeDataToData(tmpData
);
1047 propDataLength
= tmpData
->getLength();
1052 // Make sure the propertySize is known and will fit.
1053 if (propDataLength
== 0xFFFFFFFF) return false;
1054 if ((propNameLength
+ propDataLength
+ 2) > *length
) return false;
1056 // Copy the property name equal sign.
1057 buffer
+= snprintf((char *)buffer
, *length
, "%s=", propName
);
1058 remaining
= *length
- propNameLength
- 1;
1061 case kOFVariableTypeBoolean
:
1062 if (tmpBoolean
->getValue()) {
1063 strlcpy((char *)buffer
, "true", remaining
);
1065 strlcpy((char *)buffer
, "false", remaining
);
1069 case kOFVariableTypeNumber
:
1070 tmpValue
= tmpNumber
->unsigned32BitValue();
1071 if (tmpValue
== 0xFFFFFFFF) {
1072 strlcpy((char *)buffer
, "-1", remaining
);
1073 } else if (tmpValue
< 1000) {
1074 snprintf((char *)buffer
, remaining
, "%d", (uint32_t)tmpValue
);
1076 snprintf((char *)buffer
, remaining
, "0x%x", (uint32_t)tmpValue
);
1080 case kOFVariableTypeString
:
1081 strlcpy((char *)buffer
, tmpString
->getCStringNoCopy(), remaining
);
1084 case kOFVariableTypeData
:
1085 bcopy(tmpData
->getBytesNoCopy(), buffer
, propDataLength
);
1090 propDataLength
= strlen((const char *)buffer
);
1092 *length
= propNameLength
+ propDataLength
+ 2;
1098 UInt16
IODTNVRAM::generateOWChecksum(UInt8
*buffer
)
1100 UInt32 cnt
, checksum
= 0;
1101 UInt16
*tmpBuffer
= (UInt16
*)buffer
;
1103 for (cnt
= 0; cnt
< _ofPartitionSize
/ 2; cnt
++)
1104 checksum
+= tmpBuffer
[cnt
];
1106 return checksum
% 0x0000FFFF;
1109 bool IODTNVRAM::validateOWChecksum(UInt8
*buffer
)
1111 UInt32 cnt
, checksum
, sum
= 0;
1112 UInt16
*tmpBuffer
= (UInt16
*)buffer
;
1114 for (cnt
= 0; cnt
< _ofPartitionSize
/ 2; cnt
++)
1115 sum
+= tmpBuffer
[cnt
];
1117 checksum
= (sum
>> 16) + (sum
& 0x0000FFFF);
1118 if (checksum
== 0x10000) checksum
--;
1119 checksum
= (checksum
^ 0x0000FFFF) & 0x0000FFFF;
1121 return checksum
== 0;
1124 void IODTNVRAM::updateOWBootArgs(const OSSymbol
*key
, OSObject
*value
)
1126 bool wasBootArgs
, bootr
= false;
1128 OSString
*tmpString
, *bootCommand
, *bootArgs
= 0;
1129 const UInt8
*bootCommandData
, *bootArgsData
;
1131 UInt32 bootCommandDataLength
, bootArgsDataLength
, tmpDataLength
;
1133 tmpString
= OSDynamicCast(OSString
, value
);
1134 if (tmpString
== 0) return;
1136 if (key
->isEqualTo("boot-command")) {
1137 wasBootArgs
= false;
1138 bootCommand
= tmpString
;
1139 } else if (key
->isEqualTo("boot-args")) {
1141 bootArgs
= tmpString
;
1142 bootCommand
= OSDynamicCast(OSString
, _ofDict
->getObject("boot-command"));
1143 if (bootCommand
== 0) return;
1146 bootCommandData
= (const UInt8
*)bootCommand
->getCStringNoCopy();
1147 bootCommandDataLength
= bootCommand
->getLength();
1149 if (bootCommandData
== 0) return;
1151 for (cnt
= 0; cnt
< bootCommandDataLength
; cnt
++) {
1152 if ((bootCommandData
[cnt
] == 'b') &&
1153 !strncmp("bootr", (const char *)bootCommandData
+ cnt
, 5)) {
1155 while (bootCommandData
[cnt
] == ' ') cnt
++;
1161 _ofDict
->removeObject("boot-args");
1166 bootArgsData
= (const UInt8
*)bootArgs
->getCStringNoCopy();
1167 bootArgsDataLength
= bootArgs
->getLength();
1168 if (bootArgsData
== 0) return;
1170 tmpDataLength
= cnt
+ bootArgsDataLength
;
1171 tmpData
= IONew(UInt8
, tmpDataLength
+ 1);
1172 if (tmpData
== 0) return;
1174 cnt
-= strlcpy((char *)tmpData
, (const char *)bootCommandData
, cnt
);
1175 strlcat((char *)tmpData
, (const char *)bootArgsData
, cnt
);
1177 bootCommand
= OSString::withCString((const char *)tmpData
);
1178 if (bootCommand
!= 0) {
1179 _ofDict
->setObject("boot-command", bootCommand
);
1180 bootCommand
->release();
1183 IODelete(tmpData
, UInt8
, tmpDataLength
+ 1);
1185 bootArgs
= OSString::withCString((const char *)(bootCommandData
+ cnt
));
1186 if (bootArgs
!= 0) {
1187 _ofDict
->setObject("boot-args", bootArgs
);
1188 bootArgs
->release();
1193 bool IODTNVRAM::searchNVRAMProperty(IONVRAMDescriptor
*hdr
, UInt32
*where
)
1198 IOReturn
IODTNVRAM::readNVRAMPropertyType0(IORegistryEntry
*entry
,
1199 const OSSymbol
**name
,
1202 return kIOReturnUnsupported
;
1206 IOReturn
IODTNVRAM::writeNVRAMPropertyType0(IORegistryEntry
*entry
,
1207 const OSSymbol
*name
,
1210 return kIOReturnUnsupported
;
1214 OSData
*IODTNVRAM::unescapeBytesToData(const UInt8
*bytes
, UInt32 length
)
1217 UInt32 totalLength
= 0;
1222 // Calculate the actual length of the data.
1225 for (cnt
= 0; cnt
< length
;) {
1226 byte
= bytes
[cnt
++];
1228 byte
= bytes
[cnt
++];
1236 totalLength
+= cnt2
;
1240 // Create an empty OSData of the correct size.
1241 data
= OSData::withCapacity(totalLength
);
1243 for (cnt
= 0; cnt
< length
;) {
1244 byte
= bytes
[cnt
++];
1246 byte
= bytes
[cnt
++];
1248 byte
= (byte
& 0x80) ? 0xFF : 0x00;
1251 data
->appendByte(byte
, cnt2
);
1259 OSData
* IODTNVRAM::escapeDataToData(OSData
* value
)
1262 const UInt8
* startPtr
;
1263 const UInt8
* endPtr
;
1264 const UInt8
* wherePtr
;
1268 wherePtr
= (const UInt8
*) value
->getBytesNoCopy();
1269 endPtr
= wherePtr
+ value
->getLength();
1271 result
= OSData::withCapacity(endPtr
- wherePtr
);
1275 while (wherePtr
< endPtr
) {
1276 startPtr
= wherePtr
;
1278 if ((byte
== 0x00) || (byte
== 0xFF)) {
1280 ((wherePtr
- startPtr
) < 0x80) && (wherePtr
< endPtr
) && (byte
== *wherePtr
);
1282 ok
&= result
->appendByte(0xff, 1);
1283 byte
= (byte
& 0x80) | (wherePtr
- startPtr
);
1285 ok
&= result
->appendByte(byte
, 1);
1287 ok
&= result
->appendByte(0, 1);
1297 static bool IsApplePropertyName(const char * propName
)
1300 while ((c
= *propName
++)) {
1301 if ((c
>= 'A') && (c
<= 'Z'))
1308 IOReturn
IODTNVRAM::readNVRAMPropertyType1(IORegistryEntry
*entry
,
1309 const OSSymbol
**name
,
1312 IOReturn err
= kIOReturnNoResources
;
1314 const UInt8
*startPtr
;
1315 const UInt8
*endPtr
;
1316 const UInt8
*wherePtr
;
1317 const UInt8
*nvPath
= 0;
1318 const char *nvName
= 0;
1319 const char *resultName
= 0;
1320 const UInt8
*resultValue
= 0;
1321 UInt32 resultValueLen
= 0;
1324 if (_ofDict
== 0) return err
;
1326 IOLockLock(_ofLock
);
1327 data
= OSDynamicCast(OSData
, _ofDict
->getObject(_registryPropertiesKey
));
1328 IOLockUnlock(_ofLock
);
1330 if (data
== 0) return err
;
1332 startPtr
= (const UInt8
*) data
->getBytesNoCopy();
1333 endPtr
= startPtr
+ data
->getLength();
1335 wherePtr
= startPtr
;
1336 while (wherePtr
< endPtr
) {
1337 byte
= *(wherePtr
++);
1343 else if (nvName
== 0)
1344 nvName
= (const char *) startPtr
;
1346 IORegistryEntry
* compareEntry
= IORegistryEntry::fromPath((const char *) nvPath
, gIODTPlane
);
1348 compareEntry
->release();
1349 if (entry
== compareEntry
) {
1350 bool appleProp
= IsApplePropertyName(nvName
);
1351 if (!appleProp
|| !resultName
) {
1352 resultName
= nvName
;
1353 resultValue
= startPtr
;
1354 resultValueLen
= wherePtr
- startPtr
- 1;
1362 startPtr
= wherePtr
;
1365 *name
= OSSymbol::withCString(resultName
);
1366 *value
= unescapeBytesToData(resultValue
, resultValueLen
);
1367 if ((*name
!= 0) && (*value
!= 0))
1368 err
= kIOReturnSuccess
;
1370 err
= kIOReturnNoMemory
;
1375 IOReturn
IODTNVRAM::writeNVRAMPropertyType1(IORegistryEntry
*entry
,
1376 const OSSymbol
*propName
,
1381 const UInt8
*startPtr
;
1382 const UInt8
*propStart
;
1383 const UInt8
*endPtr
;
1384 const UInt8
*wherePtr
;
1385 const UInt8
*nvPath
= 0;
1386 const char *nvName
= 0;
1391 bool settingAppleProp
;
1393 if (_ofDict
== 0) return kIOReturnNoResources
;
1395 settingAppleProp
= IsApplePropertyName(propName
->getCStringNoCopy());
1397 // copy over existing properties for other entries
1399 IOLockLock(_ofLock
);
1401 oldData
= OSDynamicCast(OSData
, _ofDict
->getObject(_registryPropertiesKey
));
1403 startPtr
= (const UInt8
*) oldData
->getBytesNoCopy();
1404 endPtr
= startPtr
+ oldData
->getLength();
1406 propStart
= startPtr
;
1407 wherePtr
= startPtr
;
1408 while (wherePtr
< endPtr
) {
1409 byte
= *(wherePtr
++);
1414 else if (nvName
== 0)
1415 nvName
= (const char *) startPtr
;
1417 IORegistryEntry
* compareEntry
= IORegistryEntry::fromPath((const char *) nvPath
, gIODTPlane
);
1419 compareEntry
->release();
1420 if (entry
== compareEntry
) {
1421 if ((settingAppleProp
&& propName
->isEqualTo(nvName
))
1422 || (!settingAppleProp
&& !IsApplePropertyName(nvName
))) {
1423 // delete old property (nvPath -> wherePtr)
1424 data
= OSData::withBytes(propStart
, nvPath
- propStart
);
1426 ok
&= data
->appendBytes(wherePtr
, endPtr
- wherePtr
);
1434 startPtr
= wherePtr
;
1438 // make the new property
1442 data
= OSData::withData(oldData
);
1444 data
= OSData::withCapacity(16);
1445 if (!data
) ok
= false;
1448 if (ok
&& value
&& value
->getLength()) do {
1449 // get entries in path
1450 OSArray
*array
= OSArray::withCapacity(5);
1456 array
->setObject(entry
);
1457 while ((entry
= entry
->getParentEntry(gIODTPlane
)));
1460 for (int i
= array
->getCount() - 3;
1461 (entry
= (IORegistryEntry
*) array
->getObject(i
));
1464 name
= entry
->getName(gIODTPlane
);
1465 comp
= entry
->getLocation(gIODTPlane
);
1466 if (comp
) ok
&= data
->appendBytes("/@", 2);
1468 if (!name
) continue;
1469 ok
&= data
->appendByte('/', 1);
1472 ok
&= data
->appendBytes(comp
, strlen(comp
));
1474 ok
&= data
->appendByte(0, 1);
1478 ok
&= data
->appendBytes(propName
->getCStringNoCopy(), propName
->getLength() + 1);
1480 // append escaped data
1481 oldData
= escapeDataToData(value
);
1482 ok
&= (oldData
!= 0);
1483 if (ok
) ok
&= data
->appendBytes(oldData
);
1488 ok
= _ofDict
->setObject(_registryPropertiesKey
, data
);
1491 IOLockUnlock(_ofLock
);
1492 if (data
) data
->release();
1494 if (ok
) syncOFVariables();
1496 return ok
? kIOReturnSuccess
: kIOReturnNoMemory
;
1499 bool IODTNVRAM::safeToSync(void)
1505 // delta interval went by
1506 clock_get_uptime(&delta
);
1508 // Figure it in seconds.
1509 absolutetime_to_nanoseconds(delta
, &delta_ns
);
1510 delta_secs
= (SInt32
)(delta_ns
/ NSEC_PER_SEC
);
1512 if ((delta_secs
> (_lastDeviceSync
+ MIN_SYNC_NOW_INTERVAL
)) || _freshInterval
)
1514 _lastDeviceSync
= delta_secs
;
1515 _freshInterval
= FALSE
;