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