drm_crtc.h 41 KB

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