summaryrefslogtreecommitdiffstats
path: root/drivers/firmware/efi/libstub/smbios.c
blob: 460418b7f5f5e9ab1d721ec096eaa77bb2462c58 (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
// SPDX-License-Identifier: GPL-2.0-only
// Copyright 2022 Google LLC
// Author: Ard Biesheuvel <ardb@google.com>

#include <linux/efi.h>

#include "efistub.h"

typedef struct efi_smbios_protocol efi_smbios_protocol_t;

struct efi_smbios_protocol {
	efi_status_t (__efiapi *add)(efi_smbios_protocol_t *, efi_handle_t,
				     u16 *, struct efi_smbios_record *);
	efi_status_t (__efiapi *update_string)(efi_smbios_protocol_t *, u16 *,
					       unsigned long *, u8 *);
	efi_status_t (__efiapi *remove)(efi_smbios_protocol_t *, u16);
	efi_status_t (__efiapi *get_next)(efi_smbios_protocol_t *, u16 *, u8 *,
					  struct efi_smbios_record **,
					  efi_handle_t *);

	u8 major_version;
	u8 minor_version;
};

const u8 *__efi_get_smbios_string(u8 type, int offset, int recsize)
{
	struct efi_smbios_record *record;
	efi_smbios_protocol_t *smbios;
	efi_status_t status;
	u16 handle = 0xfffe;
	const u8 *strtable;

	status = efi_bs_call(locate_protocol, &EFI_SMBIOS_PROTOCOL_GUID, NULL,
			     (void **)&smbios) ?:
		 efi_call_proto(smbios, get_next, &handle, &type, &record, NULL);
	if (status != EFI_SUCCESS)
		return NULL;

	strtable = (u8 *)record + recsize;
	for (int i = 1; i < ((u8 *)record)[offset]; i++) {
		int len = strlen(strtable);

		if (!len)
			return NULL;
		strtable += len + 1;
	}
	return strtable;
}