summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSubhajit Paul2019-07-02 08:35:55 -0500
committerSubhajit Paul2019-07-02 08:36:27 -0500
commitb81f833f058498165f5a6778cda0ab5683122674 (patch)
treec48448cdd2f50719b86d19bb9fc3787595b9d77c
parent08c76fe1e620c44d842a663f2483365467f04dcd (diff)
downloadrpmsg-char-helper-b81f833f058498165f5a6778cda0ab5683122674.tar.gz
rpmsg-char-helper-b81f833f058498165f5a6778cda0ab5683122674.tar.xz
rpmsg-char-helper-b81f833f058498165f5a6778cda0ab5683122674.zip
feature: rproc_char_endpt_get_local_port
Signed-off-by: Subhajit Paul <subhajit_paul@ti.com>
-rw-r--r--rpmsg_char_helper.c66
-rw-r--r--rpmsg_char_helper.h1
2 files changed, 67 insertions, 0 deletions
diff --git a/rpmsg_char_helper.c b/rpmsg_char_helper.c
index 071a19a..fd424e7 100644
--- a/rpmsg_char_helper.c
+++ b/rpmsg_char_helper.c
@@ -665,6 +665,72 @@ out:
665 return ept; 665 return ept;
666} 666}
667 667
668int rproc_char_endpt_get_local_port(rproc_char_endpt_t *ept)
669{
670 struct rproc_device *dev;
671 struct rproc_map *r;
672 struct rproc_char_device *cdev;
673 char *ept_src_path;
674 int fd;
675 char buf[32];
676 int ret;
677 uint32_t src;
678
679 if(!ept) {
680 printerr("%s: ept = NULL not allowed\n", __func__);
681 return -1;
682 }
683
684 cdev = ept->cdev;
685 if(!cdev) {
686 printerr("%s: malformed ept -> cdev = NULL\n", __func__);
687 return -1;
688 }
689
690 dev = cdev->dev;
691 if(!dev) {
692 printerr("%s: malformed ept -> dev = NULL\n", __func__);
693 return -1;
694 }
695
696 r = dev->priv;
697 if(!r || (r - &maps[0]) >= NUM_RPROCS) {
698 printerr("%s: malformed ept -> bad dev->priv \n", __func__);
699 return -1;
700 }
701
702 ept_src_path = str_join("%s/remoteproc/remoteproc%u/virtio%u/virtio%u.rpmsg_chrdev.%d.%d/rpmsg/rpmsg_ctrl%u/rpmsg%u/src",
703 r->sysfs_path, dev->remoteproc_id, dev->virtio_id, dev->virtio_id,
704 cdev->src, cdev->dst, cdev->ctrl_id, ept->rpmsg_id);
705 if(ept_src_path)
706 fd = open(ept_src_path, O_RDONLY);
707 if(!ept_src_path || fd < 0) {
708 printerr("%s: could not open endpoint src for %s\n", __func__, ept->rpmsg_id);
709 if(ept_src_path)
710 free(ept_src_path);
711 return -1;
712 }
713 free(ept_src_path);
714
715 ret = read(fd, buf, 32);
716 close(fd);
717
718 if(ret <= 0) {
719 printerr("%s: could not read src file\n", __func__);
720 return -1;
721 }
722
723 buf[ret - 1] = '\0';
724
725 ret = sscanf(buf, "%u", &src);
726 if(ret != 1) {
727 printerr("%s: could not read src file data\n", __func__);
728 return -1;
729 }
730
731 return src;
732}
733
668char *rproc_char_endpt_get_dev_name(rproc_char_endpt_t *ept) 734char *rproc_char_endpt_get_dev_name(rproc_char_endpt_t *ept)
669{ 735{
670 if(!ept) { 736 if(!ept) {
diff --git a/rpmsg_char_helper.h b/rpmsg_char_helper.h
index 78a72a4..cb1a899 100644
--- a/rpmsg_char_helper.h
+++ b/rpmsg_char_helper.h
@@ -33,6 +33,7 @@ rproc_char_endpt_t *rproc_char_device_create_endpt(rproc_char_device_t *cdev, ch
33rproc_char_endpt_t *rproc_char_device_find_endpt_by_name(rproc_char_device_t *cdev, char *name); 33rproc_char_endpt_t *rproc_char_device_find_endpt_by_name(rproc_char_device_t *cdev, char *name);
34rproc_char_endpt_t *rproc_char_device_find_endpt_by_local_port(rproc_char_device_t *cdev, int local_port); 34rproc_char_endpt_t *rproc_char_device_find_endpt_by_local_port(rproc_char_device_t *cdev, int local_port);
35char *rproc_char_endpt_get_dev_name(rproc_char_endpt_t *ept); 35char *rproc_char_endpt_get_dev_name(rproc_char_endpt_t *ept);
36int rproc_char_endpt_get_local_port(rproc_char_endpt_t *ept);
36 37
37int rproc_char_endpt_destroy(rproc_char_endpt_t *ept); 38int rproc_char_endpt_destroy(rproc_char_endpt_t *ept);
38 39