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