18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2018 Red Hat Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
128c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
178c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci#include "wimm.h"
238c2ecf20Sopenharmony_ci#include "atom.h"
248c2ecf20Sopenharmony_ci#include "wndw.h"
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include <nvif/clc37b.h>
278c2ecf20Sopenharmony_ci#include <nvif/pushc37b.h>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include <nvhw/class/clc37b.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic int
328c2ecf20Sopenharmony_ciwimmc37b_update(struct nv50_wndw *wndw, u32 *interlock)
338c2ecf20Sopenharmony_ci{
348c2ecf20Sopenharmony_ci	struct nvif_push *push = wndw->wimm.push;
358c2ecf20Sopenharmony_ci	int ret;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 2)))
388c2ecf20Sopenharmony_ci		return ret;
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	PUSH_MTHD(push, NVC37B, UPDATE, 0x00000001 |
418c2ecf20Sopenharmony_ci		  NVVAL(NVC37B, UPDATE, INTERLOCK_WITH_WINDOW,
428c2ecf20Sopenharmony_ci			!!(interlock[NV50_DISP_INTERLOCK_WNDW] & wndw->interlock.data)));
438c2ecf20Sopenharmony_ci	return PUSH_KICK(push);
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic int
478c2ecf20Sopenharmony_ciwimmc37b_point(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	struct nvif_push *push = wndw->wimm.push;
508c2ecf20Sopenharmony_ci	int ret;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 2)))
538c2ecf20Sopenharmony_ci		return ret;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	PUSH_MTHD(push, NVC37B, SET_POINT_OUT(0),
568c2ecf20Sopenharmony_ci		  NVVAL(NVC37B, SET_POINT_OUT, X, asyw->point.x) |
578c2ecf20Sopenharmony_ci		  NVVAL(NVC37B, SET_POINT_OUT, Y, asyw->point.y));
588c2ecf20Sopenharmony_ci	return 0;
598c2ecf20Sopenharmony_ci}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_cistatic const struct nv50_wimm_func
628c2ecf20Sopenharmony_ciwimmc37b = {
638c2ecf20Sopenharmony_ci	.point = wimmc37b_point,
648c2ecf20Sopenharmony_ci	.update = wimmc37b_update,
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic int
688c2ecf20Sopenharmony_ciwimmc37b_init_(const struct nv50_wimm_func *func, struct nouveau_drm *drm,
698c2ecf20Sopenharmony_ci	       s32 oclass, struct nv50_wndw *wndw)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	struct nvc37b_window_imm_channel_dma_v0 args = {
728c2ecf20Sopenharmony_ci		.pushbuf = 0xb0007b00 | wndw->id,
738c2ecf20Sopenharmony_ci		.index = wndw->id,
748c2ecf20Sopenharmony_ci	};
758c2ecf20Sopenharmony_ci	struct nv50_disp *disp = nv50_disp(drm->dev);
768c2ecf20Sopenharmony_ci	int ret;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
798c2ecf20Sopenharmony_ci			       &oclass, 0, &args, sizeof(args), -1,
808c2ecf20Sopenharmony_ci			       &wndw->wimm);
818c2ecf20Sopenharmony_ci	if (ret) {
828c2ecf20Sopenharmony_ci		NV_ERROR(drm, "wimm%04x allocation failed: %d\n", oclass, ret);
838c2ecf20Sopenharmony_ci		return ret;
848c2ecf20Sopenharmony_ci	}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	wndw->interlock.wimm = wndw->interlock.data;
878c2ecf20Sopenharmony_ci	wndw->immd = func;
888c2ecf20Sopenharmony_ci	return 0;
898c2ecf20Sopenharmony_ci}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ciint
928c2ecf20Sopenharmony_ciwimmc37b_init(struct nouveau_drm *drm, s32 oclass, struct nv50_wndw *wndw)
938c2ecf20Sopenharmony_ci{
948c2ecf20Sopenharmony_ci	return wimmc37b_init_(&wimmc37b, drm, oclass, wndw);
958c2ecf20Sopenharmony_ci}
96