diff options
author | Konsta Holtta <kholtta@nvidia.com> | 2014-12-31 03:37:36 -0500 |
---|---|---|
committer | Dan Willemsen <dwillemsen@nvidia.com> | 2015-04-04 18:06:38 -0400 |
commit | 4ccb162da7a2414c344aecc9cdf85bee9c284caf (patch) | |
tree | 8387c9c2ab9b3fbbbb83f312f96e5210027c62fb /drivers/gpu/nvgpu/gk20a/mm_gk20a.c | |
parent | 364156cdcd706510bc37b93a3c7109b45b02d318 (diff) |
gpu: nvgpu: unify instance block creation
Reduce copypaste code in instance block allocation and deletion with
functions purposed for that.
Change-Id: I2c8ae6a317ac89e2c857dde4296cb4316b8aaafe
Signed-off-by: Konsta Holtta <kholtta@nvidia.com>
Reviewed-on: http://git-master/r/668698
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Tested-by: Terje Bergstrom <tbergstrom@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/mm_gk20a.c')
-rw-r--r-- | drivers/gpu/nvgpu/gk20a/mm_gk20a.c | 94 |
1 files changed, 42 insertions, 52 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c index 7695f147..949237b1 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c | |||
@@ -2656,6 +2656,44 @@ static void gk20a_deinit_vm(struct vm_gk20a *vm) | |||
2656 | kfree(vm->pdes.ptes[gmmu_page_size_big]); | 2656 | kfree(vm->pdes.ptes[gmmu_page_size_big]); |
2657 | } | 2657 | } |
2658 | 2658 | ||
2659 | int gk20a_alloc_inst_block(struct gk20a *g, struct inst_desc *inst_block) | ||
2660 | { | ||
2661 | struct device *dev = dev_from_gk20a(g); | ||
2662 | dma_addr_t iova; | ||
2663 | |||
2664 | inst_block->size = ram_in_alloc_size_v(); | ||
2665 | inst_block->cpuva = dma_alloc_coherent(dev, inst_block->size, | ||
2666 | &iova, GFP_KERNEL); | ||
2667 | if (!inst_block->cpuva) { | ||
2668 | gk20a_err(dev, "%s: memory allocation failed\n", __func__); | ||
2669 | return -ENOMEM; | ||
2670 | } | ||
2671 | |||
2672 | inst_block->iova = iova; | ||
2673 | inst_block->cpu_pa = gk20a_get_phys_from_iova(dev, inst_block->iova); | ||
2674 | if (!inst_block->cpu_pa) { | ||
2675 | gk20a_err(dev, "%s: failed to get phys address\n", __func__); | ||
2676 | gk20a_free_inst_block(g, inst_block); | ||
2677 | return -ENOMEM; | ||
2678 | } | ||
2679 | |||
2680 | memset(inst_block->cpuva, 0, inst_block->size); | ||
2681 | |||
2682 | return 0; | ||
2683 | } | ||
2684 | |||
2685 | void gk20a_free_inst_block(struct gk20a *g, struct inst_desc *inst_block) | ||
2686 | { | ||
2687 | struct device *dev = dev_from_gk20a(g); | ||
2688 | |||
2689 | if (inst_block->cpuva) { | ||
2690 | dma_free_coherent(dev, inst_block->size, | ||
2691 | inst_block->cpuva, inst_block->iova); | ||
2692 | } | ||
2693 | |||
2694 | memset(inst_block, 0, sizeof(*inst_block)); | ||
2695 | } | ||
2696 | |||
2659 | static int gk20a_init_bar1_vm(struct mm_gk20a *mm) | 2697 | static int gk20a_init_bar1_vm(struct mm_gk20a *mm) |
2660 | { | 2698 | { |
2661 | int err; | 2699 | int err; |
@@ -2666,9 +2704,7 @@ static int gk20a_init_bar1_vm(struct mm_gk20a *mm) | |||
2666 | u64 pde_addr; | 2704 | u64 pde_addr; |
2667 | u32 pde_addr_lo; | 2705 | u32 pde_addr_lo; |
2668 | u32 pde_addr_hi; | 2706 | u32 pde_addr_hi; |
2669 | struct device *d = dev_from_gk20a(g); | ||
2670 | struct inst_desc *inst_block = &mm->bar1.inst_block; | 2707 | struct inst_desc *inst_block = &mm->bar1.inst_block; |
2671 | dma_addr_t iova; | ||
2672 | u32 big_page_size = gk20a_get_platform(g->dev)->default_big_page_size; | 2708 | u32 big_page_size = gk20a_get_platform(g->dev)->default_big_page_size; |
2673 | 2709 | ||
2674 | mm->bar1.aperture_size = bar1_aperture_size_mb_gk20a() << 20; | 2710 | mm->bar1.aperture_size = bar1_aperture_size_mb_gk20a() << 20; |
@@ -2683,23 +2719,9 @@ static int gk20a_init_bar1_vm(struct mm_gk20a *mm) | |||
2683 | pde_addr_lo = u64_lo32(pde_addr >> ram_in_base_shift_v()); | 2719 | pde_addr_lo = u64_lo32(pde_addr >> ram_in_base_shift_v()); |
2684 | pde_addr_hi = u64_hi32(pde_addr); | 2720 | pde_addr_hi = u64_hi32(pde_addr); |
2685 | 2721 | ||
2686 | /* allocate instance mem for bar1 */ | 2722 | err = gk20a_alloc_inst_block(g, inst_block); |
2687 | inst_block->size = ram_in_alloc_size_v(); | 2723 | if (err) |
2688 | inst_block->cpuva = dma_alloc_coherent(d, inst_block->size, | ||
2689 | &iova, GFP_KERNEL); | ||
2690 | if (!inst_block->cpuva) { | ||
2691 | gk20a_err(d, "%s: memory allocation failed\n", __func__); | ||
2692 | err = -ENOMEM; | ||
2693 | goto clean_up_va; | 2724 | goto clean_up_va; |
2694 | } | ||
2695 | |||
2696 | inst_block->iova = iova; | ||
2697 | inst_block->cpu_pa = gk20a_get_phys_from_iova(d, inst_block->iova); | ||
2698 | if (!inst_block->cpu_pa) { | ||
2699 | gk20a_err(d, "%s: failed to get phys address\n", __func__); | ||
2700 | err = -ENOMEM; | ||
2701 | goto clean_up_inst_block; | ||
2702 | } | ||
2703 | 2725 | ||
2704 | inst_pa = inst_block->cpu_pa; | 2726 | inst_pa = inst_block->cpu_pa; |
2705 | inst_ptr = inst_block->cpuva; | 2727 | inst_ptr = inst_block->cpuva; |
@@ -2707,8 +2729,6 @@ static int gk20a_init_bar1_vm(struct mm_gk20a *mm) | |||
2707 | gk20a_dbg_info("bar1 inst block physical phys = 0x%llx, kv = 0x%p", | 2729 | gk20a_dbg_info("bar1 inst block physical phys = 0x%llx, kv = 0x%p", |
2708 | (u64)inst_pa, inst_ptr); | 2730 | (u64)inst_pa, inst_ptr); |
2709 | 2731 | ||
2710 | memset(inst_ptr, 0, inst_block->size); | ||
2711 | |||
2712 | gk20a_mem_wr32(inst_ptr, ram_in_page_dir_base_lo_w(), | 2732 | gk20a_mem_wr32(inst_ptr, ram_in_page_dir_base_lo_w(), |
2713 | ram_in_page_dir_base_target_vid_mem_f() | | 2733 | ram_in_page_dir_base_target_vid_mem_f() | |
2714 | ram_in_page_dir_base_vol_true_f() | | 2734 | ram_in_page_dir_base_vol_true_f() | |
@@ -2729,12 +2749,6 @@ static int gk20a_init_bar1_vm(struct mm_gk20a *mm) | |||
2729 | gk20a_dbg_info("bar1 inst block ptr: %08llx", (u64)inst_pa); | 2749 | gk20a_dbg_info("bar1 inst block ptr: %08llx", (u64)inst_pa); |
2730 | return 0; | 2750 | return 0; |
2731 | 2751 | ||
2732 | clean_up_inst_block: | ||
2733 | if (inst_block->cpuva) | ||
2734 | dma_free_coherent(d, inst_block->size, | ||
2735 | inst_block->cpuva, inst_block->iova); | ||
2736 | inst_block->cpuva = NULL; | ||
2737 | inst_block->iova = 0; | ||
2738 | clean_up_va: | 2752 | clean_up_va: |
2739 | gk20a_deinit_vm(vm); | 2753 | gk20a_deinit_vm(vm); |
2740 | return err; | 2754 | return err; |
@@ -2751,9 +2765,7 @@ static int gk20a_init_system_vm(struct mm_gk20a *mm) | |||
2751 | u64 pde_addr; | 2765 | u64 pde_addr; |
2752 | u32 pde_addr_lo; | 2766 | u32 pde_addr_lo; |
2753 | u32 pde_addr_hi; | 2767 | u32 pde_addr_hi; |
2754 | struct device *d = dev_from_gk20a(g); | ||
2755 | struct inst_desc *inst_block = &mm->pmu.inst_block; | 2768 | struct inst_desc *inst_block = &mm->pmu.inst_block; |
2756 | dma_addr_t iova; | ||
2757 | u32 big_page_size = gk20a_get_platform(g->dev)->default_big_page_size; | 2769 | u32 big_page_size = gk20a_get_platform(g->dev)->default_big_page_size; |
2758 | 2770 | ||
2759 | mm->pmu.aperture_size = GK20A_PMU_VA_SIZE; | 2771 | mm->pmu.aperture_size = GK20A_PMU_VA_SIZE; |
@@ -2769,31 +2781,15 @@ static int gk20a_init_system_vm(struct mm_gk20a *mm) | |||
2769 | pde_addr_lo = u64_lo32(pde_addr >> ram_in_base_shift_v()); | 2781 | pde_addr_lo = u64_lo32(pde_addr >> ram_in_base_shift_v()); |
2770 | pde_addr_hi = u64_hi32(pde_addr); | 2782 | pde_addr_hi = u64_hi32(pde_addr); |
2771 | 2783 | ||
2772 | /* allocate instance mem for pmu */ | 2784 | err = gk20a_alloc_inst_block(g, inst_block); |
2773 | inst_block->size = ram_in_alloc_size_v(); | 2785 | if (err) |
2774 | inst_block->cpuva = dma_alloc_coherent(d, inst_block->size, | ||
2775 | &iova, GFP_KERNEL); | ||
2776 | if (!inst_block->cpuva) { | ||
2777 | gk20a_err(d, "%s: memory allocation failed\n", __func__); | ||
2778 | err = -ENOMEM; | ||
2779 | goto clean_up_va; | 2786 | goto clean_up_va; |
2780 | } | ||
2781 | |||
2782 | inst_block->iova = iova; | ||
2783 | inst_block->cpu_pa = gk20a_get_phys_from_iova(d, inst_block->iova); | ||
2784 | if (!inst_block->cpu_pa) { | ||
2785 | gk20a_err(d, "%s: failed to get phys address\n", __func__); | ||
2786 | err = -ENOMEM; | ||
2787 | goto clean_up_inst_block; | ||
2788 | } | ||
2789 | 2787 | ||
2790 | inst_pa = inst_block->cpu_pa; | 2788 | inst_pa = inst_block->cpu_pa; |
2791 | inst_ptr = inst_block->cpuva; | 2789 | inst_ptr = inst_block->cpuva; |
2792 | 2790 | ||
2793 | gk20a_dbg_info("pmu inst block physical addr: 0x%llx", (u64)inst_pa); | 2791 | gk20a_dbg_info("pmu inst block physical addr: 0x%llx", (u64)inst_pa); |
2794 | 2792 | ||
2795 | memset(inst_ptr, 0, inst_block->size); | ||
2796 | |||
2797 | gk20a_mem_wr32(inst_ptr, ram_in_page_dir_base_lo_w(), | 2793 | gk20a_mem_wr32(inst_ptr, ram_in_page_dir_base_lo_w(), |
2798 | ram_in_page_dir_base_target_vid_mem_f() | | 2794 | ram_in_page_dir_base_target_vid_mem_f() | |
2799 | ram_in_page_dir_base_vol_true_f() | | 2795 | ram_in_page_dir_base_vol_true_f() | |
@@ -2813,12 +2809,6 @@ static int gk20a_init_system_vm(struct mm_gk20a *mm) | |||
2813 | 2809 | ||
2814 | return 0; | 2810 | return 0; |
2815 | 2811 | ||
2816 | clean_up_inst_block: | ||
2817 | if (inst_block->cpuva) | ||
2818 | dma_free_coherent(d, inst_block->size, | ||
2819 | inst_block->cpuva, inst_block->iova); | ||
2820 | inst_block->cpuva = NULL; | ||
2821 | inst_block->iova = 0; | ||
2822 | clean_up_va: | 2812 | clean_up_va: |
2823 | gk20a_deinit_vm(vm); | 2813 | gk20a_deinit_vm(vm); |
2824 | return err; | 2814 | return err; |