Commit | Line | Data |
---|---|---|
6ee73861 BS |
1 | /* |
2 | * Copyright © 2007 David Airlie | |
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 (including the next | |
12 | * paragraph) shall be included in all copies or substantial portions of the | |
13 | * Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | * Authors: | |
24 | * David Airlie | |
25 | */ | |
26 | ||
27 | #include <linux/module.h> | |
28 | #include <linux/kernel.h> | |
29 | #include <linux/errno.h> | |
30 | #include <linux/string.h> | |
31 | #include <linux/mm.h> | |
32 | #include <linux/tty.h> | |
6ee73861 BS |
33 | #include <linux/sysrq.h> |
34 | #include <linux/delay.h> | |
6ee73861 BS |
35 | #include <linux/init.h> |
36 | #include <linux/screen_info.h> | |
6a9ee8af | 37 | #include <linux/vga_switcheroo.h> |
cf41d53b | 38 | #include <linux/console.h> |
6ee73861 | 39 | |
760285e7 DH |
40 | #include <drm/drmP.h> |
41 | #include <drm/drm_crtc.h> | |
42 | #include <drm/drm_crtc_helper.h> | |
43 | #include <drm/drm_fb_helper.h> | |
ebb945a9 | 44 | |
4dc28134 | 45 | #include "nouveau_drv.h" |
ebb945a9 BS |
46 | #include "nouveau_gem.h" |
47 | #include "nouveau_bo.h" | |
6ee73861 | 48 | #include "nouveau_fbcon.h" |
ebb945a9 BS |
49 | #include "nouveau_chan.h" |
50 | ||
51 | #include "nouveau_crtc.h" | |
52 | ||
ebb945a9 | 53 | MODULE_PARM_DESC(nofbaccel, "Disable fbcon acceleration"); |
703fa264 | 54 | int nouveau_nofbaccel = 0; |
ebb945a9 | 55 | module_param_named(nofbaccel, nouveau_nofbaccel, int, 0400); |
6ee73861 | 56 | |
ceed5f30 BS |
57 | static void |
58 | nouveau_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect) | |
59 | { | |
ebb945a9 | 60 | struct nouveau_fbdev *fbcon = info->par; |
77145f1c | 61 | struct nouveau_drm *drm = nouveau_drm(fbcon->dev); |
967e7bde | 62 | struct nvif_device *device = &drm->device; |
ceed5f30 BS |
63 | int ret; |
64 | ||
65 | if (info->state != FBINFO_STATE_RUNNING) | |
66 | return; | |
67 | ||
68 | ret = -ENODEV; | |
9acc8100 | 69 | if (!in_interrupt() && !(info->flags & FBINFO_HWACCEL_DISABLED) && |
ebb945a9 | 70 | mutex_trylock(&drm->client.mutex)) { |
967e7bde | 71 | if (device->info.family < NV_DEVICE_INFO_V0_TESLA) |
ceed5f30 BS |
72 | ret = nv04_fbcon_fillrect(info, rect); |
73 | else | |
967e7bde | 74 | if (device->info.family < NV_DEVICE_INFO_V0_FERMI) |
ceed5f30 | 75 | ret = nv50_fbcon_fillrect(info, rect); |
ddbaf79a BS |
76 | else |
77 | ret = nvc0_fbcon_fillrect(info, rect); | |
ebb945a9 | 78 | mutex_unlock(&drm->client.mutex); |
ceed5f30 BS |
79 | } |
80 | ||
81 | if (ret == 0) | |
82 | return; | |
83 | ||
84 | if (ret != -ENODEV) | |
85 | nouveau_fbcon_gpu_lockup(info); | |
b166aeb9 | 86 | drm_fb_helper_cfb_fillrect(info, rect); |
ceed5f30 BS |
87 | } |
88 | ||
89 | static void | |
90 | nouveau_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *image) | |
91 | { | |
ebb945a9 | 92 | struct nouveau_fbdev *fbcon = info->par; |
77145f1c | 93 | struct nouveau_drm *drm = nouveau_drm(fbcon->dev); |
967e7bde | 94 | struct nvif_device *device = &drm->device; |
ceed5f30 BS |
95 | int ret; |
96 | ||
97 | if (info->state != FBINFO_STATE_RUNNING) | |
98 | return; | |
99 | ||
100 | ret = -ENODEV; | |
9acc8100 | 101 | if (!in_interrupt() && !(info->flags & FBINFO_HWACCEL_DISABLED) && |
ebb945a9 | 102 | mutex_trylock(&drm->client.mutex)) { |
967e7bde | 103 | if (device->info.family < NV_DEVICE_INFO_V0_TESLA) |
ceed5f30 BS |
104 | ret = nv04_fbcon_copyarea(info, image); |
105 | else | |
967e7bde | 106 | if (device->info.family < NV_DEVICE_INFO_V0_FERMI) |
ceed5f30 | 107 | ret = nv50_fbcon_copyarea(info, image); |
ddbaf79a BS |
108 | else |
109 | ret = nvc0_fbcon_copyarea(info, image); | |
ebb945a9 | 110 | mutex_unlock(&drm->client.mutex); |
ceed5f30 BS |
111 | } |
112 | ||
113 | if (ret == 0) | |
114 | return; | |
115 | ||
116 | if (ret != -ENODEV) | |
117 | nouveau_fbcon_gpu_lockup(info); | |
b166aeb9 | 118 | drm_fb_helper_cfb_copyarea(info, image); |
ceed5f30 BS |
119 | } |
120 | ||
121 | static void | |
122 | nouveau_fbcon_imageblit(struct fb_info *info, const struct fb_image *image) | |
123 | { | |
ebb945a9 | 124 | struct nouveau_fbdev *fbcon = info->par; |
77145f1c | 125 | struct nouveau_drm *drm = nouveau_drm(fbcon->dev); |
967e7bde | 126 | struct nvif_device *device = &drm->device; |
ceed5f30 BS |
127 | int ret; |
128 | ||
129 | if (info->state != FBINFO_STATE_RUNNING) | |
130 | return; | |
131 | ||
132 | ret = -ENODEV; | |
9acc8100 | 133 | if (!in_interrupt() && !(info->flags & FBINFO_HWACCEL_DISABLED) && |
ebb945a9 | 134 | mutex_trylock(&drm->client.mutex)) { |
967e7bde | 135 | if (device->info.family < NV_DEVICE_INFO_V0_TESLA) |
ceed5f30 BS |
136 | ret = nv04_fbcon_imageblit(info, image); |
137 | else | |
967e7bde | 138 | if (device->info.family < NV_DEVICE_INFO_V0_FERMI) |
ceed5f30 | 139 | ret = nv50_fbcon_imageblit(info, image); |
ddbaf79a BS |
140 | else |
141 | ret = nvc0_fbcon_imageblit(info, image); | |
ebb945a9 | 142 | mutex_unlock(&drm->client.mutex); |
ceed5f30 BS |
143 | } |
144 | ||
145 | if (ret == 0) | |
146 | return; | |
147 | ||
148 | if (ret != -ENODEV) | |
149 | nouveau_fbcon_gpu_lockup(info); | |
b166aeb9 | 150 | drm_fb_helper_cfb_imageblit(info, image); |
ceed5f30 BS |
151 | } |
152 | ||
6ee73861 BS |
153 | static int |
154 | nouveau_fbcon_sync(struct fb_info *info) | |
155 | { | |
ebb945a9 | 156 | struct nouveau_fbdev *fbcon = info->par; |
77145f1c | 157 | struct nouveau_drm *drm = nouveau_drm(fbcon->dev); |
ebb945a9 | 158 | struct nouveau_channel *chan = drm->channel; |
78df3a1c | 159 | int ret; |
6ee73861 | 160 | |
6a6b73f2 | 161 | if (!chan || !chan->accel_done || in_interrupt() || |
6ee73861 BS |
162 | info->state != FBINFO_STATE_RUNNING || |
163 | info->flags & FBINFO_HWACCEL_DISABLED) | |
164 | return 0; | |
165 | ||
ebb945a9 | 166 | if (!mutex_trylock(&drm->client.mutex)) |
9acc8100 BS |
167 | return 0; |
168 | ||
78df3a1c | 169 | ret = nouveau_channel_idle(chan); |
ebb945a9 | 170 | mutex_unlock(&drm->client.mutex); |
6ee73861 | 171 | if (ret) { |
846975a9 | 172 | nouveau_fbcon_gpu_lockup(info); |
6ee73861 BS |
173 | return 0; |
174 | } | |
175 | ||
176 | chan->accel_done = false; | |
177 | return 0; | |
178 | } | |
179 | ||
f231976c BS |
180 | static int |
181 | nouveau_fbcon_open(struct fb_info *info, int user) | |
182 | { | |
183 | struct nouveau_fbdev *fbcon = info->par; | |
184 | struct nouveau_drm *drm = nouveau_drm(fbcon->dev); | |
185 | int ret = pm_runtime_get_sync(drm->dev->dev); | |
186 | if (ret < 0 && ret != -EACCES) | |
187 | return ret; | |
188 | return 0; | |
189 | } | |
190 | ||
191 | static int | |
192 | nouveau_fbcon_release(struct fb_info *info, int user) | |
193 | { | |
194 | struct nouveau_fbdev *fbcon = info->par; | |
195 | struct nouveau_drm *drm = nouveau_drm(fbcon->dev); | |
196 | pm_runtime_put(drm->dev->dev); | |
197 | return 0; | |
198 | } | |
199 | ||
6ee73861 BS |
200 | static struct fb_ops nouveau_fbcon_ops = { |
201 | .owner = THIS_MODULE, | |
f231976c BS |
202 | .fb_open = nouveau_fbcon_open, |
203 | .fb_release = nouveau_fbcon_release, | |
6ee73861 BS |
204 | .fb_check_var = drm_fb_helper_check_var, |
205 | .fb_set_par = drm_fb_helper_set_par, | |
ceed5f30 BS |
206 | .fb_fillrect = nouveau_fbcon_fillrect, |
207 | .fb_copyarea = nouveau_fbcon_copyarea, | |
208 | .fb_imageblit = nouveau_fbcon_imageblit, | |
6ee73861 BS |
209 | .fb_sync = nouveau_fbcon_sync, |
210 | .fb_pan_display = drm_fb_helper_pan_display, | |
211 | .fb_blank = drm_fb_helper_blank, | |
212 | .fb_setcmap = drm_fb_helper_setcmap, | |
be64c2bb CB |
213 | .fb_debug_enter = drm_fb_helper_debug_enter, |
214 | .fb_debug_leave = drm_fb_helper_debug_leave, | |
6ee73861 BS |
215 | }; |
216 | ||
ceed5f30 | 217 | static struct fb_ops nouveau_fbcon_sw_ops = { |
126b5440 | 218 | .owner = THIS_MODULE, |
f231976c BS |
219 | .fb_open = nouveau_fbcon_open, |
220 | .fb_release = nouveau_fbcon_release, | |
126b5440 MK |
221 | .fb_check_var = drm_fb_helper_check_var, |
222 | .fb_set_par = drm_fb_helper_set_par, | |
b166aeb9 AT |
223 | .fb_fillrect = drm_fb_helper_cfb_fillrect, |
224 | .fb_copyarea = drm_fb_helper_cfb_copyarea, | |
225 | .fb_imageblit = drm_fb_helper_cfb_imageblit, | |
126b5440 MK |
226 | .fb_pan_display = drm_fb_helper_pan_display, |
227 | .fb_blank = drm_fb_helper_blank, | |
228 | .fb_setcmap = drm_fb_helper_setcmap, | |
be64c2bb CB |
229 | .fb_debug_enter = drm_fb_helper_debug_enter, |
230 | .fb_debug_leave = drm_fb_helper_debug_leave, | |
126b5440 MK |
231 | }; |
232 | ||
4b5098f3 BS |
233 | void |
234 | nouveau_fbcon_accel_save_disable(struct drm_device *dev) | |
235 | { | |
236 | struct nouveau_drm *drm = nouveau_drm(dev); | |
237 | if (drm->fbcon) { | |
238 | drm->fbcon->saved_flags = drm->fbcon->helper.fbdev->flags; | |
239 | drm->fbcon->helper.fbdev->flags |= FBINFO_HWACCEL_DISABLED; | |
240 | } | |
241 | } | |
242 | ||
243 | void | |
244 | nouveau_fbcon_accel_restore(struct drm_device *dev) | |
245 | { | |
246 | struct nouveau_drm *drm = nouveau_drm(dev); | |
247 | if (drm->fbcon) { | |
248 | drm->fbcon->helper.fbdev->flags = drm->fbcon->saved_flags; | |
249 | } | |
250 | } | |
251 | ||
e715396a | 252 | static void |
4b5098f3 BS |
253 | nouveau_fbcon_accel_fini(struct drm_device *dev) |
254 | { | |
255 | struct nouveau_drm *drm = nouveau_drm(dev); | |
256 | struct nouveau_fbdev *fbcon = drm->fbcon; | |
257 | if (fbcon && drm->channel) { | |
258 | console_lock(); | |
259 | fbcon->helper.fbdev->flags |= FBINFO_HWACCEL_DISABLED; | |
260 | console_unlock(); | |
261 | nouveau_channel_idle(drm->channel); | |
0ad72863 BS |
262 | nvif_object_fini(&fbcon->twod); |
263 | nvif_object_fini(&fbcon->blit); | |
264 | nvif_object_fini(&fbcon->gdi); | |
265 | nvif_object_fini(&fbcon->patt); | |
266 | nvif_object_fini(&fbcon->rop); | |
267 | nvif_object_fini(&fbcon->clip); | |
268 | nvif_object_fini(&fbcon->surf2d); | |
4b5098f3 BS |
269 | } |
270 | } | |
271 | ||
e715396a | 272 | static void |
4b5098f3 BS |
273 | nouveau_fbcon_accel_init(struct drm_device *dev) |
274 | { | |
275 | struct nouveau_drm *drm = nouveau_drm(dev); | |
276 | struct nouveau_fbdev *fbcon = drm->fbcon; | |
277 | struct fb_info *info = fbcon->helper.fbdev; | |
278 | int ret; | |
279 | ||
967e7bde | 280 | if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) |
4b5098f3 BS |
281 | ret = nv04_fbcon_accel_init(info); |
282 | else | |
967e7bde | 283 | if (drm->device.info.family < NV_DEVICE_INFO_V0_FERMI) |
4b5098f3 BS |
284 | ret = nv50_fbcon_accel_init(info); |
285 | else | |
286 | ret = nvc0_fbcon_accel_init(info); | |
287 | ||
288 | if (ret == 0) | |
289 | info->fbops = &nouveau_fbcon_ops; | |
290 | } | |
291 | ||
6ee73861 BS |
292 | static void nouveau_fbcon_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
293 | u16 blue, int regno) | |
294 | { | |
295 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); | |
296 | ||
297 | nv_crtc->lut.r[regno] = red; | |
298 | nv_crtc->lut.g[regno] = green; | |
299 | nv_crtc->lut.b[regno] = blue; | |
300 | } | |
301 | ||
302 | static void nouveau_fbcon_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, | |
303 | u16 *blue, int regno) | |
304 | { | |
305 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); | |
306 | ||
307 | *red = nv_crtc->lut.r[regno]; | |
308 | *green = nv_crtc->lut.g[regno]; | |
309 | *blue = nv_crtc->lut.b[regno]; | |
310 | } | |
311 | ||
38651674 | 312 | static void |
ebb945a9 | 313 | nouveau_fbcon_zfill(struct drm_device *dev, struct nouveau_fbdev *fbcon) |
6ee73861 | 314 | { |
ebb945a9 | 315 | struct fb_info *info = fbcon->helper.fbdev; |
6ee73861 BS |
316 | struct fb_fillrect rect; |
317 | ||
318 | /* Clear the entire fbcon. The drm will program every connector | |
319 | * with it's preferred mode. If the sizes differ, one display will | |
320 | * quite likely have garbage around the console. | |
321 | */ | |
322 | rect.dx = rect.dy = 0; | |
323 | rect.width = info->var.xres_virtual; | |
324 | rect.height = info->var.yres_virtual; | |
325 | rect.color = 0; | |
326 | rect.rop = ROP_COPY; | |
327 | info->fbops->fb_fillrect(info, &rect); | |
328 | } | |
329 | ||
330 | static int | |
cd5428a5 | 331 | nouveau_fbcon_create(struct drm_fb_helper *helper, |
8be48d92 | 332 | struct drm_fb_helper_surface_size *sizes) |
6ee73861 | 333 | { |
918b7ed4 FF |
334 | struct nouveau_fbdev *fbcon = |
335 | container_of(helper, struct nouveau_fbdev, helper); | |
ebb945a9 | 336 | struct drm_device *dev = fbcon->dev; |
77145f1c | 337 | struct nouveau_drm *drm = nouveau_drm(dev); |
967e7bde | 338 | struct nvif_device *device = &drm->device; |
6ee73861 | 339 | struct fb_info *info; |
6ee73861 BS |
340 | struct drm_framebuffer *fb; |
341 | struct nouveau_framebuffer *nouveau_fb; | |
45143cb5 | 342 | struct nouveau_channel *chan; |
6ee73861 | 343 | struct nouveau_bo *nvbo; |
308e5bcb | 344 | struct drm_mode_fb_cmd2 mode_cmd; |
6ee73861 BS |
345 | int size, ret; |
346 | ||
38651674 DA |
347 | mode_cmd.width = sizes->surface_width; |
348 | mode_cmd.height = sizes->surface_height; | |
6ee73861 | 349 | |
308e5bcb JB |
350 | mode_cmd.pitches[0] = mode_cmd.width * (sizes->surface_bpp >> 3); |
351 | mode_cmd.pitches[0] = roundup(mode_cmd.pitches[0], 256); | |
6ee73861 | 352 | |
308e5bcb JB |
353 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
354 | sizes->surface_depth); | |
355 | ||
356 | size = mode_cmd.pitches[0] * mode_cmd.height; | |
1c7059e4 | 357 | size = roundup(size, PAGE_SIZE); |
6ee73861 | 358 | |
f6d4e621 BS |
359 | ret = nouveau_gem_new(dev, size, 0, NOUVEAU_GEM_DOMAIN_VRAM, |
360 | 0, 0x0000, &nvbo); | |
6ee73861 | 361 | if (ret) { |
ebb945a9 | 362 | NV_ERROR(drm, "failed to allocate framebuffer\n"); |
6ee73861 BS |
363 | goto out; |
364 | } | |
365 | ||
ad76b3f7 | 366 | ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_VRAM, false); |
6ee73861 | 367 | if (ret) { |
ebb945a9 | 368 | NV_ERROR(drm, "failed to pin fb: %d\n", ret); |
1e2bd5f5 | 369 | goto out_unref; |
6ee73861 BS |
370 | } |
371 | ||
372 | ret = nouveau_bo_map(nvbo); | |
373 | if (ret) { | |
ebb945a9 | 374 | NV_ERROR(drm, "failed to map fb: %d\n", ret); |
1e2bd5f5 | 375 | goto out_unpin; |
6ee73861 BS |
376 | } |
377 | ||
ebb945a9 | 378 | chan = nouveau_nofbaccel ? NULL : drm->channel; |
967e7bde | 379 | if (chan && device->info.family >= NV_DEVICE_INFO_V0_TESLA) { |
0ad72863 | 380 | ret = nouveau_bo_vma_add(nvbo, drm->client.vm, |
ebb945a9 | 381 | &fbcon->nouveau_fb.vma); |
45143cb5 | 382 | if (ret) { |
ebb945a9 | 383 | NV_ERROR(drm, "failed to map fb into chan: %d\n", ret); |
45143cb5 BS |
384 | chan = NULL; |
385 | } | |
386 | } | |
387 | ||
b166aeb9 AT |
388 | info = drm_fb_helper_alloc_fbi(helper); |
389 | if (IS_ERR(info)) { | |
390 | ret = PTR_ERR(info); | |
1e2bd5f5 | 391 | goto out_unlock; |
6ee73861 | 392 | } |
4dc63933 | 393 | info->skip_vt_switch = 1; |
6ee73861 | 394 | |
ebb945a9 | 395 | info->par = fbcon; |
38651674 | 396 | |
ebb945a9 | 397 | nouveau_framebuffer_init(dev, &fbcon->nouveau_fb, &mode_cmd, nvbo); |
38651674 | 398 | |
ebb945a9 | 399 | nouveau_fb = &fbcon->nouveau_fb; |
8be48d92 | 400 | fb = &nouveau_fb->base; |
38651674 | 401 | |
8be48d92 | 402 | /* setup helper */ |
ebb945a9 | 403 | fbcon->helper.fb = fb; |
6ee73861 BS |
404 | |
405 | strcpy(info->fix.id, "nouveaufb"); | |
1e2bd5f5 | 406 | if (!chan) |
a32ed69d MK |
407 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_DISABLED; |
408 | else | |
409 | info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA | | |
410 | FBINFO_HWACCEL_FILLRECT | | |
411 | FBINFO_HWACCEL_IMAGEBLIT; | |
8fd4bd22 | 412 | info->flags |= FBINFO_CAN_FORCE_OUTPUT; |
ceed5f30 | 413 | info->fbops = &nouveau_fbcon_sw_ops; |
f01a9720 BS |
414 | info->fix.smem_start = nvbo->bo.mem.bus.base + |
415 | nvbo->bo.mem.bus.offset; | |
6ee73861 BS |
416 | info->fix.smem_len = size; |
417 | ||
418 | info->screen_base = nvbo_kmap_obj_iovirtual(nouveau_fb->nvbo); | |
419 | info->screen_size = size; | |
420 | ||
01f2c773 | 421 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
ebb945a9 | 422 | drm_fb_helper_fill_var(info, &fbcon->helper, sizes->fb_width, sizes->fb_height); |
1471ca9a | 423 | |
fb2a99e1 | 424 | /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */ |
6ee73861 | 425 | |
4b5098f3 BS |
426 | if (chan) |
427 | nouveau_fbcon_accel_init(dev); | |
ebb945a9 | 428 | nouveau_fbcon_zfill(dev, fbcon); |
6ee73861 BS |
429 | |
430 | /* To allow resizeing without swapping buffers */ | |
54c4cd68 | 431 | NV_INFO(drm, "allocated %dx%d fb: 0x%llx, bo %p\n", |
ebb945a9 BS |
432 | nouveau_fb->base.width, nouveau_fb->base.height, |
433 | nvbo->bo.offset, nvbo); | |
6ee73861 | 434 | |
6a9ee8af | 435 | vga_switcheroo_client_fb_set(dev->pdev, info); |
6ee73861 BS |
436 | return 0; |
437 | ||
1e2bd5f5 | 438 | out_unlock: |
1e2bd5f5 ML |
439 | if (chan) |
440 | nouveau_bo_vma_del(nvbo, &fbcon->nouveau_fb.vma); | |
fdfb8332 | 441 | nouveau_bo_unmap(nvbo); |
1e2bd5f5 ML |
442 | out_unpin: |
443 | nouveau_bo_unpin(nvbo); | |
444 | out_unref: | |
445 | nouveau_bo_ref(NULL, &nvbo); | |
6ee73861 BS |
446 | out: |
447 | return ret; | |
448 | } | |
449 | ||
eb1f8e4f DA |
450 | void |
451 | nouveau_fbcon_output_poll_changed(struct drm_device *dev) | |
6ee73861 | 452 | { |
77145f1c | 453 | struct nouveau_drm *drm = nouveau_drm(dev); |
8a258353 ML |
454 | if (drm->fbcon) |
455 | drm_fb_helper_hotplug_event(&drm->fbcon->helper); | |
6ee73861 BS |
456 | } |
457 | ||
6e86e041 | 458 | static int |
ebb945a9 | 459 | nouveau_fbcon_destroy(struct drm_device *dev, struct nouveau_fbdev *fbcon) |
6ee73861 | 460 | { |
ebb945a9 | 461 | struct nouveau_framebuffer *nouveau_fb = &fbcon->nouveau_fb; |
6ee73861 | 462 | |
b166aeb9 AT |
463 | drm_fb_helper_unregister_fbi(&fbcon->helper); |
464 | drm_fb_helper_release_fbi(&fbcon->helper); | |
6ee73861 | 465 | |
8be48d92 | 466 | if (nouveau_fb->nvbo) { |
6ee73861 | 467 | nouveau_bo_unmap(nouveau_fb->nvbo); |
45143cb5 | 468 | nouveau_bo_vma_del(nouveau_fb->nvbo, &nouveau_fb->vma); |
1e2bd5f5 | 469 | nouveau_bo_unpin(nouveau_fb->nvbo); |
55fb74ad | 470 | drm_gem_object_unreference_unlocked(&nouveau_fb->nvbo->gem); |
6ee73861 | 471 | nouveau_fb->nvbo = NULL; |
6ee73861 | 472 | } |
ebb945a9 | 473 | drm_fb_helper_fini(&fbcon->helper); |
36206361 | 474 | drm_framebuffer_unregister_private(&nouveau_fb->base); |
38651674 | 475 | drm_framebuffer_cleanup(&nouveau_fb->base); |
6ee73861 BS |
476 | return 0; |
477 | } | |
846975a9 MS |
478 | |
479 | void nouveau_fbcon_gpu_lockup(struct fb_info *info) | |
480 | { | |
ebb945a9 | 481 | struct nouveau_fbdev *fbcon = info->par; |
77145f1c | 482 | struct nouveau_drm *drm = nouveau_drm(fbcon->dev); |
846975a9 | 483 | |
ebb945a9 | 484 | NV_ERROR(drm, "GPU lockup - switching to software fbcon\n"); |
846975a9 MS |
485 | info->flags |= FBINFO_HWACCEL_DISABLED; |
486 | } | |
38651674 | 487 | |
3a493879 | 488 | static const struct drm_fb_helper_funcs nouveau_fbcon_helper_funcs = { |
4abe3520 DA |
489 | .gamma_set = nouveau_fbcon_gamma_set, |
490 | .gamma_get = nouveau_fbcon_gamma_get, | |
cd5428a5 | 491 | .fb_probe = nouveau_fbcon_create, |
4abe3520 DA |
492 | }; |
493 | ||
7bb6d442 BS |
494 | void |
495 | nouveau_fbcon_set_suspend(struct drm_device *dev, int state) | |
496 | { | |
497 | struct nouveau_drm *drm = nouveau_drm(dev); | |
498 | if (drm->fbcon) { | |
7bb6d442 | 499 | console_lock(); |
4dc63933 ML |
500 | if (state == FBINFO_STATE_RUNNING) |
501 | nouveau_fbcon_accel_restore(dev); | |
b166aeb9 | 502 | drm_fb_helper_set_suspend(&drm->fbcon->helper, state); |
4dc63933 ML |
503 | if (state != FBINFO_STATE_RUNNING) |
504 | nouveau_fbcon_accel_save_disable(dev); | |
7bb6d442 BS |
505 | console_unlock(); |
506 | } | |
507 | } | |
508 | ||
ebb945a9 BS |
509 | int |
510 | nouveau_fbcon_init(struct drm_device *dev) | |
38651674 | 511 | { |
77145f1c | 512 | struct nouveau_drm *drm = nouveau_drm(dev); |
ebb945a9 | 513 | struct nouveau_fbdev *fbcon; |
1e482f75 | 514 | int preferred_bpp; |
5a79395b | 515 | int ret; |
8be48d92 | 516 | |
fc162088 BS |
517 | if (!dev->mode_config.num_crtc || |
518 | (dev->pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) | |
ebb945a9 BS |
519 | return 0; |
520 | ||
521 | fbcon = kzalloc(sizeof(struct nouveau_fbdev), GFP_KERNEL); | |
522 | if (!fbcon) | |
8be48d92 DA |
523 | return -ENOMEM; |
524 | ||
ebb945a9 BS |
525 | fbcon->dev = dev; |
526 | drm->fbcon = fbcon; | |
10a23102 TR |
527 | |
528 | drm_fb_helper_prepare(dev, &fbcon->helper, &nouveau_fbcon_helper_funcs); | |
8be48d92 | 529 | |
ebb945a9 | 530 | ret = drm_fb_helper_init(dev, &fbcon->helper, |
9bd0c15f | 531 | dev->mode_config.num_crtc, 4); |
01934c2a TR |
532 | if (ret) |
533 | goto free; | |
5a79395b | 534 | |
01934c2a TR |
535 | ret = drm_fb_helper_single_add_all_connectors(&fbcon->helper); |
536 | if (ret) | |
537 | goto fini; | |
1e482f75 | 538 | |
f392ec4b | 539 | if (drm->device.info.ram_size <= 32 * 1024 * 1024) |
1e482f75 | 540 | preferred_bpp = 8; |
ebb945a9 | 541 | else |
f392ec4b | 542 | if (drm->device.info.ram_size <= 64 * 1024 * 1024) |
1e482f75 MS |
543 | preferred_bpp = 16; |
544 | else | |
545 | preferred_bpp = 32; | |
546 | ||
76a39dbf DV |
547 | /* disable all the possible outputs/crtcs before entering KMS mode */ |
548 | drm_helper_disable_unused_functions(dev); | |
549 | ||
01934c2a TR |
550 | ret = drm_fb_helper_initial_config(&fbcon->helper, preferred_bpp); |
551 | if (ret) | |
552 | goto fini; | |
553 | ||
52dfcc5c DT |
554 | if (fbcon->helper.fbdev) |
555 | fbcon->helper.fbdev->pixmap.buf_align = 4; | |
38651674 | 556 | return 0; |
01934c2a TR |
557 | |
558 | fini: | |
559 | drm_fb_helper_fini(&fbcon->helper); | |
560 | free: | |
561 | kfree(fbcon); | |
562 | return ret; | |
38651674 DA |
563 | } |
564 | ||
ebb945a9 BS |
565 | void |
566 | nouveau_fbcon_fini(struct drm_device *dev) | |
38651674 | 567 | { |
77145f1c | 568 | struct nouveau_drm *drm = nouveau_drm(dev); |
8be48d92 | 569 | |
ebb945a9 | 570 | if (!drm->fbcon) |
8be48d92 DA |
571 | return; |
572 | ||
4b5098f3 | 573 | nouveau_fbcon_accel_fini(dev); |
ebb945a9 BS |
574 | nouveau_fbcon_destroy(dev, drm->fbcon); |
575 | kfree(drm->fbcon); | |
576 | drm->fbcon = NULL; | |
38651674 | 577 | } |