blob: 5cdf7aa75be501722e4716488f92305c41e0a0a2 [file] [log] [blame]
Alex Dai33a732f2015-08-12 15:43:36 +01001/*
2 * Copyright © 2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 */
24#ifndef _INTEL_GUC_H_
25#define _INTEL_GUC_H_
26
27#include "intel_guc_fwif.h"
28#include "i915_guc_reg.h"
Dave Gordon0b63bb12016-06-20 15:18:07 +010029#include "intel_ringbuffer.h"
Alex Dai33a732f2015-08-12 15:43:36 +010030
Chris Wilsone73bdd22016-04-13 17:35:01 +010031struct drm_i915_gem_request;
32
Dave Gordon86e06cc2016-04-19 16:08:36 +010033/*
34 * This structure primarily describes the GEM object shared with the GuC.
35 * The GEM object is held for the entire lifetime of our interaction with
36 * the GuC, being allocated before the GuC is loaded with its firmware.
37 * Because there's no way to update the address used by the GuC after
38 * initialisation, the shared object must stay pinned into the GGTT as
39 * long as the GuC is in use. We also keep the first page (only) mapped
40 * into kernel address space, as it includes shared data that must be
41 * updated on every request submission.
42 *
43 * The single GEM object described here is actually made up of several
44 * separate areas, as far as the GuC is concerned. The first page (kept
45 * kmap'd) includes the "process decriptor" which holds sequence data for
46 * the doorbell, and one cacheline which actually *is* the doorbell; a
47 * write to this will "ring the doorbell" (i.e. send an interrupt to the
48 * GuC). The subsequent pages of the client object constitute the work
49 * queue (a circular array of work items), again described in the process
50 * descriptor. Work queue pages are mapped momentarily as required.
51 *
Dave Gordon551aaec2016-05-13 15:36:33 +010052 * We also keep a few statistics on failures. Ideally, these should all
53 * be zero!
54 * no_wq_space: times that the submission pre-check found no space was
55 * available in the work queue (note, the queue is shared,
56 * not per-engine). It is OK for this to be nonzero, but
57 * it should not be huge!
58 * q_fail: failed to enqueue a work item. This should never happen,
59 * because we check for space beforehand.
60 * b_fail: failed to ring the doorbell. This should never happen, unless
61 * somehow the hardware misbehaves, or maybe if the GuC firmware
62 * crashes? We probably need to reset the GPU to recover.
63 * retcode: errno from last guc_submit()
Dave Gordon86e06cc2016-04-19 16:08:36 +010064 */
Dave Gordon44a28b12015-08-12 15:43:41 +010065struct i915_guc_client {
Chris Wilson8b797af2016-08-15 10:48:51 +010066 struct i915_vma *vma;
Dave Gordon0d92a6a2016-04-19 16:08:34 +010067 void *client_base; /* first page (only) of above */
Chris Wilsone2efd132016-05-24 14:53:34 +010068 struct i915_gem_context *owner;
Dave Gordon44a28b12015-08-12 15:43:41 +010069 struct intel_guc *guc;
Dave Gordone02757d2016-08-09 15:19:21 +010070
71 uint32_t engines; /* bitmap of (host) engine ids */
Dave Gordon44a28b12015-08-12 15:43:41 +010072 uint32_t priority;
73 uint32_t ctx_index;
Dave Gordon44a28b12015-08-12 15:43:41 +010074 uint32_t proc_desc_offset;
Dave Gordon774439e12016-08-09 15:19:23 +010075
Dave Gordon44a28b12015-08-12 15:43:41 +010076 uint32_t doorbell_offset;
77 uint32_t cookie;
78 uint16_t doorbell_id;
Dave Gordon774439e12016-08-09 15:19:23 +010079 uint16_t padding[3]; /* Maintain alignment */
Dave Gordon44a28b12015-08-12 15:43:41 +010080
Chris Wilsondadd4812016-09-09 14:11:57 +010081 spinlock_t wq_lock;
Dave Gordon44a28b12015-08-12 15:43:41 +010082 uint32_t wq_offset;
83 uint32_t wq_size;
Dave Gordon44a28b12015-08-12 15:43:41 +010084 uint32_t wq_tail;
Chris Wilsondadd4812016-09-09 14:11:57 +010085 uint32_t wq_rsvd;
Dave Gordon551aaec2016-05-13 15:36:33 +010086 uint32_t no_wq_space;
Dave Gordon44a28b12015-08-12 15:43:41 +010087 uint32_t b_fail;
88 int retcode;
Dave Gordon551aaec2016-05-13 15:36:33 +010089
90 /* Per-engine counts of GuC submissions */
Dave Gordon0b63bb12016-06-20 15:18:07 +010091 uint64_t submissions[I915_NUM_ENGINES];
Dave Gordon44a28b12015-08-12 15:43:41 +010092};
93
Alex Dai33a732f2015-08-12 15:43:36 +010094enum intel_guc_fw_status {
95 GUC_FIRMWARE_FAIL = -1,
96 GUC_FIRMWARE_NONE = 0,
97 GUC_FIRMWARE_PENDING,
98 GUC_FIRMWARE_SUCCESS
99};
100
101/*
102 * This structure encapsulates all the data needed during the process
103 * of fetching, caching, and loading the firmware image into the GuC.
104 */
105struct intel_guc_fw {
106 struct drm_device * guc_dev;
107 const char * guc_fw_path;
108 size_t guc_fw_size;
109 struct drm_i915_gem_object * guc_fw_obj;
110 enum intel_guc_fw_status guc_fw_fetch_status;
111 enum intel_guc_fw_status guc_fw_load_status;
112
113 uint16_t guc_fw_major_wanted;
114 uint16_t guc_fw_minor_wanted;
115 uint16_t guc_fw_major_found;
116 uint16_t guc_fw_minor_found;
Alex Daifeda33e2015-10-19 16:10:54 -0700117
118 uint32_t header_size;
119 uint32_t header_offset;
120 uint32_t rsa_size;
121 uint32_t rsa_offset;
122 uint32_t ucode_size;
123 uint32_t ucode_offset;
Alex Dai33a732f2015-08-12 15:43:36 +0100124};
125
126struct intel_guc {
127 struct intel_guc_fw guc_fw;
Alex Dai33a732f2015-08-12 15:43:36 +0100128 uint32_t log_flags;
Chris Wilson8b797af2016-08-15 10:48:51 +0100129 struct i915_vma *log_vma;
Alex Daibac427f2015-08-12 15:43:39 +0100130
Chris Wilson8b797af2016-08-15 10:48:51 +0100131 struct i915_vma *ads_vma;
132 struct i915_vma *ctx_pool_vma;
Alex Daibac427f2015-08-12 15:43:39 +0100133 struct ida ctx_ids;
Dave Gordon44a28b12015-08-12 15:43:41 +0100134
135 struct i915_guc_client *execbuf_client;
136
Dave Gordon44a28b12015-08-12 15:43:41 +0100137 DECLARE_BITMAP(doorbell_bitmap, GUC_MAX_DOORBELLS);
138 uint32_t db_cacheline; /* Cyclic counter mod pagesize */
139
140 /* Action status & statistics */
141 uint64_t action_count; /* Total commands issued */
142 uint32_t action_cmd; /* Last command word */
143 uint32_t action_status; /* Last return status */
144 uint32_t action_fail; /* Total number of failures */
145 int32_t action_err; /* Last error code */
146
Dave Gordon0b63bb12016-06-20 15:18:07 +0100147 uint64_t submissions[I915_NUM_ENGINES];
148 uint32_t last_seqno[I915_NUM_ENGINES];
Alex Dai33a732f2015-08-12 15:43:36 +0100149};
150
151/* intel_guc_loader.c */
Dave Gordonf09d6752016-05-13 15:36:29 +0100152extern void intel_guc_init(struct drm_device *dev);
153extern int intel_guc_setup(struct drm_device *dev);
154extern void intel_guc_fini(struct drm_device *dev);
Alex Dai33a732f2015-08-12 15:43:36 +0100155extern const char *intel_guc_fw_status_repr(enum intel_guc_fw_status status);
Alex Daia1c41992015-09-30 09:46:37 -0700156extern int intel_guc_suspend(struct drm_device *dev);
157extern int intel_guc_resume(struct drm_device *dev);
Alex Dai33a732f2015-08-12 15:43:36 +0100158
Alex Daibac427f2015-08-12 15:43:39 +0100159/* i915_guc_submission.c */
Dave Gordonbeffa512016-06-10 18:29:26 +0100160int i915_guc_submission_init(struct drm_i915_private *dev_priv);
161int i915_guc_submission_enable(struct drm_i915_private *dev_priv);
Dave Gordon7a9347f2016-09-12 21:19:37 +0100162int i915_guc_wq_reserve(struct drm_i915_gem_request *rq);
Chris Wilson449f6612016-10-07 07:53:27 +0100163void i915_guc_wq_unreserve(struct drm_i915_gem_request *request);
Dave Gordonbeffa512016-06-10 18:29:26 +0100164void i915_guc_submission_disable(struct drm_i915_private *dev_priv);
165void i915_guc_submission_fini(struct drm_i915_private *dev_priv);
Alex Daibac427f2015-08-12 15:43:39 +0100166
Alex Dai33a732f2015-08-12 15:43:36 +0100167#endif