Blame SOURCES/0016-Make-a-linux-device-root-for-SOC-devices-that-use-FD.patch

821f82
From d8637ea2b540fc9d16f1d1c1312e49a24082eefe Mon Sep 17 00:00:00 2001
821f82
From: Peter Jones <pjones@redhat.com>
821f82
Date: Wed, 20 Jun 2018 16:16:35 -0400
821f82
Subject: [PATCH 16/17] Make a linux device root for SOC devices that use FDT.
821f82
821f82
Add parsing for FDT devices in sysfs.  These devices have to use HD() or
821f82
File() because we don't have a way to express FDT nodes in a Device
821f82
Path.
821f82
821f82
Signed-off-by: Peter Jones <pjones@redhat.com>
821f82
---
821f82
 src/linux-soc-root.c | 72 ++++++++++++++++++++++++++++++++++++++++++++
821f82
 src/linux.c          |  1 +
821f82
 src/linux.h          |  3 +-
821f82
 3 files changed, 75 insertions(+), 1 deletion(-)
821f82
 create mode 100644 src/linux-soc-root.c
821f82
821f82
diff --git a/src/linux-soc-root.c b/src/linux-soc-root.c
821f82
new file mode 100644
821f82
index 00000000000..57dd9b04f2c
821f82
--- /dev/null
821f82
+++ b/src/linux-soc-root.c
821f82
@@ -0,0 +1,72 @@
821f82
+/*
821f82
+ * libefiboot - library for the manipulation of EFI boot variables
821f82
+ * Copyright 2012-2018 Red Hat, Inc.
821f82
+ *
821f82
+ * This library is free software; you can redistribute it and/or
821f82
+ * modify it under the terms of the GNU Lesser General Public License as
821f82
+ * published by the Free Software Foundation; either version 2.1 of the
821f82
+ * License, or (at your option) any later version.
821f82
+ *
821f82
+ * This library is distributed in the hope that it will be useful,
821f82
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
821f82
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
821f82
+ * Lesser General Public License for more details.
821f82
+ *
821f82
+ * You should have received a copy of the GNU Lesser General Public
821f82
+ * License along with this library; if not, see
821f82
+ * <http://www.gnu.org/licenses/>.
821f82
+ *
821f82
+ */
821f82
+
821f82
+#include "fix_coverity.h"
821f82
+
821f82
+#include <errno.h>
821f82
+#include <fcntl.h>
821f82
+#include <inttypes.h>
821f82
+#include <stdint.h>
821f82
+#include <unistd.h>
821f82
+
821f82
+#include "efiboot.h"
821f82
+
821f82
+/*
821f82
+ * support for soc platforms
821f82
+ *
821f82
+ * various devices /sys/dev/block/$major:$minor start with:
821f82
+ * maj:min ->  ../../devices/platform/soc/$DEVICETREE_NODE/$BLOCKDEV_STUFF/block/$DISK/$PART
821f82
+ * i.e.:                              soc/1a400000.sata/ata1/host0/target0:0:0/0:0:0:0/block/sda/sda1
821f82
+ *                                        ^ dt node     ^ blockdev stuff                     ^ disk
821f82
+ * I don't *think* the devicetree nodes stack.
821f82
+ */
821f82
+static ssize_t
821f82
+parse_soc_root(struct device *dev UNUSED, const char *current, const char *root UNUSED)
821f82
+{
821f82
+        int rc;
821f82
+        int pos;
821f82
+        const char *devpart = current;
821f82
+        char *spaces;
821f82
+
821f82
+        pos = strlen(current);
821f82
+        spaces = alloca(pos+1);
821f82
+        memset(spaces, ' ', pos+1);
821f82
+        spaces[pos] = '\0';
821f82
+        pos = 0;
821f82
+
821f82
+        debug(DEBUG, "entry");
821f82
+
821f82
+        rc = sscanf(devpart, "../../devices/platform/soc/%*[^/]/%n", &pos;;
821f82
+        if (rc != 0)
821f82
+                return 0;
821f82
+        devpart += pos;
821f82
+        debug(DEBUG, "new position is \"%s\"", devpart);
821f82
+
821f82
+        return devpart - current;
821f82
+}
821f82
+
821f82
+enum interface_type soc_root_iftypes[] = { soc_root, unknown };
821f82
+
821f82
+struct dev_probe HIDDEN soc_root_parser = {
821f82
+        .name = "soc_root",
821f82
+        .iftypes = soc_root_iftypes,
821f82
+        .flags = DEV_ABBREV_ONLY|DEV_PROVIDES_ROOT,
821f82
+        .parse = parse_soc_root,
821f82
+};
821f82
diff --git a/src/linux.c b/src/linux.c
821f82
index 83adc510944..1e7db4e3f61 100644
821f82
--- a/src/linux.c
821f82
+++ b/src/linux.c
821f82
@@ -237,6 +237,7 @@ static struct dev_probe *dev_probes[] = {
821f82
         &pmem_parser,
821f82
         &acpi_root_parser,
821f82
         &pci_root_parser,
821f82
+        &soc_root_parser,
821f82
         &pci_parser,
821f82
         &virtblk_parser,
821f82
         &sas_parser,
821f82
diff --git a/src/linux.h b/src/linux.h
821f82
index ef7dba769bd..99d61013e02 100644
821f82
--- a/src/linux.h
821f82
+++ b/src/linux.h
821f82
@@ -95,7 +95,7 @@ struct nvdimm_info {
821f82
 
821f82
 enum interface_type {
821f82
         unknown,
821f82
-        isa, acpi_root, pci_root, pci, network,
821f82
+        isa, acpi_root, pci_root, soc_root, pci, network,
821f82
         ata, atapi, scsi, sata, sas,
821f82
         usb, i1394, fibre, i2o,
821f82
         md, virtblk,
821f82
@@ -268,6 +268,7 @@ extern ssize_t parse_scsi_link(const char *current, uint32_t *host,
821f82
 extern struct dev_probe pmem_parser;
821f82
 extern struct dev_probe pci_root_parser;
821f82
 extern struct dev_probe acpi_root_parser;
821f82
+extern struct dev_probe soc_root_parser;
821f82
 extern struct dev_probe pci_parser;
821f82
 extern struct dev_probe sas_parser;
821f82
 extern struct dev_probe sata_parser;
821f82
-- 
821f82
2.17.1
821f82