]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/hibernate_i386.c
xnu-3789.60.24.tar.gz
[apple/xnu.git] / osfmk / i386 / hibernate_i386.c
index f164b8ec9cb1673aa29c27da771cab7a991d6c17..a16994234bc29b218e59819711a21f64f9b6bdb1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2004-2012 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
 #include <vm/vm_page.h>
 #include <i386/i386_lowmem.h>
 
+extern ppnum_t max_ppnum;
+
 #define MAX_BANKS      32
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 hibernate_page_list_t *
-hibernate_page_list_allocate(void)
+hibernate_page_list_allocate(boolean_t log)
 {
     ppnum_t                base, num;
     vm_size_t               size;
@@ -62,6 +64,7 @@ hibernate_page_list_allocate(void)
     uint32_t               mcount, msize, i;
     hibernate_bitmap_t     dram_ranges[MAX_BANKS];
     boot_args *                    args = (boot_args *) PE_state.bootArgs;
+    uint32_t               non_os_pagecount;
 
     mptr = (EfiMemoryRange *)ml_static_ptovirt(args->MemoryMap);
     if (args->MemoryMapDescriptorSize == 0)
@@ -70,23 +73,32 @@ hibernate_page_list_allocate(void)
     mcount = args->MemoryMapSize / msize;
 
     num_banks = 0;
+    non_os_pagecount = 0;
     for (i = 0; i < mcount; i++, mptr = (EfiMemoryRange *)(((vm_offset_t)mptr) + msize))
     {
        base = (ppnum_t) (mptr->PhysicalStart >> I386_PGSHIFT);
        num = (ppnum_t) mptr->NumberOfPages;
+
+       if (base > max_ppnum)
+               continue;
+       if ((base + num - 1) > max_ppnum)
+               num = max_ppnum - base + 1;
        if (!num)
-           continue;
+               continue;
 
        switch (mptr->Type)
        {
            // any kind of dram
+           case kEfiACPIMemoryNVS:
+           case kEfiPalCode:
+               non_os_pagecount += num;
+
+           // OS used dram
            case kEfiLoaderCode:
            case kEfiLoaderData:
            case kEfiBootServicesCode:
            case kEfiBootServicesData:
            case kEfiConventionalMemory:
-           case kEfiACPIMemoryNVS:
-           case kEfiPalCode:
 
                for (bank = 0; bank < num_banks; bank++)
                {
@@ -160,11 +172,11 @@ hibernate_page_list_allocate(void)
         bitmap->last_page  = dram_ranges[bank].last_page;
         bitmap->bitmapwords = (bitmap->last_page + 1
                                - bitmap->first_page + 31) >> 5;
-        kprintf("hib bank[%d]: 0x%x000 end 0x%xfff\n", bank,
-                bitmap->first_page,
-                bitmap->last_page);
+        if (log) kprintf("hib bank[%d]: 0x%x000 end 0x%xfff\n",
+                         bank, bitmap->first_page, bitmap->last_page);
        bitmap = (hibernate_bitmap_t *) &bitmap->bitmap[bitmap->bitmapwords];
     }
+    if (log) printf("efi pagecount %d\n", non_os_pagecount);
 
     return (list);
 }
@@ -174,6 +186,7 @@ hibernate_page_list_allocate(void)
 void
 hibernate_page_list_setall_machine( __unused hibernate_page_list_t * page_list,
                                     __unused hibernate_page_list_t * page_list_wired,
+                                    __unused boolean_t preflight,
                                     __unused uint32_t * pagesOut)
 {
 }
@@ -186,13 +199,6 @@ hibernate_page_list_set_volatile( hibernate_page_list_t * page_list,
 {
     boot_args * args = (boot_args *) PE_state.bootArgs;
 
-#if !defined(x86_64)
-    hibernate_set_page_state(page_list, page_list_wired, 
-               I386_HIB_PAGETABLE, I386_HIB_PAGETABLE_COUNT, 
-               kIOHibernatePageStateFree);
-    *pagesOut -= I386_HIB_PAGETABLE_COUNT;
-#endif
-
     if (args->efiRuntimeServicesPageStart)
     {
        hibernate_set_page_state(page_list, page_list_wired, 
@@ -213,13 +219,8 @@ hibernate_processor_setup(IOHibernateImageHeader * header)
     header->runtimePages     = args->efiRuntimeServicesPageStart;
     header->runtimePageCount = args->efiRuntimeServicesPageCount;
     header->runtimeVirtualPages = args->efiRuntimeServicesVirtualPageStart;
-    if (args->Version == kBootArgsVersion1 && args->Revision >= kBootArgsRevision1_6) {
-        header->performanceDataStart = args->performanceDataStart;
-        header->performanceDataSize = args->performanceDataSize;
-    } else {
-        header->performanceDataStart = 0;
-        header->performanceDataSize = 0;
-    }
+    header->performanceDataStart = args->performanceDataStart;
+    header->performanceDataSize = args->performanceDataSize;
 
     return (KERN_SUCCESS);
 }
@@ -227,42 +228,11 @@ hibernate_processor_setup(IOHibernateImageHeader * header)
 void
 hibernate_vm_lock(void)
 {
-    if (current_cpu_datap()->cpu_hibernate)
-    {
-        vm_page_lock_queues();
-        lck_mtx_lock(&vm_page_queue_free_lock);
-
-       if (vm_page_local_q) {
-               uint32_t  i;
-
-               for (i = 0; i < vm_page_local_q_count; i++) {
-                       struct vpl      *lq;
-
-                       lq = &vm_page_local_q[i].vpl_un.vpl;
-
-                       VPL_LOCK(&lq->vpl_lock);
-               }
-       }
-    }
+    if (current_cpu_datap()->cpu_hibernate) hibernate_vm_lock_queues();
 }
 
 void
 hibernate_vm_unlock(void)
 {
-    if (current_cpu_datap()->cpu_hibernate)
-    {
-       if (vm_page_local_q) {
-               uint32_t  i;
-
-               for (i = 0; i < vm_page_local_q_count; i++) {
-                       struct vpl      *lq;
-
-                       lq = &vm_page_local_q[i].vpl_un.vpl;
-
-                       VPL_UNLOCK(&lq->vpl_lock);
-               }
-       }
-        lck_mtx_unlock(&vm_page_queue_free_lock);
-        vm_page_unlock_queues();
-    }
+    if (current_cpu_datap()->cpu_hibernate)  hibernate_vm_unlock_queues();
 }