drm/radeon: convert SI,CIK to use sumo_rlc functions
authorAlex Deucher <alexander.deucher@amd.com>
Wed, 17 Apr 2013 21:53:50 +0000 (17:53 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 30 Aug 2013 20:30:08 +0000 (16:30 -0400)
and remove duplicate si_rlc functions.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/radeon/cik.c
drivers/gpu/drm/radeon/clearstate_cayman.h
drivers/gpu/drm/radeon/clearstate_evergreen.h
drivers/gpu/drm/radeon/evergreen.c
drivers/gpu/drm/radeon/ni.c
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/si.c

index e92a972..8389917 100644 (file)
@@ -57,9 +57,9 @@ extern void r600_ih_ring_fini(struct radeon_device *rdev);
 extern void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save);
 extern void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save);
 extern bool evergreen_is_display_hung(struct radeon_device *rdev);
+extern void sumo_rlc_fini(struct radeon_device *rdev);
+extern int sumo_rlc_init(struct radeon_device *rdev);
 extern void si_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
-extern void si_rlc_fini(struct radeon_device *rdev);
-extern int si_rlc_init(struct radeon_device *rdev);
 extern void si_rlc_reset(struct radeon_device *rdev);
 static void cik_rlc_stop(struct radeon_device *rdev);
 static void cik_pcie_gen3_enable(struct radeon_device *rdev);
@@ -6019,7 +6019,7 @@ static int cik_startup(struct radeon_device *rdev)
        cik_gpu_init(rdev);
 
        /* allocate rlc buffers */
-       r = si_rlc_init(rdev);
+       r = sumo_rlc_init(rdev);
        if (r) {
                DRM_ERROR("Failed to init rlc BOs!\n");
                return r;
@@ -6343,7 +6343,7 @@ int cik_init(struct radeon_device *rdev)
                cik_cp_fini(rdev);
                cik_sdma_fini(rdev);
                cik_irq_fini(rdev);
-               si_rlc_fini(rdev);
+               sumo_rlc_fini(rdev);
                cik_mec_fini(rdev);
                radeon_wb_fini(rdev);
                radeon_ib_pool_fini(rdev);
@@ -6379,7 +6379,7 @@ void cik_fini(struct radeon_device *rdev)
        cik_cp_fini(rdev);
        cik_sdma_fini(rdev);
        cik_irq_fini(rdev);
-       si_rlc_fini(rdev);
+       sumo_rlc_fini(rdev);
        cik_mec_fini(rdev);
        radeon_wb_fini(rdev);
        radeon_vm_manager_fini(rdev);
index c003394..aa908c5 100644 (file)
@@ -1073,7 +1073,7 @@ static const struct cs_extent_def SECT_CTRLCONST_defs[] =
     {SECT_CTRLCONST_def_1, 0x0000f3fc, 2 },
     { 0, 0, 0 }
 };
