Deleted Added
full compact
tdfx_pci.c (62028) tdfx_pci.c (63488)
1/*
2 * Copyright (c) 2000 by Coleman Kane <cokane@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

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.
30 *
1/*
2 * Copyright (c) 2000 by Coleman Kane <cokane@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

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.
30 *
31 * $FreeBSD: head/sys/dev/tdfx/tdfx_pci.c 62028 2000-06-24 06:20:55Z cokane $
31 * $FreeBSD: head/sys/dev/tdfx/tdfx_pci.c 63488 2000-07-19 05:41:14Z cokane $
32 */
33
34/* 3dfx driver for FreeBSD 4.x - Finished 11 May 2000, 12:25AM ET
35 *
36 * Copyright (C) 2000, by Coleman Kane <cokane@FreeBSD.org>,
37 * based upon the 3dfx driver written for linux, by Daryll Straus, Jon Taylor,
38 * and Jens Axboe, located at http://linux.3dfx.com.
39 */

--- 123 unchanged lines hidden (view full) ---

163 * supports a given card. We now proceed to initialize this card for use with
164 * the system. I want to map the device memory for userland allocation and
165 * fill an information structure with information on this card. I'd also like
166 * to set Write Combining with the MTRR code so that we can hopefully speed
167 * up memory writes. The last thing is to register the character device
168 * interface to the card, so we can open it from /dev/3dfxN, where N is a
169 * small, whole number.
170 */
32 */
33
34/* 3dfx driver for FreeBSD 4.x - Finished 11 May 2000, 12:25AM ET
35 *
36 * Copyright (C) 2000, by Coleman Kane <cokane@FreeBSD.org>,
37 * based upon the 3dfx driver written for linux, by Daryll Straus, Jon Taylor,
38 * and Jens Axboe, located at http://linux.3dfx.com.
39 */

--- 123 unchanged lines hidden (view full) ---

163 * supports a given card. We now proceed to initialize this card for use with
164 * the system. I want to map the device memory for userland allocation and
165 * fill an information structure with information on this card. I'd also like
166 * to set Write Combining with the MTRR code so that we can hopefully speed
167 * up memory writes. The last thing is to register the character device
168 * interface to the card, so we can open it from /dev/3dfxN, where N is a
169 * small, whole number.
170 */
171
172 struct tdfx_softc *tdfx_info;
173 u_long val;
174 /* rid value tells bus_alloc_resource where to find the addresses of ports or
175 * of memory ranges in the PCI config space*/
176 int rid = PCIR_MAPS;
177
178 /* Increment the card counter (for the ioctl code) */
179 tdfx_count++;

--- 17 unchanged lines hidden (view full) ---

197 * Get the Memory Location from the PCI Config, mask out lower word, since
198 * the config space register is only one word long (this is nicer than a
199 * bitshift).
200 */
201 tdfx_info->addr0 = (pci_read_config(dev, 0x10, 4) & 0xffff0000);
202#ifdef DEBUG
203 device_printf(dev, "Base0 @ 0x%x\n", tdfx_info->addr0);
204#endif
171 struct tdfx_softc *tdfx_info;
172 u_long val;
173 /* rid value tells bus_alloc_resource where to find the addresses of ports or
174 * of memory ranges in the PCI config space*/
175 int rid = PCIR_MAPS;
176
177 /* Increment the card counter (for the ioctl code) */
178 tdfx_count++;

--- 17 unchanged lines hidden (view full) ---

