]>
Commit | Line | Data |
---|---|---|
3a60a9f5 | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved. |
3a60a9f5 | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
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. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
3a60a9f5 A |
27 | */ |
28 | ||
29 | #include <kern/kalloc.h> | |
30 | #include <kern/machine.h> | |
31 | #include <kern/misc_protos.h> | |
32 | #include <kern/thread.h> | |
33 | #include <kern/processor.h> | |
34 | #include <mach/machine.h> | |
35 | #include <mach/processor_info.h> | |
36 | #include <mach/mach_types.h> | |
3a60a9f5 | 37 | #include <IOKit/IOPlatformExpert.h> |
3a60a9f5 A |
38 | |
39 | #include <IOKit/IOHibernatePrivate.h> | |
40 | #include <vm/vm_page.h> | |
41 | #include <vm/vm_pageout.h> | |
2d21ac55 | 42 | #include <vm/vm_purgeable_internal.h> |
39236c6e | 43 | #include <vm/vm_compressor.h> |
3a60a9f5 | 44 | |
3a60a9f5 A |
45 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
46 | ||
0a7de745 | 47 | boolean_t need_to_unlock_decompressor = FALSE; |
39236c6e | 48 | |
0a7de745 | 49 | kern_return_t |
39236c6e | 50 | hibernate_alloc_page_lists( |
0a7de745 A |
51 | hibernate_page_list_t ** page_list_ret, |
52 | hibernate_page_list_t ** page_list_wired_ret, | |
53 | hibernate_page_list_t ** page_list_pal_ret) | |
3a60a9f5 | 54 | { |
0a7de745 A |
55 | kern_return_t retval = KERN_SUCCESS; |
56 | ||
57 | hibernate_page_list_t * page_list = NULL; | |
58 | hibernate_page_list_t * page_list_wired = NULL; | |
59 | hibernate_page_list_t * page_list_pal = NULL; | |
60 | ||
61 | page_list = hibernate_page_list_allocate(TRUE); | |
62 | if (!page_list) { | |
cb323159 | 63 | HIBLOG("%s: failed for page_list\n", __FUNCTION__); |
0a7de745 A |
64 | retval = KERN_RESOURCE_SHORTAGE; |
65 | goto done; | |
66 | } | |
67 | page_list_wired = hibernate_page_list_allocate(FALSE); | |
68 | if (!page_list_wired) { | |
69 | kfree(page_list, page_list->list_size); | |
cb323159 | 70 | HIBLOG("%s: failed for page_list_wired\n", __FUNCTION__); |
0a7de745 A |
71 | retval = KERN_RESOURCE_SHORTAGE; |
72 | goto done; | |
73 | } | |
74 | page_list_pal = hibernate_page_list_allocate(FALSE); | |
75 | if (!page_list_pal) { | |
76 | kfree(page_list, page_list->list_size); | |
77 | kfree(page_list_wired, page_list_wired->list_size); | |
cb323159 | 78 | HIBLOG("%s: failed for page_list_pal\n", __FUNCTION__); |
0a7de745 A |
79 | retval = KERN_RESOURCE_SHORTAGE; |
80 | goto done; | |
81 | } | |
82 | *page_list_ret = page_list; | |
83 | *page_list_wired_ret = page_list_wired; | |
84 | *page_list_pal_ret = page_list_pal; | |
39236c6e A |
85 | |
86 | done: | |
0a7de745 | 87 | return retval; |
39236c6e A |
88 | } |
89 | ||
90 | extern int sync_internal(void); | |
91 | ||
0a7de745 | 92 | kern_return_t |
39236c6e | 93 | hibernate_setup(IOHibernateImageHeader * header, |
0a7de745 A |
94 | boolean_t vmflush, |
95 | hibernate_page_list_t * page_list __unused, | |
96 | hibernate_page_list_t * page_list_wired __unused, | |
97 | hibernate_page_list_t * page_list_pal __unused) | |
39236c6e | 98 | { |
0a7de745 A |
99 | kern_return_t retval = KERN_SUCCESS; |
100 | ||
101 | hibernate_create_paddr_map(); | |
39236c6e | 102 | |
0a7de745 | 103 | hibernate_reset_stats(); |
fe8ab488 | 104 | |
0a7de745 A |
105 | if (vmflush && VM_CONFIG_COMPRESSOR_IS_PRESENT) { |
106 | sync_internal(); | |
39236c6e | 107 | |
0a7de745 A |
108 | vm_decompressor_lock(); |
109 | need_to_unlock_decompressor = TRUE; | |
39037602 | 110 | |
0a7de745 A |
111 | hibernate_flush_memory(); |
112 | } | |
3a60a9f5 | 113 | |
0a7de745 | 114 | // no failures hereafter |
3a60a9f5 | 115 | |
0a7de745 | 116 | hibernate_processor_setup(header); |
3a60a9f5 | 117 | |
0a7de745 A |
118 | HIBLOG("hibernate_alloc_pages act %d, inact %d, anon %d, throt %d, spec %d, wire %d, wireinit %d\n", |
119 | vm_page_active_count, vm_page_inactive_count, | |
120 | vm_page_anonymous_count, vm_page_throttled_count, vm_page_speculative_count, | |
db609669 A |
121 | vm_page_wire_count, vm_page_wire_count_initial); |
122 | ||
0a7de745 A |
123 | if (retval != KERN_SUCCESS && need_to_unlock_decompressor == TRUE) { |
124 | need_to_unlock_decompressor = FALSE; | |
125 | vm_decompressor_unlock(); | |
126 | } | |
127 | return retval; | |
3a60a9f5 A |
128 | } |
129 | ||
0a7de745 | 130 | kern_return_t |
3a60a9f5 | 131 | hibernate_teardown(hibernate_page_list_t * page_list, |
0a7de745 A |
132 | hibernate_page_list_t * page_list_wired, |
133 | hibernate_page_list_t * page_list_pal) | |
3a60a9f5 | 134 | { |
0a7de745 A |
135 | hibernate_free_gobble_pages(); |
136 | ||
137 | if (page_list) { | |
138 | kfree(page_list, page_list->list_size); | |
139 | } | |
140 | if (page_list_wired) { | |
141 | kfree(page_list_wired, page_list_wired->list_size); | |
142 | } | |
143 | if (page_list_pal) { | |
144 | kfree(page_list_pal, page_list_pal->list_size); | |
145 | } | |
146 | ||
147 | if (VM_CONFIG_COMPRESSOR_IS_PRESENT) { | |
148 | if (need_to_unlock_decompressor == TRUE) { | |
149 | need_to_unlock_decompressor = FALSE; | |
150 | vm_decompressor_unlock(); | |
151 | } | |
152 | vm_compressor_delay_trim(); | |
153 | } | |
154 | return KERN_SUCCESS; | |
3a60a9f5 | 155 | } |