]> git.saurik.com Git - apple/xnu.git/blob - osfmk/arm64/pal_hibernate.h
88724f77272c2c860969e8f50bc8a2bd582fc328
[apple/xnu.git] / osfmk / arm64 / pal_hibernate.h
1 /*
2 * Copyright (c) 2020 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /**
29 * ARM64 specific definitions for hibernation platform abstraction layer.
30 */
31
32 #ifndef _ARM64_PAL_HIBERNATE_H
33 #define _ARM64_PAL_HIBERNATE_H
34
35 #include <IOKit/IOHibernatePrivate.h>
36
37 __BEGIN_DECLS
38
39 /*!
40 * @enum pal_hib_map_type_t
41 * @discussion Parameter to pal_hib_map used to signify which memory region to map.
42 */
43 typedef enum {
44 DEST_COPY_AREA = 1,
45 COPY_PAGE_AREA,
46 BITMAP_AREA,
47 IMAGE_AREA,
48 IMAGE2_AREA,
49 SCRATCH_AREA,
50 WKDM_AREA,
51 } pal_hib_map_type_t;
52
53 /*!
54 * @struct pal_hib_ctx
55 * @discussion ARM64-specific PAL context; see pal_hib_ctx_t for details.
56 */
57 struct pal_hib_ctx {
58 #if HIBERNATE_HMAC_IMAGE
59 struct ccdigest_info di;
60 hibernate_scratch_t pagesRestored;
61 #endif /* HIBERNATE_HMAC_IMAGE */
62 };
63
64 /*!
65 * @typedef pal_hib_globals_t
66 * @discussion ARM64-specific state preserved pre-hibernation and needed during hibernation resume.
67 *
68 * @field dockChannelRegBase Physical address of the dockchannel registers
69 * @field dockChannelWstatMask Mask to apply to dockchannel WSTAT register to compute available FIFO entries
70 * @field hibUartRegBase Physical address of the UART registers
71 * @field hmacRegBase Physical address of the hmac block registers
72 */
73 typedef struct {
74 uint64_t dockChannelRegBase;
75 uint64_t dockChannelWstatMask;
76 uint64_t hibUartRegBase;
77 uint64_t hmacRegBase;
78 } pal_hib_globals_t;
79 extern pal_hib_globals_t gHibernateGlobals;
80
81 /*!
82 * @function pal_hib_get_stack_pages
83 * @discussion Returns the stack base address and number of pages to use during hibernation resume.
84 *
85 * @param first_page Out parameter: the base address of the hibernation resume stack
86 * @param page_count Out parameter: the number of pages in the hibernation stack
87 */
88 void pal_hib_get_stack_pages(vm_offset_t *first_page, vm_offset_t *page_count);
89
90 /*!
91 * @function pal_hib_resume_tramp
92 * @discussion Platform-specific system setup before calling hibernate_kernel_entrypoint.
93 *
94 * @param headerPpnum The page number of the IOHibernateImageHeader
95 */
96 void pal_hib_resume_tramp(uint32_t headerPpnum);
97
98 /*!
99 * @typedef pal_hib_tramp_result_t
100 * @discussion This type is used to store the result of pal_hib_resume_tramp.
101 *
102 * @field ttbr0 Physical address of the first level translation table (low mem)
103 * @field ttbr1 Physical address of the first level translation table (high mem)
104 * @field memSlide Offset from physical address to virtual address during hibernation resume
105 * @field kernelSlide Offset from physical address to virtual address in the kernel map
106 */
107 typedef struct{
108 uint64_t ttbr0;
109 uint64_t ttbr1;
110 uint64_t memSlide;
111 uint64_t kernelSlide;
112 } pal_hib_tramp_result_t;
113
114 #if HIBERNATE_TRAP_HANDLER
115 /*!
116 * @function hibernate_trap
117 * @discussion Platform-specific function for handling a trap during hibernation resume.
118 *
119 * @param context The context captured during the trap
120 * @param trap_addr The address of the low level trap handler that was invoked
121 */
122 void hibernate_trap(arm_context_t *context, uint64_t trap_addr) __attribute__((noreturn));
123 #endif /* HIBERNATE_TRAP_HANDLER */
124
125 __END_DECLS
126
127 #endif /* _ARM64_PAL_HIBERNATE_H */