1 /* 2 * Copyright 2006-2007, 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 #ifndef INTEL_EXTREME_H 9 #define INTEL_EXTREME_H 10 11 12 #include "lock.h" 13 14 #include <memory_manager.h> 15 16 #include <Accelerant.h> 17 #include <Drivers.h> 18 #include <PCI.h> 19 20 21 #define VENDOR_ID_INTEL 0x8086 22 23 #define INTEL_TYPE_FAMILY_MASK 0x0f 24 #define INTEL_TYPE_GROUP_MASK 0xf0 25 #define INTEL_TYPE_7xx 0x01 26 #define INTEL_TYPE_8xx 0x02 27 #define INTEL_TYPE_9xx 0x04 28 #define INTEL_TYPE_83x 0x10 29 #define INTEL_TYPE_85x 0x20 30 #define INTEL_TYPE_915 0x10 31 #define INTEL_TYPE_945 0x20 32 #define INTEL_TYPE_965 0x40 33 34 #define DEVICE_NAME "intel_extreme" 35 #define INTEL_ACCELERANT_NAME "intel_extreme.accelerant" 36 37 // info about PLL on graphics card 38 struct pll_info { 39 uint32 reference_frequency; 40 uint32 max_frequency; 41 uint32 min_frequency; 42 uint32 divisor_register; 43 }; 44 45 struct ring_buffer { 46 struct lock lock; 47 uint32 register_base; 48 uint32 handle; 49 uint32 offset; 50 uint32 size; 51 uint32 position; 52 uint8 *base; 53 }; 54 55 struct overlay_registers; 56 57 struct intel_shared_info { 58 area_id mode_list_area; // area containing display mode list 59 uint32 mode_count; 60 61 display_mode current_mode; 62 uint32 bytes_per_row; 63 uint32 bits_per_pixel; 64 uint32 dpms_mode; 65 66 area_id registers_area; // area of memory mapped registers 67 uint8 *physical_status_page; 68 uint8 *physical_cursor_memory; 69 area_id graphics_memory_area; 70 uint8 *graphics_memory; 71 uint8 *physical_graphics_memory; 72 uint32 graphics_memory_size; 73 74 uint32 frame_buffer_offset; 75 76 struct lock accelerant_lock; 77 struct lock engine_lock; 78 79 ring_buffer primary_ring_buffer; 80 ring_buffer secondary_ring_buffer; 81 82 int32 overlay_channel_used; 83 bool overlay_active; 84 uint32 overlay_token; 85 uint8* physical_overlay_registers; 86 87 bool hardware_cursor_enabled; 88 sem_id vblank_sem; 89 90 uint32 cursor_buffer_offset; 91 uint32 cursor_format; 92 bool cursor_visible; 93 uint16 cursor_hot_x; 94 uint16 cursor_hot_y; 95 96 uint32 device_type; 97 char device_identifier[32]; 98 struct pll_info pll_info; 99 }; 100 101 //----------------- ioctl() interface ---------------- 102 103 // magic code for ioctls 104 #define INTEL_PRIVATE_DATA_MAGIC 'itic' 105 106 // list ioctls 107 enum { 108 INTEL_GET_PRIVATE_DATA = B_DEVICE_OP_CODES_END + 1, 109 110 INTEL_GET_DEVICE_NAME, 111 INTEL_ALLOCATE_GRAPHICS_MEMORY, 112 INTEL_FREE_GRAPHICS_MEMORY 113 }; 114 115 // retrieve the area_id of the kernel/accelerant shared info 116 struct intel_get_private_data { 117 uint32 magic; // magic number 118 area_id shared_info_area; 119 }; 120 121 // allocate graphics memory 122 struct intel_allocate_graphics_memory { 123 uint32 magic; 124 uint32 size; 125 uint32 buffer_offset; 126 uint32 handle; 127 }; 128 129 // free graphics memory 130 struct intel_free_graphics_memory { 131 uint32 magic; 132 uint32 handle; 133 }; 134 135 //---------------------------------------------------------- 136 // Register definitions, taken from X driver 137 138 // PCI bridge memory management 139 #define INTEL_GRAPHICS_MEMORY_CONTROL 0x52 140 #define STOLEN_MEMORY_MASK 0x70 141 142 // models i830 and up 143 #define i830_LOCAL_MEMORY_ONLY 0x10 144 #define i830_STOLEN_512K 0x20 145 #define i830_STOLEN_1M 0x30 146 #define i830_STOLEN_8M 0x40 147 148 // models i855 and up 149 #define i855_STOLEN_MEMORY_1M 0x10 150 #define i855_STOLEN_MEMORY_4M 0x20 151 #define i855_STOLEN_MEMORY_8M 0x30 152 #define i855_STOLEN_MEMORY_16M 0x40 153 #define i855_STOLEN_MEMORY_32M 0x50 154 #define i855_STOLEN_MEMORY_48M 0x60 155 #define i855_STOLEN_MEMORY_64M 0x70 156 157 // graphics page translation table 158 #define INTEL_PAGE_TABLE_CONTROL 0x02020 159 #define INTEL_PAGE_TABLE_ERROR 0x02024 160 #define INTEL_HARDWARE_STATUS_PAGE 0x02080 161 #define INTEL_GTT_BASE 0x10000 // (- 0x2ffff) 162 #define GTT_ENTRY_VALID 0x01 163 #define GTT_ENTRY_LOCAL_MEMORY 0x02 164 165 // interrupts 166 #define INTEL_INTERRUPT_ENABLED 0x020a0 167 #define INTEL_INTERRUPT_IDENTITY 0x020a4 168 #define INTEL_INTERRUPT_MASK 0x020a8 169 #define INTEL_INTERRUPT_STATUS 0x020ac 170 #define INTERRUPT_VBLANK (1 << 7) 171 172 // ring buffer 173 #define INTEL_PRIMARY_RING_BUFFER 0x02030 174 #define INTEL_SECONDARY_RING_BUFFER_0 0x02100 175 #define INTEL_SECONDARY_RING_BUFFER_1 0x02110 176 // offsets for the ring buffer base registers above 177 #define RING_BUFFER_TAIL 0x0 178 #define RING_BUFFER_HEAD 0x4 179 #define RING_BUFFER_START 0x8 180 #define RING_BUFFER_CONTROL 0xc 181 #define INTEL_RING_BUFFER_SIZE_MASK 0x000ff800 182 #define INTEL_RING_BUFFER_HEAD_MASK 0x001ffffc 183 #define INTEL_RING_BUFFER_ENABLED 1 184 185 // display A 186 #define INTEL_DISPLAY_A_HTOTAL 0x60000 187 #define INTEL_DISPLAY_A_HBLANK 0x60004 188 #define INTEL_DISPLAY_A_HSYNC 0x60008 189 #define INTEL_DISPLAY_A_VTOTAL 0x6000c 190 #define INTEL_DISPLAY_A_VBLANK 0x60010 191 #define INTEL_DISPLAY_A_VSYNC 0x60014 192 #define INTEL_DISPLAY_A_IMAGE_SIZE 0x6001c 193 194 #define INTEL_DISPLAY_A_CONTROL 0x70180 195 #define INTEL_DISPLAY_A_BASE 0x70184 196 #define INTEL_DISPLAY_A_BYTES_PER_ROW 0x70188 197 #define DISPLAY_CONTROL_ENABLED (1UL << 31) 198 #define DISPLAY_CONTROL_GAMMA (1UL << 30) 199 #define DISPLAY_CONTROL_COLOR_MASK (0x0fUL << 26) 200 #define DISPLAY_CONTROL_CMAP8 (2UL << 26) 201 #define DISPLAY_CONTROL_RGB15 (4UL << 26) 202 #define DISPLAY_CONTROL_RGB16 (5UL << 26) 203 #define DISPLAY_CONTROL_RGB32 (7UL << 26) 204 205 #define INTEL_VGA_DISPLAY_CONTROL 0x71400 206 #define VGA_DISPLAY_DISABLED (1UL << 31) 207 208 #define INTEL_DISPLAY_A_PALETTE 0x0a000 209 210 #define INTEL_DISPLAY_A_PIPE_CONTROL 0x70008 211 #define DISPLAY_PIPE_ENABLED (1UL << 31) 212 #define INTEL_DISPLAY_A_PIPE_STATUS 0x70024 213 #define DISPLAY_PIPE_VBLANK_ENABLED (1UL << 17) 214 #define DISPLAY_PIPE_VBLANK_STATUS (1UL << 1) 215 216 #define INTEL_DISPLAY_A_PLL 0x06014 217 #define INTEL_DISPLAY_A_PLL_DIVISOR_0 0x06040 218 #define INTEL_DISPLAY_A_PLL_DIVISOR_1 0x06044 219 #define DISPLAY_PLL_ENABLED (1UL << 31) 220 #define DISPLAY_PLL_2X_CLOCK (1UL << 30) 221 #define DISPLAY_PLL_SYNC_LOCK_ENABLED (1UL << 29) 222 #define DISPLAY_PLL_NO_VGA_CONTROL (1UL << 28) 223 #define DISPLAY_PLL_MODE_ANALOG (1UL << 26) 224 #define DISPLAY_PLL_DIVIDE_HIGH (1UL << 24) 225 #define DISPLAY_PLL_DIVIDE_4X (1UL << 23) 226 #define DISPLAY_PLL_POST1_DIVISOR_MASK 0x001f0000 227 #define DISPLAY_PLL_9xx_POST1_DIVISOR_MASK 0x00ff0000 228 #define DISPLAY_PLL_POST1_DIVISOR_SHIFT 16 229 #define DISPLAY_PLL_DIVISOR_1 (1UL << 8) 230 #define DISPLAY_PLL_N_DIVISOR_MASK 0x001f0000 231 #define DISPLAY_PLL_M1_DIVISOR_MASK 0x00001f00 232 #define DISPLAY_PLL_M2_DIVISOR_MASK 0x0000001f 233 #define DISPLAY_PLL_N_DIVISOR_SHIFT 16 234 #define DISPLAY_PLL_M1_DIVISOR_SHIFT 8 235 #define DISPLAY_PLL_M2_DIVISOR_SHIFT 0 236 #define DISPLAY_PLL_PULSE_PHASE_SHIFT 9 237 238 #define INTEL_DISPLAY_A_ANALOG_PORT 0x61100 239 #define DISPLAY_MONITOR_PORT_ENABLED (1UL << 31) 240 #define DISPLAY_MONITOR_VGA_POLARITY (1UL << 15) 241 #define DISPLAY_MONITOR_MODE_MASK (3UL << 10) 242 #define DISPLAY_MONITOR_ON 0 243 #define DISPLAY_MONITOR_SUSPEND (1UL << 10) 244 #define DISPLAY_MONITOR_STAND_BY (2UL << 10) 245 #define DISPLAY_MONITOR_OFF (3UL << 10) 246 #define DISPLAY_MONITOR_POLARITY_MASK (3UL << 3) 247 #define DISPLAY_MONITOR_POSITIVE_HSYNC (1UL << 3) 248 #define DISPLAY_MONITOR_POSITIVE_VSYNC (2UL << 3) 249 250 // display B 251 #define INTEL_DISPLAY_B_DIGITAL_PORT 0x61140 252 #define INTEL_DISPLAY_B_IMAGE_SIZE 0x6101c 253 254 #define INTEL_DISPLAY_B_PIPE_CONTROL 0x71008 255 256 #define INTEL_DISPLAY_B_CONTROL 0x71180 257 #define INTEL_DISPLAY_B_BASE 0x71184 258 #define INTEL_DISPLAY_B_BYTES_PER_ROW 0x71188 259 260 #define INTEL_DISPLAY_B_PALETTE 0x0a800 261 262 #define INTEL_DISPLAY_A_DIGITAL_PORT 0x61120 263 #define INTEL_DISPLAY_C_DIGITAL 0x61160 264 #define INTEL_DISPLAY_LVDS_PORT 0x61180 265 266 // cursor 267 #define INTEL_CURSOR_CONTROL 0x70080 268 #define INTEL_CURSOR_BASE 0x70084 269 #define INTEL_CURSOR_POSITION 0x70088 270 #define INTEL_CURSOR_PALETTE 0x70090 // (- 0x7009f) 271 #define INTEL_CURSOR_SIZE 0x700a0 272 #define CURSOR_ENABLED (1UL << 31) 273 #define CURSOR_FORMAT_2_COLORS (0UL << 24) 274 #define CURSOR_FORMAT_3_COLORS (1UL << 24) 275 #define CURSOR_FORMAT_4_COLORS (2UL << 24) 276 #define CURSOR_FORMAT_ARGB (4UL << 24) 277 #define CURSOR_FORMAT_XRGB (5UL << 24) 278 #define CURSOR_POSITION_NEGATIVE 0x8000 279 #define CURSOR_POSITION_MASK 0x3fff 280 281 // ring buffer commands 282 283 #define COMMAND_NOOP 0x00 284 #define COMMAND_WAIT_FOR_EVENT (0x03 << 23) 285 #define COMMAND_WAIT_FOR_OVERLAY_FLIP (1 << 16) 286 287 #define COMMAND_FLUSH (0x04 << 23) 288 289 // overlay flip 290 #define COMMAND_OVERLAY_FLIP (0x11 << 23) 291 #define COMMAND_OVERLAY_CONTINUE (0 << 21) 292 #define COMMAND_OVERLAY_ON (1 << 21) 293 #define COMMAND_OVERLAY_OFF (2 << 21) 294 #define OVERLAY_UPDATE_COEFFICIENTS 0x1 295 296 // 2D acceleration 297 #define XY_COMMAND_SOURCE_BLIT 0x54c00006 298 #define XY_COMMAND_COLOR_BLIT 0x54000004 299 #define XY_COMMAND_SETUP_MONO_PATTERN 0x44400007 300 #define XY_COMMAND_SCANLINE_BLIT 0x49400001 301 #define COMMAND_COLOR_BLIT 0x50000003 302 #define COMMAND_BLIT_RGBA 0x00300000 303 304 #define COMMAND_MODE_SOLID_PATTERN 0x80 305 #define COMMAND_MODE_CMAP8 0x00 306 #define COMMAND_MODE_RGB15 0x02 307 #define COMMAND_MODE_RGB16 0x01 308 #define COMMAND_MODE_RGB32 0x03 309 310 // overlay 311 312 #define INTEL_OVERLAY_UPDATE 0x30000 313 #define INTEL_OVERLAY_TEST 0x30004 314 #define INTEL_OVERLAY_STATUS 0x30008 315 #define INTEL_OVERLAY_EXTENDED_STATUS 0x3000c 316 #define INTEL_OVERLAY_GAMMA_5 0x30010 317 #define INTEL_OVERLAY_GAMMA_4 0x30014 318 #define INTEL_OVERLAY_GAMMA_3 0x30018 319 #define INTEL_OVERLAY_GAMMA_2 0x3001c 320 #define INTEL_OVERLAY_GAMMA_1 0x30020 321 #define INTEL_OVERLAY_GAMMA_0 0x30024 322 323 struct overlay_scale { 324 uint32 _reserved0 : 3; 325 uint32 horizontal_scale_fraction : 12; 326 uint32 _reserved1 : 1; 327 uint32 horizontal_downscale_factor : 3; 328 uint32 _reserved2 : 1; 329 uint32 vertical_scale_fraction : 12; 330 }; 331 332 #define OVERLAY_FORMAT_RGB15 0x2 333 #define OVERLAY_FORMAT_RGB16 0x3 334 #define OVERLAY_FORMAT_RGB32 0x1 335 #define OVERLAY_FORMAT_YCbCr422 0x8 336 #define OVERLAY_FORMAT_YCbCr411 0x9 337 #define OVERLAY_FORMAT_YCbCr420 0xc 338 339 #define OVERLAY_MIRROR_NORMAL 0x0 340 #define OVERLAY_MIRROR_HORIZONTAL 0x1 341 #define OVERLAY_MIRROR_VERTICAL 0x2 342 343 // The real overlay registers are written to using an update buffer 344 345 struct overlay_registers { 346 uint32 buffer_rgb0; 347 uint32 buffer_rgb1; 348 uint32 buffer_u0; 349 uint32 buffer_v0; 350 uint32 buffer_u1; 351 uint32 buffer_v1; 352 // (0x18) OSTRIDE - overlay stride 353 uint16 stride_rgb; 354 uint16 stride_uv; 355 // (0x1c) YRGB_VPH - Y/RGB vertical phase 356 uint16 vertical_phase0_rgb; 357 uint16 vertical_phase1_rgb; 358 // (0x20) UV_VPH - UV vertical phase 359 uint16 vertical_phase0_uv; 360 uint16 vertical_phase1_uv; 361 // (0x24) HORZ_PH - horizontal phase 362 uint16 horizontal_phase_rgb; 363 uint16 horizontal_phase_uv; 364 // (0x28) INIT_PHS - initial phase shift 365 uint32 initial_vertical_phase0_shift_rgb0 : 4; 366 uint32 initial_vertical_phase1_shift_rgb0 : 4; 367 uint32 initial_horizontal_phase_shift_rgb0 : 4; 368 uint32 initial_vertical_phase0_shift_uv : 4; 369 uint32 initial_vertical_phase1_shift_uv : 4; 370 uint32 initial_horizontal_phase_shift_uv : 4; 371 uint32 _reserved0 : 8; 372 // (0x2c) DWINPOS - destination window position 373 uint16 window_left; 374 uint16 window_top; 375 // (0x30) DWINSZ - destination window size 376 uint16 window_width; 377 uint16 window_height; 378 // (0x34) SWIDTH - source width 379 uint16 source_width_rgb; 380 uint16 source_width_uv; 381 // (0x38) SWITDHSW - source width in 8 byte steps 382 uint16 source_bytes_per_row_rgb; 383 uint16 source_bytes_per_row_uv; 384 uint16 source_height_rgb; 385 uint16 source_height_uv; 386 overlay_scale scale_rgb; 387 overlay_scale scale_uv; 388 // (0x48) OCLRC0 - overlay color correction 0 389 uint32 brightness_correction : 8; // signed, -128 to 127 390 uint32 _reserved1 : 10; 391 uint32 contrast_correction : 9; // fixed point: 3.6 bits 392 uint32 _reserved2 : 5; 393 // (0x4c) OCLRC1 - overlay color correction 1 394 uint32 saturation_cos_correction : 10; // fixed point: 3.7 bits 395 uint32 _reserved3 : 6; 396 uint32 saturation_sin_correction : 11; // signed fixed point: 3.7 bits 397 uint32 _reserved4 : 5; 398 // (0x50) DCLRKV - destination color key value 399 uint32 color_key_blue : 8; 400 uint32 color_key_green : 8; 401 uint32 color_key_red : 8; 402 uint32 _reserved5 : 8; 403 // (0x54) DCLRKM - destination color key mask 404 uint32 color_key_mask_blue : 8; 405 uint32 color_key_mask_green : 8; 406 uint32 color_key_mask_red : 8; 407 uint32 _reserved6 : 7; 408 uint32 color_key_enabled : 1; 409 // (0x58) SCHRKVH - source chroma key high value 410 uint32 source_chroma_key_high_red : 8; 411 uint32 source_chroma_key_high_blue : 8; 412 uint32 source_chroma_key_high_green : 8; 413 uint32 _reserved7 : 8; 414 // (0x5c) SCHRKVL - source chroma key low value 415 uint32 source_chroma_key_low_red : 8; 416 uint32 source_chroma_key_low_blue : 8; 417 uint32 source_chroma_key_low_green : 8; 418 uint32 _reserved8 : 8; 419 // (0x60) SCHRKEN - source chroma key enable 420 uint32 _reserved9 : 24; 421 uint32 source_chroma_key_red_enabled : 1; 422 uint32 source_chroma_key_blue_enabled : 1; 423 uint32 source_chroma_key_green_enabled : 1; 424 uint32 _reserved10 : 5; 425 // (0x64) OCONFIG - overlay configuration 426 uint32 _reserved11 : 3; 427 uint32 color_control_output_mode : 1; 428 uint32 yuv_to_rgb_bypass : 1; 429 uint32 _reserved12 : 11; 430 uint32 gamma2_enabled : 1; 431 uint32 _reserved13 : 1; 432 uint32 select_pipe : 1; 433 uint32 slot_time : 8; 434 uint32 _reserved14 : 5; 435 // (0x68) OCOMD - overlay command 436 uint32 overlay_enabled : 1; 437 uint32 active_field : 1; 438 uint32 active_buffer : 2; 439 uint32 test_mode : 1; 440 uint32 buffer_field_mode : 1; 441 uint32 _reserved15 : 1; 442 uint32 tv_flip_field_enabled : 1; 443 uint32 _reserved16 : 1; 444 uint32 tv_flip_field_parity : 1; 445 uint32 source_format : 4; 446 uint32 ycbcr422_order : 2; 447 uint32 _reserved18 : 1; 448 uint32 mirroring_mode : 2; 449 uint32 _reserved19 : 13; 450 451 uint32 _reserved20; 452 453 // (0x70) AWINPOS - alpha blend window position 454 uint32 awinpos; 455 // (0x74) AWINSZ - alpha blend window size 456 uint32 awinsz; 457 458 uint32 _reserved21[10]; 459 460 // (0xa0) FASTHSCALE - fast horizontal downscale (strangely enough, 461 // the next two registers switch the usual Y/RGB vs. UV order) 462 uint16 horizontal_scale_uv; 463 uint16 horizontal_scale_rgb; 464 // (0xa4) UVSCALEV - vertical downscale 465 uint16 vertical_scale_uv; 466 uint16 vertical_scale_rgb; 467 468 uint32 _reserved22[86]; 469 470 // (0x200) polyphase filter coefficients 471 uint16 vertical_coefficients_rgb[128]; 472 uint16 horizontal_coefficients_rgb[128]; 473 474 uint32 _reserved23[64]; 475 476 // (0x500) 477 uint16 vertical_coefficients_uv[128]; 478 uint16 horizontal_coefficients_uv[128]; 479 }; 480 481 struct hardware_status { 482 uint32 interrupt_status_register; 483 uint32 _reserved0[3]; 484 void *primary_ring_head_storage; 485 uint32 _reserved1[3]; 486 void *secondary_ring_0_head_storage; 487 void *secondary_ring_1_head_storage; 488 uint32 _reserved2[2]; 489 void *binning_head_storage; 490 uint32 _reserved3[3]; 491 uint32 store[1008]; 492 }; 493 494 #endif /* INTEL_EXTREME_H */ 495