UAPI: (Scripted) Convert #include "..." to #include <path/...> in drivers/gpu/
[linux-2.6-block.git] / drivers / gpu / drm / nouveau / nvc0_fb.c
CommitLineData
4b223eef 1/*
310ff414 2 * Copyright 2011 Red Hat Inc.
4b223eef
BS
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
760285e7 25#include <drm/drmP.h>
4b223eef 26#include "nouveau_drv.h"
760285e7 27#include <drm/nouveau_drm.h>
310ff414
BS
28
29struct nvc0_fb_priv {
30 struct page *r100c10_page;
31 dma_addr_t r100c10;
32};
33
a1484512
BS
34static inline void
35nvc0_mfb_subp_isr(struct drm_device *dev, int unit, int subp)
36{
37 u32 subp_base = 0x141000 + (unit * 0x2000) + (subp * 0x400);
38 u32 stat = nv_rd32(dev, subp_base + 0x020);
39
40 if (stat) {
41 NV_INFO(dev, "PMFB%d_SUBP%d: 0x%08x\n", unit, subp, stat);
42 nv_wr32(dev, subp_base + 0x020, stat);
43 }
44}
45
46static void
47nvc0_mfb_isr(struct drm_device *dev)
48{
49 u32 units = nv_rd32(dev, 0x00017c);
50 while (units) {
51 u32 subp, unit = ffs(units) - 1;
52 for (subp = 0; subp < 2; subp++)
53 nvc0_mfb_subp_isr(dev, unit, subp);
54 units &= ~(1 << unit);
55 }
ffc6a4e4
CB
56
57 /* we do something horribly wrong and upset PMFB a lot, so mask off
58 * interrupts from it after the first one until it's fixed
59 */
60 nv_mask(dev, 0x000640, 0x02000000, 0x00000000);
a1484512
BS
61}
62
310ff414
BS
63static void
64nvc0_fb_destroy(struct drm_device *dev)
65{
66 struct drm_nouveau_private *dev_priv = dev->dev_private;
67 struct nouveau_fb_engine *pfb = &dev_priv->engine.fb;
68 struct nvc0_fb_priv *priv = pfb->priv;
69
a1484512
BS
70 nouveau_irq_unregister(dev, 25);
71
310ff414
BS
72 if (priv->r100c10_page) {
73 pci_unmap_page(dev->pdev, priv->r100c10, PAGE_SIZE,
74 PCI_DMA_BIDIRECTIONAL);
75 __free_page(priv->r100c10_page);
76 }
77
78 kfree(priv);
79 pfb->priv = NULL;
80}
81
82static int
83nvc0_fb_create(struct drm_device *dev)
84{
85 struct drm_nouveau_private *dev_priv = dev->dev_private;
86 struct nouveau_fb_engine *pfb = &dev_priv->engine.fb;
87 struct nvc0_fb_priv *priv;
88
89 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
90 if (!priv)
91 return -ENOMEM;
92 pfb->priv = priv;
93
94 priv->r100c10_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
95 if (!priv->r100c10_page) {
96 nvc0_fb_destroy(dev);
97 return -ENOMEM;
98 }
99
100 priv->r100c10 = pci_map_page(dev->pdev, priv->r100c10_page, 0,
101 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
102 if (pci_dma_mapping_error(dev->pdev, priv->r100c10)) {
103 nvc0_fb_destroy(dev);
104 return -EFAULT;
105 }
106
a1484512 107 nouveau_irq_register(dev, 25, nvc0_mfb_isr);
310ff414
BS
108 return 0;
109}
4b223eef
BS
110
111int
112nvc0_fb_init(struct drm_device *dev)
113{
310ff414
BS
114 struct drm_nouveau_private *dev_priv = dev->dev_private;
115 struct nvc0_fb_priv *priv;
116 int ret;
117
118 if (!dev_priv->engine.fb.priv) {
119 ret = nvc0_fb_create(dev);
120 if (ret)
121 return ret;
122 }
123 priv = dev_priv->engine.fb.priv;
124
125 nv_wr32(dev, 0x100c10, priv->r100c10 >> 8);
79eee7aa 126 nv_mask(dev, 0x17e820, 0x00100000, 0x00000000); /* NV_PLTCG_INTR_EN */
4b223eef
BS
127 return 0;
128}
129
130void
131nvc0_fb_takedown(struct drm_device *dev)
132{
310ff414 133 nvc0_fb_destroy(dev);
4b223eef 134}