summaryrefslogtreecommitdiff
path: root/src/drivers/ocp/dmi/smbios.c
blob: 4e54af0b2a3e0e77c4a4c681c9b4f65faee22194 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* SPDX-License-Identifier: GPL-2.0-or-later */

#include <console/console.h>
#include <device/device.h>
#include <drivers/ipmi/ipmi_ops.h>
#include <delay.h>
#include <cpu/x86/mp.h>
#include <timer.h>
#include <stdio.h>
#include <string.h>
#include <soc/soc_util.h>
#include <soc/cpu.h>
#include <smbios.h>

#include "ocp_dmi.h"

#define PPIN_STR_LEN 17

struct fru_info_str fru_strings = {0};
/* The spec defines only at most 2 sockets */
msr_t xeon_sp_ppin[2] = {0};
static bool remote_ppin_done = false;

/* Override SMBIOS type 1 data. */
const char *smbios_system_manufacturer(void)
{
	if (fru_strings.prod_info.manufacturer != NULL)
		return (const char *)fru_strings.prod_info.manufacturer;
	else
		return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
}

const char *smbios_system_product_name(void)
{
	if (fru_strings.board_info.product_name != NULL)
		return (const char *)fru_strings.prod_info.product_name;
	else
		return CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME;
}

const char *smbios_system_serial_number(void)
{
	if (fru_strings.prod_info.serial_number != NULL)
		return (const char *)fru_strings.prod_info.serial_number;
	else
		return CONFIG_MAINBOARD_SERIAL_NUMBER;
}

const char *smbios_system_version(void)
{
	if (fru_strings.prod_info.product_version != NULL)
		return (const char *)fru_strings.prod_info.product_version;
	else
		return CONFIG_MAINBOARD_VERSION;
}

/* Override SMBIOS type 1 uuid from the value from BMC. */
void smbios_system_set_uuid(u8 *uuid)
{
	ipmi_get_system_guid(CONFIG_BMC_KCS_BASE, uuid);
}

/* Override SMBIOS type 2 data. */
const char *smbios_mainboard_version(void)
{
	if (fru_strings.board_info.part_number != NULL)
		return (const char *)fru_strings.board_info.part_number;
	else
		return CONFIG_MAINBOARD_VERSION;
}

const char *smbios_mainboard_manufacturer(void)
{
	if (fru_strings.board_info.manufacturer != NULL)
		return (const char *)fru_strings.board_info.manufacturer;
	else
		return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
}

const char *smbios_mainboard_product_name(void)
{
	if (fru_strings.board_info.product_name != NULL)
		return (const char *)fru_strings.board_info.product_name;
	else
		return CONFIG_MAINBOARD_SMBIOS_PRODUCT_NAME;
}

const char *smbios_mainboard_serial_number(void)
{
	if (fru_strings.board_info.serial_number != NULL)
		return (const char *)fru_strings.board_info.serial_number;
	else
		return CONFIG_MAINBOARD_SERIAL_NUMBER;
}

/* Override SMBIOS type 2 and 3 asset_tag data. */
const char *smbios_mainboard_asset_tag(void)
{
	if (fru_strings.prod_info.asset_tag != NULL)
		return (const char *)fru_strings.prod_info.asset_tag;
	else
		return "";
}

/* Override SMBIOS type 3 data. */
smbios_enclosure_type smbios_mainboard_enclosure_type(void)
{
	/* SMBIOS System Enclosure or Chassis Types are values from 0 to 20h. */
	if (fru_strings.chassis_info.chassis_type <= 0x20)
		return fru_strings.chassis_info.chassis_type;
	else
		return SMBIOS_ENCLOSURE_RACK_MOUNT_CHASSIS;
}

const char *smbios_chassis_version(void)
{
	if (fru_strings.chassis_info.chassis_partnumber != NULL)
		return fru_strings.chassis_info.chassis_partnumber;
	else
		return "";
}

const char *smbios_chassis_serial_number(void)
{
	if (fru_strings.chassis_info.serial_number != NULL)
		return fru_strings.chassis_info.serial_number;
	else
		return "";
}

/* Override SMBIOS type 4 processor serial numbers from FRU Chassis custom data. */
const char *smbios_processor_serial_number(void)
{
	/* For now type 4 only creates for one CPU, so it can only write the serial number
	 * of CPU0.
	 */
	if (*fru_strings.chassis_info.chassis_custom != NULL)
		return *fru_strings.chassis_info.chassis_custom;
	else
		return "";
}

static void read_remote_ppin(void *data)
{
	*(msr_t *)data = read_msr_ppin();
	remote_ppin_done = true;
}

