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

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