r600.c 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <linux/slab.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/firmware.h>
  31. #include <linux/platform_device.h>
  32. #include "drmP.h"
  33. #include "radeon_drm.h"
  34. #include "radeon.h"
  35. #include "radeon_asic.h"
  36. #include "radeon_mode.h"
  37. #include "r600d.h"
  38. #include "atom.h"
  39. #include "avivod.h"
  40. #define PFP_UCODE_SIZE 576
  41. #define PM4_UCODE_SIZE 1792
  42. #define RLC_UCODE_SIZE 768
  43. #define R700_PFP_UCODE_SIZE 848
  44. #define R700_PM4_UCODE_SIZE 1360
  45. #define R700_RLC_UCODE_SIZE 1024
  46. #define EVERGREEN_PFP_UCODE_SIZE 1120
  47. #define EVERGREEN_PM4_UCODE_SIZE 1376
  48. #define EVERGREEN_RLC_UCODE_SIZE 768
  49. /* Firmware Names */
  50. MODULE_FIRMWARE("radeon/R600_pfp.bin");
  51. MODULE_FIRMWARE("radeon/R600_me.bin");
  52. MODULE_FIRMWARE("radeon/RV610_pfp.bin");
  53. MODULE_FIRMWARE("radeon/RV610_me.bin");
  54. MODULE_FIRMWARE("radeon/RV630_pfp.bin");
  55. MODULE_FIRMWARE("radeon/RV630_me.bin");
  56. MODULE_FIRMWARE("radeon/RV620_pfp.bin");
  57. MODULE_FIRMWARE("radeon/RV620_me.bin");
  58. MODULE_FIRMWARE("radeon/RV635_pfp.bin");
  59. MODULE_FIRMWARE("radeon/RV635_me.bin");
  60. MODULE_FIRMWARE("radeon/RV670_pfp.bin");
  61. MODULE_FIRMWARE("radeon/RV670_me.bin");
  62. MODULE_FIRMWARE("radeon/RS780_pfp.bin");
  63. MODULE_FIRMWARE("radeon/RS780_me.bin");
  64. MODULE_FIRMWARE("radeon/RV770_pfp.bin");
  65. MODULE_FIRMWARE("radeon/RV770_me.bin");
  66. MODULE_FIRMWARE("radeon/RV730_pfp.bin");
  67. MODULE_FIRMWARE("radeon/RV730_me.bin");
  68. MODULE_FIRMWARE("radeon/RV710_pfp.bin");
  69. MODULE_FIRMWARE("radeon/RV710_me.bin");
  70. MODULE_FIRMWARE("radeon/R600_rlc.bin");
  71. MODULE_FIRMWARE("radeon/R700_rlc.bin");
  72. MODULE_FIRMWARE("radeon/CEDAR_pfp.bin");
  73. MODULE_FIRMWARE("radeon/CEDAR_me.bin");
  74. MODULE_FIRMWARE("radeon/CEDAR_rlc.bin");
  75. MODULE_FIRMWARE("radeon/REDWOOD_pfp.bin");
  76. MODULE_FIRMWARE("radeon/REDWOOD_me.bin");
  77. MODULE_FIRMWARE("radeon/REDWOOD_rlc.bin");
  78. MODULE_FIRMWARE("radeon/JUNIPER_pfp.bin");
  79. MODULE_FIRMWARE("radeon/JUNIPER_me.bin");
  80. MODULE_FIRMWARE("radeon/JUNIPER_rlc.bin");
  81. MODULE_FIRMWARE("radeon/CYPRESS_pfp.bin");
  82. MODULE_FIRMWARE("radeon/CYPRESS_me.bin");
  83. MODULE_FIRMWARE("radeon/CYPRESS_rlc.bin");
  84. int r600_debugfs_mc_info_init(struct radeon_device *rdev);
  85. /* r600,rv610,rv630,rv620,rv635,rv670 */
  86. int r600_mc_wait_for_idle(struct radeon_device *rdev);
  87. void r600_gpu_init(struct radeon_device *rdev);
  88. void r600_fini(struct radeon_device *rdev);
  89. void r600_irq_disable(struct radeon_device *rdev);
  90. bool r600_gui_idle(struct radeon_device *rdev)
  91. {
  92. if (RREG32(GRBM_STATUS) & GUI_ACTIVE)
  93. return false;
  94. else
  95. return true;
  96. }
  97. /* hpd for digital panel detect/disconnect */
  98. bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  99. {
  100. bool connected = false;
  101. if (ASIC_IS_DCE3(rdev)) {
  102. switch (hpd) {
  103. case RADEON_HPD_1:
  104. if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
  105. connected = true;
  106. break;
  107. case RADEON_HPD_2:
  108. if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
  109. connected = true;
  110. break;
  111. case RADEON_HPD_3:
  112. if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
  113. connected = true;
  114. break;
  115. case RADEON_HPD_4:
  116. if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
  117. connected = true;
  118. break;
  119. /* DCE 3.2 */
  120. case RADEON_HPD_5:
  121. if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
  122. connected = true;
  123. break;
  124. case RADEON_HPD_6:
  125. if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
  126. connected = true;
  127. break;
  128. default:
  129. break;
  130. }
  131. } else {
  132. switch (hpd) {
  133. case RADEON_HPD_1:
  134. if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  135. connected = true;
  136. break;
  137. case RADEON_HPD_2:
  138. if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  139. connected = true;
  140. break;
  141. case RADEON_HPD_3:
  142. if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  143. connected = true;
  144. break;
  145. default:
  146. break;
  147. }
  148. }
  149. return connected;
  150. }
  151. void r600_hpd_set_polarity(struct radeon_device *rdev,
  152. enum radeon_hpd_id hpd)
  153. {
  154. u32 tmp;
  155. bool connected = r600_hpd_sense(rdev, hpd);
  156. if (ASIC_IS_DCE3(rdev)) {
  157. switch (hpd) {
  158. case RADEON_HPD_1:
  159. tmp = RREG32(DC_HPD1_INT_CONTROL);
  160. if (connected)
  161. tmp &= ~DC_HPDx_INT_POLARITY;
  162. else
  163. tmp |= DC_HPDx_INT_POLARITY;
  164. WREG32(DC_HPD1_INT_CONTROL, tmp);
  165. break;
  166. case RADEON_HPD_2:
  167. tmp = RREG32(DC_HPD2_INT_CONTROL);
  168. if (connected)
  169. tmp &= ~DC_HPDx_INT_POLARITY;
  170. else
  171. tmp |= DC_HPDx_INT_POLARITY;
  172. WREG32(DC_HPD2_INT_CONTROL, tmp);
  173. break;
  174. case RADEON_HPD_3:
  175. tmp = RREG32(DC_HPD3_INT_CONTROL);
  176. if (connected)
  177. tmp &= ~DC_HPDx_INT_POLARITY;
  178. else
  179. tmp |= DC_HPDx_INT_POLARITY;
  180. WREG32(DC_HPD3_INT_CONTROL, tmp);
  181. break;
  182. case RADEON_HPD_4:
  183. tmp = RREG32(DC_HPD4_INT_CONTROL);
  184. if (connected)
  185. tmp &= ~DC_HPDx_INT_POLARITY;
  186. else
  187. tmp |= DC_HPDx_INT_POLARITY;
  188. WREG32(DC_HPD4_INT_CONTROL, tmp);
  189. break;
  190. case RADEON_HPD_5:
  191. tmp = RREG32(DC_HPD5_INT_CONTROL);
  192. if (connected)
  193. tmp &= ~DC_HPDx_INT_POLARITY;
  194. else
  195. tmp |= DC_HPDx_INT_POLARITY;
  196. WREG32(DC_HPD5_INT_CONTROL, tmp);
  197. break;
  198. /* DCE 3.2 */
  199. case RADEON_HPD_6:
  200. tmp = RREG32(DC_HPD6_INT_CONTROL);
  201. if (connected)
  202. tmp &= ~DC_HPDx_INT_POLARITY;
  203. else
  204. tmp |= DC_HPDx_INT_POLARITY;
  205. WREG32(DC_HPD6_INT_CONTROL, tmp);
  206. break;
  207. default:
  208. break;
  209. }
  210. } else {
  211. switch (hpd) {
  212. case RADEON_HPD_1:
  213. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
  214. if (connected)
  215. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  216. else
  217. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  218. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  219. break;
  220. case RADEON_HPD_2:
  221. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
  222. if (connected)
  223. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  224. else
  225. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  226. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  227. break;
  228. case RADEON_HPD_3:
  229. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
  230. if (connected)
  231. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  232. else
  233. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  234. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  235. break;
  236. default:
  237. break;
  238. }
  239. }
  240. }
  241. void r600_hpd_init(struct radeon_device *rdev)
  242. {
  243. struct drm_device *dev = rdev->ddev;
  244. struct drm_connector *connector;
  245. if (ASIC_IS_DCE3(rdev)) {
  246. u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
  247. if (ASIC_IS_DCE32(rdev))
  248. tmp |= DC_HPDx_EN;
  249. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  250. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  251. switch (radeon_connector->hpd.hpd) {
  252. case RADEON_HPD_1:
  253. WREG32(DC_HPD1_CONTROL, tmp);
  254. rdev->irq.hpd[0] = true;
  255. break;
  256. case RADEON_HPD_2:
  257. WREG32(DC_HPD2_CONTROL, tmp);
  258. rdev->irq.hpd[1] = true;
  259. break;
  260. case RADEON_HPD_3:
  261. WREG32(DC_HPD3_CONTROL, tmp);
  262. rdev->irq.hpd[2] = true;
  263. break;
  264. case RADEON_HPD_4:
  265. WREG32(DC_HPD4_CONTROL, tmp);
  266. rdev->irq.hpd[3] = true;
  267. break;
  268. /* DCE 3.2 */
  269. case RADEON_HPD_5:
  270. WREG32(DC_HPD5_CONTROL, tmp);
  271. rdev->irq.hpd[4] = true;
  272. break;
  273. case RADEON_HPD_6:
  274. WREG32(DC_HPD6_CONTROL, tmp);
  275. rdev->irq.hpd[5] = true;
  276. break;
  277. default:
  278. break;
  279. }
  280. }
  281. } else {
  282. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  283. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  284. switch (radeon_connector->hpd.hpd) {
  285. case RADEON_HPD_1:
  286. WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  287. rdev->irq.hpd[0] = true;
  288. break;
  289. case RADEON_HPD_2:
  290. WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  291. rdev->irq.hpd[1] = true;
  292. break;
  293. case RADEON_HPD_3:
  294. WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  295. rdev->irq.hpd[2] = true;
  296. break;
  297. default:
  298. break;
  299. }
  300. }
  301. }
  302. if (rdev->irq.installed)
  303. r600_irq_set(rdev);
  304. }
  305. void r600_hpd_fini(struct radeon_device *rdev)
  306. {
  307. struct drm_device *dev = rdev->ddev;
  308. struct drm_connector *connector;
  309. if (ASIC_IS_DCE3(rdev)) {
  310. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  311. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  312. switch (radeon_connector->hpd.hpd) {
  313. case RADEON_HPD_1:
  314. WREG32(DC_HPD1_CONTROL, 0);
  315. rdev->irq.hpd[0] = false;
  316. break;
  317. case RADEON_HPD_2:
  318. WREG32(DC_HPD2_CONTROL, 0);
  319. rdev->irq.hpd[1] = false;
  320. break;
  321. case RADEON_HPD_3:
  322. WREG32(DC_HPD3_CONTROL, 0);
  323. rdev->irq.hpd[2] = false;
  324. break;
  325. case RADEON_HPD_4:
  326. WREG32(DC_HPD4_CONTROL, 0);
  327. rdev->irq.hpd[3] = false;
  328. break;
  329. /* DCE 3.2 */
  330. case RADEON_HPD_5:
  331. WREG32(DC_HPD5_CONTROL, 0);
  332. rdev->irq.hpd[4] = false;
  333. break;
  334. case RADEON_HPD_6:
  335. WREG32(DC_HPD6_CONTROL, 0);
  336. rdev->irq.hpd[5] = false;
  337. break;
  338. default:
  339. break;
  340. }
  341. }
  342. } else {
  343. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  344. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  345. switch (radeon_connector->hpd.hpd) {
  346. case RADEON_HPD_1:
  347. WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
  348. rdev->irq.hpd[0] = false;
  349. break;
  350. case RADEON_HPD_2:
  351. WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
  352. rdev->irq.hpd[1] = false;
  353. break;
  354. case RADEON_HPD_3:
  355. WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
  356. rdev->irq.hpd[2] = false;
  357. break;
  358. default:
  359. break;
  360. }
  361. }
  362. }
  363. }
  364. /*
  365. * R600 PCIE GART
  366. */
  367. void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
  368. {
  369. unsigned i;
  370. u32 tmp;
  371. /* flush hdp cache so updates hit vram */
  372. WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  373. WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
  374. WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
  375. WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
  376. for (i = 0; i < rdev->usec_timeout; i++) {
  377. /* read MC_STATUS */
  378. tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
  379. tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
  380. if (tmp == 2) {
  381. printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
  382. return;
  383. }
  384. if (tmp) {
  385. return;
  386. }
  387. udelay(1);
  388. }
  389. }
  390. int r600_pcie_gart_init(struct radeon_device *rdev)
  391. {
  392. int r;
  393. if (rdev->gart.table.vram.robj) {
  394. WARN(1, "R600 PCIE GART already initialized.\n");
  395. return 0;
  396. }
  397. /* Initialize common gart structure */
  398. r = radeon_gart_init(rdev);
  399. if (r)
  400. return r;
  401. rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
  402. return radeon_gart_table_vram_alloc(rdev);
  403. }
  404. int r600_pcie_gart_enable(struct radeon_device *rdev)
  405. {
  406. u32 tmp;
  407. int r, i;
  408. if (rdev->gart.table.vram.robj == NULL) {
  409. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  410. return -EINVAL;
  411. }
  412. r = radeon_gart_table_vram_pin(rdev);
  413. if (r)
  414. return r;
  415. radeon_gart_restore(rdev);
  416. /* Setup L2 cache */
  417. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  418. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  419. EFFECTIVE_L2_QUEUE_SIZE(7));
  420. WREG32(VM_L2_CNTL2, 0);
  421. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  422. /* Setup TLB control */
  423. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  424. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  425. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  426. ENABLE_WAIT_L2_QUERY;
  427. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  428. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  429. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
  430. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  431. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  432. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  433. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  434. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  435. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  436. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  437. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  438. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  439. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  440. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  441. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  442. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  443. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  444. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  445. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  446. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  447. (u32)(rdev->dummy_page.addr >> 12));
  448. for (i = 1; i < 7; i++)
  449. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  450. r600_pcie_gart_tlb_flush(rdev);
  451. rdev->gart.ready = true;
  452. return 0;
  453. }
  454. void r600_pcie_gart_disable(struct radeon_device *rdev)
  455. {
  456. u32 tmp;
  457. int i, r;
  458. /* Disable all tables */
  459. for (i = 0; i < 7; i++)
  460. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  461. /* Disable L2 cache */
  462. WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
  463. EFFECTIVE_L2_QUEUE_SIZE(7));
  464. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  465. /* Setup L1 TLB control */
  466. tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  467. ENABLE_WAIT_L2_QUERY;
  468. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  469. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  470. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  471. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  472. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  473. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  474. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  475. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  476. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
  477. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
  478. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  479. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  480. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
  481. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  482. if (rdev->gart.table.vram.robj) {
  483. r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
  484. if (likely(r == 0)) {
  485. radeon_bo_kunmap(rdev->gart.table.vram.robj);
  486. radeon_bo_unpin(rdev->gart.table.vram.robj);
  487. radeon_bo_unreserve(rdev->gart.table.vram.robj);
  488. }
  489. }
  490. }
  491. void r600_pcie_gart_fini(struct radeon_device *rdev)
  492. {
  493. radeon_gart_fini(rdev);
  494. r600_pcie_gart_disable(rdev);
  495. radeon_gart_table_vram_free(rdev);
  496. }
  497. void r600_agp_enable(struct radeon_device *rdev)
  498. {
  499. u32 tmp;
  500. int i;
  501. /* Setup L2 cache */
  502. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  503. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  504. EFFECTIVE_L2_QUEUE_SIZE(7));
  505. WREG32(VM_L2_CNTL2, 0);
  506. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  507. /* Setup TLB control */
  508. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  509. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  510. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  511. ENABLE_WAIT_L2_QUERY;
  512. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  513. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  514. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
  515. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  516. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  517. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  518. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  519. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  520. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  521. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  522. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  523. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  524. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  525. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  526. for (i = 0; i < 7; i++)
  527. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  528. }
  529. int r600_mc_wait_for_idle(struct radeon_device *rdev)
  530. {
  531. unsigned i;
  532. u32 tmp;
  533. for (i = 0; i < rdev->usec_timeout; i++) {
  534. /* read MC_STATUS */
  535. tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
  536. if (!tmp)
  537. return 0;
  538. udelay(1);
  539. }
  540. return -1;
  541. }
  542. static void r600_mc_program(struct radeon_device *rdev)
  543. {
  544. struct rv515_mc_save save;
  545. u32 tmp;
  546. int i, j;
  547. /* Initialize HDP */
  548. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  549. WREG32((0x2c14 + j), 0x00000000);
  550. WREG32((0x2c18 + j), 0x00000000);
  551. WREG32((0x2c1c + j), 0x00000000);
  552. WREG32((0x2c20 + j), 0x00000000);
  553. WREG32((0x2c24 + j), 0x00000000);
  554. }
  555. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  556. rv515_mc_stop(rdev, &save);
  557. if (r600_mc_wait_for_idle(rdev)) {
  558. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  559. }
  560. /* Lockout access through VGA aperture (doesn't exist before R600) */
  561. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  562. /* Update configuration */
  563. if (rdev->flags & RADEON_IS_AGP) {
  564. if (rdev->mc.vram_start < rdev->mc.gtt_start) {
  565. /* VRAM before AGP */
  566. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  567. rdev->mc.vram_start >> 12);
  568. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  569. rdev->mc.gtt_end >> 12);
  570. } else {
  571. /* VRAM after AGP */
  572. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  573. rdev->mc.gtt_start >> 12);
  574. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  575. rdev->mc.vram_end >> 12);
  576. }
  577. } else {
  578. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
  579. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
  580. }
  581. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0);
  582. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  583. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  584. WREG32(MC_VM_FB_LOCATION, tmp);
  585. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  586. WREG32(HDP_NONSURFACE_INFO, (2 << 7));
  587. WREG32(HDP_NONSURFACE_SIZE, rdev->mc.mc_vram_size | 0x3FF);
  588. if (rdev->flags & RADEON_IS_AGP) {
  589. WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
  590. WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
  591. WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
  592. } else {
  593. WREG32(MC_VM_AGP_BASE, 0);
  594. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  595. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  596. }
  597. if (r600_mc_wait_for_idle(rdev)) {
  598. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  599. }
  600. rv515_mc_resume(rdev, &save);
  601. /* we need to own VRAM, so turn off the VGA renderer here
  602. * to stop it overwriting our objects */
  603. rv515_vga_render_disable(rdev);
  604. }
  605. /**
  606. * r600_vram_gtt_location - try to find VRAM & GTT location
  607. * @rdev: radeon device structure holding all necessary informations
  608. * @mc: memory controller structure holding memory informations
  609. *
  610. * Function will place try to place VRAM at same place as in CPU (PCI)
  611. * address space as some GPU seems to have issue when we reprogram at
  612. * different address space.
  613. *
  614. * If there is not enough space to fit the unvisible VRAM after the
  615. * aperture then we limit the VRAM size to the aperture.
  616. *
  617. * If we are using AGP then place VRAM adjacent to AGP aperture are we need
  618. * them to be in one from GPU point of view so that we can program GPU to
  619. * catch access outside them (weird GPU policy see ??).
  620. *
  621. * This function will never fails, worst case are limiting VRAM or GTT.
  622. *
  623. * Note: GTT start, end, size should be initialized before calling this
  624. * function on AGP platform.
  625. */
  626. void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
  627. {
  628. u64 size_bf, size_af;
  629. if (mc->mc_vram_size > 0xE0000000) {
  630. /* leave room for at least 512M GTT */
  631. dev_warn(rdev->dev, "limiting VRAM\n");
  632. mc->real_vram_size = 0xE0000000;
  633. mc->mc_vram_size = 0xE0000000;
  634. }
  635. if (rdev->flags & RADEON_IS_AGP) {
  636. size_bf = mc->gtt_start;
  637. size_af = 0xFFFFFFFF - mc->gtt_end + 1;
  638. if (size_bf > size_af) {
  639. if (mc->mc_vram_size > size_bf) {
  640. dev_warn(rdev->dev, "limiting VRAM\n");
  641. mc->real_vram_size = size_bf;
  642. mc->mc_vram_size = size_bf;
  643. }
  644. mc->vram_start = mc->gtt_start - mc->mc_vram_size;
  645. } else {
  646. if (mc->mc_vram_size > size_af) {
  647. dev_warn(rdev->dev, "limiting VRAM\n");
  648. mc->real_vram_size = size_af;
  649. mc->mc_vram_size = size_af;
  650. }
  651. mc->vram_start = mc->gtt_end;
  652. }
  653. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  654. dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
  655. mc->mc_vram_size >> 20, mc->vram_start,
  656. mc->vram_end, mc->real_vram_size >> 20);
  657. } else {
  658. u64 base = 0;
  659. if (rdev->flags & RADEON_IS_IGP)
  660. base = (RREG32(MC_VM_FB_LOCATION) & 0xFFFF) << 24;
  661. radeon_vram_location(rdev, &rdev->mc, base);
  662. radeon_gtt_location(rdev, mc);
  663. }
  664. }
  665. int r600_mc_init(struct radeon_device *rdev)
  666. {
  667. u32 tmp;
  668. int chansize, numchan;
  669. /* Get VRAM informations */
  670. rdev->mc.vram_is_ddr = true;
  671. tmp = RREG32(RAMCFG);
  672. if (tmp & CHANSIZE_OVERRIDE) {
  673. chansize = 16;
  674. } else if (tmp & CHANSIZE_MASK) {
  675. chansize = 64;
  676. } else {
  677. chansize = 32;
  678. }
  679. tmp = RREG32(CHMAP);
  680. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  681. case 0:
  682. default:
  683. numchan = 1;
  684. break;
  685. case 1:
  686. numchan = 2;
  687. break;
  688. case 2:
  689. numchan = 4;
  690. break;
  691. case 3:
  692. numchan = 8;
  693. break;
  694. }
  695. rdev->mc.vram_width = numchan * chansize;
  696. /* Could aper size report 0 ? */
  697. rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
  698. rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
  699. /* Setup GPU memory space */
  700. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
  701. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
  702. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  703. r600_vram_gtt_location(rdev, &rdev->mc);
  704. if (rdev->flags & RADEON_IS_IGP)
  705. rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
  706. radeon_update_bandwidth_info(rdev);
  707. return 0;
  708. }
  709. /* We doesn't check that the GPU really needs a reset we simply do the
  710. * reset, it's up to the caller to determine if the GPU needs one. We
  711. * might add an helper function to check that.
  712. */
  713. int r600_gpu_soft_reset(struct radeon_device *rdev)
  714. {
  715. struct rv515_mc_save save;
  716. u32 grbm_busy_mask = S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
  717. S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
  718. S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
  719. S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
  720. S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
  721. S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
  722. S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
  723. S_008010_GUI_ACTIVE(1);
  724. u32 grbm2_busy_mask = S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
  725. S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
  726. S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
  727. S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
  728. S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
  729. S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
  730. S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
  731. S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
  732. u32 tmp;
  733. dev_info(rdev->dev, "GPU softreset \n");
  734. dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
  735. RREG32(R_008010_GRBM_STATUS));
  736. dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
  737. RREG32(R_008014_GRBM_STATUS2));
  738. dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
  739. RREG32(R_000E50_SRBM_STATUS));
  740. rv515_mc_stop(rdev, &save);
  741. if (r600_mc_wait_for_idle(rdev)) {
  742. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  743. }
  744. /* Disable CP parsing/prefetching */
  745. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
  746. /* Check if any of the rendering block is busy and reset it */
  747. if ((RREG32(R_008010_GRBM_STATUS) & grbm_busy_mask) ||
  748. (RREG32(R_008014_GRBM_STATUS2) & grbm2_busy_mask)) {
  749. tmp = S_008020_SOFT_RESET_CR(1) |
  750. S_008020_SOFT_RESET_DB(1) |
  751. S_008020_SOFT_RESET_CB(1) |
  752. S_008020_SOFT_RESET_PA(1) |
  753. S_008020_SOFT_RESET_SC(1) |
  754. S_008020_SOFT_RESET_SMX(1) |
  755. S_008020_SOFT_RESET_SPI(1) |
  756. S_008020_SOFT_RESET_SX(1) |
  757. S_008020_SOFT_RESET_SH(1) |
  758. S_008020_SOFT_RESET_TC(1) |
  759. S_008020_SOFT_RESET_TA(1) |
  760. S_008020_SOFT_RESET_VC(1) |
  761. S_008020_SOFT_RESET_VGT(1);
  762. dev_info(rdev->dev, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
  763. WREG32(R_008020_GRBM_SOFT_RESET, tmp);
  764. RREG32(R_008020_GRBM_SOFT_RESET);
  765. mdelay(15);
  766. WREG32(R_008020_GRBM_SOFT_RESET, 0);
  767. }
  768. /* Reset CP (we always reset CP) */
  769. tmp = S_008020_SOFT_RESET_CP(1);
  770. dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
  771. WREG32(R_008020_GRBM_SOFT_RESET, tmp);
  772. RREG32(R_008020_GRBM_SOFT_RESET);
  773. mdelay(15);
  774. WREG32(R_008020_GRBM_SOFT_RESET, 0);
  775. /* Wait a little for things to settle down */
  776. mdelay(1);
  777. dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
  778. RREG32(R_008010_GRBM_STATUS));
  779. dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
  780. RREG32(R_008014_GRBM_STATUS2));
  781. dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
  782. RREG32(R_000E50_SRBM_STATUS));
  783. rv515_mc_resume(rdev, &save);
  784. return 0;
  785. }
  786. bool r600_gpu_is_lockup(struct radeon_device *rdev)
  787. {
  788. u32 srbm_status;
  789. u32 grbm_status;
  790. u32 grbm_status2;
  791. int r;
  792. srbm_status = RREG32(R_000E50_SRBM_STATUS);
  793. grbm_status = RREG32(R_008010_GRBM_STATUS);
  794. grbm_status2 = RREG32(R_008014_GRBM_STATUS2);
  795. if (!G_008010_GUI_ACTIVE(grbm_status)) {
  796. r100_gpu_lockup_update(&rdev->config.r300.lockup, &rdev->cp);
  797. return false;
  798. }
  799. /* force CP activities */
  800. r = radeon_ring_lock(rdev, 2);
  801. if (!r) {
  802. /* PACKET2 NOP */
  803. radeon_ring_write(rdev, 0x80000000);
  804. radeon_ring_write(rdev, 0x80000000);
  805. radeon_ring_unlock_commit(rdev);
  806. }
  807. rdev->cp.rptr = RREG32(R600_CP_RB_RPTR);
  808. return r100_gpu_cp_is_lockup(rdev, &rdev->config.r300.lockup, &rdev->cp);
  809. }
  810. int r600_asic_reset(struct radeon_device *rdev)
  811. {
  812. return r600_gpu_soft_reset(rdev);
  813. }
  814. static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes,
  815. u32 num_backends,
  816. u32 backend_disable_mask)
  817. {
  818. u32 backend_map = 0;
  819. u32 enabled_backends_mask;
  820. u32 enabled_backends_count;
  821. u32 cur_pipe;
  822. u32 swizzle_pipe[R6XX_MAX_PIPES];
  823. u32 cur_backend;
  824. u32 i;
  825. if (num_tile_pipes > R6XX_MAX_PIPES)
  826. num_tile_pipes = R6XX_MAX_PIPES;
  827. if (num_tile_pipes < 1)
  828. num_tile_pipes = 1;
  829. if (num_backends > R6XX_MAX_BACKENDS)
  830. num_backends = R6XX_MAX_BACKENDS;
  831. if (num_backends < 1)
  832. num_backends = 1;
  833. enabled_backends_mask = 0;
  834. enabled_backends_count = 0;
  835. for (i = 0; i < R6XX_MAX_BACKENDS; ++i) {
  836. if (((backend_disable_mask >> i) & 1) == 0) {
  837. enabled_backends_mask |= (1 << i);
  838. ++enabled_backends_count;
  839. }
  840. if (enabled_backends_count == num_backends)
  841. break;
  842. }
  843. if (enabled_backends_count == 0) {
  844. enabled_backends_mask = 1;
  845. enabled_backends_count = 1;
  846. }
  847. if (enabled_backends_count != num_backends)
  848. num_backends = enabled_backends_count;
  849. memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
  850. switch (num_tile_pipes) {
  851. case 1:
  852. swizzle_pipe[0] = 0;
  853. break;
  854. case 2:
  855. swizzle_pipe[0] = 0;
  856. swizzle_pipe[1] = 1;
  857. break;
  858. case 3:
  859. swizzle_pipe[0] = 0;
  860. swizzle_pipe[1] = 1;
  861. swizzle_pipe[2] = 2;
  862. break;
  863. case 4:
  864. swizzle_pipe[0] = 0;
  865. swizzle_pipe[1] = 1;
  866. swizzle_pipe[2] = 2;
  867. swizzle_pipe[3] = 3;
  868. break;
  869. case 5:
  870. swizzle_pipe[0] = 0;
  871. swizzle_pipe[1] = 1;
  872. swizzle_pipe[2] = 2;
  873. swizzle_pipe[3] = 3;
  874. swizzle_pipe[4] = 4;
  875. break;
  876. case 6:
  877. swizzle_pipe[0] = 0;
  878. swizzle_pipe[1] = 2;
  879. swizzle_pipe[2] = 4;
  880. swizzle_pipe[3] = 5;
  881. swizzle_pipe[4] = 1;
  882. swizzle_pipe[5] = 3;
  883. break;
  884. case 7:
  885. swizzle_pipe[0] = 0;
  886. swizzle_pipe[1] = 2;
  887. swizzle_pipe[2] = 4;
  888. swizzle_pipe[3] = 6;
  889. swizzle_pipe[4] = 1;
  890. swizzle_pipe[5] = 3;
  891. swizzle_pipe[6] = 5;
  892. break;
  893. case 8:
  894. swizzle_pipe[0] = 0;
  895. swizzle_pipe[1] = 2;
  896. swizzle_pipe[2] = 4;
  897. swizzle_pipe[3] = 6;
  898. swizzle_pipe[4] = 1;
  899. swizzle_pipe[5] = 3;
  900. swizzle_pipe[6] = 5;
  901. swizzle_pipe[7] = 7;
  902. break;
  903. }
  904. cur_backend = 0;
  905. for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
  906. while (((1 << cur_backend) & enabled_backends_mask) == 0)
  907. cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
  908. backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
  909. cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
  910. }
  911. return backend_map;
  912. }
  913. int r600_count_pipe_bits(uint32_t val)
  914. {
  915. int i, ret = 0;
  916. for (i = 0; i < 32; i++) {
  917. ret += val & 1;
  918. val >>= 1;
  919. }
  920. return ret;
  921. }
  922. void r600_gpu_init(struct radeon_device *rdev)
  923. {
  924. u32 tiling_config;
  925. u32 ramcfg;
  926. u32 backend_map;
  927. u32 cc_rb_backend_disable;
  928. u32 cc_gc_shader_pipe_config;
  929. u32 tmp;
  930. int i, j;
  931. u32 sq_config;
  932. u32 sq_gpr_resource_mgmt_1 = 0;
  933. u32 sq_gpr_resource_mgmt_2 = 0;
  934. u32 sq_thread_resource_mgmt = 0;
  935. u32 sq_stack_resource_mgmt_1 = 0;
  936. u32 sq_stack_resource_mgmt_2 = 0;
  937. /* FIXME: implement */
  938. switch (rdev->family) {
  939. case CHIP_R600:
  940. rdev->config.r600.max_pipes = 4;
  941. rdev->config.r600.max_tile_pipes = 8;
  942. rdev->config.r600.max_simds = 4;
  943. rdev->config.r600.max_backends = 4;
  944. rdev->config.r600.max_gprs = 256;
  945. rdev->config.r600.max_threads = 192;
  946. rdev->config.r600.max_stack_entries = 256;
  947. rdev->config.r600.max_hw_contexts = 8;
  948. rdev->config.r600.max_gs_threads = 16;
  949. rdev->config.r600.sx_max_export_size = 128;
  950. rdev->config.r600.sx_max_export_pos_size = 16;
  951. rdev->config.r600.sx_max_export_smx_size = 128;
  952. rdev->config.r600.sq_num_cf_insts = 2;
  953. break;
  954. case CHIP_RV630:
  955. case CHIP_RV635:
  956. rdev->config.r600.max_pipes = 2;
  957. rdev->config.r600.max_tile_pipes = 2;
  958. rdev->config.r600.max_simds = 3;
  959. rdev->config.r600.max_backends = 1;
  960. rdev->config.r600.max_gprs = 128;
  961. rdev->config.r600.max_threads = 192;
  962. rdev->config.r600.max_stack_entries = 128;
  963. rdev->config.r600.max_hw_contexts = 8;
  964. rdev->config.r600.max_gs_threads = 4;
  965. rdev->config.r600.sx_max_export_size = 128;
  966. rdev->config.r600.sx_max_export_pos_size = 16;
  967. rdev->config.r600.sx_max_export_smx_size = 128;
  968. rdev->config.r600.sq_num_cf_insts = 2;
  969. break;
  970. case CHIP_RV610:
  971. case CHIP_RV620:
  972. case CHIP_RS780:
  973. case CHIP_RS880:
  974. rdev->config.r600.max_pipes = 1;
  975. rdev->config.r600.max_tile_pipes = 1;
  976. rdev->config.r600.max_simds = 2;
  977. rdev->config.r600.max_backends = 1;
  978. rdev->config.r600.max_gprs = 128;
  979. rdev->config.r600.max_threads = 192;
  980. rdev->config.r600.max_stack_entries = 128;
  981. rdev->config.r600.max_hw_contexts = 4;
  982. rdev->config.r600.max_gs_threads = 4;
  983. rdev->config.r600.sx_max_export_size = 128;
  984. rdev->config.r600.sx_max_export_pos_size = 16;
  985. rdev->config.r600.sx_max_export_smx_size = 128;
  986. rdev->config.r600.sq_num_cf_insts = 1;
  987. break;
  988. case CHIP_RV670:
  989. rdev->config.r600.max_pipes = 4;
  990. rdev->config.r600.max_tile_pipes = 4;
  991. rdev->config.r600.max_simds = 4;
  992. rdev->config.r600.max_backends = 4;
  993. rdev->config.r600.max_gprs = 192;
  994. rdev->config.r600.max_threads = 192;
  995. rdev->config.r600.max_stack_entries = 256;
  996. rdev->config.r600.max_hw_contexts = 8;
  997. rdev->config.r600.max_gs_threads = 16;
  998. rdev->config.r600.sx_max_export_size = 128;
  999. rdev->config.r600.sx_max_export_pos_size = 16;
  1000. rdev->config.r600.sx_max_export_smx_size = 128;
  1001. rdev->config.r600.sq_num_cf_insts = 2;
  1002. break;
  1003. default:
  1004. break;
  1005. }
  1006. /* Initialize HDP */
  1007. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  1008. WREG32((0x2c14 + j), 0x00000000);
  1009. WREG32((0x2c18 + j), 0x00000000);
  1010. WREG32((0x2c1c + j), 0x00000000);
  1011. WREG32((0x2c20 + j), 0x00000000);
  1012. WREG32((0x2c24 + j), 0x00000000);
  1013. }
  1014. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  1015. /* Setup tiling */
  1016. tiling_config = 0;
  1017. ramcfg = RREG32(RAMCFG);
  1018. switch (rdev->config.r600.max_tile_pipes) {
  1019. case 1:
  1020. tiling_config |= PIPE_TILING(0);
  1021. break;
  1022. case 2:
  1023. tiling_config |= PIPE_TILING(1);
  1024. break;
  1025. case 4:
  1026. tiling_config |= PIPE_TILING(2);
  1027. break;
  1028. case 8:
  1029. tiling_config |= PIPE_TILING(3);
  1030. break;
  1031. default:
  1032. break;
  1033. }
  1034. rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
  1035. rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
  1036. tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
  1037. tiling_config |= GROUP_SIZE(0);
  1038. rdev->config.r600.tiling_group_size = 256;
  1039. tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
  1040. if (tmp > 3) {
  1041. tiling_config |= ROW_TILING(3);
  1042. tiling_config |= SAMPLE_SPLIT(3);
  1043. } else {
  1044. tiling_config |= ROW_TILING(tmp);
  1045. tiling_config |= SAMPLE_SPLIT(tmp);
  1046. }
  1047. tiling_config |= BANK_SWAPS(1);
  1048. cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
  1049. cc_rb_backend_disable |=
  1050. BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << rdev->config.r600.max_backends) & R6XX_MAX_BACKENDS_MASK);
  1051. cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
  1052. cc_gc_shader_pipe_config |=
  1053. INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << rdev->config.r600.max_pipes) & R6XX_MAX_PIPES_MASK);
  1054. cc_gc_shader_pipe_config |=
  1055. INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << rdev->config.r600.max_simds) & R6XX_MAX_SIMDS_MASK);
  1056. backend_map = r600_get_tile_pipe_to_backend_map(rdev->config.r600.max_tile_pipes,
  1057. (R6XX_MAX_BACKENDS -
  1058. r600_count_pipe_bits((cc_rb_backend_disable &
  1059. R6XX_MAX_BACKENDS_MASK) >> 16)),
  1060. (cc_rb_backend_disable >> 16));
  1061. tiling_config |= BACKEND_MAP(backend_map);
  1062. WREG32(GB_TILING_CONFIG, tiling_config);
  1063. WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
  1064. WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
  1065. /* Setup pipes */
  1066. WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
  1067. WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  1068. WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  1069. tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
  1070. WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
  1071. WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
  1072. /* Setup some CP states */
  1073. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
  1074. WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
  1075. WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
  1076. SYNC_WALKER | SYNC_ALIGNER));
  1077. /* Setup various GPU states */
  1078. if (rdev->family == CHIP_RV670)
  1079. WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
  1080. tmp = RREG32(SX_DEBUG_1);
  1081. tmp |= SMX_EVENT_RELEASE;
  1082. if ((rdev->family > CHIP_R600))
  1083. tmp |= ENABLE_NEW_SMX_ADDRESS;
  1084. WREG32(SX_DEBUG_1, tmp);
  1085. if (((rdev->family) == CHIP_R600) ||
  1086. ((rdev->family) == CHIP_RV630) ||
  1087. ((rdev->family) == CHIP_RV610) ||
  1088. ((rdev->family) == CHIP_RV620) ||
  1089. ((rdev->family) == CHIP_RS780) ||
  1090. ((rdev->family) == CHIP_RS880)) {
  1091. WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
  1092. } else {
  1093. WREG32(DB_DEBUG, 0);
  1094. }
  1095. WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
  1096. DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
  1097. WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
  1098. WREG32(VGT_NUM_INSTANCES, 0);
  1099. WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
  1100. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
  1101. tmp = RREG32(SQ_MS_FIFO_SIZES);
  1102. if (((rdev->family) == CHIP_RV610) ||
  1103. ((rdev->family) == CHIP_RV620) ||
  1104. ((rdev->family) == CHIP_RS780) ||
  1105. ((rdev->family) == CHIP_RS880)) {
  1106. tmp = (CACHE_FIFO_SIZE(0xa) |
  1107. FETCH_FIFO_HIWATER(0xa) |
  1108. DONE_FIFO_HIWATER(0xe0) |
  1109. ALU_UPDATE_FIFO_HIWATER(0x8));
  1110. } else if (((rdev->family) == CHIP_R600) ||
  1111. ((rdev->family) == CHIP_RV630)) {
  1112. tmp &= ~DONE_FIFO_HIWATER(0xff);
  1113. tmp |= DONE_FIFO_HIWATER(0x4);
  1114. }
  1115. WREG32(SQ_MS_FIFO_SIZES, tmp);
  1116. /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
  1117. * should be adjusted as needed by the 2D/3D drivers. This just sets default values
  1118. */
  1119. sq_config = RREG32(SQ_CONFIG);
  1120. sq_config &= ~(PS_PRIO(3) |
  1121. VS_PRIO(3) |
  1122. GS_PRIO(3) |
  1123. ES_PRIO(3));
  1124. sq_config |= (DX9_CONSTS |
  1125. VC_ENABLE |
  1126. PS_PRIO(0) |
  1127. VS_PRIO(1) |
  1128. GS_PRIO(2) |
  1129. ES_PRIO(3));
  1130. if ((rdev->family) == CHIP_R600) {
  1131. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
  1132. NUM_VS_GPRS(124) |
  1133. NUM_CLAUSE_TEMP_GPRS(4));
  1134. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
  1135. NUM_ES_GPRS(0));
  1136. sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
  1137. NUM_VS_THREADS(48) |
  1138. NUM_GS_THREADS(4) |
  1139. NUM_ES_THREADS(4));
  1140. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
  1141. NUM_VS_STACK_ENTRIES(128));
  1142. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
  1143. NUM_ES_STACK_ENTRIES(0));
  1144. } else if (((rdev->family) == CHIP_RV610) ||
  1145. ((rdev->family) == CHIP_RV620) ||
  1146. ((rdev->family) == CHIP_RS780) ||
  1147. ((rdev->family) == CHIP_RS880)) {
  1148. /* no vertex cache */
  1149. sq_config &= ~VC_ENABLE;
  1150. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  1151. NUM_VS_GPRS(44) |
  1152. NUM_CLAUSE_TEMP_GPRS(2));
  1153. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
  1154. NUM_ES_GPRS(17));
  1155. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  1156. NUM_VS_THREADS(78) |
  1157. NUM_GS_THREADS(4) |
  1158. NUM_ES_THREADS(31));
  1159. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
  1160. NUM_VS_STACK_ENTRIES(40));
  1161. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
  1162. NUM_ES_STACK_ENTRIES(16));
  1163. } else if (((rdev->family) == CHIP_RV630) ||
  1164. ((rdev->family) == CHIP_RV635)) {
  1165. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  1166. NUM_VS_GPRS(44) |
  1167. NUM_CLAUSE_TEMP_GPRS(2));
  1168. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
  1169. NUM_ES_GPRS(18));
  1170. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  1171. NUM_VS_THREADS(78) |
  1172. NUM_GS_THREADS(4) |
  1173. NUM_ES_THREADS(31));
  1174. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
  1175. NUM_VS_STACK_ENTRIES(40));
  1176. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
  1177. NUM_ES_STACK_ENTRIES(16));
  1178. } else if ((rdev->family) == CHIP_RV670) {
  1179. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  1180. NUM_VS_GPRS(44) |
  1181. NUM_CLAUSE_TEMP_GPRS(2));
  1182. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
  1183. NUM_ES_GPRS(17));
  1184. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  1185. NUM_VS_THREADS(78) |
  1186. NUM_GS_THREADS(4) |
  1187. NUM_ES_THREADS(31));
  1188. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
  1189. NUM_VS_STACK_ENTRIES(64));
  1190. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
  1191. NUM_ES_STACK_ENTRIES(64));
  1192. }
  1193. WREG32(SQ_CONFIG, sq_config);
  1194. WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
  1195. WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
  1196. WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  1197. WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
  1198. WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
  1199. if (((rdev->family) == CHIP_RV610) ||
  1200. ((rdev->family) == CHIP_RV620) ||
  1201. ((rdev->family) == CHIP_RS780) ||
  1202. ((rdev->family) == CHIP_RS880)) {
  1203. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
  1204. } else {
  1205. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
  1206. }
  1207. /* More default values. 2D/3D driver should adjust as needed */
  1208. WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
  1209. S1_X(0x4) | S1_Y(0xc)));
  1210. WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
  1211. S1_X(0x2) | S1_Y(0x2) |
  1212. S2_X(0xa) | S2_Y(0x6) |
  1213. S3_X(0x6) | S3_Y(0xa)));
  1214. WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
  1215. S1_X(0x4) | S1_Y(0xc) |
  1216. S2_X(0x1) | S2_Y(0x6) |
  1217. S3_X(0xa) | S3_Y(0xe)));
  1218. WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
  1219. S5_X(0x0) | S5_Y(0x0) |
  1220. S6_X(0xb) | S6_Y(0x4) |
  1221. S7_X(0x7) | S7_Y(0x8)));
  1222. WREG32(VGT_STRMOUT_EN, 0);
  1223. tmp = rdev->config.r600.max_pipes * 16;
  1224. switch (rdev->family) {
  1225. case CHIP_RV610:
  1226. case CHIP_RV620:
  1227. case CHIP_RS780:
  1228. case CHIP_RS880:
  1229. tmp += 32;
  1230. break;
  1231. case CHIP_RV670:
  1232. tmp += 128;
  1233. break;
  1234. default:
  1235. break;
  1236. }
  1237. if (tmp > 256) {
  1238. tmp = 256;
  1239. }
  1240. WREG32(VGT_ES_PER_GS, 128);
  1241. WREG32(VGT_GS_PER_ES, tmp);
  1242. WREG32(VGT_GS_PER_VS, 2);
  1243. WREG32(VGT_GS_VERTEX_REUSE, 16);
  1244. /* more default values. 2D/3D driver should adjust as needed */
  1245. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  1246. WREG32(VGT_STRMOUT_EN, 0);
  1247. WREG32(SX_MISC, 0);
  1248. WREG32(PA_SC_MODE_CNTL, 0);
  1249. WREG32(PA_SC_AA_CONFIG, 0);
  1250. WREG32(PA_SC_LINE_STIPPLE, 0);
  1251. WREG32(SPI_INPUT_Z, 0);
  1252. WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
  1253. WREG32(CB_COLOR7_FRAG, 0);
  1254. /* Clear render buffer base addresses */
  1255. WREG32(CB_COLOR0_BASE, 0);
  1256. WREG32(CB_COLOR1_BASE, 0);
  1257. WREG32(CB_COLOR2_BASE, 0);
  1258. WREG32(CB_COLOR3_BASE, 0);
  1259. WREG32(CB_COLOR4_BASE, 0);
  1260. WREG32(CB_COLOR5_BASE, 0);
  1261. WREG32(CB_COLOR6_BASE, 0);
  1262. WREG32(CB_COLOR7_BASE, 0);
  1263. WREG32(CB_COLOR7_FRAG, 0);
  1264. switch (rdev->family) {
  1265. case CHIP_RV610:
  1266. case CHIP_RV620:
  1267. case CHIP_RS780:
  1268. case CHIP_RS880:
  1269. tmp = TC_L2_SIZE(8);
  1270. break;
  1271. case CHIP_RV630:
  1272. case CHIP_RV635:
  1273. tmp = TC_L2_SIZE(4);
  1274. break;
  1275. case CHIP_R600:
  1276. tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
  1277. break;
  1278. default:
  1279. tmp = TC_L2_SIZE(0);
  1280. break;
  1281. }
  1282. WREG32(TC_CNTL, tmp);
  1283. tmp = RREG32(HDP_HOST_PATH_CNTL);
  1284. WREG32(HDP_HOST_PATH_CNTL, tmp);
  1285. tmp = RREG32(ARB_POP);
  1286. tmp |= ENABLE_TC128;
  1287. WREG32(ARB_POP, tmp);
  1288. WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
  1289. WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
  1290. NUM_CLIP_SEQ(3)));
  1291. WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
  1292. }
  1293. /*
  1294. * Indirect registers accessor
  1295. */
  1296. u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
  1297. {
  1298. u32 r;
  1299. WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
  1300. (void)RREG32(PCIE_PORT_INDEX);
  1301. r = RREG32(PCIE_PORT_DATA);
  1302. return r;
  1303. }
  1304. void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  1305. {
  1306. WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
  1307. (void)RREG32(PCIE_PORT_INDEX);
  1308. WREG32(PCIE_PORT_DATA, (v));
  1309. (void)RREG32(PCIE_PORT_DATA);
  1310. }
  1311. /*
  1312. * CP & Ring
  1313. */
  1314. void r600_cp_stop(struct radeon_device *rdev)
  1315. {
  1316. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
  1317. }
  1318. int r600_init_microcode(struct radeon_device *rdev)
  1319. {
  1320. struct platform_device *pdev;
  1321. const char *chip_name;
  1322. const char *rlc_chip_name;
  1323. size_t pfp_req_size, me_req_size, rlc_req_size;
  1324. char fw_name[30];
  1325. int err;
  1326. DRM_DEBUG("\n");
  1327. pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
  1328. err = IS_ERR(pdev);
  1329. if (err) {
  1330. printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
  1331. return -EINVAL;
  1332. }
  1333. switch (rdev->family) {
  1334. case CHIP_R600:
  1335. chip_name = "R600";
  1336. rlc_chip_name = "R600";
  1337. break;
  1338. case CHIP_RV610:
  1339. chip_name = "RV610";
  1340. rlc_chip_name = "R600";
  1341. break;
  1342. case CHIP_RV630:
  1343. chip_name = "RV630";
  1344. rlc_chip_name = "R600";
  1345. break;
  1346. case CHIP_RV620:
  1347. chip_name = "RV620";
  1348. rlc_chip_name = "R600";
  1349. break;
  1350. case CHIP_RV635:
  1351. chip_name = "RV635";
  1352. rlc_chip_name = "R600";
  1353. break;
  1354. case CHIP_RV670:
  1355. chip_name = "RV670";
  1356. rlc_chip_name = "R600";
  1357. break;
  1358. case CHIP_RS780:
  1359. case CHIP_RS880:
  1360. chip_name = "RS780";
  1361. rlc_chip_name = "R600";
  1362. break;
  1363. case CHIP_RV770:
  1364. chip_name = "RV770";
  1365. rlc_chip_name = "R700";
  1366. break;
  1367. case CHIP_RV730:
  1368. case CHIP_RV740:
  1369. chip_name = "RV730";
  1370. rlc_chip_name = "R700";
  1371. break;
  1372. case CHIP_RV710:
  1373. chip_name = "RV710";
  1374. rlc_chip_name = "R700";
  1375. break;
  1376. case CHIP_CEDAR:
  1377. chip_name = "CEDAR";
  1378. rlc_chip_name = "CEDAR";
  1379. break;
  1380. case CHIP_REDWOOD:
  1381. chip_name = "REDWOOD";
  1382. rlc_chip_name = "REDWOOD";
  1383. break;
  1384. case CHIP_JUNIPER:
  1385. chip_name = "JUNIPER";
  1386. rlc_chip_name = "JUNIPER";
  1387. break;
  1388. case CHIP_CYPRESS:
  1389. case CHIP_HEMLOCK:
  1390. chip_name = "CYPRESS";
  1391. rlc_chip_name = "CYPRESS";
  1392. break;
  1393. default: BUG();
  1394. }
  1395. if (rdev->family >= CHIP_CEDAR) {
  1396. pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
  1397. me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
  1398. rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
  1399. } else if (rdev->family >= CHIP_RV770) {
  1400. pfp_req_size = R700_PFP_UCODE_SIZE * 4;
  1401. me_req_size = R700_PM4_UCODE_SIZE * 4;
  1402. rlc_req_size = R700_RLC_UCODE_SIZE * 4;
  1403. } else {
  1404. pfp_req_size = PFP_UCODE_SIZE * 4;
  1405. me_req_size = PM4_UCODE_SIZE * 12;
  1406. rlc_req_size = RLC_UCODE_SIZE * 4;
  1407. }
  1408. DRM_INFO("Loading %s Microcode\n", chip_name);
  1409. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  1410. err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
  1411. if (err)
  1412. goto out;
  1413. if (rdev->pfp_fw->size != pfp_req_size) {
  1414. printk(KERN_ERR
  1415. "r600_cp: Bogus length %zu in firmware \"%s\"\n",
  1416. rdev->pfp_fw->size, fw_name);
  1417. err = -EINVAL;
  1418. goto out;
  1419. }
  1420. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  1421. err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
  1422. if (err)
  1423. goto out;
  1424. if (rdev->me_fw->size != me_req_size) {
  1425. printk(KERN_ERR
  1426. "r600_cp: Bogus length %zu in firmware \"%s\"\n",
  1427. rdev->me_fw->size, fw_name);
  1428. err = -EINVAL;
  1429. }
  1430. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  1431. err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
  1432. if (err)
  1433. goto out;
  1434. if (rdev->rlc_fw->size != rlc_req_size) {
  1435. printk(KERN_ERR
  1436. "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
  1437. rdev->rlc_fw->size, fw_name);
  1438. err = -EINVAL;
  1439. }
  1440. out:
  1441. platform_device_unregister(pdev);
  1442. if (err) {
  1443. if (err != -EINVAL)
  1444. printk(KERN_ERR
  1445. "r600_cp: Failed to load firmware \"%s\"\n",
  1446. fw_name);
  1447. release_firmware(rdev->pfp_fw);
  1448. rdev->pfp_fw = NULL;
  1449. release_firmware(rdev->me_fw);
  1450. rdev->me_fw = NULL;
  1451. release_firmware(rdev->rlc_fw);
  1452. rdev->rlc_fw = NULL;
  1453. }
  1454. return err;
  1455. }
  1456. static int r600_cp_load_microcode(struct radeon_device *rdev)
  1457. {
  1458. const __be32 *fw_data;
  1459. int i;
  1460. if (!rdev->me_fw || !rdev->pfp_fw)
  1461. return -EINVAL;
  1462. r600_cp_stop(rdev);
  1463. WREG32(CP_RB_CNTL, RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
  1464. /* Reset cp */
  1465. WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
  1466. RREG32(GRBM_SOFT_RESET);
  1467. mdelay(15);
  1468. WREG32(GRBM_SOFT_RESET, 0);
  1469. WREG32(CP_ME_RAM_WADDR, 0);
  1470. fw_data = (const __be32 *)rdev->me_fw->data;
  1471. WREG32(CP_ME_RAM_WADDR, 0);
  1472. for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
  1473. WREG32(CP_ME_RAM_DATA,
  1474. be32_to_cpup(fw_data++));
  1475. fw_data = (const __be32 *)rdev->pfp_fw->data;
  1476. WREG32(CP_PFP_UCODE_ADDR, 0);
  1477. for (i = 0; i < PFP_UCODE_SIZE; i++)
  1478. WREG32(CP_PFP_UCODE_DATA,
  1479. be32_to_cpup(fw_data++));
  1480. WREG32(CP_PFP_UCODE_ADDR, 0);
  1481. WREG32(CP_ME_RAM_WADDR, 0);
  1482. WREG32(CP_ME_RAM_RADDR, 0);
  1483. return 0;
  1484. }
  1485. int r600_cp_start(struct radeon_device *rdev)
  1486. {
  1487. int r;
  1488. uint32_t cp_me;
  1489. r = radeon_ring_lock(rdev, 7);
  1490. if (r) {
  1491. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  1492. return r;
  1493. }
  1494. radeon_ring_write(rdev, PACKET3(PACKET3_ME_INITIALIZE, 5));
  1495. radeon_ring_write(rdev, 0x1);
  1496. if (rdev->family >= CHIP_CEDAR) {
  1497. radeon_ring_write(rdev, 0x0);
  1498. radeon_ring_write(rdev, rdev->config.evergreen.max_hw_contexts - 1);
  1499. } else if (rdev->family >= CHIP_RV770) {
  1500. radeon_ring_write(rdev, 0x0);
  1501. radeon_ring_write(rdev, rdev->config.rv770.max_hw_contexts - 1);
  1502. } else {
  1503. radeon_ring_write(rdev, 0x3);
  1504. radeon_ring_write(rdev, rdev->config.r600.max_hw_contexts - 1);
  1505. }
  1506. radeon_ring_write(rdev, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  1507. radeon_ring_write(rdev, 0);
  1508. radeon_ring_write(rdev, 0);
  1509. radeon_ring_unlock_commit(rdev);
  1510. cp_me = 0xff;
  1511. WREG32(R_0086D8_CP_ME_CNTL, cp_me);
  1512. return 0;
  1513. }
  1514. int r600_cp_resume(struct radeon_device *rdev)
  1515. {
  1516. u32 tmp;
  1517. u32 rb_bufsz;
  1518. int r;
  1519. /* Reset cp */
  1520. WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
  1521. RREG32(GRBM_SOFT_RESET);
  1522. mdelay(15);
  1523. WREG32(GRBM_SOFT_RESET, 0);
  1524. /* Set ring buffer size */
  1525. rb_bufsz = drm_order(rdev->cp.ring_size / 8);
  1526. tmp = RB_NO_UPDATE | (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  1527. #ifdef __BIG_ENDIAN
  1528. tmp |= BUF_SWAP_32BIT;
  1529. #endif
  1530. WREG32(CP_RB_CNTL, tmp);
  1531. WREG32(CP_SEM_WAIT_TIMER, 0x4);
  1532. /* Set the write pointer delay */
  1533. WREG32(CP_RB_WPTR_DELAY, 0);
  1534. /* Initialize the ring buffer's read and write pointers */
  1535. WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
  1536. WREG32(CP_RB_RPTR_WR, 0);
  1537. WREG32(CP_RB_WPTR, 0);
  1538. WREG32(CP_RB_RPTR_ADDR, rdev->cp.gpu_addr & 0xFFFFFFFF);
  1539. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->cp.gpu_addr));
  1540. mdelay(1);
  1541. WREG32(CP_RB_CNTL, tmp);
  1542. WREG32(CP_RB_BASE, rdev->cp.gpu_addr >> 8);
  1543. WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
  1544. rdev->cp.rptr = RREG32(CP_RB_RPTR);
  1545. rdev->cp.wptr = RREG32(CP_RB_WPTR);
  1546. r600_cp_start(rdev);
  1547. rdev->cp.ready = true;
  1548. r = radeon_ring_test(rdev);
  1549. if (r) {
  1550. rdev->cp.ready = false;
  1551. return r;
  1552. }
  1553. return 0;
  1554. }
  1555. void r600_cp_commit(struct radeon_device *rdev)
  1556. {
  1557. WREG32(CP_RB_WPTR, rdev->cp.wptr);
  1558. (void)RREG32(CP_RB_WPTR);
  1559. }
  1560. void r600_ring_init(struct radeon_device *rdev, unsigned ring_size)
  1561. {
  1562. u32 rb_bufsz;
  1563. /* Align ring size */
  1564. rb_bufsz = drm_order(ring_size / 8);
  1565. ring_size = (1 << (rb_bufsz + 1)) * 4;
  1566. rdev->cp.ring_size = ring_size;
  1567. rdev->cp.align_mask = 16 - 1;
  1568. }
  1569. void r600_cp_fini(struct radeon_device *rdev)
  1570. {
  1571. r600_cp_stop(rdev);
  1572. radeon_ring_fini(rdev);
  1573. }
  1574. /*
  1575. * GPU scratch registers helpers function.
  1576. */
  1577. void r600_scratch_init(struct radeon_device *rdev)
  1578. {
  1579. int i;
  1580. rdev->scratch.num_reg = 7;
  1581. for (i = 0; i < rdev->scratch.num_reg; i++) {
  1582. rdev->scratch.free[i] = true;
  1583. rdev->scratch.reg[i] = SCRATCH_REG0 + (i * 4);
  1584. }
  1585. }
  1586. int r600_ring_test(struct radeon_device *rdev)
  1587. {
  1588. uint32_t scratch;
  1589. uint32_t tmp = 0;
  1590. unsigned i;
  1591. int r;
  1592. r = radeon_scratch_get(rdev, &scratch);
  1593. if (r) {
  1594. DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
  1595. return r;
  1596. }
  1597. WREG32(scratch, 0xCAFEDEAD);
  1598. r = radeon_ring_lock(rdev, 3);
  1599. if (r) {
  1600. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  1601. radeon_scratch_free(rdev, scratch);
  1602. return r;
  1603. }
  1604. radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  1605. radeon_ring_write(rdev, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
  1606. radeon_ring_write(rdev, 0xDEADBEEF);
  1607. radeon_ring_unlock_commit(rdev);
  1608. for (i = 0; i < rdev->usec_timeout; i++) {
  1609. tmp = RREG32(scratch);
  1610. if (tmp == 0xDEADBEEF)
  1611. break;
  1612. DRM_UDELAY(1);
  1613. }
  1614. if (i < rdev->usec_timeout) {
  1615. DRM_INFO("ring test succeeded in %d usecs\n", i);
  1616. } else {
  1617. DRM_ERROR("radeon: ring test failed (scratch(0x%04X)=0x%08X)\n",
  1618. scratch, tmp);
  1619. r = -EINVAL;
  1620. }
  1621. radeon_scratch_free(rdev, scratch);
  1622. return r;
  1623. }
  1624. void r600_wb_disable(struct radeon_device *rdev)
  1625. {
  1626. int r;
  1627. WREG32(SCRATCH_UMSK, 0);
  1628. if (rdev->wb.wb_obj) {
  1629. r = radeon_bo_reserve(rdev->wb.wb_obj, false);
  1630. if (unlikely(r != 0))
  1631. return;
  1632. radeon_bo_kunmap(rdev->wb.wb_obj);
  1633. radeon_bo_unpin(rdev->wb.wb_obj);
  1634. radeon_bo_unreserve(rdev->wb.wb_obj);
  1635. }
  1636. }
  1637. void r600_wb_fini(struct radeon_device *rdev)
  1638. {
  1639. r600_wb_disable(rdev);
  1640. if (rdev->wb.wb_obj) {
  1641. radeon_bo_unref(&rdev->wb.wb_obj);
  1642. rdev->wb.wb = NULL;
  1643. rdev->wb.wb_obj = NULL;
  1644. }
  1645. }
  1646. int r600_wb_enable(struct radeon_device *rdev)
  1647. {
  1648. int r;
  1649. if (rdev->wb.wb_obj == NULL) {
  1650. r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, true,
  1651. RADEON_GEM_DOMAIN_GTT, &rdev->wb.wb_obj);
  1652. if (r) {
  1653. dev_warn(rdev->dev, "(%d) create WB bo failed\n", r);
  1654. return r;
  1655. }
  1656. r = radeon_bo_reserve(rdev->wb.wb_obj, false);
  1657. if (unlikely(r != 0)) {
  1658. r600_wb_fini(rdev);
  1659. return r;
  1660. }
  1661. r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT,
  1662. &rdev->wb.gpu_addr);
  1663. if (r) {
  1664. radeon_bo_unreserve(rdev->wb.wb_obj);
  1665. dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r);
  1666. r600_wb_fini(rdev);
  1667. return r;
  1668. }
  1669. r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb);
  1670. radeon_bo_unreserve(rdev->wb.wb_obj);
  1671. if (r) {
  1672. dev_warn(rdev->dev, "(%d) map WB bo failed\n", r);
  1673. r600_wb_fini(rdev);
  1674. return r;
  1675. }
  1676. }
  1677. WREG32(SCRATCH_ADDR, (rdev->wb.gpu_addr >> 8) & 0xFFFFFFFF);
  1678. WREG32(CP_RB_RPTR_ADDR, (rdev->wb.gpu_addr + 1024) & 0xFFFFFFFC);
  1679. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + 1024) & 0xFF);
  1680. WREG32(SCRATCH_UMSK, 0xff);
  1681. return 0;
  1682. }
  1683. void r600_fence_ring_emit(struct radeon_device *rdev,
  1684. struct radeon_fence *fence)
  1685. {
  1686. /* Also consider EVENT_WRITE_EOP. it handles the interrupts + timestamps + events */
  1687. radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE, 0));
  1688. radeon_ring_write(rdev, CACHE_FLUSH_AND_INV_EVENT);
  1689. /* wait for 3D idle clean */
  1690. radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  1691. radeon_ring_write(rdev, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  1692. radeon_ring_write(rdev, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
  1693. /* Emit fence sequence & fire IRQ */
  1694. radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  1695. radeon_ring_write(rdev, ((rdev->fence_drv.scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
  1696. radeon_ring_write(rdev, fence->seq);
  1697. /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
  1698. radeon_ring_write(rdev, PACKET0(CP_INT_STATUS, 0));
  1699. radeon_ring_write(rdev, RB_INT_STAT);
  1700. }
  1701. int r600_copy_blit(struct radeon_device *rdev,
  1702. uint64_t src_offset, uint64_t dst_offset,
  1703. unsigned num_pages, struct radeon_fence *fence)
  1704. {
  1705. int r;
  1706. mutex_lock(&rdev->r600_blit.mutex);
  1707. rdev->r600_blit.vb_ib = NULL;
  1708. r = r600_blit_prepare_copy(rdev, num_pages * RADEON_GPU_PAGE_SIZE);
  1709. if (r) {
  1710. if (rdev->r600_blit.vb_ib)
  1711. radeon_ib_free(rdev, &rdev->r600_blit.vb_ib);
  1712. mutex_unlock(&rdev->r600_blit.mutex);
  1713. return r;
  1714. }
  1715. r600_kms_blit_copy(rdev, src_offset, dst_offset, num_pages * RADEON_GPU_PAGE_SIZE);
  1716. r600_blit_done_copy(rdev, fence);
  1717. mutex_unlock(&rdev->r600_blit.mutex);
  1718. return 0;
  1719. }
  1720. int r600_set_surface_reg(struct radeon_device *rdev, int reg,
  1721. uint32_t tiling_flags, uint32_t pitch,
  1722. uint32_t offset, uint32_t obj_size)
  1723. {
  1724. /* FIXME: implement */
  1725. return 0;
  1726. }
  1727. void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
  1728. {
  1729. /* FIXME: implement */
  1730. }
  1731. bool r600_card_posted(struct radeon_device *rdev)
  1732. {
  1733. uint32_t reg;
  1734. /* first check CRTCs */
  1735. reg = RREG32(D1CRTC_CONTROL) |
  1736. RREG32(D2CRTC_CONTROL);
  1737. if (reg & CRTC_EN)
  1738. return true;
  1739. /* then check MEM_SIZE, in case the crtcs are off */
  1740. if (RREG32(CONFIG_MEMSIZE))
  1741. return true;
  1742. return false;
  1743. }
  1744. int r600_startup(struct radeon_device *rdev)
  1745. {
  1746. int r;
  1747. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  1748. r = r600_init_microcode(rdev);
  1749. if (r) {
  1750. DRM_ERROR("Failed to load firmware!\n");
  1751. return r;
  1752. }
  1753. }
  1754. r600_mc_program(rdev);
  1755. if (rdev->flags & RADEON_IS_AGP) {
  1756. r600_agp_enable(rdev);
  1757. } else {
  1758. r = r600_pcie_gart_enable(rdev);
  1759. if (r)
  1760. return r;
  1761. }
  1762. r600_gpu_init(rdev);
  1763. r = r600_blit_init(rdev);
  1764. if (r) {
  1765. r600_blit_fini(rdev);
  1766. rdev->asic->copy = NULL;
  1767. dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
  1768. }
  1769. /* pin copy shader into vram */
  1770. if (rdev->r600_blit.shader_obj) {
  1771. r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
  1772. if (unlikely(r != 0))
  1773. return r;
  1774. r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM,
  1775. &rdev->r600_blit.shader_gpu_addr);
  1776. radeon_bo_unreserve(rdev->r600_blit.shader_obj);
  1777. if (r) {
  1778. dev_err(rdev->dev, "(%d) pin blit object failed\n", r);
  1779. return r;
  1780. }
  1781. }
  1782. /* Enable IRQ */
  1783. r = r600_irq_init(rdev);
  1784. if (r) {
  1785. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  1786. radeon_irq_kms_fini(rdev);
  1787. return r;
  1788. }
  1789. r600_irq_set(rdev);
  1790. r = radeon_ring_init(rdev, rdev->cp.ring_size);
  1791. if (r)
  1792. return r;
  1793. r = r600_cp_load_microcode(rdev);
  1794. if (r)
  1795. return r;
  1796. r = r600_cp_resume(rdev);
  1797. if (r)
  1798. return r;
  1799. /* write back buffer are not vital so don't worry about failure */
  1800. r600_wb_enable(rdev);
  1801. return 0;
  1802. }
  1803. void r600_vga_set_state(struct radeon_device *rdev, bool state)
  1804. {
  1805. uint32_t temp;
  1806. temp = RREG32(CONFIG_CNTL);
  1807. if (state == false) {
  1808. temp &= ~(1<<0);
  1809. temp |= (1<<1);
  1810. } else {
  1811. temp &= ~(1<<1);
  1812. }
  1813. WREG32(CONFIG_CNTL, temp);
  1814. }
  1815. int r600_resume(struct radeon_device *rdev)
  1816. {
  1817. int r;
  1818. /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
  1819. * posting will perform necessary task to bring back GPU into good
  1820. * shape.
  1821. */
  1822. /* post card */
  1823. atom_asic_init(rdev->mode_info.atom_context);
  1824. /* Initialize clocks */
  1825. r = radeon_clocks_init(rdev);
  1826. if (r) {
  1827. return r;
  1828. }
  1829. r = r600_startup(rdev);
  1830. if (r) {
  1831. DRM_ERROR("r600 startup failed on resume\n");
  1832. return r;
  1833. }
  1834. r = r600_ib_test(rdev);
  1835. if (r) {
  1836. DRM_ERROR("radeon: failled testing IB (%d).\n", r);
  1837. return r;
  1838. }
  1839. r = r600_audio_init(rdev);
  1840. if (r) {
  1841. DRM_ERROR("radeon: audio resume failed\n");
  1842. return r;
  1843. }
  1844. return r;
  1845. }
  1846. int r600_suspend(struct radeon_device *rdev)
  1847. {
  1848. int r;
  1849. r600_audio_fini(rdev);
  1850. /* FIXME: we should wait for ring to be empty */
  1851. r600_cp_stop(rdev);
  1852. rdev->cp.ready = false;
  1853. r600_irq_suspend(rdev);
  1854. r600_wb_disable(rdev);
  1855. r600_pcie_gart_disable(rdev);
  1856. /* unpin shaders bo */
  1857. if (rdev->r600_blit.shader_obj) {
  1858. r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
  1859. if (!r) {
  1860. radeon_bo_unpin(rdev->r600_blit.shader_obj);
  1861. radeon_bo_unreserve(rdev->r600_blit.shader_obj);
  1862. }
  1863. }
  1864. return 0;
  1865. }
  1866. /* Plan is to move initialization in that function and use
  1867. * helper function so that radeon_device_init pretty much
  1868. * do nothing more than calling asic specific function. This
  1869. * should also allow to remove a bunch of callback function
  1870. * like vram_info.
  1871. */
  1872. int r600_init(struct radeon_device *rdev)
  1873. {
  1874. int r;
  1875. r = radeon_dummy_page_init(rdev);
  1876. if (r)
  1877. return r;
  1878. if (r600_debugfs_mc_info_init(rdev)) {
  1879. DRM_ERROR("Failed to register debugfs file for mc !\n");
  1880. }
  1881. /* This don't do much */
  1882. r = radeon_gem_init(rdev);
  1883. if (r)
  1884. return r;
  1885. /* Read BIOS */
  1886. if (!radeon_get_bios(rdev)) {
  1887. if (ASIC_IS_AVIVO(rdev))
  1888. return -EINVAL;
  1889. }
  1890. /* Must be an ATOMBIOS */
  1891. if (!rdev->is_atom_bios) {
  1892. dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
  1893. return -EINVAL;
  1894. }
  1895. r = radeon_atombios_init(rdev);
  1896. if (r)
  1897. return r;
  1898. /* Post card if necessary */
  1899. if (!r600_card_posted(rdev)) {
  1900. if (!rdev->bios) {
  1901. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  1902. return -EINVAL;
  1903. }
  1904. DRM_INFO("GPU not posted. posting now...\n");
  1905. atom_asic_init(rdev->mode_info.atom_context);
  1906. }
  1907. /* Initialize scratch registers */
  1908. r600_scratch_init(rdev);
  1909. /* Initialize surface registers */
  1910. radeon_surface_init(rdev);
  1911. /* Initialize clocks */
  1912. radeon_get_clock_info(rdev->ddev);
  1913. r = radeon_clocks_init(rdev);
  1914. if (r)
  1915. return r;
  1916. /* Initialize power management */
  1917. radeon_pm_init(rdev);
  1918. /* Fence driver */
  1919. r = radeon_fence_driver_init(rdev);
  1920. if (r)
  1921. return r;
  1922. if (rdev->flags & RADEON_IS_AGP) {
  1923. r = radeon_agp_init(rdev);
  1924. if (r)
  1925. radeon_agp_disable(rdev);
  1926. }
  1927. r = r600_mc_init(rdev);
  1928. if (r)
  1929. return r;
  1930. /* Memory manager */
  1931. r = radeon_bo_init(rdev);
  1932. if (r)
  1933. return r;
  1934. r = radeon_irq_kms_init(rdev);
  1935. if (r)
  1936. return r;
  1937. rdev->cp.ring_obj = NULL;
  1938. r600_ring_init(rdev, 1024 * 1024);
  1939. rdev->ih.ring_obj = NULL;
  1940. r600_ih_ring_init(rdev, 64 * 1024);
  1941. r = r600_pcie_gart_init(rdev);
  1942. if (r)
  1943. return r;
  1944. rdev->accel_working = true;
  1945. r = r600_startup(rdev);
  1946. if (r) {
  1947. dev_err(rdev->dev, "disabling GPU acceleration\n");
  1948. r600_cp_fini(rdev);
  1949. r600_wb_fini(rdev);
  1950. r600_irq_fini(rdev);
  1951. radeon_irq_kms_fini(rdev);
  1952. r600_pcie_gart_fini(rdev);
  1953. rdev->accel_working = false;
  1954. }
  1955. if (rdev->accel_working) {
  1956. r = radeon_ib_pool_init(rdev);
  1957. if (r) {
  1958. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  1959. rdev->accel_working = false;
  1960. } else {
  1961. r = r600_ib_test(rdev);
  1962. if (r) {
  1963. dev_err(rdev->dev, "IB test failed (%d).\n", r);
  1964. rdev->accel_working = false;
  1965. }
  1966. }
  1967. }
  1968. r = r600_audio_init(rdev);
  1969. if (r)
  1970. return r; /* TODO error handling */
  1971. return 0;
  1972. }
  1973. void r600_fini(struct radeon_device *rdev)
  1974. {
  1975. radeon_pm_fini(rdev);
  1976. r600_audio_fini(rdev);
  1977. r600_blit_fini(rdev);
  1978. r600_cp_fini(rdev);
  1979. r600_wb_fini(rdev);
  1980. r600_irq_fini(rdev);
  1981. radeon_irq_kms_fini(rdev);
  1982. r600_pcie_gart_fini(rdev);
  1983. radeon_agp_fini(rdev);
  1984. radeon_gem_fini(rdev);
  1985. radeon_fence_driver_fini(rdev);
  1986. radeon_clocks_fini(rdev);
  1987. radeon_bo_fini(rdev);
  1988. radeon_atombios_fini(rdev);
  1989. kfree(rdev->bios);
  1990. rdev->bios = NULL;
  1991. radeon_dummy_page_fini(rdev);
  1992. }
  1993. /*
  1994. * CS stuff
  1995. */
  1996. void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  1997. {
  1998. /* FIXME: implement */
  1999. radeon_ring_write(rdev, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  2000. radeon_ring_write(rdev, ib->gpu_addr & 0xFFFFFFFC);
  2001. radeon_ring_write(rdev, upper_32_bits(ib->gpu_addr) & 0xFF);
  2002. radeon_ring_write(rdev, ib->length_dw);
  2003. }
  2004. int r600_ib_test(struct radeon_device *rdev)
  2005. {
  2006. struct radeon_ib *ib;
  2007. uint32_t scratch;
  2008. uint32_t tmp = 0;
  2009. unsigned i;
  2010. int r;
  2011. r = radeon_scratch_get(rdev, &scratch);
  2012. if (r) {
  2013. DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
  2014. return r;
  2015. }
  2016. WREG32(scratch, 0xCAFEDEAD);
  2017. r = radeon_ib_get(rdev, &ib);
  2018. if (r) {
  2019. DRM_ERROR("radeon: failed to get ib (%d).\n", r);
  2020. return r;
  2021. }
  2022. ib->ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
  2023. ib->ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  2024. ib->ptr[2] = 0xDEADBEEF;
  2025. ib->ptr[3] = PACKET2(0);
  2026. ib->ptr[4] = PACKET2(0);
  2027. ib->ptr[5] = PACKET2(0);
  2028. ib->ptr[6] = PACKET2(0);
  2029. ib->ptr[7] = PACKET2(0);
  2030. ib->ptr[8] = PACKET2(0);
  2031. ib->ptr[9] = PACKET2(0);
  2032. ib->ptr[10] = PACKET2(0);
  2033. ib->ptr[11] = PACKET2(0);
  2034. ib->ptr[12] = PACKET2(0);
  2035. ib->ptr[13] = PACKET2(0);
  2036. ib->ptr[14] = PACKET2(0);
  2037. ib->ptr[15] = PACKET2(0);
  2038. ib->length_dw = 16;
  2039. r = radeon_ib_schedule(rdev, ib);
  2040. if (r) {
  2041. radeon_scratch_free(rdev, scratch);
  2042. radeon_ib_free(rdev, &ib);
  2043. DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
  2044. return r;
  2045. }
  2046. r = radeon_fence_wait(ib->fence, false);
  2047. if (r) {
  2048. DRM_ERROR("radeon: fence wait failed (%d).\n", r);
  2049. return r;
  2050. }
  2051. for (i = 0; i < rdev->usec_timeout; i++) {
  2052. tmp = RREG32(scratch);
  2053. if (tmp == 0xDEADBEEF)
  2054. break;
  2055. DRM_UDELAY(1);
  2056. }
  2057. if (i < rdev->usec_timeout) {
  2058. DRM_INFO("ib test succeeded in %u usecs\n", i);
  2059. } else {
  2060. DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n",
  2061. scratch, tmp);
  2062. r = -EINVAL;
  2063. }
  2064. radeon_scratch_free(rdev, scratch);
  2065. radeon_ib_free(rdev, &ib);
  2066. return r;
  2067. }
  2068. /*
  2069. * Interrupts
  2070. *
  2071. * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
  2072. * the same as the CP ring buffer, but in reverse. Rather than the CPU
  2073. * writing to the ring and the GPU consuming, the GPU writes to the ring
  2074. * and host consumes. As the host irq handler processes interrupts, it
  2075. * increments the rptr. When the rptr catches up with the wptr, all the
  2076. * current interrupts have been processed.
  2077. */
  2078. void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
  2079. {
  2080. u32 rb_bufsz;
  2081. /* Align ring size */
  2082. rb_bufsz = drm_order(ring_size / 4);
  2083. ring_size = (1 << rb_bufsz) * 4;
  2084. rdev->ih.ring_size = ring_size;
  2085. rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
  2086. rdev->ih.rptr = 0;
  2087. }
  2088. static int r600_ih_ring_alloc(struct radeon_device *rdev)
  2089. {
  2090. int r;
  2091. /* Allocate ring buffer */
  2092. if (rdev->ih.ring_obj == NULL) {
  2093. r = radeon_bo_create(rdev, NULL, rdev->ih.ring_size,
  2094. true,
  2095. RADEON_GEM_DOMAIN_GTT,
  2096. &rdev->ih.ring_obj);
  2097. if (r) {
  2098. DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
  2099. return r;
  2100. }
  2101. r = radeon_bo_reserve(rdev->ih.ring_obj, false);
  2102. if (unlikely(r != 0))
  2103. return r;
  2104. r = radeon_bo_pin(rdev->ih.ring_obj,
  2105. RADEON_GEM_DOMAIN_GTT,
  2106. &rdev->ih.gpu_addr);
  2107. if (r) {
  2108. radeon_bo_unreserve(rdev->ih.ring_obj);
  2109. DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
  2110. return r;
  2111. }
  2112. r = radeon_bo_kmap(rdev->ih.ring_obj,
  2113. (void **)&rdev->ih.ring);
  2114. radeon_bo_unreserve(rdev->ih.ring_obj);
  2115. if (r) {
  2116. DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
  2117. return r;
  2118. }
  2119. }
  2120. return 0;
  2121. }
  2122. static void r600_ih_ring_fini(struct radeon_device *rdev)
  2123. {
  2124. int r;
  2125. if (rdev->ih.ring_obj) {
  2126. r = radeon_bo_reserve(rdev->ih.ring_obj, false);
  2127. if (likely(r == 0)) {
  2128. radeon_bo_kunmap(rdev->ih.ring_obj);
  2129. radeon_bo_unpin(rdev->ih.ring_obj);
  2130. radeon_bo_unreserve(rdev->ih.ring_obj);
  2131. }
  2132. radeon_bo_unref(&rdev->ih.ring_obj);
  2133. rdev->ih.ring = NULL;
  2134. rdev->ih.ring_obj = NULL;
  2135. }
  2136. }
  2137. void r600_rlc_stop(struct radeon_device *rdev)
  2138. {
  2139. if ((rdev->family >= CHIP_RV770) &&
  2140. (rdev->family <= CHIP_RV740)) {
  2141. /* r7xx asics need to soft reset RLC before halting */
  2142. WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
  2143. RREG32(SRBM_SOFT_RESET);
  2144. udelay(15000);
  2145. WREG32(SRBM_SOFT_RESET, 0);
  2146. RREG32(SRBM_SOFT_RESET);
  2147. }
  2148. WREG32(RLC_CNTL, 0);
  2149. }
  2150. static void r600_rlc_start(struct radeon_device *rdev)
  2151. {
  2152. WREG32(RLC_CNTL, RLC_ENABLE);
  2153. }
  2154. static int r600_rlc_init(struct radeon_device *rdev)
  2155. {
  2156. u32 i;
  2157. const __be32 *fw_data;
  2158. if (!rdev->rlc_fw)
  2159. return -EINVAL;
  2160. r600_rlc_stop(rdev);
  2161. WREG32(RLC_HB_BASE, 0);
  2162. WREG32(RLC_HB_CNTL, 0);
  2163. WREG32(RLC_HB_RPTR, 0);
  2164. WREG32(RLC_HB_WPTR, 0);
  2165. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  2166. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  2167. WREG32(RLC_MC_CNTL, 0);
  2168. WREG32(RLC_UCODE_CNTL, 0);
  2169. fw_data = (const __be32 *)rdev->rlc_fw->data;
  2170. if (rdev->family >= CHIP_CEDAR) {
  2171. for (i = 0; i < EVERGREEN_RLC_UCODE_SIZE; i++) {
  2172. WREG32(RLC_UCODE_ADDR, i);
  2173. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  2174. }
  2175. } else if (rdev->family >= CHIP_RV770) {
  2176. for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
  2177. WREG32(RLC_UCODE_ADDR, i);
  2178. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  2179. }
  2180. } else {
  2181. for (i = 0; i < RLC_UCODE_SIZE; i++) {
  2182. WREG32(RLC_UCODE_ADDR, i);
  2183. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  2184. }
  2185. }
  2186. WREG32(RLC_UCODE_ADDR, 0);
  2187. r600_rlc_start(rdev);
  2188. return 0;
  2189. }
  2190. static void r600_enable_interrupts(struct radeon_device *rdev)
  2191. {
  2192. u32 ih_cntl = RREG32(IH_CNTL);
  2193. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  2194. ih_cntl |= ENABLE_INTR;
  2195. ih_rb_cntl |= IH_RB_ENABLE;
  2196. WREG32(IH_CNTL, ih_cntl);
  2197. WREG32(IH_RB_CNTL, ih_rb_cntl);
  2198. rdev->ih.enabled = true;
  2199. }
  2200. void r600_disable_interrupts(struct radeon_device *rdev)
  2201. {
  2202. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  2203. u32 ih_cntl = RREG32(IH_CNTL);
  2204. ih_rb_cntl &= ~IH_RB_ENABLE;
  2205. ih_cntl &= ~ENABLE_INTR;
  2206. WREG32(IH_RB_CNTL, ih_rb_cntl);
  2207. WREG32(IH_CNTL, ih_cntl);
  2208. /* set rptr, wptr to 0 */
  2209. WREG32(IH_RB_RPTR, 0);
  2210. WREG32(IH_RB_WPTR, 0);
  2211. rdev->ih.enabled = false;
  2212. rdev->ih.wptr = 0;
  2213. rdev->ih.rptr = 0;
  2214. }
  2215. static void r600_disable_interrupt_state(struct radeon_device *rdev)
  2216. {
  2217. u32 tmp;
  2218. WREG32(CP_INT_CNTL, 0);
  2219. WREG32(GRBM_INT_CNTL, 0);
  2220. WREG32(DxMODE_INT_MASK, 0);
  2221. if (ASIC_IS_DCE3(rdev)) {
  2222. WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
  2223. WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
  2224. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2225. WREG32(DC_HPD1_INT_CONTROL, tmp);
  2226. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2227. WREG32(DC_HPD2_INT_CONTROL, tmp);
  2228. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2229. WREG32(DC_HPD3_INT_CONTROL, tmp);
  2230. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2231. WREG32(DC_HPD4_INT_CONTROL, tmp);
  2232. if (ASIC_IS_DCE32(rdev)) {
  2233. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2234. WREG32(DC_HPD5_INT_CONTROL, tmp);
  2235. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2236. WREG32(DC_HPD6_INT_CONTROL, tmp);
  2237. }
  2238. } else {
  2239. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  2240. WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
  2241. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  2242. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  2243. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  2244. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  2245. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  2246. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  2247. }
  2248. }
  2249. int r600_irq_init(struct radeon_device *rdev)
  2250. {
  2251. int ret = 0;
  2252. int rb_bufsz;
  2253. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  2254. /* allocate ring */
  2255. ret = r600_ih_ring_alloc(rdev);
  2256. if (ret)
  2257. return ret;
  2258. /* disable irqs */
  2259. r600_disable_interrupts(rdev);
  2260. /* init rlc */
  2261. ret = r600_rlc_init(rdev);
  2262. if (ret) {
  2263. r600_ih_ring_fini(rdev);
  2264. return ret;
  2265. }
  2266. /* setup interrupt control */
  2267. /* set dummy read address to ring address */
  2268. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  2269. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  2270. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  2271. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  2272. */
  2273. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  2274. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  2275. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  2276. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  2277. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  2278. rb_bufsz = drm_order(rdev->ih.ring_size / 4);
  2279. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  2280. IH_WPTR_OVERFLOW_CLEAR |
  2281. (rb_bufsz << 1));
  2282. /* WPTR writeback, not yet */
  2283. /*ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;*/
  2284. WREG32(IH_RB_WPTR_ADDR_LO, 0);
  2285. WREG32(IH_RB_WPTR_ADDR_HI, 0);
  2286. WREG32(IH_RB_CNTL, ih_rb_cntl);
  2287. /* set rptr, wptr to 0 */
  2288. WREG32(IH_RB_RPTR, 0);
  2289. WREG32(IH_RB_WPTR, 0);
  2290. /* Default settings for IH_CNTL (disabled at first) */
  2291. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
  2292. /* RPTR_REARM only works if msi's are enabled */
  2293. if (rdev->msi_enabled)
  2294. ih_cntl |= RPTR_REARM;
  2295. #ifdef __BIG_ENDIAN
  2296. ih_cntl |= IH_MC_SWAP(IH_MC_SWAP_32BIT);
  2297. #endif
  2298. WREG32(IH_CNTL, ih_cntl);
  2299. /* force the active interrupt state to all disabled */
  2300. if (rdev->family >= CHIP_CEDAR)
  2301. evergreen_disable_interrupt_state(rdev);
  2302. else
  2303. r600_disable_interrupt_state(rdev);
  2304. /* enable irqs */
  2305. r600_enable_interrupts(rdev);
  2306. return ret;
  2307. }
  2308. void r600_irq_suspend(struct radeon_device *rdev)
  2309. {
  2310. r600_irq_disable(rdev);
  2311. r600_rlc_stop(rdev);
  2312. }
  2313. void r600_irq_fini(struct radeon_device *rdev)
  2314. {
  2315. r600_irq_suspend(rdev);
  2316. r600_ih_ring_fini(rdev);
  2317. }
  2318. int r600_irq_set(struct radeon_device *rdev)
  2319. {
  2320. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  2321. u32 mode_int = 0;
  2322. u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
  2323. u32 hdmi1, hdmi2;
  2324. if (!rdev->irq.installed) {
  2325. WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n");
  2326. return -EINVAL;
  2327. }
  2328. /* don't enable anything if the ih is disabled */
  2329. if (!rdev->ih.enabled) {
  2330. r600_disable_interrupts(rdev);
  2331. /* force the active interrupt state to all disabled */
  2332. r600_disable_interrupt_state(rdev);
  2333. return 0;
  2334. }
  2335. hdmi1 = RREG32(R600_HDMI_BLOCK1 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
  2336. if (ASIC_IS_DCE3(rdev)) {
  2337. hdmi2 = RREG32(R600_HDMI_BLOCK3 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
  2338. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2339. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2340. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2341. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2342. if (ASIC_IS_DCE32(rdev)) {
  2343. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2344. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2345. }
  2346. } else {
  2347. hdmi2 = RREG32(R600_HDMI_BLOCK2 + R600_HDMI_CNTL) & ~R600_HDMI_INT_EN;
  2348. hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2349. hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2350. hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2351. }
  2352. if (rdev->irq.sw_int) {
  2353. DRM_DEBUG("r600_irq_set: sw int\n");
  2354. cp_int_cntl |= RB_INT_ENABLE;
  2355. }
  2356. if (rdev->irq.crtc_vblank_int[0]) {
  2357. DRM_DEBUG("r600_irq_set: vblank 0\n");
  2358. mode_int |= D1MODE_VBLANK_INT_MASK;
  2359. }
  2360. if (rdev->irq.crtc_vblank_int[1]) {
  2361. DRM_DEBUG("r600_irq_set: vblank 1\n");
  2362. mode_int |= D2MODE_VBLANK_INT_MASK;
  2363. }
  2364. if (rdev->irq.hpd[0]) {
  2365. DRM_DEBUG("r600_irq_set: hpd 1\n");
  2366. hpd1 |= DC_HPDx_INT_EN;
  2367. }
  2368. if (rdev->irq.hpd[1]) {
  2369. DRM_DEBUG("r600_irq_set: hpd 2\n");
  2370. hpd2 |= DC_HPDx_INT_EN;
  2371. }
  2372. if (rdev->irq.hpd[2]) {
  2373. DRM_DEBUG("r600_irq_set: hpd 3\n");
  2374. hpd3 |= DC_HPDx_INT_EN;
  2375. }
  2376. if (rdev->irq.hpd[3]) {
  2377. DRM_DEBUG("r600_irq_set: hpd 4\n");
  2378. hpd4 |= DC_HPDx_INT_EN;
  2379. }
  2380. if (rdev->irq.hpd[4]) {
  2381. DRM_DEBUG("r600_irq_set: hpd 5\n");
  2382. hpd5 |= DC_HPDx_INT_EN;
  2383. }
  2384. if (rdev->irq.hpd[5]) {
  2385. DRM_DEBUG("r600_irq_set: hpd 6\n");
  2386. hpd6 |= DC_HPDx_INT_EN;
  2387. }
  2388. if (rdev->irq.hdmi[0]) {
  2389. DRM_DEBUG("r600_irq_set: hdmi 1\n");
  2390. hdmi1 |= R600_HDMI_INT_EN;
  2391. }
  2392. if (rdev->irq.hdmi[1]) {
  2393. DRM_DEBUG("r600_irq_set: hdmi 2\n");
  2394. hdmi2 |= R600_HDMI_INT_EN;
  2395. }
  2396. WREG32(CP_INT_CNTL, cp_int_cntl);
  2397. WREG32(DxMODE_INT_MASK, mode_int);
  2398. WREG32(R600_HDMI_BLOCK1 + R600_HDMI_CNTL, hdmi1);
  2399. if (ASIC_IS_DCE3(rdev)) {
  2400. WREG32(R600_HDMI_BLOCK3 + R600_HDMI_CNTL, hdmi2);
  2401. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  2402. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  2403. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  2404. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  2405. if (ASIC_IS_DCE32(rdev)) {
  2406. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  2407. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  2408. }
  2409. } else {
  2410. WREG32(R600_HDMI_BLOCK2 + R600_HDMI_CNTL, hdmi2);
  2411. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
  2412. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
  2413. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
  2414. }
  2415. return 0;
  2416. }
  2417. static inline void r600_irq_ack(struct radeon_device *rdev,
  2418. u32 *disp_int,
  2419. u32 *disp_int_cont,
  2420. u32 *disp_int_cont2)
  2421. {
  2422. u32 tmp;
  2423. if (ASIC_IS_DCE3(rdev)) {
  2424. *disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
  2425. *disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
  2426. *disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
  2427. } else {
  2428. *disp_int = RREG32(DISP_INTERRUPT_STATUS);
  2429. *disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  2430. *disp_int_cont2 = 0;
  2431. }
  2432. if (*disp_int & LB_D1_VBLANK_INTERRUPT)
  2433. WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
  2434. if (*disp_int & LB_D1_VLINE_INTERRUPT)
  2435. WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
  2436. if (*disp_int & LB_D2_VBLANK_INTERRUPT)
  2437. WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
  2438. if (*disp_int & LB_D2_VLINE_INTERRUPT)
  2439. WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
  2440. if (*disp_int & DC_HPD1_INTERRUPT) {
  2441. if (ASIC_IS_DCE3(rdev)) {
  2442. tmp = RREG32(DC_HPD1_INT_CONTROL);
  2443. tmp |= DC_HPDx_INT_ACK;
  2444. WREG32(DC_HPD1_INT_CONTROL, tmp);
  2445. } else {
  2446. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
  2447. tmp |= DC_HPDx_INT_ACK;
  2448. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  2449. }
  2450. }
  2451. if (*disp_int & DC_HPD2_INTERRUPT) {
  2452. if (ASIC_IS_DCE3(rdev)) {
  2453. tmp = RREG32(DC_HPD2_INT_CONTROL);
  2454. tmp |= DC_HPDx_INT_ACK;
  2455. WREG32(DC_HPD2_INT_CONTROL, tmp);
  2456. } else {
  2457. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
  2458. tmp |= DC_HPDx_INT_ACK;
  2459. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  2460. }
  2461. }
  2462. if (*disp_int_cont & DC_HPD3_INTERRUPT) {
  2463. if (ASIC_IS_DCE3(rdev)) {
  2464. tmp = RREG32(DC_HPD3_INT_CONTROL);
  2465. tmp |= DC_HPDx_INT_ACK;
  2466. WREG32(DC_HPD3_INT_CONTROL, tmp);
  2467. } else {
  2468. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
  2469. tmp |= DC_HPDx_INT_ACK;
  2470. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  2471. }
  2472. }
  2473. if (*disp_int_cont & DC_HPD4_INTERRUPT) {
  2474. tmp = RREG32(DC_HPD4_INT_CONTROL);
  2475. tmp |= DC_HPDx_INT_ACK;
  2476. WREG32(DC_HPD4_INT_CONTROL, tmp);
  2477. }
  2478. if (ASIC_IS_DCE32(rdev)) {
  2479. if (*disp_int_cont2 & DC_HPD5_INTERRUPT) {
  2480. tmp = RREG32(DC_HPD5_INT_CONTROL);
  2481. tmp |= DC_HPDx_INT_ACK;
  2482. WREG32(DC_HPD5_INT_CONTROL, tmp);
  2483. }
  2484. if (*disp_int_cont2 & DC_HPD6_INTERRUPT) {
  2485. tmp = RREG32(DC_HPD5_INT_CONTROL);
  2486. tmp |= DC_HPDx_INT_ACK;
  2487. WREG32(DC_HPD6_INT_CONTROL, tmp);
  2488. }
  2489. }
  2490. if (RREG32(R600_HDMI_BLOCK1 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
  2491. WREG32_P(R600_HDMI_BLOCK1 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
  2492. }
  2493. if (ASIC_IS_DCE3(rdev)) {
  2494. if (RREG32(R600_HDMI_BLOCK3 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
  2495. WREG32_P(R600_HDMI_BLOCK3 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
  2496. }
  2497. } else {
  2498. if (RREG32(R600_HDMI_BLOCK2 + R600_HDMI_STATUS) & R600_HDMI_INT_PENDING) {
  2499. WREG32_P(R600_HDMI_BLOCK2 + R600_HDMI_CNTL, R600_HDMI_INT_ACK, ~R600_HDMI_INT_ACK);
  2500. }
  2501. }
  2502. }
  2503. void r600_irq_disable(struct radeon_device *rdev)
  2504. {
  2505. u32 disp_int, disp_int_cont, disp_int_cont2;
  2506. r600_disable_interrupts(rdev);
  2507. /* Wait and acknowledge irq */
  2508. mdelay(1);
  2509. r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
  2510. r600_disable_interrupt_state(rdev);
  2511. }
  2512. static inline u32 r600_get_ih_wptr(struct radeon_device *rdev)
  2513. {
  2514. u32 wptr, tmp;
  2515. /* XXX use writeback */
  2516. wptr = RREG32(IH_RB_WPTR);
  2517. if (wptr & RB_OVERFLOW) {
  2518. /* When a ring buffer overflow happen start parsing interrupt
  2519. * from the last not overwritten vector (wptr + 16). Hopefully
  2520. * this should allow us to catchup.
  2521. */
  2522. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  2523. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  2524. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  2525. tmp = RREG32(IH_RB_CNTL);
  2526. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  2527. WREG32(IH_RB_CNTL, tmp);
  2528. }
  2529. return (wptr & rdev->ih.ptr_mask);
  2530. }
  2531. /* r600 IV Ring
  2532. * Each IV ring entry is 128 bits:
  2533. * [7:0] - interrupt source id
  2534. * [31:8] - reserved
  2535. * [59:32] - interrupt source data
  2536. * [127:60] - reserved
  2537. *
  2538. * The basic interrupt vector entries
  2539. * are decoded as follows:
  2540. * src_id src_data description
  2541. * 1 0 D1 Vblank
  2542. * 1 1 D1 Vline
  2543. * 5 0 D2 Vblank
  2544. * 5 1 D2 Vline
  2545. * 19 0 FP Hot plug detection A
  2546. * 19 1 FP Hot plug detection B
  2547. * 19 2 DAC A auto-detection
  2548. * 19 3 DAC B auto-detection
  2549. * 21 4 HDMI block A
  2550. * 21 5 HDMI block B
  2551. * 176 - CP_INT RB
  2552. * 177 - CP_INT IB1
  2553. * 178 - CP_INT IB2
  2554. * 181 - EOP Interrupt
  2555. * 233 - GUI Idle
  2556. *
  2557. * Note, these are based on r600 and may need to be
  2558. * adjusted or added to on newer asics
  2559. */
  2560. int r600_irq_process(struct radeon_device *rdev)
  2561. {
  2562. u32 wptr = r600_get_ih_wptr(rdev);
  2563. u32 rptr = rdev->ih.rptr;
  2564. u32 src_id, src_data;
  2565. u32 ring_index, disp_int, disp_int_cont, disp_int_cont2;
  2566. unsigned long flags;
  2567. bool queue_hotplug = false;
  2568. DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  2569. if (!rdev->ih.enabled)
  2570. return IRQ_NONE;
  2571. spin_lock_irqsave(&rdev->ih.lock, flags);
  2572. if (rptr == wptr) {
  2573. spin_unlock_irqrestore(&rdev->ih.lock, flags);
  2574. return IRQ_NONE;
  2575. }
  2576. if (rdev->shutdown) {
  2577. spin_unlock_irqrestore(&rdev->ih.lock, flags);
  2578. return IRQ_NONE;
  2579. }
  2580. restart_ih:
  2581. /* display interrupts */
  2582. r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
  2583. rdev->ih.wptr = wptr;
  2584. while (rptr != wptr) {
  2585. /* wptr/rptr are in bytes! */
  2586. ring_index = rptr / 4;
  2587. src_id = rdev->ih.ring[ring_index] & 0xff;
  2588. src_data = rdev->ih.ring[ring_index + 1] & 0xfffffff;
  2589. switch (src_id) {
  2590. case 1: /* D1 vblank/vline */
  2591. switch (src_data) {
  2592. case 0: /* D1 vblank */
  2593. if (disp_int & LB_D1_VBLANK_INTERRUPT) {
  2594. drm_handle_vblank(rdev->ddev, 0);
  2595. rdev->pm.vblank_sync = true;
  2596. wake_up(&rdev->irq.vblank_queue);
  2597. disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  2598. DRM_DEBUG("IH: D1 vblank\n");
  2599. }
  2600. break;
  2601. case 1: /* D1 vline */
  2602. if (disp_int & LB_D1_VLINE_INTERRUPT) {
  2603. disp_int &= ~LB_D1_VLINE_INTERRUPT;
  2604. DRM_DEBUG("IH: D1 vline\n");
  2605. }
  2606. break;
  2607. default:
  2608. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2609. break;
  2610. }
  2611. break;
  2612. case 5: /* D2 vblank/vline */
  2613. switch (src_data) {
  2614. case 0: /* D2 vblank */
  2615. if (disp_int & LB_D2_VBLANK_INTERRUPT) {
  2616. drm_handle_vblank(rdev->ddev, 1);
  2617. rdev->pm.vblank_sync = true;
  2618. wake_up(&rdev->irq.vblank_queue);
  2619. disp_int &= ~LB_D2_VBLANK_INTERRUPT;
  2620. DRM_DEBUG("IH: D2 vblank\n");
  2621. }
  2622. break;
  2623. case 1: /* D1 vline */
  2624. if (disp_int & LB_D2_VLINE_INTERRUPT) {
  2625. disp_int &= ~LB_D2_VLINE_INTERRUPT;
  2626. DRM_DEBUG("IH: D2 vline\n");
  2627. }
  2628. break;
  2629. default:
  2630. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2631. break;
  2632. }
  2633. break;
  2634. case 19: /* HPD/DAC hotplug */
  2635. switch (src_data) {
  2636. case 0:
  2637. if (disp_int & DC_HPD1_INTERRUPT) {
  2638. disp_int &= ~DC_HPD1_INTERRUPT;
  2639. queue_hotplug = true;
  2640. DRM_DEBUG("IH: HPD1\n");
  2641. }
  2642. break;
  2643. case 1:
  2644. if (disp_int & DC_HPD2_INTERRUPT) {
  2645. disp_int &= ~DC_HPD2_INTERRUPT;
  2646. queue_hotplug = true;
  2647. DRM_DEBUG("IH: HPD2\n");
  2648. }
  2649. break;
  2650. case 4:
  2651. if (disp_int_cont & DC_HPD3_INTERRUPT) {
  2652. disp_int_cont &= ~DC_HPD3_INTERRUPT;
  2653. queue_hotplug = true;
  2654. DRM_DEBUG("IH: HPD3\n");
  2655. }
  2656. break;
  2657. case 5:
  2658. if (disp_int_cont & DC_HPD4_INTERRUPT) {
  2659. disp_int_cont &= ~DC_HPD4_INTERRUPT;
  2660. queue_hotplug = true;
  2661. DRM_DEBUG("IH: HPD4\n");
  2662. }
  2663. break;
  2664. case 10:
  2665. if (disp_int_cont2 & DC_HPD5_INTERRUPT) {
  2666. disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
  2667. queue_hotplug = true;
  2668. DRM_DEBUG("IH: HPD5\n");
  2669. }
  2670. break;
  2671. case 12:
  2672. if (disp_int_cont2 & DC_HPD6_INTERRUPT) {
  2673. disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
  2674. queue_hotplug = true;
  2675. DRM_DEBUG("IH: HPD6\n");
  2676. }
  2677. break;
  2678. default:
  2679. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2680. break;
  2681. }
  2682. break;
  2683. case 21: /* HDMI */
  2684. DRM_DEBUG("IH: HDMI: 0x%x\n", src_data);
  2685. r600_audio_schedule_polling(rdev);
  2686. break;
  2687. case 176: /* CP_INT in ring buffer */
  2688. case 177: /* CP_INT in IB1 */
  2689. case 178: /* CP_INT in IB2 */
  2690. DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
  2691. radeon_fence_process(rdev);
  2692. break;
  2693. case 181: /* CP EOP event */
  2694. DRM_DEBUG("IH: CP EOP\n");
  2695. break;
  2696. default:
  2697. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2698. break;
  2699. }
  2700. /* wptr/rptr are in bytes! */
  2701. rptr += 16;
  2702. rptr &= rdev->ih.ptr_mask;
  2703. }
  2704. /* make sure wptr hasn't changed while processing */
  2705. wptr = r600_get_ih_wptr(rdev);
  2706. if (wptr != rdev->ih.wptr)
  2707. goto restart_ih;
  2708. if (queue_hotplug)
  2709. queue_work(rdev->wq, &rdev->hotplug_work);
  2710. rdev->ih.rptr = rptr;
  2711. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  2712. spin_unlock_irqrestore(&rdev->ih.lock, flags);
  2713. return IRQ_HANDLED;
  2714. }
  2715. /*
  2716. * Debugfs info
  2717. */
  2718. #if defined(CONFIG_DEBUG_FS)
  2719. static int r600_debugfs_cp_ring_info(struct seq_file *m, void *data)
  2720. {
  2721. struct drm_info_node *node = (struct drm_info_node *) m->private;
  2722. struct drm_device *dev = node->minor->dev;
  2723. struct radeon_device *rdev = dev->dev_private;
  2724. unsigned count, i, j;
  2725. radeon_ring_free_size(rdev);
  2726. count = (rdev->cp.ring_size / 4) - rdev->cp.ring_free_dw;
  2727. seq_printf(m, "CP_STAT 0x%08x\n", RREG32(CP_STAT));
  2728. seq_printf(m, "CP_RB_WPTR 0x%08x\n", RREG32(CP_RB_WPTR));
  2729. seq_printf(m, "CP_RB_RPTR 0x%08x\n", RREG32(CP_RB_RPTR));
  2730. seq_printf(m, "driver's copy of the CP_RB_WPTR 0x%08x\n", rdev->cp.wptr);
  2731. seq_printf(m, "driver's copy of the CP_RB_RPTR 0x%08x\n", rdev->cp.rptr);
  2732. seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw);
  2733. seq_printf(m, "%u dwords in ring\n", count);
  2734. i = rdev->cp.rptr;
  2735. for (j = 0; j <= count; j++) {
  2736. seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]);
  2737. i = (i + 1) & rdev->cp.ptr_mask;
  2738. }
  2739. return 0;
  2740. }
  2741. static int r600_debugfs_mc_info(struct seq_file *m, void *data)
  2742. {
  2743. struct drm_info_node *node = (struct drm_info_node *) m->private;
  2744. struct drm_device *dev = node->minor->dev;
  2745. struct radeon_device *rdev = dev->dev_private;
  2746. DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
  2747. DREG32_SYS(m, rdev, VM_L2_STATUS);
  2748. return 0;
  2749. }
  2750. static struct drm_info_list r600_mc_info_list[] = {
  2751. {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
  2752. {"r600_ring_info", r600_debugfs_cp_ring_info, 0, NULL},
  2753. };
  2754. #endif
  2755. int r600_debugfs_mc_info_init(struct radeon_device *rdev)
  2756. {
  2757. #if defined(CONFIG_DEBUG_FS)
  2758. return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
  2759. #else
  2760. return 0;
  2761. #endif
  2762. }
  2763. /**
  2764. * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
  2765. * rdev: radeon device structure
  2766. * bo: buffer object struct which userspace is waiting for idle
  2767. *
  2768. * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
  2769. * through ring buffer, this leads to corruption in rendering, see
  2770. * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
  2771. * directly perform HDP flush by writing register through MMIO.
  2772. */
  2773. void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
  2774. {
  2775. WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  2776. }