Merge drm/drm-next into drm-intel-next-queued
[sfrench/cifs-2.6.git] / drivers / gpu / drm / i915 / intel_uc_fw.h
1 /*
2  * Copyright © 2014-2017 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
25 #ifndef _INTEL_UC_FW_H_
26 #define _INTEL_UC_FW_H_
27
28 #include <linux/types.h>
29
30 struct drm_printer;
31 struct drm_i915_private;
32
33 /* Home of GuC, HuC and DMC firmwares */
34 #define INTEL_UC_FIRMWARE_URL "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915"
35
36 enum intel_uc_fw_status {
37         INTEL_UC_FIRMWARE_FAIL = -1,
38         INTEL_UC_FIRMWARE_NONE = 0,
39         INTEL_UC_FIRMWARE_PENDING,
40         INTEL_UC_FIRMWARE_SUCCESS
41 };
42
43 enum intel_uc_fw_type {
44         INTEL_UC_FW_TYPE_GUC,
45         INTEL_UC_FW_TYPE_HUC
46 };
47
48 /*
49  * This structure encapsulates all the data needed during the process
50  * of fetching, caching, and loading the firmware image into the uC.
51  */
52 struct intel_uc_fw {
53         const char *path;
54         size_t size;
55         struct drm_i915_gem_object *obj;
56         enum intel_uc_fw_status fetch_status;
57         enum intel_uc_fw_status load_status;
58
59         /*
60          * The firmware build process will generate a version header file with major and
61          * minor version defined. The versions are built into CSS header of firmware.
62          * i915 kernel driver set the minimal firmware version required per platform.
63          */
64         u16 major_ver_wanted;
65         u16 minor_ver_wanted;
66         u16 major_ver_found;
67         u16 minor_ver_found;
68
69         enum intel_uc_fw_type type;
70         u32 header_size;
71         u32 header_offset;
72         u32 rsa_size;
73         u32 rsa_offset;
74         u32 ucode_size;
75         u32 ucode_offset;
76 };
77
78 static inline
79 const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status)
80 {
81         switch (status) {
82         case INTEL_UC_FIRMWARE_FAIL:
83                 return "FAIL";
84         case INTEL_UC_FIRMWARE_NONE:
85                 return "NONE";
86         case INTEL_UC_FIRMWARE_PENDING:
87                 return "PENDING";
88         case INTEL_UC_FIRMWARE_SUCCESS:
89                 return "SUCCESS";
90         }
91         return "<invalid>";
92 }
93
94 static inline const char *intel_uc_fw_type_repr(enum intel_uc_fw_type type)
95 {
96         switch (type) {
97         case INTEL_UC_FW_TYPE_GUC:
98                 return "GuC";
99         case INTEL_UC_FW_TYPE_HUC:
100                 return "HuC";
101         }
102         return "uC";
103 }
104
105 static inline
106 void intel_uc_fw_init_early(struct intel_uc_fw *uc_fw,
107                             enum intel_uc_fw_type type)
108 {
109         uc_fw->path = NULL;
110         uc_fw->fetch_status = INTEL_UC_FIRMWARE_NONE;
111         uc_fw->load_status = INTEL_UC_FIRMWARE_NONE;
112         uc_fw->type = type;
113 }
114
115 static inline bool intel_uc_fw_is_selected(struct intel_uc_fw *uc_fw)
116 {
117         return uc_fw->path != NULL;
118 }
119
120 static inline bool intel_uc_fw_is_loaded(struct intel_uc_fw *uc_fw)
121 {
122         return uc_fw->load_status == INTEL_UC_FIRMWARE_SUCCESS;
123 }
124
125 static inline void intel_uc_fw_sanitize(struct intel_uc_fw *uc_fw)
126 {
127         if (intel_uc_fw_is_loaded(uc_fw))
128                 uc_fw->load_status = INTEL_UC_FIRMWARE_PENDING;
129 }
130
131 /**
132  * intel_uc_fw_get_upload_size() - Get size of firmware needed to be uploaded.
133  * @uc_fw: uC firmware.
134  *
135  * Get the size of the firmware and header that will be uploaded to WOPCM.
136  *
137  * Return: Upload firmware size, or zero on firmware fetch failure.
138  */
139 static inline u32 intel_uc_fw_get_upload_size(struct intel_uc_fw *uc_fw)
140 {
141         if (uc_fw->fetch_status != INTEL_UC_FIRMWARE_SUCCESS)
142                 return 0;
143
144         return uc_fw->header_size + uc_fw->ucode_size;
145 }
146
147 void intel_uc_fw_fetch(struct drm_i915_private *dev_priv,
148                        struct intel_uc_fw *uc_fw);
149 void intel_uc_fw_cleanup_fetch(struct intel_uc_fw *uc_fw);
150 int intel_uc_fw_upload(struct intel_uc_fw *uc_fw,
151                        int (*xfer)(struct intel_uc_fw *uc_fw));
152 int intel_uc_fw_init(struct intel_uc_fw *uc_fw);
153 void intel_uc_fw_fini(struct intel_uc_fw *uc_fw);
154 u32 intel_uc_fw_ggtt_offset(struct intel_uc_fw *uc_fw);
155 void intel_uc_fw_dump(const struct intel_uc_fw *uc_fw, struct drm_printer *p);
156
157 #endif