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
);
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
,
212 #endif /* __linux__ */
215 nouveau_card_init(struct drm_device
*dev
)
217 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
218 struct nouveau_engine
*engine
;
222 NV_DEBUG(dev
, "prev state = %d\n", dev_priv
->init_state
);
224 if (dev_priv
->init_state
== NOUVEAU_CARD_INIT_DONE
)
227 NV_INFO(dev
, "Initializing card...\n");
230 vga_client_register(dev
->pdev
, dev
, NULL
, nouveau_vga_set_decode
);
231 #ifdef PSCNV_KAPI_SWITCHEROO_OPS
232 vga_switcheroo_register_client(dev
->pdev
, &nouveau_switcheroo_ops
);
234 #ifdef PSCNV_KAPI_SWITCHEROO_REPROBE
235 vga_switcheroo_register_client(dev
->pdev
, nouveau_switcheroo_set_state
,
236 nouveau_switcheroo_reprobe
,
237 nouveau_switcheroo_can_switch
);
239 vga_switcheroo_register_client(dev
->pdev
, nouveau_switcheroo_set_state
,
240 nouveau_switcheroo_can_switch
);
243 #endif /* __linux__ */
245 dev_priv
->init_state
= NOUVEAU_CARD_INIT_FAILED
;
247 /* Initialise internal driver API hooks */
248 ret
= nouveau_init_engine_ptrs(dev
);
251 engine
= &dev_priv
->engine
;
252 spin_lock_init(&dev_priv
->context_switch_lock
);
254 /* Make the CRTCs and I2C buses accessible */
255 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
256 ret
= engine
->display
.early_init(dev
);
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
);
265 goto out_display_early
;
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...
271 if (dev_priv
->chipset
== 0xc1) {
272 nv_mask(dev
, 0x00088080, 0x00000800, 0x00000000);
276 ret
= pscnv_mem_init(dev
);
280 nouveau_pm_init(dev
);
282 switch (dev_priv
->card_type
) {
284 ret
= nv50_chan_init(dev
);
288 ret
= nvc0_chan_init(dev
);
291 NV_ERROR(dev
, "No CHAN implementation for NV%02x!\n", dev_priv
->chipset
);
297 switch (dev_priv
->card_type
) {
299 ret
= nv50_vm_init(dev
);
303 ret
= nvc0_vm_init(dev
);
306 NV_ERROR(dev
, "No VM implementation for NV%02x!\n", dev_priv
->chipset
);
313 nv_wr32(dev
, NV03_PMC_ENABLE
, 0xFFFFFFFF);
316 nv_wr32(dev
, 0x1100, 0xFFFFFFFF);
317 nv_wr32(dev
, 0x1140, 0xFFFFFFFF);
320 ret
= engine
->gpio
.init(dev
);
325 ret
= nv04_timer_init(dev
);
329 /* XXX: handle noaccel */
330 switch (dev_priv
->card_type
) {
333 ret
= nv50_fifo_init(dev
);
336 nv50_graph_init(dev
);
342 ret
= nvc0_fifo_init(dev
);
345 ret
= nvc0_graph_init(dev
);
346 if (!ret
&& dev_priv
->card_type
== NV_C0
) {
348 nvc0_copy_init(dev
, 0);
350 nvc0_copy_init(dev
, 1);
357 switch (dev_priv
->chipset
) {
364 nv84_crypt_init(dev
);
369 nv98_crypt_init(dev
);
373 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
374 ret
= nouveau_display_create(dev
);
379 /* this call irq_preinstall, register irq handler and
380 * call irq_postinstall
383 ret
= drm_irq_install(dev
);
387 ret
= drm_irq_install(dev
);
393 ret
= drm_vblank_init(dev
, 0);
397 /* what about PVIDEO/PCRTC/PRAMDAC etc? */
399 if (!engine
->graph
.accel_blocked
) {
400 ret
= nouveau_card_init_channel(dev
);
406 ret
= nouveau_backlight_init(dev
);
408 NV_ERROR(dev
, "Error %d registering backlight\n", ret
);
410 dev_priv
->init_state
= NOUVEAU_CARD_INIT_DONE
;
412 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
414 nouveau_fbcon_init(dev
);
418 nouveau_fbcon_init(dev
);
421 drm_kms_helper_poll_init(dev
);
424 NV_INFO(dev
, "Card initialized.\n");
429 if (dev_priv
->channel
) {
430 nouveau_channel_free(dev_priv
->channel
);
431 dev_priv
->channel
= NULL
;
435 drm_irq_uninstall(dev
);
437 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
438 nouveau_display_destroy(dev
);
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;
447 dev_priv
->fifo
->takedown(dev
);
449 engine
->gpio
.takedown(dev
);
451 nv_wr32(dev
, 0x1140, 0);
452 dev_priv
->vm
->takedown(dev
);
454 dev_priv
->chan
->takedown(dev
);
455 nouveau_pm_fini(dev
);
457 pscnv_mem_takedown(dev
);
459 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
460 nouveau_bios_takedown(dev
);
463 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
464 engine
->display
.late_takedown(dev
);
468 vga_client_register(dev
->pdev
, NULL
, NULL
, NULL
);
473 static void nouveau_card_takedown(struct drm_device
*dev
)
475 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
478 NV_DEBUG(dev
, "prev state = %d\n", dev_priv
->init_state
);
480 if (dev_priv
->init_state
== NOUVEAU_CARD_INIT_DONE
) {
481 NV_INFO(dev
, "Stopping card...\n");
482 nouveau_backlight_exit(dev
);
483 drm_irq_uninstall(dev
);
484 flush_workqueue(dev_priv
->wq
);
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;
491 dev_priv
->fifo
->takedown(dev
);
492 dev_priv
->vm
->takedown(dev
);
493 dev_priv
->chan
->takedown(dev
);
494 pscnv_mem_takedown(dev
);
495 nv_wr32(dev
, 0x1140, 0);
496 nouveau_pm_fini(dev
);
497 nouveau_bios_takedown(dev
);
500 vga_client_register(dev
->pdev
, NULL
, NULL
, NULL
);
502 dev_priv
->init_state
= NOUVEAU_CARD_INIT_DOWN
;
503 NV_INFO(dev
, "Card stopped.\n");
507 /* here a client dies, release the stuff that was allocated for its
509 void nouveau_preclose(struct drm_device
*dev
, struct drm_file
*file_priv
)
511 pscnv_chan_cleanup(dev
, file_priv
);
512 pscnv_vspace_cleanup(dev
, file_priv
);
515 /* first module load, setup the mmio/fb mapping */
516 /* KMS: we need mmio at load time, not when the first drm client opens. */
517 int nouveau_firstopen(struct drm_device
*dev
)
519 nouveau_card_init(dev
);
523 /* if we have an OF card, copy vbios to RAMIN */
524 static void nouveau_OF_copy_vbios_to_ramin(struct drm_device
*dev
)
526 #if defined(__powerpc__)
528 const uint32_t *bios
;
529 struct device_node
*dn
= pci_device_to_OF_node(dev
->pdev
);
531 NV_INFO(dev
, "Unable to get the OF node\n");
535 bios
= of_get_property(dn
, "NVDA,BMP", &size
);
537 for (i
= 0; i
< size
; i
+= 4)
538 nv_wi32(dev
, i
, bios
[i
/4]);
539 NV_INFO(dev
, "OF bios successfully copied (%d bytes)\n", size
);
541 NV_INFO(dev
, "Unable to get the OF bios\n");
547 static struct apertures_struct
*nouveau_get_apertures(struct drm_device
*dev
)
549 struct pci_dev
*pdev
= dev
->pdev
;
550 struct apertures_struct
*aper
= alloc_apertures(3);
554 aper
->ranges
[0].base
= pci_resource_start(pdev
, 1);
555 aper
->ranges
[0].size
= pci_resource_len(pdev
, 1);
558 if (pci_resource_len(pdev
, 2)) {
559 aper
->ranges
[aper
->count
].base
= pci_resource_start(pdev
, 2);
560 aper
->ranges
[aper
->count
].size
= pci_resource_len(pdev
, 2);
564 if (pci_resource_len(pdev
, 3)) {
565 aper
->ranges
[aper
->count
].base
= pci_resource_start(pdev
, 3);
566 aper
->ranges
[aper
->count
].size
= pci_resource_len(pdev
, 3);
574 static int nouveau_remove_conflicting_drivers(struct drm_device
*dev
)
577 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
578 bool primary
= false;
579 dev_priv
->apertures
= nouveau_get_apertures(dev
);
580 if (!dev_priv
->apertures
)
584 primary
= dev
->pdev
->resource
[PCI_ROM_RESOURCE
].flags
& IORESOURCE_ROM_SHADOW
;
587 remove_conflicting_framebuffers(dev_priv
->apertures
, "nouveaufb", primary
);
592 int nouveau_load(struct drm_device
*dev
, unsigned long flags
)
594 struct drm_nouveau_private
*dev_priv
;
595 uint32_t reg0
, strap
;
596 resource_size_t mmio_start_offs
;
599 dev_priv
= kzalloc(sizeof(*dev_priv
), GFP_KERNEL
);
602 dev
->dev_private
= dev_priv
;
605 dev_priv
->flags
= flags
/* & NOUVEAU_FLAGS*/;
606 dev_priv
->init_state
= NOUVEAU_CARD_INIT_DOWN
;
608 NV_DEBUG(dev
, "vendor: 0x%X device: 0x%X\n",
609 dev
->pci_vendor
, dev
->pci_device
);
611 dev_priv
->wq
= create_workqueue("nouveau");
615 /* resource 0 is mmio regs */
616 /* resource 1 is linear FB */
617 /* resource 2 is RAMIN (mmio regs + 0x1000000) */
618 /* resource 6 is bios */
620 /* map the mmio regs */
621 mmio_start_offs
= drm_get_resource_start(dev
, 0);
622 ret
= drm_addmap(dev
, mmio_start_offs
, 0x00800000, _DRM_REGISTERS
,
623 _DRM_KERNEL
| _DRM_DRIVER
, &dev_priv
->mmio
);
626 NV_ERROR(dev
, "Unable to initialize the mmio mapping. "
627 "Please report your setup to " DRIVER_EMAIL
"\n");
630 NV_DEBUG(dev
, "regs mapped ok at 0x%llx\n",
631 (unsigned long long)mmio_start_offs
);
634 /* Put the card in BE mode if it's not */
635 if (nv_rd32(dev
, NV03_PMC_BOOT_1
))
636 nv_wr32(dev
, NV03_PMC_BOOT_1
, 0x00000001);
641 /* Time to determine the card architecture */
642 reg0
= nv_rd32(dev
, NV03_PMC_BOOT_0
);
644 /* We're dealing with >=NV10 */
645 if ((reg0
& 0x0f000000) > 0) {
646 /* Bit 27-20 contain the architecture in hex */
647 dev_priv
->chipset
= (reg0
& 0xff00000) >> 20;
649 } else if ((reg0
& 0xff00fff0) == 0x20004000) {
650 if (reg0
& 0x00f00000)
651 dev_priv
->chipset
= 0x05;
653 dev_priv
->chipset
= 0x04;
655 dev_priv
->chipset
= (reg0
& 0xf0000) >> 16;
656 if (dev_priv
->chipset
< 1 || dev_priv
->chipset
> 3)
657 dev_priv
->chipset
= 0xff;
660 switch (dev_priv
->chipset
& 0xf0) {
662 if (dev_priv
->chipset
>= 4)
663 dev_priv
->card_type
= NV_04
;
665 dev_priv
->card_type
= dev_priv
->chipset
;
670 dev_priv
->card_type
= dev_priv
->chipset
& 0xf0;
674 dev_priv
->card_type
= NV_40
;
680 dev_priv
->card_type
= NV_50
;
683 dev_priv
->card_type
= NV_C0
;
686 dev_priv
->card_type
= NV_D0
;
689 NV_INFO(dev
, "Unsupported chipset 0x%08x\n", reg0
);
693 NV_INFO(dev
, "Detected an NV%02x generation card (0x%08x)\n",
694 dev_priv
->card_type
, reg0
);
696 /* determine frequency of timing crystal */
697 strap
= nv_rd32(dev
, 0x101000);
698 if ( dev_priv
->chipset
< 0x17 ||
699 (dev_priv
->chipset
>= 0x20 && dev_priv
->chipset
<= 0x25))
705 case 0x00000000: dev_priv
->crystal
= 13500; break;
706 case 0x00000040: dev_priv
->crystal
= 14318; break;
707 case 0x00400000: dev_priv
->crystal
= 27000; break;
708 case 0x00400040: dev_priv
->crystal
= 25000; break;
711 NV_DEBUG(dev
, "crystal freq: %dKHz\n", dev_priv
->crystal
);
713 dev_priv
->fb_size
= drm_get_resource_len(dev
, 1);
714 dev_priv
->fb_phys
= drm_get_resource_start(dev
, 1);
715 dev_priv
->mmio_phys
= drm_get_resource_start(dev
, 0);
717 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
718 int ret
= nouveau_remove_conflicting_drivers(dev
);
723 /* map larger RAMIN aperture on NV40 cards */
724 if (dev_priv
->card_type
>= NV_40
) {
726 if (drm_get_resource_len(dev
, ramin_bar
) < PAGE_SIZE
)
729 dev_priv
->ramin_size
= drm_get_resource_len(dev
, ramin_bar
);
730 ret
= drm_addmap(dev
, drm_get_resource_start(dev
, ramin_bar
),
731 dev_priv
->ramin_size
, _DRM_REGISTERS
,
732 _DRM_KERNEL
| _DRM_DRIVER
, &dev_priv
->ramin
);
734 NV_ERROR(dev
, "Failed to init RAMIN mapping\n");
739 nouveau_OF_copy_vbios_to_ramin(dev
);
742 if (dev
->pci_device
== 0x01a0)
743 dev_priv
->flags
|= NV_NFORCE
;
744 else if (dev
->pci_device
== 0x01f0)
745 dev_priv
->flags
|= NV_NFORCE2
;
747 /* For kernel modesetting, init card now and bring up fbcon */
748 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
749 int ret
= nouveau_card_init(dev
);
757 static void nouveau_close(struct drm_device
*dev
)
759 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
761 /* In the case of an error dev_priv may not be allocated yet */
763 nouveau_card_takedown(dev
);
766 /* KMS: we need mmio at load time, not when the first drm client opens. */
767 void nouveau_lastclose(struct drm_device
*dev
)
769 if (drm_core_check_feature(dev
, DRIVER_MODESET
))
775 int nouveau_unload(struct drm_device
*dev
)
777 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
779 if (drm_core_check_feature(dev
, DRIVER_MODESET
)) {
780 nouveau_fbcon_fini(dev
);
781 nouveau_display_destroy(dev
);
784 destroy_workqueue(dev_priv
->wq
);
786 drm_rmmap(dev
, dev_priv
->mmio
);
787 drm_rmmap(dev
, dev_priv
->ramin
);
790 dev
->dev_private
= NULL
;
794 /* Wait until (value(reg) & mask) == val, up until timeout has hit */
795 bool nouveau_wait_until(struct drm_device
*dev
, uint64_t timeout
,
796 uint32_t reg
, uint32_t mask
, uint32_t val
)
798 uint64_t start
= nv04_timer_read(dev
);
801 if ((nv_rd32(dev
, reg
) & mask
) == val
)
803 } while (nv04_timer_read(dev
) - start
< timeout
);
808 /* Wait until (value(reg) & mask) != val, up until timeout has hit. */
809 bool nouveau_wait_until_neq(struct drm_device
*dev
, uint64_t timeout
,
810 uint32_t reg
, uint32_t mask
, uint32_t val
)
812 uint64_t start
= nv04_timer_read(dev
);
815 if ((nv_rd32(dev
, reg
) & mask
) != val
)
817 } while (nv04_timer_read(dev
) - start
< timeout
);
823 nouveau_wait_cb(struct drm_device
*dev
, uint64_t timeout
,
824 bool (*cond
)(void *), void *data
)
826 uint64_t start
= nv04_timer_read(dev
);
829 if (cond(data
) == true)
831 } while (nv04_timer_read(dev
) - start
< timeout
);