drm_crtc.h 57 KB

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