1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright © 2023-2024 Intel Corporation 4 */ 5 6 #ifndef _XE_SRIOV_PF_HELPERS_H_ 7 #define _XE_SRIOV_PF_HELPERS_H_ 8 9 #include "xe_assert.h" 10 #include "xe_device_types.h" 11 #include "xe_sriov.h" 12 #include "xe_sriov_types.h" 13 14 /** 15 * xe_sriov_pf_assert_vfid() - warn if &id is not a supported VF number when debugging. 16 * @xe: the PF &xe_device to assert on 17 * @vfid: the VF number to assert 18 * 19 * Assert that &xe represents the Physical Function (PF) device and provided &vfid 20 * is within a range of supported VF numbers (up to maximum number of VFs that 21 * driver can support, including VF0 that represents the PF itself). 22 * 23 * Note: Effective only on debug builds. See `Xe Asserts`_ for more information. 24 */ 25 #define xe_sriov_pf_assert_vfid(xe, vfid) \ 26 xe_assert((xe), (vfid) <= xe_sriov_pf_get_totalvfs(xe)) 27 28 /** 29 * xe_sriov_pf_get_totalvfs() - Get maximum number of VFs that driver can support. 30 * @xe: the &xe_device to query (shall be PF) 31 * 32 * Return: Maximum number of VFs that this PF driver supports. 33 */ 34 static inline int xe_sriov_pf_get_totalvfs(struct xe_device *xe) 35 { 36 xe_assert(xe, IS_SRIOV_PF(xe)); 37 return xe->sriov.pf.driver_max_vfs; 38 } 39 40 /** 41 * xe_sriov_pf_num_vfs() - Number of enabled VFs on the PF. 42 * @xe: the PF &xe_device 43 * 44 * Return: Number of enabled VFs on the PF. 45 */ 46 static inline unsigned int xe_sriov_pf_num_vfs(const struct xe_device *xe) 47 { 48 return pci_num_vf(to_pci_dev(xe->drm.dev)); 49 } 50 51 /** 52 * xe_sriov_pf_admin_only() - Check if PF is mainly used for VFs administration. 53 * @xe: the PF &xe_device 54 * 55 * Return: True if PF is mainly used for VFs administration. 56 */ 57 static inline bool xe_sriov_pf_admin_only(const struct xe_device *xe) 58 { 59 return !xe->info.probe_display; 60 } 61 62 static inline struct mutex *xe_sriov_pf_master_mutex(struct xe_device *xe) 63 { 64 xe_assert(xe, IS_SRIOV_PF(xe)); 65 return &xe->sriov.pf.master_lock; 66 } 67 68 int xe_sriov_pf_arm_guard(struct xe_device *xe, struct xe_guard *guard, 69 bool write, void *who); 70 void xe_sriov_pf_disarm_guard(struct xe_device *xe, struct xe_guard *guard, 71 bool write, void *who); 72 73 #endif 74