1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2023 Intel Corporation 4 */ 5 6 #include "xe_assert.h" 7 #include "xe_sriov.h" 8 9 /** 10 * xe_sriov_mode_to_string - Convert enum value to string. 11 * @mode: the &xe_sriov_mode to convert 12 * 13 * Returns: SR-IOV mode as a user friendly string. 14 */ 15 const char *xe_sriov_mode_to_string(enum xe_sriov_mode mode) 16 { 17 switch (mode) { 18 case XE_SRIOV_MODE_NONE: 19 return "none"; 20 case XE_SRIOV_MODE_PF: 21 return "SR-IOV PF"; 22 case XE_SRIOV_MODE_VF: 23 return "SR-IOV VF"; 24 default: 25 return "<invalid>"; 26 } 27 } 28 29 /** 30 * xe_sriov_probe_early - Probe a SR-IOV mode. 31 * @xe: the &xe_device to probe mode on 32 * @has_sriov: flag indicating hardware support for SR-IOV 33 * 34 * This function should be called only once and as soon as possible during 35 * driver probe to detect whether we are running a SR-IOV Physical Function 36 * (PF) or a Virtual Function (VF) device. 37 * 38 * SR-IOV PF mode detection is based on PCI @dev_is_pf() function. 39 * SR-IOV VF mode detection is based on dedicated MMIO register read. 40 */ 41 void xe_sriov_probe_early(struct xe_device *xe, bool has_sriov) 42 { 43 enum xe_sriov_mode mode = XE_SRIOV_MODE_NONE; 44 45 /* TODO: replace with proper mode detection */ 46 xe_assert(xe, !has_sriov); 47 48 xe_assert(xe, !xe->sriov.__mode); 49 xe->sriov.__mode = mode; 50 xe_assert(xe, xe->sriov.__mode); 51 52 if (has_sriov) 53 drm_info(&xe->drm, "Running in %s mode\n", 54 xe_sriov_mode_to_string(xe_device_sriov_mode(xe))); 55 } 56