2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
24 * Authors: Dave Airlie
29 #include "radeon_drm.h"
30 #include "radeon_reg.h"
31 #include "radeon_microcode.h"
35 static inline uint32_t r100_irq_ack(struct radeon_device *rdev)
37 uint32_t irqs = RREG32(RADEON_GEN_INT_STATUS);
38 uint32_t irq_mask = RADEON_SW_INT_TEST;
41 WREG32(RADEON_GEN_INT_STATUS, irqs);
43 return irqs & irq_mask;
46 int r100_irq_set(struct radeon_device *rdev)
50 if (rdev->irq.sw_int) {
51 tmp |= RADEON_SW_INT_ENABLE;
53 /* Todo go through CRTC and enable vblank int or not */
54 WREG32(RADEON_GEN_INT_CNTL, tmp);
58 int r100_irq_process(struct radeon_device *rdev)
62 status = r100_irq_ack(rdev);
68 if (status & RADEON_SW_INT_TEST) {
69 radeon_fence_process(rdev);
71 status = r100_irq_ack(rdev);
76 int rs600_irq_set(struct radeon_device *rdev)
80 if (rdev->irq.sw_int) {
81 tmp |= RADEON_SW_INT_ENABLE;
83 WREG32(RADEON_GEN_INT_CNTL, tmp);
84 /* Todo go through CRTC and enable vblank int or not */
85 WREG32(R500_DxMODE_INT_MASK, 0);
89 irqreturn_t radeon_driver_irq_handler_kms(DRM_IRQ_ARGS)
91 struct drm_device *dev = (struct drm_device *) arg;
92 struct radeon_device *rdev = dev->dev_private;
94 return radeon_irq_process(rdev);
97 void radeon_driver_irq_preinstall_kms(struct drm_device *dev)
99 struct radeon_device *rdev = dev->dev_private;
102 /* Disable *all* interrupts */
103 rdev->irq.sw_int = false;
104 for (i = 0; i < 2; i++) {
105 rdev->irq.crtc_vblank_int[i] = false;
107 radeon_irq_set(rdev);
109 radeon_irq_process(rdev);
112 int radeon_driver_irq_postinstall_kms(struct drm_device *dev)
114 struct radeon_device *rdev = dev->dev_private;
116 dev->max_vblank_count = 0x001fffff;
117 rdev->irq.sw_int = true;
118 radeon_irq_set(rdev);
122 void radeon_driver_irq_uninstall_kms(struct drm_device *dev)
124 struct radeon_device *rdev = dev->dev_private;
130 /* Disable *all* interrupts */
131 rdev->irq.sw_int = false;
132 for (i = 0; i < 2; i++) {
133 rdev->irq.crtc_vblank_int[i] = false;
135 radeon_irq_set(rdev);
138 int radeon_irq_kms_init(struct radeon_device *rdev)
142 r = drm_vblank_init(rdev->ddev, 2);
146 drm_irq_install(rdev->ddev);
147 rdev->irq.installed = true;
148 DRM_INFO("radeon: irq initialized.\n");
152 void radeon_irq_kms_fini(struct radeon_device *rdev)
154 if (rdev->irq.installed) {
155 rdev->irq.installed = false;
156 drm_irq_uninstall(rdev->ddev);