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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _X86PI_IMPL_H
28 #define	_X86PI_IMPL_H
29 
30 /*
31  * i86pc Generic Enumerator private interfaces
32  */
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #include <smbios.h>
39 #include <ctype.h>
40 
41 
42 /*
43  * Table showing the relationship between hc-canonical names and the
44  * SMBIOS tables/values.
45  *
46  * **************************************************************************
47  * | hc-name             | SMB Table | Offset - Name            | Value     |
48  * --------------------------------------------------------------------------
49  * --------------------------------------------------------------------------
50  * | "motherboard"       | Type 2    | 0x0D - Board Type        | 0x0A      |
51  * --------------------------------------------------------------------------
52  * | "cpuboard"          | Type 2    | 0x0D - Board Type        | 0x06      |
53  * --------------------------------------------------------------------------
54  * | "memboard"          | Type 2    | 0x0D - Board Type        | 0x08      |
55  * --------------------------------------------------------------------------
56  * | "ioboard"           | Type 2    | 0x0D - Board Type        | 0x07      |
57  * --------------------------------------------------------------------------
58  * | "systemboard"       | Type 2    | 0x0D - Board Type        | 0x03,0x09,|
59  * |                     |           |                          | 0x0B,0x0C |
60  * --------------------------------------------------------------------------
61  * | "bay"               | Type 136  |                                      |
62  * --------------------------------------------------------------------------
63  * | "hostbridge"        | Type 138  |                                      |
64  * --------------------------------------------------------------------------
65  * | "pciexrc"           | Type 138  |                                      |
66  * **************************************************************************
67  */
68 
69 
70 /* Definitions used when registering the enumerator with libtopo */
71 #define	X86PI_DESC	"i86pc Generic Topology Enumerator"
72 #define	X86PI_SCHEME	"hc"
73 #define	X86PI_VERSION	TOPO_VERSION
74 
75 /*
76  * Solaris FMA Compliance level for SMBIOS.
77  * The same X86PI_* definitions are used in chip.h
78  * please keep them in sync
79  */
80 #define	X86PI_FULL	1
81 #define	X86PI_NONE	2
82 
83 /* used in traversing contained bboards */
84 #define	X86PI_VISITED	1
85 
86 #define	LABEL		1
87 
88 /* Flags used by x86pi_enum_generic */
89 #define	X86PI_ENUM_FRU	0x0001	/* Indicates a FRU */
90 
91 /* max allowed contained count */
92 #define	SMB_MAX_ID	0x40
93 
94 /* indication of successful fac node creation */
95 int fac_done;
96 
97 /*
98  * Count and smbios struct id(s) for each smbios struct type.
99  */
100 typedef struct smbs_con_ids {
101 	id_t id;			/* smbios struct id */
102 	id_t con_cnt;			/* containee count */
103 	id_t con_ids[SMB_MAX_ID];	/* containee ids */
104 	id_t con_by_id;			/* container id */
105 	int visited;			/* visit flag */
106 	tnode_t *node;
107 } smbs_con_ids_t;
108 
109 typedef struct smbs_cnt {
110 	int type;		/* SMBIOS stucture type */
111 	int count;		/* number of table entries */
112 	smbs_con_ids_t ids[SMB_MAX_ID]; /* SMBIOS table entry id(s) */
113 } smbs_cnt_t;
114 
115 smbs_cnt_t stypes[SMB_TYPE_OEM_HI]; /* one for each struct */
116 
117 /*
118  * The enumerator needs to pass some state in to the function that walks
119  * the PRI graph.  This structure contains the necessary information.
120  */
121 struct x86pi_enum_s {
122 	topo_mod_t	*mod;		/* Topo module handle */
123 	tnode_t		*t_parent;	/* "Chassis" parent */
124 	uint32_t	force;		/* force legacy */
125 	void		*priv;		/* Private data */
126 };
127 typedef struct x86pi_enum_s x86pi_enum_t;
128 
129 /*
130  * x86gentopo hcfmri info structure.
131  *
132  * Available unformed SMBIOS strings:
133  *  smbi_manufacturer
134  *  smbi_product
135  *  smbi_version
136  *  smbi_serial
137  *  smbi_asset
138  *  smbi_location
139  *  smbi_part
140  *
141  */
142 struct x86pi_hcfmri_info_s {
143 	int		instance;
144 	int		rev;
145 
146 	const char	*hc_name;
147 	const char	*manufacturer;
148 	const char	*product;
149 	const char	*version;
150 	const char	*serial_number;
151 	const char	*asset_tag;
152 	const char	*location;
153 	const char	*part_number;
154 };
155 typedef struct x86pi_hcfmri_info_s x86pi_hcfmri_t;
156 
157 /*
158  * Prototypes
159  */
160 
161 /* SMBIOS */
162 smbios_hdl_t *x86pi_smb_open(topo_mod_t *);
163 void x86pi_smb_strcnt(smbios_hdl_t *, smbs_cnt_t *);
164 int x86pi_check_comp(topo_mod_t *, smbios_hdl_t *);
165 
166 /* Node generation */
167 tnode_t *x86pi_gen_chassis(topo_mod_t *, tnode_t *, smbios_hdl_t *, int, int);
168 tnode_t *x86pi_gen_bboard(topo_mod_t *, tnode_t *, smbios_hdl_t *, int, int,
169     int);
170 int x86pi_gen_cmp(topo_mod_t *, tnode_t *, smbios_hdl_t *, int, int, int);
171 int x86pi_gen_core(topo_mod_t *, tnode_t *, int, int, int);
172 int x86pi_gen_strand(topo_mod_t *, tnode_t *, int, int, int);
173 int x86pi_gen_memarray(topo_mod_t *, tnode_t *, smbios_hdl_t *, int, int);
174 void x86pi_gen_memdev(topo_mod_t *, tnode_t *, smbios_hdl_t *, int, int, int);
175 int x86pi_gen_hbr(topo_mod_t *, tnode_t *, smbios_hdl_t *, int,
176     topo_instance_t, topo_instance_t *);
177 int x86pi_gen_bay(topo_mod_t *, tnode_t *, smbios_hdl_t *, smbios_port_ext_t *,
178     int);
179 
180 /* support routines */
181 int x86pi_enum_generic(topo_mod_t *, x86pi_hcfmri_t *, tnode_t *, tnode_t *,
182     tnode_t **, int);
183 tnode_t *x86pi_node_bind(topo_mod_t *, tnode_t *, x86pi_hcfmri_t *, nvlist_t *,
184     int);
185 void x86pi_hcfmri_info_fini(topo_mod_t *, x86pi_hcfmri_t *);
186 uint16_t x86pi_bdf(topo_mod_t *, di_node_t);
187 int x86pi_phy(topo_mod_t *, di_node_t);
188 
189 /* get/set info */
190 char *x86pi_get_serverid(topo_mod_t *);
191 int x86pi_set_frufmri(topo_mod_t *, x86pi_hcfmri_t *, tnode_t *, tnode_t *,
192     int);
193 int x86pi_set_label(topo_mod_t *, const char *, const char *, tnode_t *);
194 int x86pi_set_auth(topo_mod_t *, x86pi_hcfmri_t *, tnode_t *, tnode_t *);
195 int x86pi_set_system(topo_mod_t *, tnode_t *);
196 
197 /* hostbridge */
198 int x86pi_hbr_enum_init(topo_mod_t *);
199 void x86pi_hbr_enum_fini(topo_mod_t *);
200 
201 /* base board */
202 id_t x86pi_bb_topparent(smbios_hdl_t *, int, tnode_t **, id_t *);
203 int x86pi_bb_contains(topo_mod_t *, smbios_hdl_t *);
204 int x86pi_bb_getchips(topo_mod_t *, smbios_hdl_t *, int, int);
205 
206 const char *x86pi_cleanup_smbios_str(topo_mod_t *, const char *, int);
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif /* _X86PI_IMPL_H */
213