]>
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@ |
3a60a9f5 | 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. | |
8f6c56a5 | 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. | |
17 | * | |
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. | |
8f6c56a5 | 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> | |
37 | #include <default_pager/default_pager_internal.h> | |
38 | #include <IOKit/IOPlatformExpert.h> | |
3a60a9f5 A |
39 | |
40 | #include <IOKit/IOHibernatePrivate.h> | |
41 | #include <vm/vm_page.h> | |
42 | #include <vm/vm_pageout.h> | |
2d21ac55 | 43 | #include <vm/vm_purgeable_internal.h> |
3a60a9f5 | 44 | |
3a60a9f5 A |
45 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
46 | ||
47 | kern_return_t | |
48 | hibernate_setup(IOHibernateImageHeader * header, | |
0b4c1975 A |
49 | uint32_t free_page_ratio, |
50 | uint32_t free_page_time, | |
51 | boolean_t vmflush, | |
3a60a9f5 A |
52 | hibernate_page_list_t ** page_list_ret, |
53 | hibernate_page_list_t ** page_list_wired_ret, | |
6d2010ae | 54 | hibernate_page_list_t ** page_list_pal_ret, |
3a60a9f5 A |
55 | boolean_t * encryptedswap) |
56 | { | |
57 | hibernate_page_list_t * page_list = NULL; | |
58 | hibernate_page_list_t * page_list_wired = NULL; | |
6d2010ae | 59 | hibernate_page_list_t * page_list_pal = NULL; |
b0d623f7 | 60 | uint32_t gobble_count; |
3a60a9f5 A |
61 | |
62 | *page_list_ret = NULL; | |
63 | *page_list_wired_ret = NULL; | |
6d2010ae | 64 | *page_list_pal_ret = NULL; |
0b4c1975 A |
65 | |
66 | if (vmflush) | |
67 | hibernate_flush_memory(); | |
3a60a9f5 A |
68 | |
69 | page_list = hibernate_page_list_allocate(); | |
70 | if (!page_list) | |
71 | return (KERN_RESOURCE_SHORTAGE); | |
72 | page_list_wired = hibernate_page_list_allocate(); | |
73 | if (!page_list_wired) | |
74 | { | |
75 | kfree(page_list, page_list->list_size); | |
76 | return (KERN_RESOURCE_SHORTAGE); | |
77 | } | |
6d2010ae A |
78 | page_list_pal = hibernate_page_list_allocate(); |
79 | if (!page_list_pal) | |
80 | { | |
81 | kfree(page_list, page_list->list_size); | |
82 | kfree(page_list_wired, page_list_wired->list_size); | |
83 | return (KERN_RESOURCE_SHORTAGE); | |
84 | } | |
3a60a9f5 A |
85 | |
86 | *encryptedswap = dp_encryption; | |
87 | ||
88 | // pages we could force out to reduce hibernate image size | |
b0d623f7 | 89 | gobble_count = (uint32_t)((((uint64_t) page_list->page_count) * ((uint64_t) free_page_ratio)) / 100); |
3a60a9f5 A |
90 | |
91 | // no failures hereafter | |
92 | ||
93 | hibernate_processor_setup(header); | |
94 | ||
2d21ac55 | 95 | HIBLOG("hibernate_alloc_pages flags %08x, gobbling %d pages\n", |
3a60a9f5 A |
96 | header->processorFlags, gobble_count); |
97 | ||
98 | if (gobble_count) | |
b0d623f7 | 99 | hibernate_gobble_pages(gobble_count, free_page_time); |
3a60a9f5 A |
100 | |
101 | *page_list_ret = page_list; | |
102 | *page_list_wired_ret = page_list_wired; | |
6d2010ae | 103 | *page_list_pal_ret = page_list_pal; |
3a60a9f5 A |
104 | |
105 | return (KERN_SUCCESS); | |
106 | } | |
107 | ||
108 | kern_return_t | |
109 | hibernate_teardown(hibernate_page_list_t * page_list, | |
110 | hibernate_page_list_t * page_list_wired) | |
111 | { | |
b0d623f7 | 112 | hibernate_free_gobble_pages(); |
3a60a9f5 A |
113 | |
114 | if (page_list) | |
115 | kfree(page_list, page_list->list_size); | |
116 | if (page_list_wired) | |
117 | kfree(page_list_wired, page_list_wired->list_size); | |
118 | ||
119 | return (KERN_SUCCESS); | |
120 | } | |
121 |