1 /* savage_drv.c -- Savage DRI driver
4 * Copyright 2005 Eric Anholt
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
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.
26 * Eric Anholt <anholt@FreeBSD.org>
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
[] = {
40 static void savage_configure(struct drm_device
*dev
)
42 dev
->driver
->driver_features
=
43 DRIVER_USE_AGP
| DRIVER_USE_MTRR
| DRIVER_PCI_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__)
68 savage_probe(device_t kdev
)
70 return drm_probe(kdev
, savage_pciidlist
);
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
,
81 savage_configure(dev
);
83 return drm_attach(kdev
, savage_pciidlist
);
87 savage_detach(device_t kdev
)
89 struct drm_device
*dev
= device_get_softc(kdev
);
92 ret
= drm_detach(kdev
);
94 free(dev
->driver
, DRM_MEM_DRIVER
);
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
),
108 static driver_t savage_driver
= {
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);
118 DRIVER_MODULE(savage
, pci
, savage_driver
, drm_devclass
, 0, 0);
120 MODULE_DEPEND(savage
, drm
, 1, 1, 1);
122 #elif defined(__NetBSD__)
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
);
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
,
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
);
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",
164 .cf_fstate
= FSTATE_STAR
,
167 .cf_pspec
= &drmparent
,
173 savagedrm_modcmd(modcmd_t cmd
, void *arg
)
178 case MODULE_CMD_INIT
:
179 err
= config_cfdriver_attach(&savagedrm_cd
);
182 err
= config_cfattach_attach("savagedrm", &savagedrm_ca
);
184 config_cfdriver_detach(&savagedrm_cd
);
187 err
= config_cfdata_attach(savagedrm_cfdata
, 1);
189 config_cfattach_detach("savagedrm", &savagedrm_ca
);
190 config_cfdriver_detach(&savagedrm_cd
);
194 case MODULE_CMD_FINI
:
195 err
= config_cfdata_detach(savagedrm_cfdata
);
198 config_cfattach_detach("savagedrm", &savagedrm_ca
);
199 config_cfdriver_detach(&savagedrm_cd
);