Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Date: Fri, 25 Jan 2019 13:17:38 -0700
- Subject: [PATCH] Disable logging by default and clarified reading back of
- state
- Updated to use driver instead of device
- ---
- arch/arm/mach-imx/mu.c | 26 +++++---
- drivers/rpmsg/imx_rpmsg.c | 26 +++++---
- drivers/rpmsg/imx_rpmsg_tty.c | 29 +++++---
- drivers/rpmsg/virtio_rpmsg_bus.c | 139 ++++++++++++++++++---------------------
- 4 files changed, 120 insertions(+), 100 deletions(-)
- diff --git a/arch/arm/mach-imx/mu.c b/arch/arm/mach-imx/mu.c
- index a962b44..201528b 100644
- --- a/arch/arm/mach-imx/mu.c
- +++ b/arch/arm/mach-imx/mu.c
- @@ -65,7 +65,7 @@ struct irq_domain *domain;
- static bool m4_in_stop;
- static struct clk *clk;
- static DEFINE_SPINLOCK(mu_lock);
- -static bool logging_enabled = true;
- +static bool logging_enabled = false;
- void imx_mu_set_m4_run_mode(void)
- {
- @@ -478,15 +478,25 @@ static int imx_mu_probe(struct platform_device *pdev)
- return 0;
- }
- -static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
- +static ssize_t show_log_level(struct device_driver * dev, char* buf)
- {
- - return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
- + return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "1 - on" : "0 - off");
- }
- -static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
- +static ssize_t toggle_log_level(struct device_driver * dev, const char* buf, size_t count)
- {
- - logging_enabled = logging_enabled ? false : true;
- - return count;
- + if(buf && count > 0)
- + {
- + if(buf[0] == '1')
- + {
- + logging_enabled = true;
- + }
- + else
- + {
- + logging_enabled = false;
- + }
- + }
- + return count;
- }
- static const struct of_device_id imx_mu_ids[] = {
- @@ -496,9 +506,9 @@ static const struct of_device_id imx_mu_ids[] = {
- { }
- };
- -static DEVICE_ATTR(log_enabled, 0644, show_log_level, toggle_log_level);
- +static DRIVER_ATTR(log_enabled, 0644, show_log_level, toggle_log_level);
- static struct attribute* dev_attrs[] = {
- - &dev_attr_log_enabled.attr,
- + &driver_attr_log_enabled.attr,
- NULL,
- };
- static struct attribute_group dev_attr_group = {
- diff --git a/drivers/rpmsg/imx_rpmsg.c b/drivers/rpmsg/imx_rpmsg.c
- index b84601a..041f542 100644
- --- a/drivers/rpmsg/imx_rpmsg.c
- +++ b/drivers/rpmsg/imx_rpmsg.c
- @@ -105,7 +105,7 @@ struct imx_rpmsg_vq_info {
- struct imx_rpmsg_vproc *rpdev;
- };
- -static bool logging_enabled = true;
- +static bool logging_enabled = false;
- static u64 imx_rpmsg_get_features(struct virtio_device *vdev)
- {
- @@ -551,20 +551,30 @@ static int imx_rpmsg_probe(struct platform_device *pdev)
- return ret;
- }
- -static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
- +static ssize_t show_log_level(struct device_driver * dev, char* buf)
- {
- - return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
- + return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "1 - on" : "0 - off");
- }
- -static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
- +static ssize_t toggle_log_level(struct device_driver * dev, const char* buf, size_t count)
- {
- - logging_enabled = logging_enabled ? false : true;
- - return count;
- + if(buf && count > 0)
- + {
- + if(buf[0] == '1')
- + {
- + logging_enabled = true;
- + }
- + else
- + {
- + logging_enabled = false;
- + }
- + }
- + return count;
- }
- -static DEVICE_ATTR(log_enabled, 0644, show_log_level, toggle_log_level);
- +static DRIVER_ATTR(log_enabled, 0644, show_log_level, toggle_log_level);
- static struct attribute *dev_attrs[] = {
- - &dev_attr_log_enabled.attr,
- + &driver_attr_log_enabled.attr,
- NULL,
- };
- static struct attribute_group dev_attr_group = {
- diff --git a/drivers/rpmsg/imx_rpmsg_tty.c b/drivers/rpmsg/imx_rpmsg_tty.c
- index 4503fe0..09640cc 100644
- --- a/drivers/rpmsg/imx_rpmsg_tty.c
- +++ b/drivers/rpmsg/imx_rpmsg_tty.c
- @@ -38,17 +38,27 @@ static struct rpmsgtty_port rpmsg_tty_port;
- #define RPMSG_MAX_SIZE 256
- #define MSG "hello world!"
- -static bool logging_enabled = true;
- +static bool logging_enabled = false;
- -static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
- +static ssize_t show_log_level(struct device_driver * dev, char* buf)
- {
- - return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
- + return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "1 - on" : "0 - off");
- }
- -static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
- +static ssize_t toggle_log_level(struct device_driver * dev, const char* buf, size_t count)
- {
- - logging_enabled = logging_enabled ? false : true;
- - return count;
- + if(buf && count > 0)
- + {
- + if(buf[0] == '1')
- + {
- + logging_enabled = true;
- + }
- + else
- + {
- + logging_enabled = false;
- + }
- + }
- + return count;
- }
- static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len,
- @@ -195,8 +205,9 @@ static int rpmsg_tty_probe(struct rpmsg_device *rpdev)
- if (err < 0) {
- pr_err("Couldn't install rpmsg tty driver: err %d\n", err);
- goto error;
- - } else if (logging_enabled)
- + } else if (logging_enabled) {
- pr_info("Install rpmsg tty driver!\n");
- + }
- cport->rpdev = rpdev;
- return 0;
- @@ -224,9 +235,9 @@ static void rpmsg_tty_remove(struct rpmsg_device *rpdev)
- rpmsgtty_driver = NULL;
- }
- -static DEVICE_ATTR(logging_enabled, 0644, show_log_level, toggle_log_level);
- +static DRIVER_ATTR(logging_enabled, 0644, show_log_level, toggle_log_level);
- static struct attribute* dev_attrs[] = {
- - &dev_attr_logging_enabled.attr,
- + &driver_attr_logging_enabled.attr,
- NULL,
- };
- static struct attribute_group dev_attr_group = {
- diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
- index 2a5d6cc..caa0e72 100644
- --- a/drivers/rpmsg/virtio_rpmsg_bus.c
- +++ b/drivers/rpmsg/virtio_rpmsg_bus.c
- @@ -192,17 +192,27 @@ static const struct rpmsg_endpoint_ops virtio_endpoint_ops = {
- .trysend_offchannel = virtio_rpmsg_trysend_offchannel,
- };
- -static bool logging_enabled = true;
- +static bool logging_enabled = false;
- -static ssize_t show_log_level(struct device* dev, struct device_attribute* attr, char* buf)
- +static ssize_t show_log_level(struct device_driver * dev, char* buf)
- {
- - return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "0" : "1");
- + return scnprintf(buf, PAGE_SIZE, "%s\n", logging_enabled ? "1 - on" : "0 - off");
- }
- -static ssize_t toggle_log_level(struct device* dev, struct device_attribute* attr, const char* buf, size_t count)
- +static ssize_t toggle_log_level(struct device_driver * dev, const char* buf, size_t count)
- {
- - logging_enabled = logging_enabled ? false : true;
- - return count;
- + if(buf && count > 0)
- + {
- + if(buf[0] == '1')
- + {
- + logging_enabled = true;
- + }
- + else
- + {
- + logging_enabled = false;
- + }
- + }
- + return count;
- }
- /**
- @@ -576,9 +586,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
- /* bcasting isn't allowed */
- if (src == RPMSG_ADDR_ANY || dst == RPMSG_ADDR_ANY) {
- - if (logging_enabled) {
- - dev_err(dev, "invalid addr (src 0x%x, dst 0x%x)\n", src, dst);
- - }
- + dev_err(dev, "invalid addr (src 0x%x, dst 0x%x)\n", src, dst);
- return -EINVAL;
- }
- @@ -592,9 +600,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
- * variable-length buffer sizes.
- */
- if (len > RPMSG_BUF_SIZE - sizeof(struct rpmsg_hdr)) {
- - if (logging_enabled) {
- - dev_err(dev, "message is too big (%d)\n", len);
- - }
- + dev_err(dev, "message is too big (%d)\n", len);
- return -EMSGSIZE;
- }
- @@ -623,9 +629,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
- /* timeout ? */
- if (!err) {
- - if (logging_enabled) {
- - dev_err(dev, "timeout waiting for a tx buffer\n");
- - }
- + dev_err(dev, "timeout waiting for a tx buffer\n");
- return -ERESTARTSYS;
- }
- }
- @@ -637,20 +641,18 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
- msg->reserved = 0;
- memcpy(msg->data, data, len);
- - if (logging_enabled) {
- - dev_dbg(dev, "TX From 0x%x, To 0x%x, Len %d, Flags %d, Reserved %d\n",
- - msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
- + if (logging_enabled) {
- + dev_dbg(dev, "TX From 0x%x, To 0x%x, Len %d, Flags %d, Reserved %d\n",
- + msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
- #if defined(CONFIG_DYNAMIC_DEBUG)
- - dynamic_hex_dump("rpmsg_virtio TX: ", DUMP_PREFIX_NONE, 16, 1,
- - msg, sizeof(*msg) + msg->len, true);
- + dynamic_hex_dump("rpmsg_virtio TX: ", DUMP_PREFIX_NONE, 16, 1,
- + msg, sizeof(*msg) + msg->len, true);
- #endif
- - }
- + }
- err = sg_init_one_full(&sg, msg, sizeof(*msg) + len);
- if (err) {
- - if (logging_enabled) {
- - dev_err(dev, "virtqueue_add_outbuf sg_init failed: %d\n", err);
- - }
- + dev_err(dev, "virtqueue_add_outbuf sg_init failed: %d\n", err);
- return err;
- }
- @@ -664,9 +666,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
- * (memory won't leak, but rpmsg won't use it again for TX).
- * this will wait for a buffer management overhaul.
- */
- - if (logging_enabled) {
- - dev_err(dev, "virtqueue_add_outbuf failed: %d\n", err);
- - }
- + dev_err(dev, "virtqueue_add_outbuf failed: %d\n", err);
- goto out;
- }
- @@ -735,14 +735,14 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
- struct scatterlist sg;
- int err;
- - if (logging_enabled) {
- - dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n",
- - msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
- + if (logging_enabled) {
- + dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n",
- + msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
- #if defined(CONFIG_DYNAMIC_DEBUG)
- - dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1,
- - msg, sizeof(*msg) + msg->len, true);
- + dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1,
- + msg, sizeof(*msg) + msg->len, true);
- #endif
- - }
- + }
- /*
- * We currently use fixed-sized buffers, so trivially sanitize
- @@ -750,9 +750,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
- */
- if (len > RPMSG_BUF_SIZE ||
- msg->len > (len - sizeof(struct rpmsg_hdr))) {
- - if (logging_enabled) {
- - dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len);
- - }
- + dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len);
- return -EINVAL;
- }
- @@ -779,24 +777,21 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
- /* farewell, ept, we don't need you anymore */
- kref_put(&ept->refcount, __ept_release);
- - } else if (logging_enabled)
- + } else if (logging_enabled) {
- dev_warn(dev, "msg received with no recipient\n");
- + }
- /* publish the real size of the buffer */
- err = sg_init_one_full(&sg, msg, RPMSG_BUF_SIZE);
- if (err) {
- - if (logging_enabled) {
- - dev_err(dev, "rpmsg_recv_done sg_init failed: %d\n", err);
- - }
- + dev_err(dev, "rpmsg_recv_done sg_init failed: %d\n", err);
- return err;
- }
- /* add the buffer back to the remote processor's virtqueue */
- err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL);
- if (err < 0) {
- - if (logging_enabled) {
- - dev_err(dev, "failed to add a virtqueue buffer: %d\n", err);
- - }
- + dev_err(dev, "failed to add a virtqueue buffer: %d\n", err);
- return err;
- }
- @@ -814,9 +809,7 @@ static void rpmsg_recv_done(struct virtqueue *rvq)
- msg = virtqueue_get_buf(rvq, &len);
- if (!msg) {
- - if (logging_enabled) {
- - dev_err(dev, "uhm, incoming signal, but no used buffer ?\n");
- - }
- + dev_err(dev, "uhm, incoming signal, but no used buffer ?\n");
- return;
- }
- @@ -830,9 +823,9 @@ static void rpmsg_recv_done(struct virtqueue *rvq)
- msg = virtqueue_get_buf(rvq, &len);
- }
- - if (logging_enabled) {
- - dev_dbg(dev, "Received %u messages\n", msgs_received);
- - }
- + if (logging_enabled) {
- + dev_dbg(dev, "Received %u messages\n", msgs_received);
- + }
- /* tell the remote processor we added another available rx buffer */
- if (msgs_received)
- @@ -870,16 +863,14 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
- int ret;
- #if defined(CONFIG_DYNAMIC_DEBUG)
- - if (logging_enabled) {
- - dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1,
- - data, len, true);
- - }
- + if (logging_enabled) {
- + dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1,
- + data, len, true);
- + }
- #endif
- if (len != sizeof(*msg)) {
- - if (logging_enabled) {
- - dev_err(dev, "malformed ns msg (%d)\n", len);
- - }
- + dev_err(dev, "malformed ns msg (%d)\n", len);
- return -EINVAL;
- }
- @@ -890,20 +881,18 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
- * in somehow.
- */
- if (rpdev) {
- - if (logging_enabled) {
- - dev_err(dev, "anomaly: ns ept has an rpdev handle\n");
- - }
- + dev_err(dev, "anomaly: ns ept has an rpdev handle\n");
- return -EINVAL;
- }
- /* don't trust the remote processor for null terminating the name */
- msg->name[RPMSG_NAME_SIZE - 1] = '\0';
- - if (logging_enabled) {
- - dev_info(dev, "%sing channel %s addr 0x%x\n",
- - msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat",
- - msg->name, msg->addr);
- - }
- + if (logging_enabled) {
- + dev_info(dev, "%sing channel %s addr 0x%x\n",
- + msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat",
- + msg->name, msg->addr);
- + }
- strncpy(chinfo.name, msg->name, sizeof(chinfo.name));
- chinfo.src = RPMSG_ADDR_ANY;
- @@ -911,11 +900,11 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
- if (msg->flags & RPMSG_NS_DESTROY) {
- ret = rpmsg_unregister_device(&vrp->vdev->dev, &chinfo);
- - if (ret && logging_enabled)
- + if (ret)
- dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret);
- } else {
- newch = rpmsg_create_channel(vrp, &chinfo);
- - if (!newch && logging_enabled)
- + if (!newch)
- dev_err(dev, "rpmsg_create_channel failed\n");
- }
- @@ -973,10 +962,10 @@ static int rpmsg_probe(struct virtio_device *vdev)
- goto vqs_del;
- }
- - if (logging_enabled) {
- - dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n",
- - bufs_va, &vrp->bufs_dma);
- - }
- + if (logging_enabled) {
- + dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n",
- + bufs_va, &vrp->bufs_dma);
- + }
- /* half of the buffers is dedicated for RX */
- vrp->rbufs = bufs_va;
- @@ -1034,9 +1023,9 @@ static int rpmsg_probe(struct virtio_device *vdev)
- if (notify)
- virtqueue_notify(vrp->rvq);
- - if (logging_enabled) {
- - dev_info(&vdev->dev, "rpmsg host is online\n");
- - }
- + if (logging_enabled) {
- + dev_info(&vdev->dev, "rpmsg host is online\n");
- + }
- return 0;
- @@ -1091,9 +1080,9 @@ static unsigned int features[] = {
- VIRTIO_RPMSG_F_NS,
- };
- -static DEVICE_ATTR(logging_enabled, 0644, show_log_level, toggle_log_level);
- +static DRIVER_ATTR(logging_enabled, 0644, show_log_level, toggle_log_level);
- static struct attribute* dev_attrs[] = {
- - &dev_attr_logging_enabled.attr,
- + &driver_attr_logging_enabled.attr,
- NULL,
- };
- static struct attribute_group dev_attr_group = {
- --
- 2.7.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement