Path: blob/master/drivers/accel/habanalabs/common/asid.c
26450 views
// SPDX-License-Identifier: GPL-2.012/*3* Copyright 2016-2019 HabanaLabs, Ltd.4* All Rights Reserved.5*/67#include "habanalabs.h"89#include <linux/slab.h>1011int hl_asid_init(struct hl_device *hdev)12{13hdev->asid_bitmap = bitmap_zalloc(hdev->asic_prop.max_asid, GFP_KERNEL);14if (!hdev->asid_bitmap)15return -ENOMEM;1617mutex_init(&hdev->asid_mutex);1819/* ASID 0 is reserved for the kernel driver and device CPU */20set_bit(0, hdev->asid_bitmap);2122return 0;23}2425void hl_asid_fini(struct hl_device *hdev)26{27mutex_destroy(&hdev->asid_mutex);28bitmap_free(hdev->asid_bitmap);29}3031unsigned long hl_asid_alloc(struct hl_device *hdev)32{33unsigned long found;3435mutex_lock(&hdev->asid_mutex);3637found = find_first_zero_bit(hdev->asid_bitmap,38hdev->asic_prop.max_asid);39if (found == hdev->asic_prop.max_asid)40found = 0;41else42set_bit(found, hdev->asid_bitmap);4344mutex_unlock(&hdev->asid_mutex);4546return found;47}4849void hl_asid_free(struct hl_device *hdev, unsigned long asid)50{51if (asid == HL_KERNEL_ASID_ID || asid >= hdev->asic_prop.max_asid) {52dev_crit(hdev->dev, "Invalid ASID %lu", asid);53return;54}5556clear_bit(asid, hdev->asid_bitmap);57}585960