nouveau_display.c revision 2a44e4997c5fee8e1da1589ff57e0bd1c53f03ce
16ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs/* 26ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * Copyright (C) 2008 Maarten Maathuis. 36ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * All Rights Reserved. 46ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * 56ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * Permission is hereby granted, free of charge, to any person obtaining 66ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * a copy of this software and associated documentation files (the 76ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * "Software"), to deal in the Software without restriction, including 86ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * without limitation the rights to use, copy, modify, merge, publish, 96ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * distribute, sublicense, and/or sell copies of the Software, and to 106ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * permit persons to whom the Software is furnished to do so, subject to 116ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * the following conditions: 126ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * 136ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * The above copyright notice and this permission notice (including the 146ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * next paragraph) shall be included in all copies or substantial 156ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * portions of the Software. 166ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * 176ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 186ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 196ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 206ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 216ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 226ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 236ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 246ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs * 256ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs */ 266ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 276ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs#include "drmP.h" 286ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs#include "drm_crtc_helper.h" 296ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs#include "nouveau_drv.h" 306ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs#include "nouveau_fb.h" 316ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs#include "nouveau_fbcon.h" 32042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez#include "nouveau_hw.h" 33332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez#include "nouveau_crtc.h" 34332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez#include "nouveau_dma.h" 35de69185573586302ada2e59ba41835df36986277Ben Skeggs#include "nouveau_connector.h" 3645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs#include "nv50_display.h" 376ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 386ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsstatic void 396ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsnouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb) 406ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs{ 416ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); 426ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 43bc9025bdc4e2b591734cca17697093845007b63dLuca Barbieri if (fb->nvbo) 44bc9025bdc4e2b591734cca17697093845007b63dLuca Barbieri drm_gem_object_unreference_unlocked(fb->nvbo->gem); 456ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 466ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs drm_framebuffer_cleanup(drm_fb); 476ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs kfree(fb); 486ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs} 496ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 506ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsstatic int 516ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsnouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb, 526ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs struct drm_file *file_priv, 536ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs unsigned int *handle) 546ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs{ 556ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); 566ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 576ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs return drm_gem_handle_create(file_priv, fb->nvbo->gem, handle); 586ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs} 596ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 606ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsstatic const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = { 616ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs .destroy = nouveau_user_framebuffer_destroy, 626ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs .create_handle = nouveau_user_framebuffer_create_handle, 636ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs}; 646ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 65386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlieint 6645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggsnouveau_framebuffer_init(struct drm_device *dev, 6745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs struct nouveau_framebuffer *nv_fb, 68308e5bcbdb10452e8aba31aa21432fb67ee46d72Jesse Barnes struct drm_mode_fb_cmd2 *mode_cmd, 6945c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs struct nouveau_bo *nvbo) 706ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs{ 7145c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs struct drm_nouveau_private *dev_priv = dev->dev_private; 7245c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs struct drm_framebuffer *fb = &nv_fb->base; 736ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs int ret; 746ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 7545c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs ret = drm_framebuffer_init(dev, fb, &nouveau_framebuffer_funcs); 766ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs if (ret) { 77386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie return ret; 786ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs } 796ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 8045c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs drm_helper_mode_fill_fb_struct(fb, mode_cmd); 8145c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs nv_fb->nvbo = nvbo; 8245c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs 8345c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs if (dev_priv->card_type >= NV_50) { 8445c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs u32 tile_flags = nouveau_bo_tile_layout(nvbo); 8545c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs if (tile_flags == 0x7a00 || 8645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs tile_flags == 0xfe00) 8745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs nv_fb->r_dma = NvEvoFB32; 8845c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs else 8945c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs if (tile_flags == 0x7000) 9045c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs nv_fb->r_dma = NvEvoFB16; 9145c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs else 9245c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs nv_fb->r_dma = NvEvoVRAM_LP; 9345c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs 9445c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs switch (fb->depth) { 9545c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 8: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_8; break; 9645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 15: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_15; break; 9745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 16: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_16; break; 9845c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 24: 9945c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 32: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_24; break; 10045c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 30: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_30; break; 10145c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs default: 10245c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs NV_ERROR(dev, "unknown depth %d\n", fb->depth); 10345c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs return -EINVAL; 10445c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs } 10545c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs 10645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs if (dev_priv->chipset == 0x50) 10745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs nv_fb->r_format |= (tile_flags << 8); 10845c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs 1092fad3d5e2bc8776a2963399a936db13814107646Ben Skeggs if (!tile_flags) { 1102fad3d5e2bc8776a2963399a936db13814107646Ben Skeggs if (dev_priv->card_type < NV_D0) 11101f2c7730e188077026c5f766f85f329c7000c54Ville Syrjälä nv_fb->r_pitch = 0x00100000 | fb->pitches[0]; 1122fad3d5e2bc8776a2963399a936db13814107646Ben Skeggs else 11301f2c7730e188077026c5f766f85f329c7000c54Ville Syrjälä nv_fb->r_pitch = 0x01000000 | fb->pitches[0]; 1142fad3d5e2bc8776a2963399a936db13814107646Ben Skeggs } else { 11545c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs u32 mode = nvbo->tile_mode; 11645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs if (dev_priv->card_type >= NV_C0) 11745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs mode >>= 4; 11801f2c7730e188077026c5f766f85f329c7000c54Ville Syrjälä nv_fb->r_pitch = ((fb->pitches[0] / 4) << 4) | mode; 11945c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs } 12045c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs } 12145c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs 122386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie return 0; 1236ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs} 1246ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 1256ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsstatic struct drm_framebuffer * 1266ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsnouveau_user_framebuffer_create(struct drm_device *dev, 1276ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs struct drm_file *file_priv, 128308e5bcbdb10452e8aba31aa21432fb67ee46d72Jesse Barnes struct drm_mode_fb_cmd2 *mode_cmd) 1296ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs{ 130386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie struct nouveau_framebuffer *nouveau_fb; 1316ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs struct drm_gem_object *gem; 132386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie int ret; 1336ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 134308e5bcbdb10452e8aba31aa21432fb67ee46d72Jesse Barnes gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]); 1356ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs if (!gem) 136cce13ff7596985903ad924504562190a2c163a63Chris Wilson return ERR_PTR(-ENOENT); 1376ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 138386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL); 139386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie if (!nouveau_fb) 140cce13ff7596985903ad924504562190a2c163a63Chris Wilson return ERR_PTR(-ENOMEM); 141386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie 142386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem)); 143386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie if (ret) { 1446ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs drm_gem_object_unreference(gem); 145cce13ff7596985903ad924504562190a2c163a63Chris Wilson return ERR_PTR(ret); 1466ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs } 1476ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 148386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie return &nouveau_fb->base; 1496ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs} 1506ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 15127d5030a235d89842ed70e18d924f017b34a496dBen Skeggsstatic const struct drm_mode_config_funcs nouveau_mode_config_funcs = { 1526ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs .fb_create = nouveau_user_framebuffer_create, 153eb1f8e4f3be898df808e2dfc131099f5831d491dDave Airlie .output_poll_changed = nouveau_fbcon_output_poll_changed, 1546ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs}; 1556ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 156b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 157b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggsstruct drm_prop_enum_list { 158de69185573586302ada2e59ba41835df36986277Ben Skeggs u8 gen_mask; 159b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs int type; 160b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs char *name; 161b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs}; 162b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 163de69185573586302ada2e59ba41835df36986277Ben Skeggsstatic struct drm_prop_enum_list underscan[] = { 164de69185573586302ada2e59ba41835df36986277Ben Skeggs { 2, UNDERSCAN_AUTO, "auto" }, 165de69185573586302ada2e59ba41835df36986277Ben Skeggs { 2, UNDERSCAN_OFF, "off" }, 166de69185573586302ada2e59ba41835df36986277Ben Skeggs { 2, UNDERSCAN_ON, "on" }, 167de69185573586302ada2e59ba41835df36986277Ben Skeggs {} 168b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs}; 169b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 170de69185573586302ada2e59ba41835df36986277Ben Skeggsstatic struct drm_prop_enum_list dither_mode[] = { 171de69185573586302ada2e59ba41835df36986277Ben Skeggs { 7, DITHERING_MODE_AUTO, "auto" }, 172de69185573586302ada2e59ba41835df36986277Ben Skeggs { 7, DITHERING_MODE_OFF, "off" }, 173de69185573586302ada2e59ba41835df36986277Ben Skeggs { 1, DITHERING_MODE_ON, "on" }, 174de69185573586302ada2e59ba41835df36986277Ben Skeggs { 6, DITHERING_MODE_STATIC2X2, "static 2x2" }, 175de69185573586302ada2e59ba41835df36986277Ben Skeggs { 6, DITHERING_MODE_DYNAMIC2X2, "dynamic 2x2" }, 176de69185573586302ada2e59ba41835df36986277Ben Skeggs { 4, DITHERING_MODE_TEMPORAL, "temporal" }, 177de69185573586302ada2e59ba41835df36986277Ben Skeggs {} 178de69185573586302ada2e59ba41835df36986277Ben Skeggs}; 179de69185573586302ada2e59ba41835df36986277Ben Skeggs 180de69185573586302ada2e59ba41835df36986277Ben Skeggsstatic struct drm_prop_enum_list dither_depth[] = { 181de69185573586302ada2e59ba41835df36986277Ben Skeggs { 6, DITHERING_DEPTH_AUTO, "auto" }, 182de69185573586302ada2e59ba41835df36986277Ben Skeggs { 6, DITHERING_DEPTH_6BPC, "6 bpc" }, 183de69185573586302ada2e59ba41835df36986277Ben Skeggs { 6, DITHERING_DEPTH_8BPC, "8 bpc" }, 184de69185573586302ada2e59ba41835df36986277Ben Skeggs {} 185de69185573586302ada2e59ba41835df36986277Ben Skeggs}; 186de69185573586302ada2e59ba41835df36986277Ben Skeggs 187de69185573586302ada2e59ba41835df36986277Ben Skeggs#define PROP_ENUM(p,gen,n,list) do { \ 188de69185573586302ada2e59ba41835df36986277Ben Skeggs struct drm_prop_enum_list *l = (list); \ 189de69185573586302ada2e59ba41835df36986277Ben Skeggs int c = 0; \ 190de69185573586302ada2e59ba41835df36986277Ben Skeggs while (l->gen_mask) { \ 191de69185573586302ada2e59ba41835df36986277Ben Skeggs if (l->gen_mask & (1 << (gen))) \ 192de69185573586302ada2e59ba41835df36986277Ben Skeggs c++; \ 193de69185573586302ada2e59ba41835df36986277Ben Skeggs l++; \ 194de69185573586302ada2e59ba41835df36986277Ben Skeggs } \ 195de69185573586302ada2e59ba41835df36986277Ben Skeggs if (c) { \ 196de69185573586302ada2e59ba41835df36986277Ben Skeggs p = drm_property_create(dev, DRM_MODE_PROP_ENUM, n, c); \ 197de69185573586302ada2e59ba41835df36986277Ben Skeggs l = (list); \ 198de69185573586302ada2e59ba41835df36986277Ben Skeggs c = 0; \ 199de69185573586302ada2e59ba41835df36986277Ben Skeggs while (p && l->gen_mask) { \ 200de69185573586302ada2e59ba41835df36986277Ben Skeggs if (l->gen_mask & (1 << (gen))) { \ 201de69185573586302ada2e59ba41835df36986277Ben Skeggs drm_property_add_enum(p, c, l->type, l->name); \ 202de69185573586302ada2e59ba41835df36986277Ben Skeggs c++; \ 203de69185573586302ada2e59ba41835df36986277Ben Skeggs } \ 204de69185573586302ada2e59ba41835df36986277Ben Skeggs l++; \ 205de69185573586302ada2e59ba41835df36986277Ben Skeggs } \ 206de69185573586302ada2e59ba41835df36986277Ben Skeggs } \ 207de69185573586302ada2e59ba41835df36986277Ben Skeggs} while(0) 208de69185573586302ada2e59ba41835df36986277Ben Skeggs 209042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerezint 21027d5030a235d89842ed70e18d924f017b34a496dBen Skeggsnouveau_display_create(struct drm_device *dev) 21127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs{ 21227d5030a235d89842ed70e18d924f017b34a496dBen Skeggs struct drm_nouveau_private *dev_priv = dev->dev_private; 21327d5030a235d89842ed70e18d924f017b34a496dBen Skeggs struct nouveau_display_engine *disp = &dev_priv->engine.display; 214de69185573586302ada2e59ba41835df36986277Ben Skeggs int ret, gen; 21527d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 21627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs drm_mode_config_init(dev); 21727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs drm_mode_create_scaling_mode_property(dev); 2184ceca5f8649125645fc4e7f178a1dca1345ab9b4Ben Skeggs drm_mode_create_dvi_i_properties(dev); 219de69185573586302ada2e59ba41835df36986277Ben Skeggs 220de69185573586302ada2e59ba41835df36986277Ben Skeggs if (dev_priv->card_type < NV_50) 221de69185573586302ada2e59ba41835df36986277Ben Skeggs gen = 0; 222de69185573586302ada2e59ba41835df36986277Ben Skeggs else 223de69185573586302ada2e59ba41835df36986277Ben Skeggs if (dev_priv->card_type < NV_D0) 224de69185573586302ada2e59ba41835df36986277Ben Skeggs gen = 1; 225de69185573586302ada2e59ba41835df36986277Ben Skeggs else 226de69185573586302ada2e59ba41835df36986277Ben Skeggs gen = 2; 227de69185573586302ada2e59ba41835df36986277Ben Skeggs 228de69185573586302ada2e59ba41835df36986277Ben Skeggs PROP_ENUM(disp->dithering_mode, gen, "dithering mode", dither_mode); 229de69185573586302ada2e59ba41835df36986277Ben Skeggs PROP_ENUM(disp->dithering_depth, gen, "dithering depth", dither_depth); 230de69185573586302ada2e59ba41835df36986277Ben Skeggs PROP_ENUM(disp->underscan_property, gen, "underscan", underscan); 231b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 232b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_hborder_property = 233b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs drm_property_create(dev, DRM_MODE_PROP_RANGE, 234b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs "underscan hborder", 2); 235b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_hborder_property->values[0] = 0; 236b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_hborder_property->values[1] = 128; 237b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 238b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_vborder_property = 239b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs drm_property_create(dev, DRM_MODE_PROP_RANGE, 240b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs "underscan vborder", 2); 241b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_vborder_property->values[0] = 0; 242b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_vborder_property->values[1] = 128; 243b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 24427d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs; 24527d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.fb_base = pci_resource_start(dev->pdev, 1); 24627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 24727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.min_width = 0; 24827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.min_height = 0; 24927d5030a235d89842ed70e18d924f017b34a496dBen Skeggs if (dev_priv->card_type < NV_10) { 25027d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_width = 2048; 25127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_height = 2048; 25227d5030a235d89842ed70e18d924f017b34a496dBen Skeggs } else 25327d5030a235d89842ed70e18d924f017b34a496dBen Skeggs if (dev_priv->card_type < NV_50) { 25427d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_width = 4096; 25527d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_height = 4096; 25627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs } else { 25727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_width = 8192; 25827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_height = 8192; 25927d5030a235d89842ed70e18d924f017b34a496dBen Skeggs } 26027d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 26127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs ret = disp->create(dev); 26227d5030a235d89842ed70e18d924f017b34a496dBen Skeggs if (ret) 26327d5030a235d89842ed70e18d924f017b34a496dBen Skeggs return ret; 26427d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 2652a44e4997c5fee8e1da1589ff57e0bd1c53f03ceBen Skeggs ret = disp->init(dev); 2662a44e4997c5fee8e1da1589ff57e0bd1c53f03ceBen Skeggs if (ret) 2672a44e4997c5fee8e1da1589ff57e0bd1c53f03ceBen Skeggs disp->destroy(dev); 2682a44e4997c5fee8e1da1589ff57e0bd1c53f03ceBen Skeggs return ret; 26927d5030a235d89842ed70e18d924f017b34a496dBen Skeggs} 27027d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 27127d5030a235d89842ed70e18d924f017b34a496dBen Skeggsvoid 27227d5030a235d89842ed70e18d924f017b34a496dBen Skeggsnouveau_display_destroy(struct drm_device *dev) 27327d5030a235d89842ed70e18d924f017b34a496dBen Skeggs{ 27427d5030a235d89842ed70e18d924f017b34a496dBen Skeggs struct drm_nouveau_private *dev_priv = dev->dev_private; 27527d5030a235d89842ed70e18d924f017b34a496dBen Skeggs struct nouveau_display_engine *disp = &dev_priv->engine.display; 27627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 2772a44e4997c5fee8e1da1589ff57e0bd1c53f03ceBen Skeggs disp->fini(dev); 27827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs disp->destroy(dev); 27927d5030a235d89842ed70e18d924f017b34a496dBen Skeggs drm_mode_config_cleanup(dev); 28027d5030a235d89842ed70e18d924f017b34a496dBen Skeggs} 28127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 28227d5030a235d89842ed70e18d924f017b34a496dBen Skeggsint 283042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jereznouveau_vblank_enable(struct drm_device *dev, int crtc) 284042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez{ 285042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez struct drm_nouveau_private *dev_priv = dev->dev_private; 286042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 287042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez if (dev_priv->card_type >= NV_50) 288042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, 0, 289042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc)); 290042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez else 291042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, 292042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NV_PCRTC_INTR_0_VBLANK); 293042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 294042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez return 0; 295042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez} 296042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 297042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerezvoid 298042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jereznouveau_vblank_disable(struct drm_device *dev, int crtc) 299042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez{ 300042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez struct drm_nouveau_private *dev_priv = dev->dev_private; 301042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 302042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez if (dev_priv->card_type >= NV_50) 303042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, 304042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc), 0); 305042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez else 306042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, 0); 307042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez} 308332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 309332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezstatic int 310332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_page_flip_reserve(struct nouveau_bo *old_bo, 311332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo) 312332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 313332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez int ret; 314332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 315332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM); 316332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 317332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 318332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 319332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = ttm_bo_reserve(&new_bo->bo, false, false, false, 0); 320332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 321332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 322332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 323332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = ttm_bo_reserve(&old_bo->bo, false, false, false, 0); 324332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 325332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail_unreserve; 326332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 327332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 328332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 329332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail_unreserve: 330332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ttm_bo_unreserve(&new_bo->bo); 331332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail: 332332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_unpin(new_bo); 333332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 334332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 335332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 336332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezstatic void 337332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_page_flip_unreserve(struct nouveau_bo *old_bo, 338332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo, 339332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_fence *fence) 340332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 341332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_fence(new_bo, fence); 342332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ttm_bo_unreserve(&new_bo->bo); 343332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 344332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_fence(old_bo, fence); 345332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ttm_bo_unreserve(&old_bo->bo); 346332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 347332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_unpin(old_bo); 348332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 349332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 350332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezstatic int 351332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_page_flip_emit(struct nouveau_channel *chan, 352332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *old_bo, 353332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo, 354332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *s, 355332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_fence **pfence) 356332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 357bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs struct drm_nouveau_private *dev_priv = chan->dev->dev_private; 358332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_device *dev = chan->dev; 359332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez unsigned long flags; 360332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez int ret; 361332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 362332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Queue it to the pending list */ 363332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_lock_irqsave(&dev->event_lock, flags); 364332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_add_tail(&s->head, &chan->nvsw.flip); 365332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 366332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 367332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Synchronize with the old framebuffer */ 368332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_fence_sync(old_bo->bo.sync_obj, chan); 369332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 370332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 371332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 372332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Emit the pageflip */ 373332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = RING_SPACE(chan, 2); 374332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 375332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 376332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 377bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs if (dev_priv->card_type < NV_C0) 378bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs BEGIN_RING(chan, NvSubSw, NV_SW_PAGE_FLIP, 1); 379bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs else 380bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs BEGIN_NVC0(chan, 2, NvSubM2MF, 0x0500, 1); 381bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs OUT_RING (chan, 0); 382bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs FIRE_RING (chan); 383332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 384332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_fence_new(chan, pfence, true); 385332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 386332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 387332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 388332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 389332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail: 390332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_lock_irqsave(&dev->event_lock, flags); 391332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_del(&s->head); 392332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 393332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 394332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 395332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 396332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezint 397332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, 398332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_pending_vblank_event *event) 399332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 400332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_device *dev = crtc->dev; 401332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_nouveau_private *dev_priv = dev->dev_private; 402332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->fb)->nvbo; 403332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo; 404332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *s; 405332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_channel *chan; 406332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_fence *fence; 407332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez int ret; 408332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 409a82dd49f14742e2529f79feb6360e0993277e788Ben Skeggs if (!dev_priv->channel) 410332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return -ENODEV; 411332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 412332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez s = kzalloc(sizeof(*s), GFP_KERNEL); 413332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (!s) 414332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return -ENOMEM; 415332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 416332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Don't let the buffers go away while we flip */ 417332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_page_flip_reserve(old_bo, new_bo); 418332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 419332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail_free; 420332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 421332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Initialize a page flip struct */ 422332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez *s = (struct nouveau_page_flip_state) 4232503c6fa3edf7c2bb001c7f7926786eed24cc06eBenjamin Franzke { { }, event, nouveau_crtc(crtc)->index, 42401f2c7730e188077026c5f766f85f329c7000c54Ville Syrjälä fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y, 425332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez new_bo->bo.offset }; 426332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 427332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Choose the channel the flip will be handled in */ 428332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez chan = nouveau_fence_channel(new_bo->bo.sync_obj); 429332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (!chan) 430332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez chan = nouveau_channel_get_unlocked(dev_priv->channel); 431332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez mutex_lock(&chan->mutex); 432332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 433332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Emit a page flip */ 434d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs if (dev_priv->card_type >= NV_50) { 435d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs ret = nv50_display_flip_next(crtc, fb, chan); 436d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs if (ret) { 437d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs nouveau_channel_put(&chan); 438d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs goto fail_unreserve; 439d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs } 440d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs } 441d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs 442332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence); 443332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_channel_put(&chan); 444332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 445332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail_unreserve; 446332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 447332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Update the crtc struct and cleanup */ 448332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez crtc->fb = fb; 449332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 450332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_page_flip_unreserve(old_bo, new_bo, fence); 451332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_fence_unref(&fence); 452332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 453332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 454332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail_unreserve: 455332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_page_flip_unreserve(old_bo, new_bo, NULL); 456332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail_free: 457332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez kfree(s); 458332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 459332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 460332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 461332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezint 462332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_finish_page_flip(struct nouveau_channel *chan, 463332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *ps) 464332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 465332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_device *dev = chan->dev; 466332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *s; 467332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez unsigned long flags; 468332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 469332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_lock_irqsave(&dev->event_lock, flags); 470332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 471332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (list_empty(&chan->nvsw.flip)) { 472332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez NV_ERROR(dev, "Unexpected pageflip in channel %d.\n", chan->id); 473332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 474332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return -EINVAL; 475332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez } 476332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 477332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez s = list_first_entry(&chan->nvsw.flip, 478332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state, head); 479332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (s->event) { 480332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_pending_vblank_event *e = s->event; 481332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct timeval now; 482332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 483332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez do_gettimeofday(&now); 484332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez e->event.sequence = 0; 485332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez e->event.tv_sec = now.tv_sec; 486332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez e->event.tv_usec = now.tv_usec; 487332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_add_tail(&e->base.link, &e->base.file_priv->event_list); 488332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez wake_up_interruptible(&e->base.file_priv->event_wait); 489332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez } 490332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 491332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_del(&s->head); 492d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs if (ps) 493d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs *ps = *s; 494332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez kfree(s); 495332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 496332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 497332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 498332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 49933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 50033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsint 50133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsnouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev, 50233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct drm_mode_create_dumb *args) 50333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs{ 50433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct nouveau_bo *bo; 50533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs int ret; 50633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 50733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs args->pitch = roundup(args->width * (args->bpp / 8), 256); 50833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs args->size = args->pitch * args->height; 50933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs args->size = roundup(args->size, PAGE_SIZE); 51033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 51133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs ret = nouveau_gem_new(dev, args->size, 0, TTM_PL_FLAG_VRAM, 0, 0, &bo); 51233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs if (ret) 51333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return ret; 51433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 51533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs ret = drm_gem_handle_create(file_priv, bo->gem, &args->handle); 51633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs drm_gem_object_unreference_unlocked(bo->gem); 51733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return ret; 51833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs} 51933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 52033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsint 52133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsnouveau_display_dumb_destroy(struct drm_file *file_priv, struct drm_device *dev, 52233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs uint32_t handle) 52333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs{ 52433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return drm_gem_handle_delete(file_priv, handle); 52533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs} 52633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 52733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsint 52833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsnouveau_display_dumb_map_offset(struct drm_file *file_priv, 52933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct drm_device *dev, 53033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs uint32_t handle, uint64_t *poffset) 53133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs{ 53233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct drm_gem_object *gem; 53333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 53433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs gem = drm_gem_object_lookup(dev, file_priv, handle); 53533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs if (gem) { 53633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct nouveau_bo *bo = gem->driver_private; 53733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs *poffset = bo->bo.addr_space_offset; 53833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs drm_gem_object_unreference_unlocked(gem); 53933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return 0; 54033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs } 54133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 54233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return -ENOENT; 54333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs} 544