Subversion Repositories Kolibri OS

Rev

Rev 6660 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6660 Rev 6937
1
/*
1
/*
2
 * Copyright © 2014 Intel Corporation
2
 * Copyright © 2014 Intel Corporation
3
 *
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a
4
 * Permission is hereby granted, free of charge, to any person obtaining a
5
 * copy of this software and associated documentation files (the "Software"),
5
 * copy of this software and associated documentation files (the "Software"),
6
 * to deal in the Software without restriction, including without limitation
6
 * to deal in the Software without restriction, including without limitation
7
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
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
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:
9
 * Software is furnished to do so, subject to the following conditions:
10
 *
10
 *
11
 * The above copyright notice and this permission notice (including the next
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
12
 * paragraph) shall be included in all copies or substantial portions of the
13
 * Software.
13
 * Software.
14
 *
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
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,
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
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
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
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
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
 * IN THE SOFTWARE.
21
 * IN THE SOFTWARE.
22
 *
22
 *
23
 */
23
 */
24
#include 
24
#include 
25
#include "i915_drv.h"
25
#include "i915_drv.h"
26
#include "i915_reg.h"
26
#include "i915_reg.h"
27
 
27
 
28
/**
28
/**
29
 * DOC: csr support for dmc
29
 * DOC: csr support for dmc
30
 *
30
 *
31
 * Display Context Save and Restore (CSR) firmware support added from gen9
31
 * Display Context Save and Restore (CSR) firmware support added from gen9
32
 * onwards to drive newly added DMC (Display microcontroller) in display
32
 * onwards to drive newly added DMC (Display microcontroller) in display
33
 * engine to save and restore the state of display engine when it enter into
33
 * engine to save and restore the state of display engine when it enter into
34
 * low-power state and comes back to normal.
34
 * low-power state and comes back to normal.
35
 *
35
 *
36
 * Firmware loading status will be one of the below states: FW_UNINITIALIZED,
36
 * Firmware loading status will be one of the below states: FW_UNINITIALIZED,
37
 * FW_LOADED, FW_FAILED.
37
 * FW_LOADED, FW_FAILED.
38
 *
38
 *
39
 * Once the firmware is written into the registers status will be moved from
39
 * Once the firmware is written into the registers status will be moved from
40
 * FW_UNINITIALIZED to FW_LOADED and for any erroneous condition status will
40
 * FW_UNINITIALIZED to FW_LOADED and for any erroneous condition status will
41
 * be moved to FW_FAILED.
41
 * be moved to FW_FAILED.
42
 */
42
 */
43
 
43
 
44
#define I915_CSR_SKL "i915/skl_dmc_ver1.bin"
44
#define I915_CSR_SKL "i915/skl_dmc_ver1.bin"
45
#define I915_CSR_BXT "i915/bxt_dmc_ver1.bin"
45
#define I915_CSR_BXT "i915/bxt_dmc_ver1.bin"
46
 
46
 
47
MODULE_FIRMWARE(I915_CSR_SKL);
47
MODULE_FIRMWARE(I915_CSR_SKL);
48
MODULE_FIRMWARE(I915_CSR_BXT);
48
MODULE_FIRMWARE(I915_CSR_BXT);
49
 
-
 
50
/*
49
 
51
* SKL CSR registers for DC5 and DC6
50
#define SKL_CSR_VERSION_REQUIRED	CSR_VERSION(1, 23)
52
*/
-
 
53
#define CSR_PROGRAM(i)			(0x80000 + (i) * 4)
-
 
54
#define CSR_SSP_BASE_ADDR_GEN9		0x00002FC0
-
 
55
#define CSR_HTP_ADDR_SKL		0x00500034
-
 
56
#define CSR_SSP_BASE			0x8F074
-
 
57
#define CSR_HTP_SKL			0x8F004
-
 
58
#define CSR_LAST_WRITE			0x8F034
-
 
59
#define CSR_LAST_WRITE_VALUE		0xc003b400
-
 
60
/* MMIO address range for CSR program (0x80000 - 0x82FFF) */
51
 
61
#define CSR_MAX_FW_SIZE			0x2FFF
52
#define CSR_MAX_FW_SIZE			0x2FFF
62
#define CSR_DEFAULT_FW_OFFSET		0xFFFFFFFF
-
 
63
#define CSR_MMIO_START_RANGE	0x80000
-
 
64
#define CSR_MMIO_END_RANGE		0x8FFFF
53
#define CSR_DEFAULT_FW_OFFSET		0xFFFFFFFF
65
 
54
 
