Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2016, NVIDIA CORPORATION.  All rights reserved.
0004  */
0005 
0006 #ifndef __SOC_TEGRA_BPMP_H
0007 #define __SOC_TEGRA_BPMP_H
0008 
0009 #include <linux/mailbox_client.h>
0010 #include <linux/pm_domain.h>
0011 #include <linux/reset-controller.h>
0012 #include <linux/semaphore.h>
0013 #include <linux/types.h>
0014 
0015 #include <soc/tegra/bpmp-abi.h>
0016 
0017 struct tegra_bpmp_clk;
0018 struct tegra_bpmp_ops;
0019 
0020 struct tegra_bpmp_soc {
0021     struct {
0022         struct {
0023             unsigned int offset;
0024             unsigned int count;
0025             unsigned int timeout;
0026         } cpu_tx, thread, cpu_rx;
0027     } channels;
0028 
0029     const struct tegra_bpmp_ops *ops;
0030     unsigned int num_resets;
0031 };
0032 
0033 struct tegra_bpmp_mb_data {
0034     u32 code;
0035     u32 flags;
0036     u8 data[MSG_DATA_MIN_SZ];
0037 } __packed;
0038 
0039 struct tegra_bpmp_channel {
0040     struct tegra_bpmp *bpmp;
0041     struct tegra_bpmp_mb_data *ib;
0042     struct tegra_bpmp_mb_data *ob;
0043     struct completion completion;
0044     struct tegra_ivc *ivc;
0045     unsigned int index;
0046 };
0047 
0048 typedef void (*tegra_bpmp_mrq_handler_t)(unsigned int mrq,
0049                      struct tegra_bpmp_channel *channel,
0050                      void *data);
0051 
0052 struct tegra_bpmp_mrq {
0053     struct list_head list;
0054     unsigned int mrq;
0055     tegra_bpmp_mrq_handler_t handler;
0056     void *data;
0057 };
0058 
0059 struct tegra_bpmp {
0060     const struct tegra_bpmp_soc *soc;
0061     struct device *dev;
0062     void *priv;
0063 
0064     struct {
0065         struct mbox_client client;
0066         struct mbox_chan *channel;
0067     } mbox;
0068 
0069     spinlock_t atomic_tx_lock;
0070     struct tegra_bpmp_channel *tx_channel, *rx_channel, *threaded_channels;
0071 
0072     struct {
0073         unsigned long *allocated;
0074         unsigned long *busy;
0075         unsigned int count;
0076         struct semaphore lock;
0077     } threaded;
0078 
0079     struct list_head mrqs;
0080     spinlock_t lock;
0081 
0082     struct tegra_bpmp_clk **clocks;
0083     unsigned int num_clocks;
0084 
0085     struct reset_controller_dev rstc;
0086 
0087     struct genpd_onecell_data genpd;
0088 
0089 #ifdef CONFIG_DEBUG_FS
0090     struct dentry *debugfs_mirror;
0091 #endif
0092 };
0093 
0094 struct tegra_bpmp_message {
0095     unsigned int mrq;
0096 
0097     struct {
0098         const void *data;
0099         size_t size;
0100     } tx;
0101 
0102     struct {
0103         void *data;
0104         size_t size;
0105         int ret;
0106     } rx;
0107 };
0108 
0109 #if IS_ENABLED(CONFIG_TEGRA_BPMP)
0110 struct tegra_bpmp *tegra_bpmp_get(struct device *dev);
0111 void tegra_bpmp_put(struct tegra_bpmp *bpmp);
0112 int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
0113                    struct tegra_bpmp_message *msg);
0114 int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
0115             struct tegra_bpmp_message *msg);
0116 void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel, int code,
0117                const void *data, size_t size);
0118 
0119 int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
0120                tegra_bpmp_mrq_handler_t handler, void *data);
0121 void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
0122              void *data);
0123 bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp, unsigned int mrq);
0124 #else
0125 static inline struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
0126 {
0127     return ERR_PTR(-ENOTSUPP);
0128 }
0129 static inline void tegra_bpmp_put(struct tegra_bpmp *bpmp)
0130 {
0131 }
0132 static inline int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
0133                          struct tegra_bpmp_message *msg)
0134 {
0135     return -ENOTSUPP;
0136 }
0137 static inline int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
0138                       struct tegra_bpmp_message *msg)
0139 {
0140     return -ENOTSUPP;
0141 }
0142 static inline void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel,
0143                      int code, const void *data,
0144                      size_t size)
0145 {
0146 }
0147 
0148 static inline int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp,
0149                      unsigned int mrq,
0150                      tegra_bpmp_mrq_handler_t handler,
0151                      void *data)
0152 {
0153     return -ENOTSUPP;
0154 }
0155 static inline void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp,
0156                        unsigned int mrq, void *data)
0157 {
0158 }
0159 
0160 static inline bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp,
0161                           unsigned int mrq)
0162 {
0163     return false;
0164 }
0165 #endif
0166 
0167 void tegra_bpmp_handle_rx(struct tegra_bpmp *bpmp);
0168 
0169 #if IS_ENABLED(CONFIG_CLK_TEGRA_BPMP)
0170 int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp);
0171 #else
0172 static inline int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp)
0173 {
0174     return 0;
0175 }
0176 #endif
0177 
0178 #if IS_ENABLED(CONFIG_RESET_TEGRA_BPMP)
0179 int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp);
0180 #else
0181 static inline int tegra_bpmp_init_resets(struct tegra_bpmp *bpmp)
0182 {
0183     return 0;
0184 }
0185 #endif
0186 
0187 #if IS_ENABLED(CONFIG_SOC_TEGRA_POWERGATE_BPMP)
0188 int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp);
0189 #else
0190 static inline int tegra_bpmp_init_powergates(struct tegra_bpmp *bpmp)
0191 {
0192     return 0;
0193 }
0194 #endif
0195 
0196 #if IS_ENABLED(CONFIG_DEBUG_FS)
0197 int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp);
0198 #else
0199 static inline int tegra_bpmp_init_debugfs(struct tegra_bpmp *bpmp)
0200 {
0201     return 0;
0202 }
0203 #endif
0204 
0205 
0206 #endif /* __SOC_TEGRA_BPMP_H */