2 * Copyright (c) 2000-2001 by Coleman Kane <cokane@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Gardner Buchanan.
16 * 4. The name of Gardner Buchanan may not be used to endorse or promote
17 * products derived from this software without specific prior written
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 /* 3dfx driver for FreeBSD 4.x - Finished 11 May 2000, 12:25AM ET
37 * Copyright (C) 2000-2001, by Coleman Kane <cokane@FreeBSD.org>,
38 * based upon the 3dfx driver written for linux, by Daryll Straus, Jon Taylor,
39 * and Jens Axboe, located at http://linux.3dfx.com.
42 #include <sys/param.h>
46 #include <sys/fcntl.h>
48 #include <sys/filedesc.h>
49 #include <sys/filio.h>
50 #include <sys/ioccom.h>
51 #include <sys/kernel.h>
52 #include <sys/module.h>
53 #include <sys/malloc.h>
55 #include <sys/signalvar.h>
56 #include <sys/systm.h>
59 #include <dev/pci/pcivar.h>
60 #include <dev/pci/pcireg.h>
63 #include <vm/vm_kern.h>
65 #include <vm/vm_extern.h>
67 /* rman.h depends on machine/bus.h */
68 #include <machine/resource.h>
69 #include <machine/bus.h>
72 #include <dev/tdfx/tdfx_io.h>
73 #include <dev/tdfx/tdfx_vars.h>
74 #include <dev/tdfx/tdfx_pci.h>
77 static devclass_t tdfx_devclass;
80 static int tdfx_count = 0;
83 /* Set up the boot probe/attach routines */
84 static device_method_t tdfx_methods[] = {
85 DEVMETHOD(device_probe, tdfx_probe),
86 DEVMETHOD(device_attach, tdfx_attach),
87 DEVMETHOD(device_detach, tdfx_detach),
88 DEVMETHOD(device_shutdown, tdfx_shutdown),
92 static MALLOC_DEFINE(M_TDFX,"tdfx_driver","3DFX Graphics[/2D]/3D Accelerators");
94 /* Char. Dev. file operations structure */
95 static struct cdevsw tdfx_cdev = {
96 .d_version = D_VERSION,
97 .d_flags = D_NEEDGIANT,
99 .d_close = tdfx_close,
100 .d_ioctl = tdfx_ioctl,
106 tdfx_probe(device_t dev)
109 * probe routine called on kernel boot to register supported devices. We get
110 * a device structure to work with, and we can test the VENDOR/DEVICE IDs to
111 * see if this PCI device is one that we support. Return BUS_PRROBE_DEFAULT
112 * if yes, ENXIO if not.
114 switch(pci_get_devid(dev)) {
115 case PCI_DEVICE_ALLIANCE_AT3D:
116 device_set_desc(dev, "ProMotion At3D 3D Accelerator");
117 return BUS_PROBE_DEFAULT;
118 case PCI_DEVICE_3DFX_VOODOO2:
119 device_set_desc(dev, "3DFX Voodoo II 3D Accelerator");
120 return BUS_PROBE_DEFAULT;
121 /*case PCI_DEVICE_3DFX_BANSHEE:
122 device_set_desc(dev, "3DFX Voodoo Banshee 2D/3D Graphics Accelerator");
123 return BUS_PROBE_DEFAULT;
124 case PCI_DEVICE_3DFX_VOODOO3:
125 device_set_desc(dev, "3DFX Voodoo3 2D/3D Graphics Accelerator");
126 return BUS_PROBE_DEFAULT;*/
127 case PCI_DEVICE_3DFX_VOODOO1:
128 device_set_desc(dev, "3DFX Voodoo Graphics 3D Accelerator");
129 return BUS_PROBE_DEFAULT;
136 tdfx_attach(device_t dev) {
138 * The attach routine is called after the probe routine successfully says it
139 * supports a given card. We now proceed to initialize this card for use with
140 * the system. I want to map the device memory for userland allocation and
141 * fill an information structure with information on this card. I'd also like
142 * to set Write Combining with the MTRR code so that we can hopefully speed
143 * up memory writes. The last thing is to register the character device
144 * interface to the card, so we can open it from /dev/3dfxN, where N is a
145 * small, whole number.
147 struct tdfx_softc *tdfx_info;
149 /* rid value tells bus_alloc_resource where to find the addresses of ports or
150 * of memory ranges in the PCI config space*/
151 int rid = PCIR_BAR(0);
153 /* Increment the card counter (for the ioctl code) */
156 /* Enable MemMap on Voodoo */
157 val = pci_read_config(dev, PCIR_COMMAND, 2);
158 val |= (PCIM_CMD_MEMEN);
159 pci_write_config(dev, PCIR_COMMAND, val, 2);
160 val = pci_read_config(dev, PCIR_COMMAND, 2);
162 /* Fill the soft config struct with info about this device*/
163 tdfx_info = device_get_softc(dev);
164 tdfx_info->dev = dev;
165 tdfx_info->vendor = pci_get_vendor(dev);
166 tdfx_info->type = pci_get_devid(dev) >> 16;
167 tdfx_info->bus = pci_get_bus(dev);
168 tdfx_info->dv = pci_get_slot(dev);
169 tdfx_info->curFile = NULL;
172 * Get the Memory Location from the PCI Config, mask out lower word, since
173 * the config space register is only one word long (this is nicer than a
176 tdfx_info->addr0 = (pci_read_config(dev, 0x10, 4) & 0xffff0000);
178 device_printf(dev, "Base0 @ 0x%x\n", tdfx_info->addr0);
180 /* Notify the VM that we will be mapping some memory later */
181 tdfx_info->memrange = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
182 &rid, RF_ACTIVE | RF_SHAREABLE);
183 if(tdfx_info->memrange == NULL) {
185 device_printf(dev, "Error mapping mem, won't be able to use mmap()\n");
187 tdfx_info->memrid = 0;
190 tdfx_info->memrid = rid;
192 device_printf(dev, "Mapped to: 0x%x\n",
193 (unsigned int)rman_get_start(tdfx_info->memrange));
197 /* Setup for Voodoo3 and Banshee, PIO and an extram Memrange */
198 if(pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3 ||
199 pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE) {
200 rid = 0x14; /* 2nd mem map */
201 tdfx_info->addr1 = (pci_read_config(dev, 0x14, 4) & 0xffff0000);
203 device_printf(dev, "Base1 @ 0x%x\n", tdfx_info->addr1);
205 tdfx_info->memrange2 = bus_alloc_resource_any(dev,
206 SYS_RES_MEMORY, &rid, RF_ACTIVE | RF_SHAREABLE);
207 if(tdfx_info->memrange2 == NULL) {
209 device_printf(dev, "Mem1 couldn't be allocated, glide may not work.");
211 tdfx_info->memrid2 = 0;
214 tdfx_info->memrid2 = rid;
216 /* Now to map the PIO stuff */
217 rid = PCIR_IOBASE0_2;
218 tdfx_info->pio0 = pci_read_config(dev, 0x2c, 2);
219 tdfx_info->pio0max = pci_read_config(dev, 0x30, 2) + tdfx_info->pio0;
220 tdfx_info->piorange = bus_alloc_resource_any(dev,
221 SYS_RES_IOPORT, &rid, RF_ACTIVE | RF_SHAREABLE);
222 if(tdfx_info->piorange == NULL) {
224 device_printf(dev, "Couldn't map PIO range.");
226 tdfx_info->piorid = 0;
229 tdfx_info->piorid = rid;
232 tdfx_info->addr1 = 0;
233 tdfx_info->memrange2 = NULL;
234 tdfx_info->piorange = NULL;
238 * Set Writecombining, or at least Uncacheable for the memory region, if we
242 if(tdfx_setmtrr(dev) != 0) {
244 device_printf(dev, "Some weird error setting MTRRs");
250 * make_dev registers the cdev to access the 3dfx card from /dev
251 * use hex here for the dev num, simply to provide better support if > 10
252 * voodoo cards, for the mad. The user must set the link.
253 * Why would we want that many voodoo cards anyhow?
255 tdfx_info->devt = make_dev(&tdfx_cdev, device_get_unit(dev),
256 UID_ROOT, GID_WHEEL, 0600, "3dfx%x", device_get_unit(dev));
257 tdfx_info->devt->si_drv1 = tdfx_info;
263 tdfx_detach(device_t dev) {
264 struct tdfx_softc* tdfx_info;
266 tdfx_info = device_get_softc(dev);
268 /* Delete allocated resource, of course */
269 bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid,
270 tdfx_info->memrange);
272 /* Release extended Voodoo3/Banshee resources */
273 if(pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE ||
274 pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3) {
275 if(tdfx_info->memrange2 != NULL)
276 bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid2,
277 tdfx_info->memrange);
278 /* if(tdfx_info->piorange != NULL)
279 bus_release_resource(dev, SYS_RES_IOPORT, tdfx_info->piorid,
280 tdfx_info->piorange);*/
283 /* Though it is safe to leave the WRCOMB support since the
284 mem driver checks for it, we should remove it in order
285 to free an MTRR for another device */
286 retval = tdfx_clrmtrr(dev);
289 printf("tdfx: For some reason, I couldn't clear the mtrr\n");
291 /* Remove device entry when it can no longer be accessed */
292 destroy_dev(tdfx_info->devt);
297 tdfx_shutdown(device_t dev) {
299 device_printf(dev, "tdfx: Device Shutdown\n");
305 tdfx_clrmtrr(device_t dev) {
306 /* This function removes the MTRR set by the attach call, so it can be used
307 * in the future by other drivers.
310 struct tdfx_softc *tdfx_info = device_get_softc(dev);
312 act = MEMRANGE_SET_REMOVE;
313 retval = mem_range_attr_set(&tdfx_info->mrdesc, &act);
318 tdfx_setmtrr(device_t dev) {
320 * This is the MTRR setting function for the 3dfx card. It is called from
321 * tdfx_attach. If we can't set the MTRR properly, it's not the end of the
322 * world. We can still continue, just with slightly (very slightly) degraded
326 struct tdfx_softc *tdfx_info = device_get_softc(dev);
328 /* The older Voodoo cards have a shorter memrange than the newer ones */
329 if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO1) || (pci_get_devid(dev) ==
330 PCI_DEVICE_3DFX_VOODOO2)) {
331 tdfx_info->mrdesc.mr_len = 0x400000;
333 /* The memory descriptor is described as the top 15 bits of the real
335 tdfx_info->mrdesc.mr_base = tdfx_info->addr0 & 0xfffe0000;
337 else if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3) ||
338 (pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE)) {
339 tdfx_info->mrdesc.mr_len = 0x1000000;
340 /* The Voodoo3 and Banshee LFB is the second memory address */
341 /* The memory descriptor is described as the top 15 bits of the real
343 tdfx_info->mrdesc.mr_base = tdfx_info->addr1 & 0xfffe0000;
348 * The Alliance Pro Motion AT3D was not mentioned in the linux
349 * driver as far as MTRR support goes, so I just won't put the
350 * code in here for it. This is where it should go, though.
353 /* Firstly, try to set write combining */
354 tdfx_info->mrdesc.mr_flags = MDF_WRITECOMBINE;
355 bcopy("tdfx", &tdfx_info->mrdesc.mr_owner, 4);
356 act = MEMRANGE_SET_UPDATE;
357 retval = mem_range_attr_set(&tdfx_info->mrdesc, &act);
361 device_printf(dev, "MTRR Set Correctly for tdfx\n");
363 } else if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO2) ||
364 (pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO1)) {
365 /* if, for some reason we can't set the WRCOMB range with the V1/V2, we
366 * can still possibly use the UNCACHEABLE region for it instead, and help
367 * out in a small way */
368 tdfx_info->mrdesc.mr_flags = MDF_UNCACHEABLE;
369 /* This length of 1000h was taken from the linux device driver... */
370 tdfx_info->mrdesc.mr_len = 0x1000;
373 * If, for some reason, we can't set the MTRR (N/A?) we may still continue
376 device_printf(dev, "MTRR Set Type Uncacheable %x\n",
377 (u_int32_t)tdfx_info->mrdesc.mr_base);
382 device_printf(dev, "Couldn't Set MTRR\n");
390 tdfx_open(struct cdev *dev, int flags, int fmt, struct thread *td)
393 * The open cdev method handles open(2) calls to /dev/3dfx[n]
394 * We can pretty much allow any opening of the device.
396 struct tdfx_softc *tdfx_info = dev->si_drv1;
397 if(tdfx_info->busy != 0) return EBUSY;
399 printf("3dfx: Opened by #%d\n", td->td_proc->p_pid);
401 /* Set the driver as busy */
407 tdfx_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
410 * The close cdev method handles close(2) calls to /dev/3dfx[n]
411 * We'll always want to close the device when it's called.
413 struct tdfx_softc *tdfx_info = dev->si_drv1;
414 if(tdfx_info->busy == 0) return EBADF;
417 printf("Closed by #%d\n", td->td_proc->p_pid);
423 tdfx_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr,
424 int nprot, vm_memattr_t *memattr)
427 * mmap(2) is called by a user process to request that an area of memory
428 * associated with this device be mapped for the process to work with. Nprot
429 * holds the protections requested, PROT_READ, PROT_WRITE, or both.
432 /**** OLD GET CONFIG ****/
433 /* struct tdfx_softc* tdfx_info; */
435 /* Get the configuration for our card XXX*/
436 /*tdfx_info = dev->si_drv1; */
437 /************************/
439 struct tdfx_softc* tdfx_info[2];
441 tdfx_info[0] = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, 0);
443 /* If, for some reason, its not configured, we bail out */
444 if(tdfx_info[0] == NULL) {
446 printf("tdfx: tdfx_info (softc) is NULL\n");
451 /* We must stay within the bound of our address space */
452 if((offset & 0xff000000) == tdfx_info[0]->addr0) {
454 *paddr = rman_get_start(tdfx_info[0]->memrange) + offset;
459 tdfx_info[1] = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, 1);
460 if((offset & 0xff000000) == tdfx_info[1]->addr0) {
462 *paddr = rman_get_start(tdfx_info[1]->memrange) +
468 /* See if the Banshee/V3 LFB is being requested */
469 /*if(tdfx_info->memrange2 != NULL && (offset & 0xff000000) ==
472 return atop(rman_get_start(tdfx_info[1]->memrange2) + offset);
473 }*/ /* VoodooNG code */
476 /* atop -> address to page
477 * rman_get_start, get the (struct resource*)->r_start member,
478 * the mapping base address.
484 tdfx_query_boards(void) {
486 * This returns the number of installed tdfx cards, we have been keeping
487 * count, look at tdfx_attach
493 tdfx_query_fetch(u_int cmd, struct tdfx_pio_data *piod)
495 /* XXX Comment this later, after careful inspection and spring cleaning :) */
496 /* Various return values 8bit-32bit */
500 struct tdfx_softc* tdfx_info = NULL;
502 /* This one depend on the tdfx_* structs being properly initialized */
504 /*piod->device &= 0xf;*/
505 if((piod == NULL) ||(tdfx_count <= piod->device) ||
506 (piod->device < 0)) {
508 printf("tdfx: Bad device or internal struct in tdfx_query_fetch\n");
513 tdfx_info = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass,
516 if(tdfx_info == NULL) return -ENXIO;
518 /* We must restrict the size reads from the port, since to high or low of a
519 * size witll result in wrong data being passed, and that's bad */
520 /* A few of these were pulled during the attach phase */
522 case PCI_VENDOR_ID_FREEBSD:
523 if(piod->size != 2) return -EINVAL;
524 copyout(&tdfx_info->vendor, piod->value, piod->size);
526 case PCI_DEVICE_ID_FREEBSD:
527 if(piod->size != 2) return -EINVAL;
528 copyout(&tdfx_info->type, piod->value, piod->size);
530 case PCI_BASE_ADDRESS_0_FREEBSD:
531 if(piod->size != 4) return -EINVAL;
532 copyout(&tdfx_info->addr0, piod->value, piod->size);
534 case PCI_BASE_ADDRESS_1_FREEBSD:
535 if(piod->size != 4) return -EINVAL;
536 copyout(&tdfx_info->addr1, piod->value, piod->size);
538 case PCI_PRIBUS_FREEBSD:
539 if(piod->size != 1) return -EINVAL;
541 case PCI_IOBASE_0_FREEBSD:
542 if(piod->size != 2) return -EINVAL;
544 case PCI_IOLIMIT_0_FREEBSD:
545 if(piod->size != 2) return -EINVAL;
547 case SST1_PCI_SPECIAL1_FREEBSD:
548 if(piod->size != 4) return -EINVAL;
550 case PCI_REVISION_ID_FREEBSD:
551 if(piod->size != 1) return -EINVAL;
553 case SST1_PCI_SPECIAL4_FREEBSD:
554 if(piod->size != 4) return -EINVAL;
561 /* Read the value and return */
564 ret_byte = pci_read_config(tdfx_info[piod->device].dev,
566 copyout(&ret_byte, piod->value, 1);
569 ret_word = pci_read_config(tdfx_info[piod->device].dev,
571 copyout(&ret_word, piod->value, 2);
574 ret_dword = pci_read_config(tdfx_info[piod->device].dev,
576 copyout(&ret_dword, piod->value, 4);
585 tdfx_query_update(u_int cmd, struct tdfx_pio_data *piod)
587 /* XXX Comment this later, after careful inspection and spring cleaning :) */
593 /* Port vals, mask */
594 u_int32_t retval, preval, mask;
595 struct tdfx_softc* tdfx_info = NULL;
598 if((piod == NULL) || (piod->device >= (tdfx_count &
601 printf("tdfx: Bad struct or device in tdfx_query_update\n");
606 tdfx_info = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass,
608 if(tdfx_info == NULL) return -ENXIO;
609 /* Code below this line in the fuction was taken from the
610 * Linux driver and converted for freebsd. */
612 /* Check the size for all the ports, to make sure stuff doesn't get messed up
613 * by poorly written clients */
616 case PCI_COMMAND_FREEBSD:
617 if(piod->size != 2) return -EINVAL;
619 case SST1_PCI_SPECIAL1_FREEBSD:
620 if(piod->size != 4) return -EINVAL;
622 case SST1_PCI_SPECIAL2_FREEBSD:
623 if(piod->size != 4) return -EINVAL;
625 case SST1_PCI_SPECIAL3_FREEBSD:
626 if(piod->size != 4) return -EINVAL;
628 case SST1_PCI_SPECIAL4_FREEBSD:
629 if(piod->size != 4) return -EINVAL;
634 /* Read the current value */
635 retval = pci_read_config(tdfx_info->dev, piod->port & ~3, 4);
637 /* These set up a mask to use, since apparently they wanted to write 4 bytes
638 * at once to the ports */
639 switch (piod->size) {
641 copyin(piod->value, &ret_byte, 1);
642 preval = ret_byte << (8 * (piod->port & 0x3));
643 mask = 0xff << (8 * (piod->port & 0x3));
646 copyin(piod->value, &ret_word, 2);
647 preval = ret_word << (8 * (piod->port & 0x3));
648 mask = 0xffff << (8 * (piod->port & 0x3));
651 copyin(piod->value, &ret_dword, 4);
658 /* Finally, combine the values and write it to the port */
659 retval = (retval & ~mask) | preval;
660 pci_write_config(tdfx_info->dev, piod->port & ~3, retval, 4);
665 /* For both of these, I added a variable named workport of type u_int so
666 * that I could eliminate the warning about my data type size. The
667 * applications expect the port to be of type short, so I needed to change
668 * this within the function */
670 tdfx_do_pio_rd(struct tdfx_pio_data *piod)
675 struct tdfx_softc *tdfx_info =
676 (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, piod->device);
678 /* Restricts the access of ports other than those we use */
679 if(((piod->port != VGA_INPUT_STATUS_1C) || (piod->port != SC_INDEX) ||
680 (piod->port != SC_DATA) || (piod->port != VGA_MISC_OUTPUT_READ)) &&
681 (piod->port < tdfx_info->pio0) && (piod->port > tdfx_info->pio0max))
684 /* All VGA STATUS REGS are byte registers, size should never be > 1 */
685 if(piod->size != 1) {
689 /* Write the data to the intended port */
690 workport = piod->port;
691 ret_byte = inb(workport);
692 copyout(&ret_byte, piod->value, sizeof(u_int8_t));
697 tdfx_do_pio_wt(struct tdfx_pio_data *piod)
702 struct tdfx_softc *tdfx_info = (struct
703 tdfx_softc*)devclass_get_softc(tdfx_devclass, piod->device);
704 /* Replace old switch w/ massive if(...) */
705 /* Restricts the access of ports other than those we use */
706 if(((piod->port != SC_INDEX) && (piod->port != SC_DATA) &&
707 (piod->port != VGA_MISC_OUTPUT_READ)) /* Can't write VGA_ST_1C */ &&
708 (piod->port < tdfx_info->pio0) && (piod->port > tdfx_info->pio0max))
711 /* All VGA STATUS REGS are byte registers, size should never be > 1 */
712 if(piod->size != 1) {
716 /* Write the data to the intended port */
717 copyin(piod->value, &ret_byte, sizeof(u_int8_t));
718 workport = piod->port;
719 outb(workport, ret_byte);
724 tdfx_do_query(u_int cmd, struct tdfx_pio_data *piod)
726 /* There are three sub-commands to the query 0x33 */
727 switch(_IOC_NR(cmd)) {
729 return tdfx_query_boards();
732 return tdfx_query_fetch(cmd, piod);
735 return tdfx_query_update(cmd, piod);
738 /* In case we are thrown a bogus sub-command! */
740 printf("Bad Sub-cmd: 0x%x\n", _IOC_NR(cmd));
747 tdfx_do_pio(u_int cmd, struct tdfx_pio_data *piod)
749 /* Two types of PIO, INPUT and OUTPUT, as the name suggests */
750 switch(_IOC_DIR(cmd)) {
752 return tdfx_do_pio_rd(piod);
755 return tdfx_do_pio_wt(piod);
762 /* Calls to ioctl(2) eventually end up here. Unhandled ioctls return an ENXIO,
763 * normally, you would read in the data pointed to by data, then write your
764 * output to it. The ioctl *should* normally return zero if everything is
765 * alright, but 3dfx didn't make it that way...
767 * For all of the ioctl code, in the event of a real error,
768 * we return -Exxxx rather than simply Exxxx. The reason for this
769 * is that the ioctls actually RET information back to the program
770 * sometimes, rather than filling it in the passed structure. We
771 * want to distinguish errors from useful data, and maintain compatibility.
773 * There is this portion of the proc struct called p_retval[], we can store a
774 * return value in td->td_retval[0] and place the return value if it is positive
775 * in there, then we can return 0 (good). If the return value is negative, we
776 * can return -retval and the error should be properly handled.
779 tdfx_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
782 struct tdfx_pio_data *piod = (struct tdfx_pio_data*)data;
784 printf("IOCTL'd by #%d, cmd: 0x%x, data: %p\n", td->td_proc->p_pid, (u_int32_t)cmd,
787 switch(_IOC_TYPE(cmd)) {
788 /* Return the real error if negative, or simply stick the valid return
789 * in td->td_retval */
791 /* The '3'(0x33) type IOCTL is for querying the installed cards */
792 if((retval = tdfx_do_query(cmd, piod)) > 0) td->td_retval[0] = retval;
796 /* The 0 type IOCTL is for programmed I/O methods */
797 if((tdfx_do_pio(cmd, piod)) > 0) td->td_retval[0] = retval;
801 /* Technically, we won't reach this from linux emu, but when glide
802 * finally gets ported, watch out! */
804 printf("Bad IOCTL from #%d\n", td->td_proc->p_pid);
812 /* This is the device driver struct. This is sent to the driver subsystem to
813 * register the method structure and the info strcut space for this particular
814 * instance of the driver.
816 static driver_t tdfx_driver = {
819 sizeof(struct tdfx_softc),
822 /* Tell Mr. Kernel about us! */
823 DRIVER_MODULE(tdfx, pci, tdfx_driver, tdfx_devclass, 0, 0);
824 MODULE_DEPEND(tdfx, mem, 1, 1, 1);
825 MODULE_VERSION(tdfx, 1);