intel_csr.c 17.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright © 2014 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 */
24

25
#include <linux/firmware.h>
26

27 28
#include "i915_drv.h"
#include "i915_reg.h"
29
#include "intel_csr.h"
30

31 32 33 34 35 36 37 38 39
/**
 * DOC: csr support for dmc
 *
 * Display Context Save and Restore (CSR) firmware support added from gen9
 * onwards to drive newly added DMC (Display microcontroller) in display
 * engine to save and restore the state of display engine when it enter into
 * low-power state and comes back to normal.
 */

40 41
#define GEN12_CSR_MAX_FW_SIZE		ICL_CSR_MAX_FW_SIZE

42
#define ICL_CSR_PATH			"i915/icl_dmc_ver1_07.bin"
43
#define ICL_CSR_VERSION_REQUIRED	CSR_VERSION(1, 7)
44
#define ICL_CSR_MAX_FW_SIZE		0x6000
45
MODULE_FIRMWARE(ICL_CSR_PATH);
46

47
#define CNL_CSR_PATH			"i915/cnl_dmc_ver1_07.bin"
48
#define CNL_CSR_VERSION_REQUIRED	CSR_VERSION(1, 7)
49 50
#define CNL_CSR_MAX_FW_SIZE		GLK_CSR_MAX_FW_SIZE
MODULE_FIRMWARE(CNL_CSR_PATH);
51

52 53 54 55 56 57
#define GLK_CSR_PATH			"i915/glk_dmc_ver1_04.bin"
#define GLK_CSR_VERSION_REQUIRED	CSR_VERSION(1, 4)
#define GLK_CSR_MAX_FW_SIZE		0x4000
MODULE_FIRMWARE(GLK_CSR_PATH);

#define KBL_CSR_PATH			"i915/kbl_dmc_ver1_04.bin"
58
#define KBL_CSR_VERSION_REQUIRED	CSR_VERSION(1, 4)
59 60
#define KBL_CSR_MAX_FW_SIZE		BXT_CSR_MAX_FW_SIZE
MODULE_FIRMWARE(KBL_CSR_PATH);
61

62
#define SKL_CSR_PATH			"i915/skl_dmc_ver1_27.bin"
63
#define SKL_CSR_VERSION_REQUIRED	CSR_VERSION(1, 27)
64 65
#define SKL_CSR_MAX_FW_SIZE		BXT_CSR_MAX_FW_SIZE
MODULE_FIRMWARE(SKL_CSR_PATH);
66

67
#define BXT_CSR_PATH			"i915/bxt_dmc_ver1_07.bin"
68
#define BXT_CSR_VERSION_REQUIRED	CSR_VERSION(1, 7)
69
#define BXT_CSR_MAX_FW_SIZE		0x3000
70 71
MODULE_FIRMWARE(BXT_CSR_PATH);

72
#define CSR_DEFAULT_FW_OFFSET		0xFFFFFFFF
73
#define PACKAGE_MAX_FW_INFO_ENTRIES	20
74
#define PACKAGE_V2_MAX_FW_INFO_ENTRIES	32
75 76 77

struct intel_css_header {
	/* 0x09 for DMC */
78
	u32 module_type;
79 80

	/* Includes the DMC specific header in dwords */
81
	u32 header_len;
82 83

	/* always value would be 0x10000 */
84
	u32 header_ver;
85 86

	/* Not used */
87
	u32 module_id;
88 89

	/* Not used */
90
	u32 module_vendor;
91 92

	/* in YYYYMMDD format */
93
	u32 date;
94 95

	/* Size in dwords (CSS_Headerlen + PackageHeaderLen + dmc FWsLen)/4 */
96
	u32 size;
97 98

	/* Not used */
99
	u32 key_size;
100 101

	/* Not used */
102
	u32 modulus_size;
103 104

	/* Not used */
105
	u32 exponent_size;
106 107

	/* Not used */
108
	u32 reserved1[12];
109 110

	/* Major Minor */
111
	u32 version;
112 113

	/* Not used */
114
	u32 reserved2[8];
115 116

	/* Not used */
117
	u32 kernel_header_info;
118 119 120
} __packed;

struct intel_fw_info {
121
	u16 reserved1;
122 123 124 125 126 127 128

