drm/nouveau/kms/nv50-: convert core wndw_owner() to new push macros
[linux-2.6-microblaze.git] / drivers / gpu / drm / nouveau / dispnv50 / corec37d.c
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 "core.h"
23 #include "head.h"
24
25 #include <nvif/class.h>
26 #include <nvif/pushc37b.h>
27 #include <nvif/timer.h>
28
29 #include <nouveau_bo.h>
30
31 int
32 corec37d_wndw_owner(struct nv50_core *core)
33 {
34         struct nvif_push *push = core->chan.push;
35         const u32 windows = 8; /*XXX*/
36         int ret, i;
37
38         if ((ret = PUSH_WAIT(push, windows * 2)))
39                 return ret;
40
41         for (i = 0; i < windows; i++)
42                 PUSH_NVSQ(push, NVC37D, 0x1000 + (i * 0x080), i >> 1);
43
44         return 0;
45 }
46
47 int
48 corec37d_update(struct nv50_core *core, u32 *interlock, bool ntfy)
49 {
50         struct nvif_push *push = core->chan.push;
51         int ret;
52
53         if ((ret = PUSH_WAIT(push, 9)))
54                 return ret;
55
56         if (ntfy)
57                 PUSH_NVSQ(push, NVC37D, 0x020c, 0x00001000 | NV50_DISP_CORE_NTFY);
58
59         PUSH_NVSQ(push, NVC37D, 0x0218, interlock[NV50_DISP_INTERLOCK_CURS],
60                                 0x021c, interlock[NV50_DISP_INTERLOCK_WNDW]);
61         PUSH_NVSQ(push, NVC37D, 0x0200, 0x00000001);
62
63         if (ntfy)
64                 PUSH_NVSQ(push, NVC37D, 0x020c, 0x00000000);
65
66         return PUSH_KICK(push);
67 }
68
69 int
70 corec37d_ntfy_wait_done(struct nouveau_bo *bo, u32 offset,
71                         struct nvif_device *device)
72 {
73         u32 data;
74         s64 time = nvif_msec(device, 2000ULL,
75                 data = nouveau_bo_rd32(bo, offset / 4 + 0);
76                 if ((data & 0xc0000000) == 0x80000000)
77                         break;
78                 usleep_range(1, 2);
79         );
80         return time < 0 ? time : 0;
81 }
82
83 void
84 corec37d_ntfy_init(struct nouveau_bo *bo, u32 offset)
85 {
86         nouveau_bo_wr32(bo, offset / 4 + 0, 0x00000000);
87         nouveau_bo_wr32(bo, offset / 4 + 1, 0x00000000);
88         nouveau_bo_wr32(bo, offset / 4 + 2, 0x00000000);
89         nouveau_bo_wr32(bo, offset / 4 + 3, 0x00000000);
90 }
91
92 int corec37d_caps_init(struct nouveau_drm *drm, struct nv50_disp *disp)
93 {
94         int ret;
95
96         ret = nvif_object_ctor(&disp->disp->object, "dispCaps", 0,
97                                GV100_DISP_CAPS, NULL, 0, &disp->caps);
98         if (ret) {
99                 NV_ERROR(drm,
100                          "Failed to init notifier caps region: %d\n",
101                          ret);
102                 return ret;
103         }
104
105         ret = nvif_object_map(&disp->caps, NULL, 0);
106         if (ret) {
107                 NV_ERROR(drm,
108                          "Failed to map notifier caps region: %d\n",
109                          ret);
110                 return ret;
111         }
112
113         return 0;
114 }
115
116 static int
117 corec37d_init(struct nv50_core *core)
118 {
119         struct nvif_push *push = core->chan.push;
120         const u32 windows = 8; /*XXX*/
121         int ret, i;
122
123         if ((ret = PUSH_WAIT(push, 2 + windows * 5)))
124                 return ret;
125
126         PUSH_NVSQ(push, NVC37D, 0x0208, core->chan.sync.handle);
127
128         for (i = 0; i < windows; i++) {
129                 PUSH_NVSQ(push, NVC37D, 0x1004 + (i * 0x080), 0x0000001f,
130                                         0x1008 + (i * 0x080), 0x00000000);
131                 PUSH_NVSQ(push, NVC37D, 0x1010 + (i * 0x080), 0x00127fff);
132         }
133
134         core->assign_windows = true;
135         return PUSH_KICK(push);
136 }
137
138 static const struct nv50_core_func
139 corec37d = {
140         .init = corec37d_init,
141         .ntfy_init = corec37d_ntfy_init,
142         .caps_init = corec37d_caps_init,
143         .ntfy_wait_done = corec37d_ntfy_wait_done,
144         .update = corec37d_update,
145         .wndw.owner = corec37d_wndw_owner,
146         .head = &headc37d,
147         .sor = &sorc37d,
148 #if IS_ENABLED(CONFIG_DEBUG_FS)
149         .crc = &crcc37d,
150 #endif
151 };
152
153 int
154 corec37d_new(struct nouveau_drm *drm, s32 oclass, struct nv50_core **pcore)
155 {
156         return core507d_new_(&corec37d, drm, oclass, pcore);
157 }