xref: /titanic_52/usr/src/psm/stand/cpr/sparcv9/sun4u/cprboot.h (revision 6185db853e024a486ff8837e6784dd290d866112)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1999-2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _CPRBOOT_H
28 #define	_CPRBOOT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * defs for sun4u cprboot
38  */
39 
40 /*
41  * select virt ranges well past _end;
42  * these ranges are used for tmp tlb entries
43  *
44  *     CB_SRC_VIRT	source statefile buffer pages
45  *     CB_DST_VIRT	destination kernel pages
46  *     CB_STACK_VIRT	new stack
47  *     CB_HIGH_VIRT	...and above for the bitmap and co.
48  */
49 
50 #define	CB_SRC_VIRT	0x200000
51 #define	CB_DST_VIRT	0x300000
52 #define	CB_STACK_VIRT	0x400000
53 #define	CB_HIGH_VIRT	0x500000
54 
55 /*
56  * master cpu and slave cpu stack sizes
57  * their sum should be (n * MMU_PAGESIZE)
58  */
59 #define	CB_MSS		0x009000
60 #define	CB_SSS		0x001000
61 #define	CB_STACK_SIZE	(CB_MSS + CB_SSS)
62 
63 
64 /*
65  * max number of tlb entries and tmp pages for
66  * src statefile buf pages and dst kernel pages
67  */
68 #define	CB_MAX_KPAGES	mmu_btop(CPR_MAX_BLOCK)
69 #define	CB_MAX_BPAGES	(CB_MAX_KPAGES + 1)
70 
71 #define	ERR		-1
72 
73 
74 #ifndef _ASM
75 
76 #define	CB_VPRINTF(args) \
77 	if (verbose) prom_printf args
78 
79 #define	CB_VENTRY(name) \
80 	CB_VPRINTF((ent_fmt, #name, entry))
81 
82 #define	NULLP (char *)0
83 
84 #define	CPR_DBG(n)	(cpr_debug & LEVEL##n)
85 
86 
87 /*
88  * info for handling statefile data
89  */
90 struct statefile {
91 	int	fd;			/* prom file handle */
92 	int	kpages;			/* total number of kernel pages */
93 	size_t	size;			/* file size, rounded for alloc */
94 	caddr_t	buf;			/* allocated file buffer */
95 	size_t	buf_offset;		/* byte offset from buf */
96 	uint_t	*buf_map;		/* map of buf phys page numbers */
97 	pfn_t	low_ppn;		/* lowest buf ppn */
98 	pfn_t	high_ppn;		/* highest buf ppn */
99 	int	npages;			/* nubmer of pages restored */
100 	int	ngroups;		/* number of page groups restored */
101 	int	outside;		/* kpage is outside of buf range */
102 	int	precede;		/* kpage preceeds buf offset */
103 	int	move;			/* number of buf pages moved */
104 	int	recycle;		/* free tmp page for reuse */
105 };
106 
107 /*
108  * convert a statefile buffer byte-offset into a buffer ppn;
109  * buf_map starts out as an identity map, and gets updated as
110  * pages are moved; the original ppn can always be derived
111  * from the ORIG macro:
112  */
113 #define	SF_BUF_PPN(off)		*(sfile.buf_map + mmu_btop(off))
114 #define	SF_ORIG_PPN(off)	sfile.low_ppn + mmu_btop(off)
115 #define	SF_SAME_PPN(off)	(SF_BUF_PPN(off) == SF_ORIG_PPN(off))
116 #define	SF_DIFF_PPN(off)	(SF_BUF_PPN(off) != SF_ORIG_PPN(off))
117 
118 #define	SF_STAT_INC(field)	sfile.field++
119 
120 
121 /*
122  * next data in statefile buffer
123  */
124 #define	SF_DATA()	sfile.buf + sfile.buf_offset
125 
126 /*
127  * advance statefile buffer offset
128  */
129 #define	SF_ADV(len)	sfile.buf_offset += len
130 
131 /*
132  * struct data is written to the statefile without any alignment
133  * handling; for easy access, struct data gets copied to aligned
134  * space and the buf data pointer is advanced
135  */
136 #define	SF_DCOPY(space) \
137 	bcopy(SF_DATA(), &space, sizeof (space)); \
138 	SF_ADV(sizeof (space))
139 
140 
141 /*
142  * structure of "available" property from /memory node
143  */
144 struct prom_physavail {
145 	physaddr_t base;		/* start of phys range */
146 	size_t size;			/* size of phys range */
147 };
148 
149 struct avail_range {
150 	pfn_t low;
151 	pfn_t high;
152 	pgcnt_t nfree;
153 };
154 
155 typedef struct prom_physavail pphav_t;
156 typedef struct avail_range arange_t;
157 
158 
159 /*
160  * prom properties and data
161  */
162 struct cb_props {
163 	caddr_t prop;
164 	uint_t *datap;
165 };
166 
167 
168 /*
169  * ../../common/support.c
170  */
171 extern int cpr_reset_properties(void);
172 extern int cpr_locate_statefile(char *, char *);
173 extern void cpr_update_terminator(ctrm_t *, caddr_t);
174 
175 /*
176  * cprboot.c
177  */
178 extern struct statefile sfile;
179 extern char prog[];
180 extern char rsvp[];
181 extern char entry[];
182 extern char ent_fmt[];
183 extern int verbose;
184 extern uint_t cb_dents;
185 extern uint_t cb_msec;
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_get_props(void);
230 extern void cb_mapin(caddr_t, pfn_t, uint_t, uint_t, uint_t);
231 extern int cb_usb_setup(void);
232 extern void cb_enter_mon(void);
233 extern void cb_exit_to_mon(void);
234 
235 /*
236  * cb_srt0.s
237  */
238 extern caddr_t _end[];
239 extern void *estack;
240 extern void _start(void *, ...);
241 extern void exit_to_kernel(void *, csu_md_t *);
242 extern void bzero(void *, size_t);
243 extern void phys_xcopy(physaddr_t, physaddr_t, size_t);
244 extern void ptov_bcopy(physaddr_t, void *, size_t);
245 extern void get_dtlb_entry(int, caddr_t *, tte_t *);
246 extern void set_dtlb_entry(int, caddr_t, tte_t *);
247 extern void set_itlb_entry(int, caddr_t, tte_t *);
248 extern void cpu_launch(int);
249 extern void cb_usec_wait(int);
250 extern void membar_stld(void);
251 extern uint_t getmid(void);
252 
253 #endif /* !_ASM */
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 #endif	/* _CPRBOOT_H */
260