2 * Copyright 2018 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <nvif/class.h>
27 #include <nvif/cl0002.h>
29 #include <nvhw/class/cl507c.h>
30 #include <nvhw/class/cl507e.h>
31 #include <nvhw/class/clc37e.h>
33 #include <drm/drm_atomic.h>
34 #include <drm/drm_atomic_helper.h>
35 #include <drm/drm_fourcc.h>
37 #include "nouveau_bo.h"
38 #include "nouveau_gem.h"
41 nv50_wndw_ctxdma_del(struct nv50_wndw_ctxdma *ctxdma)
43 nvif_object_dtor(&ctxdma->object);
44 list_del(&ctxdma->head);
48 static struct nv50_wndw_ctxdma *
49 nv50_wndw_ctxdma_new(struct nv50_wndw *wndw, struct drm_framebuffer *fb)
51 struct nouveau_drm *drm = nouveau_drm(fb->dev);
52 struct nv50_wndw_ctxdma *ctxdma;
57 struct nv_dma_v0 base;
59 struct nv50_dma_v0 nv50;
60 struct gf100_dma_v0 gf100;
61 struct gf119_dma_v0 gf119;
64 u32 argc = sizeof(args.base);
67 nouveau_framebuffer_get_layout(fb, &unused, &kind);
68 handle = NV50_DISP_HANDLE_WNDW_CTX(kind);
70 list_for_each_entry(ctxdma, &wndw->ctxdma.list, head) {
71 if (ctxdma->object.handle == handle)
75 if (!(ctxdma = kzalloc(sizeof(*ctxdma), GFP_KERNEL)))
76 return ERR_PTR(-ENOMEM);
77 list_add(&ctxdma->head, &wndw->ctxdma.list);
79 args.base.target = NV_DMA_V0_TARGET_VRAM;
80 args.base.access = NV_DMA_V0_ACCESS_RDWR;
82 args.base.limit = drm->client.device.info.ram_user - 1;
84 if (drm->client.device.info.chipset < 0x80) {
85 args.nv50.part = NV50_DMA_V0_PART_256;
86 argc += sizeof(args.nv50);
88 if (drm->client.device.info.chipset < 0xc0) {
89 args.nv50.part = NV50_DMA_V0_PART_256;
90 args.nv50.kind = kind;
91 argc += sizeof(args.nv50);
93 if (drm->client.device.info.chipset < 0xd0) {
94 args.gf100.kind = kind;
95 argc += sizeof(args.gf100);
97 args.gf119.page = GF119_DMA_V0_PAGE_LP;
98 args.gf119.kind = kind;
99 argc += sizeof(args.gf119);
102 ret = nvif_object_ctor(wndw->ctxdma.parent, "kmsFbCtxDma", handle,
103 NV_DMA_IN_MEMORY, &args, argc, &ctxdma->object);
105 nv50_wndw_ctxdma_del(ctxdma);
113 nv50_wndw_wait_armed(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
115 struct nv50_disp *disp = nv50_disp(wndw->plane.dev);
116 if (asyw->set.ntfy) {
117 return wndw->func->ntfy_wait_begun(disp->sync,
119 wndw->wndw.base.device);
125 nv50_wndw_flush_clr(struct nv50_wndw *wndw, u32 *interlock, bool flush,
126 struct nv50_wndw_atom *asyw)
128 union nv50_wndw_atom_mask clr = {
129 .mask = asyw->clr.mask & ~(flush ? 0 : asyw->set.mask),
131 if (clr.sema ) wndw->func-> sema_clr(wndw);
132 if (clr.ntfy ) wndw->func-> ntfy_clr(wndw);
133 if (clr.xlut ) wndw->func-> xlut_clr(wndw);
134 if (clr.csc ) wndw->func-> csc_clr(wndw);
135 if (clr.image) wndw->func->image_clr(wndw);
137 interlock[wndw->interlock.type] |= wndw->interlock.data;
141 nv50_wndw_flush_set(struct nv50_wndw *wndw, u32 *interlock,
142 struct nv50_wndw_atom *asyw)
144 if (interlock[NV50_DISP_INTERLOCK_CORE]) {
145 asyw->image.mode = NV507C_SET_PRESENT_CONTROL_BEGIN_MODE_NON_TEARING;
146 asyw->image.interval = 1;
149 if (asyw->set.sema ) wndw->func->sema_set (wndw, asyw);
150 if (asyw->set.ntfy ) wndw->func->ntfy_set (wndw, asyw);
151 if (asyw->set.image) wndw->func->image_set(wndw, asyw);
153 if (asyw->set.xlut ) {
155 asyw->xlut.i.offset =
156 nv50_lut_load(&wndw->ilut, asyw->xlut.i.buffer,
157 asyw->ilut, asyw->xlut.i.load);
159 wndw->func->xlut_set(wndw, asyw);
162 if (asyw->set.csc ) wndw->func->csc_set (wndw, asyw);
163 if (asyw->set.scale) wndw->func->scale_set(wndw, asyw);
164 if (asyw->set.blend) wndw->func->blend_set(wndw, asyw);
165 if (asyw->set.point) {
166 if (asyw->set.point = false, asyw->set.mask)
167 interlock[wndw->interlock.type] |= wndw->interlock.data;
168 interlock[NV50_DISP_INTERLOCK_WIMM] |= wndw->interlock.wimm;
170 wndw->immd->point(wndw, asyw);
171 wndw->immd->update(wndw, interlock);
173 interlock[wndw->interlock.type] |= wndw->interlock.data;
178 nv50_wndw_ntfy_enable(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
180 struct nv50_disp *disp = nv50_disp(wndw->plane.dev);
182 asyw->ntfy.handle = wndw->wndw.sync.handle;
183 asyw->ntfy.offset = wndw->ntfy;
184 asyw->ntfy.awaken = false;
185 asyw->set.ntfy = true;
187 wndw->func->ntfy_reset(disp->sync, wndw->ntfy);
192 nv50_wndw_atomic_check_release(struct nv50_wndw *wndw,
193 struct nv50_wndw_atom *asyw,
194 struct nv50_head_atom *asyh)
196 struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev);
197 NV_ATOMIC(drm, "%s release\n", wndw->plane.name);
198 wndw->func->release(wndw, asyw, asyh);
199 asyw->ntfy.handle = 0;
200 asyw->sema.handle = 0;
201 asyw->xlut.handle = 0;
202 memset(asyw->image.handle, 0x00, sizeof(asyw->image.handle));
206 nv50_wndw_atomic_check_acquire_yuv(struct nv50_wndw_atom *asyw)
208 switch (asyw->state.fb->format->format) {
209 case DRM_FORMAT_YUYV:
210 asyw->image.format = NV507E_SURFACE_SET_PARAMS_FORMAT_VE8YO8UE8YE8;
212 case DRM_FORMAT_UYVY:
213 asyw->image.format = NV507E_SURFACE_SET_PARAMS_FORMAT_YO8VE8YE8UE8;
220 asyw->image.colorspace = NV507E_SURFACE_SET_PARAMS_COLOR_SPACE_YUV_601;
225 nv50_wndw_atomic_check_acquire_rgb(struct nv50_wndw_atom *asyw)
227 switch (asyw->state.fb->format->format) {
229 asyw->image.format = NV507C_SURFACE_SET_PARAMS_FORMAT_I8;
231 case DRM_FORMAT_XRGB8888:
232 case DRM_FORMAT_ARGB8888:
233 asyw->image.format = NV507C_SURFACE_SET_PARAMS_FORMAT_A8R8G8B8;
235 case DRM_FORMAT_RGB565:
236 asyw->image.format = NV507C_SURFACE_SET_PARAMS_FORMAT_R5G6B5;
238 case DRM_FORMAT_XRGB1555:
239 case DRM_FORMAT_ARGB1555:
240 asyw->image.format = NV507C_SURFACE_SET_PARAMS_FORMAT_A1R5G5B5;
242 case DRM_FORMAT_XBGR2101010:
243 case DRM_FORMAT_ABGR2101010:
244 asyw->image.format = NV507C_SURFACE_SET_PARAMS_FORMAT_A2B10G10R10;
246 case DRM_FORMAT_XBGR8888:
247 case DRM_FORMAT_ABGR8888:
248 asyw->image.format = NV507C_SURFACE_SET_PARAMS_FORMAT_A8B8G8R8;
250 case DRM_FORMAT_XRGB2101010:
251 case DRM_FORMAT_ARGB2101010:
252 asyw->image.format = NVC37E_SET_PARAMS_FORMAT_A2R10G10B10;
254 case DRM_FORMAT_XBGR16161616F:
255 case DRM_FORMAT_ABGR16161616F:
256 asyw->image.format = NV507C_SURFACE_SET_PARAMS_FORMAT_RF16_GF16_BF16_AF16;
262 asyw->image.colorspace = NV507E_SURFACE_SET_PARAMS_COLOR_SPACE_RGB;
267 nv50_wndw_atomic_check_acquire(struct nv50_wndw *wndw, bool modeset,
268 struct nv50_wndw_atom *armw,
269 struct nv50_wndw_atom *asyw,
270 struct nv50_head_atom *asyh)
272 struct drm_framebuffer *fb = asyw->state.fb;
273 struct nouveau_drm *drm = nouveau_drm(wndw->plane.dev);
278 NV_ATOMIC(drm, "%s acquire\n", wndw->plane.name);
280 if (fb != armw->state.fb || !armw->visible || modeset) {
281 nouveau_framebuffer_get_layout(fb, &tile_mode, &kind);
283 asyw->image.w = fb->width;
284 asyw->image.h = fb->height;
285 asyw->image.kind = kind;
287 ret = nv50_wndw_atomic_check_acquire_rgb(asyw);
289 ret = nv50_wndw_atomic_check_acquire_yuv(asyw);
294 if (asyw->image.kind) {
295 asyw->image.layout = NV507C_SURFACE_SET_STORAGE_MEMORY_LAYOUT_BLOCKLINEAR;
296 if (drm->client.device.info.chipset >= 0xc0)
297 asyw->image.blockh = tile_mode >> 4;
299 asyw->image.blockh = tile_mode;
300 asyw->image.blocks[0] = fb->pitches[0] / 64;
301 asyw->image.pitch[0] = 0;
303 asyw->image.layout = NV507C_SURFACE_SET_STORAGE_MEMORY_LAYOUT_PITCH;
304 asyw->image.blockh = NV507C_SURFACE_SET_STORAGE_BLOCK_HEIGHT_ONE_GOB;
305 asyw->image.blocks[0] = 0;
306 asyw->image.pitch[0] = fb->pitches[0];
309 if (!asyh->state.async_flip)
310 asyw->image.interval = 1;
312 asyw->image.interval = 0;
314 if (asyw->image.interval)
315 asyw->image.mode = NV507C_SET_PRESENT_CONTROL_BEGIN_MODE_NON_TEARING;
317 asyw->image.mode = NV507C_SET_PRESENT_CONTROL_BEGIN_MODE_IMMEDIATE;
319 asyw->set.image = wndw->func->image_set != NULL;
322 if (wndw->func->scale_set) {
323 asyw->scale.sx = asyw->state.src_x >> 16;
324 asyw->scale.sy = asyw->state.src_y >> 16;
325 asyw->scale.sw = asyw->state.src_w >> 16;
326 asyw->scale.sh = asyw->state.src_h >> 16;
327 asyw->scale.dw = asyw->state.crtc_w;
328 asyw->scale.dh = asyw->state.crtc_h;
329 if (memcmp(&armw->scale, &asyw->scale, sizeof(asyw->scale)))
330 asyw->set.scale = true;
333 if (wndw->func->blend_set) {
334 asyw->blend.depth = 255 - asyw->state.normalized_zpos;
335 asyw->blend.k1 = asyw->state.alpha >> 8;
336 switch (asyw->state.pixel_blend_mode) {
337 case DRM_MODE_BLEND_PREMULTI:
338 asyw->blend.src_color = NVC37E_SET_COMPOSITION_FACTOR_SELECT_SRC_COLOR_FACTOR_MATCH_SELECT_K1;
339 asyw->blend.dst_color = NVC37E_SET_COMPOSITION_FACTOR_SELECT_DST_COLOR_FACTOR_MATCH_SELECT_NEG_K1_TIMES_SRC;
341 case DRM_MODE_BLEND_COVERAGE:
342 asyw->blend.src_color = NVC37E_SET_COMPOSITION_FACTOR_SELECT_SRC_COLOR_FACTOR_MATCH_SELECT_K1_TIMES_SRC;
343 asyw->blend.dst_color = NVC37E_SET_COMPOSITION_FACTOR_SELECT_DST_COLOR_FACTOR_MATCH_SELECT_NEG_K1_TIMES_SRC;
345 case DRM_MODE_BLEND_PIXEL_NONE:
347 asyw->blend.src_color = NVC37E_SET_COMPOSITION_FACTOR_SELECT_SRC_COLOR_FACTOR_MATCH_SELECT_K1;
348 asyw->blend.dst_color = NVC37E_SET_COMPOSITION_FACTOR_SELECT_DST_COLOR_FACTOR_MATCH_SELECT_NEG_K1;
351 if (memcmp(&armw->blend, &asyw->blend, sizeof(asyw->blend)))
352 asyw->set.blend = true;
356 asyw->point.x = asyw->state.crtc_x;
357 asyw->point.y = asyw->state.crtc_y;
358 if (memcmp(&armw->point, &asyw->point, sizeof(asyw->point)))
359 asyw->set.point = true;
362 return wndw->func->acquire(wndw, asyw, asyh);
366 nv50_wndw_atomic_check_lut(struct nv50_wndw *wndw,
367 struct nv50_wndw_atom *armw,
368 struct nv50_wndw_atom *asyw,
369 struct nv50_head_atom *asyh)
371 struct drm_property_blob *ilut = asyh->state.degamma_lut;
373 /* I8 format without an input LUT makes no sense, and the
374 * HW error-checks for this.
376 * In order to handle legacy gamma, when there's no input
377 * LUT we need to steal the output LUT and use it instead.
379 if (!ilut && asyw->state.fb->format->format == DRM_FORMAT_C8) {
380 /* This should be an error, but there's legacy clients
381 * that do a modeset before providing a gamma table.
383 * We keep the window disabled to avoid angering HW.
385 if (!(ilut = asyh->state.gamma_lut)) {
386 asyw->visible = false;
390 if (wndw->func->ilut)
391 asyh->wndw.olut |= BIT(wndw->id);
393 asyh->wndw.olut &= ~BIT(wndw->id);
396 if (!ilut && wndw->func->ilut_identity &&
397 asyw->state.fb->format->format != DRM_FORMAT_XBGR16161616F &&
398 asyw->state.fb->format->format != DRM_FORMAT_ABGR16161616F) {
399 static struct drm_property_blob dummy = {};
403 /* Recalculate LUT state. */
404 memset(&asyw->xlut, 0x00, sizeof(asyw->xlut));
405 if ((asyw->ilut = wndw->func->ilut ? ilut : NULL)) {
406 if (!wndw->func->ilut(wndw, asyw, drm_color_lut_size(ilut))) {
407 DRM_DEBUG_KMS("Invalid ilut\n");
410 asyw->xlut.handle = wndw->wndw.vram.handle;
411 asyw->xlut.i.buffer = !asyw->xlut.i.buffer;
412 asyw->set.xlut = true;
414 asyw->clr.xlut = armw->xlut.handle != 0;
417 /* Handle setting base SET_OUTPUT_LUT_LO_ENABLE_USE_CORE_LUT. */
418 if (wndw->func->olut_core &&
419 (!armw->visible || (armw->xlut.handle && !asyw->xlut.handle)))
420 asyw->set.xlut = true;
422 if (wndw->func->csc && asyh->state.ctm) {
423 const struct drm_color_ctm *ctm = asyh->state.ctm->data;
424 wndw->func->csc(wndw, asyw, ctm);
425 asyw->csc.valid = true;
426 asyw->set.csc = true;
428 asyw->csc.valid = false;
429 asyw->clr.csc = armw->csc.valid;
432 /* Can't do an immediate flip while changing the LUT. */
433 asyh->state.async_flip = false;
438 nv50_wndw_atomic_check(struct drm_plane *plane,
439 struct drm_atomic_state *state)
441 struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
443 struct nouveau_drm *drm = nouveau_drm(plane->dev);
444 struct nv50_wndw *wndw = nv50_wndw(plane);
445 struct nv50_wndw_atom *armw = nv50_wndw_atom(wndw->plane.state);
446 struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state);
447 struct nv50_head_atom *harm = NULL, *asyh = NULL;
448 bool modeset = false;
451 NV_ATOMIC(drm, "%s atomic_check\n", plane->name);
453 /* Fetch the assembly state for the head the window will belong to,
454 * and determine whether the window will be visible.
456 if (asyw->state.crtc) {
457 asyh = nv50_head_atom_get(asyw->state.state, asyw->state.crtc);
459 return PTR_ERR(asyh);
460 modeset = drm_atomic_crtc_needs_modeset(&asyh->state);
461 asyw->visible = asyh->state.active;
463 asyw->visible = false;
466 /* Fetch assembly state for the head the window used to belong to. */
467 if (armw->state.crtc) {
468 harm = nv50_head_atom_get(asyw->state.state, armw->state.crtc);
470 return PTR_ERR(harm);
473 /* LUT configuration can potentially cause the window to be disabled. */
474 if (asyw->visible && wndw->func->xlut_set &&
476 asyh->state.color_mgmt_changed ||
477 asyw->state.fb->format->format !=
478 armw->state.fb->format->format)) {
479 ret = nv50_wndw_atomic_check_lut(wndw, armw, asyw, asyh);
484 /* Calculate new window state. */
486 ret = nv50_wndw_atomic_check_acquire(wndw, modeset,
491 asyh->wndw.mask |= BIT(wndw->id);
494 nv50_wndw_atomic_check_release(wndw, asyw, harm);
495 harm->wndw.mask &= ~BIT(wndw->id);
500 /* Aside from the obvious case where the window is actively being
501 * disabled, we might also need to temporarily disable the window
502 * when performing certain modeset operations.
504 if (!asyw->visible || modeset) {
505 asyw->clr.ntfy = armw->ntfy.handle != 0;
506 asyw->clr.sema = armw->sema.handle != 0;
507 asyw->clr.xlut = armw->xlut.handle != 0;
508 if (asyw->clr.xlut && asyw->visible)
509 asyw->set.xlut = asyw->xlut.handle != 0;
510 asyw->clr.csc = armw->csc.valid;
511 if (wndw->func->image_clr)
512 asyw->clr.image = armw->image.handle[0] != 0;
519 nv50_wndw_cleanup_fb(struct drm_plane *plane, struct drm_plane_state *old_state)
521 struct nouveau_drm *drm = nouveau_drm(plane->dev);
522 struct nouveau_bo *nvbo;
524 NV_ATOMIC(drm, "%s cleanup: %p\n", plane->name, old_state->fb);
528 nvbo = nouveau_gem_object(old_state->fb->obj[0]);
529 nouveau_bo_unpin(nvbo);
533 nv50_wndw_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state)
535 struct drm_framebuffer *fb = state->fb;
536 struct nouveau_drm *drm = nouveau_drm(plane->dev);
537 struct nv50_wndw *wndw = nv50_wndw(plane);
538 struct nv50_wndw_atom *asyw = nv50_wndw_atom(state);
539 struct nouveau_bo *nvbo;
540 struct nv50_head_atom *asyh;
541 struct nv50_wndw_ctxdma *ctxdma;
542 struct dma_resv_iter cursor;
543 struct dma_fence *fence;
546 NV_ATOMIC(drm, "%s prepare: %p\n", plane->name, fb);
550 nvbo = nouveau_gem_object(fb->obj[0]);
551 ret = nouveau_bo_pin(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, true);
555 if (wndw->ctxdma.parent) {
556 ctxdma = nv50_wndw_ctxdma_new(wndw, fb);
557 if (IS_ERR(ctxdma)) {
558 nouveau_bo_unpin(nvbo);
559 return PTR_ERR(ctxdma);
563 asyw->image.handle[0] = ctxdma->object.handle;
566 dma_resv_iter_begin(&cursor, nvbo->bo.base.resv, false);
567 dma_resv_for_each_fence_unlocked(&cursor, fence) {
568 /* TODO: We only use the first writer here */
569 asyw->state.fence = dma_fence_get(fence);
572 dma_resv_iter_end(&cursor);
573 asyw->image.offset[0] = nvbo->offset;
575 if (wndw->func->prepare) {
576 asyh = nv50_head_atom_get(asyw->state.state, asyw->state.crtc);
578 return PTR_ERR(asyh);
580 wndw->func->prepare(wndw, asyh, asyw);
586 static const struct drm_plane_helper_funcs
588 .prepare_fb = nv50_wndw_prepare_fb,
589 .cleanup_fb = nv50_wndw_cleanup_fb,
590 .atomic_check = nv50_wndw_atomic_check,
594 nv50_wndw_atomic_destroy_state(struct drm_plane *plane,
595 struct drm_plane_state *state)
597 struct nv50_wndw_atom *asyw = nv50_wndw_atom(state);
598 __drm_atomic_helper_plane_destroy_state(&asyw->state);
602 static struct drm_plane_state *
603 nv50_wndw_atomic_duplicate_state(struct drm_plane *plane)
605 struct nv50_wndw_atom *armw = nv50_wndw_atom(plane->state);
606 struct nv50_wndw_atom *asyw;
607 if (!(asyw = kmalloc(sizeof(*asyw), GFP_KERNEL)))
609 __drm_atomic_helper_plane_duplicate_state(plane, &asyw->state);
610 asyw->sema = armw->sema;
611 asyw->ntfy = armw->ntfy;
613 asyw->xlut = armw->xlut;
614 asyw->csc = armw->csc;
615 asyw->image = armw->image;
616 asyw->point = armw->point;
623 nv50_wndw_zpos_default(struct drm_plane *plane)
625 return (plane->type == DRM_PLANE_TYPE_PRIMARY) ? 0 :
626 (plane->type == DRM_PLANE_TYPE_OVERLAY) ? 1 : 255;
630 nv50_wndw_reset(struct drm_plane *plane)
632 struct nv50_wndw_atom *asyw;
634 if (WARN_ON(!(asyw = kzalloc(sizeof(*asyw), GFP_KERNEL))))
638 plane->funcs->atomic_destroy_state(plane, plane->state);
640 __drm_atomic_helper_plane_reset(plane, &asyw->state);
641 plane->state->zpos = nv50_wndw_zpos_default(plane);
642 plane->state->normalized_zpos = nv50_wndw_zpos_default(plane);
646 nv50_wndw_destroy(struct drm_plane *plane)
648 struct nv50_wndw *wndw = nv50_wndw(plane);
649 struct nv50_wndw_ctxdma *ctxdma, *ctxtmp;
651 list_for_each_entry_safe(ctxdma, ctxtmp, &wndw->ctxdma.list, head) {
652 nv50_wndw_ctxdma_del(ctxdma);
655 nvif_notify_dtor(&wndw->notify);
656 nv50_dmac_destroy(&wndw->wimm);
657 nv50_dmac_destroy(&wndw->wndw);
659 nv50_lut_fini(&wndw->ilut);
661 drm_plane_cleanup(&wndw->plane);
665 /* This function assumes the format has already been validated against the plane
666 * and the modifier was validated against the device-wides modifier list at FB
669 static bool nv50_plane_format_mod_supported(struct drm_plane *plane,
670 u32 format, u64 modifier)
672 struct nouveau_drm *drm = nouveau_drm(plane->dev);
675 if (drm->client.device.info.chipset < 0xc0) {
676 const struct drm_format_info *info = drm_format_info(format);
677 const uint8_t kind = (modifier >> 12) & 0xff;
679 if (!format) return false;
681 for (i = 0; i < info->num_planes; i++)
682 if ((info->cpp[i] != 4) && kind != 0x70) return false;
688 const struct drm_plane_funcs
690 .update_plane = drm_atomic_helper_update_plane,
691 .disable_plane = drm_atomic_helper_disable_plane,
692 .destroy = nv50_wndw_destroy,
693 .reset = nv50_wndw_reset,
694 .atomic_duplicate_state = nv50_wndw_atomic_duplicate_state,
695 .atomic_destroy_state = nv50_wndw_atomic_destroy_state,
696 .format_mod_supported = nv50_plane_format_mod_supported,
700 nv50_wndw_notify(struct nvif_notify *notify)
702 return NVIF_NOTIFY_KEEP;
706 nv50_wndw_fini(struct nv50_wndw *wndw)
708 nvif_notify_put(&wndw->notify);
712 nv50_wndw_init(struct nv50_wndw *wndw)
714 nvif_notify_get(&wndw->notify);
717 static const u64 nv50_cursor_format_modifiers[] = {
718 DRM_FORMAT_MOD_LINEAR,
719 DRM_FORMAT_MOD_INVALID,
723 nv50_wndw_new_(const struct nv50_wndw_func *func, struct drm_device *dev,
724 enum drm_plane_type type, const char *name, int index,
725 const u32 *format, u32 heads,
726 enum nv50_disp_interlock_type interlock_type, u32 interlock_data,
727 struct nv50_wndw **pwndw)
729 struct nouveau_drm *drm = nouveau_drm(dev);
730 struct nvif_mmu *mmu = &drm->client.mmu;
731 struct nv50_disp *disp = nv50_disp(dev);
732 struct nv50_wndw *wndw;
733 const u64 *format_modifiers;
737 if (!(wndw = *pwndw = kzalloc(sizeof(*wndw), GFP_KERNEL)))
741 wndw->interlock.type = interlock_type;
742 wndw->interlock.data = interlock_data;
744 wndw->ctxdma.parent = &wndw->wndw.base.user;
745 INIT_LIST_HEAD(&wndw->ctxdma.list);
747 for (nformat = 0; format[nformat]; nformat++);
749 if (type == DRM_PLANE_TYPE_CURSOR)
750 format_modifiers = nv50_cursor_format_modifiers;
752 format_modifiers = nouveau_display(dev)->format_modifiers;
754 ret = drm_universal_plane_init(dev, &wndw->plane, heads, &nv50_wndw, format, nformat,
755 format_modifiers, type, "%s-%d", name, index);
762 drm_plane_helper_add(&wndw->plane, &nv50_wndw_helper);
764 if (wndw->func->ilut) {
765 ret = nv50_lut_init(disp, mmu, &wndw->ilut);
770 wndw->notify.func = nv50_wndw_notify;
772 if (wndw->func->blend_set) {
773 ret = drm_plane_create_zpos_property(&wndw->plane,
774 nv50_wndw_zpos_default(&wndw->plane), 0, 254);
778 ret = drm_plane_create_alpha_property(&wndw->plane);
782 ret = drm_plane_create_blend_mode_property(&wndw->plane,
783 BIT(DRM_MODE_BLEND_PIXEL_NONE) |
784 BIT(DRM_MODE_BLEND_PREMULTI) |
785 BIT(DRM_MODE_BLEND_COVERAGE));
789 ret = drm_plane_create_zpos_immutable_property(&wndw->plane,
790 nv50_wndw_zpos_default(&wndw->plane));
799 nv50_wndw_new(struct nouveau_drm *drm, enum drm_plane_type type, int index,
800 struct nv50_wndw **pwndw)
805 int (*new)(struct nouveau_drm *, enum drm_plane_type,
806 int, s32, struct nv50_wndw **);
808 { GA102_DISP_WINDOW_CHANNEL_DMA, 0, wndwc67e_new },
809 { TU102_DISP_WINDOW_CHANNEL_DMA, 0, wndwc57e_new },
810 { GV100_DISP_WINDOW_CHANNEL_DMA, 0, wndwc37e_new },
813 struct nv50_disp *disp = nv50_disp(drm->dev);
816 cid = nvif_mclass(&disp->disp->object, wndws);
818 NV_ERROR(drm, "No supported window class\n");
822 ret = wndws[cid].new(drm, type, index, wndws[cid].oclass, pwndw);
826 return nv50_wimm_init(drm, *pwndw);