Home | History | Annotate | Line # | Download | only in bsd-core
      1 /* r128_drv.c -- ATI Rage 128 driver -*- linux-c -*-
      2  * Created: Mon Dec 13 09:47:27 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  * VA LINUX SYSTEMS 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
     26  * OTHER DEALINGS IN THE SOFTWARE.
     27  *
     28  * Authors:
     29  *    Rickard E. (Rik) Faith <faith (at) valinux.com>
     30  *    Gareth Hughes <gareth (at) valinux.com>
     31  *
     32  */
     33 
     34 #include "drmP.h"
     35 #include "drm.h"
     36 #include "r128_drm.h"
     37 #include "r128_drv.h"
     38 #include "drm_pciids.h"
     39 
     40 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
     41 static drm_pci_id_list_t r128_pciidlist[] = {
     42 	r128_PCI_IDS
     43 };
     44 
     45 int r128_driver_load(struct drm_device * dev, unsigned long flags)
     46 {
     47 	return drm_vblank_init(dev, 1);
     48 }
     49 
     50 static void r128_configure(struct drm_device *dev)
     51 {
     52 	dev->driver->driver_features =
     53 	    DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
     54 	    DRIVER_SG | DRIVER_HAVE_DMA | DRIVER_HAVE_IRQ;
     55 
     56 	dev->driver->buf_priv_size	= sizeof(drm_r128_buf_priv_t);
     57 	dev->driver->load		= r128_driver_load;
     58 	dev->driver->preclose		= r128_driver_preclose;
     59 	dev->driver->lastclose		= r128_driver_lastclose;
     60 	dev->driver->get_vblank_counter	= r128_get_vblank_counter;
     61 	dev->driver->enable_vblank	= r128_enable_vblank;
     62 	dev->driver->disable_vblank	= r128_disable_vblank;
     63 	dev->driver->irq_preinstall	= r128_driver_irq_preinstall;
     64 	dev->driver->irq_postinstall	= r128_driver_irq_postinstall;
     65 	dev->driver->irq_uninstall	= r128_driver_irq_uninstall;
     66 	dev->driver->irq_handler	= r128_driver_irq_handler;
     67 	dev->driver->dma_ioctl		= r128_cce_buffers;
     68 
     69 	dev->driver->ioctls		= r128_ioctls;
     70 	dev->driver->max_ioctl		= r128_max_ioctl;
     71 
     72 	dev->driver->name		= DRIVER_NAME;
     73 	dev->driver->desc		= DRIVER_DESC;
     74 	dev->driver->date		= DRIVER_DATE;
     75 	dev->driver->major		= DRIVER_MAJOR;
     76 	dev->driver->minor		= DRIVER_MINOR;
     77 	dev->driver->patchlevel		= DRIVER_PATCHLEVEL;
     78 }
     79 
     80 #if defined(__FreeBSD__)
     81 
     82 static int
     83 r128_probe(device_t kdev)
     84 {
     85 	return drm_probe(kdev, r128_pciidlist);
     86 }
     87 
     88 static int
     89 r128_attach(device_t kdev)
     90 {
     91 	struct drm_device *dev = device_get_softc(kdev);
     92 
     93 	dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
     94 	    M_WAITOK | M_ZERO);
     95 
     96 	r128_configure(dev);
     97 
     98 	return drm_attach(kdev, r128_pciidlist);
     99 }
    100 
    101 static int
    102 r128_detach(device_t kdev)
    103 {
    104 	struct drm_device *dev = device_get_softc(kdev);
    105 	int ret;
    106 
    107 	ret = drm_detach(kdev);
    108 
    109 	free(dev->driver, DRM_MEM_DRIVER);
    110 
    111 	return ret;
    112 }
    113 
    114 static device_method_t r128_methods[] = {
    115 	/* Device interface */
    116 	DEVMETHOD(device_probe,		r128_probe),
    117 	DEVMETHOD(device_attach,	r128_attach),
    118 	DEVMETHOD(device_detach,	r128_detach),
    119 
    120 	{ 0, 0 }
    121 };
    122 
    123 static driver_t r128_driver = {
    124 	"drm",
    125 	r128_methods,
    126 	sizeof(struct drm_device)
    127 };
    128 
    129 extern devclass_t drm_devclass;
    130 #if __FreeBSD_version >= 700010
    131 DRIVER_MODULE(r128, vgapci, r128_driver, drm_devclass, 0, 0);
    132 #else
    133 DRIVER_MODULE(r128, pci, r128_driver, drm_devclass, 0, 0);
    134 #endif
    135 MODULE_DEPEND(r128, drm, 1, 1, 1);
    136 
    137 #elif   defined(__NetBSD__)
    138 
    139 static int
    140 r128drm_probe(device_t parent, cfdata_t match, void *aux)
    141 {
    142 	struct pci_attach_args *pa = aux;
    143 
    144 	return drm_probe(pa, r128_pciidlist);
    145 }
    146 
    147 static void
    148 r128drm_attach(device_t parent, device_t self, void *aux)
    149 {
    150 	struct pci_attach_args *pa = aux;
    151 	struct drm_device *dev = device_private(self);
    152 
    153 	dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
    154 	    M_WAITOK | M_ZERO);
    155 
    156 	r128_configure(dev);
    157 
    158 	drm_attach(self, pa, r128_pciidlist);
    159 }
    160 
    161 CFATTACH_DECL_NEW(r128drm, sizeof(struct drm_device),
    162     r128drm_probe, r128drm_attach, drm_detach, NULL);
    163 
    164 MODULE(MODULE_CLASS_DRIVER, r128drm, "drm,ati_pcigart");
    165 
    166 #ifdef _MODULE
    167 #include "ioconf.c"
    168 #endif
    169 
    170 static int
    171 r128drm_modcmd(modcmd_t cmd, void *arg)
    172 {
    173 	int error = 0;
    174 
    175 	switch (cmd) {
    176 	case MODULE_CMD_INIT:
    177 #ifdef _MODULE
    178 		error = config_init_component(cfdriver_ioconf_r128drm,
    179 		    cfattach_ioconf_r128drm, cfdata_ioconf_r128drm);
    180 #endif
    181 		break;
    182 	case MODULE_CMD_FINI:
    183 #ifdef _MODULE
    184 		error = config_fini_component(cfdriver_ioconf_r128drm,
    185 		    cfattach_ioconf_r128drm, cfdata_ioconf_r128drm);
    186 #endif
    187 		break;
    188 	default:
    189 		return ENOTTY;
    190 	}
    191 
    192 	return error;
    193 }
    194 
    195 #endif
    196