diff options
author | Alexander Shishkin <alexander.shishkin@linux.intel.com> | 2018-10-05 08:42:55 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-10-11 06:12:54 -0400 |
commit | d279a38020d2483cb75f5f82f5e4ab5f73bc94f2 (patch) | |
tree | 0b7140fd53dfd22d275117be65803b3a15cf403b | |
parent | c7fd62bc69d0224877a49383e606f0fe52cba741 (diff) |
stm class: Add a helper for writing data packets
Add a helper to write a sequence of bytes as STP data packets. This
is used by protocol drivers to output their metadata, as well as the
actual data payload.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Tested-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/hwtracing/stm/core.c | 51 | ||||
-rw-r--r-- | drivers/hwtracing/stm/stm.h | 3 |
2 files changed, 41 insertions, 13 deletions
diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index 915af2541dcd..b789a5f0688e 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c | |||
@@ -569,27 +569,52 @@ stm_assign_first_policy(struct stm_device *stm, struct stm_output *output, | |||
569 | return err; | 569 | return err; |
570 | } | 570 | } |
571 | 571 | ||
572 | static ssize_t notrace stm_write(struct stm_data *data, unsigned int master, | 572 | /** |
573 | unsigned int channel, const char *buf, size_t count) | 573 | * stm_data_write() - send the given payload as data packets |
574 | * @data: stm driver's data | ||
575 | * @m: STP master | ||
576 | * @c: STP channel | ||
577 | * @ts_first: timestamp the first packet | ||
578 | * @buf: data payload buffer | ||
579 | * @count: data payload size | ||
580 | */ | ||
581 | ssize_t notrace stm_data_write(struct stm_data *data, unsigned int m, | ||
582 | unsigned int c, bool ts_first, const void *buf, | ||
583 | size_t count) | ||
574 | { | 584 | { |
575 | unsigned int flags = STP_PACKET_TIMESTAMPED; | 585 | unsigned int flags = ts_first ? STP_PACKET_TIMESTAMPED : 0; |
576 | const unsigned char *p = buf, nil = 0; | ||
577 | size_t pos; | ||
578 | ssize_t sz; | 586 | ssize_t sz; |
587 | size_t pos; | ||
579 | 588 | ||
580 | for (pos = 0, p = buf; count > pos; pos += sz, p += sz) { | 589 | for (pos = 0, sz = 0; pos < count; pos += sz) { |
581 | sz = min_t(unsigned int, count - pos, 8); | 590 | sz = min_t(unsigned int, count - pos, 8); |
582 | sz = data->packet(data, master, channel, STP_PACKET_DATA, flags, | 591 | sz = data->packet(data, m, c, STP_PACKET_DATA, flags, sz, |
583 | sz, p); | 592 | &((u8 *)buf)[pos]); |
584 | flags = 0; | 593 | if (sz <= 0) |
585 | |||
586 | if (sz < 0) | ||
587 | break; | 594 | break; |
595 | |||
596 | if (ts_first) { | ||
597 | flags = 0; | ||
598 | ts_first = false; | ||
599 | } | ||
588 | } | 600 | } |
589 | 601 | ||
590 | data->packet(data, master, channel, STP_PACKET_FLAG, 0, 0, &nil); | 602 | return sz < 0 ? sz : pos; |
603 | } | ||
604 | EXPORT_SYMBOL_GPL(stm_data_write); | ||
605 | |||
606 | static ssize_t notrace stm_write(struct stm_data *data, unsigned int master, | ||
607 | unsigned int channel, const char *buf, size_t count) | ||
608 | { | ||
609 | const unsigned char nil = 0; | ||
610 | ssize_t sz; | ||
611 | |||
612 | sz = stm_data_write(data, master, channel, true, buf, count); | ||
613 | if (sz > 0) | ||
614 | data->packet(data, master, channel, STP_PACKET_FLAG, 0, 0, | ||
615 | &nil); | ||
591 | 616 | ||
592 | return pos; | 617 | return sz; |
593 | } | 618 | } |
594 | 619 | ||
595 | static ssize_t stm_char_write(struct file *file, const char __user *buf, | 620 | static ssize_t stm_char_write(struct file *file, const char __user *buf, |
diff --git a/drivers/hwtracing/stm/stm.h b/drivers/hwtracing/stm/stm.h index ed7f3d07fa47..3569439d53bb 100644 --- a/drivers/hwtracing/stm/stm.h +++ b/drivers/hwtracing/stm/stm.h | |||
@@ -110,5 +110,8 @@ int stm_lookup_protocol(const char *name, | |||
110 | const struct stm_protocol_driver **pdrv, | 110 | const struct stm_protocol_driver **pdrv, |
111 | const struct config_item_type **type); | 111 | const struct config_item_type **type); |
112 | void stm_put_protocol(const struct stm_protocol_driver *pdrv); | 112 | void stm_put_protocol(const struct stm_protocol_driver *pdrv); |
113 | ssize_t stm_data_write(struct stm_data *data, unsigned int m, | ||
114 | unsigned int c, bool ts_first, const void *buf, | ||
115 | size_t count); | ||
113 | 116 | ||
114 | #endif /* _STM_STM_H_ */ | 117 | #endif /* _STM_STM_H_ */ |