nouveau_display.c revision 4a67d39190315558631d944b1cea4466ed4c86d8
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 = 284b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs drm_property_create(dev, DRM_MODE_PROP_RANGE, 285b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs "underscan hborder", 2); 286b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_hborder_property->values[0] = 0; 287b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_hborder_property->values[1] = 128; 288b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 289b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_vborder_property = 290b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs drm_property_create(dev, DRM_MODE_PROP_RANGE, 291b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs "underscan vborder", 2); 292b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_vborder_property->values[0] = 0; 293b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs disp->underscan_vborder_property->values[1] = 128; 294b29caa5885e85bbda7c84ea55721b9e79718583aBen Skeggs 29527d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs; 29627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.fb_base = pci_resource_start(dev->pdev, 1); 29727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 29827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.min_width = 0; 29927d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.min_height = 0; 30027d5030a235d89842ed70e18d924f017b34a496dBen Skeggs if (dev_priv->card_type < NV_10) { 30127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_width = 2048; 30227d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_height = 2048; 30327d5030a235d89842ed70e18d924f017b34a496dBen Skeggs } else 30427d5030a235d89842ed70e18d924f017b34a496dBen Skeggs if (dev_priv->card_type < NV_50) { 30527d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_width = 4096; 30627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_height = 4096; 30727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs } else { 30827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_width = 8192; 30927d5030a235d89842ed70e18d924f017b34a496dBen Skeggs dev->mode_config.max_height = 8192; 31027d5030a235d89842ed70e18d924f017b34a496dBen Skeggs } 31127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 312f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs drm_kms_helper_poll_init(dev); 313f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs drm_kms_helper_poll_disable(dev); 314f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 31527d5030a235d89842ed70e18d924f017b34a496dBen Skeggs ret = disp->create(dev); 31627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs if (ret) 31727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs return ret; 31827d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 319f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs if (dev->mode_config.num_crtc) { 320f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs ret = drm_vblank_init(dev, dev->mode_config.num_crtc); 321f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs if (ret) 322f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs return ret; 323f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs } 324f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 3252a44e4997c5fee8e1da1589ff57e0bd1c53f03ceBen Skeggs return ret; 32627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs} 32727d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 32827d5030a235d89842ed70e18d924f017b34a496dBen Skeggsvoid 32927d5030a235d89842ed70e18d924f017b34a496dBen Skeggsnouveau_display_destroy(struct drm_device *dev) 33027d5030a235d89842ed70e18d924f017b34a496dBen Skeggs{ 33127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs struct drm_nouveau_private *dev_priv = dev->dev_private; 33227d5030a235d89842ed70e18d924f017b34a496dBen Skeggs struct nouveau_display_engine *disp = &dev_priv->engine.display; 33327d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 334f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs drm_vblank_cleanup(dev); 335f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 33627d5030a235d89842ed70e18d924f017b34a496dBen Skeggs disp->destroy(dev); 337f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs 338f62b27db6b5479efe376b408802a081a834ef50eBen Skeggs drm_kms_helper_poll_fini(dev); 33927d5030a235d89842ed70e18d924f017b34a496dBen Skeggs drm_mode_config_cleanup(dev); 34027d5030a235d89842ed70e18d924f017b34a496dBen Skeggs} 34127d5030a235d89842ed70e18d924f017b34a496dBen Skeggs 34227d5030a235d89842ed70e18d924f017b34a496dBen Skeggsint 343042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jereznouveau_vblank_enable(struct drm_device *dev, int crtc) 344042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez{ 345042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez struct drm_nouveau_private *dev_priv = dev->dev_private; 346042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 347042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez if (dev_priv->card_type >= NV_50) 348042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, 0, 349042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc)); 350042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez else 351042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, 352042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NV_PCRTC_INTR_0_VBLANK); 353042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 354042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez return 0; 355042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez} 356042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 357042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerezvoid 358042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jereznouveau_vblank_disable(struct drm_device *dev, int crtc) 359042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez{ 360042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez struct drm_nouveau_private *dev_priv = dev->dev_private; 361042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez 362042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez if (dev_priv->card_type >= NV_50) 363042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez nv_mask(dev, NV50_PDISPLAY_INTR_EN_1, 364042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NV50_PDISPLAY_INTR_EN_1_VBLANK_CRTC_(crtc), 0); 365042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez else 366042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez NVWriteCRTC(dev, crtc, NV_PCRTC_INTR_EN_0, 0); 367042206c0cd4924879c4292c5ffa2bf1e8023ae5aFrancisco Jerez} 368332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 369332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezstatic int 370332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_page_flip_reserve(struct nouveau_bo *old_bo, 371332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo) 372332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 373332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez int ret; 374332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 375332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM); 376332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 377332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 378332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 379332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = ttm_bo_reserve(&new_bo->bo, false, false, false, 0); 380332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 381332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 382332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 383332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = ttm_bo_reserve(&old_bo->bo, false, false, false, 0); 384332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 385332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail_unreserve; 386332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 387332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 388332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 389332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail_unreserve: 390332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ttm_bo_unreserve(&new_bo->bo); 391332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail: 392332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_unpin(new_bo); 393332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 394332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 395332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 396332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezstatic void 397332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_page_flip_unreserve(struct nouveau_bo *old_bo, 398332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo, 399332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_fence *fence) 400332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 401332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_fence(new_bo, fence); 402332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ttm_bo_unreserve(&new_bo->bo); 403332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 404332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_fence(old_bo, fence); 405332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ttm_bo_unreserve(&old_bo->bo); 406332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 407332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_bo_unpin(old_bo); 408332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 409332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 410332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezstatic int 411332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_page_flip_emit(struct nouveau_channel *chan, 412332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *old_bo, 413332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo, 414332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *s, 415332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_fence **pfence) 416332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 417bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs struct drm_nouveau_private *dev_priv = chan->dev->dev_private; 418332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_device *dev = chan->dev; 419332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez unsigned long flags; 420332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez int ret; 421332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 422332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Queue it to the pending list */ 423332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_lock_irqsave(&dev->event_lock, flags); 424332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_add_tail(&s->head, &chan->nvsw.flip); 425332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 426332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 427332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Synchronize with the old framebuffer */ 428332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_fence_sync(old_bo->bo.sync_obj, chan); 429332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 430332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 431332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 432332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Emit the pageflip */ 433332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = RING_SPACE(chan, 2); 434332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 435332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 436332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 437bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs if (dev_priv->card_type < NV_C0) 438bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs BEGIN_RING(chan, NvSubSw, NV_SW_PAGE_FLIP, 1); 439bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs else 440bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs BEGIN_NVC0(chan, 2, NvSubM2MF, 0x0500, 1); 441bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs OUT_RING (chan, 0); 442bd2f2037a42d4657ead3be2918db22e63626cd35Ben Skeggs FIRE_RING (chan); 443332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 444332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_fence_new(chan, pfence, true); 445332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 446332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail; 447332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 448332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 449332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail: 450332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_lock_irqsave(&dev->event_lock, flags); 451332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_del(&s->head); 452332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 453332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 454332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 455332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 456332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezint 457332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, 458332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_pending_vblank_event *event) 459332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 460332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_device *dev = crtc->dev; 461332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_nouveau_private *dev_priv = dev->dev_private; 462332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *old_bo = nouveau_framebuffer(crtc->fb)->nvbo; 463332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_bo *new_bo = nouveau_framebuffer(fb)->nvbo; 464332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *s; 465332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_channel *chan; 466332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_fence *fence; 467332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez int ret; 468332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 469a82dd49f14742e2529f79feb6360e0993277e788Ben Skeggs if (!dev_priv->channel) 470332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return -ENODEV; 471332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 472332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez s = kzalloc(sizeof(*s), GFP_KERNEL); 473332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (!s) 474332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return -ENOMEM; 475332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 476332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Don't let the buffers go away while we flip */ 477332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_page_flip_reserve(old_bo, new_bo); 478332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 479332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail_free; 480332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 481332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Initialize a page flip struct */ 482332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez *s = (struct nouveau_page_flip_state) 4832503c6fa3edf7c2bb001c7f7926786eed24cc06eBenjamin Franzke { { }, event, nouveau_crtc(crtc)->index, 48401f2c7730e188077026c5f766f85f329c7000c54Ville Syrjälä fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y, 485332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez new_bo->bo.offset }; 486332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 487332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Choose the channel the flip will be handled in */ 488332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez chan = nouveau_fence_channel(new_bo->bo.sync_obj); 489332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (!chan) 490332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez chan = nouveau_channel_get_unlocked(dev_priv->channel); 491332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez mutex_lock(&chan->mutex); 492332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 493332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Emit a page flip */ 494d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs if (dev_priv->card_type >= NV_50) { 4953376ee374d2318d311bd3aa7b9bb0186f64ccca5Ben Skeggs if (dev_priv->card_type >= NV_D0) 4963376ee374d2318d311bd3aa7b9bb0186f64ccca5Ben Skeggs ret = nvd0_display_flip_next(crtc, fb, chan, 0); 4973376ee374d2318d311bd3aa7b9bb0186f64ccca5Ben Skeggs else 4983376ee374d2318d311bd3aa7b9bb0186f64ccca5Ben Skeggs ret = nv50_display_flip_next(crtc, fb, chan); 499d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs if (ret) { 500d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs nouveau_channel_put(&chan); 501d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs goto fail_unreserve; 502d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs } 503d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs } 504d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs 505332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez ret = nouveau_page_flip_emit(chan, old_bo, new_bo, s, &fence); 506332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_channel_put(&chan); 507332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (ret) 508332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez goto fail_unreserve; 509332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 510332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez /* Update the crtc struct and cleanup */ 511332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez crtc->fb = fb; 512332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 513332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_page_flip_unreserve(old_bo, new_bo, fence); 514332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_fence_unref(&fence); 515332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 516332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 517332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail_unreserve: 518332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez nouveau_page_flip_unreserve(old_bo, new_bo, NULL); 519332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezfail_free: 520332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez kfree(s); 521332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return ret; 522332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 523332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 524332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerezint 525332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jereznouveau_finish_page_flip(struct nouveau_channel *chan, 526332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *ps) 527332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez{ 528332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_device *dev = chan->dev; 529332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state *s; 530332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez unsigned long flags; 531332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 532332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_lock_irqsave(&dev->event_lock, flags); 533332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 534332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (list_empty(&chan->nvsw.flip)) { 535332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez NV_ERROR(dev, "Unexpected pageflip in channel %d.\n", chan->id); 536332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 537332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return -EINVAL; 538332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez } 539332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 540332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez s = list_first_entry(&chan->nvsw.flip, 541332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct nouveau_page_flip_state, head); 542332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez if (s->event) { 543332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct drm_pending_vblank_event *e = s->event; 544332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez struct timeval now; 545332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 546332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez do_gettimeofday(&now); 547332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez e->event.sequence = 0; 548332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez e->event.tv_sec = now.tv_sec; 549332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez e->event.tv_usec = now.tv_usec; 550332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_add_tail(&e->base.link, &e->base.file_priv->event_list); 551332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez wake_up_interruptible(&e->base.file_priv->event_wait); 552332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez } 553332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 554332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez list_del(&s->head); 555d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs if (ps) 556d7117e0d4e21034202833088e51fc21f8c8271f9Ben Skeggs *ps = *s; 557332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez kfree(s); 558332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez 559332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez spin_unlock_irqrestore(&dev->event_lock, flags); 560332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez return 0; 561332b242f47786d1a43bd7a19a0513dd5d493db8eFrancisco Jerez} 56233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 56333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsint 56433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsnouveau_display_dumb_create(struct drm_file *file_priv, struct drm_device *dev, 56533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct drm_mode_create_dumb *args) 56633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs{ 56733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct nouveau_bo *bo; 56833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs int ret; 56933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 57033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs args->pitch = roundup(args->width * (args->bpp / 8), 256); 57133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs args->size = args->pitch * args->height; 57233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs args->size = roundup(args->size, PAGE_SIZE); 57333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 57433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs ret = nouveau_gem_new(dev, args->size, 0, TTM_PL_FLAG_VRAM, 0, 0, &bo); 57533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs if (ret) 57633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return ret; 57733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 57833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs ret = drm_gem_handle_create(file_priv, bo->gem, &args->handle); 57933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs drm_gem_object_unreference_unlocked(bo->gem); 58033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return ret; 58133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs} 58233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 58333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsint 58433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsnouveau_display_dumb_destroy(struct drm_file *file_priv, struct drm_device *dev, 58533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs uint32_t handle) 58633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs{ 58733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return drm_gem_handle_delete(file_priv, handle); 58833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs} 58933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 59033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsint 59133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggsnouveau_display_dumb_map_offset(struct drm_file *file_priv, 59233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct drm_device *dev, 59333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs uint32_t handle, uint64_t *poffset) 59433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs{ 59533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct drm_gem_object *gem; 59633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 59733dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs gem = drm_gem_object_lookup(dev, file_priv, handle); 59833dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs if (gem) { 59933dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs struct nouveau_bo *bo = gem->driver_private; 60033dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs *poffset = bo->bo.addr_space_offset; 60133dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs drm_gem_object_unreference_unlocked(gem); 60233dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return 0; 60333dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs } 60433dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs 60533dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs return -ENOENT; 60633dbc27f1ab3a37d04a8d226327fb3d384870e43Ben Skeggs} 607