Home | History | Annotate | Line # | Download | only in radeon
      1  1.8       mrg /*	$NetBSD: radeon_cik.c,v 1.8 2023/09/30 10:46:45 mrg Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright 2012 Advanced Micro Devices, Inc.
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice shall be included in
     14  1.1  riastrad  * all copies or substantial portions of the Software.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     19  1.1  riastrad  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     20  1.1  riastrad  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     21  1.1  riastrad  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     22  1.1  riastrad  * OTHER DEALINGS IN THE SOFTWARE.
     23  1.1  riastrad  *
     24  1.1  riastrad  * Authors: Alex Deucher
     25  1.1  riastrad  */
     26  1.3  riastrad 
     27  1.1  riastrad #include <sys/cdefs.h>
     28  1.8       mrg __KERNEL_RCSID(0, "$NetBSD: radeon_cik.c,v 1.8 2023/09/30 10:46:45 mrg Exp $");
     29  1.1  riastrad 
     30  1.1  riastrad #include <linux/firmware.h>
     31  1.3  riastrad #include <linux/module.h>
     32  1.3  riastrad #include <linux/pci.h>
     33  1.1  riastrad #include <linux/slab.h>
     34  1.3  riastrad 
     35  1.3  riastrad #include <drm/drm_vblank.h>
     36  1.3  riastrad 
     37  1.3  riastrad #include "atom.h"
     38  1.3  riastrad #include "cik_blit_shaders.h"
     39  1.3  riastrad #include "cikd.h"
     40  1.3  riastrad #include "clearstate_ci.h"
     41  1.1  riastrad #include "radeon.h"
     42  1.1  riastrad #include "radeon_asic.h"
     43  1.1  riastrad #include "radeon_audio.h"
     44  1.1  riastrad #include "radeon_ucode.h"
     45  1.3  riastrad 
     46  1.3  riastrad #define SH_MEM_CONFIG_GFX_DEFAULT \
     47  1.3  riastrad 	ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED)
     48  1.1  riastrad 
     49  1.2  riastrad #include <linux/nbsd-namespace.h>
     50  1.2  riastrad 
     51  1.1  riastrad MODULE_FIRMWARE("radeon/BONAIRE_pfp.bin");
     52  1.1  riastrad MODULE_FIRMWARE("radeon/BONAIRE_me.bin");
     53  1.1  riastrad MODULE_FIRMWARE("radeon/BONAIRE_ce.bin");
     54  1.1  riastrad MODULE_FIRMWARE("radeon/BONAIRE_mec.bin");
     55  1.1  riastrad MODULE_FIRMWARE("radeon/BONAIRE_mc.bin");
     56  1.1  riastrad MODULE_FIRMWARE("radeon/BONAIRE_mc2.bin");
     57  1.1  riastrad MODULE_FIRMWARE("radeon/BONAIRE_rlc.bin");
     58  1.1  riastrad MODULE_FIRMWARE("radeon/BONAIRE_sdma.bin");
     59  1.1  riastrad MODULE_FIRMWARE("radeon/BONAIRE_smc.bin");
     60  1.1  riastrad 
     61  1.1  riastrad MODULE_FIRMWARE("radeon/bonaire_pfp.bin");
     62  1.1  riastrad MODULE_FIRMWARE("radeon/bonaire_me.bin");
     63  1.1  riastrad MODULE_FIRMWARE("radeon/bonaire_ce.bin");
     64  1.1  riastrad MODULE_FIRMWARE("radeon/bonaire_mec.bin");
     65  1.1  riastrad MODULE_FIRMWARE("radeon/bonaire_mc.bin");
     66  1.1  riastrad MODULE_FIRMWARE("radeon/bonaire_rlc.bin");
     67  1.1  riastrad MODULE_FIRMWARE("radeon/bonaire_sdma.bin");
     68  1.1  riastrad MODULE_FIRMWARE("radeon/bonaire_smc.bin");
     69  1.3  riastrad MODULE_FIRMWARE("radeon/bonaire_k_smc.bin");
     70  1.1  riastrad 
     71  1.1  riastrad MODULE_FIRMWARE("radeon/HAWAII_pfp.bin");
     72  1.1  riastrad MODULE_FIRMWARE("radeon/HAWAII_me.bin");
     73  1.1  riastrad MODULE_FIRMWARE("radeon/HAWAII_ce.bin");
     74  1.1  riastrad MODULE_FIRMWARE("radeon/HAWAII_mec.bin");
     75  1.1  riastrad MODULE_FIRMWARE("radeon/HAWAII_mc.bin");
     76  1.1  riastrad MODULE_FIRMWARE("radeon/HAWAII_mc2.bin");
     77  1.1  riastrad MODULE_FIRMWARE("radeon/HAWAII_rlc.bin");
     78  1.1  riastrad MODULE_FIRMWARE("radeon/HAWAII_sdma.bin");
     79  1.1  riastrad MODULE_FIRMWARE("radeon/HAWAII_smc.bin");
     80  1.1  riastrad 
     81  1.1  riastrad MODULE_FIRMWARE("radeon/hawaii_pfp.bin");
     82  1.1  riastrad MODULE_FIRMWARE("radeon/hawaii_me.bin");
     83  1.1  riastrad MODULE_FIRMWARE("radeon/hawaii_ce.bin");
     84  1.1  riastrad MODULE_FIRMWARE("radeon/hawaii_mec.bin");
     85  1.1  riastrad MODULE_FIRMWARE("radeon/hawaii_mc.bin");
     86  1.1  riastrad MODULE_FIRMWARE("radeon/hawaii_rlc.bin");
     87  1.1  riastrad MODULE_FIRMWARE("radeon/hawaii_sdma.bin");
     88  1.1  riastrad MODULE_FIRMWARE("radeon/hawaii_smc.bin");
     89  1.3  riastrad MODULE_FIRMWARE("radeon/hawaii_k_smc.bin");
     90  1.1  riastrad 
     91  1.1  riastrad MODULE_FIRMWARE("radeon/KAVERI_pfp.bin");
     92  1.1  riastrad MODULE_FIRMWARE("radeon/KAVERI_me.bin");
     93  1.1  riastrad MODULE_FIRMWARE("radeon/KAVERI_ce.bin");
     94  1.1  riastrad MODULE_FIRMWARE("radeon/KAVERI_mec.bin");
     95  1.1  riastrad MODULE_FIRMWARE("radeon/KAVERI_rlc.bin");
     96  1.1  riastrad MODULE_FIRMWARE("radeon/KAVERI_sdma.bin");
     97  1.1  riastrad 
     98  1.1  riastrad MODULE_FIRMWARE("radeon/kaveri_pfp.bin");
     99  1.1  riastrad MODULE_FIRMWARE("radeon/kaveri_me.bin");
    100  1.1  riastrad MODULE_FIRMWARE("radeon/kaveri_ce.bin");
    101  1.1  riastrad MODULE_FIRMWARE("radeon/kaveri_mec.bin");
    102  1.1  riastrad MODULE_FIRMWARE("radeon/kaveri_mec2.bin");
    103  1.1  riastrad MODULE_FIRMWARE("radeon/kaveri_rlc.bin");
    104  1.1  riastrad MODULE_FIRMWARE("radeon/kaveri_sdma.bin");
    105  1.1  riastrad 
    106  1.1  riastrad MODULE_FIRMWARE("radeon/KABINI_pfp.bin");
    107  1.1  riastrad MODULE_FIRMWARE("radeon/KABINI_me.bin");
    108  1.1  riastrad MODULE_FIRMWARE("radeon/KABINI_ce.bin");
    109  1.1  riastrad MODULE_FIRMWARE("radeon/KABINI_mec.bin");
    110  1.1  riastrad MODULE_FIRMWARE("radeon/KABINI_rlc.bin");
    111  1.1  riastrad MODULE_FIRMWARE("radeon/KABINI_sdma.bin");
    112  1.1  riastrad 
    113  1.1  riastrad MODULE_FIRMWARE("radeon/kabini_pfp.bin");
    114  1.1  riastrad MODULE_FIRMWARE("radeon/kabini_me.bin");
    115  1.1  riastrad MODULE_FIRMWARE("radeon/kabini_ce.bin");
    116  1.1  riastrad MODULE_FIRMWARE("radeon/kabini_mec.bin");
    117  1.1  riastrad MODULE_FIRMWARE("radeon/kabini_rlc.bin");
    118  1.1  riastrad MODULE_FIRMWARE("radeon/kabini_sdma.bin");
    119  1.1  riastrad 
    120  1.1  riastrad MODULE_FIRMWARE("radeon/MULLINS_pfp.bin");
    121  1.1  riastrad MODULE_FIRMWARE("radeon/MULLINS_me.bin");
    122  1.1  riastrad MODULE_FIRMWARE("radeon/MULLINS_ce.bin");
    123  1.1  riastrad MODULE_FIRMWARE("radeon/MULLINS_mec.bin");
    124  1.1  riastrad MODULE_FIRMWARE("radeon/MULLINS_rlc.bin");
    125  1.1  riastrad MODULE_FIRMWARE("radeon/MULLINS_sdma.bin");
    126  1.1  riastrad 
    127  1.1  riastrad MODULE_FIRMWARE("radeon/mullins_pfp.bin");
    128  1.1  riastrad MODULE_FIRMWARE("radeon/mullins_me.bin");
    129  1.1  riastrad MODULE_FIRMWARE("radeon/mullins_ce.bin");
    130  1.1  riastrad MODULE_FIRMWARE("radeon/mullins_mec.bin");
    131  1.1  riastrad MODULE_FIRMWARE("radeon/mullins_rlc.bin");
    132  1.1  riastrad MODULE_FIRMWARE("radeon/mullins_sdma.bin");
    133  1.1  riastrad 
    134  1.1  riastrad extern int r600_ih_ring_alloc(struct radeon_device *rdev);
    135  1.1  riastrad extern void r600_ih_ring_fini(struct radeon_device *rdev);
    136  1.1  riastrad extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
    137  1.1  riastrad extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
    138  1.1  riastrad extern bool evergreen_is_display_hung(struct radeon_device *rdev);
    139  1.1  riastrad extern void sumo_rlc_fini(struct radeon_device *rdev);
    140  1.1  riastrad extern int sumo_rlc_init(struct radeon_device *rdev);
    141  1.1  riastrad extern void si_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
    142  1.1  riastrad extern void si_rlc_reset(struct radeon_device *rdev);
    143  1.1  riastrad extern void si_init_uvd_internal_cg(struct radeon_device *rdev);
    144  1.1  riastrad static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh);
    145  1.1  riastrad extern int cik_sdma_resume(struct radeon_device *rdev);
    146  1.1  riastrad extern void cik_sdma_enable(struct radeon_device *rdev, bool enable);
    147  1.1  riastrad extern void cik_sdma_fini(struct radeon_device *rdev);
    148  1.1  riastrad extern void vce_v2_0_enable_mgcg(struct radeon_device *rdev, bool enable);
    149  1.1  riastrad static void cik_rlc_stop(struct radeon_device *rdev);
    150  1.1  riastrad static void cik_pcie_gen3_enable(struct radeon_device *rdev);
    151  1.1  riastrad static void cik_program_aspm(struct radeon_device *rdev);
    152  1.1  riastrad static void cik_init_pg(struct radeon_device *rdev);
    153  1.1  riastrad static void cik_init_cg(struct radeon_device *rdev);
    154  1.1  riastrad static void cik_fini_pg(struct radeon_device *rdev);
    155  1.1  riastrad static void cik_fini_cg(struct radeon_device *rdev);
    156  1.1  riastrad static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
    157  1.1  riastrad 					  bool enable);
    158  1.1  riastrad 
    159  1.1  riastrad /**
    160  1.1  riastrad  * cik_get_allowed_info_register - fetch the register for the info ioctl
    161  1.1  riastrad  *
    162  1.1  riastrad  * @rdev: radeon_device pointer
    163  1.1  riastrad  * @reg: register offset in bytes
    164  1.1  riastrad  * @val: register value
    165  1.1  riastrad  *
    166  1.1  riastrad  * Returns 0 for success or -EINVAL for an invalid register
    167  1.1  riastrad  *
    168  1.1  riastrad  */
    169  1.1  riastrad int cik_get_allowed_info_register(struct radeon_device *rdev,
    170  1.1  riastrad 				  u32 reg, u32 *val)
    171  1.1  riastrad {
    172  1.1  riastrad 	switch (reg) {
    173  1.1  riastrad 	case GRBM_STATUS:
    174  1.1  riastrad 	case GRBM_STATUS2:
    175  1.1  riastrad 	case GRBM_STATUS_SE0:
    176  1.1  riastrad 	case GRBM_STATUS_SE1:
    177  1.1  riastrad 	case GRBM_STATUS_SE2:
    178  1.1  riastrad 	case GRBM_STATUS_SE3:
    179  1.1  riastrad 	case SRBM_STATUS:
    180  1.1  riastrad 	case SRBM_STATUS2:
    181  1.1  riastrad 	case (SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET):
    182  1.1  riastrad 	case (SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET):
    183  1.1  riastrad 	case UVD_STATUS:
    184  1.1  riastrad 	/* TODO VCE */
    185  1.1  riastrad 		*val = RREG32(reg);
    186  1.1  riastrad 		return 0;
    187  1.1  riastrad 	default:
    188  1.1  riastrad 		return -EINVAL;
    189  1.1  riastrad 	}
    190  1.1  riastrad }
    191  1.1  riastrad 
    192  1.1  riastrad /*
    193  1.1  riastrad  * Indirect registers accessor
    194  1.1  riastrad  */
    195  1.1  riastrad u32 cik_didt_rreg(struct radeon_device *rdev, u32 reg)
    196  1.1  riastrad {
    197  1.1  riastrad 	unsigned long flags;
    198  1.1  riastrad 	u32 r;
    199  1.1  riastrad 
    200  1.1  riastrad 	spin_lock_irqsave(&rdev->didt_idx_lock, flags);
    201  1.1  riastrad 	WREG32(CIK_DIDT_IND_INDEX, (reg));
    202  1.1  riastrad 	r = RREG32(CIK_DIDT_IND_DATA);
    203  1.1  riastrad 	spin_unlock_irqrestore(&rdev->didt_idx_lock, flags);
    204  1.1  riastrad 	return r;
    205  1.1  riastrad }
    206  1.1  riastrad 
    207  1.1  riastrad void cik_didt_wreg(struct radeon_device *rdev, u32 reg, u32 v)
    208  1.1  riastrad {
    209  1.1  riastrad 	unsigned long flags;
    210  1.1  riastrad 
    211  1.1  riastrad 	spin_lock_irqsave(&rdev->didt_idx_lock, flags);
    212  1.1  riastrad 	WREG32(CIK_DIDT_IND_INDEX, (reg));
    213  1.1  riastrad 	WREG32(CIK_DIDT_IND_DATA, (v));
    214  1.1  riastrad 	spin_unlock_irqrestore(&rdev->didt_idx_lock, flags);
    215  1.1  riastrad }
    216  1.1  riastrad 
    217  1.1  riastrad /* get temperature in millidegrees */
    218  1.1  riastrad int ci_get_temp(struct radeon_device *rdev)
    219  1.1  riastrad {
    220  1.1  riastrad 	u32 temp;
    221  1.1  riastrad 	int actual_temp = 0;
    222  1.1  riastrad 
    223  1.1  riastrad 	temp = (RREG32_SMC(CG_MULT_THERMAL_STATUS) & CTF_TEMP_MASK) >>
    224  1.1  riastrad 		CTF_TEMP_SHIFT;
    225  1.1  riastrad 
    226  1.1  riastrad 	if (temp & 0x200)
    227  1.1  riastrad 		actual_temp = 255;
    228  1.1  riastrad 	else
    229  1.1  riastrad 		actual_temp = temp & 0x1ff;
    230  1.1  riastrad 
    231  1.3  riastrad 	return actual_temp * 1000;
    232  1.1  riastrad }
    233  1.1  riastrad 
    234  1.1  riastrad /* get temperature in millidegrees */
    235  1.1  riastrad int kv_get_temp(struct radeon_device *rdev)
    236  1.1  riastrad {
    237  1.1  riastrad 	u32 temp;
    238  1.1  riastrad 	int actual_temp = 0;
    239  1.1  riastrad 
    240  1.1  riastrad 	temp = RREG32_SMC(0xC0300E0C);
    241  1.1  riastrad 
    242  1.1  riastrad 	if (temp)
    243  1.1  riastrad 		actual_temp = (temp / 8) - 49;
    244  1.1  riastrad 	else
    245  1.1  riastrad 		actual_temp = 0;
    246  1.1  riastrad 
    247  1.3  riastrad 	return actual_temp * 1000;
    248  1.1  riastrad }
    249  1.1  riastrad 
    250  1.1  riastrad /*
    251  1.1  riastrad  * Indirect registers accessor
    252  1.1  riastrad  */
    253  1.1  riastrad u32 cik_pciep_rreg(struct radeon_device *rdev, u32 reg)
    254  1.1  riastrad {
    255  1.1  riastrad 	unsigned long flags;
    256  1.1  riastrad 	u32 r;
    257  1.1  riastrad 
    258  1.1  riastrad 	spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
    259  1.1  riastrad 	WREG32(PCIE_INDEX, reg);
    260  1.1  riastrad 	(void)RREG32(PCIE_INDEX);
    261  1.1  riastrad 	r = RREG32(PCIE_DATA);
    262  1.1  riastrad 	spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
    263  1.1  riastrad 	return r;
    264  1.1  riastrad }
    265  1.1  riastrad 
    266  1.1  riastrad void cik_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
    267  1.1  riastrad {
    268  1.1  riastrad 	unsigned long flags;
    269  1.1  riastrad 
    270  1.1  riastrad 	spin_lock_irqsave(&rdev->pciep_idx_lock, flags);
    271  1.1  riastrad 	WREG32(PCIE_INDEX, reg);
    272  1.1  riastrad 	(void)RREG32(PCIE_INDEX);
    273  1.1  riastrad 	WREG32(PCIE_DATA, v);
    274  1.1  riastrad 	(void)RREG32(PCIE_DATA);
    275  1.1  riastrad 	spin_unlock_irqrestore(&rdev->pciep_idx_lock, flags);
    276  1.1  riastrad }
    277  1.1  riastrad 
    278  1.1  riastrad static const u32 spectre_rlc_save_restore_register_list[] =
    279  1.1  riastrad {
    280  1.1  riastrad 	(0x0e00 << 16) | (0xc12c >> 2),
    281  1.1  riastrad 	0x00000000,
    282  1.1  riastrad 	(0x0e00 << 16) | (0xc140 >> 2),
    283  1.1  riastrad 	0x00000000,
    284  1.1  riastrad 	(0x0e00 << 16) | (0xc150 >> 2),
    285  1.1  riastrad 	0x00000000,
    286  1.1  riastrad 	(0x0e00 << 16) | (0xc15c >> 2),
    287  1.1  riastrad 	0x00000000,
    288  1.1  riastrad 	(0x0e00 << 16) | (0xc168 >> 2),
    289  1.1  riastrad 	0x00000000,
    290  1.1  riastrad 	(0x0e00 << 16) | (0xc170 >> 2),
    291  1.1  riastrad 	0x00000000,
    292  1.1  riastrad 	(0x0e00 << 16) | (0xc178 >> 2),
    293  1.1  riastrad 	0x00000000,
    294  1.1  riastrad 	(0x0e00 << 16) | (0xc204 >> 2),
    295  1.1  riastrad 	0x00000000,
    296  1.1  riastrad 	(0x0e00 << 16) | (0xc2b4 >> 2),
    297  1.1  riastrad 	0x00000000,
    298  1.1  riastrad 	(0x0e00 << 16) | (0xc2b8 >> 2),
    299  1.1  riastrad 	0x00000000,
    300  1.1  riastrad 	(0x0e00 << 16) | (0xc2bc >> 2),
    301  1.1  riastrad 	0x00000000,
    302  1.1  riastrad 	(0x0e00 << 16) | (0xc2c0 >> 2),
    303  1.1  riastrad 	0x00000000,
    304  1.1  riastrad 	(0x0e00 << 16) | (0x8228 >> 2),
    305  1.1  riastrad 	0x00000000,
    306  1.1  riastrad 	(0x0e00 << 16) | (0x829c >> 2),
    307  1.1  riastrad 	0x00000000,
    308  1.1  riastrad 	(0x0e00 << 16) | (0x869c >> 2),
    309  1.1  riastrad 	0x00000000,
    310  1.1  riastrad 	(0x0600 << 16) | (0x98f4 >> 2),
    311  1.1  riastrad 	0x00000000,
    312  1.1  riastrad 	(0x0e00 << 16) | (0x98f8 >> 2),
    313  1.1  riastrad 	0x00000000,
    314  1.1  riastrad 	(0x0e00 << 16) | (0x9900 >> 2),
    315  1.1  riastrad 	0x00000000,
    316  1.1  riastrad 	(0x0e00 << 16) | (0xc260 >> 2),
    317  1.1  riastrad 	0x00000000,
    318  1.1  riastrad 	(0x0e00 << 16) | (0x90e8 >> 2),
    319  1.1  riastrad 	0x00000000,
    320  1.1  riastrad 	(0x0e00 << 16) | (0x3c000 >> 2),
    321  1.1  riastrad 	0x00000000,
    322  1.1  riastrad 	(0x0e00 << 16) | (0x3c00c >> 2),
    323  1.1  riastrad 	0x00000000,
    324  1.1  riastrad 	(0x0e00 << 16) | (0x8c1c >> 2),
    325  1.1  riastrad 	0x00000000,
    326  1.1  riastrad 	(0x0e00 << 16) | (0x9700 >> 2),
    327  1.1  riastrad 	0x00000000,
    328  1.1  riastrad 	(0x0e00 << 16) | (0xcd20 >> 2),
    329  1.1  riastrad 	0x00000000,
    330  1.1  riastrad 	(0x4e00 << 16) | (0xcd20 >> 2),
    331  1.1  riastrad 	0x00000000,
    332  1.1  riastrad 	(0x5e00 << 16) | (0xcd20 >> 2),
    333  1.1  riastrad 	0x00000000,
    334  1.1  riastrad 	(0x6e00 << 16) | (0xcd20 >> 2),
    335  1.1  riastrad 	0x00000000,
    336  1.1  riastrad 	(0x7e00 << 16) | (0xcd20 >> 2),
    337  1.1  riastrad 	0x00000000,
    338  1.1  riastrad 	(0x8e00 << 16) | (0xcd20 >> 2),
    339  1.1  riastrad 	0x00000000,
    340  1.1  riastrad 	(0x9e00 << 16) | (0xcd20 >> 2),
    341  1.1  riastrad 	0x00000000,
    342  1.1  riastrad 	(0xae00 << 16) | (0xcd20 >> 2),
    343  1.1  riastrad 	0x00000000,
    344  1.1  riastrad 	(0xbe00 << 16) | (0xcd20 >> 2),
    345  1.1  riastrad 	0x00000000,
    346  1.1  riastrad 	(0x0e00 << 16) | (0x89bc >> 2),
    347  1.1  riastrad 	0x00000000,
    348  1.1  riastrad 	(0x0e00 << 16) | (0x8900 >> 2),
    349  1.1  riastrad 	0x00000000,
    350  1.1  riastrad 	0x3,
    351  1.1  riastrad 	(0x0e00 << 16) | (0xc130 >> 2),
    352  1.1  riastrad 	0x00000000,
    353  1.1  riastrad 	(0x0e00 << 16) | (0xc134 >> 2),
    354  1.1  riastrad 	0x00000000,
    355  1.1  riastrad 	(0x0e00 << 16) | (0xc1fc >> 2),
    356  1.1  riastrad 	0x00000000,
    357  1.1  riastrad 	(0x0e00 << 16) | (0xc208 >> 2),
    358  1.1  riastrad 	0x00000000,
    359  1.1  riastrad 	(0x0e00 << 16) | (0xc264 >> 2),
    360  1.1  riastrad 	0x00000000,
    361  1.1  riastrad 	(0x0e00 << 16) | (0xc268 >> 2),
    362  1.1  riastrad 	0x00000000,
    363  1.1  riastrad 	(0x0e00 << 16) | (0xc26c >> 2),
    364  1.1  riastrad 	0x00000000,
    365  1.1  riastrad 	(0x0e00 << 16) | (0xc270 >> 2),
    366  1.1  riastrad 	0x00000000,
    367  1.1  riastrad 	(0x0e00 << 16) | (0xc274 >> 2),
    368  1.1  riastrad 	0x00000000,
    369  1.1  riastrad 	(0x0e00 << 16) | (0xc278 >> 2),
    370  1.1  riastrad 	0x00000000,
    371  1.1  riastrad 	(0x0e00 << 16) | (0xc27c >> 2),
    372  1.1  riastrad 	0x00000000,
    373  1.1  riastrad 	(0x0e00 << 16) | (0xc280 >> 2),
    374  1.1  riastrad 	0x00000000,
    375  1.1  riastrad 	(0x0e00 << 16) | (0xc284 >> 2),
    376  1.1  riastrad 	0x00000000,
    377  1.1  riastrad 	(0x0e00 << 16) | (0xc288 >> 2),
    378  1.1  riastrad 	0x00000000,
    379  1.1  riastrad 	(0x0e00 << 16) | (0xc28c >> 2),
    380  1.1  riastrad 	0x00000000,
    381  1.1  riastrad 	(0x0e00 << 16) | (0xc290 >> 2),
    382  1.1  riastrad 	0x00000000,
    383  1.1  riastrad 	(0x0e00 << 16) | (0xc294 >> 2),
    384  1.1  riastrad 	0x00000000,
    385  1.1  riastrad 	(0x0e00 << 16) | (0xc298 >> 2),
    386  1.1  riastrad 	0x00000000,
    387  1.1  riastrad 	(0x0e00 << 16) | (0xc29c >> 2),
    388  1.1  riastrad 	0x00000000,
    389  1.1  riastrad 	(0x0e00 << 16) | (0xc2a0 >> 2),
    390  1.1  riastrad 	0x00000000,
    391  1.1  riastrad 	(0x0e00 << 16) | (0xc2a4 >> 2),
    392  1.1  riastrad 	0x00000000,
    393  1.1  riastrad 	(0x0e00 << 16) | (0xc2a8 >> 2),
    394  1.1  riastrad 	0x00000000,
    395  1.1  riastrad 	(0x0e00 << 16) | (0xc2ac  >> 2),
    396  1.1  riastrad 	0x00000000,
    397  1.1  riastrad 	(0x0e00 << 16) | (0xc2b0 >> 2),
    398  1.1  riastrad 	0x00000000,
    399  1.1  riastrad 	(0x0e00 << 16) | (0x301d0 >> 2),
    400  1.1  riastrad 	0x00000000,
    401  1.1  riastrad 	(0x0e00 << 16) | (0x30238 >> 2),
    402  1.1  riastrad 	0x00000000,
    403  1.1  riastrad 	(0x0e00 << 16) | (0x30250 >> 2),
    404  1.1  riastrad 	0x00000000,
    405  1.1  riastrad 	(0x0e00 << 16) | (0x30254 >> 2),
    406  1.1  riastrad 	0x00000000,
    407  1.1  riastrad 	(0x0e00 << 16) | (0x30258 >> 2),
    408  1.1  riastrad 	0x00000000,
    409  1.1  riastrad 	(0x0e00 << 16) | (0x3025c >> 2),
    410  1.1  riastrad 	0x00000000,
    411  1.1  riastrad 	(0x4e00 << 16) | (0xc900 >> 2),
    412  1.1  riastrad 	0x00000000,
    413  1.1  riastrad 	(0x5e00 << 16) | (0xc900 >> 2),
    414  1.1  riastrad 	0x00000000,
    415  1.1  riastrad 	(0x6e00 << 16) | (0xc900 >> 2),
    416  1.1  riastrad 	0x00000000,
    417  1.1  riastrad 	(0x7e00 << 16) | (0xc900 >> 2),
    418  1.1  riastrad 	0x00000000,
    419  1.1  riastrad 	(0x8e00 << 16) | (0xc900 >> 2),
    420  1.1  riastrad 	0x00000000,
    421  1.1  riastrad 	(0x9e00 << 16) | (0xc900 >> 2),
    422  1.1  riastrad 	0x00000000,
    423  1.1  riastrad 	(0xae00 << 16) | (0xc900 >> 2),
    424  1.1  riastrad 	0x00000000,
    425  1.1  riastrad 	(0xbe00 << 16) | (0xc900 >> 2),
    426  1.1  riastrad 	0x00000000,
    427  1.1  riastrad 	(0x4e00 << 16) | (0xc904 >> 2),
    428  1.1  riastrad 	0x00000000,
    429  1.1  riastrad 	(0x5e00 << 16) | (0xc904 >> 2),
    430  1.1  riastrad 	0x00000000,
    431  1.1  riastrad 	(0x6e00 << 16) | (0xc904 >> 2),
    432  1.1  riastrad 	0x00000000,
    433  1.1  riastrad 	(0x7e00 << 16) | (0xc904 >> 2),
    434  1.1  riastrad 	0x00000000,
    435  1.1  riastrad 	(0x8e00 << 16) | (0xc904 >> 2),
    436  1.1  riastrad 	0x00000000,
    437  1.1  riastrad 	(0x9e00 << 16) | (0xc904 >> 2),
    438  1.1  riastrad 	0x00000000,
    439  1.1  riastrad 	(0xae00 << 16) | (0xc904 >> 2),
    440  1.1  riastrad 	0x00000000,
    441  1.1  riastrad 	(0xbe00 << 16) | (0xc904 >> 2),
    442  1.1  riastrad 	0x00000000,
    443  1.1  riastrad 	(0x4e00 << 16) | (0xc908 >> 2),
    444  1.1  riastrad 	0x00000000,
    445  1.1  riastrad 	(0x5e00 << 16) | (0xc908 >> 2),
    446  1.1  riastrad 	0x00000000,
    447  1.1  riastrad 	(0x6e00 << 16) | (0xc908 >> 2),
    448  1.1  riastrad 	0x00000000,
    449  1.1  riastrad 	(0x7e00 << 16) | (0xc908 >> 2),
    450  1.1  riastrad 	0x00000000,
    451  1.1  riastrad 	(0x8e00 << 16) | (0xc908 >> 2),
    452  1.1  riastrad 	0x00000000,
    453  1.1  riastrad 	(0x9e00 << 16) | (0xc908 >> 2),
    454  1.1  riastrad 	0x00000000,
    455  1.1  riastrad 	(0xae00 << 16) | (0xc908 >> 2),
    456  1.1  riastrad 	0x00000000,
    457  1.1  riastrad 	(0xbe00 << 16) | (0xc908 >> 2),
    458  1.1  riastrad 	0x00000000,
    459  1.1  riastrad 	(0x4e00 << 16) | (0xc90c >> 2),
    460  1.1  riastrad 	0x00000000,
    461  1.1  riastrad 	(0x5e00 << 16) | (0xc90c >> 2),
    462  1.1  riastrad 	0x00000000,
    463  1.1  riastrad 	(0x6e00 << 16) | (0xc90c >> 2),
    464  1.1  riastrad 	0x00000000,
    465  1.1  riastrad 	(0x7e00 << 16) | (0xc90c >> 2),
    466  1.1  riastrad 	0x00000000,
    467  1.1  riastrad 	(0x8e00 << 16) | (0xc90c >> 2),
    468  1.1  riastrad 	0x00000000,
    469  1.1  riastrad 	(0x9e00 << 16) | (0xc90c >> 2),
    470  1.1  riastrad 	0x00000000,
    471  1.1  riastrad 	(0xae00 << 16) | (0xc90c >> 2),
    472  1.1  riastrad 	0x00000000,
    473  1.1  riastrad 	(0xbe00 << 16) | (0xc90c >> 2),
    474  1.1  riastrad 	0x00000000,
    475  1.1  riastrad 	(0x4e00 << 16) | (0xc910 >> 2),
    476  1.1  riastrad 	0x00000000,
    477  1.1  riastrad 	(0x5e00 << 16) | (0xc910 >> 2),
    478  1.1  riastrad 	0x00000000,
    479  1.1  riastrad 	(0x6e00 << 16) | (0xc910 >> 2),
    480  1.1  riastrad 	0x00000000,
    481  1.1  riastrad 	(0x7e00 << 16) | (0xc910 >> 2),
    482  1.1  riastrad 	0x00000000,
    483  1.1  riastrad 	(0x8e00 << 16) | (0xc910 >> 2),
    484  1.1  riastrad 	0x00000000,
    485  1.1  riastrad 	(0x9e00 << 16) | (0xc910 >> 2),
    486  1.1  riastrad 	0x00000000,
    487  1.1  riastrad 	(0xae00 << 16) | (0xc910 >> 2),
    488  1.1  riastrad 	0x00000000,
    489  1.1  riastrad 	(0xbe00 << 16) | (0xc910 >> 2),
    490  1.1  riastrad 	0x00000000,
    491  1.1  riastrad 	(0x0e00 << 16) | (0xc99c >> 2),
    492  1.1  riastrad 	0x00000000,
    493  1.1  riastrad 	(0x0e00 << 16) | (0x9834 >> 2),
    494  1.1  riastrad 	0x00000000,
    495  1.1  riastrad 	(0x0000 << 16) | (0x30f00 >> 2),
    496  1.1  riastrad 	0x00000000,
    497  1.1  riastrad 	(0x0001 << 16) | (0x30f00 >> 2),
    498  1.1  riastrad 	0x00000000,
    499  1.1  riastrad 	(0x0000 << 16) | (0x30f04 >> 2),
    500  1.1  riastrad 	0x00000000,
    501  1.1  riastrad 	(0x0001 << 16) | (0x30f04 >> 2),
    502  1.1  riastrad 	0x00000000,
    503  1.1  riastrad 	(0x0000 << 16) | (0x30f08 >> 2),
    504  1.1  riastrad 	0x00000000,
    505  1.1  riastrad 	(0x0001 << 16) | (0x30f08 >> 2),
    506  1.1  riastrad 	0x00000000,
    507  1.1  riastrad 	(0x0000 << 16) | (0x30f0c >> 2),
    508  1.1  riastrad 	0x00000000,
    509  1.1  riastrad 	(0x0001 << 16) | (0x30f0c >> 2),
    510  1.1  riastrad 	0x00000000,
    511  1.1  riastrad 	(0x0600 << 16) | (0x9b7c >> 2),
    512  1.1  riastrad 	0x00000000,
    513  1.1  riastrad 	(0x0e00 << 16) | (0x8a14 >> 2),
    514  1.1  riastrad 	0x00000000,
    515  1.1  riastrad 	(0x0e00 << 16) | (0x8a18 >> 2),
    516  1.1  riastrad 	0x00000000,
    517  1.1  riastrad 	(0x0600 << 16) | (0x30a00 >> 2),
    518  1.1  riastrad 	0x00000000,
    519  1.1  riastrad 	(0x0e00 << 16) | (0x8bf0 >> 2),
    520  1.1  riastrad 	0x00000000,
    521  1.1  riastrad 	(0x0e00 << 16) | (0x8bcc >> 2),
    522  1.1  riastrad 	0x00000000,
    523  1.1  riastrad 	(0x0e00 << 16) | (0x8b24 >> 2),
    524  1.1  riastrad 	0x00000000,
    525  1.1  riastrad 	(0x0e00 << 16) | (0x30a04 >> 2),
    526  1.1  riastrad 	0x00000000,
    527  1.1  riastrad 	(0x0600 << 16) | (0x30a10 >> 2),
    528  1.1  riastrad 	0x00000000,
    529  1.1  riastrad 	(0x0600 << 16) | (0x30a14 >> 2),
    530  1.1  riastrad 	0x00000000,
    531  1.1  riastrad 	(0x0600 << 16) | (0x30a18 >> 2),
    532  1.1  riastrad 	0x00000000,
    533  1.1  riastrad 	(0x0600 << 16) | (0x30a2c >> 2),
    534  1.1  riastrad 	0x00000000,
    535  1.1  riastrad 	(0x0e00 << 16) | (0xc700 >> 2),
    536  1.1  riastrad 	0x00000000,
    537  1.1  riastrad 	(0x0e00 << 16) | (0xc704 >> 2),
    538  1.1  riastrad 	0x00000000,
    539  1.1  riastrad 	(0x0e00 << 16) | (0xc708 >> 2),
    540  1.1  riastrad 	0x00000000,
    541  1.1  riastrad 	(0x0e00 << 16) | (0xc768 >> 2),
    542  1.1  riastrad 	0x00000000,
    543  1.1  riastrad 	(0x0400 << 16) | (0xc770 >> 2),
    544  1.1  riastrad 	0x00000000,
    545  1.1  riastrad 	(0x0400 << 16) | (0xc774 >> 2),
    546  1.1  riastrad 	0x00000000,
    547  1.1  riastrad 	(0x0400 << 16) | (0xc778 >> 2),
    548  1.1  riastrad 	0x00000000,
    549  1.1  riastrad 	(0x0400 << 16) | (0xc77c >> 2),
    550  1.1  riastrad 	0x00000000,
    551  1.1  riastrad 	(0x0400 << 16) | (0xc780 >> 2),
    552  1.1  riastrad 	0x00000000,
    553  1.1  riastrad 	(0x0400 << 16) | (0xc784 >> 2),
    554  1.1  riastrad 	0x00000000,
    555  1.1  riastrad 	(0x0400 << 16) | (0xc788 >> 2),
    556  1.1  riastrad 	0x00000000,
    557  1.1  riastrad 	(0x0400 << 16) | (0xc78c >> 2),
    558  1.1  riastrad 	0x00000000,
    559  1.1  riastrad 	(0x0400 << 16) | (0xc798 >> 2),
    560  1.1  riastrad 	0x00000000,
    561  1.1  riastrad 	(0x0400 << 16) | (0xc79c >> 2),
    562  1.1  riastrad 	0x00000000,
    563  1.1  riastrad 	(0x0400 << 16) | (0xc7a0 >> 2),
    564  1.1  riastrad 	0x00000000,
    565  1.1  riastrad 	(0x0400 << 16) | (0xc7a4 >> 2),
    566  1.1  riastrad 	0x00000000,
    567  1.1  riastrad 	(0x0400 << 16) | (0xc7a8 >> 2),
    568  1.1  riastrad 	0x00000000,
    569  1.1  riastrad 	(0x0400 << 16) | (0xc7ac >> 2),
    570  1.1  riastrad 	0x00000000,
    571  1.1  riastrad 	(0x0400 << 16) | (0xc7b0 >> 2),
    572  1.1  riastrad 	0x00000000,
    573  1.1  riastrad 	(0x0400 << 16) | (0xc7b4 >> 2),
    574  1.1  riastrad 	0x00000000,
    575  1.1  riastrad 	(0x0e00 << 16) | (0x9100 >> 2),
    576  1.1  riastrad 	0x00000000,
    577  1.1  riastrad 	(0x0e00 << 16) | (0x3c010 >> 2),
    578  1.1  riastrad 	0x00000000,
    579  1.1  riastrad 	(0x0e00 << 16) | (0x92a8 >> 2),
    580  1.1  riastrad 	0x00000000,
    581  1.1  riastrad 	(0x0e00 << 16) | (0x92ac >> 2),
    582  1.1  riastrad 	0x00000000,
    583  1.1  riastrad 	(0x0e00 << 16) | (0x92b4 >> 2),
    584  1.1  riastrad 	0x00000000,
    585  1.1  riastrad 	(0x0e00 << 16) | (0x92b8 >> 2),
    586  1.1  riastrad 	0x00000000,
    587  1.1  riastrad 	(0x0e00 << 16) | (0x92bc >> 2),
    588  1.1  riastrad 	0x00000000,
    589  1.1  riastrad 	(0x0e00 << 16) | (0x92c0 >> 2),
    590  1.1  riastrad 	0x00000000,
    591  1.1  riastrad 	(0x0e00 << 16) | (0x92c4 >> 2),
    592  1.1  riastrad 	0x00000000,
    593  1.1  riastrad 	(0x0e00 << 16) | (0x92c8 >> 2),
    594  1.1  riastrad 	0x00000000,
    595  1.1  riastrad 	(0x0e00 << 16) | (0x92cc >> 2),
    596  1.1  riastrad 	0x00000000,
    597  1.1  riastrad 	(0x0e00 << 16) | (0x92d0 >> 2),
    598  1.1  riastrad 	0x00000000,
    599  1.1  riastrad 	(0x0e00 << 16) | (0x8c00 >> 2),
    600  1.1  riastrad 	0x00000000,
    601  1.1  riastrad 	(0x0e00 << 16) | (0x8c04 >> 2),
    602  1.1  riastrad 	0x00000000,
    603  1.1  riastrad 	(0x0e00 << 16) | (0x8c20 >> 2),
    604  1.1  riastrad 	0x00000000,
    605  1.1  riastrad 	(0x0e00 << 16) | (0x8c38 >> 2),
    606  1.1  riastrad 	0x00000000,
    607  1.1  riastrad 	(0x0e00 << 16) | (0x8c3c >> 2),
    608  1.1  riastrad 	0x00000000,
    609  1.1  riastrad 	(0x0e00 << 16) | (0xae00 >> 2),
    610  1.1  riastrad 	0x00000000,
    611  1.1  riastrad 	(0x0e00 << 16) | (0x9604 >> 2),
    612  1.1  riastrad 	0x00000000,
    613  1.1  riastrad 	(0x0e00 << 16) | (0xac08 >> 2),
    614  1.1  riastrad 	0x00000000,
    615  1.1  riastrad 	(0x0e00 << 16) | (0xac0c >> 2),
    616  1.1  riastrad 	0x00000000,
    617  1.1  riastrad 	(0x0e00 << 16) | (0xac10 >> 2),
    618  1.1  riastrad 	0x00000000,
    619  1.1  riastrad 	(0x0e00 << 16) | (0xac14 >> 2),
    620  1.1  riastrad 	0x00000000,
    621  1.1  riastrad 	(0x0e00 << 16) | (0xac58 >> 2),
    622  1.1  riastrad 	0x00000000,
    623  1.1  riastrad 	(0x0e00 << 16) | (0xac68 >> 2),
    624  1.1  riastrad 	0x00000000,
    625  1.1  riastrad 	(0x0e00 << 16) | (0xac6c >> 2),
    626  1.1  riastrad 	0x00000000,
    627  1.1  riastrad 	(0x0e00 << 16) | (0xac70 >> 2),
    628  1.1  riastrad 	0x00000000,
    629  1.1  riastrad 	(0x0e00 << 16) | (0xac74 >> 2),
    630  1.1  riastrad 	0x00000000,
    631  1.1  riastrad 	(0x0e00 << 16) | (0xac78 >> 2),
    632  1.1  riastrad 	0x00000000,
    633  1.1  riastrad 	(0x0e00 << 16) | (0xac7c >> 2),
    634  1.1  riastrad 	0x00000000,
    635  1.1  riastrad 	(0x0e00 << 16) | (0xac80 >> 2),
    636  1.1  riastrad 	0x00000000,
    637  1.1  riastrad 	(0x0e00 << 16) | (0xac84 >> 2),
    638  1.1  riastrad 	0x00000000,
    639  1.1  riastrad 	(0x0e00 << 16) | (0xac88 >> 2),
    640  1.1  riastrad 	0x00000000,
    641  1.1  riastrad 	(0x0e00 << 16) | (0xac8c >> 2),
    642  1.1  riastrad 	0x00000000,
    643  1.1  riastrad 	(0x0e00 << 16) | (0x970c >> 2),
    644  1.1  riastrad 	0x00000000,
    645  1.1  riastrad 	(0x0e00 << 16) | (0x9714 >> 2),
    646  1.1  riastrad 	0x00000000,
    647  1.1  riastrad 	(0x0e00 << 16) | (0x9718 >> 2),
    648  1.1  riastrad 	0x00000000,
    649  1.1  riastrad 	(0x0e00 << 16) | (0x971c >> 2),
    650  1.1  riastrad 	0x00000000,
    651  1.1  riastrad 	(0x0e00 << 16) | (0x31068 >> 2),
    652  1.1  riastrad 	0x00000000,
    653  1.1  riastrad 	(0x4e00 << 16) | (0x31068 >> 2),
    654  1.1  riastrad 	0x00000000,
    655  1.1  riastrad 	(0x5e00 << 16) | (0x31068 >> 2),
    656  1.1  riastrad 	0x00000000,
    657  1.1  riastrad 	(0x6e00 << 16) | (0x31068 >> 2),
    658  1.1  riastrad 	0x00000000,
    659  1.1  riastrad 	(0x7e00 << 16) | (0x31068 >> 2),
    660  1.1  riastrad 	0x00000000,
    661  1.1  riastrad 	(0x8e00 << 16) | (0x31068 >> 2),
    662  1.1  riastrad 	0x00000000,
    663  1.1  riastrad 	(0x9e00 << 16) | (0x31068 >> 2),
    664  1.1  riastrad 	0x00000000,
    665  1.1  riastrad 	(0xae00 << 16) | (0x31068 >> 2),
    666  1.1  riastrad 	0x00000000,
    667  1.1  riastrad 	(0xbe00 << 16) | (0x31068 >> 2),
    668  1.1  riastrad 	0x00000000,
    669  1.1  riastrad 	(0x0e00 << 16) | (0xcd10 >> 2),
    670  1.1  riastrad 	0x00000000,
    671  1.1  riastrad 	(0x0e00 << 16) | (0xcd14 >> 2),
    672  1.1  riastrad 	0x00000000,
    673  1.1  riastrad 	(0x0e00 << 16) | (0x88b0 >> 2),
    674  1.1  riastrad 	0x00000000,
    675  1.1  riastrad 	(0x0e00 << 16) | (0x88b4 >> 2),
    676  1.1  riastrad 	0x00000000,
    677  1.1  riastrad 	(0x0e00 << 16) | (0x88b8 >> 2),
    678  1.1  riastrad 	0x00000000,
    679  1.1  riastrad 	(0x0e00 << 16) | (0x88bc >> 2),
    680  1.1  riastrad 	0x00000000,
    681  1.1  riastrad 	(0x0400 << 16) | (0x89c0 >> 2),
    682  1.1  riastrad 	0x00000000,
    683  1.1  riastrad 	(0x0e00 << 16) | (0x88c4 >> 2),
    684  1.1  riastrad 	0x00000000,
    685  1.1  riastrad 	(0x0e00 << 16) | (0x88c8 >> 2),
    686  1.1  riastrad 	0x00000000,
    687  1.1  riastrad 	(0x0e00 << 16) | (0x88d0 >> 2),
    688  1.1  riastrad 	0x00000000,
    689  1.1  riastrad 	(0x0e00 << 16) | (0x88d4 >> 2),
    690  1.1  riastrad 	0x00000000,
    691  1.1  riastrad 	(0x0e00 << 16) | (0x88d8 >> 2),
    692  1.1  riastrad 	0x00000000,
    693  1.1  riastrad 	(0x0e00 << 16) | (0x8980 >> 2),
    694  1.1  riastrad 	0x00000000,
    695  1.1  riastrad 	(0x0e00 << 16) | (0x30938 >> 2),
    696  1.1  riastrad 	0x00000000,
    697  1.1  riastrad 	(0x0e00 << 16) | (0x3093c >> 2),
    698  1.1  riastrad 	0x00000000,
    699  1.1  riastrad 	(0x0e00 << 16) | (0x30940 >> 2),
    700  1.1  riastrad 	0x00000000,
    701  1.1  riastrad 	(0x0e00 << 16) | (0x89a0 >> 2),
    702  1.1  riastrad 	0x00000000,
    703  1.1  riastrad 	(0x0e00 << 16) | (0x30900 >> 2),
    704  1.1  riastrad 	0x00000000,
    705  1.1  riastrad 	(0x0e00 << 16) | (0x30904 >> 2),
    706  1.1  riastrad 	0x00000000,
    707  1.1  riastrad 	(0x0e00 << 16) | (0x89b4 >> 2),
    708  1.1  riastrad 	0x00000000,
    709  1.1  riastrad 	(0x0e00 << 16) | (0x3c210 >> 2),
    710  1.1  riastrad 	0x00000000,
    711  1.1  riastrad 	(0x0e00 << 16) | (0x3c214 >> 2),
    712  1.1  riastrad 	0x00000000,
    713  1.1  riastrad 	(0x0e00 << 16) | (0x3c218 >> 2),
    714  1.1  riastrad 	0x00000000,
    715  1.1  riastrad 	(0x0e00 << 16) | (0x8904 >> 2),
    716  1.1  riastrad 	0x00000000,
    717  1.1  riastrad 	0x5,
    718  1.1  riastrad 	(0x0e00 << 16) | (0x8c28 >> 2),
    719  1.1  riastrad 	(0x0e00 << 16) | (0x8c2c >> 2),
    720  1.1  riastrad 	(0x0e00 << 16) | (0x8c30 >> 2),
    721  1.1  riastrad 	(0x0e00 << 16) | (0x8c34 >> 2),
    722  1.1  riastrad 	(0x0e00 << 16) | (0x9600 >> 2),
    723  1.1  riastrad };
    724  1.1  riastrad 
    725  1.1  riastrad static const u32 kalindi_rlc_save_restore_register_list[] =
    726  1.1  riastrad {
    727  1.1  riastrad 	(0x0e00 << 16) | (0xc12c >> 2),
    728  1.1  riastrad 	0x00000000,
    729  1.1  riastrad 	(0x0e00 << 16) | (0xc140 >> 2),
    730  1.1  riastrad 	0x00000000,
    731  1.1  riastrad 	(0x0e00 << 16) | (0xc150 >> 2),
    732  1.1  riastrad 	0x00000000,
    733  1.1  riastrad 	(0x0e00 << 16) | (0xc15c >> 2),
    734  1.1  riastrad 	0x00000000,
    735  1.1  riastrad 	(0x0e00 << 16) | (0xc168 >> 2),
    736  1.1  riastrad 	0x00000000,
    737  1.1  riastrad 	(0x0e00 << 16) | (0xc170 >> 2),
    738  1.1  riastrad 	0x00000000,
    739  1.1  riastrad 	(0x0e00 << 16) | (0xc204 >> 2),
    740  1.1  riastrad 	0x00000000,
    741  1.1  riastrad 	(0x0e00 << 16) | (0xc2b4 >> 2),
    742  1.1  riastrad 	0x00000000,
    743  1.1  riastrad 	(0x0e00 << 16) | (0xc2b8 >> 2),
    744  1.1  riastrad 	0x00000000,
    745  1.1  riastrad 	(0x0e00 << 16) | (0xc2bc >> 2),
    746  1.1  riastrad 	0x00000000,
    747  1.1  riastrad 	(0x0e00 << 16) | (0xc2c0 >> 2),
    748  1.1  riastrad 	0x00000000,
    749  1.1  riastrad 	(0x0e00 << 16) | (0x8228 >> 2),
    750  1.1  riastrad 	0x00000000,
    751  1.1  riastrad 	(0x0e00 << 16) | (0x829c >> 2),
    752  1.1  riastrad 	0x00000000,
    753  1.1  riastrad 	(0x0e00 << 16) | (0x869c >> 2),
    754  1.1  riastrad 	0x00000000,
    755  1.1  riastrad 	(0x0600 << 16) | (0x98f4 >> 2),
    756  1.1  riastrad 	0x00000000,
    757  1.1  riastrad 	(0x0e00 << 16) | (0x98f8 >> 2),
    758  1.1  riastrad 	0x00000000,
    759  1.1  riastrad 	(0x0e00 << 16) | (0x9900 >> 2),
    760  1.1  riastrad 	0x00000000,
    761  1.1  riastrad 	(0x0e00 << 16) | (0xc260 >> 2),
    762  1.1  riastrad 	0x00000000,
    763  1.1  riastrad 	(0x0e00 << 16) | (0x90e8 >> 2),
    764  1.1  riastrad 	0x00000000,
    765  1.1  riastrad 	(0x0e00 << 16) | (0x3c000 >> 2),
    766  1.1  riastrad 	0x00000000,
    767  1.1  riastrad 	(0x0e00 << 16) | (0x3c00c >> 2),
    768  1.1  riastrad 	0x00000000,
    769  1.1  riastrad 	(0x0e00 << 16) | (0x8c1c >> 2),
    770  1.1  riastrad 	0x00000000,
    771  1.1  riastrad 	(0x0e00 << 16) | (0x9700 >> 2),
    772  1.1  riastrad 	0x00000000,
    773  1.1  riastrad 	(0x0e00 << 16) | (0xcd20 >> 2),
    774  1.1  riastrad 	0x00000000,
    775  1.1  riastrad 	(0x4e00 << 16) | (0xcd20 >> 2),
    776  1.1  riastrad 	0x00000000,
    777  1.1  riastrad 	(0x5e00 << 16) | (0xcd20 >> 2),
    778  1.1  riastrad 	0x00000000,
    779  1.1  riastrad 	(0x6e00 << 16) | (0xcd20 >> 2),
    780  1.1  riastrad 	0x00000000,
    781  1.1  riastrad 	(0x7e00 << 16) | (0xcd20 >> 2),
    782  1.1  riastrad 	0x00000000,
    783  1.1  riastrad 	(0x0e00 << 16) | (0x89bc >> 2),
    784  1.1  riastrad 	0x00000000,
    785  1.1  riastrad 	(0x0e00 << 16) | (0x8900 >> 2),
    786  1.1  riastrad 	0x00000000,
    787  1.1  riastrad 	0x3,
    788  1.1  riastrad 	(0x0e00 << 16) | (0xc130 >> 2),
    789  1.1  riastrad 	0x00000000,
    790  1.1  riastrad 	(0x0e00 << 16) | (0xc134 >> 2),
    791  1.1  riastrad 	0x00000000,
    792  1.1  riastrad 	(0x0e00 << 16) | (0xc1fc >> 2),
    793  1.1  riastrad 	0x00000000,
    794  1.1  riastrad 	(0x0e00 << 16) | (0xc208 >> 2),
    795  1.1  riastrad 	0x00000000,
    796  1.1  riastrad 	(0x0e00 << 16) | (0xc264 >> 2),
    797  1.1  riastrad 	0x00000000,
    798  1.1  riastrad 	(0x0e00 << 16) | (0xc268 >> 2),
    799  1.1  riastrad 	0x00000000,
    800  1.1  riastrad 	(0x0e00 << 16) | (0xc26c >> 2),
    801  1.1  riastrad 	0x00000000,
    802  1.1  riastrad 	(0x0e00 << 16) | (0xc270 >> 2),
    803  1.1  riastrad 	0x00000000,
    804  1.1  riastrad 	(0x0e00 << 16) | (0xc274 >> 2),
    805  1.1  riastrad 	0x00000000,
    806  1.1  riastrad 	(0x0e00 << 16) | (0xc28c >> 2),
    807  1.1  riastrad 	0x00000000,
    808  1.1  riastrad 	(0x0e00 << 16) | (0xc290 >> 2),
    809  1.1  riastrad 	0x00000000,
    810  1.1  riastrad 	(0x0e00 << 16) | (0xc294 >> 2),
    811  1.1  riastrad 	0x00000000,
    812  1.1  riastrad 	(0x0e00 << 16) | (0xc298 >> 2),
    813  1.1  riastrad 	0x00000000,
    814  1.1  riastrad 	(0x0e00 << 16) | (0xc2a0 >> 2),
    815  1.1  riastrad 	0x00000000,
    816  1.1  riastrad 	(0x0e00 << 16) | (0xc2a4 >> 2),
    817  1.1  riastrad 	0x00000000,
    818  1.1  riastrad 	(0x0e00 << 16) | (0xc2a8 >> 2),
    819  1.1  riastrad 	0x00000000,
    820  1.1  riastrad 	(0x0e00 << 16) | (0xc2ac >> 2),
    821  1.1  riastrad 	0x00000000,
    822  1.1  riastrad 	(0x0e00 << 16) | (0x301d0 >> 2),
    823  1.1  riastrad 	0x00000000,
    824  1.1  riastrad 	(0x0e00 << 16) | (0x30238 >> 2),
    825  1.1  riastrad 	0x00000000,
    826  1.1  riastrad 	(0x0e00 << 16) | (0x30250 >> 2),
    827  1.1  riastrad 	0x00000000,
    828  1.1  riastrad 	(0x0e00 << 16) | (0x30254 >> 2),
    829  1.1  riastrad 	0x00000000,
    830  1.1  riastrad 	(0x0e00 << 16) | (0x30258 >> 2),
    831  1.1  riastrad 	0x00000000,
    832  1.1  riastrad 	(0x0e00 << 16) | (0x3025c >> 2),
    833  1.1  riastrad 	0x00000000,
    834  1.1  riastrad 	(0x4e00 << 16) | (0xc900 >> 2),
    835  1.1  riastrad 	0x00000000,
    836  1.1  riastrad 	(0x5e00 << 16) | (0xc900 >> 2),
    837  1.1  riastrad 	0x00000000,
    838  1.1  riastrad 	(0x6e00 << 16) | (0xc900 >> 2),
    839  1.1  riastrad 	0x00000000,
    840  1.1  riastrad 	(0x7e00 << 16) | (0xc900 >> 2),
    841  1.1  riastrad 	0x00000000,
    842  1.1  riastrad 	(0x4e00 << 16) | (0xc904 >> 2),
    843  1.1  riastrad 	0x00000000,
    844  1.1  riastrad 	(0x5e00 << 16) | (0xc904 >> 2),
    845  1.1  riastrad 	0x00000000,
    846  1.1  riastrad 	(0x6e00 << 16) | (0xc904 >> 2),
    847  1.1  riastrad 	0x00000000,
    848  1.1  riastrad 	(0x7e00 << 16) | (0xc904 >> 2),
    849  1.1  riastrad 	0x00000000,
    850  1.1  riastrad 	(0x4e00 << 16) | (0xc908 >> 2),
    851  1.1  riastrad 	0x00000000,
    852  1.1  riastrad 	(0x5e00 << 16) | (0xc908 >> 2),
    853  1.1  riastrad 	0x00000000,
    854  1.1  riastrad 	(0x6e00 << 16) | (0xc908 >> 2),
    855  1.1  riastrad 	0x00000000,
    856  1.1  riastrad 	(0x7e00 << 16) | (0xc908 >> 2),
    857  1.1  riastrad 	0x00000000,
    858  1.1  riastrad 	(0x4e00 << 16) | (0xc90c >> 2),
    859  1.1  riastrad 	0x00000000,
    860  1.1  riastrad 	(0x5e00 << 16) | (0xc90c >> 2),
    861  1.1  riastrad 	0x00000000,
    862  1.1  riastrad 	(0x6e00 << 16) | (0xc90c >> 2),
    863  1.1  riastrad 	0x00000000,
    864  1.1  riastrad 	(0x7e00 << 16) | (0xc90c >> 2),
    865  1.1  riastrad 	0x00000000,
    866  1.1  riastrad 	(0x4e00 << 16) | (0xc910 >> 2),
    867  1.1  riastrad 	0x00000000,
    868  1.1  riastrad 	(0x5e00 << 16) | (0xc910 >> 2),
    869  1.1  riastrad 	0x00000000,
    870  1.1  riastrad 	(0x6e00 << 16) | (0xc910 >> 2),
    871  1.1  riastrad 	0x00000000,
    872  1.1  riastrad 	(0x7e00 << 16) | (0xc910 >> 2),
    873  1.1  riastrad 	0x00000000,
    874  1.1  riastrad 	(0x0e00 << 16) | (0xc99c >> 2),
    875  1.1  riastrad 	0x00000000,
    876  1.1  riastrad 	(0x0e00 << 16) | (0x9834 >> 2),
    877  1.1  riastrad 	0x00000000,
    878  1.1  riastrad 	(0x0000 << 16) | (0x30f00 >> 2),
    879  1.1  riastrad 	0x00000000,
    880  1.1  riastrad 	(0x0000 << 16) | (0x30f04 >> 2),
    881  1.1  riastrad 	0x00000000,
    882  1.1  riastrad 	(0x0000 << 16) | (0x30f08 >> 2),
    883  1.1  riastrad 	0x00000000,
    884  1.1  riastrad 	(0x0000 << 16) | (0x30f0c >> 2),
    885  1.1  riastrad 	0x00000000,
    886  1.1  riastrad 	(0x0600 << 16) | (0x9b7c >> 2),
    887  1.1  riastrad 	0x00000000,
    888  1.1  riastrad 	(0x0e00 << 16) | (0x8a14 >> 2),
    889  1.1  riastrad 	0x00000000,
    890  1.1  riastrad 	(0x0e00 << 16) | (0x8a18 >> 2),
    891  1.1  riastrad 	0x00000000,
    892  1.1  riastrad 	(0x0600 << 16) | (0x30a00 >> 2),
    893  1.1  riastrad 	0x00000000,
    894  1.1  riastrad 	(0x0e00 << 16) | (0x8bf0 >> 2),
    895  1.1  riastrad 	0x00000000,
    896  1.1  riastrad 	(0x0e00 << 16) | (0x8bcc >> 2),
    897  1.1  riastrad 	0x00000000,
    898  1.1  riastrad 	(0x0e00 << 16) | (0x8b24 >> 2),
    899  1.1  riastrad 	0x00000000,
    900  1.1  riastrad 	(0x0e00 << 16) | (0x30a04 >> 2),
    901  1.1  riastrad 	0x00000000,
    902  1.1  riastrad 	(0x0600 << 16) | (0x30a10 >> 2),
    903  1.1  riastrad 	0x00000000,
    904  1.1  riastrad 	(0x0600 << 16) | (0x30a14 >> 2),
    905  1.1  riastrad 	0x00000000,
    906  1.1  riastrad 	(0x0600 << 16) | (0x30a18 >> 2),
    907  1.1  riastrad 	0x00000000,
    908  1.1  riastrad 	(0x0600 << 16) | (0x30a2c >> 2),
    909  1.1  riastrad 	0x00000000,
    910  1.1  riastrad 	(0x0e00 << 16) | (0xc700 >> 2),
    911  1.1  riastrad 	0x00000000,
    912  1.1  riastrad 	(0x0e00 << 16) | (0xc704 >> 2),
    913  1.1  riastrad 	0x00000000,
    914  1.1  riastrad 	(0x0e00 << 16) | (0xc708 >> 2),
    915  1.1  riastrad 	0x00000000,
    916  1.1  riastrad 	(0x0e00 << 16) | (0xc768 >> 2),
    917  1.1  riastrad 	0x00000000,
    918  1.1  riastrad 	(0x0400 << 16) | (0xc770 >> 2),
    919  1.1  riastrad 	0x00000000,
    920  1.1  riastrad 	(0x0400 << 16) | (0xc774 >> 2),
    921  1.1  riastrad 	0x00000000,
    922  1.1  riastrad 	(0x0400 << 16) | (0xc798 >> 2),
    923  1.1  riastrad 	0x00000000,
    924  1.1  riastrad 	(0x0400 << 16) | (0xc79c >> 2),
    925  1.1  riastrad 	0x00000000,
    926  1.1  riastrad 	(0x0e00 << 16) | (0x9100 >> 2),
    927  1.1  riastrad 	0x00000000,
    928  1.1  riastrad 	(0x0e00 << 16) | (0x3c010 >> 2),
    929  1.1  riastrad 	0x00000000,
    930  1.1  riastrad 	(0x0e00 << 16) | (0x8c00 >> 2),
    931  1.1  riastrad 	0x00000000,
    932  1.1  riastrad 	(0x0e00 << 16) | (0x8c04 >> 2),
    933  1.1  riastrad 	0x00000000,
    934  1.1  riastrad 	(0x0e00 << 16) | (0x8c20 >> 2),
    935  1.1  riastrad 	0x00000000,
    936  1.1  riastrad 	(0x0e00 << 16) | (0x8c38 >> 2),
    937  1.1  riastrad 	0x00000000,
    938  1.1  riastrad 	(0x0e00 << 16) | (0x8c3c >> 2),
    939  1.1  riastrad 	0x00000000,
    940  1.1  riastrad 	(0x0e00 << 16) | (0xae00 >> 2),
    941  1.1  riastrad 	0x00000000,
    942  1.1  riastrad 	(0x0e00 << 16) | (0x9604 >> 2),
    943  1.1  riastrad 	0x00000000,
    944  1.1  riastrad 	(0x0e00 << 16) | (0xac08 >> 2),
    945  1.1  riastrad 	0x00000000,
    946  1.1  riastrad 	(0x0e00 << 16) | (0xac0c >> 2),
    947  1.1  riastrad 	0x00000000,
    948  1.1  riastrad 	(0x0e00 << 16) | (0xac10 >> 2),
    949  1.1  riastrad 	0x00000000,
    950  1.1  riastrad 	(0x0e00 << 16) | (0xac14 >> 2),
    951  1.1  riastrad 	0x00000000,
    952  1.1  riastrad 	(0x0e00 << 16) | (0xac58 >> 2),
    953  1.1  riastrad 	0x00000000,
    954  1.1  riastrad 	(0x0e00 << 16) | (0xac68 >> 2),
    955  1.1  riastrad 	0x00000000,
    956  1.1  riastrad 	(0x0e00 << 16) | (0xac6c >> 2),
    957  1.1  riastrad 	0x00000000,
    958  1.1  riastrad 	(0x0e00 << 16) | (0xac70 >> 2),
    959  1.1  riastrad 	0x00000000,
    960  1.1  riastrad 	(0x0e00 << 16) | (0xac74 >> 2),
    961  1.1  riastrad 	0x00000000,
    962  1.1  riastrad 	(0x0e00 << 16) | (0xac78 >> 2),
    963  1.1  riastrad 	0x00000000,
    964  1.1  riastrad 	(0x0e00 << 16) | (0xac7c >> 2),
    965  1.1  riastrad 	0x00000000,
    966  1.1  riastrad 	(0x0e00 << 16) | (0xac80 >> 2),
    967  1.1  riastrad 	0x00000000,
    968  1.1  riastrad 	(0x0e00 << 16) | (0xac84 >> 2),
    969  1.1  riastrad 	0x00000000,
    970  1.1  riastrad 	(0x0e00 << 16) | (0xac88 >> 2),
    971  1.1  riastrad 	0x00000000,
    972  1.1  riastrad 	(0x0e00 << 16) | (0xac8c >> 2),
    973  1.1  riastrad 	0x00000000,
    974  1.1  riastrad 	(0x0e00 << 16) | (0x970c >> 2),
    975  1.1  riastrad 	0x00000000,
    976  1.1  riastrad 	(0x0e00 << 16) | (0x9714 >> 2),
    977  1.1  riastrad 	0x00000000,
    978  1.1  riastrad 	(0x0e00 << 16) | (0x9718 >> 2),
    979  1.1  riastrad 	0x00000000,
    980  1.1  riastrad 	(0x0e00 << 16) | (0x971c >> 2),
    981  1.1  riastrad 	0x00000000,
    982  1.1  riastrad 	(0x0e00 << 16) | (0x31068 >> 2),
    983  1.1  riastrad 	0x00000000,
    984  1.1  riastrad 	(0x4e00 << 16) | (0x31068 >> 2),
    985  1.1  riastrad 	0x00000000,
    986  1.1  riastrad 	(0x5e00 << 16) | (0x31068 >> 2),
    987  1.1  riastrad 	0x00000000,
    988  1.1  riastrad 	(0x6e00 << 16) | (0x31068 >> 2),
    989  1.1  riastrad 	0x00000000,
    990  1.1  riastrad 	(0x7e00 << 16) | (0x31068 >> 2),
    991  1.1  riastrad 	0x00000000,
    992  1.1  riastrad 	(0x0e00 << 16) | (0xcd10 >> 2),
    993  1.1  riastrad 	0x00000000,
    994  1.1  riastrad 	(0x0e00 << 16) | (0xcd14 >> 2),
    995  1.1  riastrad 	0x00000000,
    996  1.1  riastrad 	(0x0e00 << 16) | (0x88b0 >> 2),
    997  1.1  riastrad 	0x00000000,
    998  1.1  riastrad 	(0x0e00 << 16) | (0x88b4 >> 2),
    999  1.1  riastrad 	0x00000000,
   1000  1.1  riastrad 	(0x0e00 << 16) | (0x88b8 >> 2),
   1001  1.1  riastrad 	0x00000000,
   1002  1.1  riastrad 	(0x0e00 << 16) | (0x88bc >> 2),
   1003  1.1  riastrad 	0x00000000,
   1004  1.1  riastrad 	(0x0400 << 16) | (0x89c0 >> 2),
   1005  1.1  riastrad 	0x00000000,
   1006  1.1  riastrad 	(0x0e00 << 16) | (0x88c4 >> 2),
   1007  1.1  riastrad 	0x00000000,
   1008  1.1  riastrad 	(0x0e00 << 16) | (0x88c8 >> 2),
   1009  1.1  riastrad 	0x00000000,
   1010  1.1  riastrad 	(0x0e00 << 16) | (0x88d0 >> 2),
   1011  1.1  riastrad 	0x00000000,
   1012  1.1  riastrad 	(0x0e00 << 16) | (0x88d4 >> 2),
   1013  1.1  riastrad 	0x00000000,
   1014  1.1  riastrad 	(0x0e00 << 16) | (0x88d8 >> 2),
   1015  1.1  riastrad 	0x00000000,
   1016  1.1  riastrad 	(0x0e00 << 16) | (0x8980 >> 2),
   1017  1.1  riastrad 	0x00000000,
   1018  1.1  riastrad 	(0x0e00 << 16) | (0x30938 >> 2),
   1019  1.1  riastrad 	0x00000000,
   1020  1.1  riastrad 	(0x0e00 << 16) | (0x3093c >> 2),
   1021  1.1  riastrad 	0x00000000,
   1022  1.1  riastrad 	(0x0e00 << 16) | (0x30940 >> 2),
   1023  1.1  riastrad 	0x00000000,
   1024  1.1  riastrad 	(0x0e00 << 16) | (0x89a0 >> 2),
   1025  1.1  riastrad 	0x00000000,
   1026  1.1  riastrad 	(0x0e00 << 16) | (0x30900 >> 2),
   1027  1.1  riastrad 	0x00000000,
   1028  1.1  riastrad 	(0x0e00 << 16) | (0x30904 >> 2),
   1029  1.1  riastrad 	0x00000000,
   1030  1.1  riastrad 	(0x0e00 << 16) | (0x89b4 >> 2),
   1031  1.1  riastrad 	0x00000000,
   1032  1.1  riastrad 	(0x0e00 << 16) | (0x3e1fc >> 2),
   1033  1.1  riastrad 	0x00000000,
   1034  1.1  riastrad 	(0x0e00 << 16) | (0x3c210 >> 2),
   1035  1.1  riastrad 	0x00000000,
   1036  1.1  riastrad 	(0x0e00 << 16) | (0x3c214 >> 2),
   1037  1.1  riastrad 	0x00000000,
   1038  1.1  riastrad 	(0x0e00 << 16) | (0x3c218 >> 2),
   1039  1.1  riastrad 	0x00000000,
   1040  1.1  riastrad 	(0x0e00 << 16) | (0x8904 >> 2),
   1041  1.1  riastrad 	0x00000000,
   1042  1.1  riastrad 	0x5,
   1043  1.1  riastrad 	(0x0e00 << 16) | (0x8c28 >> 2),
   1044  1.1  riastrad 	(0x0e00 << 16) | (0x8c2c >> 2),
   1045  1.1  riastrad 	(0x0e00 << 16) | (0x8c30 >> 2),
   1046  1.1  riastrad 	(0x0e00 << 16) | (0x8c34 >> 2),
   1047  1.1  riastrad 	(0x0e00 << 16) | (0x9600 >> 2),
   1048  1.1  riastrad };
   1049  1.1  riastrad 
   1050  1.1  riastrad static const u32 bonaire_golden_spm_registers[] =
   1051  1.1  riastrad {
   1052  1.1  riastrad 	0x30800, 0xe0ffffff, 0xe0000000
   1053  1.1  riastrad };
   1054  1.1  riastrad 
   1055  1.1  riastrad static const u32 bonaire_golden_common_registers[] =
   1056  1.1  riastrad {
   1057  1.1  riastrad 	0xc770, 0xffffffff, 0x00000800,
   1058  1.1  riastrad 	0xc774, 0xffffffff, 0x00000800,
   1059  1.1  riastrad 	0xc798, 0xffffffff, 0x00007fbf,
   1060  1.1  riastrad 	0xc79c, 0xffffffff, 0x00007faf
   1061  1.1  riastrad };
   1062  1.1  riastrad 
   1063  1.1  riastrad static const u32 bonaire_golden_registers[] =
   1064  1.1  riastrad {
   1065  1.1  riastrad 	0x3354, 0x00000333, 0x00000333,
   1066  1.1  riastrad 	0x3350, 0x000c0fc0, 0x00040200,
   1067  1.1  riastrad 	0x9a10, 0x00010000, 0x00058208,
   1068  1.1  riastrad 	0x3c000, 0xffff1fff, 0x00140000,
   1069  1.1  riastrad 	0x3c200, 0xfdfc0fff, 0x00000100,
   1070  1.1  riastrad 	0x3c234, 0x40000000, 0x40000200,
   1071  1.1  riastrad 	0x9830, 0xffffffff, 0x00000000,
   1072  1.1  riastrad 	0x9834, 0xf00fffff, 0x00000400,
   1073  1.1  riastrad 	0x9838, 0x0002021c, 0x00020200,
   1074  1.1  riastrad 	0xc78, 0x00000080, 0x00000000,
   1075  1.1  riastrad 	0x5bb0, 0x000000f0, 0x00000070,
   1076  1.1  riastrad 	0x5bc0, 0xf0311fff, 0x80300000,
   1077  1.1  riastrad 	0x98f8, 0x73773777, 0x12010001,
   1078  1.1  riastrad 	0x350c, 0x00810000, 0x408af000,
   1079  1.1  riastrad 	0x7030, 0x31000111, 0x00000011,
   1080  1.1  riastrad 	0x2f48, 0x73773777, 0x12010001,
   1081  1.1  riastrad 	0x220c, 0x00007fb6, 0x0021a1b1,
   1082  1.1  riastrad 	0x2210, 0x00007fb6, 0x002021b1,
   1083  1.1  riastrad 	0x2180, 0x00007fb6, 0x00002191,
   1084  1.1  riastrad 	0x2218, 0x00007fb6, 0x002121b1,
   1085  1.1  riastrad 	0x221c, 0x00007fb6, 0x002021b1,
   1086  1.1  riastrad 	0x21dc, 0x00007fb6, 0x00002191,
   1087  1.1  riastrad 	0x21e0, 0x00007fb6, 0x00002191,
   1088  1.1  riastrad 	0x3628, 0x0000003f, 0x0000000a,
   1089  1.1  riastrad 	0x362c, 0x0000003f, 0x0000000a,
   1090  1.1  riastrad 	0x2ae4, 0x00073ffe, 0x000022a2,
   1091  1.1  riastrad 	0x240c, 0x000007ff, 0x00000000,
   1092  1.1  riastrad 	0x8a14, 0xf000003f, 0x00000007,
   1093  1.1  riastrad 	0x8bf0, 0x00002001, 0x00000001,
   1094  1.1  riastrad 	0x8b24, 0xffffffff, 0x00ffffff,
   1095  1.1  riastrad 	0x30a04, 0x0000ff0f, 0x00000000,
   1096  1.1  riastrad 	0x28a4c, 0x07ffffff, 0x06000000,
   1097  1.1  riastrad 	0x4d8, 0x00000fff, 0x00000100,
   1098  1.1  riastrad 	0x3e78, 0x00000001, 0x00000002,
   1099  1.1  riastrad 	0x9100, 0x03000000, 0x0362c688,
   1100  1.1  riastrad 	0x8c00, 0x000000ff, 0x00000001,
   1101  1.1  riastrad 	0xe40, 0x00001fff, 0x00001fff,
   1102  1.1  riastrad 	0x9060, 0x0000007f, 0x00000020,
   1103  1.1  riastrad 	0x9508, 0x00010000, 0x00010000,
   1104  1.1  riastrad 	0xac14, 0x000003ff, 0x000000f3,
   1105  1.1  riastrad 	0xac0c, 0xffffffff, 0x00001032
   1106  1.1  riastrad };
   1107  1.1  riastrad 
   1108  1.1  riastrad static const u32 bonaire_mgcg_cgcg_init[] =
   1109  1.1  riastrad {
   1110  1.1  riastrad 	0xc420, 0xffffffff, 0xfffffffc,
   1111  1.1  riastrad 	0x30800, 0xffffffff, 0xe0000000,
   1112  1.1  riastrad 	0x3c2a0, 0xffffffff, 0x00000100,
   1113  1.1  riastrad 	0x3c208, 0xffffffff, 0x00000100,
   1114  1.1  riastrad 	0x3c2c0, 0xffffffff, 0xc0000100,
   1115  1.1  riastrad 	0x3c2c8, 0xffffffff, 0xc0000100,
   1116  1.1  riastrad 	0x3c2c4, 0xffffffff, 0xc0000100,
   1117  1.1  riastrad 	0x55e4, 0xffffffff, 0x00600100,
   1118  1.1  riastrad 	0x3c280, 0xffffffff, 0x00000100,
   1119  1.1  riastrad 	0x3c214, 0xffffffff, 0x06000100,
   1120  1.1  riastrad 	0x3c220, 0xffffffff, 0x00000100,
   1121  1.1  riastrad 	0x3c218, 0xffffffff, 0x06000100,
   1122  1.1  riastrad 	0x3c204, 0xffffffff, 0x00000100,
   1123  1.1  riastrad 	0x3c2e0, 0xffffffff, 0x00000100,
   1124  1.1  riastrad 	0x3c224, 0xffffffff, 0x00000100,
   1125  1.1  riastrad 	0x3c200, 0xffffffff, 0x00000100,
   1126  1.1  riastrad 	0x3c230, 0xffffffff, 0x00000100,
   1127  1.1  riastrad 	0x3c234, 0xffffffff, 0x00000100,
   1128  1.1  riastrad 	0x3c250, 0xffffffff, 0x00000100,
   1129  1.1  riastrad 	0x3c254, 0xffffffff, 0x00000100,
   1130  1.1  riastrad 	0x3c258, 0xffffffff, 0x00000100,
   1131  1.1  riastrad 	0x3c25c, 0xffffffff, 0x00000100,
   1132  1.1  riastrad 	0x3c260, 0xffffffff, 0x00000100,
   1133  1.1  riastrad 	0x3c27c, 0xffffffff, 0x00000100,
   1134  1.1  riastrad 	0x3c278, 0xffffffff, 0x00000100,
   1135  1.1  riastrad 	0x3c210, 0xffffffff, 0x06000100,
   1136  1.1  riastrad 	0x3c290, 0xffffffff, 0x00000100,
   1137  1.1  riastrad 	0x3c274, 0xffffffff, 0x00000100,
   1138  1.1  riastrad 	0x3c2b4, 0xffffffff, 0x00000100,
   1139  1.1  riastrad 	0x3c2b0, 0xffffffff, 0x00000100,
   1140  1.1  riastrad 	0x3c270, 0xffffffff, 0x00000100,
   1141  1.1  riastrad 	0x30800, 0xffffffff, 0xe0000000,
   1142  1.1  riastrad 	0x3c020, 0xffffffff, 0x00010000,
   1143  1.1  riastrad 	0x3c024, 0xffffffff, 0x00030002,
   1144  1.1  riastrad 	0x3c028, 0xffffffff, 0x00040007,
   1145  1.1  riastrad 	0x3c02c, 0xffffffff, 0x00060005,
   1146  1.1  riastrad 	0x3c030, 0xffffffff, 0x00090008,
   1147  1.1  riastrad 	0x3c034, 0xffffffff, 0x00010000,
   1148  1.1  riastrad 	0x3c038, 0xffffffff, 0x00030002,
   1149  1.1  riastrad 	0x3c03c, 0xffffffff, 0x00040007,
   1150  1.1  riastrad 	0x3c040, 0xffffffff, 0x00060005,
   1151  1.1  riastrad 	0x3c044, 0xffffffff, 0x00090008,
   1152  1.1  riastrad 	0x3c048, 0xffffffff, 0x00010000,
   1153  1.1  riastrad 	0x3c04c, 0xffffffff, 0x00030002,
   1154  1.1  riastrad 	0x3c050, 0xffffffff, 0x00040007,
   1155  1.1  riastrad 	0x3c054, 0xffffffff, 0x00060005,
   1156  1.1  riastrad 	0x3c058, 0xffffffff, 0x00090008,
   1157  1.1  riastrad 	0x3c05c, 0xffffffff, 0x00010000,
   1158  1.1  riastrad 	0x3c060, 0xffffffff, 0x00030002,
   1159  1.1  riastrad 	0x3c064, 0xffffffff, 0x00040007,
   1160  1.1  riastrad 	0x3c068, 0xffffffff, 0x00060005,
   1161  1.1  riastrad 	0x3c06c, 0xffffffff, 0x00090008,
   1162  1.1  riastrad 	0x3c070, 0xffffffff, 0x00010000,
   1163  1.1  riastrad 	0x3c074, 0xffffffff, 0x00030002,
   1164  1.1  riastrad 	0x3c078, 0xffffffff, 0x00040007,
   1165  1.1  riastrad 	0x3c07c, 0xffffffff, 0x00060005,
   1166  1.1  riastrad 	0x3c080, 0xffffffff, 0x00090008,
   1167  1.1  riastrad 	0x3c084, 0xffffffff, 0x00010000,
   1168  1.1  riastrad 	0x3c088, 0xffffffff, 0x00030002,
   1169  1.1  riastrad 	0x3c08c, 0xffffffff, 0x00040007,
   1170  1.1  riastrad 	0x3c090, 0xffffffff, 0x00060005,
   1171  1.1  riastrad 	0x3c094, 0xffffffff, 0x00090008,
   1172  1.1  riastrad 	0x3c098, 0xffffffff, 0x00010000,
   1173  1.1  riastrad 	0x3c09c, 0xffffffff, 0x00030002,
   1174  1.1  riastrad 	0x3c0a0, 0xffffffff, 0x00040007,
   1175  1.1  riastrad 	0x3c0a4, 0xffffffff, 0x00060005,
   1176  1.1  riastrad 	0x3c0a8, 0xffffffff, 0x00090008,
   1177  1.1  riastrad 	0x3c000, 0xffffffff, 0x96e00200,
   1178  1.1  riastrad 	0x8708, 0xffffffff, 0x00900100,
   1179  1.1  riastrad 	0xc424, 0xffffffff, 0x0020003f,
   1180  1.1  riastrad 	0x38, 0xffffffff, 0x0140001c,
   1181  1.1  riastrad 	0x3c, 0x000f0000, 0x000f0000,
   1182  1.1  riastrad 	0x220, 0xffffffff, 0xC060000C,
   1183  1.1  riastrad 	0x224, 0xc0000fff, 0x00000100,
   1184  1.1  riastrad 	0xf90, 0xffffffff, 0x00000100,
   1185  1.1  riastrad 	0xf98, 0x00000101, 0x00000000,
   1186  1.1  riastrad 	0x20a8, 0xffffffff, 0x00000104,
   1187  1.1  riastrad 	0x55e4, 0xff000fff, 0x00000100,
   1188  1.1  riastrad 	0x30cc, 0xc0000fff, 0x00000104,
   1189  1.1  riastrad 	0xc1e4, 0x00000001, 0x00000001,
   1190  1.1  riastrad 	0xd00c, 0xff000ff0, 0x00000100,
   1191  1.1  riastrad 	0xd80c, 0xff000ff0, 0x00000100
   1192  1.1  riastrad };
   1193  1.1  riastrad 
   1194  1.1  riastrad static const u32 spectre_golden_spm_registers[] =
   1195  1.1  riastrad {
   1196  1.1  riastrad 	0x30800, 0xe0ffffff, 0xe0000000
   1197  1.1  riastrad };
   1198  1.1  riastrad 
   1199  1.1  riastrad static const u32 spectre_golden_common_registers[] =
   1200  1.1  riastrad {
   1201  1.1  riastrad 	0xc770, 0xffffffff, 0x00000800,
   1202  1.1  riastrad 	0xc774, 0xffffffff, 0x00000800,
   1203  1.1  riastrad 	0xc798, 0xffffffff, 0x00007fbf,
   1204  1.1  riastrad 	0xc79c, 0xffffffff, 0x00007faf
   1205  1.1  riastrad };
   1206  1.1  riastrad 
   1207  1.1  riastrad static const u32 spectre_golden_registers[] =
   1208  1.1  riastrad {
   1209  1.1  riastrad 	0x3c000, 0xffff1fff, 0x96940200,
   1210  1.1  riastrad 	0x3c00c, 0xffff0001, 0xff000000,
   1211  1.1  riastrad 	0x3c200, 0xfffc0fff, 0x00000100,
   1212  1.1  riastrad 	0x6ed8, 0x00010101, 0x00010000,
   1213  1.1  riastrad 	0x9834, 0xf00fffff, 0x00000400,
   1214  1.1  riastrad 	0x9838, 0xfffffffc, 0x00020200,
   1215  1.1  riastrad 	0x5bb0, 0x000000f0, 0x00000070,
   1216  1.1  riastrad 	0x5bc0, 0xf0311fff, 0x80300000,
   1217  1.1  riastrad 	0x98f8, 0x73773777, 0x12010001,
   1218  1.1  riastrad 	0x9b7c, 0x00ff0000, 0x00fc0000,
   1219  1.1  riastrad 	0x2f48, 0x73773777, 0x12010001,
   1220  1.1  riastrad 	0x8a14, 0xf000003f, 0x00000007,
   1221  1.1  riastrad 	0x8b24, 0xffffffff, 0x00ffffff,
   1222  1.1  riastrad 	0x28350, 0x3f3f3fff, 0x00000082,
   1223  1.1  riastrad 	0x28354, 0x0000003f, 0x00000000,
   1224  1.1  riastrad 	0x3e78, 0x00000001, 0x00000002,
   1225  1.1  riastrad 	0x913c, 0xffff03df, 0x00000004,
   1226  1.1  riastrad 	0xc768, 0x00000008, 0x00000008,
   1227  1.1  riastrad 	0x8c00, 0x000008ff, 0x00000800,
   1228  1.1  riastrad 	0x9508, 0x00010000, 0x00010000,
   1229  1.1  riastrad 	0xac0c, 0xffffffff, 0x54763210,
   1230  1.1  riastrad 	0x214f8, 0x01ff01ff, 0x00000002,
   1231  1.1  riastrad 	0x21498, 0x007ff800, 0x00200000,
   1232  1.1  riastrad 	0x2015c, 0xffffffff, 0x00000f40,
   1233  1.1  riastrad 	0x30934, 0xffffffff, 0x00000001
   1234  1.1  riastrad };
   1235  1.1  riastrad 
   1236  1.1  riastrad static const u32 spectre_mgcg_cgcg_init[] =
   1237  1.1  riastrad {
   1238  1.1  riastrad 	0xc420, 0xffffffff, 0xfffffffc,
   1239  1.1  riastrad 	0x30800, 0xffffffff, 0xe0000000,
   1240  1.1  riastrad 	0x3c2a0, 0xffffffff, 0x00000100,
   1241  1.1  riastrad 	0x3c208, 0xffffffff, 0x00000100,
   1242  1.1  riastrad 	0x3c2c0, 0xffffffff, 0x00000100,
   1243  1.1  riastrad 	0x3c2c8, 0xffffffff, 0x00000100,
   1244  1.1  riastrad 	0x3c2c4, 0xffffffff, 0x00000100,
   1245  1.1  riastrad 	0x55e4, 0xffffffff, 0x00600100,
   1246  1.1  riastrad 	0x3c280, 0xffffffff, 0x00000100,
   1247  1.1  riastrad 	0x3c214, 0xffffffff, 0x06000100,
   1248  1.1  riastrad 	0x3c220, 0xffffffff, 0x00000100,
   1249  1.1  riastrad 	0x3c218, 0xffffffff, 0x06000100,
   1250  1.1  riastrad 	0x3c204, 0xffffffff, 0x00000100,
   1251  1.1  riastrad 	0x3c2e0, 0xffffffff, 0x00000100,
   1252  1.1  riastrad 	0x3c224, 0xffffffff, 0x00000100,
   1253  1.1  riastrad 	0x3c200, 0xffffffff, 0x00000100,
   1254  1.1  riastrad 	0x3c230, 0xffffffff, 0x00000100,
   1255  1.1  riastrad 	0x3c234, 0xffffffff, 0x00000100,
   1256  1.1  riastrad 	0x3c250, 0xffffffff, 0x00000100,
   1257  1.1  riastrad 	0x3c254, 0xffffffff, 0x00000100,
   1258  1.1  riastrad 	0x3c258, 0xffffffff, 0x00000100,
   1259  1.1  riastrad 	0x3c25c, 0xffffffff, 0x00000100,
   1260  1.1  riastrad 	0x3c260, 0xffffffff, 0x00000100,
   1261  1.1  riastrad 	0x3c27c, 0xffffffff, 0x00000100,
   1262  1.1  riastrad 	0x3c278, 0xffffffff, 0x00000100,
   1263  1.1  riastrad 	0x3c210, 0xffffffff, 0x06000100,
   1264  1.1  riastrad 	0x3c290, 0xffffffff, 0x00000100,
   1265  1.1  riastrad 	0x3c274, 0xffffffff, 0x00000100,
   1266  1.1  riastrad 	0x3c2b4, 0xffffffff, 0x00000100,
   1267  1.1  riastrad 	0x3c2b0, 0xffffffff, 0x00000100,
   1268  1.1  riastrad 	0x3c270, 0xffffffff, 0x00000100,
   1269  1.1  riastrad 	0x30800, 0xffffffff, 0xe0000000,
   1270  1.1  riastrad 	0x3c020, 0xffffffff, 0x00010000,
   1271  1.1  riastrad 	0x3c024, 0xffffffff, 0x00030002,
   1272  1.1  riastrad 	0x3c028, 0xffffffff, 0x00040007,
   1273  1.1  riastrad 	0x3c02c, 0xffffffff, 0x00060005,
   1274  1.1  riastrad 	0x3c030, 0xffffffff, 0x00090008,
   1275  1.1  riastrad 	0x3c034, 0xffffffff, 0x00010000,
   1276  1.1  riastrad 	0x3c038, 0xffffffff, 0x00030002,
   1277  1.1  riastrad 	0x3c03c, 0xffffffff, 0x00040007,
   1278  1.1  riastrad 	0x3c040, 0xffffffff, 0x00060005,
   1279  1.1  riastrad 	0x3c044, 0xffffffff, 0x00090008,
   1280  1.1  riastrad 	0x3c048, 0xffffffff, 0x00010000,
   1281  1.1  riastrad 	0x3c04c, 0xffffffff, 0x00030002,
   1282  1.1  riastrad 	0x3c050, 0xffffffff, 0x00040007,
   1283  1.1  riastrad 	0x3c054, 0xffffffff, 0x00060005,
   1284  1.1  riastrad 	0x3c058, 0xffffffff, 0x00090008,
   1285  1.1  riastrad 	0x3c05c, 0xffffffff, 0x00010000,
   1286  1.1  riastrad 	0x3c060, 0xffffffff, 0x00030002,
   1287  1.1  riastrad 	0x3c064, 0xffffffff, 0x00040007,
   1288  1.1  riastrad 	0x3c068, 0xffffffff, 0x00060005,
   1289  1.1  riastrad 	0x3c06c, 0xffffffff, 0x00090008,
   1290  1.1  riastrad 	0x3c070, 0xffffffff, 0x00010000,
   1291  1.1  riastrad 	0x3c074, 0xffffffff, 0x00030002,
   1292  1.1  riastrad 	0x3c078, 0xffffffff, 0x00040007,
   1293  1.1  riastrad 	0x3c07c, 0xffffffff, 0x00060005,
   1294  1.1  riastrad 	0x3c080, 0xffffffff, 0x00090008,
   1295  1.1  riastrad 	0x3c084, 0xffffffff, 0x00010000,
   1296  1.1  riastrad 	0x3c088, 0xffffffff, 0x00030002,
   1297  1.1  riastrad 	0x3c08c, 0xffffffff, 0x00040007,
   1298  1.1  riastrad 	0x3c090, 0xffffffff, 0x00060005,
   1299  1.1  riastrad 	0x3c094, 0xffffffff, 0x00090008,
   1300  1.1  riastrad 	0x3c098, 0xffffffff, 0x00010000,
   1301  1.1  riastrad 	0x3c09c, 0xffffffff, 0x00030002,
   1302  1.1  riastrad 	0x3c0a0, 0xffffffff, 0x00040007,
   1303  1.1  riastrad 	0x3c0a4, 0xffffffff, 0x00060005,
   1304  1.1  riastrad 	0x3c0a8, 0xffffffff, 0x00090008,
   1305  1.1  riastrad 	0x3c0ac, 0xffffffff, 0x00010000,
   1306  1.1  riastrad 	0x3c0b0, 0xffffffff, 0x00030002,
   1307  1.1  riastrad 	0x3c0b4, 0xffffffff, 0x00040007,
   1308  1.1  riastrad 	0x3c0b8, 0xffffffff, 0x00060005,
   1309  1.1  riastrad 	0x3c0bc, 0xffffffff, 0x00090008,
   1310  1.1  riastrad 	0x3c000, 0xffffffff, 0x96e00200,
   1311  1.1  riastrad 	0x8708, 0xffffffff, 0x00900100,
   1312  1.1  riastrad 	0xc424, 0xffffffff, 0x0020003f,
   1313  1.1  riastrad 	0x38, 0xffffffff, 0x0140001c,
   1314  1.1  riastrad 	0x3c, 0x000f0000, 0x000f0000,
   1315  1.1  riastrad 	0x220, 0xffffffff, 0xC060000C,
   1316  1.1  riastrad 	0x224, 0xc0000fff, 0x00000100,
   1317  1.1  riastrad 	0xf90, 0xffffffff, 0x00000100,
   1318  1.1  riastrad 	0xf98, 0x00000101, 0x00000000,
   1319  1.1  riastrad 	0x20a8, 0xffffffff, 0x00000104,
   1320  1.1  riastrad 	0x55e4, 0xff000fff, 0x00000100,
   1321  1.1  riastrad 	0x30cc, 0xc0000fff, 0x00000104,
   1322  1.1  riastrad 	0xc1e4, 0x00000001, 0x00000001,
   1323  1.1  riastrad 	0xd00c, 0xff000ff0, 0x00000100,
   1324  1.1  riastrad 	0xd80c, 0xff000ff0, 0x00000100
   1325  1.1  riastrad };
   1326  1.1  riastrad 
   1327  1.1  riastrad static const u32 kalindi_golden_spm_registers[] =
   1328  1.1  riastrad {
   1329  1.1  riastrad 	0x30800, 0xe0ffffff, 0xe0000000
   1330  1.1  riastrad };
   1331  1.1  riastrad 
   1332  1.1  riastrad static const u32 kalindi_golden_common_registers[] =
   1333  1.1  riastrad {
   1334  1.1  riastrad 	0xc770, 0xffffffff, 0x00000800,
   1335  1.1  riastrad 	0xc774, 0xffffffff, 0x00000800,
   1336  1.1  riastrad 	0xc798, 0xffffffff, 0x00007fbf,
   1337  1.1  riastrad 	0xc79c, 0xffffffff, 0x00007faf
   1338  1.1  riastrad };
   1339  1.1  riastrad 
   1340  1.1  riastrad static const u32 kalindi_golden_registers[] =
   1341  1.1  riastrad {
   1342  1.1  riastrad 	0x3c000, 0xffffdfff, 0x6e944040,
   1343  1.1  riastrad 	0x55e4, 0xff607fff, 0xfc000100,
   1344  1.1  riastrad 	0x3c220, 0xff000fff, 0x00000100,
   1345  1.1  riastrad 	0x3c224, 0xff000fff, 0x00000100,
   1346  1.1  riastrad 	0x3c200, 0xfffc0fff, 0x00000100,
   1347  1.1  riastrad 	0x6ed8, 0x00010101, 0x00010000,
   1348  1.1  riastrad 	0x9830, 0xffffffff, 0x00000000,
   1349  1.1  riastrad 	0x9834, 0xf00fffff, 0x00000400,
   1350  1.1  riastrad 	0x5bb0, 0x000000f0, 0x00000070,
   1351  1.1  riastrad 	0x5bc0, 0xf0311fff, 0x80300000,
   1352  1.1  riastrad 	0x98f8, 0x73773777, 0x12010001,
   1353  1.1  riastrad 	0x98fc, 0xffffffff, 0x00000010,
   1354  1.1  riastrad 	0x9b7c, 0x00ff0000, 0x00fc0000,
   1355  1.1  riastrad 	0x8030, 0x00001f0f, 0x0000100a,
   1356  1.1  riastrad 	0x2f48, 0x73773777, 0x12010001,
   1357  1.1  riastrad 	0x2408, 0x000fffff, 0x000c007f,
   1358  1.1  riastrad 	0x8a14, 0xf000003f, 0x00000007,
   1359  1.1  riastrad 	0x8b24, 0x3fff3fff, 0x00ffcfff,
   1360  1.1  riastrad 	0x30a04, 0x0000ff0f, 0x00000000,
   1361  1.1  riastrad 	0x28a4c, 0x07ffffff, 0x06000000,
   1362  1.1  riastrad 	0x4d8, 0x00000fff, 0x00000100,
   1363  1.1  riastrad 	0x3e78, 0x00000001, 0x00000002,
   1364  1.1  riastrad 	0xc768, 0x00000008, 0x00000008,
   1365  1.1  riastrad 	0x8c00, 0x000000ff, 0x00000003,
   1366  1.1  riastrad 	0x214f8, 0x01ff01ff, 0x00000002,
   1367  1.1  riastrad 	0x21498, 0x007ff800, 0x00200000,
   1368  1.1  riastrad 	0x2015c, 0xffffffff, 0x00000f40,
   1369  1.1  riastrad 	0x88c4, 0x001f3ae3, 0x00000082,
   1370  1.1  riastrad 	0x88d4, 0x0000001f, 0x00000010,
   1371  1.1  riastrad 	0x30934, 0xffffffff, 0x00000000
   1372  1.1  riastrad };
   1373  1.1  riastrad 
   1374  1.1  riastrad static const u32 kalindi_mgcg_cgcg_init[] =
   1375  1.1  riastrad {
   1376  1.1  riastrad 	0xc420, 0xffffffff, 0xfffffffc,
   1377  1.1  riastrad 	0x30800, 0xffffffff, 0xe0000000,
   1378  1.1  riastrad 	0x3c2a0, 0xffffffff, 0x00000100,
   1379  1.1  riastrad 	0x3c208, 0xffffffff, 0x00000100,
   1380  1.1  riastrad 	0x3c2c0, 0xffffffff, 0x00000100,
   1381  1.1  riastrad 	0x3c2c8, 0xffffffff, 0x00000100,
   1382  1.1  riastrad 	0x3c2c4, 0xffffffff, 0x00000100,
   1383  1.1  riastrad 	0x55e4, 0xffffffff, 0x00600100,
   1384  1.1  riastrad 	0x3c280, 0xffffffff, 0x00000100,
   1385  1.1  riastrad 	0x3c214, 0xffffffff, 0x06000100,
   1386  1.1  riastrad 	0x3c220, 0xffffffff, 0x00000100,
   1387  1.1  riastrad 	0x3c218, 0xffffffff, 0x06000100,
   1388  1.1  riastrad 	0x3c204, 0xffffffff, 0x00000100,
   1389  1.1  riastrad 	0x3c2e0, 0xffffffff, 0x00000100,
   1390  1.1  riastrad 	0x3c224, 0xffffffff, 0x00000100,
   1391  1.1  riastrad 	0x3c200, 0xffffffff, 0x00000100,
   1392  1.1  riastrad 	0x3c230, 0xffffffff, 0x00000100,
   1393  1.1  riastrad 	0x3c234, 0xffffffff, 0x00000100,
   1394  1.1  riastrad 	0x3c250, 0xffffffff, 0x00000100,
   1395  1.1  riastrad 	0x3c254, 0xffffffff, 0x00000100,
   1396  1.1  riastrad 	0x3c258, 0xffffffff, 0x00000100,
   1397  1.1  riastrad 	0x3c25c, 0xffffffff, 0x00000100,
   1398  1.1  riastrad 	0x3c260, 0xffffffff, 0x00000100,
   1399  1.1  riastrad 	0x3c27c, 0xffffffff, 0x00000100,
   1400  1.1  riastrad 	0x3c278, 0xffffffff, 0x00000100,
   1401  1.1  riastrad 	0x3c210, 0xffffffff, 0x06000100,
   1402  1.1  riastrad 	0x3c290, 0xffffffff, 0x00000100,
   1403  1.1  riastrad 	0x3c274, 0xffffffff, 0x00000100,
   1404  1.1  riastrad 	0x3c2b4, 0xffffffff, 0x00000100,
   1405  1.1  riastrad 	0x3c2b0, 0xffffffff, 0x00000100,
   1406  1.1  riastrad 	0x3c270, 0xffffffff, 0x00000100,
   1407  1.1  riastrad 	0x30800, 0xffffffff, 0xe0000000,
   1408  1.1  riastrad 	0x3c020, 0xffffffff, 0x00010000,
   1409  1.1  riastrad 	0x3c024, 0xffffffff, 0x00030002,
   1410  1.1  riastrad 	0x3c028, 0xffffffff, 0x00040007,
   1411  1.1  riastrad 	0x3c02c, 0xffffffff, 0x00060005,
   1412  1.1  riastrad 	0x3c030, 0xffffffff, 0x00090008,
   1413  1.1  riastrad 	0x3c034, 0xffffffff, 0x00010000,
   1414  1.1  riastrad 	0x3c038, 0xffffffff, 0x00030002,
   1415  1.1  riastrad 	0x3c03c, 0xffffffff, 0x00040007,
   1416  1.1  riastrad 	0x3c040, 0xffffffff, 0x00060005,
   1417  1.1  riastrad 	0x3c044, 0xffffffff, 0x00090008,
   1418  1.1  riastrad 	0x3c000, 0xffffffff, 0x96e00200,
   1419  1.1  riastrad 	0x8708, 0xffffffff, 0x00900100,
   1420  1.1  riastrad 	0xc424, 0xffffffff, 0x0020003f,
   1421  1.1  riastrad 	0x38, 0xffffffff, 0x0140001c,
   1422  1.1  riastrad 	0x3c, 0x000f0000, 0x000f0000,
   1423  1.1  riastrad 	0x220, 0xffffffff, 0xC060000C,
   1424  1.1  riastrad 	0x224, 0xc0000fff, 0x00000100,
   1425  1.1  riastrad 	0x20a8, 0xffffffff, 0x00000104,
   1426  1.1  riastrad 	0x55e4, 0xff000fff, 0x00000100,
   1427  1.1  riastrad 	0x30cc, 0xc0000fff, 0x00000104,
   1428  1.1  riastrad 	0xc1e4, 0x00000001, 0x00000001,
   1429  1.1  riastrad 	0xd00c, 0xff000ff0, 0x00000100,
   1430  1.1  riastrad 	0xd80c, 0xff000ff0, 0x00000100
   1431  1.1  riastrad };
   1432  1.1  riastrad 
   1433  1.1  riastrad static const u32 hawaii_golden_spm_registers[] =
   1434  1.1  riastrad {
   1435  1.1  riastrad 	0x30800, 0xe0ffffff, 0xe0000000
   1436  1.1  riastrad };
   1437  1.1  riastrad 
   1438  1.1  riastrad static const u32 hawaii_golden_common_registers[] =
   1439  1.1  riastrad {
   1440  1.1  riastrad 	0x30800, 0xffffffff, 0xe0000000,
   1441  1.1  riastrad 	0x28350, 0xffffffff, 0x3a00161a,
   1442  1.1  riastrad 	0x28354, 0xffffffff, 0x0000002e,
   1443  1.1  riastrad 	0x9a10, 0xffffffff, 0x00018208,
   1444  1.1  riastrad 	0x98f8, 0xffffffff, 0x12011003
   1445  1.1  riastrad };
   1446  1.1  riastrad 
   1447  1.1  riastrad static const u32 hawaii_golden_registers[] =
   1448  1.1  riastrad {
   1449  1.1  riastrad 	0x3354, 0x00000333, 0x00000333,
   1450  1.1  riastrad 	0x9a10, 0x00010000, 0x00058208,
   1451  1.1  riastrad 	0x9830, 0xffffffff, 0x00000000,
   1452  1.1  riastrad 	0x9834, 0xf00fffff, 0x00000400,
   1453  1.1  riastrad 	0x9838, 0x0002021c, 0x00020200,
   1454  1.1  riastrad 	0xc78, 0x00000080, 0x00000000,
   1455  1.1  riastrad 	0x5bb0, 0x000000f0, 0x00000070,
   1456  1.1  riastrad 	0x5bc0, 0xf0311fff, 0x80300000,
   1457  1.1  riastrad 	0x350c, 0x00810000, 0x408af000,
   1458  1.1  riastrad 	0x7030, 0x31000111, 0x00000011,
   1459  1.1  riastrad 	0x2f48, 0x73773777, 0x12010001,
   1460  1.1  riastrad 	0x2120, 0x0000007f, 0x0000001b,
   1461  1.1  riastrad 	0x21dc, 0x00007fb6, 0x00002191,
   1462  1.1  riastrad 	0x3628, 0x0000003f, 0x0000000a,
   1463  1.1  riastrad 	0x362c, 0x0000003f, 0x0000000a,
   1464  1.1  riastrad 	0x2ae4, 0x00073ffe, 0x000022a2,
   1465  1.1  riastrad 	0x240c, 0x000007ff, 0x00000000,
   1466  1.1  riastrad 	0x8bf0, 0x00002001, 0x00000001,
   1467  1.1  riastrad 	0x8b24, 0xffffffff, 0x00ffffff,
   1468  1.1  riastrad 	0x30a04, 0x0000ff0f, 0x00000000,
   1469  1.1  riastrad 	0x28a4c, 0x07ffffff, 0x06000000,
   1470  1.1  riastrad 	0x3e78, 0x00000001, 0x00000002,
   1471  1.1  riastrad 	0xc768, 0x00000008, 0x00000008,
   1472  1.1  riastrad 	0xc770, 0x00000f00, 0x00000800,
   1473  1.1  riastrad 	0xc774, 0x00000f00, 0x00000800,
   1474  1.1  riastrad 	0xc798, 0x00ffffff, 0x00ff7fbf,
   1475  1.1  riastrad 	0xc79c, 0x00ffffff, 0x00ff7faf,
   1476  1.1  riastrad 	0x8c00, 0x000000ff, 0x00000800,
   1477  1.1  riastrad 	0xe40, 0x00001fff, 0x00001fff,
   1478  1.1  riastrad 	0x9060, 0x0000007f, 0x00000020,
   1479  1.1  riastrad 	0x9508, 0x00010000, 0x00010000,
   1480  1.1  riastrad 	0xae00, 0x00100000, 0x000ff07c,
   1481  1.1  riastrad 	0xac14, 0x000003ff, 0x0000000f,
   1482  1.1  riastrad 	0xac10, 0xffffffff, 0x7564fdec,
   1483  1.1  riastrad 	0xac0c, 0xffffffff, 0x3120b9a8,
   1484  1.1  riastrad 	0xac08, 0x20000000, 0x0f9c0000
   1485  1.1  riastrad };
   1486  1.1  riastrad 
   1487  1.1  riastrad static const u32 hawaii_mgcg_cgcg_init[] =
   1488  1.1  riastrad {
   1489  1.1  riastrad 	0xc420, 0xffffffff, 0xfffffffd,
   1490  1.1  riastrad 	0x30800, 0xffffffff, 0xe0000000,
   1491  1.1  riastrad 	0x3c2a0, 0xffffffff, 0x00000100,
   1492  1.1  riastrad 	0x3c208, 0xffffffff, 0x00000100,
   1493  1.1  riastrad 	0x3c2c0, 0xffffffff, 0x00000100,
   1494  1.1  riastrad 	0x3c2c8, 0xffffffff, 0x00000100,
   1495  1.1  riastrad 	0x3c2c4, 0xffffffff, 0x00000100,
   1496  1.1  riastrad 	0x55e4, 0xffffffff, 0x00200100,
   1497  1.1  riastrad 	0x3c280, 0xffffffff, 0x00000100,
   1498  1.1  riastrad 	0x3c214, 0xffffffff, 0x06000100,
   1499  1.1  riastrad 	0x3c220, 0xffffffff, 0x00000100,
   1500  1.1  riastrad 	0x3c218, 0xffffffff, 0x06000100,
   1501  1.1  riastrad 	0x3c204, 0xffffffff, 0x00000100,
   1502  1.1  riastrad 	0x3c2e0, 0xffffffff, 0x00000100,
   1503  1.1  riastrad 	0x3c224, 0xffffffff, 0x00000100,
   1504  1.1  riastrad 	0x3c200, 0xffffffff, 0x00000100,
   1505  1.1  riastrad 	0x3c230, 0xffffffff, 0x00000100,
   1506  1.1  riastrad 	0x3c234, 0xffffffff, 0x00000100,
   1507  1.1  riastrad 	0x3c250, 0xffffffff, 0x00000100,
   1508  1.1  riastrad 	0x3c254, 0xffffffff, 0x00000100,
   1509  1.1  riastrad 	0x3c258, 0xffffffff, 0x00000100,
   1510  1.1  riastrad 	0x3c25c, 0xffffffff, 0x00000100,
   1511  1.1  riastrad 	0x3c260, 0xffffffff, 0x00000100,
   1512  1.1  riastrad 	0x3c27c, 0xffffffff, 0x00000100,
   1513  1.1  riastrad 	0x3c278, 0xffffffff, 0x00000100,
   1514  1.1  riastrad 	0x3c210, 0xffffffff, 0x06000100,
   1515  1.1  riastrad 	0x3c290, 0xffffffff, 0x00000100,
   1516  1.1  riastrad 	0x3c274, 0xffffffff, 0x00000100,
   1517  1.1  riastrad 	0x3c2b4, 0xffffffff, 0x00000100,
   1518  1.1  riastrad 	0x3c2b0, 0xffffffff, 0x00000100,
   1519  1.1  riastrad 	0x3c270, 0xffffffff, 0x00000100,
   1520  1.1  riastrad 	0x30800, 0xffffffff, 0xe0000000,
   1521  1.1  riastrad 	0x3c020, 0xffffffff, 0x00010000,
   1522  1.1  riastrad 	0x3c024, 0xffffffff, 0x00030002,
   1523  1.1  riastrad 	0x3c028, 0xffffffff, 0x00040007,
   1524  1.1  riastrad 	0x3c02c, 0xffffffff, 0x00060005,
   1525  1.1  riastrad 	0x3c030, 0xffffffff, 0x00090008,
   1526  1.1  riastrad 	0x3c034, 0xffffffff, 0x00010000,
   1527  1.1  riastrad 	0x3c038, 0xffffffff, 0x00030002,
   1528  1.1  riastrad 	0x3c03c, 0xffffffff, 0x00040007,
   1529  1.1  riastrad 	0x3c040, 0xffffffff, 0x00060005,
   1530  1.1  riastrad 	0x3c044, 0xffffffff, 0x00090008,
   1531  1.1  riastrad 	0x3c048, 0xffffffff, 0x00010000,
   1532  1.1  riastrad 	0x3c04c, 0xffffffff, 0x00030002,
   1533  1.1  riastrad 	0x3c050, 0xffffffff, 0x00040007,
   1534  1.1  riastrad 	0x3c054, 0xffffffff, 0x00060005,
   1535  1.1  riastrad 	0x3c058, 0xffffffff, 0x00090008,
   1536  1.1  riastrad 	0x3c05c, 0xffffffff, 0x00010000,
   1537  1.1  riastrad 	0x3c060, 0xffffffff, 0x00030002,
   1538  1.1  riastrad 	0x3c064, 0xffffffff, 0x00040007,
   1539  1.1  riastrad 	0x3c068, 0xffffffff, 0x00060005,
   1540  1.1  riastrad 	0x3c06c, 0xffffffff, 0x00090008,
   1541  1.1  riastrad 	0x3c070, 0xffffffff, 0x00010000,
   1542  1.1  riastrad 	0x3c074, 0xffffffff, 0x00030002,
   1543  1.1  riastrad 	0x3c078, 0xffffffff, 0x00040007,
   1544  1.1  riastrad 	0x3c07c, 0xffffffff, 0x00060005,
   1545  1.1  riastrad 	0x3c080, 0xffffffff, 0x00090008,
   1546  1.1  riastrad 	0x3c084, 0xffffffff, 0x00010000,
   1547  1.1  riastrad 	0x3c088, 0xffffffff, 0x00030002,
   1548  1.1  riastrad 	0x3c08c, 0xffffffff, 0x00040007,
   1549  1.1  riastrad 	0x3c090, 0xffffffff, 0x00060005,
   1550  1.1  riastrad 	0x3c094, 0xffffffff, 0x00090008,
   1551  1.1  riastrad 	0x3c098, 0xffffffff, 0x00010000,
   1552  1.1  riastrad 	0x3c09c, 0xffffffff, 0x00030002,
   1553  1.1  riastrad 	0x3c0a0, 0xffffffff, 0x00040007,
   1554  1.1  riastrad 	0x3c0a4, 0xffffffff, 0x00060005,
   1555  1.1  riastrad 	0x3c0a8, 0xffffffff, 0x00090008,
   1556  1.1  riastrad 	0x3c0ac, 0xffffffff, 0x00010000,
   1557  1.1  riastrad 	0x3c0b0, 0xffffffff, 0x00030002,
   1558  1.1  riastrad 	0x3c0b4, 0xffffffff, 0x00040007,
   1559  1.1  riastrad 	0x3c0b8, 0xffffffff, 0x00060005,
   1560  1.1  riastrad 	0x3c0bc, 0xffffffff, 0x00090008,
   1561  1.1  riastrad 	0x3c0c0, 0xffffffff, 0x00010000,
   1562  1.1  riastrad 	0x3c0c4, 0xffffffff, 0x00030002,
   1563  1.1  riastrad 	0x3c0c8, 0xffffffff, 0x00040007,
   1564  1.1  riastrad 	0x3c0cc, 0xffffffff, 0x00060005,
   1565  1.1  riastrad 	0x3c0d0, 0xffffffff, 0x00090008,
   1566  1.1  riastrad 	0x3c0d4, 0xffffffff, 0x00010000,
   1567  1.1  riastrad 	0x3c0d8, 0xffffffff, 0x00030002,
   1568  1.1  riastrad 	0x3c0dc, 0xffffffff, 0x00040007,
   1569  1.1  riastrad 	0x3c0e0, 0xffffffff, 0x00060005,
   1570  1.1  riastrad 	0x3c0e4, 0xffffffff, 0x00090008,
   1571  1.1  riastrad 	0x3c0e8, 0xffffffff, 0x00010000,
   1572  1.1  riastrad 	0x3c0ec, 0xffffffff, 0x00030002,
   1573  1.1  riastrad 	0x3c0f0, 0xffffffff, 0x00040007,
   1574  1.1  riastrad 	0x3c0f4, 0xffffffff, 0x00060005,
   1575  1.1  riastrad 	0x3c0f8, 0xffffffff, 0x00090008,
   1576  1.1  riastrad 	0xc318, 0xffffffff, 0x00020200,
   1577  1.1  riastrad 	0x3350, 0xffffffff, 0x00000200,
   1578  1.1  riastrad 	0x15c0, 0xffffffff, 0x00000400,
   1579  1.1  riastrad 	0x55e8, 0xffffffff, 0x00000000,
   1580  1.1  riastrad 	0x2f50, 0xffffffff, 0x00000902,
   1581  1.1  riastrad 	0x3c000, 0xffffffff, 0x96940200,
   1582  1.1  riastrad 	0x8708, 0xffffffff, 0x00900100,
   1583  1.1  riastrad 	0xc424, 0xffffffff, 0x0020003f,
   1584  1.1  riastrad 	0x38, 0xffffffff, 0x0140001c,
   1585  1.1  riastrad 	0x3c, 0x000f0000, 0x000f0000,
   1586  1.1  riastrad 	0x220, 0xffffffff, 0xc060000c,
   1587  1.1  riastrad 	0x224, 0xc0000fff, 0x00000100,
   1588  1.1  riastrad 	0xf90, 0xffffffff, 0x00000100,
   1589  1.1  riastrad 	0xf98, 0x00000101, 0x00000000,
   1590  1.1  riastrad 	0x20a8, 0xffffffff, 0x00000104,
   1591  1.1  riastrad 	0x55e4, 0xff000fff, 0x00000100,
   1592  1.1  riastrad 	0x30cc, 0xc0000fff, 0x00000104,
   1593  1.1  riastrad 	0xc1e4, 0x00000001, 0x00000001,
   1594  1.1  riastrad 	0xd00c, 0xff000ff0, 0x00000100,
   1595  1.1  riastrad 	0xd80c, 0xff000ff0, 0x00000100
   1596  1.1  riastrad };
   1597  1.1  riastrad 
   1598  1.1  riastrad static const u32 godavari_golden_registers[] =
   1599  1.1  riastrad {
   1600  1.1  riastrad 	0x55e4, 0xff607fff, 0xfc000100,
   1601  1.1  riastrad 	0x6ed8, 0x00010101, 0x00010000,
   1602  1.1  riastrad 	0x9830, 0xffffffff, 0x00000000,
   1603  1.1  riastrad 	0x98302, 0xf00fffff, 0x00000400,
   1604  1.1  riastrad 	0x6130, 0xffffffff, 0x00010000,
   1605  1.1  riastrad 	0x5bb0, 0x000000f0, 0x00000070,
   1606  1.1  riastrad 	0x5bc0, 0xf0311fff, 0x80300000,
   1607  1.1  riastrad 	0x98f8, 0x73773777, 0x12010001,
   1608  1.1  riastrad 	0x98fc, 0xffffffff, 0x00000010,
   1609  1.1  riastrad 	0x8030, 0x00001f0f, 0x0000100a,
   1610  1.1  riastrad 	0x2f48, 0x73773777, 0x12010001,
   1611  1.1  riastrad 	0x2408, 0x000fffff, 0x000c007f,
   1612  1.1  riastrad 	0x8a14, 0xf000003f, 0x00000007,
   1613  1.1  riastrad 	0x8b24, 0xffffffff, 0x00ff0fff,
   1614  1.1  riastrad 	0x30a04, 0x0000ff0f, 0x00000000,
   1615  1.1  riastrad 	0x28a4c, 0x07ffffff, 0x06000000,
   1616  1.1  riastrad 	0x4d8, 0x00000fff, 0x00000100,
   1617  1.1  riastrad 	0xd014, 0x00010000, 0x00810001,
   1618  1.1  riastrad 	0xd814, 0x00010000, 0x00810001,
   1619  1.1  riastrad 	0x3e78, 0x00000001, 0x00000002,
   1620  1.1  riastrad 	0xc768, 0x00000008, 0x00000008,
   1621  1.1  riastrad 	0xc770, 0x00000f00, 0x00000800,
   1622  1.1  riastrad 	0xc774, 0x00000f00, 0x00000800,
   1623  1.1  riastrad 	0xc798, 0x00ffffff, 0x00ff7fbf,
   1624  1.1  riastrad 	0xc79c, 0x00ffffff, 0x00ff7faf,
   1625  1.1  riastrad 	0x8c00, 0x000000ff, 0x00000001,
   1626  1.1  riastrad 	0x214f8, 0x01ff01ff, 0x00000002,
   1627  1.1  riastrad 	0x21498, 0x007ff800, 0x00200000,
   1628  1.1  riastrad 	0x2015c, 0xffffffff, 0x00000f40,
   1629  1.1  riastrad 	0x88c4, 0x001f3ae3, 0x00000082,
   1630  1.1  riastrad 	0x88d4, 0x0000001f, 0x00000010,
   1631  1.1  riastrad 	0x30934, 0xffffffff, 0x00000000
   1632  1.1  riastrad };
   1633  1.1  riastrad 
   1634  1.1  riastrad 
   1635  1.1  riastrad static void cik_init_golden_registers(struct radeon_device *rdev)
   1636  1.1  riastrad {
   1637  1.1  riastrad 	switch (rdev->family) {
   1638  1.1  riastrad 	case CHIP_BONAIRE:
   1639  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1640  1.1  riastrad 						 bonaire_mgcg_cgcg_init,
   1641  1.1  riastrad 						 (const u32)ARRAY_SIZE(bonaire_mgcg_cgcg_init));
   1642  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1643  1.1  riastrad 						 bonaire_golden_registers,
   1644  1.1  riastrad 						 (const u32)ARRAY_SIZE(bonaire_golden_registers));
   1645  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1646  1.1  riastrad 						 bonaire_golden_common_registers,
   1647  1.1  riastrad 						 (const u32)ARRAY_SIZE(bonaire_golden_common_registers));
   1648  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1649  1.1  riastrad 						 bonaire_golden_spm_registers,
   1650  1.1  riastrad 						 (const u32)ARRAY_SIZE(bonaire_golden_spm_registers));
   1651  1.1  riastrad 		break;
   1652  1.1  riastrad 	case CHIP_KABINI:
   1653  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1654  1.1  riastrad 						 kalindi_mgcg_cgcg_init,
   1655  1.1  riastrad 						 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
   1656  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1657  1.1  riastrad 						 kalindi_golden_registers,
   1658  1.1  riastrad 						 (const u32)ARRAY_SIZE(kalindi_golden_registers));
   1659  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1660  1.1  riastrad 						 kalindi_golden_common_registers,
   1661  1.1  riastrad 						 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
   1662  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1663  1.1  riastrad 						 kalindi_golden_spm_registers,
   1664  1.1  riastrad 						 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
   1665  1.1  riastrad 		break;
   1666  1.1  riastrad 	case CHIP_MULLINS:
   1667  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1668  1.1  riastrad 						 kalindi_mgcg_cgcg_init,
   1669  1.1  riastrad 						 (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
   1670  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1671  1.1  riastrad 						 godavari_golden_registers,
   1672  1.1  riastrad 						 (const u32)ARRAY_SIZE(godavari_golden_registers));
   1673  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1674  1.1  riastrad 						 kalindi_golden_common_registers,
   1675  1.1  riastrad 						 (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
   1676  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1677  1.1  riastrad 						 kalindi_golden_spm_registers,
   1678  1.1  riastrad 						 (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
   1679  1.1  riastrad 		break;
   1680  1.1  riastrad 	case CHIP_KAVERI:
   1681  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1682  1.1  riastrad 						 spectre_mgcg_cgcg_init,
   1683  1.1  riastrad 						 (const u32)ARRAY_SIZE(spectre_mgcg_cgcg_init));
   1684  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1685  1.1  riastrad 						 spectre_golden_registers,
   1686  1.1  riastrad 						 (const u32)ARRAY_SIZE(spectre_golden_registers));
   1687  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1688  1.1  riastrad 						 spectre_golden_common_registers,
   1689  1.1  riastrad 						 (const u32)ARRAY_SIZE(spectre_golden_common_registers));
   1690  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1691  1.1  riastrad 						 spectre_golden_spm_registers,
   1692  1.1  riastrad 						 (const u32)ARRAY_SIZE(spectre_golden_spm_registers));
   1693  1.1  riastrad 		break;
   1694  1.1  riastrad 	case CHIP_HAWAII:
   1695  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1696  1.1  riastrad 						 hawaii_mgcg_cgcg_init,
   1697  1.1  riastrad 						 (const u32)ARRAY_SIZE(hawaii_mgcg_cgcg_init));
   1698  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1699  1.1  riastrad 						 hawaii_golden_registers,
   1700  1.1  riastrad 						 (const u32)ARRAY_SIZE(hawaii_golden_registers));
   1701  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1702  1.1  riastrad 						 hawaii_golden_common_registers,
   1703  1.1  riastrad 						 (const u32)ARRAY_SIZE(hawaii_golden_common_registers));
   1704  1.1  riastrad 		radeon_program_register_sequence(rdev,
   1705  1.1  riastrad 						 hawaii_golden_spm_registers,
   1706  1.1  riastrad 						 (const u32)ARRAY_SIZE(hawaii_golden_spm_registers));
   1707  1.1  riastrad 		break;
   1708  1.1  riastrad 	default:
   1709  1.1  riastrad 		break;
   1710  1.1  riastrad 	}
   1711  1.1  riastrad }
   1712  1.1  riastrad 
   1713  1.1  riastrad /**
   1714  1.1  riastrad  * cik_get_xclk - get the xclk
   1715  1.1  riastrad  *
   1716  1.1  riastrad  * @rdev: radeon_device pointer
   1717  1.1  riastrad  *
   1718  1.1  riastrad  * Returns the reference clock used by the gfx engine
   1719  1.1  riastrad  * (CIK).
   1720  1.1  riastrad  */
   1721  1.1  riastrad u32 cik_get_xclk(struct radeon_device *rdev)
   1722  1.1  riastrad {
   1723  1.3  riastrad 	u32 reference_clock = rdev->clock.spll.reference_freq;
   1724  1.1  riastrad 
   1725  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP) {
   1726  1.1  riastrad 		if (RREG32_SMC(GENERAL_PWRMGT) & GPU_COUNTER_CLK)
   1727  1.1  riastrad 			return reference_clock / 2;
   1728  1.1  riastrad 	} else {
   1729  1.1  riastrad 		if (RREG32_SMC(CG_CLKPIN_CNTL) & XTALIN_DIVIDE)
   1730  1.1  riastrad 			return reference_clock / 4;
   1731  1.1  riastrad 	}
   1732  1.1  riastrad 	return reference_clock;
   1733  1.1  riastrad }
   1734  1.1  riastrad 
   1735  1.1  riastrad /**
   1736  1.1  riastrad  * cik_mm_rdoorbell - read a doorbell dword
   1737  1.1  riastrad  *
   1738  1.1  riastrad  * @rdev: radeon_device pointer
   1739  1.1  riastrad  * @index: doorbell index
   1740  1.1  riastrad  *
   1741  1.1  riastrad  * Returns the value in the doorbell aperture at the
   1742  1.1  riastrad  * requested doorbell index (CIK).
   1743  1.1  riastrad  */
   1744  1.1  riastrad u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 index)
   1745  1.1  riastrad {
   1746  1.1  riastrad 	if (index < rdev->doorbell.num_doorbells) {
   1747  1.1  riastrad #ifdef __NetBSD__
   1748  1.1  riastrad 		return bus_space_read_4(rdev->doorbell.bst, rdev->doorbell.bsh,
   1749  1.1  riastrad 		    index*4);
   1750  1.1  riastrad #else
   1751  1.1  riastrad 		return readl(rdev->doorbell.ptr + index);
   1752  1.1  riastrad #endif
   1753  1.1  riastrad 	} else {
   1754  1.1  riastrad 		DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
   1755  1.1  riastrad 		return 0;
   1756  1.1  riastrad 	}
   1757  1.1  riastrad }
   1758  1.1  riastrad 
   1759  1.1  riastrad /**
   1760  1.1  riastrad  * cik_mm_wdoorbell - write a doorbell dword
   1761  1.1  riastrad  *
   1762  1.1  riastrad  * @rdev: radeon_device pointer
   1763  1.1  riastrad  * @index: doorbell index
   1764  1.1  riastrad  * @v: value to write
   1765  1.1  riastrad  *
   1766  1.1  riastrad  * Writes @v to the doorbell aperture at the
   1767  1.1  riastrad  * requested doorbell index (CIK).
   1768  1.1  riastrad  */
   1769  1.1  riastrad void cik_mm_wdoorbell(struct radeon_device *rdev, u32 index, u32 v)
   1770  1.1  riastrad {
   1771  1.1  riastrad 	if (index < rdev->doorbell.num_doorbells) {
   1772  1.1  riastrad #ifdef __NetBSD__
   1773  1.1  riastrad 		bus_space_write_4(rdev->doorbell.bst, rdev->doorbell.bsh,
   1774  1.1  riastrad 		    index*4, v);
   1775  1.1  riastrad #else
   1776  1.1  riastrad 		writel(v, rdev->doorbell.ptr + index);
   1777  1.1  riastrad #endif
   1778  1.1  riastrad 	} else {
   1779  1.1  riastrad 		DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
   1780  1.1  riastrad 	}
   1781  1.1  riastrad }
   1782  1.1  riastrad 
   1783  1.1  riastrad #define BONAIRE_IO_MC_REGS_SIZE 36
   1784  1.1  riastrad 
   1785  1.1  riastrad static const u32 bonaire_io_mc_regs[BONAIRE_IO_MC_REGS_SIZE][2] =
   1786  1.1  riastrad {
   1787  1.1  riastrad 	{0x00000070, 0x04400000},
   1788  1.1  riastrad 	{0x00000071, 0x80c01803},
   1789  1.1  riastrad 	{0x00000072, 0x00004004},
   1790  1.1  riastrad 	{0x00000073, 0x00000100},
   1791  1.1  riastrad 	{0x00000074, 0x00ff0000},
   1792  1.1  riastrad 	{0x00000075, 0x34000000},
   1793  1.1  riastrad 	{0x00000076, 0x08000014},
   1794  1.1  riastrad 	{0x00000077, 0x00cc08ec},
   1795  1.1  riastrad 	{0x00000078, 0x00000400},
   1796  1.1  riastrad 	{0x00000079, 0x00000000},
   1797  1.1  riastrad 	{0x0000007a, 0x04090000},
   1798  1.1  riastrad 	{0x0000007c, 0x00000000},
   1799  1.1  riastrad 	{0x0000007e, 0x4408a8e8},
   1800  1.1  riastrad 	{0x0000007f, 0x00000304},
   1801  1.1  riastrad 	{0x00000080, 0x00000000},
   1802  1.1  riastrad 	{0x00000082, 0x00000001},
   1803  1.1  riastrad 	{0x00000083, 0x00000002},
   1804  1.1  riastrad 	{0x00000084, 0xf3e4f400},
   1805  1.1  riastrad 	{0x00000085, 0x052024e3},
   1806  1.1  riastrad 	{0x00000087, 0x00000000},
   1807  1.1  riastrad 	{0x00000088, 0x01000000},
   1808  1.1  riastrad 	{0x0000008a, 0x1c0a0000},
   1809  1.1  riastrad 	{0x0000008b, 0xff010000},
   1810  1.1  riastrad 	{0x0000008d, 0xffffefff},
   1811  1.1  riastrad 	{0x0000008e, 0xfff3efff},
   1812  1.1  riastrad 	{0x0000008f, 0xfff3efbf},
   1813  1.1  riastrad 	{0x00000092, 0xf7ffffff},
   1814  1.1  riastrad 	{0x00000093, 0xffffff7f},
   1815  1.1  riastrad 	{0x00000095, 0x00101101},
   1816  1.1  riastrad 	{0x00000096, 0x00000fff},
   1817  1.1  riastrad 	{0x00000097, 0x00116fff},
   1818  1.1  riastrad 	{0x00000098, 0x60010000},
   1819  1.1  riastrad 	{0x00000099, 0x10010000},
   1820  1.1  riastrad 	{0x0000009a, 0x00006000},
   1821  1.1  riastrad 	{0x0000009b, 0x00001000},
   1822  1.1  riastrad 	{0x0000009f, 0x00b48000}
   1823  1.1  riastrad };
   1824  1.1  riastrad 
   1825  1.1  riastrad #define HAWAII_IO_MC_REGS_SIZE 22
   1826  1.1  riastrad 
   1827  1.1  riastrad static const u32 hawaii_io_mc_regs[HAWAII_IO_MC_REGS_SIZE][2] =
   1828  1.1  riastrad {
   1829  1.1  riastrad 	{0x0000007d, 0x40000000},
   1830  1.1  riastrad 	{0x0000007e, 0x40180304},
   1831  1.1  riastrad 	{0x0000007f, 0x0000ff00},
   1832  1.1  riastrad 	{0x00000081, 0x00000000},
   1833  1.1  riastrad 	{0x00000083, 0x00000800},
   1834  1.1  riastrad 	{0x00000086, 0x00000000},
   1835  1.1  riastrad 	{0x00000087, 0x00000100},
   1836  1.1  riastrad 	{0x00000088, 0x00020100},
   1837  1.1  riastrad 	{0x00000089, 0x00000000},
   1838  1.1  riastrad 	{0x0000008b, 0x00040000},
   1839  1.1  riastrad 	{0x0000008c, 0x00000100},
   1840  1.1  riastrad 	{0x0000008e, 0xff010000},
   1841  1.1  riastrad 	{0x00000090, 0xffffefff},
   1842  1.1  riastrad 	{0x00000091, 0xfff3efff},
   1843  1.1  riastrad 	{0x00000092, 0xfff3efbf},
   1844  1.1  riastrad 	{0x00000093, 0xf7ffffff},
   1845  1.1  riastrad 	{0x00000094, 0xffffff7f},
   1846  1.1  riastrad 	{0x00000095, 0x00000fff},
   1847  1.1  riastrad 	{0x00000096, 0x00116fff},
   1848  1.1  riastrad 	{0x00000097, 0x60010000},
   1849  1.1  riastrad 	{0x00000098, 0x10010000},
   1850  1.1  riastrad 	{0x0000009f, 0x00c79000}
   1851  1.1  riastrad };
   1852  1.1  riastrad 
   1853  1.1  riastrad 
   1854  1.1  riastrad /**
   1855  1.1  riastrad  * cik_srbm_select - select specific register instances
   1856  1.1  riastrad  *
   1857  1.1  riastrad  * @rdev: radeon_device pointer
   1858  1.1  riastrad  * @me: selected ME (micro engine)
   1859  1.1  riastrad  * @pipe: pipe
   1860  1.1  riastrad  * @queue: queue
   1861  1.1  riastrad  * @vmid: VMID
   1862  1.1  riastrad  *
   1863  1.1  riastrad  * Switches the currently active registers instances.  Some
   1864  1.1  riastrad  * registers are instanced per VMID, others are instanced per
   1865  1.1  riastrad  * me/pipe/queue combination.
   1866  1.1  riastrad  */
   1867  1.1  riastrad static void cik_srbm_select(struct radeon_device *rdev,
   1868  1.1  riastrad 			    u32 me, u32 pipe, u32 queue, u32 vmid)
   1869  1.1  riastrad {
   1870  1.1  riastrad 	u32 srbm_gfx_cntl = (PIPEID(pipe & 0x3) |
   1871  1.1  riastrad 			     MEID(me & 0x3) |
   1872  1.1  riastrad 			     VMID(vmid & 0xf) |
   1873  1.1  riastrad 			     QUEUEID(queue & 0x7));
   1874  1.1  riastrad 	WREG32(SRBM_GFX_CNTL, srbm_gfx_cntl);
   1875  1.1  riastrad }
   1876  1.1  riastrad 
   1877  1.1  riastrad /* ucode loading */
   1878  1.1  riastrad /**
   1879  1.1  riastrad  * ci_mc_load_microcode - load MC ucode into the hw
   1880  1.1  riastrad  *
   1881  1.1  riastrad  * @rdev: radeon_device pointer
   1882  1.1  riastrad  *
   1883  1.1  riastrad  * Load the GDDR MC ucode into the hw (CIK).
   1884  1.1  riastrad  * Returns 0 on success, error on failure.
   1885  1.1  riastrad  */
   1886  1.1  riastrad int ci_mc_load_microcode(struct radeon_device *rdev)
   1887  1.1  riastrad {
   1888  1.1  riastrad 	const __be32 *fw_data = NULL;
   1889  1.1  riastrad 	const __le32 *new_fw_data = NULL;
   1890  1.3  riastrad 	u32 running, tmp;
   1891  1.6  riastrad 	const u32 *io_mc_regs = NULL;
   1892  1.1  riastrad 	const __le32 *new_io_mc_regs = NULL;
   1893  1.1  riastrad 	int i, regs_size, ucode_size;
   1894  1.1  riastrad 
   1895  1.1  riastrad 	if (!rdev->mc_fw)
   1896  1.1  riastrad 		return -EINVAL;
   1897  1.1  riastrad 
   1898  1.1  riastrad 	if (rdev->new_fw) {
   1899  1.1  riastrad 		const struct mc_firmware_header_v1_0 *hdr =
   1900  1.1  riastrad 			(const struct mc_firmware_header_v1_0 *)rdev->mc_fw->data;
   1901  1.1  riastrad 
   1902  1.1  riastrad 		radeon_ucode_print_mc_hdr(&hdr->header);
   1903  1.1  riastrad 
   1904  1.1  riastrad 		regs_size = le32_to_cpu(hdr->io_debug_size_bytes) / (4 * 2);
   1905  1.1  riastrad 		new_io_mc_regs = (const __le32 *)
   1906  1.1  riastrad 			(rdev->mc_fw->data + le32_to_cpu(hdr->io_debug_array_offset_bytes));
   1907  1.1  riastrad 		ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
   1908  1.1  riastrad 		new_fw_data = (const __le32 *)
   1909  1.1  riastrad 			(rdev->mc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
   1910  1.1  riastrad 	} else {
   1911  1.1  riastrad 		ucode_size = rdev->mc_fw->size / 4;
   1912  1.1  riastrad 
   1913  1.1  riastrad 		switch (rdev->family) {
   1914  1.1  riastrad 		case CHIP_BONAIRE:
   1915  1.1  riastrad 			io_mc_regs = &bonaire_io_mc_regs[0][0];
   1916  1.1  riastrad 			regs_size = BONAIRE_IO_MC_REGS_SIZE;
   1917  1.1  riastrad 			break;
   1918  1.1  riastrad 		case CHIP_HAWAII:
   1919  1.1  riastrad 			io_mc_regs = &hawaii_io_mc_regs[0][0];
   1920  1.1  riastrad 			regs_size = HAWAII_IO_MC_REGS_SIZE;
   1921  1.1  riastrad 			break;
   1922  1.1  riastrad 		default:
   1923  1.1  riastrad 			return -EINVAL;
   1924  1.1  riastrad 		}
   1925  1.1  riastrad 		fw_data = (const __be32 *)rdev->mc_fw->data;
   1926  1.1  riastrad 	}
   1927  1.1  riastrad 
   1928  1.1  riastrad 	running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
   1929  1.1  riastrad 
   1930  1.1  riastrad 	if (running == 0) {
   1931  1.1  riastrad 		/* reset the engine and set to writable */
   1932  1.1  riastrad 		WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
   1933  1.1  riastrad 		WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
   1934  1.1  riastrad 
   1935  1.1  riastrad 		/* load mc io regs */
   1936  1.1  riastrad 		for (i = 0; i < regs_size; i++) {
   1937  1.1  riastrad 			if (rdev->new_fw) {
   1938  1.1  riastrad 				WREG32(MC_SEQ_IO_DEBUG_INDEX, le32_to_cpup(new_io_mc_regs++));
   1939  1.1  riastrad 				WREG32(MC_SEQ_IO_DEBUG_DATA, le32_to_cpup(new_io_mc_regs++));
   1940  1.1  riastrad 			} else {
   1941  1.1  riastrad 				WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
   1942  1.1  riastrad 				WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
   1943  1.1  riastrad 			}
   1944  1.1  riastrad 		}
   1945  1.1  riastrad 
   1946  1.1  riastrad 		tmp = RREG32(MC_SEQ_MISC0);
   1947  1.1  riastrad 		if ((rdev->pdev->device == 0x6649) && ((tmp & 0xff00) == 0x5600)) {
   1948  1.1  riastrad 			WREG32(MC_SEQ_IO_DEBUG_INDEX, 5);
   1949  1.1  riastrad 			WREG32(MC_SEQ_IO_DEBUG_DATA, 0x00000023);
   1950  1.1  riastrad 			WREG32(MC_SEQ_IO_DEBUG_INDEX, 9);
   1951  1.1  riastrad 			WREG32(MC_SEQ_IO_DEBUG_DATA, 0x000001f0);
   1952  1.1  riastrad 		}
   1953  1.1  riastrad 
   1954  1.1  riastrad 		/* load the MC ucode */
   1955  1.1  riastrad 		for (i = 0; i < ucode_size; i++) {
   1956  1.1  riastrad 			if (rdev->new_fw)
   1957  1.1  riastrad 				WREG32(MC_SEQ_SUP_PGM, le32_to_cpup(new_fw_data++));
   1958  1.1  riastrad 			else
   1959  1.1  riastrad 				WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
   1960  1.1  riastrad 		}
   1961  1.1  riastrad 
   1962  1.1  riastrad 		/* put the engine back into the active state */
   1963  1.1  riastrad 		WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
   1964  1.1  riastrad 		WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
   1965  1.1  riastrad 		WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
   1966  1.1  riastrad 
   1967  1.1  riastrad 		/* wait for training to complete */
   1968  1.1  riastrad 		for (i = 0; i < rdev->usec_timeout; i++) {
   1969  1.1  riastrad 			if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D0)
   1970  1.1  riastrad 				break;
   1971  1.1  riastrad 			udelay(1);
   1972  1.1  riastrad 		}
   1973  1.1  riastrad 		for (i = 0; i < rdev->usec_timeout; i++) {
   1974  1.1  riastrad 			if (RREG32(MC_SEQ_TRAIN_WAKEUP_CNTL) & TRAIN_DONE_D1)
   1975  1.1  riastrad 				break;
   1976  1.1  riastrad 			udelay(1);
   1977  1.1  riastrad 		}
   1978  1.1  riastrad 	}
   1979  1.1  riastrad 
   1980  1.1  riastrad 	return 0;
   1981  1.1  riastrad }
   1982  1.1  riastrad 
   1983  1.1  riastrad /**
   1984  1.1  riastrad  * cik_init_microcode - load ucode images from disk
   1985  1.1  riastrad  *
   1986  1.1  riastrad  * @rdev: radeon_device pointer
   1987  1.1  riastrad  *
   1988  1.1  riastrad  * Use the firmware interface to load the ucode images into
   1989  1.1  riastrad  * the driver (not loaded into hw).
   1990  1.1  riastrad  * Returns 0 on success, error on failure.
   1991  1.1  riastrad  */
   1992  1.1  riastrad static int cik_init_microcode(struct radeon_device *rdev)
   1993  1.1  riastrad {
   1994  1.1  riastrad 	const char *chip_name;
   1995  1.1  riastrad 	const char *new_chip_name;
   1996  1.1  riastrad 	size_t pfp_req_size, me_req_size, ce_req_size,
   1997  1.1  riastrad 		mec_req_size, rlc_req_size, mc_req_size = 0,
   1998  1.1  riastrad 		sdma_req_size, smc_req_size = 0, mc2_req_size = 0;
   1999  1.1  riastrad 	char fw_name[30];
   2000  1.1  riastrad 	int new_fw = 0;
   2001  1.1  riastrad 	int err;
   2002  1.1  riastrad 	int num_fw;
   2003  1.3  riastrad 	bool new_smc = false;
   2004  1.1  riastrad 
   2005  1.1  riastrad 	DRM_DEBUG("\n");
   2006  1.1  riastrad 
   2007  1.1  riastrad 	switch (rdev->family) {
   2008  1.1  riastrad 	case CHIP_BONAIRE:
   2009  1.1  riastrad 		chip_name = "BONAIRE";
   2010  1.3  riastrad 		if ((rdev->pdev->revision == 0x80) ||
   2011  1.3  riastrad 		    (rdev->pdev->revision == 0x81) ||
   2012  1.3  riastrad 		    (rdev->pdev->device == 0x665f))
   2013  1.3  riastrad 			new_smc = true;
   2014  1.1  riastrad 		new_chip_name = "bonaire";
   2015  1.1  riastrad 		pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
   2016  1.1  riastrad 		me_req_size = CIK_ME_UCODE_SIZE * 4;
   2017  1.1  riastrad 		ce_req_size = CIK_CE_UCODE_SIZE * 4;
   2018  1.1  riastrad 		mec_req_size = CIK_MEC_UCODE_SIZE * 4;
   2019  1.1  riastrad 		rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
   2020  1.1  riastrad 		mc_req_size = BONAIRE_MC_UCODE_SIZE * 4;
   2021  1.1  riastrad 		mc2_req_size = BONAIRE_MC2_UCODE_SIZE * 4;
   2022  1.1  riastrad 		sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
   2023  1.5  riastrad 		smc_req_size = round_up(BONAIRE_SMC_UCODE_SIZE, 4);
   2024  1.1  riastrad 		num_fw = 8;
   2025  1.1  riastrad 		break;
   2026  1.1  riastrad 	case CHIP_HAWAII:
   2027  1.1  riastrad 		chip_name = "HAWAII";
   2028  1.3  riastrad 		if (rdev->pdev->revision == 0x80)
   2029  1.3  riastrad 			new_smc = true;
   2030  1.1  riastrad 		new_chip_name = "hawaii";
   2031  1.1  riastrad 		pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
   2032  1.1  riastrad 		me_req_size = CIK_ME_UCODE_SIZE * 4;
   2033  1.1  riastrad 		ce_req_size = CIK_CE_UCODE_SIZE * 4;
   2034  1.1  riastrad 		mec_req_size = CIK_MEC_UCODE_SIZE * 4;
   2035  1.1  riastrad 		rlc_req_size = BONAIRE_RLC_UCODE_SIZE * 4;
   2036  1.1  riastrad 		mc_req_size = HAWAII_MC_UCODE_SIZE * 4;
   2037  1.1  riastrad 		mc2_req_size = HAWAII_MC2_UCODE_SIZE * 4;
   2038  1.1  riastrad 		sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
   2039  1.5  riastrad 		smc_req_size = round_up(HAWAII_SMC_UCODE_SIZE, 4);
   2040  1.1  riastrad 		num_fw = 8;
   2041  1.1  riastrad 		break;
   2042  1.1  riastrad 	case CHIP_KAVERI:
   2043  1.1  riastrad 		chip_name = "KAVERI";
   2044  1.1  riastrad 		new_chip_name = "kaveri";
   2045  1.1  riastrad 		pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
   2046  1.1  riastrad 		me_req_size = CIK_ME_UCODE_SIZE * 4;
   2047  1.1  riastrad 		ce_req_size = CIK_CE_UCODE_SIZE * 4;
   2048  1.1  riastrad 		mec_req_size = CIK_MEC_UCODE_SIZE * 4;
   2049  1.1  riastrad 		rlc_req_size = KV_RLC_UCODE_SIZE * 4;
   2050  1.1  riastrad 		sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
   2051  1.1  riastrad 		num_fw = 7;
   2052  1.1  riastrad 		break;
   2053  1.1  riastrad 	case CHIP_KABINI:
   2054  1.1  riastrad 		chip_name = "KABINI";
   2055  1.1  riastrad 		new_chip_name = "kabini";
   2056  1.1  riastrad 		pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
   2057  1.1  riastrad 		me_req_size = CIK_ME_UCODE_SIZE * 4;
   2058  1.1  riastrad 		ce_req_size = CIK_CE_UCODE_SIZE * 4;
   2059  1.1  riastrad 		mec_req_size = CIK_MEC_UCODE_SIZE * 4;
   2060  1.1  riastrad 		rlc_req_size = KB_RLC_UCODE_SIZE * 4;
   2061  1.1  riastrad 		sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
   2062  1.1  riastrad 		num_fw = 6;
   2063  1.1  riastrad 		break;
   2064  1.1  riastrad 	case CHIP_MULLINS:
   2065  1.1  riastrad 		chip_name = "MULLINS";
   2066  1.1  riastrad 		new_chip_name = "mullins";
   2067  1.1  riastrad 		pfp_req_size = CIK_PFP_UCODE_SIZE * 4;
   2068  1.1  riastrad 		me_req_size = CIK_ME_UCODE_SIZE * 4;
   2069  1.1  riastrad 		ce_req_size = CIK_CE_UCODE_SIZE * 4;
   2070  1.1  riastrad 		mec_req_size = CIK_MEC_UCODE_SIZE * 4;
   2071  1.1  riastrad 		rlc_req_size = ML_RLC_UCODE_SIZE * 4;
   2072  1.1  riastrad 		sdma_req_size = CIK_SDMA_UCODE_SIZE * 4;
   2073  1.1  riastrad 		num_fw = 6;
   2074  1.1  riastrad 		break;
   2075  1.1  riastrad 	default: BUG();
   2076  1.1  riastrad 	}
   2077  1.1  riastrad 
   2078  1.1  riastrad 	DRM_INFO("Loading %s Microcode\n", new_chip_name);
   2079  1.1  riastrad 
   2080  1.1  riastrad 	snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", new_chip_name);
   2081  1.1  riastrad 	err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
   2082  1.1  riastrad 	if (err) {
   2083  1.1  riastrad 		snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
   2084  1.1  riastrad 		err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
   2085  1.1  riastrad 		if (err)
   2086  1.1  riastrad 			goto out;
   2087  1.1  riastrad 		if (rdev->pfp_fw->size != pfp_req_size) {
   2088  1.3  riastrad 			pr_err("cik_cp: Bogus length %zu in firmware \"%s\"\n",
   2089  1.1  riastrad 			       rdev->pfp_fw->size, fw_name);
   2090  1.1  riastrad 			err = -EINVAL;
   2091  1.1  riastrad 			goto out;
   2092  1.1  riastrad 		}
   2093  1.1  riastrad 	} else {
   2094  1.1  riastrad 		err = radeon_ucode_validate(rdev->pfp_fw);
   2095  1.1  riastrad 		if (err) {
   2096  1.3  riastrad 			pr_err("cik_fw: validation failed for firmware \"%s\"\n",
   2097  1.1  riastrad 			       fw_name);
   2098  1.1  riastrad 			goto out;
   2099  1.1  riastrad 		} else {
   2100  1.1  riastrad 			new_fw++;
   2101  1.1  riastrad 		}
   2102  1.1  riastrad 	}
   2103  1.1  riastrad 
   2104  1.1  riastrad 	snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", new_chip_name);
   2105  1.1  riastrad 	err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
   2106  1.1  riastrad 	if (err) {
   2107  1.1  riastrad 		snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
   2108  1.1  riastrad 		err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
   2109  1.1  riastrad 		if (err)
   2110  1.1  riastrad 			goto out;
   2111  1.1  riastrad 		if (rdev->me_fw->size != me_req_size) {
   2112  1.3  riastrad 			pr_err("cik_cp: Bogus length %zu in firmware \"%s\"\n",
   2113  1.1  riastrad 			       rdev->me_fw->size, fw_name);
   2114  1.1  riastrad 			err = -EINVAL;
   2115  1.1  riastrad 		}
   2116  1.1  riastrad 	} else {
   2117  1.1  riastrad 		err = radeon_ucode_validate(rdev->me_fw);
   2118  1.1  riastrad 		if (err) {
   2119  1.3  riastrad 			pr_err("cik_fw: validation failed for firmware \"%s\"\n",
   2120  1.1  riastrad 			       fw_name);
   2121  1.1  riastrad 			goto out;
   2122  1.1  riastrad 		} else {
   2123  1.1  riastrad 			new_fw++;
   2124  1.1  riastrad 		}
   2125  1.1  riastrad 	}
   2126  1.1  riastrad 
   2127  1.1  riastrad 	snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", new_chip_name);
   2128  1.1  riastrad 	err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
   2129  1.1  riastrad 	if (err) {
   2130  1.1  riastrad 		snprintf(fw_name, sizeof(fw_name), "radeon/%s_ce.bin", chip_name);
   2131  1.1  riastrad 		err = request_firmware(&rdev->ce_fw, fw_name, rdev->dev);
   2132  1.1  riastrad 		if (err)
   2133  1.1  riastrad 			goto out;
   2134  1.1  riastrad 		if (rdev->ce_fw->size != ce_req_size) {
   2135  1.3  riastrad 			pr_err("cik_cp: Bogus length %zu in firmware \"%s\"\n",
   2136  1.1  riastrad 			       rdev->ce_fw->size, fw_name);
   2137  1.1  riastrad 			err = -EINVAL;
   2138  1.1  riastrad 		}
   2139  1.1  riastrad 	} else {
   2140  1.1  riastrad 		err = radeon_ucode_validate(rdev->ce_fw);
   2141  1.1  riastrad 		if (err) {
   2142  1.3  riastrad 			pr_err("cik_fw: validation failed for firmware \"%s\"\n",
   2143  1.1  riastrad 			       fw_name);
   2144  1.1  riastrad 			goto out;
   2145  1.1  riastrad 		} else {
   2146  1.1  riastrad 			new_fw++;
   2147  1.1  riastrad 		}
   2148  1.1  riastrad 	}
   2149  1.1  riastrad 
   2150  1.1  riastrad 	snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec.bin", new_chip_name);
   2151  1.1  riastrad 	err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
   2152  1.1  riastrad 	if (err) {
   2153  1.1  riastrad 		snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec.bin", chip_name);
   2154  1.1  riastrad 		err = request_firmware(&rdev->mec_fw, fw_name, rdev->dev);
   2155  1.1  riastrad 		if (err)
   2156  1.1  riastrad 			goto out;
   2157  1.1  riastrad 		if (rdev->mec_fw->size != mec_req_size) {
   2158  1.3  riastrad 			pr_err("cik_cp: Bogus length %zu in firmware \"%s\"\n",
   2159  1.1  riastrad 			       rdev->mec_fw->size, fw_name);
   2160  1.1  riastrad 			err = -EINVAL;
   2161  1.1  riastrad 		}
   2162  1.1  riastrad 	} else {
   2163  1.1  riastrad 		err = radeon_ucode_validate(rdev->mec_fw);
   2164  1.1  riastrad 		if (err) {
   2165  1.3  riastrad 			pr_err("cik_fw: validation failed for firmware \"%s\"\n",
   2166  1.1  riastrad 			       fw_name);
   2167  1.1  riastrad 			goto out;
   2168  1.1  riastrad 		} else {
   2169  1.1  riastrad 			new_fw++;
   2170  1.1  riastrad 		}
   2171  1.1  riastrad 	}
   2172  1.1  riastrad 
   2173  1.1  riastrad 	if (rdev->family == CHIP_KAVERI) {
   2174  1.1  riastrad 		snprintf(fw_name, sizeof(fw_name), "radeon/%s_mec2.bin", new_chip_name);
   2175  1.1  riastrad 		err = request_firmware(&rdev->mec2_fw, fw_name, rdev->dev);
   2176  1.1  riastrad 		if (err) {
   2177  1.1  riastrad 			goto out;
   2178  1.1  riastrad 		} else {
   2179  1.1  riastrad 			err = radeon_ucode_validate(rdev->mec2_fw);
   2180  1.1  riastrad 			if (err) {
   2181  1.1  riastrad 				goto out;
   2182  1.1  riastrad 			} else {
   2183  1.1  riastrad 				new_fw++;
   2184  1.1  riastrad 			}
   2185  1.1  riastrad 		}
   2186  1.1  riastrad 	}
   2187  1.1  riastrad 
   2188  1.1  riastrad 	snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", new_chip_name);
   2189  1.1  riastrad 	err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
   2190  1.1  riastrad 	if (err) {
   2191  1.1  riastrad 		snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", chip_name);
   2192  1.1  riastrad 		err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
   2193  1.1  riastrad 		if (err)
   2194  1.1  riastrad 			goto out;
   2195  1.1  riastrad 		if (rdev->rlc_fw->size != rlc_req_size) {
   2196  1.3  riastrad 			pr_err("cik_rlc: Bogus length %zu in firmware \"%s\"\n",
   2197  1.1  riastrad 			       rdev->rlc_fw->size, fw_name);
   2198  1.1  riastrad 			err = -EINVAL;
   2199  1.1  riastrad 		}
   2200  1.1  riastrad 	} else {
   2201  1.1  riastrad 		err = radeon_ucode_validate(rdev->rlc_fw);
   2202  1.1  riastrad 		if (err) {
   2203  1.3  riastrad 			pr_err("cik_fw: validation failed for firmware \"%s\"\n",
   2204  1.1  riastrad 			       fw_name);
   2205  1.1  riastrad 			goto out;
   2206  1.1  riastrad 		} else {
   2207  1.1  riastrad 			new_fw++;
   2208  1.1  riastrad 		}
   2209  1.1  riastrad 	}
   2210  1.1  riastrad 
   2211  1.1  riastrad 	snprintf(fw_name, sizeof(fw_name), "radeon/%s_sdma.bin", new_chip_name);
   2212  1.1  riastrad 	err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
   2213  1.1  riastrad 	if (err) {
   2214  1.1  riastrad 		snprintf(fw_name, sizeof(fw_name), "radeon/%s_sdma.bin", chip_name);
   2215  1.1  riastrad 		err = request_firmware(&rdev->sdma_fw, fw_name, rdev->dev);
   2216  1.1  riastrad 		if (err)
   2217  1.1  riastrad 			goto out;
   2218  1.1  riastrad 		if (rdev->sdma_fw->size != sdma_req_size) {
   2219  1.3  riastrad 			pr_err("cik_sdma: Bogus length %zu in firmware \"%s\"\n",
   2220  1.1  riastrad 			       rdev->sdma_fw->size, fw_name);
   2221  1.1  riastrad 			err = -EINVAL;
   2222  1.1  riastrad 		}
   2223  1.1  riastrad 	} else {
   2224  1.1  riastrad 		err = radeon_ucode_validate(rdev->sdma_fw);
   2225  1.1  riastrad 		if (err) {
   2226  1.3  riastrad 			pr_err("cik_fw: validation failed for firmware \"%s\"\n",
   2227  1.1  riastrad 			       fw_name);
   2228  1.1  riastrad 			goto out;
   2229  1.1  riastrad 		} else {
   2230  1.1  riastrad 			new_fw++;
   2231  1.1  riastrad 		}
   2232  1.1  riastrad 	}
   2233  1.1  riastrad 
   2234  1.1  riastrad 	/* No SMC, MC ucode on APUs */
   2235  1.1  riastrad 	if (!(rdev->flags & RADEON_IS_IGP)) {
   2236  1.1  riastrad 		snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", new_chip_name);
   2237  1.1  riastrad 		err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
   2238  1.1  riastrad 		if (err) {
   2239  1.1  riastrad 			snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc2.bin", chip_name);
   2240  1.1  riastrad 			err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
   2241  1.1  riastrad 			if (err) {
   2242  1.1  riastrad 				snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
   2243  1.1  riastrad 				err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
   2244  1.1  riastrad 				if (err)
   2245  1.1  riastrad 					goto out;
   2246  1.1  riastrad 			}
   2247  1.1  riastrad 			if ((rdev->mc_fw->size != mc_req_size) &&
   2248  1.1  riastrad 			    (rdev->mc_fw->size != mc2_req_size)){
   2249  1.3  riastrad 				pr_err("cik_mc: Bogus length %zu in firmware \"%s\"\n",
   2250  1.1  riastrad 				       rdev->mc_fw->size, fw_name);
   2251  1.1  riastrad 				err = -EINVAL;
   2252  1.1  riastrad 			}
   2253  1.1  riastrad 			DRM_INFO("%s: %zu bytes\n", fw_name, rdev->mc_fw->size);
   2254  1.1  riastrad 		} else {
   2255  1.1  riastrad 			err = radeon_ucode_validate(rdev->mc_fw);
   2256  1.1  riastrad 			if (err) {
   2257  1.3  riastrad 				pr_err("cik_fw: validation failed for firmware \"%s\"\n",
   2258  1.1  riastrad 				       fw_name);
   2259  1.1  riastrad 				goto out;
   2260  1.1  riastrad 			} else {
   2261  1.1  riastrad 				new_fw++;
   2262  1.1  riastrad 			}
   2263  1.1  riastrad 		}
   2264  1.1  riastrad 
   2265  1.3  riastrad 		if (new_smc)
   2266  1.3  riastrad 			snprintf(fw_name, sizeof(fw_name), "radeon/%s_k_smc.bin", new_chip_name);
   2267  1.3  riastrad 		else
   2268  1.3  riastrad 			snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", new_chip_name);
   2269  1.1  riastrad 		err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
   2270  1.1  riastrad 		if (err) {
   2271  1.1  riastrad 			snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name);
   2272  1.1  riastrad 			err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
   2273  1.1  riastrad 			if (err) {
   2274  1.3  riastrad 				pr_err("smc: error loading firmware \"%s\"\n",
   2275  1.1  riastrad 				       fw_name);
   2276  1.1  riastrad 				release_firmware(rdev->smc_fw);
   2277  1.1  riastrad 				rdev->smc_fw = NULL;
   2278  1.1  riastrad 				err = 0;
   2279  1.1  riastrad 			} else if (rdev->smc_fw->size != smc_req_size) {
   2280  1.3  riastrad 				pr_err("cik_smc: Bogus length %zu in firmware \"%s\"\n",
   2281  1.1  riastrad 				       rdev->smc_fw->size, fw_name);
   2282  1.1  riastrad 				err = -EINVAL;
   2283  1.1  riastrad 			}
   2284  1.1  riastrad 		} else {
   2285  1.1  riastrad 			err = radeon_ucode_validate(rdev->smc_fw);
   2286  1.1  riastrad 			if (err) {
   2287  1.3  riastrad 				pr_err("cik_fw: validation failed for firmware \"%s\"\n",
   2288  1.1  riastrad 				       fw_name);
   2289  1.1  riastrad 				goto out;
   2290  1.1  riastrad 			} else {
   2291  1.1  riastrad 				new_fw++;
   2292  1.1  riastrad 			}
   2293  1.1  riastrad 		}
   2294  1.1  riastrad 	}
   2295  1.1  riastrad 
   2296  1.1  riastrad 	if (new_fw == 0) {
   2297  1.1  riastrad 		rdev->new_fw = false;
   2298  1.1  riastrad 	} else if (new_fw < num_fw) {
   2299  1.3  riastrad 		pr_err("ci_fw: mixing new and old firmware!\n");
   2300  1.1  riastrad 		err = -EINVAL;
   2301  1.1  riastrad 	} else {
   2302  1.1  riastrad 		rdev->new_fw = true;
   2303  1.1  riastrad 	}
   2304  1.1  riastrad 
   2305  1.1  riastrad out:
   2306  1.1  riastrad 	if (err) {
   2307  1.1  riastrad 		if (err != -EINVAL)
   2308  1.3  riastrad 			pr_err("cik_cp: Failed to load firmware \"%s\"\n",
   2309  1.1  riastrad 			       fw_name);
   2310  1.1  riastrad 		release_firmware(rdev->pfp_fw);
   2311  1.1  riastrad 		rdev->pfp_fw = NULL;
   2312  1.1  riastrad 		release_firmware(rdev->me_fw);
   2313  1.1  riastrad 		rdev->me_fw = NULL;
   2314  1.1  riastrad 		release_firmware(rdev->ce_fw);
   2315  1.1  riastrad 		rdev->ce_fw = NULL;
   2316  1.1  riastrad 		release_firmware(rdev->mec_fw);
   2317  1.1  riastrad 		rdev->mec_fw = NULL;
   2318  1.1  riastrad 		release_firmware(rdev->mec2_fw);
   2319  1.1  riastrad 		rdev->mec2_fw = NULL;
   2320  1.1  riastrad 		release_firmware(rdev->rlc_fw);
   2321  1.1  riastrad 		rdev->rlc_fw = NULL;
   2322  1.1  riastrad 		release_firmware(rdev->sdma_fw);
   2323  1.1  riastrad 		rdev->sdma_fw = NULL;
   2324  1.1  riastrad 		release_firmware(rdev->mc_fw);
   2325  1.1  riastrad 		rdev->mc_fw = NULL;
   2326  1.1  riastrad 		release_firmware(rdev->smc_fw);
   2327  1.1  riastrad 		rdev->smc_fw = NULL;
   2328  1.1  riastrad 	}
   2329  1.1  riastrad 	return err;
   2330  1.1  riastrad }
   2331  1.1  riastrad 
   2332  1.1  riastrad /*
   2333  1.1  riastrad  * Core functions
   2334  1.1  riastrad  */
   2335  1.1  riastrad /**
   2336  1.1  riastrad  * cik_tiling_mode_table_init - init the hw tiling table
   2337  1.1  riastrad  *
   2338  1.1  riastrad  * @rdev: radeon_device pointer
   2339  1.1  riastrad  *
   2340  1.1  riastrad  * Starting with SI, the tiling setup is done globally in a
   2341  1.1  riastrad  * set of 32 tiling modes.  Rather than selecting each set of
   2342  1.1  riastrad  * parameters per surface as on older asics, we just select
   2343  1.1  riastrad  * which index in the tiling table we want to use, and the
   2344  1.1  riastrad  * surface uses those parameters (CIK).
   2345  1.1  riastrad  */
   2346  1.1  riastrad static void cik_tiling_mode_table_init(struct radeon_device *rdev)
   2347  1.1  riastrad {
   2348  1.3  riastrad 	u32 *tile = rdev->config.cik.tile_mode_array;
   2349  1.3  riastrad 	u32 *macrotile = rdev->config.cik.macrotile_mode_array;
   2350  1.3  riastrad 	const u32 num_tile_mode_states =
   2351  1.3  riastrad 			ARRAY_SIZE(rdev->config.cik.tile_mode_array);
   2352  1.3  riastrad 	const u32 num_secondary_tile_mode_states =
   2353  1.3  riastrad 			ARRAY_SIZE(rdev->config.cik.macrotile_mode_array);
   2354  1.3  riastrad 	u32 reg_offset, split_equal_to_row_size;
   2355  1.1  riastrad 	u32 num_pipe_configs;
   2356  1.1  riastrad 	u32 num_rbs = rdev->config.cik.max_backends_per_se *
   2357  1.1  riastrad 		rdev->config.cik.max_shader_engines;
   2358  1.1  riastrad 
   2359  1.1  riastrad 	switch (rdev->config.cik.mem_row_size_in_kb) {
   2360  1.1  riastrad 	case 1:
   2361  1.1  riastrad 		split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_1KB;
   2362  1.1  riastrad 		break;
   2363  1.1  riastrad 	case 2:
   2364  1.1  riastrad 	default:
   2365  1.1  riastrad 		split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_2KB;
   2366  1.1  riastrad 		break;
   2367  1.1  riastrad 	case 4:
   2368  1.1  riastrad 		split_equal_to_row_size = ADDR_SURF_TILE_SPLIT_4KB;
   2369  1.1  riastrad 		break;
   2370  1.1  riastrad 	}
   2371  1.1  riastrad 
   2372  1.1  riastrad 	num_pipe_configs = rdev->config.cik.max_tile_pipes;
   2373  1.1  riastrad 	if (num_pipe_configs > 8)
   2374  1.1  riastrad 		num_pipe_configs = 16;
   2375  1.1  riastrad 
   2376  1.3  riastrad 	for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
   2377  1.3  riastrad 		tile[reg_offset] = 0;
   2378  1.3  riastrad 	for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
   2379  1.3  riastrad 		macrotile[reg_offset] = 0;
   2380  1.3  riastrad 
   2381  1.3  riastrad 	switch(num_pipe_configs) {
   2382  1.3  riastrad 	case 16:
   2383  1.3  riastrad 		tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2384  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2385  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2386  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
   2387  1.3  riastrad 		tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2388  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2389  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2390  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
   2391  1.3  riastrad 		tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2392  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2393  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2394  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
   2395  1.3  riastrad 		tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2396  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2397  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2398  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
   2399  1.3  riastrad 		tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2400  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2401  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2402  1.3  riastrad 			   TILE_SPLIT(split_equal_to_row_size));
   2403  1.3  riastrad 		tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2404  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2405  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
   2406  1.3  riastrad 		tile[6] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2407  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2408  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2409  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
   2410  1.3  riastrad 		tile[7] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2411  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2412  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2413  1.3  riastrad 			   TILE_SPLIT(split_equal_to_row_size));
   2414  1.3  riastrad 		tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
   2415  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16));
   2416  1.3  riastrad 		tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2417  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2418  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
   2419  1.3  riastrad 		tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2420  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2421  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2422  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2423  1.3  riastrad 		tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2424  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2425  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
   2426  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2427  1.3  riastrad 		tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2428  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2429  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2430  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2431  1.3  riastrad 		tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2432  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2433  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
   2434  1.3  riastrad 		tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2435  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2436  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2437  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2438  1.3  riastrad 		tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2439  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2440  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
   2441  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2442  1.3  riastrad 		tile[17] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2443  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2444  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2445  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2446  1.3  riastrad 		tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2447  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2448  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
   2449  1.3  riastrad 		tile[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2450  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2451  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2452  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2453  1.3  riastrad 		tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2454  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2455  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_8x16) |
   2456  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2457  1.3  riastrad 		tile[30] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2458  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2459  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P16_32x32_16x16) |
   2460  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2461  1.3  riastrad 
   2462  1.3  riastrad 		macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2463  1.3  riastrad 			   BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
   2464  1.3  riastrad 			   MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2465  1.3  riastrad 			   NUM_BANKS(ADDR_SURF_16_BANK));
   2466  1.3  riastrad 		macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2467  1.3  riastrad 			   BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
   2468  1.3  riastrad 			   MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2469  1.3  riastrad 			   NUM_BANKS(ADDR_SURF_16_BANK));
   2470  1.3  riastrad 		macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2471  1.3  riastrad 			   BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2472  1.3  riastrad 			   MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2473  1.3  riastrad 			   NUM_BANKS(ADDR_SURF_16_BANK));
   2474  1.3  riastrad 		macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2475  1.3  riastrad 			   BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2476  1.3  riastrad 			   MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2477  1.3  riastrad 			   NUM_BANKS(ADDR_SURF_16_BANK));
   2478  1.3  riastrad 		macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2479  1.3  riastrad 			   BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2480  1.3  riastrad 			   MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2481  1.3  riastrad 			   NUM_BANKS(ADDR_SURF_8_BANK));
   2482  1.3  riastrad 		macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2483  1.3  riastrad 			   BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2484  1.3  riastrad 			   MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2485  1.3  riastrad 			   NUM_BANKS(ADDR_SURF_4_BANK));
   2486  1.3  riastrad 		macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2487  1.3  riastrad 			   BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2488  1.3  riastrad 			   MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2489  1.3  riastrad 			   NUM_BANKS(ADDR_SURF_2_BANK));
   2490  1.3  riastrad 		macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2491  1.3  riastrad 			   BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
   2492  1.3  riastrad 			   MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2493  1.3  riastrad 			   NUM_BANKS(ADDR_SURF_16_BANK));
   2494  1.3  riastrad 		macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2495  1.3  riastrad 			   BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
   2496  1.3  riastrad 			   MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2497  1.3  riastrad 			   NUM_BANKS(ADDR_SURF_16_BANK));
   2498  1.3  riastrad 		macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2499  1.3  riastrad 			    BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2500  1.3  riastrad 			    MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2501  1.3  riastrad 			    NUM_BANKS(ADDR_SURF_16_BANK));
   2502  1.3  riastrad 		macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2503  1.3  riastrad 			    BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2504  1.3  riastrad 			    MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2505  1.3  riastrad 			    NUM_BANKS(ADDR_SURF_8_BANK));
   2506  1.3  riastrad 		macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2507  1.3  riastrad 			    BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2508  1.3  riastrad 			    MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2509  1.3  riastrad 			    NUM_BANKS(ADDR_SURF_4_BANK));
   2510  1.3  riastrad 		macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2511  1.3  riastrad 			    BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2512  1.3  riastrad 			    MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2513  1.3  riastrad 			    NUM_BANKS(ADDR_SURF_2_BANK));
   2514  1.3  riastrad 		macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2515  1.3  riastrad 			    BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2516  1.3  riastrad 			    MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2517  1.3  riastrad 			    NUM_BANKS(ADDR_SURF_2_BANK));
   2518  1.3  riastrad 
   2519  1.3  riastrad 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
   2520  1.3  riastrad 			WREG32(GB_TILE_MODE0 + (reg_offset * 4), tile[reg_offset]);
   2521  1.3  riastrad 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
   2522  1.3  riastrad 			WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), macrotile[reg_offset]);
   2523  1.3  riastrad 		break;
   2524  1.3  riastrad 
   2525  1.3  riastrad 	case 8:
   2526  1.3  riastrad 		tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2527  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2528  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2529  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
   2530  1.3  riastrad 		tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2531  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2532  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2533  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
   2534  1.3  riastrad 		tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2535  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2536  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2537  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
   2538  1.3  riastrad 		tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2539  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2540  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2541  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
   2542  1.3  riastrad 		tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2543  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2544  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2545  1.3  riastrad 			   TILE_SPLIT(split_equal_to_row_size));
   2546  1.3  riastrad 		tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2547  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2548  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
   2549  1.3  riastrad 		tile[6] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2550  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2551  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2552  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
   2553  1.3  riastrad 		tile[7] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2554  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2555  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2556  1.3  riastrad 			   TILE_SPLIT(split_equal_to_row_size));
   2557  1.3  riastrad 		tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
   2558  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16));
   2559  1.3  riastrad 		tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2560  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2561  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
   2562  1.3  riastrad 		tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2563  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2564  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2565  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2566  1.3  riastrad 		tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2567  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2568  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
   2569  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2570  1.3  riastrad 		tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2571  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2572  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2573  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2574  1.3  riastrad 		tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2575  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2576  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
   2577  1.3  riastrad 		tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2578  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2579  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2580  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2581  1.3  riastrad 		tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2582  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2583  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
   2584  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2585  1.3  riastrad 		tile[17] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2586  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2587  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2588  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2589  1.3  riastrad 		tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2590  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2591  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
   2592  1.3  riastrad 		tile[28] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2593  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2594  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2595  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2596  1.3  riastrad 		tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2597  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2598  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_8x16) |
   2599  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2600  1.3  riastrad 		tile[30] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2601  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2602  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P8_32x32_16x16) |
   2603  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2604  1.3  riastrad 
   2605  1.3  riastrad 		macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2606  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
   2607  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2608  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2609  1.3  riastrad 		macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2610  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
   2611  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2612  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2613  1.3  riastrad 		macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2614  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2615  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2616  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2617  1.3  riastrad 		macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2618  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2619  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2620  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2621  1.3  riastrad 		macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2622  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2623  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2624  1.3  riastrad 				NUM_BANKS(ADDR_SURF_8_BANK));
   2625  1.3  riastrad 		macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2626  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2627  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2628  1.3  riastrad 				NUM_BANKS(ADDR_SURF_4_BANK));
   2629  1.3  riastrad 		macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2630  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2631  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2632  1.3  riastrad 				NUM_BANKS(ADDR_SURF_2_BANK));
   2633  1.3  riastrad 		macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2634  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
   2635  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2636  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2637  1.3  riastrad 		macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2638  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
   2639  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2640  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2641  1.3  riastrad 		macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2642  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
   2643  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2644  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2645  1.3  riastrad 		macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2646  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2647  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2648  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2649  1.3  riastrad 		macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2650  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2651  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2652  1.3  riastrad 				NUM_BANKS(ADDR_SURF_8_BANK));
   2653  1.3  riastrad 		macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2654  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2655  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2656  1.3  riastrad 				NUM_BANKS(ADDR_SURF_4_BANK));
   2657  1.3  riastrad 		macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2658  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2659  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2660  1.3  riastrad 				NUM_BANKS(ADDR_SURF_2_BANK));
   2661  1.3  riastrad 
   2662  1.3  riastrad 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
   2663  1.3  riastrad 			WREG32(GB_TILE_MODE0 + (reg_offset * 4), tile[reg_offset]);
   2664  1.3  riastrad 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
   2665  1.3  riastrad 			WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), macrotile[reg_offset]);
   2666  1.3  riastrad 		break;
   2667  1.3  riastrad 
   2668  1.3  riastrad 	case 4:
   2669  1.1  riastrad 		if (num_rbs == 4) {
   2670  1.3  riastrad 		tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2671  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2672  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2673  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
   2674  1.3  riastrad 		tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2675  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2676  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2677  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
   2678  1.3  riastrad 		tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2679  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2680  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2681  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
   2682  1.3  riastrad 		tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2683  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2684  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2685  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
   2686  1.3  riastrad 		tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2687  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2688  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2689  1.3  riastrad 			   TILE_SPLIT(split_equal_to_row_size));
   2690  1.3  riastrad 		tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2691  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2692  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
   2693  1.3  riastrad 		tile[6] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2694  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2695  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2696  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
   2697  1.3  riastrad 		tile[7] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2698  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2699  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2700  1.3  riastrad 			   TILE_SPLIT(split_equal_to_row_size));
   2701  1.3  riastrad 		tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
   2702  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_16x16));
   2703  1.3  riastrad 		tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2704  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2705  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
   2706  1.3  riastrad 		tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2707  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2708  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2709  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2710  1.3  riastrad 		tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2711  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2712  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2713  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2714  1.3  riastrad 		tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2715  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2716  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2717  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2718  1.3  riastrad 		tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2719  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2720  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
   2721  1.3  riastrad 		tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2722  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2723  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2724  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2725  1.3  riastrad 		tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2726  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2727  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2728  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2729  1.3  riastrad 		tile[17] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2730  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2731  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2732  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2733  1.3  riastrad 		tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2734  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2735  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
   2736  1.3  riastrad 		tile[28] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2737  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2738  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2739  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2740  1.3  riastrad 		tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2741  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2742  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2743  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2744  1.3  riastrad 		tile[30] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2745  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2746  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_16x16) |
   2747  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2748  1.3  riastrad 
   2749  1.1  riastrad 		} else if (num_rbs < 4) {
   2750  1.3  riastrad 		tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2751  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2752  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2753  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
   2754  1.3  riastrad 		tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2755  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2756  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2757  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
   2758  1.3  riastrad 		tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2759  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2760  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2761  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
   2762  1.3  riastrad 		tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2763  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2764  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2765  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
   2766  1.3  riastrad 		tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2767  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2768  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2769  1.3  riastrad 			   TILE_SPLIT(split_equal_to_row_size));
   2770  1.3  riastrad 		tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2771  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2772  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
   2773  1.3  riastrad 		tile[6] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2774  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2775  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2776  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
   2777  1.3  riastrad 		tile[7] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2778  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2779  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2780  1.3  riastrad 			   TILE_SPLIT(split_equal_to_row_size));
   2781  1.3  riastrad 		tile[8] = (ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
   2782  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_8x16));
   2783  1.3  riastrad 		tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2784  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2785  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING));
   2786  1.3  riastrad 		tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2787  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2788  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2789  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2790  1.3  riastrad 		tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2791  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2792  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2793  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2794  1.3  riastrad 		tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2795  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2796  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2797  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2798  1.3  riastrad 		tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2799  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2800  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
   2801  1.3  riastrad 		tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2802  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2803  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2804  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2805  1.3  riastrad 		tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2806  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2807  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2808  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2809  1.3  riastrad 		tile[17] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2810  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2811  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2812  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2813  1.3  riastrad 		tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2814  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2815  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING));
   2816  1.3  riastrad 		tile[28] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2817  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2818  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2819  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2820  1.3  riastrad 		tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2821  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2822  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2823  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2824  1.3  riastrad 		tile[30] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2825  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2826  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P4_8x16) |
   2827  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2828  1.3  riastrad 		}
   2829  1.3  riastrad 
   2830  1.3  riastrad 		macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2831  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
   2832  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2833  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2834  1.3  riastrad 		macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2835  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
   2836  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2837  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2838  1.3  riastrad 		macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2839  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2840  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2841  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2842  1.3  riastrad 		macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2843  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2844  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2845  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2846  1.3  riastrad 		macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2847  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2848  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2849  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2850  1.3  riastrad 		macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2851  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2852  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2853  1.3  riastrad 				NUM_BANKS(ADDR_SURF_8_BANK));
   2854  1.3  riastrad 		macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2855  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2856  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2857  1.3  riastrad 				NUM_BANKS(ADDR_SURF_4_BANK));
   2858  1.3  riastrad 		macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
   2859  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
   2860  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2861  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2862  1.3  riastrad 		macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
   2863  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
   2864  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2865  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2866  1.3  riastrad 		macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2867  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
   2868  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2869  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2870  1.3  riastrad 		macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2871  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
   2872  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2873  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2874  1.3  riastrad 		macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2875  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2876  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2877  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2878  1.3  riastrad 		macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2879  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2880  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   2881  1.3  riastrad 				NUM_BANKS(ADDR_SURF_8_BANK));
   2882  1.3  riastrad 		macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2883  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2884  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_1) |
   2885  1.3  riastrad 				NUM_BANKS(ADDR_SURF_4_BANK));
   2886  1.3  riastrad 
   2887  1.3  riastrad 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
   2888  1.3  riastrad 			WREG32(GB_TILE_MODE0 + (reg_offset * 4), tile[reg_offset]);
   2889  1.3  riastrad 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
   2890  1.3  riastrad 			WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), macrotile[reg_offset]);
   2891  1.3  riastrad 		break;
   2892  1.3  riastrad 
   2893  1.3  riastrad 	case 2:
   2894  1.3  riastrad 		tile[0] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2895  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2896  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P2) |
   2897  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_64B));
   2898  1.3  riastrad 		tile[1] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2899  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2900  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P2) |
   2901  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_128B));
   2902  1.3  riastrad 		tile[2] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2903  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2904  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P2) |
   2905  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
   2906  1.3  riastrad 		tile[3] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2907  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2908  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P2) |
   2909  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_512B));
   2910  1.3  riastrad 		tile[4] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2911  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2912  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P2) |
   2913  1.3  riastrad 			   TILE_SPLIT(split_equal_to_row_size));
   2914  1.3  riastrad 		tile[5] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2915  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P2) |
   2916  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING));
   2917  1.3  riastrad 		tile[6] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2918  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2919  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P2) |
   2920  1.3  riastrad 			   TILE_SPLIT(ADDR_SURF_TILE_SPLIT_256B));
   2921  1.3  riastrad 		tile[7] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2922  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DEPTH_MICRO_TILING) |
   2923  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P2) |
   2924  1.3  riastrad 			   TILE_SPLIT(split_equal_to_row_size));
   2925  1.3  riastrad 		tile[8] = ARRAY_MODE(ARRAY_LINEAR_ALIGNED) |
   2926  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P2);
   2927  1.3  riastrad 		tile[9] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2928  1.3  riastrad 			   MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2929  1.3  riastrad 			   PIPE_CONFIG(ADDR_SURF_P2));
   2930  1.3  riastrad 		tile[10] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2931  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2932  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2) |
   2933  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2934  1.3  riastrad 		tile[11] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2935  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2936  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2) |
   2937  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2938  1.3  riastrad 		tile[12] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2939  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_DISPLAY_MICRO_TILING) |
   2940  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2) |
   2941  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2942  1.3  riastrad 		tile[13] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2943  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2) |
   2944  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING));
   2945  1.3  riastrad 		tile[14] = (ARRAY_MODE(ARRAY_2D_TILED_THIN1) |
   2946  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2947  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2) |
   2948  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2949  1.3  riastrad 		tile[16] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2950  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2951  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2) |
   2952  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2953  1.3  riastrad 		tile[17] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2954  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_THIN_MICRO_TILING) |
   2955  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2) |
   2956  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2957  1.3  riastrad 		tile[27] = (ARRAY_MODE(ARRAY_1D_TILED_THIN1) |
   2958  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2959  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2));
   2960  1.3  riastrad 		tile[28] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2961  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2962  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2) |
   2963  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2964  1.3  riastrad 		tile[29] = (ARRAY_MODE(ARRAY_PRT_TILED_THIN1) |
   2965  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2966  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2) |
   2967  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2968  1.3  riastrad 		tile[30] = (ARRAY_MODE(ARRAY_PRT_2D_TILED_THIN1) |
   2969  1.3  riastrad 			    MICRO_TILE_MODE_NEW(ADDR_SURF_ROTATED_MICRO_TILING) |
   2970  1.3  riastrad 			    PIPE_CONFIG(ADDR_SURF_P2) |
   2971  1.3  riastrad 			    SAMPLE_SPLIT(ADDR_SURF_SAMPLE_SPLIT_2));
   2972  1.3  riastrad 
   2973  1.3  riastrad 		macrotile[0] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
   2974  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
   2975  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2976  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2977  1.3  riastrad 		macrotile[1] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
   2978  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
   2979  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2980  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2981  1.3  riastrad 		macrotile[2] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2982  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
   2983  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2984  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2985  1.3  riastrad 		macrotile[3] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2986  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2987  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2988  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2989  1.3  riastrad 		macrotile[4] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2990  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2991  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2992  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2993  1.3  riastrad 		macrotile[5] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2994  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2995  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   2996  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   2997  1.3  riastrad 		macrotile[6] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   2998  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   2999  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   3000  1.3  riastrad 				NUM_BANKS(ADDR_SURF_8_BANK));
   3001  1.3  riastrad 		macrotile[8] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
   3002  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_8) |
   3003  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   3004  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   3005  1.3  riastrad 		macrotile[9] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_4) |
   3006  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
   3007  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   3008  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   3009  1.3  riastrad 		macrotile[10] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
   3010  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_4) |
   3011  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   3012  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   3013  1.3  riastrad 		macrotile[11] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_2) |
   3014  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
   3015  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   3016  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   3017  1.3  riastrad 		macrotile[12] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   3018  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_2) |
   3019  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   3020  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   3021  1.3  riastrad 		macrotile[13] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   3022  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   3023  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_4) |
   3024  1.3  riastrad 				NUM_BANKS(ADDR_SURF_16_BANK));
   3025  1.3  riastrad 		macrotile[14] = (BANK_WIDTH(ADDR_SURF_BANK_WIDTH_1) |
   3026  1.3  riastrad 				BANK_HEIGHT(ADDR_SURF_BANK_HEIGHT_1) |
   3027  1.3  riastrad 				MACRO_TILE_ASPECT(ADDR_SURF_MACRO_ASPECT_2) |
   3028  1.3  riastrad 				NUM_BANKS(ADDR_SURF_8_BANK));
   3029  1.3  riastrad 
   3030  1.3  riastrad 		for (reg_offset = 0; reg_offset < num_tile_mode_states; reg_offset++)
   3031  1.3  riastrad 			WREG32(GB_TILE_MODE0 + (reg_offset * 4), tile[reg_offset]);
   3032  1.3  riastrad 		for (reg_offset = 0; reg_offset < num_secondary_tile_mode_states; reg_offset++)
   3033  1.3  riastrad 			WREG32(GB_MACROTILE_MODE0 + (reg_offset * 4), macrotile[reg_offset]);
   3034  1.3  riastrad 		break;
   3035  1.3  riastrad 
   3036  1.3  riastrad 	default:
   3037  1.1  riastrad 		DRM_ERROR("unknown num pipe config: 0x%x\n", num_pipe_configs);
   3038  1.3  riastrad 	}
   3039  1.1  riastrad }
   3040  1.1  riastrad 
   3041  1.1  riastrad /**
   3042  1.1  riastrad  * cik_select_se_sh - select which SE, SH to address
   3043  1.1  riastrad  *
   3044  1.1  riastrad  * @rdev: radeon_device pointer
   3045  1.1  riastrad  * @se_num: shader engine to address
   3046  1.1  riastrad  * @sh_num: sh block to address
   3047  1.1  riastrad  *
   3048  1.1  riastrad  * Select which SE, SH combinations to address. Certain
   3049  1.1  riastrad  * registers are instanced per SE or SH.  0xffffffff means
   3050  1.1  riastrad  * broadcast to all SEs or SHs (CIK).
   3051  1.1  riastrad  */
   3052  1.1  riastrad static void cik_select_se_sh(struct radeon_device *rdev,
   3053  1.1  riastrad 			     u32 se_num, u32 sh_num)
   3054  1.1  riastrad {
   3055  1.1  riastrad 	u32 data = INSTANCE_BROADCAST_WRITES;
   3056  1.1  riastrad 
   3057  1.1  riastrad 	if ((se_num == 0xffffffff) && (sh_num == 0xffffffff))
   3058  1.1  riastrad 		data |= SH_BROADCAST_WRITES | SE_BROADCAST_WRITES;
   3059  1.1  riastrad 	else if (se_num == 0xffffffff)
   3060  1.1  riastrad 		data |= SE_BROADCAST_WRITES | SH_INDEX(sh_num);
   3061  1.1  riastrad 	else if (sh_num == 0xffffffff)
   3062  1.1  riastrad 		data |= SH_BROADCAST_WRITES | SE_INDEX(se_num);
   3063  1.1  riastrad 	else
   3064  1.1  riastrad 		data |= SH_INDEX(sh_num) | SE_INDEX(se_num);
   3065  1.1  riastrad 	WREG32(GRBM_GFX_INDEX, data);
   3066  1.1  riastrad }
   3067  1.1  riastrad 
   3068  1.1  riastrad /**
   3069  1.1  riastrad  * cik_create_bitmask - create a bitmask
   3070  1.1  riastrad  *
   3071  1.1  riastrad  * @bit_width: length of the mask
   3072  1.1  riastrad  *
   3073  1.1  riastrad  * create a variable length bit mask (CIK).
   3074  1.1  riastrad  * Returns the bitmask.
   3075  1.1  riastrad  */
   3076  1.1  riastrad static u32 cik_create_bitmask(u32 bit_width)
   3077  1.1  riastrad {
   3078  1.1  riastrad 	u32 i, mask = 0;
   3079  1.1  riastrad 
   3080  1.1  riastrad 	for (i = 0; i < bit_width; i++) {
   3081  1.1  riastrad 		mask <<= 1;
   3082  1.1  riastrad 		mask |= 1;
   3083  1.1  riastrad 	}
   3084  1.1  riastrad 	return mask;
   3085  1.1  riastrad }
   3086  1.1  riastrad 
   3087  1.1  riastrad /**
   3088  1.1  riastrad  * cik_get_rb_disabled - computes the mask of disabled RBs
   3089  1.1  riastrad  *
   3090  1.1  riastrad  * @rdev: radeon_device pointer
   3091  1.1  riastrad  * @max_rb_num: max RBs (render backends) for the asic
   3092  1.1  riastrad  * @se_num: number of SEs (shader engines) for the asic
   3093  1.1  riastrad  * @sh_per_se: number of SH blocks per SE for the asic
   3094  1.1  riastrad  *
   3095  1.1  riastrad  * Calculates the bitmask of disabled RBs (CIK).
   3096  1.1  riastrad  * Returns the disabled RB bitmask.
   3097  1.1  riastrad  */
   3098  1.1  riastrad static u32 cik_get_rb_disabled(struct radeon_device *rdev,
   3099  1.1  riastrad 			      u32 max_rb_num_per_se,
   3100  1.1  riastrad 			      u32 sh_per_se)
   3101  1.1  riastrad {
   3102  1.1  riastrad 	u32 data, mask;
   3103  1.1  riastrad 
   3104  1.1  riastrad 	data = RREG32(CC_RB_BACKEND_DISABLE);
   3105  1.1  riastrad 	if (data & 1)
   3106  1.1  riastrad 		data &= BACKEND_DISABLE_MASK;
   3107  1.1  riastrad 	else
   3108  1.1  riastrad 		data = 0;
   3109  1.1  riastrad 	data |= RREG32(GC_USER_RB_BACKEND_DISABLE);
   3110  1.1  riastrad 
   3111  1.1  riastrad 	data >>= BACKEND_DISABLE_SHIFT;
   3112  1.1  riastrad 
   3113  1.1  riastrad 	mask = cik_create_bitmask(max_rb_num_per_se / sh_per_se);
   3114  1.1  riastrad 
   3115  1.1  riastrad 	return data & mask;
   3116  1.1  riastrad }
   3117  1.1  riastrad 
   3118  1.1  riastrad /**
   3119  1.1  riastrad  * cik_setup_rb - setup the RBs on the asic
   3120  1.1  riastrad  *
   3121  1.1  riastrad  * @rdev: radeon_device pointer
   3122  1.1  riastrad  * @se_num: number of SEs (shader engines) for the asic
   3123  1.1  riastrad  * @sh_per_se: number of SH blocks per SE for the asic
   3124  1.1  riastrad  * @max_rb_num: max RBs (render backends) for the asic
   3125  1.1  riastrad  *
   3126  1.1  riastrad  * Configures per-SE/SH RB registers (CIK).
   3127  1.1  riastrad  */
   3128  1.1  riastrad static void cik_setup_rb(struct radeon_device *rdev,
   3129  1.1  riastrad 			 u32 se_num, u32 sh_per_se,
   3130  1.1  riastrad 			 u32 max_rb_num_per_se)
   3131  1.1  riastrad {
   3132  1.1  riastrad 	int i, j;
   3133  1.1  riastrad 	u32 data, mask;
   3134  1.1  riastrad 	u32 disabled_rbs = 0;
   3135  1.1  riastrad 	u32 enabled_rbs = 0;
   3136  1.1  riastrad 
   3137  1.1  riastrad 	for (i = 0; i < se_num; i++) {
   3138  1.1  riastrad 		for (j = 0; j < sh_per_se; j++) {
   3139  1.1  riastrad 			cik_select_se_sh(rdev, i, j);
   3140  1.1  riastrad 			data = cik_get_rb_disabled(rdev, max_rb_num_per_se, sh_per_se);
   3141  1.1  riastrad 			if (rdev->family == CHIP_HAWAII)
   3142  1.1  riastrad 				disabled_rbs |= data << ((i * sh_per_se + j) * HAWAII_RB_BITMAP_WIDTH_PER_SH);
   3143  1.1  riastrad 			else
   3144  1.1  riastrad 				disabled_rbs |= data << ((i * sh_per_se + j) * CIK_RB_BITMAP_WIDTH_PER_SH);
   3145  1.1  riastrad 		}
   3146  1.1  riastrad 	}
   3147  1.1  riastrad 	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
   3148  1.1  riastrad 
   3149  1.1  riastrad 	mask = 1;
   3150  1.1  riastrad 	for (i = 0; i < max_rb_num_per_se * se_num; i++) {
   3151  1.1  riastrad 		if (!(disabled_rbs & mask))
   3152  1.1  riastrad 			enabled_rbs |= mask;
   3153  1.1  riastrad 		mask <<= 1;
   3154  1.1  riastrad 	}
   3155  1.1  riastrad 
   3156  1.1  riastrad 	rdev->config.cik.backend_enable_mask = enabled_rbs;
   3157  1.1  riastrad 
   3158  1.1  riastrad 	for (i = 0; i < se_num; i++) {
   3159  1.1  riastrad 		cik_select_se_sh(rdev, i, 0xffffffff);
   3160  1.1  riastrad 		data = 0;
   3161  1.1  riastrad 		for (j = 0; j < sh_per_se; j++) {
   3162  1.1  riastrad 			switch (enabled_rbs & 3) {
   3163  1.1  riastrad 			case 0:
   3164  1.1  riastrad 				if (j == 0)
   3165  1.1  riastrad 					data |= PKR_MAP(RASTER_CONFIG_RB_MAP_3);
   3166  1.1  riastrad 				else
   3167  1.1  riastrad 					data |= PKR_MAP(RASTER_CONFIG_RB_MAP_0);
   3168  1.1  riastrad 				break;
   3169  1.1  riastrad 			case 1:
   3170  1.1  riastrad 				data |= (RASTER_CONFIG_RB_MAP_0 << (i * sh_per_se + j) * 2);
   3171  1.1  riastrad 				break;
   3172  1.1  riastrad 			case 2:
   3173  1.1  riastrad 				data |= (RASTER_CONFIG_RB_MAP_3 << (i * sh_per_se + j) * 2);
   3174  1.1  riastrad 				break;
   3175  1.1  riastrad 			case 3:
   3176  1.1  riastrad 			default:
   3177  1.1  riastrad 				data |= (RASTER_CONFIG_RB_MAP_2 << (i * sh_per_se + j) * 2);
   3178  1.1  riastrad 				break;
   3179  1.1  riastrad 			}
   3180  1.1  riastrad 			enabled_rbs >>= 2;
   3181  1.1  riastrad 		}
   3182  1.1  riastrad 		WREG32(PA_SC_RASTER_CONFIG, data);
   3183  1.1  riastrad 	}
   3184  1.1  riastrad 	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
   3185  1.1  riastrad }
   3186  1.1  riastrad 
   3187  1.1  riastrad /**
   3188  1.1  riastrad  * cik_gpu_init - setup the 3D engine
   3189  1.1  riastrad  *
   3190  1.1  riastrad  * @rdev: radeon_device pointer
   3191  1.1  riastrad  *
   3192  1.1  riastrad  * Configures the 3D engine and tiling configuration
   3193  1.1  riastrad  * registers so that the 3D engine is usable.
   3194  1.1  riastrad  */
   3195  1.1  riastrad static void cik_gpu_init(struct radeon_device *rdev)
   3196  1.1  riastrad {
   3197  1.1  riastrad 	u32 gb_addr_config = RREG32(GB_ADDR_CONFIG);
   3198  1.1  riastrad 	u32 mc_shared_chmap __unused, mc_arb_ramcfg;
   3199  1.1  riastrad 	u32 hdp_host_path_cntl;
   3200  1.1  riastrad 	u32 tmp;
   3201  1.1  riastrad 	int i, j;
   3202  1.1  riastrad 
   3203  1.1  riastrad 	switch (rdev->family) {
   3204  1.1  riastrad 	case CHIP_BONAIRE:
   3205  1.1  riastrad 		rdev->config.cik.max_shader_engines = 2;
   3206  1.1  riastrad 		rdev->config.cik.max_tile_pipes = 4;
   3207  1.1  riastrad 		rdev->config.cik.max_cu_per_sh = 7;
   3208  1.1  riastrad 		rdev->config.cik.max_sh_per_se = 1;
   3209  1.1  riastrad 		rdev->config.cik.max_backends_per_se = 2;
   3210  1.1  riastrad 		rdev->config.cik.max_texture_channel_caches = 4;
   3211  1.1  riastrad 		rdev->config.cik.max_gprs = 256;
   3212  1.1  riastrad 		rdev->config.cik.max_gs_threads = 32;
   3213  1.1  riastrad 		rdev->config.cik.max_hw_contexts = 8;
   3214  1.1  riastrad 
   3215  1.1  riastrad 		rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
   3216  1.1  riastrad 		rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
   3217  1.1  riastrad 		rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
   3218  1.1  riastrad 		rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
   3219  1.1  riastrad 		gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
   3220  1.1  riastrad 		break;
   3221  1.1  riastrad 	case CHIP_HAWAII:
   3222  1.1  riastrad 		rdev->config.cik.max_shader_engines = 4;
   3223  1.1  riastrad 		rdev->config.cik.max_tile_pipes = 16;
   3224  1.1  riastrad 		rdev->config.cik.max_cu_per_sh = 11;
   3225  1.1  riastrad 		rdev->config.cik.max_sh_per_se = 1;
   3226  1.1  riastrad 		rdev->config.cik.max_backends_per_se = 4;
   3227  1.1  riastrad 		rdev->config.cik.max_texture_channel_caches = 16;
   3228  1.1  riastrad 		rdev->config.cik.max_gprs = 256;
   3229  1.1  riastrad 		rdev->config.cik.max_gs_threads = 32;
   3230  1.1  riastrad 		rdev->config.cik.max_hw_contexts = 8;
   3231  1.1  riastrad 
   3232  1.1  riastrad 		rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
   3233  1.1  riastrad 		rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
   3234  1.1  riastrad 		rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
   3235  1.1  riastrad 		rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
   3236  1.1  riastrad 		gb_addr_config = HAWAII_GB_ADDR_CONFIG_GOLDEN;
   3237  1.1  riastrad 		break;
   3238  1.1  riastrad 	case CHIP_KAVERI:
   3239  1.1  riastrad 		rdev->config.cik.max_shader_engines = 1;
   3240  1.1  riastrad 		rdev->config.cik.max_tile_pipes = 4;
   3241  1.1  riastrad 		rdev->config.cik.max_cu_per_sh = 8;
   3242  1.1  riastrad 		rdev->config.cik.max_backends_per_se = 2;
   3243  1.1  riastrad 		rdev->config.cik.max_sh_per_se = 1;
   3244  1.1  riastrad 		rdev->config.cik.max_texture_channel_caches = 4;
   3245  1.1  riastrad 		rdev->config.cik.max_gprs = 256;
   3246  1.1  riastrad 		rdev->config.cik.max_gs_threads = 16;
   3247  1.1  riastrad 		rdev->config.cik.max_hw_contexts = 8;
   3248  1.1  riastrad 
   3249  1.1  riastrad 		rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
   3250  1.1  riastrad 		rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
   3251  1.1  riastrad 		rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
   3252  1.1  riastrad 		rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
   3253  1.1  riastrad 		gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
   3254  1.1  riastrad 		break;
   3255  1.1  riastrad 	case CHIP_KABINI:
   3256  1.1  riastrad 	case CHIP_MULLINS:
   3257  1.1  riastrad 	default:
   3258  1.1  riastrad 		rdev->config.cik.max_shader_engines = 1;
   3259  1.1  riastrad 		rdev->config.cik.max_tile_pipes = 2;
   3260  1.1  riastrad 		rdev->config.cik.max_cu_per_sh = 2;
   3261  1.1  riastrad 		rdev->config.cik.max_sh_per_se = 1;
   3262  1.1  riastrad 		rdev->config.cik.max_backends_per_se = 1;
   3263  1.1  riastrad 		rdev->config.cik.max_texture_channel_caches = 2;
   3264  1.1  riastrad 		rdev->config.cik.max_gprs = 256;
   3265  1.1  riastrad 		rdev->config.cik.max_gs_threads = 16;
   3266  1.1  riastrad 		rdev->config.cik.max_hw_contexts = 8;
   3267  1.1  riastrad 
   3268  1.1  riastrad 		rdev->config.cik.sc_prim_fifo_size_frontend = 0x20;
   3269  1.1  riastrad 		rdev->config.cik.sc_prim_fifo_size_backend = 0x100;
   3270  1.1  riastrad 		rdev->config.cik.sc_hiz_tile_fifo_size = 0x30;
   3271  1.1  riastrad 		rdev->config.cik.sc_earlyz_tile_fifo_size = 0x130;
   3272  1.1  riastrad 		gb_addr_config = BONAIRE_GB_ADDR_CONFIG_GOLDEN;
   3273  1.1  riastrad 		break;
   3274  1.1  riastrad 	}
   3275  1.1  riastrad 
   3276  1.1  riastrad 	/* Initialize HDP */
   3277  1.1  riastrad 	for (i = 0, j = 0; i < 32; i++, j += 0x18) {
   3278  1.1  riastrad 		WREG32((0x2c14 + j), 0x00000000);
   3279  1.1  riastrad 		WREG32((0x2c18 + j), 0x00000000);
   3280  1.1  riastrad 		WREG32((0x2c1c + j), 0x00000000);
   3281  1.1  riastrad 		WREG32((0x2c20 + j), 0x00000000);
   3282  1.1  riastrad 		WREG32((0x2c24 + j), 0x00000000);
   3283  1.1  riastrad 	}
   3284  1.1  riastrad 
   3285  1.1  riastrad 	WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
   3286  1.1  riastrad 	WREG32(SRBM_INT_CNTL, 0x1);
   3287  1.1  riastrad 	WREG32(SRBM_INT_ACK, 0x1);
   3288  1.1  riastrad 
   3289  1.1  riastrad 	WREG32(BIF_FB_EN, FB_READ_EN | FB_WRITE_EN);
   3290  1.1  riastrad 
   3291  1.1  riastrad 	mc_shared_chmap = RREG32(MC_SHARED_CHMAP);
   3292  1.1  riastrad 	mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
   3293  1.1  riastrad 
   3294  1.1  riastrad 	rdev->config.cik.num_tile_pipes = rdev->config.cik.max_tile_pipes;
   3295  1.1  riastrad 	rdev->config.cik.mem_max_burst_length_bytes = 256;
   3296  1.1  riastrad 	tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
   3297  1.1  riastrad 	rdev->config.cik.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
   3298  1.1  riastrad 	if (rdev->config.cik.mem_row_size_in_kb > 4)
   3299  1.1  riastrad 		rdev->config.cik.mem_row_size_in_kb = 4;
   3300  1.1  riastrad 	/* XXX use MC settings? */
   3301  1.1  riastrad 	rdev->config.cik.shader_engine_tile_size = 32;
   3302  1.1  riastrad 	rdev->config.cik.num_gpus = 1;
   3303  1.1  riastrad 	rdev->config.cik.multi_gpu_tile_size = 64;
   3304  1.1  riastrad 
   3305  1.1  riastrad 	/* fix up row size */
   3306  1.1  riastrad 	gb_addr_config &= ~ROW_SIZE_MASK;
   3307  1.1  riastrad 	switch (rdev->config.cik.mem_row_size_in_kb) {
   3308  1.1  riastrad 	case 1:
   3309  1.1  riastrad 	default:
   3310  1.1  riastrad 		gb_addr_config |= ROW_SIZE(0);
   3311  1.1  riastrad 		break;
   3312  1.1  riastrad 	case 2:
   3313  1.1  riastrad 		gb_addr_config |= ROW_SIZE(1);
   3314  1.1  riastrad 		break;
   3315  1.1  riastrad 	case 4:
   3316  1.1  riastrad 		gb_addr_config |= ROW_SIZE(2);
   3317  1.1  riastrad 		break;
   3318  1.1  riastrad 	}
   3319  1.1  riastrad 
   3320  1.1  riastrad 	/* setup tiling info dword.  gb_addr_config is not adequate since it does
   3321  1.1  riastrad 	 * not have bank info, so create a custom tiling dword.
   3322  1.1  riastrad 	 * bits 3:0   num_pipes
   3323  1.1  riastrad 	 * bits 7:4   num_banks
   3324  1.1  riastrad 	 * bits 11:8  group_size
   3325  1.1  riastrad 	 * bits 15:12 row_size
   3326  1.1  riastrad 	 */
   3327  1.1  riastrad 	rdev->config.cik.tile_config = 0;
   3328  1.1  riastrad 	switch (rdev->config.cik.num_tile_pipes) {
   3329  1.1  riastrad 	case 1:
   3330  1.1  riastrad 		rdev->config.cik.tile_config |= (0 << 0);
   3331  1.1  riastrad 		break;
   3332  1.1  riastrad 	case 2:
   3333  1.1  riastrad 		rdev->config.cik.tile_config |= (1 << 0);
   3334  1.1  riastrad 		break;
   3335  1.1  riastrad 	case 4:
   3336  1.1  riastrad 		rdev->config.cik.tile_config |= (2 << 0);
   3337  1.1  riastrad 		break;
   3338  1.1  riastrad 	case 8:
   3339  1.1  riastrad 	default:
   3340  1.1  riastrad 		/* XXX what about 12? */
   3341  1.1  riastrad 		rdev->config.cik.tile_config |= (3 << 0);
   3342  1.1  riastrad 		break;
   3343  1.1  riastrad 	}
   3344  1.1  riastrad 	rdev->config.cik.tile_config |=
   3345  1.1  riastrad 		((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) << 4;
   3346  1.1  riastrad 	rdev->config.cik.tile_config |=
   3347  1.1  riastrad 		((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
   3348  1.1  riastrad 	rdev->config.cik.tile_config |=
   3349  1.1  riastrad 		((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
   3350  1.1  riastrad 
   3351  1.1  riastrad 	WREG32(GB_ADDR_CONFIG, gb_addr_config);
   3352  1.1  riastrad 	WREG32(HDP_ADDR_CONFIG, gb_addr_config);
   3353  1.1  riastrad 	WREG32(DMIF_ADDR_CALC, gb_addr_config);
   3354  1.1  riastrad 	WREG32(SDMA0_TILING_CONFIG + SDMA0_REGISTER_OFFSET, gb_addr_config & 0x70);
   3355  1.1  riastrad 	WREG32(SDMA0_TILING_CONFIG + SDMA1_REGISTER_OFFSET, gb_addr_config & 0x70);
   3356  1.1  riastrad 	WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
   3357  1.1  riastrad 	WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
   3358  1.1  riastrad 	WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
   3359  1.1  riastrad 
   3360  1.1  riastrad 	cik_tiling_mode_table_init(rdev);
   3361  1.1  riastrad 
   3362  1.1  riastrad 	cik_setup_rb(rdev, rdev->config.cik.max_shader_engines,
   3363  1.1  riastrad 		     rdev->config.cik.max_sh_per_se,
   3364  1.1  riastrad 		     rdev->config.cik.max_backends_per_se);
   3365  1.1  riastrad 
   3366  1.1  riastrad 	rdev->config.cik.active_cus = 0;
   3367  1.1  riastrad 	for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
   3368  1.1  riastrad 		for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
   3369  1.1  riastrad 			rdev->config.cik.active_cus +=
   3370  1.1  riastrad 				hweight32(cik_get_cu_active_bitmap(rdev, i, j));
   3371  1.1  riastrad 		}
   3372  1.1  riastrad 	}
   3373  1.1  riastrad 
   3374  1.1  riastrad 	/* set HW defaults for 3D engine */
   3375  1.1  riastrad 	WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
   3376  1.1  riastrad 
   3377  1.1  riastrad 	WREG32(SX_DEBUG_1, 0x20);
   3378  1.1  riastrad 
   3379  1.1  riastrad 	WREG32(TA_CNTL_AUX, 0x00010000);
   3380  1.1  riastrad 
   3381  1.1  riastrad 	tmp = RREG32(SPI_CONFIG_CNTL);
   3382  1.1  riastrad 	tmp |= 0x03000000;
   3383  1.1  riastrad 	WREG32(SPI_CONFIG_CNTL, tmp);
   3384  1.1  riastrad 
   3385  1.1  riastrad 	WREG32(SQ_CONFIG, 1);
   3386  1.1  riastrad 
   3387  1.1  riastrad 	WREG32(DB_DEBUG, 0);
   3388  1.1  riastrad 
   3389  1.1  riastrad 	tmp = RREG32(DB_DEBUG2) & ~0xf00fffff;
   3390  1.1  riastrad 	tmp |= 0x00000400;
   3391  1.1  riastrad 	WREG32(DB_DEBUG2, tmp);
   3392  1.1  riastrad 
   3393  1.1  riastrad 	tmp = RREG32(DB_DEBUG3) & ~0x0002021c;
   3394  1.1  riastrad 	tmp |= 0x00020200;
   3395  1.1  riastrad 	WREG32(DB_DEBUG3, tmp);
   3396  1.1  riastrad 
   3397  1.1  riastrad 	tmp = RREG32(CB_HW_CONTROL) & ~0x00010000;
   3398  1.1  riastrad 	tmp |= 0x00018208;
   3399  1.1  riastrad 	WREG32(CB_HW_CONTROL, tmp);
   3400  1.1  riastrad 
   3401  1.1  riastrad 	WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4));
   3402  1.1  riastrad 
   3403  1.1  riastrad 	WREG32(PA_SC_FIFO_SIZE, (SC_FRONTEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_frontend) |
   3404  1.1  riastrad 				 SC_BACKEND_PRIM_FIFO_SIZE(rdev->config.cik.sc_prim_fifo_size_backend) |
   3405  1.1  riastrad 				 SC_HIZ_TILE_FIFO_SIZE(rdev->config.cik.sc_hiz_tile_fifo_size) |
   3406  1.1  riastrad 				 SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cik.sc_earlyz_tile_fifo_size)));
   3407  1.1  riastrad 
   3408  1.1  riastrad 	WREG32(VGT_NUM_INSTANCES, 1);
   3409  1.1  riastrad 
   3410  1.1  riastrad 	WREG32(CP_PERFMON_CNTL, 0);
   3411  1.1  riastrad 
   3412  1.1  riastrad 	WREG32(SQ_CONFIG, 0);
   3413  1.1  riastrad 
   3414  1.1  riastrad 	WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
   3415  1.1  riastrad 					  FORCE_EOV_MAX_REZ_CNT(255)));
   3416  1.1  riastrad 
   3417  1.1  riastrad 	WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
   3418  1.1  riastrad 	       AUTO_INVLD_EN(ES_AND_GS_AUTO));
   3419  1.1  riastrad 
   3420  1.1  riastrad 	WREG32(VGT_GS_VERTEX_REUSE, 16);
   3421  1.1  riastrad 	WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
   3422  1.1  riastrad 
   3423  1.1  riastrad 	tmp = RREG32(HDP_MISC_CNTL);
   3424  1.1  riastrad 	tmp |= HDP_FLUSH_INVALIDATE_CACHE;
   3425  1.1  riastrad 	WREG32(HDP_MISC_CNTL, tmp);
   3426  1.1  riastrad 
   3427  1.1  riastrad 	hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
   3428  1.1  riastrad 	WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
   3429  1.1  riastrad 
   3430  1.1  riastrad 	WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
   3431  1.1  riastrad 	WREG32(PA_SC_ENHANCE, ENABLE_PA_SC_OUT_OF_ORDER);
   3432  1.1  riastrad 
   3433  1.1  riastrad 	udelay(50);
   3434  1.1  riastrad }
   3435  1.1  riastrad 
   3436  1.1  riastrad /*
   3437  1.1  riastrad  * GPU scratch registers helpers function.
   3438  1.1  riastrad  */
   3439  1.1  riastrad /**
   3440  1.1  riastrad  * cik_scratch_init - setup driver info for CP scratch regs
   3441  1.1  riastrad  *
   3442  1.1  riastrad  * @rdev: radeon_device pointer
   3443  1.1  riastrad  *
   3444  1.1  riastrad  * Set up the number and offset of the CP scratch registers.
   3445  1.1  riastrad  * NOTE: use of CP scratch registers is a legacy inferface and
   3446  1.1  riastrad  * is not used by default on newer asics (r6xx+).  On newer asics,
   3447  1.1  riastrad  * memory buffers are used for fences rather than scratch regs.
   3448  1.1  riastrad  */
   3449  1.1  riastrad static void cik_scratch_init(struct radeon_device *rdev)
   3450  1.1  riastrad {
   3451  1.1  riastrad 	int i;
   3452  1.1  riastrad 
   3453  1.1  riastrad 	rdev->scratch.num_reg = 7;
   3454  1.1  riastrad 	rdev->scratch.reg_base = SCRATCH_REG0;
   3455  1.1  riastrad 	for (i = 0; i < rdev->scratch.num_reg; i++) {
   3456  1.1  riastrad 		rdev->scratch.free[i] = true;
   3457  1.1  riastrad 		rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
   3458  1.1  riastrad 	}
   3459  1.1  riastrad }
   3460  1.1  riastrad 
   3461  1.1  riastrad /**
   3462  1.1  riastrad  * cik_ring_test - basic gfx ring test
   3463  1.1  riastrad  *
   3464  1.1  riastrad  * @rdev: radeon_device pointer
   3465  1.1  riastrad  * @ring: radeon_ring structure holding ring information
   3466  1.1  riastrad  *
   3467  1.1  riastrad  * Allocate a scratch register and write to it using the gfx ring (CIK).
   3468  1.1  riastrad  * Provides a basic gfx ring test to verify that the ring is working.
   3469  1.1  riastrad  * Used by cik_cp_gfx_resume();
   3470  1.1  riastrad  * Returns 0 on success, error on failure.
   3471  1.1  riastrad  */
   3472  1.1  riastrad int cik_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)
   3473  1.1  riastrad {
   3474  1.1  riastrad 	uint32_t scratch;
   3475  1.1  riastrad 	uint32_t tmp = 0;
   3476  1.1  riastrad 	unsigned i;
   3477  1.1  riastrad 	int r;
   3478  1.1  riastrad 
   3479  1.1  riastrad 	r = radeon_scratch_get(rdev, &scratch);
   3480  1.1  riastrad 	if (r) {
   3481  1.1  riastrad 		DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
   3482  1.1  riastrad 		return r;
   3483  1.1  riastrad 	}
   3484  1.1  riastrad 	WREG32(scratch, 0xCAFEDEAD);
   3485  1.1  riastrad 	r = radeon_ring_lock(rdev, ring, 3);
   3486  1.1  riastrad 	if (r) {
   3487  1.1  riastrad 		DRM_ERROR("radeon: cp failed to lock ring %d (%d).\n", ring->idx, r);
   3488  1.1  riastrad 		radeon_scratch_free(rdev, scratch);
   3489  1.1  riastrad 		return r;
   3490  1.1  riastrad 	}
   3491  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
   3492  1.1  riastrad 	radeon_ring_write(ring, ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2));
   3493  1.1  riastrad 	radeon_ring_write(ring, 0xDEADBEEF);
   3494  1.1  riastrad 	radeon_ring_unlock_commit(rdev, ring, false);
   3495  1.1  riastrad 
   3496  1.1  riastrad 	for (i = 0; i < rdev->usec_timeout; i++) {
   3497  1.1  riastrad 		tmp = RREG32(scratch);
   3498  1.1  riastrad 		if (tmp == 0xDEADBEEF)
   3499  1.1  riastrad 			break;
   3500  1.3  riastrad 		udelay(1);
   3501  1.1  riastrad 	}
   3502  1.1  riastrad 	if (i < rdev->usec_timeout) {
   3503  1.1  riastrad 		DRM_INFO("ring test on %d succeeded in %d usecs\n", ring->idx, i);
   3504  1.1  riastrad 	} else {
   3505  1.1  riastrad 		DRM_ERROR("radeon: ring %d test failed (scratch(0x%04X)=0x%08X)\n",
   3506  1.1  riastrad 			  ring->idx, scratch, tmp);
   3507  1.1  riastrad 		r = -EINVAL;
   3508  1.1  riastrad 	}
   3509  1.1  riastrad 	radeon_scratch_free(rdev, scratch);
   3510  1.1  riastrad 	return r;
   3511  1.1  riastrad }
   3512  1.1  riastrad 
   3513  1.1  riastrad /**
   3514  1.1  riastrad  * cik_hdp_flush_cp_ring_emit - emit an hdp flush on the cp
   3515  1.1  riastrad  *
   3516  1.1  riastrad  * @rdev: radeon_device pointer
   3517  1.1  riastrad  * @ridx: radeon ring index
   3518  1.1  riastrad  *
   3519  1.1  riastrad  * Emits an hdp flush on the cp.
   3520  1.1  riastrad  */
   3521  1.1  riastrad static void cik_hdp_flush_cp_ring_emit(struct radeon_device *rdev,
   3522  1.1  riastrad 				       int ridx)
   3523  1.1  riastrad {
   3524  1.1  riastrad 	struct radeon_ring *ring = &rdev->ring[ridx];
   3525  1.1  riastrad 	u32 ref_and_mask;
   3526  1.1  riastrad 
   3527  1.1  riastrad 	switch (ring->idx) {
   3528  1.1  riastrad 	case CAYMAN_RING_TYPE_CP1_INDEX:
   3529  1.1  riastrad 	case CAYMAN_RING_TYPE_CP2_INDEX:
   3530  1.1  riastrad 	default:
   3531  1.1  riastrad 		switch (ring->me) {
   3532  1.1  riastrad 		case 0:
   3533  1.1  riastrad 			ref_and_mask = CP2 << ring->pipe;
   3534  1.1  riastrad 			break;
   3535  1.1  riastrad 		case 1:
   3536  1.1  riastrad 			ref_and_mask = CP6 << ring->pipe;
   3537  1.1  riastrad 			break;
   3538  1.1  riastrad 		default:
   3539  1.1  riastrad 			return;
   3540  1.1  riastrad 		}
   3541  1.1  riastrad 		break;
   3542  1.1  riastrad 	case RADEON_RING_TYPE_GFX_INDEX:
   3543  1.1  riastrad 		ref_and_mask = CP0;
   3544  1.1  riastrad 		break;
   3545  1.1  riastrad 	}
   3546  1.1  riastrad 
   3547  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
   3548  1.1  riastrad 	radeon_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* write, wait, write */
   3549  1.1  riastrad 				 WAIT_REG_MEM_FUNCTION(3) |  /* == */
   3550  1.1  riastrad 				 WAIT_REG_MEM_ENGINE(1)));   /* pfp */
   3551  1.1  riastrad 	radeon_ring_write(ring, GPU_HDP_FLUSH_REQ >> 2);
   3552  1.1  riastrad 	radeon_ring_write(ring, GPU_HDP_FLUSH_DONE >> 2);
   3553  1.1  riastrad 	radeon_ring_write(ring, ref_and_mask);
   3554  1.1  riastrad 	radeon_ring_write(ring, ref_and_mask);
   3555  1.1  riastrad 	radeon_ring_write(ring, 0x20); /* poll interval */
   3556  1.1  riastrad }
   3557  1.1  riastrad 
   3558  1.1  riastrad /**
   3559  1.1  riastrad  * cik_fence_gfx_ring_emit - emit a fence on the gfx ring
   3560  1.1  riastrad  *
   3561  1.1  riastrad  * @rdev: radeon_device pointer
   3562  1.1  riastrad  * @fence: radeon fence object
   3563  1.1  riastrad  *
   3564  1.1  riastrad  * Emits a fence sequnce number on the gfx ring and flushes
   3565  1.1  riastrad  * GPU caches.
   3566  1.1  riastrad  */
   3567  1.1  riastrad void cik_fence_gfx_ring_emit(struct radeon_device *rdev,
   3568  1.1  riastrad 			     struct radeon_fence *fence)
   3569  1.1  riastrad {
   3570  1.1  riastrad 	struct radeon_ring *ring = &rdev->ring[fence->ring];
   3571  1.1  riastrad 	u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
   3572  1.1  riastrad 
   3573  1.1  riastrad 	/* Workaround for cache flush problems. First send a dummy EOP
   3574  1.1  riastrad 	 * event down the pipe with seq one below.
   3575  1.1  riastrad 	 */
   3576  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
   3577  1.1  riastrad 	radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
   3578  1.1  riastrad 				 EOP_TC_ACTION_EN |
   3579  1.1  riastrad 				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
   3580  1.1  riastrad 				 EVENT_INDEX(5)));
   3581  1.1  riastrad 	radeon_ring_write(ring, addr & 0xfffffffc);
   3582  1.1  riastrad 	radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) |
   3583  1.1  riastrad 				DATA_SEL(1) | INT_SEL(0));
   3584  1.1  riastrad 	radeon_ring_write(ring, fence->seq - 1);
   3585  1.1  riastrad 	radeon_ring_write(ring, 0);
   3586  1.1  riastrad 
   3587  1.1  riastrad 	/* Then send the real EOP event down the pipe. */
   3588  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
   3589  1.1  riastrad 	radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
   3590  1.1  riastrad 				 EOP_TC_ACTION_EN |
   3591  1.1  riastrad 				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
   3592  1.1  riastrad 				 EVENT_INDEX(5)));
   3593  1.1  riastrad 	radeon_ring_write(ring, addr & 0xfffffffc);
   3594  1.1  riastrad 	radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | DATA_SEL(1) | INT_SEL(2));
   3595  1.1  riastrad 	radeon_ring_write(ring, fence->seq);
   3596  1.1  riastrad 	radeon_ring_write(ring, 0);
   3597  1.1  riastrad }
   3598  1.1  riastrad 
   3599  1.1  riastrad /**
   3600  1.1  riastrad  * cik_fence_compute_ring_emit - emit a fence on the compute ring
   3601  1.1  riastrad  *
   3602  1.1  riastrad  * @rdev: radeon_device pointer
   3603  1.1  riastrad  * @fence: radeon fence object
   3604  1.1  riastrad  *
   3605  1.1  riastrad  * Emits a fence sequnce number on the compute ring and flushes
   3606  1.1  riastrad  * GPU caches.
   3607  1.1  riastrad  */
   3608  1.1  riastrad void cik_fence_compute_ring_emit(struct radeon_device *rdev,
   3609  1.1  riastrad 				 struct radeon_fence *fence)
   3610  1.1  riastrad {
   3611  1.1  riastrad 	struct radeon_ring *ring = &rdev->ring[fence->ring];
   3612  1.1  riastrad 	u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
   3613  1.1  riastrad 
   3614  1.1  riastrad 	/* RELEASE_MEM - flush caches, send int */
   3615  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_RELEASE_MEM, 5));
   3616  1.1  riastrad 	radeon_ring_write(ring, (EOP_TCL1_ACTION_EN |
   3617  1.1  riastrad 				 EOP_TC_ACTION_EN |
   3618  1.1  riastrad 				 EVENT_TYPE(CACHE_FLUSH_AND_INV_TS_EVENT) |
   3619  1.1  riastrad 				 EVENT_INDEX(5)));
   3620  1.1  riastrad 	radeon_ring_write(ring, DATA_SEL(1) | INT_SEL(2));
   3621  1.1  riastrad 	radeon_ring_write(ring, addr & 0xfffffffc);
   3622  1.1  riastrad 	radeon_ring_write(ring, upper_32_bits(addr));
   3623  1.1  riastrad 	radeon_ring_write(ring, fence->seq);
   3624  1.1  riastrad 	radeon_ring_write(ring, 0);
   3625  1.1  riastrad }
   3626  1.1  riastrad 
   3627  1.1  riastrad /**
   3628  1.1  riastrad  * cik_semaphore_ring_emit - emit a semaphore on the CP ring
   3629  1.1  riastrad  *
   3630  1.1  riastrad  * @rdev: radeon_device pointer
   3631  1.1  riastrad  * @ring: radeon ring buffer object
   3632  1.1  riastrad  * @semaphore: radeon semaphore object
   3633  1.1  riastrad  * @emit_wait: Is this a sempahore wait?
   3634  1.1  riastrad  *
   3635  1.1  riastrad  * Emits a semaphore signal/wait packet to the CP ring and prevents the PFP
   3636  1.1  riastrad  * from running ahead of semaphore waits.
   3637  1.1  riastrad  */
   3638  1.1  riastrad bool cik_semaphore_ring_emit(struct radeon_device *rdev,
   3639  1.1  riastrad 			     struct radeon_ring *ring,
   3640  1.1  riastrad 			     struct radeon_semaphore *semaphore,
   3641  1.1  riastrad 			     bool emit_wait)
   3642  1.1  riastrad {
   3643  1.1  riastrad 	uint64_t addr = semaphore->gpu_addr;
   3644  1.1  riastrad 	unsigned sel = emit_wait ? PACKET3_SEM_SEL_WAIT : PACKET3_SEM_SEL_SIGNAL;
   3645  1.1  riastrad 
   3646  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_MEM_SEMAPHORE, 1));
   3647  1.1  riastrad 	radeon_ring_write(ring, lower_32_bits(addr));
   3648  1.1  riastrad 	radeon_ring_write(ring, (upper_32_bits(addr) & 0xffff) | sel);
   3649  1.1  riastrad 
   3650  1.1  riastrad 	if (emit_wait && ring->idx == RADEON_RING_TYPE_GFX_INDEX) {
   3651  1.1  riastrad 		/* Prevent the PFP from running ahead of the semaphore wait */
   3652  1.1  riastrad 		radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
   3653  1.1  riastrad 		radeon_ring_write(ring, 0x0);
   3654  1.1  riastrad 	}
   3655  1.1  riastrad 
   3656  1.1  riastrad 	return true;
   3657  1.1  riastrad }
   3658  1.1  riastrad 
   3659  1.1  riastrad /**
   3660  1.1  riastrad  * cik_copy_cpdma - copy pages using the CP DMA engine
   3661  1.1  riastrad  *
   3662  1.1  riastrad  * @rdev: radeon_device pointer
   3663  1.1  riastrad  * @src_offset: src GPU address
   3664  1.1  riastrad  * @dst_offset: dst GPU address
   3665  1.1  riastrad  * @num_gpu_pages: number of GPU pages to xfer
   3666  1.1  riastrad  * @resv: reservation object to sync to
   3667  1.1  riastrad  *
   3668  1.1  riastrad  * Copy GPU paging using the CP DMA engine (CIK+).
   3669  1.1  riastrad  * Used by the radeon ttm implementation to move pages if
   3670  1.1  riastrad  * registered as the asic copy callback.
   3671  1.1  riastrad  */
   3672  1.1  riastrad struct radeon_fence *cik_copy_cpdma(struct radeon_device *rdev,
   3673  1.1  riastrad 				    uint64_t src_offset, uint64_t dst_offset,
   3674  1.1  riastrad 				    unsigned num_gpu_pages,
   3675  1.3  riastrad 				    struct dma_resv *resv)
   3676  1.1  riastrad {
   3677  1.1  riastrad 	struct radeon_fence *fence;
   3678  1.1  riastrad 	struct radeon_sync sync;
   3679  1.1  riastrad 	int ring_index = rdev->asic->copy.blit_ring_index;
   3680  1.1  riastrad 	struct radeon_ring *ring = &rdev->ring[ring_index];
   3681  1.1  riastrad 	u32 size_in_bytes, cur_size_in_bytes, control;
   3682  1.1  riastrad 	int i, num_loops;
   3683  1.1  riastrad 	int r = 0;
   3684  1.1  riastrad 
   3685  1.1  riastrad 	radeon_sync_create(&sync);
   3686  1.1  riastrad 
   3687  1.1  riastrad 	size_in_bytes = (num_gpu_pages << RADEON_GPU_PAGE_SHIFT);
   3688  1.1  riastrad 	num_loops = DIV_ROUND_UP(size_in_bytes, 0x1fffff);
   3689  1.1  riastrad 	r = radeon_ring_lock(rdev, ring, num_loops * 7 + 18);
   3690  1.1  riastrad 	if (r) {
   3691  1.1  riastrad 		DRM_ERROR("radeon: moving bo (%d).\n", r);
   3692  1.1  riastrad 		radeon_sync_free(rdev, &sync, NULL);
   3693  1.1  riastrad 		return ERR_PTR(r);
   3694  1.1  riastrad 	}
   3695  1.1  riastrad 
   3696  1.1  riastrad 	radeon_sync_resv(rdev, &sync, resv, false);
   3697  1.1  riastrad 	radeon_sync_rings(rdev, &sync, ring->idx);
   3698  1.1  riastrad 
   3699  1.1  riastrad 	for (i = 0; i < num_loops; i++) {
   3700  1.1  riastrad 		cur_size_in_bytes = size_in_bytes;
   3701  1.1  riastrad 		if (cur_size_in_bytes > 0x1fffff)
   3702  1.1  riastrad 			cur_size_in_bytes = 0x1fffff;
   3703  1.1  riastrad 		size_in_bytes -= cur_size_in_bytes;
   3704  1.1  riastrad 		control = 0;
   3705  1.1  riastrad 		if (size_in_bytes == 0)
   3706  1.1  riastrad 			control |= PACKET3_DMA_DATA_CP_SYNC;
   3707  1.1  riastrad 		radeon_ring_write(ring, PACKET3(PACKET3_DMA_DATA, 5));
   3708  1.1  riastrad 		radeon_ring_write(ring, control);
   3709  1.1  riastrad 		radeon_ring_write(ring, lower_32_bits(src_offset));
   3710  1.1  riastrad 		radeon_ring_write(ring, upper_32_bits(src_offset));
   3711  1.1  riastrad 		radeon_ring_write(ring, lower_32_bits(dst_offset));
   3712  1.1  riastrad 		radeon_ring_write(ring, upper_32_bits(dst_offset));
   3713  1.1  riastrad 		radeon_ring_write(ring, cur_size_in_bytes);
   3714  1.1  riastrad 		src_offset += cur_size_in_bytes;
   3715  1.1  riastrad 		dst_offset += cur_size_in_bytes;
   3716  1.1  riastrad 	}
   3717  1.1  riastrad 
   3718  1.1  riastrad 	r = radeon_fence_emit(rdev, &fence, ring->idx);
   3719  1.1  riastrad 	if (r) {
   3720  1.1  riastrad 		radeon_ring_unlock_undo(rdev, ring);
   3721  1.1  riastrad 		radeon_sync_free(rdev, &sync, NULL);
   3722  1.1  riastrad 		return ERR_PTR(r);
   3723  1.1  riastrad 	}
   3724  1.1  riastrad 
   3725  1.1  riastrad 	radeon_ring_unlock_commit(rdev, ring, false);
   3726  1.1  riastrad 	radeon_sync_free(rdev, &sync, fence);
   3727  1.1  riastrad 
   3728  1.1  riastrad 	return fence;
   3729  1.1  riastrad }
   3730  1.1  riastrad 
   3731  1.1  riastrad /*
   3732  1.1  riastrad  * IB stuff
   3733  1.1  riastrad  */
   3734  1.1  riastrad /**
   3735  1.1  riastrad  * cik_ring_ib_execute - emit an IB (Indirect Buffer) on the gfx ring
   3736  1.1  riastrad  *
   3737  1.1  riastrad  * @rdev: radeon_device pointer
   3738  1.1  riastrad  * @ib: radeon indirect buffer object
   3739  1.1  riastrad  *
   3740  1.3  riastrad  * Emits a DE (drawing engine) or CE (constant engine) IB
   3741  1.1  riastrad  * on the gfx ring.  IBs are usually generated by userspace
   3742  1.1  riastrad  * acceleration drivers and submitted to the kernel for
   3743  1.3  riastrad  * scheduling on the ring.  This function schedules the IB
   3744  1.1  riastrad  * on the gfx ring for execution by the GPU.
   3745  1.1  riastrad  */
   3746  1.1  riastrad void cik_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
   3747  1.1  riastrad {
   3748  1.1  riastrad 	struct radeon_ring *ring = &rdev->ring[ib->ring];
   3749  1.1  riastrad 	unsigned vm_id = ib->vm ? ib->vm->ids[ib->ring].id : 0;
   3750  1.1  riastrad 	u32 header, control = INDIRECT_BUFFER_VALID;
   3751  1.1  riastrad 
   3752  1.1  riastrad 	if (ib->is_const_ib) {
   3753  1.1  riastrad 		/* set switch buffer packet before const IB */
   3754  1.1  riastrad 		radeon_ring_write(ring, PACKET3(PACKET3_SWITCH_BUFFER, 0));
   3755  1.1  riastrad 		radeon_ring_write(ring, 0);
   3756  1.1  riastrad 
   3757  1.1  riastrad 		header = PACKET3(PACKET3_INDIRECT_BUFFER_CONST, 2);
   3758  1.1  riastrad 	} else {
   3759  1.1  riastrad 		u32 next_rptr;
   3760  1.1  riastrad 		if (ring->rptr_save_reg) {
   3761  1.1  riastrad 			next_rptr = ring->wptr + 3 + 4;
   3762  1.1  riastrad 			radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));
   3763  1.1  riastrad 			radeon_ring_write(ring, ((ring->rptr_save_reg -
   3764  1.1  riastrad 						  PACKET3_SET_UCONFIG_REG_START) >> 2));
   3765  1.1  riastrad 			radeon_ring_write(ring, next_rptr);
   3766  1.1  riastrad 		} else if (rdev->wb.enabled) {
   3767  1.1  riastrad 			next_rptr = ring->wptr + 5 + 4;
   3768  1.1  riastrad 			radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
   3769  1.1  riastrad 			radeon_ring_write(ring, WRITE_DATA_DST_SEL(1));
   3770  1.1  riastrad 			radeon_ring_write(ring, ring->next_rptr_gpu_addr & 0xfffffffc);
   3771  1.1  riastrad 			radeon_ring_write(ring, upper_32_bits(ring->next_rptr_gpu_addr));
   3772  1.1  riastrad 			radeon_ring_write(ring, next_rptr);
   3773  1.1  riastrad 		}
   3774  1.1  riastrad 
   3775  1.1  riastrad 		header = PACKET3(PACKET3_INDIRECT_BUFFER, 2);
   3776  1.1  riastrad 	}
   3777  1.1  riastrad 
   3778  1.1  riastrad 	control |= ib->length_dw | (vm_id << 24);
   3779  1.1  riastrad 
   3780  1.1  riastrad 	radeon_ring_write(ring, header);
   3781  1.1  riastrad 	radeon_ring_write(ring, (ib->gpu_addr & 0xFFFFFFFC));
   3782  1.1  riastrad 	radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFFFF);
   3783  1.1  riastrad 	radeon_ring_write(ring, control);
   3784  1.1  riastrad }
   3785  1.1  riastrad 
   3786  1.1  riastrad /**
   3787  1.1  riastrad  * cik_ib_test - basic gfx ring IB test
   3788  1.1  riastrad  *
   3789  1.1  riastrad  * @rdev: radeon_device pointer
   3790  1.1  riastrad  * @ring: radeon_ring structure holding ring information
   3791  1.1  riastrad  *
   3792  1.1  riastrad  * Allocate an IB and execute it on the gfx ring (CIK).
   3793  1.1  riastrad  * Provides a basic gfx ring test to verify that IBs are working.
   3794  1.1  riastrad  * Returns 0 on success, error on failure.
   3795  1.1  riastrad  */
   3796  1.1  riastrad int cik_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
   3797  1.1  riastrad {
   3798  1.1  riastrad 	struct radeon_ib ib;
   3799  1.1  riastrad 	uint32_t scratch;
   3800  1.1  riastrad 	uint32_t tmp = 0;
   3801  1.1  riastrad 	unsigned i;
   3802  1.1  riastrad 	int r;
   3803  1.1  riastrad 
   3804  1.1  riastrad 	r = radeon_scratch_get(rdev, &scratch);
   3805  1.1  riastrad 	if (r) {
   3806  1.1  riastrad 		DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
   3807  1.1  riastrad 		return r;
   3808  1.1  riastrad 	}
   3809  1.1  riastrad 	WREG32(scratch, 0xCAFEDEAD);
   3810  1.1  riastrad 	r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
   3811  1.1  riastrad 	if (r) {
   3812  1.1  riastrad 		DRM_ERROR("radeon: failed to get ib (%d).\n", r);
   3813  1.1  riastrad 		radeon_scratch_free(rdev, scratch);
   3814  1.1  riastrad 		return r;
   3815  1.1  riastrad 	}
   3816  1.1  riastrad 	ib.ptr[0] = PACKET3(PACKET3_SET_UCONFIG_REG, 1);
   3817  1.1  riastrad 	ib.ptr[1] = ((scratch - PACKET3_SET_UCONFIG_REG_START) >> 2);
   3818  1.1  riastrad 	ib.ptr[2] = 0xDEADBEEF;
   3819  1.1  riastrad 	ib.length_dw = 3;
   3820  1.1  riastrad 	r = radeon_ib_schedule(rdev, &ib, NULL, false);
   3821  1.1  riastrad 	if (r) {
   3822  1.1  riastrad 		radeon_scratch_free(rdev, scratch);
   3823  1.1  riastrad 		radeon_ib_free(rdev, &ib);
   3824  1.1  riastrad 		DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
   3825  1.1  riastrad 		return r;
   3826  1.1  riastrad 	}
   3827  1.3  riastrad 	r = radeon_fence_wait_timeout(ib.fence, false, usecs_to_jiffies(
   3828  1.3  riastrad 		RADEON_USEC_IB_TEST_TIMEOUT));
   3829  1.3  riastrad 	if (r < 0) {
   3830  1.1  riastrad 		DRM_ERROR("radeon: fence wait failed (%d).\n", r);
   3831  1.1  riastrad 		radeon_scratch_free(rdev, scratch);
   3832  1.1  riastrad 		radeon_ib_free(rdev, &ib);
   3833  1.1  riastrad 		return r;
   3834  1.3  riastrad 	} else if (r == 0) {
   3835  1.3  riastrad 		DRM_ERROR("radeon: fence wait timed out.\n");
   3836  1.3  riastrad 		radeon_scratch_free(rdev, scratch);
   3837  1.3  riastrad 		radeon_ib_free(rdev, &ib);
   3838  1.3  riastrad 		return -ETIMEDOUT;
   3839  1.1  riastrad 	}
   3840  1.3  riastrad 	r = 0;
   3841  1.1  riastrad 	for (i = 0; i < rdev->usec_timeout; i++) {
   3842  1.1  riastrad 		tmp = RREG32(scratch);
   3843  1.1  riastrad 		if (tmp == 0xDEADBEEF)
   3844  1.1  riastrad 			break;
   3845  1.3  riastrad 		udelay(1);
   3846  1.1  riastrad 	}
   3847  1.1  riastrad 	if (i < rdev->usec_timeout) {
   3848  1.1  riastrad 		DRM_INFO("ib test on ring %d succeeded in %u usecs\n", ib.fence->ring, i);
   3849  1.1  riastrad 	} else {
   3850  1.1  riastrad 		DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
   3851  1.1  riastrad 			  scratch, tmp);
   3852  1.1  riastrad 		r = -EINVAL;
   3853  1.1  riastrad 	}
   3854  1.1  riastrad 	radeon_scratch_free(rdev, scratch);
   3855  1.1  riastrad 	radeon_ib_free(rdev, &ib);
   3856  1.1  riastrad 	return r;
   3857  1.1  riastrad }
   3858  1.1  riastrad 
   3859  1.1  riastrad /*
   3860  1.1  riastrad  * CP.
   3861  1.1  riastrad  * On CIK, gfx and compute now have independant command processors.
   3862  1.1  riastrad  *
   3863  1.1  riastrad  * GFX
   3864  1.1  riastrad  * Gfx consists of a single ring and can process both gfx jobs and
   3865  1.1  riastrad  * compute jobs.  The gfx CP consists of three microengines (ME):
   3866  1.1  riastrad  * PFP - Pre-Fetch Parser
   3867  1.1  riastrad  * ME - Micro Engine
   3868  1.1  riastrad  * CE - Constant Engine
   3869  1.1  riastrad  * The PFP and ME make up what is considered the Drawing Engine (DE).
   3870  1.1  riastrad  * The CE is an asynchronous engine used for updating buffer desciptors
   3871  1.1  riastrad  * used by the DE so that they can be loaded into cache in parallel
   3872  1.1  riastrad  * while the DE is processing state update packets.
   3873  1.1  riastrad  *
   3874  1.1  riastrad  * Compute
   3875  1.1  riastrad  * The compute CP consists of two microengines (ME):
   3876  1.1  riastrad  * MEC1 - Compute MicroEngine 1
   3877  1.1  riastrad  * MEC2 - Compute MicroEngine 2
   3878  1.1  riastrad  * Each MEC supports 4 compute pipes and each pipe supports 8 queues.
   3879  1.1  riastrad  * The queues are exposed to userspace and are programmed directly
   3880  1.1  riastrad  * by the compute runtime.
   3881  1.1  riastrad  */
   3882  1.1  riastrad /**
   3883  1.1  riastrad  * cik_cp_gfx_enable - enable/disable the gfx CP MEs
   3884  1.1  riastrad  *
   3885  1.1  riastrad  * @rdev: radeon_device pointer
   3886  1.1  riastrad  * @enable: enable or disable the MEs
   3887  1.1  riastrad  *
   3888  1.1  riastrad  * Halts or unhalts the gfx MEs.
   3889  1.1  riastrad  */
   3890  1.1  riastrad static void cik_cp_gfx_enable(struct radeon_device *rdev, bool enable)
   3891  1.1  riastrad {
   3892  1.1  riastrad 	if (enable)
   3893  1.1  riastrad 		WREG32(CP_ME_CNTL, 0);
   3894  1.1  riastrad 	else {
   3895  1.1  riastrad 		if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
   3896  1.1  riastrad 			radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
   3897  1.1  riastrad 		WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT));
   3898  1.1  riastrad 		rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
   3899  1.1  riastrad 	}
   3900  1.1  riastrad 	udelay(50);
   3901  1.1  riastrad }
   3902  1.1  riastrad 
   3903  1.1  riastrad /**
   3904  1.1  riastrad  * cik_cp_gfx_load_microcode - load the gfx CP ME ucode
   3905  1.1  riastrad  *
   3906  1.1  riastrad  * @rdev: radeon_device pointer
   3907  1.1  riastrad  *
   3908  1.1  riastrad  * Loads the gfx PFP, ME, and CE ucode.
   3909  1.1  riastrad  * Returns 0 for success, -EINVAL if the ucode is not available.
   3910  1.1  riastrad  */
   3911  1.1  riastrad static int cik_cp_gfx_load_microcode(struct radeon_device *rdev)
   3912  1.1  riastrad {
   3913  1.1  riastrad 	int i;
   3914  1.1  riastrad 
   3915  1.1  riastrad 	if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw)
   3916  1.1  riastrad 		return -EINVAL;
   3917  1.1  riastrad 
   3918  1.1  riastrad 	cik_cp_gfx_enable(rdev, false);
   3919  1.1  riastrad 
   3920  1.1  riastrad 	if (rdev->new_fw) {
   3921  1.1  riastrad 		const struct gfx_firmware_header_v1_0 *pfp_hdr =
   3922  1.1  riastrad 			(const struct gfx_firmware_header_v1_0 *)rdev->pfp_fw->data;
   3923  1.1  riastrad 		const struct gfx_firmware_header_v1_0 *ce_hdr =
   3924  1.1  riastrad 			(const struct gfx_firmware_header_v1_0 *)rdev->ce_fw->data;
   3925  1.1  riastrad 		const struct gfx_firmware_header_v1_0 *me_hdr =
   3926  1.1  riastrad 			(const struct gfx_firmware_header_v1_0 *)rdev->me_fw->data;
   3927  1.1  riastrad 		const __le32 *fw_data;
   3928  1.1  riastrad 		u32 fw_size;
   3929  1.1  riastrad 
   3930  1.1  riastrad 		radeon_ucode_print_gfx_hdr(&pfp_hdr->header);
   3931  1.1  riastrad 		radeon_ucode_print_gfx_hdr(&ce_hdr->header);
   3932  1.1  riastrad 		radeon_ucode_print_gfx_hdr(&me_hdr->header);
   3933  1.1  riastrad 
   3934  1.1  riastrad 		/* PFP */
   3935  1.1  riastrad 		fw_data = (const __le32 *)
   3936  1.1  riastrad 			(rdev->pfp_fw->data + le32_to_cpu(pfp_hdr->header.ucode_array_offset_bytes));
   3937  1.1  riastrad 		fw_size = le32_to_cpu(pfp_hdr->header.ucode_size_bytes) / 4;
   3938  1.1  riastrad 		WREG32(CP_PFP_UCODE_ADDR, 0);
   3939  1.1  riastrad 		for (i = 0; i < fw_size; i++)
   3940  1.1  riastrad 			WREG32(CP_PFP_UCODE_DATA, le32_to_cpup(fw_data++));
   3941  1.1  riastrad 		WREG32(CP_PFP_UCODE_ADDR, le32_to_cpu(pfp_hdr->header.ucode_version));
   3942  1.1  riastrad 
   3943  1.1  riastrad 		/* CE */
   3944  1.1  riastrad 		fw_data = (const __le32 *)
   3945  1.1  riastrad 			(rdev->ce_fw->data + le32_to_cpu(ce_hdr->header.ucode_array_offset_bytes));
   3946  1.1  riastrad 		fw_size = le32_to_cpu(ce_hdr->header.ucode_size_bytes) / 4;
   3947  1.1  riastrad 		WREG32(CP_CE_UCODE_ADDR, 0);
   3948  1.1  riastrad 		for (i = 0; i < fw_size; i++)
   3949  1.1  riastrad 			WREG32(CP_CE_UCODE_DATA, le32_to_cpup(fw_data++));
   3950  1.1  riastrad 		WREG32(CP_CE_UCODE_ADDR, le32_to_cpu(ce_hdr->header.ucode_version));
   3951  1.1  riastrad 
   3952  1.1  riastrad 		/* ME */
   3953  1.1  riastrad 		fw_data = (const __be32 *)
   3954  1.1  riastrad 			(rdev->me_fw->data + le32_to_cpu(me_hdr->header.ucode_array_offset_bytes));
   3955  1.1  riastrad 		fw_size = le32_to_cpu(me_hdr->header.ucode_size_bytes) / 4;
   3956  1.1  riastrad 		WREG32(CP_ME_RAM_WADDR, 0);
   3957  1.1  riastrad 		for (i = 0; i < fw_size; i++)
   3958  1.1  riastrad 			WREG32(CP_ME_RAM_DATA, le32_to_cpup(fw_data++));
   3959  1.1  riastrad 		WREG32(CP_ME_RAM_WADDR, le32_to_cpu(me_hdr->header.ucode_version));
   3960  1.1  riastrad 		WREG32(CP_ME_RAM_RADDR, le32_to_cpu(me_hdr->header.ucode_version));
   3961  1.1  riastrad 	} else {
   3962  1.1  riastrad 		const __be32 *fw_data;
   3963  1.1  riastrad 
   3964  1.1  riastrad 		/* PFP */
   3965  1.1  riastrad 		fw_data = (const __be32 *)rdev->pfp_fw->data;
   3966  1.1  riastrad 		WREG32(CP_PFP_UCODE_ADDR, 0);
   3967  1.1  riastrad 		for (i = 0; i < CIK_PFP_UCODE_SIZE; i++)
   3968  1.1  riastrad 			WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
   3969  1.1  riastrad 		WREG32(CP_PFP_UCODE_ADDR, 0);
   3970  1.1  riastrad 
   3971  1.1  riastrad 		/* CE */
   3972  1.1  riastrad 		fw_data = (const __be32 *)rdev->ce_fw->data;
   3973  1.1  riastrad 		WREG32(CP_CE_UCODE_ADDR, 0);
   3974  1.1  riastrad 		for (i = 0; i < CIK_CE_UCODE_SIZE; i++)
   3975  1.1  riastrad 			WREG32(CP_CE_UCODE_DATA, be32_to_cpup(fw_data++));
   3976  1.1  riastrad 		WREG32(CP_CE_UCODE_ADDR, 0);
   3977  1.1  riastrad 
   3978  1.1  riastrad 		/* ME */
   3979  1.1  riastrad 		fw_data = (const __be32 *)rdev->me_fw->data;
   3980  1.1  riastrad 		WREG32(CP_ME_RAM_WADDR, 0);
   3981  1.1  riastrad 		for (i = 0; i < CIK_ME_UCODE_SIZE; i++)
   3982  1.1  riastrad 			WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
   3983  1.1  riastrad 		WREG32(CP_ME_RAM_WADDR, 0);
   3984  1.1  riastrad 	}
   3985  1.1  riastrad 
   3986  1.1  riastrad 	return 0;
   3987  1.1  riastrad }
   3988  1.1  riastrad 
   3989  1.1  riastrad /**
   3990  1.1  riastrad  * cik_cp_gfx_start - start the gfx ring
   3991  1.1  riastrad  *
   3992  1.1  riastrad  * @rdev: radeon_device pointer
   3993  1.1  riastrad  *
   3994  1.1  riastrad  * Enables the ring and loads the clear state context and other
   3995  1.1  riastrad  * packets required to init the ring.
   3996  1.1  riastrad  * Returns 0 for success, error for failure.
   3997  1.1  riastrad  */
   3998  1.1  riastrad static int cik_cp_gfx_start(struct radeon_device *rdev)
   3999  1.1  riastrad {
   4000  1.1  riastrad 	struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
   4001  1.1  riastrad 	int r, i;
   4002  1.1  riastrad 
   4003  1.1  riastrad 	/* init the CP */
   4004  1.1  riastrad 	WREG32(CP_MAX_CONTEXT, rdev->config.cik.max_hw_contexts - 1);
   4005  1.1  riastrad 	WREG32(CP_ENDIAN_SWAP, 0);
   4006  1.1  riastrad 	WREG32(CP_DEVICE_ID, 1);
   4007  1.1  riastrad 
   4008  1.1  riastrad 	cik_cp_gfx_enable(rdev, true);
   4009  1.1  riastrad 
   4010  1.1  riastrad 	r = radeon_ring_lock(rdev, ring, cik_default_size + 17);
   4011  1.1  riastrad 	if (r) {
   4012  1.1  riastrad 		DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
   4013  1.1  riastrad 		return r;
   4014  1.1  riastrad 	}
   4015  1.1  riastrad 
   4016  1.1  riastrad 	/* init the CE partitions.  CE only used for gfx on CIK */
   4017  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
   4018  1.1  riastrad 	radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
   4019  1.1  riastrad 	radeon_ring_write(ring, 0x8000);
   4020  1.1  riastrad 	radeon_ring_write(ring, 0x8000);
   4021  1.1  riastrad 
   4022  1.1  riastrad 	/* setup clear context state */
   4023  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
   4024  1.1  riastrad 	radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
   4025  1.1  riastrad 
   4026  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_CONTEXT_CONTROL, 1));
   4027  1.1  riastrad 	radeon_ring_write(ring, 0x80000000);
   4028  1.1  riastrad 	radeon_ring_write(ring, 0x80000000);
   4029  1.1  riastrad 
   4030  1.1  riastrad 	for (i = 0; i < cik_default_size; i++)
   4031  1.1  riastrad 		radeon_ring_write(ring, cik_default_state[i]);
   4032  1.1  riastrad 
   4033  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
   4034  1.1  riastrad 	radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
   4035  1.1  riastrad 
   4036  1.1  riastrad 	/* set clear context state */
   4037  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
   4038  1.1  riastrad 	radeon_ring_write(ring, 0);
   4039  1.1  riastrad 
   4040  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
   4041  1.1  riastrad 	radeon_ring_write(ring, 0x00000316);
   4042  1.1  riastrad 	radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
   4043  1.1  riastrad 	radeon_ring_write(ring, 0x00000010); /* VGT_OUT_DEALLOC_CNTL */
   4044  1.1  riastrad 
   4045  1.1  riastrad 	radeon_ring_unlock_commit(rdev, ring, false);
   4046  1.1  riastrad 
   4047  1.1  riastrad 	return 0;
   4048  1.1  riastrad }
   4049  1.1  riastrad 
   4050  1.1  riastrad /**
   4051  1.1  riastrad  * cik_cp_gfx_fini - stop the gfx ring
   4052  1.1  riastrad  *
   4053  1.1  riastrad  * @rdev: radeon_device pointer
   4054  1.1  riastrad  *
   4055  1.1  riastrad  * Stop the gfx ring and tear down the driver ring
   4056  1.1  riastrad  * info.
   4057  1.1  riastrad  */
   4058  1.1  riastrad static void cik_cp_gfx_fini(struct radeon_device *rdev)
   4059  1.1  riastrad {
   4060  1.1  riastrad 	cik_cp_gfx_enable(rdev, false);
   4061  1.1  riastrad 	radeon_ring_fini(rdev, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
   4062  1.1  riastrad }
   4063  1.1  riastrad 
   4064  1.1  riastrad /**
   4065  1.1  riastrad  * cik_cp_gfx_resume - setup the gfx ring buffer registers
   4066  1.1  riastrad  *
   4067  1.1  riastrad  * @rdev: radeon_device pointer
   4068  1.1  riastrad  *
   4069  1.1  riastrad  * Program the location and size of the gfx ring buffer
   4070  1.1  riastrad  * and test it to make sure it's working.
   4071  1.1  riastrad  * Returns 0 for success, error for failure.
   4072  1.1  riastrad  */
   4073  1.1  riastrad static int cik_cp_gfx_resume(struct radeon_device *rdev)
   4074  1.1  riastrad {
   4075  1.1  riastrad 	struct radeon_ring *ring;
   4076  1.1  riastrad 	u32 tmp;
   4077  1.1  riastrad 	u32 rb_bufsz;
   4078  1.1  riastrad 	u64 rb_addr;
   4079  1.1  riastrad 	int r;
   4080  1.1  riastrad 
   4081  1.1  riastrad 	WREG32(CP_SEM_WAIT_TIMER, 0x0);
   4082  1.1  riastrad 	if (rdev->family != CHIP_HAWAII)
   4083  1.1  riastrad 		WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
   4084  1.1  riastrad 
   4085  1.1  riastrad 	/* Set the write pointer delay */
   4086  1.1  riastrad 	WREG32(CP_RB_WPTR_DELAY, 0);
   4087  1.1  riastrad 
   4088  1.1  riastrad 	/* set the RB to use vmid 0 */
   4089  1.1  riastrad 	WREG32(CP_RB_VMID, 0);
   4090  1.1  riastrad 
   4091  1.1  riastrad 	WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
   4092  1.1  riastrad 
   4093  1.1  riastrad 	/* ring 0 - compute and gfx */
   4094  1.1  riastrad 	/* Set ring buffer size */
   4095  1.1  riastrad 	ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
   4096  1.1  riastrad 	rb_bufsz = order_base_2(ring->ring_size / 8);
   4097  1.1  riastrad 	tmp = (order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
   4098  1.1  riastrad #ifdef __BIG_ENDIAN
   4099  1.1  riastrad 	tmp |= BUF_SWAP_32BIT;
   4100  1.1  riastrad #endif
   4101  1.1  riastrad 	WREG32(CP_RB0_CNTL, tmp);
   4102  1.1  riastrad 
   4103  1.1  riastrad 	/* Initialize the ring buffer's read and write pointers */
   4104  1.1  riastrad 	WREG32(CP_RB0_CNTL, tmp | RB_RPTR_WR_ENA);
   4105  1.1  riastrad 	ring->wptr = 0;
   4106  1.1  riastrad 	WREG32(CP_RB0_WPTR, ring->wptr);
   4107  1.1  riastrad 
   4108  1.1  riastrad 	/* set the wb address wether it's enabled or not */
   4109  1.1  riastrad 	WREG32(CP_RB0_RPTR_ADDR, (rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFFFFFFFC);
   4110  1.1  riastrad 	WREG32(CP_RB0_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) & 0xFF);
   4111  1.1  riastrad 
   4112  1.1  riastrad 	/* scratch register shadowing is no longer supported */
   4113  1.1  riastrad 	WREG32(SCRATCH_UMSK, 0);
   4114  1.1  riastrad 
   4115  1.1  riastrad 	if (!rdev->wb.enabled)
   4116  1.1  riastrad 		tmp |= RB_NO_UPDATE;
   4117  1.1  riastrad 
   4118  1.1  riastrad 	mdelay(1);
   4119  1.1  riastrad 	WREG32(CP_RB0_CNTL, tmp);
   4120  1.1  riastrad 
   4121  1.1  riastrad 	rb_addr = ring->gpu_addr >> 8;
   4122  1.1  riastrad 	WREG32(CP_RB0_BASE, rb_addr);
   4123  1.1  riastrad 	WREG32(CP_RB0_BASE_HI, upper_32_bits(rb_addr));
   4124  1.1  riastrad 
   4125  1.1  riastrad 	/* start the ring */
   4126  1.1  riastrad 	cik_cp_gfx_start(rdev);
   4127  1.1  riastrad 	rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
   4128  1.1  riastrad 	r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
   4129  1.1  riastrad 	if (r) {
   4130  1.1  riastrad 		rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
   4131  1.1  riastrad 		return r;
   4132  1.1  riastrad 	}
   4133  1.1  riastrad 
   4134  1.1  riastrad 	if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
   4135  1.1  riastrad 		radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
   4136  1.1  riastrad 
   4137  1.1  riastrad 	return 0;
   4138  1.1  riastrad }
   4139  1.1  riastrad 
   4140  1.1  riastrad u32 cik_gfx_get_rptr(struct radeon_device *rdev,
   4141  1.1  riastrad 		     struct radeon_ring *ring)
   4142  1.1  riastrad {
   4143  1.1  riastrad 	u32 rptr;
   4144  1.1  riastrad 
   4145  1.1  riastrad 	if (rdev->wb.enabled)
   4146  1.1  riastrad 		rptr = rdev->wb.wb[ring->rptr_offs/4];
   4147  1.1  riastrad 	else
   4148  1.1  riastrad 		rptr = RREG32(CP_RB0_RPTR);
   4149  1.1  riastrad 
   4150  1.1  riastrad 	return rptr;
   4151  1.1  riastrad }
   4152  1.1  riastrad 
   4153  1.1  riastrad u32 cik_gfx_get_wptr(struct radeon_device *rdev,
   4154  1.1  riastrad 		     struct radeon_ring *ring)
   4155  1.1  riastrad {
   4156  1.3  riastrad 	return RREG32(CP_RB0_WPTR);
   4157  1.1  riastrad }
   4158  1.1  riastrad 
   4159  1.1  riastrad void cik_gfx_set_wptr(struct radeon_device *rdev,
   4160  1.1  riastrad 		      struct radeon_ring *ring)
   4161  1.1  riastrad {
   4162  1.1  riastrad 	WREG32(CP_RB0_WPTR, ring->wptr);
   4163  1.1  riastrad 	(void)RREG32(CP_RB0_WPTR);
   4164  1.1  riastrad }
   4165  1.1  riastrad 
   4166  1.1  riastrad u32 cik_compute_get_rptr(struct radeon_device *rdev,
   4167  1.1  riastrad 			 struct radeon_ring *ring)
   4168  1.1  riastrad {
   4169  1.1  riastrad 	u32 rptr;
   4170  1.1  riastrad 
   4171  1.1  riastrad 	if (rdev->wb.enabled) {
   4172  1.1  riastrad 		rptr = rdev->wb.wb[ring->rptr_offs/4];
   4173  1.1  riastrad 	} else {
   4174  1.1  riastrad 		mutex_lock(&rdev->srbm_mutex);
   4175  1.1  riastrad 		cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
   4176  1.1  riastrad 		rptr = RREG32(CP_HQD_PQ_RPTR);
   4177  1.1  riastrad 		cik_srbm_select(rdev, 0, 0, 0, 0);
   4178  1.1  riastrad 		mutex_unlock(&rdev->srbm_mutex);
   4179  1.1  riastrad 	}
   4180  1.1  riastrad 
   4181  1.1  riastrad 	return rptr;
   4182  1.1  riastrad }
   4183  1.1  riastrad 
   4184  1.1  riastrad u32 cik_compute_get_wptr(struct radeon_device *rdev,
   4185  1.1  riastrad 			 struct radeon_ring *ring)
   4186  1.1  riastrad {
   4187  1.1  riastrad 	u32 wptr;
   4188  1.1  riastrad 
   4189  1.1  riastrad 	if (rdev->wb.enabled) {
   4190  1.1  riastrad 		/* XXX check if swapping is necessary on BE */
   4191  1.1  riastrad 		wptr = rdev->wb.wb[ring->wptr_offs/4];
   4192  1.1  riastrad 	} else {
   4193  1.1  riastrad 		mutex_lock(&rdev->srbm_mutex);
   4194  1.1  riastrad 		cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
   4195  1.1  riastrad 		wptr = RREG32(CP_HQD_PQ_WPTR);
   4196  1.1  riastrad 		cik_srbm_select(rdev, 0, 0, 0, 0);
   4197  1.1  riastrad 		mutex_unlock(&rdev->srbm_mutex);
   4198  1.1  riastrad 	}
   4199  1.1  riastrad 
   4200  1.1  riastrad 	return wptr;
   4201  1.1  riastrad }
   4202  1.1  riastrad 
   4203  1.1  riastrad void cik_compute_set_wptr(struct radeon_device *rdev,
   4204  1.1  riastrad 			  struct radeon_ring *ring)
   4205  1.1  riastrad {
   4206  1.1  riastrad 	/* XXX check if swapping is necessary on BE */
   4207  1.1  riastrad 	rdev->wb.wb[ring->wptr_offs/4] = ring->wptr;
   4208  1.1  riastrad 	WDOORBELL32(ring->doorbell_index, ring->wptr);
   4209  1.1  riastrad }
   4210  1.1  riastrad 
   4211  1.1  riastrad static void cik_compute_stop(struct radeon_device *rdev,
   4212  1.1  riastrad 			     struct radeon_ring *ring)
   4213  1.1  riastrad {
   4214  1.1  riastrad 	u32 j, tmp;
   4215  1.1  riastrad 
   4216  1.1  riastrad 	cik_srbm_select(rdev, ring->me, ring->pipe, ring->queue, 0);
   4217  1.1  riastrad 	/* Disable wptr polling. */
   4218  1.1  riastrad 	tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
   4219  1.1  riastrad 	tmp &= ~WPTR_POLL_EN;
   4220  1.1  riastrad 	WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
   4221  1.1  riastrad 	/* Disable HQD. */
   4222  1.1  riastrad 	if (RREG32(CP_HQD_ACTIVE) & 1) {
   4223  1.1  riastrad 		WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
   4224  1.1  riastrad 		for (j = 0; j < rdev->usec_timeout; j++) {
   4225  1.1  riastrad 			if (!(RREG32(CP_HQD_ACTIVE) & 1))
   4226  1.1  riastrad 				break;
   4227  1.1  riastrad 			udelay(1);
   4228  1.1  riastrad 		}
   4229  1.1  riastrad 		WREG32(CP_HQD_DEQUEUE_REQUEST, 0);
   4230  1.1  riastrad 		WREG32(CP_HQD_PQ_RPTR, 0);
   4231  1.1  riastrad 		WREG32(CP_HQD_PQ_WPTR, 0);
   4232  1.1  riastrad 	}
   4233  1.1  riastrad 	cik_srbm_select(rdev, 0, 0, 0, 0);
   4234  1.1  riastrad }
   4235  1.1  riastrad 
   4236  1.1  riastrad /**
   4237  1.1  riastrad  * cik_cp_compute_enable - enable/disable the compute CP MEs
   4238  1.1  riastrad  *
   4239  1.1  riastrad  * @rdev: radeon_device pointer
   4240  1.1  riastrad  * @enable: enable or disable the MEs
   4241  1.1  riastrad  *
   4242  1.1  riastrad  * Halts or unhalts the compute MEs.
   4243  1.1  riastrad  */
   4244  1.1  riastrad static void cik_cp_compute_enable(struct radeon_device *rdev, bool enable)
   4245  1.1  riastrad {
   4246  1.1  riastrad 	if (enable)
   4247  1.1  riastrad 		WREG32(CP_MEC_CNTL, 0);
   4248  1.1  riastrad 	else {
   4249  1.1  riastrad 		/*
   4250  1.1  riastrad 		 * To make hibernation reliable we need to clear compute ring
   4251  1.1  riastrad 		 * configuration before halting the compute ring.
   4252  1.1  riastrad 		 */
   4253  1.1  riastrad 		mutex_lock(&rdev->srbm_mutex);
   4254  1.1  riastrad 		cik_compute_stop(rdev,&rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX]);
   4255  1.1  riastrad 		cik_compute_stop(rdev,&rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX]);
   4256  1.1  riastrad 		mutex_unlock(&rdev->srbm_mutex);
   4257  1.1  riastrad 
   4258  1.1  riastrad 		WREG32(CP_MEC_CNTL, (MEC_ME1_HALT | MEC_ME2_HALT));
   4259  1.1  riastrad 		rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
   4260  1.1  riastrad 		rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
   4261  1.1  riastrad 	}
   4262  1.1  riastrad 	udelay(50);
   4263  1.1  riastrad }
   4264  1.1  riastrad 
   4265  1.1  riastrad /**
   4266  1.1  riastrad  * cik_cp_compute_load_microcode - load the compute CP ME ucode
   4267  1.1  riastrad  *
   4268  1.1  riastrad  * @rdev: radeon_device pointer
   4269  1.1  riastrad  *
   4270  1.1  riastrad  * Loads the compute MEC1&2 ucode.
   4271  1.1  riastrad  * Returns 0 for success, -EINVAL if the ucode is not available.
   4272  1.1  riastrad  */
   4273  1.1  riastrad static int cik_cp_compute_load_microcode(struct radeon_device *rdev)
   4274  1.1  riastrad {
   4275  1.1  riastrad 	int i;
   4276  1.1  riastrad 
   4277  1.1  riastrad 	if (!rdev->mec_fw)
   4278  1.1  riastrad 		return -EINVAL;
   4279  1.1  riastrad 
   4280  1.1  riastrad 	cik_cp_compute_enable(rdev, false);
   4281  1.1  riastrad 
   4282  1.1  riastrad 	if (rdev->new_fw) {
   4283  1.1  riastrad 		const struct gfx_firmware_header_v1_0 *mec_hdr =
   4284  1.1  riastrad 			(const struct gfx_firmware_header_v1_0 *)rdev->mec_fw->data;
   4285  1.1  riastrad 		const __le32 *fw_data;
   4286  1.1  riastrad 		u32 fw_size;
   4287  1.1  riastrad 
   4288  1.1  riastrad 		radeon_ucode_print_gfx_hdr(&mec_hdr->header);
   4289  1.1  riastrad 
   4290  1.1  riastrad 		/* MEC1 */
   4291  1.1  riastrad 		fw_data = (const __le32 *)
   4292  1.1  riastrad 			(rdev->mec_fw->data + le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
   4293  1.1  riastrad 		fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes) / 4;
   4294  1.1  riastrad 		WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
   4295  1.1  riastrad 		for (i = 0; i < fw_size; i++)
   4296  1.1  riastrad 			WREG32(CP_MEC_ME1_UCODE_DATA, le32_to_cpup(fw_data++));
   4297  1.1  riastrad 		WREG32(CP_MEC_ME1_UCODE_ADDR, le32_to_cpu(mec_hdr->header.ucode_version));
   4298  1.1  riastrad 
   4299  1.1  riastrad 		/* MEC2 */
   4300  1.1  riastrad 		if (rdev->family == CHIP_KAVERI) {
   4301  1.1  riastrad 			const struct gfx_firmware_header_v1_0 *mec2_hdr =
   4302  1.1  riastrad 				(const struct gfx_firmware_header_v1_0 *)rdev->mec2_fw->data;
   4303  1.1  riastrad 
   4304  1.1  riastrad 			fw_data = (const __le32 *)
   4305  1.1  riastrad 				(rdev->mec2_fw->data +
   4306  1.1  riastrad 				 le32_to_cpu(mec2_hdr->header.ucode_array_offset_bytes));
   4307  1.1  riastrad 			fw_size = le32_to_cpu(mec2_hdr->header.ucode_size_bytes) / 4;
   4308  1.1  riastrad 			WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
   4309  1.1  riastrad 			for (i = 0; i < fw_size; i++)
   4310  1.1  riastrad 				WREG32(CP_MEC_ME2_UCODE_DATA, le32_to_cpup(fw_data++));
   4311  1.1  riastrad 			WREG32(CP_MEC_ME2_UCODE_ADDR, le32_to_cpu(mec2_hdr->header.ucode_version));
   4312  1.1  riastrad 		}
   4313  1.1  riastrad 	} else {
   4314  1.1  riastrad 		const __be32 *fw_data;
   4315  1.1  riastrad 
   4316  1.1  riastrad 		/* MEC1 */
   4317  1.1  riastrad 		fw_data = (const __be32 *)rdev->mec_fw->data;
   4318  1.1  riastrad 		WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
   4319  1.1  riastrad 		for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
   4320  1.1  riastrad 			WREG32(CP_MEC_ME1_UCODE_DATA, be32_to_cpup(fw_data++));
   4321  1.1  riastrad 		WREG32(CP_MEC_ME1_UCODE_ADDR, 0);
   4322  1.1  riastrad 
   4323  1.1  riastrad 		if (rdev->family == CHIP_KAVERI) {
   4324  1.1  riastrad 			/* MEC2 */
   4325  1.1  riastrad 			fw_data = (const __be32 *)rdev->mec_fw->data;
   4326  1.1  riastrad 			WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
   4327  1.1  riastrad 			for (i = 0; i < CIK_MEC_UCODE_SIZE; i++)
   4328  1.1  riastrad 				WREG32(CP_MEC_ME2_UCODE_DATA, be32_to_cpup(fw_data++));
   4329  1.1  riastrad 			WREG32(CP_MEC_ME2_UCODE_ADDR, 0);
   4330  1.1  riastrad 		}
   4331  1.1  riastrad 	}
   4332  1.1  riastrad 
   4333  1.1  riastrad 	return 0;
   4334  1.1  riastrad }
   4335  1.1  riastrad 
   4336  1.1  riastrad /**
   4337  1.1  riastrad  * cik_cp_compute_start - start the compute queues
   4338  1.1  riastrad  *
   4339  1.1  riastrad  * @rdev: radeon_device pointer
   4340  1.1  riastrad  *
   4341  1.1  riastrad  * Enable the compute queues.
   4342  1.1  riastrad  * Returns 0 for success, error for failure.
   4343  1.1  riastrad  */
   4344  1.1  riastrad static int cik_cp_compute_start(struct radeon_device *rdev)
   4345  1.1  riastrad {
   4346  1.1  riastrad 	cik_cp_compute_enable(rdev, true);
   4347  1.1  riastrad 
   4348  1.1  riastrad 	return 0;
   4349  1.1  riastrad }
   4350  1.1  riastrad 
   4351  1.1  riastrad /**
   4352  1.1  riastrad  * cik_cp_compute_fini - stop the compute queues
   4353  1.1  riastrad  *
   4354  1.1  riastrad  * @rdev: radeon_device pointer
   4355  1.1  riastrad  *
   4356  1.1  riastrad  * Stop the compute queues and tear down the driver queue
   4357  1.1  riastrad  * info.
   4358  1.1  riastrad  */
   4359  1.1  riastrad static void cik_cp_compute_fini(struct radeon_device *rdev)
   4360  1.1  riastrad {
   4361  1.1  riastrad 	int i, idx, r;
   4362  1.1  riastrad 
   4363  1.1  riastrad 	cik_cp_compute_enable(rdev, false);
   4364  1.1  riastrad 
   4365  1.1  riastrad 	for (i = 0; i < 2; i++) {
   4366  1.1  riastrad 		if (i == 0)
   4367  1.1  riastrad 			idx = CAYMAN_RING_TYPE_CP1_INDEX;
   4368  1.1  riastrad 		else
   4369  1.1  riastrad 			idx = CAYMAN_RING_TYPE_CP2_INDEX;
   4370  1.1  riastrad 
   4371  1.1  riastrad 		if (rdev->ring[idx].mqd_obj) {
   4372  1.1  riastrad 			r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
   4373  1.1  riastrad 			if (unlikely(r != 0))
   4374  1.1  riastrad 				dev_warn(rdev->dev, "(%d) reserve MQD bo failed\n", r);
   4375  1.1  riastrad 
   4376  1.1  riastrad 			radeon_bo_unpin(rdev->ring[idx].mqd_obj);
   4377  1.1  riastrad 			radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
   4378  1.1  riastrad 
   4379  1.1  riastrad 			radeon_bo_unref(&rdev->ring[idx].mqd_obj);
   4380  1.1  riastrad 			rdev->ring[idx].mqd_obj = NULL;
   4381  1.1  riastrad 		}
   4382  1.1  riastrad 	}
   4383  1.1  riastrad }
   4384  1.1  riastrad 
   4385  1.1  riastrad static void cik_mec_fini(struct radeon_device *rdev)
   4386  1.1  riastrad {
   4387  1.1  riastrad 	int r;
   4388  1.1  riastrad 
   4389  1.1  riastrad 	if (rdev->mec.hpd_eop_obj) {
   4390  1.1  riastrad 		r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
   4391  1.1  riastrad 		if (unlikely(r != 0))
   4392  1.1  riastrad 			dev_warn(rdev->dev, "(%d) reserve HPD EOP bo failed\n", r);
   4393  1.1  riastrad 		radeon_bo_unpin(rdev->mec.hpd_eop_obj);
   4394  1.1  riastrad 		radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
   4395  1.1  riastrad 
   4396  1.1  riastrad 		radeon_bo_unref(&rdev->mec.hpd_eop_obj);
   4397  1.1  riastrad 		rdev->mec.hpd_eop_obj = NULL;
   4398  1.1  riastrad 	}
   4399  1.1  riastrad }
   4400  1.1  riastrad 
   4401  1.1  riastrad #define MEC_HPD_SIZE 2048
   4402  1.1  riastrad 
   4403  1.1  riastrad static int cik_mec_init(struct radeon_device *rdev)
   4404  1.1  riastrad {
   4405  1.1  riastrad 	int r;
   4406  1.1  riastrad 	u32 *hpd;
   4407  1.1  riastrad 
   4408  1.1  riastrad 	/*
   4409  1.1  riastrad 	 * KV:    2 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 64 Queues total
   4410  1.1  riastrad 	 * CI/KB: 1 MEC, 4 Pipes/MEC, 8 Queues/Pipe - 32 Queues total
   4411  1.1  riastrad 	 */
   4412  1.3  riastrad 	if (rdev->family == CHIP_KAVERI)
   4413  1.3  riastrad 		rdev->mec.num_mec = 2;
   4414  1.3  riastrad 	else
   4415  1.3  riastrad 		rdev->mec.num_mec = 1;
   4416  1.3  riastrad 	rdev->mec.num_pipe = 4;
   4417  1.1  riastrad 	rdev->mec.num_queue = rdev->mec.num_mec * rdev->mec.num_pipe * 8;
   4418  1.1  riastrad 
   4419  1.1  riastrad 	if (rdev->mec.hpd_eop_obj == NULL) {
   4420  1.1  riastrad 		r = radeon_bo_create(rdev,
   4421  1.1  riastrad 				     rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2,
   4422  1.1  riastrad 				     PAGE_SIZE, true,
   4423  1.1  riastrad 				     RADEON_GEM_DOMAIN_GTT, 0, NULL, NULL,
   4424  1.1  riastrad 				     &rdev->mec.hpd_eop_obj);
   4425  1.1  riastrad 		if (r) {
   4426  1.1  riastrad 			dev_warn(rdev->dev, "(%d) create HDP EOP bo failed\n", r);
   4427  1.1  riastrad 			return r;
   4428  1.1  riastrad 		}
   4429  1.1  riastrad 	}
   4430  1.1  riastrad 
   4431  1.1  riastrad 	r = radeon_bo_reserve(rdev->mec.hpd_eop_obj, false);
   4432  1.1  riastrad 	if (unlikely(r != 0)) {
   4433  1.1  riastrad 		cik_mec_fini(rdev);
   4434  1.1  riastrad 		return r;
   4435  1.1  riastrad 	}
   4436  1.1  riastrad 	r = radeon_bo_pin(rdev->mec.hpd_eop_obj, RADEON_GEM_DOMAIN_GTT,
   4437  1.1  riastrad 			  &rdev->mec.hpd_eop_gpu_addr);
   4438  1.1  riastrad 	if (r) {
   4439  1.1  riastrad 		dev_warn(rdev->dev, "(%d) pin HDP EOP bo failed\n", r);
   4440  1.1  riastrad 		cik_mec_fini(rdev);
   4441  1.1  riastrad 		return r;
   4442  1.1  riastrad 	}
   4443  1.1  riastrad 	r = radeon_bo_kmap(rdev->mec.hpd_eop_obj, (void **)&hpd);
   4444  1.1  riastrad 	if (r) {
   4445  1.1  riastrad 		dev_warn(rdev->dev, "(%d) map HDP EOP bo failed\n", r);
   4446  1.1  riastrad 		cik_mec_fini(rdev);
   4447  1.1  riastrad 		return r;
   4448  1.1  riastrad 	}
   4449  1.1  riastrad 
   4450  1.1  riastrad 	/* clear memory.  Not sure if this is required or not */
   4451  1.1  riastrad 	memset(hpd, 0, rdev->mec.num_mec *rdev->mec.num_pipe * MEC_HPD_SIZE * 2);
   4452  1.1  riastrad 
   4453  1.1  riastrad 	radeon_bo_kunmap(rdev->mec.hpd_eop_obj);
   4454  1.1  riastrad 	radeon_bo_unreserve(rdev->mec.hpd_eop_obj);
   4455  1.1  riastrad 
   4456  1.1  riastrad 	return 0;
   4457  1.1  riastrad }
   4458  1.1  riastrad 
   4459  1.1  riastrad struct hqd_registers
   4460  1.1  riastrad {
   4461  1.1  riastrad 	u32 cp_mqd_base_addr;
   4462  1.1  riastrad 	u32 cp_mqd_base_addr_hi;
   4463  1.1  riastrad 	u32 cp_hqd_active;
   4464  1.1  riastrad 	u32 cp_hqd_vmid;
   4465  1.1  riastrad 	u32 cp_hqd_persistent_state;
   4466  1.1  riastrad 	u32 cp_hqd_pipe_priority;
   4467  1.1  riastrad 	u32 cp_hqd_queue_priority;
   4468  1.1  riastrad 	u32 cp_hqd_quantum;
   4469  1.1  riastrad 	u32 cp_hqd_pq_base;
   4470  1.1  riastrad 	u32 cp_hqd_pq_base_hi;
   4471  1.1  riastrad 	u32 cp_hqd_pq_rptr;
   4472  1.1  riastrad 	u32 cp_hqd_pq_rptr_report_addr;
   4473  1.1  riastrad 	u32 cp_hqd_pq_rptr_report_addr_hi;
   4474  1.1  riastrad 	u32 cp_hqd_pq_wptr_poll_addr;
   4475  1.1  riastrad 	u32 cp_hqd_pq_wptr_poll_addr_hi;
   4476  1.1  riastrad 	u32 cp_hqd_pq_doorbell_control;
   4477  1.1  riastrad 	u32 cp_hqd_pq_wptr;
   4478  1.1  riastrad 	u32 cp_hqd_pq_control;
   4479  1.1  riastrad 	u32 cp_hqd_ib_base_addr;
   4480  1.1  riastrad 	u32 cp_hqd_ib_base_addr_hi;
   4481  1.1  riastrad 	u32 cp_hqd_ib_rptr;
   4482  1.1  riastrad 	u32 cp_hqd_ib_control;
   4483  1.1  riastrad 	u32 cp_hqd_iq_timer;
   4484  1.1  riastrad 	u32 cp_hqd_iq_rptr;
   4485  1.1  riastrad 	u32 cp_hqd_dequeue_request;
   4486  1.1  riastrad 	u32 cp_hqd_dma_offload;
   4487  1.1  riastrad 	u32 cp_hqd_sema_cmd;
   4488  1.1  riastrad 	u32 cp_hqd_msg_type;
   4489  1.1  riastrad 	u32 cp_hqd_atomic0_preop_lo;
   4490  1.1  riastrad 	u32 cp_hqd_atomic0_preop_hi;
   4491  1.1  riastrad 	u32 cp_hqd_atomic1_preop_lo;
   4492  1.1  riastrad 	u32 cp_hqd_atomic1_preop_hi;
   4493  1.1  riastrad 	u32 cp_hqd_hq_scheduler0;
   4494  1.1  riastrad 	u32 cp_hqd_hq_scheduler1;
   4495  1.1  riastrad 	u32 cp_mqd_control;
   4496  1.1  riastrad };
   4497  1.1  riastrad 
   4498  1.1  riastrad struct bonaire_mqd
   4499  1.1  riastrad {
   4500  1.1  riastrad 	u32 header;
   4501  1.1  riastrad 	u32 dispatch_initiator;
   4502  1.1  riastrad 	u32 dimensions[3];
   4503  1.1  riastrad 	u32 start_idx[3];
   4504  1.1  riastrad 	u32 num_threads[3];
   4505  1.1  riastrad 	u32 pipeline_stat_enable;
   4506  1.1  riastrad 	u32 perf_counter_enable;
   4507  1.1  riastrad 	u32 pgm[2];
   4508  1.1  riastrad 	u32 tba[2];
   4509  1.1  riastrad 	u32 tma[2];
   4510  1.1  riastrad 	u32 pgm_rsrc[2];
   4511  1.1  riastrad 	u32 vmid;
   4512  1.1  riastrad 	u32 resource_limits;
   4513  1.1  riastrad 	u32 static_thread_mgmt01[2];
   4514  1.1  riastrad 	u32 tmp_ring_size;
   4515  1.1  riastrad 	u32 static_thread_mgmt23[2];
   4516  1.1  riastrad 	u32 restart[3];
   4517  1.1  riastrad 	u32 thread_trace_enable;
   4518  1.1  riastrad 	u32 reserved1;
   4519  1.1  riastrad 	u32 user_data[16];
   4520  1.1  riastrad 	u32 vgtcs_invoke_count[2];
   4521  1.1  riastrad 	struct hqd_registers queue_state;
   4522  1.1  riastrad 	u32 dequeue_cntr;
   4523  1.1  riastrad 	u32 interrupt_queue[64];
   4524  1.1  riastrad };
   4525  1.1  riastrad 
   4526  1.1  riastrad /**
   4527  1.1  riastrad  * cik_cp_compute_resume - setup the compute queue registers
   4528  1.1  riastrad  *
   4529  1.1  riastrad  * @rdev: radeon_device pointer
   4530  1.1  riastrad  *
   4531  1.1  riastrad  * Program the compute queues and test them to make sure they
   4532  1.1  riastrad  * are working.
   4533  1.1  riastrad  * Returns 0 for success, error for failure.
   4534  1.1  riastrad  */
   4535  1.1  riastrad static int cik_cp_compute_resume(struct radeon_device *rdev)
   4536  1.1  riastrad {
   4537  1.1  riastrad 	int r, i, j, idx;
   4538  1.1  riastrad 	u32 tmp;
   4539  1.1  riastrad 	bool use_doorbell = true;
   4540  1.1  riastrad 	u64 hqd_gpu_addr;
   4541  1.1  riastrad 	u64 mqd_gpu_addr;
   4542  1.1  riastrad 	u64 eop_gpu_addr;
   4543  1.1  riastrad 	u64 wb_gpu_addr;
   4544  1.1  riastrad 	u32 *buf;
   4545  1.1  riastrad 	struct bonaire_mqd *mqd;
   4546  1.1  riastrad 
   4547  1.1  riastrad 	r = cik_cp_compute_start(rdev);
   4548  1.1  riastrad 	if (r)
   4549  1.1  riastrad 		return r;
   4550  1.1  riastrad 
   4551  1.1  riastrad 	/* fix up chicken bits */
   4552  1.1  riastrad 	tmp = RREG32(CP_CPF_DEBUG);
   4553  1.1  riastrad 	tmp |= (1 << 23);
   4554  1.1  riastrad 	WREG32(CP_CPF_DEBUG, tmp);
   4555  1.1  riastrad 
   4556  1.1  riastrad 	/* init the pipes */
   4557  1.1  riastrad 	mutex_lock(&rdev->srbm_mutex);
   4558  1.1  riastrad 
   4559  1.3  riastrad 	for (i = 0; i < (rdev->mec.num_pipe * rdev->mec.num_mec); ++i) {
   4560  1.3  riastrad 		int me = (i < 4) ? 1 : 2;
   4561  1.3  riastrad 		int pipe = (i < 4) ? i : (i - 4);
   4562  1.3  riastrad 
   4563  1.3  riastrad 		cik_srbm_select(rdev, me, pipe, 0, 0);
   4564  1.3  riastrad 
   4565  1.3  riastrad 		eop_gpu_addr = rdev->mec.hpd_eop_gpu_addr + (i * MEC_HPD_SIZE * 2) ;
   4566  1.3  riastrad 		/* write the EOP addr */
   4567  1.3  riastrad 		WREG32(CP_HPD_EOP_BASE_ADDR, eop_gpu_addr >> 8);
   4568  1.3  riastrad 		WREG32(CP_HPD_EOP_BASE_ADDR_HI, upper_32_bits(eop_gpu_addr) >> 8);
   4569  1.3  riastrad 
   4570  1.3  riastrad 		/* set the VMID assigned */
   4571  1.3  riastrad 		WREG32(CP_HPD_EOP_VMID, 0);
   4572  1.3  riastrad 
   4573  1.3  riastrad 		/* set the EOP size, register value is 2^(EOP_SIZE+1) dwords */
   4574  1.3  riastrad 		tmp = RREG32(CP_HPD_EOP_CONTROL);
   4575  1.3  riastrad 		tmp &= ~EOP_SIZE_MASK;
   4576  1.3  riastrad 		tmp |= order_base_2(MEC_HPD_SIZE / 8);
   4577  1.3  riastrad 		WREG32(CP_HPD_EOP_CONTROL, tmp);
   4578  1.1  riastrad 
   4579  1.3  riastrad 	}
   4580  1.1  riastrad 	cik_srbm_select(rdev, 0, 0, 0, 0);
   4581  1.1  riastrad 	mutex_unlock(&rdev->srbm_mutex);
   4582  1.1  riastrad 
   4583  1.1  riastrad 	/* init the queues.  Just two for now. */
   4584  1.1  riastrad 	for (i = 0; i < 2; i++) {
   4585  1.1  riastrad 		if (i == 0)
   4586  1.1  riastrad 			idx = CAYMAN_RING_TYPE_CP1_INDEX;
   4587  1.1  riastrad 		else
   4588  1.1  riastrad 			idx = CAYMAN_RING_TYPE_CP2_INDEX;
   4589  1.1  riastrad 
   4590  1.1  riastrad 		if (rdev->ring[idx].mqd_obj == NULL) {
   4591  1.1  riastrad 			r = radeon_bo_create(rdev,
   4592  1.1  riastrad 					     sizeof(struct bonaire_mqd),
   4593  1.1  riastrad 					     PAGE_SIZE, true,
   4594  1.1  riastrad 					     RADEON_GEM_DOMAIN_GTT, 0, NULL,
   4595  1.1  riastrad 					     NULL, &rdev->ring[idx].mqd_obj);
   4596  1.1  riastrad 			if (r) {
   4597  1.1  riastrad 				dev_warn(rdev->dev, "(%d) create MQD bo failed\n", r);
   4598  1.1  riastrad 				return r;
   4599  1.1  riastrad 			}
   4600  1.1  riastrad 		}
   4601  1.1  riastrad 
   4602  1.1  riastrad 		r = radeon_bo_reserve(rdev->ring[idx].mqd_obj, false);
   4603  1.1  riastrad 		if (unlikely(r != 0)) {
   4604  1.1  riastrad 			cik_cp_compute_fini(rdev);
   4605  1.1  riastrad 			return r;
   4606  1.1  riastrad 		}
   4607  1.1  riastrad 		r = radeon_bo_pin(rdev->ring[idx].mqd_obj, RADEON_GEM_DOMAIN_GTT,
   4608  1.1  riastrad 				  &mqd_gpu_addr);
   4609  1.1  riastrad 		if (r) {
   4610  1.1  riastrad 			dev_warn(rdev->dev, "(%d) pin MQD bo failed\n", r);
   4611  1.1  riastrad 			cik_cp_compute_fini(rdev);
   4612  1.1  riastrad 			return r;
   4613  1.1  riastrad 		}
   4614  1.1  riastrad 		r = radeon_bo_kmap(rdev->ring[idx].mqd_obj, (void **)&buf);
   4615  1.1  riastrad 		if (r) {
   4616  1.1  riastrad 			dev_warn(rdev->dev, "(%d) map MQD bo failed\n", r);
   4617  1.1  riastrad 			cik_cp_compute_fini(rdev);
   4618  1.1  riastrad 			return r;
   4619  1.1  riastrad 		}
   4620  1.1  riastrad 
   4621  1.1  riastrad 		/* init the mqd struct */
   4622  1.1  riastrad 		memset(buf, 0, sizeof(struct bonaire_mqd));
   4623  1.1  riastrad 
   4624  1.1  riastrad 		mqd = (struct bonaire_mqd *)buf;
   4625  1.1  riastrad 		mqd->header = 0xC0310800;
   4626  1.1  riastrad 		mqd->static_thread_mgmt01[0] = 0xffffffff;
   4627  1.1  riastrad 		mqd->static_thread_mgmt01[1] = 0xffffffff;
   4628  1.1  riastrad 		mqd->static_thread_mgmt23[0] = 0xffffffff;
   4629  1.1  riastrad 		mqd->static_thread_mgmt23[1] = 0xffffffff;
   4630  1.1  riastrad 
   4631  1.1  riastrad 		mutex_lock(&rdev->srbm_mutex);
   4632  1.1  riastrad 		cik_srbm_select(rdev, rdev->ring[idx].me,
   4633  1.1  riastrad 				rdev->ring[idx].pipe,
   4634  1.1  riastrad 				rdev->ring[idx].queue, 0);
   4635  1.1  riastrad 
   4636  1.1  riastrad 		/* disable wptr polling */
   4637  1.1  riastrad 		tmp = RREG32(CP_PQ_WPTR_POLL_CNTL);
   4638  1.1  riastrad 		tmp &= ~WPTR_POLL_EN;
   4639  1.1  riastrad 		WREG32(CP_PQ_WPTR_POLL_CNTL, tmp);
   4640  1.1  riastrad 
   4641  1.1  riastrad 		/* enable doorbell? */
   4642  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_doorbell_control =
   4643  1.1  riastrad 			RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
   4644  1.1  riastrad 		if (use_doorbell)
   4645  1.1  riastrad 			mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
   4646  1.1  riastrad 		else
   4647  1.1  riastrad 			mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_EN;
   4648  1.1  riastrad 		WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
   4649  1.1  riastrad 		       mqd->queue_state.cp_hqd_pq_doorbell_control);
   4650  1.1  riastrad 
   4651  1.1  riastrad 		/* disable the queue if it's active */
   4652  1.1  riastrad 		mqd->queue_state.cp_hqd_dequeue_request = 0;
   4653  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_rptr = 0;
   4654  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_wptr= 0;
   4655  1.1  riastrad 		if (RREG32(CP_HQD_ACTIVE) & 1) {
   4656  1.1  riastrad 			WREG32(CP_HQD_DEQUEUE_REQUEST, 1);
   4657  1.1  riastrad 			for (j = 0; j < rdev->usec_timeout; j++) {
   4658  1.1  riastrad 				if (!(RREG32(CP_HQD_ACTIVE) & 1))
   4659  1.1  riastrad 					break;
   4660  1.1  riastrad 				udelay(1);
   4661  1.1  riastrad 			}
   4662  1.1  riastrad 			WREG32(CP_HQD_DEQUEUE_REQUEST, mqd->queue_state.cp_hqd_dequeue_request);
   4663  1.1  riastrad 			WREG32(CP_HQD_PQ_RPTR, mqd->queue_state.cp_hqd_pq_rptr);
   4664  1.1  riastrad 			WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
   4665  1.1  riastrad 		}
   4666  1.1  riastrad 
   4667  1.1  riastrad 		/* set the pointer to the MQD */
   4668  1.1  riastrad 		mqd->queue_state.cp_mqd_base_addr = mqd_gpu_addr & 0xfffffffc;
   4669  1.1  riastrad 		mqd->queue_state.cp_mqd_base_addr_hi = upper_32_bits(mqd_gpu_addr);
   4670  1.1  riastrad 		WREG32(CP_MQD_BASE_ADDR, mqd->queue_state.cp_mqd_base_addr);
   4671  1.1  riastrad 		WREG32(CP_MQD_BASE_ADDR_HI, mqd->queue_state.cp_mqd_base_addr_hi);
   4672  1.1  riastrad 		/* set MQD vmid to 0 */
   4673  1.1  riastrad 		mqd->queue_state.cp_mqd_control = RREG32(CP_MQD_CONTROL);
   4674  1.1  riastrad 		mqd->queue_state.cp_mqd_control &= ~MQD_VMID_MASK;
   4675  1.1  riastrad 		WREG32(CP_MQD_CONTROL, mqd->queue_state.cp_mqd_control);
   4676  1.1  riastrad 
   4677  1.1  riastrad 		/* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */
   4678  1.1  riastrad 		hqd_gpu_addr = rdev->ring[idx].gpu_addr >> 8;
   4679  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_base = hqd_gpu_addr;
   4680  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_base_hi = upper_32_bits(hqd_gpu_addr);
   4681  1.1  riastrad 		WREG32(CP_HQD_PQ_BASE, mqd->queue_state.cp_hqd_pq_base);
   4682  1.1  riastrad 		WREG32(CP_HQD_PQ_BASE_HI, mqd->queue_state.cp_hqd_pq_base_hi);
   4683  1.1  riastrad 
   4684  1.1  riastrad 		/* set up the HQD, this is similar to CP_RB0_CNTL */
   4685  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_control = RREG32(CP_HQD_PQ_CONTROL);
   4686  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_control &=
   4687  1.1  riastrad 			~(QUEUE_SIZE_MASK | RPTR_BLOCK_SIZE_MASK);
   4688  1.1  riastrad 
   4689  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_control |=
   4690  1.1  riastrad 			order_base_2(rdev->ring[idx].ring_size / 8);
   4691  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_control |=
   4692  1.1  riastrad 			(order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8);
   4693  1.1  riastrad #ifdef __BIG_ENDIAN
   4694  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_control |= BUF_SWAP_32BIT;
   4695  1.1  riastrad #endif
   4696  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_control &=
   4697  1.1  riastrad 			~(UNORD_DISPATCH | ROQ_PQ_IB_FLIP | PQ_VOLATILE);
   4698  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_control |=
   4699  1.1  riastrad 			PRIV_STATE | KMD_QUEUE; /* assuming kernel queue control */
   4700  1.1  riastrad 		WREG32(CP_HQD_PQ_CONTROL, mqd->queue_state.cp_hqd_pq_control);
   4701  1.1  riastrad 
   4702  1.1  riastrad 		/* only used if CP_PQ_WPTR_POLL_CNTL.WPTR_POLL_EN=1 */
   4703  1.1  riastrad 		if (i == 0)
   4704  1.1  riastrad 			wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP1_WPTR_OFFSET;
   4705  1.1  riastrad 		else
   4706  1.1  riastrad 			wb_gpu_addr = rdev->wb.gpu_addr + CIK_WB_CP2_WPTR_OFFSET;
   4707  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_wptr_poll_addr = wb_gpu_addr & 0xfffffffc;
   4708  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits(wb_gpu_addr) & 0xffff;
   4709  1.1  riastrad 		WREG32(CP_HQD_PQ_WPTR_POLL_ADDR, mqd->queue_state.cp_hqd_pq_wptr_poll_addr);
   4710  1.1  riastrad 		WREG32(CP_HQD_PQ_WPTR_POLL_ADDR_HI,
   4711  1.1  riastrad 		       mqd->queue_state.cp_hqd_pq_wptr_poll_addr_hi);
   4712  1.1  riastrad 
   4713  1.1  riastrad 		/* set the wb address wether it's enabled or not */
   4714  1.1  riastrad 		if (i == 0)
   4715  1.1  riastrad 			wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP1_RPTR_OFFSET;
   4716  1.1  riastrad 		else
   4717  1.1  riastrad 			wb_gpu_addr = rdev->wb.gpu_addr + RADEON_WB_CP2_RPTR_OFFSET;
   4718  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_rptr_report_addr = wb_gpu_addr & 0xfffffffc;
   4719  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi =
   4720  1.1  riastrad 			upper_32_bits(wb_gpu_addr) & 0xffff;
   4721  1.1  riastrad 		WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR,
   4722  1.1  riastrad 		       mqd->queue_state.cp_hqd_pq_rptr_report_addr);
   4723  1.1  riastrad 		WREG32(CP_HQD_PQ_RPTR_REPORT_ADDR_HI,
   4724  1.1  riastrad 		       mqd->queue_state.cp_hqd_pq_rptr_report_addr_hi);
   4725  1.1  riastrad 
   4726  1.1  riastrad 		/* enable the doorbell if requested */
   4727  1.1  riastrad 		if (use_doorbell) {
   4728  1.1  riastrad 			mqd->queue_state.cp_hqd_pq_doorbell_control =
   4729  1.1  riastrad 				RREG32(CP_HQD_PQ_DOORBELL_CONTROL);
   4730  1.1  riastrad 			mqd->queue_state.cp_hqd_pq_doorbell_control &= ~DOORBELL_OFFSET_MASK;
   4731  1.1  riastrad 			mqd->queue_state.cp_hqd_pq_doorbell_control |=
   4732  1.1  riastrad 				DOORBELL_OFFSET(rdev->ring[idx].doorbell_index);
   4733  1.1  riastrad 			mqd->queue_state.cp_hqd_pq_doorbell_control |= DOORBELL_EN;
   4734  1.1  riastrad 			mqd->queue_state.cp_hqd_pq_doorbell_control &=
   4735  1.1  riastrad 				~(DOORBELL_SOURCE | DOORBELL_HIT);
   4736  1.1  riastrad 
   4737  1.1  riastrad 		} else {
   4738  1.1  riastrad 			mqd->queue_state.cp_hqd_pq_doorbell_control = 0;
   4739  1.1  riastrad 		}
   4740  1.1  riastrad 		WREG32(CP_HQD_PQ_DOORBELL_CONTROL,
   4741  1.1  riastrad 		       mqd->queue_state.cp_hqd_pq_doorbell_control);
   4742  1.1  riastrad 
   4743  1.1  riastrad 		/* read and write pointers, similar to CP_RB0_WPTR/_RPTR */
   4744  1.1  riastrad 		rdev->ring[idx].wptr = 0;
   4745  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_wptr = rdev->ring[idx].wptr;
   4746  1.1  riastrad 		WREG32(CP_HQD_PQ_WPTR, mqd->queue_state.cp_hqd_pq_wptr);
   4747  1.1  riastrad 		mqd->queue_state.cp_hqd_pq_rptr = RREG32(CP_HQD_PQ_RPTR);
   4748  1.1  riastrad 
   4749  1.1  riastrad 		/* set the vmid for the queue */
   4750  1.1  riastrad 		mqd->queue_state.cp_hqd_vmid = 0;
   4751  1.1  riastrad 		WREG32(CP_HQD_VMID, mqd->queue_state.cp_hqd_vmid);
   4752  1.1  riastrad 
   4753  1.1  riastrad 		/* activate the queue */
   4754  1.1  riastrad 		mqd->queue_state.cp_hqd_active = 1;
   4755  1.1  riastrad 		WREG32(CP_HQD_ACTIVE, mqd->queue_state.cp_hqd_active);
   4756  1.1  riastrad 
   4757  1.1  riastrad 		cik_srbm_select(rdev, 0, 0, 0, 0);
   4758  1.1  riastrad 		mutex_unlock(&rdev->srbm_mutex);
   4759  1.1  riastrad 
   4760  1.1  riastrad 		radeon_bo_kunmap(rdev->ring[idx].mqd_obj);
   4761  1.1  riastrad 		radeon_bo_unreserve(rdev->ring[idx].mqd_obj);
   4762  1.1  riastrad 
   4763  1.1  riastrad 		rdev->ring[idx].ready = true;
   4764  1.1  riastrad 		r = radeon_ring_test(rdev, idx, &rdev->ring[idx]);
   4765  1.1  riastrad 		if (r)
   4766  1.1  riastrad 			rdev->ring[idx].ready = false;
   4767  1.1  riastrad 	}
   4768  1.1  riastrad 
   4769  1.1  riastrad 	return 0;
   4770  1.1  riastrad }
   4771  1.1  riastrad 
   4772  1.1  riastrad static void cik_cp_enable(struct radeon_device *rdev, bool enable)
   4773  1.1  riastrad {
   4774  1.1  riastrad 	cik_cp_gfx_enable(rdev, enable);
   4775  1.1  riastrad 	cik_cp_compute_enable(rdev, enable);
   4776  1.1  riastrad }
   4777  1.1  riastrad 
   4778  1.1  riastrad static int cik_cp_load_microcode(struct radeon_device *rdev)
   4779  1.1  riastrad {
   4780  1.1  riastrad 	int r;
   4781  1.1  riastrad 
   4782  1.1  riastrad 	r = cik_cp_gfx_load_microcode(rdev);
   4783  1.1  riastrad 	if (r)
   4784  1.1  riastrad 		return r;
   4785  1.1  riastrad 	r = cik_cp_compute_load_microcode(rdev);
   4786  1.1  riastrad 	if (r)
   4787  1.1  riastrad 		return r;
   4788  1.1  riastrad 
   4789  1.1  riastrad 	return 0;
   4790  1.1  riastrad }
   4791  1.1  riastrad 
   4792  1.1  riastrad static void cik_cp_fini(struct radeon_device *rdev)
   4793  1.1  riastrad {
   4794  1.1  riastrad 	cik_cp_gfx_fini(rdev);
   4795  1.1  riastrad 	cik_cp_compute_fini(rdev);
   4796  1.1  riastrad }
   4797  1.1  riastrad 
   4798  1.1  riastrad static int cik_cp_resume(struct radeon_device *rdev)
   4799  1.1  riastrad {
   4800  1.1  riastrad 	int r;
   4801  1.1  riastrad 
   4802  1.1  riastrad 	cik_enable_gui_idle_interrupt(rdev, false);
   4803  1.1  riastrad 
   4804  1.1  riastrad 	r = cik_cp_load_microcode(rdev);
   4805  1.1  riastrad 	if (r)
   4806  1.1  riastrad 		return r;
   4807  1.1  riastrad 
   4808  1.1  riastrad 	r = cik_cp_gfx_resume(rdev);
   4809  1.1  riastrad 	if (r)
   4810  1.1  riastrad 		return r;
   4811  1.1  riastrad 	r = cik_cp_compute_resume(rdev);
   4812  1.1  riastrad 	if (r)
   4813  1.1  riastrad 		return r;
   4814  1.1  riastrad 
   4815  1.1  riastrad 	cik_enable_gui_idle_interrupt(rdev, true);
   4816  1.1  riastrad 
   4817  1.1  riastrad 	return 0;
   4818  1.1  riastrad }
   4819  1.1  riastrad 
   4820  1.1  riastrad static void cik_print_gpu_status_regs(struct radeon_device *rdev)
   4821  1.1  riastrad {
   4822  1.1  riastrad 	dev_info(rdev->dev, "  GRBM_STATUS=0x%08X\n",
   4823  1.1  riastrad 		RREG32(GRBM_STATUS));
   4824  1.1  riastrad 	dev_info(rdev->dev, "  GRBM_STATUS2=0x%08X\n",
   4825  1.1  riastrad 		RREG32(GRBM_STATUS2));
   4826  1.1  riastrad 	dev_info(rdev->dev, "  GRBM_STATUS_SE0=0x%08X\n",
   4827  1.1  riastrad 		RREG32(GRBM_STATUS_SE0));
   4828  1.1  riastrad 	dev_info(rdev->dev, "  GRBM_STATUS_SE1=0x%08X\n",
   4829  1.1  riastrad 		RREG32(GRBM_STATUS_SE1));
   4830  1.1  riastrad 	dev_info(rdev->dev, "  GRBM_STATUS_SE2=0x%08X\n",
   4831  1.1  riastrad 		RREG32(GRBM_STATUS_SE2));
   4832  1.1  riastrad 	dev_info(rdev->dev, "  GRBM_STATUS_SE3=0x%08X\n",
   4833  1.1  riastrad 		RREG32(GRBM_STATUS_SE3));
   4834  1.1  riastrad 	dev_info(rdev->dev, "  SRBM_STATUS=0x%08X\n",
   4835  1.1  riastrad 		RREG32(SRBM_STATUS));
   4836  1.1  riastrad 	dev_info(rdev->dev, "  SRBM_STATUS2=0x%08X\n",
   4837  1.1  riastrad 		RREG32(SRBM_STATUS2));
   4838  1.1  riastrad 	dev_info(rdev->dev, "  SDMA0_STATUS_REG   = 0x%08X\n",
   4839  1.1  riastrad 		RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET));
   4840  1.1  riastrad 	dev_info(rdev->dev, "  SDMA1_STATUS_REG   = 0x%08X\n",
   4841  1.1  riastrad 		 RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET));
   4842  1.1  riastrad 	dev_info(rdev->dev, "  CP_STAT = 0x%08x\n", RREG32(CP_STAT));
   4843  1.1  riastrad 	dev_info(rdev->dev, "  CP_STALLED_STAT1 = 0x%08x\n",
   4844  1.1  riastrad 		 RREG32(CP_STALLED_STAT1));
   4845  1.1  riastrad 	dev_info(rdev->dev, "  CP_STALLED_STAT2 = 0x%08x\n",
   4846  1.1  riastrad 		 RREG32(CP_STALLED_STAT2));
   4847  1.1  riastrad 	dev_info(rdev->dev, "  CP_STALLED_STAT3 = 0x%08x\n",
   4848  1.1  riastrad 		 RREG32(CP_STALLED_STAT3));
   4849  1.1  riastrad 	dev_info(rdev->dev, "  CP_CPF_BUSY_STAT = 0x%08x\n",
   4850  1.1  riastrad 		 RREG32(CP_CPF_BUSY_STAT));
   4851  1.1  riastrad 	dev_info(rdev->dev, "  CP_CPF_STALLED_STAT1 = 0x%08x\n",
   4852  1.1  riastrad 		 RREG32(CP_CPF_STALLED_STAT1));
   4853  1.1  riastrad 	dev_info(rdev->dev, "  CP_CPF_STATUS = 0x%08x\n", RREG32(CP_CPF_STATUS));
   4854  1.1  riastrad 	dev_info(rdev->dev, "  CP_CPC_BUSY_STAT = 0x%08x\n", RREG32(CP_CPC_BUSY_STAT));
   4855  1.1  riastrad 	dev_info(rdev->dev, "  CP_CPC_STALLED_STAT1 = 0x%08x\n",
   4856  1.1  riastrad 		 RREG32(CP_CPC_STALLED_STAT1));
   4857  1.1  riastrad 	dev_info(rdev->dev, "  CP_CPC_STATUS = 0x%08x\n", RREG32(CP_CPC_STATUS));
   4858  1.1  riastrad }
   4859  1.1  riastrad 
   4860  1.1  riastrad /**
   4861  1.1  riastrad  * cik_gpu_check_soft_reset - check which blocks are busy
   4862  1.1  riastrad  *
   4863  1.1  riastrad  * @rdev: radeon_device pointer
   4864  1.1  riastrad  *
   4865  1.1  riastrad  * Check which blocks are busy and return the relevant reset
   4866  1.1  riastrad  * mask to be used by cik_gpu_soft_reset().
   4867  1.1  riastrad  * Returns a mask of the blocks to be reset.
   4868  1.1  riastrad  */
   4869  1.1  riastrad u32 cik_gpu_check_soft_reset(struct radeon_device *rdev)
   4870  1.1  riastrad {
   4871  1.1  riastrad 	u32 reset_mask = 0;
   4872  1.1  riastrad 	u32 tmp;
   4873  1.1  riastrad 
   4874  1.1  riastrad 	/* GRBM_STATUS */
   4875  1.1  riastrad 	tmp = RREG32(GRBM_STATUS);
   4876  1.1  riastrad 	if (tmp & (PA_BUSY | SC_BUSY |
   4877  1.1  riastrad 		   BCI_BUSY | SX_BUSY |
   4878  1.1  riastrad 		   TA_BUSY | VGT_BUSY |
   4879  1.1  riastrad 		   DB_BUSY | CB_BUSY |
   4880  1.1  riastrad 		   GDS_BUSY | SPI_BUSY |
   4881  1.1  riastrad 		   IA_BUSY | IA_BUSY_NO_DMA))
   4882  1.1  riastrad 		reset_mask |= RADEON_RESET_GFX;
   4883  1.1  riastrad 
   4884  1.1  riastrad 	if (tmp & (CP_BUSY | CP_COHERENCY_BUSY))
   4885  1.1  riastrad 		reset_mask |= RADEON_RESET_CP;
   4886  1.1  riastrad 
   4887  1.1  riastrad 	/* GRBM_STATUS2 */
   4888  1.1  riastrad 	tmp = RREG32(GRBM_STATUS2);
   4889  1.1  riastrad 	if (tmp & RLC_BUSY)
   4890  1.1  riastrad 		reset_mask |= RADEON_RESET_RLC;
   4891  1.1  riastrad 
   4892  1.1  riastrad 	/* SDMA0_STATUS_REG */
   4893  1.1  riastrad 	tmp = RREG32(SDMA0_STATUS_REG + SDMA0_REGISTER_OFFSET);
   4894  1.1  riastrad 	if (!(tmp & SDMA_IDLE))
   4895  1.1  riastrad 		reset_mask |= RADEON_RESET_DMA;
   4896  1.1  riastrad 
   4897  1.1  riastrad 	/* SDMA1_STATUS_REG */
   4898  1.1  riastrad 	tmp = RREG32(SDMA0_STATUS_REG + SDMA1_REGISTER_OFFSET);
   4899  1.1  riastrad 	if (!(tmp & SDMA_IDLE))
   4900  1.1  riastrad 		reset_mask |= RADEON_RESET_DMA1;
   4901  1.1  riastrad 
   4902  1.1  riastrad 	/* SRBM_STATUS2 */
   4903  1.1  riastrad 	tmp = RREG32(SRBM_STATUS2);
   4904  1.1  riastrad 	if (tmp & SDMA_BUSY)
   4905  1.1  riastrad 		reset_mask |= RADEON_RESET_DMA;
   4906  1.1  riastrad 
   4907  1.1  riastrad 	if (tmp & SDMA1_BUSY)
   4908  1.1  riastrad 		reset_mask |= RADEON_RESET_DMA1;
   4909  1.1  riastrad 
   4910  1.1  riastrad 	/* SRBM_STATUS */
   4911  1.1  riastrad 	tmp = RREG32(SRBM_STATUS);
   4912  1.1  riastrad 
   4913  1.1  riastrad 	if (tmp & IH_BUSY)
   4914  1.1  riastrad 		reset_mask |= RADEON_RESET_IH;
   4915  1.1  riastrad 
   4916  1.1  riastrad 	if (tmp & SEM_BUSY)
   4917  1.1  riastrad 		reset_mask |= RADEON_RESET_SEM;
   4918  1.1  riastrad 
   4919  1.1  riastrad 	if (tmp & GRBM_RQ_PENDING)
   4920  1.1  riastrad 		reset_mask |= RADEON_RESET_GRBM;
   4921  1.1  riastrad 
   4922  1.1  riastrad 	if (tmp & VMC_BUSY)
   4923  1.1  riastrad 		reset_mask |= RADEON_RESET_VMC;
   4924  1.1  riastrad 
   4925  1.1  riastrad 	if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
   4926  1.1  riastrad 		   MCC_BUSY | MCD_BUSY))
   4927  1.1  riastrad 		reset_mask |= RADEON_RESET_MC;
   4928  1.1  riastrad 
   4929  1.1  riastrad 	if (evergreen_is_display_hung(rdev))
   4930  1.1  riastrad 		reset_mask |= RADEON_RESET_DISPLAY;
   4931  1.1  riastrad 
   4932  1.1  riastrad 	/* Skip MC reset as it's mostly likely not hung, just busy */
   4933  1.1  riastrad 	if (reset_mask & RADEON_RESET_MC) {
   4934  1.1  riastrad 		DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
   4935  1.1  riastrad 		reset_mask &= ~RADEON_RESET_MC;
   4936  1.1  riastrad 	}
   4937  1.1  riastrad 
   4938  1.1  riastrad 	return reset_mask;
   4939  1.1  riastrad }
   4940  1.1  riastrad 
   4941  1.1  riastrad /**
   4942  1.1  riastrad  * cik_gpu_soft_reset - soft reset GPU
   4943  1.1  riastrad  *
   4944  1.1  riastrad  * @rdev: radeon_device pointer
   4945  1.1  riastrad  * @reset_mask: mask of which blocks to reset
   4946  1.1  riastrad  *
   4947  1.1  riastrad  * Soft reset the blocks specified in @reset_mask.
   4948  1.1  riastrad  */
   4949  1.1  riastrad static void cik_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
   4950  1.1  riastrad {
   4951  1.1  riastrad 	struct evergreen_mc_save save;
   4952  1.1  riastrad 	u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
   4953  1.1  riastrad 	u32 tmp;
   4954  1.1  riastrad 
   4955  1.1  riastrad 	if (reset_mask == 0)
   4956  1.1  riastrad 		return;
   4957  1.1  riastrad 
   4958  1.1  riastrad 	dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
   4959  1.1  riastrad 
   4960  1.1  riastrad 	cik_print_gpu_status_regs(rdev);
   4961  1.1  riastrad 	dev_info(rdev->dev, "  VM_CONTEXT1_PROTECTION_FAULT_ADDR   0x%08X\n",
   4962  1.1  riastrad 		 RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR));
   4963  1.1  riastrad 	dev_info(rdev->dev, "  VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
   4964  1.1  riastrad 		 RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS));
   4965  1.1  riastrad 
   4966  1.1  riastrad 	/* disable CG/PG */
   4967  1.1  riastrad 	cik_fini_pg(rdev);
   4968  1.1  riastrad 	cik_fini_cg(rdev);
   4969  1.1  riastrad 
   4970  1.1  riastrad 	/* stop the rlc */
   4971  1.1  riastrad 	cik_rlc_stop(rdev);
   4972  1.1  riastrad 
   4973  1.1  riastrad 	/* Disable GFX parsing/prefetching */
   4974  1.1  riastrad 	WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
   4975  1.1  riastrad 
   4976  1.1  riastrad 	/* Disable MEC parsing/prefetching */
   4977  1.1  riastrad 	WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
   4978  1.1  riastrad 
   4979  1.1  riastrad 	if (reset_mask & RADEON_RESET_DMA) {
   4980  1.1  riastrad 		/* sdma0 */
   4981  1.1  riastrad 		tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
   4982  1.1  riastrad 		tmp |= SDMA_HALT;
   4983  1.1  riastrad 		WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
   4984  1.1  riastrad 	}
   4985  1.1  riastrad 	if (reset_mask & RADEON_RESET_DMA1) {
   4986  1.1  riastrad 		/* sdma1 */
   4987  1.1  riastrad 		tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
   4988  1.1  riastrad 		tmp |= SDMA_HALT;
   4989  1.1  riastrad 		WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
   4990  1.1  riastrad 	}
   4991  1.1  riastrad 
   4992  1.1  riastrad 	evergreen_mc_stop(rdev, &save);
   4993  1.1  riastrad 	if (evergreen_mc_wait_for_idle(rdev)) {
   4994  1.1  riastrad 		dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
   4995  1.1  riastrad 	}
   4996  1.1  riastrad 
   4997  1.1  riastrad 	if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE | RADEON_RESET_CP))
   4998  1.1  riastrad 		grbm_soft_reset = SOFT_RESET_CP | SOFT_RESET_GFX;
   4999  1.1  riastrad 
   5000  1.1  riastrad 	if (reset_mask & RADEON_RESET_CP) {
   5001  1.1  riastrad 		grbm_soft_reset |= SOFT_RESET_CP;
   5002  1.1  riastrad 
   5003  1.1  riastrad 		srbm_soft_reset |= SOFT_RESET_GRBM;
   5004  1.1  riastrad 	}
   5005  1.1  riastrad 
   5006  1.1  riastrad 	if (reset_mask & RADEON_RESET_DMA)
   5007  1.1  riastrad 		srbm_soft_reset |= SOFT_RESET_SDMA;
   5008  1.1  riastrad 
   5009  1.1  riastrad 	if (reset_mask & RADEON_RESET_DMA1)
   5010  1.1  riastrad 		srbm_soft_reset |= SOFT_RESET_SDMA1;
   5011  1.1  riastrad 
   5012  1.1  riastrad 	if (reset_mask & RADEON_RESET_DISPLAY)
   5013  1.1  riastrad 		srbm_soft_reset |= SOFT_RESET_DC;
   5014  1.1  riastrad 
   5015  1.1  riastrad 	if (reset_mask & RADEON_RESET_RLC)
   5016  1.1  riastrad 		grbm_soft_reset |= SOFT_RESET_RLC;
   5017  1.1  riastrad 
   5018  1.1  riastrad 	if (reset_mask & RADEON_RESET_SEM)
   5019  1.1  riastrad 		srbm_soft_reset |= SOFT_RESET_SEM;
   5020  1.1  riastrad 
   5021  1.1  riastrad 	if (reset_mask & RADEON_RESET_IH)
   5022  1.1  riastrad 		srbm_soft_reset |= SOFT_RESET_IH;
   5023  1.1  riastrad 
   5024  1.1  riastrad 	if (reset_mask & RADEON_RESET_GRBM)
   5025  1.1  riastrad 		srbm_soft_reset |= SOFT_RESET_GRBM;
   5026  1.1  riastrad 
   5027  1.1  riastrad 	if (reset_mask & RADEON_RESET_VMC)
   5028  1.1  riastrad 		srbm_soft_reset |= SOFT_RESET_VMC;
   5029  1.1  riastrad 
   5030  1.1  riastrad 	if (!(rdev->flags & RADEON_IS_IGP)) {
   5031  1.1  riastrad 		if (reset_mask & RADEON_RESET_MC)
   5032  1.1  riastrad 			srbm_soft_reset |= SOFT_RESET_MC;
   5033  1.1  riastrad 	}
   5034  1.1  riastrad 
   5035  1.1  riastrad 	if (grbm_soft_reset) {
   5036  1.1  riastrad 		tmp = RREG32(GRBM_SOFT_RESET);
   5037  1.1  riastrad 		tmp |= grbm_soft_reset;
   5038  1.1  riastrad 		dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
   5039  1.1  riastrad 		WREG32(GRBM_SOFT_RESET, tmp);
   5040  1.1  riastrad 		tmp = RREG32(GRBM_SOFT_RESET);
   5041  1.1  riastrad 
   5042  1.1  riastrad 		udelay(50);
   5043  1.1  riastrad 
   5044  1.1  riastrad 		tmp &= ~grbm_soft_reset;
   5045  1.1  riastrad 		WREG32(GRBM_SOFT_RESET, tmp);
   5046  1.1  riastrad 		tmp = RREG32(GRBM_SOFT_RESET);
   5047  1.1  riastrad 	}
   5048  1.1  riastrad 
   5049  1.1  riastrad 	if (srbm_soft_reset) {
   5050  1.1  riastrad 		tmp = RREG32(SRBM_SOFT_RESET);
   5051  1.1  riastrad 		tmp |= srbm_soft_reset;
   5052  1.1  riastrad 		dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
   5053  1.1  riastrad 		WREG32(SRBM_SOFT_RESET, tmp);
   5054  1.1  riastrad 		tmp = RREG32(SRBM_SOFT_RESET);
   5055  1.1  riastrad 
   5056  1.1  riastrad 		udelay(50);
   5057  1.1  riastrad 
   5058  1.1  riastrad 		tmp &= ~srbm_soft_reset;
   5059  1.1  riastrad 		WREG32(SRBM_SOFT_RESET, tmp);
   5060  1.1  riastrad 		tmp = RREG32(SRBM_SOFT_RESET);
   5061  1.1  riastrad 	}
   5062  1.1  riastrad 
   5063  1.1  riastrad 	/* Wait a little for things to settle down */
   5064  1.1  riastrad 	udelay(50);
   5065  1.1  riastrad 
   5066  1.1  riastrad 	evergreen_mc_resume(rdev, &save);
   5067  1.1  riastrad 	udelay(50);
   5068  1.1  riastrad 
   5069  1.1  riastrad 	cik_print_gpu_status_regs(rdev);
   5070  1.1  riastrad }
   5071  1.1  riastrad 
   5072  1.1  riastrad struct kv_reset_save_regs {
   5073  1.1  riastrad 	u32 gmcon_reng_execute;
   5074  1.1  riastrad 	u32 gmcon_misc;
   5075  1.1  riastrad 	u32 gmcon_misc3;
   5076  1.1  riastrad };
   5077  1.1  riastrad 
   5078  1.1  riastrad static void kv_save_regs_for_reset(struct radeon_device *rdev,
   5079  1.1  riastrad 				   struct kv_reset_save_regs *save)
   5080  1.1  riastrad {
   5081  1.1  riastrad 	save->gmcon_reng_execute = RREG32(GMCON_RENG_EXECUTE);
   5082  1.1  riastrad 	save->gmcon_misc = RREG32(GMCON_MISC);
   5083  1.1  riastrad 	save->gmcon_misc3 = RREG32(GMCON_MISC3);
   5084  1.1  riastrad 
   5085  1.1  riastrad 	WREG32(GMCON_RENG_EXECUTE, save->gmcon_reng_execute & ~RENG_EXECUTE_ON_PWR_UP);
   5086  1.1  riastrad 	WREG32(GMCON_MISC, save->gmcon_misc & ~(RENG_EXECUTE_ON_REG_UPDATE |
   5087  1.1  riastrad 						STCTRL_STUTTER_EN));
   5088  1.1  riastrad }
   5089  1.1  riastrad 
   5090  1.1  riastrad static void kv_restore_regs_for_reset(struct radeon_device *rdev,
   5091  1.1  riastrad 				      struct kv_reset_save_regs *save)
   5092  1.1  riastrad {
   5093  1.1  riastrad 	int i;
   5094  1.1  riastrad 
   5095  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0);
   5096  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0x200010ff);
   5097  1.1  riastrad 
   5098  1.1  riastrad 	for (i = 0; i < 5; i++)
   5099  1.1  riastrad 		WREG32(GMCON_PGFSM_WRITE, 0);
   5100  1.1  riastrad 
   5101  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0);
   5102  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0x300010ff);
   5103  1.1  riastrad 
   5104  1.1  riastrad 	for (i = 0; i < 5; i++)
   5105  1.1  riastrad 		WREG32(GMCON_PGFSM_WRITE, 0);
   5106  1.1  riastrad 
   5107  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0x210000);
   5108  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0xa00010ff);
   5109  1.1  riastrad 
   5110  1.1  riastrad 	for (i = 0; i < 5; i++)
   5111  1.1  riastrad 		WREG32(GMCON_PGFSM_WRITE, 0);
   5112  1.1  riastrad 
   5113  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0x21003);
   5114  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0xb00010ff);
   5115  1.1  riastrad 
   5116  1.1  riastrad 	for (i = 0; i < 5; i++)
   5117  1.1  riastrad 		WREG32(GMCON_PGFSM_WRITE, 0);
   5118  1.1  riastrad 
   5119  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0x2b00);
   5120  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0xc00010ff);
   5121  1.1  riastrad 
   5122  1.1  riastrad 	for (i = 0; i < 5; i++)
   5123  1.1  riastrad 		WREG32(GMCON_PGFSM_WRITE, 0);
   5124  1.1  riastrad 
   5125  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0);
   5126  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0xd00010ff);
   5127  1.1  riastrad 
   5128  1.1  riastrad 	for (i = 0; i < 5; i++)
   5129  1.1  riastrad 		WREG32(GMCON_PGFSM_WRITE, 0);
   5130  1.1  riastrad 
   5131  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0x420000);
   5132  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0x100010ff);
   5133  1.1  riastrad 
   5134  1.1  riastrad 	for (i = 0; i < 5; i++)
   5135  1.1  riastrad 		WREG32(GMCON_PGFSM_WRITE, 0);
   5136  1.1  riastrad 
   5137  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0x120202);
   5138  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0x500010ff);
   5139  1.1  riastrad 
   5140  1.1  riastrad 	for (i = 0; i < 5; i++)
   5141  1.1  riastrad 		WREG32(GMCON_PGFSM_WRITE, 0);
   5142  1.1  riastrad 
   5143  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0x3e3e36);
   5144  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0x600010ff);
   5145  1.1  riastrad 
   5146  1.1  riastrad 	for (i = 0; i < 5; i++)
   5147  1.1  riastrad 		WREG32(GMCON_PGFSM_WRITE, 0);
   5148  1.1  riastrad 
   5149  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0x373f3e);
   5150  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0x700010ff);
   5151  1.1  riastrad 
   5152  1.1  riastrad 	for (i = 0; i < 5; i++)
   5153  1.1  riastrad 		WREG32(GMCON_PGFSM_WRITE, 0);
   5154  1.1  riastrad 
   5155  1.1  riastrad 	WREG32(GMCON_PGFSM_WRITE, 0x3e1332);
   5156  1.1  riastrad 	WREG32(GMCON_PGFSM_CONFIG, 0xe00010ff);
   5157  1.1  riastrad 
   5158  1.1  riastrad 	WREG32(GMCON_MISC3, save->gmcon_misc3);
   5159  1.1  riastrad 	WREG32(GMCON_MISC, save->gmcon_misc);
   5160  1.1  riastrad 	WREG32(GMCON_RENG_EXECUTE, save->gmcon_reng_execute);
   5161  1.1  riastrad }
   5162  1.1  riastrad 
   5163  1.1  riastrad static void cik_gpu_pci_config_reset(struct radeon_device *rdev)
   5164  1.1  riastrad {
   5165  1.1  riastrad 	struct evergreen_mc_save save;
   5166  1.1  riastrad 	struct kv_reset_save_regs kv_save = { 0 };
   5167  1.1  riastrad 	u32 tmp, i;
   5168  1.1  riastrad 
   5169  1.1  riastrad 	dev_info(rdev->dev, "GPU pci config reset\n");
   5170  1.1  riastrad 
   5171  1.1  riastrad 	/* disable dpm? */
   5172  1.1  riastrad 
   5173  1.1  riastrad 	/* disable cg/pg */
   5174  1.1  riastrad 	cik_fini_pg(rdev);
   5175  1.1  riastrad 	cik_fini_cg(rdev);
   5176  1.1  riastrad 
   5177  1.1  riastrad 	/* Disable GFX parsing/prefetching */
   5178  1.1  riastrad 	WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT | CP_CE_HALT);
   5179  1.1  riastrad 
   5180  1.1  riastrad 	/* Disable MEC parsing/prefetching */
   5181  1.1  riastrad 	WREG32(CP_MEC_CNTL, MEC_ME1_HALT | MEC_ME2_HALT);
   5182  1.1  riastrad 
   5183  1.1  riastrad 	/* sdma0 */
   5184  1.1  riastrad 	tmp = RREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET);
   5185  1.1  riastrad 	tmp |= SDMA_HALT;
   5186  1.1  riastrad 	WREG32(SDMA0_ME_CNTL + SDMA0_REGISTER_OFFSET, tmp);
   5187  1.1  riastrad 	/* sdma1 */
   5188  1.1  riastrad 	tmp = RREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET);
   5189  1.1  riastrad 	tmp |= SDMA_HALT;
   5190  1.1  riastrad 	WREG32(SDMA0_ME_CNTL + SDMA1_REGISTER_OFFSET, tmp);
   5191  1.1  riastrad 	/* XXX other engines? */
   5192  1.1  riastrad 
   5193  1.1  riastrad 	/* halt the rlc, disable cp internal ints */
   5194  1.1  riastrad 	cik_rlc_stop(rdev);
   5195  1.1  riastrad 
   5196  1.1  riastrad 	udelay(50);
   5197  1.1  riastrad 
   5198  1.1  riastrad 	/* disable mem access */
   5199  1.1  riastrad 	evergreen_mc_stop(rdev, &save);
   5200  1.1  riastrad 	if (evergreen_mc_wait_for_idle(rdev)) {
   5201  1.1  riastrad 		dev_warn(rdev->dev, "Wait for MC idle timed out !\n");
   5202  1.1  riastrad 	}
   5203  1.1  riastrad 
   5204  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP)
   5205  1.1  riastrad 		kv_save_regs_for_reset(rdev, &kv_save);
   5206  1.1  riastrad 
   5207  1.1  riastrad 	/* disable BM */
   5208  1.1  riastrad 	pci_clear_master(rdev->pdev);
   5209  1.1  riastrad 	/* reset */
   5210  1.1  riastrad 	radeon_pci_config_reset(rdev);
   5211  1.1  riastrad 
   5212  1.1  riastrad 	udelay(100);
   5213  1.1  riastrad 
   5214  1.1  riastrad 	/* wait for asic to come out of reset */
   5215  1.1  riastrad 	for (i = 0; i < rdev->usec_timeout; i++) {
   5216  1.1  riastrad 		if (RREG32(CONFIG_MEMSIZE) != 0xffffffff)
   5217  1.1  riastrad 			break;
   5218  1.1  riastrad 		udelay(1);
   5219  1.1  riastrad 	}
   5220  1.1  riastrad 
   5221  1.1  riastrad 	/* does asic init need to be run first??? */
   5222  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP)
   5223  1.1  riastrad 		kv_restore_regs_for_reset(rdev, &kv_save);
   5224  1.1  riastrad }
   5225  1.1  riastrad 
   5226  1.1  riastrad /**
   5227  1.1  riastrad  * cik_asic_reset - soft reset GPU
   5228  1.1  riastrad  *
   5229  1.1  riastrad  * @rdev: radeon_device pointer
   5230  1.3  riastrad  * @hard: force hard reset
   5231  1.1  riastrad  *
   5232  1.1  riastrad  * Look up which blocks are hung and attempt
   5233  1.1  riastrad  * to reset them.
   5234  1.1  riastrad  * Returns 0 for success.
   5235  1.1  riastrad  */
   5236  1.3  riastrad int cik_asic_reset(struct radeon_device *rdev, bool hard)
   5237  1.1  riastrad {
   5238  1.1  riastrad 	u32 reset_mask;
   5239  1.1  riastrad 
   5240  1.3  riastrad 	if (hard) {
   5241  1.3  riastrad 		cik_gpu_pci_config_reset(rdev);
   5242  1.3  riastrad 		return 0;
   5243  1.3  riastrad 	}
   5244  1.3  riastrad 
   5245  1.1  riastrad 	reset_mask = cik_gpu_check_soft_reset(rdev);
   5246  1.1  riastrad 
   5247  1.1  riastrad 	if (reset_mask)
   5248  1.1  riastrad 		r600_set_bios_scratch_engine_hung(rdev, true);
   5249  1.1  riastrad 
   5250  1.1  riastrad 	/* try soft reset */
   5251  1.1  riastrad 	cik_gpu_soft_reset(rdev, reset_mask);
   5252  1.1  riastrad 
   5253  1.1  riastrad 	reset_mask = cik_gpu_check_soft_reset(rdev);
   5254  1.1  riastrad 
   5255  1.1  riastrad 	/* try pci config reset */
   5256  1.1  riastrad 	if (reset_mask && radeon_hard_reset)
   5257  1.1  riastrad 		cik_gpu_pci_config_reset(rdev);
   5258  1.1  riastrad 
   5259  1.1  riastrad 	reset_mask = cik_gpu_check_soft_reset(rdev);
   5260  1.1  riastrad 
   5261  1.1  riastrad 	if (!reset_mask)
   5262  1.1  riastrad 		r600_set_bios_scratch_engine_hung(rdev, false);
   5263  1.1  riastrad 
   5264  1.1  riastrad 	return 0;
   5265  1.1  riastrad }
   5266  1.1  riastrad 
   5267  1.1  riastrad /**
   5268  1.1  riastrad  * cik_gfx_is_lockup - check if the 3D engine is locked up
   5269  1.1  riastrad  *
   5270  1.1  riastrad  * @rdev: radeon_device pointer
   5271  1.1  riastrad  * @ring: radeon_ring structure holding ring information
   5272  1.1  riastrad  *
   5273  1.1  riastrad  * Check if the 3D engine is locked up (CIK).
   5274  1.1  riastrad  * Returns true if the engine is locked, false if not.
   5275  1.1  riastrad  */
   5276  1.1  riastrad bool cik_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
   5277  1.1  riastrad {
   5278  1.1  riastrad 	u32 reset_mask = cik_gpu_check_soft_reset(rdev);
   5279  1.1  riastrad 
   5280  1.1  riastrad 	if (!(reset_mask & (RADEON_RESET_GFX |
   5281  1.1  riastrad 			    RADEON_RESET_COMPUTE |
   5282  1.1  riastrad 			    RADEON_RESET_CP))) {
   5283  1.1  riastrad 		radeon_ring_lockup_update(rdev, ring);
   5284  1.1  riastrad 		return false;
   5285  1.1  riastrad 	}
   5286  1.1  riastrad 	return radeon_ring_test_lockup(rdev, ring);
   5287  1.1  riastrad }
   5288  1.1  riastrad 
   5289  1.1  riastrad /* MC */
   5290  1.1  riastrad /**
   5291  1.1  riastrad  * cik_mc_program - program the GPU memory controller
   5292  1.1  riastrad  *
   5293  1.1  riastrad  * @rdev: radeon_device pointer
   5294  1.1  riastrad  *
   5295  1.1  riastrad  * Set the location of vram, gart, and AGP in the GPU's
   5296  1.1  riastrad  * physical address space (CIK).
   5297  1.1  riastrad  */
   5298  1.1  riastrad static void cik_mc_program(struct radeon_device *rdev)
   5299  1.1  riastrad {
   5300  1.1  riastrad 	struct evergreen_mc_save save;
   5301  1.1  riastrad 	u32 tmp;
   5302  1.1  riastrad 	int i, j;
   5303  1.1  riastrad 
   5304  1.1  riastrad 	/* Initialize HDP */
   5305  1.1  riastrad 	for (i = 0, j = 0; i < 32; i++, j += 0x18) {
   5306  1.1  riastrad 		WREG32((0x2c14 + j), 0x00000000);
   5307  1.1  riastrad 		WREG32((0x2c18 + j), 0x00000000);
   5308  1.1  riastrad 		WREG32((0x2c1c + j), 0x00000000);
   5309  1.1  riastrad 		WREG32((0x2c20 + j), 0x00000000);
   5310  1.1  riastrad 		WREG32((0x2c24 + j), 0x00000000);
   5311  1.1  riastrad 	}
   5312  1.1  riastrad 	WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
   5313  1.1  riastrad 
   5314  1.1  riastrad 	evergreen_mc_stop(rdev, &save);
   5315  1.1  riastrad 	if (radeon_mc_wait_for_idle(rdev)) {
   5316  1.1  riastrad 		dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
   5317  1.1  riastrad 	}
   5318  1.1  riastrad 	/* Lockout access through VGA aperture*/
   5319  1.1  riastrad 	WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
   5320  1.1  riastrad 	/* Update configuration */
   5321  1.1  riastrad 	WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
   5322  1.1  riastrad 	       rdev->mc.vram_start >> 12);
   5323  1.1  riastrad 	WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
   5324  1.1  riastrad 	       rdev->mc.vram_end >> 12);
   5325  1.1  riastrad 	WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR,
   5326  1.1  riastrad 	       rdev->vram_scratch.gpu_addr >> 12);
   5327  1.1  riastrad 	tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
   5328  1.1  riastrad 	tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
   5329  1.1  riastrad 	WREG32(MC_VM_FB_LOCATION, tmp);
   5330  1.1  riastrad 	/* XXX double check these! */
   5331  1.1  riastrad 	WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
   5332  1.1  riastrad 	WREG32(HDP_NONSURFACE_INFO, (2 << 7) | (1 << 30));
   5333  1.1  riastrad 	WREG32(HDP_NONSURFACE_SIZE, 0x3FFFFFFF);
   5334  1.1  riastrad 	WREG32(MC_VM_AGP_BASE, 0);
   5335  1.1  riastrad 	WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
   5336  1.1  riastrad 	WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
   5337  1.1  riastrad 	if (radeon_mc_wait_for_idle(rdev)) {
   5338  1.1  riastrad 		dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
   5339  1.1  riastrad 	}
   5340  1.1  riastrad 	evergreen_mc_resume(rdev, &save);
   5341  1.1  riastrad 	/* we need to own VRAM, so turn off the VGA renderer here
   5342  1.1  riastrad 	 * to stop it overwriting our objects */
   5343  1.1  riastrad 	rv515_vga_render_disable(rdev);
   5344  1.1  riastrad }
   5345  1.1  riastrad 
   5346  1.1  riastrad /**
   5347  1.1  riastrad  * cik_mc_init - initialize the memory controller driver params
   5348  1.1  riastrad  *
   5349  1.1  riastrad  * @rdev: radeon_device pointer
   5350  1.1  riastrad  *
   5351  1.1  riastrad  * Look up the amount of vram, vram width, and decide how to place
   5352  1.1  riastrad  * vram and gart within the GPU's physical address space (CIK).
   5353  1.1  riastrad  * Returns 0 for success.
   5354  1.1  riastrad  */
   5355  1.1  riastrad static int cik_mc_init(struct radeon_device *rdev)
   5356  1.1  riastrad {
   5357  1.1  riastrad 	u32 tmp;
   5358  1.1  riastrad 	int chansize, numchan;
   5359  1.1  riastrad 
   5360  1.1  riastrad 	/* Get VRAM informations */
   5361  1.1  riastrad 	rdev->mc.vram_is_ddr = true;
   5362  1.1  riastrad 	tmp = RREG32(MC_ARB_RAMCFG);
   5363  1.1  riastrad 	if (tmp & CHANSIZE_MASK) {
   5364  1.1  riastrad 		chansize = 64;
   5365  1.1  riastrad 	} else {
   5366  1.1  riastrad 		chansize = 32;
   5367  1.1  riastrad 	}
   5368  1.1  riastrad 	tmp = RREG32(MC_SHARED_CHMAP);
   5369  1.1  riastrad 	switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
   5370  1.1  riastrad 	case 0:
   5371  1.1  riastrad 	default:
   5372  1.1  riastrad 		numchan = 1;
   5373  1.1  riastrad 		break;
   5374  1.1  riastrad 	case 1:
   5375  1.1  riastrad 		numchan = 2;
   5376  1.1  riastrad 		break;
   5377  1.1  riastrad 	case 2:
   5378  1.1  riastrad 		numchan = 4;
   5379  1.1  riastrad 		break;
   5380  1.1  riastrad 	case 3:
   5381  1.1  riastrad 		numchan = 8;
   5382  1.1  riastrad 		break;
   5383  1.1  riastrad 	case 4:
   5384  1.1  riastrad 		numchan = 3;
   5385  1.1  riastrad 		break;
   5386  1.1  riastrad 	case 5:
   5387  1.1  riastrad 		numchan = 6;
   5388  1.1  riastrad 		break;
   5389  1.1  riastrad 	case 6:
   5390  1.1  riastrad 		numchan = 10;
   5391  1.1  riastrad 		break;
   5392  1.1  riastrad 	case 7:
   5393  1.1  riastrad 		numchan = 12;
   5394  1.1  riastrad 		break;
   5395  1.1  riastrad 	case 8:
   5396  1.1  riastrad 		numchan = 16;
   5397  1.1  riastrad 		break;
   5398  1.1  riastrad 	}
   5399  1.1  riastrad 	rdev->mc.vram_width = numchan * chansize;
   5400  1.1  riastrad 	/* Could aper size report 0 ? */
   5401  1.1  riastrad 	rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
   5402  1.1  riastrad 	rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
   5403  1.1  riastrad 	/* size in MB on si */
   5404  1.1  riastrad 	rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
   5405  1.1  riastrad 	rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024ULL * 1024ULL;
   5406  1.1  riastrad 	rdev->mc.visible_vram_size = rdev->mc.aper_size;
   5407  1.1  riastrad 	si_vram_gtt_location(rdev, &rdev->mc);
   5408  1.1  riastrad 	radeon_update_bandwidth_info(rdev);
   5409  1.1  riastrad 
   5410  1.1  riastrad 	return 0;
   5411  1.1  riastrad }
   5412  1.1  riastrad 
   5413  1.1  riastrad /*
   5414  1.1  riastrad  * GART
   5415  1.1  riastrad  * VMID 0 is the physical GPU addresses as used by the kernel.
   5416  1.1  riastrad  * VMIDs 1-15 are used for userspace clients and are handled
   5417  1.1  riastrad  * by the radeon vm/hsa code.
   5418  1.1  riastrad  */
   5419  1.1  riastrad /**
   5420  1.1  riastrad  * cik_pcie_gart_tlb_flush - gart tlb flush callback
   5421  1.1  riastrad  *
   5422  1.1  riastrad  * @rdev: radeon_device pointer
   5423  1.1  riastrad  *
   5424  1.1  riastrad  * Flush the TLB for the VMID 0 page table (CIK).
   5425  1.1  riastrad  */
   5426  1.1  riastrad void cik_pcie_gart_tlb_flush(struct radeon_device *rdev)
   5427  1.1  riastrad {
   5428  1.1  riastrad 	/* flush hdp cache */
   5429  1.1  riastrad 	WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0);
   5430  1.1  riastrad 
   5431  1.1  riastrad 	/* bits 0-15 are the VM contexts0-15 */
   5432  1.1  riastrad 	WREG32(VM_INVALIDATE_REQUEST, 0x1);
   5433  1.1  riastrad }
   5434  1.1  riastrad 
   5435  1.1  riastrad /**
   5436  1.1  riastrad  * cik_pcie_gart_enable - gart enable
   5437  1.1  riastrad  *
   5438  1.1  riastrad  * @rdev: radeon_device pointer
   5439  1.1  riastrad  *
   5440  1.1  riastrad  * This sets up the TLBs, programs the page tables for VMID0,
   5441  1.1  riastrad  * sets up the hw for VMIDs 1-15 which are allocated on
   5442  1.1  riastrad  * demand, and sets up the global locations for the LDS, GDS,
   5443  1.1  riastrad  * and GPUVM for FSA64 clients (CIK).
   5444  1.1  riastrad  * Returns 0 for success, errors for failure.
   5445  1.1  riastrad  */
   5446  1.1  riastrad static int cik_pcie_gart_enable(struct radeon_device *rdev)
   5447  1.1  riastrad {
   5448  1.1  riastrad 	int r, i;
   5449  1.1  riastrad 
   5450  1.1  riastrad 	if (rdev->gart.robj == NULL) {
   5451  1.1  riastrad 		dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
   5452  1.1  riastrad 		return -EINVAL;
   5453  1.1  riastrad 	}
   5454  1.1  riastrad 	r = radeon_gart_table_vram_pin(rdev);
   5455  1.1  riastrad 	if (r)
   5456  1.1  riastrad 		return r;
   5457  1.1  riastrad 	/* Setup TLB control */
   5458  1.1  riastrad 	WREG32(MC_VM_MX_L1_TLB_CNTL,
   5459  1.1  riastrad 	       (0xA << 7) |
   5460  1.1  riastrad 	       ENABLE_L1_TLB |
   5461  1.1  riastrad 	       ENABLE_L1_FRAGMENT_PROCESSING |
   5462  1.1  riastrad 	       SYSTEM_ACCESS_MODE_NOT_IN_SYS |
   5463  1.1  riastrad 	       ENABLE_ADVANCED_DRIVER_MODEL |
   5464  1.1  riastrad 	       SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
   5465  1.1  riastrad 	/* Setup L2 cache */
   5466  1.1  riastrad 	WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
   5467  1.1  riastrad 	       ENABLE_L2_FRAGMENT_PROCESSING |
   5468  1.1  riastrad 	       ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
   5469  1.1  riastrad 	       ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
   5470  1.1  riastrad 	       EFFECTIVE_L2_QUEUE_SIZE(7) |
   5471  1.1  riastrad 	       CONTEXT1_IDENTITY_ACCESS_MODE(1));
   5472  1.1  riastrad 	WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
   5473  1.1  riastrad 	WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
   5474  1.1  riastrad 	       BANK_SELECT(4) |
   5475  1.1  riastrad 	       L2_CACHE_BIGK_FRAGMENT_SIZE(4));
   5476  1.1  riastrad 	/* setup context0 */
   5477  1.1  riastrad 	WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
   5478  1.1  riastrad 	WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
   5479  1.1  riastrad 	WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
   5480  1.1  riastrad 	WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
   5481  1.1  riastrad 			(u32)(rdev->dummy_page.addr >> 12));
   5482  1.1  riastrad 	WREG32(VM_CONTEXT0_CNTL2, 0);
   5483  1.1  riastrad 	WREG32(VM_CONTEXT0_CNTL, (ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
   5484  1.1  riastrad 				  RANGE_PROTECTION_FAULT_ENABLE_DEFAULT));
   5485  1.1  riastrad 
   5486  1.1  riastrad 	WREG32(0x15D4, 0);
   5487  1.1  riastrad 	WREG32(0x15D8, 0);
   5488  1.1  riastrad 	WREG32(0x15DC, 0);
   5489  1.1  riastrad 
   5490  1.1  riastrad 	/* restore context1-15 */
   5491  1.1  riastrad 	/* set vm size, must be a multiple of 4 */
   5492  1.1  riastrad 	WREG32(VM_CONTEXT1_PAGE_TABLE_START_ADDR, 0);
   5493  1.1  riastrad 	WREG32(VM_CONTEXT1_PAGE_TABLE_END_ADDR, rdev->vm_manager.max_pfn - 1);
   5494  1.1  riastrad 	for (i = 1; i < 16; i++) {
   5495  1.1  riastrad 		if (i < 8)
   5496  1.1  riastrad 			WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
   5497  1.1  riastrad 			       rdev->vm_manager.saved_table_addr[i]);
   5498  1.1  riastrad 		else
   5499  1.1  riastrad 			WREG32(VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2),
   5500  1.1  riastrad 			       rdev->vm_manager.saved_table_addr[i]);
   5501  1.1  riastrad 	}
   5502  1.1  riastrad 
   5503  1.1  riastrad 	/* enable context1-15 */
   5504  1.1  riastrad 	WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
   5505  1.1  riastrad 	       (u32)(rdev->dummy_page.addr >> 12));
   5506  1.1  riastrad 	WREG32(VM_CONTEXT1_CNTL2, 4);
   5507  1.1  riastrad 	WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
   5508  1.1  riastrad 				PAGE_TABLE_BLOCK_SIZE(radeon_vm_block_size - 9) |
   5509  1.1  riastrad 				RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
   5510  1.1  riastrad 				RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
   5511  1.1  riastrad 				DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
   5512  1.1  riastrad 				DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
   5513  1.1  riastrad 				PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
   5514  1.1  riastrad 				PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
   5515  1.1  riastrad 				VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
   5516  1.1  riastrad 				VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
   5517  1.1  riastrad 				READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
   5518  1.1  riastrad 				READ_PROTECTION_FAULT_ENABLE_DEFAULT |
   5519  1.1  riastrad 				WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
   5520  1.1  riastrad 				WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
   5521  1.1  riastrad 
   5522  1.1  riastrad 	if (rdev->family == CHIP_KAVERI) {
   5523  1.1  riastrad 		u32 tmp = RREG32(CHUB_CONTROL);
   5524  1.1  riastrad 		tmp &= ~BYPASS_VM;
   5525  1.1  riastrad 		WREG32(CHUB_CONTROL, tmp);
   5526  1.1  riastrad 	}
   5527  1.1  riastrad 
   5528  1.1  riastrad 	/* XXX SH_MEM regs */
   5529  1.1  riastrad 	/* where to put LDS, scratch, GPUVM in FSA64 space */
   5530  1.1  riastrad 	mutex_lock(&rdev->srbm_mutex);
   5531  1.1  riastrad 	for (i = 0; i < 16; i++) {
   5532  1.1  riastrad 		cik_srbm_select(rdev, 0, 0, 0, i);
   5533  1.1  riastrad 		/* CP and shaders */
   5534  1.3  riastrad 		WREG32(SH_MEM_CONFIG, SH_MEM_CONFIG_GFX_DEFAULT);
   5535  1.1  riastrad 		WREG32(SH_MEM_APE1_BASE, 1);
   5536  1.1  riastrad 		WREG32(SH_MEM_APE1_LIMIT, 0);
   5537  1.1  riastrad 		WREG32(SH_MEM_BASES, 0);
   5538  1.1  riastrad 		/* SDMA GFX */
   5539  1.1  riastrad 		WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA0_REGISTER_OFFSET, 0);
   5540  1.1  riastrad 		WREG32(SDMA0_GFX_APE1_CNTL + SDMA0_REGISTER_OFFSET, 0);
   5541  1.1  riastrad 		WREG32(SDMA0_GFX_VIRTUAL_ADDR + SDMA1_REGISTER_OFFSET, 0);
   5542  1.1  riastrad 		WREG32(SDMA0_GFX_APE1_CNTL + SDMA1_REGISTER_OFFSET, 0);
   5543  1.1  riastrad 		/* XXX SDMA RLC - todo */
   5544  1.1  riastrad 	}
   5545  1.1  riastrad 	cik_srbm_select(rdev, 0, 0, 0, 0);
   5546  1.1  riastrad 	mutex_unlock(&rdev->srbm_mutex);
   5547  1.1  riastrad 
   5548  1.1  riastrad 	cik_pcie_gart_tlb_flush(rdev);
   5549  1.1  riastrad 	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
   5550  1.1  riastrad 		 (unsigned)(rdev->mc.gtt_size >> 20),
   5551  1.1  riastrad 		 (unsigned long long)rdev->gart.table_addr);
   5552  1.1  riastrad 	rdev->gart.ready = true;
   5553  1.1  riastrad 	return 0;
   5554  1.1  riastrad }
   5555  1.1  riastrad 
   5556  1.1  riastrad /**
   5557  1.1  riastrad  * cik_pcie_gart_disable - gart disable
   5558  1.1  riastrad  *
   5559  1.1  riastrad  * @rdev: radeon_device pointer
   5560  1.1  riastrad  *
   5561  1.1  riastrad  * This disables all VM page table (CIK).
   5562  1.1  riastrad  */
   5563  1.1  riastrad static void cik_pcie_gart_disable(struct radeon_device *rdev)
   5564  1.1  riastrad {
   5565  1.1  riastrad 	unsigned i;
   5566  1.1  riastrad 
   5567  1.1  riastrad 	for (i = 1; i < 16; ++i) {
   5568  1.1  riastrad 		uint32_t reg;
   5569  1.1  riastrad 		if (i < 8)
   5570  1.1  riastrad 			reg = VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2);
   5571  1.1  riastrad 		else
   5572  1.1  riastrad 			reg = VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((i - 8) << 2);
   5573  1.1  riastrad 		rdev->vm_manager.saved_table_addr[i] = RREG32(reg);
   5574  1.1  riastrad 	}
   5575  1.1  riastrad 
   5576  1.1  riastrad 	/* Disable all tables */
   5577  1.1  riastrad 	WREG32(VM_CONTEXT0_CNTL, 0);
   5578  1.1  riastrad 	WREG32(VM_CONTEXT1_CNTL, 0);
   5579  1.1  riastrad 	/* Setup TLB control */
   5580  1.1  riastrad 	WREG32(MC_VM_MX_L1_TLB_CNTL, SYSTEM_ACCESS_MODE_NOT_IN_SYS |
   5581  1.1  riastrad 	       SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
   5582  1.1  riastrad 	/* Setup L2 cache */
   5583  1.1  riastrad 	WREG32(VM_L2_CNTL,
   5584  1.1  riastrad 	       ENABLE_L2_FRAGMENT_PROCESSING |
   5585  1.1  riastrad 	       ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
   5586  1.1  riastrad 	       ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
   5587  1.1  riastrad 	       EFFECTIVE_L2_QUEUE_SIZE(7) |
   5588  1.1  riastrad 	       CONTEXT1_IDENTITY_ACCESS_MODE(1));
   5589  1.1  riastrad 	WREG32(VM_L2_CNTL2, 0);
   5590  1.1  riastrad 	WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
   5591  1.1  riastrad 	       L2_CACHE_BIGK_FRAGMENT_SIZE(6));
   5592  1.1  riastrad 	radeon_gart_table_vram_unpin(rdev);
   5593  1.1  riastrad }
   5594  1.1  riastrad 
   5595  1.1  riastrad /**
   5596  1.1  riastrad  * cik_pcie_gart_fini - vm fini callback
   5597  1.1  riastrad  *
   5598  1.1  riastrad  * @rdev: radeon_device pointer
   5599  1.1  riastrad  *
   5600  1.1  riastrad  * Tears down the driver GART/VM setup (CIK).
   5601  1.1  riastrad  */
   5602  1.1  riastrad static void cik_pcie_gart_fini(struct radeon_device *rdev)
   5603  1.1  riastrad {
   5604  1.1  riastrad 	cik_pcie_gart_disable(rdev);
   5605  1.1  riastrad 	radeon_gart_table_vram_free(rdev);
   5606  1.1  riastrad 	radeon_gart_fini(rdev);
   5607  1.1  riastrad }
   5608  1.1  riastrad 
   5609  1.1  riastrad /* vm parser */
   5610  1.1  riastrad /**
   5611  1.1  riastrad  * cik_ib_parse - vm ib_parse callback
   5612  1.1  riastrad  *
   5613  1.1  riastrad  * @rdev: radeon_device pointer
   5614  1.1  riastrad  * @ib: indirect buffer pointer
   5615  1.1  riastrad  *
   5616  1.1  riastrad  * CIK uses hw IB checking so this is a nop (CIK).
   5617  1.1  riastrad  */
   5618  1.1  riastrad int cik_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib)
   5619  1.1  riastrad {
   5620  1.1  riastrad 	return 0;
   5621  1.1  riastrad }
   5622  1.1  riastrad 
   5623  1.1  riastrad /*
   5624  1.1  riastrad  * vm
   5625  1.1  riastrad  * VMID 0 is the physical GPU addresses as used by the kernel.
   5626  1.1  riastrad  * VMIDs 1-15 are used for userspace clients and are handled
   5627  1.1  riastrad  * by the radeon vm/hsa code.
   5628  1.1  riastrad  */
   5629  1.1  riastrad /**
   5630  1.1  riastrad  * cik_vm_init - cik vm init callback
   5631  1.1  riastrad  *
   5632  1.1  riastrad  * @rdev: radeon_device pointer
   5633  1.1  riastrad  *
   5634  1.1  riastrad  * Inits cik specific vm parameters (number of VMs, base of vram for
   5635  1.1  riastrad  * VMIDs 1-15) (CIK).
   5636  1.1  riastrad  * Returns 0 for success.
   5637  1.1  riastrad  */
   5638  1.1  riastrad int cik_vm_init(struct radeon_device *rdev)
   5639  1.1  riastrad {
   5640  1.1  riastrad 	/*
   5641  1.1  riastrad 	 * number of VMs
   5642  1.1  riastrad 	 * VMID 0 is reserved for System
   5643  1.3  riastrad 	 * radeon graphics/compute will use VMIDs 1-15
   5644  1.1  riastrad 	 */
   5645  1.3  riastrad 	rdev->vm_manager.nvm = 16;
   5646  1.1  riastrad 	/* base offset of vram pages */
   5647  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP) {
   5648  1.1  riastrad 		u64 tmp = RREG32(MC_VM_FB_OFFSET);
   5649  1.1  riastrad 		tmp <<= 22;
   5650  1.1  riastrad 		rdev->vm_manager.vram_base_offset = tmp;
   5651  1.1  riastrad 	} else
   5652  1.1  riastrad 		rdev->vm_manager.vram_base_offset = 0;
   5653  1.1  riastrad 
   5654  1.1  riastrad 	return 0;
   5655  1.1  riastrad }
   5656  1.1  riastrad 
   5657  1.1  riastrad /**
   5658  1.1  riastrad  * cik_vm_fini - cik vm fini callback
   5659  1.1  riastrad  *
   5660  1.1  riastrad  * @rdev: radeon_device pointer
   5661  1.1  riastrad  *
   5662  1.1  riastrad  * Tear down any asic specific VM setup (CIK).
   5663  1.1  riastrad  */
   5664  1.1  riastrad void cik_vm_fini(struct radeon_device *rdev)
   5665  1.1  riastrad {
   5666  1.1  riastrad }
   5667  1.1  riastrad 
   5668  1.1  riastrad /**
   5669  1.1  riastrad  * cik_vm_decode_fault - print human readable fault info
   5670  1.1  riastrad  *
   5671  1.1  riastrad  * @rdev: radeon_device pointer
   5672  1.1  riastrad  * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
   5673  1.1  riastrad  * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
   5674  1.1  riastrad  *
   5675  1.1  riastrad  * Print human readable fault information (CIK).
   5676  1.1  riastrad  */
   5677  1.1  riastrad static void cik_vm_decode_fault(struct radeon_device *rdev,
   5678  1.1  riastrad 				u32 status, u32 addr, u32 mc_client)
   5679  1.1  riastrad {
   5680  1.1  riastrad 	u32 mc_id;
   5681  1.1  riastrad 	u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
   5682  1.1  riastrad 	u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
   5683  1.1  riastrad 	char block[5] = { mc_client >> 24, (mc_client >> 16) & 0xff,
   5684  1.1  riastrad 		(mc_client >> 8) & 0xff, mc_client & 0xff, 0 };
   5685  1.1  riastrad 
   5686  1.1  riastrad 	if (rdev->family == CHIP_HAWAII)
   5687  1.1  riastrad 		mc_id = (status & HAWAII_MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
   5688  1.1  riastrad 	else
   5689  1.1  riastrad 		mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
   5690  1.1  riastrad 
   5691  1.1  riastrad 	printk("VM fault (0x%02x, vmid %d) at page %u, %s from '%s' (0x%08x) (%d)\n",
   5692  1.1  riastrad 	       protections, vmid, addr,
   5693  1.1  riastrad 	       (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
   5694  1.1  riastrad 	       block, mc_client, mc_id);
   5695  1.1  riastrad }
   5696  1.1  riastrad 
   5697  1.1  riastrad /**
   5698  1.1  riastrad  * cik_vm_flush - cik vm flush using the CP
   5699  1.1  riastrad  *
   5700  1.1  riastrad  * @rdev: radeon_device pointer
   5701  1.1  riastrad  *
   5702  1.1  riastrad  * Update the page table base and flush the VM TLB
   5703  1.1  riastrad  * using the CP (CIK).
   5704  1.1  riastrad  */
   5705  1.1  riastrad void cik_vm_flush(struct radeon_device *rdev, struct radeon_ring *ring,
   5706  1.1  riastrad 		  unsigned vm_id, uint64_t pd_addr)
   5707  1.1  riastrad {
   5708  1.1  riastrad 	int usepfp = (ring->idx == RADEON_RING_TYPE_GFX_INDEX);
   5709  1.1  riastrad 
   5710  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
   5711  1.1  riastrad 	radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
   5712  1.1  riastrad 				 WRITE_DATA_DST_SEL(0)));
   5713  1.1  riastrad 	if (vm_id < 8) {
   5714  1.1  riastrad 		radeon_ring_write(ring,
   5715  1.1  riastrad 				  (VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm_id << 2)) >> 2);
   5716  1.1  riastrad 	} else {
   5717  1.1  riastrad 		radeon_ring_write(ring,
   5718  1.1  riastrad 				  (VM_CONTEXT8_PAGE_TABLE_BASE_ADDR + ((vm_id - 8) << 2)) >> 2);
   5719  1.1  riastrad 	}
   5720  1.1  riastrad 	radeon_ring_write(ring, 0);
   5721  1.1  riastrad 	radeon_ring_write(ring, pd_addr >> 12);
   5722  1.1  riastrad 
   5723  1.1  riastrad 	/* update SH_MEM_* regs */
   5724  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
   5725  1.1  riastrad 	radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
   5726  1.1  riastrad 				 WRITE_DATA_DST_SEL(0)));
   5727  1.1  riastrad 	radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
   5728  1.1  riastrad 	radeon_ring_write(ring, 0);
   5729  1.1  riastrad 	radeon_ring_write(ring, VMID(vm_id));
   5730  1.1  riastrad 
   5731  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 6));
   5732  1.1  riastrad 	radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
   5733  1.1  riastrad 				 WRITE_DATA_DST_SEL(0)));
   5734  1.1  riastrad 	radeon_ring_write(ring, SH_MEM_BASES >> 2);
   5735  1.1  riastrad 	radeon_ring_write(ring, 0);
   5736  1.1  riastrad 
   5737  1.1  riastrad 	radeon_ring_write(ring, 0); /* SH_MEM_BASES */
   5738  1.3  riastrad 	radeon_ring_write(ring, SH_MEM_CONFIG_GFX_DEFAULT); /* SH_MEM_CONFIG */
   5739  1.1  riastrad 	radeon_ring_write(ring, 1); /* SH_MEM_APE1_BASE */
   5740  1.1  riastrad 	radeon_ring_write(ring, 0); /* SH_MEM_APE1_LIMIT */
   5741  1.1  riastrad 
   5742  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
   5743  1.1  riastrad 	radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
   5744  1.1  riastrad 				 WRITE_DATA_DST_SEL(0)));
   5745  1.1  riastrad 	radeon_ring_write(ring, SRBM_GFX_CNTL >> 2);
   5746  1.1  riastrad 	radeon_ring_write(ring, 0);
   5747  1.1  riastrad 	radeon_ring_write(ring, VMID(0));
   5748  1.1  riastrad 
   5749  1.1  riastrad 	/* HDP flush */
   5750  1.1  riastrad 	cik_hdp_flush_cp_ring_emit(rdev, ring->idx);
   5751  1.1  riastrad 
   5752  1.1  riastrad 	/* bits 0-15 are the VM contexts0-15 */
   5753  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));
   5754  1.1  riastrad 	radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(usepfp) |
   5755  1.1  riastrad 				 WRITE_DATA_DST_SEL(0)));
   5756  1.1  riastrad 	radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
   5757  1.1  riastrad 	radeon_ring_write(ring, 0);
   5758  1.1  riastrad 	radeon_ring_write(ring, 1 << vm_id);
   5759  1.1  riastrad 
   5760  1.1  riastrad 	/* wait for the invalidate to complete */
   5761  1.1  riastrad 	radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
   5762  1.1  riastrad 	radeon_ring_write(ring, (WAIT_REG_MEM_OPERATION(0) | /* wait */
   5763  1.1  riastrad 				 WAIT_REG_MEM_FUNCTION(0) |  /* always */
   5764  1.1  riastrad 				 WAIT_REG_MEM_ENGINE(0))); /* me */
   5765  1.1  riastrad 	radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
   5766  1.1  riastrad 	radeon_ring_write(ring, 0);
   5767  1.1  riastrad 	radeon_ring_write(ring, 0); /* ref */
   5768  1.1  riastrad 	radeon_ring_write(ring, 0); /* mask */
   5769  1.1  riastrad 	radeon_ring_write(ring, 0x20); /* poll interval */
   5770  1.1  riastrad 
   5771  1.1  riastrad 	/* compute doesn't have PFP */
   5772  1.1  riastrad 	if (usepfp) {
   5773  1.1  riastrad 		/* sync PFP to ME, otherwise we might get invalid PFP reads */
   5774  1.1  riastrad 		radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
   5775  1.1  riastrad 		radeon_ring_write(ring, 0x0);
   5776  1.1  riastrad 	}
   5777  1.1  riastrad }
   5778  1.1  riastrad 
   5779  1.1  riastrad /*
   5780  1.1  riastrad  * RLC
   5781  1.1  riastrad  * The RLC is a multi-purpose microengine that handles a
   5782  1.1  riastrad  * variety of functions, the most important of which is
   5783  1.1  riastrad  * the interrupt controller.
   5784  1.1  riastrad  */
   5785  1.1  riastrad static void cik_enable_gui_idle_interrupt(struct radeon_device *rdev,
   5786  1.1  riastrad 					  bool enable)
   5787  1.1  riastrad {
   5788  1.1  riastrad 	u32 tmp = RREG32(CP_INT_CNTL_RING0);
   5789  1.1  riastrad 
   5790  1.1  riastrad 	if (enable)
   5791  1.1  riastrad 		tmp |= (CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
   5792  1.1  riastrad 	else
   5793  1.1  riastrad 		tmp &= ~(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
   5794  1.1  riastrad 	WREG32(CP_INT_CNTL_RING0, tmp);
   5795  1.1  riastrad }
   5796  1.1  riastrad 
   5797  1.1  riastrad static void cik_enable_lbpw(struct radeon_device *rdev, bool enable)
   5798  1.1  riastrad {
   5799  1.1  riastrad 	u32 tmp;
   5800  1.1  riastrad 
   5801  1.1  riastrad 	tmp = RREG32(RLC_LB_CNTL);
   5802  1.1  riastrad 	if (enable)
   5803  1.1  riastrad 		tmp |= LOAD_BALANCE_ENABLE;
   5804  1.1  riastrad 	else
   5805  1.1  riastrad 		tmp &= ~LOAD_BALANCE_ENABLE;
   5806  1.1  riastrad 	WREG32(RLC_LB_CNTL, tmp);
   5807  1.1  riastrad }
   5808  1.1  riastrad 
   5809  1.1  riastrad static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)
   5810  1.1  riastrad {
   5811  1.1  riastrad 	u32 i, j, k;
   5812  1.1  riastrad 	u32 mask;
   5813  1.1  riastrad 
   5814  1.1  riastrad 	for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
   5815  1.1  riastrad 		for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
   5816  1.1  riastrad 			cik_select_se_sh(rdev, i, j);
   5817  1.1  riastrad 			for (k = 0; k < rdev->usec_timeout; k++) {
   5818  1.1  riastrad 				if (RREG32(RLC_SERDES_CU_MASTER_BUSY) == 0)
   5819  1.1  riastrad 					break;
   5820  1.1  riastrad 				udelay(1);
   5821  1.1  riastrad 			}
   5822  1.1  riastrad 		}
   5823  1.1  riastrad 	}
   5824  1.1  riastrad 	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
   5825  1.1  riastrad 
   5826  1.1  riastrad 	mask = SE_MASTER_BUSY_MASK | GC_MASTER_BUSY | TC0_MASTER_BUSY | TC1_MASTER_BUSY;
   5827  1.1  riastrad 	for (k = 0; k < rdev->usec_timeout; k++) {
   5828  1.1  riastrad 		if ((RREG32(RLC_SERDES_NONCU_MASTER_BUSY) & mask) == 0)
   5829  1.1  riastrad 			break;
   5830  1.1  riastrad 		udelay(1);
   5831  1.1  riastrad 	}
   5832  1.1  riastrad }
   5833  1.1  riastrad 
   5834  1.1  riastrad static void cik_update_rlc(struct radeon_device *rdev, u32 rlc)
   5835  1.1  riastrad {
   5836  1.1  riastrad 	u32 tmp;
   5837  1.1  riastrad 
   5838  1.1  riastrad 	tmp = RREG32(RLC_CNTL);
   5839  1.1  riastrad 	if (tmp != rlc)
   5840  1.1  riastrad 		WREG32(RLC_CNTL, rlc);
   5841  1.1  riastrad }
   5842  1.1  riastrad 
   5843  1.1  riastrad static u32 cik_halt_rlc(struct radeon_device *rdev)
   5844  1.1  riastrad {
   5845  1.1  riastrad 	u32 data, orig;
   5846  1.1  riastrad 
   5847  1.1  riastrad 	orig = data = RREG32(RLC_CNTL);
   5848  1.1  riastrad 
   5849  1.1  riastrad 	if (data & RLC_ENABLE) {
   5850  1.1  riastrad 		u32 i;
   5851  1.1  riastrad 
   5852  1.1  riastrad 		data &= ~RLC_ENABLE;
   5853  1.1  riastrad 		WREG32(RLC_CNTL, data);
   5854  1.1  riastrad 
   5855  1.1  riastrad 		for (i = 0; i < rdev->usec_timeout; i++) {
   5856  1.1  riastrad 			if ((RREG32(RLC_GPM_STAT) & RLC_GPM_BUSY) == 0)
   5857  1.1  riastrad 				break;
   5858  1.1  riastrad 			udelay(1);
   5859  1.1  riastrad 		}
   5860  1.1  riastrad 
   5861  1.1  riastrad 		cik_wait_for_rlc_serdes(rdev);
   5862  1.1  riastrad 	}
   5863  1.1  riastrad 
   5864  1.1  riastrad 	return orig;
   5865  1.1  riastrad }
   5866  1.1  riastrad 
   5867  1.1  riastrad void cik_enter_rlc_safe_mode(struct radeon_device *rdev)
   5868  1.1  riastrad {
   5869  1.1  riastrad 	u32 tmp, i, mask;
   5870  1.1  riastrad 
   5871  1.1  riastrad 	tmp = REQ | MESSAGE(MSG_ENTER_RLC_SAFE_MODE);
   5872  1.1  riastrad 	WREG32(RLC_GPR_REG2, tmp);
   5873  1.1  riastrad 
   5874  1.1  riastrad 	mask = GFX_POWER_STATUS | GFX_CLOCK_STATUS;
   5875  1.1  riastrad 	for (i = 0; i < rdev->usec_timeout; i++) {
   5876  1.1  riastrad 		if ((RREG32(RLC_GPM_STAT) & mask) == mask)
   5877  1.1  riastrad 			break;
   5878  1.1  riastrad 		udelay(1);
   5879  1.1  riastrad 	}
   5880  1.1  riastrad 
   5881  1.1  riastrad 	for (i = 0; i < rdev->usec_timeout; i++) {
   5882  1.1  riastrad 		if ((RREG32(RLC_GPR_REG2) & REQ) == 0)
   5883  1.1  riastrad 			break;
   5884  1.1  riastrad 		udelay(1);
   5885  1.1  riastrad 	}
   5886  1.1  riastrad }
   5887  1.1  riastrad 
   5888  1.1  riastrad void cik_exit_rlc_safe_mode(struct radeon_device *rdev)
   5889  1.1  riastrad {
   5890  1.1  riastrad 	u32 tmp;
   5891  1.1  riastrad 
   5892  1.1  riastrad 	tmp = REQ | MESSAGE(MSG_EXIT_RLC_SAFE_MODE);
   5893  1.1  riastrad 	WREG32(RLC_GPR_REG2, tmp);
   5894  1.1  riastrad }
   5895  1.1  riastrad 
   5896  1.1  riastrad /**
   5897  1.1  riastrad  * cik_rlc_stop - stop the RLC ME
   5898  1.1  riastrad  *
   5899  1.1  riastrad  * @rdev: radeon_device pointer
   5900  1.1  riastrad  *
   5901  1.1  riastrad  * Halt the RLC ME (MicroEngine) (CIK).
   5902  1.1  riastrad  */
   5903  1.1  riastrad static void cik_rlc_stop(struct radeon_device *rdev)
   5904  1.1  riastrad {
   5905  1.1  riastrad 	WREG32(RLC_CNTL, 0);
   5906  1.1  riastrad 
   5907  1.1  riastrad 	cik_enable_gui_idle_interrupt(rdev, false);
   5908  1.1  riastrad 
   5909  1.1  riastrad 	cik_wait_for_rlc_serdes(rdev);
   5910  1.1  riastrad }
   5911  1.1  riastrad 
   5912  1.1  riastrad /**
   5913  1.1  riastrad  * cik_rlc_start - start the RLC ME
   5914  1.1  riastrad  *
   5915  1.1  riastrad  * @rdev: radeon_device pointer
   5916  1.1  riastrad  *
   5917  1.1  riastrad  * Unhalt the RLC ME (MicroEngine) (CIK).
   5918  1.1  riastrad  */
   5919  1.1  riastrad static void cik_rlc_start(struct radeon_device *rdev)
   5920  1.1  riastrad {
   5921  1.1  riastrad 	WREG32(RLC_CNTL, RLC_ENABLE);
   5922  1.1  riastrad 
   5923  1.1  riastrad 	cik_enable_gui_idle_interrupt(rdev, true);
   5924  1.1  riastrad 
   5925  1.1  riastrad 	udelay(50);
   5926  1.1  riastrad }
   5927  1.1  riastrad 
   5928  1.1  riastrad /**
   5929  1.1  riastrad  * cik_rlc_resume - setup the RLC hw
   5930  1.1  riastrad  *
   5931  1.1  riastrad  * @rdev: radeon_device pointer
   5932  1.1  riastrad  *
   5933  1.1  riastrad  * Initialize the RLC registers, load the ucode,
   5934  1.1  riastrad  * and start the RLC (CIK).
   5935  1.1  riastrad  * Returns 0 for success, -EINVAL if the ucode is not available.
   5936  1.1  riastrad  */
   5937  1.1  riastrad static int cik_rlc_resume(struct radeon_device *rdev)
   5938  1.1  riastrad {
   5939  1.1  riastrad 	u32 i, size, tmp;
   5940  1.1  riastrad 
   5941  1.1  riastrad 	if (!rdev->rlc_fw)
   5942  1.1  riastrad 		return -EINVAL;
   5943  1.1  riastrad 
   5944  1.1  riastrad 	cik_rlc_stop(rdev);
   5945  1.1  riastrad 
   5946  1.1  riastrad 	/* disable CG */
   5947  1.1  riastrad 	tmp = RREG32(RLC_CGCG_CGLS_CTRL) & 0xfffffffc;
   5948  1.1  riastrad 	WREG32(RLC_CGCG_CGLS_CTRL, tmp);
   5949  1.1  riastrad 
   5950  1.1  riastrad 	si_rlc_reset(rdev);
   5951  1.1  riastrad 
   5952  1.1  riastrad 	cik_init_pg(rdev);
   5953  1.1  riastrad 
   5954  1.1  riastrad 	cik_init_cg(rdev);
   5955  1.1  riastrad 
   5956  1.1  riastrad 	WREG32(RLC_LB_CNTR_INIT, 0);
   5957  1.1  riastrad 	WREG32(RLC_LB_CNTR_MAX, 0x00008000);
   5958  1.1  riastrad 
   5959  1.1  riastrad 	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
   5960  1.1  riastrad 	WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
   5961  1.1  riastrad 	WREG32(RLC_LB_PARAMS, 0x00600408);
   5962  1.1  riastrad 	WREG32(RLC_LB_CNTL, 0x80000004);
   5963  1.1  riastrad 
   5964  1.1  riastrad 	WREG32(RLC_MC_CNTL, 0);
   5965  1.1  riastrad 	WREG32(RLC_UCODE_CNTL, 0);
   5966  1.1  riastrad 
   5967  1.1  riastrad 	if (rdev->new_fw) {
   5968  1.1  riastrad 		const struct rlc_firmware_header_v1_0 *hdr =
   5969  1.1  riastrad 			(const struct rlc_firmware_header_v1_0 *)rdev->rlc_fw->data;
   5970  1.1  riastrad 		const __le32 *fw_data = (const __le32 *)
   5971  1.1  riastrad 			(rdev->rlc_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
   5972  1.1  riastrad 
   5973  1.1  riastrad 		radeon_ucode_print_rlc_hdr(&hdr->header);
   5974  1.1  riastrad 
   5975  1.1  riastrad 		size = le32_to_cpu(hdr->header.ucode_size_bytes) / 4;
   5976  1.1  riastrad 		WREG32(RLC_GPM_UCODE_ADDR, 0);
   5977  1.1  riastrad 		for (i = 0; i < size; i++)
   5978  1.1  riastrad 			WREG32(RLC_GPM_UCODE_DATA, le32_to_cpup(fw_data++));
   5979  1.1  riastrad 		WREG32(RLC_GPM_UCODE_ADDR, le32_to_cpu(hdr->header.ucode_version));
   5980  1.1  riastrad 	} else {
   5981  1.1  riastrad 		const __be32 *fw_data;
   5982  1.1  riastrad 
   5983  1.1  riastrad 		switch (rdev->family) {
   5984  1.1  riastrad 		case CHIP_BONAIRE:
   5985  1.1  riastrad 		case CHIP_HAWAII:
   5986  1.1  riastrad 		default:
   5987  1.1  riastrad 			size = BONAIRE_RLC_UCODE_SIZE;
   5988  1.1  riastrad 			break;
   5989  1.1  riastrad 		case CHIP_KAVERI:
   5990  1.1  riastrad 			size = KV_RLC_UCODE_SIZE;
   5991  1.1  riastrad 			break;
   5992  1.1  riastrad 		case CHIP_KABINI:
   5993  1.1  riastrad 			size = KB_RLC_UCODE_SIZE;
   5994  1.1  riastrad 			break;
   5995  1.1  riastrad 		case CHIP_MULLINS:
   5996  1.1  riastrad 			size = ML_RLC_UCODE_SIZE;
   5997  1.1  riastrad 			break;
   5998  1.1  riastrad 		}
   5999  1.1  riastrad 
   6000  1.1  riastrad 		fw_data = (const __be32 *)rdev->rlc_fw->data;
   6001  1.1  riastrad 		WREG32(RLC_GPM_UCODE_ADDR, 0);
   6002  1.1  riastrad 		for (i = 0; i < size; i++)
   6003  1.1  riastrad 			WREG32(RLC_GPM_UCODE_DATA, be32_to_cpup(fw_data++));
   6004  1.1  riastrad 		WREG32(RLC_GPM_UCODE_ADDR, 0);
   6005  1.1  riastrad 	}
   6006  1.1  riastrad 
   6007  1.1  riastrad 	/* XXX - find out what chips support lbpw */
   6008  1.1  riastrad 	cik_enable_lbpw(rdev, false);
   6009  1.1  riastrad 
   6010  1.1  riastrad 	if (rdev->family == CHIP_BONAIRE)
   6011  1.1  riastrad 		WREG32(RLC_DRIVER_DMA_STATUS, 0);
   6012  1.1  riastrad 
   6013  1.1  riastrad 	cik_rlc_start(rdev);
   6014  1.1  riastrad 
   6015  1.1  riastrad 	return 0;
   6016  1.1  riastrad }
   6017  1.1  riastrad 
   6018  1.1  riastrad static void cik_enable_cgcg(struct radeon_device *rdev, bool enable)
   6019  1.1  riastrad {
   6020  1.1  riastrad 	u32 data, orig, tmp, tmp2;
   6021  1.1  riastrad 
   6022  1.1  riastrad 	orig = data = RREG32(RLC_CGCG_CGLS_CTRL);
   6023  1.1  riastrad 
   6024  1.1  riastrad 	if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGCG)) {
   6025  1.1  riastrad 		cik_enable_gui_idle_interrupt(rdev, true);
   6026  1.1  riastrad 
   6027  1.1  riastrad 		tmp = cik_halt_rlc(rdev);
   6028  1.1  riastrad 
   6029  1.1  riastrad 		cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
   6030  1.1  riastrad 		WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
   6031  1.1  riastrad 		WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
   6032  1.1  riastrad 		tmp2 = BPM_ADDR_MASK | CGCG_OVERRIDE_0 | CGLS_ENABLE;
   6033  1.1  riastrad 		WREG32(RLC_SERDES_WR_CTRL, tmp2);
   6034  1.1  riastrad 
   6035  1.1  riastrad 		cik_update_rlc(rdev, tmp);
   6036  1.1  riastrad 
   6037  1.1  riastrad 		data |= CGCG_EN | CGLS_EN;
   6038  1.1  riastrad 	} else {
   6039  1.1  riastrad 		cik_enable_gui_idle_interrupt(rdev, false);
   6040  1.1  riastrad 
   6041  1.1  riastrad 		RREG32(CB_CGTT_SCLK_CTRL);
   6042  1.1  riastrad 		RREG32(CB_CGTT_SCLK_CTRL);
   6043  1.1  riastrad 		RREG32(CB_CGTT_SCLK_CTRL);
   6044  1.1  riastrad 		RREG32(CB_CGTT_SCLK_CTRL);
   6045  1.1  riastrad 
   6046  1.1  riastrad 		data &= ~(CGCG_EN | CGLS_EN);
   6047  1.1  riastrad 	}
   6048  1.1  riastrad 
   6049  1.1  riastrad 	if (orig != data)
   6050  1.1  riastrad 		WREG32(RLC_CGCG_CGLS_CTRL, data);
   6051  1.1  riastrad 
   6052  1.1  riastrad }
   6053  1.1  riastrad 
   6054  1.1  riastrad static void cik_enable_mgcg(struct radeon_device *rdev, bool enable)
   6055  1.1  riastrad {
   6056  1.1  riastrad 	u32 data, orig, tmp = 0;
   6057  1.1  riastrad 
   6058  1.1  riastrad 	if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGCG)) {
   6059  1.1  riastrad 		if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) {
   6060  1.1  riastrad 			if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CP_LS) {
   6061  1.1  riastrad 				orig = data = RREG32(CP_MEM_SLP_CNTL);
   6062  1.1  riastrad 				data |= CP_MEM_LS_EN;
   6063  1.1  riastrad 				if (orig != data)
   6064  1.1  riastrad 					WREG32(CP_MEM_SLP_CNTL, data);
   6065  1.1  riastrad 			}
   6066  1.1  riastrad 		}
   6067  1.1  riastrad 
   6068  1.1  riastrad 		orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
   6069  1.1  riastrad 		data |= 0x00000001;
   6070  1.1  riastrad 		data &= 0xfffffffd;
   6071  1.1  riastrad 		if (orig != data)
   6072  1.1  riastrad 			WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
   6073  1.1  riastrad 
   6074  1.1  riastrad 		tmp = cik_halt_rlc(rdev);
   6075  1.1  riastrad 
   6076  1.1  riastrad 		cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
   6077  1.1  riastrad 		WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
   6078  1.1  riastrad 		WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
   6079  1.1  riastrad 		data = BPM_ADDR_MASK | MGCG_OVERRIDE_0;
   6080  1.1  riastrad 		WREG32(RLC_SERDES_WR_CTRL, data);
   6081  1.1  riastrad 
   6082  1.1  riastrad 		cik_update_rlc(rdev, tmp);
   6083  1.1  riastrad 
   6084  1.1  riastrad 		if (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS) {
   6085  1.1  riastrad 			orig = data = RREG32(CGTS_SM_CTRL_REG);
   6086  1.1  riastrad 			data &= ~SM_MODE_MASK;
   6087  1.1  riastrad 			data |= SM_MODE(0x2);
   6088  1.1  riastrad 			data |= SM_MODE_ENABLE;
   6089  1.1  riastrad 			data &= ~CGTS_OVERRIDE;
   6090  1.1  riastrad 			if ((rdev->cg_flags & RADEON_CG_SUPPORT_GFX_MGLS) &&
   6091  1.1  riastrad 			    (rdev->cg_flags & RADEON_CG_SUPPORT_GFX_CGTS_LS))
   6092  1.1  riastrad 				data &= ~CGTS_LS_OVERRIDE;
   6093  1.1  riastrad 			data &= ~ON_MONITOR_ADD_MASK;
   6094  1.1  riastrad 			data |= ON_MONITOR_ADD_EN;
   6095  1.1  riastrad 			data |= ON_MONITOR_ADD(0x96);
   6096  1.1  riastrad 			if (orig != data)
   6097  1.1  riastrad 				WREG32(CGTS_SM_CTRL_REG, data);
   6098  1.1  riastrad 		}
   6099  1.1  riastrad 	} else {
   6100  1.1  riastrad 		orig = data = RREG32(RLC_CGTT_MGCG_OVERRIDE);
   6101  1.1  riastrad 		data |= 0x00000003;
   6102  1.1  riastrad 		if (orig != data)
   6103  1.1  riastrad 			WREG32(RLC_CGTT_MGCG_OVERRIDE, data);
   6104  1.1  riastrad 
   6105  1.1  riastrad 		data = RREG32(RLC_MEM_SLP_CNTL);
   6106  1.1  riastrad 		if (data & RLC_MEM_LS_EN) {
   6107  1.1  riastrad 			data &= ~RLC_MEM_LS_EN;
   6108  1.1  riastrad 			WREG32(RLC_MEM_SLP_CNTL, data);
   6109  1.1  riastrad 		}
   6110  1.1  riastrad 
   6111  1.1  riastrad 		data = RREG32(CP_MEM_SLP_CNTL);
   6112  1.1  riastrad 		if (data & CP_MEM_LS_EN) {
   6113  1.1  riastrad 			data &= ~CP_MEM_LS_EN;
   6114  1.1  riastrad 			WREG32(CP_MEM_SLP_CNTL, data);
   6115  1.1  riastrad 		}
   6116  1.1  riastrad 
   6117  1.1  riastrad 		orig = data = RREG32(CGTS_SM_CTRL_REG);
   6118  1.1  riastrad 		data |= CGTS_OVERRIDE | CGTS_LS_OVERRIDE;
   6119  1.1  riastrad 		if (orig != data)
   6120  1.1  riastrad 			WREG32(CGTS_SM_CTRL_REG, data);
   6121  1.1  riastrad 
   6122  1.1  riastrad 		tmp = cik_halt_rlc(rdev);
   6123  1.1  riastrad 
   6124  1.1  riastrad 		cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
   6125  1.1  riastrad 		WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
   6126  1.1  riastrad 		WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
   6127  1.1  riastrad 		data = BPM_ADDR_MASK | MGCG_OVERRIDE_1;
   6128  1.1  riastrad 		WREG32(RLC_SERDES_WR_CTRL, data);
   6129  1.1  riastrad 
   6130  1.1  riastrad 		cik_update_rlc(rdev, tmp);
   6131  1.1  riastrad 	}
   6132  1.1  riastrad }
   6133  1.1  riastrad 
   6134  1.1  riastrad static const u32 mc_cg_registers[] =
   6135  1.1  riastrad {
   6136  1.1  riastrad 	MC_HUB_MISC_HUB_CG,
   6137  1.1  riastrad 	MC_HUB_MISC_SIP_CG,
   6138  1.1  riastrad 	MC_HUB_MISC_VM_CG,
   6139  1.1  riastrad 	MC_XPB_CLK_GAT,
   6140  1.1  riastrad 	ATC_MISC_CG,
   6141  1.1  riastrad 	MC_CITF_MISC_WR_CG,
   6142  1.1  riastrad 	MC_CITF_MISC_RD_CG,
   6143  1.1  riastrad 	MC_CITF_MISC_VM_CG,
   6144  1.1  riastrad 	VM_L2_CG,
   6145  1.1  riastrad };
   6146  1.1  riastrad 
   6147  1.1  riastrad static void cik_enable_mc_ls(struct radeon_device *rdev,
   6148  1.1  riastrad 			     bool enable)
   6149  1.1  riastrad {
   6150  1.1  riastrad 	int i;
   6151  1.1  riastrad 	u32 orig, data;
   6152  1.1  riastrad 
   6153  1.1  riastrad 	for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
   6154  1.1  riastrad 		orig = data = RREG32(mc_cg_registers[i]);
   6155  1.1  riastrad 		if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_LS))
   6156  1.1  riastrad 			data |= MC_LS_ENABLE;
   6157  1.1  riastrad 		else
   6158  1.1  riastrad 			data &= ~MC_LS_ENABLE;
   6159  1.1  riastrad 		if (data != orig)
   6160  1.1  riastrad 			WREG32(mc_cg_registers[i], data);
   6161  1.1  riastrad 	}
   6162  1.1  riastrad }
   6163  1.1  riastrad 
   6164  1.1  riastrad static void cik_enable_mc_mgcg(struct radeon_device *rdev,
   6165  1.1  riastrad 			       bool enable)
   6166  1.1  riastrad {
   6167  1.1  riastrad 	int i;
   6168  1.1  riastrad 	u32 orig, data;
   6169  1.1  riastrad 
   6170  1.1  riastrad 	for (i = 0; i < ARRAY_SIZE(mc_cg_registers); i++) {
   6171  1.1  riastrad 		orig = data = RREG32(mc_cg_registers[i]);
   6172  1.1  riastrad 		if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_MC_MGCG))
   6173  1.1  riastrad 			data |= MC_CG_ENABLE;
   6174  1.1  riastrad 		else
   6175  1.1  riastrad 			data &= ~MC_CG_ENABLE;
   6176  1.1  riastrad 		if (data != orig)
   6177  1.1  riastrad 			WREG32(mc_cg_registers[i], data);
   6178  1.1  riastrad 	}
   6179  1.1  riastrad }
   6180  1.1  riastrad 
   6181  1.1  riastrad static void cik_enable_sdma_mgcg(struct radeon_device *rdev,
   6182  1.1  riastrad 				 bool enable)
   6183  1.1  riastrad {
   6184  1.1  riastrad 	u32 orig, data;
   6185  1.1  riastrad 
   6186  1.1  riastrad 	if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_MGCG)) {
   6187  1.1  riastrad 		WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, 0x00000100);
   6188  1.1  riastrad 		WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, 0x00000100);
   6189  1.1  riastrad 	} else {
   6190  1.1  riastrad 		orig = data = RREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET);
   6191  1.1  riastrad 		data |= 0xff000000;
   6192  1.1  riastrad 		if (data != orig)
   6193  1.1  riastrad 			WREG32(SDMA0_CLK_CTRL + SDMA0_REGISTER_OFFSET, data);
   6194  1.1  riastrad 
   6195  1.1  riastrad 		orig = data = RREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET);
   6196  1.1  riastrad 		data |= 0xff000000;
   6197  1.1  riastrad 		if (data != orig)
   6198  1.1  riastrad 			WREG32(SDMA0_CLK_CTRL + SDMA1_REGISTER_OFFSET, data);
   6199  1.1  riastrad 	}
   6200  1.1  riastrad }
   6201  1.1  riastrad 
   6202  1.1  riastrad static void cik_enable_sdma_mgls(struct radeon_device *rdev,
   6203  1.1  riastrad 				 bool enable)
   6204  1.1  riastrad {
   6205  1.1  riastrad 	u32 orig, data;
   6206  1.1  riastrad 
   6207  1.1  riastrad 	if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_SDMA_LS)) {
   6208  1.1  riastrad 		orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
   6209  1.1  riastrad 		data |= 0x100;
   6210  1.1  riastrad 		if (orig != data)
   6211  1.1  riastrad 			WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
   6212  1.1  riastrad 
   6213  1.1  riastrad 		orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
   6214  1.1  riastrad 		data |= 0x100;
   6215  1.1  riastrad 		if (orig != data)
   6216  1.1  riastrad 			WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
   6217  1.1  riastrad 	} else {
   6218  1.1  riastrad 		orig = data = RREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET);
   6219  1.1  riastrad 		data &= ~0x100;
   6220  1.1  riastrad 		if (orig != data)
   6221  1.1  riastrad 			WREG32(SDMA0_POWER_CNTL + SDMA0_REGISTER_OFFSET, data);
   6222  1.1  riastrad 
   6223  1.1  riastrad 		orig = data = RREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET);
   6224  1.1  riastrad 		data &= ~0x100;
   6225  1.1  riastrad 		if (orig != data)
   6226  1.1  riastrad 			WREG32(SDMA0_POWER_CNTL + SDMA1_REGISTER_OFFSET, data);
   6227  1.1  riastrad 	}
   6228  1.1  riastrad }
   6229  1.1  riastrad 
   6230  1.1  riastrad static void cik_enable_uvd_mgcg(struct radeon_device *rdev,
   6231  1.1  riastrad 				bool enable)
   6232  1.1  riastrad {
   6233  1.1  riastrad 	u32 orig, data;
   6234  1.1  riastrad 
   6235  1.1  riastrad 	if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_UVD_MGCG)) {
   6236  1.1  riastrad 		data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
   6237  1.1  riastrad 		data = 0xfff;
   6238  1.1  riastrad 		WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
   6239  1.1  riastrad 
   6240  1.1  riastrad 		orig = data = RREG32(UVD_CGC_CTRL);
   6241  1.1  riastrad 		data |= DCM;
   6242  1.1  riastrad 		if (orig != data)
   6243  1.1  riastrad 			WREG32(UVD_CGC_CTRL, data);
   6244  1.1  riastrad 	} else {
   6245  1.1  riastrad 		data = RREG32_UVD_CTX(UVD_CGC_MEM_CTRL);
   6246  1.1  riastrad 		data &= ~0xfff;
   6247  1.1  riastrad 		WREG32_UVD_CTX(UVD_CGC_MEM_CTRL, data);
   6248  1.1  riastrad 
   6249  1.1  riastrad 		orig = data = RREG32(UVD_CGC_CTRL);
   6250  1.1  riastrad 		data &= ~DCM;
   6251  1.1  riastrad 		if (orig != data)
   6252  1.1  riastrad 			WREG32(UVD_CGC_CTRL, data);
   6253  1.1  riastrad 	}
   6254  1.1  riastrad }
   6255  1.1  riastrad 
   6256  1.1  riastrad static void cik_enable_bif_mgls(struct radeon_device *rdev,
   6257  1.1  riastrad 			       bool enable)
   6258  1.1  riastrad {
   6259  1.1  riastrad 	u32 orig, data;
   6260  1.1  riastrad 
   6261  1.1  riastrad 	orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
   6262  1.1  riastrad 
   6263  1.1  riastrad 	if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_BIF_LS))
   6264  1.1  riastrad 		data |= SLV_MEM_LS_EN | MST_MEM_LS_EN |
   6265  1.1  riastrad 			REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN;
   6266  1.1  riastrad 	else
   6267  1.1  riastrad 		data &= ~(SLV_MEM_LS_EN | MST_MEM_LS_EN |
   6268  1.1  riastrad 			  REPLAY_MEM_LS_EN | SLV_MEM_AGGRESSIVE_LS_EN);
   6269  1.1  riastrad 
   6270  1.1  riastrad 	if (orig != data)
   6271  1.1  riastrad 		WREG32_PCIE_PORT(PCIE_CNTL2, data);
   6272  1.1  riastrad }
   6273  1.1  riastrad 
   6274  1.1  riastrad static void cik_enable_hdp_mgcg(struct radeon_device *rdev,
   6275  1.1  riastrad 				bool enable)
   6276  1.1  riastrad {
   6277  1.1  riastrad 	u32 orig, data;
   6278  1.1  riastrad 
   6279  1.1  riastrad 	orig = data = RREG32(HDP_HOST_PATH_CNTL);
   6280  1.1  riastrad 
   6281  1.1  riastrad 	if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_MGCG))
   6282  1.1  riastrad 		data &= ~CLOCK_GATING_DIS;
   6283  1.1  riastrad 	else
   6284  1.1  riastrad 		data |= CLOCK_GATING_DIS;
   6285  1.1  riastrad 
   6286  1.1  riastrad 	if (orig != data)
   6287  1.1  riastrad 		WREG32(HDP_HOST_PATH_CNTL, data);
   6288  1.1  riastrad }
   6289  1.1  riastrad 
   6290  1.1  riastrad static void cik_enable_hdp_ls(struct radeon_device *rdev,
   6291  1.1  riastrad 			      bool enable)
   6292  1.1  riastrad {
   6293  1.1  riastrad 	u32 orig, data;
   6294  1.1  riastrad 
   6295  1.1  riastrad 	orig = data = RREG32(HDP_MEM_POWER_LS);
   6296  1.1  riastrad 
   6297  1.1  riastrad 	if (enable && (rdev->cg_flags & RADEON_CG_SUPPORT_HDP_LS))
   6298  1.1  riastrad 		data |= HDP_LS_ENABLE;
   6299  1.1  riastrad 	else
   6300  1.1  riastrad 		data &= ~HDP_LS_ENABLE;
   6301  1.1  riastrad 
   6302  1.1  riastrad 	if (orig != data)
   6303  1.1  riastrad 		WREG32(HDP_MEM_POWER_LS, data);
   6304  1.1  riastrad }
   6305  1.1  riastrad 
   6306  1.1  riastrad void cik_update_cg(struct radeon_device *rdev,
   6307  1.1  riastrad 		   u32 block, bool enable)
   6308  1.1  riastrad {
   6309  1.1  riastrad 
   6310  1.1  riastrad 	if (block & RADEON_CG_BLOCK_GFX) {
   6311  1.1  riastrad 		cik_enable_gui_idle_interrupt(rdev, false);
   6312  1.1  riastrad 		/* order matters! */
   6313  1.1  riastrad 		if (enable) {
   6314  1.1  riastrad 			cik_enable_mgcg(rdev, true);
   6315  1.1  riastrad 			cik_enable_cgcg(rdev, true);
   6316  1.1  riastrad 		} else {
   6317  1.1  riastrad 			cik_enable_cgcg(rdev, false);
   6318  1.1  riastrad 			cik_enable_mgcg(rdev, false);
   6319  1.1  riastrad 		}
   6320  1.1  riastrad 		cik_enable_gui_idle_interrupt(rdev, true);
   6321  1.1  riastrad 	}
   6322  1.1  riastrad 
   6323  1.1  riastrad 	if (block & RADEON_CG_BLOCK_MC) {
   6324  1.1  riastrad 		if (!(rdev->flags & RADEON_IS_IGP)) {
   6325  1.1  riastrad 			cik_enable_mc_mgcg(rdev, enable);
   6326  1.1  riastrad 			cik_enable_mc_ls(rdev, enable);
   6327  1.1  riastrad 		}
   6328  1.1  riastrad 	}
   6329  1.1  riastrad 
   6330  1.1  riastrad 	if (block & RADEON_CG_BLOCK_SDMA) {
   6331  1.1  riastrad 		cik_enable_sdma_mgcg(rdev, enable);
   6332  1.1  riastrad 		cik_enable_sdma_mgls(rdev, enable);
   6333  1.1  riastrad 	}
   6334  1.1  riastrad 
   6335  1.1  riastrad 	if (block & RADEON_CG_BLOCK_BIF) {
   6336  1.1  riastrad 		cik_enable_bif_mgls(rdev, enable);
   6337  1.1  riastrad 	}
   6338  1.1  riastrad 
   6339  1.1  riastrad 	if (block & RADEON_CG_BLOCK_UVD) {
   6340  1.1  riastrad 		if (rdev->has_uvd)
   6341  1.1  riastrad 			cik_enable_uvd_mgcg(rdev, enable);
   6342  1.1  riastrad 	}
   6343  1.1  riastrad 
   6344  1.1  riastrad 	if (block & RADEON_CG_BLOCK_HDP) {
   6345  1.1  riastrad 		cik_enable_hdp_mgcg(rdev, enable);
   6346  1.1  riastrad 		cik_enable_hdp_ls(rdev, enable);
   6347  1.1  riastrad 	}
   6348  1.1  riastrad 
   6349  1.1  riastrad 	if (block & RADEON_CG_BLOCK_VCE) {
   6350  1.1  riastrad 		vce_v2_0_enable_mgcg(rdev, enable);
   6351  1.1  riastrad 	}
   6352  1.1  riastrad }
   6353  1.1  riastrad 
   6354  1.1  riastrad static void cik_init_cg(struct radeon_device *rdev)
   6355  1.1  riastrad {
   6356  1.1  riastrad 
   6357  1.1  riastrad 	cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, true);
   6358  1.1  riastrad 
   6359  1.1  riastrad 	if (rdev->has_uvd)
   6360  1.1  riastrad 		si_init_uvd_internal_cg(rdev);
   6361  1.1  riastrad 
   6362  1.1  riastrad 	cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
   6363  1.1  riastrad 			     RADEON_CG_BLOCK_SDMA |
   6364  1.1  riastrad 			     RADEON_CG_BLOCK_BIF |
   6365  1.1  riastrad 			     RADEON_CG_BLOCK_UVD |
   6366  1.1  riastrad 			     RADEON_CG_BLOCK_HDP), true);
   6367  1.1  riastrad }
   6368  1.1  riastrad 
   6369  1.1  riastrad static void cik_fini_cg(struct radeon_device *rdev)
   6370  1.1  riastrad {
   6371  1.1  riastrad 	cik_update_cg(rdev, (RADEON_CG_BLOCK_MC |
   6372  1.1  riastrad 			     RADEON_CG_BLOCK_SDMA |
   6373  1.1  riastrad 			     RADEON_CG_BLOCK_BIF |
   6374  1.1  riastrad 			     RADEON_CG_BLOCK_UVD |
   6375  1.1  riastrad 			     RADEON_CG_BLOCK_HDP), false);
   6376  1.1  riastrad 
   6377  1.1  riastrad 	cik_update_cg(rdev, RADEON_CG_BLOCK_GFX, false);
   6378  1.1  riastrad }
   6379  1.1  riastrad 
   6380  1.1  riastrad static void cik_enable_sck_slowdown_on_pu(struct radeon_device *rdev,
   6381  1.1  riastrad 					  bool enable)
   6382  1.1  riastrad {
   6383  1.1  riastrad 	u32 data, orig;
   6384  1.1  riastrad 
   6385  1.1  riastrad 	orig = data = RREG32(RLC_PG_CNTL);
   6386  1.1  riastrad 	if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
   6387  1.1  riastrad 		data |= SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
   6388  1.1  riastrad 	else
   6389  1.1  riastrad 		data &= ~SMU_CLK_SLOWDOWN_ON_PU_ENABLE;
   6390  1.1  riastrad 	if (orig != data)
   6391  1.1  riastrad 		WREG32(RLC_PG_CNTL, data);
   6392  1.1  riastrad }
   6393  1.1  riastrad 
   6394  1.1  riastrad static void cik_enable_sck_slowdown_on_pd(struct radeon_device *rdev,
   6395  1.1  riastrad 					  bool enable)
   6396  1.1  riastrad {
   6397  1.1  riastrad 	u32 data, orig;
   6398  1.1  riastrad 
   6399  1.1  riastrad 	orig = data = RREG32(RLC_PG_CNTL);
   6400  1.1  riastrad 	if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_RLC_SMU_HS))
   6401  1.1  riastrad 		data |= SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
   6402  1.1  riastrad 	else
   6403  1.1  riastrad 		data &= ~SMU_CLK_SLOWDOWN_ON_PD_ENABLE;
   6404  1.1  riastrad 	if (orig != data)
   6405  1.1  riastrad 		WREG32(RLC_PG_CNTL, data);
   6406  1.1  riastrad }
   6407  1.1  riastrad 
   6408  1.1  riastrad static void cik_enable_cp_pg(struct radeon_device *rdev, bool enable)
   6409  1.1  riastrad {
   6410  1.1  riastrad 	u32 data, orig;
   6411  1.1  riastrad 
   6412  1.1  riastrad 	orig = data = RREG32(RLC_PG_CNTL);
   6413  1.1  riastrad 	if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_CP))
   6414  1.1  riastrad 		data &= ~DISABLE_CP_PG;
   6415  1.1  riastrad 	else
   6416  1.1  riastrad 		data |= DISABLE_CP_PG;
   6417  1.1  riastrad 	if (orig != data)
   6418  1.1  riastrad 		WREG32(RLC_PG_CNTL, data);
   6419  1.1  riastrad }
   6420  1.1  riastrad 
   6421  1.1  riastrad static void cik_enable_gds_pg(struct radeon_device *rdev, bool enable)
   6422  1.1  riastrad {
   6423  1.1  riastrad 	u32 data, orig;
   6424  1.1  riastrad 
   6425  1.1  riastrad 	orig = data = RREG32(RLC_PG_CNTL);
   6426  1.1  riastrad 	if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GDS))
   6427  1.1  riastrad 		data &= ~DISABLE_GDS_PG;
   6428  1.1  riastrad 	else
   6429  1.1  riastrad 		data |= DISABLE_GDS_PG;
   6430  1.1  riastrad 	if (orig != data)
   6431  1.1  riastrad 		WREG32(RLC_PG_CNTL, data);
   6432  1.1  riastrad }
   6433  1.1  riastrad 
   6434  1.1  riastrad #define CP_ME_TABLE_SIZE    96
   6435  1.1  riastrad #define CP_ME_TABLE_OFFSET  2048
   6436  1.1  riastrad #define CP_MEC_TABLE_OFFSET 4096
   6437  1.1  riastrad 
   6438  1.1  riastrad void cik_init_cp_pg_table(struct radeon_device *rdev)
   6439  1.1  riastrad {
   6440  1.1  riastrad 	volatile u32 *dst_ptr;
   6441  1.1  riastrad 	int me, i, max_me = 4;
   6442  1.1  riastrad 	u32 bo_offset = 0;
   6443  1.1  riastrad 	u32 table_offset, table_size;
   6444  1.1  riastrad 
   6445  1.1  riastrad 	if (rdev->family == CHIP_KAVERI)
   6446  1.1  riastrad 		max_me = 5;
   6447  1.1  riastrad 
   6448  1.1  riastrad 	if (rdev->rlc.cp_table_ptr == NULL)
   6449  1.1  riastrad 		return;
   6450  1.1  riastrad 
   6451  1.1  riastrad 	/* write the cp table buffer */
   6452  1.1  riastrad 	dst_ptr = rdev->rlc.cp_table_ptr;
   6453  1.1  riastrad 	for (me = 0; me < max_me; me++) {
   6454  1.1  riastrad 		if (rdev->new_fw) {
   6455  1.1  riastrad 			const __le32 *fw_data;
   6456  1.1  riastrad 			const struct gfx_firmware_header_v1_0 *hdr;
   6457  1.1  riastrad 
   6458  1.1  riastrad 			if (me == 0) {
   6459  1.1  riastrad 				hdr = (const struct gfx_firmware_header_v1_0 *)rdev->ce_fw->data;
   6460  1.1  riastrad 				fw_data = (const __le32 *)
   6461  1.1  riastrad 					(rdev->ce_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
   6462  1.1  riastrad 				table_offset = le32_to_cpu(hdr->jt_offset);
   6463  1.1  riastrad 				table_size = le32_to_cpu(hdr->jt_size);
   6464  1.1  riastrad 			} else if (me == 1) {
   6465  1.1  riastrad 				hdr = (const struct gfx_firmware_header_v1_0 *)rdev->pfp_fw->data;
   6466  1.1  riastrad 				fw_data = (const __le32 *)
   6467  1.1  riastrad 					(rdev->pfp_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
   6468  1.1  riastrad 				table_offset = le32_to_cpu(hdr->jt_offset);
   6469  1.1  riastrad 				table_size = le32_to_cpu(hdr->jt_size);
   6470  1.1  riastrad 			} else if (me == 2) {
   6471  1.1  riastrad 				hdr = (const struct gfx_firmware_header_v1_0 *)rdev->me_fw->data;
   6472  1.1  riastrad 				fw_data = (const __le32 *)
   6473  1.1  riastrad 					(rdev->me_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
   6474  1.1  riastrad 				table_offset = le32_to_cpu(hdr->jt_offset);
   6475  1.1  riastrad 				table_size = le32_to_cpu(hdr->jt_size);
   6476  1.1  riastrad 			} else if (me == 3) {
   6477  1.1  riastrad 				hdr = (const struct gfx_firmware_header_v1_0 *)rdev->mec_fw->data;
   6478  1.1  riastrad 				fw_data = (const __le32 *)
   6479  1.1  riastrad 					(rdev->mec_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
   6480  1.1  riastrad 				table_offset = le32_to_cpu(hdr->jt_offset);
   6481  1.1  riastrad 				table_size = le32_to_cpu(hdr->jt_size);
   6482  1.1  riastrad 			} else {
   6483  1.1  riastrad 				hdr = (const struct gfx_firmware_header_v1_0 *)rdev->mec2_fw->data;
   6484  1.1  riastrad 				fw_data = (const __le32 *)
   6485  1.1  riastrad 					(rdev->mec2_fw->data + le32_to_cpu(hdr->header.ucode_array_offset_bytes));
   6486  1.1  riastrad 				table_offset = le32_to_cpu(hdr->jt_offset);
   6487  1.1  riastrad 				table_size = le32_to_cpu(hdr->jt_size);
   6488  1.1  riastrad 			}
   6489  1.1  riastrad 
   6490  1.1  riastrad 			for (i = 0; i < table_size; i ++) {
   6491  1.1  riastrad 				dst_ptr[bo_offset + i] =
   6492  1.1  riastrad 					cpu_to_le32(le32_to_cpu(fw_data[table_offset + i]));
   6493  1.1  riastrad 			}
   6494  1.1  riastrad 			bo_offset += table_size;
   6495  1.1  riastrad 		} else {
   6496  1.1  riastrad 			const __be32 *fw_data;
   6497  1.1  riastrad 			table_size = CP_ME_TABLE_SIZE;
   6498  1.1  riastrad 
   6499  1.1  riastrad 			if (me == 0) {
   6500  1.1  riastrad 				fw_data = (const __be32 *)rdev->ce_fw->data;
   6501  1.1  riastrad 				table_offset = CP_ME_TABLE_OFFSET;
   6502  1.1  riastrad 			} else if (me == 1) {
   6503  1.1  riastrad 				fw_data = (const __be32 *)rdev->pfp_fw->data;
   6504  1.1  riastrad 				table_offset = CP_ME_TABLE_OFFSET;
   6505  1.1  riastrad 			} else if (me == 2) {
   6506  1.1  riastrad 				fw_data = (const __be32 *)rdev->me_fw->data;
   6507  1.1  riastrad 				table_offset = CP_ME_TABLE_OFFSET;
   6508  1.1  riastrad 			} else {
   6509  1.1  riastrad 				fw_data = (const __be32 *)rdev->mec_fw->data;
   6510  1.1  riastrad 				table_offset = CP_MEC_TABLE_OFFSET;
   6511  1.1  riastrad 			}
   6512  1.1  riastrad 
   6513  1.1  riastrad 			for (i = 0; i < table_size; i ++) {
   6514  1.1  riastrad 				dst_ptr[bo_offset + i] =
   6515  1.1  riastrad 					cpu_to_le32(be32_to_cpu(fw_data[table_offset + i]));
   6516  1.1  riastrad 			}
   6517  1.1  riastrad 			bo_offset += table_size;
   6518  1.1  riastrad 		}
   6519  1.1  riastrad 	}
   6520  1.1  riastrad }
   6521  1.1  riastrad 
   6522  1.1  riastrad static void cik_enable_gfx_cgpg(struct radeon_device *rdev,
   6523  1.1  riastrad 				bool enable)
   6524  1.1  riastrad {
   6525  1.1  riastrad 	u32 data, orig;
   6526  1.1  riastrad 
   6527  1.1  riastrad 	if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG)) {
   6528  1.1  riastrad 		orig = data = RREG32(RLC_PG_CNTL);
   6529  1.1  riastrad 		data |= GFX_PG_ENABLE;
   6530  1.1  riastrad 		if (orig != data)
   6531  1.1  riastrad 			WREG32(RLC_PG_CNTL, data);
   6532  1.1  riastrad 
   6533  1.1  riastrad 		orig = data = RREG32(RLC_AUTO_PG_CTRL);
   6534  1.1  riastrad 		data |= AUTO_PG_EN;
   6535  1.1  riastrad 		if (orig != data)
   6536  1.1  riastrad 			WREG32(RLC_AUTO_PG_CTRL, data);
   6537  1.1  riastrad 	} else {
   6538  1.1  riastrad 		orig = data = RREG32(RLC_PG_CNTL);
   6539  1.1  riastrad 		data &= ~GFX_PG_ENABLE;
   6540  1.1  riastrad 		if (orig != data)
   6541  1.1  riastrad 			WREG32(RLC_PG_CNTL, data);
   6542  1.1  riastrad 
   6543  1.1  riastrad 		orig = data = RREG32(RLC_AUTO_PG_CTRL);
   6544  1.1  riastrad 		data &= ~AUTO_PG_EN;
   6545  1.1  riastrad 		if (orig != data)
   6546  1.1  riastrad 			WREG32(RLC_AUTO_PG_CTRL, data);
   6547  1.1  riastrad 
   6548  1.1  riastrad 		data = RREG32(DB_RENDER_CONTROL);
   6549  1.1  riastrad 	}
   6550  1.1  riastrad }
   6551  1.1  riastrad 
   6552  1.1  riastrad static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
   6553  1.1  riastrad {
   6554  1.1  riastrad 	u32 mask = 0, tmp, tmp1;
   6555  1.1  riastrad 	int i;
   6556  1.1  riastrad 
   6557  1.1  riastrad 	cik_select_se_sh(rdev, se, sh);
   6558  1.1  riastrad 	tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
   6559  1.1  riastrad 	tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
   6560  1.1  riastrad 	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
   6561  1.1  riastrad 
   6562  1.1  riastrad 	tmp &= 0xffff0000;
   6563  1.1  riastrad 
   6564  1.1  riastrad 	tmp |= tmp1;
   6565  1.1  riastrad 	tmp >>= 16;
   6566  1.1  riastrad 
   6567  1.1  riastrad 	for (i = 0; i < rdev->config.cik.max_cu_per_sh; i ++) {
   6568  1.1  riastrad 		mask <<= 1;
   6569  1.1  riastrad 		mask |= 1;
   6570  1.1  riastrad 	}
   6571  1.1  riastrad 
   6572  1.1  riastrad 	return (~tmp) & mask;
   6573  1.1  riastrad }
   6574  1.1  riastrad 
   6575  1.1  riastrad static void cik_init_ao_cu_mask(struct radeon_device *rdev)
   6576  1.1  riastrad {
   6577  1.1  riastrad 	u32 i, j, k, active_cu_number = 0;
   6578  1.1  riastrad 	u32 mask, counter, cu_bitmap;
   6579  1.1  riastrad 	u32 tmp = 0;
   6580  1.1  riastrad 
   6581  1.1  riastrad 	for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
   6582  1.1  riastrad 		for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
   6583  1.1  riastrad 			mask = 1;
   6584  1.1  riastrad 			cu_bitmap = 0;
   6585  1.1  riastrad 			counter = 0;
   6586  1.1  riastrad 			for (k = 0; k < rdev->config.cik.max_cu_per_sh; k ++) {
   6587  1.1  riastrad 				if (cik_get_cu_active_bitmap(rdev, i, j) & mask) {
   6588  1.1  riastrad 					if (counter < 2)
   6589  1.1  riastrad 						cu_bitmap |= mask;
   6590  1.1  riastrad 					counter ++;
   6591  1.1  riastrad 				}
   6592  1.1  riastrad 				mask <<= 1;
   6593  1.1  riastrad 			}
   6594  1.1  riastrad 
   6595  1.1  riastrad 			active_cu_number += counter;
   6596  1.1  riastrad 			tmp |= (cu_bitmap << (i * 16 + j * 8));
   6597  1.1  riastrad 		}
   6598  1.1  riastrad 	}
   6599  1.1  riastrad 
   6600  1.1  riastrad 	WREG32(RLC_PG_AO_CU_MASK, tmp);
   6601  1.1  riastrad 
   6602  1.1  riastrad 	tmp = RREG32(RLC_MAX_PG_CU);
   6603  1.1  riastrad 	tmp &= ~MAX_PU_CU_MASK;
   6604  1.1  riastrad 	tmp |= MAX_PU_CU(active_cu_number);
   6605  1.1  riastrad 	WREG32(RLC_MAX_PG_CU, tmp);
   6606  1.1  riastrad }
   6607  1.1  riastrad 
   6608  1.1  riastrad static void cik_enable_gfx_static_mgpg(struct radeon_device *rdev,
   6609  1.1  riastrad 				       bool enable)
   6610  1.1  riastrad {
   6611  1.1  riastrad 	u32 data, orig;
   6612  1.1  riastrad 
   6613  1.1  riastrad 	orig = data = RREG32(RLC_PG_CNTL);
   6614  1.1  riastrad 	if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_SMG))
   6615  1.1  riastrad 		data |= STATIC_PER_CU_PG_ENABLE;
   6616  1.1  riastrad 	else
   6617  1.1  riastrad 		data &= ~STATIC_PER_CU_PG_ENABLE;
   6618  1.1  riastrad 	if (orig != data)
   6619  1.1  riastrad 		WREG32(RLC_PG_CNTL, data);
   6620  1.1  riastrad }
   6621  1.1  riastrad 
   6622  1.1  riastrad static void cik_enable_gfx_dynamic_mgpg(struct radeon_device *rdev,
   6623  1.1  riastrad 					bool enable)
   6624  1.1  riastrad {
   6625  1.1  riastrad 	u32 data, orig;
   6626  1.1  riastrad 
   6627  1.1  riastrad 	orig = data = RREG32(RLC_PG_CNTL);
   6628  1.1  riastrad 	if (enable && (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_DMG))
   6629  1.1  riastrad 		data |= DYN_PER_CU_PG_ENABLE;
   6630  1.1  riastrad 	else
   6631  1.1  riastrad 		data &= ~DYN_PER_CU_PG_ENABLE;
   6632  1.1  riastrad 	if (orig != data)
   6633  1.1  riastrad 		WREG32(RLC_PG_CNTL, data);
   6634  1.1  riastrad }
   6635  1.1  riastrad 
   6636  1.1  riastrad #define RLC_SAVE_AND_RESTORE_STARTING_OFFSET 0x90
   6637  1.1  riastrad #define RLC_CLEAR_STATE_DESCRIPTOR_OFFSET    0x3D
   6638  1.1  riastrad 
   6639  1.1  riastrad static void cik_init_gfx_cgpg(struct radeon_device *rdev)
   6640  1.1  riastrad {
   6641  1.1  riastrad 	u32 data, orig;
   6642  1.1  riastrad 	u32 i;
   6643  1.1  riastrad 
   6644  1.1  riastrad 	if (rdev->rlc.cs_data) {
   6645  1.1  riastrad 		WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
   6646  1.1  riastrad 		WREG32(RLC_GPM_SCRATCH_DATA, upper_32_bits(rdev->rlc.clear_state_gpu_addr));
   6647  1.1  riastrad 		WREG32(RLC_GPM_SCRATCH_DATA, lower_32_bits(rdev->rlc.clear_state_gpu_addr));
   6648  1.1  riastrad 		WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.clear_state_size);
   6649  1.1  riastrad 	} else {
   6650  1.1  riastrad 		WREG32(RLC_GPM_SCRATCH_ADDR, RLC_CLEAR_STATE_DESCRIPTOR_OFFSET);
   6651  1.1  riastrad 		for (i = 0; i < 3; i++)
   6652  1.1  riastrad 			WREG32(RLC_GPM_SCRATCH_DATA, 0);
   6653  1.1  riastrad 	}
   6654  1.1  riastrad 	if (rdev->rlc.reg_list) {
   6655  1.1  riastrad 		WREG32(RLC_GPM_SCRATCH_ADDR, RLC_SAVE_AND_RESTORE_STARTING_OFFSET);
   6656  1.1  riastrad 		for (i = 0; i < rdev->rlc.reg_list_size; i++)
   6657  1.1  riastrad 			WREG32(RLC_GPM_SCRATCH_DATA, rdev->rlc.reg_list[i]);
   6658  1.1  riastrad 	}
   6659  1.1  riastrad 
   6660  1.1  riastrad 	orig = data = RREG32(RLC_PG_CNTL);
   6661  1.1  riastrad 	data |= GFX_PG_SRC;
   6662  1.1  riastrad 	if (orig != data)
   6663  1.1  riastrad 		WREG32(RLC_PG_CNTL, data);
   6664  1.1  riastrad 
   6665  1.1  riastrad 	WREG32(RLC_SAVE_AND_RESTORE_BASE, rdev->rlc.save_restore_gpu_addr >> 8);
   6666  1.1  riastrad 	WREG32(RLC_CP_TABLE_RESTORE, rdev->rlc.cp_table_gpu_addr >> 8);
   6667  1.1  riastrad 
   6668  1.1  riastrad 	data = RREG32(CP_RB_WPTR_POLL_CNTL);
   6669  1.1  riastrad 	data &= ~IDLE_POLL_COUNT_MASK;
   6670  1.1  riastrad 	data |= IDLE_POLL_COUNT(0x60);
   6671  1.1  riastrad 	WREG32(CP_RB_WPTR_POLL_CNTL, data);
   6672  1.1  riastrad 
   6673  1.1  riastrad 	data = 0x10101010;
   6674  1.1  riastrad 	WREG32(RLC_PG_DELAY, data);
   6675  1.1  riastrad 
   6676  1.1  riastrad 	data = RREG32(RLC_PG_DELAY_2);
   6677  1.1  riastrad 	data &= ~0xff;
   6678  1.1  riastrad 	data |= 0x3;
   6679  1.1  riastrad 	WREG32(RLC_PG_DELAY_2, data);
   6680  1.1  riastrad 
   6681  1.1  riastrad 	data = RREG32(RLC_AUTO_PG_CTRL);
   6682  1.1  riastrad 	data &= ~GRBM_REG_SGIT_MASK;
   6683  1.1  riastrad 	data |= GRBM_REG_SGIT(0x700);
   6684  1.1  riastrad 	WREG32(RLC_AUTO_PG_CTRL, data);
   6685  1.1  riastrad 
   6686  1.1  riastrad }
   6687  1.1  riastrad 
   6688  1.1  riastrad static void cik_update_gfx_pg(struct radeon_device *rdev, bool enable)
   6689  1.1  riastrad {
   6690  1.1  riastrad 	cik_enable_gfx_cgpg(rdev, enable);
   6691  1.1  riastrad 	cik_enable_gfx_static_mgpg(rdev, enable);
   6692  1.1  riastrad 	cik_enable_gfx_dynamic_mgpg(rdev, enable);
   6693  1.1  riastrad }
   6694  1.1  riastrad 
   6695  1.1  riastrad u32 cik_get_csb_size(struct radeon_device *rdev)
   6696  1.1  riastrad {
   6697  1.1  riastrad 	u32 count = 0;
   6698  1.1  riastrad 	const struct cs_section_def *sect = NULL;
   6699  1.1  riastrad 	const struct cs_extent_def *ext = NULL;
   6700  1.1  riastrad 
   6701  1.1  riastrad 	if (rdev->rlc.cs_data == NULL)
   6702  1.1  riastrad 		return 0;
   6703  1.1  riastrad 
   6704  1.1  riastrad 	/* begin clear state */
   6705  1.1  riastrad 	count += 2;
   6706  1.1  riastrad 	/* context control state */
   6707  1.1  riastrad 	count += 3;
   6708  1.1  riastrad 
   6709  1.1  riastrad 	for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
   6710  1.1  riastrad 		for (ext = sect->section; ext->extent != NULL; ++ext) {
   6711  1.1  riastrad 			if (sect->id == SECT_CONTEXT)
   6712  1.1  riastrad 				count += 2 + ext->reg_count;
   6713  1.1  riastrad 			else
   6714  1.1  riastrad 				return 0;
   6715  1.1  riastrad 		}
   6716  1.1  riastrad 	}
   6717  1.1  riastrad 	/* pa_sc_raster_config/pa_sc_raster_config1 */
   6718  1.1  riastrad 	count += 4;
   6719  1.1  riastrad 	/* end clear state */
   6720  1.1  riastrad 	count += 2;
   6721  1.1  riastrad 	/* clear state */
   6722  1.1  riastrad 	count += 2;
   6723  1.1  riastrad 
   6724  1.1  riastrad 	return count;
   6725  1.1  riastrad }
   6726  1.1  riastrad 
   6727  1.1  riastrad void cik_get_csb_buffer(struct radeon_device *rdev, volatile u32 *buffer)
   6728  1.1  riastrad {
   6729  1.1  riastrad 	u32 count = 0, i;
   6730  1.1  riastrad 	const struct cs_section_def *sect = NULL;
   6731  1.1  riastrad 	const struct cs_extent_def *ext = NULL;
   6732  1.1  riastrad 
   6733  1.1  riastrad 	if (rdev->rlc.cs_data == NULL)
   6734  1.1  riastrad 		return;
   6735  1.1  riastrad 	if (buffer == NULL)
   6736  1.1  riastrad 		return;
   6737  1.1  riastrad 
   6738  1.1  riastrad 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
   6739  1.1  riastrad 	buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
   6740  1.1  riastrad 
   6741  1.1  riastrad 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CONTEXT_CONTROL, 1));
   6742  1.1  riastrad 	buffer[count++] = cpu_to_le32(0x80000000);
   6743  1.1  riastrad 	buffer[count++] = cpu_to_le32(0x80000000);
   6744  1.1  riastrad 
   6745  1.1  riastrad 	for (sect = rdev->rlc.cs_data; sect->section != NULL; ++sect) {
   6746  1.1  riastrad 		for (ext = sect->section; ext->extent != NULL; ++ext) {
   6747  1.1  riastrad 			if (sect->id == SECT_CONTEXT) {
   6748  1.1  riastrad 				buffer[count++] =
   6749  1.1  riastrad 					cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
   6750  1.1  riastrad 				buffer[count++] = cpu_to_le32(ext->reg_index - 0xa000);
   6751  1.1  riastrad 				for (i = 0; i < ext->reg_count; i++)
   6752  1.1  riastrad 					buffer[count++] = cpu_to_le32(ext->extent[i]);
   6753  1.1  riastrad 			} else {
   6754  1.1  riastrad 				return;
   6755  1.1  riastrad 			}
   6756  1.1  riastrad 		}
   6757  1.1  riastrad 	}
   6758  1.1  riastrad 
   6759  1.1  riastrad 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_SET_CONTEXT_REG, 2));
   6760  1.1  riastrad 	buffer[count++] = cpu_to_le32(PA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
   6761  1.1  riastrad 	switch (rdev->family) {
   6762  1.1  riastrad 	case CHIP_BONAIRE:
   6763  1.1  riastrad 		buffer[count++] = cpu_to_le32(0x16000012);
   6764  1.1  riastrad 		buffer[count++] = cpu_to_le32(0x00000000);
   6765  1.1  riastrad 		break;
   6766  1.1  riastrad 	case CHIP_KAVERI:
   6767  1.1  riastrad 		buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
   6768  1.1  riastrad 		buffer[count++] = cpu_to_le32(0x00000000);
   6769  1.1  riastrad 		break;
   6770  1.1  riastrad 	case CHIP_KABINI:
   6771  1.1  riastrad 	case CHIP_MULLINS:
   6772  1.1  riastrad 		buffer[count++] = cpu_to_le32(0x00000000); /* XXX */
   6773  1.1  riastrad 		buffer[count++] = cpu_to_le32(0x00000000);
   6774  1.1  riastrad 		break;
   6775  1.1  riastrad 	case CHIP_HAWAII:
   6776  1.1  riastrad 		buffer[count++] = cpu_to_le32(0x3a00161a);
   6777  1.1  riastrad 		buffer[count++] = cpu_to_le32(0x0000002e);
   6778  1.1  riastrad 		break;
   6779  1.1  riastrad 	default:
   6780  1.1  riastrad 		buffer[count++] = cpu_to_le32(0x00000000);
   6781  1.1  riastrad 		buffer[count++] = cpu_to_le32(0x00000000);
   6782  1.1  riastrad 		break;
   6783  1.1  riastrad 	}
   6784  1.1  riastrad 
   6785  1.1  riastrad 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_PREAMBLE_CNTL, 0));
   6786  1.1  riastrad 	buffer[count++] = cpu_to_le32(PACKET3_PREAMBLE_END_CLEAR_STATE);
   6787  1.1  riastrad 
   6788  1.1  riastrad 	buffer[count++] = cpu_to_le32(PACKET3(PACKET3_CLEAR_STATE, 0));
   6789  1.1  riastrad 	buffer[count++] = cpu_to_le32(0);
   6790  1.1  riastrad }
   6791  1.1  riastrad 
   6792  1.1  riastrad static void cik_init_pg(struct radeon_device *rdev)
   6793  1.1  riastrad {
   6794  1.1  riastrad 	if (rdev->pg_flags) {
   6795  1.1  riastrad 		cik_enable_sck_slowdown_on_pu(rdev, true);
   6796  1.1  riastrad 		cik_enable_sck_slowdown_on_pd(rdev, true);
   6797  1.1  riastrad 		if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
   6798  1.1  riastrad 			cik_init_gfx_cgpg(rdev);
   6799  1.1  riastrad 			cik_enable_cp_pg(rdev, true);
   6800  1.1  riastrad 			cik_enable_gds_pg(rdev, true);
   6801  1.1  riastrad 		}
   6802  1.1  riastrad 		cik_init_ao_cu_mask(rdev);
   6803  1.1  riastrad 		cik_update_gfx_pg(rdev, true);
   6804  1.1  riastrad 	}
   6805  1.1  riastrad }
   6806  1.1  riastrad 
   6807  1.1  riastrad static void cik_fini_pg(struct radeon_device *rdev)
   6808  1.1  riastrad {
   6809  1.1  riastrad 	if (rdev->pg_flags) {
   6810  1.1  riastrad 		cik_update_gfx_pg(rdev, false);
   6811  1.1  riastrad 		if (rdev->pg_flags & RADEON_PG_SUPPORT_GFX_PG) {
   6812  1.1  riastrad 			cik_enable_cp_pg(rdev, false);
   6813  1.1  riastrad 			cik_enable_gds_pg(rdev, false);
   6814  1.1  riastrad 		}
   6815  1.1  riastrad 	}
   6816  1.1  riastrad }
   6817  1.1  riastrad 
   6818  1.1  riastrad /*
   6819  1.1  riastrad  * Interrupts
   6820  1.1  riastrad  * Starting with r6xx, interrupts are handled via a ring buffer.
   6821  1.1  riastrad  * Ring buffers are areas of GPU accessible memory that the GPU
   6822  1.1  riastrad  * writes interrupt vectors into and the host reads vectors out of.
   6823  1.1  riastrad  * There is a rptr (read pointer) that determines where the
   6824  1.1  riastrad  * host is currently reading, and a wptr (write pointer)
   6825  1.1  riastrad  * which determines where the GPU has written.  When the
   6826  1.1  riastrad  * pointers are equal, the ring is idle.  When the GPU
   6827  1.1  riastrad  * writes vectors to the ring buffer, it increments the
   6828  1.1  riastrad  * wptr.  When there is an interrupt, the host then starts
   6829  1.1  riastrad  * fetching commands and processing them until the pointers are
   6830  1.1  riastrad  * equal again at which point it updates the rptr.
   6831  1.1  riastrad  */
   6832  1.1  riastrad 
   6833  1.1  riastrad /**
   6834  1.1  riastrad  * cik_enable_interrupts - Enable the interrupt ring buffer
   6835  1.1  riastrad  *
   6836  1.1  riastrad  * @rdev: radeon_device pointer
   6837  1.1  riastrad  *
   6838  1.1  riastrad  * Enable the interrupt ring buffer (CIK).
   6839  1.1  riastrad  */
   6840  1.1  riastrad static void cik_enable_interrupts(struct radeon_device *rdev)
   6841  1.1  riastrad {
   6842  1.1  riastrad 	u32 ih_cntl = RREG32(IH_CNTL);
   6843  1.1  riastrad 	u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
   6844  1.1  riastrad 
   6845  1.1  riastrad 	ih_cntl |= ENABLE_INTR;
   6846  1.1  riastrad 	ih_rb_cntl |= IH_RB_ENABLE;
   6847  1.1  riastrad 	WREG32(IH_CNTL, ih_cntl);
   6848  1.1  riastrad 	WREG32(IH_RB_CNTL, ih_rb_cntl);
   6849  1.1  riastrad 	rdev->ih.enabled = true;
   6850  1.1  riastrad }
   6851  1.1  riastrad 
   6852  1.1  riastrad /**
   6853  1.1  riastrad  * cik_disable_interrupts - Disable the interrupt ring buffer
   6854  1.1  riastrad  *
   6855  1.1  riastrad  * @rdev: radeon_device pointer
   6856  1.1  riastrad  *
   6857  1.1  riastrad  * Disable the interrupt ring buffer (CIK).
   6858  1.1  riastrad  */
   6859  1.1  riastrad static void cik_disable_interrupts(struct radeon_device *rdev)
   6860  1.1  riastrad {
   6861  1.1  riastrad 	u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
   6862  1.1  riastrad 	u32 ih_cntl = RREG32(IH_CNTL);
   6863  1.1  riastrad 
   6864  1.1  riastrad 	ih_rb_cntl &= ~IH_RB_ENABLE;
   6865  1.1  riastrad 	ih_cntl &= ~ENABLE_INTR;
   6866  1.1  riastrad 	WREG32(IH_RB_CNTL, ih_rb_cntl);
   6867  1.1  riastrad 	WREG32(IH_CNTL, ih_cntl);
   6868  1.1  riastrad 	/* set rptr, wptr to 0 */
   6869  1.1  riastrad 	WREG32(IH_RB_RPTR, 0);
   6870  1.1  riastrad 	WREG32(IH_RB_WPTR, 0);
   6871  1.1  riastrad 	rdev->ih.enabled = false;
   6872  1.1  riastrad 	rdev->ih.rptr = 0;
   6873  1.1  riastrad }
   6874  1.1  riastrad 
   6875  1.1  riastrad /**
   6876  1.1  riastrad  * cik_disable_interrupt_state - Disable all interrupt sources
   6877  1.1  riastrad  *
   6878  1.1  riastrad  * @rdev: radeon_device pointer
   6879  1.1  riastrad  *
   6880  1.1  riastrad  * Clear all interrupt enable bits used by the driver (CIK).
   6881  1.1  riastrad  */
   6882  1.1  riastrad static void cik_disable_interrupt_state(struct radeon_device *rdev)
   6883  1.1  riastrad {
   6884  1.1  riastrad 	u32 tmp;
   6885  1.1  riastrad 
   6886  1.1  riastrad 	/* gfx ring */
   6887  1.1  riastrad 	tmp = RREG32(CP_INT_CNTL_RING0) &
   6888  1.1  riastrad 		(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
   6889  1.1  riastrad 	WREG32(CP_INT_CNTL_RING0, tmp);
   6890  1.1  riastrad 	/* sdma */
   6891  1.1  riastrad 	tmp = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
   6892  1.1  riastrad 	WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, tmp);
   6893  1.1  riastrad 	tmp = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
   6894  1.1  riastrad 	WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, tmp);
   6895  1.1  riastrad 	/* compute queues */
   6896  1.1  riastrad 	WREG32(CP_ME1_PIPE0_INT_CNTL, 0);
   6897  1.1  riastrad 	WREG32(CP_ME1_PIPE1_INT_CNTL, 0);
   6898  1.1  riastrad 	WREG32(CP_ME1_PIPE2_INT_CNTL, 0);
   6899  1.1  riastrad 	WREG32(CP_ME1_PIPE3_INT_CNTL, 0);
   6900  1.1  riastrad 	WREG32(CP_ME2_PIPE0_INT_CNTL, 0);
   6901  1.1  riastrad 	WREG32(CP_ME2_PIPE1_INT_CNTL, 0);
   6902  1.1  riastrad 	WREG32(CP_ME2_PIPE2_INT_CNTL, 0);
   6903  1.1  riastrad 	WREG32(CP_ME2_PIPE3_INT_CNTL, 0);
   6904  1.1  riastrad 	/* grbm */
   6905  1.1  riastrad 	WREG32(GRBM_INT_CNTL, 0);
   6906  1.1  riastrad 	/* SRBM */
   6907  1.1  riastrad 	WREG32(SRBM_INT_CNTL, 0);
   6908  1.1  riastrad 	/* vline/vblank, etc. */
   6909  1.1  riastrad 	WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
   6910  1.1  riastrad 	WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
   6911  1.1  riastrad 	if (rdev->num_crtc >= 4) {
   6912  1.1  riastrad 		WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
   6913  1.1  riastrad 		WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
   6914  1.1  riastrad 	}
   6915  1.1  riastrad 	if (rdev->num_crtc >= 6) {
   6916  1.1  riastrad 		WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
   6917  1.1  riastrad 		WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
   6918  1.1  riastrad 	}
   6919  1.1  riastrad 	/* pflip */
   6920  1.1  riastrad 	if (rdev->num_crtc >= 2) {
   6921  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
   6922  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
   6923  1.1  riastrad 	}
   6924  1.1  riastrad 	if (rdev->num_crtc >= 4) {
   6925  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0);
   6926  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0);
   6927  1.1  riastrad 	}
   6928  1.1  riastrad 	if (rdev->num_crtc >= 6) {
   6929  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0);
   6930  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0);
   6931  1.1  riastrad 	}
   6932  1.1  riastrad 
   6933  1.1  riastrad 	/* dac hotplug */
   6934  1.1  riastrad 	WREG32(DAC_AUTODETECT_INT_CONTROL, 0);
   6935  1.1  riastrad 
   6936  1.1  riastrad 	/* digital hotplug */
   6937  1.1  riastrad 	tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
   6938  1.1  riastrad 	WREG32(DC_HPD1_INT_CONTROL, tmp);
   6939  1.1  riastrad 	tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
   6940  1.1  riastrad 	WREG32(DC_HPD2_INT_CONTROL, tmp);
   6941  1.1  riastrad 	tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
   6942  1.1  riastrad 	WREG32(DC_HPD3_INT_CONTROL, tmp);
   6943  1.1  riastrad 	tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
   6944  1.1  riastrad 	WREG32(DC_HPD4_INT_CONTROL, tmp);
   6945  1.1  riastrad 	tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
   6946  1.1  riastrad 	WREG32(DC_HPD5_INT_CONTROL, tmp);
   6947  1.1  riastrad 	tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
   6948  1.1  riastrad 	WREG32(DC_HPD6_INT_CONTROL, tmp);
   6949  1.1  riastrad 
   6950  1.1  riastrad }
   6951  1.1  riastrad 
   6952  1.1  riastrad /**
   6953  1.1  riastrad  * cik_irq_init - init and enable the interrupt ring
   6954  1.1  riastrad  *
   6955  1.1  riastrad  * @rdev: radeon_device pointer
   6956  1.1  riastrad  *
   6957  1.1  riastrad  * Allocate a ring buffer for the interrupt controller,
   6958  1.1  riastrad  * enable the RLC, disable interrupts, enable the IH
   6959  1.1  riastrad  * ring buffer and enable it (CIK).
   6960  1.1  riastrad  * Called at device load and reume.
   6961  1.1  riastrad  * Returns 0 for success, errors for failure.
   6962  1.1  riastrad  */
   6963  1.1  riastrad static int cik_irq_init(struct radeon_device *rdev)
   6964  1.1  riastrad {
   6965  1.1  riastrad 	int ret = 0;
   6966  1.1  riastrad 	int rb_bufsz;
   6967  1.1  riastrad 	u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
   6968  1.1  riastrad 
   6969  1.1  riastrad 	/* allocate ring */
   6970  1.1  riastrad 	ret = r600_ih_ring_alloc(rdev);
   6971  1.1  riastrad 	if (ret)
   6972  1.1  riastrad 		return ret;
   6973  1.1  riastrad 
   6974  1.1  riastrad 	/* disable irqs */
   6975  1.1  riastrad 	cik_disable_interrupts(rdev);
   6976  1.1  riastrad 
   6977  1.1  riastrad 	/* init rlc */
   6978  1.1  riastrad 	ret = cik_rlc_resume(rdev);
   6979  1.1  riastrad 	if (ret) {
   6980  1.1  riastrad 		r600_ih_ring_fini(rdev);
   6981  1.1  riastrad 		return ret;
   6982  1.1  riastrad 	}
   6983  1.1  riastrad 
   6984  1.1  riastrad 	/* setup interrupt control */
   6985  1.3  riastrad 	/* set dummy read address to dummy page address */
   6986  1.3  riastrad 	WREG32(INTERRUPT_CNTL2, rdev->dummy_page.addr >> 8);
   6987  1.1  riastrad 	interrupt_cntl = RREG32(INTERRUPT_CNTL);
   6988  1.1  riastrad 	/* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
   6989  1.1  riastrad 	 * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
   6990  1.1  riastrad 	 */
   6991  1.1  riastrad 	interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
   6992  1.1  riastrad 	/* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
   6993  1.1  riastrad 	interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
   6994  1.1  riastrad 	WREG32(INTERRUPT_CNTL, interrupt_cntl);
   6995  1.1  riastrad 
   6996  1.1  riastrad 	WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
   6997  1.1  riastrad 	rb_bufsz = order_base_2(rdev->ih.ring_size / 4);
   6998  1.1  riastrad 
   6999  1.1  riastrad 	ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
   7000  1.1  riastrad 		      IH_WPTR_OVERFLOW_CLEAR |
   7001  1.1  riastrad 		      (rb_bufsz << 1));
   7002  1.1  riastrad 
   7003  1.1  riastrad 	if (rdev->wb.enabled)
   7004  1.1  riastrad 		ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;
   7005  1.1  riastrad 
   7006  1.1  riastrad 	/* set the writeback address whether it's enabled or not */
   7007  1.1  riastrad 	WREG32(IH_RB_WPTR_ADDR_LO, (rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFFFFFFFC);
   7008  1.1  riastrad 	WREG32(IH_RB_WPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + R600_WB_IH_WPTR_OFFSET) & 0xFF);
   7009  1.1  riastrad 
   7010  1.1  riastrad 	WREG32(IH_RB_CNTL, ih_rb_cntl);
   7011  1.1  riastrad 
   7012  1.1  riastrad 	/* set rptr, wptr to 0 */
   7013  1.1  riastrad 	WREG32(IH_RB_RPTR, 0);
   7014  1.1  riastrad 	WREG32(IH_RB_WPTR, 0);
   7015  1.1  riastrad 
   7016  1.1  riastrad 	/* Default settings for IH_CNTL (disabled at first) */
   7017  1.1  riastrad 	ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10) | MC_VMID(0);
   7018  1.1  riastrad 	/* RPTR_REARM only works if msi's are enabled */
   7019  1.1  riastrad 	if (rdev->msi_enabled)
   7020  1.1  riastrad 		ih_cntl |= RPTR_REARM;
   7021  1.1  riastrad 	WREG32(IH_CNTL, ih_cntl);
   7022  1.1  riastrad 
   7023  1.1  riastrad 	/* force the active interrupt state to all disabled */
   7024  1.1  riastrad 	cik_disable_interrupt_state(rdev);
   7025  1.1  riastrad 
   7026  1.1  riastrad 	pci_set_master(rdev->pdev);
   7027  1.1  riastrad 
   7028  1.1  riastrad 	/* enable irqs */
   7029  1.1  riastrad 	cik_enable_interrupts(rdev);
   7030  1.1  riastrad 
   7031  1.1  riastrad 	return ret;
   7032  1.1  riastrad }
   7033  1.1  riastrad 
   7034  1.1  riastrad /**
   7035  1.1  riastrad  * cik_irq_set - enable/disable interrupt sources
   7036  1.1  riastrad  *
   7037  1.1  riastrad  * @rdev: radeon_device pointer
   7038  1.1  riastrad  *
   7039  1.1  riastrad  * Enable interrupt sources on the GPU (vblanks, hpd,
   7040  1.1  riastrad  * etc.) (CIK).
   7041  1.1  riastrad  * Returns 0 for success, errors for failure.
   7042  1.1  riastrad  */
   7043  1.1  riastrad int cik_irq_set(struct radeon_device *rdev)
   7044  1.1  riastrad {
   7045  1.1  riastrad 	u32 cp_int_cntl;
   7046  1.3  riastrad 	u32 cp_m1p0, cp_m1p1, cp_m1p2, cp_m1p3;
   7047  1.3  riastrad 	u32 cp_m2p0, cp_m2p1, cp_m2p2, cp_m2p3;
   7048  1.1  riastrad 	u32 crtc1 = 0, crtc2 = 0, crtc3 = 0, crtc4 = 0, crtc5 = 0, crtc6 = 0;
   7049  1.1  riastrad 	u32 hpd1, hpd2, hpd3, hpd4, hpd5, hpd6;
   7050  1.1  riastrad 	u32 grbm_int_cntl = 0;
   7051  1.1  riastrad 	u32 dma_cntl, dma_cntl1;
   7052  1.1  riastrad 
   7053  1.1  riastrad 	if (!rdev->irq.installed) {
   7054  1.1  riastrad 		WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
   7055  1.1  riastrad 		return -EINVAL;
   7056  1.1  riastrad 	}
   7057  1.1  riastrad 	/* don't enable anything if the ih is disabled */
   7058  1.1  riastrad 	if (!rdev->ih.enabled) {
   7059  1.1  riastrad 		cik_disable_interrupts(rdev);
   7060  1.1  riastrad 		/* force the active interrupt state to all disabled */
   7061  1.1  riastrad 		cik_disable_interrupt_state(rdev);
   7062  1.1  riastrad 		return 0;
   7063  1.1  riastrad 	}
   7064  1.1  riastrad 
   7065  1.1  riastrad 	cp_int_cntl = RREG32(CP_INT_CNTL_RING0) &
   7066  1.1  riastrad 		(CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
   7067  1.1  riastrad 	cp_int_cntl |= PRIV_INSTR_INT_ENABLE | PRIV_REG_INT_ENABLE;
   7068  1.1  riastrad 
   7069  1.1  riastrad 	hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
   7070  1.1  riastrad 	hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
   7071  1.1  riastrad 	hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
   7072  1.1  riastrad 	hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
   7073  1.1  riastrad 	hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
   7074  1.1  riastrad 	hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~(DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN);
   7075  1.1  riastrad 
   7076  1.1  riastrad 	dma_cntl = RREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET) & ~TRAP_ENABLE;
   7077  1.1  riastrad 	dma_cntl1 = RREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET) & ~TRAP_ENABLE;
   7078  1.1  riastrad 
   7079  1.1  riastrad 	cp_m1p0 = RREG32(CP_ME1_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
   7080  1.3  riastrad 	cp_m1p1 = RREG32(CP_ME1_PIPE1_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
   7081  1.3  riastrad 	cp_m1p2 = RREG32(CP_ME1_PIPE2_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
   7082  1.3  riastrad 	cp_m1p3 = RREG32(CP_ME1_PIPE3_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
   7083  1.3  riastrad 	cp_m2p0 = RREG32(CP_ME2_PIPE0_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
   7084  1.3  riastrad 	cp_m2p1 = RREG32(CP_ME2_PIPE1_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
   7085  1.3  riastrad 	cp_m2p2 = RREG32(CP_ME2_PIPE2_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
   7086  1.3  riastrad 	cp_m2p3 = RREG32(CP_ME2_PIPE3_INT_CNTL) & ~TIME_STAMP_INT_ENABLE;
   7087  1.1  riastrad 
   7088  1.1  riastrad 	/* enable CP interrupts on all rings */
   7089  1.1  riastrad 	if (atomic_read(&rdev->irq.ring_int[RADEON_RING_TYPE_GFX_INDEX])) {
   7090  1.1  riastrad 		DRM_DEBUG("cik_irq_set: sw int gfx\n");
   7091  1.1  riastrad 		cp_int_cntl |= TIME_STAMP_INT_ENABLE;
   7092  1.1  riastrad 	}
   7093  1.1  riastrad 	if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP1_INDEX])) {
   7094  1.1  riastrad 		struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
   7095  1.1  riastrad 		DRM_DEBUG("si_irq_set: sw int cp1\n");
   7096  1.1  riastrad 		if (ring->me == 1) {
   7097  1.1  riastrad 			switch (ring->pipe) {
   7098  1.1  riastrad 			case 0:
   7099  1.1  riastrad 				cp_m1p0 |= TIME_STAMP_INT_ENABLE;
   7100  1.1  riastrad 				break;
   7101  1.3  riastrad 			case 1:
   7102  1.3  riastrad 				cp_m1p1 |= TIME_STAMP_INT_ENABLE;
   7103  1.3  riastrad 				break;
   7104  1.3  riastrad 			case 2:
   7105  1.3  riastrad 				cp_m1p2 |= TIME_STAMP_INT_ENABLE;
   7106  1.3  riastrad 				break;
   7107  1.3  riastrad 			case 3:
   7108  1.3  riastrad 				cp_m1p2 |= TIME_STAMP_INT_ENABLE;
   7109  1.3  riastrad 				break;
   7110  1.3  riastrad 			default:
   7111  1.3  riastrad 				DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
   7112  1.3  riastrad 				break;
   7113  1.3  riastrad 			}
   7114  1.3  riastrad 		} else if (ring->me == 2) {
   7115  1.3  riastrad 			switch (ring->pipe) {
   7116  1.3  riastrad 			case 0:
   7117  1.3  riastrad 				cp_m2p0 |= TIME_STAMP_INT_ENABLE;
   7118  1.3  riastrad 				break;
   7119  1.3  riastrad 			case 1:
   7120  1.3  riastrad 				cp_m2p1 |= TIME_STAMP_INT_ENABLE;
   7121  1.3  riastrad 				break;
   7122  1.3  riastrad 			case 2:
   7123  1.3  riastrad 				cp_m2p2 |= TIME_STAMP_INT_ENABLE;
   7124  1.3  riastrad 				break;
   7125  1.3  riastrad 			case 3:
   7126  1.3  riastrad 				cp_m2p2 |= TIME_STAMP_INT_ENABLE;
   7127  1.3  riastrad 				break;
   7128  1.1  riastrad 			default:
   7129  1.1  riastrad 				DRM_DEBUG("si_irq_set: sw int cp1 invalid pipe %d\n", ring->pipe);
   7130  1.1  riastrad 				break;
   7131  1.1  riastrad 			}
   7132  1.1  riastrad 		} else {
   7133  1.1  riastrad 			DRM_DEBUG("si_irq_set: sw int cp1 invalid me %d\n", ring->me);
   7134  1.1  riastrad 		}
   7135  1.1  riastrad 	}
   7136  1.1  riastrad 	if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_CP2_INDEX])) {
   7137  1.1  riastrad 		struct radeon_ring *ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
   7138  1.1  riastrad 		DRM_DEBUG("si_irq_set: sw int cp2\n");
   7139  1.1  riastrad 		if (ring->me == 1) {
   7140  1.1  riastrad 			switch (ring->pipe) {
   7141  1.1  riastrad 			case 0:
   7142  1.1  riastrad 				cp_m1p0 |= TIME_STAMP_INT_ENABLE;
   7143  1.1  riastrad 				break;
   7144  1.3  riastrad 			case 1:
   7145  1.3  riastrad 				cp_m1p1 |= TIME_STAMP_INT_ENABLE;
   7146  1.3  riastrad 				break;
   7147  1.3  riastrad 			case 2:
   7148  1.3  riastrad 				cp_m1p2 |= TIME_STAMP_INT_ENABLE;
   7149  1.3  riastrad 				break;
   7150  1.3  riastrad 			case 3:
   7151  1.3  riastrad 				cp_m1p2 |= TIME_STAMP_INT_ENABLE;
   7152  1.3  riastrad 				break;
   7153  1.3  riastrad 			default:
   7154  1.3  riastrad 				DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
   7155  1.3  riastrad 				break;
   7156  1.3  riastrad 			}
   7157  1.3  riastrad 		} else if (ring->me == 2) {
   7158  1.3  riastrad 			switch (ring->pipe) {
   7159  1.3  riastrad 			case 0:
   7160  1.3  riastrad 				cp_m2p0 |= TIME_STAMP_INT_ENABLE;
   7161  1.3  riastrad 				break;
   7162  1.3  riastrad 			case 1:
   7163  1.3  riastrad 				cp_m2p1 |= TIME_STAMP_INT_ENABLE;
   7164  1.3  riastrad 				break;
   7165  1.3  riastrad 			case 2:
   7166  1.3  riastrad 				cp_m2p2 |= TIME_STAMP_INT_ENABLE;
   7167  1.3  riastrad 				break;
   7168  1.3  riastrad 			case 3:
   7169  1.3  riastrad 				cp_m2p2 |= TIME_STAMP_INT_ENABLE;
   7170  1.3  riastrad 				break;
   7171  1.1  riastrad 			default:
   7172  1.1  riastrad 				DRM_DEBUG("si_irq_set: sw int cp2 invalid pipe %d\n", ring->pipe);
   7173  1.1  riastrad 				break;
   7174  1.1  riastrad 			}
   7175  1.1  riastrad 		} else {
   7176  1.1  riastrad 			DRM_DEBUG("si_irq_set: sw int cp2 invalid me %d\n", ring->me);
   7177  1.1  riastrad 		}
   7178  1.1  riastrad 	}
   7179  1.1  riastrad 
   7180  1.1  riastrad 	if (atomic_read(&rdev->irq.ring_int[R600_RING_TYPE_DMA_INDEX])) {
   7181  1.1  riastrad 		DRM_DEBUG("cik_irq_set: sw int dma\n");
   7182  1.1  riastrad 		dma_cntl |= TRAP_ENABLE;
   7183  1.1  riastrad 	}
   7184  1.1  riastrad 
   7185  1.1  riastrad 	if (atomic_read(&rdev->irq.ring_int[CAYMAN_RING_TYPE_DMA1_INDEX])) {
   7186  1.1  riastrad 		DRM_DEBUG("cik_irq_set: sw int dma1\n");
   7187  1.1  riastrad 		dma_cntl1 |= TRAP_ENABLE;
   7188  1.1  riastrad 	}
   7189  1.1  riastrad 
   7190  1.1  riastrad 	if (rdev->irq.crtc_vblank_int[0] ||
   7191  1.1  riastrad 	    atomic_read(&rdev->irq.pflip[0])) {
   7192  1.1  riastrad 		DRM_DEBUG("cik_irq_set: vblank 0\n");
   7193  1.1  riastrad 		crtc1 |= VBLANK_INTERRUPT_MASK;
   7194  1.1  riastrad 	}
   7195  1.1  riastrad 	if (rdev->irq.crtc_vblank_int[1] ||
   7196  1.1  riastrad 	    atomic_read(&rdev->irq.pflip[1])) {
   7197  1.1  riastrad 		DRM_DEBUG("cik_irq_set: vblank 1\n");
   7198  1.1  riastrad 		crtc2 |= VBLANK_INTERRUPT_MASK;
   7199  1.1  riastrad 	}
   7200  1.1  riastrad 	if (rdev->irq.crtc_vblank_int[2] ||
   7201  1.1  riastrad 	    atomic_read(&rdev->irq.pflip[2])) {
   7202  1.1  riastrad 		DRM_DEBUG("cik_irq_set: vblank 2\n");
   7203  1.1  riastrad 		crtc3 |= VBLANK_INTERRUPT_MASK;
   7204  1.1  riastrad 	}
   7205  1.1  riastrad 	if (rdev->irq.crtc_vblank_int[3] ||
   7206  1.1  riastrad 	    atomic_read(&rdev->irq.pflip[3])) {
   7207  1.1  riastrad 		DRM_DEBUG("cik_irq_set: vblank 3\n");
   7208  1.1  riastrad 		crtc4 |= VBLANK_INTERRUPT_MASK;
   7209  1.1  riastrad 	}
   7210  1.1  riastrad 	if (rdev->irq.crtc_vblank_int[4] ||
   7211  1.1  riastrad 	    atomic_read(&rdev->irq.pflip[4])) {
   7212  1.1  riastrad 		DRM_DEBUG("cik_irq_set: vblank 4\n");
   7213  1.1  riastrad 		crtc5 |= VBLANK_INTERRUPT_MASK;
   7214  1.1  riastrad 	}
   7215  1.1  riastrad 	if (rdev->irq.crtc_vblank_int[5] ||
   7216  1.1  riastrad 	    atomic_read(&rdev->irq.pflip[5])) {
   7217  1.1  riastrad 		DRM_DEBUG("cik_irq_set: vblank 5\n");
   7218  1.1  riastrad 		crtc6 |= VBLANK_INTERRUPT_MASK;
   7219  1.1  riastrad 	}
   7220  1.1  riastrad 	if (rdev->irq.hpd[0]) {
   7221  1.1  riastrad 		DRM_DEBUG("cik_irq_set: hpd 1\n");
   7222  1.1  riastrad 		hpd1 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
   7223  1.1  riastrad 	}
   7224  1.1  riastrad 	if (rdev->irq.hpd[1]) {
   7225  1.1  riastrad 		DRM_DEBUG("cik_irq_set: hpd 2\n");
   7226  1.1  riastrad 		hpd2 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
   7227  1.1  riastrad 	}
   7228  1.1  riastrad 	if (rdev->irq.hpd[2]) {
   7229  1.1  riastrad 		DRM_DEBUG("cik_irq_set: hpd 3\n");
   7230  1.1  riastrad 		hpd3 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
   7231  1.1  riastrad 	}
   7232  1.1  riastrad 	if (rdev->irq.hpd[3]) {
   7233  1.1  riastrad 		DRM_DEBUG("cik_irq_set: hpd 4\n");
   7234  1.1  riastrad 		hpd4 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
   7235  1.1  riastrad 	}
   7236  1.1  riastrad 	if (rdev->irq.hpd[4]) {
   7237  1.1  riastrad 		DRM_DEBUG("cik_irq_set: hpd 5\n");
   7238  1.1  riastrad 		hpd5 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
   7239  1.1  riastrad 	}
   7240  1.1  riastrad 	if (rdev->irq.hpd[5]) {
   7241  1.1  riastrad 		DRM_DEBUG("cik_irq_set: hpd 6\n");
   7242  1.1  riastrad 		hpd6 |= DC_HPDx_INT_EN | DC_HPDx_RX_INT_EN;
   7243  1.1  riastrad 	}
   7244  1.1  riastrad 
   7245  1.1  riastrad 	WREG32(CP_INT_CNTL_RING0, cp_int_cntl);
   7246  1.1  riastrad 
   7247  1.1  riastrad 	WREG32(SDMA0_CNTL + SDMA0_REGISTER_OFFSET, dma_cntl);
   7248  1.1  riastrad 	WREG32(SDMA0_CNTL + SDMA1_REGISTER_OFFSET, dma_cntl1);
   7249  1.1  riastrad 
   7250  1.1  riastrad 	WREG32(CP_ME1_PIPE0_INT_CNTL, cp_m1p0);
   7251  1.3  riastrad 	WREG32(CP_ME1_PIPE1_INT_CNTL, cp_m1p1);
   7252  1.3  riastrad 	WREG32(CP_ME1_PIPE2_INT_CNTL, cp_m1p2);
   7253  1.3  riastrad 	WREG32(CP_ME1_PIPE3_INT_CNTL, cp_m1p3);
   7254  1.3  riastrad 	WREG32(CP_ME2_PIPE0_INT_CNTL, cp_m2p0);
   7255  1.3  riastrad 	WREG32(CP_ME2_PIPE1_INT_CNTL, cp_m2p1);
   7256  1.3  riastrad 	WREG32(CP_ME2_PIPE2_INT_CNTL, cp_m2p2);
   7257  1.3  riastrad 	WREG32(CP_ME2_PIPE3_INT_CNTL, cp_m2p3);
   7258  1.1  riastrad 
   7259  1.1  riastrad 	WREG32(GRBM_INT_CNTL, grbm_int_cntl);
   7260  1.1  riastrad 
   7261  1.1  riastrad 	WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, crtc1);
   7262  1.1  riastrad 	WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, crtc2);
   7263  1.1  riastrad 	if (rdev->num_crtc >= 4) {
   7264  1.1  riastrad 		WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC2_REGISTER_OFFSET, crtc3);
   7265  1.1  riastrad 		WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC3_REGISTER_OFFSET, crtc4);
   7266  1.1  riastrad 	}
   7267  1.1  riastrad 	if (rdev->num_crtc >= 6) {
   7268  1.1  riastrad 		WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC4_REGISTER_OFFSET, crtc5);
   7269  1.1  riastrad 		WREG32(LB_INTERRUPT_MASK + EVERGREEN_CRTC5_REGISTER_OFFSET, crtc6);
   7270  1.1  riastrad 	}
   7271  1.1  riastrad 
   7272  1.1  riastrad 	if (rdev->num_crtc >= 2) {
   7273  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET,
   7274  1.1  riastrad 		       GRPH_PFLIP_INT_MASK);
   7275  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET,
   7276  1.1  riastrad 		       GRPH_PFLIP_INT_MASK);
   7277  1.1  riastrad 	}
   7278  1.1  riastrad 	if (rdev->num_crtc >= 4) {
   7279  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET,
   7280  1.1  riastrad 		       GRPH_PFLIP_INT_MASK);
   7281  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET,
   7282  1.1  riastrad 		       GRPH_PFLIP_INT_MASK);
   7283  1.1  riastrad 	}
   7284  1.1  riastrad 	if (rdev->num_crtc >= 6) {
   7285  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET,
   7286  1.1  riastrad 		       GRPH_PFLIP_INT_MASK);
   7287  1.1  riastrad 		WREG32(GRPH_INT_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET,
   7288  1.1  riastrad 		       GRPH_PFLIP_INT_MASK);
   7289  1.1  riastrad 	}
   7290  1.1  riastrad 
   7291  1.1  riastrad 	WREG32(DC_HPD1_INT_CONTROL, hpd1);
   7292  1.1  riastrad 	WREG32(DC_HPD2_INT_CONTROL, hpd2);
   7293  1.1  riastrad 	WREG32(DC_HPD3_INT_CONTROL, hpd3);
   7294  1.1  riastrad 	WREG32(DC_HPD4_INT_CONTROL, hpd4);
   7295  1.1  riastrad 	WREG32(DC_HPD5_INT_CONTROL, hpd5);
   7296  1.1  riastrad 	WREG32(DC_HPD6_INT_CONTROL, hpd6);
   7297  1.1  riastrad 
   7298  1.1  riastrad 	/* posting read */
   7299  1.1  riastrad 	RREG32(SRBM_STATUS);
   7300  1.1  riastrad 
   7301  1.1  riastrad 	return 0;
   7302  1.1  riastrad }
   7303  1.1  riastrad 
   7304  1.1  riastrad /**
   7305  1.1  riastrad  * cik_irq_ack - ack interrupt sources
   7306  1.1  riastrad  *
   7307  1.1  riastrad  * @rdev: radeon_device pointer
   7308  1.1  riastrad  *
   7309  1.1  riastrad  * Ack interrupt sources on the GPU (vblanks, hpd,
   7310  1.1  riastrad  * etc.) (CIK).  Certain interrupts sources are sw
   7311  1.1  riastrad  * generated and do not require an explicit ack.
   7312  1.1  riastrad  */
   7313  1.1  riastrad static inline void cik_irq_ack(struct radeon_device *rdev)
   7314  1.1  riastrad {
   7315  1.1  riastrad 	u32 tmp;
   7316  1.1  riastrad 
   7317  1.1  riastrad 	rdev->irq.stat_regs.cik.disp_int = RREG32(DISP_INTERRUPT_STATUS);
   7318  1.1  riastrad 	rdev->irq.stat_regs.cik.disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
   7319  1.1  riastrad 	rdev->irq.stat_regs.cik.disp_int_cont2 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE2);
   7320  1.1  riastrad 	rdev->irq.stat_regs.cik.disp_int_cont3 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE3);
   7321  1.1  riastrad 	rdev->irq.stat_regs.cik.disp_int_cont4 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE4);
   7322  1.1  riastrad 	rdev->irq.stat_regs.cik.disp_int_cont5 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE5);
   7323  1.1  riastrad 	rdev->irq.stat_regs.cik.disp_int_cont6 = RREG32(DISP_INTERRUPT_STATUS_CONTINUE6);
   7324  1.1  riastrad 
   7325  1.1  riastrad 	rdev->irq.stat_regs.cik.d1grph_int = RREG32(GRPH_INT_STATUS +
   7326  1.1  riastrad 		EVERGREEN_CRTC0_REGISTER_OFFSET);
   7327  1.1  riastrad 	rdev->irq.stat_regs.cik.d2grph_int = RREG32(GRPH_INT_STATUS +
   7328  1.1  riastrad 		EVERGREEN_CRTC1_REGISTER_OFFSET);
   7329  1.1  riastrad 	if (rdev->num_crtc >= 4) {
   7330  1.1  riastrad 		rdev->irq.stat_regs.cik.d3grph_int = RREG32(GRPH_INT_STATUS +
   7331  1.1  riastrad 			EVERGREEN_CRTC2_REGISTER_OFFSET);
   7332  1.1  riastrad 		rdev->irq.stat_regs.cik.d4grph_int = RREG32(GRPH_INT_STATUS +
   7333  1.1  riastrad 			EVERGREEN_CRTC3_REGISTER_OFFSET);
   7334  1.1  riastrad 	}
   7335  1.1  riastrad 	if (rdev->num_crtc >= 6) {
   7336  1.1  riastrad 		rdev->irq.stat_regs.cik.d5grph_int = RREG32(GRPH_INT_STATUS +
   7337  1.1  riastrad 			EVERGREEN_CRTC4_REGISTER_OFFSET);
   7338  1.1  riastrad 		rdev->irq.stat_regs.cik.d6grph_int = RREG32(GRPH_INT_STATUS +
   7339  1.1  riastrad 			EVERGREEN_CRTC5_REGISTER_OFFSET);
   7340  1.1  riastrad 	}
   7341  1.1  riastrad 
   7342  1.1  riastrad 	if (rdev->irq.stat_regs.cik.d1grph_int & GRPH_PFLIP_INT_OCCURRED)
   7343  1.1  riastrad 		WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET,
   7344  1.1  riastrad 		       GRPH_PFLIP_INT_CLEAR);
   7345  1.1  riastrad 	if (rdev->irq.stat_regs.cik.d2grph_int & GRPH_PFLIP_INT_OCCURRED)
   7346  1.1  riastrad 		WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET,
   7347  1.1  riastrad 		       GRPH_PFLIP_INT_CLEAR);
   7348  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT)
   7349  1.1  riastrad 		WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VBLANK_ACK);
   7350  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT)
   7351  1.1  riastrad 		WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC0_REGISTER_OFFSET, VLINE_ACK);
   7352  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT)
   7353  1.1  riastrad 		WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VBLANK_ACK);
   7354  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT)
   7355  1.1  riastrad 		WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC1_REGISTER_OFFSET, VLINE_ACK);
   7356  1.1  riastrad 
   7357  1.1  riastrad 	if (rdev->num_crtc >= 4) {
   7358  1.1  riastrad 		if (rdev->irq.stat_regs.cik.d3grph_int & GRPH_PFLIP_INT_OCCURRED)
   7359  1.1  riastrad 			WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET,
   7360  1.1  riastrad 			       GRPH_PFLIP_INT_CLEAR);
   7361  1.1  riastrad 		if (rdev->irq.stat_regs.cik.d4grph_int & GRPH_PFLIP_INT_OCCURRED)
   7362  1.1  riastrad 			WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET,
   7363  1.1  riastrad 			       GRPH_PFLIP_INT_CLEAR);
   7364  1.1  riastrad 		if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT)
   7365  1.1  riastrad 			WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VBLANK_ACK);
   7366  1.1  riastrad 		if (rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT)
   7367  1.1  riastrad 			WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC2_REGISTER_OFFSET, VLINE_ACK);
   7368  1.1  riastrad 		if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT)
   7369  1.1  riastrad 			WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VBLANK_ACK);
   7370  1.1  riastrad 		if (rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT)
   7371  1.1  riastrad 			WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC3_REGISTER_OFFSET, VLINE_ACK);
   7372  1.1  riastrad 	}
   7373  1.1  riastrad 
   7374  1.1  riastrad 	if (rdev->num_crtc >= 6) {
   7375  1.1  riastrad 		if (rdev->irq.stat_regs.cik.d5grph_int & GRPH_PFLIP_INT_OCCURRED)
   7376  1.1  riastrad 			WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET,
   7377  1.1  riastrad 			       GRPH_PFLIP_INT_CLEAR);
   7378  1.1  riastrad 		if (rdev->irq.stat_regs.cik.d6grph_int & GRPH_PFLIP_INT_OCCURRED)
   7379  1.1  riastrad 			WREG32(GRPH_INT_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET,
   7380  1.1  riastrad 			       GRPH_PFLIP_INT_CLEAR);
   7381  1.1  riastrad 		if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT)
   7382  1.1  riastrad 			WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VBLANK_ACK);
   7383  1.1  riastrad 		if (rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT)
   7384  1.1  riastrad 			WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC4_REGISTER_OFFSET, VLINE_ACK);
   7385  1.1  riastrad 		if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT)
   7386  1.1  riastrad 			WREG32(LB_VBLANK_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VBLANK_ACK);
   7387  1.1  riastrad 		if (rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT)
   7388  1.1  riastrad 			WREG32(LB_VLINE_STATUS + EVERGREEN_CRTC5_REGISTER_OFFSET, VLINE_ACK);
   7389  1.1  riastrad 	}
   7390  1.1  riastrad 
   7391  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT) {
   7392  1.1  riastrad 		tmp = RREG32(DC_HPD1_INT_CONTROL);
   7393  1.1  riastrad 		tmp |= DC_HPDx_INT_ACK;
   7394  1.1  riastrad 		WREG32(DC_HPD1_INT_CONTROL, tmp);
   7395  1.1  riastrad 	}
   7396  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT) {
   7397  1.1  riastrad 		tmp = RREG32(DC_HPD2_INT_CONTROL);
   7398  1.1  riastrad 		tmp |= DC_HPDx_INT_ACK;
   7399  1.1  riastrad 		WREG32(DC_HPD2_INT_CONTROL, tmp);
   7400  1.1  riastrad 	}
   7401  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT) {
   7402  1.1  riastrad 		tmp = RREG32(DC_HPD3_INT_CONTROL);
   7403  1.1  riastrad 		tmp |= DC_HPDx_INT_ACK;
   7404  1.1  riastrad 		WREG32(DC_HPD3_INT_CONTROL, tmp);
   7405  1.1  riastrad 	}
   7406  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT) {
   7407  1.1  riastrad 		tmp = RREG32(DC_HPD4_INT_CONTROL);
   7408  1.1  riastrad 		tmp |= DC_HPDx_INT_ACK;
   7409  1.1  riastrad 		WREG32(DC_HPD4_INT_CONTROL, tmp);
   7410  1.1  riastrad 	}
   7411  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT) {
   7412  1.1  riastrad 		tmp = RREG32(DC_HPD5_INT_CONTROL);
   7413  1.1  riastrad 		tmp |= DC_HPDx_INT_ACK;
   7414  1.1  riastrad 		WREG32(DC_HPD5_INT_CONTROL, tmp);
   7415  1.1  riastrad 	}
   7416  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT) {
   7417  1.1  riastrad 		tmp = RREG32(DC_HPD6_INT_CONTROL);
   7418  1.1  riastrad 		tmp |= DC_HPDx_INT_ACK;
   7419  1.1  riastrad 		WREG32(DC_HPD6_INT_CONTROL, tmp);
   7420  1.1  riastrad 	}
   7421  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int & DC_HPD1_RX_INTERRUPT) {
   7422  1.1  riastrad 		tmp = RREG32(DC_HPD1_INT_CONTROL);
   7423  1.1  riastrad 		tmp |= DC_HPDx_RX_INT_ACK;
   7424  1.1  riastrad 		WREG32(DC_HPD1_INT_CONTROL, tmp);
   7425  1.1  riastrad 	}
   7426  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_RX_INTERRUPT) {
   7427  1.1  riastrad 		tmp = RREG32(DC_HPD2_INT_CONTROL);
   7428  1.1  riastrad 		tmp |= DC_HPDx_RX_INT_ACK;
   7429  1.1  riastrad 		WREG32(DC_HPD2_INT_CONTROL, tmp);
   7430  1.1  riastrad 	}
   7431  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_RX_INTERRUPT) {
   7432  1.1  riastrad 		tmp = RREG32(DC_HPD3_INT_CONTROL);
   7433  1.1  riastrad 		tmp |= DC_HPDx_RX_INT_ACK;
   7434  1.1  riastrad 		WREG32(DC_HPD3_INT_CONTROL, tmp);
   7435  1.1  riastrad 	}
   7436  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_RX_INTERRUPT) {
   7437  1.1  riastrad 		tmp = RREG32(DC_HPD4_INT_CONTROL);
   7438  1.1  riastrad 		tmp |= DC_HPDx_RX_INT_ACK;
   7439  1.1  riastrad 		WREG32(DC_HPD4_INT_CONTROL, tmp);
   7440  1.1  riastrad 	}
   7441  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_RX_INTERRUPT) {
   7442  1.1  riastrad 		tmp = RREG32(DC_HPD5_INT_CONTROL);
   7443  1.1  riastrad 		tmp |= DC_HPDx_RX_INT_ACK;
   7444  1.1  riastrad 		WREG32(DC_HPD5_INT_CONTROL, tmp);
   7445  1.1  riastrad 	}
   7446  1.1  riastrad 	if (rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_RX_INTERRUPT) {
   7447  1.1  riastrad 		tmp = RREG32(DC_HPD6_INT_CONTROL);
   7448  1.1  riastrad 		tmp |= DC_HPDx_RX_INT_ACK;
   7449  1.1  riastrad 		WREG32(DC_HPD6_INT_CONTROL, tmp);
   7450  1.1  riastrad 	}
   7451  1.1  riastrad }
   7452  1.1  riastrad 
   7453  1.1  riastrad /**
   7454  1.1  riastrad  * cik_irq_disable - disable interrupts
   7455  1.1  riastrad  *
   7456  1.1  riastrad  * @rdev: radeon_device pointer
   7457  1.1  riastrad  *
   7458  1.1  riastrad  * Disable interrupts on the hw (CIK).
   7459  1.1  riastrad  */
   7460  1.1  riastrad static void cik_irq_disable(struct radeon_device *rdev)
   7461  1.1  riastrad {
   7462  1.1  riastrad 	cik_disable_interrupts(rdev);
   7463  1.1  riastrad 	/* Wait and acknowledge irq */
   7464  1.1  riastrad 	mdelay(1);
   7465  1.1  riastrad 	cik_irq_ack(rdev);
   7466  1.1  riastrad 	cik_disable_interrupt_state(rdev);
   7467  1.1  riastrad }
   7468  1.1  riastrad 
   7469  1.1  riastrad /**
   7470  1.1  riastrad  * cik_irq_disable - disable interrupts for suspend
   7471  1.1  riastrad  *
   7472  1.1  riastrad  * @rdev: radeon_device pointer
   7473  1.1  riastrad  *
   7474  1.1  riastrad  * Disable interrupts and stop the RLC (CIK).
   7475  1.1  riastrad  * Used for suspend.
   7476  1.1  riastrad  */
   7477  1.1  riastrad static void cik_irq_suspend(struct radeon_device *rdev)
   7478  1.1  riastrad {
   7479  1.1  riastrad 	cik_irq_disable(rdev);
   7480  1.1  riastrad 	cik_rlc_stop(rdev);
   7481  1.1  riastrad }
   7482  1.1  riastrad 
   7483  1.1  riastrad /**
   7484  1.1  riastrad  * cik_irq_fini - tear down interrupt support
   7485  1.1  riastrad  *
   7486  1.1  riastrad  * @rdev: radeon_device pointer
   7487  1.1  riastrad  *
   7488  1.1  riastrad  * Disable interrupts on the hw and free the IH ring
   7489  1.1  riastrad  * buffer (CIK).
   7490  1.1  riastrad  * Used for driver unload.
   7491  1.1  riastrad  */
   7492  1.1  riastrad static void cik_irq_fini(struct radeon_device *rdev)
   7493  1.1  riastrad {
   7494  1.1  riastrad 	cik_irq_suspend(rdev);
   7495  1.1  riastrad 	r600_ih_ring_fini(rdev);
   7496  1.1  riastrad }
   7497  1.1  riastrad 
   7498  1.1  riastrad /**
   7499  1.1  riastrad  * cik_get_ih_wptr - get the IH ring buffer wptr
   7500  1.1  riastrad  *
   7501  1.1  riastrad  * @rdev: radeon_device pointer
   7502  1.1  riastrad  *
   7503  1.1  riastrad  * Get the IH ring buffer wptr from either the register
   7504  1.1  riastrad  * or the writeback memory buffer (CIK).  Also check for
   7505  1.1  riastrad  * ring buffer overflow and deal with it.
   7506  1.1  riastrad  * Used by cik_irq_process().
   7507  1.1  riastrad  * Returns the value of the wptr.
   7508  1.1  riastrad  */
   7509  1.1  riastrad static inline u32 cik_get_ih_wptr(struct radeon_device *rdev)
   7510  1.1  riastrad {
   7511  1.1  riastrad 	u32 wptr, tmp;
   7512  1.1  riastrad 
   7513  1.1  riastrad 	if (rdev->wb.enabled)
   7514  1.1  riastrad 		wptr = le32_to_cpu(rdev->wb.wb[R600_WB_IH_WPTR_OFFSET/4]);
   7515  1.1  riastrad 	else
   7516  1.1  riastrad 		wptr = RREG32(IH_RB_WPTR);
   7517  1.1  riastrad 
   7518  1.1  riastrad 	if (wptr & RB_OVERFLOW) {
   7519  1.1  riastrad 		wptr &= ~RB_OVERFLOW;
   7520  1.1  riastrad 		/* When a ring buffer overflow happen start parsing interrupt
   7521  1.1  riastrad 		 * from the last not overwritten vector (wptr + 16). Hopefully
   7522  1.1  riastrad 		 * this should allow us to catchup.
   7523  1.1  riastrad 		 */
   7524  1.1  riastrad 		dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, 0x%08X, 0x%08X)\n",
   7525  1.1  riastrad 			 wptr, rdev->ih.rptr, (wptr + 16) & rdev->ih.ptr_mask);
   7526  1.1  riastrad 		rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
   7527  1.1  riastrad 		tmp = RREG32(IH_RB_CNTL);
   7528  1.1  riastrad 		tmp |= IH_WPTR_OVERFLOW_CLEAR;
   7529  1.1  riastrad 		WREG32(IH_RB_CNTL, tmp);
   7530  1.1  riastrad 	}
   7531  1.1  riastrad 	return (wptr & rdev->ih.ptr_mask);
   7532  1.1  riastrad }
   7533  1.1  riastrad 
   7534  1.1  riastrad /*        CIK IV Ring
   7535  1.1  riastrad  * Each IV ring entry is 128 bits:
   7536  1.1  riastrad  * [7:0]    - interrupt source id
   7537  1.1  riastrad  * [31:8]   - reserved
   7538  1.1  riastrad  * [59:32]  - interrupt source data
   7539  1.1  riastrad  * [63:60]  - reserved
   7540  1.1  riastrad  * [71:64]  - RINGID
   7541  1.1  riastrad  *            CP:
   7542  1.1  riastrad  *            ME_ID [1:0], PIPE_ID[1:0], QUEUE_ID[2:0]
   7543  1.1  riastrad  *            QUEUE_ID - for compute, which of the 8 queues owned by the dispatcher
   7544  1.1  riastrad  *                     - for gfx, hw shader state (0=PS...5=LS, 6=CS)
   7545  1.1  riastrad  *            ME_ID - 0 = gfx, 1 = first 4 CS pipes, 2 = second 4 CS pipes
   7546  1.1  riastrad  *            PIPE_ID - ME0 0=3D
   7547  1.1  riastrad  *                    - ME1&2 compute dispatcher (4 pipes each)
   7548  1.1  riastrad  *            SDMA:
   7549  1.1  riastrad  *            INSTANCE_ID [1:0], QUEUE_ID[1:0]
   7550  1.1  riastrad  *            INSTANCE_ID - 0 = sdma0, 1 = sdma1
   7551  1.1  riastrad  *            QUEUE_ID - 0 = gfx, 1 = rlc0, 2 = rlc1
   7552  1.1  riastrad  * [79:72]  - VMID
   7553  1.1  riastrad  * [95:80]  - PASID
   7554  1.1  riastrad  * [127:96] - reserved
   7555  1.1  riastrad  */
   7556  1.1  riastrad /**
   7557  1.1  riastrad  * cik_irq_process - interrupt handler
   7558  1.1  riastrad  *
   7559  1.1  riastrad  * @rdev: radeon_device pointer
   7560  1.1  riastrad  *
   7561  1.1  riastrad  * Interrupt hander (CIK).  Walk the IH ring,
   7562  1.1  riastrad  * ack interrupts and schedule work to handle
   7563  1.1  riastrad  * interrupt events.
   7564  1.1  riastrad  * Returns irq process return code.
   7565  1.1  riastrad  */
   7566  1.1  riastrad int cik_irq_process(struct radeon_device *rdev)
   7567  1.1  riastrad {
   7568  1.1  riastrad 	struct radeon_ring *cp1_ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
   7569  1.1  riastrad 	struct radeon_ring *cp2_ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
   7570  1.1  riastrad 	u32 wptr;
   7571  1.1  riastrad 	u32 rptr;
   7572  1.1  riastrad 	u32 src_id, src_data, ring_id;
   7573  1.1  riastrad 	u8 me_id, pipe_id, queue_id;
   7574  1.1  riastrad 	u32 ring_index;
   7575  1.1  riastrad 	bool queue_hotplug = false;
   7576  1.1  riastrad 	bool queue_dp = false;
   7577  1.1  riastrad 	bool queue_reset = false;
   7578  1.1  riastrad 	u32 addr, status, mc_client;
   7579  1.1  riastrad 	bool queue_thermal = false;
   7580  1.1  riastrad 
   7581  1.1  riastrad 	if (!rdev->ih.enabled || rdev->shutdown)
   7582  1.1  riastrad 		return IRQ_NONE;
   7583  1.1  riastrad 
   7584  1.1  riastrad 	wptr = cik_get_ih_wptr(rdev);
   7585  1.1  riastrad 
   7586  1.1  riastrad restart_ih:
   7587  1.1  riastrad 	/* is somebody else already processing irqs? */
   7588  1.1  riastrad 	if (atomic_xchg(&rdev->ih.lock, 1))
   7589  1.1  riastrad 		return IRQ_NONE;
   7590  1.1  riastrad 
   7591  1.1  riastrad 	rptr = rdev->ih.rptr;
   7592  1.1  riastrad 	DRM_DEBUG("cik_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
   7593  1.1  riastrad 
   7594  1.1  riastrad 	/* Order reading of wptr vs. reading of IH ring data */
   7595  1.1  riastrad 	rmb();
   7596  1.1  riastrad 
   7597  1.1  riastrad 	/* display interrupts */
   7598  1.1  riastrad 	cik_irq_ack(rdev);
   7599  1.1  riastrad 
   7600  1.1  riastrad 	while (rptr != wptr) {
   7601  1.1  riastrad 		/* wptr/rptr are in bytes! */
   7602  1.1  riastrad 		ring_index = rptr / 4;
   7603  1.1  riastrad 
   7604  1.1  riastrad 		src_id =  le32_to_cpu(rdev->ih.ring[ring_index]) & 0xff;
   7605  1.1  riastrad 		src_data = le32_to_cpu(rdev->ih.ring[ring_index + 1]) & 0xfffffff;
   7606  1.1  riastrad 		ring_id = le32_to_cpu(rdev->ih.ring[ring_index + 2]) & 0xff;
   7607  1.1  riastrad 
   7608  1.1  riastrad 		switch (src_id) {
   7609  1.1  riastrad 		case 1: /* D1 vblank/vline */
   7610  1.1  riastrad 			switch (src_data) {
   7611  1.1  riastrad 			case 0: /* D1 vblank */
   7612  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int & LB_D1_VBLANK_INTERRUPT))
   7613  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7614  1.1  riastrad 
   7615  1.1  riastrad 				if (rdev->irq.crtc_vblank_int[0]) {
   7616  1.1  riastrad 					drm_handle_vblank(rdev->ddev, 0);
   7617  1.1  riastrad #ifdef __NetBSD__
   7618  1.1  riastrad 						spin_lock(&rdev->irq.vblank_lock);
   7619  1.1  riastrad 						rdev->pm.vblank_sync = true;
   7620  1.1  riastrad 						DRM_SPIN_WAKEUP_ONE(&rdev->irq.vblank_queue, &rdev->irq.vblank_lock);
   7621  1.1  riastrad 						spin_unlock(&rdev->irq.vblank_lock);
   7622  1.1  riastrad #else
   7623  1.1  riastrad 					rdev->pm.vblank_sync = true;
   7624  1.1  riastrad 					wake_up(&rdev->irq.vblank_queue);
   7625  1.1  riastrad #endif
   7626  1.1  riastrad 				}
   7627  1.1  riastrad 				if (atomic_read(&rdev->irq.pflip[0]))
   7628  1.1  riastrad 					radeon_crtc_handle_vblank(rdev, 0);
   7629  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VBLANK_INTERRUPT;
   7630  1.1  riastrad 				DRM_DEBUG("IH: D1 vblank\n");
   7631  1.1  riastrad 
   7632  1.1  riastrad 				break;
   7633  1.1  riastrad 			case 1: /* D1 vline */
   7634  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int & LB_D1_VLINE_INTERRUPT))
   7635  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7636  1.1  riastrad 
   7637  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int &= ~LB_D1_VLINE_INTERRUPT;
   7638  1.1  riastrad 				DRM_DEBUG("IH: D1 vline\n");
   7639  1.1  riastrad 
   7640  1.1  riastrad 				break;
   7641  1.1  riastrad 			default:
   7642  1.1  riastrad 				DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
   7643  1.1  riastrad 				break;
   7644  1.1  riastrad 			}
   7645  1.1  riastrad 			break;
   7646  1.1  riastrad 		case 2: /* D2 vblank/vline */
   7647  1.1  riastrad 			switch (src_data) {
   7648  1.1  riastrad 			case 0: /* D2 vblank */
   7649  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VBLANK_INTERRUPT))
   7650  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7651  1.1  riastrad 
   7652  1.1  riastrad 				if (rdev->irq.crtc_vblank_int[1]) {
   7653  1.1  riastrad 					drm_handle_vblank(rdev->ddev, 1);
   7654  1.1  riastrad #ifdef __NetBSD__
   7655  1.1  riastrad 						spin_lock(&rdev->irq.vblank_lock);
   7656  1.1  riastrad 						rdev->pm.vblank_sync = true;
   7657  1.1  riastrad 						DRM_SPIN_WAKEUP_ONE(&rdev->irq.vblank_queue, &rdev->irq.vblank_lock);
   7658  1.1  riastrad 						spin_unlock(&rdev->irq.vblank_lock);
   7659  1.1  riastrad #else
   7660  1.1  riastrad 					rdev->pm.vblank_sync = true;
   7661  1.1  riastrad 					wake_up(&rdev->irq.vblank_queue);
   7662  1.1  riastrad #endif
   7663  1.1  riastrad 				}
   7664  1.1  riastrad 				if (atomic_read(&rdev->irq.pflip[1]))
   7665  1.1  riastrad 					radeon_crtc_handle_vblank(rdev, 1);
   7666  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VBLANK_INTERRUPT;
   7667  1.1  riastrad 				DRM_DEBUG("IH: D2 vblank\n");
   7668  1.1  riastrad 
   7669  1.1  riastrad 				break;
   7670  1.1  riastrad 			case 1: /* D2 vline */
   7671  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont & LB_D2_VLINE_INTERRUPT))
   7672  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7673  1.1  riastrad 
   7674  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont &= ~LB_D2_VLINE_INTERRUPT;
   7675  1.1  riastrad 				DRM_DEBUG("IH: D2 vline\n");
   7676  1.1  riastrad 
   7677  1.1  riastrad 				break;
   7678  1.1  riastrad 			default:
   7679  1.1  riastrad 				DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
   7680  1.1  riastrad 				break;
   7681  1.1  riastrad 			}
   7682  1.1  riastrad 			break;
   7683  1.1  riastrad 		case 3: /* D3 vblank/vline */
   7684  1.1  riastrad 			switch (src_data) {
   7685  1.1  riastrad 			case 0: /* D3 vblank */
   7686  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VBLANK_INTERRUPT))
   7687  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7688  1.1  riastrad 
   7689  1.1  riastrad 				if (rdev->irq.crtc_vblank_int[2]) {
   7690  1.1  riastrad 					drm_handle_vblank(rdev->ddev, 2);
   7691  1.1  riastrad #ifdef __NetBSD__
   7692  1.1  riastrad 						spin_lock(&rdev->irq.vblank_lock);
   7693  1.1  riastrad 						rdev->pm.vblank_sync = true;
   7694  1.1  riastrad 						DRM_SPIN_WAKEUP_ONE(&rdev->irq.vblank_queue, &rdev->irq.vblank_lock);
   7695  1.1  riastrad 						spin_unlock(&rdev->irq.vblank_lock);
   7696  1.1  riastrad #else
   7697  1.1  riastrad 					rdev->pm.vblank_sync = true;
   7698  1.1  riastrad 					wake_up(&rdev->irq.vblank_queue);
   7699  1.1  riastrad #endif
   7700  1.1  riastrad 				}
   7701  1.1  riastrad 				if (atomic_read(&rdev->irq.pflip[2]))
   7702  1.1  riastrad 					radeon_crtc_handle_vblank(rdev, 2);
   7703  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VBLANK_INTERRUPT;
   7704  1.1  riastrad 				DRM_DEBUG("IH: D3 vblank\n");
   7705  1.1  riastrad 
   7706  1.1  riastrad 				break;
   7707  1.1  riastrad 			case 1: /* D3 vline */
   7708  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & LB_D3_VLINE_INTERRUPT))
   7709  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7710  1.1  riastrad 
   7711  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont2 &= ~LB_D3_VLINE_INTERRUPT;
   7712  1.1  riastrad 				DRM_DEBUG("IH: D3 vline\n");
   7713  1.1  riastrad 
   7714  1.1  riastrad 				break;
   7715  1.1  riastrad 			default:
   7716  1.1  riastrad 				DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
   7717  1.1  riastrad 				break;
   7718  1.1  riastrad 			}
   7719  1.1  riastrad 			break;
   7720  1.1  riastrad 		case 4: /* D4 vblank/vline */
   7721  1.1  riastrad 			switch (src_data) {
   7722  1.1  riastrad 			case 0: /* D4 vblank */
   7723  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VBLANK_INTERRUPT))
   7724  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7725  1.1  riastrad 
   7726  1.1  riastrad 				if (rdev->irq.crtc_vblank_int[3]) {
   7727  1.1  riastrad 					drm_handle_vblank(rdev->ddev, 3);
   7728  1.1  riastrad #ifdef __NetBSD__
   7729  1.1  riastrad 						spin_lock(&rdev->irq.vblank_lock);
   7730  1.1  riastrad 						rdev->pm.vblank_sync = true;
   7731  1.1  riastrad 						DRM_SPIN_WAKEUP_ONE(&rdev->irq.vblank_queue, &rdev->irq.vblank_lock);
   7732  1.1  riastrad 						spin_unlock(&rdev->irq.vblank_lock);
   7733  1.1  riastrad #else
   7734  1.1  riastrad 					rdev->pm.vblank_sync = true;
   7735  1.1  riastrad 					wake_up(&rdev->irq.vblank_queue);
   7736  1.1  riastrad #endif
   7737  1.1  riastrad 				}
   7738  1.1  riastrad 				if (atomic_read(&rdev->irq.pflip[3]))
   7739  1.1  riastrad 					radeon_crtc_handle_vblank(rdev, 3);
   7740  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VBLANK_INTERRUPT;
   7741  1.1  riastrad 				DRM_DEBUG("IH: D4 vblank\n");
   7742  1.1  riastrad 
   7743  1.1  riastrad 				break;
   7744  1.1  riastrad 			case 1: /* D4 vline */
   7745  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & LB_D4_VLINE_INTERRUPT))
   7746  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7747  1.1  riastrad 
   7748  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont3 &= ~LB_D4_VLINE_INTERRUPT;
   7749  1.1  riastrad 				DRM_DEBUG("IH: D4 vline\n");
   7750  1.1  riastrad 
   7751  1.1  riastrad 				break;
   7752  1.1  riastrad 			default:
   7753  1.1  riastrad 				DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
   7754  1.1  riastrad 				break;
   7755  1.1  riastrad 			}
   7756  1.1  riastrad 			break;
   7757  1.1  riastrad 		case 5: /* D5 vblank/vline */
   7758  1.1  riastrad 			switch (src_data) {
   7759  1.1  riastrad 			case 0: /* D5 vblank */
   7760  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VBLANK_INTERRUPT))
   7761  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7762  1.1  riastrad 
   7763  1.1  riastrad 				if (rdev->irq.crtc_vblank_int[4]) {
   7764  1.1  riastrad 					drm_handle_vblank(rdev->ddev, 4);
   7765  1.1  riastrad #ifdef __NetBSD__
   7766  1.1  riastrad 						spin_lock(&rdev->irq.vblank_lock);
   7767  1.1  riastrad 						rdev->pm.vblank_sync = true;
   7768  1.1  riastrad 						DRM_SPIN_WAKEUP_ONE(&rdev->irq.vblank_queue, &rdev->irq.vblank_lock);
   7769  1.1  riastrad 						spin_unlock(&rdev->irq.vblank_lock);
   7770  1.1  riastrad #else
   7771  1.1  riastrad 					rdev->pm.vblank_sync = true;
   7772  1.1  riastrad 					wake_up(&rdev->irq.vblank_queue);
   7773  1.1  riastrad #endif
   7774  1.1  riastrad 				}
   7775  1.1  riastrad 				if (atomic_read(&rdev->irq.pflip[4]))
   7776  1.1  riastrad 					radeon_crtc_handle_vblank(rdev, 4);
   7777  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VBLANK_INTERRUPT;
   7778  1.1  riastrad 				DRM_DEBUG("IH: D5 vblank\n");
   7779  1.1  riastrad 
   7780  1.1  riastrad 				break;
   7781  1.1  riastrad 			case 1: /* D5 vline */
   7782  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & LB_D5_VLINE_INTERRUPT))
   7783  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7784  1.1  riastrad 
   7785  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont4 &= ~LB_D5_VLINE_INTERRUPT;
   7786  1.1  riastrad 				DRM_DEBUG("IH: D5 vline\n");
   7787  1.1  riastrad 
   7788  1.1  riastrad 				break;
   7789  1.1  riastrad 			default:
   7790  1.1  riastrad 				DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
   7791  1.1  riastrad 				break;
   7792  1.1  riastrad 			}
   7793  1.1  riastrad 			break;
   7794  1.1  riastrad 		case 6: /* D6 vblank/vline */
   7795  1.1  riastrad 			switch (src_data) {
   7796  1.1  riastrad 			case 0: /* D6 vblank */
   7797  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VBLANK_INTERRUPT))
   7798  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7799  1.1  riastrad 
   7800  1.1  riastrad 				if (rdev->irq.crtc_vblank_int[5]) {
   7801  1.1  riastrad 					drm_handle_vblank(rdev->ddev, 5);
   7802  1.1  riastrad #ifdef __NetBSD__
   7803  1.1  riastrad 						spin_lock(&rdev->irq.vblank_lock);
   7804  1.1  riastrad 						rdev->pm.vblank_sync = true;
   7805  1.1  riastrad 						DRM_SPIN_WAKEUP_ONE(&rdev->irq.vblank_queue, &rdev->irq.vblank_lock);
   7806  1.1  riastrad 						spin_unlock(&rdev->irq.vblank_lock);
   7807  1.1  riastrad #else
   7808  1.1  riastrad 					rdev->pm.vblank_sync = true;
   7809  1.1  riastrad 					wake_up(&rdev->irq.vblank_queue);
   7810  1.1  riastrad #endif
   7811  1.1  riastrad 				}
   7812  1.1  riastrad 				if (atomic_read(&rdev->irq.pflip[5]))
   7813  1.1  riastrad 					radeon_crtc_handle_vblank(rdev, 5);
   7814  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VBLANK_INTERRUPT;
   7815  1.1  riastrad 				DRM_DEBUG("IH: D6 vblank\n");
   7816  1.1  riastrad 
   7817  1.1  riastrad 				break;
   7818  1.1  riastrad 			case 1: /* D6 vline */
   7819  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & LB_D6_VLINE_INTERRUPT))
   7820  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7821  1.1  riastrad 
   7822  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont5 &= ~LB_D6_VLINE_INTERRUPT;
   7823  1.1  riastrad 				DRM_DEBUG("IH: D6 vline\n");
   7824  1.1  riastrad 
   7825  1.1  riastrad 				break;
   7826  1.1  riastrad 			default:
   7827  1.1  riastrad 				DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
   7828  1.1  riastrad 				break;
   7829  1.1  riastrad 			}
   7830  1.1  riastrad 			break;
   7831  1.1  riastrad 		case 8: /* D1 page flip */
   7832  1.1  riastrad 		case 10: /* D2 page flip */
   7833  1.1  riastrad 		case 12: /* D3 page flip */
   7834  1.1  riastrad 		case 14: /* D4 page flip */
   7835  1.1  riastrad 		case 16: /* D5 page flip */
   7836  1.1  riastrad 		case 18: /* D6 page flip */
   7837  1.1  riastrad 			DRM_DEBUG("IH: D%d flip\n", ((src_id - 8) >> 1) + 1);
   7838  1.1  riastrad 			if (radeon_use_pflipirq > 0)
   7839  1.1  riastrad 				radeon_crtc_handle_flip(rdev, (src_id - 8) >> 1);
   7840  1.1  riastrad 			break;
   7841  1.1  riastrad 		case 42: /* HPD hotplug */
   7842  1.1  riastrad 			switch (src_data) {
   7843  1.1  riastrad 			case 0:
   7844  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int & DC_HPD1_INTERRUPT))
   7845  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7846  1.1  riastrad 
   7847  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_INTERRUPT;
   7848  1.1  riastrad 				queue_hotplug = true;
   7849  1.1  riastrad 				DRM_DEBUG("IH: HPD1\n");
   7850  1.1  riastrad 
   7851  1.1  riastrad 				break;
   7852  1.1  riastrad 			case 1:
   7853  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_INTERRUPT))
   7854  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7855  1.1  riastrad 
   7856  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_INTERRUPT;
   7857  1.1  riastrad 				queue_hotplug = true;
   7858  1.1  riastrad 				DRM_DEBUG("IH: HPD2\n");
   7859  1.1  riastrad 
   7860  1.1  riastrad 				break;
   7861  1.1  riastrad 			case 2:
   7862  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_INTERRUPT))
   7863  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7864  1.1  riastrad 
   7865  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_INTERRUPT;
   7866  1.1  riastrad 				queue_hotplug = true;
   7867  1.1  riastrad 				DRM_DEBUG("IH: HPD3\n");
   7868  1.1  riastrad 
   7869  1.1  riastrad 				break;
   7870  1.1  riastrad 			case 3:
   7871  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_INTERRUPT))
   7872  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7873  1.1  riastrad 
   7874  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_INTERRUPT;
   7875  1.1  riastrad 				queue_hotplug = true;
   7876  1.1  riastrad 				DRM_DEBUG("IH: HPD4\n");
   7877  1.1  riastrad 
   7878  1.1  riastrad 				break;
   7879  1.1  riastrad 			case 4:
   7880  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_INTERRUPT))
   7881  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7882  1.1  riastrad 
   7883  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_INTERRUPT;
   7884  1.1  riastrad 				queue_hotplug = true;
   7885  1.1  riastrad 				DRM_DEBUG("IH: HPD5\n");
   7886  1.1  riastrad 
   7887  1.1  riastrad 				break;
   7888  1.1  riastrad 			case 5:
   7889  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_INTERRUPT))
   7890  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7891  1.1  riastrad 
   7892  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_INTERRUPT;
   7893  1.1  riastrad 				queue_hotplug = true;
   7894  1.1  riastrad 				DRM_DEBUG("IH: HPD6\n");
   7895  1.1  riastrad 
   7896  1.1  riastrad 				break;
   7897  1.1  riastrad 			case 6:
   7898  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int & DC_HPD1_RX_INTERRUPT))
   7899  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7900  1.1  riastrad 
   7901  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int &= ~DC_HPD1_RX_INTERRUPT;
   7902  1.1  riastrad 				queue_dp = true;
   7903  1.1  riastrad 				DRM_DEBUG("IH: HPD_RX 1\n");
   7904  1.1  riastrad 
   7905  1.1  riastrad 				break;
   7906  1.1  riastrad 			case 7:
   7907  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont & DC_HPD2_RX_INTERRUPT))
   7908  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7909  1.1  riastrad 
   7910  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont &= ~DC_HPD2_RX_INTERRUPT;
   7911  1.1  riastrad 				queue_dp = true;
   7912  1.1  riastrad 				DRM_DEBUG("IH: HPD_RX 2\n");
   7913  1.1  riastrad 
   7914  1.1  riastrad 				break;
   7915  1.1  riastrad 			case 8:
   7916  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont2 & DC_HPD3_RX_INTERRUPT))
   7917  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7918  1.1  riastrad 
   7919  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont2 &= ~DC_HPD3_RX_INTERRUPT;
   7920  1.1  riastrad 				queue_dp = true;
   7921  1.1  riastrad 				DRM_DEBUG("IH: HPD_RX 3\n");
   7922  1.1  riastrad 
   7923  1.1  riastrad 				break;
   7924  1.1  riastrad 			case 9:
   7925  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont3 & DC_HPD4_RX_INTERRUPT))
   7926  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7927  1.1  riastrad 
   7928  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont3 &= ~DC_HPD4_RX_INTERRUPT;
   7929  1.1  riastrad 				queue_dp = true;
   7930  1.1  riastrad 				DRM_DEBUG("IH: HPD_RX 4\n");
   7931  1.1  riastrad 
   7932  1.1  riastrad 				break;
   7933  1.1  riastrad 			case 10:
   7934  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont4 & DC_HPD5_RX_INTERRUPT))
   7935  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7936  1.1  riastrad 
   7937  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont4 &= ~DC_HPD5_RX_INTERRUPT;
   7938  1.1  riastrad 				queue_dp = true;
   7939  1.1  riastrad 				DRM_DEBUG("IH: HPD_RX 5\n");
   7940  1.1  riastrad 
   7941  1.1  riastrad 				break;
   7942  1.1  riastrad 			case 11:
   7943  1.1  riastrad 				if (!(rdev->irq.stat_regs.cik.disp_int_cont5 & DC_HPD6_RX_INTERRUPT))
   7944  1.1  riastrad 					DRM_DEBUG("IH: IH event w/o asserted irq bit?\n");
   7945  1.1  riastrad 
   7946  1.1  riastrad 				rdev->irq.stat_regs.cik.disp_int_cont5 &= ~DC_HPD6_RX_INTERRUPT;
   7947  1.1  riastrad 				queue_dp = true;
   7948  1.1  riastrad 				DRM_DEBUG("IH: HPD_RX 6\n");
   7949  1.1  riastrad 
   7950  1.1  riastrad 				break;
   7951  1.1  riastrad 			default:
   7952  1.1  riastrad 				DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
   7953  1.1  riastrad 				break;
   7954  1.1  riastrad 			}
   7955  1.1  riastrad 			break;
   7956  1.1  riastrad 		case 96:
   7957  1.1  riastrad 			DRM_ERROR("SRBM_READ_ERROR: 0x%x\n", RREG32(SRBM_READ_ERROR));
   7958  1.1  riastrad 			WREG32(SRBM_INT_ACK, 0x1);
   7959  1.1  riastrad 			break;
   7960  1.1  riastrad 		case 124: /* UVD */
   7961  1.1  riastrad 			DRM_DEBUG("IH: UVD int: 0x%08x\n", src_data);
   7962  1.1  riastrad 			radeon_fence_process(rdev, R600_RING_TYPE_UVD_INDEX);
   7963  1.1  riastrad 			break;
   7964  1.1  riastrad 		case 146:
   7965  1.1  riastrad 		case 147:
   7966  1.1  riastrad 			addr = RREG32(VM_CONTEXT1_PROTECTION_FAULT_ADDR);
   7967  1.1  riastrad 			status = RREG32(VM_CONTEXT1_PROTECTION_FAULT_STATUS);
   7968  1.1  riastrad 			mc_client = RREG32(VM_CONTEXT1_PROTECTION_FAULT_MCCLIENT);
   7969  1.1  riastrad 			/* reset addr and status */
   7970  1.1  riastrad 			WREG32_P(VM_CONTEXT1_CNTL2, 1, ~1);
   7971  1.1  riastrad 			if (addr == 0x0 && status == 0x0)
   7972  1.1  riastrad 				break;
   7973  1.1  riastrad 			dev_err(rdev->dev, "GPU fault detected: %d 0x%08x\n", src_id, src_data);
   7974  1.1  riastrad 			dev_err(rdev->dev, "  VM_CONTEXT1_PROTECTION_FAULT_ADDR   0x%08X\n",
   7975  1.1  riastrad 				addr);
   7976  1.1  riastrad 			dev_err(rdev->dev, "  VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
   7977  1.1  riastrad 				status);
   7978  1.1  riastrad 			cik_vm_decode_fault(rdev, status, addr, mc_client);
   7979  1.1  riastrad 			break;
   7980  1.1  riastrad 		case 167: /* VCE */
   7981  1.1  riastrad 			DRM_DEBUG("IH: VCE int: 0x%08x\n", src_data);
   7982  1.1  riastrad 			switch (src_data) {
   7983  1.1  riastrad 			case 0:
   7984  1.1  riastrad 				radeon_fence_process(rdev, TN_RING_TYPE_VCE1_INDEX);
   7985  1.1  riastrad 				break;
   7986  1.1  riastrad 			case 1:
   7987  1.1  riastrad 				radeon_fence_process(rdev, TN_RING_TYPE_VCE2_INDEX);
   7988  1.1  riastrad 				break;
   7989  1.1  riastrad 			default:
   7990  1.1  riastrad 				DRM_ERROR("Unhandled interrupt: %d %d\n", src_id, src_data);
   7991  1.1  riastrad 				break;
   7992  1.1  riastrad 			}
   7993  1.1  riastrad 			break;
   7994  1.1  riastrad 		case 176: /* GFX RB CP_INT */
   7995  1.1  riastrad 		case 177: /* GFX IB CP_INT */
   7996  1.1  riastrad 			radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
   7997  1.1  riastrad 			break;
   7998  1.1  riastrad 		case 181: /* CP EOP event */
   7999  1.1  riastrad 			DRM_DEBUG("IH: CP EOP\n");
   8000  1.1  riastrad 			/* XXX check the bitfield order! */
   8001  1.1  riastrad 			me_id = (ring_id & 0x60) >> 5;
   8002  1.1  riastrad 			pipe_id = (ring_id & 0x18) >> 3;
   8003  1.1  riastrad 			queue_id = (ring_id & 0x7) >> 0;
   8004  1.1  riastrad 			switch (me_id) {
   8005  1.1  riastrad 			case 0:
   8006  1.1  riastrad 				radeon_fence_process(rdev, RADEON_RING_TYPE_GFX_INDEX);
   8007  1.1  riastrad 				break;
   8008  1.1  riastrad 			case 1:
   8009  1.1  riastrad 			case 2:
   8010  1.1  riastrad 				if ((cp1_ring->me == me_id) & (cp1_ring->pipe == pipe_id))
   8011  1.1  riastrad 					radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
   8012  1.1  riastrad 				if ((cp2_ring->me == me_id) & (cp2_ring->pipe == pipe_id))
   8013  1.1  riastrad 					radeon_fence_process(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
   8014  1.1  riastrad 				break;
   8015  1.1  riastrad 			}
   8016  1.1  riastrad 			break;
   8017  1.1  riastrad 		case 184: /* CP Privileged reg access */
   8018  1.1  riastrad 			DRM_ERROR("Illegal register access in command stream\n");
   8019  1.1  riastrad 			/* XXX check the bitfield order! */
   8020  1.1  riastrad 			me_id = (ring_id & 0x60) >> 5;
   8021  1.1  riastrad 			pipe_id = (ring_id & 0x18) >> 3;
   8022  1.1  riastrad 			queue_id = (ring_id & 0x7) >> 0;
   8023  1.1  riastrad 			switch (me_id) {
   8024  1.1  riastrad 			case 0:
   8025  1.1  riastrad 				/* This results in a full GPU reset, but all we need to do is soft
   8026  1.1  riastrad 				 * reset the CP for gfx
   8027  1.1  riastrad 				 */
   8028  1.1  riastrad 				queue_reset = true;
   8029  1.1  riastrad 				break;
   8030  1.1  riastrad 			case 1:
   8031  1.1  riastrad 				/* XXX compute */
   8032  1.1  riastrad 				queue_reset = true;
   8033  1.1  riastrad 				break;
   8034  1.1  riastrad 			case 2:
   8035  1.1  riastrad 				/* XXX compute */
   8036  1.1  riastrad 				queue_reset = true;
   8037  1.1  riastrad 				break;
   8038  1.1  riastrad 			}
   8039  1.1  riastrad 			break;
   8040  1.1  riastrad 		case 185: /* CP Privileged inst */
   8041  1.1  riastrad 			DRM_ERROR("Illegal instruction in command stream\n");
   8042  1.1  riastrad 			/* XXX check the bitfield order! */
   8043  1.1  riastrad 			me_id = (ring_id & 0x60) >> 5;
   8044  1.1  riastrad 			pipe_id = (ring_id & 0x18) >> 3;
   8045  1.1  riastrad 			queue_id = (ring_id & 0x7) >> 0;
   8046  1.1  riastrad 			switch (me_id) {
   8047  1.1  riastrad 			case 0:
   8048  1.1  riastrad 				/* This results in a full GPU reset, but all we need to do is soft
   8049  1.1  riastrad 				 * reset the CP for gfx
   8050  1.1  riastrad 				 */
   8051  1.1  riastrad 				queue_reset = true;
   8052  1.1  riastrad 				break;
   8053  1.1  riastrad 			case 1:
   8054  1.1  riastrad 				/* XXX compute */
   8055  1.1  riastrad 				queue_reset = true;
   8056  1.1  riastrad 				break;
   8057  1.1  riastrad 			case 2:
   8058  1.1  riastrad 				/* XXX compute */
   8059  1.1  riastrad 				queue_reset = true;
   8060  1.1  riastrad 				break;
   8061  1.1  riastrad 			}
   8062  1.1  riastrad 			break;
   8063  1.1  riastrad 		case 224: /* SDMA trap event */
   8064  1.1  riastrad 			/* XXX check the bitfield order! */
   8065  1.1  riastrad 			me_id = (ring_id & 0x3) >> 0;
   8066  1.1  riastrad 			queue_id = (ring_id & 0xc) >> 2;
   8067  1.1  riastrad 			DRM_DEBUG("IH: SDMA trap\n");
   8068  1.1  riastrad 			switch (me_id) {
   8069  1.1  riastrad 			case 0:
   8070  1.1  riastrad 				switch (queue_id) {
   8071  1.1  riastrad 				case 0:
   8072  1.1  riastrad 					radeon_fence_process(rdev, R600_RING_TYPE_DMA_INDEX);
   8073  1.1  riastrad 					break;
   8074  1.1  riastrad 				case 1:
   8075  1.1  riastrad 					/* XXX compute */
   8076  1.1  riastrad 					break;
   8077  1.1  riastrad 				case 2:
   8078  1.1  riastrad 					/* XXX compute */
   8079  1.1  riastrad 					break;
   8080  1.1  riastrad 				}
   8081  1.1  riastrad 				break;
   8082  1.1  riastrad 			case 1:
   8083  1.1  riastrad 				switch (queue_id) {
   8084  1.1  riastrad 				case 0:
   8085  1.1  riastrad 					radeon_fence_process(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
   8086  1.1  riastrad 					break;
   8087  1.1  riastrad 				case 1:
   8088  1.1  riastrad 					/* XXX compute */
   8089  1.1  riastrad 					break;
   8090  1.1  riastrad 				case 2:
   8091  1.1  riastrad 					/* XXX compute */
   8092  1.1  riastrad 					break;
   8093  1.1  riastrad 				}
   8094  1.1  riastrad 				break;
   8095  1.1  riastrad 			}
   8096  1.1  riastrad 			break;
   8097  1.1  riastrad 		case 230: /* thermal low to high */
   8098  1.1  riastrad 			DRM_DEBUG("IH: thermal low to high\n");
   8099  1.1  riastrad 			rdev->pm.dpm.thermal.high_to_low = false;
   8100  1.1  riastrad 			queue_thermal = true;
   8101  1.1  riastrad 			break;
   8102  1.1  riastrad 		case 231: /* thermal high to low */
   8103  1.1  riastrad 			DRM_DEBUG("IH: thermal high to low\n");
   8104  1.1  riastrad 			rdev->pm.dpm.thermal.high_to_low = true;
   8105  1.1  riastrad 			queue_thermal = true;
   8106  1.1  riastrad 			break;
   8107  1.1  riastrad 		case 233: /* GUI IDLE */
   8108  1.1  riastrad 			DRM_DEBUG("IH: GUI idle\n");
   8109  1.1  riastrad 			break;
   8110  1.1  riastrad 		case 241: /* SDMA Privileged inst */
   8111  1.1  riastrad 		case 247: /* SDMA Privileged inst */
   8112  1.1  riastrad 			DRM_ERROR("Illegal instruction in SDMA command stream\n");
   8113  1.1  riastrad 			/* XXX check the bitfield order! */
   8114  1.1  riastrad 			me_id = (ring_id & 0x3) >> 0;
   8115  1.1  riastrad 			queue_id = (ring_id & 0xc) >> 2;
   8116  1.1  riastrad 			switch (me_id) {
   8117  1.1  riastrad 			case 0:
   8118  1.1  riastrad 				switch (queue_id) {
   8119  1.1  riastrad 				case 0:
   8120  1.1  riastrad 					queue_reset = true;
   8121  1.1  riastrad 					break;
   8122  1.1  riastrad 				case 1:
   8123  1.1  riastrad 					/* XXX compute */
   8124  1.1  riastrad 					queue_reset = true;
   8125  1.1  riastrad 					break;
   8126  1.1  riastrad 				case 2:
   8127  1.1  riastrad 					/* XXX compute */
   8128  1.1  riastrad 					queue_reset = true;
   8129  1.1  riastrad 					break;
   8130  1.1  riastrad 				}
   8131  1.1  riastrad 				break;
   8132  1.1  riastrad 			case 1:
   8133  1.1  riastrad 				switch (queue_id) {
   8134  1.1  riastrad 				case 0:
   8135  1.1  riastrad 					queue_reset = true;
   8136  1.1  riastrad 					break;
   8137  1.1  riastrad 				case 1:
   8138  1.1  riastrad 					/* XXX compute */
   8139  1.1  riastrad 					queue_reset = true;
   8140  1.1  riastrad 					break;
   8141  1.1  riastrad 				case 2:
   8142  1.1  riastrad 					/* XXX compute */
   8143  1.1  riastrad 					queue_reset = true;
   8144  1.1  riastrad 					break;
   8145  1.1  riastrad 				}
   8146  1.1  riastrad 				break;
   8147  1.1  riastrad 			}
   8148  1.1  riastrad 			break;
   8149  1.1  riastrad 		default:
   8150  1.1  riastrad 			DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
   8151  1.1  riastrad 			break;
   8152  1.1  riastrad 		}
   8153  1.1  riastrad 
   8154  1.1  riastrad 		/* wptr/rptr are in bytes! */
   8155  1.1  riastrad 		rptr += 16;
   8156  1.1  riastrad 		rptr &= rdev->ih.ptr_mask;
   8157  1.1  riastrad 		WREG32(IH_RB_RPTR, rptr);
   8158  1.1  riastrad 	}
   8159  1.1  riastrad 	if (queue_dp)
   8160  1.1  riastrad 		schedule_work(&rdev->dp_work);
   8161  1.1  riastrad 	if (queue_hotplug)
   8162  1.1  riastrad 		schedule_delayed_work(&rdev->hotplug_work, 0);
   8163  1.1  riastrad 	if (queue_reset) {
   8164  1.1  riastrad #ifdef __NetBSD__
   8165  1.1  riastrad 		spin_lock(&rdev->fence_lock);
   8166  1.1  riastrad 		rdev->needs_reset = true;
   8167  1.1  riastrad 		radeon_fence_wakeup_locked(rdev);
   8168  1.1  riastrad 		spin_unlock(&rdev->fence_lock);
   8169  1.1  riastrad #else
   8170  1.1  riastrad 		rdev->needs_reset = true;
   8171  1.1  riastrad 		wake_up_all(&rdev->fence_queue);
   8172  1.1  riastrad #endif
   8173  1.1  riastrad 	}
   8174  1.1  riastrad 	if (queue_thermal)
   8175  1.1  riastrad 		schedule_work(&rdev->pm.dpm.thermal.work);
   8176  1.1  riastrad 	rdev->ih.rptr = rptr;
   8177  1.1  riastrad 	atomic_set(&rdev->ih.lock, 0);
   8178  1.1  riastrad 
   8179  1.1  riastrad 	/* make sure wptr hasn't changed while processing */
   8180  1.1  riastrad 	wptr = cik_get_ih_wptr(rdev);
   8181  1.1  riastrad 	if (wptr != rptr)
   8182  1.1  riastrad 		goto restart_ih;
   8183  1.1  riastrad 
   8184  1.1  riastrad 	return IRQ_HANDLED;
   8185  1.1  riastrad }
   8186  1.1  riastrad 
   8187  1.1  riastrad /*
   8188  1.1  riastrad  * startup/shutdown callbacks
   8189  1.1  riastrad  */
   8190  1.3  riastrad static void cik_uvd_init(struct radeon_device *rdev)
   8191  1.3  riastrad {
   8192  1.3  riastrad 	int r;
   8193  1.3  riastrad 
   8194  1.3  riastrad 	if (!rdev->has_uvd)
   8195  1.3  riastrad 		return;
   8196  1.3  riastrad 
   8197  1.3  riastrad 	r = radeon_uvd_init(rdev);
   8198  1.3  riastrad 	if (r) {
   8199  1.3  riastrad 		dev_err(rdev->dev, "failed UVD (%d) init.\n", r);
   8200  1.3  riastrad 		/*
   8201  1.3  riastrad 		 * At this point rdev->uvd.vcpu_bo is NULL which trickles down
   8202  1.3  riastrad 		 * to early fails cik_uvd_start() and thus nothing happens
   8203  1.3  riastrad 		 * there. So it is pointless to try to go through that code
   8204  1.3  riastrad 		 * hence why we disable uvd here.
   8205  1.3  riastrad 		 */
   8206  1.3  riastrad 		rdev->has_uvd = false;
   8207  1.3  riastrad 		return;
   8208  1.3  riastrad 	}
   8209  1.3  riastrad 	rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
   8210  1.3  riastrad 	r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX], 4096);
   8211  1.3  riastrad }
   8212  1.3  riastrad 
   8213  1.3  riastrad static void cik_uvd_start(struct radeon_device *rdev)
   8214  1.3  riastrad {
   8215  1.3  riastrad 	int r;
   8216  1.3  riastrad 
   8217  1.3  riastrad 	if (!rdev->has_uvd)
   8218  1.3  riastrad 		return;
   8219  1.3  riastrad 
   8220  1.3  riastrad 	r = radeon_uvd_resume(rdev);
   8221  1.3  riastrad 	if (r) {
   8222  1.3  riastrad 		dev_err(rdev->dev, "failed UVD resume (%d).\n", r);
   8223  1.3  riastrad 		goto error;
   8224  1.3  riastrad 	}
   8225  1.3  riastrad 	r = uvd_v4_2_resume(rdev);
   8226  1.3  riastrad 	if (r) {
   8227  1.3  riastrad 		dev_err(rdev->dev, "failed UVD 4.2 resume (%d).\n", r);
   8228  1.3  riastrad 		goto error;
   8229  1.3  riastrad 	}
   8230  1.3  riastrad 	r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_UVD_INDEX);
   8231  1.3  riastrad 	if (r) {
   8232  1.3  riastrad 		dev_err(rdev->dev, "failed initializing UVD fences (%d).\n", r);
   8233  1.3  riastrad 		goto error;
   8234  1.3  riastrad 	}
   8235  1.3  riastrad 	return;
   8236  1.3  riastrad 
   8237  1.3  riastrad error:
   8238  1.3  riastrad 	rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
   8239  1.3  riastrad }
   8240  1.3  riastrad 
   8241  1.3  riastrad static void cik_uvd_resume(struct radeon_device *rdev)
   8242  1.3  riastrad {
   8243  1.3  riastrad 	struct radeon_ring *ring;
   8244  1.3  riastrad 	int r;
   8245  1.3  riastrad 
   8246  1.3  riastrad 	if (!rdev->has_uvd || !rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size)
   8247  1.3  riastrad 		return;
   8248  1.3  riastrad 
   8249  1.3  riastrad 	ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
   8250  1.3  riastrad 	r = radeon_ring_init(rdev, ring, ring->ring_size, 0, PACKET0(UVD_NO_OP, 0));
   8251  1.3  riastrad 	if (r) {
   8252  1.3  riastrad 		dev_err(rdev->dev, "failed initializing UVD ring (%d).\n", r);
   8253  1.3  riastrad 		return;
   8254  1.3  riastrad 	}
   8255  1.3  riastrad 	r = uvd_v1_0_init(rdev);
   8256  1.3  riastrad 	if (r) {
   8257  1.3  riastrad 		dev_err(rdev->dev, "failed initializing UVD (%d).\n", r);
   8258  1.3  riastrad 		return;
   8259  1.3  riastrad 	}
   8260  1.3  riastrad }
   8261  1.3  riastrad 
   8262  1.3  riastrad static void cik_vce_init(struct radeon_device *rdev)
   8263  1.3  riastrad {
   8264  1.3  riastrad 	int r;
   8265  1.3  riastrad 
   8266  1.3  riastrad 	if (!rdev->has_vce)
   8267  1.3  riastrad 		return;
   8268  1.3  riastrad 
   8269  1.3  riastrad 	r = radeon_vce_init(rdev);
   8270  1.3  riastrad 	if (r) {
   8271  1.3  riastrad 		dev_err(rdev->dev, "failed VCE (%d) init.\n", r);
   8272  1.3  riastrad 		/*
   8273  1.3  riastrad 		 * At this point rdev->vce.vcpu_bo is NULL which trickles down
   8274  1.3  riastrad 		 * to early fails cik_vce_start() and thus nothing happens
   8275  1.3  riastrad 		 * there. So it is pointless to try to go through that code
   8276  1.3  riastrad 		 * hence why we disable vce here.
   8277  1.3  riastrad 		 */
   8278  1.3  riastrad 		rdev->has_vce = false;
   8279  1.3  riastrad 		return;
   8280  1.3  riastrad 	}
   8281  1.3  riastrad 	rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_obj = NULL;
   8282  1.3  riastrad 	r600_ring_init(rdev, &rdev->ring[TN_RING_TYPE_VCE1_INDEX], 4096);
   8283  1.3  riastrad 	rdev->ring[TN_RING_TYPE_VCE2_INDEX].ring_obj = NULL;
   8284  1.3  riastrad 	r600_ring_init(rdev, &rdev->ring[TN_RING_TYPE_VCE2_INDEX], 4096);
   8285  1.3  riastrad }
   8286  1.3  riastrad 
   8287  1.3  riastrad static void cik_vce_start(struct radeon_device *rdev)
   8288  1.3  riastrad {
   8289  1.3  riastrad 	int r;
   8290  1.3  riastrad 
   8291  1.3  riastrad 	if (!rdev->has_vce)
   8292  1.3  riastrad 		return;
   8293  1.3  riastrad 
   8294  1.3  riastrad 	r = radeon_vce_resume(rdev);
   8295  1.3  riastrad 	if (r) {
   8296  1.3  riastrad 		dev_err(rdev->dev, "failed VCE resume (%d).\n", r);
   8297  1.3  riastrad 		goto error;
   8298  1.3  riastrad 	}
   8299  1.3  riastrad 	r = vce_v2_0_resume(rdev);
   8300  1.3  riastrad 	if (r) {
   8301  1.3  riastrad 		dev_err(rdev->dev, "failed VCE resume (%d).\n", r);
   8302  1.3  riastrad 		goto error;
   8303  1.3  riastrad 	}
   8304  1.3  riastrad 	r = radeon_fence_driver_start_ring(rdev, TN_RING_TYPE_VCE1_INDEX);
   8305  1.3  riastrad 	if (r) {
   8306  1.3  riastrad 		dev_err(rdev->dev, "failed initializing VCE1 fences (%d).\n", r);
   8307  1.3  riastrad 		goto error;
   8308  1.3  riastrad 	}
   8309  1.3  riastrad 	r = radeon_fence_driver_start_ring(rdev, TN_RING_TYPE_VCE2_INDEX);
   8310  1.3  riastrad 	if (r) {
   8311  1.3  riastrad 		dev_err(rdev->dev, "failed initializing VCE2 fences (%d).\n", r);
   8312  1.3  riastrad 		goto error;
   8313  1.3  riastrad 	}
   8314  1.3  riastrad 	return;
   8315  1.3  riastrad 
   8316  1.3  riastrad error:
   8317  1.3  riastrad 	rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_size = 0;
   8318  1.3  riastrad 	rdev->ring[TN_RING_TYPE_VCE2_INDEX].ring_size = 0;
   8319  1.3  riastrad }
   8320  1.3  riastrad 
   8321  1.3  riastrad static void cik_vce_resume(struct radeon_device *rdev)
   8322  1.3  riastrad {
   8323  1.3  riastrad 	struct radeon_ring *ring;
   8324  1.3  riastrad 	int r;
   8325  1.3  riastrad 
   8326  1.3  riastrad 	if (!rdev->has_vce || !rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_size)
   8327  1.3  riastrad 		return;
   8328  1.3  riastrad 
   8329  1.3  riastrad 	ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
   8330  1.3  riastrad 	r = radeon_ring_init(rdev, ring, ring->ring_size, 0, VCE_CMD_NO_OP);
   8331  1.3  riastrad 	if (r) {
   8332  1.3  riastrad 		dev_err(rdev->dev, "failed initializing VCE1 ring (%d).\n", r);
   8333  1.3  riastrad 		return;
   8334  1.3  riastrad 	}
   8335  1.3  riastrad 	ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
   8336  1.3  riastrad 	r = radeon_ring_init(rdev, ring, ring->ring_size, 0, VCE_CMD_NO_OP);
   8337  1.3  riastrad 	if (r) {
   8338  1.3  riastrad 		dev_err(rdev->dev, "failed initializing VCE1 ring (%d).\n", r);
   8339  1.3  riastrad 		return;
   8340  1.3  riastrad 	}
   8341  1.3  riastrad 	r = vce_v1_0_init(rdev);
   8342  1.3  riastrad 	if (r) {
   8343  1.3  riastrad 		dev_err(rdev->dev, "failed initializing VCE (%d).\n", r);
   8344  1.3  riastrad 		return;
   8345  1.3  riastrad 	}
   8346  1.3  riastrad }
   8347  1.3  riastrad 
   8348  1.1  riastrad /**
   8349  1.1  riastrad  * cik_startup - program the asic to a functional state
   8350  1.1  riastrad  *
   8351  1.1  riastrad  * @rdev: radeon_device pointer
   8352  1.1  riastrad  *
   8353  1.1  riastrad  * Programs the asic to a functional state (CIK).
   8354  1.1  riastrad  * Called by cik_init() and cik_resume().
   8355  1.1  riastrad  * Returns 0 for success, error for failure.
   8356  1.1  riastrad  */
   8357  1.1  riastrad static int cik_startup(struct radeon_device *rdev)
   8358  1.1  riastrad {
   8359  1.1  riastrad 	struct radeon_ring *ring;
   8360  1.1  riastrad 	u32 nop;
   8361  1.1  riastrad 	int r;
   8362  1.1  riastrad 
   8363  1.1  riastrad 	/* enable pcie gen2/3 link */
   8364  1.1  riastrad 	cik_pcie_gen3_enable(rdev);
   8365  1.1  riastrad 	/* enable aspm */
   8366  1.1  riastrad 	cik_program_aspm(rdev);
   8367  1.1  riastrad 
   8368  1.1  riastrad 	/* scratch needs to be initialized before MC */
   8369  1.1  riastrad 	r = r600_vram_scratch_init(rdev);
   8370  1.1  riastrad 	if (r)
   8371  1.1  riastrad 		return r;
   8372  1.1  riastrad 
   8373  1.1  riastrad 	cik_mc_program(rdev);
   8374  1.1  riastrad 
   8375  1.1  riastrad 	if (!(rdev->flags & RADEON_IS_IGP) && !rdev->pm.dpm_enabled) {
   8376  1.1  riastrad 		r = ci_mc_load_microcode(rdev);
   8377  1.1  riastrad 		if (r) {
   8378  1.1  riastrad 			DRM_ERROR("Failed to load MC firmware!\n");
   8379  1.1  riastrad 			return r;
   8380  1.1  riastrad 		}
   8381  1.1  riastrad 	}
   8382  1.1  riastrad 
   8383  1.1  riastrad 	r = cik_pcie_gart_enable(rdev);
   8384  1.1  riastrad 	if (r)
   8385  1.1  riastrad 		return r;
   8386  1.1  riastrad 	cik_gpu_init(rdev);
   8387  1.1  riastrad 
   8388  1.1  riastrad 	/* allocate rlc buffers */
   8389  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP) {
   8390  1.1  riastrad 		if (rdev->family == CHIP_KAVERI) {
   8391  1.1  riastrad 			rdev->rlc.reg_list = spectre_rlc_save_restore_register_list;
   8392  1.1  riastrad 			rdev->rlc.reg_list_size =
   8393  1.1  riastrad 				(u32)ARRAY_SIZE(spectre_rlc_save_restore_register_list);
   8394  1.1  riastrad 		} else {
   8395  1.1  riastrad 			rdev->rlc.reg_list = kalindi_rlc_save_restore_register_list;
   8396  1.1  riastrad 			rdev->rlc.reg_list_size =
   8397  1.1  riastrad 				(u32)ARRAY_SIZE(kalindi_rlc_save_restore_register_list);
   8398  1.1  riastrad 		}
   8399  1.1  riastrad 	}
   8400  1.1  riastrad 	rdev->rlc.cs_data = ci_cs_data;
   8401  1.4  riastrad 	rdev->rlc.cp_table_size = round_up(CP_ME_TABLE_SIZE * 5 * 4, 2048); /* CP JT */
   8402  1.3  riastrad 	rdev->rlc.cp_table_size += 64 * 1024; /* GDS */
   8403  1.1  riastrad 	r = sumo_rlc_init(rdev);
   8404  1.1  riastrad 	if (r) {
   8405  1.1  riastrad 		DRM_ERROR("Failed to init rlc BOs!\n");
   8406  1.1  riastrad 		return r;
   8407  1.1  riastrad 	}
   8408  1.1  riastrad 
   8409  1.1  riastrad 	/* allocate wb buffer */
   8410  1.1  riastrad 	r = radeon_wb_init(rdev);
   8411  1.1  riastrad 	if (r)
   8412  1.1  riastrad 		return r;
   8413  1.1  riastrad 
   8414  1.1  riastrad 	/* allocate mec buffers */
   8415  1.1  riastrad 	r = cik_mec_init(rdev);
   8416  1.1  riastrad 	if (r) {
   8417  1.1  riastrad 		DRM_ERROR("Failed to init MEC BOs!\n");
   8418  1.1  riastrad 		return r;
   8419  1.1  riastrad 	}
   8420  1.1  riastrad 
   8421  1.1  riastrad 	r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
   8422  1.1  riastrad 	if (r) {
   8423  1.1  riastrad 		dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
   8424  1.1  riastrad 		return r;
   8425  1.1  riastrad 	}
   8426  1.1  riastrad 
   8427  1.1  riastrad 	r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
   8428  1.1  riastrad 	if (r) {
   8429  1.1  riastrad 		dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
   8430  1.1  riastrad 		return r;
   8431  1.1  riastrad 	}
   8432  1.1  riastrad 
   8433  1.1  riastrad 	r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
   8434  1.1  riastrad 	if (r) {
   8435  1.1  riastrad 		dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
   8436  1.1  riastrad 		return r;
   8437  1.1  riastrad 	}
   8438  1.1  riastrad 
   8439  1.1  riastrad 	r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
   8440  1.1  riastrad 	if (r) {
   8441  1.1  riastrad 		dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
   8442  1.1  riastrad 		return r;
   8443  1.1  riastrad 	}
   8444  1.1  riastrad 
   8445  1.1  riastrad 	r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
   8446  1.1  riastrad 	if (r) {
   8447  1.1  riastrad 		dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
   8448  1.1  riastrad 		return r;
   8449  1.1  riastrad 	}
   8450  1.1  riastrad 
   8451  1.3  riastrad 	cik_uvd_start(rdev);
   8452  1.3  riastrad 	cik_vce_start(rdev);
   8453  1.1  riastrad 
   8454  1.1  riastrad 	/* Enable IRQ */
   8455  1.1  riastrad 	if (!rdev->irq.installed) {
   8456  1.1  riastrad 		r = radeon_irq_kms_init(rdev);
   8457  1.1  riastrad 		if (r)
   8458  1.1  riastrad 			return r;
   8459  1.1  riastrad 	}
   8460  1.1  riastrad 
   8461  1.1  riastrad 	r = cik_irq_init(rdev);
   8462  1.1  riastrad 	if (r) {
   8463  1.1  riastrad 		DRM_ERROR("radeon: IH init failed (%d).\n", r);
   8464  1.1  riastrad 		radeon_irq_kms_fini(rdev);
   8465  1.1  riastrad 		return r;
   8466  1.1  riastrad 	}
   8467  1.1  riastrad 	cik_irq_set(rdev);
   8468  1.1  riastrad 
   8469  1.1  riastrad 	if (rdev->family == CHIP_HAWAII) {
   8470  1.1  riastrad 		if (rdev->new_fw)
   8471  1.1  riastrad 			nop = PACKET3(PACKET3_NOP, 0x3FFF);
   8472  1.1  riastrad 		else
   8473  1.1  riastrad 			nop = RADEON_CP_PACKET2;
   8474  1.1  riastrad 	} else {
   8475  1.1  riastrad 		nop = PACKET3(PACKET3_NOP, 0x3FFF);
   8476  1.1  riastrad 	}
   8477  1.1  riastrad 
   8478  1.1  riastrad 	ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
   8479  1.1  riastrad 	r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
   8480  1.1  riastrad 			     nop);
   8481  1.1  riastrad 	if (r)
   8482  1.1  riastrad 		return r;
   8483  1.1  riastrad 
   8484  1.1  riastrad 	/* set up the compute queues */
   8485  1.1  riastrad 	/* type-2 packets are deprecated on MEC, use type-3 instead */
   8486  1.1  riastrad 	ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
   8487  1.1  riastrad 	r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP1_RPTR_OFFSET,
   8488  1.1  riastrad 			     nop);
   8489  1.1  riastrad 	if (r)
   8490  1.1  riastrad 		return r;
   8491  1.1  riastrad 	ring->me = 1; /* first MEC */
   8492  1.1  riastrad 	ring->pipe = 0; /* first pipe */
   8493  1.1  riastrad 	ring->queue = 0; /* first queue */
   8494  1.1  riastrad 	ring->wptr_offs = CIK_WB_CP1_WPTR_OFFSET;
   8495  1.1  riastrad 
   8496  1.1  riastrad 	/* type-2 packets are deprecated on MEC, use type-3 instead */
   8497  1.1  riastrad 	ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
   8498  1.1  riastrad 	r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP2_RPTR_OFFSET,
   8499  1.1  riastrad 			     nop);
   8500  1.1  riastrad 	if (r)
   8501  1.1  riastrad 		return r;
   8502  1.1  riastrad 	/* dGPU only have 1 MEC */
   8503  1.1  riastrad 	ring->me = 1; /* first MEC */
   8504  1.1  riastrad 	ring->pipe = 0; /* first pipe */
   8505  1.1  riastrad 	ring->queue = 1; /* second queue */
   8506  1.1  riastrad 	ring->wptr_offs = CIK_WB_CP2_WPTR_OFFSET;
   8507  1.1  riastrad 
   8508  1.1  riastrad 	ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
   8509  1.1  riastrad 	r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
   8510  1.1  riastrad 			     SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
   8511  1.1  riastrad 	if (r)
   8512  1.1  riastrad 		return r;
   8513  1.1  riastrad 
   8514  1.1  riastrad 	ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
   8515  1.1  riastrad 	r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
   8516  1.1  riastrad 			     SDMA_PACKET(SDMA_OPCODE_NOP, 0, 0));
   8517  1.1  riastrad 	if (r)
   8518  1.1  riastrad 		return r;
   8519  1.1  riastrad 
   8520  1.1  riastrad 	r = cik_cp_resume(rdev);
   8521  1.1  riastrad 	if (r)
   8522  1.1  riastrad 		return r;
   8523  1.1  riastrad 
   8524  1.1  riastrad 	r = cik_sdma_resume(rdev);
   8525  1.1  riastrad 	if (r)
   8526  1.1  riastrad 		return r;
   8527  1.1  riastrad 
   8528  1.3  riastrad 	cik_uvd_resume(rdev);
   8529  1.3  riastrad 	cik_vce_resume(rdev);
   8530  1.1  riastrad 
   8531  1.1  riastrad 	r = radeon_ib_pool_init(rdev);
   8532  1.1  riastrad 	if (r) {
   8533  1.1  riastrad 		dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
   8534  1.1  riastrad 		return r;
   8535  1.1  riastrad 	}
   8536  1.1  riastrad 
   8537  1.1  riastrad 	r = radeon_vm_manager_init(rdev);
   8538  1.1  riastrad 	if (r) {
   8539  1.1  riastrad 		dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
   8540  1.1  riastrad 		return r;
   8541  1.1  riastrad 	}
   8542  1.1  riastrad 
   8543  1.1  riastrad 	r = radeon_audio_init(rdev);
   8544  1.1  riastrad 	if (r)
   8545  1.1  riastrad 		return r;
   8546  1.1  riastrad 
   8547  1.1  riastrad 	return 0;
   8548  1.1  riastrad }
   8549  1.1  riastrad 
   8550  1.1  riastrad /**
   8551  1.1  riastrad  * cik_resume - resume the asic to a functional state
   8552  1.1  riastrad  *
   8553  1.1  riastrad  * @rdev: radeon_device pointer
   8554  1.1  riastrad  *
   8555  1.1  riastrad  * Programs the asic to a functional state (CIK).
   8556  1.1  riastrad  * Called at resume.
   8557  1.1  riastrad  * Returns 0 for success, error for failure.
   8558  1.1  riastrad  */
   8559  1.1  riastrad int cik_resume(struct radeon_device *rdev)
   8560  1.1  riastrad {
   8561  1.1  riastrad 	int r;
   8562  1.1  riastrad 
   8563  1.1  riastrad 	/* post card */
   8564  1.1  riastrad 	atom_asic_init(rdev->mode_info.atom_context);
   8565  1.1  riastrad 
   8566  1.1  riastrad 	/* init golden registers */
   8567  1.1  riastrad 	cik_init_golden_registers(rdev);
   8568  1.1  riastrad 
   8569  1.1  riastrad 	if (rdev->pm.pm_method == PM_METHOD_DPM)
   8570  1.1  riastrad 		radeon_pm_resume(rdev);
   8571  1.1  riastrad 
   8572  1.1  riastrad 	rdev->accel_working = true;
   8573  1.1  riastrad 	r = cik_startup(rdev);
   8574  1.1  riastrad 	if (r) {
   8575  1.1  riastrad 		DRM_ERROR("cik startup failed on resume\n");
   8576  1.1  riastrad 		rdev->accel_working = false;
   8577  1.1  riastrad 		return r;
   8578  1.1  riastrad 	}
   8579  1.1  riastrad 
   8580  1.1  riastrad 	return r;
   8581  1.1  riastrad 
   8582  1.1  riastrad }
   8583  1.1  riastrad 
   8584  1.1  riastrad /**
   8585  1.1  riastrad  * cik_suspend - suspend the asic
   8586  1.1  riastrad  *
   8587  1.1  riastrad  * @rdev: radeon_device pointer
   8588  1.1  riastrad  *
   8589  1.1  riastrad  * Bring the chip into a state suitable for suspend (CIK).
   8590  1.1  riastrad  * Called at suspend.
   8591  1.1  riastrad  * Returns 0 for success.
   8592  1.1  riastrad  */
   8593  1.1  riastrad int cik_suspend(struct radeon_device *rdev)
   8594  1.1  riastrad {
   8595  1.1  riastrad 	radeon_pm_suspend(rdev);
   8596  1.1  riastrad 	radeon_audio_fini(rdev);
   8597  1.1  riastrad 	radeon_vm_manager_fini(rdev);
   8598  1.1  riastrad 	cik_cp_enable(rdev, false);
   8599  1.1  riastrad 	cik_sdma_enable(rdev, false);
   8600  1.3  riastrad 	if (rdev->has_uvd) {
   8601  1.3  riastrad 		uvd_v1_0_fini(rdev);
   8602  1.3  riastrad 		radeon_uvd_suspend(rdev);
   8603  1.3  riastrad 	}
   8604  1.3  riastrad 	if (rdev->has_vce)
   8605  1.3  riastrad 		radeon_vce_suspend(rdev);
   8606  1.1  riastrad 	cik_fini_pg(rdev);
   8607  1.1  riastrad 	cik_fini_cg(rdev);
   8608  1.1  riastrad 	cik_irq_suspend(rdev);
   8609  1.1  riastrad 	radeon_wb_disable(rdev);
   8610  1.1  riastrad 	cik_pcie_gart_disable(rdev);
   8611  1.1  riastrad 	return 0;
   8612  1.1  riastrad }
   8613  1.1  riastrad 
   8614  1.1  riastrad /* Plan is to move initialization in that function and use
   8615  1.1  riastrad  * helper function so that radeon_device_init pretty much
   8616  1.1  riastrad  * do nothing more than calling asic specific function. This
   8617  1.1  riastrad  * should also allow to remove a bunch of callback function
   8618  1.1  riastrad  * like vram_info.
   8619  1.1  riastrad  */
   8620  1.1  riastrad /**
   8621  1.1  riastrad  * cik_init - asic specific driver and hw init
   8622  1.1  riastrad  *
   8623  1.1  riastrad  * @rdev: radeon_device pointer
   8624  1.1  riastrad  *
   8625  1.1  riastrad  * Setup asic specific driver variables and program the hw
   8626  1.1  riastrad  * to a functional state (CIK).
   8627  1.1  riastrad  * Called at driver startup.
   8628  1.1  riastrad  * Returns 0 for success, errors for failure.
   8629  1.1  riastrad  */
   8630  1.1  riastrad int cik_init(struct radeon_device *rdev)
   8631  1.1  riastrad {
   8632  1.1  riastrad 	struct radeon_ring *ring;
   8633  1.1  riastrad 	int r;
   8634  1.1  riastrad 
   8635  1.1  riastrad 	/* Read BIOS */
   8636  1.1  riastrad 	if (!radeon_get_bios(rdev)) {
   8637  1.1  riastrad 		if (ASIC_IS_AVIVO(rdev))
   8638  1.1  riastrad 			return -EINVAL;
   8639  1.1  riastrad 	}
   8640  1.1  riastrad 	/* Must be an ATOMBIOS */
   8641  1.1  riastrad 	if (!rdev->is_atom_bios) {
   8642  1.1  riastrad 		dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
   8643  1.1  riastrad 		return -EINVAL;
   8644  1.1  riastrad 	}
   8645  1.1  riastrad 	r = radeon_atombios_init(rdev);
   8646  1.1  riastrad 	if (r)
   8647  1.1  riastrad 		return r;
   8648  1.1  riastrad 
   8649  1.1  riastrad 	/* Post card if necessary */
   8650  1.1  riastrad 	if (!radeon_card_posted(rdev)) {
   8651  1.1  riastrad 		if (!rdev->bios) {
   8652  1.1  riastrad 			dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
   8653  1.1  riastrad 			return -EINVAL;
   8654  1.1  riastrad 		}
   8655  1.1  riastrad 		DRM_INFO("GPU not posted. posting now...\n");
   8656  1.1  riastrad 		atom_asic_init(rdev->mode_info.atom_context);
   8657  1.1  riastrad 	}
   8658  1.1  riastrad 	/* init golden registers */
   8659  1.1  riastrad 	cik_init_golden_registers(rdev);
   8660  1.1  riastrad 	/* Initialize scratch registers */
   8661  1.1  riastrad 	cik_scratch_init(rdev);
   8662  1.1  riastrad 	/* Initialize surface registers */
   8663  1.1  riastrad 	radeon_surface_init(rdev);
   8664  1.1  riastrad 	/* Initialize clocks */
   8665  1.1  riastrad 	radeon_get_clock_info(rdev->ddev);
   8666  1.1  riastrad 
   8667  1.1  riastrad 	/* Fence driver */
   8668  1.1  riastrad 	r = radeon_fence_driver_init(rdev);
   8669  1.1  riastrad 	if (r)
   8670  1.1  riastrad 		return r;
   8671  1.1  riastrad 
   8672  1.1  riastrad 	/* initialize memory controller */
   8673  1.1  riastrad 	r = cik_mc_init(rdev);
   8674  1.1  riastrad 	if (r)
   8675  1.1  riastrad 		return r;
   8676  1.1  riastrad 	/* Memory manager */
   8677  1.1  riastrad 	r = radeon_bo_init(rdev);
   8678  1.1  riastrad 	if (r)
   8679  1.1  riastrad 		return r;
   8680  1.1  riastrad 
   8681  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP) {
   8682  1.1  riastrad 		if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
   8683  1.1  riastrad 		    !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw) {
   8684  1.1  riastrad 			r = cik_init_microcode(rdev);
   8685  1.1  riastrad 			if (r) {
   8686  1.1  riastrad 				DRM_ERROR("Failed to load firmware!\n");
   8687  1.1  riastrad 				return r;
   8688  1.1  riastrad 			}
   8689  1.1  riastrad 		}
   8690  1.1  riastrad 	} else {
   8691  1.1  riastrad 		if (!rdev->me_fw || !rdev->pfp_fw || !rdev->ce_fw ||
   8692  1.1  riastrad 		    !rdev->mec_fw || !rdev->sdma_fw || !rdev->rlc_fw ||
   8693  1.1  riastrad 		    !rdev->mc_fw) {
   8694  1.1  riastrad 			r = cik_init_microcode(rdev);
   8695  1.1  riastrad 			if (r) {
   8696  1.1  riastrad 				DRM_ERROR("Failed to load firmware!\n");
   8697  1.1  riastrad 				return r;
   8698  1.1  riastrad 			}
   8699  1.1  riastrad 		}
   8700  1.1  riastrad 	}
   8701  1.1  riastrad 
   8702  1.1  riastrad 	/* Initialize power management */
   8703  1.1  riastrad 	radeon_pm_init(rdev);
   8704  1.1  riastrad 
   8705  1.1  riastrad 	ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
   8706  1.1  riastrad 	ring->ring_obj = NULL;
   8707  1.1  riastrad 	r600_ring_init(rdev, ring, 1024 * 1024);
   8708  1.1  riastrad 
   8709  1.1  riastrad 	ring = &rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX];
   8710  1.1  riastrad 	ring->ring_obj = NULL;
   8711  1.1  riastrad 	r600_ring_init(rdev, ring, 1024 * 1024);
   8712  1.1  riastrad 	r = radeon_doorbell_get(rdev, &ring->doorbell_index);
   8713  1.1  riastrad 	if (r)
   8714  1.1  riastrad 		return r;
   8715  1.1  riastrad 
   8716  1.1  riastrad 	ring = &rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX];
   8717  1.1  riastrad 	ring->ring_obj = NULL;
   8718  1.1  riastrad 	r600_ring_init(rdev, ring, 1024 * 1024);
   8719  1.1  riastrad 	r = radeon_doorbell_get(rdev, &ring->doorbell_index);
   8720  1.1  riastrad 	if (r)
   8721  1.1  riastrad 		return r;
   8722  1.1  riastrad 
   8723  1.1  riastrad 	ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
   8724  1.1  riastrad 	ring->ring_obj = NULL;
   8725  1.1  riastrad 	r600_ring_init(rdev, ring, 256 * 1024);
   8726  1.1  riastrad 
   8727  1.1  riastrad 	ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
   8728  1.1  riastrad 	ring->ring_obj = NULL;
   8729  1.1  riastrad 	r600_ring_init(rdev, ring, 256 * 1024);
   8730  1.1  riastrad 
   8731  1.3  riastrad 	cik_uvd_init(rdev);
   8732  1.3  riastrad 	cik_vce_init(rdev);
   8733  1.1  riastrad 
   8734  1.1  riastrad 	rdev->ih.ring_obj = NULL;
   8735  1.1  riastrad 	r600_ih_ring_init(rdev, 64 * 1024);
   8736  1.1  riastrad 
   8737  1.1  riastrad 	r = r600_pcie_gart_init(rdev);
   8738  1.1  riastrad 	if (r)
   8739  1.1  riastrad 		return r;
   8740  1.1  riastrad 
   8741  1.1  riastrad 	rdev->accel_working = true;
   8742  1.1  riastrad 	r = cik_startup(rdev);
   8743  1.1  riastrad 	if (r) {
   8744  1.1  riastrad 		dev_err(rdev->dev, "disabling GPU acceleration\n");
   8745  1.1  riastrad 		cik_cp_fini(rdev);
   8746  1.1  riastrad 		cik_sdma_fini(rdev);
   8747  1.1  riastrad 		cik_irq_fini(rdev);
   8748  1.1  riastrad 		sumo_rlc_fini(rdev);
   8749  1.1  riastrad 		cik_mec_fini(rdev);
   8750  1.1  riastrad 		radeon_wb_fini(rdev);
   8751  1.1  riastrad 		radeon_ib_pool_fini(rdev);
   8752  1.1  riastrad 		radeon_vm_manager_fini(rdev);
   8753  1.1  riastrad 		radeon_irq_kms_fini(rdev);
   8754  1.1  riastrad 		cik_pcie_gart_fini(rdev);
   8755  1.1  riastrad 		rdev->accel_working = false;
   8756  1.1  riastrad 	}
   8757  1.1  riastrad 
   8758  1.1  riastrad 	/* Don't start up if the MC ucode is missing.
   8759  1.1  riastrad 	 * The default clocks and voltages before the MC ucode
   8760  1.1  riastrad 	 * is loaded are not suffient for advanced operations.
   8761  1.1  riastrad 	 */
   8762  1.1  riastrad 	if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
   8763  1.1  riastrad 		DRM_ERROR("radeon: MC ucode required for NI+.\n");
   8764  1.1  riastrad 		return -EINVAL;
   8765  1.1  riastrad 	}
   8766  1.1  riastrad 
   8767  1.1  riastrad 	return 0;
   8768  1.1  riastrad }
   8769  1.1  riastrad 
   8770  1.1  riastrad /**
   8771  1.1  riastrad  * cik_fini - asic specific driver and hw fini
   8772  1.1  riastrad  *
   8773  1.1  riastrad  * @rdev: radeon_device pointer
   8774  1.1  riastrad  *
   8775  1.1  riastrad  * Tear down the asic specific driver variables and program the hw
   8776  1.1  riastrad  * to an idle state (CIK).
   8777  1.1  riastrad  * Called at driver unload.
   8778  1.1  riastrad  */
   8779  1.1  riastrad void cik_fini(struct radeon_device *rdev)
   8780  1.1  riastrad {
   8781  1.1  riastrad 	radeon_pm_fini(rdev);
   8782  1.1  riastrad 	cik_cp_fini(rdev);
   8783  1.1  riastrad 	cik_sdma_fini(rdev);
   8784  1.1  riastrad 	cik_fini_pg(rdev);
   8785  1.1  riastrad 	cik_fini_cg(rdev);
   8786  1.1  riastrad 	cik_irq_fini(rdev);
   8787  1.1  riastrad 	sumo_rlc_fini(rdev);
   8788  1.1  riastrad 	cik_mec_fini(rdev);
   8789  1.1  riastrad 	radeon_wb_fini(rdev);
   8790  1.1  riastrad 	radeon_vm_manager_fini(rdev);
   8791  1.1  riastrad 	radeon_ib_pool_fini(rdev);
   8792  1.1  riastrad 	radeon_irq_kms_fini(rdev);
   8793  1.1  riastrad 	uvd_v1_0_fini(rdev);
   8794  1.1  riastrad 	radeon_uvd_fini(rdev);
   8795  1.1  riastrad 	radeon_vce_fini(rdev);
   8796  1.1  riastrad 	cik_pcie_gart_fini(rdev);
   8797  1.1  riastrad 	r600_vram_scratch_fini(rdev);
   8798  1.1  riastrad 	radeon_gem_fini(rdev);
   8799  1.1  riastrad 	radeon_fence_driver_fini(rdev);
   8800  1.1  riastrad 	radeon_bo_fini(rdev);
   8801  1.1  riastrad 	radeon_atombios_fini(rdev);
   8802  1.1  riastrad 	kfree(rdev->bios);
   8803  1.1  riastrad 	rdev->bios = NULL;
   8804  1.1  riastrad }
   8805  1.1  riastrad 
   8806  1.1  riastrad void dce8_program_fmt(struct drm_encoder *encoder)
   8807  1.1  riastrad {
   8808  1.1  riastrad 	struct drm_device *dev = encoder->dev;
   8809  1.1  riastrad 	struct radeon_device *rdev = dev->dev_private;
   8810  1.1  riastrad 	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
   8811  1.1  riastrad 	struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc);
   8812  1.1  riastrad 	struct drm_connector *connector = radeon_get_connector_for_encoder(encoder);
   8813  1.1  riastrad 	int bpc = 0;
   8814  1.1  riastrad 	u32 tmp = 0;
   8815  1.1  riastrad 	enum radeon_connector_dither dither = RADEON_FMT_DITHER_DISABLE;
   8816  1.1  riastrad 
   8817  1.1  riastrad 	if (connector) {
   8818  1.1  riastrad 		struct radeon_connector *radeon_connector = to_radeon_connector(connector);
   8819  1.1  riastrad 		bpc = radeon_get_monitor_bpc(connector);
   8820  1.1  riastrad 		dither = radeon_connector->dither;
   8821  1.1  riastrad 	}
   8822  1.1  riastrad 
   8823  1.1  riastrad 	/* LVDS/eDP FMT is set up by atom */
   8824  1.1  riastrad 	if (radeon_encoder->devices & ATOM_DEVICE_LCD_SUPPORT)
   8825  1.1  riastrad 		return;
   8826  1.1  riastrad 
   8827  1.1  riastrad 	/* not needed for analog */
   8828  1.1  riastrad 	if ((radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1) ||
   8829  1.1  riastrad 	    (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2))
   8830  1.1  riastrad 		return;
   8831  1.1  riastrad 
   8832  1.1  riastrad 	if (bpc == 0)
   8833  1.1  riastrad 		return;
   8834  1.1  riastrad 
   8835  1.1  riastrad 	switch (bpc) {
   8836  1.1  riastrad 	case 6:
   8837  1.1  riastrad 		if (dither == RADEON_FMT_DITHER_ENABLE)
   8838  1.1  riastrad 			/* XXX sort out optimal dither settings */
   8839  1.1  riastrad 			tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
   8840  1.1  riastrad 				FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(0));
   8841  1.1  riastrad 		else
   8842  1.1  riastrad 			tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(0));
   8843  1.1  riastrad 		break;
   8844  1.1  riastrad 	case 8:
   8845  1.1  riastrad 		if (dither == RADEON_FMT_DITHER_ENABLE)
   8846  1.1  riastrad 			/* XXX sort out optimal dither settings */
   8847  1.1  riastrad 			tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
   8848  1.1  riastrad 				FMT_RGB_RANDOM_ENABLE |
   8849  1.1  riastrad 				FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(1));
   8850  1.1  riastrad 		else
   8851  1.1  riastrad 			tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(1));
   8852  1.1  riastrad 		break;
   8853  1.1  riastrad 	case 10:
   8854  1.1  riastrad 		if (dither == RADEON_FMT_DITHER_ENABLE)
   8855  1.1  riastrad 			/* XXX sort out optimal dither settings */
   8856  1.1  riastrad 			tmp |= (FMT_FRAME_RANDOM_ENABLE | FMT_HIGHPASS_RANDOM_ENABLE |
   8857  1.1  riastrad 				FMT_RGB_RANDOM_ENABLE |
   8858  1.1  riastrad 				FMT_SPATIAL_DITHER_EN | FMT_SPATIAL_DITHER_DEPTH(2));
   8859  1.1  riastrad 		else
   8860  1.1  riastrad 			tmp |= (FMT_TRUNCATE_EN | FMT_TRUNCATE_DEPTH(2));
   8861  1.1  riastrad 		break;
   8862  1.1  riastrad 	default:
   8863  1.1  riastrad 		/* not needed */
   8864  1.1  riastrad 		break;
   8865  1.1  riastrad 	}
   8866  1.1  riastrad 
   8867  1.1  riastrad 	WREG32(FMT_BIT_DEPTH_CONTROL + radeon_crtc->crtc_offset, tmp);
   8868  1.1  riastrad }
   8869  1.1  riastrad 
   8870  1.1  riastrad /* display watermark setup */
   8871  1.1  riastrad /**
   8872  1.1  riastrad  * dce8_line_buffer_adjust - Set up the line buffer
   8873  1.1  riastrad  *
   8874  1.1  riastrad  * @rdev: radeon_device pointer
   8875  1.1  riastrad  * @radeon_crtc: the selected display controller
   8876  1.1  riastrad  * @mode: the current display mode on the selected display
   8877  1.1  riastrad  * controller
   8878  1.1  riastrad  *
   8879  1.1  riastrad  * Setup up the line buffer allocation for
   8880  1.1  riastrad  * the selected display controller (CIK).
   8881  1.1  riastrad  * Returns the line buffer size in pixels.
   8882  1.1  riastrad  */
   8883  1.1  riastrad static u32 dce8_line_buffer_adjust(struct radeon_device *rdev,
   8884  1.1  riastrad 				   struct radeon_crtc *radeon_crtc,
   8885  1.1  riastrad 				   struct drm_display_mode *mode)
   8886  1.1  riastrad {
   8887  1.1  riastrad 	u32 tmp, buffer_alloc, i;
   8888  1.1  riastrad 	u32 pipe_offset = radeon_crtc->crtc_id * 0x20;
   8889  1.1  riastrad 	/*
   8890  1.1  riastrad 	 * Line Buffer Setup
   8891  1.1  riastrad 	 * There are 6 line buffers, one for each display controllers.
   8892  1.1  riastrad 	 * There are 3 partitions per LB. Select the number of partitions
   8893  1.1  riastrad 	 * to enable based on the display width.  For display widths larger
   8894  1.1  riastrad 	 * than 4096, you need use to use 2 display controllers and combine
   8895  1.1  riastrad 	 * them using the stereo blender.
   8896  1.1  riastrad 	 */
   8897  1.1  riastrad 	if (radeon_crtc->base.enabled && mode) {
   8898  1.1  riastrad 		if (mode->crtc_hdisplay < 1920) {
   8899  1.1  riastrad 			tmp = 1;
   8900  1.1  riastrad 			buffer_alloc = 2;
   8901  1.1  riastrad 		} else if (mode->crtc_hdisplay < 2560) {
   8902  1.1  riastrad 			tmp = 2;
   8903  1.1  riastrad 			buffer_alloc = 2;
   8904  1.1  riastrad 		} else if (mode->crtc_hdisplay < 4096) {
   8905  1.1  riastrad 			tmp = 0;
   8906  1.1  riastrad 			buffer_alloc = (rdev->flags & RADEON_IS_IGP) ? 2 : 4;
   8907  1.1  riastrad 		} else {
   8908  1.1  riastrad 			DRM_DEBUG_KMS("Mode too big for LB!\n");
   8909  1.1  riastrad 			tmp = 0;
   8910  1.1  riastrad 			buffer_alloc = (rdev->flags & RADEON_IS_IGP) ? 2 : 4;
   8911  1.1  riastrad 		}
   8912  1.1  riastrad 	} else {
   8913  1.1  riastrad 		tmp = 1;
   8914  1.1  riastrad 		buffer_alloc = 0;
   8915  1.1  riastrad 	}
   8916  1.1  riastrad 
   8917  1.1  riastrad 	WREG32(LB_MEMORY_CTRL + radeon_crtc->crtc_offset,
   8918  1.1  riastrad 	       LB_MEMORY_CONFIG(tmp) | LB_MEMORY_SIZE(0x6B0));
   8919  1.1  riastrad 
   8920  1.1  riastrad 	WREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset,
   8921  1.1  riastrad 	       DMIF_BUFFERS_ALLOCATED(buffer_alloc));
   8922  1.1  riastrad 	for (i = 0; i < rdev->usec_timeout; i++) {
   8923  1.1  riastrad 		if (RREG32(PIPE0_DMIF_BUFFER_CONTROL + pipe_offset) &
   8924  1.1  riastrad 		    DMIF_BUFFERS_ALLOCATED_COMPLETED)
   8925  1.1  riastrad 			break;
   8926  1.1  riastrad 		udelay(1);
   8927  1.1  riastrad 	}
   8928  1.1  riastrad 
   8929  1.1  riastrad 	if (radeon_crtc->base.enabled && mode) {
   8930  1.1  riastrad 		switch (tmp) {
   8931  1.1  riastrad 		case 0:
   8932  1.1  riastrad 		default:
   8933  1.1  riastrad 			return 4096 * 2;
   8934  1.1  riastrad 		case 1:
   8935  1.1  riastrad 			return 1920 * 2;
   8936  1.1  riastrad 		case 2:
   8937  1.1  riastrad 			return 2560 * 2;
   8938  1.1  riastrad 		}
   8939  1.1  riastrad 	}
   8940  1.1  riastrad 
   8941  1.1  riastrad 	/* controller not enabled, so no lb used */
   8942  1.1  riastrad 	return 0;
   8943  1.1  riastrad }
   8944  1.1  riastrad 
   8945  1.1  riastrad /**
   8946  1.1  riastrad  * cik_get_number_of_dram_channels - get the number of dram channels
   8947  1.1  riastrad  *
   8948  1.1  riastrad  * @rdev: radeon_device pointer
   8949  1.1  riastrad  *
   8950  1.1  riastrad  * Look up the number of video ram channels (CIK).
   8951  1.1  riastrad  * Used for display watermark bandwidth calculations
   8952  1.1  riastrad  * Returns the number of dram channels
   8953  1.1  riastrad  */
   8954  1.1  riastrad static u32 cik_get_number_of_dram_channels(struct radeon_device *rdev)
   8955  1.1  riastrad {
   8956  1.1  riastrad 	u32 tmp = RREG32(MC_SHARED_CHMAP);
   8957  1.1  riastrad 
   8958  1.1  riastrad 	switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
   8959  1.1  riastrad 	case 0:
   8960  1.1  riastrad 	default:
   8961  1.1  riastrad 		return 1;
   8962  1.1  riastrad 	case 1:
   8963  1.1  riastrad 		return 2;
   8964  1.1  riastrad 	case 2:
   8965  1.1  riastrad 		return 4;
   8966  1.1  riastrad 	case 3:
   8967  1.1  riastrad 		return 8;
   8968  1.1  riastrad 	case 4:
   8969  1.1  riastrad 		return 3;
   8970  1.1  riastrad 	case 5:
   8971  1.1  riastrad 		return 6;
   8972  1.1  riastrad 	case 6:
   8973  1.1  riastrad 		return 10;
   8974  1.1  riastrad 	case 7:
   8975  1.1  riastrad 		return 12;
   8976  1.1  riastrad 	case 8:
   8977  1.1  riastrad 		return 16;
   8978  1.1  riastrad 	}
   8979  1.1  riastrad }
   8980  1.1  riastrad 
   8981  1.1  riastrad struct dce8_wm_params {
   8982  1.1  riastrad 	u32 dram_channels; /* number of dram channels */
   8983  1.1  riastrad 	u32 yclk;          /* bandwidth per dram data pin in kHz */
   8984  1.1  riastrad 	u32 sclk;          /* engine clock in kHz */
   8985  1.1  riastrad 	u32 disp_clk;      /* display clock in kHz */
   8986  1.1  riastrad 	u32 src_width;     /* viewport width */
   8987  1.1  riastrad 	u32 active_time;   /* active display time in ns */
   8988  1.1  riastrad 	u32 blank_time;    /* blank time in ns */
   8989  1.1  riastrad 	bool interlaced;    /* mode is interlaced */
   8990  1.1  riastrad 	fixed20_12 vsc;    /* vertical scale ratio */
   8991  1.1  riastrad 	u32 num_heads;     /* number of active crtcs */
   8992  1.1  riastrad 	u32 bytes_per_pixel; /* bytes per pixel display + overlay */
   8993  1.1  riastrad 	u32 lb_size;       /* line buffer allocated to pipe */
   8994  1.1  riastrad 	u32 vtaps;         /* vertical scaler taps */
   8995  1.1  riastrad };
   8996  1.1  riastrad 
   8997  1.1  riastrad /**
   8998  1.1  riastrad  * dce8_dram_bandwidth - get the dram bandwidth
   8999  1.1  riastrad  *
   9000  1.1  riastrad  * @wm: watermark calculation data
   9001  1.1  riastrad  *
   9002  1.1  riastrad  * Calculate the raw dram bandwidth (CIK).
   9003  1.1  riastrad  * Used for display watermark bandwidth calculations
   9004  1.1  riastrad  * Returns the dram bandwidth in MBytes/s
   9005  1.1  riastrad  */
   9006  1.1  riastrad static u32 dce8_dram_bandwidth(struct dce8_wm_params *wm)
   9007  1.1  riastrad {
   9008  1.1  riastrad 	/* Calculate raw DRAM Bandwidth */
   9009  1.1  riastrad 	fixed20_12 dram_efficiency; /* 0.7 */
   9010  1.1  riastrad 	fixed20_12 yclk, dram_channels, bandwidth;
   9011  1.1  riastrad 	fixed20_12 a;
   9012  1.1  riastrad 
   9013  1.1  riastrad 	a.full = dfixed_const(1000);
   9014  1.1  riastrad 	yclk.full = dfixed_const(wm->yclk);
   9015  1.1  riastrad 	yclk.full = dfixed_div(yclk, a);
   9016  1.1  riastrad 	dram_channels.full = dfixed_const(wm->dram_channels * 4);
   9017  1.1  riastrad 	a.full = dfixed_const(10);
   9018  1.1  riastrad 	dram_efficiency.full = dfixed_const(7);
   9019  1.1  riastrad 	dram_efficiency.full = dfixed_div(dram_efficiency, a);
   9020  1.1  riastrad 	bandwidth.full = dfixed_mul(dram_channels, yclk);
   9021  1.1  riastrad 	bandwidth.full = dfixed_mul(bandwidth, dram_efficiency);
   9022  1.1  riastrad 
   9023  1.1  riastrad 	return dfixed_trunc(bandwidth);
   9024  1.1  riastrad }
   9025  1.1  riastrad 
   9026  1.1  riastrad /**
   9027  1.1  riastrad  * dce8_dram_bandwidth_for_display - get the dram bandwidth for display
   9028  1.1  riastrad  *
   9029  1.1  riastrad  * @wm: watermark calculation data
   9030  1.1  riastrad  *
   9031  1.1  riastrad  * Calculate the dram bandwidth used for display (CIK).
   9032  1.1  riastrad  * Used for display watermark bandwidth calculations
   9033  1.1  riastrad  * Returns the dram bandwidth for display in MBytes/s
   9034  1.1  riastrad  */
   9035  1.1  riastrad static u32 dce8_dram_bandwidth_for_display(struct dce8_wm_params *wm)
   9036  1.1  riastrad {
   9037  1.1  riastrad 	/* Calculate DRAM Bandwidth and the part allocated to display. */
   9038  1.1  riastrad 	fixed20_12 disp_dram_allocation; /* 0.3 to 0.7 */
   9039  1.1  riastrad 	fixed20_12 yclk, dram_channels, bandwidth;
   9040  1.1  riastrad 	fixed20_12 a;
   9041  1.1  riastrad 
   9042  1.1  riastrad 	a.full = dfixed_const(1000);
   9043  1.1  riastrad 	yclk.full = dfixed_const(wm->yclk);
   9044  1.1  riastrad 	yclk.full = dfixed_div(yclk, a);
   9045  1.1  riastrad 	dram_channels.full = dfixed_const(wm->dram_channels * 4);
   9046  1.1  riastrad 	a.full = dfixed_const(10);
   9047  1.1  riastrad 	disp_dram_allocation.full = dfixed_const(3); /* XXX worse case value 0.3 */
   9048  1.1  riastrad 	disp_dram_allocation.full = dfixed_div(disp_dram_allocation, a);
   9049  1.1  riastrad 	bandwidth.full = dfixed_mul(dram_channels, yclk);
   9050  1.1  riastrad 	bandwidth.full = dfixed_mul(bandwidth, disp_dram_allocation);
   9051  1.1  riastrad 
   9052  1.1  riastrad 	return dfixed_trunc(bandwidth);
   9053  1.1  riastrad }
   9054  1.1  riastrad 
   9055  1.1  riastrad /**
   9056  1.1  riastrad  * dce8_data_return_bandwidth - get the data return bandwidth
   9057  1.1  riastrad  *
   9058  1.1  riastrad  * @wm: watermark calculation data
   9059  1.1  riastrad  *
   9060  1.1  riastrad  * Calculate the data return bandwidth used for display (CIK).
   9061  1.1  riastrad  * Used for display watermark bandwidth calculations
   9062  1.1  riastrad  * Returns the data return bandwidth in MBytes/s
   9063  1.1  riastrad  */
   9064  1.1  riastrad static u32 dce8_data_return_bandwidth(struct dce8_wm_params *wm)
   9065  1.1  riastrad {
   9066  1.1  riastrad 	/* Calculate the display Data return Bandwidth */
   9067  1.1  riastrad 	fixed20_12 return_efficiency; /* 0.8 */
   9068  1.1  riastrad 	fixed20_12 sclk, bandwidth;
   9069  1.1  riastrad 	fixed20_12 a;
   9070  1.1  riastrad 
   9071  1.1  riastrad 	a.full = dfixed_const(1000);
   9072  1.1  riastrad 	sclk.full = dfixed_const(wm->sclk);
   9073  1.1  riastrad 	sclk.full = dfixed_div(sclk, a);
   9074  1.1  riastrad 	a.full = dfixed_const(10);
   9075  1.1  riastrad 	return_efficiency.full = dfixed_const(8);
   9076  1.1  riastrad 	return_efficiency.full = dfixed_div(return_efficiency, a);
   9077  1.1  riastrad 	a.full = dfixed_const(32);
   9078  1.1  riastrad 	bandwidth.full = dfixed_mul(a, sclk);
   9079  1.1  riastrad 	bandwidth.full = dfixed_mul(bandwidth, return_efficiency);
   9080  1.1  riastrad 
   9081  1.1  riastrad 	return dfixed_trunc(bandwidth);
   9082  1.1  riastrad }
   9083  1.1  riastrad 
   9084  1.1  riastrad /**
   9085  1.1  riastrad  * dce8_dmif_request_bandwidth - get the dmif bandwidth
   9086  1.1  riastrad  *
   9087  1.1  riastrad  * @wm: watermark calculation data
   9088  1.1  riastrad  *
   9089  1.1  riastrad  * Calculate the dmif bandwidth used for display (CIK).
   9090  1.1  riastrad  * Used for display watermark bandwidth calculations
   9091  1.1  riastrad  * Returns the dmif bandwidth in MBytes/s
   9092  1.1  riastrad  */
   9093  1.1  riastrad static u32 dce8_dmif_request_bandwidth(struct dce8_wm_params *wm)
   9094  1.1  riastrad {
   9095  1.1  riastrad 	/* Calculate the DMIF Request Bandwidth */
   9096  1.1  riastrad 	fixed20_12 disp_clk_request_efficiency; /* 0.8 */
   9097  1.1  riastrad 	fixed20_12 disp_clk, bandwidth;
   9098  1.1  riastrad 	fixed20_12 a, b;
   9099  1.1  riastrad 
   9100  1.1  riastrad 	a.full = dfixed_const(1000);
   9101  1.1  riastrad 	disp_clk.full = dfixed_const(wm->disp_clk);
   9102  1.1  riastrad 	disp_clk.full = dfixed_div(disp_clk, a);
   9103  1.1  riastrad 	a.full = dfixed_const(32);
   9104  1.1  riastrad 	b.full = dfixed_mul(a, disp_clk);
   9105  1.1  riastrad 
   9106  1.1  riastrad 	a.full = dfixed_const(10);
   9107  1.1  riastrad 	disp_clk_request_efficiency.full = dfixed_const(8);
   9108  1.1  riastrad 	disp_clk_request_efficiency.full = dfixed_div(disp_clk_request_efficiency, a);
   9109  1.1  riastrad 
   9110  1.1  riastrad 	bandwidth.full = dfixed_mul(b, disp_clk_request_efficiency);
   9111  1.1  riastrad 
   9112  1.1  riastrad 	return dfixed_trunc(bandwidth);
   9113  1.1  riastrad }
   9114  1.1  riastrad 
   9115  1.1  riastrad /**
   9116  1.1  riastrad  * dce8_available_bandwidth - get the min available bandwidth
   9117  1.1  riastrad  *
   9118  1.1  riastrad  * @wm: watermark calculation data
   9119  1.1  riastrad  *
   9120  1.1  riastrad  * Calculate the min available bandwidth used for display (CIK).
   9121  1.1  riastrad  * Used for display watermark bandwidth calculations
   9122  1.1  riastrad  * Returns the min available bandwidth in MBytes/s
   9123  1.1  riastrad  */
   9124  1.1  riastrad static u32 dce8_available_bandwidth(struct dce8_wm_params *wm)
   9125  1.1  riastrad {
   9126  1.1  riastrad 	/* Calculate the Available bandwidth. Display can use this temporarily but not in average. */
   9127  1.1  riastrad 	u32 dram_bandwidth = dce8_dram_bandwidth(wm);
   9128  1.1  riastrad 	u32 data_return_bandwidth = dce8_data_return_bandwidth(wm);
   9129  1.1  riastrad 	u32 dmif_req_bandwidth = dce8_dmif_request_bandwidth(wm);
   9130  1.1  riastrad 
   9131  1.1  riastrad 	return min(dram_bandwidth, min(data_return_bandwidth, dmif_req_bandwidth));
   9132  1.1  riastrad }
   9133  1.1  riastrad 
   9134  1.1  riastrad /**
   9135  1.1  riastrad  * dce8_average_bandwidth - get the average available bandwidth
   9136  1.1  riastrad  *
   9137  1.1  riastrad  * @wm: watermark calculation data
   9138  1.1  riastrad  *
   9139  1.1  riastrad  * Calculate the average available bandwidth used for display (CIK).
   9140  1.1  riastrad  * Used for display watermark bandwidth calculations
   9141  1.1  riastrad  * Returns the average available bandwidth in MBytes/s
   9142  1.1  riastrad  */
   9143  1.1  riastrad static u32 dce8_average_bandwidth(struct dce8_wm_params *wm)
   9144  1.1  riastrad {
   9145  1.1  riastrad 	/* Calculate the display mode Average Bandwidth
   9146  1.1  riastrad 	 * DisplayMode should contain the source and destination dimensions,
   9147  1.1  riastrad 	 * timing, etc.
   9148  1.1  riastrad 	 */
   9149  1.1  riastrad 	fixed20_12 bpp;
   9150  1.1  riastrad 	fixed20_12 line_time;
   9151  1.1  riastrad 	fixed20_12 src_width;
   9152  1.1  riastrad 	fixed20_12 bandwidth;
   9153  1.1  riastrad 	fixed20_12 a;
   9154  1.1  riastrad 
   9155  1.1  riastrad 	a.full = dfixed_const(1000);
   9156  1.1  riastrad 	line_time.full = dfixed_const(wm->active_time + wm->blank_time);
   9157  1.1  riastrad 	line_time.full = dfixed_div(line_time, a);
   9158  1.1  riastrad 	bpp.full = dfixed_const(wm->bytes_per_pixel);
   9159  1.1  riastrad 	src_width.full = dfixed_const(wm->src_width);
   9160  1.1  riastrad 	bandwidth.full = dfixed_mul(src_width, bpp);
   9161  1.1  riastrad 	bandwidth.full = dfixed_mul(bandwidth, wm->vsc);
   9162  1.1  riastrad 	bandwidth.full = dfixed_div(bandwidth, line_time);
   9163  1.1  riastrad 
   9164  1.1  riastrad 	return dfixed_trunc(bandwidth);
   9165  1.1  riastrad }
   9166  1.1  riastrad 
   9167  1.1  riastrad /**
   9168  1.1  riastrad  * dce8_latency_watermark - get the latency watermark
   9169  1.1  riastrad  *
   9170  1.1  riastrad  * @wm: watermark calculation data
   9171  1.1  riastrad  *
   9172  1.1  riastrad  * Calculate the latency watermark (CIK).
   9173  1.1  riastrad  * Used for display watermark bandwidth calculations
   9174  1.1  riastrad  * Returns the latency watermark in ns
   9175  1.1  riastrad  */
   9176  1.1  riastrad static u32 dce8_latency_watermark(struct dce8_wm_params *wm)
   9177  1.1  riastrad {
   9178  1.1  riastrad 	/* First calculate the latency in ns */
   9179  1.1  riastrad 	u32 mc_latency = 2000; /* 2000 ns. */
   9180  1.1  riastrad 	u32 available_bandwidth = dce8_available_bandwidth(wm);
   9181  1.1  riastrad 	u32 worst_chunk_return_time = (512 * 8 * 1000) / available_bandwidth;
   9182  1.1  riastrad 	u32 cursor_line_pair_return_time = (128 * 4 * 1000) / available_bandwidth;
   9183  1.1  riastrad 	u32 dc_latency = 40000000 / wm->disp_clk; /* dc pipe latency */
   9184  1.1  riastrad 	u32 other_heads_data_return_time = ((wm->num_heads + 1) * worst_chunk_return_time) +
   9185  1.1  riastrad 		(wm->num_heads * cursor_line_pair_return_time);
   9186  1.1  riastrad 	u32 latency = mc_latency + other_heads_data_return_time + dc_latency;
   9187  1.1  riastrad 	u32 max_src_lines_per_dst_line, lb_fill_bw, line_fill_time;
   9188  1.1  riastrad 	u32 tmp, dmif_size = 12288;
   9189  1.1  riastrad 	fixed20_12 a, b, c;
   9190  1.1  riastrad 
   9191  1.1  riastrad 	if (wm->num_heads == 0)
   9192  1.1  riastrad 		return 0;
   9193  1.1  riastrad 
   9194  1.1  riastrad 	a.full = dfixed_const(2);
   9195  1.1  riastrad 	b.full = dfixed_const(1);
   9196  1.1  riastrad 	if ((wm->vsc.full > a.full) ||
   9197  1.1  riastrad 	    ((wm->vsc.full > b.full) && (wm->vtaps >= 3)) ||
   9198  1.1  riastrad 	    (wm->vtaps >= 5) ||
   9199  1.1  riastrad 	    ((wm->vsc.full >= a.full) && wm->interlaced))
   9200  1.1  riastrad 		max_src_lines_per_dst_line = 4;
   9201  1.1  riastrad 	else
   9202  1.1  riastrad 		max_src_lines_per_dst_line = 2;
   9203  1.1  riastrad 
   9204  1.1  riastrad 	a.full = dfixed_const(available_bandwidth);
   9205  1.1  riastrad 	b.full = dfixed_const(wm->num_heads);
   9206  1.1  riastrad 	a.full = dfixed_div(a, b);
   9207  1.3  riastrad 	tmp = div_u64((u64) dmif_size * (u64) wm->disp_clk, mc_latency + 512);
   9208  1.3  riastrad 	tmp = min(dfixed_trunc(a), tmp);
   9209  1.1  riastrad 
   9210  1.3  riastrad 	lb_fill_bw = min(tmp, wm->disp_clk * wm->bytes_per_pixel / 1000);
   9211  1.1  riastrad 
   9212  1.1  riastrad 	a.full = dfixed_const(max_src_lines_per_dst_line * wm->src_width * wm->bytes_per_pixel);
   9213  1.1  riastrad 	b.full = dfixed_const(1000);
   9214  1.1  riastrad 	c.full = dfixed_const(lb_fill_bw);
   9215  1.1  riastrad 	b.full = dfixed_div(c, b);
   9216  1.1  riastrad 	a.full = dfixed_div(a, b);
   9217  1.1  riastrad 	line_fill_time = dfixed_trunc(a);
   9218  1.1  riastrad 
   9219  1.1  riastrad 	if (line_fill_time < wm->active_time)
   9220  1.1  riastrad 		return latency;
   9221  1.1  riastrad 	else
   9222  1.1  riastrad 		return latency + (line_fill_time - wm->active_time);
   9223  1.1  riastrad 
   9224  1.1  riastrad }
   9225  1.1  riastrad 
   9226  1.1  riastrad /**
   9227  1.1  riastrad  * dce8_average_bandwidth_vs_dram_bandwidth_for_display - check
   9228  1.1  riastrad  * average and available dram bandwidth
   9229  1.1  riastrad  *
   9230  1.1  riastrad  * @wm: watermark calculation data
   9231  1.1  riastrad  *
   9232  1.1  riastrad  * Check if the display average bandwidth fits in the display
   9233  1.1  riastrad  * dram bandwidth (CIK).
   9234  1.1  riastrad  * Used for display watermark bandwidth calculations
   9235  1.1  riastrad  * Returns true if the display fits, false if not.
   9236  1.1  riastrad  */
   9237  1.1  riastrad static bool dce8_average_bandwidth_vs_dram_bandwidth_for_display(struct dce8_wm_params *wm)
   9238  1.1  riastrad {
   9239  1.1  riastrad 	if (dce8_average_bandwidth(wm) <=
   9240  1.1  riastrad 	    (dce8_dram_bandwidth_for_display(wm) / wm->num_heads))
   9241  1.1  riastrad 		return true;
   9242  1.1  riastrad 	else
   9243  1.1  riastrad 		return false;
   9244  1.1  riastrad }
   9245  1.1  riastrad 
   9246  1.1  riastrad /**
   9247  1.1  riastrad  * dce8_average_bandwidth_vs_available_bandwidth - check
   9248  1.1  riastrad  * average and available bandwidth
   9249  1.1  riastrad  *
   9250  1.1  riastrad  * @wm: watermark calculation data
   9251  1.1  riastrad  *
   9252  1.1  riastrad  * Check if the display average bandwidth fits in the display
   9253  1.1  riastrad  * available bandwidth (CIK).
   9254  1.1  riastrad  * Used for display watermark bandwidth calculations
   9255  1.1  riastrad  * Returns true if the display fits, false if not.
   9256  1.1  riastrad  */
   9257  1.1  riastrad static bool dce8_average_bandwidth_vs_available_bandwidth(struct dce8_wm_params *wm)
   9258  1.1  riastrad {
   9259  1.1  riastrad 	if (dce8_average_bandwidth(wm) <=
   9260  1.1  riastrad 	    (dce8_available_bandwidth(wm) / wm->num_heads))
   9261  1.1  riastrad 		return true;
   9262  1.1  riastrad 	else
   9263  1.1  riastrad 		return false;
   9264  1.1  riastrad }
   9265  1.1  riastrad 
   9266  1.1  riastrad /**
   9267  1.1  riastrad  * dce8_check_latency_hiding - check latency hiding
   9268  1.1  riastrad  *
   9269  1.1  riastrad  * @wm: watermark calculation data
   9270  1.1  riastrad  *
   9271  1.1  riastrad  * Check latency hiding (CIK).
   9272  1.1  riastrad  * Used for display watermark bandwidth calculations
   9273  1.1  riastrad  * Returns true if the display fits, false if not.
   9274  1.1  riastrad  */
   9275  1.1  riastrad static bool dce8_check_latency_hiding(struct dce8_wm_params *wm)
   9276  1.1  riastrad {
   9277  1.1  riastrad 	u32 lb_partitions = wm->lb_size / wm->src_width;
   9278  1.1  riastrad 	u32 line_time = wm->active_time + wm->blank_time;
   9279  1.1  riastrad 	u32 latency_tolerant_lines;
   9280  1.1  riastrad 	u32 latency_hiding;
   9281  1.1  riastrad 	fixed20_12 a;
   9282  1.1  riastrad 
   9283  1.1  riastrad 	a.full = dfixed_const(1);
   9284  1.1  riastrad 	if (wm->vsc.full > a.full)
   9285  1.1  riastrad 		latency_tolerant_lines = 1;
   9286  1.1  riastrad 	else {
   9287  1.1  riastrad 		if (lb_partitions <= (wm->vtaps + 1))
   9288  1.1  riastrad 			latency_tolerant_lines = 1;
   9289  1.1  riastrad 		else
   9290  1.1  riastrad 			latency_tolerant_lines = 2;
   9291  1.1  riastrad 	}
   9292  1.1  riastrad 
   9293  1.1  riastrad 	latency_hiding = (latency_tolerant_lines * line_time + wm->blank_time);
   9294  1.1  riastrad 
   9295  1.1  riastrad 	if (dce8_latency_watermark(wm) <= latency_hiding)
   9296  1.1  riastrad 		return true;
   9297  1.1  riastrad 	else
   9298  1.1  riastrad 		return false;
   9299  1.1  riastrad }
   9300  1.1  riastrad 
   9301  1.1  riastrad /**
   9302  1.1  riastrad  * dce8_program_watermarks - program display watermarks
   9303  1.1  riastrad  *
   9304  1.1  riastrad  * @rdev: radeon_device pointer
   9305  1.1  riastrad  * @radeon_crtc: the selected display controller
   9306  1.1  riastrad  * @lb_size: line buffer size
   9307  1.1  riastrad  * @num_heads: number of display controllers in use
   9308  1.1  riastrad  *
   9309  1.1  riastrad  * Calculate and program the display watermarks for the
   9310  1.1  riastrad  * selected display controller (CIK).
   9311  1.1  riastrad  */
   9312  1.1  riastrad static void dce8_program_watermarks(struct radeon_device *rdev,
   9313  1.1  riastrad 				    struct radeon_crtc *radeon_crtc,
   9314  1.1  riastrad 				    u32 lb_size, u32 num_heads)
   9315  1.1  riastrad {
   9316  1.1  riastrad 	struct drm_display_mode *mode = &radeon_crtc->base.mode;
   9317  1.1  riastrad 	struct dce8_wm_params wm_low, wm_high;
   9318  1.3  riastrad 	u32 active_time;
   9319  1.1  riastrad 	u32 line_time = 0;
   9320  1.1  riastrad 	u32 latency_watermark_a = 0, latency_watermark_b = 0;
   9321  1.1  riastrad 	u32 tmp, wm_mask;
   9322  1.1  riastrad 
   9323  1.1  riastrad 	if (radeon_crtc->base.enabled && num_heads && mode) {
   9324  1.3  riastrad 		active_time = (u32) div_u64((u64)mode->crtc_hdisplay * 1000000,
   9325  1.3  riastrad 					    (u32)mode->clock);
   9326  1.3  riastrad 		line_time = (u32) div_u64((u64)mode->crtc_htotal * 1000000,
   9327  1.3  riastrad 					  (u32)mode->clock);
   9328  1.3  riastrad 		line_time = min(line_time, (u32)65535);
   9329  1.1  riastrad 
   9330  1.1  riastrad 		/* watermark for high clocks */
   9331  1.1  riastrad 		if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
   9332  1.1  riastrad 		    rdev->pm.dpm_enabled) {
   9333  1.1  riastrad 			wm_high.yclk =
   9334  1.1  riastrad 				radeon_dpm_get_mclk(rdev, false) * 10;
   9335  1.1  riastrad 			wm_high.sclk =
   9336  1.1  riastrad 				radeon_dpm_get_sclk(rdev, false) * 10;
   9337  1.1  riastrad 		} else {
   9338  1.1  riastrad 			wm_high.yclk = rdev->pm.current_mclk * 10;
   9339  1.1  riastrad 			wm_high.sclk = rdev->pm.current_sclk * 10;
   9340  1.1  riastrad 		}
   9341  1.1  riastrad 
   9342  1.1  riastrad 		wm_high.disp_clk = mode->clock;
   9343  1.1  riastrad 		wm_high.src_width = mode->crtc_hdisplay;
   9344  1.3  riastrad 		wm_high.active_time = active_time;
   9345  1.1  riastrad 		wm_high.blank_time = line_time - wm_high.active_time;
   9346  1.1  riastrad 		wm_high.interlaced = false;
   9347  1.1  riastrad 		if (mode->flags & DRM_MODE_FLAG_INTERLACE)
   9348  1.1  riastrad 			wm_high.interlaced = true;
   9349  1.1  riastrad 		wm_high.vsc = radeon_crtc->vsc;
   9350  1.1  riastrad 		wm_high.vtaps = 1;
   9351  1.1  riastrad 		if (radeon_crtc->rmx_type != RMX_OFF)
   9352  1.1  riastrad 			wm_high.vtaps = 2;
   9353  1.1  riastrad 		wm_high.bytes_per_pixel = 4; /* XXX: get this from fb config */
   9354  1.1  riastrad 		wm_high.lb_size = lb_size;
   9355  1.1  riastrad 		wm_high.dram_channels = cik_get_number_of_dram_channels(rdev);
   9356  1.1  riastrad 		wm_high.num_heads = num_heads;
   9357  1.1  riastrad 
   9358  1.1  riastrad 		/* set for high clocks */
   9359  1.1  riastrad 		latency_watermark_a = min(dce8_latency_watermark(&wm_high), (u32)65535);
   9360  1.1  riastrad 
   9361  1.1  riastrad 		/* possibly force display priority to high */
   9362  1.1  riastrad 		/* should really do this at mode validation time... */
   9363  1.1  riastrad 		if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_high) ||
   9364  1.1  riastrad 		    !dce8_average_bandwidth_vs_available_bandwidth(&wm_high) ||
   9365  1.1  riastrad 		    !dce8_check_latency_hiding(&wm_high) ||
   9366  1.1  riastrad 		    (rdev->disp_priority == 2)) {
   9367  1.1  riastrad 			DRM_DEBUG_KMS("force priority to high\n");
   9368  1.1  riastrad 		}
   9369  1.1  riastrad 
   9370  1.1  riastrad 		/* watermark for low clocks */
   9371  1.1  riastrad 		if ((rdev->pm.pm_method == PM_METHOD_DPM) &&
   9372  1.1  riastrad 		    rdev->pm.dpm_enabled) {
   9373  1.1  riastrad 			wm_low.yclk =
   9374  1.1  riastrad 				radeon_dpm_get_mclk(rdev, true) * 10;
   9375  1.1  riastrad 			wm_low.sclk =
   9376  1.1  riastrad 				radeon_dpm_get_sclk(rdev, true) * 10;
   9377  1.1  riastrad 		} else {
   9378  1.1  riastrad 			wm_low.yclk = rdev->pm.current_mclk * 10;
   9379  1.1  riastrad 			wm_low.sclk = rdev->pm.current_sclk * 10;
   9380  1.1  riastrad 		}
   9381  1.1  riastrad 
   9382  1.1  riastrad 		wm_low.disp_clk = mode->clock;
   9383  1.1  riastrad 		wm_low.src_width = mode->crtc_hdisplay;
   9384  1.3  riastrad 		wm_low.active_time = active_time;
   9385  1.1  riastrad 		wm_low.blank_time = line_time - wm_low.active_time;
   9386  1.1  riastrad 		wm_low.interlaced = false;
   9387  1.1  riastrad 		if (mode->flags & DRM_MODE_FLAG_INTERLACE)
   9388  1.1  riastrad 			wm_low.interlaced = true;
   9389  1.1  riastrad 		wm_low.vsc = radeon_crtc->vsc;
   9390  1.1  riastrad 		wm_low.vtaps = 1;
   9391  1.1  riastrad 		if (radeon_crtc->rmx_type != RMX_OFF)
   9392  1.1  riastrad 			wm_low.vtaps = 2;
   9393  1.1  riastrad 		wm_low.bytes_per_pixel = 4; /* XXX: get this from fb config */
   9394  1.1  riastrad 		wm_low.lb_size = lb_size;
   9395  1.1  riastrad 		wm_low.dram_channels = cik_get_number_of_dram_channels(rdev);
   9396  1.1  riastrad 		wm_low.num_heads = num_heads;
   9397  1.1  riastrad 
   9398  1.1  riastrad 		/* set for low clocks */
   9399  1.1  riastrad 		latency_watermark_b = min(dce8_latency_watermark(&wm_low), (u32)65535);
   9400  1.1  riastrad 
   9401  1.1  riastrad 		/* possibly force display priority to high */
   9402  1.1  riastrad 		/* should really do this at mode validation time... */
   9403  1.1  riastrad 		if (!dce8_average_bandwidth_vs_dram_bandwidth_for_display(&wm_low) ||
   9404  1.1  riastrad 		    !dce8_average_bandwidth_vs_available_bandwidth(&wm_low) ||
   9405  1.1  riastrad 		    !dce8_check_latency_hiding(&wm_low) ||
   9406  1.1  riastrad 		    (rdev->disp_priority == 2)) {
   9407  1.1  riastrad 			DRM_DEBUG_KMS("force priority to high\n");
   9408  1.1  riastrad 		}
   9409  1.1  riastrad 
   9410  1.1  riastrad 		/* Save number of lines the linebuffer leads before the scanout */
   9411  1.1  riastrad 		radeon_crtc->lb_vblank_lead_lines = DIV_ROUND_UP(lb_size, mode->crtc_hdisplay);
   9412  1.1  riastrad 	}
   9413  1.1  riastrad 
   9414  1.1  riastrad 	/* select wm A */
   9415  1.1  riastrad 	wm_mask = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
   9416  1.1  riastrad 	tmp = wm_mask;
   9417  1.1  riastrad 	tmp &= ~LATENCY_WATERMARK_MASK(3);
   9418  1.1  riastrad 	tmp |= LATENCY_WATERMARK_MASK(1);
   9419  1.1  riastrad 	WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
   9420  1.1  riastrad 	WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
   9421  1.1  riastrad 	       (LATENCY_LOW_WATERMARK(latency_watermark_a) |
   9422  1.1  riastrad 		LATENCY_HIGH_WATERMARK(line_time)));
   9423  1.1  riastrad 	/* select wm B */
   9424  1.1  riastrad 	tmp = RREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset);
   9425  1.1  riastrad 	tmp &= ~LATENCY_WATERMARK_MASK(3);
   9426  1.1  riastrad 	tmp |= LATENCY_WATERMARK_MASK(2);
   9427  1.1  riastrad 	WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, tmp);
   9428  1.1  riastrad 	WREG32(DPG_PIPE_LATENCY_CONTROL + radeon_crtc->crtc_offset,
   9429  1.1  riastrad 	       (LATENCY_LOW_WATERMARK(latency_watermark_b) |
   9430  1.1  riastrad 		LATENCY_HIGH_WATERMARK(line_time)));
   9431  1.1  riastrad 	/* restore original selection */
   9432  1.1  riastrad 	WREG32(DPG_WATERMARK_MASK_CONTROL + radeon_crtc->crtc_offset, wm_mask);
   9433  1.1  riastrad 
   9434  1.1  riastrad 	/* save values for DPM */
   9435  1.1  riastrad 	radeon_crtc->line_time = line_time;
   9436  1.1  riastrad 	radeon_crtc->wm_high = latency_watermark_a;
   9437  1.1  riastrad 	radeon_crtc->wm_low = latency_watermark_b;
   9438  1.1  riastrad }
   9439  1.1  riastrad 
   9440  1.1  riastrad /**
   9441  1.1  riastrad  * dce8_bandwidth_update - program display watermarks
   9442  1.1  riastrad  *
   9443  1.1  riastrad  * @rdev: radeon_device pointer
   9444  1.1  riastrad  *
   9445  1.1  riastrad  * Calculate and program the display watermarks and line
   9446  1.1  riastrad  * buffer allocation (CIK).
   9447  1.1  riastrad  */
   9448  1.1  riastrad void dce8_bandwidth_update(struct radeon_device *rdev)
   9449  1.1  riastrad {
   9450  1.1  riastrad 	struct drm_display_mode *mode = NULL;
   9451  1.1  riastrad 	u32 num_heads = 0, lb_size;
   9452  1.1  riastrad 	int i;
   9453  1.1  riastrad 
   9454  1.1  riastrad 	if (!rdev->mode_info.mode_config_initialized)
   9455  1.1  riastrad 		return;
   9456  1.1  riastrad 
   9457  1.1  riastrad 	radeon_update_display_priority(rdev);
   9458  1.1  riastrad 
   9459  1.1  riastrad 	for (i = 0; i < rdev->num_crtc; i++) {
   9460  1.1  riastrad 		if (rdev->mode_info.crtcs[i]->base.enabled)
   9461  1.1  riastrad 			num_heads++;
   9462  1.1  riastrad 	}
   9463  1.1  riastrad 	for (i = 0; i < rdev->num_crtc; i++) {
   9464  1.1  riastrad 		mode = &rdev->mode_info.crtcs[i]->base.mode;
   9465  1.1  riastrad 		lb_size = dce8_line_buffer_adjust(rdev, rdev->mode_info.crtcs[i], mode);
   9466  1.1  riastrad 		dce8_program_watermarks(rdev, rdev->mode_info.crtcs[i], lb_size, num_heads);
   9467  1.1  riastrad 	}
   9468  1.1  riastrad }
   9469  1.1  riastrad 
   9470  1.1  riastrad /**
   9471  1.1  riastrad  * cik_get_gpu_clock_counter - return GPU clock counter snapshot
   9472  1.1  riastrad  *
   9473  1.1  riastrad  * @rdev: radeon_device pointer
   9474  1.1  riastrad  *
   9475  1.1  riastrad  * Fetches a GPU clock counter snapshot (SI).
   9476  1.1  riastrad  * Returns the 64 bit clock counter snapshot.
   9477  1.1  riastrad  */
   9478  1.1  riastrad uint64_t cik_get_gpu_clock_counter(struct radeon_device *rdev)
   9479  1.1  riastrad {
   9480  1.1  riastrad 	uint64_t clock;
   9481  1.1  riastrad 
   9482  1.1  riastrad 	mutex_lock(&rdev->gpu_clock_mutex);
   9483  1.1  riastrad 	WREG32(RLC_CAPTURE_GPU_CLOCK_COUNT, 1);
   9484  1.1  riastrad 	clock = (uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_LSB) |
   9485  1.3  riastrad 		((uint64_t)RREG32(RLC_GPU_CLOCK_COUNT_MSB) << 32ULL);
   9486  1.1  riastrad 	mutex_unlock(&rdev->gpu_clock_mutex);
   9487  1.1  riastrad 	return clock;
   9488  1.1  riastrad }
   9489  1.1  riastrad 
   9490  1.1  riastrad static int cik_set_uvd_clock(struct radeon_device *rdev, u32 clock,
   9491  1.3  riastrad 			     u32 cntl_reg, u32 status_reg)
   9492  1.1  riastrad {
   9493  1.1  riastrad 	int r, i;
   9494  1.1  riastrad 	struct atom_clock_dividers dividers;
   9495  1.1  riastrad 	uint32_t tmp;
   9496  1.1  riastrad 
   9497  1.1  riastrad 	r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
   9498  1.1  riastrad 					   clock, false, &dividers);
   9499  1.1  riastrad 	if (r)
   9500  1.1  riastrad 		return r;
   9501  1.1  riastrad 
   9502  1.1  riastrad 	tmp = RREG32_SMC(cntl_reg);
   9503  1.1  riastrad 	tmp &= ~(DCLK_DIR_CNTL_EN|DCLK_DIVIDER_MASK);
   9504  1.1  riastrad 	tmp |= dividers.post_divider;
   9505  1.1  riastrad 	WREG32_SMC(cntl_reg, tmp);
   9506  1.1  riastrad 
   9507  1.1  riastrad 	for (i = 0; i < 100; i++) {
   9508  1.1  riastrad 		if (RREG32_SMC(status_reg) & DCLK_STATUS)
   9509  1.1  riastrad 			break;
   9510  1.1  riastrad 		mdelay(10);
   9511  1.1  riastrad 	}
   9512  1.1  riastrad 	if (i == 100)
   9513  1.1  riastrad 		return -ETIMEDOUT;
   9514  1.1  riastrad 
   9515  1.1  riastrad 	return 0;
   9516  1.1  riastrad }
   9517  1.1  riastrad 
   9518  1.1  riastrad int cik_set_uvd_clocks(struct radeon_device *rdev, u32 vclk, u32 dclk)
   9519  1.1  riastrad {
   9520  1.1  riastrad 	int r = 0;
   9521  1.1  riastrad 
   9522  1.1  riastrad 	r = cik_set_uvd_clock(rdev, vclk, CG_VCLK_CNTL, CG_VCLK_STATUS);
   9523  1.1  riastrad 	if (r)
   9524  1.1  riastrad 		return r;
   9525  1.1  riastrad 
   9526  1.1  riastrad 	r = cik_set_uvd_clock(rdev, dclk, CG_DCLK_CNTL, CG_DCLK_STATUS);
   9527  1.1  riastrad 	return r;
   9528  1.1  riastrad }
   9529  1.1  riastrad 
   9530  1.1  riastrad int cik_set_vce_clocks(struct radeon_device *rdev, u32 evclk, u32 ecclk)
   9531  1.1  riastrad {
   9532  1.1  riastrad 	int r, i;
   9533  1.1  riastrad 	struct atom_clock_dividers dividers;
   9534  1.1  riastrad 	u32 tmp;
   9535  1.1  riastrad 
   9536  1.1  riastrad 	r = radeon_atom_get_clock_dividers(rdev, COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
   9537  1.1  riastrad 					   ecclk, false, &dividers);
   9538  1.1  riastrad 	if (r)
   9539  1.1  riastrad 		return r;
   9540  1.1  riastrad 
   9541  1.1  riastrad 	for (i = 0; i < 100; i++) {
   9542  1.1  riastrad 		if (RREG32_SMC(CG_ECLK_STATUS) & ECLK_STATUS)
   9543  1.1  riastrad 			break;
   9544  1.1  riastrad 		mdelay(10);
   9545  1.1  riastrad 	}
   9546  1.1  riastrad 	if (i == 100)
   9547  1.1  riastrad 		return -ETIMEDOUT;
   9548  1.1  riastrad 
   9549  1.1  riastrad 	tmp = RREG32_SMC(CG_ECLK_CNTL);
   9550  1.1  riastrad 	tmp &= ~(ECLK_DIR_CNTL_EN|ECLK_DIVIDER_MASK);
   9551  1.1  riastrad 	tmp |= dividers.post_divider;
   9552  1.1  riastrad 	WREG32_SMC(CG_ECLK_CNTL, tmp);
   9553  1.1  riastrad 
   9554  1.1  riastrad 	for (i = 0; i < 100; i++) {
   9555  1.1  riastrad 		if (RREG32_SMC(CG_ECLK_STATUS) & ECLK_STATUS)
   9556  1.1  riastrad 			break;
   9557  1.1  riastrad 		mdelay(10);
   9558  1.1  riastrad 	}
   9559  1.1  riastrad 	if (i == 100)
   9560  1.1  riastrad 		return -ETIMEDOUT;
   9561  1.1  riastrad 
   9562  1.1  riastrad 	return 0;
   9563  1.1  riastrad }
   9564  1.1  riastrad 
   9565  1.1  riastrad static void cik_pcie_gen3_enable(struct radeon_device *rdev)
   9566  1.1  riastrad {
   9567  1.1  riastrad 	struct pci_dev *root = rdev->pdev->bus->self;
   9568  1.3  riastrad 	enum pci_bus_speed speed_cap;
   9569  1.3  riastrad 	u32 speed_cntl, current_data_rate;
   9570  1.3  riastrad 	int i;
   9571  1.1  riastrad 	u16 tmp16;
   9572  1.1  riastrad 
   9573  1.1  riastrad 	if (pci_is_root_bus(rdev->pdev->bus))
   9574  1.1  riastrad 		return;
   9575  1.1  riastrad 
   9576  1.1  riastrad 	if (radeon_pcie_gen2 == 0)
   9577  1.1  riastrad 		return;
   9578  1.1  riastrad 
   9579  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP)
   9580  1.1  riastrad 		return;
   9581  1.1  riastrad 
   9582  1.1  riastrad 	if (!(rdev->flags & RADEON_IS_PCIE))
   9583  1.1  riastrad 		return;
   9584  1.1  riastrad 
   9585  1.3  riastrad 	speed_cap = pcie_get_speed_cap(root);
   9586  1.3  riastrad 	if (speed_cap == PCI_SPEED_UNKNOWN)
   9587  1.1  riastrad 		return;
   9588  1.1  riastrad 
   9589  1.3  riastrad 	if ((speed_cap != PCIE_SPEED_8_0GT) &&
   9590  1.3  riastrad 	    (speed_cap != PCIE_SPEED_5_0GT))
   9591  1.1  riastrad 		return;
   9592  1.1  riastrad 
   9593  1.1  riastrad 	speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
   9594  1.1  riastrad 	current_data_rate = (speed_cntl & LC_CURRENT_DATA_RATE_MASK) >>
   9595  1.1  riastrad 		LC_CURRENT_DATA_RATE_SHIFT;
   9596  1.3  riastrad 	if (speed_cap == PCIE_SPEED_8_0GT) {
   9597  1.1  riastrad 		if (current_data_rate == 2) {
   9598  1.1  riastrad 			DRM_INFO("PCIE gen 3 link speeds already enabled\n");
   9599  1.1  riastrad 			return;
   9600  1.1  riastrad 		}
   9601  1.1  riastrad 		DRM_INFO("enabling PCIE gen 3 link speeds, disable with radeon.pcie_gen2=0\n");
   9602  1.3  riastrad 	} else if (speed_cap == PCIE_SPEED_5_0GT) {
   9603  1.1  riastrad 		if (current_data_rate == 1) {
   9604  1.1  riastrad 			DRM_INFO("PCIE gen 2 link speeds already enabled\n");
   9605  1.1  riastrad 			return;
   9606  1.1  riastrad 		}
   9607  1.1  riastrad 		DRM_INFO("enabling PCIE gen 2 link speeds, disable with radeon.pcie_gen2=0\n");
   9608  1.1  riastrad 	}
   9609  1.1  riastrad 
   9610  1.3  riastrad 	if (!pci_is_pcie(root) || !pci_is_pcie(rdev->pdev))
   9611  1.1  riastrad 		return;
   9612  1.1  riastrad 
   9613  1.3  riastrad 	if (speed_cap == PCIE_SPEED_8_0GT) {
   9614  1.1  riastrad 		/* re-try equalization if gen3 is not already enabled */
   9615  1.1  riastrad 		if (current_data_rate != 2) {
   9616  1.1  riastrad 			u16 bridge_cfg, gpu_cfg;
   9617  1.1  riastrad 			u16 bridge_cfg2, gpu_cfg2;
   9618  1.1  riastrad 			u32 max_lw, current_lw, tmp;
   9619  1.1  riastrad 
   9620  1.3  riastrad 			pcie_capability_read_word(root, PCI_EXP_LNKCTL,
   9621  1.3  riastrad 						  &bridge_cfg);
   9622  1.3  riastrad 			pcie_capability_read_word(rdev->pdev, PCI_EXP_LNKCTL,
   9623  1.3  riastrad 						  &gpu_cfg);
   9624  1.1  riastrad 
   9625  1.1  riastrad 			tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
   9626  1.3  riastrad 			pcie_capability_write_word(root, PCI_EXP_LNKCTL, tmp16);
   9627  1.1  riastrad 
   9628  1.1  riastrad 			tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
   9629  1.3  riastrad 			pcie_capability_write_word(rdev->pdev, PCI_EXP_LNKCTL,
   9630  1.3  riastrad 						   tmp16);
   9631  1.1  riastrad 
   9632  1.1  riastrad 			tmp = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
   9633  1.1  riastrad 			max_lw = (tmp & LC_DETECTED_LINK_WIDTH_MASK) >> LC_DETECTED_LINK_WIDTH_SHIFT;
   9634  1.1  riastrad 			current_lw = (tmp & LC_OPERATING_LINK_WIDTH_MASK) >> LC_OPERATING_LINK_WIDTH_SHIFT;
   9635  1.1  riastrad 
   9636  1.1  riastrad 			if (current_lw < max_lw) {
   9637  1.1  riastrad 				tmp = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
   9638  1.1  riastrad 				if (tmp & LC_RENEGOTIATION_SUPPORT) {
   9639  1.1  riastrad 					tmp &= ~(LC_LINK_WIDTH_MASK | LC_UPCONFIGURE_DIS);
   9640  1.1  riastrad 					tmp |= (max_lw << LC_LINK_WIDTH_SHIFT);
   9641  1.1  riastrad 					tmp |= LC_UPCONFIGURE_SUPPORT | LC_RENEGOTIATE_EN | LC_RECONFIG_NOW;
   9642  1.1  riastrad 					WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, tmp);
   9643  1.1  riastrad 				}
   9644  1.1  riastrad 			}
   9645  1.1  riastrad 
   9646  1.1  riastrad 			for (i = 0; i < 10; i++) {
   9647  1.1  riastrad 				/* check status */
   9648  1.3  riastrad 				pcie_capability_read_word(rdev->pdev,
   9649  1.3  riastrad 							  PCI_EXP_DEVSTA,
   9650  1.3  riastrad 							  &tmp16);
   9651  1.1  riastrad 				if (tmp16 & PCI_EXP_DEVSTA_TRPND)
   9652  1.1  riastrad 					break;
   9653  1.1  riastrad 
   9654  1.3  riastrad 				pcie_capability_read_word(root, PCI_EXP_LNKCTL,
   9655  1.3  riastrad 							  &bridge_cfg);
   9656  1.3  riastrad 				pcie_capability_read_word(rdev->pdev,
   9657  1.3  riastrad 							  PCI_EXP_LNKCTL,
   9658  1.3  riastrad 							  &gpu_cfg);
   9659  1.3  riastrad 
   9660  1.3  riastrad 				pcie_capability_read_word(root, PCI_EXP_LNKCTL2,
   9661  1.3  riastrad 							  &bridge_cfg2);
   9662  1.3  riastrad 				pcie_capability_read_word(rdev->pdev,
   9663  1.3  riastrad 							  PCI_EXP_LNKCTL2,
   9664  1.3  riastrad 							  &gpu_cfg2);
   9665  1.1  riastrad 
   9666  1.1  riastrad 				tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
   9667  1.1  riastrad 				tmp |= LC_SET_QUIESCE;
   9668  1.1  riastrad 				WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
   9669  1.1  riastrad 
   9670  1.1  riastrad 				tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
   9671  1.1  riastrad 				tmp |= LC_REDO_EQ;
   9672  1.1  riastrad 				WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
   9673  1.1  riastrad 
   9674  1.3  riastrad 				msleep(100);
   9675  1.1  riastrad 
   9676  1.1  riastrad 				/* linkctl */
   9677  1.3  riastrad 				pcie_capability_read_word(root, PCI_EXP_LNKCTL,
   9678  1.3  riastrad 							  &tmp16);
   9679  1.1  riastrad 				tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
   9680  1.1  riastrad 				tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
   9681  1.3  riastrad 				pcie_capability_write_word(root, PCI_EXP_LNKCTL,
   9682  1.3  riastrad 							   tmp16);
   9683  1.1  riastrad 
   9684  1.3  riastrad 				pcie_capability_read_word(rdev->pdev,
   9685  1.3  riastrad 							  PCI_EXP_LNKCTL,
   9686  1.3  riastrad 							  &tmp16);
   9687  1.1  riastrad 				tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
   9688  1.1  riastrad 				tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
   9689  1.3  riastrad 				pcie_capability_write_word(rdev->pdev,
   9690  1.3  riastrad 							   PCI_EXP_LNKCTL,
   9691  1.3  riastrad 							   tmp16);
   9692  1.1  riastrad 
   9693  1.1  riastrad 				/* linkctl2 */
   9694  1.3  riastrad 				pcie_capability_read_word(root, PCI_EXP_LNKCTL2,
   9695  1.3  riastrad 							  &tmp16);
   9696  1.3  riastrad 				tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP |
   9697  1.3  riastrad 					   PCI_EXP_LNKCTL2_TX_MARGIN);
   9698  1.3  riastrad 				tmp16 |= (bridge_cfg2 &
   9699  1.3  riastrad 					  (PCI_EXP_LNKCTL2_ENTER_COMP |
   9700  1.3  riastrad 					   PCI_EXP_LNKCTL2_TX_MARGIN));
   9701  1.3  riastrad 				pcie_capability_write_word(root,
   9702  1.3  riastrad 							   PCI_EXP_LNKCTL2,
   9703  1.3  riastrad 							   tmp16);
   9704  1.3  riastrad 
   9705  1.3  riastrad 				pcie_capability_read_word(rdev->pdev,
   9706  1.3  riastrad 							  PCI_EXP_LNKCTL2,
   9707  1.3  riastrad 							  &tmp16);
   9708  1.3  riastrad 				tmp16 &= ~(PCI_EXP_LNKCTL2_ENTER_COMP |
   9709  1.3  riastrad 					   PCI_EXP_LNKCTL2_TX_MARGIN);
   9710  1.3  riastrad 				tmp16 |= (gpu_cfg2 &
   9711  1.3  riastrad 					  (PCI_EXP_LNKCTL2_ENTER_COMP |
   9712  1.3  riastrad 					   PCI_EXP_LNKCTL2_TX_MARGIN));
   9713  1.3  riastrad 				pcie_capability_write_word(rdev->pdev,
   9714  1.3  riastrad 							   PCI_EXP_LNKCTL2,
   9715  1.3  riastrad 							   tmp16);
   9716  1.1  riastrad 
   9717  1.1  riastrad 				tmp = RREG32_PCIE_PORT(PCIE_LC_CNTL4);
   9718  1.1  riastrad 				tmp &= ~LC_SET_QUIESCE;
   9719  1.1  riastrad 				WREG32_PCIE_PORT(PCIE_LC_CNTL4, tmp);
   9720  1.1  riastrad 			}
   9721  1.1  riastrad 		}
   9722  1.1  riastrad 	}
   9723  1.1  riastrad 
   9724  1.1  riastrad 	/* set the link speed */
   9725  1.1  riastrad 	speed_cntl |= LC_FORCE_EN_SW_SPEED_CHANGE | LC_FORCE_DIS_HW_SPEED_CHANGE;
   9726  1.1  riastrad 	speed_cntl &= ~LC_FORCE_DIS_SW_SPEED_CHANGE;
   9727  1.1  riastrad 	WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
   9728  1.1  riastrad 
   9729  1.3  riastrad 	pcie_capability_read_word(rdev->pdev, PCI_EXP_LNKCTL2, &tmp16);
   9730  1.3  riastrad 	tmp16 &= ~PCI_EXP_LNKCTL2_TLS;
   9731  1.3  riastrad 	if (speed_cap == PCIE_SPEED_8_0GT)
   9732  1.3  riastrad 		tmp16 |= PCI_EXP_LNKCTL2_TLS_8_0GT; /* gen3 */
   9733  1.3  riastrad 	else if (speed_cap == PCIE_SPEED_5_0GT)
   9734  1.3  riastrad 		tmp16 |= PCI_EXP_LNKCTL2_TLS_5_0GT; /* gen2 */
   9735  1.1  riastrad 	else
   9736  1.3  riastrad 		tmp16 |= PCI_EXP_LNKCTL2_TLS_2_5GT; /* gen1 */
   9737  1.3  riastrad 	pcie_capability_write_word(rdev->pdev, PCI_EXP_LNKCTL2, tmp16);
   9738  1.1  riastrad 
   9739  1.1  riastrad 	speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
   9740  1.1  riastrad 	speed_cntl |= LC_INITIATE_LINK_SPEED_CHANGE;
   9741  1.1  riastrad 	WREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL, speed_cntl);
   9742  1.1  riastrad 
   9743  1.1  riastrad 	for (i = 0; i < rdev->usec_timeout; i++) {
   9744  1.1  riastrad 		speed_cntl = RREG32_PCIE_PORT(PCIE_LC_SPEED_CNTL);
   9745  1.1  riastrad 		if ((speed_cntl & LC_INITIATE_LINK_SPEED_CHANGE) == 0)
   9746  1.1  riastrad 			break;
   9747  1.1  riastrad 		udelay(1);
   9748  1.1  riastrad 	}
   9749  1.1  riastrad }
   9750  1.1  riastrad 
   9751  1.1  riastrad static void cik_program_aspm(struct radeon_device *rdev)
   9752  1.1  riastrad {
   9753  1.1  riastrad 	u32 data, orig;
   9754  1.1  riastrad 	bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
   9755  1.1  riastrad 	bool disable_clkreq = false;
   9756  1.1  riastrad 
   9757  1.1  riastrad 	if (radeon_aspm == 0)
   9758  1.1  riastrad 		return;
   9759  1.1  riastrad 
   9760  1.1  riastrad 	/* XXX double check IGPs */
   9761  1.1  riastrad 	if (rdev->flags & RADEON_IS_IGP)
   9762  1.1  riastrad 		return;
   9763  1.1  riastrad 
   9764  1.1  riastrad 	if (!(rdev->flags & RADEON_IS_PCIE))
   9765  1.1  riastrad 		return;
   9766  1.1  riastrad 
   9767  1.1  riastrad 	orig = data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
   9768  1.1  riastrad 	data &= ~LC_XMIT_N_FTS_MASK;
   9769  1.1  riastrad 	data |= LC_XMIT_N_FTS(0x24) | LC_XMIT_N_FTS_OVERRIDE_EN;
   9770  1.1  riastrad 	if (orig != data)
   9771  1.1  riastrad 		WREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL, data);
   9772  1.1  riastrad 
   9773  1.1  riastrad 	orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL3);
   9774  1.1  riastrad 	data |= LC_GO_TO_RECOVERY;
   9775  1.1  riastrad 	if (orig != data)
   9776  1.1  riastrad 		WREG32_PCIE_PORT(PCIE_LC_CNTL3, data);
   9777  1.1  riastrad 
   9778  1.1  riastrad 	orig = data = RREG32_PCIE_PORT(PCIE_P_CNTL);
   9779  1.1  riastrad 	data |= P_IGNORE_EDB_ERR;
   9780  1.1  riastrad 	if (orig != data)
   9781  1.1  riastrad 		WREG32_PCIE_PORT(PCIE_P_CNTL, data);
   9782  1.1  riastrad 
   9783  1.1  riastrad 	orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
   9784  1.1  riastrad 	data &= ~(LC_L0S_INACTIVITY_MASK | LC_L1_INACTIVITY_MASK);
   9785  1.1  riastrad 	data |= LC_PMI_TO_L1_DIS;
   9786  1.1  riastrad 	if (!disable_l0s)
   9787  1.1  riastrad 		data |= LC_L0S_INACTIVITY(7);
   9788  1.1  riastrad 
   9789  1.1  riastrad 	if (!disable_l1) {
   9790  1.1  riastrad 		data |= LC_L1_INACTIVITY(7);
   9791  1.1  riastrad 		data &= ~LC_PMI_TO_L1_DIS;
   9792  1.1  riastrad 		if (orig != data)
   9793  1.1  riastrad 			WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
   9794  1.1  riastrad 
   9795  1.1  riastrad 		if (!disable_plloff_in_l1) {
   9796  1.1  riastrad 			bool clk_req_support;
   9797  1.1  riastrad 
   9798  1.1  riastrad 			orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0);
   9799  1.1  riastrad 			data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
   9800  1.1  riastrad 			data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
   9801  1.1  riastrad 			if (orig != data)
   9802  1.1  riastrad 				WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_0, data);
   9803  1.1  riastrad 
   9804  1.1  riastrad 			orig = data = RREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1);
   9805  1.1  riastrad 			data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
   9806  1.1  riastrad 			data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
   9807  1.1  riastrad 			if (orig != data)
   9808  1.1  riastrad 				WREG32_PCIE_PORT(PB0_PIF_PWRDOWN_1, data);
   9809  1.1  riastrad 
   9810  1.1  riastrad 			orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0);
   9811  1.1  riastrad 			data &= ~(PLL_POWER_STATE_IN_OFF_0_MASK | PLL_POWER_STATE_IN_TXS2_0_MASK);
   9812  1.1  riastrad 			data |= PLL_POWER_STATE_IN_OFF_0(7) | PLL_POWER_STATE_IN_TXS2_0(7);
   9813  1.1  riastrad 			if (orig != data)
   9814  1.1  riastrad 				WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_0, data);
   9815  1.1  riastrad 
   9816  1.1  riastrad 			orig = data = RREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1);
   9817  1.1  riastrad 			data &= ~(PLL_POWER_STATE_IN_OFF_1_MASK | PLL_POWER_STATE_IN_TXS2_1_MASK);
   9818  1.1  riastrad 			data |= PLL_POWER_STATE_IN_OFF_1(7) | PLL_POWER_STATE_IN_TXS2_1(7);
   9819  1.1  riastrad 			if (orig != data)
   9820  1.1  riastrad 				WREG32_PCIE_PORT(PB1_PIF_PWRDOWN_1, data);
   9821  1.1  riastrad 
   9822  1.1  riastrad 			orig = data = RREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL);
   9823  1.1  riastrad 			data &= ~LC_DYN_LANES_PWR_STATE_MASK;
   9824  1.1  riastrad 			data |= LC_DYN_LANES_PWR_STATE(3);
   9825  1.1  riastrad 			if (orig != data)
   9826  1.1  riastrad 				WREG32_PCIE_PORT(PCIE_LC_LINK_WIDTH_CNTL, data);
   9827  1.1  riastrad 
   9828  1.1  riastrad 			if (!disable_clkreq &&
   9829  1.1  riastrad 			    !pci_is_root_bus(rdev->pdev->bus)) {
   9830  1.1  riastrad 				struct pci_dev *root = rdev->pdev->bus->self;
   9831  1.1  riastrad 				u32 lnkcap;
   9832  1.1  riastrad 
   9833  1.1  riastrad 				clk_req_support = false;
   9834  1.1  riastrad 				pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
   9835  1.1  riastrad 				if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
   9836  1.1  riastrad 					clk_req_support = true;
   9837  1.1  riastrad 			} else {
   9838  1.1  riastrad 				clk_req_support = false;
   9839  1.1  riastrad 			}
   9840  1.1  riastrad 
   9841  1.1  riastrad 			if (clk_req_support) {
   9842  1.1  riastrad 				orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL2);
   9843  1.1  riastrad 				data |= LC_ALLOW_PDWN_IN_L1 | LC_ALLOW_PDWN_IN_L23;
   9844  1.1  riastrad 				if (orig != data)
   9845  1.1  riastrad 					WREG32_PCIE_PORT(PCIE_LC_CNTL2, data);
   9846  1.1  riastrad 
   9847  1.1  riastrad 				orig = data = RREG32_SMC(THM_CLK_CNTL);
   9848  1.1  riastrad 				data &= ~(CMON_CLK_SEL_MASK | TMON_CLK_SEL_MASK);
   9849  1.1  riastrad 				data |= CMON_CLK_SEL(1) | TMON_CLK_SEL(1);
   9850  1.1  riastrad 				if (orig != data)
   9851  1.1  riastrad 					WREG32_SMC(THM_CLK_CNTL, data);
   9852  1.1  riastrad 
   9853  1.1  riastrad 				orig = data = RREG32_SMC(MISC_CLK_CTRL);
   9854  1.1  riastrad 				data &= ~(DEEP_SLEEP_CLK_SEL_MASK | ZCLK_SEL_MASK);
   9855  1.1  riastrad 				data |= DEEP_SLEEP_CLK_SEL(1) | ZCLK_SEL(1);
   9856  1.1  riastrad 				if (orig != data)
   9857  1.1  riastrad 					WREG32_SMC(MISC_CLK_CTRL, data);
   9858  1.1  riastrad 
   9859  1.1  riastrad 				orig = data = RREG32_SMC(CG_CLKPIN_CNTL);
   9860  1.1  riastrad 				data &= ~BCLK_AS_XCLK;
   9861  1.1  riastrad 				if (orig != data)
   9862  1.1  riastrad 					WREG32_SMC(CG_CLKPIN_CNTL, data);
   9863  1.1  riastrad 
   9864  1.1  riastrad 				orig = data = RREG32_SMC(CG_CLKPIN_CNTL_2);
   9865  1.1  riastrad 				data &= ~FORCE_BIF_REFCLK_EN;
   9866  1.1  riastrad 				if (orig != data)
   9867  1.1  riastrad 					WREG32_SMC(CG_CLKPIN_CNTL_2, data);
   9868  1.1  riastrad 
   9869  1.1  riastrad 				orig = data = RREG32_SMC(MPLL_BYPASSCLK_SEL);
   9870  1.1  riastrad 				data &= ~MPLL_CLKOUT_SEL_MASK;
   9871  1.1  riastrad 				data |= MPLL_CLKOUT_SEL(4);
   9872  1.1  riastrad 				if (orig != data)
   9873  1.1  riastrad 					WREG32_SMC(MPLL_BYPASSCLK_SEL, data);
   9874  1.1  riastrad 			}
   9875  1.1  riastrad 		}
   9876  1.1  riastrad 	} else {
   9877  1.1  riastrad 		if (orig != data)
   9878  1.1  riastrad 			WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
   9879  1.1  riastrad 	}
   9880  1.1  riastrad 
   9881  1.1  riastrad 	orig = data = RREG32_PCIE_PORT(PCIE_CNTL2);
   9882  1.1  riastrad 	data |= SLV_MEM_LS_EN | MST_MEM_LS_EN | REPLAY_MEM_LS_EN;
   9883  1.1  riastrad 	if (orig != data)
   9884  1.1  riastrad 		WREG32_PCIE_PORT(PCIE_CNTL2, data);
   9885  1.1  riastrad 
   9886  1.1  riastrad 	if (!disable_l0s) {
   9887  1.1  riastrad 		data = RREG32_PCIE_PORT(PCIE_LC_N_FTS_CNTL);
   9888  1.1  riastrad 		if((data & LC_N_FTS_MASK) == LC_N_FTS_MASK) {
   9889  1.1  riastrad 			data = RREG32_PCIE_PORT(PCIE_LC_STATUS1);
   9890  1.1  riastrad 			if ((data & LC_REVERSE_XMIT) && (data & LC_REVERSE_RCVR)) {
   9891  1.1  riastrad 				orig = data = RREG32_PCIE_PORT(PCIE_LC_CNTL);
   9892  1.1  riastrad 				data &= ~LC_L0S_INACTIVITY_MASK;
   9893  1.1  riastrad 				if (orig != data)
   9894  1.1  riastrad 					WREG32_PCIE_PORT(PCIE_LC_CNTL, data);
   9895  1.1  riastrad 			}
   9896  1.1  riastrad 		}
   9897  1.1  riastrad 	}
   9898  1.1  riastrad }
   9899