amdgpu_irq.c 17.2 KB
Newer Older
A
Alex Deucher 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Copyright 2008 Advanced Micro Devices, Inc.
 * Copyright 2008 Red Hat Inc.
 * Copyright 2009 Jerome Glisse.
 *
 * 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.
 *
 * Authors: Dave Airlie
 *          Alex Deucher
 *          Jerome Glisse
 */
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

/**
 * DOC: Interrupt Handling
 *
 * Interrupts generated within GPU hardware raise interrupt requests that are
 * passed to amdgpu IRQ handler which is responsible for detecting source and
 * type of the interrupt and dispatching matching handlers. If handling an
 * interrupt requires calling kernel functions that may sleep processing is
 * dispatched to work handlers.
 *
 * If MSI functionality is not disabled by module parameter then MSI
 * support will be enabled.
 *
 * For GPU interrupt sources that may be driven by another driver, IRQ domain
 * support is used (with mapping between virtual and hardware IRQs).
 */

45
#include <linux/irq.h>
A
Alex Deucher 已提交
46 47 48 49 50 51 52
#include <drm/drmP.h>
#include <drm/drm_crtc_helper.h>
#include <drm/amdgpu_drm.h>
#include "amdgpu.h"
#include "amdgpu_ih.h"
#include "atom.h"
#include "amdgpu_connectors.h"
53
#include "amdgpu_trace.h"
54
#include "amdgpu_amdkfd.h"
A
Alex Deucher 已提交
55 56 57

#include <linux/pm_runtime.h>

58 59 60 61
#ifdef CONFIG_DRM_AMD_DC
#include "amdgpu_dm_irq.h"
#endif

A
Alex Deucher 已提交
62 63 64
#define AMDGPU_WAIT_IDLE_TIMEOUT 200

/**
65
 * amdgpu_hotplug_work_func - work handler for display hotplug event
A
Alex Deucher 已提交
66
 *
67
 * @work: work struct pointer
A
Alex Deucher 已提交
68
 *
69 70 71 72 73 74 75 76 77 78
 * This is the hotplug event work handler (all ASICs).
 * The work gets scheduled from the IRQ handler if there
 * was a hotplug interrupt.  It walks through the connector table
 * and calls hotplug handler for each connector. After this, it sends
 * a DRM hotplug event to alert userspace.
 *
 * This design approach is required in order to defer hotplug event handling
 * from the IRQ handler to a work handler because hotplug handler has to use
 * mutexes which cannot be locked in an IRQ handler (since &mutex_lock may
 * sleep).
A
Alex Deucher 已提交
79 80 81 82 83 84 85 86 87
 */
static void amdgpu_hotplug_work_func(struct work_struct *work)
{
	struct amdgpu_device *adev = container_of(work, struct amdgpu_device,
						  hotplug_work);
	struct drm_device *dev = adev->ddev;
	struct drm_mode_config *mode_config = &dev->mode_config;
	struct drm_connector *connector;

88
	mutex_lock(&mode_config->mutex);
89 90
	list_for_each_entry(connector, &mode_config->connector_list, head)
		amdgpu_connector_hotplug(connector);
91
	mutex_unlock(&mode_config->mutex);
A
Alex Deucher 已提交
92 93 94 95
	/* Just fire off a uevent and let userspace tell us what to do */
	drm_helper_hpd_irq_event(dev);
}

96 97 98 99 100 101 102
/**
 * amdgpu_irq_disable_all - disable *all* interrupts
 *
 * @adev: amdgpu device pointer
 *
 * Disable all types of interrupts from all sources.
 */