66
struct intel_css_header {
55
struct intel_css_header {
67
	/* 0x09 for DMC */
56
	/* 0x09 for DMC */
68
	uint32_t module_type;
57
	uint32_t module_type;
69
 
58
 
70
	/* Includes the DMC specific header in dwords */
59
	/* Includes the DMC specific header in dwords */
71
	uint32_t header_len;
60
	uint32_t header_len;
72
 
61
 
73
	/* always value would be 0x10000 */
62
	/* always value would be 0x10000 */
74
	uint32_t header_ver;
63
	uint32_t header_ver;
75
 
64
 
76
	/* Not used */
65
	/* Not used */
77
	uint32_t module_id;
66
	uint32_t module_id;
78
 
67
 
79
	/* Not used */
68
	/* Not used */
80
	uint32_t module_vendor;
69
	uint32_t module_vendor;
81
 
70
 
82
	/* in YYYYMMDD format */
71
	/* in YYYYMMDD format */
83
	uint32_t date;
72
	uint32_t date;
84
 
73
 
85
	/* Size in dwords (CSS_Headerlen + PackageHeaderLen + dmc FWsLen)/4 */
74
	/* Size in dwords (CSS_Headerlen + PackageHeaderLen + dmc FWsLen)/4 */
86
	uint32_t size;
75
	uint32_t size;
87
 
76
 
88
	/* Not used */
77
	/* Not used */
89
	uint32_t key_size;
78
	uint32_t key_size;
90
 
79
 
91
	/* Not used */
80
	/* Not used */
92
	uint32_t modulus_size;
81
	uint32_t modulus_size;
93
 
82
 
94
	/* Not used */
83
	/* Not used */
95
	uint32_t exponent_size;
84
	uint32_t exponent_size;
96
 
85
 
97
	/* Not used */
86
	/* Not used */
98
	uint32_t reserved1[12];
87
	uint32_t reserved1[12];
99
 
88
 
100
	/* Major Minor */
89
	/* Major Minor */
101
	uint32_t version;
90
	uint32_t version;
102
 
91
 
103
	/* Not used */
92
	/* Not used */
104
	uint32_t reserved2[8];
93
	uint32_t reserved2[8];
105
 
94
 
106
	/* Not used */
95
	/* Not used */
107
	uint32_t kernel_header_info;
96
	uint32_t kernel_header_info;
108
} __packed;
97
} __packed;
109
 
98
 
110
struct intel_fw_info {
99
struct intel_fw_info {
111
	uint16_t reserved1;
100
	uint16_t reserved1;
112
 
101
 
113
	/* Stepping (A, B, C, ..., *). * is a wildcard */
102
	/* Stepping (A, B, C, ..., *). * is a wildcard */
114
	char stepping;
103
	char stepping;
115
 
104
 
116
	/* Sub-stepping (0, 1, ..., *). * is a wildcard */
105
	/* Sub-stepping (0, 1, ..., *). * is a wildcard */
117
	char substepping;
106
	char substepping;
118
 
107
 
119
	uint32_t offset;
108
	uint32_t offset;
120
	uint32_t reserved2;
109
	uint32_t reserved2;
121
} __packed;
110
} __packed;
122
 
111
 
123
struct intel_package_header {
112
struct intel_package_header {
124
	/* DMC container header length in dwords */
113
	/* DMC container header length in dwords */
125
	unsigned char header_len;
114
	unsigned char header_len;
126
 
115
 
127
	/* always value would be 0x01 */
116
	/* always value would be 0x01 */
128
	unsigned char header_ver;
117
	unsigned char header_ver;
129
 
118
 
130
	unsigned char reserved[10];
119
	unsigned char reserved[10];
131
 
120
 
132
	/* Number of valid entries in the FWInfo array below */
121
	/* Number of valid entries in the FWInfo array below */
133
	uint32_t num_entries;
122
	uint32_t num_entries;
134
 
123
 
135
	struct intel_fw_info fw_info[20];
124
	struct intel_fw_info fw_info[20];
136
} __packed;
125
} __packed;
137
 
126
 
