aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/imagination/pvr_job.h
blob: 0ca003c5c4751e6fb5a9fda84b37dd1787e6196a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
/* Copyright (c) 2023 Imagination Technologies Ltd. */

#ifndef PVR_JOB_H
#define PVR_JOB_H

#include <uapi/drm/pvr_drm.h>

#include <linux/kref.h>
#include <linux/types.h>

#include <drm/drm_gem.h>
#include <drm/gpu_scheduler.h>

#include "pvr_power.h"

/* Forward declaration from "pvr_context.h". */
struct pvr_context;

/* Forward declarations from "pvr_device.h". */
struct pvr_device;
struct pvr_file;

/* Forward declarations from "pvr_hwrt.h". */
struct pvr_hwrt_data;

/* Forward declaration from "pvr_queue.h". */
struct pvr_queue;

struct pvr_job {
	/** @base: drm_sched_job object. */
	struct drm_sched_job base;

	/** @ref_count: Refcount for job. */
	struct kref ref_count;

	/** @type: Type of job. */
	enum drm_pvr_job_type type;

	/** @id: Job ID number. */
	u32 id;

	/**
	 * @paired_job: Job paired to this job.
	 *
	 * This field is only meaningful for geometry and fragment jobs.
	 *
	 * Paired jobs are executed on the same context, and need to be submitted
	 * atomically to the FW, to make sure the partial render logic has a
	 * fragment job to execute when the Parameter Manager runs out of memory.
	 *
	 * The geometry job should point to the fragment job it's paired with,
	 * and the fragment job should point to the geometry job it's paired with.
	 */
	struct pvr_job *paired_job;

	/** @cccb_fence: Fence used to wait for CCCB space. */
	struct dma_fence *cccb_fence;

	/** @kccb_fence: Fence used to wait for KCCB space. */
	struct dma_fence *kccb_fence;

	/** @done_fence: Fence to signal when the job is done. */
	struct dma_fence *done_fence;

	/** @pvr_dev: Device pointer. */
	struct pvr_device *pvr_dev;

	/** @ctx: Pointer to owning context. */
	struct pvr_context *ctx;

	/** @cmd: Command data. Format depends on @type. */
	void *cmd;

	/** @cmd_len: Length of command data, in bytes. */
	u32 cmd_len;

	/**
	 * @fw_ccb_cmd_type: Firmware CCB command type. Must be one of %ROGUE_FWIF_CCB_CMD_TYPE_*.
	 */
	u32 fw_ccb_cmd_type;

	/** @hwrt: HWRT object. Will be NULL for compute and transfer jobs. */
	struct pvr_hwrt_data *hwrt;

	/**
	 * @has_pm_ref: True if the job has a power ref, thus forcing the GPU to stay on until
	 * the job is done.
	 */
	bool has_pm_ref;
};

/**
 * pvr_job_get() - Take additional reference on job.
 * @job: Job pointer.
 *
 * Call pvr_job_put() to release.
 *
 * Returns:
 *  * The requested job on success, or
 *  * %NULL if no job pointer passed.
 */
static __always_inline struct pvr_job *
pvr_job_get(struct pvr_job *job)
{
	if (job)
		kref_get(&job->ref_count);

	return job;
}

void pvr_job_put(struct pvr_job *job);

/**
 * pvr_job_release_pm_ref() - Release the PM ref if the job acquired it.
 * @job: The job to release the PM ref on.
 */
static __always_inline void
pvr_job_release_pm_ref(struct pvr_job *job)
{
	if (job->has_pm_ref) {
		pvr_power_put(job->pvr_dev);
		job->has_pm_ref = false;
	}
}

/**
 * pvr_job_get_pm_ref() - Get a PM ref and attach it to the job.
 * @job: The job to attach the PM ref to.
 *
 * Return:
 *  * 0 on success, or
 *  * Any error returned by pvr_power_get() otherwise.
 */
static __always_inline int
pvr_job_get_pm_ref(struct pvr_job *job)
{
	int err;

	if (job->has_pm_ref)
		return 0;

	err = pvr_power_get(job->pvr_dev);
	if (!err)
		job->has_pm_ref = true;

	return err;
}

int pvr_job_wait_first_non_signaled_native_dep(struct pvr_job *job);

bool pvr_job_non_native_deps_done(struct pvr_job *job);

int pvr_job_fits_in_cccb(struct pvr_job *job, unsigned long native_dep_count);

void pvr_job_submit(struct pvr_job *job);

int pvr_submit_jobs(struct pvr_device *pvr_dev, struct pvr_file *pvr_file,
		    struct drm_pvr_ioctl_submit_jobs_args *args);

#endif /* PVR_JOB_H */