r600.c 77 KB

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