196 * Get the Memory Location from the PCI Config, mask out lower word, since
197 * the config space register is only one word long (this is nicer than a
198 * bitshift).
199 */
200 tdfx_info->addr0 = (pci_read_config(dev, 0x10, 4) & 0xffff0000);
201#ifdef DEBUG
202 device_printf(dev, "Base0 @ 0x%x\n", tdfx_info->addr0);
203#endif
205
206 /* Notify the VM that we will be mapping some memory later */
207 tdfx_info->memrange = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0, ~0, 1,
208 RF_ACTIVE | RF_SHAREABLE);
209 if(tdfx_info->memrange == NULL) {
210#ifdef DEBUG
211 device_printf(dev, "Error mapping mem, won't be able to use mmap()\n");
212#endif
213 tdfx_info->memrid = 0;
214 }
215 else {
216 tdfx_info->memrid = rid;
217#ifdef DEBUG
218 device_printf(dev, "Mapped to: 0x%x\n",
219 (unsigned int)rman_get_start(tdfx_info->memrange));
220#endif
221 }
222
204 /* Notify the VM that we will be mapping some memory later */
205 tdfx_info->memrange = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0, ~0, 1,
206 RF_ACTIVE | RF_SHAREABLE);
207 if(tdfx_info->memrange == NULL) {
208#ifdef DEBUG
209 device_printf(dev, "Error mapping mem, won't be able to use mmap()\n");
210#endif
211 tdfx_info->memrid = 0;
212 }
213 else {
214 tdfx_info->memrid = rid;
215#ifdef DEBUG
216 device_printf(dev, "Mapped to: 0x%x\n",
217 (unsigned int)rman_get_start(tdfx_info->memrange));
218#endif
219 }
220
221 /* Setup for Voodoo3 and Banshee, PIO and an extram Memrange */
222 if(pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3 ||
223 pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE) {
224 rid = PCIR_MAPS;
225 tdfx_info->addr1 = (pci_read_config(dev, 0x14, 4) & 0xffff0000);
226#ifdef DEBUG
227 device_printf(dev, "Base1 @ 0x%x\n", tdfx_info->addr1);
228#endif
229 tdfx_info->memrange2 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
230 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
231 if(tdfx_info->memrange2 == NULL) {
232#ifdef DEBUG
233 device_printf(dev, "Mem1 couldn't be allocated, glide may not work.");
234#endif
235 tdfx_info->memrid2 = 0;
236 }
237 else {
238 tdfx_info->memrid2 = rid;
239 }
240 /* Now to map the PIO stuff */
241 rid = 0;
242 tdfx_info->piorange = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
243 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
244 if(tdfx_info->piorange == NULL) {
245#ifdef DEBUG
246 device_printf(dev, "Couldn't map PIO range.");
247#endif
248 tdfx_info->piorid = 0;
249 }
250 else {
251 tdfx_info->piorid = rid;
252 }
253 } else {
254 tdfx_info->addr1 = 0;
255 tdfx_info->memrange2 = NULL;
256 tdfx_info->piorange = NULL;
257 }
258
223 /*
224 * Set Writecombining, or at least Uncacheable for the memory region, if we
225 * are able to
226 */
227
228 if(tdfx_setmtrr(dev) != 0) {
229#ifdef DEBUG
230 device_printf(dev, "Some weird error setting MTRRs");
231#endif
232 return -1;
233 }
259 /*
260 * Set Writecombining, or at least Uncacheable for the memory region, if we
261 * are able to
262 */
263
264 if(tdfx_setmtrr(dev) != 0) {
265#ifdef DEBUG
266 device_printf(dev, "Some weird error setting MTRRs");
267#endif
268 return -1;
269 }
234
270
235 /*
236 * make_dev registers the cdev to access the 3dfx card from /dev
237 * use hex here for the dev num, simply to provide better support if > 10
238 * voodoo cards, for the mad. The user must set the link, or use MAKEDEV.
239 * Why would we want that many voodoo cards anyhow?
240 */
241 tdfx_info->devt = make_dev(&tdfx_cdev, dev->unit, 0, 0, 02660,
242 "3dfx%x", dev->unit);
243
244 return 0;
245}
246
247static int
248tdfx_detach(device_t dev) {
249 struct tdfx_softc* tdfx_info;
250 int retval;
251 tdfx_info = device_get_softc(dev);
252
253 /* Delete allocated resource, of course */
271 /*
272 * make_dev registers the cdev to access the 3dfx card from /dev
273 * use hex here for the dev num, simply to provide better support if > 10
274 * voodoo cards, for the mad. The user must set the link, or use MAKEDEV.
275 * Why would we want that many voodoo cards anyhow?
276 */
277 tdfx_info->devt = make_dev(&tdfx_cdev, dev->unit, 0, 0, 02660,
278 "3dfx%x", dev->unit);
279
280 return 0;
281}
282
283static int
284tdfx_detach(device_t dev) {
285 struct tdfx_softc* tdfx_info;
286 int retval;
287 tdfx_info = device_get_softc(dev);
288
289 /* Delete allocated resource, of course */
254 bus_release_resource(dev, SYS_RES_MEMORY, PCI_MAP_REG_START,
290 bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid,
255 tdfx_info->memrange);
291 tdfx_info->memrange);
256
292
293 /* Release extended Voodoo3/Banshee resources */
294 if(pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE ||
295 pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3) {
296 if(tdfx_info->memrange2 != NULL)
297 bus_release_resource(dev, SYS_RES_MEMORY, tdfx_info->memrid2,
298 tdfx_info->memrange);
299 if(tdfx_info->piorange != NULL)
300 bus_release_resource(dev, SYS_RES_IOPORT, tdfx_info->piorid,
301 tdfx_info->piorange);
302 }
303
257 /* Though it is safe to leave the WRCOMB support since the
258 mem driver checks for it, we should remove it in order
259 to free an MTRR for another device */
260 retval = tdfx_clrmtrr(dev);
261#ifdef DEBUG
262 if(retval != 0)
263 printf("tdfx: For some reason, I couldn't clear the mtrr\n");
264#endif

