1926deccbSFrançois Tigeot /*
2926deccbSFrançois Tigeot * Copyright 2008 Advanced Micro Devices, Inc.
3926deccbSFrançois Tigeot * Copyright 2008 Red Hat Inc.
4926deccbSFrançois Tigeot * Copyright 2009 Jerome Glisse.
5926deccbSFrançois Tigeot *
6926deccbSFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a
7926deccbSFrançois Tigeot * copy of this software and associated documentation files (the "Software"),
8926deccbSFrançois Tigeot * to deal in the Software without restriction, including without limitation
9926deccbSFrançois Tigeot * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10926deccbSFrançois Tigeot * and/or sell copies of the Software, and to permit persons to whom the
11926deccbSFrançois Tigeot * Software is furnished to do so, subject to the following conditions:
12926deccbSFrançois Tigeot *
13926deccbSFrançois Tigeot * The above copyright notice and this permission notice shall be included in
14926deccbSFrançois Tigeot * all copies or substantial portions of the Software.
15926deccbSFrançois Tigeot *
16926deccbSFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17926deccbSFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18926deccbSFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19926deccbSFrançois Tigeot * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20926deccbSFrançois Tigeot * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21926deccbSFrançois Tigeot * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22926deccbSFrançois Tigeot * OTHER DEALINGS IN THE SOFTWARE.
23926deccbSFrançois Tigeot *
24926deccbSFrançois Tigeot * Authors: Dave Airlie
25926deccbSFrançois Tigeot * Alex Deucher
26926deccbSFrançois Tigeot * Jerome Glisse
27926deccbSFrançois Tigeot */
28926deccbSFrançois Tigeot #include <drm/drmP.h>
29926deccbSFrançois Tigeot #include <drm/drm_crtc_helper.h>
3083b4b9b9SFrançois Tigeot #include <drm/radeon_drm.h>
31926deccbSFrançois Tigeot #include "radeon_reg.h"
32926deccbSFrançois Tigeot #include "radeon_irq_kms.h"
33926deccbSFrançois Tigeot #include "radeon.h"
34926deccbSFrançois Tigeot #include "atom.h"
35926deccbSFrançois Tigeot
36c6f73aabSFrançois Tigeot #include <linux/pm_runtime.h>
37c6f73aabSFrançois Tigeot
38926deccbSFrançois Tigeot #define RADEON_WAIT_IDLE_TIMEOUT 200
39926deccbSFrançois Tigeot
40926deccbSFrançois Tigeot /**
41926deccbSFrançois Tigeot * radeon_driver_irq_handler_kms - irq handler for KMS
42926deccbSFrançois Tigeot *
43a85cb24fSFrançois Tigeot * @int irq, void *arg: args
44926deccbSFrançois Tigeot *
45926deccbSFrançois Tigeot * This is the irq handler for the radeon KMS driver (all asics).
46926deccbSFrançois Tigeot * radeon_irq_process is a macro that points to the per-asic
47926deccbSFrançois Tigeot * irq handler callback.
48926deccbSFrançois Tigeot */
radeon_driver_irq_handler_kms(int irq,void * arg)49183e2373SFrançois Tigeot irqreturn_t radeon_driver_irq_handler_kms(int irq, void *arg)
50926deccbSFrançois Tigeot {
51926deccbSFrançois Tigeot struct drm_device *dev = (struct drm_device *) arg;
52926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private;
53c6f73aabSFrançois Tigeot irqreturn_t ret;
54926deccbSFrançois Tigeot
55c6f73aabSFrançois Tigeot ret = radeon_irq_process(rdev);
56183e2373SFrançois Tigeot #ifdef PM_TODO
57c6f73aabSFrançois Tigeot if (ret == IRQ_HANDLED)
58c6f73aabSFrançois Tigeot pm_runtime_mark_last_busy(dev->dev);
59c6f73aabSFrançois Tigeot #endif
60183e2373SFrançois Tigeot return ret;
61926deccbSFrançois Tigeot }
62926deccbSFrançois Tigeot
63926deccbSFrançois Tigeot /*
64926deccbSFrançois Tigeot * Handle hotplug events outside the interrupt handler proper.
65926deccbSFrançois Tigeot */
66926deccbSFrançois Tigeot /**
67926deccbSFrançois Tigeot * radeon_hotplug_work_func - display hotplug work handler
68926deccbSFrançois Tigeot *
69926deccbSFrançois Tigeot * @work: work struct
70926deccbSFrançois Tigeot *
71926deccbSFrançois Tigeot * This is the hot plug event work handler (all asics).
72926deccbSFrançois Tigeot * The work gets scheduled from the irq handler if there
73926deccbSFrançois Tigeot * was a hot plug interrupt. It walks the connector table
74926deccbSFrançois Tigeot * and calls the hotplug handler for each one, then sends
75926deccbSFrançois Tigeot * a drm hotplug event to alert userspace.
76926deccbSFrançois Tigeot */
radeon_hotplug_work_func(struct work_struct * work)772c5cc6b9SFrançois Tigeot static void radeon_hotplug_work_func(struct work_struct *work)
78926deccbSFrançois Tigeot {
792c5cc6b9SFrançois Tigeot struct radeon_device *rdev = container_of(work, struct radeon_device,
80c59a5c48SFrançois Tigeot hotplug_work.work);
81926deccbSFrançois Tigeot struct drm_device *dev = rdev->ddev;
82926deccbSFrançois Tigeot struct drm_mode_config *mode_config = &dev->mode_config;
83926deccbSFrançois Tigeot struct drm_connector *connector;
84926deccbSFrançois Tigeot
85c59a5c48SFrançois Tigeot /* we can race here at startup, some boards seem to trigger
86c59a5c48SFrançois Tigeot * hotplug irqs when they shouldn't. */
87c59a5c48SFrançois Tigeot if (!rdev->mode_info.mode_config_initialized)
88c59a5c48SFrançois Tigeot return;
89c59a5c48SFrançois Tigeot
90c59a5c48SFrançois Tigeot mutex_lock(&mode_config->mutex);
91926deccbSFrançois Tigeot list_for_each_entry(connector, &mode_config->connector_list, head)
92926deccbSFrançois Tigeot radeon_connector_hotplug(connector);
93c59a5c48SFrançois Tigeot mutex_unlock(&mode_config->mutex);
94926deccbSFrançois Tigeot /* Just fire off a uevent and let userspace tell us what to do */
95926deccbSFrançois Tigeot drm_helper_hpd_irq_event(dev);
96926deccbSFrançois Tigeot }
97926deccbSFrançois Tigeot
radeon_dp_work_func(struct work_struct * work)98c59a5c48SFrançois Tigeot static void radeon_dp_work_func(struct work_struct *work)
99c59a5c48SFrançois Tigeot {
100c59a5c48SFrançois Tigeot struct radeon_device *rdev = container_of(work, struct radeon_device,
101c59a5c48SFrançois Tigeot dp_work);
102c59a5c48SFrançois Tigeot struct drm_device *dev = rdev->ddev;
103c59a5c48SFrançois Tigeot struct drm_mode_config *mode_config = &dev->mode_config;
104c59a5c48SFrançois Tigeot struct drm_connector *connector;
105c59a5c48SFrançois Tigeot
106c59a5c48SFrançois Tigeot /* this should take a mutex */
107c59a5c48SFrançois Tigeot list_for_each_entry(connector, &mode_config->connector_list, head)
108c59a5c48SFrançois Tigeot radeon_connector_hotplug(connector);
109c59a5c48SFrançois Tigeot }
110926deccbSFrançois Tigeot /**
111926deccbSFrançois Tigeot * radeon_driver_irq_preinstall_kms - drm irq preinstall callback
112926deccbSFrançois Tigeot *
113926deccbSFrançois Tigeot * @dev: drm dev pointer
114926deccbSFrançois Tigeot *
115926deccbSFrançois Tigeot * Gets the hw ready to enable irqs (all asics).
116926deccbSFrançois Tigeot * This function disables all interrupt sources on the GPU.
117926deccbSFrançois Tigeot */
radeon_driver_irq_preinstall_kms(struct drm_device * dev)118926deccbSFrançois Tigeot void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
119926deccbSFrançois Tigeot {
120926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private;
121a85cb24fSFrançois Tigeot unsigned long irqflags;
122926deccbSFrançois Tigeot unsigned i;
123926deccbSFrançois Tigeot
124a85cb24fSFrançois Tigeot spin_lock_irqsave(&rdev->irq.lock, irqflags);
125926deccbSFrançois Tigeot /* Disable *all* interrupts */
126926deccbSFrançois Tigeot for (i = 0; i < RADEON_NUM_RINGS; i++)
127926deccbSFrançois Tigeot atomic_set(&rdev->irq.ring_int[i], 0);
12857e252bfSMichael Neumann rdev->irq.dpm_thermal = false;
129926deccbSFrançois Tigeot for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
130926deccbSFrançois Tigeot rdev->irq.hpd[i] = false;
131926deccbSFrançois Tigeot for (i = 0; i < RADEON_MAX_CRTCS; i++) {
132926deccbSFrançois Tigeot rdev->irq.crtc_vblank_int[i] = false;
133926deccbSFrançois Tigeot atomic_set(&rdev->irq.pflip[i], 0);
134926deccbSFrançois Tigeot rdev->irq.afmt[i] = false;
135926deccbSFrançois Tigeot }
136926deccbSFrançois Tigeot radeon_irq_set(rdev);
137a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
138926deccbSFrançois Tigeot /* Clear bits */
139926deccbSFrançois Tigeot radeon_irq_process(rdev);
140926deccbSFrançois Tigeot }
141926deccbSFrançois Tigeot
142926deccbSFrançois Tigeot /**
143926deccbSFrançois Tigeot * radeon_driver_irq_postinstall_kms - drm irq preinstall callback
144926deccbSFrançois Tigeot *
145926deccbSFrançois Tigeot * @dev: drm dev pointer
146926deccbSFrançois Tigeot *
147926deccbSFrançois Tigeot * Handles stuff to be done after enabling irqs (all asics).
148926deccbSFrançois Tigeot * Returns 0 on success.
149926deccbSFrançois Tigeot */
radeon_driver_irq_postinstall_kms(struct drm_device * dev)150926deccbSFrançois Tigeot int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
151926deccbSFrançois Tigeot {
152c59a5c48SFrançois Tigeot struct radeon_device *rdev = dev->dev_private;
153c59a5c48SFrançois Tigeot
154c59a5c48SFrançois Tigeot if (ASIC_IS_AVIVO(rdev))
155c59a5c48SFrançois Tigeot dev->max_vblank_count = 0x00ffffff;
156c59a5c48SFrançois Tigeot else
157926deccbSFrançois Tigeot dev->max_vblank_count = 0x001fffff;
158c59a5c48SFrançois Tigeot
159926deccbSFrançois Tigeot return 0;
160926deccbSFrançois Tigeot }
161926deccbSFrançois Tigeot
162926deccbSFrançois Tigeot /**
163926deccbSFrançois Tigeot * radeon_driver_irq_uninstall_kms - drm irq uninstall callback
164926deccbSFrançois Tigeot *
165926deccbSFrançois Tigeot * @dev: drm dev pointer
166926deccbSFrançois Tigeot *
167926deccbSFrançois Tigeot * This function disables all interrupt sources on the GPU (all asics).
168926deccbSFrançois Tigeot */
radeon_driver_irq_uninstall_kms(struct drm_device * dev)169926deccbSFrançois Tigeot void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
170926deccbSFrançois Tigeot {
171926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private;
172a85cb24fSFrançois Tigeot unsigned long irqflags;
173926deccbSFrançois Tigeot unsigned i;
174926deccbSFrançois Tigeot
175926deccbSFrançois Tigeot if (rdev == NULL) {
176926deccbSFrançois Tigeot return;
177926deccbSFrançois Tigeot }
178a85cb24fSFrançois Tigeot spin_lock_irqsave(&rdev->irq.lock, irqflags);
179926deccbSFrançois Tigeot /* Disable *all* interrupts */
180926deccbSFrançois Tigeot for (i = 0; i < RADEON_NUM_RINGS; i++)
181926deccbSFrançois Tigeot atomic_set(&rdev->irq.ring_int[i], 0);
18257e252bfSMichael Neumann rdev->irq.dpm_thermal = false;
183926deccbSFrançois Tigeot for (i = 0; i < RADEON_MAX_HPD_PINS; i++)
184926deccbSFrançois Tigeot rdev->irq.hpd[i] = false;
185926deccbSFrançois Tigeot for (i = 0; i < RADEON_MAX_CRTCS; i++) {
186926deccbSFrançois Tigeot rdev->irq.crtc_vblank_int[i] = false;
187926deccbSFrançois Tigeot atomic_set(&rdev->irq.pflip[i], 0);
188926deccbSFrançois Tigeot rdev->irq.afmt[i] = false;
189926deccbSFrançois Tigeot }
190926deccbSFrançois Tigeot radeon_irq_set(rdev);
191a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
192926deccbSFrançois Tigeot }
193926deccbSFrançois Tigeot
194a85cb24fSFrançois Tigeot #if 0
195926deccbSFrançois Tigeot /**
196926deccbSFrançois Tigeot * radeon_msi_ok - asic specific msi checks
197926deccbSFrançois Tigeot *
198926deccbSFrançois Tigeot * @rdev: radeon device pointer
199926deccbSFrançois Tigeot *
200926deccbSFrançois Tigeot * Handles asic specific MSI checks to determine if
201926deccbSFrançois Tigeot * MSIs should be enabled on a particular chip (all asics).
202926deccbSFrançois Tigeot * Returns true if MSIs should be enabled, false if MSIs
203926deccbSFrançois Tigeot * should not be enabled.
204926deccbSFrançois Tigeot */
205a85cb24fSFrançois Tigeot static bool radeon_msi_ok(struct radeon_device *rdev)
206926deccbSFrançois Tigeot {
207926deccbSFrançois Tigeot /* RV370/RV380 was first asic with MSI support */
208a85cb24fSFrançois Tigeot if (rdev->family < CHIP_RV380)
209926deccbSFrançois Tigeot return false;
210926deccbSFrançois Tigeot
211926deccbSFrançois Tigeot /* MSIs don't work on AGP */
212e3ac6954Szrj if (drm_pci_device_is_agp(rdev))
213926deccbSFrançois Tigeot return false;
214926deccbSFrançois Tigeot
215c59a5c48SFrançois Tigeot /*
216c59a5c48SFrançois Tigeot * Older chips have a HW limitation, they can only generate 40 bits
217c59a5c48SFrançois Tigeot * of address for "64-bit" MSIs which breaks on some platforms, notably
218c59a5c48SFrançois Tigeot * IBM POWER servers, so we limit them
219c59a5c48SFrançois Tigeot */
220a85cb24fSFrançois Tigeot if (rdev->family < CHIP_BONAIRE) {
221c59a5c48SFrançois Tigeot dev_info(rdev->dev, "radeon: MSI limited to 32-bit\n");
222c59a5c48SFrançois Tigeot rdev->pdev->no_64bit_msi = 1;
223c59a5c48SFrançois Tigeot }
224c59a5c48SFrançois Tigeot
225926deccbSFrançois Tigeot /* force MSI on */
226926deccbSFrançois Tigeot if (radeon_msi == 1)
227926deccbSFrançois Tigeot return true;
228926deccbSFrançois Tigeot else if (radeon_msi == 0)
229926deccbSFrançois Tigeot return false;
230926deccbSFrançois Tigeot
231926deccbSFrançois Tigeot /* Quirks */
232926deccbSFrançois Tigeot /* HP RS690 only seems to work with MSIs. */
233ccebb33fSFrançois Tigeot if ((rdev->pdev->device == 0x791f) &&
234ccebb33fSFrançois Tigeot (rdev->pdev->subsystem_vendor == 0x103c) &&
235ccebb33fSFrançois Tigeot (rdev->pdev->subsystem_device == 0x30c2))
236926deccbSFrançois Tigeot return true;
237926deccbSFrançois Tigeot
238926deccbSFrançois Tigeot /* Dell RS690 only seems to work with MSIs. */
239ccebb33fSFrançois Tigeot if ((rdev->pdev->device == 0x791f) &&
240ccebb33fSFrançois Tigeot (rdev->pdev->subsystem_vendor == 0x1028) &&
241ccebb33fSFrançois Tigeot (rdev->pdev->subsystem_device == 0x01fc))
242926deccbSFrançois Tigeot return true;
243926deccbSFrançois Tigeot
244926deccbSFrançois Tigeot /* Dell RS690 only seems to work with MSIs. */
245ccebb33fSFrançois Tigeot if ((rdev->pdev->device == 0x791f) &&
246ccebb33fSFrançois Tigeot (rdev->pdev->subsystem_vendor == 0x1028) &&
247ccebb33fSFrançois Tigeot (rdev->pdev->subsystem_device == 0x01fd))
248926deccbSFrançois Tigeot return true;
249926deccbSFrançois Tigeot
250926deccbSFrançois Tigeot /* Gateway RS690 only seems to work with MSIs. */
251ccebb33fSFrançois Tigeot if ((rdev->pdev->device == 0x791f) &&
252ccebb33fSFrançois Tigeot (rdev->pdev->subsystem_vendor == 0x107b) &&
253ccebb33fSFrançois Tigeot (rdev->pdev->subsystem_device == 0x0185))
254926deccbSFrançois Tigeot return true;
255926deccbSFrançois Tigeot
256926deccbSFrançois Tigeot /* try and enable MSIs by default on all RS690s */
257a85cb24fSFrançois Tigeot if (rdev->family == CHIP_RS690)
258926deccbSFrançois Tigeot return true;
259926deccbSFrançois Tigeot
260926deccbSFrançois Tigeot /* RV515 seems to have MSI issues where it loses
261926deccbSFrançois Tigeot * MSI rearms occasionally. This leads to lockups and freezes.
262926deccbSFrançois Tigeot * disable it by default.
263926deccbSFrançois Tigeot */
264a85cb24fSFrançois Tigeot if (rdev->family == CHIP_RV515)
265926deccbSFrançois Tigeot return false;
266a85cb24fSFrançois Tigeot if (rdev->flags & RADEON_IS_IGP) {
267926deccbSFrançois Tigeot /* APUs work fine with MSIs */
268a85cb24fSFrançois Tigeot if (rdev->family >= CHIP_PALM)
269926deccbSFrançois Tigeot return true;
270926deccbSFrançois Tigeot /* lots of IGPs have problems with MSIs */
271926deccbSFrançois Tigeot return false;
272926deccbSFrançois Tigeot }
273926deccbSFrançois Tigeot
274926deccbSFrançois Tigeot return true;
275926deccbSFrançois Tigeot }
276a85cb24fSFrançois Tigeot #endif
277926deccbSFrançois Tigeot
278926deccbSFrançois Tigeot /**
279926deccbSFrançois Tigeot * radeon_irq_kms_init - init driver interrupt info
280926deccbSFrançois Tigeot *
281926deccbSFrançois Tigeot * @rdev: radeon device pointer
282926deccbSFrançois Tigeot *
283926deccbSFrançois Tigeot * Sets up the work irq handlers, vblank init, MSIs, etc. (all asics).
284926deccbSFrançois Tigeot * Returns 0 for success, error for failure.
285926deccbSFrançois Tigeot */
radeon_irq_kms_init(struct radeon_device * rdev)286926deccbSFrançois Tigeot int radeon_irq_kms_init(struct radeon_device *rdev)
287926deccbSFrançois Tigeot {
288926deccbSFrançois Tigeot int r = 0;
289926deccbSFrançois Tigeot
290a85cb24fSFrançois Tigeot lockinit(&rdev->irq.lock, "drdil", 0, 0);
291*3f2dd94aSFrançois Tigeot
292*3f2dd94aSFrançois Tigeot /* Disable vblank irqs aggressively for power-saving */
293*3f2dd94aSFrançois Tigeot rdev->ddev->vblank_disable_immediate = true;
294*3f2dd94aSFrançois Tigeot
295926deccbSFrançois Tigeot r = drm_vblank_init(rdev->ddev, rdev->num_crtc);
296926deccbSFrançois Tigeot if (r) {
297926deccbSFrançois Tigeot return r;
298926deccbSFrançois Tigeot }
299d235ee5fSFrançois Tigeot
300926deccbSFrançois Tigeot /* enable msi */
301183e2373SFrançois Tigeot rdev->msi_enabled = (rdev->ddev->pdev->_irq_type == PCI_INTR_TYPE_MSI);
302926deccbSFrançois Tigeot
303d235ee5fSFrançois Tigeot #ifndef __DragonFly__
304d235ee5fSFrançois Tigeot if (radeon_msi_ok(rdev)) {
305d235ee5fSFrançois Tigeot int ret = pci_enable_msi(rdev->pdev);
306d235ee5fSFrançois Tigeot if (!ret) {
307d235ee5fSFrançois Tigeot rdev->msi_enabled = 1;
308d235ee5fSFrançois Tigeot dev_info(rdev->dev, "radeon: using MSI.\n");
309d235ee5fSFrançois Tigeot }
310d235ee5fSFrançois Tigeot }
311d235ee5fSFrançois Tigeot #endif
312d235ee5fSFrançois Tigeot
313c59a5c48SFrançois Tigeot INIT_DELAYED_WORK(&rdev->hotplug_work, radeon_hotplug_work_func);
314c59a5c48SFrançois Tigeot INIT_WORK(&rdev->dp_work, radeon_dp_work_func);
3152c5cc6b9SFrançois Tigeot INIT_WORK(&rdev->audio_work, r600_audio_update_hdmi);
3164cd92098Szrj
317926deccbSFrançois Tigeot rdev->irq.installed = true;
318183e2373SFrançois Tigeot r = drm_irq_install(rdev->ddev, rdev->ddev->pdev->irq);
319926deccbSFrançois Tigeot if (r) {
320926deccbSFrançois Tigeot rdev->irq.installed = false;
321c59a5c48SFrançois Tigeot flush_delayed_work(&rdev->hotplug_work);
322926deccbSFrançois Tigeot return r;
323926deccbSFrançois Tigeot }
32457e252bfSMichael Neumann
325926deccbSFrançois Tigeot DRM_INFO("radeon: irq initialized.\n");
326926deccbSFrançois Tigeot return 0;
327926deccbSFrançois Tigeot }
328926deccbSFrançois Tigeot
329926deccbSFrançois Tigeot /**
330f43cf1b1SMichael Neumann * radeon_irq_kms_fini - tear down driver interrupt info
331926deccbSFrançois Tigeot *
332926deccbSFrançois Tigeot * @rdev: radeon device pointer
333926deccbSFrançois Tigeot *
334926deccbSFrançois Tigeot * Tears down the work irq handlers, vblank handlers, MSIs, etc. (all asics).
335926deccbSFrançois Tigeot */
radeon_irq_kms_fini(struct radeon_device * rdev)336926deccbSFrançois Tigeot void radeon_irq_kms_fini(struct radeon_device *rdev)
337926deccbSFrançois Tigeot {
338926deccbSFrançois Tigeot if (rdev->irq.installed) {
339926deccbSFrançois Tigeot drm_irq_uninstall(rdev->ddev);
340926deccbSFrançois Tigeot rdev->irq.installed = false;
341c59a5c48SFrançois Tigeot #ifndef __DragonFly__
342c59a5c48SFrançois Tigeot if (rdev->msi_enabled)
343c59a5c48SFrançois Tigeot pci_disable_msi(rdev->pdev);
344c59a5c48SFrançois Tigeot #endif
345c59a5c48SFrançois Tigeot flush_delayed_work(&rdev->hotplug_work);
346926deccbSFrançois Tigeot }
3474cd92098Szrj }
348926deccbSFrançois Tigeot
349926deccbSFrançois Tigeot /**
350926deccbSFrançois Tigeot * radeon_irq_kms_sw_irq_get - enable software interrupt
351926deccbSFrançois Tigeot *
352926deccbSFrançois Tigeot * @rdev: radeon device pointer
353926deccbSFrançois Tigeot * @ring: ring whose interrupt you want to enable
354926deccbSFrançois Tigeot *
355926deccbSFrançois Tigeot * Enables the software interrupt for a specific ring (all asics).
356926deccbSFrançois Tigeot * The software interrupt is generally used to signal a fence on
357926deccbSFrançois Tigeot * a particular ring.
358926deccbSFrançois Tigeot */
radeon_irq_kms_sw_irq_get(struct radeon_device * rdev,int ring)359926deccbSFrançois Tigeot void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring)
360926deccbSFrançois Tigeot {
361a85cb24fSFrançois Tigeot unsigned long irqflags;
362a85cb24fSFrançois Tigeot
363926deccbSFrançois Tigeot if (!rdev->ddev->irq_enabled)
364926deccbSFrançois Tigeot return;
365926deccbSFrançois Tigeot
366926deccbSFrançois Tigeot if (atomic_inc_return(&rdev->irq.ring_int[ring]) == 1) {
367a85cb24fSFrançois Tigeot spin_lock_irqsave(&rdev->irq.lock, irqflags);
368926deccbSFrançois Tigeot radeon_irq_set(rdev);
369a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
370926deccbSFrançois Tigeot }
371926deccbSFrançois Tigeot }
372926deccbSFrançois Tigeot
373926deccbSFrançois Tigeot /**
374bd519cccSFrançois Tigeot * radeon_irq_kms_sw_irq_get_delayed - enable software interrupt
375bd519cccSFrançois Tigeot *
376bd519cccSFrançois Tigeot * @rdev: radeon device pointer
377bd519cccSFrançois Tigeot * @ring: ring whose interrupt you want to enable
378bd519cccSFrançois Tigeot *
379bd519cccSFrançois Tigeot * Enables the software interrupt for a specific ring (all asics).
380bd519cccSFrançois Tigeot * The software interrupt is generally used to signal a fence on
381bd519cccSFrançois Tigeot * a particular ring.
382bd519cccSFrançois Tigeot */
radeon_irq_kms_sw_irq_get_delayed(struct radeon_device * rdev,int ring)383bd519cccSFrançois Tigeot bool radeon_irq_kms_sw_irq_get_delayed(struct radeon_device *rdev, int ring)
384bd519cccSFrançois Tigeot {
385bd519cccSFrançois Tigeot return atomic_inc_return(&rdev->irq.ring_int[ring]) == 1;
386bd519cccSFrançois Tigeot }
387bd519cccSFrançois Tigeot
388bd519cccSFrançois Tigeot /**
389926deccbSFrançois Tigeot * radeon_irq_kms_sw_irq_put - disable software interrupt
390926deccbSFrançois Tigeot *
391926deccbSFrançois Tigeot * @rdev: radeon device pointer
392926deccbSFrançois Tigeot * @ring: ring whose interrupt you want to disable
393926deccbSFrançois Tigeot *
394926deccbSFrançois Tigeot * Disables the software interrupt for a specific ring (all asics).
395926deccbSFrançois Tigeot * The software interrupt is generally used to signal a fence on
396926deccbSFrançois Tigeot * a particular ring.
397926deccbSFrançois Tigeot */
radeon_irq_kms_sw_irq_put(struct radeon_device * rdev,int ring)398926deccbSFrançois Tigeot void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring)
399926deccbSFrançois Tigeot {
400a85cb24fSFrançois Tigeot unsigned long irqflags;
401a85cb24fSFrançois Tigeot
402926deccbSFrançois Tigeot if (!rdev->ddev->irq_enabled)
403926deccbSFrançois Tigeot return;
404926deccbSFrançois Tigeot
405926deccbSFrançois Tigeot if (atomic_dec_and_test(&rdev->irq.ring_int[ring])) {
406a85cb24fSFrançois Tigeot spin_lock_irqsave(&rdev->irq.lock, irqflags);
407926deccbSFrançois Tigeot radeon_irq_set(rdev);
408a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
409926deccbSFrançois Tigeot }
410926deccbSFrançois Tigeot }
411926deccbSFrançois Tigeot
412926deccbSFrançois Tigeot /**
413926deccbSFrançois Tigeot * radeon_irq_kms_pflip_irq_get - enable pageflip interrupt
414926deccbSFrançois Tigeot *
415926deccbSFrançois Tigeot * @rdev: radeon device pointer
416926deccbSFrançois Tigeot * @crtc: crtc whose interrupt you want to enable
417926deccbSFrançois Tigeot *
418926deccbSFrançois Tigeot * Enables the pageflip interrupt for a specific crtc (all asics).
419926deccbSFrançois Tigeot * For pageflips we use the vblank interrupt source.
420926deccbSFrançois Tigeot */
radeon_irq_kms_pflip_irq_get(struct radeon_device * rdev,int crtc)421926deccbSFrançois Tigeot void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc)
422926deccbSFrançois Tigeot {
423a85cb24fSFrançois Tigeot unsigned long irqflags;
424a85cb24fSFrançois Tigeot
425926deccbSFrançois Tigeot if (crtc < 0 || crtc >= rdev->num_crtc)
426926deccbSFrançois Tigeot return;
427926deccbSFrançois Tigeot
428926deccbSFrançois Tigeot if (!rdev->ddev->irq_enabled)
429926deccbSFrançois Tigeot return;
430926deccbSFrançois Tigeot
431926deccbSFrançois Tigeot if (atomic_inc_return(&rdev->irq.pflip[crtc]) == 1) {
432a85cb24fSFrançois Tigeot spin_lock_irqsave(&rdev->irq.lock, irqflags);
433926deccbSFrançois Tigeot radeon_irq_set(rdev);
434a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
435926deccbSFrançois Tigeot }
436926deccbSFrançois Tigeot }
437926deccbSFrançois Tigeot
438926deccbSFrançois Tigeot /**
439926deccbSFrançois Tigeot * radeon_irq_kms_pflip_irq_put - disable pageflip interrupt
440926deccbSFrançois Tigeot *
441926deccbSFrançois Tigeot * @rdev: radeon device pointer
442926deccbSFrançois Tigeot * @crtc: crtc whose interrupt you want to disable
443926deccbSFrançois Tigeot *
444926deccbSFrançois Tigeot * Disables the pageflip interrupt for a specific crtc (all asics).
445926deccbSFrançois Tigeot * For pageflips we use the vblank interrupt source.
446926deccbSFrançois Tigeot */
radeon_irq_kms_pflip_irq_put(struct radeon_device * rdev,int crtc)447926deccbSFrançois Tigeot void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc)
448926deccbSFrançois Tigeot {
449a85cb24fSFrançois Tigeot unsigned long irqflags;
450a85cb24fSFrançois Tigeot
451926deccbSFrançois Tigeot if (crtc < 0 || crtc >= rdev->num_crtc)
452926deccbSFrançois Tigeot return;
453926deccbSFrançois Tigeot
454926deccbSFrançois Tigeot if (!rdev->ddev->irq_enabled)
455926deccbSFrançois Tigeot return;
456926deccbSFrançois Tigeot
457926deccbSFrançois Tigeot if (atomic_dec_and_test(&rdev->irq.pflip[crtc])) {
458a85cb24fSFrançois Tigeot spin_lock_irqsave(&rdev->irq.lock, irqflags);
459926deccbSFrançois Tigeot radeon_irq_set(rdev);
460a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
461926deccbSFrançois Tigeot }
462926deccbSFrançois Tigeot }
463926deccbSFrançois Tigeot
464926deccbSFrançois Tigeot /**
465926deccbSFrançois Tigeot * radeon_irq_kms_enable_afmt - enable audio format change interrupt
466926deccbSFrançois Tigeot *
467926deccbSFrançois Tigeot * @rdev: radeon device pointer
468926deccbSFrançois Tigeot * @block: afmt block whose interrupt you want to enable
469926deccbSFrançois Tigeot *
470926deccbSFrançois Tigeot * Enables the afmt change interrupt for a specific afmt block (all asics).
471926deccbSFrançois Tigeot */
radeon_irq_kms_enable_afmt(struct radeon_device * rdev,int block)472926deccbSFrançois Tigeot void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block)
473926deccbSFrançois Tigeot {
474a85cb24fSFrançois Tigeot unsigned long irqflags;
475a85cb24fSFrançois Tigeot
476b403bed8SMichael Neumann if (!rdev->ddev->irq_enabled)
477b403bed8SMichael Neumann return;
478b403bed8SMichael Neumann
479a85cb24fSFrançois Tigeot spin_lock_irqsave(&rdev->irq.lock, irqflags);
480926deccbSFrançois Tigeot rdev->irq.afmt[block] = true;
481926deccbSFrançois Tigeot radeon_irq_set(rdev);
482a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
483a85cb24fSFrançois Tigeot
484926deccbSFrançois Tigeot }
485926deccbSFrançois Tigeot
486926deccbSFrançois Tigeot /**
487926deccbSFrançois Tigeot * radeon_irq_kms_disable_afmt - disable audio format change interrupt
488926deccbSFrançois Tigeot *
489926deccbSFrançois Tigeot * @rdev: radeon device pointer
490926deccbSFrançois Tigeot * @block: afmt block whose interrupt you want to disable
491926deccbSFrançois Tigeot *
492926deccbSFrançois Tigeot * Disables the afmt change interrupt for a specific afmt block (all asics).
493926deccbSFrançois Tigeot */
radeon_irq_kms_disable_afmt(struct radeon_device * rdev,int block)494926deccbSFrançois Tigeot void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block)
495926deccbSFrançois Tigeot {
496a85cb24fSFrançois Tigeot unsigned long irqflags;
497a85cb24fSFrançois Tigeot
498b403bed8SMichael Neumann if (!rdev->ddev->irq_enabled)
499b403bed8SMichael Neumann return;
500b403bed8SMichael Neumann
501a85cb24fSFrançois Tigeot spin_lock_irqsave(&rdev->irq.lock, irqflags);
502926deccbSFrançois Tigeot rdev->irq.afmt[block] = false;
503926deccbSFrançois Tigeot radeon_irq_set(rdev);
504a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
505926deccbSFrançois Tigeot }
506926deccbSFrançois Tigeot
507926deccbSFrançois Tigeot /**
508926deccbSFrançois Tigeot * radeon_irq_kms_enable_hpd - enable hotplug detect interrupt
509926deccbSFrançois Tigeot *
510926deccbSFrançois Tigeot * @rdev: radeon device pointer
511926deccbSFrançois Tigeot * @hpd_mask: mask of hpd pins you want to enable.
512926deccbSFrançois Tigeot *
513926deccbSFrançois Tigeot * Enables the hotplug detect interrupt for a specific hpd pin (all asics).
514926deccbSFrançois Tigeot */
radeon_irq_kms_enable_hpd(struct radeon_device * rdev,unsigned hpd_mask)515926deccbSFrançois Tigeot void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
516926deccbSFrançois Tigeot {
517a85cb24fSFrançois Tigeot unsigned long irqflags;
518926deccbSFrançois Tigeot int i;
519926deccbSFrançois Tigeot
520b403bed8SMichael Neumann if (!rdev->ddev->irq_enabled)
521b403bed8SMichael Neumann return;
522b403bed8SMichael Neumann
523a85cb24fSFrançois Tigeot spin_lock_irqsave(&rdev->irq.lock, irqflags);
524926deccbSFrançois Tigeot for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
525926deccbSFrançois Tigeot rdev->irq.hpd[i] |= !!(hpd_mask & (1 << i));
526926deccbSFrançois Tigeot radeon_irq_set(rdev);
527a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
528926deccbSFrançois Tigeot }
529926deccbSFrançois Tigeot
530926deccbSFrançois Tigeot /**
531926deccbSFrançois Tigeot * radeon_irq_kms_disable_hpd - disable hotplug detect interrupt
532926deccbSFrançois Tigeot *
533926deccbSFrançois Tigeot * @rdev: radeon device pointer
534926deccbSFrançois Tigeot * @hpd_mask: mask of hpd pins you want to disable.
535926deccbSFrançois Tigeot *
536926deccbSFrançois Tigeot * Disables the hotplug detect interrupt for a specific hpd pin (all asics).
537926deccbSFrançois Tigeot */
radeon_irq_kms_disable_hpd(struct radeon_device * rdev,unsigned hpd_mask)538926deccbSFrançois Tigeot void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask)
539926deccbSFrançois Tigeot {
540a85cb24fSFrançois Tigeot unsigned long irqflags;
541926deccbSFrançois Tigeot int i;
542926deccbSFrançois Tigeot
543b403bed8SMichael Neumann if (!rdev->ddev->irq_enabled)
544b403bed8SMichael Neumann return;
545b403bed8SMichael Neumann
546a85cb24fSFrançois Tigeot spin_lock_irqsave(&rdev->irq.lock, irqflags);
547926deccbSFrançois Tigeot for (i = 0; i < RADEON_MAX_HPD_PINS; ++i)
548926deccbSFrançois Tigeot rdev->irq.hpd[i] &= !(hpd_mask & (1 << i));
549926deccbSFrançois Tigeot radeon_irq_set(rdev);
550a85cb24fSFrançois Tigeot spin_unlock_irqrestore(&rdev->irq.lock, irqflags);
551926deccbSFrançois Tigeot }
552926deccbSFrançois Tigeot
553*3f2dd94aSFrançois Tigeot /**
554*3f2dd94aSFrançois Tigeot * radeon_irq_kms_update_int_n - helper for updating interrupt enable registers
555*3f2dd94aSFrançois Tigeot *
556*3f2dd94aSFrançois Tigeot * @rdev: radeon device pointer
557*3f2dd94aSFrançois Tigeot * @reg: the register to write to enable/disable interrupts
558*3f2dd94aSFrançois Tigeot * @mask: the mask that enables the interrupts
559*3f2dd94aSFrançois Tigeot * @enable: whether to enable or disable the interrupt register
560*3f2dd94aSFrançois Tigeot * @name: the name of the interrupt register to print to the kernel log
561*3f2dd94aSFrançois Tigeot * @num: the number of the interrupt register to print to the kernel log
562*3f2dd94aSFrançois Tigeot *
563*3f2dd94aSFrançois Tigeot * Helper for updating the enable state of interrupt registers. Checks whether
564*3f2dd94aSFrançois Tigeot * or not the interrupt matches the enable state we want. If it doesn't, then
565*3f2dd94aSFrançois Tigeot * we update it and print a debugging message to the kernel log indicating the
566*3f2dd94aSFrançois Tigeot * new state of the interrupt register.
567*3f2dd94aSFrançois Tigeot *
568*3f2dd94aSFrançois Tigeot * Used for updating sequences of interrupts registers like HPD1, HPD2, etc.
569*3f2dd94aSFrançois Tigeot */
radeon_irq_kms_set_irq_n_enabled(struct radeon_device * rdev,u32 reg,u32 mask,bool enable,const char * name,unsigned n)570*3f2dd94aSFrançois Tigeot void radeon_irq_kms_set_irq_n_enabled(struct radeon_device *rdev,
571*3f2dd94aSFrançois Tigeot u32 reg, u32 mask,
572*3f2dd94aSFrançois Tigeot bool enable, const char *name, unsigned n)
573*3f2dd94aSFrançois Tigeot {
574*3f2dd94aSFrançois Tigeot u32 tmp = RREG32(reg);
575*3f2dd94aSFrançois Tigeot
576*3f2dd94aSFrançois Tigeot /* Interrupt state didn't change */
577*3f2dd94aSFrançois Tigeot if (!!(tmp & mask) == enable)
578*3f2dd94aSFrançois Tigeot return;
579*3f2dd94aSFrançois Tigeot
580*3f2dd94aSFrançois Tigeot if (enable) {
581*3f2dd94aSFrançois Tigeot DRM_DEBUG("%s%d interrupts enabled\n", name, n);
582*3f2dd94aSFrançois Tigeot WREG32(reg, tmp |= mask);
583*3f2dd94aSFrançois Tigeot } else {
584*3f2dd94aSFrançois Tigeot DRM_DEBUG("%s%d interrupts disabled\n", name, n);
585*3f2dd94aSFrançois Tigeot WREG32(reg, tmp & ~mask);
586*3f2dd94aSFrançois Tigeot }
587*3f2dd94aSFrançois Tigeot }
588