blob: 6ce1529aaa34a9bc26ef43e22cb1ea3d79d71b26 [file] [log] [blame]
Ben Skeggs26f6d882011-07-04 16:25:18 +10001/*
2 * Copyright 2011 Red Hat Inc.
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
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28#include "nouveau_connector.h"
29#include "nouveau_encoder.h"
30#include "nouveau_crtc.h"
31
32struct nvd0_display {
33 struct nouveau_gpuobj *mem;
34};
35
36static struct nvd0_display *
37nvd0_display(struct drm_device *dev)
38{
39 struct drm_nouveau_private *dev_priv = dev->dev_private;
40 return dev_priv->engine.display.priv;
41}
42
43/******************************************************************************
44 * DAC
45 *****************************************************************************/
46
47/******************************************************************************
48 * SOR
49 *****************************************************************************/
50
51/******************************************************************************
52 * IRQ
53 *****************************************************************************/
54
55/******************************************************************************
56 * Init
57 *****************************************************************************/
58static void
59nvd0_display_fini(struct drm_device *dev)
60{
61 int i;
62
63 /* fini cursors */
64 for (i = 14; i >= 13; i--) {
65 if (!(nv_rd32(dev, 0x610490 + (i * 0x10)) & 0x00000001))
66 continue;
67
68 nv_mask(dev, 0x610490 + (i * 0x10), 0x00000001, 0x00000000);
69 nv_wait(dev, 0x610490 + (i * 0x10), 0x00010000, 0x00000000);
70 nv_mask(dev, 0x610090, 1 << i, 0x00000000);
71 nv_mask(dev, 0x6100a0, 1 << i, 0x00000000);
72 }
73
74 /* fini master */
75 if (nv_rd32(dev, 0x610490) & 0x00000010) {
76 nv_mask(dev, 0x610490, 0x00000010, 0x00000000);
77 nv_mask(dev, 0x610490, 0x00000003, 0x00000000);
78 nv_wait(dev, 0x610490, 0x80000000, 0x00000000);
79 nv_mask(dev, 0x610090, 0x00000001, 0x00000000);
80 nv_mask(dev, 0x6100a0, 0x00000001, 0x00000000);
81 }
82}
83
84int
85nvd0_display_init(struct drm_device *dev)
86{
87 struct nvd0_display *disp = nvd0_display(dev);
88 int i;
89
90 if (nv_rd32(dev, 0x6100ac) & 0x00000100) {
91 nv_wr32(dev, 0x6100ac, 0x00000100);
92 nv_mask(dev, 0x6194e8, 0x00000001, 0x00000000);
93 if (!nv_wait(dev, 0x6194e8, 0x00000002, 0x00000000)) {
94 NV_ERROR(dev, "PDISP: 0x6194e8 0x%08x\n",
95 nv_rd32(dev, 0x6194e8));
96 return -EBUSY;
97 }
98 }
99
100 nv_wr32(dev, 0x610010, (disp->mem->vinst >> 8) | 9);
101
102 /* init master */
103 nv_wr32(dev, 0x610494, ((disp->mem->vinst + 0x1000) >> 8) | 1);
104 nv_wr32(dev, 0x610498, 0x00010000);
105 nv_wr32(dev, 0x61049c, 0x00000000);
106 nv_mask(dev, 0x610490, 0x00000010, 0x00000010);
107 nv_wr32(dev, 0x640000, 0x00000000);
108 nv_wr32(dev, 0x610490, 0x01000013);
109 if (!nv_wait(dev, 0x610490, 0x80000000, 0x00000000)) {
110 NV_ERROR(dev, "PDISP: master 0x%08x\n",
111 nv_rd32(dev, 0x610490));
112 return -EBUSY;
113 }
114 nv_mask(dev, 0x610090, 0x00000001, 0x00000001);
115 nv_mask(dev, 0x6100a0, 0x00000001, 0x00000001);
116
117 /* init cursors */
118 for (i = 13; i <= 14; i++) {
119 nv_wr32(dev, 0x610490 + (i * 0x10), 0x00000001);
120 if (!nv_wait(dev, 0x610490 + (i * 0x10), 0x00010000, 0x00010000)) {
121 NV_ERROR(dev, "PDISP: curs%d 0x%08x\n", i,
122 nv_rd32(dev, 0x610490 + (i * 0x10)));
123 return -EBUSY;
124 }
125
126 nv_mask(dev, 0x610090, 1 << i, 1 << i);
127 nv_mask(dev, 0x6100a0, 1 << i, 1 << i);
128 }
129
130 return 0;
131}
132
133void
134nvd0_display_destroy(struct drm_device *dev)
135{
136 struct drm_nouveau_private *dev_priv = dev->dev_private;
137 struct nvd0_display *disp = nvd0_display(dev);
138
139 nvd0_display_fini(dev);
140
141 dev_priv->engine.display.priv = NULL;
142 nouveau_gpuobj_ref(NULL, &disp->mem);
143 kfree(disp);
144}
145
146int
147nvd0_display_create(struct drm_device *dev)
148{
149 struct drm_nouveau_private *dev_priv = dev->dev_private;
150 struct nvd0_display *disp;
151 int ret;
152
153 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
154 if (!disp)
155 return -ENOMEM;
156 dev_priv->engine.display.priv = disp;
157
158 ret = nouveau_gpuobj_new(dev, NULL, 8 * 1024, 0x1000, 0, &disp->mem);
159 if (ret)
160 goto out;
161
162 ret = nvd0_display_init(dev);
163 if (ret)
164 goto out;
165
166out:
167 if (ret)
168 nvd0_display_destroy(dev);
169 return ret;
170}