drm_crtc.h 54 KB

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