103
void amdgpu_irq_disable_all(struct amdgpu_device *adev)
A
Alex Deucher 已提交
104 105
{
	unsigned long irqflags;
106
	unsigned i, j, k;
A
Alex Deucher 已提交
107 108 109
	int r;

	spin_lock_irqsave(&adev->irq.lock, irqflags);
110
	for (i = 0; i < AMDGPU_IRQ_CLIENTID_MAX; ++i) {
111
		if (!adev->irq.client[i].sources)
A
Alex Deucher 已提交
112 113
			continue;

114 115 116 117 118 119 120 121 122 123 124 125 126 127
		for (j = 0; j < AMDGPU_MAX_IRQ_SRC_ID; ++j) {
			struct amdgpu_irq_src *src = adev->irq.client[i].sources[j];

			if (!src || !src->funcs->set || !src->num_types)
				continue;

			for (k = 0; k < src->num_types; ++k) {
				atomic_set(&src->enabled_types[k], 0);
				r = src->funcs->set(adev, src, k,
						    AMDGPU_IRQ_STATE_DISABLE);
				if (r)
					DRM_ERROR("error disabling interrupt (%d)\n",
						  r);
			}
A
Alex Deucher 已提交
128 129 130 131 132
		}
	}
	spin_unlock_irqrestore(&adev->irq.lock, irqflags);
}

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
/**
 * amdgpu_irq_callback - callback from the IH ring
 *
 * @adev: amdgpu device pointer
 * @ih: amdgpu ih ring
 *
 * Callback from IH ring processing to handle the entry at the current position
 * and advance the read pointer.
 */
static void amdgpu_irq_callback(struct amdgpu_device *adev,
				struct amdgpu_ih_ring *ih)
{
	u32 ring_index = ih->rptr >> 2;
	struct amdgpu_iv_entry entry;

	entry.iv_entry = (const uint32_t *)&ih->ring[ring_index];
	amdgpu_ih_decode_iv(adev, &entry);

151 152
	trace_amdgpu_iv(ih - &adev->irq.ih, &entry);

153 154 155
	amdgpu_irq_dispatch(adev, &entry);
}

A
Alex Deucher 已提交
156
/**
157 158 159 160
 * amdgpu_irq_handler - IRQ handler
 *
 * @irq: IRQ number (unused)
 * @arg: pointer to DRM device
A
Alex Deucher 已提交
161
 *
162
 * IRQ handler for amdgpu driver (all ASICs).
A
Alex Deucher 已提交
163
 *
164 165
 * Returns:
 * result of handling the IRQ, as defined by &irqreturn_t
A
Alex Deucher 已提交
166 167 168 169 170 171 172
 */
irqreturn_t amdgpu_irq_handler(int irq, void *arg)
{
	struct drm_device *dev = (struct drm_device *) arg;
	struct amdgpu_device *adev = dev->dev_private;
	irqreturn_t ret;

173
	ret = amdgpu_ih_process(adev, &adev->irq.ih, amdgpu_irq_callback);
A
Alex Deucher 已提交
174 175 176 177 178
	if (ret == IRQ_HANDLED)
		pm_runtime_mark_last_busy(dev->dev);
	return ret;
}

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
/**
 * amdgpu_irq_handle_ih1 - kick of processing for IH1
 *
 * @work: work structure in struct amdgpu_irq
 *
 * Kick of processing IH ring 1.
 */
static void amdgpu_irq_handle_ih1(struct work_struct *work)
{
	struct amdgpu_device *adev = container_of(work, struct amdgpu_device,
						  irq.ih1_work);

	amdgpu_ih_process(adev, &adev->irq.ih1, amdgpu_irq_callback);
}

/**
 * amdgpu_irq_handle_ih2 - kick of processing for IH2
 *
 * @work: work structure in struct amdgpu_irq
 *
 * Kick of processing IH ring 2.
 */
static void amdgpu_irq_handle_ih2(struct work_struct *work)
{
	struct amdgpu_device *adev = container_of(work, struct amdgpu_device,
						  irq.ih2_work);

	amdgpu_ih_process(adev, &adev->irq.ih2, amdgpu_irq_callback);
}

A
Alex Deucher 已提交
209
/**
210
 * amdgpu_msi_ok - check whether MSI functionality is enabled
A
Alex Deucher 已提交
211
 *
212 213 214 215
 * @adev: amdgpu device pointer (unused)
 *
 * Checks whether MSI functionality has been disabled via module parameter
 * (all ASICs).
A
Alex Deucher 已提交
216
 *
217 218
 * Returns:
 * *true* if MSIs are allowed to be enabled or *false* otherwise
A
Alex Deucher 已提交
219 220 221 222 223 224 225 226 227 228 229 230
 */
static bool amdgpu_msi_ok(struct amdgpu_device *adev)
{
	if (amdgpu_msi == 1)
		return true;
	else if (amdgpu_msi == 0)
		return false;

	return true;
}

