Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Ilia Mirkin |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 18 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF |
| 19 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | * SOFTWARE. |
| 21 | * |
| 22 | * Implementation based on the pre-KMS implementation in xf86-video-nouveau, |
| 23 | * written by Arthur Huillet. |
| 24 | */ |
| 25 | |
| 26 | #include <drm/drmP.h> |
| 27 | #include <drm/drm_crtc.h> |
| 28 | #include <drm/drm_fourcc.h> |
| 29 | |
Ben Skeggs | 4dc2813 | 2016-05-20 09:22:55 +1000 | [diff] [blame] | 30 | #include "nouveau_drv.h" |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 31 | |
| 32 | #include "nouveau_bo.h" |
| 33 | #include "nouveau_connector.h" |
| 34 | #include "nouveau_display.h" |
| 35 | #include "nvreg.h" |
Baoyou Xie | e8390eb | 2016-10-24 11:09:02 +0800 | [diff] [blame] | 36 | #include "disp.h" |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 37 | |
| 38 | struct nouveau_plane { |
| 39 | struct drm_plane base; |
| 40 | bool flip; |
| 41 | struct nouveau_bo *cur; |
| 42 | |
| 43 | struct { |
| 44 | struct drm_property *colorkey; |
| 45 | struct drm_property *contrast; |
| 46 | struct drm_property *brightness; |
| 47 | struct drm_property *hue; |
| 48 | struct drm_property *saturation; |
| 49 | struct drm_property *iturbt_709; |
| 50 | } props; |
| 51 | |
| 52 | int colorkey; |
| 53 | int contrast; |
| 54 | int brightness; |
| 55 | int hue; |
| 56 | int saturation; |
| 57 | int iturbt_709; |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 58 | |
| 59 | void (*set_params)(struct nouveau_plane *); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static uint32_t formats[] = { |
Ilia Mirkin | 7ffb078 | 2013-11-15 11:26:44 -0500 | [diff] [blame] | 63 | DRM_FORMAT_YUYV, |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 64 | DRM_FORMAT_UYVY, |
Ilia Mirkin | efffa98 | 2013-11-15 11:26:43 -0500 | [diff] [blame] | 65 | DRM_FORMAT_NV12, |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /* Sine can be approximated with |
| 69 | * http://en.wikipedia.org/wiki/Bhaskara_I's_sine_approximation_formula |
| 70 | * sin(x degrees) ~= 4 x (180 - x) / (40500 - x (180 - x) ) |
| 71 | * Note that this only works for the range [0, 180]. |
| 72 | * Also note that sin(x) == -sin(x - 180) |
| 73 | */ |
| 74 | static inline int |
| 75 | sin_mul(int degrees, int factor) |
| 76 | { |
| 77 | if (degrees > 180) { |
| 78 | degrees -= 180; |
| 79 | factor *= -1; |
| 80 | } |
| 81 | return factor * 4 * degrees * (180 - degrees) / |
| 82 | (40500 - degrees * (180 - degrees)); |
| 83 | } |
| 84 | |
| 85 | /* cos(x) = sin(x + 90) */ |
| 86 | static inline int |
| 87 | cos_mul(int degrees, int factor) |
| 88 | { |
| 89 | return sin_mul((degrees + 90) % 360, factor); |
| 90 | } |
| 91 | |
| 92 | static int |
| 93 | nv10_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
| 94 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
| 95 | unsigned int crtc_w, unsigned int crtc_h, |
| 96 | uint32_t src_x, uint32_t src_y, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 97 | uint32_t src_w, uint32_t src_h, |
| 98 | struct drm_modeset_acquire_ctx *ctx) |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 99 | { |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 100 | struct nouveau_drm *drm = nouveau_drm(plane->dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 101 | struct nvif_object *dev = &drm->client.device.object; |
Fabian Frederick | 5ee932d | 2014-09-14 18:40:18 +0200 | [diff] [blame] | 102 | struct nouveau_plane *nv_plane = |
| 103 | container_of(plane, struct nouveau_plane, base); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 104 | struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb); |
| 105 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 106 | struct nouveau_bo *cur = nv_plane->cur; |
| 107 | bool flip = nv_plane->flip; |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 108 | int soff = NV_PCRTC0_SIZE * nv_crtc->index; |
| 109 | int soff2 = NV_PCRTC0_SIZE * !nv_crtc->index; |
Ilia Mirkin | 92e5b0a | 2013-11-15 11:26:41 -0500 | [diff] [blame] | 110 | int format, ret; |
| 111 | |
| 112 | /* Source parameters given in 16.16 fixed point, ignore fractional. */ |
| 113 | src_x >>= 16; |
| 114 | src_y >>= 16; |
| 115 | src_w >>= 16; |
| 116 | src_h >>= 16; |
| 117 | |
| 118 | format = ALIGN(src_w * 4, 0x100); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 119 | |
| 120 | if (format > 0xffff) |
Ilia Mirkin | 050828e | 2013-11-15 11:26:42 -0500 | [diff] [blame] | 121 | return -ERANGE; |
| 122 | |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 123 | if (drm->client.device.info.chipset >= 0x30) { |
Ilia Mirkin | 050828e | 2013-11-15 11:26:42 -0500 | [diff] [blame] | 124 | if (crtc_w < (src_w >> 1) || crtc_h < (src_h >> 1)) |
| 125 | return -ERANGE; |
| 126 | } else { |
| 127 | if (crtc_w < (src_w >> 3) || crtc_h < (src_h >> 3)) |
| 128 | return -ERANGE; |
| 129 | } |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 130 | |
Ben Skeggs | ad76b3f | 2014-11-10 11:24:27 +1000 | [diff] [blame] | 131 | ret = nouveau_bo_pin(nv_fb->nvbo, TTM_PL_FLAG_VRAM, false); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 132 | if (ret) |
| 133 | return ret; |
| 134 | |
| 135 | nv_plane->cur = nv_fb->nvbo; |
| 136 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 137 | nvif_mask(dev, NV_PCRTC_ENGINE_CTRL + soff, NV_CRTC_FSEL_OVERLAY, NV_CRTC_FSEL_OVERLAY); |
| 138 | nvif_mask(dev, NV_PCRTC_ENGINE_CTRL + soff2, NV_CRTC_FSEL_OVERLAY, 0); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 139 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 140 | nvif_wr32(dev, NV_PVIDEO_BASE(flip), 0); |
| 141 | nvif_wr32(dev, NV_PVIDEO_OFFSET_BUFF(flip), nv_fb->nvbo->bo.offset); |
| 142 | nvif_wr32(dev, NV_PVIDEO_SIZE_IN(flip), src_h << 16 | src_w); |
| 143 | nvif_wr32(dev, NV_PVIDEO_POINT_IN(flip), src_y << 16 | src_x); |
| 144 | nvif_wr32(dev, NV_PVIDEO_DS_DX(flip), (src_w << 20) / crtc_w); |
| 145 | nvif_wr32(dev, NV_PVIDEO_DT_DY(flip), (src_h << 20) / crtc_h); |
| 146 | nvif_wr32(dev, NV_PVIDEO_POINT_OUT(flip), crtc_y << 16 | crtc_x); |
| 147 | nvif_wr32(dev, NV_PVIDEO_SIZE_OUT(flip), crtc_h << 16 | crtc_w); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 148 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 149 | if (fb->format->format != DRM_FORMAT_UYVY) |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 150 | format |= NV_PVIDEO_FORMAT_COLOR_LE_CR8YB8CB8YA8; |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 151 | if (fb->format->format == DRM_FORMAT_NV12) |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 152 | format |= NV_PVIDEO_FORMAT_PLANAR; |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 153 | if (nv_plane->iturbt_709) |
| 154 | format |= NV_PVIDEO_FORMAT_MATRIX_ITURBT709; |
| 155 | if (nv_plane->colorkey & (1 << 24)) |
| 156 | format |= NV_PVIDEO_FORMAT_DISPLAY_COLOR_KEY; |
| 157 | |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 158 | if (fb->format->format == DRM_FORMAT_NV12) { |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 159 | nvif_wr32(dev, NV_PVIDEO_UVPLANE_BASE(flip), 0); |
| 160 | nvif_wr32(dev, NV_PVIDEO_UVPLANE_OFFSET_BUFF(flip), |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 161 | nv_fb->nvbo->bo.offset + fb->offsets[1]); |
| 162 | } |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 163 | nvif_wr32(dev, NV_PVIDEO_FORMAT(flip), format); |
| 164 | nvif_wr32(dev, NV_PVIDEO_STOP, 0); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 165 | /* TODO: wait for vblank? */ |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 166 | nvif_wr32(dev, NV_PVIDEO_BUFFER, flip ? 0x10 : 0x1); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 167 | nv_plane->flip = !flip; |
| 168 | |
| 169 | if (cur) |
| 170 | nouveau_bo_unpin(cur); |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | static int |
| 176 | nv10_disable_plane(struct drm_plane *plane) |
| 177 | { |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 178 | struct nvif_object *dev = &nouveau_drm(plane->dev)->client.device.object; |
Fabian Frederick | 5ee932d | 2014-09-14 18:40:18 +0200 | [diff] [blame] | 179 | struct nouveau_plane *nv_plane = |
| 180 | container_of(plane, struct nouveau_plane, base); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 181 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 182 | nvif_wr32(dev, NV_PVIDEO_STOP, 1); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 183 | if (nv_plane->cur) { |
| 184 | nouveau_bo_unpin(nv_plane->cur); |
| 185 | nv_plane->cur = NULL; |
| 186 | } |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static void |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 192 | nv_destroy_plane(struct drm_plane *plane) |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 193 | { |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 194 | plane->funcs->disable_plane(plane); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 195 | drm_plane_cleanup(plane); |
| 196 | kfree(plane); |
| 197 | } |
| 198 | |
| 199 | static void |
| 200 | nv10_set_params(struct nouveau_plane *plane) |
| 201 | { |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 202 | struct nvif_object *dev = &nouveau_drm(plane->base.dev)->client.device.object; |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 203 | u32 luma = (plane->brightness - 512) << 16 | plane->contrast; |
| 204 | u32 chroma = ((sin_mul(plane->hue, plane->saturation) & 0xffff) << 16) | |
| 205 | (cos_mul(plane->hue, plane->saturation) & 0xffff); |
| 206 | u32 format = 0; |
| 207 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 208 | nvif_wr32(dev, NV_PVIDEO_LUMINANCE(0), luma); |
| 209 | nvif_wr32(dev, NV_PVIDEO_LUMINANCE(1), luma); |
| 210 | nvif_wr32(dev, NV_PVIDEO_CHROMINANCE(0), chroma); |
| 211 | nvif_wr32(dev, NV_PVIDEO_CHROMINANCE(1), chroma); |
| 212 | nvif_wr32(dev, NV_PVIDEO_COLOR_KEY, plane->colorkey & 0xffffff); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 213 | |
| 214 | if (plane->cur) { |
| 215 | if (plane->iturbt_709) |
| 216 | format |= NV_PVIDEO_FORMAT_MATRIX_ITURBT709; |
| 217 | if (plane->colorkey & (1 << 24)) |
| 218 | format |= NV_PVIDEO_FORMAT_DISPLAY_COLOR_KEY; |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 219 | nvif_mask(dev, NV_PVIDEO_FORMAT(plane->flip), |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 220 | NV_PVIDEO_FORMAT_MATRIX_ITURBT709 | |
| 221 | NV_PVIDEO_FORMAT_DISPLAY_COLOR_KEY, |
| 222 | format); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | static int |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 227 | nv_set_property(struct drm_plane *plane, |
| 228 | struct drm_property *property, |
| 229 | uint64_t value) |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 230 | { |
Fabian Frederick | 5ee932d | 2014-09-14 18:40:18 +0200 | [diff] [blame] | 231 | struct nouveau_plane *nv_plane = |
| 232 | container_of(plane, struct nouveau_plane, base); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 233 | |
| 234 | if (property == nv_plane->props.colorkey) |
| 235 | nv_plane->colorkey = value; |
| 236 | else if (property == nv_plane->props.contrast) |
| 237 | nv_plane->contrast = value; |
| 238 | else if (property == nv_plane->props.brightness) |
| 239 | nv_plane->brightness = value; |
| 240 | else if (property == nv_plane->props.hue) |
| 241 | nv_plane->hue = value; |
| 242 | else if (property == nv_plane->props.saturation) |
| 243 | nv_plane->saturation = value; |
| 244 | else if (property == nv_plane->props.iturbt_709) |
| 245 | nv_plane->iturbt_709 = value; |
| 246 | else |
| 247 | return -EINVAL; |
| 248 | |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 249 | if (nv_plane->set_params) |
| 250 | nv_plane->set_params(nv_plane); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static const struct drm_plane_funcs nv10_plane_funcs = { |
| 255 | .update_plane = nv10_update_plane, |
| 256 | .disable_plane = nv10_disable_plane, |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 257 | .set_property = nv_set_property, |
| 258 | .destroy = nv_destroy_plane, |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 259 | }; |
| 260 | |
| 261 | static void |
| 262 | nv10_overlay_init(struct drm_device *device) |
| 263 | { |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 264 | struct nouveau_drm *drm = nouveau_drm(device); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 265 | struct nouveau_plane *plane = kzalloc(sizeof(struct nouveau_plane), GFP_KERNEL); |
Thierry Reding | 45e3743 | 2015-08-12 16:54:28 +0200 | [diff] [blame] | 266 | unsigned int num_formats = ARRAY_SIZE(formats); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 267 | int ret; |
| 268 | |
| 269 | if (!plane) |
| 270 | return; |
| 271 | |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 272 | switch (drm->client.device.info.chipset) { |
Ilia Mirkin | efffa98 | 2013-11-15 11:26:43 -0500 | [diff] [blame] | 273 | case 0x10: |
| 274 | case 0x11: |
| 275 | case 0x15: |
| 276 | case 0x1a: |
| 277 | case 0x20: |
Ilia Mirkin | 7ffb078 | 2013-11-15 11:26:44 -0500 | [diff] [blame] | 278 | num_formats = 2; |
Ilia Mirkin | efffa98 | 2013-11-15 11:26:43 -0500 | [diff] [blame] | 279 | break; |
| 280 | } |
| 281 | |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 282 | ret = drm_plane_init(device, &plane->base, 3 /* both crtc's */, |
| 283 | &nv10_plane_funcs, |
Ilia Mirkin | efffa98 | 2013-11-15 11:26:43 -0500 | [diff] [blame] | 284 | formats, num_formats, false); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 285 | if (ret) |
| 286 | goto err; |
| 287 | |
| 288 | /* Set up the plane properties */ |
| 289 | plane->props.colorkey = drm_property_create_range( |
| 290 | device, 0, "colorkey", 0, 0x01ffffff); |
| 291 | plane->props.contrast = drm_property_create_range( |
| 292 | device, 0, "contrast", 0, 8192 - 1); |
| 293 | plane->props.brightness = drm_property_create_range( |
| 294 | device, 0, "brightness", 0, 1024); |
| 295 | plane->props.hue = drm_property_create_range( |
| 296 | device, 0, "hue", 0, 359); |
| 297 | plane->props.saturation = drm_property_create_range( |
| 298 | device, 0, "saturation", 0, 8192 - 1); |
| 299 | plane->props.iturbt_709 = drm_property_create_range( |
| 300 | device, 0, "iturbt_709", 0, 1); |
| 301 | if (!plane->props.colorkey || |
| 302 | !plane->props.contrast || |
| 303 | !plane->props.brightness || |
| 304 | !plane->props.hue || |
| 305 | !plane->props.saturation || |
| 306 | !plane->props.iturbt_709) |
| 307 | goto cleanup; |
| 308 | |
| 309 | plane->colorkey = 0; |
| 310 | drm_object_attach_property(&plane->base.base, |
| 311 | plane->props.colorkey, plane->colorkey); |
| 312 | |
| 313 | plane->contrast = 0x1000; |
| 314 | drm_object_attach_property(&plane->base.base, |
| 315 | plane->props.contrast, plane->contrast); |
| 316 | |
| 317 | plane->brightness = 512; |
| 318 | drm_object_attach_property(&plane->base.base, |
| 319 | plane->props.brightness, plane->brightness); |
| 320 | |
| 321 | plane->hue = 0; |
| 322 | drm_object_attach_property(&plane->base.base, |
| 323 | plane->props.hue, plane->hue); |
| 324 | |
| 325 | plane->saturation = 0x1000; |
| 326 | drm_object_attach_property(&plane->base.base, |
| 327 | plane->props.saturation, plane->saturation); |
| 328 | |
| 329 | plane->iturbt_709 = 0; |
| 330 | drm_object_attach_property(&plane->base.base, |
| 331 | plane->props.iturbt_709, plane->iturbt_709); |
| 332 | |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 333 | plane->set_params = nv10_set_params; |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 334 | nv10_set_params(plane); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 335 | nv10_disable_plane(&plane->base); |
| 336 | return; |
| 337 | cleanup: |
| 338 | drm_plane_cleanup(&plane->base); |
| 339 | err: |
| 340 | kfree(plane); |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 341 | NV_ERROR(drm, "Failed to create plane\n"); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static int |
| 345 | nv04_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, |
| 346 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
| 347 | unsigned int crtc_w, unsigned int crtc_h, |
| 348 | uint32_t src_x, uint32_t src_y, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 349 | uint32_t src_w, uint32_t src_h, |
| 350 | struct drm_modeset_acquire_ctx *ctx) |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 351 | { |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 352 | struct nvif_object *dev = &nouveau_drm(plane->dev)->client.device.object; |
Fabian Frederick | 5ee932d | 2014-09-14 18:40:18 +0200 | [diff] [blame] | 353 | struct nouveau_plane *nv_plane = |
| 354 | container_of(plane, struct nouveau_plane, base); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 355 | struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb); |
| 356 | struct nouveau_bo *cur = nv_plane->cur; |
| 357 | uint32_t overlay = 1; |
| 358 | int brightness = (nv_plane->brightness - 512) * 62 / 512; |
| 359 | int pitch, ret, i; |
| 360 | |
| 361 | /* Source parameters given in 16.16 fixed point, ignore fractional. */ |
| 362 | src_x >>= 16; |
| 363 | src_y >>= 16; |
| 364 | src_w >>= 16; |
| 365 | src_h >>= 16; |
| 366 | |
| 367 | pitch = ALIGN(src_w * 4, 0x100); |
| 368 | |
| 369 | if (pitch > 0xffff) |
| 370 | return -ERANGE; |
| 371 | |
| 372 | /* TODO: Compute an offset? Not sure how to do this for YUYV. */ |
| 373 | if (src_x != 0 || src_y != 0) |
| 374 | return -ERANGE; |
| 375 | |
| 376 | if (crtc_w < src_w || crtc_h < src_h) |
| 377 | return -ERANGE; |
| 378 | |
Ben Skeggs | ad76b3f | 2014-11-10 11:24:27 +1000 | [diff] [blame] | 379 | ret = nouveau_bo_pin(nv_fb->nvbo, TTM_PL_FLAG_VRAM, false); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 380 | if (ret) |
| 381 | return ret; |
| 382 | |
| 383 | nv_plane->cur = nv_fb->nvbo; |
| 384 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 385 | nvif_wr32(dev, NV_PVIDEO_OE_STATE, 0); |
| 386 | nvif_wr32(dev, NV_PVIDEO_SU_STATE, 0); |
| 387 | nvif_wr32(dev, NV_PVIDEO_RM_STATE, 0); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 388 | |
| 389 | for (i = 0; i < 2; i++) { |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 390 | nvif_wr32(dev, NV_PVIDEO_BUFF0_START_ADDRESS + 4 * i, |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 391 | nv_fb->nvbo->bo.offset); |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 392 | nvif_wr32(dev, NV_PVIDEO_BUFF0_PITCH_LENGTH + 4 * i, pitch); |
| 393 | nvif_wr32(dev, NV_PVIDEO_BUFF0_OFFSET + 4 * i, 0); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 394 | } |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 395 | nvif_wr32(dev, NV_PVIDEO_WINDOW_START, crtc_y << 16 | crtc_x); |
| 396 | nvif_wr32(dev, NV_PVIDEO_WINDOW_SIZE, crtc_h << 16 | crtc_w); |
| 397 | nvif_wr32(dev, NV_PVIDEO_STEP_SIZE, |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 398 | (uint32_t)(((src_h - 1) << 11) / (crtc_h - 1)) << 16 | (uint32_t)(((src_w - 1) << 11) / (crtc_w - 1))); |
| 399 | |
| 400 | /* It should be possible to convert hue/contrast to this */ |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 401 | nvif_wr32(dev, NV_PVIDEO_RED_CSC_OFFSET, 0x69 - brightness); |
| 402 | nvif_wr32(dev, NV_PVIDEO_GREEN_CSC_OFFSET, 0x3e + brightness); |
| 403 | nvif_wr32(dev, NV_PVIDEO_BLUE_CSC_OFFSET, 0x89 - brightness); |
| 404 | nvif_wr32(dev, NV_PVIDEO_CSC_ADJUST, 0); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 405 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 406 | nvif_wr32(dev, NV_PVIDEO_CONTROL_Y, 0x001); /* (BLUR_ON, LINE_HALF) */ |
| 407 | nvif_wr32(dev, NV_PVIDEO_CONTROL_X, 0x111); /* (WEIGHT_HEAVY, SHARPENING_ON, SMOOTHING_ON) */ |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 408 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 409 | nvif_wr32(dev, NV_PVIDEO_FIFO_BURST_LENGTH, 0x03); |
| 410 | nvif_wr32(dev, NV_PVIDEO_FIFO_THRES_SIZE, 0x38); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 411 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 412 | nvif_wr32(dev, NV_PVIDEO_KEY, nv_plane->colorkey); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 413 | |
| 414 | if (nv_plane->colorkey & (1 << 24)) |
| 415 | overlay |= 0x10; |
Ville Syrjälä | 438b74a | 2016-12-14 23:32:55 +0200 | [diff] [blame] | 416 | if (fb->format->format == DRM_FORMAT_YUYV) |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 417 | overlay |= 0x100; |
| 418 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 419 | nvif_wr32(dev, NV_PVIDEO_OVERLAY, overlay); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 420 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 421 | nvif_wr32(dev, NV_PVIDEO_SU_STATE, nvif_rd32(dev, NV_PVIDEO_SU_STATE) ^ (1 << 16)); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 422 | |
| 423 | if (cur) |
| 424 | nouveau_bo_unpin(cur); |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static int |
| 430 | nv04_disable_plane(struct drm_plane *plane) |
| 431 | { |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 432 | struct nvif_object *dev = &nouveau_drm(plane->dev)->client.device.object; |
Fabian Frederick | 5ee932d | 2014-09-14 18:40:18 +0200 | [diff] [blame] | 433 | struct nouveau_plane *nv_plane = |
| 434 | container_of(plane, struct nouveau_plane, base); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 435 | |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 436 | nvif_mask(dev, NV_PVIDEO_OVERLAY, 1, 0); |
| 437 | nvif_wr32(dev, NV_PVIDEO_OE_STATE, 0); |
| 438 | nvif_wr32(dev, NV_PVIDEO_SU_STATE, 0); |
| 439 | nvif_wr32(dev, NV_PVIDEO_RM_STATE, 0); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 440 | if (nv_plane->cur) { |
| 441 | nouveau_bo_unpin(nv_plane->cur); |
| 442 | nv_plane->cur = NULL; |
| 443 | } |
| 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static const struct drm_plane_funcs nv04_plane_funcs = { |
| 449 | .update_plane = nv04_update_plane, |
| 450 | .disable_plane = nv04_disable_plane, |
| 451 | .set_property = nv_set_property, |
| 452 | .destroy = nv_destroy_plane, |
| 453 | }; |
| 454 | |
| 455 | static void |
| 456 | nv04_overlay_init(struct drm_device *device) |
| 457 | { |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 458 | struct nouveau_drm *drm = nouveau_drm(device); |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 459 | struct nouveau_plane *plane = kzalloc(sizeof(struct nouveau_plane), GFP_KERNEL); |
| 460 | int ret; |
| 461 | |
| 462 | if (!plane) |
| 463 | return; |
| 464 | |
| 465 | ret = drm_plane_init(device, &plane->base, 1 /* single crtc */, |
| 466 | &nv04_plane_funcs, |
| 467 | formats, 2, false); |
| 468 | if (ret) |
| 469 | goto err; |
| 470 | |
| 471 | /* Set up the plane properties */ |
| 472 | plane->props.colorkey = drm_property_create_range( |
| 473 | device, 0, "colorkey", 0, 0x01ffffff); |
| 474 | plane->props.brightness = drm_property_create_range( |
| 475 | device, 0, "brightness", 0, 1024); |
| 476 | if (!plane->props.colorkey || |
| 477 | !plane->props.brightness) |
| 478 | goto cleanup; |
| 479 | |
| 480 | plane->colorkey = 0; |
| 481 | drm_object_attach_property(&plane->base.base, |
| 482 | plane->props.colorkey, plane->colorkey); |
| 483 | |
| 484 | plane->brightness = 512; |
| 485 | drm_object_attach_property(&plane->base.base, |
| 486 | plane->props.brightness, plane->brightness); |
| 487 | |
| 488 | nv04_disable_plane(&plane->base); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 489 | return; |
| 490 | cleanup: |
| 491 | drm_plane_cleanup(&plane->base); |
| 492 | err: |
| 493 | kfree(plane); |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 494 | NV_ERROR(drm, "Failed to create plane\n"); |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | void |
| 498 | nouveau_overlay_init(struct drm_device *device) |
| 499 | { |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 500 | struct nvif_device *dev = &nouveau_drm(device)->client.device; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 501 | if (dev->info.chipset < 0x10) |
Ilia Mirkin | ab9b18a | 2013-11-15 11:26:45 -0500 | [diff] [blame] | 502 | nv04_overlay_init(device); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 503 | else if (dev->info.chipset <= 0x40) |
Ilia Mirkin | 515de6b | 2013-09-07 20:33:43 -0400 | [diff] [blame] | 504 | nv10_overlay_init(device); |
| 505 | } |