	/* Stepping (A, B, C, ..., *). * is a wildcard */
	char stepping;

	/* Sub-stepping (0, 1, ..., *). * is a wildcard */
	char substepping;

129 130
	u32 offset;
	u32 reserved2;
131 132 133 134
} __packed;

struct intel_package_header {
	/* DMC container header length in dwords */
L
Lucas De Marchi 已提交
135
	u8 header_len;
136

137
	/* 0x01, 0x02 */
L
Lucas De Marchi 已提交
138
	u8 header_ver;
139

L
Lucas De Marchi 已提交
140
	u8 reserved[10];
141 142

	/* Number of valid entries in the FWInfo array below */
143
	u32 num_entries;
144 145 146 147
} __packed;

struct intel_dmc_header {
	/* always value would be 0x40403E3E */
148
	u32 signature;
149 150

	/* DMC binary header length */
L
Lucas De Marchi 已提交
151
	u8 header_len;
152 153

	/* 0x01 */
L
Lucas De Marchi 已提交
154
	u8 header_ver;
155 156

	/* Reserved */
157
	u16 dmcc_ver;
158 159

	/* Major, Minor */
160
	u32 project;
161 162

	/* Firmware program size (excluding header) in dwords */
163
	u32 fw_size;
164 165

	/* Major Minor version */
166
	u32 fw_version;
167 168

	/* Number of valid MMIO cycles present. */
169
	u32 mmio_count;
170 171

	/* MMIO address */
172
	u32 mmioaddr[8];
173 174

	/* MMIO data */
175
	u32 mmiodata[8];
176 177 178 179

	/* FW filename  */
	unsigned char dfile[32];

180
	u32 reserved1[2];
181 182 183 184 185 186 187 188
} __packed;

struct stepping_info {
	char stepping;
	char substepping;
};

static const struct stepping_info skl_stepping_info[] = {
189 190
	{'A', '0'}, {'B', '0'}, {'C', '0'},
	{'D', '0'}, {'E', '0'}, {'F', '0'},
191 192
	{'G', '0'}, {'H', '0'}, {'I', '0'},
	{'J', '0'}, {'K', '0'}
193 194
};

J
Jani Nikula 已提交
195
static const struct stepping_info bxt_stepping_info[] = {
196 197 198 199
	{'A', '0'}, {'A', '1'}, {'A', '2'},
	{'B', '0'}, {'B', '1'}, {'B', '2'}
};

200 201 202 203 204 205
static const struct stepping_info icl_stepping_info[] = {
	{'A', '0'}, {'A', '1'}, {'A', '2'},
	{'B', '0'}, {'B', '2'},
	{'C', '0'}
};

206 207 208 209
static const struct stepping_info no_stepping_info = { '*', '*' };

static const struct stepping_info *
intel_get_stepping_info(struct drm_i915_private *dev_priv)
210
{
211 212 213
	const struct stepping_info *si;
	unsigned int size;

214 215 216 217
	if (IS_ICELAKE(dev_priv)) {
		size = ARRAY_SIZE(icl_stepping_info);
		si = icl_stepping_info;
	} else if (IS_SKYLAKE(dev_priv)) {
218 219
		size = ARRAY_SIZE(skl_stepping_info);
		si = skl_stepping_info;
220
	} else if (IS_BROXTON(dev_priv)) {
221 222 223
		size = ARRAY_SIZE(bxt_stepping_info);
		si = bxt_stepping_info;
	} else {
224
		size = 0;
225
		si = NULL;
226
	}
227

228 229
	if (INTEL_REVID(dev_priv) < size)
		return si + INTEL_REVID(dev_priv);
230

231
	return &no_stepping_info;
232 233
}

234 235
static void gen9_set_dc_state_debugmask(struct drm_i915_private *dev_priv)
{
236
	u32 val, mask;
237 238 239

	mask = DC_STATE_DEBUG_MASK_MEMORY_UP;

240
	if (IS_GEN9_LP(dev_priv))
241 242 243 244 245 246 247 248 249 250 251
		mask |= DC_STATE_DEBUG_MASK_CORES;

	/* The below bit doesn't need to be cleared ever afterwards */
	val = I915_READ(DC_STATE_DEBUG);
	if ((val & mask) != mask) {
		val |= mask;
		I915_WRITE(DC_STATE_DEBUG, val);
		POSTING_READ(DC_STATE_DEBUG);
	}
}

