radeon_module.c revision 1.2.6.3 1 1.2.6.2 tls /* $NetBSD: radeon_module.c,v 1.2.6.3 2017/12/03 11:38:00 jdolecek Exp $ */
2 1.2.6.2 tls
3 1.2.6.2 tls /*-
4 1.2.6.2 tls * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 1.2.6.2 tls * All rights reserved.
6 1.2.6.2 tls *
7 1.2.6.2 tls * This code is derived from software contributed to The NetBSD Foundation
8 1.2.6.2 tls * by Taylor R. Campbell.
9 1.2.6.2 tls *
10 1.2.6.2 tls * Redistribution and use in source and binary forms, with or without
11 1.2.6.2 tls * modification, are permitted provided that the following conditions
12 1.2.6.2 tls * are met:
13 1.2.6.2 tls * 1. Redistributions of source code must retain the above copyright
14 1.2.6.2 tls * notice, this list of conditions and the following disclaimer.
15 1.2.6.2 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.6.2 tls * notice, this list of conditions and the following disclaimer in the
17 1.2.6.2 tls * documentation and/or other materials provided with the distribution.
18 1.2.6.2 tls *
19 1.2.6.2 tls * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2.6.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2.6.2 tls * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2.6.2 tls * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2.6.2 tls * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2.6.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2.6.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2.6.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2.6.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2.6.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2.6.2 tls * POSSIBILITY OF SUCH DAMAGE.
30 1.2.6.2 tls */
31 1.2.6.2 tls
32 1.2.6.2 tls #include <sys/cdefs.h>
33 1.2.6.2 tls __KERNEL_RCSID(0, "$NetBSD: radeon_module.c,v 1.2.6.3 2017/12/03 11:38:00 jdolecek Exp $");
34 1.2.6.2 tls
35 1.2.6.2 tls #include <sys/types.h>
36 1.2.6.2 tls #include <sys/module.h>
37 1.2.6.2 tls #ifndef _MODULE
38 1.2.6.2 tls #include <sys/once.h>
39 1.2.6.2 tls #endif
40 1.2.6.2 tls #include <sys/systm.h>
41 1.2.6.2 tls
42 1.2.6.2 tls #include <drm/drmP.h>
43 1.2.6.3 jdolecek #include <drm/drm_sysctl.h>
44 1.2.6.2 tls
45 1.2.6.2 tls #include "radeon_drv.h"
46 1.2.6.2 tls
47 1.2.6.2 tls MODULE(MODULE_CLASS_DRIVER, radeon, "drmkms,drmkms_pci"); /* XXX drmkms_i2c, drmkms_ttm */
48 1.2.6.2 tls
49 1.2.6.2 tls #ifdef _MODULE
50 1.2.6.2 tls #include "ioconf.c"
51 1.2.6.2 tls #endif
52 1.2.6.2 tls
53 1.2.6.2 tls /* XXX Kludge to get these from radeon_drv.c. */
54 1.2.6.2 tls extern struct drm_driver *const radeon_drm_driver;
55 1.2.6.2 tls extern int radeon_max_kms_ioctl;
56 1.2.6.2 tls
57 1.2.6.3 jdolecek struct drm_sysctl_def radeon_def = DRM_SYSCTL_INIT();
58 1.2.6.3 jdolecek
59 1.2.6.2 tls static int
60 1.2.6.2 tls radeon_init(void)
61 1.2.6.2 tls {
62 1.2.6.2 tls extern int drm_guarantee_initialized(void);
63 1.2.6.2 tls int error;
64 1.2.6.2 tls
65 1.2.6.2 tls error = drm_guarantee_initialized();
66 1.2.6.2 tls if (error)
67 1.2.6.2 tls return error;
68 1.2.6.2 tls
69 1.2.6.2 tls radeon_drm_driver->num_ioctls = radeon_max_kms_ioctl;
70 1.2.6.2 tls radeon_drm_driver->driver_features |= DRIVER_MODESET;
71 1.2.6.2 tls
72 1.2.6.2 tls error = drm_pci_init(radeon_drm_driver, NULL);
73 1.2.6.2 tls if (error) {
74 1.2.6.2 tls aprint_error("radeon: failed to init pci: %d\n",
75 1.2.6.2 tls error);
76 1.2.6.2 tls return error;
77 1.2.6.2 tls }
78 1.2.6.3 jdolecek drm_sysctl_init(&radeon_def);
79 1.2.6.2 tls
80 1.2.6.2 tls return 0;
81 1.2.6.2 tls }
82 1.2.6.2 tls
83 1.2.6.2 tls int radeon_guarantee_initialized(void); /* XXX */
84 1.2.6.2 tls int
85 1.2.6.2 tls radeon_guarantee_initialized(void)
86 1.2.6.2 tls {
87 1.2.6.2 tls #ifdef _MODULE
88 1.2.6.2 tls return 0;
89 1.2.6.2 tls #else
90 1.2.6.2 tls static ONCE_DECL(radeon_init_once);
91 1.2.6.2 tls
92 1.2.6.2 tls return RUN_ONCE(&radeon_init_once, &radeon_init);
93 1.2.6.2 tls #endif
94 1.2.6.2 tls }
95 1.2.6.2 tls
96 1.2.6.2 tls static void
97 1.2.6.2 tls radeon_fini(void)
98 1.2.6.2 tls {
99 1.2.6.3 jdolecek drm_sysctl_fini(&radeon_def);
100 1.2.6.2 tls drm_pci_exit(radeon_drm_driver, NULL);
101 1.2.6.2 tls }
102 1.2.6.2 tls
103 1.2.6.2 tls static int
104 1.2.6.2 tls radeon_modcmd(modcmd_t cmd, void *arg __unused)
105 1.2.6.2 tls {
106 1.2.6.2 tls int error;
107 1.2.6.2 tls
108 1.2.6.2 tls switch (cmd) {
109 1.2.6.2 tls case MODULE_CMD_INIT:
110 1.2.6.2 tls /* XXX Kludge it up... Must happen before attachment. */
111 1.2.6.2 tls #ifdef _MODULE
112 1.2.6.2 tls error = radeon_init();
113 1.2.6.2 tls #else
114 1.2.6.2 tls error = radeon_guarantee_initialized();
115 1.2.6.2 tls #endif
116 1.2.6.2 tls if (error) {
117 1.2.6.2 tls aprint_error("radeon: failed to initialize: %d\n",
118 1.2.6.2 tls error);
119 1.2.6.2 tls return error;
120 1.2.6.2 tls }
121 1.2.6.2 tls #ifdef _MODULE
122 1.2.6.2 tls error = config_init_component(cfdriver_ioconf_radeon,
123 1.2.6.2 tls cfattach_ioconf_radeon, cfdata_ioconf_radeon);
124 1.2.6.2 tls if (error) {
125 1.2.6.2 tls aprint_error("radeon: failed to init component"
126 1.2.6.2 tls ": %d\n", error);
127 1.2.6.2 tls radeon_fini();
128 1.2.6.2 tls return error;
129 1.2.6.2 tls }
130 1.2.6.2 tls #endif
131 1.2.6.2 tls return 0;
132 1.2.6.2 tls
133 1.2.6.2 tls case MODULE_CMD_FINI:
134 1.2.6.2 tls #ifdef _MODULE
135 1.2.6.2 tls error = config_fini_component(cfdriver_ioconf_radeon,
136 1.2.6.2 tls cfattach_ioconf_radeon, cfdata_ioconf_radeon);
137 1.2.6.2 tls if (error) {
138 1.2.6.2 tls aprint_error("radeon: failed to fini component"
139 1.2.6.2 tls ": %d\n", error);
140 1.2.6.2 tls return error;
141 1.2.6.2 tls }
142 1.2.6.2 tls #endif
143 1.2.6.2 tls radeon_fini();
144 1.2.6.2 tls return 0;
145 1.2.6.2 tls
146 1.2.6.2 tls default:
147 1.2.6.2 tls return ENOTTY;
148 1.2.6.2 tls }
149 1.2.6.2 tls }
150