/**
231
 * amdgpu_irq_init - initialize interrupt handling
A
Alex Deucher 已提交
232 233 234
 *
 * @adev: amdgpu device pointer
 *
235 236 237 238 239
 * Sets up work functions for hotplug and reset interrupts, enables MSI
 * functionality, initializes vblank, hotplug and reset interrupt handling.
 *
 * Returns:
 * 0 on success or error code on failure
A
Alex Deucher 已提交
240 241 242 243 244 245
 */
int amdgpu_irq_init(struct amdgpu_device *adev)
{
	int r = 0;

	spin_lock_init(&adev->irq.lock);
246

247
	/* Enable MSI if not disabled by module parameter */
A
Alex Deucher 已提交
248 249 250 251 252 253
	adev->irq.msi_enabled = false;

	if (amdgpu_msi_ok(adev)) {
		int ret = pci_enable_msi(adev->pdev);
		if (!ret) {
			adev->irq.msi_enabled = true;
254
			dev_dbg(adev->dev, "amdgpu: using MSI.\n");
A
Alex Deucher 已提交
255 256 257
		}
	}

258 259
	if (!amdgpu_device_has_dc_support(adev)) {
		if (!adev->enable_virtual_display)
260
			/* Disable vblank IRQs aggressively for power-saving */
261 262 263 264 265 266 267
			/* XXX: can this be enabled for DC? */
			adev->ddev->vblank_disable_immediate = true;

		r = drm_vblank_init(adev->ddev, adev->mode_info.num_crtc);
		if (r)
			return r;

268
		/* Pre-DCE11 */
269 270 271 272
		INIT_WORK(&adev->hotplug_work,
				amdgpu_hotplug_work_func);
	}

273 274 275
	INIT_WORK(&adev->irq.ih1_work, amdgpu_irq_handle_ih1);
	INIT_WORK(&adev->irq.ih2_work, amdgpu_irq_handle_ih2);

A
Alex Deucher 已提交
276 277 278 279
	adev->irq.installed = true;
	r = drm_irq_install(adev->ddev, adev->ddev->pdev->irq);
	if (r) {
		adev->irq.installed = false;
280 281
		if (!amdgpu_device_has_dc_support(adev))
			flush_work(&adev->hotplug_work);
A
Alex Deucher 已提交
282 283
		return r;
	}
284
	adev->ddev->max_vblank_count = 0x00ffffff;
A
Alex Deucher 已提交
285

286
	DRM_DEBUG("amdgpu: irq initialized.\n");
A
Alex Deucher 已提交
287 288 289 290
	return 0;
}

/**
291
 * amdgpu_irq_fini - shut down interrupt handling
A
Alex Deucher 已提交
292 293 294
 *
 * @adev: amdgpu device pointer
 *
295 296 297
 * Tears down work functions for hotplug and reset interrupts, disables MSI
 * functionality, shuts down vblank, hotplug and reset interrupt handling,
 * turns off interrupts from all sources (all ASICs).
A
Alex Deucher 已提交
298 299 300
 */
void amdgpu_irq_fini(struct amdgpu_device *adev)
{
301
	unsigned i, j;
A
Alex Deucher 已提交
302 303 304 305 306 307

	if (adev->irq.installed) {
		drm_irq_uninstall(adev->ddev);
		adev->irq.installed = false;
		if (adev->irq.msi_enabled)
			pci_disable_msi(adev->pdev);
308 309
		if (!amdgpu_device_has_dc_support(adev))
			flush_work(&adev->hotplug_work);
A
Alex Deucher 已提交
310 311
	}

312
	for (i = 0; i < AMDGPU_IRQ_CLIENTID_MAX; ++i) {
313
		if (!adev->irq.client[i].sources)
A
Alex Deucher 已提交
314 315
			continue;

316 317 318 319 320 321 322 323 324 325 326 327 328
		for (j = 0; j < AMDGPU_MAX_IRQ_SRC_ID; ++j) {
			struct amdgpu_irq_src *src = adev->irq.client[i].sources[j];

			if (!src)
				continue;

			kfree(src->enabled_types);
			src->enabled_types = NULL;
			if (src->data) {
				kfree(src->data);
				kfree(src);
				adev->irq.client[i].sources[j] = NULL;
			}
329
		}
330
		kfree(adev->irq.client[i].sources);
331
		adev->irq.client[i].sources = NULL;
A
Alex Deucher 已提交
332 333 334 335
	}
}

