1 // SPDX-License-Identifier: GPL-2.0-only
3 * Tegra host1x Interrupt Management
5 * Copyright (C) 2010 Google, Inc.
6 * Copyright (c) 2010-2013, NVIDIA Corporation.
9 #include <linux/interrupt.h>
10 #include <linux/irq.h>
16 static irqreturn_t syncpt_thresh_isr(int irq, void *dev_id)
18 struct host1x *host = dev_id;
22 for (i = 0; i < DIV_ROUND_UP(host->info->nb_pts, 32); i++) {
23 reg = host1x_sync_readl(host,
24 HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(i));
26 host1x_sync_writel(host, reg,
27 HOST1X_SYNC_SYNCPT_THRESH_INT_DISABLE(i));
28 host1x_sync_writel(host, reg,
29 HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(i));
31 for_each_set_bit(id, ®, 32)
32 host1x_intr_handle_interrupt(host, i * 32 + id);
38 static void host1x_intr_disable_all_syncpt_intrs(struct host1x *host)
42 for (i = 0; i < DIV_ROUND_UP(host->info->nb_pts, 32); ++i) {
43 host1x_sync_writel(host, 0xffffffffu,
44 HOST1X_SYNC_SYNCPT_THRESH_INT_DISABLE(i));
45 host1x_sync_writel(host, 0xffffffffu,
46 HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(i));
50 static void intr_hw_init(struct host1x *host, u32 cpm)
53 /* disable the ip_busy_timeout. this prevents write drops */
54 host1x_sync_writel(host, 0, HOST1X_SYNC_IP_BUSY_TIMEOUT);
57 * increase the auto-ack timout to the maximum value. 2d will hang
58 * otherwise on Tegra2.
60 host1x_sync_writel(host, 0xff, HOST1X_SYNC_CTXSW_TIMEOUT_CFG);
62 /* update host clocks per usec */
63 host1x_sync_writel(host, cpm, HOST1X_SYNC_USEC_CLK);
69 * Program threshold interrupt destination among 8 lines per VM,
70 * per syncpoint. For now, just direct all to the first interrupt
73 for (id = 0; id < host->info->nb_pts; id++)
74 host1x_sync_writel(host, 0, HOST1X_SYNC_SYNCPT_INTR_DEST(id));
79 host1x_intr_init_host_sync(struct host1x *host, u32 cpm)
83 host1x_hw_intr_disable_all_syncpt_intrs(host);
85 err = devm_request_irq(host->dev, host->syncpt_irq,
86 syncpt_thresh_isr, IRQF_SHARED,
87 "host1x_syncpt", host);
91 intr_hw_init(host, cpm);
96 static void host1x_intr_set_syncpt_threshold(struct host1x *host,
100 host1x_sync_writel(host, thresh, HOST1X_SYNC_SYNCPT_INT_THRESH(id));
103 static void host1x_intr_enable_syncpt_intr(struct host1x *host,
106 host1x_sync_writel(host, BIT(id % 32),
107 HOST1X_SYNC_SYNCPT_THRESH_INT_ENABLE_CPU0(id / 32));
110 static void host1x_intr_disable_syncpt_intr(struct host1x *host,
113 host1x_sync_writel(host, BIT(id % 32),
114 HOST1X_SYNC_SYNCPT_THRESH_INT_DISABLE(id / 32));
115 host1x_sync_writel(host, BIT(id % 32),
116 HOST1X_SYNC_SYNCPT_THRESH_CPU0_INT_STATUS(id / 32));
119 static const struct host1x_intr_ops host1x_intr_ops = {
120 .init_host_sync = host1x_intr_init_host_sync,
121 .set_syncpt_threshold = host1x_intr_set_syncpt_threshold,
122 .enable_syncpt_intr = host1x_intr_enable_syncpt_intr,
123 .disable_syncpt_intr = host1x_intr_disable_syncpt_intr,
124 .disable_all_syncpt_intrs = host1x_intr_disable_all_syncpt_intrs,