2003-08-24 17:55:58 +00:00
|
|
|
/*-
|
2001-03-20 19:34:22 +00:00
|
|
|
* Copyright (c) 2000-2001 by Coleman Kane <cokane@FreeBSD.org>
|
2000-06-22 05:37:17 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Gardner Buchanan.
|
|
|
|
* 4. The name of Gardner Buchanan may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-06-21 20:09:31 +00:00
|
|
|
/* 3dfx driver for FreeBSD 4.x - Finished 11 May 2000, 12:25AM ET
|
|
|
|
*
|
2001-03-20 19:34:22 +00:00
|
|
|
* Copyright (C) 2000-2001, by Coleman Kane <cokane@FreeBSD.org>,
|
2000-06-21 20:09:31 +00:00
|
|
|
* based upon the 3dfx driver written for linux, by Daryll Straus, Jon Taylor,
|
|
|
|
* and Jens Axboe, located at http://linux.3dfx.com.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/filio.h>
|
|
|
|
#include <sys/ioccom.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/malloc.h>
|
2000-06-21 20:09:31 +00:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
2003-08-22 07:08:17 +00:00
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
2000-06-21 20:09:31 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_kern.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
|
|
|
|
/* rman.h depends on machine/bus.h */
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
2000-06-24 06:20:55 +00:00
|
|
|
|
2000-06-21 20:09:31 +00:00
|
|
|
#include <dev/tdfx/tdfx_io.h>
|
|
|
|
#include <dev/tdfx/tdfx_vars.h>
|
|
|
|
#include <dev/tdfx/tdfx_pci.h>
|
|
|
|
|
|
|
|
|
|
|
|
static devclass_t tdfx_devclass;
|
|
|
|
|
|
|
|
|
|
|
|
static int tdfx_count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Set up the boot probe/attach routines */
|
|
|
|
static device_method_t tdfx_methods[] = {
|
|
|
|
DEVMETHOD(device_probe, tdfx_probe),
|
|
|
|
DEVMETHOD(device_attach, tdfx_attach),
|
|
|
|
DEVMETHOD(device_detach, tdfx_detach),
|
|
|
|
DEVMETHOD(device_shutdown, tdfx_shutdown),
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
2005-10-31 15:41:29 +00:00
|
|
|
MALLOC_DEFINE(M_TDFX,"tdfx_driver","3DFX Graphics[/2D]/3D Accelerator(s)");
|
2000-06-21 20:09:31 +00:00
|
|
|
|
|
|
|
/* Char. Dev. file operations structure */
|
|
|
|
static struct cdevsw tdfx_cdev = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_flags = D_NEEDGIANT,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = tdfx_open,
|
|
|
|
.d_close = tdfx_close,
|
|
|
|
.d_ioctl = tdfx_ioctl,
|
|
|
|
.d_mmap = tdfx_mmap,
|
|
|
|
.d_name = "tdfx",
|
2000-06-21 20:09:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_probe(device_t dev)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* probe routine called on kernel boot to register supported devices. We get
|
|
|
|
* a device structure to work with, and we can test the VENDOR/DEVICE IDs to
|
2005-03-01 07:50:12 +00:00
|
|
|
* see if this PCI device is one that we support. Return BUS_PRROBE_DEFAULT
|
|
|
|
* if yes, ENXIO if not.
|
2000-06-21 20:09:31 +00:00
|
|
|
*/
|
|
|
|
switch(pci_get_devid(dev)) {
|
|
|
|
case PCI_DEVICE_ALLIANCE_AT3D:
|
|
|
|
device_set_desc(dev, "ProMotion At3D 3D Accelerator");
|
2005-03-01 07:50:12 +00:00
|
|
|
return BUS_PROBE_DEFAULT;
|
2000-06-21 20:09:31 +00:00
|
|
|
case PCI_DEVICE_3DFX_VOODOO2:
|
|
|
|
device_set_desc(dev, "3DFX Voodoo II 3D Accelerator");
|
2005-03-01 07:50:12 +00:00
|
|
|
return BUS_PROBE_DEFAULT;
|
2000-08-28 04:28:53 +00:00
|
|
|
/*case PCI_DEVICE_3DFX_BANSHEE:
|
2000-06-21 20:09:31 +00:00
|
|
|
device_set_desc(dev, "3DFX Voodoo Banshee 2D/3D Graphics Accelerator");
|
2005-03-01 07:50:12 +00:00
|
|
|
return BUS_PROBE_DEFAULT;
|
2000-06-21 20:09:31 +00:00
|
|
|
case PCI_DEVICE_3DFX_VOODOO3:
|
|
|
|
device_set_desc(dev, "3DFX Voodoo3 2D/3D Graphics Accelerator");
|
2005-03-01 07:50:12 +00:00
|
|
|
return BUS_PROBE_DEFAULT;*/
|
2000-06-21 20:09:31 +00:00
|
|
|
case PCI_DEVICE_3DFX_VOODOO1:
|
|
|
|
device_set_desc(dev, "3DFX Voodoo Graphics 3D Accelerator");
|
2005-03-01 07:50:12 +00:00
|
|
|
return BUS_PROBE_DEFAULT;
|
2000-06-21 20:09:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_attach(device_t dev) {
|
|
|
|
/*
|
|
|
|
* The attach routine is called after the probe routine successfully says it
|
|
|
|
* supports a given card. We now proceed to initialize this card for use with
|
|
|
|
* the system. I want to map the device memory for userland allocation and
|
|
|
|
* fill an information structure with information on this card. I'd also like
|
|
|
|
* to set Write Combining with the MTRR code so that we can hopefully speed
|
|
|
|
* up memory writes. The last thing is to register the character device
|
|
|
|
* interface to the card, so we can open it from /dev/3dfxN, where N is a
|
|
|
|
* small, whole number.
|
|
|
|
*/
|
|
|
|
struct tdfx_softc *tdfx_info;
|
|
|
|
u_long val;
|
|
|
|
/* rid value tells bus_alloc_resource where to find the addresses of ports or
|
|
|
|
* of memory ranges in the PCI config space*/
|
2003-09-02 17:30:40 +00:00
|
|
|
int rid = PCIR_BAR(0);
|
2000-06-21 20:09:31 +00:00
|
|
|
|
|
|
|
/* Increment the card counter (for the ioctl code) */
|
|
|
|
tdfx_count++;
|
|
|
|
|
|
|
|
/* Enable MemMap on Voodoo */
|
|
|
|
val = pci_read_config(dev, PCIR_COMMAND, 2);
|
|
|
|
val |= (PCIM_CMD_MEMEN);
|
|
|
|
pci_write_config(dev, PCIR_COMMAND, val, 2);
|
|
|
|
val = pci_read_config(dev, PCIR_COMMAND, 2);
|
|
|
|
|
|
|
|
/* Fill the soft config struct with info about this device*/
|
|
|
|
tdfx_info = device_get_softc(dev);
|
|
|
|
tdfx_info->dev = dev;
|
|
|
|
tdfx_info->vendor = pci_get_vendor(dev);
|
|
|
|
tdfx_info->type = pci_get_devid(dev) >> 16;
|
|
|
|
tdfx_info->bus = pci_get_bus(dev);
|
|
|
|
tdfx_info->dv = pci_get_slot(dev);
|
|
|
|
tdfx_info->curFile = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the Memory Location from the PCI Config, mask out lower word, since
|
|
|
|
* the config space register is only one word long (this is nicer than a
|
|
|
|
* bitshift).
|
|
|
|
*/
|
|
|
|
tdfx_info->addr0 = (pci_read_config(dev, 0x10, 4) & 0xffff0000);
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
device_printf(dev, "Base0 @ 0x%x\n", tdfx_info->addr0);
|
|
|
|
#endif
|
|
|
|
/* Notify the VM that we will be mapping some memory later */
|
2004-03-17 17:50:55 +00:00
|
|
|
tdfx_info->memrange = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
|
|
|
|
&rid, RF_ACTIVE | RF_SHAREABLE);
|
2000-06-21 20:09:31 +00:00
|
|
|
if(tdfx_info->memrange == NULL) {
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
device_printf(dev, "Error mapping mem, won't be able to use mmap()\n");
|
|
|
|
#endif
|
|
|
|
tdfx_info->memrid = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tdfx_info->memrid = rid;
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
device_printf(dev, "Mapped to: 0x%x\n",
|
|
|
|
(unsigned int)rman_get_start(tdfx_info->memrange));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-07-19 05:41:14 +00:00
|
|
|
/* Setup for Voodoo3 and Banshee, PIO and an extram Memrange */
|
|
|
|
if(pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3 ||
|
|
|
|
pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE) {
|
2000-08-01 05:10:29 +00:00
|
|
|
rid = 0x14; /* 2nd mem map */
|
2000-07-19 05:41:14 +00:00
|
|
|
tdfx_info->addr1 = (pci_read_config(dev, 0x14, 4) & 0xffff0000);
|
|
|
|
#ifdef DEBUG
|
|
|
|
device_printf(dev, "Base1 @ 0x%x\n", tdfx_info->addr1);
|
|
|
|
#endif
|
2004-03-17 17:50:55 +00:00
|
|
|
tdfx_info->memrange2 = bus_alloc_resource_any(dev,
|
|
|
|
SYS_RES_MEMORY, &rid, RF_ACTIVE | RF_SHAREABLE);
|
2000-07-19 05:41:14 +00:00
|
|
|
if(tdfx_info->memrange2 == NULL) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
device_printf(dev, "Mem1 couldn't be allocated, glide may not work.");
|
|
|
|
#endif
|
|
|
|
tdfx_info->memrid2 = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tdfx_info->memrid2 = rid;
|
|
|
|
}
|
|
|
|
/* Now to map the PIO stuff */
|
2000-08-28 04:28:53 +00:00
|
|
|
rid = PCIR_IOBASE0_2;
|
|
|
|
tdfx_info->pio0 = pci_read_config(dev, 0x2c, 2);
|
|
|
|
tdfx_info->pio0max = pci_read_config(dev, 0x30, 2) + tdfx_info->pio0;
|
2004-03-17 17:50:55 +00:00
|
|
|
tdfx_info->piorange = bus_alloc_resource_any(dev,
|
|
|
|
SYS_RES_IOPORT, &rid, RF_ACTIVE | RF_SHAREABLE);
|
2000-07-19 05:41:14 +00:00
|
|
|
if(tdfx_info->piorange == NULL) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
device_printf(dev, "Couldn't map PIO range.");
|
|
|
|
#endif
|
|
|
|
tdfx_info->piorid = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tdfx_info->piorid = rid;
|
2000-08-28 04:28:53 +00:00
|
|
|
}
|
2000-07-19 05:41:14 +00:00
|
|
|
} else {
|
|
|
|
tdfx_info->addr1 = 0;
|
|
|
|
tdfx_info->memrange2 = NULL;
|
|
|
|
tdfx_info->piorange = NULL;
|
|
|
|
}
|
|
|
|
|
2000-06-21 20:09:31 +00:00
|
|
|
/*
|
|
|
|
* Set Writecombining, or at least Uncacheable for the memory region, if we
|
|
|
|
* are able to
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(tdfx_setmtrr(dev) != 0) {
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
device_printf(dev, "Some weird error setting MTRRs");
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
2000-07-19 05:41:14 +00:00
|
|
|
|
2000-06-21 20:09:31 +00:00
|
|
|
/*
|
|
|
|
* make_dev registers the cdev to access the 3dfx card from /dev
|
|
|
|
* use hex here for the dev num, simply to provide better support if > 10
|
|
|
|
* voodoo cards, for the mad. The user must set the link, or use MAKEDEV.
|
|
|
|
* Why would we want that many voodoo cards anyhow?
|
|
|
|
*/
|
2002-09-28 20:56:32 +00:00
|
|
|
tdfx_info->devt = make_dev(&tdfx_cdev, device_get_unit(dev),
|
2002-12-27 16:40:54 +00:00
|
|
|
UID_ROOT, GID_WHEEL, 0600, "3dfx%x", device_get_unit(dev));
|
2000-06-21 20:09:31 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_detach(device_t dev) {
|
|
|
|
struct tdfx_softc* tdfx_info;
|
|
|
|
int retval;
|
|
|
|
tdfx_info = device_get_softc(dev);
|
|
|
|
|
|
|
|
/* Delete allocated resource, of course */
|
2000-07-19 05:41:14 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid,
|
2000-06-21 20:09:31 +00:00
|
|
|
tdfx_info->memrange);
|
2000-07-19 05:41:14 +00:00
|
|
|
|
|
|
|
/* Release extended Voodoo3/Banshee resources */
|
|
|
|
if(pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE ||
|
|
|
|
pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3) {
|
|
|
|
if(tdfx_info->memrange2 != NULL)
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid2,
|
|
|
|
tdfx_info->memrange);
|
2000-08-01 05:10:29 +00:00
|
|
|
/* if(tdfx_info->piorange != NULL)
|
2000-07-19 05:41:14 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, tdfx_info->piorid,
|
2000-08-01 05:10:29 +00:00
|
|
|
tdfx_info->piorange);*/
|
2000-07-19 05:41:14 +00:00
|
|
|
}
|
|
|
|
|
2000-06-21 20:09:31 +00:00
|
|
|
/* Though it is safe to leave the WRCOMB support since the
|
|
|
|
mem driver checks for it, we should remove it in order
|
|
|
|
to free an MTRR for another device */
|
|
|
|
retval = tdfx_clrmtrr(dev);
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
if(retval != 0)
|
|
|
|
printf("tdfx: For some reason, I couldn't clear the mtrr\n");
|
|
|
|
#endif
|
2000-06-23 05:54:01 +00:00
|
|
|
/* Remove device entry when it can no longer be accessed */
|
|
|
|
destroy_dev(tdfx_info->devt);
|
2000-06-21 20:09:31 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_shutdown(device_t dev) {
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
device_printf(dev, "tdfx: Device Shutdown\n");
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_clrmtrr(device_t dev) {
|
|
|
|
/* This function removes the MTRR set by the attach call, so it can be used
|
|
|
|
* in the future by other drivers.
|
|
|
|
*/
|
|
|
|
int retval, act;
|
|
|
|
struct tdfx_softc *tdfx_info = device_get_softc(dev);
|
|
|
|
|
|
|
|
act = MEMRANGE_SET_REMOVE;
|
|
|
|
retval = mem_range_attr_set(&tdfx_info->mrdesc, &act);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_setmtrr(device_t dev) {
|
|
|
|
/*
|
|
|
|
* This is the MTRR setting function for the 3dfx card. It is called from
|
|
|
|
* tdfx_attach. If we can't set the MTRR properly, it's not the end of the
|
|
|
|
* world. We can still continue, just with slightly (very slightly) degraded
|
|
|
|
* performance.
|
|
|
|
*/
|
|
|
|
int retval = 0, act;
|
|
|
|
struct tdfx_softc *tdfx_info = device_get_softc(dev);
|
|
|
|
|
|
|
|
/* The older Voodoo cards have a shorter memrange than the newer ones */
|
|
|
|
if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO1) || (pci_get_devid(dev) ==
|
2000-07-19 05:41:14 +00:00
|
|
|
PCI_DEVICE_3DFX_VOODOO2)) {
|
2000-06-21 20:09:31 +00:00
|
|
|
tdfx_info->mrdesc.mr_len = 0x400000;
|
2000-07-19 05:41:14 +00:00
|
|
|
|
|
|
|
/* The memory descriptor is described as the top 15 bits of the real
|
|
|
|
address */
|
|
|
|
tdfx_info->mrdesc.mr_base = tdfx_info->addr0 & 0xfffe0000;
|
|
|
|
}
|
2000-06-21 20:09:31 +00:00
|
|
|
else if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3) ||
|
2000-07-19 05:41:14 +00:00
|
|
|
(pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE)) {
|
2000-06-21 20:09:31 +00:00
|
|
|
tdfx_info->mrdesc.mr_len = 0x1000000;
|
2000-07-19 05:41:14 +00:00
|
|
|
/* The Voodoo3 and Banshee LFB is the second memory address */
|
|
|
|
/* The memory descriptor is described as the top 15 bits of the real
|
|
|
|
address */
|
|
|
|
tdfx_info->mrdesc.mr_base = tdfx_info->addr1 & 0xfffe0000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2000-06-21 20:09:31 +00:00
|
|
|
/*
|
|
|
|
* The Alliance Pro Motion AT3D was not mentioned in the linux
|
|
|
|
* driver as far as MTRR support goes, so I just won't put the
|
|
|
|
* code in here for it. This is where it should go, though.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Firstly, try to set write combining */
|
|
|
|
tdfx_info->mrdesc.mr_flags = MDF_WRITECOMBINE;
|
|
|
|
bcopy("tdfx", &tdfx_info->mrdesc.mr_owner, 4);
|
|
|
|
act = MEMRANGE_SET_UPDATE;
|
|
|
|
retval = mem_range_attr_set(&tdfx_info->mrdesc, &act);
|
|
|
|
|
|
|
|
if(retval == 0) {
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
device_printf(dev, "MTRR Set Correctly for tdfx\n");
|
|
|
|
#endif
|
|
|
|
} else if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO2) ||
|
|
|
|
(pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO1)) {
|
|
|
|
/* if, for some reason we can't set the WRCOMB range with the V1/V2, we
|
|
|
|
* can still possibly use the UNCACHEABLE region for it instead, and help
|
|
|
|
* out in a small way */
|
|
|
|
tdfx_info->mrdesc.mr_flags = MDF_UNCACHEABLE;
|
|
|
|
/* This length of 1000h was taken from the linux device driver... */
|
|
|
|
tdfx_info->mrdesc.mr_len = 0x1000;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If, for some reason, we can't set the MTRR (N/A?) we may still continue
|
|
|
|
*/
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2005-02-22 18:57:18 +00:00
|
|
|
device_printf(dev, "MTRR Set Type Uncacheable %x\n",
|
|
|
|
(u_int32_t)tdfx_info->mrdesc.mr_base);
|
2000-06-21 20:09:31 +00:00
|
|
|
#endif
|
|
|
|
}
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
else {
|
|
|
|
device_printf(dev, "Couldn't Set MTRR\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
tdfx_open(struct cdev *dev, int flags, int fmt, struct thread *td)
|
2000-06-21 20:09:31 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The open cdev method handles open(2) calls to /dev/3dfx[n]
|
|
|
|
* We can pretty much allow any opening of the device.
|
|
|
|
*/
|
|
|
|
struct tdfx_softc *tdfx_info = devclass_get_softc(tdfx_devclass,
|
2008-09-27 08:51:18 +00:00
|
|
|
UNIT(dev2unit(dev)));
|
2000-06-21 20:09:31 +00:00
|
|
|
if(tdfx_info->busy != 0) return EBUSY;
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2001-09-12 08:38:13 +00:00
|
|
|
printf("3dfx: Opened by #%d\n", td->td_proc->p_pid);
|
2000-06-21 20:09:31 +00:00
|
|
|
#endif
|
|
|
|
/* Set the driver as busy */
|
|
|
|
tdfx_info->busy++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
tdfx_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
|
2000-06-21 20:09:31 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The close cdev method handles close(2) calls to /dev/3dfx[n]
|
|
|
|
* We'll always want to close the device when it's called.
|
|
|
|
*/
|
|
|
|
struct tdfx_softc *tdfx_info = devclass_get_softc(tdfx_devclass,
|
2008-09-27 08:51:18 +00:00
|
|
|
UNIT(dev2unit(dev)));
|
2000-06-21 20:09:31 +00:00
|
|
|
if(tdfx_info->busy == 0) return EBADF;
|
|
|
|
tdfx_info->busy = 0;
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2001-09-12 08:38:13 +00:00
|
|
|
printf("Closed by #%d\n", td->td_proc->p_pid);
|
2000-06-21 20:09:31 +00:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
tdfx_mmap(struct cdev *dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
|
2000-06-21 20:09:31 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* mmap(2) is called by a user process to request that an area of memory
|
|
|
|
* associated with this device be mapped for the process to work with. Nprot
|
|
|
|
* holds the protections requested, PROT_READ, PROT_WRITE, or both.
|
|
|
|
*/
|
2000-10-10 03:51:54 +00:00
|
|
|
|
|
|
|
/**** OLD GET CONFIG ****/
|
|
|
|
/* struct tdfx_softc* tdfx_info; */
|
2000-06-21 20:09:31 +00:00
|
|
|
|
|
|
|
/* Get the configuration for our card XXX*/
|
2000-10-10 03:51:54 +00:00
|
|
|
/*tdfx_info = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass,
|
2008-09-27 08:51:18 +00:00
|
|
|
UNIT(dev2unit(dev)));*/
|
2000-10-10 03:51:54 +00:00
|
|
|
/************************/
|
|
|
|
|
|
|
|
struct tdfx_softc* tdfx_info[2];
|
2000-06-21 20:09:31 +00:00
|
|
|
|
2000-10-10 03:51:54 +00:00
|
|
|
tdfx_info[0] = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, 0);
|
|
|
|
|
2000-06-21 20:09:31 +00:00
|
|
|
/* If, for some reason, its not configured, we bail out */
|
2000-10-10 03:51:54 +00:00
|
|
|
if(tdfx_info[0] == NULL) {
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
printf("tdfx: tdfx_info (softc) is NULL\n");
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
2000-10-10 03:51:54 +00:00
|
|
|
|
2000-06-21 20:09:31 +00:00
|
|
|
/* We must stay within the bound of our address space */
|
2000-10-10 03:51:54 +00:00
|
|
|
if((offset & 0xff000000) == tdfx_info[0]->addr0) {
|
2000-06-21 20:09:31 +00:00
|
|
|
offset &= 0xffffff;
|
2003-02-25 03:21:22 +00:00
|
|
|
*paddr = rman_get_start(tdfx_info[0]->memrange) + offset;
|
|
|
|
return 0;
|
2000-10-10 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(tdfx_count > 1) {
|
|
|
|
tdfx_info[1] = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, 1);
|
|
|
|
if((offset & 0xff000000) == tdfx_info[1]->addr0) {
|
|
|
|
offset &= 0xffffff;
|
2003-02-25 03:21:22 +00:00
|
|
|
*paddr = rman_get_start(tdfx_info[1]->memrange) +
|
|
|
|
offset;
|
|
|
|
return 0;
|
2000-10-10 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
2000-07-19 05:41:14 +00:00
|
|
|
|
|
|
|
/* See if the Banshee/V3 LFB is being requested */
|
2000-10-10 03:51:54 +00:00
|
|
|
/*if(tdfx_info->memrange2 != NULL && (offset & 0xff000000) ==
|
2000-08-01 05:10:29 +00:00
|
|
|
tdfx_info->addr1) {
|
2000-07-19 05:41:14 +00:00
|
|
|
offset &= 0xffffff;
|
2000-10-10 03:51:54 +00:00
|
|
|
return atop(rman_get_start(tdfx_info[1]->memrange2) + offset);
|
|
|
|
}*/ /* VoodooNG code */
|
2000-06-21 20:09:31 +00:00
|
|
|
|
2000-10-10 03:51:54 +00:00
|
|
|
/* The ret call */
|
2000-06-21 20:09:31 +00:00
|
|
|
/* atop -> address to page
|
|
|
|
* rman_get_start, get the (struct resource*)->r_start member,
|
|
|
|
* the mapping base address.
|
|
|
|
*/
|
2000-10-10 03:51:54 +00:00
|
|
|
return -1;
|
2000-06-21 20:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_query_boards(void) {
|
|
|
|
/*
|
|
|
|
* This returns the number of installed tdfx cards, we have been keeping
|
|
|
|
* count, look at tdfx_attach
|
|
|
|
*/
|
|
|
|
return tdfx_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_query_fetch(u_int cmd, struct tdfx_pio_data *piod)
|
|
|
|
{
|
|
|
|
/* XXX Comment this later, after careful inspection and spring cleaning :) */
|
|
|
|
/* Various return values 8bit-32bit */
|
|
|
|
u_int8_t ret_byte;
|
|
|
|
u_int16_t ret_word;
|
|
|
|
u_int32_t ret_dword;
|
|
|
|
struct tdfx_softc* tdfx_info = NULL;
|
|
|
|
|
|
|
|
/* This one depend on the tdfx_* structs being properly initialized */
|
|
|
|
|
|
|
|
/*piod->device &= 0xf;*/
|
|
|
|
if((piod == NULL) ||(tdfx_count <= piod->device) ||
|
|
|
|
(piod->device < 0)) {
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
printf("tdfx: Bad device or internal struct in tdfx_query_fetch\n");
|
|
|
|
#endif
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tdfx_info = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass,
|
|
|
|
piod->device);
|
|
|
|
|
|
|
|
if(tdfx_info == NULL) return -ENXIO;
|
|
|
|
|
|
|
|
/* We must restrict the size reads from the port, since to high or low of a
|
|
|
|
* size witll result in wrong data being passed, and that's bad */
|
|
|
|
/* A few of these were pulled during the attach phase */
|
|
|
|
switch(piod->port) {
|
|
|
|
case PCI_VENDOR_ID_FREEBSD:
|
|
|
|
if(piod->size != 2) return -EINVAL;
|
|
|
|
copyout(&tdfx_info->vendor, piod->value, piod->size);
|
|
|
|
return 0;
|
|
|
|
case PCI_DEVICE_ID_FREEBSD:
|
|
|
|
if(piod->size != 2) return -EINVAL;
|
|
|
|
copyout(&tdfx_info->type, piod->value, piod->size);
|
|
|
|
return 0;
|
|
|
|
case PCI_BASE_ADDRESS_0_FREEBSD:
|
|
|
|
if(piod->size != 4) return -EINVAL;
|
|
|
|
copyout(&tdfx_info->addr0, piod->value, piod->size);
|
|
|
|
return 0;
|
2000-08-28 04:28:53 +00:00
|
|
|
case PCI_BASE_ADDRESS_1_FREEBSD:
|
|
|
|
if(piod->size != 4) return -EINVAL;
|
|
|
|
copyout(&tdfx_info->addr1, piod->value, piod->size);
|
|
|
|
return 0;
|
|
|
|
case PCI_PRIBUS_FREEBSD:
|
|
|
|
if(piod->size != 1) return -EINVAL;
|
|
|
|
break;
|
|
|
|
case PCI_IOBASE_0_FREEBSD:
|
|
|
|
if(piod->size != 2) return -EINVAL;
|
|
|
|
break;
|
|
|
|
case PCI_IOLIMIT_0_FREEBSD:
|
|
|
|
if(piod->size != 2) return -EINVAL;
|
|
|
|
break;
|
2000-06-21 20:09:31 +00:00
|
|
|
case SST1_PCI_SPECIAL1_FREEBSD:
|
|
|
|
if(piod->size != 4) return -EINVAL;
|
|
|
|
break;
|
|
|
|
case PCI_REVISION_ID_FREEBSD:
|
|
|
|
if(piod->size != 1) return -EINVAL;
|
|
|
|
break;
|
|
|
|
case SST1_PCI_SPECIAL4_FREEBSD:
|
|
|
|
if(piod->size != 4) return -EINVAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Read the value and return */
|
|
|
|
switch(piod->size) {
|
|
|
|
case 1:
|
|
|
|
ret_byte = pci_read_config(tdfx_info[piod->device].dev,
|
|
|
|
piod->port, 1);
|
|
|
|
copyout(&ret_byte, piod->value, 1);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ret_word = pci_read_config(tdfx_info[piod->device].dev,
|
|
|
|
piod->port, 2);
|
|
|
|
copyout(&ret_word, piod->value, 2);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
ret_dword = pci_read_config(tdfx_info[piod->device].dev,
|
|
|
|
piod->port, 4);
|
|
|
|
copyout(&ret_dword, piod->value, 4);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_query_update(u_int cmd, struct tdfx_pio_data *piod)
|
|
|
|
{
|
|
|
|
/* XXX Comment this later, after careful inspection and spring cleaning :) */
|
|
|
|
/* Return vals */
|
|
|
|
u_int8_t ret_byte;
|
|
|
|
u_int16_t ret_word;
|
|
|
|
u_int32_t ret_dword;
|
|
|
|
|
|
|
|
/* Port vals, mask */
|
|
|
|
u_int32_t retval, preval, mask;
|
|
|
|
struct tdfx_softc* tdfx_info = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if((piod == NULL) || (piod->device >= (tdfx_count &
|
|
|
|
0xf))) {
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
printf("tdfx: Bad struct or device in tdfx_query_update\n");
|
|
|
|
#endif
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tdfx_info = (struct tdfx_softc*)devclass_get_softc(tdfx_devclass,
|
|
|
|
piod->device);
|
|
|
|
if(tdfx_info == NULL) return -ENXIO;
|
|
|
|
/* Code below this line in the fuction was taken from the
|
|
|
|
* Linux driver and converted for freebsd. */
|
|
|
|
|
|
|
|
/* Check the size for all the ports, to make sure stuff doesn't get messed up
|
|
|
|
* by poorly written clients */
|
|
|
|
|
|
|
|
switch(piod->port) {
|
|
|
|
case PCI_COMMAND_FREEBSD:
|
|
|
|
if(piod->size != 2) return -EINVAL;
|
|
|
|
break;
|
|
|
|
case SST1_PCI_SPECIAL1_FREEBSD:
|
|
|
|
if(piod->size != 4) return -EINVAL;
|
|
|
|
break;
|
|
|
|
case SST1_PCI_SPECIAL2_FREEBSD:
|
|
|
|
if(piod->size != 4) return -EINVAL;
|
|
|
|
break;
|
|
|
|
case SST1_PCI_SPECIAL3_FREEBSD:
|
|
|
|
if(piod->size != 4) return -EINVAL;
|
|
|
|
break;
|
|
|
|
case SST1_PCI_SPECIAL4_FREEBSD:
|
|
|
|
if(piod->size != 4) return -EINVAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/* Read the current value */
|
|
|
|
retval = pci_read_config(tdfx_info->dev, piod->port & ~3, 4);
|
|
|
|
|
|
|
|
/* These set up a mask to use, since apparently they wanted to write 4 bytes
|
|
|
|
* at once to the ports */
|
|
|
|
switch (piod->size) {
|
|
|
|
case 1:
|
|
|
|
copyin(piod->value, &ret_byte, 1);
|
|
|
|
preval = ret_byte << (8 * (piod->port & 0x3));
|
|
|
|
mask = 0xff << (8 * (piod->port & 0x3));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
copyin(piod->value, &ret_word, 2);
|
|
|
|
preval = ret_word << (8 * (piod->port & 0x3));
|
|
|
|
mask = 0xffff << (8 * (piod->port & 0x3));
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
copyin(piod->value, &ret_dword, 4);
|
|
|
|
preval = ret_dword;
|
|
|
|
mask = ~0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/* Finally, combine the values and write it to the port */
|
|
|
|
retval = (retval & ~mask) | preval;
|
|
|
|
pci_write_config(tdfx_info->dev, piod->port & ~3, retval, 4);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-07-19 05:41:14 +00:00
|
|
|
/* For both of these, I added a variable named workport of type u_int so
|
|
|
|
* that I could eliminate the warning about my data type size. The
|
|
|
|
* applications expect the port to be of type short, so I needed to change
|
|
|
|
* this within the function */
|
2000-06-21 20:09:31 +00:00
|
|
|
static int
|
|
|
|
tdfx_do_pio_rd(struct tdfx_pio_data *piod)
|
|
|
|
{
|
|
|
|
/* Return val */
|
|
|
|
u_int8_t ret_byte;
|
2000-07-19 05:41:14 +00:00
|
|
|
u_int workport;
|
2000-08-28 04:28:53 +00:00
|
|
|
struct tdfx_softc *tdfx_info =
|
|
|
|
(struct tdfx_softc*)devclass_get_softc(tdfx_devclass, piod->device);
|
|
|
|
|
2000-06-21 20:09:31 +00:00
|
|
|
/* Restricts the access of ports other than those we use */
|
2000-08-28 04:28:53 +00:00
|
|
|
if(((piod->port != VGA_INPUT_STATUS_1C) || (piod->port != SC_INDEX) ||
|
|
|
|
(piod->port != SC_DATA) || (piod->port != VGA_MISC_OUTPUT_READ)) &&
|
|
|
|
(piod->port < tdfx_info->pio0) && (piod->port > tdfx_info->pio0max))
|
2000-06-21 20:09:31 +00:00
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
/* All VGA STATUS REGS are byte registers, size should never be > 1 */
|
|
|
|
if(piod->size != 1) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the data to the intended port */
|
2000-07-19 05:41:14 +00:00
|
|
|
workport = piod->port;
|
|
|
|
ret_byte = inb(workport);
|
2000-06-21 20:09:31 +00:00
|
|
|
copyout(&ret_byte, piod->value, sizeof(u_int8_t));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_do_pio_wt(struct tdfx_pio_data *piod)
|
|
|
|
{
|
|
|
|
/* return val */
|
|
|
|
u_int8_t ret_byte;
|
2000-07-19 05:41:14 +00:00
|
|
|
u_int workport;
|
2000-08-28 04:28:53 +00:00
|
|
|
struct tdfx_softc *tdfx_info = (struct
|
|
|
|
tdfx_softc*)devclass_get_softc(tdfx_devclass, piod->device);
|
2000-06-21 20:09:31 +00:00
|
|
|
/* Replace old switch w/ massive if(...) */
|
|
|
|
/* Restricts the access of ports other than those we use */
|
2000-08-28 04:28:53 +00:00
|
|
|
if(((piod->port != SC_INDEX) && (piod->port != SC_DATA) &&
|
|
|
|
(piod->port != VGA_MISC_OUTPUT_READ)) /* Can't write VGA_ST_1C */ &&
|
|
|
|
(piod->port < tdfx_info->pio0) && (piod->port > tdfx_info->pio0max))
|
2000-06-21 20:09:31 +00:00
|
|
|
return -EPERM;
|
|
|
|
|
|
|
|
/* All VGA STATUS REGS are byte registers, size should never be > 1 */
|
|
|
|
if(piod->size != 1) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the data to the intended port */
|
|
|
|
copyin(piod->value, &ret_byte, sizeof(u_int8_t));
|
2000-07-19 05:41:14 +00:00
|
|
|
workport = piod->port;
|
|
|
|
outb(workport, ret_byte);
|
2000-06-21 20:09:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_do_query(u_int cmd, struct tdfx_pio_data *piod)
|
|
|
|
{
|
|
|
|
/* There are three sub-commands to the query 0x33 */
|
|
|
|
switch(_IOC_NR(cmd)) {
|
|
|
|
case 2:
|
|
|
|
return tdfx_query_boards();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
return tdfx_query_fetch(cmd, piod);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
return tdfx_query_update(cmd, piod);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* In case we are thrown a bogus sub-command! */
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2000-06-21 20:09:31 +00:00
|
|
|
printf("Bad Sub-cmd: 0x%x\n", _IOC_NR(cmd));
|
|
|
|
#endif
|
|
|
|
return -EINVAL;
|
2003-05-31 18:57:41 +00:00
|
|
|
}
|
2000-06-21 20:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tdfx_do_pio(u_int cmd, struct tdfx_pio_data *piod)
|
|
|
|
{
|
|
|
|
/* Two types of PIO, INPUT and OUTPUT, as the name suggests */
|
|
|
|
switch(_IOC_DIR(cmd)) {
|
|
|
|
case IOCV_OUT:
|
|
|
|
return tdfx_do_pio_rd(piod);
|
|
|
|
break;
|
|
|
|
case IOCV_IN:
|
|
|
|
return tdfx_do_pio_wt(piod);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2003-05-31 18:57:41 +00:00
|
|
|
}
|
2000-06-21 20:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calls to ioctl(2) eventually end up here. Unhandled ioctls return an ENXIO,
|
|
|
|
* normally, you would read in the data pointed to by data, then write your
|
|
|
|
* output to it. The ioctl *should* normally return zero if everything is
|
|
|
|
* alright, but 3dfx didn't make it that way...
|
|
|
|
*
|
|
|
|
* For all of the ioctl code, in the event of a real error,
|
|
|
|
* we return -Exxxx rather than simply Exxxx. The reason for this
|
|
|
|
* is that the ioctls actually RET information back to the program
|
|
|
|
* sometimes, rather than filling it in the passed structure. We
|
|
|
|
* want to distinguish errors from useful data, and maintain compatibility.
|
|
|
|
*
|
|
|
|
* There is this portion of the proc struct called p_retval[], we can store a
|
2001-09-12 08:38:13 +00:00
|
|
|
* return value in td->td_retval[0] and place the return value if it is positive
|
2000-06-21 20:09:31 +00:00
|
|
|
* in there, then we can return 0 (good). If the return value is negative, we
|
|
|
|
* can return -retval and the error should be properly handled.
|
|
|
|
*/
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
tdfx_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
2000-06-21 20:09:31 +00:00
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
struct tdfx_pio_data *piod = (struct tdfx_pio_data*)data;
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2002-11-07 21:19:47 +00:00
|
|
|
printf("IOCTL'd by #%d, cmd: 0x%x, data: %p\n", td->td_proc->p_pid, (u_int32_t)cmd,
|
|
|
|
piod);
|
2000-06-21 20:09:31 +00:00
|
|
|
#endif
|
|
|
|
switch(_IOC_TYPE(cmd)) {
|
|
|
|
/* Return the real error if negative, or simply stick the valid return
|
2001-09-12 08:38:13 +00:00
|
|
|
* in td->td_retval */
|
2000-06-21 20:09:31 +00:00
|
|
|
case 0x33:
|
|
|
|
/* The '3'(0x33) type IOCTL is for querying the installed cards */
|
2001-09-12 08:38:13 +00:00
|
|
|
if((retval = tdfx_do_query(cmd, piod)) > 0) td->td_retval[0] = retval;
|
2000-06-21 20:09:31 +00:00
|
|
|
else return -retval;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
/* The 0 type IOCTL is for programmed I/O methods */
|
2001-09-12 08:38:13 +00:00
|
|
|
if((tdfx_do_pio(cmd, piod)) > 0) td->td_retval[0] = retval;
|
2000-06-21 20:09:31 +00:00
|
|
|
else return -retval;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Technically, we won't reach this from linux emu, but when glide
|
|
|
|
* finally gets ported, watch out! */
|
2000-06-22 05:37:17 +00:00
|
|
|
#ifdef DEBUG
|
2001-09-12 08:38:13 +00:00
|
|
|
printf("Bad IOCTL from #%d\n", td->td_proc->p_pid);
|
2000-06-21 20:09:31 +00:00
|
|
|
#endif
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the device driver struct. This is sent to the driver subsystem to
|
|
|
|
* register the method structure and the info strcut space for this particular
|
|
|
|
* instance of the driver.
|
|
|
|
*/
|
|
|
|
static driver_t tdfx_driver = {
|
|
|
|
"tdfx",
|
|
|
|
tdfx_methods,
|
|
|
|
sizeof(struct tdfx_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Tell Mr. Kernel about us! */
|
|
|
|
DRIVER_MODULE(tdfx, pci, tdfx_driver, tdfx_devclass, 0, 0);
|
2008-03-13 14:08:41 +00:00
|
|
|
MODULE_DEPEND(tdfx, mem, 1, 1, 1);
|
2006-03-03 21:37:38 +00:00
|
|
|
MODULE_VERSION(tdfx, 1);
|