Path: blob/master/drivers/gpu/drm/amd/include/amd_pcie_helpers.h
26517 views
/*1* Copyright 2015 Advanced Micro Devices, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*/2122#ifndef __AMD_PCIE_HELPERS_H__23#define __AMD_PCIE_HELPERS_H__2425#include "amd_pcie.h"2627static inline bool is_pcie_gen3_supported(uint32_t pcie_link_speed_cap)28{29if (pcie_link_speed_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)30return true;3132return false;33}3435static inline bool is_pcie_gen2_supported(uint32_t pcie_link_speed_cap)36{37if (pcie_link_speed_cap & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2)38return true;3940return false;41}4243/* Get the new PCIE speed given the ASIC PCIE Cap and the NewState's requested PCIE speed*/44static inline uint16_t get_pcie_gen_support(uint32_t pcie_link_speed_cap,45uint16_t ns_pcie_gen)46{47uint32_t asic_pcie_link_speed_cap = (pcie_link_speed_cap &48CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_MASK);49uint32_t sys_pcie_link_speed_cap = (pcie_link_speed_cap &50CAIL_PCIE_LINK_SPEED_SUPPORT_MASK);5152switch (asic_pcie_link_speed_cap) {53case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1:54return PP_PCIEGen1;5556case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2:57return PP_PCIEGen2;5859case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3:60return PP_PCIEGen3;6162default:63if (is_pcie_gen3_supported(sys_pcie_link_speed_cap) &&64(ns_pcie_gen == PP_PCIEGen3)) {65return PP_PCIEGen3;66} else if (is_pcie_gen2_supported(sys_pcie_link_speed_cap) &&67((ns_pcie_gen == PP_PCIEGen3) || (ns_pcie_gen == PP_PCIEGen2))) {68return PP_PCIEGen2;69}70}7172return PP_PCIEGen1;73}7475static inline uint16_t get_pcie_lane_support(uint32_t pcie_lane_width_cap,76uint16_t ns_pcie_lanes)77{78int i, j;79uint16_t new_pcie_lanes = ns_pcie_lanes;80uint16_t pcie_lanes[7] = {1, 2, 4, 8, 12, 16, 32};8182switch (pcie_lane_width_cap) {83case 0:84pr_err("No valid PCIE lane width reported\n");85break;86case CAIL_PCIE_LINK_WIDTH_SUPPORT_X1:87new_pcie_lanes = 1;88break;89case CAIL_PCIE_LINK_WIDTH_SUPPORT_X2:90new_pcie_lanes = 2;91break;92case CAIL_PCIE_LINK_WIDTH_SUPPORT_X4:93new_pcie_lanes = 4;94break;95case CAIL_PCIE_LINK_WIDTH_SUPPORT_X8:96new_pcie_lanes = 8;97break;98case CAIL_PCIE_LINK_WIDTH_SUPPORT_X12:99new_pcie_lanes = 12;100break;101case CAIL_PCIE_LINK_WIDTH_SUPPORT_X16:102new_pcie_lanes = 16;103break;104case CAIL_PCIE_LINK_WIDTH_SUPPORT_X32:105new_pcie_lanes = 32;106break;107default:108for (i = 0; i < 7; i++) {109if (ns_pcie_lanes == pcie_lanes[i]) {110if (pcie_lane_width_cap & (0x10000 << i)) {111break;112} else {113for (j = i - 1; j >= 0; j--) {114if (pcie_lane_width_cap & (0x10000 << j)) {115new_pcie_lanes = pcie_lanes[j];116break;117}118}119120if (j < 0) {121for (j = i + 1; j < 7; j++) {122if (pcie_lane_width_cap & (0x10000 << j)) {123new_pcie_lanes = pcie_lanes[j];124break;125}126}127if (j > 7)128pr_err("Cannot find a valid PCIE lane width!\n");129}130}131break;132}133}134break;135}136137return new_pcie_lanes;138}139140#endif141142143