/**
336
 * amdgpu_irq_add_id - register IRQ source
A
Alex Deucher 已提交
337 338
 *
 * @adev: amdgpu device pointer
339 340 341 342 343
 * @client_id: client id
 * @src_id: source id
 * @source: IRQ source pointer
 *
 * Registers IRQ source on a client.
A
Alex Deucher 已提交
344
 *
345 346
 * Returns:
 * 0 on success or error code otherwise
A
Alex Deucher 已提交
347
 */
348 349
int amdgpu_irq_add_id(struct amdgpu_device *adev,
		      unsigned client_id, unsigned src_id,
A
Alex Deucher 已提交
350 351
		      struct amdgpu_irq_src *source)
{
352
	if (client_id >= AMDGPU_IRQ_CLIENTID_MAX)
A
Alex Deucher 已提交
353 354
		return -EINVAL;

355
	if (src_id >= AMDGPU_MAX_IRQ_SRC_ID)
A
Alex Deucher 已提交
356 357 358 359 360
		return -EINVAL;

	if (!source->funcs)
		return -EINVAL;

361
	if (!adev->irq.client[client_id].sources) {
362 363 364 365
		adev->irq.client[client_id].sources =
			kcalloc(AMDGPU_MAX_IRQ_SRC_ID,
				sizeof(struct amdgpu_irq_src *),
				GFP_KERNEL);
366 367 368 369 370 371 372
		if (!adev->irq.client[client_id].sources)
			return -ENOMEM;
	}

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

A
Alex Deucher 已提交
373 374 375 376 377 378 379 380 381 382 383
	if (source->num_types && !source->enabled_types) {
		atomic_t *types;

		types = kcalloc(source->num_types, sizeof(atomic_t),
				GFP_KERNEL);
		if (!types)
			return -ENOMEM;

		source->enabled_types = types;
	}

384
	adev->irq.client[client_id].sources[src_id] = source;
A
Alex Deucher 已提交
385 386 387 388
	return 0;
}

/**
389
 * amdgpu_irq_dispatch - dispatch IRQ to IP blocks
A
Alex Deucher 已提交
390 391
 *
 * @adev: amdgpu device pointer
392
 * @entry: interrupt vector pointer
A
Alex Deucher 已提交
393
 *
394
 * Dispatches IRQ to IP blocks.
A
Alex Deucher 已提交
395 396 397 398
 */
void amdgpu_irq_dispatch(struct amdgpu_device *adev,
			 struct amdgpu_iv_entry *entry)
{
399
	unsigned client_id = entry->client_id;
A
Alex Deucher 已提交
400 401
	unsigned src_id = entry->src_id;
	struct amdgpu_irq_src *src;
402
	bool handled = false;
A
Alex Deucher 已提交
403 404
	int r;

405
	if (client_id >= AMDGPU_IRQ_CLIENTID_MAX) {
406 407
		DRM_DEBUG("Invalid client_id in IV: %d\n", client_id);

408
	} else	if (src_id >= AMDGPU_MAX_IRQ_SRC_ID) {
A
Alex Deucher 已提交
409 410
		DRM_DEBUG("Invalid src_id in IV: %d\n", src_id);

411
	} else if (adev->irq.virq[src_id]) {
412
		generic_handle_irq(irq_find_mapping(adev->irq.domain, src_id));
413

414 415 416
	} else if (!adev->irq.client[client_id].sources) {
		DRM_DEBUG("Unregistered interrupt client_id: %d src_id: %d\n",
			  client_id, src_id);
A
Alex Deucher 已提交
417

418
	} else if ((src = adev->irq.client[client_id].sources[src_id])) {
419
		r = src->funcs->process(adev, src, entry);
420
		if (r < 0)
421
			DRM_ERROR("error processing interrupt (%d)\n", r);
422 423 424 425 426
		else if (r)
			handled = true;

	} else {
		DRM_DEBUG("Unhandled interrupt src_id: %d\n", src_id);
427
	}
428 429 430 431

	/* Send it to amdkfd as well if it isn't already handled */
	if (!handled)
		amdgpu_amdkfd_interrupt(adev, entry->iv_entry);
A
Alex Deucher 已提交
432 433 434
}

