Lines Matching +full:dfx +full:- +full:bus

1 /*-
2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 2000-2001 by Coleman Kane <cokane@FreeBSD.org>
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.
44 #include <sys/bus.h>
67 /* rman.h depends on machine/bus.h */
69 #include <machine/bus.h>
89 static MALLOC_DEFINE(M_TDFX,"tdfx_driver","3DFX Graphics[/2D]/3D Accelerators");
116 device_set_desc(dev, "3DFX Voodoo II 3D Accelerator"); in tdfx_probe()
119 device_set_desc(dev, "3DFX Voodoo Banshee 2D/3D Graphics Accelerator"); in tdfx_probe()
122 device_set_desc(dev, "3DFX Voodoo3 2D/3D Graphics Accelerator"); in tdfx_probe()
125 device_set_desc(dev, "3DFX Voodoo Graphics 3D Accelerator"); in tdfx_probe()
154 tdfx_info->dev = dev; in tdfx_attach()
155 tdfx_info->vendor = pci_get_vendor(dev); in tdfx_attach()
156 tdfx_info->type = pci_get_devid(dev) >> 16; in tdfx_attach()
157 tdfx_info->bus = pci_get_bus(dev); in tdfx_attach()
158 tdfx_info->dv = pci_get_slot(dev); in tdfx_attach()
159 tdfx_info->curFile = NULL; in tdfx_attach()
166 tdfx_info->addr0 = (pci_read_config(dev, 0x10, 4) & 0xffff0000); in tdfx_attach()
168 device_printf(dev, "Base0 @ 0x%x\n", tdfx_info->addr0); in tdfx_attach()
171 tdfx_info->memrange = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in tdfx_attach()
173 if(tdfx_info->memrange == NULL) { in tdfx_attach()
177 tdfx_info->memrid = 0; in tdfx_attach()
180 tdfx_info->memrid = rid; in tdfx_attach()
183 (unsigned int)rman_get_start(tdfx_info->memrange)); in tdfx_attach()
191 tdfx_info->addr1 = (pci_read_config(dev, 0x14, 4) & 0xffff0000); in tdfx_attach()
193 device_printf(dev, "Base1 @ 0x%x\n", tdfx_info->addr1); in tdfx_attach()
195 tdfx_info->memrange2 = bus_alloc_resource_any(dev, in tdfx_attach()
197 if(tdfx_info->memrange2 == NULL) { in tdfx_attach()
201 tdfx_info->memrid2 = 0; in tdfx_attach()
204 tdfx_info->memrid2 = rid; in tdfx_attach()
208 tdfx_info->pio0 = pci_read_config(dev, 0x2c, 2); in tdfx_attach()
209 tdfx_info->pio0max = pci_read_config(dev, 0x30, 2) + tdfx_info->pio0; in tdfx_attach()
210 tdfx_info->piorange = bus_alloc_resource_any(dev, in tdfx_attach()
212 if(tdfx_info->piorange == NULL) { in tdfx_attach()
216 tdfx_info->piorid = 0; in tdfx_attach()
219 tdfx_info->piorid = rid; in tdfx_attach()
222 tdfx_info->addr1 = 0; in tdfx_attach()
223 tdfx_info->memrange2 = NULL; in tdfx_attach()
224 tdfx_info->piorange = NULL; in tdfx_attach()
236 return -1; in tdfx_attach()
240 * make_dev registers the cdev to access the 3dfx card from /dev in tdfx_attach()
245 tdfx_info->devt = make_dev(&tdfx_cdev, device_get_unit(dev), in tdfx_attach()
246 UID_ROOT, GID_WHEEL, 0600, "3dfx%x", device_get_unit(dev)); in tdfx_attach()
247 tdfx_info->devt->si_drv1 = tdfx_info; in tdfx_attach()
259 bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid, in tdfx_detach()
260 tdfx_info->memrange); in tdfx_detach()
265 if(tdfx_info->memrange2 != NULL) in tdfx_detach()
266 bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid2, in tdfx_detach()
267 tdfx_info->memrange); in tdfx_detach()
268 /* if(tdfx_info->piorange != NULL) in tdfx_detach()
269 bus_release_resource(dev, SYS_RES_IOPORT, tdfx_info->piorid, in tdfx_detach()
270 tdfx_info->piorange);*/ in tdfx_detach()
282 destroy_dev(tdfx_info->devt); in tdfx_detach()
303 retval = mem_range_attr_set(&tdfx_info->mrdesc, &act); in tdfx_clrmtrr()
310 * This is the MTRR setting function for the 3dfx card. It is called from in tdfx_setmtrr()
321 tdfx_info->mrdesc.mr_len = 0x400000; in tdfx_setmtrr()
325 tdfx_info->mrdesc.mr_base = tdfx_info->addr0 & 0xfffe0000; in tdfx_setmtrr()
329 tdfx_info->mrdesc.mr_len = 0x1000000; in tdfx_setmtrr()
333 tdfx_info->mrdesc.mr_base = tdfx_info->addr1 & 0xfffe0000; in tdfx_setmtrr()
344 tdfx_info->mrdesc.mr_flags = MDF_WRITECOMBINE; in tdfx_setmtrr()
345 bcopy("tdfx", &tdfx_info->mrdesc.mr_owner, 4); in tdfx_setmtrr()
347 retval = mem_range_attr_set(&tdfx_info->mrdesc, &act); in tdfx_setmtrr()
358 tdfx_info->mrdesc.mr_flags = MDF_UNCACHEABLE; in tdfx_setmtrr()
360 tdfx_info->mrdesc.mr_len = 0x1000; in tdfx_setmtrr()
367 (u_int32_t)tdfx_info->mrdesc.mr_base); in tdfx_setmtrr()
383 * The open cdev method handles open(2) calls to /dev/3dfx[n] in tdfx_open()
386 struct tdfx_softc *tdfx_info = dev->si_drv1; in tdfx_open()
387 if(tdfx_info->busy != 0) return EBUSY; in tdfx_open()
389 printf("3dfx: Opened by #%d\n", td->td_proc->p_pid); in tdfx_open()
392 tdfx_info->busy++; in tdfx_open()
400 * The close cdev method handles close(2) calls to /dev/3dfx[n] in tdfx_close()
403 struct tdfx_softc *tdfx_info = dev->si_drv1; in tdfx_close()
404 if(tdfx_info->busy == 0) return EBADF; in tdfx_close()
405 tdfx_info->busy = 0; in tdfx_close()
407 printf("Closed by #%d\n", td->td_proc->p_pid); in tdfx_close()
426 /*tdfx_info = dev->si_drv1; */ in tdfx_mmap()
438 return -1; in tdfx_mmap()
442 if((offset & 0xff000000) == tdfx_info[0]->addr0) { in tdfx_mmap()
444 *paddr = rman_get_start(tdfx_info[0]->memrange) + offset; in tdfx_mmap()
450 if((offset & 0xff000000) == tdfx_info[1]->addr0) { in tdfx_mmap()
452 *paddr = rman_get_start(tdfx_info[1]->memrange) + in tdfx_mmap()
459 /*if(tdfx_info->memrange2 != NULL && (offset & 0xff000000) == in tdfx_mmap()
460 tdfx_info->addr1) { in tdfx_mmap()
462 return atop(rman_get_start(tdfx_info[1]->memrange2) + offset); in tdfx_mmap()
466 /* atop -> address to page in tdfx_mmap()
467 * rman_get_start, get the (struct resource*)->r_start member, in tdfx_mmap()
470 return -1; in tdfx_mmap()
486 /* Various return values 8bit-32bit */ in tdfx_query_fetch()
494 /*piod->device &= 0xf;*/ in tdfx_query_fetch()
495 if((piod == NULL) ||(tdfx_count <= piod->device) || in tdfx_query_fetch()
496 (piod->device < 0)) { in tdfx_query_fetch()
500 return -EINVAL; in tdfx_query_fetch()
504 piod->device); in tdfx_query_fetch()
506 if(tdfx_info == NULL) return -ENXIO; in tdfx_query_fetch()
511 switch(piod->port) { in tdfx_query_fetch()
513 if(piod->size != 2) return -EINVAL; in tdfx_query_fetch()
514 return -copyout(&tdfx_info->vendor, piod->value, piod->size); in tdfx_query_fetch()
516 if(piod->size != 2) return -EINVAL; in tdfx_query_fetch()
517 return -copyout(&tdfx_info->type, piod->value, piod->size); in tdfx_query_fetch()
519 if(piod->size != 4) return -EINVAL; in tdfx_query_fetch()
520 return -copyout(&tdfx_info->addr0, piod->value, piod->size); in tdfx_query_fetch()
522 if(piod->size != 4) return -EINVAL; in tdfx_query_fetch()
523 return -copyout(&tdfx_info->addr1, piod->value, piod->size); in tdfx_query_fetch()
525 if(piod->size != 1) return -EINVAL; in tdfx_query_fetch()
528 if(piod->size != 2) return -EINVAL; in tdfx_query_fetch()
531 if(piod->size != 2) return -EINVAL; in tdfx_query_fetch()
534 if(piod->size != 4) return -EINVAL; in tdfx_query_fetch()
537 if(piod->size != 1) return -EINVAL; in tdfx_query_fetch()
540 if(piod->size != 4) return -EINVAL; in tdfx_query_fetch()
543 return -EINVAL; in tdfx_query_fetch()
547 switch(piod->size) { in tdfx_query_fetch()
549 ret_byte = pci_read_config(tdfx_info[piod->device].dev, in tdfx_query_fetch()
550 piod->port, 1); in tdfx_query_fetch()
551 return -copyout(&ret_byte, piod->value, 1); in tdfx_query_fetch()
553 ret_word = pci_read_config(tdfx_info[piod->device].dev, in tdfx_query_fetch()
554 piod->port, 2); in tdfx_query_fetch()
555 return -copyout(&ret_word, piod->value, 2); in tdfx_query_fetch()
557 ret_dword = pci_read_config(tdfx_info[piod->device].dev, in tdfx_query_fetch()
558 piod->port, 4); in tdfx_query_fetch()
559 return -copyout(&ret_dword, piod->value, 4); in tdfx_query_fetch()
561 return -EINVAL; in tdfx_query_fetch()
580 if((piod == NULL) || (piod->device >= (tdfx_count & in tdfx_query_update()
585 return -EINVAL; in tdfx_query_update()
589 piod->device); in tdfx_query_update()
590 if(tdfx_info == NULL) return -ENXIO; in tdfx_query_update()
597 switch(piod->port) { in tdfx_query_update()
599 if(piod->size != 2) return -EINVAL; in tdfx_query_update()
602 if(piod->size != 4) return -EINVAL; in tdfx_query_update()
605 if(piod->size != 4) return -EINVAL; in tdfx_query_update()
608 if(piod->size != 4) return -EINVAL; in tdfx_query_update()
611 if(piod->size != 4) return -EINVAL; in tdfx_query_update()
614 return -EINVAL; in tdfx_query_update()
617 retval = pci_read_config(tdfx_info->dev, piod->port & ~3, 4); in tdfx_query_update()
621 switch (piod->size) { in tdfx_query_update()
623 error = copyin(piod->value, &ret_byte, 1); in tdfx_query_update()
625 return -error; in tdfx_query_update()
626 preval = ret_byte << (8 * (piod->port & 0x3)); in tdfx_query_update()
627 mask = 0xff << (8 * (piod->port & 0x3)); in tdfx_query_update()
630 error = copyin(piod->value, &ret_word, 2); in tdfx_query_update()
632 return -error; in tdfx_query_update()
633 preval = ret_word << (8 * (piod->port & 0x3)); in tdfx_query_update()
634 mask = 0xffff << (8 * (piod->port & 0x3)); in tdfx_query_update()
637 error = copyin(piod->value, &ret_dword, 4); in tdfx_query_update()
639 return -error; in tdfx_query_update()
644 return -EINVAL; in tdfx_query_update()
648 pci_write_config(tdfx_info->dev, piod->port & ~3, retval, 4); in tdfx_query_update()
664 (struct tdfx_softc*)devclass_get_softc(tdfx_devclass, piod->device); in tdfx_do_pio_rd()
667 if(((piod->port != VGA_INPUT_STATUS_1C) || (piod->port != SC_INDEX) || in tdfx_do_pio_rd()
668 (piod->port != SC_DATA) || (piod->port != VGA_MISC_OUTPUT_READ)) && in tdfx_do_pio_rd()
669 (piod->port < tdfx_info->pio0) && (piod->port > tdfx_info->pio0max)) in tdfx_do_pio_rd()
670 return -EPERM; in tdfx_do_pio_rd()
673 if(piod->size != 1) { in tdfx_do_pio_rd()
674 return -EINVAL; in tdfx_do_pio_rd()
678 workport = piod->port; in tdfx_do_pio_rd()
680 return copyout(&ret_byte, piod->value, sizeof(u_int8_t)); in tdfx_do_pio_rd()
690 tdfx_softc*)devclass_get_softc(tdfx_devclass, piod->device); in tdfx_do_pio_wt()
693 if(((piod->port != SC_INDEX) && (piod->port != SC_DATA) && in tdfx_do_pio_wt()
694 (piod->port != VGA_MISC_OUTPUT_READ)) /* Can't write VGA_ST_1C */ && in tdfx_do_pio_wt()
695 (piod->port < tdfx_info->pio0) && (piod->port > tdfx_info->pio0max)) in tdfx_do_pio_wt()
696 return -EPERM; in tdfx_do_pio_wt()
699 if(piod->size != 1) { in tdfx_do_pio_wt()
700 return -EINVAL; in tdfx_do_pio_wt()
704 int error = -copyin(piod->value, &ret_byte, sizeof(u_int8_t)); in tdfx_do_pio_wt()
706 workport = piod->port; in tdfx_do_pio_wt()
715 /* There are three sub-commands to the query 0x33 */ in tdfx_do_query()
727 /* In case we are thrown a bogus sub-command! */ in tdfx_do_query()
729 printf("Bad Sub-cmd: 0x%x\n", _IOC_NR(cmd)); in tdfx_do_query()
731 return -EINVAL; in tdfx_do_query()
747 return -EINVAL; in tdfx_do_pio()
754 * alright, but 3dfx didn't make it that way...
757 * we return -Exxxx rather than simply Exxxx. The reason for this
763 * return value in td->td_retval[0] and place the return value if it is positive
765 * can return -retval and the error should be properly handled.
773 printf("IOCTL'd by #%d, cmd: 0x%x, data: %p\n", td->td_proc->p_pid, (u_int32_t)cmd, in tdfx_ioctl()
778 * in td->td_retval */ in tdfx_ioctl()
781 if((retval = tdfx_do_query(cmd, piod)) > 0) td->td_retval[0] = retval; in tdfx_ioctl()
782 else return -retval; in tdfx_ioctl()
786 if((tdfx_do_pio(cmd, piod)) > 0) td->td_retval[0] = retval; in tdfx_ioctl()
787 else return -retval; in tdfx_ioctl()
793 printf("Bad IOCTL from #%d\n", td->td_proc->p_pid); in tdfx_ioctl()