shared_mem: Update device-tree parsing to accomodate @Addr master DEV.MPM-TRANSPORT-02.00.04.00
authorSam Nelson <sam.nelson@ti.com>
Sat, 22 Apr 2017 00:57:39 +0000 (20:57 -0400)
committerSam Nelson <sam.nelson@ti.com>
Sat, 22 Apr 2017 03:07:27 +0000 (23:07 -0400)
The linux device tree nodes are getting updated to include the Address
in the node name to follow the upstream convention
(e.g dsp0 --> dsp0@10800000)

The code for parsing the device-tree is updated to adapt to this.

In future: Planning to remove the device-tree parsing and just use sysfs
entry parsing. So this is just a temporary workaround.

Signed-off-by: Sam Nelson <sam.nelson@ti.com>
src/transport/sharedmem/mpm_transport_sharedmem.c

index 2cd3689016cfab33d83b67b7e7016bae98294872..f0cf6f1a632292ad6cff390b2d609633465b4d8e 100755 (executable)
@@ -37,6 +37,7 @@
 #include <unistd.h>
 #include <malloc.h>
 #include <errno.h>
+#include <dirent.h>
 
 #include "mpm_transport_sharedmem.h"
 #include <syslog.h>
@@ -205,12 +206,39 @@ static int update_mem_entries(mpm_transport_cfg_t *sp,
        return 0;
 }
 
+/* Find the device_tree _name that matches the device_name */
+int get_dev_tree_name(char *dev_name, char *dev_tree_name)  {
+
+       DIR *dir = 0;
+       struct dirent *entry = 0;
+       char *ret_ptr;
+
+       dir = opendir("/proc/device-tree/soc");
+       if (!dir) {
+               perror("readdir /proc/device-tree/soc");
+               return -1;
+       }
+
+       while ((entry = readdir(dir)) != NULL) {
+               ret_ptr = strstr (entry->d_name, dev_name);
+               if ((ret_ptr == NULL) &&  (ret_ptr != entry->d_name)) {
+                       continue;
+               }
+               strcpy(dev_tree_name, entry->d_name);
+               closedir(dir);
+               return 0;
+       }
+       if (dir) closedir(dir);
+       return -1;
+}
+
 int mpm_transport_sharedmem_open(mpm_transport_cfg_t *sp, mpm_transport_open_t *ocfg)
 {
        int i, j, k;
        mpm_transport_sharedmem_t *td;
        int fd;
        char filename[MAX_FILE_NAME_LENGTH];
+       char dev_tree_name[MAX_FILE_NAME_LENGTH];
        char hexstring[MAX_PARAM_VAL_LENGTH];
        off_t  fileSize;
        struct stat statbuf;
@@ -336,8 +364,14 @@ int mpm_transport_sharedmem_open(mpm_transport_cfg_t *sp, mpm_transport_open_t *
                        mpm_printf(1, "\nFailed to open \"%s\" err=%s\n",
                                        filename, strerror(errno));
 #endif
+                       ret = get_dev_tree_name(devname, dev_tree_name);
+                       if (ret) {
+                               mpm_printf(1, "Failed to find dev tree entry for \"%s\" err=%d\n",
+                                       filename, ret);
+                               return MPM_TRANSPORT_SHM_OPEN_ERR_MEM_FILE_OPEN;
+                       }
                        /* Check device tree and record the index of the mmap */
-                       snprintf(filename, MAX_FILE_NAME_LENGTH, "/proc/device-tree/soc/%s/reg", devname);
+                       snprintf(filename, MAX_FILE_NAME_LENGTH, "/proc/device-tree/soc/%s/reg", dev_tree_name);
 
                        if ((fd = open(filename, O_RDONLY)) == -1)
                        {