162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright 2021 Red Hat Inc.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation
762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
1262306a36Sopenharmony_ci * all copies or substantial portions of the Software.
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1562306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1662306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1762306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1862306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1962306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2062306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
2162306a36Sopenharmony_ci */
2262306a36Sopenharmony_ci#include "wndw.h"
2362306a36Sopenharmony_ci#include "atom.h"
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#include <nvif/pushc37b.h>
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#include <nvhw/class/clc57e.h>
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cistatic int
3062306a36Sopenharmony_ciwndwc67e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
3162306a36Sopenharmony_ci{
3262306a36Sopenharmony_ci	struct nvif_push *push = wndw->wndw.push;
3362306a36Sopenharmony_ci	int ret;
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 17)))
3662306a36Sopenharmony_ci		return ret;
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci	PUSH_MTHD(push, NVC57E, SET_PRESENT_CONTROL,
3962306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_PRESENT_CONTROL, MIN_PRESENT_INTERVAL, asyw->image.interval) |
4062306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_PRESENT_CONTROL, BEGIN_MODE, asyw->image.mode) |
4162306a36Sopenharmony_ci		  NVDEF(NVC57E, SET_PRESENT_CONTROL, TIMESTAMP_MODE, DISABLE));
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci	PUSH_MTHD(push, NVC57E, SET_SIZE,
4462306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_SIZE, WIDTH, asyw->image.w) |
4562306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_SIZE, HEIGHT, asyw->image.h),
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci				SET_STORAGE,
4862306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_STORAGE, BLOCK_HEIGHT, asyw->image.blockh),
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci				SET_PARAMS,
5162306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_PARAMS, FORMAT, asyw->image.format) |
5262306a36Sopenharmony_ci		  NVDEF(NVC57E, SET_PARAMS, CLAMP_BEFORE_BLEND, DISABLE) |
5362306a36Sopenharmony_ci		  NVDEF(NVC57E, SET_PARAMS, SWAP_UV, DISABLE) |
5462306a36Sopenharmony_ci		  NVDEF(NVC57E, SET_PARAMS, FMT_ROUNDING_MODE, ROUND_TO_NEAREST),
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci				SET_PLANAR_STORAGE(0),
5762306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_PLANAR_STORAGE, PITCH, asyw->image.blocks[0]) |
5862306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_PLANAR_STORAGE, PITCH, asyw->image.pitch[0] >> 6));
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci	PUSH_MTHD(push, NVC57E, SET_CONTEXT_DMA_ISO(0), asyw->image.handle, 1);
6162306a36Sopenharmony_ci	PUSH_MTHD(push, NVC57E, SET_OFFSET(0), asyw->image.offset[0] >> 8);
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci	PUSH_MTHD(push, NVC57E, SET_POINT_IN(0),
6462306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_POINT_IN, X, asyw->state.src_x >> 16) |
6562306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_POINT_IN, Y, asyw->state.src_y >> 16));
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci	PUSH_MTHD(push, NVC57E, SET_SIZE_IN,
6862306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_SIZE_IN, WIDTH, asyw->state.src_w >> 16) |
6962306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_SIZE_IN, HEIGHT, asyw->state.src_h >> 16));
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci	PUSH_MTHD(push, NVC57E, SET_SIZE_OUT,
7262306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_SIZE_OUT, WIDTH, asyw->state.crtc_w) |
7362306a36Sopenharmony_ci		  NVVAL(NVC57E, SET_SIZE_OUT, HEIGHT, asyw->state.crtc_h));
7462306a36Sopenharmony_ci	return 0;
7562306a36Sopenharmony_ci}
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cistatic const struct nv50_wndw_func
7862306a36Sopenharmony_ciwndwc67e = {
7962306a36Sopenharmony_ci	.acquire = wndwc37e_acquire,
8062306a36Sopenharmony_ci	.release = wndwc37e_release,
8162306a36Sopenharmony_ci	.sema_set = wndwc37e_sema_set,
8262306a36Sopenharmony_ci	.sema_clr = wndwc37e_sema_clr,
8362306a36Sopenharmony_ci	.ntfy_set = wndwc37e_ntfy_set,
8462306a36Sopenharmony_ci	.ntfy_clr = wndwc37e_ntfy_clr,
8562306a36Sopenharmony_ci	.ntfy_reset = corec37d_ntfy_init,
8662306a36Sopenharmony_ci	.ntfy_wait_begun = base507c_ntfy_wait_begun,
8762306a36Sopenharmony_ci	.ilut = wndwc57e_ilut,
8862306a36Sopenharmony_ci	.ilut_identity = true,
8962306a36Sopenharmony_ci	.ilut_size = 1024,
9062306a36Sopenharmony_ci	.xlut_set = wndwc57e_ilut_set,
9162306a36Sopenharmony_ci	.xlut_clr = wndwc57e_ilut_clr,
9262306a36Sopenharmony_ci	.csc = base907c_csc,
9362306a36Sopenharmony_ci	.csc_set = wndwc57e_csc_set,
9462306a36Sopenharmony_ci	.csc_clr = wndwc57e_csc_clr,
9562306a36Sopenharmony_ci	.image_set = wndwc67e_image_set,
9662306a36Sopenharmony_ci	.image_clr = wndwc37e_image_clr,
9762306a36Sopenharmony_ci	.blend_set = wndwc37e_blend_set,
9862306a36Sopenharmony_ci	.update = wndwc37e_update,
9962306a36Sopenharmony_ci};
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ciint
10262306a36Sopenharmony_ciwndwc67e_new(struct nouveau_drm *drm, enum drm_plane_type type, int index,
10362306a36Sopenharmony_ci	     s32 oclass, struct nv50_wndw **pwndw)
10462306a36Sopenharmony_ci{
10562306a36Sopenharmony_ci	return wndwc37e_new_(&wndwc67e, drm, type, index, oclass, BIT(index >> 1), pwndw);
10662306a36Sopenharmony_ci}
107