/**
435
 * amdgpu_irq_update - update hardware interrupt state
A
Alex Deucher 已提交
436 437
 *
 * @adev: amdgpu device pointer
438 439
 * @src: interrupt source pointer
 * @type: type of interrupt
A
Alex Deucher 已提交
440
 *
441
 * Updates interrupt state for the specific source (all ASICs).
A
Alex Deucher 已提交
442 443 444 445 446 447 448 449 450 451
 */
int amdgpu_irq_update(struct amdgpu_device *adev,
			     struct amdgpu_irq_src *src, unsigned type)
{
	unsigned long irqflags;
	enum amdgpu_interrupt_state state;
	int r;

	spin_lock_irqsave(&adev->irq.lock, irqflags);

452
	/* We need to determine after taking the lock, otherwise
A
Alex Deucher 已提交
453 454 455 456 457 458 459 460 461 462 463
	   we might disable just enabled interrupts again */
	if (amdgpu_irq_enabled(adev, src, type))
		state = AMDGPU_IRQ_STATE_ENABLE;
	else
		state = AMDGPU_IRQ_STATE_DISABLE;

	r = src->funcs->set(adev, src, type, state);
	spin_unlock_irqrestore(&adev->irq.lock, irqflags);
	return r;
}

464 465 466 467 468 469 470 471
/**
 * amdgpu_irq_gpu_reset_resume_helper - update interrupt states on all sources
 *
 * @adev: amdgpu device pointer
 *
 * Updates state of all types of interrupts on all sources on resume after
 * reset.
 */
472 473
void amdgpu_irq_gpu_reset_resume_helper(struct amdgpu_device *adev)
{
474 475
	int i, j, k;

476
	for (i = 0; i < AMDGPU_IRQ_CLIENTID_MAX; ++i) {
477
		if (!adev->irq.client[i].sources)
478
			continue;
479 480 481 482 483 484 485 486 487

		for (j = 0; j < AMDGPU_MAX_IRQ_SRC_ID; ++j) {
			struct amdgpu_irq_src *src = adev->irq.client[i].sources[j];

			if (!src)
				continue;
			for (k = 0; k < src->num_types; k++)
				amdgpu_irq_update(adev, src, k);
		}
488 489 490
	}
}

A
Alex Deucher 已提交
491 492 493 494
/**
 * amdgpu_irq_get - enable interrupt
 *
 * @adev: amdgpu device pointer
495 496
 * @src: interrupt source pointer
 * @type: type of interrupt
A
Alex Deucher 已提交
497
 *
498 499 500 501
 * Enables specified type of interrupt on the specified source (all ASICs).
 *
 * Returns:
 * 0 on success or error code otherwise
A
Alex Deucher 已提交
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
 */
int amdgpu_irq_get(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
		   unsigned type)
{
	if (!adev->ddev->irq_enabled)
		return -ENOENT;

	if (type >= src->num_types)
		return -EINVAL;

	if (!src->enabled_types || !src->funcs->set)
		return -EINVAL;

	if (atomic_inc_return(&src->enabled_types[type]) == 1)
		return amdgpu_irq_update(adev, src, type);

	return 0;
}

/**
 * amdgpu_irq_put - disable interrupt
 *
 * @adev: amdgpu device pointer
525 526 527 528
 * @src: interrupt source pointer
 * @type: type of interrupt
 *
 * Enables specified type of interrupt on the specified source (all ASICs).
A
Alex Deucher 已提交
529
 *
530 531
 * Returns:
 * 0 on success or error code otherwise
A
Alex Deucher 已提交
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
 */
int amdgpu_irq_put(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
		   unsigned type)
{
	if (!adev->ddev->irq_enabled)
		return -ENOENT;

	if (type >= src->num_types)
		return -EINVAL;

	if (!src->enabled_types || !src->funcs->set)
		return -EINVAL;

	if (atomic_dec_and_test(&src->enabled_types[type]))
		return amdgpu_irq_update(adev, src, type);

	return 0;
}

/**
552
 * amdgpu_irq_enabled - check whether interrupt is enabled or not
A
Alex Deucher 已提交
553 554
 *
 * @adev: amdgpu device pointer
555 556
 * @src: interrupt source pointer
 * @type: type of interrupt
A
Alex Deucher 已提交
557
 *
558 559 560 561 562
 * Checks whether the given type of interrupt is enabled on the given source.
 *
 * Returns:
 * *true* if interrupt is enabled, *false* if interrupt is disabled or on
 * invalid parameters
A
Alex Deucher 已提交
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
 */
