Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Ben Skeggs. |
| 3 | * |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | * a copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial |
| 16 | * portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 21 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 23 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 24 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * Authors: |
| 30 | * Ben Skeggs <darktama@iinet.net.au> |
| 31 | */ |
| 32 | |
| 33 | #include "drmP.h" |
| 34 | #include "drm.h" |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 35 | #include <nouveau_drm.h> |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 36 | #include "nouveau_drv.h" |
| 37 | #include "nouveau_reg.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 38 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 39 | void |
| 40 | nouveau_irq_preinstall(struct drm_device *dev) |
| 41 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 42 | /* Master disable */ |
| 43 | nv_wr32(dev, NV03_PMC_INTR_EN_0, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | int |
| 47 | nouveau_irq_postinstall(struct drm_device *dev) |
| 48 | { |
Ben Skeggs | 35fa2f2 | 2010-10-21 14:07:03 +1000 | [diff] [blame] | 49 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 50 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 51 | /* Master enable */ |
| 52 | nv_wr32(dev, NV03_PMC_INTR_EN_0, NV_PMC_INTR_EN_0_MASTER_ENABLE); |
Ben Skeggs | 35fa2f2 | 2010-10-21 14:07:03 +1000 | [diff] [blame] | 53 | if (dev_priv->msi_enabled) |
| 54 | nv_wr08(dev, 0x00088068, 0xff); |
| 55 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | void |
| 60 | nouveau_irq_uninstall(struct drm_device *dev) |
| 61 | { |
| 62 | /* Master disable */ |
| 63 | nv_wr32(dev, NV03_PMC_INTR_EN_0, 0); |
| 64 | } |
| 65 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 66 | irqreturn_t |
| 67 | nouveau_irq_handler(DRM_IRQ_ARGS) |
| 68 | { |
| 69 | struct drm_device *dev = (struct drm_device *)arg; |
| 70 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Maarten Maathuis | ff9e527 | 2010-02-01 20:58:27 +0100 | [diff] [blame] | 71 | unsigned long flags; |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 72 | u32 stat; |
Ben Skeggs | 8f8a544 | 2010-11-03 09:57:28 +1000 | [diff] [blame] | 73 | int i; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 74 | |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 75 | stat = nv_rd32(dev, NV03_PMC_INTR_0); |
Ben Skeggs | 9717f3d | 2011-07-12 15:42:45 +1000 | [diff] [blame] | 76 | if (stat == 0 || stat == ~0) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 77 | return IRQ_NONE; |
| 78 | |
Maarten Maathuis | ff9e527 | 2010-02-01 20:58:27 +0100 | [diff] [blame] | 79 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 80 | for (i = 0; i < 32 && stat; i++) { |
| 81 | if (!(stat & (1 << i)) || !dev_priv->irq_handler[i]) |
Ben Skeggs | 8f8a544 | 2010-11-03 09:57:28 +1000 | [diff] [blame] | 82 | continue; |
| 83 | |
| 84 | dev_priv->irq_handler[i](dev); |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 85 | stat &= ~(1 << i); |
Ben Skeggs | 8f8a544 | 2010-11-03 09:57:28 +1000 | [diff] [blame] | 86 | } |
| 87 | |
Ben Skeggs | 7d9115d | 2012-07-11 15:58:56 +1000 | [diff] [blame] | 88 | nv_intr(dev); |
| 89 | |
Ben Skeggs | 35fa2f2 | 2010-10-21 14:07:03 +1000 | [diff] [blame] | 90 | if (dev_priv->msi_enabled) |
| 91 | nv_wr08(dev, 0x00088068, 0xff); |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 92 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
Ben Skeggs | 35fa2f2 | 2010-10-21 14:07:03 +1000 | [diff] [blame] | 93 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 94 | return IRQ_HANDLED; |
| 95 | } |
Ben Skeggs | 35fa2f2 | 2010-10-21 14:07:03 +1000 | [diff] [blame] | 96 | |
| 97 | int |
| 98 | nouveau_irq_init(struct drm_device *dev) |
| 99 | { |
| 100 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 101 | int ret; |
| 102 | |
| 103 | if (nouveau_msi != 0 && dev_priv->card_type >= NV_50) { |
| 104 | ret = pci_enable_msi(dev->pdev); |
| 105 | if (ret == 0) { |
| 106 | NV_INFO(dev, "enabled MSI\n"); |
| 107 | dev_priv->msi_enabled = true; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | return drm_irq_install(dev); |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | nouveau_irq_fini(struct drm_device *dev) |
| 116 | { |
| 117 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 118 | |
| 119 | drm_irq_uninstall(dev); |
| 120 | if (dev_priv->msi_enabled) |
| 121 | pci_disable_msi(dev->pdev); |
| 122 | } |
Ben Skeggs | 8f8a544 | 2010-11-03 09:57:28 +1000 | [diff] [blame] | 123 | |
| 124 | void |
| 125 | nouveau_irq_register(struct drm_device *dev, int status_bit, |
| 126 | void (*handler)(struct drm_device *)) |
| 127 | { |
| 128 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 129 | unsigned long flags; |
| 130 | |
| 131 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
| 132 | dev_priv->irq_handler[status_bit] = handler; |
| 133 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
| 134 | } |
| 135 | |
| 136 | void |
| 137 | nouveau_irq_unregister(struct drm_device *dev, int status_bit) |
| 138 | { |
| 139 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 140 | unsigned long flags; |
| 141 | |
| 142 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
| 143 | dev_priv->irq_handler[status_bit] = NULL; |
| 144 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
| 145 | } |