1/* $NetBSD: nouveau_module.c,v 1.4 2015/10/17 12:02:44 jmcneill 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.4 2015/10/17 12:02:44 jmcneill Exp $");
34
35#include <sys/types.h>
36#include <sys/module.h>
37#include <sys/systm.h>
38
39#include <drm/drmP.h>
40#include <drm/drm_sysctl.h>
41
42#include <core/object.h>
43#include <engine/device.h>
44
45MODULE(MODULE_CLASS_DRIVER, nouveau, "drmkms"); /* XXX drmkms_i2c, drmkms_ttm */
46
47#ifdef _MODULE
48#include "ioconf.c"
49#endif
50
51struct drm_sysctl_def nouveau_def = DRM_SYSCTL_INIT();
52
53extern struct drm_driver *const nouveau_drm_driver; /* XXX */
54
55static int
56nouveau_init(void)
57{
58 nouveau_objects_init();
59 nouveau_devices_init();
60 drm_sysctl_init(&nouveau_def);
61
62 return 0;
63}
64
65static void
66nouveau_fini(void)
67{
68
69 drm_sysctl_fini(&nouveau_def);
70 nouveau_devices_fini();
71 nouveau_objects_fini();
72}
73
74static int
75nouveau_modcmd(modcmd_t cmd, void *arg __unused)
76{
77 int error;
78
79 switch (cmd) {
80 case MODULE_CMD_INIT:
81 error = nouveau_init();
82 if (error) {
83 aprint_error("nouveau: failed to initialize: %d\n",
84 error);
85 return error;
86 }
87#ifdef _MODULE
88 error = config_init_component(cfdriver_ioconf_nouveau,
89 cfattach_ioconf_nouveau, cfdata_ioconf_nouveau);
90 if (error) {
91 aprint_error("nouveau: failed to init component"
92 ": %d\n", error);
93 nouveau_fini();
94 return error;
95 }
96#endif
97 return 0;
98
99 case MODULE_CMD_FINI:
100#ifdef _MODULE
101 error = config_fini_component(cfdriver_ioconf_nouveau,
102 cfattach_ioconf_nouveau, cfdata_ioconf_nouveau);
103 if (error) {
104 aprint_error("nouveau: failed to fini component"
105 ": %d\n", error);
106 return error;
107 }
108#endif
109 nouveau_fini();
110 return 0;
111
112 default:
113 return ENOTTY;
114 }
115}
116