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