diff options
author | Ben Skeggs <bskeggs@redhat.com> | 2009-03-09 10:56:01 +1000 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2009-03-09 10:58:57 +1000 |
commit | fa73fa68896b2c2656dd9bee1a818afc294232f0 (patch) | |
tree | e5cef8c6aa3f3f21ae0491b0fa3951399aa6b9f2 | |
parent | f158b0253b13d2616c8017f4c357be48da36694a (diff) |
nouveau: big rewrite of nv50 kms code
This is a essentially a big squash merge from the kernel tree I've been
working in, sorry about the loss of history, but commiting each patch
individually would've taken quite a while to do.
The nv50 kms code now uses the helpers in the drm, simplifying the
code greatly.
The code is far more stable than previously on all the G8x cards I've
been able to test on, but there's likely still bugs to be ironed out!
-rw-r--r-- | linux-core/Makefile.kernel | 6 | ||||
-rw-r--r-- | linux-core/nouveau_connector.h | 52 | ||||
-rw-r--r-- | linux-core/nouveau_crtc.h | 59 | ||||
-rw-r--r-- | linux-core/nouveau_display.c | 108 | ||||
-rw-r--r-- | linux-core/nouveau_dma.h | 2 | ||||
-rw-r--r-- | linux-core/nouveau_drv.c | 5 | ||||
-rw-r--r-- | linux-core/nouveau_encoder.h | 44 | ||||
-rw-r--r-- | linux-core/nouveau_fb.h | 44 | ||||
-rw-r--r-- | linux-core/nouveau_fbcon.c | 945 | ||||
-rw-r--r-- | linux-core/nouveau_fbcon.h (renamed from linux-core/nv50_fbcon.h) | 21 | ||||
-rw-r--r-- | linux-core/nv50_connector.c | 615 | ||||
-rw-r--r-- | linux-core/nv50_crtc.c | 1038 | ||||
-rw-r--r-- | linux-core/nv50_cursor.c | 93 | ||||
-rw-r--r-- | linux-core/nv50_cursor.h | 21 | ||||
-rw-r--r-- | linux-core/nv50_dac.c | 270 | ||||
-rw-r--r-- | linux-core/nv50_display.c | 302 | ||||
-rw-r--r-- | linux-core/nv50_display.h | 24 | ||||
-rw-r--r-- | linux-core/nv50_fbcon.c | 752 | ||||
-rw-r--r-- | linux-core/nv50_fbcon_accel.c | 216 | ||||
-rw-r--r-- | linux-core/nv50_i2c.c | 2 | ||||
-rw-r--r-- | linux-core/nv50_sor.c | 258 | ||||
-rw-r--r-- | shared-core/nouveau_irq.c | 73 | ||||
-rw-r--r-- | shared-core/nouveau_state.c | 10 |
23 files changed, 2648 insertions, 2312 deletions
diff --git a/linux-core/Makefile.kernel b/linux-core/Makefile.kernel index c25ae7c3..4fd21f55 100644 --- a/linux-core/Makefile.kernel +++ b/linux-core/Makefile.kernel @@ -38,9 +38,9 @@ nouveau-objs := nouveau_drv.o nouveau_state.o nouveau_fifo.o nouveau_mem.o \ nv04_graph.o nv10_graph.o nv20_graph.o \ nv40_graph.o nv50_graph.o \ nv04_instmem.o nv50_instmem.o \ - nouveau_bios.o \ - nv50_crtc.o nv50_cursor.o nv50_lut.o nv50_sor.o nv50_dac.o nv50_connector.o nv50_i2c.o nv50_display.o \ - nv50_fbcon.o nv50_fbcon_accel.o + nouveau_bios.o nouveau_display.o nouveau_fbcon.o \ + nv50_display.o nv50_connector.o nv50_sor.o nv50_dac.o \ + nv50_crtc.o nv50_cursor.o nv50_i2c.o nv50_fbcon.o radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o r300_cmdbuf.o radeon_gem.o \ radeon_buffer.o radeon_fence.o atom.o radeon_display.o radeon_atombios.o radeon_i2c.o radeon_connectors.o radeon_cs.o \ atombios_crtc.o radeon_encoders.o radeon_fb.o radeon_combios.o radeon_legacy_crtc.o radeon_legacy_encoders.o \ diff --git a/linux-core/nouveau_connector.h b/linux-core/nouveau_connector.h new file mode 100644 index 00000000..4259eb3c --- /dev/null +++ b/linux-core/nouveau_connector.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2008 Maarten Maathuis. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef __NOUVEAU_CONNECTOR_H__ +#define __NOUVEAU_CONNECTOR_H__ + +#include "nv50_i2c.h" + +struct nouveau_connector { + struct drm_connector base; + + struct drm_display_mode *native_mode; + bool digital; + + int bus; + struct nv50_i2c_channel *i2c_chan; + + int scaling_mode; + + bool use_dithering; + + struct nouveau_encoder *(*to_encoder) (struct nouveau_connector *connector, bool digital); +}; +#define to_nouveau_connector(x) container_of((x), struct nouveau_connector, base) + +int nv50_connector_create(struct drm_device *dev, int bus, int i2c_index, int type); +void nv50_connector_detect_all(struct drm_device *dev); + +#endif /* __NOUVEAU_CONNECTOR_H__ */ diff --git a/linux-core/nouveau_crtc.h b/linux-core/nouveau_crtc.h new file mode 100644 index 00000000..0ba94756 --- /dev/null +++ b/linux-core/nouveau_crtc.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2008 Maarten Maathuis. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef __NOUVEAU_CRTC_H__ +#define __NOUVEAU_CRTC_H__ + +struct nouveau_crtc { + struct drm_crtc base; + + int index; + + struct drm_mode_set mode_set; + + struct drm_display_mode *mode; + bool use_dithering; + + struct nv50_cursor *cursor; + struct { + struct mem_block *mem; + uint16_t r[256]; + uint16_t g[256]; + uint16_t b[256]; + int depth; + } lut; + + int (*set_dither) (struct nouveau_crtc *crtc); + int (*set_scale) (struct nouveau_crtc *crtc, int mode, bool update); + int (*set_clock) (struct nouveau_crtc *crtc, struct drm_display_mode *); + int (*set_clock_mode) (struct nouveau_crtc *crtc); + int (*destroy) (struct nouveau_crtc *crtc); +}; +#define to_nouveau_crtc(x) container_of((x), struct nouveau_crtc, base) + +int nv50_crtc_create(struct drm_device *dev, int index); + +#endif /* __NOUVEAU_CRTC_H__ */ diff --git a/linux-core/nouveau_display.c b/linux-core/nouveau_display.c new file mode 100644 index 00000000..5636bdda --- /dev/null +++ b/linux-core/nouveau_display.c @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2008 Maarten Maathuis. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include "drmP.h" +#include "drm_crtc_helper.h" +#include "nouveau_fb.h" +#include "nouveau_fbcon.h" + +static void +nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb) +{ + struct nouveau_framebuffer *fb = to_nouveau_framebuffer(drm_fb); + struct drm_device *dev = drm_fb->dev; + + if (drm_fb->fbdev) + nouveau_fbcon_remove(dev, drm_fb); + + if (fb->gem) { + mutex_lock(&dev->struct_mutex); + drm_gem_object_unreference(fb->gem); + mutex_unlock(&dev->struct_mutex); + } + + drm_framebuffer_cleanup(drm_fb); + kfree(fb); +} + +static int +nouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb, + struct drm_file *file_priv, + unsigned int *handle) +{ + struct nouveau_framebuffer *fb = to_nouveau_framebuffer(drm_fb); + + return drm_gem_handle_create(file_priv, fb->gem, handle); +} + +static const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = { + .destroy = nouveau_user_framebuffer_destroy, + .create_handle = nouveau_user_framebuffer_create_handle, +}; + +struct drm_framebuffer * +nouveau_framebuffer_create(struct drm_device *dev, struct drm_gem_object *gem, + struct drm_mode_fb_cmd *mode_cmd) +{ + struct nouveau_framebuffer *fb; + + fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL); + if (!fb) + return NULL; + + drm_framebuffer_init(dev, &fb->base, &nouveau_framebuffer_funcs); + drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd); + + fb->gem = gem; + return &fb->base; +} + +static struct drm_framebuffer * +nouveau_user_framebuffer_create(struct drm_device *dev, + struct drm_file *file_priv, + struct drm_mode_fb_cmd *mode_cmd) +{ + struct drm_framebuffer *fb; + struct drm_gem_object *gem; + + gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle); + if (!gem) + return NULL; + + fb = nouveau_framebuffer_create(dev, gem, mode_cmd); + if (!fb) { + drm_gem_object_unreference(gem); + return NULL; + } + + return fb; +} + +const struct drm_mode_config_funcs nouveau_mode_config_funcs = { + .fb_create = nouveau_user_framebuffer_create, + .fb_changed = nouveau_fbcon_probe, +}; + diff --git a/linux-core/nouveau_dma.h b/linux-core/nouveau_dma.h index 0d21609f..66d567fb 100644 --- a/linux-core/nouveau_dma.h +++ b/linux-core/nouveau_dma.h @@ -99,7 +99,7 @@ FIRE_RING(struct nouveau_channel *chan) /* This should allow easy switching to a real fifo in the future. */ #define OUT_MODE(mthd, val) do { \ - nv50_display_command(dev_priv, mthd, val); \ + nv50_display_command(dev, mthd, val); \ } while(0) #endif diff --git a/linux-core/nouveau_drv.c b/linux-core/nouveau_drv.c index 2aca7536..8b0abf08 100644 --- a/linux-core/nouveau_drv.c +++ b/linux-core/nouveau_drv.c @@ -31,9 +31,12 @@ int nouveau_mm_enabled = 0; module_param_named(mm_enabled, nouveau_mm_enabled, int, 0400); -unsigned int nouveau_modeset = 0; /* kms */ +int nouveau_modeset = 0; /* kms */ module_param_named(modeset, nouveau_modeset, int, 0400); +int nouveau_fbpercrtc = 0; +module_param_named(fbpercrtc, nouveau_fbpercrtc, int, 0400); + static struct pci_device_id pciidlist[] = { { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID), diff --git a/linux-core/nouveau_encoder.h b/linux-core/nouveau_encoder.h new file mode 100644 index 00000000..36fcf3ff --- /dev/null +++ b/linux-core/nouveau_encoder.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2008 Maarten Maathuis. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef __NOUVEAU_OUTPUT_H__ +#define __NOUVEAU_OUTPUT_H__ + +struct nouveau_encoder { + struct drm_encoder base; + + struct dcb_entry *dcb_entry; + int or; + + int (*set_clock_mode) (struct nouveau_encoder *encoder, + struct drm_display_mode *mode); +}; +#define to_nouveau_encoder(x) container_of((x), struct nouveau_encoder, base) + +int nv50_sor_create(struct drm_device *dev, struct dcb_entry *entry); +int nv50_dac_create(struct drm_device *dev, struct dcb_entry *entry); + +#endif /* __NOUVEAU_OUTPUT_H__ */ diff --git a/linux-core/nouveau_fb.h b/linux-core/nouveau_fb.h new file mode 100644 index 00000000..88ffdc0a --- /dev/null +++ b/linux-core/nouveau_fb.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2008 Maarten Maathuis. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef __NOUVEAU_FB_H__ +#define __NOUVEAU_FB_H__ + +struct nouveau_framebuffer { + struct drm_framebuffer base; + struct drm_gem_object *gem; + struct drm_bo_kmap_obj kmap; +}; + +#define to_nouveau_framebuffer(x) container_of((x), struct nouveau_framebuffer, base) + +extern const struct drm_mode_config_funcs nouveau_mode_config_funcs; + +struct drm_framebuffer * +nouveau_framebuffer_create(struct drm_device *, struct drm_gem_object *, + struct drm_mode_fb_cmd *); + +#endif /* __NOUVEAU_FB_H__ */ diff --git a/linux-core/nouveau_fbcon.c b/linux-core/nouveau_fbcon.c new file mode 100644 index 00000000..6c9db9e8 --- /dev/null +++ b/linux-core/nouveau_fbcon.c @@ -0,0 +1,945 @@ +/* + * Copyright © 2007 David Airlie + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Authors: + * David Airlie + */ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/errno.h> +#include <linux/string.h> +#include <linux/mm.h> +#include <linux/tty.h> +#include <linux/slab.h> +#include <linux/sysrq.h> +#include <linux/delay.h> +#include <linux/fb.h> +#include <linux/init.h> + +#include "drmP.h" +#include "drm.h" +#include "drm_crtc.h" +#include "drm_crtc_helper.h" +#include "nouveau_drv.h" +#include "nouveau_drm.h" +#include "nouveau_crtc.h" +#include "nouveau_fb.h" +#include "nouveau_fbcon.h" + +extern int nouveau_fbpercrtc; + +static int nouveau_fbcon_setcolreg(unsigned regno, unsigned red, unsigned green, + unsigned blue, unsigned transp, + struct fb_info *info) +{ + struct nouveau_fbcon_par *par = info->par; + struct drm_device *dev = par->dev; + struct drm_crtc *crtc; + int i; + + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + struct nouveau_crtc *nouveau_crtc = to_nouveau_crtc(crtc); + struct drm_mode_set *modeset = &nouveau_crtc->mode_set; + struct drm_framebuffer *fb = modeset->fb; + + for (i = 0; i < par->crtc_count; i++) + if (crtc->base.id == par->crtc_ids[i]) + break; + + if (i == par->crtc_count) + continue; + + + if (regno > 255) + return 1; + + if (fb->depth == 8) { + /* TODO */ + } + + if (regno < 16) { + switch (fb->depth) { + case 15: + fb->pseudo_palette[regno] = ((red & 0xf800) >> 1) | + ((green & 0xf800) >> 6) | + ((blue & 0xf800) >> 11); + break; + case 16: + fb->pseudo_palette[regno] = (red & 0xf800) | + ((green & 0xfc00) >> 5) | + ((blue & 0xf800) >> 11); + break; + case 24: + case 32: + fb->pseudo_palette[regno] = ((red & 0xff00) << 8) | + (green & 0xff00) | + ((blue & 0xff00) >> 8); + break; + } + } + } + return 0; +} + +static int nouveau_fbcon_check_var(struct fb_var_screeninfo *var, + struct fb_info *info) +{ + struct nouveau_fbcon_par *par = info->par; + struct nouveau_framebuffer *nouveau_fb = par->nouveau_fb; + struct drm_framebuffer *fb = &nouveau_fb->base; + int depth; + + if (var->pixclock == -1 || !var->pixclock) + return -EINVAL; + + /* Need to resize the fb object !!! */ + if (var->xres > fb->width || var->yres > fb->height) { + DRM_ERROR("Requested width/height is greater than current fb object %dx%d > %dx%d\n",var->xres,var->yres,fb->width,fb->height); + DRM_ERROR("Need resizing code.\n"); + return -EINVAL; + } + + switch (var->bits_per_pixel) { + case 16: + depth = (var->green.length == 6) ? 16 : 15; + break; + case 32: + depth = (var->transp.length > 0) ? 32 : 24; + break; + default: + depth = var->bits_per_pixel; + break; + } + + switch (depth) { + case 8: + var->red.offset = 0; + var->green.offset = 0; + var->blue.offset = 0; + var->red.length = 8; + var->green.length = 8; + var->blue.length = 8; + var->transp.length = 0; + var->transp.offset = 0; + break; + case 15: + var->red.offset = 10; + var->green.offset = 5; + var->blue.offset = 0; + var->red.length = 5; + var->green.length = 5; + var->blue.length = 5; + var->transp.length = 1; + var->transp.offset = 15; + break; + case 16: + var->red.offset = 11; + var->green.offset = 5; + var->blue.offset = 0; + var->red.length = 5; + var->green.length = 6; + var->blue.length = 5; + var->transp.length = 0; + var->transp.offset = 0; + break; + case 24: + var->red.offset = 16; + var->green.offset = 8; + var->blue.offset = 0; + var->red.length = 8; + var->green.length = 8; + var->blue.length = 8; + var->transp.length = 0; + var->transp.offset = 0; + break; + case 32: + var->red.offset = 16; + var->green.offset = 8; + var->blue.offset = 0; + var->red.length = 8; + var->green.length = 8; + var->blue.length = 8; + var->transp.length = 8; + var->transp.offset = 24; + break; + default: + return -EINVAL; + } + + return 0; +} + +/* this will let fbcon do the mode init */ +/* FIXME: take mode config lock? */ +static int nouveau_fbcon_set_par(struct fb_info *info) +{ + struct nouveau_fbcon_par *par = info->par; + struct drm_device *dev = par->dev; + struct fb_var_screeninfo *var = &info->var; + int i; + + DRM_DEBUG("%d %d\n", var->xres, var->pixclock); + + if (var->pixclock != -1) { + + DRM_ERROR("PIXEL CLCOK SET\n"); + return -EINVAL; + } else { + struct drm_crtc *crtc; + int ret; + + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + struct nouveau_crtc *nouveau_crtc = to_nouveau_crtc(crtc); + + for (i = 0; i < par->crtc_count; i++) + if (crtc->base.id == par->crtc_ids[i]) + break; + + if (i == par->crtc_count) + continue; + + if (crtc->fb == nouveau_crtc->mode_set.fb) { + mutex_lock(&dev->mode_config.mutex); + ret = crtc->funcs->set_config(&nouveau_crtc->mode_set); + mutex_unlock(&dev->mode_config.mutex); + if (ret) + return ret; + } + } + return 0; + } +} + +static int nouveau_fbcon_pan_display(struct fb_var_screeninfo *var, + struct fb_info *info) +{ + struct nouveau_fbcon_par *par = info->par; + struct drm_device *dev = par->dev; + struct drm_mode_set *modeset; + struct drm_crtc *crtc; + struct nouveau_crtc *nouveau_crtc; + int ret = 0; + int i; + + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + for (i = 0; i < par->crtc_count; i++) + if (crtc->base.id == par->crtc_ids[i]) + break; + + if (i == par->crtc_count) + continue; + + nouveau_crtc = to_nouveau_crtc(crtc); + modeset = &nouveau_crtc->mode_set; + + modeset->x = var->xoffset; + modeset->y = var->yoffset; + + if (modeset->num_connectors) { + mutex_lock(&dev->mode_config.mutex); + ret = crtc->funcs->set_config(modeset); + mutex_unlock(&dev->mode_config.mutex); + if (!ret) { + info->var.xoffset = var->xoffset; + info->var.yoffset = var->yoffset; + } + } + } + + return ret; +} + +static void nouveau_fbcon_on(struct fb_info *info) +{ + struct nouveau_fbcon_par *par = info->par; + struct drm_device *dev = par->dev; + struct drm_crtc *crtc; + struct drm_encoder *encoder; + int i; + + /* + * For each CRTC in this fb, find all associated encoders + * and turn them off, then turn off the CRTC. + */ + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; + + for (i = 0; i < par->crtc_count; i++) + if (crtc->base.id == par->crtc_ids[i]) + break; + + crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); + + /* Found a CRTC on this fb, now find encoders */ + list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { + if (encoder->crtc == crtc) { + struct drm_encoder_helper_funcs *encoder_funcs; + encoder_funcs = encoder->helper_private; + encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON); + } + } + } +} + +static void nouveau_fbcon_off(struct fb_info *info, int dpms_mode) +{ + struct nouveau_fbcon_par *par = info->par; + struct drm_device *dev = par->dev; + struct drm_crtc *crtc; + struct drm_encoder *encoder; + int i; + + /* + * For each CRTC in this fb, find all associated encoders + * and turn them off, then turn off the CRTC. + */ + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; + + for (i = 0; i < par->crtc_count; i++) + if (crtc->base.id == par->crtc_ids[i]) + break; + + /* Found a CRTC on this fb, now find encoders */ + list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { + if (encoder->crtc == crtc) { + struct drm_encoder_helper_funcs *encoder_funcs; + encoder_funcs = encoder->helper_private; + encoder_funcs->dpms(encoder, dpms_mode); + } + } + if (dpms_mode == DRM_MODE_DPMS_OFF) + crtc_funcs->dpms(crtc, dpms_mode); + } +} + +static int nouveau_fbcon_blank(int blank, struct fb_info *info) +{ + switch (blank) { + case FB_BLANK_UNBLANK: + nouveau_fbcon_on(info); + break; + case FB_BLANK_NORMAL: + nouveau_fbcon_off(info, DRM_MODE_DPMS_STANDBY); + break; + case FB_BLANK_HSYNC_SUSPEND: + nouveau_fbcon_off(info, DRM_MODE_DPMS_STANDBY); + break; + case FB_BLANK_VSYNC_SUSPEND: + nouveau_fbcon_off(info, DRM_MODE_DPMS_SUSPEND); + break; + case FB_BLANK_POWERDOWN: + nouveau_fbcon_off(info, DRM_MODE_DPMS_OFF); + break; + } + return 0; +} + +static struct fb_ops nouveau_fbcon_ops = { + .owner = THIS_MODULE, + .fb_check_var = nouveau_fbcon_check_var, + .fb_set_par = nouveau_fbcon_set_par, + .fb_setcolreg = nouveau_fbcon_setcolreg, + .fb_fillrect = cfb_fillrect, + .fb_copyarea = cfb_copyarea, + .fb_imageblit = cfb_imageblit, + .fb_pan_display = nouveau_fbcon_pan_display, + .fb_blank = nouveau_fbcon_blank, +}; + +/** + * Curretly it is assumed that the old framebuffer is reused. + * + * LOCKING + * caller should hold the mode config lock. + * + */ +int nouveau_fbcon_resize(struct drm_device *dev, struct drm_crtc *crtc) +{ + struct fb_info *info; + struct drm_framebuffer *fb; + struct drm_display_mode *mode = crtc->desired_mode; + + fb = crtc->fb; + if (!fb) + return 1; + + info = fb->fbdev; + if (!info) + return 1; + + if (!mode) + return 1; + + info->var.xres = mode->hdisplay; + info->var.right_margin = mode->hsync_start - mode->hdisplay; + info->var.hsync_len = mode->hsync_end - mode->hsync_start; + info->var.left_margin = mode->htotal - mode->hsync_end; + info->var.yres = mode->vdisplay; + info->var.lower_margin = mode->vsync_start - mode->vdisplay; + info->var.vsync_len = mode->vsync_end - mode->vsync_start; + info->var.upper_margin = mode->vtotal - mode->vsync_end; + info->var.pixclock = 10000000 / mode->htotal * 1000 / mode->vtotal * 100; + /* avoid overflow */ + info->var.pixclock = info->var.pixclock * 1000 / mode->vrefresh; + + return 0; +} +EXPORT_SYMBOL(nouveau_fbcon_resize); + +static struct drm_mode_set kernelfb_mode; + +static int nouveau_fbcon_panic(struct notifier_block *n, unsigned long ununsed, + void *panic_str) +{ + DRM_ERROR("panic occurred, switching back to text console\n"); + + nouveau_fbcon_restore(); + return 0; +} + +static struct notifier_block paniced = { + .notifier_call = nouveau_fbcon_panic, +}; + +static int nouveau_fbcon_create(struct drm_device *dev, uint32_t fb_width, + uint32_t fb_height, uint32_t surface_width, + uint32_t surface_height, + struct nouveau_framebuffer **nouveau_fb_p) +{ + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct fb_info *info; + struct nouveau_fbcon_par *par; + struct drm_framebuffer *fb; + struct nouveau_framebuffer *nouveau_fb; + struct drm_mode_fb_cmd mode_cmd; + struct drm_gem_object *gem = NULL; + struct nouveau_gem_object *ngem; + struct device *device = &dev->pdev->dev; + struct fb_fillrect rect; + int size, ret; + + mode_cmd.width = surface_width; + mode_cmd.height = surface_height; + + mode_cmd.bpp = 32; + mode_cmd.pitch = ALIGN(mode_cmd.width, 64) * ((mode_cmd.bpp + 1) / 8); + mode_cmd.depth = 24; + + size = mode_cmd.pitch * mode_cmd.height; + size = ALIGN(size, PAGE_SIZE); + + ret = nouveau_gem_new(dev, NULL, size, 0, NOUVEAU_GEM_DOMAIN_VRAM, &gem); + if (ret) { + printk(KERN_ERR "failed to allocate framebuffer\n"); + ret = -ENOMEM; + goto out; + } + ngem = gem->driver_private; + + ret = nouveau_gem_pin(gem, NOUVEAU_GEM_DOMAIN_VRAM); + mutex_lock(&dev->struct_mutex); + if (ret) { + DRM_ERROR("failed to pin fb: %d\n", ret); + goto out_unref; + } + + fb = nouveau_framebuffer_create(dev, gem, &mode_cmd); + if (!fb) { + ret = -ENOMEM; + DRM_ERROR("failed to allocate fb.\n"); + goto out_unref; + } + + list_add(&fb->filp_head, &dev->mode_config.fb_kernel_list); + + nouveau_fb = to_nouveau_framebuffer(fb); + *nouveau_fb_p = nouveau_fb; + + ret = drm_bo_kmap(ngem->bo, 0, ngem->bo->mem.num_pages, + &nouveau_fb->kmap); + if (ret) { + DRM_ERROR("failed to kmap fb: %d\n", ret); + goto out_unref; + } + + info = framebuffer_alloc(sizeof(struct nouveau_fbcon_par), device); + if (!info) { + ret = -ENOMEM; + goto out_unref; + } + + par = info->par; + + strcpy(info->fix.id, "nouveaudrmfb"); + info->fix.type = FB_TYPE_PACKED_PIXELS; + info->fix.visual = FB_VISUAL_TRUECOLOR; + info->fix.type_aux = 0; + info->fix.xpanstep = 1; /* doing it in hw */ + info->fix.ypanstep = 1; /* doing it in hw */ + info->fix.ywrapstep = 0; + info->fix.accel = FB_ACCEL_I830; + info->fix.type_aux = 0; + + info->flags = FBINFO_DEFAULT; + + info->fbops = &nouveau_fbcon_ops; + + info->fix.line_length = fb->pitch; + info->fix.smem_start = dev->mode_config.fb_base + ngem->bo->offset - + dev_priv->vm_vram_base; + info->fix.smem_len = size; + + info->flags = FBINFO_DEFAULT; + + info->screen_base = nouveau_fb->kmap.virtual; + info->screen_size = size; + +// memset(info->screen_base, 0, size); + + info->pseudo_palette = fb->pseudo_palette; + info->var.xres_virtual = fb->width; + info->var.yres_virtual = fb->height; + info->var.bits_per_pixel = fb->bits_per_pixel; + info->var.xoffset = 0; + info->var.yoffset = 0; + info->var.activate = FB_ACTIVATE_NOW; + info->var.height = -1; + info->var.width = -1; + + info->var.xres = fb_width; + info->var.yres = fb_height; + + /* FIXME: we really shouldn't expose mmio space at all */ + info->fix.mmio_start = pci_resource_start(dev->pdev, 1); + info->fix.mmio_len = pci_resource_len(dev->pdev, 1); + + info->pixmap.size = 64*1024; + info->pixmap.buf_align = 8; + info->pixmap.access_align = 32; + info->pixmap.flags = FB_PIXMAP_SYSTEM; + info->pixmap.scan_align = 1; + + switch(fb->depth) { + case 8: + info->var.red.offset = 0; + info->var.green.offset = 0; + info->var.blue.offset = 0; + info->var.red.length = 8; /* 8bit DAC */ + info->var.green.length = 8; + info->var.blue.length = 8; + info->var.transp.offset = 0; + info->var.transp.length = 0; + break; + case 15: + info->var.red.offset = 10; + info->var.green.offset = 5; + info->var.blue.offset = 0; + info->var.red.length = 5; + info->var.green.length = 5; + info->var.blue.length = 5; + info->var.transp.offset = 15; + info->var.transp.length = 1; + break; + case 16: + info->var.red.offset = 11; + info->var.green.offset = 5; + info->var.blue.offset = 0; + info->var.red.length = 5; + info->var.green.length = 6; + info->var.blue.length = 5; + info->var.transp.offset = 0; + break; + case 24: + info->var.red.offset = 16; + info->var.green.offset = 8; + info->var.blue.offset = 0; + info->var.red.length = 8; + info->var.green.length = 8; + info->var.blue.length = 8; + info->var.transp.offset = 0; + info->var.transp.length = 0; + break; + case 32: + info->var.red.offset = 16; + info->var.green.offset = 8; + info->var.blue.offset = 0; + info->var.red.length = 8; + info->var.green.length = 8; + info->var.blue.length = 8; + info->var.transp.offset = 24; + info->var.transp.length = 8; + break; + default: + break; + } + + fb->fbdev = info; + + par->nouveau_fb = nouveau_fb; + par->dev = dev; + + switch (dev_priv->card_type) { + case NV_50: + nv50_fbcon_accel_init(info); + break; + default: + break; + }; + + /* Clear the entire fbcon. The drm will program every connector + * with it's preferred mode. If the sizes differ, one display will + * quite likely have garbage around the console. + */ + rect.dx = rect.dy = 0; + rect.width = surface_width; + rect.height = surface_height; + rect.color = 0; + rect.rop = ROP_COPY; + info->fbops->fb_fillrect(info, &rect); + + /* To allow resizeing without swapping buffers */ + printk("allocated %dx%d fb: 0x%lx, bo %p\n", nouveau_fb->base.width, + nouveau_fb->base.height, ngem->bo->offset, gem); + + mutex_unlock(&dev->struct_mutex); + return 0; + +out_unref: + drm_gem_object_unreference(gem); + mutex_unlock(&dev->struct_mutex); +out: + return ret; +} + +static int nouveau_fbcon_multi_fb_probe_crtc(struct drm_device *dev, + struct drm_crtc *crtc) +{ + struct nouveau_crtc *nouveau_crtc = to_nouveau_crtc(crtc); + struct nouveau_framebuffer *nouveau_fb; + struct drm_framebuffer *fb; + struct drm_connector *connector; + struct fb_info *info; + struct nouveau_fbcon_par *par; + struct drm_mode_set *modeset; + unsigned int width, height; + int new_fb = 0; + int ret, i, conn_count; + + if (!drm_helper_crtc_in_use(crtc)) + return 0; + + if (!crtc->desired_mode) + return 0; + + width = crtc->desired_mode->hdisplay; + height = crtc->desired_mode->vdisplay; + + /* is there an fb bound to this crtc already */ + if (!nouveau_crtc->mode_set.fb) { + ret = nouveau_fbcon_create(dev, width, height, width, height, &nouveau_fb); + if (ret) + return -EINVAL; + new_fb = 1; + } else { + fb = nouveau_crtc->mode_set.fb; + nouveau_fb = to_nouveau_framebuffer(fb); + if ((nouveau_fb->base.width < width) || (nouveau_fb->base.height < height)) + return -EINVAL; + } + + info = nouveau_fb->base.fbdev; + par = info->par; + + modeset = &nouveau_crtc->mode_set; + modeset->fb = &nouveau_fb->base; + conn_count = 0; + list_for_each_entry(connector, &dev->mode_config.connector_list, head) { + if (connector->encoder) { + if (connector->encoder->crtc == modeset->crtc) { + modeset->connectors[conn_count] = connector; + conn_count++; + if (conn_count > NOUVEAUFB_CONN_LIMIT) + BUG(); + } + } + } + + for (i = conn_count; i < NOUVEAUFB_CONN_LIMIT; i++) + modeset->connectors[i] = NULL; + + par->crtc_ids[0] = crtc->base.id; + + modeset->num_connectors = conn_count; + if (modeset->mode != modeset->crtc->desired_mode) + modeset->mode = modeset->crtc->desired_mode; + + par->crtc_count = 1; + + if (new_fb) { + info->var.pixclock = -1; + if (register_framebuffer(info) < 0) + return -EINVAL; + } else + nouveau_fbcon_set_par(info); + + printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, + info->fix.id); + + /* Switch back to kernel console on panic */ + kernelfb_mode = *modeset; + atomic_notifier_chain_register(&panic_notifier_list, &paniced); + printk(KERN_INFO "registered panic notifier\n"); + + return 0; +} + +static int nouveau_fbcon_multi_fb_probe(struct drm_device *dev) +{ + + struct drm_crtc *crtc; + int ret = 0; + + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + ret = nouveau_fbcon_multi_fb_probe_crtc(dev, crtc); + if (ret) + return ret; + } + return ret; +} + +static int nouveau_fbcon_single_fb_probe(struct drm_device *dev) +{ + struct drm_crtc *crtc; + struct drm_connector *connector; + unsigned int fb_width = (unsigned)-1, fb_height = (unsigned)-1; + unsigned int surface_width = 0, surface_height = 0; + int new_fb = 0; + int crtc_count = 0; + int ret, i, conn_count = 0; + struct nouveau_framebuffer *nouveau_fb; + struct fb_info *info; + struct nouveau_fbcon_par *par; + struct drm_mode_set *modeset = NULL; + + DRM_DEBUG("\n"); + + /* Get a count of crtcs now in use and new min/maxes width/heights */ + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + if (!drm_helper_crtc_in_use(crtc)) + continue; + + crtc_count++; + if (!crtc->desired_mode) + continue; + + /* Smallest mode determines console size... */ + if (crtc->desired_mode->hdisplay < fb_width) + fb_width = crtc->desired_mode->hdisplay; + + if (crtc->desired_mode->vdisplay < fb_height) + fb_height = crtc->desired_mode->vdisplay; + + /* ... but largest for memory allocation dimensions */ + if (crtc->desired_mode->hdisplay > surface_width) + surface_width = crtc->desired_mode->hdisplay; + + if (crtc->desired_mode->vdisplay > surface_height) + surface_height = crtc->desired_mode->vdisplay; + } + + if (crtc_count == 0 || fb_width == -1 || fb_height == -1) { + /* hmm everyone went away - assume VGA cable just fell out + and will come back later. */ + DRM_DEBUG("no CRTCs available?\n"); + return 0; + } + +//fail + /* Find the fb for our new config */ + if (list_empty(&dev->mode_config.fb_kernel_list)) { + DRM_DEBUG("creating new fb (console size %dx%d, " + "buffer size %dx%d)\n", fb_width, fb_height, + surface_width, surface_height); + ret = nouveau_fbcon_create(dev, fb_width, fb_height, surface_width, + surface_height, &nouveau_fb); + if (ret) + return -EINVAL; + new_fb = 1; + } else { + struct drm_framebuffer *fb; + + fb = list_first_entry(&dev->mode_config.fb_kernel_list, + struct drm_framebuffer, filp_head); + nouveau_fb = to_nouveau_framebuffer(fb); + + /* if someone hotplugs something bigger than we have already + * allocated, we are pwned. As really we can't resize an + * fbdev that is in the wild currently due to fbdev not really + * being designed for the lower layers moving stuff around + * under it. + * - so in the grand style of things - punt. + */ + if ((fb->width < surface_width) || + (fb->height < surface_height)) { + DRM_ERROR("fb not large enough for console\n"); + return -EINVAL; + } + } +// fail + + info = nouveau_fb->base.fbdev; + par = info->par; + + crtc_count = 0; + /* + * For each CRTC, set up the connector list for the CRTC's mode + * set configuration. + */ + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + struct nouveau_crtc *nouveau_crtc = to_nouveau_crtc(crtc); + + modeset = &nouveau_crtc->mode_set; + modeset->fb = &nouveau_fb->base; + conn_count = 0; + list_for_each_entry(connector, &dev->mode_config.connector_list, + head) { + if (!connector->encoder) + continue; + + if(connector->encoder->crtc == modeset->crtc) { + modeset->connectors[conn_count++] = connector; + if (conn_count > NOUVEAUFB_CONN_LIMIT) + BUG(); + } + } + + /* Zero out remaining connector pointers */ + for (i = conn_count; i < NOUVEAUFB_CONN_LIMIT; i++) + modeset->connectors[i] = NULL; + + par->crtc_ids[crtc_count++] = crtc->base.id; + + modeset->num_connectors = conn_count; + if (modeset->mode != modeset->crtc->desired_mode) + modeset->mode = modeset->crtc->desired_mode; + } + par->crtc_count = crtc_count; + + if (new_fb) { + info->var.pixclock = -1; + if (register_framebuffer(info) < 0) + return -EINVAL; + } else + nouveau_fbcon_set_par(info); + + printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, + info->fix.id); + + /* Switch back to kernel console on panic */ + kernelfb_mode = *modeset; + atomic_notifier_chain_register(&panic_notifier_list, &paniced); + printk(KERN_INFO "registered panic notifier\n"); + + return 0; +} + +/** + * nouveau_fbcon_restore - restore the framebuffer console (kernel) config + * + * Restore's the kernel's fbcon mode, used for lastclose & panic paths. + */ +void nouveau_fbcon_restore(void) +{ + drm_crtc_helper_set_config(&kernelfb_mode); +} + +static void nouveau_fbcon_sysrq(int dummy1, struct tty_struct *dummy3) +{ + nouveau_fbcon_restore(); +} + +static struct sysrq_key_op sysrq_nouveau_fbcon_restore_op = { + .handler = nouveau_fbcon_sysrq, + .help_msg = "force fb", + .action_msg = "force restore of fb console", +}; + +int nouveau_fbcon_probe(struct drm_device *dev) +{ + int ret; + + DRM_DEBUG("\n"); + + /* something has changed in the lower levels of hell - deal with it + here */ + + /* two modes : a) 1 fb to rule all crtcs. + b) one fb per crtc. + two actions 1) new connected device + 2) device removed. + case a/1 : if the fb surface isn't big enough - resize the surface fb. + if the fb size isn't big enough - resize fb into surface. + if everything big enough configure the new crtc/etc. + case a/2 : undo the configuration + possibly resize down the fb to fit the new configuration. + case b/1 : see if it is on a new crtc - setup a new fb and add it. + case b/2 : teardown the new fb. + */ + + /* mode a first */ + /* search for an fb */ + if (nouveau_fbpercrtc) { + ret = nouveau_fbcon_multi_fb_probe(dev); + } else { + ret = nouveau_fbcon_single_fb_probe(dev); + } + + register_sysrq_key('g', &sysrq_nouveau_fbcon_restore_op); + + return ret; +} +EXPORT_SYMBOL(nouveau_fbcon_probe); + +int nouveau_fbcon_remove(struct drm_device *dev, struct drm_framebuffer *fb) +{ + struct nouveau_framebuffer *nouveau_fb = to_nouveau_framebuffer(fb); + struct fb_info *info; + + if (!fb) + return -EINVAL; + + info = fb->fbdev; + + if (info) { + unregister_framebuffer(info); + drm_bo_kunmap(&nouveau_fb->kmap); + framebuffer_release(info); + } + + atomic_notifier_chain_unregister(&panic_notifier_list, &paniced); + memset(&kernelfb_mode, 0, sizeof(struct drm_mode_set)); + return 0; +} +EXPORT_SYMBOL(nouveau_fbcon_remove); +MODULE_LICENSE("GPL and additional rights"); diff --git a/linux-core/nv50_fbcon.h b/linux-core/nouveau_fbcon.h index 6f56bb29..471d2e88 100644 --- a/linux-core/nv50_fbcon.h +++ b/linux-core/nouveau_fbcon.h @@ -24,17 +24,24 @@ * */ -#ifndef __NV50_FBCON_H__ -#define __NV50_FBCON_H__ +#ifndef __NOUVEAU_FBCON_H__ +#define __NOUVEAU_FBCON_H__ -struct nv50_fbcon_par { - struct drm_framebuffer *fb; +#define NOUVEAUFB_CONN_LIMIT 4 + +struct nouveau_fbcon_par { struct drm_device *dev; - bool use_preferred_mode; + struct drm_display_mode *our_mode; + struct nouveau_framebuffer *nouveau_fb; + int crtc_count; + /* crtc currently bound to this */ + uint32_t crtc_ids[2]; }; -int nv50_fbcon_init(struct drm_device *dev); -int nv50_fbcon_destroy(struct drm_device *dev); +int nouveau_fbcon_probe(struct drm_device *dev); +int nouveau_fbcon_remove(struct drm_device *dev, struct drm_framebuffer *fb); +void nouveau_fbcon_restore(void); + int nv50_fbcon_accel_init(struct fb_info *info); #endif /* __NV50_FBCON_H__ */ diff --git a/linux-core/nv50_connector.c b/linux-core/nv50_connector.c index 16ab7fbd..dd404734 100644 --- a/linux-core/nv50_connector.c +++ b/linux-core/nv50_connector.c @@ -24,10 +24,62 @@ * */ +#include "drmP.h" #include "drm_edid.h" -#include "nv50_connector.h" +#include "drm_crtc_helper.h" +#include "nouveau_reg.h" +#include "nouveau_drv.h" +#include "nouveau_encoder.h" +#include "nouveau_crtc.h" +#include "nouveau_connector.h" +#include "nv50_display_commands.h" + +static struct drm_display_mode * +nv50_connector_lvds_native_mode(struct drm_device *dev) +{ + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct drm_display_mode *mode; + uint32_t output, tmp; + + output = nv_rd32(0x610050); + if ((output & 0x00000003) == 0x00000002) + output = 0x00000000; + else + if ((output & 0x00000300) == 0x00000200) + output = 0x000000540; + else { + DRM_ERROR("Unable to determine LVDS head: 0x%08x\n", output); + return NULL; + } -static struct nv50_output *nv50_connector_to_output(struct nv50_connector *connector, bool digital) + mode = drm_mode_create(dev); + if (!mode) + return NULL; + + mode->clock = nv_rd32(0x610ad4 + output) & 0x003fffff; + tmp = nv_rd32(0x610b4c + output); + mode->hdisplay = (tmp & 0x00003fff); + mode->vdisplay = (tmp & 0x3fff0000) >> 16; + tmp = nv_rd32(0x610afc + output); + mode->htotal = tmp & 0x3fff; + mode->vtotal = tmp >> 16; + tmp = nv_rd32(0x610ae8 + output); + mode->hsync_start = mode->htotal - (tmp & 0x3fff) - 1; + mode->vsync_start = mode->vtotal - (tmp >> 16) - 1; + tmp = nv_rd32(0x610b00 + output); + mode->hsync_end = mode->hsync_start + (tmp & 0x3fff) + 1; + mode->vsync_end = mode->vsync_start + (tmp >> 16) + 1; + mode->flags = 0; + mode->type = DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER; + mode->vrefresh = drm_mode_vrefresh(mode); + + DRM_DEBUG("Probed current LVDS mode:\n"); + drm_mode_debug_printmodeline(mode); + return mode; +} + +static struct nouveau_encoder * +nv50_connector_to_encoder(struct nouveau_connector *connector, bool digital) { struct drm_device *dev = connector->base.dev; struct drm_encoder *drm_encoder; @@ -59,24 +111,24 @@ static struct nv50_output *nv50_connector_to_output(struct nv50_connector *conne return NULL; list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { - struct nv50_output *output = to_nv50_output(drm_encoder); + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); - if (connector->bus != output->dcb_entry->bus) + if (connector->bus != encoder->dcb_entry->bus) continue; if (digital) { - switch (output->base.encoder_type) { + switch (encoder->base.encoder_type) { case DRM_MODE_ENCODER_TMDS: case DRM_MODE_ENCODER_LVDS: - return output; + return encoder; default: break; } } else { - switch (output->base.encoder_type) { + switch (encoder->base.encoder_type) { case DRM_MODE_ENCODER_DAC: case DRM_MODE_ENCODER_TVDAC: - return output; + return encoder; default: break; } @@ -86,49 +138,27 @@ static struct nv50_output *nv50_connector_to_output(struct nv50_connector *conne return NULL; } -static int nv50_connector_hpd_detect(struct nv50_connector *connector) +static bool nv50_connector_hpd_detect(struct nouveau_connector *connector) { struct drm_nouveau_private *dev_priv = connector->base.dev->dev_private; - bool present = 0; - uint32_t reg = 0; + uint32_t bus = connector->bus, reg; + bool present = false; - /* Assume connected for the moment. */ - if (connector->base.connector_type == DRM_MODE_CONNECTOR_LVDS) { - DRM_DEBUG("LVDS is defaulting to connected for the moment.\n"); - return 1; - } - - /* No i2c port, no idea what to do for hotplug. */ - if (connector->i2c_chan->index == 15) { - DRM_ERROR("You have a non-LVDS SOR with no i2c port, please report\n"); - return -EINVAL; - } - - if (connector->i2c_chan->index > 3) { - DRM_ERROR("You have an unusual configuration, index is %d\n", connector->i2c_chan->index); - DRM_ERROR("Please report.\n"); - return -EINVAL; - } - - /* Check hotplug pins. */ reg = nv_rd32(NV50_PCONNECTOR_HOTPLUG_STATE); - if (reg & (NV50_PCONNECTOR_HOTPLUG_STATE_PIN_CONNECTED_I2C0 << (4 * connector->i2c_chan->index))) - present = 1; - - if (present) - DRM_DEBUG("Hotplug detect returned positive for bus %d\n", connector->bus); - else - DRM_DEBUG("Hotplug detect returned negative for bus %d\n", connector->bus); + if (reg & (NV50_PCONNECTOR_HOTPLUG_STATE_PIN_CONNECTED_I2C0 << (4 * bus))) + present = true; + DRM_DEBUG("hpd_detect: bus=%d reg=0x%08x present=%d\n", + connector->bus, reg, present); return present; } -static int nv50_connector_i2c_detect(struct nv50_connector *connector) +static bool nv50_connector_i2c_detect(struct nouveau_connector *connector) { /* kindly borrrowed from the intel driver, hope it works. */ uint8_t out_buf[] = { 0x0, 0x0}; uint8_t buf[2]; - int ret; + bool ret; struct i2c_msg msgs[] = { { .addr = 0x50, @@ -145,20 +175,17 @@ static int nv50_connector_i2c_detect(struct nv50_connector *connector) }; if (!connector->i2c_chan) - return -EINVAL; - - ret = i2c_transfer(&connector->i2c_chan->adapter, msgs, 2); - DRM_DEBUG("I2C detect returned %d\n", ret); + return false; - if (ret == 2) - return true; + ret = (i2c_transfer(&connector->i2c_chan->adapter, msgs, 2) == 2); - return false; + DRM_DEBUG("i2c_detect: bus=%d present=%d\n", connector->bus, ret); + return ret; } static void nv50_connector_destroy(struct drm_connector *drm_connector) { - struct nv50_connector *connector = to_nv50_connector(drm_connector); + struct nouveau_connector *connector = to_nouveau_connector(drm_connector); struct drm_device *dev = connector->base.dev; struct nv50_display *display = nv50_get_display(dev); @@ -175,89 +202,25 @@ static void nv50_connector_destroy(struct drm_connector *drm_connector) kfree(drm_connector); } -/* These 2 functions wrap the connector properties that deal with multiple encoders per connector. */ -bool nv50_connector_get_digital(struct drm_connector *drm_connector) +static void +nv50_connector_set_digital(struct nouveau_connector *connector, bool digital) { - struct drm_device *dev = drm_connector->dev; - - switch (drm_connector->connector_type) { - case DRM_MODE_CONNECTOR_VGA: - case DRM_MODE_CONNECTOR_SVIDEO: - return false; - case DRM_MODE_CONNECTOR_DVID: - case DRM_MODE_CONNECTOR_LVDS: - return true; - default: - break; - } - - if (drm_connector->connector_type == DRM_MODE_CONNECTOR_DVII) { - int rval; - uint64_t prop_val; - - rval = drm_connector_property_get_value(drm_connector, dev->mode_config.dvi_i_select_subconnector_property, &prop_val); - if (rval) { - DRM_ERROR("Unable to find select subconnector property, defaulting to DVI-D\n"); - return true; - } + struct drm_device *dev = connector->base.dev; - /* Is a subconnector explicitly selected? */ - switch (prop_val) { - case DRM_MODE_SUBCONNECTOR_DVID: - return true; - case DRM_MODE_SUBCONNECTOR_DVIA: - return false; - default: - break; - } + if (connector->base.connector_type == DRM_MODE_CONNECTOR_DVII) { + struct drm_property *prop = + dev->mode_config.dvi_i_subconnector_property; + uint64_t val; - rval = drm_connector_property_get_value(drm_connector, dev->mode_config.dvi_i_subconnector_property, &prop_val); - if (rval) { - DRM_ERROR("Unable to find subconnector property, defaulting to DVI-D\n"); - return true; - } + if (digital) + val = DRM_MODE_SUBCONNECTOR_DVID; + else + val = DRM_MODE_SUBCONNECTOR_DVIA; - /* Do we know what subconnector we currently have connected? */ - switch (prop_val) { - case DRM_MODE_SUBCONNECTOR_DVID: - return true; - case DRM_MODE_SUBCONNECTOR_DVIA: - return false; - default: - DRM_ERROR("Unknown subconnector value, defaulting to DVI-D\n"); - return true; - } + drm_connector_property_set_value(&connector->base, prop, val); } - DRM_ERROR("Unknown connector type, defaulting to analog\n"); - return false; -} - -static void nv50_connector_set_digital(struct drm_connector *drm_connector, int digital, bool force) -{ - struct drm_device *dev = drm_connector->dev; - - if (drm_connector->connector_type == DRM_MODE_CONNECTOR_DVII) { - uint64_t cur_value, new_value; - - int rval = drm_connector_property_get_value(drm_connector, dev->mode_config.dvi_i_subconnector_property, &cur_value); - if (rval) { - DRM_ERROR("Unable to find subconnector property\n"); - return; - } - - /* Only set when unknown or when forced to do so. */ - if (cur_value != DRM_MODE_SUBCONNECTOR_Unknown && !force) - return; - - if (digital == 1) - new_value = DRM_MODE_SUBCONNECTOR_DVID; - else if (digital == 0) - new_value = DRM_MODE_SUBCONNECTOR_DVIA; - else - new_value = DRM_MODE_SUBCONNECTOR_Unknown; - drm_connector_property_set_value(drm_connector, dev->mode_config.dvi_i_subconnector_property, new_value); - } + connector->digital = digital; } void nv50_connector_detect_all(struct drm_device *dev) @@ -269,177 +232,51 @@ void nv50_connector_detect_all(struct drm_device *dev) } } -static enum drm_connector_status nv50_connector_detect(struct drm_connector *drm_connector) -{ - struct drm_device *dev = drm_connector->dev; - struct nv50_connector *connector = to_nv50_connector(drm_connector); - struct nv50_output *output = NULL; - int hpd_detect = 0, load_detect = 0, i2c_detect = 0; - int old_status = drm_connector->status; - - /* hotplug detect */ - hpd_detect = connector->hpd_detect(connector); - - /* load detect */ - output = connector->to_output(connector, false); /* analog */ - if (output && output->detect) - load_detect = output->detect(output); - - if (hpd_detect < 0 || load_detect < 0) /* did an error occur? */ - i2c_detect = connector->i2c_detect(connector); - - if (load_detect == 1) { - nv50_connector_set_digital(drm_connector, 0, true); /* analog, forced */ - } else if (hpd_detect == 1 && load_detect == 0) { - nv50_connector_set_digital(drm_connector, 1, true); /* digital, forced */ - } else { - nv50_connector_set_digital(drm_connector, -1, true); /* unknown, forced */ - } - - if (hpd_detect == 1 || load_detect == 1 || i2c_detect == 1) - drm_connector->status = connector_status_connected; - else - drm_connector->status = connector_status_disconnected; - - /* update our modes whenever there is reason to */ - if (old_status != drm_connector->status) { - drm_connector->funcs->fill_modes(drm_connector, 0, 0); - - /* notify fb of changes */ - dev->mode_config.funcs->fb_changed(dev); - - /* sent a hotplug event when appropriate. */ - drm_sysfs_hotplug_event(dev); - } - - return drm_connector->status; -} - -/* - * Detailed mode info for a standard 640x480@60Hz monitor - */ -static struct drm_display_mode std_mode[] = { - /*{ DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 25200, 640, 656, - 752, 800, 0, 480, 490, 492, 525, 0, - DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },*/ /* 640x480@60Hz */ - { DRM_MODE("1280x1024", DRM_MODE_TYPE_DEFAULT, 135000, 1280, 1296, - 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */ -}; - -static void nv50_connector_fill_modes(struct drm_connector *drm_connector, uint32_t maxX, uint32_t maxY) +static enum drm_connector_status +nv50_connector_detect(struct drm_connector *drm_connector) { - struct nv50_connector *connector = to_nv50_connector(drm_connector); - struct drm_device *dev = drm_connector->dev; - int rval = 0; - bool connected = false; - struct drm_display_mode *mode, *t; - struct edid *edid = NULL; - - DRM_DEBUG("%s\n", drm_get_connector_name(drm_connector)); - /* set all modes to the unverified state */ - list_for_each_entry_safe(mode, t, &drm_connector->modes, head) - mode->status = MODE_UNVERIFIED; - - if (nv50_connector_detect(drm_connector) == connector_status_connected) - connected = true; - - if (connected) - DRM_DEBUG("%s is connected\n", drm_get_connector_name(drm_connector)); - else - DRM_DEBUG("%s is disconnected\n", drm_get_connector_name(drm_connector)); - - /* Not all connnectors have an i2c channel. */ - if (connected && connector->i2c_chan) - edid = (struct edid *) drm_do_probe_ddc_edid(&connector->i2c_chan->adapter); - - /* This will remove edid if needed. */ - drm_mode_connector_update_edid_property(drm_connector, edid); - - if (edid) { - rval = drm_add_edid_modes(drm_connector, edid); - - /* Only update when relevant and when detect couldn't determine type. */ - nv50_connector_set_digital(drm_connector, edid->digital ? 1 : 0, false); - - kfree(edid); - } - - if (rval) /* number of modes > 1 */ - drm_mode_connector_list_update(drm_connector); - - if (maxX && maxY) - drm_mode_validate_size(dev, &drm_connector->modes, maxX, maxY, 0); - - list_for_each_entry_safe(mode, t, &drm_connector->modes, head) { - if (mode->status == MODE_OK) { - struct nv50_output *output = connector->to_output(connector, nv50_connector_get_digital(drm_connector)); - - mode->status = output->validate_mode(output, mode); - /* find native mode, TODO: also check if we actually found one */ - if (mode->status == MODE_OK) { - if (mode->type & DRM_MODE_TYPE_PREFERRED) - *output->native_mode = *mode; - } + struct nouveau_connector *connector = to_nouveau_connector(drm_connector); + struct nouveau_encoder *encoder = NULL; + struct drm_encoder_helper_funcs *helper = NULL; + bool hpd, i2c; + + if (drm_connector->connector_type == DRM_MODE_CONNECTOR_LVDS) { + if (!connector->native_mode) { + DRM_ERROR("No native mode for LVDS.\n"); + return connector_status_disconnected; } - } - - /* revalidate now that we have native mode */ - list_for_each_entry_safe(mode, t, &drm_connector->modes, head) { - if (mode->status == MODE_OK) { - struct nv50_output *output = connector->to_output(connector, nv50_connector_get_digital(drm_connector)); - mode->status = output->validate_mode(output, mode); - } + nv50_connector_set_digital(connector, true); + return connector_status_connected; } - drm_mode_prune_invalid(dev, &drm_connector->modes, true); - - /* pruning is done, so bail out. */ - if (!connected) - return; - - if (list_empty(&drm_connector->modes)) { - struct drm_display_mode *stdmode; - struct nv50_output *output; - - DRM_DEBUG("No valid modes on %s\n", drm_get_connector_name(drm_connector)); + encoder = connector->to_encoder(connector, false); + if (encoder) + helper = encoder->base.helper_private; - /* Making up native modes for LVDS is a bad idea. */ - if (drm_connector->connector_type == DRM_MODE_CONNECTOR_LVDS) - return; - - /* Should we do this here ??? - * When no valid EDID modes are available we end up - * here and bailed in the past, now we add a standard - * 640x480@60Hz mode and carry on. - */ - stdmode = drm_mode_duplicate(dev, &std_mode[0]); - drm_mode_probed_add(drm_connector, stdmode); - drm_mode_list_concat(&drm_connector->probed_modes, - &drm_connector->modes); - - /* also add it as native mode */ - output = connector->to_output(connector, nv50_connector_get_digital(drm_connector)); - - if (mode) - *output->native_mode = *mode; - - DRM_DEBUG("Adding standard 640x480 @ 60Hz to %s\n", - drm_get_connector_name(drm_connector)); + if (helper && helper->detect(&encoder->base, &connector->base) == + connector_status_connected) { + nv50_connector_set_digital(connector, false); + return connector_status_connected; } - drm_mode_sort(&drm_connector->modes); - - DRM_DEBUG("Probed modes for %s\n", drm_get_connector_name(drm_connector)); - - list_for_each_entry_safe(mode, t, &drm_connector->modes, head) { - mode->vrefresh = drm_mode_vrefresh(mode); - - /* is this needed, as it's unused by the driver? */ - drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); - drm_mode_debug_printmodeline(mode); + /* It's not certain if we can trust the hotplug pins just yet, + * at least, we haven't found a reliable way of determining which + * pin is wired to which connector. We'll do both hpd and single-byte + * i2c detect, and report if they differ for reference, and then + * trust i2c detect. + */ + hpd = nv50_connector_hpd_detect(connector); + i2c = nv50_connector_i2c_detect(connector); + if (hpd != i2c) + DRM_INFO("i2c and hpd detect differ: %d vs %d\n", i2c, hpd); + + if (i2c) { + nv50_connector_set_digital(connector, true); + return connector_status_connected; } + + return connector_status_disconnected; } static int nv50_connector_set_property(struct drm_connector *drm_connector, @@ -447,23 +284,21 @@ static int nv50_connector_set_property(struct drm_connector *drm_connector, uint64_t value) { struct drm_device *dev = drm_connector->dev; - struct nv50_connector *connector = to_nv50_connector(drm_connector); - int rval = 0; - bool delay_change = false; + struct nouveau_connector *connector = to_nouveau_connector(drm_connector); + int rval; /* DPMS */ - if (property == dev->mode_config.dpms_property && drm_connector->encoder) { - struct nv50_output *output = to_nv50_output(drm_connector->encoder); - - rval = output->set_power_mode(output, (int) value); + if (property == dev->mode_config.dpms_property) { + if (value > 3) + return -EINVAL; - return rval; + drm_helper_set_connector_dpms(drm_connector, value); } /* Scaling mode */ if (property == dev->mode_config.scaling_mode_property) { - struct nv50_crtc *crtc = NULL; - struct nv50_display *display = nv50_get_display(dev); + struct nouveau_crtc *crtc = NULL; + bool modeset = false; switch (value) { case DRM_MODE_SCALE_NON_GPU: @@ -480,43 +315,39 @@ static int nv50_connector_set_property(struct drm_connector *drm_connector, value == DRM_MODE_SCALE_NON_GPU) return -EINVAL; - connector->requested_scaling_mode = value; + /* Changing between GPU and panel scaling requires a full + * modeset + */ + if ((connector->scaling_mode == DRM_MODE_SCALE_NON_GPU) || + (value == DRM_MODE_SCALE_NON_GPU)) + modeset = true; + connector->scaling_mode = value; if (drm_connector->encoder && drm_connector->encoder->crtc) - crtc = to_nv50_crtc(drm_connector->encoder->crtc); + crtc = to_nouveau_crtc(drm_connector->encoder->crtc); if (!crtc) return 0; - crtc->requested_scaling_mode = connector->requested_scaling_mode; - - /* going from and to a gpu scaled regime requires a - * modesetting, so wait until next modeset - */ - if (crtc->scaling_mode == DRM_MODE_SCALE_NON_GPU || - value == DRM_MODE_SCALE_NON_GPU) { - DRM_INFO("Moving from or to a non-gpu scaled mode, " - "this will be processed upon next modeset."); - delay_change = true; + if (modeset) { + rval = drm_crtc_helper_set_mode(&crtc->base, + &crtc->base.mode, + crtc->base.x, + crtc->base.y); + if (rval) + return rval; + } else { + rval = crtc->set_scale(crtc, value, true); + if (rval) + return rval; } - if (delay_change) - return 0; - - rval = crtc->set_scale(crtc); - if (rval) - return rval; - - /* process command buffer */ - display->update(display); - return 0; } /* Dithering */ if (property == dev->mode_config.dithering_mode_property) { - struct nv50_crtc *crtc = NULL; - struct nv50_display *display = nv50_get_display(dev); + struct nouveau_crtc *crtc = NULL; if (value == DRM_MODE_DITHERING_ON) connector->use_dithering = true; @@ -524,7 +355,7 @@ static int nv50_connector_set_property(struct drm_connector *drm_connector, connector->use_dithering = false; if (drm_connector->encoder && drm_connector->encoder->crtc) - crtc = to_nv50_crtc(drm_connector->encoder->crtc); + crtc = to_nouveau_crtc(drm_connector->encoder->crtc); if (!crtc) return 0; @@ -536,7 +367,7 @@ static int nv50_connector_set_property(struct drm_connector *drm_connector, return rval; /* process command buffer */ - display->update(display); + OUT_MODE(NV50_UPDATE_DISPLAY, 0); return 0; } @@ -544,28 +375,135 @@ static int nv50_connector_set_property(struct drm_connector *drm_connector, return -EINVAL; } +static struct drm_display_mode * +nv50_connector_native_mode(struct nouveau_connector *connector) +{ + struct drm_device *dev = connector->base.dev; + struct drm_display_mode *mode; + + if (!connector->digital) + return NULL; + + list_for_each_entry(mode, &connector->base.probed_modes, head) { + DRM_INFO("%d %d 0x%08x\n", mode->hdisplay, mode->vdisplay, mode->type); + if (mode->type & DRM_MODE_TYPE_PREFERRED) + return drm_mode_duplicate(dev, mode); + } + + return NULL; +} + +static int nv50_connector_get_modes(struct drm_connector *drm_connector) +{ + struct drm_device *dev = drm_connector->dev; + struct nouveau_connector *connector = to_nouveau_connector(drm_connector); + struct edid *edid = NULL; + int ret = 0; + + /* If we're not LVDS, destroy the previous native mode, the attached + * monitor could have changed. + */ + if (drm_connector->connector_type != DRM_MODE_CONNECTOR_LVDS && + connector->native_mode) { + drm_mode_destroy(dev, connector->native_mode); + connector->native_mode = NULL; + } + + if (connector->i2c_chan) + edid = (struct edid *)drm_do_probe_ddc_edid(&connector->i2c_chan->adapter); + drm_mode_connector_update_edid_property(drm_connector, edid); + + if (edid) { + ret = drm_add_edid_modes(drm_connector, edid); + kfree(edid); + } + + /* Find the native mode if this is a digital panel, if we didn't + * find any modes through DDC previously add the native mode to + * the list of modes. + */ + if (!connector->native_mode) + connector->native_mode = nv50_connector_native_mode(connector); + if (ret == 0 && connector->native_mode) { + struct drm_display_mode *mode; + + mode = drm_mode_duplicate(dev, connector->native_mode); + drm_mode_probed_add(drm_connector, mode); + ret = 1; + } + + return ret; +} + +static int nv50_connector_mode_valid(struct drm_connector *drm_connector, + struct drm_display_mode *mode) +{ + struct nouveau_connector *connector = to_nouveau_connector(drm_connector); + struct nouveau_encoder *encoder = + connector->to_encoder(connector, connector->digital); + unsigned min_clock, max_clock; + + min_clock = 25000; + + switch (encoder->base.encoder_type) { + case DRM_MODE_ENCODER_LVDS: + if (!connector->native_mode) { + DRM_ERROR("AIIII no native mode\n"); + return MODE_PANEL; + } + + if (mode->hdisplay > connector->native_mode->hdisplay || + mode->vdisplay > connector->native_mode->vdisplay) + return MODE_PANEL; + /* fall-through */ + case DRM_MODE_ENCODER_TMDS: + max_clock = 165000; + break; + default: + max_clock = 400000; + break; + } + + if (mode->clock < min_clock) + return MODE_CLOCK_LOW; + + if (mode->clock > max_clock) + return MODE_CLOCK_HIGH; + + return MODE_OK; +} + +static struct drm_encoder * +nv50_connector_best_encoder(struct drm_connector *drm_connector) +{ + struct nouveau_connector *connector = to_nouveau_connector(drm_connector); + + return &connector->to_encoder(connector, connector->digital)->base; +} + +static const struct drm_connector_helper_funcs nv50_connector_helper_funcs = { + .get_modes = nv50_connector_get_modes, + .mode_valid = nv50_connector_mode_valid, + .best_encoder = nv50_connector_best_encoder, +}; + static const struct drm_connector_funcs nv50_connector_funcs = { .save = NULL, .restore = NULL, .detect = nv50_connector_detect, .destroy = nv50_connector_destroy, - .fill_modes = nv50_connector_fill_modes, + .fill_modes = drm_helper_probe_single_connector_modes, .set_property = nv50_connector_set_property }; int nv50_connector_create(struct drm_device *dev, int bus, int i2c_index, int type) { struct drm_nouveau_private *dev_priv = dev->dev_private; - struct nv50_connector *connector = NULL; - struct nv50_display *display = NULL; + struct nouveau_connector *connector = NULL; int i; DRM_DEBUG("\n"); - display = nv50_get_display(dev); - if (!display || type == DRM_MODE_CONNECTOR_Unknown) - return -EINVAL; - connector = kzalloc(sizeof(*connector), GFP_KERNEL); if (!connector) return -ENOMEM; @@ -583,6 +521,7 @@ int nv50_connector_create(struct drm_device *dev, int bus, int i2c_index, int ty DRM_INFO("Detected a DVI-I connector\n"); break; case DRM_MODE_CONNECTOR_LVDS: + connector->native_mode = nv50_connector_lvds_native_mode(dev); DRM_INFO("Detected a LVDS connector\n"); break; case DRM_MODE_CONNECTOR_SVIDEO: @@ -598,10 +537,10 @@ int nv50_connector_create(struct drm_device *dev, int bus, int i2c_index, int ty case DRM_MODE_CONNECTOR_DVII: case DRM_MODE_CONNECTOR_DVID: case DRM_MODE_CONNECTOR_LVDS: - connector->requested_scaling_mode = DRM_MODE_SCALE_FULLSCREEN; + connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN; break; default: - connector->requested_scaling_mode = DRM_MODE_SCALE_NON_GPU; + connector->scaling_mode = DRM_MODE_SCALE_NON_GPU; break; } @@ -613,15 +552,14 @@ int nv50_connector_create(struct drm_device *dev, int bus, int i2c_index, int ty } /* set function pointers */ - connector->hpd_detect = nv50_connector_hpd_detect; - connector->i2c_detect = nv50_connector_i2c_detect; - connector->to_output = nv50_connector_to_output; + connector->to_encoder = nv50_connector_to_encoder; /* It should be allowed sometimes, but let's be safe for the moment. */ connector->base.interlace_allowed = false; connector->base.doublescan_allowed = false; drm_connector_init(dev, &connector->base, &nv50_connector_funcs, type); + drm_connector_helper_add(&connector->base, &nv50_connector_helper_funcs); /* Init DVI-I specific properties */ if (type == DRM_MODE_CONNECTOR_DVII) { @@ -634,20 +572,21 @@ int nv50_connector_create(struct drm_device *dev, int bus, int i2c_index, int ty * internally and not expose them. */ if (type != DRM_MODE_CONNECTOR_SVIDEO) { - drm_connector_attach_property(&connector->base, dev->mode_config.scaling_mode_property, connector->requested_scaling_mode); + drm_connector_attach_property(&connector->base, dev->mode_config.scaling_mode_property, connector->scaling_mode); } drm_connector_attach_property(&connector->base, dev->mode_config.dithering_mode_property, connector->use_dithering ? DRM_MODE_DITHERING_ON : DRM_MODE_DITHERING_OFF); /* attach encoders, possibilities are analog + digital */ for (i = 0; i < 2; i++) { - struct nv50_output *output = connector->to_output(connector, i); - if (!output) + struct nouveau_encoder *encoder = connector->to_encoder(connector, i); + if (!encoder) continue; - drm_mode_connector_attach_encoder(&connector->base, &output->base); + drm_mode_connector_attach_encoder(&connector->base, &encoder->base); } drm_sysfs_connector_add(&connector->base); + return 0; } diff --git a/linux-core/nv50_crtc.c b/linux-core/nv50_crtc.c index 7e8f0ada..efd3b9cf 100644 --- a/linux-core/nv50_crtc.c +++ b/linux-core/nv50_crtc.c @@ -24,151 +24,71 @@ * */ -#include "nv50_crtc.h" +#include "drmP.h" +#include "drm_mode.h" +#include "drm_crtc_helper.h" +#include "nouveau_reg.h" +#include "nouveau_drv.h" +#include "nouveau_encoder.h" +#include "nouveau_crtc.h" +#include "nouveau_fb.h" +#include "nouveau_fbcon.h" +#include "nouveau_connector.h" #include "nv50_cursor.h" -#include "nv50_lut.h" -#include "nv50_fb.h" -#include "nv50_connector.h" -static int nv50_crtc_validate_mode(struct nv50_crtc *crtc, struct drm_display_mode *mode) +#define NV50_LUT_INDEX(val, w) ((val << (8 - w)) | (val >> ((w << 1) - 8))) +static int +nv50_crtc_lut_load(struct nouveau_crtc *crtc) { - DRM_DEBUG("\n"); - - if (mode->clock > 400000) - return MODE_CLOCK_HIGH; - - if (mode->clock < 25000) - return MODE_CLOCK_LOW; - - return MODE_OK; -} - -static int nv50_crtc_set_mode(struct nv50_crtc *crtc, struct drm_display_mode *mode) -{ - struct drm_display_mode *hw_mode = crtc->mode; - uint8_t rval; - - DRM_DEBUG("index %d\n", crtc->index); - - if (!mode) { - DRM_ERROR("No mode\n"); - return MODE_NOMODE; - } - - if ((rval = crtc->validate_mode(crtc, mode))) { - DRM_ERROR("Mode invalid\n"); - return rval; - } - - /* copy values to mode */ - *hw_mode = *mode; - return 0; -} - -static int nv50_crtc_execute_mode(struct nv50_crtc *crtc) -{ - struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; - struct drm_display_mode *mode; - uint32_t hsync_dur, vsync_dur, hsync_start_to_end, vsync_start_to_end; - uint32_t hunk1, vunk1, vunk2a, vunk2b; - uint32_t offset = crtc->index * 0x400; - - DRM_DEBUG("index %d\n", crtc->index); - DRM_DEBUG("%s native mode\n", crtc->use_native_mode ? "using" : "not using"); - - if (crtc->use_native_mode) - mode = crtc->native_mode; - else - mode = crtc->mode; - - hsync_dur = mode->hsync_end - mode->hsync_start; - vsync_dur = mode->vsync_end - mode->vsync_start; - hsync_start_to_end = mode->htotal - mode->hsync_start; - vsync_start_to_end = mode->vtotal - mode->vsync_start; - /* I can't give this a proper name, anyone else can? */ - hunk1 = mode->htotal - mode->hsync_start + mode->hdisplay; - vunk1 = mode->vtotal - mode->vsync_start + mode->vdisplay; - /* Another strange value, this time only for interlaced modes. */ - vunk2a = 2*mode->vtotal - mode->vsync_start + mode->vdisplay; - vunk2b = mode->vtotal - mode->vsync_start + mode->vtotal; - - if (mode->flags & DRM_MODE_FLAG_INTERLACE) { - vsync_dur /= 2; - vsync_start_to_end /= 2; - vunk1 /= 2; - vunk2a /= 2; - vunk2b /= 2; - /* magic */ - if (mode->flags & DRM_MODE_FLAG_DBLSCAN) { - vsync_start_to_end -= 1; - vunk1 -= 1; - vunk2a -= 1; - vunk2b -= 1; - } - } - - OUT_MODE(NV50_CRTC0_CLOCK + offset, mode->clock | 0x800000); - OUT_MODE(NV50_CRTC0_INTERLACE + offset, (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 0); - OUT_MODE(NV50_CRTC0_DISPLAY_START + offset, 0); - OUT_MODE(NV50_CRTC0_UNK82C + offset, 0); - OUT_MODE(NV50_CRTC0_DISPLAY_TOTAL + offset, mode->vtotal << 16 | mode->htotal); - OUT_MODE(NV50_CRTC0_SYNC_DURATION + offset, (vsync_dur - 1) << 16 | (hsync_dur - 1)); - OUT_MODE(NV50_CRTC0_SYNC_START_TO_BLANK_END + offset, (vsync_start_to_end - 1) << 16 | (hsync_start_to_end - 1)); - OUT_MODE(NV50_CRTC0_MODE_UNK1 + offset, (vunk1 - 1) << 16 | (hunk1 - 1)); - if (mode->flags & DRM_MODE_FLAG_INTERLACE) { - OUT_MODE(NV50_CRTC0_MODE_UNK2 + offset, (vunk2b - 1) << 16 | (vunk2a - 1)); - } - - crtc->set_fb(crtc); - crtc->set_dither(crtc); - - /* This is the actual resolution of the mode. */ - OUT_MODE(NV50_CRTC0_REAL_RES + offset, (crtc->mode->vdisplay << 16) | crtc->mode->hdisplay); - OUT_MODE(NV50_CRTC0_SCALE_CENTER_OFFSET + offset, NV50_CRTC_SCALE_CENTER_OFFSET_VAL(0,0)); - - /* Maybe move this as well? */ - crtc->blank(crtc, false); - - return 0; -} - -static int nv50_crtc_set_fb(struct nv50_crtc *crtc) -{ - struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; - struct drm_framebuffer *drm_fb = crtc->base.fb; - uint32_t offset = crtc->index * 0x400; + uint32_t index = 0, i; + void __iomem *lut = crtc->lut.mem->kmap.virtual; DRM_DEBUG("\n"); - OUT_MODE(NV50_CRTC0_FB_SIZE + offset, drm_fb->height << 16 | drm_fb->width); - - /* I suspect this flag indicates a linear fb. */ - OUT_MODE(NV50_CRTC0_FB_PITCH + offset, drm_fb->pitch | 0x100000); - - switch (drm_fb->depth) { - case 8: - OUT_MODE(NV50_CRTC0_DEPTH + offset, NV50_CRTC0_DEPTH_8BPP); - break; + /* 16 bits, red, green, blue, unused, total of 64 bits per index */ + /* 10 bits lut, with 14 bits values. */ + switch (crtc->lut.depth) { case 15: - OUT_MODE(NV50_CRTC0_DEPTH + offset, NV50_CRTC0_DEPTH_15BPP); + /* R5G5B5 */ + for (i = 0; i < 32; i++) { + index = NV50_LUT_INDEX(i, 5); + writew(crtc->lut.r[i] >> 2, lut + 8*index + 0); + writew(crtc->lut.g[i] >> 2, lut + 8*index + 2); + writew(crtc->lut.b[i] >> 2, lut + 8*index + 4); + } break; case 16: - OUT_MODE(NV50_CRTC0_DEPTH + offset, NV50_CRTC0_DEPTH_16BPP); + /* R5G6B5 */ + for (i = 0; i < 32; i++) { + index = NV50_LUT_INDEX(i, 5); + writew(crtc->lut.r[i] >> 2, lut + 8*index + 0); + writew(crtc->lut.b[i] >> 2, lut + 8*index + 4); + } + + /* Green has an extra bit. */ + for (i = 0; i < 64; i++) { + index = NV50_LUT_INDEX(i, 6); + writew(crtc->lut.g[i] >> 2, lut + 8*index + 2); + } break; - case 24: - OUT_MODE(NV50_CRTC0_DEPTH + offset, NV50_CRTC0_DEPTH_24BPP); + default: + /* R8G8B8 */ + for (i = 0; i < 256; i++) { + writew(crtc->lut.r[i] >> 2, lut + 8*i + 0); + writew(crtc->lut.g[i] >> 2, lut + 8*i + 2); + writew(crtc->lut.b[i] >> 2, lut + 8*i + 4); + } break; } - OUT_MODE(NV50_CRTC0_COLOR_CTRL + offset, NV50_CRTC_COLOR_CTRL_MODE_COLOR); - OUT_MODE(NV50_CRTC0_FB_POS + offset, (crtc->base.desired_y << 16) | (crtc->base.desired_x)); - return 0; } -static int nv50_crtc_blank(struct nv50_crtc *crtc, bool blanked) +static int +nv50_crtc_blank(struct nouveau_crtc *crtc, bool blanked) { - struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; + struct drm_device *dev = crtc->base.dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; uint32_t offset = crtc->index * 0x400; DRM_DEBUG("index %d\n", crtc->index); @@ -177,124 +97,167 @@ static int nv50_crtc_blank(struct nv50_crtc *crtc, bool blanked) if (blanked) { crtc->cursor->hide(crtc); - OUT_MODE(NV50_CRTC0_CLUT_MODE + offset, NV50_CRTC0_CLUT_MODE_BLANK); - OUT_MODE(NV50_CRTC0_CLUT_OFFSET + offset, 0); + OUT_MODE(NV50_CRTC0_CLUT_MODE + offset, + NV50_CRTC0_CLUT_MODE_BLANK); if (dev_priv->chipset != 0x50) - OUT_MODE(NV84_CRTC0_BLANK_UNK1 + offset, NV84_CRTC0_BLANK_UNK1_BLANK); - OUT_MODE(NV50_CRTC0_BLANK_CTRL + offset, NV50_CRTC0_BLANK_CTRL_BLANK); + OUT_MODE(NV84_CRTC0_BLANK_UNK1 + offset, + NV84_CRTC0_BLANK_UNK1_BLANK); + OUT_MODE(NV50_CRTC0_BLANK_CTRL + offset, + NV50_CRTC0_BLANK_CTRL_BLANK); if (dev_priv->chipset != 0x50) - OUT_MODE(NV84_CRTC0_BLANK_UNK2 + offset, NV84_CRTC0_BLANK_UNK2_BLANK); + OUT_MODE(NV84_CRTC0_BLANK_UNK2 + offset, + NV84_CRTC0_BLANK_UNK2_BLANK); } else { - struct nv50_framebuffer *fb = to_nv50_framebuffer(crtc->base.fb); - struct nouveau_gem_object *ngem = nouveau_gem_object(fb->gem); - uint32_t v_vram = ngem->bo->offset - dev_priv->vm_vram_base; - uint32_t v_lut = crtc->lut->bo->offset - dev_priv->vm_vram_base; - - OUT_MODE(NV50_CRTC0_FB_OFFSET + offset, v_vram >> 8); - OUT_MODE(0x864 + offset, 0); - crtc->cursor->set_offset(crtc); if (dev_priv->chipset != 0x50) - OUT_MODE(NV84_CRTC0_BLANK_UNK2 + offset, NV84_CRTC0_BLANK_UNK2_UNBLANK); + OUT_MODE(NV84_CRTC0_BLANK_UNK2 + offset, + NV84_CRTC0_BLANK_UNK2_UNBLANK); if (crtc->cursor->visible) crtc->cursor->show(crtc); else crtc->cursor->hide(crtc); - OUT_MODE(NV50_CRTC0_CLUT_MODE + offset, - fb->base.depth == 8 ? NV50_CRTC0_CLUT_MODE_OFF : NV50_CRTC0_CLUT_MODE_ON); - OUT_MODE(NV50_CRTC0_CLUT_OFFSET + offset, v_lut >> 8); if (dev_priv->chipset != 0x50) - OUT_MODE(NV84_CRTC0_BLANK_UNK1 + offset, NV84_CRTC0_BLANK_UNK1_UNBLANK); - OUT_MODE(NV50_CRTC0_BLANK_CTRL + offset, NV50_CRTC0_BLANK_CTRL_UNBLANK); + OUT_MODE(NV84_CRTC0_BLANK_UNK1 + offset, + NV84_CRTC0_BLANK_UNK1_UNBLANK); + OUT_MODE(NV50_CRTC0_BLANK_CTRL + offset, + NV50_CRTC0_BLANK_CTRL_UNBLANK); } - /* sometimes you need to know if a screen is already blanked. */ - crtc->blanked = blanked; - + OUT_MODE(NV50_UPDATE_DISPLAY, 0); return 0; } -static int nv50_crtc_set_dither(struct nv50_crtc *crtc) +static int nv50_crtc_set_dither(struct nouveau_crtc *crtc) { - struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; + struct drm_device *dev = crtc->base.dev; uint32_t offset = crtc->index * 0x400; DRM_DEBUG("\n"); - OUT_MODE(NV50_CRTC0_DITHERING_CTRL + offset, crtc->use_dithering ? - NV50_CRTC0_DITHERING_CTRL_ON : NV50_CRTC0_DITHERING_CTRL_OFF); + OUT_MODE(NV50_CRTC0_DITHERING_CTRL + offset, crtc->use_dithering ? + NV50_CRTC0_DITHERING_CTRL_ON : NV50_CRTC0_DITHERING_CTRL_OFF); return 0; } -static void nv50_crtc_calc_scale(struct nv50_crtc *crtc, uint32_t *outX, uint32_t *outY) +static struct nouveau_encoder * +nouveau_crtc_encoder_get(struct nouveau_crtc *crtc) { - uint32_t hor_scale, ver_scale; + struct drm_device *dev = crtc->base.dev; + struct drm_encoder *drm_encoder; - /* max res is 8192, which is 2^13, which leaves 19 bits */ - hor_scale = (crtc->native_mode->hdisplay << 19)/crtc->mode->hdisplay; - ver_scale = (crtc->native_mode->vdisplay << 19)/crtc->mode->vdisplay; + list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { + if (drm_encoder->crtc == &crtc->base) + return to_nouveau_encoder(drm_encoder); + } - if (ver_scale > hor_scale) { - *outX = (crtc->mode->hdisplay * hor_scale) >> 19; - *outY = (crtc->mode->vdisplay * hor_scale) >> 19; - } else { - *outX = (crtc->mode->hdisplay * ver_scale) >> 19; - *outY = (crtc->mode->vdisplay * ver_scale) >> 19; + return NULL; +} + +static struct nouveau_connector * +nouveau_crtc_connector_get(struct nouveau_crtc *crtc) +{ + struct drm_device *dev = crtc->base.dev; + struct drm_connector *drm_connector; + struct nouveau_encoder *encoder; + + encoder = nouveau_crtc_encoder_get(crtc); + if (!encoder) + return NULL; + + list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) { + if (drm_connector->encoder == &encoder->base) + return to_nouveau_connector(drm_connector); } + + return NULL; } -static int nv50_crtc_set_scale(struct nv50_crtc *crtc) +static int +nv50_crtc_set_scale(struct nouveau_crtc *crtc, int scaling_mode, bool update) { - struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; + struct nouveau_connector *connector = nouveau_crtc_connector_get(crtc); + struct drm_device *dev = crtc->base.dev; + struct drm_display_mode *native_mode = NULL; + struct drm_display_mode *mode = &crtc->base.mode; uint32_t offset = crtc->index * 0x400; - uint32_t outX, outY; + uint32_t outX, outY, horiz, vert; DRM_DEBUG("\n"); - switch (crtc->requested_scaling_mode) { + if (!connector->digital) + scaling_mode = DRM_MODE_SCALE_NON_GPU; + + switch (scaling_mode) { + case DRM_MODE_SCALE_NO_SCALE: + case DRM_MODE_SCALE_NON_GPU: + break; + default: + if (!connector || !connector->native_mode) { + DRM_ERROR("No native mode, forcing panel scaling\n"); + scaling_mode = DRM_MODE_SCALE_NON_GPU; + } else { + native_mode = connector->native_mode; + } + break; + } + + switch (scaling_mode) { case DRM_MODE_SCALE_ASPECT: - nv50_crtc_calc_scale(crtc, &outX, &outY); + horiz = (native_mode->hdisplay << 19) / mode->hdisplay; + vert = (native_mode->vdisplay << 19) / mode->vdisplay; + + if (vert > horiz) { + outX = (mode->hdisplay * horiz) >> 19; + outY = (mode->vdisplay * horiz) >> 19; + } else { + outX = (mode->hdisplay * vert) >> 19; + outY = (mode->vdisplay * vert) >> 19; + } break; case DRM_MODE_SCALE_FULLSCREEN: - outX = crtc->native_mode->hdisplay; - outY = crtc->native_mode->vdisplay; + outX = native_mode->hdisplay; + outY = native_mode->vdisplay; break; case DRM_MODE_SCALE_NO_SCALE: case DRM_MODE_SCALE_NON_GPU: default: - outX = crtc->mode->hdisplay; - outY = crtc->mode->vdisplay; + outX = mode->hdisplay; + outY = mode->vdisplay; break; } /* Got a better name for SCALER_ACTIVE? */ /* One day i've got to really figure out why this is needed. */ - if ((crtc->mode->flags & DRM_MODE_FLAG_DBLSCAN) || (crtc->mode->flags & DRM_MODE_FLAG_INTERLACE) || - crtc->mode->hdisplay != outX || crtc->mode->vdisplay != outY) { - OUT_MODE(NV50_CRTC0_SCALE_CTRL + offset, NV50_CRTC0_SCALE_CTRL_SCALER_ACTIVE); + if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) || + (mode->flags & DRM_MODE_FLAG_INTERLACE) || + mode->hdisplay != outX || mode->vdisplay != outY) { + OUT_MODE(NV50_CRTC0_SCALE_CTRL + offset, + NV50_CRTC0_SCALE_CTRL_SCALER_ACTIVE); } else { - OUT_MODE(NV50_CRTC0_SCALE_CTRL + offset, NV50_CRTC0_SCALE_CTRL_SCALER_INACTIVE); + OUT_MODE(NV50_CRTC0_SCALE_CTRL + offset, + NV50_CRTC0_SCALE_CTRL_SCALER_INACTIVE); } OUT_MODE(NV50_CRTC0_SCALE_RES1 + offset, outY << 16 | outX); OUT_MODE(NV50_CRTC0_SCALE_RES2 + offset, outY << 16 | outX); - /* processed */ - crtc->scaling_mode = crtc->requested_scaling_mode; + if (update) + OUT_MODE(NV50_UPDATE_DISPLAY, 0); return 0; } -static int nv50_crtc_calc_clock(struct nv50_crtc *crtc, - uint32_t *bestN1, uint32_t *bestN2, uint32_t *bestM1, uint32_t *bestM2, uint32_t *bestlog2P) +static int +nv50_crtc_calc_clock(struct nouveau_crtc *crtc, struct drm_display_mode *mode, + uint32_t *bestN1, uint32_t *bestN2, uint32_t *bestM1, + uint32_t *bestM2, uint32_t *bestlog2P) { - struct drm_display_mode *mode; struct pll_lims limits; - int clk, vco2, crystal; + int clk = mode->clock, vco2, crystal; int minvco1, minvco2, minU1, maxU1, minU2, maxU2, minM1, maxM1; int maxvco1, maxvco2, minN1, maxN1, minM2, maxM2, minN2, maxN2; bool fixedgain2; @@ -305,15 +268,10 @@ static int nv50_crtc_calc_clock(struct nv50_crtc *crtc, DRM_DEBUG("\n"); - if (crtc->use_native_mode) - mode = crtc->native_mode; - else - mode = crtc->mode; - - clk = mode->clock; - /* These are in the g80 bios tables, at least in mine. */ - if (!get_pll_limits(crtc->base.dev, NV50_PDISPLAY_CRTC_CLK_CLK_CTRL1(crtc->index), &limits)) + if (!get_pll_limits(crtc->base.dev, + NV50_PDISPLAY_CRTC_CLK_CLK_CTRL1(crtc->index), + &limits)) return -EINVAL; minvco1 = limits.vco1.minfreq, maxvco1 = limits.vco1.maxfreq; @@ -328,8 +286,8 @@ static int nv50_crtc_calc_clock(struct nv50_crtc *crtc, fixedgain2 = (minM2 == maxM2 && minN2 == maxN2); vco2 = (maxvco2 - maxvco2/200) / 2; - for (log2P = 0; clk && log2P < 6 && clk <= (vco2 >> log2P); log2P++) /* log2P is maximum of 6 */ - ; + /* log2P is maximum of 6 */ + for (log2P = 0; clk && log2P < 6 && clk <= (vco2 >> log2P); log2P++); clkP = clk << log2P; if (maxvco2 < clk + clk/200) /* +0.5% */ @@ -372,8 +330,8 @@ static int nv50_crtc_calc_clock(struct nv50_crtc *crtc, calcclkout = calcclk2 >> log2P; delta = abs(calcclkout - clk); - /* we do an exhaustive search rather than terminating - * on an optimality condition... + /* we do an exhaustive search rather than + * terminating on an optimality condition... */ if (delta < bestdelta) { bestdelta = delta; @@ -393,7 +351,8 @@ static int nv50_crtc_calc_clock(struct nv50_crtc *crtc, return bestclk; } -static int nv50_crtc_set_clock(struct nv50_crtc *crtc) +static int +nv50_crtc_set_clock(struct nouveau_crtc *crtc, struct drm_display_mode *mode) { struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; @@ -412,7 +371,7 @@ static int nv50_crtc_set_clock(struct nv50_crtc *crtc) reg1 &= 0xff00ff00; reg2 &= 0x8000ff00; - if (!nv50_crtc_calc_clock(crtc, &N1, &N2, &M1, &M2, &log2P)) + if (!nv50_crtc_calc_clock(crtc, mode, &N1, &N2, &M1, &M2, &log2P)) return -EINVAL; DRM_DEBUG("N1 %d N2 %d M1 %d M2 %d log2P %d\n", N1, N2, M1, M2, log2P); @@ -426,7 +385,7 @@ static int nv50_crtc_set_clock(struct nv50_crtc *crtc) return 0; } -static int nv50_crtc_set_clock_mode(struct nv50_crtc *crtc) +static int nv50_crtc_set_clock_mode(struct nouveau_crtc *crtc) { struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; @@ -440,7 +399,7 @@ static int nv50_crtc_set_clock_mode(struct nv50_crtc *crtc) static void nv50_crtc_destroy(struct drm_crtc *drm_crtc) { - struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc); + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_crtc); DRM_DEBUG("\n"); @@ -449,11 +408,11 @@ static void nv50_crtc_destroy(struct drm_crtc *drm_crtc) drm_crtc_cleanup(&crtc->base); - nv50_lut_destroy(crtc); nv50_cursor_destroy(crtc); + if (crtc->lut.mem) + nouveau_mem_free(drm_crtc->dev, crtc->lut.mem); kfree(crtc->mode); - kfree(crtc->native_mode); kfree(crtc); } @@ -463,8 +422,7 @@ static int nv50_crtc_cursor_set(struct drm_crtc *drm_crtc, uint32_t width, uint32_t height) { struct drm_device *dev = drm_crtc->dev; - struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc); - struct nv50_display *display = nv50_get_display(crtc->base.dev); + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_crtc); struct drm_gem_object *gem = NULL; int ret = 0; @@ -492,512 +450,267 @@ static int nv50_crtc_cursor_set(struct drm_crtc *drm_crtc, crtc->cursor->hide(crtc); } - display->update(display); + OUT_MODE(NV50_UPDATE_DISPLAY, 0); return ret; } static int nv50_crtc_cursor_move(struct drm_crtc *drm_crtc, int x, int y) { - struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc); + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_crtc); return crtc->cursor->set_pos(crtc, x, y); } -void nv50_crtc_gamma_set(struct drm_crtc *drm_crtc, u16 *r, u16 *g, u16 *b, - uint32_t size) +void +nv50_crtc_gamma_set(struct drm_crtc *drm_crtc, u16 *r, u16 *g, u16 *b, + uint32_t size) { - struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc); + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_crtc); + int i; if (size != 256) return; - crtc->lut->set(crtc, (uint16_t *)r, (uint16_t *)g, (uint16_t *)b); -} - -int nv50_crtc_set_config(struct drm_mode_set *set) -{ - int rval = 0, i; - uint32_t crtc_mask = 0; - struct drm_device *dev = NULL; - struct drm_nouveau_private *dev_priv = NULL; - struct nv50_display *display = NULL; - struct drm_connector *drm_connector = NULL; - struct drm_encoder *drm_encoder = NULL; - struct drm_crtc *drm_crtc = NULL; - - struct nv50_crtc *crtc = NULL; - struct nv50_output *output = NULL; - struct nv50_connector *connector = NULL; - - bool blank = false; - bool switch_fb = false; - bool modeset = false; - - DRM_DEBUG("\n"); - - /* - * Supported operations: - * - Switch mode. - * - Switch framebuffer. - * - Blank screen. - */ - - /* Sanity checking */ - if (!set) { - DRM_ERROR("Sanity check failed\n"); - goto out; + for (i = 0; i < 256; i++) { + crtc->lut.r[i] = r[i]; + crtc->lut.g[i] = g[i]; + crtc->lut.b[i] = b[i]; } - if (!set->crtc) { - DRM_ERROR("Sanity check failed\n"); - goto out; - } - - if (set->mode) { - if (set->fb) { - if (!drm_mode_equal(set->mode, &set->crtc->mode)) - modeset = true; - - if (set->fb != set->crtc->fb) - switch_fb = true; - - if (set->x != set->crtc->x || set->y != set->crtc->y) - switch_fb = true; - } - } else { - blank = true; - } - - if (!set->connectors && !blank) { - DRM_ERROR("Sanity check failed\n"); - goto out; - } - - /* Basic variable setting */ - dev = set->crtc->dev; - dev_priv = dev->dev_private; - display = nv50_get_display(dev); - crtc = to_nv50_crtc(set->crtc); - - /** - * Wiring up the encoders and connectors. + /* We need to know the depth before we upload, but it's possible to + * get called before a framebuffer is bound. If this is the case, + * mark the lut values as dirty by setting depth==0, and it'll be + * uploaded on the first mode_set_base() */ - - /* for switch_fb we verify if any important changes happened */ - if (!blank) { - /* Mode validation */ - - rval = crtc->validate_mode(crtc, set->mode); - if (rval != MODE_OK) { - DRM_ERROR("Mode not ok\n"); - goto out; - } - - for (i = 0; i < set->num_connectors; i++) { - drm_connector = set->connectors[i]; - if (!drm_connector) { - DRM_ERROR("No connector\n"); - goto out; - } - connector = to_nv50_connector(drm_connector); - - /* This is to ensure it knows the connector subtype. */ - drm_connector->funcs->fill_modes(drm_connector, 0, 0); - - output = connector->to_output(connector, nv50_connector_get_digital(drm_connector)); - if (!output) { - DRM_ERROR("No output\n"); - goto out; - } - - rval = output->validate_mode(output, set->mode); - if (rval != MODE_OK) { - DRM_ERROR("Mode not ok\n"); - goto out; - } - - /* verify if any "sneaky" changes happened */ - if (&output->base != drm_connector->encoder) - modeset = true; - - if (output->base.crtc != &crtc->base) - modeset = true; - } - } - - /* Now we verified if anything changed, fail if nothing has. */ - if (!modeset && !switch_fb && !blank) - DRM_INFO("A seemingly empty modeset encountered, this could be a bug.\n"); - - /* Validation done, move on to cleaning of existing structures. */ - if (modeset) { - /* find encoders that use this crtc. */ - list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { - if (drm_encoder->crtc == set->crtc) { - /* find the connector that goes with it */ - list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) { - if (drm_connector->encoder == drm_encoder) { - drm_connector->encoder = NULL; - break; - } - } - drm_encoder->crtc = NULL; - } - } - - /* now find if our desired encoders or connectors are in use already. */ - for (i = 0; i < set->num_connectors; i++) { - drm_connector = set->connectors[i]; - if (!drm_connector) { - DRM_ERROR("No connector\n"); - goto out; - } - - if (!drm_connector->encoder) - continue; - - drm_encoder = drm_connector->encoder; - drm_connector->encoder = NULL; - - if (!drm_encoder->crtc) - continue; - - drm_crtc = drm_encoder->crtc; - drm_encoder->crtc = NULL; - - drm_crtc->enabled = false; - } - - /* Time to wire up the public encoder, the private one will be handled later. */ - for (i = 0; i < set->num_connectors; i++) { - drm_connector = set->connectors[i]; - if (!drm_connector) { - DRM_ERROR("No connector\n"); - goto out; - } - - output = connector->to_output(connector, nv50_connector_get_digital(drm_connector)); - if (!output) { - DRM_ERROR("No output\n"); - goto out; - } - - output->base.crtc = set->crtc; - set->crtc->enabled = true; - drm_connector->encoder = &output->base; - } + if (!crtc->base.fb) { + crtc->lut.depth = 0; + return; } - /** - * Disable crtc. - */ - - if (blank) { - crtc = to_nv50_crtc(set->crtc); - - set->crtc->enabled = false; + nv50_crtc_lut_load(crtc); +} - /* disconnect encoders and connectors */ - for (i = 0; i < set->num_connectors; i++) { - drm_connector = set->connectors[i]; +static const struct drm_crtc_funcs nv50_crtc_funcs = { + .save = NULL, + .restore = NULL, + .cursor_set = nv50_crtc_cursor_set, + .cursor_move = nv50_crtc_cursor_move, + .gamma_set = nv50_crtc_gamma_set, + .set_config = drm_crtc_helper_set_config, + .destroy = nv50_crtc_destroy, +}; - if (!drm_connector->encoder) - continue; +static void nv50_crtc_dpms(struct drm_crtc *drm_crtc, int mode) +{ + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_crtc); - drm_connector->encoder->crtc = NULL; - drm_connector->encoder = NULL; - } + switch (mode) { + case DRM_MODE_DPMS_ON: + case DRM_MODE_DPMS_STANDBY: + case DRM_MODE_DPMS_SUSPEND: + nv50_crtc_blank(crtc, false); + break; + case DRM_MODE_DPMS_OFF: + nv50_crtc_blank(crtc, true); + break; } +} - /** - * All state should now be updated, now onto the real work. - */ - - /** - * Bind framebuffer. - */ - - if (switch_fb) { - struct nv50_crtc *crtc = to_nv50_crtc(set->crtc); - int r_size = 0, g_size = 0, b_size = 0; - uint16_t *r_val, *g_val, *b_val; - int i; - - /* set framebuffer */ - set->crtc->fb = set->fb; - set->crtc->desired_x = set->x; - set->crtc->desired_y = set->y; - - switch (set->crtc->fb->depth) { - case 15: - r_size = 32; - g_size = 32; - b_size = 32; - break; - case 16: - r_size = 32; - g_size = 64; - b_size = 32; - break; - case 24: - default: - r_size = 256; - g_size = 256; - b_size = 256; - break; - } - - r_val = kmalloc(r_size * sizeof(uint16_t), GFP_KERNEL); - g_val = kmalloc(g_size * sizeof(uint16_t), GFP_KERNEL); - b_val = kmalloc(b_size * sizeof(uint16_t), GFP_KERNEL); - - if (!r_val || !g_val || !b_val) - return -ENOMEM; - - /* Set the color indices. */ - for (i = 0; i < r_size; i++) { - r_val[i] = i << 8; - } - for (i = 0; i < g_size; i++) { - g_val[i] = i << 8; - } - for (i = 0; i < b_size; i++) { - b_val[i] = i << 8; - } - - rval = crtc->lut->set(crtc, r_val, g_val, b_val); - - /* free before returning */ - kfree(r_val); - kfree(g_val); - kfree(b_val); +static void nv50_crtc_prepare(struct drm_crtc *drm_crtc) +{ + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_crtc); - if (rval != 0) - return rval; - } + nv50_crtc_blank(crtc, true); +} - /* this is !cursor_show */ - if (!crtc->cursor->enabled) { - rval = crtc->cursor->enable(crtc); - if (rval != 0) { - DRM_ERROR("cursor_enable failed\n"); - goto out; - } - } +static void nv50_crtc_commit(struct drm_crtc *drm_crtc) +{ +} - /** - * Blanking. - */ +static bool nv50_crtc_mode_fixup(struct drm_crtc *drm_crtc, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ + return true; +} - if (blank) { - crtc = to_nv50_crtc(set->crtc); +static int +nv50_crtc_execute_mode(struct nouveau_crtc *crtc, struct drm_display_mode *mode) +{ + struct drm_device *dev = crtc->base.dev; + uint32_t hsync_dur, vsync_dur, hsync_start_to_end, vsync_start_to_end; + uint32_t hunk1, vunk1, vunk2a, vunk2b; + uint32_t offset = crtc->index * 0x400; - rval = crtc->blank(crtc, true); - if (rval != 0) { - DRM_ERROR("blanking failed\n"); - goto out; - } + DRM_DEBUG("index %d\n", crtc->index); - /* detach any outputs that are currently unused */ - list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { - if (!drm_encoder->crtc) { - output = to_nv50_output(drm_encoder); + hsync_dur = mode->hsync_end - mode->hsync_start; + vsync_dur = mode->vsync_end - mode->vsync_start; + hsync_start_to_end = mode->htotal - mode->hsync_start; + vsync_start_to_end = mode->vtotal - mode->vsync_start; + /* I can't give this a proper name, anyone else can? */ + hunk1 = mode->htotal - mode->hsync_start + mode->hdisplay; + vunk1 = mode->vtotal - mode->vsync_start + mode->vdisplay; + /* Another strange value, this time only for interlaced modes. */ + vunk2a = 2*mode->vtotal - mode->vsync_start + mode->vdisplay; + vunk2b = mode->vtotal - mode->vsync_start + mode->vtotal; - rval = output->execute_mode(output, true); - if (rval != 0) { - DRM_ERROR("detaching output failed\n"); - goto out; - } - } + if (mode->flags & DRM_MODE_FLAG_INTERLACE) { + vsync_dur /= 2; + vsync_start_to_end /= 2; + vunk1 /= 2; + vunk2a /= 2; + vunk2b /= 2; + /* magic */ + if (mode->flags & DRM_MODE_FLAG_DBLSCAN) { + vsync_start_to_end -= 1; + vunk1 -= 1; + vunk2a -= 1; + vunk2b -= 1; } } - /** - * Change framebuffer, without changing mode. - */ - - if (switch_fb && !modeset && !blank) { - crtc = to_nv50_crtc(set->crtc); - - rval = crtc->set_fb(crtc); - if (rval != 0) { - DRM_ERROR("set_fb failed\n"); - goto out; - } - - /* this also sets the fb offset */ - rval = crtc->blank(crtc, false); - if (rval != 0) { - DRM_ERROR("unblanking failed\n"); - goto out; - } + OUT_MODE(NV50_CRTC0_CLOCK + offset, mode->clock | 0x800000); + OUT_MODE(NV50_CRTC0_INTERLACE + offset, + (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 0); + OUT_MODE(NV50_CRTC0_DISPLAY_START + offset, 0); + OUT_MODE(NV50_CRTC0_UNK82C + offset, 0); + OUT_MODE(NV50_CRTC0_DISPLAY_TOTAL + offset, + mode->vtotal << 16 | mode->htotal); + OUT_MODE(NV50_CRTC0_SYNC_DURATION + offset, + (vsync_dur - 1) << 16 | (hsync_dur - 1)); + OUT_MODE(NV50_CRTC0_SYNC_START_TO_BLANK_END + offset, + (vsync_start_to_end - 1) << 16 | (hsync_start_to_end - 1)); + OUT_MODE(NV50_CRTC0_MODE_UNK1 + offset, + (vunk1 - 1) << 16 | (hunk1 - 1)); + if (mode->flags & DRM_MODE_FLAG_INTERLACE) { + OUT_MODE(NV50_CRTC0_MODE_UNK2 + offset, + (vunk2b - 1) << 16 | (vunk2a - 1)); } - /** - * Normal modesetting. - */ + crtc->set_dither(crtc); - if (modeset) { - crtc = to_nv50_crtc(set->crtc); - - /* disconnect unused outputs */ - list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { - output = to_nv50_output(drm_encoder); - - if (drm_encoder->crtc) { - crtc = to_nv50_crtc(drm_encoder->crtc); - crtc_mask |= 1 << crtc->index; - } else { - rval = output->execute_mode(output, true); - if (rval != 0) { - DRM_ERROR("detaching output failed\n"); - goto out; - } - } - } + /* This is the actual resolution of the mode. */ + OUT_MODE(NV50_CRTC0_REAL_RES + offset, + (crtc->base.mode.vdisplay << 16) | crtc->base.mode.hdisplay); + OUT_MODE(NV50_CRTC0_SCALE_CENTER_OFFSET + offset, + NV50_CRTC_SCALE_CENTER_OFFSET_VAL(0,0)); - /* blank any unused crtcs */ - list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) { - crtc = to_nv50_crtc(drm_crtc); - if (!(crtc_mask & (1 << crtc->index))) - crtc->blank(crtc, true); - } + nv50_crtc_blank(crtc, false); + return 0; +} - crtc = to_nv50_crtc(set->crtc); - rval = crtc->set_mode(crtc, set->mode); - if (rval != 0) { - DRM_ERROR("crtc mode set failed\n"); - goto out; - } +static void +nv50_crtc_mode_set(struct drm_crtc *drm_crtc, struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode, int x, int y) +{ + struct drm_device *dev = drm_crtc->dev; + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_crtc); + struct drm_encoder *drm_encoder; + struct nouveau_encoder *encoder; + struct drm_crtc_helper_funcs *crtc_helper = drm_crtc->helper_private; + struct nouveau_connector *connector = NULL; + + /* Find the connector attached to this CRTC */ + list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { + struct drm_connector *drm_connector; + + encoder = to_nouveau_encoder(drm_encoder); + if (drm_encoder->crtc != &crtc->base) + continue; - /* find native mode. */ - list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { - output = to_nv50_output(drm_encoder); - if (drm_encoder->crtc != &crtc->base) + list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) { + connector = to_nouveau_connector(drm_connector); + if (drm_connector->encoder != drm_encoder) continue; - *crtc->native_mode = *output->native_mode; - list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) { - connector = to_nv50_connector(drm_connector); - if (drm_connector->encoder != drm_encoder) - continue; - - crtc->requested_scaling_mode = connector->requested_scaling_mode; - crtc->use_dithering = connector->use_dithering; - break; - } - - if (crtc->requested_scaling_mode == DRM_MODE_SCALE_NON_GPU) - crtc->use_native_mode = false; - else - crtc->use_native_mode = true; - - break; /* no use in finding more than one mode */ - } - - rval = crtc->execute_mode(crtc); - if (rval != 0) { - DRM_ERROR("crtc execute mode failed\n"); - goto out; + break; } + break; /* no use in finding more than one mode */ + } - list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { - output = to_nv50_output(drm_encoder); - if (drm_encoder->crtc != &crtc->base) - continue; + *crtc->mode = *adjusted_mode; + crtc->use_dithering = connector->use_dithering; - rval = output->execute_mode(output, false); - if (rval != 0) { - DRM_ERROR("output execute mode failed\n"); - goto out; - } - } + nv50_crtc_execute_mode(crtc, adjusted_mode); + crtc->set_scale(crtc, connector->scaling_mode, false); + crtc_helper->mode_set_base(drm_crtc, x, y); +} - rval = crtc->set_scale(crtc); - if (rval != 0) { - DRM_ERROR("crtc set scale failed\n"); - goto out; - } +static void +nv50_crtc_mode_set_base(struct drm_crtc *drm_crtc, int x, int y) +{ + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_crtc); + struct drm_device *dev = crtc->base.dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct drm_framebuffer *drm_fb = crtc->base.fb; + struct nouveau_framebuffer *fb = to_nouveau_framebuffer(drm_fb); + struct nouveau_gem_object *ngem = nouveau_gem_object(fb->gem); + uint32_t v_vram = ngem->bo->offset - dev_priv->vm_vram_base; + uint32_t offset = crtc->index * 0x400; - /* next line changes crtc, so putting it here is important */ - display->last_crtc = crtc->index; - } + OUT_MODE(NV50_CRTC0_FB_OFFSET + offset, v_vram >> 8); + OUT_MODE(0x864 + offset, 0); - /* always reset dpms, regardless if any other modesetting is done. */ - if (!blank) { - /* this is executed immediately */ - list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { - output = to_nv50_output(drm_encoder); - if (drm_encoder->crtc != &crtc->base) - continue; + OUT_MODE(NV50_CRTC0_FB_SIZE + offset, + drm_fb->height << 16 | drm_fb->width); - rval = output->set_power_mode(output, DRM_MODE_DPMS_ON); - if (rval != 0) { - DRM_ERROR("output set power mode failed\n"); - goto out; - } - } - - /* update dpms state to DPMSModeOn */ - for (i = 0; i < set->num_connectors; i++) { - drm_connector = set->connectors[i]; - if (!drm_connector) { - DRM_ERROR("No connector\n"); - goto out; - } + /* I suspect this flag indicates a linear fb. */ + OUT_MODE(NV50_CRTC0_FB_PITCH + offset, drm_fb->pitch | 0x100000); - rval = drm_connector_property_set_value(drm_connector, - dev->mode_config.dpms_property, - DRM_MODE_DPMS_ON); - if (rval != 0) { - DRM_ERROR("failed to update dpms state\n"); - goto out; - } - } + switch (drm_fb->depth) { + case 8: + OUT_MODE(NV50_CRTC0_DEPTH + offset, NV50_CRTC0_DEPTH_8BPP); + break; + case 15: + OUT_MODE(NV50_CRTC0_DEPTH + offset, NV50_CRTC0_DEPTH_15BPP); + break; + case 16: + OUT_MODE(NV50_CRTC0_DEPTH + offset, NV50_CRTC0_DEPTH_16BPP); + break; + case 24: + OUT_MODE(NV50_CRTC0_DEPTH + offset, NV50_CRTC0_DEPTH_24BPP); + break; } - display->update(display); + OUT_MODE(NV50_CRTC0_COLOR_CTRL + offset, + NV50_CRTC_COLOR_CTRL_MODE_COLOR); + OUT_MODE(NV50_CRTC0_FB_POS + offset, (y << 16) | x); - /* Update the current mode, now that all has gone well. */ - if (modeset) { - set->crtc->mode = *(set->mode); - set->crtc->x = set->x; - set->crtc->y = set->y; + if (crtc->lut.depth != fb->base.depth) { + crtc->lut.depth = fb->base.depth; + nv50_crtc_lut_load(crtc); } - return 0; + OUT_MODE(NV50_CRTC0_CLUT_MODE + offset, fb->base.depth == 8 ? + NV50_CRTC0_CLUT_MODE_OFF : NV50_CRTC0_CLUT_MODE_ON); + OUT_MODE(NV50_CRTC0_CLUT_OFFSET + offset, crtc->lut.mem->start >> 8); -out: - if (rval != 0) - return rval; - else - return -EINVAL; + OUT_MODE(NV50_UPDATE_DISPLAY, 0); } -static const struct drm_crtc_funcs nv50_crtc_funcs = { - .save = NULL, - .restore = NULL, - .cursor_set = nv50_crtc_cursor_set, - .cursor_move = nv50_crtc_cursor_move, - .gamma_set = nv50_crtc_gamma_set, - .set_config = nv50_crtc_set_config, - .destroy = nv50_crtc_destroy, + +static const struct drm_crtc_helper_funcs nv50_crtc_helper_funcs = { + .dpms = nv50_crtc_dpms, + .prepare = nv50_crtc_prepare, + .commit = nv50_crtc_commit, + .mode_fixup = nv50_crtc_mode_fixup, + .mode_set = nv50_crtc_mode_set, + .mode_set_base = nv50_crtc_mode_set_base, }; int nv50_crtc_create(struct drm_device *dev, int index) { - struct nv50_crtc *crtc = NULL; - struct nv50_display *display = NULL; + struct nouveau_crtc *crtc = NULL; + int ret, i; DRM_DEBUG("\n"); - display = nv50_get_display(dev); - if (!display) - return -EINVAL; - - crtc = kzalloc(sizeof(*crtc), GFP_KERNEL); + crtc = kzalloc(sizeof(*crtc) + + NOUVEAUFB_CONN_LIMIT * sizeof(struct drm_connector *), + GFP_KERNEL); if (!crtc) return -ENOMEM; @@ -1007,32 +720,51 @@ int nv50_crtc_create(struct drm_device *dev, int index) return -ENOMEM; } - crtc->native_mode = kzalloc(sizeof(*crtc->native_mode), GFP_KERNEL); - if (!crtc->native_mode) { + /* Default CLUT parameters, will be activated on the hw upon + * first mode set. + */ + for (i = 0; i < 256; i++) { + crtc->lut.r[i] = i << 8; + crtc->lut.g[i] = i << 8; + crtc->lut.b[i] = i << 8; + } + crtc->lut.depth = 0; + + crtc->lut.mem = nouveau_mem_alloc(dev, 0x100, 4096, NOUVEAU_MEM_FB | + NOUVEAU_MEM_NOVM | NOUVEAU_MEM_MAPPED, + (struct drm_file *)-2); + if (crtc->lut.mem) { + ret = drm_bo_kmap(crtc->lut.mem->bo, 0, + crtc->lut.mem->bo->mem.num_pages, + &crtc->lut.mem->kmap); + if (ret) { + nouveau_mem_free(dev, crtc->lut.mem); + crtc->lut.mem = NULL; + } + } + + if (!crtc->lut.mem) { kfree(crtc->mode); kfree(crtc); return -ENOMEM; } crtc->index = index; - crtc->requested_scaling_mode = DRM_MODE_SCALE_NO_SCALE; - crtc->scaling_mode = DRM_MODE_SCALE_NO_SCALE; /* set function pointers */ - crtc->validate_mode = nv50_crtc_validate_mode; - crtc->set_mode = nv50_crtc_set_mode; - crtc->execute_mode = nv50_crtc_execute_mode; - crtc->set_fb = nv50_crtc_set_fb; - crtc->blank = nv50_crtc_blank; crtc->set_dither = nv50_crtc_set_dither; crtc->set_scale = nv50_crtc_set_scale; crtc->set_clock = nv50_crtc_set_clock; crtc->set_clock_mode = nv50_crtc_set_clock_mode; + crtc->mode_set.crtc = &crtc->base; + crtc->mode_set.connectors = (struct drm_connector **)(crtc + 1); + crtc->mode_set.num_connectors = 0; + drm_crtc_init(dev, &crtc->base, &nv50_crtc_funcs); + drm_crtc_helper_add(&crtc->base, &nv50_crtc_helper_funcs); drm_mode_crtc_set_gamma_size(&crtc->base, 256); - nv50_lut_create(crtc); nv50_cursor_create(crtc); return 0; } diff --git a/linux-core/nv50_cursor.c b/linux-core/nv50_cursor.c index 073b407d..fca5b4a4 100644 --- a/linux-core/nv50_cursor.c +++ b/linux-core/nv50_cursor.c @@ -24,46 +24,69 @@ * */ +#include "drmP.h" +#include "drm_mode.h" +#include "nouveau_reg.h" +#include "nouveau_drv.h" +#include "nouveau_crtc.h" #include "nv50_cursor.h" -#include "nv50_crtc.h" #include "nv50_display.h" -static int nv50_cursor_enable(struct nv50_crtc *crtc) +static int nv50_cursor_enable(struct nouveau_crtc *crtc) { - struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; + struct drm_device *dev = crtc->base.dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; + int idx = crtc->index; DRM_DEBUG("\n"); - nv_wr32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(crtc->index), 0x2000); - while(nv_rd32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(crtc->index)) & NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_MASK); - - nv_wr32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(crtc->index), NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_ON); - while((nv_rd32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(crtc->index)) & NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_MASK) - != NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_ACTIVE); + nv_wr32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(idx), 0x2000); + if (!nv_wait(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(idx), + NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_MASK, 0)) { + DRM_ERROR("timeout: CURSOR_CTRL2_STATUS == 0\n"); + DRM_ERROR("CURSOR_CTRL2 = 0x%08x\n", + nv_rd32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(idx))); + return -EBUSY; + } - crtc->cursor->enabled = true; + nv_wr32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(crtc->index), + NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_ON); + if (!nv_wait(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(idx), + NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_ACTIVE, + NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_ACTIVE)) { + DRM_ERROR("timeout: CURSOR_CTRL2_STATUS_ACTIVE(%d)\n", idx); + DRM_ERROR("CURSOR_CTRL2(%d) = 0x%08x\n", idx, + nv_rd32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(idx))); + return -EBUSY; + } return 0; } -static int nv50_cursor_disable(struct nv50_crtc *crtc) +static int nv50_cursor_disable(struct nouveau_crtc *crtc) { - struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; + struct drm_device *dev = crtc->base.dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; + int idx = crtc->index; DRM_DEBUG("\n"); - nv_wr32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(crtc->index), 0); - while(nv_rd32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(crtc->index)) & NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_MASK); - - crtc->cursor->enabled = false; + nv_wr32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(idx), 0); + if (!nv_wait(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(idx), + NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_MASK, 0)) { + DRM_ERROR("timeout: CURSOR_CTRL2_STATUS == 0\n"); + DRM_ERROR("CURSOR_CTRL2 = 0x%08x\n", + nv_rd32(NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(idx))); + return -EBUSY; + } return 0; } /* Calling update or changing the stored cursor state is left to the higher level ioctl's. */ -static int nv50_cursor_show(struct nv50_crtc *crtc) +static int nv50_cursor_show(struct nouveau_crtc *crtc) { - struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; + struct drm_device *dev = crtc->base.dev; uint32_t offset = crtc->index * 0x400; DRM_DEBUG("\n"); @@ -81,9 +104,9 @@ static int nv50_cursor_show(struct nv50_crtc *crtc) return 0; } -static int nv50_cursor_hide(struct nv50_crtc *crtc) +static int nv50_cursor_hide(struct nouveau_crtc *crtc) { - struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; + struct drm_device *dev = crtc->base.dev; uint32_t offset = crtc->index * 0x400; DRM_DEBUG("\n"); @@ -94,7 +117,7 @@ static int nv50_cursor_hide(struct nv50_crtc *crtc) return 0; } -static int nv50_cursor_set_pos(struct nv50_crtc *crtc, int x, int y) +static int nv50_cursor_set_pos(struct nouveau_crtc *crtc, int x, int y) { struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; @@ -105,9 +128,10 @@ static int nv50_cursor_set_pos(struct nv50_crtc *crtc, int x, int y) return 0; } -static int nv50_cursor_set_offset(struct nv50_crtc *crtc) +static int nv50_cursor_set_offset(struct nouveau_crtc *crtc) { - struct drm_nouveau_private *dev_priv = crtc->base.dev->dev_private; + struct drm_device *dev = crtc->base.dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; struct nouveau_gem_object *ngem = nouveau_gem_object(crtc->cursor->gem); DRM_DEBUG("\n"); @@ -123,7 +147,7 @@ static int nv50_cursor_set_offset(struct nv50_crtc *crtc) } static int -nv50_cursor_set_bo(struct nv50_crtc *crtc, struct drm_gem_object *gem) +nv50_cursor_set_bo(struct nouveau_crtc *crtc, struct drm_gem_object *gem) { struct nv50_cursor *cursor = crtc->cursor; @@ -139,43 +163,36 @@ nv50_cursor_set_bo(struct nv50_crtc *crtc, struct drm_gem_object *gem) return 0; } -int nv50_cursor_create(struct nv50_crtc *crtc) +int nv50_cursor_create(struct nouveau_crtc *crtc) { DRM_DEBUG("\n"); - if (!crtc) + if (!crtc || crtc->cursor) return -EINVAL; crtc->cursor = kzalloc(sizeof(struct nv50_cursor), GFP_KERNEL); if (!crtc->cursor) return -ENOMEM; + nv50_cursor_enable(crtc); + /* function pointers */ crtc->cursor->show = nv50_cursor_show; crtc->cursor->hide = nv50_cursor_hide; crtc->cursor->set_pos = nv50_cursor_set_pos; crtc->cursor->set_offset = nv50_cursor_set_offset; crtc->cursor->set_bo = nv50_cursor_set_bo; - crtc->cursor->enable = nv50_cursor_enable; - crtc->cursor->disable = nv50_cursor_disable; - return 0; } -int nv50_cursor_destroy(struct nv50_crtc *crtc) +int nv50_cursor_destroy(struct nouveau_crtc *crtc) { - int rval = 0; - DRM_DEBUG("\n"); - if (!crtc) + if (!crtc || !crtc->cursor) return -EINVAL; - if (crtc->cursor->enabled) { - rval = crtc->cursor->disable(crtc); - if (rval != 0) - return rval; - } + nv50_cursor_disable(crtc); kfree(crtc->cursor); crtc->cursor = NULL; diff --git a/linux-core/nv50_cursor.h b/linux-core/nv50_cursor.h index 1d4ebf7a..9be1591a 100644 --- a/linux-core/nv50_cursor.h +++ b/linux-core/nv50_cursor.h @@ -27,26 +27,19 @@ #ifndef __NV50_CURSOR_H__ #define __NV50_CURSOR_H__ -#include "nv50_display.h" - -struct nv50_crtc; - struct nv50_cursor { struct drm_gem_object *gem; int x, y; bool visible; - bool enabled; - int (*show) (struct nv50_crtc *crtc); - int (*hide) (struct nv50_crtc *crtc); - int (*set_pos) (struct nv50_crtc *crtc, int x, int y); - int (*set_offset) (struct nv50_crtc *crtc); - int (*set_bo) (struct nv50_crtc *crtc, struct drm_gem_object *gem); - int (*enable) (struct nv50_crtc *crtc); - int (*disable) (struct nv50_crtc *crtc); + int (*show) (struct nouveau_crtc *crtc); + int (*hide) (struct nouveau_crtc *crtc); + int (*set_pos) (struct nouveau_crtc *crtc, int x, int y); + int (*set_offset) (struct nouveau_crtc *crtc); + int (*set_bo) (struct nouveau_crtc *crtc, struct drm_gem_object *gem); }; -int nv50_cursor_create(struct nv50_crtc *crtc); -int nv50_cursor_destroy(struct nv50_crtc *crtc); +int nv50_cursor_create(struct nouveau_crtc *crtc); +int nv50_cursor_destroy(struct nouveau_crtc *crtc); #endif /* __NV50_CURSOR_H__ */ diff --git a/linux-core/nv50_dac.c b/linux-core/nv50_dac.c index 4cd1a05f..98c378fa 100644 --- a/linux-core/nv50_dac.c +++ b/linux-core/nv50_dac.c @@ -24,89 +24,111 @@ * */ -#include "nv50_output.h" - -static int nv50_dac_validate_mode(struct nv50_output *output, - struct drm_display_mode *mode) +#include "drmP.h" +#include "drm_crtc_helper.h" +#include "nouveau_reg.h" +#include "nouveau_drv.h" +#include "nouveau_dma.h" +#include "nouveau_encoder.h" +#include "nouveau_crtc.h" +#include "nv50_display.h" +#include "nv50_display_commands.h" + +static void +nv50_dac_disconnect(struct nouveau_encoder *encoder) { - DRM_DEBUG("\n"); - - if (mode->clock > 400000) - return MODE_CLOCK_HIGH; + struct drm_device *dev = encoder->base.dev; + uint32_t offset = encoder->or * 0x80; - if (mode->clock < 25000) - return MODE_CLOCK_LOW; + DRM_DEBUG("or %d\n", encoder->or); - return MODE_OK; + OUT_MODE(NV50_DAC0_MODE_CTRL + offset, NV50_DAC_MODE_CTRL_OFF); } -static int nv50_dac_execute_mode(struct nv50_output *output, bool disconnect) +static int +nv50_dac_set_clock_mode(struct nouveau_encoder *encoder, + struct drm_display_mode *mode) { - struct drm_encoder *drm_encoder = &output->base; - struct drm_nouveau_private *dev_priv = drm_encoder->dev->dev_private; - struct nv50_crtc *crtc = to_nv50_crtc(drm_encoder->crtc); - struct drm_display_mode *desired_mode = NULL; - uint32_t offset = output->or * 0x80; - uint32_t mode_ctl = NV50_DAC_MODE_CTRL_OFF; - uint32_t mode_ctl2 = 0; + struct drm_nouveau_private *dev_priv = encoder->base.dev->dev_private; - DRM_DEBUG("or %d\n", output->or); + DRM_DEBUG("or %d\n", encoder->or); - if (disconnect) { - DRM_DEBUG("Disconnecting DAC\n"); - OUT_MODE(NV50_DAC0_MODE_CTRL + offset, mode_ctl); - return 0; - } + nv_wr32(NV50_PDISPLAY_DAC_CLK_CLK_CTRL2(encoder->or), 0); + return 0; +} - desired_mode = (crtc->use_native_mode ? crtc->native_mode : - crtc->mode); +static enum drm_connector_status +nv50_dac_detect(struct drm_encoder *drm_encoder, + struct drm_connector *drm_connector) +{ + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); + struct drm_device *dev = encoder->base.dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; + enum drm_connector_status status = connector_status_disconnected; + uint32_t dpms_state, load_pattern, load_state; + int or = encoder->or; - if (crtc->index == 1) - mode_ctl |= NV50_DAC_MODE_CTRL_CRTC1; - else - mode_ctl |= NV50_DAC_MODE_CTRL_CRTC0; + nv_wr32(NV50_PDISPLAY_DAC_REGS_CLK_CTRL1(or), 0x00000001); + dpms_state = nv_rd32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or)); - /* Lacking a working tv-out, this is not a 100% sure. */ - if (output->base.encoder_type == DRM_MODE_ENCODER_DAC) { - mode_ctl |= 0x40; - } else - if (output->base.encoder_type == DRM_MODE_ENCODER_TVDAC) { - mode_ctl |= 0x100; + nv_wr32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or), + 0x00150000 | NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING); + if (!nv_wait(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or), + NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING, 0)) { + DRM_ERROR("timeout: DAC_DPMS_CTRL_PENDING(%d) == 0\n", or); + DRM_ERROR("DAC_DPMS_CTRL(%d) = 0x%08x\n", or, + nv_rd32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or))); + return status; } - if (desired_mode->flags & DRM_MODE_FLAG_NHSYNC) - mode_ctl2 |= NV50_DAC_MODE_CTRL2_NHSYNC; - - if (desired_mode->flags & DRM_MODE_FLAG_NVSYNC) - mode_ctl2 |= NV50_DAC_MODE_CTRL2_NVSYNC; - - OUT_MODE(NV50_DAC0_MODE_CTRL + offset, mode_ctl); - OUT_MODE(NV50_DAC0_MODE_CTRL2 + offset, mode_ctl2); + /* Use bios provided value if possible. */ + if (dev_priv->bios.dactestval) { + load_pattern = dev_priv->bios.dactestval; + DRM_DEBUG("Using bios provided load_pattern of %d\n", + load_pattern); + } else { + load_pattern = 340; + DRM_DEBUG("Using default load_pattern of %d\n", load_pattern); + } - return 0; -} + nv_wr32(NV50_PDISPLAY_DAC_REGS_LOAD_CTRL(or), + NV50_PDISPLAY_DAC_REGS_LOAD_CTRL_ACTIVE | load_pattern); + udelay(10000); /* give it some time to process */ + load_state = nv_rd32(NV50_PDISPLAY_DAC_REGS_LOAD_CTRL(or)); -static int nv50_dac_set_clock_mode(struct nv50_output *output) -{ - struct drm_nouveau_private *dev_priv = output->base.dev->dev_private; + nv_wr32(NV50_PDISPLAY_DAC_REGS_LOAD_CTRL(or), 0); + nv_wr32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or), dpms_state); - DRM_DEBUG("or %d\n", output->or); + if ((load_state & NV50_PDISPLAY_DAC_REGS_LOAD_CTRL_PRESENT) == + NV50_PDISPLAY_DAC_REGS_LOAD_CTRL_PRESENT) + status = connector_status_connected; - nv_wr32(NV50_PDISPLAY_DAC_CLK_CLK_CTRL2(output->or), 0); + if (status == connector_status_connected) + DRM_DEBUG("Load was detected on output with or %d\n", or); + else + DRM_DEBUG("Load was not detected on output with or %d\n", or); - return 0; + return status; } -static int nv50_dac_set_power_mode(struct nv50_output *output, int mode) +static void nv50_dac_dpms(struct drm_encoder *drm_encoder, int mode) { - struct drm_nouveau_private *dev_priv = output->base.dev->dev_private; + struct drm_device *dev = drm_encoder->dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); uint32_t val; - int or = output->or; + int or = encoder->or; DRM_DEBUG("or %d\n", or); /* wait for it to be done */ - while (nv_rd32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or)) & NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING); + if (!nv_wait(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or), + NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING, 0)) { + DRM_ERROR("timeout: DAC_DPMS_CTRL_PENDING(%d) == 0\n", or); + DRM_ERROR("DAC_DPMS_CTRL(%d) = 0x%08x\n", or, + nv_rd32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or))); + return; + } val = nv_rd32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or)) & ~0x7F; @@ -129,64 +151,100 @@ static int nv50_dac_set_power_mode(struct nv50_output *output, int mode) break; } - nv_wr32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or), val | NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING); + nv_wr32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or), + val | NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING); +} - return 0; +static void nv50_dac_save(struct drm_encoder *drm_encoder) +{ + DRM_ERROR("!!\n"); } -static int nv50_dac_detect(struct nv50_output *output) +static void nv50_dac_restore(struct drm_encoder *drm_encoder) { - struct drm_nouveau_private *dev_priv = output->base.dev->dev_private; - bool present = 0; - uint32_t dpms_state, load_pattern, load_state; - int or = output->or; + DRM_ERROR("!!\n"); +} - nv_wr32(NV50_PDISPLAY_DAC_REGS_CLK_CTRL1(or), 0x00000001); - dpms_state = nv_rd32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or)); +static bool nv50_dac_mode_fixup(struct drm_encoder *drm_encoder, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ + return true; +} - nv_wr32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or), 0x00150000 | NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING); - while (nv_rd32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or)) & NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING); +static void nv50_dac_prepare(struct drm_encoder *drm_encoder) +{ + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); - /* Use bios provided value if possible. */ - if (dev_priv->bios.dactestval) { - load_pattern = dev_priv->bios.dactestval; - DRM_DEBUG("Using bios provided load_pattern of %d\n", load_pattern); - } else { - load_pattern = 340; - DRM_DEBUG("Using default load_pattern of %d\n", load_pattern); - } + nv50_dac_dpms(drm_encoder, DRM_MODE_DPMS_OFF); + nv50_dac_disconnect(encoder); +} - nv_wr32(NV50_PDISPLAY_DAC_REGS_LOAD_CTRL(or), NV50_PDISPLAY_DAC_REGS_LOAD_CTRL_ACTIVE | load_pattern); - udelay(10000); /* give it some time to process */ - load_state = nv_rd32(NV50_PDISPLAY_DAC_REGS_LOAD_CTRL(or)); +static void nv50_dac_commit(struct drm_encoder *drm_encoder) +{ + nv50_dac_dpms(drm_encoder, DRM_MODE_DPMS_ON); +} - nv_wr32(NV50_PDISPLAY_DAC_REGS_LOAD_CTRL(or), 0); - nv_wr32(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or), dpms_state); +static void nv50_dac_mode_set(struct drm_encoder *drm_encoder, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); + struct drm_device *dev = drm_encoder->dev; + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_encoder->crtc); + uint32_t offset = encoder->or * 0x80; + uint32_t mode_ctl = NV50_DAC_MODE_CTRL_OFF; + uint32_t mode_ctl2 = 0; - if ((load_state & NV50_PDISPLAY_DAC_REGS_LOAD_CTRL_PRESENT) == NV50_PDISPLAY_DAC_REGS_LOAD_CTRL_PRESENT) - present = 1; + DRM_DEBUG("or %d\n", encoder->or); - if (present) - DRM_DEBUG("Load was detected on output with or %d\n", or); + if (crtc->index == 1) + mode_ctl |= NV50_DAC_MODE_CTRL_CRTC1; else - DRM_DEBUG("Load was not detected on output with or %d\n", or); + mode_ctl |= NV50_DAC_MODE_CTRL_CRTC0; + + /* Lacking a working tv-out, this is not a 100% sure. */ + if (encoder->base.encoder_type == DRM_MODE_ENCODER_DAC) { + mode_ctl |= 0x40; + } else + if (encoder->base.encoder_type == DRM_MODE_ENCODER_TVDAC) { + mode_ctl |= 0x100; + } - return present; + if (mode->flags & DRM_MODE_FLAG_NHSYNC) + mode_ctl2 |= NV50_DAC_MODE_CTRL2_NHSYNC; + + if (mode->flags & DRM_MODE_FLAG_NVSYNC) + mode_ctl2 |= NV50_DAC_MODE_CTRL2_NVSYNC; + + OUT_MODE(NV50_DAC0_MODE_CTRL + offset, mode_ctl); + OUT_MODE(NV50_DAC0_MODE_CTRL2 + offset, mode_ctl2); + OUT_MODE(NV50_UPDATE_DISPLAY, 0); } +static const struct drm_encoder_helper_funcs nv50_dac_helper_funcs = { + .dpms = nv50_dac_dpms, + .save = nv50_dac_save, + .restore = nv50_dac_restore, + .mode_fixup = nv50_dac_mode_fixup, + .prepare = nv50_dac_prepare, + .commit = nv50_dac_commit, + .mode_set = nv50_dac_mode_set, + .detect = nv50_dac_detect +}; + static void nv50_dac_destroy(struct drm_encoder *drm_encoder) { - struct nv50_output *output = to_nv50_output(drm_encoder); + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); DRM_DEBUG("\n"); if (!drm_encoder) return; - drm_encoder_cleanup(&output->base); + drm_encoder_cleanup(&encoder->base); - kfree(output->native_mode); - kfree(output); + kfree(encoder); } static const struct drm_encoder_funcs nv50_dac_encoder_funcs = { @@ -195,36 +253,28 @@ static const struct drm_encoder_funcs nv50_dac_encoder_funcs = { int nv50_dac_create(struct drm_device *dev, struct dcb_entry *entry) { - struct nv50_output *output = NULL; + struct nouveau_encoder *encoder = NULL; DRM_DEBUG("\n"); DRM_INFO("Detected a DAC output\n"); - output = kzalloc(sizeof(*output), GFP_KERNEL); - if (!output) - return -ENOMEM; - - output->native_mode = kzalloc(sizeof(*output->native_mode), GFP_KERNEL); - if (!output->native_mode) { - kfree(output); + encoder = kzalloc(sizeof(*encoder), GFP_KERNEL); + if (!encoder) return -ENOMEM; - } - output->dcb_entry = entry; - output->or = ffs(entry->or) - 1; + encoder->dcb_entry = entry; + encoder->or = ffs(entry->or) - 1; /* Set function pointers. */ - output->validate_mode = nv50_dac_validate_mode; - output->execute_mode = nv50_dac_execute_mode; - output->set_clock_mode = nv50_dac_set_clock_mode; - output->set_power_mode = nv50_dac_set_power_mode; - output->detect = nv50_dac_detect; + encoder->set_clock_mode = nv50_dac_set_clock_mode; - drm_encoder_init(dev, &output->base, &nv50_dac_encoder_funcs, + drm_encoder_init(dev, &encoder->base, &nv50_dac_encoder_funcs, DRM_MODE_ENCODER_DAC); + drm_encoder_helper_add(&encoder->base, &nv50_dac_helper_funcs); + /* I've never seen possible crtc's restricted. */ - output->base.possible_crtcs = 3; - output->base.possible_clones = 0; + encoder->base.possible_crtcs = 3; + encoder->base.possible_clones = 0; return 0; } diff --git a/linux-core/nv50_display.c b/linux-core/nv50_display.c index 5500e201..0e9fd371 100644 --- a/linux-core/nv50_display.c +++ b/linux-core/nv50_display.c @@ -25,15 +25,14 @@ */ #include "nv50_display.h" -#include "nv50_crtc.h" -#include "nv50_output.h" -#include "nv50_connector.h" -#include "nv50_fb.h" +#include "nouveau_crtc.h" +#include "nouveau_encoder.h" +#include "nouveau_connector.h" +#include "nouveau_fb.h" #include "drm_crtc_helper.h" -static int nv50_display_pre_init(struct nv50_display *display) +static int nv50_display_pre_init(struct drm_device *dev) { - struct drm_device *dev = display->dev; struct drm_nouveau_private *dev_priv = dev->dev_private; int i; uint32_t ram_amount; @@ -60,6 +59,7 @@ static int nv50_display_pre_init(struct nv50_display *display) /* SOR */ nv_wr32(0x006101e0 + 0 * 0x4, nv_rd32(0x0061c000 + 0 * 0x800)); nv_wr32(0x006101e0 + 1 * 0x4, nv_rd32(0x0061c000 + 1 * 0x800)); + nv_wr32(0x006101e0 + 2 * 0x4, nv_rd32(0x0061c000 + 2 * 0x800)); /* Something not yet in use, tv-out maybe. */ nv_wr32(0x006101f0 + 0 * 0x4, nv_rd32(0x0061e000 + 0 * 0x800)); nv_wr32(0x006101f0 + 1 * 0x4, nv_rd32(0x0061e000 + 1 * 0x800)); @@ -73,7 +73,7 @@ static int nv50_display_pre_init(struct nv50_display *display) /* This used to be in crtc unblank, but seems out of place there. */ nv_wr32(NV50_PDISPLAY_UNK_380, 0); /* RAM is clamped to 256 MiB. */ - ram_amount = nouveau_mem_fb_amount(display->dev); + ram_amount = nouveau_mem_fb_amount(dev); DRM_DEBUG("ram_amount %d\n", ram_amount); if (ram_amount > 256*1024*1024) ram_amount = 256*1024*1024; @@ -81,40 +81,59 @@ static int nv50_display_pre_init(struct nv50_display *display) nv_wr32(NV50_PDISPLAY_UNK_388, 0x150000); nv_wr32(NV50_PDISPLAY_UNK_38C, 0); - display->preinit_done = true; - return 0; } -static int nv50_display_init(struct nv50_display *display) +static int +nv50_display_init(struct drm_device *dev) { - struct drm_device *dev = display->dev; struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer; + uint64_t start; uint32_t val; DRM_DEBUG("\n"); - /* The precise purpose is unknown, i suspect it has something to do with text mode. */ + /* The precise purpose is unknown, i suspect it has something to do + * with text mode. + */ if (nv_rd32(NV50_PDISPLAY_SUPERVISOR) & 0x100) { nv_wr32(NV50_PDISPLAY_SUPERVISOR, 0x100); nv_wr32(0x006194e8, nv_rd32(0x006194e8) & ~1); - while (nv_rd32(0x006194e8) & 2); + if (!nv_wait(0x006194e8, 2, 0)) { + DRM_ERROR("timeout: (0x6194e8 & 2) != 0\n"); + DRM_ERROR("0x6194e8 = 0x%08x\n", nv_rd32(0x6194e8)); + return -EBUSY; + } } - /* taken from nv bug #12637 */ + /* taken from nv bug #12637, attempts to un-wedge the hw if it's + * stuck in some unspecified state + */ + start = ptimer->read(dev); nv_wr32(NV50_PDISPLAY_UNK200_CTRL, 0x2b00); - do { - val = nv_rd32(NV50_PDISPLAY_UNK200_CTRL); + while ((val = nv_rd32(NV50_PDISPLAY_UNK200_CTRL)) & 0x1e0000) { if ((val & 0x9f0000) == 0x20000) nv_wr32(NV50_PDISPLAY_UNK200_CTRL, val | 0x800000); if ((val & 0x3f0000) == 0x30000) nv_wr32(NV50_PDISPLAY_UNK200_CTRL, val | 0x200000); - } while (val & 0x1e0000); + + if (ptimer->read(dev) - start > 1000000000ULL) { + DRM_ERROR("timeout: (0x610200 & 0x1e0000) != 0\n"); + DRM_ERROR("0x610200 = 0x%08x\n", val); + return -EBUSY; + } + } nv_wr32(NV50_PDISPLAY_CTRL_STATE, NV50_PDISPLAY_CTRL_STATE_ENABLE); nv_wr32(NV50_PDISPLAY_UNK200_CTRL, 0x1000b03); - while (!(nv_rd32(NV50_PDISPLAY_UNK200_CTRL) & 0x40000000)); + if (!nv_wait(NV50_PDISPLAY_UNK200_CTRL, 0x40000000, 0x40000000)) { + DRM_ERROR("timeout: (0x610200 & 0x40000000) == 0x40000000\n"); + DRM_ERROR("0x610200 = 0x%08x\n", + nv_rd32(NV50_PDISPLAY_UNK200_CTRL)); + return -EBUSY; + } /* For the moment this is just a wrapper, which should be replaced with a real fifo at some point. */ OUT_MODE(NV50_UNK84, 0); @@ -124,20 +143,21 @@ static int nv50_display_init(struct nv50_display *display) OUT_MODE(NV50_CRTC0_DISPLAY_START, 0); OUT_MODE(NV50_CRTC0_UNK82C, 0); + OUT_MODE(NV50_UPDATE_DISPLAY, 0); + /* enable clock change interrupts. */ - nv_wr32(NV50_PDISPLAY_SUPERVISOR_INTR, nv_rd32(NV50_PDISPLAY_SUPERVISOR_INTR) | 0x70); +// nv_wr32(NV50_PDISPLAY_SUPERVISOR_INTR, nv_rd32(NV50_PDISPLAY_SUPERVISOR_INTR) | 0x70); /* enable hotplug interrupts */ - nv_wr32(NV50_PCONNECTOR_HOTPLUG_INTR, 0x7FFF7FFF); + nv_wr32(NV50_PCONNECTOR_HOTPLUG_CTRL, 0x7FFF7FFF); +// nv_wr32(NV50_PCONNECTOR_HOTPLUG_INTR, 0x7FFF7FFF); - display->init_done = true; return 0; } -static int nv50_display_disable(struct nv50_display *display) +static int nv50_display_disable(struct drm_device *dev) { - struct drm_device *dev = display->dev; struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_crtc *drm_crtc; int i; @@ -145,16 +165,16 @@ static int nv50_display_disable(struct nv50_display *display) DRM_DEBUG("\n"); list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) { - struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc); + struct drm_crtc_helper_funcs *helper = drm_crtc->helper_private; - crtc->blank(crtc, true); + helper->dpms(drm_crtc, DRM_MODE_DPMS_OFF); } - display->update(display); + OUT_MODE(NV50_UPDATE_DISPLAY, 0); /* Almost like ack'ing a vblank interrupt, maybe in the spirit of cleaning up? */ list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) { - struct nv50_crtc *crtc = to_nv50_crtc(drm_crtc); + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_crtc); if (crtc->base.enabled) { uint32_t mask; @@ -165,125 +185,53 @@ static int nv50_display_disable(struct nv50_display *display) mask = NV50_PDISPLAY_SUPERVISOR_CRTC0; nv_wr32(NV50_PDISPLAY_SUPERVISOR, mask); - while (!(nv_rd32(NV50_PDISPLAY_SUPERVISOR) & mask)); + if (!nv_wait(NV50_PDISPLAY_SUPERVISOR, mask, mask)) { + DRM_ERROR("timeout: (0x610024 & 0x%08x) == " + "0x%08x\n", mask, mask); + DRM_ERROR("0x610024 = 0x%08x\n", + nv_rd32(0x610024)); + } } } +#if 0 nv_wr32(NV50_PDISPLAY_UNK200_CTRL, 0); nv_wr32(NV50_PDISPLAY_CTRL_STATE, 0); - while ((nv_rd32(NV50_PDISPLAY_UNK200_CTRL) & 0x1e0000) != 0); - - for (i = 0; i < 2; i++) { - while (nv_rd32(NV50_PDISPLAY_SOR_REGS_DPMS_STATE(i)) & NV50_PDISPLAY_SOR_REGS_DPMS_STATE_WAIT); + if (!nv_wait(NV50_PDISPLAY_UNK200_CTRL, 0x1e0000, 0)) { + DRM_ERROR("timeout: (0x610200 & 0x1e0000) == 0\n"); + DRM_ERROR("0x610200 = 0x%08x\n", + nv_rd32(NV50_PDISPLAY_UNK200_CTRL)); + } +#endif + + for (i = 0; i < NV50_PDISPLAY_SOR_REGS__LEN; i++) { + if (!nv_wait(NV50_PDISPLAY_SOR_REGS_DPMS_STATE(i), + NV50_PDISPLAY_SOR_REGS_DPMS_STATE_WAIT, 0)) { + DRM_ERROR("timeout: SOR_DPMS_STATE_WAIT(%d) == 0\n", i); + DRM_ERROR("SOR_DPMS_STATE(%d) = 0x%08x\n", i, + nv_rd32(NV50_PDISPLAY_SOR_REGS_DPMS_STATE(i))); + } } /* disable clock change interrupts. */ - nv_wr32(NV50_PDISPLAY_SUPERVISOR_INTR, nv_rd32(NV50_PDISPLAY_SUPERVISOR_INTR) & ~0x70); + nv_wr32(NV50_PDISPLAY_SUPERVISOR_INTR, + nv_rd32(NV50_PDISPLAY_SUPERVISOR_INTR) & ~0x70); /* disable hotplug interrupts */ nv_wr32(NV50_PCONNECTOR_HOTPLUG_INTR, 0); - display->init_done = false; - - return 0; -} - -static int nv50_display_update(struct nv50_display *display) -{ - struct drm_device *dev = display->dev; - struct drm_nouveau_private *dev_priv = dev->dev_private; - - DRM_DEBUG("\n"); - - OUT_MODE(NV50_UPDATE_DISPLAY, 0); - return 0; } -static void nv50_user_framebuffer_destroy(struct drm_framebuffer *drm_fb) -{ - struct nv50_framebuffer *fb = to_nv50_framebuffer(drm_fb); - struct drm_device *dev = drm_fb->dev; - - if (drm_fb->fbdev) - DRM_ERROR("radeonfb_remove(dev, drm_fb);\n"); - - if (fb->gem) { - mutex_lock(&dev->struct_mutex); - drm_gem_object_unreference(fb->gem); - mutex_unlock(&dev->struct_mutex); - } - - drm_framebuffer_cleanup(drm_fb); - kfree(fb); -} - -static int nv50_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb, - struct drm_file *file_priv, - unsigned int *handle) -{ - struct nv50_framebuffer *fb = to_nv50_framebuffer(drm_fb); - - return drm_gem_handle_create(file_priv, fb->gem, handle); -} - -static const struct drm_framebuffer_funcs nv50_framebuffer_funcs = { - .destroy = nv50_user_framebuffer_destroy, - .create_handle = nv50_user_framebuffer_create_handle, -}; - -struct drm_framebuffer * -nv50_framebuffer_create(struct drm_device *dev, struct drm_gem_object *gem, - struct drm_mode_fb_cmd *mode_cmd) -{ - struct nv50_framebuffer *fb; - - fb = kzalloc(sizeof(struct nv50_framebuffer), GFP_KERNEL); - if (!fb) - return NULL; - - drm_framebuffer_init(dev, &fb->base, &nv50_framebuffer_funcs); - drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd); - - fb->gem = gem; - return &fb->base; -} - -static struct drm_framebuffer * -nv50_user_framebuffer_create(struct drm_device *dev, struct drm_file *file_priv, - struct drm_mode_fb_cmd *mode_cmd) -{ - struct drm_gem_object *gem; - - gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle); - return nv50_framebuffer_create(dev, gem, mode_cmd); -} - -static int nv50_framebuffer_changed(struct drm_device *dev) -{ - return 0; /* not needed until nouveaufb? */ -} - -static const struct drm_mode_config_funcs nv50_mode_config_funcs = { - .fb_create = nv50_user_framebuffer_create, - .fb_changed = nv50_framebuffer_changed, -}; - int nv50_display_create(struct drm_device *dev) { struct drm_nouveau_private *dev_priv = dev->dev_private; - struct nv50_display *display; uint32_t bus_mask = 0; uint32_t bus_digital = 0, bus_analog = 0; int ret, i; DRM_DEBUG("\n"); - display = kzalloc(sizeof(*display), GFP_KERNEL); - if (!display) - return -ENOMEM; - dev_priv->display_priv = display; - /* init basic kernel modesetting */ drm_mode_config_init(dev); @@ -294,7 +242,7 @@ int nv50_display_create(struct drm_device *dev) dev->mode_config.min_width = 0; dev->mode_config.min_height = 0; - dev->mode_config.funcs = (void *)&nv50_mode_config_funcs; + dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs; dev->mode_config.max_width = 8192; dev->mode_config.max_height = 8192; @@ -369,49 +317,90 @@ int nv50_display_create(struct drm_device *dev) bus_mask |= (1 << entry->bus); } - display->dev = dev; - - /* function pointers */ - display->init = nv50_display_init; - display->pre_init = nv50_display_pre_init; - display->disable = nv50_display_disable; - display->update = nv50_display_update; - - ret = display->pre_init(display); + ret = nv50_display_pre_init(dev); if (ret) return ret; - ret = display->init(display); + ret = nv50_display_init(dev); if (ret) return ret; - display->update(display); return 0; } int nv50_display_destroy(struct drm_device *dev) { - struct drm_nouveau_private *dev_priv = dev->dev_private; - struct nv50_display *display = nv50_get_display(dev); - DRM_DEBUG("\n"); - if (display->init_done) - display->disable(display); + nv50_display_disable(dev); drm_mode_config_cleanup(dev); - kfree(display); - dev_priv->display_priv = NULL; - return 0; } /* This can be replaced with a real fifo in the future. */ -void nv50_display_command(struct drm_nouveau_private *dev_priv, - uint32_t mthd, uint32_t val) +static void nv50_display_vclk_update(struct drm_device *dev) { - uint32_t counter = 0; + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct drm_encoder *drm_encoder; + struct drm_crtc *drm_crtc; + struct nouveau_encoder *encoder = NULL; + struct nouveau_crtc *crtc = NULL; + int crtc_index; + uint32_t unk30 = nv_rd32(NV50_PDISPLAY_UNK30_CTRL); + + for (crtc_index = 0; crtc_index < 2; crtc_index++) { + bool clock_change = false; + bool clock_ack = false; + + if (crtc_index == 0 && (unk30 & NV50_PDISPLAY_UNK30_CTRL_UPDATE_VCLK0)) + clock_change = true; + + if (crtc_index == 1 && (unk30 & NV50_PDISPLAY_UNK30_CTRL_UPDATE_VCLK1)) + clock_change = true; + + if (clock_change) + clock_ack = true; + +#if 0 + if (dev_priv->last_crtc == crtc_index) +#endif + clock_ack = true; + + list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) { + crtc = to_nouveau_crtc(drm_crtc); + if (crtc->index == crtc_index) + break; + } + + if (clock_change) + crtc->set_clock(crtc, crtc->mode); + + DRM_DEBUG("index %d clock_change %d clock_ack %d\n", crtc_index, clock_change, clock_ack); + + if (!clock_ack) + continue; + + crtc->set_clock_mode(crtc); + + list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { + encoder = to_nouveau_encoder(drm_encoder); + + if (!drm_encoder->crtc) + continue; + + if (drm_encoder->crtc == drm_crtc) + encoder->set_clock_mode(encoder, crtc->mode); + } + } +} + +void nv50_display_command(struct drm_device *dev, uint32_t mthd, uint32_t val) +{ + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer; + uint64_t start; DRM_DEBUG("mthd 0x%03X val 0x%08X\n", mthd, val); @@ -420,13 +409,28 @@ void nv50_display_command(struct drm_nouveau_private *dev_priv, NV50_PDISPLAY_CTRL_STATE_ENABLE | 0x10000 | mthd); + start = ptimer->read(dev); while (nv_rd32(NV50_PDISPLAY_CTRL_STATE) & NV50_PDISPLAY_CTRL_STATE_PENDING) { - counter++; - if (counter > 1000000) { - DRM_ERROR("You probably need a reboot now\n"); + const uint32_t super = nv_rd32(NV50_PDISPLAY_SUPERVISOR); + uint32_t state; + + state = (super & NV50_PDISPLAY_SUPERVISOR_CLK_MASK); + state >>= NV50_PDISPLAY_SUPERVISOR_CLK_MASK__SHIFT; + if (state) { + if (state == 2) + nv50_display_vclk_update(dev); + + nv_wr32(NV50_PDISPLAY_SUPERVISOR, + (super & NV50_PDISPLAY_SUPERVISOR_CLK_MASK)); + nv_wr32(NV50_PDISPLAY_UNK30_CTRL, + NV50_PDISPLAY_UNK30_CTRL_PENDING); + } + + if (ptimer->read(dev) - start > 1000000000ULL) { + DRM_ERROR("timeout: 0x610300 = 0x%08x\n", + nv_rd32(NV50_PDISPLAY_CTRL_STATE)); break; } - udelay(1); } } diff --git a/linux-core/nv50_display.h b/linux-core/nv50_display.h index a7bec9a3..72fbf025 100644 --- a/linux-core/nv50_display.h +++ b/linux-core/nv50_display.h @@ -34,31 +34,9 @@ #include "nouveau_reg.h" #include "nv50_display_commands.h" -struct nv50_crtc; -struct nv50_output; -struct nv50_connector; - -struct nv50_display { - struct drm_device *dev; - - bool preinit_done; - bool init_done; - - int last_crtc; /* crtc used for last mode set */ - - int (*pre_init) (struct nv50_display *display); - int (*init) (struct nv50_display *display); - int (*disable) (struct nv50_display *display); - int (*update) (struct nv50_display *display); -}; - -void nv50_display_command(struct drm_nouveau_private *dev_priv, uint32_t mthd, uint32_t val); +void nv50_display_command(struct drm_device *dev, uint32_t mthd, uint32_t val); struct nv50_display *nv50_get_display(struct drm_device *dev); int nv50_display_create(struct drm_device *dev); int nv50_display_destroy(struct drm_device *dev); -struct drm_framebuffer * -nv50_framebuffer_create(struct drm_device *, struct drm_gem_object *, - struct drm_mode_fb_cmd *); - #endif /* __NV50_DISPLAY_H__ */ diff --git a/linux-core/nv50_fbcon.c b/linux-core/nv50_fbcon.c index c0da05e5..dfa14ae7 100644 --- a/linux-core/nv50_fbcon.c +++ b/linux-core/nv50_fbcon.c @@ -1,624 +1,218 @@ -/* - * Copyright (C) 2008 Maarten Maathuis. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/errno.h> -#include <linux/string.h> -#include <linux/mm.h> -#include <linux/tty.h> -#include <linux/slab.h> -#include <linux/delay.h> -#include <linux/fb.h> -#include <linux/init.h> - #include "drmP.h" #include "nouveau_drv.h" -#include "nouveau_drm.h" - -#include "nv50_fbcon.h" -#include "nv50_display.h" -#include "nv50_fb.h" +#include "nouveau_dma.h" +#include "nouveau_fbcon.h" -static int nv50_fbcon_setcolreg(unsigned regno, unsigned red, unsigned green, - unsigned blue, unsigned transp, - struct fb_info *info) +static int +nv50_fbcon_sync(struct fb_info *info) { - struct nv50_fbcon_par *par = info->par; + struct nouveau_fbcon_par *par = info->par; struct drm_device *dev = par->dev; - struct drm_framebuffer *drm_fb; - - list_for_each_entry(drm_fb, &dev->mode_config.fb_kernel_list, filp_head) { - if (regno > 255) - return 1; - - /* TODO: 8 bit support */ - if (regno < 16) { - switch (drm_fb->depth) { - case 15: - drm_fb->pseudo_palette[regno] = ((red & 0xf800) >> 1) | - ((green & 0xf800) >> 6) | - ((blue & 0xf800) >> 11); - break; - case 16: - drm_fb->pseudo_palette[regno] = (red & 0xf800) | - ((green & 0xfc00) >> 5) | - ((blue & 0xf800) >> 11); - break; - case 24: - case 32: - drm_fb->pseudo_palette[regno] = ((red & 0xff00) << 8) | - (green & 0xff00) | - ((blue & 0xff00) >> 8); - break; - } + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_channel *chan = dev_priv->channel; + int ret, i; + + if (info->state != FBINFO_STATE_RUNNING || + info->flags & FBINFO_HWACCEL_DISABLED) + return 0; + + if (RING_SPACE(chan, 4)) { + DRM_ERROR("GPU lockup - switching to software fbcon\n"); + info->flags |= FBINFO_HWACCEL_DISABLED; + return 0; + } + + BEGIN_RING(chan, 0, 0x0104, 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, 0, 0x0100, 1); + OUT_RING (chan, 0); + chan->m2mf_ntfy_map[3] = 0xffffffff; + FIRE_RING (chan); + + ret = -EBUSY; + for (i = 0; i < 100000; i++) { + if (chan->m2mf_ntfy_map[3] == 0) { + ret = 0; + break; } - } - return 0; -} - -static int nv50_fbcon_check_var(struct fb_var_screeninfo *var, struct fb_info *info) -{ - struct nv50_fbcon_par *par = info->par; - struct drm_framebuffer *drm_fb = par->fb; - int depth; - - DRM_DEBUG("\n"); - - if (!var || !drm_fb || !info) { - DRM_ERROR("No var, drm_fb or info\n"); - } - - par->use_preferred_mode = false; - - if (var->pixclock == -1 || !var->pixclock) { - DRM_INFO("Using preferred mode.\n"); - par->use_preferred_mode = true; - } - - /* Need to resize the fb object !!! */ - if (var->xres > drm_fb->width || var->yres > drm_fb->height) { - DRM_ERROR("Requested width/height is greater than current fb object %dx%d > %dx%d\n", var->xres,var->yres, drm_fb->width, drm_fb->height); - DRM_ERROR("Need resizing code.\n"); - return -EINVAL; - } - - switch (var->bits_per_pixel) { - case 16: - depth = (var->green.length == 6) ? 16 : 15; - break; - case 32: - depth = (var->transp.length > 0) ? 32 : 24; - break; - default: - depth = var->bits_per_pixel; - break; + DRM_UDELAY(1); } - switch (depth) { - case 15: - var->red.offset = 10; - var->green.offset = 5; - var->blue.offset = 0; - var->red.length = 5; - var->green.length = 5; - var->blue.length = 5; - var->transp.length = 1; - var->transp.offset = 15; - break; - case 16: - var->red.offset = 11; - var->green.offset = 5; - var->blue.offset = 0; - var->red.length = 5; - var->green.length = 6; - var->blue.length = 5; - var->transp.length = 0; - var->transp.offset = 0; - break; - case 24: - var->red.offset = 16; - var->green.offset = 8; - var->blue.offset = 0; - var->red.length = 8; - var->green.length = 8; - var->blue.length = 8; - var->transp.length = 0; - var->transp.offset = 0; - break; - case 32: - var->red.offset = 16; - var->green.offset = 8; - var->blue.offset = 0; - var->red.length = 8; - var->green.length = 8; - var->blue.length = 8; - var->transp.length = 8; - var->transp.offset = 24; - break; - default: - DRM_ERROR("Invalid depth %d\n", depth); - return -EINVAL; + if (ret) { + DRM_ERROR("GPU lockup - switching to software fbcon\n"); + info->flags |= FBINFO_HWACCEL_DISABLED; + return 0; } return 0; } -static int nv50_fbcon_set_par(struct fb_info *info) +static void +nv50_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect) { - struct nv50_fbcon_par *par; - struct drm_framebuffer *drm_fb; - struct drm_connector *drm_connector; - struct drm_crtc *drm_crtc; - struct fb_var_screeninfo *var; - struct drm_display_mode *drm_mode = NULL, *t; - struct drm_device *dev; - int rval; - bool crtc_used[2] = {false, false}; - - DRM_DEBUG("\n"); - - if (!info) { - DRM_ERROR("No fb_info\n"); - return -EINVAL; - } - - par = info->par; - - if (!par) { - DRM_ERROR("No nv50_fbcon_par\n"); - return -EINVAL; - } + struct nouveau_fbcon_par *par = info->par; + struct drm_nouveau_private *dev_priv = par->dev->dev_private; + struct nouveau_channel *chan = dev_priv->channel; - drm_fb = par->fb; - var = &info->var; - dev = par->dev; + if (info->state != FBINFO_STATE_RUNNING) + return; - if (!drm_fb || !var || !dev) { - DRM_ERROR("No drm_fb, var or dev\n"); - return -EINVAL; + if (info->flags & FBINFO_HWACCEL_DISABLED) { + cfb_fillrect(info, rect); + return; } - par->use_preferred_mode = false; - - if (var->pixclock == -1 || !var->pixclock) { - DRM_INFO("Using preferred mode.\n"); - par->use_preferred_mode = true; - } - - /* FB setup */ - switch (var->bits_per_pixel) { - case 16: - drm_fb->depth = (var->green.length == 6) ? 16 : 15; - break; - case 32: - drm_fb->depth = (var->transp.length > 0) ? 32 : 24; - break; - default: - drm_fb->depth = var->bits_per_pixel; - break; - } - - drm_fb->bits_per_pixel = var->bits_per_pixel; - - info->fix.line_length = drm_fb->pitch; - info->fix.smem_len = info->fix.line_length * drm_fb->height; - /* ignoring 8bpp for the moment */ - info->fix.visual = FB_VISUAL_TRUECOLOR; - - info->screen_size = info->fix.smem_len; /* ??? */ - - /* create a drm mode */ - if (!par->use_preferred_mode) { - drm_mode = drm_mode_create(dev); - drm_mode->hdisplay = var->xres; - drm_mode->hsync_start = drm_mode->hdisplay + var->right_margin; - drm_mode->hsync_end = drm_mode->hsync_start + var->hsync_len; - drm_mode->htotal = drm_mode->hsync_end + var->left_margin; - drm_mode->vdisplay = var->yres; - drm_mode->vsync_start = drm_mode->vdisplay + var->lower_margin; - drm_mode->vsync_end = drm_mode->vsync_start + var->vsync_len; - drm_mode->vtotal = drm_mode->vsync_end + var->upper_margin; - drm_mode->clock = PICOS2KHZ(var->pixclock); - drm_mode->vrefresh = drm_mode_vrefresh(drm_mode); - drm_mode->flags = 0; - drm_mode->flags |= var->sync & FB_SYNC_HOR_HIGH_ACT ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC; - drm_mode->flags |= var->sync & FB_SYNC_VERT_HIGH_ACT ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC; - - drm_mode_set_name(drm_mode); - drm_mode_set_crtcinfo(drm_mode, CRTC_INTERLACE_HALVE_V); - } - - /* hook up crtc's */ - list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) { - enum drm_connector_status status; - struct drm_mode_set mode_set; - int crtc_count = 0; - - status = drm_connector->funcs->detect(drm_connector); - - if (status != connector_status_connected) - continue; - - memset(&mode_set, 0, sizeof(struct drm_mode_set)); - - /* set connector */ - mode_set.num_connectors = 1; - mode_set.connectors = kzalloc(sizeof(struct drm_connector *), GFP_KERNEL); - if (!mode_set.connectors) { - rval = -ENOMEM; - goto out; - } - mode_set.connectors[0] = drm_connector; - - /* set fb */ - list_for_each_entry(drm_fb, &dev->mode_config.fb_kernel_list, filp_head) { - break; /* first entry is the only entry */ - } - mode_set.fb = drm_fb; - - /* set mode */ - if (par->use_preferred_mode) { - /* find preferred mode */ - list_for_each_entry_safe(drm_mode, t, &drm_connector->modes, head) { - if (drm_mode->type & DRM_MODE_TYPE_PREFERRED) - break; - } - } - mode_set.mode = drm_mode; - - /* choose crtc it already has, if possible */ - if (drm_connector->encoder) { - struct drm_encoder *drm_encoder = drm_connector->encoder; - - if (drm_encoder->crtc) { - list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) { - if (drm_crtc == drm_encoder->crtc) { - if (!crtc_used[crtc_count]) /* still available? */ - mode_set.crtc = drm_crtc; - break; - } - - crtc_count++; - } - } - } - - /* proceed as planned */ - if (mode_set.crtc) { - mode_set.crtc->funcs->set_config(&mode_set); - crtc_used[crtc_count] = true; - } - - if (!mode_set.crtc) { - crtc_count = 0; /* reset */ - - /* choose a "random" crtc */ - list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) { - if (crtc_used[crtc_count]) { - crtc_count++; - continue; - } - - /* found a crtc */ - mode_set.crtc = drm_crtc; - - break; - } - - /* proceed as planned */ - if (mode_set.crtc) { - mode_set.crtc->funcs->set_config(&mode_set); - crtc_used[crtc_count] = true; - } - } + if (RING_SPACE(chan, 9)) { + DRM_ERROR("GPU lockup - switching to software fbcon\n"); - kfree(mode_set.connectors); + info->flags |= FBINFO_HWACCEL_DISABLED; + cfb_fillrect(info, rect); + return; } - return 0; - -out: - return rval; + BEGIN_RING(chan, NvSub2D, 0x02ac, 1); + OUT_RING (chan, rect->rop == ROP_COPY ? 3 : 1); + BEGIN_RING(chan, NvSub2D, 0x0588, 1); + OUT_RING (chan, rect->color); + BEGIN_RING(chan, NvSub2D, 0x0600, 4); + OUT_RING (chan, rect->dx); + OUT_RING (chan, rect->dy); + OUT_RING (chan, rect->dx + rect->width); + OUT_RING (chan, rect->dy + rect->height); + FIRE_RING (chan); } -static struct fb_ops nv50_fb_ops = { - .owner = THIS_MODULE, - //.fb_open = nv50_fb_open, - //.fb_read = nv50_fb_read, - //.fb_write = nv50_fb_write, - //.fb_release = nv50_fb_release, - //.fb_ioctl = nv50_fb_ioctl, - .fb_check_var = nv50_fbcon_check_var, - .fb_set_par = nv50_fbcon_set_par, - .fb_setcolreg = nv50_fbcon_setcolreg, - .fb_fillrect = cfb_fillrect, - .fb_copyarea = cfb_copyarea, - .fb_imageblit = cfb_imageblit, - //.fb_pan_display = nv50_fb_pan_display, -}; - -static int nv50_fbcon_initial_config(struct drm_device *dev) +static void +nv50_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region) { - struct drm_connector *drm_connector; - struct drm_framebuffer *drm_fb = NULL; - struct drm_mode_fb_cmd drm_fb_cmd; - enum drm_connector_status status; - uint32_t max_width = 0, max_height = 0, pitch = 0; - struct drm_gem_object *gem = NULL; - int ret = 0; - - list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) { - status = drm_connector->funcs->detect(drm_connector); - - /* find the framebuffer size */ - if (status == connector_status_connected) { - struct drm_display_mode *mode, *t; - list_for_each_entry_safe(mode, t, &drm_connector->modes, head) { - if (mode->type & DRM_MODE_TYPE_PREFERRED) { - if (mode->hdisplay > max_width) - max_width = mode->hdisplay; - if (mode->vdisplay > max_height) - max_height = mode->vdisplay; - } - } - } - } - - if (!max_width || !max_height) { - DRM_ERROR("Can't determine framebuffer size!\n"); - return -EINVAL; - } - - /* allocate framebuffer */ - pitch = (max_width + 63) & ~63; - pitch *= 4; /* TODO */ - - ret = nouveau_gem_new(dev, NULL, pitch * max_height, 0, - NOUVEAU_GEM_DOMAIN_VRAM, &gem); - if (ret) - goto out; - - ret = nouveau_gem_pin(gem, NOUVEAU_GEM_DOMAIN_VRAM); - if (ret) { - mutex_lock(&dev->struct_mutex); - drm_gem_object_unreference(gem); - mutex_unlock(&dev->struct_mutex); - goto out; - } - - memset(&drm_fb_cmd, 0, sizeof(struct drm_mode_fb_cmd)); + struct nouveau_fbcon_par *par = info->par; + struct drm_nouveau_private *dev_priv = par->dev->dev_private; + struct nouveau_channel *chan = dev_priv->channel; + + if (info->state != FBINFO_STATE_RUNNING) + return; + + if (info->flags & FBINFO_HWACCEL_DISABLED) { + cfb_copyarea(info, region); + return; + } + + if (RING_SPACE(chan, 17)) { + DRM_ERROR("GPU lockup - switching to software fbcon\n"); + + info->flags |= FBINFO_HWACCEL_DISABLED; + cfb_copyarea(info, region); + return; + } + + BEGIN_RING(chan, NvSub2D, 0x02ac, 1); + OUT_RING (chan, 3); + BEGIN_RING(chan, NvSub2D, 0x0110, 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, NvSub2D, 0x08b0, 12); + OUT_RING (chan, region->dx); + OUT_RING (chan, region->dy); + OUT_RING (chan, region->width); + OUT_RING (chan, region->height); + OUT_RING (chan, 0); + OUT_RING (chan, 1); + OUT_RING (chan, 0); + OUT_RING (chan, 1); + OUT_RING (chan, 0); + OUT_RING (chan, region->sx); + OUT_RING (chan, 0); + OUT_RING (chan, region->sy); + FIRE_RING (chan); +} - drm_fb_cmd.width = max_width; - drm_fb_cmd.height = max_height; - drm_fb_cmd.pitch = pitch; - drm_fb_cmd.bpp = 32; /* TODO */ - drm_fb_cmd.depth = 24; /* TODO */ +static void +nv50_fbcon_imageblit(struct fb_info *info, const struct fb_image *image) +{ + if (info->state != FBINFO_STATE_RUNNING) + return; - drm_fb = nv50_framebuffer_create(dev, gem, &drm_fb_cmd); - if (!drm_fb) { - ret = -EINVAL; - goto out; + if (info->flags & FBINFO_HWACCEL_DISABLED) { + cfb_imageblit(info, image); + return; } - list_add(&drm_fb->filp_head, &dev->mode_config.fb_kernel_list); - - return 0; - -out: - if (drm_fb) - drm_fb->funcs->destroy(drm_fb); - - return ret; + cfb_imageblit(info, image); } -/* - * Single framebuffer, ideally operating in clone mode across various connectors. - */ -int nv50_fbcon_init(struct drm_device *dev) +int +nv50_fbcon_accel_init(struct fb_info *info) { + struct nouveau_fbcon_par *par = info->par; + struct drm_device *dev = par->dev; struct drm_nouveau_private *dev_priv = dev->dev_private; - struct fb_info *info; - struct nv50_fbcon_par *par; - struct device *device = &dev->pdev->dev; - struct drm_framebuffer *drm_fb; - struct nv50_framebuffer *fb; - struct nouveau_gem_object *ngem; - int ret; - - ret = nv50_fbcon_initial_config(dev); - if (ret != 0) { - DRM_ERROR("nv50_fbcon_initial_config failed\n"); - return ret; - } - - list_for_each_entry(drm_fb, &dev->mode_config.fb_kernel_list, filp_head) { - break; /* first entry is the only entry */ - } - - if (!drm_fb) { - DRM_ERROR("no drm_fb found\n"); - return -EINVAL; - } - fb = to_nv50_framebuffer(drm_fb); - - ngem = nouveau_gem_object(fb->gem); - if (!ngem) { - DRM_ERROR("no buffer object for FB!\n"); - return -EINVAL; - } - - - info = framebuffer_alloc(sizeof(struct nv50_fbcon_par), device); - if (!info) { - DRM_ERROR("framebuffer_alloc failed\n"); - return -EINVAL; - } - - par = info->par; - - strcpy(info->fix.id, "nv50drmfb"); - info->fix.type = FB_TYPE_PACKED_PIXELS; - info->fix.visual = FB_VISUAL_TRUECOLOR; - info->fix.type_aux = 0; - info->fix.xpanstep = 0; /* 1 is doing it in hw */ - info->fix.ypanstep = 0; - info->fix.ywrapstep = 0; - info->fix.accel = FB_ACCEL_NONE; - info->fix.type_aux = 0; + struct nouveau_channel *chan = dev_priv->channel; + struct nouveau_gpuobj *eng2d = NULL; + int ret, format; - info->flags = FBINFO_DEFAULT; - - info->fbops = &nv50_fb_ops; - - info->fix.line_length = drm_fb->pitch; - info->fix.smem_start = dev_priv->fb_phys + ngem->bo->offset; - info->fix.smem_len = info->fix.line_length * drm_fb->height; - - info->flags = FBINFO_DEFAULT; - - ret = drm_bo_kmap(ngem->bo, 0, ngem->bo->mem.num_pages, &fb->kmap); - if (ret) { - DRM_ERROR("Error mapping framebuffer: %d\n", ret); - return ret; - } - - info->screen_base = fb->kmap.virtual; - info->screen_size = info->fix.smem_len; /* FIXME */ - - info->pseudo_palette = drm_fb->pseudo_palette; - info->var.xres_virtual = drm_fb->width; - info->var.yres_virtual = drm_fb->height; - info->var.bits_per_pixel = drm_fb->bits_per_pixel; - info->var.xoffset = 0; - info->var.yoffset = 0; - info->var.activate = FB_ACTIVATE_NOW; - info->var.height = -1; - info->var.width = -1; - - /* TODO: improve this */ - info->var.xres = drm_fb->width; - info->var.yres = drm_fb->height; - - info->fix.mmio_start = drm_get_resource_start(dev, 0); - info->fix.mmio_len = drm_get_resource_len(dev, 0); - - DRM_DEBUG("fb depth is %d\n", drm_fb->depth); - DRM_DEBUG(" pitch is %d\n", drm_fb->pitch); - - switch(drm_fb->depth) { - case 15: - info->var.red.offset = 10; - info->var.green.offset = 5; - info->var.blue.offset = 0; - info->var.red.length = 5; - info->var.green.length = 5; - info->var.blue.length = 5; - info->var.transp.offset = 15; - info->var.transp.length = 1; - break; + switch (info->var.bits_per_pixel) { case 16: - info->var.red.offset = 11; - info->var.green.offset = 5; - info->var.blue.offset = 0; - info->var.red.length = 5; - info->var.green.length = 6; - info->var.blue.length = 5; - info->var.transp.offset = 0; - break; - case 24: - info->var.red.offset = 16; - info->var.green.offset = 8; - info->var.blue.offset = 0; - info->var.red.length = 8; - info->var.green.length = 8; - info->var.blue.length = 8; - info->var.transp.offset = 0; - info->var.transp.length = 0; - break; - case 32: - info->var.red.offset = 16; - info->var.green.offset = 8; - info->var.blue.offset = 0; - info->var.red.length = 8; - info->var.green.length = 8; - info->var.blue.length = 8; - info->var.transp.offset = 24; - info->var.transp.length = 8; + format = 0xe8; break; default: + format = 0xe6; break; } - drm_fb->fbdev = info; - par->dev = dev; - par->fb = drm_fb; - - nv50_fbcon_accel_init(info); - - register_framebuffer(info); - - DRM_INFO("nv50drmfb initialised\n"); - - return 0; -} - -int nv50_fbcon_destroy(struct drm_device *dev) -{ - struct drm_framebuffer *drm_fb; - struct nv50_framebuffer *fb; - struct fb_info *info; - - list_for_each_entry(drm_fb, &dev->mode_config.fb_kernel_list, filp_head) { - break; /* first entry is the only entry */ - } - - if (!drm_fb) { - DRM_ERROR("No framebuffer to destroy\n"); - return -EINVAL; - } - fb = to_nv50_framebuffer(drm_fb); - - info = drm_fb->fbdev; - if (!info) { - DRM_ERROR("No fb_info\n"); - return -EINVAL; - } + ret = nouveau_gpuobj_gr_new(dev_priv->channel, 0x502d, &eng2d); + if (ret) + return ret; - unregister_framebuffer(info); + ret = nouveau_gpuobj_ref_add(dev, dev_priv->channel, Nv2D, eng2d, NULL); + if (ret) + return ret; - if (fb->kmap.virtual) - drm_bo_kunmap(&fb->kmap); - if (fb->gem) { - mutex_lock(&dev->struct_mutex); - drm_gem_object_unreference(fb->gem); - mutex_unlock(&dev->struct_mutex); + ret = RING_SPACE(chan, 34); + if (ret) { + DRM_ERROR("GPU lockup - switching to software fbcon\n"); + return ret; } - framebuffer_release(info); - + BEGIN_RING(chan, NvSub2D, 0x0000, 1); + OUT_RING (chan, Nv2D); + BEGIN_RING(chan, NvSub2D, 0x0180, 4); + OUT_RING (chan, NvNotify0); + OUT_RING (chan, chan->vram_handle); + OUT_RING (chan, chan->vram_handle); + OUT_RING (chan, chan->vram_handle); + BEGIN_RING(chan, NvSub2D, 0x0290, 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, NvSub2D, 0x0888, 1); + OUT_RING (chan, 1); + BEGIN_RING(chan, NvSub2D, 0x02a0, 1); + OUT_RING (chan, 0x55); + BEGIN_RING(chan, NvSub2D, 0x0580, 2); + OUT_RING (chan, 4); + OUT_RING (chan, format); + BEGIN_RING(chan, NvSub2D, 0x0200, 2); + OUT_RING (chan, format); + OUT_RING (chan, 1); + BEGIN_RING(chan, NvSub2D, 0x0214, 5); + OUT_RING (chan, info->fix.line_length); + OUT_RING (chan, info->var.xres_virtual); + OUT_RING (chan, info->var.yres_virtual); + OUT_RING (chan, 0); + OUT_RING (chan, info->fix.smem_start - dev_priv->fb_phys + + dev_priv->vm_vram_base); + BEGIN_RING(chan, NvSub2D, 0x0230, 2); + OUT_RING (chan, format); + OUT_RING (chan, 1); + BEGIN_RING(chan, NvSub2D, 0x0244, 5); + OUT_RING (chan, info->fix.line_length); + OUT_RING (chan, info->var.xres_virtual); + OUT_RING (chan, info->var.yres_virtual); + OUT_RING (chan, 0); + OUT_RING (chan, info->fix.smem_start - dev_priv->fb_phys + + dev_priv->vm_vram_base); + + info->fbops->fb_fillrect = nv50_fbcon_fillrect; + info->fbops->fb_copyarea = nv50_fbcon_copyarea; + info->fbops->fb_imageblit = nv50_fbcon_imageblit; + info->fbops->fb_sync = nv50_fbcon_sync; return 0; } + diff --git a/linux-core/nv50_fbcon_accel.c b/linux-core/nv50_fbcon_accel.c deleted file mode 100644 index b067d0df..00000000 --- a/linux-core/nv50_fbcon_accel.c +++ /dev/null @@ -1,216 +0,0 @@ -#include "drmP.h" -#include "nouveau_drv.h" -#include "nouveau_dma.h" -#include "nv50_fbcon.h" - -static int -nv50_fbcon_sync(struct fb_info *info) -{ - struct nv50_fbcon_par *par = info->par; - struct drm_device *dev = par->dev; - struct drm_nouveau_private *dev_priv = dev->dev_private; - struct nouveau_channel *chan = dev_priv->channel; - int ret, i; - - if (info->state != FBINFO_STATE_RUNNING || - info->flags & FBINFO_HWACCEL_DISABLED) - return 0; - - if (RING_SPACE(chan, 4)) { - DRM_ERROR("GPU lockup - switching to software fbcon\n"); - info->flags |= FBINFO_HWACCEL_DISABLED; - return 0; - } - - BEGIN_RING(chan, 0, 0x0104, 1); - OUT_RING (chan, 0); - BEGIN_RING(chan, 0, 0x0100, 1); - OUT_RING (chan, 0); - chan->m2mf_ntfy_map[3] = 0xffffffff; - FIRE_RING (chan); - - ret = -EBUSY; - for (i = 0; i < 100000; i++) { - if (chan->m2mf_ntfy_map[3] == 0) { - ret = 0; - break; - } - DRM_UDELAY(1); - } - - if (ret) { - DRM_ERROR("GPU lockup - switching to software fbcon\n"); - info->flags |= FBINFO_HWACCEL_DISABLED; - return 0; - } - - return 0; -} - -static void -nv50_fbcon_fillrect(struct fb_info *info, const struct fb_fillrect *rect) -{ - struct nv50_fbcon_par *par = info->par; - struct drm_nouveau_private *dev_priv = par->dev->dev_private; - struct nouveau_channel *chan = dev_priv->channel; - - if (info->state != FBINFO_STATE_RUNNING) - return; - - if (info->flags & FBINFO_HWACCEL_DISABLED) { - cfb_fillrect(info, rect); - return; - } - - if (RING_SPACE(chan, 9)) { - DRM_ERROR("GPU lockup - switching to software fbcon\n"); - - info->flags |= FBINFO_HWACCEL_DISABLED; - cfb_fillrect(info, rect); - return; - } - - BEGIN_RING(chan, NvSub2D, 0x02ac, 1); - OUT_RING (chan, rect->rop == ROP_COPY ? 3 : 1); - BEGIN_RING(chan, NvSub2D, 0x0588, 1); - OUT_RING (chan, rect->color); - BEGIN_RING(chan, NvSub2D, 0x0600, 4); - OUT_RING (chan, rect->dx); - OUT_RING (chan, rect->dy); - OUT_RING (chan, rect->dx + rect->width); - OUT_RING (chan, rect->dy + rect->height); - FIRE_RING (chan); -} - -static void -nv50_fbcon_copyarea(struct fb_info *info, const struct fb_copyarea *region) -{ - struct nv50_fbcon_par *par = info->par; - struct drm_nouveau_private *dev_priv = par->dev->dev_private; - struct nouveau_channel *chan = dev_priv->channel; - - if (info->state != FBINFO_STATE_RUNNING) - return; - - if (info->flags & FBINFO_HWACCEL_DISABLED) { - cfb_copyarea(info, region); - return; - } - - if (RING_SPACE(chan, 17)) { - DRM_ERROR("GPU lockup - switching to software fbcon\n"); - - info->flags |= FBINFO_HWACCEL_DISABLED; - cfb_copyarea(info, region); - return; - } - - BEGIN_RING(chan, NvSub2D, 0x02ac, 1); - OUT_RING (chan, 3); - BEGIN_RING(chan, NvSub2D, 0x0110, 1); - OUT_RING (chan, 0); - BEGIN_RING(chan, NvSub2D, 0x08b0, 12); - OUT_RING (chan, region->dx); - OUT_RING (chan, region->dy); - OUT_RING (chan, region->width); - OUT_RING (chan, region->height); - OUT_RING (chan, 0); - OUT_RING (chan, 1); - OUT_RING (chan, 0); - OUT_RING (chan, 1); - OUT_RING (chan, 0); - OUT_RING (chan, region->sx); - OUT_RING (chan, 0); - OUT_RING (chan, region->sy); - FIRE_RING (chan); -} - -static void -nv50_fbcon_imageblit(struct fb_info *info, const struct fb_image *image) -{ - if (info->state != FBINFO_STATE_RUNNING) - return; - - if (info->flags & FBINFO_HWACCEL_DISABLED) { - cfb_imageblit(info, image); - return; - } - - cfb_imageblit(info, image); -} - -int -nv50_fbcon_accel_init(struct fb_info *info) -{ - struct nv50_fbcon_par *par = info->par; - struct drm_device *dev = par->dev; - struct drm_nouveau_private *dev_priv = dev->dev_private; - struct nouveau_channel *chan = dev_priv->channel; - struct nouveau_gpuobj *eng2d = NULL; - int ret, format; - - switch (info->var.bits_per_pixel) { - case 16: - format = 0xe8; - break; - default: - format = 0xe6; - break; - } - - ret = nouveau_gpuobj_gr_new(dev_priv->channel, 0x502d, &eng2d); - if (ret) - return ret; - - ret = nouveau_gpuobj_ref_add(dev, dev_priv->channel, Nv2D, eng2d, NULL); - if (ret) - return ret; - - ret = RING_SPACE(chan, 34); - if (ret) { - DRM_ERROR("GPU lockup - switching to software fbcon\n"); - return ret; - } - - BEGIN_RING(chan, NvSub2D, 0x0000, 1); - OUT_RING (chan, Nv2D); - BEGIN_RING(chan, NvSub2D, 0x0180, 4); - OUT_RING (chan, NvNotify0); - OUT_RING (chan, chan->vram_handle); - OUT_RING (chan, chan->vram_handle); - OUT_RING (chan, chan->vram_handle); - BEGIN_RING(chan, NvSub2D, 0x0290, 1); - OUT_RING (chan, 0); - BEGIN_RING(chan, NvSub2D, 0x0888, 1); - OUT_RING (chan, 1); - BEGIN_RING(chan, NvSub2D, 0x02a0, 1); - OUT_RING (chan, 0x55); - BEGIN_RING(chan, NvSub2D, 0x0580, 2); - OUT_RING (chan, 4); - OUT_RING (chan, format); - BEGIN_RING(chan, NvSub2D, 0x0200, 2); - OUT_RING (chan, format); - OUT_RING (chan, 1); - BEGIN_RING(chan, NvSub2D, 0x0214, 5); - OUT_RING (chan, info->fix.line_length); - OUT_RING (chan, info->var.xres_virtual); - OUT_RING (chan, info->var.yres_virtual); - OUT_RING (chan, 0); - OUT_RING (chan, info->fix.smem_start - dev_priv->fb_phys); - BEGIN_RING(chan, NvSub2D, 0x0230, 2); - OUT_RING (chan, format); - OUT_RING (chan, 1); - BEGIN_RING(chan, NvSub2D, 0x0244, 5); - OUT_RING (chan, info->fix.line_length); - OUT_RING (chan, info->var.xres_virtual); - OUT_RING (chan, info->var.yres_virtual); - OUT_RING (chan, 0); - OUT_RING (chan, info->fix.smem_start - dev_priv->fb_phys); - - info->fbops->fb_fillrect = nv50_fbcon_fillrect; - info->fbops->fb_copyarea = nv50_fbcon_copyarea; - info->fbops->fb_imageblit = nv50_fbcon_imageblit; - info->fbops->fb_sync = nv50_fbcon_sync; - return 0; -} - diff --git a/linux-core/nv50_i2c.c b/linux-core/nv50_i2c.c index 7a918739..e3a64309 100644 --- a/linux-core/nv50_i2c.c +++ b/linux-core/nv50_i2c.c @@ -319,7 +319,7 @@ static bool nv50_i2c_write(struct nv50_i2c_channel *chan, uint8_t address, uint8 static int nv50_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num) { struct nv50_i2c_channel *chan = i2c_get_adapdata(i2c_adap); - bool rval; + bool rval = 0; int i; for (i = 0; i < num; i++) { diff --git a/linux-core/nv50_sor.c b/linux-core/nv50_sor.c index 42d39a55..fd29ffc9 100644 --- a/linux-core/nv50_sor.c +++ b/linux-core/nv50_sor.c @@ -24,132 +24,199 @@ * */ -#include "nv50_output.h" - -static int nv50_sor_validate_mode(struct nv50_output *output, - struct drm_display_mode *mode) +#include "drmP.h" +#include "drm_crtc_helper.h" +#include "nouveau_reg.h" +#include "nouveau_drv.h" +#include "nouveau_dma.h" +#include "nouveau_encoder.h" +#include "nouveau_connector.h" +#include "nouveau_crtc.h" +#include "nv50_display.h" +#include "nv50_display_commands.h" + +static void +nv50_sor_disconnect(struct nouveau_encoder *encoder) { - DRM_DEBUG("\n"); - - if (mode->clock > 165000) /* no dual link until we figure it out completely */ - return MODE_CLOCK_HIGH; + struct drm_device *dev = encoder->base.dev; + uint32_t offset = encoder->or * 0x40; - if (mode->clock < 25000) - return MODE_CLOCK_LOW; - - if (output->native_mode->hdisplay > 0 && output->native_mode->vdisplay > 0) { - if (mode->hdisplay > output->native_mode->hdisplay || mode->vdisplay > output->native_mode->vdisplay) - return MODE_PANEL; - } + DRM_DEBUG("Disconnecting SOR %d\n", encoder->or); - return MODE_OK; + OUT_MODE(NV50_SOR0_MODE_CTRL + offset, NV50_SOR_MODE_CTRL_OFF); + OUT_MODE(NV50_UPDATE_DISPLAY, 0); } -static int nv50_sor_execute_mode(struct nv50_output *output, bool disconnect) +static int +nv50_sor_set_clock_mode(struct nouveau_encoder *encoder, + struct drm_display_mode *mode) { - struct drm_encoder *drm_encoder = &output->base; + struct drm_encoder *drm_encoder = &encoder->base; struct drm_nouveau_private *dev_priv = drm_encoder->dev->dev_private; - struct nv50_crtc *crtc = to_nv50_crtc(drm_encoder->crtc); - struct drm_display_mode *desired_mode = NULL; - uint32_t offset = output->or * 0x40; - uint32_t mode_ctl = NV50_SOR_MODE_CTRL_OFF; + uint32_t limit = 165000; - DRM_DEBUG("or %d\n", output->or); + DRM_DEBUG("or %d\n", encoder->or); - if (disconnect) { - DRM_DEBUG("Disconnecting SOR\n"); - OUT_MODE(NV50_SOR0_MODE_CTRL + offset, mode_ctl); + /* We don't yet know what to do, if anything at all. */ + if (encoder->base.encoder_type == DRM_MODE_ENCODER_LVDS) return 0; - } - desired_mode = (crtc->use_native_mode ? crtc->native_mode : crtc->mode); + /* 0x70000 was a late addition to nv, mentioned as fixing tmds + * initialisation on certain gpu's. I presume it's some kind of + * clock setting, but what precisely i do not know. + */ + nv_wr32(NV50_PDISPLAY_SOR_CLK_CLK_CTRL2(encoder->or), + 0x70000 | ((mode->clock > limit) ? 0x101 : 0)); - if (output->base.encoder_type == DRM_MODE_ENCODER_LVDS) { - mode_ctl |= NV50_SOR_MODE_CTRL_LVDS; - } else { - mode_ctl |= NV50_SOR_MODE_CTRL_TMDS; - if (desired_mode->clock > 165000) - mode_ctl |= NV50_SOR_MODE_CTRL_TMDS_DUAL_LINK; + return 0; +} + +static void nv50_sor_dpms(struct drm_encoder *drm_encoder, int mode) +{ + struct drm_device *dev = drm_encoder->dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); + uint32_t val; + int or = encoder->or; + + DRM_DEBUG("or %d\n", encoder->or); + + /* wait for it to be done */ + if (!nv_wait(NV50_PDISPLAY_SOR_REGS_DPMS_CTRL(or), + NV50_PDISPLAY_SOR_REGS_DPMS_CTRL_PENDING, 0)) { + DRM_ERROR("timeout: SOR_DPMS_CTRL_PENDING(%d) == 0\n", or); + DRM_ERROR("SOR_DPMS_CTRL(%d) = 0x%08x\n", or, + nv_rd32(NV50_PDISPLAY_SOR_REGS_DPMS_CTRL(or))); } - if (crtc->index == 1) - mode_ctl |= NV50_SOR_MODE_CTRL_CRTC1; - else - mode_ctl |= NV50_SOR_MODE_CTRL_CRTC0; + val = nv_rd32(NV50_PDISPLAY_SOR_REGS_DPMS_CTRL(or)); - if (desired_mode->flags & DRM_MODE_FLAG_NHSYNC) - mode_ctl |= NV50_SOR_MODE_CTRL_NHSYNC; + if (mode == DRM_MODE_DPMS_ON) + val |= NV50_PDISPLAY_SOR_REGS_DPMS_CTRL_ON; + else + val &= ~NV50_PDISPLAY_SOR_REGS_DPMS_CTRL_ON; - if (desired_mode->flags & DRM_MODE_FLAG_NVSYNC) - mode_ctl |= NV50_SOR_MODE_CTRL_NVSYNC; + nv_wr32(NV50_PDISPLAY_SOR_REGS_DPMS_CTRL(or), val | + NV50_PDISPLAY_SOR_REGS_DPMS_CTRL_PENDING); +} - OUT_MODE(NV50_SOR0_MODE_CTRL + offset, mode_ctl); +static void nv50_sor_save(struct drm_encoder *drm_encoder) +{ + DRM_ERROR("!!\n"); +} - return 0; +static void nv50_sor_restore(struct drm_encoder *drm_encoder) +{ + DRM_ERROR("!!\n"); } -static int nv50_sor_set_clock_mode(struct nv50_output *output) +static struct nouveau_connector * +nouveau_encoder_connector_get(struct nouveau_encoder *encoder) { - struct drm_encoder *drm_encoder = &output->base; - struct drm_nouveau_private *dev_priv = drm_encoder->dev->dev_private; - struct nv50_crtc *crtc = to_nv50_crtc(drm_encoder->crtc); - uint32_t limit = 165000; - struct drm_display_mode *mode; + struct drm_device *dev = encoder->base.dev; + struct drm_connector *drm_connector; - DRM_DEBUG("or %d\n", output->or); + list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head) { + if (drm_connector->encoder == &encoder->base) + return to_nouveau_connector(drm_connector); + } - /* We don't yet know what to do, if anything at all. */ - if (output->base.encoder_type == DRM_MODE_ENCODER_LVDS) - return 0; + return NULL; +} - if (crtc->use_native_mode) - mode = crtc->native_mode; - else - mode = crtc->mode; +static bool nv50_sor_mode_fixup(struct drm_encoder *drm_encoder, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); + struct nouveau_connector *connector; + + connector = nouveau_encoder_connector_get(encoder); + if (!connector) + return false; + + if ((connector->scaling_mode != DRM_MODE_SCALE_NON_GPU && + connector->scaling_mode != DRM_MODE_SCALE_NO_SCALE) && + connector->native_mode) { + int id = adjusted_mode->base.id; + *adjusted_mode = *connector->native_mode; + adjusted_mode->base.id = id; + } - /* 0x70000 was a late addition to nv, mentioned as fixing tmds initialisation on certain gpu's. */ - /* I presume it's some kind of clock setting, but what precisely i do not know. */ - nv_wr32(NV50_PDISPLAY_SOR_CLK_CLK_CTRL2(output->or), 0x70000 | ((mode->clock > limit) ? 0x101 : 0)); + return true; +} - return 0; +static void nv50_sor_prepare(struct drm_encoder *drm_encoder) +{ + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); + + nv50_sor_dpms(drm_encoder, DRM_MODE_DPMS_OFF); + nv50_sor_disconnect(encoder); } -static int nv50_sor_set_power_mode(struct nv50_output *output, int mode) +static void nv50_sor_commit(struct drm_encoder *drm_encoder) { - struct drm_nouveau_private *dev_priv = output->base.dev->dev_private; - uint32_t val; - int or = output->or; + nv50_sor_dpms(drm_encoder, DRM_MODE_DPMS_ON); +} - DRM_DEBUG("or %d\n", output->or); +static void nv50_sor_mode_set(struct drm_encoder *drm_encoder, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); + struct drm_device *dev = drm_encoder->dev; + struct nouveau_crtc *crtc = to_nouveau_crtc(drm_encoder->crtc); + uint32_t offset = encoder->or * 0x40; + uint32_t mode_ctl = NV50_SOR_MODE_CTRL_OFF; - /* wait for it to be done */ - while (nv_rd32(NV50_PDISPLAY_SOR_REGS_DPMS_CTRL(or)) & NV50_PDISPLAY_SOR_REGS_DPMS_CTRL_PENDING); + DRM_DEBUG("or %d\n", encoder->or); - val = nv_rd32(NV50_PDISPLAY_SOR_REGS_DPMS_CTRL(or)); + if (encoder->base.encoder_type == DRM_MODE_ENCODER_LVDS) { + mode_ctl |= NV50_SOR_MODE_CTRL_LVDS; + } else { + mode_ctl |= NV50_SOR_MODE_CTRL_TMDS; + if (mode->clock > 165000) + mode_ctl |= NV50_SOR_MODE_CTRL_TMDS_DUAL_LINK; + } - if (mode == DRM_MODE_DPMS_ON) - val |= NV50_PDISPLAY_SOR_REGS_DPMS_CTRL_ON; + if (crtc->index == 1) + mode_ctl |= NV50_SOR_MODE_CTRL_CRTC1; else - val &= ~NV50_PDISPLAY_SOR_REGS_DPMS_CTRL_ON; + mode_ctl |= NV50_SOR_MODE_CTRL_CRTC0; - nv_wr32(NV50_PDISPLAY_SOR_REGS_DPMS_CTRL(or), val | NV50_PDISPLAY_SOR_REGS_DPMS_CTRL_PENDING); + if (mode->flags & DRM_MODE_FLAG_NHSYNC) + mode_ctl |= NV50_SOR_MODE_CTRL_NHSYNC; - return 0; + if (mode->flags & DRM_MODE_FLAG_NVSYNC) + mode_ctl |= NV50_SOR_MODE_CTRL_NVSYNC; + + OUT_MODE(NV50_SOR0_MODE_CTRL + offset, mode_ctl); + OUT_MODE(NV50_UPDATE_DISPLAY, 0); } +static const struct drm_encoder_helper_funcs nv50_sor_helper_funcs = { + .dpms = nv50_sor_dpms, + .save = nv50_sor_save, + .restore = nv50_sor_restore, + .mode_fixup = nv50_sor_mode_fixup, + .prepare = nv50_sor_prepare, + .commit = nv50_sor_commit, + .mode_set = nv50_sor_mode_set, + .detect = NULL +}; + static void nv50_sor_destroy(struct drm_encoder *drm_encoder) { - struct nv50_output *output = to_nv50_output(drm_encoder); + struct nouveau_encoder *encoder = to_nouveau_encoder(drm_encoder); DRM_DEBUG("\n"); if (!drm_encoder) return; - drm_encoder_cleanup(&output->base); + drm_encoder_cleanup(&encoder->base); - kfree(output->native_mode); - kfree(output); + kfree(encoder); } static const struct drm_encoder_funcs nv50_sor_encoder_funcs = { @@ -159,7 +226,7 @@ static const struct drm_encoder_funcs nv50_sor_encoder_funcs = { int nv50_sor_create(struct drm_device *dev, struct dcb_entry *entry) { struct drm_nouveau_private *dev_priv = dev->dev_private; - struct nv50_output *output = NULL; + struct nouveau_encoder *encoder = NULL; int type; DRM_DEBUG("\n"); @@ -177,35 +244,26 @@ int nv50_sor_create(struct drm_device *dev, struct dcb_entry *entry) return -EINVAL; } - output = kzalloc(sizeof(*output), GFP_KERNEL); - if (!output) - return -ENOMEM; - - output->native_mode = kzalloc(sizeof(*output->native_mode), GFP_KERNEL); - if (!output->native_mode) { - kfree(output); + encoder = kzalloc(sizeof(*encoder), GFP_KERNEL); + if (!encoder) return -ENOMEM; - } - output->dcb_entry = entry; - output->or = ffs(entry->or) - 1; + encoder->dcb_entry = entry; + encoder->or = ffs(entry->or) - 1; /* Set function pointers. */ - output->validate_mode = nv50_sor_validate_mode; - output->execute_mode = nv50_sor_execute_mode; - output->set_clock_mode = nv50_sor_set_clock_mode; - output->set_power_mode = nv50_sor_set_power_mode; - output->detect = NULL; + encoder->set_clock_mode = nv50_sor_set_clock_mode; - drm_encoder_init(dev, &output->base, &nv50_sor_encoder_funcs, type); + drm_encoder_init(dev, &encoder->base, &nv50_sor_encoder_funcs, type); + drm_encoder_helper_add(&encoder->base, &nv50_sor_helper_funcs); /* I've never seen possible crtc's restricted. */ - output->base.possible_crtcs = 3; - output->base.possible_clones = 0; + encoder->base.possible_crtcs = 3; + encoder->base.possible_clones = 0; /* Some default state, unknown what it precisely means. */ - if (output->base.encoder_type == DRM_MODE_ENCODER_TMDS) { - int or = output->or; + if (encoder->base.encoder_type == DRM_MODE_ENCODER_TMDS) { + int or = encoder->or; nv_wr32(NV50_PDISPLAY_SOR_REGS_UNK_00C(or), 0x03010700); nv_wr32(NV50_PDISPLAY_SOR_REGS_UNK_010(or), 0x0000152f); diff --git a/shared-core/nouveau_irq.c b/shared-core/nouveau_irq.c index 3c0d192c..6bcfd82c 100644 --- a/shared-core/nouveau_irq.c +++ b/shared-core/nouveau_irq.c @@ -37,12 +37,8 @@ #include "nouveau_reg.h" #include "nouveau_swmthd.h" -/* needed for interrupt based vpll changes */ -#include "nv50_display.h" -#include "nv50_crtc.h" -#include "nv50_output.h" /* needed for hotplug irq */ -#include "nv50_connector.h" +#include "nouveau_connector.h" void nouveau_irq_preinstall(struct drm_device *dev) @@ -535,8 +531,6 @@ nouveau_nv50_display_irq_handler(struct drm_device *dev) { struct drm_nouveau_private *dev_priv = dev->dev_private; uint32_t val = nv_rd32(NV50_PDISPLAY_SUPERVISOR); - struct drm_encoder *drm_encoder; - struct drm_crtc *drm_crtc; DRM_DEBUG("NV50_PDISPLAY_SUPERVISOR - 0x%08X\n", val); @@ -546,71 +540,6 @@ nouveau_nv50_display_irq_handler(struct drm_device *dev) val &= ~NV50_PDISPLAY_SUPERVISOR_CRTCn; } - /* clock setting amongst other things. */ - if (val & NV50_PDISPLAY_SUPERVISOR_CLK_MASK) { - uint32_t state = (val & NV50_PDISPLAY_SUPERVISOR_CLK_MASK) >> NV50_PDISPLAY_SUPERVISOR_CLK_MASK__SHIFT; - - DRM_DEBUG("state %d\n", state); - - /* Set pll */ - if (state == 2) { - struct nv50_display *display = nv50_get_display(dev); - struct nv50_output *output = NULL; - struct nv50_crtc *crtc = NULL; - int crtc_index; - - uint32_t unk30 = nv_rd32(NV50_PDISPLAY_UNK30_CTRL); - - for (crtc_index = 0; crtc_index < 2; crtc_index++) { - bool clock_change = false; - bool clock_ack = false; - - if (crtc_index == 0 && (unk30 & NV50_PDISPLAY_UNK30_CTRL_UPDATE_VCLK0)) - clock_change = true; - - if (crtc_index == 1 && (unk30 & NV50_PDISPLAY_UNK30_CTRL_UPDATE_VCLK1)) - clock_change = true; - - if (clock_change) - clock_ack = true; - - if (display->last_crtc == crtc_index) - clock_ack = true; - - list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) { - crtc = to_nv50_crtc(drm_crtc); - if (crtc->index == crtc_index) - break; - } - - if (clock_change) - crtc->set_clock(crtc); - - DRM_DEBUG("index %d clock_change %d clock_ack %d\n", crtc_index, clock_change, clock_ack); - - if (!clock_ack) - continue; - - crtc->set_clock_mode(crtc); - - list_for_each_entry(drm_encoder, &dev->mode_config.encoder_list, head) { - output = to_nv50_output(drm_encoder); - - if (!drm_encoder->crtc) - continue; - - if (drm_encoder->crtc == drm_crtc) - output->set_clock_mode(output); - } - } - } - - nv_wr32(NV50_PDISPLAY_UNK30_CTRL, NV50_PDISPLAY_UNK30_CTRL_PENDING); - nv_wr32(NV50_PDISPLAY_SUPERVISOR, val & NV50_PDISPLAY_SUPERVISOR_CLK_MASK); - - val &= ~NV50_PDISPLAY_SUPERVISOR_CLK_MASK; - } - if (val) DRM_ERROR("unsupported NV50_DISPLAY_INTR - 0x%08X\n", val); diff --git a/shared-core/nouveau_state.c b/shared-core/nouveau_state.c index d26be48d..c023557d 100644 --- a/shared-core/nouveau_state.c +++ b/shared-core/nouveau_state.c @@ -26,10 +26,10 @@ #include "drmP.h" #include "drm.h" #include "drm_sarea.h" +#include "drm_crtc_helper.h" #include "nouveau_drv.h" #include "nouveau_drm.h" #include "nv50_display.h" -#include "nv50_fbcon.h" static int nouveau_stub_init(struct drm_device *dev) { return 0; } static void nouveau_stub_takedown(struct drm_device *dev) {} @@ -350,11 +350,8 @@ nouveau_card_init(struct drm_device *dev) dev_priv->init_state = NOUVEAU_CARD_INIT_DONE; - if (drm_core_check_feature(dev, DRIVER_MODESET)) { - ret = nv50_fbcon_init(dev); - if (ret) - return ret; - } + if (drm_core_check_feature(dev, DRIVER_MODESET)) + drm_helper_initial_config(dev, false); return 0; } @@ -626,7 +623,6 @@ int nouveau_unload(struct drm_device *dev) struct drm_nouveau_private *dev_priv = dev->dev_private; if (drm_core_check_feature(dev, DRIVER_MODESET)) { - nv50_fbcon_destroy(dev); nv50_display_destroy(dev); nouveau_close(dev); } |