No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / bsd / drm / dist / bsd-core / savage_drv.c
blob5ac5d26e046a6ade5233b1ddb82b68b51dec7b6f
1 /* savage_drv.c -- Savage DRI driver
2 */
3 /*-
4 * Copyright 2005 Eric Anholt
5 * All Rights Reserved.
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:
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.
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.
25 * Authors:
26 * Eric Anholt <anholt@FreeBSD.org>
29 #include "drmP.h"
30 #include "drm.h"
31 #include "savage_drm.h"
32 #include "savage_drv.h"
33 #include "drm_pciids.h"
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
40 static void savage_configure(struct drm_device *dev)
42 dev->driver->driver_features =
43 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_PCI_DMA |
44 DRIVER_HAVE_DMA;
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;
54 dev->driver->ioctls = savage_ioctls;
55 dev->driver->max_ioctl = savage_max_ioctl;
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;
65 #if defined(__FreeBSD__)
67 static int
68 savage_probe(device_t kdev)
70 return drm_probe(kdev, savage_pciidlist);
73 static int
74 savage_attach(device_t kdev)
76 struct drm_device *dev = device_get_softc(kdev);
78 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
79 M_WAITOK | M_ZERO);
81 savage_configure(dev);
83 return drm_attach(kdev, savage_pciidlist);
86 static int
87 savage_detach(device_t kdev)
89 struct drm_device *dev = device_get_softc(kdev);
90 int ret;
92 ret = drm_detach(kdev);
94 free(dev->driver, DRM_MEM_DRIVER);
96 return ret;
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),
105 { 0, 0 }
108 static driver_t savage_driver = {
109 "drm",
110 savage_methods,
111 sizeof(struct drm_device)
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);
122 #elif defined(__NetBSD__)
124 static int
125 savagedrm_probe(device_t parent, cfdata_t match, void *aux)
127 struct pci_attach_args *pa = aux;
129 return drm_probe(pa, savage_pciidlist);
132 static void
133 savagedrm_attach(device_t parent, device_t self, void *aux)
135 struct pci_attach_args *pa = aux;
136 struct drm_device *dev = device_private(self);
138 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
139 M_WAITOK | M_ZERO);
141 savage_configure(dev);
143 drm_attach(self, pa, savage_pciidlist);
146 CFATTACH_DECL_NEW(savagedrm, sizeof(struct drm_device),
147 savagedrm_probe, savagedrm_attach, drm_detach, NULL);
149 #ifdef _MODULE
151 MODULE(MODULE_CLASS_DRIVER, savagedrm, NULL);
153 CFDRIVER_DECL(savagedrm, DV_DULL, NULL);
154 extern struct cfattach savagedrm_ca;
155 static int drmloc[] = { -1 };
156 static struct cfparent drmparent = {
157 "drm", "vga", DVUNIT_ANY
159 static struct cfdata savagedrm_cfdata[] = {
161 .cf_name = "savagedrm",
162 .cf_atname = "savagedrm",
163 .cf_unit = 0,
164 .cf_fstate = FSTATE_STAR,
165 .cf_loc = drmloc,
166 .cf_flags = 0,
167 .cf_pspec = &drmparent,
169 { NULL }
172 static int
173 savagedrm_modcmd(modcmd_t cmd, void *arg)
175 int err;
177 switch (cmd) {
178 case MODULE_CMD_INIT:
179 err = config_cfdriver_attach(&savagedrm_cd);
180 if (err)
181 return err;
182 err = config_cfattach_attach("savagedrm", &savagedrm_ca);
183 if (err) {
184 config_cfdriver_detach(&savagedrm_cd);
185 return err;
187 err = config_cfdata_attach(savagedrm_cfdata, 1);
188 if (err) {
189 config_cfattach_detach("savagedrm", &savagedrm_ca);
190 config_cfdriver_detach(&savagedrm_cd);
191 return err;
193 return 0;
194 case MODULE_CMD_FINI:
195 err = config_cfdata_detach(savagedrm_cfdata);
196 if (err)
197 return err;
198 config_cfattach_detach("savagedrm", &savagedrm_ca);
199 config_cfdriver_detach(&savagedrm_cd);
200 return 0;
201 default:
202 return ENOTTY;
205 #endif /* _MODULE */
207 #endif