drm_crtc.h 55 KB

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