bool amdgpu_irq_enabled(struct amdgpu_device *adev, struct amdgpu_irq_src *src,
			unsigned type)
{
	if (!adev->ddev->irq_enabled)
		return false;

	if (type >= src->num_types)
		return false;

	if (!src->enabled_types || !src->funcs->set)
		return false;

	return !!atomic_read(&src->enabled_types[type]);
}
578

579
/* XXX: Generic IRQ handling */
580 581 582 583 584 585 586 587 588 589
static void amdgpu_irq_mask(struct irq_data *irqd)
{
	/* XXX */
}

static void amdgpu_irq_unmask(struct irq_data *irqd)
{
	/* XXX */
}

590
/* amdgpu hardware interrupt chip descriptor */
591 592 593 594 595 596
static struct irq_chip amdgpu_irq_chip = {
	.name = "amdgpu-ih",
	.irq_mask = amdgpu_irq_mask,
	.irq_unmask = amdgpu_irq_unmask,
};

597 598 599 600 601 602 603 604 605 606 607 608 609
/**
 * amdgpu_irqdomain_map - create mapping between virtual and hardware IRQ numbers
 *
 * @d: amdgpu IRQ domain pointer (unused)
 * @irq: virtual IRQ number
 * @hwirq: hardware irq number
 *
 * Current implementation assigns simple interrupt handler to the given virtual
 * IRQ.
 *
 * Returns:
 * 0 on success or error code otherwise
 */
610 611 612 613 614 615 616 617 618 619 620
static int amdgpu_irqdomain_map(struct irq_domain *d,
				unsigned int irq, irq_hw_number_t hwirq)
{
	if (hwirq >= AMDGPU_MAX_IRQ_SRC_ID)
		return -EPERM;

	irq_set_chip_and_handler(irq,
				 &amdgpu_irq_chip, handle_simple_irq);
	return 0;
}

621
/* Implementation of methods for amdgpu IRQ domain */
622
static const struct irq_domain_ops amdgpu_hw_irqdomain_ops = {
623 624 625 626
	.map = amdgpu_irqdomain_map,
};

/**
627
 * amdgpu_irq_add_domain - create a linear IRQ domain
628 629 630
 *
 * @adev: amdgpu device pointer
 *
631
 * Creates an IRQ domain for GPU interrupt sources
632
 * that may be driven by another driver (e.g., ACP).
633 634 635
 *
 * Returns:
 * 0 on success or error code otherwise
636 637 638 639 640 641 642 643 644 645 646 647 648 649
 */
int amdgpu_irq_add_domain(struct amdgpu_device *adev)
{
	adev->irq.domain = irq_domain_add_linear(NULL, AMDGPU_MAX_IRQ_SRC_ID,
						 &amdgpu_hw_irqdomain_ops, adev);
	if (!adev->irq.domain) {
		DRM_ERROR("GPU irq add domain failed\n");
		return -ENODEV;
	}

	return 0;
}

/**
650
 * amdgpu_irq_remove_domain - remove the IRQ domain
651 652 653
 *
 * @adev: amdgpu device pointer
 *
654
 * Removes the IRQ domain for GPU interrupt sources
655 656 657 658 659 660 661 662 663 664 665
 * that may be driven by another driver (e.g., ACP).
 */
void amdgpu_irq_remove_domain(struct amdgpu_device *adev)
{
	if (adev->irq.domain) {
		irq_domain_remove(adev->irq.domain);
		adev->irq.domain = NULL;
	}
}

/**
666
 * amdgpu_irq_create_mapping - create mapping between domain Linux IRQs
667 668 669 670
 *
 * @adev: amdgpu device pointer
 * @src_id: IH source id
 *
671
 * Creates mapping between a domain IRQ (GPU IH src id) and a Linux IRQ
672 673
 * Use this for components that generate a GPU interrupt, but are driven
 * by a different driver (e.g., ACP).
674 675 676
 *
 * Returns:
 * Linux IRQ
677 678 679 680 681 682 683
 */
unsigned amdgpu_irq_create_mapping(struct amdgpu_device *adev, unsigned src_id)
{
	adev->irq.virq[src_id] = irq_create_mapping(adev->irq.domain, src_id);

	return adev->irq.virq[src_id];
}