2 * Copyright 2005 Stephane Marchesin
3 * Copyright 2008 Stuart Bennett
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 (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
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.
26 #include "nouveau_drv.h"
28 #include "drm_sarea.h"
29 #include "drm_crtc_helper.h"
31 #include <linux/swab.h>
32 #include <linux/slab.h>
33 #include <linux/vgaarb.h>
34 #include <linux/vga_switcheroo.h>
37 #include "pscnv_drm.h"
38 #include "nouveau_reg.h"
39 #include "nouveau_fbcon.h"
40 #include "nouveau_pm.h"
41 #include "nv50_display.h"
43 #include "pscnv_chan.h"
44 #include "pscnv_fifo.h"
45 #include "pscnv_ioctl.h"
47 static void nouveau_stub_takedown(struct drm_device
*dev
) {}
48 static int nouveau_stub_init(struct drm_device
*dev
) { return 0; }
50 static int nouveau_init_engine_ptrs(struct drm_device
*dev
)
52 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
53 struct nouveau_engine
*engine
= &dev_priv
->engine
;
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
;
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
;
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
;
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
;
74 u32 chip
= dev_priv
->chipset
;
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
;
82 engine
->pm
.pwm_get
= nv50_pm_pwm_get
;
83 engine
->pm
.pwm_set
= nv50_pm_pwm_set
;
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
;
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
;
102 engine
->gpio
.get
= nvd0_gpio_get
;
103 engine
->gpio
.set
= nvd0_gpio_set
;
104 engine
->pm
.pwm_get
= NULL
;
105 engine
->pm
.pwm_set
= NULL
;
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
;
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
;
119 if (dev_priv
->chipset
< 0x40) {
121 } else if (dev_priv
->chipset
< 0x80) {
122 engine
->pm
.temp_get
= nv40_temp_get
;
124 engine
->pm
.temp_get
= nv84_temp_get
;
127 engine
->pm
.voltage_get
= nouveau_voltage_gpio_get
;
128 engine
->pm
.voltage_set_range
= nouveau_voltage_gpio_set_range
;
130 if (dev_priv
->chipset
< 0x50 || (dev_priv
->chipset
& 0xf0) == 0x60) {
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
;
138 NV_ERROR(dev
, "NV%02x unsupported\n", dev_priv
->chipset
);
140 } else if (dev_priv
->chipset
< 0xd0) {
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
;
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
;
159 nouveau_vga_set_decode(void *priv
, bool state
)
161 struct drm_device
*dev
= priv
;
162 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
164 if (dev_priv
->chipset
>= 0x40)
165 nv_wr32(dev
, 0x88054, state
);
167 nv_wr32(dev
, 0x1854, state
);
170 return VGA_RSRC_LEGACY_IO
| VGA_RSRC_LEGACY_MEM
|
171 VGA_RSRC_NORMAL_IO
| VGA_RSRC_NORMAL_MEM
;
173 return VGA_RSRC_NORMAL_IO
| VGA_RSRC_NORMAL_MEM
;
176 static void nouveau_switcheroo_set_state(struct pci_dev
*pdev
,
177 enum vga_switcheroo_state state
)
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
);
184 printk(KERN_ERR
"VGA switcheroo: switched nouveau off\n");
185 nouveau_pci_suspend(pdev
, pmm
);
189 static void nouveau_switcheroo_reprobe(struct pci_dev
*pdev
)
191 struct drm_device
*dev
= pci_get_drvdata(pdev
);
192 nouveau_fbcon_output_poll_changed(dev
);
195 static bool nouveau_switcheroo_can_switch(struct pci_dev
*pdev
)
197 struct drm_device
*dev
= pci_get_drvdata(pdev
);
200 spin_lock(&dev
->count_lock
);
201 can_switch
= (dev
->open_count
== 0);
202 spin_unlock(&dev
->count_lock
);
208 nouveau_card_init(struct drm_device
*dev
)
210 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
211 struct nouveau_engine
*engine
;
215 NV_DEBUG(dev
, "prev state = %d\n", dev_priv
->init_state
);
217 if (dev_priv
->init_state
== NOUVEAU_CARD_INIT_DONE
)
220 NV_INFO(dev
, "Initializing card...\n");
223 vga_client_register(dev
->pdev
, dev
, NULL
, nouveau_vga_set_decode
);
224 #ifdef PSCNV_KAPI_SWITCHEROO_REPROBE
225 vga_switcheroo_register_client(dev
->pdev
, nouveau_switcheroo_set_state
,
226 nouveau_switcheroo_can_switch
);
228 vga_switcheroo_register_client(dev
->pdev
, nouveau_switcheroo_set_state
,
229 nouveau_switcheroo_reprobe
,
230 nouveau_switcheroo_can_switch
);
234 dev_priv
->init_state
= NOUVEAU_CARD_INIT_FAILED
;
236 /* Initialise internal driver API hooks */
237 ret
= nouveau_init_engine_ptrs(dev
);
240 engine
= &dev_priv
->engine
;
241 spin_lock_init(&dev_priv
->context_switch_lock
);
243 /* Make the CRTCs and I2C buses accessible */
244 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
245 ret
= engine
->display
.early_init(dev
);
250 /* Parse BIOS tables / Run init tables if card not POSTed */
251 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
252 ret
= nouveau_bios_init(dev
);
254 goto out_display_early
;
256 /* workaround an odd issue on nvc1 by disabling the device's
257 * nosnoop capability. hopefully won't cause issues until a
258 * better fix is found - assuming there is one...
260 if (dev_priv
->chipset
== 0xc1) {
261 nv_mask(dev
, 0x00088080, 0x00000800, 0x00000000);
265 ret
= pscnv_mem_init(dev
);
269 nouveau_pm_init(dev
);
271 switch (dev_priv
->card_type
) {
273 ret
= nv50_chan_init(dev
);
277 ret
= nvc0_chan_init(dev
);
280 NV_ERROR(dev
, "No CHAN implementation for NV%02x!\n", dev_priv
->chipset
);
286 switch (dev_priv
->card_type
) {
288 ret
= nv50_vm_init(dev
);
292 ret
= nvc0_vm_init(dev
);
295 NV_ERROR(dev
, "No VM implementation for NV%02x!\n", dev_priv
->chipset
);
302 nv_wr32(dev
, NV03_PMC_ENABLE
, 0xFFFFFFFF);
305 nv_wr32(dev
, 0x1100, 0xFFFFFFFF);
306 nv_wr32(dev
, 0x1140, 0xFFFFFFFF);
309 ret
= engine
->gpio
.init(dev
);
314 ret
= nv04_timer_init(dev
);
318 /* XXX: handle noaccel */
319 switch (dev_priv
->card_type
) {
322 ret
= nv50_fifo_init(dev
);
325 nv50_graph_init(dev
);
331 ret
= nvc0_fifo_init(dev
);
334 ret
= nvc0_graph_init(dev
);
335 if (!ret
&& dev_priv
->card_type
== NV_C0
) {
337 nvc0_copy_init(dev
, 0);
339 nvc0_copy_init(dev
, 1);
346 switch (dev_priv
->chipset
) {
353 nv84_crypt_init(dev
);
358 nv98_crypt_init(dev
);
362 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
363 ret
= nouveau_display_create(dev
);
368 /* this call irq_preinstall, register irq handler and
369 * call irq_postinstall
372 ret
= drm_irq_install(dev
);
376 ret
= drm_irq_install(dev
);
382 ret
= drm_vblank_init(dev
, 0);
386 /* what about PVIDEO/PCRTC/PRAMDAC etc? */
388 if (!engine
->graph
.accel_blocked
) {
389 ret
= nouveau_card_init_channel(dev
);
395 ret
= nouveau_backlight_init(dev
);
397 NV_ERROR(dev
, "Error %d registering backlight\n", ret
);
399 dev_priv
->init_state
= NOUVEAU_CARD_INIT_DONE
;
401 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
403 nouveau_fbcon_init(dev
);
407 nouveau_fbcon_init(dev
);
410 drm_kms_helper_poll_init(dev
);
413 NV_INFO(dev
, "Card initialized.\n");
418 if (dev_priv
->channel
) {
419 nouveau_channel_free(dev_priv
->channel
);
420 dev_priv
->channel
= NULL
;
424 drm_irq_uninstall(dev
);
426 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
427 nouveau_display_destroy(dev
);
430 for (i
= 0; i
< PSCNV_ENGINES_NUM
; i
++)
431 if (dev_priv
->engines
[i
]) {
432 dev_priv
->engines
[i
]->takedown(dev_priv
->engines
[i
]);
433 dev_priv
->engines
[i
] = 0;
436 dev_priv
->fifo
->takedown(dev
);
438 engine
->gpio
.takedown(dev
);
440 nv_wr32(dev
, 0x1140, 0);
441 dev_priv
->vm
->takedown(dev
);
443 dev_priv
->chan
->takedown(dev
);
444 nouveau_pm_fini(dev
);
446 pscnv_mem_takedown(dev
);
448 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
449 nouveau_bios_takedown(dev
);
452 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
453 engine
->display
.late_takedown(dev
);
457 vga_client_register(dev
->pdev
, NULL
, NULL
, NULL
);
462 static void nouveau_card_takedown(struct drm_device
*dev
)
464 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
467 NV_DEBUG(dev
, "prev state = %d\n", dev_priv
->init_state
);
469 if (dev_priv
->init_state
== NOUVEAU_CARD_INIT_DONE
) {
470 NV_INFO(dev
, "Stopping card...\n");
471 nouveau_backlight_exit(dev
);
472 drm_irq_uninstall(dev
);
473 flush_workqueue(dev_priv
->wq
);
474 for (i
= 0; i
< PSCNV_ENGINES_NUM
; i
++)
475 if (dev_priv
->engines
[i
]) {
476 dev_priv
->engines
[i
]->takedown(dev_priv
->engines
[i
]);
477 dev_priv
->engines
[i
] = 0;
480 dev_priv
->fifo
->takedown(dev
);
481 dev_priv
->vm
->takedown(dev
);
482 dev_priv
->chan
->takedown(dev
);
483 pscnv_mem_takedown(dev
);
484 nv_wr32(dev
, 0x1140, 0);
485 nouveau_pm_fini(dev
);
486 nouveau_bios_takedown(dev
);
489 vga_client_register(dev
->pdev
, NULL
, NULL
, NULL
);
491 dev_priv
->init_state
= NOUVEAU_CARD_INIT_DOWN
;
492 NV_INFO(dev
, "Card stopped.\n");
496 /* here a client dies, release the stuff that was allocated for its
498 void nouveau_preclose(struct drm_device
*dev
, struct drm_file
*file_priv
)
500 pscnv_chan_cleanup(dev
, file_priv
);
501 pscnv_vspace_cleanup(dev
, file_priv
);
504 /* first module load, setup the mmio/fb mapping */
505 /* KMS: we need mmio at load time, not when the first drm client opens. */
506 int nouveau_firstopen(struct drm_device
*dev
)
508 nouveau_card_init(dev
);
512 /* if we have an OF card, copy vbios to RAMIN */
513 static void nouveau_OF_copy_vbios_to_ramin(struct drm_device
*dev
)
515 #if defined(__powerpc__)
517 const uint32_t *bios
;
518 struct device_node
*dn
= pci_device_to_OF_node(dev
->pdev
);
520 NV_INFO(dev
, "Unable to get the OF node\n");
524 bios
= of_get_property(dn
, "NVDA,BMP", &size
);
526 for (i
= 0; i
< size
; i
+= 4)
527 nv_wi32(dev
, i
, bios
[i
/4]);
528 NV_INFO(dev
, "OF bios successfully copied (%d bytes)\n", size
);
530 NV_INFO(dev
, "Unable to get the OF bios\n");
536 static struct apertures_struct
*nouveau_get_apertures(struct drm_device
*dev
)
538 struct pci_dev
*pdev
= dev
->pdev
;
539 struct apertures_struct
*aper
= alloc_apertures(3);
543 aper
->ranges
[0].base
= pci_resource_start(pdev
, 1);
544 aper
->ranges
[0].size
= pci_resource_len(pdev
, 1);
547 if (pci_resource_len(pdev
, 2)) {
548 aper
->ranges
[aper
->count
].base
= pci_resource_start(pdev
, 2);
549 aper
->ranges
[aper
->count
].size
= pci_resource_len(pdev
, 2);
553 if (pci_resource_len(pdev
, 3)) {
554 aper
->ranges
[aper
->count
].base
= pci_resource_start(pdev
, 3);
555 aper
->ranges
[aper
->count
].size
= pci_resource_len(pdev
, 3);
563 static int nouveau_remove_conflicting_drivers(struct drm_device
*dev
)
566 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
567 bool primary
= false;
568 dev_priv
->apertures
= nouveau_get_apertures(dev
);
569 if (!dev_priv
->apertures
)
573 primary
= dev
->pdev
->resource
[PCI_ROM_RESOURCE
].flags
& IORESOURCE_ROM_SHADOW
;
576 remove_conflicting_framebuffers(dev_priv
->apertures
, "nouveaufb", primary
);
581 int nouveau_load(struct drm_device
*dev
, unsigned long flags
)
583 struct drm_nouveau_private
*dev_priv
;
584 uint32_t reg0
, strap
;
585 resource_size_t mmio_start_offs
;
588 dev_priv
= kzalloc(sizeof(*dev_priv
), GFP_KERNEL
);
591 dev
->dev_private
= dev_priv
;
594 dev_priv
->flags
= flags
/* & NOUVEAU_FLAGS*/;
595 dev_priv
->init_state
= NOUVEAU_CARD_INIT_DOWN
;
597 NV_DEBUG(dev
, "vendor: 0x%X device: 0x%X\n",
598 dev
->pci_vendor
, dev
->pci_device
);
600 dev_priv
->wq
= create_workqueue("nouveau");
604 /* resource 0 is mmio regs */
605 /* resource 1 is linear FB */
606 /* resource 2 is RAMIN (mmio regs + 0x1000000) */
607 /* resource 6 is bios */
609 /* map the mmio regs */
610 mmio_start_offs
= drm_get_resource_start(dev
, 0);
611 ret
= drm_addmap(dev
, mmio_start_offs
, 0x00800000, _DRM_REGISTERS
,
612 _DRM_KERNEL
| _DRM_DRIVER
, &dev_priv
->mmio
);
615 NV_ERROR(dev
, "Unable to initialize the mmio mapping. "
616 "Please report your setup to " DRIVER_EMAIL
"\n");
619 NV_DEBUG(dev
, "regs mapped ok at 0x%llx\n",
620 (unsigned long long)mmio_start_offs
);
623 /* Put the card in BE mode if it's not */
624 if (nv_rd32(dev
, NV03_PMC_BOOT_1
))
625 nv_wr32(dev
, NV03_PMC_BOOT_1
, 0x00000001);
630 /* Time to determine the card architecture */
631 reg0
= nv_rd32(dev
, NV03_PMC_BOOT_0
);
633 /* We're dealing with >=NV10 */
634 if ((reg0
& 0x0f000000) > 0) {
635 /* Bit 27-20 contain the architecture in hex */
636 dev_priv
->chipset
= (reg0
& 0xff00000) >> 20;
638 } else if ((reg0
& 0xff00fff0) == 0x20004000) {
639 if (reg0
& 0x00f00000)
640 dev_priv
->chipset
= 0x05;
642 dev_priv
->chipset
= 0x04;
644 dev_priv
->chipset
= (reg0
& 0xf0000) >> 16;
645 if (dev_priv
->chipset
< 1 || dev_priv
->chipset
> 3)
646 dev_priv
->chipset
= 0xff;
649 switch (dev_priv
->chipset
& 0xf0) {
651 if (dev_priv
->chipset
>= 4)
652 dev_priv
->card_type
= NV_04
;
654 dev_priv
->card_type
= dev_priv
->chipset
;
659 dev_priv
->card_type
= dev_priv
->chipset
& 0xf0;
663 dev_priv
->card_type
= NV_40
;
669 dev_priv
->card_type
= NV_50
;
672 dev_priv
->card_type
= NV_C0
;
675 dev_priv
->card_type
= NV_D0
;
678 NV_INFO(dev
, "Unsupported chipset 0x%08x\n", reg0
);
682 NV_INFO(dev
, "Detected an NV%02x generation card (0x%08x)\n",
683 dev_priv
->card_type
, reg0
);
685 /* determine frequency of timing crystal */
686 strap
= nv_rd32(dev
, 0x101000);
687 if ( dev_priv
->chipset
< 0x17 ||
688 (dev_priv
->chipset
>= 0x20 && dev_priv
->chipset
<= 0x25))
694 case 0x00000000: dev_priv
->crystal
= 13500; break;
695 case 0x00000040: dev_priv
->crystal
= 14318; break;
696 case 0x00400000: dev_priv
->crystal
= 27000; break;
697 case 0x00400040: dev_priv
->crystal
= 25000; break;
700 NV_DEBUG(dev
, "crystal freq: %dKHz\n", dev_priv
->crystal
);
702 dev_priv
->fb_size
= drm_get_resource_len(dev
, 1);
703 dev_priv
->fb_phys
= drm_get_resource_start(dev
, 1);
704 dev_priv
->mmio_phys
= drm_get_resource_start(dev
, 0);
706 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
707 int ret
= nouveau_remove_conflicting_drivers(dev
);
712 /* map larger RAMIN aperture on NV40 cards */
713 if (dev_priv
->card_type
>= NV_40
) {
715 if (drm_get_resource_len(dev
, ramin_bar
) < PAGE_SIZE
)
718 dev_priv
->ramin_size
= drm_get_resource_len(dev
, ramin_bar
);
719 ret
= drm_addmap(dev
, drm_get_resource_start(dev
, ramin_bar
),
720 dev_priv
->ramin_size
, _DRM_REGISTERS
,
721 _DRM_KERNEL
| _DRM_DRIVER
, &dev_priv
->ramin
);
723 NV_ERROR(dev
, "Failed to init RAMIN mapping\n");
728 nouveau_OF_copy_vbios_to_ramin(dev
);
731 if (dev
->pci_device
== 0x01a0)
732 dev_priv
->flags
|= NV_NFORCE
;
733 else if (dev
->pci_device
== 0x01f0)
734 dev_priv
->flags
|= NV_NFORCE2
;
736 /* For kernel modesetting, init card now and bring up fbcon */
737 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
738 int ret
= nouveau_card_init(dev
);
746 static void nouveau_close(struct drm_device
*dev
)
748 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
750 /* In the case of an error dev_priv may not be allocated yet */
752 nouveau_card_takedown(dev
);
755 /* KMS: we need mmio at load time, not when the first drm client opens. */
756 void nouveau_lastclose(struct drm_device
*dev
)
758 if (drm_core_check_feature(dev
, DRIVER_MODESET
))
764 int nouveau_unload(struct drm_device
*dev
)
766 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
768 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
769 nouveau_fbcon_fini(dev
);
770 nouveau_display_destroy(dev
);
773 destroy_workqueue(dev_priv
->wq
);
775 drm_rmmap(dev
, dev_priv
->mmio
);
776 drm_rmmap(dev
, dev_priv
->ramin
);
779 dev
->dev_private
= NULL
;
783 /* Wait until (value(reg) & mask) == val, up until timeout has hit */
784 bool nouveau_wait_until(struct drm_device
*dev
, uint64_t timeout
,
785 uint32_t reg
, uint32_t mask
, uint32_t val
)
787 uint64_t start
= nv04_timer_read(dev
);
790 if ((nv_rd32(dev
, reg
) & mask
) == val
)
792 } while (nv04_timer_read(dev
) - start
< timeout
);
797 /* Wait until (value(reg) & mask) != val, up until timeout has hit. */
798 bool nouveau_wait_until_neq(struct drm_device
*dev
, uint64_t timeout
,
799 uint32_t reg
, uint32_t mask
, uint32_t val
)
801 uint64_t start
= nv04_timer_read(dev
);
804 if ((nv_rd32(dev
, reg
) & mask
) != val
)
806 } while (nv04_timer_read(dev
) - start
< timeout
);
812 nouveau_wait_cb(struct drm_device
*dev
, uint64_t timeout
,
813 bool (*cond
)(void *), void *data
)
815 uint64_t start
= nv04_timer_read(dev
);
818 if (cond(data
) == true)
820 } while (nv04_timer_read(dev
) - start
< timeout
);