drm_crtc.h 51 KB

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