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

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