138
struct intel_dmc_header {
127
struct intel_dmc_header {
139
	/* always value would be 0x40403E3E */
128
	/* always value would be 0x40403E3E */
140
	uint32_t signature;
129
	uint32_t signature;
141
 
130
 
142
	/* DMC binary header length */
131
	/* DMC binary header length */
143
	unsigned char header_len;
132
	unsigned char header_len;
144
 
133
 
145
	/* 0x01 */
134
	/* 0x01 */
146
	unsigned char header_ver;
135
	unsigned char header_ver;
147
 
136
 
148
	/* Reserved */
137
	/* Reserved */
149
	uint16_t dmcc_ver;
138
	uint16_t dmcc_ver;
150
 
139
 
151
	/* Major, Minor */
140
	/* Major, Minor */
152
	uint32_t	project;
141
	uint32_t	project;
153
 
142
 
154
	/* Firmware program size (excluding header) in dwords */
143
	/* Firmware program size (excluding header) in dwords */
155
	uint32_t	fw_size;
144
	uint32_t	fw_size;
156
 
145
 
157
	/* Major Minor version */
146
	/* Major Minor version */
158
	uint32_t fw_version;
147
	uint32_t fw_version;
159
 
148
 
160
	/* Number of valid MMIO cycles present. */
149
	/* Number of valid MMIO cycles present. */
161
	uint32_t mmio_count;
150
	uint32_t mmio_count;
162
 
151
 
163
	/* MMIO address */
152
	/* MMIO address */
164
	uint32_t mmioaddr[8];
153
	uint32_t mmioaddr[8];
165
 
154
 
166
	/* MMIO data */
155
	/* MMIO data */
167
	uint32_t mmiodata[8];
156
	uint32_t mmiodata[8];
168
 
157
 
169
	/* FW filename  */
158
	/* FW filename  */
170
	unsigned char dfile[32];
159
	unsigned char dfile[32];
171
 
160
 
172
	uint32_t reserved1[2];
161
	uint32_t reserved1[2];
173
} __packed;
162
} __packed;
174
 
163
 
175
struct stepping_info {
164
struct stepping_info {
176
	char stepping;
165
	char stepping;
177
	char substepping;
166
	char substepping;
178
};
167
};
-
 
168
 
-
 
169
/*
-
 
170
 * Kabylake derivated from Skylake H0, so SKL H0
-
 
171
 * is the right firmware for KBL A0 (revid 0).
-
 
172
 */
-
 
173
static const struct stepping_info kbl_stepping_info[] = {
-
 
174
	{'H', '0'}, {'I', '0'}
-
 
175
};
179
 
176
 
180
static const struct stepping_info skl_stepping_info[] = {
177
static const struct stepping_info skl_stepping_info[] = {
181
		{'A', '0'}, {'B', '0'}, {'C', '0'},
178
		{'A', '0'}, {'B', '0'}, {'C', '0'},
182
		{'D', '0'}, {'E', '0'}, {'F', '0'},
179
		{'D', '0'}, {'E', '0'}, {'F', '0'},
183
		{'G', '0'}, {'H', '0'}, {'I', '0'},
180
		{'G', '0'}, {'H', '0'}, {'I', '0'},
184
		{'J', '0'}, {'K', '0'}
181
		{'J', '0'}, {'K', '0'}
185
};
182
};
186
 
183
 
187
static struct stepping_info bxt_stepping_info[] = {
184
static const struct stepping_info bxt_stepping_info[] = {
188
	{'A', '0'}, {'A', '1'}, {'A', '2'},
185
	{'A', '0'}, {'A', '1'}, {'A', '2'},
189
	{'B', '0'}, {'B', '1'}, {'B', '2'}
186
	{'B', '0'}, {'B', '1'}, {'B', '2'}
190
};
187
};
191
 
188
 
