blob: 291c08117ab65337f7a9d8567cec08207cd555db [file] [log] [blame]
Ben Skeggs15907002018-05-08 20:39:47 +10001/*
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 "curs.h"
23#include "core.h"
Ben Skeggs01d380a2018-05-08 20:39:47 +100024#include "head.h"
Ben Skeggs15907002018-05-08 20:39:47 +100025
26#include <nvif/cl507a.h>
27
28#include <drm/drm_atomic_helper.h>
29#include <drm/drm_plane_helper.h>
30
Ben Skeggs53e0a3e2018-05-08 20:39:47 +100031static void
32curs507a_update(struct nv50_wndw *wndw, u32 *interlock)
Ben Skeggs15907002018-05-08 20:39:47 +100033{
34 nvif_wr32(&wndw->wimm.base.user, 0x0080, 0x00000000);
Ben Skeggs15907002018-05-08 20:39:47 +100035}
36
37static void
38curs507a_point(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
39{
40 nvif_wr32(&wndw->wimm.base.user, 0x0084, asyw->point.y << 16 |
41 asyw->point.x);
42}
43
Ben Skeggs53e0a3e2018-05-08 20:39:47 +100044const struct nv50_wimm_func
Ben Skeggs15907002018-05-08 20:39:47 +100045curs507a = {
46 .point = curs507a_point,
47 .update = curs507a_update,
48};
49
50static void
51curs507a_prepare(struct nv50_wndw *wndw, struct nv50_head_atom *asyh,
52 struct nv50_wndw_atom *asyw)
53{
54 u32 handle = nv50_disp(wndw->plane.dev)->core->chan.vram.handle;
Ben Skeggs261fcfa2018-05-08 20:39:47 +100055 u32 offset = asyw->image.offset[0];
Ben Skeggs15907002018-05-08 20:39:47 +100056 if (asyh->curs.handle != handle || asyh->curs.offset != offset) {
57 asyh->curs.handle = handle;
58 asyh->curs.offset = offset;
59 asyh->set.curs = asyh->curs.visible;
60 }
61}
62
63static void
64curs507a_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
65 struct nv50_head_atom *asyh)
66{
67 asyh->curs.visible = false;
68}
69
70static int
71curs507a_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
72 struct nv50_head_atom *asyh)
73{
Ben Skeggs01d380a2018-05-08 20:39:47 +100074 struct nv50_head *head = nv50_head(asyw->state.crtc);
Ben Skeggs15907002018-05-08 20:39:47 +100075 int ret;
76
77 ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
78 DRM_PLANE_HELPER_NO_SCALING,
79 DRM_PLANE_HELPER_NO_SCALING,
80 true, true);
81 asyh->curs.visible = asyw->state.visible;
82 if (ret || !asyh->curs.visible)
83 return ret;
84
Ben Skeggs01d380a2018-05-08 20:39:47 +100085 if (asyw->image.w != asyw->image.h)
Ben Skeggs15907002018-05-08 20:39:47 +100086 return -EINVAL;
87
Ben Skeggs01d380a2018-05-08 20:39:47 +100088 ret = head->func->curs_layout(head, asyw, asyh);
89 if (ret)
90 return ret;
Ben Skeggs15907002018-05-08 20:39:47 +100091
Ben Skeggs01d380a2018-05-08 20:39:47 +100092 return head->func->curs_format(head, asyw, asyh);
Ben Skeggs15907002018-05-08 20:39:47 +100093}
94
95static const u32
96curs507a_format[] = {
97 DRM_FORMAT_ARGB8888,
98 0
99};
100
101static const struct nv50_wndw_func
102curs507a_wndw = {
103 .acquire = curs507a_acquire,
104 .release = curs507a_release,
105 .prepare = curs507a_prepare,
106};
107
Ben Skeggs53e0a3e2018-05-08 20:39:47 +1000108int
Ben Skeggs15907002018-05-08 20:39:47 +1000109curs507a_new_(const struct nv50_wimm_func *func, struct nouveau_drm *drm,
Ben Skeggs53e0a3e2018-05-08 20:39:47 +1000110 int head, s32 oclass, u32 interlock_data,
111 struct nv50_wndw **pwndw)
Ben Skeggs15907002018-05-08 20:39:47 +1000112{
113 struct nv50_disp_cursor_v0 args = {
114 .head = head,
115 };
116 struct nv50_disp *disp = nv50_disp(drm->dev);
117 struct nv50_wndw *wndw;
118 int ret;
119
120 ret = nv50_wndw_new_(&curs507a_wndw, drm->dev, DRM_PLANE_TYPE_CURSOR,
Ben Skeggs53e0a3e2018-05-08 20:39:47 +1000121 "curs", head, curs507a_format, BIT(head),
122 NV50_DISP_INTERLOCK_CURS, interlock_data, &wndw);
Ben Skeggs15907002018-05-08 20:39:47 +1000123 if (*pwndw = wndw, ret)
124 return ret;
125
126 ret = nvif_object_init(&disp->disp->object, 0, oclass, &args,
127 sizeof(args), &wndw->wimm.base.user);
128 if (ret) {
129 NV_ERROR(drm, "curs%04x allocation failed: %d\n", oclass, ret);
130 return ret;
131 }
132
133 nvif_object_map(&wndw->wimm.base.user, NULL, 0);
134 wndw->immd = func;
135 wndw->ctxdma.parent = &disp->core->chan.base.user;
136 return 0;
137}
138
139int
140curs507a_new(struct nouveau_drm *drm, int head, s32 oclass,
141 struct nv50_wndw **pwndw)
142{
Ben Skeggs53e0a3e2018-05-08 20:39:47 +1000143 return curs507a_new_(&curs507a, drm, head, oclass,
144 0x00000001 << (head * 8), pwndw);
Ben Skeggs15907002018-05-08 20:39:47 +1000145}