18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2010 Advanced Micro Devices, Inc.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next
128c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
138c2ecf20Sopenharmony_ci * Software.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
188c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
198c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
208c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
218c2ecf20Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * Authors:
248c2ecf20Sopenharmony_ci *     Alex Deucher <alexander.deucher@amd.com>
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#include <linux/bug.h>
288c2ecf20Sopenharmony_ci#include <linux/types.h>
298c2ecf20Sopenharmony_ci#include <linux/kernel.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/*
328c2ecf20Sopenharmony_ci * evergreen cards need to use the 3D engine to blit data which requires
338c2ecf20Sopenharmony_ci * quite a bit of hw state setup.  Rather than pull the whole 3D driver
348c2ecf20Sopenharmony_ci * (which normally generates the 3D state) into the DRM, we opt to use
358c2ecf20Sopenharmony_ci * statically generated state tables.  The register state and shaders
368c2ecf20Sopenharmony_ci * were hand generated to support blitting functionality.  See the 3D
378c2ecf20Sopenharmony_ci * driver or documentation for descriptions of the registers and
388c2ecf20Sopenharmony_ci * shader instructions.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciconst u32 evergreen_default_state[] =
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	0xc0016900,
448c2ecf20Sopenharmony_ci	0x0000023b,
458c2ecf20Sopenharmony_ci	0x00000000, /* SQ_LDS_ALLOC_PS */
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	0xc0066900,
488c2ecf20Sopenharmony_ci	0x00000240,
498c2ecf20Sopenharmony_ci	0x00000000, /* SQ_ESGS_RING_ITEMSIZE */
508c2ecf20Sopenharmony_ci	0x00000000,
518c2ecf20Sopenharmony_ci	0x00000000,
528c2ecf20Sopenharmony_ci	0x00000000,
538c2ecf20Sopenharmony_ci	0x00000000,
548c2ecf20Sopenharmony_ci	0x00000000,
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	0xc0046900,
578c2ecf20Sopenharmony_ci	0x00000247,
588c2ecf20Sopenharmony_ci	0x00000000, /* SQ_GS_VERT_ITEMSIZE */
598c2ecf20Sopenharmony_ci	0x00000000,
608c2ecf20Sopenharmony_ci	0x00000000,
618c2ecf20Sopenharmony_ci	0x00000000,
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	0xc0026900,
648c2ecf20Sopenharmony_ci	0x00000010,
658c2ecf20Sopenharmony_ci	0x00000000, /* DB_Z_INFO */
668c2ecf20Sopenharmony_ci	0x00000000, /* DB_STENCIL_INFO */
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	0xc0016900,
698c2ecf20Sopenharmony_ci	0x00000200,
708c2ecf20Sopenharmony_ci	0x00000000, /* DB_DEPTH_CONTROL */
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	0xc0066900,
738c2ecf20Sopenharmony_ci	0x00000000,
748c2ecf20Sopenharmony_ci	0x00000060, /* DB_RENDER_CONTROL */
758c2ecf20Sopenharmony_ci	0x00000000, /* DB_COUNT_CONTROL */
768c2ecf20Sopenharmony_ci	0x00000000, /* DB_DEPTH_VIEW */
778c2ecf20Sopenharmony_ci	0x0000002a, /* DB_RENDER_OVERRIDE */
788c2ecf20Sopenharmony_ci	0x00000000, /* DB_RENDER_OVERRIDE2 */
798c2ecf20Sopenharmony_ci	0x00000000, /* DB_HTILE_DATA_BASE */
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	0xc0026900,
828c2ecf20Sopenharmony_ci	0x0000000a,
838c2ecf20Sopenharmony_ci	0x00000000, /* DB_STENCIL_CLEAR */
848c2ecf20Sopenharmony_ci	0x00000000, /* DB_DEPTH_CLEAR */
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	0xc0016900,
878c2ecf20Sopenharmony_ci	0x000002dc,
888c2ecf20Sopenharmony_ci	0x0000aa00, /* DB_ALPHA_TO_MASK */
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	0xc0016900,
918c2ecf20Sopenharmony_ci	0x00000080,
928c2ecf20Sopenharmony_ci	0x00000000, /* PA_SC_WINDOW_OFFSET */
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	0xc00d6900,
958c2ecf20Sopenharmony_ci	0x00000083,
968c2ecf20Sopenharmony_ci	0x0000ffff, /* PA_SC_CLIPRECT_RULE */
978c2ecf20Sopenharmony_ci	0x00000000, /* PA_SC_CLIPRECT_0_TL */
988c2ecf20Sopenharmony_ci	0x20002000, /* PA_SC_CLIPRECT_0_BR */
998c2ecf20Sopenharmony_ci	0x00000000,
1008c2ecf20Sopenharmony_ci	0x20002000,
1018c2ecf20Sopenharmony_ci	0x00000000,
1028c2ecf20Sopenharmony_ci	0x20002000,
1038c2ecf20Sopenharmony_ci	0x00000000,
1048c2ecf20Sopenharmony_ci	0x20002000,
1058c2ecf20Sopenharmony_ci	0xaaaaaaaa, /* PA_SC_EDGERULE */
1068c2ecf20Sopenharmony_ci	0x00000000, /* PA_SU_HARDWARE_SCREEN_OFFSET */
1078c2ecf20Sopenharmony_ci	0x0000000f, /* CB_TARGET_MASK */
1088c2ecf20Sopenharmony_ci	0x0000000f, /* CB_SHADER_MASK */
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	0xc0226900,
1118c2ecf20Sopenharmony_ci	0x00000094,
1128c2ecf20Sopenharmony_ci	0x80000000, /* PA_SC_VPORT_SCISSOR_0_TL */
1138c2ecf20Sopenharmony_ci	0x20002000, /* PA_SC_VPORT_SCISSOR_0_BR */
1148c2ecf20Sopenharmony_ci	0x80000000,
1158c2ecf20Sopenharmony_ci	0x20002000,
1168c2ecf20Sopenharmony_ci	0x80000000,
1178c2ecf20Sopenharmony_ci	0x20002000,
1188c2ecf20Sopenharmony_ci	0x80000000,
1198c2ecf20Sopenharmony_ci	0x20002000,
1208c2ecf20Sopenharmony_ci	0x80000000,
1218c2ecf20Sopenharmony_ci	0x20002000,
1228c2ecf20Sopenharmony_ci	0x80000000,
1238c2ecf20Sopenharmony_ci	0x20002000,
1248c2ecf20Sopenharmony_ci	0x80000000,
1258c2ecf20Sopenharmony_ci	0x20002000,
1268c2ecf20Sopenharmony_ci	0x80000000,
1278c2ecf20Sopenharmony_ci	0x20002000,
1288c2ecf20Sopenharmony_ci	0x80000000,
1298c2ecf20Sopenharmony_ci	0x20002000,
1308c2ecf20Sopenharmony_ci	0x80000000,
1318c2ecf20Sopenharmony_ci	0x20002000,
1328c2ecf20Sopenharmony_ci	0x80000000,
1338c2ecf20Sopenharmony_ci	0x20002000,
1348c2ecf20Sopenharmony_ci	0x80000000,
1358c2ecf20Sopenharmony_ci	0x20002000,
1368c2ecf20Sopenharmony_ci	0x80000000,
1378c2ecf20Sopenharmony_ci	0x20002000,
1388c2ecf20Sopenharmony_ci	0x80000000,
1398c2ecf20Sopenharmony_ci	0x20002000,
1408c2ecf20Sopenharmony_ci	0x80000000,
1418c2ecf20Sopenharmony_ci	0x20002000,
1428c2ecf20Sopenharmony_ci	0x80000000,
1438c2ecf20Sopenharmony_ci	0x20002000,
1448c2ecf20Sopenharmony_ci	0x00000000, /* PA_SC_VPORT_ZMIN_0 */
1458c2ecf20Sopenharmony_ci	0x3f800000, /* PA_SC_VPORT_ZMAX_0 */
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	0xc0016900,
1488c2ecf20Sopenharmony_ci	0x000000d4,
1498c2ecf20Sopenharmony_ci	0x00000000, /* SX_MISC */
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci	0xc0026900,
1528c2ecf20Sopenharmony_ci	0x00000292,
1538c2ecf20Sopenharmony_ci	0x00000000, /* PA_SC_MODE_CNTL_0 */
1548c2ecf20Sopenharmony_ci	0x00000000, /* PA_SC_MODE_CNTL_1 */
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	0xc0106900,
1578c2ecf20Sopenharmony_ci	0x00000300,
1588c2ecf20Sopenharmony_ci	0x00000000, /* PA_SC_LINE_CNTL */
1598c2ecf20Sopenharmony_ci	0x00000000, /* PA_SC_AA_CONFIG */
1608c2ecf20Sopenharmony_ci	0x00000005, /* PA_SU_VTX_CNTL */
1618c2ecf20Sopenharmony_ci	0x3f800000, /* PA_CL_GB_VERT_CLIP_ADJ */
1628c2ecf20Sopenharmony_ci	0x3f800000, /* PA_CL_GB_VERT_DISC_ADJ */
1638c2ecf20Sopenharmony_ci	0x3f800000, /* PA_CL_GB_HORZ_CLIP_ADJ */
1648c2ecf20Sopenharmony_ci	0x3f800000, /* PA_CL_GB_HORZ_DISC_ADJ */
1658c2ecf20Sopenharmony_ci	0x00000000, /* PA_SC_AA_SAMPLE_LOCS_0 */
1668c2ecf20Sopenharmony_ci	0x00000000, /*  */
1678c2ecf20Sopenharmony_ci	0x00000000, /*  */
1688c2ecf20Sopenharmony_ci	0x00000000, /*  */
1698c2ecf20Sopenharmony_ci	0x00000000, /*  */
1708c2ecf20Sopenharmony_ci	0x00000000, /*  */
1718c2ecf20Sopenharmony_ci	0x00000000, /*  */
1728c2ecf20Sopenharmony_ci	0x00000000, /* PA_SC_AA_SAMPLE_LOCS_7 */
1738c2ecf20Sopenharmony_ci	0xffffffff, /* PA_SC_AA_MASK */
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	0xc00d6900,
1768c2ecf20Sopenharmony_ci	0x00000202,
1778c2ecf20Sopenharmony_ci	0x00cc0010, /* CB_COLOR_CONTROL */
1788c2ecf20Sopenharmony_ci	0x00000210, /* DB_SHADER_CONTROL */
1798c2ecf20Sopenharmony_ci	0x00010000, /* PA_CL_CLIP_CNTL */
1808c2ecf20Sopenharmony_ci	0x00000004, /* PA_SU_SC_MODE_CNTL */
1818c2ecf20Sopenharmony_ci	0x00000100, /* PA_CL_VTE_CNTL */
1828c2ecf20Sopenharmony_ci	0x00000000, /* PA_CL_VS_OUT_CNTL */
1838c2ecf20Sopenharmony_ci	0x00000000, /* PA_CL_NANINF_CNTL */
1848c2ecf20Sopenharmony_ci	0x00000000, /* PA_SU_LINE_STIPPLE_CNTL */
1858c2ecf20Sopenharmony_ci	0x00000000, /* PA_SU_LINE_STIPPLE_SCALE */
1868c2ecf20Sopenharmony_ci	0x00000000, /* PA_SU_PRIM_FILTER_CNTL */
1878c2ecf20Sopenharmony_ci	0x00000000, /*  */
1888c2ecf20Sopenharmony_ci	0x00000000, /*  */
1898c2ecf20Sopenharmony_ci	0x00000000, /* SQ_DYN_GPR_RESOURCE_LIMIT_1 */
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	0xc0066900,
1928c2ecf20Sopenharmony_ci	0x000002de,
1938c2ecf20Sopenharmony_ci	0x00000000, /* PA_SU_POLY_OFFSET_DB_FMT_CNTL */
1948c2ecf20Sopenharmony_ci	0x00000000, /*  */
1958c2ecf20Sopenharmony_ci	0x00000000, /*  */
1968c2ecf20Sopenharmony_ci	0x00000000, /*  */
1978c2ecf20Sopenharmony_ci	0x00000000, /*  */
1988c2ecf20Sopenharmony_ci	0x00000000, /*  */
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	0xc0016900,
2018c2ecf20Sopenharmony_ci	0x00000229,
2028c2ecf20Sopenharmony_ci	0x00000000, /* SQ_PGM_START_FS */
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	0xc0016900,
2058c2ecf20Sopenharmony_ci	0x0000022a,
2068c2ecf20Sopenharmony_ci	0x00000000, /* SQ_PGM_RESOURCES_FS */
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	0xc0096900,
2098c2ecf20Sopenharmony_ci	0x00000100,
2108c2ecf20Sopenharmony_ci	0x00ffffff, /* VGT_MAX_VTX_INDX */
2118c2ecf20Sopenharmony_ci	0x00000000, /*  */
2128c2ecf20Sopenharmony_ci	0x00000000, /*  */
2138c2ecf20Sopenharmony_ci	0x00000000, /*  */
2148c2ecf20Sopenharmony_ci	0x00000000, /* SX_ALPHA_TEST_CONTROL */
2158c2ecf20Sopenharmony_ci	0x00000000, /* CB_BLEND_RED */
2168c2ecf20Sopenharmony_ci	0x00000000, /* CB_BLEND_GREEN */
2178c2ecf20Sopenharmony_ci	0x00000000, /* CB_BLEND_BLUE */
2188c2ecf20Sopenharmony_ci	0x00000000, /* CB_BLEND_ALPHA */
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	0xc0026900,
2218c2ecf20Sopenharmony_ci	0x000002a8,
2228c2ecf20Sopenharmony_ci	0x00000000, /* VGT_INSTANCE_STEP_RATE_0 */
2238c2ecf20Sopenharmony_ci	0x00000000, /*  */
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	0xc0026900,
2268c2ecf20Sopenharmony_ci	0x000002ad,
2278c2ecf20Sopenharmony_ci	0x00000000, /* VGT_REUSE_OFF */
2288c2ecf20Sopenharmony_ci	0x00000000, /*  */
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	0xc0116900,
2318c2ecf20Sopenharmony_ci	0x00000280,
2328c2ecf20Sopenharmony_ci	0x00000000, /* PA_SU_POINT_SIZE */
2338c2ecf20Sopenharmony_ci	0x00000000, /* PA_SU_POINT_MINMAX */
2348c2ecf20Sopenharmony_ci	0x00000008, /* PA_SU_LINE_CNTL */
2358c2ecf20Sopenharmony_ci	0x00000000, /* PA_SC_LINE_STIPPLE */
2368c2ecf20Sopenharmony_ci	0x00000000, /* VGT_OUTPUT_PATH_CNTL */
2378c2ecf20Sopenharmony_ci	0x00000000, /* VGT_HOS_CNTL */
2388c2ecf20Sopenharmony_ci	0x00000000, /*  */
2398c2ecf20Sopenharmony_ci	0x00000000, /*  */
2408c2ecf20Sopenharmony_ci	0x00000000, /*  */
2418c2ecf20Sopenharmony_ci	0x00000000, /*  */
2428c2ecf20Sopenharmony_ci	0x00000000, /*  */
2438c2ecf20Sopenharmony_ci	0x00000000, /*  */
2448c2ecf20Sopenharmony_ci	0x00000000, /*  */
2458c2ecf20Sopenharmony_ci	0x00000000, /*  */
2468c2ecf20Sopenharmony_ci	0x00000000, /*  */
2478c2ecf20Sopenharmony_ci	0x00000000, /*  */
2488c2ecf20Sopenharmony_ci	0x00000000, /* VGT_GS_MODE */
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	0xc0016900,
2518c2ecf20Sopenharmony_ci	0x000002a1,
2528c2ecf20Sopenharmony_ci	0x00000000, /* VGT_PRIMITIVEID_EN */
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	0xc0016900,
2558c2ecf20Sopenharmony_ci	0x000002a5,
2568c2ecf20Sopenharmony_ci	0x00000000, /* VGT_MULTI_PRIM_IB_RESET_EN */
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	0xc0016900,
2598c2ecf20Sopenharmony_ci	0x000002d5,
2608c2ecf20Sopenharmony_ci	0x00000000, /* VGT_SHADER_STAGES_EN */
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci	0xc0026900,
2638c2ecf20Sopenharmony_ci	0x000002e5,
2648c2ecf20Sopenharmony_ci	0x00000000, /* VGT_STRMOUT_CONFIG */
2658c2ecf20Sopenharmony_ci	0x00000000, /*  */
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci	0xc0016900,
2688c2ecf20Sopenharmony_ci	0x000001e0,
2698c2ecf20Sopenharmony_ci	0x00000000, /* CB_BLEND0_CONTROL */
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	0xc0016900,
2728c2ecf20Sopenharmony_ci	0x000001b1,
2738c2ecf20Sopenharmony_ci	0x00000000, /* SPI_VS_OUT_CONFIG */
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	0xc0016900,
2768c2ecf20Sopenharmony_ci	0x00000187,
2778c2ecf20Sopenharmony_ci	0x00000000, /* SPI_VS_OUT_ID_0 */
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	0xc0016900,
2808c2ecf20Sopenharmony_ci	0x00000191,
2818c2ecf20Sopenharmony_ci	0x00000100, /* SPI_PS_INPUT_CNTL_0 */
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	0xc00b6900,
2848c2ecf20Sopenharmony_ci	0x000001b3,
2858c2ecf20Sopenharmony_ci	0x20000001, /* SPI_PS_IN_CONTROL_0 */
2868c2ecf20Sopenharmony_ci	0x00000000, /* SPI_PS_IN_CONTROL_1 */
2878c2ecf20Sopenharmony_ci	0x00000000, /* SPI_INTERP_CONTROL_0 */
2888c2ecf20Sopenharmony_ci	0x00000000, /* SPI_INPUT_Z */
2898c2ecf20Sopenharmony_ci	0x00000000, /* SPI_FOG_CNTL */
2908c2ecf20Sopenharmony_ci	0x00100000, /* SPI_BARYC_CNTL */
2918c2ecf20Sopenharmony_ci	0x00000000, /* SPI_PS_IN_CONTROL_2 */
2928c2ecf20Sopenharmony_ci	0x00000000, /*  */
2938c2ecf20Sopenharmony_ci	0x00000000, /*  */
2948c2ecf20Sopenharmony_ci	0x00000000, /*  */
2958c2ecf20Sopenharmony_ci	0x00000000, /*  */
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	0xc0026900,
2988c2ecf20Sopenharmony_ci	0x00000316,
2998c2ecf20Sopenharmony_ci	0x0000000e, /* VGT_VERTEX_REUSE_BLOCK_CNTL */
3008c2ecf20Sopenharmony_ci	0x00000010, /*  */
3018c2ecf20Sopenharmony_ci};
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ciconst u32 evergreen_default_size = ARRAY_SIZE(evergreen_default_state);
304