Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 842 lines (739 sloc) 22.069 kb
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
1 /*
2 * Copyright 2005 Stephane Marchesin
3 * Copyright 2008 Stuart Bennett
4 * All Rights Reserved.
5 *
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:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
1cf0fec @mlankhorst freebsd WIP
mlankhorst authored
26 #include "nouveau_drv.h"
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
27 #include "drm.h"
28 #include "drm_sarea.h"
29 #include "drm_crtc_helper.h"
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
30 #ifdef __linux__
9b94ad5 @mlankhorst get compile working on freebsd
mlankhorst authored
31 #include <linux/swab.h>
32 #include <linux/slab.h>
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
33 #include <linux/vgaarb.h>
34 #include <linux/vga_switcheroo.h>
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
35 #endif
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
36
1432c97 @koriakin nouveau_drm.h -> pscnv_drm.h and some associated renames.
koriakin authored
37 #include "pscnv_drm.h"
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
38 #include "nouveau_reg.h"
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
39 #include "nouveau_fbcon.h"
420c14a @koriakin Merge upstream commit 5a4ff9f48f638d0cddeb6788743f32d8cdc89423
koriakin authored
40 #include "nouveau_pm.h"
3434652 @koriakin Add KMS support.
koriakin authored
41 #include "nv50_display.h"
1c50cd3 @koriakin vm: First bits and pieces.
koriakin authored
42 #include "pscnv_vm.h"
8697b19 @koriakin Clean up fd's channels after close.
koriakin authored
43 #include "pscnv_chan.h"
e6e794c @koriakin Make fifo into a separate engine type, abstract FIFO init properly.
koriakin authored
44 #include "pscnv_fifo.h"
319035b @koriakin Move ioctls and some other userland interface stuff to a separate file.
koriakin authored
45 #include "pscnv_ioctl.h"
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
46
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
47 static void nouveau_stub_takedown(struct drm_device *dev) {}
48 static int nouveau_stub_init(struct drm_device *dev) { return 0; }
49
50 static int nouveau_init_engine_ptrs(struct drm_device *dev)
51 {
52 struct drm_nouveau_private *dev_priv = dev->dev_private;
53 struct nouveau_engine *engine = &dev_priv->engine;
54
55 if (dev_priv->chipset < 0x10) {
56 engine->gpio.init = nouveau_stub_init;
57 engine->gpio.takedown = nouveau_stub_takedown;
58 engine->gpio.get = NULL;
59 engine->gpio.set = NULL;
60 engine->gpio.irq_enable = NULL;
de0a506 @mlankhorst update pm to nouveau git
mlankhorst authored
61 engine->pm.clocks_get = nv04_pm_clocks_get;
62 engine->pm.clocks_pre = nv04_pm_clocks_pre;
63 engine->pm.clocks_set = nv04_pm_clocks_set;
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
64 } else if (dev_priv->chipset < 0x50 || (dev_priv->chipset & 0xf0) == 0x60) {
65 engine->gpio.init = nouveau_stub_init;
66 engine->gpio.takedown = nouveau_stub_takedown;
67 engine->gpio.get = nv10_gpio_get;
68 engine->gpio.set = nv10_gpio_set;
69 engine->gpio.irq_enable = NULL;
de0a506 @mlankhorst update pm to nouveau git
mlankhorst authored
70 engine->pm.clocks_get = nv04_pm_clocks_get;
71 engine->pm.clocks_pre = nv04_pm_clocks_pre;
72 engine->pm.clocks_set = nv04_pm_clocks_set;
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
73 } else {
f669f81 @mlankhorst pscnv: fix some pointer initializations
mlankhorst authored
74 u32 chip = dev_priv->chipset;
75 if (chip >= 0xc0)
76 chip &= ~0xf;
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
77 engine->gpio.init = nv50_gpio_init;
78 engine->gpio.takedown = nouveau_stub_takedown;
79 engine->gpio.get = nv50_gpio_get;
80 engine->gpio.set = nv50_gpio_set;
81 engine->gpio.irq_enable = nv50_gpio_irq_enable;
1a5820c @mlankhorst PWM fixes, still untested
mlankhorst authored
82 engine->pm.pwm_get = nv50_pm_pwm_get;
83 engine->pm.pwm_set = nv50_pm_pwm_set;
1780bb4 @mlankhorst add missing pm performance counters
mlankhorst authored
84 engine->pm.counter.init = nv40_counter_init;
85 engine->pm.counter.takedown = nv40_counter_fini;
86 engine->pm.counter.watch = nv40_counter_watch_signal;
87 engine->pm.counter.unwatch = nv40_counter_unwatch_signal;
88 engine->pm.counter.poll = nv40_counter_poll;
89 engine->pm.counter.start = nv40_counter_start;
90 engine->pm.counter.stop = nv40_counter_stop;
91 engine->pm.counter.signal_value = nv40_counter_value;
f669f81 @mlankhorst pscnv: fix some pointer initializations
mlankhorst authored
92 switch (chip) {
420c14a @koriakin Merge upstream commit 5a4ff9f48f638d0cddeb6788743f32d8cdc89423
koriakin authored
93 case 0xa3:
94 case 0xa5:
95 case 0xa8:
96 case 0xaf:
de0a506 @mlankhorst update pm to nouveau git
mlankhorst authored
97 engine->pm.clocks_get = nva3_pm_clocks_get;
98 engine->pm.clocks_pre = nva3_pm_clocks_pre;
99 engine->pm.clocks_set = nva3_pm_clocks_set;
420c14a @koriakin Merge upstream commit 5a4ff9f48f638d0cddeb6788743f32d8cdc89423
koriakin authored
100 break;
327ca9a @mlankhorst add nvd0 gpio based on darktamas commit
mlankhorst authored
101 case 0xd0:
102 engine->gpio.get = nvd0_gpio_get;
103 engine->gpio.set = nvd0_gpio_set;
270c119 @mlankhorst fix d9 support and corruption
mlankhorst authored
104 engine->pm.pwm_get = NULL;
105 engine->pm.pwm_set = NULL;
420c14a @koriakin Merge upstream commit 5a4ff9f48f638d0cddeb6788743f32d8cdc89423
koriakin authored
106 case 0xc0:
585e835 @mlankhorst and add nvc0 support
mlankhorst authored
107 engine->pm.clocks_get = nvc0_pm_clocks_get;
108 engine->pm.clocks_pre = nvc0_pm_clocks_pre;
109 engine->pm.clocks_set = nvc0_pm_clocks_set;
420c14a @koriakin Merge upstream commit 5a4ff9f48f638d0cddeb6788743f32d8cdc89423
koriakin authored
110 break;
111 default:
de0a506 @mlankhorst update pm to nouveau git
mlankhorst authored
112 engine->pm.clocks_get = nv50_pm_clocks_get;
113 engine->pm.clocks_pre = nv50_pm_clocks_pre;
114 engine->pm.clocks_set = nv50_pm_clocks_set;
420c14a @koriakin Merge upstream commit 5a4ff9f48f638d0cddeb6788743f32d8cdc89423
koriakin authored
115 break;
116 }
117 }
118
119 if (dev_priv->chipset < 0x40) {
387c8b9 @mlankhorst add missing voltage_get/set
mlankhorst authored
120 // Missing
420c14a @koriakin Merge upstream commit 5a4ff9f48f638d0cddeb6788743f32d8cdc89423
koriakin authored
121 } else if (dev_priv->chipset < 0x80) {
122 engine->pm.temp_get = nv40_temp_get;
123 } else {
124 engine->pm.temp_get = nv84_temp_get;
125 }
126
387c8b9 @mlankhorst add missing voltage_get/set
mlankhorst authored
127 engine->pm.voltage_get = nouveau_voltage_gpio_get;
128 engine->pm.voltage_set_range = nouveau_voltage_gpio_set_range;
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
129
130 if (dev_priv->chipset < 0x50 || (dev_priv->chipset & 0xf0) == 0x60) {
131 #if 0
132 engine->display.early_init = nv04_display_early_init;
133 engine->display.late_takedown = nv04_display_late_takedown;
134 engine->display.create = nv04_display_create;
135 engine->display.init = nv04_display_init;
136 engine->display.destroy = nv04_display_destroy;
137 #endif
138 NV_ERROR(dev, "NV%02x unsupported\n", dev_priv->chipset);
635f153 @koriakin Fix crash on unsupported chipsets.
koriakin authored
139 return -ENOSYS;
e618124 @mlankhorst add nvd0 display support
mlankhorst authored
140 } else if (dev_priv->chipset < 0xd0) {
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
141 engine->display.early_init = nv50_display_early_init;
142 engine->display.late_takedown = nv50_display_late_takedown;
143 engine->display.create = nv50_display_create;
144 engine->display.init = nv50_display_init;
145 engine->display.destroy = nv50_display_destroy;
e618124 @mlankhorst add nvd0 display support
mlankhorst authored
146 } else {
147 engine->display.early_init = nouveau_stub_init;
148 engine->display.late_takedown = nouveau_stub_takedown;
149 engine->display.create = nvd0_display_create;
150 engine->display.init = nvd0_display_init;
151 engine->display.destroy = nvd0_display_destroy;
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
152 }
153
154 return 0;
155 }
156
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
157 #ifdef __linux__
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
158 static unsigned int
159 nouveau_vga_set_decode(void *priv, bool state)
160 {
161 struct drm_device *dev = priv;
162 struct drm_nouveau_private *dev_priv = dev->dev_private;
163
164 if (dev_priv->chipset >= 0x40)
165 nv_wr32(dev, 0x88054, state);
166 else
167 nv_wr32(dev, 0x1854, state);
168
169 if (state)
170 return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
171 VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
172 else
173 return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
174 }
175
176 static void nouveau_switcheroo_set_state(struct pci_dev *pdev,
177 enum vga_switcheroo_state state)
178 {
179 pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
180 if (state == VGA_SWITCHEROO_ON) {
181 printk(KERN_ERR "VGA switcheroo: switched nouveau on\n");
182 nouveau_pci_resume(pdev);
183 } else {
184 printk(KERN_ERR "VGA switcheroo: switched nouveau off\n");
185 nouveau_pci_suspend(pdev, pmm);
186 }
187 }
188
79f0ea1 Add {i2c_id,pci_driver,switcheroo_reprobe,getparam_bus_type} to kapitest
Shinpei Kato authored
189 static void nouveau_switcheroo_reprobe(struct pci_dev *pdev)
190 {
191 struct drm_device *dev = pci_get_drvdata(pdev);
192 nouveau_fbcon_output_poll_changed(dev);
193 }
194
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
195 static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
196 {
197 struct drm_device *dev = pci_get_drvdata(pdev);
198 bool can_switch;
199
200 spin_lock(&dev->count_lock);
201 can_switch = (dev->open_count == 0);
202 spin_unlock(&dev->count_lock);
203 return can_switch;
204 }
eca97b9 @mharsch allow for changes to vga_switcheroo_register_client in v3.5
mharsch authored
205 #ifdef PSCNV_KAPI_SWITCHEROO_OPS
206 static const struct vga_switcheroo_client_ops nouveau_switcheroo_ops = {
207 .set_gpu_state = nouveau_switcheroo_set_state,
208 .reprobe = nouveau_switcheroo_reprobe,
209 .can_switch = nouveau_switcheroo_can_switch,
210 };
cf65809 @mlankhorst and get more files to compile on bsd
mlankhorst authored
211 #endif
eca97b9 @mharsch allow for changes to vga_switcheroo_register_client in v3.5
mharsch authored
212 #endif /* __linux__ */
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
213
214 int
215 nouveau_card_init(struct drm_device *dev)
216 {
217 struct drm_nouveau_private *dev_priv = dev->dev_private;
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
218 struct nouveau_engine *engine;
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
219 int ret;
e7e8ccb @koriakin pfifo/pgraph: The new engine abstraction.
koriakin authored
220 int i;
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
221
222 NV_DEBUG(dev, "prev state = %d\n", dev_priv->init_state);
223
224 if (dev_priv->init_state == NOUVEAU_CARD_INIT_DONE)
225 return 0;
226
227 NV_INFO(dev, "Initializing card...\n");
228
1cf0fec @mlankhorst freebsd WIP
mlankhorst authored
229 #ifdef __linux__
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
230 vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode);
eca97b9 @mharsch allow for changes to vga_switcheroo_register_client in v3.5
mharsch authored
231 #ifdef PSCNV_KAPI_SWITCHEROO_OPS
232 vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops);
233 #else
79f0ea1 Add {i2c_id,pci_driver,switcheroo_reprobe,getparam_bus_type} to kapitest
Shinpei Kato authored
234 #ifdef PSCNV_KAPI_SWITCHEROO_REPROBE
235 vga_switcheroo_register_client(dev->pdev, nouveau_switcheroo_set_state,
eca97b9 @mharsch allow for changes to vga_switcheroo_register_client in v3.5
mharsch authored
236 nouveau_switcheroo_reprobe,
79f0ea1 Add {i2c_id,pci_driver,switcheroo_reprobe,getparam_bus_type} to kapitest
Shinpei Kato authored
237 nouveau_switcheroo_can_switch);
238 #else
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
239 vga_switcheroo_register_client(dev->pdev, nouveau_switcheroo_set_state,
79f0ea1 Add {i2c_id,pci_driver,switcheroo_reprobe,getparam_bus_type} to kapitest
Shinpei Kato authored
240 nouveau_switcheroo_can_switch);
241 #endif
1cf0fec @mlankhorst freebsd WIP
mlankhorst authored
242 #endif
eca97b9 @mharsch allow for changes to vga_switcheroo_register_client in v3.5
mharsch authored
243 #endif /* __linux__ */
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
244
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
245 dev_priv->init_state = NOUVEAU_CARD_INIT_FAILED;
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
246
247 /* Initialise internal driver API hooks */
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
248 ret = nouveau_init_engine_ptrs(dev);
249 if (ret)
250 goto out;
251 engine = &dev_priv->engine;
de0a506 @mlankhorst update pm to nouveau git
mlankhorst authored
252 spin_lock_init(&dev_priv->context_switch_lock);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
253
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
254 /* Make the CRTCs and I2C buses accessible */
255 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
256 ret = engine->display.early_init(dev);
257 if (ret)
258 goto out;
259 }
260
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
261 /* Parse BIOS tables / Run init tables if card not POSTed */
262 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
263 ret = nouveau_bios_init(dev);
264 if (ret)
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
265 goto out_display_early;
c1aa285 nvc0: fix pgraph channel takedown/free
Shinpei Kato authored
266
267 /* workaround an odd issue on nvc1 by disabling the device's
268 * nosnoop capability. hopefully won't cause issues until a
269 * better fix is found - assuming there is one...
270 */
271 if (dev_priv->chipset == 0xc1) {
272 nv_mask(dev, 0x00088080, 0x00000800, 0x00000000);
273 }
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
274 }
275
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
276 ret = pscnv_mem_init(dev);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
277 if (ret)
278 goto out_bios;
279
2f00026 @mlankhorst move PM until after memory is initialized, for vram memory type detectio...
mlankhorst authored
280 nouveau_pm_init(dev);
281
6036861 @koriakin Some nouveau_state.c fixes.
koriakin authored
282 switch (dev_priv->card_type) {
283 case NV_50:
c355a5c @koriakin First shot at chan engine.
koriakin authored
284 ret = nv50_chan_init(dev);
285 break;
270c119 @mlankhorst fix d9 support and corruption
mlankhorst authored
286 case NV_D0:
1ea52ab @koriakin vm, chan: Add NVC0 support.
koriakin authored
287 case NV_C0:
288 ret = nvc0_chan_init(dev);
289 break;
c355a5c @koriakin First shot at chan engine.
koriakin authored
290 default:
291 NV_ERROR(dev, "No CHAN implementation for NV%02x!\n", dev_priv->chipset);
292 ret = -ENOSYS;
293 }
294 if (ret)
295 goto out_vram;
296
297 switch (dev_priv->card_type) {
298 case NV_50:
6036861 @koriakin Some nouveau_state.c fixes.
koriakin authored
299 ret = nv50_vm_init(dev);
300 break;
270c119 @mlankhorst fix d9 support and corruption
mlankhorst authored
301 case NV_D0:
1ea52ab @koriakin vm, chan: Add NVC0 support.
koriakin authored
302 case NV_C0:
303 ret = nvc0_vm_init(dev);
304 break;
6036861 @koriakin Some nouveau_state.c fixes.
koriakin authored
305 default:
306 NV_ERROR(dev, "No VM implementation for NV%02x!\n", dev_priv->chipset);
307 ret = -ENOSYS;
308 }
1c50cd3 @koriakin vm: First bits and pieces.
koriakin authored
309 if (ret)
c355a5c @koriakin First shot at chan engine.
koriakin authored
310 goto out_chan;
1c50cd3 @koriakin vm: First bits and pieces.
koriakin authored
311
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
312 /* PMC */
0e92a44 @koriakin Nuke fb/mc engines and some other stuff.
koriakin authored
313 nv_wr32(dev, NV03_PMC_ENABLE, 0xFFFFFFFF);
314
315 /* PBUS */
316 nv_wr32(dev, 0x1100, 0xFFFFFFFF);
317 nv_wr32(dev, 0x1140, 0xFFFFFFFF);
e55ad57 @koriakin Throw in PMC init too.
koriakin authored
318
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
319 /* PGPIO */
320 ret = engine->gpio.init(dev);
321 if (ret)
322 goto out_vm;
323
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
324 /* PTIMER */
2a99513 @koriakin Nuke ptimer engine.
koriakin authored
325 ret = nv04_timer_init(dev);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
326 if (ret)
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
327 goto out_gpio;
8d3954b @koriakin PFIFO code.
koriakin authored
328
b8d8367 @koriakin Add PGRAPH code.
koriakin authored
329 /* XXX: handle noaccel */
6036861 @koriakin Some nouveau_state.c fixes.
koriakin authored
330 switch (dev_priv->card_type) {
331 case NV_50:
332 /* PFIFO */
333 ret = nv50_fifo_init(dev);
334 if (!ret) {
335 /* PGRAPH */
336 nv50_graph_init(dev);
337 }
338 break;
df317bc @mlankhorst add graph support for d9
mlankhorst authored
339 case NV_D0:
5a997ff @koriakin nvc0/fifo: Port from nvc0 branch with some improvements.
koriakin authored
340 case NV_C0:
341 /* PFIFO */
4512e63 nvc0: make it build again
Christoph Bumiller authored
342 ret = nvc0_fifo_init(dev);
343 if (!ret) {
344 /* PGRAPH */
71293cb nvc0: Add pcopy engines
Shinpei Kato authored
345 ret = nvc0_graph_init(dev);
df317bc @mlankhorst add graph support for d9
mlankhorst authored
346 if (!ret && dev_priv->card_type == NV_C0) {
71293cb nvc0: Add pcopy engines
Shinpei Kato authored
347 /* PCOPY0 */
348 nvc0_copy_init(dev, 0);
349 /* PCOPY1 */
350 nvc0_copy_init(dev, 1);
351 }
4512e63 nvc0: make it build again
Christoph Bumiller authored
352 }
5a997ff @koriakin nvc0/fifo: Port from nvc0 branch with some improvements.
koriakin authored
353 break;
6036861 @koriakin Some nouveau_state.c fixes.
koriakin authored
354 default:
355 break;
e7e8ccb @koriakin pfifo/pgraph: The new engine abstraction.
koriakin authored
356 }
76ec440 @koriakin nv84/crypt: Initial implementation.
koriakin authored
357 switch (dev_priv->chipset) {
358 case 0x84:
359 case 0x86:
360 case 0x92:
361 case 0x94:
362 case 0x96:
363 case 0xa0:
364 nv84_crypt_init(dev);
365 break;
6562aab @koriakin nv98: Add PCRYPT support.
koriakin authored
366 case 0x98:
367 case 0xaa:
368 case 0xac:
369 nv98_crypt_init(dev);
370 break;
76ec440 @koriakin nv84/crypt: Initial implementation.
koriakin authored
371 }
b8d8367 @koriakin Add PGRAPH code.
koriakin authored
372
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
373 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
134d63e @mlankhorst update display properties to current mainline nouveau
mlankhorst authored
374 ret = nouveau_display_create(dev);
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
375 if (ret)
376 goto out_fifo;
377 }
378
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
379 /* this call irq_preinstall, register irq handler and
380 * call irq_postinstall
381 */
06e9464 @mlankhorst and get bsd support working without kernel panic
mlankhorst authored
382 #ifdef __linux__
383 ret = drm_irq_install(dev);
384 #else
385 // SIGH
172511e DRM_LOCK()/DRM_UNLOCK() accepts struct drm_device now
Alexander Polakov authored
386 DRM_UNLOCK(dev);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
387 ret = drm_irq_install(dev);
172511e DRM_LOCK()/DRM_UNLOCK() accepts struct drm_device now
Alexander Polakov authored
388 DRM_LOCK(dev);
06e9464 @mlankhorst and get bsd support working without kernel panic
mlankhorst authored
389 #endif
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
390 if (ret)
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
391 goto out_display;
3434652 @koriakin Add KMS support.
koriakin authored
392
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
393 ret = drm_vblank_init(dev, 0);
394 if (ret)
395 goto out_irq;
396
397 /* what about PVIDEO/PCRTC/PRAMDAC etc? */
3434652 @koriakin Add KMS support.
koriakin authored
398 #if 0
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
399 if (!engine->graph.accel_blocked) {
400 ret = nouveau_card_init_channel(dev);
401 if (ret)
402 goto out_irq;
403 }
3434652 @koriakin Add KMS support.
koriakin authored
404 #endif
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
405
406 ret = nouveau_backlight_init(dev);
407 if (ret)
408 NV_ERROR(dev, "Error %d registering backlight\n", ret);
3434652 @koriakin Add KMS support.
koriakin authored
409
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
410 dev_priv->init_state = NOUVEAU_CARD_INIT_DONE;
3434652 @koriakin Add KMS support.
koriakin authored
411
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
412 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
06e9464 @mlankhorst and get bsd support working without kernel panic
mlankhorst authored
413 #ifdef __linux__
414 nouveau_fbcon_init(dev);
415 #else
416 // SIGH
172511e DRM_LOCK()/DRM_UNLOCK() accepts struct drm_device now
Alexander Polakov authored
417 DRM_UNLOCK(dev);
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
418 nouveau_fbcon_init(dev);
172511e DRM_LOCK()/DRM_UNLOCK() accepts struct drm_device now
Alexander Polakov authored
419 DRM_LOCK(dev);
06e9464 @mlankhorst and get bsd support working without kernel panic
mlankhorst authored
420 #endif
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
421 drm_kms_helper_poll_init(dev);
422 }
3434652 @koriakin Add KMS support.
koriakin authored
423
af2b8d0 @koriakin Print a message on init/takedown done.
koriakin authored
424 NV_INFO(dev, "Card initialized.\n");
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
425 return 0;
3434652 @koriakin Add KMS support.
koriakin authored
426
427 #if 0
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
428 out_channel:
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
429 if (dev_priv->channel) {
430 nouveau_channel_free(dev_priv->channel);
431 dev_priv->channel = NULL;
432 }
433 #endif
3434652 @koriakin Add KMS support.
koriakin authored
434 out_irq:
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
435 drm_irq_uninstall(dev);
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
436 out_display:
437 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
134d63e @mlankhorst update display properties to current mainline nouveau
mlankhorst authored
438 nouveau_display_destroy(dev);
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
439 }
440 out_fifo:
e7e8ccb @koriakin pfifo/pgraph: The new engine abstraction.
koriakin authored
441 for (i = 0; i < PSCNV_ENGINES_NUM; i++)
442 if (dev_priv->engines[i]) {
443 dev_priv->engines[i]->takedown(dev_priv->engines[i]);
444 dev_priv->engines[i] = 0;
445 }
e6e794c @koriakin Make fifo into a separate engine type, abstract FIFO init properly.
koriakin authored
446 if (dev_priv->fifo)
447 dev_priv->fifo->takedown(dev);
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
448 out_gpio:
449 engine->gpio.takedown(dev);
b8d8367 @koriakin Add PGRAPH code.
koriakin authored
450 out_vm:
868ec75 @koriakin Disable PBUS interrupts on takedown.
koriakin authored
451 nv_wr32(dev, 0x1140, 0);
6b1d7e8 @koriakin vm: Introduce VM engine.
koriakin authored
452 dev_priv->vm->takedown(dev);
c355a5c @koriakin First shot at chan engine.
koriakin authored
453 out_chan:
454 dev_priv->chan->takedown(dev);
270c119 @mlankhorst fix d9 support and corruption
mlankhorst authored
455 nouveau_pm_fini(dev);
1c50cd3 @koriakin vm: First bits and pieces.
koriakin authored
456 out_vram:
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
457 pscnv_mem_takedown(dev);
0bf7ad6 @koriakin Start VRAM allocator
koriakin authored
458 out_bios:
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
459 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
460 nouveau_bios_takedown(dev);
461 }
462 out_display_early:
463 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
464 engine->display.late_takedown(dev);
465 }
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
466 out:
1cf0fec @mlankhorst freebsd WIP
mlankhorst authored
467 #ifdef __linux__
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
468 vga_client_register(dev->pdev, NULL, NULL, NULL);
1cf0fec @mlankhorst freebsd WIP
mlankhorst authored
469 #endif
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
470 return ret;
471 }
472
473 static void nouveau_card_takedown(struct drm_device *dev)
474 {
475 struct drm_nouveau_private *dev_priv = dev->dev_private;
e7e8ccb @koriakin pfifo/pgraph: The new engine abstraction.
koriakin authored
476 int i;
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
477
478 NV_DEBUG(dev, "prev state = %d\n", dev_priv->init_state);
479
9b94ad5 @mlankhorst get compile working on freebsd
mlankhorst authored
480 if (dev_priv->init_state == NOUVEAU_CARD_INIT_DONE) {
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
481 NV_INFO(dev, "Stopping card...\n");
482 nouveau_backlight_exit(dev);
3434652 @koriakin Add KMS support.
koriakin authored
483 drm_irq_uninstall(dev);
79f17b3 @mlankhorst fix vram timing support
mlankhorst authored
484 flush_workqueue(dev_priv->wq);
e7e8ccb @koriakin pfifo/pgraph: The new engine abstraction.
koriakin authored
485 for (i = 0; i < PSCNV_ENGINES_NUM; i++)
486 if (dev_priv->engines[i]) {
487 dev_priv->engines[i]->takedown(dev_priv->engines[i]);
488 dev_priv->engines[i] = 0;
489 }
e6e794c @koriakin Make fifo into a separate engine type, abstract FIFO init properly.
koriakin authored
490 if (dev_priv->fifo)
491 dev_priv->fifo->takedown(dev);
6b1d7e8 @koriakin vm: Introduce VM engine.
koriakin authored
492 dev_priv->vm->takedown(dev);
c355a5c @koriakin First shot at chan engine.
koriakin authored
493 dev_priv->chan->takedown(dev);
3375d31 @koriakin vram: Split to pscnv_vram and pscnv_mem, vo -> bo everywhere.
koriakin authored
494 pscnv_mem_takedown(dev);
868ec75 @koriakin Disable PBUS interrupts on takedown.
koriakin authored
495 nv_wr32(dev, 0x1140, 0);
420c14a @koriakin Merge upstream commit 5a4ff9f48f638d0cddeb6788743f32d8cdc89423
koriakin authored
496 nouveau_pm_fini(dev);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
497 nouveau_bios_takedown(dev);
498
1cf0fec @mlankhorst freebsd WIP
mlankhorst authored
499 #ifdef __linux__
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
500 vga_client_register(dev->pdev, NULL, NULL, NULL);
1cf0fec @mlankhorst freebsd WIP
mlankhorst authored
501 #endif
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
502 dev_priv->init_state = NOUVEAU_CARD_INIT_DOWN;
af2b8d0 @koriakin Print a message on init/takedown done.
koriakin authored
503 NV_INFO(dev, "Card stopped.\n");
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
504 }
505 }
506
507 /* here a client dies, release the stuff that was allocated for its
508 * file_priv */
509 void nouveau_preclose(struct drm_device *dev, struct drm_file *file_priv)
510 {
edf0adb Lock is locked by drm_close()
Alexander Polakov authored
511 DRM_LOCK_ASSERT(dev);
8697b19 @koriakin Clean up fd's channels after close.
koriakin authored
512 pscnv_chan_cleanup(dev, file_priv);
dd0782c @koriakin vm: Add refcounting for vspaces.
koriakin authored
513 pscnv_vspace_cleanup(dev, file_priv);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
514 }
515
516 /* first module load, setup the mmio/fb mapping */
517 /* KMS: we need mmio at load time, not when the first drm client opens. */
518 int nouveau_firstopen(struct drm_device *dev)
519 {
520 nouveau_card_init(dev);
521 return 0;
522 }
523
524 /* if we have an OF card, copy vbios to RAMIN */
525 static void nouveau_OF_copy_vbios_to_ramin(struct drm_device *dev)
526 {
527 #if defined(__powerpc__)
528 int size, i;
529 const uint32_t *bios;
530 struct device_node *dn = pci_device_to_OF_node(dev->pdev);
531 if (!dn) {
532 NV_INFO(dev, "Unable to get the OF node\n");
533 return;
534 }
535
536 bios = of_get_property(dn, "NVDA,BMP", &size);
537 if (bios) {
538 for (i = 0; i < size; i += 4)
539 nv_wi32(dev, i, bios[i/4]);
540 NV_INFO(dev, "OF bios successfully copied (%d bytes)\n", size);
541 } else {
542 NV_INFO(dev, "Unable to get the OF bios\n");
543 }
544 #endif
545 }
546
9b94ad5 @mlankhorst get compile working on freebsd
mlankhorst authored
547 #ifdef __linux__
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
548 static struct apertures_struct *nouveau_get_apertures(struct drm_device *dev)
549 {
550 struct pci_dev *pdev = dev->pdev;
551 struct apertures_struct *aper = alloc_apertures(3);
552 if (!aper)
553 return NULL;
554
555 aper->ranges[0].base = pci_resource_start(pdev, 1);
556 aper->ranges[0].size = pci_resource_len(pdev, 1);
557 aper->count = 1;
558
559 if (pci_resource_len(pdev, 2)) {
560 aper->ranges[aper->count].base = pci_resource_start(pdev, 2);
561 aper->ranges[aper->count].size = pci_resource_len(pdev, 2);
562 aper->count++;
563 }
564
565 if (pci_resource_len(pdev, 3)) {
566 aper->ranges[aper->count].base = pci_resource_start(pdev, 3);
567 aper->ranges[aper->count].size = pci_resource_len(pdev, 3);
568 aper->count++;
569 }
570
571 return aper;
572 }
9b94ad5 @mlankhorst get compile working on freebsd
mlankhorst authored
573 #endif
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
574
575 static int nouveau_remove_conflicting_drivers(struct drm_device *dev)
576 {
9b94ad5 @mlankhorst get compile working on freebsd
mlankhorst authored
577 #ifdef __linux__
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
578 struct drm_nouveau_private *dev_priv = dev->dev_private;
579 bool primary = false;
580 dev_priv->apertures = nouveau_get_apertures(dev);
581 if (!dev_priv->apertures)
582 return -ENOMEM;
583
584 #ifdef CONFIG_X86
585 primary = dev->pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
586 #endif
587
588 remove_conflicting_framebuffers(dev_priv->apertures, "nouveaufb", primary);
9b94ad5 @mlankhorst get compile working on freebsd
mlankhorst authored
589 #endif
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
590 return 0;
591 }
592
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
593 int nouveau_load(struct drm_device *dev, unsigned long flags)
594 {
595 struct drm_nouveau_private *dev_priv;
de0a506 @mlankhorst update pm to nouveau git
mlankhorst authored
596 uint32_t reg0, strap;
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
597 resource_size_t mmio_start_offs;
df8fa30 @mlankhorst and more fixes
mlankhorst authored
598 int ret;
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
599
600 dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
601 if (!dev_priv)
602 return -ENOMEM;
603 dev->dev_private = dev_priv;
604 dev_priv->dev = dev;
605
606 dev_priv->flags = flags/* & NOUVEAU_FLAGS*/;
607 dev_priv->init_state = NOUVEAU_CARD_INIT_DOWN;
608
1cf0fec @mlankhorst freebsd WIP
mlankhorst authored
609 NV_DEBUG(dev, "vendor: 0x%X device: 0x%X\n",
610 dev->pci_vendor, dev->pci_device);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
611
612 dev_priv->wq = create_workqueue("nouveau");
613 if (!dev_priv->wq)
614 return -EINVAL;
615
616 /* resource 0 is mmio regs */
617 /* resource 1 is linear FB */
618 /* resource 2 is RAMIN (mmio regs + 0x1000000) */
619 /* resource 6 is bios */
620
621 /* map the mmio regs */
5cda219 @mlankhorst minor steps to getting running on bsd
mlankhorst authored
622 mmio_start_offs = drm_get_resource_start(dev, 0);
df8fa30 @mlankhorst and more fixes
mlankhorst authored
623 ret = drm_addmap(dev, mmio_start_offs, 0x00800000, _DRM_REGISTERS,
624 _DRM_KERNEL | _DRM_DRIVER, &dev_priv->mmio);
625
626 if (ret) {
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
627 NV_ERROR(dev, "Unable to initialize the mmio mapping. "
628 "Please report your setup to " DRIVER_EMAIL "\n");
df8fa30 @mlankhorst and more fixes
mlankhorst authored
629 return ret;
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
630 }
631 NV_DEBUG(dev, "regs mapped ok at 0x%llx\n",
632 (unsigned long long)mmio_start_offs);
633
634 #ifdef __BIG_ENDIAN
635 /* Put the card in BE mode if it's not */
636 if (nv_rd32(dev, NV03_PMC_BOOT_1))
637 nv_wr32(dev, NV03_PMC_BOOT_1, 0x00000001);
638
639 DRM_MEMORYBARRIER();
640 #endif
641
642 /* Time to determine the card architecture */
643 reg0 = nv_rd32(dev, NV03_PMC_BOOT_0);
644
645 /* We're dealing with >=NV10 */
646 if ((reg0 & 0x0f000000) > 0) {
647 /* Bit 27-20 contain the architecture in hex */
648 dev_priv->chipset = (reg0 & 0xff00000) >> 20;
649 /* NV04 or NV05 */
650 } else if ((reg0 & 0xff00fff0) == 0x20004000) {
651 if (reg0 & 0x00f00000)
652 dev_priv->chipset = 0x05;
653 else
654 dev_priv->chipset = 0x04;
63c75bd @koriakin Recognise pre-NV04 chipsets.
koriakin authored
655 } else {
656 dev_priv->chipset = (reg0 & 0xf0000) >> 16;
657 if (dev_priv->chipset < 1 || dev_priv->chipset > 3)
658 dev_priv->chipset = 0xff;
659 }
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
660
661 switch (dev_priv->chipset & 0xf0) {
662 case 0x00:
63c75bd @koriakin Recognise pre-NV04 chipsets.
koriakin authored
663 if (dev_priv->chipset >= 4)
664 dev_priv->card_type = NV_04;
665 else
666 dev_priv->card_type = dev_priv->chipset;
667 break;
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
668 case 0x10:
669 case 0x20:
670 case 0x30:
671 dev_priv->card_type = dev_priv->chipset & 0xf0;
672 break;
673 case 0x40:
674 case 0x60:
675 dev_priv->card_type = NV_40;
676 break;
677 case 0x50:
678 case 0x80:
679 case 0x90:
680 case 0xa0:
681 dev_priv->card_type = NV_50;
682 break;
6036861 @koriakin Some nouveau_state.c fixes.
koriakin authored
683 case 0xc0:
684 dev_priv->card_type = NV_C0;
685 break;
327ca9a @mlankhorst add nvd0 gpio based on darktamas commit
mlankhorst authored
686 case 0xd0:
687 dev_priv->card_type = NV_D0;
688 break;
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
689 default:
690 NV_INFO(dev, "Unsupported chipset 0x%08x\n", reg0);
691 return -EINVAL;
692 }
693
63c75bd @koriakin Recognise pre-NV04 chipsets.
koriakin authored
694 NV_INFO(dev, "Detected an NV%02x generation card (0x%08x)\n",
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
695 dev_priv->card_type, reg0);
696
de0a506 @mlankhorst update pm to nouveau git
mlankhorst authored
697 /* determine frequency of timing crystal */
698 strap = nv_rd32(dev, 0x101000);
699 if ( dev_priv->chipset < 0x17 ||
700 (dev_priv->chipset >= 0x20 && dev_priv->chipset <= 0x25))
701 strap &= 0x00000040;
702 else
703 strap &= 0x00400040;
704
705 switch (strap) {
706 case 0x00000000: dev_priv->crystal = 13500; break;
707 case 0x00000040: dev_priv->crystal = 14318; break;
708 case 0x00400000: dev_priv->crystal = 27000; break;
709 case 0x00400040: dev_priv->crystal = 25000; break;
710 }
711
712 NV_DEBUG(dev, "crystal freq: %dKHz\n", dev_priv->crystal);
713
5cda219 @mlankhorst minor steps to getting running on bsd
mlankhorst authored
714 dev_priv->fb_size = drm_get_resource_len(dev, 1);
715 dev_priv->fb_phys = drm_get_resource_start(dev, 1);
716 dev_priv->mmio_phys = drm_get_resource_start(dev, 0);
a256613 @koriakin Throw out old fb_* fields, add fb_size.
koriakin authored
717
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
718 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
719 int ret = nouveau_remove_conflicting_drivers(dev);
720 if (ret)
721 return ret;
722 }
723
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
724 /* map larger RAMIN aperture on NV40 cards */
725 if (dev_priv->card_type >= NV_40) {
726 int ramin_bar = 2;
06e9464 @mlankhorst and get bsd support working without kernel panic
mlankhorst authored
727 if (drm_get_resource_len(dev, ramin_bar) < PAGE_SIZE)
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
728 ramin_bar = 3;
729
5cda219 @mlankhorst minor steps to getting running on bsd
mlankhorst authored
730 dev_priv->ramin_size = drm_get_resource_len(dev, ramin_bar);
df8fa30 @mlankhorst and more fixes
mlankhorst authored
731 ret = drm_addmap(dev, drm_get_resource_start(dev, ramin_bar),
732 dev_priv->ramin_size, _DRM_REGISTERS,
733 _DRM_KERNEL | _DRM_DRIVER, &dev_priv->ramin);
734 if (ret) {
86ceea0 @koriakin Fix RAMIN mapping.
koriakin authored
735 NV_ERROR(dev, "Failed to init RAMIN mapping\n");
df8fa30 @mlankhorst and more fixes
mlankhorst authored
736 return ret;
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
737 }
738 }
739
740 nouveau_OF_copy_vbios_to_ramin(dev);
741
742 /* Special flags */
743 if (dev->pci_device == 0x01a0)
744 dev_priv->flags |= NV_NFORCE;
745 else if (dev->pci_device == 0x01f0)
746 dev_priv->flags |= NV_NFORCE2;
747
748 /* For kernel modesetting, init card now and bring up fbcon */
749 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
750 int ret = nouveau_card_init(dev);
751 if (ret)
752 return ret;
753 }
6185655 Kill bo->fakepages
Alexander Polakov authored
754 device_printf(dev->device,
755 "taking over the fictitious range 0x%lx-0x%lx...",
756 dev_priv->fb_phys, dev_priv->fb_phys + dev_priv->fb_size);
757 if ((ret = -vm_phys_fictitious_reg_range(dev_priv->fb_phys, dev_priv->fb_phys + dev_priv->fb_size, 0 /* PLHK FIXME */)))
758 return (ret);
759 device_printf(dev->device, "OK\n");
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
760
761 return 0;
762 }
763
764 static void nouveau_close(struct drm_device *dev)
765 {
766 struct drm_nouveau_private *dev_priv = dev->dev_private;
767
768 /* In the case of an error dev_priv may not be allocated yet */
769 if (dev_priv)
770 nouveau_card_takedown(dev);
771 }
772
773 /* KMS: we need mmio at load time, not when the first drm client opens. */
774 void nouveau_lastclose(struct drm_device *dev)
775 {
776 if (drm_core_check_feature(dev, DRIVER_MODESET))
777 return;
778
779 nouveau_close(dev);
780 }
781
782 int nouveau_unload(struct drm_device *dev)
783 {
784 struct drm_nouveau_private *dev_priv = dev->dev_private;
785
786 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
c2f32b8 @koriakin Bump to kernel 2.6.35.
koriakin authored
787 nouveau_fbcon_fini(dev);
e47bd7d @mlankhorst fixup HEAD^^ (display)
mlankhorst authored
788 nouveau_display_destroy(dev);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
789 nouveau_close(dev);
790 }
79f17b3 @mlankhorst fix vram timing support
mlankhorst authored
791 destroy_workqueue(dev_priv->wq);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
792
df8fa30 @mlankhorst and more fixes
mlankhorst authored
793 drm_rmmap(dev, dev_priv->mmio);
794 drm_rmmap(dev, dev_priv->ramin);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
795
796 kfree(dev_priv);
797 dev->dev_private = NULL;
798 return 0;
799 }
800
801 /* Wait until (value(reg) & mask) == val, up until timeout has hit */
802 bool nouveau_wait_until(struct drm_device *dev, uint64_t timeout,
803 uint32_t reg, uint32_t mask, uint32_t val)
804 {
2a99513 @koriakin Nuke ptimer engine.
koriakin authored
805 uint64_t start = nv04_timer_read(dev);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
806
807 do {
808 if ((nv_rd32(dev, reg) & mask) == val)
809 return true;
2a99513 @koriakin Nuke ptimer engine.
koriakin authored
810 } while (nv04_timer_read(dev) - start < timeout);
978685f @koriakin pscnv: Import linux module skeleton.
koriakin authored
811
812 return false;
813 }
4512e63 nvc0: make it build again
Christoph Bumiller authored
814
815 /* Wait until (value(reg) & mask) != val, up until timeout has hit. */
816 bool nouveau_wait_until_neq(struct drm_device *dev, uint64_t timeout,
817 uint32_t reg, uint32_t mask, uint32_t val)
818 {
819 uint64_t start = nv04_timer_read(dev);
820
821 do {
822 if ((nv_rd32(dev, reg) & mask) != val)
823 return true;
824 } while (nv04_timer_read(dev) - start < timeout);
825
826 return false;
827 }
de0a506 @mlankhorst update pm to nouveau git
mlankhorst authored
828
829 bool
830 nouveau_wait_cb(struct drm_device *dev, uint64_t timeout,
831 bool (*cond)(void *), void *data)
832 {
833 uint64_t start = nv04_timer_read(dev);
834
835 do {
836 if (cond(data) == true)
837 return true;
838 } while (nv04_timer_read(dev) - start < timeout);
839
840 return false;
841 }
Something went wrong with that request. Please try again.