]>
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/kern_types.h> | |
30 | #include <kern/kalloc.h> | |
31 | #include <kern/machine.h> | |
32 | #include <kern/misc_protos.h> | |
33 | #include <kern/thread.h> | |
34 | #include <kern/processor.h> | |
35 | #include <mach/machine.h> | |
36 | #include <mach/processor_info.h> | |
37 | #include <mach/mach_types.h> | |
38 | #include <ppc/proc_reg.h> | |
39 | #include <ppc/misc_protos.h> | |
40 | #include <ppc/machine_routines.h> | |
41 | #include <ppc/machine_cpu.h> | |
42 | #include <ppc/exception.h> | |
43 | #include <ppc/asm.h> | |
44 | #include <ppc/hw_perfmon.h> | |
45 | #include <pexpert/pexpert.h> | |
46 | #include <kern/cpu_data.h> | |
47 | #include <ppc/mappings.h> | |
48 | #include <ppc/Diagnostics.h> | |
49 | #include <ppc/trap.h> | |
50 | #include <ppc/mem.h> | |
51 | #include <IOKit/IOPlatformExpert.h> | |
3a60a9f5 A |
52 | #include <IOKit/IOHibernatePrivate.h> |
53 | #include <vm/vm_page.h> | |
54 | ||
55 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
56 | ||
0b4c1975 A |
57 | unsigned int save_kdebug_enable = 0; |
58 | ||
59 | ||
3a60a9f5 A |
60 | hibernate_page_list_t * |
61 | hibernate_page_list_allocate(void) | |
62 | { | |
63 | vm_size_t size; | |
64 | uint32_t bank; | |
65 | uint32_t pages, page_count; | |
66 | hibernate_page_list_t * list; | |
67 | hibernate_bitmap_t * bitmap; | |
68 | ||
69 | page_count = 0; | |
70 | size = sizeof(hibernate_page_list_t); | |
71 | ||
72 | for (bank = 0; bank < (uint32_t) pmap_mem_regions_count; bank++) | |
73 | { | |
74 | size += sizeof(hibernate_bitmap_t); | |
75 | pages = pmap_mem_regions[bank].mrEnd + 1 - pmap_mem_regions[bank].mrStart; | |
76 | page_count += pages; | |
77 | size += ((pages + 31) >> 5) * sizeof(uint32_t); | |
78 | } | |
79 | ||
80 | list = kalloc(size); | |
81 | if (!list) | |
82 | return (list); | |
83 | ||
84 | list->list_size = size; | |
85 | list->page_count = page_count; | |
86 | list->bank_count = pmap_mem_regions_count; | |
87 | ||
88 | bitmap = &list->bank_bitmap[0]; | |
89 | for (bank = 0; bank < list->bank_count; bank++) | |
90 | { | |
91 | bitmap->first_page = pmap_mem_regions[bank].mrStart; | |
92 | bitmap->last_page = pmap_mem_regions[bank].mrEnd; | |
93 | bitmap->bitmapwords = (pmap_mem_regions[bank].mrEnd + 1 | |
94 | - pmap_mem_regions[bank].mrStart + 31) >> 5; | |
95 | ||
96 | bitmap = (hibernate_bitmap_t *) &bitmap->bitmap[bitmap->bitmapwords]; | |
97 | } | |
98 | return (list); | |
99 | } | |
100 | ||
101 | void | |
102 | hibernate_page_list_setall_machine(hibernate_page_list_t * page_list, | |
103 | hibernate_page_list_t * page_list_wired, | |
104 | uint32_t * pagesOut) | |
105 | { | |
106 | uint32_t page, count, PCAsize; | |
107 | ||
108 | /* Get total size of PCA table */ | |
109 | PCAsize = round_page((hash_table_size / PerProcTable[0].ppe_vaddr->pf.pfPTEG) | |
110 | * sizeof(PCA_t)); | |
111 | ||
112 | page = atop_64(hash_table_base - PCAsize); | |
113 | count = atop_64(hash_table_size + PCAsize); | |
114 | ||
115 | hibernate_set_page_state(page_list, page_list_wired, page, count, 0); | |
116 | pagesOut -= count; | |
117 | ||
118 | HIBLOG("removed hash, pca: %d pages\n", count); | |
119 | ||
120 | save_snapshot(); | |
121 | } | |
122 | ||
0c530ab8 A |
123 | // mark pages not to be saved and not for scratch usage during restore |
124 | void | |
2d21ac55 A |
125 | hibernate_page_list_set_volatile(__unused hibernate_page_list_t *page_list, |
126 | __unused hibernate_page_list_t *page_list_wired, | |
127 | __unused uint32_t *pagesOut) | |
0c530ab8 A |
128 | { |
129 | } | |
130 | ||
3a60a9f5 A |
131 | kern_return_t |
132 | hibernate_processor_setup(IOHibernateImageHeader * header) | |
133 | { | |
134 | header->processorFlags = PerProcTable[0].ppe_vaddr->pf.Available; | |
135 | ||
136 | PerProcTable[0].ppe_vaddr->hibernate = 1; | |
137 | ||
138 | return (KERN_SUCCESS); | |
139 | } | |
140 | ||
141 | void | |
142 | hibernate_vm_lock(void) | |
143 | { | |
144 | if (getPerProc()->hibernate) | |
145 | { | |
146 | vm_page_lock_queues(); | |
b0d623f7 | 147 | lck_mtx_lock(&vm_page_queue_free_lock); |
3a60a9f5 A |
148 | } |
149 | } | |
150 | ||
151 | void | |
152 | hibernate_vm_unlock(void) | |
153 | { | |
154 | if (getPerProc()->hibernate) | |
155 | { | |
b0d623f7 | 156 | lck_mtx_unlock(&vm_page_queue_free_lock); |
3a60a9f5 A |
157 | vm_page_unlock_queues(); |
158 | } | |
159 | } | |
160 | ||
161 | void ml_ppc_sleep(void) | |
162 | { | |
163 | struct per_proc_info *proc_info; | |
164 | boolean_t dohalt; | |
165 | ||
166 | proc_info = getPerProc(); | |
167 | if (!proc_info->hibernate) | |
168 | { | |
169 | ml_ppc_do_sleep(); | |
170 | return; | |
171 | } | |
172 | ||
173 | { | |
174 | uint64_t start, end, nsec; | |
175 | ||
176 | HIBLOG("mapping_hibernate_flush start\n"); | |
177 | clock_get_uptime(&start); | |
178 | ||
179 | mapping_hibernate_flush(); | |
180 | ||
181 | clock_get_uptime(&end); | |
182 | absolutetime_to_nanoseconds(end - start, &nsec); | |
183 | HIBLOG("mapping_hibernate_flush time: %qd ms\n", nsec / 1000000ULL); | |
184 | } | |
185 | ||
186 | dohalt = hibernate_write_image(); | |
187 | ||
188 | if (dohalt) | |
189 | { | |
190 | // off | |
191 | HIBLOG("power off\n"); | |
192 | if (PE_halt_restart) | |
193 | (*PE_halt_restart)(kPEHaltCPU); | |
194 | } | |
195 | else | |
196 | { | |
197 | // sleep | |
198 | HIBLOG("sleep\n"); | |
199 | ||
200 | // should we come back via regular wake, set the state in memory. | |
201 | PerProcTable[0].ppe_vaddr->hibernate = 0; | |
202 | ||
203 | PE_cpu_machine_quiesce(proc_info->cpu_id); | |
204 | return; | |
205 | } | |
206 | } | |
207 | ||
0c530ab8 | 208 | void |
2d21ac55 A |
209 | hibernate_newruntime_map(__unused void * map, |
210 | __unused vm_size_t map_size, | |
211 | __unused uint32_t runtime_offset) | |
0c530ab8 A |
212 | { |
213 | } |