aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Olšák <marek.olsak@amd.com>2015-05-14 17:48:26 -0400
committerAlex Deucher <alexander.deucher@amd.com>2015-06-03 21:03:46 -0400
commitfbd76d59efe061c89d4ba14eef3a2cac1e3056c2 (patch)
tree7fbb02d149ed64072cbf05a1e05292749bd51292
parent63ab1c2beefe36d49a19f9f715fefdc293546e39 (diff)
drm/amdgpu: rework tiling flags
Signed-off-by: Marek Olšák <marek.olsak@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Acked-by: Christian König <christian.koenig@amd.com>
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c3
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_object.c43
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v10_0.c92
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v11_0.c93
-rw-r--r--drivers/gpu/drm/amd/amdgpu/dce_v8_0.c91
-rw-r--r--include/uapi/drm/amdgpu_drm.h40
6 files changed, 58 insertions, 304 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index ef611986b2b6..73b7aad5a872 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -32,6 +32,7 @@
32#include <drm/drm_crtc_helper.h> 32#include <drm/drm_crtc_helper.h>
33#include <drm/amdgpu_drm.h> 33#include <drm/amdgpu_drm.h>
34#include "amdgpu.h" 34#include "amdgpu.h"
35#include "cikd.h"
35 36
36#include <drm/drm_fb_helper.h> 37#include <drm/drm_fb_helper.h>
37 38
@@ -135,7 +136,7 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev,
135 rbo = gem_to_amdgpu_bo(gobj); 136 rbo = gem_to_amdgpu_bo(gobj);
136 137
137 if (fb_tiled) 138 if (fb_tiled)
138 tiling_flags = AMDGPU_TILING_MACRO; 139 tiling_flags = AMDGPU_TILING_SET(ARRAY_MODE, GRPH_ARRAY_2D_TILED_THIN1);
139 140
140 ret = amdgpu_bo_reserve(rbo, false); 141 ret = amdgpu_bo_reserve(rbo, false);
141 if (unlikely(ret != 0)) 142 if (unlikely(ret != 0))
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index a721f5044557..b545f614628c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -459,49 +459,8 @@ int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
459 459
460int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags) 460int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags)
461{ 461{
462 unsigned bankw, bankh, mtaspect, tilesplit, stilesplit; 462 if (AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT) > 6)
463
464 bankw = (tiling_flags >> AMDGPU_TILING_EG_BANKW_SHIFT) & AMDGPU_TILING_EG_BANKW_MASK;
465 bankh = (tiling_flags >> AMDGPU_TILING_EG_BANKH_SHIFT) & AMDGPU_TILING_EG_BANKH_MASK;
466 mtaspect = (tiling_flags >> AMDGPU_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & AMDGPU_TILING_EG_MACRO_TILE_ASPECT_MASK;
467 tilesplit = (tiling_flags >> AMDGPU_TILING_EG_TILE_SPLIT_SHIFT) & AMDGPU_TILING_EG_TILE_SPLIT_MASK;
468 stilesplit = (tiling_flags >> AMDGPU_TILING_EG_STENCIL_TILE_SPLIT_SHIFT) & AMDGPU_TILING_EG_STENCIL_TILE_SPLIT_MASK;
469 switch (bankw) {
470 case 0:
471 case 1:
472 case 2:
473 case 4:
474 case 8:
475 break;
476 default:
477 return -EINVAL; 463 return -EINVAL;
478 }
479 switch (bankh) {
480 case 0:
481 case 1:
482 case 2:
483 case 4:
484 case 8:
485 break;
486 default:
487 return -EINVAL;
488 }
489 switch (mtaspect) {
490 case 0:
491 case 1:
492 case 2:
493 case 4:
494 case 8:
495 break;
496 default:
497 return -EINVAL;
498 }
499 if (tilesplit > 6) {
500 return -EINVAL;
501 }
502 if (stilesplit > 6) {
503 return -EINVAL;
504 }
505 464
506 bo->tiling_flags = tiling_flags; 465 bo->tiling_flags = tiling_flags;
507 return 0; 466 return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
index d412291ed70e..37b96236fe2c 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v10_0.c
@@ -2008,61 +2008,6 @@ static void dce_v10_0_grph_enable(struct drm_crtc *crtc, bool enable)
2008 WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 0); 2008 WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 0);
2009} 2009}
2010 2010
2011static void dce_v10_0_tiling_fields(uint64_t tiling_flags, unsigned *bankw,
2012 unsigned *bankh, unsigned *mtaspect,
2013 unsigned *tile_split)
2014{
2015 *bankw = (tiling_flags >> AMDGPU_TILING_EG_BANKW_SHIFT) & AMDGPU_TILING_EG_BANKW_MASK;
2016 *bankh = (tiling_flags >> AMDGPU_TILING_EG_BANKH_SHIFT) & AMDGPU_TILING_EG_BANKH_MASK;
2017 *mtaspect = (tiling_flags >> AMDGPU_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & AMDGPU_TILING_EG_MACRO_TILE_ASPECT_MASK;
2018 *tile_split = (tiling_flags >> AMDGPU_TILING_EG_TILE_SPLIT_SHIFT) & AMDGPU_TILING_EG_TILE_SPLIT_MASK;
2019 switch (*bankw) {
2020 default:
2021 case 1:
2022 *bankw = ADDR_SURF_BANK_WIDTH_1;
2023 break;
2024 case 2:
2025 *bankw = ADDR_SURF_BANK_WIDTH_2;
2026 break;
2027 case 4:
2028 *bankw = ADDR_SURF_BANK_WIDTH_4;
2029 break;
2030 case 8:
2031 *bankw = ADDR_SURF_BANK_WIDTH_8;
2032 break;
2033 }
2034 switch (*bankh) {
2035 default:
2036 case 1:
2037 *bankh = ADDR_SURF_BANK_HEIGHT_1;
2038 break;
2039 case 2:
2040 *bankh = ADDR_SURF_BANK_HEIGHT_2;
2041 break;
2042 case 4:
2043 *bankh = ADDR_SURF_BANK_HEIGHT_4;
2044 break;
2045 case 8:
2046 *bankh = ADDR_SURF_BANK_HEIGHT_8;
2047 break;
2048 }
2049 switch (*mtaspect) {
2050 default:
2051 case 1:
2052 *mtaspect = ADDR_SURF_MACRO_ASPECT_1;
2053 break;
2054 case 2:
2055 *mtaspect = ADDR_SURF_MACRO_ASPECT_2;
2056 break;
2057 case 4:
2058 *mtaspect = ADDR_SURF_MACRO_ASPECT_4;
2059 break;
2060 case 8:
2061 *mtaspect = ADDR_SURF_MACRO_ASPECT_8;
2062 break;
2063 }
2064}
2065
2066static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc, 2011static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,
2067 struct drm_framebuffer *fb, 2012 struct drm_framebuffer *fb,
2068 int x, int y, int atomic) 2013 int x, int y, int atomic)
@@ -2076,10 +2021,8 @@ static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,
2076 struct amdgpu_bo *rbo; 2021 struct amdgpu_bo *rbo;
2077 uint64_t fb_location, tiling_flags; 2022 uint64_t fb_location, tiling_flags;
2078 uint32_t fb_format, fb_pitch_pixels; 2023 uint32_t fb_format, fb_pitch_pixels;
2079 unsigned bankw, bankh, mtaspect, tile_split;
2080 u32 fb_swap = REG_SET_FIELD(0, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, ENDIAN_NONE); 2024 u32 fb_swap = REG_SET_FIELD(0, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, ENDIAN_NONE);
2081 /* XXX change to VI */ 2025 u32 pipe_config;
2082 u32 pipe_config = (adev->gfx.config.tile_mode_array[10] >> 6) & 0x1f;
2083 u32 tmp, viewport_w, viewport_h; 2026 u32 tmp, viewport_w, viewport_h;
2084 int r; 2027 int r;
2085 bool bypass_lut = false; 2028 bool bypass_lut = false;
@@ -2121,6 +2064,8 @@ static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,
2121 amdgpu_bo_get_tiling_flags(rbo, &tiling_flags); 2064 amdgpu_bo_get_tiling_flags(rbo, &tiling_flags);
2122 amdgpu_bo_unreserve(rbo); 2065 amdgpu_bo_unreserve(rbo);
2123 2066
2067 pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
2068
2124 switch (target_fb->pixel_format) { 2069 switch (target_fb->pixel_format) {
2125 case DRM_FORMAT_C8: 2070 case DRM_FORMAT_C8:
2126 fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 0); 2071 fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 0);
@@ -2198,27 +2143,15 @@ static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,
2198 return -EINVAL; 2143 return -EINVAL;
2199 } 2144 }
2200 2145
2201 if (tiling_flags & AMDGPU_TILING_MACRO) { 2146 if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) {
2202 unsigned tileb, index, num_banks, tile_split_bytes; 2147 unsigned bankw, bankh, mtaspect, tile_split, num_banks;
2203
2204 dce_v10_0_tiling_fields(tiling_flags, &bankw, &bankh, &mtaspect, &tile_split);
2205 /* Set NUM_BANKS. */
2206 /* Calculate the macrotile mode index. */
2207 tile_split_bytes = 64 << tile_split;
2208 tileb = 8 * 8 * target_fb->bits_per_pixel / 8;
2209 tileb = min(tile_split_bytes, tileb);
2210 2148
2211 for (index = 0; tileb > 64; index++) { 2149 bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
2212 tileb >>= 1; 2150 bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
2213 } 2151 mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
2214 2152 tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
2215 if (index >= 16) { 2153 num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
2216 DRM_ERROR("Wrong screen bpp (%u) or tile split (%u)\n",
2217 target_fb->bits_per_pixel, tile_split);
2218 return -EINVAL;
2219 }
2220 2154
2221 num_banks = (adev->gfx.config.macrotile_mode_array[index] >> 6) & 0x3;
2222 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_NUM_BANKS, num_banks); 2155 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_NUM_BANKS, num_banks);
2223 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_ARRAY_MODE, 2156 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_ARRAY_MODE,
2224 ARRAY_2D_TILED_THIN1); 2157 ARRAY_2D_TILED_THIN1);
@@ -2230,14 +2163,11 @@ static int dce_v10_0_crtc_do_set_base(struct drm_crtc *crtc,
2230 mtaspect); 2163 mtaspect);
2231 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_MICRO_TILE_MODE, 2164 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_MICRO_TILE_MODE,
2232 ADDR_SURF_MICRO_TILING_DISPLAY); 2165 ADDR_SURF_MICRO_TILING_DISPLAY);
2233 } else if (tiling_flags & AMDGPU_TILING_MICRO) { 2166 } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) {
2234 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_ARRAY_MODE, 2167 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_ARRAY_MODE,
2235 ARRAY_1D_TILED_THIN1); 2168 ARRAY_1D_TILED_THIN1);
2236 } 2169 }
2237 2170
2238 /* Read the pipe config from the 2D TILED SCANOUT mode.
2239 * It should be the same for the other modes too, but not all
2240 * modes set the pipe config field. */
2241 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_PIPE_CONFIG, 2171 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_PIPE_CONFIG,
2242 pipe_config); 2172 pipe_config);
2243 2173
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
index 55fef15a4fcf..04a5d4cd75b6 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v11_0.c
@@ -2006,61 +2006,6 @@ static void dce_v11_0_grph_enable(struct drm_crtc *crtc, bool enable)
2006 WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 0); 2006 WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 0);
2007} 2007}
2008 2008
2009static void dce_v11_0_tiling_fields(uint64_t tiling_flags, unsigned *bankw,
2010 unsigned *bankh, unsigned *mtaspect,
2011 unsigned *tile_split)
2012{
2013 *bankw = (tiling_flags >> AMDGPU_TILING_EG_BANKW_SHIFT) & AMDGPU_TILING_EG_BANKW_MASK;
2014 *bankh = (tiling_flags >> AMDGPU_TILING_EG_BANKH_SHIFT) & AMDGPU_TILING_EG_BANKH_MASK;
2015 *mtaspect = (tiling_flags >> AMDGPU_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & AMDGPU_TILING_EG_MACRO_TILE_ASPECT_MASK;
2016 *tile_split = (tiling_flags >> AMDGPU_TILING_EG_TILE_SPLIT_SHIFT) & AMDGPU_TILING_EG_TILE_SPLIT_MASK;
2017 switch (*bankw) {
2018 default:
2019 case 1:
2020 *bankw = ADDR_SURF_BANK_WIDTH_1;
2021 break;
2022 case 2:
2023 *bankw = ADDR_SURF_BANK_WIDTH_2;
2024 break;
2025 case 4:
2026 *bankw = ADDR_SURF_BANK_WIDTH_4;
2027 break;
2028 case 8:
2029 *bankw = ADDR_SURF_BANK_WIDTH_8;
2030 break;
2031 }
2032 switch (*bankh) {
2033 default:
2034 case 1:
2035 *bankh = ADDR_SURF_BANK_HEIGHT_1;
2036 break;
2037 case 2:
2038 *bankh = ADDR_SURF_BANK_HEIGHT_2;
2039 break;
2040 case 4:
2041 *bankh = ADDR_SURF_BANK_HEIGHT_4;
2042 break;
2043 case 8:
2044 *bankh = ADDR_SURF_BANK_HEIGHT_8;
2045 break;
2046 }
2047 switch (*mtaspect) {
2048 default:
2049 case 1:
2050 *mtaspect = ADDR_SURF_MACRO_ASPECT_1;
2051 break;
2052 case 2:
2053 *mtaspect = ADDR_SURF_MACRO_ASPECT_2;
2054 break;
2055 case 4:
2056 *mtaspect = ADDR_SURF_MACRO_ASPECT_4;
2057 break;
2058 case 8:
2059 *mtaspect = ADDR_SURF_MACRO_ASPECT_8;
2060 break;
2061 }
2062}
2063
2064static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc, 2009static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,
2065 struct drm_framebuffer *fb, 2010 struct drm_framebuffer *fb,
2066 int x, int y, int atomic) 2011 int x, int y, int atomic)
@@ -2074,10 +2019,8 @@ static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,
2074 struct amdgpu_bo *rbo; 2019 struct amdgpu_bo *rbo;
2075 uint64_t fb_location, tiling_flags; 2020 uint64_t fb_location, tiling_flags;
2076 uint32_t fb_format, fb_pitch_pixels; 2021 uint32_t fb_format, fb_pitch_pixels;
2077 unsigned bankw, bankh, mtaspect, tile_split;
2078 u32 fb_swap = REG_SET_FIELD(0, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, ENDIAN_NONE); 2022 u32 fb_swap = REG_SET_FIELD(0, GRPH_SWAP_CNTL, GRPH_ENDIAN_SWAP, ENDIAN_NONE);
2079 /* XXX change to VI */ 2023 u32 pipe_config;
2080 u32 pipe_config = (adev->gfx.config.tile_mode_array[10] >> 6) & 0x1f;
2081 u32 tmp, viewport_w, viewport_h; 2024 u32 tmp, viewport_w, viewport_h;
2082 int r; 2025 int r;
2083 bool bypass_lut = false; 2026 bool bypass_lut = false;
@@ -2119,6 +2062,8 @@ static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,
2119 amdgpu_bo_get_tiling_flags(rbo, &tiling_flags); 2062 amdgpu_bo_get_tiling_flags(rbo, &tiling_flags);
2120 amdgpu_bo_unreserve(rbo); 2063 amdgpu_bo_unreserve(rbo);
2121 2064
2065 pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
2066
2122 switch (target_fb->pixel_format) { 2067 switch (target_fb->pixel_format) {
2123 case DRM_FORMAT_C8: 2068 case DRM_FORMAT_C8:
2124 fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 0); 2069 fb_format = REG_SET_FIELD(0, GRPH_CONTROL, GRPH_DEPTH, 0);
@@ -2196,28 +2141,15 @@ static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,
2196 return -EINVAL; 2141 return -EINVAL;
2197 } 2142 }
2198 2143
2199 if (tiling_flags & AMDGPU_TILING_MACRO) { 2144 if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) {
2200 unsigned tileb, index, num_banks, tile_split_bytes; 2145 unsigned bankw, bankh, mtaspect, tile_split, num_banks;
2201
2202 dce_v11_0_tiling_fields(tiling_flags, &bankw, &bankh, &mtaspect, &tile_split);
2203 /* Set NUM_BANKS. */
2204 /* Calculate the macrotile mode index. */
2205 tile_split_bytes = 64 << tile_split;
2206 tileb = 8 * 8 * target_fb->bits_per_pixel / 8;
2207 tileb = min(tile_split_bytes, tileb);
2208 2146
2209 for (index = 0; tileb > 64; index++) { 2147 bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
2210 tileb >>= 1; 2148 bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
2211 } 2149 mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
2212 2150 tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
2213 if (index >= 16) { 2151 num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
2214 DRM_ERROR("Wrong screen bpp (%u) or tile split (%u)\n",
2215 target_fb->bits_per_pixel, tile_split);
2216 return -EINVAL;
2217 }
2218 2152
2219 /* XXX fix me for VI */
2220 num_banks = (adev->gfx.config.macrotile_mode_array[index] >> 6) & 0x3;
2221 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_NUM_BANKS, num_banks); 2153 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_NUM_BANKS, num_banks);
2222 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_ARRAY_MODE, 2154 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_ARRAY_MODE,
2223 ARRAY_2D_TILED_THIN1); 2155 ARRAY_2D_TILED_THIN1);
@@ -2229,14 +2161,11 @@ static int dce_v11_0_crtc_do_set_base(struct drm_crtc *crtc,
2229 mtaspect); 2161 mtaspect);
2230 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_MICRO_TILE_MODE, 2162 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_MICRO_TILE_MODE,
2231 ADDR_SURF_MICRO_TILING_DISPLAY); 2163 ADDR_SURF_MICRO_TILING_DISPLAY);
2232 } else if (tiling_flags & AMDGPU_TILING_MICRO) { 2164 } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) {
2233 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_ARRAY_MODE, 2165 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_ARRAY_MODE,
2234 ARRAY_1D_TILED_THIN1); 2166 ARRAY_1D_TILED_THIN1);
2235 } 2167 }
2236 2168
2237 /* Read the pipe config from the 2D TILED SCANOUT mode.
2238 * It should be the same for the other modes too, but not all
2239 * modes set the pipe config field. */
2240 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_PIPE_CONFIG, 2169 fb_format = REG_SET_FIELD(fb_format, GRPH_CONTROL, GRPH_PIPE_CONFIG,
2241 pipe_config); 2170 pipe_config);
2242 2171
diff --git a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
index c1bc6935c88e..9f2ff8d374f3 100644
--- a/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/dce_v8_0.c
@@ -1976,61 +1976,6 @@ static void dce_v8_0_grph_enable(struct drm_crtc *crtc, bool enable)
1976 WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 0); 1976 WREG32(mmGRPH_ENABLE + amdgpu_crtc->crtc_offset, 0);
1977} 1977}
1978 1978
1979static void dce_v8_0_tiling_fields(uint64_t tiling_flags, unsigned *bankw,
1980 unsigned *bankh, unsigned *mtaspect,
1981 unsigned *tile_split)
1982{
1983 *bankw = (tiling_flags >> AMDGPU_TILING_EG_BANKW_SHIFT) & AMDGPU_TILING_EG_BANKW_MASK;
1984 *bankh = (tiling_flags >> AMDGPU_TILING_EG_BANKH_SHIFT) & AMDGPU_TILING_EG_BANKH_MASK;
1985 *mtaspect = (tiling_flags >> AMDGPU_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & AMDGPU_TILING_EG_MACRO_TILE_ASPECT_MASK;
1986 *tile_split = (tiling_flags >> AMDGPU_TILING_EG_TILE_SPLIT_SHIFT) & AMDGPU_TILING_EG_TILE_SPLIT_MASK;
1987 switch (*bankw) {
1988 default:
1989 case 1:
1990 *bankw = ADDR_SURF_BANK_WIDTH_1;
1991 break;
1992 case 2:
1993 *bankw = ADDR_SURF_BANK_WIDTH_2;
1994 break;
1995 case 4:
1996 *bankw = ADDR_SURF_BANK_WIDTH_4;
1997 break;
1998 case 8:
1999 *bankw = ADDR_SURF_BANK_WIDTH_8;
2000 break;
2001 }
2002 switch (*bankh) {
2003 default:
2004 case 1:
2005 *bankh = ADDR_SURF_BANK_HEIGHT_1;
2006 break;
2007 case 2:
2008 *bankh = ADDR_SURF_BANK_HEIGHT_2;
2009 break;
2010 case 4:
2011 *bankh = ADDR_SURF_BANK_HEIGHT_4;
2012 break;
2013 case 8:
2014 *bankh = ADDR_SURF_BANK_HEIGHT_8;
2015 break;
2016 }
2017 switch (*mtaspect) {
2018 default:
2019 case 1:
2020 *mtaspect = ADDR_SURF_MACRO_TILE_ASPECT_1;
2021 break;
2022 case 2:
2023 *mtaspect = ADDR_SURF_MACRO_TILE_ASPECT_2;
2024 break;
2025 case 4:
2026 *mtaspect = ADDR_SURF_MACRO_TILE_ASPECT_4;
2027 break;
2028 case 8:
2029 *mtaspect = ADDR_SURF_MACRO_TILE_ASPECT_8;
2030 break;
2031 }
2032}
2033
2034static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc, 1979static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
2035 struct drm_framebuffer *fb, 1980 struct drm_framebuffer *fb,
2036 int x, int y, int atomic) 1981 int x, int y, int atomic)
@@ -2044,9 +1989,8 @@ static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
2044 struct amdgpu_bo *rbo; 1989 struct amdgpu_bo *rbo;
2045 uint64_t fb_location, tiling_flags; 1990 uint64_t fb_location, tiling_flags;
2046 uint32_t fb_format, fb_pitch_pixels; 1991 uint32_t fb_format, fb_pitch_pixels;
2047 unsigned bankw, bankh, mtaspect, tile_split;
2048 u32 fb_swap = (GRPH_ENDIAN_NONE << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT); 1992 u32 fb_swap = (GRPH_ENDIAN_NONE << GRPH_SWAP_CNTL__GRPH_ENDIAN_SWAP__SHIFT);
2049 u32 pipe_config = (adev->gfx.config.tile_mode_array[10] >> 6) & 0x1f; 1993 u32 pipe_config;
2050 u32 tmp, viewport_w, viewport_h; 1994 u32 tmp, viewport_w, viewport_h;
2051 int r; 1995 int r;
2052 bool bypass_lut = false; 1996 bool bypass_lut = false;
@@ -2088,6 +2032,8 @@ static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
2088 amdgpu_bo_get_tiling_flags(rbo, &tiling_flags); 2032 amdgpu_bo_get_tiling_flags(rbo, &tiling_flags);
2089 amdgpu_bo_unreserve(rbo); 2033 amdgpu_bo_unreserve(rbo);
2090 2034
2035 pipe_config = AMDGPU_TILING_GET(tiling_flags, PIPE_CONFIG);
2036
2091 switch (target_fb->pixel_format) { 2037 switch (target_fb->pixel_format) {
2092 case DRM_FORMAT_C8: 2038 case DRM_FORMAT_C8:
2093 fb_format = ((GRPH_DEPTH_8BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) | 2039 fb_format = ((GRPH_DEPTH_8BPP << GRPH_CONTROL__GRPH_DEPTH__SHIFT) |
@@ -2158,27 +2104,15 @@ static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
2158 return -EINVAL; 2104 return -EINVAL;
2159 } 2105 }
2160 2106
2161 if (tiling_flags & AMDGPU_TILING_MACRO) { 2107 if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_2D_TILED_THIN1) {
2162 unsigned tileb, index, num_banks, tile_split_bytes; 2108 unsigned bankw, bankh, mtaspect, tile_split, num_banks;
2163
2164 dce_v8_0_tiling_fields(tiling_flags, &bankw, &bankh, &mtaspect, &tile_split);
2165 /* Set NUM_BANKS. */
2166 /* Calculate the macrotile mode index. */
2167 tile_split_bytes = 64 << tile_split;
2168 tileb = 8 * 8 * target_fb->bits_per_pixel / 8;
2169 tileb = min(tile_split_bytes, tileb);
2170 2109
2171 for (index = 0; tileb > 64; index++) { 2110 bankw = AMDGPU_TILING_GET(tiling_flags, BANK_WIDTH);
2172 tileb >>= 1; 2111 bankh = AMDGPU_TILING_GET(tiling_flags, BANK_HEIGHT);
2173 } 2112 mtaspect = AMDGPU_TILING_GET(tiling_flags, MACRO_TILE_ASPECT);
2174 2113 tile_split = AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT);
2175 if (index >= 16) { 2114 num_banks = AMDGPU_TILING_GET(tiling_flags, NUM_BANKS);
2176 DRM_ERROR("Wrong screen bpp (%u) or tile split (%u)\n",
2177 target_fb->bits_per_pixel, tile_split);
2178 return -EINVAL;
2179 }
2180 2115
2181 num_banks = (adev->gfx.config.macrotile_mode_array[index] >> 6) & 0x3;
2182 fb_format |= (num_banks << GRPH_CONTROL__GRPH_NUM_BANKS__SHIFT); 2116 fb_format |= (num_banks << GRPH_CONTROL__GRPH_NUM_BANKS__SHIFT);
2183 fb_format |= (GRPH_ARRAY_2D_TILED_THIN1 << GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT); 2117 fb_format |= (GRPH_ARRAY_2D_TILED_THIN1 << GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT);
2184 fb_format |= (tile_split << GRPH_CONTROL__GRPH_TILE_SPLIT__SHIFT); 2118 fb_format |= (tile_split << GRPH_CONTROL__GRPH_TILE_SPLIT__SHIFT);
@@ -2186,13 +2120,10 @@ static int dce_v8_0_crtc_do_set_base(struct drm_crtc *crtc,
2186 fb_format |= (bankh << GRPH_CONTROL__GRPH_BANK_HEIGHT__SHIFT); 2120 fb_format |= (bankh << GRPH_CONTROL__GRPH_BANK_HEIGHT__SHIFT);
2187 fb_format |= (mtaspect << GRPH_CONTROL__GRPH_MACRO_TILE_ASPECT__SHIFT); 2121 fb_format |= (mtaspect << GRPH_CONTROL__GRPH_MACRO_TILE_ASPECT__SHIFT);
2188 fb_format |= (DISPLAY_MICRO_TILING << GRPH_CONTROL__GRPH_MICRO_TILE_MODE__SHIFT); 2122 fb_format |= (DISPLAY_MICRO_TILING << GRPH_CONTROL__GRPH_MICRO_TILE_MODE__SHIFT);
2189 } else if (tiling_flags & AMDGPU_TILING_MICRO) { 2123 } else if (AMDGPU_TILING_GET(tiling_flags, ARRAY_MODE) == ARRAY_1D_TILED_THIN1) {
2190 fb_format |= (GRPH_ARRAY_1D_TILED_THIN1 << GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT); 2124 fb_format |= (GRPH_ARRAY_1D_TILED_THIN1 << GRPH_CONTROL__GRPH_ARRAY_MODE__SHIFT);
2191 } 2125 }
2192 2126
2193 /* Read the pipe config from the 2D TILED SCANOUT mode.
2194 * It should be the same for the other modes too, but not all
2195 * modes set the pipe config field. */
2196 fb_format |= (pipe_config << GRPH_CONTROL__GRPH_PIPE_CONFIG__SHIFT); 2127 fb_format |= (pipe_config << GRPH_CONTROL__GRPH_PIPE_CONFIG__SHIFT);
2197 2128
2198 dce_v8_0_vga_enable(crtc, false); 2129 dce_v8_0_vga_enable(crtc, false);
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 46580e950036..d9b9b6f8de2b 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -199,24 +199,28 @@ struct drm_amdgpu_gem_userptr {
199 uint32_t handle; 199 uint32_t handle;
200}; 200};
201 201
202#define AMDGPU_TILING_MACRO 0x1 202/* same meaning as the GB_TILE_MODE and GL_MACRO_TILE_MODE fields */
203#define AMDGPU_TILING_MICRO 0x2 203#define AMDGPU_TILING_ARRAY_MODE_SHIFT 0
204#define AMDGPU_TILING_SWAP_16BIT 0x4 204#define AMDGPU_TILING_ARRAY_MODE_MASK 0xf
205#define AMDGPU_TILING_R600_NO_SCANOUT AMDGPU_TILING_SWAP_16BIT 205#define AMDGPU_TILING_PIPE_CONFIG_SHIFT 4
206#define AMDGPU_TILING_SWAP_32BIT 0x8 206#define AMDGPU_TILING_PIPE_CONFIG_MASK 0x1f
207/* this object requires a surface when mapped - i.e. front buffer */ 207#define AMDGPU_TILING_TILE_SPLIT_SHIFT 9
208#define AMDGPU_TILING_SURFACE 0x10 208#define AMDGPU_TILING_TILE_SPLIT_MASK 0x7
209#define AMDGPU_TILING_MICRO_SQUARE 0x20 209#define AMDGPU_TILING_MICRO_TILE_MODE_SHIFT 12
210#define AMDGPU_TILING_EG_BANKW_SHIFT 8 210#define AMDGPU_TILING_MICRO_TILE_MODE_MASK 0x7
211#define AMDGPU_TILING_EG_BANKW_MASK 0xf 211#define AMDGPU_TILING_BANK_WIDTH_SHIFT 15
212#define AMDGPU_TILING_EG_BANKH_SHIFT 12 212#define AMDGPU_TILING_BANK_WIDTH_MASK 0x3
213#define AMDGPU_TILING_EG_BANKH_MASK 0xf 213#define AMDGPU_TILING_BANK_HEIGHT_SHIFT 17
214#define AMDGPU_TILING_EG_MACRO_TILE_ASPECT_SHIFT 16 214#define AMDGPU_TILING_BANK_HEIGHT_MASK 0x3
215#define AMDGPU_TILING_EG_MACRO_TILE_ASPECT_MASK 0xf 215#define AMDGPU_TILING_MACRO_TILE_ASPECT_SHIFT 19
216#define AMDGPU_TILING_EG_TILE_SPLIT_SHIFT 24 216#define AMDGPU_TILING_MACRO_TILE_ASPECT_MASK 0x3
217#define AMDGPU_TILING_EG_TILE_SPLIT_MASK 0xf 217#define AMDGPU_TILING_NUM_BANKS_SHIFT 21
218#define AMDGPU_TILING_EG_STENCIL_TILE_SPLIT_SHIFT 28 218#define AMDGPU_TILING_NUM_BANKS_MASK 0x3
219#define AMDGPU_TILING_EG_STENCIL_TILE_SPLIT_MASK 0xf 219
220#define AMDGPU_TILING_SET(field, value) \
221 (((value) & AMDGPU_TILING_##field##_MASK) << AMDGPU_TILING_##field##_SHIFT)
222#define AMDGPU_TILING_GET(value, field) \
223 (((value) >> AMDGPU_TILING_##field##_SHIFT) & AMDGPU_TILING_##field##_MASK)
220 224
221#define AMDGPU_GEM_METADATA_OP_SET_METADATA 1 225#define AMDGPU_GEM_METADATA_OP_SET_METADATA 1
222#define AMDGPU_GEM_METADATA_OP_GET_METADATA 2 226#define AMDGPU_GEM_METADATA_OP_GET_METADATA 2