252 253
/**
 * intel_csr_load_program() - write the firmware from memory to register.
254
 * @dev_priv: i915 drm device.
255 256 257 258 259
 *
 * CSR firmware is read from a .bin file and kept in internal memory one time.
 * Everytime display comes back from low power state this function is called to
 * copy the firmware from internal memory to registers.
 */
260
void intel_csr_load_program(struct drm_i915_private *dev_priv)
261
{
262
	u32 *payload = dev_priv->csr.dmc_payload;
263
	u32 i, fw_size;
264

265
	if (!HAS_CSR(dev_priv)) {
266
		DRM_ERROR("No CSR support available for this platform\n");
267
		return;
268 269
	}

270 271
	if (!dev_priv->csr.dmc_payload) {
		DRM_ERROR("Tried to program CSR with empty payload\n");
272
		return;
273
	}
274

275
	fw_size = dev_priv->csr.dmc_fw_size;
276
	assert_rpm_wakelock_held(&dev_priv->runtime_pm);
277 278 279

	preempt_disable();

280
	for (i = 0; i < fw_size; i++)
281 282 283
		I915_WRITE_FW(CSR_PROGRAM(i), payload[i]);

	preempt_enable();
284 285 286

	for (i = 0; i < dev_priv->csr.mmio_count; i++) {
		I915_WRITE(dev_priv->csr.mmioaddr[i],
287
			   dev_priv->csr.mmiodata[i]);
288
	}
289 290

	dev_priv->csr.dc_state = 0;
291

292
	gen9_set_dc_state_debugmask(dev_priv);
293 294
}

295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
/*
 * Search fw_info table for dmc_offset to find firmware binary: num_entries is
 * already sanitized.
 */
static u32 find_dmc_fw_offset(const struct intel_fw_info *fw_info,
			      unsigned int num_entries,
			      const struct stepping_info *si)
{
	u32 dmc_offset = CSR_DEFAULT_FW_OFFSET;
	unsigned int i;

	for (i = 0; i < num_entries; i++) {
		if (fw_info[i].substepping == '*' &&
		    si->stepping == fw_info[i].stepping) {
			dmc_offset = fw_info[i].offset;
			break;
		}

		if (si->stepping == fw_info[i].stepping &&
		    si->substepping == fw_info[i].substepping) {
			dmc_offset = fw_info[i].offset;
			break;
		}

		if (fw_info[i].stepping == '*' &&
		    fw_info[i].substepping == '*') {
			/*
			 * In theory we should stop the search as generic
			 * entries should always come after the more specific
			 * ones, but let's continue to make sure to work even
			 * with "broken" firmwares. If we don't find a more
			 * specific one, then we use this entry
			 */
			dmc_offset = fw_info[i].offset;
		}
	}

	return dmc_offset;
}

335 336
static u32 *parse_csr_fw(struct drm_i915_private *dev_priv,
			 const struct firmware *fw)
