Home | History | Annotate | Line # | Download | only in nouveau
nouveau_module.c revision 1.4.16.1
      1 /*	$NetBSD: nouveau_module.c,v 1.4.16.1 2018/09/06 06:56:37 pgoyette 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.16.1 2018/09/06 06:56:37 pgoyette 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 static int
     53 nouveau_init(void)
     54 {
     55 
     56 	nvkm_devices_init();
     57 	drm_sysctl_init(&nouveau_def);
     58 
     59 	return 0;
     60 }
     61 
     62 static void
     63 nouveau_fini(void)
     64 {
     65 
     66 	drm_sysctl_fini(&nouveau_def);
     67 	nvkm_devices_fini();
     68 }
     69 
     70 static int
     71 nouveau_modcmd(modcmd_t cmd, void *arg __unused)
     72 {
     73 	int error;
     74 
     75 	switch (cmd) {
     76 	case MODULE_CMD_INIT:
     77 		error = nouveau_init();
     78 		if (error) {
     79 			aprint_error("nouveau: failed to initialize: %d\n",
     80 			    error);
     81 			return error;
     82 		}
     83 #ifdef _MODULE
     84 		error = config_init_component(cfdriver_ioconf_nouveau,
     85 		    cfattach_ioconf_nouveau, cfdata_ioconf_nouveau);
     86 		if (error) {
     87 			aprint_error("nouveau: failed to init component"
     88 			    ": %d\n", error);
     89 			nouveau_fini();
     90 			return error;
     91 		}
     92 #endif
     93 		return 0;
     94 
     95 	case MODULE_CMD_FINI:
     96 #ifdef _MODULE
     97 		error = config_fini_component(cfdriver_ioconf_nouveau,
     98 		    cfattach_ioconf_nouveau, cfdata_ioconf_nouveau);
     99 		if (error) {
    100 			aprint_error("nouveau: failed to fini component"
    101 			    ": %d\n", error);
    102 			return error;
    103 		}
    104 #endif
    105 		nouveau_fini();
    106 		return 0;
    107 
    108 	default:
    109 		return ENOTTY;
    110 	}
    111 }
    112