drm_module.c revision 1.7.4.2 1 1.7.4.2 tls /* $NetBSD: drm_module.c,v 1.7.4.2 2014/08/20 00:04:20 tls 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.2 2014/08/20 00:04:20 tls Exp $");
34 1.7.4.2 tls
35 1.7.4.2 tls #include <sys/types.h>
36 1.7.4.2 tls #include <sys/device.h>
37 1.7.4.2 tls #include <sys/module.h>
38 1.7.4.2 tls #ifndef _MODULE
39 1.7.4.2 tls #include <sys/once.h>
40 1.7.4.2 tls #endif
41 1.7.4.2 tls #include <sys/reboot.h>
42 1.7.4.2 tls #include <sys/systm.h>
43 1.7.4.2 tls
44 1.7.4.2 tls #include <linux/mutex.h>
45 1.7.4.2 tls
46 1.7.4.2 tls #include <drm/drmP.h>
47 1.7.4.2 tls
48 1.7.4.2 tls /*
49 1.7.4.2 tls * XXX I2C stuff should be moved to a separate drmkms_i2c module.
50 1.7.4.2 tls */
51 1.7.4.2 tls MODULE(MODULE_CLASS_DRIVER, drmkms, "iic,drmkms_linux");
52 1.7.4.2 tls
53 1.7.4.2 tls #ifdef _MODULE
54 1.7.4.2 tls #include "ioconf.c"
55 1.7.4.2 tls #endif
56 1.7.4.2 tls
57 1.7.4.2 tls struct mutex drm_global_mutex;
58 1.7.4.2 tls
59 1.7.4.2 tls static int
60 1.7.4.2 tls drm_init(void)
61 1.7.4.2 tls {
62 1.7.4.2 tls extern int linux_guarantee_initialized(void);
63 1.7.4.2 tls int error;
64 1.7.4.2 tls
65 1.7.4.2 tls error = linux_guarantee_initialized();
66 1.7.4.2 tls if (error)
67 1.7.4.2 tls return error;
68 1.7.4.2 tls
69 1.7.4.2 tls if (ISSET(boothowto, AB_DEBUG))
70 1.7.4.2 tls drm_debug = ~(unsigned int)0;
71 1.7.4.2 tls
72 1.7.4.2 tls spin_lock_init(&drm_minor_lock);
73 1.7.4.2 tls idr_init(&drm_minors_idr);
74 1.7.4.2 tls linux_mutex_init(&drm_global_mutex);
75 1.7.4.2 tls drm_connector_ida_init();
76 1.7.4.2 tls drm_global_init();
77 1.7.4.2 tls
78 1.7.4.2 tls return 0;
79 1.7.4.2 tls }
80 1.7.4.2 tls
81 1.7.4.2 tls int drm_guarantee_initialized(void); /* XXX */
82 1.7.4.2 tls int
83 1.7.4.2 tls drm_guarantee_initialized(void)
84 1.7.4.2 tls {
85 1.7.4.2 tls #ifdef _MODULE
86 1.7.4.2 tls return 0;
87 1.7.4.2 tls #else
88 1.7.4.2 tls static ONCE_DECL(drm_init_once);
89 1.7.4.2 tls
90 1.7.4.2 tls return RUN_ONCE(&drm_init_once, &drm_init);
91 1.7.4.2 tls #endif
92 1.7.4.2 tls }
93 1.7.4.2 tls
94 1.7.4.2 tls static void
95 1.7.4.2 tls drm_fini(void)
96 1.7.4.2 tls {
97 1.7.4.2 tls
98 1.7.4.2 tls drm_global_release();
99 1.7.4.2 tls drm_connector_ida_destroy();
100 1.7.4.2 tls linux_mutex_destroy(&drm_global_mutex);
101 1.7.4.2 tls idr_destroy(&drm_minors_idr);
102 1.7.4.2 tls spin_lock_destroy(&drm_minor_lock);
103 1.7.4.2 tls }
104 1.7.4.2 tls
105 1.7.4.2 tls static int
106 1.7.4.2 tls drmkms_modcmd(modcmd_t cmd, void *arg __unused)
107 1.7.4.2 tls {
108 1.7.4.2 tls #ifdef _MODULE
109 1.7.4.2 tls devmajor_t bmajor = NODEVMAJOR, cmajor = NODEVMAJOR;
110 1.7.4.2 tls #endif
111 1.7.4.2 tls int error;
112 1.7.4.2 tls
113 1.7.4.2 tls switch (cmd) {
114 1.7.4.2 tls case MODULE_CMD_INIT:
115 1.7.4.2 tls #ifdef _MODULE
116 1.7.4.2 tls error = drm_init();
117 1.7.4.2 tls #else
118 1.7.4.2 tls error = drm_guarantee_initialized();
119 1.7.4.2 tls #endif
120 1.7.4.2 tls if (error)
121 1.7.4.2 tls return error;
122 1.7.4.2 tls #ifdef _MODULE
123 1.7.4.2 tls error = devsw_attach("drm", NULL, &bmajor,
124 1.7.4.2 tls &drm_cdevsw, &cmajor);
125 1.7.4.2 tls if (error) {
126 1.7.4.2 tls aprint_error("drmkms: unable to attach devsw: %d\n",
127 1.7.4.2 tls error);
128 1.7.4.2 tls return error;
129 1.7.4.2 tls }
130 1.7.4.2 tls #endif
131 1.7.4.2 tls return 0;
132 1.7.4.2 tls
133 1.7.4.2 tls case MODULE_CMD_FINI:
134 1.7.4.2 tls #ifdef _MODULE
135 1.7.4.2 tls error = devsw_detach(NULL, &drm_cdevsw);
136 1.7.4.2 tls if (error)
137 1.7.4.2 tls return error;
138 1.7.4.2 tls #endif
139 1.7.4.2 tls drm_fini();
140 1.7.4.2 tls return 0;
141 1.7.4.2 tls
142 1.7.4.2 tls default:
143 1.7.4.2 tls return ENOTTY;
144 1.7.4.2 tls }
145 1.7.4.2 tls }
146