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