Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / external / bsd / drm / dist / bsd-core / sis_drv.c
blob3279577330d1ce6b8686bd0f179e13573119d0c4
1 /* sis.c -- sis driver -*- linux-c -*-
2 */
3 /*-
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
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 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
29 #include "drmP.h"
30 #include "sis_drm.h"
31 #include "sis_drv.h"
32 #include "drm_pciids.h"
34 /* drv_PCI_IDs comes from drm_pciids.h, generated from drm_pciids.txt. */
35 static drm_pci_id_list_t sis_pciidlist[] = {
36 sis_PCI_IDS
39 static void sis_configure(struct drm_device *dev)
41 dev->driver->driver_features =
42 DRIVER_USE_AGP | DRIVER_USE_MTRR;
44 dev->driver->buf_priv_size = 1; /* No dev_priv */
45 dev->driver->context_ctor = sis_init_context;
46 dev->driver->context_dtor = sis_final_context;
48 dev->driver->ioctls = sis_ioctls;
49 dev->driver->max_ioctl = sis_max_ioctl;
51 dev->driver->name = DRIVER_NAME;
52 dev->driver->desc = DRIVER_DESC;
53 dev->driver->date = DRIVER_DATE;
54 dev->driver->major = DRIVER_MAJOR;
55 dev->driver->minor = DRIVER_MINOR;
56 dev->driver->patchlevel = DRIVER_PATCHLEVEL;
59 #if defined(__FreeBSD__)
61 static int
62 sis_probe(device_t kdev)
64 return drm_probe(kdev, sis_pciidlist);
67 static int
68 sis_attach(device_t kdev)
70 struct drm_device *dev = device_get_softc(kdev);
72 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
73 M_WAITOK | M_ZERO);
75 sis_configure(dev);
77 return drm_attach(kdev, sis_pciidlist);
80 static int
81 sis_detach(device_t kdev)
83 struct drm_device *dev = device_get_softc(kdev);
84 int ret;
86 ret = drm_detach(kdev);
88 free(dev->driver, DRM_MEM_DRIVER);
90 return ret;
93 static device_method_t sis_methods[] = {
94 /* Device interface */
95 DEVMETHOD(device_probe, sis_probe),
96 DEVMETHOD(device_attach, sis_attach),
97 DEVMETHOD(device_detach, sis_detach),
99 { 0, 0 }
102 static driver_t sis_driver = {
103 "drm",
104 sis_methods,
105 sizeof(struct drm_device)
108 extern devclass_t drm_devclass;
109 #if __FreeBSD_version >= 700010
110 DRIVER_MODULE(sisdrm, vgapci, sis_driver, drm_devclass, 0, 0);
111 #else
112 DRIVER_MODULE(sisdrm, pci, sis_driver, drm_devclass, 0, 0);
113 #endif
114 MODULE_DEPEND(sisdrm, drm, 1, 1, 1);
116 #elif defined(__NetBSD__)
118 static int
119 sisdrm_probe(device_t parent, cfdata_t match, void *aux)
121 struct pci_attach_args *pa = aux;
123 return drm_probe(pa, sis_pciidlist);
126 static void
127 sisdrm_attach(device_t parent, device_t self, void *aux)
129 struct pci_attach_args *pa = aux;
130 struct drm_device *dev = device_private(self);
132 dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
133 M_WAITOK | M_ZERO);
135 sis_configure(dev);
137 drm_attach(self, pa, sis_pciidlist);
140 CFATTACH_DECL_NEW(sisdrm, sizeof(struct drm_device),
141 sisdrm_probe, sisdrm_attach, drm_detach, NULL);
143 #ifdef _MODULE
145 MODULE(MODULE_CLASS_DRIVER, sisdrm, NULL);
147 CFDRIVER_DECL(sisdrm, DV_DULL, NULL);
148 extern struct cfattach sisdrm_ca;
149 static int drmloc[] = { -1 };
150 static struct cfparent drmparent = {
151 "drm", "vga", DVUNIT_ANY
153 static struct cfdata sisdrm_cfdata[] = {
155 .cf_name = "sisdrm",
156 .cf_atname = "sisdrm",
157 .cf_unit = 0,
158 .cf_fstate = FSTATE_STAR,
159 .cf_loc = drmloc,
160 .cf_flags = 0,
161 .cf_pspec = &drmparent,
163 { NULL }
166 static int
167 sisdrm_modcmd(modcmd_t cmd, void *arg)
169 int err;
171 switch (cmd) {
172 case MODULE_CMD_INIT:
173 err = config_cfdriver_attach(&sisdrm_cd);
174 if (err)
175 return err;
176 err = config_cfattach_attach("sisdrm", &sisdrm_ca);
177 if (err) {
178 config_cfdriver_detach(&sisdrm_cd);
179 return err;
181 err = config_cfdata_attach(sisdrm_cfdata, 1);
182 if (err) {
183 config_cfattach_detach("sisdrm", &sisdrm_ca);
184 config_cfdriver_detach(&sisdrm_cd);
185 return err;
187 return 0;
188 case MODULE_CMD_FINI:
189 err = config_cfdata_detach(sisdrm_cfdata);
190 if (err)
191 return err;
192 config_cfattach_detach("sisdrm", &sisdrm_ca);
193 config_cfdriver_detach(&sisdrm_cd);
194 return 0;
195 default:
196 return ENOTTY;
199 #endif /* _MODULE */
201 #endif