--- 28 unchanged lines hidden (view full) ---

293 /*
294 * This is the MTRR setting function for the 3dfx card. It is called from
295 * tdfx_attach. If we can't set the MTRR properly, it's not the end of the
296 * world. We can still continue, just with slightly (very slightly) degraded
297 * performance.
298 */
299 int retval = 0, act;
300 struct tdfx_softc *tdfx_info = device_get_softc(dev);
304 /* Though it is safe to leave the WRCOMB support since the
305 mem driver checks for it, we should remove it in order
306 to free an MTRR for another device */
307 retval = tdfx_clrmtrr(dev);
308#ifdef DEBUG
309 if(retval != 0)
310 printf("tdfx: For some reason, I couldn't clear the mtrr\n");
311#endif

--- 28 unchanged lines hidden (view full) ---

340 /*
341 * This is the MTRR setting function for the 3dfx card. It is called from
342 * tdfx_attach. If we can't set the MTRR properly, it's not the end of the
343 * world. We can still continue, just with slightly (very slightly) degraded
344 * performance.
345 */
346 int retval = 0, act;
347 struct tdfx_softc *tdfx_info = device_get_softc(dev);
301 /* The memory descriptor is described as the top 15 bits of the real
302 address */
303 tdfx_info->mrdesc.mr_base = pci_read_config(dev, 0x10, 4) & 0xfffe0000;
304
305 /* The older Voodoo cards have a shorter memrange than the newer ones */
306 if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO1) || (pci_get_devid(dev) ==
348
349 /* The older Voodoo cards have a shorter memrange than the newer ones */
350 if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO1) || (pci_get_devid(dev) ==
307 PCI_DEVICE_3DFX_VOODOO2))
351 PCI_DEVICE_3DFX_VOODOO2)) {
308 tdfx_info->mrdesc.mr_len = 0x400000;
352 tdfx_info->mrdesc.mr_len = 0x400000;
353
354 /* The memory descriptor is described as the top 15 bits of the real
355 address */
356 tdfx_info->mrdesc.mr_base = tdfx_info->addr0 & 0xfffe0000;
357 }
309 else if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3) ||
358 else if((pci_get_devid(dev) == PCI_DEVICE_3DFX_VOODOO3) ||
310 (pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE))
359 (pci_get_devid(dev) == PCI_DEVICE_3DFX_BANSHEE)) {
311 tdfx_info->mrdesc.mr_len = 0x1000000;
360 tdfx_info->mrdesc.mr_len = 0x1000000;
312
313 else return 0;
361 /* The Voodoo3 and Banshee LFB is the second memory address */
362 /* The memory descriptor is described as the top 15 bits of the real
363 address */
364 tdfx_info->mrdesc.mr_base = tdfx_info->addr1 & 0xfffe0000;
365 }
366 else
367 return 0;
314 /*
315 * The Alliance Pro Motion AT3D was not mentioned in the linux
316 * driver as far as MTRR support goes, so I just won't put the
317 * code in here for it. This is where it should go, though.
318 */
319
320 /* Firstly, try to set write combining */
321 tdfx_info->mrdesc.mr_flags = MDF_WRITECOMBINE;

--- 90 unchanged lines hidden (view full) ---

412 printf("tdfx: tdfx_info (softc) is NULL\n");
413#endif
414 return -1;
415 }
416
417 /* We must stay within the bound of our address space */
418 if((offset & 0xff000000) == tdfx_info->addr0)
419 offset &= 0xffffff;
368 /*
369 * The Alliance Pro Motion AT3D was not mentioned in the linux
370 * driver as far as MTRR support goes, so I just won't put the
371 * code in here for it. This is where it should go, though.
372 */
373
374 /* Firstly, try to set write combining */
375 tdfx_info->mrdesc.mr_flags = MDF_WRITECOMBINE;

--- 90 unchanged lines hidden (view full) ---

