12fa91d15SJani Nikula========================= 22fa91d15SJani NikulaKernel Mode Setting (KMS) 32fa91d15SJani Nikula========================= 42fa91d15SJani Nikula 52fa91d15SJani NikulaDrivers must initialize the mode setting core by calling 62fa91d15SJani Nikula:c:func:`drm_mode_config_init()` on the DRM device. The function 72fa91d15SJani Nikulainitializes the :c:type:`struct drm_device <drm_device>` 82fa91d15SJani Nikulamode_config field and never fails. Once done, mode configuration must 92fa91d15SJani Nikulabe setup by initializing the following fields. 102fa91d15SJani Nikula 112fa91d15SJani Nikula- int min_width, min_height; int max_width, max_height; 122fa91d15SJani Nikula Minimum and maximum width and height of the frame buffers in pixel 132fa91d15SJani Nikula units. 142fa91d15SJani Nikula 152fa91d15SJani Nikula- struct drm_mode_config_funcs \*funcs; 162fa91d15SJani Nikula Mode setting functions. 172fa91d15SJani Nikula 18949619f3SDaniel VetterModeset Base Object Abstraction 19949619f3SDaniel Vetter=============================== 20949619f3SDaniel Vetter 21949619f3SDaniel Vetter.. kernel-doc:: include/drm/drm_mode_object.h 22949619f3SDaniel Vetter :internal: 23949619f3SDaniel Vetter 24949619f3SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_mode_object.c 25949619f3SDaniel Vetter :export: 26949619f3SDaniel Vetter 27311b62d9SDaniel VetterKMS Data Structures 28311b62d9SDaniel Vetter=================== 292fa91d15SJani Nikula 30311b62d9SDaniel Vetter.. kernel-doc:: include/drm/drm_crtc.h 312fa91d15SJani Nikula :internal: 322fa91d15SJani Nikula 33311b62d9SDaniel VetterKMS API Functions 34311b62d9SDaniel Vetter================= 35311b62d9SDaniel Vetter 36311b62d9SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_crtc.c 372fa91d15SJani Nikula :export: 382fa91d15SJani Nikula 392fa91d15SJani NikulaAtomic Mode Setting Function Reference 40311b62d9SDaniel Vetter====================================== 412fa91d15SJani Nikula 422fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_atomic.c 432fa91d15SJani Nikula :export: 442fa91d15SJani Nikula 455d070be6SDaniel Vetter.. kernel-doc:: include/drm/drm_atomic.h 462fa91d15SJani Nikula :internal: 472fa91d15SJani Nikula 482fa91d15SJani NikulaFrame Buffer Abstraction 49311b62d9SDaniel Vetter======================== 502fa91d15SJani Nikula 51750fb8c4SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c 52750fb8c4SDaniel Vetter :doc: overview 532fa91d15SJani Nikula 547520a277SDaniel VetterFrame Buffer Functions Reference 557520a277SDaniel Vetter-------------------------------- 567520a277SDaniel Vetter 577520a277SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c 587520a277SDaniel Vetter :export: 597520a277SDaniel Vetter 607520a277SDaniel Vetter.. kernel-doc:: include/drm/drm_framebuffer.h 617520a277SDaniel Vetter :internal: 627520a277SDaniel Vetter 632fa91d15SJani NikulaDRM Format Handling 64311b62d9SDaniel Vetter=================== 652fa91d15SJani Nikula 6684770cc2SLaurent Pinchart.. kernel-doc:: include/drm/drm_fourcc.h 6784770cc2SLaurent Pinchart :internal: 6884770cc2SLaurent Pinchart 692fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_fourcc.c 702fa91d15SJani Nikula :export: 712fa91d15SJani Nikula 722fa91d15SJani NikulaDumb Buffer Objects 73311b62d9SDaniel Vetter=================== 742fa91d15SJani Nikula 75*4f93624eSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_dumb_buffers.c 76*4f93624eSDaniel Vetter :doc: overview 772fa91d15SJani Nikula 7843968d7bSDaniel VetterPlane Abstraction 7943968d7bSDaniel Vetter================= 8043968d7bSDaniel Vetter 81532b3671SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_plane.c 82532b3671SDaniel Vetter :doc: overview 83532b3671SDaniel Vetter 8443968d7bSDaniel VetterPlane Functions Reference 8543968d7bSDaniel Vetter------------------------- 8643968d7bSDaniel Vetter 8743968d7bSDaniel Vetter.. kernel-doc:: include/drm/drm_plane.h 8843968d7bSDaniel Vetter :internal: 8943968d7bSDaniel Vetter 9043968d7bSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_plane.c 9143968d7bSDaniel Vetter :export: 9243968d7bSDaniel Vetter 93311b62d9SDaniel VetterDisplay Modes Function Reference 94311b62d9SDaniel Vetter================================ 952fa91d15SJani Nikula 96311b62d9SDaniel Vetter.. kernel-doc:: include/drm/drm_modes.h 97311b62d9SDaniel Vetter :internal: 98311b62d9SDaniel Vetter 99311b62d9SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_modes.c 100311b62d9SDaniel Vetter :export: 1012fa91d15SJani Nikula 102ae2a6da8SDaniel VetterConnector Abstraction 103ae2a6da8SDaniel Vetter===================== 104ae2a6da8SDaniel Vetter 105ae2a6da8SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_connector.c 106ae2a6da8SDaniel Vetter :doc: overview 107ae2a6da8SDaniel Vetter 108ae2a6da8SDaniel VetterConnector Functions Reference 109ae2a6da8SDaniel Vetter----------------------------- 11052217195SDaniel Vetter 11152217195SDaniel Vetter.. kernel-doc:: include/drm/drm_connector.h 11252217195SDaniel Vetter :internal: 11352217195SDaniel Vetter 11452217195SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_connector.c 11552217195SDaniel Vetter :export: 11652217195SDaniel Vetter 117321a95aeSDaniel VetterEncoder Abstraction 118321a95aeSDaniel Vetter=================== 119321a95aeSDaniel Vetter 120e03e6de0SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_encoder.c 121e03e6de0SDaniel Vetter :doc: overview 122e03e6de0SDaniel Vetter 123e03e6de0SDaniel VetterEncoder Functions Reference 124e03e6de0SDaniel Vetter--------------------------- 125e03e6de0SDaniel Vetter 126321a95aeSDaniel Vetter.. kernel-doc:: include/drm/drm_encoder.h 127321a95aeSDaniel Vetter :internal: 128321a95aeSDaniel Vetter 129321a95aeSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_encoder.c 130321a95aeSDaniel Vetter :export: 131321a95aeSDaniel Vetter 1322fa91d15SJani NikulaKMS Initialization and Cleanup 1332fa91d15SJani Nikula============================== 1342fa91d15SJani Nikula 1352fa91d15SJani NikulaA KMS device is abstracted and exposed as a set of planes, CRTCs, 1362fa91d15SJani Nikulaencoders and connectors. KMS drivers must thus create and initialize all 1372fa91d15SJani Nikulathose objects at load time after initializing mode setting. 1382fa91d15SJani Nikula 1392fa91d15SJani NikulaCRTCs (:c:type:`struct drm_crtc <drm_crtc>`) 1402fa91d15SJani Nikula-------------------------------------------- 1412fa91d15SJani Nikula 1422fa91d15SJani NikulaA CRTC is an abstraction representing a part of the chip that contains a 1432fa91d15SJani Nikulapointer to a scanout buffer. Therefore, the number of CRTCs available 1442fa91d15SJani Nikuladetermines how many independent scanout buffers can be active at any 1452fa91d15SJani Nikulagiven time. The CRTC structure contains several fields to support this: 1462fa91d15SJani Nikulaa pointer to some video memory (abstracted as a frame buffer object), a 1472fa91d15SJani Nikuladisplay mode, and an (x, y) offset into the video memory to support 1482fa91d15SJani Nikulapanning or configurations where one piece of video memory spans multiple 1492fa91d15SJani NikulaCRTCs. 1502fa91d15SJani Nikula 1512fa91d15SJani NikulaCRTC Initialization 1522fa91d15SJani Nikula~~~~~~~~~~~~~~~~~~~ 1532fa91d15SJani Nikula 1542fa91d15SJani NikulaA KMS device must create and register at least one struct 1552fa91d15SJani Nikula:c:type:`struct drm_crtc <drm_crtc>` instance. The instance is 1562fa91d15SJani Nikulaallocated and zeroed by the driver, possibly as part of a larger 1572fa91d15SJani Nikulastructure, and registered with a call to :c:func:`drm_crtc_init()` 1582fa91d15SJani Nikulawith a pointer to CRTC functions. 1592fa91d15SJani Nikula 1602fa91d15SJani Nikula 1612fa91d15SJani NikulaCleanup 1622fa91d15SJani Nikula------- 1632fa91d15SJani Nikula 1642fa91d15SJani NikulaThe DRM core manages its objects' lifetime. When an object is not needed 1652fa91d15SJani Nikulaanymore the core calls its destroy function, which must clean up and 1662fa91d15SJani Nikulafree every resource allocated for the object. Every 1672fa91d15SJani Nikula:c:func:`drm_\*_init()` call must be matched with a corresponding 1682fa91d15SJani Nikula:c:func:`drm_\*_cleanup()` call to cleanup CRTCs 1692fa91d15SJani Nikula(:c:func:`drm_crtc_cleanup()`), planes 1702fa91d15SJani Nikula(:c:func:`drm_plane_cleanup()`), encoders 1712fa91d15SJani Nikula(:c:func:`drm_encoder_cleanup()`) and connectors 1722fa91d15SJani Nikula(:c:func:`drm_connector_cleanup()`). Furthermore, connectors that 1732fa91d15SJani Nikulahave been added to sysfs must be removed by a call to 1742fa91d15SJani Nikula:c:func:`drm_connector_unregister()` before calling 1752fa91d15SJani Nikula:c:func:`drm_connector_cleanup()`. 1762fa91d15SJani Nikula 1772fa91d15SJani NikulaConnectors state change detection must be cleanup up with a call to 1782fa91d15SJani Nikula:c:func:`drm_kms_helper_poll_fini()`. 1792fa91d15SJani Nikula 1802fa91d15SJani NikulaOutput discovery and initialization example 1812fa91d15SJani Nikula------------------------------------------- 1822fa91d15SJani Nikula 1832fa91d15SJani Nikula:: 1842fa91d15SJani Nikula 1852fa91d15SJani Nikula void intel_crt_init(struct drm_device *dev) 1862fa91d15SJani Nikula { 1872fa91d15SJani Nikula struct drm_connector *connector; 1882fa91d15SJani Nikula struct intel_output *intel_output; 1892fa91d15SJani Nikula 1902fa91d15SJani Nikula intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL); 1912fa91d15SJani Nikula if (!intel_output) 1922fa91d15SJani Nikula return; 1932fa91d15SJani Nikula 1942fa91d15SJani Nikula connector = &intel_output->base; 1952fa91d15SJani Nikula drm_connector_init(dev, &intel_output->base, 1962fa91d15SJani Nikula &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA); 1972fa91d15SJani Nikula 1982fa91d15SJani Nikula drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs, 1992fa91d15SJani Nikula DRM_MODE_ENCODER_DAC); 2002fa91d15SJani Nikula 2012fa91d15SJani Nikula drm_mode_connector_attach_encoder(&intel_output->base, 2022fa91d15SJani Nikula &intel_output->enc); 2032fa91d15SJani Nikula 2042fa91d15SJani Nikula /* Set up the DDC bus. */ 2052fa91d15SJani Nikula intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A"); 2062fa91d15SJani Nikula if (!intel_output->ddc_bus) { 2072fa91d15SJani Nikula dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration " 2082fa91d15SJani Nikula "failed.\n"); 2092fa91d15SJani Nikula return; 2102fa91d15SJani Nikula } 2112fa91d15SJani Nikula 2122fa91d15SJani Nikula intel_output->type = INTEL_OUTPUT_ANALOG; 2132fa91d15SJani Nikula connector->interlace_allowed = 0; 2142fa91d15SJani Nikula connector->doublescan_allowed = 0; 2152fa91d15SJani Nikula 2162fa91d15SJani Nikula drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs); 2172fa91d15SJani Nikula drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs); 2182fa91d15SJani Nikula 2192fa91d15SJani Nikula drm_connector_register(connector); 2202fa91d15SJani Nikula } 2212fa91d15SJani Nikula 2222fa91d15SJani NikulaIn the example above (taken from the i915 driver), a CRTC, connector and 2232fa91d15SJani Nikulaencoder combination is created. A device-specific i2c bus is also 2242fa91d15SJani Nikulacreated for fetching EDID data and performing monitor detection. Once 2252fa91d15SJani Nikulathe process is complete, the new connector is registered with sysfs to 2262fa91d15SJani Nikulamake its properties available to applications. 2272fa91d15SJani Nikula 2282fa91d15SJani NikulaKMS Locking 229311b62d9SDaniel Vetter=========== 2302fa91d15SJani Nikula 2312fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c 2322fa91d15SJani Nikula :doc: kms locking 2332fa91d15SJani Nikula 2342fa91d15SJani Nikula.. kernel-doc:: include/drm/drm_modeset_lock.h 2352fa91d15SJani Nikula :internal: 2362fa91d15SJani Nikula 2372fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c 2382fa91d15SJani Nikula :export: 2392fa91d15SJani Nikula 2402fa91d15SJani NikulaKMS Properties 2412fa91d15SJani Nikula============== 2422fa91d15SJani Nikula 24359e71ee7SDaniel VetterProperty Types and Blob Property Support 24459e71ee7SDaniel Vetter---------------------------------------- 24559e71ee7SDaniel Vetter 246c8458c7eSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_property.c 247c8458c7eSDaniel Vetter :doc: overview 248c8458c7eSDaniel Vetter 24959e71ee7SDaniel Vetter.. kernel-doc:: include/drm/drm_property.h 25059e71ee7SDaniel Vetter :internal: 25159e71ee7SDaniel Vetter 25259e71ee7SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_property.c 25359e71ee7SDaniel Vetter :export: 25459e71ee7SDaniel Vetter 2551e4d84c6SDaniel VetterPlane Composition Properties 2561e4d84c6SDaniel Vetter---------------------------- 2571e4d84c6SDaniel Vetter 2581e4d84c6SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_blend.c 2591e4d84c6SDaniel Vetter :doc: overview 26052a9fcdaSDaniel Vetter 26152a9fcdaSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_blend.c 26252a9fcdaSDaniel Vetter :export: 26352a9fcdaSDaniel Vetter 264a6acccf8SDaniel VetterColor Management Properties 265a6acccf8SDaniel Vetter--------------------------- 266a6acccf8SDaniel Vetter 267a6acccf8SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c 268a6acccf8SDaniel Vetter :doc: overview 269a6acccf8SDaniel Vetter 270a6acccf8SDaniel Vetter.. kernel-doc:: include/drm/drm_color_mgmt.h 271a6acccf8SDaniel Vetter :internal: 272a6acccf8SDaniel Vetter 273a6acccf8SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c 274a6acccf8SDaniel Vetter :export: 275a6acccf8SDaniel Vetter 2762fa91d15SJani NikulaExisting KMS Properties 2772fa91d15SJani Nikula----------------------- 2782fa91d15SJani Nikula 2792fa91d15SJani NikulaThe following table gives description of drm properties exposed by 2802fa91d15SJani Nikulavarious modules/drivers. 2812fa91d15SJani Nikula 2822fa91d15SJani Nikula.. csv-table:: 2832fa91d15SJani Nikula :header-rows: 1 2842fa91d15SJani Nikula :file: kms-properties.csv 2852fa91d15SJani Nikula 2862fa91d15SJani NikulaVertical Blanking 2872fa91d15SJani Nikula================= 2882fa91d15SJani Nikula 2892fa91d15SJani NikulaVertical blanking plays a major role in graphics rendering. To achieve 2902fa91d15SJani Nikulatear-free display, users must synchronize page flips and/or rendering to 2912fa91d15SJani Nikulavertical blanking. The DRM API offers ioctls to perform page flips 2922fa91d15SJani Nikulasynchronized to vertical blanking and wait for vertical blanking. 2932fa91d15SJani Nikula 2942fa91d15SJani NikulaThe DRM core handles most of the vertical blanking management logic, 2952fa91d15SJani Nikulawhich involves filtering out spurious interrupts, keeping race-free 2962fa91d15SJani Nikulablanking counters, coping with counter wrap-around and resets and 2972fa91d15SJani Nikulakeeping use counts. It relies on the driver to generate vertical 2982fa91d15SJani Nikulablanking interrupts and optionally provide a hardware vertical blanking 2992fa91d15SJani Nikulacounter. Drivers must implement the following operations. 3002fa91d15SJani Nikula 3012fa91d15SJani Nikula- int (\*enable_vblank) (struct drm_device \*dev, int crtc); void 3022fa91d15SJani Nikula (\*disable_vblank) (struct drm_device \*dev, int crtc); 3032fa91d15SJani Nikula Enable or disable vertical blanking interrupts for the given CRTC. 3042fa91d15SJani Nikula 3052fa91d15SJani Nikula- u32 (\*get_vblank_counter) (struct drm_device \*dev, int crtc); 3062fa91d15SJani Nikula Retrieve the value of the vertical blanking counter for the given 3072fa91d15SJani Nikula CRTC. If the hardware maintains a vertical blanking counter its value 3082fa91d15SJani Nikula should be returned. Otherwise drivers can use the 3092fa91d15SJani Nikula :c:func:`drm_vblank_count()` helper function to handle this 3102fa91d15SJani Nikula operation. 3112fa91d15SJani Nikula 3122fa91d15SJani NikulaDrivers must initialize the vertical blanking handling core with a call 3132fa91d15SJani Nikulato :c:func:`drm_vblank_init()` in their load operation. 3142fa91d15SJani Nikula 3152fa91d15SJani NikulaVertical blanking interrupts can be enabled by the DRM core or by 3162fa91d15SJani Nikuladrivers themselves (for instance to handle page flipping operations). 3172fa91d15SJani NikulaThe DRM core maintains a vertical blanking use count to ensure that the 3182fa91d15SJani Nikulainterrupts are not disabled while a user still needs them. To increment 3192fa91d15SJani Nikulathe use count, drivers call :c:func:`drm_vblank_get()`. Upon 3202fa91d15SJani Nikulareturn vertical blanking interrupts are guaranteed to be enabled. 3212fa91d15SJani Nikula 3222fa91d15SJani NikulaTo decrement the use count drivers call 3232fa91d15SJani Nikula:c:func:`drm_vblank_put()`. Only when the use count drops to zero 3242fa91d15SJani Nikulawill the DRM core disable the vertical blanking interrupts after a delay 3252fa91d15SJani Nikulaby scheduling a timer. The delay is accessible through the 3262fa91d15SJani Nikulavblankoffdelay module parameter or the ``drm_vblank_offdelay`` global 3272fa91d15SJani Nikulavariable and expressed in milliseconds. Its default value is 5000 ms. 3282fa91d15SJani NikulaZero means never disable, and a negative value means disable 3292fa91d15SJani Nikulaimmediately. Drivers may override the behaviour by setting the 3302fa91d15SJani Nikula:c:type:`struct drm_device <drm_device>` 3312fa91d15SJani Nikulavblank_disable_immediate flag, which when set causes vblank interrupts 3322fa91d15SJani Nikulato be disabled immediately regardless of the drm_vblank_offdelay 3332fa91d15SJani Nikulavalue. The flag should only be set if there's a properly working 3342fa91d15SJani Nikulahardware vblank counter present. 3352fa91d15SJani Nikula 3362fa91d15SJani NikulaWhen a vertical blanking interrupt occurs drivers only need to call the 3372fa91d15SJani Nikula:c:func:`drm_handle_vblank()` function to account for the 3382fa91d15SJani Nikulainterrupt. 3392fa91d15SJani Nikula 3402fa91d15SJani NikulaResources allocated by :c:func:`drm_vblank_init()` must be freed 3412fa91d15SJani Nikulawith a call to :c:func:`drm_vblank_cleanup()` in the driver unload 3422fa91d15SJani Nikulaoperation handler. 3432fa91d15SJani Nikula 3442fa91d15SJani NikulaVertical Blanking and Interrupt Handling Functions Reference 3452fa91d15SJani Nikula------------------------------------------------------------ 3462fa91d15SJani Nikula 3472fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_irq.c 3482fa91d15SJani Nikula :export: 3492fa91d15SJani Nikula 35034a67dd7SDaniel Vetter.. kernel-doc:: include/drm/drm_irq.h 35134a67dd7SDaniel Vetter :internal: 352