337 338 339 340 341
{
	struct intel_css_header *css_header;
	struct intel_package_header *package_header;
	struct intel_dmc_header *dmc_header;
	struct intel_csr *csr = &dev_priv->csr;
342
	const struct stepping_info *si = intel_get_stepping_info(dev_priv);
343
	u32 dmc_offset, num_entries, max_entries, readcount = 0, nbytes;
344 345
	u32 i;
	u32 *dmc_payload;
346
	size_t fsize;
347

348
	if (!fw)
349
		return NULL;
350

351 352 353 354 355 356
	fsize = sizeof(struct intel_css_header) +
		sizeof(struct intel_package_header) +
		sizeof(struct intel_dmc_header);
	if (fsize > fw->size)
		goto error_truncated;

357 358 359
	/* Extract CSS Header information*/
	css_header = (struct intel_css_header *)fw->data;
	if (sizeof(struct intel_css_header) !=
360
	    (css_header->header_len * 4)) {
361 362
		DRM_ERROR("DMC firmware has wrong CSS header length "
			  "(%u bytes)\n",
363
			  (css_header->header_len * 4));
364
		return NULL;
365
	}
366

367 368
	if (csr->required_version &&
	    css_header->version != csr->required_version) {
369
		DRM_INFO("Refusing to load DMC firmware v%u.%u,"
370
			 " please use v%u.%u\n",
371 372 373 374
			 CSR_VERSION_MAJOR(css_header->version),
			 CSR_VERSION_MINOR(css_header->version),
			 CSR_VERSION_MAJOR(csr->required_version),
			 CSR_VERSION_MINOR(csr->required_version));
375
		return NULL;
376 377
	}

378 379
	csr->version = css_header->version;

380 381 382 383
	readcount += sizeof(struct intel_css_header);

	/* Extract Package Header information*/
	package_header = (struct intel_package_header *)
384
		&fw->data[readcount];
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400

	readcount += sizeof(struct intel_package_header);

	if (package_header->header_ver == 1) {
		max_entries = PACKAGE_MAX_FW_INFO_ENTRIES;
	} else if (package_header->header_ver == 2) {
		max_entries = PACKAGE_V2_MAX_FW_INFO_ENTRIES;
	} else {
		DRM_ERROR("DMC firmware has unknown header version %u\n",
			  package_header->header_ver);
		return NULL;
	}

	if (package_header->header_len * 4 !=
	    sizeof(struct intel_package_header) +
	    max_entries * sizeof(struct intel_fw_info)) {
401
		DRM_ERROR("DMC firmware has wrong package header length "
402
			  "(%u bytes)\n", package_header->header_len * 4);
403
		return NULL;
404
	}
405 406

	num_entries = package_header->num_entries;
407 408
	if (WARN_ON(package_header->num_entries > max_entries))
		num_entries = max_entries;
409

410
	fsize += max_entries * sizeof(struct intel_fw_info);
411 412 413 414 415
	if (fsize > fw->size)
		goto error_truncated;

	dmc_offset = find_dmc_fw_offset((struct intel_fw_info *)
					&fw->data[readcount], num_entries, si);
416
	if (dmc_offset == CSR_DEFAULT_FW_OFFSET) {
417
		DRM_ERROR("DMC firmware not supported for %c stepping\n",
418
			  si->stepping);
419
		return NULL;
420
	}
421 422 423

	/* we always have space for max_entries, even if not all are used */
	readcount += max_entries * sizeof(struct intel_fw_info);
424

425 426
	/* Convert dmc_offset into number of bytes. By default it is in dwords*/
	dmc_offset *= 4;
427
	readcount += dmc_offset;
428 429 430
	fsize += dmc_offset;
	if (fsize > fw->size)
		goto error_truncated;
431 432 433 434

	/* Extract dmc_header information. */
	dmc_header = (struct intel_dmc_header *)&fw->data[readcount];
	if (sizeof(struct intel_dmc_header) != (dmc_header->header_len)) {
435 436
		DRM_ERROR("DMC firmware has wrong dmc header length "
			  "(%u bytes)\n",
437
			  (dmc_header->header_len));
438
		return NULL;
439 440 441 442 443
	}
	readcount += sizeof(struct intel_dmc_header);

	/* Cache the dmc header info. */
	if (dmc_header->mmio_count > ARRAY_SIZE(csr->mmioaddr)) {
444
		DRM_ERROR("DMC firmware has wrong mmio count %u\n",
445
			  dmc_header->mmio_count);
446
		return NULL;
447 448 449
	}
	csr->mmio_count = dmc_header->mmio_count;
	for (i = 0; i < dmc_header->mmio_count; i++) {
450
		if (dmc_header->mmioaddr[i] < CSR_MMIO_START_RANGE ||
451
		    dmc_header->mmioaddr[i] > CSR_MMIO_END_RANGE) {
452
			DRM_ERROR("DMC firmware has wrong mmio address 0x%x\n",
453
				  dmc_header->mmioaddr[i]);
454
			return NULL;
455
		}
456
		csr->mmioaddr[i] = _MMIO(dmc_header->mmioaddr[i]);
457 458 459 460 461
		csr->mmiodata[i] = dmc_header->mmiodata[i];
	}

	/* fw_size is in dwords, so multiplied by 4 to convert into bytes. */
	nbytes = dmc_header->fw_size * 4;
462 463 464 465
	fsize += nbytes;
	if (fsize > fw->size)
		goto error_truncated;

466
	if (nbytes > csr->max_fw_size) {
467
		DRM_ERROR("DMC FW too big (%u bytes)\n", nbytes);
468
		return NULL;
469 470 471
	}
	csr->dmc_fw_size = dmc_header->fw_size;

472 473
	dmc_payload = kmalloc(nbytes, GFP_KERNEL);
	if (!dmc_payload) {
474
		DRM_ERROR("Memory allocation failed for dmc payload\n");
475
		return NULL;
476 477
	}

478
	return memcpy(dmc_payload, &fw->data[readcount], nbytes);
479 480 481 482

error_truncated:
	DRM_ERROR("Truncated DMC firmware, rejecting.\n");
	return NULL;
483 484
}

