xref: /openbmc/linux/drivers/gpu/host1x/job.h (revision 6579324a41cc414009a601738b70a53d6376325c)
1*6579324aSTerje Bergstrom /*
2*6579324aSTerje Bergstrom  * Tegra host1x Job
3*6579324aSTerje Bergstrom  *
4*6579324aSTerje Bergstrom  * Copyright (c) 2011-2013, NVIDIA Corporation.
5*6579324aSTerje Bergstrom  *
6*6579324aSTerje Bergstrom  * This program is free software; you can redistribute it and/or modify it
7*6579324aSTerje Bergstrom  * under the terms and conditions of the GNU General Public License,
8*6579324aSTerje Bergstrom  * version 2, as published by the Free Software Foundation.
9*6579324aSTerje Bergstrom  *
10*6579324aSTerje Bergstrom  * This program is distributed in the hope it will be useful, but WITHOUT
11*6579324aSTerje Bergstrom  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12*6579324aSTerje Bergstrom  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13*6579324aSTerje Bergstrom  * more details.
14*6579324aSTerje Bergstrom  *
15*6579324aSTerje Bergstrom  * You should have received a copy of the GNU General Public License
16*6579324aSTerje Bergstrom  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17*6579324aSTerje Bergstrom  */
18*6579324aSTerje Bergstrom 
19*6579324aSTerje Bergstrom #ifndef __HOST1X_JOB_H
20*6579324aSTerje Bergstrom #define __HOST1X_JOB_H
21*6579324aSTerje Bergstrom 
22*6579324aSTerje Bergstrom struct host1x_job_gather {
23*6579324aSTerje Bergstrom 	u32 words;
24*6579324aSTerje Bergstrom 	dma_addr_t base;
25*6579324aSTerje Bergstrom 	struct host1x_bo *bo;
26*6579324aSTerje Bergstrom 	int offset;
27*6579324aSTerje Bergstrom 	bool handled;
28*6579324aSTerje Bergstrom };
29*6579324aSTerje Bergstrom 
30*6579324aSTerje Bergstrom struct host1x_cmdbuf {
31*6579324aSTerje Bergstrom 	u32 handle;
32*6579324aSTerje Bergstrom 	u32 offset;
33*6579324aSTerje Bergstrom 	u32 words;
34*6579324aSTerje Bergstrom 	u32 pad;
35*6579324aSTerje Bergstrom };
36*6579324aSTerje Bergstrom 
37*6579324aSTerje Bergstrom struct host1x_reloc {
38*6579324aSTerje Bergstrom 	struct host1x_bo *cmdbuf;
39*6579324aSTerje Bergstrom 	u32 cmdbuf_offset;
40*6579324aSTerje Bergstrom 	struct host1x_bo *target;
41*6579324aSTerje Bergstrom 	u32 target_offset;
42*6579324aSTerje Bergstrom 	u32 shift;
43*6579324aSTerje Bergstrom 	u32 pad;
44*6579324aSTerje Bergstrom };
45*6579324aSTerje Bergstrom 
46*6579324aSTerje Bergstrom struct host1x_waitchk {
47*6579324aSTerje Bergstrom 	struct host1x_bo *bo;
48*6579324aSTerje Bergstrom 	u32 offset;
49*6579324aSTerje Bergstrom 	u32 syncpt_id;
50*6579324aSTerje Bergstrom 	u32 thresh;
51*6579324aSTerje Bergstrom };
52*6579324aSTerje Bergstrom 
53*6579324aSTerje Bergstrom struct host1x_job_unpin_data {
54*6579324aSTerje Bergstrom 	struct host1x_bo *bo;
55*6579324aSTerje Bergstrom 	struct sg_table *sgt;
56*6579324aSTerje Bergstrom };
57*6579324aSTerje Bergstrom 
58*6579324aSTerje Bergstrom /*
59*6579324aSTerje Bergstrom  * Each submit is tracked as a host1x_job.
60*6579324aSTerje Bergstrom  */
61*6579324aSTerje Bergstrom struct host1x_job {
62*6579324aSTerje Bergstrom 	/* When refcount goes to zero, job can be freed */
63*6579324aSTerje Bergstrom 	struct kref ref;
64*6579324aSTerje Bergstrom 
65*6579324aSTerje Bergstrom 	/* List entry */
66*6579324aSTerje Bergstrom 	struct list_head list;
67*6579324aSTerje Bergstrom 
68*6579324aSTerje Bergstrom 	/* Channel where job is submitted to */
69*6579324aSTerje Bergstrom 	struct host1x_channel *channel;
70*6579324aSTerje Bergstrom 
71*6579324aSTerje Bergstrom 	u32 client;
72*6579324aSTerje Bergstrom 
73*6579324aSTerje Bergstrom 	/* Gathers and their memory */
74*6579324aSTerje Bergstrom 	struct host1x_job_gather *gathers;
75*6579324aSTerje Bergstrom 	unsigned int num_gathers;
76*6579324aSTerje Bergstrom 
77*6579324aSTerje Bergstrom 	/* Wait checks to be processed at submit time */
78*6579324aSTerje Bergstrom 	struct host1x_waitchk *waitchk;
79*6579324aSTerje Bergstrom 	unsigned int num_waitchk;
80*6579324aSTerje Bergstrom 	u32 waitchk_mask;
81*6579324aSTerje Bergstrom 
82*6579324aSTerje Bergstrom 	/* Array of handles to be pinned & unpinned */
83*6579324aSTerje Bergstrom 	struct host1x_reloc *relocarray;
84*6579324aSTerje Bergstrom 	unsigned int num_relocs;
85*6579324aSTerje Bergstrom 	struct host1x_job_unpin_data *unpins;
86*6579324aSTerje Bergstrom 	unsigned int num_unpins;
87*6579324aSTerje Bergstrom 
88*6579324aSTerje Bergstrom 	dma_addr_t *addr_phys;
89*6579324aSTerje Bergstrom 	dma_addr_t *gather_addr_phys;
90*6579324aSTerje Bergstrom 	dma_addr_t *reloc_addr_phys;
91*6579324aSTerje Bergstrom 
92*6579324aSTerje Bergstrom 	/* Sync point id, number of increments and end related to the submit */
93*6579324aSTerje Bergstrom 	u32 syncpt_id;
94*6579324aSTerje Bergstrom 	u32 syncpt_incrs;
95*6579324aSTerje Bergstrom 	u32 syncpt_end;
96*6579324aSTerje Bergstrom 
97*6579324aSTerje Bergstrom 	/* Maximum time to wait for this job */
98*6579324aSTerje Bergstrom 	unsigned int timeout;
99*6579324aSTerje Bergstrom 
100*6579324aSTerje Bergstrom 	/* Index and number of slots used in the push buffer */
101*6579324aSTerje Bergstrom 	unsigned int first_get;
102*6579324aSTerje Bergstrom 	unsigned int num_slots;
103*6579324aSTerje Bergstrom 
104*6579324aSTerje Bergstrom 	/* Copy of gathers */
105*6579324aSTerje Bergstrom 	size_t gather_copy_size;
106*6579324aSTerje Bergstrom 	dma_addr_t gather_copy;
107*6579324aSTerje Bergstrom 	u8 *gather_copy_mapped;
108*6579324aSTerje Bergstrom 
109*6579324aSTerje Bergstrom 	/* Check if register is marked as an address reg */
110*6579324aSTerje Bergstrom 	int (*is_addr_reg)(struct device *dev, u32 reg, u32 class);
111*6579324aSTerje Bergstrom 
112*6579324aSTerje Bergstrom 	/* Request a SETCLASS to this class */
113*6579324aSTerje Bergstrom 	u32 class;
114*6579324aSTerje Bergstrom 
115*6579324aSTerje Bergstrom 	/* Add a channel wait for previous ops to complete */
116*6579324aSTerje Bergstrom 	bool serialize;
117*6579324aSTerje Bergstrom };
118*6579324aSTerje Bergstrom /*
119*6579324aSTerje Bergstrom  * Allocate memory for a job. Just enough memory will be allocated to
120*6579324aSTerje Bergstrom  * accomodate the submit.
121*6579324aSTerje Bergstrom  */
122*6579324aSTerje Bergstrom struct host1x_job *host1x_job_alloc(struct host1x_channel *ch,
123*6579324aSTerje Bergstrom 				    u32 num_cmdbufs, u32 num_relocs,
124*6579324aSTerje Bergstrom 				    u32 num_waitchks);
125*6579324aSTerje Bergstrom 
126*6579324aSTerje Bergstrom /*
127*6579324aSTerje Bergstrom  * Add a gather to a job.
128*6579324aSTerje Bergstrom  */
129*6579324aSTerje Bergstrom void host1x_job_add_gather(struct host1x_job *job, struct host1x_bo *mem_id,
130*6579324aSTerje Bergstrom 			   u32 words, u32 offset);
131*6579324aSTerje Bergstrom 
132*6579324aSTerje Bergstrom /*
133*6579324aSTerje Bergstrom  * Increment reference going to host1x_job.
134*6579324aSTerje Bergstrom  */
135*6579324aSTerje Bergstrom struct host1x_job *host1x_job_get(struct host1x_job *job);
136*6579324aSTerje Bergstrom 
137*6579324aSTerje Bergstrom /*
138*6579324aSTerje Bergstrom  * Decrement reference job, free if goes to zero.
139*6579324aSTerje Bergstrom  */
140*6579324aSTerje Bergstrom void host1x_job_put(struct host1x_job *job);
141*6579324aSTerje Bergstrom 
142*6579324aSTerje Bergstrom /*
143*6579324aSTerje Bergstrom  * Pin memory related to job. This handles relocation of addresses to the
144*6579324aSTerje Bergstrom  * host1x address space. Handles both the gather memory and any other memory
145*6579324aSTerje Bergstrom  * referred to from the gather buffers.
146*6579324aSTerje Bergstrom  *
147*6579324aSTerje Bergstrom  * Handles also patching out host waits that would wait for an expired sync
148*6579324aSTerje Bergstrom  * point value.
149*6579324aSTerje Bergstrom  */
150*6579324aSTerje Bergstrom int host1x_job_pin(struct host1x_job *job, struct device *dev);
151*6579324aSTerje Bergstrom 
152*6579324aSTerje Bergstrom /*
153*6579324aSTerje Bergstrom  * Unpin memory related to job.
154*6579324aSTerje Bergstrom  */
155*6579324aSTerje Bergstrom void host1x_job_unpin(struct host1x_job *job);
156*6579324aSTerje Bergstrom 
157*6579324aSTerje Bergstrom /*
158*6579324aSTerje Bergstrom  * Dump contents of job to debug output.
159*6579324aSTerje Bergstrom  */
160*6579324aSTerje Bergstrom void host1x_job_dump(struct device *dev, struct host1x_job *job);
161*6579324aSTerje Bergstrom 
162*6579324aSTerje Bergstrom #endif
163