Skip to content

Commit f1b53c4

Browse files
cyndisthierryreding
authored andcommitted
gpu: host1x: Add Tegra186 support
Add support for the implementation of Host1x present on the Tegra186. The register space has been shuffled around a little bit, requiring addition of some chip-specific code sections. Tegra186 also adds several new features, most importantly the hypervisor, but those are not yet supported with this commit. Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com> Reviewed-by: Dmitry Osipenko <digetx@gmail.com> Tested-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Thierry Reding <treding@nvidia.com>
1 parent d3b3efa commit f1b53c4

18 files changed

Lines changed: 876 additions & 168 deletions

‎drivers/gpu/host1x/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ host1x-y = \
1111
hw/host1x01.o \
1212
hw/host1x02.o \
1313
hw/host1x04.o \
14-
hw/host1x05.o
14+
hw/host1x05.o \
15+
hw/host1x06.o
1516

1617
obj-$(CONFIG_TEGRA_HOST1X) += host1x.o

‎drivers/gpu/host1x/dev.c‎

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
#include "hw/host1x02.h"
4040
#include "hw/host1x04.h"
4141
#include "hw/host1x05.h"
42+
#include "hw/host1x06.h"
43+
44+
void host1x_hypervisor_writel(struct host1x *host1x, u32 v, u32 r)
45+
{
46+
writel(v, host1x->hv_regs + r);
47+
}
48+
49+
u32 host1x_hypervisor_readl(struct host1x *host1x, u32 r)
50+
{
51+
return readl(host1x->hv_regs + r);
52+
}
4253