static void wait_for_remote_ppin(void)
{
	struct stopwatch sw;

	stopwatch_init_msecs_expire(&sw, 500);
	while (!stopwatch_expired(&sw)) {
		if (remote_ppin_done)
			break;
		mdelay(100);
	}
	if (stopwatch_expired(&sw))
		printk(BIOS_ERR, "Wait for read_remote_ppin() timeout\n");
}

int smbios_add_oem_string(u8 *start, const char *str)
{
	int i = 1;
	char *p = (char *)start;

	if (*str == '\0')
		return 0;

	for (;;) {
		if (!*p) {
			strcpy(p, str);
			p += strlen(str);
			*p++ = '\0';
			*p++ = '\0';
			return i;
		}

		p += strlen(p)+1;
		i++;
	}
}

/* When the most significant 4 bits of PPIN hi/lo are 0, add '0' to the beginning */
static void ppin_string_fixup(int i, char *ppin)
{
	if ((xeon_sp_ppin[i].hi & 0xf0000000) == 0) {
		if ((xeon_sp_ppin[i].lo & 0xf0000000) == 0)
			snprintf(ppin, PPIN_STR_LEN, "0%x0%x", xeon_sp_ppin[i].hi,
				xeon_sp_ppin[i].lo);
		else
			snprintf(ppin, PPIN_STR_LEN, "0%x%x", xeon_sp_ppin[i].hi,
				xeon_sp_ppin[i].lo);
	} else if ((xeon_sp_ppin[i].lo & 0xf0000000) == 0) {
		snprintf(ppin, PPIN_STR_LEN, "%x0%x", xeon_sp_ppin[i].hi, xeon_sp_ppin[i].lo);
	} else {
		snprintf(ppin, PPIN_STR_LEN, "%x%x", xeon_sp_ppin[i].hi, xeon_sp_ppin[i].lo);
	}
}

/*
 * Override SMBIOS type 11 OEM string 1 to string 6, the rest are project dependent
 * and can be added in the mainboard code.
 */
void ocp_oem_smbios_strings(struct device *dev, struct smbios_type11 *t)
{
	char ppin[PPIN_STR_LEN];

	/* Add OEM string 1 to 4 */
	if (fru_strings.board_info.custom_count > 0 &&
			*fru_strings.board_info.board_custom != NULL)
		t->count = smbios_add_oem_string(t->eos, *fru_strings.board_info.board_custom);
	else
		t->count = smbios_add_oem_string(t->eos, TBF);

	if (fru_strings.prod_info.custom_count > 0 &&
			*fru_strings.prod_info.product_custom != NULL)
		t->count = smbios_add_oem_string(t->eos, *fru_strings.prod_info.product_custom);
	else
		t->count = smbios_add_oem_string(t->eos, TBF);

	if (fru_strings.prod_info.custom_count > 1 &&
			*(fru_strings.prod_info.product_custom + 1) != NULL)
		t->count = smbios_add_oem_string(t->eos,
			*(fru_strings.prod_info.product_custom + 1));
	else
		t->count = smbios_add_oem_string(t->eos, TBF);

	if (fru_strings.prod_info.custom_count > 2 &&
			*(fru_strings.prod_info.product_custom + 2) != NULL) {
		t->count = smbios_add_oem_string(t->eos,
			*(fru_strings.prod_info.product_custom + 2));
	} else {
		t->count = smbios_add_oem_string(t->eos, TBF);
	}

	/* Add CPU0 PPIN to OEM string 5 */
	xeon_sp_ppin[0] = read_msr_ppin();
	ppin_string_fixup(0, ppin);
	t->count = smbios_add_oem_string(t->eos, ppin);

	/* Add CPU1 PPIN to OEM string 6 */
	if (CONFIG_MAX_SOCKET == 2 && CONFIG(PARALLEL_MP_AP_WORK)) {
		/* Read the last CPU MSR */
		if (mp_run_on_aps(read_remote_ppin, (void *)&xeon_sp_ppin[1],
				get_platform_thread_count() - 1, 100 * USECS_PER_MSEC)) {
			printk(BIOS_ERR, "Failed to read remote PPIN.\n");
			t->count = smbios_add_oem_string(t->eos, TBF);
		} else {
			/* Wait for read_remote_ppin() to finish because it's executed
			   in parallel */
			wait_for_remote_ppin();
			ppin_string_fixup(1, ppin);
			t->count = smbios_add_oem_string(t->eos, ppin);
		}
	} else {
		t->count = smbios_add_oem_string(t->eos, "0000");
	}
}