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

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