amdgpu_cgs.c 33.2 KB
Newer Older
C
Chunming Zhou 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright 2015 Advanced Micro Devices, Inc.
 *
 * 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 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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/list.h>
#include <linux/slab.h>
26
#include <linux/pci.h>
27
#include <linux/acpi.h>
28
#include <drm/drmP.h>
29
#include <linux/firmware.h>
30
#include <drm/amdgpu_drm.h>
C
Chunming Zhou 已提交
31 32
#include "amdgpu.h"
#include "cgs_linux.h"
33
#include "atom.h"
34 35
#include "amdgpu_ucode.h"

C
Chunming Zhou 已提交
36 37 38 39 40 41 42 43 44
struct amdgpu_cgs_device {
	struct cgs_device base;
	struct amdgpu_device *adev;
};

#define CGS_FUNC_ADEV							\
	struct amdgpu_device *adev =					\
		((struct amdgpu_cgs_device *)cgs_device)->adev

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
static void *amdgpu_cgs_register_pp_handle(struct cgs_device *cgs_device,
			int (*call_back_func)(struct amd_pp_init *, void **))
{
	CGS_FUNC_ADEV;
	struct amd_pp_init pp_init;
	struct amd_powerplay *amd_pp;

	if (call_back_func == NULL)
		return NULL;

	amd_pp = &(adev->powerplay);
	pp_init.chip_family = adev->family;
	pp_init.chip_id = adev->asic_type;
	pp_init.pm_en = (amdgpu_dpm != 0 && !amdgpu_sriov_vf(adev)) ? true : false;
	pp_init.feature_mask = amdgpu_pp_feature_mask;
	pp_init.device = cgs_device;
	if (call_back_func(&pp_init, &(amd_pp->pp_handle)))
		return NULL;

	return adev->powerplay.pp_handle;
}

67
static int amdgpu_cgs_alloc_gpu_mem(struct cgs_device *cgs_device,
C
Chunming Zhou 已提交
68 69 70 71
				    enum cgs_gpu_mem_type type,
				    uint64_t size, uint64_t align,
				    cgs_handle_t *handle)
{
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
	CGS_FUNC_ADEV;
	uint16_t flags = 0;
	int ret = 0;
	uint32_t domain = 0;
	struct amdgpu_bo *obj;

	/* fail if the alignment is not a power of 2 */
	if (((align != 1) && (align & (align - 1)))
	    || size == 0 || align == 0)
		return -EINVAL;


	switch(type) {
	case CGS_GPU_MEM_TYPE__VISIBLE_CONTIG_FB:
	case CGS_GPU_MEM_TYPE__VISIBLE_FB:
87 88
		flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
89 90 91 92
		domain = AMDGPU_GEM_DOMAIN_VRAM;
		break;
	case CGS_GPU_MEM_TYPE__INVISIBLE_CONTIG_FB:
	case CGS_GPU_MEM_TYPE__INVISIBLE_FB:
93 94
		flags = AMDGPU_GEM_CREATE_NO_CPU_ACCESS |
			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
		domain = AMDGPU_GEM_DOMAIN_VRAM;
		break;
	case CGS_GPU_MEM_TYPE__GART_CACHEABLE:
		domain = AMDGPU_GEM_DOMAIN_GTT;
		break;
	case CGS_GPU_MEM_TYPE__GART_WRITECOMBINE:
		flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC;
		domain = AMDGPU_GEM_DOMAIN_GTT;
		break;
	default:
		return -EINVAL;
	}


	*handle = 0;

111 112
	ret = amdgpu_bo_create(adev, size, align, true, domain, flags,
			       NULL, NULL, 0, &obj);
113 114 115 116 117 118 119
	if (ret) {
		DRM_ERROR("(%d) bo create failed\n", ret);
		return ret;
	}
	*handle = (cgs_handle_t)obj;

	return ret;
C
Chunming Zhou 已提交
120 121
}

122
static int amdgpu_cgs_free_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle)
C
Chunming Zhou 已提交
123
{
124 125 126
	struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;

	if (obj) {
127
		int r = amdgpu_bo_reserve(obj, true);
128 129 130 131 132 133 134 135
		if (likely(r == 0)) {
			amdgpu_bo_kunmap(obj);
			amdgpu_bo_unpin(obj);
			amdgpu_bo_unreserve(obj);
		}
		amdgpu_bo_unref(&obj);

	}
C
Chunming Zhou 已提交
136 137 138
	return 0;
}

139
static int amdgpu_cgs_gmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle,
C
Chunming Zhou 已提交
140 141
				   uint64_t *mcaddr)
{
142 143 144 145 146
	int r;
	struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;

	WARN_ON_ONCE(obj->placement.num_placement > 1);

147
	r = amdgpu_bo_reserve(obj, true);
148 149
	if (unlikely(r != 0))
		return r;
150
	r = amdgpu_bo_pin(obj, obj->preferred_domains, mcaddr);
151 152
	amdgpu_bo_unreserve(obj);
	return r;
C
Chunming Zhou 已提交
153 154
}

155
static int amdgpu_cgs_gunmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle)
C
Chunming Zhou 已提交
156
{
157 158
	int r;
	struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
159
	r = amdgpu_bo_reserve(obj, true);
160 161 162 163 164
	if (unlikely(r != 0))
		return r;
	r = amdgpu_bo_unpin(obj);
	amdgpu_bo_unreserve(obj);
	return r;
C
Chunming Zhou 已提交
165 166
}

167
static int amdgpu_cgs_kmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle,
C
Chunming Zhou 已提交
168 169
				   void **map)
{
170 171
	int r;
	struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
172
	r = amdgpu_bo_reserve(obj, true);
173 174 175 176 177
	if (unlikely(r != 0))
		return r;
	r = amdgpu_bo_kmap(obj, map);
	amdgpu_bo_unreserve(obj);
	return r;
C
Chunming Zhou 已提交
178 179
}

