Home | History | Annotate | Line # | Download | only in nouveau
nouveau_module.c revision 1.5
      1 /*	$NetBSD: nouveau_module.c,v 1.5 2018/08/27 06:41:25 riastradh 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.5 2018/08/27 06:41:25 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 #include <drm/drm_sysctl.h>
     41 
     42 #include <core/device.h>
     43 
     44 MODULE(MODULE_CLASS_DRIVER, nouveau, "drmkms"); /* XXX drmkms_i2c, drmkms_ttm */
     45 
     46 #ifdef _MODULE
     47 #include "ioconf.c"
     48 #endif
     49 
     50 struct drm_sysctl_def nouveau_def = DRM_SYSCTL_INIT();
     51 
     52 extern struct drm_driver *const nouveau_drm_driver; /* XXX */
     53 
     54 static int
     55 nouveau_init(void)
     56 {
     57 	nouveau_devices_init();
     58 	drm_sysctl_init(&nouveau_def);
     59 
     60 	return 0;
     61 }
     62 
     63 static void
     64 nouveau_fini(void)
     65 {
     66 
     67 	drm_sysctl_fini(&nouveau_def);
     68 	nouveau_devices_fini();
     69 }
     70 
     71 static int
     72 nouveau_modcmd(modcmd_t cmd, void *arg __unused)
     73 {
     74 	int error;
     75 
     76 	switch (cmd) {
     77 	case MODULE_CMD_INIT:
     78 		error = nouveau_init();
     79 		if (error) {
     80 			aprint_error("nouveau: failed to initialize: %d\n",
     81 			    error);
     82 			return error;
     83 		}
     84 #ifdef _MODULE
     85 		error = config_init_component(cfdriver_ioconf_nouveau,
     86 		    cfattach_ioconf_nouveau, cfdata_ioconf_nouveau);
     87 		if (error) {
     88 			aprint_error("nouveau: failed to init component"
     89 			    ": %d\n", error);
     90 			nouveau_fini();
     91 			return error;
     92 		}
     93 #endif
     94 		return 0;
     95 
     96 	case MODULE_CMD_FINI:
     97 #ifdef _MODULE
     98 		error = config_fini_component(cfdriver_ioconf_nouveau,
     99 		    cfattach_ioconf_nouveau, cfdata_ioconf_nouveau);
    100 		if (error) {
    101 			aprint_error("nouveau: failed to fini component"
    102 			    ": %d\n", error);
    103 			return error;
    104 		}
    105 #endif
    106 		nouveau_fini();
    107 		return 0;
    108 
    109 	default:
    110 		return ENOTTY;
    111 	}
    112 }
    113