485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
static void intel_csr_runtime_pm_get(struct drm_i915_private *dev_priv)
{
	WARN_ON(dev_priv->csr.wakeref);
	dev_priv->csr.wakeref =
		intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
}

static void intel_csr_runtime_pm_put(struct drm_i915_private *dev_priv)
{
	intel_wakeref_t wakeref __maybe_unused =
		fetch_and_zero(&dev_priv->csr.wakeref);

	intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
}

500
static void csr_load_work_fn(struct work_struct *work)
501
{
502 503
	struct drm_i915_private *dev_priv;
	struct intel_csr *csr;
504
	const struct firmware *fw = NULL;
505 506 507

	dev_priv = container_of(work, typeof(*dev_priv), csr.work);
	csr = &dev_priv->csr;
508

509
	request_firmware(&fw, dev_priv->csr.fw_path, &dev_priv->drm.pdev->dev);
510 511
	if (fw)
		dev_priv->csr.dmc_payload = parse_csr_fw(dev_priv, fw);
512 513

	if (dev_priv->csr.dmc_payload) {
514
		intel_csr_load_program(dev_priv);
515
		intel_csr_runtime_pm_put(dev_priv);
516

517
		DRM_INFO("Finished loading DMC firmware %s (v%u.%u)\n",
518 519 520 521
			 dev_priv->csr.fw_path,
			 CSR_VERSION_MAJOR(csr->version),
			 CSR_VERSION_MINOR(csr->version));
	} else {
522
		dev_notice(dev_priv->drm.dev,
523 524 525 526 527
			   "Failed to load DMC firmware %s."
			   " Disabling runtime power management.\n",
			   csr->fw_path);
		dev_notice(dev_priv->drm.dev, "DMC firmware homepage: %s",
			   INTEL_UC_FIRMWARE_URL);
528 529
	}

530 531 532
	release_firmware(fw);
}

533 534
/**
 * intel_csr_ucode_init() - initialize the firmware loading.
535
 * @dev_priv: i915 drm device.
536 537 538 539
 *
 * This function is called at the time of loading the display driver to read
 * firmware from a .bin file and copied into a internal memory.
 */
