1 /* 2 * Copyright 2006-2009, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include "driver.h" 11 #include "device.h" 12 #include "lock.h" 13 14 #include <stdlib.h> 15 #include <stdio.h> 16 #include <string.h> 17 18 #include <AGP.h> 19 #include <KernelExport.h> 20 #include <OS.h> 21 #include <PCI.h> 22 #include <SupportDefs.h> 23 24 25 #define TRACE_DRIVER 26 #ifdef TRACE_DRIVER 27 # define TRACE(x...) dprintf("intel_extreme: " x) 28 #else 29 # define TRACE(x) ; 30 #endif 31 32 #define ERROR(x...) dprintf("intel_extreme: " x) 33 #define CALLED(x...) TRACE("CALLED %s\n", __PRETTY_FUNCTION__) 34 35 36 #define MAX_CARDS 4 37 38 39 // list of supported devices 40 const struct supported_device { 41 uint32 device_id; 42 int32 type; 43 const char* name; 44 } kSupportedDevices[] = { 45 {0x3577, INTEL_GROUP_83x, "i830GM"}, 46 {0x2562, INTEL_GROUP_83x, "i845G"}, 47 48 {0x2572, INTEL_GROUP_85x, "i865G"}, 49 {0x3582, INTEL_GROUP_85x, "i855G"}, 50 {0x358e, INTEL_GROUP_85x, "i855G"}, 51 52 {0x2582, INTEL_MODEL_915, "i915G"}, 53 {0x258a, INTEL_MODEL_915, "i915"}, 54 {0x2592, INTEL_MODEL_915M, "i915GM"}, 55 {0x2792, INTEL_MODEL_915, "i910"}, 56 {0x2772, INTEL_MODEL_945, "i945G"}, 57 {0x27a2, INTEL_MODEL_945M, "i945GM"}, 58 {0x27ae, INTEL_MODEL_945M, "i945GME"}, 59 {0x2972, INTEL_MODEL_965, "i946G"}, 60 {0x2982, INTEL_MODEL_965, "G35"}, 61 {0x2992, INTEL_MODEL_965, "i965Q"}, 62 {0x29a2, INTEL_MODEL_965, "i965G"}, 63 {0x2a02, INTEL_MODEL_965M, "i965GM"}, 64 {0x2a12, INTEL_MODEL_965M, "i965GME"}, 65 {0x29b2, INTEL_MODEL_G33, "G33G"}, 66 {0x29c2, INTEL_MODEL_G33, "Q35G"}, 67 {0x29d2, INTEL_MODEL_G33, "Q33G"}, 68 69 {0x2a42, INTEL_MODEL_GM45, "GM45"}, 70 {0x2e02, INTEL_MODEL_G45, "IGD"}, 71 {0x2e12, INTEL_MODEL_G45, "Q45"}, 72 {0x2e22, INTEL_MODEL_G45, "G45"}, 73 {0x2e32, INTEL_MODEL_G45, "G41"}, 74 {0x2e42, INTEL_MODEL_G45, "B43"}, 75 {0x2e92, INTEL_MODEL_G45, "B43"}, 76 77 {0xa001, INTEL_MODEL_PINE, "Atom D4xx"}, 78 {0xa002, INTEL_MODEL_PINE, "Atom D5xx"}, 79 {0xa011, INTEL_MODEL_PINEM, "Atom N4xx"}, 80 {0xa012, INTEL_MODEL_PINEM, "Atom N5xx"}, 81 82 {0x0042, INTEL_MODEL_ILKG, "IronLake Desktop"}, 83 {0x0046, INTEL_MODEL_ILKGM, "IronLake Mobile"}, 84 {0x0046, INTEL_MODEL_ILKGM, "IronLake Mobile"}, 85 {0x0046, INTEL_MODEL_ILKGM, "IronLake Mobile"}, 86 87 {0x0102, INTEL_MODEL_SNBG, "SandyBridge Desktop GT1"}, 88 {0x0112, INTEL_MODEL_SNBG, "SandyBridge Desktop GT2"}, 89 {0x0122, INTEL_MODEL_SNBG, "SandyBridge Desktop GT2+"}, 90 {0x0106, INTEL_MODEL_SNBGM, "SandyBridge Mobile GT1"}, 91 {0x0116, INTEL_MODEL_SNBGM, "SandyBridge Mobile GT2"}, 92 {0x0126, INTEL_MODEL_SNBGM, "SandyBridge Mobile GT2+"}, 93 {0x010a, INTEL_MODEL_SNBGS, "SandyBridge Server"}, 94 95 {0x0152, INTEL_MODEL_IVBG, "IvyBridge Desktop GT1"}, 96 {0x0162, INTEL_MODEL_IVBG, "IvyBridge Desktop GT2"}, 97 {0x0156, INTEL_MODEL_IVBGM, "IvyBridge Mobile GT1"}, 98 {0x0166, INTEL_MODEL_IVBGM, "IvyBridge Mobile GT2"}, 99 {0x0152, INTEL_MODEL_IVBGS, "IvyBridge Server"}, 100 {0x015a, INTEL_MODEL_IVBGS, "IvyBridge Server GT1"}, 101 {0x016a, INTEL_MODEL_IVBGS, "IvyBridge Server GT2"}, 102 103 {0x0412, INTEL_MODEL_HAS, "Haswell Desktop"}, 104 {0x0416, INTEL_MODEL_HASM, "Haswell Mobile"}, 105 {0x0d26, INTEL_MODEL_HASM, "Haswell Mobile"}, 106 {0x0a16, INTEL_MODEL_HASM, "Haswell Mobile"}, 107 108 #if 0 109 // The driver does not make any attempt to handle this modern hardware. 110 // Better let VESA/UEFI do it. 111 {0x0155, INTEL_MODEL_VLV, "ValleyView Desktop"}, 112 {0x0f30, INTEL_MODEL_VLVM, "ValleyView Mobile"}, 113 {0x0f31, INTEL_MODEL_VLVM, "ValleyView Mobile"}, 114 {0x0f32, INTEL_MODEL_VLVM, "ValleyView Mobile"}, 115 {0x0f33, INTEL_MODEL_VLVM, "ValleyView Mobile"}, 116 {0x0157, INTEL_MODEL_VLVM, "ValleyView Mobile"}, 117 118 // {0x1616, INTEL_MODEL_BDWM, "HD Graphics 5500 (Broadwell GT2)"}, 119 #endif 120 121 {0x1902, INTEL_MODEL_SKY, "Skylake GT1"}, 122 {0x1906, INTEL_MODEL_SKYM, "Skylake GT1"}, 123 {0x190a, INTEL_MODEL_SKYS, "Skylake GT1"}, 124 {0x190b, INTEL_MODEL_SKY, "Skylake GT1"}, 125 {0x190e, INTEL_MODEL_SKYM, "Skylake GT1"}, 126 {0x1912, INTEL_MODEL_SKY, "Skylake GT2"}, //confirmed OK 127 {0x1916, INTEL_MODEL_SKYM, "Skylake GT2"}, //confirmed native mode panel OK 128 {0x191a, INTEL_MODEL_SKYS, "Skylake GT2"}, 129 {0x191b, INTEL_MODEL_SKY, "Skylake GT2"}, 130 {0x191d, INTEL_MODEL_SKY, "Skylake GT2"}, 131 {0x191e, INTEL_MODEL_SKYM, "Skylake GT2"}, 132 {0x1921, INTEL_MODEL_SKYM, "Skylake GT2F"}, 133 {0x1926, INTEL_MODEL_SKYM, "Skylake GT3"}, 134 {0x192a, INTEL_MODEL_SKYS, "Skylake GT3"}, 135 {0x192b, INTEL_MODEL_SKY, "Skylake GT3"}, 136 137 {0x5906, INTEL_MODEL_KBY, "Kabylake ULT GT1"}, 138 {0x5902, INTEL_MODEL_KBY, "Kabylake DT GT1"}, 139 {0x5916, INTEL_MODEL_KBYM, "Kabylake ULT GT2"}, 140 {0x5921, INTEL_MODEL_KBYM, "Kabylake ULT GT2F"}, 141 {0x591c, INTEL_MODEL_KBY, "Kabylake ULX GT2"}, 142 {0x591e, INTEL_MODEL_KBY, "Kabylake ULX GT2"}, 143 {0x5912, INTEL_MODEL_KBY, "Kabylake DT GT2"}, 144 {0x5917, INTEL_MODEL_KBYM, "Kabylake Mobile GT2"}, 145 {0x591b, INTEL_MODEL_KBYM, "Kabylake Halo GT2"}, 146 {0x591d, INTEL_MODEL_KBY, "Kabylake WKS GT2"}, 147 {0x5926, INTEL_MODEL_KBY, "Kabylake ULT GT3"}, 148 {0x5927, INTEL_MODEL_KBY, "Kabylake ULT GT3"}, 149 150 {0x3e90, INTEL_MODEL_CFL, "CoffeeLake GT1"}, 151 {0x3e93, INTEL_MODEL_CFL, "CoffeeLake GT1"}, 152 {0x3e91, INTEL_MODEL_CFL, "CoffeeLake GT2"}, 153 {0x3e92, INTEL_MODEL_CFL, "CoffeeLake GT2"}, 154 {0x3e96, INTEL_MODEL_CFL, "CoffeeLake GT2"}, 155 {0x3e98, INTEL_MODEL_CFL, "CoffeeLake GT2"}, 156 {0x3e9a, INTEL_MODEL_CFL, "CoffeeLake GT2"}, 157 {0x3e9b, INTEL_MODEL_CFLM, "CoffeeLake Halo GT2"}, 158 {0x3eab, INTEL_MODEL_CFLM, "CoffeeLake Halo GT2"}, 159 {0x3ea5, INTEL_MODEL_CFL, "CoffeeLake GT3"}, 160 {0x3ea6, INTEL_MODEL_CFL, "CoffeeLake GT3"}, 161 }; 162 163 int32 api_version = B_CUR_DRIVER_API_VERSION; 164 165 char* gDeviceNames[MAX_CARDS + 1]; 166 intel_info* gDeviceInfo[MAX_CARDS]; 167 pci_module_info* gPCI; 168 pci_x86_module_info* gPCIx86Module = NULL; 169 agp_gart_module_info* gGART; 170 mutex gLock; 171 172 173 static status_t 174 get_next_intel_extreme(int32* _cookie, pci_info &info, uint32 &type) 175 { 176 int32 index = *_cookie; 177 178 // find devices 179 180 for (; gPCI->get_nth_pci_info(index, &info) == B_OK; index++) { 181 // check vendor 182 if (info.vendor_id != VENDOR_ID_INTEL 183 || info.class_base != PCI_display 184 || (info.class_sub != PCI_vga && info.class_sub != PCI_display_other)) 185 continue; 186 187 // check device 188 for (uint32 i = 0; i < sizeof(kSupportedDevices) 189 / sizeof(kSupportedDevices[0]); i++) { 190 if (info.device_id == kSupportedDevices[i].device_id) { 191 type = i; 192 *_cookie = index + 1; 193 ERROR("%s: Intel gfx deviceID: 0x%04x\n", __func__, info.device_id); 194 return B_OK; 195 } 196 } 197 } 198 199 return B_ENTRY_NOT_FOUND; 200 } 201 202 203 static enum pch_info 204 detect_intel_pch() 205 { 206 pci_info info; 207 208 // find devices 209 for (int32 i = 0; gPCI->get_nth_pci_info(i, &info) == B_OK; i++) { 210 // check vendor 211 if (info.vendor_id != VENDOR_ID_INTEL 212 || info.class_base != PCI_bridge 213 || info.class_sub != PCI_isa) { 214 continue; 215 } 216 217 // check device 218 unsigned short id = info.device_id & INTEL_PCH_DEVICE_ID_MASK; 219 ERROR("%s: Intel PCH deviceID: 0x%04x\n", __func__, info.device_id); 220 switch(id) { 221 case INTEL_PCH_IBX_DEVICE_ID: 222 ERROR("%s: Found Ibex Peak PCH\n", __func__); 223 return INTEL_PCH_IBX; 224 case INTEL_PCH_CPT_DEVICE_ID: 225 ERROR("%s: Found CougarPoint PCH\n", __func__); 226 return INTEL_PCH_CPT; 227 case INTEL_PCH_PPT_DEVICE_ID: 228 ERROR("%s: Found PantherPoint PCH\n", __func__); 229 return INTEL_PCH_CPT; 230 case INTEL_PCH_LPT_DEVICE_ID: 231 case INTEL_PCH_LPT_LP_DEVICE_ID: 232 ERROR("%s: Found LynxPoint PCH\n", __func__); 233 return INTEL_PCH_LPT; 234 case INTEL_PCH_WPT_DEVICE_ID: 235 case INTEL_PCH_WPT_LP_DEVICE_ID: 236 ERROR("%s: Found WildcatPoint PCH\n", __func__); 237 return INTEL_PCH_LPT; 238 case INTEL_PCH_SPT_DEVICE_ID: 239 case INTEL_PCH_SPT_LP_DEVICE_ID: 240 ERROR("%s: Found SunrisePoint PCH\n", __func__); 241 return INTEL_PCH_SPT; 242 case INTEL_PCH_KBP_DEVICE_ID: 243 ERROR("%s: Found Kaby Lake PCH\n", __func__); 244 return INTEL_PCH_SPT; 245 case INTEL_PCH_CNP_DEVICE_ID: 246 case INTEL_PCH_CNP_LP_DEVICE_ID: 247 ERROR("%s: Found Cannon Lake PCH\n", __func__); 248 return INTEL_PCH_CNP; 249 case INTEL_PCH_CMP_DEVICE_ID: 250 case INTEL_PCH_CMP2_DEVICE_ID: 251 ERROR("%s: Found Comet Lake PCH\n", __func__); 252 return INTEL_PCH_CNP; 253 case INTEL_PCH_CMP_V_DEVICE_ID: 254 ERROR("%s: Found Comet Lake V PCH\n", __func__); 255 return INTEL_PCH_SPT; 256 case INTEL_PCH_ICP_DEVICE_ID: 257 ERROR("%s: Found Ice Lake PCH\n", __func__); 258 return INTEL_PCH_ICP; 259 case INTEL_PCH_MCC_DEVICE_ID: 260 ERROR("%s: Found Mule Creek Canyon PCH\n", __func__); 261 return INTEL_PCH_MCC; 262 case INTEL_PCH_TGP_DEVICE_ID: 263 case INTEL_PCH_TGP2_DEVICE_ID: 264 ERROR("%s: Found Tiger Lake PCH\n", __func__); 265 return INTEL_PCH_TGP; 266 case INTEL_PCH_JSP_DEVICE_ID: 267 case INTEL_PCH_JSP2_DEVICE_ID: 268 ERROR("%s: Found Jasper Lake PCH\n", __func__); 269 return INTEL_PCH_JSP; 270 case INTEL_PCH_ADP_DEVICE_ID: 271 case INTEL_PCH_ADP2_DEVICE_ID: 272 ERROR("%s: Found Alder Lake PCH\n", __func__); 273 return INTEL_PCH_ADP; 274 } 275 } 276 277 ERROR("%s: No PCH detected.\n", __func__); 278 return INTEL_PCH_NONE; 279 } 280 281 282 extern "C" const char** 283 publish_devices(void) 284 { 285 CALLED(); 286 return (const char**)gDeviceNames; 287 } 288 289 290 extern "C" status_t 291 init_hardware(void) 292 { 293 CALLED(); 294 295 status_t status = get_module(B_PCI_MODULE_NAME,(module_info**)&gPCI); 296 if (status != B_OK) { 297 ERROR("pci module unavailable\n"); 298 return status; 299 } 300 301 int32 cookie = 0; 302 uint32 type; 303 pci_info info; 304 status = get_next_intel_extreme(&cookie, info, type); 305 306 put_module(B_PCI_MODULE_NAME); 307 return status; 308 } 309 310 311 extern "C" status_t 312 init_driver(void) 313 { 314 CALLED(); 315 316 status_t status = get_module(B_PCI_MODULE_NAME, (module_info**)&gPCI); 317 if (status != B_OK) { 318 ERROR("pci module unavailable\n"); 319 return status; 320 } 321 322 status = get_module(B_AGP_GART_MODULE_NAME, (module_info**)&gGART); 323 if (status != B_OK) { 324 ERROR("AGP GART module unavailable\n"); 325 put_module(B_PCI_MODULE_NAME); 326 return status; 327 } 328 329 mutex_init(&gLock, "intel extreme ksync"); 330 331 // Try to get the PCI x86 module as well so we can enable possible MSIs. 332 if (get_module(B_PCI_X86_MODULE_NAME, 333 (module_info **)&gPCIx86Module) != B_OK) { 334 ERROR("failed to get pci x86 module\n"); 335 gPCIx86Module = NULL; 336 } 337 338 // find the PCH device (if any) 339 enum pch_info pchInfo = detect_intel_pch(); 340 341 // find devices 342 343 int32 found = 0; 344 345 for (int32 cookie = 0; found < MAX_CARDS;) { 346 pci_info* info = (pci_info*)malloc(sizeof(pci_info)); 347 if (info == NULL) 348 break; 349 350 uint32 type; 351 status = get_next_intel_extreme(&cookie, *info, type); 352 if (status < B_OK) { 353 free(info); 354 break; 355 } 356 357 // create device names & allocate device info structure 358 359 char name[64]; 360 sprintf(name, "graphics/intel_extreme_%02x%02x%02x", 361 info->bus, info->device, 362 info->function); 363 364 gDeviceNames[found] = strdup(name); 365 if (gDeviceNames[found] == NULL) 366 break; 367 368 gDeviceInfo[found] = (intel_info*)malloc(sizeof(intel_info)); 369 if (gDeviceInfo[found] == NULL) { 370 free(gDeviceNames[found]); 371 break; 372 } 373 374 // initialize the structure for later use 375 376 memset(gDeviceInfo[found], 0, sizeof(intel_info)); 377 gDeviceInfo[found]->init_status = B_NO_INIT; 378 gDeviceInfo[found]->id = found; 379 gDeviceInfo[found]->pci = info; 380 gDeviceInfo[found]->registers = info->u.h0.base_registers[0]; 381 gDeviceInfo[found]->device_identifier = kSupportedDevices[type].name; 382 gDeviceInfo[found]->device_type = kSupportedDevices[type].type; 383 gDeviceInfo[found]->pch_info = pchInfo; 384 385 dprintf(DEVICE_NAME ": (%" B_PRId32 ") %s, revision = 0x%x\n", found, 386 kSupportedDevices[type].name, info->revision); 387 388 found++; 389 } 390 391 gDeviceNames[found] = NULL; 392 393 if (found == 0) { 394 mutex_destroy(&gLock); 395 put_module(B_AGP_GART_MODULE_NAME); 396 put_module(B_PCI_MODULE_NAME); 397 if (gPCIx86Module != NULL) { 398 gPCIx86Module = NULL; 399 put_module(B_PCI_X86_MODULE_NAME); 400 } 401 return ENODEV; 402 } 403 404 return B_OK; 405 } 406 407 408 extern "C" void 409 uninit_driver(void) 410 { 411 CALLED(); 412 413 mutex_destroy(&gLock); 414 415 // free device related structures 416 char* name; 417 for (int32 index = 0; (name = gDeviceNames[index]) != NULL; index++) { 418 free(gDeviceInfo[index]); 419 free(name); 420 } 421 422 put_module(B_AGP_GART_MODULE_NAME); 423 put_module(B_PCI_MODULE_NAME); 424 if (gPCIx86Module != NULL) { 425 gPCIx86Module = NULL; 426 put_module(B_PCI_X86_MODULE_NAME); 427 } 428 } 429 430 431 extern "C" device_hooks* 432 find_device(const char* name) 433 { 434 CALLED(); 435 436 int index; 437 for (index = 0; gDeviceNames[index] != NULL; index++) { 438 if (!strcmp(name, gDeviceNames[index])) 439 return &gDeviceHooks; 440 } 441 442 return NULL; 443 } 444