192
static char intel_get_stepping(struct drm_device *dev)
189
static const struct stepping_info *intel_get_stepping_info(struct drm_device *dev)
193
{
-
 
194
	if (IS_SKYLAKE(dev) && (dev->pdev->revision <
-
 
195
			ARRAY_SIZE(skl_stepping_info)))
-
 
196
		return skl_stepping_info[dev->pdev->revision].stepping;
-
 
197
	else if (IS_BROXTON(dev) && (dev->pdev->revision <
190
{
198
				ARRAY_SIZE(bxt_stepping_info)))
-
 
199
		return bxt_stepping_info[dev->pdev->revision].stepping;
-
 
200
	else
191
	const struct stepping_info *si;
201
		return -ENODATA;
-
 
-
 
192
	unsigned int size;
202
}
193
 
203
 
-
 
-
 
194
	if (IS_KABYLAKE(dev)) {
204
static char intel_get_substepping(struct drm_device *dev)
195
		size = ARRAY_SIZE(kbl_stepping_info);
205
{
196
		si = kbl_stepping_info;
206
	if (IS_SKYLAKE(dev) && (dev->pdev->revision <
197
	} else if (IS_SKYLAKE(dev)) {
207
			ARRAY_SIZE(skl_stepping_info)))
198
		size = ARRAY_SIZE(skl_stepping_info);
208
		return skl_stepping_info[dev->pdev->revision].substepping;
199
		si = skl_stepping_info;
209
	else if (IS_BROXTON(dev) && (dev->pdev->revision <
200
	} else if (IS_BROXTON(dev)) {
210
			ARRAY_SIZE(bxt_stepping_info)))
201
		size = ARRAY_SIZE(bxt_stepping_info);
211
		return bxt_stepping_info[dev->pdev->revision].substepping;
202
		si = bxt_stepping_info;
212
	else
203
	} else {
213
		return -ENODATA;
-
 
214
}
-
 
215
 
204
		return NULL;
216
/**
-
 
217
 * intel_csr_load_status_get() - to get firmware loading status.
-
 
218
 * @dev_priv: i915 device.
-
 
219
 *
205
	}
220
 * This function helps to get the firmware loading status.
-
 
221
 *
-
 
222
 * Return: Firmware loading status.
-
 
223
 */
-
 
224
enum csr_state intel_csr_load_status_get(struct drm_i915_private *dev_priv)
-
 
225
{
-
 
226
	enum csr_state state;
-
 
227
 
-
 
228
	mutex_lock(&dev_priv->csr_lock);
206
 
229
	state = dev_priv->csr.state;
-
 
230
	mutex_unlock(&dev_priv->csr_lock);
-
 
231
 
-
 
232
	return state;
-
 
233
}
-
 
234
 
-
 
235
/**
-
 
236
 * intel_csr_load_status_set() - help to set firmware loading status.
-
 
237
 * @dev_priv: i915 device.
-
 
238
 * @state: enumeration of firmware loading status.
-
 
239
 *
-
 
240
 * Set the firmware loading status.
-
 
241
 */
-
 
242
void intel_csr_load_status_set(struct drm_i915_private *dev_priv,
-
 
243
			enum csr_state state)
-
 
244
{
207
	if (INTEL_REVID(dev) < size)
245
	mutex_lock(&dev_priv->csr_lock);
208
		return si + INTEL_REVID(dev);
246
	dev_priv->csr.state = state;
209
 
247
	mutex_unlock(&dev_priv->csr_lock);
210
	return NULL;
248
}
211
}
249
 
212
 
250
/**
213
/**
251
 * intel_csr_load_program() - write the firmware from memory to register.
214
 * intel_csr_load_program() - write the firmware from memory to register.
252
 * @dev: drm device.
215
 * @dev_priv: i915 drm device.
253
 *
216
 *
254
 * CSR firmware is read from a .bin file and kept in internal memory one time.
217
 * CSR firmware is read from a .bin file and kept in internal memory one time.
255
 * Everytime display comes back from low power state this function is called to
218
 * Everytime display comes back from low power state this function is called to
256
 * copy the firmware from internal memory to registers.
219
 * copy the firmware from internal memory to registers.
257
 */
220
 */
258
void intel_csr_load_program(struct drm_device *dev)
221
void intel_csr_load_program(struct drm_i915_private *dev_priv)
259
{
222
{
260
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
261
	u32 *payload = dev_priv->csr.dmc_payload;
223
	u32 *payload = dev_priv->csr.dmc_payload;
262
	uint32_t i, fw_size;
224
	uint32_t i, fw_size;
263
 
225
 
264
	if (!IS_GEN9(dev)) {
226
	if (!IS_GEN9(dev_priv)) {
265
		DRM_ERROR("No CSR support available for this platform\n");
227
		DRM_ERROR("No CSR support available for this platform\n");
266
		return;
228
		return;
267
	}
229
	}
268
 
-
 
269
	/*
-
 
270
	 * FIXME: Firmware gets lost on S3/S4, but not when entering system
-
 
271
	 * standby or suspend-to-idle (which is just like forced runtime pm).
230
 
272
	 * Unfortunately the ACPI subsystem doesn't yet give us a way to
231
	if (!dev_priv->csr.dmc_payload) {
273
	 * differentiate this, hence figure it out with this hack.
-
 
274
	 */
-
 
275
	if (I915_READ(CSR_PROGRAM(0)))
232
		DRM_ERROR("Tried to program CSR with empty payload\n");
-
 
233
		return;
276
		return;
-
 
277
 
234
	}
278
	mutex_lock(&dev_priv->csr_lock);
235
 
279
	fw_size = dev_priv->csr.dmc_fw_size;
236
	fw_size = dev_priv->csr.dmc_fw_size;
280
	for (i = 0; i < fw_size; i++)
237
	for (i = 0; i < fw_size; i++)
281
		I915_WRITE(CSR_PROGRAM(i), payload[i]);
238
		I915_WRITE(CSR_PROGRAM(i), payload[i]);
282
 
239
 
283
	for (i = 0; i < dev_priv->csr.mmio_count; i++) {
240
	for (i = 0; i < dev_priv->csr.mmio_count; i++) {
284
		I915_WRITE(dev_priv->csr.mmioaddr[i],
241
		I915_WRITE(dev_priv->csr.mmioaddr[i],
285
			dev_priv->csr.mmiodata[i]);
242
			dev_priv->csr.mmiodata[i]);
286
	}
243
	}
287
 
244
 
288
	dev_priv->csr.state = FW_LOADED;
-
 
289
	mutex_unlock(&dev_priv->csr_lock);
245
	dev_priv->csr.dc_state = 0;
290
}
246
}
-
 
