]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/hibernate_ppc.c
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #include <kern/kern_types.h>
24 #include <kern/kalloc.h>
25 #include <kern/machine.h>
26 #include <kern/misc_protos.h>
27 #include <kern/thread.h>
28 #include <kern/processor.h>
29 #include <mach/machine.h>
30 #include <mach/processor_info.h>
31 #include <mach/mach_types.h>
32 #include <ppc/proc_reg.h>
33 #include <ppc/misc_protos.h>
34 #include <ppc/machine_routines.h>
35 #include <ppc/machine_cpu.h>
36 #include <ppc/exception.h>
38 #include <ppc/hw_perfmon.h>
39 #include <pexpert/pexpert.h>
40 #include <kern/cpu_data.h>
41 #include <ppc/mappings.h>
42 #include <ppc/Diagnostics.h>
45 #include <IOKit/IOPlatformExpert.h>
48 #include <IOKit/IOHibernatePrivate.h>
49 #include <vm/vm_page.h>
51 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
53 hibernate_page_list_t
*
54 hibernate_page_list_allocate(void)
58 uint32_t pages
, page_count
;
59 hibernate_page_list_t
* list
;
60 hibernate_bitmap_t
* bitmap
;
63 size
= sizeof(hibernate_page_list_t
);
65 for (bank
= 0; bank
< (uint32_t) pmap_mem_regions_count
; bank
++)
67 size
+= sizeof(hibernate_bitmap_t
);
68 pages
= pmap_mem_regions
[bank
].mrEnd
+ 1 - pmap_mem_regions
[bank
].mrStart
;
70 size
+= ((pages
+ 31) >> 5) * sizeof(uint32_t);
77 list
->list_size
= size
;
78 list
->page_count
= page_count
;
79 list
->bank_count
= pmap_mem_regions_count
;
81 bitmap
= &list
->bank_bitmap
[0];
82 for (bank
= 0; bank
< list
->bank_count
; bank
++)
84 bitmap
->first_page
= pmap_mem_regions
[bank
].mrStart
;
85 bitmap
->last_page
= pmap_mem_regions
[bank
].mrEnd
;
86 bitmap
->bitmapwords
= (pmap_mem_regions
[bank
].mrEnd
+ 1
87 - pmap_mem_regions
[bank
].mrStart
+ 31) >> 5;
89 bitmap
= (hibernate_bitmap_t
*) &bitmap
->bitmap
[bitmap
->bitmapwords
];
95 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
96 hibernate_page_list_t
* page_list_wired
,
99 uint32_t page
, count
, PCAsize
;
101 /* Get total size of PCA table */
102 PCAsize
= round_page((hash_table_size
/ PerProcTable
[0].ppe_vaddr
->pf
.pfPTEG
)
105 page
= atop_64(hash_table_base
- PCAsize
);
106 count
= atop_64(hash_table_size
+ PCAsize
);
108 hibernate_set_page_state(page_list
, page_list_wired
, page
, count
, 0);
111 HIBLOG("removed hash, pca: %d pages\n", count
);
117 hibernate_processor_setup(IOHibernateImageHeader
* header
)
119 header
->processorFlags
= PerProcTable
[0].ppe_vaddr
->pf
.Available
;
121 PerProcTable
[0].ppe_vaddr
->hibernate
= 1;
123 return (KERN_SUCCESS
);
127 hibernate_vm_lock(void)
129 if (getPerProc()->hibernate
)
131 vm_page_lock_queues();
132 mutex_lock(&vm_page_queue_free_lock
);
137 hibernate_vm_unlock(void)
139 if (getPerProc()->hibernate
)
141 mutex_unlock(&vm_page_queue_free_lock
);
142 vm_page_unlock_queues();
146 void ml_ppc_sleep(void)
148 struct per_proc_info
*proc_info
;
151 proc_info
= getPerProc();
152 if (!proc_info
->hibernate
)
159 uint64_t start
, end
, nsec
;
161 HIBLOG("mapping_hibernate_flush start\n");
162 clock_get_uptime(&start
);
164 mapping_hibernate_flush();
166 clock_get_uptime(&end
);
167 absolutetime_to_nanoseconds(end
- start
, &nsec
);
168 HIBLOG("mapping_hibernate_flush time: %qd ms\n", nsec
/ 1000000ULL);
171 dohalt
= hibernate_write_image();
176 HIBLOG("power off\n");
178 (*PE_halt_restart
)(kPEHaltCPU
);
185 // should we come back via regular wake, set the state in memory.
186 PerProcTable
[0].ppe_vaddr
->hibernate
= 0;
188 PE_cpu_machine_quiesce(proc_info
->cpu_id
);