mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-25 11:04:51 +03:00
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>
This commit is contained in:
committed by
Dan Willemsen
parent
364156cdcd
commit
4ccb162da7
@@ -341,54 +341,24 @@ void channel_gk20a_unbind(struct channel_gk20a *ch_gk20a)
|
||||
|
||||
int channel_gk20a_alloc_inst(struct gk20a *g, struct channel_gk20a *ch)
|
||||
{
|
||||
struct device *d = dev_from_gk20a(g);
|
||||
int err = 0;
|
||||
dma_addr_t iova;
|
||||
int err;
|
||||
|
||||
gk20a_dbg_fn("");
|
||||
|
||||
ch->inst_block.size = ram_in_alloc_size_v();
|
||||
ch->inst_block.cpuva = dma_alloc_coherent(d,
|
||||
ch->inst_block.size,
|
||||
&iova,
|
||||
GFP_KERNEL);
|
||||
if (!ch->inst_block.cpuva) {
|
||||
gk20a_err(d, "%s: memory allocation failed\n", __func__);
|
||||
err = -ENOMEM;
|
||||
goto clean_up;
|
||||
}
|
||||
|
||||
ch->inst_block.iova = iova;
|
||||
ch->inst_block.cpu_pa = gk20a_get_phys_from_iova(d,
|
||||
ch->inst_block.iova);
|
||||
if (!ch->inst_block.cpu_pa) {
|
||||
gk20a_err(d, "%s: failed to get physical address\n", __func__);
|
||||
err = -ENOMEM;
|
||||
goto clean_up;
|
||||
}
|
||||
err = gk20a_alloc_inst_block(g, &ch->inst_block);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
gk20a_dbg_info("channel %d inst block physical addr: 0x%16llx",
|
||||
ch->hw_chid, (u64)ch->inst_block.cpu_pa);
|
||||
|
||||
gk20a_dbg_fn("done");
|
||||
return 0;
|
||||
|
||||
clean_up:
|
||||
gk20a_err(d, "fail");
|
||||
g->ops.fifo.free_inst(g, ch);
|
||||
return err;
|
||||
}
|
||||
|
||||
void channel_gk20a_free_inst(struct gk20a *g, struct channel_gk20a *ch)
|
||||
{
|
||||
struct device *d = dev_from_gk20a(g);
|
||||
|
||||
if (ch->inst_block.cpuva)
|
||||
dma_free_coherent(d, ch->inst_block.size,
|
||||
ch->inst_block.cpuva, ch->inst_block.iova);
|
||||
ch->inst_block.cpuva = NULL;
|
||||
ch->inst_block.iova = 0;
|
||||
memset(&ch->inst_block, 0, sizeof(struct inst_desc));
|
||||
gk20a_free_inst_block(g, &ch->inst_block);
|
||||
}
|
||||
|
||||
static int channel_gk20a_update_runlist(struct channel_gk20a *c, bool add)
|
||||
|
||||
@@ -1687,22 +1687,11 @@ static int gr_gk20a_init_ctxsw_ucode_vaspace(struct gk20a *g)
|
||||
u32 pde_addr_lo;
|
||||
u32 pde_addr_hi;
|
||||
u64 pde_addr;
|
||||
dma_addr_t iova;
|
||||
int err;
|
||||
|
||||
/* Alloc mem of inst block */
|
||||
ucode_info->inst_blk_desc.size = ram_in_alloc_size_v();
|
||||
ucode_info->inst_blk_desc.cpuva = dma_alloc_coherent(d,
|
||||
ucode_info->inst_blk_desc.size,
|
||||
&iova,
|
||||
GFP_KERNEL);
|
||||
if (!ucode_info->inst_blk_desc.cpuva) {
|
||||
gk20a_err(d, "failed to allocate memory\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ucode_info->inst_blk_desc.iova = iova;
|
||||
ucode_info->inst_blk_desc.cpu_pa = gk20a_get_phys_from_iova(d,
|
||||
ucode_info->inst_blk_desc.iova);
|
||||
err = gk20a_alloc_inst_block(g, &ucode_info->inst_blk_desc);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
inst_ptr = ucode_info->inst_blk_desc.cpuva;
|
||||
|
||||
|
||||
@@ -2656,6 +2656,44 @@ static void gk20a_deinit_vm(struct vm_gk20a *vm)
|
||||
kfree(vm->pdes.ptes[gmmu_page_size_big]);
|
||||
}
|
||||
|
||||
int gk20a_alloc_inst_block(struct gk20a *g, struct inst_desc *inst_block)
|
||||
{
|
||||
struct device *dev = dev_from_gk20a(g);
|
||||
dma_addr_t iova;
|
||||
|
||||
inst_block->size = ram_in_alloc_size_v();
|
||||
inst_block->cpuva = dma_alloc_coherent(dev, inst_block->size,
|
||||
&iova, GFP_KERNEL);
|
||||
if (!inst_block->cpuva) {
|
||||
gk20a_err(dev, "%s: memory allocation failed\n", __func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
inst_block->iova = iova;
|
||||
inst_block->cpu_pa = gk20a_get_phys_from_iova(dev, inst_block->iova);
|
||||
if (!inst_block->cpu_pa) {
|
||||
gk20a_err(dev, "%s: failed to get phys address\n", __func__);
|
||||
gk20a_free_inst_block(g, inst_block);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
memset(inst_block->cpuva, 0, inst_block->size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void gk20a_free_inst_block(struct gk20a *g, struct inst_desc *inst_block)
|
||||
{
|
||||
struct device *dev = dev_from_gk20a(g);
|
||||
|
||||
if (inst_block->cpuva) {
|
||||
dma_free_coherent(dev, inst_block->size,
|
||||
inst_block->cpuva, inst_block->iova);
|
||||
}
|
||||
|
||||
memset(inst_block, 0, sizeof(*inst_block));
|
||||
}
|
||||
|
||||
static int gk20a_init_bar1_vm(struct mm_gk20a *mm)
|
||||
{
|
||||
int err;
|
||||
@@ -2666,9 +2704,7 @@ static int gk20a_init_bar1_vm(struct mm_gk20a *mm)
|
||||
u64 pde_addr;
|
||||
u32 pde_addr_lo;
|
||||
u32 pde_addr_hi;
|
||||
struct device *d = dev_from_gk20a(g);
|
||||
struct inst_desc *inst_block = &mm->bar1.inst_block;
|
||||
dma_addr_t iova;
|
||||
u32 big_page_size = gk20a_get_platform(g->dev)->default_big_page_size;
|
||||
|
||||
mm->bar1.aperture_size = bar1_aperture_size_mb_gk20a() << 20;
|
||||
@@ -2683,23 +2719,9 @@ static int gk20a_init_bar1_vm(struct mm_gk20a *mm)
|
||||
pde_addr_lo = u64_lo32(pde_addr >> ram_in_base_shift_v());
|
||||
pde_addr_hi = u64_hi32(pde_addr);
|
||||
|
||||
/* allocate instance mem for bar1 */
|
||||
inst_block->size = ram_in_alloc_size_v();
|
||||
inst_block->cpuva = dma_alloc_coherent(d, inst_block->size,
|
||||
&iova, GFP_KERNEL);
|
||||
if (!inst_block->cpuva) {
|
||||
gk20a_err(d, "%s: memory allocation failed\n", __func__);
|
||||
err = -ENOMEM;
|
||||
err = gk20a_alloc_inst_block(g, inst_block);
|
||||
if (err)
|
||||
goto clean_up_va;
|
||||
}
|
||||
|
||||
inst_block->iova = iova;
|
||||
inst_block->cpu_pa = gk20a_get_phys_from_iova(d, inst_block->iova);
|
||||
if (!inst_block->cpu_pa) {
|
||||
gk20a_err(d, "%s: failed to get phys address\n", __func__);
|
||||
err = -ENOMEM;
|
||||
goto clean_up_inst_block;
|
||||
}
|
||||
|
||||
inst_pa = inst_block->cpu_pa;
|
||||
inst_ptr = inst_block->cpuva;
|
||||
@@ -2707,8 +2729,6 @@ static int gk20a_init_bar1_vm(struct mm_gk20a *mm)
|
||||
gk20a_dbg_info("bar1 inst block physical phys = 0x%llx, kv = 0x%p",
|
||||
(u64)inst_pa, inst_ptr);
|
||||
|
||||
memset(inst_ptr, 0, inst_block->size);
|
||||
|
||||
gk20a_mem_wr32(inst_ptr, ram_in_page_dir_base_lo_w(),
|
||||
ram_in_page_dir_base_target_vid_mem_f() |
|
||||
ram_in_page_dir_base_vol_true_f() |
|
||||
@@ -2729,12 +2749,6 @@ static int gk20a_init_bar1_vm(struct mm_gk20a *mm)
|
||||
gk20a_dbg_info("bar1 inst block ptr: %08llx", (u64)inst_pa);
|
||||
return 0;
|
||||
|
||||
clean_up_inst_block:
|
||||
if (inst_block->cpuva)
|
||||
dma_free_coherent(d, inst_block->size,
|
||||
inst_block->cpuva, inst_block->iova);
|
||||
inst_block->cpuva = NULL;
|
||||
inst_block->iova = 0;
|
||||
clean_up_va:
|
||||
gk20a_deinit_vm(vm);
|
||||
return err;
|
||||
@@ -2751,9 +2765,7 @@ static int gk20a_init_system_vm(struct mm_gk20a *mm)
|
||||
u64 pde_addr;
|
||||
u32 pde_addr_lo;
|
||||
u32 pde_addr_hi;
|
||||
struct device *d = dev_from_gk20a(g);
|
||||
struct inst_desc *inst_block = &mm->pmu.inst_block;
|
||||
dma_addr_t iova;
|
||||
u32 big_page_size = gk20a_get_platform(g->dev)->default_big_page_size;
|
||||
|
||||
mm->pmu.aperture_size = GK20A_PMU_VA_SIZE;
|
||||
@@ -2769,31 +2781,15 @@ static int gk20a_init_system_vm(struct mm_gk20a *mm)
|
||||
pde_addr_lo = u64_lo32(pde_addr >> ram_in_base_shift_v());
|
||||
pde_addr_hi = u64_hi32(pde_addr);
|
||||
|
||||
/* allocate instance mem for pmu */
|
||||
inst_block->size = ram_in_alloc_size_v();
|
||||
inst_block->cpuva = dma_alloc_coherent(d, inst_block->size,
|
||||
&iova, GFP_KERNEL);
|
||||
if (!inst_block->cpuva) {
|
||||
gk20a_err(d, "%s: memory allocation failed\n", __func__);
|
||||
err = -ENOMEM;
|
||||
err = gk20a_alloc_inst_block(g, inst_block);
|
||||
if (err)
|
||||
goto clean_up_va;
|
||||
}
|
||||
|
||||
inst_block->iova = iova;
|
||||
inst_block->cpu_pa = gk20a_get_phys_from_iova(d, inst_block->iova);
|
||||
if (!inst_block->cpu_pa) {
|
||||
gk20a_err(d, "%s: failed to get phys address\n", __func__);
|
||||
err = -ENOMEM;
|
||||
goto clean_up_inst_block;
|
||||
}
|
||||
|
||||
inst_pa = inst_block->cpu_pa;
|
||||
inst_ptr = inst_block->cpuva;
|
||||
|
||||
gk20a_dbg_info("pmu inst block physical addr: 0x%llx", (u64)inst_pa);
|
||||
|
||||
memset(inst_ptr, 0, inst_block->size);
|
||||
|
||||
gk20a_mem_wr32(inst_ptr, ram_in_page_dir_base_lo_w(),
|
||||
ram_in_page_dir_base_target_vid_mem_f() |
|
||||
ram_in_page_dir_base_vol_true_f() |
|
||||
@@ -2813,12 +2809,6 @@ static int gk20a_init_system_vm(struct mm_gk20a *mm)
|
||||
|
||||
return 0;
|
||||
|
||||
clean_up_inst_block:
|
||||
if (inst_block->cpuva)
|
||||
dma_free_coherent(d, inst_block->size,
|
||||
inst_block->cpuva, inst_block->iova);
|
||||
inst_block->cpuva = NULL;
|
||||
inst_block->iova = 0;
|
||||
clean_up_va:
|
||||
gk20a_deinit_vm(vm);
|
||||
return err;
|
||||
|
||||
@@ -389,6 +389,9 @@ static inline int max_vaddr_bits_gk20a(void)
|
||||
#define bar1_instance_block_shift_gk20a() bus_bar1_block_ptr_shift_v()
|
||||
#endif
|
||||
|
||||
int gk20a_alloc_inst_block(struct gk20a *g, struct inst_desc *inst_block);
|
||||
void gk20a_free_inst_block(struct gk20a *g, struct inst_desc *inst_block);
|
||||
|
||||
void gk20a_mm_dump_vm(struct vm_gk20a *vm,
|
||||
u64 va_begin, u64 va_end, char *label);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user