]>
Commit | Line | Data |
---|---|---|
2fa91d15 JN |
1 | ========================= |
2 | Kernel Mode Setting (KMS) | |
3 | ========================= | |
4 | ||
2fa91d15 JN |
5 | Drivers must initialize the mode setting core by calling |
6 | :c:func:`drm_mode_config_init()` on the DRM device. The function | |
7 | initializes the :c:type:`struct drm_device <drm_device>` | |
8 | mode_config field and never fails. Once done, mode configuration must | |
9 | be setup by initializing the following fields. | |
10 | ||
11 | - int min_width, min_height; int max_width, max_height; | |
12 | Minimum and maximum width and height of the frame buffers in pixel | |
13 | units. | |
14 | ||
15 | - struct drm_mode_config_funcs \*funcs; | |
16 | Mode setting functions. | |
17 | ||
949619f3 DV |
18 | Modeset Base Object Abstraction |
19 | =============================== | |
20 | ||
21 | .. kernel-doc:: include/drm/drm_mode_object.h | |
22 | :internal: | |
23 | ||
24 | .. kernel-doc:: drivers/gpu/drm/drm_mode_object.c | |
25 | :export: | |
26 | ||
311b62d9 DV |
27 | KMS Data Structures |
28 | =================== | |
2fa91d15 | 29 | |
311b62d9 | 30 | .. kernel-doc:: include/drm/drm_crtc.h |
2fa91d15 JN |
31 | :internal: |
32 | ||
311b62d9 DV |
33 | KMS API Functions |
34 | ================= | |
35 | ||
36 | .. kernel-doc:: drivers/gpu/drm/drm_crtc.c | |
2fa91d15 JN |
37 | :export: |
38 | ||
39 | Atomic Mode Setting Function Reference | |
311b62d9 | 40 | ====================================== |
2fa91d15 JN |
41 | |
42 | .. kernel-doc:: drivers/gpu/drm/drm_atomic.c | |
43 | :export: | |
44 | ||
5d070be6 | 45 | .. kernel-doc:: include/drm/drm_atomic.h |
2fa91d15 JN |
46 | :internal: |
47 | ||
48 | Frame Buffer Abstraction | |
311b62d9 | 49 | ======================== |
2fa91d15 | 50 | |
750fb8c4 DV |
51 | .. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c |
52 | :doc: overview | |
2fa91d15 | 53 | |
7520a277 DV |
54 | Frame Buffer Functions Reference |
55 | -------------------------------- | |
56 | ||
57 | .. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c | |
58 | :export: | |
59 | ||
60 | .. kernel-doc:: include/drm/drm_framebuffer.h | |
61 | :internal: | |
62 | ||
2fa91d15 | 63 | DRM Format Handling |
311b62d9 | 64 | =================== |
2fa91d15 | 65 | |
84770cc2 LP |
66 | .. kernel-doc:: include/drm/drm_fourcc.h |
67 | :internal: | |
68 | ||
2fa91d15 JN |
69 | .. kernel-doc:: drivers/gpu/drm/drm_fourcc.c |
70 | :export: | |
71 | ||
72 | Dumb Buffer Objects | |
311b62d9 | 73 | =================== |
2fa91d15 | 74 | |
4f93624e DV |
75 | .. kernel-doc:: drivers/gpu/drm/drm_dumb_buffers.c |
76 | :doc: overview | |
2fa91d15 | 77 | |
43968d7b DV |
78 | Plane Abstraction |
79 | ================= | |
80 | ||
532b3671 DV |
81 | .. kernel-doc:: drivers/gpu/drm/drm_plane.c |
82 | :doc: overview | |
83 | ||
43968d7b DV |
84 | Plane Functions Reference |
85 | ------------------------- | |
86 | ||
87 | .. kernel-doc:: include/drm/drm_plane.h | |
88 | :internal: | |
89 | ||
90 | .. kernel-doc:: drivers/gpu/drm/drm_plane.c | |
91 | :export: | |
92 | ||
311b62d9 DV |
93 | Display Modes Function Reference |
94 | ================================ | |
2fa91d15 | 95 | |
311b62d9 DV |
96 | .. kernel-doc:: include/drm/drm_modes.h |
97 | :internal: | |
98 | ||
99 | .. kernel-doc:: drivers/gpu/drm/drm_modes.c | |
100 | :export: | |
2fa91d15 | 101 | |
ae2a6da8 DV |
102 | Connector Abstraction |
103 | ===================== | |
104 | ||
105 | .. kernel-doc:: drivers/gpu/drm/drm_connector.c | |
106 | :doc: overview | |
107 | ||
108 | Connector Functions Reference | |
109 | ----------------------------- | |
52217195 DV |
110 | |
111 | .. kernel-doc:: include/drm/drm_connector.h | |
112 | :internal: | |
113 | ||
114 | .. kernel-doc:: drivers/gpu/drm/drm_connector.c | |
115 | :export: | |
116 | ||
321a95ae DV |
117 | Encoder Abstraction |
118 | =================== | |
119 | ||
e03e6de0 DV |
120 | .. kernel-doc:: drivers/gpu/drm/drm_encoder.c |
121 | :doc: overview | |
122 | ||
123 | Encoder Functions Reference | |
124 | --------------------------- | |
125 | ||
321a95ae DV |
126 | .. kernel-doc:: include/drm/drm_encoder.h |
127 | :internal: | |
128 | ||
129 | .. kernel-doc:: drivers/gpu/drm/drm_encoder.c | |
130 | :export: | |
131 | ||
2fa91d15 JN |
132 | KMS Initialization and Cleanup |
133 | ============================== | |
134 | ||
135 | A KMS device is abstracted and exposed as a set of planes, CRTCs, | |
136 | encoders and connectors. KMS drivers must thus create and initialize all | |
137 | those objects at load time after initializing mode setting. | |
138 | ||
139 | CRTCs (:c:type:`struct drm_crtc <drm_crtc>`) | |
140 | -------------------------------------------- | |
141 | ||
142 | A CRTC is an abstraction representing a part of the chip that contains a | |
143 | pointer to a scanout buffer. Therefore, the number of CRTCs available | |
144 | determines how many independent scanout buffers can be active at any | |
145 | given time. The CRTC structure contains several fields to support this: | |
146 | a pointer to some video memory (abstracted as a frame buffer object), a | |
147 | display mode, and an (x, y) offset into the video memory to support | |
148 | panning or configurations where one piece of video memory spans multiple | |
149 | CRTCs. | |
150 | ||
151 | CRTC Initialization | |
152 | ~~~~~~~~~~~~~~~~~~~ | |
153 | ||
154 | A KMS device must create and register at least one struct | |
155 | :c:type:`struct drm_crtc <drm_crtc>` instance. The instance is | |
156 | allocated and zeroed by the driver, possibly as part of a larger | |
157 | structure, and registered with a call to :c:func:`drm_crtc_init()` | |
158 | with a pointer to CRTC functions. | |
159 | ||
2fa91d15 | 160 | |
2fa91d15 JN |
161 | Cleanup |
162 | ------- | |
163 | ||
164 | The DRM core manages its objects' lifetime. When an object is not needed | |
165 | anymore the core calls its destroy function, which must clean up and | |
166 | free every resource allocated for the object. Every | |
167 | :c:func:`drm_\*_init()` call must be matched with a corresponding | |
168 | :c:func:`drm_\*_cleanup()` call to cleanup CRTCs | |
169 | (:c:func:`drm_crtc_cleanup()`), planes | |
170 | (:c:func:`drm_plane_cleanup()`), encoders | |
171 | (:c:func:`drm_encoder_cleanup()`) and connectors | |
172 | (:c:func:`drm_connector_cleanup()`). Furthermore, connectors that | |
173 | have been added to sysfs must be removed by a call to | |
174 | :c:func:`drm_connector_unregister()` before calling | |
175 | :c:func:`drm_connector_cleanup()`. | |
176 | ||
177 | Connectors state change detection must be cleanup up with a call to | |
178 | :c:func:`drm_kms_helper_poll_fini()`. | |
179 | ||
180 | Output discovery and initialization example | |
181 | ------------------------------------------- | |
182 | ||
183 | :: | |
184 | ||
185 | void intel_crt_init(struct drm_device *dev) | |
186 | { | |
187 | struct drm_connector *connector; | |
188 | struct intel_output *intel_output; | |
189 | ||
190 | intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL); | |
191 | if (!intel_output) | |
192 | return; | |
193 | ||
194 | connector = &intel_output->base; | |
195 | drm_connector_init(dev, &intel_output->base, | |
196 | &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA); | |
197 | ||
198 | drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs, | |
199 | DRM_MODE_ENCODER_DAC); | |
200 | ||
201 | drm_mode_connector_attach_encoder(&intel_output->base, | |
202 | &intel_output->enc); | |
203 | ||
204 | /* Set up the DDC bus. */ | |
205 | intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A"); | |
206 | if (!intel_output->ddc_bus) { | |
207 | dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration " | |
208 | "failed.\n"); | |
209 | return; | |
210 | } | |
211 | ||
212 | intel_output->type = INTEL_OUTPUT_ANALOG; | |
213 | connector->interlace_allowed = 0; | |
214 | connector->doublescan_allowed = 0; | |
215 | ||
216 | drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs); | |
217 | drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs); | |
218 | ||
219 | drm_connector_register(connector); | |
220 | } | |
221 | ||
222 | In the example above (taken from the i915 driver), a CRTC, connector and | |
223 | encoder combination is created. A device-specific i2c bus is also | |
224 | created for fetching EDID data and performing monitor detection. Once | |
225 | the process is complete, the new connector is registered with sysfs to | |
226 | make its properties available to applications. | |
227 | ||
2fa91d15 | 228 | KMS Locking |
311b62d9 | 229 | =========== |
2fa91d15 JN |
230 | |
231 | .. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c | |
232 | :doc: kms locking | |
233 | ||
234 | .. kernel-doc:: include/drm/drm_modeset_lock.h | |
235 | :internal: | |
236 | ||
237 | .. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c | |
238 | :export: | |
239 | ||
240 | KMS Properties | |
241 | ============== | |
242 | ||
59e71ee7 DV |
243 | Property Types and Blob Property Support |
244 | ---------------------------------------- | |
245 | ||
c8458c7e DV |
246 | .. kernel-doc:: drivers/gpu/drm/drm_property.c |
247 | :doc: overview | |
248 | ||
59e71ee7 DV |
249 | .. kernel-doc:: include/drm/drm_property.h |
250 | :internal: | |
251 | ||
252 | .. kernel-doc:: drivers/gpu/drm/drm_property.c | |
253 | :export: | |
254 | ||
1e4d84c6 DV |
255 | Plane Composition Properties |
256 | ---------------------------- | |
257 | ||
258 | .. kernel-doc:: drivers/gpu/drm/drm_blend.c | |
259 | :doc: overview | |
52a9fcda DV |
260 | |
261 | .. kernel-doc:: drivers/gpu/drm/drm_blend.c | |
262 | :export: | |
263 | ||
a6acccf8 DV |
264 | Color Management Properties |
265 | --------------------------- | |
266 | ||
267 | .. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c | |
268 | :doc: overview | |
269 | ||
270 | .. kernel-doc:: include/drm/drm_color_mgmt.h | |
271 | :internal: | |
272 | ||
273 | .. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c | |
274 | :export: | |
275 | ||
2fa91d15 JN |
276 | Existing KMS Properties |
277 | ----------------------- | |
278 | ||
279 | The following table gives description of drm properties exposed by | |
280 | various modules/drivers. | |
281 | ||
282 | .. csv-table:: | |
283 | :header-rows: 1 | |
284 | :file: kms-properties.csv | |
285 | ||
286 | Vertical Blanking | |
287 | ================= | |
288 | ||
289 | Vertical blanking plays a major role in graphics rendering. To achieve | |
290 | tear-free display, users must synchronize page flips and/or rendering to | |
291 | vertical blanking. The DRM API offers ioctls to perform page flips | |
292 | synchronized to vertical blanking and wait for vertical blanking. | |
293 | ||
294 | The DRM core handles most of the vertical blanking management logic, | |
295 | which involves filtering out spurious interrupts, keeping race-free | |
296 | blanking counters, coping with counter wrap-around and resets and | |
297 | keeping use counts. It relies on the driver to generate vertical | |
298 | blanking interrupts and optionally provide a hardware vertical blanking | |
299 | counter. Drivers must implement the following operations. | |
300 | ||
301 | - int (\*enable_vblank) (struct drm_device \*dev, int crtc); void | |
302 | (\*disable_vblank) (struct drm_device \*dev, int crtc); | |
303 | Enable or disable vertical blanking interrupts for the given CRTC. | |
304 | ||
305 | - u32 (\*get_vblank_counter) (struct drm_device \*dev, int crtc); | |
306 | Retrieve the value of the vertical blanking counter for the given | |
307 | CRTC. If the hardware maintains a vertical blanking counter its value | |
308 | should be returned. Otherwise drivers can use the | |
309 | :c:func:`drm_vblank_count()` helper function to handle this | |
310 | operation. | |
311 | ||
312 | Drivers must initialize the vertical blanking handling core with a call | |
313 | to :c:func:`drm_vblank_init()` in their load operation. | |
314 | ||
315 | Vertical blanking interrupts can be enabled by the DRM core or by | |
316 | drivers themselves (for instance to handle page flipping operations). | |
317 | The DRM core maintains a vertical blanking use count to ensure that the | |
318 | interrupts are not disabled while a user still needs them. To increment | |
319 | the use count, drivers call :c:func:`drm_vblank_get()`. Upon | |
320 | return vertical blanking interrupts are guaranteed to be enabled. | |
321 | ||
322 | To decrement the use count drivers call | |
323 | :c:func:`drm_vblank_put()`. Only when the use count drops to zero | |
324 | will the DRM core disable the vertical blanking interrupts after a delay | |
325 | by scheduling a timer. The delay is accessible through the | |
326 | vblankoffdelay module parameter or the ``drm_vblank_offdelay`` global | |
327 | variable and expressed in milliseconds. Its default value is 5000 ms. | |
328 | Zero means never disable, and a negative value means disable | |
329 | immediately. Drivers may override the behaviour by setting the | |
330 | :c:type:`struct drm_device <drm_device>` | |
331 | vblank_disable_immediate flag, which when set causes vblank interrupts | |
332 | to be disabled immediately regardless of the drm_vblank_offdelay | |
333 | value. The flag should only be set if there's a properly working | |
334 | hardware vblank counter present. | |
335 | ||
336 | When a vertical blanking interrupt occurs drivers only need to call the | |
337 | :c:func:`drm_handle_vblank()` function to account for the | |
338 | interrupt. | |
339 | ||
340 | Resources allocated by :c:func:`drm_vblank_init()` must be freed | |
341 | with a call to :c:func:`drm_vblank_cleanup()` in the driver unload | |
342 | operation handler. | |
343 | ||
344 | Vertical Blanking and Interrupt Handling Functions Reference | |
345 | ------------------------------------------------------------ | |
346 | ||
347 | .. kernel-doc:: drivers/gpu/drm/drm_irq.c | |
348 | :export: | |
349 | ||
34a67dd7 DV |
350 | .. kernel-doc:: include/drm/drm_irq.h |
351 | :internal: |