1/* $NetBSD: nouveau_nvkm_engine_disp_rootnv04.c,v 1.3 2021/12/18 23:45:35 riastradh Exp $ */ 2 3/* 4 * Copyright 2012 Red Hat Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: Ben Skeggs 25 */ 26#include <sys/cdefs.h> 27__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_disp_rootnv04.c,v 1.3 2021/12/18 23:45:35 riastradh Exp $"); 28 29#define nv04_disp_root(p) container_of((p), struct nv04_disp_root, object) 30#include "priv.h" 31#include "head.h" 32 33#include <core/client.h> 34 35#include <nvif/class.h> 36#include <nvif/cl0046.h> 37#include <nvif/unpack.h> 38 39struct nv04_disp_root { 40 struct nvkm_object object; 41 struct nvkm_disp *disp; 42}; 43 44static int 45nv04_disp_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size) 46{ 47 struct nv04_disp_root *root = nv04_disp_root(object); 48 union { 49 struct nv04_disp_mthd_v0 v0; 50 } *args = data; 51 struct nvkm_head *head; 52 int id, ret = -ENOSYS; 53 54 nvif_ioctl(object, "disp mthd size %d\n", size); 55 if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) { 56 nvif_ioctl(object, "disp mthd vers %d mthd %02x head %d\n", 57 args->v0.version, args->v0.method, args->v0.head); 58 mthd = args->v0.method; 59 id = args->v0.head; 60 } else 61 return ret; 62 63 if (!(head = nvkm_head_find(root->disp, id))) 64 return -ENXIO; 65 66 switch (mthd) { 67 case NV04_DISP_SCANOUTPOS: 68 return nvkm_head_mthd_scanoutpos(object, head, data, size); 69 default: 70 break; 71 } 72 73 return -EINVAL; 74} 75 76static const struct nvkm_object_func 77nv04_disp_root = { 78 .mthd = nv04_disp_mthd, 79 .ntfy = nvkm_disp_ntfy, 80}; 81 82static int 83nv04_disp_root_new(struct nvkm_disp *disp, const struct nvkm_oclass *oclass, 84 void *data, u32 size, struct nvkm_object **pobject) 85{ 86 struct nv04_disp_root *root; 87 88 if (!(root = kzalloc(sizeof(*root), GFP_KERNEL))) 89 return -ENOMEM; 90 root->disp = disp; 91 *pobject = &root->object; 92 93 nvkm_object_ctor(&nv04_disp_root, oclass, &root->object); 94 return 0; 95} 96 97const struct nvkm_disp_oclass 98nv04_disp_root_oclass = { 99 .base.oclass = NV04_DISP, 100 .base.minver = -1, 101 .base.maxver = -1, 102 .ctor = nv04_disp_root_new, 103}; 104