247
 
291
 
248
static uint32_t *parse_csr_fw(struct drm_i915_private *dev_priv,
292
static void finish_csr_load(const struct firmware *fw, void *context)
-
 
293
{
249
			      const struct firmware *fw)
294
	struct drm_i915_private *dev_priv = context;
250
{
295
	struct drm_device *dev = dev_priv->dev;
251
	struct drm_device *dev = dev_priv->dev;
296
	struct intel_css_header *css_header;
252
	struct intel_css_header *css_header;
297
	struct intel_package_header *package_header;
253
	struct intel_package_header *package_header;
298
	struct intel_dmc_header *dmc_header;
254
	struct intel_dmc_header *dmc_header;
299
	struct intel_csr *csr = &dev_priv->csr;
255
	struct intel_csr *csr = &dev_priv->csr;
300
	char stepping = intel_get_stepping(dev);
256
	const struct stepping_info *stepping_info = intel_get_stepping_info(dev);
301
	char substepping = intel_get_substepping(dev);
257
	char stepping, substepping;
302
	uint32_t dmc_offset = CSR_DEFAULT_FW_OFFSET, readcount = 0, nbytes;
258
	uint32_t dmc_offset = CSR_DEFAULT_FW_OFFSET, readcount = 0, nbytes;
303
	uint32_t i;
259
	uint32_t i;
304
	uint32_t *dmc_payload;
260
	uint32_t *dmc_payload;
305
	bool fw_loaded = false;
-
 
306
 
261
 
307
	if (!fw) {
-
 
308
		i915_firmware_load_error_print(csr->fw_path, 0);
262
	if (!fw)
309
		goto out;
-
 
310
	}
263
		return NULL;
311
 
264
 
312
	if ((stepping == -ENODATA) || (substepping == -ENODATA)) {
265
	if (!stepping_info) {
313
		DRM_ERROR("Unknown stepping info, firmware loading failed\n");
266
		DRM_ERROR("Unknown stepping info, firmware loading failed\n");
-
 
267
		return NULL;
-
 
268
	}
-
 
269
 
314
		goto out;
270
	stepping = stepping_info->stepping;
315
	}
271
	substepping = stepping_info->substepping;
316
 
272
 
317
	/* Extract CSS Header information*/
273
	/* Extract CSS Header information*/
318
	css_header = (struct intel_css_header *)fw->data;
274
	css_header = (struct intel_css_header *)fw->data;
319
	if (sizeof(struct intel_css_header) !=
275
	if (sizeof(struct intel_css_header) !=
320
		(css_header->header_len * 4)) {
276
		(css_header->header_len * 4)) {
321
		DRM_ERROR("Firmware has wrong CSS header length %u bytes\n",
277
		DRM_ERROR("Firmware has wrong CSS header length %u bytes\n",
322
			(css_header->header_len * 4));
278
			(css_header->header_len * 4));
323
		goto out;
279
		return NULL;
-
 
280
	}
-
 
281
 
-
 
282
	csr->version = css_header->version;
-
 
283
 
-
 
284
	if (IS_SKYLAKE(dev) && csr->version < SKL_CSR_VERSION_REQUIRED) {
-
 
285
		DRM_INFO("Refusing to load old Skylake DMC firmware v%u.%u,"
-
 
286
			 " please upgrade to v%u.%u or later"
-
 
287
			 " [https://01.org/linuxgraphics/intel-linux-graphics-firmwares].\n",
-
 
288
			 CSR_VERSION_MAJOR(csr->version),
-
 
289
			 CSR_VERSION_MINOR(csr->version),
-
 
290
			 CSR_VERSION_MAJOR(SKL_CSR_VERSION_REQUIRED),
-
 
291
			 CSR_VERSION_MINOR(SKL_CSR_VERSION_REQUIRED));
-
 
292
		return NULL;
324
	}
293
	}
-
 
294
 
325
	readcount += sizeof(struct intel_css_header);
295
	readcount += sizeof(struct intel_css_header);
326
 
296
 
327
	/* Extract Package Header information*/
297
	/* Extract Package Header information*/
328
	package_header = (struct intel_package_header *)
298
	package_header = (struct intel_package_header *)
329
					&fw->data[readcount];
299
					&fw->data[readcount];
330
	if (sizeof(struct intel_package_header) !=
300
	if (sizeof(struct intel_package_header) !=
331
		(package_header->header_len * 4)) {
301
		(package_header->header_len * 4)) {
332
		DRM_ERROR("Firmware has wrong package header length %u bytes\n",
302
		DRM_ERROR("Firmware has wrong package header length %u bytes\n",
333
			(package_header->header_len * 4));
303
			(package_header->header_len * 4));
334
		goto out;
304
		return NULL;
335
	}
305
	}
336
	readcount += sizeof(struct intel_package_header);
306
	readcount += sizeof(struct intel_package_header);
337
 
307
 
338
	/* Search for dmc_offset to find firware binary. */
308
	/* Search for dmc_offset to find firware binary. */
339
	for (i = 0; i < package_header->num_entries; i++) {
309
	for (i = 0; i < package_header->num_entries; i++) {
340
		if (package_header->fw_info[i].substepping == '*' &&
310
		if (package_header->fw_info[i].substepping == '*' &&
341
			stepping == package_header->fw_info[i].stepping) {
311
			stepping == package_header->fw_info[i].stepping) {
342
			dmc_offset = package_header->fw_info[i].offset;
312
			dmc_offset = package_header->fw_info[i].offset;
343
			break;
313
			break;
344
		} else if (stepping == package_header->fw_info[i].stepping &&
314
		} else if (stepping == package_header->fw_info[i].stepping &&
345
			substepping == package_header->fw_info[i].substepping) {
315
			substepping == package_header->fw_info[i].substepping) {
346
			dmc_offset = package_header->fw_info[i].offset;
316
			dmc_offset = package_header->fw_info[i].offset;
347
			break;
317
			break;
348
		} else if (package_header->fw_info[i].stepping == '*' &&
318
		} else if (package_header->fw_info[i].stepping == '*' &&
349
			package_header->fw_info[i].substepping == '*')
319
			package_header->fw_info[i].substepping == '*')
350
			dmc_offset = package_header->fw_info[i].offset;
320
			dmc_offset = package_header->fw_info[i].offset;
351
	}
321
	}
352
	if (dmc_offset == CSR_DEFAULT_FW_OFFSET) {
322
	if (dmc_offset == CSR_DEFAULT_FW_OFFSET) {
353
		DRM_ERROR("Firmware not supported for %c stepping\n", stepping);
323
		DRM_ERROR("Firmware not supported for %c stepping\n", stepping);
354
		goto out;
324
		return NULL;
355
	}
325
	}
356
	readcount += dmc_offset;
326
	readcount += dmc_offset;
357
 
327
 
358
	/* Extract dmc_header information. */
328
	/* Extract dmc_header information. */
359
	dmc_header = (struct intel_dmc_header *)&fw->data[readcount];
329
	dmc_header = (struct intel_dmc_header *)&fw->data[readcount];
360
	if (sizeof(struct intel_dmc_header) != (dmc_header->header_len)) {
330
	if (sizeof(struct intel_dmc_header) != (dmc_header->header_len)) {
361
		DRM_ERROR("Firmware has wrong dmc header length %u bytes\n",
331
		DRM_ERROR("Firmware has wrong dmc header length %u bytes\n",
362
				(dmc_header->header_len));
332
				(dmc_header->header_len));
363
		goto out;
333
		return NULL;
364
	}
334
	}
365
	readcount += sizeof(struct intel_dmc_header);
335
	readcount += sizeof(struct intel_dmc_header);
366
 
336
 
367
	/* Cache the dmc header info. */
337
	/* Cache the dmc header info. */
368
	if (dmc_header->mmio_count > ARRAY_SIZE(csr->mmioaddr)) {
338
	if (dmc_header->mmio_count > ARRAY_SIZE(csr->mmioaddr)) {
369
		DRM_ERROR("Firmware has wrong mmio count %u\n",
339
		DRM_ERROR("Firmware has wrong mmio count %u\n",
370
						dmc_header->mmio_count);
340
						dmc_header->mmio_count);
371
		goto out;
341
		return NULL;
372
	}
342
	}
373
	csr->mmio_count = dmc_header->mmio_count;
343
	csr->mmio_count = dmc_header->mmio_count;
374
	for (i = 0; i < dmc_header->mmio_count; i++) {
344
	for (i = 0; i < dmc_header->mmio_count; i++) {
375
		if (dmc_header->mmioaddr[i] < CSR_MMIO_START_RANGE ||
345
		if (dmc_header->mmioaddr[i] < CSR_MMIO_START_RANGE ||
376
			dmc_header->mmioaddr[i] > CSR_MMIO_END_RANGE) {
346
			dmc_header->mmioaddr[i] > CSR_MMIO_END_RANGE) {
377
			DRM_ERROR(" Firmware has wrong mmio address 0x%x\n",
347
			DRM_ERROR(" Firmware has wrong mmio address 0x%x\n",
378
						dmc_header->mmioaddr[i]);
348
						dmc_header->mmioaddr[i]);
379
			goto out;
349
			return NULL;
380
		}
350
		}
381
		csr->mmioaddr[i] = dmc_header->mmioaddr[i];
351
		csr->mmioaddr[i] = _MMIO(dmc_header->mmioaddr[i]);
382
		csr->mmiodata[i] = dmc_header->mmiodata[i];
352
		csr->mmiodata[i] = dmc_header->mmiodata[i];
383
	}
353
	}
384
 
354
 
385
	/* fw_size is in dwords, so multiplied by 4 to convert into bytes. */
355
	/* fw_size is in dwords, so multiplied by 4 to convert into bytes. */
386
	nbytes = dmc_header->fw_size * 4;
356
	nbytes = dmc_header->fw_size * 4;
387
	if (nbytes > CSR_MAX_FW_SIZE) {
357
	if (nbytes > CSR_MAX_FW_SIZE) {
388
		DRM_ERROR("CSR firmware too big (%u) bytes\n", nbytes);
358
		DRM_ERROR("CSR firmware too big (%u) bytes\n", nbytes);
389
		goto out;
359
		return NULL;
390
	}
360
	}
391
	csr->dmc_fw_size = dmc_header->fw_size;
361
	csr->dmc_fw_size = dmc_header->fw_size;
392
 
362
 
393
	csr->dmc_payload = kmalloc(nbytes, GFP_KERNEL);
363
	dmc_payload = kmalloc(nbytes, GFP_KERNEL);
394
	if (!csr->dmc_payload) {
364
	if (!dmc_payload) {
395
		DRM_ERROR("Memory allocation failed for dmc payload\n");
365
		DRM_ERROR("Memory allocation failed for dmc payload\n");
396
		goto out;
366
		return NULL;
397
	}
-
 
398
 
367
	}
-
 
368
 
-
 
369
	memcpy(dmc_payload, &fw->data[readcount], nbytes);
-
 
370
 
-
 
371
	return dmc_payload;
-
 
372
}
-
 
373
 
-
 
374
static void csr_load_work_fn(struct drm_i915_private *dev_priv)
-
 
375
{
-
 
376
	struct intel_csr *csr;
-
 
377
	const struct firmware *fw;
-
 
378
	int ret;
-
 
379
 
-
 
380
	csr = &dev_priv->csr;
-
 
381
 
-
 
382
	ret = request_firmware(&fw, dev_priv->csr.fw_path,
-
 
383
			       &dev_priv->dev->pdev->dev);
-
 
384
	if (!fw)
-
 
385
		goto out;
-
 
386
 
-
 
387
	dev_priv->csr.dmc_payload = parse_csr_fw(dev_priv, fw);
399
	dmc_payload = csr->dmc_payload;
388
	if (!dev_priv->csr.dmc_payload)
400
	memcpy(dmc_payload, &fw->data[readcount], nbytes);
389
		goto out;
401
 
-
 
402
	/* load csr program during system boot, as needed for DC states */
-
 
403
	intel_csr_load_program(dev);
390
 
404
	fw_loaded = true;
391
	/* load csr program during system boot, as needed for DC states */
405
 
392
	intel_csr_load_program(dev_priv);
-
 
393
 
-
 
394
out:
-
 
395
	if (dev_priv->csr.dmc_payload) {
-
 
396
		intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
-
 
397
 
406
	DRM_DEBUG_KMS("Finished loading %s\n", dev_priv->csr.fw_path);
398
		DRM_INFO("Finished loading %s (v%u.%u)\n",
407
out:
399
			 dev_priv->csr.fw_path,
-
 
400
			 CSR_VERSION_MAJOR(csr->version),
408
	if (fw_loaded)
401
			 CSR_VERSION_MINOR(csr->version));
409
		intel_runtime_pm_put(dev_priv);
402
	} else {
410
	else
403
		DRM_ERROR("Failed to load DMC firmware, disabling rpm\n");
411
		intel_csr_load_status_set(dev_priv, FW_FAILED);
404
    }
412
 
405
 
413
	release_firmware(fw);
406
	release_firmware(fw);
414
}
407
}
415
 
