17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ae115bc7Smrj  * Common Development and Distribution License (the "License").
6ae115bc7Smrj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*e7cbe64fSgw25295  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _CPRBOOT_H
277c478bd9Sstevel@tonic-gate #define	_CPRBOOT_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef __cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * defs for sun4u cprboot
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * select virt ranges well past _end;
417c478bd9Sstevel@tonic-gate  * these ranges are used for tmp tlb entries
427c478bd9Sstevel@tonic-gate  *
437c478bd9Sstevel@tonic-gate  *     CB_SRC_VIRT	source statefile buffer pages
447c478bd9Sstevel@tonic-gate  *     CB_DST_VIRT	destination kernel pages
457c478bd9Sstevel@tonic-gate  *     CB_STACK_VIRT	new stack
467c478bd9Sstevel@tonic-gate  *     CB_HIGH_VIRT	...and above for the bitmap and co.
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #define	CB_SRC_VIRT	0x200000
507c478bd9Sstevel@tonic-gate #define	CB_DST_VIRT	0x300000
517c478bd9Sstevel@tonic-gate #define	CB_STACK_VIRT	0x400000
527c478bd9Sstevel@tonic-gate #define	CB_HIGH_VIRT	0x500000
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * master cpu and slave cpu stack sizes
567c478bd9Sstevel@tonic-gate  * their sum should be (n * MMU_PAGESIZE)
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate #define	CB_MSS		0x009000
597c478bd9Sstevel@tonic-gate #define	CB_SSS		0x001000
607c478bd9Sstevel@tonic-gate #define	CB_STACK_SIZE	(CB_MSS + CB_SSS)
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * max number of tlb entries and tmp pages for
657c478bd9Sstevel@tonic-gate  * src statefile buf pages and dst kernel pages
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate #define	CB_MAX_KPAGES	mmu_btop(CPR_MAX_BLOCK)
687c478bd9Sstevel@tonic-gate #define	CB_MAX_BPAGES	(CB_MAX_KPAGES + 1)
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	ERR		-1
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate #ifndef _ASM
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #define	CB_VPRINTF(args) \
767c478bd9Sstevel@tonic-gate 	if (verbose) prom_printf args
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #define	CB_VENTRY(name) \
797c478bd9Sstevel@tonic-gate 	CB_VPRINTF((ent_fmt, #name, entry))
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	NULLP (char *)0
827c478bd9Sstevel@tonic-gate 
83ae115bc7Smrj #define	CPR_DBG(n)	(cpr_debug & CPR_DEBUG##n)
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * info for handling statefile data
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate struct statefile {
907c478bd9Sstevel@tonic-gate 	int	fd;			/* prom file handle */
917c478bd9Sstevel@tonic-gate 	int	kpages;			/* total number of kernel pages */
927c478bd9Sstevel@tonic-gate 	size_t	size;			/* file size, rounded for alloc */
937c478bd9Sstevel@tonic-gate 	caddr_t	buf;			/* allocated file buffer */
947c478bd9Sstevel@tonic-gate 	size_t	buf_offset;		/* byte offset from buf */
957c478bd9Sstevel@tonic-gate 	uint_t	*buf_map;		/* map of buf phys page numbers */
967c478bd9Sstevel@tonic-gate 	pfn_t	low_ppn;		/* lowest buf ppn */
977c478bd9Sstevel@tonic-gate 	pfn_t	high_ppn;		/* highest buf ppn */
987c478bd9Sstevel@tonic-gate 	int	npages;			/* nubmer of pages restored */
997c478bd9Sstevel@tonic-gate 	int	ngroups;		/* number of page groups restored */
1007c478bd9Sstevel@tonic-gate 	int	outside;		/* kpage is outside of buf range */
1017c478bd9Sstevel@tonic-gate 	int	precede;		/* kpage preceeds buf offset */
1027c478bd9Sstevel@tonic-gate 	int	move;			/* number of buf pages moved */
1037c478bd9Sstevel@tonic-gate 	int	recycle;		/* free tmp page for reuse */
1047c478bd9Sstevel@tonic-gate };
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * convert a statefile buffer byte-offset into a buffer ppn;
1087c478bd9Sstevel@tonic-gate  * buf_map starts out as an identity map, and gets updated as
1097c478bd9Sstevel@tonic-gate  * pages are moved; the original ppn can always be derived
1107c478bd9Sstevel@tonic-gate  * from the ORIG macro:
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate #define	SF_BUF_PPN(off)		*(sfile.buf_map + mmu_btop(off))
1137c478bd9Sstevel@tonic-gate #define	SF_ORIG_PPN(off)	sfile.low_ppn + mmu_btop(off)
1147c478bd9Sstevel@tonic-gate #define	SF_SAME_PPN(off)	(SF_BUF_PPN(off) == SF_ORIG_PPN(off))
1157c478bd9Sstevel@tonic-gate #define	SF_DIFF_PPN(off)	(SF_BUF_PPN(off) != SF_ORIG_PPN(off))
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #define	SF_STAT_INC(field)	sfile.field++
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * next data in statefile buffer
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate #define	SF_DATA()	sfile.buf + sfile.buf_offset
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate  * advance statefile buffer offset
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate #define	SF_ADV(len)	sfile.buf_offset += len
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate /*
1317c478bd9Sstevel@tonic-gate  * struct data is written to the statefile without any alignment
1327c478bd9Sstevel@tonic-gate  * handling; for easy access, struct data gets copied to aligned
1337c478bd9Sstevel@tonic-gate  * space and the buf data pointer is advanced
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate #define	SF_DCOPY(space) \
1367c478bd9Sstevel@tonic-gate 	bcopy(SF_DATA(), &space, sizeof (space)); \
1377c478bd9Sstevel@tonic-gate 	SF_ADV(sizeof (space))
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate  * structure of "available" property from /memory node
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate struct prom_physavail {
1447c478bd9Sstevel@tonic-gate 	physaddr_t base;		/* start of phys range */
1457c478bd9Sstevel@tonic-gate 	size_t size;			/* size of phys range */
1467c478bd9Sstevel@tonic-gate };
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate struct avail_range {
1497c478bd9Sstevel@tonic-gate 	pfn_t low;
1507c478bd9Sstevel@tonic-gate 	pfn_t high;
1517c478bd9Sstevel@tonic-gate 	pgcnt_t nfree;
1527c478bd9Sstevel@tonic-gate };
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate typedef struct prom_physavail pphav_t;
1557c478bd9Sstevel@tonic-gate typedef struct avail_range arange_t;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate  * prom properties and data
1607c478bd9Sstevel@tonic-gate  */
1617c478bd9Sstevel@tonic-gate struct cb_props {
1627c478bd9Sstevel@tonic-gate 	caddr_t prop;
1637c478bd9Sstevel@tonic-gate 	uint_t *datap;
1647c478bd9Sstevel@tonic-gate };
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate  * ../../common/support.c
1697c478bd9Sstevel@tonic-gate  */
1707c478bd9Sstevel@tonic-gate extern int cpr_reset_properties(void);
1717c478bd9Sstevel@tonic-gate extern int cpr_locate_statefile(char *, char *);
1727c478bd9Sstevel@tonic-gate extern void cpr_update_terminator(ctrm_t *, caddr_t);
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /*
1757c478bd9Sstevel@tonic-gate  * cprboot.c
1767c478bd9Sstevel@tonic-gate  */
1777c478bd9Sstevel@tonic-gate extern struct statefile sfile;
1787c478bd9Sstevel@tonic-gate extern char prog[];
1797c478bd9Sstevel@tonic-gate extern char rsvp[];
1807c478bd9Sstevel@tonic-gate extern char entry[];
1817c478bd9Sstevel@tonic-gate extern char ent_fmt[];
1827c478bd9Sstevel@tonic-gate extern int verbose;
1837c478bd9Sstevel@tonic-gate extern uint_t cb_dents;
1847c478bd9Sstevel@tonic-gate extern uint_t cb_msec;
185*e7cbe64fSgw25295 extern char *volname;
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * machdep.c
1897c478bd9Sstevel@tonic-gate  */
1907c478bd9Sstevel@tonic-gate extern int cpr_test_mode;
1917c478bd9Sstevel@tonic-gate extern csu_md_t mdinfo;
1927c478bd9Sstevel@tonic-gate extern uint_t cpu_delay;
1937c478bd9Sstevel@tonic-gate extern uint_t cb_mid;
1947c478bd9Sstevel@tonic-gate extern uint_t cb_clock_freq;
1957c478bd9Sstevel@tonic-gate extern int cb_check_machdep(void);
1967c478bd9Sstevel@tonic-gate extern int cb_interpret(void);
1977c478bd9Sstevel@tonic-gate extern int cb_ksetup(void);
1987c478bd9Sstevel@tonic-gate extern int cb_mpsetup(void);
1997c478bd9Sstevel@tonic-gate extern void slave_init(int);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate /*
2027c478bd9Sstevel@tonic-gate  * pages.c
2037c478bd9Sstevel@tonic-gate  */
2047c478bd9Sstevel@tonic-gate extern int cb_restore_kpages(void);
2057c478bd9Sstevel@tonic-gate extern int cb_terminator(void);
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * bitmap.c
2097c478bd9Sstevel@tonic-gate  */
2107c478bd9Sstevel@tonic-gate extern int cb_nbitmaps;
2117c478bd9Sstevel@tonic-gate extern pfn_t find_apage(void);
2127c478bd9Sstevel@tonic-gate extern int cb_set_bitmap(void);
2137c478bd9Sstevel@tonic-gate extern int cb_get_newstack(void);
2147c478bd9Sstevel@tonic-gate extern int cb_tracking_setup(void);
2157c478bd9Sstevel@tonic-gate extern int cb_get_physavail(void);
2167c478bd9Sstevel@tonic-gate extern int cb_relocate(void);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate  * util.c
2207c478bd9Sstevel@tonic-gate  */
2217c478bd9Sstevel@tonic-gate extern int cpr_statefile_open(char *, char *);
2227c478bd9Sstevel@tonic-gate extern int cpr_statefile_close(int);
2237c478bd9Sstevel@tonic-gate extern int cpr_read(int, caddr_t, size_t);
2247c478bd9Sstevel@tonic-gate extern void cb_spin(void);
2257c478bd9Sstevel@tonic-gate extern pfn_t cpr_vatopfn(caddr_t);
2267c478bd9Sstevel@tonic-gate extern int prom_remap(size_t, caddr_t, physaddr_t);
2277c478bd9Sstevel@tonic-gate extern void install_remap(void);
2287c478bd9Sstevel@tonic-gate extern int cb_alloc(size_t, uint_t, caddr_t *, physaddr_t *);
229986fd29aSsetje extern int cb_mountroot(void);
230986fd29aSsetje extern int cb_unmountroot(void);
2317c478bd9Sstevel@tonic-gate extern int cb_get_props(void);
2327c478bd9Sstevel@tonic-gate extern void cb_mapin(caddr_t, pfn_t, uint_t, uint_t, uint_t);
2337c478bd9Sstevel@tonic-gate extern int cb_usb_setup(void);
2347c478bd9Sstevel@tonic-gate extern void cb_enter_mon(void);
2357c478bd9Sstevel@tonic-gate extern void cb_exit_to_mon(void);
236986fd29aSsetje extern int cpr_fs_close(int);
237*e7cbe64fSgw25295 extern int cpr_fs_volopen(char *);
238986fd29aSsetje extern int cpr_fs_open(char *);
239986fd29aSsetje extern int cpr_fs_read(int, char *, int);
240986fd29aSsetje extern int cpr_fs_seek(int, offset_t);
241986fd29aSsetje extern int cpr_read(int, char *, size_t);
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate  * cb_srt0.s
2457c478bd9Sstevel@tonic-gate  */
2467c478bd9Sstevel@tonic-gate extern caddr_t _end[];
2477c478bd9Sstevel@tonic-gate extern void *estack;
2487c478bd9Sstevel@tonic-gate extern void _start(void *, ...);
2497c478bd9Sstevel@tonic-gate extern void exit_to_kernel(void *, csu_md_t *);
2507c478bd9Sstevel@tonic-gate extern void bzero(void *, size_t);
2517c478bd9Sstevel@tonic-gate extern void phys_xcopy(physaddr_t, physaddr_t, size_t);
2527c478bd9Sstevel@tonic-gate extern void ptov_bcopy(physaddr_t, void *, size_t);
2537c478bd9Sstevel@tonic-gate extern void get_dtlb_entry(int, caddr_t *, tte_t *);
2547c478bd9Sstevel@tonic-gate extern void set_dtlb_entry(int, caddr_t, tte_t *);
2557c478bd9Sstevel@tonic-gate extern void set_itlb_entry(int, caddr_t, tte_t *);
2567c478bd9Sstevel@tonic-gate extern void cpu_launch(int);
2577c478bd9Sstevel@tonic-gate extern void cb_usec_wait(int);
2587c478bd9Sstevel@tonic-gate extern void membar_stld(void);
2597c478bd9Sstevel@tonic-gate extern uint_t getmid(void);
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate #endif /* !_ASM */
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2647c478bd9Sstevel@tonic-gate }
2657c478bd9Sstevel@tonic-gate #endif
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate #endif	/* _CPRBOOT_H */
268