]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/nouveau/nvkm/subdev/ltc/base.c
drm/nouveau/ltc/gf100-: allocate tagram with nvkm_ram_get()
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / nouveau / nvkm / subdev / ltc / base.c
CommitLineData
95484b57
BS
1/*
2 * Copyright 2014 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 * Authors: Ben Skeggs <bskeggs@redhat.com>
23 */
95484b57
BS
24#include "priv.h"
25
bd447053 26#include <core/memory.h>
70bc7182 27#include <subdev/fb.h>
95484b57 28
70bc7182
BS
29int
30nvkm_ltc_tags_alloc(struct nvkm_ltc *ltc, u32 n, struct nvkm_mm_node **pnode)
31{
6cd7670c
BS
32 struct nvkm_fb *fb = ltc->subdev.device->fb;
33 int ret = nvkm_mm_head(&fb->tags, 0, 1, n, n, 1, pnode);
95484b57
BS
34 if (ret)
35 *pnode = NULL;
95484b57
BS
36 return ret;
37}
38
70bc7182
BS
39void
40nvkm_ltc_tags_free(struct nvkm_ltc *ltc, struct nvkm_mm_node **pnode)
95484b57 41{
6cd7670c
BS
42 struct nvkm_fb *fb = ltc->subdev.device->fb;
43 nvkm_mm_free(&fb->tags, pnode);
95484b57
BS
44}
45
70bc7182 46void
b1e839f3 47nvkm_ltc_tags_clear(struct nvkm_device *device, u32 first, u32 count)
95484b57 48{
b1e839f3 49 struct nvkm_ltc *ltc = device->ltc;
95484b57
BS
50 const u32 limit = first + count - 1;
51
c7750cfb 52 BUG_ON((first > limit) || (limit >= ltc->num_tags));
95484b57 53
f4e65efc 54 mutex_lock(&ltc->subdev.mutex);
70bc7182
BS
55 ltc->func->cbc_clear(ltc, first, limit);
56 ltc->func->cbc_wait(ltc);
f4e65efc 57 mutex_unlock(&ltc->subdev.mutex);
95484b57
BS
58}
59
70bc7182
BS
60int
61nvkm_ltc_zbc_color_get(struct nvkm_ltc *ltc, int index, const u32 color[4])
f38fdb6a 62{
c7750cfb 63 memcpy(ltc->zbc_color[index], color, sizeof(ltc->zbc_color[index]));
70bc7182 64 ltc->func->zbc_clear_color(ltc, index, color);
f38fdb6a
BS
65 return index;
66}
67
70bc7182
BS
68int
69nvkm_ltc_zbc_depth_get(struct nvkm_ltc *ltc, int index, const u32 depth)
f38fdb6a 70{
c7750cfb 71 ltc->zbc_depth[index] = depth;
70bc7182 72 ltc->func->zbc_clear_depth(ltc, index, depth);
f38fdb6a
BS
73 return index;
74}
75
38a8fc78
AC
76void
77nvkm_ltc_invalidate(struct nvkm_ltc *ltc)
78{
79 if (ltc->func->invalidate)
80 ltc->func->invalidate(ltc);
81}
82
83void
84nvkm_ltc_flush(struct nvkm_ltc *ltc)
85{
86 if (ltc->func->flush)
87 ltc->func->flush(ltc);
88}
89
70bc7182
BS
90static void
91nvkm_ltc_intr(struct nvkm_subdev *subdev)
f38fdb6a 92{
70bc7182
BS
93 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
94 ltc->func->intr(ltc);
95}
f38fdb6a 96
70bc7182
BS
97static int
98nvkm_ltc_oneinit(struct nvkm_subdev *subdev)
99{
100 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
101 return ltc->func->oneinit(ltc);
102}
103
104static int
105nvkm_ltc_init(struct nvkm_subdev *subdev)
106{
107 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
108 int i;
f38fdb6a 109
70bc7182
BS
110 for (i = ltc->zbc_min; i <= ltc->zbc_max; i++) {
111 ltc->func->zbc_clear_color(ltc, i, ltc->zbc_color[i]);
112 ltc->func->zbc_clear_depth(ltc, i, ltc->zbc_depth[i]);
f38fdb6a
BS
113 }
114
70bc7182 115 ltc->func->init(ltc);
f38fdb6a
BS
116 return 0;
117}
118
70bc7182
BS
119static void *
120nvkm_ltc_dtor(struct nvkm_subdev *subdev)
121{
122 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
bd447053 123 nvkm_memory_unref(&ltc->tag_ram);
70bc7182
BS
124 return ltc;
125}
126
127static const struct nvkm_subdev_func
128nvkm_ltc = {
129 .dtor = nvkm_ltc_dtor,
130 .oneinit = nvkm_ltc_oneinit,
131 .init = nvkm_ltc_init,
132 .intr = nvkm_ltc_intr,
133};
134
95484b57 135int
70bc7182
BS
136nvkm_ltc_new_(const struct nvkm_ltc_func *func, struct nvkm_device *device,
137 int index, struct nvkm_ltc **pltc)
95484b57 138{
70bc7182 139 struct nvkm_ltc *ltc;
95484b57 140
70bc7182
BS
141 if (!(ltc = *pltc = kzalloc(sizeof(*ltc), GFP_KERNEL)))
142 return -ENOMEM;
143
56d06fa2 144 nvkm_subdev_ctor(&nvkm_ltc, device, index, &ltc->subdev);
70bc7182
BS
145 ltc->func = func;
146 ltc->zbc_min = 1; /* reserve 0 for disabled */
147 ltc->zbc_max = min(func->zbc, NVKM_LTC_MAX_ZBC_CNT) - 1;
95484b57
BS
148 return 0;
149}