aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/drm/mga_state.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/drm/mga_state.c')
-rw-r--r--drivers/char/drm/mga_state.c149
1 files changed, 54 insertions, 95 deletions
diff --git a/drivers/char/drm/mga_state.c b/drivers/char/drm/mga_state.c
index 74811727595a..5ec8b61c5d45 100644
--- a/drivers/char/drm/mga_state.c
+++ b/drivers/char/drm/mga_state.c
@@ -828,24 +828,20 @@ static void mga_dma_dispatch_blit(struct drm_device * dev, drm_mga_blit_t * blit
828 * 828 *
829 */ 829 */
830 830
831static int mga_dma_clear(DRM_IOCTL_ARGS) 831static int mga_dma_clear(struct drm_device *dev, void *data, struct drm_file *file_priv)
832{ 832{
833 DRM_DEVICE;
834 drm_mga_private_t *dev_priv = dev->dev_private; 833 drm_mga_private_t *dev_priv = dev->dev_private;
835 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv; 834 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
836 drm_mga_clear_t clear; 835 drm_mga_clear_t *clear = data;
837 836
838 LOCK_TEST_WITH_RETURN(dev, file_priv); 837 LOCK_TEST_WITH_RETURN(dev, file_priv);
839 838
840 DRM_COPY_FROM_USER_IOCTL(clear, (drm_mga_clear_t __user *) data,
841 sizeof(clear));
842
843 if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS) 839 if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
844 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS; 840 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
845 841
846 WRAP_TEST_WITH_RETURN(dev_priv); 842 WRAP_TEST_WITH_RETURN(dev_priv);
847 843
848 mga_dma_dispatch_clear(dev, &clear); 844 mga_dma_dispatch_clear(dev, clear);
849 845
850 /* Make sure we restore the 3D state next time. 846 /* Make sure we restore the 3D state next time.
851 */ 847 */
@@ -854,9 +850,8 @@ static int mga_dma_clear(DRM_IOCTL_ARGS)
854 return 0; 850 return 0;
855} 851}
856 852
857static int mga_dma_swap(DRM_IOCTL_ARGS) 853static int mga_dma_swap(struct drm_device *dev, void *data, struct drm_file *file_priv)
858{ 854{
859 DRM_DEVICE;
860 drm_mga_private_t *dev_priv = dev->dev_private; 855 drm_mga_private_t *dev_priv = dev->dev_private;
861 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv; 856 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
862 857
@@ -876,31 +871,26 @@ static int mga_dma_swap(DRM_IOCTL_ARGS)
876 return 0; 871 return 0;
877} 872}
878 873
879static int mga_dma_vertex(DRM_IOCTL_ARGS) 874static int mga_dma_vertex(struct drm_device *dev, void *data, struct drm_file *file_priv)
880{ 875{
881 DRM_DEVICE;
882 drm_mga_private_t *dev_priv = dev->dev_private; 876 drm_mga_private_t *dev_priv = dev->dev_private;
883 struct drm_device_dma *dma = dev->dma; 877 struct drm_device_dma *dma = dev->dma;
884 struct drm_buf *buf; 878 struct drm_buf *buf;
885 drm_mga_buf_priv_t *buf_priv; 879 drm_mga_buf_priv_t *buf_priv;
886 drm_mga_vertex_t vertex; 880 drm_mga_vertex_t *vertex = data;
887 881
888 LOCK_TEST_WITH_RETURN(dev, file_priv); 882 LOCK_TEST_WITH_RETURN(dev, file_priv);
889 883
890 DRM_COPY_FROM_USER_IOCTL(vertex, 884 if (vertex->idx < 0 || vertex->idx > dma->buf_count)
891 (drm_mga_vertex_t __user *) data,
892 sizeof(vertex));
893
894 if (vertex.idx < 0 || vertex.idx > dma->buf_count)
895 return -EINVAL; 885 return -EINVAL;
896 buf = dma->buflist[vertex.idx]; 886 buf = dma->buflist[vertex->idx];
897 buf_priv = buf->dev_private; 887 buf_priv = buf->dev_private;
898 888
899 buf->used = vertex.used; 889 buf->used = vertex->used;
900 buf_priv->discard = vertex.discard; 890 buf_priv->discard = vertex->discard;
901 891
902 if (!mga_verify_state(dev_priv)) { 892 if (!mga_verify_state(dev_priv)) {
903 if (vertex.discard) { 893 if (vertex->discard) {
904 if (buf_priv->dispatched == 1) 894 if (buf_priv->dispatched == 1)
905 AGE_BUFFER(buf_priv); 895 AGE_BUFFER(buf_priv);
906 buf_priv->dispatched = 0; 896 buf_priv->dispatched = 0;
@@ -916,31 +906,26 @@ static int mga_dma_vertex(DRM_IOCTL_ARGS)
916 return 0; 906 return 0;
917} 907}
918 908
919static int mga_dma_indices(DRM_IOCTL_ARGS) 909static int mga_dma_indices(struct drm_device *dev, void *data, struct drm_file *file_priv)
920{ 910{
921 DRM_DEVICE;
922 drm_mga_private_t *dev_priv = dev->dev_private; 911 drm_mga_private_t *dev_priv = dev->dev_private;
923 struct drm_device_dma *dma = dev->dma; 912 struct drm_device_dma *dma = dev->dma;
924 struct drm_buf *buf; 913 struct drm_buf *buf;
925 drm_mga_buf_priv_t *buf_priv; 914 drm_mga_buf_priv_t *buf_priv;
926 drm_mga_indices_t indices; 915 drm_mga_indices_t *indices = data;
927 916
928 LOCK_TEST_WITH_RETURN(dev, file_priv); 917 LOCK_TEST_WITH_RETURN(dev, file_priv);
929 918
930 DRM_COPY_FROM_USER_IOCTL(indices, 919 if (indices->idx < 0 || indices->idx > dma->buf_count)
931 (drm_mga_indices_t __user *) data,
932 sizeof(indices));
933
934 if (indices.idx < 0 || indices.idx > dma->buf_count)
935 return -EINVAL; 920 return -EINVAL;
936 921
937 buf = dma->buflist[indices.idx]; 922 buf = dma->buflist[indices->idx];
938 buf_priv = buf->dev_private; 923 buf_priv = buf->dev_private;
939 924
940 buf_priv->discard = indices.discard; 925 buf_priv->discard = indices->discard;
941 926
942 if (!mga_verify_state(dev_priv)) { 927 if (!mga_verify_state(dev_priv)) {
943 if (indices.discard) { 928 if (indices->discard) {
944 if (buf_priv->dispatched == 1) 929 if (buf_priv->dispatched == 1)
945 AGE_BUFFER(buf_priv); 930 AGE_BUFFER(buf_priv);
946 buf_priv->dispatched = 0; 931 buf_priv->dispatched = 0;
@@ -951,26 +936,22 @@ static int mga_dma_indices(DRM_IOCTL_ARGS)
951 936
952 WRAP_TEST_WITH_RETURN(dev_priv); 937 WRAP_TEST_WITH_RETURN(dev_priv);
953 938
954 mga_dma_dispatch_indices(dev, buf, indices.start, indices.end); 939 mga_dma_dispatch_indices(dev, buf, indices->start, indices->end);
955 940
956 return 0; 941 return 0;
957} 942}
958 943
959static int mga_dma_iload(DRM_IOCTL_ARGS) 944static int mga_dma_iload(struct drm_device *dev, void *data, struct drm_file *file_priv)
960{ 945{
961 DRM_DEVICE;
962 struct drm_device_dma *dma = dev->dma; 946 struct drm_device_dma *dma = dev->dma;
963 drm_mga_private_t *dev_priv = dev->dev_private; 947 drm_mga_private_t *dev_priv = dev->dev_private;
964 struct drm_buf *buf; 948 struct drm_buf *buf;
965 drm_mga_buf_priv_t *buf_priv; 949 drm_mga_buf_priv_t *buf_priv;
966 drm_mga_iload_t iload; 950 drm_mga_iload_t *iload = data;
967 DRM_DEBUG("\n"); 951 DRM_DEBUG("\n");
968 952
969 LOCK_TEST_WITH_RETURN(dev, file_priv); 953 LOCK_TEST_WITH_RETURN(dev, file_priv);
970 954
971 DRM_COPY_FROM_USER_IOCTL(iload, (drm_mga_iload_t __user *) data,
972 sizeof(iload));
973
974#if 0 955#if 0
975 if (mga_do_wait_for_idle(dev_priv) < 0) { 956 if (mga_do_wait_for_idle(dev_priv) < 0) {
976 if (MGA_DMA_DEBUG) 957 if (MGA_DMA_DEBUG)
@@ -978,20 +959,20 @@ static int mga_dma_iload(DRM_IOCTL_ARGS)
978 return -EBUSY; 959 return -EBUSY;
979 } 960 }
980#endif 961#endif
981 if (iload.idx < 0 || iload.idx > dma->buf_count) 962 if (iload->idx < 0 || iload->idx > dma->buf_count)
982 return -EINVAL; 963 return -EINVAL;
983 964
984 buf = dma->buflist[iload.idx]; 965 buf = dma->buflist[iload->idx];
985 buf_priv = buf->dev_private; 966 buf_priv = buf->dev_private;
986 967
987 if (mga_verify_iload(dev_priv, iload.dstorg, iload.length)) { 968 if (mga_verify_iload(dev_priv, iload->dstorg, iload->length)) {
988 mga_freelist_put(dev, buf); 969 mga_freelist_put(dev, buf);
989 return -EINVAL; 970 return -EINVAL;
990 } 971 }
991 972
992 WRAP_TEST_WITH_RETURN(dev_priv); 973 WRAP_TEST_WITH_RETURN(dev_priv);
993 974
994 mga_dma_dispatch_iload(dev, buf, iload.dstorg, iload.length); 975 mga_dma_dispatch_iload(dev, buf, iload->dstorg, iload->length);
995 976
996 /* Make sure we restore the 3D state next time. 977 /* Make sure we restore the 3D state next time.
997 */ 978 */
@@ -1000,28 +981,24 @@ static int mga_dma_iload(DRM_IOCTL_ARGS)
1000 return 0; 981 return 0;
1001} 982}
1002 983
1003static int mga_dma_blit(DRM_IOCTL_ARGS) 984static int mga_dma_blit(struct drm_device *dev, void *data, struct drm_file *file_priv)
1004{ 985{
1005 DRM_DEVICE;
1006 drm_mga_private_t *dev_priv = dev->dev_private; 986 drm_mga_private_t *dev_priv = dev->dev_private;
1007 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv; 987 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
1008 drm_mga_blit_t blit; 988 drm_mga_blit_t *blit = data;
1009 DRM_DEBUG("\n"); 989 DRM_DEBUG("\n");
1010 990
1011 LOCK_TEST_WITH_RETURN(dev, file_priv); 991 LOCK_TEST_WITH_RETURN(dev, file_priv);
1012 992
1013 DRM_COPY_FROM_USER_IOCTL(blit, (drm_mga_blit_t __user *) data,
1014 sizeof(blit));
1015
1016 if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS) 993 if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
1017 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS; 994 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
1018 995
1019 if (mga_verify_blit(dev_priv, blit.srcorg, blit.dstorg)) 996 if (mga_verify_blit(dev_priv, blit->srcorg, blit->dstorg))
1020 return -EINVAL; 997 return -EINVAL;
1021 998
1022 WRAP_TEST_WITH_RETURN(dev_priv); 999 WRAP_TEST_WITH_RETURN(dev_priv);
1023 1000
1024 mga_dma_dispatch_blit(dev, &blit); 1001 mga_dma_dispatch_blit(dev, blit);
1025 1002
1026 /* Make sure we restore the 3D state next time. 1003 /* Make sure we restore the 3D state next time.
1027 */ 1004 */
@@ -1030,11 +1007,10 @@ static int mga_dma_blit(DRM_IOCTL_ARGS)
1030 return 0; 1007 return 0;
1031} 1008}
1032 1009
1033static int mga_getparam(DRM_IOCTL_ARGS) 1010static int mga_getparam(struct drm_device *dev, void *data, struct drm_file *file_priv)
1034{ 1011{
1035 DRM_DEVICE;
1036 drm_mga_private_t *dev_priv = dev->dev_private; 1012 drm_mga_private_t *dev_priv = dev->dev_private;
1037 drm_mga_getparam_t param; 1013 drm_mga_getparam_t *param = data;
1038 int value; 1014 int value;
1039 1015
1040 if (!dev_priv) { 1016 if (!dev_priv) {
@@ -1042,12 +1018,9 @@ static int mga_getparam(DRM_IOCTL_ARGS)
1042 return -EINVAL; 1018 return -EINVAL;
1043 } 1019 }
1044 1020
1045 DRM_COPY_FROM_USER_IOCTL(param, (drm_mga_getparam_t __user *) data,
1046 sizeof(param));
1047
1048 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID); 1021 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
1049 1022
1050 switch (param.param) { 1023 switch (param->param) {
1051 case MGA_PARAM_IRQ_NR: 1024 case MGA_PARAM_IRQ_NR:
1052 value = dev->irq; 1025 value = dev->irq;
1053 break; 1026 break;
@@ -1058,7 +1031,7 @@ static int mga_getparam(DRM_IOCTL_ARGS)
1058 return -EINVAL; 1031 return -EINVAL;
1059 } 1032 }
1060 1033
1061 if (DRM_COPY_TO_USER(param.value, &value, sizeof(int))) { 1034 if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
1062 DRM_ERROR("copy_to_user\n"); 1035 DRM_ERROR("copy_to_user\n");
1063 return -EFAULT; 1036 return -EFAULT;
1064 } 1037 }
@@ -1066,11 +1039,10 @@ static int mga_getparam(DRM_IOCTL_ARGS)
1066 return 0; 1039 return 0;
1067} 1040}
1068 1041
1069static int mga_set_fence(DRM_IOCTL_ARGS) 1042static int mga_set_fence(struct drm_device *dev, void *data, struct drm_file *file_priv)
1070{ 1043{
1071 DRM_DEVICE;
1072 drm_mga_private_t *dev_priv = dev->dev_private; 1044 drm_mga_private_t *dev_priv = dev->dev_private;
1073 u32 temp; 1045 u32 *fence = data;
1074 DMA_LOCALS; 1046 DMA_LOCALS;
1075 1047
1076 if (!dev_priv) { 1048 if (!dev_priv) {
@@ -1080,11 +1052,11 @@ static int mga_set_fence(DRM_IOCTL_ARGS)
1080 1052
1081 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID); 1053 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
1082 1054
1083 /* I would normal do this assignment in the declaration of temp, 1055 /* I would normal do this assignment in the declaration of fence,
1084 * but dev_priv may be NULL. 1056 * but dev_priv may be NULL.
1085 */ 1057 */
1086 1058
1087 temp = dev_priv->next_fence_to_post; 1059 *fence = dev_priv->next_fence_to_post;
1088 dev_priv->next_fence_to_post++; 1060 dev_priv->next_fence_to_post++;
1089 1061
1090 BEGIN_DMA(1); 1062 BEGIN_DMA(1);
@@ -1093,53 +1065,40 @@ static int mga_set_fence(DRM_IOCTL_ARGS)
1093 MGA_DMAPAD, 0x00000000, MGA_SOFTRAP, 0x00000000); 1065 MGA_DMAPAD, 0x00000000, MGA_SOFTRAP, 0x00000000);
1094 ADVANCE_DMA(); 1066 ADVANCE_DMA();
1095 1067
1096 if (DRM_COPY_TO_USER((u32 __user *) data, &temp, sizeof(u32))) {
1097 DRM_ERROR("copy_to_user\n");
1098 return -EFAULT;
1099 }
1100
1101 return 0; 1068 return 0;
1102} 1069}
1103 1070
1104static int mga_wait_fence(DRM_IOCTL_ARGS) 1071static int mga_wait_fence(struct drm_device *dev, void *data, struct drm_file *
1072file_priv)
1105{ 1073{
1106 DRM_DEVICE;
1107 drm_mga_private_t *dev_priv = dev->dev_private; 1074 drm_mga_private_t *dev_priv = dev->dev_private;
1108 u32 fence; 1075 u32 *fence = data;
1109 1076
1110 if (!dev_priv) { 1077 if (!dev_priv) {
1111 DRM_ERROR("%s called with no initialization\n", __FUNCTION__); 1078 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1112 return -EINVAL; 1079 return -EINVAL;
1113 } 1080 }
1114 1081
1115 DRM_COPY_FROM_USER_IOCTL(fence, (u32 __user *) data, sizeof(u32));
1116
1117 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID); 1082 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
1118 1083
1119 mga_driver_fence_wait(dev, &fence); 1084 mga_driver_fence_wait(dev, fence);
1120
1121 if (DRM_COPY_TO_USER((u32 __user *) data, &fence, sizeof(u32))) {
1122 DRM_ERROR("copy_to_user\n");
1123 return -EFAULT;
1124 }
1125
1126 return 0; 1085 return 0;
1127} 1086}
1128 1087
1129drm_ioctl_desc_t mga_ioctls[] = { 1088struct drm_ioctl_desc mga_ioctls[] = {
1130 [DRM_IOCTL_NR(DRM_MGA_INIT)] = {mga_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 1089 DRM_IOCTL_DEF(DRM_MGA_INIT, mga_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1131 [DRM_IOCTL_NR(DRM_MGA_FLUSH)] = {mga_dma_flush, DRM_AUTH}, 1090 DRM_IOCTL_DEF(DRM_MGA_FLUSH, mga_dma_flush, DRM_AUTH),
1132 [DRM_IOCTL_NR(DRM_MGA_RESET)] = {mga_dma_reset, DRM_AUTH}, 1091 DRM_IOCTL_DEF(DRM_MGA_RESET, mga_dma_reset, DRM_AUTH),
1133 [DRM_IOCTL_NR(DRM_MGA_SWAP)] = {mga_dma_swap, DRM_AUTH}, 1092 DRM_IOCTL_DEF(DRM_MGA_SWAP, mga_dma_swap, DRM_AUTH),
1134 [DRM_IOCTL_NR(DRM_MGA_CLEAR)] = {mga_dma_clear, DRM_AUTH}, 1093 DRM_IOCTL_DEF(DRM_MGA_CLEAR, mga_dma_clear, DRM_AUTH),
1135 [DRM_IOCTL_NR(DRM_MGA_VERTEX)] = {mga_dma_vertex, DRM_AUTH}, 1094 DRM_IOCTL_DEF(DRM_MGA_VERTEX, mga_dma_vertex, DRM_AUTH),
1136 [DRM_IOCTL_NR(DRM_MGA_INDICES)] = {mga_dma_indices, DRM_AUTH}, 1095 DRM_IOCTL_DEF(DRM_MGA_INDICES, mga_dma_indices, DRM_AUTH),
1137 [DRM_IOCTL_NR(DRM_MGA_ILOAD)] = {mga_dma_iload, DRM_AUTH}, 1096 DRM_IOCTL_DEF(DRM_MGA_ILOAD, mga_dma_iload, DRM_AUTH),
1138 [DRM_IOCTL_NR(DRM_MGA_BLIT)] = {mga_dma_blit, DRM_AUTH}, 1097 DRM_IOCTL_DEF(DRM_MGA_BLIT, mga_dma_blit, DRM_AUTH),
1139 [DRM_IOCTL_NR(DRM_MGA_GETPARAM)] = {mga_getparam, DRM_AUTH}, 1098 DRM_IOCTL_DEF(DRM_MGA_GETPARAM, mga_getparam, DRM_AUTH),
1140 [DRM_IOCTL_NR(DRM_MGA_SET_FENCE)] = {mga_set_fence, DRM_AUTH}, 1099 DRM_IOCTL_DEF(DRM_MGA_SET_FENCE, mga_set_fence, DRM_AUTH),
1141 [DRM_IOCTL_NR(DRM_MGA_WAIT_FENCE)] = {mga_wait_fence, DRM_AUTH}, 1100 DRM_IOCTL_DEF(DRM_MGA_WAIT_FENCE, mga_wait_fence, DRM_AUTH),
1142 [DRM_IOCTL_NR(DRM_MGA_DMA_BOOTSTRAP)] = {mga_dma_bootstrap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 1101 DRM_IOCTL_DEF(DRM_MGA_DMA_BOOTSTRAP, mga_dma_bootstrap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1143}; 1102};
1144 1103
1145int mga_max_ioctl = DRM_ARRAY_SIZE(mga_ioctls); 1104int mga_max_ioctl = DRM_ARRAY_SIZE(mga_ioctls);