xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvif/driver.c (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
104b88677SBen Skeggs /*
204b88677SBen Skeggs  * Copyright 2016 Red Hat Inc.
304b88677SBen Skeggs  *
404b88677SBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
504b88677SBen Skeggs  * copy of this software and associated documentation files (the "Software"),
604b88677SBen Skeggs  * to deal in the Software without restriction, including without limitation
704b88677SBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
804b88677SBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
904b88677SBen Skeggs  * Software is furnished to do so, subject to the following conditions:
1004b88677SBen Skeggs  *
1104b88677SBen Skeggs  * The above copyright notice and this permission notice shall be included in
1204b88677SBen Skeggs  * all copies or substantial portions of the Software.
1304b88677SBen Skeggs  *
1404b88677SBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1504b88677SBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1604b88677SBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1704b88677SBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1804b88677SBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1904b88677SBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2004b88677SBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
2104b88677SBen Skeggs  *
2204b88677SBen Skeggs  * Authors: Ben Skeggs
2304b88677SBen Skeggs  */
2404b88677SBen Skeggs #include <nvif/driver.h>
2504b88677SBen Skeggs #include <nvif/client.h>
2604b88677SBen Skeggs 
2704b88677SBen Skeggs static const struct nvif_driver *
2804b88677SBen Skeggs nvif_driver[] = {
2904b88677SBen Skeggs #ifdef __KERNEL__
3004b88677SBen Skeggs 	&nvif_driver_nvkm,
3104b88677SBen Skeggs #else
3204b88677SBen Skeggs 	&nvif_driver_drm,
3304b88677SBen Skeggs 	&nvif_driver_lib,
3404b88677SBen Skeggs 	&nvif_driver_null,
3504b88677SBen Skeggs #endif
3604b88677SBen Skeggs 	NULL
3704b88677SBen Skeggs };
3804b88677SBen Skeggs 
3904b88677SBen Skeggs int
nvif_driver_init(const char * drv,const char * cfg,const char * dbg,const char * name,u64 device,struct nvif_client * client)4004b88677SBen Skeggs nvif_driver_init(const char *drv, const char *cfg, const char *dbg,
4104b88677SBen Skeggs 		 const char *name, u64 device, struct nvif_client *client)
4204b88677SBen Skeggs {
4304b88677SBen Skeggs 	int ret = -EINVAL, i;
4404b88677SBen Skeggs 
4504b88677SBen Skeggs 	for (i = 0; (client->driver = nvif_driver[i]); i++) {
4604b88677SBen Skeggs 		if (!drv || !strcmp(client->driver->name, drv)) {
4704b88677SBen Skeggs 			ret = client->driver->init(name, device, cfg, dbg,
4804b88677SBen Skeggs 						   &client->object.priv);
4904b88677SBen Skeggs 			if (ret == 0)
5004b88677SBen Skeggs 				break;
5104b88677SBen Skeggs 			client->driver->fini(client->object.priv);
5204b88677SBen Skeggs 		}
5304b88677SBen Skeggs 	}
5404b88677SBen Skeggs 
5504b88677SBen Skeggs 	if (ret == 0)
56*6db25fb1SBen Skeggs 		ret = nvif_client_ctor(client, name, device, client);
5704b88677SBen Skeggs 	return ret;
5804b88677SBen Skeggs }
59