drm_crtc.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. /*
  2. * Copyright © 2006 Keith Packard
  3. * Copyright © 2007-2008 Dave Airlie
  4. * Copyright © 2007-2008 Intel Corporation
  5. * Jesse Barnes <jesse.barnes@intel.com>
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. * OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef __DRM_CRTC_H__
  26. #define __DRM_CRTC_H__
  27. #include <linux/i2c.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/types.h>
  30. #include <linux/idr.h>
  31. #include <linux/fb.h>
  32. #include <linux/hdmi.h>
  33. #include <drm/drm_mode.h>
  34. #include <drm/drm_fourcc.h>
  35. #include <drm/drm_modeset_lock.h>
  36. struct drm_device;
  37. struct drm_mode_set;
  38. struct drm_framebuffer;
  39. struct drm_object_properties;
  40. struct drm_file;
  41. struct drm_clip_rect;
  42. #define DRM_MODE_OBJECT_CRTC 0xcccccccc
  43. #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
  44. #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
  45. #define DRM_MODE_OBJECT_MODE 0xdededede
  46. #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
  47. #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
  48. #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
  49. #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
  50. #define DRM_MODE_OBJECT_BRIDGE 0xbdbdbdbd
  51. #define DRM_MODE_OBJECT_ANY 0
  52. struct drm_mode_object {
  53. uint32_t id;
  54. uint32_t type;
  55. struct drm_object_properties *properties;
  56. };
  57. #define DRM_OBJECT_MAX_PROPERTY 24
  58. struct drm_object_properties {
  59. int count;
  60. uint32_t ids[DRM_OBJECT_MAX_PROPERTY];
  61. uint64_t values[DRM_OBJECT_MAX_PROPERTY];
  62. };
  63. static inline int64_t U642I64(uint64_t val)
  64. {
  65. return (int64_t)*((int64_t *)&val);
  66. }
  67. static inline uint64_t I642U64(int64_t val)
  68. {
  69. return (uint64_t)*((uint64_t *)&val);
  70. }
  71. enum drm_connector_force {
  72. DRM_FORCE_UNSPECIFIED,
  73. DRM_FORCE_OFF,
  74. DRM_FORCE_ON, /* force on analog part normally */
  75. DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
  76. };
  77. #include <drm/drm_modes.h>
  78. enum drm_connector_status {
  79. connector_status_connected = 1,
  80. connector_status_disconnected = 2,
  81. connector_status_unknown = 3,
  82. };
  83. enum subpixel_order {
  84. SubPixelUnknown = 0,
  85. SubPixelHorizontalRGB,
  86. SubPixelHorizontalBGR,
  87. SubPixelVerticalRGB,
  88. SubPixelVerticalBGR,
  89. SubPixelNone,
  90. };
  91. #define DRM_COLOR_FORMAT_RGB444 (1<<0)
  92. #define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
  93. #define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
  94. /*
  95. * Describes a given display (e.g. CRT or flat panel) and its limitations.
  96. */
  97. struct drm_display_info {
  98. char name[DRM_DISPLAY_INFO_LEN];
  99. /* Physical size */
  100. unsigned int width_mm;
  101. unsigned int height_mm;
  102. /* Clock limits FIXME: storage format */
  103. unsigned int min_vfreq, max_vfreq;
  104. unsigned int min_hfreq, max_hfreq;
  105. unsigned int pixel_clock;
  106. unsigned int bpc;
  107. enum subpixel_order subpixel_order;
  108. u32 color_formats;
  109. /* Mask of supported hdmi deep color modes */
  110. u8 edid_hdmi_dc_modes;
  111. u8 cea_rev;
  112. };
  113. struct drm_framebuffer_funcs {
  114. /* note: use drm_framebuffer_remove() */
  115. void (*destroy)(struct drm_framebuffer *framebuffer);
  116. int (*create_handle)(struct drm_framebuffer *fb,
  117. struct drm_file *file_priv,
  118. unsigned int *handle);
  119. /**
  120. * Optinal callback for the dirty fb ioctl.
  121. *
  122. * Userspace can notify the driver via this callback
  123. * that a area of the framebuffer has changed and should
  124. * be flushed to the display hardware.
  125. *
  126. * See documentation in drm_mode.h for the struct
  127. * drm_mode_fb_dirty_cmd for more information as all
  128. * the semantics and arguments have a one to one mapping
  129. * on this function.
  130. */
  131. int (*dirty)(struct drm_framebuffer *framebuffer,
  132. struct drm_file *file_priv, unsigned flags,
  133. unsigned color, struct drm_clip_rect *clips,
  134. unsigned num_clips);
  135. };
  136. struct drm_framebuffer {
  137. struct drm_device *dev;
  138. /*
  139. * Note that the fb is refcounted for the benefit of driver internals,
  140. * for example some hw, disabling a CRTC/plane is asynchronous, and
  141. * scanout does not actually complete until the next vblank. So some
  142. * cleanup (like releasing the reference(s) on the backing GEM bo(s))
  143. * should be deferred. In cases like this, the driver would like to
  144. * hold a ref to the fb even though it has already been removed from
  145. * userspace perspective.
  146. */
  147. struct kref refcount;
  148. /*
  149. * Place on the dev->mode_config.fb_list, access protected by
  150. * dev->mode_config.fb_lock.
  151. */
  152. struct list_head head;
  153. struct drm_mode_object base;
  154. const struct drm_framebuffer_funcs *funcs;
  155. unsigned int pitches[4];
  156. unsigned int offsets[4];
  157. unsigned int width;
  158. unsigned int height;
  159. /* depth can be 15 or 16 */
  160. unsigned int depth;
  161. int bits_per_pixel;
  162. int flags;
  163. uint32_t pixel_format; /* fourcc format */
  164. struct list_head filp_head;
  165. /* if you are using the helper */
  166. void *helper_private;
  167. };
  168. struct drm_property_blob {
  169. struct drm_mode_object base;
  170. struct list_head head;
  171. unsigned int length;
  172. unsigned char data[];
  173. };
  174. struct drm_property_enum {
  175. uint64_t value;
  176. struct list_head head;
  177. char name[DRM_PROP_NAME_LEN];
  178. };
  179. struct drm_property {
  180. struct list_head head;
  181. struct drm_mode_object base;
  182. uint32_t flags;
  183. char name[DRM_PROP_NAME_LEN];
  184. uint32_t num_values;
  185. uint64_t *values;
  186. struct drm_device *dev;
  187. struct list_head enum_blob_list;
  188. };
  189. void drm_modeset_lock_all(struct drm_device *dev);
  190. void drm_modeset_unlock_all(struct drm_device *dev);
  191. void drm_warn_on_modeset_not_all_locked(struct drm_device *dev);
  192. struct drm_crtc;
  193. struct drm_connector;
  194. struct drm_encoder;
  195. struct drm_pending_vblank_event;
  196. struct drm_plane;
  197. struct drm_bridge;
  198. /**
  199. * drm_crtc_funcs - control CRTCs for a given device
  200. * @save: save CRTC state
  201. * @restore: restore CRTC state
  202. * @reset: reset CRTC after state has been invalidated (e.g. resume)
  203. * @cursor_set: setup the cursor
  204. * @cursor_move: move the cursor
  205. * @gamma_set: specify color ramp for CRTC
  206. * @destroy: deinit and free object
  207. * @set_property: called when a property is changed
  208. * @set_config: apply a new CRTC configuration
  209. * @page_flip: initiate a page flip
  210. *
  211. * The drm_crtc_funcs structure is the central CRTC management structure
  212. * in the DRM. Each CRTC controls one or more connectors (note that the name
  213. * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
  214. * connectors, not just CRTs).
  215. *
  216. * Each driver is responsible for filling out this structure at startup time,
  217. * in addition to providing other modesetting features, like i2c and DDC
  218. * bus accessors.
  219. */
  220. struct drm_crtc_funcs {
  221. /* Save CRTC state */
  222. void (*save)(struct drm_crtc *crtc); /* suspend? */
  223. /* Restore CRTC state */
  224. void (*restore)(struct drm_crtc *crtc); /* resume? */
  225. /* Reset CRTC state */
  226. void (*reset)(struct drm_crtc *crtc);
  227. /* cursor controls */
  228. int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
  229. uint32_t handle, uint32_t width, uint32_t height);
  230. int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
  231. uint32_t handle, uint32_t width, uint32_t height,
  232. int32_t hot_x, int32_t hot_y);
  233. int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
  234. /* Set gamma on the CRTC */
  235. void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  236. uint32_t start, uint32_t size);
  237. /* Object destroy routine */
  238. void (*destroy)(struct drm_crtc *crtc);
  239. int (*set_config)(struct drm_mode_set *set);
  240. /*
  241. * Flip to the given framebuffer. This implements the page
  242. * flip ioctl described in drm_mode.h, specifically, the
  243. * implementation must return immediately and block all
  244. * rendering to the current fb until the flip has completed.
  245. * If userspace set the event flag in the ioctl, the event
  246. * argument will point to an event to send back when the flip
  247. * completes, otherwise it will be NULL.
  248. */
  249. int (*page_flip)(struct drm_crtc *crtc,
  250. struct drm_framebuffer *fb,
  251. struct drm_pending_vblank_event *event,
  252. uint32_t flags);
  253. int (*set_property)(struct drm_crtc *crtc,
  254. struct drm_property *property, uint64_t val);
  255. };
  256. /**
  257. * drm_crtc - central CRTC control structure
  258. * @dev: parent DRM device
  259. * @head: list management
  260. * @mutex: per-CRTC locking
  261. * @base: base KMS object for ID tracking etc.
  262. * @primary: primary plane for this CRTC
  263. * @cursor: cursor plane for this CRTC
  264. * @enabled: is this CRTC enabled?
  265. * @mode: current mode timings
  266. * @hwmode: mode timings as programmed to hw regs
  267. * @invert_dimensions: for purposes of error checking crtc vs fb sizes,
  268. * invert the width/height of the crtc. This is used if the driver
  269. * is performing 90 or 270 degree rotated scanout
  270. * @x: x position on screen
  271. * @y: y position on screen
  272. * @funcs: CRTC control functions
  273. * @gamma_size: size of gamma ramp
  274. * @gamma_store: gamma ramp values
  275. * @framedur_ns: precise frame timing
  276. * @framedur_ns: precise line timing
  277. * @pixeldur_ns: precise pixel timing
  278. * @helper_private: mid-layer private data
  279. * @properties: property tracking for this CRTC
  280. *
  281. * Each CRTC may have one or more connectors associated with it. This structure
  282. * allows the CRTC to be controlled.
  283. */
  284. struct drm_crtc {
  285. struct drm_device *dev;
  286. struct list_head head;
  287. /**
  288. * crtc mutex
  289. *
  290. * This provides a read lock for the overall crtc state (mode, dpms
  291. * state, ...) and a write lock for everything which can be update
  292. * without a full modeset (fb, cursor data, ...)
  293. */
  294. struct drm_modeset_lock mutex;
  295. struct drm_mode_object base;
  296. /* primary and cursor planes for CRTC */
  297. struct drm_plane *primary;
  298. struct drm_plane *cursor;
  299. /* Temporary tracking of the old fb while a modeset is ongoing. Used
  300. * by drm_mode_set_config_internal to implement correct refcounting. */
  301. struct drm_framebuffer *old_fb;
  302. bool enabled;
  303. /* Requested mode from modesetting. */
  304. struct drm_display_mode mode;
  305. /* Programmed mode in hw, after adjustments for encoders,
  306. * crtc, panel scaling etc. Needed for timestamping etc.
  307. */
  308. struct drm_display_mode hwmode;
  309. bool invert_dimensions;
  310. int x, y;
  311. const struct drm_crtc_funcs *funcs;
  312. /* CRTC gamma size for reporting to userspace */
  313. uint32_t gamma_size;
  314. uint16_t *gamma_store;
  315. /* Constants needed for precise vblank and swap timestamping. */
  316. int framedur_ns, linedur_ns, pixeldur_ns;
  317. /* if you are using the helper */
  318. void *helper_private;
  319. struct drm_object_properties properties;
  320. };
  321. /**
  322. * drm_connector_funcs - control connectors on a given device
  323. * @dpms: set power state (see drm_crtc_funcs above)
  324. * @save: save connector state
  325. * @restore: restore connector state
  326. * @reset: reset connector after state has been invalidated (e.g. resume)
  327. * @detect: is this connector active?
  328. * @fill_modes: fill mode list for this connector
  329. * @set_property: property for this connector may need an update
  330. * @destroy: make object go away
  331. * @force: notify the driver that the connector is forced on
  332. *
  333. * Each CRTC may have one or more connectors attached to it. The functions
  334. * below allow the core DRM code to control connectors, enumerate available modes,
  335. * etc.
  336. */
  337. struct drm_connector_funcs {
  338. void (*dpms)(struct drm_connector *connector, int mode);
  339. void (*save)(struct drm_connector *connector);
  340. void (*restore)(struct drm_connector *connector);
  341. void (*reset)(struct drm_connector *connector);
  342. /* Check to see if anything is attached to the connector.
  343. * @force is set to false whilst polling, true when checking the
  344. * connector due to user request. @force can be used by the driver
  345. * to avoid expensive, destructive operations during automated
  346. * probing.
  347. */
  348. enum drm_connector_status (*detect)(struct drm_connector *connector,
  349. bool force);
  350. int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
  351. int (*set_property)(struct drm_connector *connector, struct drm_property *property,
  352. uint64_t val);
  353. void (*destroy)(struct drm_connector *connector);
  354. void (*force)(struct drm_connector *connector);
  355. };
  356. /**
  357. * drm_encoder_funcs - encoder controls
  358. * @reset: reset state (e.g. at init or resume time)
  359. * @destroy: cleanup and free associated data
  360. *
  361. * Encoders sit between CRTCs and connectors.
  362. */
  363. struct drm_encoder_funcs {
  364. void (*reset)(struct drm_encoder *encoder);
  365. void (*destroy)(struct drm_encoder *encoder);
  366. };
  367. #define DRM_CONNECTOR_MAX_ENCODER 3
  368. /**
  369. * drm_encoder - central DRM encoder structure
  370. * @dev: parent DRM device
  371. * @head: list management
  372. * @base: base KMS object
  373. * @name: encoder name
  374. * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
  375. * @possible_crtcs: bitmask of potential CRTC bindings
  376. * @possible_clones: bitmask of potential sibling encoders for cloning
  377. * @crtc: currently bound CRTC
  378. * @bridge: bridge associated to the encoder
  379. * @funcs: control functions
  380. * @helper_private: mid-layer private data
  381. *
  382. * CRTCs drive pixels to encoders, which convert them into signals
  383. * appropriate for a given connector or set of connectors.
  384. */
  385. struct drm_encoder {
  386. struct drm_device *dev;
  387. struct list_head head;
  388. struct drm_mode_object base;
  389. char *name;
  390. int encoder_type;
  391. uint32_t possible_crtcs;
  392. uint32_t possible_clones;
  393. struct drm_crtc *crtc;
  394. struct drm_bridge *bridge;
  395. const struct drm_encoder_funcs *funcs;
  396. void *helper_private;
  397. };
  398. /* should we poll this connector for connects and disconnects */
  399. /* hot plug detectable */
  400. #define DRM_CONNECTOR_POLL_HPD (1 << 0)
  401. /* poll for connections */
  402. #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
  403. /* can cleanly poll for disconnections without flickering the screen */
  404. /* DACs should rarely do this without a lot of testing */
  405. #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
  406. #define MAX_ELD_BYTES 128
  407. /**
  408. * drm_connector - central DRM connector control structure
  409. * @dev: parent DRM device
  410. * @kdev: kernel device for sysfs attributes
  411. * @attr: sysfs attributes
  412. * @head: list management
  413. * @base: base KMS object
  414. * @name: connector name
  415. * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
  416. * @connector_type_id: index into connector type enum
  417. * @interlace_allowed: can this connector handle interlaced modes?
  418. * @doublescan_allowed: can this connector handle doublescan?
  419. * @modes: modes available on this connector (from fill_modes() + user)
  420. * @status: one of the drm_connector_status enums (connected, not, or unknown)
  421. * @probed_modes: list of modes derived directly from the display
  422. * @display_info: information about attached display (e.g. from EDID)
  423. * @funcs: connector control functions
  424. * @edid_blob_ptr: DRM property containing EDID if present
  425. * @properties: property tracking for this connector
  426. * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
  427. * @dpms: current dpms state
  428. * @helper_private: mid-layer private data
  429. * @force: a %DRM_FORCE_<foo> state for forced mode sets
  430. * @encoder_ids: valid encoders for this connector
  431. * @encoder: encoder driving this connector, if any
  432. * @eld: EDID-like data, if present
  433. * @dvi_dual: dual link DVI, if found
  434. * @max_tmds_clock: max clock rate, if found
  435. * @latency_present: AV delay info from ELD, if found
  436. * @video_latency: video latency info from ELD, if found
  437. * @audio_latency: audio latency info from ELD, if found
  438. * @null_edid_counter: track sinks that give us all zeros for the EDID
  439. *
  440. * Each connector may be connected to one or more CRTCs, or may be clonable by
  441. * another connector if they can share a CRTC. Each connector also has a specific
  442. * position in the broader display (referred to as a 'screen' though it could
  443. * span multiple monitors).
  444. */
  445. struct drm_connector {
  446. struct drm_device *dev;
  447. struct device *kdev;
  448. struct device_attribute *attr;
  449. struct list_head head;
  450. struct drm_mode_object base;
  451. char *name;
  452. int connector_type;
  453. int connector_type_id;
  454. bool interlace_allowed;
  455. bool doublescan_allowed;
  456. bool stereo_allowed;
  457. struct list_head modes; /* list of modes on this connector */
  458. enum drm_connector_status status;
  459. /* these are modes added by probing with DDC or the BIOS */
  460. struct list_head probed_modes;
  461. struct drm_display_info display_info;
  462. const struct drm_connector_funcs *funcs;
  463. struct drm_property_blob *edid_blob_ptr;
  464. struct drm_object_properties properties;
  465. uint8_t polled; /* DRM_CONNECTOR_POLL_* */
  466. /* requested DPMS state */
  467. int dpms;
  468. void *helper_private;
  469. /* forced on connector */
  470. enum drm_connector_force force;
  471. uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
  472. struct drm_encoder *encoder; /* currently active encoder */
  473. /* EDID bits */
  474. uint8_t eld[MAX_ELD_BYTES];
  475. bool dvi_dual;
  476. int max_tmds_clock; /* in MHz */
  477. bool latency_present[2];
  478. int video_latency[2]; /* [0]: progressive, [1]: interlaced */
  479. int audio_latency[2];
  480. int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
  481. unsigned bad_edid_counter;
  482. };
  483. /**
  484. * drm_plane_funcs - driver plane control functions
  485. * @update_plane: update the plane configuration
  486. * @disable_plane: shut down the plane
  487. * @destroy: clean up plane resources
  488. * @set_property: called when a property is changed
  489. */
  490. struct drm_plane_funcs {
  491. int (*update_plane)(struct drm_plane *plane,
  492. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  493. int crtc_x, int crtc_y,
  494. unsigned int crtc_w, unsigned int crtc_h,
  495. uint32_t src_x, uint32_t src_y,
  496. uint32_t src_w, uint32_t src_h);
  497. int (*disable_plane)(struct drm_plane *plane);
  498. void (*destroy)(struct drm_plane *plane);
  499. int (*set_property)(struct drm_plane *plane,
  500. struct drm_property *property, uint64_t val);
  501. };
  502. enum drm_plane_type {
  503. DRM_PLANE_TYPE_OVERLAY,
  504. DRM_PLANE_TYPE_PRIMARY,
  505. DRM_PLANE_TYPE_CURSOR,
  506. };
  507. /**
  508. * drm_plane - central DRM plane control structure
  509. * @dev: DRM device this plane belongs to
  510. * @head: for list management
  511. * @base: base mode object
  512. * @possible_crtcs: pipes this plane can be bound to
  513. * @format_types: array of formats supported by this plane
  514. * @format_count: number of formats supported
  515. * @crtc: currently bound CRTC
  516. * @fb: currently bound fb
  517. * @funcs: helper functions
  518. * @properties: property tracking for this plane
  519. * @type: type of plane (overlay, primary, cursor)
  520. */
  521. struct drm_plane {
  522. struct drm_device *dev;
  523. struct list_head head;
  524. struct drm_mode_object base;
  525. uint32_t possible_crtcs;
  526. uint32_t *format_types;
  527. uint32_t format_count;
  528. struct drm_crtc *crtc;
  529. struct drm_framebuffer *fb;
  530. const struct drm_plane_funcs *funcs;
  531. struct drm_object_properties properties;
  532. enum drm_plane_type type;
  533. };
  534. /**
  535. * drm_bridge_funcs - drm_bridge control functions
  536. * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
  537. * @disable: Called right before encoder prepare, disables the bridge
  538. * @post_disable: Called right after encoder prepare, for lockstepped disable
  539. * @mode_set: Set this mode to the bridge
  540. * @pre_enable: Called right before encoder commit, for lockstepped commit
  541. * @enable: Called right after encoder commit, enables the bridge
  542. * @destroy: make object go away
  543. */
  544. struct drm_bridge_funcs {
  545. bool (*mode_fixup)(struct drm_bridge *bridge,
  546. const struct drm_display_mode *mode,
  547. struct drm_display_mode *adjusted_mode);
  548. void (*disable)(struct drm_bridge *bridge);
  549. void (*post_disable)(struct drm_bridge *bridge);
  550. void (*mode_set)(struct drm_bridge *bridge,
  551. struct drm_display_mode *mode,
  552. struct drm_display_mode *adjusted_mode);
  553. void (*pre_enable)(struct drm_bridge *bridge);
  554. void (*enable)(struct drm_bridge *bridge);
  555. void (*destroy)(struct drm_bridge *bridge);
  556. };
  557. /**
  558. * drm_bridge - central DRM bridge control structure
  559. * @dev: DRM device this bridge belongs to
  560. * @head: list management
  561. * @base: base mode object
  562. * @funcs: control functions
  563. * @driver_private: pointer to the bridge driver's internal context
  564. */
  565. struct drm_bridge {
  566. struct drm_device *dev;
  567. struct list_head head;
  568. struct drm_mode_object base;
  569. const struct drm_bridge_funcs *funcs;
  570. void *driver_private;
  571. };
  572. /**
  573. * drm_mode_set - new values for a CRTC config change
  574. * @head: list management
  575. * @fb: framebuffer to use for new config
  576. * @crtc: CRTC whose configuration we're about to change
  577. * @mode: mode timings to use
  578. * @x: position of this CRTC relative to @fb
  579. * @y: position of this CRTC relative to @fb
  580. * @connectors: array of connectors to drive with this CRTC if possible
  581. * @num_connectors: size of @connectors array
  582. *
  583. * Represents a single crtc the connectors that it drives with what mode
  584. * and from which framebuffer it scans out from.
  585. *
  586. * This is used to set modes.
  587. */
  588. struct drm_mode_set {
  589. struct drm_framebuffer *fb;
  590. struct drm_crtc *crtc;
  591. struct drm_display_mode *mode;
  592. uint32_t x;
  593. uint32_t y;
  594. struct drm_connector **connectors;
  595. size_t num_connectors;
  596. };
  597. /**
  598. * struct drm_mode_config_funcs - basic driver provided mode setting functions
  599. * @fb_create: create a new framebuffer object
  600. * @output_poll_changed: function to handle output configuration changes
  601. *
  602. * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
  603. * involve drivers.
  604. */
  605. struct drm_mode_config_funcs {
  606. struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
  607. struct drm_file *file_priv,
  608. struct drm_mode_fb_cmd2 *mode_cmd);
  609. void (*output_poll_changed)(struct drm_device *dev);
  610. };
  611. /**
  612. * drm_mode_group - group of mode setting resources for potential sub-grouping
  613. * @num_crtcs: CRTC count
  614. * @num_encoders: encoder count
  615. * @num_connectors: connector count
  616. * @id_list: list of KMS object IDs in this group
  617. *
  618. * Currently this simply tracks the global mode setting state. But in the
  619. * future it could allow groups of objects to be set aside into independent
  620. * control groups for use by different user level processes (e.g. two X servers
  621. * running simultaneously on different heads, each with their own mode
  622. * configuration and freedom of mode setting).
  623. */
  624. struct drm_mode_group {
  625. uint32_t num_crtcs;
  626. uint32_t num_encoders;
  627. uint32_t num_connectors;
  628. uint32_t num_bridges;
  629. /* list of object IDs for this group */
  630. uint32_t *id_list;
  631. };
  632. /**
  633. * drm_mode_config - Mode configuration control structure
  634. * @mutex: mutex protecting KMS related lists and structures
  635. * @idr_mutex: mutex for KMS ID allocation and management
  636. * @crtc_idr: main KMS ID tracking object
  637. * @num_fb: number of fbs available
  638. * @fb_list: list of framebuffers available
  639. * @num_connector: number of connectors on this device
  640. * @connector_list: list of connector objects
  641. * @num_bridge: number of bridges on this device
  642. * @bridge_list: list of bridge objects
  643. * @num_encoder: number of encoders on this device
  644. * @encoder_list: list of encoder objects
  645. * @num_crtc: number of CRTCs on this device
  646. * @crtc_list: list of CRTC objects
  647. * @min_width: minimum pixel width on this device
  648. * @min_height: minimum pixel height on this device
  649. * @max_width: maximum pixel width on this device
  650. * @max_height: maximum pixel height on this device
  651. * @funcs: core driver provided mode setting functions
  652. * @fb_base: base address of the framebuffer
  653. * @poll_enabled: track polling status for this device
  654. * @output_poll_work: delayed work for polling in process context
  655. * @*_property: core property tracking
  656. *
  657. * Core mode resource tracking structure. All CRTC, encoders, and connectors
  658. * enumerated by the driver are added here, as are global properties. Some
  659. * global restrictions are also here, e.g. dimension restrictions.
  660. */
  661. struct drm_mode_config {
  662. struct mutex mutex; /* protects configuration (mode lists etc.) */
  663. struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
  664. struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
  665. struct mutex idr_mutex; /* for IDR management */
  666. struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
  667. /* this is limited to one for now */
  668. /**
  669. * fb_lock - mutex to protect fb state
  670. *
  671. * Besides the global fb list his also protects the fbs list in the
  672. * file_priv
  673. */
  674. struct mutex fb_lock;
  675. int num_fb;
  676. struct list_head fb_list;
  677. int num_connector;
  678. struct list_head connector_list;
  679. int num_bridge;
  680. struct list_head bridge_list;
  681. int num_encoder;
  682. struct list_head encoder_list;
  683. /*
  684. * Track # of overlay planes separately from # of total planes. By
  685. * default we only advertise overlay planes to userspace; if userspace
  686. * sets the "universal plane" capability bit, we'll go ahead and
  687. * expose all planes.
  688. */
  689. int num_overlay_plane;
  690. int num_total_plane;
  691. struct list_head plane_list;
  692. int num_crtc;
  693. struct list_head crtc_list;
  694. struct list_head property_list;
  695. int min_width, min_height;
  696. int max_width, max_height;
  697. const struct drm_mode_config_funcs *funcs;
  698. resource_size_t fb_base;
  699. /* output poll support */
  700. bool poll_enabled;
  701. bool poll_running;
  702. struct delayed_work output_poll_work;
  703. /* pointers to standard properties */
  704. struct list_head property_blob_list;
  705. struct drm_property *edid_property;
  706. struct drm_property *dpms_property;
  707. struct drm_property *plane_type_property;
  708. /* DVI-I properties */
  709. struct drm_property *dvi_i_subconnector_property;
  710. struct drm_property *dvi_i_select_subconnector_property;
  711. /* TV properties */
  712. struct drm_property *tv_subconnector_property;
  713. struct drm_property *tv_select_subconnector_property;
  714. struct drm_property *tv_mode_property;
  715. struct drm_property *tv_left_margin_property;
  716. struct drm_property *tv_right_margin_property;
  717. struct drm_property *tv_top_margin_property;
  718. struct drm_property *tv_bottom_margin_property;
  719. struct drm_property *tv_brightness_property;
  720. struct drm_property *tv_contrast_property;
  721. struct drm_property *tv_flicker_reduction_property;
  722. struct drm_property *tv_overscan_property;
  723. struct drm_property *tv_saturation_property;
  724. struct drm_property *tv_hue_property;
  725. /* Optional properties */
  726. struct drm_property *scaling_mode_property;
  727. struct drm_property *dirty_info_property;
  728. /* dumb ioctl parameters */
  729. uint32_t preferred_depth, prefer_shadow;
  730. /* whether async page flip is supported or not */
  731. bool async_page_flip;
  732. /* cursor size */
  733. uint32_t cursor_width, cursor_height;
  734. };
  735. #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
  736. #define obj_to_connector(x) container_of(x, struct drm_connector, base)
  737. #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
  738. #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
  739. #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
  740. #define obj_to_property(x) container_of(x, struct drm_property, base)
  741. #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
  742. #define obj_to_plane(x) container_of(x, struct drm_plane, base)
  743. struct drm_prop_enum_list {
  744. int type;
  745. char *name;
  746. };
  747. extern int drm_crtc_init_with_planes(struct drm_device *dev,
  748. struct drm_crtc *crtc,
  749. struct drm_plane *primary,
  750. void *cursor,
  751. const struct drm_crtc_funcs *funcs);
  752. extern int drm_crtc_init(struct drm_device *dev,
  753. struct drm_crtc *crtc,
  754. const struct drm_crtc_funcs *funcs);
  755. extern void drm_crtc_cleanup(struct drm_crtc *crtc);
  756. extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
  757. /**
  758. * drm_crtc_mask - find the mask of a registered CRTC
  759. * @crtc: CRTC to find mask for
  760. *
  761. * Given a registered CRTC, return the mask bit of that CRTC for an
  762. * encoder's possible_crtcs field.
  763. */
  764. static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
  765. {
  766. return 1 << drm_crtc_index(crtc);
  767. }
  768. extern void drm_connector_ida_init(void);
  769. extern void drm_connector_ida_destroy(void);
  770. extern int drm_connector_init(struct drm_device *dev,
  771. struct drm_connector *connector,
  772. const struct drm_connector_funcs *funcs,
  773. int connector_type);
  774. extern void drm_connector_cleanup(struct drm_connector *connector);
  775. /* helper to unplug all connectors from sysfs for device */
  776. extern void drm_connector_unplug_all(struct drm_device *dev);
  777. extern int drm_bridge_init(struct drm_device *dev, struct drm_bridge *bridge,
  778. const struct drm_bridge_funcs *funcs);
  779. extern void drm_bridge_cleanup(struct drm_bridge *bridge);
  780. extern int drm_encoder_init(struct drm_device *dev,
  781. struct drm_encoder *encoder,
  782. const struct drm_encoder_funcs *funcs,
  783. int encoder_type);
  784. /**
  785. * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
  786. * @encoder: encoder to test
  787. * @crtc: crtc to test
  788. *
  789. * Return false if @encoder can't be driven by @crtc, true otherwise.
  790. */
  791. static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
  792. struct drm_crtc *crtc)
  793. {
  794. return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
  795. }
  796. extern int drm_universal_plane_init(struct drm_device *dev,
  797. struct drm_plane *plane,
  798. unsigned long possible_crtcs,
  799. const struct drm_plane_funcs *funcs,
  800. const uint32_t *formats,
  801. uint32_t format_count,
  802. enum drm_plane_type type);
  803. extern int drm_plane_init(struct drm_device *dev,
  804. struct drm_plane *plane,
  805. unsigned long possible_crtcs,
  806. const struct drm_plane_funcs *funcs,
  807. const uint32_t *formats, uint32_t format_count,
  808. bool is_primary);
  809. extern void drm_plane_cleanup(struct drm_plane *plane);
  810. extern void drm_plane_force_disable(struct drm_plane *plane);
  811. extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
  812. int x, int y,
  813. const struct drm_display_mode *mode,
  814. const struct drm_framebuffer *fb);
  815. extern void drm_encoder_cleanup(struct drm_encoder *encoder);
  816. extern const char *drm_get_connector_status_name(enum drm_connector_status status);
  817. extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
  818. extern const char *drm_get_dpms_name(int val);
  819. extern const char *drm_get_dvi_i_subconnector_name(int val);
  820. extern const char *drm_get_dvi_i_select_name(int val);
  821. extern const char *drm_get_tv_subconnector_name(int val);
  822. extern const char *drm_get_tv_select_name(int val);
  823. extern void drm_fb_release(struct drm_file *file_priv);
  824. extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
  825. extern void drm_mode_group_destroy(struct drm_mode_group *group);
  826. extern bool drm_probe_ddc(struct i2c_adapter *adapter);
  827. extern struct edid *drm_get_edid(struct drm_connector *connector,
  828. struct i2c_adapter *adapter);
  829. extern struct edid *drm_edid_duplicate(const struct edid *edid);
  830. extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
  831. extern void drm_mode_config_init(struct drm_device *dev);
  832. extern void drm_mode_config_reset(struct drm_device *dev);
  833. extern void drm_mode_config_cleanup(struct drm_device *dev);
  834. extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
  835. struct edid *edid);
  836. static inline bool drm_property_type_is(struct drm_property *property,
  837. uint32_t type)
  838. {
  839. /* instanceof for props.. handles extended type vs original types: */
  840. if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
  841. return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
  842. return property->flags & type;
  843. }
  844. static inline bool drm_property_type_valid(struct drm_property *property)
  845. {
  846. if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
  847. return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
  848. return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
  849. }
  850. extern int drm_object_property_set_value(struct drm_mode_object *obj,
  851. struct drm_property *property,
  852. uint64_t val);
  853. extern int drm_object_property_get_value(struct drm_mode_object *obj,
  854. struct drm_property *property,
  855. uint64_t *value);
  856. extern int drm_framebuffer_init(struct drm_device *dev,
  857. struct drm_framebuffer *fb,
  858. const struct drm_framebuffer_funcs *funcs);
  859. extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
  860. uint32_t id);
  861. extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
  862. extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
  863. extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
  864. extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
  865. extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
  866. extern void drm_object_attach_property(struct drm_mode_object *obj,
  867. struct drm_property *property,
  868. uint64_t init_val);
  869. extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
  870. const char *name, int num_values);
  871. extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
  872. const char *name,
  873. const struct drm_prop_enum_list *props,
  874. int num_values);
  875. struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
  876. int flags, const char *name,
  877. const struct drm_prop_enum_list *props,
  878. int num_values);
  879. struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
  880. const char *name,
  881. uint64_t min, uint64_t max);
  882. struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
  883. int flags, const char *name,
  884. int64_t min, int64_t max);
  885. struct drm_property *drm_property_create_object(struct drm_device *dev,
  886. int flags, const char *name, uint32_t type);
  887. extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
  888. extern int drm_property_add_enum(struct drm_property *property, int index,
  889. uint64_t value, const char *name);
  890. extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
  891. extern int drm_mode_create_tv_properties(struct drm_device *dev, int num_formats,
  892. char *formats[]);
  893. extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
  894. extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
  895. extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
  896. struct drm_encoder *encoder);
  897. extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
  898. int gamma_size);
  899. extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
  900. uint32_t id, uint32_t type);
  901. /* IOCTLs */
  902. extern int drm_mode_getresources(struct drm_device *dev,
  903. void *data, struct drm_file *file_priv);
  904. extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
  905. struct drm_file *file_priv);
  906. extern int drm_mode_getcrtc(struct drm_device *dev,
  907. void *data, struct drm_file *file_priv);
  908. extern int drm_mode_getconnector(struct drm_device *dev,
  909. void *data, struct drm_file *file_priv);
  910. extern int drm_mode_set_config_internal(struct drm_mode_set *set);
  911. extern int drm_mode_setcrtc(struct drm_device *dev,
  912. void *data, struct drm_file *file_priv);
  913. extern int drm_mode_getplane(struct drm_device *dev,
  914. void *data, struct drm_file *file_priv);
  915. extern int drm_mode_setplane(struct drm_device *dev,
  916. void *data, struct drm_file *file_priv);
  917. extern int drm_mode_cursor_ioctl(struct drm_device *dev,
  918. void *data, struct drm_file *file_priv);
  919. extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
  920. void *data, struct drm_file *file_priv);
  921. extern int drm_mode_addfb(struct drm_device *dev,
  922. void *data, struct drm_file *file_priv);
  923. extern int drm_mode_addfb2(struct drm_device *dev,
  924. void *data, struct drm_file *file_priv);
  925. extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
  926. extern int drm_mode_rmfb(struct drm_device *dev,
  927. void *data, struct drm_file *file_priv);
  928. extern int drm_mode_getfb(struct drm_device *dev,
  929. void *data, struct drm_file *file_priv);
  930. extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
  931. void *data, struct drm_file *file_priv);
  932. extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
  933. void *data, struct drm_file *file_priv);
  934. extern int drm_mode_getblob_ioctl(struct drm_device *dev,
  935. void *data, struct drm_file *file_priv);
  936. extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
  937. void *data, struct drm_file *file_priv);
  938. extern int drm_mode_getencoder(struct drm_device *dev,
  939. void *data, struct drm_file *file_priv);
  940. extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
  941. void *data, struct drm_file *file_priv);
  942. extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
  943. void *data, struct drm_file *file_priv);
  944. extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
  945. extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
  946. extern bool drm_detect_hdmi_monitor(struct edid *edid);
  947. extern bool drm_detect_monitor_audio(struct edid *edid);
  948. extern bool drm_rgb_quant_range_selectable(struct edid *edid);
  949. extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
  950. void *data, struct drm_file *file_priv);
  951. extern int drm_add_modes_noedid(struct drm_connector *connector,
  952. int hdisplay, int vdisplay);
  953. extern void drm_set_preferred_mode(struct drm_connector *connector,
  954. int hpref, int vpref);
  955. extern int drm_edid_header_is_valid(const u8 *raw_edid);
  956. extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid);
  957. extern bool drm_edid_is_valid(struct edid *edid);
  958. struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
  959. int hsize, int vsize, int fresh,
  960. bool rb);
  961. extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
  962. void *data, struct drm_file *file_priv);
  963. extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
  964. void *data, struct drm_file *file_priv);
  965. extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
  966. void *data, struct drm_file *file_priv);
  967. extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
  968. struct drm_file *file_priv);
  969. extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
  970. struct drm_file *file_priv);
  971. extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
  972. int *bpp);
  973. extern int drm_format_num_planes(uint32_t format);
  974. extern int drm_format_plane_cpp(uint32_t format, int plane);
  975. extern int drm_format_horz_chroma_subsampling(uint32_t format);
  976. extern int drm_format_vert_chroma_subsampling(uint32_t format);
  977. extern const char *drm_get_format_name(uint32_t format);
  978. /* Helpers */
  979. static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
  980. uint32_t id)
  981. {
  982. struct drm_mode_object *mo;
  983. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
  984. return mo ? obj_to_plane(mo) : NULL;
  985. }
  986. static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
  987. uint32_t id)
  988. {
  989. struct drm_mode_object *mo;
  990. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
  991. return mo ? obj_to_crtc(mo) : NULL;
  992. }
  993. static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
  994. uint32_t id)
  995. {
  996. struct drm_mode_object *mo;
  997. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
  998. return mo ? obj_to_encoder(mo) : NULL;
  999. }
  1000. static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
  1001. uint32_t id)
  1002. {
  1003. struct drm_mode_object *mo;
  1004. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
  1005. return mo ? obj_to_connector(mo) : NULL;
  1006. }
  1007. static inline struct drm_property *drm_property_find(struct drm_device *dev,
  1008. uint32_t id)
  1009. {
  1010. struct drm_mode_object *mo;
  1011. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
  1012. return mo ? obj_to_property(mo) : NULL;
  1013. }
  1014. static inline struct drm_property_blob *
  1015. drm_property_blob_find(struct drm_device *dev, uint32_t id)
  1016. {
  1017. struct drm_mode_object *mo;
  1018. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_BLOB);
  1019. return mo ? obj_to_blob(mo) : NULL;
  1020. }
  1021. /* Plane list iterator for legacy (overlay only) planes. */
  1022. #define drm_for_each_legacy_plane(plane, planelist) \
  1023. list_for_each_entry(plane, planelist, head) \
  1024. if (plane->type == DRM_PLANE_TYPE_OVERLAY)
  1025. #endif /* __DRM_CRTC_H__ */