// SPDX-License-Identifier: MIT /* * Copyright © 2023 Intel Corporation */ #include <linux/bitmap.h> #include <linux/mutex.h> #include <drm/drm_managed.h> #include "regs/xe_guc_regs.h" #include "xe_assert.h" #include "xe_gt_printk.h" #include "xe_guc.h" #include "xe_guc_db_mgr.h" #include "xe_guc_types.h" /** * DOC: GuC Doorbells * * The GFX doorbell solution provides a mechanism for submission of workload * to the graphics hardware by a ring3 application without the penalty of * ring transition for each workload submission. * * In SR-IOV mode, the doorbells are treated as shared resource and PF must * be able to provision exclusive range of IDs across VFs, which may want to * use this feature. */ static struct xe_guc *dbm_to_guc(struct xe_guc_db_mgr *dbm) { … } static struct xe_gt *dbm_to_gt(struct xe_guc_db_mgr *dbm) { … } static struct xe_device *dbm_to_xe(struct xe_guc_db_mgr *dbm) { … } #define dbm_assert(_dbm, _cond) … #define dbm_mutex(_dbm) … static void dbm_print_locked(struct xe_guc_db_mgr *dbm, struct drm_printer *p, int indent); static void __fini_dbm(struct drm_device *drm, void *arg) { … } /** * xe_guc_db_mgr_init() - Initialize GuC Doorbells Manager. * @dbm: the &xe_guc_db_mgr to initialize * @count: number of doorbells to manage * * The bare-metal or PF driver can pass ~0 as &count to indicate that all * doorbells supported by the hardware are available for use. * * Only VF's drivers will have to provide explicit number of doorbells IDs * that they can use. * * Return: 0 on success or a negative error code on failure. */ int xe_guc_db_mgr_init(struct xe_guc_db_mgr *dbm, unsigned int count) { … } static int dbm_reserve_chunk_locked(struct xe_guc_db_mgr *dbm, unsigned int count, unsigned int spare) { … } static void dbm_release_chunk_locked(struct xe_guc_db_mgr *dbm, unsigned int start, unsigned int count) { … } /** * xe_guc_db_mgr_reserve_id_locked() - Reserve a single GuC Doorbell ID. * @dbm: the &xe_guc_db_mgr * * This function expects that submission lock is already taken. * * Return: ID of the allocated GuC doorbell or a negative error code on failure. */ int xe_guc_db_mgr_reserve_id_locked(struct xe_guc_db_mgr *dbm) { … } /** * xe_guc_db_mgr_release_id_locked() - Release a single GuC Doorbell ID. * @dbm: the &xe_guc_db_mgr * @id: the GuC Doorbell ID to release * * This function expects that submission lock is already taken. */ void xe_guc_db_mgr_release_id_locked(struct xe_guc_db_mgr *dbm, unsigned int id) { … } /** * xe_guc_db_mgr_reserve_range() - Reserve a range of GuC Doorbell IDs. * @dbm: the &xe_guc_db_mgr * @count: number of GuC doorbell IDs to reserve * @spare: number of GuC doorbell IDs to keep available * * This function is dedicated for the for use by the PF which expects that * allocated range for the VF will be contiguous and that there will be at * least &spare IDs still available for the PF use after this reservation. * * Return: starting ID of the allocated GuC doorbell ID range or * a negative error code on failure. */ int xe_guc_db_mgr_reserve_range(struct xe_guc_db_mgr *dbm, unsigned int count, unsigned int spare) { … } /** * xe_guc_db_mgr_release_range() - Release a range of Doorbell IDs. * @dbm: the &xe_guc_db_mgr * @start: the starting ID of GuC doorbell ID range to release * @count: number of GuC doorbell IDs to release */ void xe_guc_db_mgr_release_range(struct xe_guc_db_mgr *dbm, unsigned int start, unsigned int count) { … } static void dbm_print_locked(struct xe_guc_db_mgr *dbm, struct drm_printer *p, int indent) { … } /** * xe_guc_db_mgr_print() - Print status of GuC Doorbells Manager. * @dbm: the &xe_guc_db_mgr to print * @p: the &drm_printer to print to * @indent: tab indentation level */ void xe_guc_db_mgr_print(struct xe_guc_db_mgr *dbm, struct drm_printer *p, int indent) { … } #if IS_BUILTIN(CONFIG_DRM_XE_KUNIT_TEST) #include "tests/xe_guc_db_mgr_test.c" #endif