4354
void host1x_sync_writel(struct host1x *host1x, u32 v, u32 r)
4455
{
@@ -104,7 +115,19 @@ static const struct host1x_info host1x05_info = {
104115
.dma_mask = DMA_BIT_MASK(34),
105116
};
106117

118+
static const struct host1x_info host1x06_info = {
119+
.nb_channels = 63,
120+
.nb_pts = 576,
121+
.nb_mlocks = 24,
122+
.nb_bases = 16,
123+
.init = host1x06_init,
124+
.sync_offset = 0x0,
125+
.dma_mask = DMA_BIT_MASK(34),
126+
.has_hypervisor = true,
127+
};
128+
107129
static const struct of_device_id host1x_of_match[] = {
130+
{ .compatible = "nvidia,tegra186-host1x", .data = &host1x06_info, },
108131
{ .compatible = "nvidia,tegra210-host1x", .data = &host1x05_info, },
109132
{ .compatible = "nvidia,tegra124-host1x", .data = &host1x04_info, },
110133
{ .compatible = "nvidia,tegra114-host1x", .data = &host1x02_info, },
@@ -117,7 +140,7 @@ MODULE_DEVICE_TABLE(of, host1x_of_match);
117140
static int host1x_probe(struct platform_device *pdev)
118141
{
119142
struct host1x *host;
120-
struct resource *regs;
143+
struct resource *regs, *hv_regs = NULL;
121144
int syncpt_irq;
122145
int err;
123146

@@ -127,10 +150,26 @@ static int host1x_probe(struct platform_device *pdev)
127150

128151
host->info = of_device_get_match_data(&pdev->dev);
129152

130-
regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
131-
if (!regs) {
132-
dev_err(&pdev->dev, "failed to get registers\n");
133-
return -ENXIO;
153+
if (host->info->has_hypervisor) {
154+
regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "vm");
155+
if (!regs) {
156+
dev_err(&pdev->dev, "failed to get vm registers\n");
157+
return -ENXIO;
158+
}
159+
160+
hv_regs = platform_get_resource_byname(pdev, IORESOURCE_MEM,
161+
"hypervisor");
162+
if (!hv_regs) {
163+
dev_err(&pdev->dev,
164+
"failed to get hypervisor registers\n");
165+
return -ENXIO;
166+
}
167+
} else {
168+
regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
169+
if (!regs) {
170+
dev_err(&pdev->dev, "failed to get registers\n");
171+
return -ENXIO;
172+
}
134173
}
135174

136175
syncpt_irq = platform_get_irq(pdev, 0);
@@ -151,6 +190,12 @@ static int host1x_probe(struct platform_device *pdev)
151190
if (IS_ERR(host->regs))
152191
return PTR_ERR(host->regs);
153192

193+
if (host->info->has_hypervisor) {
194+
host->hv_regs = devm_ioremap_resource(&pdev->dev, hv_regs);
195+
if (IS_ERR(host->hv_regs))
196+
return PTR_ERR(host->hv_regs);
197+
}
198+
154199
dma_set_mask_and_coherent(host->dev, host->info->dma_mask);
155200

156201
if (host->info->init) {

‎drivers/gpu/host1x/dev.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ struct host1x_info {
100100
int (*init)(struct host1x *host1x); /* initialize per SoC ops */
101101
unsigned int sync_offset; /* offset of syncpoint registers */
102102
u64 dma_mask; /* mask of addressable memory */
103+
bool has_hypervisor; /* has hypervisor registers */
103104
};
104105

105106
struct host1x {
106107
const struct host1x_info *info;
107108

108109
void __iomem *regs;
110+
void __iomem *hv_regs; /* hypervisor region */
109111
struct host1x_syncpt *syncpt;
110112
struct host1x_syncpt_base *bases;
111113
struct device *dev;
@@ -140,6 +142,8 @@ struct host1x {
140142
struct list_head list;
141143
};
142144

145+
void host1x_hypervisor_writel(struct host1x *host1x, u32 r, u32 v);
146+
u32 host1x_hypervisor_readl(struct host1x *host1x, u32 r);
143147
void host1x_sync_writel(struct host1x *host1x, u32 r, u32 v);
144148
u32 host1x_sync_readl(struct host1x *host1x, u32 r);
145149
void host1x_ch_writel(struct host1x_channel *ch, u32 r, u32 v);

‎drivers/gpu/host1x/hw/cdma_hw.c‎

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,30 @@ static void cdma_stop(struct host1x_cdma *cdma)
172172
mutex_unlock(&cdma->lock);
173173
}
174174

175+
static void cdma_hw_cmdproc_stop(struct host1x *host, struct host1x_channel *ch,
176+
bool stop)
177+
{
178+
#if HOST1X_HW >= 6
179+
host1x_ch_writel(ch, stop ? 0x1 : 0x0, HOST1X_CHANNEL_CMDPROC_STOP);
180+
#else
181+
u32 cmdproc_stop = host1x_sync_readl(host, HOST1X_SYNC_CMDPROC_STOP);
182+
if (stop)
183+
cmdproc_stop |= BIT(ch->id);
184+
else
185+
cmdproc_stop &= ~BIT(ch->id);
186+
host1x_sync_writel(host, cmdproc_stop, HOST1X_SYNC_CMDPROC_STOP);
187+
#endif
188+
}
189+
190+
static void cdma_hw_teardown(struct host1x *host, struct host1x_channel *ch)
191+
{
192+
#if HOST1X_HW >= 6
193+
host1x_ch_writel(ch, 0x1, HOST1X_CHANNEL_TEARDOWN);
194+
#else
195+
host1x_sync_writel(host, BIT(ch->id), HOST1X_SYNC_CH_TEARDOWN);
196+
#endif
197+
}
198+
175199
/*
176200
* Stops both channel's command processor and CDMA immediately.
177201
* Also, tears down the channel and resets corresponding module.
@@ -180,7 +204,6 @@ static void cdma_freeze(struct host1x_cdma *cdma)
180204
{
181205
struct host1x *host = cdma_to_host1x(cdma);
182206
struct host1x_channel *ch = cdma_to_channel(cdma);
183-
u32 cmdproc_stop;
184207

185208
if (cdma->torndown && !cdma->running) {
186209
dev_warn(host->dev, "Already torn down\n");
@@ -189,9 +212,7 @@ static void cdma_freeze(struct host1x_cdma *cdma)
189212

190213
dev_dbg(host->dev, "freezing channel (id %d)\n", ch->id);
191214

192-
cmdproc_stop = host1x_sync_readl(host, HOST1X_SYNC_CMDPROC_STOP);
193-
cmdproc_stop |= BIT(ch->id);
194-
host1x_sync_writel(host, cmdproc_stop, HOST1X_SYNC_CMDPROC_STOP);
215+
cdma_hw_cmdproc_stop(host, ch, true);
195216

196217
dev_dbg(host->dev, "%s: DMA GET 0x%x, PUT HW 0x%x / shadow 0x%x\n",
197218
__func__, host1x_ch_readl(ch, HOST1X_CHANNEL_DMAGET),
@@ -201,7 +222,7 @@ static void cdma_freeze(struct host1x_cdma *cdma)
201222
host1x_ch_writel(ch, HOST1X_CHANNEL_DMACTRL_DMASTOP,
202223
HOST1X_CHANNEL_DMACTRL);
203224

204-
host1x_sync_writel(host, BIT(ch->id), HOST1X_SYNC_CH_TEARDOWN);
225+
cdma_hw_teardown(host, ch);
205226

206227
cdma->running = false;
207228
cdma->torndown = true;
@@ -211,15 +232,12 @@ static void cdma_resume(struct host1x_cdma *cdma, u32 getptr)
211232
{
212233
struct host1x *host1x = cdma_to_host1x(cdma);
213234
struct host1x_channel *ch = cdma_to_channel(cdma);
214-
u32 cmdproc_stop;
215235

216236
dev_dbg(host1x->dev,
217237
"resuming channel (id %u, DMAGET restart = 0x%x)\n",
218238
ch->id, getptr);
219239

220-
cmdproc_stop = host1x_sync_readl(host1x, HOST1X_SYNC_CMDPROC_STOP);
221-
cmdproc_stop &= ~BIT(ch->id);
222-
host1x_sync_writel(host1x, cmdproc_stop, HOST1X_SYNC_CMDPROC_STOP);
240+
cdma_hw_cmdproc_stop(host1x, ch, false);
223241

224242
cdma->torndown = false;
225243
cdma_timeout_restart(cdma, getptr);
@@ -232,7 +250,7 @@ static void cdma_resume(struct host1x_cdma *cdma, u32 getptr)
232250
*/
233251
static void cdma_timeout_handler(struct work_struct *work)
234252
{
235-
u32 prev_cmdproc, cmdproc_stop, syncpt_val;
253+
u32 syncpt_val;
236254
struct host1x_cdma *cdma;
237255
struct host1x *host1x;
238256
struct host1x_channel *ch;
@@ -254,12 +272,7 @@ static void cdma_timeout_handler(struct work_struct *work)
254272
}
255273

256274
/* stop processing to get a clean snapshot */
257-
prev_cmdproc = host1x_sync_readl(host1x, HOST1X_SYNC_CMDPROC_STOP);
258-
cmdproc_stop = prev_cmdproc | BIT(ch->id);
259-
host1x_sync_writel(host1x, cmdproc_stop, HOST1X_SYNC_CMDPROC_STOP);
260-
261-
dev_dbg(host1x->dev, "cdma_timeout: cmdproc was 0x%x is 0x%x\n",
262-
prev_cmdproc, cmdproc_stop);
275+
cdma_hw_cmdproc_stop(host1x, ch, true);
263276

264277
syncpt_val = host1x_syncpt_load(cdma->timeout.syncpt);
265278

@@ -268,9 +281,7 @@ static void cdma_timeout_handler(struct work_struct *work)
268281
dev_dbg(host1x->dev,
269282
"cdma_timeout: expired, but buffer had completed\n");
270283
/* restore */
271-
cmdproc_stop = prev_cmdproc & ~(BIT(ch->id));
272-
host1x_sync_writel(host1x, cmdproc_stop,
273-
HOST1X_SYNC_CMDPROC_STOP);
284+
cdma_hw_cmdproc_stop(host1x, ch, false);
274285
mutex_unlock(&cdma->lock);
275286
return;
276287
}

‎drivers/gpu/host1x/hw/debug_hw.c‎

Lines changed: 5 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -174,138 +174,11 @@ static void show_channel_gathers(struct output *o, struct host1x_cdma *cdma)
174174
}
175175
}
176176

177-
static void host1x_debug_show_channel_cdma(struct host1x *host,
178-
struct host1x_channel *ch,
179-
struct output *o)
180-
{
181-
struct host1x_cdma *cdma = &ch->cdma;
182-
u32 dmaput, dmaget, dmactrl;
183-
u32 cbstat, cbread;
184-
u32 val, base, baseval;
185-
186-
dmaput = host1x_ch_readl(ch, HOST1X_CHANNEL_DMAPUT);
187-
dmaget = host1x_ch_readl(ch, HOST1X_CHANNEL_DMAGET);
188-
dmactrl = host1x_ch_readl(ch, HOST1X_CHANNEL_DMACTRL);
189-
cbread = host1x_sync_readl(host, HOST1X_SYNC_CBREAD(ch->id));
190-
cbstat = host1x_sync_readl(host, HOST1X_SYNC_CBSTAT(ch->id));
191-
192-
host1x_debug_output(o, "%u-%s: ", ch->id, dev_name(ch->dev));
193-
194-
if (HOST1X_CHANNEL_DMACTRL_DMASTOP_V(dmactrl) ||
195-
!ch->cdma.push_buffer.mapped) {
196-
host1x_debug_output(o, "inactive\n\n");
197-
return;
198-
}
199-
200-
if (HOST1X_SYNC_CBSTAT_CBCLASS_V(cbstat) == HOST1X_CLASS_HOST1X &&
201-
HOST1X_SYNC_CBSTAT_CBOFFSET_V(cbstat) ==
202-
HOST1X_UCLASS_WAIT_SYNCPT)
203-
host1x_debug_output(o, "waiting on syncpt %d val %d\n",
204-
cbread >> 24, cbread & 0xffffff);
205-
else if (HOST1X_SYNC_CBSTAT_CBCLASS_V(cbstat) ==
206-
HOST1X_CLASS_HOST1X &&
207-
HOST1X_SYNC_CBSTAT_CBOFFSET_V(cbstat) ==
208-
HOST1X_UCLASS_WAIT_SYNCPT_BASE) {
209-
base = (cbread >> 16) & 0xff;
210-
baseval =
211-
host1x_sync_readl(host, HOST1X_SYNC_SYNCPT_BASE(base));
212-
val = cbread & 0xffff;
213-
host1x_debug_output(o, "waiting on syncpt %d val %d (base %d = %d; offset = %d)\n",
214-
cbread >> 24, baseval + val, base,
215-
baseval, val);
216-
} else
217-
host1x_debug_output(o, "active class %02x, offset %04x, val %08x\n",
218-
HOST1X_SYNC_CBSTAT_CBCLASS_V(cbstat),
219-
HOST1X_SYNC_CBSTAT_CBOFFSET_V(cbstat),
220-
cbread);
221-
222-
host1x_debug_output(o, "DMAPUT %08x, DMAGET %08x, DMACTL %08x\n",
223-
dmaput, dmaget, dmactrl);
224-
host1x_debug_output(o, "CBREAD %08x, CBSTAT %08x\n", cbread, cbstat);
225-
226-
show_channel_gathers(o, cdma);
227-
host1x_debug_output(o, "\n");
228-
}
229-
230-
static void host1x_debug_show_channel_fifo(struct host1x *host,
231-
struct host1x_channel *ch,
232-
struct output *o)
233-
{
234-
u32 val, rd_ptr, wr_ptr, start, end;
235-
unsigned int data_count = 0;
236-
237-
host1x_debug_output(o, "%u: fifo:\n", ch->id);
238-
239-
val = host1x_ch_readl(ch, HOST1X_CHANNEL_FIFOSTAT);
240-
host1x_debug_output(o, "FIFOSTAT %08x\n", val);
241-
if (HOST1X_CHANNEL_FIFOSTAT_CFEMPTY_V(val)) {
242-
host1x_debug_output(o, "[empty]\n");
243-
return;
244-
}
245-
246-
host1x_sync_writel(host, 0x0, HOST1X_SYNC_CFPEEK_CTRL);
247-
host1x_sync_writel(host, HOST1X_SYNC_CFPEEK_CTRL_ENA_F(1) |
248-
HOST1X_SYNC_CFPEEK_CTRL_CHANNR_F(ch->id),
249-
HOST1X_SYNC_CFPEEK_CTRL);
250-
251-
val = host1x_sync_readl(host, HOST1X_SYNC_CFPEEK_PTRS);
252-
rd_ptr = HOST1X_SYNC_CFPEEK_PTRS_CF_RD_PTR_V(val);
253-
wr_ptr = HOST1X_SYNC_CFPEEK_PTRS_CF_WR_PTR_V(val);
254-
255-
val = host1x_sync_readl(host, HOST1X_SYNC_CF_SETUP(ch->id));
256-
start = HOST1X_SYNC_CF_SETUP_BASE_V(val);
257-
end = HOST1X_SYNC_CF_SETUP_LIMIT_V(val);
258-
259-
do {
260-
host1x_sync_writel(host, 0x0, HOST1X_SYNC_CFPEEK_CTRL);
261-
host1x_sync_writel(host, HOST1X_SYNC_CFPEEK_CTRL_ENA_F(1) |
262-
HOST1X_SYNC_CFPEEK_CTRL_CHANNR_F(ch->id) |
263-
HOST1X_SYNC_CFPEEK_CTRL_ADDR_F(rd_ptr),
264-
HOST1X_SYNC_CFPEEK_CTRL);
265-
val = host1x_sync_readl(host, HOST1X_SYNC_CFPEEK_READ);
266-
267-
if (!data_count) {
268-
host1x_debug_output(o, "%08x:", val);
269-
data_count = show_channel_command(o, val);
270-
} else {
271-
host1x_debug_output(o, "%08x%s", val,
272-
data_count > 0 ? ", " : "])\n");
273-
data_count--;
274-
}
275-
276-
if (rd_ptr == end)
277-
rd_ptr = start;
278-
else
279-
rd_ptr++;
280-
} while (rd_ptr != wr_ptr);
281-
282-
if (data_count)
283-
host1x_debug_output(o, ", ...])\n");
284-
host1x_debug_output(o, "\n");
285-
286-
host1x_sync_writel(host, 0x0, HOST1X_SYNC_CFPEEK_CTRL);
287-
}
288-
289-
static void host1x_debug_show_mlocks(struct host1x *host, struct output *o)
290-
{
291-
unsigned int i;
292-
293-
host1x_debug_output(o, "---- mlocks ----\n");
294-
295-
for (i = 0; i < host1x_syncpt_nb_mlocks(host); i++) {
296-
u32 owner =
297-
host1x_sync_readl(host, HOST1X_SYNC_MLOCK_OWNER(i));
298-
if (HOST1X_SYNC_MLOCK_OWNER_CH_OWNS_V(owner))
299-
host1x_debug_output(o, "%u: locked by channel %u\n",
300-
i, HOST1X_SYNC_MLOCK_OWNER_CHID_V(owner));
301-
else if (HOST1X_SYNC_MLOCK_OWNER_CPU_OWNS_V(owner))
302-
host1x_debug_output(o, "%u: locked by cpu\n", i);
303-
else
304-
host1x_debug_output(o, "%u: unlocked\n", i);
305-
}
306-
307-
host1x_debug_output(o, "\n");
308-
}
177+
#if HOST1X_HW >= 6
178+
#include "debug_hw_1x06.c"
179+
#else
180+
#include "debug_hw_1x01.c"
181+
#endif
309182

310183
static const struct host1x_debug_ops host1x_debug_ops = {
311184
.show_channel_cdma = host1x_debug_show_channel_cdma,

0 commit comments

Comments
 (0)