1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs * Copyright 2014 Red Hat Inc.
3c39f472eSBen Skeggs *
4c39f472eSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs *
11c39f472eSBen Skeggs * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs *
14c39f472eSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17c39f472eSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs *
22c39f472eSBen Skeggs * Authors: Ben Skeggs <bskeggs@redhat.com>
23c39f472eSBen Skeggs */
24c39f472eSBen Skeggs #include "priv.h"
25c39f472eSBen Skeggs
26bd447053SBen Skeggs #include <core/memory.h>
27c39f472eSBen Skeggs
2870bc7182SBen Skeggs void
nvkm_ltc_tags_clear(struct nvkm_device * device,u32 first,u32 count)29b1e839f3SBen Skeggs nvkm_ltc_tags_clear(struct nvkm_device *device, u32 first, u32 count)
30c39f472eSBen Skeggs {
31b1e839f3SBen Skeggs struct nvkm_ltc *ltc = device->ltc;
32c39f472eSBen Skeggs const u32 limit = first + count - 1;
33c39f472eSBen Skeggs
34c7750cfbSBen Skeggs BUG_ON((first > limit) || (limit >= ltc->num_tags));
35c39f472eSBen Skeggs
36dbffdff7SBen Skeggs mutex_lock(<c->mutex);
3770bc7182SBen Skeggs ltc->func->cbc_clear(ltc, first, limit);
3870bc7182SBen Skeggs ltc->func->cbc_wait(ltc);
39dbffdff7SBen Skeggs mutex_unlock(<c->mutex);
40c39f472eSBen Skeggs }
41c39f472eSBen Skeggs
4270bc7182SBen Skeggs int
nvkm_ltc_zbc_color_get(struct nvkm_ltc * ltc,int index,const u32 color[4])4370bc7182SBen Skeggs nvkm_ltc_zbc_color_get(struct nvkm_ltc *ltc, int index, const u32 color[4])
44c39f472eSBen Skeggs {
45c7750cfbSBen Skeggs memcpy(ltc->zbc_color[index], color, sizeof(ltc->zbc_color[index]));
4670bc7182SBen Skeggs ltc->func->zbc_clear_color(ltc, index, color);
47c39f472eSBen Skeggs return index;
48c39f472eSBen Skeggs }
49c39f472eSBen Skeggs
50c39f472eSBen Skeggs int
nvkm_ltc_zbc_depth_get(struct nvkm_ltc * ltc,int index,const u32 depth)5170bc7182SBen Skeggs nvkm_ltc_zbc_depth_get(struct nvkm_ltc *ltc, int index, const u32 depth)
52c39f472eSBen Skeggs {
5370bc7182SBen Skeggs ltc->zbc_depth[index] = depth;
5470bc7182SBen Skeggs ltc->func->zbc_clear_depth(ltc, index, depth);
5570bc7182SBen Skeggs return index;
56c39f472eSBen Skeggs }
57c39f472eSBen Skeggs
584b2c71edSBen Skeggs int
nvkm_ltc_zbc_stencil_get(struct nvkm_ltc * ltc,int index,const u32 stencil)594b2c71edSBen Skeggs nvkm_ltc_zbc_stencil_get(struct nvkm_ltc *ltc, int index, const u32 stencil)
604b2c71edSBen Skeggs {
614b2c71edSBen Skeggs ltc->zbc_stencil[index] = stencil;
624b2c71edSBen Skeggs ltc->func->zbc_clear_stencil(ltc, index, stencil);
634b2c71edSBen Skeggs return index;
644b2c71edSBen Skeggs }
654b2c71edSBen Skeggs
6638a8fc78SAlexandre Courbot void
nvkm_ltc_invalidate(struct nvkm_ltc * ltc)6738a8fc78SAlexandre Courbot nvkm_ltc_invalidate(struct nvkm_ltc *ltc)
6838a8fc78SAlexandre Courbot {
6938a8fc78SAlexandre Courbot if (ltc->func->invalidate)
7038a8fc78SAlexandre Courbot ltc->func->invalidate(ltc);
7138a8fc78SAlexandre Courbot }
7238a8fc78SAlexandre Courbot
7338a8fc78SAlexandre Courbot void
nvkm_ltc_flush(struct nvkm_ltc * ltc)7438a8fc78SAlexandre Courbot nvkm_ltc_flush(struct nvkm_ltc *ltc)
7538a8fc78SAlexandre Courbot {
7638a8fc78SAlexandre Courbot if (ltc->func->flush)
7738a8fc78SAlexandre Courbot ltc->func->flush(ltc);
7838a8fc78SAlexandre Courbot }
7938a8fc78SAlexandre Courbot
8070bc7182SBen Skeggs static void
nvkm_ltc_intr(struct nvkm_subdev * subdev)8170bc7182SBen Skeggs nvkm_ltc_intr(struct nvkm_subdev *subdev)
8270bc7182SBen Skeggs {
8370bc7182SBen Skeggs struct nvkm_ltc *ltc = nvkm_ltc(subdev);
8470bc7182SBen Skeggs ltc->func->intr(ltc);
8570bc7182SBen Skeggs }
8670bc7182SBen Skeggs
8770bc7182SBen Skeggs static int
nvkm_ltc_oneinit(struct nvkm_subdev * subdev)8870bc7182SBen Skeggs nvkm_ltc_oneinit(struct nvkm_subdev *subdev)
8970bc7182SBen Skeggs {
9070bc7182SBen Skeggs struct nvkm_ltc *ltc = nvkm_ltc(subdev);
9170bc7182SBen Skeggs return ltc->func->oneinit(ltc);
9270bc7182SBen Skeggs }
9370bc7182SBen Skeggs
9470bc7182SBen Skeggs static int
nvkm_ltc_init(struct nvkm_subdev * subdev)9570bc7182SBen Skeggs nvkm_ltc_init(struct nvkm_subdev *subdev)
9670bc7182SBen Skeggs {
9770bc7182SBen Skeggs struct nvkm_ltc *ltc = nvkm_ltc(subdev);
9870bc7182SBen Skeggs int i;
9970bc7182SBen Skeggs
100*4500031fSBen Skeggs for (i = ltc->zbc_color_min; i <= ltc->zbc_color_max; i++)
10170bc7182SBen Skeggs ltc->func->zbc_clear_color(ltc, i, ltc->zbc_color[i]);
102*4500031fSBen Skeggs
103*4500031fSBen Skeggs for (i = ltc->zbc_depth_min; i <= ltc->zbc_depth_max; i++) {
10470bc7182SBen Skeggs ltc->func->zbc_clear_depth(ltc, i, ltc->zbc_depth[i]);
1054b2c71edSBen Skeggs if (ltc->func->zbc_clear_stencil)
1064b2c71edSBen Skeggs ltc->func->zbc_clear_stencil(ltc, i, ltc->zbc_stencil[i]);
10770bc7182SBen Skeggs }
10870bc7182SBen Skeggs
10970bc7182SBen Skeggs ltc->func->init(ltc);
110c39f472eSBen Skeggs return 0;
111c39f472eSBen Skeggs }
112c39f472eSBen Skeggs
11370bc7182SBen Skeggs static void *
nvkm_ltc_dtor(struct nvkm_subdev * subdev)11470bc7182SBen Skeggs nvkm_ltc_dtor(struct nvkm_subdev *subdev)
115c39f472eSBen Skeggs {
11670bc7182SBen Skeggs struct nvkm_ltc *ltc = nvkm_ltc(subdev);
117bd447053SBen Skeggs nvkm_memory_unref(<c->tag_ram);
118dbffdff7SBen Skeggs mutex_destroy(<c->mutex);
11970bc7182SBen Skeggs return ltc;
12070bc7182SBen Skeggs }
121c39f472eSBen Skeggs
12270bc7182SBen Skeggs static const struct nvkm_subdev_func
12370bc7182SBen Skeggs nvkm_ltc = {
12470bc7182SBen Skeggs .dtor = nvkm_ltc_dtor,
12570bc7182SBen Skeggs .oneinit = nvkm_ltc_oneinit,
12670bc7182SBen Skeggs .init = nvkm_ltc_init,
12770bc7182SBen Skeggs .intr = nvkm_ltc_intr,
12870bc7182SBen Skeggs };
129c39f472eSBen Skeggs
13070bc7182SBen Skeggs int
nvkm_ltc_new_(const struct nvkm_ltc_func * func,struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_ltc ** pltc)13170bc7182SBen Skeggs nvkm_ltc_new_(const struct nvkm_ltc_func *func, struct nvkm_device *device,
1320afc1c4cSBen Skeggs enum nvkm_subdev_type type, int inst, struct nvkm_ltc **pltc)
13370bc7182SBen Skeggs {
13470bc7182SBen Skeggs struct nvkm_ltc *ltc;
135c39f472eSBen Skeggs
13670bc7182SBen Skeggs if (!(ltc = *pltc = kzalloc(sizeof(*ltc), GFP_KERNEL)))
13770bc7182SBen Skeggs return -ENOMEM;
13870bc7182SBen Skeggs
1390afc1c4cSBen Skeggs nvkm_subdev_ctor(&nvkm_ltc, device, type, inst, <c->subdev);
14070bc7182SBen Skeggs ltc->func = func;
141dbffdff7SBen Skeggs mutex_init(<c->mutex);
142*4500031fSBen Skeggs ltc->zbc_color_min = 1; /* reserve 0 for disabled */
143*4500031fSBen Skeggs ltc->zbc_color_max = min(func->zbc_color, NVKM_LTC_MAX_ZBC_COLOR_CNT) - 1;
144*4500031fSBen Skeggs ltc->zbc_depth_min = 1; /* reserve 0 for disabled */
145*4500031fSBen Skeggs ltc->zbc_depth_max = min(func->zbc_depth, NVKM_LTC_MAX_ZBC_DEPTH_CNT) - 1;
146c39f472eSBen Skeggs return 0;
147c39f472eSBen Skeggs }
148