xref: /netbsd-src/sys/external/bsd/drm2/nouveau/nouveau_module.c (revision 8d8a9557294fe65eec872af0a3978bf9d4834ced)
1 /*	$NetBSD: nouveau_module.c,v 1.11 2022/07/17 15:36:51 riastradh Exp $	*/
2 
3 /*-
4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Taylor R. Campbell.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: nouveau_module.c,v 1.11 2022/07/17 15:36:51 riastradh Exp $");
34 
35 #include <sys/types.h>
36 #include <sys/module.h>
37 #include <sys/systm.h>
38 
39 #include <drm/drm_sysctl.h>
40 
41 #include <core/device.h>
42 
43 MODULE(MODULE_CLASS_DRIVER, nouveau, "drmkms,drmkms_ttm"); /* XXX drmkms_i2c */
44 
45 #ifdef _MODULE
46 #include "ioconf.c"
47 #endif
48 
49 struct drm_sysctl_def nouveau_def = DRM_SYSCTL_INIT();
50 
51 static int
nouveau_init(void)52 nouveau_init(void)
53 {
54 
55 	nvkm_devices_init();
56 	drm_sysctl_init(&nouveau_def);
57 
58 	return 0;
59 }
60 
61 static void
nouveau_fini(void)62 nouveau_fini(void)
63 {
64 
65 	drm_sysctl_fini(&nouveau_def);
66 	nvkm_devices_fini();
67 }
68 
69 static int
nouveau_modcmd(modcmd_t cmd,void * arg __unused)70 nouveau_modcmd(modcmd_t cmd, void *arg __unused)
71 {
72 	int error;
73 
74 	switch (cmd) {
75 	case MODULE_CMD_INIT:
76 		error = nouveau_init();
77 		if (error) {
78 			aprint_error("nouveau: failed to initialize: %d\n",
79 			    error);
80 			return error;
81 		}
82 #ifdef _MODULE
83 		error = config_init_component(cfdriver_ioconf_nouveau,
84 		    cfattach_ioconf_nouveau, cfdata_ioconf_nouveau);
85 		if (error) {
86 			aprint_error("nouveau: failed to init component"
87 			    ": %d\n", error);
88 			nouveau_fini();
89 			return error;
90 		}
91 #endif
92 		return 0;
93 
94 	case MODULE_CMD_FINI:
95 #ifdef _MODULE
96 		error = config_fini_component(cfdriver_ioconf_nouveau,
97 		    cfattach_ioconf_nouveau, cfdata_ioconf_nouveau);
98 		if (error) {
99 			aprint_error("nouveau: failed to fini component"
100 			    ": %d\n", error);
101 			return error;
102 		}
103 #endif
104 		nouveau_fini();
105 		return 0;
106 
107 	default:
108 		return ENOTTY;
109 	}
110 }
111