2 * Copyright 2014 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
26 #include <core/memory.h>
29 nvkm_ltc_tags_clear(struct nvkm_device
*device
, u32 first
, u32 count
)
31 struct nvkm_ltc
*ltc
= device
->ltc
;
32 const u32 limit
= first
+ count
- 1;
34 BUG_ON((first
> limit
) || (limit
>= ltc
->num_tags
));
36 mutex_lock(<c
->subdev
.mutex
);
37 ltc
->func
->cbc_clear(ltc
, first
, limit
);
38 ltc
->func
->cbc_wait(ltc
);
39 mutex_unlock(<c
->subdev
.mutex
);
43 nvkm_ltc_zbc_color_get(struct nvkm_ltc
*ltc
, int index
, const u32 color
[4])
45 memcpy(ltc
->zbc_color
[index
], color
, sizeof(ltc
->zbc_color
[index
]));
46 ltc
->func
->zbc_clear_color(ltc
, index
, color
);
51 nvkm_ltc_zbc_depth_get(struct nvkm_ltc
*ltc
, int index
, const u32 depth
)
53 ltc
->zbc_depth
[index
] = depth
;
54 ltc
->func
->zbc_clear_depth(ltc
, index
, depth
);
59 nvkm_ltc_zbc_stencil_get(struct nvkm_ltc
*ltc
, int index
, const u32 stencil
)
61 ltc
->zbc_stencil
[index
] = stencil
;
62 ltc
->func
->zbc_clear_stencil(ltc
, index
, stencil
);
67 nvkm_ltc_invalidate(struct nvkm_ltc
*ltc
)
69 if (ltc
->func
->invalidate
)
70 ltc
->func
->invalidate(ltc
);
74 nvkm_ltc_flush(struct nvkm_ltc
*ltc
)
77 ltc
->func
->flush(ltc
);
81 nvkm_ltc_intr(struct nvkm_subdev
*subdev
)
83 struct nvkm_ltc
*ltc
= nvkm_ltc(subdev
);
88 nvkm_ltc_oneinit(struct nvkm_subdev
*subdev
)
90 struct nvkm_ltc
*ltc
= nvkm_ltc(subdev
);
91 return ltc
->func
->oneinit(ltc
);
95 nvkm_ltc_init(struct nvkm_subdev
*subdev
)
97 struct nvkm_ltc
*ltc
= nvkm_ltc(subdev
);
100 for (i
= ltc
->zbc_min
; i
<= ltc
->zbc_max
; i
++) {
101 ltc
->func
->zbc_clear_color(ltc
, i
, ltc
->zbc_color
[i
]);
102 ltc
->func
->zbc_clear_depth(ltc
, i
, ltc
->zbc_depth
[i
]);
103 if (ltc
->func
->zbc_clear_stencil
)
104 ltc
->func
->zbc_clear_stencil(ltc
, i
, ltc
->zbc_stencil
[i
]);
107 ltc
->func
->init(ltc
);
112 nvkm_ltc_dtor(struct nvkm_subdev
*subdev
)
114 struct nvkm_ltc
*ltc
= nvkm_ltc(subdev
);
115 nvkm_memory_unref(<c
->tag_ram
);
119 static const struct nvkm_subdev_func
121 .dtor
= nvkm_ltc_dtor
,
122 .oneinit
= nvkm_ltc_oneinit
,
123 .init
= nvkm_ltc_init
,
124 .intr
= nvkm_ltc_intr
,
128 nvkm_ltc_new_(const struct nvkm_ltc_func
*func
, struct nvkm_device
*device
,
129 int index
, struct nvkm_ltc
**pltc
)
131 struct nvkm_ltc
*ltc
;
133 if (!(ltc
= *pltc
= kzalloc(sizeof(*ltc
), GFP_KERNEL
)))
136 nvkm_subdev_ctor(&nvkm_ltc
, device
, index
, <c
->subdev
);
138 ltc
->zbc_min
= 1; /* reserve 0 for disabled */
139 ltc
->zbc_max
= min(func
->zbc
, NVKM_LTC_MAX_ZBC_CNT
) - 1;