summaryrefslogtreecommitdiff
path: root/DynamicTablesPkg/Include/Library/SmbiosStringTableLib.h
blob: b10a4aef6c027ee15f887b86a3fb353b15867cad (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
/** @file
  SMBIOS String Table Helper library.

  Copyright (c) 2022, Arm Limited. All rights reserved.<BR>
  SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#pragma once

/** A structure representing a string in the string table.
*/
typedef struct StringElement {
  /// Length of the string (does not include the NULL termination)
  UINTN          StringLen;

  /// Reference to the string
  CONST CHAR8    *String;
} STRING_ELEMENT;

/** A structure representing a string table.
*/
typedef struct StringTable {
  /// Count of strings in the table
  UINT8             StrCount;

  /// Total length of all strings in the table (does not include
  // the NULL termination for each string)
  UINTN             TotalStrLen;

  /// Maximum string count
  UINT8             MaxStringElements;

  /// Pointer to the string table elements
  STRING_ELEMENT    *Elements;
} STRING_TABLE;

/** Add a string to the string table

  @param[in]   StrTable  Pointer to the string table
  @param[in]   Str       Pointer to the string
  @param[out]  StrRef    Optional pointer to retrieve the string field
                         reference of the string in the string table

  @return EFI_SUCCESS            Success
  @return EFI_INVALID_PARAMETER  Invalid string table pointer
  @return EFI_BUFFER_TOO_SMALL   Insufficient space to add string
**/
EFI_STATUS
EFIAPI
StringTableAddString (
  IN        STRING_TABLE *CONST  StrTable,
  IN  CONST CHAR8                *Str,
  OUT       UINT8                *StrRef      OPTIONAL
  );

/** Returns the total size required to publish the strings to the SMBIOS
    string area.

  @param[in] StrTable              Pointer to the string table

  @return Total size required to publish the strings in the SMBIOS string area.
**/
UINTN
EFIAPI
StringTableGetStringSetSize (
  IN  STRING_TABLE *CONST  StrTable
  );

/** Iterate through the string table and publish the strings in the SMBIOS
    string area.

  @param[in] StrTable              Pointer to the string table
  @param[in] SmbiosStringAreaStart Start address of the SMBIOS string area.
  @param[in] SmbiosStringAreaSize  Size of the SMBIOS string area.

  @return EFI_SUCCESS            Success
  @return EFI_INVALID_PARAMETER  Invalid string table pointer
  @return EFI_BUFFER_TOO_SMALL   Insufficient space to publish strings
**/
EFI_STATUS
EFIAPI
StringTablePublishStringSet (
  IN        STRING_TABLE  *CONST  StrTable,
  IN        CHAR8         *CONST  SmbiosStringAreaStart,
  IN  CONST UINTN                 SmbiosStringAreaSize
  );

/** Initialise the string table and allocate memory for the string elements.

  @param[in] StrTable           Pointer to the string table
  @param[in] MaxStringElements  Maximum number of strings that the string
                                 table can hold.

  @return EFI_SUCCESS            Success
  @return EFI_INVALID_PARAMETER  Invalid string table pointer
  @return EFI_OUT_OF_RESOURCES   Failed to allocate memory for string elements
**/
EFI_STATUS
EFIAPI
StringTableInitialize (
  IN STRING_TABLE *CONST  StrTable,
  IN UINTN                MaxStringElements
  );

/** Free memory allocated for the string elements in the string table.

  @param[in] StrTable           Pointer to the string table

  @return EFI_SUCCESS            Success
  @return EFI_INVALID_PARAMETER  Invalid string table pointer or string elements
**/
EFI_STATUS
EFIAPI
StringTableFree (
  IN STRING_TABLE *CONST  StrTable
  );

/** Allocate a zeroed buffer for a SMBIOS record, including the string area.

  Per SMBIOS Specification Section 6.1.3, if the structure has no strings the
  formatted section is followed by two null (00h) bytes.  If strings are
  present each string is null-terminated and the set is terminated by an
  additional null byte.  This function encapsulates that rule so callers do
  not need to account for the terminator explicitly.

  @param[in]  StructSize  Size of the fixed-size part of the SMBIOS structure.
  @param[in]  StrTable    Optional pointer to a populated string table.
                          If NULL, the allocation includes only the two-byte
                          double-NULL terminator.
                          If non-NULL, the allocation includes the full string
                          area as returned by StringTableGetStringSetSize().

  @return  Pointer to the allocated SMBIOS record buffer, or NULL on failure.
**/
VOID *
EFIAPI
AllocateSmbiosRecord (
  IN        UINTN   StructSize,
  IN  STRING_TABLE  *StrTable    OPTIONAL
  );