clk: davinci: Use the correct size when allocating memory
[linux-2.6-microblaze.git] / drivers / soc / qcom / rpmh-internal.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
4  */
5
6
7 #ifndef __RPM_INTERNAL_H__
8 #define __RPM_INTERNAL_H__
9
10 #include <linux/bitmap.h>
11 #include <soc/qcom/tcs.h>
12
13 #define TCS_TYPE_NR                     4
14 #define MAX_CMDS_PER_TCS                16
15 #define MAX_TCS_PER_TYPE                3
16 #define MAX_TCS_NR                      (MAX_TCS_PER_TYPE * TCS_TYPE_NR)
17 #define MAX_TCS_SLOTS                   (MAX_CMDS_PER_TCS * MAX_TCS_PER_TYPE)
18
19 struct rsc_drv;
20
21 /**
22  * struct tcs_group: group of Trigger Command Sets (TCS) to send state requests
23  * to the controller
24  *
25  * @drv:       The controller.
26  * @type:      Type of the TCS in this group - active, sleep, wake.
27  * @mask:      Mask of the TCSes relative to all the TCSes in the RSC.
28  * @offset:    Start of the TCS group relative to the TCSes in the RSC.
29  * @num_tcs:   Number of TCSes in this type.
30  * @ncpt:      Number of commands in each TCS.
31  * @req:       Requests that are sent from the TCS; only used for ACTIVE_ONLY
32  *             transfers (could be on a wake/sleep TCS if we are borrowing for
33  *             an ACTIVE_ONLY transfer).
34  *             Start: grab drv->lock, set req, set tcs_in_use, drop drv->lock,
35  *                    trigger
36  *             End: get irq, access req,
37  *                  grab drv->lock, clear tcs_in_use, drop drv->lock
38  * @slots:     Indicates which of @cmd_addr are occupied; only used for
39  *             SLEEP / WAKE TCSs.  Things are tightly packed in the
40  *             case that (ncpt < MAX_CMDS_PER_TCS).  That is if ncpt = 2 and
41  *             MAX_CMDS_PER_TCS = 16 then bit[2] = the first bit in 2nd TCS.
42  */
43 struct tcs_group {
44         struct rsc_drv *drv;
45         int type;
46         u32 mask;
47         u32 offset;
48         int num_tcs;
49         int ncpt;
50         const struct tcs_request *req[MAX_TCS_PER_TYPE];
51         DECLARE_BITMAP(slots, MAX_TCS_SLOTS);
52 };
53
54 /**
55  * struct rpmh_request: the message to be sent to rpmh-rsc
56  *
57  * @msg: the request
58  * @cmd: the payload that will be part of the @msg
59  * @completion: triggered when request is done
60  * @dev: the device making the request
61  * @err: err return from the controller
62  * @needs_free: check to free dynamically allocated request object
63  */
64 struct rpmh_request {
65         struct tcs_request msg;
66         struct tcs_cmd cmd[MAX_RPMH_PAYLOAD];
67         struct completion *completion;
68         const struct device *dev;
69         int err;
70         bool needs_free;
71 };
72
73 /**
74  * struct rpmh_ctrlr: our representation of the controller
75  *
76  * @cache: the list of cached requests
77  * @cache_lock: synchronize access to the cache data
78  * @dirty: was the cache updated since flush
79  * @batch_cache: Cache sleep and wake requests sent as batch
80  */
81 struct rpmh_ctrlr {
82         struct list_head cache;
83         spinlock_t cache_lock;
84         bool dirty;
85         struct list_head batch_cache;
86 };
87
88 /**
89  * struct rsc_drv: the Direct Resource Voter (DRV) of the
90  * Resource State Coordinator controller (RSC)
91  *
92  * @name:               Controller identifier.
93  * @tcs_base:           Start address of the TCS registers in this controller.
94  * @id:                 Instance id in the controller (Direct Resource Voter).
95  * @num_tcs:            Number of TCSes in this DRV.
96  * @rsc_pm:             CPU PM notifier for controller.
97  *                      Used when solver mode is not present.
98  * @cpus_in_pm:         Number of CPUs not in idle power collapse.
99  *                      Used when solver mode is not present.
100  * @tcs:                TCS groups.
101  * @tcs_in_use:         S/W state of the TCS; only set for ACTIVE_ONLY
102  *                      transfers, but might show a sleep/wake TCS in use if
103  *                      it was borrowed for an active_only transfer.  You
104  *                      must hold the lock in this struct (AKA drv->lock) in
105  *                      order to update this.
106  * @lock:               Synchronize state of the controller.  If RPMH's cache
107  *                      lock will also be held, the order is: drv->lock then
108  *                      cache_lock.
109  * @client:             Handle to the DRV's client.
110  */
111 struct rsc_drv {
112         const char *name;
113         void __iomem *tcs_base;
114         int id;
115         int num_tcs;
116         struct notifier_block rsc_pm;
117         atomic_t cpus_in_pm;
118         struct tcs_group tcs[TCS_TYPE_NR];
119         DECLARE_BITMAP(tcs_in_use, MAX_TCS_NR);
120         spinlock_t lock;
121         struct rpmh_ctrlr client;
122 };
123
124 int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg);
125 int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv,
126                              const struct tcs_request *msg);
127 void rpmh_rsc_invalidate(struct rsc_drv *drv);
128
129 void rpmh_tx_done(const struct tcs_request *msg, int r);
130 int rpmh_flush(struct rpmh_ctrlr *ctrlr);
131
132 #endif /* __RPM_INTERNAL_H__ */