1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
6 #include <linux/kernel.h>
7 #include <linux/init.h>
8 #include <linux/types.h>
9 #include <linux/device.h>
11 #include <linux/err.h>
12 #include <linux/export.h>
13 #include <linux/slab.h>
14 #include <linux/mutex.h>
15 #include <linux/clk.h>
16 #include <linux/coresight.h>
17 #include <linux/of_platform.h>
18 #include <linux/delay.h>
19 #include <linux/pm_runtime.h>
21 #include "coresight-priv.h"
23 static DEFINE_MUTEX(coresight_mutex);
26 * struct coresight_node - elements of a path, from source to sink
27 * @csdev: Address of an element.
28 * @link: hook to the list.
30 struct coresight_node {
31 struct coresight_device *csdev;
32 struct list_head link;
36 * When operating Coresight drivers from the sysFS interface, only a single
37 * path can exist from a tracer (associated to a CPU) to a sink.
39 static DEFINE_PER_CPU(struct list_head *, tracer_path);
42 * As of this writing only a single STM can be found in CS topologies. Since
43 * there is no way to know if we'll ever see more and what kind of
44 * configuration they will enact, for the time being only define a single path
47 static struct list_head *stm_path;
50 * When losing synchronisation a new barrier packet needs to be inserted at the
51 * beginning of the data collected in a buffer. That way the decoder knows that
52 * it needs to look for another sync sequence.
54 const u32 barrier_pkt[4] = {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff};
56 static int coresight_id_match(struct device *dev, void *data)
58 int trace_id, i_trace_id;
59 struct coresight_device *csdev, *i_csdev;
62 i_csdev = to_coresight_device(dev);
65 * No need to care about oneself and components that are not
66 * sources or not enabled
68 if (i_csdev == csdev || !i_csdev->enable ||
69 i_csdev->type != CORESIGHT_DEV_TYPE_SOURCE)
72 /* Get the source ID for both compoment */
73 trace_id = source_ops(csdev)->trace_id(csdev);
74 i_trace_id = source_ops(i_csdev)->trace_id(i_csdev);
76 /* All you need is one */
77 if (trace_id == i_trace_id)
83 static int coresight_source_is_unique(struct coresight_device *csdev)
85 int trace_id = source_ops(csdev)->trace_id(csdev);
87 /* this shouldn't happen */
91 return !bus_for_each_dev(&coresight_bustype, NULL,
92 csdev, coresight_id_match);
95 static int coresight_find_link_inport(struct coresight_device *csdev,
96 struct coresight_device *parent)
99 struct coresight_connection *conn;
101 for (i = 0; i < parent->nr_outport; i++) {
102 conn = &parent->conns[i];
103 if (conn->child_dev == csdev)
104 return conn->child_port;
107 dev_err(&csdev->dev, "couldn't find inport, parent: %s, child: %s\n",
108 dev_name(&parent->dev), dev_name(&csdev->dev));
113 static int coresight_find_link_outport(struct coresight_device *csdev,
114 struct coresight_device *child)
117 struct coresight_connection *conn;
119 for (i = 0; i < csdev->nr_outport; i++) {
120 conn = &csdev->conns[i];
121 if (conn->child_dev == child)
122 return conn->outport;
125 dev_err(&csdev->dev, "couldn't find outport, parent: %s, child: %s\n",
126 dev_name(&csdev->dev), dev_name(&child->dev));
131 static inline u32 coresight_read_claim_tags(void __iomem *base)
133 return readl_relaxed(base + CORESIGHT_CLAIMCLR);
136 static inline bool coresight_is_claimed_self_hosted(void __iomem *base)
138 return coresight_read_claim_tags(base) == CORESIGHT_CLAIM_SELF_HOSTED;
141 static inline bool coresight_is_claimed_any(void __iomem *base)
143 return coresight_read_claim_tags(base) != 0;
146 static inline void coresight_set_claim_tags(void __iomem *base)
148 writel_relaxed(CORESIGHT_CLAIM_SELF_HOSTED, base + CORESIGHT_CLAIMSET);
152 static inline void coresight_clear_claim_tags(void __iomem *base)
154 writel_relaxed(CORESIGHT_CLAIM_SELF_HOSTED, base + CORESIGHT_CLAIMCLR);
159 * coresight_claim_device_unlocked : Claim the device for self-hosted usage
160 * to prevent an external tool from touching this device. As per PSCI
161 * standards, section "Preserving the execution context" => "Debug and Trace
162 * save and Restore", DBGCLAIM[1] is reserved for Self-hosted debug/trace and
163 * DBGCLAIM[0] is reserved for external tools.
165 * Called with CS_UNLOCKed for the component.
166 * Returns : 0 on success
168 int coresight_claim_device_unlocked(void __iomem *base)
170 if (coresight_is_claimed_any(base))
173 coresight_set_claim_tags(base);
174 if (coresight_is_claimed_self_hosted(base))
176 /* There was a race setting the tags, clean up and fail */
177 coresight_clear_claim_tags(base);
181 int coresight_claim_device(void __iomem *base)
186 rc = coresight_claim_device_unlocked(base);
193 * coresight_disclaim_device_unlocked : Clear the claim tags for the device.
194 * Called with CS_UNLOCKed for the component.
196 void coresight_disclaim_device_unlocked(void __iomem *base)
199 if (coresight_is_claimed_self_hosted(base))
200 coresight_clear_claim_tags(base);
203 * The external agent may have not honoured our claim
204 * and has manipulated it. Or something else has seriously
205 * gone wrong in our driver.
210 void coresight_disclaim_device(void __iomem *base)
213 coresight_disclaim_device_unlocked(base);
217 static int coresight_enable_sink(struct coresight_device *csdev,
218 u32 mode, void *data)
223 * We need to make sure the "new" session is compatible with the
224 * existing "mode" of operation.
226 if (sink_ops(csdev)->enable) {
227 ret = sink_ops(csdev)->enable(csdev, mode, data);
230 csdev->enable = true;
233 atomic_inc(csdev->refcnt);
238 static void coresight_disable_sink(struct coresight_device *csdev)
240 if (atomic_dec_return(csdev->refcnt) == 0) {
241 if (sink_ops(csdev)->disable) {
242 sink_ops(csdev)->disable(csdev);
243 csdev->enable = false;
248 static int coresight_enable_link(struct coresight_device *csdev,
249 struct coresight_device *parent,
250 struct coresight_device *child)
254 int refport, inport, outport;
256 if (!parent || !child)
259 inport = coresight_find_link_inport(csdev, parent);
260 outport = coresight_find_link_outport(csdev, child);
261 link_subtype = csdev->subtype.link_subtype;
263 if (link_subtype == CORESIGHT_DEV_SUBTYPE_LINK_MERG)
265 else if (link_subtype == CORESIGHT_DEV_SUBTYPE_LINK_SPLIT)
273 if (atomic_inc_return(&csdev->refcnt[refport]) == 1) {
274 if (link_ops(csdev)->enable) {
275 ret = link_ops(csdev)->enable(csdev, inport, outport);
277 atomic_dec(&csdev->refcnt[refport]);
283 csdev->enable = true;
288 static void coresight_disable_link(struct coresight_device *csdev,
289 struct coresight_device *parent,
290 struct coresight_device *child)
294 int refport, inport, outport;
296 if (!parent || !child)
299 inport = coresight_find_link_inport(csdev, parent);
300 outport = coresight_find_link_outport(csdev, child);
301 link_subtype = csdev->subtype.link_subtype;
303 if (link_subtype == CORESIGHT_DEV_SUBTYPE_LINK_MERG) {
305 nr_conns = csdev->nr_inport;
306 } else if (link_subtype == CORESIGHT_DEV_SUBTYPE_LINK_SPLIT) {
308 nr_conns = csdev->nr_outport;
314 if (atomic_dec_return(&csdev->refcnt[refport]) == 0) {
315 if (link_ops(csdev)->disable)
316 link_ops(csdev)->disable(csdev, inport, outport);
319 for (i = 0; i < nr_conns; i++)
320 if (atomic_read(&csdev->refcnt[i]) != 0)
323 csdev->enable = false;
326 static int coresight_enable_source(struct coresight_device *csdev, u32 mode)
330 if (!coresight_source_is_unique(csdev)) {
331 dev_warn(&csdev->dev, "traceID %d not unique\n",
332 source_ops(csdev)->trace_id(csdev));
336 if (!csdev->enable) {
337 if (source_ops(csdev)->enable) {
338 ret = source_ops(csdev)->enable(csdev, NULL, mode);
342 csdev->enable = true;
345 atomic_inc(csdev->refcnt);
351 * coresight_disable_source - Drop the reference count by 1 and disable
352 * the device if there are no users left.
354 * @csdev - The coresight device to disable
356 * Returns true if the device has been disabled.
358 static bool coresight_disable_source(struct coresight_device *csdev)
360 if (atomic_dec_return(csdev->refcnt) == 0) {
361 if (source_ops(csdev)->disable)
362 source_ops(csdev)->disable(csdev, NULL);
363 csdev->enable = false;
365 return !csdev->enable;
369 * coresight_disable_path_from : Disable components in the given path beyond
370 * @nd in the list. If @nd is NULL, all the components, except the SOURCE are
373 static void coresight_disable_path_from(struct list_head *path,
374 struct coresight_node *nd)
377 struct coresight_device *csdev, *parent, *child;
380 nd = list_first_entry(path, struct coresight_node, link);
382 list_for_each_entry_continue(nd, path, link) {
387 * ETF devices are tricky... They can be a link or a sink,
388 * depending on how they are configured. If an ETF has been
389 * "activated" it will be configured as a sink, otherwise
390 * go ahead with the link configuration.
392 if (type == CORESIGHT_DEV_TYPE_LINKSINK)
393 type = (csdev == coresight_get_sink(path)) ?
394 CORESIGHT_DEV_TYPE_SINK :
395 CORESIGHT_DEV_TYPE_LINK;
398 case CORESIGHT_DEV_TYPE_SINK:
399 coresight_disable_sink(csdev);
401 case CORESIGHT_DEV_TYPE_SOURCE:
403 * We skip the first node in the path assuming that it
404 * is the source. So we don't expect a source device in
405 * the middle of a path.
409 case CORESIGHT_DEV_TYPE_LINK:
410 parent = list_prev_entry(nd, link)->csdev;
411 child = list_next_entry(nd, link)->csdev;
412 coresight_disable_link(csdev, parent, child);
420 void coresight_disable_path(struct list_head *path)
422 coresight_disable_path_from(path, NULL);
425 int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data)
430 struct coresight_node *nd;
431 struct coresight_device *csdev, *parent, *child;
433 list_for_each_entry_reverse(nd, path, link) {
438 * ETF devices are tricky... They can be a link or a sink,
439 * depending on how they are configured. If an ETF has been
440 * "activated" it will be configured as a sink, otherwise
441 * go ahead with the link configuration.
443 if (type == CORESIGHT_DEV_TYPE_LINKSINK)
444 type = (csdev == coresight_get_sink(path)) ?
445 CORESIGHT_DEV_TYPE_SINK :
446 CORESIGHT_DEV_TYPE_LINK;
449 case CORESIGHT_DEV_TYPE_SINK:
450 ret = coresight_enable_sink(csdev, mode, sink_data);
452 * Sink is the first component turned on. If we
453 * failed to enable the sink, there are no components
454 * that need disabling. Disabling the path here
455 * would mean we could disrupt an existing session.
460 case CORESIGHT_DEV_TYPE_SOURCE:
461 /* sources are enabled from either sysFS or Perf */
463 case CORESIGHT_DEV_TYPE_LINK:
464 parent = list_prev_entry(nd, link)->csdev;
465 child = list_next_entry(nd, link)->csdev;
466 ret = coresight_enable_link(csdev, parent, child);
478 coresight_disable_path_from(path, nd);
482 struct coresight_device *coresight_get_sink(struct list_head *path)
484 struct coresight_device *csdev;
489 csdev = list_last_entry(path, struct coresight_node, link)->csdev;
490 if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
491 csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
497 static int coresight_enabled_sink(struct device *dev, void *data)
500 struct coresight_device *csdev = to_coresight_device(dev);
502 if ((csdev->type == CORESIGHT_DEV_TYPE_SINK ||
503 csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) &&
506 * Now that we have a handle on the sink for this session,
507 * disable the sysFS "enable_sink" flag so that possible
508 * concurrent perf session that wish to use another sink don't
509 * trip on it. Doing so has no ramification for the current
513 csdev->activated = false;
522 * coresight_get_enabled_sink - returns the first enabled sink found on the bus
523 * @deactivate: Whether the 'enable_sink' flag should be reset
525 * When operated from perf the deactivate parameter should be set to 'true'.
526 * That way the "enabled_sink" flag of the sink that was selected can be reset,
527 * allowing for other concurrent perf sessions to choose a different sink.
529 * When operated from sysFS users have full control and as such the deactivate
530 * parameter should be set to 'false', hence mandating users to explicitly
533 struct coresight_device *coresight_get_enabled_sink(bool deactivate)
535 struct device *dev = NULL;
537 dev = bus_find_device(&coresight_bustype, NULL, &deactivate,
538 coresight_enabled_sink);
540 return dev ? to_coresight_device(dev) : NULL;
544 * coresight_grab_device - Power up this device and any of the helper
545 * devices connected to it for trace operation. Since the helper devices
546 * don't appear on the trace path, they should be handled along with the
549 static void coresight_grab_device(struct coresight_device *csdev)
553 for (i = 0; i < csdev->nr_outport; i++) {
554 struct coresight_device *child = csdev->conns[i].child_dev;
556 if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
557 pm_runtime_get_sync(child->dev.parent);
559 pm_runtime_get_sync(csdev->dev.parent);
563 * coresight_drop_device - Release this device and any of the helper
564 * devices connected to it.
566 static void coresight_drop_device(struct coresight_device *csdev)
570 pm_runtime_put(csdev->dev.parent);
571 for (i = 0; i < csdev->nr_outport; i++) {
572 struct coresight_device *child = csdev->conns[i].child_dev;
574 if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
575 pm_runtime_put(child->dev.parent);
580 * _coresight_build_path - recursively build a path from a @csdev to a sink.
581 * @csdev: The device to start from.
582 * @path: The list to add devices to.
584 * The tree of Coresight device is traversed until an activated sink is
585 * found. From there the sink is added to the list along with all the
586 * devices that led to that point - the end result is a list from source
587 * to sink. In that list the source is the first device and the sink the
590 static int _coresight_build_path(struct coresight_device *csdev,
591 struct coresight_device *sink,
592 struct list_head *path)
596 struct coresight_node *node;
598 /* An activated sink has been found. Enqueue the element */
602 /* Not a sink - recursively explore each port found on this element */
603 for (i = 0; i < csdev->nr_outport; i++) {
604 struct coresight_device *child_dev = csdev->conns[i].child_dev;
607 _coresight_build_path(child_dev, sink, path) == 0) {
618 * A path from this element to a sink has been found. The elements
619 * leading to the sink are already enqueued, all that is left to do
620 * is tell the PM runtime core we need this element and add a node
623 node = kzalloc(sizeof(struct coresight_node), GFP_KERNEL);
627 coresight_grab_device(csdev);
629 list_add(&node->link, path);
634 struct list_head *coresight_build_path(struct coresight_device *source,
635 struct coresight_device *sink)
637 struct list_head *path;
641 return ERR_PTR(-EINVAL);
643 path = kzalloc(sizeof(struct list_head), GFP_KERNEL);
645 return ERR_PTR(-ENOMEM);
647 INIT_LIST_HEAD(path);
649 rc = _coresight_build_path(source, sink, path);
659 * coresight_release_path - release a previously built path.
660 * @path: the path to release.
662 * Go through all the elements of a path and 1) removed it from the list and
663 * 2) free the memory allocated for each node.
665 void coresight_release_path(struct list_head *path)
667 struct coresight_device *csdev;
668 struct coresight_node *nd, *next;
670 list_for_each_entry_safe(nd, next, path, link) {
673 coresight_drop_device(csdev);
682 /** coresight_validate_source - make sure a source has the right credentials
683 * @csdev: the device structure for a source.
684 * @function: the function this was called from.
686 * Assumes the coresight_mutex is held.
688 static int coresight_validate_source(struct coresight_device *csdev,
689 const char *function)
694 subtype = csdev->subtype.source_subtype;
696 if (type != CORESIGHT_DEV_TYPE_SOURCE) {
697 dev_err(&csdev->dev, "wrong device type in %s\n", function);
701 if (subtype != CORESIGHT_DEV_SUBTYPE_SOURCE_PROC &&
702 subtype != CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE) {
703 dev_err(&csdev->dev, "wrong device subtype in %s\n", function);
710 int coresight_enable(struct coresight_device *csdev)
713 struct coresight_device *sink;
714 struct list_head *path;
715 enum coresight_dev_subtype_source subtype;
717 subtype = csdev->subtype.source_subtype;
719 mutex_lock(&coresight_mutex);
721 ret = coresight_validate_source(csdev, __func__);
727 * There could be multiple applications driving the software
728 * source. So keep the refcount for each such user when the
729 * source is already enabled.
731 if (subtype == CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE)
732 atomic_inc(csdev->refcnt);
737 * Search for a valid sink for this session but don't reset the
738 * "enable_sink" flag in sysFS. Users get to do that explicitly.
740 sink = coresight_get_enabled_sink(false);
746 path = coresight_build_path(csdev, sink);
748 pr_err("building path(s) failed\n");
753 ret = coresight_enable_path(path, CS_MODE_SYSFS, NULL);
757 ret = coresight_enable_source(csdev, CS_MODE_SYSFS);
762 case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC:
764 * When working from sysFS it is important to keep track
765 * of the paths that were created so that they can be
766 * undone in 'coresight_disable()'. Since there can only
767 * be a single session per tracer (when working from sysFS)
768 * a per-cpu variable will do just fine.
770 cpu = source_ops(csdev)->cpu_id(csdev);
771 per_cpu(tracer_path, cpu) = path;
773 case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE:
777 /* We can't be here */
782 mutex_unlock(&coresight_mutex);
786 coresight_disable_path(path);
789 coresight_release_path(path);
792 EXPORT_SYMBOL_GPL(coresight_enable);
794 void coresight_disable(struct coresight_device *csdev)
797 struct list_head *path = NULL;
799 mutex_lock(&coresight_mutex);
801 ret = coresight_validate_source(csdev, __func__);
805 if (!csdev->enable || !coresight_disable_source(csdev))
808 switch (csdev->subtype.source_subtype) {
809 case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC:
810 cpu = source_ops(csdev)->cpu_id(csdev);
811 path = per_cpu(tracer_path, cpu);
812 per_cpu(tracer_path, cpu) = NULL;
814 case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE:
819 /* We can't be here */
823 coresight_disable_path(path);
824 coresight_release_path(path);
827 mutex_unlock(&coresight_mutex);
829 EXPORT_SYMBOL_GPL(coresight_disable);
831 static ssize_t enable_sink_show(struct device *dev,
832 struct device_attribute *attr, char *buf)
834 struct coresight_device *csdev = to_coresight_device(dev);
836 return scnprintf(buf, PAGE_SIZE, "%u\n", csdev->activated);
839 static ssize_t enable_sink_store(struct device *dev,
840 struct device_attribute *attr,
841 const char *buf, size_t size)
845 struct coresight_device *csdev = to_coresight_device(dev);
847 ret = kstrtoul(buf, 10, &val);
852 csdev->activated = true;
854 csdev->activated = false;
859 static DEVICE_ATTR_RW(enable_sink);
861 static ssize_t enable_source_show(struct device *dev,
862 struct device_attribute *attr, char *buf)
864 struct coresight_device *csdev = to_coresight_device(dev);
866 return scnprintf(buf, PAGE_SIZE, "%u\n", csdev->enable);
869 static ssize_t enable_source_store(struct device *dev,
870 struct device_attribute *attr,
871 const char *buf, size_t size)
875 struct coresight_device *csdev = to_coresight_device(dev);
877 ret = kstrtoul(buf, 10, &val);
882 ret = coresight_enable(csdev);
886 coresight_disable(csdev);
891 static DEVICE_ATTR_RW(enable_source);
893 static struct attribute *coresight_sink_attrs[] = {
894 &dev_attr_enable_sink.attr,
897 ATTRIBUTE_GROUPS(coresight_sink);
899 static struct attribute *coresight_source_attrs[] = {
900 &dev_attr_enable_source.attr,
903 ATTRIBUTE_GROUPS(coresight_source);
905 static struct device_type coresight_dev_type[] = {
911 .groups = coresight_sink_groups,
918 .groups = coresight_sink_groups,
922 .groups = coresight_source_groups,
929 static void coresight_device_release(struct device *dev)
931 struct coresight_device *csdev = to_coresight_device(dev);
934 kfree(csdev->refcnt);
938 static int coresight_orphan_match(struct device *dev, void *data)
941 bool still_orphan = false;
942 struct coresight_device *csdev, *i_csdev;
943 struct coresight_connection *conn;
946 i_csdev = to_coresight_device(dev);
948 /* No need to check oneself */
949 if (csdev == i_csdev)
952 /* Move on to another component if no connection is orphan */
953 if (!i_csdev->orphan)
956 * Circle throuch all the connection of that component. If we find
957 * an orphan connection whose name matches @csdev, link it.
959 for (i = 0; i < i_csdev->nr_outport; i++) {
960 conn = &i_csdev->conns[i];
962 /* We have found at least one orphan connection */
963 if (conn->child_dev == NULL) {
964 /* Does it match this newly added device? */
965 if (conn->child_name &&
966 !strcmp(dev_name(&csdev->dev), conn->child_name)) {
967 conn->child_dev = csdev;
969 /* This component still has an orphan */
975 i_csdev->orphan = still_orphan;
978 * Returning '0' ensures that all known component on the
979 * bus will be checked.
984 static void coresight_fixup_orphan_conns(struct coresight_device *csdev)
987 * No need to check for a return value as orphan connection(s)
988 * are hooked-up with each newly added component.
990 bus_for_each_dev(&coresight_bustype, NULL,
991 csdev, coresight_orphan_match);
995 static void coresight_fixup_device_conns(struct coresight_device *csdev)
999 for (i = 0; i < csdev->nr_outport; i++) {
1000 struct coresight_connection *conn = &csdev->conns[i];
1001 struct device *dev = NULL;
1003 if (conn->child_name)
1004 dev = bus_find_device_by_name(&coresight_bustype, NULL,
1007 conn->child_dev = to_coresight_device(dev);
1008 /* and put reference from 'bus_find_device()' */
1011 csdev->orphan = true;
1012 conn->child_dev = NULL;
1017 static int coresight_remove_match(struct device *dev, void *data)
1020 struct coresight_device *csdev, *iterator;
1021 struct coresight_connection *conn;
1024 iterator = to_coresight_device(dev);
1026 /* No need to check oneself */
1027 if (csdev == iterator)
1031 * Circle throuch all the connection of that component. If we find
1032 * a connection whose name matches @csdev, remove it.
1034 for (i = 0; i < iterator->nr_outport; i++) {
1035 conn = &iterator->conns[i];
1037 if (conn->child_dev == NULL)
1040 if (!strcmp(dev_name(&csdev->dev), conn->child_name)) {
1041 iterator->orphan = true;
1042 conn->child_dev = NULL;
1043 /* No need to continue */
1049 * Returning '0' ensures that all known component on the
1050 * bus will be checked.
1055 static void coresight_remove_conns(struct coresight_device *csdev)
1057 bus_for_each_dev(&coresight_bustype, NULL,
1058 csdev, coresight_remove_match);
1062 * coresight_timeout - loop until a bit has changed to a specific state.
1063 * @addr: base address of the area of interest.
1064 * @offset: address of a register, starting from @addr.
1065 * @position: the position of the bit of interest.
1066 * @value: the value the bit should have.
1068 * Return: 0 as soon as the bit has taken the desired state or -EAGAIN if
1069 * TIMEOUT_US has elapsed, which ever happens first.
1072 int coresight_timeout(void __iomem *addr, u32 offset, int position, int value)
1077 for (i = TIMEOUT_US; i > 0; i--) {
1078 val = __raw_readl(addr + offset);
1079 /* waiting on the bit to go from 0 to 1 */
1081 if (val & BIT(position))
1083 /* waiting on the bit to go from 1 to 0 */
1085 if (!(val & BIT(position)))
1090 * Delay is arbitrary - the specification doesn't say how long
1091 * we are expected to wait. Extra check required to make sure
1092 * we don't wait needlessly on the last iteration.
1101 struct bus_type coresight_bustype = {
1102 .name = "coresight",
1105 static int __init coresight_init(void)
1107 return bus_register(&coresight_bustype);
1109 postcore_initcall(coresight_init);
1111 struct coresight_device *coresight_register(struct coresight_desc *desc)
1116 atomic_t *refcnts = NULL;
1117 struct coresight_device *csdev;
1119 csdev = kzalloc(sizeof(*csdev), GFP_KERNEL);
1125 if (desc->type == CORESIGHT_DEV_TYPE_LINK ||
1126 desc->type == CORESIGHT_DEV_TYPE_LINKSINK) {
1127 link_subtype = desc->subtype.link_subtype;
1129 if (link_subtype == CORESIGHT_DEV_SUBTYPE_LINK_MERG)
1130 nr_refcnts = desc->pdata->nr_inport;
1131 else if (link_subtype == CORESIGHT_DEV_SUBTYPE_LINK_SPLIT)
1132 nr_refcnts = desc->pdata->nr_outport;
1135 refcnts = kcalloc(nr_refcnts, sizeof(*refcnts), GFP_KERNEL);
1138 goto err_free_csdev;
1141 csdev->refcnt = refcnts;
1143 csdev->nr_inport = desc->pdata->nr_inport;
1144 csdev->nr_outport = desc->pdata->nr_outport;
1146 csdev->conns = desc->pdata->conns;
1148 csdev->type = desc->type;
1149 csdev->subtype = desc->subtype;
1150 csdev->ops = desc->ops;
1151 csdev->orphan = false;
1153 csdev->dev.type = &coresight_dev_type[desc->type];
1154 csdev->dev.groups = desc->groups;
1155 csdev->dev.parent = desc->dev;
1156 csdev->dev.release = coresight_device_release;
1157 csdev->dev.bus = &coresight_bustype;
1158 dev_set_name(&csdev->dev, "%s", desc->pdata->name);
1160 ret = device_register(&csdev->dev);
1162 put_device(&csdev->dev);
1164 * All resources are free'd explicitly via
1165 * coresight_device_release(), triggered from put_device().
1170 mutex_lock(&coresight_mutex);
1172 coresight_fixup_device_conns(csdev);
1173 coresight_fixup_orphan_conns(csdev);
1175 mutex_unlock(&coresight_mutex);
1182 return ERR_PTR(ret);
1184 EXPORT_SYMBOL_GPL(coresight_register);
1186 void coresight_unregister(struct coresight_device *csdev)
1188 /* Remove references of that device in the topology */
1189 coresight_remove_conns(csdev);
1190 device_unregister(&csdev->dev);
1192 EXPORT_SYMBOL_GPL(coresight_unregister);