logo资料库

drm架构解析.pdf

第1页 / 共54页
第2页 / 共54页
第3页 / 共54页
第4页 / 共54页
第5页 / 共54页
第6页 / 共54页
第7页 / 共54页
第8页 / 共54页
资料共54页,剩余部分请下载后查看
Linux DRM Developer's Guide Page 1 of 54 Linux DRM Developer's Guide Jesse Barnes Initial version  Intel Corporation         Laurent Pinchart Driver internals  Ideas on board SPRL         Copyright © 2008-2009, 2012 Intel Corporation, Laurent Pinchart The contents of this file may be used under the terms of the GNU General Public License version 2 (the "GPL") as distributed in the kernel source COPYING file. Revision History Revision 1.0 Added extensive documentation about driver internals. Table of Contents 1. Introduction 2012-07-13 LP http://landley.net/kdocs/htmldocs/drm.html 2013-4-27
Page 2 of 54 Linux DRM Developer's Guide 2. DRM Internals Driver Initialization Driver Information Driver Load Memory management The Translation Table Manager (TTM) The Graphics Execution Manager (GEM) Mode Setting Frame Buffer Creation Output Polling KMS Initialization and Cleanup CRTCs (struct drm_crtc) Planes (struct drm_plane) Encoders (struct drm_encoder) Connectors (struct drm_connector) Cleanup Output discovery and initialization example Mode Setting Helper Functions Helper Functions CRTC Helper Operations Encoder Helper Operations Connector Helper Operations Modeset Helper Functions Reference fbdev Helper Functions Reference Display Port Helper Functions Reference Vertical Blanking http://landley.net/kdocs/htmldocs/drm.html 2013-4-27
Linux DRM Developer's Guide Page 3 of 54 Open/Close, File Operations and IOCTLs Open and Close File Operations IOCTLs Command submission & fencing Suspend/Resume DMA services 3. Userland interfaces VBlank event handling A. DRM Driver API Chapter 1. Introduction The Linux DRM layer contains code intended to support the needs of complex graphics devices, usually containing programmable pipelines well suited to 3D graphics acceleration. Graphics drivers in the kernel may make use of DRM functions to make tasks like memory management, interrupt handling and DMA easier, and provide a uniform interface to applications. A note on versions: this guide covers features found in the DRM tree, including the TTM memory manager, output configuration and mode setting, and the new vblank internals, in addition to all the regular features found in current kernels. [Insert diagram of typical DRM stack here] Chapter 2. DRM Internals Table of Contents Driver Initialization Driver Information Driver Load http://landley.net/kdocs/htmldocs/drm.html 2013-4-27
Linux DRM Developer's Guide Page 4 of 54 Memory management The Translation Table Manager (TTM) The Graphics Execution Manager (GEM) Mode Setting Frame Buffer Creation Output Polling KMS Initialization and Cleanup CRTCs (struct drm_crtc) Planes (struct drm_plane) Encoders (struct drm_encoder) Connectors (struct drm_connector) Cleanup Output discovery and initialization example Mode Setting Helper Functions Helper Functions CRTC Helper Operations Encoder Helper Operations Connector Helper Operations Modeset Helper Functions Reference fbdev Helper Functions Reference Display Port Helper Functions Reference Vertical Blanking Open/Close, File Operations and IOCTLs Open and Close File Operations IOCTLs Command submission & fencing http://landley.net/kdocs/htmldocs/drm.html 2013-4-27
Linux DRM Developer's Guide Suspend/Resume DMA services Page 5 of 54 This chapter documents DRM internals relevant to driver authors and developers working to add support for the latest features to existing drivers. First, we go over some typical driver initialization requirements, like setting up command buffers, creating an initial output configuration, and initializing core services. Subsequent sections cover core internals in more detail, providing implementation notes and examples. The DRM layer provides several services to graphics drivers, many of them driven by the application interfaces it provides through libdrm, the library that wraps most of the DRM ioctls. These include vblank event handling, memory management, output management, framebuffer management, command submission & fencing, suspend/resume support, and DMA services. Driver Initialization At the core of every DRM driver is a drm_driver structure. Drivers typically statically initialize a drm_driver structure, and then pass it to one of the drm_*_init() functions to register it with the DRM subsystem. The drm_driver structure contains static information that describes the driver and features it supports, and pointers to methods that the DRM core will call to implement the DRM API. We will first go through the drm_driver static information fields, and will then describe individual operations in details as they get used in later sections. Driver Information Driver Features Drivers inform the DRM core about their requirements and supported features by setting appropriate flags in the driver_features field. Since those flags influence the DRM core behaviour since registration time, most of them must be set to registering the drm_driver instance. u32 driver_features; Driver Feature Flags DRIVER_USE_AGP Driver uses AGP interface, the DRM core will manage AGP resources. http://landley.net/kdocs/htmldocs/drm.html 2013-4-27
Linux DRM Developer's Guide DRIVER_REQUIRE_AGP Page 6 of 54 Driver needs AGP interface to function. AGP initialization failure will become a fatal error. DRIVER_USE_MTRR Driver uses MTRR interface for mapping memory, the DRM core will manage MTRR resources. Deprecated. DRIVER_PCI_DMA Driver is capable of PCI DMA, mapping of PCI DMA buffers to userspace will be enabled. Deprecated. DRIVER_SG Driver can perform scatter/gather DMA, allocation and mapping of scatter/gather buffers will be enabled. Deprecated. DRIVER_HAVE_DMA Driver supports DMA, the userspace DMA API will be supported. Deprecated. DRIVER_HAVE_IRQ, DRIVER_IRQ_SHARED DRIVER_HAVE_IRQ indicates whether the driver has an IRQ handler. The DRM core will automatically register an interrupt handler when the flag is set. DRIVER_IRQ_SHARED indicates whether the device & handler support shared IRQs (note that this is required of PCI drivers). DRIVER_IRQ_VBL Unused. Deprecated. DRIVER_DMA_QUEUE Should be set if the driver queues DMA requests and completes them asynchronously. Deprecated. DRIVER_FB_DMA Driver supports DMA to/from the framebuffer, mapping of frambuffer DMA buffers to userspace will be supported. Deprecated. DRIVER_IRQ_VBL2 http://landley.net/kdocs/htmldocs/drm.html 2013-4-27
Page 7 of 54 Linux DRM Developer's Guide Unused. Deprecated. DRIVER_GEM Driver use the GEM memory manager. DRIVER_MODESET Driver supports mode setting interfaces (KMS). DRIVER_PRIME Driver implements DRM PRIME buffer sharing. Major, Minor and Patchlevel int major; int minor; int patchlevel; The DRM core identifies driver versions by a major, minor and patch level triplet. The information is printed to the kernel log at initialization time and passed to userspace through the DRM_IOCTL_VERSION ioctl. The major and minor numbers are also used to verify the requested driver API version passed to DRM_IOCTL_SET_VERSION. When the driver API changes between minor versions, applications can call DRM_IOCTL_SET_VERSION to select a specific version of the API. If the requested major isn't equal to the driver major, or the requested minor is larger than the driver minor, the DRM_IOCTL_SET_VERSION call will return an error. Otherwise the driver's set_version() method will be called with the requested version. Name, Description and Date char *name; char *desc; char *date; The driver name is printed to the kernel log at initialization time, used for IRQ registration and passed to userspace through DRM_IOCTL_VERSION. http://landley.net/kdocs/htmldocs/drm.html 2013-4-27
Linux DRM Developer's Guide Page 8 of 54 The driver description is a purely informative string passed to userspace through the DRM_IOCTL_VERSION ioctl and otherwise unused by the kernel. The driver date, formatted as YYYYMMDD, is meant to identify the date of the latest modification to the driver. However, as most drivers fail to update it, its value is mostly useless. The DRM core prints it to the kernel log at initialization time and passes it to userspace through the DRM_IOCTL_VERSION ioctl. Driver Load The load method is the driver and device initialization entry point. The method is responsible for allocating and initializing driver private data, specifying supported performance counters, performing resource allocation and mapping (e.g. acquiring clocks, mapping registers or allocating command buffers), initializing the memory manager (the section called “Memory management”), installing the IRQ handler (the section called “IRQ Registration”), setting up vertical blanking handling (the section called “Vertical Blanking”), mode setting (the section called “Mode Setting”) and initial output configuration (the section called “KMS Initialization and Cleanup”). Note If compatibility is a concern (e.g. with drivers converted over from User Mode Setting to Kernel Mode Setting), care must be taken to prevent device initialization and control that is incompatible with currently active userspace drivers. For instance, if user level mode setting drivers are in use, it would be problematic to perform output discovery & configuration at load time. Likewise, if user-level drivers unaware of memory management are in use, memory management and command buffer setup may need to be omitted. These requirements are driver-specific, and care needs to be taken to keep both old and new applications and libraries working. int (*load) (struct drm_device *, unsigned long flags); The method takes two arguments, a pointer to the newly created drm_device and flags. The flags are used to pass the driver_data field of the device id corresponding to the device passed to drm_*_init(). Only PCI devices currently use this, USB and platform DRM drivers have their load method called with flags to 0. Driver Private & Performance Counters The driver private hangs off the main drm_device structure and can be used for tracking various device-specific bits of information, like register offsets, command buffer status, register state for suspend/resume, etc. At load time, a driver may simply allocate one and set drm_device.dev_priv appropriately; it should be freed and drm_device.dev_priv set to NULL when the driver is unloaded. http://landley.net/kdocs/htmldocs/drm.html 2013-4-27
分享到:
收藏