Lines Matching full:tcs
25 #include <soc/qcom/tcs.h>
41 /* DRV TCS Configuration Information Register */
48 /* Offsets for common TCS Registers, one bit per TCS */
54 * Offsets for per TCS Registers.
57 * Multiply tcs_id by RSC_DRV_TCS_OFFSET to find a given TCS and add one
62 #define RSC_DRV_STATUS 0x18 /* zero if tcs is busy */
66 * Offsets for per command in a TCS.
68 * Commands (up to 16) start at 0x30 in a TCS; multiply command index
80 /* TCS CMD register bit mask */
94 * space are all the TCS blocks. The offset of the TCS blocks is
95 * specified in the device tree by "qcom,tcs-offset" and used to
97 * - TCS blocks come one after another. Type, count, and order are
98 * specified by the device tree as "qcom,tcs-config".
99 * - Each TCS block has some registers, then space for up to 16 commands.
101 * might be present. See ncpt (num cmds per TCS).
197 * tcs_is_free() - Return if a TCS is totally free.
199 * @tcs_id: The global ID of this TCS.
201 * Returns true if nobody has claimed this TCS (by setting tcs_in_use).
205 * Return: true if the given TCS is free.
227 struct tcs_group *tcs = &drv->tcs[type]; in tcs_invalidate() local
230 if (bitmap_empty(tcs->slots, MAX_TCS_SLOTS)) in tcs_invalidate()
233 for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) { in tcs_invalidate()
237 bitmap_zero(tcs->slots, MAX_TCS_SLOTS); in tcs_invalidate()
268 struct tcs_group *tcs; in get_tcs_for_msg() local
286 * dedicated TCS for active state use, then re-purpose a wake TCS to in get_tcs_for_msg()
291 tcs = &drv->tcs[type]; in get_tcs_for_msg()
292 if (msg->state == RPMH_ACTIVE_ONLY_STATE && !tcs->num_tcs) in get_tcs_for_msg()
293 tcs = &drv->tcs[WAKE_TCS]; in get_tcs_for_msg()
295 return tcs; in get_tcs_for_msg()
299 * get_req_from_tcs() - Get a stashed request that was xfering on the given TCS.
301 * @tcs_id: The global ID of this TCS.
317 struct tcs_group *tcs; in get_req_from_tcs() local
321 tcs = &drv->tcs[i]; in get_req_from_tcs()
322 if (tcs->mask & BIT(tcs_id)) in get_req_from_tcs()
323 return tcs->req[tcs_id - tcs->offset]; in get_req_from_tcs()
330 * __tcs_set_trigger() - Start xfer on a TCS or unset trigger on a borrowed TCS
332 * @tcs_id: The global ID of this TCS.
336 * transfer. That will un-trigger/disable the TCS from the last transfer
339 * If we borrowed a wake TCS for an active-only transfer we'll also call
341 * before using the TCS for wake purposes again.
351 * HW req: Clear the DRV_CONTROL and enable TCS again in __tcs_set_trigger()
362 /* Enable the AMC mode on the TCS and then trigger the TCS */ in __tcs_set_trigger()
371 * enable_tcs_irq() - Enable or disable interrupts on the given TCS.
373 * @tcs_id: The global ID of this TCS.
376 * We only ever call this when we borrow a wake TCS for an active-only
436 * If wake tcs was re-purposed for sending active in tcs_tx_done()
438 * disable interrupt for this TCS in tcs_tx_done()
440 if (!drv->tcs[ACTIVE_TCS].num_tcs) in tcs_tx_done()
443 /* Reclaim the TCS */ in tcs_tx_done()
450 * Disable interrupt for WAKE TCS to avoid being in tcs_tx_done()
454 if (!drv->tcs[ACTIVE_TCS].num_tcs) in tcs_tx_done()
466 * __tcs_buffer_write() - Write to TCS hardware from a request; don't trigger.
468 * @tcs_id: The global ID of this TCS.
469 * @cmd_id: The index within the TCS to start writing.
471 * pairs to program (but few enough that they all fit in one TCS).
511 * @tcs: A pointer to the tcs_group used for ACTIVE_ONLY transfers.
513 * pairs to program (but few enough that they all fit in one TCS).
528 static int check_for_req_inflight(struct rsc_drv *drv, struct tcs_group *tcs, in check_for_req_inflight() argument
534 int tcs_id = tcs->offset; in check_for_req_inflight()
536 for (i = 0; i < tcs->num_tcs; i++, tcs_id++) { in check_for_req_inflight()
555 * find_free_tcs() - Find free tcs in the given tcs_group; only for active.
556 * @tcs: A pointer to the active-only tcs_group (or the wake tcs_group if
561 * Return: The first tcs that's free.
563 static int find_free_tcs(struct tcs_group *tcs) in find_free_tcs() argument
567 for (i = 0; i < tcs->num_tcs; i++) { in find_free_tcs()
568 if (tcs_is_free(tcs->drv, tcs->offset + i)) in find_free_tcs()
569 return tcs->offset + i; in find_free_tcs()
576 * claim_tcs_for_req() - Claim a tcs in the given tcs_group; only for active.
578 * @tcs: The tcs_group used for ACTIVE_ONLY transfers.
581 * Claims a tcs in the given tcs_group while making sure that no existing cmd
587 * Return: The id of the claimed tcs or -EBUSY if a matching msg is in flight
590 static int claim_tcs_for_req(struct rsc_drv *drv, struct tcs_group *tcs, in claim_tcs_for_req() argument
599 ret = check_for_req_inflight(drv, tcs, msg); in claim_tcs_for_req()
603 return find_free_tcs(tcs); in claim_tcs_for_req()
614 * - To do the transfer, we will grab a whole TCS for ourselves--we don't
630 struct tcs_group *tcs; in rpmh_rsc_send_data() local
634 tcs = get_tcs_for_msg(drv, msg); in rpmh_rsc_send_data()
635 if (IS_ERR(tcs)) in rpmh_rsc_send_data()
636 return PTR_ERR(tcs); in rpmh_rsc_send_data()
640 /* Wait forever for a free tcs. It better be there eventually! */ in rpmh_rsc_send_data()
642 (tcs_id = claim_tcs_for_req(drv, tcs, msg)) >= 0, in rpmh_rsc_send_data()
645 tcs->req[tcs_id - tcs->offset] = msg; in rpmh_rsc_send_data()
647 if (msg->state == RPMH_ACTIVE_ONLY_STATE && tcs->type != ACTIVE_TCS) { in rpmh_rsc_send_data()
650 * repurposed TCS to avoid triggering them. tcs->slots will be in rpmh_rsc_send_data()
675 * @tcs: The tcs group to search.
678 * TCS to write to here.
680 * the command array of the returned TCS where the client should
684 * tcs->slots for.
688 static int find_slots(struct tcs_group *tcs, const struct tcs_request *msg, in find_slots() argument
694 /* Do over, until we can fit the full payload in a single TCS */ in find_slots()
696 slot = bitmap_find_next_zero_area(tcs->slots, MAX_TCS_SLOTS, in find_slots()
698 if (slot >= tcs->num_tcs * tcs->ncpt) in find_slots()
700 i += tcs->ncpt; in find_slots()
703 bitmap_set(tcs->slots, slot, msg->num_cmds); in find_slots()
705 offset = slot / tcs->ncpt; in find_slots()
706 *tcs_id = offset + tcs->offset; in find_slots()
707 *cmd_id = slot % tcs->ncpt; in find_slots()
727 struct tcs_group *tcs; in rpmh_rsc_write_ctrl_data() local
731 tcs = get_tcs_for_msg(drv, msg); in rpmh_rsc_write_ctrl_data()
732 if (IS_ERR(tcs)) in rpmh_rsc_write_ctrl_data()
733 return PTR_ERR(tcs); in rpmh_rsc_write_ctrl_data()
735 /* find the TCS id and the command in the TCS to write to */ in rpmh_rsc_write_ctrl_data()
736 ret = find_slots(tcs, msg, &tcs_id, &cmd_id); in rpmh_rsc_write_ctrl_data()
761 struct tcs_group *tcs = &drv->tcs[ACTIVE_TCS]; in rpmh_rsc_ctrlr_is_busy() local
765 * dedicated TCS for active state use, then re-purposed wake TCSes in rpmh_rsc_ctrlr_is_busy()
769 if (!tcs->num_tcs) in rpmh_rsc_ctrlr_is_busy()
770 tcs = &drv->tcs[WAKE_TCS]; in rpmh_rsc_ctrlr_is_busy()
772 for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) { in rpmh_rsc_ctrlr_is_busy()
871 struct tcs_group *tcs; in rpmh_probe_tcs_config() local
873 ret = of_property_read_u32(dn, "qcom,tcs-offset", &offset); in rpmh_probe_tcs_config()
887 n = of_property_count_u32_elems(dn, "qcom,tcs-config"); in rpmh_probe_tcs_config()
892 ret = of_property_read_u32_index(dn, "qcom,tcs-config", in rpmh_probe_tcs_config()
899 ret = of_property_read_u32_index(dn, "qcom,tcs-config", in rpmh_probe_tcs_config()
908 tcs = &drv->tcs[tcs_cfg[i].type]; in rpmh_probe_tcs_config()
909 if (tcs->drv) in rpmh_probe_tcs_config()
911 tcs->drv = drv; in rpmh_probe_tcs_config()
912 tcs->type = tcs_cfg[i].type; in rpmh_probe_tcs_config()
913 tcs->num_tcs = tcs_cfg[i].n; in rpmh_probe_tcs_config()
914 tcs->ncpt = ncpt; in rpmh_probe_tcs_config()
916 if (!tcs->num_tcs || tcs->type == CONTROL_TCS) in rpmh_probe_tcs_config()
919 if (st + tcs->num_tcs > max_tcs || in rpmh_probe_tcs_config()
920 st + tcs->num_tcs >= BITS_PER_BYTE * sizeof(tcs->mask)) in rpmh_probe_tcs_config()
923 tcs->mask = ((1 << tcs->num_tcs) - 1) << st; in rpmh_probe_tcs_config()
924 tcs->offset = st; in rpmh_probe_tcs_config()
925 st += tcs->num_tcs; in rpmh_probe_tcs_config()
1004 /* Enable the active TCS to send requests immediately */ in rpmh_rsc_probe()
1005 writel_relaxed(drv->tcs[ACTIVE_TCS].mask, in rpmh_rsc_probe()