408
 
416
/**
409
/**
417
 * intel_csr_ucode_init() - initialize the firmware loading.
410
 * intel_csr_ucode_init() - initialize the firmware loading.
418
 * @dev: drm device.
411
 * @dev_priv: i915 drm device.
419
 *
412
 *
420
 * This function is called at the time of loading the display driver to read
413
 * This function is called at the time of loading the display driver to read
421
 * firmware from a .bin file and copied into a internal memory.
414
 * firmware from a .bin file and copied into a internal memory.
422
 */
415
 */
423
void intel_csr_ucode_init(struct drm_device *dev)
416
void intel_csr_ucode_init(struct drm_i915_private *dev_priv)
424
{
417
{
425
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
426
	struct intel_csr *csr = &dev_priv->csr;
418
	struct intel_csr *csr = &dev_priv->csr;
427
	int ret;
-
 
428
 
419
 
429
	if (!HAS_CSR(dev))
420
	if (!HAS_CSR(dev_priv))
430
		return;
421
		return;
431
 
422
 
432
	if (IS_SKYLAKE(dev))
423
	if (IS_SKYLAKE(dev_priv))
433
		csr->fw_path = I915_CSR_SKL;
424
		csr->fw_path = I915_CSR_SKL;
434
	else if (IS_BROXTON(dev_priv))
425
	else if (IS_BROXTON(dev_priv))
435
		csr->fw_path = I915_CSR_BXT;
426
		csr->fw_path = I915_CSR_BXT;
436
	else {
427
	else {
437
		DRM_ERROR("Unexpected: no known CSR firmware for platform\n");
428
		DRM_ERROR("Unexpected: no known CSR firmware for platform\n");
438
		intel_csr_load_status_set(dev_priv, FW_FAILED);
-
 
439
		return;
429
		return;
440
	}
430
	}
441
#if 0
431
 
442
	DRM_DEBUG_KMS("Loading %s\n", csr->fw_path);
432
	DRM_DEBUG_KMS("Loading %s\n", csr->fw_path);
443
 
433
 
444
	/*
434
	/*
445
	 * Obtain a runtime pm reference, until CSR is loaded,
435
	 * Obtain a runtime pm reference, until CSR is loaded,
446
	 * to avoid entering runtime-suspend.
436
	 * to avoid entering runtime-suspend.
447
	 */
437
	 */
448
	intel_runtime_pm_get(dev_priv);
438
	intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
449
 
-
 
450
	/* CSR supported for platform, load firmware */
-
 
451
	ret = request_firmware_nowait(THIS_MODULE, true, csr->fw_path,
-
 
452
				&dev_priv->dev->pdev->dev,
439
 
453
				GFP_KERNEL, dev_priv,
-
 
454
				finish_csr_load);
-
 
455
	if (ret) {
-
 
456
		i915_firmware_load_error_print(csr->fw_path, ret);
-
 
457
		intel_csr_load_status_set(dev_priv, FW_FAILED);
-
 
458
	}
-
 
459
#endif
440
	csr_load_work_fn(dev_priv);
460
}
441
}
461
 
