xref: /linux/include/soc/tegra/bpmp.h (revision 96ac6d435100450f0565708d9b885ea2a7400e0a)
1 /*
2  * Copyright (c) 2016, NVIDIA CORPORATION.  All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  */
13 
14 #ifndef __SOC_TEGRA_BPMP_H
15 #define __SOC_TEGRA_BPMP_H
16 
17 #include <linux/mailbox_client.h>
18 #include <linux/pm_domain.h>
19 #include <linux/reset-controller.h>
20 #include <linux/semaphore.h>
21 #include <linux/types.h>
22 
23 #include <soc/tegra/bpmp-abi.h>
24 
25 struct tegra_bpmp_clk;
26 struct tegra_bpmp_ops;
27 
28 struct tegra_bpmp_soc {
29 	struct {
30 		struct {
31 			unsigned int offset;
32 			unsigned int count;
33 			unsigned int timeout;
34 		} cpu_tx, thread, cpu_rx;
35 	} channels;
36 
37 	const struct tegra_bpmp_ops *ops;
38 	unsigned int num_resets;
39 };
40 
41 struct tegra_bpmp_mb_data {
42 	u32 code;
43 	u32 flags;
44 	u8 data[MSG_DATA_MIN_SZ];
45 } __packed;
46 
47 struct tegra_bpmp_channel {
48 	struct tegra_bpmp *bpmp;
49 	struct tegra_bpmp_mb_data *ib;
50 	struct tegra_bpmp_mb_data *ob;
51 	struct completion completion;
52 	struct tegra_ivc *ivc;
53 	unsigned int index;
54 };
55 
56 typedef void (*tegra_bpmp_mrq_handler_t)(unsigned int mrq,
57 					 struct tegra_bpmp_channel *channel,
58 					 void *data);
59 
60 struct tegra_bpmp_mrq {
61 	struct list_head list;
62 	unsigned int mrq;
63 	tegra_bpmp_mrq_handler_t handler;
64 	void *data;
65 };
66 
67 struct tegra_bpmp {
68 	const struct tegra_bpmp_soc *soc;
69 	struct device *dev;
70 	void *priv;
71 
72 	struct {
73 		struct mbox_client client;
74 		struct mbox_chan *channel;
75 	} mbox;
76 
77 	spinlock_t atomic_tx_lock;
78 	struct tegra_bpmp_channel *tx_channel, *rx_channel, *threaded_channels;
79 
80 	struct {
81 		unsigned long *allocated;
82 		unsigned long *busy;
83 		unsigned int count;
84 		struct semaphore lock;
85 	} threaded;
86 
87 	struct list_head mrqs;
88 	spinlock_t lock;
89 
90 	struct tegra_bpmp_clk **clocks;
91 	unsigned int num_clocks;
92 
93 	struct reset_controller_dev rstc;
94 
95 	struct genpd_onecell_data genpd;
96 
97 #ifdef CONFIG_DEBUG_FS
98 	struct dentry *debugfs_mirror;
99 #endif
100 };
101 
102 struct tegra_bpmp_message {
103 	unsigned int mrq;
104 
105 	struct {
106 		const void *data;
107 		size_t size;
108 	} tx;
109 
110 	struct {
111 		void *data;
112 		size_t size;
113 		int ret;
114 	} rx;
115 };
116 
117 #if IS_ENABLED(CONFIG_TEGRA_BPMP)
118 struct tegra_bpmp *tegra_bpmp_get(struct device *dev);
119 void tegra_bpmp_put(struct tegra_bpmp *bpmp);
120 int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
121 			       struct tegra_bpmp_message *msg);
122 int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
123 			struct tegra_bpmp_message *msg);
124 void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel, int code,
125 			   const void *data, size_t size);
126 
127 int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
128 			   tegra_bpmp_mrq_handler_t handler, void *data);
129 void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
130 			 void *data);
131 bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp, unsigned int mrq);
132 #else
133 static inline struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
134 {
135 	return ERR_PTR(-ENOTSUPP);
136 }
137 static inline void tegra_bpmp_put(struct tegra_bpmp *bpmp)
138 {
139 }
140 static inline int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
141 					     struct tegra_bpmp_message *msg)
142 {
143 	return -ENOTSUPP;
144 }
145 static inline int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
146 				      struct tegra_bpmp_message *msg)
147 {
148 	return -ENOTSUPP;
149 }
150 static inline void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel,
151 					 int code, const void *data,
152 					 size_t size)
153 {
154 }
155 
156 static inline int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp,
157 					 unsigned int mrq,
158 					 tegra_bpmp_mrq_handler_t handler,
159 					 void *data)
160 {
161 	return -ENOTSUPP;
162 }
163 static inline void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp,
164 				       unsigned int mrq, void *data)
165 {
166 }
167 
168 static inline bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp,
169 					      unsigned int mrq)
170 {
171 	return false;
172 }
173 #endif
174 
175 void tegra_bpmp_handle_rx(struct tegra_bpmp *bpmp);
176 
177 #if IS_ENABLED(CONFIG_CLK_TEGRA_BPMP)
178 int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp);
179 #else
180 static inline int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp)
181 {
182 	return 0;
183 }
184 #endif
185 
186 #if IS_ENABLED(CONFIG_RESET_TEGRA_BPMP)
187 int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp);
188 #else
189 static inline int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
190 {
191 	return 0;
192 }
193 #endif
194 
195 #if IS_ENABLED(CONFIG_SOC_TEGRA_POWERGATE_BPMP)
196 int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp);
197 #else
198 static inline int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp)
199 {
200 	return 0;
201 }
202 #endif
203 
204 #if IS_ENABLED(CONFIG_DEBUG_FS)
205 int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp);
206 #else
207 static inline int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp)
208 {
209 	return 0;
210 }
211 #endif
212 
213 
214 #endif /* __SOC_TEGRA_BPMP_H */
215