Lines Matching +full:tcs +full:- +full:wait

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
19 #include <linux/wait.h>
23 #include "rpmh-internal.h"
59 * struct batch_cache_req - An entry in our batch catch
74 struct rsc_drv *drv = dev_get_drvdata(dev->parent); in get_rpmh_ctrlr()
76 return &drv->client; in get_rpmh_ctrlr()
83 struct completion *compl = rpm_msg->completion; in rpmh_tx_done()
84 bool free = rpm_msg->needs_free; in rpmh_tx_done()
101 list_for_each_entry(p, &ctrlr->cache, list) { in __find_req()
102 if (p->addr == addr) { in __find_req()
119 spin_lock_irqsave(&ctrlr->cache_lock, flags); in cache_rpm_request()
120 req = __find_req(ctrlr, cmd->addr); in cache_rpm_request()
126 req = ERR_PTR(-ENOMEM); in cache_rpm_request()
130 req->addr = cmd->addr; in cache_rpm_request()
131 req->sleep_val = req->wake_val = UINT_MAX; in cache_rpm_request()
132 list_add_tail(&req->list, &ctrlr->cache); in cache_rpm_request()
135 old_sleep_val = req->sleep_val; in cache_rpm_request()
136 old_wake_val = req->wake_val; in cache_rpm_request()
141 req->wake_val = cmd->data; in cache_rpm_request()
144 req->sleep_val = cmd->data; in cache_rpm_request()
148 ctrlr->dirty |= (req->sleep_val != old_sleep_val || in cache_rpm_request()
149 req->wake_val != old_wake_val) && in cache_rpm_request()
150 req->sleep_val != UINT_MAX && in cache_rpm_request()
151 req->wake_val != UINT_MAX; in cache_rpm_request()
154 spin_unlock_irqrestore(&ctrlr->cache_lock, flags); in cache_rpm_request()
174 int ret = -EINVAL; in __rpmh_write()
179 for (i = 0; i < rpm_msg->msg.num_cmds; i++) { in __rpmh_write()
180 req = cache_rpm_request(ctrlr, state, &rpm_msg->msg.cmds[i]); in __rpmh_write()
187 ret = rpmh_rsc_send_data(ctrlr_to_drv(ctrlr), &rpm_msg->msg); in __rpmh_write()
191 rpmh_tx_done(&rpm_msg->msg); in __rpmh_write()
201 return -EINVAL; in __fill_rpmh_msg()
203 memcpy(req->cmd, cmd, n * sizeof(*cmd)); in __fill_rpmh_msg()
205 req->msg.state = state; in __fill_rpmh_msg()
206 req->msg.cmds = req->cmd; in __fill_rpmh_msg()
207 req->msg.num_cmds = n; in __fill_rpmh_msg()
231 return -ENOMEM; in rpmh_write_async()
232 rpm_msg->needs_free = true; in rpmh_write_async()
271 return (ret > 0) ? 0 : -ETIMEDOUT; in rpmh_write()
279 spin_lock_irqsave(&ctrlr->cache_lock, flags); in cache_batch()
280 list_add_tail(&req->list, &ctrlr->batch_cache); in cache_batch()
281 ctrlr->dirty = true; in cache_batch()
282 spin_unlock_irqrestore(&ctrlr->cache_lock, flags); in cache_batch()
293 list_for_each_entry(req, &ctrlr->batch_cache, list) { in flush_batch()
294 for (i = 0; i < req->count; i++) { in flush_batch()
295 rpm_msg = req->rpm_msgs + i; in flush_batch()
297 &rpm_msg->msg); in flush_batch()
307 * rpmh_write_batch: Write multiple sets of RPMH commands and wait for the
319 * request is sent as fire-n-forget and no ack is expected.
336 return -EINVAL; in rpmh_write_batch()
341 return -EINVAL; in rpmh_write_batch()
344 count * (sizeof(req->rpm_msgs[0]) + sizeof(*compls)), in rpmh_write_batch()
347 return -ENOMEM; in rpmh_write_batch()
352 req->count = count; in rpmh_write_batch()
353 rpm_msgs = req->rpm_msgs; in rpmh_write_batch()
379 while (i--) { in rpmh_write_batch()
388 ret = -ETIMEDOUT; in rpmh_write_batch()
402 return (req->sleep_val != UINT_MAX && in is_req_valid()
403 req->wake_val != UINT_MAX && in is_req_valid()
404 req->sleep_val != req->wake_val); in is_req_valid()
422 * rpmh_flush() - Flushes the buffered sleep and wake sets to TCSes
427 * * 0 - Success
428 * * Error code - Otherwise
442 if (!spin_trylock(&ctrlr->cache_lock)) in rpmh_flush()
443 return -EBUSY; in rpmh_flush()
445 if (!ctrlr->dirty) { in rpmh_flush()
446 pr_debug("Skipping flush, TCS has latest data.\n"); in rpmh_flush()
458 list_for_each_entry(p, &ctrlr->cache, list) { in rpmh_flush()
461 __func__, p->addr, p->sleep_val, p->wake_val); in rpmh_flush()
464 ret = send_single(ctrlr, RPMH_SLEEP_STATE, p->addr, in rpmh_flush()
465 p->sleep_val); in rpmh_flush()
468 ret = send_single(ctrlr, RPMH_WAKE_ONLY_STATE, p->addr, in rpmh_flush()
469 p->wake_val); in rpmh_flush()
474 ctrlr->dirty = false; in rpmh_flush()
479 spin_unlock(&ctrlr->cache_lock); in rpmh_flush()
496 spin_lock_irqsave(&ctrlr->cache_lock, flags); in rpmh_invalidate()
497 list_for_each_entry_safe(req, tmp, &ctrlr->batch_cache, list) in rpmh_invalidate()
499 INIT_LIST_HEAD(&ctrlr->batch_cache); in rpmh_invalidate()
500 ctrlr->dirty = true; in rpmh_invalidate()
501 spin_unlock_irqrestore(&ctrlr->cache_lock, flags); in rpmh_invalidate()