193974072f41a843678abf5f61979c748687e66bSherry Moore * CDDL HEADER START
193974072f41a843678abf5f61979c748687e66bSherry Moore * The contents of this file are subject to the terms of the
193974072f41a843678abf5f61979c748687e66bSherry Moore * Common Development and Distribution License (the "License").
193974072f41a843678abf5f61979c748687e66bSherry Moore * You may not use this file except in compliance with the License.
193974072f41a843678abf5f61979c748687e66bSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
193974072f41a843678abf5f61979c748687e66bSherry Moore * See the License for the specific language governing permissions
193974072f41a843678abf5f61979c748687e66bSherry Moore * and limitations under the License.
193974072f41a843678abf5f61979c748687e66bSherry Moore * When distributing Covered Code, include this CDDL HEADER in each
193974072f41a843678abf5f61979c748687e66bSherry Moore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
193974072f41a843678abf5f61979c748687e66bSherry Moore * If applicable, add the following below this CDDL HEADER, with the
193974072f41a843678abf5f61979c748687e66bSherry Moore * fields enclosed by brackets "[]" replaced with your own identifying
193974072f41a843678abf5f61979c748687e66bSherry Moore * information: Portions Copyright [yyyy] [name of copyright owner]
193974072f41a843678abf5f61979c748687e66bSherry Moore * CDDL HEADER END
7417cfdecea1902cef03c0d61a72df97d945925dKuriakose Kuruvilla * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * This file contains the functions for performing Fast Reboot -- a
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * reboot which bypasses the firmware and bootloader, considerably
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * reducing downtime.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fastboot_load_kernel(): This function is invoked by mdpreboot() in the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * reboot path. It loads the new kernel and boot archive into memory, builds
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * the data structure containing sufficient information about the new
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * kernel and boot archive to be passed to the fast reboot switcher
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * (see fb_swtch_src.s for details). When invoked the switcher relocates
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * the new kernel and boot archive to physically contiguous low memory,
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * similar to where the boot loader would have loaded them, and jumps to
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * the new kernel.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If fastreboot_onpanic is enabled, fastboot_load_kernel() is called
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * by fastreboot_post_startup() to load the back up kernel in case of
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * The physical addresses of the memory allocated for the new kernel, boot
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * archive and their page tables must be above where the boot archive ends
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * after it has been relocated by the switcher, otherwise the new files
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * and their page tables could be overridden during relocation.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * fast_reboot(): This function is invoked by mdboot() once it's determined
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * that the system is capable of fast reboot. It jumps to the fast reboot
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * switcher with the data structure built by fastboot_load_kernel() as the
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Macro to determine how many pages are needed for PTEs to map a particular
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * file. Allocate one extra page table entry for terminating the list.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore P2ROUNDUP((((fsize) >> PAGESHIFT) + 1) * sizeof (x86pte_t), PAGESIZE)
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * Data structure containing necessary information for the fast reboot
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * switcher to jump to the new kernel.
193974072f41a843678abf5f61979c748687e66bSherry Moorestatic char fastboot_filename[2][OBP_MAXPATHLEN] = { { 0 }, { 0 }};
193974072f41a843678abf5f61979c748687e66bSherry Moorestatic x86pte_t ptp_bits = PT_VALID | PT_REF | PT_USER | PT_WRITABLE;
193974072f41a843678abf5f61979c748687e66bSherry Moore PT_VALID | PT_REF | PT_MOD | PT_NOCONSIST | PT_WRITABLE;
193974072f41a843678abf5f61979c748687e66bSherry Moorestatic uint_t fastboot_shift_amt_pae[] = {12, 21, 30, 39};
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev/* Index into Fast Reboot not supported message array */
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyevstatic uint32_t fastreboot_nosup_id = FBNS_DEFAULT;
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev/* Fast Reboot not supported message array */
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyevstatic const char * const fastreboot_nosup_desc[FBNS_END] = {
193974072f41a843678abf5f61979c748687e66bSherry Moore * Fake starting va for new kernel and boot archive.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Reserve memory below PA 1G in preparation of fast reboot.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * This variable is only checked when fastreboot_capable is set, but
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fastreboot_onpanic is not set. The amount of memory reserved
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * is negligible, but just in case we are really short of low memory,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * this variable will give us a backdoor to not consume memory at all.
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore * Mutex to protect fastreboot_onpanic.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Amount of memory below PA 1G to reserve for constructing the multiboot
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * data structure and the page tables as we tend to run out of those
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * when more drivers are loaded.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorestatic size_t fastboot_mbi_size = 0x2000; /* 8K */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorestatic size_t fastboot_pagetable_size = 0x5000; /* 20K */
835b9930bd7bb9c7d0ed6d788e7314ffd3f3177dSherry Moore * Minimum system uptime in clock_t before Fast Reboot should be used
835b9930bd7bb9c7d0ed6d788e7314ffd3f3177dSherry Moore * on panic. Will be initialized in fastboot_post_startup().
835b9930bd7bb9c7d0ed6d788e7314ffd3f3177dSherry Moore * lbolt value when the system booted. This value will be used if the system
835b9930bd7bb9c7d0ed6d788e7314ffd3f3177dSherry Moore * panics to calculate how long the system has been up. If the uptime is less
835b9930bd7bb9c7d0ed6d788e7314ffd3f3177dSherry Moore * than fastreboot_onpanic_uptime, a reboot through BIOS will be performed to
835b9930bd7bb9c7d0ed6d788e7314ffd3f3177dSherry Moore * avoid a potential panic/reboot loop.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Use below 1G for page tables as
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * 1. we are only doing 1:1 mapping of the bottom 1G of physical memory.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * 2. we are using 2G as the fake virtual address for the new kernel and
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * boot archive.
193974072f41a843678abf5f61979c748687e66bSherry Moorestatic ddi_dma_attr_t fastboot_below_1G_dma_attr = {
193974072f41a843678abf5f61979c748687e66bSherry Moore 0x0000000008000000ULL, /* dma_attr_addr_lo: 128MB */
193974072f41a843678abf5f61979c748687e66bSherry Moore 0x000000003FFFFFFFULL, /* dma_attr_addr_hi: 1G */
193974072f41a843678abf5f61979c748687e66bSherry Moore 0x00000000FFFFFFFFULL, /* dma_attr_count_max */
193974072f41a843678abf5f61979c748687e66bSherry Moore 0x0000000000001000ULL, /* dma_attr_align: 4KB */
193974072f41a843678abf5f61979c748687e66bSherry Moore 0, /* dma_attr_flags */
193974072f41a843678abf5f61979c748687e66bSherry Moore 0x0000000008000000ULL, /* dma_attr_addr_lo: 128MB */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev 0xFFFFFFFFFFFFFFFFULL, /* dma_attr_addr_hi: 2^64B */
193974072f41a843678abf5f61979c748687e66bSherry Moore 0x0000000FFFFFFFFFULL, /* dma_attr_addr_hi: 64GB */
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev#endif /* __amd64 */
193974072f41a843678abf5f61979c748687e66bSherry Moore 0x00000000FFFFFFFFULL, /* dma_attr_count_max */
193974072f41a843678abf5f61979c748687e66bSherry Moore 0x0000000000001000ULL, /* dma_attr_align: 4KB */
193974072f41a843678abf5f61979c748687e66bSherry Moore 0, /* dma_attr_flags */
193974072f41a843678abf5f61979c748687e66bSherry Moore * Various information saved from the previous boot to reconstruct
193974072f41a843678abf5f61979c748687e66bSherry Moore * multiboot_info.
193974072f41a843678abf5f61979c748687e66bSherry Mooreextern mb_memory_map_t saved_mmap[FASTBOOT_SAVED_MMAP_COUNT];
6915124bb75bc67ae012532a3a7727adc043a7cbKonstantin Ananyevextern uint8_t saved_drives[FASTBOOT_SAVED_DRIVES_SIZE];
193974072f41a843678abf5f61979c748687e66bSherry Mooreextern char saved_cmdline[FASTBOOT_SAVED_CMDLINE_LEN];
193974072f41a843678abf5f61979c748687e66bSherry Mooreextern void* contig_alloc(size_t size, ddi_dma_attr_t *attr,
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Mooreextern void contig_free(void *addr, size_t size);
193974072f41a843678abf5f61979c748687e66bSherry Moore/* PRINTLIKE */
193974072f41a843678abf5f61979c748687e66bSherry Moore * Need to be able to get boot_archives from other places
193974072f41a843678abf5f61979c748687e66bSherry Moore#define BOOTARCHIVE64 "/platform/i86pc/amd64/boot_archive"
193974072f41a843678abf5f61979c748687e66bSherry Moore#define BOOTARCHIVE32 "/platform/i86pc/boot_archive"
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#define BOOTARCHIVE32_FAILSAFE "/boot/x86.miniroot-safe"
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#define BOOTARCHIVE64_FAILSAFE "/boot/amd64/x86.miniroot-safe"
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#define FAILSAFE_BOOTFILE32 "/boot/platform/i86pc/kernel/unix"
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore#define FAILSAFE_BOOTFILE64 "/boot/platform/i86pc/kernel/amd64/unix"
193974072f41a843678abf5f61979c748687e66bSherry Moorestatic uint_t fastboot_vatoindex(fastboot_info_t *, uintptr_t, int);
193974072f41a843678abf5f61979c748687e66bSherry Moorestatic void fastboot_map_with_size(fastboot_info_t *, uintptr_t,
193974072f41a843678abf5f61979c748687e66bSherry Moorestatic void fastboot_build_pagetables(fastboot_info_t *);
193974072f41a843678abf5f61979c748687e66bSherry Moorestatic int fastboot_build_mbi(char *, fastboot_info_t *);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorestatic void fastboot_free_file(fastboot_file_t *);
a2491ff449494db9d1f602890eee6caa157e7f81Sherry Moorestatic const char fastboot_enomem_msg[] = "!Fastboot: Couldn't allocate 0x%"
193974072f41a843678abf5f61979c748687e66bSherry Moore * Return the index corresponding to a virt address at a given page table level.
193974072f41a843678abf5f61979c748687e66bSherry Moorefastboot_vatoindex(fastboot_info_t *nk, uintptr_t va, int level)
193974072f41a843678abf5f61979c748687e66bSherry Moore return ((va >> nk->fi_shift_amt[level]) & (nk->fi_ptes_per_table - 1));
193974072f41a843678abf5f61979c748687e66bSherry Moore * Add mapping from vstart to pstart for the specified size.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * vstart, pstart and size should all have been aligned at 2M boundaries.
193974072f41a843678abf5f61979c748687e66bSherry Moorefastboot_map_with_size(fastboot_info_t *nk, uintptr_t vstart, paddr_t pstart,
193974072f41a843678abf5f61979c748687e66bSherry Moore * Last level. Program the page table entries.
193974072f41a843678abf5f61979c748687e66bSherry Moore uint_t index = fastboot_vatoindex(nk, vaddr, l);
193974072f41a843678abf5f61979c748687e66bSherry Moore ((uintptr_t)(((paddr_t)table[index] & MMU_PAGEMASK)
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * Intermediate levels.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * Program with either valid bit or PTP bits.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev table[index] = nk->fi_next_table_pa | ptp_bits;
193974072f41a843678abf5f61979c748687e66bSherry Moore table[index] = nk->fi_next_table_pa | PT_VALID;
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev#endif /* __amd64 */
193974072f41a843678abf5f61979c748687e66bSherry Moore table[index] = nk->fi_next_table_pa | ptp_bits;
193974072f41a843678abf5f61979c748687e66bSherry Moore * Build page tables for the lower 1G of physical memory using 2M
193974072f41a843678abf5f61979c748687e66bSherry Moore * pages, and prepare page tables for mapping new kernel and boot
193974072f41a843678abf5f61979c748687e66bSherry Moore * archive pages using 4K pages.
193974072f41a843678abf5f61979c748687e66bSherry Moore * Map lower 1G physical memory. Use large pages.
193974072f41a843678abf5f61979c748687e66bSherry Moore * Map one 4K page to get the middle page tables set up.
193974072f41a843678abf5f61979c748687e66bSherry Moore fake_va = P2ALIGN_TYPED(fake_va, nk->fi_lpagesize, uintptr_t);
193974072f41a843678abf5f61979c748687e66bSherry Moore nk->fi_files[0].fb_pte_list_va[0] & MMU_PAGEMASK, PAGESIZE, 0);
193974072f41a843678abf5f61979c748687e66bSherry Moore * Sanity check. Look for dboot offset.
193974072f41a843678abf5f61979c748687e66bSherry Moorefastboot_elf64_find_dboot_load_offset(void *img, off_t imgsz, uint32_t *offp)
193974072f41a843678abf5f61979c748687e66bSherry Moore if ((ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize) >= imgsz)
193974072f41a843678abf5f61979c748687e66bSherry Moore return (-1);
193974072f41a843678abf5f61979c748687e66bSherry Moore phdr = (Elf64_Phdr *)(phdrbase + ehdr->e_phentsize * i);
193974072f41a843678abf5f61979c748687e66bSherry Moore return (-1);
193974072f41a843678abf5f61979c748687e66bSherry Moore * Initialize text and data section information for 32-bit kernel.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * sectcntp - is both input/output parameter.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * On entry, *sectcntp contains maximum allowable number of sections;
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * on return, it contains the actual number of sections filled.
193974072f41a843678abf5f61979c748687e66bSherry Moorefastboot_elf32_find_loadables(void *img, off_t imgsz, fastboot_section_t *sectp,
193974072f41a843678abf5f61979c748687e66bSherry Moore if ((ehdr->e_phoff + ehdr->e_phnum * ehdr->e_phentsize) >= imgsz)
193974072f41a843678abf5f61979c748687e66bSherry Moore return (-1);
193974072f41a843678abf5f61979c748687e66bSherry Moore phdr = (Elf32_Phdr *)(phdrbase + ehdr->e_phentsize * i);
193974072f41a843678abf5f61979c748687e66bSherry Moore return (-1);
193974072f41a843678abf5f61979c748687e66bSherry Moore sectp[used_sections].fb_sec_offset = phdr->p_offset;
193974072f41a843678abf5f61979c748687e66bSherry Moore sectp[used_sections].fb_sec_paddr = phdr->p_paddr;
193974072f41a843678abf5f61979c748687e66bSherry Moore sectp[used_sections].fb_sec_size = phdr->p_filesz;
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev /* Extra sanity check for the input object file */
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Create multiboot info structure (mbi) base on the saved mbi.
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Recalculate values of the pointer type fields in the data
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * structure based on the new starting physical address of the
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * data structure.
193974072f41a843678abf5f61979c748687e66bSherry Moorefastboot_build_mbi(char *mdep, fastboot_info_t *nk)
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev multiboot_info_t *mbi; /* pointer to multiboot structure */
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev uintptr_t start_addr_va; /* starting VA of mbi */
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev uintptr_t start_addr_pa; /* starting PA of mbi */
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev size_t offs = 0; /* offset from the starting address */
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev size_t arglen; /* length of the command line arg */
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev size_t size; /* size of the memory reserved for mbi */
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev size_t mdnsz; /* length of the boot archive name */
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * If mdep is not NULL or empty, use the length of mdep + 1
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * (for NULL terminating) as the length of the new command
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * line; else use the saved command line length as the
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * length for the new command line.
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Allocate memory for the new multiboot info structure (mbi).
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * If we have reserved memory for mbi but it's not enough,
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * free it and reallocate.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (nk->fi_mbi_size && nk->fi_mbi_size < size) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore contig_free((void *)nk->fi_new_mbi_va, nk->fi_mbi_size);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (uintptr_t)contig_alloc(size, &fastboot_below_1G_dma_attr,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (-1);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fi_mbi_size must be set after the allocation succeeds
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * as it's used to determine how much memory to free.
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Initalize memory
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore bzero((void *)nk->fi_new_mbi_va, nk->fi_mbi_size);
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Get PA for the new mbi
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev start_addr_pa = mmu_ptob((uint64_t)hat_getpfnum(kas.a_hat,
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev nk->fi_new_mbi_pa = (paddr_t)start_addr_pa;
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Populate the rest of the fields in the data structure
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Copy from the saved mbi to preserve all non-pointer type fields.
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Recalculate mods_addr. Set mod_start and mod_end based on
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * the physical address of the new boot archive. Set mod_name
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * to the name of the new boto archive.
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev mbp = (mb_module_t *)(start_addr_va + offs);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore mbp->mod_start = nk->fi_files[FASTBOOT_BOOTARCHIVE].fb_dest_pa;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore mbp->mod_end = nk->fi_files[FASTBOOT_BOOTARCHIVE].fb_next_pa;
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev mdnsz = strlen(fastboot_filename[FASTBOOT_NAME_BOOTARCHIVE]) + 1;
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev bcopy(fastboot_filename[FASTBOOT_NAME_BOOTARCHIVE],
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Make sure the offset is 16-byte aligned to avoid unaligned access.
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev offs = P2ROUNDUP_TYPED(offs, 16, size_t);
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Recalculate mmap_addr
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev bcopy((void *)(uintptr_t)saved_mmap, (void *)(start_addr_va + offs),
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Recalculate drives_addr
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev bcopy((void *)(uintptr_t)saved_drives, (void *)(start_addr_va + offs),
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * Recalculate the address of cmdline. Set cmdline to contain the
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev * new boot argument.
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev bcopy(mdep, (void *)(start_addr_va + offs), arglen);
1a6f4459015a5e6c608d53b5942bd44755933cd5Konstantin Ananyev bcopy((void *)saved_cmdline, (void *)(start_addr_va + offs),
6915124bb75bc67ae012532a3a7727adc043a7cbKonstantin Ananyev /* clear fields and flags that are not copied */
6915124bb75bc67ae012532a3a7727adc043a7cbKonstantin Ananyev sizeof (*mbi) - offsetof(multiboot_info_t, config_table));
6915124bb75bc67ae012532a3a7727adc043a7cbKonstantin Ananyev mbi->flags &= ~(MB_INFO_CONFIG_TABLE | MB_INFO_BOOT_LOADER_NAME |
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * Initialize HAT related fields
7417cfdecea1902cef03c0d61a72df97d945925dKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_PAE)) {
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev#endif /* __amd64 */
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * Process boot argument
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moorefastboot_parse_mdep(char *mdep, char *kern_bootpath, int *bootpath_len,
193974072f41a843678abf5f61979c748687e66bSherry Moore * If mdep is not NULL, it comes in the format of
193974072f41a843678abf5f61979c748687e66bSherry Moore * mountpoint unix args
193974072f41a843678abf5f61979c748687e66bSherry Moore /* First get the root argument */
193974072f41a843678abf5f61979c748687e66bSherry Moore if (i < 4 || strncmp(&mdep[i-4], "unix", 4) != 0) {
193974072f41a843678abf5f61979c748687e66bSherry Moore /* mount point */
193974072f41a843678abf5f61979c748687e66bSherry Moore * Get the next argument. It should be unix as
193974072f41a843678abf5f61979c748687e66bSherry Moore * we have validated in in halt.c.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Reserve memory under PA 1G for mapping the new kernel and boot archive.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * This function is only called if fastreboot_onpanic is *not* set.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * A valid kernel is in place. No need to reserve any memory.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Reserve memory under PA 1G for PTE lists.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < FASTBOOT_MAX_FILES_MAP; i++) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore fsize_roundup = P2ROUNDUP_TYPED(saved_file_size[i],
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore &fastboot_below_1G_dma_attr, PAGESIZE, 0)) == NULL) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Reserve memory under PA 1G for page tables.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore (uintptr_t)contig_alloc(fastboot_pagetable_size,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore &fastboot_below_1G_dma_attr, PAGESIZE, 0)) == NULL) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore nk->fi_pagetable_size = fastboot_pagetable_size;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Reserve memory under PA 1G for multiboot structure.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if ((nk->fi_new_mbi_va = (uintptr_t)contig_alloc(fastboot_mbi_size,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore &fastboot_below_1G_dma_attr, PAGESIZE, 0)) == NULL) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Calculate MD5 digest for the given fastboot_file.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Assumes that the file is allready loaded properly.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorefastboot_cksum_file(fastboot_file_t *fb, uchar_t *md5_hash)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore MD5Update(&md5_ctx, (void *)fb->fb_va, fb->fb_size);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Free up the memory we have allocated for a file
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore fsize_roundup = P2ROUNDUP_TYPED(fb->fb_size, PAGESIZE, size_t);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Free up memory used by the PTEs for a file.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorefastboot_free_file_pte(fastboot_file_t *fb, uint64_t endaddr)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (fb->fb_pte_list_size && fb->fb_pte_list_pa < endaddr) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore contig_free((void *)fb->fb_pte_list_va, fb->fb_pte_list_size);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Free up all the memory used for representing a kernel with
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fastboot_info_t.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorefastboot_free_mem(fastboot_info_t *nk, uint64_t endaddr)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < FASTBOOT_MAX_FILES_MAP; i++) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore fastboot_free_file_pte(nk->fi_files + i, endaddr);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (nk->fi_pagetable_size && nk->fi_pagetable_pa < endaddr) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore contig_free((void *)nk->fi_pagetable_va, nk->fi_pagetable_size);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (nk->fi_mbi_size && nk->fi_new_mbi_pa < endaddr) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore contig_free((void *)nk->fi_new_mbi_va, nk->fi_mbi_size);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Only free up the memory allocated for the kernel and boot archive,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * but not for the page tables.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Free the memory we have allocated
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < FASTBOOT_MAX_FILES_MAP; i++) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorefastboot_cksum_cdata(fastboot_info_t *nk, uchar_t *md5_hash)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < FASTBOOT_MAX_FILES_MAP; i++) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore MD5Update(&md5_ctx, nk->fi_files[i].fb_pte_list_va,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore MD5Update(&md5_ctx, (void *)nk->fi_pagetable_va, nk->fi_pagetable_size);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore MD5Update(&md5_ctx, (void *)nk->fi_new_mbi_va, nk->fi_mbi_size);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Generate MD5 checksum of the given kernel.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < FASTBOOT_MAX_FILES_MAP; i++) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore fastboot_cksum_file(nk->fi_files + i, nk->fi_md5_hash[i]);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Calculate MD5 checksum of the given kernel and verify that
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * it matches with what was calculated before.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < FASTBOOT_MAX_FILES_MAP; i++) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore fastboot_cksum_file(nk->fi_files + i, md5_hash);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (i + 1);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore return (i + 1);
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * This function performs the following tasks:
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * - Read the sizes of the new kernel and boot archive.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * - Allocate memory for the new kernel and boot archive.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * - Allocate memory for page tables necessary for mapping the memory
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * allocated for the files.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * - Read the new kernel and boot archive into memory.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * - Map in the fast reboot switcher.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * - Load the fast reboot switcher to FASTBOOT_SWTCH_PA.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * - Build the new multiboot_info structure
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * - Build page tables for the low 1G of physical memory.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * - Mark the data structure as valid if all steps have succeeded.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * Initialize various HAT related fields in the data structure
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * Process the boot argument
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore fastboot_parse_mdep(mdep, kern_bootpath, &bootpath_len, fastboot_args);
193974072f41a843678abf5f61979c748687e66bSherry Moore * Make sure we get the null character
193974072f41a843678abf5f61979c748687e66bSherry Moore bcopy(kern_bootpath, fastboot_filename[FASTBOOT_NAME_UNIX],
193974072f41a843678abf5f61979c748687e66bSherry Moore &fastboot_filename[FASTBOOT_NAME_UNIX][bootpath_len],
193974072f41a843678abf5f61979c748687e66bSherry Moore bcopy(kern_bootpath, fastboot_filename[FASTBOOT_NAME_BOOTARCHIVE],
193974072f41a843678abf5f61979c748687e66bSherry Moore * Read in unix and boot_archive
193974072f41a843678abf5f61979c748687e66bSherry Moore for (i = 0; i < FASTBOOT_MAX_FILES_MAP; i++) {
193974072f41a843678abf5f61979c748687e66bSherry Moore if ((file = kobj_open_file(fastboot_filename[i])) ==
a2491ff449494db9d1f602890eee6caa157e7f81Sherry Moore cmn_err(CE_NOTE, "!Fastboot: Couldn't open %s",
a2491ff449494db9d1f602890eee6caa157e7f81Sherry Moore "!Fastboot: Couldn't get filesize for %s",
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore fsize_roundup = P2ROUNDUP_TYPED(fsize, PAGESIZE, size_t);
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * Where the files end in physical memory after being
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * relocated by the fast boot switcher.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore if (end_addr > fastboot_below_1G_dma_attr.dma_attr_addr_hi) {
a2491ff449494db9d1f602890eee6caa157e7f81Sherry Moore cmn_err(CE_NOTE, "!Fastboot: boot archive is too big");
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * Adjust dma_attr_addr_lo so that the new kernel and boot
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * archive will not be overridden during relocation.
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore if (end_addr > fastboot_dma_attr.dma_attr_addr_lo ||
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore end_addr > fastboot_below_1G_dma_attr.dma_attr_addr_lo) {
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * If we have already tried and didn't succeed,
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * just give up.
a2491ff449494db9d1f602890eee6caa157e7f81Sherry Moore "!Fastboot: boot archive is too big");
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore /* Set the flag so we don't keep retrying */
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore /* Adjust dma_attr_addr_lo */
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * Free the memory we have already allocated
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * whose physical addresses might not fit
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * the new lo and hi constraints.
193974072f41a843678abf5f61979c748687e66bSherry Moore dma_attr.dma_attr_sgllen = (fsize / PAGESIZE) +
193974072f41a843678abf5f61979c748687e66bSherry Moore if ((buf = contig_alloc(fsize, &dma_attr, PAGESIZE, 0))
a2491ff449494db9d1f602890eee6caa157e7f81Sherry Moore cmn_err(CE_NOTE, fastboot_enomem_msg, fsize, "64G");
193974072f41a843678abf5f61979c748687e66bSherry Moore va = P2ROUNDUP_TYPED((uintptr_t)buf, PAGESIZE, uintptr_t);
193974072f41a843678abf5f61979c748687e66bSherry Moore if (kobj_read_file(file, (char *)va, fsize, 0) < 0) {
a2491ff449494db9d1f602890eee6caa157e7f81Sherry Moore cmn_err(CE_NOTE, "!Fastboot: Couldn't read %s",
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore pt_size = FASTBOOT_PTE_LIST_SIZE(fsize_roundup);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If we have reserved memory but it not enough, free it.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (fb->fb_pte_list_size && fb->fb_pte_list_size < pt_size) {
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fb_pte_list_size must be set after the allocation
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * succeeds as it's used to determine how much memory to
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore bzero((void *)(fb->fb_pte_list_va), fb->fb_pte_list_size);
193974072f41a843678abf5f61979c748687e66bSherry Moore fb->fb_pte_list_pa = mmu_ptob((uint64_t)hat_getpfnum(kas.a_hat,
193974072f41a843678abf5f61979c748687e66bSherry Moore for (page_index = 0, offset = 0; offset < fb->fb_size;
193974072f41a843678abf5f61979c748687e66bSherry Moore paddr = mmu_ptob((uint64_t)hat_getpfnum(kas.a_hat,
193974072f41a843678abf5f61979c748687e66bSherry Moore ASSERT(paddr >= fastboot_dma_attr.dma_attr_addr_lo);
193974072f41a843678abf5f61979c748687e66bSherry Moore * Include the pte_bits so we don't have to make
193974072f41a843678abf5f61979c748687e66bSherry Moore * it in assembly.
193974072f41a843678abf5f61979c748687e66bSherry Moore fb->fb_pte_list_va[page_index] = FASTBOOT_TERMINATE;
193974072f41a843678abf5f61979c748687e66bSherry Moore * Sanity checks:
193974072f41a843678abf5f61979c748687e66bSherry Moore for (j = 0; j < SELFMAG; j++) {
193974072f41a843678abf5f61979c748687e66bSherry Moore "signature");
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev fb->fb_sectcnt = sizeof (fb->fb_sections) /
193974072f41a843678abf5f61979c748687e66bSherry Moore "program section failure");
193974072f41a843678abf5f61979c748687e66bSherry Moore "program sections found");
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Failsafe boot_archive */
193974072f41a843678abf5f61979c748687e66bSherry Moore } else if (ehdr->e_ident[EI_CLASS] == ELFCLASS64 &&
193974072f41a843678abf5f61979c748687e66bSherry Moore "find ELF64 dboot entry offset");
193974072f41a843678abf5f61979c748687e66bSherry Moore "reboot to %s: "
193974072f41a843678abf5f61979c748687e66bSherry Moore "not a 64-bit capable system",
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* Failsafe boot_archive */
a2491ff449494db9d1f602890eee6caa157e7f81Sherry Moore cmn_err(CE_NOTE, "!Fastboot: Unknown ELF type");
193974072f41a843678abf5f61979c748687e66bSherry Moore fb->fb_next_pa = DBOOT_ENTRY_ADDRESS + fsize_roundup;
193974072f41a843678abf5f61979c748687e66bSherry Moore fb->fb_dest_pa = newkernel.fi_files[i - 1].fb_next_pa;
193974072f41a843678abf5f61979c748687e66bSherry Moore fb->fb_next_pa = fb->fb_dest_pa + fsize_roundup;
193974072f41a843678abf5f61979c748687e66bSherry Moore * Add the function that will switch us to 32-bit protected mode
193974072f41a843678abf5f61979c748687e66bSherry Moore fb->fb_va = fb->fb_dest_pa = FASTBOOT_SWTCH_PA;
193974072f41a843678abf5f61979c748687e66bSherry Moore * Build the new multiboot_info structure
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (fastboot_build_mbi(fastboot_args, &newkernel) != 0) {
193974072f41a843678abf5f61979c748687e66bSherry Moore * Build page table for low 1G physical memory. Use big pages.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * Allocate 4 (5 for amd64) pages for the page tables.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * 1 page for PML4 (amd64)
193974072f41a843678abf5f61979c748687e66bSherry Moore * 1 page for Page-Directory-Pointer Table
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev * 2 pages for Page Directory
193974072f41a843678abf5f61979c748687e66bSherry Moore * 1 page for Page Table.
193974072f41a843678abf5f61979c748687e66bSherry Moore * The page table entry will be rewritten to map the physical
193974072f41a843678abf5f61979c748687e66bSherry Moore * address as we do the copying.
877400d375b54199aef7c18828cb32f991339ff7Konstantin Ananyev#endif /* __amd64 */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (newkernel.fi_pagetable_size && newkernel.fi_pagetable_size
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore contig_alloc(size, &fastboot_below_1G_dma_attr,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fi_pagetable_size must be set after the allocation
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * succeeds as it's used to determine how much memory to
193974072f41a843678abf5f61979c748687e66bSherry Moore bzero((void *)(newkernel.fi_pagetable_va), size);
193974072f41a843678abf5f61979c748687e66bSherry Moore newkernel.fi_last_table_pa = newkernel.fi_pagetable_pa +
193974072f41a843678abf5f61979c748687e66bSherry Moore newkernel.fi_next_table_va = newkernel.fi_pagetable_va +
193974072f41a843678abf5f61979c748687e66bSherry Moore newkernel.fi_next_table_pa = newkernel.fi_pagetable_pa +
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /* Generate MD5 checksums */
193974072f41a843678abf5f61979c748687e66bSherry Moore /* Mark it as valid */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore/* ARGSUSED */
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moorefastboot_xc_func(fastboot_info_t *nk, xc_arg_t unused2, xc_arg_t unused3)
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore fastboot_file_t *fb = &nk->fi_files[FASTBOOT_SWTCH];
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore hat_devload(curproc->p_as->a_hat, (caddr_t)fb->fb_va,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If we have pinned a thread, make sure the address is mapped
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * in the address space of the pinned thread.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (t_intr && t_intr->t_procp->p_as->a_hat != curproc->p_as->a_hat &&
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore hat_devload(t_intr->t_procp->p_as->a_hat, (caddr_t)fb->fb_va,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore /*NOTREACHED*/
6bc8bc6a97518e9ec3d440de43fc1a30a7db825fSherry Moore * Jump to the fast reboot switcher. This function never returns.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Map the address into both the current proc's address
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * space and the kernel's address space in case the panic
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * is forced by kmdb.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore hat_devload(curproc->p_as->a_hat, (caddr_t)fb->fb_va,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore bcopy((void *)fb_swtch_image, (void *)fb->fb_va, fb->fb_size);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Set fb_va to fake_va
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore for (i = 0; i < FASTBOOT_MAX_FILES_MAP; i++) {
f34a71784df3fbc5d1227a7b6201fd318ad1667eJoe Bonasera extern void panic_idle(void);
f34a71784df3fbc5d1227a7b6201fd318ad1667eJoe Bonasera xc_priority((xc_arg_t)&newkernel, 0, 0, CPUSET2BV(cpuset),
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Get boot property value for fastreboot_onpanic.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * NOTE: If fastreboot_onpanic is set to non-zero in /etc/system,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * new setting passed in via "-B fastreboot_onpanic" is ignored.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * This order of precedence is to enable developers debugging panics
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * that occur early in boot to utilize Fast Reboot on panic.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore ret = ddi_prop_lookup_string(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Only set fastreboot_onpanic to the value passed in
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * if it's not already set to non-zero, and the value
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * has indeed been passed in via command line.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore } else if (ret != DDI_PROP_NOT_FOUND && ret != DDI_PROP_UNDEFINED) {
a2491ff449494db9d1f602890eee6caa157e7f81Sherry Moore cmn_err(CE_NOTE, "!%s value is invalid, will be ignored",
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore ret = ddi_getlongprop_buf(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore FASTREBOOT_ONPANIC_CMDLINE, fastreboot_onpanic_cmdline, &len);
a2491ff449494db9d1f602890eee6caa157e7f81Sherry Moore cmn_err(CE_NOTE, "!%s value is too long, will be ignored",
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * This function is called by main() to either load the backup kernel for panic
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * fast reboot, or to reserve low physical memory for fast reboot.
835b9930bd7bb9c7d0ed6d788e7314ffd3f3177dSherry Moore /* Default to 10 minutes */
835b9930bd7bb9c7d0ed6d788e7314ffd3f3177dSherry Moore fastreboot_onpanic_uptime = SEC_TO_TICK(10 * 60);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore fastboot_load_kernel(fastreboot_onpanic_cmdline);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * Update boot configuration settings.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * If the new fastreboot_onpanic setting is false, and a kernel has
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * been preloaded, free the memory;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * if the new fastreboot_onpanic setting is true and newkernel is
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore * not valid, load the new kernel.
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore fastreboot_onpanic = boot_config & UA_FASTREBOOT_ONPANIC;
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (fastreboot_onpanic && (!cur_fastreboot_onpanic ||
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore fastboot_load_kernel(fastreboot_onpanic_cmdline);
753a6d457b330b1b29b2d3eefcd0831116ce950dSherry Moore if (cur_fastreboot_onpanic && !fastreboot_onpanic)
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * This is an internal interface to disable Fast Reboot on Panic.
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * It frees up memory allocated for the backup kernel and sets
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * fastreboot_onpanic to zero.
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore uint8_t boot_config = (uint8_t)(~UA_FASTREBOOT_ONPANIC);
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore fastboot_update_config((const char *)&boot_config);
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore * This is the interface to be called by fm_panic() in case FMA has diagnosed
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore * a terminal machine check exception. It does not free up memory allocated
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore * for the backup kernel. General disabling fastreboot_onpanic in a
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * non-panicking situation must go through fastboot_onpanic_disable().
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * This is an internal interface to disable Fast Reboot by Default.
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * It does not free up memory allocated for the backup kernel.
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyevfastreboot_capable_disable(uint32_t msgid)
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev if (msgid < sizeof (fastreboot_nosup_desc) /
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * This is the kernel interface for disabling
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * Fast Reboot by Default and Fast Reboot on Panic.
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * Frees up memory allocated for the backup kernel.
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * General disabling of the Fast Reboot by Default feature should be done
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * via the userland interface scf_fastreboot_default_set_transient().
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * Returns Fast Reboot not support message for fastreboot_nosup_id.
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * If fastreboot_nosup_id contains invalid index, default
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev * Fast Reboot not support message is returned.
5ee8e422dc45ae866a24584daa90397099b2f01bKonstantin Ananyev if (msgid >= sizeof (fastreboot_nosup_desc) /
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore * A simplified interface for uadmin to call to update the configuration
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore * setting and load a new kernel if necessary.
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore * If user has explicitly requested reboot to prom,
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore * or uadmin(1M) was invoked with other functions,
c90a5fbe436d54a1d69dbcf41c7f1cc7b2834a18Sherry Moore * don't try to fast reboot after dumping.