drm_crtc.h 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197
  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. struct edid;
  46. struct drm_mode_object {
  47. uint32_t id;
  48. uint32_t type;
  49. struct drm_object_properties *properties;
  50. struct kref refcount;
  51. void (*free_cb)(struct kref *kref);
  52. };
  53. #define DRM_OBJECT_MAX_PROPERTY 24
  54. struct drm_object_properties {
  55. int count, atomic_count;
  56. /* NOTE: if we ever start dynamically destroying properties (ie.
  57. * not at drm_mode_config_cleanup() time), then we'd have to do
  58. * a better job of detaching property from mode objects to avoid
  59. * dangling property pointers:
  60. */
  61. struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
  62. /* do not read/write values directly, but use drm_object_property_get_value()
  63. * and drm_object_property_set_value():
  64. */
  65. uint64_t values[DRM_OBJECT_MAX_PROPERTY];
  66. };
  67. static inline int64_t U642I64(uint64_t val)
  68. {
  69. return (int64_t)*((int64_t *)&val);
  70. }
  71. static inline uint64_t I642U64(int64_t val)
  72. {
  73. return (uint64_t)*((uint64_t *)&val);
  74. }
  75. /*
  76. * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
  77. * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
  78. * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
  79. */
  80. #define DRM_ROTATE_MASK 0x0f
  81. #define DRM_ROTATE_0 0
  82. #define DRM_ROTATE_90 1
  83. #define DRM_ROTATE_180 2
  84. #define DRM_ROTATE_270 3
  85. #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
  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. #define DRM_BUS_FLAG_DE_LOW (1<<0)
  112. #define DRM_BUS_FLAG_DE_HIGH (1<<1)
  113. /* drive data on pos. edge */
  114. #define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
  115. /* drive data on neg. edge */
  116. #define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
  117. /*
  118. * Describes a given display (e.g. CRT or flat panel) and its limitations.
  119. */
  120. struct drm_display_info {
  121. char name[DRM_DISPLAY_INFO_LEN];
  122. /* Physical size */
  123. unsigned int width_mm;
  124. unsigned int height_mm;
  125. /* Clock limits FIXME: storage format */
  126. unsigned int min_vfreq, max_vfreq;
  127. unsigned int min_hfreq, max_hfreq;
  128. unsigned int pixel_clock;
  129. unsigned int bpc;
  130. enum subpixel_order subpixel_order;
  131. u32 color_formats;
  132. const u32 *bus_formats;
  133. unsigned int num_bus_formats;
  134. u32 bus_flags;
  135. /* Mask of supported hdmi deep color modes */
  136. u8 edid_hdmi_dc_modes;
  137. u8 cea_rev;
  138. };
  139. /* data corresponds to displayid vend/prod/serial */
  140. struct drm_tile_group {
  141. struct kref refcount;
  142. struct drm_device *dev;
  143. int id;
  144. u8 group_data[8];
  145. };
  146. /**
  147. * struct drm_framebuffer_funcs - framebuffer hooks
  148. */
  149. struct drm_framebuffer_funcs {
  150. /**
  151. * @destroy:
  152. *
  153. * Clean up framebuffer resources, specifically also unreference the
  154. * backing storage. The core guarantees to call this function for every
  155. * framebuffer successfully created by ->fb_create() in
  156. * &drm_mode_config_funcs. Drivers must also call
  157. * drm_framebuffer_cleanup() to release DRM core resources for this
  158. * framebuffer.
  159. */
  160. void (*destroy)(struct drm_framebuffer *framebuffer);
  161. /**
  162. * @create_handle:
  163. *
  164. * Create a buffer handle in the driver-specific buffer manager (either
  165. * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
  166. * the core to implement the GETFB IOCTL, which returns (for
  167. * sufficiently priviledged user) also a native buffer handle. This can
  168. * be used for seamless transitions between modesetting clients by
  169. * copying the current screen contents to a private buffer and blending
  170. * between that and the new contents.
  171. *
  172. * GEM based drivers should call drm_gem_handle_create() to create the
  173. * handle.
  174. *
  175. * RETURNS:
  176. *
  177. * 0 on success or a negative error code on failure.
  178. */
  179. int (*create_handle)(struct drm_framebuffer *fb,
  180. struct drm_file *file_priv,
  181. unsigned int *handle);
  182. /**
  183. * @dirty:
  184. *
  185. * Optional callback for the dirty fb IOCTL.
  186. *
  187. * Userspace can notify the driver via this callback that an area of the
  188. * framebuffer has changed and should be flushed to the display
  189. * hardware. This can also be used internally, e.g. by the fbdev
  190. * emulation, though that's not the case currently.
  191. *
  192. * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
  193. * for more information as all the semantics and arguments have a one to
  194. * one mapping on this function.
  195. *
  196. * RETURNS:
  197. *
  198. * 0 on success or a negative error code on failure.
  199. */
  200. int (*dirty)(struct drm_framebuffer *framebuffer,
  201. struct drm_file *file_priv, unsigned flags,
  202. unsigned color, struct drm_clip_rect *clips,
  203. unsigned num_clips);
  204. };
  205. struct drm_framebuffer {
  206. struct drm_device *dev;
  207. /*
  208. * Note that the fb is refcounted for the benefit of driver internals,
  209. * for example some hw, disabling a CRTC/plane is asynchronous, and
  210. * scanout does not actually complete until the next vblank. So some
  211. * cleanup (like releasing the reference(s) on the backing GEM bo(s))
  212. * should be deferred. In cases like this, the driver would like to
  213. * hold a ref to the fb even though it has already been removed from
  214. * userspace perspective.
  215. * The refcount is stored inside the mode object.
  216. */
  217. /*
  218. * Place on the dev->mode_config.fb_list, access protected by
  219. * dev->mode_config.fb_lock.
  220. */
  221. struct list_head head;
  222. struct drm_mode_object base;
  223. const struct drm_framebuffer_funcs *funcs;
  224. unsigned int pitches[4];
  225. unsigned int offsets[4];
  226. uint64_t modifier[4];
  227. unsigned int width;
  228. unsigned int height;
  229. /* depth can be 15 or 16 */
  230. unsigned int depth;
  231. int bits_per_pixel;
  232. int flags;
  233. uint32_t pixel_format; /* fourcc format */
  234. int hot_x;
  235. int hot_y;
  236. struct list_head filp_head;
  237. };
  238. struct drm_property_blob {
  239. struct drm_mode_object base;
  240. struct drm_device *dev;
  241. struct list_head head_global;
  242. struct list_head head_file;
  243. size_t length;
  244. unsigned char data[];
  245. };
  246. struct drm_property_enum {
  247. uint64_t value;
  248. struct list_head head;
  249. char name[DRM_PROP_NAME_LEN];
  250. };
  251. struct drm_property {
  252. struct list_head head;
  253. struct drm_mode_object base;
  254. uint32_t flags;
  255. char name[DRM_PROP_NAME_LEN];
  256. uint32_t num_values;
  257. uint64_t *values;
  258. struct drm_device *dev;
  259. struct list_head enum_list;
  260. };
  261. struct drm_crtc;
  262. struct drm_connector;
  263. struct drm_encoder;
  264. struct drm_pending_vblank_event;
  265. struct drm_plane;
  266. struct drm_bridge;
  267. struct drm_atomic_state;
  268. struct drm_crtc_helper_funcs;
  269. struct drm_encoder_helper_funcs;
  270. struct drm_connector_helper_funcs;
  271. struct drm_plane_helper_funcs;
  272. /**
  273. * struct drm_crtc_state - mutable CRTC state
  274. * @crtc: backpointer to the CRTC
  275. * @enable: whether the CRTC should be enabled, gates all other state
  276. * @active: whether the CRTC is actively displaying (used for DPMS)
  277. * @planes_changed: planes on this crtc are updated
  278. * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
  279. * @active_changed: crtc_state->active has been toggled.
  280. * @connectors_changed: connectors to this crtc have been updated
  281. * @zpos_changed: zpos values of planes on this crtc have been updated
  282. * @color_mgmt_changed: color management properties have changed (degamma or
  283. * gamma LUT or CSC matrix)
  284. * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
  285. * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
  286. * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
  287. * @last_vblank_count: for helpers and drivers to capture the vblank of the
  288. * update to ensure framebuffer cleanup isn't done too early
  289. * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
  290. * @mode: current mode timings
  291. * @mode_blob: &drm_property_blob for @mode
  292. * @degamma_lut: Lookup table for converting framebuffer pixel data
  293. * before apply the conversion matrix
  294. * @ctm: Transformation matrix
  295. * @gamma_lut: Lookup table for converting pixel data after the
  296. * conversion matrix
  297. * @event: optional pointer to a DRM event to signal upon completion of the
  298. * state update
  299. * @state: backpointer to global drm_atomic_state
  300. *
  301. * Note that the distinction between @enable and @active is rather subtile:
  302. * Flipping @active while @enable is set without changing anything else may
  303. * never return in a failure from the ->atomic_check callback. Userspace assumes
  304. * that a DPMS On will always succeed. In other words: @enable controls resource
  305. * assignment, @active controls the actual hardware state.
  306. */
  307. struct drm_crtc_state {
  308. struct drm_crtc *crtc;
  309. bool enable;
  310. bool active;
  311. /* computed state bits used by helpers and drivers */
  312. bool planes_changed : 1;
  313. bool mode_changed : 1;
  314. bool active_changed : 1;
  315. bool connectors_changed : 1;
  316. bool zpos_changed : 1;
  317. bool color_mgmt_changed : 1;
  318. /* attached planes bitmask:
  319. * WARNING: transitional helpers do not maintain plane_mask so
  320. * drivers not converted over to atomic helpers should not rely
  321. * on plane_mask being accurate!
  322. */
  323. u32 plane_mask;
  324. u32 connector_mask;
  325. u32 encoder_mask;
  326. /* last_vblank_count: for vblank waits before cleanup */
  327. u32 last_vblank_count;
  328. /* adjusted_mode: for use by helpers and drivers */
  329. struct drm_display_mode adjusted_mode;
  330. struct drm_display_mode mode;
  331. /* blob property to expose current mode to atomic userspace */
  332. struct drm_property_blob *mode_blob;
  333. /* blob property to expose color management to userspace */
  334. struct drm_property_blob *degamma_lut;
  335. struct drm_property_blob *ctm;
  336. struct drm_property_blob *gamma_lut;
  337. struct drm_pending_vblank_event *event;
  338. struct drm_atomic_state *state;
  339. };
  340. /**
  341. * struct drm_crtc_funcs - control CRTCs for a given device
  342. *
  343. * The drm_crtc_funcs structure is the central CRTC management structure
  344. * in the DRM. Each CRTC controls one or more connectors (note that the name
  345. * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
  346. * connectors, not just CRTs).
  347. *
  348. * Each driver is responsible for filling out this structure at startup time,
  349. * in addition to providing other modesetting features, like i2c and DDC
  350. * bus accessors.
  351. */
  352. struct drm_crtc_funcs {
  353. /**
  354. * @reset:
  355. *
  356. * Reset CRTC hardware and software state to off. This function isn't
  357. * called by the core directly, only through drm_mode_config_reset().
  358. * It's not a helper hook only for historical reasons.
  359. *
  360. * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
  361. * atomic state using this hook.
  362. */
  363. void (*reset)(struct drm_crtc *crtc);
  364. /**
  365. * @cursor_set:
  366. *
  367. * Update the cursor image. The cursor position is relative to the CRTC
  368. * and can be partially or fully outside of the visible area.
  369. *
  370. * Note that contrary to all other KMS functions the legacy cursor entry
  371. * points don't take a framebuffer object, but instead take directly a
  372. * raw buffer object id from the driver's buffer manager (which is
  373. * either GEM or TTM for current drivers).
  374. *
  375. * This entry point is deprecated, drivers should instead implement
  376. * universal plane support and register a proper cursor plane using
  377. * drm_crtc_init_with_planes().
  378. *
  379. * This callback is optional
  380. *
  381. * RETURNS:
  382. *
  383. * 0 on success or a negative error code on failure.
  384. */
  385. int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
  386. uint32_t handle, uint32_t width, uint32_t height);
  387. /**
  388. * @cursor_set2:
  389. *
  390. * Update the cursor image, including hotspot information. The hotspot
  391. * must not affect the cursor position in CRTC coordinates, but is only
  392. * meant as a hint for virtualized display hardware to coordinate the
  393. * guests and hosts cursor position. The cursor hotspot is relative to
  394. * the cursor image. Otherwise this works exactly like @cursor_set.
  395. *
  396. * This entry point is deprecated, drivers should instead implement
  397. * universal plane support and register a proper cursor plane using
  398. * drm_crtc_init_with_planes().
  399. *
  400. * This callback is optional.
  401. *
  402. * RETURNS:
  403. *
  404. * 0 on success or a negative error code on failure.
  405. */
  406. int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
  407. uint32_t handle, uint32_t width, uint32_t height,
  408. int32_t hot_x, int32_t hot_y);
  409. /**
  410. * @cursor_move:
  411. *
  412. * Update the cursor position. The cursor does not need to be visible
  413. * when this hook is called.
  414. *
  415. * This entry point is deprecated, drivers should instead implement
  416. * universal plane support and register a proper cursor plane using
  417. * drm_crtc_init_with_planes().
  418. *
  419. * This callback is optional.
  420. *
  421. * RETURNS:
  422. *
  423. * 0 on success or a negative error code on failure.
  424. */
  425. int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
  426. /**
  427. * @gamma_set:
  428. *
  429. * Set gamma on the CRTC.
  430. *
  431. * This callback is optional.
  432. *
  433. * NOTE:
  434. *
  435. * Drivers that support gamma tables and also fbdev emulation through
  436. * the provided helper library need to take care to fill out the gamma
  437. * hooks for both. Currently there's a bit an unfortunate duplication
  438. * going on, which should eventually be unified to just one set of
  439. * hooks.
  440. */
  441. int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  442. uint32_t size);
  443. /**
  444. * @destroy:
  445. *
  446. * Clean up plane resources. This is only called at driver unload time
  447. * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
  448. * in DRM.
  449. */
  450. void (*destroy)(struct drm_crtc *crtc);
  451. /**
  452. * @set_config:
  453. *
  454. * This is the main legacy entry point to change the modeset state on a
  455. * CRTC. All the details of the desired configuration are passed in a
  456. * struct &drm_mode_set - see there for details.
  457. *
  458. * Drivers implementing atomic modeset should use
  459. * drm_atomic_helper_set_config() to implement this hook.
  460. *
  461. * RETURNS:
  462. *
  463. * 0 on success or a negative error code on failure.
  464. */
  465. int (*set_config)(struct drm_mode_set *set);
  466. /**
  467. * @page_flip:
  468. *
  469. * Legacy entry point to schedule a flip to the given framebuffer.
  470. *
  471. * Page flipping is a synchronization mechanism that replaces the frame
  472. * buffer being scanned out by the CRTC with a new frame buffer during
  473. * vertical blanking, avoiding tearing (except when requested otherwise
  474. * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
  475. * requests a page flip the DRM core verifies that the new frame buffer
  476. * is large enough to be scanned out by the CRTC in the currently
  477. * configured mode and then calls the CRTC ->page_flip() operation with a
  478. * pointer to the new frame buffer.
  479. *
  480. * The driver must wait for any pending rendering to the new framebuffer
  481. * to complete before executing the flip. It should also wait for any
  482. * pending rendering from other drivers if the underlying buffer is a
  483. * shared dma-buf.
  484. *
  485. * An application can request to be notified when the page flip has
  486. * completed. The drm core will supply a struct &drm_event in the event
  487. * parameter in this case. This can be handled by the
  488. * drm_crtc_send_vblank_event() function, which the driver should call on
  489. * the provided event upon completion of the flip. Note that if
  490. * the driver supports vblank signalling and timestamping the vblank
  491. * counters and timestamps must agree with the ones returned from page
  492. * flip events. With the current vblank helper infrastructure this can
  493. * be achieved by holding a vblank reference while the page flip is
  494. * pending, acquired through drm_crtc_vblank_get() and released with
  495. * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
  496. * counter and timestamp tracking though, e.g. if they have accurate
  497. * timestamp registers in hardware.
  498. *
  499. * FIXME:
  500. *
  501. * Up to that point drivers need to manage events themselves and can use
  502. * even->base.list freely for that. Specifically they need to ensure
  503. * that they don't send out page flip (or vblank) events for which the
  504. * corresponding drm file has been closed already. The drm core
  505. * unfortunately does not (yet) take care of that. Therefore drivers
  506. * currently must clean up and release pending events in their
  507. * ->preclose driver function.
  508. *
  509. * This callback is optional.
  510. *
  511. * NOTE:
  512. *
  513. * Very early versions of the KMS ABI mandated that the driver must
  514. * block (but not reject) any rendering to the old framebuffer until the
  515. * flip operation has completed and the old framebuffer is no longer
  516. * visible. This requirement has been lifted, and userspace is instead
  517. * expected to request delivery of an event and wait with recycling old
  518. * buffers until such has been received.
  519. *
  520. * RETURNS:
  521. *
  522. * 0 on success or a negative error code on failure. Note that if a
  523. * ->page_flip() operation is already pending the callback should return
  524. * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
  525. * or just runtime disabled through DPMS respectively the new atomic
  526. * "ACTIVE" state) should result in an -EINVAL error code. Note that
  527. * drm_atomic_helper_page_flip() checks this already for atomic drivers.
  528. */
  529. int (*page_flip)(struct drm_crtc *crtc,
  530. struct drm_framebuffer *fb,
  531. struct drm_pending_vblank_event *event,
  532. uint32_t flags);
  533. /**
  534. * @set_property:
  535. *
  536. * This is the legacy entry point to update a property attached to the
  537. * CRTC.
  538. *
  539. * Drivers implementing atomic modeset should use
  540. * drm_atomic_helper_crtc_set_property() to implement this hook.
  541. *
  542. * This callback is optional if the driver does not support any legacy
  543. * driver-private properties.
  544. *
  545. * RETURNS:
  546. *
  547. * 0 on success or a negative error code on failure.
  548. */
  549. int (*set_property)(struct drm_crtc *crtc,
  550. struct drm_property *property, uint64_t val);
  551. /**
  552. * @atomic_duplicate_state:
  553. *
  554. * Duplicate the current atomic state for this CRTC and return it.
  555. * The core and helpers gurantee that any atomic state duplicated with
  556. * this hook and still owned by the caller (i.e. not transferred to the
  557. * driver by calling ->atomic_commit() from struct
  558. * &drm_mode_config_funcs) will be cleaned up by calling the
  559. * @atomic_destroy_state hook in this structure.
  560. *
  561. * Atomic drivers which don't subclass struct &drm_crtc should use
  562. * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
  563. * state structure to extend it with driver-private state should use
  564. * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
  565. * duplicated in a consistent fashion across drivers.
  566. *
  567. * It is an error to call this hook before crtc->state has been
  568. * initialized correctly.
  569. *
  570. * NOTE:
  571. *
  572. * If the duplicate state references refcounted resources this hook must
  573. * acquire a reference for each of them. The driver must release these
  574. * references again in @atomic_destroy_state.
  575. *
  576. * RETURNS:
  577. *
  578. * Duplicated atomic state or NULL when the allocation failed.
  579. */
  580. struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
  581. /**
  582. * @atomic_destroy_state:
  583. *
  584. * Destroy a state duplicated with @atomic_duplicate_state and release
  585. * or unreference all resources it references
  586. */
  587. void (*atomic_destroy_state)(struct drm_crtc *crtc,
  588. struct drm_crtc_state *state);
  589. /**
  590. * @atomic_set_property:
  591. *
  592. * Decode a driver-private property value and store the decoded value
  593. * into the passed-in state structure. Since the atomic core decodes all
  594. * standardized properties (even for extensions beyond the core set of
  595. * properties which might not be implemented by all drivers) this
  596. * requires drivers to subclass the state structure.
  597. *
  598. * Such driver-private properties should really only be implemented for
  599. * truly hardware/vendor specific state. Instead it is preferred to
  600. * standardize atomic extension and decode the properties used to expose
  601. * such an extension in the core.
  602. *
  603. * Do not call this function directly, use
  604. * drm_atomic_crtc_set_property() instead.
  605. *
  606. * This callback is optional if the driver does not support any
  607. * driver-private atomic properties.
  608. *
  609. * NOTE:
  610. *
  611. * This function is called in the state assembly phase of atomic
  612. * modesets, which can be aborted for any reason (including on
  613. * userspace's request to just check whether a configuration would be
  614. * possible). Drivers MUST NOT touch any persistent state (hardware or
  615. * software) or data structures except the passed in @state parameter.
  616. *
  617. * Also since userspace controls in which order properties are set this
  618. * function must not do any input validation (since the state update is
  619. * incomplete and hence likely inconsistent). Instead any such input
  620. * validation must be done in the various atomic_check callbacks.
  621. *
  622. * RETURNS:
  623. *
  624. * 0 if the property has been found, -EINVAL if the property isn't
  625. * implemented by the driver (which should never happen, the core only
  626. * asks for properties attached to this CRTC). No other validation is
  627. * allowed by the driver. The core already checks that the property
  628. * value is within the range (integer, valid enum value, ...) the driver
  629. * set when registering the property.
  630. */
  631. int (*atomic_set_property)(struct drm_crtc *crtc,
  632. struct drm_crtc_state *state,
  633. struct drm_property *property,
  634. uint64_t val);
  635. /**
  636. * @atomic_get_property:
  637. *
  638. * Reads out the decoded driver-private property. This is used to
  639. * implement the GETCRTC IOCTL.
  640. *
  641. * Do not call this function directly, use
  642. * drm_atomic_crtc_get_property() instead.
  643. *
  644. * This callback is optional if the driver does not support any
  645. * driver-private atomic properties.
  646. *
  647. * RETURNS:
  648. *
  649. * 0 on success, -EINVAL if the property isn't implemented by the
  650. * driver (which should never happen, the core only asks for
  651. * properties attached to this CRTC).
  652. */
  653. int (*atomic_get_property)(struct drm_crtc *crtc,
  654. const struct drm_crtc_state *state,
  655. struct drm_property *property,
  656. uint64_t *val);
  657. /**
  658. * @late_register:
  659. *
  660. * This optional hook can be used to register additional userspace
  661. * interfaces attached to the crtc like debugfs interfaces.
  662. * It is called late in the driver load sequence from drm_dev_register().
  663. * Everything added from this callback should be unregistered in
  664. * the early_unregister callback.
  665. *
  666. * Returns:
  667. *
  668. * 0 on success, or a negative error code on failure.
  669. */
  670. int (*late_register)(struct drm_crtc *crtc);
  671. /**
  672. * @early_unregister:
  673. *
  674. * This optional hook should be used to unregister the additional
  675. * userspace interfaces attached to the crtc from
  676. * late_unregister(). It is called from drm_dev_unregister(),
  677. * early in the driver unload sequence to disable userspace access
  678. * before data structures are torndown.
  679. */
  680. void (*early_unregister)(struct drm_crtc *crtc);
  681. };
  682. /**
  683. * struct drm_crtc - central CRTC control structure
  684. * @dev: parent DRM device
  685. * @port: OF node used by drm_of_find_possible_crtcs()
  686. * @head: list management
  687. * @name: human readable name, can be overwritten by the driver
  688. * @mutex: per-CRTC locking
  689. * @base: base KMS object for ID tracking etc.
  690. * @primary: primary plane for this CRTC
  691. * @cursor: cursor plane for this CRTC
  692. * @cursor_x: current x position of the cursor, used for universal cursor planes
  693. * @cursor_y: current y position of the cursor, used for universal cursor planes
  694. * @enabled: is this CRTC enabled?
  695. * @mode: current mode timings
  696. * @hwmode: mode timings as programmed to hw regs
  697. * @x: x position on screen
  698. * @y: y position on screen
  699. * @funcs: CRTC control functions
  700. * @gamma_size: size of gamma ramp
  701. * @gamma_store: gamma ramp values
  702. * @helper_private: mid-layer private data
  703. * @properties: property tracking for this CRTC
  704. *
  705. * Each CRTC may have one or more connectors associated with it. This structure
  706. * allows the CRTC to be controlled.
  707. */
  708. struct drm_crtc {
  709. struct drm_device *dev;
  710. struct device_node *port;
  711. struct list_head head;
  712. char *name;
  713. /**
  714. * @mutex:
  715. *
  716. * This provides a read lock for the overall crtc state (mode, dpms
  717. * state, ...) and a write lock for everything which can be update
  718. * without a full modeset (fb, cursor data, crtc properties ...). Full
  719. * modeset also need to grab dev->mode_config.connection_mutex.
  720. */
  721. struct drm_modeset_lock mutex;
  722. struct drm_mode_object base;
  723. /* primary and cursor planes for CRTC */
  724. struct drm_plane *primary;
  725. struct drm_plane *cursor;
  726. /**
  727. * @index: Position inside the mode_config.list, can be used as an array
  728. * index. It is invariant over the lifetime of the CRTC.
  729. */
  730. unsigned index;
  731. /* position of cursor plane on crtc */
  732. int cursor_x;
  733. int cursor_y;
  734. bool enabled;
  735. /* Requested mode from modesetting. */
  736. struct drm_display_mode mode;
  737. /* Programmed mode in hw, after adjustments for encoders,
  738. * crtc, panel scaling etc. Needed for timestamping etc.
  739. */
  740. struct drm_display_mode hwmode;
  741. int x, y;
  742. const struct drm_crtc_funcs *funcs;
  743. /* Legacy FB CRTC gamma size for reporting to userspace */
  744. uint32_t gamma_size;
  745. uint16_t *gamma_store;
  746. /* if you are using the helper */
  747. const struct drm_crtc_helper_funcs *helper_private;
  748. struct drm_object_properties properties;
  749. /**
  750. * @state:
  751. *
  752. * Current atomic state for this CRTC.
  753. */
  754. struct drm_crtc_state *state;
  755. /**
  756. * @commit_list:
  757. *
  758. * List of &drm_crtc_commit structures tracking pending commits.
  759. * Protected by @commit_lock. This list doesn't hold its own full
  760. * reference, but burrows it from the ongoing commit. Commit entries
  761. * must be removed from this list once the commit is fully completed,
  762. * but before it's correspoding &drm_atomic_state gets destroyed.
  763. */
  764. struct list_head commit_list;
  765. /**
  766. * @commit_lock:
  767. *
  768. * Spinlock to protect @commit_list.
  769. */
  770. spinlock_t commit_lock;
  771. /**
  772. * @acquire_ctx:
  773. *
  774. * Per-CRTC implicit acquire context used by atomic drivers for legacy
  775. * IOCTLs, so that atomic drivers can get at the locking acquire
  776. * context.
  777. */
  778. struct drm_modeset_acquire_ctx *acquire_ctx;
  779. };
  780. /**
  781. * struct drm_connector_state - mutable connector state
  782. * @connector: backpointer to the connector
  783. * @crtc: CRTC to connect connector to, NULL if disabled
  784. * @best_encoder: can be used by helpers and drivers to select the encoder
  785. * @state: backpointer to global drm_atomic_state
  786. */
  787. struct drm_connector_state {
  788. struct drm_connector *connector;
  789. struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
  790. struct drm_encoder *best_encoder;
  791. struct drm_atomic_state *state;
  792. };
  793. /**
  794. * struct drm_connector_funcs - control connectors on a given device
  795. *
  796. * Each CRTC may have one or more connectors attached to it. The functions
  797. * below allow the core DRM code to control connectors, enumerate available modes,
  798. * etc.
  799. */
  800. struct drm_connector_funcs {
  801. /**
  802. * @dpms:
  803. *
  804. * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
  805. * is exposed as a standard property on the connector, but diverted to
  806. * this callback in the drm core. Note that atomic drivers don't
  807. * implement the 4 level DPMS support on the connector any more, but
  808. * instead only have an on/off "ACTIVE" property on the CRTC object.
  809. *
  810. * Drivers implementing atomic modeset should use
  811. * drm_atomic_helper_connector_dpms() to implement this hook.
  812. *
  813. * RETURNS:
  814. *
  815. * 0 on success or a negative error code on failure.
  816. */
  817. int (*dpms)(struct drm_connector *connector, int mode);
  818. /**
  819. * @reset:
  820. *
  821. * Reset connector hardware and software state to off. This function isn't
  822. * called by the core directly, only through drm_mode_config_reset().
  823. * It's not a helper hook only for historical reasons.
  824. *
  825. * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
  826. * atomic state using this hook.
  827. */
  828. void (*reset)(struct drm_connector *connector);
  829. /**
  830. * @detect:
  831. *
  832. * Check to see if anything is attached to the connector. The parameter
  833. * force is set to false whilst polling, true when checking the
  834. * connector due to a user request. force can be used by the driver to
  835. * avoid expensive, destructive operations during automated probing.
  836. *
  837. * FIXME:
  838. *
  839. * Note that this hook is only called by the probe helper. It's not in
  840. * the helper library vtable purely for historical reasons. The only DRM
  841. * core entry point to probe connector state is @fill_modes.
  842. *
  843. * RETURNS:
  844. *
  845. * drm_connector_status indicating the connector's status.
  846. */
  847. enum drm_connector_status (*detect)(struct drm_connector *connector,
  848. bool force);
  849. /**
  850. * @force:
  851. *
  852. * This function is called to update internal encoder state when the
  853. * connector is forced to a certain state by userspace, either through
  854. * the sysfs interfaces or on the kernel cmdline. In that case the
  855. * @detect callback isn't called.
  856. *
  857. * FIXME:
  858. *
  859. * Note that this hook is only called by the probe helper. It's not in
  860. * the helper library vtable purely for historical reasons. The only DRM
  861. * core entry point to probe connector state is @fill_modes.
  862. */
  863. void (*force)(struct drm_connector *connector);
  864. /**
  865. * @fill_modes:
  866. *
  867. * Entry point for output detection and basic mode validation. The
  868. * driver should reprobe the output if needed (e.g. when hotplug
  869. * handling is unreliable), add all detected modes to connector->modes
  870. * and filter out any the device can't support in any configuration. It
  871. * also needs to filter out any modes wider or higher than the
  872. * parameters max_width and max_height indicate.
  873. *
  874. * The drivers must also prune any modes no longer valid from
  875. * connector->modes. Furthermore it must update connector->status and
  876. * connector->edid. If no EDID has been received for this output
  877. * connector->edid must be NULL.
  878. *
  879. * Drivers using the probe helpers should use
  880. * drm_helper_probe_single_connector_modes() or
  881. * drm_helper_probe_single_connector_modes_nomerge() to implement this
  882. * function.
  883. *
  884. * RETURNS:
  885. *
  886. * The number of modes detected and filled into connector->modes.
  887. */
  888. int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
  889. /**
  890. * @set_property:
  891. *
  892. * This is the legacy entry point to update a property attached to the
  893. * connector.
  894. *
  895. * Drivers implementing atomic modeset should use
  896. * drm_atomic_helper_connector_set_property() to implement this hook.
  897. *
  898. * This callback is optional if the driver does not support any legacy
  899. * driver-private properties.
  900. *
  901. * RETURNS:
  902. *
  903. * 0 on success or a negative error code on failure.
  904. */
  905. int (*set_property)(struct drm_connector *connector, struct drm_property *property,
  906. uint64_t val);
  907. /**
  908. * @late_register:
  909. *
  910. * This optional hook can be used to register additional userspace
  911. * interfaces attached to the connector, light backlight control, i2c,
  912. * DP aux or similar interfaces. It is called late in the driver load
  913. * sequence from drm_connector_register() when registering all the
  914. * core drm connector interfaces. Everything added from this callback
  915. * should be unregistered in the early_unregister callback.
  916. *
  917. * Returns:
  918. *
  919. * 0 on success, or a negative error code on failure.
  920. */
  921. int (*late_register)(struct drm_connector *connector);
  922. /**
  923. * @early_unregister:
  924. *
  925. * This optional hook should be used to unregister the additional
  926. * userspace interfaces attached to the connector from
  927. * late_unregister(). It is called from drm_connector_unregister(),
  928. * early in the driver unload sequence to disable userspace access
  929. * before data structures are torndown.
  930. */
  931. void (*early_unregister)(struct drm_connector *connector);
  932. /**
  933. * @destroy:
  934. *
  935. * Clean up connector resources. This is called at driver unload time
  936. * through drm_mode_config_cleanup(). It can also be called at runtime
  937. * when a connector is being hot-unplugged for drivers that support
  938. * connector hotplugging (e.g. DisplayPort MST).
  939. */
  940. void (*destroy)(struct drm_connector *connector);
  941. /**
  942. * @atomic_duplicate_state:
  943. *
  944. * Duplicate the current atomic state for this connector and return it.
  945. * The core and helpers gurantee that any atomic state duplicated with
  946. * this hook and still owned by the caller (i.e. not transferred to the
  947. * driver by calling ->atomic_commit() from struct
  948. * &drm_mode_config_funcs) will be cleaned up by calling the
  949. * @atomic_destroy_state hook in this structure.
  950. *
  951. * Atomic drivers which don't subclass struct &drm_connector_state should use
  952. * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
  953. * state structure to extend it with driver-private state should use
  954. * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
  955. * duplicated in a consistent fashion across drivers.
  956. *
  957. * It is an error to call this hook before connector->state has been
  958. * initialized correctly.
  959. *
  960. * NOTE:
  961. *
  962. * If the duplicate state references refcounted resources this hook must
  963. * acquire a reference for each of them. The driver must release these
  964. * references again in @atomic_destroy_state.
  965. *
  966. * RETURNS:
  967. *
  968. * Duplicated atomic state or NULL when the allocation failed.
  969. */
  970. struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
  971. /**
  972. * @atomic_destroy_state:
  973. *
  974. * Destroy a state duplicated with @atomic_duplicate_state and release
  975. * or unreference all resources it references
  976. */
  977. void (*atomic_destroy_state)(struct drm_connector *connector,
  978. struct drm_connector_state *state);
  979. /**
  980. * @atomic_set_property:
  981. *
  982. * Decode a driver-private property value and store the decoded value
  983. * into the passed-in state structure. Since the atomic core decodes all
  984. * standardized properties (even for extensions beyond the core set of
  985. * properties which might not be implemented by all drivers) this
  986. * requires drivers to subclass the state structure.
  987. *
  988. * Such driver-private properties should really only be implemented for
  989. * truly hardware/vendor specific state. Instead it is preferred to
  990. * standardize atomic extension and decode the properties used to expose
  991. * such an extension in the core.
  992. *
  993. * Do not call this function directly, use
  994. * drm_atomic_connector_set_property() instead.
  995. *
  996. * This callback is optional if the driver does not support any
  997. * driver-private atomic properties.
  998. *
  999. * NOTE:
  1000. *
  1001. * This function is called in the state assembly phase of atomic
  1002. * modesets, which can be aborted for any reason (including on
  1003. * userspace's request to just check whether a configuration would be
  1004. * possible). Drivers MUST NOT touch any persistent state (hardware or
  1005. * software) or data structures except the passed in @state parameter.
  1006. *
  1007. * Also since userspace controls in which order properties are set this
  1008. * function must not do any input validation (since the state update is
  1009. * incomplete and hence likely inconsistent). Instead any such input
  1010. * validation must be done in the various atomic_check callbacks.
  1011. *
  1012. * RETURNS:
  1013. *
  1014. * 0 if the property has been found, -EINVAL if the property isn't
  1015. * implemented by the driver (which shouldn't ever happen, the core only
  1016. * asks for properties attached to this connector). No other validation
  1017. * is allowed by the driver. The core already checks that the property
  1018. * value is within the range (integer, valid enum value, ...) the driver
  1019. * set when registering the property.
  1020. */
  1021. int (*atomic_set_property)(struct drm_connector *connector,
  1022. struct drm_connector_state *state,
  1023. struct drm_property *property,
  1024. uint64_t val);
  1025. /**
  1026. * @atomic_get_property:
  1027. *
  1028. * Reads out the decoded driver-private property. This is used to
  1029. * implement the GETCONNECTOR IOCTL.
  1030. *
  1031. * Do not call this function directly, use
  1032. * drm_atomic_connector_get_property() instead.
  1033. *
  1034. * This callback is optional if the driver does not support any
  1035. * driver-private atomic properties.
  1036. *
  1037. * RETURNS:
  1038. *
  1039. * 0 on success, -EINVAL if the property isn't implemented by the
  1040. * driver (which shouldn't ever happen, the core only asks for
  1041. * properties attached to this connector).
  1042. */
  1043. int (*atomic_get_property)(struct drm_connector *connector,
  1044. const struct drm_connector_state *state,
  1045. struct drm_property *property,
  1046. uint64_t *val);
  1047. };
  1048. /**
  1049. * struct drm_encoder_funcs - encoder controls
  1050. *
  1051. * Encoders sit between CRTCs and connectors.
  1052. */
  1053. struct drm_encoder_funcs {
  1054. /**
  1055. * @reset:
  1056. *
  1057. * Reset encoder hardware and software state to off. This function isn't
  1058. * called by the core directly, only through drm_mode_config_reset().
  1059. * It's not a helper hook only for historical reasons.
  1060. */
  1061. void (*reset)(struct drm_encoder *encoder);
  1062. /**
  1063. * @destroy:
  1064. *
  1065. * Clean up encoder resources. This is only called at driver unload time
  1066. * through drm_mode_config_cleanup() since an encoder cannot be
  1067. * hotplugged in DRM.
  1068. */
  1069. void (*destroy)(struct drm_encoder *encoder);
  1070. /**
  1071. * @late_register:
  1072. *
  1073. * This optional hook can be used to register additional userspace
  1074. * interfaces attached to the encoder like debugfs interfaces.
  1075. * It is called late in the driver load sequence from drm_dev_register().
  1076. * Everything added from this callback should be unregistered in
  1077. * the early_unregister callback.
  1078. *
  1079. * Returns:
  1080. *
  1081. * 0 on success, or a negative error code on failure.
  1082. */
  1083. int (*late_register)(struct drm_encoder *encoder);
  1084. /**
  1085. * @early_unregister:
  1086. *
  1087. * This optional hook should be used to unregister the additional
  1088. * userspace interfaces attached to the encoder from
  1089. * late_unregister(). It is called from drm_dev_unregister(),
  1090. * early in the driver unload sequence to disable userspace access
  1091. * before data structures are torndown.
  1092. */
  1093. void (*early_unregister)(struct drm_encoder *encoder);
  1094. };
  1095. #define DRM_CONNECTOR_MAX_ENCODER 3
  1096. /**
  1097. * struct drm_encoder - central DRM encoder structure
  1098. * @dev: parent DRM device
  1099. * @head: list management
  1100. * @base: base KMS object
  1101. * @name: human readable name, can be overwritten by the driver
  1102. * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
  1103. * @possible_crtcs: bitmask of potential CRTC bindings
  1104. * @possible_clones: bitmask of potential sibling encoders for cloning
  1105. * @crtc: currently bound CRTC
  1106. * @bridge: bridge associated to the encoder
  1107. * @funcs: control functions
  1108. * @helper_private: mid-layer private data
  1109. *
  1110. * CRTCs drive pixels to encoders, which convert them into signals
  1111. * appropriate for a given connector or set of connectors.
  1112. */
  1113. struct drm_encoder {
  1114. struct drm_device *dev;
  1115. struct list_head head;
  1116. struct drm_mode_object base;
  1117. char *name;
  1118. int encoder_type;
  1119. /**
  1120. * @index: Position inside the mode_config.list, can be used as an array
  1121. * index. It is invariant over the lifetime of the encoder.
  1122. */
  1123. unsigned index;
  1124. uint32_t possible_crtcs;
  1125. uint32_t possible_clones;
  1126. struct drm_crtc *crtc;
  1127. struct drm_bridge *bridge;
  1128. const struct drm_encoder_funcs *funcs;
  1129. const struct drm_encoder_helper_funcs *helper_private;
  1130. };
  1131. /* should we poll this connector for connects and disconnects */
  1132. /* hot plug detectable */
  1133. #define DRM_CONNECTOR_POLL_HPD (1 << 0)
  1134. /* poll for connections */
  1135. #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
  1136. /* can cleanly poll for disconnections without flickering the screen */
  1137. /* DACs should rarely do this without a lot of testing */
  1138. #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
  1139. #define MAX_ELD_BYTES 128
  1140. /**
  1141. * struct drm_connector - central DRM connector control structure
  1142. * @dev: parent DRM device
  1143. * @kdev: kernel device for sysfs attributes
  1144. * @attr: sysfs attributes
  1145. * @head: list management
  1146. * @base: base KMS object
  1147. * @name: human readable name, can be overwritten by the driver
  1148. * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
  1149. * @connector_type_id: index into connector type enum
  1150. * @interlace_allowed: can this connector handle interlaced modes?
  1151. * @doublescan_allowed: can this connector handle doublescan?
  1152. * @stereo_allowed: can this connector handle stereo modes?
  1153. * @registered: is this connector exposed (registered) with userspace?
  1154. * @modes: modes available on this connector (from fill_modes() + user)
  1155. * @status: one of the drm_connector_status enums (connected, not, or unknown)
  1156. * @probed_modes: list of modes derived directly from the display
  1157. * @display_info: information about attached display (e.g. from EDID)
  1158. * @funcs: connector control functions
  1159. * @edid_blob_ptr: DRM property containing EDID if present
  1160. * @properties: property tracking for this connector
  1161. * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
  1162. * @dpms: current dpms state
  1163. * @helper_private: mid-layer private data
  1164. * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
  1165. * @force: a %DRM_FORCE_<foo> state for forced mode sets
  1166. * @override_edid: has the EDID been overwritten through debugfs for testing?
  1167. * @encoder_ids: valid encoders for this connector
  1168. * @encoder: encoder driving this connector, if any
  1169. * @eld: EDID-like data, if present
  1170. * @dvi_dual: dual link DVI, if found
  1171. * @max_tmds_clock: max clock rate, if found
  1172. * @latency_present: AV delay info from ELD, if found
  1173. * @video_latency: video latency info from ELD, if found
  1174. * @audio_latency: audio latency info from ELD, if found
  1175. * @null_edid_counter: track sinks that give us all zeros for the EDID
  1176. * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
  1177. * @edid_corrupt: indicates whether the last read EDID was corrupt
  1178. * @debugfs_entry: debugfs directory for this connector
  1179. * @state: current atomic state for this connector
  1180. * @has_tile: is this connector connected to a tiled monitor
  1181. * @tile_group: tile group for the connected monitor
  1182. * @tile_is_single_monitor: whether the tile is one monitor housing
  1183. * @num_h_tile: number of horizontal tiles in the tile group
  1184. * @num_v_tile: number of vertical tiles in the tile group
  1185. * @tile_h_loc: horizontal location of this tile
  1186. * @tile_v_loc: vertical location of this tile
  1187. * @tile_h_size: horizontal size of this tile.
  1188. * @tile_v_size: vertical size of this tile.
  1189. *
  1190. * Each connector may be connected to one or more CRTCs, or may be clonable by
  1191. * another connector if they can share a CRTC. Each connector also has a specific
  1192. * position in the broader display (referred to as a 'screen' though it could
  1193. * span multiple monitors).
  1194. */
  1195. struct drm_connector {
  1196. struct drm_device *dev;
  1197. struct device *kdev;
  1198. struct device_attribute *attr;
  1199. struct list_head head;
  1200. struct drm_mode_object base;
  1201. char *name;
  1202. /**
  1203. * @index: Compacted connector index, which matches the position inside
  1204. * the mode_config.list for drivers not supporting hot-add/removing. Can
  1205. * be used as an array index. It is invariant over the lifetime of the
  1206. * connector.
  1207. */
  1208. unsigned index;
  1209. int connector_type;
  1210. int connector_type_id;
  1211. bool interlace_allowed;
  1212. bool doublescan_allowed;
  1213. bool stereo_allowed;
  1214. bool registered;
  1215. struct list_head modes; /* list of modes on this connector */
  1216. enum drm_connector_status status;
  1217. /* these are modes added by probing with DDC or the BIOS */
  1218. struct list_head probed_modes;
  1219. struct drm_display_info display_info;
  1220. const struct drm_connector_funcs *funcs;
  1221. struct drm_property_blob *edid_blob_ptr;
  1222. struct drm_object_properties properties;
  1223. /**
  1224. * @path_blob_ptr:
  1225. *
  1226. * DRM blob property data for the DP MST path property.
  1227. */
  1228. struct drm_property_blob *path_blob_ptr;
  1229. /**
  1230. * @tile_blob_ptr:
  1231. *
  1232. * DRM blob property data for the tile property (used mostly by DP MST).
  1233. * This is meant for screens which are driven through separate display
  1234. * pipelines represented by &drm_crtc, which might not be running with
  1235. * genlocked clocks. For tiled panels which are genlocked, like
  1236. * dual-link LVDS or dual-link DSI, the driver should try to not expose
  1237. * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
  1238. */
  1239. struct drm_property_blob *tile_blob_ptr;
  1240. uint8_t polled; /* DRM_CONNECTOR_POLL_* */
  1241. /* requested DPMS state */
  1242. int dpms;
  1243. const struct drm_connector_helper_funcs *helper_private;
  1244. /* forced on connector */
  1245. struct drm_cmdline_mode cmdline_mode;
  1246. enum drm_connector_force force;
  1247. bool override_edid;
  1248. uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
  1249. struct drm_encoder *encoder; /* currently active encoder */
  1250. /* EDID bits */
  1251. uint8_t eld[MAX_ELD_BYTES];
  1252. bool dvi_dual;
  1253. int max_tmds_clock; /* in MHz */
  1254. bool latency_present[2];
  1255. int video_latency[2]; /* [0]: progressive, [1]: interlaced */
  1256. int audio_latency[2];
  1257. int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
  1258. unsigned bad_edid_counter;
  1259. /* Flag for raw EDID header corruption - used in Displayport
  1260. * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
  1261. */
  1262. bool edid_corrupt;
  1263. struct dentry *debugfs_entry;
  1264. struct drm_connector_state *state;
  1265. /* DisplayID bits */
  1266. bool has_tile;
  1267. struct drm_tile_group *tile_group;
  1268. bool tile_is_single_monitor;
  1269. uint8_t num_h_tile, num_v_tile;
  1270. uint8_t tile_h_loc, tile_v_loc;
  1271. uint16_t tile_h_size, tile_v_size;
  1272. };
  1273. /**
  1274. * struct drm_plane_state - mutable plane state
  1275. * @plane: backpointer to the plane
  1276. * @crtc: currently bound CRTC, NULL if disabled
  1277. * @fb: currently bound framebuffer
  1278. * @fence: optional fence to wait for before scanning out @fb
  1279. * @crtc_x: left position of visible portion of plane on crtc
  1280. * @crtc_y: upper position of visible portion of plane on crtc
  1281. * @crtc_w: width of visible portion of plane on crtc
  1282. * @crtc_h: height of visible portion of plane on crtc
  1283. * @src_x: left position of visible portion of plane within
  1284. * plane (in 16.16)
  1285. * @src_y: upper position of visible portion of plane within
  1286. * plane (in 16.16)
  1287. * @src_w: width of visible portion of plane (in 16.16)
  1288. * @src_h: height of visible portion of plane (in 16.16)
  1289. * @rotation: rotation of the plane
  1290. * @zpos: priority of the given plane on crtc (optional)
  1291. * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
  1292. * where N is the number of active planes for given crtc
  1293. * @state: backpointer to global drm_atomic_state
  1294. */
  1295. struct drm_plane_state {
  1296. struct drm_plane *plane;
  1297. struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
  1298. struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
  1299. struct fence *fence;
  1300. /* Signed dest location allows it to be partially off screen */
  1301. int32_t crtc_x, crtc_y;
  1302. uint32_t crtc_w, crtc_h;
  1303. /* Source values are 16.16 fixed point */
  1304. uint32_t src_x, src_y;
  1305. uint32_t src_h, src_w;
  1306. /* Plane rotation */
  1307. unsigned int rotation;
  1308. /* Plane zpos */
  1309. unsigned int zpos;
  1310. unsigned int normalized_zpos;
  1311. struct drm_atomic_state *state;
  1312. };
  1313. /**
  1314. * struct drm_plane_funcs - driver plane control functions
  1315. */
  1316. struct drm_plane_funcs {
  1317. /**
  1318. * @update_plane:
  1319. *
  1320. * This is the legacy entry point to enable and configure the plane for
  1321. * the given CRTC and framebuffer. It is never called to disable the
  1322. * plane, i.e. the passed-in crtc and fb paramters are never NULL.
  1323. *
  1324. * The source rectangle in frame buffer memory coordinates is given by
  1325. * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
  1326. * values). Devices that don't support subpixel plane coordinates can
  1327. * ignore the fractional part.
  1328. *
  1329. * The destination rectangle in CRTC coordinates is given by the
  1330. * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
  1331. * Devices scale the source rectangle to the destination rectangle. If
  1332. * scaling is not supported, and the source rectangle size doesn't match
  1333. * the destination rectangle size, the driver must return a
  1334. * -<errorname>EINVAL</errorname> error.
  1335. *
  1336. * Drivers implementing atomic modeset should use
  1337. * drm_atomic_helper_update_plane() to implement this hook.
  1338. *
  1339. * RETURNS:
  1340. *
  1341. * 0 on success or a negative error code on failure.
  1342. */
  1343. int (*update_plane)(struct drm_plane *plane,
  1344. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1345. int crtc_x, int crtc_y,
  1346. unsigned int crtc_w, unsigned int crtc_h,
  1347. uint32_t src_x, uint32_t src_y,
  1348. uint32_t src_w, uint32_t src_h);
  1349. /**
  1350. * @disable_plane:
  1351. *
  1352. * This is the legacy entry point to disable the plane. The DRM core
  1353. * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
  1354. * with the frame buffer ID set to 0. Disabled planes must not be
  1355. * processed by the CRTC.
  1356. *
  1357. * Drivers implementing atomic modeset should use
  1358. * drm_atomic_helper_disable_plane() to implement this hook.
  1359. *
  1360. * RETURNS:
  1361. *
  1362. * 0 on success or a negative error code on failure.
  1363. */
  1364. int (*disable_plane)(struct drm_plane *plane);
  1365. /**
  1366. * @destroy:
  1367. *
  1368. * Clean up plane resources. This is only called at driver unload time
  1369. * through drm_mode_config_cleanup() since a plane cannot be hotplugged
  1370. * in DRM.
  1371. */
  1372. void (*destroy)(struct drm_plane *plane);
  1373. /**
  1374. * @reset:
  1375. *
  1376. * Reset plane hardware and software state to off. This function isn't
  1377. * called by the core directly, only through drm_mode_config_reset().
  1378. * It's not a helper hook only for historical reasons.
  1379. *
  1380. * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
  1381. * atomic state using this hook.
  1382. */
  1383. void (*reset)(struct drm_plane *plane);
  1384. /**
  1385. * @set_property:
  1386. *
  1387. * This is the legacy entry point to update a property attached to the
  1388. * plane.
  1389. *
  1390. * Drivers implementing atomic modeset should use
  1391. * drm_atomic_helper_plane_set_property() to implement this hook.
  1392. *
  1393. * This callback is optional if the driver does not support any legacy
  1394. * driver-private properties.
  1395. *
  1396. * RETURNS:
  1397. *
  1398. * 0 on success or a negative error code on failure.
  1399. */
  1400. int (*set_property)(struct drm_plane *plane,
  1401. struct drm_property *property, uint64_t val);
  1402. /**
  1403. * @atomic_duplicate_state:
  1404. *
  1405. * Duplicate the current atomic state for this plane and return it.
  1406. * The core and helpers gurantee that any atomic state duplicated with
  1407. * this hook and still owned by the caller (i.e. not transferred to the
  1408. * driver by calling ->atomic_commit() from struct
  1409. * &drm_mode_config_funcs) will be cleaned up by calling the
  1410. * @atomic_destroy_state hook in this structure.
  1411. *
  1412. * Atomic drivers which don't subclass struct &drm_plane_state should use
  1413. * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
  1414. * state structure to extend it with driver-private state should use
  1415. * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
  1416. * duplicated in a consistent fashion across drivers.
  1417. *
  1418. * It is an error to call this hook before plane->state has been
  1419. * initialized correctly.
  1420. *
  1421. * NOTE:
  1422. *
  1423. * If the duplicate state references refcounted resources this hook must
  1424. * acquire a reference for each of them. The driver must release these
  1425. * references again in @atomic_destroy_state.
  1426. *
  1427. * RETURNS:
  1428. *
  1429. * Duplicated atomic state or NULL when the allocation failed.
  1430. */
  1431. struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
  1432. /**
  1433. * @atomic_destroy_state:
  1434. *
  1435. * Destroy a state duplicated with @atomic_duplicate_state and release
  1436. * or unreference all resources it references
  1437. */
  1438. void (*atomic_destroy_state)(struct drm_plane *plane,
  1439. struct drm_plane_state *state);
  1440. /**
  1441. * @atomic_set_property:
  1442. *
  1443. * Decode a driver-private property value and store the decoded value
  1444. * into the passed-in state structure. Since the atomic core decodes all
  1445. * standardized properties (even for extensions beyond the core set of
  1446. * properties which might not be implemented by all drivers) this
  1447. * requires drivers to subclass the state structure.
  1448. *
  1449. * Such driver-private properties should really only be implemented for
  1450. * truly hardware/vendor specific state. Instead it is preferred to
  1451. * standardize atomic extension and decode the properties used to expose
  1452. * such an extension in the core.
  1453. *
  1454. * Do not call this function directly, use
  1455. * drm_atomic_plane_set_property() instead.
  1456. *
  1457. * This callback is optional if the driver does not support any
  1458. * driver-private atomic properties.
  1459. *
  1460. * NOTE:
  1461. *
  1462. * This function is called in the state assembly phase of atomic
  1463. * modesets, which can be aborted for any reason (including on
  1464. * userspace's request to just check whether a configuration would be
  1465. * possible). Drivers MUST NOT touch any persistent state (hardware or
  1466. * software) or data structures except the passed in @state parameter.
  1467. *
  1468. * Also since userspace controls in which order properties are set this
  1469. * function must not do any input validation (since the state update is
  1470. * incomplete and hence likely inconsistent). Instead any such input
  1471. * validation must be done in the various atomic_check callbacks.
  1472. *
  1473. * RETURNS:
  1474. *
  1475. * 0 if the property has been found, -EINVAL if the property isn't
  1476. * implemented by the driver (which shouldn't ever happen, the core only
  1477. * asks for properties attached to this plane). No other validation is
  1478. * allowed by the driver. The core already checks that the property
  1479. * value is within the range (integer, valid enum value, ...) the driver
  1480. * set when registering the property.
  1481. */
  1482. int (*atomic_set_property)(struct drm_plane *plane,
  1483. struct drm_plane_state *state,
  1484. struct drm_property *property,
  1485. uint64_t val);
  1486. /**
  1487. * @atomic_get_property:
  1488. *
  1489. * Reads out the decoded driver-private property. This is used to
  1490. * implement the GETPLANE IOCTL.
  1491. *
  1492. * Do not call this function directly, use
  1493. * drm_atomic_plane_get_property() instead.
  1494. *
  1495. * This callback is optional if the driver does not support any
  1496. * driver-private atomic properties.
  1497. *
  1498. * RETURNS:
  1499. *
  1500. * 0 on success, -EINVAL if the property isn't implemented by the
  1501. * driver (which should never happen, the core only asks for
  1502. * properties attached to this plane).
  1503. */
  1504. int (*atomic_get_property)(struct drm_plane *plane,
  1505. const struct drm_plane_state *state,
  1506. struct drm_property *property,
  1507. uint64_t *val);
  1508. /**
  1509. * @late_register:
  1510. *
  1511. * This optional hook can be used to register additional userspace
  1512. * interfaces attached to the plane like debugfs interfaces.
  1513. * It is called late in the driver load sequence from drm_dev_register().
  1514. * Everything added from this callback should be unregistered in
  1515. * the early_unregister callback.
  1516. *
  1517. * Returns:
  1518. *
  1519. * 0 on success, or a negative error code on failure.
  1520. */
  1521. int (*late_register)(struct drm_plane *plane);
  1522. /**
  1523. * @early_unregister:
  1524. *
  1525. * This optional hook should be used to unregister the additional
  1526. * userspace interfaces attached to the plane from
  1527. * late_unregister(). It is called from drm_dev_unregister(),
  1528. * early in the driver unload sequence to disable userspace access
  1529. * before data structures are torndown.
  1530. */
  1531. void (*early_unregister)(struct drm_plane *plane);
  1532. };
  1533. enum drm_plane_type {
  1534. DRM_PLANE_TYPE_OVERLAY,
  1535. DRM_PLANE_TYPE_PRIMARY,
  1536. DRM_PLANE_TYPE_CURSOR,
  1537. };
  1538. /**
  1539. * struct drm_plane - central DRM plane control structure
  1540. * @dev: DRM device this plane belongs to
  1541. * @head: for list management
  1542. * @name: human readable name, can be overwritten by the driver
  1543. * @base: base mode object
  1544. * @possible_crtcs: pipes this plane can be bound to
  1545. * @format_types: array of formats supported by this plane
  1546. * @format_count: number of formats supported
  1547. * @format_default: driver hasn't supplied supported formats for the plane
  1548. * @crtc: currently bound CRTC
  1549. * @fb: currently bound fb
  1550. * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
  1551. * drm_mode_set_config_internal() to implement correct refcounting.
  1552. * @funcs: helper functions
  1553. * @properties: property tracking for this plane
  1554. * @type: type of plane (overlay, primary, cursor)
  1555. * @state: current atomic state for this plane
  1556. * @zpos_property: zpos property for this plane
  1557. * @helper_private: mid-layer private data
  1558. */
  1559. struct drm_plane {
  1560. struct drm_device *dev;
  1561. struct list_head head;
  1562. char *name;
  1563. /**
  1564. * @mutex:
  1565. *
  1566. * Protects modeset plane state, together with the mutex of &drm_crtc
  1567. * this plane is linked to (when active, getting actived or getting
  1568. * disabled).
  1569. */
  1570. struct drm_modeset_lock mutex;
  1571. struct drm_mode_object base;
  1572. uint32_t possible_crtcs;
  1573. uint32_t *format_types;
  1574. unsigned int format_count;
  1575. bool format_default;
  1576. struct drm_crtc *crtc;
  1577. struct drm_framebuffer *fb;
  1578. struct drm_framebuffer *old_fb;
  1579. const struct drm_plane_funcs *funcs;
  1580. struct drm_object_properties properties;
  1581. enum drm_plane_type type;
  1582. /**
  1583. * @index: Position inside the mode_config.list, can be used as an array
  1584. * index. It is invariant over the lifetime of the plane.
  1585. */
  1586. unsigned index;
  1587. const struct drm_plane_helper_funcs *helper_private;
  1588. struct drm_plane_state *state;
  1589. struct drm_property *zpos_property;
  1590. };
  1591. /**
  1592. * struct drm_bridge_funcs - drm_bridge control functions
  1593. * @attach: Called during drm_bridge_attach
  1594. */
  1595. struct drm_bridge_funcs {
  1596. int (*attach)(struct drm_bridge *bridge);
  1597. /**
  1598. * @mode_fixup:
  1599. *
  1600. * This callback is used to validate and adjust a mode. The paramater
  1601. * mode is the display mode that should be fed to the next element in
  1602. * the display chain, either the final &drm_connector or the next
  1603. * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
  1604. * requires. It can be modified by this callback and does not need to
  1605. * match mode.
  1606. *
  1607. * This is the only hook that allows a bridge to reject a modeset. If
  1608. * this function passes all other callbacks must succeed for this
  1609. * configuration.
  1610. *
  1611. * NOTE:
  1612. *
  1613. * This function is called in the check phase of atomic modesets, which
  1614. * can be aborted for any reason (including on userspace's request to
  1615. * just check whether a configuration would be possible). Drivers MUST
  1616. * NOT touch any persistent state (hardware or software) or data
  1617. * structures except the passed in @state parameter.
  1618. *
  1619. * RETURNS:
  1620. *
  1621. * True if an acceptable configuration is possible, false if the modeset
  1622. * operation should be rejected.
  1623. */
  1624. bool (*mode_fixup)(struct drm_bridge *bridge,
  1625. const struct drm_display_mode *mode,
  1626. struct drm_display_mode *adjusted_mode);
  1627. /**
  1628. * @disable:
  1629. *
  1630. * This callback should disable the bridge. It is called right before
  1631. * the preceding element in the display pipe is disabled. If the
  1632. * preceding element is a bridge this means it's called before that
  1633. * bridge's ->disable() function. If the preceding element is a
  1634. * &drm_encoder it's called right before the encoder's ->disable(),
  1635. * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  1636. *
  1637. * The bridge can assume that the display pipe (i.e. clocks and timing
  1638. * signals) feeding it is still running when this callback is called.
  1639. *
  1640. * The disable callback is optional.
  1641. */
  1642. void (*disable)(struct drm_bridge *bridge);
  1643. /**
  1644. * @post_disable:
  1645. *
  1646. * This callback should disable the bridge. It is called right after
  1647. * the preceding element in the display pipe is disabled. If the
  1648. * preceding element is a bridge this means it's called after that
  1649. * bridge's ->post_disable() function. If the preceding element is a
  1650. * &drm_encoder it's called right after the encoder's ->disable(),
  1651. * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  1652. *
  1653. * The bridge must assume that the display pipe (i.e. clocks and timing
  1654. * singals) feeding it is no longer running when this callback is
  1655. * called.
  1656. *
  1657. * The post_disable callback is optional.
  1658. */
  1659. void (*post_disable)(struct drm_bridge *bridge);
  1660. /**
  1661. * @mode_set:
  1662. *
  1663. * This callback should set the given mode on the bridge. It is called
  1664. * after the ->mode_set() callback for the preceding element in the
  1665. * display pipeline has been called already. The display pipe (i.e.
  1666. * clocks and timing signals) is off when this function is called.
  1667. */
  1668. void (*mode_set)(struct drm_bridge *bridge,
  1669. struct drm_display_mode *mode,
  1670. struct drm_display_mode *adjusted_mode);
  1671. /**
  1672. * @pre_enable:
  1673. *
  1674. * This callback should enable the bridge. It is called right before
  1675. * the preceding element in the display pipe is enabled. If the
  1676. * preceding element is a bridge this means it's called before that
  1677. * bridge's ->pre_enable() function. If the preceding element is a
  1678. * &drm_encoder it's called right before the encoder's ->enable(),
  1679. * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  1680. *
  1681. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  1682. * will not yet be running when this callback is called. The bridge must
  1683. * not enable the display link feeding the next bridge in the chain (if
  1684. * there is one) when this callback is called.
  1685. *
  1686. * The pre_enable callback is optional.
  1687. */
  1688. void (*pre_enable)(struct drm_bridge *bridge);
  1689. /**
  1690. * @enable:
  1691. *
  1692. * This callback should enable the bridge. It is called right after
  1693. * the preceding element in the display pipe is enabled. If the
  1694. * preceding element is a bridge this means it's called after that
  1695. * bridge's ->enable() function. If the preceding element is a
  1696. * &drm_encoder it's called right after the encoder's ->enable(),
  1697. * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  1698. *
  1699. * The bridge can assume that the display pipe (i.e. clocks and timing
  1700. * signals) feeding it is running when this callback is called. This
  1701. * callback must enable the display link feeding the next bridge in the
  1702. * chain if there is one.
  1703. *
  1704. * The enable callback is optional.
  1705. */
  1706. void (*enable)(struct drm_bridge *bridge);
  1707. };
  1708. /**
  1709. * struct drm_bridge - central DRM bridge control structure
  1710. * @dev: DRM device this bridge belongs to
  1711. * @encoder: encoder to which this bridge is connected
  1712. * @next: the next bridge in the encoder chain
  1713. * @of_node: device node pointer to the bridge
  1714. * @list: to keep track of all added bridges
  1715. * @funcs: control functions
  1716. * @driver_private: pointer to the bridge driver's internal context
  1717. */
  1718. struct drm_bridge {
  1719. struct drm_device *dev;
  1720. struct drm_encoder *encoder;
  1721. struct drm_bridge *next;
  1722. #ifdef CONFIG_OF
  1723. struct device_node *of_node;
  1724. #endif
  1725. struct list_head list;
  1726. const struct drm_bridge_funcs *funcs;
  1727. void *driver_private;
  1728. };
  1729. /**
  1730. * struct drm_crtc_commit - track modeset commits on a CRTC
  1731. *
  1732. * This structure is used to track pending modeset changes and atomic commit on
  1733. * a per-CRTC basis. Since updating the list should never block this structure
  1734. * is reference counted to allow waiters to safely wait on an event to complete,
  1735. * without holding any locks.
  1736. *
  1737. * It has 3 different events in total to allow a fine-grained synchronization
  1738. * between outstanding updates::
  1739. *
  1740. * atomic commit thread hardware
  1741. *
  1742. * write new state into hardware ----> ...
  1743. * signal hw_done
  1744. * switch to new state on next
  1745. * ... v/hblank
  1746. *
  1747. * wait for buffers to show up ...
  1748. *
  1749. * ... send completion irq
  1750. * irq handler signals flip_done
  1751. * cleanup old buffers
  1752. *
  1753. * signal cleanup_done
  1754. *
  1755. * wait for flip_done <----
  1756. * clean up atomic state
  1757. *
  1758. * The important bit to know is that cleanup_done is the terminal event, but the
  1759. * ordering between flip_done and hw_done is entirely up to the specific driver
  1760. * and modeset state change.
  1761. *
  1762. * For an implementation of how to use this look at
  1763. * drm_atomic_helper_setup_commit() from the atomic helper library.
  1764. */
  1765. struct drm_crtc_commit {
  1766. /**
  1767. * @crtc:
  1768. *
  1769. * DRM CRTC for this commit.
  1770. */
  1771. struct drm_crtc *crtc;
  1772. /**
  1773. * @ref:
  1774. *
  1775. * Reference count for this structure. Needed to allow blocking on
  1776. * completions without the risk of the completion disappearing
  1777. * meanwhile.
  1778. */
  1779. struct kref ref;
  1780. /**
  1781. * @flip_done:
  1782. *
  1783. * Will be signaled when the hardware has flipped to the new set of
  1784. * buffers. Signals at the same time as when the drm event for this
  1785. * commit is sent to userspace, or when an out-fence is singalled. Note
  1786. * that for most hardware, in most cases this happens after @hw_done is
  1787. * signalled.
  1788. */
  1789. struct completion flip_done;
  1790. /**
  1791. * @hw_done:
  1792. *
  1793. * Will be signalled when all hw register changes for this commit have
  1794. * been written out. Especially when disabling a pipe this can be much
  1795. * later than than @flip_done, since that can signal already when the
  1796. * screen goes black, whereas to fully shut down a pipe more register
  1797. * I/O is required.
  1798. *
  1799. * Note that this does not need to include separately reference-counted
  1800. * resources like backing storage buffer pinning, or runtime pm
  1801. * management.
  1802. */
  1803. struct completion hw_done;
  1804. /**
  1805. * @cleanup_done:
  1806. *
  1807. * Will be signalled after old buffers have been cleaned up by calling
  1808. * drm_atomic_helper_cleanup_planes(). Since this can only happen after
  1809. * a vblank wait completed it might be a bit later. This completion is
  1810. * useful to throttle updates and avoid hardware updates getting ahead
  1811. * of the buffer cleanup too much.
  1812. */
  1813. struct completion cleanup_done;
  1814. /**
  1815. * @commit_entry:
  1816. *
  1817. * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
  1818. */
  1819. struct list_head commit_entry;
  1820. /**
  1821. * @event:
  1822. *
  1823. * &drm_pending_vblank_event pointer to clean up private events.
  1824. */
  1825. struct drm_pending_vblank_event *event;
  1826. };
  1827. struct __drm_planes_state {
  1828. struct drm_plane *ptr;
  1829. struct drm_plane_state *state;
  1830. };
  1831. struct __drm_crtcs_state {
  1832. struct drm_crtc *ptr;
  1833. struct drm_crtc_state *state;
  1834. struct drm_crtc_commit *commit;
  1835. };
  1836. struct __drm_connnectors_state {
  1837. struct drm_connector *ptr;
  1838. struct drm_connector_state *state;
  1839. };
  1840. /**
  1841. * struct drm_atomic_state - the global state object for atomic updates
  1842. * @dev: parent DRM device
  1843. * @allow_modeset: allow full modeset
  1844. * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
  1845. * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
  1846. * @planes: pointer to array of structures with per-plane data
  1847. * @crtcs: pointer to array of CRTC pointers
  1848. * @num_connector: size of the @connectors and @connector_states arrays
  1849. * @connectors: pointer to array of structures with per-connector data
  1850. * @acquire_ctx: acquire context for this atomic modeset state update
  1851. */
  1852. struct drm_atomic_state {
  1853. struct drm_device *dev;
  1854. bool allow_modeset : 1;
  1855. bool legacy_cursor_update : 1;
  1856. bool legacy_set_config : 1;
  1857. struct __drm_planes_state *planes;
  1858. struct __drm_crtcs_state *crtcs;
  1859. int num_connector;
  1860. struct __drm_connnectors_state *connectors;
  1861. struct drm_modeset_acquire_ctx *acquire_ctx;
  1862. /**
  1863. * @commit_work:
  1864. *
  1865. * Work item which can be used by the driver or helpers to execute the
  1866. * commit without blocking.
  1867. */
  1868. struct work_struct commit_work;
  1869. };
  1870. /**
  1871. * struct drm_mode_set - new values for a CRTC config change
  1872. * @fb: framebuffer to use for new config
  1873. * @crtc: CRTC whose configuration we're about to change
  1874. * @mode: mode timings to use
  1875. * @x: position of this CRTC relative to @fb
  1876. * @y: position of this CRTC relative to @fb
  1877. * @connectors: array of connectors to drive with this CRTC if possible
  1878. * @num_connectors: size of @connectors array
  1879. *
  1880. * Represents a single crtc the connectors that it drives with what mode
  1881. * and from which framebuffer it scans out from.
  1882. *
  1883. * This is used to set modes.
  1884. */
  1885. struct drm_mode_set {
  1886. struct drm_framebuffer *fb;
  1887. struct drm_crtc *crtc;
  1888. struct drm_display_mode *mode;
  1889. uint32_t x;
  1890. uint32_t y;
  1891. struct drm_connector **connectors;
  1892. size_t num_connectors;
  1893. };
  1894. /**
  1895. * struct drm_mode_config_funcs - basic driver provided mode setting functions
  1896. *
  1897. * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
  1898. * involve drivers.
  1899. */
  1900. struct drm_mode_config_funcs {
  1901. /**
  1902. * @fb_create:
  1903. *
  1904. * Create a new framebuffer object. The core does basic checks on the
  1905. * requested metadata, but most of that is left to the driver. See
  1906. * struct &drm_mode_fb_cmd2 for details.
  1907. *
  1908. * If the parameters are deemed valid and the backing storage objects in
  1909. * the underlying memory manager all exist, then the driver allocates
  1910. * a new &drm_framebuffer structure, subclassed to contain
  1911. * driver-specific information (like the internal native buffer object
  1912. * references). It also needs to fill out all relevant metadata, which
  1913. * should be done by calling drm_helper_mode_fill_fb_struct().
  1914. *
  1915. * The initialization is finalized by calling drm_framebuffer_init(),
  1916. * which registers the framebuffer and makes it accessible to other
  1917. * threads.
  1918. *
  1919. * RETURNS:
  1920. *
  1921. * A new framebuffer with an initial reference count of 1 or a negative
  1922. * error code encoded with ERR_PTR().
  1923. */
  1924. struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
  1925. struct drm_file *file_priv,
  1926. const struct drm_mode_fb_cmd2 *mode_cmd);
  1927. /**
  1928. * @output_poll_changed:
  1929. *
  1930. * Callback used by helpers to inform the driver of output configuration
  1931. * changes.
  1932. *
  1933. * Drivers implementing fbdev emulation with the helpers can call
  1934. * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
  1935. * helper of output changes.
  1936. *
  1937. * FIXME:
  1938. *
  1939. * Except that there's no vtable for device-level helper callbacks
  1940. * there's no reason this is a core function.
  1941. */
  1942. void (*output_poll_changed)(struct drm_device *dev);
  1943. /**
  1944. * @atomic_check:
  1945. *
  1946. * This is the only hook to validate an atomic modeset update. This
  1947. * function must reject any modeset and state changes which the hardware
  1948. * or driver doesn't support. This includes but is of course not limited
  1949. * to:
  1950. *
  1951. * - Checking that the modes, framebuffers, scaling and placement
  1952. * requirements and so on are within the limits of the hardware.
  1953. *
  1954. * - Checking that any hidden shared resources are not oversubscribed.
  1955. * This can be shared PLLs, shared lanes, overall memory bandwidth,
  1956. * display fifo space (where shared between planes or maybe even
  1957. * CRTCs).
  1958. *
  1959. * - Checking that virtualized resources exported to userspace are not
  1960. * oversubscribed. For various reasons it can make sense to expose
  1961. * more planes, crtcs or encoders than which are physically there. One
  1962. * example is dual-pipe operations (which generally should be hidden
  1963. * from userspace if when lockstepped in hardware, exposed otherwise),
  1964. * where a plane might need 1 hardware plane (if it's just on one
  1965. * pipe), 2 hardware planes (when it spans both pipes) or maybe even
  1966. * shared a hardware plane with a 2nd plane (if there's a compatible
  1967. * plane requested on the area handled by the other pipe).
  1968. *
  1969. * - Check that any transitional state is possible and that if
  1970. * requested, the update can indeed be done in the vblank period
  1971. * without temporarily disabling some functions.
  1972. *
  1973. * - Check any other constraints the driver or hardware might have.
  1974. *
  1975. * - This callback also needs to correctly fill out the &drm_crtc_state
  1976. * in this update to make sure that drm_atomic_crtc_needs_modeset()
  1977. * reflects the nature of the possible update and returns true if and
  1978. * only if the update cannot be applied without tearing within one
  1979. * vblank on that CRTC. The core uses that information to reject
  1980. * updates which require a full modeset (i.e. blanking the screen, or
  1981. * at least pausing updates for a substantial amount of time) if
  1982. * userspace has disallowed that in its request.
  1983. *
  1984. * - The driver also does not need to repeat basic input validation
  1985. * like done for the corresponding legacy entry points. The core does
  1986. * that before calling this hook.
  1987. *
  1988. * See the documentation of @atomic_commit for an exhaustive list of
  1989. * error conditions which don't have to be checked at the
  1990. * ->atomic_check() stage?
  1991. *
  1992. * See the documentation for struct &drm_atomic_state for how exactly
  1993. * an atomic modeset update is described.
  1994. *
  1995. * Drivers using the atomic helpers can implement this hook using
  1996. * drm_atomic_helper_check(), or one of the exported sub-functions of
  1997. * it.
  1998. *
  1999. * RETURNS:
  2000. *
  2001. * 0 on success or one of the below negative error codes:
  2002. *
  2003. * - -EINVAL, if any of the above constraints are violated.
  2004. *
  2005. * - -EDEADLK, when returned from an attempt to acquire an additional
  2006. * &drm_modeset_lock through drm_modeset_lock().
  2007. *
  2008. * - -ENOMEM, if allocating additional state sub-structures failed due
  2009. * to lack of memory.
  2010. *
  2011. * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
  2012. * This can either be due to a pending signal, or because the driver
  2013. * needs to completely bail out to recover from an exceptional
  2014. * situation like a GPU hang. From a userspace point all errors are
  2015. * treated equally.
  2016. */
  2017. int (*atomic_check)(struct drm_device *dev,
  2018. struct drm_atomic_state *state);
  2019. /**
  2020. * @atomic_commit:
  2021. *
  2022. * This is the only hook to commit an atomic modeset update. The core
  2023. * guarantees that @atomic_check has been called successfully before
  2024. * calling this function, and that nothing has been changed in the
  2025. * interim.
  2026. *
  2027. * See the documentation for struct &drm_atomic_state for how exactly
  2028. * an atomic modeset update is described.
  2029. *
  2030. * Drivers using the atomic helpers can implement this hook using
  2031. * drm_atomic_helper_commit(), or one of the exported sub-functions of
  2032. * it.
  2033. *
  2034. * Nonblocking commits (as indicated with the nonblock parameter) must
  2035. * do any preparatory work which might result in an unsuccessful commit
  2036. * in the context of this callback. The only exceptions are hardware
  2037. * errors resulting in -EIO. But even in that case the driver must
  2038. * ensure that the display pipe is at least running, to avoid
  2039. * compositors crashing when pageflips don't work. Anything else,
  2040. * specifically committing the update to the hardware, should be done
  2041. * without blocking the caller. For updates which do not require a
  2042. * modeset this must be guaranteed.
  2043. *
  2044. * The driver must wait for any pending rendering to the new
  2045. * framebuffers to complete before executing the flip. It should also
  2046. * wait for any pending rendering from other drivers if the underlying
  2047. * buffer is a shared dma-buf. Nonblocking commits must not wait for
  2048. * rendering in the context of this callback.
  2049. *
  2050. * An application can request to be notified when the atomic commit has
  2051. * completed. These events are per-CRTC and can be distinguished by the
  2052. * CRTC index supplied in &drm_event to userspace.
  2053. *
  2054. * The drm core will supply a struct &drm_event in the event
  2055. * member of each CRTC's &drm_crtc_state structure. This can be handled by the
  2056. * drm_crtc_send_vblank_event() function, which the driver should call on
  2057. * the provided event upon completion of the atomic commit. Note that if
  2058. * the driver supports vblank signalling and timestamping the vblank
  2059. * counters and timestamps must agree with the ones returned from page
  2060. * flip events. With the current vblank helper infrastructure this can
  2061. * be achieved by holding a vblank reference while the page flip is
  2062. * pending, acquired through drm_crtc_vblank_get() and released with
  2063. * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
  2064. * counter and timestamp tracking though, e.g. if they have accurate
  2065. * timestamp registers in hardware.
  2066. *
  2067. * NOTE:
  2068. *
  2069. * Drivers are not allowed to shut down any display pipe successfully
  2070. * enabled through an atomic commit on their own. Doing so can result in
  2071. * compositors crashing if a page flip is suddenly rejected because the
  2072. * pipe is off.
  2073. *
  2074. * RETURNS:
  2075. *
  2076. * 0 on success or one of the below negative error codes:
  2077. *
  2078. * - -EBUSY, if a nonblocking updated is requested and there is
  2079. * an earlier updated pending. Drivers are allowed to support a queue
  2080. * of outstanding updates, but currently no driver supports that.
  2081. * Note that drivers must wait for preceding updates to complete if a
  2082. * synchronous update is requested, they are not allowed to fail the
  2083. * commit in that case.
  2084. *
  2085. * - -ENOMEM, if the driver failed to allocate memory. Specifically
  2086. * this can happen when trying to pin framebuffers, which must only
  2087. * be done when committing the state.
  2088. *
  2089. * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
  2090. * that the driver has run out of vram, iommu space or similar GPU
  2091. * address space needed for framebuffer.
  2092. *
  2093. * - -EIO, if the hardware completely died.
  2094. *
  2095. * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
  2096. * This can either be due to a pending signal, or because the driver
  2097. * needs to completely bail out to recover from an exceptional
  2098. * situation like a GPU hang. From a userspace point of view all errors are
  2099. * treated equally.
  2100. *
  2101. * This list is exhaustive. Specifically this hook is not allowed to
  2102. * return -EINVAL (any invalid requests should be caught in
  2103. * @atomic_check) or -EDEADLK (this function must not acquire
  2104. * additional modeset locks).
  2105. */
  2106. int (*atomic_commit)(struct drm_device *dev,
  2107. struct drm_atomic_state *state,
  2108. bool nonblock);
  2109. /**
  2110. * @atomic_state_alloc:
  2111. *
  2112. * This optional hook can be used by drivers that want to subclass struct
  2113. * &drm_atomic_state to be able to track their own driver-private global
  2114. * state easily. If this hook is implemented, drivers must also
  2115. * implement @atomic_state_clear and @atomic_state_free.
  2116. *
  2117. * RETURNS:
  2118. *
  2119. * A new &drm_atomic_state on success or NULL on failure.
  2120. */
  2121. struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
  2122. /**
  2123. * @atomic_state_clear:
  2124. *
  2125. * This hook must clear any driver private state duplicated into the
  2126. * passed-in &drm_atomic_state. This hook is called when the caller
  2127. * encountered a &drm_modeset_lock deadlock and needs to drop all
  2128. * already acquired locks as part of the deadlock avoidance dance
  2129. * implemented in drm_modeset_lock_backoff().
  2130. *
  2131. * Any duplicated state must be invalidated since a concurrent atomic
  2132. * update might change it, and the drm atomic interfaces always apply
  2133. * updates as relative changes to the current state.
  2134. *
  2135. * Drivers that implement this must call drm_atomic_state_default_clear()
  2136. * to clear common state.
  2137. */
  2138. void (*atomic_state_clear)(struct drm_atomic_state *state);
  2139. /**
  2140. * @atomic_state_free:
  2141. *
  2142. * This hook needs driver private resources and the &drm_atomic_state
  2143. * itself. Note that the core first calls drm_atomic_state_clear() to
  2144. * avoid code duplicate between the clear and free hooks.
  2145. *
  2146. * Drivers that implement this must call drm_atomic_state_default_free()
  2147. * to release common resources.
  2148. */
  2149. void (*atomic_state_free)(struct drm_atomic_state *state);
  2150. };
  2151. /**
  2152. * struct drm_mode_config - Mode configuration control structure
  2153. * @mutex: mutex protecting KMS related lists and structures
  2154. * @connection_mutex: ww mutex protecting connector state and routing
  2155. * @acquire_ctx: global implicit acquire context used by atomic drivers for
  2156. * legacy IOCTLs
  2157. * @fb_lock: mutex to protect fb state and lists
  2158. * @num_fb: number of fbs available
  2159. * @fb_list: list of framebuffers available
  2160. * @num_encoder: number of encoders on this device
  2161. * @encoder_list: list of encoder objects
  2162. * @num_overlay_plane: number of overlay planes on this device
  2163. * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
  2164. * @plane_list: list of plane objects
  2165. * @num_crtc: number of CRTCs on this device
  2166. * @crtc_list: list of CRTC objects
  2167. * @property_list: list of property objects
  2168. * @min_width: minimum pixel width on this device
  2169. * @min_height: minimum pixel height on this device
  2170. * @max_width: maximum pixel width on this device
  2171. * @max_height: maximum pixel height on this device
  2172. * @funcs: core driver provided mode setting functions
  2173. * @fb_base: base address of the framebuffer
  2174. * @poll_enabled: track polling support for this device
  2175. * @poll_running: track polling status for this device
  2176. * @delayed_event: track delayed poll uevent deliver for this device
  2177. * @output_poll_work: delayed work for polling in process context
  2178. * @property_blob_list: list of all the blob property objects
  2179. * @blob_lock: mutex for blob property allocation and management
  2180. * @*_property: core property tracking
  2181. * @preferred_depth: preferred RBG pixel depth, used by fb helpers
  2182. * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
  2183. * @cursor_width: hint to userspace for max cursor width
  2184. * @cursor_height: hint to userspace for max cursor height
  2185. * @helper_private: mid-layer private data
  2186. *
  2187. * Core mode resource tracking structure. All CRTC, encoders, and connectors
  2188. * enumerated by the driver are added here, as are global properties. Some
  2189. * global restrictions are also here, e.g. dimension restrictions.
  2190. */
  2191. struct drm_mode_config {
  2192. struct mutex mutex; /* protects configuration (mode lists etc.) */
  2193. struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
  2194. struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
  2195. /**
  2196. * @idr_mutex:
  2197. *
  2198. * Mutex for KMS ID allocation and management. Protects both @crtc_idr
  2199. * and @tile_idr.
  2200. */
  2201. struct mutex idr_mutex;
  2202. /**
  2203. * @crtc_idr:
  2204. *
  2205. * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
  2206. * connector, modes - just makes life easier to have only one.
  2207. */
  2208. struct idr crtc_idr;
  2209. /**
  2210. * @tile_idr:
  2211. *
  2212. * Use this idr for allocating new IDs for tiled sinks like use in some
  2213. * high-res DP MST screens.
  2214. */
  2215. struct idr tile_idr;
  2216. struct mutex fb_lock; /* proctects global and per-file fb lists */
  2217. int num_fb;
  2218. struct list_head fb_list;
  2219. /**
  2220. * @num_connector: Number of connectors on this device.
  2221. */
  2222. int num_connector;
  2223. /**
  2224. * @connector_ida: ID allocator for connector indices.
  2225. */
  2226. struct ida connector_ida;
  2227. /**
  2228. * @connector_list: List of connector objects.
  2229. */
  2230. struct list_head connector_list;
  2231. int num_encoder;
  2232. struct list_head encoder_list;
  2233. /*
  2234. * Track # of overlay planes separately from # of total planes. By
  2235. * default we only advertise overlay planes to userspace; if userspace
  2236. * sets the "universal plane" capability bit, we'll go ahead and
  2237. * expose all planes.
  2238. */
  2239. int num_overlay_plane;
  2240. int num_total_plane;
  2241. struct list_head plane_list;
  2242. int num_crtc;
  2243. struct list_head crtc_list;
  2244. struct list_head property_list;
  2245. int min_width, min_height;
  2246. int max_width, max_height;
  2247. const struct drm_mode_config_funcs *funcs;
  2248. resource_size_t fb_base;
  2249. /* output poll support */
  2250. bool poll_enabled;
  2251. bool poll_running;
  2252. bool delayed_event;
  2253. struct delayed_work output_poll_work;
  2254. struct mutex blob_lock;
  2255. /* pointers to standard properties */
  2256. struct list_head property_blob_list;
  2257. /**
  2258. * @edid_property: Default connector property to hold the EDID of the
  2259. * currently connected sink, if any.
  2260. */
  2261. struct drm_property *edid_property;
  2262. /**
  2263. * @dpms_property: Default connector property to control the
  2264. * connector's DPMS state.
  2265. */
  2266. struct drm_property *dpms_property;
  2267. /**
  2268. * @path_property: Default connector property to hold the DP MST path
  2269. * for the port.
  2270. */
  2271. struct drm_property *path_property;
  2272. /**
  2273. * @tile_property: Default connector property to store the tile
  2274. * position of a tiled screen, for sinks which need to be driven with
  2275. * multiple CRTCs.
  2276. */
  2277. struct drm_property *tile_property;
  2278. /**
  2279. * @plane_type_property: Default plane property to differentiate
  2280. * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
  2281. */
  2282. struct drm_property *plane_type_property;
  2283. /**
  2284. * @rotation_property: Optional property for planes or CRTCs to specifiy
  2285. * rotation.
  2286. */
  2287. struct drm_property *rotation_property;
  2288. /**
  2289. * @prop_src_x: Default atomic plane property for the plane source
  2290. * position in the connected &drm_framebuffer.
  2291. */
  2292. struct drm_property *prop_src_x;
  2293. /**
  2294. * @prop_src_y: Default atomic plane property for the plane source
  2295. * position in the connected &drm_framebuffer.
  2296. */
  2297. struct drm_property *prop_src_y;
  2298. /**
  2299. * @prop_src_w: Default atomic plane property for the plane source
  2300. * position in the connected &drm_framebuffer.
  2301. */
  2302. struct drm_property *prop_src_w;
  2303. /**
  2304. * @prop_src_h: Default atomic plane property for the plane source
  2305. * position in the connected &drm_framebuffer.
  2306. */
  2307. struct drm_property *prop_src_h;
  2308. /**
  2309. * @prop_crtc_x: Default atomic plane property for the plane destination
  2310. * position in the &drm_crtc is is being shown on.
  2311. */
  2312. struct drm_property *prop_crtc_x;
  2313. /**
  2314. * @prop_crtc_y: Default atomic plane property for the plane destination
  2315. * position in the &drm_crtc is is being shown on.
  2316. */
  2317. struct drm_property *prop_crtc_y;
  2318. /**
  2319. * @prop_crtc_w: Default atomic plane property for the plane destination
  2320. * position in the &drm_crtc is is being shown on.
  2321. */
  2322. struct drm_property *prop_crtc_w;
  2323. /**
  2324. * @prop_crtc_h: Default atomic plane property for the plane destination
  2325. * position in the &drm_crtc is is being shown on.
  2326. */
  2327. struct drm_property *prop_crtc_h;
  2328. /**
  2329. * @prop_fb_id: Default atomic plane property to specify the
  2330. * &drm_framebuffer.
  2331. */
  2332. struct drm_property *prop_fb_id;
  2333. /**
  2334. * @prop_crtc_id: Default atomic plane property to specify the
  2335. * &drm_crtc.
  2336. */
  2337. struct drm_property *prop_crtc_id;
  2338. /**
  2339. * @prop_active: Default atomic CRTC property to control the active
  2340. * state, which is the simplified implementation for DPMS in atomic
  2341. * drivers.
  2342. */
  2343. struct drm_property *prop_active;
  2344. /**
  2345. * @prop_mode_id: Default atomic CRTC property to set the mode for a
  2346. * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
  2347. * connectors must be of and active must be set to disabled, too.
  2348. */
  2349. struct drm_property *prop_mode_id;
  2350. /**
  2351. * @dvi_i_subconnector_property: Optional DVI-I property to
  2352. * differentiate between analog or digital mode.
  2353. */
  2354. struct drm_property *dvi_i_subconnector_property;
  2355. /**
  2356. * @dvi_i_select_subconnector_property: Optional DVI-I property to
  2357. * select between analog or digital mode.
  2358. */
  2359. struct drm_property *dvi_i_select_subconnector_property;
  2360. /**
  2361. * @tv_subconnector_property: Optional TV property to differentiate
  2362. * between different TV connector types.
  2363. */
  2364. struct drm_property *tv_subconnector_property;
  2365. /**
  2366. * @tv_select_subconnector_property: Optional TV property to select
  2367. * between different TV connector types.
  2368. */
  2369. struct drm_property *tv_select_subconnector_property;
  2370. /**
  2371. * @tv_mode_property: Optional TV property to select
  2372. * the output TV mode.
  2373. */
  2374. struct drm_property *tv_mode_property;
  2375. /**
  2376. * @tv_left_margin_property: Optional TV property to set the left
  2377. * margin.
  2378. */
  2379. struct drm_property *tv_left_margin_property;
  2380. /**
  2381. * @tv_right_margin_property: Optional TV property to set the right
  2382. * margin.
  2383. */
  2384. struct drm_property *tv_right_margin_property;
  2385. /**
  2386. * @tv_top_margin_property: Optional TV property to set the right
  2387. * margin.
  2388. */
  2389. struct drm_property *tv_top_margin_property;
  2390. /**
  2391. * @tv_bottom_margin_property: Optional TV property to set the right
  2392. * margin.
  2393. */
  2394. struct drm_property *tv_bottom_margin_property;
  2395. /**
  2396. * @tv_brightness_property: Optional TV property to set the
  2397. * brightness.
  2398. */
  2399. struct drm_property *tv_brightness_property;
  2400. /**
  2401. * @tv_contrast_property: Optional TV property to set the
  2402. * contrast.
  2403. */
  2404. struct drm_property *tv_contrast_property;
  2405. /**
  2406. * @tv_flicker_reduction_property: Optional TV property to control the
  2407. * flicker reduction mode.
  2408. */
  2409. struct drm_property *tv_flicker_reduction_property;
  2410. /**
  2411. * @tv_overscan_property: Optional TV property to control the overscan
  2412. * setting.
  2413. */
  2414. struct drm_property *tv_overscan_property;
  2415. /**
  2416. * @tv_saturation_property: Optional TV property to set the
  2417. * saturation.
  2418. */
  2419. struct drm_property *tv_saturation_property;
  2420. /**
  2421. * @tv_hue_property: Optional TV property to set the hue.
  2422. */
  2423. struct drm_property *tv_hue_property;
  2424. /**
  2425. * @scaling_mode_property: Optional connector property to control the
  2426. * upscaling, mostly used for built-in panels.
  2427. */
  2428. struct drm_property *scaling_mode_property;
  2429. /**
  2430. * @aspect_ratio_property: Optional connector property to control the
  2431. * HDMI infoframe aspect ratio setting.
  2432. */
  2433. struct drm_property *aspect_ratio_property;
  2434. /**
  2435. * @dirty_info_property: Optional connector property to give userspace a
  2436. * hint that the DIRTY_FB ioctl should be used.
  2437. */
  2438. struct drm_property *dirty_info_property;
  2439. /**
  2440. * @degamma_lut_property: Optional CRTC property to set the LUT used to
  2441. * convert the framebuffer's colors to linear gamma.
  2442. */
  2443. struct drm_property *degamma_lut_property;
  2444. /**
  2445. * @degamma_lut_size_property: Optional CRTC property for the size of
  2446. * the degamma LUT as supported by the driver (read-only).
  2447. */
  2448. struct drm_property *degamma_lut_size_property;
  2449. /**
  2450. * @ctm_property: Optional CRTC property to set the
  2451. * matrix used to convert colors after the lookup in the
  2452. * degamma LUT.
  2453. */
  2454. struct drm_property *ctm_property;
  2455. /**
  2456. * @gamma_lut_property: Optional CRTC property to set the LUT used to
  2457. * convert the colors, after the CTM matrix, to the gamma space of the
  2458. * connected screen.
  2459. */
  2460. struct drm_property *gamma_lut_property;
  2461. /**
  2462. * @gamma_lut_size_property: Optional CRTC property for the size of the
  2463. * gamma LUT as supported by the driver (read-only).
  2464. */
  2465. struct drm_property *gamma_lut_size_property;
  2466. /**
  2467. * @suggested_x_property: Optional connector property with a hint for
  2468. * the position of the output on the host's screen.
  2469. */
  2470. struct drm_property *suggested_x_property;
  2471. /**
  2472. * @suggested_y_property: Optional connector property with a hint for
  2473. * the position of the output on the host's screen.
  2474. */
  2475. struct drm_property *suggested_y_property;
  2476. /* dumb ioctl parameters */
  2477. uint32_t preferred_depth, prefer_shadow;
  2478. /**
  2479. * @async_page_flip: Does this device support async flips on the primary
  2480. * plane?
  2481. */
  2482. bool async_page_flip;
  2483. /**
  2484. * @allow_fb_modifiers:
  2485. *
  2486. * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
  2487. */
  2488. bool allow_fb_modifiers;
  2489. /* cursor size */
  2490. uint32_t cursor_width, cursor_height;
  2491. struct drm_mode_config_helper_funcs *helper_private;
  2492. };
  2493. /**
  2494. * drm_for_each_plane_mask - iterate over planes specified by bitmask
  2495. * @plane: the loop cursor
  2496. * @dev: the DRM device
  2497. * @plane_mask: bitmask of plane indices
  2498. *
  2499. * Iterate over all planes specified by bitmask.
  2500. */
  2501. #define drm_for_each_plane_mask(plane, dev, plane_mask) \
  2502. list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
  2503. for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
  2504. /**
  2505. * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
  2506. * @encoder: the loop cursor
  2507. * @dev: the DRM device
  2508. * @encoder_mask: bitmask of encoder indices
  2509. *
  2510. * Iterate over all encoders specified by bitmask.
  2511. */
  2512. #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
  2513. list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
  2514. for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
  2515. #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
  2516. #define obj_to_connector(x) container_of(x, struct drm_connector, base)
  2517. #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
  2518. #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
  2519. #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
  2520. #define obj_to_property(x) container_of(x, struct drm_property, base)
  2521. #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
  2522. #define obj_to_plane(x) container_of(x, struct drm_plane, base)
  2523. struct drm_prop_enum_list {
  2524. int type;
  2525. char *name;
  2526. };
  2527. extern __printf(6, 7)
  2528. int drm_crtc_init_with_planes(struct drm_device *dev,
  2529. struct drm_crtc *crtc,
  2530. struct drm_plane *primary,
  2531. struct drm_plane *cursor,
  2532. const struct drm_crtc_funcs *funcs,
  2533. const char *name, ...);
  2534. extern void drm_crtc_cleanup(struct drm_crtc *crtc);
  2535. /**
  2536. * drm_crtc_index - find the index of a registered CRTC
  2537. * @crtc: CRTC to find index for
  2538. *
  2539. * Given a registered CRTC, return the index of that CRTC within a DRM
  2540. * device's list of CRTCs.
  2541. */
  2542. static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
  2543. {
  2544. return crtc->index;
  2545. }
  2546. /**
  2547. * drm_crtc_mask - find the mask of a registered CRTC
  2548. * @crtc: CRTC to find mask for
  2549. *
  2550. * Given a registered CRTC, return the mask bit of that CRTC for an
  2551. * encoder's possible_crtcs field.
  2552. */
  2553. static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
  2554. {
  2555. return 1 << drm_crtc_index(crtc);
  2556. }
  2557. int drm_connector_init(struct drm_device *dev,
  2558. struct drm_connector *connector,
  2559. const struct drm_connector_funcs *funcs,
  2560. int connector_type);
  2561. int drm_connector_register(struct drm_connector *connector);
  2562. void drm_connector_unregister(struct drm_connector *connector);
  2563. extern void drm_connector_cleanup(struct drm_connector *connector);
  2564. static inline unsigned drm_connector_index(struct drm_connector *connector)
  2565. {
  2566. return connector->index;
  2567. }
  2568. extern __printf(5, 6)
  2569. int drm_encoder_init(struct drm_device *dev,
  2570. struct drm_encoder *encoder,
  2571. const struct drm_encoder_funcs *funcs,
  2572. int encoder_type, const char *name, ...);
  2573. /**
  2574. * drm_encoder_index - find the index of a registered encoder
  2575. * @encoder: encoder to find index for
  2576. *
  2577. * Given a registered encoder, return the index of that encoder within a DRM
  2578. * device's list of encoders.
  2579. */
  2580. static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
  2581. {
  2582. return encoder->index;
  2583. }
  2584. /**
  2585. * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
  2586. * @encoder: encoder to test
  2587. * @crtc: crtc to test
  2588. *
  2589. * Return false if @encoder can't be driven by @crtc, true otherwise.
  2590. */
  2591. static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
  2592. struct drm_crtc *crtc)
  2593. {
  2594. return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
  2595. }
  2596. extern __printf(8, 9)
  2597. int drm_universal_plane_init(struct drm_device *dev,
  2598. struct drm_plane *plane,
  2599. unsigned long possible_crtcs,
  2600. const struct drm_plane_funcs *funcs,
  2601. const uint32_t *formats,
  2602. unsigned int format_count,
  2603. enum drm_plane_type type,
  2604. const char *name, ...);
  2605. extern int drm_plane_init(struct drm_device *dev,
  2606. struct drm_plane *plane,
  2607. unsigned long possible_crtcs,
  2608. const struct drm_plane_funcs *funcs,
  2609. const uint32_t *formats, unsigned int format_count,
  2610. bool is_primary);
  2611. extern void drm_plane_cleanup(struct drm_plane *plane);
  2612. /**
  2613. * drm_plane_index - find the index of a registered plane
  2614. * @plane: plane to find index for
  2615. *
  2616. * Given a registered plane, return the index of that plane within a DRM
  2617. * device's list of planes.
  2618. */
  2619. static inline unsigned int drm_plane_index(struct drm_plane *plane)
  2620. {
  2621. return plane->index;
  2622. }
  2623. extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
  2624. extern void drm_plane_force_disable(struct drm_plane *plane);
  2625. extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
  2626. int *hdisplay, int *vdisplay);
  2627. extern int drm_crtc_force_disable(struct drm_crtc *crtc);
  2628. extern int drm_crtc_force_disable_all(struct drm_device *dev);
  2629. extern void drm_encoder_cleanup(struct drm_encoder *encoder);
  2630. extern const char *drm_get_connector_status_name(enum drm_connector_status status);
  2631. extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
  2632. extern const char *drm_get_dpms_name(int val);
  2633. extern const char *drm_get_dvi_i_subconnector_name(int val);
  2634. extern const char *drm_get_dvi_i_select_name(int val);
  2635. extern const char *drm_get_tv_subconnector_name(int val);
  2636. extern const char *drm_get_tv_select_name(int val);
  2637. extern void drm_mode_config_init(struct drm_device *dev);
  2638. extern void drm_mode_config_reset(struct drm_device *dev);
  2639. extern void drm_mode_config_cleanup(struct drm_device *dev);
  2640. extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
  2641. const char *path);
  2642. int drm_mode_connector_set_tile_property(struct drm_connector *connector);
  2643. extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
  2644. const struct edid *edid);
  2645. extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
  2646. const u32 *formats,
  2647. unsigned int num_formats);
  2648. static inline bool drm_property_type_is(struct drm_property *property,
  2649. uint32_t type)
  2650. {
  2651. /* instanceof for props.. handles extended type vs original types: */
  2652. if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
  2653. return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
  2654. return property->flags & type;
  2655. }
  2656. extern int drm_object_property_set_value(struct drm_mode_object *obj,
  2657. struct drm_property *property,
  2658. uint64_t val);
  2659. extern int drm_object_property_get_value(struct drm_mode_object *obj,
  2660. struct drm_property *property,
  2661. uint64_t *value);
  2662. extern int drm_framebuffer_init(struct drm_device *dev,
  2663. struct drm_framebuffer *fb,
  2664. const struct drm_framebuffer_funcs *funcs);
  2665. extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
  2666. uint32_t id);
  2667. extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
  2668. extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
  2669. extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
  2670. extern void drm_object_attach_property(struct drm_mode_object *obj,
  2671. struct drm_property *property,
  2672. uint64_t init_val);
  2673. extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
  2674. const char *name, int num_values);
  2675. extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
  2676. const char *name,
  2677. const struct drm_prop_enum_list *props,
  2678. int num_values);
  2679. struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
  2680. int flags, const char *name,
  2681. const struct drm_prop_enum_list *props,
  2682. int num_props,
  2683. uint64_t supported_bits);
  2684. struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
  2685. const char *name,
  2686. uint64_t min, uint64_t max);
  2687. struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
  2688. int flags, const char *name,
  2689. int64_t min, int64_t max);
  2690. struct drm_property *drm_property_create_object(struct drm_device *dev,
  2691. int flags, const char *name, uint32_t type);
  2692. struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
  2693. const char *name);
  2694. struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
  2695. size_t length,
  2696. const void *data);
  2697. struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
  2698. uint32_t id);
  2699. struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
  2700. void drm_property_unreference_blob(struct drm_property_blob *blob);
  2701. extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
  2702. extern int drm_property_add_enum(struct drm_property *property, int index,
  2703. uint64_t value, const char *name);
  2704. extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
  2705. extern int drm_mode_create_tv_properties(struct drm_device *dev,
  2706. unsigned int num_modes,
  2707. const char * const modes[]);
  2708. extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
  2709. extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
  2710. extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
  2711. extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
  2712. extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
  2713. struct drm_encoder *encoder);
  2714. extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
  2715. int gamma_size);
  2716. extern int drm_mode_set_config_internal(struct drm_mode_set *set);
  2717. extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
  2718. extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
  2719. char topology[8]);
  2720. extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
  2721. char topology[8]);
  2722. extern void drm_mode_put_tile_group(struct drm_device *dev,
  2723. struct drm_tile_group *tg);
  2724. extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
  2725. struct drm_property *property,
  2726. uint64_t value);
  2727. extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
  2728. unsigned int supported_rotations);
  2729. extern unsigned int drm_rotation_simplify(unsigned int rotation,
  2730. unsigned int supported_rotations);
  2731. extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
  2732. uint degamma_lut_size,
  2733. bool has_ctm,
  2734. uint gamma_lut_size);
  2735. int drm_plane_create_zpos_property(struct drm_plane *plane,
  2736. unsigned int zpos,
  2737. unsigned int min, unsigned int max);
  2738. int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
  2739. unsigned int zpos);
  2740. /* Helpers */
  2741. struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
  2742. uint32_t id, uint32_t type);
  2743. void drm_mode_object_reference(struct drm_mode_object *obj);
  2744. void drm_mode_object_unreference(struct drm_mode_object *obj);
  2745. static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
  2746. uint32_t id)
  2747. {
  2748. struct drm_mode_object *mo;
  2749. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
  2750. return mo ? obj_to_plane(mo) : NULL;
  2751. }
  2752. static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
  2753. uint32_t id)
  2754. {
  2755. struct drm_mode_object *mo;
  2756. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
  2757. return mo ? obj_to_crtc(mo) : NULL;
  2758. }
  2759. static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
  2760. uint32_t id)
  2761. {
  2762. struct drm_mode_object *mo;
  2763. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
  2764. return mo ? obj_to_encoder(mo) : NULL;
  2765. }
  2766. /**
  2767. * drm_connector_lookup - lookup connector object
  2768. * @dev: DRM device
  2769. * @id: connector object id
  2770. *
  2771. * This function looks up the connector object specified by id
  2772. * add takes a reference to it.
  2773. */
  2774. static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
  2775. uint32_t id)
  2776. {
  2777. struct drm_mode_object *mo;
  2778. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
  2779. return mo ? obj_to_connector(mo) : NULL;
  2780. }
  2781. static inline struct drm_property *drm_property_find(struct drm_device *dev,
  2782. uint32_t id)
  2783. {
  2784. struct drm_mode_object *mo;
  2785. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
  2786. return mo ? obj_to_property(mo) : NULL;
  2787. }
  2788. /*
  2789. * Extract a degamma/gamma LUT value provided by user and round it to the
  2790. * precision supported by the hardware.
  2791. */
  2792. static inline uint32_t drm_color_lut_extract(uint32_t user_input,
  2793. uint32_t bit_precision)
  2794. {
  2795. uint32_t val = user_input;
  2796. uint32_t max = 0xffff >> (16 - bit_precision);
  2797. /* Round only if we're not using full precision. */
  2798. if (bit_precision < 16) {
  2799. val += 1UL << (16 - bit_precision - 1);
  2800. val >>= 16 - bit_precision;
  2801. }
  2802. return clamp_val(val, 0, max);
  2803. }
  2804. /**
  2805. * drm_framebuffer_reference - incr the fb refcnt
  2806. * @fb: framebuffer
  2807. *
  2808. * This functions increments the fb's refcount.
  2809. */
  2810. static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
  2811. {
  2812. drm_mode_object_reference(&fb->base);
  2813. }
  2814. /**
  2815. * drm_framebuffer_unreference - unref a framebuffer
  2816. * @fb: framebuffer to unref
  2817. *
  2818. * This functions decrements the fb's refcount and frees it if it drops to zero.
  2819. */
  2820. static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
  2821. {
  2822. drm_mode_object_unreference(&fb->base);
  2823. }
  2824. /**
  2825. * drm_framebuffer_read_refcount - read the framebuffer reference count.
  2826. * @fb: framebuffer
  2827. *
  2828. * This functions returns the framebuffer's reference count.
  2829. */
  2830. static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
  2831. {
  2832. return atomic_read(&fb->base.refcount.refcount);
  2833. }
  2834. /**
  2835. * drm_connector_reference - incr the connector refcnt
  2836. * @connector: connector
  2837. *
  2838. * This function increments the connector's refcount.
  2839. */
  2840. static inline void drm_connector_reference(struct drm_connector *connector)
  2841. {
  2842. drm_mode_object_reference(&connector->base);
  2843. }
  2844. /**
  2845. * drm_connector_unreference - unref a connector
  2846. * @connector: connector to unref
  2847. *
  2848. * This function decrements the connector's refcount and frees it if it drops to zero.
  2849. */
  2850. static inline void drm_connector_unreference(struct drm_connector *connector)
  2851. {
  2852. drm_mode_object_unreference(&connector->base);
  2853. }
  2854. /* Plane list iterator for legacy (overlay only) planes. */
  2855. #define drm_for_each_legacy_plane(plane, dev) \
  2856. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
  2857. for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
  2858. #define drm_for_each_plane(plane, dev) \
  2859. list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
  2860. #define drm_for_each_crtc(crtc, dev) \
  2861. list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
  2862. static inline void
  2863. assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
  2864. {
  2865. /*
  2866. * The connector hotadd/remove code currently grabs both locks when
  2867. * updating lists. Hence readers need only hold either of them to be
  2868. * safe and the check amounts to
  2869. *
  2870. * WARN_ON(not_holding(A) && not_holding(B)).
  2871. */
  2872. WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
  2873. !drm_modeset_is_locked(&mode_config->connection_mutex));
  2874. }
  2875. #define drm_for_each_connector(connector, dev) \
  2876. for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
  2877. connector = list_first_entry(&(dev)->mode_config.connector_list, \
  2878. struct drm_connector, head); \
  2879. &connector->head != (&(dev)->mode_config.connector_list); \
  2880. connector = list_next_entry(connector, head))
  2881. #define drm_for_each_encoder(encoder, dev) \
  2882. list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
  2883. #define drm_for_each_fb(fb, dev) \
  2884. for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
  2885. fb = list_first_entry(&(dev)->mode_config.fb_list, \
  2886. struct drm_framebuffer, head); \
  2887. &fb->head != (&(dev)->mode_config.fb_list); \
  2888. fb = list_next_entry(fb, head))
  2889. /* drm_edid.c */
  2890. bool drm_probe_ddc(struct i2c_adapter *adapter);
  2891. struct edid *drm_get_edid(struct drm_connector *connector,
  2892. struct i2c_adapter *adapter);
  2893. struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
  2894. struct i2c_adapter *adapter);
  2895. struct edid *drm_edid_duplicate(const struct edid *edid);
  2896. int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
  2897. u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
  2898. enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
  2899. bool drm_detect_hdmi_monitor(struct edid *edid);
  2900. bool drm_detect_monitor_audio(struct edid *edid);
  2901. bool drm_rgb_quant_range_selectable(struct edid *edid);
  2902. int drm_add_modes_noedid(struct drm_connector *connector,
  2903. int hdisplay, int vdisplay);
  2904. void drm_set_preferred_mode(struct drm_connector *connector,
  2905. int hpref, int vpref);
  2906. int drm_edid_header_is_valid(const u8 *raw_edid);
  2907. bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
  2908. bool *edid_corrupt);
  2909. bool drm_edid_is_valid(struct edid *edid);
  2910. void drm_edid_get_monitor_name(struct edid *edid, char *name,
  2911. int buflen);
  2912. struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
  2913. int hsize, int vsize, int fresh,
  2914. bool rb);
  2915. /* drm_bridge.c */
  2916. extern int drm_bridge_add(struct drm_bridge *bridge);
  2917. extern void drm_bridge_remove(struct drm_bridge *bridge);
  2918. extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
  2919. extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
  2920. bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
  2921. const struct drm_display_mode *mode,
  2922. struct drm_display_mode *adjusted_mode);
  2923. void drm_bridge_disable(struct drm_bridge *bridge);
  2924. void drm_bridge_post_disable(struct drm_bridge *bridge);
  2925. void drm_bridge_mode_set(struct drm_bridge *bridge,
  2926. struct drm_display_mode *mode,
  2927. struct drm_display_mode *adjusted_mode);
  2928. void drm_bridge_pre_enable(struct drm_bridge *bridge);
  2929. void drm_bridge_enable(struct drm_bridge *bridge);
  2930. #endif /* __DRM_CRTC_H__ */