1 /* 2 * Copyright 2018 Red Hat Inc. 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 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. 21 */ 22 #include "ovly.h" 23 #include "atom.h" 24 25 #include <drm/drm_atomic_helper.h> 26 #include <drm/drm_fourcc.h> 27 #include <drm/drm_plane_helper.h> 28 29 #include <nvif/if0014.h> 30 #include <nvif/push507c.h> 31 32 #include <nvhw/class/cl507e.h> 33 34 int 35 ovly507e_scale_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 36 { 37 struct nvif_push *push = wndw->wndw.push; 38 int ret; 39 40 if ((ret = PUSH_WAIT(push, 4))) 41 return ret; 42 43 PUSH_MTHD(push, NV507E, SET_POINT_IN, 44 NVVAL(NV507E, SET_POINT_IN, X, asyw->scale.sx) | 45 NVVAL(NV507E, SET_POINT_IN, Y, asyw->scale.sy), 46 47 SET_SIZE_IN, 48 NVVAL(NV507E, SET_SIZE_IN, WIDTH, asyw->scale.sw) | 49 NVVAL(NV507E, SET_SIZE_IN, HEIGHT, asyw->scale.sh), 50 51 SET_SIZE_OUT, 52 NVVAL(NV507E, SET_SIZE_OUT, WIDTH, asyw->scale.dw)); 53 return 0; 54 } 55 56 static int 57 ovly507e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 58 { 59 struct nvif_push *push = wndw->wndw.push; 60 int ret; 61 62 if ((ret = PUSH_WAIT(push, 12))) 63 return ret; 64 65 PUSH_MTHD(push, NV507E, SET_PRESENT_CONTROL, 66 NVDEF(NV507E, SET_PRESENT_CONTROL, BEGIN_MODE, ASAP) | 67 NVVAL(NV507E, SET_PRESENT_CONTROL, MIN_PRESENT_INTERVAL, asyw->image.interval)); 68 69 PUSH_MTHD(push, NV507E, SET_CONTEXT_DMA_ISO, asyw->image.handle[0]); 70 71 PUSH_MTHD(push, NV507E, SET_COMPOSITION_CONTROL, 72 NVDEF(NV507E, SET_COMPOSITION_CONTROL, MODE, OPAQUE_SUSPEND_BASE)); 73 74 PUSH_MTHD(push, NV507E, SURFACE_SET_OFFSET, asyw->image.offset[0] >> 8); 75 76 PUSH_MTHD(push, NV507E, SURFACE_SET_SIZE, 77 NVVAL(NV507E, SURFACE_SET_SIZE, WIDTH, asyw->image.w) | 78 NVVAL(NV507E, SURFACE_SET_SIZE, HEIGHT, asyw->image.h), 79 80 SURFACE_SET_STORAGE, 81 NVVAL(NV507E, SURFACE_SET_STORAGE, BLOCK_HEIGHT, asyw->image.blockh) | 82 NVVAL(NV507E, SURFACE_SET_STORAGE, PITCH, (asyw->image.pitch[0] >> 8)) | 83 NVVAL(NV507E, SURFACE_SET_STORAGE, PITCH, asyw->image.blocks[0]) | 84 NVVAL(NV507E, SURFACE_SET_STORAGE, MEMORY_LAYOUT, asyw->image.layout), 85 86 SURFACE_SET_PARAMS, 87 NVVAL(NV507E, SURFACE_SET_PARAMS, FORMAT, asyw->image.format) | 88 NVVAL(NV507E, SURFACE_SET_PARAMS, COLOR_SPACE, asyw->image.colorspace) | 89 NVVAL(NV507E, SURFACE_SET_PARAMS, KIND, asyw->image.kind) | 90 NVDEF(NV507E, SURFACE_SET_PARAMS, PART_STRIDE, PARTSTRIDE_256)); 91 return 0; 92 } 93 94 void 95 ovly507e_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, 96 struct nv50_head_atom *asyh) 97 { 98 asyh->ovly.cpp = 0; 99 } 100 101 int 102 ovly507e_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, 103 struct nv50_head_atom *asyh) 104 { 105 const struct drm_framebuffer *fb = asyw->state.fb; 106 int ret; 107 108 ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state, 109 DRM_PLANE_HELPER_NO_SCALING, 110 DRM_PLANE_HELPER_NO_SCALING, 111 true, true); 112 if (ret) 113 return ret; 114 115 asyh->ovly.cpp = fb->format->cpp[0]; 116 return 0; 117 } 118 119 #include "nouveau_bo.h" 120 121 static const struct nv50_wndw_func 122 ovly507e = { 123 .acquire = ovly507e_acquire, 124 .release = ovly507e_release, 125 .ntfy_set = base507c_ntfy_set, 126 .ntfy_clr = base507c_ntfy_clr, 127 .ntfy_reset = base507c_ntfy_reset, 128 .ntfy_wait_begun = base507c_ntfy_wait_begun, 129 .image_set = ovly507e_image_set, 130 .image_clr = base507c_image_clr, 131 .scale_set = ovly507e_scale_set, 132 .update = base507c_update, 133 }; 134 135 static const u32 136 ovly507e_format[] = { 137 DRM_FORMAT_YUYV, 138 DRM_FORMAT_UYVY, 139 DRM_FORMAT_XRGB8888, 140 DRM_FORMAT_XRGB1555, 141 0 142 }; 143 144 int 145 ovly507e_new_(const struct nv50_wndw_func *func, const u32 *format, 146 struct nouveau_drm *drm, int head, s32 oclass, u32 interlock_data, 147 struct nv50_wndw **pwndw) 148 { 149 struct nvif_disp_chan_v0 args = { 150 .id = head, 151 }; 152 struct nv50_disp *disp = nv50_disp(drm->dev); 153 struct nv50_wndw *wndw; 154 int ret; 155 156 ret = nv50_wndw_new_(func, drm->dev, DRM_PLANE_TYPE_OVERLAY, 157 "ovly", head, format, BIT(head), 158 NV50_DISP_INTERLOCK_OVLY, interlock_data, 159 &wndw); 160 if (*pwndw = wndw, ret) 161 return ret; 162 163 ret = nv50_dmac_create(&drm->client.device, &disp->disp->object, 164 &oclass, 0, &args, sizeof(args), 165 disp->sync->offset, &wndw->wndw); 166 if (ret) { 167 NV_ERROR(drm, "ovly%04x allocation failed: %d\n", oclass, ret); 168 return ret; 169 } 170 171 wndw->ntfy = NV50_DISP_OVLY_NTFY(wndw->id); 172 wndw->sema = NV50_DISP_OVLY_SEM0(wndw->id); 173 wndw->data = 0x00000000; 174 return 0; 175 } 176 177 int 178 ovly507e_new(struct nouveau_drm *drm, int head, s32 oclass, 179 struct nv50_wndw **pwndw) 180 { 181 return ovly507e_new_(&ovly507e, ovly507e_format, drm, head, oclass, 182 0x00000004 << (head * 8), pwndw); 183 } 184