Przeglądaj źródła

rpmsg: rpc: use the local device pointer in all file operations

The remote processor recovery process includes the deletion and
recreation of an rpmsg-rpc device. The representative rppc_device
structure is retained and reused if there are any open applications
using the exposed character device. The underlying device pointer
for a rppc_device is though deleted and recreated and can become
NULL at any point if an error recovery happens. So, switch to using
the local reference device pointer in all the fop functions for
the exposed character device.

Signed-off-by: Suman Anna <s-anna@ti.com>
Suman Anna 11 lat temu
rodzic
commit
727a8895fe
2 zmienionych plików z 30 dodań i 32 usunięć
  1. 23 24
      drivers/rpmsg/rpmsg_rpc.c
  2. 7 8
      drivers/rpmsg/rpmsg_rpc_dmabuf.c

+ 23 - 24
drivers/rpmsg/rpmsg_rpc.c

@@ -66,7 +66,7 @@ dev_addr_t rppc_local_to_remote_da(struct rppc_instance *rpc, phys_addr_t pa)
 	struct rproc *rproc;
 	u64 da = 0;
 	dev_addr_t rda;
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 
 	if (mutex_lock_interruptible(&rpc->rppcdev->lock))
 		return 0;
@@ -97,7 +97,7 @@ static void rppc_print_msg(struct rppc_instance *rpc, char *prefix,
 	struct rppc_query_function *info = NULL;
 	struct rppc_packet *packet = NULL;
 	struct rppc_param_data *param = NULL;
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 	u32 i = 0, paramsz = sizeof(*param);
 
 	dev_dbg(dev, "%s HDR: msg_type = %d msg_len = %d\n",
@@ -153,7 +153,7 @@ struct rppc_function *rppc_find_fxn(struct rppc_instance *rpc, u16 msg_id)
 {
 	struct rppc_function *function = NULL;
 	struct rppc_function_list *pos, *n;
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 
 	mutex_lock(&rpc->lock);
 	list_for_each_entry_safe(pos, n, &rpc->fxn_list, list) {
@@ -175,7 +175,7 @@ static int rppc_add_fxn(struct rppc_instance *rpc,
 			struct rppc_function *function, u16 msg_id)
 {
 	struct rppc_function_list *fxn = NULL;
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 
 	fxn = kzalloc(sizeof(*fxn), GFP_KERNEL);
 	if (!fxn)
@@ -194,7 +194,7 @@ static int rppc_add_fxn(struct rppc_instance *rpc,
 static
 void rppc_handle_create_resp(struct rppc_instance *rpc, char *data, int len)
 {
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 	struct rppc_msg_header *hdr = (struct rppc_msg_header *)data;
 	struct rppc_instance_handle *hdl;
 	u32 exp_len = sizeof(*hdl) + sizeof(*hdr);
@@ -226,7 +226,7 @@ void rppc_handle_create_resp(struct rppc_instance *rpc, char *data, int len)
 static
 void rppc_handle_delete_resp(struct rppc_instance *rpc, char *data, int len)
 {
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 	struct rppc_msg_header *hdr = (struct rppc_msg_header *)data;
 	struct rppc_instance_handle *hdl;
 	u32 exp_len = sizeof(*hdl) + sizeof(*hdr);
@@ -289,7 +289,7 @@ static int rppc_cb(struct rpmsg_device *rpdev,
 {
 	struct rppc_msg_header *hdr = data;
 	struct rppc_instance *rpc = priv;
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 	char *buf = (char *)data;
 
 	dev_dbg(dev, "<== incoming msg src %d len %d msg_type %d msg_len %d\n",
@@ -336,7 +336,7 @@ static int rppc_connect(struct rppc_instance *rpc,
 	struct rppc_msg_header *hdr = (struct rppc_msg_header *)&kbuf[0];
 
 	if (rpc->state == RPPC_STATE_CONNECTED) {
-		dev_dbg(rppcdev->dev, "endpoint already connected\n");
+		dev_dbg(rpc->dev, "endpoint already connected\n");
 		return -EISCONN;
 	}
 
@@ -350,7 +350,7 @@ static int rppc_connect(struct rppc_instance *rpc,
 	ret = rpmsg_send_offchannel(rppcdev->rpdev->ept, rpc->ept->addr,
 				    rppcdev->rpdev->dst, (char *)kbuf, len);
 	if (ret > 0) {
-		dev_err(rppcdev->dev, "rpmsg_send failed: %d\n", ret);
+		dev_err(rpc->dev, "rpmsg_send failed: %d\n", ret);
 		return ret;
 	}
 
@@ -363,7 +363,7 @@ static int rppc_connect(struct rppc_instance *rpc,
 		return -ENXIO;
 
 	if (ret > 0) {
-		dev_err(rppcdev->dev, "premature wakeup: %d\n", ret);
+		dev_err(rpc->dev, "premature wakeup: %d\n", ret);
 		return -EIO;
 	}
 
@@ -389,12 +389,12 @@ static void rppc_disconnect(struct rppc_instance *rpc)
 	handle->status = 0;
 	len = sizeof(struct rppc_msg_header) + hdr->msg_len;
 
-	dev_dbg(rppcdev->dev, "disconnecting from RPC service at %d\n",
+	dev_dbg(rpc->dev, "disconnecting from RPC service at %d\n",
 		rpc->dst);
 	ret = rpmsg_send_offchannel(rppcdev->rpdev->ept, rpc->ept->addr,
 				    rppcdev->rpdev->dst, kbuf, len);
 	if (ret)
-		dev_err(rppcdev->dev, "rpmsg_send failed: %d\n", ret);
+		dev_err(rpc->dev, "rpmsg_send failed: %d\n", ret);
 
 	/*
 	 * TODO: should we wait for a message to come back?
@@ -569,7 +569,7 @@ static int rppc_open(struct inode *inode, struct file *filp)
 	chinfo.dst = RPMSG_ADDR_ANY;
 	rpc->ept = rpmsg_create_ept(rppcdev->rpdev, rppc_cb, rpc, chinfo);
 	if (!rpc->ept) {
-		dev_err(rppcdev->dev, "create ept failed\n");
+		dev_err(rpc->dev, "create ept failed\n");
 		put_device(rpc->dev);
 		kfree(rpc);
 		return -ENOMEM;
@@ -580,7 +580,7 @@ static int rppc_open(struct inode *inode, struct file *filp)
 	list_add(&rpc->list, &rppcdev->instances);
 	mutex_unlock(&rppcdev->lock);
 
-	dev_dbg(rppcdev->dev, "local addr assigned: 0x%x\n", rpc->ept->addr);
+	dev_dbg(rpc->dev, "local addr assigned: 0x%x\n", rpc->ept->addr);
 
 	return 0;
 }
@@ -598,7 +598,7 @@ static int rppc_release(struct inode *inode, struct file *filp)
 	struct rppc_instance *rpc = filp->private_data;
 	struct rppc_device *rppcdev = rpc->rppcdev;
 
-	dev_dbg(rppcdev->dev, "releasing Instance %p, in state %d\n", rpc,
+	dev_dbg(rpc->dev, "releasing Instance %p, in state %d\n", rpc,
 		rpc->state);
 
 	if (rpc->state != RPPC_STATE_STALE) {
@@ -620,9 +620,9 @@ static int rppc_release(struct inode *inode, struct file *filp)
 	list_del(&rpc->list);
 	mutex_unlock(&rppcdev->lock);
 
-	dev_dbg(rppcdev->dev, "instance %p has been deleted!\n", rpc);
+	dev_dbg(rpc->dev, "instance %p has been deleted!\n", rpc);
 	if (list_empty(&rppcdev->instances))
-		dev_dbg(rppcdev->dev, "all instances have been removed!\n");
+		dev_dbg(rpc->dev, "all instances have been removed!\n");
 
 	put_device(rpc->dev);
 	kfree(rpc);
@@ -632,11 +632,10 @@ static int rppc_release(struct inode *inode, struct file *filp)
 static long rppc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	struct rppc_instance *rpc = filp->private_data;
-	struct rppc_device *rppcdev = rpc->rppcdev;
 	struct rppc_create_instance connect;
 	int ret = 0;
 
-	dev_dbg(rppcdev->dev, "%s: cmd %d, arg 0x%lx\n", __func__, cmd, arg);
+	dev_dbg(rpc->dev, "%s: cmd %d, arg 0x%lx\n", __func__, cmd, arg);
 
 	if (_IOC_TYPE(cmd) != RPPC_IOC_MAGIC)
 		return -ENOTTY;
@@ -649,7 +648,7 @@ static long rppc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		ret = copy_from_user(&connect, (char __user *)arg,
 				     sizeof(connect));
 		if (ret) {
-			dev_err(rppcdev->dev, "%s: %d: copy_from_user fail: %d\n",
+			dev_err(rpc->dev, "%s: %d: copy_from_user fail: %d\n",
 				__func__, _IOC_NR(cmd), ret);
 			ret = -EFAULT;
 		} else {
@@ -664,7 +663,7 @@ static long rppc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		ret = rppc_unregister_buffers(rpc, arg);
 		break;
 	default:
-		dev_err(rppcdev->dev, "unhandled ioctl cmd: %d\n", cmd);
+		dev_err(rpc->dev, "unhandled ioctl cmd: %d\n", cmd);
 		break;
 	}
 
@@ -762,7 +761,7 @@ static ssize_t rppc_read(struct file *filp, char __user *buf, size_t len,
 	if (function && function->num_translations > 0) {
 		ret = rppc_xlate_buffers(rpc, function, RPPC_RPA_TO_UVA);
 		if (ret < 0) {
-			dev_err(rpc->rppcdev->dev, "failed to translate back pointers from remote core!\n");
+			dev_err(rpc->dev, "failed to translate back pointers from remote core!\n");
 			goto failure;
 		}
 	}
@@ -770,7 +769,7 @@ static ssize_t rppc_read(struct file *filp, char __user *buf, size_t len,
 	returned.status = packet->result;
 
 	if (copy_to_user(buf, &returned, use)) {
-		dev_err(rpc->rppcdev->dev, "%s: copy_to_user fail\n", __func__);
+		dev_err(rpc->dev, "%s: copy_to_user fail\n", __func__);
 		ret = -EFAULT;
 	} else {
 		ret = use;
@@ -788,7 +787,7 @@ static ssize_t rppc_write(struct file *filp, const char __user *ubuf,
 {
 	struct rppc_instance *rpc = filp->private_data;
 	struct rppc_device *rppcdev = rpc->rppcdev;
-	struct device *dev = rppcdev->dev;
+	struct device *dev = rpc->dev;
 	struct rppc_msg_header *hdr = NULL;
 	struct rppc_function *function = NULL;
 	struct rppc_packet *packet = NULL;

+ 7 - 8
drivers/rpmsg/rpmsg_rpc_dmabuf.c

@@ -103,7 +103,6 @@ static inline long rppc_recalc_off(phys_addr_t lpa, long uoff)
 struct rppc_dma_buf *rppc_alloc_dmabuf(struct rppc_instance *rpc, int fd,
 				       bool autoreg)
 {
-	struct rppc_device *rppcdev = rpc->rppcdev;
 	struct rppc_dma_buf *dma;
 	void *ret;
 	int id;
@@ -120,7 +119,7 @@ struct rppc_dma_buf *rppc_alloc_dmabuf(struct rppc_instance *rpc, int fd,
 		goto free_dma;
 	}
 
-	dma->attach = dma_buf_attach(dma->buf, rppcdev->dev);
+	dma->attach = dma_buf_attach(dma->buf, rpc->dev);
 	if (IS_ERR(dma->attach)) {
 		ret = dma->attach;
 		goto put_buf;
@@ -263,14 +262,14 @@ struct rppc_dma_buf *rppc_find_dmabuf(struct rppc_instance *rpc, int fd)
 	struct rppc_dma_buf *node = NULL;
 	void *data = (void *)fd;
 
-	dev_dbg(rpc->rppcdev->dev, "looking for fd %u\n", fd);
+	dev_dbg(rpc->dev, "looking for fd %u\n", fd);
 
 	mutex_lock(&rpc->lock);
 	node = (struct rppc_dma_buf *)
 			idr_for_each(&rpc->dma_idr, find_dma_by_fd, data);
 	mutex_unlock(&rpc->lock);
 
-	dev_dbg(rpc->rppcdev->dev, "returning node %p for fd %u\n",
+	dev_dbg(rpc->dev, "returning node %p for fd %u\n",
 		node, fd);
 
 	return node;
@@ -306,7 +305,7 @@ static int rppc_map_page(struct rppc_instance *rpc, int fd, u32 offset,
 	u32 pg_offset;
 	unsigned long pg_num;
 	size_t begin, end = PAGE_SIZE;
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 
 	if (!base_ptr || !dmabuf)
 		return -EINVAL;
@@ -369,7 +368,7 @@ static void rppc_unmap_page(struct rppc_instance *rpc, u32 offset,
 	u32 pg_offset;
 	unsigned long pg_num;
 	size_t begin, end = PAGE_SIZE;
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 
 	if (!base_ptr || !dmabuf)
 		return;
@@ -416,7 +415,7 @@ dev_addr_t rppc_buffer_lookup(struct rppc_instance *rpc, virt_addr_t uva,
 	phys_addr_t lpa = 0;
 	dev_addr_t rda = 0;
 	long uoff = uva - buva;
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 	struct rppc_dma_buf *buf;
 
 	dev_dbg(dev, "buva = %p uva = %p offset = %ld [0x%016lx] fd = %d\n",
@@ -469,7 +468,7 @@ int rppc_xlate_buffers(struct rppc_instance *rpc, struct rppc_function *func,
 {
 	u8 *base_ptr = NULL;
 	struct dma_buf *dbuf = NULL;
-	struct device *dev = rpc->rppcdev->dev;
+	struct device *dev = rpc->dev;
 	u32 ptr_idx, pri_offset, sec_offset, offset, pg_offset, size;
 	int i, limit, inc = 1;
 	virt_addr_t kva, uva, buva;