mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
Split as_gk20a.c into two parts: common/linux/ioctl_as.c deals with as related devnodes and ioctls. This file contains all the Linux specific parts of as_gk20a.c. common/as.c deals with general as_gk20a maintenance and is Linux independent. JIRA NVGPU-16 Change-Id: I2d8541e0bd6ce159dc6e4de8e819dfcff0fa8f80 Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-on: http://git-master/r/1330803 Reviewed-by: svccoveritychecker <svccoveritychecker@nvidia.com> GVS: Gerrit_Virtual_Submit
100 lines
2.0 KiB
C
100 lines
2.0 KiB
C
/*
|
|
* GK20A Address Spaces
|
|
*
|
|
* Copyright (c) 2011-2017, NVIDIA CORPORATION. All rights reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms and conditions of the GNU General Public License,
|
|
* version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*/
|
|
|
|
#include <trace/events/gk20a.h>
|
|
|
|
#include <nvgpu/kmem.h>
|
|
|
|
#include "gk20a/gk20a.h"
|
|
|
|
/* dumb allocator... */
|
|
static int generate_as_share_id(struct gk20a_as *as)
|
|
{
|
|
gk20a_dbg_fn("");
|
|
return ++as->last_share_id;
|
|
}
|
|
/* still dumb */
|
|
static void release_as_share_id(struct gk20a_as *as, int id)
|
|
{
|
|
gk20a_dbg_fn("");
|
|
return;
|
|
}
|
|
|
|
int gk20a_as_alloc_share(struct gk20a *g,
|
|
u32 big_page_size, u32 flags,
|
|
struct gk20a_as_share **out)
|
|
{
|
|
struct gk20a_as_share *as_share;
|
|
int err = 0;
|
|
|
|
gk20a_dbg_fn("");
|
|
g = gk20a_get(g);
|
|
if (!g)
|
|
return -ENODEV;
|
|
|
|
*out = NULL;
|
|
as_share = nvgpu_kzalloc(g, sizeof(*as_share));
|
|
if (!as_share)
|
|
return -ENOMEM;
|
|
|
|
as_share->as = &g->as;
|
|
as_share->id = generate_as_share_id(as_share->as);
|
|
|
|
/* this will set as_share->vm. */
|
|
err = gk20a_busy(g);
|
|
if (err)
|
|
goto failed;
|
|
err = g->ops.mm.vm_alloc_share(as_share, big_page_size, flags);
|
|
gk20a_idle(g);
|
|
|
|
if (err)
|
|
goto failed;
|
|
|
|
*out = as_share;
|
|
return 0;
|
|
|
|
failed:
|
|
nvgpu_kfree(g, as_share);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* channels and the device nodes call this to release.
|
|
* once the ref_cnt hits zero the share is deleted.
|
|
*/
|
|
int gk20a_as_release_share(struct gk20a_as_share *as_share)
|
|
{
|
|
struct gk20a *g = as_share->vm->mm->g;
|
|
int err;
|
|
|
|
gk20a_dbg_fn("");
|
|
|
|
err = gk20a_busy(g);
|
|
|
|
if (err)
|
|
goto release_fail;
|
|
|
|
err = gk20a_vm_release_share(as_share);
|
|
|
|
gk20a_idle(g);
|
|
|
|
release_fail:
|
|
release_as_share_id(as_share->as, as_share->id);
|
|
gk20a_put(g);
|
|
nvgpu_kfree(g, as_share);
|
|
|
|
return err;
|
|
}
|