aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/drm/r128_cce.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/drm/r128_cce.c')
-rw-r--r--drivers/char/drm/r128_cce.c138
1 files changed, 61 insertions, 77 deletions
diff --git a/drivers/char/drm/r128_cce.c b/drivers/char/drm/r128_cce.c
index b163ed09bd81..7d550aba165e 100644
--- a/drivers/char/drm/r128_cce.c
+++ b/drivers/char/drm/r128_cce.c
@@ -129,7 +129,7 @@ static int r128_do_pixcache_flush(drm_r128_private_t * dev_priv)
129#if R128_FIFO_DEBUG 129#if R128_FIFO_DEBUG
130 DRM_ERROR("failed!\n"); 130 DRM_ERROR("failed!\n");
131#endif 131#endif
132 return DRM_ERR(EBUSY); 132 return -EBUSY;
133} 133}
134 134
135static int r128_do_wait_for_fifo(drm_r128_private_t * dev_priv, int entries) 135static int r128_do_wait_for_fifo(drm_r128_private_t * dev_priv, int entries)
@@ -146,7 +146,7 @@ static int r128_do_wait_for_fifo(drm_r128_private_t * dev_priv, int entries)
146#if R128_FIFO_DEBUG 146#if R128_FIFO_DEBUG
147 DRM_ERROR("failed!\n"); 147 DRM_ERROR("failed!\n");
148#endif 148#endif
149 return DRM_ERR(EBUSY); 149 return -EBUSY;
150} 150}
151 151
152static int r128_do_wait_for_idle(drm_r128_private_t * dev_priv) 152static int r128_do_wait_for_idle(drm_r128_private_t * dev_priv)
@@ -168,7 +168,7 @@ static int r128_do_wait_for_idle(drm_r128_private_t * dev_priv)
168#if R128_FIFO_DEBUG 168#if R128_FIFO_DEBUG
169 DRM_ERROR("failed!\n"); 169 DRM_ERROR("failed!\n");
170#endif 170#endif
171 return DRM_ERR(EBUSY); 171 return -EBUSY;
172} 172}
173 173
174/* ================================================================ 174/* ================================================================
@@ -227,7 +227,7 @@ int r128_do_cce_idle(drm_r128_private_t * dev_priv)
227 DRM_ERROR("failed!\n"); 227 DRM_ERROR("failed!\n");
228 r128_status(dev_priv); 228 r128_status(dev_priv);
229#endif 229#endif
230 return DRM_ERR(EBUSY); 230 return -EBUSY;
231} 231}
232 232
233/* Start the Concurrent Command Engine. 233/* Start the Concurrent Command Engine.
@@ -355,7 +355,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
355 355
356 dev_priv = drm_alloc(sizeof(drm_r128_private_t), DRM_MEM_DRIVER); 356 dev_priv = drm_alloc(sizeof(drm_r128_private_t), DRM_MEM_DRIVER);
357 if (dev_priv == NULL) 357 if (dev_priv == NULL)
358 return DRM_ERR(ENOMEM); 358 return -ENOMEM;
359 359
360 memset(dev_priv, 0, sizeof(drm_r128_private_t)); 360 memset(dev_priv, 0, sizeof(drm_r128_private_t));
361 361
@@ -365,7 +365,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
365 DRM_ERROR("PCI GART memory not allocated!\n"); 365 DRM_ERROR("PCI GART memory not allocated!\n");
366 dev->dev_private = (void *)dev_priv; 366 dev->dev_private = (void *)dev_priv;
367 r128_do_cleanup_cce(dev); 367 r128_do_cleanup_cce(dev);
368 return DRM_ERR(EINVAL); 368 return -EINVAL;
369 } 369 }
370 370
371 dev_priv->usec_timeout = init->usec_timeout; 371 dev_priv->usec_timeout = init->usec_timeout;
@@ -374,7 +374,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
374 DRM_DEBUG("TIMEOUT problem!\n"); 374 DRM_DEBUG("TIMEOUT problem!\n");
375 dev->dev_private = (void *)dev_priv; 375 dev->dev_private = (void *)dev_priv;
376 r128_do_cleanup_cce(dev); 376 r128_do_cleanup_cce(dev);
377 return DRM_ERR(EINVAL); 377 return -EINVAL;
378 } 378 }
379 379
380 dev_priv->cce_mode = init->cce_mode; 380 dev_priv->cce_mode = init->cce_mode;
@@ -394,7 +394,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
394 DRM_DEBUG("Bad cce_mode!\n"); 394 DRM_DEBUG("Bad cce_mode!\n");
395 dev->dev_private = (void *)dev_priv; 395 dev->dev_private = (void *)dev_priv;
396 r128_do_cleanup_cce(dev); 396 r128_do_cleanup_cce(dev);
397 return DRM_ERR(EINVAL); 397 return -EINVAL;
398 } 398 }
399 399
400 switch (init->cce_mode) { 400 switch (init->cce_mode) {
@@ -461,7 +461,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
461 DRM_ERROR("could not find sarea!\n"); 461 DRM_ERROR("could not find sarea!\n");
462 dev->dev_private = (void *)dev_priv; 462 dev->dev_private = (void *)dev_priv;
463 r128_do_cleanup_cce(dev); 463 r128_do_cleanup_cce(dev);
464 return DRM_ERR(EINVAL); 464 return -EINVAL;
465 } 465 }
466 466
467 dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset); 467 dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
@@ -469,21 +469,21 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
469 DRM_ERROR("could not find mmio region!\n"); 469 DRM_ERROR("could not find mmio region!\n");
470 dev->dev_private = (void *)dev_priv; 470 dev->dev_private = (void *)dev_priv;
471 r128_do_cleanup_cce(dev); 471 r128_do_cleanup_cce(dev);
472 return DRM_ERR(EINVAL); 472 return -EINVAL;
473 } 473 }
474 dev_priv->cce_ring = drm_core_findmap(dev, init->ring_offset); 474 dev_priv->cce_ring = drm_core_findmap(dev, init->ring_offset);
475 if (!dev_priv->cce_ring) { 475 if (!dev_priv->cce_ring) {
476 DRM_ERROR("could not find cce ring region!\n"); 476 DRM_ERROR("could not find cce ring region!\n");
477 dev->dev_private = (void *)dev_priv; 477 dev->dev_private = (void *)dev_priv;
478 r128_do_cleanup_cce(dev); 478 r128_do_cleanup_cce(dev);
479 return DRM_ERR(EINVAL); 479 return -EINVAL;
480 } 480 }
481 dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset); 481 dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset);
482 if (!dev_priv->ring_rptr) { 482 if (!dev_priv->ring_rptr) {
483 DRM_ERROR("could not find ring read pointer!\n"); 483 DRM_ERROR("could not find ring read pointer!\n");
484 dev->dev_private = (void *)dev_priv; 484 dev->dev_private = (void *)dev_priv;
485 r128_do_cleanup_cce(dev); 485 r128_do_cleanup_cce(dev);
486 return DRM_ERR(EINVAL); 486 return -EINVAL;
487 } 487 }
488 dev->agp_buffer_token = init->buffers_offset; 488 dev->agp_buffer_token = init->buffers_offset;
489 dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset); 489 dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
@@ -491,7 +491,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
491 DRM_ERROR("could not find dma buffer region!\n"); 491 DRM_ERROR("could not find dma buffer region!\n");
492 dev->dev_private = (void *)dev_priv; 492 dev->dev_private = (void *)dev_priv;
493 r128_do_cleanup_cce(dev); 493 r128_do_cleanup_cce(dev);
494 return DRM_ERR(EINVAL); 494 return -EINVAL;
495 } 495 }
496 496
497 if (!dev_priv->is_pci) { 497 if (!dev_priv->is_pci) {
@@ -501,7 +501,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
501 DRM_ERROR("could not find agp texture region!\n"); 501 DRM_ERROR("could not find agp texture region!\n");
502 dev->dev_private = (void *)dev_priv; 502 dev->dev_private = (void *)dev_priv;
503 r128_do_cleanup_cce(dev); 503 r128_do_cleanup_cce(dev);
504 return DRM_ERR(EINVAL); 504 return -EINVAL;
505 } 505 }
506 } 506 }
507 507
@@ -520,7 +520,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
520 DRM_ERROR("Could not ioremap agp regions!\n"); 520 DRM_ERROR("Could not ioremap agp regions!\n");
521 dev->dev_private = (void *)dev_priv; 521 dev->dev_private = (void *)dev_priv;
522 r128_do_cleanup_cce(dev); 522 r128_do_cleanup_cce(dev);
523 return DRM_ERR(ENOMEM); 523 return -ENOMEM;
524 } 524 }
525 } else 525 } else
526#endif 526#endif
@@ -567,7 +567,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
567 DRM_ERROR("failed to init PCI GART!\n"); 567 DRM_ERROR("failed to init PCI GART!\n");
568 dev->dev_private = (void *)dev_priv; 568 dev->dev_private = (void *)dev_priv;
569 r128_do_cleanup_cce(dev); 569 r128_do_cleanup_cce(dev);
570 return DRM_ERR(ENOMEM); 570 return -ENOMEM;
571 } 571 }
572 R128_WRITE(R128_PCI_GART_PAGE, dev_priv->gart_info.bus_addr); 572 R128_WRITE(R128_PCI_GART_PAGE, dev_priv->gart_info.bus_addr);
573#if __OS_HAS_AGP 573#if __OS_HAS_AGP
@@ -625,35 +625,30 @@ int r128_do_cleanup_cce(struct drm_device * dev)
625 return 0; 625 return 0;
626} 626}
627 627
628int r128_cce_init(DRM_IOCTL_ARGS) 628int r128_cce_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
629{ 629{
630 DRM_DEVICE; 630 drm_r128_init_t *init = data;
631 drm_r128_init_t init;
632 631
633 DRM_DEBUG("\n"); 632 DRM_DEBUG("\n");
634 633
635 LOCK_TEST_WITH_RETURN(dev, filp); 634 LOCK_TEST_WITH_RETURN(dev, file_priv);
636 635
637 DRM_COPY_FROM_USER_IOCTL(init, (drm_r128_init_t __user *) data, 636 switch (init->func) {
638 sizeof(init));
639
640 switch (init.func) {
641 case R128_INIT_CCE: 637 case R128_INIT_CCE:
642 return r128_do_init_cce(dev, &init); 638 return r128_do_init_cce(dev, init);
643 case R128_CLEANUP_CCE: 639 case R128_CLEANUP_CCE:
644 return r128_do_cleanup_cce(dev); 640 return r128_do_cleanup_cce(dev);
645 } 641 }
646 642
647 return DRM_ERR(EINVAL); 643 return -EINVAL;
648} 644}
649 645
650int r128_cce_start(DRM_IOCTL_ARGS) 646int r128_cce_start(struct drm_device *dev, void *data, struct drm_file *file_priv)
651{ 647{
652 DRM_DEVICE;
653 drm_r128_private_t *dev_priv = dev->dev_private; 648 drm_r128_private_t *dev_priv = dev->dev_private;
654 DRM_DEBUG("\n"); 649 DRM_DEBUG("\n");
655 650
656 LOCK_TEST_WITH_RETURN(dev, filp); 651 LOCK_TEST_WITH_RETURN(dev, file_priv);
657 652
658 if (dev_priv->cce_running || dev_priv->cce_mode == R128_PM4_NONPM4) { 653 if (dev_priv->cce_running || dev_priv->cce_mode == R128_PM4_NONPM4) {
659 DRM_DEBUG("%s while CCE running\n", __FUNCTION__); 654 DRM_DEBUG("%s while CCE running\n", __FUNCTION__);
@@ -668,30 +663,26 @@ int r128_cce_start(DRM_IOCTL_ARGS)
668/* Stop the CCE. The engine must have been idled before calling this 663/* Stop the CCE. The engine must have been idled before calling this
669 * routine. 664 * routine.
670 */ 665 */
671int r128_cce_stop(DRM_IOCTL_ARGS) 666int r128_cce_stop(struct drm_device *dev, void *data, struct drm_file *file_priv)
672{ 667{
673 DRM_DEVICE;
674 drm_r128_private_t *dev_priv = dev->dev_private; 668 drm_r128_private_t *dev_priv = dev->dev_private;
675 drm_r128_cce_stop_t stop; 669 drm_r128_cce_stop_t *stop = data;
676 int ret; 670 int ret;
677 DRM_DEBUG("\n"); 671 DRM_DEBUG("\n");
678 672
679 LOCK_TEST_WITH_RETURN(dev, filp); 673 LOCK_TEST_WITH_RETURN(dev, file_priv);
680
681 DRM_COPY_FROM_USER_IOCTL(stop, (drm_r128_cce_stop_t __user *) data,
682 sizeof(stop));
683 674
684 /* Flush any pending CCE commands. This ensures any outstanding 675 /* Flush any pending CCE commands. This ensures any outstanding
685 * commands are exectuted by the engine before we turn it off. 676 * commands are exectuted by the engine before we turn it off.
686 */ 677 */
687 if (stop.flush) { 678 if (stop->flush) {
688 r128_do_cce_flush(dev_priv); 679 r128_do_cce_flush(dev_priv);
689 } 680 }
690 681
691 /* If we fail to make the engine go idle, we return an error 682 /* If we fail to make the engine go idle, we return an error
692 * code so that the DRM ioctl wrapper can try again. 683 * code so that the DRM ioctl wrapper can try again.
693 */ 684 */
694 if (stop.idle) { 685 if (stop->idle) {
695 ret = r128_do_cce_idle(dev_priv); 686 ret = r128_do_cce_idle(dev_priv);
696 if (ret) 687 if (ret)
697 return ret; 688 return ret;
@@ -711,17 +702,16 @@ int r128_cce_stop(DRM_IOCTL_ARGS)
711 702
712/* Just reset the CCE ring. Called as part of an X Server engine reset. 703/* Just reset the CCE ring. Called as part of an X Server engine reset.
713 */ 704 */
714int r128_cce_reset(DRM_IOCTL_ARGS) 705int r128_cce_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
715{ 706{
716 DRM_DEVICE;
717 drm_r128_private_t *dev_priv = dev->dev_private; 707 drm_r128_private_t *dev_priv = dev->dev_private;
718 DRM_DEBUG("\n"); 708 DRM_DEBUG("\n");
719 709
720 LOCK_TEST_WITH_RETURN(dev, filp); 710 LOCK_TEST_WITH_RETURN(dev, file_priv);
721 711
722 if (!dev_priv) { 712 if (!dev_priv) {
723 DRM_DEBUG("%s called before init done\n", __FUNCTION__); 713 DRM_DEBUG("%s called before init done\n", __FUNCTION__);
724 return DRM_ERR(EINVAL); 714 return -EINVAL;
725 } 715 }
726 716
727 r128_do_cce_reset(dev_priv); 717 r128_do_cce_reset(dev_priv);
@@ -732,13 +722,12 @@ int r128_cce_reset(DRM_IOCTL_ARGS)
732 return 0; 722 return 0;
733} 723}
734 724
735int r128_cce_idle(DRM_IOCTL_ARGS) 725int r128_cce_idle(struct drm_device *dev, void *data, struct drm_file *file_priv)
736{ 726{
737 DRM_DEVICE;
738 drm_r128_private_t *dev_priv = dev->dev_private; 727 drm_r128_private_t *dev_priv = dev->dev_private;
739 DRM_DEBUG("\n"); 728 DRM_DEBUG("\n");
740 729
741 LOCK_TEST_WITH_RETURN(dev, filp); 730 LOCK_TEST_WITH_RETURN(dev, file_priv);
742 731
743 if (dev_priv->cce_running) { 732 if (dev_priv->cce_running) {
744 r128_do_cce_flush(dev_priv); 733 r128_do_cce_flush(dev_priv);
@@ -747,19 +736,18 @@ int r128_cce_idle(DRM_IOCTL_ARGS)
747 return r128_do_cce_idle(dev_priv); 736 return r128_do_cce_idle(dev_priv);
748} 737}
749 738
750int r128_engine_reset(DRM_IOCTL_ARGS) 739int r128_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
751{ 740{
752 DRM_DEVICE;
753 DRM_DEBUG("\n"); 741 DRM_DEBUG("\n");
754 742
755 LOCK_TEST_WITH_RETURN(dev, filp); 743 LOCK_TEST_WITH_RETURN(dev, file_priv);
756 744
757 return r128_do_engine_reset(dev); 745 return r128_do_engine_reset(dev);
758} 746}
759 747
760int r128_fullscreen(DRM_IOCTL_ARGS) 748int r128_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv)
761{ 749{
762 return DRM_ERR(EINVAL); 750 return -EINVAL;
763} 751}
764 752
765/* ================================================================ 753/* ================================================================
@@ -780,7 +768,7 @@ static int r128_freelist_init(struct drm_device * dev)
780 768
781 dev_priv->head = drm_alloc(sizeof(drm_r128_freelist_t), DRM_MEM_DRIVER); 769 dev_priv->head = drm_alloc(sizeof(drm_r128_freelist_t), DRM_MEM_DRIVER);
782 if (dev_priv->head == NULL) 770 if (dev_priv->head == NULL)
783 return DRM_ERR(ENOMEM); 771 return -ENOMEM;
784 772
785 memset(dev_priv->head, 0, sizeof(drm_r128_freelist_t)); 773 memset(dev_priv->head, 0, sizeof(drm_r128_freelist_t));
786 dev_priv->head->age = R128_BUFFER_USED; 774 dev_priv->head->age = R128_BUFFER_USED;
@@ -791,7 +779,7 @@ static int r128_freelist_init(struct drm_device * dev)
791 779
792 entry = drm_alloc(sizeof(drm_r128_freelist_t), DRM_MEM_DRIVER); 780 entry = drm_alloc(sizeof(drm_r128_freelist_t), DRM_MEM_DRIVER);
793 if (!entry) 781 if (!entry)
794 return DRM_ERR(ENOMEM); 782 return -ENOMEM;
795 783
796 entry->age = R128_BUFFER_FREE; 784 entry->age = R128_BUFFER_FREE;
797 entry->buf = buf; 785 entry->buf = buf;
@@ -828,7 +816,7 @@ static struct drm_buf *r128_freelist_get(struct drm_device * dev)
828 for (i = 0; i < dma->buf_count; i++) { 816 for (i = 0; i < dma->buf_count; i++) {
829 buf = dma->buflist[i]; 817 buf = dma->buflist[i];
830 buf_priv = buf->dev_private; 818 buf_priv = buf->dev_private;
831 if (buf->filp == 0) 819 if (buf->file_priv == 0)
832 return buf; 820 return buf;
833 } 821 }
834 822
@@ -883,10 +871,12 @@ int r128_wait_ring(drm_r128_private_t * dev_priv, int n)
883 871
884 /* FIXME: This is being ignored... */ 872 /* FIXME: This is being ignored... */
885 DRM_ERROR("failed!\n"); 873 DRM_ERROR("failed!\n");
886 return DRM_ERR(EBUSY); 874 return -EBUSY;
887} 875}
888 876
889static int r128_cce_get_buffers(DRMFILE filp, struct drm_device * dev, struct drm_dma * d) 877static int r128_cce_get_buffers(struct drm_device * dev,
878 struct drm_file *file_priv,
879 struct drm_dma * d)
890{ 880{
891 int i; 881 int i;
892 struct drm_buf *buf; 882 struct drm_buf *buf;
@@ -894,57 +884,51 @@ static int r128_cce_get_buffers(DRMFILE filp, struct drm_device * dev, struct dr
894 for (i = d->granted_count; i < d->request_count; i++) { 884 for (i = d->granted_count; i < d->request_count; i++) {
895 buf = r128_freelist_get(dev); 885 buf = r128_freelist_get(dev);
896 if (!buf) 886 if (!buf)
897 return DRM_ERR(EAGAIN); 887 return -EAGAIN;
898 888
899 buf->filp = filp; 889 buf->file_priv = file_priv;
900 890
901 if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx, 891 if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx,
902 sizeof(buf->idx))) 892 sizeof(buf->idx)))
903 return DRM_ERR(EFAULT); 893 return -EFAULT;
904 if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total, 894 if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total,
905 sizeof(buf->total))) 895 sizeof(buf->total)))
906 return DRM_ERR(EFAULT); 896 return -EFAULT;
907 897
908 d->granted_count++; 898 d->granted_count++;
909 } 899 }
910 return 0; 900 return 0;
911} 901}
912 902
913int r128_cce_buffers(DRM_IOCTL_ARGS) 903int r128_cce_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv)
914{ 904{
915 DRM_DEVICE;
916 struct drm_device_dma *dma = dev->dma; 905 struct drm_device_dma *dma = dev->dma;
917 int ret = 0; 906 int ret = 0;
918 struct drm_dma __user *argp = (void __user *)data; 907 struct drm_dma *d = data;
919 struct drm_dma d;
920 908
921 LOCK_TEST_WITH_RETURN(dev, filp); 909 LOCK_TEST_WITH_RETURN(dev, file_priv);
922
923 DRM_COPY_FROM_USER_IOCTL(d, argp, sizeof(d));
924 910
925 /* Please don't send us buffers. 911 /* Please don't send us buffers.
926 */ 912 */
927 if (d.send_count != 0) { 913 if (d->send_count != 0) {
928 DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n", 914 DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
929 DRM_CURRENTPID, d.send_count); 915 DRM_CURRENTPID, d->send_count);
930 return DRM_ERR(EINVAL); 916 return -EINVAL;
931 } 917 }
932 918
933 /* We'll send you buffers. 919 /* We'll send you buffers.
934 */ 920 */
935 if (d.request_count < 0 || d.request_count > dma->buf_count) { 921 if (d->request_count < 0 || d->request_count > dma->buf_count) {
936 DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n", 922 DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
937 DRM_CURRENTPID, d.request_count, dma->buf_count); 923 DRM_CURRENTPID, d->request_count, dma->buf_count);
938 return DRM_ERR(EINVAL); 924 return -EINVAL;
939 } 925 }
940 926
941 d.granted_count = 0; 927 d->granted_count = 0;
942 928
943 if (d.request_count) { 929 if (d->request_count) {
944 ret = r128_cce_get_buffers(filp, dev, &d); 930 ret = r128_cce_get_buffers(dev, file_priv, d);
945 } 931 }
946 932
947 DRM_COPY_TO_USER_IOCTL(argp, d, sizeof(d));
948
949 return ret; 933 return ret;
950} 934}