// SPDX-License-Identifier: MIT /* * Copyright © 2024 Intel Corporation */ #include <linux/bitmap.h> #include <linux/mutex.h> #include <drm/drm_managed.h> #include "xe_assert.h" #include "xe_gt_printk.h" #include "xe_guc.h" #include "xe_guc_id_mgr.h" #include "xe_guc_types.h" static struct xe_guc *idm_to_guc(struct xe_guc_id_mgr *idm) { … } static struct xe_gt *idm_to_gt(struct xe_guc_id_mgr *idm) { … } static struct xe_device *idm_to_xe(struct xe_guc_id_mgr *idm) { … } #define idm_assert(idm, cond) … #define idm_mutex(idm) … static void idm_print_locked(struct xe_guc_id_mgr *idm, struct drm_printer *p, int indent); static void __fini_idm(struct drm_device *drm, void *arg) { … } /** * xe_guc_id_mgr_init() - Initialize GuC context ID Manager. * @idm: the &xe_guc_id_mgr to initialize * @limit: number of IDs to manage * * The bare-metal or PF driver can pass ~0 as &limit to indicate that all * context IDs supported by the GuC firmware are available for use. * * Only VF drivers will have to provide explicit number of context IDs * that they can use. * * Return: 0 on success or a negative error code on failure. */ int xe_guc_id_mgr_init(struct xe_guc_id_mgr *idm, unsigned int limit) { … } static unsigned int find_last_zero_area(unsigned long *bitmap, unsigned int total, unsigned int count) { … } static int idm_reserve_chunk_locked(struct xe_guc_id_mgr *idm, unsigned int count, unsigned int retain) { … } static void idm_release_chunk_locked(struct xe_guc_id_mgr *idm, unsigned int start, unsigned int count) { … } /** * xe_guc_id_mgr_reserve_locked() - Reserve one or more GuC context IDs. * @idm: the &xe_guc_id_mgr * @count: number of IDs to allocate (can't be 0) * * This function is dedicated for the use by the GuC submission code, * where submission lock is already taken. * * Return: ID of allocated GuC context or a negative error code on failure. */ int xe_guc_id_mgr_reserve_locked(struct xe_guc_id_mgr *idm, unsigned int count) { … } /** * xe_guc_id_mgr_release_locked() - Release one or more GuC context IDs. * @idm: the &xe_guc_id_mgr * @id: the GuC context ID to release * @count: number of IDs to release (can't be 0) * * This function is dedicated for the use by the GuC submission code, * where submission lock is already taken. */ void xe_guc_id_mgr_release_locked(struct xe_guc_id_mgr *idm, unsigned int id, unsigned int count) { … } /** * xe_guc_id_mgr_reserve() - Reserve a range of GuC context IDs. * @idm: the &xe_guc_id_mgr * @count: number of GuC context IDs to reserve (can't be 0) * @retain: number of GuC context IDs to keep available (can't be 0) * * This function is dedicated for the use by the PF driver which expects that * reserved range of IDs will be contiguous and that there will be at least * &retain IDs still available for the PF after this reservation. * * Return: starting ID of the allocated GuC context ID range or * a negative error code on failure. */ int xe_guc_id_mgr_reserve(struct xe_guc_id_mgr *idm, unsigned int count, unsigned int retain) { … } /** * xe_guc_id_mgr_release() - Release a range of GuC context IDs. * @idm: the &xe_guc_id_mgr * @start: the starting ID of GuC context range to release * @count: number of GuC context IDs to release */ void xe_guc_id_mgr_release(struct xe_guc_id_mgr *idm, unsigned int start, unsigned int count) { … } static void idm_print_locked(struct xe_guc_id_mgr *idm, struct drm_printer *p, int indent) { … } /** * xe_guc_id_mgr_print() - Print status of GuC ID Manager. * @idm: the &xe_guc_id_mgr to print * @p: the &drm_printer to print to * @indent: tab indentation level */ void xe_guc_id_mgr_print(struct xe_guc_id_mgr *idm, struct drm_printer *p, int indent) { … } #if IS_BUILTIN(CONFIG_DRM_XE_KUNIT_TEST) #include "tests/xe_guc_id_mgr_test.c" #endif