Intel HD Graphics 驱动支持实现指南(Ironlake)
文章目录
简介
本页介绍为 Intel 集成显卡技术实现驱动支持。目前仅涵盖第一代 'Intel HD graphics',代号 Ironlake。请注意,显卡驱动相当复杂,虽然 Intel 的显卡驱动相对简单,但这仍是一个不适合新手的主题,建议在尝试之前具备为其他现代硬件编写驱动的一些经验。此外,读者需自行承担因本文档不准确而造成的任何损害。
对设备进行试验
有多种工具可用于研究显卡设备在较简单任务中的行为,从而理解某项操作是如何完成的。一种方法是使用 Intel 的显卡调试工具(intel-gpu-tools 软件包),它允许从终端读写设备寄存器。这非常有用,例如,这种方法在研究 GMBUS 时被证明是不可或缺的。使用 GRUB2 内置终端也可以完成同样的操作,先通过 lspci 获取 MMIO 基址,然后使用读/写命令(read_byte/read_word/read_dword 和 write_byte/write_word/write_dword)对目标寄存器执行相应操作。
寄存器位置与定义
许多寄存器可能在不同代际之间移动,或被一组完全不同的寄存器取代,本文会在可能之处做出适当说明,但建议在阅读本文档的同时参考目标代际的编程参考手册。此外,Cardinal 驱动的寄存器位置定义可在 Cardinal GitHub 找到。
推荐阅读
在着手处理显卡/显示驱动之前,强烈建议进行一些额外阅读,这将有助于澄清官方 PRM 中使用的许多设计和术语。建议理解以下内容:
- EDID
- I2C
- DisplayPort
- Intel 集成显卡编程参考手册(PRM)
- OpenGL 4.0+/Vulkan/DirectX 9+:只有在你打算实现 3D 加速时才真正需要。在更高层次上理解图形流水线如何运作和组织,将有助于理解显卡芯片组暴露的硬件层结构。
显卡北桥与南桥
显示控制器流水线结构根据速度需求和整体用途被拆分为两个组件。北桥直接连接到处理器,用于内置显示以及显示管道(display pipe)和各种平面(plane)。南桥包含外部端口和 GMBUS(Graphics Management Bus)。GMBUS 是一种 I2C 兼容协议,用于与设备通信以获取信息(例如显示器的 EDID)。两个桥通过发送器和接收器机制通信;具体做法是为南桥上的显示器分配 FDI,并配置北桥上的显示管道以从分配的 FDI 接收。该系统在 #Display Pipeline Structure 一节中详细讨论。
PCI 接口与显存
PCI BAR 0(偏移 0x10)和 2(偏移 0x18)分别包含 MMIO 区域和可侦测(snooped)显存的 64 位地址。
内置显示器背光
显示器背光由 PWM(脉宽调制)单元控制。对于内置 LVDS 显示器,PWM 初始化寄存器位于南桥,而实际控制值则由北桥上的一个寄存器指定。
显示器检测
显示器检测可以通过轮询或使用中断来完成。这里讨论中断方法。
GMBUS 寄存器与 EDID
GMBUS(Graphics Management Bus)是一种 I2C 兼容协议,用于与所连接的显示器通信以获取其信息,例如 EDID。此方法不能用于读取 DisplayPort 设备的 EDID,而应使用 AUX CH。
要获取设备的 EDID,我们需要从目标设备的 I2C 设备索引 0、偏移 0x50 处读取 0x80 字节。
以下执行序列演示了如何检索前 8 字节:
void igfx_gmbus_reset(igfx_dev_state_t *driver) { igfx_write32(driver, driver->display_mmio_base + IGFX_GMBUS1, 0); igfx_gmbus_enable_writeprot(driver); igfx_gmbus_disable_writeprot(driver); } void igfx_gmbus_wait(igfx_dev_state_t *driver) { while (!(igfx_read32(driver, driver->display_mmio_base + IGFX_GMBUS2) & (1 << 11))) ; } void igfx_gmbus_stoptransaction(igfx_dev_state_t *driver) { igfx_write32(driver, driver->display_mmio_base + IGFX_GMBUS1, (1 << 30) | (1 << 27)); } void igfx_gmbus_read(igfx_dev_state_t *driver, uint32_t disp_idx, uint8_t offset, uint16_t sz, uint8_t *buf) { uint32_t gmbus0_val = 0; uint32_t gmbus1_val = 0; if (driver->device->arch == IGFX_CHERRYTRAIL) { if (disp_idx == 0) gmbus0_val = 3; } gmbus1_val = (1 << 30) /*SW Ready*/ | (1 << 25) /*WAIT*/ | (1 << 26) /*INDEX*/ | (sz & 511) << 16 | ((offset & 127) << 1) | 1 /*READ*/; igfx_gmbus_reset(driver); igfx_write32(driver, driver->display_mmio_base + IGFX_GMBUS0, gmbus0_val); igfx_write32(driver, driver->display_mmio_base + IGFX_GMBUS1, gmbus1_val); for (int i = 0; i < sz; i += 4) { igfx_gmbus_wait(driver); uint32_t bytes = igfx_read32(driver, driver->display_mmio_base + IGFX_GMBUS3); buf[i] = bytes & 0xFF; if (sz > i + 1) buf[i + 1] = (bytes >> 8) & 0xFF; if (sz > i + 2) buf[i + 2] = (bytes >> 16) & 0xFF; if (sz > i + 3) buf[i + 3] = (bytes >> 24) & 0xFF; } igfx_gmbus_stoptransaction(driver); print_hexdump(buf, sz); }
从 DisplayPort 设备获取 EDID
要与 DisplayPort 设备通信,你需要使用以下寄存器:
| 寄存器 | 描述 |
|---|---|
| DDI_AUX_CTL | 用于发起 AUX CH 请求的寄存器 |
| DP_AUX_CTL | |
| DDI_AUX_DATA | 一组 5 个寄存器,用于发送最多 20 字节的数据 |
| DP_AUX_DATA | |
| SRD_AUX_CTL | 如果使用 DDI_AUX 寄存器则必须禁用的寄存器 |
有关寄存器地址和潜在勘误,请参阅 Intel 编程手册。
要发送请求,首先将 AUX CH 数据包复制到数据寄存器,从第一个寄存器的高字节开始。然后通过设置消息长度和 send_busy 位来发起请求。等待 done 位或任一错误位置位,然后读取消息长度以及从数据寄存器中读取相应数量的数据。
注意,CTL 寄存器中的所有其他位都应保留,因此在切换任何位之前先加载寄存器。
显示流水线结构
显示管道
显示 FDI
显示平面
每个管道提供三种显示平面,即:
- 显示平面
- 光标平面
- 视频/精灵平面
还提供 VGA 平面,允许使用每个 Intel 显卡设备中都存在的 VGA 仿真硬件,但其功能非常有限,作者不建议使用。
除光标平面(在弹出式光标模式下)外,其他任何平面都不能与 VGA 平面同时启用。
显示平面提供高分辨率帧缓冲,需要先启用它,其他平面(VGA 平面除外)才能工作。
顾名思义,光标平面提供硬件加速的光标绘制。类似地,视频/精灵平面提供第二个源,可以绘制在显示平面之上,其目的是通过允许解码后的数据直接绘制到窗口,从而高效使用视频解码硬件。
简单模式设置序列
简单模式设置序列可用于默认/内置显示器,前提是引导固件已正确配置显示时序。如果不是,则需要执行包含显示电源循环的完整模式设置操作。
由于这将依赖于固件已配置好的显示器,第一步是弄清端口与管道之间的映射及其状态。
以下信息基于 intel_reg_dumper 工具针对 Haswell 集成显卡的输出:
Ports: There are 5 ports: A,B,C,D,E These represent connections to displays. The EDP port is always port A The important registers here are: PORT_CLK_SEL_[A-E] DP_TP_CTL_[A-E] DDI_BUF_CTL_A[A-E] Pipes: There are 3 general pipes A,B,C and 1 'specialized' EDP pipe that actually maps to Pipe A. Additionally, the EDP pipe (and DDI A) can only run in DP single stream (SST) mode. Pipes handle display timings/resolution settings, with the following registers:
SFUSE_STRAP : This controls overall display capability (can disable all display output - forcing the use of external graphics), VGA port capability (can disable the physical VGA port) and the physical presence of ports on the device (regardless of if the port has something plugged in).
PIPE_DDI_FUNC_CTL_[A-C,EDP] : Used to control how the system 'talks' to the device (HDMI/DisplayPort SST/DisplayPort MST), bits per channel, VSync and HSync polarities (from EDID)
WM_PIPE_[A-C] : These control when the controller generates memory accesses for pixels, the values depend on the timing information as obtained from the EDID, the exact calculation process is described in the Display Watermark section of the PRMs.
WM_LP{1-3]: Configures the memory access timings for low power mode, the associated WM_LINETIME_[A-C] must be programmed before enabling one of these.
WM_LINETIME_[A-C]: Configures the line timings for low power mode based on the horizontal resolution
PIPE_SRCSZ_[A-C]: Contains the horizontal and vertical pixel width of the output. PIPE_CONF_[A-C/EDP]: Enable/disable the pipe and some features
These registers are all based on the desired resolution, and are fairly well documented in the PRM, they rely on the EDID information. HTOTAL_[A-C/EDP] HBLANK_[A-C/EDP] HSYNC_[A-C/EDP] VTOTAL_[A-C/EDP] VBLANK_[A-C/EDP] VSYNC_[A-C/EDP] VSYNCSHIFT_[A-C/EDP]
Refresh rate timing: The calculation for these values is described in the Display chapter, section "Pipe M/N Values": Used for normal power mode: PIPE_DATA_M1 PIPE_DATA_N1 PIPE_LINK_M1 PIPE_LINK_N1
Used for low power mode: PIPE_DATA_M2 PIPE_DATA_N2 PIPE_LINK_M2 PIPE_LINK_N2
Once the above are configured as desired, the panels may be configured and used. For display output, the Primary panel is most interesting, followed by the cursor panel if a hardware cursor is desired. The EDP pipe uses Pipe A's panels.
The Primary panel has the following registers: PRI_CTL_[A-C]: Enable/Disable the panel, gamma mode, pixel format, tiling, rotation PRI_STRIDE_[A-C]: Configure the pixel stride when reading the framebuffer (in multiples of 64-bytes) PRI_SURF_[A-C]: Configure the physical address of the framebuffer, this must be mapped via the global GTT PRI_OFFSET_[A-C]: Configure the pixel offset from which to start reading
因此,只要显示器已经初始化,就可以通过直接更新主面板寄存器,然后是水平和垂直 TOTAL/BLANK/SYNC 寄存器,接着是 M/N 时序,最后是 WM 时序,来执行非常粗糙的模式设置。通过禁用然后重新启用管道,可能使该过程更干净,但尚未确认这样做是否能在无需重新校准的情况下恢复显示。不过,显示校准似乎由显卡芯片组本身处理,因此正确地执行模式设置(modesetting)可能相对简单(后续更新)。
完整模式设置序列
完整模式设置序列比简单序列长得多,但只要 EDID 有效,它保证可与所有已连接的显示器配合工作。该序列包括完全禁用显示器、重新配置 FDI 和管道的时序,然后重新开启显示器。
步骤如下:
链路训练注意事项
DDI_BUF_TRANS must be configured with voltage swing information, as specified in the Display chapter, "DDI Buffer" section
- Set the number of enabled lanes via writes to AUX 0x101, and configure the lanes,
First step of training is to set training pattern 1 and try voltage settings from smallest to largest until clock recovery is achieved - First set the sink device (via AUX channel/GMBUS) to start receiving training pattern 1 by performing a burst write to AUX 0x102-0x106, setting the lanes to expect training pattern 1 with the currently testing voltage level - Set the integrated graphics (DDI_TP_CTL) to send training pattern 1 - Wait 500us - Read offset 0x202 from the AUX channel to get the link status to determine if training was successful. - If none of the voltage levels work, reduce the bitrate and try again
- For eDP, the voltage settings can be precallibrated, allowing skipping the clock recovery process, this is determined by AUX address 0x3 bit 6 (see section 3.5.1.3 of the DisplayPort 1.4 spec)
Second training step is to determine the pre-emphasis, it's very similar to the first step, but using training pattern 2. Clock recovery may be lost in this step, in which case the clock recovery training must be restarted. Once pre-emphasis training is done, the link is ready.
DisplayPort 1.4 规范:[1]
显卡虚拟内存配置
环形缓冲区
Blitter - Block Litigated Transfer 引擎
3D 流水线
另请参阅
- Intel 编程手册 (PRM),适用于 Intel HD Graphics 设备。
来源与翻译说明
本文根据原文快照翻译,保留原有代码、数值、技术限定及历史背景。原文中的命令与运行结果不代表本站已实际执行验证。
原文:Intel HD Graphics;离线修订号:30452。对应原文版本

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论