drm/tidss: Fix typos
[drm/drm-misc.git] / include / soc / tegra / bpmp.h
blobf5e4ac5b8cce8961455a51d7151493d429549863
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
4 */
6 #ifndef __SOC_TEGRA_BPMP_H
7 #define __SOC_TEGRA_BPMP_H
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>
16 #include <soc/tegra/bpmp-abi.h>
18 struct tegra_bpmp_clk;
19 struct tegra_bpmp_ops;
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;
30 const struct tegra_bpmp_ops *ops;
31 unsigned int num_resets;
34 struct tegra_bpmp_mb_data {
35 u32 code;
36 u32 flags;
37 u8 data[MSG_DATA_MIN_SZ];
38 } __packed;
40 #define tegra_bpmp_mb_read(dst, mb, size) \
41 iosys_map_memcpy_from(dst, mb, offsetof(struct tegra_bpmp_mb_data, data), size)
43 #define tegra_bpmp_mb_write(mb, src, size) \
44 iosys_map_memcpy_to(mb, offsetof(struct tegra_bpmp_mb_data, data), src, size)
46 #define tegra_bpmp_mb_read_field(mb, field) \
47 iosys_map_rd_field(mb, 0, struct tegra_bpmp_mb_data, field)
49 #define tegra_bpmp_mb_write_field(mb, field, value) \
50 iosys_map_wr_field(mb, 0, struct tegra_bpmp_mb_data, field, value)
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;
61 typedef void (*tegra_bpmp_mrq_handler_t)(unsigned int mrq,
62 struct tegra_bpmp_channel *channel,
63 void *data);
65 struct tegra_bpmp_mrq {
66 struct list_head list;
67 unsigned int mrq;
68 tegra_bpmp_mrq_handler_t handler;
69 void *data;
72 struct tegra_bpmp {
73 const struct tegra_bpmp_soc *soc;
74 struct device *dev;
75 void *priv;
77 struct {
78 struct mbox_client client;
79 struct mbox_chan *channel;
80 } mbox;
82 spinlock_t atomic_tx_lock;
83 struct tegra_bpmp_channel *tx_channel, *rx_channel, *threaded_channels;
85 struct {
86 unsigned long *allocated;
87 unsigned long *busy;
88 unsigned int count;
89 struct semaphore lock;
90 } threaded;
92 struct list_head mrqs;
93 spinlock_t lock;
95 struct tegra_bpmp_clk **clocks;
96 unsigned int num_clocks;
98 struct reset_controller_dev rstc;
100 struct genpd_onecell_data genpd;
102 #ifdef CONFIG_DEBUG_FS
103 struct dentry *debugfs_mirror;
104 #endif
106 bool suspended;
109 #define TEGRA_BPMP_MESSAGE_RESET BIT(0)
111 struct tegra_bpmp_message {
112 unsigned int mrq;
114 struct {
115 const void *data;
116 size_t size;
117 } tx;
119 struct {
120 void *data;
121 size_t size;
122 int ret;
123 } rx;
125 unsigned long flags;
128 #if IS_ENABLED(CONFIG_TEGRA_BPMP)
129 struct tegra_bpmp *tegra_bpmp_get(struct device *dev);
130 void tegra_bpmp_put(struct tegra_bpmp *bpmp);
131 int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
132 struct tegra_bpmp_message *msg);
133 int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
134 struct tegra_bpmp_message *msg);
135 void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel, int code,
136 const void *data, size_t size);
138 int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
139 tegra_bpmp_mrq_handler_t handler, void *data);
140 void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
141 void *data);
142 bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp, unsigned int mrq);
143 #else
144 static inline struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
146 return ERR_PTR(-ENOTSUPP);
148 static inline void tegra_bpmp_put(struct tegra_bpmp *bpmp)
151 static inline int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
152 struct tegra_bpmp_message *msg)
154 return -ENOTSUPP;
156 static inline int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
157 struct tegra_bpmp_message *msg)
159 return -ENOTSUPP;
161 static inline void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel,
162 int code, const void *data,
163 size_t size)
167 static inline int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp,
168 unsigned int mrq,
169 tegra_bpmp_mrq_handler_t handler,
170 void *data)
172 return -ENOTSUPP;
174 static inline void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp,
175 unsigned int mrq, void *data)
179 static inline bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp,
180 unsigned int mrq)
182 return false;
184 #endif
186 void tegra_bpmp_handle_rx(struct tegra_bpmp *bpmp);
188 #if IS_ENABLED(CONFIG_CLK_TEGRA_BPMP)
189 int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp);
190 #else
191 static inline int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp)
193 return 0;
195 #endif
197 #if IS_ENABLED(CONFIG_RESET_TEGRA_BPMP)
198 int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp);
199 #else
200 static inline int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
202 return 0;
204 #endif
206 #if IS_ENABLED(CONFIG_SOC_TEGRA_POWERGATE_BPMP)
207 int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp);
208 #else
209 static inline int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp)
211 return 0;
213 #endif
215 #if IS_ENABLED(CONFIG_DEBUG_FS)
216 int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp);
217 #else
218 static inline int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp)
220 return 0;
222 #endif
225 #endif /* __SOC_TEGRA_BPMP_H */