Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / external / bsd / drm / dist / bsd-core / via_drv.c
blob1d8dd41472d35c0c8d64848d42820bd4baf88749
1 /* via_drv.c -- VIA unichrome driver -*- linux-c -*-
2 * Created: Fri Aug 12 2005 by anholt@FreeBSD.org
3 */
4 /*-
5 * Copyright 2005 Eric Anholt
6 * All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * ERIC ANHOLT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
23 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Authors:
27 * Eric Anholt <anholt@FreeBSD.org>
31 #include "drmP.h"
32 #include "drm.h"
33 #include "via_drm.h"
34 #include "via_drv.h"
35 #include "drm_pciids.h"
37 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
38 static drm_pci_id_list_t via_pciidlist[] = {
39 viadrv_PCI_IDS
42 static void via_configure(struct drm_device *dev)
44 dev->driver->driver_features =
45 DRIVER_USE_AGP | DRIVER_USE_MTRR | DRIVER_HAVE_IRQ;
47 dev->driver->buf_priv_size = 1;
48 dev->driver->load = via_driver_load;
49 dev->driver->unload = via_driver_unload;
50 dev->driver->context_ctor = via_init_context;
51 dev->driver->context_dtor = via_final_context;
52 dev->driver->get_vblank_counter = via_get_vblank_counter;
53 dev->driver->enable_vblank = via_enable_vblank;
54 dev->driver->disable_vblank = via_disable_vblank;
55 dev->driver->irq_preinstall = via_driver_irq_preinstall;
56 dev->driver->irq_postinstall = via_driver_irq_postinstall;
57 dev->driver->irq_uninstall = via_driver_irq_uninstall;
58 dev->driver->irq_handler = via_driver_irq_handler;
59 dev->driver->dma_quiescent = via_driver_dma_quiescent;
61 dev->driver->ioctls = via_ioctls;
62 dev->driver->max_ioctl = via_max_ioctl;
64 dev->driver->name = DRIVER_NAME;
65 dev->driver->desc = DRIVER_DESC;
66 dev->driver->date = VIA_DRM_DRIVER_DATE;
67 dev->driver->major = VIA_DRM_DRIVER_MAJOR;
68 dev->driver->minor = VIA_DRM_DRIVER_MINOR;
69 dev->driver->patchlevel = VIA_DRM_DRIVER_PATCHLEVEL;
72 #if defined(__FreeBSD__)
73 static int
74 via_probe(device_t kdev)
76 return drm_probe(kdev, via_pciidlist);
79 static int
80 via_attach(device_t kdev)
82 struct drm_device *dev = device_get_softc(kdev);
84 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
85 M_WAITOK | M_ZERO);
87 via_configure(dev);
89 return drm_attach(kdev, via_pciidlist);
92 static int
93 via_detach(device_t kdev)
95 struct drm_device *dev = device_get_softc(kdev);
96 int ret;
98 ret = drm_detach(kdev);
100 free(dev->driver, DRM_MEM_DRIVER);
102 return ret;
105 static device_method_t via_methods[] = {
106 /* Device interface */
107 DEVMETHOD(device_probe, via_probe),
108 DEVMETHOD(device_attach, via_attach),
109 DEVMETHOD(device_detach, via_detach),
111 { 0, 0 }
114 static driver_t via_driver = {
115 "drm",
116 via_methods,
117 sizeof(struct drm_device)
120 extern devclass_t drm_devclass;
121 DRIVER_MODULE(via, pci, via_driver, drm_devclass, 0, 0);
122 MODULE_DEPEND(via, drm, 1, 1, 1);
124 #elif defined(__NetBSD__)
126 static int
127 viadrm_probe(device_t parent, cfdata_t match, void *aux)
129 struct pci_attach_args *pa = aux;
130 return drm_probe(pa, via_pciidlist);
133 static void
134 viadrm_attach(device_t parent, device_t self, void *aux)
136 struct pci_attach_args *pa = aux;
137 struct drm_device *dev = device_private(self);
139 if (!pmf_device_register(self, NULL, NULL))
140 aprint_error_dev(self, "couldn't establish power handler\n");
142 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
143 M_WAITOK | M_ZERO);
145 via_configure(dev);
147 drm_attach(self, pa, via_pciidlist);
150 static int
151 viadrm_detach(device_t self, int flags)
153 pmf_device_deregister(self);
155 return drm_detach(self, flags);
158 CFATTACH_DECL_NEW(viadrm, sizeof(struct drm_device),
159 viadrm_probe, viadrm_attach, viadrm_detach, NULL);
161 #ifdef _MODULE
163 MODULE(MODULE_CLASS_DRIVER, viadrm, NULL);
165 CFDRIVER_DECL(viadrm, DV_DULL, NULL);
166 extern struct cfattach viadrm_ca;
167 static int drmloc[] = { -1 };
168 static struct cfparent drmparent = {
169 "drm", "vga", DVUNIT_ANY
171 static struct cfdata viadrm_cfdata[] = {
173 .cf_name = "viadrm",
174 .cf_atname = "viadrm",
175 .cf_unit = 0,
176 .cf_fstate = FSTATE_STAR,
177 .cf_loc = drmloc,
178 .cf_flags = 0,
179 .cf_pspec = &drmparent,
181 { NULL }
184 static int
185 viadrm_modcmd(modcmd_t cmd, void *arg)
187 int err;
189 switch (cmd) {
190 case MODULE_CMD_INIT:
191 err = config_cfdriver_attach(&viadrm_cd);
192 if (err)
193 return err;
194 err = config_cfattach_attach("viadrm", &viadrm_ca);
195 if (err) {
196 config_cfdriver_detach(&viadrm_cd);
197 return err;
199 err = config_cfdata_attach(viadrm_cfdata, 1);
200 if (err) {
201 config_cfattach_detach("viadrm", &viadrm_ca);
202 config_cfdriver_detach(&viadrm_cd);
203 return err;
205 return 0;
206 case MODULE_CMD_FINI:
207 err = config_cfdata_detach(viadrm_cfdata);
208 if (err)
209 return err;
210 config_cfattach_detach("viadrm", &viadrm_ca);
211 config_cfdriver_detach(&viadrm_cd);
212 return 0;
213 default:
214 return ENOTTY;
217 #endif /* _MODULE */
219 #endif