savage_bci.c (152909) | savage_bci.c (157617) |
---|---|
1/* savage_bci.c -- BCI support for Savage 2 * 3 * Copyright 2004 Felix Kuehling 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation --- 10 unchanged lines hidden (view full) --- 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR 21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26#include <sys/cdefs.h> | 1/* savage_bci.c -- BCI support for Savage 2 * 3 * Copyright 2004 Felix Kuehling 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation --- 10 unchanged lines hidden (view full) --- 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR 21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 22 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26#include <sys/cdefs.h> |
27__FBSDID("$FreeBSD: head/sys/dev/drm/savage_bci.c 152909 2005-11-28 23:13:57Z anholt $"); | 27__FBSDID("$FreeBSD: head/sys/dev/drm/savage_bci.c 157617 2006-04-09 20:45:45Z anholt $"); |
28#include "dev/drm/drmP.h" 29#include "dev/drm/savage_drm.h" 30#include "dev/drm/savage_drv.h" 31 32/* Need a long timeout for shadow status updates can take a while 33 * and so can waiting for events when the queue is full. */ 34#define SAVAGE_DEFAULT_USEC_TIMEOUT 1000000 /* 1s */ 35#define SAVAGE_EVENT_USEC_TIMEOUT 5000000 /* 5s */ --- 259 unchanged lines hidden (view full) --- 295 */ 296static int savage_dma_init(drm_savage_private_t *dev_priv) 297{ 298 unsigned int i; 299 300 dev_priv->nr_dma_pages = dev_priv->cmd_dma->size / 301 (SAVAGE_DMA_PAGE_SIZE*4); 302 dev_priv->dma_pages = drm_alloc(sizeof(drm_savage_dma_page_t) * | 28#include "dev/drm/drmP.h" 29#include "dev/drm/savage_drm.h" 30#include "dev/drm/savage_drv.h" 31 32/* Need a long timeout for shadow status updates can take a while 33 * and so can waiting for events when the queue is full. */ 34#define SAVAGE_DEFAULT_USEC_TIMEOUT 1000000 /* 1s */ 35#define SAVAGE_EVENT_USEC_TIMEOUT 5000000 /* 5s */ --- 259 unchanged lines hidden (view full) --- 295 */ 296static int savage_dma_init(drm_savage_private_t *dev_priv) 297{ 298 unsigned int i; 299 300 dev_priv->nr_dma_pages = dev_priv->cmd_dma->size / 301 (SAVAGE_DMA_PAGE_SIZE*4); 302 dev_priv->dma_pages = drm_alloc(sizeof(drm_savage_dma_page_t) * |
303 dev_priv->nr_dma_pages, 304 DRM_MEM_DRIVER); | 303 dev_priv->nr_dma_pages, DRM_MEM_DRIVER); |
305 if (dev_priv->dma_pages == NULL) 306 return DRM_ERR(ENOMEM); 307 308 for (i = 0; i < dev_priv->nr_dma_pages; ++i) { 309 SET_AGE(&dev_priv->dma_pages[i].age, 0, 0); 310 dev_priv->dma_pages[i].used = 0; 311 dev_priv->dma_pages[i].flushed = 0; 312 } --- 58 unchanged lines hidden (view full) --- 371 uint32_t *dma_ptr; 372 unsigned int i; 373 374 DRM_DEBUG("cur=%u, cur->used=%u, n=%u, rest=%u, nr_pages=%u\n", 375 cur, dev_priv->dma_pages[cur].used, n, rest, nr_pages); 376 377 if (cur + nr_pages < dev_priv->nr_dma_pages) { 378 dma_ptr = (uint32_t *)dev_priv->cmd_dma->handle + | 304 if (dev_priv->dma_pages == NULL) 305 return DRM_ERR(ENOMEM); 306 307 for (i = 0; i < dev_priv->nr_dma_pages; ++i) { 308 SET_AGE(&dev_priv->dma_pages[i].age, 0, 0); 309 dev_priv->dma_pages[i].used = 0; 310 dev_priv->dma_pages[i].flushed = 0; 311 } --- 58 unchanged lines hidden (view full) --- 370 uint32_t *dma_ptr; 371 unsigned int i; 372 373 DRM_DEBUG("cur=%u, cur->used=%u, n=%u, rest=%u, nr_pages=%u\n", 374 cur, dev_priv->dma_pages[cur].used, n, rest, nr_pages); 375 376 if (cur + nr_pages < dev_priv->nr_dma_pages) { 377 dma_ptr = (uint32_t *)dev_priv->cmd_dma->handle + |
379 cur*SAVAGE_DMA_PAGE_SIZE + 380 dev_priv->dma_pages[cur].used; | 378 cur*SAVAGE_DMA_PAGE_SIZE + dev_priv->dma_pages[cur].used; |
381 if (n < rest) 382 rest = n; 383 dev_priv->dma_pages[cur].used += rest; 384 n -= rest; 385 cur++; 386 } else { 387 dev_priv->dma_flush(dev_priv); | 379 if (n < rest) 380 rest = n; 381 dev_priv->dma_pages[cur].used += rest; 382 n -= rest; 383 cur++; 384 } else { 385 dev_priv->dma_flush(dev_priv); |
388 nr_pages = (n + SAVAGE_DMA_PAGE_SIZE-1) / SAVAGE_DMA_PAGE_SIZE; | 386 nr_pages = 387 (n + SAVAGE_DMA_PAGE_SIZE-1) / SAVAGE_DMA_PAGE_SIZE; |
389 for (i = cur; i < dev_priv->nr_dma_pages; ++i) { 390 dev_priv->dma_pages[i].age = dev_priv->last_dma_age; 391 dev_priv->dma_pages[i].used = 0; 392 dev_priv->dma_pages[i].flushed = 0; 393 } 394 dma_ptr = (uint32_t *)dev_priv->cmd_dma->handle; 395 dev_priv->first_dma_page = cur = 0; 396 } --- 41 unchanged lines hidden (view full) --- 438 DRM_DEBUG("first=%u, cur=%u, first->flushed=%u, cur->used=%u, " 439 "pad=%u, align=%u\n", 440 first, cur, dev_priv->dma_pages[first].flushed, 441 dev_priv->dma_pages[cur].used, pad, align); 442 443 /* pad with noops */ 444 if (pad) { 445 uint32_t *dma_ptr = (uint32_t *)dev_priv->cmd_dma->handle + | 388 for (i = cur; i < dev_priv->nr_dma_pages; ++i) { 389 dev_priv->dma_pages[i].age = dev_priv->last_dma_age; 390 dev_priv->dma_pages[i].used = 0; 391 dev_priv->dma_pages[i].flushed = 0; 392 } 393 dma_ptr = (uint32_t *)dev_priv->cmd_dma->handle; 394 dev_priv->first_dma_page = cur = 0; 395 } --- 41 unchanged lines hidden (view full) --- 437 DRM_DEBUG("first=%u, cur=%u, first->flushed=%u, cur->used=%u, " 438 "pad=%u, align=%u\n", 439 first, cur, dev_priv->dma_pages[first].flushed, 440 dev_priv->dma_pages[cur].used, pad, align); 441 442 /* pad with noops */ 443 if (pad) { 444 uint32_t *dma_ptr = (uint32_t *)dev_priv->cmd_dma->handle + |
446 cur * SAVAGE_DMA_PAGE_SIZE + 447 dev_priv->dma_pages[cur].used; | 445 cur * SAVAGE_DMA_PAGE_SIZE + dev_priv->dma_pages[cur].used; |
448 dev_priv->dma_pages[cur].used += pad; 449 while(pad != 0) { 450 *dma_ptr++ = BCI_CMD_WAIT; 451 pad--; 452 } 453 } 454 455 DRM_MEMORYBARRIER(); 456 457 /* do flush ... */ 458 phys_addr = dev_priv->cmd_dma->offset + 459 (first * SAVAGE_DMA_PAGE_SIZE + 460 dev_priv->dma_pages[first].flushed) * 4; 461 len = (cur - first) * SAVAGE_DMA_PAGE_SIZE + | 446 dev_priv->dma_pages[cur].used += pad; 447 while(pad != 0) { 448 *dma_ptr++ = BCI_CMD_WAIT; 449 pad--; 450 } 451 } 452 453 DRM_MEMORYBARRIER(); 454 455 /* do flush ... */ 456 phys_addr = dev_priv->cmd_dma->offset + 457 (first * SAVAGE_DMA_PAGE_SIZE + 458 dev_priv->dma_pages[first].flushed) * 4; 459 len = (cur - first) * SAVAGE_DMA_PAGE_SIZE + |
462 dev_priv->dma_pages[cur].used - 463 dev_priv->dma_pages[first].flushed; | 460 dev_priv->dma_pages[cur].used - dev_priv->dma_pages[first].flushed; |
464 465 DRM_DEBUG("phys_addr=%lx, len=%u\n", 466 phys_addr | dev_priv->dma_type, len); 467 468 BEGIN_BCI(3); 469 BCI_SET_REGISTERS(SAVAGE_DMABUFADDR, 1); 470 BCI_WRITE(phys_addr | dev_priv->dma_type); 471 BCI_DMA(len); --- 111 unchanged lines hidden (view full) --- 583 aper_rsrc = 0; 584 aperture_base = fb_base + SAVAGE_APERTURE_OFFSET; 585 /* this should always be true */ 586 if (drm_get_resource_len(dev, 0) == 0x08000000) { 587 /* Don't make MMIO write-cobining! We need 3 588 * MTRRs. */ 589 dev_priv->mtrr[0].base = fb_base; 590 dev_priv->mtrr[0].size = 0x01000000; | 461 462 DRM_DEBUG("phys_addr=%lx, len=%u\n", 463 phys_addr | dev_priv->dma_type, len); 464 465 BEGIN_BCI(3); 466 BCI_SET_REGISTERS(SAVAGE_DMABUFADDR, 1); 467 BCI_WRITE(phys_addr | dev_priv->dma_type); 468 BCI_DMA(len); --- 111 unchanged lines hidden (view full) --- 580 aper_rsrc = 0; 581 aperture_base = fb_base + SAVAGE_APERTURE_OFFSET; 582 /* this should always be true */ 583 if (drm_get_resource_len(dev, 0) == 0x08000000) { 584 /* Don't make MMIO write-cobining! We need 3 585 * MTRRs. */ 586 dev_priv->mtrr[0].base = fb_base; 587 dev_priv->mtrr[0].size = 0x01000000; |
591 dev_priv->mtrr[0].handle = drm_mtrr_add( 592 dev_priv->mtrr[0].base, dev_priv->mtrr[0].size, 593 DRM_MTRR_WC); | 588 dev_priv->mtrr[0].handle = 589 drm_mtrr_add(dev_priv->mtrr[0].base, 590 dev_priv->mtrr[0].size, DRM_MTRR_WC); |
594 dev_priv->mtrr[1].base = fb_base+0x02000000; 595 dev_priv->mtrr[1].size = 0x02000000; | 591 dev_priv->mtrr[1].base = fb_base+0x02000000; 592 dev_priv->mtrr[1].size = 0x02000000; |
596 dev_priv->mtrr[1].handle = drm_mtrr_add( 597 dev_priv->mtrr[1].base, dev_priv->mtrr[1].size, 598 DRM_MTRR_WC); | 593 dev_priv->mtrr[1].handle = 594 drm_mtrr_add(dev_priv->mtrr[1].base, 595 dev_priv->mtrr[1].size, DRM_MTRR_WC); |
599 dev_priv->mtrr[2].base = fb_base+0x04000000; 600 dev_priv->mtrr[2].size = 0x04000000; | 596 dev_priv->mtrr[2].base = fb_base+0x04000000; 597 dev_priv->mtrr[2].size = 0x04000000; |
601 dev_priv->mtrr[2].handle = drm_mtrr_add( 602 dev_priv->mtrr[2].base, dev_priv->mtrr[2].size, 603 DRM_MTRR_WC); | 598 dev_priv->mtrr[2].handle = 599 drm_mtrr_add(dev_priv->mtrr[2].base, 600 dev_priv->mtrr[2].size, DRM_MTRR_WC); |
604 } else { 605 DRM_ERROR("strange pci_resource_len %08lx\n", 606 drm_get_resource_len(dev, 0)); 607 } 608 } else if (dev_priv->chipset != S3_SUPERSAVAGE && 609 dev_priv->chipset != S3_SAVAGE2000) { 610 mmio_base = drm_get_resource_start(dev, 0); 611 fb_rsrc = 1; 612 fb_base = drm_get_resource_start(dev, 1); 613 fb_size = SAVAGE_FB_SIZE_S4; 614 aper_rsrc = 1; 615 aperture_base = fb_base + SAVAGE_APERTURE_OFFSET; 616 /* this should always be true */ 617 if (drm_get_resource_len(dev, 1) == 0x08000000) { 618 /* Can use one MTRR to cover both fb and 619 * aperture. */ 620 dev_priv->mtrr[0].base = fb_base; 621 dev_priv->mtrr[0].size = 0x08000000; | 601 } else { 602 DRM_ERROR("strange pci_resource_len %08lx\n", 603 drm_get_resource_len(dev, 0)); 604 } 605 } else if (dev_priv->chipset != S3_SUPERSAVAGE && 606 dev_priv->chipset != S3_SAVAGE2000) { 607 mmio_base = drm_get_resource_start(dev, 0); 608 fb_rsrc = 1; 609 fb_base = drm_get_resource_start(dev, 1); 610 fb_size = SAVAGE_FB_SIZE_S4; 611 aper_rsrc = 1; 612 aperture_base = fb_base + SAVAGE_APERTURE_OFFSET; 613 /* this should always be true */ 614 if (drm_get_resource_len(dev, 1) == 0x08000000) { 615 /* Can use one MTRR to cover both fb and 616 * aperture. */ 617 dev_priv->mtrr[0].base = fb_base; 618 dev_priv->mtrr[0].size = 0x08000000; |
622 dev_priv->mtrr[0].handle = drm_mtrr_add( 623 dev_priv->mtrr[0].base, dev_priv->mtrr[0].size, 624 DRM_MTRR_WC); | 619 dev_priv->mtrr[0].handle = 620 drm_mtrr_add(dev_priv->mtrr[0].base, 621 dev_priv->mtrr[0].size, DRM_MTRR_WC); |
625 } else { 626 DRM_ERROR("strange pci_resource_len %08lx\n", 627 drm_get_resource_len(dev, 1)); 628 } 629 } else { 630 mmio_base = drm_get_resource_start(dev, 0); 631 fb_rsrc = 1; 632 fb_base = drm_get_resource_start(dev, 1); --- 29 unchanged lines hidden (view full) --- 662{ 663 drm_savage_private_t *dev_priv = dev->dev_private; 664 int i; 665 666 for (i = 0; i < 3; ++i) 667 if (dev_priv->mtrr[i].handle >= 0) 668 drm_mtrr_del(dev_priv->mtrr[i].handle, 669 dev_priv->mtrr[i].base, | 622 } else { 623 DRM_ERROR("strange pci_resource_len %08lx\n", 624 drm_get_resource_len(dev, 1)); 625 } 626 } else { 627 mmio_base = drm_get_resource_start(dev, 0); 628 fb_rsrc = 1; 629 fb_base = drm_get_resource_start(dev, 1); --- 29 unchanged lines hidden (view full) --- 659{ 660 drm_savage_private_t *dev_priv = dev->dev_private; 661 int i; 662 663 for (i = 0; i < 3; ++i) 664 if (dev_priv->mtrr[i].handle >= 0) 665 drm_mtrr_del(dev_priv->mtrr[i].handle, 666 dev_priv->mtrr[i].base, |
670 dev_priv->mtrr[i].size, 671 DRM_MTRR_WC); | 667 dev_priv->mtrr[i].size, DRM_MTRR_WC); |
672} 673 674int savage_driver_unload(drm_device_t *dev) 675{ 676 drm_savage_private_t *dev_priv = dev->dev_private; 677 678 drm_free(dev_priv, sizeof(drm_savage_private_t), DRM_MEM_DRIVER); 679 --- 151 unchanged lines hidden (view full) --- 831 color_tile_format = dev_priv->fb_bpp == 16 ? 832 SAVAGE_BD_TILE_16BPP : SAVAGE_BD_TILE_32BPP; 833 depth_tile_format = dev_priv->depth_bpp == 16 ? 834 SAVAGE_BD_TILE_16BPP : SAVAGE_BD_TILE_32BPP; 835 } else { 836 color_tile_format = SAVAGE_BD_TILE_DEST; 837 depth_tile_format = SAVAGE_BD_TILE_DEST; 838 } | 668} 669 670int savage_driver_unload(drm_device_t *dev) 671{ 672 drm_savage_private_t *dev_priv = dev->dev_private; 673 674 drm_free(dev_priv, sizeof(drm_savage_private_t), DRM_MEM_DRIVER); 675 --- 151 unchanged lines hidden (view full) --- 827 color_tile_format = dev_priv->fb_bpp == 16 ? 828 SAVAGE_BD_TILE_16BPP : SAVAGE_BD_TILE_32BPP; 829 depth_tile_format = dev_priv->depth_bpp == 16 ? 830 SAVAGE_BD_TILE_16BPP : SAVAGE_BD_TILE_32BPP; 831 } else { 832 color_tile_format = SAVAGE_BD_TILE_DEST; 833 depth_tile_format = SAVAGE_BD_TILE_DEST; 834 } |
839 front_stride = dev_priv->front_pitch / (dev_priv->fb_bpp/8); 840 back_stride = dev_priv-> back_pitch / (dev_priv->fb_bpp/8); 841 depth_stride = dev_priv->depth_pitch / (dev_priv->depth_bpp/8); | 835 front_stride = dev_priv->front_pitch / (dev_priv->fb_bpp / 8); 836 back_stride = dev_priv->back_pitch / (dev_priv->fb_bpp / 8); 837 depth_stride = 838 dev_priv->depth_pitch / (dev_priv->depth_bpp / 8); |
842 843 dev_priv->front_bd = front_stride | SAVAGE_BD_BW_DISABLE | 844 (dev_priv->fb_bpp << SAVAGE_BD_BPP_SHIFT) | 845 (color_tile_format << SAVAGE_BD_TILE_SHIFT); 846 847 dev_priv-> back_bd = back_stride | SAVAGE_BD_BW_DISABLE | 848 (dev_priv->fb_bpp << SAVAGE_BD_BPP_SHIFT) | 849 (color_tile_format << SAVAGE_BD_TILE_SHIFT); --- 216 unchanged lines hidden (view full) --- 1066 ret = savage_bci_get_buffers(filp, dev, &d); 1067 } 1068 1069 DRM_COPY_TO_USER_IOCTL((drm_dma_t __user *)data, d, sizeof(d)); 1070 1071 return ret; 1072} 1073 | 839 840 dev_priv->front_bd = front_stride | SAVAGE_BD_BW_DISABLE | 841 (dev_priv->fb_bpp << SAVAGE_BD_BPP_SHIFT) | 842 (color_tile_format << SAVAGE_BD_TILE_SHIFT); 843 844 dev_priv-> back_bd = back_stride | SAVAGE_BD_BW_DISABLE | 845 (dev_priv->fb_bpp << SAVAGE_BD_BPP_SHIFT) | 846 (color_tile_format << SAVAGE_BD_TILE_SHIFT); --- 216 unchanged lines hidden (view full) --- 1063 ret = savage_bci_get_buffers(filp, dev, &d); 1064 } 1065 1066 DRM_COPY_TO_USER_IOCTL((drm_dma_t __user *)data, d, sizeof(d)); 1067 1068 return ret; 1069} 1070 |
1074void savage_reclaim_buffers(drm_device_t *dev, DRMFILE filp) { | 1071void savage_reclaim_buffers(drm_device_t *dev, DRMFILE filp) 1072{ |
1075 drm_device_dma_t *dma = dev->dma; 1076 drm_savage_private_t *dev_priv = dev->dev_private; 1077 int i; 1078 1079 if (!dma) 1080 return; 1081 if (!dev_priv) 1082 return; --- 31 unchanged lines hidden --- | 1073 drm_device_dma_t *dma = dev->dma; 1074 drm_savage_private_t *dev_priv = dev->dev_private; 1075 int i; 1076 1077 if (!dma) 1078 return; 1079 if (!dev_priv) 1080 return; --- 31 unchanged lines hidden --- |