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 * @lock: lock for synchronizing this TCS writes 32 * @req: requests that are sent from the TCS 33 * @cmd_cache: flattened cache of cmds in sleep/wake TCS 34 * @slots: indicates which of @cmd_addr are occupied 35 */ 36 struct tcs_group { 37 struct rsc_drv *drv; 38 int type; 39 u32 mask; 40 u32 offset; 41 int num_tcs; 42 int ncpt; 43 spinlock_t lock; 44 const struct tcs_request *req[MAX_TCS_PER_TYPE]; 45 u32 *cmd_cache; 46 DECLARE_BITMAP(slots, MAX_TCS_SLOTS); 47 }; 48 49 /** 50 * struct rpmh_request: the message to be sent to rpmh-rsc 51 * 52 * @msg: the request 53 * @cmd: the payload that will be part of the @msg 54 * @completion: triggered when request is done 55 * @dev: the device making the request 56 * @err: err return from the controller 57 * @needs_free: check to free dynamically allocated request object 58 */ 59 struct rpmh_request { 60 struct tcs_request msg; 61 struct tcs_cmd cmd[MAX_RPMH_PAYLOAD]; 62 struct completion *completion; 63 const struct device *dev; 64 int err; 65 bool needs_free; 66 }; 67 68 /** 69 * struct rpmh_ctrlr: our representation of the controller 70 * 71 * @cache: the list of cached requests 72 * @cache_lock: synchronize access to the cache data 73 * @dirty: was the cache updated since flush 74 * @batch_cache: Cache sleep and wake requests sent as batch 75 */ 76 struct rpmh_ctrlr { 77 struct list_head cache; 78 spinlock_t cache_lock; 79 bool dirty; 80 struct list_head batch_cache; 81 }; 82 83 /** 84 * struct rsc_drv: the Direct Resource Voter (DRV) of the 85 * Resource State Coordinator controller (RSC) 86 * 87 * @name: controller identifier 88 * @tcs_base: start address of the TCS registers in this controller 89 * @id: instance id in the controller (Direct Resource Voter) 90 * @num_tcs: number of TCSes in this DRV 91 * @tcs: TCS groups 92 * @tcs_in_use: s/w state of the TCS 93 * @lock: synchronize state of the controller 94 * @client: handle to the DRV's client. 95 */ 96 struct rsc_drv { 97 const char *name; 98 void __iomem *tcs_base; 99 int id; 100 int num_tcs; 101 struct tcs_group tcs[TCS_TYPE_NR]; 102 DECLARE_BITMAP(tcs_in_use, MAX_TCS_NR); 103 spinlock_t lock; 104 struct rpmh_ctrlr client; 105 }; 106 107 int rpmh_rsc_send_data(struct rsc_drv *drv, const struct tcs_request *msg); 108 int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv, 109 const struct tcs_request *msg); 110 int rpmh_rsc_invalidate(struct rsc_drv *drv); 111 112 void rpmh_tx_done(const struct tcs_request *msg, int r); 113 114 #endif /* __RPM_INTERNAL_H__ */