466 printf("tdfx: tdfx_info (softc) is NULL\n");
467#endif
468 return -1;
469 }
470
471 /* We must stay within the bound of our address space */
472 if((offset & 0xff000000) == tdfx_info->addr0)
473 offset &= 0xffffff;
474
475 /* See if the Banshee/V3 LFB is being requested */
476 if(tdfx_info->memrange2 != NULL && (offset & 0xff000000) ==
477 tdfx_info->addr1)
478 offset &= 0xffffff;
479
420 if((offset >= 0x1000000) || (offset < 0)) {
421#ifdef DEBUG
422 printf("tdfx: offset %x out of range\n", offset);
423#endif
424 return -1;
425 }
426
427 /* atop -> address to page

--- 167 unchanged lines hidden (view full) ---

595 }
596 /* Finally, combine the values and write it to the port */
597 retval = (retval & ~mask) | preval;
598 pci_write_config(tdfx_info->dev, piod->port & ~3, retval, 4);
599
600 return 0;
601}
602
480 if((offset >= 0x1000000) || (offset < 0)) {
481#ifdef DEBUG
482 printf("tdfx: offset %x out of range\n", offset);
483#endif
484 return -1;
485 }
486
487 /* atop -> address to page

--- 167 unchanged lines hidden (view full) ---

655 }
656 /* Finally, combine the values and write it to the port */
657 retval = (retval & ~mask) | preval;
658 pci_write_config(tdfx_info->dev, piod->port & ~3, retval, 4);
659
660 return 0;
661}
662
663/* For both of these, I added a variable named workport of type u_int so
664 * that I could eliminate the warning about my data type size. The
665 * applications expect the port to be of type short, so I needed to change
666 * this within the function */
603static int
604tdfx_do_pio_rd(struct tdfx_pio_data *piod)
605{
606 /* Return val */
607 u_int8_t ret_byte;
667static int
668tdfx_do_pio_rd(struct tdfx_pio_data *piod)
669{
670 /* Return val */
671 u_int8_t ret_byte;
608
672 u_int workport;
609 /* Restricts the access of ports other than those we use */
610 if((piod->port != VGA_INPUT_STATUS_1C) || (piod->port != SC_INDEX) ||
611 (piod->port != SC_DATA) || (piod->port != VGA_MISC_OUTPUT_READ))
612 return -EPERM;
613
614 /* All VGA STATUS REGS are byte registers, size should never be > 1 */
615 if(piod->size != 1) {
616 return -EINVAL;
617 }
618
619 /* Write the data to the intended port */
673 /* Restricts the access of ports other than those we use */
674 if((piod->port != VGA_INPUT_STATUS_1C) || (piod->port != SC_INDEX) ||
675 (piod->port != SC_DATA) || (piod->port != VGA_MISC_OUTPUT_READ))
676 return -EPERM;
677
678 /* All VGA STATUS REGS are byte registers, size should never be > 1 */
679 if(piod->size != 1) {
680 return -EINVAL;
681 }
682
683 /* Write the data to the intended port */
620 ret_byte = inb(piod->port);
684 workport = piod->port;
685 ret_byte = inb(workport);
621 copyout(&ret_byte, piod->value, sizeof(u_int8_t));
622 return 0;
623}
624
625static int
626tdfx_do_pio_wt(struct tdfx_pio_data *piod)
627{
628 /* return val */
629 u_int8_t ret_byte;
686 copyout(&ret_byte, piod->value, sizeof(u_int8_t));
687 return 0;
688}
689
690static int
691tdfx_do_pio_wt(struct tdfx_pio_data *piod)
692{
693 /* return val */
694 u_int8_t ret_byte;
630
695 u_int workport;
631 /* Replace old switch w/ massive if(...) */
632 /* Restricts the access of ports other than those we use */
633 if((piod->port != SC_INDEX) && (piod->port != SC_DATA) &&
634 (piod->port != VGA_MISC_OUTPUT_READ)) /* Can't write VGA_ST_1C */
635 return -EPERM;
636
637 /* All VGA STATUS REGS are byte registers, size should never be > 1 */
638 if(piod->size != 1) {
639 return -EINVAL;
640 }
641
642 /* Write the data to the intended port */
643 copyin(piod->value, &ret_byte, sizeof(u_int8_t));
696 /* Replace old switch w/ massive if(...) */
697 /* Restricts the access of ports other than those we use */
698 if((piod->port != SC_INDEX) && (piod->port != SC_DATA) &&
699 (piod->port != VGA_MISC_OUTPUT_READ)) /* Can't write VGA_ST_1C */
700 return -EPERM;
701
702 /* All VGA STATUS REGS are byte registers, size should never be > 1 */
703 if(piod->size != 1) {
704 return -EINVAL;
705 }
706
707 /* Write the data to the intended port */
708 copyin(piod->value, &ret_byte, sizeof(u_int8_t));
644 outb(piod->port, ret_byte);
709 workport = piod->port;
710 outb(workport, ret_byte);
645 return 0;
646}
647
648static int
649tdfx_do_query(u_int cmd, struct tdfx_pio_data *piod)
650{
651 /* There are three sub-commands to the query 0x33 */
652 switch(_IOC_NR(cmd)) {

--- 123 unchanged lines hidden ---
711 return 0;
712}
713
714static int
715tdfx_do_query(u_int cmd, struct tdfx_pio_data *piod)
716{
717 /* There are three sub-commands to the query 0x33 */
718 switch(_IOC_NR(cmd)) {

--- 123 unchanged lines hidden ---