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

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