xref: /titanic_50/usr/src/uts/i86pc/sys/fastboot.h (revision 0a1278f26ea4b7c8c0285d4f2d6c5b680904aa01)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_FASTBOOT_H
28 #define	_SYS_FASTBOOT_H
29 
30 
31 /*
32  * Platform dependent instruction sequences for fast reboot
33  */
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #ifndef	_ASM
40 #include <sys/types.h>
41 #include <sys/mach_mmu.h>
42 #include <sys/md5.h>
43 #endif	/* _ASM */
44 
45 #define	FASTBOOT_NAME_UNIX		0
46 #define	FASTBOOT_NAME_BOOTARCHIVE	1
47 
48 #define	FASTBOOT_MAX_FILES_MAP	2 /* max number of files that needs mapping */
49 #define	FASTBOOT_MAX_FILES_TOTAL	3 /* max number of files */
50 
51 #define	FASTBOOT_MAX_MD5_HASH	(FASTBOOT_MAX_FILES_MAP + 1)
52 
53 #define	FASTBOOT_SWTCH_PA		0x5000	/* low memory */
54 #define	FASTBOOT_STACK_OFFSET		0xe00	/* where the stack starts */
55 #define	FASTBOOT_MAGIC			('F' << 24 | 'A' << 16 | 'S' << 8 | 'T')
56 
57 #define	FASTBOOT_UNIX		0
58 #define	FASTBOOT_BOOTARCHIVE	1
59 #define	FASTBOOT_SWTCH		2
60 
61 /*
62  * Default sizes for varies information we have to save across boot for
63  * fast reboot.  If the actual size is bigger than what we saved, abort
64  * fast reboot.
65  */
66 #define	FASTBOOT_SAVED_MMAP_COUNT	32
67 
68 #define	FASTBOOT_SAVED_DRIVES_MAX	8
69 #define	FASTBOOT_SAVED_DRIVES_PORT_MAX	128
70 #define	FASTBOOT_SAVED_DRIVES_SIZE	\
71 	((offsetof(struct mb_drive_info, drive_ports) +	\
72 	FASTBOOT_SAVED_DRIVES_PORT_MAX * sizeof (uint16_t)) *	\
73 	FASTBOOT_SAVED_DRIVES_MAX)
74 
75 #define	FASTBOOT_SAVED_CMDLINE_LEN	MMU_PAGESIZE
76 
77 
78 /*
79  * dboot entry address comes from
80  * usr/src/uts/i86pc/conf/Mapfile and Mapfile.64.
81  */
82 #define	DBOOT_ENTRY_ADDRESS	0xc00000
83 
84 /*
85  * Fake starting virtual address for creating mapping for the new kernel
86  * and boot_archive.
87  */
88 #define	FASTBOOT_FAKE_VA	(2ULL << 30)
89 
90 #define	FASTBOOT_TERMINATE	0xdeadbee0	/* Terminating PTEs */
91 
92 #ifndef	_ASM
93 
94 #define	MAX_ELF32_LOAD_SECTIONS 3
95 
96 /*
97  * Data structure for specifying each section in a 32-bit ELF file.
98  */
99 typedef struct fastboot_section
100 {
101 	uint32_t		fb_sec_offset;	/* offset */
102 	uint32_t		fb_sec_paddr;	/* physical address */
103 	uint32_t		fb_sec_size;	/* size */
104 	uint32_t		fb_sec_bss_size;	/* section bss size */
105 } fastboot_section_t;
106 
107 /*
108  * Data structure for describing each file that needs to be relocated from high
109  * memory to low memory for fast reboot.  Currently these files are unix, the
110  * boot_archive, and the relocation function itself.
111  */
112 typedef struct _fastboot_file {
113 	uintptr_t		fb_va;	/* virtual address */
114 	x86pte_t		*fb_pte_list_va;	/* VA for PTE list */
115 	paddr_t			fb_pte_list_pa;		/* PA for PTE list */
116 	size_t			fb_pte_list_size;	/* size of PTE list */
117 	uintptr_t		fb_dest_pa;	/* destination PA */
118 	size_t			fb_size;	/* file size */
119 	uintptr_t		fb_next_pa;
120 	fastboot_section_t	fb_sections[MAX_ELF32_LOAD_SECTIONS];
121 	int			fb_sectcnt;	/* actual number of sections */
122 } fastboot_file_t;
123 
124 /*
125  * Data structure containing all the information the switching routine needs
126  * for fast rebooting to the new kernel.
127  *
128  * NOTE: There is limited stack space (0x200 bytes) in the switcher to
129  * copy in the data structure.  Fields that are not absolutely necessary for
130  * the switcher should be added after the fi_valid field.
131  */
132 typedef struct _fastboot_info {
133 	uint32_t		fi_magic; /* magic for fast reboot */
134 	fastboot_file_t		fi_files[FASTBOOT_MAX_FILES_TOTAL];
135 	int			fi_has_pae;
136 	uintptr_t		fi_pagetable_va;
137 	paddr_t			fi_pagetable_pa;
138 	paddr_t			fi_last_table_pa;
139 	paddr_t			fi_new_mbi_pa;	/* new multiboot info PA */
140 	int			fi_valid;	/* is the new kernel valid */
141 	uintptr_t		fi_next_table_va;
142 	paddr_t			fi_next_table_pa;
143 	uint_t			*fi_shift_amt;
144 	uint_t			fi_ptes_per_table;
145 	uint_t			fi_lpagesize;
146 	int			fi_top_level;	/* top level of page tables */
147 	size_t			fi_pagetable_size; /* size allocated for pt */
148 	uintptr_t		fi_new_mbi_va;	/* new multiboot info VA */
149 	size_t			fi_mbi_size;	/* size allocated for mbi */
150 	uchar_t		fi_md5_hash[FASTBOOT_MAX_MD5_HASH][MD5_DIGEST_LENGTH];
151 } fastboot_info_t;
152 
153 
154 /*
155  * Fast reboot core functions
156  */
157 extern void fast_reboot();	/* Entry point for fb_switch */
158 extern void fastboot_load_kernel(char *); /* Load a new kernel */
159 
160 extern int fastboot_cksum_verify(fastboot_info_t *);
161 
162 /*
163  * Additional messages explaining why Fast Reboot is not
164  * supported.
165  */
166 extern const char *fastreboot_nosup_message(void);
167 /*
168  * Fast reboot tunables
169  */
170 
171 /* If set, the system is capable of fast reboot */
172 extern int volatile fastreboot_capable;
173 
174 /*
175  * If set, force fast reboot even if the system has
176  * drivers without quiesce(9E) implementation.
177  */
178 extern int force_fastreboot;
179 
180 /* If set, fast reboot after panic. */
181 extern volatile int fastreboot_onpanic;
182 extern char fastreboot_onpanic_cmdline[FASTBOOT_SAVED_CMDLINE_LEN];
183 
184 /* Variables for avoiding panic/reboot loop */
185 extern clock_t fastreboot_onpanic_uptime;
186 extern clock_t lbolt_at_boot, panic_lbolt;
187 
188 #endif	/* _ASM */
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif	/* _SYS_FASTBOOT_H */
195