180
static int amdgpu_cgs_kunmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle)
C
Chunming Zhou 已提交
181
{
182 183
	int r;
	struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
184
	r = amdgpu_bo_reserve(obj, true);
185 186 187 188 189
	if (unlikely(r != 0))
		return r;
	amdgpu_bo_kunmap(obj);
	amdgpu_bo_unreserve(obj);
	return r;
C
Chunming Zhou 已提交
190 191
}

192
static uint32_t amdgpu_cgs_read_register(struct cgs_device *cgs_device, unsigned offset)
C
Chunming Zhou 已提交
193
{
194 195
	CGS_FUNC_ADEV;
	return RREG32(offset);
C
Chunming Zhou 已提交
196 197
}

198
static void amdgpu_cgs_write_register(struct cgs_device *cgs_device, unsigned offset,
C
Chunming Zhou 已提交
199 200
				      uint32_t value)
{
201 202
	CGS_FUNC_ADEV;
	WREG32(offset, value);
C
Chunming Zhou 已提交
203 204
}

205
static uint32_t amdgpu_cgs_read_ind_register(struct cgs_device *cgs_device,
C
Chunming Zhou 已提交
206 207 208
					     enum cgs_ind_reg space,
					     unsigned index)
{
209 210 211 212 213 214 215 216 217 218 219 220
	CGS_FUNC_ADEV;
	switch (space) {
	case CGS_IND_REG__MMIO:
		return RREG32_IDX(index);
	case CGS_IND_REG__PCIE:
		return RREG32_PCIE(index);
	case CGS_IND_REG__SMC:
		return RREG32_SMC(index);
	case CGS_IND_REG__UVD_CTX:
		return RREG32_UVD_CTX(index);
	case CGS_IND_REG__DIDT:
		return RREG32_DIDT(index);
221 222
	case CGS_IND_REG_GC_CAC:
		return RREG32_GC_CAC(index);
223 224
	case CGS_IND_REG_SE_CAC:
		return RREG32_SE_CAC(index);
225 226 227 228 229
	case CGS_IND_REG__AUDIO_ENDPT:
		DRM_ERROR("audio endpt register access not implemented.\n");
		return 0;
	}
	WARN(1, "Invalid indirect register space");
C
Chunming Zhou 已提交
230 231 232
	return 0;
}

233
static void amdgpu_cgs_write_ind_register(struct cgs_device *cgs_device,
C
Chunming Zhou 已提交
234 235 236
					  enum cgs_ind_reg space,
					  unsigned index, uint32_t value)
{
237 238 239 240 241 242 243 244 245 246 247 248
	CGS_FUNC_ADEV;
	switch (space) {
	case CGS_IND_REG__MMIO:
		return WREG32_IDX(index, value);
	case CGS_IND_REG__PCIE:
		return WREG32_PCIE(index, value);
	case CGS_IND_REG__SMC:
		return WREG32_SMC(index, value);
	case CGS_IND_REG__UVD_CTX:
		return WREG32_UVD_CTX(index, value);
	case CGS_IND_REG__DIDT:
		return WREG32_DIDT(index, value);
249 250
	case CGS_IND_REG_GC_CAC:
		return WREG32_GC_CAC(index, value);
251 252
	case CGS_IND_REG_SE_CAC:
		return WREG32_SE_CAC(index, value);
253 254 255 256 257
	case CGS_IND_REG__AUDIO_ENDPT:
		DRM_ERROR("audio endpt register access not implemented.\n");
		return;
	}
	WARN(1, "Invalid indirect register space");
C
Chunming Zhou 已提交
258 259
}

260
static int amdgpu_cgs_get_pci_resource(struct cgs_device *cgs_device,
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
				       enum cgs_resource_type resource_type,
				       uint64_t size,
				       uint64_t offset,
				       uint64_t *resource_base)
{
	CGS_FUNC_ADEV;

	if (resource_base == NULL)
		return -EINVAL;

	switch (resource_type) {
	case CGS_RESOURCE_TYPE_MMIO:
		if (adev->rmmio_size == 0)
			return -ENOENT;
		if ((offset + size) > adev->rmmio_size)
			return -EINVAL;
		*resource_base = adev->rmmio_base;
		return 0;
	case CGS_RESOURCE_TYPE_DOORBELL:
		if (adev->doorbell.size == 0)
			return -ENOENT;
		if ((offset + size) > adev->doorbell.size)
			return -EINVAL;
		*resource_base = adev->doorbell.base;
		return 0;
	case CGS_RESOURCE_TYPE_FB:
	case CGS_RESOURCE_TYPE_IO:
	case CGS_RESOURCE_TYPE_ROM:
	default:
		return -EINVAL;
	}
}

294
static const void *amdgpu_cgs_atom_get_data_table(struct cgs_device *cgs_device,
C
Chunming Zhou 已提交
295 296 297
						  unsigned table, uint16_t *size,
						  uint8_t *frev, uint8_t *crev)
{
298 299 300 301 302 303 304 305 306
	CGS_FUNC_ADEV;
	uint16_t data_start;

	if (amdgpu_atom_parse_data_header(
		    adev->mode_info.atom_context, table, size,
		    frev, crev, &data_start))
		return (uint8_t*)adev->mode_info.atom_context->bios +
			data_start;

C
Chunming Zhou 已提交
307 308 309
	return NULL;
}

310
static int amdgpu_cgs_atom_get_cmd_table_revs(struct cgs_device *cgs_device, unsigned table,
C
Chunming Zhou 已提交
311 312
					      uint8_t *frev, uint8_t *crev)
{
313 314 315 316 317 318 319 320
	CGS_FUNC_ADEV;

	if (amdgpu_atom_parse_cmd_header(
		    adev->mode_info.atom_context, table,
		    frev, crev))
		return 0;

	return -EINVAL;
C
Chunming Zhou 已提交
321 322
}

323
static int amdgpu_cgs_atom_exec_cmd_table(struct cgs_device *cgs_device, unsigned table,
C
Chunming Zhou 已提交
324 325
					  void *args)
{
326
	CGS_FUNC_ADEV;
C
Chunming Zhou 已提交
327

328 329 330
	return amdgpu_atom_execute_table(
		adev->mode_info.atom_context, table, args);
}
C
Chunming Zhou 已提交
331

