├── .gitignore ├── AllRez.xcodeproj └── project.pbxproj ├── AllRez ├── AGDCDiagnose.cpp ├── AGDCDiagnose.h ├── AppleMisc.cpp ├── AppleMisc.h ├── IOGraphics │ ├── IOGraphicsFamily │ │ ├── IOGraphicsDiagnose.h │ │ ├── IOGraphicsKTrace.h │ │ ├── IOKit │ │ │ └── graphics │ │ │ │ ├── GTraceTypes.hpp │ │ │ │ └── IOGraphicsTypesPrivate.h │ │ └── tools │ │ │ └── Utilities │ │ │ ├── IOGDiagnoseUtils.cpp │ │ │ ├── IOGDiagnoseUtils.hpp │ │ │ └── iokit.h │ └── iogdiagnose │ │ └── iogdiagnose.cpp ├── IOGraphics530.14 │ ├── GTrace │ │ └── GTraceTypes.h │ └── iogdiagnose │ │ ├── IOGDiagnoseUtils │ │ ├── IOGDiagnoseUtils.cpp │ │ └── IOGDiagnoseUtils.h │ │ └── iogdiagnose.cpp ├── IOGraphics530.66 │ └── iogdiagnose │ │ ├── IOGDiagnoseUtils │ │ └── IOGDiagnoseUtils.cpp │ │ └── iogdiagnose.cpp ├── IOGraphics576.1 │ └── iogdiagnose │ │ └── iogdiagnose.cpp ├── Kernel.framework │ └── sys │ │ ├── kdebug_kernel.h │ │ └── kdebug_private.h ├── MacOSMacros.h ├── ddccicommands.h ├── displayport.cpp ├── displayport.h ├── dpcd.cpp ├── dpcd.h ├── iofbdebuguser.cpp ├── iofbdebuguser.h ├── linux │ ├── drivers │ │ └── gpu │ │ │ └── drm │ │ │ └── amd │ │ │ └── display │ │ │ ├── dc │ │ │ ├── dc_ddc_types.h │ │ │ ├── dc_dp_types.h │ │ │ └── os_types.h │ │ │ └── include │ │ │ └── dpcd_defs.h │ └── include │ │ ├── drm │ │ ├── display │ │ │ ├── drm_dp.h │ │ │ ├── drm_dp_helper.h │ │ │ └── drm_hdcp.h │ │ └── drm_connector.h │ │ └── linux │ │ ├── delay.h │ │ ├── i2c.h │ │ └── types.h ├── main.cpp ├── oui.cpp ├── oui.h ├── ouilist.h ├── printf.cpp ├── printf.h ├── utilities.cpp ├── utilities.h ├── vcp.cpp ├── vcp.h └── vcpcodes.h ├── AllRez10.12.xcodeproj └── project.pbxproj ├── AllRez10.6.xcodeproj └── project.pbxproj └── dumpdpcd └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | DerivedData 2 | project.xcworkspace 3 | xcuserdata 4 | xcshareddata 5 | *.bc 6 | *.ii 7 | *.i 8 | *.s 9 | build 10 | *.mode1 11 | *.mode1v3 12 | *.pbxuser 13 | AllRez10.4.xcodeproj 14 | AllRez10.5.xcodeproj 15 | AllRez10.7.xcodeproj 16 | AllRez10.8.xcodeproj 17 | AllRez10.9.xcodeproj 18 | AllRez10.10.xcodeproj 19 | AllRez10.11.xcodeproj 20 | AllRez10.13.xcodeproj 21 | AllRez10.14.xcodeproj 22 | AllRez10.15.xcodeproj 23 | AllRez11.xcodeproj 24 | AllRez12.xcodeproj 25 | AllRez13.xcodeproj 26 | AllRez14.xcodeproj 27 | AllRez15.xcodeproj 28 | -------------------------------------------------------------------------------- /AllRez/AGDCDiagnose.h: -------------------------------------------------------------------------------- 1 | // 2 | // AGDCDiagnose.h 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-06-04. 6 | // 7 | 8 | #ifndef AGDCDiagnose_h 9 | #define AGDCDiagnose_h 10 | 11 | #include 12 | 13 | #define UNALIGNED __attribute__((aligned(1))) 14 | #define PACKED __attribute__((packed)) UNALIGNED 15 | 16 | typedef uint64_t reginfo; 17 | 18 | typedef struct { 19 | reginfo fb; 20 | uint64_t fbindex; 21 | } fbinfo; // 16 bytes 22 | 23 | typedef struct { 24 | /* 0 */ uint16_t gpuid; 25 | /* 2 */ uint16_t filler; 26 | /* 4 */ uint32_t flags; 27 | /* 28 | 2:"XG" 29 | 0x10:"IG" 30 | 0x20:"DG" 31 | 0x40:"NG" 32 | 1:"eject" 33 | 4:"ejectFinalizing" 34 | 8:"ejectFinalized" 35 | 0x1000000:"unsupported" 36 | 0x80000000:"published" 37 | 0x8000000:"driversStarted" 38 | 0x4000000:"hasGPUC" 39 | 0x40000000:"terminated" 40 | 0x20000000:"quiet" 41 | 0x10000000:"pubSched" 42 | 0x2000000:"pubArmed" 43 | default:"bit%d" 44 | */ 45 | /* 8 */ reginfo agdc; 46 | /* 0x10 */ reginfo pci; 47 | /* 0x18 */ uint64_t fbcount; 48 | /* 0x20 */ fbinfo fb[32]; 49 | /* 0x220 */ reginfo accel; 50 | /* 0x228 */ reginfo agdpclient; 51 | /* 0x230 */ reginfo gpuc; 52 | } subgpuinfo; // 0x238 bytes 53 | 54 | typedef struct PACKED { 55 | /* 0 */ char name[0x28]; 56 | /* 0x28 */ uint32_t state; // exists when not 0 57 | /* 0x2c */ uint32_t managerState; 58 | /* 0x30 */ uint32_t vendorclass; 59 | /* 0x34 */ uint32_t vendorid; 60 | /* 0x38 */ uint32_t vendorversion; 61 | /* 0x3c */ uint8_t filler; 62 | } launcherinfo; // 0x3d bytes 63 | 64 | typedef struct PACKED { 65 | /* 0 0x238 */ uint32_t index; 66 | /* 4 0x23c */ uint32_t state; // 0:skip, 1:"Discovered", 2:"GPUCDetect", 3:"GPUCStartDrivers", 4:"WaitForDrivers", 5:"Published", 6:"Unpublished", 7:"Gone", 8:"Eject", 0x80:"GPUCDriverStartFailed", default:"unknown" 67 | /* 8 0x240 */ uint64_t filler; 68 | /* 0x10 0x248 */ uint8_t events; // 1:terminated default:"" 69 | /* 0x11 0x249 */ PACKED subgpuinfo subgpu; 70 | /* 0x249 0x481 */ uint32_t dispPolicyState; // 0:"Pending", 1:"Managed", 2:"Unmanaged", 3:"Stopped", 4:"InitFailed", 5:"InitAborted", 6:"WaitingForAGDP", 7:"StartingManager", default:"unknown" 71 | /* 0x24d 0x485 */ uint32_t dispPolicyLaunchIndex; 72 | } gpuinfo; // 0x251 bytes 73 | 74 | typedef struct PACKED { 75 | uint64_t timestamp; 76 | uint64_t object; 77 | uint16_t line; 78 | uint16_t tag0; 79 | uint16_t tag1; 80 | uint16_t tag2; 81 | uint64_t data0; 82 | uint64_t data1; 83 | uint64_t data2; 84 | } gtraceentry; 85 | 86 | typedef struct { 87 | uint32_t gtraceid[4]; // 0x67547261, 0x63654461, 0x74614475, 0x6d700000 'gTra' 'ceDa' 'taDu' 'mp\x00\x00' 88 | uint32_t dataVersion; // 0x102 89 | uint32_t maxEntries; // 512 90 | uint32_t counter; // 106 91 | uint8_t version[4]; // 6,5,7,0 = 6.5.6 92 | uint64_t hdrSize; // 56 93 | uint64_t ussue; 94 | uint64_t usct; 95 | } gtraceheader; 96 | 97 | typedef struct { 98 | gtraceheader header; 99 | gtraceentry entry[512]; 100 | } gtraceinfo; 101 | 102 | typedef struct { 103 | /* 0 */ char boardID[32]; 104 | /* 0x20 */ uint64_t started; 105 | /* 0x28 */ uint64_t running; 106 | /* 0x30 */ uint64_t featureMask; 107 | /* 0x38 */ uint64_t platformFlags; 108 | /* 0x40 */ uint64_t extraSupportFlags; 109 | /* 0x48 */ uint64_t wranglerFlags; 110 | /* 0x50 */ UNALIGNED launcherinfo launcher[8]; 111 | /* 0x238 */ UNALIGNED gpuinfo gpu[8]; 112 | /* 0x14c0 */ gtraceinfo gtrace; 113 | /* 0x74f8 */ // end 114 | } DisplayPolicyState; 115 | 116 | extern int assertx[(__builtin_offsetof(DisplayPolicyState, gpu) == 0x238) - 1]; 117 | extern int assertx[(__builtin_offsetof(DisplayPolicyState, gtrace) == 0x14c0) - 1]; 118 | extern int assertx[(sizeof(DisplayPolicyState) == 0x74f8) - 1]; 119 | 120 | #ifdef __cplusplus 121 | extern "C" { 122 | #endif 123 | void DoDisplayPolicyState(void); 124 | #ifdef __cplusplus 125 | } 126 | #endif 127 | 128 | #endif /* AGDCDiagnose_h */ 129 | -------------------------------------------------------------------------------- /AllRez/AppleMisc.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AppleMisc.cpp 3 | // AllRez 4 | // 5 | // Created by joevt on 2023-03-09. 6 | // 7 | 8 | #include "AppleMisc.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define ConvertPointer(to, from) \ 17 | do { if (sizeof(to) < sizeof(from)) (to) = 0; else if (sizeof(to) == 8) *(uint64_t*)(&(to)) = (uint64_t)(from); else *(uint32_t*)(&(to)) = (uint32_t)(uint64_t)(from); } while (0) 18 | 19 | #define ConvertIOI2CRequest(from, to, final) \ 20 | do { \ 21 | if (!final) bzero((to), sizeof(*(to))); \ 22 | (to)->commFlags = (from)->commFlags ; \ 23 | if (!final) ConvertPointer((to)->completion, (from)->completion) ; \ 24 | (to)->minReplyDelay = (from)->minReplyDelay ; \ 25 | (to)->replyAddress = (from)->replyAddress ; \ 26 | if (!final) ConvertPointer((to)->replyBuffer, (from)->replyBuffer) ; \ 27 | (to)->replyBytes = (unsigned int)(from)->replyBytes ; \ 28 | (to)->replySubAddress = (from)->replySubAddress ; \ 29 | (to)->replyTransactionType = (from)->replyTransactionType ; \ 30 | (to)->result = (from)->result ; \ 31 | (to)->sendAddress = (from)->sendAddress ; \ 32 | if (!final) ConvertPointer((to)->sendBuffer, (from)->sendBuffer) ; \ 33 | (to)->sendBytes = (unsigned int)(from)->sendBytes ; \ 34 | (to)->sendSubAddress = (from)->sendSubAddress ; \ 35 | (to)->sendTransactionType = (from)->sendTransactionType ; \ 36 | } while (0) 37 | 38 | static char ghwmachine[20]; 39 | 40 | const char * MachineType() { 41 | if (!ghwmachine[0]) { 42 | size_t data_len = sizeof(ghwmachine) - 1; 43 | if (sysctlbyname("hw.machine", &ghwmachine, &data_len, NULL, 0)) { 44 | snprintf(ghwmachine, sizeof(ghwmachine), "unknownArch"); 45 | } 46 | else if (!strcmp(ghwmachine, "Power Macintosh")) { 47 | snprintf(ghwmachine, sizeof(ghwmachine), "ppc"); 48 | } 49 | } 50 | return ghwmachine; 51 | } 52 | 53 | static int gDarwinMajorVersion = -1; 54 | static int gDarwinMinorVersion = 0; 55 | static int gDarwinRevision = 0; 56 | static char gMacOSVersion[20]; 57 | 58 | void GetDarwinVersion() { 59 | char osversion[32]; 60 | size_t osversion_len = sizeof(osversion) - 1; 61 | int osversion_name[] = { CTL_KERN, KERN_OSRELEASE }; 62 | 63 | if (sysctl(osversion_name, 2, osversion, &osversion_len, NULL, 0) == -1) { 64 | printf("sysctl() failed\n"); 65 | return; 66 | } 67 | 68 | if (sscanf(osversion, "%u.%u.%u", &gDarwinMajorVersion, &gDarwinMinorVersion, &gDarwinRevision) != 3) { 69 | if (sscanf(osversion, "%u.%u", &gDarwinMajorVersion, &gDarwinMinorVersion) != 2) { 70 | printf("sscanf() failed\n"); 71 | return; 72 | } 73 | } 74 | } 75 | 76 | int DarwinMajorVersion() { 77 | if (gDarwinMajorVersion < 0) { 78 | GetDarwinVersion(); 79 | } 80 | return gDarwinMajorVersion; 81 | } 82 | 83 | int DarwinMinorVersion() { 84 | if (gDarwinMajorVersion < 0) { 85 | GetDarwinVersion(); 86 | } 87 | return gDarwinMinorVersion; 88 | } 89 | 90 | int DarwinRevision() { 91 | if (gDarwinMajorVersion < 0) { 92 | GetDarwinVersion(); 93 | } 94 | return gDarwinRevision; 95 | } 96 | 97 | char * MacOSVersion() { 98 | if (!gMacOSVersion[0]) { 99 | char osversion[32]; 100 | size_t osversion_len = sizeof(osversion) - 1; 101 | 102 | if (sysctlbyname("kern.osproductversion", osversion, &osversion_len, NULL, 0) == 0) { 103 | snprintf(gMacOSVersion, sizeof(gMacOSVersion), "%.*s", (int)osversion_len, osversion); 104 | if (!strcmp(gMacOSVersion, "10.16")) { 105 | gMacOSVersion[0] = '\0'; 106 | } 107 | } 108 | 109 | if (!gMacOSVersion[0]) { 110 | snprintf(gMacOSVersion, sizeof(gMacOSVersion), "%d.%d.%d", 111 | (DarwinMajorVersion() < 20) ? 10 : DarwinMajorVersion() - 9, 112 | (DarwinMajorVersion() == 1) ? (DarwinMinorVersion() == 4 ? 1 : 0) : (DarwinMajorVersion() < 20) ? DarwinMajorVersion() - 4 : DarwinMinorVersion(), 113 | (DarwinMajorVersion() < 20) ? DarwinMinorVersion() : DarwinRevision() // this is not always accurrate 114 | ); 115 | } 116 | } 117 | return gMacOSVersion; 118 | } 119 | 120 | static IOReturn I2CSendRequest_10_5( IOI2CConnectRef connect, IOOptionBits options, IOI2CRequest_10_6 * request ) 121 | { 122 | kern_return_t kr; 123 | 124 | IOI2CBuffer buffer; 125 | 126 | if( request->sendBytes > kIOI2CInlineBufferBytes) 127 | return( kIOReturnOverrun ); 128 | if( request->replyBytes > kIOI2CInlineBufferBytes) 129 | return( kIOReturnOverrun ); 130 | 131 | if (request->sendAddress > 255) { 132 | return kIOReturnBadArgument; 133 | } 134 | 135 | if (request->replyAddress > 255) { 136 | return kIOReturnBadArgument; 137 | } 138 | 139 | #if defined(__LP64__) 140 | kr = IOConnectCallMethod(connect->connect, 0, // Index 141 | NULL, 0, NULL, 0, // Input 142 | NULL, NULL, NULL, NULL); // Output 143 | #else 144 | kr = IOConnectMethodScalarIScalarO( connect->connect, 0, 0, 0 ); 145 | #endif 146 | if( kIOReturnSuccess != kr) 147 | return( kr ); 148 | 149 | void *inlineBuffer; 150 | size_t len; 151 | uint32_t *replyBytes; 152 | 153 | if (!strcmp(MachineType(), "i386")) { 154 | ConvertIOI2CRequest(request, &buffer.buf_i386.request, 0); 155 | buffer.buf_i386.request.replyBuffer = 0; 156 | buffer.buf_i386.request.sendBuffer = 0; 157 | replyBytes = &buffer.buf_i386.request.replyBytes; 158 | inlineBuffer = &buffer.buf_i386.inlineBuffer; 159 | len = sizeof(buffer.buf_i386); 160 | } 161 | else if (!strcmp(MachineType(), "ppc")) { 162 | ConvertIOI2CRequest(request, &buffer.buf_ppc.request, 0); 163 | buffer.buf_ppc.request.replyBuffer = 0; 164 | buffer.buf_ppc.request.sendBuffer = 0; 165 | replyBytes = &buffer.buf_i386.request.replyBytes; 166 | inlineBuffer = &buffer.buf_ppc.inlineBuffer; 167 | len = sizeof(buffer.buf_ppc); 168 | } 169 | else { 170 | ConvertIOI2CRequest(request, &buffer.buf_def.request, 0); 171 | buffer.buf_def.request.replyBuffer = 0; 172 | buffer.buf_def.request.sendBuffer = 0; 173 | replyBytes = &buffer.buf_i386.request.replyBytes; 174 | inlineBuffer = &buffer.buf_def.inlineBuffer; 175 | len = sizeof(buffer.buf_def); 176 | } 177 | 178 | if( request->sendBytes) 179 | bcopy( (void *) request->sendBuffer, inlineBuffer, request->sendBytes ); 180 | 181 | #if defined(__LP64__) 182 | kr = IOConnectCallMethod(connect->connect, 2, // Index 183 | NULL, 0, &buffer, len, // Input 184 | NULL, NULL, &buffer, &len); // Output 185 | #else 186 | kr = IOConnectMethodStructureIStructureO(connect->connect, 2, // Index 187 | len, &len, &buffer, &buffer); 188 | #endif 189 | 190 | if( *replyBytes) 191 | bcopy( inlineBuffer, (void *) request->replyBuffer, *replyBytes ); 192 | 193 | if (!strcmp(MachineType(), "i386")) { 194 | ConvertIOI2CRequest(&buffer.buf_i386.request, request, 1); 195 | } 196 | else if (!strcmp(MachineType(), "ppc")) { 197 | ConvertIOI2CRequest(&buffer.buf_ppc.request, request, 1); 198 | } 199 | else { 200 | ConvertIOI2CRequest(&buffer.buf_def.request, request, 1); 201 | } 202 | 203 | #if defined(__LP64__) 204 | IOConnectCallMethod(connect->connect, 1, // Index 205 | NULL, 0, NULL, 0, // Input 206 | NULL, NULL, NULL, NULL); // Output 207 | #else 208 | IOConnectMethodScalarIScalarO( connect->connect, 1, 0, 0 ); 209 | #endif 210 | 211 | return kr; 212 | } 213 | 214 | IOReturn UniversalI2CSendRequest( IOI2CConnectRef connect, IOOptionBits options, IOI2CRequest_10_6 * request ) 215 | { 216 | kern_return_t kr; 217 | if (DarwinMajorVersion() <= 9) { // 10.5 218 | #if 1 219 | kr = I2CSendRequest_10_5(connect, options, request); 220 | #else 221 | IOI2CRequest_10_5_0_user request_10_5_0; 222 | ConvertIOI2CRequest(request, &request_10_5_0, 0); 223 | kr = IOI2CSendRequest(connect, options, (IOI2CRequest*)&request_10_5_0); 224 | ConvertIOI2CRequest(&request_10_5_0, request, 1); 225 | #endif 226 | } 227 | else { 228 | kr = IOI2CSendRequest(connect, options, (IOI2CRequest*)request); 229 | } 230 | return kr; 231 | } 232 | 233 | void DumpAllBundles() 234 | { 235 | CFBundleRef bundle = NULL; 236 | CFArrayRef allbundles = CFBundleGetAllBundles(); 237 | CFIndex bundleCount = CFArrayGetCount(allbundles); 238 | for (int i = 0; i < bundleCount; i++) { 239 | bundle = (CFBundleRef)CFArrayGetValueAtIndex(allbundles, i); 240 | CFStringRef identifier = CFBundleGetIdentifier(bundle); 241 | if (identifier) { 242 | char identifierStr[256]; 243 | CFStringGetCString(identifier, identifierStr, sizeof(identifierStr), kCFStringEncodingUTF8); 244 | printf("%d %s\n", i, identifierStr); 245 | } 246 | else { 247 | printf("%d no identifier\n", i); 248 | } 249 | } 250 | } 251 | 252 | void DumpAllImages() 253 | { 254 | uint32_t imageCount = _dyld_image_count(); 255 | for (int i = 0; i < imageCount; i++) { 256 | const char* image_name = _dyld_get_image_name(i); 257 | if (image_name) { 258 | printf("%d %s\n", i, image_name); 259 | } 260 | else { 261 | printf("%d no identifier\n", i); 262 | } 263 | } 264 | } 265 | 266 | 267 | static bool triedIODisplayForFramebuffer = false; 268 | static IODisplayForFramebufferPtr gIODisplayForFramebuffer = NULL; 269 | 270 | IODisplayForFramebufferPtr GetIODisplayForFramebufferPtr() 271 | { 272 | if (!gIODisplayForFramebuffer && !triedIODisplayForFramebuffer) { 273 | #if MAC_OS_X_VERSION_SDK == MAC_OS_X_VERSION_10_5 274 | // IODisplayForFramebuffer is exported in 10.1 to 10.4 and 10.6 and later but not 10.5. 275 | // This code is here for compiling with 10.5 sdk. It will work when Allrez10.5 is run on non-10.5 macOS versions. 276 | //DumpAllBundles(); 277 | //DumpAllImages(); 278 | CFBundleRef bundle = NULL; 279 | if ((bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.framework.IOKit")))) { 280 | gIODisplayForFramebuffer = (IODisplayForFramebufferPtr)CFBundleGetFunctionPointerForName(bundle, CFSTR("IODisplayForFramebuffer")); 281 | if (!gIODisplayForFramebuffer) { 282 | gIODisplayForFramebuffer = (IODisplayForFramebufferPtr)dlsym(RTLD_DEFAULT, "IODisplayForFramebuffer"); 283 | } 284 | } 285 | triedIODisplayForFramebuffer = true; 286 | #else 287 | gIODisplayForFramebuffer = &IODisplayForFramebuffer; 288 | #endif 289 | } 290 | return gIODisplayForFramebuffer; 291 | } 292 | 293 | 294 | // https://github.com/apple-oss-distributions/IOKitUser/blob/IOKitUser-1445.71.1/graphics.subproj/IOGraphicsLib.c#L3284 295 | 296 | // 837 297 | static void 298 | AdjustTimingForInterlace( IODetailedTimingInformationV2_12 * timing ) 299 | { 300 | timing->signalConfig |= kIOInterlacedCEATiming; 301 | timing->verticalActive = (timing->verticalActive << 1); 302 | timing->verticalBlanking = (timing->verticalBlanking << 1) | 1; 303 | timing->verticalSyncPulseWidth = (timing->verticalSyncPulseWidth << 1); 304 | timing->verticalSyncOffset = (timing->verticalSyncOffset << 1) | 1; 305 | timing->verticalBorderTop = (timing->verticalBorderTop << 1); 306 | timing->verticalBorderBottom = (timing->verticalBorderBottom << 1); 307 | } 308 | 309 | IOReturn 310 | EDIDDescToDetailedTiming( EDID * edid, EDIDDetailedTimingDesc * desc, 311 | IODetailedTimingInformationV2_12 * timing ) 312 | { 313 | bool interlaced; 314 | 315 | bzero( timing, sizeof( IODetailedTimingInformationV2_12 ) ); 316 | 317 | if( !desc->clock) 318 | return( kIOReturnBadArgument ); 319 | 320 | timing->signalConfig = (edid->displayParams[0] & 16) 321 | ? kIOAnalogSetupExpected : 0; 322 | interlaced = (0 != (desc->flags & 0x80)); 323 | 324 | timing->signalLevels = (edid->displayParams[0] >> 5) & 3; 325 | 326 | timing->pixelClock = ((UInt64) OSReadLittleInt16(&desc->clock, 0)) 327 | * 10000ULL; 328 | timing->maxPixelClock = timing->pixelClock; 329 | timing->minPixelClock = timing->pixelClock; 330 | 331 | timing->horizontalActive = desc->horizActive 332 | | ((desc->horizHigh & 0xf0) << 4); 333 | timing->horizontalBlanking = desc->horizBlanking 334 | | ((desc->horizHigh & 0x0f) << 8); 335 | 336 | timing->verticalActive = desc->verticalActive 337 | | ((desc->verticalHigh & 0xf0) << 4); 338 | timing->verticalBlanking = desc->verticalBlanking 339 | | ((desc->verticalHigh & 0x0f) << 8); 340 | 341 | timing->horizontalSyncOffset = desc->horizSyncOffset 342 | | ((desc->syncHigh & 0xc0) << 2); 343 | timing->horizontalSyncPulseWidth = desc->horizSyncWidth 344 | | ((desc->syncHigh & 0x30) << 4); 345 | 346 | timing->verticalSyncOffset = ((desc->verticalSyncOffsetWidth & 0xf0) >> 4) 347 | | ((desc->syncHigh & 0x0c) << 2); 348 | timing->verticalSyncPulseWidth = ((desc->verticalSyncOffsetWidth & 0x0f) >> 0) 349 | | ((desc->syncHigh & 0x03) << 4); 350 | 351 | timing->horizontalBorderLeft = desc->horizBorder; 352 | timing->horizontalBorderRight = desc->horizBorder; 353 | timing->verticalBorderTop = desc->verticalBorder; 354 | timing->verticalBorderBottom = desc->verticalBorder; 355 | 356 | timing->horizontalSyncConfig = (desc->flags & 2) 357 | ? kIOSyncPositivePolarity : 0; 358 | timing->horizontalSyncLevel = 0; 359 | timing->verticalSyncConfig = (desc->flags & 4) 360 | ? kIOSyncPositivePolarity : 0; 361 | timing->verticalSyncLevel = 0; 362 | 363 | if (interlaced) 364 | AdjustTimingForInterlace(timing); 365 | 366 | return( kIOReturnSuccess ); 367 | } 368 | 369 | static void 370 | MaxTimingRangeRec( IODisplayTimingRangeV1_12 * range ) 371 | { 372 | bzero( range, sizeof( IODisplayTimingRangeV1_12) ); 373 | 374 | range->supportedSyncFlags = 0xffffffff; 375 | range->supportedSignalLevels = 0xffffffff; 376 | range->supportedSignalConfigs = 0xffffffff; 377 | 378 | range->maxFrameRate = 0xffffffff; 379 | range->maxLineRate = 0xffffffff; 380 | range->maxPixelClock = 0xffffffff; 381 | range->maxPixelError = 0xffffffff; 382 | 383 | range->maxHorizontalTotal = 0xffffffff; 384 | range->maxVerticalTotal = 0xffffffff; 385 | range->maxHorizontalActiveClocks = 0xffffffff; 386 | range->maxHorizontalBlankingClocks = 0xffffffff; 387 | range->maxHorizontalSyncOffsetClocks = 0xffffffff; 388 | range->maxHorizontalPulseWidthClocks = 0xffffffff; 389 | range->maxVerticalActiveClocks = 0xffffffff; 390 | range->maxVerticalBlankingClocks = 0xffffffff; 391 | range->maxVerticalSyncOffsetClocks = 0xffffffff; 392 | range->maxVerticalPulseWidthClocks = 0xffffffff; 393 | range->maxHorizontalBorderLeft = 0xffffffff; 394 | range->maxHorizontalBorderRight = 0xffffffff; 395 | range->maxVerticalBorderTop = 0xffffffff; 396 | range->maxVerticalBorderBottom = 0xffffffff; 397 | 398 | range->charSizeHorizontalActive = 1; 399 | range->charSizeHorizontalBlanking = 1; 400 | range->charSizeHorizontalSyncOffset = 1; 401 | range->charSizeHorizontalSyncPulse = 1; 402 | range->charSizeVerticalActive = 1; 403 | range->charSizeVerticalBlanking = 1; 404 | range->charSizeVerticalSyncOffset = 1; 405 | range->charSizeVerticalSyncPulse = 1; 406 | range->charSizeHorizontalBorderLeft = 1; 407 | range->charSizeHorizontalBorderRight = 1; 408 | range->charSizeVerticalBorderTop = 1; 409 | range->charSizeVerticalBorderBottom = 1; 410 | range->charSizeHorizontalTotal = 1; 411 | range->charSizeVerticalTotal = 1; 412 | } 413 | 414 | Boolean 415 | EDIDDescToDisplayTimingRangeRec( EDID * edid, EDIDGeneralDesc * desc, 416 | IODisplayTimingRangeV1_12 * range ) 417 | { 418 | UInt8 byte; 419 | 420 | if( !edid || (edid->version < 1) || (edid->revision < 1)) 421 | return( false ); 422 | 423 | if( desc->flag1 || desc->flag2 || desc->flag3) 424 | return( false ); 425 | if( 0xfd != desc->type) 426 | return( false ); 427 | 428 | MaxTimingRangeRec( range ); 429 | 430 | byte = edid->displayParams[0]; 431 | if (!(0x80 & byte)) 432 | { 433 | range->supportedSignalLevels = 1 << ((byte >> 5) & 3); 434 | range->supportedSyncFlags = ((byte & 1) ? kIORangeSupportsVSyncSerration : 0) 435 | | ((byte & 2) ? kIORangeSupportsSyncOnGreen : 0) 436 | | ((byte & 4) ? kIORangeSupportsCompositeSync : 0) 437 | | ((byte & 8) ? kIORangeSupportsSeparateSyncs : 0); 438 | } 439 | 440 | range->supportedSignalConfigs = kIORangeSupportsInterlacedCEATiming; 441 | 442 | range->minVerticalPulseWidthClocks = 1; 443 | range->minHorizontalPulseWidthClocks = 1; 444 | 445 | range->minFrameRate = desc->data[0]; 446 | range->maxFrameRate = desc->data[1]; 447 | range->minLineRate = desc->data[2] * 1000; 448 | range->maxLineRate = desc->data[3] * 1000; 449 | range->maxPixelClock = desc->data[4] * 10000000ULL; 450 | 451 | range->minHorizontalActiveClocks = 640; 452 | range->minVerticalActiveClocks = 480; 453 | 454 | if( range->minLineRate) 455 | range->maxHorizontalActiveClocks = (UInt32)(range->maxPixelClock / range->minLineRate); 456 | if( range->minFrameRate) 457 | range->maxVerticalActiveClocks = (UInt32)(range->maxPixelClock / (range->minHorizontalActiveClocks * range->minFrameRate)); 458 | 459 | return( true ); 460 | } 461 | -------------------------------------------------------------------------------- /AllRez/IOGraphics/IOGraphicsFamily/IOGraphicsDiagnose.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOGraphicsDiagnose.h 3 | // IOGraphics 4 | // 5 | // Created by bparke on 12/16/16. 6 | // 7 | // 8 | 9 | #ifndef IOGraphicsDiagnose_h 10 | #define IOGraphicsDiagnose_h 11 | 12 | #if defined(IOGD530_14) 13 | #include "GTraceTypes.h" 14 | 15 | #define IOGRAPHICS_DIAGNOSE_VERSION 6 16 | #else 17 | #define IOGRAPHICS_DIAGNOSE_VERSION 9 18 | #endif 19 | 20 | #define IOGRAPHICS_MAXIMUM_REPORTS 16 21 | #if !defined(IOGD530_14) 22 | #define IOGRAPHICS_MAXIMUM_FBS 96 23 | #else 24 | #define IOGRAPHICS_TOKENBUFFERSIZE (kGTraceMaximumLineCount * (sizeof(sGTrace) / sizeof(uint64_t))) // ensure >= kGTraceMaximumLineCount 25 | 26 | 27 | // Client Interfaces 28 | #define kIOGSharedInterface_IOGDiagnose 0 29 | #define kIOGSharedInterface_ReservedB 1 30 | #define kIOGSharedInterface_ReservedC 2 31 | #define kIOGSharedInterface_ReservedD 3 32 | #define kIOGSharedInterface_ReservedE 4 33 | 34 | #define IONotify _ionotify 35 | #define IOGReport _iogreport 36 | #define IOGDiagnose _iogdiagnose 37 | #endif 38 | 39 | // stateBits 40 | #define kIOGReportState_Opened (1 << 0) 41 | #define kIOGReportState_Usable (1 << 1) 42 | #define kIOGReportState_Paging (1 << 2) 43 | #define kIOGReportState_Clamshell (1 << 3) 44 | #define kIOGReportState_ClamshellCurrent (1 << 4) 45 | #define kIOGReportState_ClamshellLast (1 << 5) 46 | #define kIOGReportState_SystemDark (1 << 6) 47 | #define kIOGReportState_Mirrored (1 << 7) 48 | #define kIOGReportState_SystemGated (1 << 8) 49 | #define kIOGReportState_WorkloopGated (1 << 9) 50 | #define kIOGReportState_NotificationActive (1 << 10) 51 | #define kIOGReportState_ServerNotified (1 << 11) 52 | #define kIOGReportState_ServerState (1 << 12) 53 | #define kIOGReportState_ServerPendingAck (1 << 13) // unused FBv6 54 | #define kIOGReportState_PowerPendingChange (1 << 14) 55 | #define kIOGReportState_PowerPendingMuxChange (1 << 15) 56 | #define kIOGReportState_PrivateInvalid (1 << 16) 57 | #define kIOGReportState_ControllerInvalid (1 << 17) 58 | #define kIOGReportState_GraphicsWorkloopInvalid (1 << 18) 59 | #define kIOGReportState_SystemWorkloopInvalid (1 << 19) 60 | #define kIOGReportState_SystemPowerAckTo (1 << 20) 61 | #define kIOGReportState_Online (1 << 21) 62 | #define kIOGReportState_ClamshellOffline (1 << 22) 63 | #define kIOGReportState_Muted (1 << 23) 64 | #define kIOGReportState_IsMuxSwitching (1 << 24) 65 | 66 | 67 | // External API states 68 | #define kIOGReportAPIState_CreateSharedCursor (1 << 0) 69 | #define kIOGReportAPIState_GetPixelInformation (1 << 1) 70 | #define kIOGReportAPIState_GetCurrentDisplayMode (1 << 2) 71 | #define kIOGReportAPIState_SetStartupDisplayMode (1 << 3) 72 | #define kIOGReportAPIState_SetDisplayMode (1 << 4) 73 | #define kIOGReportAPIState_GetInformationForDisplayMode (1 << 5) 74 | #define kIOGReportAPIState_GetDisplayModeCount (1 << 6) 75 | #define kIOGReportAPIState_GetDisplayModes (1 << 7) 76 | #define kIOGReportAPIState_GetVRAMMapOffset (1 << 8) 77 | #define kIOGReportAPIState_SetBounds (1 << 9) 78 | #define kIOGReportAPIState_SetNewCursor (1 << 10) 79 | #define kIOGReportAPIState_SetGammaTable (1 << 11) 80 | #define kIOGReportAPIState_SetCursorVisible (1 << 12) 81 | #define kIOGReportAPIState_SetCursorPosition (1 << 13) 82 | #define kIOGReportAPIState_AcknowledgeNotification (1 << 14) 83 | #define kIOGReportAPIState_SetColorConvertTable (1 << 15) 84 | #define kIOGReportAPIState_SetCLUTWithEntries (1 << 16) 85 | #define kIOGReportAPIState_ValidateDetailedTiming (1 << 17) 86 | #define kIOGReportAPIState_GetAttribute (1 << 18) 87 | #define kIOGReportAPIState_SetAttribute (1 << 19) 88 | #define kIOGReportAPIState_WSStartAttribute (1 << 20) 89 | #define kIOGReportAPIState_EndConnectionChange (1 << 21) 90 | #define kIOGReportAPIState_ProcessConnectionChange (1 << 22) 91 | #define kIOGReportAPIState_RequestProbe (1 << 23) 92 | #define kIOGReportAPIState_Close (1 << 24) 93 | #define kIOGReportAPIState_SetProperties (1 << 25) 94 | #define kIOGReportAPIState_CopySharedCursor (1 << 26) 95 | #define kIOGReportAPIState_SetHibernateGammaTable (1 << 27) 96 | #define kIOGReportAPIState_SetNotificationPort (1 << 28) 97 | #define kIOGReportAPIState_RestoreCDBlob (1 << 29) 98 | 99 | 100 | #pragma pack(push, 4) 101 | typedef struct _iostamp { 102 | char name[64]; 103 | uint64_t start; 104 | uint64_t end; 105 | uint32_t lastEvent; 106 | } IOStamp; 107 | 108 | typedef struct IONotify { 109 | uint64_t groupID; 110 | IOStamp stamp[IOGRAPHICS_MAXIMUM_REPORTS]; 111 | } IONotify; 112 | 113 | typedef struct IOGReport { 114 | uint32_t stateBits; 115 | uint32_t pendingPowerState; 116 | 117 | uint32_t notificationGroup; 118 | uint32_t externalAPIState; 119 | 120 | uint64_t systemOwner; 121 | uint64_t workloopOwner; 122 | uint64_t notificationOwner; 123 | uint64_t regID; 124 | 125 | uint32_t dependentIndex; 126 | uint32_t wsaaState; 127 | 128 | uint32_t systemGatedCount; 129 | uint32_t workloopGatedCount; 130 | 131 | char objectName[64]; 132 | #if defined(IOGD530_14) || defined(IOGD530_66) || defined(IOGD576_1) 133 | char framebufferName[8]; 134 | #else 135 | char framebufferName[64]; 136 | #endif 137 | 138 | IONotify notifications[IOGRAPHICS_MAXIMUM_REPORTS]; 139 | 140 | uint32_t lastSuccessfulMode; 141 | uint32_t aliasID; 142 | 143 | #if defined(IOGD530_14) 144 | uint64_t reservedC[15]; 145 | #else 146 | uint32_t lastWSAAStatus; 147 | 148 | uint32_t reservedA; 149 | uint64_t reservedB[14]; 150 | #endif 151 | } IOGReport; 152 | 153 | typedef struct IOGDiagnose { 154 | // Kernel to User 155 | uint64_t version; 156 | uint64_t framebufferCount; 157 | 158 | uint32_t length; 159 | #if defined(IOGD530_14) 160 | uint32_t _reservedA; 161 | IOGReport fbState[IOGRAPHICS_MAXIMUM_REPORTS]; 162 | 163 | uint32_t _reservedB[8]; 164 | 165 | uint64_t systemBootEpochTime; 166 | uint32_t tokenLine; 167 | uint32_t tokenLineCount; 168 | uint32_t tokenSize; 169 | uint64_t tokenBuffer[IOGRAPHICS_TOKENBUFFERSIZE]; 170 | #else 171 | uint32_t _reservedB[7]; 172 | 173 | uint64_t systemBootEpochTime; 174 | 175 | IOGReport fbState[IOGRAPHICS_MAXIMUM_FBS]; 176 | #endif 177 | } IOGDiagnose; 178 | #pragma pack(pop) 179 | 180 | 181 | #endif /* IOGraphicsDiagnose_h */ 182 | -------------------------------------------------------------------------------- /AllRez/IOGraphics/IOGraphicsFamily/IOKit/graphics/GTraceTypes.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // GTraceTypes.hpp 3 | // IOGraphics 4 | // 5 | // Created by Jeremy Tran on 8/8/17. 6 | // Rewritten by Godfrey van der Linden on 2018-08-17 7 | // Shared file between kernel and user land 8 | // 9 | 10 | #ifndef GTraceTypes_hpp 11 | #define GTraceTypes_hpp 12 | 13 | #include "MacOSMacros.h" 14 | 15 | #include 16 | 17 | #if MAC_OS_X_VERSION_SDK >= MAC_OS_X_VERSION_10_10 18 | #include 19 | #endif 20 | 21 | #include 22 | 23 | #ifndef GTRACE_ARCHAIC_CPP 24 | #define GTRACE_ARCHAIC_CPP ((KERNEL || _KERNEL_) && __cplusplus < 201103L) 25 | #endif 26 | 27 | #define GTRACE_REVISION 0x2 28 | 29 | #define kGTraceMaximumBufferCount 32 30 | 31 | #define kGTraceMaxBreadcrumbSize (16 * 1024) // 16KiB 32 | #define kGTraceMinimumLineCount UINT32_C(1024) // @64b == 64k 33 | #define kGTraceDevelopLineCount UINT32_C(3072) // @64b == 192k 34 | #define kGTraceMaximumLineCount UINT32_C(8192) // @64b == 512k 35 | 36 | #if DEVELOPMENT 37 | #define kGTraceDefaultLineCount kGTraceDevelopLineCount 38 | #else 39 | #define kGTraceDefaultLineCount kGTraceMinimumLineCount 40 | #endif 41 | 42 | #pragma mark - Masks 43 | #define kGTRACE_COMPONENT_MASK 0x00000000FFFFFFFFULL // 32 bits 44 | #define kTHREAD_ID_MASK 0x0000000000FFFFFFULL // 24 bits 45 | #define kGTRACE_REGISTRYID_MASK 0x00000000FFFFFFFFULL // 32 bits 46 | 47 | 48 | // Helpers 49 | #define MAKEGTRACETAG(x) static_cast(x) 50 | #define MAKEGTRACEARG(x) static_cast(x) 51 | 52 | // Argument Tag Bits, might be better as a 16 value(4 bit) field, but for the 53 | // time being lets not confuse the binary interpretation of existing data. 54 | #define kGTRACE_ARGUMENT_Reserved1 0x1000 // Future Use 55 | #define kGTRACE_ARGUMENT_STRING 0x2000 // Argument string may be swapped to Host byte order 56 | #define kGTRACE_ARGUMENT_BESTRING 0x4000 // Argument string is in big endian byte order 57 | #if KERNEL || _KERNEL_ 58 | #define kGTRACE_ARGUMENT_POINTER 0x8000 // Arguments tagged with this bit are pointers and will be obfuscated when copied/printed. Must not be used in the first ARG position 59 | #else 60 | // kGTRACE_ARGUMENT_POINTER is undefined in user land. DO NOT record pointers 61 | // in either a trace entry nor anywhere in the breadcrumb buffer. The problem 62 | // is that pointers will be published in a sysdiagnose and would make the 63 | // randomisation slide public which defeats the purpose of address-space 64 | // randomisation. 65 | #endif 66 | 67 | #define kGTRACE_ARGUMENT_STRING_MASK (kGTRACE_ARGUMENT_STRING | kGTRACE_ARGUMENT_BESTRING) 68 | #define kGTRACE_ARGUMENT_MASK 0xF000 69 | 70 | // Use this to encode tag0, for automatic decoding and start/end pairing 71 | #define GPACKFUNCTAG(funcid, functype, tag0) \ 72 | MAKEGTRACETAG((((functype) & 0x3) << 10) | ((funcid) & 0x03FF) | (tag0)) 73 | #define GUNPACKFUNCTYPE(tag0) static_cast((tag0 >> 10) & 0x3) 74 | #define GUNPACKFUNCCODE(tag0) static_cast(tag0 & 0x03FF) 75 | #define GUNPACKTAG0(tag0) \ 76 | static_cast(tag0 & kGTRACE_ARGUMENT_MASK) 77 | 78 | #define GMUL8(v) ((v) << 3) 79 | #define GMUL16(v) ((v) << 4) 80 | #define GMUL32(v) ((v) << 5) 81 | #define GPACKNODATA 0 // 0 is a valid value, NoData used to distinguish 82 | #define GPACKBITS(shift, value) \ 83 | (MAKEGTRACEARG(value) & ((1ULL << (shift)) - 1)) 84 | 85 | /* GPACKBIT 86 | * value: boolean value 87 | * bitidx: index of bit in uint64_t result; valid range: [0, 63] */ 88 | #define GPACKBIT(bitidx, value) \ 89 | MAKEGTRACEARG((static_cast(value)) ? (1ULL << (bitidx)) : 0) 90 | #define GUNPACKBIT(bitidx, value) \ 91 | static_cast(MAKEGTRACEARG(value) & (1ULL << (bitidx))) 92 | 93 | /* GPACKUINT8T 94 | * value: uint8_t value 95 | * ui8idx: index of uint8_t in uint64_t result; valid range: [0, 7] */ 96 | #define GPACKUINT8T(ui8idx, value) \ 97 | (MAKEGTRACEARG(value & 0x000000ff) << GMUL8(ui8idx)) 98 | #define GUNPACKUINT8T(ui8idx, value) \ 99 | static_cast(MAKEGTRACEARG(value) >> GMUL8(ui8idx)) 100 | 101 | /* GPACKUINT16T 102 | * value: uint16_t value 103 | * ui16idx: index of uint16_t in uint64_t result; valid range: [0, 3] */ 104 | #define GPACKUINT16T(ui16idx, value) \ 105 | (MAKEGTRACEARG(value & 0x0000ffff) << GMUL16(ui16idx)) 106 | #define GUNPACKUINT16T(ui16idx, value) \ 107 | static_cast(MAKEGTRACEARG(value) >> GMUL16(ui16idx)) 108 | 109 | /* GPACKUINT32T 110 | * value: uint32_t value 111 | * ui8idx: index of uint32_t in uint64_t result; valid range: [0, 1] */ 112 | #define GPACKUINT32T(ui32idx, value) \ 113 | (MAKEGTRACEARG(value & 0xffffffff) << GMUL32(ui32idx)) 114 | #define GUNPACKUINT32T(ui32idx, value) \ 115 | static_cast(MAKEGTRACEARG(value) >> GMUL32(ui32idx)) 116 | 117 | #define GPACKUINT64T(value) (value) 118 | #define GUNPACKUINT64T(value) (value) 119 | 120 | #define GPACKSTRINGCAST(ia) reinterpret_cast(ia) 121 | #define GPACKSTRING(ia, str) strlcpy(GPACKSTRINGCAST(ia), str, sizeof(ia)) 122 | 123 | #if defined(IOGD530_66) 124 | // User client commands 125 | OS_ENUM(gtrace_command, uint64_t, 126 | kGTraceCmdFetch = 'Ftch', 127 | ); 128 | #endif 129 | 130 | // These structures must be power of 2 for performance, alignment, and the 131 | // buffer-to-line calculations 132 | #pragma pack(push, 1) 133 | 134 | typedef struct GTraceEntry { 135 | #if !__cplusplus 136 | uint64_t fEntry[8]; // Pure C interface 137 | #else // C++ interface 138 | // Internal structures 139 | struct ID { 140 | uint64_t fID; 141 | 142 | #if !GTRACE_ARCHAIC_CPP 143 | ID(uint64_t id) : fID(id) {} 144 | ID(uint64_t line, uint64_t component) 145 | : fID((line & 0xffff) | (component << 16)) {} 146 | #endif 147 | 148 | uint64_t id() const { return fID; } 149 | uint16_t line() const { return static_cast(fID); } 150 | uint64_t component() const { return static_cast(fID) >> 16; } 151 | }; 152 | 153 | struct ThreadInfo { 154 | uint64_t fTi; 155 | 156 | #if !GTRACE_ARCHAIC_CPP 157 | ThreadInfo(uint64_t cpu, uint64_t threadID, uint64_t registryID) 158 | : fTi( (cpu & 0xff) | ((threadID & 0xffffff) << 8) 159 | | ((registryID & 0xffffffff) << 32)) {} 160 | #endif 161 | 162 | uint8_t cpu() const { return static_cast(fTi); } 163 | uint32_t threadID() const { return static_cast(fTi) >> 8; } 164 | uint32_t registryID() const { return static_cast(fTi >> 32); } 165 | }; 166 | 167 | struct ArgsTag { 168 | static const int kNum = 4; 169 | union { 170 | uint16_t fTarg[kNum]; 171 | uint64_t fTag64; 172 | }; 173 | 174 | #if !GTRACE_ARCHAIC_CPP 175 | ArgsTag(uint64_t tag) : fTag64{tag} {} 176 | ArgsTag(uint16_t tag0, uint16_t tag1, uint16_t tag2, uint16_t tag3) 177 | { 178 | fTarg[0] = tag0; fTarg[1] = tag1; fTarg[2] = tag2; fTarg[3] = tag3; 179 | } 180 | #endif 181 | 182 | uint64_t tag() const { return fTag64; } 183 | const uint16_t& tag(const int idx) const { return fTarg[idx]; } 184 | uint16_t& tag(const int idx) { return fTarg[idx]; } 185 | }; 186 | 187 | struct Args { 188 | union { 189 | uint64_t fU64s[4]; 190 | uint32_t fU32s[8]; 191 | uint16_t fU16s[16]; 192 | uint8_t fU8s[32]; 193 | char fStr[32]; 194 | }; 195 | 196 | #if !GTRACE_ARCHAIC_CPP 197 | Args(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3) 198 | { 199 | fU64s[0] = arg0; fU64s[1] = arg1; fU64s[2] = arg2; fU64s[3] = arg3; 200 | } 201 | #endif 202 | 203 | const uint64_t& u64(const int idx) const { return fU64s[idx]; } 204 | const uint32_t& u32(const int idx) const { return fU32s[idx]; } 205 | const uint16_t& u16(const int idx) const { return fU16s[idx]; } 206 | const uint8_t& u8(const int idx) const { return fU8s[idx]; } 207 | const char* str() const { return fStr; } 208 | uint64_t& u64(const int idx) { return fU64s[idx]; } 209 | uint32_t& u32(const int idx) { return fU32s[idx]; } 210 | uint16_t& u16(const int idx) { return fU16s[idx]; } 211 | uint8_t& u8(const int idx) { return fU8s[idx]; } 212 | char* str() { return fStr; } 213 | }; 214 | 215 | // GTraceEntry data 216 | union { 217 | struct { 218 | uint64_t fTimestamp; // mach continuous time 219 | ID fID; // unique ID to entry 220 | ThreadInfo fThreadInfo; // CPU, thread info 221 | ArgsTag fArgsTag; // Argument tags 222 | Args fArgs; // Argument data 223 | }; 224 | #if !GTRACE_ARCHAIC_CPP 225 | uint64_t fEntry[8] = { 0 }; 226 | #else 227 | uint64_t fEntry[8]; 228 | #endif 229 | }; 230 | 231 | #if !GTRACE_ARCHAIC_CPP 232 | GTraceEntry() {} 233 | 234 | // Special entry used as the first entry in a binary GTrace file 235 | // If the timestamp/fEntry[0] == -1, then fEntry[1] contains a count of the 236 | // number of buffers in this file. The buffers themselves are self 237 | // describing and contain version information. 238 | GTraceEntry(const int16_t numBuffers, const uint64_t gtraceVersion) 239 | { 240 | memset(&fEntry[0], -1, sizeof(fEntry)); 241 | fID = ID(numBuffers, gtraceVersion); 242 | } 243 | 244 | // Buffer bound Entry, inserted during sorting for output 245 | GTraceEntry(const uint64_t timestamp, const uint64_t component, 246 | const uint16_t funcid) 247 | { 248 | fTimestamp = timestamp; 249 | fID = ID{0, component}; 250 | fArgsTag.fTarg[0] = funcid; 251 | } 252 | 253 | GTraceEntry(const uint64_t timestamp, const uint16_t line, 254 | const uint64_t componentID, const uint8_t cpu, 255 | const uint64_t tID, const uint32_t regID, 256 | const uint16_t tag1, const uint64_t arg1, 257 | const uint16_t tag2, const uint64_t arg2, 258 | const uint16_t tag3, const uint64_t arg3, 259 | const uint16_t tag4, const uint64_t arg4) 260 | : fTimestamp{timestamp}, fID{line, componentID}, 261 | fThreadInfo{cpu, tID, regID}, 262 | fArgsTag{tag1, tag2, tag3, tag4}, fArgs{arg1, arg2, arg3, arg4} {} 263 | #endif // !GTRACE_ARCHAIC_CPP 264 | 265 | GTraceEntry(const uint64_t timestamp, const uint16_t line, 266 | const uint64_t componentID, const uint8_t cpu, 267 | const uint64_t tID, const uint32_t regID, 268 | const uint64_t tags, const uint64_t arg1, 269 | const uint64_t arg2, const uint64_t arg3, 270 | const uint64_t arg4) 271 | : fTimestamp{timestamp}, fID{line, componentID}, 272 | fThreadInfo{cpu, tID, regID}, 273 | fArgsTag{tags}, fArgs{arg1, arg2, arg3, arg4} {} 274 | 275 | // Copy constructor and assignment 276 | GTraceEntry(const GTraceEntry& other) 277 | { memcpy(&fEntry[0], &other.fEntry[0], sizeof(fEntry)); } 278 | GTraceEntry& operator=(const GTraceEntry& other) 279 | { 280 | memcpy(&fEntry[0], &other.fEntry[0], sizeof(fEntry)); 281 | return *this; 282 | } 283 | 284 | // Accessors 285 | uint64_t timestamp() const { return fTimestamp; } 286 | uint64_t id() const { return fID.id(); } 287 | uint16_t line() const { return fID.line(); } 288 | uint64_t component() const { return fID.component(); } 289 | uint8_t cpu() const { return fThreadInfo.cpu(); } 290 | uint32_t threadID() const { return fThreadInfo.threadID(); } 291 | uint32_t registryID() const { return fThreadInfo.registryID(); } 292 | uint64_t tag() const { return fArgsTag.tag(); } 293 | const uint16_t& tag(const int idx) const { return fArgsTag.tag(idx); } 294 | const uint64_t& arg64(const int idx) const { return fArgs.u64(idx); } 295 | const uint32_t& arg32(const int idx) const { return fArgs.u32(idx); } 296 | const uint16_t& arg16(const int idx) const { return fArgs.u16(idx); } 297 | const uint8_t & arg8(const int idx) const { return fArgs.u8(idx); } 298 | uint16_t& tag(const int idx) { return fArgsTag.tag(idx); } 299 | uint64_t& arg64(const int idx) { return fArgs.u64(idx); } 300 | uint32_t& arg32(const int idx) { return fArgs.u32(idx); } 301 | uint16_t& arg16(const int idx) { return fArgs.u16(idx); } 302 | uint8_t & arg8(const int idx) { return fArgs.u8(idx); } 303 | 304 | // For sorting, timestamp, ID, CPUThreadID as uint64_t 305 | friend bool operator<(const GTraceEntry& lhs, const GTraceEntry& rhs); 306 | #endif // !__cplusplus 307 | } GTraceEntry; 308 | #define kGTraceEntrySize static_cast(sizeof(GTraceEntry)) 309 | 310 | typedef struct GTraceHeader 311 | { // [ind] uint64_ts 312 | uint64_t fDecoderName[4]; // 0 32 byte decoder module name 313 | uint64_t fBufferName[4]; // 4 32 byte buffer name 314 | uint64_t fCreationTime; // 8 creation mach continuous time 315 | uint32_t fBufferID; // 9 Unique ID of buffer 316 | uint32_t fBufferSize; // 9 Bytes, buffer size including header 317 | uint32_t fTokenLine; // 10 Current out token 318 | uint16_t fVersion; // 10 GTrace version 319 | uint16_t fBufferIndex; // 10 Index of buffer in system 320 | uint16_t fTokensMask; // 11 Mask from fTokenLine to index 321 | uint16_t fBreadcrumbTokens; // 11 Size in tokens of breadcrumb 322 | uint16_t fTokensCopied; // 11 Number of fTokens copied 323 | } GTraceHeader; 324 | 325 | // Note every section is a multiple of sizeof(GTraceEntry), i.e. 64, bytes. 326 | #define kGTraceHeaderEntries 2 327 | #define kGTraceHeaderSize (kGTraceHeaderEntries * kGTraceEntrySize) 328 | struct IOGTraceBuffer 329 | { 330 | union { 331 | GTraceHeader fHeader; 332 | GTraceEntry _padding[kGTraceHeaderEntries]; 333 | }; 334 | // Breadcrumb, fTokens[0]–fTokens[fHeader.fBreadcrumbTokens] inclusive 335 | // Tokens, fTokens[fHeader.fBreadcrumbTokens]–fTokens[fHeader.fTokensCopied] 336 | GTraceEntry fTokens[]; 337 | }; 338 | 339 | #pragma pack(pop) 340 | 341 | #if __cplusplus 342 | // May need to redesign if this assumption changes, test for it 343 | static_assert(sizeof(GTraceHeader) <= kGTraceHeaderSize, 344 | "header doesnt fit in two entries, change union to preserve alignment"); 345 | static_assert(kGTraceEntrySize == 8 * sizeof(uint64_t), 346 | "GTraceEntry != 64 bytes"); 347 | #endif // __cplusplus 348 | 349 | #if !KERNEL && __cplusplus 350 | #include 351 | #include // for std::pair 352 | class GTraceBuffer 353 | { 354 | public: 355 | using vector_type = std::vector; 356 | using vector_iter_type = vector_type::iterator; 357 | using vector_citer_type = vector_type::const_iterator; 358 | 359 | using breadcrumb_type = std::pair; 360 | using tokens_type = std::pair; 361 | using ctokens_type = std::pair; 362 | 363 | explicit GTraceBuffer(vector_type&& entries) 364 | : fData(std::move(entries)) 365 | {} 366 | GTraceBuffer(vector_citer_type begin, vector_citer_type end) 367 | : fData(vector_type(begin, end)) 368 | {} 369 | 370 | // Move constructor and assignment 371 | GTraceBuffer(GTraceBuffer&& other) 372 | : fData(std::move(other.fData)) 373 | {} 374 | GTraceBuffer& operator=(GTraceBuffer&& other) 375 | { 376 | if (this != &other) 377 | fData = std::move(other.fData); 378 | return *this; 379 | } 380 | 381 | // copy constructor and assignment 382 | GTraceBuffer(const GTraceBuffer& other) = delete; 383 | GTraceBuffer& operator=(const GTraceBuffer& other) = delete; 384 | 385 | // Accessors 386 | GTraceHeader& header() 387 | { return *reinterpret_cast(fData.data()); } 388 | const GTraceHeader& header() const 389 | { return *reinterpret_cast(fData.data()); } 390 | 391 | breadcrumb_type breadcrumb() 392 | { 393 | const size_t bcl = header().fBreadcrumbTokens; 394 | auto& firstBCEntry = fData.at(2); 395 | void* bcP = reinterpret_cast(&firstBCEntry); 396 | return breadcrumb_type{(bcl ? bcP : nullptr), bcl}; 397 | } 398 | tokens_type tokens() 399 | { 400 | tokens_type ret{fData.begin(), fData.begin()}; // Zero length 401 | if (header().fTokensCopied) { 402 | const uint32_t& bct = header().fBreadcrumbTokens; 403 | ret = tokens_type{fData.begin() + 2 + bct, fData.end()}; 404 | } 405 | return ret; 406 | } 407 | ctokens_type ctokens() const 408 | { 409 | ctokens_type ret{fData.cend(), fData.cend()}; // Zero length 410 | if (header().fTokensCopied) { 411 | const uint32_t& bct = header().fBreadcrumbTokens; 412 | ret = ctokens_type{fData.cbegin() + 2 + bct, fData.cend()}; 413 | } 414 | return ret; 415 | } 416 | const vector_type& vec() const { return fData; } 417 | const GTraceEntry* data() const { return fData.data(); } 418 | vector_type::size_type size() const { return fData.size(); } 419 | 420 | void removeTokens() 421 | { 422 | ctokens_type ctokenpair = ctokens(); 423 | fData.erase(ctokenpair.first, ctokenpair.second); 424 | fData.shrink_to_fit(); 425 | } 426 | 427 | private: 428 | std::vector fData; 429 | }; 430 | #endif // !KERNEL && __cplusplus 431 | #endif /* GTraceTypes_hpp */ 432 | -------------------------------------------------------------------------------- /AllRez/IOGraphics/IOGraphicsFamily/tools/Utilities/IOGDiagnoseUtils.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // IOGDiagnoseUtils.cpp 3 | // IOGDiagnoseUtils 4 | // 5 | // Created by Jérémy Tran on 8/8/17. 6 | // 7 | 8 | #include "IOGDiagnoseUtils.hpp" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | // Pick up local headers 17 | #include 18 | #include "AppleMisc.h" 19 | 20 | #ifdef TARGET_CPU_X86_64 21 | 22 | #define COUNT_OF(x) \ 23 | ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) 24 | #define kResourcePath kIOServicePlane ":/" kIOResourcesClass "/" 25 | 26 | namespace { 27 | kern_return_t openWranglerUC( 28 | IOConnect* diagConnectP, uint32_t type, const char **errmsgP) 29 | { 30 | static const char * const sWranglerPath = kResourcePath "IODisplayWrangler"; 31 | char errbuf[128] = ""; 32 | kern_return_t err = kIOReturnInternalError; 33 | 34 | do { 35 | err = kIOReturnNotFound; 36 | IOObject wrangler( 37 | IORegistryEntryFromPath(kIOMasterPortDefault, sWranglerPath)); 38 | if (!static_cast(wrangler)) { 39 | snprintf(errbuf, sizeof(errbuf), 40 | "IODisplayWrangler '%s' search failed", sWranglerPath); 41 | continue; 42 | } 43 | 44 | IOConnect wranglerConnect(wrangler, type); 45 | err = wranglerConnect.err(); 46 | if (err) { 47 | const char * typeStr 48 | = (type == kIOGDiagnoseConnectType) ? "Diagnose" 49 | : (type == kIOGDiagnoseGTraceType) ? "Gtrace" 50 | : "Unknown"; 51 | snprintf(errbuf, sizeof(errbuf), 52 | "IOServiceOpen(%s) on IODisplayWrangler failed", typeStr); 53 | continue; 54 | } 55 | *diagConnectP = std::move(wranglerConnect); 56 | } while(false); 57 | 58 | if (err && errmsgP) { 59 | char *tmpMsg; 60 | asprintf(&tmpMsg, "%s - %s(%x)", errbuf, mach_error_string(err), err); 61 | *errmsgP = tmpMsg; 62 | } 63 | return err; 64 | } 65 | } // namespace 66 | 67 | kern_return_t openDiagnostics(IOConnect* diagConnectP, const char **errmsgP) 68 | { 69 | return openWranglerUC(diagConnectP, kIOGDiagnoseConnectType, errmsgP); 70 | } 71 | 72 | kern_return_t openGTrace(IOConnect* gtraceConnectP, const char **errmsgP) 73 | { 74 | return openWranglerUC(gtraceConnectP, kIOGDiagnoseGTraceType, errmsgP); 75 | } 76 | 77 | #endif // TARGET_CPU_X86_64 78 | -------------------------------------------------------------------------------- /AllRez/IOGraphics/IOGraphicsFamily/tools/Utilities/IOGDiagnoseUtils.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // IOGDiagnoseUtils.hpp 3 | // IOGDiagnoseUtils 4 | // 5 | // Created by Jérémy Tran on 8/8/17. 6 | // 7 | 8 | #ifndef IOGDiagnoseUtils_hpp 9 | #define IOGDiagnoseUtils_hpp 10 | 11 | #if defined(IOGD530_66) 12 | #include 13 | #include 14 | #endif 15 | 16 | #include "iokit.h" 17 | 18 | #if defined(IOGD530_66) 19 | #include "IOGraphicsDiagnose.h" 20 | #include "GTraceTypes.hpp" 21 | #endif 22 | 23 | #if defined(IOGD530_66) 24 | kern_return_t openDiagnostics(IOConnect* diagConnectP, char **errmsgP); 25 | 26 | IOReturn fetchGTraceBuffers(const IOConnect& diag, 27 | std::vector* traceBuffersP); 28 | /*! 29 | @brief Populate a pre-allocated IOGDiagnose pointer with data coming from 30 | IOGraphics. Also populates a vector of GTraceEntry tables. 31 | 32 | @param reportP An allocated pointer to a IOGDiagnose struct. 33 | @param reportLength The memory length of the passed pointer. Should be greater 34 | or equal to @c sizeof(IOGDiagnose). 35 | @param errmsgP Pointer to a string used by the function to return error 36 | messages. Must be freed by callee. 37 | */ 38 | 39 | // If errmsgP is set then the caller is required to free returned string 40 | kern_return_t iogDiagnose(const IOConnect& diag, 41 | IOGDiagnose* reportP, size_t reportLength, 42 | std::vector* traceBuffersP, 43 | char** errmsgP); 44 | #else 45 | kern_return_t openDiagnostics(IOConnect* diagConnectP, const char **errmsgP); 46 | kern_return_t openGTrace(IOConnect* gtraceConnectP, const char **errmsgP); 47 | #endif 48 | #endif // IOGDiagnoseUtils_hpp 49 | -------------------------------------------------------------------------------- /AllRez/IOGraphics/IOGraphicsFamily/tools/Utilities/iokit.h: -------------------------------------------------------------------------------- 1 | // vim: set ft=cpp: 2 | // 3 | // IOGDiagnoseUtils/iokit 4 | // IOGDiagnoseUtils 5 | // 6 | // Created by Godfrey van der Linden 2018-10-31 7 | // 8 | 9 | #ifndef IOGDIAGNOSEUTILS_IOKIT 10 | #define IOGDIAGNOSEUTILS_IOKIT 11 | 12 | #if defined(IOGD530_66) 13 | #else 14 | #include 15 | #endif 16 | 17 | #include 18 | 19 | class IOObject 20 | { 21 | // Takes ownership of IOKit registry object 22 | mutable io_object_t fObject = MACH_PORT_NULL; 23 | void retain() const { 24 | if (fObject) 25 | IOObjectRetain(fObject); 26 | } 27 | void release() const { 28 | if (fObject) { 29 | IOObjectRelease(fObject); 30 | fObject = MACH_PORT_NULL; 31 | } 32 | } 33 | public: 34 | // Takes ownership of IOKit user client connection 35 | IOObject(io_object_t object) : fObject(object) { } 36 | ~IOObject() { release(); } 37 | // Takes ownership of underlying connect, will release at end of scope 38 | IOObject& operator=(const io_object_t& object) 39 | { 40 | release(); 41 | fObject = object; 42 | return *this; 43 | } 44 | 45 | // Copy support 46 | IOObject(const IOObject& other) 47 | { 48 | release(); 49 | other.retain(); 50 | fObject = other.fObject; 51 | } 52 | IOObject& operator=(const IOObject& other) 53 | { 54 | if (this != &other) { 55 | release(); 56 | other.retain(); 57 | fObject = other.fObject; 58 | } 59 | return *this; 60 | } 61 | 62 | // Move support 63 | IOObject(IOObject&& other) 64 | { 65 | if (this != &other) { 66 | release(); 67 | std::swap(fObject, other.fObject); 68 | } 69 | } 70 | IOObject& operator=(IOObject&& other) 71 | { 72 | if (this != &other) { 73 | release(); 74 | std::swap(fObject, other.fObject); 75 | } 76 | return *this; 77 | } 78 | io_object_t get() const { return fObject; } 79 | operator bool() const { return static_cast(get()); } 80 | }; 81 | 82 | class IOConnect 83 | { 84 | kern_return_t fLastErr = kIOReturnSuccess; 85 | io_connect_t fConnect = MACH_PORT_NULL; 86 | void release() 87 | { 88 | if (fConnect) { 89 | IOServiceClose(fConnect); 90 | fConnect = MACH_PORT_NULL; 91 | } 92 | fLastErr = kIOReturnSuccess; 93 | } 94 | kern_return_t open(const io_object_t o, const uint32_t t, io_connect_t* cp) 95 | { return IOServiceOpen(o, mach_task_self(), t, cp); } 96 | public: 97 | // Takes ownership of IOKit user client connection 98 | IOConnect(io_object_t object, uint32_t type) // Open constructor 99 | { fLastErr = open(object, type, &fConnect); } 100 | IOConnect(const IOObject& object, uint32_t type) // Open constructor 101 | { fLastErr = open(object.get(), type, &fConnect); } 102 | explicit IOConnect(io_connect_t connect) : fConnect(connect) {} 103 | IOConnect() {} 104 | ~IOConnect() { release(); } 105 | IOConnect(IOConnect&& other) 106 | { 107 | if (this != &other) { 108 | release(); 109 | std::swap(fLastErr, other.fLastErr); 110 | std::swap(fConnect, other.fConnect); 111 | } 112 | } 113 | IOConnect& operator=(IOConnect&& other) 114 | { 115 | if (this != &other) { 116 | release(); 117 | std::swap(fLastErr, other.fLastErr); 118 | std::swap(fConnect, other.fConnect); 119 | } 120 | return *this; 121 | } 122 | 123 | // Takes ownership of underlying connect, will close at end of scope 124 | IOConnect& operator=(const io_connect_t& connect) 125 | { 126 | if (fConnect != connect) { 127 | release(); 128 | fConnect = connect; 129 | } 130 | return *this; 131 | } 132 | 133 | // No valid copy semantic for io_connect_t as IOServiceClose is not 134 | // reference counted thus the first close will destroy the connection. 135 | IOConnect(const IOConnect& other) = delete; 136 | IOConnect& operator=(const IOConnect& other) = delete; 137 | 138 | io_connect_t get() const { return fConnect; } 139 | kern_return_t err() const { return fLastErr; } 140 | operator bool() const { return static_cast(get()); } 141 | 142 | kern_return_t callMethod(uint32_t selector, // In 143 | const uint64_t* in, // In 144 | uint32_t inCnt, // In 145 | const void* inBlob, // In 146 | size_t inBlobCnt, // In 147 | uint64_t* out, // Out 148 | uint32_t* outCnt, // In/Out 149 | void* outBlob, // Out 150 | size_t* outBlobCntP) // In/Out 151 | const 152 | { 153 | return IOConnectCallMethod(fConnect, selector, 154 | in, inCnt, inBlob, inBlobCnt, 155 | out, outCnt, outBlob, outBlobCntP); 156 | } 157 | }; 158 | 159 | #endif // !IOGDIAGNOSEUTILS_IOKIT 160 | -------------------------------------------------------------------------------- /AllRez/IOGraphics530.14/GTrace/GTraceTypes.h: -------------------------------------------------------------------------------- 1 | // 2 | // GTraceTypes.h 3 | // IOGraphics 4 | // 5 | // Created by Jeremy Tran on 8/8/17. 6 | // 7 | 8 | #ifndef GTrace_h 9 | #define GTrace_h 10 | 11 | #include "MacOSMacros.h" 12 | #include 13 | #include 14 | 15 | #pragma mark - Header Revision 16 | #define GTRACE_REVISION 0x1 17 | 18 | #pragma mark - Constants 19 | #define kGTraceMaximumLineCount 8192 // @64b == 512k 20 | #define kGTraceDefaultLineCount 2048 // @64b == 128K 21 | 22 | __BEGIN_DECLS 23 | 24 | #pragma mark - GTrace Structures 25 | /* 26 | These structures must be power of 2 for performance, alignment, and the buffer-to-line calculations 27 | */ 28 | #pragma pack(push, 1) 29 | typedef struct _GTraceID { 30 | union { 31 | struct { 32 | uint64_t line:16; 33 | uint64_t component:48; 34 | }; 35 | uint64_t u64; 36 | } ID; 37 | } sGTraceID; 38 | 39 | typedef struct _GTraceThreadInfo { 40 | union { 41 | struct { 42 | uint64_t cpu:8; 43 | uint64_t threadID:24; 44 | uint64_t registryID:32; 45 | }; 46 | uint64_t u64; 47 | } TI; 48 | } sGTraceThreadInfo; 49 | extern int assertx00[(sizeof(sGTraceThreadInfo) == 8) - 1]; 50 | 51 | typedef struct _GTraceArgsTag { 52 | union { 53 | struct { 54 | uint16_t targ[4]; 55 | }; 56 | uint64_t u64; 57 | } TAG; 58 | } sGTraceArgsTag; 59 | extern int assertx01[(sizeof(sGTraceArgsTag) == 8) - 1]; 60 | 61 | typedef struct _GTraceArgs { 62 | union { 63 | uint64_t u64s[4]; 64 | uint32_t u32s[8]; 65 | uint16_t u16s[16]; 66 | uint8_t u8s[32]; 67 | char str[32]; 68 | } ARGS; 69 | } sGTraceArgs; 70 | extern int assertx02[(sizeof(sGTraceArgs) == 32) - 1]; 71 | 72 | 73 | typedef struct _GTrace { 74 | union { 75 | struct { 76 | uint64_t timestamp; // mach absolute time 77 | sGTraceID traceID; // unique ID to entry 78 | sGTraceThreadInfo threadInfo; // CPU, thread info 79 | sGTraceArgsTag argsTag; // Argument tags 80 | sGTraceArgs args; // Argument data 81 | }; 82 | uint64_t entry[8]; 83 | } traceEntry; 84 | } sGTrace; 85 | #pragma pack(pop) 86 | 87 | #if defined(__cplusplus) && defined(__clang__) && MAC_OS_X_VERSION_SDK >= MAC_OS_X_VERSION_10_14 88 | static_assert(sizeof(sGTrace) == 64, "sGTrace != 64 bytes"); 89 | #else 90 | #if MAC_OS_X_VERSION_SDK >= MAC_OS_X_VERSION_10_6 91 | #include 92 | #else 93 | #ifndef __Check_Compile_Time 94 | #ifdef __GNUC__ 95 | #define __Check_Compile_Time( expr ) \ 96 | extern int compile_time_assert_failed[ ( expr ) ? 1 : -1 ] __attribute__( ( unused ) ) 97 | #else 98 | #define __Check_Compile_Time( expr ) \ 99 | extern int compile_time_assert_failed[ ( expr ) ? 1 : -1 ] 100 | #endif 101 | #endif 102 | #endif 103 | __Check_Compile_Time(sizeof(sGTrace) == 64); 104 | #endif 105 | 106 | __END_DECLS 107 | 108 | #endif /* GTraceTypes_h */ 109 | -------------------------------------------------------------------------------- /AllRez/IOGraphics530.14/iogdiagnose/IOGDiagnoseUtils/IOGDiagnoseUtils.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // IOGDiagnoseUtils.cpp 3 | // IOGDiagnoseUtils 4 | // 5 | // Created by Jérémy Tran on 8/8/17. 6 | // 7 | 8 | #define IOGD530_14 9 | 10 | #include "IOGDiagnoseUtils.h" 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #include "AppleMisc.h" 17 | 18 | kern_return_t iogDiagnose(IOGDiagnose * reportP, 19 | size_t reportLength, 20 | uint64_t version, 21 | const char ** errmsgP) 22 | { 23 | const char * errstr = NULL; 24 | kern_return_t err = kIOReturnError; 25 | io_iterator_t iterator = IO_OBJECT_NULL; 26 | 27 | if (!reportP) 28 | { 29 | errstr = "NULL IOGDiagnose pointer argument passed"; 30 | err = kIOReturnBadArgument; 31 | goto exit; 32 | } 33 | if (sizeof(*reportP) > reportLength) 34 | { 35 | errstr = "reportLength argument not big enough to contain a IOGDiagnose object"; 36 | err = kIOReturnBadArgument; 37 | goto exit; 38 | } 39 | err = IOServiceGetMatchingServices(kIOMasterPortDefault, 40 | IOServiceMatching("IOFramebuffer"), 41 | &iterator); 42 | 43 | if (kIOReturnSuccess != err) 44 | { 45 | errstr = "IOService matching of IOFramebuffer failed"; 46 | goto exit; 47 | } 48 | 49 | if (!IOIteratorIsValid(iterator)) 50 | { 51 | errstr = "IOIterator became invalid, cannot proceed forward"; 52 | err = kIOReturnError; 53 | } 54 | else 55 | { 56 | io_service_t framebuffer = IOIteratorNext(iterator); 57 | if (IO_OBJECT_NULL == framebuffer) 58 | { 59 | errstr = "IOGDiagnose failed, no framebuffers found"; 60 | err = kIOReturnNotFound; 61 | } 62 | else 63 | { 64 | io_connect_t connect = IO_OBJECT_NULL; 65 | err = IOServiceOpen(framebuffer, mach_task_self(), kIOFBDiagnoseConnectType, &connect); 66 | if (kIOReturnSuccess != err) 67 | { 68 | errstr = "IOServiceOpen on IOFramebuffer failed"; 69 | } 70 | else 71 | { 72 | bzero(reportP, reportLength); 73 | 74 | reportP->version = version; 75 | reportP->tokenSize = (uint32_t)sizeof(reportP->tokenBuffer); 76 | 77 | #if MAC_OS_X_VERSION_SDK >= MAC_OS_X_VERSION_10_5 78 | uint64_t scalerParams[] = {reportLength, version}; 79 | uint32_t scalerParamsCount = ((uint32_t)sizeof(scalerParams) / (uint32_t)sizeof(scalerParams[0])); 80 | 81 | API_OR_SDK_AVAILABLE_BEGIN(10.5, IOConnectCallMethod) { 82 | err = IOConnectCallMethod(connect, kIOGSharedInterface_IOGDiagnose, 83 | scalerParams, scalerParamsCount, NULL, 0, 84 | NULL, NULL, reportP, &reportLength); 85 | } API_OR_SDK_AVAILABLE_ELSE { 86 | err = kIOReturnUnsupported; 87 | } API_OR_SDK_AVAILABLE_END 88 | #endif 89 | if (kIOReturnSuccess != err) 90 | { 91 | errstr = "IOGDiagnose failed"; 92 | } 93 | IOServiceClose(connect); 94 | } 95 | IOObjectRelease(framebuffer); 96 | } 97 | } 98 | IOObjectRelease(iterator); 99 | 100 | exit: 101 | if (errstr && errmsgP) 102 | { 103 | *errmsgP = errstr; 104 | } 105 | return err; 106 | } 107 | -------------------------------------------------------------------------------- /AllRez/IOGraphics530.14/iogdiagnose/IOGDiagnoseUtils/IOGDiagnoseUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOGDiagnoseUtils.h 3 | // IOGDiagnoseUtils 4 | // 5 | // Created by Jérémy Tran on 8/8/17. 6 | // 7 | 8 | #ifndef IOGDiagnoseLib_h 9 | #define IOGDiagnoseLib_h 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | __BEGIN_DECLS 16 | 17 | #include "IOGraphicsDiagnose.h" 18 | 19 | /*! 20 | @brief Populate a pre-allocated IOGDiagnose pointer with data coming from IOGraphics. 21 | 22 | @param reportP An allocated pointer to a IOGDiagnose struct. 23 | @param reportLength The memory length of the passed pointer. Should be greater 24 | or equal to @c sizeof(IOGDiagnose). 25 | @param version Version of the IOGDiagnose report to request. Use 26 | @em IOGRAPHICS_DIAGNOSE_VERSION for the latest version. 27 | @param errmsgP Pointer to a string used by the function to return error messages. 28 | */ 29 | kern_return_t iogDiagnose(IOGDiagnose * reportP, 30 | size_t reportLength, 31 | uint64_t version, 32 | const char ** errmsgP); 33 | 34 | __END_DECLS 35 | 36 | #endif /* IOGDiagnoseLib_h */ 37 | -------------------------------------------------------------------------------- /AllRez/IOGraphics530.66/iogdiagnose/IOGDiagnoseUtils/IOGDiagnoseUtils.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // IOGDiagnoseUtils.cpp 3 | // IOGDiagnoseUtils 4 | // 5 | // Created by Jérémy Tran on 8/8/17. 6 | // 7 | 8 | #define IOGD530_66 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #include "iokit.h" 19 | 20 | // Pick up local headers 21 | #include 22 | #include "IOGDiagnoseUtils.hpp" 23 | #include "AppleMisc.h" 24 | 25 | using std::vector; 26 | using std::unique_ptr; 27 | 28 | #define COUNT_OF(x) \ 29 | ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) 30 | 31 | kern_return_t openDiagnostics(IOConnect* diagConnectP, char **errmsgP) 32 | { 33 | static const char * const 34 | sWranglerPath = kIOServicePlane ":/IOResources/IODisplayWrangler"; 35 | const char* errmsg; 36 | kern_return_t err = kIOReturnInternalError; 37 | 38 | do { 39 | errmsg = "IODisplayWrangler search failed"; 40 | err = kIOReturnNotFound; 41 | IOObject wrangler( 42 | IORegistryEntryFromPath(kIOMasterPortDefault, sWranglerPath)); 43 | if (!static_cast(wrangler)) 44 | continue; 45 | 46 | errmsg = "IOServiceOpen on IODisplayWrangler failed"; 47 | IOConnect wranglerConnect(wrangler, kIOGDiagnoseConnectType); 48 | err = wranglerConnect.err(); 49 | if (err) continue; 50 | *diagConnectP = std::move(wranglerConnect); 51 | } while(false); 52 | 53 | if (err && errmsgP) 54 | asprintf(errmsgP, "%s - %s(%x)", errmsg, mach_error_string(err), err); 55 | return err; 56 | 57 | } 58 | 59 | IOReturn fetchGTraceBuffers(const IOConnect& diag, 60 | vector* traceBuffersP) 61 | { 62 | uint64_t scalarParams[] = { GTRACE_REVISION, kGTraceCmdFetch, 0 }; 63 | uint32_t scalarParamsCount = COUNT_OF(scalarParams); 64 | size_t bufSize; 65 | 66 | // TODO(gvdl): Need to multithread the fetches the problem is that the 67 | // fetch code makes a subroutine call into the driver. 68 | // Single thread for the time being. 69 | 70 | // Default vector fo GTraceEntries allocates a MiB of entries 71 | const size_t kBufSizeBytes = 1024 * 1024; 72 | const vector::size_type 73 | kBufSize = kBufSizeBytes / sizeof(GTraceEntry); 74 | GTraceBuffer::vector_type buf(kBufSize); 75 | 76 | IOReturn err = kIOReturnSuccess; 77 | for (int i = 0; i < kGTraceMaximumBufferCount; i++) { 78 | scalarParams[2] = i; // GTrace buffer index 79 | bufSize = kBufSizeBytes; 80 | const IOReturn bufErr = diag.callMethod( 81 | 3, // kIOGDUCInterface_gtrace, 82 | scalarParams, scalarParamsCount, NULL, 0, // Inputs 83 | NULL, NULL, buf.data(), &bufSize); // Outputs 84 | if (!bufErr) { 85 | // Decode the gtrace buffer, massage to get access to header 86 | const auto* header = reinterpret_cast(buf.data()); 87 | bufSize = header->fBufferSize / sizeof(GTraceEntry); 88 | auto cbegin = buf.cbegin(); 89 | traceBuffersP->emplace_back(cbegin, cbegin + bufSize); 90 | } 91 | else if (bufErr != kIOReturnNotFound) { 92 | fprintf(stderr, "Error retrieving gtrace buffer %d - %s[%x]\n", 93 | i, mach_error_string(bufErr), bufErr); 94 | if (!err) 95 | err = bufErr; // Record first error 96 | } 97 | } 98 | return err; 99 | } 100 | 101 | // If errmsgP is set then the caller is required to free returned string 102 | kern_return_t iogDiagnose(const IOConnect& diag, 103 | IOGDiagnose* reportP, size_t reportLength, 104 | vector* traceBuffersP, 105 | char** errmsgP) 106 | { 107 | const char* errmsg; 108 | kern_return_t err = kIOReturnInternalError; 109 | 110 | do { 111 | errmsg = "NULL IOGDiagnose pointer argument passed"; 112 | err = kIOReturnBadArgument; 113 | if (!reportP) 114 | continue; 115 | errmsg = "report too small for an IOGDiagnose header"; 116 | err = kIOReturnBadArgument; 117 | if (sizeof(*reportP) > reportLength) 118 | continue; 119 | 120 | // Grab the main IOFB reports first 121 | errmsg = "Problem getting framebuffer diagnostic data"; 122 | uint64_t scalarParams[] = {reportLength}; 123 | const uint32_t scalarParamsCount = COUNT_OF(scalarParams); 124 | memset(reportP, 0, reportLength); 125 | err = diag.callMethod( 126 | 0, // kIOGDUCInterface_diagnose, 127 | scalarParams, scalarParamsCount, NULL, 0, // input 128 | NULL, NULL, reportP, &reportLength); // output 129 | if (!err) { 130 | errmsg = "A problem occured fetching gTrace buffers" 131 | ", see kernel logs"; 132 | err = fetchGTraceBuffers(diag, traceBuffersP); 133 | } 134 | } while(false); 135 | 136 | if (err && errmsgP) 137 | asprintf(errmsgP, "%s - %s(%x)", errmsg, mach_error_string(err), err); 138 | return err; 139 | } 140 | -------------------------------------------------------------------------------- /AllRez/IOGraphics530.66/iogdiagnose/iogdiagnose.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // iogdiagnose.cpp 3 | // iogdiagnose 4 | // 5 | // Created by bparke on 12/16/16. 6 | // 7 | // 8 | /* 9 | State bits documentation: 10 | 11 | OP: Opened (bool) 12 | ON: Online (bool) 13 | US: Usable (bool) 14 | PS: Paging (bool) 15 | CS: Clamshell (bool) 16 | CC: Clamshell Current (bool) 17 | CL: Clamshell Last (bool) 18 | DS: System Dark (bool) 19 | MR: Mirrored (bool) 20 | SG: System Gated (bool) 21 | WL: IOG Workloop Gated (bool) 22 | NA: FB Notifications Active (bool) 23 | SN: WindowServer (CoreDisplay) Notified (bool) 24 | SS: WindowServer (CoreDisplay) Notification State (bool) 25 | SA: WindowServer (CoreDisplay) Pending Acknowledgement (bool) 26 | PP: Pending Power Change (bool) 27 | SP: System Power AckTo (bool) 28 | MS: Mux Switching (bool) // version 6+ 29 | MP: Mux Power Change Pending (bool) // version 6+ 30 | MU: Muted (bool) // version 6+ 31 | MX: Pending Mux Change (bool) // version 5- 32 | PPS: Pending Power State (ordinal) 33 | NOTIFIED: Active FB Notification Group ID (ID) 34 | WSAA: Active WSAA State (enum/bitfield) 35 | 36 | A-State (External API-State) 37 | 38 | CreateSharedCursor 0x00 00 00 01 39 | GetPixelInformation 0x00 00 00 02 40 | GetCurrentDisplayMode 0x00 00 00 04 41 | SetStartupDisplayMode 0x00 00 00 08 42 | 43 | SetDisplayMode 0x00 00 00 10 44 | GetInformationForDisplayMode 0x00 00 00 20 45 | GetDisplayModeCount 0x00 00 00 40 46 | GetDisplayModes 0x00 00 00 80 47 | 48 | GetVRAMMapOffset 0x00 00 01 00 49 | SetBounds 0x00 00 02 00 50 | SetNewCursor 0x00 00 04 00 51 | SetGammaTable 0x00 00 08 00 52 | 53 | SetCursorVisible 0x00 00 10 00 54 | SetCursorPosition 0x00 00 20 00 55 | AcknowledgeNotification 0x00 00 40 00 56 | SetColorConvertTable 0x00 00 80 00 57 | 58 | SetCLUTWithEntries 0x00 01 00 00 59 | ValidateDetailedTiming 0x00 02 00 00 60 | GetAttribute 0x00 04 00 00 61 | SetAttribute 0x00 08 00 00 62 | 63 | WSStartAttribute 0x00 10 00 00 64 | EndConnectionChange 0x00 20 00 00 65 | ProcessConnectionChange 0x00 40 00 00 66 | RequestProbe 0x00 80 00 00 67 | 68 | Close 0x01 00 00 00 69 | SetProperties 0x02 00 00 00 70 | SetHibernateGamma 0x04 00 00 00 71 | 72 | */ 73 | 74 | #define IOGD530_66 75 | 76 | #include "MacOSMacros.h" 77 | 78 | // C++ headers 79 | #include 80 | #include 81 | //#include 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | 88 | #include 89 | #include 90 | #include 91 | #if MAC_OS_X_VERSION_SDK >= MAC_OS_X_VERSION_10_5 92 | extern char **environ; 93 | #include 94 | #endif 95 | #include 96 | 97 | #include "iokit.h" 98 | #include "IOGDiagnoseUtils.hpp" 99 | 100 | #include "GTraceTypes.hpp" 101 | 102 | #define kFILENAME_LENGTH 64 103 | 104 | using std::string; 105 | using std::vector; 106 | 107 | namespace { 108 | 109 | #if 0 110 | void print_usage(const char* name) 111 | { 112 | fprintf(stdout, "%s options:\n", name); 113 | 114 | fprintf(stdout, "\t--file | -f\n"); 115 | fprintf(stdout, "\t\tWrite diag to file /tmp/com.apple.iokit.IOGraphics_YYYY_MM__DD_HH-MM-SS.txt (instead of stdout)\n"); 116 | 117 | fprintf(stdout, "\n\t--binary | -b binary_file\n"); 118 | 119 | fprintf(stdout, "\n"); 120 | fflush(stdout); 121 | } 122 | #endif 123 | 124 | #if MAC_OS_X_VERSION_SDK < MAC_OS_X_VERSION_10_5 125 | 126 | #ifdef __cplusplus 127 | extern "C" { 128 | #endif 129 | int posix_spawn(pid_t *pid, const char *path, const void *file_actions, const void *attrp, char *const argv[], char *const envp[]) __attribute__((weak_import)); 130 | #ifdef __cplusplus 131 | } 132 | #endif 133 | 134 | #endif 135 | 136 | void foutsep(FILE* outfile, const string title) 137 | { 138 | static const char kSep[] = "---------------------------------------------------------------------------------------"; 139 | static const int kSepLen = static_cast(sizeof(kSep) - 1); 140 | if (title.empty()) { 141 | fprintf(outfile, "\n%s\n", kSep); 142 | return; 143 | } 144 | // Add room for spaces 145 | const int titlelen = static_cast(title.length()) + 2; 146 | assert(titlelen < kSepLen); 147 | const int remainsep = kSepLen - titlelen; 148 | const int prefixsep = remainsep / 2; 149 | const int sufficsep = prefixsep + (remainsep & 1); 150 | 151 | fprintf(outfile, "%.*s %s %.*s\n\n", 152 | prefixsep, kSep, title.c_str(), sufficsep, kSep); 153 | } 154 | inline void foutsep(FILE* outfile) { foutsep(outfile, string()); } 155 | 156 | string stringf(const char *fmt, ...) 157 | { 158 | va_list args; 159 | char buffer[1024]; // pretty big, but userland stacks are big 160 | 161 | va_start(args, fmt); 162 | const auto len = vsnprintf(buffer, sizeof(buffer), fmt, args); 163 | va_end(args); 164 | assert(len < sizeof(buffer)); (void) len; 165 | return buffer; 166 | } 167 | 168 | string formatEntry(const int currentLine, const GTraceEntry& entry) 169 | { 170 | return stringf( 171 | "\t\tTkn: %06u\tTS: %llu\tLn: %u\tC: %#llx\tCTID: %u-%#llx\t" 172 | "OID: %#llx\tTag: %#llx\tA: %#llx-%#llx-%#llx-%#llx\n", 173 | currentLine, entry.timestamp(), entry.line(), entry.component(), 174 | entry.cpu(), (uint64_t)entry.threadID(), (uint64_t)entry.registryID(), 175 | entry.tag(), entry.arg64(0), entry.arg64(1), 176 | entry.arg64(2), entry.arg64(3)); 177 | } 178 | 179 | #if MAC_OS_X_VERSION_SDK < MAC_OS_X_VERSION_10_5 180 | 181 | #ifdef __cplusplus 182 | extern "C" { 183 | #endif 184 | int posix_spawn(pid_t *pid, const char *path, const void *file_actions, const void *attrp, char *const argv[], char *const envp[]) __attribute__((weak_import)); 185 | #ifdef __cplusplus 186 | } 187 | #endif 188 | 189 | #endif 190 | 191 | void agdcdiagnose(FILE * outfile) 192 | { 193 | #define AGCKEXT "/System/Library/Extensions/AppleGraphicsControl.kext/" 194 | #define BNDLBINDIR "Contents/MacOS/" 195 | #define AGDCDIAGEXEC "AGDCDiagnose" 196 | static const char* kDiagArgs[] 197 | = { AGCKEXT BNDLBINDIR AGDCDIAGEXEC, "-a", nullptr }; 198 | 199 | if (static_cast(outfile)) { 200 | #if MAC_OS_X_VERSION_SDK >= MAC_OS_X_VERSION_10_5 201 | if (&posix_spawn) { 202 | pid_t pid = 0; 203 | foutsep(outfile, "AGDC REPORT"); fflush(outfile); 204 | 205 | auto agdcArgs = const_cast(kDiagArgs); 206 | int status = posix_spawn(&pid, kDiagArgs[0], nullptr, nullptr, 207 | agdcArgs, environ); 208 | if (0 == status) 209 | (void) waitpid(pid, &status, 0); 210 | else 211 | fprintf(outfile, "\tAGDCDiagnose failed to launch\n"); 212 | foutsep(outfile); 213 | } 214 | #endif 215 | } 216 | } 217 | 218 | void dumpTokenBuffer(FILE* outfile, const vector& gtraces) 219 | { 220 | unsigned currentLine = 0; 221 | long total_lines = 1; // Include magic 222 | for (const GTraceBuffer& buffer : gtraces) 223 | total_lines += buffer.vec().size(); 224 | if (!total_lines) { 225 | fprintf(outfile, "-1 (No Token Data Recorded)\n\n"); 226 | return; 227 | } 228 | 229 | // Marks beginning of a multi 230 | const GTraceEntry magic(gtraces.size(), GTRACE_REVISION); 231 | string line = formatEntry(currentLine++, magic); 232 | 233 | fputs("\n\n", outfile); 234 | fprintf(outfile, "Token Buffers Recorded: %d\n", 235 | static_cast(gtraces.size())); 236 | fprintf(outfile, "Token Buffer Lines : %ld\n", total_lines); 237 | fprintf(outfile, "Token Buffer Size : %ld\n", 238 | total_lines * kGTraceEntrySize); 239 | fprintf(outfile, "Token Buffer Data :\n"); 240 | fputs(line.c_str(), outfile); // out magic marks as v2 or later 241 | 242 | for (const GTraceBuffer& buffer : gtraces) { 243 | for (const GTraceEntry& entry : buffer.vec()) { 244 | line = formatEntry(currentLine++, entry); 245 | fputs(line.c_str(), outfile); 246 | } 247 | } 248 | fputc('\n', outfile); 249 | } 250 | 251 | void writeGTraceBinary(const vector& gtraces, 252 | const char* filename) 253 | { 254 | if (gtraces.empty()) { 255 | fprintf(stdout, "iogdiagnose: No GTrace data\n"); 256 | return; 257 | } 258 | 259 | FILE* fp = fopen(filename, "w"); 260 | if (!static_cast(fp)) { 261 | fprintf(stdout, 262 | "iogdiagnose: Failed to open %s for write access\n", filename); 263 | return; 264 | } 265 | 266 | // Marks beginning of a multi 267 | const GTraceEntry magic(gtraces.size(), GTRACE_REVISION); 268 | 269 | fwrite(&magic, sizeof(magic), 1, fp); // Indicates v2 gtrace binary 270 | for (const GTraceBuffer& buf : gtraces) 271 | // TODO(gvdl): how about some error checking? 272 | fwrite(buf.data(), sizeof(*buf.data()), buf.size(), fp); 273 | fclose(fp); 274 | } 275 | 276 | // Simple helpers for report dumper 277 | inline int bitIsSet(const uint32_t value, const uint32_t bit) 278 | { return static_cast(value & bit); } 279 | inline int isStateSet(const IOGReport& fbState, uint32_t bit) 280 | { return bitIsSet(fbState.stateBits, bit); } 281 | inline mach_timebase_info_data_t getMachTimebaseInfo() 282 | { 283 | mach_timebase_info_data_t ret = { 0 }; 284 | mach_timebase_info(&ret); 285 | return ret; 286 | } 287 | inline tm getTime() 288 | { 289 | tm ret; 290 | time_t rawtime = 0; time(&rawtime); 291 | localtime_r(&rawtime, &ret); 292 | return ret; 293 | } 294 | 295 | void dumpGTraceReport(const IOGDiagnose& diag, 296 | const vector& gtraces, 297 | const bool bDumpToFile) 298 | { 299 | if (diag.version < 7) { 300 | fprintf(stderr, "iogdiagnose: Can't read pre v7 IOGDiagnose reports\n"); 301 | return; 302 | } 303 | 304 | const mach_timebase_info_data_t info = getMachTimebaseInfo(); 305 | const tm timeinfo = getTime(); 306 | char filename[kFILENAME_LENGTH] = {0}; 307 | strftime(filename, sizeof(filename), 308 | "/tmp/com.apple.iokit.IOGraphics_%F_%H-%M-%S.txt", &timeinfo); 309 | 310 | FILE* const fp = (bDumpToFile) ? fopen(filename, "w+") : nullptr; 311 | FILE* const outfile = (static_cast(fp)) ? fp : stdout; 312 | foutsep(outfile, "IOGRAPHICS REPORT"); 313 | strftime(filename, sizeof(filename), "Report date: %F %H:%M:%S", &timeinfo); 314 | fprintf(outfile, "%s\n", filename); 315 | 316 | const auto fbCount = std::min( 317 | diag.framebufferCount, IOGRAPHICS_MAXIMUM_FBS); 318 | 319 | fprintf(outfile, "Report version: %#llx\n", diag.version); 320 | fprintf(outfile, "Boot Epoch Time: %llu\n", diag.systemBootEpochTime); 321 | fprintf(outfile, "Number of framebuffers: %llu%s\n\n", 322 | diag.framebufferCount, 323 | ((fbCount != diag.framebufferCount) 324 | ? " (warning: some fbs not reported)" : "")); 325 | 326 | for (uint32_t i = 0; i < fbCount; i++) { 327 | const IOGReport& fbState = diag.fbState[i]; 328 | 329 | fprintf(outfile, "\t%s::", 330 | (*fbState.objectName) ? fbState.objectName : "UNKNOWN::"); 331 | fputs((*fbState.framebufferName) ? fbState.framebufferName : "IOFB?", 332 | outfile); 333 | fprintf(outfile, 334 | " (%u %#llx)\n", fbState.dependentIndex, fbState.regID); 335 | if (fbState.aliasID) 336 | fprintf(outfile, "\t\tAlias : 0x%08x\n", fbState.aliasID); 337 | 338 | fprintf(outfile, "\t\tI-State : 0x%08x (b", fbState.stateBits); 339 | for (uint32_t mask = 0x80000000; 0 != mask; mask >>= 1) 340 | fprintf(outfile, "%d", isStateSet(fbState, mask)); 341 | fprintf(outfile, ")\n"); 342 | 343 | fprintf(outfile, "\t\tStates : OP:ON:US:PS:CS:CC:CL:CO:DS:MR:SG:WL:NA:SN:SS:SA:PP:SP:MS:MP:MU:PPS: NOTIFIED : WSAA \n"); 344 | fprintf(outfile, "\t\tState Bits: %02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:%02d:0x%01x:0x%08x:0x%08x\n", 345 | isStateSet(fbState, kIOGReportState_Opened), 346 | isStateSet(fbState, kIOGReportState_Online), 347 | isStateSet(fbState, kIOGReportState_Usable), 348 | isStateSet(fbState, kIOGReportState_Paging), 349 | isStateSet(fbState, kIOGReportState_Clamshell), 350 | isStateSet(fbState, kIOGReportState_ClamshellCurrent), 351 | isStateSet(fbState, kIOGReportState_ClamshellLast), 352 | isStateSet(fbState, kIOGReportState_ClamshellOffline), 353 | isStateSet(fbState, kIOGReportState_SystemDark), 354 | isStateSet(fbState, kIOGReportState_Mirrored), 355 | isStateSet(fbState, kIOGReportState_SystemGated), 356 | isStateSet(fbState, kIOGReportState_WorkloopGated), 357 | isStateSet(fbState, kIOGReportState_NotificationActive), 358 | isStateSet(fbState, kIOGReportState_ServerNotified), 359 | isStateSet(fbState, kIOGReportState_ServerState), 360 | isStateSet(fbState, kIOGReportState_ServerPendingAck), 361 | isStateSet(fbState, kIOGReportState_PowerPendingChange), 362 | isStateSet(fbState, kIOGReportState_SystemPowerAckTo), 363 | isStateSet(fbState, kIOGReportState_IsMuxSwitching), 364 | isStateSet(fbState, kIOGReportState_PowerPendingMuxChange), 365 | isStateSet(fbState, kIOGReportState_Muted), 366 | fbState.pendingPowerState, 367 | fbState.notificationGroup, 368 | fbState.wsaaState); 369 | 370 | if ((diag.version >= 9) && (kIOReturnSuccess != fbState.lastWSAAStatus)) { 371 | fprintf(outfile, 372 | "\t\t**** WARNING: setAttribute(WSAA) failed: %#x\n", 373 | fbState.lastWSAAStatus); 374 | } 375 | 376 | fprintf(outfile, "\t\tA-State : 0x%08x (b", fbState.externalAPIState); 377 | for (uint32_t mask = 0x80000000; 0 != mask; mask >>= 1) 378 | fprintf(outfile, "%d", bitIsSet(fbState.externalAPIState, mask)); 379 | fprintf(outfile, ")\n"); 380 | 381 | fprintf(outfile, "\t\tMode ID : %#x\n", fbState.lastSuccessfulMode); 382 | fprintf(outfile, "\t\tSystem : %llu (%#llx) (%u)\n", 383 | fbState.systemOwner, fbState.systemOwner, 384 | fbState.systemGatedCount); 385 | fprintf(outfile, "\t\tController: %llu (%#llx) (%u)\n", 386 | fbState.workloopOwner, fbState.workloopOwner, 387 | fbState.workloopGatedCount); 388 | 389 | 390 | for (int gi = 0; gi < IOGRAPHICS_MAXIMUM_REPORTS; ++gi) { 391 | const auto& group = fbState.notifications[gi]; 392 | if (!group.groupID) 393 | continue; 394 | 395 | fprintf(outfile, "\n\t\tGroup ID: %#llx\n", group.groupID - 1); 396 | for (int si = 0; si < IOGRAPHICS_MAXIMUM_REPORTS; ++si) { 397 | const auto& stamp = group.stamp[si]; 398 | if (stamp.lastEvent || stamp.start || stamp.end || *stamp.name) 399 | { 400 | fprintf(outfile, "\t\t\tComponent : %s\n", stamp.name); 401 | fprintf(outfile, "\t\t\tLast Event : %u (%#x)\n", 402 | stamp.lastEvent, stamp.lastEvent); 403 | fprintf(outfile, "\t\t\tStamp Start : %#llx\n", stamp.start); 404 | fprintf(outfile, "\t\t\tStamp End : %#llx\n", stamp.end); 405 | fprintf(outfile, "\t\t\tStamp Delta : "); 406 | if (stamp.start <= stamp.end) { 407 | fprintf(outfile, "%llu ns\n", 408 | ((stamp.end - stamp.start) 409 | * static_cast(info.numer)) 410 | / static_cast(info.denom)); 411 | } else 412 | fprintf(outfile, "Notifier Active\n"); 413 | } 414 | } 415 | } 416 | } 417 | 418 | // Tokenized logging data 419 | dumpTokenBuffer(outfile, gtraces); 420 | fflush(outfile); 421 | 422 | foutsep(outfile); 423 | agdcdiagnose(outfile); 424 | fflush(outfile); 425 | 426 | if (static_cast(fp)) 427 | fclose(fp); 428 | } 429 | }; // namespace 430 | 431 | #ifdef __cplusplus 432 | extern "C" { 433 | #endif 434 | int iogdiagnose9(int dumpToFile, char *optarg); 435 | #ifdef __cplusplus 436 | } 437 | #endif 438 | 439 | int iogdiagnose9(int dumpToFile, char *optarg) 440 | { 441 | bool bDumpToFile = false; 442 | bool bBinaryToFile = false; 443 | char inputFilename[256] = { 0 }; 444 | 445 | bDumpToFile = dumpToFile; 446 | if (optarg != nullptr) { 447 | const size_t len = strlen(optarg); 448 | if (len <= sizeof(inputFilename)) { 449 | strncpy(inputFilename, optarg, len); 450 | bBinaryToFile = true; 451 | } 452 | } 453 | 454 | int exitValue = EXIT_SUCCESS; 455 | char *error = nullptr; 456 | IOConnect dc; // Diagnostic connection 457 | kern_return_t err = openDiagnostics(&dc, &error); 458 | if (err) { 459 | fprintf(stderr, "%s %s (%#x)\n", error, mach_error_string(err), err); 460 | exit(EXIT_FAILURE); 461 | } 462 | 463 | vector gtraces; 464 | if (bBinaryToFile) { 465 | err = fetchGTraceBuffers(dc, >races); 466 | if (err) 467 | exitValue = EXIT_FAILURE; // error reported by library 468 | else 469 | writeGTraceBinary(gtraces, inputFilename); 470 | exit(exitValue); 471 | } 472 | 473 | IOGDiagnose report = { 0 }; 474 | err = iogDiagnose(dc, &report, sizeof(report), >races, &error); 475 | if (err) { 476 | fprintf(stderr, "%s %s (%#x)\n", error, mach_error_string(err), err); 477 | exitValue = EXIT_FAILURE; 478 | } 479 | else 480 | dumpGTraceReport(report, gtraces, bDumpToFile); 481 | 482 | return exitValue; 483 | } 484 | 485 | -------------------------------------------------------------------------------- /AllRez/IOGraphics576.1/iogdiagnose/iogdiagnose.cpp: -------------------------------------------------------------------------------- 1 | #define IOGD576_1 2 | 3 | #define iogdiagnose iogdiagnose_10_15_7 4 | #include "../../IOGraphics/iogdiagnose/iogdiagnose.cpp" 5 | -------------------------------------------------------------------------------- /AllRez/Kernel.framework/sys/kdebug_kernel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2018 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef BSD_SYS_KDEBUG_KERNEL_H 30 | #define BSD_SYS_KDEBUG_KERNEL_H 31 | 32 | #include "MacOSMacros.h" 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | __BEGIN_DECLS 40 | 41 | 42 | /* 43 | * To use kdebug in the kernel: 44 | * 45 | * #include 46 | * 47 | * #define DBG_NETIPINIT NETDBG_CODE(DBG_NETIP, 1) 48 | * 49 | * void 50 | * ip_init(void) 51 | * { 52 | * KDBG(DBG_NETIPINIT | DBG_FUNC_START, 1, 2, 3, 4); 53 | * ... 54 | * KDBG(DBG_NETIPINIT); 55 | * ... 56 | * KDBG(DBG_NETIPINIT | DBG_FUNC_END); 57 | * } 58 | */ 59 | 60 | #pragma mark - kernel tracepoints 61 | 62 | /* 63 | * The KDBG{,_DEBUG,_RELEASE,_FILTERED} macros are the preferred method of 64 | * making tracepoints. 65 | * 66 | * Kernel pointers must be unslid or permuted using VM_KERNEL_UNSLIDE_OR_PERM. 67 | * Do not trace any sensitive data. 68 | */ 69 | 70 | /* 71 | * Traced on debug and development (and release macOS) kernels. 72 | */ 73 | #define KDBG(x, ...) KDBG_(, x, ## __VA_ARGS__, 4, 3, 2, 1, 0) 74 | 75 | /* 76 | * Traced on debug and development (and release macOS) kernels if explicitly 77 | * requested. Omitted from tracing without a typefilter. 78 | */ 79 | #define KDBG_FILTERED(x, ...) KDBG_(_FILTERED, x, ## __VA_ARGS__, 4, 3, 2, 1, 0) 80 | 81 | 82 | /* 83 | * Traced on debug, development, and release kernels. 84 | * 85 | * Only use this tracepoint if the events are required for a shipping trace 86 | * tool. 87 | */ 88 | #define KDBG_RELEASE(x, ...) KDBG_(_RELEASE, x, ## __VA_ARGS__, 4, 3, 2, 1, 0) 89 | 90 | /* 91 | * Traced only on debug kernels. 92 | */ 93 | #define KDBG_DEBUG(x, ...) KDBG_(_DEBUG, x, ## __VA_ARGS__, 4, 3, 2, 1, 0) 94 | 95 | #pragma mark - kernel API 96 | 97 | 98 | /* 99 | * Returns true if kdebug is using continuous time for its events, and false 100 | * otherwise. 101 | */ 102 | bool kdebug_using_continuous_time(void); 103 | 104 | /* 105 | * Convert an absolute time to a kdebug timestamp. 106 | */ 107 | extern uint64_t kdebug_timestamp_from_absolute(uint64_t abstime); 108 | 109 | /* 110 | * Convert a continuous time to a kdebug timestamp. 111 | */ 112 | extern uint64_t kdebug_timestamp_from_continuous(uint64_t conttime); 113 | 114 | /* 115 | * Capture a kdebug timestamp for the current time. 116 | */ 117 | extern uint64_t kdebug_timestamp(void); 118 | 119 | /* 120 | * Returns true if kdebug will log an event with the provided debugid, and 121 | * false otherwise. 122 | */ 123 | bool kdebug_debugid_enabled(uint32_t debugid); 124 | 125 | /* 126 | * Returns true only if the debugid is explicitly enabled by filters. Returns 127 | * false otherwise, including when no filters are active. 128 | */ 129 | bool kdebug_debugid_explicitly_enabled(uint32_t debugid); 130 | 131 | uint32_t kdebug_commpage_state(void); 132 | 133 | #pragma mark - Coprocessor/IOP tracing 134 | 135 | #if MAC_OS_X_VERSION_SDK >= MAC_OS_X_VERSION_10_10 136 | 137 | typedef enum { 138 | /* Trace is now enabled. */ 139 | KD_CALLBACK_KDEBUG_ENABLED, 140 | /* 141 | * Trace is being disabled, but events are still accepted for the duration 142 | * of the callback. 143 | */ 144 | KD_CALLBACK_KDEBUG_DISABLED, 145 | /* 146 | * Request the latest events from the IOP and block until complete. Any 147 | * events that occur prior to this callback being called may be dropped by 148 | * the trace system. 149 | */ 150 | KD_CALLBACK_SYNC_FLUSH, 151 | /* 152 | * The typefilter is being used. 153 | * 154 | * A read-only pointer to the typefilter is provided as the argument, valid 155 | * only in the callback. 156 | */ 157 | KD_CALLBACK_TYPEFILTER_CHANGED, 158 | /* 159 | * The coprocessor should emit data that snapshots the current state of the 160 | * system. 161 | */ 162 | KD_CALLBACK_SNAPSHOT_STATE, 163 | } kd_callback_type; 164 | 165 | #endif 166 | 167 | __options_decl(kdebug_coproc_flags_t, uint32_t, { 168 | /* 169 | * Event timestamps from this coprocessor are in the continuous timebase. 170 | */ 171 | KDCP_CONTINUOUS_TIME = 0x001, 172 | }); 173 | 174 | typedef void (*kd_callback_fn)(void *context, kd_callback_type reason, 175 | void *arg); 176 | 177 | /* 178 | * Register a coprocessor for participation in tracing. 179 | * 180 | * The `callback` function will be called with the provided `context` when 181 | * necessary, according to the `kd_callback_type`s. 182 | * 183 | * The positive core ID is returned on success, or -1 on failure. 184 | */ 185 | int kdebug_register_coproc(const char *name, kdebug_coproc_flags_t flags, 186 | kd_callback_fn callback, void *context); 187 | 188 | void kernel_debug_enter(uint32_t coreid, uint32_t debugid, uint64_t timestamp, 189 | uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4, 190 | uintptr_t threadid); 191 | 192 | /* 193 | * Legacy definitions for the prior IOP tracing. 194 | */ 195 | 196 | #if MAC_OS_X_VERSION_SDK >= MAC_OS_X_VERSION_10_10 197 | struct kd_callback { 198 | kd_callback_fn func; 199 | void *context; 200 | /* name of IOP, NUL-terminated */ 201 | char iop_name[8]; 202 | }; 203 | typedef struct kd_callback kd_callback_t; 204 | #endif 205 | 206 | __kpi_deprecated("use kdebug_register_coproc instead") 207 | int kernel_debug_register_callback(kd_callback_t callback); 208 | 209 | #pragma mark - internals 210 | 211 | #define KDBG_(f, x, a, b, c, d, n, ...) KDBG##n(f, x, a, b, c, d) 212 | #define KDBG0(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, 0, 0, 0, 0, 0) 213 | #define KDBG1(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, 0, 0, 0, 0) 214 | #define KDBG2(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, 0, 0, 0) 215 | #define KDBG3(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, c, 0, 0) 216 | #define KDBG4(f, x, a, b, c, d) KERNEL_DEBUG_CONSTANT##f(x, a, b, c, d, 0) 217 | 218 | #define KDBG_IMPROBABLE 219 | 220 | extern unsigned int kdebug_enable; 221 | 222 | /* 223 | * The kernel debug configuration level. These values control which events are 224 | * compiled in under different build configurations. 225 | * 226 | * Infer the supported kernel debug event level from config option. Use 227 | * (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect unaudited debug 228 | * code. 229 | */ 230 | #define KDEBUG_LEVEL_NONE 0 231 | #define KDEBUG_LEVEL_IST 1 232 | #define KDEBUG_LEVEL_STANDARD 2 233 | #define KDEBUG_LEVEL_FULL 3 234 | 235 | #if NO_KDEBUG 236 | #define KDEBUG_LEVEL KDEBUG_LEVEL_NONE 237 | #elif IST_KDEBUG 238 | #define KDEBUG_LEVEL KDEBUG_LEVEL_IST 239 | #elif KDEBUG 240 | #define KDEBUG_LEVEL KDEBUG_LEVEL_FULL 241 | #else 242 | #define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD 243 | /* 244 | * Currently, all other kernel configurations (development, etc) build with 245 | * KDEBUG_LEVEL_STANDARD. 246 | */ 247 | #endif 248 | 249 | /* 250 | * KERNEL_DEBUG_CONSTANT_FILTERED events are omitted from tracing unless they 251 | * are explicitly requested in the typefilter. They are not emitted when 252 | * tracing without a typefilter. 253 | */ 254 | #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) 255 | #define KERNEL_DEBUG_CONSTANT_FILTERED(x, a, b, c, d, ...) \ 256 | do { \ 257 | if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \ 258 | kernel_debug_filtered((x), (uintptr_t)(a), (uintptr_t)(b), \ 259 | (uintptr_t)(c), (uintptr_t)(d)); \ 260 | } \ 261 | } while (0) 262 | #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */ 263 | #define KERNEL_DEBUG_CONSTANT_FILTERED(type, x, a, b, c, d, ...) do {} while (0) 264 | #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */ 265 | 266 | #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) 267 | #define KERNEL_DEBUG_CONSTANT_RELEASE_NOPROCFILT(x, a, b, c, d, ...) \ 268 | do { \ 269 | if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \ 270 | kernel_debug_flags((x), (uintptr_t)(a), (uintptr_t)(b), \ 271 | (uintptr_t)(c), (uintptr_t)(d), KDBG_FLAG_NOPROCFILT); \ 272 | } \ 273 | } while (0) 274 | #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */ 275 | #define KERNEL_DEBUG_CONSTANT_RELEASE_NOPROCFILT(x, a, b, c, d, ...) \ 276 | do { } while (0) 277 | #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */ 278 | 279 | 280 | #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) 281 | #define KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e) \ 282 | do { \ 283 | if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \ 284 | kernel_debug((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \ 285 | (uintptr_t)(d),(uintptr_t)(e)); \ 286 | } \ 287 | } while (0) 288 | 289 | /* 290 | * DO NOT USE THIS MACRO -- it breaks fundamental assumptions about ktrace and 291 | * is only meant to be used by the pthread kext and other points in the kernel 292 | * where the thread ID must be provided explicitly. 293 | */ 294 | #define KERNEL_DEBUG_CONSTANT1(x, a, b, c, d, e) \ 295 | do { \ 296 | if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \ 297 | kernel_debug1((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \ 298 | (uintptr_t)(d), (uintptr_t)(e)); \ 299 | } \ 300 | } while (0) 301 | 302 | #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */ 303 | #define KERNEL_DEBUG_CONSTANT(x, a, b, c, d, e) do {} while (0) 304 | #define KERNEL_DEBUG_CONSTANT1(x, a, b, c, d, e) do {} while (0) 305 | #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */ 306 | 307 | /* 308 | * KERNEL_DEBUG_CONSTANT_IST (in-system trace) events provide an audited subset 309 | * of tracepoints for userland system tracing tools. This tracing level was 310 | * created by 8857227 to protect fairplayd and other PT_DENY_ATTACH processes. 311 | * It has two effects: only KERNEL_DEBUG_CONSTANT_IST() traces are emitted and 312 | * any PT_DENY_ATTACH processes will only emit basic traces as defined by the 313 | * kernel_debug_filter() routine. 314 | */ 315 | #define KERNEL_DEBUG_CONSTANT_RELEASE(x, a, b, c, d, e) \ 316 | KERNEL_DEBUG_CONSTANT_IST(~KDEBUG_ENABLE_PPT, x, a, b, c, d, 0) 317 | 318 | #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) 319 | #define KERNEL_DEBUG_CONSTANT_IST(type, x, a, b, c, d, e) \ 320 | do { \ 321 | if (KDBG_IMPROBABLE(kdebug_enable & (type))) { \ 322 | kernel_debug((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \ 323 | (uintptr_t)(d), 0); \ 324 | } \ 325 | } while (0) 326 | 327 | #define KERNEL_DEBUG_CONSTANT_IST1(x, a, b, c, d, e) \ 328 | do { \ 329 | if (KDBG_IMPROBABLE(kdebug_enable)) { \ 330 | kernel_debug1((x), (uintptr_t)(a), (uintptr_t)(b), (uintptr_t)(c), \ 331 | (uintptr_t)(d), (uintptr_t)(e)); \ 332 | } \ 333 | } while (0) 334 | 335 | #define KERNEL_DEBUG_EARLY(x, a, b, c, d) \ 336 | do { \ 337 | kernel_debug_early((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \ 338 | (uintptr_t)(c), (uintptr_t)(d)); \ 339 | } while (0) 340 | 341 | #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */ 342 | #define KERNEL_DEBUG_CONSTANT_IST(type, x, a, b, c, d, e) do {} while (0) 343 | #define KERNEL_DEBUG_CONSTANT_IST1(x, a, b, c, d, e) do {} while (0) 344 | #define KERNEL_DEBUG_EARLY(x, a, b, c, d) do {} while (0) 345 | #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */ 346 | 347 | #if NO_KDEBUG 348 | #define __kdebug_constant_only __unused 349 | #endif 350 | 351 | /* 352 | * KERNEL_DEBUG events are only traced for DEBUG kernels. 353 | */ 354 | #define KERNEL_DEBUG_CONSTANT_DEBUG(x, a, b, c, d, e) \ 355 | KERNEL_DEBUG(x, a, b, c, d, e) 356 | 357 | #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) 358 | #define __kdebug_only 359 | 360 | #undef KERNEL_DEBUG 361 | #define KERNEL_DEBUG(x, a, b, c, d, e) \ 362 | do { \ 363 | if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \ 364 | kernel_debug((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \ 365 | (uintptr_t)(c), (uintptr_t)(d), (uintptr_t)(e)); \ 366 | } \ 367 | } while (0) 368 | 369 | /* 370 | * DO NOT USE THIS MACRO -- see warning above for KERNEL_DEBUG_CONSTANT1. 371 | */ 372 | #define KERNEL_DEBUG1(x, a, b, c, d, e) \ 373 | do { \ 374 | if (KDBG_IMPROBABLE(kdebug_enable & ~KDEBUG_ENABLE_PPT)) { \ 375 | kernel_debug1((uint32_t)(x), (uintptr_t)(a), (uintptr_t)(b), \ 376 | (uintptr_t)(c), (uintptr_t)(d), (uintptr_t)(e)); \ 377 | } \ 378 | } while (0) 379 | 380 | #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */ 381 | #define __kdebug_only __unused 382 | 383 | #undef KERNEL_DEBUG 384 | #define KERNEL_DEBUG(x, a, b, c, d, e) do {} while (0) 385 | #define KERNEL_DEBUG1(x, a, b, c, d, e) do {} while (0) 386 | #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_FULL) */ 387 | 388 | void kernel_debug(uint32_t debugid, uintptr_t arg1, uintptr_t arg2, 389 | uintptr_t arg3, uintptr_t arg4, uintptr_t arg5); 390 | 391 | void kernel_debug1(uint32_t debugid, uintptr_t arg1, uintptr_t arg2, 392 | uintptr_t arg3, uintptr_t arg4, uintptr_t arg5); 393 | 394 | #define KDBG_FLAG_FILTERED 0x01 395 | #define KDBG_FLAG_NOPROCFILT 0x02 396 | 397 | void kernel_debug_flags(uint32_t debugid, uintptr_t arg1, uintptr_t arg2, 398 | uintptr_t arg3, uintptr_t arg4, uint64_t flags); 399 | 400 | void kernel_debug_filtered(uint32_t debugid, uintptr_t arg1, uintptr_t arg2, 401 | uintptr_t arg3, uintptr_t arg4); 402 | 403 | #pragma mark - xnu API 404 | 405 | 406 | 407 | 408 | __END_DECLS 409 | 410 | #endif /* !defined(BSD_SYS_KDEBUG_KERNEL_H) */ 411 | -------------------------------------------------------------------------------- /AllRez/Kernel.framework/sys/kdebug_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2018 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef BSD_KDEBUG_PRIVATE_H 30 | #define BSD_KDEBUG_PRIVATE_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | __BEGIN_DECLS 38 | 39 | 40 | #pragma mark - private debugids 41 | 42 | #define DBG_PPT 36 43 | #define DBG_PERFCTRL 39 44 | #define DBG_CLPC 50 45 | #define DBG_MUSE 52 46 | 47 | /* **** 128 to 139 are reserved for IOP tracing **** */ 48 | #define DBG_ANS 128 49 | #define DBG_SIO 129 50 | #define DBG_SEP 130 51 | #define DBG_ISP 131 52 | #define DBG_OSCAR 132 53 | #define DBG_EMBEDDEDGFX 133 54 | #define DBG_PMP 134 55 | #define DBG_RTKIT 135 56 | 57 | #define MACH_BRIDGE_RCV_TS 0x1 /* receive timestamp pair from interrupt handler */ 58 | #define MACH_BRIDGE_REMOTE_TIME 0x2 /* calculate remote timestamp */ 59 | #define MACH_BRIDGE_RESET_TS 0x3 /* reset timestamp conversion parameters */ 60 | #define MACH_BRIDGE_TS_PARAMS 0x4 /* recompute timestamp conversion parameters */ 61 | #define MACH_BRIDGE_SKIP_TS 0x5 /* skip timestamp */ 62 | #define MACH_BRIDGE_TS_MISMATCH 0x6 /* mismatch between predicted and received remote timestamp */ 63 | #define MACH_BRIDGE_OBSV_RATE 0x7 /* out of range observed rates */ 64 | 65 | /* DBG_SKYWALK has same toplevel code as DBG_DLIL, so don't reuse subcodes */ 66 | #define DBG_SKYWALK_ALWAYSON 0x10 67 | #define DBG_SKYWALK_FLOWSWITCH 0x11 68 | #define DBG_SKYWALK_NETIF 0x12 69 | #define DBG_SKYWALK_CHANNEL 0x13 70 | #define DBG_SKYWALK_PACKET 0x14 71 | 72 | #define PPT_TEST 0x01 73 | #define PPT_JETSAM_HIWAT 0x02 74 | #define PPT_JETSAM_TOPPROC 0x03 75 | 76 | #define SKYWALKDBG_CODE(SubClass, code) KDBG_CODE(DBG_DLIL, SubClass, code) 77 | #define PPTDBG_CODE(SubClass, code) KDBG_CODE(DBG_PPT, SubClass, code) 78 | #define PERFCTRL_CODE(SubClass, code) KDBG_CODE(DBG_PERFCTRL, SubClass, code) 79 | 80 | 81 | extern unsigned int kdebug_enable; 82 | 83 | /* 84 | * Bits used by kdebug_enable. These used to control which events are traced at 85 | * runtime. 86 | */ 87 | #define KDEBUG_ENABLE_TRACE 0x001U 88 | /* 89 | * If set, the timestamps in events are expected to be continuous times. 90 | * Otherwise, the timestamps are absolute times. IOPs should observe this bit 91 | * in order to log events that can be merged cleanly with other event streams. 92 | */ 93 | #define KDEBUG_ENABLE_CONT_TIME 0x020U 94 | 95 | #define KDEBUG_TRACE (KDEBUG_ENABLE_TRACE) 96 | 97 | /* obsolete kdebug_enable bits */ 98 | #define KDEBUG_ENABLE_ENTROPY 0x002U 99 | #define KDEBUG_ENABLE_CHUD 0x004U 100 | #define KDEBUG_ENABLE_PPT 0x008U 101 | #define KDEBUG_ENABLE_SERIAL 0x010U 102 | #define KDEBUG_PPT (KDEBUG_ENABLE_PPT) 103 | #define KDEBUG_COMMON (KDEBUG_ENABLE_TRACE | KDEBUG_ENABLE_PPT) 104 | 105 | /* 106 | * The kernel debug configuration level. These values control which events are 107 | * compiled in under different build configurations. 108 | * 109 | * Infer the supported kernel debug event level from config option. Use 110 | * (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) as a guard to protect unaudited debug 111 | * code. 112 | */ 113 | #define KDEBUG_LEVEL_NONE 0 114 | #define KDEBUG_LEVEL_IST 1 115 | #define KDEBUG_LEVEL_STANDARD 2 116 | #define KDEBUG_LEVEL_FULL 3 117 | 118 | #if NO_KDEBUG 119 | #define KDEBUG_LEVEL KDEBUG_LEVEL_NONE 120 | #elif IST_KDEBUG 121 | #define KDEBUG_LEVEL KDEBUG_LEVEL_IST 122 | #elif KDEBUG 123 | #define KDEBUG_LEVEL KDEBUG_LEVEL_FULL 124 | #else 125 | #define KDEBUG_LEVEL KDEBUG_LEVEL_STANDARD 126 | /* 127 | * Currently, all other kernel configurations (development, etc) build with 128 | * KDEBUG_LEVEL_STANDARD. 129 | */ 130 | #endif 131 | 132 | /* 133 | * Some Apple internal clients try to use the kernel macros in user space. 134 | */ 135 | #ifndef KERNEL_DEBUG 136 | #define KERNEL_DEBUG(...) do { } while (0) 137 | #endif /* !defined(KERNEL_DEBUG) */ 138 | 139 | #pragma mark - private definitions 140 | 141 | /* 142 | * Ensure that both LP32 and LP64 variants of arm64 use the same kd_buf 143 | * structure. 144 | */ 145 | #if defined(__arm64__) 146 | typedef uint64_t kd_buf_argtype; 147 | #else 148 | typedef uintptr_t kd_buf_argtype; 149 | #endif 150 | 151 | /* 152 | * The main event ABI as recorded in the kernel. 153 | */ 154 | 155 | typedef struct { 156 | uint64_t timestamp; 157 | kd_buf_argtype arg1; 158 | kd_buf_argtype arg2; 159 | kd_buf_argtype arg3; 160 | kd_buf_argtype arg4; 161 | kd_buf_argtype arg5; /* the thread ID */ 162 | uint32_t debugid; 163 | /* 164 | * Ensure that both LP32 and LP64 variants of arm64 use the same kd_buf 165 | * structure. 166 | */ 167 | #if defined(__LP64__) || defined(__arm64__) 168 | uint32_t cpuid; 169 | kd_buf_argtype unused; 170 | #endif 171 | } kd_buf; 172 | 173 | #if defined(__LP64__) || defined(__arm64__) 174 | #define KDBG_TIMESTAMP_MASK 0xffffffffffffffffULL 175 | static inline void 176 | kdbg_set_cpu(kd_buf *kp, int cpu) 177 | { 178 | kp->cpuid = (unsigned int)cpu; 179 | } 180 | static inline int 181 | kdbg_get_cpu(kd_buf *kp) 182 | { 183 | return (int)kp->cpuid; 184 | } 185 | static inline void 186 | kdbg_set_timestamp(kd_buf *kp, uint64_t thetime) 187 | { 188 | kp->timestamp = thetime; 189 | } 190 | static inline uint64_t 191 | kdbg_get_timestamp(kd_buf *kp) 192 | { 193 | return kp->timestamp; 194 | } 195 | static inline void 196 | kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu) 197 | { 198 | kdbg_set_timestamp(kp, thetime); 199 | kdbg_set_cpu(kp, cpu); 200 | } 201 | #else 202 | #define KDBG_TIMESTAMP_MASK 0x00ffffffffffffffULL 203 | #define KDBG_CPU_MASK 0xff00000000000000ULL 204 | #define KDBG_CPU_SHIFT 56 205 | static inline void 206 | kdbg_set_cpu(kd_buf *kp, int cpu) 207 | { 208 | kp->timestamp = (kp->timestamp & KDBG_TIMESTAMP_MASK) | 209 | (((uint64_t) cpu) << KDBG_CPU_SHIFT); 210 | } 211 | static inline int 212 | kdbg_get_cpu(kd_buf *kp) 213 | { 214 | return (int) (((kp)->timestamp & KDBG_CPU_MASK) >> KDBG_CPU_SHIFT); 215 | } 216 | static inline void 217 | kdbg_set_timestamp(kd_buf *kp, uint64_t thetime) 218 | { 219 | kp->timestamp = thetime & KDBG_TIMESTAMP_MASK; 220 | } 221 | static inline uint64_t 222 | kdbg_get_timestamp(kd_buf *kp) 223 | { 224 | return kp->timestamp & KDBG_TIMESTAMP_MASK; 225 | } 226 | static inline void 227 | kdbg_set_timestamp_and_cpu(kd_buf *kp, uint64_t thetime, int cpu) 228 | { 229 | kp->timestamp = (thetime & KDBG_TIMESTAMP_MASK) | 230 | (((uint64_t) cpu) << KDBG_CPU_SHIFT); 231 | } 232 | #endif 233 | 234 | /* 235 | * 2^16 bits (8 kilobytes), one for each possible class/subclass combination 236 | */ 237 | #define KDBG_TYPEFILTER_BITMAP_SIZE ((256 * 256) / 8) 238 | 239 | /* 240 | * Bits for kd_ctrl_page.flags, KERN_KD{D,E}FLAGS. 241 | */ 242 | /* disable tracing when buffers are full */ 243 | #define KDBG_NOWRAP 0x0002 244 | /* buffer has wrapped */ 245 | #define KDBG_WRAPPED 0x0008 246 | /* only include processes with kdebug bit set in proc */ 247 | #define KDBG_PIDCHECK 0x0010 248 | /* thread map is initialized */ 249 | #define KDBG_MAPINIT 0x0020 250 | /* exclude processes based on kdebug bit in proc */ 251 | #define KDBG_PIDEXCLUDE 0x0040 252 | /* whether the kdebug locks are intialized */ 253 | #define KDBG_LOCKINIT 0x0080 254 | /* word size of the kernel */ 255 | #define KDBG_LP64 0x0100 256 | /* whether timestamps are in continuous time */ 257 | #define KDBG_CONTINUOUS_TIME 0x0200 258 | /* coprocessor tracing is disabled */ 259 | #define KDBG_DISABLE_COPROCS 0x0400 260 | /* check each event against matcher to disable tracing */ 261 | #define KDBG_MATCH_DISABLE 0x0800 262 | 263 | /* flags that are allowed to be set by user space */ 264 | #define KDBG_USERFLAGS (KDBG_NOWRAP | KDBG_CONTINUOUS_TIME | KDBG_DISABLE_COPROCS | KDBG_MATCH_DISABLE) 265 | 266 | /* bits for kd_ctrl_page.flags and kbufinfo_t.flags */ 267 | 268 | /* only trace events within a range */ 269 | #define KDBG_RANGECHECK 0x00100000U 270 | /* only trace at most 4 types of events, at the code granularity */ 271 | #define KDBG_VALCHECK 0x00200000U 272 | /* check class and subclass against the typefilter */ 273 | #define KDBG_TYPEFILTER_CHECK 0x00400000U 274 | /* we are going to use 64-bit debugid in arg4 */ 275 | #define KDBG_DEBUGID_64 0x00800000U 276 | /* kdebug trace buffers are initialized */ 277 | #define KDBG_BUFINIT 0x80000000U 278 | 279 | /* bits for the type field of kd_regtype */ 280 | #define KDBG_CLASSTYPE 0x10000 281 | #define KDBG_SUBCLSTYPE 0x20000 282 | #define KDBG_RANGETYPE 0x40000 283 | #define KDBG_TYPENONE 0x80000 284 | #define KDBG_CKTYPES 0xF0000 285 | 286 | typedef struct { 287 | unsigned int type; 288 | unsigned int value1; 289 | unsigned int value2; 290 | unsigned int value3; 291 | unsigned int value4; 292 | } kd_regtype; 293 | 294 | typedef struct { 295 | /* number of events that can fit in the buffers */ 296 | int nkdbufs; 297 | /* set if trace is disabled */ 298 | int nolog; 299 | /* kd_ctrl_page.flags */ 300 | unsigned int flags; 301 | /* number of threads in thread map */ 302 | int nkdthreads; 303 | /* the owning pid */ 304 | int bufid; 305 | } kbufinfo_t; 306 | 307 | typedef struct { 308 | /* the thread ID */ 309 | #if defined(__arm64__) 310 | uint64_t thread; 311 | #else 312 | uintptr_t thread __kernel_data_semantics; 313 | #endif 314 | /* 0 for invalid, otherwise the PID (or 1 for kernel_task) */ 315 | int valid; 316 | /* the name of the process owning the thread */ 317 | char command[20]; 318 | } kd_threadmap; 319 | 320 | typedef struct { 321 | uint32_t version_no; 322 | uint32_t cpu_count; 323 | } kd_cpumap_header; 324 | 325 | /* cpumap flags */ 326 | #define KDBG_CPUMAP_IS_IOP 0x1 327 | 328 | typedef struct { 329 | uint32_t cpu_id; 330 | uint32_t flags; 331 | char name[8]; 332 | } kd_cpumap; 333 | 334 | typedef struct { 335 | uint32_t cpu_id; 336 | uint32_t flags; 337 | char name[32]; 338 | } kd_cpumap_ext; 339 | 340 | typedef struct { 341 | int version_no; 342 | int thread_count; 343 | uint64_t TOD_secs; 344 | uint32_t TOD_usecs; 345 | } RAW_header; 346 | 347 | typedef struct { 348 | uint32_t kem_debugid; 349 | uint32_t kem_padding; 350 | uint64_t kem_args[4]; 351 | } kd_event_matcher; 352 | 353 | /* 354 | * Bits set in the comm page for kdebug. 355 | */ 356 | #define KDEBUG_COMMPAGE_ENABLE_TRACE 0x1 357 | #define KDEBUG_COMMPAGE_ENABLE_TYPEFILTER 0x2 /* Forced to false if ENABLE_TRACE is 0 */ 358 | #define KDEBUG_COMMPAGE_CONTINUOUS 0x4 /* Forced to false if ENABLE_TRACE is 0 */ 359 | 360 | #pragma mark - Tests 361 | 362 | enum kdebug_test { 363 | KDTEST_KERNEL_MACROS = 1, 364 | KDTEST_OLD_TIMESTAMP = 2, 365 | KDTEST_FUTURE_TIMESTAMP = 3, 366 | KDTEST_SETUP_IOP = 4, 367 | KDTEST_SETUP_COPROCESSOR = 5, 368 | KDTEST_CONTINUOUS_TIMESTAMP = 6, 369 | KDTEST_ABSOLUTE_TIMESTAMP = 7, 370 | }; 371 | 372 | #pragma mark - Obsolete interfaces 373 | 374 | /* obsolete KERN_KD[DE]FLAGS flags */ 375 | #define KDBG_INIT 0x01 376 | #define KDBG_FREERUN 0x04 377 | 378 | /* Obsolete IDs for trace files. */ 379 | #define RAW_VERSION0 0x55aa0000 380 | #define RAW_VERSION1 0x55aa0101 381 | #define RAW_VERSION2 0x55aa0200 382 | 383 | /* for EnergyTracing user space & clients */ 384 | #define kEnTrCompKernel 2 385 | 386 | /* 387 | * EnergyTracing opcodes 388 | * 389 | * Activations use DBG_FUNC_START/END. 390 | * Events are DBG_FUNC_NONE. 391 | */ 392 | 393 | /* Socket reads and writes are uniquely identified by the (sanitized) 394 | * pointer to the socket struct in question. To associate this address 395 | * with the user space file descriptor, we have a socket activation with 396 | * the FD as its identifier and the socket struct pointer as its value. 397 | */ 398 | #define kEnTrActKernSocket 1 399 | #define kEnTrActKernSockRead 2 400 | #define kEnTrActKernSockWrite 3 401 | 402 | #define kEnTrActKernPoll 10 403 | #define kEnTrActKernSelect 11 404 | #define kEnTrActKernKQWait 12 405 | 406 | #define kEnTrEvUnblocked 256 407 | 408 | /* Lower 16-bits of quality. */ 409 | #define kEnTrFlagNonBlocking 1 << 0 410 | #define kEnTrFlagNoWork 1 << 1 411 | 412 | /* 413 | * EnergyTracing macros. 414 | */ 415 | 416 | #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) 417 | #define ENTR_SHOULDTRACE kdebug_enable 418 | #define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) \ 419 | do { \ 420 | uint32_t kdcode__; \ 421 | uintptr_t highval__, lowval__, mask__ = 0xffffffff; \ 422 | kdcode__ = KDBG_CODE(DBG_ENERGYTRACE,component,opcode)|(lifespan); \ 423 | highval__ = ((value) >> 32) & mask__; \ 424 | lowval__ = (value) & mask__; \ 425 | ENTR_KDTRACEFUNC(kdcode__, id, quality, highval__, lowval__); \ 426 | } while(0) 427 | 428 | /* 429 | * Trace the association of two existing activations. 430 | * 431 | * An association is traced as a modification to the parent activation. 432 | * In order to fit the sub-activation's component, activation code, and 433 | * activation ID into a kdebug tracepoint, the arguments that would hold 434 | * the value are left separate, and one stores the component and opcode 435 | * of the sub-activation, while the other stores the pointer-sized 436 | * activation ID. 437 | * 438 | * arg2 arg3 arg4 439 | +-----------------+ +~+----+----+--------+ +----------+ 440 | |kEnTrModAssociate| | | | | | | | 441 | +-----------------+ +~+----+----+--------+ +----------+ 442 | * 8-bits unused sub-activation ID 443 | * 8-bit sub-component 444 | * 16-bit sub-opcode 445 | * 446 | */ 447 | #define kEnTrModAssociate (1 << 28) 448 | #define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, \ 449 | sub_comp, sub_opcode, sub_act_id) \ 450 | do { \ 451 | unsigned sub_compcode = ((unsigned)sub_comp << 16) | sub_opcode; \ 452 | ENTR_KDTRACEFUNC(KDBG_CODE(DBG_ENERGYTRACE,par_comp,par_opcode), \ 453 | par_act_id, kEnTrModAssociate, sub_compcode, \ 454 | sub_act_id); \ 455 | } while(0) 456 | 457 | #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */ 458 | 459 | #define ENTR_SHOULDTRACE FALSE 460 | #define ENTR_KDTRACE(component, opcode, lifespan, id, quality, value) \ 461 | do {} while (0) 462 | #define ENTR_KDASSOCIATE(par_comp, par_opcode, par_act_id, \ 463 | sub_comp, sub_opcode, sub_act_id) \ 464 | do {} while (0) 465 | 466 | #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_IST) */ 467 | 468 | 469 | __END_DECLS 470 | 471 | #endif /* !defined(BSD_KDEBUG_PRIVATE_H) */ 472 | -------------------------------------------------------------------------------- /AllRez/MacOSMacros.h: -------------------------------------------------------------------------------- 1 | #ifndef __MACOSMACROS_HPP__ 2 | #define __MACOSMACROS_HPP__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifndef MAC_OS_X_VERSION_10_0 9 | #define MAC_OS_X_VERSION_10_0 1000 10 | #endif 11 | 12 | #ifndef MAC_OS_X_VERSION_10_1 13 | #define MAC_OS_X_VERSION_10_1 1010 14 | #endif 15 | 16 | #ifndef MAC_OS_X_VERSION_10_2 17 | #define MAC_OS_X_VERSION_10_2 1020 18 | #endif 19 | 20 | #ifndef MAC_OS_X_VERSION_10_3 21 | #define MAC_OS_X_VERSION_10_3 1030 22 | #endif 23 | 24 | #ifndef MAC_OS_X_VERSION_10_3_9 25 | #define MAC_OS_X_VERSION_10_3_9 1039 26 | #endif 27 | 28 | #ifndef MAC_OS_X_VERSION_10_4 29 | #define MAC_OS_X_VERSION_10_4 1040 30 | #endif 31 | 32 | #ifndef MAC_OS_X_VERSION_10_5 33 | #define MAC_OS_X_VERSION_10_5 1050 34 | #endif 35 | 36 | #ifndef MAC_OS_X_VERSION_10_6 37 | #define MAC_OS_X_VERSION_10_6 1060 38 | #endif 39 | 40 | #ifndef MAC_OS_X_VERSION_10_7 41 | #define MAC_OS_X_VERSION_10_7 1070 42 | #endif 43 | 44 | #ifndef MAC_OS_X_VERSION_10_8 45 | #define MAC_OS_X_VERSION_10_8 1080 46 | #endif 47 | 48 | #ifndef MAC_OS_X_VERSION_10_9 49 | #define MAC_OS_X_VERSION_10_9 1090 50 | #endif 51 | 52 | #ifndef MAC_OS_X_VERSION_10_10 53 | #define MAC_OS_X_VERSION_10_10 101000 54 | #endif 55 | 56 | #ifndef MAC_OS_X_VERSION_10_10_2 57 | #define MAC_OS_X_VERSION_10_10_2 101002 58 | #endif 59 | 60 | #ifndef MAC_OS_X_VERSION_10_10_3 61 | #define MAC_OS_X_VERSION_10_10_3 101003 62 | #endif 63 | 64 | #ifndef MAC_OS_X_VERSION_10_11 65 | #define MAC_OS_X_VERSION_10_11 101100 66 | #endif 67 | 68 | #ifndef MAC_OS_X_VERSION_10_11_2 69 | #define MAC_OS_X_VERSION_10_11_2 101102 70 | #endif 71 | 72 | #ifndef MAC_OS_X_VERSION_10_11_3 73 | #define MAC_OS_X_VERSION_10_11_3 101103 74 | #endif 75 | 76 | #ifndef MAC_OS_X_VERSION_10_11_4 77 | #define MAC_OS_X_VERSION_10_11_4 101104 78 | #endif 79 | 80 | #ifndef MAC_OS_X_VERSION_10_12 81 | #define MAC_OS_X_VERSION_10_12 101200 82 | #endif 83 | 84 | #ifndef MAC_OS_X_VERSION_10_12_1 85 | #define MAC_OS_X_VERSION_10_12_1 101201 86 | #endif 87 | 88 | #ifndef MAC_OS_X_VERSION_10_12_2 89 | #define MAC_OS_X_VERSION_10_12_2 101202 90 | #endif 91 | 92 | #ifndef MAC_OS_X_VERSION_10_12_4 93 | #define MAC_OS_X_VERSION_10_12_4 101204 94 | #endif 95 | 96 | #ifndef MAC_OS_X_VERSION_10_13 97 | #define MAC_OS_X_VERSION_10_13 101300 98 | #endif 99 | 100 | #ifndef MAC_OS_X_VERSION_10_13_1 101 | #define MAC_OS_X_VERSION_10_13_1 101301 102 | #endif 103 | 104 | #ifndef MAC_OS_X_VERSION_10_13_2 105 | #define MAC_OS_X_VERSION_10_13_2 101302 106 | #endif 107 | 108 | #ifndef MAC_OS_X_VERSION_10_13_4 109 | #define MAC_OS_X_VERSION_10_13_4 101304 110 | #endif 111 | 112 | #ifndef MAC_OS_X_VERSION_10_14 113 | #define MAC_OS_X_VERSION_10_14 101400 114 | #endif 115 | 116 | #ifndef MAC_OS_X_VERSION_10_14_1 117 | #define MAC_OS_X_VERSION_10_14_1 101401 118 | #endif 119 | 120 | #ifndef MAC_OS_X_VERSION_10_14_4 121 | #define MAC_OS_X_VERSION_10_14_4 101404 122 | #endif 123 | 124 | #ifndef MAC_OS_X_VERSION_10_15 125 | #define MAC_OS_X_VERSION_10_15 101500 126 | #endif 127 | 128 | #ifndef MAC_OS_X_VERSION_10_15_1 129 | #define MAC_OS_X_VERSION_10_15_1 101501 130 | #endif 131 | 132 | #ifndef MAC_OS_VERSION_12_1 133 | #define MAC_OS_VERSION_12_1 120100 134 | #endif 135 | 136 | #ifndef MAC_OS_VERSION_12_2 137 | #define MAC_OS_VERSION_12_2 120200 138 | #endif 139 | 140 | #ifndef MAC_OS_VERSION_12_3 141 | #define MAC_OS_VERSION_12_3 120300 142 | #endif 143 | 144 | #if !defined(AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER) 145 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_1 146 | #elsif !defined(verify_action) 147 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_2 148 | #else 149 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_3 150 | #endif 151 | 152 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_3) 153 | #undef MAC_OS_X_VERSION_SDK 154 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_3_9 155 | #endif 156 | 157 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER) && defined(TARGET_CPU_PPC64) 158 | #undef MAC_OS_X_VERSION_SDK 159 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_4 160 | // 10.4u sdk 161 | #endif 162 | 163 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER) && defined(TARGET_OS_EMBEDDED) 164 | #undef MAC_OS_X_VERSION_SDK 165 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_5 166 | #endif 167 | 168 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER) 169 | #undef MAC_OS_X_VERSION_SDK 170 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_6 171 | #endif 172 | 173 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER) 174 | #undef MAC_OS_X_VERSION_SDK 175 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_7 176 | #endif 177 | 178 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER) 179 | #undef MAC_OS_X_VERSION_SDK 180 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_8 181 | #endif 182 | 183 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER) 184 | #undef MAC_OS_X_VERSION_SDK 185 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_9 186 | #endif 187 | 188 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER) 189 | #undef MAC_OS_X_VERSION_SDK 190 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_10 191 | #endif 192 | 193 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_10_2_AND_LATER) 194 | #undef MAC_OS_X_VERSION_SDK 195 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_10_2 196 | #endif 197 | 198 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_10_3_AND_LATER) 199 | #undef MAC_OS_X_VERSION_SDK 200 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_10_3 201 | #endif 202 | 203 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER) 204 | #undef MAC_OS_X_VERSION_SDK 205 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_11 206 | #endif 207 | 208 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_11_2_AND_LATER) 209 | #undef MAC_OS_X_VERSION_SDK 210 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_11_2 211 | #endif 212 | 213 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_11_AND_LATER) 214 | #undef MAC_OS_X_VERSION_SDK 215 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_11 216 | #endif 217 | 218 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER) 219 | #undef MAC_OS_X_VERSION_SDK 220 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_12 221 | #endif 222 | 223 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_13_AND_LATER) 224 | #undef MAC_OS_X_VERSION_SDK 225 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_13 226 | #endif 227 | 228 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_13_1_AND_LATER) 229 | #undef MAC_OS_X_VERSION_SDK 230 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_13_1 231 | #endif 232 | 233 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_13_2_AND_LATER) 234 | #undef MAC_OS_X_VERSION_SDK 235 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_13_2 236 | #endif 237 | 238 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_14_AND_LATER) 239 | #undef MAC_OS_X_VERSION_SDK 240 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_14 241 | #endif 242 | 243 | #if defined(AVAILABLE_MAC_OS_X_VERSION_10_15_AND_LATER) 244 | #undef MAC_OS_X_VERSION_SDK 245 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_15 246 | #endif 247 | 248 | #if defined(__MAC_10_15_1) 249 | #undef MAC_OS_X_VERSION_SDK 250 | #define MAC_OS_X_VERSION_SDK MAC_OS_X_VERSION_10_15_1 251 | #endif 252 | 253 | #if defined(MAC_OS_VERSION_11_0) 254 | #undef MAC_OS_X_VERSION_SDK 255 | #define MAC_OS_X_VERSION_SDK MAC_OS_VERSION_11_0 256 | #endif 257 | 258 | #if defined(MAC_OS_VERSION_11_1) 259 | #undef MAC_OS_X_VERSION_SDK 260 | #define MAC_OS_X_VERSION_SDK MAC_OS_VERSION_11_1 261 | #endif 262 | 263 | #if defined(MAC_OS_VERSION_11_2) 264 | #undef MAC_OS_X_VERSION_SDK 265 | #define MAC_OS_X_VERSION_SDK MAC_OS_VERSION_11_2 266 | #endif 267 | 268 | #if defined(MAC_OS_VERSION_11_3) 269 | #undef MAC_OS_X_VERSION_SDK 270 | #define MAC_OS_X_VERSION_SDK MAC_OS_VERSION_11_3 271 | #endif 272 | 273 | #if defined(MAC_OS_VERSION_12_0) 274 | #undef MAC_OS_X_VERSION_SDK 275 | #define MAC_OS_X_VERSION_SDK MAC_OS_VERSION_12_0 276 | #endif 277 | 278 | #if defined (__MAC_12_1) 279 | #undef MAC_OS_X_VERSION_SDK 280 | #define MAC_OS_X_VERSION_SDK MAC_OS_VERSION_12_1 281 | #endif 282 | 283 | #if defined (__MAC_12_2) 284 | #undef MAC_OS_X_VERSION_SDK 285 | #define MAC_OS_X_VERSION_SDK MAC_OS_VERSION_12_2 286 | #endif 287 | 288 | #if defined (__MAC_12_3) 289 | #undef MAC_OS_X_VERSION_SDK 290 | #define MAC_OS_X_VERSION_SDK MAC_OS_VERSION_12_3 291 | #endif 292 | 293 | #if defined(MAC_OS_VERSION_13_0) 294 | #undef MAC_OS_X_VERSION_SDK 295 | #define MAC_OS_X_VERSION_SDK MAC_OS_VERSION_13_0 296 | #endif 297 | 298 | #if defined (__MAC_13_1) 299 | #undef MAC_OS_X_VERSION_SDK 300 | #define MAC_OS_X_VERSION_SDK MAC_OS_VERSION_13_1 301 | #define MAX_TESTED_MAC_OS_X_VERSION_SDK 302 | #endif 303 | 304 | #ifndef MAC_OS_VERSION_11_0 305 | #define MAC_OS_VERSION_11_0 110000 306 | #endif 307 | 308 | #ifndef MAC_OS_VERSION_11_1 309 | #define MAC_OS_VERSION_11_1 110100 310 | #endif 311 | 312 | #ifndef MAC_OS_VERSION_11_2 313 | #define MAC_OS_VERSION_11_2 110200 314 | #endif 315 | 316 | #ifndef MAC_OS_VERSION_11_3 317 | #define MAC_OS_VERSION_11_3 110300 318 | #endif 319 | 320 | #ifndef MAC_OS_VERSION_12_0 321 | #define MAC_OS_VERSION_12_0 120000 322 | #endif 323 | 324 | #ifndef MAC_OS_VERSION_13_0 325 | #define MAC_OS_VERSION_13_0 130000 326 | #endif 327 | 328 | #ifndef MAC_OS_VERSION_13_1 329 | #define MAC_OS_VERSION_13_1 130100 330 | #endif 331 | 332 | #if !defined(MAC_OS_X_VERSION_MAX_ALLOWED) || !defined(MAC_OS_X_VERSION_SDK) 333 | #error missing #include AvailabilityMacros.h 334 | #endif 335 | 336 | #define STR_HELPER(x) #x 337 | #define STR(x) STR_HELPER(x) 338 | 339 | #if defined(__ppc64__) 340 | #define ARCHITECTURE "ppc64" 341 | #ifndef __clang__ 342 | #warning ppc64 343 | #endif 344 | #elif defined(__ppc__) 345 | #define ARCHITECTURE "ppc" 346 | #ifndef __clang__ 347 | #warning ppc 348 | #endif 349 | #elif defined(__x86_64__) 350 | #define ARCHITECTURE "x86_64" 351 | #ifndef __clang__ 352 | #warning x86_64 353 | #endif 354 | #elif defined(__i386__) 355 | #define ARCHITECTURE "i386" 356 | #ifndef __clang__ 357 | #warning i386 358 | #endif 359 | #elif defined(__arm64e__) 360 | #define ARCHITECTURE "arm64e" 361 | #ifndef __clang__ 362 | #warning arm64e 363 | #endif 364 | #elif defined(__arm64__) 365 | #define ARCHITECTURE "arm64" 366 | #ifndef __clang__ 367 | #warning arm64 368 | #endif 369 | #else 370 | #define ARCHITECTURE "unknownArch" 371 | #error other architecture 372 | #endif 373 | 374 | #pragma message ARCHITECTURE " min:" STR(MAC_OS_X_VERSION_MIN_REQUIRED) " max:" STR(MAC_OS_X_VERSION_MAX_ALLOWED) " sdk:" STR(MAC_OS_X_VERSION_SDK) 375 | 376 | #define API_OR_SDK_AVAILABLE_BEGIN(SDK, name) { { { if (&name != NULL) { 377 | #define API_OR_SDK_AVAILABLE_ELSE } else { 378 | #define API_OR_SDK_AVAILABLE_END } } } } 379 | 380 | #if defined(__has_builtin) 381 | #if __has_builtin(__builtin_available) 382 | 383 | // __builtin_available only works down to Mac OS X 10.6 because 10.5 SDK is missing __isOSVersionAtLeast. 384 | 385 | #ifdef __cplusplus 386 | extern "C" { 387 | #endif 388 | int __isOSVersionAtLeast(int Major, int Minor, int Subminor); 389 | #ifdef __cplusplus 390 | } 391 | #endif 392 | 393 | /* 394 | #undef API_OR_SDK_AVAILABLE_BEGIN 395 | #define API_OR_SDK_AVAILABLE_BEGIN(SDK, name) { if (!&__isOSVersionAtLeast) goto __label_ ## name; { if (__builtin_available(macOS SDK, *)) { \ 396 | __label_ ## name: if (&name) { 397 | */ 398 | 399 | #endif 400 | #endif 401 | 402 | #endif /* __MACOSMACROS_H__ */ 403 | -------------------------------------------------------------------------------- /AllRez/ddccicommands.h: -------------------------------------------------------------------------------- 1 | // DDC commands 2 | 3 | oneddccmd(F1, "Identification request" ) 4 | oneddccmd(F3, "Capabilities request" ) 5 | oneddccmd(B1, "Display self-test request") 6 | oneddccmd(07, "Timing request" ) 7 | oneddccmd(01, "VCP request" ) 8 | oneddccmd(03, "VCP set" ) 9 | oneddccmd(E2, "Table read request" ) 10 | oneddccmd(E7, "Table write" ) 11 | oneddccmd(F5, "Enable application report") 12 | oneddccmd(0C, "Save current settings" ) 13 | oneddccmd(E1, "Identification reply" ) 14 | oneddccmd(E3, "Capabilities reply" ) 15 | oneddccmd(A1, "Display self-test reply" ) 16 | oneddccmd(06, "Timing reply" ) 17 | oneddccmd(02, "VCP reply" ) 18 | oneddccmd(09, "VCP reset" ) 19 | oneddccmd(E4, "Table read reply" ) 20 | 21 | #undef oneddccmd 22 | -------------------------------------------------------------------------------- /AllRez/displayport.h: -------------------------------------------------------------------------------- 1 | // 2 | // displayport.h 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-05-20. 6 | // 7 | 8 | #ifndef mst_h 9 | #define mst_h 10 | 11 | #include // for guid_t 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include 18 | #include 19 | 20 | typedef enum { 21 | dpNoError, 22 | dpErrReadMsgDownRep, 23 | dpErrReadServiceIrq, 24 | dpErrResetServiceIrq, 25 | dpErrNak, 26 | dpErrIdentifierMismatch, 27 | dpErrSequenceMismatch, 28 | dpErrFirstMsgIsNotStart, 29 | dpErrStartIsNotFirstMsg, 30 | dpErrLastMsgIsNotEnd, 31 | dpErrEndIsNotLastMsg, 32 | dpErrPathMismatch, 33 | dpErrCrc, 34 | dpErrReplyTimeout, 35 | dpErrWriteMsgDownReq, 36 | dpErrReadDpcd 37 | } DpError; 38 | 39 | const char *DpErrorStr(DpError dperr); 40 | 41 | /* 42 | All fields are defined from most-significant bit and most significant byte first. 43 | */ 44 | 45 | #define UNALIGNED __attribute__((aligned(1))) 46 | #define PACKED __attribute__((packed)) UNALIGNED 47 | 48 | typedef struct I2C_Transaction { 49 | UInt8 Write_I2C_Device_Identifier : 7; // LSB 50 | UInt8 zero : 1; // MSB 51 | UInt8 Number_Of_Bytes_To_Write; 52 | UInt8 I2C_Data_To_Write[]; 53 | // I2C_Transaction2 54 | } I2C_Transaction; 55 | extern int assertx00[(__builtin_offsetof(I2C_Transaction, I2C_Data_To_Write) == 2) - 1]; 56 | 57 | typedef struct I2C_Transaction2 { 58 | UInt8 I2C_Transaction_Delay : 4; // LSB 59 | UInt8 No_Stop_Bit : 1; 60 | UInt8 zeros : 3; // MSB 61 | UInt8 end[]; 62 | } I2C_Transaction2; 63 | extern int assertx01[(__builtin_offsetof(I2C_Transaction2, end) == 1) - 1]; 64 | 65 | typedef struct Remote_I2C_Read2 { 66 | UInt8 Read_I2C_Device_Identifier : 7; // LSB 67 | UInt8 zero : 1; // MSB 68 | UInt8 Number_Of_Bytes_To_Read; 69 | UInt8 end[]; 70 | } Remote_I2C_Read2; 71 | extern int assertx02[(__builtin_offsetof(Remote_I2C_Read2, end) == 2) - 1]; 72 | 73 | typedef struct Sink_Event_Notify2 { 74 | // byte alligned after Relative_Address 75 | UInt8 Sink_Event; 76 | UInt8 end[]; 77 | } Sink_Event_Notify2; 78 | extern int assertx03[(__builtin_offsetof(Sink_Event_Notify2, end) == 1) - 1]; 79 | 80 | typedef struct Link_Address_Port { 81 | UInt8 Port_Number : 4; // LSB 82 | UInt8 Peer_Device_Type : 3; 83 | UInt8 Input_Port : 1; // MSB 84 | union { 85 | struct { 86 | UInt8 zeros : 5; // LSB; 87 | UInt8 Legacy_Device_Plug_Status : 1; 88 | UInt8 DisplayPort_Device_Plug_Status : 1; 89 | UInt8 Messaging_Capability_Status : 1; // MSB 90 | 91 | UInt8 Dpcd_Revision_Minor : 4; // LSB 92 | UInt8 Dpcd_Revision_Major : 4; // MSB 93 | 94 | PACKED guid_t Peer_Guid; // do not remove PACKED - it is needed for later compilers such as Xcode 14.2 95 | 96 | UInt8 Number_SDP_Stream_Sinks : 4; // LSB 97 | UInt8 Number_SDP_Streams : 4; // MSB 98 | UInt8 end[]; 99 | } Output; 100 | struct { 101 | UInt8 zeros : 6; // LSB 102 | UInt8 DisplayPort_Device_Plug_Status : 1; 103 | UInt8 Messaging_Capability_Status : 1; // MSB 104 | UInt8 end[]; 105 | } Input; 106 | }; 107 | } Link_Address_Port; 108 | extern int assertx04[(__builtin_offsetof(Link_Address_Port, Output.end) == 20) - 1]; 109 | extern int assertx05[(__builtin_offsetof(Link_Address_Port, Input.end) == 2) - 1]; 110 | 111 | typedef struct Message_Transaction_Request { 112 | UInt8 Request_Identifier : 7; // LSB 113 | UInt8 zero : 1; // MSB 114 | PACKED union { // Request_Data 115 | struct { 116 | UInt8 zeros : 4; // LSB 117 | UInt8 Port_Number : 4; // MSB 118 | 119 | PACKED guid_t Global_Unique_Identifier; // do not remove PACKED - it is needed for later compilers such as Xcode 14.2 120 | 121 | UInt8 Peer_Device_Type : 3; // LSB 122 | UInt8 Input_Port : 1; 123 | UInt8 Messaging_Capability_Status : 1; 124 | UInt8 DisplayPort_Device_Plug_Status : 1; 125 | UInt8 Legacy_Device_Plug_status : 1; 126 | UInt8 zero : 1; // MSB 127 | UInt8 end[]; 128 | } Connection_Status_Notify; 129 | struct { 130 | UInt8 zeros : 4; // LSB 131 | UInt8 Port_Number : 4; // MSB 132 | UInt8 end[]; 133 | } Enum_Path_Resources; 134 | struct { 135 | UInt8 Number_SDP_Streams : 4; // LSB 136 | UInt8 Port_Number : 4; // MSB 137 | 138 | UInt8 Virtual_Channel_Payload_Identifier : 7; // LSB 139 | UInt8 zero : 1; // MSB 140 | 141 | PACKED UInt16 Payload_Bandwidth_Number; // big-endian 142 | 143 | UInt8 SDP_Stream_Sink[8]; // Number_SDP_Streams nibbles 144 | } Allocate_Payload; 145 | struct { 146 | UInt8 zeros : 4; // LSB 147 | UInt8 Port_Number : 4; // MSB 148 | UInt8 Virtual_Channel_Payload_Identifier : 7; // LSB 149 | UInt8 zero : 1; // MSB 150 | UInt8 end[]; 151 | } Query_Payload; 152 | struct { 153 | UInt8 zeros : 4; // LSB 154 | UInt8 Port_Number : 4; // MSB 155 | 156 | PACKED guid_t Global_Unique_Identifier; // do not remove PACKED - it is needed for later compilers such as Xcode 14.2 157 | 158 | PACKED UInt16 Available_PBN; // big-endian 159 | UInt8 end[]; 160 | } Resource_Status_Notify; 161 | union { 162 | struct { 163 | uint32_t Number_Of_Bytes_To_Read : 8; // LSB of 32 bits 164 | uint32_t DPCD_Address : 20; 165 | uint32_t Port_Number : 4; // MSB of 32 bits 166 | UInt8 end[]; 167 | }; // big-endian 168 | uint32_t raw; // big-endian 169 | } Remote_DPCD_Read; 170 | union { 171 | struct { 172 | uint32_t Number_Of_Bytes_To_Write : 8; // LSB of 32 bits 173 | uint32_t DPCD_Address : 20; 174 | uint32_t Port_Number : 4; // MSB of 32 bits 175 | UInt8 Write_Data[]; 176 | }; // big-endian 177 | uint32_t raw; // big-endian 178 | } Remote_DPCD_Write; 179 | struct { 180 | // DisplayPort 1.2 spec page 263 has correct order but incorrect sizes. 181 | // DisplayPort 1.2 spec page 293 has incorrect order but correct sizes. 182 | UInt8 Number_Of_I2C_Write_Transactions : 2; // LSB 183 | UInt8 zeros : 2; 184 | UInt8 Port_Number : 4; // MSB 185 | I2C_Transaction Transactions[]; 186 | // Remote_I2C_Read2; 187 | } Remote_I2C_Read; 188 | struct { 189 | UInt8 zeros : 4; // LSB 190 | UInt8 Port_Number : 4; // MSB 191 | UInt8 Write_I2C_Device_Identifier : 7; // LSB 192 | UInt8 zero : 1; // MSB 193 | UInt8 Number_Of_Bytes_To_Write; 194 | UInt8 I2C_Data_To_Write[]; 195 | } Remote_I2C_Write; 196 | struct { 197 | UInt8 Port_Number : 4; // LSB 198 | UInt8 zeros : 4; // MSB 199 | UInt8 end[]; 200 | } Power_Up_PHY; 201 | struct { 202 | UInt8 Port_Number : 4; // LSB 203 | UInt8 zeros : 4; // MSB 204 | UInt8 end[]; 205 | } Power_Down_PHY; 206 | struct { 207 | UInt8 Link_Count : 4; // LSB 208 | UInt8 zeros : 4; // MSB 209 | UInt8 Relative_Address[8]; 210 | // Sink_Event_Notify2; 211 | } Sink_Event_Notify; 212 | struct { 213 | UInt8 end; 214 | } Default; 215 | } PACKED; 216 | } Message_Transaction_Request; 217 | extern int assertx06[(__builtin_offsetof(Message_Transaction_Request, Connection_Status_Notify.end) == 19) - 1]; 218 | extern int assertx07[(__builtin_offsetof(Message_Transaction_Request, Enum_Path_Resources.end) == 2) - 1]; 219 | extern int assertx08[(__builtin_offsetof(Message_Transaction_Request, Allocate_Payload.SDP_Stream_Sink) == 5) - 1]; 220 | extern int assertx09[(__builtin_offsetof(Message_Transaction_Request, Query_Payload.end) == 3) - 1]; 221 | extern int assertx10[(__builtin_offsetof(Message_Transaction_Request, Resource_Status_Notify.end) == 20) - 1]; 222 | extern int assertx11[(__builtin_offsetof(Message_Transaction_Request, Remote_DPCD_Read.end) == 5) - 1]; 223 | extern int assertx12[(__builtin_offsetof(Message_Transaction_Request, Remote_DPCD_Write.Write_Data) == 5) - 1]; 224 | extern int assertx13[(__builtin_offsetof(Message_Transaction_Request, Remote_I2C_Read.Transactions) == 2) - 1]; 225 | extern int assertx14[(__builtin_offsetof(Message_Transaction_Request, Remote_I2C_Write.I2C_Data_To_Write) == 4) - 1]; 226 | extern int assertx15[(__builtin_offsetof(Message_Transaction_Request, Power_Up_PHY.end) == 2) - 1]; 227 | extern int assertx16[(__builtin_offsetof(Message_Transaction_Request, Power_Down_PHY.end) == 2) - 1]; 228 | extern int assertx17[(__builtin_offsetof(Message_Transaction_Request, Sink_Event_Notify.Relative_Address) == 2) - 1]; 229 | extern int assertx18[(__builtin_offsetof(Message_Transaction_Request, Default.end) == 1) - 1]; 230 | 231 | typedef struct Message_Transaction_Reply { 232 | UInt8 Request_Identifier : 7; // LSB copy of same in Request Message Transaction 233 | UInt8 Reply_Type : 1; // MSB DP_SIDEBAND_REPLY_ACK=0 or DP_SIDEBAND_REPLY_NAK=1 234 | PACKED union { // Reply_Data 235 | struct { 236 | guid_t Global_Unique_Identifier; 237 | UInt8 Reason_For_NAK; // DP_NAK_INVALID_READ should actually be renamed DP_NAK_INVALID_RAD 238 | UInt8 NAK_Data; 239 | #if 0 240 | REMOTE_DPCD__WRITE_Nak_Reply() { 241 | UInt8 Request_Type : 7; // LSB 242 | UInt8 Reply_Type : 1; // MSB 243 | UInt8 Port_Number : 4; // LSB 244 | UInt8 zeros : 4; // MSB 245 | UInt8 Reason_For_Nak; 246 | UInt8 Number_Of_Bytes_Written_Before_Failure; 247 | } 248 | 249 | REMOTE_I2C_READ_Nak_Reply() { 250 | UInt8 Request_Type : 7; // LSB 251 | UInt8 Reply_Type : 1; // MSB 252 | UInt8 Size_Of_RAD : 4; // LSB 253 | UInt8 Downstream Port Number : 4; // MSB 254 | UInt8 Remaining_RAD_To_Target[8]; 255 | REMOTE_I2C_READ_Nak_Reply2() 256 | UInt8 Reason_For_Nak; 257 | UInt8 I2C_NAK_Transaction; 258 | } 259 | #endif 260 | UInt8 end[]; 261 | } NAK; // 1 262 | union { 263 | struct { 264 | guid_t Global_Unique_Identifier; 265 | UInt8 Number_Of_Ports : 4; // LSB 266 | UInt8 zeros : 4; // MSB 267 | Link_Address_Port Ports[]; // variable size 268 | } Link_Address; 269 | struct { 270 | UInt8 FEC_Capable : 1; // LSB 271 | UInt8 zeros : 3; 272 | UInt8 Port_Number : 4; // MSB 273 | 274 | PACKED UInt16 Payload_Bandwidth_Number; // big-endian 275 | PACKED UInt16 Available_PBN; // big-endian 276 | UInt8 end[]; 277 | } Enum_Path_Resources; 278 | struct { 279 | UInt8 zeros : 4; // LSB 280 | UInt8 Port_Number : 4; // MSB 281 | 282 | UInt8 Virtual_Channel_Payload_Identifier : 7; // LSB 283 | UInt8 zero : 1; // MSB 284 | 285 | PACKED UInt16 Payload_Bandwidth_Number; // big-endian 286 | UInt8 end[]; 287 | } Allocate_Payload; 288 | struct { 289 | UInt8 zeros : 4; // LSB 290 | UInt8 Port_Number : 4; // MSB 291 | PACKED UInt16 Allocated_PBN; // big-endian 292 | UInt8 end[]; 293 | } Query_Payload; 294 | struct { 295 | UInt8 Port_Number : 4; // LSB 296 | UInt8 zeros : 4; // MSB 297 | 298 | UInt8 Number_Of_Bytes_Read; 299 | UInt8 Data_Read[]; 300 | } Remote_DPCD_Read; 301 | struct { 302 | UInt8 Port_Number : 4; // LSB 303 | UInt8 zeros : 4; // MSB 304 | UInt8 end[]; 305 | } Remote_DPCD_Write; 306 | struct { 307 | UInt8 Downstream_Port_Number : 4; // LSB 308 | UInt8 zeros : 4; // MSB 309 | UInt8 Number_Of_Bytes_Read; 310 | UInt8 Data_Read[]; 311 | } Remote_I2C_Read; 312 | struct { 313 | UInt8 Port_Number : 4; // LSB 314 | UInt8 zeros : 4; // MSB 315 | UInt8 end[]; 316 | } Remote_I2C_Write; 317 | struct { 318 | UInt8 zeros : 4; // LSB 319 | UInt8 Port_Number : 4; // MSB 320 | UInt8 end[]; 321 | } Power_Up_PHY; 322 | struct { 323 | UInt8 zeros : 4; // LSB 324 | UInt8 Port_Number : 4; // MSB 325 | UInt8 end[]; 326 | } Power_Down_PHY; 327 | struct { 328 | // taken from linux drm_dp_mst_topology.c which doesn't match DisplayPort 1.2 spec. 329 | UInt8 zeros : 3; // LSB 330 | UInt8 Auth_Completed : 1; 331 | UInt8 Encryption_Enabled : 1; 332 | UInt8 Repeater_Present : 1; 333 | UInt8 State : 2; // MSB 334 | 335 | UInt8 Reply_Signed : 1; // LSB 336 | UInt8 zeros2 : 2; 337 | UInt8 Hdcp_2x_Device_Present : 1; 338 | UInt8 hdcp_1x_device_present : 1; 339 | UInt8 Query_Capable_Device_Present : 1; 340 | UInt8 Legacy_Device_Present : 1; 341 | UInt8 Unauthorizable_Device_Present : 1; // MSB 342 | 343 | UInt8 Stream_Id; 344 | UInt8 end[]; 345 | } Query_Stream_Enc_Status; 346 | struct { 347 | UInt8 end; 348 | } Default; 349 | } ACK; // 0 350 | }; 351 | } Message_Transaction_Reply; 352 | extern int assertx19[(__builtin_offsetof(Message_Transaction_Reply, NAK.end) == 19) - 1]; 353 | extern int assertx20[(__builtin_offsetof(Message_Transaction_Reply, ACK.Link_Address.Ports) == 18) - 1]; 354 | extern int assertx21[(__builtin_offsetof(Message_Transaction_Reply, ACK.Enum_Path_Resources.end) == 6) - 1]; 355 | extern int assertx22[(__builtin_offsetof(Message_Transaction_Reply, ACK.Allocate_Payload.end) == 5) - 1]; 356 | extern int assertx23[(__builtin_offsetof(Message_Transaction_Reply, ACK.Query_Payload.end) == 4) - 1]; 357 | extern int assertx24[(__builtin_offsetof(Message_Transaction_Reply, ACK.Remote_DPCD_Read.Data_Read) == 3) - 1]; 358 | extern int assertx25[(__builtin_offsetof(Message_Transaction_Reply, ACK.Remote_DPCD_Write.end) == 2) - 1]; 359 | extern int assertx26[(__builtin_offsetof(Message_Transaction_Reply, ACK.Remote_I2C_Read.Data_Read) == 3) - 1]; 360 | extern int assertx27[(__builtin_offsetof(Message_Transaction_Reply, ACK.Remote_I2C_Write.end) == 2) - 1]; 361 | extern int assertx28[(__builtin_offsetof(Message_Transaction_Reply, ACK.Power_Up_PHY.end) == 2) - 1]; 362 | extern int assertx29[(__builtin_offsetof(Message_Transaction_Reply, ACK.Power_Down_PHY.end) == 2) - 1]; 363 | extern int assertx30[(__builtin_offsetof(Message_Transaction_Reply, ACK.Query_Stream_Enc_Status.end) == 4) - 1]; 364 | 365 | typedef struct Sideband_MSG1 { 366 | struct Sideband_MSG_Header { 367 | UInt8 Link_Count_Remaining : 4; // LSB init to Link_Count_Total 368 | UInt8 Link_Count_Total : 4; // MSB 369 | 370 | UInt8 Relative_Address[8]; // 16 nibbles nibble[0] is MSB of byte[0] : nibbles = Link_Count_Total 371 | } header; 372 | // Sideband_MSG2 373 | } Sideband_MSG1; 374 | extern int assertx31[(sizeof(Sideband_MSG1) == 9) - 1]; 375 | 376 | typedef union { 377 | Message_Transaction_Request request; 378 | Message_Transaction_Reply reply; 379 | } Sideband_MSG_Body; 380 | 381 | typedef struct Sideband_MSG2 { 382 | struct Sideband_MSG_Header2 { 383 | // byte alligned after Relative_Address 384 | UInt8 Sideband_MSG_Body_Length : 6; // LSB 385 | UInt8 Path_Message : 1; 386 | UInt8 Broadcast_Message : 1; // MSB 387 | 388 | UInt8 Sideband_MSG_Header_CRC : 4; // LSB 389 | UInt8 Message_Sequence_No : 1; // bit(4) 390 | UInt8 zero : 1; // bit(5) 391 | UInt8 End_Of_Message_Transaction : 1; // bit(6) 392 | UInt8 Start_Of_Message_Transaction : 1; // MSB 393 | } header; 394 | 395 | Sideband_MSG_Body body; 396 | // Sideband_MSG3 397 | } Sideband_MSG2; 398 | extern int assertx32[(__builtin_offsetof(Sideband_MSG2, body) == 2) - 1]; 399 | 400 | typedef struct Sideband_MSG3 { 401 | struct Sideband_MSG_Body_2 { 402 | UInt8 Sideband_MSG_Body_CRC; 403 | } body; 404 | UInt8 end[]; 405 | } Sideband_MSG3; 406 | extern int assertx33[(__builtin_offsetof(Sideband_MSG3, end) == 1) - 1]; 407 | 408 | enum { 409 | kReq = (1 << 0), 410 | kRep = (1 << 1), 411 | }; 412 | extern int gDumpSidebandMessage; 413 | 414 | void DumpOneDisplayPortMessage(UInt8 *msgbytes, int msglen, uint32_t dpcdAddress); 415 | void DumpOneDisplayPortMessageBody(void *bodyData, int bodyLength, bool isReply); 416 | 417 | UInt8* mst_get_message_body(Sideband_MSG1 *msg1); 418 | UInt8 mst_get_message_request_identifier(Sideband_MSG1 *msg1); 419 | 420 | UInt8* mst_encode_link_address (UInt8 *inpath, int pathLength, UInt32 *msgLength); 421 | UInt8 *mst_encode_enum_path_resources(UInt8 *inpath, int pathLength, UInt32 *msgLength); 422 | UInt8* mst_encode_dpcd_read (UInt8 *inpath, int pathLength, UInt32 *msgLength, int dpcdAddr, int numBytes); 423 | 424 | IOReturn mst_req_link_address (io_service_t ioFramebufferService, IOI2CConnectRef i2cconnect, UInt8 *inpath, int pathLength, Sideband_MSG_Body **bodyResult, int *bodyLength, DpError *dperr); 425 | IOReturn mst_req_enum_path_resources(io_service_t ioFramebufferService, IOI2CConnectRef i2cconnect, UInt8 *inpath, int pathLength, Sideband_MSG_Body **bodyResult, int *bodyLength, DpError *dperr); 426 | IOReturn mst_req_dpcd_read (io_service_t ioFramebufferService, IOI2CConnectRef i2cconnect, UInt8 *inpath, int pathLength, int dpcdAddr, int dpcdLength, void *dpcdDest , DpError *dperr); 427 | IOReturn mst_transaction (io_service_t ioFramebufferService, IOI2CConnectRef i2cconnect, UInt8 *reqMsgs, int reqMsgsLength, Sideband_MSG_Body **bodyResult, int *bodyLength, DpError *dperr); 428 | 429 | IOReturn dp_dpcd_read (IOI2CConnectRef i2cconnect, int dpcdAddr, int dpcdLength, void *dpcdDest); 430 | IOReturn dp_dpcd_write(IOI2CConnectRef i2cconnect, int dpcdAddr, int dpcdLength, void *dpcdSource); 431 | 432 | #ifdef __cplusplus 433 | } 434 | #endif 435 | 436 | #endif /* mst_h */ 437 | -------------------------------------------------------------------------------- /AllRez/dpcd.h: -------------------------------------------------------------------------------- 1 | // 2 | // dpcd.h 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-02-19. 6 | // 7 | 8 | #ifndef dpcd_h 9 | #define dpcd_h 10 | 11 | extern int dpcdranges[]; 12 | 13 | void parsedpcd(uint8_t *dpcd); 14 | 15 | #endif /* dpcd_h */ 16 | -------------------------------------------------------------------------------- /AllRez/iofbdebuguser.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // iofbdebuguser.cpp 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-05-19. 6 | // 7 | 8 | #include "MacOSMacros.h" 9 | #include "iofbdebuguser.h" 10 | #include 11 | #include 12 | #include "AppleMisc.h" 13 | #include 14 | #include "printf.h" 15 | #ifdef __cplusplus 16 | #include 17 | #endif 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | IOReturn IoFbDoRequest(io_service_t ioFramebufferService, UInt8 *sendBuf, UInt32 sendSize, UInt8 *replyBuf, UInt32 replySize) { 31 | IOReturn result; 32 | IOItemCount i2cInterfaceCount; 33 | result = IOFBGetI2CInterfaceCount(ioFramebufferService, &i2cInterfaceCount); 34 | if (KERN_SUCCESS == result) { 35 | for (int interfaceBus = 0; interfaceBus < i2cInterfaceCount; interfaceBus++) { 36 | io_service_t i2cservice; 37 | result = IOFBCopyI2CInterfaceForBus(ioFramebufferService, interfaceBus, &i2cservice); 38 | if (KERN_SUCCESS == result) { 39 | CFMutableDictionaryRef dict = NULL; 40 | result = IORegistryEntryCreateCFProperties(i2cservice, &dict, kCFAllocatorDefault, kNilOptions); 41 | if (KERN_SUCCESS == result) { 42 | UInt32 val_IOI2CTransactionTypes = 0; 43 | CFTypeRef cf_IOI2CTransactionTypes = CFDictionaryGetValue(dict, CFSTR(kIOI2CTransactionTypesKey)); 44 | if (cf_IOI2CTransactionTypes) { 45 | if (CFGetTypeID(cf_IOI2CTransactionTypes) == CFNumberGetTypeID()) { 46 | if (CFNumberGetValue((CFNumberRef)cf_IOI2CTransactionTypes, kCFNumberSInt32Type, (void*)&val_IOI2CTransactionTypes)) { 47 | 48 | IOI2CConnectRef i2cconnect; 49 | result = IOI2CInterfaceOpen(i2cservice, kNilOptions, &i2cconnect); 50 | if (KERN_SUCCESS == result) { 51 | 52 | if (val_IOI2CTransactionTypes & (1 << kIOI2CSimpleTransactionType)) { 53 | IOI2CRequest_10_6 request; 54 | bzero(&request, sizeof(request)); 55 | request.sendTransactionType = kIOI2CSimpleTransactionType; 56 | request.sendAddress = 0xfb; 57 | request.sendSubAddress = 0xfb; 58 | request.sendBuffer = (vm_address_t)sendBuf; 59 | request.sendBytes = sendSize; 60 | if (replyBuf) { 61 | request.replyTransactionType = kIOI2CSimpleTransactionType; 62 | request.replyAddress = 0xfb; 63 | request.replySubAddress = 0xfb; 64 | request.replyBuffer = (vm_address_t)replyBuf; 65 | request.replyBytes = replySize; 66 | } 67 | result = UniversalI2CSendRequest(i2cconnect, kNilOptions, &request); 68 | if (result == kIOReturnSuccess) { 69 | result = request.result; 70 | } 71 | #if 0 72 | if (result) { 73 | char resultStr[40]; 74 | iprintf("IoFbDoRequest result:%s\n", DumpOneReturn(resultStr, sizeof(resultStr), request.result)); 75 | } 76 | #endif 77 | } // if kIOI2CDisplayPortNativeTransactionType 78 | IOI2CInterfaceClose(i2cconnect, kNilOptions); 79 | } // IOI2CInterfaceOpen 80 | } // if CFNumberGetValue 81 | } // if CFNumberGetTypeID 82 | } // if cf_IOI2CTransactionTypes 83 | } // if IORegistryEntryCreateCFProperties 84 | } // if IOFBCopyI2CInterfaceForBus 85 | } // for iterfaceBus 86 | } // if IOFBGetI2CInterfaceCount 87 | return result; 88 | } // IofbSetAttributeForService 89 | 90 | IOReturn IofbGetService(int displayIndex, io_service_t *ioFramebufferService) { 91 | CGDirectDisplayID onlineDisplays[20]; 92 | uint32_t displayCount; 93 | CGError result = CGGetOnlineDisplayList(20, onlineDisplays, &displayCount); 94 | if (result) 95 | return result; 96 | 97 | if (displayIndex >= displayCount) { 98 | iprintf("displayIndex %d out of range\n", displayIndex); 99 | return kIOReturnBadArgument; 100 | } 101 | 102 | io_service_t ioFramebufferServiceTemp = IO_OBJECT_NULL; 103 | if (!ioFramebufferService) 104 | ioFramebufferService = &ioFramebufferServiceTemp; 105 | 106 | CGDirectDisplayID display = onlineDisplays[displayIndex]; 107 | result = CGSServiceForDisplayNumber(display, ioFramebufferService); 108 | if (result) { 109 | iprintf("Error %x service for displayIndex %d\n", result, displayIndex); 110 | *ioFramebufferService = IO_OBJECT_NULL; 111 | } 112 | return result; 113 | } 114 | 115 | IOReturn IofbSetAttributeForService(io_service_t ioFramebufferService, UInt32 category, UInt32 val1, UInt32 val2, UInt32 val3, UInt32 *valGet) { 116 | UInt32 buffer[] = { category, val1, val2, val3 }; 117 | UInt32 valGet0 = 0; 118 | if (valGet) 119 | valGet0 = *valGet; 120 | IOReturn result = IoFbDoRequest(ioFramebufferService, (UInt8*)buffer, (UInt32)sizeof(buffer), valGet ? (UInt8*)&valGet0 : NULL, valGet ? (UInt32)sizeof(*valGet) : 0); 121 | if (!result && valGet) { 122 | *valGet = valGet0; 123 | } 124 | return result; 125 | } // IofbSetAttributeForService 126 | 127 | IOReturn IofbSetEDIDOverride(UInt8 *orgEDID, UInt32 orgSize, UInt8 *newEDID, UInt32 newSize) { 128 | io_service_t ioFramebufferService = IO_OBJECT_NULL; 129 | IOReturn result = IofbGetService(0, &ioFramebufferService); 130 | if (!result) { 131 | UInt32 bufferSize = (UInt32)sizeof(UInt32) * 5 + orgSize + newSize; 132 | UInt32* buf = (UInt32*)malloc(bufferSize); 133 | if (!buf) return errno; 134 | buf[0] = 'iofb'; 135 | buf[1] = 'edid'; 136 | buf[2] = orgSize; 137 | buf[3] = newSize; 138 | memcpy(&buf[4], orgEDID, orgSize); 139 | memcpy(((UInt8*)(&buf[4])) + orgSize, newEDID, newSize); 140 | result = IoFbDoRequest(ioFramebufferService, (UInt8*)buf, bufferSize, NULL, 0); 141 | } 142 | return result; 143 | } // IofbSetEDIDOverride 144 | 145 | IOReturn IofbGetSetAttributeForDisplay(int displayIndex, UInt32 category, UInt32 val1, UInt32 val2, UInt32 val3, UInt32 *valGet) { 146 | io_service_t ioFramebufferService = IO_OBJECT_NULL; 147 | IOReturn result = IofbGetService(displayIndex, &ioFramebufferService); 148 | if (!result) { 149 | result = IofbSetAttributeForService(ioFramebufferService, category, val1, val2, val3, valGet); 150 | } 151 | return result; 152 | } // IofbGetSetAttributeForDisplay 153 | 154 | IOReturn IofbSetAttributeForDisplay(int displayIndex, UInt32 category, UInt32 val1, UInt32 val2, UInt32 val3) { 155 | return IofbGetSetAttributeForDisplay(displayIndex, category, val1, val2, val3, NULL); 156 | } // IofbSetAttributeForDisplay 157 | 158 | IOReturn IofbGetAttributeForDisplay(int displayIndex, UInt32 category, UInt32 val1, UInt32 val2, UInt32 *valGet) { 159 | if (!valGet) 160 | return kIOReturnBadArgument; 161 | return IofbGetSetAttributeForDisplay(displayIndex, category, val1, val2, kIOFBUnused, valGet); 162 | } // IofbSetAttributeForDisplay 163 | 164 | 165 | void IofbSetDebugEnabled(bool debugEnabled) { 166 | IofbSetAttributeForDisplay(0, 'iofb', 'dbge', debugEnabled, kIOFBUnused); 167 | } // IofbSetDebugEnabled 168 | 169 | bool IofbAvailable(int displayIndex) { 170 | UInt32 iofbtest = 0; 171 | IofbGetAttributeForDisplay(displayIndex, 'iofb', 'iofb', kIOFBUnused, &iofbtest); 172 | return (iofbtest == 'iofb'); 173 | } 174 | 175 | void IofbSetControllerColorModeAndDepth(int displayIndex, UInt32 mode, UInt32 depth) { 176 | // changing color between 422 and RGB causes the screen to black out if the last depth does not match 177 | 178 | UInt32 currentMode; 179 | IofbGetAttributeForDisplay(displayIndex, 'atfc', kIOFBConnectIndex0, kConnectionColorMode, ¤tMode); 180 | UInt32 currentDepth; 181 | IofbGetAttributeForDisplay(displayIndex, 'atfc', kIOFBConnectIndex0, kConnectionControllerColorDepth, ¤tDepth); 182 | 183 | UInt32 tempMode; 184 | switch (mode) { 185 | case kIODisplayColorModeYCbCr422 : 186 | case kIODisplayColorModeYCbCr444 : tempMode = kIODisplayColorModeRGB; break; 187 | default : tempMode = kIODisplayColorModeYCbCr422; break; 188 | } 189 | 190 | IofbSetAttributeForDisplay(displayIndex, 'atfc', kIOFBConnectIndex0, kConnectionControllerColorDepth, depth); 191 | IofbSetAttributeForDisplay(displayIndex, 'atfc', kIOFBConnectIndex0, kConnectionColorMode, tempMode); 192 | IofbSetAttributeForDisplay(displayIndex, 'atfc', kIOFBConnectIndex0, kConnectionControllerColorDepth, depth); 193 | IofbSetAttributeForDisplay(displayIndex, 'atfc', kIOFBConnectIndex0, kConnectionColorMode, mode); 194 | IofbSetAttributeForDisplay(displayIndex, 'atfc', kIOFBConnectIndex0, kConnectionControllerColorDepth, depth); 195 | IofbSetAttributeForDisplay(displayIndex, 'atfc', kIOFBConnectIndex0, kConnectionFlushParameters, true); 196 | } 197 | 198 | void DoAttributeTest(int displayIndex) { 199 | if (IofbAvailable(displayIndex)) { 200 | // works on iMac14,2 (NVIDIA GeForce GTX 780M 4 GB) but not MacPro3,1 (NVIDIA GeForce GTX 680 2 GB). The driver accepts the attributes but doesn't update the display. 201 | IofbSetControllerColorModeAndDepth(displayIndex, kIODisplayColorModeRGB , kIODisplayRGBColorComponentBits10 ); // 30 bpp (default color depth for Nvidia Kepler) 202 | IofbSetControllerColorModeAndDepth(displayIndex, kIODisplayColorModeRGB , kIODisplayRGBColorComponentBits8 ); // 24 bpp 203 | IofbSetControllerColorModeAndDepth(displayIndex, kIODisplayColorModeRGB , kIODisplayRGBColorComponentBits6 ); // 18 bpp (low color depth = banding) 204 | IofbSetControllerColorModeAndDepth(displayIndex, kIODisplayColorModeYCbCr422, kIODisplayYCbCr422ColorComponentBits8); // 16 bpp (4:2:2 chroma subsampling = low horizontal color resolution) 205 | } 206 | else { 207 | iprintf("Iofb is not available.\n"); 208 | } 209 | } // DoAttributeTest 210 | 211 | void DoEDIDOverrideTest() { 212 | UInt8 AcerXV273JleftPartial[] = 213 | { 214 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x04, 0x72, 0xb1, 0x06, 0x53, 0x8f, 0x00, 0x85, 215 | 0x32, 0x1c, 0x01, 0x04, 0xb5, 0x3c, 0x22, 0x78, 0x3b, 0x27, 0x11, 0xac, 0x51, 0x35, 0xb5, 0x26, 216 | 0x0e, 0x50, 0x54, 0x23, 0x48, 0x00, 0x81, 0x40, 0x81, 0x80, 0x81, 0xc0, 0x81, 0x00, 0x95, 0x00, 217 | 0xb3, 0x00, 0xd1, 0xc0, 0x01, 0x01, 0x4d, 0xd0, 0x00, 0xa0, 0xf0, 0x70, 0x3e, 0x80, 0x30, 0x20, 218 | 0x35, 0x00, 0x55, 0x50, 0x21, 0x00, 0x00, 0x1a, 0xb4, 0x66, 0x00, 0xa0, 0xf0, 0x70, 0x1f, 0x80, 219 | 0x08, 0x20, 0x18, 0x04, 0x55, 0x50, 0x21, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0xfd, 0x0c, 0x30, 220 | 0x78, 0xff, 0xff, 0x6b, 0x01, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, 221 | 0x00, 0x58, 0x56, 0x32, 0x37, 0x33, 0x4b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x02, 0x39, 222 | 223 | 0x02, 0x03, 0x48, 0xf1, 0x51, 0x01, 0x03, 0x04, 0x12, 0x13, 0x05, 0x14, 0x1f, 0x90, 0x07, 0x02, 224 | 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x3f, 0x23, 0x09, 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, 0xe2, 0x00, 225 | 0xc0, 0x6d, 0x03, 0x0c, 0x00, 0x10, 0x00, 0x38, 0x78, 0x20, 0x00, 0x60, 0x01, 0x02, 0x03, 0x68, 226 | 0x1a, 0x00, 0x00, 0x01, 0x01, 0x30, 0x78, 0x00, 0xe3, 0x05, 0xe3, 0x01, 0xe4, 0x0f, 0x00, 0xc0, 227 | 0x00, 0xe6, 0x06, 0x07, 0x01, 0x61, 0x56, 0x1c, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 228 | 0x58, 0x2c, 0x45, 0x00, 0x55, 0x50, 0x21, 0x00, 0x00, 0x1e, 0x01, 0x1d, 0x00, 0x72, 0x51, 0xd0, 229 | 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, 0x55, 0x50, 0x21, 0x00, 0x00, 0x1e, 0x6f, 0xc2, 0x00, 0xa0, 230 | 0xa0, 0xa0, 0x55, 0x50, 0x30, 0x20, 0x35, 0x00, 0x55, 0x50, 0x21, 0x00, 0x00, 0x1e, 0x00, 0x51, 231 | }; 232 | 233 | UInt8 AcerXV273JrightPartial[] = 234 | { 235 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x04, 0x72, 0xb1, 0x06, 0x53, 0x8f, 0x00, 0x85, 236 | 0x32, 0x1c, 0x01, 0x04, 0xb5, 0x3c, 0x22, 0x78, 0x3b, 0x27, 0x11, 0xac, 0x51, 0x35, 0xb5, 0x26, 237 | 0x0e, 0x50, 0x54, 0x23, 0x48, 0x00, 0x81, 0x40, 0x81, 0x80, 0x81, 0xc0, 0x81, 0x00, 0x95, 0x00, 238 | 0xb3, 0x00, 0xd1, 0xc0, 0x01, 0x01, 0x4d, 0xd0, 0x00, 0xa0, 0xf0, 0x70, 0x3e, 0x80, 0x30, 0x20, 239 | 0x35, 0x00, 0x55, 0x50, 0x21, 0x00, 0x00, 0x1a, 0xb4, 0x66, 0x00, 0xa0, 0xf0, 0x70, 0x1f, 0x80, 240 | 0x08, 0x20, 0x18, 0x04, 0x55, 0x50, 0x21, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0xfd, 0x0c, 0x30, 241 | 0x78, 0xff, 0xff, 0x6b, 0x01, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc, 242 | 0x00, 0x58, 0x56, 0x32, 0x37, 0x33, 0x4b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x02, 0x39, 243 | 244 | 0x02, 0x03, 0x48, 0xf1, 0x51, 0x01, 0x03, 0x04, 0x12, 0x13, 0x05, 0x14, 0x1f, 0x90, 0x07, 0x02, 245 | 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x3f, 0x23, 0x09, 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, 0xe2, 0x00, 246 | 0xc0, 0x6d, 0x03, 0x0c, 0x00, 0x20, 0x00, 0x38, 0x78, 0x20, 0x00, 0x60, 0x01, 0x02, 0x03, 0x68, 247 | 0x1a, 0x00, 0x00, 0x01, 0x01, 0x30, 0x78, 0x00, 0xe3, 0x05, 0xe3, 0x01, 0xe4, 0x0f, 0x00, 0xc8, 248 | 0x00, 0xe6, 0x06, 0x07, 0x01, 0x61, 0x56, 0x1c, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 249 | 0x58, 0x2c, 0x45, 0x00, 0x55, 0x50, 0x21, 0x00, 0x00, 0x1e, 0x01, 0x1d, 0x00, 0x72, 0x51, 0xd0, 250 | 0x1e, 0x20, 0x6e, 0x28, 0x55, 0x00, 0x55, 0x50, 0x21, 0x00, 0x00, 0x1e, 0x6f, 0xc2, 0x00, 0xa0, 251 | 0xa0, 0xa0, 0x55, 0x50, 0x30, 0x20, 0x35, 0x00, 0x55, 0x50, 0x21, 0x00, 0x00, 0x1e, 0x00, 0x39, 252 | }; 253 | 254 | UInt8 DellUP3218Kleft[] = { 255 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x10, 0xac, 0x47, 0x41, 0x4c, 0x34, 0x32, 0x30, 256 | 0x27, 0x1c, 0x01, 0x04, 0xb5, 0x46, 0x27, 0x78, 0x3a, 0x76, 0x45, 0xae, 0x51, 0x33, 0xba, 0x26, 257 | 0x0d, 0x50, 0x54, 0xa5, 0x4b, 0x00, 0x81, 0x00, 0xb3, 0x00, 0xd1, 0x00, 0xa9, 0x40, 0x81, 0x80, 258 | 0xd1, 0xc0, 0x01, 0x01, 0x01, 0x01, 0x4d, 0xd0, 0x00, 0xa0, 0xf0, 0x70, 0x3e, 0x80, 0x30, 0x20, 259 | 0x35, 0x00, 0xba, 0x89, 0x21, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0xff, 0x00, 0x46, 0x46, 0x4e, 260 | 0x58, 0x4d, 0x38, 0x39, 0x50, 0x30, 0x32, 0x34, 0x4c, 0x0a, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x44, 261 | 0x45, 0x4c, 0x4c, 0x20, 0x55, 0x50, 0x33, 0x32, 0x31, 0x38, 0x4b, 0x0a, 0x00, 0x00, 0x00, 0xfd, 262 | 0x00, 0x18, 0x4b, 0x1e, 0xb4, 0x6c, 0x01, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x02, 0x59, 263 | 264 | 0x02, 0x03, 0x1d, 0xf1, 0x50, 0x10, 0x1f, 0x20, 0x05, 0x14, 0x04, 0x13, 0x12, 0x11, 0x03, 0x02, 265 | 0x16, 0x15, 0x07, 0x06, 0x01, 0x23, 0x09, 0x1f, 0x07, 0x83, 0x01, 0x00, 0x00, 0xa3, 0x66, 0x00, 266 | 0xa0, 0xf0, 0x70, 0x1f, 0x80, 0x30, 0x20, 0x35, 0x00, 0xba, 0x89, 0x21, 0x00, 0x00, 0x1a, 0x56, 267 | 0x5e, 0x00, 0xa0, 0xa0, 0xa0, 0x29, 0x50, 0x30, 0x20, 0x35, 0x00, 0xba, 0x89, 0x21, 0x00, 0x00, 268 | 0x1a, 0x7c, 0x39, 0x00, 0xa0, 0x80, 0x38, 0x1f, 0x40, 0x30, 0x20, 0x3a, 0x00, 0xba, 0x89, 0x21, 269 | 0x00, 0x00, 0x1a, 0xa8, 0x16, 0x00, 0xa0, 0x80, 0x38, 0x13, 0x40, 0x30, 0x20, 0x3a, 0x00, 0xba, 270 | 0x89, 0x21, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 271 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 272 | 273 | 0x70, 0x12, 0x79, 0x00, 0x00, 0x12, 0x00, 0x16, 0x82, 0x10, 0x00, 0x00, 0xff, 0x0e, 0xdf, 0x10, 274 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x45, 0x4c, 0x47, 0x41, 0x4c, 0x34, 0x32, 0x30, 0x03, 0x01, 275 | 0x50, 0x70, 0x92, 0x01, 0x84, 0xff, 0x1d, 0xc7, 0x00, 0x1d, 0x80, 0x09, 0x00, 0xdf, 0x10, 0x2f, 276 | 0x00, 0x02, 0x00, 0x04, 0x00, 0xc1, 0x42, 0x01, 0x84, 0xff, 0x1d, 0xc7, 0x00, 0x2f, 0x80, 0x1f, 277 | 0x00, 0xdf, 0x10, 0x30, 0x00, 0x02, 0x00, 0x04, 0x00, 0xa8, 0x4e, 0x01, 0x04, 0xff, 0x0e, 0xc7, 278 | 0x00, 0x2f, 0x80, 0x1f, 0x00, 0xdf, 0x10, 0x61, 0x00, 0x02, 0x00, 0x09, 0x00, 0x97, 0x9d, 0x01, 279 | 0x04, 0xff, 0x0e, 0xc7, 0x00, 0x2f, 0x80, 0x1f, 0x00, 0xdf, 0x10, 0x2f, 0x00, 0x02, 0x00, 0x09, 280 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9e, 0x90, 281 | }; 282 | 283 | UInt8 DellUP3218Kright[] = { 284 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x10, 0xac, 0x47, 0x41, 0x4c, 0x34, 0x32, 0x30, 285 | 0x27, 0x1c, 0x01, 0x04, 0xb5, 0x46, 0x27, 0x78, 0x3a, 0x76, 0x45, 0xae, 0x51, 0x33, 0xba, 0x26, 286 | 0x0d, 0x50, 0x54, 0xa5, 0x4b, 0x00, 0x81, 0x00, 0xb3, 0x00, 0xd1, 0x00, 0xa9, 0x40, 0x81, 0x80, 287 | 0xd1, 0xc0, 0x01, 0x01, 0x01, 0x01, 0x4d, 0xd0, 0x00, 0xa0, 0xf0, 0x70, 0x3e, 0x80, 0x30, 0x20, 288 | 0x35, 0x00, 0xba, 0x89, 0x21, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0xff, 0x00, 0x46, 0x46, 0x4e, 289 | 0x58, 0x4d, 0x38, 0x39, 0x50, 0x30, 0x32, 0x34, 0x4c, 0x0a, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x44, 290 | 0x45, 0x4c, 0x4c, 0x20, 0x55, 0x50, 0x33, 0x32, 0x31, 0x38, 0x4b, 0x0a, 0x00, 0x00, 0x00, 0xfd, 291 | 0x00, 0x18, 0x4b, 0x1e, 0xb4, 0x6c, 0x01, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x02, 0x59, 292 | 293 | 0x02, 0x03, 0x1d, 0xf1, 0x50, 0x10, 0x1f, 0x20, 0x05, 0x14, 0x04, 0x13, 0x12, 0x11, 0x03, 0x02, 294 | 0x16, 0x15, 0x07, 0x06, 0x01, 0x23, 0x09, 0x1f, 0x07, 0x83, 0x01, 0x00, 0x00, 0xa3, 0x66, 0x00, 295 | 0xa0, 0xf0, 0x70, 0x1f, 0x80, 0x30, 0x20, 0x35, 0x00, 0xba, 0x89, 0x21, 0x00, 0x00, 0x1a, 0x56, 296 | 0x5e, 0x00, 0xa0, 0xa0, 0xa0, 0x29, 0x50, 0x30, 0x20, 0x35, 0x00, 0xba, 0x89, 0x21, 0x00, 0x00, 297 | 0x1a, 0x7c, 0x39, 0x00, 0xa0, 0x80, 0x38, 0x1f, 0x40, 0x30, 0x20, 0x3a, 0x00, 0xba, 0x89, 0x21, 298 | 0x00, 0x00, 0x1a, 0xa8, 0x16, 0x00, 0xa0, 0x80, 0x38, 0x13, 0x40, 0x30, 0x20, 0x3a, 0x00, 0xba, 299 | 0x89, 0x21, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 300 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 301 | 302 | 0x70, 0x12, 0x79, 0x00, 0x00, 0x12, 0x00, 0x16, 0x82, 0x10, 0x10, 0x00, 0xff, 0x0e, 0xdf, 0x10, 303 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x45, 0x4c, 0x47, 0x41, 0x4c, 0x34, 0x32, 0x30, 0x03, 0x01, 304 | 0x50, 0x70, 0x92, 0x01, 0x84, 0xff, 0x1d, 0xc7, 0x00, 0x1d, 0x80, 0x09, 0x00, 0xdf, 0x10, 0x2f, 305 | 0x00, 0x02, 0x00, 0x04, 0x00, 0xc1, 0x42, 0x01, 0x84, 0xff, 0x1d, 0xc7, 0x00, 0x2f, 0x80, 0x1f, 306 | 0x00, 0xdf, 0x10, 0x30, 0x00, 0x02, 0x00, 0x04, 0x00, 0xa8, 0x4e, 0x01, 0x04, 0xff, 0x0e, 0xc7, 307 | 0x00, 0x2f, 0x80, 0x1f, 0x00, 0xdf, 0x10, 0x61, 0x00, 0x02, 0x00, 0x09, 0x00, 0x97, 0x9d, 0x01, 308 | 0x04, 0xff, 0x0e, 0xc7, 0x00, 0x2f, 0x80, 0x1f, 0x00, 0xdf, 0x10, 0x2f, 0x00, 0x02, 0x00, 0x09, 309 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x90, 310 | }; 311 | 312 | if (IofbAvailable(0)) { 313 | IofbSetEDIDOverride(AcerXV273JleftPartial, (UInt32)sizeof(AcerXV273JleftPartial), DellUP3218Kleft, (UInt32)sizeof(DellUP3218Kleft)); 314 | IofbSetEDIDOverride(AcerXV273JrightPartial, (UInt32)sizeof(AcerXV273JrightPartial), DellUP3218Kright, (UInt32)sizeof(DellUP3218Kright)); 315 | } 316 | else { 317 | iprintf("Iofb is not available.\n"); 318 | } 319 | } 320 | -------------------------------------------------------------------------------- /AllRez/iofbdebuguser.h: -------------------------------------------------------------------------------- 1 | // 2 | // iofbdebuguser.hpp 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-05-19. 6 | // 7 | 8 | #ifndef iofbdebuguser_hpp 9 | #define iofbdebuguser_hpp 10 | 11 | #include 12 | 13 | enum { 14 | kIOFBUnused = 0, 15 | 16 | kIOFBDontOverride = 0, 17 | 18 | kIOFBAll = -1, 19 | 20 | kIOFBConnectIndex0 = 0, 21 | kIOFBConnectIndex1 = 1, 22 | }; 23 | 24 | bool IofbAvailable(int displayIndex); 25 | 26 | IOReturn IofbSetAttributeForService(io_service_t ioFramebufferService, UInt32 category, UInt32 val1, UInt32 val2, UInt32 val3, UInt32 *valGet); 27 | 28 | IOReturn IofbGetSetAttributeForDisplay(int displayIndex, UInt32 category, UInt32 val1, UInt32 val2, UInt32 val3, UInt32 *valGet); 29 | 30 | IOReturn IofbSetAttributeForDisplay(int displayIndex, UInt32 category, UInt32 val1, UInt32 val2, UInt32 val3); 31 | 32 | IOReturn IofbGetAttributeForDisplay(int displayIndex, UInt32 category, UInt32 val1, UInt32 val2, UInt32 *valGet); 33 | 34 | 35 | void SetIofbDebugEnabled(bool debugEnabled); 36 | 37 | void DoAttributeTest(int displayIndex); 38 | 39 | void DoEDIDOverrideTest(void); 40 | 41 | #endif /* iofbdebuguser_hpp */ 42 | -------------------------------------------------------------------------------- /AllRez/linux/drivers/gpu/drm/amd/display/dc/dc_ddc_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-15 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * Authors: AMD 23 | * 24 | */ 25 | #ifndef DC_DDC_TYPES_H_ 26 | #define DC_DDC_TYPES_H_ 27 | 28 | enum aux_transaction_type { 29 | AUX_TRANSACTION_TYPE_DP, 30 | AUX_TRANSACTION_TYPE_I2C 31 | }; 32 | 33 | 34 | enum i2caux_transaction_action { 35 | I2CAUX_TRANSACTION_ACTION_I2C_WRITE = 0x00, 36 | I2CAUX_TRANSACTION_ACTION_I2C_READ = 0x10, 37 | I2CAUX_TRANSACTION_ACTION_I2C_STATUS_REQUEST = 0x20, 38 | 39 | I2CAUX_TRANSACTION_ACTION_I2C_WRITE_MOT = 0x40, 40 | I2CAUX_TRANSACTION_ACTION_I2C_READ_MOT = 0x50, 41 | I2CAUX_TRANSACTION_ACTION_I2C_STATUS_REQUEST_MOT = 0x60, 42 | 43 | I2CAUX_TRANSACTION_ACTION_DP_WRITE = 0x80, 44 | I2CAUX_TRANSACTION_ACTION_DP_READ = 0x90 45 | }; 46 | 47 | struct aux_request_transaction_data { 48 | enum aux_transaction_type type; 49 | enum i2caux_transaction_action action; 50 | /* 20-bit AUX channel transaction address */ 51 | uint32_t address; 52 | /* delay, in 100-microsecond units */ 53 | uint8_t delay; 54 | uint32_t length; 55 | uint8_t *data; 56 | }; 57 | 58 | enum aux_transaction_reply { 59 | AUX_TRANSACTION_REPLY_AUX_ACK = 0x00, 60 | AUX_TRANSACTION_REPLY_AUX_NACK = 0x01, 61 | AUX_TRANSACTION_REPLY_AUX_DEFER = 0x02, 62 | AUX_TRANSACTION_REPLY_I2C_OVER_AUX_NACK = 0x04, 63 | AUX_TRANSACTION_REPLY_I2C_OVER_AUX_DEFER = 0x08, 64 | 65 | AUX_TRANSACTION_REPLY_I2C_ACK = 0x00, 66 | AUX_TRANSACTION_REPLY_I2C_NACK = 0x10, 67 | AUX_TRANSACTION_REPLY_I2C_DEFER = 0x20, 68 | 69 | AUX_TRANSACTION_REPLY_HPD_DISCON = 0x40, 70 | 71 | AUX_TRANSACTION_REPLY_INVALID = 0xFF 72 | }; 73 | 74 | struct aux_reply_transaction_data { 75 | enum aux_transaction_reply status; 76 | uint32_t length; 77 | uint8_t *data; 78 | }; 79 | 80 | struct aux_payload { 81 | /* set following flag to read/write I2C data, 82 | * reset it to read/write DPCD data */ 83 | bool i2c_over_aux; 84 | /* set following flag to write data, 85 | * reset it to read data */ 86 | bool write; 87 | bool mot; 88 | bool write_status_update; 89 | 90 | uint32_t address; 91 | uint32_t length; 92 | uint8_t *data; 93 | /* 94 | * used to return the reply type of the transaction 95 | * ignored if NULL 96 | */ 97 | uint8_t *reply; 98 | /* expressed in milliseconds 99 | * zero means "use default value" 100 | */ 101 | uint32_t defer_delay; 102 | 103 | }; 104 | #define DEFAULT_AUX_MAX_DATA_SIZE 16 105 | 106 | struct i2c_payload { 107 | bool write; 108 | uint8_t address; 109 | uint32_t length; 110 | uint8_t *data; 111 | }; 112 | 113 | enum i2c_command_engine { 114 | I2C_COMMAND_ENGINE_DEFAULT, 115 | I2C_COMMAND_ENGINE_SW, 116 | I2C_COMMAND_ENGINE_HW 117 | }; 118 | 119 | #define DDC_I2C_COMMAND_ENGINE I2C_COMMAND_ENGINE_SW 120 | 121 | struct i2c_command { 122 | struct i2c_payload *payloads; 123 | uint8_t number_of_payloads; 124 | 125 | enum i2c_command_engine engine; 126 | 127 | /* expressed in KHz 128 | * zero means "use default value" */ 129 | uint32_t speed; 130 | }; 131 | 132 | struct gpio_ddc_hw_info { 133 | bool hw_supported; 134 | uint32_t ddc_channel; 135 | }; 136 | 137 | struct ddc { 138 | struct gpio *pin_data; 139 | struct gpio *pin_clock; 140 | struct gpio_ddc_hw_info hw_info; 141 | struct dc_context *ctx; 142 | }; 143 | 144 | union ddc_wa { 145 | struct { 146 | uint32_t DP_SKIP_POWER_OFF:1; 147 | uint32_t DP_AUX_POWER_UP_WA_DELAY:1; 148 | } bits; 149 | uint32_t raw; 150 | }; 151 | 152 | struct ddc_flags { 153 | uint8_t EDID_QUERY_DONE_ONCE:1; 154 | uint8_t IS_INTERNAL_DISPLAY:1; 155 | uint8_t FORCE_READ_REPEATED_START:1; 156 | uint8_t EDID_STRESS_READ:1; 157 | 158 | }; 159 | 160 | enum ddc_transaction_type { 161 | DDC_TRANSACTION_TYPE_NONE = 0, 162 | DDC_TRANSACTION_TYPE_I2C, 163 | DDC_TRANSACTION_TYPE_I2C_OVER_AUX, 164 | DDC_TRANSACTION_TYPE_I2C_OVER_AUX_WITH_DEFER, 165 | DDC_TRANSACTION_TYPE_I2C_OVER_AUX_RETRY_DEFER 166 | }; 167 | 168 | enum display_dongle_type { 169 | DISPLAY_DONGLE_NONE = 0, 170 | /* Active converter types*/ 171 | DISPLAY_DONGLE_DP_VGA_CONVERTER, 172 | DISPLAY_DONGLE_DP_DVI_CONVERTER, 173 | DISPLAY_DONGLE_DP_HDMI_CONVERTER, 174 | /* DP-HDMI/DVI passive dongles (Type 1 and Type 2)*/ 175 | DISPLAY_DONGLE_DP_DVI_DONGLE, 176 | DISPLAY_DONGLE_DP_HDMI_DONGLE, 177 | /* Other types of dongle*/ 178 | DISPLAY_DONGLE_DP_HDMI_MISMATCHED_DONGLE, 179 | }; 180 | 181 | #define DC_MAX_EDID_BUFFER_SIZE 2048 182 | #define DC_EDID_BLOCK_SIZE 128 183 | 184 | struct ddc_service { 185 | struct ddc *ddc_pin; 186 | struct ddc_flags flags; 187 | union ddc_wa wa; 188 | enum ddc_transaction_type transaction_type; 189 | enum display_dongle_type dongle_type; 190 | struct dc_context *ctx; 191 | struct dc_link *link; 192 | 193 | uint32_t address; 194 | uint32_t edid_buf_len; 195 | uint8_t edid_buf[DC_MAX_EDID_BUFFER_SIZE]; 196 | }; 197 | 198 | #endif /* DC_DDC_TYPES_H_ */ 199 | -------------------------------------------------------------------------------- /AllRez/linux/drivers/gpu/drm/amd/display/dc/os_types.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joevt/AllRez/433f3513225199f44e0e6bc90294b2be8df6b9a8/AllRez/linux/drivers/gpu/drm/amd/display/dc/os_types.h -------------------------------------------------------------------------------- /AllRez/linux/drivers/gpu/drm/amd/display/include/dpcd_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-15 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * Authors: AMD 23 | * 24 | */ 25 | 26 | #ifndef __DAL_DPCD_DEFS_H__ 27 | #define __DAL_DPCD_DEFS_H__ 28 | 29 | #include 30 | #ifndef DP_SINK_HW_REVISION_START // can remove this once the define gets into linux drm_dp_helper.h 31 | #define DP_SINK_HW_REVISION_START 0x409 32 | #endif 33 | 34 | enum dpcd_revision { 35 | DPCD_REV_10 = 0x10, 36 | DPCD_REV_11 = 0x11, 37 | DPCD_REV_12 = 0x12, 38 | DPCD_REV_13 = 0x13, 39 | DPCD_REV_14 = 0x14 40 | }; 41 | 42 | /* these are the types stored at DOWNSTREAMPORT_PRESENT */ 43 | enum dpcd_downstream_port_type { 44 | DOWNSTREAM_DP = 0, 45 | DOWNSTREAM_VGA, 46 | DOWNSTREAM_DVI_HDMI_DP_PLUS_PLUS,/* DVI, HDMI, DP++ */ 47 | DOWNSTREAM_NONDDC /* has no EDID (TV,CV) */ 48 | }; 49 | 50 | enum dpcd_link_test_patterns { 51 | LINK_TEST_PATTERN_NONE = 0, 52 | LINK_TEST_PATTERN_COLOR_RAMP, 53 | LINK_TEST_PATTERN_VERTICAL_BARS, 54 | LINK_TEST_PATTERN_COLOR_SQUARES 55 | }; 56 | 57 | enum dpcd_test_color_format { 58 | TEST_COLOR_FORMAT_RGB = 0, 59 | TEST_COLOR_FORMAT_YCBCR422, 60 | TEST_COLOR_FORMAT_YCBCR444 61 | }; 62 | 63 | enum dpcd_test_bit_depth { 64 | TEST_BIT_DEPTH_6 = 0, 65 | TEST_BIT_DEPTH_8, 66 | TEST_BIT_DEPTH_10, 67 | TEST_BIT_DEPTH_12, 68 | TEST_BIT_DEPTH_16 69 | }; 70 | 71 | /* PHY (encoder) test patterns 72 | The order of test patterns follows DPCD register PHY_TEST_PATTERN (0x248) 73 | */ 74 | enum dpcd_phy_test_patterns { 75 | PHY_TEST_PATTERN_NONE = 0, 76 | PHY_TEST_PATTERN_D10_2, 77 | PHY_TEST_PATTERN_SYMBOL_ERROR, 78 | PHY_TEST_PATTERN_PRBS7, 79 | PHY_TEST_PATTERN_80BIT_CUSTOM,/* For DP1.2 only */ 80 | PHY_TEST_PATTERN_CP2520_1, 81 | PHY_TEST_PATTERN_CP2520_2, 82 | PHY_TEST_PATTERN_CP2520_3, /* same as TPS4 */ 83 | PHY_TEST_PATTERN_128b_132b_TPS1 = 0x8, 84 | PHY_TEST_PATTERN_128b_132b_TPS2 = 0x10, 85 | PHY_TEST_PATTERN_PRBS9 = 0x18, 86 | PHY_TEST_PATTERN_PRBS11 = 0x20, 87 | PHY_TEST_PATTERN_PRBS15 = 0x28, 88 | PHY_TEST_PATTERN_PRBS23 = 0x30, 89 | PHY_TEST_PATTERN_PRBS31 = 0x38, 90 | PHY_TEST_PATTERN_264BIT_CUSTOM = 0x40, 91 | PHY_TEST_PATTERN_SQUARE = 0x48, 92 | PHY_TEST_PATTERN_SQUARE_PRESHOOT_DISABLED = 0x49, 93 | PHY_TEST_PATTERN_SQUARE_DEEMPHASIS_DISABLED = 0x4A, 94 | PHY_TEST_PATTERN_SQUARE_PRESHOOT_DEEMPHASIS_DISABLED = 0x4B, 95 | }; 96 | 97 | enum dpcd_test_dyn_range { 98 | TEST_DYN_RANGE_VESA = 0, 99 | TEST_DYN_RANGE_CEA 100 | }; 101 | 102 | enum dpcd_audio_test_pattern { 103 | AUDIO_TEST_PATTERN_OPERATOR_DEFINED = 0,/* direct HW translation */ 104 | AUDIO_TEST_PATTERN_SAWTOOTH 105 | }; 106 | 107 | enum dpcd_audio_sampling_rate { 108 | AUDIO_SAMPLING_RATE_32KHZ = 0,/* direct HW translation */ 109 | AUDIO_SAMPLING_RATE_44_1KHZ, 110 | AUDIO_SAMPLING_RATE_48KHZ, 111 | AUDIO_SAMPLING_RATE_88_2KHZ, 112 | AUDIO_SAMPLING_RATE_96KHZ, 113 | AUDIO_SAMPLING_RATE_176_4KHZ, 114 | AUDIO_SAMPLING_RATE_192KHZ 115 | }; 116 | 117 | enum dpcd_audio_channels { 118 | AUDIO_CHANNELS_1 = 0,/* direct HW translation */ 119 | AUDIO_CHANNELS_2, 120 | AUDIO_CHANNELS_3, 121 | AUDIO_CHANNELS_4, 122 | AUDIO_CHANNELS_5, 123 | AUDIO_CHANNELS_6, 124 | AUDIO_CHANNELS_7, 125 | AUDIO_CHANNELS_8, 126 | 127 | AUDIO_CHANNELS_COUNT 128 | }; 129 | 130 | enum dpcd_audio_test_pattern_periods { 131 | DPCD_AUDIO_TEST_PATTERN_PERIOD_NOTUSED = 0,/* direct HW translation */ 132 | DPCD_AUDIO_TEST_PATTERN_PERIOD_3, 133 | DPCD_AUDIO_TEST_PATTERN_PERIOD_6, 134 | DPCD_AUDIO_TEST_PATTERN_PERIOD_12, 135 | DPCD_AUDIO_TEST_PATTERN_PERIOD_24, 136 | DPCD_AUDIO_TEST_PATTERN_PERIOD_48, 137 | DPCD_AUDIO_TEST_PATTERN_PERIOD_96, 138 | DPCD_AUDIO_TEST_PATTERN_PERIOD_192, 139 | DPCD_AUDIO_TEST_PATTERN_PERIOD_384, 140 | DPCD_AUDIO_TEST_PATTERN_PERIOD_768, 141 | DPCD_AUDIO_TEST_PATTERN_PERIOD_1536 142 | }; 143 | 144 | /* This enum is for programming DPCD TRAINING_PATTERN_SET */ 145 | enum dpcd_training_patterns { 146 | DPCD_TRAINING_PATTERN_VIDEOIDLE = 0,/* direct HW translation! */ 147 | DPCD_TRAINING_PATTERN_1, 148 | DPCD_TRAINING_PATTERN_2, 149 | DPCD_TRAINING_PATTERN_3, 150 | DPCD_TRAINING_PATTERN_4 = 7, 151 | DPCD_128b_132b_TPS1 = 1, 152 | DPCD_128b_132b_TPS2 = 2, 153 | DPCD_128b_132b_TPS2_CDS = 3, 154 | }; 155 | 156 | /* This enum is for use with PsrSinkPsrStatus.bits.sinkSelfRefreshStatus 157 | It defines the possible PSR states. */ 158 | enum dpcd_psr_sink_states { 159 | PSR_SINK_STATE_INACTIVE = 0, 160 | PSR_SINK_STATE_ACTIVE_CAPTURE_DISPLAY_ON_SOURCE_TIMING = 1, 161 | PSR_SINK_STATE_ACTIVE_DISPLAY_FROM_SINK_RFB = 2, 162 | PSR_SINK_STATE_ACTIVE_CAPTURE_DISPLAY_ON_SINK_TIMING = 3, 163 | PSR_SINK_STATE_ACTIVE_CAPTURE_TIMING_RESYNC = 4, 164 | PSR_SINK_STATE_SINK_INTERNAL_ERROR = 7, 165 | }; 166 | 167 | #define DP_SOURCE_SEQUENCE 0x30c 168 | #define DP_SOURCE_TABLE_REVISION 0x310 169 | #define DP_SOURCE_PAYLOAD_SIZE 0x311 170 | #define DP_SOURCE_SINK_CAP 0x317 171 | #define DP_SOURCE_BACKLIGHT_LEVEL 0x320 172 | #define DP_SOURCE_BACKLIGHT_CURRENT_PEAK 0x326 173 | #define DP_SOURCE_BACKLIGHT_CONTROL 0x32E 174 | #define DP_SOURCE_BACKLIGHT_ENABLE 0x32F 175 | #define DP_SOURCE_MINIMUM_HBLANK_SUPPORTED 0x340 176 | 177 | #endif /* __DAL_DPCD_DEFS_H__ */ 178 | -------------------------------------------------------------------------------- /AllRez/linux/include/drm/display/drm_hdcp.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Copyright (C) 2017 Google, Inc. 4 | * 5 | * Authors: 6 | * Sean Paul 7 | */ 8 | 9 | #ifndef _DRM_HDCP_H_ 10 | #define _DRM_HDCP_H_ 11 | 12 | #include 13 | 14 | /* Period of hdcp checks (to ensure we're still authenticated) */ 15 | #define DRM_HDCP_CHECK_PERIOD_MS (128 * 16) 16 | #define DRM_HDCP2_CHECK_PERIOD_MS 500 17 | 18 | /* Shared lengths/masks between HDMI/DVI/DisplayPort */ 19 | #define DRM_HDCP_AN_LEN 8 20 | #define DRM_HDCP_BSTATUS_LEN 2 21 | #define DRM_HDCP_KSV_LEN 5 22 | #define DRM_HDCP_RI_LEN 2 23 | #define DRM_HDCP_V_PRIME_PART_LEN 4 24 | #define DRM_HDCP_V_PRIME_NUM_PARTS 5 25 | #define DRM_HDCP_NUM_DOWNSTREAM(x) (x & 0x7f) 26 | #define DRM_HDCP_MAX_CASCADE_EXCEEDED(x) (x & BIT(3)) 27 | #define DRM_HDCP_MAX_DEVICE_EXCEEDED(x) (x & BIT(7)) 28 | 29 | /* Slave address for the HDCP registers in the receiver */ 30 | #define DRM_HDCP_DDC_ADDR 0x3A 31 | 32 | /* Value to use at the end of the SHA-1 bytestream used for repeaters */ 33 | #define DRM_HDCP_SHA1_TERMINATOR 0x80 34 | 35 | /* HDCP register offsets for HDMI/DVI devices */ 36 | #define DRM_HDCP_DDC_BKSV 0x00 37 | #define DRM_HDCP_DDC_RI_PRIME 0x08 38 | #define DRM_HDCP_DDC_AKSV 0x10 39 | #define DRM_HDCP_DDC_AN 0x18 40 | #define DRM_HDCP_DDC_V_PRIME(h) (0x20 + h * 4) 41 | #define DRM_HDCP_DDC_BCAPS 0x40 42 | #define DRM_HDCP_DDC_BCAPS_REPEATER_PRESENT BIT(6) 43 | #define DRM_HDCP_DDC_BCAPS_KSV_FIFO_READY BIT(5) 44 | #define DRM_HDCP_DDC_BSTATUS 0x41 45 | #define DRM_HDCP_DDC_KSV_FIFO 0x43 46 | 47 | #define DRM_HDCP_1_4_SRM_ID 0x8 48 | #define DRM_HDCP_1_4_VRL_LENGTH_SIZE 3 49 | #define DRM_HDCP_1_4_DCP_SIG_SIZE 40 50 | 51 | /* Protocol message definition for HDCP2.2 specification */ 52 | /* 53 | * Protected content streams are classified into 2 types: 54 | * - Type0: Can be transmitted with HDCP 1.4+ 55 | * - Type1: Can be transmitted with HDCP 2.2+ 56 | */ 57 | #define HDCP_STREAM_TYPE0 0x00 58 | #define HDCP_STREAM_TYPE1 0x01 59 | 60 | /* HDCP2.2 Msg IDs */ 61 | #define HDCP_2_2_NULL_MSG 1 62 | #define HDCP_2_2_AKE_INIT 2 63 | #define HDCP_2_2_AKE_SEND_CERT 3 64 | #define HDCP_2_2_AKE_NO_STORED_KM 4 65 | #define HDCP_2_2_AKE_STORED_KM 5 66 | #define HDCP_2_2_AKE_SEND_HPRIME 7 67 | #define HDCP_2_2_AKE_SEND_PAIRING_INFO 8 68 | #define HDCP_2_2_LC_INIT 9 69 | #define HDCP_2_2_LC_SEND_LPRIME 10 70 | #define HDCP_2_2_SKE_SEND_EKS 11 71 | #define HDCP_2_2_REP_SEND_RECVID_LIST 12 72 | #define HDCP_2_2_REP_SEND_ACK 15 73 | #define HDCP_2_2_REP_STREAM_MANAGE 16 74 | #define HDCP_2_2_REP_STREAM_READY 17 75 | 76 | #define HDCP_2_2_RTX_LEN 8 77 | #define HDCP_2_2_RRX_LEN 8 78 | 79 | #define HDCP_2_2_K_PUB_RX_MOD_N_LEN 128 80 | #define HDCP_2_2_K_PUB_RX_EXP_E_LEN 3 81 | #define HDCP_2_2_K_PUB_RX_LEN (HDCP_2_2_K_PUB_RX_MOD_N_LEN + \ 82 | HDCP_2_2_K_PUB_RX_EXP_E_LEN) 83 | 84 | #define HDCP_2_2_DCP_LLC_SIG_LEN 384 85 | 86 | #define HDCP_2_2_E_KPUB_KM_LEN 128 87 | #define HDCP_2_2_E_KH_KM_M_LEN (16 + 16) 88 | #define HDCP_2_2_H_PRIME_LEN 32 89 | #define HDCP_2_2_E_KH_KM_LEN 16 90 | #define HDCP_2_2_RN_LEN 8 91 | #define HDCP_2_2_L_PRIME_LEN 32 92 | #define HDCP_2_2_E_DKEY_KS_LEN 16 93 | #define HDCP_2_2_RIV_LEN 8 94 | #define HDCP_2_2_SEQ_NUM_LEN 3 95 | #define HDCP_2_2_V_PRIME_HALF_LEN (HDCP_2_2_L_PRIME_LEN / 2) 96 | #define HDCP_2_2_RECEIVER_ID_LEN DRM_HDCP_KSV_LEN 97 | #define HDCP_2_2_MAX_DEVICE_COUNT 31 98 | #define HDCP_2_2_RECEIVER_IDS_MAX_LEN (HDCP_2_2_RECEIVER_ID_LEN * \ 99 | HDCP_2_2_MAX_DEVICE_COUNT) 100 | #define HDCP_2_2_MPRIME_LEN 32 101 | 102 | /* Following Macros take a byte at a time for bit(s) masking */ 103 | /* 104 | * TODO: HDCP_2_2_MAX_CONTENT_STREAMS_CNT is based upon actual 105 | * H/W MST streams capacity. 106 | * This required to be moved out to platform specific header. 107 | */ 108 | #define HDCP_2_2_MAX_CONTENT_STREAMS_CNT 4 109 | #define HDCP_2_2_TXCAP_MASK_LEN 2 110 | #define HDCP_2_2_RXCAPS_LEN 3 111 | #define HDCP_2_2_RX_REPEATER(x) ((x) & BIT(0)) 112 | #define HDCP_2_2_DP_HDCP_CAPABLE(x) ((x) & BIT(1)) 113 | #define HDCP_2_2_RXINFO_LEN 2 114 | 115 | /* HDCP1.x compliant device in downstream */ 116 | #define HDCP_2_2_HDCP1_DEVICE_CONNECTED(x) ((x) & BIT(0)) 117 | 118 | /* HDCP2.0 Compliant repeater in downstream */ 119 | #define HDCP_2_2_HDCP_2_0_REP_CONNECTED(x) ((x) & BIT(1)) 120 | #define HDCP_2_2_MAX_CASCADE_EXCEEDED(x) ((x) & BIT(2)) 121 | #define HDCP_2_2_MAX_DEVS_EXCEEDED(x) ((x) & BIT(3)) 122 | #define HDCP_2_2_DEV_COUNT_LO(x) (((x) & (0xF << 4)) >> 4) 123 | #define HDCP_2_2_DEV_COUNT_HI(x) ((x) & BIT(0)) 124 | #define HDCP_2_2_DEPTH(x) (((x) & (0x7 << 1)) >> 1) 125 | 126 | struct hdcp2_cert_rx { 127 | u8 receiver_id[HDCP_2_2_RECEIVER_ID_LEN]; 128 | u8 kpub_rx[HDCP_2_2_K_PUB_RX_LEN]; 129 | u8 reserved[2]; 130 | u8 dcp_signature[HDCP_2_2_DCP_LLC_SIG_LEN]; 131 | } __packed; 132 | 133 | struct hdcp2_streamid_type { 134 | u8 stream_id; 135 | u8 stream_type; 136 | } __packed; 137 | 138 | /* 139 | * The TxCaps field specified in the HDCP HDMI, DP specs 140 | * This field is big endian as specified in the errata. 141 | */ 142 | struct hdcp2_tx_caps { 143 | /* Transmitter must set this to 0x2 */ 144 | u8 version; 145 | 146 | /* Reserved for HDCP and DP Spec. Read as Zero */ 147 | u8 tx_cap_mask[HDCP_2_2_TXCAP_MASK_LEN]; 148 | } __packed; 149 | 150 | /* Main structures for HDCP2.2 protocol communication */ 151 | struct hdcp2_ake_init { 152 | u8 msg_id; 153 | u8 r_tx[HDCP_2_2_RTX_LEN]; 154 | struct hdcp2_tx_caps tx_caps; 155 | } __packed; 156 | 157 | struct hdcp2_ake_send_cert { 158 | u8 msg_id; 159 | struct hdcp2_cert_rx cert_rx; 160 | u8 r_rx[HDCP_2_2_RRX_LEN]; 161 | u8 rx_caps[HDCP_2_2_RXCAPS_LEN]; 162 | } __packed; 163 | 164 | struct hdcp2_ake_no_stored_km { 165 | u8 msg_id; 166 | u8 e_kpub_km[HDCP_2_2_E_KPUB_KM_LEN]; 167 | } __packed; 168 | 169 | struct hdcp2_ake_stored_km { 170 | u8 msg_id; 171 | u8 e_kh_km_m[HDCP_2_2_E_KH_KM_M_LEN]; 172 | } __packed; 173 | 174 | struct hdcp2_ake_send_hprime { 175 | u8 msg_id; 176 | u8 h_prime[HDCP_2_2_H_PRIME_LEN]; 177 | } __packed; 178 | 179 | struct hdcp2_ake_send_pairing_info { 180 | u8 msg_id; 181 | u8 e_kh_km[HDCP_2_2_E_KH_KM_LEN]; 182 | } __packed; 183 | 184 | struct hdcp2_lc_init { 185 | u8 msg_id; 186 | u8 r_n[HDCP_2_2_RN_LEN]; 187 | } __packed; 188 | 189 | struct hdcp2_lc_send_lprime { 190 | u8 msg_id; 191 | u8 l_prime[HDCP_2_2_L_PRIME_LEN]; 192 | } __packed; 193 | 194 | struct hdcp2_ske_send_eks { 195 | u8 msg_id; 196 | u8 e_dkey_ks[HDCP_2_2_E_DKEY_KS_LEN]; 197 | u8 riv[HDCP_2_2_RIV_LEN]; 198 | } __packed; 199 | 200 | struct hdcp2_rep_send_receiverid_list { 201 | u8 msg_id; 202 | u8 rx_info[HDCP_2_2_RXINFO_LEN]; 203 | u8 seq_num_v[HDCP_2_2_SEQ_NUM_LEN]; 204 | u8 v_prime[HDCP_2_2_V_PRIME_HALF_LEN]; 205 | u8 receiver_ids[HDCP_2_2_RECEIVER_IDS_MAX_LEN]; 206 | } __packed; 207 | 208 | struct hdcp2_rep_send_ack { 209 | u8 msg_id; 210 | u8 v[HDCP_2_2_V_PRIME_HALF_LEN]; 211 | } __packed; 212 | 213 | struct hdcp2_rep_stream_manage { 214 | u8 msg_id; 215 | u8 seq_num_m[HDCP_2_2_SEQ_NUM_LEN]; 216 | __be16 k; 217 | struct hdcp2_streamid_type streams[HDCP_2_2_MAX_CONTENT_STREAMS_CNT]; 218 | } __packed; 219 | 220 | struct hdcp2_rep_stream_ready { 221 | u8 msg_id; 222 | u8 m_prime[HDCP_2_2_MPRIME_LEN]; 223 | } __packed; 224 | 225 | /* HDCP2.2 TIMEOUTs in mSec */ 226 | #define HDCP_2_2_CERT_TIMEOUT_MS 100 227 | #define HDCP_2_2_DP_CERT_READ_TIMEOUT_MS 110 228 | #define HDCP_2_2_HPRIME_NO_PAIRED_TIMEOUT_MS 1000 229 | #define HDCP_2_2_HPRIME_PAIRED_TIMEOUT_MS 200 230 | #define HDCP_2_2_DP_HPRIME_READ_TIMEOUT_MS 7 231 | #define HDCP_2_2_PAIRING_TIMEOUT_MS 200 232 | #define HDCP_2_2_DP_PAIRING_READ_TIMEOUT_MS 5 233 | #define HDCP_2_2_HDMI_LPRIME_TIMEOUT_MS 20 234 | #define HDCP_2_2_DP_LPRIME_TIMEOUT_MS 16 235 | #define HDCP_2_2_RECVID_LIST_TIMEOUT_MS 3000 236 | #define HDCP_2_2_STREAM_READY_TIMEOUT_MS 100 237 | 238 | /* HDMI HDCP2.2 Register Offsets */ 239 | #define HDCP_2_2_HDMI_REG_VER_OFFSET 0x50 240 | #define HDCP_2_2_HDMI_REG_WR_MSG_OFFSET 0x60 241 | #define HDCP_2_2_HDMI_REG_RXSTATUS_OFFSET 0x70 242 | #define HDCP_2_2_HDMI_REG_RD_MSG_OFFSET 0x80 243 | #define HDCP_2_2_HDMI_REG_DBG_OFFSET 0xC0 244 | 245 | #define HDCP_2_2_HDMI_SUPPORT_MASK BIT(2) 246 | #define HDCP_2_2_RX_CAPS_VERSION_VAL 0x02 247 | #define HDCP_2_2_SEQ_NUM_MAX 0xFFFFFF 248 | #define HDCP_2_2_DELAY_BEFORE_ENCRYPTION_EN 200 249 | 250 | /* Below macros take a byte at a time and mask the bit(s) */ 251 | #define HDCP_2_2_HDMI_RXSTATUS_LEN 2 252 | #define HDCP_2_2_HDMI_RXSTATUS_MSG_SZ_HI(x) ((x) & 0x3) 253 | #define HDCP_2_2_HDMI_RXSTATUS_READY(x) ((x) & BIT(2)) 254 | #define HDCP_2_2_HDMI_RXSTATUS_REAUTH_REQ(x) ((x) & BIT(3)) 255 | 256 | /* 257 | * Helper functions to convert 24bit big endian hdcp sequence number to 258 | * host format and back 259 | */ 260 | static inline 261 | u32 drm_hdcp_be24_to_cpu(const u8 seq_num[HDCP_2_2_SEQ_NUM_LEN]) 262 | { 263 | return (u32)(seq_num[2] | seq_num[1] << 8 | seq_num[0] << 16); 264 | } 265 | 266 | static inline 267 | void drm_hdcp_cpu_to_be24(u8 seq_num[HDCP_2_2_SEQ_NUM_LEN], u32 val) 268 | { 269 | seq_num[0] = val >> 16; 270 | seq_num[1] = val >> 8; 271 | seq_num[2] = val; 272 | } 273 | 274 | #define DRM_HDCP_SRM_GEN1_MAX_BYTES (5 * 1024) 275 | #define DRM_HDCP_1_4_SRM_ID 0x8 276 | #define DRM_HDCP_SRM_ID_MASK (0xF << 4) 277 | #define DRM_HDCP_1_4_VRL_LENGTH_SIZE 3 278 | #define DRM_HDCP_1_4_DCP_SIG_SIZE 40 279 | #define DRM_HDCP_2_SRM_ID 0x9 280 | #define DRM_HDCP_2_INDICATOR 0x1 281 | #define DRM_HDCP_2_INDICATOR_MASK 0xF 282 | #define DRM_HDCP_2_VRL_LENGTH_SIZE 3 283 | #define DRM_HDCP_2_DCP_SIG_SIZE 384 284 | #define DRM_HDCP_2_NO_OF_DEV_PLUS_RESERVED_SZ 4 285 | #define DRM_HDCP_2_KSV_COUNT_2_LSBITS(byte) (((byte) & 0xC0) >> 6) 286 | 287 | struct hdcp_srm_header { 288 | u8 srm_id; 289 | u8 reserved; 290 | __be16 srm_version; 291 | u8 srm_gen_no; 292 | } __packed; 293 | 294 | /* Content Type classification for HDCP2.2 vs others */ 295 | #define DRM_MODE_HDCP_CONTENT_TYPE0 0 296 | #define DRM_MODE_HDCP_CONTENT_TYPE1 1 297 | 298 | #endif 299 | -------------------------------------------------------------------------------- /AllRez/linux/include/drm/drm_connector.h: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /AllRez/linux/include/linux/delay.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joevt/AllRez/433f3513225199f44e0e6bc90294b2be8df6b9a8/AllRez/linux/include/linux/delay.h -------------------------------------------------------------------------------- /AllRez/linux/include/linux/i2c.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joevt/AllRez/433f3513225199f44e0e6bc90294b2be8df6b9a8/AllRez/linux/include/linux/i2c.h -------------------------------------------------------------------------------- /AllRez/linux/include/linux/types.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUXTYPES_H__ 2 | #define __LINUXTYPES_H__ 3 | 4 | /* 5 | Types for drm_dp_helper.h 6 | */ 7 | 8 | typedef UInt8 u8; 9 | typedef UInt16 u16; 10 | typedef UInt32 u32; 11 | typedef UInt64 u64; 12 | typedef UInt16 __be16; 13 | 14 | typedef struct mutex { 15 | UInt8 stuff; 16 | } mutex; 17 | 18 | typedef struct delayed_work { 19 | UInt8 stuff; 20 | } delayed_work; 21 | 22 | typedef struct i2c_adapter { 23 | UInt8 stuff; 24 | } i2c_adapter; 25 | 26 | typedef struct work_struct { 27 | UInt8 stuff; 28 | } work_struct; 29 | 30 | #define BIT(x) (1 << (x)) 31 | 32 | #define __packed __attribute__((packed)) 33 | 34 | #define IS_ENABLED(x) 0 35 | #define IS_BUILTIN(x) 0 36 | #define IS_MODULE(x) 0 37 | 38 | #define CONFIG_DRM_AMD_DC_DCN 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /AllRez/oui.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // oui.c 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-02-19. 6 | // 7 | 8 | #include "oui.h" 9 | 10 | /* 11 | # Create the ouilist.h file by executing the command below. 12 | # There may be some duplicates that need to be commented out. 13 | 14 | for thetype in oui cid; do 15 | [[ -f "/tmp/${thetype}.txt" ]] || curl -s "http://standards-oui.ieee.org/${thetype}/${thetype}.txt" > "/tmp/${thetype}.txt" 16 | tr '\r\t' '\n ' < "/tmp/${thetype}.txt" | sed -nE '/^(......)[ ]+\(base 16\) *(.*[^ ]) *$/s//oneoui(\1, "\2")/p' 17 | done > "ouilist.h" 18 | */ 19 | 20 | typedef struct ouiRec { 21 | int val; 22 | const char *name; 23 | } ouiRec; 24 | 25 | ouiRec ouiList[] = { 26 | #define oneoui(val, name) {0x ## val, name}, 27 | #include "ouilist.h" 28 | }; 29 | 30 | const char* convertoui(int oui) { 31 | for (int i = 0; i < sizeof(ouiList) / sizeof(ouiList[0]); i++) { 32 | if (oui == ouiList[i].val) { 33 | return ouiList[i].name; 34 | } 35 | } 36 | return "Unknown OUI"; 37 | } 38 | -------------------------------------------------------------------------------- /AllRez/oui.h: -------------------------------------------------------------------------------- 1 | // 2 | // oui.h 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-02-19. 6 | // 7 | 8 | #ifndef oui_h 9 | #define oui_h 10 | 11 | const char* convertoui(int oui); 12 | 13 | #endif /* oui_h */ 14 | -------------------------------------------------------------------------------- /AllRez/printf.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // printf.c 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-02-19. 6 | // 7 | #include "MacOSMacros.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "printf.h" 14 | #include "AppleMisc.h" 15 | #include 16 | #include 17 | 18 | 19 | #if MAC_OS_X_VERSION_SDK < MAC_OS_X_VERSION_10_7 20 | #define kIOMessageConsoleSecurityChange iokit_common_msg(0x128) 21 | #define kIOMessageSystemCapabilityChange iokit_common_msg(0x340) 22 | #define kIOMessageDeviceSignaledWakeup iokit_common_msg(0x350) 23 | #define kIOMessageSystemPagingOff iokit_common_msg(0x255) 24 | #define kIOMessageDeviceWillPowerOn iokit_common_msg(0x215) 25 | #define kIOMessageDeviceHasPoweredOff iokit_common_msg(0x225) 26 | #endif 27 | 28 | 29 | int indent = 0; 30 | 31 | int scnprintf(char * str, size_t size, const char * format, ...) { 32 | va_list args; 33 | va_start(args, format); 34 | size_t result = vsnprintf(str, size, format, args); 35 | va_end(args); 36 | if (result > size) 37 | result = size; 38 | return (int)result; 39 | } 40 | 41 | char * myprintf(const char *format, ...) { 42 | char *unknownValue = (char *)malloc(20); 43 | va_list vl; 44 | va_start(vl, format); 45 | vsnprintf(unknownValue, 20, format, vl); 46 | va_end(vl); 47 | return unknownValue; 48 | } 49 | 50 | #if !defined(DUMPDPCD) 51 | void CFOutput(CFTypeRef val) { 52 | if (val) { 53 | CFStringRef theinfo = CFCopyDescription(val); // can't really parse this if the format can change for every macOS 54 | if (theinfo) { 55 | size_t maxsize = CFStringGetMaximumSizeForEncoding(CFStringGetLength(theinfo), kCFStringEncodingUTF8); 56 | char *strinfo = (char *)malloc(maxsize); 57 | if (strinfo) { 58 | if (CFStringGetCString(theinfo, strinfo, maxsize, kCFStringEncodingUTF8)) { 59 | char *s; 60 | if (DarwinMajorVersion() < 19) { // earlier than 10.15 61 | size_t l; 62 | regmatch_t p[2]; 63 | int reti; 64 | 65 | regex_t regex; 66 | 67 | reti = regcomp(®ex, "\\{contents = \"([^\"]*)\"\\}", REG_EXTENDED); 68 | if (reti) { 69 | cprintf("? Could not compile regex1"); 70 | } 71 | else { 72 | s = strinfo; 73 | l = maxsize; 74 | 75 | while (1) { 76 | reti = regexec(®ex, s, sizeof(p) / sizeof(p[0]), p, 0); 77 | if (!reti) { 78 | snprintf(s + p[0].rm_so, (size_t)(l - p[0].rm_so), "%.*s%s", (int)(p[1].rm_eo - p[1].rm_so), s + (size_t)p[1].rm_so, s + (size_t)p[0].rm_eo); 79 | s += p[0].rm_so + p[1].rm_eo - p[1].rm_so; 80 | l -= (size_t)(p[0].rm_so + p[1].rm_eo - p[1].rm_so); 81 | } 82 | else if (reti == REG_NOMATCH) { 83 | break; 84 | } 85 | else { 86 | char msgbuf[100]; 87 | regerror(reti, ®ex, msgbuf, sizeof(msgbuf)); 88 | cprintf("? Regex1 match failed: %s", msgbuf); 89 | } 90 | } 91 | regfree(®ex); 92 | } 93 | 94 | reti = regcomp(®ex, "", REG_EXTENDED); 95 | if (reti) { 96 | cprintf("? Could not compile regex2"); 97 | } 98 | else { 99 | s = strinfo; 100 | l = maxsize; 101 | 102 | while (1) { 103 | reti = regexec(®ex, s, sizeof(p) / sizeof(p[0]), p, 0); 104 | if (!reti) { 105 | snprintf(s + p[0].rm_so, l - (size_t)p[0].rm_so, "%s", s + (size_t)p[0].rm_eo); 106 | s += p[0].rm_so; 107 | l -= (int)p[0].rm_so; 108 | } 109 | else if (reti == REG_NOMATCH) { 110 | break; 111 | } 112 | else { 113 | char msgbuf[100]; 114 | regerror(reti, ®ex, msgbuf, sizeof(msgbuf)); 115 | cprintf("? Regex2 match failed: %s", msgbuf); 116 | } 117 | } 118 | regfree(®ex); 119 | } 120 | } // if earlier than 10.15 121 | 122 | // Output each line with extra indent 123 | char *next; 124 | size_t len = strlen(strinfo); 125 | if (len && strinfo[len-1] == '\n') { 126 | strinfo[len-1] = '\0'; 127 | } 128 | for (s = strinfo; ; s = next + 1) { 129 | next = strstr(s, "\n"); 130 | if (!next) { 131 | cprintf("%s", s); 132 | break; 133 | } 134 | cprintf("%.*s", (int)(next - s + 1), s); 135 | iprintf(""); 136 | } 137 | } 138 | else { 139 | cprintf("? (CFStringGetCString error)"); 140 | } 141 | free(strinfo); 142 | } 143 | CFRelease(theinfo); 144 | } 145 | else { 146 | cprintf("? (CFCopyDescription error)"); 147 | } 148 | } 149 | else { 150 | cprintf("(NULL)"); 151 | } 152 | } 153 | #endif 154 | 155 | const char * GetIOReturnStr(char * buf, size_t bufSize, int64_t val) { 156 | 157 | const char* str; 158 | #define onereturn(x) case x: str = #x; break; 159 | 160 | switch (val) { 161 | onereturn(kIOReturnSuccess) 162 | onereturn(kIOReturnError) 163 | onereturn(kIOReturnNoMemory) 164 | onereturn(kIOReturnNoResources) 165 | onereturn(kIOReturnIPCError) 166 | onereturn(kIOReturnNoDevice) 167 | onereturn(kIOReturnNotPrivileged) 168 | onereturn(kIOReturnBadArgument) 169 | onereturn(kIOReturnLockedRead) 170 | onereturn(kIOReturnLockedWrite) 171 | onereturn(kIOReturnExclusiveAccess) 172 | onereturn(kIOReturnBadMessageID) 173 | onereturn(kIOReturnUnsupported) 174 | onereturn(kIOReturnVMError) 175 | onereturn(kIOReturnInternalError) 176 | onereturn(kIOReturnIOError) 177 | onereturn(kIOReturnCannotLock) 178 | onereturn(kIOReturnNotOpen) 179 | onereturn(kIOReturnNotReadable) 180 | onereturn(kIOReturnNotWritable) 181 | onereturn(kIOReturnNotAligned) 182 | onereturn(kIOReturnBadMedia) 183 | onereturn(kIOReturnStillOpen) 184 | onereturn(kIOReturnRLDError) 185 | onereturn(kIOReturnDMAError) 186 | onereturn(kIOReturnBusy) 187 | onereturn(kIOReturnTimeout) 188 | onereturn(kIOReturnOffline) 189 | onereturn(kIOReturnNotReady) 190 | onereturn(kIOReturnNotAttached) 191 | onereturn(kIOReturnNoChannels) 192 | onereturn(kIOReturnNoSpace) 193 | onereturn(kIOReturnPortExists) 194 | onereturn(kIOReturnCannotWire) 195 | onereturn(kIOReturnNoInterrupt) 196 | onereturn(kIOReturnNoFrames) 197 | onereturn(kIOReturnMessageTooLarge) 198 | onereturn(kIOReturnNotPermitted) 199 | onereturn(kIOReturnNoPower) 200 | onereturn(kIOReturnNoMedia) 201 | onereturn(kIOReturnUnformattedMedia) 202 | onereturn(kIOReturnUnsupportedMode) 203 | onereturn(kIOReturnUnderrun) 204 | onereturn(kIOReturnOverrun) 205 | onereturn(kIOReturnDeviceError) 206 | onereturn(kIOReturnNoCompletion) 207 | onereturn(kIOReturnAborted) 208 | onereturn(kIOReturnNoBandwidth) 209 | onereturn(kIOReturnNotResponding) 210 | onereturn(kIOReturnIsoTooOld) 211 | onereturn(kIOReturnIsoTooNew) 212 | onereturn(kIOReturnNotFound) 213 | onereturn(kIOReturnInvalid) 214 | 215 | onereturn(kIOMessageServiceIsTerminated) 216 | onereturn(kIOMessageServiceIsSuspended) 217 | onereturn(kIOMessageServiceIsResumed) 218 | onereturn(kIOMessageServiceIsRequestingClose) 219 | onereturn(kIOMessageServiceIsAttemptingOpen) 220 | onereturn(kIOMessageServiceWasClosed) 221 | onereturn(kIOMessageServiceBusyStateChange) 222 | onereturn(kIOMessageConsoleSecurityChange) 223 | onereturn(kIOMessageServicePropertyChange) 224 | onereturn(kIOMessageCopyClientID) 225 | onereturn(kIOMessageSystemCapabilityChange) 226 | onereturn(kIOMessageDeviceSignaledWakeup) 227 | onereturn(kIOMessageDeviceWillPowerOff) 228 | onereturn(kIOMessageDeviceHasPoweredOn) 229 | onereturn(kIOMessageSystemWillPowerOff) 230 | onereturn(kIOMessageSystemWillRestart) 231 | onereturn(kIOMessageSystemPagingOff) 232 | onereturn(kIOMessageCanSystemSleep) 233 | onereturn(kIOMessageSystemWillNotSleep) 234 | onereturn(kIOMessageSystemWillSleep) 235 | onereturn(kIOMessageSystemWillPowerOn) 236 | onereturn(kIOMessageSystemHasPoweredOn) 237 | onereturn(kIOMessageCanDevicePowerOff) 238 | onereturn(kIOMessageDeviceWillNotPowerOff) 239 | onereturn(kIOMessageSystemWillNotPowerOff) 240 | onereturn(kIOMessageCanSystemPowerOff) 241 | onereturn(kIOMessageDeviceWillPowerOn) 242 | onereturn(kIOMessageDeviceHasPoweredOff) 243 | onereturn(kIOMessageGraphicsNotifyTerminated) 244 | onereturn(kIOMessageGraphicsProbeAccelerator) 245 | onereturn(kIOMessageGraphicsDeviceEject) 246 | onereturn(kIOMessageGraphicsDeviceEjectFinalize) 247 | onereturn(kIOMessageGraphicsDeviceEjectCancel) 248 | 249 | onereturn(nrLockedErr) 250 | onereturn(nrNotEnoughMemoryErr) 251 | onereturn(nrInvalidNodeErr) 252 | onereturn(nrNotFoundErr) 253 | onereturn(nrNotCreatedErr) 254 | onereturn(nrNameErr) 255 | onereturn(nrNotSlotDeviceErr) 256 | onereturn(nrDataTruncatedErr) 257 | onereturn(nrPowerErr) 258 | onereturn(nrPowerSwitchAbortErr) 259 | onereturn(nrTypeMismatchErr) 260 | onereturn(nrNotModifiedErr) 261 | onereturn(nrOverrunErr) 262 | onereturn(nrResultCodeBase) 263 | onereturn(nrPathNotFound) 264 | onereturn(nrPathBufferTooSmall) 265 | onereturn(nrInvalidEntryIterationOp) 266 | onereturn(nrPropertyAlreadyExists) 267 | onereturn(nrIterationDone) 268 | onereturn(nrExitedIteratorScope) 269 | onereturn(nrTransactionAborted) 270 | onereturn(gestaltUndefSelectorErr) 271 | onereturn(paramErr) 272 | onereturn(noHardwareErr) 273 | onereturn(notEnoughHardwareErr) 274 | onereturn(userCanceledErr) 275 | onereturn(qErr) 276 | onereturn(vTypErr) 277 | onereturn(corErr) 278 | onereturn(unimpErr) 279 | onereturn(SlpTypeErr) 280 | onereturn(seNoDB) 281 | onereturn(controlErr) 282 | onereturn(statusErr) 283 | onereturn(readErr) 284 | onereturn(writErr) 285 | onereturn(badUnitErr) 286 | onereturn(unitEmptyErr) 287 | onereturn(openErr) 288 | onereturn(closErr) 289 | onereturn(dRemovErr) 290 | onereturn(dInstErr) 291 | onereturn(badCksmErr) 292 | default: str = buf; snprintf(buf, bufSize, "?%#llx", val); break; 293 | } 294 | #undef onereturn 295 | return str; 296 | } // GetIOReturnStr 297 | 298 | char * DumpOneReturn(char * buf, size_t bufSize, int64_t val) 299 | { 300 | char * result = buf; 301 | if (val == kIOReturnSuccess) 302 | snprintf(buf, bufSize, ""); 303 | else { 304 | char resultStr[40]; 305 | snprintf(buf, bufSize, " result:%s", GetIOReturnStr(resultStr, sizeof(resultStr), val)); 306 | } 307 | return result; 308 | } // DumpOneReturn 309 | -------------------------------------------------------------------------------- /AllRez/printf.h: -------------------------------------------------------------------------------- 1 | // 2 | // printf.h 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-02-19. 6 | // 7 | 8 | #ifndef printf_h 9 | #define printf_h 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #define FILEOUT stdout 16 | #define OUTDENT indent -= 4; 17 | #define INDENT indent += 4; 18 | #define iprintf(s,...) fprintf(FILEOUT, "%*s" s, indent, "", ##__VA_ARGS__) 19 | #define cprintf(s,...) fprintf(FILEOUT, s, ##__VA_ARGS__) 20 | #define lf cprintf("\n") 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | int scnprintf(char * str, size_t size, const char * format, ...) __printflike(3, 4); 27 | 28 | char * myprintf(const char *format, ...) __printflike(1, 2); 29 | 30 | char * DumpOneReturn(char * buf, size_t bufSize, int64_t val); 31 | const char * GetIOReturnStr(char * buf, size_t bufSize, int64_t val); 32 | void CFOutput(CFTypeRef val); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | 39 | #define UNKNOWN_FLAG( x) (x) ? myprintf("?0x%llx,", uint64_t(x)) : "" 40 | #define UNKNOWN_VALUE(x) myprintf("?0x%llx", uint64_t(x)) 41 | 42 | extern int indent; 43 | 44 | #endif /* printf_h */ 45 | -------------------------------------------------------------------------------- /AllRez/utilities.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // utilities.cpp 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-02-19. 6 | // 7 | 8 | #include "utilities.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | uint64_t mach_time() { 15 | #if MAC_OS_X_VERSION_SDK >= MAC_OS_X_VERSION_10_12 16 | #if __has_builtin(__builtin_available) 17 | if (__builtin_available(macOS 10.12, *)) { 18 | return mach_continuous_time(); 19 | } 20 | #else 21 | if (&mach_continuous_time) { 22 | return mach_continuous_time(); 23 | } 24 | #endif 25 | #endif 26 | return mach_absolute_time(); 27 | } 28 | 29 | UInt64 MicrosecondsToAbsoluteTime(UInt64 micro) { 30 | /* minReplyDelay may require milliseconds instead of microseconds or nanoseconds so don't use this - use FORCEI2C instead */ 31 | Nanoseconds nano; 32 | *(UInt64*)(&nano) = micro * 1000; 33 | #pragma clang diagnostic push 34 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 35 | AbsoluteTime absolute = NanosecondsToAbsolute(nano); // on Intel Macs this uses 1 AbsolouteTime == 1 Nanosecond 36 | #pragma clang diagnostic pop 37 | return *(UInt64*)(&absolute); 38 | } 39 | 40 | void strftimestamp(char *buf, size_t bufsize, const char *format, int decimals, uint64_t timestamp) { 41 | static uint64_t nowct = 0; 42 | static uint64_t nowns = 0; 43 | if (!nowct) { 44 | uint64_t bestspread = -1; 45 | uint64_t bestct = 0; 46 | struct timeval besttod; 47 | 48 | struct timeval tod; 49 | for (int i = 0; i < 100; i++) { 50 | nowct = mach_time(); 51 | gettimeofday(&tod, NULL); 52 | uint64_t spread = mach_time() - nowct; 53 | if (spread < bestspread) { 54 | bestspread = spread; 55 | besttod = tod; 56 | bestct = nowct; 57 | } 58 | if (spread < 1000) 59 | break; 60 | } 61 | nowct = bestct; 62 | nowns = (besttod.tv_sec * 1000000 + besttod.tv_usec) * 1000; 63 | } 64 | 65 | if (decimals < 0) decimals = 0; 66 | else if (decimals > 9) decimals = 9; 67 | int64_t factor = 1; 68 | for (int i = decimals; i < 9; i++) { 69 | factor *= 10; 70 | } 71 | /* 72 | 9 = 1 73 | 8 = 10 74 | 7 = 100 75 | 6 = 1000 76 | 5 = 10000 77 | 4 = 100000 78 | 3 = 1000000 79 | 2 = 10000000 80 | 1 = 100000000 81 | 0 = 1000000000 82 | */ 83 | int64_t nsoffset = timestamp - nowct; 84 | int64_t thenns = nowns + nsoffset + 5LL * factor / 10; // round 85 | time_t thentime = (time_t)(thenns / 1000000000); 86 | 87 | struct tm thentm; 88 | localtime_r(&thentime, &thentm); 89 | size_t len = strftime(buf, bufsize, format, &thentm); 90 | if (decimals) snprintf(buf + len, bufsize - len, ".%0*lld", decimals, (thenns % 1000000000) / factor); 91 | } 92 | 93 | #if 0 94 | void testtime(void) { 95 | typedef struct { 96 | clockid_t clockid; 97 | const char *clockname; 98 | int result1; 99 | int result2; 100 | uint64_t nano; 101 | timespec res; 102 | timespec time; 103 | } clockitem; 104 | 105 | #define oneclock(x) { x, #x } 106 | clockitem clocks[] = { 107 | oneclock(CLOCK_REALTIME), 108 | oneclock(CLOCK_MONOTONIC), 109 | oneclock(CLOCK_MONOTONIC_RAW), 110 | oneclock(CLOCK_UPTIME_RAW), 111 | oneclock(CLOCK_MONOTONIC_RAW_APPROX), 112 | oneclock(CLOCK_UPTIME_RAW_APPROX), 113 | oneclock(CLOCK_PROCESS_CPUTIME_ID), 114 | oneclock(CLOCK_THREAD_CPUTIME_ID), 115 | {(clockid_t)-1, NULL} 116 | }; 117 | 118 | struct timeval tod; 119 | struct timezone tzp; 120 | gettimeofday(&tod, &tzp); 121 | 122 | for (clockitem* clock = &clocks[0]; clock->clockname; clock++) { 123 | clock->result1 = clock_getres(clock->clockid, &clock->res); 124 | clock->result2 = clock_gettime(clock->clockid, &clock->time); 125 | clock->nano = clock_gettime_nsec_np(clock->clockid); 126 | } // for clock 127 | 128 | uint64_t abs = mach_absolute_time(); 129 | uint64_t continuous = mach_continuous_time(); 130 | uint64_t approx = mach_approximate_time(); 131 | uint64_t contapprox = mach_continuous_approximate_time(); 132 | 133 | iprintf("%-32s res:%ld.%09ld time:%10ld.%06ld = %llu\n", "timeofday", (long)0, (long)0, (long)tod.tv_sec, (long)tod.tv_usec, (uint64_t)0); 134 | for (clockitem* clock = &clocks[0]; clock->clockname; clock++) { 135 | iprintf("%-32s res:%ld.%09ld time:%10ld.%09ld = %llu\n", clock->clockname, clock->res.tv_sec, clock->res.tv_nsec, clock->time.tv_sec, clock->time.tv_nsec, clock->nano); 136 | } // for clock 137 | iprintf("%-32s res:%ld.%09ld time:%10ld.%09ld = %llu\n", "mach_absolute_time", (long)0, (long)0, (long)0, (long)0, abs); 138 | iprintf("%-32s res:%ld.%09ld time:%10ld.%09ld = %llu\n", "mach_continuous_time", (long)0, (long)0, (long)0, (long)0, continuous); 139 | iprintf("%-32s res:%ld.%09ld time:%10ld.%09ld = %llu\n", "mach_approximate_time", (long)0, (long)0, (long)0, (long)0, approx); 140 | iprintf("%-32s res:%ld.%09ld time:%10ld.%09ld = %llu\n", "mach_continuous_approximate_time", (long)0, (long)0, (long)0, (long)0, contapprox); 141 | } // testtime 142 | #endif 143 | -------------------------------------------------------------------------------- /AllRez/utilities.h: -------------------------------------------------------------------------------- 1 | // 2 | // utilities.h 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-02-19. 6 | // 7 | 8 | #ifndef utilities_h 9 | #define utilities_h 10 | 11 | #include "MacOSMacros.h" 12 | #if MAC_OS_X_VERSION_SDK < MAC_OS_X_VERSION_10_9 13 | #include 14 | #else 15 | #include // from /usr/include 16 | #endif 17 | #include 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | UInt64 MicrosecondsToAbsoluteTime(UInt64 micro); 25 | void strftimestamp(char *buf, size_t bufsize, const char *format, int decimals, uint64_t timestamp); 26 | void testtime(void); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif /* utilities_h */ 33 | -------------------------------------------------------------------------------- /AllRez/vcp.h: -------------------------------------------------------------------------------- 1 | // 2 | // vcp.h 3 | // AllRez 4 | // 5 | // Created by joevt on 2022-02-19. 6 | // 7 | 8 | #ifndef vcp_h 9 | #define vcp_h 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include 18 | #include 19 | 20 | // These are in micoseconds 21 | 22 | #define kDelayRequest 10000 23 | #define kDelayReply 10000 24 | 25 | #define kDelayDDCEDIDReply kDelayReply 26 | 27 | #define kDelayEDDCPointerSegment kDelayRequest 28 | #define kDelayEDDCEDIDReply kDelayReply 29 | 30 | #define kDelayMCCSEDIDRequest kDelayRequest 31 | #define kDelayMCCSEDIDReply kDelayReply 32 | 33 | #define kDelayDDCIdentificationRequest kDelayRequest 34 | #define kDelayDDCIdentificationReply kDelayReply 35 | 36 | #define kDelayDDCTimingRequest kDelayRequest 37 | #define kDelayDDCTimingReply kDelayReply 38 | 39 | #define kDelayDDCVCPCapRequest kDelayRequest 40 | #define kDelayDDCVCPCapReply kDelayReply 41 | 42 | #define kDelayDDCFeatureRequest kDelayRequest 43 | #define kDelayDDCFeatureReply kDelayReply 44 | 45 | 46 | #define FORCEI2C 1 // don't use kIOI2CDDCciReplyTransactionType because some drivers (for my GTX 680 in Monterey) may treat minReplyDelay of 6000 as 6 seconds instead of 6 milliseconds 47 | 48 | void ddcsetchecksum(IOI2CRequest_10_6 *request); 49 | bool ddcreplyisgood(IOI2CRequest_10_6 *request, bool hasSize, UInt8 sendAddress, UInt8 *replyBuffer, int expectedSize); 50 | long parsevcp(int level, char *vcps, IOI2CConnectRef i2cconnect, int val_IOI2CTransactionTypes); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /dumpdpcd/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // dumpdpcd 4 | // 5 | // Created by joevt on 2025-04-21. 6 | // 7 | //================================================================================================================================= 8 | 9 | #include 10 | #include 11 | #include 12 | #include "dpcd.h" 13 | 14 | int main(int argc, const char * argv[]) { 15 | if (argc <= 1) 16 | return -1; 17 | 18 | FILE *thefile = fopen(argv[1], "rb"); 19 | 20 | uint8_t *dpcd = (uint8_t*)malloc(0x100000); 21 | if (!dpcd) 22 | return -1; 23 | memset(dpcd, 0, 0x100000); 24 | fread(dpcd, 0x100000, 1, thefile); 25 | 26 | parsedpcd(dpcd); 27 | 28 | free(dpcd); 29 | return 0; 30 | } // main 31 | --------------------------------------------------------------------------------