nouveau_display.c revision 6d597027755b2eed4298b85ebe3cb5c93b29d1a9
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" 3652c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs#include "nouveau_gpio.h" 3745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs#include "nv50_display.h" 386ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 396ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsstatic void 406ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsnouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb) 416ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs{ 426ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); 436ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 44bc9025bdc4e2b591734cca17697093845007b63dLuca Barbieri if (fb->nvbo) 45bc9025bdc4e2b591734cca17697093845007b63dLuca Barbieri drm_gem_object_unreference_unlocked(fb->nvbo->gem); 466ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 476ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs drm_framebuffer_cleanup(drm_fb); 486ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs kfree(fb); 496ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs} 506ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 516ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsstatic int 526ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsnouveau_user_framebuffer_create_handle(struct drm_framebuffer *drm_fb, 536ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs struct drm_file *file_priv, 546ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs unsigned int *handle) 556ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs{ 566ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs struct nouveau_framebuffer *fb = nouveau_framebuffer(drm_fb); 576ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 586ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs return drm_gem_handle_create(file_priv, fb->nvbo->gem, handle); 596ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs} 606ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 616ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsstatic const struct drm_framebuffer_funcs nouveau_framebuffer_funcs = { 626ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs .destroy = nouveau_user_framebuffer_destroy, 636ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs .create_handle = nouveau_user_framebuffer_create_handle, 646ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs}; 656ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 66386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlieint 6745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggsnouveau_framebuffer_init(struct drm_device *dev, 6845c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs struct nouveau_framebuffer *nv_fb, 69308e5bcbdb10452e8aba31aa21432fb67ee46d72Jesse Barnes struct drm_mode_fb_cmd2 *mode_cmd, 7045c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs struct nouveau_bo *nvbo) 716ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs{ 7245c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs struct drm_nouveau_private *dev_priv = dev->dev_private; 7345c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs struct drm_framebuffer *fb = &nv_fb->base; 746ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs int ret; 756ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 7645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs ret = drm_framebuffer_init(dev, fb, &nouveau_framebuffer_funcs); 776ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs if (ret) { 78386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie return ret; 796ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs } 806ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 8145c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs drm_helper_mode_fill_fb_struct(fb, mode_cmd); 8245c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs nv_fb->nvbo = nvbo; 8345c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs 8445c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs if (dev_priv->card_type >= NV_50) { 8545c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs u32 tile_flags = nouveau_bo_tile_layout(nvbo); 8645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs if (tile_flags == 0x7a00 || 8745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs tile_flags == 0xfe00) 8845c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs nv_fb->r_dma = NvEvoFB32; 8945c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs else 9045c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs if (tile_flags == 0x7000) 9145c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs nv_fb->r_dma = NvEvoFB16; 9245c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs else 9345c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs nv_fb->r_dma = NvEvoVRAM_LP; 9445c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs 9545c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs switch (fb->depth) { 9645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 8: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_8; break; 9745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 15: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_15; break; 9845c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 16: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_16; break; 9945c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 24: 10045c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 32: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_24; break; 10145c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs case 30: nv_fb->r_format = NV50_EVO_CRTC_FB_DEPTH_30; break; 10245c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs default: 10345c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs NV_ERROR(dev, "unknown depth %d\n", fb->depth); 10445c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs return -EINVAL; 10545c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs } 10645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs 10745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs if (dev_priv->chipset == 0x50) 10845c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs nv_fb->r_format |= (tile_flags << 8); 10945c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs 1102fad3d5e2bc8776a2963399a936db13814107646Ben Skeggs if (!tile_flags) { 1112fad3d5e2bc8776a2963399a936db13814107646Ben Skeggs if (dev_priv->card_type < NV_D0) 11201f2c7730e188077026c5f766f85f329c7000c54Ville Syrjälä nv_fb->r_pitch = 0x00100000 | fb->pitches[0]; 1132fad3d5e2bc8776a2963399a936db13814107646Ben Skeggs else 11401f2c7730e188077026c5f766f85f329c7000c54Ville Syrjälä nv_fb->r_pitch = 0x01000000 | fb->pitches[0]; 1152fad3d5e2bc8776a2963399a936db13814107646Ben Skeggs } else { 11645c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs u32 mode = nvbo->tile_mode; 11745c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs if (dev_priv->card_type >= NV_C0) 11845c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs mode >>= 4; 11901f2c7730e188077026c5f766f85f329c7000c54Ville Syrjälä nv_fb->r_pitch = ((fb->pitches[0] / 4) << 4) | mode; 12045c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs } 12145c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs } 12245c4e0aae96c6354bf5131a282a74fe38d032de3Ben Skeggs 123386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie return 0; 1246ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs} 1256ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 1266ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsstatic struct drm_framebuffer * 1276ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggsnouveau_user_framebuffer_create(struct drm_device *dev, 1286ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs struct drm_file *file_priv, 129308e5bcbdb10452e8aba31aa21432fb67ee46d72Jesse Barnes struct drm_mode_fb_cmd2 *mode_cmd) 1306ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs{ 131386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie struct nouveau_framebuffer *nouveau_fb; 1326ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs struct drm_gem_object *gem; 133386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie int ret; 1346ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 135308e5bcbdb10452e8aba31aa21432fb67ee46d72Jesse Barnes gem = drm_gem_object_lookup(dev, file_priv, mode_cmd->handles[0]); 1366ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs if (!gem) 137cce13ff7596985903ad924504562190a2c163a63Chris Wilson return ERR_PTR(-ENOENT); 1386ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 139386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie nouveau_fb = kzalloc(sizeof(struct nouveau_framebuffer), GFP_KERNEL); 140386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie if (!nouveau_fb) 141cce13ff7596985903ad924504562190a2c163a63Chris Wilson return ERR_PTR(-ENOMEM); 142386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie 143386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie ret = nouveau_framebuffer_init(dev, nouveau_fb, mode_cmd, nouveau_gem_object(gem)); 144386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie if (ret) { 1456ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs drm_gem_object_unreference(gem); 146cce13ff7596985903ad924504562190a2c163a63Chris Wilson return ERR_PTR(ret); 1476ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs } 1486ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 149386516744ba45d50f42c6999151cc210cb4f96e4Dave Airlie return &nouveau_fb->base; 1506ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs} 1516ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 15227d5030a235d89842ed70e18d924f017b34a496dBen Skeggsstatic const struct drm_mode_config_funcs nouveau_mode_config_funcs = { 1536ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs .fb_create = nouveau_user_framebuffer_create, 154eb1f8e4f3be898df808e2dfc131099f5831d491dDave Airlie .output_poll_changed = nouveau_fbcon_output_poll_changed, 1556ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs}; 1566ee738610f41b59733f63718f0bdbcba7d3a3f12Ben Skeggs 157b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 1584a67d39190315558631d944b1cea4466ed4c86d8Sascha Hauerstruct nouveau_drm_prop_enum_list { 159de69185573586302ada2e59ba41835df36986277Ben Skeggs u8 gen_mask; 160b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs int type; 161b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs char *name; 162b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs}; 163b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 1644a67d39190315558631d944b1cea4466ed4c86d8Sascha Hauerstatic struct nouveau_drm_prop_enum_list underscan[] = { 1659285462273cbccb27187d5308ed95f94a9ceb1deBen Skeggs { 6, UNDERSCAN_AUTO, "auto" }, 1669285462273cbccb27187d5308ed95f94a9ceb1deBen Skeggs { 6, UNDERSCAN_OFF, "off" }, 1679285462273cbccb27187d5308ed95f94a9ceb1deBen Skeggs { 6, UNDERSCAN_ON, "on" }, 168de69185573586302ada2e59ba41835df36986277Ben Skeggs {} 169b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs}; 170b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 1714a67d39190315558631d944b1cea4466ed4c86d8Sascha Hauerstatic struct nouveau_drm_prop_enum_list dither_mode[] = { 172de69185573586302ada2e59ba41835df36986277Ben Skeggs { 7, DITHERING_MODE_AUTO, "auto" }, 173de69185573586302ada2e59ba41835df36986277Ben Skeggs { 7, DITHERING_MODE_OFF, "off" }, 174de69185573586302ada2e59ba41835df36986277Ben Skeggs { 1, DITHERING_MODE_ON, "on" }, 175de69185573586302ada2e59ba41835df36986277Ben Skeggs { 6, DITHERING_MODE_STATIC2X2, "static 2x2" }, 176de69185573586302ada2e59ba41835df36986277Ben Skeggs { 6, DITHERING_MODE_DYNAMIC2X2, "dynamic 2x2" }, 177de69185573586302ada2e59ba41835df36986277Ben Skeggs { 4, DITHERING_MODE_TEMPORAL, "temporal" }, 178de69185573586302ada2e59ba41835df36986277Ben Skeggs {} 179de69185573586302ada2e59ba41835df36986277Ben Skeggs}; 180de69185573586302ada2e59ba41835df36986277Ben Skeggs 1814a67d39190315558631d944b1cea4466ed4c86d8Sascha Hauerstatic struct nouveau_drm_prop_enum_list dither_depth[] = { 182de69185573586302ada2e59ba41835df36986277Ben Skeggs { 6, DITHERING_DEPTH_AUTO, "auto" }, 183de69185573586302ada2e59ba41835df36986277Ben Skeggs { 6, DITHERING_DEPTH_6BPC, "6 bpc" }, 184de69185573586302ada2e59ba41835df36986277Ben Skeggs { 6, DITHERING_DEPTH_8BPC, "8 bpc" }, 185de69185573586302ada2e59ba41835df36986277Ben Skeggs {} 186de69185573586302ada2e59ba41835df36986277Ben Skeggs}; 187de69185573586302ada2e59ba41835df36986277Ben Skeggs 188de69185573586302ada2e59ba41835df36986277Ben Skeggs#define PROP_ENUM(p,gen,n,list) do { \ 1894a67d39190315558631d944b1cea4466ed4c86d8Sascha Hauer struct nouveau_drm_prop_enum_list *l = (list); \ 190de69185573586302ada2e59ba41835df36986277Ben Skeggs int c = 0; \ 191de69185573586302ada2e59ba41835df36986277Ben Skeggs while (l->gen_mask) { \ 192de69185573586302ada2e59ba41835df36986277Ben Skeggs if (l->gen_mask & (1 << (gen))) \ 193de69185573586302ada2e59ba41835df36986277Ben Skeggs c++; \ 194de69185573586302ada2e59ba41835df36986277Ben Skeggs l++; \ 195de69185573586302ada2e59ba41835df36986277Ben Skeggs } \ 196de69185573586302ada2e59ba41835df36986277Ben Skeggs if (c) { \ 197de69185573586302ada2e59ba41835df36986277Ben Skeggs p = drm_property_create(dev, DRM_MODE_PROP_ENUM, n, c); \ 198de69185573586302ada2e59ba41835df36986277Ben Skeggs l = (list); \ 199de69185573586302ada2e59ba41835df36986277Ben Skeggs c = 0; \ 200de69185573586302ada2e59ba41835df36986277Ben Skeggs while (p && l->gen_mask) { \ 201de69185573586302ada2e59ba41835df36986277Ben Skeggs if (l->gen_mask & (1 << (gen))) { \ 202de69185573586302ada2e59ba41835df36986277Ben Skeggs drm_property_add_enum(p, c, l->type, l->name); \ 203de69185573586302ada2e59ba41835df36986277Ben Skeggs c++; \ 204de69185573586302ada2e59ba41835df36986277Ben Skeggs } \ 205de69185573586302ada2e59ba41835df36986277Ben Skeggs l++; \ 206de69185573586302ada2e59ba41835df36986277Ben Skeggs } \ 207de69185573586302ada2e59ba41835df36986277Ben Skeggs } \ 208de69185573586302ada2e59ba41835df36986277Ben Skeggs} while(0) 209de69185573586302ada2e59ba41835df36986277Ben Skeggs 210042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerezint 211f62b27db6b5479efe376b408802a081a834ef50eBen Skeggsnouveau_display_init(struct drm_device *dev) 212f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs{ 213f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs struct drm_nouveau_private *dev_priv = dev->dev_private; 214f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs struct nouveau_display_engine *disp = &dev_priv->engine.display; 21552c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs struct drm_connector *connector; 216f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs int ret; 217f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 218f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs ret = disp->init(dev); 21952c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs if (ret) 22052c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs return ret; 22152c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs 2227df898b1a70b13c3a8892625f4ead929d9554293Ben Skeggs /* power on internal panel if it's not already. the init tables of 2237df898b1a70b13c3a8892625f4ead929d9554293Ben Skeggs * some vbios default this to off for some reason, causing the 2247df898b1a70b13c3a8892625f4ead929d9554293Ben Skeggs * panel to not work after resume 2257df898b1a70b13c3a8892625f4ead929d9554293Ben Skeggs */ 2267df898b1a70b13c3a8892625f4ead929d9554293Ben Skeggs if (nouveau_gpio_func_get(dev, DCB_GPIO_PANEL_POWER) == 0) { 2277df898b1a70b13c3a8892625f4ead929d9554293Ben Skeggs nouveau_gpio_func_set(dev, DCB_GPIO_PANEL_POWER, true); 2287df898b1a70b13c3a8892625f4ead929d9554293Ben Skeggs msleep(300); 2297df898b1a70b13c3a8892625f4ead929d9554293Ben Skeggs } 2307df898b1a70b13c3a8892625f4ead929d9554293Ben Skeggs 2317df898b1a70b13c3a8892625f4ead929d9554293Ben Skeggs /* enable polling for external displays */ 23252c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs drm_kms_helper_poll_enable(dev); 23352c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs 23452c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs /* enable hotplug interrupts */ 23552c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 23652c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs struct nouveau_connector *conn = nouveau_connector(connector); 23752c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs nouveau_gpio_irq(dev, 0, conn->hpd, 0xff, true); 238f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs } 239f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 240f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs return ret; 241f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs} 242f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 243f62b27db6b5479efe376b408802a081a834ef50eBen Skeggsvoid 244f62b27db6b5479efe376b408802a081a834ef50eBen Skeggsnouveau_display_fini(struct drm_device *dev) 245f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs{ 246f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs struct drm_nouveau_private *dev_priv = dev->dev_private; 247f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs struct nouveau_display_engine *disp = &dev_priv->engine.display; 24852c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs struct drm_connector *connector; 24952c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs 25052c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs /* disable hotplug interrupts */ 25152c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs list_for_each_entry(connector, &dev->mode_config.connector_list, head) { 25252c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs struct nouveau_connector *conn = nouveau_connector(connector); 25352c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs nouveau_gpio_irq(dev, 0, conn->hpd, 0xff, false); 25452c4d767437b40b0cbc02d6a4480abb45ace64bbBen Skeggs } 255f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 256f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs drm_kms_helper_poll_disable(dev); 257f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs disp->fini(dev); 258f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs} 259f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 260f62b27db6b5479efe376b408802a081a834ef50eBen Skeggsint 26127d5030a235d89842ed70e18d924f017b34a496dBen Skeggsnouveau_display_create(struct drm_device *dev) 26227d5030a235d89842ed70e18d924f017b34a496dBen Skeggs{ 26327d5030a235d89842ed70e18d924f017b34a496dBen Skeggs struct drm_nouveau_private *dev_priv = dev->dev_private; 26427d5030a235d89842ed70e18d924f017b34a496dBen Skeggs struct nouveau_display_engine *disp = &dev_priv->engine.display; 265de69185573586302ada2e59ba41835df36986277Ben Skeggs int ret, gen; 26627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 26727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs drm_mode_config_init(dev); 26827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs drm_mode_create_scaling_mode_property(dev); 2694ceca5f8649125645fc4e7f178a1dca1345ab9b4Ben Skeggs drm_mode_create_dvi_i_properties(dev); 270de69185573586302ada2e59ba41835df36986277Ben Skeggs 271de69185573586302ada2e59ba41835df36986277Ben Skeggs if (dev_priv->card_type < NV_50) 272de69185573586302ada2e59ba41835df36986277Ben Skeggs gen = 0; 273de69185573586302ada2e59ba41835df36986277Ben Skeggs else 274de69185573586302ada2e59ba41835df36986277Ben Skeggs if (dev_priv->card_type < NV_D0) 275de69185573586302ada2e59ba41835df36986277Ben Skeggs gen = 1; 276de69185573586302ada2e59ba41835df36986277Ben Skeggs else 277de69185573586302ada2e59ba41835df36986277Ben Skeggs gen = 2; 278de69185573586302ada2e59ba41835df36986277Ben Skeggs 279de69185573586302ada2e59ba41835df36986277Ben Skeggs PROP_ENUM(disp->dithering_mode, gen, "dithering mode", dither_mode); 280de69185573586302ada2e59ba41835df36986277Ben Skeggs PROP_ENUM(disp->dithering_depth, gen, "dithering depth", dither_depth); 281de69185573586302ada2e59ba41835df36986277Ben Skeggs PROP_ENUM(disp->underscan_property, gen, "underscan", underscan); 282b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 283b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_hborder_property = 284d9bc3c02e36d844c2d980e65ddda5c7699e073f8Sascha Hauer drm_property_create_range(dev, 0, "underscan hborder", 0, 128); 285b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 286b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_vborder_property = 287d9bc3c02e36d844c2d980e65ddda5c7699e073f8Sascha Hauer drm_property_create_range(dev, 0, "underscan vborder", 0, 128); 288b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 289df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller if (gen == 1) { 290df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller disp->vibrant_hue_property = 291df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller drm_property_create(dev, DRM_MODE_PROP_RANGE, 292df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller "vibrant hue", 2); 293df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller disp->vibrant_hue_property->values[0] = 0; 294df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller disp->vibrant_hue_property->values[1] = 180; /* -90..+90 */ 295df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller 296df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller disp->color_vibrance_property = 297df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller drm_property_create(dev, DRM_MODE_PROP_RANGE, 298df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller "color vibrance", 2); 299df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller disp->color_vibrance_property->values[0] = 0; 300df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller disp->color_vibrance_property->values[1] = 200; /* -100..+100 */ 301df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller } 302df26bc9c320602539b1b5b3d85786e4c8de7bf43Christoph Bumiller 303e6ecefaadfcdb03db8ac9e739b4ba7a93a8811b3Laurent Pinchart dev->mode_config.funcs = &nouveau_mode_config_funcs; 30427d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.fb_base = pci_resource_start(dev->pdev, 1); 30527d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 30627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.min_width = 0; 30727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.min_height = 0; 30827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs if (dev_priv->card_type < NV_10) { 30927d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_width = 2048; 31027d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_height = 2048; 31127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs } else 31227d5030a235d89842ed70e18d924f017b34a496dBen Skeggs if (dev_priv->card_type < NV_50) { 31327d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_width = 4096; 31427d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_height = 4096; 31527d5030a235d89842ed70e18d924f017b34a496dBen Skeggs } else { 31627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_width = 8192; 31727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_height = 8192; 31827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs } 31927d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 320f1377998eede7a8caa124fcf6a589b02c9e2bac7Dave Airlie dev->mode_config.preferred_depth = 24; 321f1377998eede7a8caa124fcf6a589b02c9e2bac7Dave Airlie dev->mode_config.prefer_shadow = 1; 322f1377998eede7a8caa124fcf6a589b02c9e2bac7Dave Airlie 323f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs drm_kms_helper_poll_init(dev); 324f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs drm_kms_helper_poll_disable(dev); 325f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 32627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs ret = disp->create(dev); 32727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs if (ret) 32827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs return ret; 32927d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 330f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs if (dev->mode_config.num_crtc) { 331f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs ret = drm_vblank_init(dev, dev->mode_config.num_crtc); 332f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs if (ret) 333f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs return ret; 334f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs } 335f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 3362a44e4997c5fee8e1da1589ff57e0bd1c53f03ceBen Skeggs return ret; 33727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs} 33827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 33927d5030a235d89842ed70e18d924f017b34a496dBen Skeggsvoid 34027d5030a235d89842ed70e18d924f017b34a496dBen Skeggsnouveau_display_destroy(struct drm_device *dev) 34127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs{ 34227d5030a235d89842ed70e18d924f017b34a496dBen Skeggs struct drm_nouveau_private *dev_priv = dev->dev_private; 34327d5030a235d89842ed70e18d924f017b34a496dBen Skeggs struct nouveau_display_engine *disp = &dev_priv->engine.display; 34427d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 345f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs drm_vblank_cleanup(dev); 346f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 34727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs disp->destroy(dev); 348f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 349f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs drm_kms_helper_poll_fini(dev); 35027d5030a235d89842ed70e18d924f017b34a496dBen Skeggs drm_mode_config_cleanup(dev); 35127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs} 35227d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 35327d5030a235d89842ed70e18d924f017b34a496dBen Skeggsint 354042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jereznouveau_vblank_enable(struct drm_device *dev, int crtc) 355042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez{ 356042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez struct drm_nouveau_private *dev_priv = dev->dev_private; 357042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 358042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez if (dev_priv->card_type >= NV_50) 359042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, 0, 360042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc)); 361042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez else 362042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, 363042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NV_PCRTC_INTR_0_VBLANK); 364042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 365042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez return 0; 366042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez} 367042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 368042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerezvoid 369042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jereznouveau_vblank_disable(struct drm_device *dev, int crtc) 370042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez{ 371042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez struct drm_nouveau_private *dev_priv = dev->dev_private; 372042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 373042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez if (dev_priv->card_type >= NV_50) 374042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, 375042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc), 0); 376042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez else 377042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, 0); 378042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez} 379332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 380332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezstatic int 381332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_page_flip_reserve(struct nouveau_bo *old_bo, 382332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo) 383332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 384332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez int ret; 385332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 386332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM); 387332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 388332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 389332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 390332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = ttm_bo_reserve(&new_bo->bo, false, false, false, 0); 391332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 392332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 393332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 394332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = ttm_bo_reserve(&old_bo->bo, false, false, false, 0); 395332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 396332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail_unreserve; 397332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 398332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 399332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 400332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail_unreserve: 401332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ttm_bo_unreserve(&new_bo->bo); 402332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail: 403332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_unpin(new_bo); 404332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 405332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 406332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 407332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezstatic void 408332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_page_flip_unreserve(struct nouveau_bo *old_bo, 409332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo, 410332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_fence *fence) 411332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 412332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_fence(new_bo, fence); 413332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ttm_bo_unreserve(&new_bo->bo); 414332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 415332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_fence(old_bo, fence); 416332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ttm_bo_unreserve(&old_bo->bo); 417332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 418332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_unpin(old_bo); 419332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 420332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 421332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezstatic int 422332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_page_flip_emit(struct nouveau_channel *chan, 423332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *old_bo, 424332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo, 425332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *s, 426332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_fence **pfence) 427332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 428bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs struct drm_nouveau_private *dev_priv = chan->dev->dev_private; 429332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_device *dev = chan->dev; 430332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez unsigned long flags; 431332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez int ret; 432332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 433332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Queue it to the pending list */ 434332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_lock_irqsave(&dev->event_lock, flags); 435332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_add_tail(&s->head, &chan->nvsw.flip); 436332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 437332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 438332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Synchronize with the old framebuffer */ 439332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_fence_sync(old_bo->bo.sync_obj, chan); 440332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 441332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 442332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 443332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Emit the pageflip */ 444d5316e251230c4e54a157349a362229c3d4daa32Ben Skeggs ret = RING_SPACE(chan, 3); 445332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 446332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 447332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 448d5316e251230c4e54a157349a362229c3d4daa32Ben Skeggs if (dev_priv->card_type < NV_C0) { 4496d597027755b2eed4298b85ebe3cb5c93b29d1a9Ben Skeggs BEGIN_NV04(chan, NvSubSw, NV_SW_PAGE_FLIP, 1); 450d5316e251230c4e54a157349a362229c3d4daa32Ben Skeggs OUT_RING (chan, 0x00000000); 451d5316e251230c4e54a157349a362229c3d4daa32Ben Skeggs OUT_RING (chan, 0x00000000); 452d5316e251230c4e54a157349a362229c3d4daa32Ben Skeggs } else { 4536d597027755b2eed4298b85ebe3cb5c93b29d1a9Ben Skeggs BEGIN_NVC0(chan, 0, NV10_SUBCHAN_REF_CNT, 1); 454d5316e251230c4e54a157349a362229c3d4daa32Ben Skeggs OUT_RING (chan, ++chan->fence.sequence); 4556d597027755b2eed4298b85ebe3cb5c93b29d1a9Ben Skeggs BEGIN_IMC0(chan, 0, NVSW_SUBCHAN_PAGE_FLIP, 0x0000); 456d5316e251230c4e54a157349a362229c3d4daa32Ben Skeggs } 457bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs FIRE_RING (chan); 458332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 459332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_fence_new(chan, pfence, true); 460332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 461332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 462332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 463332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 464332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail: 465332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_lock_irqsave(&dev->event_lock, flags); 466332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_del(&s->head); 467332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 468332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 469332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 470332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 471332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezint 472332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, 473332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_pending_vblank_event *event) 474332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 475332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_device *dev = crtc->dev; 476332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_nouveau_private *dev_priv = dev->dev_private; 477332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->fb)->nvbo; 478332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo; 479332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *s; 480332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_channel *chan; 481332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_fence *fence; 482332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez int ret; 483332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 484a82dd49f14742e2529f79feb6360e0993277e788Ben Skeggs if (!dev_priv->channel) 485332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return -ENODEV; 486332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 487332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez s = kzalloc(sizeof(*s), GFP_KERNEL); 488332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (!s) 489332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return -ENOMEM; 490332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 491332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Don't let the buffers go away while we flip */ 492332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_page_flip_reserve(old_bo, new_bo); 493332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 494332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail_free; 495332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 496332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Initialize a page flip struct */ 497332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez *s = (struct nouveau_page_flip_state) 4982503c6fa3edf7c2bb001c7f7926786eed24cc06eBenjamin Franzke { { }, event, nouveau_crtc(crtc)->index, 49901f2c7730e188077026c5f766f85f329c7000c54Ville Syrjälä fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y, 500332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez new_bo->bo.offset }; 501332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 502332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Choose the channel the flip will be handled in */ 503332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez chan = nouveau_fence_channel(new_bo->bo.sync_obj); 504332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (!chan) 505332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez chan = nouveau_channel_get_unlocked(dev_priv->channel); 506332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez mutex_lock(&chan->mutex); 507332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 508332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Emit a page flip */ 509d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs if (dev_priv->card_type >= NV_50) { 5103376ee374d2318d311bd3aa7b9bb0186f64ccca5Ben Skeggs if (dev_priv->card_type >= NV_D0) 5113376ee374d2318d311bd3aa7b9bb0186f64ccca5Ben Skeggs ret = nvd0_display_flip_next(crtc, fb, chan, 0); 5123376ee374d2318d311bd3aa7b9bb0186f64ccca5Ben Skeggs else 5133376ee374d2318d311bd3aa7b9bb0186f64ccca5Ben Skeggs ret = nv50_display_flip_next(crtc, fb, chan); 514d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs if (ret) { 515d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs nouveau_channel_put(&chan); 516d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs goto fail_unreserve; 517d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs } 518d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs } 519d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs 520332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence); 521332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_channel_put(&chan); 522332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 523332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail_unreserve; 524332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 525332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Update the crtc struct and cleanup */ 526332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez crtc->fb = fb; 527332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 528332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_page_flip_unreserve(old_bo, new_bo, fence); 529332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_fence_unref(&fence); 530332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 531332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 532332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail_unreserve: 533332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_page_flip_unreserve(old_bo, new_bo, NULL); 534332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail_free: 535332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez kfree(s); 536332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 537332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 538332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 539332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezint 540332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_finish_page_flip(struct nouveau_channel *chan, 541332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *ps) 542332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 543332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_device *dev = chan->dev; 544332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *s; 545332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez unsigned long flags; 546332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 547332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_lock_irqsave(&dev->event_lock, flags); 548332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 549332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (list_empty(&chan->nvsw.flip)) { 550332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez NV_ERROR(dev, "Unexpected pageflip in channel %d.\n", chan->id); 551332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 552332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return -EINVAL; 553332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez } 554332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 555332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez s = list_first_entry(&chan->nvsw.flip, 556332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state, head); 557332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (s->event) { 558332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_pending_vblank_event *e = s->event; 559332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct timeval now; 560332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 561332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez do_gettimeofday(&now); 562332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez e->event.sequence = 0; 563332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez e->event.tv_sec = now.tv_sec; 564332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez e->event.tv_usec = now.tv_usec; 565332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_add_tail(&e->base.link, &e->base.file_priv->event_list); 566332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez wake_up_interruptible(&e->base.file_priv->event_wait); 567332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez } 568332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 569332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_del(&s->head); 570d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs if (ps) 571d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs *ps = *s; 572332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez kfree(s); 573332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 574332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 575332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 576332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 57733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 57833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsint 57933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsnouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev, 58033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct drm_mode_create_dumb *args) 58133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs{ 58233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct nouveau_bo *bo; 58333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs int ret; 58433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 58533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs args->pitch = roundup(args->width * (args->bpp / 8), 256); 58633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs args->size = args->pitch * args->height; 58733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs args->size = roundup(args->size, PAGE_SIZE); 58833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 58933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs ret = nouveau_gem_new(dev, args->size, 0, TTM_PL_FLAG_VRAM, 0, 0, &bo); 59033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs if (ret) 59133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return ret; 59233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 59333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs ret = drm_gem_handle_create(file_priv, bo->gem, &args->handle); 59433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs drm_gem_object_unreference_unlocked(bo->gem); 59533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return ret; 59633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs} 59733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 59833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsint 59933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsnouveau_display_dumb_destroy(struct drm_file *file_priv, struct drm_device *dev, 60033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs uint32_t handle) 60133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs{ 60233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return drm_gem_handle_delete(file_priv, handle); 60333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs} 60433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 60533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsint 60633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsnouveau_display_dumb_map_offset(struct drm_file *file_priv, 60733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct drm_device *dev, 60833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs uint32_t handle, uint64_t *poffset) 60933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs{ 61033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct drm_gem_object *gem; 61133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 61233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs gem = drm_gem_object_lookup(dev, file_priv, handle); 61333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs if (gem) { 61433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct nouveau_bo *bo = gem->driver_private; 61533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs *poffset = bo->bo.addr_space_offset; 61633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs drm_gem_object_unreference_unlocked(gem); 61733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return 0; 61833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs } 61933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 62033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return -ENOENT; 62133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs} 622