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
[5] = {0x7fffffff, 0x7fffffff,
55 0x7fffffff, 0x7fffffff, 0x0};
57 static int coresight_id_match(struct device
*dev
, void *data
)
59 int trace_id
, i_trace_id
;
60 struct coresight_device
*csdev
, *i_csdev
;
63 i_csdev
= to_coresight_device(dev
);
66 * No need to care about oneself and components that are not
67 * sources or not enabled
69 if (i_csdev
== csdev
|| !i_csdev
->enable
||
70 i_csdev
->type
!= CORESIGHT_DEV_TYPE_SOURCE
)
73 /* Get the source ID for both compoment */
74 trace_id
= source_ops(csdev
)->trace_id(csdev
);
75 i_trace_id
= source_ops(i_csdev
)->trace_id(i_csdev
);
77 /* All you need is one */
78 if (trace_id
== i_trace_id
)
84 static int coresight_source_is_unique(struct coresight_device
*csdev
)
86 int trace_id
= source_ops(csdev
)->trace_id(csdev
);
88 /* this shouldn't happen */
92 return !bus_for_each_dev(&coresight_bustype
, NULL
,
93 csdev
, coresight_id_match
);
96 static int coresight_find_link_inport(struct coresight_device
*csdev
,
97 struct coresight_device
*parent
)
100 struct coresight_connection
*conn
;
102 for (i
= 0; i
< parent
->nr_outport
; i
++) {
103 conn
= &parent
->conns
[i
];
104 if (conn
->child_dev
== csdev
)
105 return conn
->child_port
;
108 dev_err(&csdev
->dev
, "couldn't find inport, parent: %s, child: %s\n",
109 dev_name(&parent
->dev
), dev_name(&csdev
->dev
));
114 static int coresight_find_link_outport(struct coresight_device
*csdev
,
115 struct coresight_device
*child
)
118 struct coresight_connection
*conn
;
120 for (i
= 0; i
< csdev
->nr_outport
; i
++) {
121 conn
= &csdev
->conns
[i
];
122 if (conn
->child_dev
== child
)
123 return conn
->outport
;
126 dev_err(&csdev
->dev
, "couldn't find outport, parent: %s, child: %s\n",
127 dev_name(&csdev
->dev
), dev_name(&child
->dev
));
132 static int coresight_enable_sink(struct coresight_device
*csdev
, u32 mode
)
136 if (!csdev
->enable
) {
137 if (sink_ops(csdev
)->enable
) {
138 ret
= sink_ops(csdev
)->enable(csdev
, mode
);
142 csdev
->enable
= true;
145 atomic_inc(csdev
->refcnt
);
150 static void coresight_disable_sink(struct coresight_device
*csdev
)
152 if (atomic_dec_return(csdev
->refcnt
) == 0) {
153 if (sink_ops(csdev
)->disable
) {
154 sink_ops(csdev
)->disable(csdev
);
155 csdev
->enable
= false;
160 static int coresight_enable_link(struct coresight_device
*csdev
,
161 struct coresight_device
*parent
,
162 struct coresight_device
*child
)
166 int refport
, inport
, outport
;
168 if (!parent
|| !child
)
171 inport
= coresight_find_link_inport(csdev
, parent
);
172 outport
= coresight_find_link_outport(csdev
, child
);
173 link_subtype
= csdev
->subtype
.link_subtype
;
175 if (link_subtype
== CORESIGHT_DEV_SUBTYPE_LINK_MERG
)
177 else if (link_subtype
== CORESIGHT_DEV_SUBTYPE_LINK_SPLIT
)
185 if (atomic_inc_return(&csdev
->refcnt
[refport
]) == 1) {
186 if (link_ops(csdev
)->enable
) {
187 ret
= link_ops(csdev
)->enable(csdev
, inport
, outport
);
193 csdev
->enable
= true;
198 static void coresight_disable_link(struct coresight_device
*csdev
,
199 struct coresight_device
*parent
,
200 struct coresight_device
*child
)
204 int refport
, inport
, outport
;
206 if (!parent
|| !child
)
209 inport
= coresight_find_link_inport(csdev
, parent
);
210 outport
= coresight_find_link_outport(csdev
, child
);
211 link_subtype
= csdev
->subtype
.link_subtype
;
213 if (link_subtype
== CORESIGHT_DEV_SUBTYPE_LINK_MERG
) {
215 nr_conns
= csdev
->nr_inport
;
216 } else if (link_subtype
== CORESIGHT_DEV_SUBTYPE_LINK_SPLIT
) {
218 nr_conns
= csdev
->nr_outport
;
224 if (atomic_dec_return(&csdev
->refcnt
[refport
]) == 0) {
225 if (link_ops(csdev
)->disable
)
226 link_ops(csdev
)->disable(csdev
, inport
, outport
);
229 for (i
= 0; i
< nr_conns
; i
++)
230 if (atomic_read(&csdev
->refcnt
[i
]) != 0)
233 csdev
->enable
= false;
236 static int coresight_enable_source(struct coresight_device
*csdev
, u32 mode
)
240 if (!coresight_source_is_unique(csdev
)) {
241 dev_warn(&csdev
->dev
, "traceID %d not unique\n",
242 source_ops(csdev
)->trace_id(csdev
));
246 if (!csdev
->enable
) {
247 if (source_ops(csdev
)->enable
) {
248 ret
= source_ops(csdev
)->enable(csdev
, NULL
, mode
);
252 csdev
->enable
= true;
255 atomic_inc(csdev
->refcnt
);
261 * coresight_disable_source - Drop the reference count by 1 and disable
262 * the device if there are no users left.
264 * @csdev - The coresight device to disable
266 * Returns true if the device has been disabled.
268 static bool coresight_disable_source(struct coresight_device
*csdev
)
270 if (atomic_dec_return(csdev
->refcnt
) == 0) {
271 if (source_ops(csdev
)->disable
)
272 source_ops(csdev
)->disable(csdev
, NULL
);
273 csdev
->enable
= false;
275 return !csdev
->enable
;
278 void coresight_disable_path(struct list_head
*path
)
281 struct coresight_node
*nd
;
282 struct coresight_device
*csdev
, *parent
, *child
;
284 list_for_each_entry(nd
, path
, link
) {
289 * ETF devices are tricky... They can be a link or a sink,
290 * depending on how they are configured. If an ETF has been
291 * "activated" it will be configured as a sink, otherwise
292 * go ahead with the link configuration.
294 if (type
== CORESIGHT_DEV_TYPE_LINKSINK
)
295 type
= (csdev
== coresight_get_sink(path
)) ?
296 CORESIGHT_DEV_TYPE_SINK
:
297 CORESIGHT_DEV_TYPE_LINK
;
300 case CORESIGHT_DEV_TYPE_SINK
:
301 coresight_disable_sink(csdev
);
303 case CORESIGHT_DEV_TYPE_SOURCE
:
304 /* sources are disabled from either sysFS or Perf */
306 case CORESIGHT_DEV_TYPE_LINK
:
307 parent
= list_prev_entry(nd
, link
)->csdev
;
308 child
= list_next_entry(nd
, link
)->csdev
;
309 coresight_disable_link(csdev
, parent
, child
);
317 int coresight_enable_path(struct list_head
*path
, u32 mode
)
322 struct coresight_node
*nd
;
323 struct coresight_device
*csdev
, *parent
, *child
;
325 list_for_each_entry_reverse(nd
, path
, link
) {
330 * ETF devices are tricky... They can be a link or a sink,
331 * depending on how they are configured. If an ETF has been
332 * "activated" it will be configured as a sink, otherwise
333 * go ahead with the link configuration.
335 if (type
== CORESIGHT_DEV_TYPE_LINKSINK
)
336 type
= (csdev
== coresight_get_sink(path
)) ?
337 CORESIGHT_DEV_TYPE_SINK
:
338 CORESIGHT_DEV_TYPE_LINK
;
341 case CORESIGHT_DEV_TYPE_SINK
:
342 ret
= coresight_enable_sink(csdev
, mode
);
346 case CORESIGHT_DEV_TYPE_SOURCE
:
347 /* sources are enabled from either sysFS or Perf */
349 case CORESIGHT_DEV_TYPE_LINK
:
350 parent
= list_prev_entry(nd
, link
)->csdev
;
351 child
= list_next_entry(nd
, link
)->csdev
;
352 ret
= coresight_enable_link(csdev
, parent
, child
);
364 coresight_disable_path(path
);
368 struct coresight_device
*coresight_get_sink(struct list_head
*path
)
370 struct coresight_device
*csdev
;
375 csdev
= list_last_entry(path
, struct coresight_node
, link
)->csdev
;
376 if (csdev
->type
!= CORESIGHT_DEV_TYPE_SINK
&&
377 csdev
->type
!= CORESIGHT_DEV_TYPE_LINKSINK
)
383 static int coresight_enabled_sink(struct device
*dev
, void *data
)
386 struct coresight_device
*csdev
= to_coresight_device(dev
);
388 if ((csdev
->type
== CORESIGHT_DEV_TYPE_SINK
||
389 csdev
->type
== CORESIGHT_DEV_TYPE_LINKSINK
) &&
392 * Now that we have a handle on the sink for this session,
393 * disable the sysFS "enable_sink" flag so that possible
394 * concurrent perf session that wish to use another sink don't
395 * trip on it. Doing so has no ramification for the current
399 csdev
->activated
= false;
408 * coresight_get_enabled_sink - returns the first enabled sink found on the bus
409 * @deactivate: Whether the 'enable_sink' flag should be reset
411 * When operated from perf the deactivate parameter should be set to 'true'.
412 * That way the "enabled_sink" flag of the sink that was selected can be reset,
413 * allowing for other concurrent perf sessions to choose a different sink.
415 * When operated from sysFS users have full control and as such the deactivate
416 * parameter should be set to 'false', hence mandating users to explicitly
419 struct coresight_device
*coresight_get_enabled_sink(bool deactivate
)
421 struct device
*dev
= NULL
;
423 dev
= bus_find_device(&coresight_bustype
, NULL
, &deactivate
,
424 coresight_enabled_sink
);
426 return dev
? to_coresight_device(dev
) : NULL
;
430 * _coresight_build_path - recursively build a path from a @csdev to a sink.
431 * @csdev: The device to start from.
432 * @path: The list to add devices to.
434 * The tree of Coresight device is traversed until an activated sink is
435 * found. From there the sink is added to the list along with all the
436 * devices that led to that point - the end result is a list from source
437 * to sink. In that list the source is the first device and the sink the
440 static int _coresight_build_path(struct coresight_device
*csdev
,
441 struct coresight_device
*sink
,
442 struct list_head
*path
)
446 struct coresight_node
*node
;
448 /* An activated sink has been found. Enqueue the element */
452 /* Not a sink - recursively explore each port found on this element */
453 for (i
= 0; i
< csdev
->nr_outport
; i
++) {
454 struct coresight_device
*child_dev
= csdev
->conns
[i
].child_dev
;
457 _coresight_build_path(child_dev
, sink
, path
) == 0) {
468 * A path from this element to a sink has been found. The elements
469 * leading to the sink are already enqueued, all that is left to do
470 * is tell the PM runtime core we need this element and add a node
473 node
= kzalloc(sizeof(struct coresight_node
), GFP_KERNEL
);
478 list_add(&node
->link
, path
);
479 pm_runtime_get_sync(csdev
->dev
.parent
);
484 struct list_head
*coresight_build_path(struct coresight_device
*source
,
485 struct coresight_device
*sink
)
487 struct list_head
*path
;
491 return ERR_PTR(-EINVAL
);
493 path
= kzalloc(sizeof(struct list_head
), GFP_KERNEL
);
495 return ERR_PTR(-ENOMEM
);
497 INIT_LIST_HEAD(path
);
499 rc
= _coresight_build_path(source
, sink
, path
);
509 * coresight_release_path - release a previously built path.
510 * @path: the path to release.
512 * Go through all the elements of a path and 1) removed it from the list and
513 * 2) free the memory allocated for each node.
515 void coresight_release_path(struct list_head
*path
)
517 struct coresight_device
*csdev
;
518 struct coresight_node
*nd
, *next
;
520 list_for_each_entry_safe(nd
, next
, path
, link
) {
523 pm_runtime_put_sync(csdev
->dev
.parent
);
532 /** coresight_validate_source - make sure a source has the right credentials
533 * @csdev: the device structure for a source.
534 * @function: the function this was called from.
536 * Assumes the coresight_mutex is held.
538 static int coresight_validate_source(struct coresight_device
*csdev
,
539 const char *function
)
544 subtype
= csdev
->subtype
.source_subtype
;
546 if (type
!= CORESIGHT_DEV_TYPE_SOURCE
) {
547 dev_err(&csdev
->dev
, "wrong device type in %s\n", function
);
551 if (subtype
!= CORESIGHT_DEV_SUBTYPE_SOURCE_PROC
&&
552 subtype
!= CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE
) {
553 dev_err(&csdev
->dev
, "wrong device subtype in %s\n", function
);
560 int coresight_enable(struct coresight_device
*csdev
)
563 struct coresight_device
*sink
;
564 struct list_head
*path
;
565 enum coresight_dev_subtype_source subtype
;
567 subtype
= csdev
->subtype
.source_subtype
;
569 mutex_lock(&coresight_mutex
);
571 ret
= coresight_validate_source(csdev
, __func__
);
577 * There could be multiple applications driving the software
578 * source. So keep the refcount for each such user when the
579 * source is already enabled.
581 if (subtype
== CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE
)
582 atomic_inc(csdev
->refcnt
);
587 * Search for a valid sink for this session but don't reset the
588 * "enable_sink" flag in sysFS. Users get to do that explicitly.
590 sink
= coresight_get_enabled_sink(false);
596 path
= coresight_build_path(csdev
, sink
);
598 pr_err("building path(s) failed\n");
603 ret
= coresight_enable_path(path
, CS_MODE_SYSFS
);
607 ret
= coresight_enable_source(csdev
, CS_MODE_SYSFS
);
612 case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC
:
614 * When working from sysFS it is important to keep track
615 * of the paths that were created so that they can be
616 * undone in 'coresight_disable()'. Since there can only
617 * be a single session per tracer (when working from sysFS)
618 * a per-cpu variable will do just fine.
620 cpu
= source_ops(csdev
)->cpu_id(csdev
);
621 per_cpu(tracer_path
, cpu
) = path
;
623 case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE
:
627 /* We can't be here */
632 mutex_unlock(&coresight_mutex
);
636 coresight_disable_path(path
);
639 coresight_release_path(path
);
642 EXPORT_SYMBOL_GPL(coresight_enable
);
644 void coresight_disable(struct coresight_device
*csdev
)
647 struct list_head
*path
= NULL
;
649 mutex_lock(&coresight_mutex
);
651 ret
= coresight_validate_source(csdev
, __func__
);
655 if (!csdev
->enable
|| !coresight_disable_source(csdev
))
658 switch (csdev
->subtype
.source_subtype
) {
659 case CORESIGHT_DEV_SUBTYPE_SOURCE_PROC
:
660 cpu
= source_ops(csdev
)->cpu_id(csdev
);
661 path
= per_cpu(tracer_path
, cpu
);
662 per_cpu(tracer_path
, cpu
) = NULL
;
664 case CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE
:
669 /* We can't be here */
673 coresight_disable_path(path
);
674 coresight_release_path(path
);
677 mutex_unlock(&coresight_mutex
);
679 EXPORT_SYMBOL_GPL(coresight_disable
);
681 static ssize_t
enable_sink_show(struct device
*dev
,
682 struct device_attribute
*attr
, char *buf
)
684 struct coresight_device
*csdev
= to_coresight_device(dev
);
686 return scnprintf(buf
, PAGE_SIZE
, "%u\n", csdev
->activated
);
689 static ssize_t
enable_sink_store(struct device
*dev
,
690 struct device_attribute
*attr
,
691 const char *buf
, size_t size
)
695 struct coresight_device
*csdev
= to_coresight_device(dev
);
697 ret
= kstrtoul(buf
, 10, &val
);
702 csdev
->activated
= true;
704 csdev
->activated
= false;
709 static DEVICE_ATTR_RW(enable_sink
);
711 static ssize_t
enable_source_show(struct device
*dev
,
712 struct device_attribute
*attr
, char *buf
)
714 struct coresight_device
*csdev
= to_coresight_device(dev
);
716 return scnprintf(buf
, PAGE_SIZE
, "%u\n", csdev
->enable
);
719 static ssize_t
enable_source_store(struct device
*dev
,
720 struct device_attribute
*attr
,
721 const char *buf
, size_t size
)
725 struct coresight_device
*csdev
= to_coresight_device(dev
);
727 ret
= kstrtoul(buf
, 10, &val
);
732 ret
= coresight_enable(csdev
);
736 coresight_disable(csdev
);
741 static DEVICE_ATTR_RW(enable_source
);
743 static struct attribute
*coresight_sink_attrs
[] = {
744 &dev_attr_enable_sink
.attr
,
747 ATTRIBUTE_GROUPS(coresight_sink
);
749 static struct attribute
*coresight_source_attrs
[] = {
750 &dev_attr_enable_source
.attr
,
753 ATTRIBUTE_GROUPS(coresight_source
);
755 static struct device_type coresight_dev_type
[] = {
761 .groups
= coresight_sink_groups
,
768 .groups
= coresight_sink_groups
,
772 .groups
= coresight_source_groups
,
776 static void coresight_device_release(struct device
*dev
)
778 struct coresight_device
*csdev
= to_coresight_device(dev
);
781 kfree(csdev
->refcnt
);
785 static int coresight_orphan_match(struct device
*dev
, void *data
)
788 bool still_orphan
= false;
789 struct coresight_device
*csdev
, *i_csdev
;
790 struct coresight_connection
*conn
;
793 i_csdev
= to_coresight_device(dev
);
795 /* No need to check oneself */
796 if (csdev
== i_csdev
)
799 /* Move on to another component if no connection is orphan */
800 if (!i_csdev
->orphan
)
803 * Circle throuch all the connection of that component. If we find
804 * an orphan connection whose name matches @csdev, link it.
806 for (i
= 0; i
< i_csdev
->nr_outport
; i
++) {
807 conn
= &i_csdev
->conns
[i
];
809 /* We have found at least one orphan connection */
810 if (conn
->child_dev
== NULL
) {
811 /* Does it match this newly added device? */
812 if (conn
->child_name
&&
813 !strcmp(dev_name(&csdev
->dev
), conn
->child_name
)) {
814 conn
->child_dev
= csdev
;
816 /* This component still has an orphan */
822 i_csdev
->orphan
= still_orphan
;
825 * Returning '0' ensures that all known component on the
826 * bus will be checked.
831 static void coresight_fixup_orphan_conns(struct coresight_device
*csdev
)
834 * No need to check for a return value as orphan connection(s)
835 * are hooked-up with each newly added component.
837 bus_for_each_dev(&coresight_bustype
, NULL
,
838 csdev
, coresight_orphan_match
);
842 static void coresight_fixup_device_conns(struct coresight_device
*csdev
)
846 for (i
= 0; i
< csdev
->nr_outport
; i
++) {
847 struct coresight_connection
*conn
= &csdev
->conns
[i
];
848 struct device
*dev
= NULL
;
850 if (conn
->child_name
)
851 dev
= bus_find_device_by_name(&coresight_bustype
, NULL
,
854 conn
->child_dev
= to_coresight_device(dev
);
855 /* and put reference from 'bus_find_device()' */
858 csdev
->orphan
= true;
859 conn
->child_dev
= NULL
;
864 static int coresight_remove_match(struct device
*dev
, void *data
)
867 struct coresight_device
*csdev
, *iterator
;
868 struct coresight_connection
*conn
;
871 iterator
= to_coresight_device(dev
);
873 /* No need to check oneself */
874 if (csdev
== iterator
)
878 * Circle throuch all the connection of that component. If we find
879 * a connection whose name matches @csdev, remove it.
881 for (i
= 0; i
< iterator
->nr_outport
; i
++) {
882 conn
= &iterator
->conns
[i
];
884 if (conn
->child_dev
== NULL
)
887 if (!strcmp(dev_name(&csdev
->dev
), conn
->child_name
)) {
888 iterator
->orphan
= true;
889 conn
->child_dev
= NULL
;
890 /* No need to continue */
896 * Returning '0' ensures that all known component on the
897 * bus will be checked.
902 static void coresight_remove_conns(struct coresight_device
*csdev
)
904 bus_for_each_dev(&coresight_bustype
, NULL
,
905 csdev
, coresight_remove_match
);
909 * coresight_timeout - loop until a bit has changed to a specific state.
910 * @addr: base address of the area of interest.
911 * @offset: address of a register, starting from @addr.
912 * @position: the position of the bit of interest.
913 * @value: the value the bit should have.
915 * Return: 0 as soon as the bit has taken the desired state or -EAGAIN if
916 * TIMEOUT_US has elapsed, which ever happens first.
919 int coresight_timeout(void __iomem
*addr
, u32 offset
, int position
, int value
)
924 for (i
= TIMEOUT_US
; i
> 0; i
--) {
925 val
= __raw_readl(addr
+ offset
);
926 /* waiting on the bit to go from 0 to 1 */
928 if (val
& BIT(position
))
930 /* waiting on the bit to go from 1 to 0 */
932 if (!(val
& BIT(position
)))
937 * Delay is arbitrary - the specification doesn't say how long
938 * we are expected to wait. Extra check required to make sure
939 * we don't wait needlessly on the last iteration.
948 struct bus_type coresight_bustype
= {
952 static int __init
coresight_init(void)
954 return bus_register(&coresight_bustype
);
956 postcore_initcall(coresight_init
);
958 struct coresight_device
*coresight_register(struct coresight_desc
*desc
)
964 atomic_t
*refcnts
= NULL
;
965 struct coresight_device
*csdev
;
966 struct coresight_connection
*conns
= NULL
;
968 csdev
= kzalloc(sizeof(*csdev
), GFP_KERNEL
);
971 goto err_kzalloc_csdev
;
974 if (desc
->type
== CORESIGHT_DEV_TYPE_LINK
||
975 desc
->type
== CORESIGHT_DEV_TYPE_LINKSINK
) {
976 link_subtype
= desc
->subtype
.link_subtype
;
978 if (link_subtype
== CORESIGHT_DEV_SUBTYPE_LINK_MERG
)
979 nr_refcnts
= desc
->pdata
->nr_inport
;
980 else if (link_subtype
== CORESIGHT_DEV_SUBTYPE_LINK_SPLIT
)
981 nr_refcnts
= desc
->pdata
->nr_outport
;
984 refcnts
= kcalloc(nr_refcnts
, sizeof(*refcnts
), GFP_KERNEL
);
987 goto err_kzalloc_refcnts
;
990 csdev
->refcnt
= refcnts
;
992 csdev
->nr_inport
= desc
->pdata
->nr_inport
;
993 csdev
->nr_outport
= desc
->pdata
->nr_outport
;
995 /* Initialise connections if there is at least one outport */
996 if (csdev
->nr_outport
) {
997 conns
= kcalloc(csdev
->nr_outport
, sizeof(*conns
), GFP_KERNEL
);
1000 goto err_kzalloc_conns
;
1003 for (i
= 0; i
< csdev
->nr_outport
; i
++) {
1004 conns
[i
].outport
= desc
->pdata
->outports
[i
];
1005 conns
[i
].child_name
= desc
->pdata
->child_names
[i
];
1006 conns
[i
].child_port
= desc
->pdata
->child_ports
[i
];
1010 csdev
->conns
= conns
;
1012 csdev
->type
= desc
->type
;
1013 csdev
->subtype
= desc
->subtype
;
1014 csdev
->ops
= desc
->ops
;
1015 csdev
->orphan
= false;
1017 csdev
->dev
.type
= &coresight_dev_type
[desc
->type
];
1018 csdev
->dev
.groups
= desc
->groups
;
1019 csdev
->dev
.parent
= desc
->dev
;
1020 csdev
->dev
.release
= coresight_device_release
;
1021 csdev
->dev
.bus
= &coresight_bustype
;
1022 dev_set_name(&csdev
->dev
, "%s", desc
->pdata
->name
);
1024 ret
= device_register(&csdev
->dev
);
1026 put_device(&csdev
->dev
);
1027 goto err_kzalloc_csdev
;
1030 mutex_lock(&coresight_mutex
);
1032 coresight_fixup_device_conns(csdev
);
1033 coresight_fixup_orphan_conns(csdev
);
1035 mutex_unlock(&coresight_mutex
);
1041 err_kzalloc_refcnts
:
1044 return ERR_PTR(ret
);
1046 EXPORT_SYMBOL_GPL(coresight_register
);
1048 void coresight_unregister(struct coresight_device
*csdev
)
1050 /* Remove references of that device in the topology */
1051 coresight_remove_conns(csdev
);
1052 device_unregister(&csdev
->dev
);
1054 EXPORT_SYMBOL_GPL(coresight_unregister
);