aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/drm/savage_state.c
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2007-09-02 22:06:45 -0400
committerDave Airlie <airlied@optimus.(none)>2007-10-14 20:38:20 -0400
commitc153f45f9b7e30289157bba3ff5682291df16caa (patch)
tree33f21e1ebd83ec548751f3d490afe6230ab99972 /drivers/char/drm/savage_state.c
parentb589ee5943a9610ebaea6e4e3433f2ae4d812b0b (diff)
drm: Replace DRM_IOCTL_ARGS with (dev, data, file_priv) and remove DRM_DEVICE.
The data is now in kernel space, copied in/out as appropriate according to t This results in DRM_COPY_{TO,FROM}_USER going away, and error paths to deal with those failures. This also means that XFree86 4.2.0 support for i810 DR is lost. Signed-off-by: Dave Airlie <airlied@linux.ie>
Diffstat (limited to 'drivers/char/drm/savage_state.c')
-rw-r--r--drivers/char/drm/savage_state.c102
1 files changed, 50 insertions, 52 deletions
diff --git a/drivers/char/drm/savage_state.c b/drivers/char/drm/savage_state.c
index 9a72d959084c..bf8e0e10fe21 100644
--- a/drivers/char/drm/savage_state.c
+++ b/drivers/char/drm/savage_state.c
@@ -953,13 +953,12 @@ static int savage_dispatch_draw(drm_savage_private_t * dev_priv,
953 return 0; 953 return 0;
954} 954}
955 955
956int savage_bci_cmdbuf(DRM_IOCTL_ARGS) 956int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_priv)
957{ 957{
958 DRM_DEVICE;
959 drm_savage_private_t *dev_priv = dev->dev_private; 958 drm_savage_private_t *dev_priv = dev->dev_private;
960 struct drm_device_dma *dma = dev->dma; 959 struct drm_device_dma *dma = dev->dma;
961 struct drm_buf *dmabuf; 960 struct drm_buf *dmabuf;
962 drm_savage_cmdbuf_t cmdbuf; 961 drm_savage_cmdbuf_t *cmdbuf = data;
963 drm_savage_cmd_header_t *kcmd_addr = NULL; 962 drm_savage_cmd_header_t *kcmd_addr = NULL;
964 drm_savage_cmd_header_t *first_draw_cmd; 963 drm_savage_cmd_header_t *first_draw_cmd;
965 unsigned int *kvb_addr = NULL; 964 unsigned int *kvb_addr = NULL;
@@ -971,17 +970,14 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
971 970
972 LOCK_TEST_WITH_RETURN(dev, file_priv); 971 LOCK_TEST_WITH_RETURN(dev, file_priv);
973 972
974 DRM_COPY_FROM_USER_IOCTL(cmdbuf, (drm_savage_cmdbuf_t __user *) data,
975 sizeof(cmdbuf));
976
977 if (dma && dma->buflist) { 973 if (dma && dma->buflist) {
978 if (cmdbuf.dma_idx > dma->buf_count) { 974 if (cmdbuf->dma_idx > dma->buf_count) {
979 DRM_ERROR 975 DRM_ERROR
980 ("vertex buffer index %u out of range (0-%u)\n", 976 ("vertex buffer index %u out of range (0-%u)\n",
981 cmdbuf.dma_idx, dma->buf_count - 1); 977 cmdbuf->dma_idx, dma->buf_count - 1);
982 return -EINVAL; 978 return -EINVAL;
983 } 979 }
984 dmabuf = dma->buflist[cmdbuf.dma_idx]; 980 dmabuf = dma->buflist[cmdbuf->dma_idx];
985 } else { 981 } else {
986 dmabuf = NULL; 982 dmabuf = NULL;
987 } 983 }
@@ -991,47 +987,47 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
991 * COPY_FROM_USER_UNCHECKED when done in other drivers, and is correct 987 * COPY_FROM_USER_UNCHECKED when done in other drivers, and is correct
992 * for locking on FreeBSD. 988 * for locking on FreeBSD.
993 */ 989 */
994 if (cmdbuf.size) { 990 if (cmdbuf->size) {
995 kcmd_addr = drm_alloc(cmdbuf.size * 8, DRM_MEM_DRIVER); 991 kcmd_addr = drm_alloc(cmdbuf->size * 8, DRM_MEM_DRIVER);
996 if (kcmd_addr == NULL) 992 if (kcmd_addr == NULL)
997 return -ENOMEM; 993 return -ENOMEM;
998 994
999 if (DRM_COPY_FROM_USER(kcmd_addr, cmdbuf.cmd_addr, 995 if (DRM_COPY_FROM_USER(kcmd_addr, cmdbuf->cmd_addr,
1000 cmdbuf.size * 8)) 996 cmdbuf->size * 8))
1001 { 997 {
1002 drm_free(kcmd_addr, cmdbuf.size * 8, DRM_MEM_DRIVER); 998 drm_free(kcmd_addr, cmdbuf->size * 8, DRM_MEM_DRIVER);
1003 return -EFAULT; 999 return -EFAULT;
1004 } 1000 }
1005 cmdbuf.cmd_addr = kcmd_addr; 1001 cmdbuf->cmd_addr = kcmd_addr;
1006 } 1002 }
1007 if (cmdbuf.vb_size) { 1003 if (cmdbuf->vb_size) {
1008 kvb_addr = drm_alloc(cmdbuf.vb_size, DRM_MEM_DRIVER); 1004 kvb_addr = drm_alloc(cmdbuf->vb_size, DRM_MEM_DRIVER);
1009 if (kvb_addr == NULL) { 1005 if (kvb_addr == NULL) {
1010 ret = -ENOMEM; 1006 ret = -ENOMEM;
1011 goto done; 1007 goto done;
1012 } 1008 }
1013 1009
1014 if (DRM_COPY_FROM_USER(kvb_addr, cmdbuf.vb_addr, 1010 if (DRM_COPY_FROM_USER(kvb_addr, cmdbuf->vb_addr,
1015 cmdbuf.vb_size)) { 1011 cmdbuf->vb_size)) {
1016 ret = -EFAULT; 1012 ret = -EFAULT;
1017 goto done; 1013 goto done;
1018 } 1014 }
1019 cmdbuf.vb_addr = kvb_addr; 1015 cmdbuf->vb_addr = kvb_addr;
1020 } 1016 }
1021 if (cmdbuf.nbox) { 1017 if (cmdbuf->nbox) {
1022 kbox_addr = drm_alloc(cmdbuf.nbox * sizeof(struct drm_clip_rect), 1018 kbox_addr = drm_alloc(cmdbuf->nbox * sizeof(struct drm_clip_rect),
1023 DRM_MEM_DRIVER); 1019 DRM_MEM_DRIVER);
1024 if (kbox_addr == NULL) { 1020 if (kbox_addr == NULL) {
1025 ret = -ENOMEM; 1021 ret = -ENOMEM;
1026 goto done; 1022 goto done;
1027 } 1023 }
1028 1024
1029 if (DRM_COPY_FROM_USER(kbox_addr, cmdbuf.box_addr, 1025 if (DRM_COPY_FROM_USER(kbox_addr, cmdbuf->box_addr,
1030 cmdbuf.nbox * sizeof(struct drm_clip_rect))) { 1026 cmdbuf->nbox * sizeof(struct drm_clip_rect))) {
1031 ret = -EFAULT; 1027 ret = -EFAULT;
1032 goto done; 1028 goto done;
1033 } 1029 }
1034 cmdbuf.box_addr = kbox_addr; 1030 cmdbuf->box_addr = kbox_addr;
1035 } 1031 }
1036 1032
1037 /* Make sure writes to DMA buffers are finished before sending 1033 /* Make sure writes to DMA buffers are finished before sending
@@ -1044,10 +1040,10 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
1044 1040
1045 i = 0; 1041 i = 0;
1046 first_draw_cmd = NULL; 1042 first_draw_cmd = NULL;
1047 while (i < cmdbuf.size) { 1043 while (i < cmdbuf->size) {
1048 drm_savage_cmd_header_t cmd_header; 1044 drm_savage_cmd_header_t cmd_header;
1049 cmd_header = *(drm_savage_cmd_header_t *)cmdbuf.cmd_addr; 1045 cmd_header = *(drm_savage_cmd_header_t *)cmdbuf->cmd_addr;
1050 cmdbuf.cmd_addr++; 1046 cmdbuf->cmd_addr++;
1051 i++; 1047 i++;
1052 1048
1053 /* Group drawing commands with same state to minimize 1049 /* Group drawing commands with same state to minimize
@@ -1057,7 +1053,7 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
1057 case SAVAGE_CMD_DMA_IDX: 1053 case SAVAGE_CMD_DMA_IDX:
1058 case SAVAGE_CMD_VB_IDX: 1054 case SAVAGE_CMD_VB_IDX:
1059 j = (cmd_header.idx.count + 3) / 4; 1055 j = (cmd_header.idx.count + 3) / 4;
1060 if (i + j > cmdbuf.size) { 1056 if (i + j > cmdbuf->size) {
1061 DRM_ERROR("indexed drawing command extends " 1057 DRM_ERROR("indexed drawing command extends "
1062 "beyond end of command buffer\n"); 1058 "beyond end of command buffer\n");
1063 DMA_FLUSH(); 1059 DMA_FLUSH();
@@ -1067,18 +1063,18 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
1067 case SAVAGE_CMD_DMA_PRIM: 1063 case SAVAGE_CMD_DMA_PRIM:
1068 case SAVAGE_CMD_VB_PRIM: 1064 case SAVAGE_CMD_VB_PRIM:
1069 if (!first_draw_cmd) 1065 if (!first_draw_cmd)
1070 first_draw_cmd = cmdbuf.cmd_addr - 1; 1066 first_draw_cmd = cmdbuf->cmd_addr - 1;
1071 cmdbuf.cmd_addr += j; 1067 cmdbuf->cmd_addr += j;
1072 i += j; 1068 i += j;
1073 break; 1069 break;
1074 default: 1070 default:
1075 if (first_draw_cmd) { 1071 if (first_draw_cmd) {
1076 ret = savage_dispatch_draw( 1072 ret = savage_dispatch_draw(
1077 dev_priv, first_draw_cmd, 1073 dev_priv, first_draw_cmd,
1078 cmdbuf.cmd_addr - 1, 1074 cmdbuf->cmd_addr - 1,
1079 dmabuf, cmdbuf.vb_addr, cmdbuf.vb_size, 1075 dmabuf, cmdbuf->vb_addr, cmdbuf->vb_size,
1080 cmdbuf.vb_stride, 1076 cmdbuf->vb_stride,
1081 cmdbuf.nbox, cmdbuf.box_addr); 1077 cmdbuf->nbox, cmdbuf->box_addr);
1082 if (ret != 0) 1078 if (ret != 0)
1083 return ret; 1079 return ret;
1084 first_draw_cmd = NULL; 1080 first_draw_cmd = NULL;
@@ -1090,7 +1086,7 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
1090 switch (cmd_header.cmd.cmd) { 1086 switch (cmd_header.cmd.cmd) {
1091 case SAVAGE_CMD_STATE: 1087 case SAVAGE_CMD_STATE:
1092 j = (cmd_header.state.count + 1) / 2; 1088 j = (cmd_header.state.count + 1) / 2;
1093 if (i + j > cmdbuf.size) { 1089 if (i + j > cmdbuf->size) {
1094 DRM_ERROR("command SAVAGE_CMD_STATE extends " 1090 DRM_ERROR("command SAVAGE_CMD_STATE extends "
1095 "beyond end of command buffer\n"); 1091 "beyond end of command buffer\n");
1096 DMA_FLUSH(); 1092 DMA_FLUSH();
@@ -1098,12 +1094,12 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
1098 goto done; 1094 goto done;
1099 } 1095 }
1100 ret = savage_dispatch_state(dev_priv, &cmd_header, 1096 ret = savage_dispatch_state(dev_priv, &cmd_header,
1101 (const uint32_t *)cmdbuf.cmd_addr); 1097 (const uint32_t *)cmdbuf->cmd_addr);
1102 cmdbuf.cmd_addr += j; 1098 cmdbuf->cmd_addr += j;
1103 i += j; 1099 i += j;
1104 break; 1100 break;
1105 case SAVAGE_CMD_CLEAR: 1101 case SAVAGE_CMD_CLEAR:
1106 if (i + 1 > cmdbuf.size) { 1102 if (i + 1 > cmdbuf->size) {
1107 DRM_ERROR("command SAVAGE_CMD_CLEAR extends " 1103 DRM_ERROR("command SAVAGE_CMD_CLEAR extends "
1108 "beyond end of command buffer\n"); 1104 "beyond end of command buffer\n");
1109 DMA_FLUSH(); 1105 DMA_FLUSH();
@@ -1111,17 +1107,19 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
1111 goto done; 1107 goto done;
1112 } 1108 }
1113 ret = savage_dispatch_clear(dev_priv, &cmd_header, 1109 ret = savage_dispatch_clear(dev_priv, &cmd_header,
1114 cmdbuf.cmd_addr, 1110 cmdbuf->cmd_addr,
1115 cmdbuf.nbox, cmdbuf.box_addr); 1111 cmdbuf->nbox,
1116 cmdbuf.cmd_addr++; 1112 cmdbuf->box_addr);
1113 cmdbuf->cmd_addr++;
1117 i++; 1114 i++;
1118 break; 1115 break;
1119 case SAVAGE_CMD_SWAP: 1116 case SAVAGE_CMD_SWAP:
1120 ret = savage_dispatch_swap(dev_priv, cmdbuf.nbox, 1117 ret = savage_dispatch_swap(dev_priv, cmdbuf->nbox,
1121 cmdbuf.box_addr); 1118 cmdbuf->box_addr);
1122 break; 1119 break;
1123 default: 1120 default:
1124 DRM_ERROR("invalid command 0x%x\n", cmd_header.cmd.cmd); 1121 DRM_ERROR("invalid command 0x%x\n",
1122 cmd_header.cmd.cmd);
1125 DMA_FLUSH(); 1123 DMA_FLUSH();
1126 ret = -EINVAL; 1124 ret = -EINVAL;
1127 goto done; 1125 goto done;
@@ -1135,9 +1133,9 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
1135 1133
1136 if (first_draw_cmd) { 1134 if (first_draw_cmd) {
1137 ret = savage_dispatch_draw ( 1135 ret = savage_dispatch_draw (
1138 dev_priv, first_draw_cmd, cmdbuf.cmd_addr, dmabuf, 1136 dev_priv, first_draw_cmd, cmdbuf->cmd_addr, dmabuf,
1139 cmdbuf.vb_addr, cmdbuf.vb_size, cmdbuf.vb_stride, 1137 cmdbuf->vb_addr, cmdbuf->vb_size, cmdbuf->vb_stride,
1140 cmdbuf.nbox, cmdbuf.box_addr); 1138 cmdbuf->nbox, cmdbuf->box_addr);
1141 if (ret != 0) { 1139 if (ret != 0) {
1142 DMA_FLUSH(); 1140 DMA_FLUSH();
1143 goto done; 1141 goto done;
@@ -1146,7 +1144,7 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
1146 1144
1147 DMA_FLUSH(); 1145 DMA_FLUSH();
1148 1146
1149 if (dmabuf && cmdbuf.discard) { 1147 if (dmabuf && cmdbuf->discard) {
1150 drm_savage_buf_priv_t *buf_priv = dmabuf->dev_private; 1148 drm_savage_buf_priv_t *buf_priv = dmabuf->dev_private;
1151 uint16_t event; 1149 uint16_t event;
1152 event = savage_bci_emit_event(dev_priv, SAVAGE_WAIT_3D); 1150 event = savage_bci_emit_event(dev_priv, SAVAGE_WAIT_3D);
@@ -1156,9 +1154,9 @@ int savage_bci_cmdbuf(DRM_IOCTL_ARGS)
1156 1154
1157done: 1155done:
1158 /* If we didn't need to allocate them, these'll be NULL */ 1156 /* If we didn't need to allocate them, these'll be NULL */
1159 drm_free(kcmd_addr, cmdbuf.size * 8, DRM_MEM_DRIVER); 1157 drm_free(kcmd_addr, cmdbuf->size * 8, DRM_MEM_DRIVER);
1160 drm_free(kvb_addr, cmdbuf.vb_size, DRM_MEM_DRIVER); 1158 drm_free(kvb_addr, cmdbuf->vb_size, DRM_MEM_DRIVER);
1161 drm_free(kbox_addr, cmdbuf.nbox * sizeof(struct drm_clip_rect), 1159 drm_free(kbox_addr, cmdbuf->nbox * sizeof(struct drm_clip_rect),
1162 DRM_MEM_DRIVER); 1160 DRM_MEM_DRIVER);
1163 1161
1164 return ret; 1162 return ret;