diff options
author | Alex Deucher <alexdeucher@gmail.com> | 2010-06-04 18:41:42 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2010-08-01 20:00:04 -0400 |
commit | 40e2a5c15d09e02a71711735564151c789f95032 (patch) | |
tree | 063600a6ea716a4dfde436bed8e34b3b99675ccb /drivers/gpu/drm/radeon | |
parent | 7f813377203a60be01a3354664edc5d3c746100d (diff) |
drm/radeon/kms: fix CS alignment checking for tiling (v2)
Covers depth, cb, and textures. Hopefully I got this right.
v2: - fix bugs:
https://bugs.freedesktop.org/show_bug.cgi?id=28327
https://bugs.freedesktop.org/show_bug.cgi?id=28381
- use ALIGNED(), IS_ALIGNED() macros
Signed-off-by: Alex Deucher <alexdeucher@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/radeon')
-rw-r--r-- | drivers/gpu/drm/radeon/r600_cs.c | 175 |
1 files changed, 136 insertions, 39 deletions
diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c index 5cab1b413b6c..39bac5c3bb2b 100644 --- a/drivers/gpu/drm/radeon/r600_cs.c +++ b/drivers/gpu/drm/radeon/r600_cs.c | |||
@@ -25,6 +25,7 @@ | |||
25 | * Alex Deucher | 25 | * Alex Deucher |
26 | * Jerome Glisse | 26 | * Jerome Glisse |
27 | */ | 27 | */ |
28 | #include <linux/kernel.h> | ||
28 | #include "drmP.h" | 29 | #include "drmP.h" |
29 | #include "radeon.h" | 30 | #include "radeon.h" |
30 | #include "r600d.h" | 31 | #include "r600d.h" |
@@ -166,7 +167,7 @@ static void r600_cs_track_init(struct r600_cs_track *track) | |||
166 | static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i) | 167 | static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i) |
167 | { | 168 | { |
168 | struct r600_cs_track *track = p->track; | 169 | struct r600_cs_track *track = p->track; |
169 | u32 bpe = 0, pitch, slice_tile_max, size, tmp, height; | 170 | u32 bpe = 0, pitch, slice_tile_max, size, tmp, height, pitch_align; |
170 | volatile u32 *ib = p->ib->ptr; | 171 | volatile u32 *ib = p->ib->ptr; |
171 | 172 | ||
172 | if (G_0280A0_TILE_MODE(track->cb_color_info[i])) { | 173 | if (G_0280A0_TILE_MODE(track->cb_color_info[i])) { |
@@ -180,56 +181,57 @@ static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i) | |||
180 | i, track->cb_color_info[i]); | 181 | i, track->cb_color_info[i]); |
181 | return -EINVAL; | 182 | return -EINVAL; |
182 | } | 183 | } |
183 | pitch = (G_028060_PITCH_TILE_MAX(track->cb_color_size[i]) + 1) << 3; | 184 | /* pitch is the number of 8x8 tiles per row */ |
185 | pitch = G_028060_PITCH_TILE_MAX(track->cb_color_size[i]) + 1; | ||
184 | slice_tile_max = G_028060_SLICE_TILE_MAX(track->cb_color_size[i]) + 1; | 186 | slice_tile_max = G_028060_SLICE_TILE_MAX(track->cb_color_size[i]) + 1; |
185 | if (!pitch) { | 187 | height = size / (pitch * 8 * bpe); |
186 | dev_warn(p->dev, "%s:%d cb pitch (%d) for %d invalid (0x%08X)\n", | ||
187 | __func__, __LINE__, pitch, i, track->cb_color_size[i]); | ||
188 | return -EINVAL; | ||
189 | } | ||
190 | height = size / (pitch * bpe); | ||
191 | if (height > 8192) | 188 | if (height > 8192) |
192 | height = 8192; | 189 | height = 8192; |
190 | if (height > 7) | ||
191 | height &= ~0x7; | ||
193 | switch (G_0280A0_ARRAY_MODE(track->cb_color_info[i])) { | 192 | switch (G_0280A0_ARRAY_MODE(track->cb_color_info[i])) { |
194 | case V_0280A0_ARRAY_LINEAR_GENERAL: | 193 | case V_0280A0_ARRAY_LINEAR_GENERAL: |
194 | /* technically height & 0x7 */ | ||
195 | break; | ||
195 | case V_0280A0_ARRAY_LINEAR_ALIGNED: | 196 | case V_0280A0_ARRAY_LINEAR_ALIGNED: |
196 | if (pitch & 0x3f) { | 197 | pitch_align = max((u32)64, (u32)(track->group_size / bpe)) / 8; |
197 | dev_warn(p->dev, "%s:%d cb pitch (%d x %d = %d) invalid\n", | 198 | if (!IS_ALIGNED(pitch, pitch_align)) { |
198 | __func__, __LINE__, pitch, bpe, pitch * bpe); | 199 | dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n", |
200 | __func__, __LINE__, pitch); | ||
199 | return -EINVAL; | 201 | return -EINVAL; |
200 | } | 202 | } |
201 | if ((pitch * bpe) & (track->group_size - 1)) { | 203 | if (!IS_ALIGNED(height, 8)) { |
202 | dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n", | 204 | dev_warn(p->dev, "%s:%d cb height (%d) invalid\n", |
203 | __func__, __LINE__, pitch); | 205 | __func__, __LINE__, height); |
204 | return -EINVAL; | 206 | return -EINVAL; |
205 | } | 207 | } |
206 | break; | 208 | break; |
207 | case V_0280A0_ARRAY_1D_TILED_THIN1: | 209 | case V_0280A0_ARRAY_1D_TILED_THIN1: |
208 | if ((pitch * 8 * bpe * track->nsamples) & (track->group_size - 1)) { | 210 | pitch_align = max((u32)8, (u32)(track->group_size / (8 * bpe * track->nsamples))) / 8; |
211 | if (!IS_ALIGNED(pitch, pitch_align)) { | ||
209 | dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n", | 212 | dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n", |
210 | __func__, __LINE__, pitch); | 213 | __func__, __LINE__, pitch); |
214 | return -EINVAL; | ||
215 | } | ||
216 | if (!IS_ALIGNED(height, 8)) { | ||
217 | dev_warn(p->dev, "%s:%d cb height (%d) invalid\n", | ||
218 | __func__, __LINE__, height); | ||
211 | return -EINVAL; | 219 | return -EINVAL; |
212 | } | 220 | } |
213 | height &= ~0x7; | ||
214 | if (!height) | ||
215 | height = 8; | ||
216 | break; | 221 | break; |
217 | case V_0280A0_ARRAY_2D_TILED_THIN1: | 222 | case V_0280A0_ARRAY_2D_TILED_THIN1: |
218 | if (pitch & ((8 * track->nbanks) - 1)) { | 223 | pitch_align = max((u32)track->nbanks, |
224 | (u32)(((track->group_size / 8) / (bpe * track->nsamples)) * track->nbanks)); | ||
225 | if (!IS_ALIGNED(pitch, pitch_align)) { | ||
219 | dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n", | 226 | dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n", |
220 | __func__, __LINE__, pitch); | 227 | __func__, __LINE__, pitch); |
221 | return -EINVAL; | 228 | return -EINVAL; |
222 | } | 229 | } |
223 | tmp = pitch * 8 * bpe * track->nsamples; | 230 | if (!IS_ALIGNED((height / 8), track->nbanks)) { |
224 | tmp = tmp / track->nbanks; | 231 | dev_warn(p->dev, "%s:%d cb height (%d) invalid\n", |
225 | if (tmp & (track->group_size - 1)) { | 232 | __func__, __LINE__, height); |
226 | dev_warn(p->dev, "%s:%d cb pitch (%d) invalid\n", | ||
227 | __func__, __LINE__, pitch); | ||
228 | return -EINVAL; | 233 | return -EINVAL; |
229 | } | 234 | } |
230 | height &= ~((16 * track->npipes) - 1); | ||
231 | if (!height) | ||
232 | height = 16 * track->npipes; | ||
233 | break; | 235 | break; |
234 | default: | 236 | default: |
235 | dev_warn(p->dev, "%s invalid tiling %d for %d (0x%08X)\n", __func__, | 237 | dev_warn(p->dev, "%s invalid tiling %d for %d (0x%08X)\n", __func__, |
@@ -238,16 +240,20 @@ static inline int r600_cs_track_validate_cb(struct radeon_cs_parser *p, int i) | |||
238 | return -EINVAL; | 240 | return -EINVAL; |
239 | } | 241 | } |
240 | /* check offset */ | 242 | /* check offset */ |
241 | tmp = height * pitch; | 243 | tmp = height * pitch * 8 * bpe; |
242 | if ((tmp + track->cb_color_bo_offset[i]) > radeon_bo_size(track->cb_color_bo[i])) { | 244 | if ((tmp + track->cb_color_bo_offset[i]) > radeon_bo_size(track->cb_color_bo[i])) { |
243 | dev_warn(p->dev, "%s offset[%d] %d to big\n", __func__, i, track->cb_color_bo_offset[i]); | 245 | dev_warn(p->dev, "%s offset[%d] %d too big\n", __func__, i, track->cb_color_bo_offset[i]); |
246 | return -EINVAL; | ||
247 | } | ||
248 | if (!IS_ALIGNED(track->cb_color_bo_offset[i], track->group_size)) { | ||
249 | dev_warn(p->dev, "%s offset[%d] %d not aligned\n", __func__, i, track->cb_color_bo_offset[i]); | ||
244 | return -EINVAL; | 250 | return -EINVAL; |
245 | } | 251 | } |
246 | /* limit max tile */ | 252 | /* limit max tile */ |
247 | tmp = (height * pitch) >> 6; | 253 | tmp = (height * pitch * 8) >> 6; |
248 | if (tmp < slice_tile_max) | 254 | if (tmp < slice_tile_max) |
249 | slice_tile_max = tmp; | 255 | slice_tile_max = tmp; |
250 | tmp = S_028060_PITCH_TILE_MAX((pitch >> 3) - 1) | | 256 | tmp = S_028060_PITCH_TILE_MAX(pitch - 1) | |
251 | S_028060_SLICE_TILE_MAX(slice_tile_max - 1); | 257 | S_028060_SLICE_TILE_MAX(slice_tile_max - 1); |
252 | ib[track->cb_color_size_idx[i]] = tmp; | 258 | ib[track->cb_color_size_idx[i]] = tmp; |
253 | return 0; | 259 | return 0; |
@@ -289,7 +295,7 @@ static int r600_cs_track_check(struct radeon_cs_parser *p) | |||
289 | /* Check depth buffer */ | 295 | /* Check depth buffer */ |
290 | if (G_028800_STENCIL_ENABLE(track->db_depth_control) || | 296 | if (G_028800_STENCIL_ENABLE(track->db_depth_control) || |
291 | G_028800_Z_ENABLE(track->db_depth_control)) { | 297 | G_028800_Z_ENABLE(track->db_depth_control)) { |
292 | u32 nviews, bpe, ntiles; | 298 | u32 nviews, bpe, ntiles, pitch, pitch_align, height, size; |
293 | if (track->db_bo == NULL) { | 299 | if (track->db_bo == NULL) { |
294 | dev_warn(p->dev, "z/stencil with no depth buffer\n"); | 300 | dev_warn(p->dev, "z/stencil with no depth buffer\n"); |
295 | return -EINVAL; | 301 | return -EINVAL; |
@@ -332,6 +338,51 @@ static int r600_cs_track_check(struct radeon_cs_parser *p) | |||
332 | } | 338 | } |
333 | ib[track->db_depth_size_idx] = S_028000_SLICE_TILE_MAX(tmp - 1) | (track->db_depth_size & 0x3FF); | 339 | ib[track->db_depth_size_idx] = S_028000_SLICE_TILE_MAX(tmp - 1) | (track->db_depth_size & 0x3FF); |
334 | } else { | 340 | } else { |
341 | size = radeon_bo_size(track->db_bo); | ||
342 | pitch = G_028000_PITCH_TILE_MAX(track->db_depth_size) + 1; | ||
343 | height = size / (pitch * 8 * bpe); | ||
344 | height &= ~0x7; | ||
345 | if (!height) | ||
346 | height = 8; | ||
347 | |||
348 | switch (G_028010_ARRAY_MODE(track->db_depth_info)) { | ||
349 | case V_028010_ARRAY_1D_TILED_THIN1: | ||
350 | pitch_align = (max((u32)8, (u32)(track->group_size / (8 * bpe))) / 8); | ||
351 | if (!IS_ALIGNED(pitch, pitch_align)) { | ||
352 | dev_warn(p->dev, "%s:%d db pitch (%d) invalid\n", | ||
353 | __func__, __LINE__, pitch); | ||
354 | return -EINVAL; | ||
355 | } | ||
356 | if (!IS_ALIGNED(height, 8)) { | ||
357 | dev_warn(p->dev, "%s:%d db height (%d) invalid\n", | ||
358 | __func__, __LINE__, height); | ||
359 | return -EINVAL; | ||
360 | } | ||
361 | break; | ||
362 | case V_028010_ARRAY_2D_TILED_THIN1: | ||
363 | pitch_align = max((u32)track->nbanks, | ||
364 | (u32)(((track->group_size / 8) / bpe) * track->nbanks)); | ||
365 | if (!IS_ALIGNED(pitch, pitch_align)) { | ||
366 | dev_warn(p->dev, "%s:%d db pitch (%d) invalid\n", | ||
367 | __func__, __LINE__, pitch); | ||
368 | return -EINVAL; | ||
369 | } | ||
370 | if ((height / 8) & (track->nbanks - 1)) { | ||
371 | dev_warn(p->dev, "%s:%d db height (%d) invalid\n", | ||
372 | __func__, __LINE__, height); | ||
373 | return -EINVAL; | ||
374 | } | ||
375 | break; | ||
376 | default: | ||
377 | dev_warn(p->dev, "%s invalid tiling %d (0x%08X)\n", __func__, | ||
378 | G_028010_ARRAY_MODE(track->db_depth_info), | ||
379 | track->db_depth_info); | ||
380 | return -EINVAL; | ||
381 | } | ||
382 | if (!IS_ALIGNED(track->db_offset, track->group_size)) { | ||
383 | dev_warn(p->dev, "%s offset[%d] %d not aligned\n", __func__, i, track->db_offset); | ||
384 | return -EINVAL; | ||
385 | } | ||
335 | ntiles = G_028000_SLICE_TILE_MAX(track->db_depth_size) + 1; | 386 | ntiles = G_028000_SLICE_TILE_MAX(track->db_depth_size) + 1; |
336 | nviews = G_028004_SLICE_MAX(track->db_depth_view) + 1; | 387 | nviews = G_028004_SLICE_MAX(track->db_depth_view) + 1; |
337 | tmp = ntiles * bpe * 64 * nviews; | 388 | tmp = ntiles * bpe * 64 * nviews; |
@@ -982,8 +1033,9 @@ static inline unsigned minify(unsigned size, unsigned levels) | |||
982 | } | 1033 | } |
983 | 1034 | ||
984 | static void r600_texture_size(unsigned nfaces, unsigned blevel, unsigned nlevels, | 1035 | static void r600_texture_size(unsigned nfaces, unsigned blevel, unsigned nlevels, |
985 | unsigned w0, unsigned h0, unsigned d0, unsigned bpe, | 1036 | unsigned w0, unsigned h0, unsigned d0, unsigned bpe, |
986 | unsigned *l0_size, unsigned *mipmap_size) | 1037 | unsigned pitch_align, |
1038 | unsigned *l0_size, unsigned *mipmap_size) | ||
987 | { | 1039 | { |
988 | unsigned offset, i, level, face; | 1040 | unsigned offset, i, level, face; |
989 | unsigned width, height, depth, rowstride, size; | 1041 | unsigned width, height, depth, rowstride, size; |
@@ -996,13 +1048,13 @@ static void r600_texture_size(unsigned nfaces, unsigned blevel, unsigned nlevels | |||
996 | height = minify(h0, i); | 1048 | height = minify(h0, i); |
997 | depth = minify(d0, i); | 1049 | depth = minify(d0, i); |
998 | for(face = 0; face < nfaces; face++) { | 1050 | for(face = 0; face < nfaces; face++) { |
999 | rowstride = ((width * bpe) + 255) & ~255; | 1051 | rowstride = ALIGN((width * bpe), pitch_align); |
1000 | size = height * rowstride * depth; | 1052 | size = height * rowstride * depth; |
1001 | offset += size; | 1053 | offset += size; |
1002 | offset = (offset + 0x1f) & ~0x1f; | 1054 | offset = (offset + 0x1f) & ~0x1f; |
1003 | } | 1055 | } |
1004 | } | 1056 | } |
1005 | *l0_size = (((w0 * bpe) + 255) & ~255) * h0 * d0; | 1057 | *l0_size = ALIGN((w0 * bpe), pitch_align) * h0 * d0; |
1006 | *mipmap_size = offset; | 1058 | *mipmap_size = offset; |
1007 | if (!blevel) | 1059 | if (!blevel) |
1008 | *mipmap_size -= *l0_size; | 1060 | *mipmap_size -= *l0_size; |
@@ -1025,8 +1077,9 @@ static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 i | |||
1025 | struct radeon_bo *mipmap, | 1077 | struct radeon_bo *mipmap, |
1026 | u32 tiling_flags) | 1078 | u32 tiling_flags) |
1027 | { | 1079 | { |
1080 | struct r600_cs_track *track = p->track; | ||
1028 | u32 nfaces, nlevels, blevel, w0, h0, d0, bpe = 0; | 1081 | u32 nfaces, nlevels, blevel, w0, h0, d0, bpe = 0; |
1029 | u32 word0, word1, l0_size, mipmap_size; | 1082 | u32 word0, word1, l0_size, mipmap_size, pitch, pitch_align; |
1030 | 1083 | ||
1031 | /* on legacy kernel we don't perform advanced check */ | 1084 | /* on legacy kernel we don't perform advanced check */ |
1032 | if (p->rdev == NULL) | 1085 | if (p->rdev == NULL) |
@@ -1063,11 +1116,55 @@ static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 i | |||
1063 | __func__, __LINE__, G_038004_DATA_FORMAT(word1)); | 1116 | __func__, __LINE__, G_038004_DATA_FORMAT(word1)); |
1064 | return -EINVAL; | 1117 | return -EINVAL; |
1065 | } | 1118 | } |
1119 | |||
1120 | pitch = G_038000_PITCH(word0) + 1; | ||
1121 | switch (G_038000_TILE_MODE(word0)) { | ||
1122 | case V_038000_ARRAY_LINEAR_GENERAL: | ||
1123 | pitch_align = 1; | ||
1124 | /* XXX check height align */ | ||
1125 | break; | ||
1126 | case V_038000_ARRAY_LINEAR_ALIGNED: | ||
1127 | pitch_align = max((u32)64, (u32)(track->group_size / bpe)) / 8; | ||
1128 | if (!IS_ALIGNED(pitch, pitch_align)) { | ||
1129 | dev_warn(p->dev, "%s:%d tex pitch (%d) invalid\n", | ||
1130 | __func__, __LINE__, pitch); | ||
1131 | return -EINVAL; | ||
1132 | } | ||
1133 | /* XXX check height align */ | ||
1134 | break; | ||
1135 | case V_038000_ARRAY_1D_TILED_THIN1: | ||
1136 | pitch_align = max((u32)8, (u32)(track->group_size / (8 * bpe))) / 8; | ||
1137 | if (!IS_ALIGNED(pitch, pitch_align)) { | ||
1138 | dev_warn(p->dev, "%s:%d tex pitch (%d) invalid\n", | ||
1139 | __func__, __LINE__, pitch); | ||
1140 | return -EINVAL; | ||
1141 | } | ||
1142 | /* XXX check height align */ | ||
1143 | break; | ||
1144 | case V_038000_ARRAY_2D_TILED_THIN1: | ||
1145 | pitch_align = max((u32)track->nbanks, | ||
1146 | (u32)(((track->group_size / 8) / bpe) * track->nbanks)); | ||
1147 | if (!IS_ALIGNED(pitch, pitch_align)) { | ||
1148 | dev_warn(p->dev, "%s:%d tex pitch (%d) invalid\n", | ||
1149 | __func__, __LINE__, pitch); | ||
1150 | return -EINVAL; | ||
1151 | } | ||
1152 | /* XXX check height align */ | ||
1153 | break; | ||
1154 | default: | ||
1155 | dev_warn(p->dev, "%s invalid tiling %d (0x%08X)\n", __func__, | ||
1156 | G_038000_TILE_MODE(word0), word0); | ||
1157 | return -EINVAL; | ||
1158 | } | ||
1159 | /* XXX check offset align */ | ||
1160 | |||
1066 | word0 = radeon_get_ib_value(p, idx + 4); | 1161 | word0 = radeon_get_ib_value(p, idx + 4); |
1067 | word1 = radeon_get_ib_value(p, idx + 5); | 1162 | word1 = radeon_get_ib_value(p, idx + 5); |
1068 | blevel = G_038010_BASE_LEVEL(word0); | 1163 | blevel = G_038010_BASE_LEVEL(word0); |
1069 | nlevels = G_038014_LAST_LEVEL(word1); | 1164 | nlevels = G_038014_LAST_LEVEL(word1); |
1070 | r600_texture_size(nfaces, blevel, nlevels, w0, h0, d0, bpe, &l0_size, &mipmap_size); | 1165 | r600_texture_size(nfaces, blevel, nlevels, w0, h0, d0, bpe, |
1166 | (pitch_align * bpe), | ||
1167 | &l0_size, &mipmap_size); | ||
1071 | /* using get ib will give us the offset into the texture bo */ | 1168 | /* using get ib will give us the offset into the texture bo */ |
1072 | word0 = radeon_get_ib_value(p, idx + 2); | 1169 | word0 = radeon_get_ib_value(p, idx + 2); |
1073 | if ((l0_size + word0) > radeon_bo_size(texture)) { | 1170 | if ((l0_size + word0) > radeon_bo_size(texture)) { |