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