blob: ac8f6c35a7a45b40df6c0c4d5645f7ff185c0de2 [file] [log] [blame]
Caleb Connolly90ff5812024-07-15 12:08:02 +02001/* 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>
Caleb Connolly90ff5812024-07-15 12:08:02 +020011#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
Caleb Connolly8a540102024-07-15 12:08:09 +020019#define USEC_PER_SEC 1000000UL
20
Caleb Connolly90ff5812024-07-15 12:08:02 +020021struct rsc_drv;
22
23/**
24 * struct tcs_group: group of Trigger Command Sets (TCS) to send state requests
25 * to the controller
26 *
27 * @drv: The controller.
28 * @type: Type of the TCS in this group - active, sleep, wake.
29 * @mask: Mask of the TCSes relative to all the TCSes in the RSC.
30 * @offset: Start of the TCS group relative to the TCSes in the RSC.
31 * @num_tcs: Number of TCSes in this type.
32 * @ncpt: Number of commands in each TCS.
33 * @req: Requests that are sent from the TCS; only used for ACTIVE_ONLY
34 * transfers (could be on a wake/sleep TCS if we are borrowing for
35 * an ACTIVE_ONLY transfer).
36 * Start: grab drv->lock, set req, set tcs_in_use, drop drv->lock,
37 * trigger
38 * End: get irq, access req,
39 * grab drv->lock, clear tcs_in_use, drop drv->lock
40 * @slots: Indicates which of @cmd_addr are occupied; only used for
41 * SLEEP / WAKE TCSs. Things are tightly packed in the
42 * case that (ncpt < MAX_CMDS_PER_TCS). That is if ncpt = 2 and
43 * MAX_CMDS_PER_TCS = 16 then bit[2] = the first bit in 2nd TCS.
44 */
45struct tcs_group {
46 struct rsc_drv *drv;
47 int type;
48 u32 mask;
49 u32 offset;
50 int num_tcs;
51 int ncpt;
52 const struct tcs_request *req[MAX_TCS_PER_TYPE];
53 DECLARE_BITMAP(slots, MAX_TCS_SLOTS);
54};
55
56/**
57 * struct rpmh_request: the message to be sent to rpmh-rsc
58 *
59 * @msg: the request
60 * @cmd: the payload that will be part of the @msg
61 * @completion: triggered when request is done
62 * @dev: the device making the request
63 * @needs_free: check to free dynamically allocated request object
64 */
65struct rpmh_request {
66 struct tcs_request msg;
67 struct tcs_cmd cmd[MAX_RPMH_PAYLOAD];
Caleb Connolly8a540102024-07-15 12:08:09 +020068 const struct udevice *dev;
Caleb Connolly90ff5812024-07-15 12:08:02 +020069 bool needs_free;
70};
71
72/**
73 * struct rpmh_ctrlr: our representation of the controller
74 *
75 * @cache: the list of cached requests
76 * @cache_lock: synchronize access to the cache data
77 * @dirty: was the cache updated since flush
78 * @batch_cache: Cache sleep and wake requests sent as batch
79 */
80struct rpmh_ctrlr {
81 struct list_head cache;
Caleb Connolly90ff5812024-07-15 12:08:02 +020082 bool dirty;
83 struct list_head batch_cache;
84};
85
86struct rsc_ver {
87 u32 major;
88 u32 minor;
89};
90
91/**
92 * struct rsc_drv: the Direct Resource Voter (DRV) of the
93 * Resource State Coordinator controller (RSC)
94 *
95 * @name: Controller identifier.
96 * @base: Start address of the DRV registers in this controller.
97 * @tcs_base: Start address of the TCS registers in this controller.
98 * @id: Instance id in the controller (Direct Resource Voter).
99 * @num_tcs: Number of TCSes in this DRV.
100 * @rsc_pm: CPU PM notifier for controller.
101 * Used when solver mode is not present.
102 * @cpus_in_pm: Number of CPUs not in idle power collapse.
103 * Used when solver mode and "power-domains" is not present.
104 * @genpd_nb: PM Domain notifier for cluster genpd notifications.
105 * @tcs: TCS groups.
106 * @tcs_in_use: S/W state of the TCS; only set for ACTIVE_ONLY
107 * transfers, but might show a sleep/wake TCS in use if
108 * it was borrowed for an active_only transfer. You
109 * must hold the lock in this struct (AKA drv->lock) in
110 * order to update this.
111 * @lock: Synchronize state of the controller. If RPMH's cache
112 * lock will also be held, the order is: drv->lock then
113 * cache_lock.
114 * @tcs_wait: Wait queue used to wait for @tcs_in_use to free up a
115 * slot
116 * @client: Handle to the DRV's client.
117 * @dev: RSC device.
118 */
119struct rsc_drv {
120 const char *name;
121 void __iomem *base;
122 void __iomem *tcs_base;
123 int id;
124 int num_tcs;
Caleb Connolly90ff5812024-07-15 12:08:02 +0200125 struct tcs_group tcs[TCS_TYPE_NR];
126 DECLARE_BITMAP(tcs_in_use, MAX_TCS_NR);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200127 struct rpmh_ctrlr client;
Caleb Connolly8a540102024-07-15 12:08:09 +0200128 struct udevice *dev;
Caleb Connolly90ff5812024-07-15 12:08:02 +0200129 struct rsc_ver ver;
130 u32 *regs;
131};
132
133int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg);
134int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv,
135 const struct tcs_request *msg);
136void rpmh_rsc_invalidate(struct rsc_drv *drv);
Caleb Connolly90ff5812024-07-15 12:08:02 +0200137
138#endif /* __RPM_INTERNAL_H__ */