1 /* 2 * SPDX-FileCopyrightText: Copyright (c) 1993-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 3 * SPDX-License-Identifier: MIT 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24 /******************************* DisplayPort *******************************\ 25 * * 26 * Module: dp_auxretry.h * 27 * Adapter interface for friendlier AuxBus * 28 * * 29 \***************************************************************************/ 30 31 #ifndef INCLUDED_DP_AUXRETRY_H 32 #define INCLUDED_DP_AUXRETRY_H 33 34 #include "dp_auxbus.h" 35 #include "dp_timeout.h" 36 37 namespace DisplayPort 38 { 39 enum 40 { 41 minimumRetriesOnDefer = 7 42 }; 43 44 class AuxRetry 45 { 46 AuxBus * aux; 47 public: 48 AuxRetry(AuxBus * aux = 0) aux(aux)49 : aux(aux) 50 { 51 } 52 getDirect()53 AuxBus * getDirect() 54 { 55 return aux; 56 } 57 58 enum status 59 { 60 ack, 61 nack, 62 unsupportedRegister, 63 defer 64 }; 65 66 // 67 // Perform an aux read transaction. 68 // - Automatically handles defers up to retry limit 69 // - Retries on partial read 70 // 71 virtual status readTransaction(int address, NvU8 * buffer, unsigned size, unsigned retries = minimumRetriesOnDefer); 72 73 // 74 // Similar to readTransaction except that it supports reading 75 // larger spans than AuxBus::transactionSize() 76 // 77 virtual status read(int address, NvU8 * buffer, unsigned size, unsigned retries = minimumRetriesOnDefer); 78 79 // 80 // Perform an aux write transaction. 81 // - Automatically handles defers up to retry limit 82 // - Retries on partial write 83 // 84 virtual status writeTransaction(int address, NvU8 * buffer, unsigned size, unsigned retries = minimumRetriesOnDefer); 85 86 // 87 // Similar to writeTransaction except that it supports writin 88 // larger spans than AuxBus::transactionSize() 89 // 90 virtual status write(int address, NvU8 * buffer, unsigned size, unsigned retries = minimumRetriesOnDefer); 91 }; 92 93 class AuxLogger : public AuxBus 94 { 95 AuxBus * bus; 96 char hex[256]; 97 char hex_body[256]; 98 char hint[128]; 99 100 public: AuxLogger(AuxBus * bus)101 AuxLogger(AuxBus * bus) : bus(bus) 102 { 103 } 104 getAction(Action action)105 const char * getAction(Action action) 106 { 107 if (action == read) 108 return "rd "; 109 else if (action == write) 110 return "wr "; 111 else if (action == writeStatusUpdateRequest) 112 return "writeStatusUpdateRequest "; 113 else 114 DP_ASSERT(0); 115 return "???"; 116 } 117 getType(Type typ)118 const char * getType(Type typ) 119 { 120 if (typ == native) 121 return ""; 122 else if (typ == i2c) 123 return "i2c "; 124 else if (typ == i2cMot) 125 return "i2cMot "; 126 else 127 DP_ASSERT(0); 128 return "???"; 129 } 130 getStatus(status stat)131 const char * getStatus(status stat) 132 { 133 if (stat == success) 134 return ""; 135 else if (stat == nack) 136 return "(nack) "; 137 else if (stat == defer) 138 return "(defer) "; 139 else 140 DP_ASSERT(0); 141 return "???"; 142 } 143 getRequestId(unsigned requestIdentifier)144 const char * getRequestId(unsigned requestIdentifier) 145 { 146 switch(requestIdentifier) 147 { 148 case 0x1: return "LINK_ADDRESS"; 149 case 0x4: return "CLEAR_PAT"; 150 case 0x10: return "ENUM_PATH"; 151 case 0x11: return "ALLOCATE"; 152 case 0x12: return "QUERY"; 153 case 0x20: return "DPCD_READ"; 154 case 0x21: return "DPCD_WRITE"; 155 case 0x22: return "I2C_READ"; 156 case 0x23: return "I2C_WRITE"; 157 case 0x24: return "POWER_UP_PHY"; 158 case 0x25: return "POWER_DOWN_PHY"; 159 case 0x38: return "HDCP_STATUS"; 160 default: return ""; 161 } 162 } 163 164 virtual status transaction(Action action, Type type, int address, 165 NvU8 * buffer, unsigned sizeRequested, 166 unsigned * sizeCompleted, unsigned * pNakReason, 167 NvU8 offset, NvU8 nWriteTransactions); 168 transactionSize()169 virtual unsigned transactionSize() 170 { 171 return bus->transactionSize(); 172 } 173 fecTransaction(NvU8 * fecStatus,NvU16 ** fecErrorCount,NvU32 flags)174 virtual status fecTransaction(NvU8 *fecStatus, NvU16 **fecErrorCount, NvU32 flags) 175 { 176 return bus->fecTransaction(fecStatus, fecErrorCount, flags); 177 } 178 }; 179 } 180 181 #endif //INCLUDED_DP_AUXRETRY_H 182