2 * libefiboot - library for the manipulation of EFI boot variables
3 * Copyright 2012-2018 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/>.
21 #include "fix_coverity.h"
32 * support NVDIMM-P (pmem / btt) devices
33 * (does not include NVDIMM-${ANYTHING_ELSE})
35 * /sys/dev/block/$major:$minor looks like:
36 * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region9/btt9.0/block/pmem9s
37 * 259:1 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region11/btt11.0/block/pmem11s
38 * 259:3 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region11/btt11.0/block/pmem11s/pmem11s1
40 * /sys/dev/block/259:0/device looks like:
41 * device -> ../../../btt9.0
42 * /sys/dev/block/259:1/device looks like:
43 * device -> ../../../btt11.0
45 * /sys/dev/block/259:1/partition looks like:
49 * /sys/dev/block/259:0/uuid looks like:
51 * 6e54091e-7476-47ac-824b-b6dd69878661
53 * pmem12s -> ../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s
55 * device -> ../../../btt12.1
56 * device/uuid: 0cee166e-dd56-4bc2-99d2-2544b69025b8
57 * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s
59 * pmem12.1s -> ../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.2/block/pmem12.1s
61 * device -> ../../../btt12.2
62 * device/uuid: 78d94521-91f7-47db-b3a7-51b764281940
63 * 259:1 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.2/block/pmem12.1s
65 * pmem12.2 -> ../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/pfn12.1/block/pmem12.2
67 * device -> ../../../pfn12.1
68 * device/uuid: 829c5205-89a5-4581-9819-df7d7754c622
69 * 259:2 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/pfn12.1/block/pmem12.2
73 parse_pmem(struct device *dev, const char *current, const char *root UNUSED)
75 uint8_t *filebuf = NULL;
76 uint8_t system, sysbus, acpi_id;
78 int ndbus, region, btt_region_id, btt_id, rc, pos;
79 char *namespace = NULL;
83 if (!strcmp(dev->driver, "nd_pmem")) {
86 } else if (!strcmp(dev->driver, "nd_blk")) {
88 dev->inteface_type = scsi;
98 * We're not actually using any of the values here except pos (our
99 * return value), but rather just being paranoid that this is the sort
100 * of device we care about.
102 * 259:0 -> ../../devices/LNXSYSTM:00/LNXSYBUS:00/ACPI0012:00/ndbus0/region12/btt12.1/block/pmem12s
105 "../../devices/LNXSYSTM:%hhx/LNXSYBUS:%hhx/ACPI%hx:%hhx/ndbus%d/region%d/btt%d.%d/%n",
106 &system, &sysbus, &pnp_id, &acpi_id, &ndbus, ®ion,
107 &btt_region_id, &btt_id, &pos);
112 * but the UUID we really do need to have.
114 rc = read_sysfs_file(&filebuf,
115 "class/block/%s/device/namespace", dev->disk_name);
116 if ((rc < 0 && errno == ENOENT) || filebuf == NULL)
119 rc = sscanf((char *)filebuf, "%ms[^\n]\n", &namespace);
120 if (rc != 1 || namespace == NULL)
124 debug("nvdimm namespace is \"%s\"", namespace);
125 rc = read_sysfs_file(&filebuf, "bus/nd/devices/%s/uuid", namespace);
127 if (rc < 0 || filebuf == NULL)
130 rc = efi_str_to_guid((char *)filebuf,
131 &dev->nvdimm_info.namespace_label);
136 rc = read_sysfs_file(&filebuf, "class/block/%s/device/uuid",
138 if (rc < 0 || filebuf == NULL)
141 rc = efi_str_to_guid((char *)filebuf,
142 &dev->nvdimm_info.nvdimm_label);
147 * Right now it's not clear what encoding NVDIMM($uuid) gets in the
148 * binary format, so this will be in the mixed endian format EFI GUIDs
149 * are in (33221100-1100-1100-0011-223344556677) unless you set this
152 if (getenv("LIBEFIBOOT_SWIZZLE_PMEM_UUID") != NULL) {
153 swizzle_guid_to_uuid(&dev->nvdimm_info.namespace_label);
154 swizzle_guid_to_uuid(&dev->nvdimm_info.nvdimm_label);
157 dev->interface_type = nd_pmem;
163 dp_create_pmem(struct device *dev,
164 uint8_t *buf, ssize_t size, ssize_t off)
170 sz = efidp_make_nvdimm(buf + off, size ? size - off : 0,
171 &dev->nvdimm_info.namespace_label);
175 sz1 = efidp_make_nvdimm(buf + off, size ? size - off : 0,
176 &dev->nvdimm_info.nvdimm_label);
183 enum interface_type pmem_iftypes[] = { nd_pmem, unknown };
185 struct dev_probe HIDDEN pmem_parser = {
187 .iftypes = pmem_iftypes,
188 .flags = DEV_PROVIDES_ROOT|DEV_PROVIDES_HD,
190 .create = dp_create_pmem,