2 * libefivar - library for the manipulation of EFI variables
3 * Copyright 2012-2015 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see
17 * <http://www.gnu.org/licenses/>.
29 _format_acpi_adr(char *buf, size_t size, const_efidp dp)
32 o += format(buf, size, o, "AcpiAdr(");
33 o += format_array(buf, size, o, "0x%"PRIx32,
34 typeof(dp->acpi_adr.adr[0]),
36 (efidp_node_size(dp)-4)/sizeof (dp->acpi_adr.adr[0]));
37 o += format(buf, size, o, ")");
40 #define format_acpi_adr(buf, size, off, dp) \
41 _format_acpi_adr(((buf)+(off)), ((size)?((size)-(off)):0), (dp))
45 _format_acpi_dn(char *buf, size_t size, const_efidp dp)
48 const char *hidstr = NULL;
50 const char *uidstr = NULL;
52 const char *cidstr = NULL;
55 if (dp->subtype == EFIDP_ACPI_ADR)
56 return format_acpi_adr(buf, size, off, dp);
58 if (dp->subtype != EFIDP_ACPI_HID_EX && dp->subtype != EFIDP_ACPI_HID) {
59 off += format(buf, size, off, "AcpiPath(%d,", dp->subtype);
60 off += format_hex(buf, size, off, (uint8_t *)dp+4,
61 (efidp_node_size(dp)-4) / 2);
62 off += format(buf, size, off, ")");
66 if (dp->subtype == EFIDP_ACPI_HID_EX) {
67 ssize_t limit = efidp_node_size(dp)
68 - offsetof(efidp_acpi_hid_ex, hidstr);
70 hidstr = dp->acpi_hid_ex.hidstr;
71 hidlen = strnlen(hidstr, limit);
74 uidstr = hidstr + hidlen + 1;
75 uidlen = strnlen(uidstr, limit);
78 cidstr = uidstr + uidlen + 1;
79 cidlen = strnlen(cidstr, limit);
83 switch (dp->acpi_hid.hid) {
84 case EFIDP_ACPI_PCI_ROOT_HID:
85 off += format(buf, size, off, "PciRoot(%s)",
88 case EFIDP_ACPI_PCIE_ROOT_HID:
89 off += format(buf, size, off, "PcieRoot(%s)",
96 switch (dp->acpi_hid.hid) {
97 case EFIDP_ACPI_PCI_ROOT_HID:
98 off += format(buf, size, off, "PciRoot(0x%"PRIx32")",
101 case EFIDP_ACPI_PCIE_ROOT_HID:
102 off += format(buf, size, off, "PcieRoot(0x%"PRIx32")",
105 case EFIDP_ACPI_FLOPPY_HID:
106 off += format(buf, size, off, "Floppy(0x%"PRIx32")",
109 case EFIDP_ACPI_KEYBOARD_HID:
110 off += format(buf, size, off, "Keyboard(0x%"PRIx32")",
113 case EFIDP_ACPI_SERIAL_HID:
114 off += format(buf, size, off, "Serial(0x%"PRIx32")",
118 switch (dp->subtype) {
119 case EFIDP_ACPI_HID_EX:
120 if (!hidstr && !cidstr &&
121 (uidstr || dp->acpi_hid_ex.uid)){
122 off += format(buf, size, off,
123 "AcpiExp(0x%"PRIx32",0x%"PRIx32",",
125 dp->acpi_hid_ex.cid);
127 off += format(buf, size, off, "%s)",
130 off += format(buf, size, off,
135 off += format(buf, size, off, "AcpiEx(");
137 off += format(buf, size, off, "%s,", hidstr);
139 off += format(buf, size, off, "0x%"PRIx32",",
142 off += format(buf, size, off, "%s,", cidstr);
144 off += format(buf, size, off, "0x%"PRIx32",",
145 dp->acpi_hid_ex.cid);
148 off += format(buf, size, off, "%s)", uidstr);
150 off += format(buf, size, off, "0x%"PRIx32")",
154 off += format(buf, size, off,
155 "Acpi(0x%"PRIx32",0x%"PRIx32")",
156 dp->acpi_hid.hid, dp->acpi_hid.uid);
165 __attribute__((__visibility__ ("default")))
166 efidp_make_acpi_hid(uint8_t *buf, ssize_t size, uint32_t hid, uint32_t uid)
168 efidp_acpi_hid *acpi_hid = (efidp_acpi_hid *)buf;
169 ssize_t req = sizeof (*acpi_hid);
172 sz = efidp_make_generic(buf, size, EFIDP_ACPI_TYPE, EFIDP_ACPI_HID,
174 if (size && sz == req) {
183 __attribute__((__visibility__ ("default")))
184 __attribute__((__nonnull__ (6,7,8)))
185 efidp_make_acpi_hid_ex(uint8_t *buf, ssize_t size,
186 uint32_t hid, uint32_t uid, uint32_t cid,
187 char *hidstr, char *uidstr, char *cidstr)
189 efidp_acpi_hid_ex *acpi_hid = (efidp_acpi_hid_ex *)buf;
193 req = sizeof (*acpi_hid) + 3 +
194 strlen(hidstr) + strlen(uidstr) + strlen(cidstr);
195 sz = efidp_make_generic(buf, size, EFIDP_ACPI_TYPE, EFIDP_ACPI_HID_EX,
197 if (size && sz == req) {
201 char *next = (char *)buf+offsetof(efidp_acpi_hid_ex, hidstr);
202 strcpy(next, hidstr);
203 next += strlen(hidstr) + 1;
204 strcpy(next, uidstr);
205 next += strlen(uidstr) + 1;
206 strcpy(next, cidstr);