Skip to contentSkip to conversation

ieee1275: add nvme support within ofpath

PATCH Applied Eric Snowberg 3 participants 4 messages Feb 20, 2018 – Feb 23, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ieee1275: add nvme support within ofpath

Add NVMe support within ofpath.

The Open Firmware text representation for a NVMe device contains the Namespace ID. An invalid namespace ID is one whose value is zero or whose value is greater than the value reported by the Number of Namespaces (NN) field in the Identify Controller data structure. At the moment only a single Namespace is supported, therefore the value is currently hard coded to one.

---
 grub-core/osdep/linux/ofpath.c |   47 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)
grub-core/osdep/linux/ofpath.c +47 -0
index 8d7d683..af068f9 100644
@@ -350,6 +350,50 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi
   return ret;
 }
 
+static char *
+of_path_of_nvme(const char *sys_devname __attribute__((unused)),
+	        const char *device,
+	        const char *devnode __attribute__((unused)),
+	        const char *devicenode)
+{
+  char *sysfs_path, *of_path, disk[MAX_DISK_CAT];
+  const char *digit_string, *part_end;
+
+  digit_string = trailing_digits (device);
+  part_end = devicenode + strlen (devicenode) - 1;
+
+  if ((digit_string != '\0') && (*part_end == 'p'))
+    {
+      /* We have a partition number, strip it off. */
+      int part;
+      char *nvmedev, *end;
+
+      nvmedev = strdup (devicenode);
+
+      if (nvmedev == NULL)
+        return NULL;
+
+      end = nvmedev + strlen (nvmedev) - 1;
+      /* Remove the p. */
+      *end = '\0';
+      sscanf (digit_string, "%d", &part);
+      snprintf (disk, sizeof (disk), "/disk@1:%c", 'a' + (part - 1));
+      sysfs_path = block_device_get_sysfs_path_and_link (nvmedev);
+      free (nvmedev);
+    }
+  else
+    {
+      /* We do not have the parition. */
+      snprintf (disk, sizeof (disk), "/disk@1");
+      sysfs_path = block_device_get_sysfs_path_and_link (device);
+    }
+
+  of_path = find_obppath (sysfs_path);
+  free (sysfs_path);
+  strcat (of_path, disk);
+  return of_path;
+}
+
 static int
 vendor_is_ATA(const char *path)
 {
@@ -681,6 +725,9 @@ grub_util_devname_to_ofpath (const char *sys_devname)
     /* All the models I've seen have a devalias "floppy".
        New models have no floppy at all. */
     ofpath = xstrdup ("floppy");
+  else if (device[0] == 'n' && device[1] == 'v' && device[2] == 'm'
+           && device[3] == 'e')
+    ofpath = of_path_of_nvme (name_buf, device, devnode, devicenode);
   else
     {
       grub_util_warn (_("unknown device type %s"), device);
Signature · 1 line
1.7.1
#1 lore raw
Quoted 10 lines · Eric Snowberg

Add NVMe support within ofpath.

The Open Firmware text representation for a NVMe device contains the Namespace ID. An invalid namespace ID is one whose value is zero or whose value is greater than the value reported by the Number of Namespaces (NN) field in the Identify Controller data structure. At the moment only a single Namespace is supported, therefore the value is currently hard coded to one.

Just one nit pick... I will change this during commit.

Otherwise Reviewed-by: Daniel Kiper <[email protected]>

Quoted 23 lines
---
 grub-core/osdep/linux/ofpath.c |   47 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)
grub-core/osdep/linux/ofpath.c +11 -0
index 8d7d683..af068f9 100644
@@ -350,6 +350,50 @@ of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi
   return ret;
 }
 
+static char *
+of_path_of_nvme(const char *sys_devname __attribute__((unused)),
+	        const char *device,
+	        const char *devnode __attribute__((unused)),
+	        const char *devicenode)
+{
+  char *sysfs_path, *of_path, disk[MAX_DISK_CAT];
+  const char *digit_string, *part_end;
+
+  digit_string = trailing_digits (device);
+  part_end = devicenode + strlen (devicenode) - 1;

grub-core/osdep/linux/ofpath.c of_path_of_ide(const char *sys_devname __attribute__((unused)), const char *devi · line 373

Quoted 10 lines
grub-core/osdep/linux/ofpath.c +10 -0
+
+  if ((digit_string != '\0') && (*part_end == 'p'))
+    {
+      /* We have a partition number, strip it off. */
+      int part;
+      char *nvmedev, *end;
+
+      nvmedev = strdup (devicenode);
+
+      if (nvmedev == NULL)

"if (!nvmedev)" is the convention in this file.

Daniel

Applied
#2 lore raw
Quoted 10 lines · Daniel Kiper
Quoted 9 lines · Eric Snowberg

Add NVMe support within ofpath.

The Open Firmware text representation for a NVMe device contains the Namespace ID. An invalid namespace ID is one whose value is zero or whose value is greater than the value reported by the Number of Namespaces (NN) field in the Identify Controller data structure. At the moment only a single Namespace is supported, therefore the value is currently hard coded to one.

Quoted 5 lines
Quoted 1 line

Just one nit pick... I will change this during commit.

Otherwise Reviewed-by: Daniel Kiper <[email protected]>

Applied!

FYI, this is last time when I sent commit confirmation. If I send one in the future then this will be rather exception than rule. So, if you receive my reviewed-by and patch is not committed in a week or two then it means that it fallen into abyss and you have to ping me.

Have a nice weekend,

Daniel

#3 lore raw
Quoted 1 line · Daniel Kiper

Applied!

Woohooo \o/. Debian on sparc64 with a working GRUB is getting closer :-).

Quoted 5 lines

FYI, this is last time when I sent commit confirmation. If I send one in the future then this will be rather exception than rule. So, if you receive my reviewed-by and patch is not committed in a week or two then it means that it fallen into abyss and you have to ping me.

The abyss a.k.a. Oracle's headquarters :D.

Quoted 1 line

Have a nice weekend,

Have a nice one, too!

Adrian

Signature · 4 lines
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - [email protected]
`. `'   Freie Universitaet Berlin - [email protected]
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913