Path: blob/master/arch/powerpc/platforms/cell/spufs/gang.c
26498 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* SPU file system3*4* (C) Copyright IBM Deutschland Entwicklung GmbH 20055*6* Author: Arnd Bergmann <[email protected]>7*/89#include <linux/list.h>10#include <linux/slab.h>1112#include "spufs.h"1314struct spu_gang *alloc_spu_gang(void)15{16struct spu_gang *gang;1718gang = kzalloc(sizeof *gang, GFP_KERNEL);19if (!gang)20goto out;2122kref_init(&gang->kref);23mutex_init(&gang->mutex);24mutex_init(&gang->aff_mutex);25INIT_LIST_HEAD(&gang->list);26INIT_LIST_HEAD(&gang->aff_list_head);27gang->alive = 1;2829out:30return gang;31}3233static void destroy_spu_gang(struct kref *kref)34{35struct spu_gang *gang;36gang = container_of(kref, struct spu_gang, kref);37WARN_ON(gang->contexts || !list_empty(&gang->list));38kfree(gang);39}4041struct spu_gang *get_spu_gang(struct spu_gang *gang)42{43kref_get(&gang->kref);44return gang;45}4647int put_spu_gang(struct spu_gang *gang)48{49return kref_put(&gang->kref, &destroy_spu_gang);50}5152void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx)53{54mutex_lock(&gang->mutex);55ctx->gang = get_spu_gang(gang);56list_add(&ctx->gang_list, &gang->list);57gang->contexts++;58mutex_unlock(&gang->mutex);59}6061void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx)62{63mutex_lock(&gang->mutex);64WARN_ON(ctx->gang != gang);65if (!list_empty(&ctx->aff_list)) {66list_del_init(&ctx->aff_list);67gang->aff_flags &= ~AFF_OFFSETS_SET;68}69list_del_init(&ctx->gang_list);70gang->contexts--;71mutex_unlock(&gang->mutex);7273put_spu_gang(gang);74}757677