xref: /openbmc/linux/include/soc/tegra/bpmp.h (revision b97d6790d03b763eca08847a9a5869a4291b9f9a)
12025cf9eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2983de5f9SThierry Reding /*
3983de5f9SThierry Reding  * Copyright (c) 2016, NVIDIA CORPORATION.  All rights reserved.
4983de5f9SThierry Reding  */
5983de5f9SThierry Reding 
6983de5f9SThierry Reding #ifndef __SOC_TEGRA_BPMP_H
7983de5f9SThierry Reding #define __SOC_TEGRA_BPMP_H
8983de5f9SThierry Reding 
94c1e0a97SThierry Reding #include <linux/iosys-map.h>
10983de5f9SThierry Reding #include <linux/mailbox_client.h>
11e7149a7aSThierry Reding #include <linux/pm_domain.h>
12983de5f9SThierry Reding #include <linux/reset-controller.h>
13983de5f9SThierry Reding #include <linux/semaphore.h>
14983de5f9SThierry Reding #include <linux/types.h>
15983de5f9SThierry Reding 
16983de5f9SThierry Reding #include <soc/tegra/bpmp-abi.h>
17983de5f9SThierry Reding 
18983de5f9SThierry Reding struct tegra_bpmp_clk;
19cdfa358bSTimo Alho struct tegra_bpmp_ops;
20983de5f9SThierry Reding 
21983de5f9SThierry Reding struct tegra_bpmp_soc {
22983de5f9SThierry Reding 	struct {
23983de5f9SThierry Reding 		struct {
24983de5f9SThierry Reding 			unsigned int offset;
25983de5f9SThierry Reding 			unsigned int count;
26983de5f9SThierry Reding 			unsigned int timeout;
27983de5f9SThierry Reding 		} cpu_tx, thread, cpu_rx;
28983de5f9SThierry Reding 	} channels;
29cdfa358bSTimo Alho 
30cdfa358bSTimo Alho 	const struct tegra_bpmp_ops *ops;
31983de5f9SThierry Reding 	unsigned int num_resets;
32983de5f9SThierry Reding };
33983de5f9SThierry Reding 
34983de5f9SThierry Reding struct tegra_bpmp_mb_data {
35983de5f9SThierry Reding 	u32 code;
36983de5f9SThierry Reding 	u32 flags;
37983de5f9SThierry Reding 	u8 data[MSG_DATA_MIN_SZ];
38983de5f9SThierry Reding } __packed;
39983de5f9SThierry Reding 
404c1e0a97SThierry Reding #define tegra_bpmp_mb_read(dst, mb, size) \
414c1e0a97SThierry Reding 	iosys_map_memcpy_from(dst, mb, offsetof(struct tegra_bpmp_mb_data, data), size)
424c1e0a97SThierry Reding 
434c1e0a97SThierry Reding #define tegra_bpmp_mb_write(mb, src, size) \
444c1e0a97SThierry Reding 	iosys_map_memcpy_to(mb, offsetof(struct tegra_bpmp_mb_data, data), src, size)
454c1e0a97SThierry Reding 
464c1e0a97SThierry Reding #define tegra_bpmp_mb_read_field(mb, field) \
474c1e0a97SThierry Reding 	iosys_map_rd_field(mb, 0, struct tegra_bpmp_mb_data, field)
484c1e0a97SThierry Reding 
494c1e0a97SThierry Reding #define tegra_bpmp_mb_write_field(mb, field, value) \
504c1e0a97SThierry Reding 	iosys_map_wr_field(mb, 0, struct tegra_bpmp_mb_data, field, value)
514c1e0a97SThierry Reding 
52983de5f9SThierry Reding struct tegra_bpmp_channel {
53983de5f9SThierry Reding 	struct tegra_bpmp *bpmp;
544c1e0a97SThierry Reding 	struct iosys_map ib;
554c1e0a97SThierry Reding 	struct iosys_map ob;
56983de5f9SThierry Reding 	struct completion completion;
57983de5f9SThierry Reding 	struct tegra_ivc *ivc;
58139251fcSTimo Alho 	unsigned int index;
59983de5f9SThierry Reding };
60983de5f9SThierry Reding 
61983de5f9SThierry Reding typedef void (*tegra_bpmp_mrq_handler_t)(unsigned int mrq,
62983de5f9SThierry Reding 					 struct tegra_bpmp_channel *channel,
63983de5f9SThierry Reding 					 void *data);
64983de5f9SThierry Reding 
65983de5f9SThierry Reding struct tegra_bpmp_mrq {
66983de5f9SThierry Reding 	struct list_head list;
67983de5f9SThierry Reding 	unsigned int mrq;
68983de5f9SThierry Reding 	tegra_bpmp_mrq_handler_t handler;
69983de5f9SThierry Reding 	void *data;
70983de5f9SThierry Reding };
71983de5f9SThierry Reding 
72983de5f9SThierry Reding struct tegra_bpmp {
73983de5f9SThierry Reding 	const struct tegra_bpmp_soc *soc;
74983de5f9SThierry Reding 	struct device *dev;
75cdfa358bSTimo Alho 	void *priv;
76983de5f9SThierry Reding 
77983de5f9SThierry Reding 	struct {
78983de5f9SThierry Reding 		struct mbox_client client;
79983de5f9SThierry Reding 		struct mbox_chan *channel;
80983de5f9SThierry Reding 	} mbox;
81983de5f9SThierry Reding 
821abb081eSMikko Perttunen 	spinlock_t atomic_tx_lock;
831abb081eSMikko Perttunen 	struct tegra_bpmp_channel *tx_channel, *rx_channel, *threaded_channels;
84983de5f9SThierry Reding 
85983de5f9SThierry Reding 	struct {
86983de5f9SThierry Reding 		unsigned long *allocated;
87983de5f9SThierry Reding 		unsigned long *busy;
88983de5f9SThierry Reding 		unsigned int count;
89983de5f9SThierry Reding 		struct semaphore lock;
90983de5f9SThierry Reding 	} threaded;
91983de5f9SThierry Reding 
92983de5f9SThierry Reding 	struct list_head mrqs;
93983de5f9SThierry Reding 	spinlock_t lock;
94983de5f9SThierry Reding 
95983de5f9SThierry Reding 	struct tegra_bpmp_clk **clocks;
96983de5f9SThierry Reding 	unsigned int num_clocks;
97983de5f9SThierry Reding 
98983de5f9SThierry Reding 	struct reset_controller_dev rstc;
99e7149a7aSThierry Reding 
100e7149a7aSThierry Reding 	struct genpd_onecell_data genpd;
101f2381f65STimo Alho 
102f2381f65STimo Alho #ifdef CONFIG_DEBUG_FS
103f2381f65STimo Alho 	struct dentry *debugfs_mirror;
104f2381f65STimo Alho #endif
105*9c9312fcSSumit Gupta 
106*9c9312fcSSumit Gupta 	bool suspended;
107983de5f9SThierry Reding };
108983de5f9SThierry Reding 
109*9c9312fcSSumit Gupta #define TEGRA_BPMP_MESSAGE_RESET BIT(0)
110*9c9312fcSSumit Gupta 
111983de5f9SThierry Reding struct tegra_bpmp_message {
112983de5f9SThierry Reding 	unsigned int mrq;
113983de5f9SThierry Reding 
114983de5f9SThierry Reding 	struct {
115983de5f9SThierry Reding 		const void *data;
116983de5f9SThierry Reding 		size_t size;
117983de5f9SThierry Reding 	} tx;
118983de5f9SThierry Reding 
119983de5f9SThierry Reding 	struct {
120983de5f9SThierry Reding 		void *data;
121983de5f9SThierry Reding 		size_t size;
122370d010fSTimo Alho 		int ret;
123983de5f9SThierry Reding 	} rx;
124*9c9312fcSSumit Gupta 
125*9c9312fcSSumit Gupta 	unsigned long flags;
126983de5f9SThierry Reding };
127983de5f9SThierry Reding 
12880d47a91SMikko Perttunen #if IS_ENABLED(CONFIG_TEGRA_BPMP)
12980d47a91SMikko Perttunen struct tegra_bpmp *tegra_bpmp_get(struct device *dev);
13080d47a91SMikko Perttunen void tegra_bpmp_put(struct tegra_bpmp *bpmp);
131983de5f9SThierry Reding int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
132983de5f9SThierry Reding 			       struct tegra_bpmp_message *msg);
133983de5f9SThierry Reding int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
134983de5f9SThierry Reding 			struct tegra_bpmp_message *msg);
1352e1e09edSMikko Perttunen void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel, int code,
1362e1e09edSMikko Perttunen 			   const void *data, size_t size);
137983de5f9SThierry Reding 
138983de5f9SThierry Reding int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
139983de5f9SThierry Reding 			   tegra_bpmp_mrq_handler_t handler, void *data);
140983de5f9SThierry Reding void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
141983de5f9SThierry Reding 			 void *data);
142d78b5bdeSTimo Alho bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp, unsigned int mrq);
14380d47a91SMikko Perttunen #else
tegra_bpmp_get(struct device * dev)14480d47a91SMikko Perttunen static inline struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
14580d47a91SMikko Perttunen {
14680d47a91SMikko Perttunen 	return ERR_PTR(-ENOTSUPP);
14780d47a91SMikko Perttunen }
tegra_bpmp_put(struct tegra_bpmp * bpmp)14880d47a91SMikko Perttunen static inline void tegra_bpmp_put(struct tegra_bpmp *bpmp)
14980d47a91SMikko Perttunen {
15080d47a91SMikko Perttunen }
tegra_bpmp_transfer_atomic(struct tegra_bpmp * bpmp,struct tegra_bpmp_message * msg)15180d47a91SMikko Perttunen static inline int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
15280d47a91SMikko Perttunen 					     struct tegra_bpmp_message *msg)
15380d47a91SMikko Perttunen {
15480d47a91SMikko Perttunen 	return -ENOTSUPP;
15580d47a91SMikko Perttunen }
tegra_bpmp_transfer(struct tegra_bpmp * bpmp,struct tegra_bpmp_message * msg)15680d47a91SMikko Perttunen static inline int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
15780d47a91SMikko Perttunen 				      struct tegra_bpmp_message *msg)
15880d47a91SMikko Perttunen {
15980d47a91SMikko Perttunen 	return -ENOTSUPP;
16080d47a91SMikko Perttunen }
tegra_bpmp_mrq_return(struct tegra_bpmp_channel * channel,int code,const void * data,size_t size)16180d47a91SMikko Perttunen static inline void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel,
16280d47a91SMikko Perttunen 					 int code, const void *data,
16380d47a91SMikko Perttunen 					 size_t size)
16480d47a91SMikko Perttunen {
16580d47a91SMikko Perttunen }
16680d47a91SMikko Perttunen 
tegra_bpmp_request_mrq(struct tegra_bpmp * bpmp,unsigned int mrq,tegra_bpmp_mrq_handler_t handler,void * data)16780d47a91SMikko Perttunen static inline int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp,
16880d47a91SMikko Perttunen 					 unsigned int mrq,
16980d47a91SMikko Perttunen 					 tegra_bpmp_mrq_handler_t handler,
17080d47a91SMikko Perttunen 					 void *data)
17180d47a91SMikko Perttunen {
17280d47a91SMikko Perttunen 	return -ENOTSUPP;
17380d47a91SMikko Perttunen }
tegra_bpmp_free_mrq(struct tegra_bpmp * bpmp,unsigned int mrq,void * data)17480d47a91SMikko Perttunen static inline void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp,
17580d47a91SMikko Perttunen 				       unsigned int mrq, void *data)
17680d47a91SMikko Perttunen {
17780d47a91SMikko Perttunen }
178d78b5bdeSTimo Alho 
tegra_bpmp_mrq_is_supported(struct tegra_bpmp * bpmp,unsigned int mrq)179d78b5bdeSTimo Alho static inline bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp,
180d78b5bdeSTimo Alho 					      unsigned int mrq)
181d78b5bdeSTimo Alho {
182d78b5bdeSTimo Alho 	return false;
183d78b5bdeSTimo Alho }
18480d47a91SMikko Perttunen #endif
185983de5f9SThierry Reding 
186cdfa358bSTimo Alho void tegra_bpmp_handle_rx(struct tegra_bpmp *bpmp);
187cdfa358bSTimo Alho 
188983de5f9SThierry Reding #if IS_ENABLED(CONFIG_CLK_TEGRA_BPMP)
189983de5f9SThierry Reding int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp);
190983de5f9SThierry Reding #else
tegra_bpmp_init_clocks(struct tegra_bpmp * bpmp)191983de5f9SThierry Reding static inline int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp)
192983de5f9SThierry Reding {
193983de5f9SThierry Reding 	return 0;
194983de5f9SThierry Reding }
195983de5f9SThierry Reding #endif
196983de5f9SThierry Reding 
197983de5f9SThierry Reding #if IS_ENABLED(CONFIG_RESET_TEGRA_BPMP)
198983de5f9SThierry Reding int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp);
199983de5f9SThierry Reding #else
tegra_bpmp_init_resets(struct tegra_bpmp * bpmp)200983de5f9SThierry Reding static inline int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
201983de5f9SThierry Reding {
202983de5f9SThierry Reding 	return 0;
203983de5f9SThierry Reding }
204983de5f9SThierry Reding #endif
205983de5f9SThierry Reding 
206e7149a7aSThierry Reding #if IS_ENABLED(CONFIG_SOC_TEGRA_POWERGATE_BPMP)
207e7149a7aSThierry Reding int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp);
208e7149a7aSThierry Reding #else
tegra_bpmp_init_powergates(struct tegra_bpmp * bpmp)209e7149a7aSThierry Reding static inline int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp)
210e7149a7aSThierry Reding {
211e7149a7aSThierry Reding 	return 0;
212e7149a7aSThierry Reding }
213e7149a7aSThierry Reding #endif
214e7149a7aSThierry Reding 
215f2381f65STimo Alho #if IS_ENABLED(CONFIG_DEBUG_FS)
216f2381f65STimo Alho int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp);
217f2381f65STimo Alho #else
tegra_bpmp_init_debugfs(struct tegra_bpmp * bpmp)218f2381f65STimo Alho static inline int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp)
219f2381f65STimo Alho {
220f2381f65STimo Alho 	return 0;
221f2381f65STimo Alho }
222f2381f65STimo Alho #endif
223f2381f65STimo Alho 
224f2381f65STimo Alho 
225983de5f9SThierry Reding #endif /* __SOC_TEGRA_BPMP_H */
226