Current File : //usr/share/src/uts/i86pc/sys/fastboot.h
/*
 * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
 */

#ifndef	_SYS_FASTBOOT_H
#define	_SYS_FASTBOOT_H


/*
 * Platform dependent instruction sequences for fast reboot
 */

#ifdef __cplusplus
extern "C" {
#endif

#ifndef	_ASM
#include <sys/types.h>
#include <sys/mach_mmu.h>
#include <sys/md5.h>
#include <sys/defdump.h>
#endif	/* _ASM */

#define	FASTBOOT_NAME_UNIX		0
#define	FASTBOOT_NAME_BOOTARCHIVE	1

#define	FASTBOOT_MAX_FILES_MAP	2 /* max number of files that needs mapping */
#define	FASTBOOT_MAX_FILES_TOTAL	3 /* max number of files */

#define	FASTBOOT_MAX_MD5_HASH	(FASTBOOT_MAX_FILES_MAP + 1)

#define	FASTBOOT_SWTCH_PA		0x5000	/* low memory */
#define	FASTBOOT_STACK_OFFSET		0xe00	/* where the stack starts */
#define	FASTBOOT_MAGIC			('F' << 24 | 'A' << 16 | 'S' << 8 | 'T')
#define	FASTBOOT_SWTCH_SIZE		MMU_PAGESIZE

#define	FASTBOOT_UNIX		0
#define	FASTBOOT_BOOTARCHIVE	1
#define	FASTBOOT_SWTCH		2

/*
 * Default sizes for varies information we have to save across boot for
 * fast reboot.  If the actual size is bigger than what we saved, abort
 * fast reboot.
 */
#define	FASTBOOT_SAVED_MMAP_COUNT	1024

#define	FASTBOOT_SAVED_DRIVES_MAX	8
#define	FASTBOOT_SAVED_DRIVES_PORT_MAX	128
#define	FASTBOOT_SAVED_DRIVES_SIZE	\
	((offsetof(struct mb_drive_info, drive_ports) +	\
	FASTBOOT_SAVED_DRIVES_PORT_MAX * sizeof (uint16_t)) *	\
	FASTBOOT_SAVED_DRIVES_MAX)

#define	FASTBOOT_SAVED_CMDLINE_LEN	MMU_PAGESIZE


/*
 * dboot entry address comes from
 * usr/src/uts/i86pc/conf/Mapfile and Mapfile.64.
 */
#define	DBOOT_ENTRY_ADDRESS	0x1400000

/*
 * Fake starting virtual address for creating mapping for the new kernel
 * and boot_archive.
 */
#define	FASTBOOT_FAKE_VA	(2ULL << 30)

#define	FASTBOOT_TERMINATE	0xdeadbee0	/* Terminating PTEs */

#ifndef	_ASM

/*
 * Data structure for describing each file that needs to be relocated from high
 * memory to low memory for fast reboot.  Currently these files are unix, the
 * boot_archive, and the relocation function itself.
 */
typedef struct _fastboot_file {
	uintptr_t		fb_va;	/* virtual address */
	x86pte_t		*fb_pte_list_va;	/* VA for PTE list */
	paddr_t			fb_pte_list_pa;		/* PA for PTE list */
	size_t			fb_pte_list_size;	/* size of PTE list */
	uintptr_t		fb_dest_pa;	/* destination PA */
	size_t			fb_size;	/* file size */
	uintptr_t		fb_next_pa;
} fastboot_file_t;

/*
 * Data structure containing all the information the switching routine needs
 * for fast rebooting to the new kernel.
 *
 * NOTE: There is limited stack space (0x200 bytes) in the switcher to
 * copy in the data structure.  Fields that are not absolutely necessary for
 * the switcher should be added after the fi_valid field.
 */
typedef struct _fastboot_info {
	uint32_t		fi_magic; /* magic for fast reboot */
	fastboot_file_t		fi_files[FASTBOOT_MAX_FILES_TOTAL];
	int			fi_has_pae;
	uintptr_t		fi_pagetable_va;
	paddr_t			fi_pagetable_pa;
	paddr_t			fi_last_table_pa;
	paddr_t			fi_new_mbi_pa;	/* new multiboot info PA */
	uint32_t		fi_mbi_bootloader_magic;
	int			fi_valid;	/* is the new kernel valid */
	uintptr_t		fi_next_table_va;
	paddr_t			fi_next_table_pa;
	uint_t			*fi_shift_amt;
	uint_t			fi_ptes_per_table;
	uint_t			fi_lpagesize;
	int			fi_top_level;	/* top level of page tables */
	size_t			fi_pagetable_size; /* size allocated for pt */
	uintptr_t		fi_new_mbi_va;	/* new multiboot info VA */
	size_t			fi_mbi_size;	/* size allocated for mbi */
	uchar_t		fi_md5_hash[FASTBOOT_MAX_MD5_HASH][MD5_DIGEST_LENGTH];
} fastboot_info_t;

extern fastboot_info_t newkernel;

/*
 * mutex to hold when calling fastboot_load_kernel()
 */
extern kmutex_t fastreboot_config_mutex;

/*
 * Fast reboot core functions
 */
extern void fast_reboot();	/* Entry point for fb_switch */
extern int fastboot_load_kernel(char *); /* Load a new kernel */

extern int fastboot_cksum_verify(fastboot_info_t *);
extern boolean_t fastboot_update_cmdline(char *cmdline);

/*
 * Additional messages explaining why Fast Reboot is not
 * supported.
 */
extern const char *fastreboot_nosup_message(void);


/*
 * Fast reboot tunables
 */

/* If set, the system is capable of fast reboot */
extern int volatile fastreboot_capable;

/*
 * If set, force fast reboot even if the system has
 * drivers without quiesce(9E) implementation.
 */
extern int force_fastreboot;

/* If set, fast reboot after panic. */
extern volatile int fastreboot_onpanic;
extern char fastreboot_onpanic_cmdline[FASTBOOT_SAVED_CMDLINE_LEN];

/* Variables for avoiding panic/reboot loop */
extern clock_t panic_lbolt;
extern boolean_t would_fastreboot(int);

#endif	/* _ASM */

#ifdef __cplusplus
}
#endif

#endif	/* _SYS_FASTBOOT_H */