drm_module.c revision 1.7.4.3 1 1.7.4.2 tls /* $NetBSD: drm_module.c,v 1.7.4.3 2017/12/03 11:37:58 jdolecek Exp $ */
2 1.7.4.2 tls
3 1.7.4.2 tls /*-
4 1.7.4.2 tls * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 1.7.4.2 tls * All rights reserved.
6 1.7.4.2 tls *
7 1.7.4.2 tls * This code is derived from software contributed to The NetBSD Foundation
8 1.7.4.2 tls * by Taylor R. Campbell.
9 1.7.4.2 tls *
10 1.7.4.2 tls * Redistribution and use in source and binary forms, with or without
11 1.7.4.2 tls * modification, are permitted provided that the following conditions
12 1.7.4.2 tls * are met:
13 1.7.4.2 tls * 1. Redistributions of source code must retain the above copyright
14 1.7.4.2 tls * notice, this list of conditions and the following disclaimer.
15 1.7.4.2 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.7.4.2 tls * notice, this list of conditions and the following disclaimer in the
17 1.7.4.2 tls * documentation and/or other materials provided with the distribution.
18 1.7.4.2 tls *
19 1.7.4.2 tls * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.7.4.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.7.4.2 tls * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.7.4.2 tls * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.7.4.2 tls * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.7.4.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.7.4.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.7.4.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.7.4.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.7.4.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.7.4.2 tls * POSSIBILITY OF SUCH DAMAGE.
30 1.7.4.2 tls */
31 1.7.4.2 tls
32 1.7.4.2 tls #include <sys/cdefs.h>
33 1.7.4.2 tls __KERNEL_RCSID(0, "$NetBSD: drm_module.c,v 1.7.4.3 2017/12/03 11:37:58 jdolecek Exp $");
34 1.7.4.2 tls
35 1.7.4.2 tls #include <sys/types.h>
36 1.7.4.3 jdolecek #include <sys/conf.h>
37 1.7.4.2 tls #include <sys/device.h>
38 1.7.4.2 tls #include <sys/module.h>
39 1.7.4.2 tls #ifndef _MODULE
40 1.7.4.2 tls #include <sys/once.h>
41 1.7.4.2 tls #endif
42 1.7.4.2 tls #include <sys/reboot.h>
43 1.7.4.2 tls #include <sys/systm.h>
44 1.7.4.2 tls
45 1.7.4.2 tls #include <linux/mutex.h>
46 1.7.4.2 tls
47 1.7.4.2 tls #include <drm/drmP.h>
48 1.7.4.3 jdolecek #include <drm/drm_encoder_slave.h>
49 1.7.4.3 jdolecek #include <drm/drm_sysctl.h>
50 1.7.4.2 tls
51 1.7.4.2 tls /*
52 1.7.4.2 tls * XXX I2C stuff should be moved to a separate drmkms_i2c module.
53 1.7.4.2 tls */
54 1.7.4.3 jdolecek MODULE(MODULE_CLASS_DRIVER, drmkms, "drmkms_linux");
55 1.7.4.2 tls
56 1.7.4.2 tls struct mutex drm_global_mutex;
57 1.7.4.2 tls
58 1.7.4.3 jdolecek struct drm_sysctl_def drm_def = DRM_SYSCTL_INIT();
59 1.7.4.3 jdolecek
60 1.7.4.2 tls static int
61 1.7.4.2 tls drm_init(void)
62 1.7.4.2 tls {
63 1.7.4.2 tls extern int linux_guarantee_initialized(void);
64 1.7.4.2 tls int error;
65 1.7.4.2 tls
66 1.7.4.2 tls error = linux_guarantee_initialized();
67 1.7.4.2 tls if (error)
68 1.7.4.2 tls return error;
69 1.7.4.2 tls
70 1.7.4.2 tls if (ISSET(boothowto, AB_DEBUG))
71 1.7.4.2 tls drm_debug = ~(unsigned int)0;
72 1.7.4.2 tls
73 1.7.4.2 tls spin_lock_init(&drm_minor_lock);
74 1.7.4.2 tls idr_init(&drm_minors_idr);
75 1.7.4.2 tls linux_mutex_init(&drm_global_mutex);
76 1.7.4.2 tls drm_connector_ida_init();
77 1.7.4.2 tls drm_global_init();
78 1.7.4.3 jdolecek drm_sysctl_init(&drm_def);
79 1.7.4.3 jdolecek drm_i2c_encoders_init();
80 1.7.4.2 tls
81 1.7.4.2 tls return 0;
82 1.7.4.2 tls }
83 1.7.4.2 tls
84 1.7.4.2 tls int drm_guarantee_initialized(void); /* XXX */
85 1.7.4.2 tls int
86 1.7.4.2 tls drm_guarantee_initialized(void)
87 1.7.4.2 tls {
88 1.7.4.2 tls #ifdef _MODULE
89 1.7.4.2 tls return 0;
90 1.7.4.2 tls #else
91 1.7.4.2 tls static ONCE_DECL(drm_init_once);
92 1.7.4.2 tls
93 1.7.4.2 tls return RUN_ONCE(&drm_init_once, &drm_init);
94 1.7.4.2 tls #endif
95 1.7.4.2 tls }
96 1.7.4.2 tls
97 1.7.4.2 tls static void
98 1.7.4.2 tls drm_fini(void)
99 1.7.4.2 tls {
100 1.7.4.2 tls
101 1.7.4.3 jdolecek drm_i2c_encoders_fini();
102 1.7.4.3 jdolecek drm_sysctl_fini(&drm_def);
103 1.7.4.2 tls drm_global_release();
104 1.7.4.2 tls drm_connector_ida_destroy();
105 1.7.4.2 tls linux_mutex_destroy(&drm_global_mutex);
106 1.7.4.2 tls idr_destroy(&drm_minors_idr);
107 1.7.4.2 tls spin_lock_destroy(&drm_minor_lock);
108 1.7.4.2 tls }
109 1.7.4.2 tls
110 1.7.4.2 tls static int
111 1.7.4.2 tls drmkms_modcmd(modcmd_t cmd, void *arg __unused)
112 1.7.4.2 tls {
113 1.7.4.2 tls #ifdef _MODULE
114 1.7.4.2 tls devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR;
115 1.7.4.2 tls #endif
116 1.7.4.2 tls int error;
117 1.7.4.2 tls
118 1.7.4.2 tls switch (cmd) {
119 1.7.4.2 tls case MODULE_CMD_INIT:
120 1.7.4.2 tls #ifdef _MODULE
121 1.7.4.2 tls error = drm_init();
122 1.7.4.2 tls #else
123 1.7.4.2 tls error = drm_guarantee_initialized();
124 1.7.4.2 tls #endif
125 1.7.4.2 tls if (error)
126 1.7.4.2 tls return error;
127 1.7.4.2 tls #ifdef _MODULE
128 1.7.4.2 tls error = devsw_attach("drm", NULL, &bmajor,
129 1.7.4.2 tls &drm_cdevsw, &cmajor);
130 1.7.4.2 tls if (error) {
131 1.7.4.2 tls aprint_error("drmkms: unable to attach devsw: %d\n",
132 1.7.4.2 tls error);
133 1.7.4.2 tls return error;
134 1.7.4.2 tls }
135 1.7.4.2 tls #endif
136 1.7.4.2 tls return 0;
137 1.7.4.2 tls
138 1.7.4.2 tls case MODULE_CMD_FINI:
139 1.7.4.2 tls #ifdef _MODULE
140 1.7.4.2 tls error = devsw_detach(NULL, &drm_cdevsw);
141 1.7.4.2 tls if (error)
142 1.7.4.2 tls return error;
143 1.7.4.2 tls #endif
144 1.7.4.2 tls drm_fini();
145 1.7.4.2 tls return 0;
146 1.7.4.2 tls
147 1.7.4.2 tls default:
148 1.7.4.2 tls return ENOTTY;
149 1.7.4.2 tls }
150 1.7.4.2 tls }
151