2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 2000-2001 by Coleman Kane <cokane@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Gardner Buchanan.
18 * 4. The name of Gardner Buchanan may not be used to endorse or promote
19 * products derived from this software without specific prior written
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 /* 3dfx driver for FreeBSD 4.x - Finished 11 May 2000, 12:25AM ET
39 * Copyright (C) 2000-2001, by Coleman Kane <cokane@FreeBSD.org>,
40 * based upon the 3dfx driver written for linux, by Daryll Straus, Jon Taylor,
41 * and Jens Axboe, located at http://linux.3dfx.com.
44 #include <sys/param.h>
48 #include <sys/fcntl.h>
50 #include <sys/filedesc.h>
51 #include <sys/filio.h>
52 #include <sys/ioccom.h>
53 #include <sys/kernel.h>
54 #include <sys/module.h>
55 #include <sys/malloc.h>
57 #include <sys/signalvar.h>
58 #include <sys/systm.h>
61 #include <dev/pci/pcivar.h>
62 #include <dev/pci/pcireg.h>
65 #include <vm/vm_kern.h>
67 #include <vm/vm_extern.h>
69 /* rman.h depends on machine/bus.h */
70 #include <machine/resource.h>
71 #include <machine/bus.h>
74 #include <dev/tdfx/tdfx_io.h>
75 #include <dev/tdfx/tdfx_vars.h>
76 #include <dev/tdfx/tdfx_pci.h>
78 static devclass_t tdfx_devclass;
80 static int tdfx_count = 0;
82 /* Set up the boot probe/attach routines */
83 static device_method_t tdfx_methods[] = {
84 DEVMETHOD(device_probe, tdfx_probe),
85 DEVMETHOD(device_attach, tdfx_attach),
86 DEVMETHOD(device_detach, tdfx_detach),
87 DEVMETHOD(device_shutdown, tdfx_shutdown),
91 static MALLOC_DEFINE(M_TDFX,"tdfx_driver","3DFX Graphics[/2D]/3D Accelerators");
93 /* Char. Dev. file operations structure */
94 static struct cdevsw tdfx_cdev = {
95 .d_version = D_VERSION,
96 .d_flags = D_NEEDGIANT,
98 .d_close = tdfx_close,
99 .d_ioctl = tdfx_ioctl,
105 tdfx_probe(device_t dev)
108 * probe routine called on kernel boot to register supported devices. We get
109 * a device structure to work with, and we can test the VENDOR/DEVICE IDs to
110 * see if this PCI device is one that we support. Return BUS_PRROBE_DEFAULT
111 * if yes, ENXIO if not.
113 switch(pci_get_devid(dev)) {
114 case PCI_DEVICE_ALLIANCE_AT3D:
115 device_set_desc(dev, "ProMotion At3D 3D Accelerator");
116 return BUS_PROBE_DEFAULT;
117 case PCI_DEVICE_3DFX_VOODOO2:
118 device_set_desc(dev, "3DFX Voodoo II 3D Accelerator");
119 return BUS_PROBE_DEFAULT;
120 /*case PCI_DEVICE_3DFX_BANSHEE:
121 device_set_desc(dev, "3DFX Voodoo Banshee 2D/3D Graphics Accelerator");
122 return BUS_PROBE_DEFAULT;
123 case PCI_DEVICE_3DFX_VOODOO3:
124 device_set_desc(dev, "3DFX Voodoo3 2D/3D Graphics Accelerator");
125 return BUS_PROBE_DEFAULT;*/
126 case PCI_DEVICE_3DFX_VOODOO1:
127 device_set_desc(dev, "3DFX Voodoo Graphics 3D Accelerator");
128 return BUS_PROBE_DEFAULT;
135 tdfx_attach(device_t dev) {
137 * The attach routine is called after the probe routine successfully says it
138 * supports a given card. We now proceed to initialize this card for use with
139 * the system. I want to map the device memory for userland allocation and
140 * fill an information structure with information on this card. I'd also like
141 * to set Write Combining with the MTRR code so that we can hopefully speed
142 * up memory writes. The last thing is to register the character device
143 * interface to the card, so we can open it from /dev/3dfxN, where N is a
144 * small, whole number.
146 struct tdfx_softc *tdfx_info;
147 /* rid value tells bus_alloc_resource where to find the addresses of ports or
148 * of memory ranges in the PCI config space*/
149 int rid = PCIR_BAR(0);
151 /* Increment the card counter (for the ioctl code) */
154 /* Fill the soft config struct with info about this device*/
155 tdfx_info = device_get_softc(dev);
156 tdfx_info->dev = dev;
157 tdfx_info->vendor = pci_get_vendor(dev);
158 tdfx_info->type = pci_get_devid(dev) >> 16;
159 tdfx_info->bus = pci_get_bus(dev);
160 tdfx_info->dv = pci_get_slot(dev);
161 tdfx_info->curFile = NULL;
164 * Get the Memory Location from the PCI Config, mask out lower word, since
165 * the config space register is only one word long (this is nicer than a
168 tdfx_info->addr0 = (pci_read_config(dev, 0x10, 4) & 0xffff0000);
170 device_printf(dev, "Base0 @ 0x%x\n", tdfx_info->addr0);
172 /* Notify the VM that we will be mapping some memory later */
173 tdfx_info->memrange = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
174 &rid, RF_ACTIVE | RF_SHAREABLE);
175 if(tdfx_info->memrange == NULL) {
177 device_printf(dev, "Error mapping mem, won't be able to use mmap()\n");
179 tdfx_info->memrid = 0;
182 tdfx_info->memrid = rid;
184 device_printf(dev, "Mapped to: 0x%x\n",
185 (unsigned int)rman_get_start(tdfx_info->memrange));
189 /* Setup for Voodoo3 and Banshee, PIO and an extram Memrange */
190 if(pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3 ||
191 pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE) {
192 rid = 0x14; /* 2nd mem map */
193 tdfx_info->addr1 = (pci_read_config(dev, 0x14, 4) & 0xffff0000);
195 device_printf(dev, "Base1 @ 0x%x\n", tdfx_info->addr1);
197 tdfx_info->memrange2 = bus_alloc_resource_any(dev,
198 SYS_RES_MEMORY, &rid, RF_ACTIVE | RF_SHAREABLE);
199 if(tdfx_info->memrange2 == NULL) {
201 device_printf(dev, "Mem1 couldn't be allocated, glide may not work.");
203 tdfx_info->memrid2 = 0;
206 tdfx_info->memrid2 = rid;
208 /* Now to map the PIO stuff */
209 rid = PCIR_IOBASE0_2;
210 tdfx_info->pio0 = pci_read_config(dev, 0x2c, 2);
211 tdfx_info->pio0max = pci_read_config(dev, 0x30, 2) + tdfx_info->pio0;
212 tdfx_info->piorange = bus_alloc_resource_any(dev,
213 SYS_RES_IOPORT, &rid, RF_ACTIVE | RF_SHAREABLE);
214 if(tdfx_info->piorange == NULL) {
216 device_printf(dev, "Couldn't map PIO range.");
218 tdfx_info->piorid = 0;
221 tdfx_info->piorid = rid;
224 tdfx_info->addr1 = 0;
225 tdfx_info->memrange2 = NULL;
226 tdfx_info->piorange = NULL;
230 * Set Writecombining, or at least Uncacheable for the memory region, if we
234 if(tdfx_setmtrr(dev) != 0) {
236 device_printf(dev, "Some weird error setting MTRRs");
242 * make_dev registers the cdev to access the 3dfx card from /dev
243 * use hex here for the dev num, simply to provide better support if > 10
244 * voodoo cards, for the mad. The user must set the link.
245 * Why would we want that many voodoo cards anyhow?
247 tdfx_info->devt = make_dev(&tdfx_cdev, device_get_unit(dev),
248 UID_ROOT, GID_WHEEL, 0600, "3dfx%x", device_get_unit(dev));
249 tdfx_info->devt->si_drv1 = tdfx_info;
255 tdfx_detach(device_t dev) {
256 struct tdfx_softc* tdfx_info;
258 tdfx_info = device_get_softc(dev);
260 /* Delete allocated resource, of course */
261 bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid,
262 tdfx_info->memrange);
264 /* Release extended Voodoo3/Banshee resources */
265 if(pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE ||
266 pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3) {
267 if(tdfx_info->memrange2 != NULL)
268 bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid2,
269 tdfx_info->memrange);
270 /* if(tdfx_info->piorange != NULL)
271 bus_release_resource(dev, SYS_RES_IOPORT, tdfx_info->piorid,
272 tdfx_info->piorange);*/
275 /* Though it is safe to leave the WRCOMB support since the
276 mem driver checks for it, we should remove it in order
277 to free an MTRR for another device */
278 retval = tdfx_clrmtrr(dev);
281 printf("tdfx: For some reason, I couldn't clear the mtrr\n");
283 /* Remove device entry when it can no longer be accessed */
284 destroy_dev(tdfx_info->devt);
289 tdfx_shutdown(device_t dev) {
291 device_printf(dev, "tdfx: Device Shutdown\n");
297 tdfx_clrmtrr(device_t dev) {
298 /* This function removes the MTRR set by the attach call, so it can be used
299 * in the future by other drivers.
302 struct tdfx_softc *tdfx_info = device_get_softc(dev);
304 act = MEMRANGE_SET_REMOVE;
305 retval = mem_range_attr_set(&tdfx_info->mrdesc, &act);
310 tdfx_setmtrr(device_t dev) {
312 * This is the MTRR setting function for the 3dfx card. It is called from
313 * tdfx_attach. If we can't set the MTRR properly, it's not the end of the
314 * world. We can still continue, just with slightly (very slightly) degraded
318 struct tdfx_softc *tdfx_info = device_get_softc(dev);
320 /* The older Voodoo cards have a shorter memrange than the newer ones */
321 if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO1) || (pci_get_devid(dev) ==
322 PCI_DEVICE_3DFX_VOODOO2)) {
323 tdfx_info->mrdesc.mr_len = 0x400000;
325 /* The memory descriptor is described as the top 15 bits of the real
327 tdfx_info->mrdesc.mr_base = tdfx_info->addr0 & 0xfffe0000;
329 else if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3) ||
330 (pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE)) {
331 tdfx_info->mrdesc.mr_len = 0x1000000;
332 /* The Voodoo3 and Banshee LFB is the second memory address */
333 /* The memory descriptor is described as the top 15 bits of the real
335 tdfx_info->mrdesc.mr_base = tdfx_info->addr1 & 0xfffe0000;
340 * The Alliance Pro Motion AT3D was not mentioned in the linux
341 * driver as far as MTRR support goes, so I just won't put the
342 * code in here for it. This is where it should go, though.
345 /* Firstly, try to set write combining */
346 tdfx_info->mrdesc.mr_flags = MDF_WRITECOMBINE;
347 bcopy("tdfx", &tdfx_info->mrdesc.mr_owner, 4);
348 act = MEMRANGE_SET_UPDATE;
349 retval = mem_range_attr_set(&tdfx_info->mrdesc, &act);
353 device_printf(dev, "MTRR Set Correctly for tdfx\n");
355 } else if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO2) ||
356 (pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO1)) {
357 /* if, for some reason we can't set the WRCOMB range with the V1/V2, we
358 * can still possibly use the UNCACHEABLE region for it instead, and help
359 * out in a small way */
360 tdfx_info->mrdesc.mr_flags = MDF_UNCACHEABLE;
361 /* This length of 1000h was taken from the linux device driver... */
362 tdfx_info->mrdesc.mr_len = 0x1000;
365 * If, for some reason, we can't set the MTRR (N/A?) we may still continue
368 device_printf(dev, "MTRR Set Type Uncacheable %x\n",
369 (u_int32_t)tdfx_info->mrdesc.mr_base);
374 device_printf(dev, "Couldn't Set MTRR\n");
382 tdfx_open(struct cdev *dev, int flags, int fmt, struct thread *td)
385 * The open cdev method handles open(2) calls to /dev/3dfx[n]
386 * We can pretty much allow any opening of the device.
388 struct tdfx_softc *tdfx_info = dev->si_drv1;
389 if(tdfx_info->busy != 0) return EBUSY;
391 printf("3dfx: Opened by #%d\n", td->td_proc->p_pid);
393 /* Set the driver as busy */
399 tdfx_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
402 * The close cdev method handles close(2) calls to /dev/3dfx[n]
403 * We'll always want to close the device when it's called.
405 struct tdfx_softc *tdfx_info = dev->si_drv1;
406 if(tdfx_info->busy == 0) return EBADF;
409 printf("Closed by #%d\n", td->td_proc->p_pid);
415 tdfx_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
416 int nprot, vm_memattr_t *memattr)
419 * mmap(2) is called by a user process to request that an area of memory
420 * associated with this device be mapped for the process to work with. Nprot
421 * holds the protections requested, PROT_READ, PROT_WRITE, or both.
424 /**** OLD GET CONFIG ****/
425 /* struct tdfx_softc* tdfx_info; */
427 /* Get the configuration for our card XXX*/
428 /*tdfx_info = dev->si_drv1; */
429 /************************/
431 struct tdfx_softc* tdfx_info[2];
433 tdfx_info[0] = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, 0);
435 /* If, for some reason, its not configured, we bail out */
436 if(tdfx_info[0] == NULL) {
438 printf("tdfx: tdfx_info (softc) is NULL\n");
443 /* We must stay within the bound of our address space */
444 if((offset & 0xff000000) == tdfx_info[0]->addr0) {
446 *paddr = rman_get_start(tdfx_info[0]->memrange) + offset;
451 tdfx_info[1] = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, 1);
452 if((offset & 0xff000000) == tdfx_info[1]->addr0) {
454 *paddr = rman_get_start(tdfx_info[1]->memrange) +
460 /* See if the Banshee/V3 LFB is being requested */
461 /*if(tdfx_info->memrange2 != NULL && (offset & 0xff000000) ==
464 return atop(rman_get_start(tdfx_info[1]->memrange2) + offset);
465 }*/ /* VoodooNG code */
468 /* atop -> address to page
469 * rman_get_start, get the (struct resource*)->r_start member,
470 * the mapping base address.
476 tdfx_query_boards(void) {
478 * This returns the number of installed tdfx cards, we have been keeping
479 * count, look at tdfx_attach
485 tdfx_query_fetch(u_int cmd, struct tdfx_pio_data *piod)
487 /* XXX Comment this later, after careful inspection and spring cleaning :) */
488 /* Various return values 8bit-32bit */
492 struct tdfx_softc* tdfx_info = NULL;
494 /* This one depend on the tdfx_* structs being properly initialized */
496 /*piod->device &= 0xf;*/
497 if((piod == NULL) ||(tdfx_count <= piod->device) ||
498 (piod->device < 0)) {
500 printf("tdfx: Bad device or internal struct in tdfx_query_fetch\n");
505 tdfx_info = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass,
508 if(tdfx_info == NULL) return -ENXIO;
510 /* We must restrict the size reads from the port, since to high or low of a
511 * size witll result in wrong data being passed, and that's bad */
512 /* A few of these were pulled during the attach phase */
514 case PCI_VENDOR_ID_FREEBSD:
515 if(piod->size != 2) return -EINVAL;
516 copyout(&tdfx_info->vendor, piod->value, piod->size);
518 case PCI_DEVICE_ID_FREEBSD:
519 if(piod->size != 2) return -EINVAL;
520 copyout(&tdfx_info->type, piod->value, piod->size);
522 case PCI_BASE_ADDRESS_0_FREEBSD:
523 if(piod->size != 4) return -EINVAL;
524 copyout(&tdfx_info->addr0, piod->value, piod->size);
526 case PCI_BASE_ADDRESS_1_FREEBSD:
527 if(piod->size != 4) return -EINVAL;
528 copyout(&tdfx_info->addr1, piod->value, piod->size);
530 case PCI_PRIBUS_FREEBSD:
531 if(piod->size != 1) return -EINVAL;
533 case PCI_IOBASE_0_FREEBSD:
534 if(piod->size != 2) return -EINVAL;
536 case PCI_IOLIMIT_0_FREEBSD:
537 if(piod->size != 2) return -EINVAL;
539 case SST1_PCI_SPECIAL1_FREEBSD:
540 if(piod->size != 4) return -EINVAL;
542 case PCI_REVISION_ID_FREEBSD:
543 if(piod->size != 1) return -EINVAL;
545 case SST1_PCI_SPECIAL4_FREEBSD:
546 if(piod->size != 4) return -EINVAL;
552 /* Read the value and return */
555 ret_byte = pci_read_config(tdfx_info[piod->device].dev,
557 copyout(&ret_byte, piod->value, 1);
560 ret_word = pci_read_config(tdfx_info[piod->device].dev,
562 copyout(&ret_word, piod->value, 2);
565 ret_dword = pci_read_config(tdfx_info[piod->device].dev,
567 copyout(&ret_dword, piod->value, 4);
576 tdfx_query_update(u_int cmd, struct tdfx_pio_data *piod)
578 /* XXX Comment this later, after careful inspection and spring cleaning :) */
584 /* Port vals, mask */
585 u_int32_t retval, preval, mask;
586 struct tdfx_softc* tdfx_info = NULL;
589 if((piod == NULL) || (piod->device >= (tdfx_count &
592 printf("tdfx: Bad struct or device in tdfx_query_update\n");
597 tdfx_info = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass,
599 if(tdfx_info == NULL) return -ENXIO;
600 /* Code below this line in the fuction was taken from the
601 * Linux driver and converted for freebsd. */
603 /* Check the size for all the ports, to make sure stuff doesn't get messed up
604 * by poorly written clients */
607 case PCI_COMMAND_FREEBSD:
608 if(piod->size != 2) return -EINVAL;
610 case SST1_PCI_SPECIAL1_FREEBSD:
611 if(piod->size != 4) return -EINVAL;
613 case SST1_PCI_SPECIAL2_FREEBSD:
614 if(piod->size != 4) return -EINVAL;
616 case SST1_PCI_SPECIAL3_FREEBSD:
617 if(piod->size != 4) return -EINVAL;
619 case SST1_PCI_SPECIAL4_FREEBSD:
620 if(piod->size != 4) return -EINVAL;
625 /* Read the current value */
626 retval = pci_read_config(tdfx_info->dev, piod->port & ~3, 4);
628 /* These set up a mask to use, since apparently they wanted to write 4 bytes
629 * at once to the ports */
630 switch (piod->size) {
632 copyin(piod->value, &ret_byte, 1);
633 preval = ret_byte << (8 * (piod->port & 0x3));
634 mask = 0xff << (8 * (piod->port & 0x3));
637 copyin(piod->value, &ret_word, 2);
638 preval = ret_word << (8 * (piod->port & 0x3));
639 mask = 0xffff << (8 * (piod->port & 0x3));
642 copyin(piod->value, &ret_dword, 4);
649 /* Finally, combine the values and write it to the port */
650 retval = (retval & ~mask) | preval;
651 pci_write_config(tdfx_info->dev, piod->port & ~3, retval, 4);
656 /* For both of these, I added a variable named workport of type u_int so
657 * that I could eliminate the warning about my data type size. The
658 * applications expect the port to be of type short, so I needed to change
659 * this within the function */
661 tdfx_do_pio_rd(struct tdfx_pio_data *piod)
666 struct tdfx_softc *tdfx_info =
667 (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, piod->device);
669 /* Restricts the access of ports other than those we use */
670 if(((piod->port != VGA_INPUT_STATUS_1C) || (piod->port != SC_INDEX) ||
671 (piod->port != SC_DATA) || (piod->port != VGA_MISC_OUTPUT_READ)) &&
672 (piod->port < tdfx_info->pio0) && (piod->port > tdfx_info->pio0max))
675 /* All VGA STATUS REGS are byte registers, size should never be > 1 */
676 if(piod->size != 1) {
680 /* Write the data to the intended port */
681 workport = piod->port;
682 ret_byte = inb(workport);
683 copyout(&ret_byte, piod->value, sizeof(u_int8_t));
688 tdfx_do_pio_wt(struct tdfx_pio_data *piod)
693 struct tdfx_softc *tdfx_info = (struct
694 tdfx_softc*)devclass_get_softc(tdfx_devclass, piod->device);
695 /* Replace old switch w/ massive if(...) */
696 /* Restricts the access of ports other than those we use */
697 if(((piod->port != SC_INDEX) && (piod->port != SC_DATA) &&
698 (piod->port != VGA_MISC_OUTPUT_READ)) /* Can't write VGA_ST_1C */ &&
699 (piod->port < tdfx_info->pio0) && (piod->port > tdfx_info->pio0max))
702 /* All VGA STATUS REGS are byte registers, size should never be > 1 */
703 if(piod->size != 1) {
707 /* Write the data to the intended port */
708 copyin(piod->value, &ret_byte, sizeof(u_int8_t));
709 workport = piod->port;
710 outb(workport, ret_byte);
715 tdfx_do_query(u_int cmd, struct tdfx_pio_data *piod)
717 /* There are three sub-commands to the query 0x33 */
718 switch(_IOC_NR(cmd)) {
720 return tdfx_query_boards();
723 return tdfx_query_fetch(cmd, piod);
726 return tdfx_query_update(cmd, piod);
729 /* In case we are thrown a bogus sub-command! */
731 printf("Bad Sub-cmd: 0x%x\n", _IOC_NR(cmd));
738 tdfx_do_pio(u_int cmd, struct tdfx_pio_data *piod)
740 /* Two types of PIO, INPUT and OUTPUT, as the name suggests */
741 switch(_IOC_DIR(cmd)) {
743 return tdfx_do_pio_rd(piod);
746 return tdfx_do_pio_wt(piod);
753 /* Calls to ioctl(2) eventually end up here. Unhandled ioctls return an ENXIO,
754 * normally, you would read in the data pointed to by data, then write your
755 * output to it. The ioctl *should* normally return zero if everything is
756 * alright, but 3dfx didn't make it that way...
758 * For all of the ioctl code, in the event of a real error,
759 * we return -Exxxx rather than simply Exxxx. The reason for this
760 * is that the ioctls actually RET information back to the program
761 * sometimes, rather than filling it in the passed structure. We
762 * want to distinguish errors from useful data, and maintain compatibility.
764 * There is this portion of the proc struct called p_retval[], we can store a
765 * return value in td->td_retval[0] and place the return value if it is positive
766 * in there, then we can return 0 (good). If the return value is negative, we
767 * can return -retval and the error should be properly handled.
770 tdfx_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
773 struct tdfx_pio_data *piod = (struct tdfx_pio_data*)data;
775 printf("IOCTL'd by #%d, cmd: 0x%x, data: %p\n", td->td_proc->p_pid, (u_int32_t)cmd,
778 switch(_IOC_TYPE(cmd)) {
779 /* Return the real error if negative, or simply stick the valid return
780 * in td->td_retval */
782 /* The '3'(0x33) type IOCTL is for querying the installed cards */
783 if((retval = tdfx_do_query(cmd, piod)) > 0) td->td_retval[0] = retval;
787 /* The 0 type IOCTL is for programmed I/O methods */
788 if((tdfx_do_pio(cmd, piod)) > 0) td->td_retval[0] = retval;
792 /* Technically, we won't reach this from linux emu, but when glide
793 * finally gets ported, watch out! */
795 printf("Bad IOCTL from #%d\n", td->td_proc->p_pid);
803 /* This is the device driver struct. This is sent to the driver subsystem to
804 * register the method structure and the info strcut space for this particular
805 * instance of the driver.
807 static driver_t tdfx_driver = {
810 sizeof(struct tdfx_softc),
813 /* Tell Mr. Kernel about us! */
814 DRIVER_MODULE(tdfx, pci, tdfx_driver, tdfx_devclass, 0, 0);
815 MODULE_DEPEND(tdfx, mem, 1, 1, 1);
816 MODULE_VERSION(tdfx, 1);