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

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