Home | History | Annotate | Line # | Download | only in bsd-core
      1 /* tdfx_drv.c -- tdfx driver -*- linux-c -*-
      2  * Created: Thu Oct  7 10:38:32 1999 by faith (at) precisioninsight.com
      3  */
      4 /*-
      5  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
      6  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
      7  * All Rights Reserved.
      8  *
      9  * Permission is hereby granted, free of charge, to any person obtaining a
     10  * copy of this software and associated documentation files (the "Software"),
     11  * to deal in the Software without restriction, including without limitation
     12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     13  * and/or sell copies of the Software, and to permit persons to whom the
     14  * Software is furnished to do so, subject to the following conditions:
     15  *
     16  * The above copyright notice and this permission notice (including the next
     17  * paragraph) shall be included in all copies or substantial portions of the
     18  * Software.
     19  *
     20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     23  * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
     24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     26  * DEALINGS IN THE SOFTWARE.
     27  *
     28  * Authors:
     29  *    Rickard E. (Rik) Faith <faith (at) valinux.com>
     30  *    Daryll Strauss <daryll (at) valinux.com>
     31  *    Gareth Hughes <gareth (at) valinux.com>
     32  *
     33  */
     34 
     35 #include "tdfx_drv.h"
     36 #include "drmP.h"
     37 #include "drm_pciids.h"
     38 
     39 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
     40 static drm_pci_id_list_t tdfx_pciidlist[] = {
     41 	tdfx_PCI_IDS
     42 };
     43 
     44 static void tdfx_configure(struct drm_device *dev)
     45 {
     46 	dev->driver->driver_features =
     47 	    DRIVER_USE_MTRR;
     48 
     49 	dev->driver->buf_priv_size	= 1; /* No dev_priv */
     50 
     51 	dev->driver->max_ioctl		= 0;
     52 
     53 	dev->driver->name		= DRIVER_NAME;
     54 	dev->driver->desc		= DRIVER_DESC;
     55 	dev->driver->date		= DRIVER_DATE;
     56 	dev->driver->major		= DRIVER_MAJOR;
     57 	dev->driver->minor		= DRIVER_MINOR;
     58 	dev->driver->patchlevel		= DRIVER_PATCHLEVEL;
     59 }
     60 
     61 #if defined(__FreeBSD__)
     62 
     63 static int
     64 tdfx_probe(device_t kdev)
     65 {
     66 	return drm_probe(kdev, tdfx_pciidlist);
     67 }
     68 
     69 static int
     70 tdfx_attach(device_t kdev)
     71 {
     72 	struct drm_device *dev = device_get_softc(kdev);
     73 
     74 	dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
     75 	    M_WAITOK | M_ZERO);
     76 
     77 	tdfx_configure(dev);
     78 
     79 	return drm_attach(kdev, tdfx_pciidlist);
     80 }
     81 
     82 static int
     83 tdfx_detach(device_t kdev)
     84 {
     85 	struct drm_device *dev = device_get_softc(kdev);
     86 	int ret;
     87 
     88 	ret = drm_detach(kdev);
     89 
     90 	free(dev->driver, DRM_MEM_DRIVER);
     91 
     92 	return ret;
     93 }
     94 
     95 static device_method_t tdfx_methods[] = {
     96 	/* Device interface */
     97 	DEVMETHOD(device_probe,		tdfx_probe),
     98 	DEVMETHOD(device_attach,	tdfx_attach),
     99 	DEVMETHOD(device_detach,	tdfx_detach),
    100 
    101 	{ 0, 0 }
    102 };
    103 
    104 static driver_t tdfx_driver = {
    105 	"drm",
    106 	tdfx_methods,
    107 	sizeof(struct drm_device)
    108 };
    109 
    110 extern devclass_t drm_devclass;
    111 #if __FreeBSD_version >= 700010
    112 DRIVER_MODULE(tdfx, vgapci, tdfx_driver, drm_devclass, 0, 0);
    113 #else
    114 DRIVER_MODULE(tdfx, pci, tdfx_driver, drm_devclass, 0, 0);
    115 #endif
    116 MODULE_DEPEND(tdfx, drm, 1, 1, 1);
    117 
    118 #elif   defined(__NetBSD__)
    119 
    120 static int
    121 tdfxdrm_probe(device_t parent, cfdata_t match, void *aux)
    122 {
    123 	struct pci_attach_args *pa = aux;
    124 
    125 	return drm_probe(pa, tdfx_pciidlist);
    126 }
    127 
    128 static void
    129 tdfxdrm_attach(device_t parent, device_t self, void *aux)
    130 {
    131 	struct pci_attach_args *pa = aux;
    132 	struct drm_device *dev = device_private(self);
    133 
    134 	dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
    135 	    M_WAITOK | M_ZERO);
    136 
    137 	tdfx_configure(dev);
    138 
    139 	drm_attach(self, pa, tdfx_pciidlist);
    140 }
    141 
    142 CFATTACH_DECL_NEW(tdfxdrm, sizeof(struct drm_device),
    143     tdfxdrm_probe, tdfxdrm_attach, drm_detach, NULL);
    144 
    145 MODULE(MODULE_CLASS_DRIVER, tdfxdrm, "drm");
    146 
    147 #ifdef _MODULE
    148 #include "ioconf.c"
    149 #endif
    150 
    151 static int
    152 tdfxdrm_modcmd(modcmd_t cmd, void *arg)
    153 {
    154 	int error = 0;
    155 
    156 	switch (cmd) {
    157 	case MODULE_CMD_INIT:
    158 #ifdef _MODULE
    159 		error = config_init_component(cfdriver_ioconf_tdfxdrm,
    160 		    cfattach_ioconf_tdfxdrm, cfdata_ioconf_tdfxdrm);
    161 #endif
    162 		break;
    163 	case MODULE_CMD_FINI:
    164 #ifdef _MODULE
    165 		error = config_fini_component(cfdriver_ioconf_tdfxdrm,
    166 		    cfattach_ioconf_tdfxdrm, cfdata_ioconf_tdfxdrm);
    167 #endif
    168 		break;
    169 	default:
    170 		return ENOTTY;
    171 	}
    172 
    173 	return error;
    174 }
    175 
    176 #endif
    177