drm.tmpl 162 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
  4. <book id="drmDevelopersGuide">
  5. <bookinfo>
  6. <title>Linux DRM Developer's Guide</title>
  7. <authorgroup>
  8. <author>
  9. <firstname>Jesse</firstname>
  10. <surname>Barnes</surname>
  11. <contrib>Initial version</contrib>
  12. <affiliation>
  13. <orgname>Intel Corporation</orgname>
  14. <address>
  15. <email>jesse.barnes@intel.com</email>
  16. </address>
  17. </affiliation>
  18. </author>
  19. <author>
  20. <firstname>Laurent</firstname>
  21. <surname>Pinchart</surname>
  22. <contrib>Driver internals</contrib>
  23. <affiliation>
  24. <orgname>Ideas on board SPRL</orgname>
  25. <address>
  26. <email>laurent.pinchart@ideasonboard.com</email>
  27. </address>
  28. </affiliation>
  29. </author>
  30. <author>
  31. <firstname>Daniel</firstname>
  32. <surname>Vetter</surname>
  33. <contrib>Contributions all over the place</contrib>
  34. <affiliation>
  35. <orgname>Intel Corporation</orgname>
  36. <address>
  37. <email>daniel.vetter@ffwll.ch</email>
  38. </address>
  39. </affiliation>
  40. </author>
  41. </authorgroup>
  42. <copyright>
  43. <year>2008-2009</year>
  44. <year>2013-2014</year>
  45. <holder>Intel Corporation</holder>
  46. </copyright>
  47. <copyright>
  48. <year>2012</year>
  49. <holder>Laurent Pinchart</holder>
  50. </copyright>
  51. <legalnotice>
  52. <para>
  53. The contents of this file may be used under the terms of the GNU
  54. General Public License version 2 (the "GPL") as distributed in
  55. the kernel source COPYING file.
  56. </para>
  57. </legalnotice>
  58. <revhistory>
  59. <!-- Put document revisions here, newest first. -->
  60. <revision>
  61. <revnumber>1.0</revnumber>
  62. <date>2012-07-13</date>
  63. <authorinitials>LP</authorinitials>
  64. <revremark>Added extensive documentation about driver internals.
  65. </revremark>
  66. </revision>
  67. </revhistory>
  68. </bookinfo>
  69. <toc></toc>
  70. <part id="drmCore">
  71. <title>DRM Core</title>
  72. <partintro>
  73. <para>
  74. This first part of the DRM Developer's Guide documents core DRM code,
  75. helper libraries for writing drivers and generic userspace interfaces
  76. exposed by DRM drivers.
  77. </para>
  78. </partintro>
  79. <chapter id="drmIntroduction">
  80. <title>Introduction</title>
  81. <para>
  82. The Linux DRM layer contains code intended to support the needs
  83. of complex graphics devices, usually containing programmable
  84. pipelines well suited to 3D graphics acceleration. Graphics
  85. drivers in the kernel may make use of DRM functions to make
  86. tasks like memory management, interrupt handling and DMA easier,
  87. and provide a uniform interface to applications.
  88. </para>
  89. <para>
  90. A note on versions: this guide covers features found in the DRM
  91. tree, including the TTM memory manager, output configuration and
  92. mode setting, and the new vblank internals, in addition to all
  93. the regular features found in current kernels.
  94. </para>
  95. <para>
  96. [Insert diagram of typical DRM stack here]
  97. </para>
  98. </chapter>
  99. <!-- Internals -->
  100. <chapter id="drmInternals">
  101. <title>DRM Internals</title>
  102. <para>
  103. This chapter documents DRM internals relevant to driver authors
  104. and developers working to add support for the latest features to
  105. existing drivers.
  106. </para>
  107. <para>
  108. First, we go over some typical driver initialization
  109. requirements, like setting up command buffers, creating an
  110. initial output configuration, and initializing core services.
  111. Subsequent sections cover core internals in more detail,
  112. providing implementation notes and examples.
  113. </para>
  114. <para>
  115. The DRM layer provides several services to graphics drivers,
  116. many of them driven by the application interfaces it provides
  117. through libdrm, the library that wraps most of the DRM ioctls.
  118. These include vblank event handling, memory
  119. management, output management, framebuffer management, command
  120. submission &amp; fencing, suspend/resume support, and DMA
  121. services.
  122. </para>
  123. <!-- Internals: driver init -->
  124. <sect1>
  125. <title>Driver Initialization</title>
  126. <para>
  127. At the core of every DRM driver is a <structname>drm_driver</structname>
  128. structure. Drivers typically statically initialize a drm_driver structure,
  129. and then pass it to one of the <function>drm_*_init()</function> functions
  130. to register it with the DRM subsystem.
  131. </para>
  132. <para>
  133. Newer drivers that no longer require a <structname>drm_bus</structname>
  134. structure can alternatively use the low-level device initialization and
  135. registration functions such as <function>drm_dev_alloc()</function> and
  136. <function>drm_dev_register()</function> directly.
  137. </para>
  138. <para>
  139. The <structname>drm_driver</structname> structure contains static
  140. information that describes the driver and features it supports, and
  141. pointers to methods that the DRM core will call to implement the DRM API.
  142. We will first go through the <structname>drm_driver</structname> static
  143. information fields, and will then describe individual operations in
  144. details as they get used in later sections.
  145. </para>
  146. <sect2>
  147. <title>Driver Information</title>
  148. <sect3>
  149. <title>Driver Features</title>
  150. <para>
  151. Drivers inform the DRM core about their requirements and supported
  152. features by setting appropriate flags in the
  153. <structfield>driver_features</structfield> field. Since those flags
  154. influence the DRM core behaviour since registration time, most of them
  155. must be set to registering the <structname>drm_driver</structname>
  156. instance.
  157. </para>
  158. <synopsis>u32 driver_features;</synopsis>
  159. <variablelist>
  160. <title>Driver Feature Flags</title>
  161. <varlistentry>
  162. <term>DRIVER_USE_AGP</term>
  163. <listitem><para>
  164. Driver uses AGP interface, the DRM core will manage AGP resources.
  165. </para></listitem>
  166. </varlistentry>
  167. <varlistentry>
  168. <term>DRIVER_REQUIRE_AGP</term>
  169. <listitem><para>
  170. Driver needs AGP interface to function. AGP initialization failure
  171. will become a fatal error.
  172. </para></listitem>
  173. </varlistentry>
  174. <varlistentry>
  175. <term>DRIVER_PCI_DMA</term>
  176. <listitem><para>
  177. Driver is capable of PCI DMA, mapping of PCI DMA buffers to
  178. userspace will be enabled. Deprecated.
  179. </para></listitem>
  180. </varlistentry>
  181. <varlistentry>
  182. <term>DRIVER_SG</term>
  183. <listitem><para>
  184. Driver can perform scatter/gather DMA, allocation and mapping of
  185. scatter/gather buffers will be enabled. Deprecated.
  186. </para></listitem>
  187. </varlistentry>
  188. <varlistentry>
  189. <term>DRIVER_HAVE_DMA</term>
  190. <listitem><para>
  191. Driver supports DMA, the userspace DMA API will be supported.
  192. Deprecated.
  193. </para></listitem>
  194. </varlistentry>
  195. <varlistentry>
  196. <term>DRIVER_HAVE_IRQ</term><term>DRIVER_IRQ_SHARED</term>
  197. <listitem><para>
  198. DRIVER_HAVE_IRQ indicates whether the driver has an IRQ handler
  199. managed by the DRM Core. The core will support simple IRQ handler
  200. installation when the flag is set. The installation process is
  201. described in <xref linkend="drm-irq-registration"/>.</para>
  202. <para>DRIVER_IRQ_SHARED indicates whether the device &amp; handler
  203. support shared IRQs (note that this is required of PCI drivers).
  204. </para></listitem>
  205. </varlistentry>
  206. <varlistentry>
  207. <term>DRIVER_GEM</term>
  208. <listitem><para>
  209. Driver use the GEM memory manager.
  210. </para></listitem>
  211. </varlistentry>
  212. <varlistentry>
  213. <term>DRIVER_MODESET</term>
  214. <listitem><para>
  215. Driver supports mode setting interfaces (KMS).
  216. </para></listitem>
  217. </varlistentry>
  218. <varlistentry>
  219. <term>DRIVER_PRIME</term>
  220. <listitem><para>
  221. Driver implements DRM PRIME buffer sharing.
  222. </para></listitem>
  223. </varlistentry>
  224. <varlistentry>
  225. <term>DRIVER_RENDER</term>
  226. <listitem><para>
  227. Driver supports dedicated render nodes.
  228. </para></listitem>
  229. </varlistentry>
  230. </variablelist>
  231. </sect3>
  232. <sect3>
  233. <title>Major, Minor and Patchlevel</title>
  234. <synopsis>int major;
  235. int minor;
  236. int patchlevel;</synopsis>
  237. <para>
  238. The DRM core identifies driver versions by a major, minor and patch
  239. level triplet. The information is printed to the kernel log at
  240. initialization time and passed to userspace through the
  241. DRM_IOCTL_VERSION ioctl.
  242. </para>
  243. <para>
  244. The major and minor numbers are also used to verify the requested driver
  245. API version passed to DRM_IOCTL_SET_VERSION. When the driver API changes
  246. between minor versions, applications can call DRM_IOCTL_SET_VERSION to
  247. select a specific version of the API. If the requested major isn't equal
  248. to the driver major, or the requested minor is larger than the driver
  249. minor, the DRM_IOCTL_SET_VERSION call will return an error. Otherwise
  250. the driver's set_version() method will be called with the requested
  251. version.
  252. </para>
  253. </sect3>
  254. <sect3>
  255. <title>Name, Description and Date</title>
  256. <synopsis>char *name;
  257. char *desc;
  258. char *date;</synopsis>
  259. <para>
  260. The driver name is printed to the kernel log at initialization time,
  261. used for IRQ registration and passed to userspace through
  262. DRM_IOCTL_VERSION.
  263. </para>
  264. <para>
  265. The driver description is a purely informative string passed to
  266. userspace through the DRM_IOCTL_VERSION ioctl and otherwise unused by
  267. the kernel.
  268. </para>
  269. <para>
  270. The driver date, formatted as YYYYMMDD, is meant to identify the date of
  271. the latest modification to the driver. However, as most drivers fail to
  272. update it, its value is mostly useless. The DRM core prints it to the
  273. kernel log at initialization time and passes it to userspace through the
  274. DRM_IOCTL_VERSION ioctl.
  275. </para>
  276. </sect3>
  277. </sect2>
  278. <sect2>
  279. <title>Device Registration</title>
  280. <para>
  281. A number of functions are provided to help with device registration.
  282. The functions deal with PCI and platform devices, respectively.
  283. </para>
  284. !Edrivers/gpu/drm/drm_pci.c
  285. !Edrivers/gpu/drm/drm_platform.c
  286. <para>
  287. New drivers that no longer rely on the services provided by the
  288. <structname>drm_bus</structname> structure can call the low-level
  289. device registration functions directly. The
  290. <function>drm_dev_alloc()</function> function can be used to allocate
  291. and initialize a new <structname>drm_device</structname> structure.
  292. Drivers will typically want to perform some additional setup on this
  293. structure, such as allocating driver-specific data and storing a
  294. pointer to it in the DRM device's <structfield>dev_private</structfield>
  295. field. Drivers should also set the device's unique name using the
  296. <function>drm_dev_set_unique()</function> function. After it has been
  297. set up a device can be registered with the DRM subsystem by calling
  298. <function>drm_dev_register()</function>. This will cause the device to
  299. be exposed to userspace and will call the driver's
  300. <structfield>.load()</structfield> implementation. When a device is
  301. removed, the DRM device can safely be unregistered and freed by calling
  302. <function>drm_dev_unregister()</function> followed by a call to
  303. <function>drm_dev_unref()</function>.
  304. </para>
  305. !Edrivers/gpu/drm/drm_drv.c
  306. </sect2>
  307. <sect2>
  308. <title>Driver Load</title>
  309. <para>
  310. The <methodname>load</methodname> method is the driver and device
  311. initialization entry point. The method is responsible for allocating and
  312. initializing driver private data, performing resource allocation and
  313. mapping (e.g. acquiring
  314. clocks, mapping registers or allocating command buffers), initializing
  315. the memory manager (<xref linkend="drm-memory-management"/>), installing
  316. the IRQ handler (<xref linkend="drm-irq-registration"/>), setting up
  317. vertical blanking handling (<xref linkend="drm-vertical-blank"/>), mode
  318. setting (<xref linkend="drm-mode-setting"/>) and initial output
  319. configuration (<xref linkend="drm-kms-init"/>).
  320. </para>
  321. <note><para>
  322. If compatibility is a concern (e.g. with drivers converted over from
  323. User Mode Setting to Kernel Mode Setting), care must be taken to prevent
  324. device initialization and control that is incompatible with currently
  325. active userspace drivers. For instance, if user level mode setting
  326. drivers are in use, it would be problematic to perform output discovery
  327. &amp; configuration at load time. Likewise, if user-level drivers
  328. unaware of memory management are in use, memory management and command
  329. buffer setup may need to be omitted. These requirements are
  330. driver-specific, and care needs to be taken to keep both old and new
  331. applications and libraries working.
  332. </para></note>
  333. <synopsis>int (*load) (struct drm_device *, unsigned long flags);</synopsis>
  334. <para>
  335. The method takes two arguments, a pointer to the newly created
  336. <structname>drm_device</structname> and flags. The flags are used to
  337. pass the <structfield>driver_data</structfield> field of the device id
  338. corresponding to the device passed to <function>drm_*_init()</function>.
  339. Only PCI devices currently use this, USB and platform DRM drivers have
  340. their <methodname>load</methodname> method called with flags to 0.
  341. </para>
  342. <sect3>
  343. <title>Driver Private Data</title>
  344. <para>
  345. The driver private hangs off the main
  346. <structname>drm_device</structname> structure and can be used for
  347. tracking various device-specific bits of information, like register
  348. offsets, command buffer status, register state for suspend/resume, etc.
  349. At load time, a driver may simply allocate one and set
  350. <structname>drm_device</structname>.<structfield>dev_priv</structfield>
  351. appropriately; it should be freed and
  352. <structname>drm_device</structname>.<structfield>dev_priv</structfield>
  353. set to NULL when the driver is unloaded.
  354. </para>
  355. </sect3>
  356. <sect3 id="drm-irq-registration">
  357. <title>IRQ Registration</title>
  358. <para>
  359. The DRM core tries to facilitate IRQ handler registration and
  360. unregistration by providing <function>drm_irq_install</function> and
  361. <function>drm_irq_uninstall</function> functions. Those functions only
  362. support a single interrupt per device, devices that use more than one
  363. IRQs need to be handled manually.
  364. </para>
  365. <sect4>
  366. <title>Managed IRQ Registration</title>
  367. <para>
  368. <function>drm_irq_install</function> starts by calling the
  369. <methodname>irq_preinstall</methodname> driver operation. The operation
  370. is optional and must make sure that the interrupt will not get fired by
  371. clearing all pending interrupt flags or disabling the interrupt.
  372. </para>
  373. <para>
  374. The passed-in IRQ will then be requested by a call to
  375. <function>request_irq</function>. If the DRIVER_IRQ_SHARED driver
  376. feature flag is set, a shared (IRQF_SHARED) IRQ handler will be
  377. requested.
  378. </para>
  379. <para>
  380. The IRQ handler function must be provided as the mandatory irq_handler
  381. driver operation. It will get passed directly to
  382. <function>request_irq</function> and thus has the same prototype as all
  383. IRQ handlers. It will get called with a pointer to the DRM device as the
  384. second argument.
  385. </para>
  386. <para>
  387. Finally the function calls the optional
  388. <methodname>irq_postinstall</methodname> driver operation. The operation
  389. usually enables interrupts (excluding the vblank interrupt, which is
  390. enabled separately), but drivers may choose to enable/disable interrupts
  391. at a different time.
  392. </para>
  393. <para>
  394. <function>drm_irq_uninstall</function> is similarly used to uninstall an
  395. IRQ handler. It starts by waking up all processes waiting on a vblank
  396. interrupt to make sure they don't hang, and then calls the optional
  397. <methodname>irq_uninstall</methodname> driver operation. The operation
  398. must disable all hardware interrupts. Finally the function frees the IRQ
  399. by calling <function>free_irq</function>.
  400. </para>
  401. </sect4>
  402. <sect4>
  403. <title>Manual IRQ Registration</title>
  404. <para>
  405. Drivers that require multiple interrupt handlers can't use the managed
  406. IRQ registration functions. In that case IRQs must be registered and
  407. unregistered manually (usually with the <function>request_irq</function>
  408. and <function>free_irq</function> functions, or their devm_* equivalent).
  409. </para>
  410. <para>
  411. When manually registering IRQs, drivers must not set the DRIVER_HAVE_IRQ
  412. driver feature flag, and must not provide the
  413. <methodname>irq_handler</methodname> driver operation. They must set the
  414. <structname>drm_device</structname> <structfield>irq_enabled</structfield>
  415. field to 1 upon registration of the IRQs, and clear it to 0 after
  416. unregistering the IRQs.
  417. </para>
  418. </sect4>
  419. </sect3>
  420. <sect3>
  421. <title>Memory Manager Initialization</title>
  422. <para>
  423. Every DRM driver requires a memory manager which must be initialized at
  424. load time. DRM currently contains two memory managers, the Translation
  425. Table Manager (TTM) and the Graphics Execution Manager (GEM).
  426. This document describes the use of the GEM memory manager only. See
  427. <xref linkend="drm-memory-management"/> for details.
  428. </para>
  429. </sect3>
  430. <sect3>
  431. <title>Miscellaneous Device Configuration</title>
  432. <para>
  433. Another task that may be necessary for PCI devices during configuration
  434. is mapping the video BIOS. On many devices, the VBIOS describes device
  435. configuration, LCD panel timings (if any), and contains flags indicating
  436. device state. Mapping the BIOS can be done using the pci_map_rom() call,
  437. a convenience function that takes care of mapping the actual ROM,
  438. whether it has been shadowed into memory (typically at address 0xc0000)
  439. or exists on the PCI device in the ROM BAR. Note that after the ROM has
  440. been mapped and any necessary information has been extracted, it should
  441. be unmapped; on many devices, the ROM address decoder is shared with
  442. other BARs, so leaving it mapped could cause undesired behaviour like
  443. hangs or memory corruption.
  444. <!--!Fdrivers/pci/rom.c pci_map_rom-->
  445. </para>
  446. </sect3>
  447. </sect2>
  448. </sect1>
  449. <!-- Internals: memory management -->
  450. <sect1 id="drm-memory-management">
  451. <title>Memory management</title>
  452. <para>
  453. Modern Linux systems require large amount of graphics memory to store
  454. frame buffers, textures, vertices and other graphics-related data. Given
  455. the very dynamic nature of many of that data, managing graphics memory
  456. efficiently is thus crucial for the graphics stack and plays a central
  457. role in the DRM infrastructure.
  458. </para>
  459. <para>
  460. The DRM core includes two memory managers, namely Translation Table Maps
  461. (TTM) and Graphics Execution Manager (GEM). TTM was the first DRM memory
  462. manager to be developed and tried to be a one-size-fits-them all
  463. solution. It provides a single userspace API to accommodate the need of
  464. all hardware, supporting both Unified Memory Architecture (UMA) devices
  465. and devices with dedicated video RAM (i.e. most discrete video cards).
  466. This resulted in a large, complex piece of code that turned out to be
  467. hard to use for driver development.
  468. </para>
  469. <para>
  470. GEM started as an Intel-sponsored project in reaction to TTM's
  471. complexity. Its design philosophy is completely different: instead of
  472. providing a solution to every graphics memory-related problems, GEM
  473. identified common code between drivers and created a support library to
  474. share it. GEM has simpler initialization and execution requirements than
  475. TTM, but has no video RAM management capabilities and is thus limited to
  476. UMA devices.
  477. </para>
  478. <sect2>
  479. <title>The Translation Table Manager (TTM)</title>
  480. <para>
  481. TTM design background and information belongs here.
  482. </para>
  483. <sect3>
  484. <title>TTM initialization</title>
  485. <warning><para>This section is outdated.</para></warning>
  486. <para>
  487. Drivers wishing to support TTM must fill out a drm_bo_driver
  488. structure. The structure contains several fields with function
  489. pointers for initializing the TTM, allocating and freeing memory,
  490. waiting for command completion and fence synchronization, and memory
  491. migration. See the radeon_ttm.c file for an example of usage.
  492. </para>
  493. <para>
  494. The ttm_global_reference structure is made up of several fields:
  495. </para>
  496. <programlisting>
  497. struct ttm_global_reference {
  498. enum ttm_global_types global_type;
  499. size_t size;
  500. void *object;
  501. int (*init) (struct ttm_global_reference *);
  502. void (*release) (struct ttm_global_reference *);
  503. };
  504. </programlisting>
  505. <para>
  506. There should be one global reference structure for your memory
  507. manager as a whole, and there will be others for each object
  508. created by the memory manager at runtime. Your global TTM should
  509. have a type of TTM_GLOBAL_TTM_MEM. The size field for the global
  510. object should be sizeof(struct ttm_mem_global), and the init and
  511. release hooks should point at your driver-specific init and
  512. release routines, which probably eventually call
  513. ttm_mem_global_init and ttm_mem_global_release, respectively.
  514. </para>
  515. <para>
  516. Once your global TTM accounting structure is set up and initialized
  517. by calling ttm_global_item_ref() on it,
  518. you need to create a buffer object TTM to
  519. provide a pool for buffer object allocation by clients and the
  520. kernel itself. The type of this object should be TTM_GLOBAL_TTM_BO,
  521. and its size should be sizeof(struct ttm_bo_global). Again,
  522. driver-specific init and release functions may be provided,
  523. likely eventually calling ttm_bo_global_init() and
  524. ttm_bo_global_release(), respectively. Also, like the previous
  525. object, ttm_global_item_ref() is used to create an initial reference
  526. count for the TTM, which will call your initialization function.
  527. </para>
  528. </sect3>
  529. </sect2>
  530. <sect2 id="drm-gem">
  531. <title>The Graphics Execution Manager (GEM)</title>
  532. <para>
  533. The GEM design approach has resulted in a memory manager that doesn't
  534. provide full coverage of all (or even all common) use cases in its
  535. userspace or kernel API. GEM exposes a set of standard memory-related
  536. operations to userspace and a set of helper functions to drivers, and let
  537. drivers implement hardware-specific operations with their own private API.
  538. </para>
  539. <para>
  540. The GEM userspace API is described in the
  541. <ulink url="http://lwn.net/Articles/283798/"><citetitle>GEM - the Graphics
  542. Execution Manager</citetitle></ulink> article on LWN. While slightly
  543. outdated, the document provides a good overview of the GEM API principles.
  544. Buffer allocation and read and write operations, described as part of the
  545. common GEM API, are currently implemented using driver-specific ioctls.
  546. </para>
  547. <para>
  548. GEM is data-agnostic. It manages abstract buffer objects without knowing
  549. what individual buffers contain. APIs that require knowledge of buffer
  550. contents or purpose, such as buffer allocation or synchronization
  551. primitives, are thus outside of the scope of GEM and must be implemented
  552. using driver-specific ioctls.
  553. </para>
  554. <para>
  555. On a fundamental level, GEM involves several operations:
  556. <itemizedlist>
  557. <listitem>Memory allocation and freeing</listitem>
  558. <listitem>Command execution</listitem>
  559. <listitem>Aperture management at command execution time</listitem>
  560. </itemizedlist>
  561. Buffer object allocation is relatively straightforward and largely
  562. provided by Linux's shmem layer, which provides memory to back each
  563. object.
  564. </para>
  565. <para>
  566. Device-specific operations, such as command execution, pinning, buffer
  567. read &amp; write, mapping, and domain ownership transfers are left to
  568. driver-specific ioctls.
  569. </para>
  570. <sect3>
  571. <title>GEM Initialization</title>
  572. <para>
  573. Drivers that use GEM must set the DRIVER_GEM bit in the struct
  574. <structname>drm_driver</structname>
  575. <structfield>driver_features</structfield> field. The DRM core will
  576. then automatically initialize the GEM core before calling the
  577. <methodname>load</methodname> operation. Behind the scene, this will
  578. create a DRM Memory Manager object which provides an address space
  579. pool for object allocation.
  580. </para>
  581. <para>
  582. In a KMS configuration, drivers need to allocate and initialize a
  583. command ring buffer following core GEM initialization if required by
  584. the hardware. UMA devices usually have what is called a "stolen"
  585. memory region, which provides space for the initial framebuffer and
  586. large, contiguous memory regions required by the device. This space is
  587. typically not managed by GEM, and must be initialized separately into
  588. its own DRM MM object.
  589. </para>
  590. </sect3>
  591. <sect3>
  592. <title>GEM Objects Creation</title>
  593. <para>
  594. GEM splits creation of GEM objects and allocation of the memory that
  595. backs them in two distinct operations.
  596. </para>
  597. <para>
  598. GEM objects are represented by an instance of struct
  599. <structname>drm_gem_object</structname>. Drivers usually need to extend
  600. GEM objects with private information and thus create a driver-specific
  601. GEM object structure type that embeds an instance of struct
  602. <structname>drm_gem_object</structname>.
  603. </para>
  604. <para>
  605. To create a GEM object, a driver allocates memory for an instance of its
  606. specific GEM object type and initializes the embedded struct
  607. <structname>drm_gem_object</structname> with a call to
  608. <function>drm_gem_object_init</function>. The function takes a pointer to
  609. the DRM device, a pointer to the GEM object and the buffer object size
  610. in bytes.
  611. </para>
  612. <para>
  613. GEM uses shmem to allocate anonymous pageable memory.
  614. <function>drm_gem_object_init</function> will create an shmfs file of
  615. the requested size and store it into the struct
  616. <structname>drm_gem_object</structname> <structfield>filp</structfield>
  617. field. The memory is used as either main storage for the object when the
  618. graphics hardware uses system memory directly or as a backing store
  619. otherwise.
  620. </para>
  621. <para>
  622. Drivers are responsible for the actual physical pages allocation by
  623. calling <function>shmem_read_mapping_page_gfp</function> for each page.
  624. Note that they can decide to allocate pages when initializing the GEM
  625. object, or to delay allocation until the memory is needed (for instance
  626. when a page fault occurs as a result of a userspace memory access or
  627. when the driver needs to start a DMA transfer involving the memory).
  628. </para>
  629. <para>
  630. Anonymous pageable memory allocation is not always desired, for instance
  631. when the hardware requires physically contiguous system memory as is
  632. often the case in embedded devices. Drivers can create GEM objects with
  633. no shmfs backing (called private GEM objects) by initializing them with
  634. a call to <function>drm_gem_private_object_init</function> instead of
  635. <function>drm_gem_object_init</function>. Storage for private GEM
  636. objects must be managed by drivers.
  637. </para>
  638. <para>
  639. Drivers that do not need to extend GEM objects with private information
  640. can call the <function>drm_gem_object_alloc</function> function to
  641. allocate and initialize a struct <structname>drm_gem_object</structname>
  642. instance. The GEM core will call the optional driver
  643. <methodname>gem_init_object</methodname> operation after initializing
  644. the GEM object with <function>drm_gem_object_init</function>.
  645. <synopsis>int (*gem_init_object) (struct drm_gem_object *obj);</synopsis>
  646. </para>
  647. <para>
  648. No alloc-and-init function exists for private GEM objects.
  649. </para>
  650. </sect3>
  651. <sect3>
  652. <title>GEM Objects Lifetime</title>
  653. <para>
  654. All GEM objects are reference-counted by the GEM core. References can be
  655. acquired and release by <function>calling drm_gem_object_reference</function>
  656. and <function>drm_gem_object_unreference</function> respectively. The
  657. caller must hold the <structname>drm_device</structname>
  658. <structfield>struct_mutex</structfield> lock. As a convenience, GEM
  659. provides the <function>drm_gem_object_reference_unlocked</function> and
  660. <function>drm_gem_object_unreference_unlocked</function> functions that
  661. can be called without holding the lock.
  662. </para>
  663. <para>
  664. When the last reference to a GEM object is released the GEM core calls
  665. the <structname>drm_driver</structname>
  666. <methodname>gem_free_object</methodname> operation. That operation is
  667. mandatory for GEM-enabled drivers and must free the GEM object and all
  668. associated resources.
  669. </para>
  670. <para>
  671. <synopsis>void (*gem_free_object) (struct drm_gem_object *obj);</synopsis>
  672. Drivers are responsible for freeing all GEM object resources, including
  673. the resources created by the GEM core. If an mmap offset has been
  674. created for the object (in which case
  675. <structname>drm_gem_object</structname>::<structfield>map_list</structfield>::<structfield>map</structfield>
  676. is not NULL) it must be freed by a call to
  677. <function>drm_gem_free_mmap_offset</function>. The shmfs backing store
  678. must be released by calling <function>drm_gem_object_release</function>
  679. (that function can safely be called if no shmfs backing store has been
  680. created).
  681. </para>
  682. </sect3>
  683. <sect3>
  684. <title>GEM Objects Naming</title>
  685. <para>
  686. Communication between userspace and the kernel refers to GEM objects
  687. using local handles, global names or, more recently, file descriptors.
  688. All of those are 32-bit integer values; the usual Linux kernel limits
  689. apply to the file descriptors.
  690. </para>
  691. <para>
  692. GEM handles are local to a DRM file. Applications get a handle to a GEM
  693. object through a driver-specific ioctl, and can use that handle to refer
  694. to the GEM object in other standard or driver-specific ioctls. Closing a
  695. DRM file handle frees all its GEM handles and dereferences the
  696. associated GEM objects.
  697. </para>
  698. <para>
  699. To create a handle for a GEM object drivers call
  700. <function>drm_gem_handle_create</function>. The function takes a pointer
  701. to the DRM file and the GEM object and returns a locally unique handle.
  702. When the handle is no longer needed drivers delete it with a call to
  703. <function>drm_gem_handle_delete</function>. Finally the GEM object
  704. associated with a handle can be retrieved by a call to
  705. <function>drm_gem_object_lookup</function>.
  706. </para>
  707. <para>
  708. Handles don't take ownership of GEM objects, they only take a reference
  709. to the object that will be dropped when the handle is destroyed. To
  710. avoid leaking GEM objects, drivers must make sure they drop the
  711. reference(s) they own (such as the initial reference taken at object
  712. creation time) as appropriate, without any special consideration for the
  713. handle. For example, in the particular case of combined GEM object and
  714. handle creation in the implementation of the
  715. <methodname>dumb_create</methodname> operation, drivers must drop the
  716. initial reference to the GEM object before returning the handle.
  717. </para>
  718. <para>
  719. GEM names are similar in purpose to handles but are not local to DRM
  720. files. They can be passed between processes to reference a GEM object
  721. globally. Names can't be used directly to refer to objects in the DRM
  722. API, applications must convert handles to names and names to handles
  723. using the DRM_IOCTL_GEM_FLINK and DRM_IOCTL_GEM_OPEN ioctls
  724. respectively. The conversion is handled by the DRM core without any
  725. driver-specific support.
  726. </para>
  727. <para>
  728. GEM also supports buffer sharing with dma-buf file descriptors through
  729. PRIME. GEM-based drivers must use the provided helpers functions to
  730. implement the exporting and importing correctly. See <xref linkend="drm-prime-support" />.
  731. Since sharing file descriptors is inherently more secure than the
  732. easily guessable and global GEM names it is the preferred buffer
  733. sharing mechanism. Sharing buffers through GEM names is only supported
  734. for legacy userspace. Furthermore PRIME also allows cross-device
  735. buffer sharing since it is based on dma-bufs.
  736. </para>
  737. </sect3>
  738. <sect3 id="drm-gem-objects-mapping">
  739. <title>GEM Objects Mapping</title>
  740. <para>
  741. Because mapping operations are fairly heavyweight GEM favours
  742. read/write-like access to buffers, implemented through driver-specific
  743. ioctls, over mapping buffers to userspace. However, when random access
  744. to the buffer is needed (to perform software rendering for instance),
  745. direct access to the object can be more efficient.
  746. </para>
  747. <para>
  748. The mmap system call can't be used directly to map GEM objects, as they
  749. don't have their own file handle. Two alternative methods currently
  750. co-exist to map GEM objects to userspace. The first method uses a
  751. driver-specific ioctl to perform the mapping operation, calling
  752. <function>do_mmap</function> under the hood. This is often considered
  753. dubious, seems to be discouraged for new GEM-enabled drivers, and will
  754. thus not be described here.
  755. </para>
  756. <para>
  757. The second method uses the mmap system call on the DRM file handle.
  758. <synopsis>void *mmap(void *addr, size_t length, int prot, int flags, int fd,
  759. off_t offset);</synopsis>
  760. DRM identifies the GEM object to be mapped by a fake offset passed
  761. through the mmap offset argument. Prior to being mapped, a GEM object
  762. must thus be associated with a fake offset. To do so, drivers must call
  763. <function>drm_gem_create_mmap_offset</function> on the object. The
  764. function allocates a fake offset range from a pool and stores the
  765. offset divided by PAGE_SIZE in
  766. <literal>obj-&gt;map_list.hash.key</literal>. Care must be taken not to
  767. call <function>drm_gem_create_mmap_offset</function> if a fake offset
  768. has already been allocated for the object. This can be tested by
  769. <literal>obj-&gt;map_list.map</literal> being non-NULL.
  770. </para>
  771. <para>
  772. Once allocated, the fake offset value
  773. (<literal>obj-&gt;map_list.hash.key &lt;&lt; PAGE_SHIFT</literal>)
  774. must be passed to the application in a driver-specific way and can then
  775. be used as the mmap offset argument.
  776. </para>
  777. <para>
  778. The GEM core provides a helper method <function>drm_gem_mmap</function>
  779. to handle object mapping. The method can be set directly as the mmap
  780. file operation handler. It will look up the GEM object based on the
  781. offset value and set the VMA operations to the
  782. <structname>drm_driver</structname> <structfield>gem_vm_ops</structfield>
  783. field. Note that <function>drm_gem_mmap</function> doesn't map memory to
  784. userspace, but relies on the driver-provided fault handler to map pages
  785. individually.
  786. </para>
  787. <para>
  788. To use <function>drm_gem_mmap</function>, drivers must fill the struct
  789. <structname>drm_driver</structname> <structfield>gem_vm_ops</structfield>
  790. field with a pointer to VM operations.
  791. </para>
  792. <para>
  793. <synopsis>struct vm_operations_struct *gem_vm_ops
  794. struct vm_operations_struct {
  795. void (*open)(struct vm_area_struct * area);
  796. void (*close)(struct vm_area_struct * area);
  797. int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf);
  798. };</synopsis>
  799. </para>
  800. <para>
  801. The <methodname>open</methodname> and <methodname>close</methodname>
  802. operations must update the GEM object reference count. Drivers can use
  803. the <function>drm_gem_vm_open</function> and
  804. <function>drm_gem_vm_close</function> helper functions directly as open
  805. and close handlers.
  806. </para>
  807. <para>
  808. The fault operation handler is responsible for mapping individual pages
  809. to userspace when a page fault occurs. Depending on the memory
  810. allocation scheme, drivers can allocate pages at fault time, or can
  811. decide to allocate memory for the GEM object at the time the object is
  812. created.
  813. </para>
  814. <para>
  815. Drivers that want to map the GEM object upfront instead of handling page
  816. faults can implement their own mmap file operation handler.
  817. </para>
  818. </sect3>
  819. <sect3>
  820. <title>Memory Coherency</title>
  821. <para>
  822. When mapped to the device or used in a command buffer, backing pages
  823. for an object are flushed to memory and marked write combined so as to
  824. be coherent with the GPU. Likewise, if the CPU accesses an object
  825. after the GPU has finished rendering to the object, then the object
  826. must be made coherent with the CPU's view of memory, usually involving
  827. GPU cache flushing of various kinds. This core CPU&lt;-&gt;GPU
  828. coherency management is provided by a device-specific ioctl, which
  829. evaluates an object's current domain and performs any necessary
  830. flushing or synchronization to put the object into the desired
  831. coherency domain (note that the object may be busy, i.e. an active
  832. render target; in that case, setting the domain blocks the client and
  833. waits for rendering to complete before performing any necessary
  834. flushing operations).
  835. </para>
  836. </sect3>
  837. <sect3>
  838. <title>Command Execution</title>
  839. <para>
  840. Perhaps the most important GEM function for GPU devices is providing a
  841. command execution interface to clients. Client programs construct
  842. command buffers containing references to previously allocated memory
  843. objects, and then submit them to GEM. At that point, GEM takes care to
  844. bind all the objects into the GTT, execute the buffer, and provide
  845. necessary synchronization between clients accessing the same buffers.
  846. This often involves evicting some objects from the GTT and re-binding
  847. others (a fairly expensive operation), and providing relocation
  848. support which hides fixed GTT offsets from clients. Clients must take
  849. care not to submit command buffers that reference more objects than
  850. can fit in the GTT; otherwise, GEM will reject them and no rendering
  851. will occur. Similarly, if several objects in the buffer require fence
  852. registers to be allocated for correct rendering (e.g. 2D blits on
  853. pre-965 chips), care must be taken not to require more fence registers
  854. than are available to the client. Such resource management should be
  855. abstracted from the client in libdrm.
  856. </para>
  857. </sect3>
  858. <sect3>
  859. <title>GEM Function Reference</title>
  860. !Edrivers/gpu/drm/drm_gem.c
  861. </sect3>
  862. </sect2>
  863. <sect2>
  864. <title>VMA Offset Manager</title>
  865. !Pdrivers/gpu/drm/drm_vma_manager.c vma offset manager
  866. !Edrivers/gpu/drm/drm_vma_manager.c
  867. !Iinclude/drm/drm_vma_manager.h
  868. </sect2>
  869. <sect2 id="drm-prime-support">
  870. <title>PRIME Buffer Sharing</title>
  871. <para>
  872. PRIME is the cross device buffer sharing framework in drm, originally
  873. created for the OPTIMUS range of multi-gpu platforms. To userspace
  874. PRIME buffers are dma-buf based file descriptors.
  875. </para>
  876. <sect3>
  877. <title>Overview and Driver Interface</title>
  878. <para>
  879. Similar to GEM global names, PRIME file descriptors are
  880. also used to share buffer objects across processes. They offer
  881. additional security: as file descriptors must be explicitly sent over
  882. UNIX domain sockets to be shared between applications, they can't be
  883. guessed like the globally unique GEM names.
  884. </para>
  885. <para>
  886. Drivers that support the PRIME
  887. API must set the DRIVER_PRIME bit in the struct
  888. <structname>drm_driver</structname>
  889. <structfield>driver_features</structfield> field, and implement the
  890. <methodname>prime_handle_to_fd</methodname> and
  891. <methodname>prime_fd_to_handle</methodname> operations.
  892. </para>
  893. <para>
  894. <synopsis>int (*prime_handle_to_fd)(struct drm_device *dev,
  895. struct drm_file *file_priv, uint32_t handle,
  896. uint32_t flags, int *prime_fd);
  897. int (*prime_fd_to_handle)(struct drm_device *dev,
  898. struct drm_file *file_priv, int prime_fd,
  899. uint32_t *handle);</synopsis>
  900. Those two operations convert a handle to a PRIME file descriptor and
  901. vice versa. Drivers must use the kernel dma-buf buffer sharing framework
  902. to manage the PRIME file descriptors. Similar to the mode setting
  903. API PRIME is agnostic to the underlying buffer object manager, as
  904. long as handles are 32bit unsigned integers.
  905. </para>
  906. <para>
  907. While non-GEM drivers must implement the operations themselves, GEM
  908. drivers must use the <function>drm_gem_prime_handle_to_fd</function>
  909. and <function>drm_gem_prime_fd_to_handle</function> helper functions.
  910. Those helpers rely on the driver
  911. <methodname>gem_prime_export</methodname> and
  912. <methodname>gem_prime_import</methodname> operations to create a dma-buf
  913. instance from a GEM object (dma-buf exporter role) and to create a GEM
  914. object from a dma-buf instance (dma-buf importer role).
  915. </para>
  916. <para>
  917. <synopsis>struct dma_buf * (*gem_prime_export)(struct drm_device *dev,
  918. struct drm_gem_object *obj,
  919. int flags);
  920. struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev,
  921. struct dma_buf *dma_buf);</synopsis>
  922. These two operations are mandatory for GEM drivers that support
  923. PRIME.
  924. </para>
  925. </sect3>
  926. <sect3>
  927. <title>PRIME Helper Functions</title>
  928. !Pdrivers/gpu/drm/drm_prime.c PRIME Helpers
  929. </sect3>
  930. </sect2>
  931. <sect2>
  932. <title>PRIME Function References</title>
  933. !Edrivers/gpu/drm/drm_prime.c
  934. </sect2>
  935. <sect2>
  936. <title>DRM MM Range Allocator</title>
  937. <sect3>
  938. <title>Overview</title>
  939. !Pdrivers/gpu/drm/drm_mm.c Overview
  940. </sect3>
  941. <sect3>
  942. <title>LRU Scan/Eviction Support</title>
  943. !Pdrivers/gpu/drm/drm_mm.c lru scan roaster
  944. </sect3>
  945. </sect2>
  946. <sect2>
  947. <title>DRM MM Range Allocator Function References</title>
  948. !Edrivers/gpu/drm/drm_mm.c
  949. !Iinclude/drm/drm_mm.h
  950. </sect2>
  951. </sect1>
  952. <!-- Internals: mode setting -->
  953. <sect1 id="drm-mode-setting">
  954. <title>Mode Setting</title>
  955. <para>
  956. Drivers must initialize the mode setting core by calling
  957. <function>drm_mode_config_init</function> on the DRM device. The function
  958. initializes the <structname>drm_device</structname>
  959. <structfield>mode_config</structfield> field and never fails. Once done,
  960. mode configuration must be setup by initializing the following fields.
  961. </para>
  962. <itemizedlist>
  963. <listitem>
  964. <synopsis>int min_width, min_height;
  965. int max_width, max_height;</synopsis>
  966. <para>
  967. Minimum and maximum width and height of the frame buffers in pixel
  968. units.
  969. </para>
  970. </listitem>
  971. <listitem>
  972. <synopsis>struct drm_mode_config_funcs *funcs;</synopsis>
  973. <para>Mode setting functions.</para>
  974. </listitem>
  975. </itemizedlist>
  976. <sect2>
  977. <title>Display Modes Function Reference</title>
  978. !Iinclude/drm/drm_modes.h
  979. !Edrivers/gpu/drm/drm_modes.c
  980. </sect2>
  981. <sect2>
  982. <title>Frame Buffer Creation</title>
  983. <synopsis>struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
  984. struct drm_file *file_priv,
  985. struct drm_mode_fb_cmd2 *mode_cmd);</synopsis>
  986. <para>
  987. Frame buffers are abstract memory objects that provide a source of
  988. pixels to scanout to a CRTC. Applications explicitly request the
  989. creation of frame buffers through the DRM_IOCTL_MODE_ADDFB(2) ioctls and
  990. receive an opaque handle that can be passed to the KMS CRTC control,
  991. plane configuration and page flip functions.
  992. </para>
  993. <para>
  994. Frame buffers rely on the underneath memory manager for low-level memory
  995. operations. When creating a frame buffer applications pass a memory
  996. handle (or a list of memory handles for multi-planar formats) through
  997. the <parameter>drm_mode_fb_cmd2</parameter> argument. For drivers using
  998. GEM as their userspace buffer management interface this would be a GEM
  999. handle. Drivers are however free to use their own backing storage object
  1000. handles, e.g. vmwgfx directly exposes special TTM handles to userspace
  1001. and so expects TTM handles in the create ioctl and not GEM handles.
  1002. </para>
  1003. <para>
  1004. Drivers must first validate the requested frame buffer parameters passed
  1005. through the mode_cmd argument. In particular this is where invalid
  1006. sizes, pixel formats or pitches can be caught.
  1007. </para>
  1008. <para>
  1009. If the parameters are deemed valid, drivers then create, initialize and
  1010. return an instance of struct <structname>drm_framebuffer</structname>.
  1011. If desired the instance can be embedded in a larger driver-specific
  1012. structure. Drivers must fill its <structfield>width</structfield>,
  1013. <structfield>height</structfield>, <structfield>pitches</structfield>,
  1014. <structfield>offsets</structfield>, <structfield>depth</structfield>,
  1015. <structfield>bits_per_pixel</structfield> and
  1016. <structfield>pixel_format</structfield> fields from the values passed
  1017. through the <parameter>drm_mode_fb_cmd2</parameter> argument. They
  1018. should call the <function>drm_helper_mode_fill_fb_struct</function>
  1019. helper function to do so.
  1020. </para>
  1021. <para>
  1022. The initialization of the new framebuffer instance is finalized with a
  1023. call to <function>drm_framebuffer_init</function> which takes a pointer
  1024. to DRM frame buffer operations (struct
  1025. <structname>drm_framebuffer_funcs</structname>). Note that this function
  1026. publishes the framebuffer and so from this point on it can be accessed
  1027. concurrently from other threads. Hence it must be the last step in the
  1028. driver's framebuffer initialization sequence. Frame buffer operations
  1029. are
  1030. <itemizedlist>
  1031. <listitem>
  1032. <synopsis>int (*create_handle)(struct drm_framebuffer *fb,
  1033. struct drm_file *file_priv, unsigned int *handle);</synopsis>
  1034. <para>
  1035. Create a handle to the frame buffer underlying memory object. If
  1036. the frame buffer uses a multi-plane format, the handle will
  1037. reference the memory object associated with the first plane.
  1038. </para>
  1039. <para>
  1040. Drivers call <function>drm_gem_handle_create</function> to create
  1041. the handle.
  1042. </para>
  1043. </listitem>
  1044. <listitem>
  1045. <synopsis>void (*destroy)(struct drm_framebuffer *framebuffer);</synopsis>
  1046. <para>
  1047. Destroy the frame buffer object and frees all associated
  1048. resources. Drivers must call
  1049. <function>drm_framebuffer_cleanup</function> to free resources
  1050. allocated by the DRM core for the frame buffer object, and must
  1051. make sure to unreference all memory objects associated with the
  1052. frame buffer. Handles created by the
  1053. <methodname>create_handle</methodname> operation are released by
  1054. the DRM core.
  1055. </para>
  1056. </listitem>
  1057. <listitem>
  1058. <synopsis>int (*dirty)(struct drm_framebuffer *framebuffer,
  1059. struct drm_file *file_priv, unsigned flags, unsigned color,
  1060. struct drm_clip_rect *clips, unsigned num_clips);</synopsis>
  1061. <para>
  1062. This optional operation notifies the driver that a region of the
  1063. frame buffer has changed in response to a DRM_IOCTL_MODE_DIRTYFB
  1064. ioctl call.
  1065. </para>
  1066. </listitem>
  1067. </itemizedlist>
  1068. </para>
  1069. <para>
  1070. The lifetime of a drm framebuffer is controlled with a reference count,
  1071. drivers can grab additional references with
  1072. <function>drm_framebuffer_reference</function>and drop them
  1073. again with <function>drm_framebuffer_unreference</function>. For
  1074. driver-private framebuffers for which the last reference is never
  1075. dropped (e.g. for the fbdev framebuffer when the struct
  1076. <structname>drm_framebuffer</structname> is embedded into the fbdev
  1077. helper struct) drivers can manually clean up a framebuffer at module
  1078. unload time with
  1079. <function>drm_framebuffer_unregister_private</function>.
  1080. </para>
  1081. </sect2>
  1082. <sect2>
  1083. <title>Dumb Buffer Objects</title>
  1084. <para>
  1085. The KMS API doesn't standardize backing storage object creation and
  1086. leaves it to driver-specific ioctls. Furthermore actually creating a
  1087. buffer object even for GEM-based drivers is done through a
  1088. driver-specific ioctl - GEM only has a common userspace interface for
  1089. sharing and destroying objects. While not an issue for full-fledged
  1090. graphics stacks that include device-specific userspace components (in
  1091. libdrm for instance), this limit makes DRM-based early boot graphics
  1092. unnecessarily complex.
  1093. </para>
  1094. <para>
  1095. Dumb objects partly alleviate the problem by providing a standard
  1096. API to create dumb buffers suitable for scanout, which can then be used
  1097. to create KMS frame buffers.
  1098. </para>
  1099. <para>
  1100. To support dumb objects drivers must implement the
  1101. <methodname>dumb_create</methodname>,
  1102. <methodname>dumb_destroy</methodname> and
  1103. <methodname>dumb_map_offset</methodname> operations.
  1104. </para>
  1105. <itemizedlist>
  1106. <listitem>
  1107. <synopsis>int (*dumb_create)(struct drm_file *file_priv, struct drm_device *dev,
  1108. struct drm_mode_create_dumb *args);</synopsis>
  1109. <para>
  1110. The <methodname>dumb_create</methodname> operation creates a driver
  1111. object (GEM or TTM handle) suitable for scanout based on the
  1112. width, height and depth from the struct
  1113. <structname>drm_mode_create_dumb</structname> argument. It fills the
  1114. argument's <structfield>handle</structfield>,
  1115. <structfield>pitch</structfield> and <structfield>size</structfield>
  1116. fields with a handle for the newly created object and its line
  1117. pitch and size in bytes.
  1118. </para>
  1119. </listitem>
  1120. <listitem>
  1121. <synopsis>int (*dumb_destroy)(struct drm_file *file_priv, struct drm_device *dev,
  1122. uint32_t handle);</synopsis>
  1123. <para>
  1124. The <methodname>dumb_destroy</methodname> operation destroys a dumb
  1125. object created by <methodname>dumb_create</methodname>.
  1126. </para>
  1127. </listitem>
  1128. <listitem>
  1129. <synopsis>int (*dumb_map_offset)(struct drm_file *file_priv, struct drm_device *dev,
  1130. uint32_t handle, uint64_t *offset);</synopsis>
  1131. <para>
  1132. The <methodname>dumb_map_offset</methodname> operation associates an
  1133. mmap fake offset with the object given by the handle and returns
  1134. it. Drivers must use the
  1135. <function>drm_gem_create_mmap_offset</function> function to
  1136. associate the fake offset as described in
  1137. <xref linkend="drm-gem-objects-mapping"/>.
  1138. </para>
  1139. </listitem>
  1140. </itemizedlist>
  1141. <para>
  1142. Note that dumb objects may not be used for gpu acceleration, as has been
  1143. attempted on some ARM embedded platforms. Such drivers really must have
  1144. a hardware-specific ioctl to allocate suitable buffer objects.
  1145. </para>
  1146. </sect2>
  1147. <sect2>
  1148. <title>Output Polling</title>
  1149. <synopsis>void (*output_poll_changed)(struct drm_device *dev);</synopsis>
  1150. <para>
  1151. This operation notifies the driver that the status of one or more
  1152. connectors has changed. Drivers that use the fb helper can just call the
  1153. <function>drm_fb_helper_hotplug_event</function> function to handle this
  1154. operation.
  1155. </para>
  1156. </sect2>
  1157. <sect2>
  1158. <title>Locking</title>
  1159. <para>
  1160. Beside some lookup structures with their own locking (which is hidden
  1161. behind the interface functions) most of the modeset state is protected
  1162. by the <code>dev-&lt;mode_config.lock</code> mutex and additionally
  1163. per-crtc locks to allow cursor updates, pageflips and similar operations
  1164. to occur concurrently with background tasks like output detection.
  1165. Operations which cross domains like a full modeset always grab all
  1166. locks. Drivers there need to protect resources shared between crtcs with
  1167. additional locking. They also need to be careful to always grab the
  1168. relevant crtc locks if a modset functions touches crtc state, e.g. for
  1169. load detection (which does only grab the <code>mode_config.lock</code>
  1170. to allow concurrent screen updates on live crtcs).
  1171. </para>
  1172. </sect2>
  1173. </sect1>
  1174. <!-- Internals: kms initialization and cleanup -->
  1175. <sect1 id="drm-kms-init">
  1176. <title>KMS Initialization and Cleanup</title>
  1177. <para>
  1178. A KMS device is abstracted and exposed as a set of planes, CRTCs, encoders
  1179. and connectors. KMS drivers must thus create and initialize all those
  1180. objects at load time after initializing mode setting.
  1181. </para>
  1182. <sect2>
  1183. <title>CRTCs (struct <structname>drm_crtc</structname>)</title>
  1184. <para>
  1185. A CRTC is an abstraction representing a part of the chip that contains a
  1186. pointer to a scanout buffer. Therefore, the number of CRTCs available
  1187. determines how many independent scanout buffers can be active at any
  1188. given time. The CRTC structure contains several fields to support this:
  1189. a pointer to some video memory (abstracted as a frame buffer object), a
  1190. display mode, and an (x, y) offset into the video memory to support
  1191. panning or configurations where one piece of video memory spans multiple
  1192. CRTCs.
  1193. </para>
  1194. <sect3>
  1195. <title>CRTC Initialization</title>
  1196. <para>
  1197. A KMS device must create and register at least one struct
  1198. <structname>drm_crtc</structname> instance. The instance is allocated
  1199. and zeroed by the driver, possibly as part of a larger structure, and
  1200. registered with a call to <function>drm_crtc_init</function> with a
  1201. pointer to CRTC functions.
  1202. </para>
  1203. </sect3>
  1204. <sect3 id="drm-kms-crtcops">
  1205. <title>CRTC Operations</title>
  1206. <sect4>
  1207. <title>Set Configuration</title>
  1208. <synopsis>int (*set_config)(struct drm_mode_set *set);</synopsis>
  1209. <para>
  1210. Apply a new CRTC configuration to the device. The configuration
  1211. specifies a CRTC, a frame buffer to scan out from, a (x,y) position in
  1212. the frame buffer, a display mode and an array of connectors to drive
  1213. with the CRTC if possible.
  1214. </para>
  1215. <para>
  1216. If the frame buffer specified in the configuration is NULL, the driver
  1217. must detach all encoders connected to the CRTC and all connectors
  1218. attached to those encoders and disable them.
  1219. </para>
  1220. <para>
  1221. This operation is called with the mode config lock held.
  1222. </para>
  1223. <note><para>
  1224. Note that the drm core has no notion of restoring the mode setting
  1225. state after resume, since all resume handling is in the full
  1226. responsibility of the driver. The common mode setting helper library
  1227. though provides a helper which can be used for this:
  1228. <function>drm_helper_resume_force_mode</function>.
  1229. </para></note>
  1230. </sect4>
  1231. <sect4>
  1232. <title>Page Flipping</title>
  1233. <synopsis>int (*page_flip)(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1234. struct drm_pending_vblank_event *event);</synopsis>
  1235. <para>
  1236. Schedule a page flip to the given frame buffer for the CRTC. This
  1237. operation is called with the mode config mutex held.
  1238. </para>
  1239. <para>
  1240. Page flipping is a synchronization mechanism that replaces the frame
  1241. buffer being scanned out by the CRTC with a new frame buffer during
  1242. vertical blanking, avoiding tearing. When an application requests a page
  1243. flip the DRM core verifies that the new frame buffer is large enough to
  1244. be scanned out by the CRTC in the currently configured mode and then
  1245. calls the CRTC <methodname>page_flip</methodname> operation with a
  1246. pointer to the new frame buffer.
  1247. </para>
  1248. <para>
  1249. The <methodname>page_flip</methodname> operation schedules a page flip.
  1250. Once any pending rendering targeting the new frame buffer has
  1251. completed, the CRTC will be reprogrammed to display that frame buffer
  1252. after the next vertical refresh. The operation must return immediately
  1253. without waiting for rendering or page flip to complete and must block
  1254. any new rendering to the frame buffer until the page flip completes.
  1255. </para>
  1256. <para>
  1257. If a page flip can be successfully scheduled the driver must set the
  1258. <code>drm_crtc-&lt;fb</code> field to the new framebuffer pointed to
  1259. by <code>fb</code>. This is important so that the reference counting
  1260. on framebuffers stays balanced.
  1261. </para>
  1262. <para>
  1263. If a page flip is already pending, the
  1264. <methodname>page_flip</methodname> operation must return
  1265. -<errorname>EBUSY</errorname>.
  1266. </para>
  1267. <para>
  1268. To synchronize page flip to vertical blanking the driver will likely
  1269. need to enable vertical blanking interrupts. It should call
  1270. <function>drm_vblank_get</function> for that purpose, and call
  1271. <function>drm_vblank_put</function> after the page flip completes.
  1272. </para>
  1273. <para>
  1274. If the application has requested to be notified when page flip completes
  1275. the <methodname>page_flip</methodname> operation will be called with a
  1276. non-NULL <parameter>event</parameter> argument pointing to a
  1277. <structname>drm_pending_vblank_event</structname> instance. Upon page
  1278. flip completion the driver must call <methodname>drm_send_vblank_event</methodname>
  1279. to fill in the event and send to wake up any waiting processes.
  1280. This can be performed with
  1281. <programlisting><![CDATA[
  1282. spin_lock_irqsave(&dev->event_lock, flags);
  1283. ...
  1284. drm_send_vblank_event(dev, pipe, event);
  1285. spin_unlock_irqrestore(&dev->event_lock, flags);
  1286. ]]></programlisting>
  1287. </para>
  1288. <note><para>
  1289. FIXME: Could drivers that don't need to wait for rendering to complete
  1290. just add the event to <literal>dev-&gt;vblank_event_list</literal> and
  1291. let the DRM core handle everything, as for "normal" vertical blanking
  1292. events?
  1293. </para></note>
  1294. <para>
  1295. While waiting for the page flip to complete, the
  1296. <literal>event-&gt;base.link</literal> list head can be used freely by
  1297. the driver to store the pending event in a driver-specific list.
  1298. </para>
  1299. <para>
  1300. If the file handle is closed before the event is signaled, drivers must
  1301. take care to destroy the event in their
  1302. <methodname>preclose</methodname> operation (and, if needed, call
  1303. <function>drm_vblank_put</function>).
  1304. </para>
  1305. </sect4>
  1306. <sect4>
  1307. <title>Miscellaneous</title>
  1308. <itemizedlist>
  1309. <listitem>
  1310. <synopsis>void (*set_property)(struct drm_crtc *crtc,
  1311. struct drm_property *property, uint64_t value);</synopsis>
  1312. <para>
  1313. Set the value of the given CRTC property to
  1314. <parameter>value</parameter>. See <xref linkend="drm-kms-properties"/>
  1315. for more information about properties.
  1316. </para>
  1317. </listitem>
  1318. <listitem>
  1319. <synopsis>void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  1320. uint32_t start, uint32_t size);</synopsis>
  1321. <para>
  1322. Apply a gamma table to the device. The operation is optional.
  1323. </para>
  1324. </listitem>
  1325. <listitem>
  1326. <synopsis>void (*destroy)(struct drm_crtc *crtc);</synopsis>
  1327. <para>
  1328. Destroy the CRTC when not needed anymore. See
  1329. <xref linkend="drm-kms-init"/>.
  1330. </para>
  1331. </listitem>
  1332. </itemizedlist>
  1333. </sect4>
  1334. </sect3>
  1335. </sect2>
  1336. <sect2>
  1337. <title>Planes (struct <structname>drm_plane</structname>)</title>
  1338. <para>
  1339. A plane represents an image source that can be blended with or overlayed
  1340. on top of a CRTC during the scanout process. Planes are associated with
  1341. a frame buffer to crop a portion of the image memory (source) and
  1342. optionally scale it to a destination size. The result is then blended
  1343. with or overlayed on top of a CRTC.
  1344. </para>
  1345. <para>
  1346. The DRM core recognizes three types of planes:
  1347. <itemizedlist>
  1348. <listitem>
  1349. DRM_PLANE_TYPE_PRIMARY represents a "main" plane for a CRTC. Primary
  1350. planes are the planes operated upon by by CRTC modesetting and flipping
  1351. operations described in <xref linkend="drm-kms-crtcops"/>.
  1352. </listitem>
  1353. <listitem>
  1354. DRM_PLANE_TYPE_CURSOR represents a "cursor" plane for a CRTC. Cursor
  1355. planes are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and
  1356. DRM_IOCTL_MODE_CURSOR2 ioctls.
  1357. </listitem>
  1358. <listitem>
  1359. DRM_PLANE_TYPE_OVERLAY represents all non-primary, non-cursor planes.
  1360. Some drivers refer to these types of planes as "sprites" internally.
  1361. </listitem>
  1362. </itemizedlist>
  1363. For compatibility with legacy userspace, only overlay planes are made
  1364. available to userspace by default. Userspace clients may set the
  1365. DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that
  1366. they wish to receive a universal plane list containing all plane types.
  1367. </para>
  1368. <sect3>
  1369. <title>Plane Initialization</title>
  1370. <para>
  1371. To create a plane, a KMS drivers allocates and
  1372. zeroes an instances of struct <structname>drm_plane</structname>
  1373. (possibly as part of a larger structure) and registers it with a call
  1374. to <function>drm_universal_plane_init</function>. The function takes a bitmask
  1375. of the CRTCs that can be associated with the plane, a pointer to the
  1376. plane functions, a list of format supported formats, and the type of
  1377. plane (primary, cursor, or overlay) being initialized.
  1378. </para>
  1379. <para>
  1380. Cursor and overlay planes are optional. All drivers should provide
  1381. one primary plane per CRTC (although this requirement may change in
  1382. the future); drivers that do not wish to provide special handling for
  1383. primary planes may make use of the helper functions described in
  1384. <xref linkend="drm-kms-planehelpers"/> to create and register a
  1385. primary plane with standard capabilities.
  1386. </para>
  1387. </sect3>
  1388. <sect3>
  1389. <title>Plane Operations</title>
  1390. <itemizedlist>
  1391. <listitem>
  1392. <synopsis>int (*update_plane)(struct drm_plane *plane, struct drm_crtc *crtc,
  1393. struct drm_framebuffer *fb, int crtc_x, int crtc_y,
  1394. unsigned int crtc_w, unsigned int crtc_h,
  1395. uint32_t src_x, uint32_t src_y,
  1396. uint32_t src_w, uint32_t src_h);</synopsis>
  1397. <para>
  1398. Enable and configure the plane to use the given CRTC and frame buffer.
  1399. </para>
  1400. <para>
  1401. The source rectangle in frame buffer memory coordinates is given by
  1402. the <parameter>src_x</parameter>, <parameter>src_y</parameter>,
  1403. <parameter>src_w</parameter> and <parameter>src_h</parameter>
  1404. parameters (as 16.16 fixed point values). Devices that don't support
  1405. subpixel plane coordinates can ignore the fractional part.
  1406. </para>
  1407. <para>
  1408. The destination rectangle in CRTC coordinates is given by the
  1409. <parameter>crtc_x</parameter>, <parameter>crtc_y</parameter>,
  1410. <parameter>crtc_w</parameter> and <parameter>crtc_h</parameter>
  1411. parameters (as integer values). Devices scale the source rectangle to
  1412. the destination rectangle. If scaling is not supported, and the source
  1413. rectangle size doesn't match the destination rectangle size, the
  1414. driver must return a -<errorname>EINVAL</errorname> error.
  1415. </para>
  1416. </listitem>
  1417. <listitem>
  1418. <synopsis>int (*disable_plane)(struct drm_plane *plane);</synopsis>
  1419. <para>
  1420. Disable the plane. The DRM core calls this method in response to a
  1421. DRM_IOCTL_MODE_SETPLANE ioctl call with the frame buffer ID set to 0.
  1422. Disabled planes must not be processed by the CRTC.
  1423. </para>
  1424. </listitem>
  1425. <listitem>
  1426. <synopsis>void (*destroy)(struct drm_plane *plane);</synopsis>
  1427. <para>
  1428. Destroy the plane when not needed anymore. See
  1429. <xref linkend="drm-kms-init"/>.
  1430. </para>
  1431. </listitem>
  1432. </itemizedlist>
  1433. </sect3>
  1434. </sect2>
  1435. <sect2>
  1436. <title>Encoders (struct <structname>drm_encoder</structname>)</title>
  1437. <para>
  1438. An encoder takes pixel data from a CRTC and converts it to a format
  1439. suitable for any attached connectors. On some devices, it may be
  1440. possible to have a CRTC send data to more than one encoder. In that
  1441. case, both encoders would receive data from the same scanout buffer,
  1442. resulting in a "cloned" display configuration across the connectors
  1443. attached to each encoder.
  1444. </para>
  1445. <sect3>
  1446. <title>Encoder Initialization</title>
  1447. <para>
  1448. As for CRTCs, a KMS driver must create, initialize and register at
  1449. least one struct <structname>drm_encoder</structname> instance. The
  1450. instance is allocated and zeroed by the driver, possibly as part of a
  1451. larger structure.
  1452. </para>
  1453. <para>
  1454. Drivers must initialize the struct <structname>drm_encoder</structname>
  1455. <structfield>possible_crtcs</structfield> and
  1456. <structfield>possible_clones</structfield> fields before registering the
  1457. encoder. Both fields are bitmasks of respectively the CRTCs that the
  1458. encoder can be connected to, and sibling encoders candidate for cloning.
  1459. </para>
  1460. <para>
  1461. After being initialized, the encoder must be registered with a call to
  1462. <function>drm_encoder_init</function>. The function takes a pointer to
  1463. the encoder functions and an encoder type. Supported types are
  1464. <itemizedlist>
  1465. <listitem>
  1466. DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A
  1467. </listitem>
  1468. <listitem>
  1469. DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort
  1470. </listitem>
  1471. <listitem>
  1472. DRM_MODE_ENCODER_LVDS for display panels
  1473. </listitem>
  1474. <listitem>
  1475. DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video, Component,
  1476. SCART)
  1477. </listitem>
  1478. <listitem>
  1479. DRM_MODE_ENCODER_VIRTUAL for virtual machine displays
  1480. </listitem>
  1481. </itemizedlist>
  1482. </para>
  1483. <para>
  1484. Encoders must be attached to a CRTC to be used. DRM drivers leave
  1485. encoders unattached at initialization time. Applications (or the fbdev
  1486. compatibility layer when implemented) are responsible for attaching the
  1487. encoders they want to use to a CRTC.
  1488. </para>
  1489. </sect3>
  1490. <sect3>
  1491. <title>Encoder Operations</title>
  1492. <itemizedlist>
  1493. <listitem>
  1494. <synopsis>void (*destroy)(struct drm_encoder *encoder);</synopsis>
  1495. <para>
  1496. Called to destroy the encoder when not needed anymore. See
  1497. <xref linkend="drm-kms-init"/>.
  1498. </para>
  1499. </listitem>
  1500. <listitem>
  1501. <synopsis>void (*set_property)(struct drm_plane *plane,
  1502. struct drm_property *property, uint64_t value);</synopsis>
  1503. <para>
  1504. Set the value of the given plane property to
  1505. <parameter>value</parameter>. See <xref linkend="drm-kms-properties"/>
  1506. for more information about properties.
  1507. </para>
  1508. </listitem>
  1509. </itemizedlist>
  1510. </sect3>
  1511. </sect2>
  1512. <sect2>
  1513. <title>Connectors (struct <structname>drm_connector</structname>)</title>
  1514. <para>
  1515. A connector is the final destination for pixel data on a device, and
  1516. usually connects directly to an external display device like a monitor
  1517. or laptop panel. A connector can only be attached to one encoder at a
  1518. time. The connector is also the structure where information about the
  1519. attached display is kept, so it contains fields for display data, EDID
  1520. data, DPMS &amp; connection status, and information about modes
  1521. supported on the attached displays.
  1522. </para>
  1523. <sect3>
  1524. <title>Connector Initialization</title>
  1525. <para>
  1526. Finally a KMS driver must create, initialize, register and attach at
  1527. least one struct <structname>drm_connector</structname> instance. The
  1528. instance is created as other KMS objects and initialized by setting the
  1529. following fields.
  1530. </para>
  1531. <variablelist>
  1532. <varlistentry>
  1533. <term><structfield>interlace_allowed</structfield></term>
  1534. <listitem><para>
  1535. Whether the connector can handle interlaced modes.
  1536. </para></listitem>
  1537. </varlistentry>
  1538. <varlistentry>
  1539. <term><structfield>doublescan_allowed</structfield></term>
  1540. <listitem><para>
  1541. Whether the connector can handle doublescan.
  1542. </para></listitem>
  1543. </varlistentry>
  1544. <varlistentry>
  1545. <term><structfield>display_info
  1546. </structfield></term>
  1547. <listitem><para>
  1548. Display information is filled from EDID information when a display
  1549. is detected. For non hot-pluggable displays such as flat panels in
  1550. embedded systems, the driver should initialize the
  1551. <structfield>display_info</structfield>.<structfield>width_mm</structfield>
  1552. and
  1553. <structfield>display_info</structfield>.<structfield>height_mm</structfield>
  1554. fields with the physical size of the display.
  1555. </para></listitem>
  1556. </varlistentry>
  1557. <varlistentry>
  1558. <term id="drm-kms-connector-polled"><structfield>polled</structfield></term>
  1559. <listitem><para>
  1560. Connector polling mode, a combination of
  1561. <variablelist>
  1562. <varlistentry>
  1563. <term>DRM_CONNECTOR_POLL_HPD</term>
  1564. <listitem><para>
  1565. The connector generates hotplug events and doesn't need to be
  1566. periodically polled. The CONNECT and DISCONNECT flags must not
  1567. be set together with the HPD flag.
  1568. </para></listitem>
  1569. </varlistentry>
  1570. <varlistentry>
  1571. <term>DRM_CONNECTOR_POLL_CONNECT</term>
  1572. <listitem><para>
  1573. Periodically poll the connector for connection.
  1574. </para></listitem>
  1575. </varlistentry>
  1576. <varlistentry>
  1577. <term>DRM_CONNECTOR_POLL_DISCONNECT</term>
  1578. <listitem><para>
  1579. Periodically poll the connector for disconnection.
  1580. </para></listitem>
  1581. </varlistentry>
  1582. </variablelist>
  1583. Set to 0 for connectors that don't support connection status
  1584. discovery.
  1585. </para></listitem>
  1586. </varlistentry>
  1587. </variablelist>
  1588. <para>
  1589. The connector is then registered with a call to
  1590. <function>drm_connector_init</function> with a pointer to the connector
  1591. functions and a connector type, and exposed through sysfs with a call to
  1592. <function>drm_connector_register</function>.
  1593. </para>
  1594. <para>
  1595. Supported connector types are
  1596. <itemizedlist>
  1597. <listitem>DRM_MODE_CONNECTOR_VGA</listitem>
  1598. <listitem>DRM_MODE_CONNECTOR_DVII</listitem>
  1599. <listitem>DRM_MODE_CONNECTOR_DVID</listitem>
  1600. <listitem>DRM_MODE_CONNECTOR_DVIA</listitem>
  1601. <listitem>DRM_MODE_CONNECTOR_Composite</listitem>
  1602. <listitem>DRM_MODE_CONNECTOR_SVIDEO</listitem>
  1603. <listitem>DRM_MODE_CONNECTOR_LVDS</listitem>
  1604. <listitem>DRM_MODE_CONNECTOR_Component</listitem>
  1605. <listitem>DRM_MODE_CONNECTOR_9PinDIN</listitem>
  1606. <listitem>DRM_MODE_CONNECTOR_DisplayPort</listitem>
  1607. <listitem>DRM_MODE_CONNECTOR_HDMIA</listitem>
  1608. <listitem>DRM_MODE_CONNECTOR_HDMIB</listitem>
  1609. <listitem>DRM_MODE_CONNECTOR_TV</listitem>
  1610. <listitem>DRM_MODE_CONNECTOR_eDP</listitem>
  1611. <listitem>DRM_MODE_CONNECTOR_VIRTUAL</listitem>
  1612. </itemizedlist>
  1613. </para>
  1614. <para>
  1615. Connectors must be attached to an encoder to be used. For devices that
  1616. map connectors to encoders 1:1, the connector should be attached at
  1617. initialization time with a call to
  1618. <function>drm_mode_connector_attach_encoder</function>. The driver must
  1619. also set the <structname>drm_connector</structname>
  1620. <structfield>encoder</structfield> field to point to the attached
  1621. encoder.
  1622. </para>
  1623. <para>
  1624. Finally, drivers must initialize the connectors state change detection
  1625. with a call to <function>drm_kms_helper_poll_init</function>. If at
  1626. least one connector is pollable but can't generate hotplug interrupts
  1627. (indicated by the DRM_CONNECTOR_POLL_CONNECT and
  1628. DRM_CONNECTOR_POLL_DISCONNECT connector flags), a delayed work will
  1629. automatically be queued to periodically poll for changes. Connectors
  1630. that can generate hotplug interrupts must be marked with the
  1631. DRM_CONNECTOR_POLL_HPD flag instead, and their interrupt handler must
  1632. call <function>drm_helper_hpd_irq_event</function>. The function will
  1633. queue a delayed work to check the state of all connectors, but no
  1634. periodic polling will be done.
  1635. </para>
  1636. </sect3>
  1637. <sect3>
  1638. <title>Connector Operations</title>
  1639. <note><para>
  1640. Unless otherwise state, all operations are mandatory.
  1641. </para></note>
  1642. <sect4>
  1643. <title>DPMS</title>
  1644. <synopsis>void (*dpms)(struct drm_connector *connector, int mode);</synopsis>
  1645. <para>
  1646. The DPMS operation sets the power state of a connector. The mode
  1647. argument is one of
  1648. <itemizedlist>
  1649. <listitem><para>DRM_MODE_DPMS_ON</para></listitem>
  1650. <listitem><para>DRM_MODE_DPMS_STANDBY</para></listitem>
  1651. <listitem><para>DRM_MODE_DPMS_SUSPEND</para></listitem>
  1652. <listitem><para>DRM_MODE_DPMS_OFF</para></listitem>
  1653. </itemizedlist>
  1654. </para>
  1655. <para>
  1656. In all but DPMS_ON mode the encoder to which the connector is attached
  1657. should put the display in low-power mode by driving its signals
  1658. appropriately. If more than one connector is attached to the encoder
  1659. care should be taken not to change the power state of other displays as
  1660. a side effect. Low-power mode should be propagated to the encoders and
  1661. CRTCs when all related connectors are put in low-power mode.
  1662. </para>
  1663. </sect4>
  1664. <sect4>
  1665. <title>Modes</title>
  1666. <synopsis>int (*fill_modes)(struct drm_connector *connector, uint32_t max_width,
  1667. uint32_t max_height);</synopsis>
  1668. <para>
  1669. Fill the mode list with all supported modes for the connector. If the
  1670. <parameter>max_width</parameter> and <parameter>max_height</parameter>
  1671. arguments are non-zero, the implementation must ignore all modes wider
  1672. than <parameter>max_width</parameter> or higher than
  1673. <parameter>max_height</parameter>.
  1674. </para>
  1675. <para>
  1676. The connector must also fill in this operation its
  1677. <structfield>display_info</structfield>
  1678. <structfield>width_mm</structfield> and
  1679. <structfield>height_mm</structfield> fields with the connected display
  1680. physical size in millimeters. The fields should be set to 0 if the value
  1681. isn't known or is not applicable (for instance for projector devices).
  1682. </para>
  1683. </sect4>
  1684. <sect4>
  1685. <title>Connection Status</title>
  1686. <para>
  1687. The connection status is updated through polling or hotplug events when
  1688. supported (see <xref linkend="drm-kms-connector-polled"/>). The status
  1689. value is reported to userspace through ioctls and must not be used
  1690. inside the driver, as it only gets initialized by a call to
  1691. <function>drm_mode_getconnector</function> from userspace.
  1692. </para>
  1693. <synopsis>enum drm_connector_status (*detect)(struct drm_connector *connector,
  1694. bool force);</synopsis>
  1695. <para>
  1696. Check to see if anything is attached to the connector. The
  1697. <parameter>force</parameter> parameter is set to false whilst polling or
  1698. to true when checking the connector due to user request.
  1699. <parameter>force</parameter> can be used by the driver to avoid
  1700. expensive, destructive operations during automated probing.
  1701. </para>
  1702. <para>
  1703. Return connector_status_connected if something is connected to the
  1704. connector, connector_status_disconnected if nothing is connected and
  1705. connector_status_unknown if the connection state isn't known.
  1706. </para>
  1707. <para>
  1708. Drivers should only return connector_status_connected if the connection
  1709. status has really been probed as connected. Connectors that can't detect
  1710. the connection status, or failed connection status probes, should return
  1711. connector_status_unknown.
  1712. </para>
  1713. </sect4>
  1714. <sect4>
  1715. <title>Miscellaneous</title>
  1716. <itemizedlist>
  1717. <listitem>
  1718. <synopsis>void (*set_property)(struct drm_connector *connector,
  1719. struct drm_property *property, uint64_t value);</synopsis>
  1720. <para>
  1721. Set the value of the given connector property to
  1722. <parameter>value</parameter>. See <xref linkend="drm-kms-properties"/>
  1723. for more information about properties.
  1724. </para>
  1725. </listitem>
  1726. <listitem>
  1727. <synopsis>void (*destroy)(struct drm_connector *connector);</synopsis>
  1728. <para>
  1729. Destroy the connector when not needed anymore. See
  1730. <xref linkend="drm-kms-init"/>.
  1731. </para>
  1732. </listitem>
  1733. </itemizedlist>
  1734. </sect4>
  1735. </sect3>
  1736. </sect2>
  1737. <sect2>
  1738. <title>Cleanup</title>
  1739. <para>
  1740. The DRM core manages its objects' lifetime. When an object is not needed
  1741. anymore the core calls its destroy function, which must clean up and
  1742. free every resource allocated for the object. Every
  1743. <function>drm_*_init</function> call must be matched with a
  1744. corresponding <function>drm_*_cleanup</function> call to cleanup CRTCs
  1745. (<function>drm_crtc_cleanup</function>), planes
  1746. (<function>drm_plane_cleanup</function>), encoders
  1747. (<function>drm_encoder_cleanup</function>) and connectors
  1748. (<function>drm_connector_cleanup</function>). Furthermore, connectors
  1749. that have been added to sysfs must be removed by a call to
  1750. <function>drm_connector_unregister</function> before calling
  1751. <function>drm_connector_cleanup</function>.
  1752. </para>
  1753. <para>
  1754. Connectors state change detection must be cleanup up with a call to
  1755. <function>drm_kms_helper_poll_fini</function>.
  1756. </para>
  1757. </sect2>
  1758. <sect2>
  1759. <title>Output discovery and initialization example</title>
  1760. <programlisting><![CDATA[
  1761. void intel_crt_init(struct drm_device *dev)
  1762. {
  1763. struct drm_connector *connector;
  1764. struct intel_output *intel_output;
  1765. intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL);
  1766. if (!intel_output)
  1767. return;
  1768. connector = &intel_output->base;
  1769. drm_connector_init(dev, &intel_output->base,
  1770. &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
  1771. drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs,
  1772. DRM_MODE_ENCODER_DAC);
  1773. drm_mode_connector_attach_encoder(&intel_output->base,
  1774. &intel_output->enc);
  1775. /* Set up the DDC bus. */
  1776. intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A");
  1777. if (!intel_output->ddc_bus) {
  1778. dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
  1779. "failed.\n");
  1780. return;
  1781. }
  1782. intel_output->type = INTEL_OUTPUT_ANALOG;
  1783. connector->interlace_allowed = 0;
  1784. connector->doublescan_allowed = 0;
  1785. drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs);
  1786. drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
  1787. drm_connector_register(connector);
  1788. }]]></programlisting>
  1789. <para>
  1790. In the example above (taken from the i915 driver), a CRTC, connector and
  1791. encoder combination is created. A device-specific i2c bus is also
  1792. created for fetching EDID data and performing monitor detection. Once
  1793. the process is complete, the new connector is registered with sysfs to
  1794. make its properties available to applications.
  1795. </para>
  1796. </sect2>
  1797. <sect2>
  1798. <title>KMS API Functions</title>
  1799. !Edrivers/gpu/drm/drm_crtc.c
  1800. </sect2>
  1801. <sect2>
  1802. <title>KMS Locking</title>
  1803. !Pdrivers/gpu/drm/drm_modeset_lock.c kms locking
  1804. !Iinclude/drm/drm_modeset_lock.h
  1805. !Edrivers/gpu/drm/drm_modeset_lock.c
  1806. </sect2>
  1807. </sect1>
  1808. <!-- Internals: kms helper functions -->
  1809. <sect1>
  1810. <title>Mode Setting Helper Functions</title>
  1811. <para>
  1812. The plane, CRTC, encoder and connector functions provided by the drivers
  1813. implement the DRM API. They're called by the DRM core and ioctl handlers
  1814. to handle device state changes and configuration request. As implementing
  1815. those functions often requires logic not specific to drivers, mid-layer
  1816. helper functions are available to avoid duplicating boilerplate code.
  1817. </para>
  1818. <para>
  1819. The DRM core contains one mid-layer implementation. The mid-layer provides
  1820. implementations of several plane, CRTC, encoder and connector functions
  1821. (called from the top of the mid-layer) that pre-process requests and call
  1822. lower-level functions provided by the driver (at the bottom of the
  1823. mid-layer). For instance, the
  1824. <function>drm_crtc_helper_set_config</function> function can be used to
  1825. fill the struct <structname>drm_crtc_funcs</structname>
  1826. <structfield>set_config</structfield> field. When called, it will split
  1827. the <methodname>set_config</methodname> operation in smaller, simpler
  1828. operations and call the driver to handle them.
  1829. </para>
  1830. <para>
  1831. To use the mid-layer, drivers call <function>drm_crtc_helper_add</function>,
  1832. <function>drm_encoder_helper_add</function> and
  1833. <function>drm_connector_helper_add</function> functions to install their
  1834. mid-layer bottom operations handlers, and fill the
  1835. <structname>drm_crtc_funcs</structname>,
  1836. <structname>drm_encoder_funcs</structname> and
  1837. <structname>drm_connector_funcs</structname> structures with pointers to
  1838. the mid-layer top API functions. Installing the mid-layer bottom operation
  1839. handlers is best done right after registering the corresponding KMS object.
  1840. </para>
  1841. <para>
  1842. The mid-layer is not split between CRTC, encoder and connector operations.
  1843. To use it, a driver must provide bottom functions for all of the three KMS
  1844. entities.
  1845. </para>
  1846. <sect2>
  1847. <title>Helper Functions</title>
  1848. <itemizedlist>
  1849. <listitem>
  1850. <synopsis>int drm_crtc_helper_set_config(struct drm_mode_set *set);</synopsis>
  1851. <para>
  1852. The <function>drm_crtc_helper_set_config</function> helper function
  1853. is a CRTC <methodname>set_config</methodname> implementation. It
  1854. first tries to locate the best encoder for each connector by calling
  1855. the connector <methodname>best_encoder</methodname> helper
  1856. operation.
  1857. </para>
  1858. <para>
  1859. After locating the appropriate encoders, the helper function will
  1860. call the <methodname>mode_fixup</methodname> encoder and CRTC helper
  1861. operations to adjust the requested mode, or reject it completely in
  1862. which case an error will be returned to the application. If the new
  1863. configuration after mode adjustment is identical to the current
  1864. configuration the helper function will return without performing any
  1865. other operation.
  1866. </para>
  1867. <para>
  1868. If the adjusted mode is identical to the current mode but changes to
  1869. the frame buffer need to be applied, the
  1870. <function>drm_crtc_helper_set_config</function> function will call
  1871. the CRTC <methodname>mode_set_base</methodname> helper operation. If
  1872. the adjusted mode differs from the current mode, or if the
  1873. <methodname>mode_set_base</methodname> helper operation is not
  1874. provided, the helper function performs a full mode set sequence by
  1875. calling the <methodname>prepare</methodname>,
  1876. <methodname>mode_set</methodname> and
  1877. <methodname>commit</methodname> CRTC and encoder helper operations,
  1878. in that order.
  1879. </para>
  1880. </listitem>
  1881. <listitem>
  1882. <synopsis>void drm_helper_connector_dpms(struct drm_connector *connector, int mode);</synopsis>
  1883. <para>
  1884. The <function>drm_helper_connector_dpms</function> helper function
  1885. is a connector <methodname>dpms</methodname> implementation that
  1886. tracks power state of connectors. To use the function, drivers must
  1887. provide <methodname>dpms</methodname> helper operations for CRTCs
  1888. and encoders to apply the DPMS state to the device.
  1889. </para>
  1890. <para>
  1891. The mid-layer doesn't track the power state of CRTCs and encoders.
  1892. The <methodname>dpms</methodname> helper operations can thus be
  1893. called with a mode identical to the currently active mode.
  1894. </para>
  1895. </listitem>
  1896. <listitem>
  1897. <synopsis>int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
  1898. uint32_t maxX, uint32_t maxY);</synopsis>
  1899. <para>
  1900. The <function>drm_helper_probe_single_connector_modes</function> helper
  1901. function is a connector <methodname>fill_modes</methodname>
  1902. implementation that updates the connection status for the connector
  1903. and then retrieves a list of modes by calling the connector
  1904. <methodname>get_modes</methodname> helper operation.
  1905. </para>
  1906. <para>
  1907. The function filters out modes larger than
  1908. <parameter>max_width</parameter> and <parameter>max_height</parameter>
  1909. if specified. It then calls the optional connector
  1910. <methodname>mode_valid</methodname> helper operation for each mode in
  1911. the probed list to check whether the mode is valid for the connector.
  1912. </para>
  1913. </listitem>
  1914. </itemizedlist>
  1915. </sect2>
  1916. <sect2>
  1917. <title>CRTC Helper Operations</title>
  1918. <itemizedlist>
  1919. <listitem id="drm-helper-crtc-mode-fixup">
  1920. <synopsis>bool (*mode_fixup)(struct drm_crtc *crtc,
  1921. const struct drm_display_mode *mode,
  1922. struct drm_display_mode *adjusted_mode);</synopsis>
  1923. <para>
  1924. Let CRTCs adjust the requested mode or reject it completely. This
  1925. operation returns true if the mode is accepted (possibly after being
  1926. adjusted) or false if it is rejected.
  1927. </para>
  1928. <para>
  1929. The <methodname>mode_fixup</methodname> operation should reject the
  1930. mode if it can't reasonably use it. The definition of "reasonable"
  1931. is currently fuzzy in this context. One possible behaviour would be
  1932. to set the adjusted mode to the panel timings when a fixed-mode
  1933. panel is used with hardware capable of scaling. Another behaviour
  1934. would be to accept any input mode and adjust it to the closest mode
  1935. supported by the hardware (FIXME: This needs to be clarified).
  1936. </para>
  1937. </listitem>
  1938. <listitem>
  1939. <synopsis>int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
  1940. struct drm_framebuffer *old_fb)</synopsis>
  1941. <para>
  1942. Move the CRTC on the current frame buffer (stored in
  1943. <literal>crtc-&gt;fb</literal>) to position (x,y). Any of the frame
  1944. buffer, x position or y position may have been modified.
  1945. </para>
  1946. <para>
  1947. This helper operation is optional. If not provided, the
  1948. <function>drm_crtc_helper_set_config</function> function will fall
  1949. back to the <methodname>mode_set</methodname> helper operation.
  1950. </para>
  1951. <note><para>
  1952. FIXME: Why are x and y passed as arguments, as they can be accessed
  1953. through <literal>crtc-&gt;x</literal> and
  1954. <literal>crtc-&gt;y</literal>?
  1955. </para></note>
  1956. </listitem>
  1957. <listitem>
  1958. <synopsis>void (*prepare)(struct drm_crtc *crtc);</synopsis>
  1959. <para>
  1960. Prepare the CRTC for mode setting. This operation is called after
  1961. validating the requested mode. Drivers use it to perform
  1962. device-specific operations required before setting the new mode.
  1963. </para>
  1964. </listitem>
  1965. <listitem>
  1966. <synopsis>int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
  1967. struct drm_display_mode *adjusted_mode, int x, int y,
  1968. struct drm_framebuffer *old_fb);</synopsis>
  1969. <para>
  1970. Set a new mode, position and frame buffer. Depending on the device
  1971. requirements, the mode can be stored internally by the driver and
  1972. applied in the <methodname>commit</methodname> operation, or
  1973. programmed to the hardware immediately.
  1974. </para>
  1975. <para>
  1976. The <methodname>mode_set</methodname> operation returns 0 on success
  1977. or a negative error code if an error occurs.
  1978. </para>
  1979. </listitem>
  1980. <listitem>
  1981. <synopsis>void (*commit)(struct drm_crtc *crtc);</synopsis>
  1982. <para>
  1983. Commit a mode. This operation is called after setting the new mode.
  1984. Upon return the device must use the new mode and be fully
  1985. operational.
  1986. </para>
  1987. </listitem>
  1988. </itemizedlist>
  1989. </sect2>
  1990. <sect2>
  1991. <title>Encoder Helper Operations</title>
  1992. <itemizedlist>
  1993. <listitem>
  1994. <synopsis>bool (*mode_fixup)(struct drm_encoder *encoder,
  1995. const struct drm_display_mode *mode,
  1996. struct drm_display_mode *adjusted_mode);</synopsis>
  1997. <para>
  1998. Let encoders adjust the requested mode or reject it completely. This
  1999. operation returns true if the mode is accepted (possibly after being
  2000. adjusted) or false if it is rejected. See the
  2001. <link linkend="drm-helper-crtc-mode-fixup">mode_fixup CRTC helper
  2002. operation</link> for an explanation of the allowed adjustments.
  2003. </para>
  2004. </listitem>
  2005. <listitem>
  2006. <synopsis>void (*prepare)(struct drm_encoder *encoder);</synopsis>
  2007. <para>
  2008. Prepare the encoder for mode setting. This operation is called after
  2009. validating the requested mode. Drivers use it to perform
  2010. device-specific operations required before setting the new mode.
  2011. </para>
  2012. </listitem>
  2013. <listitem>
  2014. <synopsis>void (*mode_set)(struct drm_encoder *encoder,
  2015. struct drm_display_mode *mode,
  2016. struct drm_display_mode *adjusted_mode);</synopsis>
  2017. <para>
  2018. Set a new mode. Depending on the device requirements, the mode can
  2019. be stored internally by the driver and applied in the
  2020. <methodname>commit</methodname> operation, or programmed to the
  2021. hardware immediately.
  2022. </para>
  2023. </listitem>
  2024. <listitem>
  2025. <synopsis>void (*commit)(struct drm_encoder *encoder);</synopsis>
  2026. <para>
  2027. Commit a mode. This operation is called after setting the new mode.
  2028. Upon return the device must use the new mode and be fully
  2029. operational.
  2030. </para>
  2031. </listitem>
  2032. </itemizedlist>
  2033. </sect2>
  2034. <sect2>
  2035. <title>Connector Helper Operations</title>
  2036. <itemizedlist>
  2037. <listitem>
  2038. <synopsis>struct drm_encoder *(*best_encoder)(struct drm_connector *connector);</synopsis>
  2039. <para>
  2040. Return a pointer to the best encoder for the connecter. Device that
  2041. map connectors to encoders 1:1 simply return the pointer to the
  2042. associated encoder. This operation is mandatory.
  2043. </para>
  2044. </listitem>
  2045. <listitem>
  2046. <synopsis>int (*get_modes)(struct drm_connector *connector);</synopsis>
  2047. <para>
  2048. Fill the connector's <structfield>probed_modes</structfield> list
  2049. by parsing EDID data with <function>drm_add_edid_modes</function> or
  2050. calling <function>drm_mode_probed_add</function> directly for every
  2051. supported mode and return the number of modes it has detected. This
  2052. operation is mandatory.
  2053. </para>
  2054. <para>
  2055. When adding modes manually the driver creates each mode with a call to
  2056. <function>drm_mode_create</function> and must fill the following fields.
  2057. <itemizedlist>
  2058. <listitem>
  2059. <synopsis>__u32 type;</synopsis>
  2060. <para>
  2061. Mode type bitmask, a combination of
  2062. <variablelist>
  2063. <varlistentry>
  2064. <term>DRM_MODE_TYPE_BUILTIN</term>
  2065. <listitem><para>not used?</para></listitem>
  2066. </varlistentry>
  2067. <varlistentry>
  2068. <term>DRM_MODE_TYPE_CLOCK_C</term>
  2069. <listitem><para>not used?</para></listitem>
  2070. </varlistentry>
  2071. <varlistentry>
  2072. <term>DRM_MODE_TYPE_CRTC_C</term>
  2073. <listitem><para>not used?</para></listitem>
  2074. </varlistentry>
  2075. <varlistentry>
  2076. <term>
  2077. DRM_MODE_TYPE_PREFERRED - The preferred mode for the connector
  2078. </term>
  2079. <listitem>
  2080. <para>not used?</para>
  2081. </listitem>
  2082. </varlistentry>
  2083. <varlistentry>
  2084. <term>DRM_MODE_TYPE_DEFAULT</term>
  2085. <listitem><para>not used?</para></listitem>
  2086. </varlistentry>
  2087. <varlistentry>
  2088. <term>DRM_MODE_TYPE_USERDEF</term>
  2089. <listitem><para>not used?</para></listitem>
  2090. </varlistentry>
  2091. <varlistentry>
  2092. <term>DRM_MODE_TYPE_DRIVER</term>
  2093. <listitem>
  2094. <para>
  2095. The mode has been created by the driver (as opposed to
  2096. to user-created modes).
  2097. </para>
  2098. </listitem>
  2099. </varlistentry>
  2100. </variablelist>
  2101. Drivers must set the DRM_MODE_TYPE_DRIVER bit for all modes they
  2102. create, and set the DRM_MODE_TYPE_PREFERRED bit for the preferred
  2103. mode.
  2104. </para>
  2105. </listitem>
  2106. <listitem>
  2107. <synopsis>__u32 clock;</synopsis>
  2108. <para>Pixel clock frequency in kHz unit</para>
  2109. </listitem>
  2110. <listitem>
  2111. <synopsis>__u16 hdisplay, hsync_start, hsync_end, htotal;
  2112. __u16 vdisplay, vsync_start, vsync_end, vtotal;</synopsis>
  2113. <para>Horizontal and vertical timing information</para>
  2114. <screen><![CDATA[
  2115. Active Front Sync Back
  2116. Region Porch Porch
  2117. <-----------------------><----------------><-------------><-------------->
  2118. //////////////////////|
  2119. ////////////////////// |
  2120. ////////////////////// |.................. ................
  2121. _______________
  2122. <----- [hv]display ----->
  2123. <------------- [hv]sync_start ------------>
  2124. <--------------------- [hv]sync_end --------------------->
  2125. <-------------------------------- [hv]total ----------------------------->
  2126. ]]></screen>
  2127. </listitem>
  2128. <listitem>
  2129. <synopsis>__u16 hskew;
  2130. __u16 vscan;</synopsis>
  2131. <para>Unknown</para>
  2132. </listitem>
  2133. <listitem>
  2134. <synopsis>__u32 flags;</synopsis>
  2135. <para>
  2136. Mode flags, a combination of
  2137. <variablelist>
  2138. <varlistentry>
  2139. <term>DRM_MODE_FLAG_PHSYNC</term>
  2140. <listitem><para>
  2141. Horizontal sync is active high
  2142. </para></listitem>
  2143. </varlistentry>
  2144. <varlistentry>
  2145. <term>DRM_MODE_FLAG_NHSYNC</term>
  2146. <listitem><para>
  2147. Horizontal sync is active low
  2148. </para></listitem>
  2149. </varlistentry>
  2150. <varlistentry>
  2151. <term>DRM_MODE_FLAG_PVSYNC</term>
  2152. <listitem><para>
  2153. Vertical sync is active high
  2154. </para></listitem>
  2155. </varlistentry>
  2156. <varlistentry>
  2157. <term>DRM_MODE_FLAG_NVSYNC</term>
  2158. <listitem><para>
  2159. Vertical sync is active low
  2160. </para></listitem>
  2161. </varlistentry>
  2162. <varlistentry>
  2163. <term>DRM_MODE_FLAG_INTERLACE</term>
  2164. <listitem><para>
  2165. Mode is interlaced
  2166. </para></listitem>
  2167. </varlistentry>
  2168. <varlistentry>
  2169. <term>DRM_MODE_FLAG_DBLSCAN</term>
  2170. <listitem><para>
  2171. Mode uses doublescan
  2172. </para></listitem>
  2173. </varlistentry>
  2174. <varlistentry>
  2175. <term>DRM_MODE_FLAG_CSYNC</term>
  2176. <listitem><para>
  2177. Mode uses composite sync
  2178. </para></listitem>
  2179. </varlistentry>
  2180. <varlistentry>
  2181. <term>DRM_MODE_FLAG_PCSYNC</term>
  2182. <listitem><para>
  2183. Composite sync is active high
  2184. </para></listitem>
  2185. </varlistentry>
  2186. <varlistentry>
  2187. <term>DRM_MODE_FLAG_NCSYNC</term>
  2188. <listitem><para>
  2189. Composite sync is active low
  2190. </para></listitem>
  2191. </varlistentry>
  2192. <varlistentry>
  2193. <term>DRM_MODE_FLAG_HSKEW</term>
  2194. <listitem><para>
  2195. hskew provided (not used?)
  2196. </para></listitem>
  2197. </varlistentry>
  2198. <varlistentry>
  2199. <term>DRM_MODE_FLAG_BCAST</term>
  2200. <listitem><para>
  2201. not used?
  2202. </para></listitem>
  2203. </varlistentry>
  2204. <varlistentry>
  2205. <term>DRM_MODE_FLAG_PIXMUX</term>
  2206. <listitem><para>
  2207. not used?
  2208. </para></listitem>
  2209. </varlistentry>
  2210. <varlistentry>
  2211. <term>DRM_MODE_FLAG_DBLCLK</term>
  2212. <listitem><para>
  2213. not used?
  2214. </para></listitem>
  2215. </varlistentry>
  2216. <varlistentry>
  2217. <term>DRM_MODE_FLAG_CLKDIV2</term>
  2218. <listitem><para>
  2219. ?
  2220. </para></listitem>
  2221. </varlistentry>
  2222. </variablelist>
  2223. </para>
  2224. <para>
  2225. Note that modes marked with the INTERLACE or DBLSCAN flags will be
  2226. filtered out by
  2227. <function>drm_helper_probe_single_connector_modes</function> if
  2228. the connector's <structfield>interlace_allowed</structfield> or
  2229. <structfield>doublescan_allowed</structfield> field is set to 0.
  2230. </para>
  2231. </listitem>
  2232. <listitem>
  2233. <synopsis>char name[DRM_DISPLAY_MODE_LEN];</synopsis>
  2234. <para>
  2235. Mode name. The driver must call
  2236. <function>drm_mode_set_name</function> to fill the mode name from
  2237. <structfield>hdisplay</structfield>,
  2238. <structfield>vdisplay</structfield> and interlace flag after
  2239. filling the corresponding fields.
  2240. </para>
  2241. </listitem>
  2242. </itemizedlist>
  2243. </para>
  2244. <para>
  2245. The <structfield>vrefresh</structfield> value is computed by
  2246. <function>drm_helper_probe_single_connector_modes</function>.
  2247. </para>
  2248. <para>
  2249. When parsing EDID data, <function>drm_add_edid_modes</function> fill the
  2250. connector <structfield>display_info</structfield>
  2251. <structfield>width_mm</structfield> and
  2252. <structfield>height_mm</structfield> fields. When creating modes
  2253. manually the <methodname>get_modes</methodname> helper operation must
  2254. set the <structfield>display_info</structfield>
  2255. <structfield>width_mm</structfield> and
  2256. <structfield>height_mm</structfield> fields if they haven't been set
  2257. already (for instance at initialization time when a fixed-size panel is
  2258. attached to the connector). The mode <structfield>width_mm</structfield>
  2259. and <structfield>height_mm</structfield> fields are only used internally
  2260. during EDID parsing and should not be set when creating modes manually.
  2261. </para>
  2262. </listitem>
  2263. <listitem>
  2264. <synopsis>int (*mode_valid)(struct drm_connector *connector,
  2265. struct drm_display_mode *mode);</synopsis>
  2266. <para>
  2267. Verify whether a mode is valid for the connector. Return MODE_OK for
  2268. supported modes and one of the enum drm_mode_status values (MODE_*)
  2269. for unsupported modes. This operation is optional.
  2270. </para>
  2271. <para>
  2272. As the mode rejection reason is currently not used beside for
  2273. immediately removing the unsupported mode, an implementation can
  2274. return MODE_BAD regardless of the exact reason why the mode is not
  2275. valid.
  2276. </para>
  2277. <note><para>
  2278. Note that the <methodname>mode_valid</methodname> helper operation is
  2279. only called for modes detected by the device, and
  2280. <emphasis>not</emphasis> for modes set by the user through the CRTC
  2281. <methodname>set_config</methodname> operation.
  2282. </para></note>
  2283. </listitem>
  2284. </itemizedlist>
  2285. </sect2>
  2286. <sect2>
  2287. <title>Modeset Helper Functions Reference</title>
  2288. !Edrivers/gpu/drm/drm_crtc_helper.c
  2289. </sect2>
  2290. <sect2>
  2291. <title>Output Probing Helper Functions Reference</title>
  2292. !Pdrivers/gpu/drm/drm_probe_helper.c output probing helper overview
  2293. !Edrivers/gpu/drm/drm_probe_helper.c
  2294. </sect2>
  2295. <sect2>
  2296. <title>fbdev Helper Functions Reference</title>
  2297. !Pdrivers/gpu/drm/drm_fb_helper.c fbdev helpers
  2298. !Edrivers/gpu/drm/drm_fb_helper.c
  2299. !Iinclude/drm/drm_fb_helper.h
  2300. </sect2>
  2301. <sect2>
  2302. <title>Display Port Helper Functions Reference</title>
  2303. !Pdrivers/gpu/drm/drm_dp_helper.c dp helpers
  2304. !Iinclude/drm/drm_dp_helper.h
  2305. !Edrivers/gpu/drm/drm_dp_helper.c
  2306. </sect2>
  2307. <sect2>
  2308. <title>Display Port MST Helper Functions Reference</title>
  2309. !Pdrivers/gpu/drm/drm_dp_mst_topology.c dp mst helper
  2310. !Iinclude/drm/drm_dp_mst_helper.h
  2311. !Edrivers/gpu/drm/drm_dp_mst_topology.c
  2312. </sect2>
  2313. <sect2>
  2314. <title>EDID Helper Functions Reference</title>
  2315. !Edrivers/gpu/drm/drm_edid.c
  2316. </sect2>
  2317. <sect2>
  2318. <title>Rectangle Utilities Reference</title>
  2319. !Pinclude/drm/drm_rect.h rect utils
  2320. !Iinclude/drm/drm_rect.h
  2321. !Edrivers/gpu/drm/drm_rect.c
  2322. </sect2>
  2323. <sect2>
  2324. <title>Flip-work Helper Reference</title>
  2325. !Pinclude/drm/drm_flip_work.h flip utils
  2326. !Iinclude/drm/drm_flip_work.h
  2327. !Edrivers/gpu/drm/drm_flip_work.c
  2328. </sect2>
  2329. <sect2>
  2330. <title>HDMI Infoframes Helper Reference</title>
  2331. <para>
  2332. Strictly speaking this is not a DRM helper library but generally useable
  2333. by any driver interfacing with HDMI outputs like v4l or alsa drivers.
  2334. But it nicely fits into the overall topic of mode setting helper
  2335. libraries and hence is also included here.
  2336. </para>
  2337. !Iinclude/linux/hdmi.h
  2338. !Edrivers/video/hdmi.c
  2339. </sect2>
  2340. <sect2>
  2341. <title id="drm-kms-planehelpers">Plane Helper Reference</title>
  2342. !Edrivers/gpu/drm/drm_plane_helper.c Plane Helpers
  2343. </sect2>
  2344. </sect1>
  2345. <!-- Internals: kms properties -->
  2346. <sect1 id="drm-kms-properties">
  2347. <title>KMS Properties</title>
  2348. <para>
  2349. Drivers may need to expose additional parameters to applications than
  2350. those described in the previous sections. KMS supports attaching
  2351. properties to CRTCs, connectors and planes and offers a userspace API to
  2352. list, get and set the property values.
  2353. </para>
  2354. <para>
  2355. Properties are identified by a name that uniquely defines the property
  2356. purpose, and store an associated value. For all property types except blob
  2357. properties the value is a 64-bit unsigned integer.
  2358. </para>
  2359. <para>
  2360. KMS differentiates between properties and property instances. Drivers
  2361. first create properties and then create and associate individual instances
  2362. of those properties to objects. A property can be instantiated multiple
  2363. times and associated with different objects. Values are stored in property
  2364. instances, and all other property information are stored in the property
  2365. and shared between all instances of the property.
  2366. </para>
  2367. <para>
  2368. Every property is created with a type that influences how the KMS core
  2369. handles the property. Supported property types are
  2370. <variablelist>
  2371. <varlistentry>
  2372. <term>DRM_MODE_PROP_RANGE</term>
  2373. <listitem><para>Range properties report their minimum and maximum
  2374. admissible values. The KMS core verifies that values set by
  2375. application fit in that range.</para></listitem>
  2376. </varlistentry>
  2377. <varlistentry>
  2378. <term>DRM_MODE_PROP_ENUM</term>
  2379. <listitem><para>Enumerated properties take a numerical value that
  2380. ranges from 0 to the number of enumerated values defined by the
  2381. property minus one, and associate a free-formed string name to each
  2382. value. Applications can retrieve the list of defined value-name pairs
  2383. and use the numerical value to get and set property instance values.
  2384. </para></listitem>
  2385. </varlistentry>
  2386. <varlistentry>
  2387. <term>DRM_MODE_PROP_BITMASK</term>
  2388. <listitem><para>Bitmask properties are enumeration properties that
  2389. additionally restrict all enumerated values to the 0..63 range.
  2390. Bitmask property instance values combine one or more of the
  2391. enumerated bits defined by the property.</para></listitem>
  2392. </varlistentry>
  2393. <varlistentry>
  2394. <term>DRM_MODE_PROP_BLOB</term>
  2395. <listitem><para>Blob properties store a binary blob without any format
  2396. restriction. The binary blobs are created as KMS standalone objects,
  2397. and blob property instance values store the ID of their associated
  2398. blob object.</para>
  2399. <para>Blob properties are only used for the connector EDID property
  2400. and cannot be created by drivers.</para></listitem>
  2401. </varlistentry>
  2402. </variablelist>
  2403. </para>
  2404. <para>
  2405. To create a property drivers call one of the following functions depending
  2406. on the property type. All property creation functions take property flags
  2407. and name, as well as type-specific arguments.
  2408. <itemizedlist>
  2409. <listitem>
  2410. <synopsis>struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
  2411. const char *name,
  2412. uint64_t min, uint64_t max);</synopsis>
  2413. <para>Create a range property with the given minimum and maximum
  2414. values.</para>
  2415. </listitem>
  2416. <listitem>
  2417. <synopsis>struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
  2418. const char *name,
  2419. const struct drm_prop_enum_list *props,
  2420. int num_values);</synopsis>
  2421. <para>Create an enumerated property. The <parameter>props</parameter>
  2422. argument points to an array of <parameter>num_values</parameter>
  2423. value-name pairs.</para>
  2424. </listitem>
  2425. <listitem>
  2426. <synopsis>struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
  2427. int flags, const char *name,
  2428. const struct drm_prop_enum_list *props,
  2429. int num_values);</synopsis>
  2430. <para>Create a bitmask property. The <parameter>props</parameter>
  2431. argument points to an array of <parameter>num_values</parameter>
  2432. value-name pairs.</para>
  2433. </listitem>
  2434. </itemizedlist>
  2435. </para>
  2436. <para>
  2437. Properties can additionally be created as immutable, in which case they
  2438. will be read-only for applications but can be modified by the driver. To
  2439. create an immutable property drivers must set the DRM_MODE_PROP_IMMUTABLE
  2440. flag at property creation time.
  2441. </para>
  2442. <para>
  2443. When no array of value-name pairs is readily available at property
  2444. creation time for enumerated or range properties, drivers can create
  2445. the property using the <function>drm_property_create</function> function
  2446. and manually add enumeration value-name pairs by calling the
  2447. <function>drm_property_add_enum</function> function. Care must be taken to
  2448. properly specify the property type through the <parameter>flags</parameter>
  2449. argument.
  2450. </para>
  2451. <para>
  2452. After creating properties drivers can attach property instances to CRTC,
  2453. connector and plane objects by calling the
  2454. <function>drm_object_attach_property</function>. The function takes a
  2455. pointer to the target object, a pointer to the previously created property
  2456. and an initial instance value.
  2457. </para>
  2458. <sect2>
  2459. <title>Existing KMS Properties</title>
  2460. <para>
  2461. The following table gives description of drm properties exposed by various
  2462. modules/drivers.
  2463. </para>
  2464. <table border="1" cellpadding="0" cellspacing="0">
  2465. <tbody>
  2466. <tr style="font-weight: bold;">
  2467. <td valign="top" >Owner Module/Drivers</td>
  2468. <td valign="top" >Group</td>
  2469. <td valign="top" >Property Name</td>
  2470. <td valign="top" >Type</td>
  2471. <td valign="top" >Property Values</td>
  2472. <td valign="top" >Object attached</td>
  2473. <td valign="top" >Description/Restrictions</td>
  2474. </tr>
  2475. <tr>
  2476. <td rowspan="21" valign="top" >DRM</td>
  2477. <td rowspan="2" valign="top" >Generic</td>
  2478. <td valign="top" >“EDID”</td>
  2479. <td valign="top" >BLOB | IMMUTABLE</td>
  2480. <td valign="top" >0</td>
  2481. <td valign="top" >Connector</td>
  2482. <td valign="top" >Contains id of edid blob ptr object.</td>
  2483. </tr>
  2484. <tr>
  2485. <td valign="top" >“DPMS”</td>
  2486. <td valign="top" >ENUM</td>
  2487. <td valign="top" >{ “On”, “Standby”, “Suspend”, “Off” }</td>
  2488. <td valign="top" >Connector</td>
  2489. <td valign="top" >Contains DPMS operation mode value.</td>
  2490. </tr>
  2491. <tr>
  2492. <td rowspan="1" valign="top" >Plane</td>
  2493. <td valign="top" >“type”</td>
  2494. <td valign="top" >ENUM | IMMUTABLE</td>
  2495. <td valign="top" >{ "Overlay", "Primary", "Cursor" }</td>
  2496. <td valign="top" >Plane</td>
  2497. <td valign="top" >Plane type</td>
  2498. </tr>
  2499. <tr>
  2500. <td rowspan="2" valign="top" >DVI-I</td>
  2501. <td valign="top" >“subconnector”</td>
  2502. <td valign="top" >ENUM</td>
  2503. <td valign="top" >{ “Unknown”, “DVI-D”, “DVI-A” }</td>
  2504. <td valign="top" >Connector</td>
  2505. <td valign="top" >TBD</td>
  2506. </tr>
  2507. <tr>
  2508. <td valign="top" >“select subconnector”</td>
  2509. <td valign="top" >ENUM</td>
  2510. <td valign="top" >{ “Automatic”, “DVI-D”, “DVI-A” }</td>
  2511. <td valign="top" >Connector</td>
  2512. <td valign="top" >TBD</td>
  2513. </tr>
  2514. <tr>
  2515. <td rowspan="13" valign="top" >TV</td>
  2516. <td valign="top" >“subconnector”</td>
  2517. <td valign="top" >ENUM</td>
  2518. <td valign="top" >{ "Unknown", "Composite", "SVIDEO", "Component", "SCART" }</td>
  2519. <td valign="top" >Connector</td>
  2520. <td valign="top" >TBD</td>
  2521. </tr>
  2522. <tr>
  2523. <td valign="top" >“select subconnector”</td>
  2524. <td valign="top" >ENUM</td>
  2525. <td valign="top" >{ "Automatic", "Composite", "SVIDEO", "Component", "SCART" }</td>
  2526. <td valign="top" >Connector</td>
  2527. <td valign="top" >TBD</td>
  2528. </tr>
  2529. <tr>
  2530. <td valign="top" >“mode”</td>
  2531. <td valign="top" >ENUM</td>
  2532. <td valign="top" >{ "NTSC_M", "NTSC_J", "NTSC_443", "PAL_B" } etc.</td>
  2533. <td valign="top" >Connector</td>
  2534. <td valign="top" >TBD</td>
  2535. </tr>
  2536. <tr>
  2537. <td valign="top" >“left margin”</td>
  2538. <td valign="top" >RANGE</td>
  2539. <td valign="top" >Min=0, Max=100</td>
  2540. <td valign="top" >Connector</td>
  2541. <td valign="top" >TBD</td>
  2542. </tr>
  2543. <tr>
  2544. <td valign="top" >“right margin”</td>
  2545. <td valign="top" >RANGE</td>
  2546. <td valign="top" >Min=0, Max=100</td>
  2547. <td valign="top" >Connector</td>
  2548. <td valign="top" >TBD</td>
  2549. </tr>
  2550. <tr>
  2551. <td valign="top" >“top margin”</td>
  2552. <td valign="top" >RANGE</td>
  2553. <td valign="top" >Min=0, Max=100</td>
  2554. <td valign="top" >Connector</td>
  2555. <td valign="top" >TBD</td>
  2556. </tr>
  2557. <tr>
  2558. <td valign="top" >“bottom margin”</td>
  2559. <td valign="top" >RANGE</td>
  2560. <td valign="top" >Min=0, Max=100</td>
  2561. <td valign="top" >Connector</td>
  2562. <td valign="top" >TBD</td>
  2563. </tr>
  2564. <tr>
  2565. <td valign="top" >“brightness”</td>
  2566. <td valign="top" >RANGE</td>
  2567. <td valign="top" >Min=0, Max=100</td>
  2568. <td valign="top" >Connector</td>
  2569. <td valign="top" >TBD</td>
  2570. </tr>
  2571. <tr>
  2572. <td valign="top" >“contrast”</td>
  2573. <td valign="top" >RANGE</td>
  2574. <td valign="top" >Min=0, Max=100</td>
  2575. <td valign="top" >Connector</td>
  2576. <td valign="top" >TBD</td>
  2577. </tr>
  2578. <tr>
  2579. <td valign="top" >“flicker reduction”</td>
  2580. <td valign="top" >RANGE</td>
  2581. <td valign="top" >Min=0, Max=100</td>
  2582. <td valign="top" >Connector</td>
  2583. <td valign="top" >TBD</td>
  2584. </tr>
  2585. <tr>
  2586. <td valign="top" >“overscan”</td>
  2587. <td valign="top" >RANGE</td>
  2588. <td valign="top" >Min=0, Max=100</td>
  2589. <td valign="top" >Connector</td>
  2590. <td valign="top" >TBD</td>
  2591. </tr>
  2592. <tr>
  2593. <td valign="top" >“saturation”</td>
  2594. <td valign="top" >RANGE</td>
  2595. <td valign="top" >Min=0, Max=100</td>
  2596. <td valign="top" >Connector</td>
  2597. <td valign="top" >TBD</td>
  2598. </tr>
  2599. <tr>
  2600. <td valign="top" >“hue”</td>
  2601. <td valign="top" >RANGE</td>
  2602. <td valign="top" >Min=0, Max=100</td>
  2603. <td valign="top" >Connector</td>
  2604. <td valign="top" >TBD</td>
  2605. </tr>
  2606. <tr>
  2607. <td rowspan="3" valign="top" >Optional</td>
  2608. <td valign="top" >“scaling mode”</td>
  2609. <td valign="top" >ENUM</td>
  2610. <td valign="top" >{ "None", "Full", "Center", "Full aspect" }</td>
  2611. <td valign="top" >Connector</td>
  2612. <td valign="top" >TBD</td>
  2613. </tr>
  2614. <tr>
  2615. <td valign="top" >"aspect ratio"</td>
  2616. <td valign="top" >ENUM</td>
  2617. <td valign="top" >{ "None", "4:3", "16:9" }</td>
  2618. <td valign="top" >Connector</td>
  2619. <td valign="top" >DRM property to set aspect ratio from user space app.
  2620. This enum is made generic to allow addition of custom aspect
  2621. ratios.</td>
  2622. </tr>
  2623. <tr>
  2624. <td valign="top" >“dirty”</td>
  2625. <td valign="top" >ENUM | IMMUTABLE</td>
  2626. <td valign="top" >{ "Off", "On", "Annotate" }</td>
  2627. <td valign="top" >Connector</td>
  2628. <td valign="top" >TBD</td>
  2629. </tr>
  2630. <tr>
  2631. <td rowspan="21" valign="top" >i915</td>
  2632. <td rowspan="2" valign="top" >Generic</td>
  2633. <td valign="top" >"Broadcast RGB"</td>
  2634. <td valign="top" >ENUM</td>
  2635. <td valign="top" >{ "Automatic", "Full", "Limited 16:235" }</td>
  2636. <td valign="top" >Connector</td>
  2637. <td valign="top" >TBD</td>
  2638. </tr>
  2639. <tr>
  2640. <td valign="top" >“audio”</td>
  2641. <td valign="top" >ENUM</td>
  2642. <td valign="top" >{ "force-dvi", "off", "auto", "on" }</td>
  2643. <td valign="top" >Connector</td>
  2644. <td valign="top" >TBD</td>
  2645. </tr>
  2646. <tr>
  2647. <td rowspan="1" valign="top" >Plane</td>
  2648. <td valign="top" >“rotation”</td>
  2649. <td valign="top" >BITMASK</td>
  2650. <td valign="top" >{ 0, "rotate-0" }, { 2, "rotate-180" }</td>
  2651. <td valign="top" >Plane</td>
  2652. <td valign="top" >TBD</td>
  2653. </tr>
  2654. <tr>
  2655. <td rowspan="17" valign="top" >SDVO-TV</td>
  2656. <td valign="top" >“mode”</td>
  2657. <td valign="top" >ENUM</td>
  2658. <td valign="top" >{ "NTSC_M", "NTSC_J", "NTSC_443", "PAL_B" } etc.</td>
  2659. <td valign="top" >Connector</td>
  2660. <td valign="top" >TBD</td>
  2661. </tr>
  2662. <tr>
  2663. <td valign="top" >"left_margin"</td>
  2664. <td valign="top" >RANGE</td>
  2665. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2666. <td valign="top" >Connector</td>
  2667. <td valign="top" >TBD</td>
  2668. </tr>
  2669. <tr>
  2670. <td valign="top" >"right_margin"</td>
  2671. <td valign="top" >RANGE</td>
  2672. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2673. <td valign="top" >Connector</td>
  2674. <td valign="top" >TBD</td>
  2675. </tr>
  2676. <tr>
  2677. <td valign="top" >"top_margin"</td>
  2678. <td valign="top" >RANGE</td>
  2679. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2680. <td valign="top" >Connector</td>
  2681. <td valign="top" >TBD</td>
  2682. </tr>
  2683. <tr>
  2684. <td valign="top" >"bottom_margin"</td>
  2685. <td valign="top" >RANGE</td>
  2686. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2687. <td valign="top" >Connector</td>
  2688. <td valign="top" >TBD</td>
  2689. </tr>
  2690. <tr>
  2691. <td valign="top" >“hpos”</td>
  2692. <td valign="top" >RANGE</td>
  2693. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2694. <td valign="top" >Connector</td>
  2695. <td valign="top" >TBD</td>
  2696. </tr>
  2697. <tr>
  2698. <td valign="top" >“vpos”</td>
  2699. <td valign="top" >RANGE</td>
  2700. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2701. <td valign="top" >Connector</td>
  2702. <td valign="top" >TBD</td>
  2703. </tr>
  2704. <tr>
  2705. <td valign="top" >“contrast”</td>
  2706. <td valign="top" >RANGE</td>
  2707. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2708. <td valign="top" >Connector</td>
  2709. <td valign="top" >TBD</td>
  2710. </tr>
  2711. <tr>
  2712. <td valign="top" >“saturation”</td>
  2713. <td valign="top" >RANGE</td>
  2714. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2715. <td valign="top" >Connector</td>
  2716. <td valign="top" >TBD</td>
  2717. </tr>
  2718. <tr>
  2719. <td valign="top" >“hue”</td>
  2720. <td valign="top" >RANGE</td>
  2721. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2722. <td valign="top" >Connector</td>
  2723. <td valign="top" >TBD</td>
  2724. </tr>
  2725. <tr>
  2726. <td valign="top" >“sharpness”</td>
  2727. <td valign="top" >RANGE</td>
  2728. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2729. <td valign="top" >Connector</td>
  2730. <td valign="top" >TBD</td>
  2731. </tr>
  2732. <tr>
  2733. <td valign="top" >“flicker_filter”</td>
  2734. <td valign="top" >RANGE</td>
  2735. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2736. <td valign="top" >Connector</td>
  2737. <td valign="top" >TBD</td>
  2738. </tr>
  2739. <tr>
  2740. <td valign="top" >“flicker_filter_adaptive”</td>
  2741. <td valign="top" >RANGE</td>
  2742. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2743. <td valign="top" >Connector</td>
  2744. <td valign="top" >TBD</td>
  2745. </tr>
  2746. <tr>
  2747. <td valign="top" >“flicker_filter_2d”</td>
  2748. <td valign="top" >RANGE</td>
  2749. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2750. <td valign="top" >Connector</td>
  2751. <td valign="top" >TBD</td>
  2752. </tr>
  2753. <tr>
  2754. <td valign="top" >“tv_chroma_filter”</td>
  2755. <td valign="top" >RANGE</td>
  2756. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2757. <td valign="top" >Connector</td>
  2758. <td valign="top" >TBD</td>
  2759. </tr>
  2760. <tr>
  2761. <td valign="top" >“tv_luma_filter”</td>
  2762. <td valign="top" >RANGE</td>
  2763. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2764. <td valign="top" >Connector</td>
  2765. <td valign="top" >TBD</td>
  2766. </tr>
  2767. <tr>
  2768. <td valign="top" >“dot_crawl”</td>
  2769. <td valign="top" >RANGE</td>
  2770. <td valign="top" >Min=0, Max=1</td>
  2771. <td valign="top" >Connector</td>
  2772. <td valign="top" >TBD</td>
  2773. </tr>
  2774. <tr>
  2775. <td valign="top" >SDVO-TV/LVDS</td>
  2776. <td valign="top" >“brightness”</td>
  2777. <td valign="top" >RANGE</td>
  2778. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2779. <td valign="top" >Connector</td>
  2780. <td valign="top" >TBD</td>
  2781. </tr>
  2782. <tr>
  2783. <td rowspan="2" valign="top" >CDV gma-500</td>
  2784. <td rowspan="2" valign="top" >Generic</td>
  2785. <td valign="top" >"Broadcast RGB"</td>
  2786. <td valign="top" >ENUM</td>
  2787. <td valign="top" >{ “Full”, “Limited 16:235” }</td>
  2788. <td valign="top" >Connector</td>
  2789. <td valign="top" >TBD</td>
  2790. </tr>
  2791. <tr>
  2792. <td valign="top" >"Broadcast RGB"</td>
  2793. <td valign="top" >ENUM</td>
  2794. <td valign="top" >{ “off”, “auto”, “on” }</td>
  2795. <td valign="top" >Connector</td>
  2796. <td valign="top" >TBD</td>
  2797. </tr>
  2798. <tr>
  2799. <td rowspan="19" valign="top" >Poulsbo</td>
  2800. <td rowspan="1" valign="top" >Generic</td>
  2801. <td valign="top" >“backlight”</td>
  2802. <td valign="top" >RANGE</td>
  2803. <td valign="top" >Min=0, Max=100</td>
  2804. <td valign="top" >Connector</td>
  2805. <td valign="top" >TBD</td>
  2806. </tr>
  2807. <tr>
  2808. <td rowspan="17" valign="top" >SDVO-TV</td>
  2809. <td valign="top" >“mode”</td>
  2810. <td valign="top" >ENUM</td>
  2811. <td valign="top" >{ "NTSC_M", "NTSC_J", "NTSC_443", "PAL_B" } etc.</td>
  2812. <td valign="top" >Connector</td>
  2813. <td valign="top" >TBD</td>
  2814. </tr>
  2815. <tr>
  2816. <td valign="top" >"left_margin"</td>
  2817. <td valign="top" >RANGE</td>
  2818. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2819. <td valign="top" >Connector</td>
  2820. <td valign="top" >TBD</td>
  2821. </tr>
  2822. <tr>
  2823. <td valign="top" >"right_margin"</td>
  2824. <td valign="top" >RANGE</td>
  2825. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2826. <td valign="top" >Connector</td>
  2827. <td valign="top" >TBD</td>
  2828. </tr>
  2829. <tr>
  2830. <td valign="top" >"top_margin"</td>
  2831. <td valign="top" >RANGE</td>
  2832. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2833. <td valign="top" >Connector</td>
  2834. <td valign="top" >TBD</td>
  2835. </tr>
  2836. <tr>
  2837. <td valign="top" >"bottom_margin"</td>
  2838. <td valign="top" >RANGE</td>
  2839. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2840. <td valign="top" >Connector</td>
  2841. <td valign="top" >TBD</td>
  2842. </tr>
  2843. <tr>
  2844. <td valign="top" >“hpos”</td>
  2845. <td valign="top" >RANGE</td>
  2846. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2847. <td valign="top" >Connector</td>
  2848. <td valign="top" >TBD</td>
  2849. </tr>
  2850. <tr>
  2851. <td valign="top" >“vpos”</td>
  2852. <td valign="top" >RANGE</td>
  2853. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2854. <td valign="top" >Connector</td>
  2855. <td valign="top" >TBD</td>
  2856. </tr>
  2857. <tr>
  2858. <td valign="top" >“contrast”</td>
  2859. <td valign="top" >RANGE</td>
  2860. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2861. <td valign="top" >Connector</td>
  2862. <td valign="top" >TBD</td>
  2863. </tr>
  2864. <tr>
  2865. <td valign="top" >“saturation”</td>
  2866. <td valign="top" >RANGE</td>
  2867. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2868. <td valign="top" >Connector</td>
  2869. <td valign="top" >TBD</td>
  2870. </tr>
  2871. <tr>
  2872. <td valign="top" >“hue”</td>
  2873. <td valign="top" >RANGE</td>
  2874. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2875. <td valign="top" >Connector</td>
  2876. <td valign="top" >TBD</td>
  2877. </tr>
  2878. <tr>
  2879. <td valign="top" >“sharpness”</td>
  2880. <td valign="top" >RANGE</td>
  2881. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2882. <td valign="top" >Connector</td>
  2883. <td valign="top" >TBD</td>
  2884. </tr>
  2885. <tr>
  2886. <td valign="top" >“flicker_filter”</td>
  2887. <td valign="top" >RANGE</td>
  2888. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2889. <td valign="top" >Connector</td>
  2890. <td valign="top" >TBD</td>
  2891. </tr>
  2892. <tr>
  2893. <td valign="top" >“flicker_filter_adaptive”</td>
  2894. <td valign="top" >RANGE</td>
  2895. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2896. <td valign="top" >Connector</td>
  2897. <td valign="top" >TBD</td>
  2898. </tr>
  2899. <tr>
  2900. <td valign="top" >“flicker_filter_2d”</td>
  2901. <td valign="top" >RANGE</td>
  2902. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2903. <td valign="top" >Connector</td>
  2904. <td valign="top" >TBD</td>
  2905. </tr>
  2906. <tr>
  2907. <td valign="top" >“tv_chroma_filter”</td>
  2908. <td valign="top" >RANGE</td>
  2909. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2910. <td valign="top" >Connector</td>
  2911. <td valign="top" >TBD</td>
  2912. </tr>
  2913. <tr>
  2914. <td valign="top" >“tv_luma_filter”</td>
  2915. <td valign="top" >RANGE</td>
  2916. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2917. <td valign="top" >Connector</td>
  2918. <td valign="top" >TBD</td>
  2919. </tr>
  2920. <tr>
  2921. <td valign="top" >“dot_crawl”</td>
  2922. <td valign="top" >RANGE</td>
  2923. <td valign="top" >Min=0, Max=1</td>
  2924. <td valign="top" >Connector</td>
  2925. <td valign="top" >TBD</td>
  2926. </tr>
  2927. <tr>
  2928. <td valign="top" >SDVO-TV/LVDS</td>
  2929. <td valign="top" >“brightness”</td>
  2930. <td valign="top" >RANGE</td>
  2931. <td valign="top" >Min=0, Max= SDVO dependent</td>
  2932. <td valign="top" >Connector</td>
  2933. <td valign="top" >TBD</td>
  2934. </tr>
  2935. <tr>
  2936. <td rowspan="11" valign="top" >armada</td>
  2937. <td rowspan="2" valign="top" >CRTC</td>
  2938. <td valign="top" >"CSC_YUV"</td>
  2939. <td valign="top" >ENUM</td>
  2940. <td valign="top" >{ "Auto" , "CCIR601", "CCIR709" }</td>
  2941. <td valign="top" >CRTC</td>
  2942. <td valign="top" >TBD</td>
  2943. </tr>
  2944. <tr>
  2945. <td valign="top" >"CSC_RGB"</td>
  2946. <td valign="top" >ENUM</td>
  2947. <td valign="top" >{ "Auto", "Computer system", "Studio" }</td>
  2948. <td valign="top" >CRTC</td>
  2949. <td valign="top" >TBD</td>
  2950. </tr>
  2951. <tr>
  2952. <td rowspan="9" valign="top" >Overlay</td>
  2953. <td valign="top" >"colorkey"</td>
  2954. <td valign="top" >RANGE</td>
  2955. <td valign="top" >Min=0, Max=0xffffff</td>
  2956. <td valign="top" >Plane</td>
  2957. <td valign="top" >TBD</td>
  2958. </tr>
  2959. <tr>
  2960. <td valign="top" >"colorkey_min"</td>
  2961. <td valign="top" >RANGE</td>
  2962. <td valign="top" >Min=0, Max=0xffffff</td>
  2963. <td valign="top" >Plane</td>
  2964. <td valign="top" >TBD</td>
  2965. </tr>
  2966. <tr>
  2967. <td valign="top" >"colorkey_max"</td>
  2968. <td valign="top" >RANGE</td>
  2969. <td valign="top" >Min=0, Max=0xffffff</td>
  2970. <td valign="top" >Plane</td>
  2971. <td valign="top" >TBD</td>
  2972. </tr>
  2973. <tr>
  2974. <td valign="top" >"colorkey_val"</td>
  2975. <td valign="top" >RANGE</td>
  2976. <td valign="top" >Min=0, Max=0xffffff</td>
  2977. <td valign="top" >Plane</td>
  2978. <td valign="top" >TBD</td>
  2979. </tr>
  2980. <tr>
  2981. <td valign="top" >"colorkey_alpha"</td>
  2982. <td valign="top" >RANGE</td>
  2983. <td valign="top" >Min=0, Max=0xffffff</td>
  2984. <td valign="top" >Plane</td>
  2985. <td valign="top" >TBD</td>
  2986. </tr>
  2987. <tr>
  2988. <td valign="top" >"colorkey_mode"</td>
  2989. <td valign="top" >ENUM</td>
  2990. <td valign="top" >{ "disabled", "Y component", "U component"
  2991. , "V component", "RGB", “R component", "G component", "B component" }</td>
  2992. <td valign="top" >Plane</td>
  2993. <td valign="top" >TBD</td>
  2994. </tr>
  2995. <tr>
  2996. <td valign="top" >"brightness"</td>
  2997. <td valign="top" >RANGE</td>
  2998. <td valign="top" >Min=0, Max=256 + 255</td>
  2999. <td valign="top" >Plane</td>
  3000. <td valign="top" >TBD</td>
  3001. </tr>
  3002. <tr>
  3003. <td valign="top" >"contrast"</td>
  3004. <td valign="top" >RANGE</td>
  3005. <td valign="top" >Min=0, Max=0x7fff</td>
  3006. <td valign="top" >Plane</td>
  3007. <td valign="top" >TBD</td>
  3008. </tr>
  3009. <tr>
  3010. <td valign="top" >"saturation"</td>
  3011. <td valign="top" >RANGE</td>
  3012. <td valign="top" >Min=0, Max=0x7fff</td>
  3013. <td valign="top" >Plane</td>
  3014. <td valign="top" >TBD</td>
  3015. </tr>
  3016. <tr>
  3017. <td rowspan="2" valign="top" >exynos</td>
  3018. <td valign="top" >CRTC</td>
  3019. <td valign="top" >“mode”</td>
  3020. <td valign="top" >ENUM</td>
  3021. <td valign="top" >{ "normal", "blank" }</td>
  3022. <td valign="top" >CRTC</td>
  3023. <td valign="top" >TBD</td>
  3024. </tr>
  3025. <tr>
  3026. <td valign="top" >Overlay</td>
  3027. <td valign="top" >“zpos”</td>
  3028. <td valign="top" >RANGE</td>
  3029. <td valign="top" >Min=0, Max=MAX_PLANE-1</td>
  3030. <td valign="top" >Plane</td>
  3031. <td valign="top" >TBD</td>
  3032. </tr>
  3033. <tr>
  3034. <td rowspan="2" valign="top" >i2c/ch7006_drv</td>
  3035. <td valign="top" >Generic</td>
  3036. <td valign="top" >“scale”</td>
  3037. <td valign="top" >RANGE</td>
  3038. <td valign="top" >Min=0, Max=2</td>
  3039. <td valign="top" >Connector</td>
  3040. <td valign="top" >TBD</td>
  3041. </tr>
  3042. <tr>
  3043. <td rowspan="1" valign="top" >TV</td>
  3044. <td valign="top" >“mode”</td>
  3045. <td valign="top" >ENUM</td>
  3046. <td valign="top" >{ "PAL", "PAL-M","PAL-N"}, ”PAL-Nc"
  3047. , "PAL-60", "NTSC-M", "NTSC-J" }</td>
  3048. <td valign="top" >Connector</td>
  3049. <td valign="top" >TBD</td>
  3050. </tr>
  3051. <tr>
  3052. <td rowspan="15" valign="top" >nouveau</td>
  3053. <td rowspan="6" valign="top" >NV10 Overlay</td>
  3054. <td valign="top" >"colorkey"</td>
  3055. <td valign="top" >RANGE</td>
  3056. <td valign="top" >Min=0, Max=0x01ffffff</td>
  3057. <td valign="top" >Plane</td>
  3058. <td valign="top" >TBD</td>
  3059. </tr>
  3060. <tr>
  3061. <td valign="top" >“contrast”</td>
  3062. <td valign="top" >RANGE</td>
  3063. <td valign="top" >Min=0, Max=8192-1</td>
  3064. <td valign="top" >Plane</td>
  3065. <td valign="top" >TBD</td>
  3066. </tr>
  3067. <tr>
  3068. <td valign="top" >“brightness”</td>
  3069. <td valign="top" >RANGE</td>
  3070. <td valign="top" >Min=0, Max=1024</td>
  3071. <td valign="top" >Plane</td>
  3072. <td valign="top" >TBD</td>
  3073. </tr>
  3074. <tr>
  3075. <td valign="top" >“hue”</td>
  3076. <td valign="top" >RANGE</td>
  3077. <td valign="top" >Min=0, Max=359</td>
  3078. <td valign="top" >Plane</td>
  3079. <td valign="top" >TBD</td>
  3080. </tr>
  3081. <tr>
  3082. <td valign="top" >“saturation”</td>
  3083. <td valign="top" >RANGE</td>
  3084. <td valign="top" >Min=0, Max=8192-1</td>
  3085. <td valign="top" >Plane</td>
  3086. <td valign="top" >TBD</td>
  3087. </tr>
  3088. <tr>
  3089. <td valign="top" >“iturbt_709”</td>
  3090. <td valign="top" >RANGE</td>
  3091. <td valign="top" >Min=0, Max=1</td>
  3092. <td valign="top" >Plane</td>
  3093. <td valign="top" >TBD</td>
  3094. </tr>
  3095. <tr>
  3096. <td rowspan="2" valign="top" >Nv04 Overlay</td>
  3097. <td valign="top" >“colorkey”</td>
  3098. <td valign="top" >RANGE</td>
  3099. <td valign="top" >Min=0, Max=0x01ffffff</td>
  3100. <td valign="top" >Plane</td>
  3101. <td valign="top" >TBD</td>
  3102. </tr>
  3103. <tr>
  3104. <td valign="top" >“brightness”</td>
  3105. <td valign="top" >RANGE</td>
  3106. <td valign="top" >Min=0, Max=1024</td>
  3107. <td valign="top" >Plane</td>
  3108. <td valign="top" >TBD</td>
  3109. </tr>
  3110. <tr>
  3111. <td rowspan="7" valign="top" >Display</td>
  3112. <td valign="top" >“dithering mode”</td>
  3113. <td valign="top" >ENUM</td>
  3114. <td valign="top" >{ "auto", "off", "on" }</td>
  3115. <td valign="top" >Connector</td>
  3116. <td valign="top" >TBD</td>
  3117. </tr>
  3118. <tr>
  3119. <td valign="top" >“dithering depth”</td>
  3120. <td valign="top" >ENUM</td>
  3121. <td valign="top" >{ "auto", "off", "on", "static 2x2", "dynamic 2x2", "temporal" }</td>
  3122. <td valign="top" >Connector</td>
  3123. <td valign="top" >TBD</td>
  3124. </tr>
  3125. <tr>
  3126. <td valign="top" >“underscan”</td>
  3127. <td valign="top" >ENUM</td>
  3128. <td valign="top" >{ "auto", "6 bpc", "8 bpc" }</td>
  3129. <td valign="top" >Connector</td>
  3130. <td valign="top" >TBD</td>
  3131. </tr>
  3132. <tr>
  3133. <td valign="top" >“underscan hborder”</td>
  3134. <td valign="top" >RANGE</td>
  3135. <td valign="top" >Min=0, Max=128</td>
  3136. <td valign="top" >Connector</td>
  3137. <td valign="top" >TBD</td>
  3138. </tr>
  3139. <tr>
  3140. <td valign="top" >“underscan vborder”</td>
  3141. <td valign="top" >RANGE</td>
  3142. <td valign="top" >Min=0, Max=128</td>
  3143. <td valign="top" >Connector</td>
  3144. <td valign="top" >TBD</td>
  3145. </tr>
  3146. <tr>
  3147. <td valign="top" >“vibrant hue”</td>
  3148. <td valign="top" >RANGE</td>
  3149. <td valign="top" >Min=0, Max=180</td>
  3150. <td valign="top" >Connector</td>
  3151. <td valign="top" >TBD</td>
  3152. </tr>
  3153. <tr>
  3154. <td valign="top" >“color vibrance”</td>
  3155. <td valign="top" >RANGE</td>
  3156. <td valign="top" >Min=0, Max=200</td>
  3157. <td valign="top" >Connector</td>
  3158. <td valign="top" >TBD</td>
  3159. </tr>
  3160. <tr>
  3161. <td rowspan="2" valign="top" >omap</td>
  3162. <td rowspan="2" valign="top" >Generic</td>
  3163. <td valign="top" >“rotation”</td>
  3164. <td valign="top" >BITMASK</td>
  3165. <td valign="top" >{ 0, "rotate-0" },
  3166. { 1, "rotate-90" },
  3167. { 2, "rotate-180" },
  3168. { 3, "rotate-270" },
  3169. { 4, "reflect-x" },
  3170. { 5, "reflect-y" }</td>
  3171. <td valign="top" >CRTC, Plane</td>
  3172. <td valign="top" >TBD</td>
  3173. </tr>
  3174. <tr>
  3175. <td valign="top" >“zorder”</td>
  3176. <td valign="top" >RANGE</td>
  3177. <td valign="top" >Min=0, Max=3</td>
  3178. <td valign="top" >CRTC, Plane</td>
  3179. <td valign="top" >TBD</td>
  3180. </tr>
  3181. <tr>
  3182. <td valign="top" >qxl</td>
  3183. <td valign="top" >Generic</td>
  3184. <td valign="top" >“hotplug_mode_update"</td>
  3185. <td valign="top" >RANGE</td>
  3186. <td valign="top" >Min=0, Max=1</td>
  3187. <td valign="top" >Connector</td>
  3188. <td valign="top" >TBD</td>
  3189. </tr>
  3190. <tr>
  3191. <td rowspan="9" valign="top" >radeon</td>
  3192. <td valign="top" >DVI-I</td>
  3193. <td valign="top" >“coherent”</td>
  3194. <td valign="top" >RANGE</td>
  3195. <td valign="top" >Min=0, Max=1</td>
  3196. <td valign="top" >Connector</td>
  3197. <td valign="top" >TBD</td>
  3198. </tr>
  3199. <tr>
  3200. <td valign="top" >DAC enable load detect</td>
  3201. <td valign="top" >“load detection”</td>
  3202. <td valign="top" >RANGE</td>
  3203. <td valign="top" >Min=0, Max=1</td>
  3204. <td valign="top" >Connector</td>
  3205. <td valign="top" >TBD</td>
  3206. </tr>
  3207. <tr>
  3208. <td valign="top" >TV Standard</td>
  3209. <td valign="top" >"tv standard"</td>
  3210. <td valign="top" >ENUM</td>
  3211. <td valign="top" >{ "ntsc", "pal", "pal-m", "pal-60", "ntsc-j"
  3212. , "scart-pal", "pal-cn", "secam" }</td>
  3213. <td valign="top" >Connector</td>
  3214. <td valign="top" >TBD</td>
  3215. </tr>
  3216. <tr>
  3217. <td valign="top" >legacy TMDS PLL detect</td>
  3218. <td valign="top" >"tmds_pll"</td>
  3219. <td valign="top" >ENUM</td>
  3220. <td valign="top" >{ "driver", "bios" }</td>
  3221. <td valign="top" >-</td>
  3222. <td valign="top" >TBD</td>
  3223. </tr>
  3224. <tr>
  3225. <td rowspan="3" valign="top" >Underscan</td>
  3226. <td valign="top" >"underscan"</td>
  3227. <td valign="top" >ENUM</td>
  3228. <td valign="top" >{ "off", "on", "auto" }</td>
  3229. <td valign="top" >Connector</td>
  3230. <td valign="top" >TBD</td>
  3231. </tr>
  3232. <tr>
  3233. <td valign="top" >"underscan hborder"</td>
  3234. <td valign="top" >RANGE</td>
  3235. <td valign="top" >Min=0, Max=128</td>
  3236. <td valign="top" >Connector</td>
  3237. <td valign="top" >TBD</td>
  3238. </tr>
  3239. <tr>
  3240. <td valign="top" >"underscan vborder"</td>
  3241. <td valign="top" >RANGE</td>
  3242. <td valign="top" >Min=0, Max=128</td>
  3243. <td valign="top" >Connector</td>
  3244. <td valign="top" >TBD</td>
  3245. </tr>
  3246. <tr>
  3247. <td valign="top" >Audio</td>
  3248. <td valign="top" >“audio”</td>
  3249. <td valign="top" >ENUM</td>
  3250. <td valign="top" >{ "off", "on", "auto" }</td>
  3251. <td valign="top" >Connector</td>
  3252. <td valign="top" >TBD</td>
  3253. </tr>
  3254. <tr>
  3255. <td valign="top" >FMT Dithering</td>
  3256. <td valign="top" >“dither”</td>
  3257. <td valign="top" >ENUM</td>
  3258. <td valign="top" >{ "off", "on" }</td>
  3259. <td valign="top" >Connector</td>
  3260. <td valign="top" >TBD</td>
  3261. </tr>
  3262. <tr>
  3263. <td rowspan="3" valign="top" >rcar-du</td>
  3264. <td rowspan="3" valign="top" >Generic</td>
  3265. <td valign="top" >"alpha"</td>
  3266. <td valign="top" >RANGE</td>
  3267. <td valign="top" >Min=0, Max=255</td>
  3268. <td valign="top" >Plane</td>
  3269. <td valign="top" >TBD</td>
  3270. </tr>
  3271. <tr>
  3272. <td valign="top" >"colorkey"</td>
  3273. <td valign="top" >RANGE</td>
  3274. <td valign="top" >Min=0, Max=0x01ffffff</td>
  3275. <td valign="top" >Plane</td>
  3276. <td valign="top" >TBD</td>
  3277. </tr>
  3278. <tr>
  3279. <td valign="top" >"zpos"</td>
  3280. <td valign="top" >RANGE</td>
  3281. <td valign="top" >Min=1, Max=7</td>
  3282. <td valign="top" >Plane</td>
  3283. <td valign="top" >TBD</td>
  3284. </tr>
  3285. </tbody>
  3286. </table>
  3287. </sect2>
  3288. </sect1>
  3289. <!-- Internals: vertical blanking -->
  3290. <sect1 id="drm-vertical-blank">
  3291. <title>Vertical Blanking</title>
  3292. <para>
  3293. Vertical blanking plays a major role in graphics rendering. To achieve
  3294. tear-free display, users must synchronize page flips and/or rendering to
  3295. vertical blanking. The DRM API offers ioctls to perform page flips
  3296. synchronized to vertical blanking and wait for vertical blanking.
  3297. </para>
  3298. <para>
  3299. The DRM core handles most of the vertical blanking management logic, which
  3300. involves filtering out spurious interrupts, keeping race-free blanking
  3301. counters, coping with counter wrap-around and resets and keeping use
  3302. counts. It relies on the driver to generate vertical blanking interrupts
  3303. and optionally provide a hardware vertical blanking counter. Drivers must
  3304. implement the following operations.
  3305. </para>
  3306. <itemizedlist>
  3307. <listitem>
  3308. <synopsis>int (*enable_vblank) (struct drm_device *dev, int crtc);
  3309. void (*disable_vblank) (struct drm_device *dev, int crtc);</synopsis>
  3310. <para>
  3311. Enable or disable vertical blanking interrupts for the given CRTC.
  3312. </para>
  3313. </listitem>
  3314. <listitem>
  3315. <synopsis>u32 (*get_vblank_counter) (struct drm_device *dev, int crtc);</synopsis>
  3316. <para>
  3317. Retrieve the value of the vertical blanking counter for the given
  3318. CRTC. If the hardware maintains a vertical blanking counter its value
  3319. should be returned. Otherwise drivers can use the
  3320. <function>drm_vblank_count</function> helper function to handle this
  3321. operation.
  3322. </para>
  3323. </listitem>
  3324. </itemizedlist>
  3325. <para>
  3326. Drivers must initialize the vertical blanking handling core with a call to
  3327. <function>drm_vblank_init</function> in their
  3328. <methodname>load</methodname> operation. The function will set the struct
  3329. <structname>drm_device</structname>
  3330. <structfield>vblank_disable_allowed</structfield> field to 0. This will
  3331. keep vertical blanking interrupts enabled permanently until the first mode
  3332. set operation, where <structfield>vblank_disable_allowed</structfield> is
  3333. set to 1. The reason behind this is not clear. Drivers can set the field
  3334. to 1 after <function>calling drm_vblank_init</function> to make vertical
  3335. blanking interrupts dynamically managed from the beginning.
  3336. </para>
  3337. <para>
  3338. Vertical blanking interrupts can be enabled by the DRM core or by drivers
  3339. themselves (for instance to handle page flipping operations). The DRM core
  3340. maintains a vertical blanking use count to ensure that the interrupts are
  3341. not disabled while a user still needs them. To increment the use count,
  3342. drivers call <function>drm_vblank_get</function>. Upon return vertical
  3343. blanking interrupts are guaranteed to be enabled.
  3344. </para>
  3345. <para>
  3346. To decrement the use count drivers call
  3347. <function>drm_vblank_put</function>. Only when the use count drops to zero
  3348. will the DRM core disable the vertical blanking interrupts after a delay
  3349. by scheduling a timer. The delay is accessible through the vblankoffdelay
  3350. module parameter or the <varname>drm_vblank_offdelay</varname> global
  3351. variable and expressed in milliseconds. Its default value is 5000 ms.
  3352. Zero means never disable, and a negative value means disable immediately.
  3353. Drivers may override the behaviour by setting the
  3354. <structname>drm_device</structname>
  3355. <structfield>vblank_disable_immediate</structfield> flag, which when set
  3356. causes vblank interrupts to be disabled immediately regardless of the
  3357. drm_vblank_offdelay value. The flag should only be set if there's a
  3358. properly working hardware vblank counter present.
  3359. </para>
  3360. <para>
  3361. When a vertical blanking interrupt occurs drivers only need to call the
  3362. <function>drm_handle_vblank</function> function to account for the
  3363. interrupt.
  3364. </para>
  3365. <para>
  3366. Resources allocated by <function>drm_vblank_init</function> must be freed
  3367. with a call to <function>drm_vblank_cleanup</function> in the driver
  3368. <methodname>unload</methodname> operation handler.
  3369. </para>
  3370. <sect2>
  3371. <title>Vertical Blanking and Interrupt Handling Functions Reference</title>
  3372. !Edrivers/gpu/drm/drm_irq.c
  3373. !Finclude/drm/drmP.h drm_crtc_vblank_waitqueue
  3374. </sect2>
  3375. </sect1>
  3376. <!-- Internals: open/close, file operations and ioctls -->
  3377. <sect1>
  3378. <title>Open/Close, File Operations and IOCTLs</title>
  3379. <sect2>
  3380. <title>Open and Close</title>
  3381. <synopsis>int (*firstopen) (struct drm_device *);
  3382. void (*lastclose) (struct drm_device *);
  3383. int (*open) (struct drm_device *, struct drm_file *);
  3384. void (*preclose) (struct drm_device *, struct drm_file *);
  3385. void (*postclose) (struct drm_device *, struct drm_file *);</synopsis>
  3386. <abstract>Open and close handlers. None of those methods are mandatory.
  3387. </abstract>
  3388. <para>
  3389. The <methodname>firstopen</methodname> method is called by the DRM core
  3390. for legacy UMS (User Mode Setting) drivers only when an application
  3391. opens a device that has no other opened file handle. UMS drivers can
  3392. implement it to acquire device resources. KMS drivers can't use the
  3393. method and must acquire resources in the <methodname>load</methodname>
  3394. method instead.
  3395. </para>
  3396. <para>
  3397. Similarly the <methodname>lastclose</methodname> method is called when
  3398. the last application holding a file handle opened on the device closes
  3399. it, for both UMS and KMS drivers. Additionally, the method is also
  3400. called at module unload time or, for hot-pluggable devices, when the
  3401. device is unplugged. The <methodname>firstopen</methodname> and
  3402. <methodname>lastclose</methodname> calls can thus be unbalanced.
  3403. </para>
  3404. <para>
  3405. The <methodname>open</methodname> method is called every time the device
  3406. is opened by an application. Drivers can allocate per-file private data
  3407. in this method and store them in the struct
  3408. <structname>drm_file</structname> <structfield>driver_priv</structfield>
  3409. field. Note that the <methodname>open</methodname> method is called
  3410. before <methodname>firstopen</methodname>.
  3411. </para>
  3412. <para>
  3413. The close operation is split into <methodname>preclose</methodname> and
  3414. <methodname>postclose</methodname> methods. Drivers must stop and
  3415. cleanup all per-file operations in the <methodname>preclose</methodname>
  3416. method. For instance pending vertical blanking and page flip events must
  3417. be cancelled. No per-file operation is allowed on the file handle after
  3418. returning from the <methodname>preclose</methodname> method.
  3419. </para>
  3420. <para>
  3421. Finally the <methodname>postclose</methodname> method is called as the
  3422. last step of the close operation, right before calling the
  3423. <methodname>lastclose</methodname> method if no other open file handle
  3424. exists for the device. Drivers that have allocated per-file private data
  3425. in the <methodname>open</methodname> method should free it here.
  3426. </para>
  3427. <para>
  3428. The <methodname>lastclose</methodname> method should restore CRTC and
  3429. plane properties to default value, so that a subsequent open of the
  3430. device will not inherit state from the previous user. It can also be
  3431. used to execute delayed power switching state changes, e.g. in
  3432. conjunction with the vga-switcheroo infrastructure. Beyond that KMS
  3433. drivers should not do any further cleanup. Only legacy UMS drivers might
  3434. need to clean up device state so that the vga console or an independent
  3435. fbdev driver could take over.
  3436. </para>
  3437. </sect2>
  3438. <sect2>
  3439. <title>File Operations</title>
  3440. <synopsis>const struct file_operations *fops</synopsis>
  3441. <abstract>File operations for the DRM device node.</abstract>
  3442. <para>
  3443. Drivers must define the file operations structure that forms the DRM
  3444. userspace API entry point, even though most of those operations are
  3445. implemented in the DRM core. The <methodname>open</methodname>,
  3446. <methodname>release</methodname> and <methodname>ioctl</methodname>
  3447. operations are handled by
  3448. <programlisting>
  3449. .owner = THIS_MODULE,
  3450. .open = drm_open,
  3451. .release = drm_release,
  3452. .unlocked_ioctl = drm_ioctl,
  3453. #ifdef CONFIG_COMPAT
  3454. .compat_ioctl = drm_compat_ioctl,
  3455. #endif
  3456. </programlisting>
  3457. </para>
  3458. <para>
  3459. Drivers that implement private ioctls that requires 32/64bit
  3460. compatibility support must provide their own
  3461. <methodname>compat_ioctl</methodname> handler that processes private
  3462. ioctls and calls <function>drm_compat_ioctl</function> for core ioctls.
  3463. </para>
  3464. <para>
  3465. The <methodname>read</methodname> and <methodname>poll</methodname>
  3466. operations provide support for reading DRM events and polling them. They
  3467. are implemented by
  3468. <programlisting>
  3469. .poll = drm_poll,
  3470. .read = drm_read,
  3471. .llseek = no_llseek,
  3472. </programlisting>
  3473. </para>
  3474. <para>
  3475. The memory mapping implementation varies depending on how the driver
  3476. manages memory. Pre-GEM drivers will use <function>drm_mmap</function>,
  3477. while GEM-aware drivers will use <function>drm_gem_mmap</function>. See
  3478. <xref linkend="drm-gem"/>.
  3479. <programlisting>
  3480. .mmap = drm_gem_mmap,
  3481. </programlisting>
  3482. </para>
  3483. <para>
  3484. No other file operation is supported by the DRM API.
  3485. </para>
  3486. </sect2>
  3487. <sect2>
  3488. <title>IOCTLs</title>
  3489. <synopsis>struct drm_ioctl_desc *ioctls;
  3490. int num_ioctls;</synopsis>
  3491. <abstract>Driver-specific ioctls descriptors table.</abstract>
  3492. <para>
  3493. Driver-specific ioctls numbers start at DRM_COMMAND_BASE. The ioctls
  3494. descriptors table is indexed by the ioctl number offset from the base
  3495. value. Drivers can use the DRM_IOCTL_DEF_DRV() macro to initialize the
  3496. table entries.
  3497. </para>
  3498. <para>
  3499. <programlisting>DRM_IOCTL_DEF_DRV(ioctl, func, flags)</programlisting>
  3500. <para>
  3501. <parameter>ioctl</parameter> is the ioctl name. Drivers must define
  3502. the DRM_##ioctl and DRM_IOCTL_##ioctl macros to the ioctl number
  3503. offset from DRM_COMMAND_BASE and the ioctl number respectively. The
  3504. first macro is private to the device while the second must be exposed
  3505. to userspace in a public header.
  3506. </para>
  3507. <para>
  3508. <parameter>func</parameter> is a pointer to the ioctl handler function
  3509. compatible with the <type>drm_ioctl_t</type> type.
  3510. <programlisting>typedef int drm_ioctl_t(struct drm_device *dev, void *data,
  3511. struct drm_file *file_priv);</programlisting>
  3512. </para>
  3513. <para>
  3514. <parameter>flags</parameter> is a bitmask combination of the following
  3515. values. It restricts how the ioctl is allowed to be called.
  3516. <itemizedlist>
  3517. <listitem><para>
  3518. DRM_AUTH - Only authenticated callers allowed
  3519. </para></listitem>
  3520. <listitem><para>
  3521. DRM_MASTER - The ioctl can only be called on the master file
  3522. handle
  3523. </para></listitem>
  3524. <listitem><para>
  3525. DRM_ROOT_ONLY - Only callers with the SYSADMIN capability allowed
  3526. </para></listitem>
  3527. <listitem><para>
  3528. DRM_CONTROL_ALLOW - The ioctl can only be called on a control
  3529. device
  3530. </para></listitem>
  3531. <listitem><para>
  3532. DRM_UNLOCKED - The ioctl handler will be called without locking
  3533. the DRM global mutex
  3534. </para></listitem>
  3535. </itemizedlist>
  3536. </para>
  3537. </para>
  3538. </sect2>
  3539. </sect1>
  3540. <sect1>
  3541. <title>Legacy Support Code</title>
  3542. <para>
  3543. The section very briefly covers some of the old legacy support code which
  3544. is only used by old DRM drivers which have done a so-called shadow-attach
  3545. to the underlying device instead of registering as a real driver. This
  3546. also includes some of the old generic buffer management and command
  3547. submission code. Do not use any of this in new and modern drivers.
  3548. </para>
  3549. <sect2>
  3550. <title>Legacy Suspend/Resume</title>
  3551. <para>
  3552. The DRM core provides some suspend/resume code, but drivers wanting full
  3553. suspend/resume support should provide save() and restore() functions.
  3554. These are called at suspend, hibernate, or resume time, and should perform
  3555. any state save or restore required by your device across suspend or
  3556. hibernate states.
  3557. </para>
  3558. <synopsis>int (*suspend) (struct drm_device *, pm_message_t state);
  3559. int (*resume) (struct drm_device *);</synopsis>
  3560. <para>
  3561. Those are legacy suspend and resume methods which
  3562. <emphasis>only</emphasis> work with the legacy shadow-attach driver
  3563. registration functions. New driver should use the power management
  3564. interface provided by their bus type (usually through
  3565. the struct <structname>device_driver</structname> dev_pm_ops) and set
  3566. these methods to NULL.
  3567. </para>
  3568. </sect2>
  3569. <sect2>
  3570. <title>Legacy DMA Services</title>
  3571. <para>
  3572. This should cover how DMA mapping etc. is supported by the core.
  3573. These functions are deprecated and should not be used.
  3574. </para>
  3575. </sect2>
  3576. </sect1>
  3577. </chapter>
  3578. <!-- TODO
  3579. - Add a glossary
  3580. - Document the struct_mutex catch-all lock
  3581. - Document connector properties
  3582. - Why is the load method optional?
  3583. - What are drivers supposed to set the initial display state to, and how?
  3584. Connector's DPMS states are not initialized and are thus equal to
  3585. DRM_MODE_DPMS_ON. The fbcon compatibility layer calls
  3586. drm_helper_disable_unused_functions(), which disables unused encoders and
  3587. CRTCs, but doesn't touch the connectors' DPMS state, and
  3588. drm_helper_connector_dpms() in reaction to fbdev blanking events. Do drivers
  3589. that don't implement (or just don't use) fbcon compatibility need to call
  3590. those functions themselves?
  3591. - KMS drivers must call drm_vblank_pre_modeset() and drm_vblank_post_modeset()
  3592. around mode setting. Should this be done in the DRM core?
  3593. - vblank_disable_allowed is set to 1 in the first drm_vblank_post_modeset()
  3594. call and never set back to 0. It seems to be safe to permanently set it to 1
  3595. in drm_vblank_init() for KMS driver, and it might be safe for UMS drivers as
  3596. well. This should be investigated.
  3597. - crtc and connector .save and .restore operations are only used internally in
  3598. drivers, should they be removed from the core?
  3599. - encoder mid-layer .save and .restore operations are only used internally in
  3600. drivers, should they be removed from the core?
  3601. - encoder mid-layer .detect operation is only used internally in drivers,
  3602. should it be removed from the core?
  3603. -->
  3604. <!-- External interfaces -->
  3605. <chapter id="drmExternals">
  3606. <title>Userland interfaces</title>
  3607. <para>
  3608. The DRM core exports several interfaces to applications,
  3609. generally intended to be used through corresponding libdrm
  3610. wrapper functions. In addition, drivers export device-specific
  3611. interfaces for use by userspace drivers &amp; device-aware
  3612. applications through ioctls and sysfs files.
  3613. </para>
  3614. <para>
  3615. External interfaces include: memory mapping, context management,
  3616. DMA operations, AGP management, vblank control, fence
  3617. management, memory management, and output management.
  3618. </para>
  3619. <para>
  3620. Cover generic ioctls and sysfs layout here. We only need high-level
  3621. info, since man pages should cover the rest.
  3622. </para>
  3623. <!-- External: render nodes -->
  3624. <sect1>
  3625. <title>Render nodes</title>
  3626. <para>
  3627. DRM core provides multiple character-devices for user-space to use.
  3628. Depending on which device is opened, user-space can perform a different
  3629. set of operations (mainly ioctls). The primary node is always created
  3630. and called card&lt;num&gt;. Additionally, a currently
  3631. unused control node, called controlD&lt;num&gt; is also
  3632. created. The primary node provides all legacy operations and
  3633. historically was the only interface used by userspace. With KMS, the
  3634. control node was introduced. However, the planned KMS control interface
  3635. has never been written and so the control node stays unused to date.
  3636. </para>
  3637. <para>
  3638. With the increased use of offscreen renderers and GPGPU applications,
  3639. clients no longer require running compositors or graphics servers to
  3640. make use of a GPU. But the DRM API required unprivileged clients to
  3641. authenticate to a DRM-Master prior to getting GPU access. To avoid this
  3642. step and to grant clients GPU access without authenticating, render
  3643. nodes were introduced. Render nodes solely serve render clients, that
  3644. is, no modesetting or privileged ioctls can be issued on render nodes.
  3645. Only non-global rendering commands are allowed. If a driver supports
  3646. render nodes, it must advertise it via the DRIVER_RENDER
  3647. DRM driver capability. If not supported, the primary node must be used
  3648. for render clients together with the legacy drmAuth authentication
  3649. procedure.
  3650. </para>
  3651. <para>
  3652. If a driver advertises render node support, DRM core will create a
  3653. separate render node called renderD&lt;num&gt;. There will
  3654. be one render node per device. No ioctls except PRIME-related ioctls
  3655. will be allowed on this node. Especially GEM_OPEN will be
  3656. explicitly prohibited. Render nodes are designed to avoid the
  3657. buffer-leaks, which occur if clients guess the flink names or mmap
  3658. offsets on the legacy interface. Additionally to this basic interface,
  3659. drivers must mark their driver-dependent render-only ioctls as
  3660. DRM_RENDER_ALLOW so render clients can use them. Driver
  3661. authors must be careful not to allow any privileged ioctls on render
  3662. nodes.
  3663. </para>
  3664. <para>
  3665. With render nodes, user-space can now control access to the render node
  3666. via basic file-system access-modes. A running graphics server which
  3667. authenticates clients on the privileged primary/legacy node is no longer
  3668. required. Instead, a client can open the render node and is immediately
  3669. granted GPU access. Communication between clients (or servers) is done
  3670. via PRIME. FLINK from render node to legacy node is not supported. New
  3671. clients must not use the insecure FLINK interface.
  3672. </para>
  3673. <para>
  3674. Besides dropping all modeset/global ioctls, render nodes also drop the
  3675. DRM-Master concept. There is no reason to associate render clients with
  3676. a DRM-Master as they are independent of any graphics server. Besides,
  3677. they must work without any running master, anyway.
  3678. Drivers must be able to run without a master object if they support
  3679. render nodes. If, on the other hand, a driver requires shared state
  3680. between clients which is visible to user-space and accessible beyond
  3681. open-file boundaries, they cannot support render nodes.
  3682. </para>
  3683. </sect1>
  3684. <!-- External: vblank handling -->
  3685. <sect1>
  3686. <title>VBlank event handling</title>
  3687. <para>
  3688. The DRM core exposes two vertical blank related ioctls:
  3689. <variablelist>
  3690. <varlistentry>
  3691. <term>DRM_IOCTL_WAIT_VBLANK</term>
  3692. <listitem>
  3693. <para>
  3694. This takes a struct drm_wait_vblank structure as its argument,
  3695. and it is used to block or request a signal when a specified
  3696. vblank event occurs.
  3697. </para>
  3698. </listitem>
  3699. </varlistentry>
  3700. <varlistentry>
  3701. <term>DRM_IOCTL_MODESET_CTL</term>
  3702. <listitem>
  3703. <para>
  3704. This was only used for user-mode-settind drivers around
  3705. modesetting changes to allow the kernel to update the vblank
  3706. interrupt after mode setting, since on many devices the vertical
  3707. blank counter is reset to 0 at some point during modeset. Modern
  3708. drivers should not call this any more since with kernel mode
  3709. setting it is a no-op.
  3710. </para>
  3711. </listitem>
  3712. </varlistentry>
  3713. </variablelist>
  3714. </para>
  3715. </sect1>
  3716. </chapter>
  3717. </part>
  3718. <part id="drmDrivers">
  3719. <title>DRM Drivers</title>
  3720. <partintro>
  3721. <para>
  3722. This second part of the DRM Developer's Guide documents driver code,
  3723. implementation details and also all the driver-specific userspace
  3724. interfaces. Especially since all hardware-acceleration interfaces to
  3725. userspace are driver specific for efficiency and other reasons these
  3726. interfaces can be rather substantial. Hence every driver has its own
  3727. chapter.
  3728. </para>
  3729. </partintro>
  3730. <chapter id="drmI915">
  3731. <title>drm/i915 Intel GFX Driver</title>
  3732. <para>
  3733. The drm/i915 driver supports all (with the exception of some very early
  3734. models) integrated GFX chipsets with both Intel display and rendering
  3735. blocks. This excludes a set of SoC platforms with an SGX rendering unit,
  3736. those have basic support through the gma500 drm driver.
  3737. </para>
  3738. <sect1>
  3739. <title>Display Hardware Handling</title>
  3740. <para>
  3741. This section covers everything related to the display hardware including
  3742. the mode setting infrastructure, plane, sprite and cursor handling and
  3743. display, output probing and related topics.
  3744. </para>
  3745. <sect2>
  3746. <title>Mode Setting Infrastructure</title>
  3747. <para>
  3748. The i915 driver is thus far the only DRM driver which doesn't use the
  3749. common DRM helper code to implement mode setting sequences. Thus it
  3750. has its own tailor-made infrastructure for executing a display
  3751. configuration change.
  3752. </para>
  3753. </sect2>
  3754. <sect2>
  3755. <title>Plane Configuration</title>
  3756. <para>
  3757. This section covers plane configuration and composition with the
  3758. primary plane, sprites, cursors and overlays. This includes the
  3759. infrastructure to do atomic vsync'ed updates of all this state and
  3760. also tightly coupled topics like watermark setup and computation,
  3761. framebuffer compression and panel self refresh.
  3762. </para>
  3763. </sect2>
  3764. <sect2>
  3765. <title>Output Probing</title>
  3766. <para>
  3767. This section covers output probing and related infrastructure like the
  3768. hotplug interrupt storm detection and mitigation code. Note that the
  3769. i915 driver still uses most of the common DRM helper code for output
  3770. probing, so those sections fully apply.
  3771. </para>
  3772. </sect2>
  3773. <sect2>
  3774. <title>DPIO</title>
  3775. !Pdrivers/gpu/drm/i915/i915_reg.h DPIO
  3776. <table id="dpiox2">
  3777. <title>Dual channel PHY (VLV/CHV)</title>
  3778. <tgroup cols="8">
  3779. <colspec colname="c0" />
  3780. <colspec colname="c1" />
  3781. <colspec colname="c2" />
  3782. <colspec colname="c3" />
  3783. <colspec colname="c4" />
  3784. <colspec colname="c5" />
  3785. <colspec colname="c6" />
  3786. <colspec colname="c7" />
  3787. <spanspec spanname="ch0" namest="c0" nameend="c3" />
  3788. <spanspec spanname="ch1" namest="c4" nameend="c7" />
  3789. <spanspec spanname="ch0pcs01" namest="c0" nameend="c1" />
  3790. <spanspec spanname="ch0pcs23" namest="c2" nameend="c3" />
  3791. <spanspec spanname="ch1pcs01" namest="c4" nameend="c5" />
  3792. <spanspec spanname="ch1pcs23" namest="c6" nameend="c7" />
  3793. <thead>
  3794. <row>
  3795. <entry spanname="ch0">CH0</entry>
  3796. <entry spanname="ch1">CH1</entry>
  3797. </row>
  3798. </thead>
  3799. <tbody valign="top" align="center">
  3800. <row>
  3801. <entry spanname="ch0">CMN/PLL/REF</entry>
  3802. <entry spanname="ch1">CMN/PLL/REF</entry>
  3803. </row>
  3804. <row>
  3805. <entry spanname="ch0pcs01">PCS01</entry>
  3806. <entry spanname="ch0pcs23">PCS23</entry>
  3807. <entry spanname="ch1pcs01">PCS01</entry>
  3808. <entry spanname="ch1pcs23">PCS23</entry>
  3809. </row>
  3810. <row>
  3811. <entry>TX0</entry>
  3812. <entry>TX1</entry>
  3813. <entry>TX2</entry>
  3814. <entry>TX3</entry>
  3815. <entry>TX0</entry>
  3816. <entry>TX1</entry>
  3817. <entry>TX2</entry>
  3818. <entry>TX3</entry>
  3819. </row>
  3820. <row>
  3821. <entry spanname="ch0">DDI0</entry>
  3822. <entry spanname="ch1">DDI1</entry>
  3823. </row>
  3824. </tbody>
  3825. </tgroup>
  3826. </table>
  3827. <table id="dpiox1">
  3828. <title>Single channel PHY (CHV)</title>
  3829. <tgroup cols="4">
  3830. <colspec colname="c0" />
  3831. <colspec colname="c1" />
  3832. <colspec colname="c2" />
  3833. <colspec colname="c3" />
  3834. <spanspec spanname="ch0" namest="c0" nameend="c3" />
  3835. <spanspec spanname="ch0pcs01" namest="c0" nameend="c1" />
  3836. <spanspec spanname="ch0pcs23" namest="c2" nameend="c3" />
  3837. <thead>
  3838. <row>
  3839. <entry spanname="ch0">CH0</entry>
  3840. </row>
  3841. </thead>
  3842. <tbody valign="top" align="center">
  3843. <row>
  3844. <entry spanname="ch0">CMN/PLL/REF</entry>
  3845. </row>
  3846. <row>
  3847. <entry spanname="ch0pcs01">PCS01</entry>
  3848. <entry spanname="ch0pcs23">PCS23</entry>
  3849. </row>
  3850. <row>
  3851. <entry>TX0</entry>
  3852. <entry>TX1</entry>
  3853. <entry>TX2</entry>
  3854. <entry>TX3</entry>
  3855. </row>
  3856. <row>
  3857. <entry spanname="ch0">DDI2</entry>
  3858. </row>
  3859. </tbody>
  3860. </tgroup>
  3861. </table>
  3862. </sect2>
  3863. </sect1>
  3864. <sect1>
  3865. <title>Memory Management and Command Submission</title>
  3866. <para>
  3867. This sections covers all things related to the GEM implementation in the
  3868. i915 driver.
  3869. </para>
  3870. <sect2>
  3871. <title>Batchbuffer Parsing</title>
  3872. !Pdrivers/gpu/drm/i915/i915_cmd_parser.c batch buffer command parser
  3873. !Idrivers/gpu/drm/i915/i915_cmd_parser.c
  3874. </sect2>
  3875. <sect2>
  3876. <title>Logical Rings, Logical Ring Contexts and Execlists</title>
  3877. !Pdrivers/gpu/drm/i915/intel_lrc.c Logical Rings, Logical Ring Contexts and Execlists
  3878. !Idrivers/gpu/drm/i915/intel_lrc.c
  3879. </sect2>
  3880. </sect1>
  3881. </chapter>
  3882. </part>
  3883. </book>