1*753a6d45SSherry Moore /* 2*753a6d45SSherry Moore * CDDL HEADER START 3*753a6d45SSherry Moore * 4*753a6d45SSherry Moore * The contents of this file are subject to the terms of the 5*753a6d45SSherry Moore * Common Development and Distribution License (the "License"). 6*753a6d45SSherry Moore * You may not use this file except in compliance with the License. 7*753a6d45SSherry Moore * 8*753a6d45SSherry Moore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*753a6d45SSherry Moore * or http://www.opensolaris.org/os/licensing. 10*753a6d45SSherry Moore * See the License for the specific language governing permissions 11*753a6d45SSherry Moore * and limitations under the License. 12*753a6d45SSherry Moore * 13*753a6d45SSherry Moore * When distributing Covered Code, include this CDDL HEADER in each 14*753a6d45SSherry Moore * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*753a6d45SSherry Moore * If applicable, add the following below this CDDL HEADER, with the 16*753a6d45SSherry Moore * fields enclosed by brackets "[]" replaced with your own identifying 17*753a6d45SSherry Moore * information: Portions Copyright [yyyy] [name of copyright owner] 18*753a6d45SSherry Moore * 19*753a6d45SSherry Moore * CDDL HEADER END 20*753a6d45SSherry Moore */ 21*753a6d45SSherry Moore 22*753a6d45SSherry Moore /* 23*753a6d45SSherry Moore * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24*753a6d45SSherry Moore * Use is subject to license terms. 25*753a6d45SSherry Moore */ 26*753a6d45SSherry Moore 27*753a6d45SSherry Moore /* 28*753a6d45SSherry Moore * This file contains high level functions used by multiple utilities. 29*753a6d45SSherry Moore */ 30*753a6d45SSherry Moore 31*753a6d45SSherry Moore #include "libscf_impl.h" 32*753a6d45SSherry Moore 33*753a6d45SSherry Moore #include <assert.h> 34*753a6d45SSherry Moore #include <libuutil.h> 35*753a6d45SSherry Moore #include <string.h> 36*753a6d45SSherry Moore #include <stdlib.h> 37*753a6d45SSherry Moore #include <sys/systeminfo.h> 38*753a6d45SSherry Moore #include <sys/uadmin.h> 39*753a6d45SSherry Moore #include <sys/utsname.h> 40*753a6d45SSherry Moore 41*753a6d45SSherry Moore #ifdef __x86 42*753a6d45SSherry Moore #include <smbios.h> 43*753a6d45SSherry Moore 44*753a6d45SSherry Moore /* 45*753a6d45SSherry Moore * Check whether the platform is on the fastreboot_blacklist. 46*753a6d45SSherry Moore * Return 1 if the platform has been blacklisted, 0 otherwise. 47*753a6d45SSherry Moore */ 48*753a6d45SSherry Moore static int 49*753a6d45SSherry Moore scf_is_fb_blacklisted(void) 50*753a6d45SSherry Moore { 51*753a6d45SSherry Moore smbios_hdl_t *shp; 52*753a6d45SSherry Moore smbios_system_t sys; 53*753a6d45SSherry Moore smbios_info_t info; 54*753a6d45SSherry Moore 55*753a6d45SSherry Moore id_t id; 56*753a6d45SSherry Moore int err; 57*753a6d45SSherry Moore int i; 58*753a6d45SSherry Moore 59*753a6d45SSherry Moore scf_simple_prop_t *prop = NULL; 60*753a6d45SSherry Moore ssize_t numvals; 61*753a6d45SSherry Moore char *platform_name; 62*753a6d45SSherry Moore 63*753a6d45SSherry Moore int blacklisted = 0; 64*753a6d45SSherry Moore 65*753a6d45SSherry Moore /* 66*753a6d45SSherry Moore * If there's no SMBIOS, assume it's blacklisted. 67*753a6d45SSherry Moore */ 68*753a6d45SSherry Moore if ((shp = smbios_open(NULL, SMB_VERSION, 0, &err)) == NULL) 69*753a6d45SSherry Moore return (1); 70*753a6d45SSherry Moore 71*753a6d45SSherry Moore /* 72*753a6d45SSherry Moore * If we can't read system info, assume it's blacklisted. 73*753a6d45SSherry Moore */ 74*753a6d45SSherry Moore if ((id = smbios_info_system(shp, &sys)) == SMB_ERR || 75*753a6d45SSherry Moore smbios_info_common(shp, id, &info) == SMB_ERR) { 76*753a6d45SSherry Moore blacklisted = 1; 77*753a6d45SSherry Moore goto fb_out; 78*753a6d45SSherry Moore } 79*753a6d45SSherry Moore 80*753a6d45SSherry Moore /* 81*753a6d45SSherry Moore * If we can't read the "platforms" property from property group 82*753a6d45SSherry Moore * BOOT_CONFIG_PG_FBBLACKLIST, assume no platforms have 83*753a6d45SSherry Moore * been blacklisted. 84*753a6d45SSherry Moore */ 85*753a6d45SSherry Moore if ((prop = scf_simple_prop_get(NULL, FMRI_BOOT_CONFIG, 86*753a6d45SSherry Moore BOOT_CONFIG_PG_FBBLACKLIST, "platforms")) == NULL) 87*753a6d45SSherry Moore goto fb_out; 88*753a6d45SSherry Moore 89*753a6d45SSherry Moore numvals = scf_simple_prop_numvalues(prop); 90*753a6d45SSherry Moore 91*753a6d45SSherry Moore for (i = 0; i < numvals; i++) { 92*753a6d45SSherry Moore platform_name = scf_simple_prop_next_astring(prop); 93*753a6d45SSherry Moore if (platform_name == NULL) 94*753a6d45SSherry Moore break; 95*753a6d45SSherry Moore if (strcmp(platform_name, info.smbi_product) == 0) { 96*753a6d45SSherry Moore blacklisted = 1; 97*753a6d45SSherry Moore break; 98*753a6d45SSherry Moore } 99*753a6d45SSherry Moore } 100*753a6d45SSherry Moore 101*753a6d45SSherry Moore fb_out: 102*753a6d45SSherry Moore smbios_close(shp); 103*753a6d45SSherry Moore scf_simple_prop_free(prop); 104*753a6d45SSherry Moore 105*753a6d45SSherry Moore return (blacklisted); 106*753a6d45SSherry Moore } 107*753a6d45SSherry Moore #endif /* __x86 */ 108*753a6d45SSherry Moore 109*753a6d45SSherry Moore /* 110*753a6d45SSherry Moore * Get config properties from svc:/system/boot-config:default. 111*753a6d45SSherry Moore * It prints errors with uu_warn(). 112*753a6d45SSherry Moore */ 113*753a6d45SSherry Moore void 114*753a6d45SSherry Moore scf_get_boot_config(uint8_t *boot_config) 115*753a6d45SSherry Moore { 116*753a6d45SSherry Moore assert(boot_config); 117*753a6d45SSherry Moore *boot_config = 0; 118*753a6d45SSherry Moore 119*753a6d45SSherry Moore #ifndef __x86 120*753a6d45SSherry Moore return; 121*753a6d45SSherry Moore #else 122*753a6d45SSherry Moore { 123*753a6d45SSherry Moore /* 124*753a6d45SSherry Moore * Property vector for BOOT_CONFIG_PG_PARAMS property group. 125*753a6d45SSherry Moore */ 126*753a6d45SSherry Moore scf_propvec_t ua_boot_config[] = { 127*753a6d45SSherry Moore { "fastreboot_default", NULL, SCF_TYPE_BOOLEAN, NULL, 128*753a6d45SSherry Moore UA_FASTREBOOT_DEFAULT }, 129*753a6d45SSherry Moore { FASTREBOOT_ONPANIC, NULL, SCF_TYPE_BOOLEAN, NULL, 130*753a6d45SSherry Moore UA_FASTREBOOT_ONPANIC }, 131*753a6d45SSherry Moore { NULL } 132*753a6d45SSherry Moore }; 133*753a6d45SSherry Moore scf_propvec_t *prop; 134*753a6d45SSherry Moore 135*753a6d45SSherry Moore for (prop = ua_boot_config; prop->pv_prop != NULL; prop++) 136*753a6d45SSherry Moore prop->pv_ptr = boot_config; 137*753a6d45SSherry Moore prop = NULL; 138*753a6d45SSherry Moore if (scf_read_propvec(FMRI_BOOT_CONFIG, BOOT_CONFIG_PG_PARAMS, 139*753a6d45SSherry Moore B_TRUE, ua_boot_config, &prop) != SCF_FAILED) { 140*753a6d45SSherry Moore /* 141*753a6d45SSherry Moore * Unset both flags if the platform has been 142*753a6d45SSherry Moore * blacklisted. 143*753a6d45SSherry Moore */ 144*753a6d45SSherry Moore if (scf_is_fb_blacklisted()) 145*753a6d45SSherry Moore *boot_config &= ~(UA_FASTREBOOT_DEFAULT | 146*753a6d45SSherry Moore UA_FASTREBOOT_ONPANIC); 147*753a6d45SSherry Moore return; 148*753a6d45SSherry Moore } 149*753a6d45SSherry Moore #if defined(FASTREBOOT_DEBUG) 150*753a6d45SSherry Moore if (prop != NULL) { 151*753a6d45SSherry Moore (void) uu_warn("Service %s property '%s/%s' " 152*753a6d45SSherry Moore "not found.\n", FMRI_BOOT_CONFIG, 153*753a6d45SSherry Moore BOOT_CONFIG_PG_PARAMS, prop->pv_prop); 154*753a6d45SSherry Moore } else { 155*753a6d45SSherry Moore (void) uu_warn("Unable to read service %s " 156*753a6d45SSherry Moore "property '%s': %s\n", FMRI_BOOT_CONFIG, 157*753a6d45SSherry Moore BOOT_CONFIG_PG_PARAMS, scf_strerror(scf_error())); 158*753a6d45SSherry Moore } 159*753a6d45SSherry Moore #endif /* FASTREBOOT_DEBUG */ 160*753a6d45SSherry Moore } 161*753a6d45SSherry Moore #endif /* __x86 */ 162*753a6d45SSherry Moore } 163*753a6d45SSherry Moore 164*753a6d45SSherry Moore /* 165*753a6d45SSherry Moore * Check whether Fast Reboot is the default operating mode. 166*753a6d45SSherry Moore * Return 0 if 167*753a6d45SSherry Moore * 1. the platform is xVM 168*753a6d45SSherry Moore * or 169*753a6d45SSherry Moore * 2. svc:/system/boot-config:default service doesn't exist, 170*753a6d45SSherry Moore * or 171*753a6d45SSherry Moore * 3. property "fastreboot_default" doesn't exist, 172*753a6d45SSherry Moore * or 173*753a6d45SSherry Moore * 4. value of property "fastreboot_default" is set to 0. 174*753a6d45SSherry Moore * or 175*753a6d45SSherry Moore * 5. the platform has been blacklisted. 176*753a6d45SSherry Moore * Return non-zero otherwise. 177*753a6d45SSherry Moore */ 178*753a6d45SSherry Moore int 179*753a6d45SSherry Moore scf_is_fastboot_default(void) 180*753a6d45SSherry Moore { 181*753a6d45SSherry Moore uint8_t boot_config = 0; 182*753a6d45SSherry Moore char procbuf[SYS_NMLN]; 183*753a6d45SSherry Moore 184*753a6d45SSherry Moore /* 185*753a6d45SSherry Moore * If we are on xVM, do not fast reboot by default. 186*753a6d45SSherry Moore */ 187*753a6d45SSherry Moore if (sysinfo(SI_PLATFORM, procbuf, sizeof (procbuf)) == -1 || 188*753a6d45SSherry Moore strcmp(procbuf, "i86xpv") == 0) 189*753a6d45SSherry Moore return (0); 190*753a6d45SSherry Moore 191*753a6d45SSherry Moore scf_get_boot_config(&boot_config); 192*753a6d45SSherry Moore return (boot_config & UA_FASTREBOOT_DEFAULT); 193*753a6d45SSherry Moore } 194