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