summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/transport/sharedmem/mpm_transport_sharedmem.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/transport/sharedmem/mpm_transport_sharedmem.c b/src/transport/sharedmem/mpm_transport_sharedmem.c
index 2cd3689..f0cf6f1 100755
--- a/src/transport/sharedmem/mpm_transport_sharedmem.c
+++ b/src/transport/sharedmem/mpm_transport_sharedmem.c
@@ -37,6 +37,7 @@
37#include <unistd.h> 37#include <unistd.h>
38#include <malloc.h> 38#include <malloc.h>
39#include <errno.h> 39#include <errno.h>
40#include <dirent.h>
40 41
41#include "mpm_transport_sharedmem.h" 42#include "mpm_transport_sharedmem.h"
42#include <syslog.h> 43#include <syslog.h>
@@ -205,12 +206,39 @@ static int update_mem_entries(mpm_transport_cfg_t *sp,
205 return 0; 206 return 0;
206} 207}
207 208
209/* Find the device_tree _name that matches the device_name */
210int get_dev_tree_name(char *dev_name, char *dev_tree_name) {
211
212 DIR *dir = 0;
213 struct dirent *entry = 0;
214 char *ret_ptr;
215
216 dir = opendir("/proc/device-tree/soc");
217 if (!dir) {
218 perror("readdir /proc/device-tree/soc");
219 return -1;
220 }
221
222 while ((entry = readdir(dir)) != NULL) {
223 ret_ptr = strstr (entry->d_name, dev_name);
224 if ((ret_ptr == NULL) && (ret_ptr != entry->d_name)) {
225 continue;
226 }
227 strcpy(dev_tree_name, entry->d_name);
228 closedir(dir);
229 return 0;
230 }
231 if (dir) closedir(dir);
232 return -1;
233}
234
208int mpm_transport_sharedmem_open(mpm_transport_cfg_t *sp, mpm_transport_open_t *ocfg) 235int mpm_transport_sharedmem_open(mpm_transport_cfg_t *sp, mpm_transport_open_t *ocfg)
209{ 236{
210 int i, j, k; 237 int i, j, k;
211 mpm_transport_sharedmem_t *td; 238 mpm_transport_sharedmem_t *td;
212 int fd; 239 int fd;
213 char filename[MAX_FILE_NAME_LENGTH]; 240 char filename[MAX_FILE_NAME_LENGTH];
241 char dev_tree_name[MAX_FILE_NAME_LENGTH];
214 char hexstring[MAX_PARAM_VAL_LENGTH]; 242 char hexstring[MAX_PARAM_VAL_LENGTH];
215 off_t fileSize; 243 off_t fileSize;
216 struct stat statbuf; 244 struct stat statbuf;
@@ -336,8 +364,14 @@ int mpm_transport_sharedmem_open(mpm_transport_cfg_t *sp, mpm_transport_open_t *
336 mpm_printf(1, "\nFailed to open \"%s\" err=%s\n", 364 mpm_printf(1, "\nFailed to open \"%s\" err=%s\n",
337 filename, strerror(errno)); 365 filename, strerror(errno));
338#endif 366#endif
367 ret = get_dev_tree_name(devname, dev_tree_name);
368 if (ret) {
369 mpm_printf(1, "Failed to find dev tree entry for \"%s\" err=%d\n",
370 filename, ret);
371 return MPM_TRANSPORT_SHM_OPEN_ERR_MEM_FILE_OPEN;
372 }
339 /* Check device tree and record the index of the mmap */ 373 /* Check device tree and record the index of the mmap */
340 snprintf(filename, MAX_FILE_NAME_LENGTH, "/proc/device-tree/soc/%s/reg", devname); 374 snprintf(filename, MAX_FILE_NAME_LENGTH, "/proc/device-tree/soc/%s/reg", dev_tree_name);
341 375
342 if ((fd = open(filename, O_RDONLY)) == -1) 376 if ((fd = open(filename, O_RDONLY)) == -1)
343 { 377 {