stm class: Fix link list locking
[cascardo/linux.git] / drivers / hwtracing / stm / stm.h
1 /*
2  * System Trace Module (STM) infrastructure
3  * Copyright (c) 2014, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * STM class implements generic infrastructure for  System Trace Module devices
15  * as defined in MIPI STPv2 specification.
16  */
17
18 #ifndef _STM_STM_H_
19 #define _STM_STM_H_
20
21 struct stp_policy;
22 struct stp_policy_node;
23
24 struct stp_policy_node *
25 stp_policy_node_lookup(struct stm_device *stm, char *s);
26 void stp_policy_node_put(struct stp_policy_node *policy_node);
27 void stp_policy_unbind(struct stp_policy *policy);
28
29 void stp_policy_node_get_ranges(struct stp_policy_node *policy_node,
30                                 unsigned int *mstart, unsigned int *mend,
31                                 unsigned int *cstart, unsigned int *cend);
32 int stp_configfs_init(void);
33 void stp_configfs_exit(void);
34
35 struct stp_master {
36         unsigned int    nr_free;
37         unsigned long   chan_map[0];
38 };
39
40 struct stm_device {
41         struct device           dev;
42         struct module           *owner;
43         struct stp_policy       *policy;
44         struct mutex            policy_mutex;
45         int                     major;
46         unsigned int            sw_nmasters;
47         struct stm_data         *data;
48         struct mutex            link_mutex;
49         spinlock_t              link_lock;
50         struct list_head        link_list;
51         /* master allocation */
52         spinlock_t              mc_lock;
53         struct stp_master       *masters[0];
54 };
55
56 #define to_stm_device(_d)                               \
57         container_of((_d), struct stm_device, dev)
58
59 struct stm_output {
60         unsigned int            master;
61         unsigned int            channel;
62         unsigned int            nr_chans;
63 };
64
65 struct stm_file {
66         struct stm_device       *stm;
67         struct stp_policy_node  *policy_node;
68         struct stm_output       output;
69 };
70
71 struct stm_device *stm_find_device(const char *name);
72 void stm_put_device(struct stm_device *stm);
73
74 struct stm_source_device {
75         struct device           dev;
76         struct stm_source_data  *data;
77         spinlock_t              link_lock;
78         struct stm_device __rcu *link;
79         struct list_head        link_entry;
80         /* one output per stm_source device */
81         struct stp_policy_node  *policy_node;
82         struct stm_output       output;
83 };
84
85 #define to_stm_source_device(_d)                                \
86         container_of((_d), struct stm_source_device, dev)
87
88 #endif /* _STM_STM_H_ */