xref: /illumos-gate/usr/src/common/smbios/mktables.sh (revision 7f3d7c9289dee6488b3cd2848a68c0b8580d750c)
1#!/bin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright 2015 OmniTI Computer Consulting, Inc.  All rights reserved.
25# Copyright (c) 2018, Joyent, Inc.
26# Copyright 2025 Oxide Computer Company
27# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28# Use is subject to license terms.
29#
30
31#
32# The SMBIOS interfaces defined in <sys/smbios.h> include a set of integer-to-
33# string conversion routines for the various constants defined in the SMBIOS
34# spec.  These functions are used by smbios(8) and prtdiag(8) and can be
35# leveraged by other clients as well.  To simplify maintenance of the source
36# base, this shell script automatically generates the source code for all of
37# these functions from the <sys/smbios.h> header file and its comments.  Each
38# set of constants should be given a unique #define prefix, listed in the
39# tables below.  The smbios_*_name() functions return the identifier of the
40# cpp define, and the smbios_*_desc() functions return the text of the comment.
41#
42
43name_funcs='
44SMB_BBFL_	smbios_bboard_flag_name		uint_t
45SMB_BIOSFL_	smbios_bios_flag_name		uint64_t
46SMB_BIOSXB1_	smbios_bios_xb1_name		uint_t
47SMB_BIOSXB2_	smbios_bios_xb2_name		uint_t
48SMB_CAT_	smbios_cache_ctype_name		uint_t
49SMB_CAF_	smbios_cache_flag_name		uint_t
50SMB_EVFL_	smbios_evlog_flag_name		uint_t
51SMB_FWC_	smbios_fwinfo_ch_name		uint_t
52SMB_IPMI_F_	smbios_ipmi_flag_name		uint_t
53SMB_POWERSUP_F_	smbios_powersup_flag_name	uint_t
54SMB_MOMC_	smbios_memdevice_op_capab_name	uint_t
55SMB_MDF_	smbios_memdevice_flag_name	uint_t
56SMB_PRC_	smbios_processor_core_flag_name	uint_t
57SMB_RV_ISA_	smbios_riscv_isa_name		uint64_t
58SMB_RV_PRIV_	smbios_riscv_priv_name		uint_t
59SMB_TYPE_	smbios_type_name		uint_t
60SMB_SLCH1_	smbios_slot_ch1_name		uint_t
61SMB_SLCH2_	smbios_slot_ch2_name		uint_t
62SMB_TPMC_	smbios_tpm_char_name		uint64_t
63'
64
65desc_funcs='
66SMB_BBFL_	smbios_bboard_flag_desc		uint_t
67SMB_BBT_	smbios_bboard_type_desc		uint_t
68SMB_BDC_	smbios_battery_chem_desc	uint_t
69SMB_BIOSFL_	smbios_bios_flag_desc		uint64_t
70SMB_BIOSXB1_	smbios_bios_xb1_desc		uint_t
71SMB_BIOSXB2_	smbios_bios_xb2_desc		uint_t
72SMB_BOOT_	smbios_boot_desc		uint_t
73SMB_CAA_	smbios_cache_assoc_desc		uint_t
74SMB_CAT_	smbios_cache_ctype_desc		uint_t
75SMB_CAE_	smbios_cache_ecc_desc		uint_t
76SMB_CAF_	smbios_cache_flag_desc		uint_t
77SMB_CAL_	smbios_cache_loc_desc		uint_t
78SMB_CAG_	smbios_cache_logical_desc	uint_t
79SMB_CAM_	smbios_cache_mode_desc		uint_t
80SMB_CHST_	smbios_chassis_state_desc	uint_t
81SMB_CHT_	smbios_chassis_type_desc	uint_t
82SMB_CRT_	smbios_chassis_rack_type_desc	uint_t
83SMB_COOLDEV_S_	smbios_cooldev_status_desc	uint_t
84SMB_COOLDEV_T_	smbios_cooldev_type_desc	uint_t
85SMB_EVFL_	smbios_evlog_flag_desc		uint_t
86SMB_EVHF_	smbios_evlog_format_desc	uint_t
87SMB_EVM_	smbios_evlog_method_desc	uint_t
88SMB_FWC_	smbios_fwinfo_ch_desc		uint_t
89SMB_FWI_	smbios_fwinfo_id_desc		uint_t
90SMB_FWS_	smbios_fwinfo_state_desc	uint_t
91SMB_FWV_	smbios_fwinfo_vers_desc		uint_t
92SMB_HWSEC_PS_	smbios_hwsec_desc		uint_t
93SMB_IPMI_F_	smbios_ipmi_flag_desc		uint_t
94SMB_IPMI_T_	smbios_ipmi_type_desc		uint_t
95SMB_IPROBE_L_	smbios_iprobe_loc_desc		uint_t
96SMB_IPROBE_S_	smbios_iprobe_status_desc	uint_t
97SMB_MGMTDEV_AT_	smbios_mgmtdev_atype_desc	uint_t
98SMB_MGMTDEV_DT_	smbios_mgmtdev_dtype_desc	uint_t
99SMB_POWERSUP_F_	smbios_powersup_flag_desc	uint_t
100SMB_POWERSUP_I_	smbios_powersup_input_desc	uint_t
101SMB_POWERSUP_S_	smbios_powersup_status_desc	uint_t
102SMB_POWERSUP_T_	smbios_powersup_type_desc	uint_t
103SMB_MAL_	smbios_memarray_loc_desc	uint_t
104SMB_MAU_	smbios_memarray_use_desc	uint_t
105SMB_MAE_	smbios_memarray_ecc_desc	uint_t
106SMB_MDF_	smbios_memdevice_flag_desc	uint_t
107SMB_MDFF_	smbios_memdevice_form_desc	uint_t
108SMB_MDT_	smbios_memdevice_type_desc	uint_t
109SMB_MDR_	smbios_memdevice_rank_desc	uint_t
110SMB_MTECH_	smbios_memdevice_memtech_desc	uint_t
111SMB_MOMC_	smbios_memdevice_op_capab_desc	uint_t
112SMB_OBT_	smbios_onboard_type_desc	uint_t
113SMB_OBET_	smbios_onboard_ext_type_desc	uint_t
114SMB_PDI_	smbios_pointdev_iface_desc	uint_t
115SMB_PDT_	smbios_pointdev_type_desc	uint_t
116SMB_POC_	smbios_port_conn_desc		uint_t
117SMB_POT_	smbios_port_type_desc		uint_t
118SMB_PRC_	smbios_processor_core_flag_desc	uint_t
119SMB_PRF_	smbios_processor_family_desc	uint_t
120SMB_PROCINFO_T	smbios_processor_info_type_desc	uint_t
121SMB_PRS_	smbios_processor_status_desc	uint_t
122SMB_PRT_	smbios_processor_type_desc	uint_t
123SMB_PRU_	smbios_processor_upgrade_desc	uint_t
124SMB_RV_ISA_	smbios_riscv_isa_desc		uint64_t
125SMB_RV_PRIV_	smbios_riscv_priv_desc		uint_t
126SMB_RV_WIDTH_	smbios_riscv_width_desc		uint_t
127SMB_SLCH1_	smbios_slot_ch1_desc		uint_t
128SMB_SLCH2_	smbios_slot_ch2_desc		uint_t
129SMB_SLHT_	smbios_slot_height_desc		uint_t
130SMB_SLL_	smbios_slot_length_desc		uint_t
131SMB_SLT_	smbios_slot_type_desc		uint_t
132SMB_SLU_	smbios_slot_usage_desc		uint_t
133SMB_SLW_	smbios_slot_width_desc		uint_t
134SMB_STRP_	smbios_strprop_id_desc		uint_t
135SMB_TPMC_	smbios_tpm_char_desc		uint64_t
136SMB_TPROBE_L_	smbios_tprobe_loc_desc		uint_t
137SMB_TPROBE_S_	smbios_tprobe_status_desc	uint_t
138SMB_TYPE_	smbios_type_desc		uint_t
139SMB_VPROBE_L_	smbios_vprobe_loc_desc		uint_t
140SMB_VPROBE_S_	smbios_vprobe_status_desc	uint_t
141SMB_WAKEUP_	smbios_system_wakeup_desc	uint_t
142'
143
144if [ $# -ne 1 ]; then
145	echo "Usage: $0 file.h > file.c" >&2
146	exit 2
147fi
148
149echo "\
150/*\n\
151 * Copyright 2015 OmniTI Computer Consulting, Inc.  All rights reserved.\n\
152 * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.\n\
153 * Use is subject to license terms.\n\
154 */\n\
155\n\
156#include <smbios.h>"
157
158echo "$name_funcs" | while read p name type; do
159	[ -z "$p" ] && continue
160	pattern="^#define[	 ]\(${p}[A-Za-z0-9_]*\)[	 ]*[A-Z0-9]*.*\$"
161	replace='	case \1: return ("\1");'
162
163	echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {"
164	sed -n "s@$pattern@$replace@p" < $1 || exit 1
165	echo "\t}\n\treturn (NULL);\n}"
166done
167
168#
169# Generate the description functions based on the comment next to a #define.
170# The transformations for descriptive comments are slightly more complicated
171# than those used for the identifier->name functions above:
172#
173# (1) strip any [RO] suffix from the comment (a header file convention)
174# (2) replace any " with \" so it is escaped for the final output string
175# (3) replace return (...); with return ("..."); to finish the code
176#
177echo "$desc_funcs" | while read p name type; do
178	[ -z "$p" ] && continue
179	pattern="^#define[	 ]\(${p}[A-Za-z0-9_]*\)[	 ]*.*/\\* \(.*\) \\*/\$"
180	replace='	case \1: return (\2);'
181
182	echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {"
183	sed -n "s@$pattern@$replace@p" < $1 | sed 's/ ([RO]))/)/' | \
184	    sed 's/"/\\"/g' | sed 's/(/("/;s/);$/");/' || exit 1
185	echo "\t}\n\treturn (NULL);\n}"
186done
187
188exit 0
189