332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
struct cgs_irq_params {
	unsigned src_id;
	cgs_irq_source_set_func_t set;
	cgs_irq_handler_func_t handler;
	void *private_data;
};

static int cgs_set_irq_state(struct amdgpu_device *adev,
			     struct amdgpu_irq_src *src,
			     unsigned type,
			     enum amdgpu_interrupt_state state)
{
	struct cgs_irq_params *irq_params =
		(struct cgs_irq_params *)src->data;
	if (!irq_params)
		return -EINVAL;
	if (!irq_params->set)
		return -EINVAL;
	return irq_params->set(irq_params->private_data,
			       irq_params->src_id,
			       type,
			       (int)state);
}

static int cgs_process_irq(struct amdgpu_device *adev,
			   struct amdgpu_irq_src *source,
			   struct amdgpu_iv_entry *entry)
{
	struct cgs_irq_params *irq_params =
		(struct cgs_irq_params *)source->data;
	if (!irq_params)
		return -EINVAL;
	if (!irq_params->handler)
		return -EINVAL;
	return irq_params->handler(irq_params->private_data,
				   irq_params->src_id,
				   entry->iv_entry);
}

static const struct amdgpu_irq_src_funcs cgs_irq_funcs = {
	.set = cgs_set_irq_state,
	.process = cgs_process_irq,
};

376 377 378
static int amdgpu_cgs_add_irq_source(void *cgs_device,
				     unsigned client_id,
				     unsigned src_id,
C
Chunming Zhou 已提交
379 380 381 382 383
				     unsigned num_types,
				     cgs_irq_source_set_func_t set,
				     cgs_irq_handler_func_t handler,
				     void *private_data)
{
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
	CGS_FUNC_ADEV;
	int ret = 0;
	struct cgs_irq_params *irq_params;
	struct amdgpu_irq_src *source =
		kzalloc(sizeof(struct amdgpu_irq_src), GFP_KERNEL);
	if (!source)
		return -ENOMEM;
	irq_params =
		kzalloc(sizeof(struct cgs_irq_params), GFP_KERNEL);
	if (!irq_params) {
		kfree(source);
		return -ENOMEM;
	}
	source->num_types = num_types;
	source->funcs = &cgs_irq_funcs;
	irq_params->src_id = src_id;
	irq_params->set = set;
	irq_params->handler = handler;
	irq_params->private_data = private_data;
	source->data = (void *)irq_params;
404
	ret = amdgpu_irq_add_id(adev, client_id, src_id, source);
405 406 407 408 409 410
	if (ret) {
		kfree(irq_params);
		kfree(source);
	}

	return ret;
C
Chunming Zhou 已提交
411 412
}

413 414
static int amdgpu_cgs_irq_get(void *cgs_device, unsigned client_id,
			      unsigned src_id, unsigned type)
C
Chunming Zhou 已提交
415
{
416
	CGS_FUNC_ADEV;
417 418 419 420 421

	if (!adev->irq.client[client_id].sources)
		return -EINVAL;

	return amdgpu_irq_get(adev, adev->irq.client[client_id].sources[src_id], type);
C
Chunming Zhou 已提交
422 423
}

424 425
static int amdgpu_cgs_irq_put(void *cgs_device, unsigned client_id,
			      unsigned src_id, unsigned type)
C
Chunming Zhou 已提交
426
{
427
	CGS_FUNC_ADEV;
428 429 430 431 432

	if (!adev->irq.client[client_id].sources)
		return -EINVAL;

	return amdgpu_irq_put(adev, adev->irq.client[client_id].sources[src_id], type);
C
Chunming Zhou 已提交
433 434
}

435
static int amdgpu_cgs_set_clockgating_state(struct cgs_device *cgs_device,
436 437 438 439 440 441 442
				  enum amd_ip_block_type block_type,
				  enum amd_clockgating_state state)
{
	CGS_FUNC_ADEV;
	int i, r = -1;

	for (i = 0; i < adev->num_ip_blocks; i++) {
443
		if (!adev->ip_blocks[i].status.valid)
444 445
			continue;

446 447
		if (adev->ip_blocks[i].version->type == block_type) {
			r = adev->ip_blocks[i].version->funcs->set_clockgating_state(
448 449 450 451 452 453 454 455
								(void *)adev,
									state);
			break;
		}
	}
	return r;
}

456
static int amdgpu_cgs_set_powergating_state(struct cgs_device *cgs_device,
457 458 459 460 461 462 463
				  enum amd_ip_block_type block_type,
				  enum amd_powergating_state state)
{
	CGS_FUNC_ADEV;
	int i, r = -1;

	for (i = 0; i < adev->num_ip_blocks; i++) {
464
		if (!adev->ip_blocks[i].status.valid)
465 466
			continue;

467 468
		if (adev->ip_blocks[i].version->type == block_type) {
			r = adev->ip_blocks[i].version->funcs->set_powergating_state(
469 470 471 472 473 474 475 476 477
								(void *)adev,
									state);
			break;
		}
	}
	return r;
}


