1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 1987-2000 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/types.h> 30*0Sstevel@tonic-gate #include <sys/cpr.h> 31*0Sstevel@tonic-gate #include <sys/pte.h> 32*0Sstevel@tonic-gate #include <sys/promimpl.h> 33*0Sstevel@tonic-gate #include <sys/prom_plat.h> 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate extern int cpr_ufs_close(int); 36*0Sstevel@tonic-gate extern int cpr_ufs_open(char *, char *); 37*0Sstevel@tonic-gate extern int cpr_ufs_read(int, char *, int); 38*0Sstevel@tonic-gate extern int cpr_read(int, char *, size_t); 39*0Sstevel@tonic-gate extern void prom_unmap(caddr_t, uint_t); 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate extern int cpr_debug; 42*0Sstevel@tonic-gate static int cpr_show_props = 0; 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate /* 46*0Sstevel@tonic-gate * Read the config file and pass back the file path, filesystem 47*0Sstevel@tonic-gate * device path. 48*0Sstevel@tonic-gate */ 49*0Sstevel@tonic-gate int 50*0Sstevel@tonic-gate cpr_read_cprinfo(int fd, char *file_path, char *fs_path) 51*0Sstevel@tonic-gate { 52*0Sstevel@tonic-gate struct cprconfig cf; 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate if (cpr_ufs_read(fd, (char *)&cf, sizeof (cf)) != sizeof (cf) || 55*0Sstevel@tonic-gate cf.cf_magic != CPR_CONFIG_MAGIC) 56*0Sstevel@tonic-gate return (-1); 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate (void) prom_strcpy(file_path, cf.cf_path); 59*0Sstevel@tonic-gate (void) prom_strcpy(fs_path, cf.cf_dev_prom); 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate return (0); 62*0Sstevel@tonic-gate } 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate /* 66*0Sstevel@tonic-gate * Read the location of the state file from the root filesystem. 67*0Sstevel@tonic-gate * Pass back to the caller the full device path of the filesystem 68*0Sstevel@tonic-gate * and the filename relative to that fs. 69*0Sstevel@tonic-gate */ 70*0Sstevel@tonic-gate int 71*0Sstevel@tonic-gate cpr_locate_statefile(char *file_path, char *fs_path) 72*0Sstevel@tonic-gate { 73*0Sstevel@tonic-gate int fd; 74*0Sstevel@tonic-gate char *boot_path = prom_bootpath(); 75*0Sstevel@tonic-gate int rc; 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate if ((fd = cpr_ufs_open(CPR_CONFIG, boot_path)) != -1) { 78*0Sstevel@tonic-gate rc = cpr_read_cprinfo(fd, file_path, fs_path); 79*0Sstevel@tonic-gate (void) cpr_ufs_close(fd); 80*0Sstevel@tonic-gate } else 81*0Sstevel@tonic-gate rc = -1; 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate return (rc); 84*0Sstevel@tonic-gate } 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate /* 88*0Sstevel@tonic-gate * Open the "defaults" file in the root fs and read the values of the 89*0Sstevel@tonic-gate * properties saved during the checkpoint. Restore the values to nvram. 90*0Sstevel@tonic-gate * 91*0Sstevel@tonic-gate * Note: an invalid magic number in the "defaults" file means that the 92*0Sstevel@tonic-gate * state file is bad or obsolete so our caller should not proceed with 93*0Sstevel@tonic-gate * the resume. 94*0Sstevel@tonic-gate */ 95*0Sstevel@tonic-gate int 96*0Sstevel@tonic-gate cpr_reset_properties(void) 97*0Sstevel@tonic-gate { 98*0Sstevel@tonic-gate char *str, *boot_path, *default_path; 99*0Sstevel@tonic-gate int fd, len, rc, prop_errors; 100*0Sstevel@tonic-gate cprop_t *prop, *tail; 101*0Sstevel@tonic-gate cdef_t cdef; 102*0Sstevel@tonic-gate dnode_t node; 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate str = "cpr_reset_properties"; 105*0Sstevel@tonic-gate default_path = CPR_DEFAULT; 106*0Sstevel@tonic-gate boot_path = prom_bootpath(); 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate if ((fd = cpr_ufs_open(default_path, boot_path)) == -1) { 109*0Sstevel@tonic-gate prom_printf("%s: unable to open %s on %s\n", 110*0Sstevel@tonic-gate str, default_path, boot_path); 111*0Sstevel@tonic-gate return (-1); 112*0Sstevel@tonic-gate } 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate rc = 0; 115*0Sstevel@tonic-gate len = cpr_ufs_read(fd, (char *)&cdef, sizeof (cdef)); 116*0Sstevel@tonic-gate if (len != sizeof (cdef)) { 117*0Sstevel@tonic-gate prom_printf("%s: error reading %s\n", str, default_path); 118*0Sstevel@tonic-gate rc = -1; 119*0Sstevel@tonic-gate } else if (cdef.mini.magic != CPR_DEFAULT_MAGIC) { 120*0Sstevel@tonic-gate prom_printf("%s: bad magic number in %s\n", str, default_path); 121*0Sstevel@tonic-gate rc = -1; 122*0Sstevel@tonic-gate } 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate (void) cpr_ufs_close(fd); 125*0Sstevel@tonic-gate if (rc) 126*0Sstevel@tonic-gate return (rc); 127*0Sstevel@tonic-gate 128*0Sstevel@tonic-gate node = prom_optionsnode(); 129*0Sstevel@tonic-gate if (node == OBP_NONODE || node == OBP_BADNODE) { 130*0Sstevel@tonic-gate prom_printf("%s: cannot find \"options\" node\n"); 131*0Sstevel@tonic-gate return (-1); 132*0Sstevel@tonic-gate } 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate /* 135*0Sstevel@tonic-gate * reset nvram to the original property values 136*0Sstevel@tonic-gate */ 137*0Sstevel@tonic-gate if (cpr_show_props) 138*0Sstevel@tonic-gate prom_printf("\n\ncpr_show_props:\n"); 139*0Sstevel@tonic-gate for (prop_errors = 0, prop = cdef.props, tail = prop + CPR_MAXPROP; 140*0Sstevel@tonic-gate prop < tail; prop++) { 141*0Sstevel@tonic-gate if (cpr_show_props) { 142*0Sstevel@tonic-gate prom_printf("mod=%c, name=\"%s\",\tvalue=\"%s\"\n", 143*0Sstevel@tonic-gate prop->mod, prop->name, prop->value); 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate if (prop->mod != PROP_MOD) 146*0Sstevel@tonic-gate continue; 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate len = prom_strlen(prop->value); 149*0Sstevel@tonic-gate if (prom_setprop(node, prop->name, prop->value, len + 1) < 0 || 150*0Sstevel@tonic-gate prom_getproplen(node, prop->name) != len) { 151*0Sstevel@tonic-gate prom_printf("%s: error setting \"%s\" to \"%s\"\n", 152*0Sstevel@tonic-gate str, prop->name, prop->value); 153*0Sstevel@tonic-gate prop_errors++; 154*0Sstevel@tonic-gate } 155*0Sstevel@tonic-gate } 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate return (prop_errors ? -1 : 0); 158*0Sstevel@tonic-gate } 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate 161*0Sstevel@tonic-gate /* 162*0Sstevel@tonic-gate * Read and verify cpr dump descriptor 163*0Sstevel@tonic-gate */ 164*0Sstevel@tonic-gate int 165*0Sstevel@tonic-gate cpr_read_cdump(int fd, cdd_t *cdp, ushort_t mach_type) 166*0Sstevel@tonic-gate { 167*0Sstevel@tonic-gate char *str; 168*0Sstevel@tonic-gate int nread; 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate str = "\ncpr_read_cdump:"; 171*0Sstevel@tonic-gate nread = cpr_read(fd, (caddr_t)cdp, sizeof (*cdp)); 172*0Sstevel@tonic-gate if (nread != sizeof (*cdp)) { 173*0Sstevel@tonic-gate prom_printf("%s Error reading cpr dump descriptor\n", str); 174*0Sstevel@tonic-gate return (-1); 175*0Sstevel@tonic-gate } 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate if (cdp->cdd_magic != CPR_DUMP_MAGIC) { 178*0Sstevel@tonic-gate prom_printf("%s bad dump magic 0x%x, expected 0x%x\n", 179*0Sstevel@tonic-gate str, cdp->cdd_magic, CPR_DUMP_MAGIC); 180*0Sstevel@tonic-gate return (-1); 181*0Sstevel@tonic-gate } 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate if (cdp->cdd_version != CPR_VERSION) { 184*0Sstevel@tonic-gate prom_printf("%s bad cpr version %d, expected %d\n", 185*0Sstevel@tonic-gate str, cdp->cdd_version, CPR_VERSION); 186*0Sstevel@tonic-gate return (-1); 187*0Sstevel@tonic-gate } 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate if (cdp->cdd_machine != mach_type) { 190*0Sstevel@tonic-gate prom_printf("%s bad machine type 0x%x, expected 0x%x\n", 191*0Sstevel@tonic-gate str, cdp->cdd_machine, mach_type); 192*0Sstevel@tonic-gate return (-1); 193*0Sstevel@tonic-gate } 194*0Sstevel@tonic-gate 195*0Sstevel@tonic-gate if (cdp->cdd_bitmaprec <= 0) { 196*0Sstevel@tonic-gate prom_printf("%s bad bitmap %d\n", str, cdp->cdd_bitmaprec); 197*0Sstevel@tonic-gate return (-1); 198*0Sstevel@tonic-gate } 199*0Sstevel@tonic-gate 200*0Sstevel@tonic-gate if (cdp->cdd_dumppgsize <= 0) { 201*0Sstevel@tonic-gate prom_printf("%s Bad pg tot %d\n", str, cdp->cdd_dumppgsize); 202*0Sstevel@tonic-gate return (-1); 203*0Sstevel@tonic-gate } 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate cpr_debug = cdp->cdd_debug; 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate return (0); 208*0Sstevel@tonic-gate } 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate /* 212*0Sstevel@tonic-gate * update cpr dump terminator 213*0Sstevel@tonic-gate */ 214*0Sstevel@tonic-gate void 215*0Sstevel@tonic-gate cpr_update_terminator(ctrm_t *file_term, caddr_t mapva) 216*0Sstevel@tonic-gate { 217*0Sstevel@tonic-gate ctrm_t *mem_term; 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate /* 220*0Sstevel@tonic-gate * Add the offset to reach the terminator in the kernel so that we 221*0Sstevel@tonic-gate * can directly change the restored kernel image. 222*0Sstevel@tonic-gate */ 223*0Sstevel@tonic-gate mem_term = (ctrm_t *)(mapva + (file_term->va & MMU_PAGEOFFSET)); 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gate mem_term->real_statef_size = file_term->real_statef_size; 226*0Sstevel@tonic-gate mem_term->tm_shutdown = file_term->tm_shutdown; 227*0Sstevel@tonic-gate mem_term->tm_cprboot_start.tv_sec = file_term->tm_cprboot_start.tv_sec; 228*0Sstevel@tonic-gate mem_term->tm_cprboot_end.tv_sec = prom_gettime() / 1000; 229*0Sstevel@tonic-gate } 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate /* 233*0Sstevel@tonic-gate * simple bcopy for cprboot 234*0Sstevel@tonic-gate */ 235*0Sstevel@tonic-gate void 236*0Sstevel@tonic-gate bcopy(const void *s, void *d, size_t count) 237*0Sstevel@tonic-gate { 238*0Sstevel@tonic-gate const char *src = s; 239*0Sstevel@tonic-gate char *dst = d; 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate while (count--) 242*0Sstevel@tonic-gate *dst++ = *src++; 243*0Sstevel@tonic-gate } 244