2 * Copyright 2012 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.
32 #include "nvif/class.h"
35 abi16_chan_nv04(struct nouveau_object *obj)
37 struct nouveau_drm *drm = nouveau_drm(obj);
38 struct nv04_fifo *nv04 = obj->data;
39 struct drm_nouveau_channel_alloc req = {
40 .fb_ctxdma_handle = nv04->vram,
41 .tt_ctxdma_handle = nv04->gart
45 ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_CHANNEL_ALLOC,
50 nv04->base.channel = req.channel;
51 nv04->base.pushbuf = req.pushbuf_domains;
52 nv04->notify = req.notifier_handle;
53 nv04->base.object->handle = req.channel;
54 nv04->base.object->length = sizeof(*nv04);
59 abi16_chan_nvc0(struct nouveau_object *obj)
61 struct nouveau_drm *drm = nouveau_drm(obj);
62 struct drm_nouveau_channel_alloc req = {};
63 struct nvc0_fifo *nvc0 = obj->data;
66 ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_CHANNEL_ALLOC,
71 nvc0->base.channel = req.channel;
72 nvc0->base.pushbuf = req.pushbuf_domains;
73 nvc0->notify = req.notifier_handle;
74 nvc0->base.object->handle = req.channel;
75 nvc0->base.object->length = sizeof(*nvc0);
80 abi16_chan_nve0(struct nouveau_object *obj)
82 struct nouveau_drm *drm = nouveau_drm(obj);
83 struct drm_nouveau_channel_alloc req = {};
84 struct nve0_fifo *nve0 = obj->data;
87 if (obj->length > offsetof(struct nve0_fifo, engine)) {
88 req.fb_ctxdma_handle = 0xffffffff;
89 req.tt_ctxdma_handle = nve0->engine;
92 ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_CHANNEL_ALLOC,
97 nve0->base.channel = req.channel;
98 nve0->base.pushbuf = req.pushbuf_domains;
99 nve0->notify = req.notifier_handle;
100 nve0->base.object->handle = req.channel;
101 nve0->base.object->length = sizeof(*nve0);
106 abi16_engobj(struct nouveau_object *obj)
108 struct nouveau_drm *drm = nouveau_drm(obj);
109 struct drm_nouveau_grobj_alloc req = {
110 .channel = obj->parent->handle,
111 .handle = obj->handle,
112 .class = obj->oclass,
116 /* Older kernel versions did not have the concept of nouveau-
117 * specific classes and abused some NVIDIA-assigned ones for
118 * a SW class. The ABI16 layer has compatibility in place to
119 * translate these older identifiers to the newer ones.
121 * Clients that have been updated to use NVIF are required to
122 * use the newer class identifiers, which means that they'll
123 * break if running on an older kernel.
125 * To handle this case, when using ABI16, we translate to the
126 * older values which work on any kernel.
129 case NVIF_CLASS_SW_NV04 : req.class = 0x006e; break;
130 case NVIF_CLASS_SW_NV10 : req.class = 0x016e; break;
131 case NVIF_CLASS_SW_NV50 : req.class = 0x506e; break;
132 case NVIF_CLASS_SW_GF100: req.class = 0x906e; break;
137 ret = drmCommandWrite(drm->fd, DRM_NOUVEAU_GROBJ_ALLOC,
142 obj->length = sizeof(struct nouveau_object *);
147 abi16_ntfy(struct nouveau_object *obj)
149 struct nouveau_drm *drm = nouveau_drm(obj);
150 struct nv04_notify *ntfy = obj->data;
151 struct drm_nouveau_notifierobj_alloc req = {
152 .channel = obj->parent->handle,
153 .handle = ntfy->object->handle,
154 .size = ntfy->length,
158 ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_NOTIFIEROBJ_ALLOC,
163 ntfy->offset = req.offset;
164 ntfy->object->length = sizeof(*ntfy);
169 abi16_sclass(struct nouveau_object *obj, struct nouveau_sclass **psclass)
171 struct nouveau_sclass *sclass;
172 struct nouveau_device *dev;
174 if (!(sclass = calloc(8, sizeof(*sclass))))
178 switch (obj->oclass) {
179 case NOUVEAU_FIFO_CHANNEL_CLASS:
180 /* Older kernel versions were exposing the wrong video engine
181 * classes on certain G98:GF100 boards. This has since been
182 * corrected, but ABI16 has compatibility in place to avoid
183 * breaking older userspace.
185 * Clients that have been updated to use NVIF are required to
186 * use the correct classes, which means that they'll break if
187 * running on an older kernel.
189 * To handle this issue, if using the older kernel interfaces,
190 * we'll magic up a list containing the vdec classes that the
191 * kernel will accept for these boards. Clients should make
192 * use of this information instead of hardcoding classes for
195 dev = (struct nouveau_device *)obj->parent;
196 if (dev->chipset >= 0x98 &&
197 dev->chipset != 0xa0 &&
198 dev->chipset < 0xc0) {
199 *sclass++ = (struct nouveau_sclass){
202 *sclass++ = (struct nouveau_sclass){
205 *sclass++ = (struct nouveau_sclass){
214 return sclass - *psclass;
218 abi16_delete(struct nouveau_object *obj)
220 struct nouveau_drm *drm = nouveau_drm(obj);
221 if (obj->oclass == NOUVEAU_FIFO_CHANNEL_CLASS) {
222 struct drm_nouveau_channel_free req;
223 req.channel = obj->handle;
224 drmCommandWrite(drm->fd, DRM_NOUVEAU_CHANNEL_FREE,
227 struct drm_nouveau_gpuobj_free req;
228 req.channel = obj->parent->handle;
229 req.handle = obj->handle;
230 drmCommandWrite(drm->fd, DRM_NOUVEAU_GPUOBJ_FREE,
236 abi16_object(struct nouveau_object *obj, int (**func)(struct nouveau_object *))
238 struct nouveau_object *parent = obj->parent;
240 /* nouveau_object::length is (ab)used to determine whether the
241 * object is a legacy object (!=0), or a real NVIF object.
243 if ((parent->length != 0 && parent->oclass == NOUVEAU_DEVICE_CLASS) ||
244 (parent->length == 0 && parent->oclass == NV_DEVICE)) {
245 if (obj->oclass == NOUVEAU_FIFO_CHANNEL_CLASS) {
246 struct nouveau_device *dev = (void *)parent;
247 if (dev->chipset < 0xc0)
248 *func = abi16_chan_nv04;
250 if (dev->chipset < 0xe0)
251 *func = abi16_chan_nvc0;
253 *func = abi16_chan_nve0;
257 if ((parent->length != 0 &&
258 parent->oclass == NOUVEAU_FIFO_CHANNEL_CLASS)) {
259 if (obj->oclass == NOUVEAU_NOTIFIER_CLASS) {
264 *func = abi16_engobj;
265 return false; /* try NVIF, if supported, before calling func */
273 abi16_bo_info(struct nouveau_bo *bo, struct drm_nouveau_gem_info *info)
275 struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
277 nvbo->map_handle = info->map_handle;
278 bo->handle = info->handle;
279 bo->size = info->size;
280 bo->offset = info->offset;
283 if (info->domain & NOUVEAU_GEM_DOMAIN_VRAM)
284 bo->flags |= NOUVEAU_BO_VRAM;
285 if (info->domain & NOUVEAU_GEM_DOMAIN_GART)
286 bo->flags |= NOUVEAU_BO_GART;
287 if (!(info->tile_flags & NOUVEAU_GEM_TILE_NONCONTIG))
288 bo->flags |= NOUVEAU_BO_CONTIG;
289 if (nvbo->map_handle)
290 bo->flags |= NOUVEAU_BO_MAP;
292 if (bo->device->chipset >= 0xc0) {
293 bo->config.nvc0.memtype = (info->tile_flags & 0xff00) >> 8;
294 bo->config.nvc0.tile_mode = info->tile_mode;
296 if (bo->device->chipset >= 0x80 || bo->device->chipset == 0x50) {
297 bo->config.nv50.memtype = (info->tile_flags & 0x07f00) >> 8 |
298 (info->tile_flags & 0x30000) >> 9;
299 bo->config.nv50.tile_mode = info->tile_mode << 4;
301 bo->config.nv04.surf_flags = info->tile_flags & 7;
302 bo->config.nv04.surf_pitch = info->tile_mode;
307 abi16_bo_init(struct nouveau_bo *bo, uint32_t alignment,
308 union nouveau_bo_config *config)
310 struct nouveau_device *dev = bo->device;
311 struct nouveau_drm *drm = nouveau_drm(&dev->object);
312 struct drm_nouveau_gem_new req = {};
313 struct drm_nouveau_gem_info *info = &req.info;
316 if (bo->flags & NOUVEAU_BO_VRAM)
317 info->domain |= NOUVEAU_GEM_DOMAIN_VRAM;
318 if (bo->flags & NOUVEAU_BO_GART)
319 info->domain |= NOUVEAU_GEM_DOMAIN_GART;
321 info->domain |= NOUVEAU_GEM_DOMAIN_VRAM |
322 NOUVEAU_GEM_DOMAIN_GART;
324 if (bo->flags & NOUVEAU_BO_MAP)
325 info->domain |= NOUVEAU_GEM_DOMAIN_MAPPABLE;
327 if (bo->flags & NOUVEAU_BO_COHERENT)
328 info->domain |= NOUVEAU_GEM_DOMAIN_COHERENT;
330 if (!(bo->flags & NOUVEAU_BO_CONTIG))
331 info->tile_flags = NOUVEAU_GEM_TILE_NONCONTIG;
333 info->size = bo->size;
334 req.align = alignment;
337 if (dev->chipset >= 0xc0) {
338 info->tile_flags = (config->nvc0.memtype & 0xff) << 8;
339 info->tile_mode = config->nvc0.tile_mode;
341 if (dev->chipset >= 0x80 || dev->chipset == 0x50) {
342 info->tile_flags = (config->nv50.memtype & 0x07f) << 8 |
343 (config->nv50.memtype & 0x180) << 9;
344 info->tile_mode = config->nv50.tile_mode >> 4;
346 info->tile_flags = config->nv04.surf_flags & 7;
347 info->tile_mode = config->nv04.surf_pitch;
351 if (!nouveau_device(dev)->have_bo_usage)
352 info->tile_flags &= 0x0000ff00;
354 ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_GEM_NEW,
357 abi16_bo_info(bo, &req.info);