478
static uint32_t fw_type_convert(struct cgs_device *cgs_device, uint32_t fw_type)
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
{
	CGS_FUNC_ADEV;
	enum AMDGPU_UCODE_ID result = AMDGPU_UCODE_ID_MAXIMUM;

	switch (fw_type) {
	case CGS_UCODE_ID_SDMA0:
		result = AMDGPU_UCODE_ID_SDMA0;
		break;
	case CGS_UCODE_ID_SDMA1:
		result = AMDGPU_UCODE_ID_SDMA1;
		break;
	case CGS_UCODE_ID_CP_CE:
		result = AMDGPU_UCODE_ID_CP_CE;
		break;
	case CGS_UCODE_ID_CP_PFP:
		result = AMDGPU_UCODE_ID_CP_PFP;
		break;
	case CGS_UCODE_ID_CP_ME:
		result = AMDGPU_UCODE_ID_CP_ME;
		break;
	case CGS_UCODE_ID_CP_MEC:
	case CGS_UCODE_ID_CP_MEC_JT1:
		result = AMDGPU_UCODE_ID_CP_MEC1;
		break;
	case CGS_UCODE_ID_CP_MEC_JT2:
504 505 506 507 508
		/* for VI. JT2 should be the same as JT1, because:
			1, MEC2 and MEC1 use exactly same FW.
			2, JT2 is not pached but JT1 is.
		*/
		if (adev->asic_type >= CHIP_TOPAZ)
509
			result = AMDGPU_UCODE_ID_CP_MEC1;
510 511
		else
			result = AMDGPU_UCODE_ID_CP_MEC2;
512 513 514 515
		break;
	case CGS_UCODE_ID_RLC_G:
		result = AMDGPU_UCODE_ID_RLC_G;
		break;
516 517 518
	case CGS_UCODE_ID_STORAGE:
		result = AMDGPU_UCODE_ID_STORAGE;
		break;
519 520 521 522 523 524
	default:
		DRM_ERROR("Firmware type not supported\n");
	}
	return result;
}

525 526 527 528 529
static int amdgpu_cgs_rel_firmware(struct cgs_device *cgs_device, enum cgs_ucode_id type)
{
	CGS_FUNC_ADEV;
	if ((CGS_UCODE_ID_SMU == type) || (CGS_UCODE_ID_SMU_SK == type)) {
		release_firmware(adev->pm.fw);
530
		adev->pm.fw = NULL;
531 532 533 534 535 536
		return 0;
	}
	/* cannot release other firmware because they are not created by cgs */
	return -EINVAL;
}

537 538 539 540
static uint16_t amdgpu_get_firmware_version(struct cgs_device *cgs_device,
					enum cgs_ucode_id type)
{
	CGS_FUNC_ADEV;
541
	uint16_t fw_version = 0;
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570

	switch (type) {
		case CGS_UCODE_ID_SDMA0:
			fw_version = adev->sdma.instance[0].fw_version;
			break;
		case CGS_UCODE_ID_SDMA1:
			fw_version = adev->sdma.instance[1].fw_version;
			break;
		case CGS_UCODE_ID_CP_CE:
			fw_version = adev->gfx.ce_fw_version;
			break;
		case CGS_UCODE_ID_CP_PFP:
			fw_version = adev->gfx.pfp_fw_version;
			break;
		case CGS_UCODE_ID_CP_ME:
			fw_version = adev->gfx.me_fw_version;
			break;
		case CGS_UCODE_ID_CP_MEC:
			fw_version = adev->gfx.mec_fw_version;
			break;
		case CGS_UCODE_ID_CP_MEC_JT1:
			fw_version = adev->gfx.mec_fw_version;
			break;
		case CGS_UCODE_ID_CP_MEC_JT2:
			fw_version = adev->gfx.mec_fw_version;
			break;
		case CGS_UCODE_ID_RLC_G:
			fw_version = adev->gfx.rlc_fw_version;
			break;
571 572
		case CGS_UCODE_ID_STORAGE:
			break;
573 574
		default:
			DRM_ERROR("firmware type %d do not have version\n", type);
575
			break;
576 577 578 579
	}
	return fw_version;
}

580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
static int amdgpu_cgs_enter_safe_mode(struct cgs_device *cgs_device,
					bool en)
{
	CGS_FUNC_ADEV;

	if (adev->gfx.rlc.funcs->enter_safe_mode == NULL ||
		adev->gfx.rlc.funcs->exit_safe_mode == NULL)
		return 0;

	if (en)
		adev->gfx.rlc.funcs->enter_safe_mode(adev);
	else
		adev->gfx.rlc.funcs->exit_safe_mode(adev);

	return 0;
}

597 598 599 600 601 602 603 604 605 606 607
static void amdgpu_cgs_lock_grbm_idx(struct cgs_device *cgs_device,
					bool lock)
{
	CGS_FUNC_ADEV;

	if (lock)
		mutex_lock(&adev->grbm_idx_mutex);
	else
		mutex_unlock(&adev->grbm_idx_mutex);
}

