^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Tegra host1x Interrupt Management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2010-2013, NVIDIA Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <trace/events/host1x.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "channel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "intr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* Wait list management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) enum waitlist_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) WLS_PENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) WLS_REMOVED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) WLS_CANCELLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) WLS_HANDLED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static void waiter_release(struct kref *kref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) kfree(container_of(kref, struct host1x_waitlist, refcount));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * add a waiter to a waiter queue, sorted by threshold
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * returns true if it was added at the head of the queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static bool add_waiter_to_queue(struct host1x_waitlist *waiter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct list_head *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct host1x_waitlist *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) u32 thresh = waiter->thresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) list_for_each_entry_reverse(pos, queue, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if ((s32)(pos->thresh - thresh) <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) list_add(&waiter->list, &pos->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) list_add(&waiter->list, queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * run through a waiter queue for a single sync point ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * and gather all completed waiters into lists by actions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void remove_completed_waiters(struct list_head *head, u32 sync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct list_head completed[HOST1X_INTR_ACTION_COUNT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct list_head *dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct host1x_waitlist *waiter, *next, *prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) list_for_each_entry_safe(waiter, next, head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if ((s32)(waiter->thresh - sync) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) dest = completed + waiter->action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* consolidate submit cleanups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) if (waiter->action == HOST1X_INTR_ACTION_SUBMIT_COMPLETE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) !list_empty(dest)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) prev = list_entry(dest->prev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct host1x_waitlist, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (prev->data == waiter->data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) prev->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) dest = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* PENDING->REMOVED or CANCELLED->HANDLED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (atomic_inc_return(&waiter->state) == WLS_HANDLED || !dest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) list_del(&waiter->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) kref_put(&waiter->refcount, waiter_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) list_move_tail(&waiter->list, dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static void reset_threshold_interrupt(struct host1x *host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) unsigned int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) u32 thresh =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) list_first_entry(head, struct host1x_waitlist, list)->thresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) host1x_hw_intr_set_syncpt_threshold(host, id, thresh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) host1x_hw_intr_enable_syncpt_intr(host, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static void action_submit_complete(struct host1x_waitlist *waiter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct host1x_channel *channel = waiter->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) host1x_cdma_update(&channel->cdma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Add nr_completed to trace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) trace_host1x_channel_submit_complete(dev_name(channel->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) waiter->count, waiter->thresh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static void action_wakeup(struct host1x_waitlist *waiter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) wait_queue_head_t *wq = waiter->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) wake_up(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static void action_wakeup_interruptible(struct host1x_waitlist *waiter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) wait_queue_head_t *wq = waiter->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) wake_up_interruptible(wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) typedef void (*action_handler)(struct host1x_waitlist *waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static const action_handler action_handlers[HOST1X_INTR_ACTION_COUNT] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) action_submit_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) action_wakeup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) action_wakeup_interruptible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static void run_handlers(struct list_head completed[HOST1X_INTR_ACTION_COUNT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct list_head *head = completed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) for (i = 0; i < HOST1X_INTR_ACTION_COUNT; ++i, ++head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) action_handler handler = action_handlers[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct host1x_waitlist *waiter, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) list_for_each_entry_safe(waiter, next, head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) list_del(&waiter->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) handler(waiter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) WARN_ON(atomic_xchg(&waiter->state, WLS_HANDLED) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) WLS_REMOVED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) kref_put(&waiter->refcount, waiter_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * Remove & handle all waiters that have completed for the given syncpt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static int process_wait_list(struct host1x *host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct host1x_syncpt *syncpt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) u32 threshold)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct list_head completed[HOST1X_INTR_ACTION_COUNT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) for (i = 0; i < HOST1X_INTR_ACTION_COUNT; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) INIT_LIST_HEAD(completed + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) spin_lock(&syncpt->intr.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) remove_completed_waiters(&syncpt->intr.wait_head, threshold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) completed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) empty = list_empty(&syncpt->intr.wait_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (empty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) host1x_hw_intr_disable_syncpt_intr(host, syncpt->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) reset_threshold_interrupt(host, &syncpt->intr.wait_head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) syncpt->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) spin_unlock(&syncpt->intr.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) run_handlers(completed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * Sync point threshold interrupt service thread function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * Handles sync point threshold triggers, in thread context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static void syncpt_thresh_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct host1x_syncpt_intr *syncpt_intr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) container_of(work, struct host1x_syncpt_intr, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct host1x_syncpt *syncpt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) container_of(syncpt_intr, struct host1x_syncpt, intr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) unsigned int id = syncpt->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct host1x *host = syncpt->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) (void)process_wait_list(host, syncpt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) host1x_syncpt_load(host->syncpt + id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int host1x_intr_add_action(struct host1x *host, struct host1x_syncpt *syncpt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) u32 thresh, enum host1x_intr_action action,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) void *data, struct host1x_waitlist *waiter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) void **ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int queue_was_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (waiter == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) pr_warn("%s: NULL waiter\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* initialize a new waiter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) INIT_LIST_HEAD(&waiter->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) kref_init(&waiter->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) kref_get(&waiter->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) waiter->thresh = thresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) waiter->action = action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) atomic_set(&waiter->state, WLS_PENDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) waiter->data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) waiter->count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) spin_lock(&syncpt->intr.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) queue_was_empty = list_empty(&syncpt->intr.wait_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (add_waiter_to_queue(waiter, &syncpt->intr.wait_head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* added at head of list - new threshold value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) host1x_hw_intr_set_syncpt_threshold(host, syncpt->id, thresh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* added as first waiter - enable interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (queue_was_empty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) host1x_hw_intr_enable_syncpt_intr(host, syncpt->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) spin_unlock(&syncpt->intr.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) *ref = waiter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) void host1x_intr_put_ref(struct host1x *host, unsigned int id, void *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct host1x_waitlist *waiter = ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct host1x_syncpt *syncpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) while (atomic_cmpxchg(&waiter->state, WLS_PENDING, WLS_CANCELLED) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) WLS_REMOVED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) syncpt = host->syncpt + id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) (void)process_wait_list(host, syncpt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) host1x_syncpt_load(host->syncpt + id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) kref_put(&waiter->refcount, waiter_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int host1x_intr_init(struct host1x *host, unsigned int irq_sync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) u32 nb_pts = host1x_syncpt_nb_pts(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) mutex_init(&host->intr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) host->intr_syncpt_irq = irq_sync;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) for (id = 0; id < nb_pts; ++id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct host1x_syncpt *syncpt = host->syncpt + id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) spin_lock_init(&syncpt->intr.lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) INIT_LIST_HEAD(&syncpt->intr.wait_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) snprintf(syncpt->intr.thresh_irq_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) sizeof(syncpt->intr.thresh_irq_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) "host1x_sp_%02u", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) host1x_intr_start(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) void host1x_intr_deinit(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) host1x_intr_stop(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) void host1x_intr_start(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) u32 hz = clk_get_rate(host->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) mutex_lock(&host->intr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) err = host1x_hw_intr_init_host_sync(host, DIV_ROUND_UP(hz, 1000000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) syncpt_thresh_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) mutex_unlock(&host->intr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) mutex_unlock(&host->intr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) void host1x_intr_stop(struct host1x *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct host1x_syncpt *syncpt = host->syncpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) u32 nb_pts = host1x_syncpt_nb_pts(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) mutex_lock(&host->intr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) host1x_hw_intr_disable_all_syncpt_intrs(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) for (id = 0; id < nb_pts; ++id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct host1x_waitlist *waiter, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) list_for_each_entry_safe(waiter, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) &syncpt[id].intr.wait_head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (atomic_cmpxchg(&waiter->state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) WLS_CANCELLED, WLS_HANDLED) == WLS_CANCELLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) list_del(&waiter->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) kref_put(&waiter->refcount, waiter_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (!list_empty(&syncpt[id].intr.wait_head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /* output diagnostics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) mutex_unlock(&host->intr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) pr_warn("%s cannot stop syncpt intr id=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) __func__, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) host1x_hw_intr_free_syncpt_irq(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) mutex_unlock(&host->intr_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }