xref: /netbsd-src/sys/external/bsd/drm2/i915drm/i915_module.c (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /*	$NetBSD: i915_module.c,v 1.2 2014/03/18 18:20:42 riastradh Exp $	*/
2 
3 /*-
4  * Copyright (c) 2013 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: i915_module.c,v 1.2 2014/03/18 18:20:42 riastradh Exp $");
34 
35 #include <sys/types.h>
36 #include <sys/module.h>
37 #include <sys/systm.h>
38 
39 #include <drm/drmP.h>
40 
41 #include "i915_drv.h"
42 
43 MODULE(MODULE_CLASS_DRIVER, i915drmkms, "drmkms,drmkms_pci"); /* XXX drmkms_i2c */
44 
45 #ifdef _MODULE
46 #include "ioconf.c"
47 #endif
48 
49 /* XXX Kludge.  */
50 extern struct drm_driver *const i915_drm_driver;
51 
52 static int
53 i915drmkms_modcmd(modcmd_t cmd, void *arg __unused)
54 {
55 	int error;
56 
57 	switch (cmd) {
58 	case MODULE_CMD_INIT:
59 		/* XXX Kludge it up...  Must happen before attachment.  */
60 		i915_drm_driver->num_ioctls = i915_max_ioctl;
61 		i915_drm_driver->driver_features |= DRIVER_MODESET;
62 
63 		error = drm_pci_init(i915_drm_driver, NULL);
64 		if (error) {
65 			aprint_error("i915drmkms: failed to init pci: %d\n",
66 			    error);
67 			return error;
68 		}
69 #ifdef _MODULE
70 		error = config_init_component(cfdriver_ioconf_i915drmkms,
71 		    cfattach_ioconf_i915drmkms, cfdata_ioconf_i915drmkms);
72 		if (error) {
73 			aprint_error("i915drmkms: failed to init component"
74 			    ": %d\n", error);
75 			drm_pci_exit(i915_drm_driver, NULL);
76 			return error;
77 		}
78 #endif
79 		return 0;
80 
81 	case MODULE_CMD_FINI:
82 #ifdef _MODULE
83 		error = config_fini_component(cfdriver_ioconf_i915drmkms,
84 		    cfattach_ioconf_i915drmkms, cfdata_ioconf_i915drmkms);
85 		if (error) {
86 			aprint_error("i915drmkms: failed to fini component"
87 			    ": %d\n", error);
88 			return error;
89 		}
90 #endif
91 		drm_pci_exit(i915_drm_driver, NULL);
92 		return 0;
93 
94 	default:
95 		return ENOTTY;
96 	}
97 }
98