608
static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
609 610 611 612 613
					enum cgs_ucode_id type,
					struct cgs_firmware_info *info)
{
	CGS_FUNC_ADEV;

614
	if ((CGS_UCODE_ID_SMU != type) && (CGS_UCODE_ID_SMU_SK != type)) {
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
		uint64_t gpu_addr;
		uint32_t data_size;
		const struct gfx_firmware_header_v1_0 *header;
		enum AMDGPU_UCODE_ID id;
		struct amdgpu_firmware_info *ucode;

		id = fw_type_convert(cgs_device, type);
		ucode = &adev->firmware.ucode[id];
		if (ucode->fw == NULL)
			return -EINVAL;

		gpu_addr  = ucode->mc_addr;
		header = (const struct gfx_firmware_header_v1_0 *)ucode->fw->data;
		data_size = le32_to_cpu(header->header.ucode_size_bytes);

		if ((type == CGS_UCODE_ID_CP_MEC_JT1) ||
		    (type == CGS_UCODE_ID_CP_MEC_JT2)) {
632
			gpu_addr += ALIGN(le32_to_cpu(header->header.ucode_size_bytes), PAGE_SIZE);
633 634
			data_size = le32_to_cpu(header->jt_size) << 2;
		}
635 636

		info->kptr = ucode->kaddr;
637
		info->image_size = data_size;
638
		info->mc_addr = gpu_addr;
639
		info->version = (uint16_t)le32_to_cpu(header->header.ucode_version);
640 641

		if (CGS_UCODE_ID_CP_MEC == type)
642
			info->image_size = le32_to_cpu(header->jt_offset) << 2;
643

644
		info->fw_version = amdgpu_get_firmware_version(cgs_device, type);
645 646 647 648 649 650 651 652
		info->feature_version = (uint16_t)le32_to_cpu(header->ucode_feature_version);
	} else {
		char fw_name[30] = {0};
		int err = 0;
		uint32_t ucode_size;
		uint32_t ucode_start_address;
		const uint8_t *src;
		const struct smc_firmware_header_v1_0 *hdr;
653 654
		const struct common_firmware_header *header;
		struct amdgpu_firmware_info *ucode = NULL;
655

656 657
		if (!adev->pm.fw) {
			switch (adev->asic_type) {
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
			case CHIP_TAHITI:
				strcpy(fw_name, "radeon/tahiti_smc.bin");
				break;
			case CHIP_PITCAIRN:
				if ((adev->pdev->revision == 0x81) &&
				    ((adev->pdev->device == 0x6810) ||
				    (adev->pdev->device == 0x6811))) {
					info->is_kicker = true;
					strcpy(fw_name, "radeon/pitcairn_k_smc.bin");
				} else {
					strcpy(fw_name, "radeon/pitcairn_smc.bin");
				}
				break;
			case CHIP_VERDE:
				if (((adev->pdev->device == 0x6820) &&
					((adev->pdev->revision == 0x81) ||
					(adev->pdev->revision == 0x83))) ||
				    ((adev->pdev->device == 0x6821) &&
					((adev->pdev->revision == 0x83) ||
					(adev->pdev->revision == 0x87))) ||
				    ((adev->pdev->revision == 0x87) &&
					((adev->pdev->device == 0x6823) ||
					(adev->pdev->device == 0x682b)))) {
					info->is_kicker = true;
					strcpy(fw_name, "radeon/verde_k_smc.bin");
				} else {
					strcpy(fw_name, "radeon/verde_smc.bin");
				}
				break;
			case CHIP_OLAND:
				if (((adev->pdev->revision == 0x81) &&
					((adev->pdev->device == 0x6600) ||
					(adev->pdev->device == 0x6604) ||
					(adev->pdev->device == 0x6605) ||
					(adev->pdev->device == 0x6610))) ||
				    ((adev->pdev->revision == 0x83) &&
					(adev->pdev->device == 0x6610))) {
					info->is_kicker = true;
					strcpy(fw_name, "radeon/oland_k_smc.bin");
				} else {
					strcpy(fw_name, "radeon/oland_smc.bin");
				}
				break;
			case CHIP_HAINAN:
				if (((adev->pdev->revision == 0x81) &&
					(adev->pdev->device == 0x6660)) ||
				    ((adev->pdev->revision == 0x83) &&
					((adev->pdev->device == 0x6660) ||
					(adev->pdev->device == 0x6663) ||
					(adev->pdev->device == 0x6665) ||
					 (adev->pdev->device == 0x6667)))) {
					info->is_kicker = true;
					strcpy(fw_name, "radeon/hainan_k_smc.bin");
				} else if ((adev->pdev->revision == 0xc3) &&
					 (adev->pdev->device == 0x6665)) {
					info->is_kicker = true;
					strcpy(fw_name, "radeon/banks_k_2_smc.bin");
				} else {
					strcpy(fw_name, "radeon/hainan_smc.bin");
				}
				break;
			case CHIP_BONAIRE:
				if ((adev->pdev->revision == 0x80) ||
					(adev->pdev->revision == 0x81) ||
					(adev->pdev->device == 0x665f)) {
					info->is_kicker = true;
					strcpy(fw_name, "radeon/bonaire_k_smc.bin");
				} else {
					strcpy(fw_name, "radeon/bonaire_smc.bin");
				}
				break;
			case CHIP_HAWAII:
				if (adev->pdev->revision == 0x80) {
					info->is_kicker = true;
					strcpy(fw_name, "radeon/hawaii_k_smc.bin");
				} else {
					strcpy(fw_name, "radeon/hawaii_smc.bin");
				}
				break;
737
			case CHIP_TOPAZ:
738 739
				if (((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0x81)) ||
				    ((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0x83)) ||
740 741
				    ((adev->pdev->device == 0x6907) && (adev->pdev->revision == 0x87))) {
					info->is_kicker = true;
742
					strcpy(fw_name, "amdgpu/topaz_k_smc.bin");
743
				} else
744
					strcpy(fw_name, "amdgpu/topaz_smc.bin");
745
				break;
746
			case CHIP_TONGA:
747
				if (((adev->pdev->device == 0x6939) && (adev->pdev->revision == 0xf1)) ||
748 749
				    ((adev->pdev->device == 0x6938) && (adev->pdev->revision == 0xf1))) {
					info->is_kicker = true;
750
					strcpy(fw_name, "amdgpu/tonga_k_smc.bin");
751
				} else
752
					strcpy(fw_name, "amdgpu/tonga_smc.bin");
753 754 755 756 757
				break;
			case CHIP_FIJI:
				strcpy(fw_name, "amdgpu/fiji_smc.bin");
				break;
			case CHIP_POLARIS11:
758 759 760 761 762 763 764 765
				if (type == CGS_UCODE_ID_SMU) {
					if (((adev->pdev->device == 0x67ef) &&
					     ((adev->pdev->revision == 0xe0) ||
					      (adev->pdev->revision == 0xe2) ||
					      (adev->pdev->revision == 0xe5))) ||
					    ((adev->pdev->device == 0x67ff) &&
					     ((adev->pdev->revision == 0xcf) ||
					      (adev->pdev->revision == 0xef) ||
766 767
					      (adev->pdev->revision == 0xff)))) {
						info->is_kicker = true;
768
						strcpy(fw_name, "amdgpu/polaris11_k_smc.bin");
769
					} else
770 771
						strcpy(fw_name, "amdgpu/polaris11_smc.bin");
				} else if (type == CGS_UCODE_ID_SMU_SK) {
772
					strcpy(fw_name, "amdgpu/polaris11_smc_sk.bin");
773
				}
774 775
				break;
			case CHIP_POLARIS10:
776 777 778 779 780 781 782
				if (type == CGS_UCODE_ID_SMU) {
					if ((adev->pdev->device == 0x67df) &&
					    ((adev->pdev->revision == 0xe0) ||
					     (adev->pdev->revision == 0xe3) ||
					     (adev->pdev->revision == 0xe4) ||
					     (adev->pdev->revision == 0xe5) ||
					     (adev->pdev->revision == 0xe7) ||
783 784
					     (adev->pdev->revision == 0xef))) {
						info->is_kicker = true;
785
						strcpy(fw_name, "amdgpu/polaris10_k_smc.bin");
786
					} else
787 788
						strcpy(fw_name, "amdgpu/polaris10_smc.bin");
				} else if (type == CGS_UCODE_ID_SMU_SK) {
789
					strcpy(fw_name, "amdgpu/polaris10_smc_sk.bin");
790
				}
791
				break;
792 793 794
			case CHIP_POLARIS12:
				strcpy(fw_name, "amdgpu/polaris12_smc.bin");
				break;
K
Ken Wang 已提交
795
			case CHIP_VEGA10:
796 797 798 799 800 801 802
				if ((adev->pdev->device == 0x687f) &&
					((adev->pdev->revision == 0xc0) ||
					(adev->pdev->revision == 0xc1) ||
					(adev->pdev->revision == 0xc3)))
					strcpy(fw_name, "amdgpu/vega10_acg_smc.bin");
				else
					strcpy(fw_name, "amdgpu/vega10_smc.bin");
K
Ken Wang 已提交
803
				break;
R
Rex Zhu 已提交
804 805 806
			case CHIP_RAVEN:
				adev->pm.fw_version = info->version;
				return 0;
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
			default:
				DRM_ERROR("SMC firmware not supported\n");
				return -EINVAL;
			}

			err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
			if (err) {
				DRM_ERROR("Failed to request firmware\n");
				return err;
			}

			err = amdgpu_ucode_validate(adev->pm.fw);
			if (err) {
				DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
				release_firmware(adev->pm.fw);
				adev->pm.fw = NULL;
				return err;
			}
825 826 827 828 829 830 831 832 833

			if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
				ucode = &adev->firmware.ucode[AMDGPU_UCODE_ID_SMC];
				ucode->ucode_id = AMDGPU_UCODE_ID_SMC;
				ucode->fw = adev->pm.fw;
				header = (const struct common_firmware_header *)ucode->fw->data;
				adev->firmware.fw_size +=
					ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
			}
834 835 836
		}

		hdr = (const struct smc_firmware_header_v1_0 *)	adev->pm.fw->data;
Y
yanyang1 已提交
837
		amdgpu_ucode_print_smc_hdr(&hdr->header);
838 839 840 841 842 843 844 845
		adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version);
		ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes);
		ucode_start_address = le32_to_cpu(hdr->ucode_start_addr);
		src = (const uint8_t *)(adev->pm.fw->data +
		       le32_to_cpu(hdr->header.ucode_array_offset_bytes));

		info->version = adev->pm.fw_version;
		info->image_size = ucode_size;
846
		info->ucode_start_address = ucode_start_address;
847 848 849 850 851
		info->kptr = (void *)src;
	}
	return 0;
}

852 853 854 855 856 857
static int amdgpu_cgs_is_virtualization_enabled(void *cgs_device)
{
	CGS_FUNC_ADEV;
	return amdgpu_sriov_vf(adev);
}

858
static int amdgpu_cgs_query_system_info(struct cgs_device *cgs_device,
859
					struct cgs_system_info *sys_info)
860 861 862 863 864 865 866 867 868 869 870 871 872
{
	CGS_FUNC_ADEV;

	if (NULL == sys_info)
		return -ENODEV;

	if (sizeof(struct cgs_system_info) != sys_info->size)
		return -ENODEV;

	switch (sys_info->info_id) {
	case CGS_SYSTEM_INFO_ADAPTER_BDF_ID:
		sys_info->value = adev->pdev->devfn | (adev->pdev->bus->number << 8);
		break;
873 874 875 876 877 878
	case CGS_SYSTEM_INFO_PCIE_GEN_INFO:
		sys_info->value = adev->pm.pcie_gen_mask;
		break;
	case CGS_SYSTEM_INFO_PCIE_MLW:
		sys_info->value = adev->pm.pcie_mlw_mask;
		break;
879 880 881 882 883 884
	case CGS_SYSTEM_INFO_PCIE_DEV:
		sys_info->value = adev->pdev->device;
		break;
	case CGS_SYSTEM_INFO_PCIE_REV:
		sys_info->value = adev->pdev->revision;
		break;
885 886 887 888 889 890
	case CGS_SYSTEM_INFO_CG_FLAGS:
		sys_info->value = adev->cg_flags;
		break;
	case CGS_SYSTEM_INFO_PG_FLAGS:
		sys_info->value = adev->pg_flags;
		break;
891
	case CGS_SYSTEM_INFO_GFX_CU_INFO:
892
		sys_info->value = adev->gfx.cu_info.number;
893
		break;
894 895 896
	case CGS_SYSTEM_INFO_GFX_SE_INFO:
		sys_info->value = adev->gfx.config.max_shader_engines;
		break;
897 898 899 900 901 902
	case CGS_SYSTEM_INFO_PCIE_SUB_SYS_ID:
		sys_info->value = adev->pdev->subsystem_device;
		break;
	case CGS_SYSTEM_INFO_PCIE_SUB_SYS_VENDOR_ID:
		sys_info->value = adev->pdev->subsystem_vendor;
		break;
903 904 905
	case CGS_SYSTEM_INFO_PCIE_BUS_DEVFN:
		sys_info->value = adev->pdev->devfn;
		break;
906 907 908 909 910 911 912
	default:
		return -ENODEV;
	}

	return 0;
}

913
static int amdgpu_cgs_get_active_displays_info(struct cgs_device *cgs_device,
914 915 916
					  struct cgs_display_info *info)
{
	CGS_FUNC_ADEV;
917
	struct cgs_mode_info *mode_info;
918 919 920 921

