1 /* savage_drv.c -- Savage DRI driver 2 */ 3 /*- 4 * Copyright 2005 Eric Anholt 5 * All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the next 15 * paragraph) shall be included in all copies or substantial portions of the 16 * Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 * ERIC ANHOLT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 22 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * 25 * Authors: 26 * Eric Anholt <anholt (at) FreeBSD.org> 27 */ 28 29 #include "drmP.h" 30 #include "drm.h" 31 #include "savage_drm.h" 32 #include "savage_drv.h" 33 #include "drm_pciids.h" 34 35 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */ 36 static drm_pci_id_list_t savage_pciidlist[] = { 37 savage_PCI_IDS 38 }; 39 40 static void savage_configure(struct drm_device *dev) 41 { 42 dev->driver->driver_features = 43 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA | 44 DRIVER_HAVE_DMA; 45 46 dev->driver->buf_priv_size = sizeof(drm_savage_buf_priv_t); 47 dev->driver->load = savage_driver_load; 48 dev->driver->firstopen = savage_driver_firstopen; 49 dev->driver->lastclose = savage_driver_lastclose; 50 dev->driver->unload = savage_driver_unload; 51 dev->driver->reclaim_buffers_locked = savage_reclaim_buffers; 52 dev->driver->dma_ioctl = savage_bci_buffers; 53 54 dev->driver->ioctls = savage_ioctls; 55 dev->driver->max_ioctl = savage_max_ioctl; 56 57 dev->driver->name = DRIVER_NAME; 58 dev->driver->desc = DRIVER_DESC; 59 dev->driver->date = DRIVER_DATE; 60 dev->driver->major = DRIVER_MAJOR; 61 dev->driver->minor = DRIVER_MINOR; 62 dev->driver->patchlevel = DRIVER_PATCHLEVEL; 63 } 64 65 #if defined(__FreeBSD__) 66 67 static int 68 savage_probe(device_t kdev) 69 { 70 return drm_probe(kdev, savage_pciidlist); 71 } 72 73 static int 74 savage_attach(device_t kdev) 75 { 76 struct drm_device *dev = device_get_softc(kdev); 77 78 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, 79 M_WAITOK | M_ZERO); 80 81 savage_configure(dev); 82 83 return drm_attach(kdev, savage_pciidlist); 84 } 85 86 static int 87 savage_detach(device_t kdev) 88 { 89 struct drm_device *dev = device_get_softc(kdev); 90 int ret; 91 92 ret = drm_detach(kdev); 93 94 free(dev->driver, DRM_MEM_DRIVER); 95 96 return ret; 97 } 98 99 static device_method_t savage_methods[] = { 100 /* Device interface */ 101 DEVMETHOD(device_probe, savage_probe), 102 DEVMETHOD(device_attach, savage_attach), 103 DEVMETHOD(device_detach, savage_detach), 104 105 { 0, 0 } 106 }; 107 108 static driver_t savage_driver = { 109 "drm", 110 savage_methods, 111 sizeof(struct drm_device) 112 }; 113 114 extern devclass_t drm_devclass; 115 #if __FreeBSD_version >= 700010 116 DRIVER_MODULE(savage, vgapci, savage_driver, drm_devclass, 0, 0); 117 #else 118 DRIVER_MODULE(savage, pci, savage_driver, drm_devclass, 0, 0); 119 #endif 120 MODULE_DEPEND(savage, drm, 1, 1, 1); 121 122 #elif defined(__NetBSD__) 123 124 static int 125 savagedrm_probe(device_t parent, cfdata_t match, void *aux) 126 { 127 struct pci_attach_args *pa = aux; 128 129 return drm_probe(pa, savage_pciidlist); 130 } 131 132 static void 133 savagedrm_attach(device_t parent, device_t self, void *aux) 134 { 135 struct pci_attach_args *pa = aux; 136 struct drm_device *dev = device_private(self); 137 138 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER, 139 M_WAITOK | M_ZERO); 140 141 savage_configure(dev); 142 143 drm_attach(self, pa, savage_pciidlist); 144 } 145 146 CFATTACH_DECL_NEW(savagedrm, sizeof(struct drm_device), 147 savagedrm_probe, savagedrm_attach, drm_detach, NULL); 148 149 MODULE(MODULE_CLASS_DRIVER, savagedrm, "drm"); 150 151 #ifdef _MODULE 152 #include "ioconf.c" 153 #endif 154 155 static int 156 savagedrm_modcmd(modcmd_t cmd, void *arg) 157 { 158 int error = 0; 159 160 switch (cmd) { 161 case MODULE_CMD_INIT: 162 #ifdef _MODULE 163 error = config_init_component(cfdriver_ioconf_savagedrm, 164 cfattach_ioconf_savagedrm, cfdata_ioconf_savagedrm); 165 #endif 166 break; 167 case MODULE_CMD_FINI: 168 #ifdef _MODULE 169 error = config_fini_component(cfdriver_ioconf_savagedrm, 170 cfattach_ioconf_savagedrm, cfdata_ioconf_savagedrm); 171 #endif 172 break; 173 default: 174 return ENOTTY; 175 } 176 177 return error; 178 } 179 180 #endif 181