153e0a3e7SBen Skeggs /*
253e0a3e7SBen Skeggs * Copyright 2018 Red Hat Inc.
353e0a3e7SBen Skeggs *
453e0a3e7SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
553e0a3e7SBen Skeggs * copy of this software and associated documentation files (the "Software"),
653e0a3e7SBen Skeggs * to deal in the Software without restriction, including without limitation
753e0a3e7SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
853e0a3e7SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
953e0a3e7SBen Skeggs * Software is furnished to do so, subject to the following conditions:
1053e0a3e7SBen Skeggs *
1153e0a3e7SBen Skeggs * The above copyright notice and this permission notice shall be included in
1253e0a3e7SBen Skeggs * all copies or substantial portions of the Software.
1353e0a3e7SBen Skeggs *
1453e0a3e7SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1553e0a3e7SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1653e0a3e7SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1753e0a3e7SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1853e0a3e7SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1953e0a3e7SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2053e0a3e7SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
2153e0a3e7SBen Skeggs */
2253e0a3e7SBen Skeggs #include "ovly.h"
232ce7f386SBen Skeggs #include "atom.h"
2453e0a3e7SBen Skeggs
2553e0a3e7SBen Skeggs #include <nouveau_bo.h>
2653e0a3e7SBen Skeggs
276d6e11e2SBen Skeggs #include <nvif/push507c.h>
28ed3d1489SBen Skeggs #include <nvif/timer.h>
29ed3d1489SBen Skeggs
300ecaefc1SBen Skeggs #include <nvhw/class/cl827e.h>
310ecaefc1SBen Skeggs
326d6e11e2SBen Skeggs static int
ovly827e_image_set(struct nv50_wndw * wndw,struct nv50_wndw_atom * asyw)332ce7f386SBen Skeggs ovly827e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
342ce7f386SBen Skeggs {
356d6e11e2SBen Skeggs struct nvif_push *push = wndw->wndw.push;
366d6e11e2SBen Skeggs int ret;
376d6e11e2SBen Skeggs
386d6e11e2SBen Skeggs if ((ret = PUSH_WAIT(push, 12)))
396d6e11e2SBen Skeggs return ret;
406d6e11e2SBen Skeggs
41*f844eb48SBen Skeggs PUSH_MTHD(push, NV827E, SET_PRESENT_CONTROL,
42*f844eb48SBen Skeggs NVDEF(NV827E, SET_PRESENT_CONTROL, BEGIN_MODE, ASAP) |
43*f844eb48SBen Skeggs NVVAL(NV827E, SET_PRESENT_CONTROL, MIN_PRESENT_INTERVAL, asyw->image.interval));
44*f844eb48SBen Skeggs
45*f844eb48SBen Skeggs PUSH_MTHD(push, NV827E, SET_CONTEXT_DMA_ISO, asyw->image.handle[0]);
46*f844eb48SBen Skeggs
47*f844eb48SBen Skeggs PUSH_MTHD(push, NV827E, SET_COMPOSITION_CONTROL,
48*f844eb48SBen Skeggs NVDEF(NV827E, SET_COMPOSITION_CONTROL, MODE, OPAQUE_SUSPEND_BASE));
49*f844eb48SBen Skeggs
50*f844eb48SBen Skeggs PUSH_MTHD(push, NV827E, SURFACE_SET_OFFSET, asyw->image.offset[0] >> 8);
51*f844eb48SBen Skeggs
52*f844eb48SBen Skeggs PUSH_MTHD(push, NV827E, SURFACE_SET_SIZE,
53*f844eb48SBen Skeggs NVVAL(NV827E, SURFACE_SET_SIZE, WIDTH, asyw->image.w) |
54*f844eb48SBen Skeggs NVVAL(NV827E, SURFACE_SET_SIZE, HEIGHT, asyw->image.h),
55*f844eb48SBen Skeggs
56*f844eb48SBen Skeggs SURFACE_SET_STORAGE,
57*f844eb48SBen Skeggs NVVAL(NV827E, SURFACE_SET_STORAGE, BLOCK_HEIGHT, asyw->image.blockh) |
58*f844eb48SBen Skeggs NVVAL(NV827E, SURFACE_SET_STORAGE, PITCH, (asyw->image.pitch[0] >> 8)) |
59*f844eb48SBen Skeggs NVVAL(NV827E, SURFACE_SET_STORAGE, PITCH, asyw->image.blocks[0]) |
60*f844eb48SBen Skeggs NVVAL(NV827E, SURFACE_SET_STORAGE, MEMORY_LAYOUT, asyw->image.layout),
61*f844eb48SBen Skeggs
62*f844eb48SBen Skeggs SURFACE_SET_PARAMS,
63*f844eb48SBen Skeggs NVVAL(NV827E, SURFACE_SET_PARAMS, FORMAT, asyw->image.format) |
64*f844eb48SBen Skeggs NVVAL(NV827E, SURFACE_SET_PARAMS, COLOR_SPACE, asyw->image.colorspace));
656d6e11e2SBen Skeggs return 0;
662ce7f386SBen Skeggs }
672ce7f386SBen Skeggs
682ce7f386SBen Skeggs int
ovly827e_ntfy_wait_begun(struct nouveau_bo * bo,u32 offset,struct nvif_device * device)692ce7f386SBen Skeggs ovly827e_ntfy_wait_begun(struct nouveau_bo *bo, u32 offset,
702ce7f386SBen Skeggs struct nvif_device *device)
712ce7f386SBen Skeggs {
722ce7f386SBen Skeggs s64 time = nvif_msec(device, 2000ULL,
7375bd8304SBen Skeggs if (NVBO_TD32(bo, offset, NV_DISP_NOTIFICATION_1, _3, STATUS, ==, BEGUN))
742ce7f386SBen Skeggs break;
752ce7f386SBen Skeggs usleep_range(1, 2);
762ce7f386SBen Skeggs );
772ce7f386SBen Skeggs return time < 0 ? time : 0;
782ce7f386SBen Skeggs }
792ce7f386SBen Skeggs
802ce7f386SBen Skeggs void
ovly827e_ntfy_reset(struct nouveau_bo * bo,u32 offset)812ce7f386SBen Skeggs ovly827e_ntfy_reset(struct nouveau_bo *bo, u32 offset)
822ce7f386SBen Skeggs {
830ecaefc1SBen Skeggs NVBO_WR32(bo, offset, NV_DISP_NOTIFICATION_1, TIME_STAMP_0, 0);
840ecaefc1SBen Skeggs NVBO_WR32(bo, offset, NV_DISP_NOTIFICATION_1, TIME_STAMP_1, 0);
850ecaefc1SBen Skeggs NVBO_WR32(bo, offset, NV_DISP_NOTIFICATION_1, _2, 0);
860ecaefc1SBen Skeggs NVBO_WR32(bo, offset, NV_DISP_NOTIFICATION_1, _3,
870ecaefc1SBen Skeggs NVDEF(NV_DISP_NOTIFICATION_1, _3, STATUS, NOT_BEGUN));
882ce7f386SBen Skeggs }
8953e0a3e7SBen Skeggs
9053e0a3e7SBen Skeggs static const struct nv50_wndw_func
9153e0a3e7SBen Skeggs ovly827e = {
922ce7f386SBen Skeggs .acquire = ovly507e_acquire,
932ce7f386SBen Skeggs .release = ovly507e_release,
94fe8a2eecSBen Skeggs .ntfy_set = base507c_ntfy_set,
95bcae99c2SBen Skeggs .ntfy_clr = base507c_ntfy_clr,
962ce7f386SBen Skeggs .ntfy_reset = ovly827e_ntfy_reset,
972ce7f386SBen Skeggs .ntfy_wait_begun = ovly827e_ntfy_wait_begun,
982ce7f386SBen Skeggs .image_set = ovly827e_image_set,
998944d8b3SBen Skeggs .image_clr = base507c_image_clr,
1002ce7f386SBen Skeggs .scale_set = ovly507e_scale_set,
1013afb4db7SBen Skeggs .update = base507c_update,
10253e0a3e7SBen Skeggs };
10353e0a3e7SBen Skeggs
10453e0a3e7SBen Skeggs const u32
10553e0a3e7SBen Skeggs ovly827e_format[] = {
1062ce7f386SBen Skeggs DRM_FORMAT_YUYV,
1072ce7f386SBen Skeggs DRM_FORMAT_UYVY,
1082ce7f386SBen Skeggs DRM_FORMAT_XRGB8888,
1092ce7f386SBen Skeggs DRM_FORMAT_XRGB1555,
1102ce7f386SBen Skeggs DRM_FORMAT_XBGR2101010,
11153e0a3e7SBen Skeggs 0
11253e0a3e7SBen Skeggs };
11353e0a3e7SBen Skeggs
11453e0a3e7SBen Skeggs int
ovly827e_new(struct nouveau_drm * drm,int head,s32 oclass,struct nv50_wndw ** pwndw)11553e0a3e7SBen Skeggs ovly827e_new(struct nouveau_drm *drm, int head, s32 oclass,
11653e0a3e7SBen Skeggs struct nv50_wndw **pwndw)
11753e0a3e7SBen Skeggs {
11853e0a3e7SBen Skeggs return ovly507e_new_(&ovly827e, ovly827e_format, drm, head, oclass,
11953e0a3e7SBen Skeggs 0x00000004 << (head * 8), pwndw);
12053e0a3e7SBen Skeggs }
121