	if (info == NULL)
		return -EINVAL;

922
	mode_info = info->mode_info;
923
	if (mode_info) {
924 925
		/* if the displays are off, vblank time is max */
		mode_info->vblank_time_us = 0xffffffff;
926 927 928
		/* always set the reference clock */
		mode_info->ref_clock = adev->clock.spll.reference_freq;
	}
929

930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
	if (!amdgpu_device_has_dc_support(adev)) {
		struct amdgpu_crtc *amdgpu_crtc;
		struct drm_device *ddev = adev->ddev;
		struct drm_crtc *crtc;
		uint32_t line_time_us, vblank_lines;

		if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
			list_for_each_entry(crtc,
					&ddev->mode_config.crtc_list, head) {
				amdgpu_crtc = to_amdgpu_crtc(crtc);
				if (crtc->enabled) {
					info->active_display_mask |= (1 << amdgpu_crtc->crtc_id);
					info->display_count++;
				}
				if (mode_info != NULL &&
					crtc->enabled && amdgpu_crtc->enabled &&
					amdgpu_crtc->hw_mode.clock) {
					line_time_us = (amdgpu_crtc->hw_mode.crtc_htotal * 1000) /
								amdgpu_crtc->hw_mode.clock;
					vblank_lines = amdgpu_crtc->hw_mode.crtc_vblank_end -
								amdgpu_crtc->hw_mode.crtc_vdisplay +
								(amdgpu_crtc->v_border * 2);
					mode_info->vblank_time_us = vblank_lines * line_time_us;
					mode_info->refresh_rate = drm_mode_vrefresh(&amdgpu_crtc->hw_mode);
					mode_info = NULL;
				}
956 957
			}
		}
958 959 960 961 962 963
	} else {
		info->display_count = adev->pm.pm_display_cfg.num_display;
		if (mode_info != NULL) {
			mode_info->vblank_time_us = adev->pm.pm_display_cfg.min_vblank_time;
			mode_info->refresh_rate = adev->pm.pm_display_cfg.vrefresh;
		}
964 965 966 967
	}
	return 0;
}

968

969
static int amdgpu_cgs_notify_dpm_enabled(struct cgs_device *cgs_device, bool enabled)
970 971 972 973 974 975 976 977
{
	CGS_FUNC_ADEV;

	adev->pm.dpm_enabled = enabled;

	return 0;
}

978 979 980 981 982 983 984
/** \brief evaluate acpi namespace object, handle or pathname must be valid
 *  \param cgs_device
 *  \param info input/output arguments for the control method
 *  \return status
 */

#if defined(CONFIG_ACPI)
985
static int amdgpu_cgs_acpi_eval_object(struct cgs_device *cgs_device,
986 987 988 989 990 991
				    struct cgs_acpi_method_info *info)
{
	CGS_FUNC_ADEV;
	acpi_handle handle;
	struct acpi_object_list input;
	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
992
	union acpi_object *params, *obj;
993
	uint8_t name[5] = {'\0'};
994
	struct cgs_acpi_method_argument *argument;
995 996
	uint32_t i, count;
	acpi_status status;
997
	int result;
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012

	handle = ACPI_HANDLE(&adev->pdev->dev);
	if (!handle)
		return -ENODEV;

	memset(&input, 0, sizeof(struct acpi_object_list));

	/* validate input info */
	if (info->size != sizeof(struct cgs_acpi_method_info))
		return -EINVAL;

	input.count = info->input_count;
	if (info->input_count > 0) {
		if (info->pinput_argument == NULL)
			return -EINVAL;
1013 1014 1015 1016 1017 1018 1019 1020
		argument = info->pinput_argument;
		for (i = 0; i < info->input_count; i++) {
			if (((argument->type == ACPI_TYPE_STRING) ||
			     (argument->type == ACPI_TYPE_BUFFER)) &&
			    (argument->pointer == NULL))
				return -EINVAL;
			argument++;
		}
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
	}

	if (info->output_count > 0) {
		if (info->poutput_argument == NULL)
			return -EINVAL;
		argument = info->poutput_argument;
		for (i = 0; i < info->output_count; i++) {
			if (((argument->type == ACPI_TYPE_STRING) ||
				(argument->type == ACPI_TYPE_BUFFER))
				&& (argument->pointer == NULL))
				return -EINVAL;
			argument++;
		}
	}

	/* The path name passed to acpi_evaluate_object should be null terminated */
	if ((info->field & CGS_ACPI_FIELD_METHOD_NAME) != 0) {
		strncpy(name, (char *)&(info->name), sizeof(uint32_t));
		name[4] = '\0';
	}

	/* parse input parameters */
	if (input.count > 0) {
		input.pointer = params =
				kzalloc(sizeof(union acpi_object) * input.count, GFP_KERNEL);
		if (params == NULL)
			return -EINVAL;

		argument = info->pinput_argument;

		for (i = 0; i < input.count; i++) {
			params->type = argument->type;
			switch (params->type) {
			case ACPI_TYPE_INTEGER:
				params->integer.value = argument->value;
				break;
			case ACPI_TYPE_STRING:
1058
				params->string.length = argument->data_length;
1059 1060 1061
				params->string.pointer = argument->pointer;
				break;
			case ACPI_TYPE_BUFFER:
1062
				params->buffer.length = argument->data_length;
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
				params->buffer.pointer = argument->pointer;
				break;
			default:
				break;
			}
			params++;
			argument++;
		}
	}

	/* parse output info */
	count = info->output_count;
	argument = info->poutput_argument;

	/* evaluate the acpi method */
	status = acpi_evaluate_object(handle, name, &input, &output);

	if (ACPI_FAILURE(status)) {
		result = -EIO;
1082
		goto free_input;
1083 1084 1085 1086 1087 1088 1089 1090 1091
	}

	/* return the output info */
	obj = output.pointer;

	if (count > 1) {
		if ((obj->type != ACPI_TYPE_PACKAGE) ||
			(obj->package.count != count)) {
			result = -EIO;
1092
			goto free_obj;
1093 1094 1095 1096 1097 1098 1099
		}
		params = obj->package.elements;
	} else
		params = obj;

	if (params == NULL) {
		result = -EIO;
1100
		goto free_obj;
1101 1102 1103 1104 1105
	}

