11590700dSBen Skeggs /* 21590700dSBen Skeggs * Copyright 2018 Red Hat Inc. 31590700dSBen Skeggs * 41590700dSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a 51590700dSBen Skeggs * copy of this software and associated documentation files (the "Software"), 61590700dSBen Skeggs * to deal in the Software without restriction, including without limitation 71590700dSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense, 81590700dSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the 91590700dSBen Skeggs * Software is furnished to do so, subject to the following conditions: 101590700dSBen Skeggs * 111590700dSBen Skeggs * The above copyright notice and this permission notice shall be included in 121590700dSBen Skeggs * all copies or substantial portions of the Software. 131590700dSBen Skeggs * 141590700dSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 151590700dSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 161590700dSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 171590700dSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 181590700dSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 191590700dSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 201590700dSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE. 211590700dSBen Skeggs */ 221590700dSBen Skeggs #include "curs.h" 231590700dSBen Skeggs #include "core.h" 2401d380abSBen Skeggs #include "head.h" 251590700dSBen Skeggs 261590700dSBen Skeggs #include <nvif/cl507a.h> 27374b5580SBen Skeggs #include <nvif/timer.h> 281590700dSBen Skeggs 292a0d40bbSBen Skeggs #include <nvhw/class/cl507a.h> 302a0d40bbSBen Skeggs 311590700dSBen Skeggs #include <drm/drm_atomic_helper.h> 321590700dSBen Skeggs #include <drm/drm_plane_helper.h> 331590700dSBen Skeggs 34374b5580SBen Skeggs bool 35374b5580SBen Skeggs curs507a_space(struct nv50_wndw *wndw) 36374b5580SBen Skeggs { 3718d8cf93SBen Skeggs nvif_msec(&nouveau_drm(wndw->plane.dev)->client.device, 100, 382a0d40bbSBen Skeggs if (NVIF_TV32(&wndw->wimm.base.user, NV507A, FREE, COUNT, >=, 4)) 39374b5580SBen Skeggs return true; 40374b5580SBen Skeggs ); 412a0d40bbSBen Skeggs 42374b5580SBen Skeggs WARN_ON(1); 43374b5580SBen Skeggs return false; 44374b5580SBen Skeggs } 45374b5580SBen Skeggs 469659be21SBen Skeggs static int 4753e0a3e7SBen Skeggs curs507a_update(struct nv50_wndw *wndw, u32 *interlock) 481590700dSBen Skeggs { 499659be21SBen Skeggs int ret = nvif_chan_wait(&wndw->wimm, 1); 509659be21SBen Skeggs if (ret == 0) 511590700dSBen Skeggs nvif_wr32(&wndw->wimm.base.user, 0x0080, 0x00000000); 529659be21SBen Skeggs return ret; 531590700dSBen Skeggs } 541590700dSBen Skeggs 55bea8395cSBen Skeggs static int 561590700dSBen Skeggs curs507a_point(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw) 571590700dSBen Skeggs { 58*93701408SBen Skeggs struct nvif_object *user = &wndw->wimm.base.user; 59bea8395cSBen Skeggs int ret = nvif_chan_wait(&wndw->wimm, 1); 60bea8395cSBen Skeggs if (ret == 0) { 61*93701408SBen Skeggs NVIF_WR32(user, NV507A, SET_CURSOR_HOT_SPOT_POINT_OUT, 62*93701408SBen Skeggs NVVAL(NV507A, SET_CURSOR_HOT_SPOT_POINT_OUT, X, asyw->point.x) | 63*93701408SBen Skeggs NVVAL(NV507A, SET_CURSOR_HOT_SPOT_POINT_OUT, Y, asyw->point.y)); 641590700dSBen Skeggs } 65bea8395cSBen Skeggs return ret; 66374b5580SBen Skeggs } 671590700dSBen Skeggs 6853e0a3e7SBen Skeggs const struct nv50_wimm_func 691590700dSBen Skeggs curs507a = { 701590700dSBen Skeggs .point = curs507a_point, 711590700dSBen Skeggs .update = curs507a_update, 721590700dSBen Skeggs }; 731590700dSBen Skeggs 741590700dSBen Skeggs static void 751590700dSBen Skeggs curs507a_prepare(struct nv50_wndw *wndw, struct nv50_head_atom *asyh, 761590700dSBen Skeggs struct nv50_wndw_atom *asyw) 771590700dSBen Skeggs { 781590700dSBen Skeggs u32 handle = nv50_disp(wndw->plane.dev)->core->chan.vram.handle; 79261fcfa9SBen Skeggs u32 offset = asyw->image.offset[0]; 801590700dSBen Skeggs if (asyh->curs.handle != handle || asyh->curs.offset != offset) { 811590700dSBen Skeggs asyh->curs.handle = handle; 821590700dSBen Skeggs asyh->curs.offset = offset; 831590700dSBen Skeggs asyh->set.curs = asyh->curs.visible; 841590700dSBen Skeggs } 851590700dSBen Skeggs } 861590700dSBen Skeggs 871590700dSBen Skeggs static void 881590700dSBen Skeggs curs507a_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, 891590700dSBen Skeggs struct nv50_head_atom *asyh) 901590700dSBen Skeggs { 911590700dSBen Skeggs asyh->curs.visible = false; 921590700dSBen Skeggs } 931590700dSBen Skeggs 941590700dSBen Skeggs static int 951590700dSBen Skeggs curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw, 961590700dSBen Skeggs struct nv50_head_atom *asyh) 971590700dSBen Skeggs { 9801d380abSBen Skeggs struct nv50_head *head = nv50_head(asyw->state.crtc); 991590700dSBen Skeggs int ret; 1001590700dSBen Skeggs 1011590700dSBen Skeggs ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state, 1021590700dSBen Skeggs DRM_PLANE_HELPER_NO_SCALING, 1031590700dSBen Skeggs DRM_PLANE_HELPER_NO_SCALING, 1041590700dSBen Skeggs true, true); 1051590700dSBen Skeggs asyh->curs.visible = asyw->state.visible; 1061590700dSBen Skeggs if (ret || !asyh->curs.visible) 1071590700dSBen Skeggs return ret; 1081590700dSBen Skeggs 10901d380abSBen Skeggs if (asyw->image.w != asyw->image.h) 1101590700dSBen Skeggs return -EINVAL; 1111590700dSBen Skeggs 11201d380abSBen Skeggs ret = head->func->curs_layout(head, asyw, asyh); 11301d380abSBen Skeggs if (ret) 11401d380abSBen Skeggs return ret; 1151590700dSBen Skeggs 11601d380abSBen Skeggs return head->func->curs_format(head, asyw, asyh); 1171590700dSBen Skeggs } 1181590700dSBen Skeggs 1191590700dSBen Skeggs static const u32 1201590700dSBen Skeggs curs507a_format[] = { 1211590700dSBen Skeggs DRM_FORMAT_ARGB8888, 1221590700dSBen Skeggs 0 1231590700dSBen Skeggs }; 1241590700dSBen Skeggs 1251590700dSBen Skeggs static const struct nv50_wndw_func 1261590700dSBen Skeggs curs507a_wndw = { 1271590700dSBen Skeggs .acquire = curs507a_acquire, 1281590700dSBen Skeggs .release = curs507a_release, 1291590700dSBen Skeggs .prepare = curs507a_prepare, 1301590700dSBen Skeggs }; 1311590700dSBen Skeggs 13253e0a3e7SBen Skeggs int 1331590700dSBen Skeggs curs507a_new_(const struct nv50_wimm_func *func, struct nouveau_drm *drm, 13453e0a3e7SBen Skeggs int head, s32 oclass, u32 interlock_data, 13553e0a3e7SBen Skeggs struct nv50_wndw **pwndw) 1361590700dSBen Skeggs { 1371590700dSBen Skeggs struct nv50_disp_cursor_v0 args = { 1381590700dSBen Skeggs .head = head, 1391590700dSBen Skeggs }; 1401590700dSBen Skeggs struct nv50_disp *disp = nv50_disp(drm->dev); 1411590700dSBen Skeggs struct nv50_wndw *wndw; 1421590700dSBen Skeggs int ret; 1431590700dSBen Skeggs 1441590700dSBen Skeggs ret = nv50_wndw_new_(&curs507a_wndw, drm->dev, DRM_PLANE_TYPE_CURSOR, 14553e0a3e7SBen Skeggs "curs", head, curs507a_format, BIT(head), 14653e0a3e7SBen Skeggs NV50_DISP_INTERLOCK_CURS, interlock_data, &wndw); 1471590700dSBen Skeggs if (*pwndw = wndw, ret) 1481590700dSBen Skeggs return ret; 1491590700dSBen Skeggs 1509ac596a4SBen Skeggs ret = nvif_object_ctor(&disp->disp->object, "kmsCurs", 0, oclass, 1519ac596a4SBen Skeggs &args, sizeof(args), &wndw->wimm.base.user); 1521590700dSBen Skeggs if (ret) { 1531590700dSBen Skeggs NV_ERROR(drm, "curs%04x allocation failed: %d\n", oclass, ret); 1541590700dSBen Skeggs return ret; 1551590700dSBen Skeggs } 1561590700dSBen Skeggs 1571590700dSBen Skeggs nvif_object_map(&wndw->wimm.base.user, NULL, 0); 1581590700dSBen Skeggs wndw->immd = func; 1591264f832SBen Skeggs wndw->ctxdma.parent = NULL; 1601590700dSBen Skeggs return 0; 1611590700dSBen Skeggs } 1621590700dSBen Skeggs 1631590700dSBen Skeggs int 1641590700dSBen Skeggs curs507a_new(struct nouveau_drm *drm, int head, s32 oclass, 1651590700dSBen Skeggs struct nv50_wndw **pwndw) 1661590700dSBen Skeggs { 16753e0a3e7SBen Skeggs return curs507a_new_(&curs507a, drm, head, oclass, 16853e0a3e7SBen Skeggs 0x00000001 << (head * 8), pwndw); 1691590700dSBen Skeggs } 170