xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvif/user.c (revision 58c3d3c8)
137e1c45aSBen Skeggs /*
237e1c45aSBen Skeggs  * Copyright 2018 Red Hat Inc.
337e1c45aSBen Skeggs  *
437e1c45aSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
537e1c45aSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
637e1c45aSBen Skeggs  * to deal in the Software without restriction, including without limitation
737e1c45aSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
837e1c45aSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
937e1c45aSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
1037e1c45aSBen Skeggs  *
1137e1c45aSBen Skeggs  * The above copyright notice and this permission notice shall be included in
1237e1c45aSBen Skeggs  * all copies or substantial portions of the Software.
1337e1c45aSBen Skeggs  *
1437e1c45aSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1537e1c45aSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1637e1c45aSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1737e1c45aSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1837e1c45aSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1937e1c45aSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2037e1c45aSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
2137e1c45aSBen Skeggs  */
2237e1c45aSBen Skeggs #include <nvif/user.h>
2337e1c45aSBen Skeggs #include <nvif/device.h>
2437e1c45aSBen Skeggs 
2537e1c45aSBen Skeggs #include <nvif/class.h>
2637e1c45aSBen Skeggs 
2737e1c45aSBen Skeggs void
nvif_user_dtor(struct nvif_device * device)2864a0f59aSBen Skeggs nvif_user_dtor(struct nvif_device *device)
2937e1c45aSBen Skeggs {
3037e1c45aSBen Skeggs 	if (device->user.func) {
319ac596a4SBen Skeggs 		nvif_object_dtor(&device->user.object);
3237e1c45aSBen Skeggs 		device->user.func = NULL;
3337e1c45aSBen Skeggs 	}
3437e1c45aSBen Skeggs }
3537e1c45aSBen Skeggs 
3637e1c45aSBen Skeggs int
nvif_user_ctor(struct nvif_device * device,const char * name)3764a0f59aSBen Skeggs nvif_user_ctor(struct nvif_device *device, const char *name)
3837e1c45aSBen Skeggs {
3937e1c45aSBen Skeggs 	struct {
4037e1c45aSBen Skeggs 		s32 oclass;
4137e1c45aSBen Skeggs 		int version;
4237e1c45aSBen Skeggs 		const struct nvif_user_func *func;
4337e1c45aSBen Skeggs 	} users[] = {
44*58c3d3c8SBen Skeggs 		{ AMPERE_USERMODE_A, -1, &nvif_userc361 },
45*58c3d3c8SBen Skeggs 		{ TURING_USERMODE_A, -1, &nvif_userc361 },
4637e1c45aSBen Skeggs 		{  VOLTA_USERMODE_A, -1, &nvif_userc361 },
4737e1c45aSBen Skeggs 		{}
4837e1c45aSBen Skeggs 	};
4937e1c45aSBen Skeggs 	int cid, ret;
5037e1c45aSBen Skeggs 
5137e1c45aSBen Skeggs 	if (device->user.func)
5237e1c45aSBen Skeggs 		return 0;
5337e1c45aSBen Skeggs 
5437e1c45aSBen Skeggs 	cid = nvif_mclass(&device->object, users);
5537e1c45aSBen Skeggs 	if (cid < 0)
5637e1c45aSBen Skeggs 		return cid;
5737e1c45aSBen Skeggs 
5864a0f59aSBen Skeggs 	ret = nvif_object_ctor(&device->object, name ? name : "nvifUsermode",
599ac596a4SBen Skeggs 			       0, users[cid].oclass, NULL, 0,
6037e1c45aSBen Skeggs 			       &device->user.object);
6137e1c45aSBen Skeggs 	if (ret)
6237e1c45aSBen Skeggs 		return ret;
6337e1c45aSBen Skeggs 
6437e1c45aSBen Skeggs 	nvif_object_map(&device->user.object, NULL, 0);
6537e1c45aSBen Skeggs 	device->user.func = users[cid].func;
6637e1c45aSBen Skeggs 	return 0;
6737e1c45aSBen Skeggs }
68