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_plane_helper.h> 27 28 #include <nvif/cl507e.h> 29 #include <nvif/event.h> 30 31 void 32 ovly507e_update(struct nv50_wndw *wndw, u32 *interlock) 33 { 34 u32 *push; 35 if ((push = evo_wait(&wndw->wndw, 2))) { 36 evo_mthd(push, 0x0080, 1); 37 evo_data(push, interlock[NV50_DISP_INTERLOCK_CORE]); 38 evo_kick(push, &wndw->wndw); 39 } 40 } 41 42 void 43 ovly507e_scale_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 44 { 45 u32 *push; 46 if ((push = evo_wait(&wndw->wndw, 4))) { 47 evo_mthd(push, 0x00e0, 3); 48 evo_data(push, asyw->scale.sy << 16 | asyw->scale.sx); 49 evo_data(push, asyw->scale.sh << 16 | asyw->scale.sw); 50 evo_data(push, asyw->scale.dw); 51 evo_kick(push, &wndw->wndw); 52 } 53 } 54 55 void 56 ovly507e_image_clr(struct nv50_wndw *wndw) 57 { 58 u32 *push; 59 if ((push = evo_wait(&wndw->wndw, 4))) { 60 evo_mthd(push, 0x0084, 1); 61 evo_data(push, 0x00000000); 62 evo_mthd(push, 0x00c0, 1); 63 evo_data(push, 0x00000000); 64 evo_kick(push, &wndw->wndw); 65 } 66 } 67 68 static void 69 ovly507e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 70 { 71 u32 *push; 72 if ((push = evo_wait(&wndw->wndw, 12))) { 73 evo_mthd(push, 0x0084, 1); 74 evo_data(push, asyw->image.interval << 4); 75 evo_mthd(push, 0x00c0, 1); 76 evo_data(push, asyw->image.handle[0]); 77 evo_mthd(push, 0x0100, 1); 78 evo_data(push, 0x00000002); 79 evo_mthd(push, 0x0800, 1); 80 evo_data(push, asyw->image.offset[0] >> 8); 81 evo_mthd(push, 0x0808, 3); 82 evo_data(push, asyw->image.h << 16 | asyw->image.w); 83 evo_data(push, asyw->image.layout << 20 | 84 (asyw->image.pitch[0] >> 8) << 8 | 85 asyw->image.blocks[0] << 8 | 86 asyw->image.blockh); 87 evo_data(push, asyw->image.kind << 16 | 88 asyw->image.format << 8 | 89 asyw->image.colorspace); 90 evo_kick(push, &wndw->wndw); 91 } 92 } 93 94 void 95 ovly507e_ntfy_clr(struct nv50_wndw *wndw) 96 { 97 u32 *push; 98 if ((push = evo_wait(&wndw->wndw, 2))) { 99 evo_mthd(push, 0x00a4, 1); 100 evo_data(push, 0x00000000); 101 evo_kick(push, &wndw->wndw); 102 } 103 } 104 105 void 106 ovly507e_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 107 { 108 u32 *push; 109 if ((push = evo_wait(&wndw->wndw, 3))) { 110 evo_mthd(push, 0x00a0, 2); 111 evo_data(push, asyw->ntfy.awaken << 30 | asyw->ntfy.offset); 112 evo_data(push, asyw->ntfy.handle); 113 evo_kick(push, &wndw->wndw); 114 } 115 } 116 117 void 118 ovly507e_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, 119 struct nv50_head_atom *asyh) 120 { 121 asyh->ovly.cpp = 0; 122 } 123 124 int 125 ovly507e_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, 126 struct nv50_head_atom *asyh) 127 { 128 const struct drm_framebuffer *fb = asyw->state.fb; 129 int ret; 130 131 ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state, 132 DRM_PLANE_HELPER_NO_SCALING, 133 DRM_PLANE_HELPER_NO_SCALING, 134 true, true); 135 if (ret) 136 return ret; 137 138 asyh->ovly.cpp = fb->format->cpp[0]; 139 return 0; 140 } 141 142 #include "nouveau_bo.h" 143 144 static const struct nv50_wndw_func 145 ovly507e = { 146 .acquire = ovly507e_acquire, 147 .release = ovly507e_release, 148 .ntfy_set = ovly507e_ntfy_set, 149 .ntfy_clr = ovly507e_ntfy_clr, 150 .ntfy_reset = base507c_ntfy_reset, 151 .ntfy_wait_begun = base507c_ntfy_wait_begun, 152 .image_set = ovly507e_image_set, 153 .image_clr = ovly507e_image_clr, 154 .scale_set = ovly507e_scale_set, 155 .update = ovly507e_update, 156 }; 157 158 static const u32 159 ovly507e_format[] = { 160 DRM_FORMAT_YUYV, 161 DRM_FORMAT_UYVY, 162 DRM_FORMAT_XRGB8888, 163 DRM_FORMAT_ARGB8888, 164 DRM_FORMAT_XRGB1555, 165 DRM_FORMAT_ARGB1555, 166 0 167 }; 168 169 int 170 ovly507e_new_(const struct nv50_wndw_func *func, const u32 *format, 171 struct nouveau_drm *drm, int head, s32 oclass, u32 interlock_data, 172 struct nv50_wndw **pwndw) 173 { 174 struct nv50_disp_overlay_channel_dma_v0 args = { 175 .head = head, 176 }; 177 struct nv50_disp *disp = nv50_disp(drm->dev); 178 struct nv50_wndw *wndw; 179 int ret; 180 181 ret = nv50_wndw_new_(func, drm->dev, DRM_PLANE_TYPE_OVERLAY, 182 "ovly", head, format, BIT(head), 183 NV50_DISP_INTERLOCK_OVLY, interlock_data, 184 &wndw); 185 if (*pwndw = wndw, ret) 186 return ret; 187 188 ret = nv50_dmac_create(&drm->client.device, &disp->disp->object, 189 &oclass, 0, &args, sizeof(args), 190 disp->sync->bo.offset, &wndw->wndw); 191 if (ret) { 192 NV_ERROR(drm, "ovly%04x allocation failed: %d\n", oclass, ret); 193 return ret; 194 } 195 196 ret = nvif_notify_init(&wndw->wndw.base.user, wndw->notify.func, false, 197 NV50_DISP_OVERLAY_CHANNEL_DMA_V0_NTFY_UEVENT, 198 &(struct nvif_notify_uevent_req) {}, 199 sizeof(struct nvif_notify_uevent_req), 200 sizeof(struct nvif_notify_uevent_rep), 201 &wndw->notify); 202 if (ret) 203 return ret; 204 205 wndw->ntfy = NV50_DISP_OVLY_NTFY(wndw->id); 206 wndw->sema = NV50_DISP_OVLY_SEM0(wndw->id); 207 wndw->data = 0x00000000; 208 return 0; 209 } 210 211 int 212 ovly507e_new(struct nouveau_drm *drm, int head, s32 oclass, 213 struct nv50_wndw **pwndw) 214 { 215 return ovly507e_new_(&ovly507e, ovly507e_format, drm, head, oclass, 216 0x00000004 << (head * 8), pwndw); 217 } 218