xref: /openbmc/linux/drivers/gpu/drm/nouveau/dispnv50/curs507a.c (revision 9659be21e8034528839216b21794da73fdbedec2)
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 
291590700dSBen Skeggs #include <drm/drm_atomic_helper.h>
301590700dSBen Skeggs #include <drm/drm_plane_helper.h>
311590700dSBen Skeggs 
32374b5580SBen Skeggs bool
33374b5580SBen Skeggs curs507a_space(struct nv50_wndw *wndw)
34374b5580SBen Skeggs {
3518d8cf93SBen Skeggs 	nvif_msec(&nouveau_drm(wndw->plane.dev)->client.device, 100,
36374b5580SBen Skeggs 		if (nvif_rd32(&wndw->wimm.base.user, 0x0008) >= 4)
37374b5580SBen Skeggs 			return true;
38374b5580SBen Skeggs 	);
39374b5580SBen Skeggs 	WARN_ON(1);
40374b5580SBen Skeggs 	return false;
41374b5580SBen Skeggs }
42374b5580SBen Skeggs 
43*9659be21SBen Skeggs static int
4453e0a3e7SBen Skeggs curs507a_update(struct nv50_wndw *wndw, u32 *interlock)
451590700dSBen Skeggs {
46*9659be21SBen Skeggs 	int ret = nvif_chan_wait(&wndw->wimm, 1);
47*9659be21SBen Skeggs 	if (ret == 0)
481590700dSBen Skeggs 		nvif_wr32(&wndw->wimm.base.user, 0x0080, 0x00000000);
49*9659be21SBen Skeggs 	return ret;
501590700dSBen Skeggs }
511590700dSBen Skeggs 
52bea8395cSBen Skeggs static int
531590700dSBen Skeggs curs507a_point(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
541590700dSBen Skeggs {
55bea8395cSBen Skeggs 	int ret = nvif_chan_wait(&wndw->wimm, 1);
56bea8395cSBen Skeggs 	if (ret == 0) {
571590700dSBen Skeggs 		nvif_wr32(&wndw->wimm.base.user, 0x0084, asyw->point.y << 16 |
581590700dSBen Skeggs 							 asyw->point.x);
591590700dSBen Skeggs 	}
60bea8395cSBen Skeggs 	return ret;
61374b5580SBen Skeggs }
621590700dSBen Skeggs 
6353e0a3e7SBen Skeggs const struct nv50_wimm_func
641590700dSBen Skeggs curs507a = {
651590700dSBen Skeggs 	.point = curs507a_point,
661590700dSBen Skeggs 	.update = curs507a_update,
671590700dSBen Skeggs };
681590700dSBen Skeggs 
691590700dSBen Skeggs static void
701590700dSBen Skeggs curs507a_prepare(struct nv50_wndw *wndw, struct nv50_head_atom *asyh,
711590700dSBen Skeggs 		 struct nv50_wndw_atom *asyw)
721590700dSBen Skeggs {
731590700dSBen Skeggs 	u32 handle = nv50_disp(wndw->plane.dev)->core->chan.vram.handle;
74261fcfa9SBen Skeggs 	u32 offset = asyw->image.offset[0];
751590700dSBen Skeggs 	if (asyh->curs.handle != handle || asyh->curs.offset != offset) {
761590700dSBen Skeggs 		asyh->curs.handle = handle;
771590700dSBen Skeggs 		asyh->curs.offset = offset;
781590700dSBen Skeggs 		asyh->set.curs = asyh->curs.visible;
791590700dSBen Skeggs 	}
801590700dSBen Skeggs }
811590700dSBen Skeggs 
821590700dSBen Skeggs static void
831590700dSBen Skeggs curs507a_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
841590700dSBen Skeggs 		 struct nv50_head_atom *asyh)
851590700dSBen Skeggs {
861590700dSBen Skeggs 	asyh->curs.visible = false;
871590700dSBen Skeggs }
881590700dSBen Skeggs 
891590700dSBen Skeggs static int
901590700dSBen Skeggs curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
911590700dSBen Skeggs 		 struct nv50_head_atom *asyh)
921590700dSBen Skeggs {
9301d380abSBen Skeggs 	struct nv50_head *head = nv50_head(asyw->state.crtc);
941590700dSBen Skeggs 	int ret;
951590700dSBen Skeggs 
961590700dSBen Skeggs 	ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
971590700dSBen Skeggs 						  DRM_PLANE_HELPER_NO_SCALING,
981590700dSBen Skeggs 						  DRM_PLANE_HELPER_NO_SCALING,
991590700dSBen Skeggs 						  true, true);
1001590700dSBen Skeggs 	asyh->curs.visible = asyw->state.visible;
1011590700dSBen Skeggs 	if (ret || !asyh->curs.visible)
1021590700dSBen Skeggs 		return ret;
1031590700dSBen Skeggs 
10401d380abSBen Skeggs 	if (asyw->image.w != asyw->image.h)
1051590700dSBen Skeggs 		return -EINVAL;
1061590700dSBen Skeggs 
10701d380abSBen Skeggs 	ret = head->func->curs_layout(head, asyw, asyh);
10801d380abSBen Skeggs 	if (ret)
10901d380abSBen Skeggs 		return ret;
1101590700dSBen Skeggs 
11101d380abSBen Skeggs 	return head->func->curs_format(head, asyw, asyh);
1121590700dSBen Skeggs }
1131590700dSBen Skeggs 
1141590700dSBen Skeggs static const u32
1151590700dSBen Skeggs curs507a_format[] = {
1161590700dSBen Skeggs 	DRM_FORMAT_ARGB8888,
1171590700dSBen Skeggs 	0
1181590700dSBen Skeggs };
1191590700dSBen Skeggs 
1201590700dSBen Skeggs static const struct nv50_wndw_func
1211590700dSBen Skeggs curs507a_wndw = {
1221590700dSBen Skeggs 	.acquire = curs507a_acquire,
1231590700dSBen Skeggs 	.release = curs507a_release,
1241590700dSBen Skeggs 	.prepare = curs507a_prepare,
1251590700dSBen Skeggs };
1261590700dSBen Skeggs 
12753e0a3e7SBen Skeggs int
1281590700dSBen Skeggs curs507a_new_(const struct nv50_wimm_func *func, struct nouveau_drm *drm,
12953e0a3e7SBen Skeggs 	      int head, s32 oclass, u32 interlock_data,
13053e0a3e7SBen Skeggs 	      struct nv50_wndw **pwndw)
1311590700dSBen Skeggs {
1321590700dSBen Skeggs 	struct nv50_disp_cursor_v0 args = {
1331590700dSBen Skeggs 		.head = head,
1341590700dSBen Skeggs 	};
1351590700dSBen Skeggs 	struct nv50_disp *disp = nv50_disp(drm->dev);
1361590700dSBen Skeggs 	struct nv50_wndw *wndw;
1371590700dSBen Skeggs 	int ret;
1381590700dSBen Skeggs 
1391590700dSBen Skeggs 	ret = nv50_wndw_new_(&curs507a_wndw, drm->dev, DRM_PLANE_TYPE_CURSOR,
14053e0a3e7SBen Skeggs 			     "curs", head, curs507a_format, BIT(head),
14153e0a3e7SBen Skeggs 			     NV50_DISP_INTERLOCK_CURS, interlock_data, &wndw);
1421590700dSBen Skeggs 	if (*pwndw = wndw, ret)
1431590700dSBen Skeggs 		return ret;
1441590700dSBen Skeggs 
1459ac596a4SBen Skeggs 	ret = nvif_object_ctor(&disp->disp->object, "kmsCurs", 0, oclass,
1469ac596a4SBen Skeggs 			       &args, sizeof(args), &wndw->wimm.base.user);
1471590700dSBen Skeggs 	if (ret) {
1481590700dSBen Skeggs 		NV_ERROR(drm, "curs%04x allocation failed: %d\n", oclass, ret);
1491590700dSBen Skeggs 		return ret;
1501590700dSBen Skeggs 	}
1511590700dSBen Skeggs 
1521590700dSBen Skeggs 	nvif_object_map(&wndw->wimm.base.user, NULL, 0);
1531590700dSBen Skeggs 	wndw->immd = func;
1541264f832SBen Skeggs 	wndw->ctxdma.parent = NULL;
1551590700dSBen Skeggs 	return 0;
1561590700dSBen Skeggs }
1571590700dSBen Skeggs 
1581590700dSBen Skeggs int
1591590700dSBen Skeggs curs507a_new(struct nouveau_drm *drm, int head, s32 oclass,
1601590700dSBen Skeggs 	     struct nv50_wndw **pwndw)
1611590700dSBen Skeggs {
16253e0a3e7SBen Skeggs 	return curs507a_new_(&curs507a, drm, head, oclass,
16353e0a3e7SBen Skeggs 			     0x00000001 << (head * 8), pwndw);
1641590700dSBen Skeggs }
165