Files
linux-nvgpu/drivers/gpu/nvgpu/common/pmu/pmu_mutex.c
Sagar Kamble 9a55ecb5d2 gpu: nvgpu: prepare pmu mutexes unit
PMU mutexes used by FIFO and runlists is functionality independent of
the PMU command and message management.
Remove related functionality from pmu_ipc.c and prepare pmu_mutex.c.
Prepare PMU HAL unit that contains gk20a specific PMU mutexes
handling.

JIRA NVGPU-1970

Change-Id: I0204be2ef9d2c000004667af3c18dc527d7ac25f
Signed-off-by: Sagar Kamble <skamble@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2079142
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
2019-04-05 05:05:27 -07:00

112 lines
2.9 KiB
C

/*
* Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <nvgpu/pmu/mutex.h>
#include <nvgpu/gk20a.h>
int nvgpu_pmu_mutexes_alloc(struct gk20a *g, struct pmu_mutexes *mutexes)
{
mutexes->cnt = g->ops.pmu.pmu_mutex_size();
mutexes->mutex = nvgpu_kzalloc(g, mutexes->cnt *
sizeof(struct pmu_mutex));
if (mutexes->mutex == NULL) {
return -ENOMEM;
}
return 0;
}
void nvgpu_pmu_mutexes_init(struct pmu_mutexes *mutexes)
{
u32 i;
for (i = 0; i < mutexes->cnt; i++) {
mutexes->mutex[i].id = i;
mutexes->mutex[i].index = i;
}
}
void nvgpu_pmu_mutexes_free(struct gk20a *g, struct pmu_mutexes *mutexes)
{
nvgpu_kfree(g, mutexes->mutex);
}
int nvgpu_pmu_mutex_acquire(struct gk20a *g, struct pmu_mutexes *mutexes,
u32 id, u32 *token)
{
struct pmu_mutex *mutex;
u32 owner;
int err;
WARN_ON(token == NULL);
WARN_ON(!PMU_MUTEX_ID_IS_VALID(id));
WARN_ON(id > mutexes->cnt);
mutex = &mutexes->mutex[id];
owner = g->ops.pmu.pmu_mutex_owner(g, mutexes, id);
if (*token != PMU_INVALID_MUTEX_OWNER_ID && *token == owner) {
WARN_ON(mutex->ref_cnt == 0U);
nvgpu_err(g, "already acquired by owner : 0x%08x", *token);
mutex->ref_cnt++;
return 0;
}
err = g->ops.pmu.pmu_mutex_acquire(g, mutexes, id, token);
if (err == 0) {
mutex->ref_cnt = 1;
}
return err;
}
int nvgpu_pmu_mutex_release(struct gk20a *g, struct pmu_mutexes *mutexes,
u32 id, u32 *token)
{
struct pmu_mutex *mutex;
u32 owner;
WARN_ON(token == NULL);
WARN_ON(!PMU_MUTEX_ID_IS_VALID(id));
WARN_ON(id > mutexes->cnt);
mutex = &mutexes->mutex[id];
owner = g->ops.pmu.pmu_mutex_owner(g, mutexes, id);
if (*token != owner) {
nvgpu_err(g, "requester 0x%08x NOT match owner 0x%08x",
*token, owner);
return -EINVAL;
}
if (--mutex->ref_cnt > 0U) {
return -EBUSY;
}
g->ops.pmu.pmu_mutex_release(g, mutexes, id, token);
return 0;
}