540
void intel_csr_ucode_init(struct drm_i915_private *dev_priv)
541 542
{
	struct intel_csr *csr = &dev_priv->csr;
543 544

	INIT_WORK(&dev_priv->csr.work, csr_load_work_fn);
545

546
	if (!HAS_CSR(dev_priv))
547 548
		return;

549 550 551 552 553 554 555 556
	/*
	 * Obtain a runtime pm reference, until CSR is loaded, to avoid entering
	 * runtime-suspend.
	 *
	 * On error, we return with the rpm wakeref held to prevent runtime
	 * suspend as runtime suspend *requires* a working CSR for whatever
	 * reason.
	 */
557
	intel_csr_runtime_pm_get(dev_priv);
558

559 560 561
	if (INTEL_GEN(dev_priv) >= 12) {
		/* Allow to load fw via parameter using the last known size */
		csr->max_fw_size = GEN12_CSR_MAX_FW_SIZE;
562
	} else if (IS_GEN(dev_priv, 11)) {
563
		csr->fw_path = ICL_CSR_PATH;
564
		csr->required_version = ICL_CSR_VERSION_REQUIRED;
565
		csr->max_fw_size = ICL_CSR_MAX_FW_SIZE;
566
	} else if (IS_CANNONLAKE(dev_priv)) {
567
		csr->fw_path = CNL_CSR_PATH;
568
		csr->required_version = CNL_CSR_VERSION_REQUIRED;
569
		csr->max_fw_size = CNL_CSR_MAX_FW_SIZE;
570
	} else if (IS_GEMINILAKE(dev_priv)) {
571
		csr->fw_path = GLK_CSR_PATH;
572
		csr->required_version = GLK_CSR_VERSION_REQUIRED;
573
		csr->max_fw_size = GLK_CSR_MAX_FW_SIZE;
574
	} else if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) {
575
		csr->fw_path = KBL_CSR_PATH;
576
		csr->required_version = KBL_CSR_VERSION_REQUIRED;
577
		csr->max_fw_size = KBL_CSR_MAX_FW_SIZE;
578
	} else if (IS_SKYLAKE(dev_priv)) {
579
		csr->fw_path = SKL_CSR_PATH;
580
		csr->required_version = SKL_CSR_VERSION_REQUIRED;
581
		csr->max_fw_size = SKL_CSR_MAX_FW_SIZE;
582
	} else if (IS_BROXTON(dev_priv)) {
583
		csr->fw_path = BXT_CSR_PATH;
584
		csr->required_version = BXT_CSR_VERSION_REQUIRED;
585
		csr->max_fw_size = BXT_CSR_MAX_FW_SIZE;
586
	}
587

588
	if (i915_modparams.dmc_firmware_path) {
589 590
		if (strlen(i915_modparams.dmc_firmware_path) == 0) {
			csr->fw_path = NULL;
591
			DRM_INFO("Disabling CSR firmware and runtime PM\n");
592 593 594
			return;
		}

595 596 597 598
		csr->fw_path = i915_modparams.dmc_firmware_path;
		/* Bypass version check for firmware override. */
		csr->required_version = 0;
	}
599

600 601 602 603 604 605
	if (csr->fw_path == NULL) {
		DRM_DEBUG_KMS("No known CSR firmware for platform, disabling runtime PM\n");
		return;
	}

	DRM_DEBUG_KMS("Loading %s\n", csr->fw_path);
606
	schedule_work(&dev_priv->csr.work);
607 608
}

609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
/**
 * intel_csr_ucode_suspend() - prepare CSR firmware before system suspend
 * @dev_priv: i915 drm device
 *
 * Prepare the DMC firmware before entering system suspend. This includes
 * flushing pending work items and releasing any resources acquired during
 * init.
 */
void intel_csr_ucode_suspend(struct drm_i915_private *dev_priv)
{
	if (!HAS_CSR(dev_priv))
		return;

	flush_work(&dev_priv->csr.work);

	/* Drop the reference held in case DMC isn't loaded. */
	if (!dev_priv->csr.dmc_payload)
626
		intel_csr_runtime_pm_put(dev_priv);
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645
}

/**
 * intel_csr_ucode_resume() - init CSR firmware during system resume
 * @dev_priv: i915 drm device
 *
 * Reinitialize the DMC firmware during system resume, reacquiring any
 * resources released in intel_csr_ucode_suspend().
 */
void intel_csr_ucode_resume(struct drm_i915_private *dev_priv)
{
	if (!HAS_CSR(dev_priv))
		return;

	/*
	 * Reacquire the reference to keep RPM disabled in case DMC isn't
	 * loaded.
	 */
	if (!dev_priv->csr.dmc_payload)
646
		intel_csr_runtime_pm_get(dev_priv);
647 648
}

649 650
/**
 * intel_csr_ucode_fini() - unload the CSR firmware.
651
 * @dev_priv: i915 drm device.
652
 *
653
 * Firmmware unloading includes freeing the internal memory and reset the
654 655
 * firmware loading status.
 */
656
void intel_csr_ucode_fini(struct drm_i915_private *dev_priv)
657
{
658
	if (!HAS_CSR(dev_priv))
659 660
		return;

661
	intel_csr_ucode_suspend(dev_priv);
662
	WARN_ON(dev_priv->csr.wakeref);
663

664 665
	kfree(dev_priv->csr.dmc_payload);
}