xref: /titanic_41/usr/src/psm/stand/cpr/sparcv9/sun4u/cprboot.h (revision 5fbb41393be5d63f75952b1d72d4df2642d22557)
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _CPRBOOT_H
27 #define	_CPRBOOT_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * defs for sun4u cprboot
37  */
38 
39 /*
40  * select virt ranges well past _end;
41  * these ranges are used for tmp tlb entries
42  *
43  *     CB_SRC_VIRT	source statefile buffer pages
44  *     CB_DST_VIRT	destination kernel pages
45  *     CB_STACK_VIRT	new stack
46  *     CB_HIGH_VIRT	...and above for the bitmap and co.
47  */
48 
49 #define	CB_SRC_VIRT	0x200000
50 #define	CB_DST_VIRT	0x300000
51 #define	CB_STACK_VIRT	0x400000
52 #define	CB_HIGH_VIRT	0x500000
53 
54 /*
55  * master cpu and slave cpu stack sizes
56  * their sum should be (n * MMU_PAGESIZE)
57  */
58 #define	CB_MSS		0x009000
59 #define	CB_SSS		0x001000
60 #define	CB_STACK_SIZE	(CB_MSS + CB_SSS)
61 
62 
63 /*
64  * max number of tlb entries and tmp pages for
65  * src statefile buf pages and dst kernel pages
66  */
67 #define	CB_MAX_KPAGES	mmu_btop(CPR_MAX_BLOCK)
68 #define	CB_MAX_BPAGES	(CB_MAX_KPAGES + 1)
69 
70 #define	ERR		-1
71 
72 
73 #ifndef _ASM
74 
75 #define	CB_VPRINTF(args) \
76 	if (verbose) prom_printf args
77 
78 #define	CB_VENTRY(name) \
79 	CB_VPRINTF((ent_fmt, #name, entry))
80 
81 #define	NULLP (char *)0
82 
83 #define	CPR_DBG(n)	(cpr_debug & CPR_DEBUG##n)
84 
85 
86 /*
87  * info for handling statefile data
88  */
89 struct statefile {
90 	int	fd;			/* prom file handle */
91 	int	kpages;			/* total number of kernel pages */
92 	size_t	size;			/* file size, rounded for alloc */
93 	caddr_t	buf;			/* allocated file buffer */
94 	size_t	buf_offset;		/* byte offset from buf */
95 	uint_t	*buf_map;		/* map of buf phys page numbers */
96 	pfn_t	low_ppn;		/* lowest buf ppn */
97 	pfn_t	high_ppn;		/* highest buf ppn */
98 	int	npages;			/* nubmer of pages restored */
99 	int	ngroups;		/* number of page groups restored */
100 	int	outside;		/* kpage is outside of buf range */
101 	int	precede;		/* kpage preceeds buf offset */
102 	int	move;			/* number of buf pages moved */
103 	int	recycle;		/* free tmp page for reuse */
104 };
105 
106 /*
107  * convert a statefile buffer byte-offset into a buffer ppn;
108  * buf_map starts out as an identity map, and gets updated as
109  * pages are moved; the original ppn can always be derived
110  * from the ORIG macro:
111  */
112 #define	SF_BUF_PPN(off)		*(sfile.buf_map + mmu_btop(off))
113 #define	SF_ORIG_PPN(off)	sfile.low_ppn + mmu_btop(off)
114 #define	SF_SAME_PPN(off)	(SF_BUF_PPN(off) == SF_ORIG_PPN(off))
115 #define	SF_DIFF_PPN(off)	(SF_BUF_PPN(off) != SF_ORIG_PPN(off))
116 
117 #define	SF_STAT_INC(field)	sfile.field++
118 
119 
120 /*
121  * next data in statefile buffer
122  */
123 #define	SF_DATA()	sfile.buf + sfile.buf_offset
124 
125 /*
126  * advance statefile buffer offset
127  */
128 #define	SF_ADV(len)	sfile.buf_offset += len
129 
130 /*
131  * struct data is written to the statefile without any alignment
132  * handling; for easy access, struct data gets copied to aligned
133  * space and the buf data pointer is advanced
134  */
135 #define	SF_DCOPY(space) \
136 	bcopy(SF_DATA(), &space, sizeof (space)); \
137 	SF_ADV(sizeof (space))
138 
139 
140 /*
141  * structure of "available" property from /memory node
142  */
143 struct prom_physavail {
144 	physaddr_t base;		/* start of phys range */
145 	size_t size;			/* size of phys range */
146 };
147 
148 struct avail_range {
149 	pfn_t low;
150 	pfn_t high;
151 	pgcnt_t nfree;
152 };
153 
154 typedef struct prom_physavail pphav_t;
155 typedef struct avail_range arange_t;
156 
157 
158 /*
159  * prom properties and data
160  */
161 struct cb_props {
162 	caddr_t prop;
163 	uint_t *datap;
164 };
165 
166 
167 /*
168  * ../../common/support.c
169  */
170 extern int cpr_reset_properties(void);
171 extern int cpr_locate_statefile(char *, char *);
172 extern void cpr_update_terminator(ctrm_t *, caddr_t);
173 
174 /*
175  * cprboot.c
176  */
177 extern struct statefile sfile;
178 extern char prog[];
179 extern char rsvp[];
180 extern char entry[];
181 extern char ent_fmt[];
182 extern int verbose;
183 extern uint_t cb_dents;
184 extern uint_t cb_msec;
185 extern char *volname;
186 
187 /*
188  * machdep.c
189  */
190 extern int cpr_test_mode;
191 extern csu_md_t mdinfo;
192 extern uint_t cpu_delay;
193 extern uint_t cb_mid;
194 extern uint_t cb_clock_freq;
195 extern int cb_check_machdep(void);
196 extern int cb_interpret(void);
197 extern int cb_ksetup(void);
198 extern int cb_mpsetup(void);
199 extern void slave_init(int);
200 
201 /*
202  * pages.c
203  */
204 extern int cb_restore_kpages(void);
205 extern int cb_terminator(void);
206 
207 /*
208  * bitmap.c
209  */
210 extern int cb_nbitmaps;
211 extern pfn_t find_apage(void);
212 extern int cb_set_bitmap(void);
213 extern int cb_get_newstack(void);
214 extern int cb_tracking_setup(void);
215 extern int cb_get_physavail(void);
216 extern int cb_relocate(void);
217 
218 /*
219  * util.c
220  */
221 extern int cpr_statefile_open(char *, char *);
222 extern int cpr_statefile_close(int);
223 extern int cpr_read(int, caddr_t, size_t);
224 extern void cb_spin(void);
225 extern pfn_t cpr_vatopfn(caddr_t);
226 extern int prom_remap(size_t, caddr_t, physaddr_t);
227 extern void install_remap(void);
228 extern int cb_alloc(size_t, uint_t, caddr_t *, physaddr_t *);
229 extern int cb_mountroot(void);
230 extern int cb_unmountroot(void);
231 extern int cb_get_props(void);
232 extern void cb_mapin(caddr_t, pfn_t, uint_t, uint_t, uint_t);
233 extern int cb_usb_setup(void);
234 extern void cb_enter_mon(void);
235 extern void cb_exit_to_mon(void);
236 extern int cpr_fs_close(int);
237 extern int cpr_fs_volopen(char *);
238 extern int cpr_fs_open(char *);
239 extern int cpr_fs_read(int, char *, int);
240 extern int cpr_fs_seek(int, offset_t);
241 extern int cpr_read(int, char *, size_t);
242 
243 /*
244  * cb_srt0.s
245  */
246 extern caddr_t _end[];
247 extern void *estack;
248 extern void _start(void *, ...);
249 extern void exit_to_kernel(void *, csu_md_t *);
250 extern void bzero(void *, size_t);
251 extern void phys_xcopy(physaddr_t, physaddr_t, size_t);
252 extern void ptov_bcopy(physaddr_t, void *, size_t);
253 extern void get_dtlb_entry(int, caddr_t *, tte_t *);
254 extern void set_dtlb_entry(int, caddr_t, tte_t *);
255 extern void set_itlb_entry(int, caddr_t, tte_t *);
256 extern void cpu_launch(int);
257 extern void cb_usec_wait(int);
258 extern void membar_stld(void);
259 extern uint_t getmid(void);
260 
261 #endif /* !_ASM */
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif	/* _CPRBOOT_H */
268