	for (i = 0; i < count; i++) {
		if (argument->type != params->type) {
			result = -EIO;
1106
			goto free_obj;
1107 1108 1109 1110 1111 1112 1113 1114 1115
		}
		switch (params->type) {
		case ACPI_TYPE_INTEGER:
			argument->value = params->integer.value;
			break;
		case ACPI_TYPE_STRING:
			if ((params->string.length != argument->data_length) ||
				(params->string.pointer == NULL)) {
				result = -EIO;
1116
				goto free_obj;
1117 1118 1119 1120 1121 1122 1123 1124
			}
			strncpy(argument->pointer,
				params->string.pointer,
				params->string.length);
			break;
		case ACPI_TYPE_BUFFER:
			if (params->buffer.pointer == NULL) {
				result = -EIO;
1125
				goto free_obj;
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
			}
			memcpy(argument->pointer,
				params->buffer.pointer,
				argument->data_length);
			break;
		default:
			break;
		}
		argument++;
		params++;
	}

1138
	result = 0;
1139
free_obj:
1140
	kfree(obj);
1141
free_input:
1142 1143 1144 1145
	kfree((void *)input.pointer);
	return result;
}
#else
1146
static int amdgpu_cgs_acpi_eval_object(struct cgs_device *cgs_device,
1147 1148 1149 1150 1151 1152
				struct cgs_acpi_method_info *info)
{
	return -EIO;
}
#endif

1153
static int amdgpu_cgs_call_acpi_method(struct cgs_device *cgs_device,
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
					uint32_t acpi_method,
					uint32_t acpi_function,
					void *pinput, void *poutput,
					uint32_t output_count,
					uint32_t input_size,
					uint32_t output_size)
{
	struct cgs_acpi_method_argument acpi_input[2] = { {0}, {0} };
	struct cgs_acpi_method_argument acpi_output = {0};
	struct cgs_acpi_method_info info = {0};

	acpi_input[0].type = CGS_ACPI_TYPE_INTEGER;
	acpi_input[0].data_length = sizeof(uint32_t);
	acpi_input[0].value = acpi_function;

	acpi_input[1].type = CGS_ACPI_TYPE_BUFFER;
	acpi_input[1].data_length = input_size;
	acpi_input[1].pointer = pinput;

	acpi_output.type = CGS_ACPI_TYPE_BUFFER;
	acpi_output.data_length = output_size;
	acpi_output.pointer = poutput;

	info.size = sizeof(struct cgs_acpi_method_info);
	info.field = CGS_ACPI_FIELD_METHOD_NAME | CGS_ACPI_FIELD_INPUT_ARGUMENT_COUNT;
	info.input_count = 2;
	info.name = acpi_method;
	info.pinput_argument = acpi_input;
	info.output_count = output_count;
	info.poutput_argument = &acpi_output;

	return amdgpu_cgs_acpi_eval_object(cgs_device, &info);
}

C
Chunming Zhou 已提交
1188
static const struct cgs_ops amdgpu_cgs_ops = {
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
	.alloc_gpu_mem = amdgpu_cgs_alloc_gpu_mem,
	.free_gpu_mem = amdgpu_cgs_free_gpu_mem,
	.gmap_gpu_mem = amdgpu_cgs_gmap_gpu_mem,
	.gunmap_gpu_mem = amdgpu_cgs_gunmap_gpu_mem,
	.kmap_gpu_mem = amdgpu_cgs_kmap_gpu_mem,
	.kunmap_gpu_mem = amdgpu_cgs_kunmap_gpu_mem,
	.read_register = amdgpu_cgs_read_register,
	.write_register = amdgpu_cgs_write_register,
	.read_ind_register = amdgpu_cgs_read_ind_register,
	.write_ind_register = amdgpu_cgs_write_ind_register,
	.get_pci_resource = amdgpu_cgs_get_pci_resource,
	.atom_get_data_table = amdgpu_cgs_atom_get_data_table,
	.atom_get_cmd_table_revs = amdgpu_cgs_atom_get_cmd_table_revs,
	.atom_exec_cmd_table = amdgpu_cgs_atom_exec_cmd_table,
	.get_firmware_info = amdgpu_cgs_get_firmware_info,
	.rel_firmware = amdgpu_cgs_rel_firmware,
	.set_powergating_state = amdgpu_cgs_set_powergating_state,
	.set_clockgating_state = amdgpu_cgs_set_clockgating_state,
	.get_active_displays_info = amdgpu_cgs_get_active_displays_info,
	.notify_dpm_enabled = amdgpu_cgs_notify_dpm_enabled,
	.call_acpi_method = amdgpu_cgs_call_acpi_method,
	.query_system_info = amdgpu_cgs_query_system_info,
	.is_virtualization_enabled = amdgpu_cgs_is_virtualization_enabled,
1212
	.enter_safe_mode = amdgpu_cgs_enter_safe_mode,
1213
	.lock_grbm_idx = amdgpu_cgs_lock_grbm_idx,
1214
	.register_pp_handle = amdgpu_cgs_register_pp_handle,
C
Chunming Zhou 已提交
1215 1216 1217
};

static const struct cgs_os_ops amdgpu_cgs_os_ops = {
1218 1219 1220
	.add_irq_source = amdgpu_cgs_add_irq_source,
	.irq_get = amdgpu_cgs_irq_get,
	.irq_put = amdgpu_cgs_irq_put
C
Chunming Zhou 已提交
1221 1222
};

1223
struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev)
C
Chunming Zhou 已提交
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
{
	struct amdgpu_cgs_device *cgs_device =
		kmalloc(sizeof(*cgs_device), GFP_KERNEL);

	if (!cgs_device) {
		DRM_ERROR("Couldn't allocate CGS device structure\n");
		return NULL;
	}

	cgs_device->base.ops = &amdgpu_cgs_ops;
	cgs_device->base.os_ops = &amdgpu_cgs_os_ops;
	cgs_device->adev = adev;

1237
	return (struct cgs_device *)cgs_device;
C
Chunming Zhou 已提交
1238 1239
}

1240
void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device)
C
Chunming Zhou 已提交
1241 1242 1243
{
	kfree(cgs_device);
}