442
 
462
/**
443
/**
463
 * intel_csr_ucode_fini() - unload the CSR firmware.
444
 * intel_csr_ucode_fini() - unload the CSR firmware.
464
 * @dev: drm device.
445
 * @dev_priv: i915 drm device.
465
 *
446
 *
466
 * Firmmware unloading includes freeing the internal momory and reset the
447
 * Firmmware unloading includes freeing the internal momory and reset the
467
 * firmware loading status.
448
 * firmware loading status.
468
 */
449
 */
469
void intel_csr_ucode_fini(struct drm_device *dev)
450
void intel_csr_ucode_fini(struct drm_i915_private *dev_priv)
470
{
451
{
471
	struct drm_i915_private *dev_priv = dev->dev_private;
-
 
472
 
-
 
473
	if (!HAS_CSR(dev))
452
	if (!HAS_CSR(dev_priv))
474
		return;
453
		return;
475
 
-
 
476
	intel_csr_load_status_set(dev_priv, FW_FAILED);
-
 
477
	kfree(dev_priv->csr.dmc_payload);
-
 
478
}
-
 
479
 
-
 
480
void assert_csr_loaded(struct drm_i915_private *dev_priv)
-
 
481
{
454
 
482
	WARN_ONCE(intel_csr_load_status_get(dev_priv) != FW_LOADED,
-
 
483
		  "CSR is not loaded.\n");
-
 
484
	WARN_ONCE(!I915_READ(CSR_PROGRAM(0)),
-
 
485
		  "CSR program storage start is NULL\n");
-
 
486
	WARN_ONCE(!I915_READ(CSR_SSP_BASE), "CSR SSP Base Not fine\n");
455
 
487
	WARN_ONCE(!I915_READ(CSR_HTP_SKL), "CSR HTP Not fine\n");
456
	kfree(dev_priv->csr.dmc_payload);
488
}
457
}
489
>
-
 
490
>
-
 
491
>
-
 
492
>
-