-struct cs_section_def cayman_cs_data[] = {
+static const struct cs_section_def cayman_cs_data[] = {
     { SECT_CONTEXT_defs, SECT_CONTEXT },
     { SECT_CLEAR_defs, SECT_CLEAR },
     { SECT_CTRLCONST_defs, SECT_CTRLCONST },
index 4791d85..63a1ffb 100644 (file)
@@ -1072,7 +1072,7 @@ static const struct cs_extent_def SECT_CTRLCONST_defs[] =
     {SECT_CTRLCONST_def_1, 0x0000f3fc, 2 },
     { 0, 0, 0 }
 };
-struct cs_section_def evergreen_cs_data[] = {
+static const struct cs_section_def evergreen_cs_data[] = {
     { SECT_CONTEXT_defs, SECT_CONTEXT },
     { SECT_CLEAR_defs, SECT_CLEAR },
     { SECT_CTRLCONST_defs, SECT_CTRLCONST },
index 6178408..6fc876a 100644 (file)
@@ -47,7 +47,7 @@ static const u32 crtc_offsets[6] =
 
 #include "clearstate_evergreen.h"
 
-static u32 sumo_rlc_save_restore_register_list[] =
+static const u32 sumo_rlc_save_restore_register_list[] =
 {
        0x98fc,
        0x9830,
@@ -131,7 +131,6 @@ static u32 sumo_rlc_save_restore_register_list[] =
        0x9150,
        0x802c,
 };
-static u32 sumo_rlc_save_restore_register_list_size = ARRAY_SIZE(sumo_rlc_save_restore_register_list);
 
 static void evergreen_gpu_init(struct radeon_device *rdev);
 void evergreen_fini(struct radeon_device *rdev);
@@ -3898,12 +3897,12 @@ void sumo_rlc_fini(struct radeon_device *rdev)
 
 int sumo_rlc_init(struct radeon_device *rdev)
 {
-       u32 *src_ptr;
+       const u32 *src_ptr;
        volatile u32 *dst_ptr;
        u32 dws, data, i, j, k, reg_num;
        u32 reg_list_num, reg_list_hdr_blk_index, reg_list_blk_index;
        u64 reg_list_mc_addr;
-       struct cs_section_def *cs_data;
+       const struct cs_section_def *cs_data;
        int r;
 
        src_ptr = rdev->rlc.reg_list;
@@ -3943,22 +3942,28 @@ int sumo_rlc_init(struct radeon_device *rdev)
                }
                /* write the sr buffer */
                dst_ptr = rdev->rlc.sr_ptr;
-               /* format:
-                * dw0: (reg2 << 16) | reg1
-                * dw1: reg1 save space
-                * dw2: reg2 save space
-                */
-               for (i = 0; i < dws; i++) {
-                       data = src_ptr[i] >> 2;
-                       i++;
-                       if (i < dws)
-                               data |= (src_ptr[i] >> 2) << 16;
-                       j = (((i - 1) * 3) / 2);
-                       dst_ptr[j] = data;
+               if (rdev->family >= CHIP_TAHITI) {
+                       /* SI */
+                       for (i = 0; i < dws; i++)
+                               dst_ptr[i] = src_ptr[i];
+               } else {
+                       /* ON/LN/TN */
+                       /* format:
+                        * dw0: (reg2 << 16) | reg1
+                        * dw1: reg1 save space
+                        * dw2: reg2 save space
+                        */
+                       for (i = 0; i < dws; i++) {
+                               data = src_ptr[i] >> 2;
+                               i++;
+                               if (i < dws)
+                                       data |= (src_ptr[i] >> 2) << 16;
+                               j = (((i - 1) * 3) / 2);
+                               dst_ptr[j] = data;
+                       }
+                       j = ((i * 3) / 2);
+                       dst_ptr[j] = RLC_SAVE_RESTORE_LIST_END_MARKER;
                }
-               j = ((i * 3) / 2);
-               dst_ptr[j] = RLC_SAVE_RESTORE_LIST_END_MARKER;
-
                radeon_bo_kunmap(rdev->rlc.save_restore_obj);
                radeon_bo_unreserve(rdev->rlc.save_restore_obj);
        }
@@ -5152,7 +5157,8 @@ static int evergreen_startup(struct radeon_device *rdev)
        /* allocate rlc buffers */
        if (rdev->flags & RADEON_IS_IGP) {
                rdev->rlc.reg_list = sumo_rlc_save_restore_register_list;
-               rdev->rlc.reg_list_size = sumo_rlc_save_restore_register_list_size;
+               rdev->rlc.reg_list_size =
+                       (u32)ARRAY_SIZE(sumo_rlc_save_restore_register_list);
                rdev->rlc.cs_data = evergreen_cs_data;
                r = sumo_rlc_init(rdev);
                if (r) {
index acdd603..21f2ece 100644 (file)
@@ -35,7 +35,7 @@
 #include "radeon_ucode.h"
 #include "clearstate_cayman.h"
 
-static u32 tn_rlc_save_restore_register_list[] =
+static const u32 tn_rlc_save_restore_register_list[] =
 {
        0x98fc,
        0x98f0,
@@ -160,7 +160,6 @@ static u32 tn_rlc_save_restore_register_list[] =
        0x9830,
        0x802c,
 };
-static u32 tn_rlc_save_restore_register_list_size = ARRAY_SIZE(tn_rlc_save_restore_register_list);
 
 extern bool evergreen_is_display_hung(struct radeon_device *rdev);
 extern void evergreen_print_gpu_status_regs(struct radeon_device *rdev);
@@ -2121,7 +2120,8 @@ static int cayman_startup(struct radeon_device *rdev)
        /* allocate rlc buffers */
        if (rdev->flags & RADEON_IS_IGP) {
                rdev->rlc.reg_list = tn_rlc_save_restore_register_list;
-               rdev->rlc.reg_list_size = tn_rlc_save_restore_register_list_size;
+               rdev->rlc.reg_list_size =
+                       (u32)ARRAY_SIZE(tn_rlc_save_restore_register_list);
                rdev->rlc.cs_data = cayman_cs_data;
                r = sumo_rlc_init(rdev);
                if (r) {
index 0347828..b9706e8 100644 (file)
@@ -854,13 +854,13 @@ struct radeon_rlc {
        struct radeon_bo        *save_restore_obj;
        uint64_t                save_restore_gpu_addr;
        volatile uint32_t       *sr_ptr;
-       u32                     *reg_list;
+       const u32               *reg_list;
        u32                     reg_list_size;
        /* for clear state */
        struct radeon_bo        *clear_state_obj;
        uint64_t                clear_state_gpu_addr;
        volatile uint32_t       *cs_ptr;
-       struct cs_section_def   *cs_data;
+       const struct cs_section_def   *cs_data;
 };
 
 int radeon_ib_get(struct radeon_device *rdev, int ring,
index 610adfc..8b8963d 100644 (file)
@@ -68,6 +68,8 @@ MODULE_FIRMWARE("radeon/HAINAN_smc.bin");
 
 static void si_pcie_gen3_enable(struct radeon_device *rdev);
 static void si_program_aspm(struct radeon_device *rdev);
+extern void sumo_rlc_fini(struct radeon_device *rdev);
+extern int sumo_rlc_init(struct radeon_device *rdev);
 extern int r600_ih_ring_alloc(struct radeon_device *rdev);
 extern void r600_ih_ring_fini(struct radeon_device *rdev);
 extern void evergreen_fix_pci_max_read_req_size(struct radeon_device *rdev);
@@ -5275,166 +5277,6 @@ static void si_fini_pg(struct radeon_device *rdev)
 /*
  * RLC
  */
-void si_rlc_fini(struct radeon_device *rdev)
-{
-       int r;
-
-       /* save restore block */
-       if (rdev->rlc.save_restore_obj) {
-               r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
-               if (unlikely(r != 0))
-                       dev_warn(rdev->dev, "(%d) reserve RLC sr bo failed\n", r);
-               radeon_bo_unpin(rdev->rlc.save_restore_obj);
-               radeon_bo_unreserve(rdev->rlc.save_restore_obj);
-
-               radeon_bo_unref(&rdev->rlc.save_restore_obj);
-               rdev->rlc.save_restore_obj = NULL;
-       }
-
-       /* clear state block */
-       if (rdev->rlc.clear_state_obj) {
-               r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
-               if (unlikely(r != 0))
-                       dev_warn(rdev->dev, "(%d) reserve RLC c bo failed\n", r);
-               radeon_bo_unpin(rdev->rlc.clear_state_obj);
-               radeon_bo_unreserve(rdev->rlc.clear_state_obj);
-
-               radeon_bo_unref(&rdev->rlc.clear_state_obj);
-               rdev->rlc.clear_state_obj = NULL;
-       }
-}
-
-#define RLC_CLEAR_STATE_END_MARKER          0x00000001
-
-int si_rlc_init(struct radeon_device *rdev)
-{
-       volatile u32 *dst_ptr;
-       u32 dws, data, i, j, k, reg_num;
-       u32 reg_list_num, reg_list_hdr_blk_index, reg_list_blk_index;
-       u64 reg_list_mc_addr;
-       const struct cs_section_def *cs_data = si_cs_data;
-       int r;
-
-       /* save restore block */
-       if (rdev->rlc.save_restore_obj == NULL) {
-               r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
-                                    RADEON_GEM_DOMAIN_VRAM, NULL,
-                                    &rdev->rlc.save_restore_obj);
-               if (r) {
-                       dev_warn(rdev->dev, "(%d) create RLC sr bo failed\n", r);
-                       return r;
-               }
-       }
-
-       r = radeon_bo_reserve(rdev->rlc.save_restore_obj, false);
-       if (unlikely(r != 0)) {
-               si_rlc_fini(rdev);
-               return r;
-       }
-       r = radeon_bo_pin(rdev->rlc.save_restore_obj, RADEON_GEM_DOMAIN_VRAM,
-                         &rdev->rlc.save_restore_gpu_addr);
-       if (r) {
-               radeon_bo_unreserve(rdev->rlc.save_restore_obj);
-               dev_warn(rdev->dev, "(%d) pin RLC sr bo failed\n", r);
-               si_rlc_fini(rdev);
-               return r;
-       }
-
-       if (rdev->family == CHIP_VERDE) {
-               r = radeon_bo_kmap(rdev->rlc.save_restore_obj, (void **)&rdev->rlc.sr_ptr);
-               if (r) {
-                       dev_warn(rdev->dev, "(%d) map RLC sr bo failed\n", r);
-                       si_rlc_fini(rdev);
-               return r;
-               }
-               /* write the sr buffer */
-               dst_ptr = rdev->rlc.sr_ptr;
-               for (i = 0; i < ARRAY_SIZE(verde_rlc_save_restore_register_list); i++) {
-                       dst_ptr[i] = verde_rlc_save_restore_register_list[i];
-               }
-               radeon_bo_kunmap(rdev->rlc.save_restore_obj);
-       }
-       radeon_bo_unreserve(rdev->rlc.save_restore_obj);
-
-       /* clear state block */
-       reg_list_num = 0;
-       dws = 0;
-       for (i = 0; cs_data[i].section != NULL; i++) {
-               for (j = 0; cs_data[i].section[j].extent != NULL; j++) {
-                       reg_list_num++;
-                       dws += cs_data[i].section[j].reg_count;
-               }
-       }
-       reg_list_blk_index = (3 * reg_list_num + 2);
-       dws += reg_list_blk_index;
-
-       if (rdev->rlc.clear_state_obj == NULL) {
-               r = radeon_bo_create(rdev, dws * 4, PAGE_SIZE, true,
-                                    RADEON_GEM_DOMAIN_VRAM, NULL, &rdev->rlc.clear_state_obj);
-               if (r) {
-                       dev_warn(rdev->dev, "(%d) create RLC c bo failed\n", r);
-                       si_rlc_fini(rdev);
-                       return r;
-               }
-       }
-       r = radeon_bo_reserve(rdev->rlc.clear_state_obj, false);
-       if (unlikely(r != 0)) {
-               si_rlc_fini(rdev);
-               return r;
-       }
-       r = radeon_bo_pin(rdev->rlc.clear_state_obj, RADEON_GEM_DOMAIN_VRAM,
-                         &rdev->rlc.clear_state_gpu_addr);
-       if (r) {
-
-               radeon_bo_unreserve(rdev->rlc.clear_state_obj);
-               dev_warn(rdev->dev, "(%d) pin RLC c bo failed\n", r);
-               si_rlc_fini(rdev);
-               return r;
-       }
-       r = radeon_bo_kmap(rdev->rlc.clear_state_obj, (void **)&rdev->rlc.cs_ptr);
-       if (r) {
-               dev_warn(rdev->dev, "(%d) map RLC c bo failed\n", r);
-               si_rlc_fini(rdev);
-               return r;
-       }
-       /* set up the cs buffer */
-       dst_ptr = rdev->rlc.cs_ptr;
-       reg_list_hdr_blk_index = 0;
-       reg_list_mc_addr = rdev->rlc.clear_state_gpu_addr + (reg_list_blk_index * 4);
-       data = upper_32_bits(reg_list_mc_addr);
-       dst_ptr[reg_list_hdr_blk_index] = data;
-       reg_list_hdr_blk_index++;
-       for (i = 0; cs_data[i].section != NULL; i++) {
-               for (j = 0; cs_data[i].section[j].extent != NULL; j++) {
-                       reg_num = cs_data[i].section[j].reg_count;
-                       data = reg_list_mc_addr & 0xffffffff;
-                       dst_ptr[reg_list_hdr_blk_index] = data;
-                       reg_list_hdr_blk_index++;
-
-                       data = (cs_data[i].section[j].reg_index * 4) & 0xffffffff;
-                       dst_ptr[reg_list_hdr_blk_index] = data;
-                       reg_list_hdr_blk_index++;
-
-                       data = 0x08000000 | (reg_num * 4);
-                       dst_ptr[reg_list_hdr_blk_index] = data;
-                       reg_list_hdr_blk_index++;
-
-                       for (k = 0; k < reg_num; k++) {
-                               data = cs_data[i].section[j].extent[k];
-                               dst_ptr[reg_list_blk_index + k] = data;
-                       }
-                       reg_list_mc_addr += reg_num * 4;
-                       reg_list_blk_index += reg_num;
-               }
-       }
-       dst_ptr[reg_list_hdr_blk_index] = RLC_CLEAR_STATE_END_MARKER;
-
-       radeon_bo_kunmap(rdev->rlc.clear_state_obj);
-       radeon_bo_unreserve(rdev->rlc.clear_state_obj);
-
-       return 0;
-}
-
 void si_rlc_reset(struct radeon_device *rdev)
 {
        u32 tmp = RREG32(GRBM_SOFT_RESET);
@@ -6449,7 +6291,13 @@ static int si_startup(struct radeon_device *rdev)
        si_gpu_init(rdev);
 
        /* allocate rlc buffers */
-       r = si_rlc_init(rdev);
+       if (rdev->family == CHIP_VERDE) {
+               rdev->rlc.reg_list = verde_rlc_save_restore_register_list;
+               rdev->rlc.reg_list_size =
+                       (u32)ARRAY_SIZE(verde_rlc_save_restore_register_list);
+       }
+       rdev->rlc.cs_data = si_cs_data;
+       r = sumo_rlc_init(rdev);
        if (r) {
                DRM_ERROR("Failed to init rlc BOs!\n");
                return r;
@@ -6735,7 +6583,7 @@ int si_init(struct radeon_device *rdev)
                si_cp_fini(rdev);
                cayman_dma_fini(rdev);
                si_irq_fini(rdev);
-               si_rlc_fini(rdev);
+               sumo_rlc_fini(rdev);
                radeon_wb_fini(rdev);
                radeon_ib_pool_fini(rdev);
                radeon_vm_manager_fini(rdev);
@@ -6761,7 +6609,7 @@ void si_fini(struct radeon_device *rdev)
        si_cp_fini(rdev);
        cayman_dma_fini(rdev);
        si_irq_fini(rdev);
-       si_rlc_fini(rdev);
+       sumo_rlc_fini(rdev);
        si_fini_cg(rdev);
        si_fini_pg(rdev);
        radeon_wb_fini(rdev);