1*437Smws /* 2*437Smws * CDDL HEADER START 3*437Smws * 4*437Smws * The contents of this file are subject to the terms of the 5*437Smws * Common Development and Distribution License, Version 1.0 only 6*437Smws * (the "License"). You may not use this file except in compliance 7*437Smws * with the License. 8*437Smws * 9*437Smws * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*437Smws * or http://www.opensolaris.org/os/licensing. 11*437Smws * See the License for the specific language governing permissions 12*437Smws * and limitations under the License. 13*437Smws * 14*437Smws * When distributing Covered Code, include this CDDL HEADER in each 15*437Smws * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*437Smws * If applicable, add the following below this CDDL HEADER, with the 17*437Smws * fields enclosed by brackets "[]" replaced with your own identifying 18*437Smws * information: Portions Copyright [yyyy] [name of copyright owner] 19*437Smws * 20*437Smws * CDDL HEADER END 21*437Smws */ 22*437Smws 23*437Smws /* 24*437Smws * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 25*437Smws * Use is subject to license terms. 26*437Smws */ 27*437Smws 28*437Smws #pragma ident "%Z%%M% %I% %E% SMI" 29*437Smws 30*437Smws /* 31*437Smws * Platform-Specific SMBIOS Subroutines 32*437Smws * 33*437Smws * The routines in this file form part of <sys/smbios_impl.h> and combine with 34*437Smws * the usr/src/common/smbios code to form an in-kernel SMBIOS decoding service. 35*437Smws * The SMBIOS entry point is locating by scanning a range of physical memory 36*437Smws * assigned to BIOS as described in Section 2 of the DMTF SMBIOS specification. 37*437Smws */ 38*437Smws 39*437Smws #include <sys/smbios_impl.h> 40*437Smws #include <sys/sysmacros.h> 41*437Smws #include <sys/errno.h> 42*437Smws #include <sys/psm.h> 43*437Smws #include <sys/smp_impldefs.h> 44*437Smws 45*437Smws smbios_hdl_t *ksmbios; 46*437Smws int ksmbios_flags; 47*437Smws 48*437Smws smbios_hdl_t * 49*437Smws smb_open_error(smbios_hdl_t *shp, int *errp, int err) 50*437Smws { 51*437Smws if (shp != NULL) 52*437Smws smbios_close(shp); 53*437Smws 54*437Smws if (errp != NULL) 55*437Smws *errp = err; 56*437Smws 57*437Smws if (ksmbios == NULL) 58*437Smws cmn_err(CE_CONT, "?SMBIOS not loaded (%s)", smbios_errmsg(err)); 59*437Smws 60*437Smws return (NULL); 61*437Smws } 62*437Smws 63*437Smws smbios_hdl_t * 64*437Smws smbios_open(const char *file, int version, int flags, int *errp) 65*437Smws { 66*437Smws smbios_hdl_t *shp = NULL; 67*437Smws smbios_entry_t ep; 68*437Smws caddr_t stbuf, bios, p, q; 69*437Smws size_t bioslen; 70*437Smws int err; 71*437Smws 72*437Smws if (file != NULL || (flags & ~SMB_O_MASK)) 73*437Smws return (smb_open_error(shp, errp, ESMB_INVAL)); 74*437Smws 75*437Smws bioslen = SMB_RANGE_LIMIT - SMB_RANGE_START + 1; 76*437Smws bios = psm_map_phys(SMB_RANGE_START, bioslen, PSM_PROT_READ); 77*437Smws 78*437Smws if (bios == NULL) 79*437Smws return (smb_open_error(shp, errp, ESMB_MAPDEV)); 80*437Smws 81*437Smws for (p = bios, q = bios + bioslen; p < q; p += 16) { 82*437Smws if (strncmp(p, SMB_ENTRY_EANCHOR, SMB_ENTRY_EANCHORLEN) == 0) 83*437Smws break; 84*437Smws } 85*437Smws 86*437Smws if (p >= q) { 87*437Smws psm_unmap_phys(bios, bioslen); 88*437Smws return (smb_open_error(shp, errp, ESMB_NOTFOUND)); 89*437Smws } 90*437Smws 91*437Smws bcopy(p, &ep, sizeof (smbios_entry_t)); 92*437Smws psm_unmap_phys(bios, bioslen); 93*437Smws bios = psm_map_phys(ep.smbe_staddr, ep.smbe_stlen, PSM_PROT_READ); 94*437Smws 95*437Smws if (bios == NULL) 96*437Smws return (smb_open_error(shp, errp, ESMB_MAPDEV)); 97*437Smws 98*437Smws stbuf = smb_alloc(ep.smbe_stlen); 99*437Smws bcopy(bios, stbuf, ep.smbe_stlen); 100*437Smws psm_unmap_phys(bios, ep.smbe_stlen); 101*437Smws shp = smbios_bufopen(&ep, stbuf, ep.smbe_stlen, version, flags, &err); 102*437Smws 103*437Smws if (shp == NULL) { 104*437Smws smb_free(stbuf, ep.smbe_stlen); 105*437Smws return (smb_open_error(shp, errp, err)); 106*437Smws } 107*437Smws 108*437Smws if (ksmbios == NULL) { 109*437Smws cmn_err(CE_CONT, "?SMBIOS v%u.%u loaded (%u bytes)", 110*437Smws ep.smbe_major, ep.smbe_minor, ep.smbe_stlen); 111*437Smws } 112*437Smws 113*437Smws shp->sh_flags |= SMB_FL_BUFALLOC; 114*437Smws return (shp); 115*437Smws } 116*437Smws 117*437Smws /*ARGSUSED*/ 118*437Smws smbios_hdl_t * 119*437Smws smbios_fdopen(int fd, int version, int flags, int *errp) 120*437Smws { 121*437Smws return (smb_open_error(NULL, errp, ENOTSUP)); 122*437Smws } 123*437Smws 124*437Smws /*ARGSUSED*/ 125*437Smws int 126*437Smws smbios_write(smbios_hdl_t *shp, int fd) 127*437Smws { 128*437Smws return (smb_set_errno(shp, ENOTSUP)); 129*437Smws } 130