r100.c 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973
  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/slab.h>
  30. #include "drmP.h"
  31. #include "drm.h"
  32. #include "radeon_drm.h"
  33. #include "radeon_reg.h"
  34. #include "radeon.h"
  35. #include "radeon_asic.h"
  36. #include "r100d.h"
  37. #include "rs100d.h"
  38. #include "rv200d.h"
  39. #include "rv250d.h"
  40. #include "atom.h"
  41. #include <linux/firmware.h>
  42. #include <linux/platform_device.h>
  43. #include "r100_reg_safe.h"
  44. #include "rn50_reg_safe.h"
  45. /* Firmware Names */
  46. #define FIRMWARE_R100 "radeon/R100_cp.bin"
  47. #define FIRMWARE_R200 "radeon/R200_cp.bin"
  48. #define FIRMWARE_R300 "radeon/R300_cp.bin"
  49. #define FIRMWARE_R420 "radeon/R420_cp.bin"
  50. #define FIRMWARE_RS690 "radeon/RS690_cp.bin"
  51. #define FIRMWARE_RS600 "radeon/RS600_cp.bin"
  52. #define FIRMWARE_R520 "radeon/R520_cp.bin"
  53. MODULE_FIRMWARE(FIRMWARE_R100);
  54. MODULE_FIRMWARE(FIRMWARE_R200);
  55. MODULE_FIRMWARE(FIRMWARE_R300);
  56. MODULE_FIRMWARE(FIRMWARE_R420);
  57. MODULE_FIRMWARE(FIRMWARE_RS690);
  58. MODULE_FIRMWARE(FIRMWARE_RS600);
  59. MODULE_FIRMWARE(FIRMWARE_R520);
  60. #include "r100_track.h"
  61. /* This files gather functions specifics to:
  62. * r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280
  63. */
  64. void r100_pre_page_flip(struct radeon_device *rdev, int crtc)
  65. {
  66. /* enable the pflip int */
  67. radeon_irq_kms_pflip_irq_get(rdev, crtc);
  68. }
  69. void r100_post_page_flip(struct radeon_device *rdev, int crtc)
  70. {
  71. /* disable the pflip int */
  72. radeon_irq_kms_pflip_irq_put(rdev, crtc);
  73. }
  74. u32 r100_page_flip(struct radeon_device *rdev, int crtc_id, u64 crtc_base)
  75. {
  76. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  77. u32 tmp = ((u32)crtc_base) | RADEON_CRTC_OFFSET__OFFSET_LOCK;
  78. int i;
  79. /* Lock the graphics update lock */
  80. /* update the scanout addresses */
  81. WREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset, tmp);
  82. /* Wait for update_pending to go high. */
  83. for (i = 0; i < rdev->usec_timeout; i++) {
  84. if (RREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset) & RADEON_CRTC_OFFSET__GUI_TRIG_OFFSET)
  85. break;
  86. udelay(1);
  87. }
  88. DRM_DEBUG("Update pending now high. Unlocking vupdate_lock.\n");
  89. /* Unlock the lock, so double-buffering can take place inside vblank */
  90. tmp &= ~RADEON_CRTC_OFFSET__OFFSET_LOCK;
  91. WREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset, tmp);
  92. /* Return current update_pending status: */
  93. return RREG32(RADEON_CRTC_OFFSET + radeon_crtc->crtc_offset) & RADEON_CRTC_OFFSET__GUI_TRIG_OFFSET;
  94. }
  95. void r100_pm_get_dynpm_state(struct radeon_device *rdev)
  96. {
  97. int i;
  98. rdev->pm.dynpm_can_upclock = true;
  99. rdev->pm.dynpm_can_downclock = true;
  100. switch (rdev->pm.dynpm_planned_action) {
  101. case DYNPM_ACTION_MINIMUM:
  102. rdev->pm.requested_power_state_index = 0;
  103. rdev->pm.dynpm_can_downclock = false;
  104. break;
  105. case DYNPM_ACTION_DOWNCLOCK:
  106. if (rdev->pm.current_power_state_index == 0) {
  107. rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
  108. rdev->pm.dynpm_can_downclock = false;
  109. } else {
  110. if (rdev->pm.active_crtc_count > 1) {
  111. for (i = 0; i < rdev->pm.num_power_states; i++) {
  112. if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
  113. continue;
  114. else if (i >= rdev->pm.current_power_state_index) {
  115. rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
  116. break;
  117. } else {
  118. rdev->pm.requested_power_state_index = i;
  119. break;
  120. }
  121. }
  122. } else
  123. rdev->pm.requested_power_state_index =
  124. rdev->pm.current_power_state_index - 1;
  125. }
  126. /* don't use the power state if crtcs are active and no display flag is set */
  127. if ((rdev->pm.active_crtc_count > 0) &&
  128. (rdev->pm.power_state[rdev->pm.requested_power_state_index].clock_info[0].flags &
  129. RADEON_PM_MODE_NO_DISPLAY)) {
  130. rdev->pm.requested_power_state_index++;
  131. }
  132. break;
  133. case DYNPM_ACTION_UPCLOCK:
  134. if (rdev->pm.current_power_state_index == (rdev->pm.num_power_states - 1)) {
  135. rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
  136. rdev->pm.dynpm_can_upclock = false;
  137. } else {
  138. if (rdev->pm.active_crtc_count > 1) {
  139. for (i = (rdev->pm.num_power_states - 1); i >= 0; i--) {
  140. if (rdev->pm.power_state[i].flags & RADEON_PM_STATE_SINGLE_DISPLAY_ONLY)
  141. continue;
  142. else if (i <= rdev->pm.current_power_state_index) {
  143. rdev->pm.requested_power_state_index = rdev->pm.current_power_state_index;
  144. break;
  145. } else {
  146. rdev->pm.requested_power_state_index = i;
  147. break;
  148. }
  149. }
  150. } else
  151. rdev->pm.requested_power_state_index =
  152. rdev->pm.current_power_state_index + 1;
  153. }
  154. break;
  155. case DYNPM_ACTION_DEFAULT:
  156. rdev->pm.requested_power_state_index = rdev->pm.default_power_state_index;
  157. rdev->pm.dynpm_can_upclock = false;
  158. break;
  159. case DYNPM_ACTION_NONE:
  160. default:
  161. DRM_ERROR("Requested mode for not defined action\n");
  162. return;
  163. }
  164. /* only one clock mode per power state */
  165. rdev->pm.requested_clock_mode_index = 0;
  166. DRM_DEBUG_DRIVER("Requested: e: %d m: %d p: %d\n",
  167. rdev->pm.power_state[rdev->pm.requested_power_state_index].
  168. clock_info[rdev->pm.requested_clock_mode_index].sclk,
  169. rdev->pm.power_state[rdev->pm.requested_power_state_index].
  170. clock_info[rdev->pm.requested_clock_mode_index].mclk,
  171. rdev->pm.power_state[rdev->pm.requested_power_state_index].
  172. pcie_lanes);
  173. }
  174. void r100_pm_init_profile(struct radeon_device *rdev)
  175. {
  176. /* default */
  177. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  178. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  179. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  180. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  181. /* low sh */
  182. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
  183. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
  184. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  185. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  186. /* mid sh */
  187. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
  188. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 0;
  189. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  190. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  191. /* high sh */
  192. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
  193. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  194. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  195. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
  196. /* low mh */
  197. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
  198. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  199. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  200. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  201. /* mid mh */
  202. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
  203. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  204. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  205. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  206. /* high mh */
  207. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
  208. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  209. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  210. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
  211. }
  212. void r100_pm_misc(struct radeon_device *rdev)
  213. {
  214. int requested_index = rdev->pm.requested_power_state_index;
  215. struct radeon_power_state *ps = &rdev->pm.power_state[requested_index];
  216. struct radeon_voltage *voltage = &ps->clock_info[0].voltage;
  217. u32 tmp, sclk_cntl, sclk_cntl2, sclk_more_cntl;
  218. if ((voltage->type == VOLTAGE_GPIO) && (voltage->gpio.valid)) {
  219. if (ps->misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) {
  220. tmp = RREG32(voltage->gpio.reg);
  221. if (voltage->active_high)
  222. tmp |= voltage->gpio.mask;
  223. else
  224. tmp &= ~(voltage->gpio.mask);
  225. WREG32(voltage->gpio.reg, tmp);
  226. if (voltage->delay)
  227. udelay(voltage->delay);
  228. } else {
  229. tmp = RREG32(voltage->gpio.reg);
  230. if (voltage->active_high)
  231. tmp &= ~voltage->gpio.mask;
  232. else
  233. tmp |= voltage->gpio.mask;
  234. WREG32(voltage->gpio.reg, tmp);
  235. if (voltage->delay)
  236. udelay(voltage->delay);
  237. }
  238. }
  239. sclk_cntl = RREG32_PLL(SCLK_CNTL);
  240. sclk_cntl2 = RREG32_PLL(SCLK_CNTL2);
  241. sclk_cntl2 &= ~REDUCED_SPEED_SCLK_SEL(3);
  242. sclk_more_cntl = RREG32_PLL(SCLK_MORE_CNTL);
  243. sclk_more_cntl &= ~VOLTAGE_DELAY_SEL(3);
  244. if (ps->misc & ATOM_PM_MISCINFO_ASIC_REDUCED_SPEED_SCLK_EN) {
  245. sclk_more_cntl |= REDUCED_SPEED_SCLK_EN;
  246. if (ps->misc & ATOM_PM_MISCINFO_DYN_CLK_3D_IDLE)
  247. sclk_cntl2 |= REDUCED_SPEED_SCLK_MODE;
  248. else
  249. sclk_cntl2 &= ~REDUCED_SPEED_SCLK_MODE;
  250. if (ps->misc & ATOM_PM_MISCINFO_DYNAMIC_CLOCK_DIVIDER_BY_2)
  251. sclk_cntl2 |= REDUCED_SPEED_SCLK_SEL(0);
  252. else if (ps->misc & ATOM_PM_MISCINFO_DYNAMIC_CLOCK_DIVIDER_BY_4)
  253. sclk_cntl2 |= REDUCED_SPEED_SCLK_SEL(2);
  254. } else
  255. sclk_more_cntl &= ~REDUCED_SPEED_SCLK_EN;
  256. if (ps->misc & ATOM_PM_MISCINFO_ASIC_DYNAMIC_VOLTAGE_EN) {
  257. sclk_more_cntl |= IO_CG_VOLTAGE_DROP;
  258. if (voltage->delay) {
  259. sclk_more_cntl |= VOLTAGE_DROP_SYNC;
  260. switch (voltage->delay) {
  261. case 33:
  262. sclk_more_cntl |= VOLTAGE_DELAY_SEL(0);
  263. break;
  264. case 66:
  265. sclk_more_cntl |= VOLTAGE_DELAY_SEL(1);
  266. break;
  267. case 99:
  268. sclk_more_cntl |= VOLTAGE_DELAY_SEL(2);
  269. break;
  270. case 132:
  271. sclk_more_cntl |= VOLTAGE_DELAY_SEL(3);
  272. break;
  273. }
  274. } else
  275. sclk_more_cntl &= ~VOLTAGE_DROP_SYNC;
  276. } else
  277. sclk_more_cntl &= ~IO_CG_VOLTAGE_DROP;
  278. if (ps->misc & ATOM_PM_MISCINFO_DYNAMIC_HDP_BLOCK_EN)
  279. sclk_cntl &= ~FORCE_HDP;
  280. else
  281. sclk_cntl |= FORCE_HDP;
  282. WREG32_PLL(SCLK_CNTL, sclk_cntl);
  283. WREG32_PLL(SCLK_CNTL2, sclk_cntl2);
  284. WREG32_PLL(SCLK_MORE_CNTL, sclk_more_cntl);
  285. /* set pcie lanes */
  286. if ((rdev->flags & RADEON_IS_PCIE) &&
  287. !(rdev->flags & RADEON_IS_IGP) &&
  288. rdev->asic->set_pcie_lanes &&
  289. (ps->pcie_lanes !=
  290. rdev->pm.power_state[rdev->pm.current_power_state_index].pcie_lanes)) {
  291. radeon_set_pcie_lanes(rdev,
  292. ps->pcie_lanes);
  293. DRM_DEBUG_DRIVER("Setting: p: %d\n", ps->pcie_lanes);
  294. }
  295. }
  296. void r100_pm_prepare(struct radeon_device *rdev)
  297. {
  298. struct drm_device *ddev = rdev->ddev;
  299. struct drm_crtc *crtc;
  300. struct radeon_crtc *radeon_crtc;
  301. u32 tmp;
  302. /* disable any active CRTCs */
  303. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  304. radeon_crtc = to_radeon_crtc(crtc);
  305. if (radeon_crtc->enabled) {
  306. if (radeon_crtc->crtc_id) {
  307. tmp = RREG32(RADEON_CRTC2_GEN_CNTL);
  308. tmp |= RADEON_CRTC2_DISP_REQ_EN_B;
  309. WREG32(RADEON_CRTC2_GEN_CNTL, tmp);
  310. } else {
  311. tmp = RREG32(RADEON_CRTC_GEN_CNTL);
  312. tmp |= RADEON_CRTC_DISP_REQ_EN_B;
  313. WREG32(RADEON_CRTC_GEN_CNTL, tmp);
  314. }
  315. }
  316. }
  317. }
  318. void r100_pm_finish(struct radeon_device *rdev)
  319. {
  320. struct drm_device *ddev = rdev->ddev;
  321. struct drm_crtc *crtc;
  322. struct radeon_crtc *radeon_crtc;
  323. u32 tmp;
  324. /* enable any active CRTCs */
  325. list_for_each_entry(crtc, &ddev->mode_config.crtc_list, head) {
  326. radeon_crtc = to_radeon_crtc(crtc);
  327. if (radeon_crtc->enabled) {
  328. if (radeon_crtc->crtc_id) {
  329. tmp = RREG32(RADEON_CRTC2_GEN_CNTL);
  330. tmp &= ~RADEON_CRTC2_DISP_REQ_EN_B;
  331. WREG32(RADEON_CRTC2_GEN_CNTL, tmp);
  332. } else {
  333. tmp = RREG32(RADEON_CRTC_GEN_CNTL);
  334. tmp &= ~RADEON_CRTC_DISP_REQ_EN_B;
  335. WREG32(RADEON_CRTC_GEN_CNTL, tmp);
  336. }
  337. }
  338. }
  339. }
  340. bool r100_gui_idle(struct radeon_device *rdev)
  341. {
  342. if (RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_ACTIVE)
  343. return false;
  344. else
  345. return true;
  346. }
  347. /* hpd for digital panel detect/disconnect */
  348. bool r100_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  349. {
  350. bool connected = false;
  351. switch (hpd) {
  352. case RADEON_HPD_1:
  353. if (RREG32(RADEON_FP_GEN_CNTL) & RADEON_FP_DETECT_SENSE)
  354. connected = true;
  355. break;
  356. case RADEON_HPD_2:
  357. if (RREG32(RADEON_FP2_GEN_CNTL) & RADEON_FP2_DETECT_SENSE)
  358. connected = true;
  359. break;
  360. default:
  361. break;
  362. }
  363. return connected;
  364. }
  365. void r100_hpd_set_polarity(struct radeon_device *rdev,
  366. enum radeon_hpd_id hpd)
  367. {
  368. u32 tmp;
  369. bool connected = r100_hpd_sense(rdev, hpd);
  370. switch (hpd) {
  371. case RADEON_HPD_1:
  372. tmp = RREG32(RADEON_FP_GEN_CNTL);
  373. if (connected)
  374. tmp &= ~RADEON_FP_DETECT_INT_POL;
  375. else
  376. tmp |= RADEON_FP_DETECT_INT_POL;
  377. WREG32(RADEON_FP_GEN_CNTL, tmp);
  378. break;
  379. case RADEON_HPD_2:
  380. tmp = RREG32(RADEON_FP2_GEN_CNTL);
  381. if (connected)
  382. tmp &= ~RADEON_FP2_DETECT_INT_POL;
  383. else
  384. tmp |= RADEON_FP2_DETECT_INT_POL;
  385. WREG32(RADEON_FP2_GEN_CNTL, tmp);
  386. break;
  387. default:
  388. break;
  389. }
  390. }
  391. void r100_hpd_init(struct radeon_device *rdev)
  392. {
  393. struct drm_device *dev = rdev->ddev;
  394. struct drm_connector *connector;
  395. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  396. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  397. switch (radeon_connector->hpd.hpd) {
  398. case RADEON_HPD_1:
  399. rdev->irq.hpd[0] = true;
  400. break;
  401. case RADEON_HPD_2:
  402. rdev->irq.hpd[1] = true;
  403. break;
  404. default:
  405. break;
  406. }
  407. radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd);
  408. }
  409. if (rdev->irq.installed)
  410. r100_irq_set(rdev);
  411. }
  412. void r100_hpd_fini(struct radeon_device *rdev)
  413. {
  414. struct drm_device *dev = rdev->ddev;
  415. struct drm_connector *connector;
  416. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  417. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  418. switch (radeon_connector->hpd.hpd) {
  419. case RADEON_HPD_1:
  420. rdev->irq.hpd[0] = false;
  421. break;
  422. case RADEON_HPD_2:
  423. rdev->irq.hpd[1] = false;
  424. break;
  425. default:
  426. break;
  427. }
  428. }
  429. }
  430. /*
  431. * PCI GART
  432. */
  433. void r100_pci_gart_tlb_flush(struct radeon_device *rdev)
  434. {
  435. /* TODO: can we do somethings here ? */
  436. /* It seems hw only cache one entry so we should discard this
  437. * entry otherwise if first GPU GART read hit this entry it
  438. * could end up in wrong address. */
  439. }
  440. int r100_pci_gart_init(struct radeon_device *rdev)
  441. {
  442. int r;
  443. if (rdev->gart.table.ram.ptr) {
  444. WARN(1, "R100 PCI GART already initialized\n");
  445. return 0;
  446. }
  447. /* Initialize common gart structure */
  448. r = radeon_gart_init(rdev);
  449. if (r)
  450. return r;
  451. rdev->gart.table_size = rdev->gart.num_gpu_pages * 4;
  452. rdev->asic->gart_tlb_flush = &r100_pci_gart_tlb_flush;
  453. rdev->asic->gart_set_page = &r100_pci_gart_set_page;
  454. return radeon_gart_table_ram_alloc(rdev);
  455. }
  456. /* required on r1xx, r2xx, r300, r(v)350, r420/r481, rs400/rs480 */
  457. void r100_enable_bm(struct radeon_device *rdev)
  458. {
  459. uint32_t tmp;
  460. /* Enable bus mastering */
  461. tmp = RREG32(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS;
  462. WREG32(RADEON_BUS_CNTL, tmp);
  463. }
  464. int r100_pci_gart_enable(struct radeon_device *rdev)
  465. {
  466. uint32_t tmp;
  467. radeon_gart_restore(rdev);
  468. /* discard memory request outside of configured range */
  469. tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS;
  470. WREG32(RADEON_AIC_CNTL, tmp);
  471. /* set address range for PCI address translate */
  472. WREG32(RADEON_AIC_LO_ADDR, rdev->mc.gtt_start);
  473. WREG32(RADEON_AIC_HI_ADDR, rdev->mc.gtt_end);
  474. /* set PCI GART page-table base address */
  475. WREG32(RADEON_AIC_PT_BASE, rdev->gart.table_addr);
  476. tmp = RREG32(RADEON_AIC_CNTL) | RADEON_PCIGART_TRANSLATE_EN;
  477. WREG32(RADEON_AIC_CNTL, tmp);
  478. r100_pci_gart_tlb_flush(rdev);
  479. rdev->gart.ready = true;
  480. return 0;
  481. }
  482. void r100_pci_gart_disable(struct radeon_device *rdev)
  483. {
  484. uint32_t tmp;
  485. /* discard memory request outside of configured range */
  486. tmp = RREG32(RADEON_AIC_CNTL) | RADEON_DIS_OUT_OF_PCI_GART_ACCESS;
  487. WREG32(RADEON_AIC_CNTL, tmp & ~RADEON_PCIGART_TRANSLATE_EN);
  488. WREG32(RADEON_AIC_LO_ADDR, 0);
  489. WREG32(RADEON_AIC_HI_ADDR, 0);
  490. }
  491. int r100_pci_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
  492. {
  493. if (i < 0 || i > rdev->gart.num_gpu_pages) {
  494. return -EINVAL;
  495. }
  496. rdev->gart.table.ram.ptr[i] = cpu_to_le32(lower_32_bits(addr));
  497. return 0;
  498. }
  499. void r100_pci_gart_fini(struct radeon_device *rdev)
  500. {
  501. radeon_gart_fini(rdev);
  502. r100_pci_gart_disable(rdev);
  503. radeon_gart_table_ram_free(rdev);
  504. }
  505. int r100_irq_set(struct radeon_device *rdev)
  506. {
  507. uint32_t tmp = 0;
  508. if (!rdev->irq.installed) {
  509. WARN(1, "Can't enable IRQ/MSI because no handler is installed\n");
  510. WREG32(R_000040_GEN_INT_CNTL, 0);
  511. return -EINVAL;
  512. }
  513. if (rdev->irq.sw_int) {
  514. tmp |= RADEON_SW_INT_ENABLE;
  515. }
  516. if (rdev->irq.gui_idle) {
  517. tmp |= RADEON_GUI_IDLE_MASK;
  518. }
  519. if (rdev->irq.crtc_vblank_int[0] ||
  520. rdev->irq.pflip[0]) {
  521. tmp |= RADEON_CRTC_VBLANK_MASK;
  522. }
  523. if (rdev->irq.crtc_vblank_int[1] ||
  524. rdev->irq.pflip[1]) {
  525. tmp |= RADEON_CRTC2_VBLANK_MASK;
  526. }
  527. if (rdev->irq.hpd[0]) {
  528. tmp |= RADEON_FP_DETECT_MASK;
  529. }
  530. if (rdev->irq.hpd[1]) {
  531. tmp |= RADEON_FP2_DETECT_MASK;
  532. }
  533. WREG32(RADEON_GEN_INT_CNTL, tmp);
  534. return 0;
  535. }
  536. void r100_irq_disable(struct radeon_device *rdev)
  537. {
  538. u32 tmp;
  539. WREG32(R_000040_GEN_INT_CNTL, 0);
  540. /* Wait and acknowledge irq */
  541. mdelay(1);
  542. tmp = RREG32(R_000044_GEN_INT_STATUS);
  543. WREG32(R_000044_GEN_INT_STATUS, tmp);
  544. }
  545. static inline uint32_t r100_irq_ack(struct radeon_device *rdev)
  546. {
  547. uint32_t irqs = RREG32(RADEON_GEN_INT_STATUS);
  548. uint32_t irq_mask = RADEON_SW_INT_TEST |
  549. RADEON_CRTC_VBLANK_STAT | RADEON_CRTC2_VBLANK_STAT |
  550. RADEON_FP_DETECT_STAT | RADEON_FP2_DETECT_STAT;
  551. /* the interrupt works, but the status bit is permanently asserted */
  552. if (rdev->irq.gui_idle && radeon_gui_idle(rdev)) {
  553. if (!rdev->irq.gui_idle_acked)
  554. irq_mask |= RADEON_GUI_IDLE_STAT;
  555. }
  556. if (irqs) {
  557. WREG32(RADEON_GEN_INT_STATUS, irqs);
  558. }
  559. return irqs & irq_mask;
  560. }
  561. int r100_irq_process(struct radeon_device *rdev)
  562. {
  563. uint32_t status, msi_rearm;
  564. bool queue_hotplug = false;
  565. /* reset gui idle ack. the status bit is broken */
  566. rdev->irq.gui_idle_acked = false;
  567. status = r100_irq_ack(rdev);
  568. if (!status) {
  569. return IRQ_NONE;
  570. }
  571. if (rdev->shutdown) {
  572. return IRQ_NONE;
  573. }
  574. while (status) {
  575. /* SW interrupt */
  576. if (status & RADEON_SW_INT_TEST) {
  577. radeon_fence_process(rdev);
  578. }
  579. /* gui idle interrupt */
  580. if (status & RADEON_GUI_IDLE_STAT) {
  581. rdev->irq.gui_idle_acked = true;
  582. rdev->pm.gui_idle = true;
  583. wake_up(&rdev->irq.idle_queue);
  584. }
  585. /* Vertical blank interrupts */
  586. if (status & RADEON_CRTC_VBLANK_STAT) {
  587. if (rdev->irq.crtc_vblank_int[0]) {
  588. drm_handle_vblank(rdev->ddev, 0);
  589. rdev->pm.vblank_sync = true;
  590. wake_up(&rdev->irq.vblank_queue);
  591. }
  592. if (rdev->irq.pflip[0])
  593. radeon_crtc_handle_flip(rdev, 0);
  594. }
  595. if (status & RADEON_CRTC2_VBLANK_STAT) {
  596. if (rdev->irq.crtc_vblank_int[1]) {
  597. drm_handle_vblank(rdev->ddev, 1);
  598. rdev->pm.vblank_sync = true;
  599. wake_up(&rdev->irq.vblank_queue);
  600. }
  601. if (rdev->irq.pflip[1])
  602. radeon_crtc_handle_flip(rdev, 1);
  603. }
  604. if (status & RADEON_FP_DETECT_STAT) {
  605. queue_hotplug = true;
  606. DRM_DEBUG("HPD1\n");
  607. }
  608. if (status & RADEON_FP2_DETECT_STAT) {
  609. queue_hotplug = true;
  610. DRM_DEBUG("HPD2\n");
  611. }
  612. status = r100_irq_ack(rdev);
  613. }
  614. /* reset gui idle ack. the status bit is broken */
  615. rdev->irq.gui_idle_acked = false;
  616. if (queue_hotplug)
  617. schedule_work(&rdev->hotplug_work);
  618. if (rdev->msi_enabled) {
  619. switch (rdev->family) {
  620. case CHIP_RS400:
  621. case CHIP_RS480:
  622. msi_rearm = RREG32(RADEON_AIC_CNTL) & ~RS400_MSI_REARM;
  623. WREG32(RADEON_AIC_CNTL, msi_rearm);
  624. WREG32(RADEON_AIC_CNTL, msi_rearm | RS400_MSI_REARM);
  625. break;
  626. default:
  627. WREG32(RADEON_MSI_REARM_EN, RV370_MSI_REARM_EN);
  628. break;
  629. }
  630. }
  631. return IRQ_HANDLED;
  632. }
  633. u32 r100_get_vblank_counter(struct radeon_device *rdev, int crtc)
  634. {
  635. if (crtc == 0)
  636. return RREG32(RADEON_CRTC_CRNT_FRAME);
  637. else
  638. return RREG32(RADEON_CRTC2_CRNT_FRAME);
  639. }
  640. /* Who ever call radeon_fence_emit should call ring_lock and ask
  641. * for enough space (today caller are ib schedule and buffer move) */
  642. void r100_fence_ring_emit(struct radeon_device *rdev,
  643. struct radeon_fence *fence)
  644. {
  645. /* We have to make sure that caches are flushed before
  646. * CPU might read something from VRAM. */
  647. radeon_ring_write(rdev, PACKET0(RADEON_RB3D_DSTCACHE_CTLSTAT, 0));
  648. radeon_ring_write(rdev, RADEON_RB3D_DC_FLUSH_ALL);
  649. radeon_ring_write(rdev, PACKET0(RADEON_RB3D_ZCACHE_CTLSTAT, 0));
  650. radeon_ring_write(rdev, RADEON_RB3D_ZC_FLUSH_ALL);
  651. /* Wait until IDLE & CLEAN */
  652. radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
  653. radeon_ring_write(rdev, RADEON_WAIT_2D_IDLECLEAN | RADEON_WAIT_3D_IDLECLEAN);
  654. radeon_ring_write(rdev, PACKET0(RADEON_HOST_PATH_CNTL, 0));
  655. radeon_ring_write(rdev, rdev->config.r100.hdp_cntl |
  656. RADEON_HDP_READ_BUFFER_INVALIDATE);
  657. radeon_ring_write(rdev, PACKET0(RADEON_HOST_PATH_CNTL, 0));
  658. radeon_ring_write(rdev, rdev->config.r100.hdp_cntl);
  659. /* Emit fence sequence & fire IRQ */
  660. radeon_ring_write(rdev, PACKET0(rdev->fence_drv.scratch_reg, 0));
  661. radeon_ring_write(rdev, fence->seq);
  662. radeon_ring_write(rdev, PACKET0(RADEON_GEN_INT_STATUS, 0));
  663. radeon_ring_write(rdev, RADEON_SW_INT_FIRE);
  664. }
  665. int r100_copy_blit(struct radeon_device *rdev,
  666. uint64_t src_offset,
  667. uint64_t dst_offset,
  668. unsigned num_gpu_pages,
  669. struct radeon_fence *fence)
  670. {
  671. uint32_t cur_pages;
  672. uint32_t stride_bytes = RADEON_GPU_PAGE_SIZE;
  673. uint32_t pitch;
  674. uint32_t stride_pixels;
  675. unsigned ndw;
  676. int num_loops;
  677. int r = 0;
  678. /* radeon limited to 16k stride */
  679. stride_bytes &= 0x3fff;
  680. /* radeon pitch is /64 */
  681. pitch = stride_bytes / 64;
  682. stride_pixels = stride_bytes / 4;
  683. num_loops = DIV_ROUND_UP(num_gpu_pages, 8191);
  684. /* Ask for enough room for blit + flush + fence */
  685. ndw = 64 + (10 * num_loops);
  686. r = radeon_ring_lock(rdev, ndw);
  687. if (r) {
  688. DRM_ERROR("radeon: moving bo (%d) asking for %u dw.\n", r, ndw);
  689. return -EINVAL;
  690. }
  691. while (num_gpu_pages > 0) {
  692. cur_pages = num_gpu_pages;
  693. if (cur_pages > 8191) {
  694. cur_pages = 8191;
  695. }
  696. num_gpu_pages -= cur_pages;
  697. /* pages are in Y direction - height
  698. page width in X direction - width */
  699. radeon_ring_write(rdev, PACKET3(PACKET3_BITBLT_MULTI, 8));
  700. radeon_ring_write(rdev,
  701. RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
  702. RADEON_GMC_DST_PITCH_OFFSET_CNTL |
  703. RADEON_GMC_SRC_CLIPPING |
  704. RADEON_GMC_DST_CLIPPING |
  705. RADEON_GMC_BRUSH_NONE |
  706. (RADEON_COLOR_FORMAT_ARGB8888 << 8) |
  707. RADEON_GMC_SRC_DATATYPE_COLOR |
  708. RADEON_ROP3_S |
  709. RADEON_DP_SRC_SOURCE_MEMORY |
  710. RADEON_GMC_CLR_CMP_CNTL_DIS |
  711. RADEON_GMC_WR_MSK_DIS);
  712. radeon_ring_write(rdev, (pitch << 22) | (src_offset >> 10));
  713. radeon_ring_write(rdev, (pitch << 22) | (dst_offset >> 10));
  714. radeon_ring_write(rdev, (0x1fff) | (0x1fff << 16));
  715. radeon_ring_write(rdev, 0);
  716. radeon_ring_write(rdev, (0x1fff) | (0x1fff << 16));
  717. radeon_ring_write(rdev, num_gpu_pages);
  718. radeon_ring_write(rdev, num_gpu_pages);
  719. radeon_ring_write(rdev, cur_pages | (stride_pixels << 16));
  720. }
  721. radeon_ring_write(rdev, PACKET0(RADEON_DSTCACHE_CTLSTAT, 0));
  722. radeon_ring_write(rdev, RADEON_RB2D_DC_FLUSH_ALL);
  723. radeon_ring_write(rdev, PACKET0(RADEON_WAIT_UNTIL, 0));
  724. radeon_ring_write(rdev,
  725. RADEON_WAIT_2D_IDLECLEAN |
  726. RADEON_WAIT_HOST_IDLECLEAN |
  727. RADEON_WAIT_DMA_GUI_IDLE);
  728. if (fence) {
  729. r = radeon_fence_emit(rdev, fence);
  730. }
  731. radeon_ring_unlock_commit(rdev);
  732. return r;
  733. }
  734. static int r100_cp_wait_for_idle(struct radeon_device *rdev)
  735. {
  736. unsigned i;
  737. u32 tmp;
  738. for (i = 0; i < rdev->usec_timeout; i++) {
  739. tmp = RREG32(R_000E40_RBBM_STATUS);
  740. if (!G_000E40_CP_CMDSTRM_BUSY(tmp)) {
  741. return 0;
  742. }
  743. udelay(1);
  744. }
  745. return -1;
  746. }
  747. void r100_ring_start(struct radeon_device *rdev)
  748. {
  749. int r;
  750. r = radeon_ring_lock(rdev, 2);
  751. if (r) {
  752. return;
  753. }
  754. radeon_ring_write(rdev, PACKET0(RADEON_ISYNC_CNTL, 0));
  755. radeon_ring_write(rdev,
  756. RADEON_ISYNC_ANY2D_IDLE3D |
  757. RADEON_ISYNC_ANY3D_IDLE2D |
  758. RADEON_ISYNC_WAIT_IDLEGUI |
  759. RADEON_ISYNC_CPSCRATCH_IDLEGUI);
  760. radeon_ring_unlock_commit(rdev);
  761. }
  762. /* Load the microcode for the CP */
  763. static int r100_cp_init_microcode(struct radeon_device *rdev)
  764. {
  765. struct platform_device *pdev;
  766. const char *fw_name = NULL;
  767. int err;
  768. DRM_DEBUG_KMS("\n");
  769. pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
  770. err = IS_ERR(pdev);
  771. if (err) {
  772. printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
  773. return -EINVAL;
  774. }
  775. if ((rdev->family == CHIP_R100) || (rdev->family == CHIP_RV100) ||
  776. (rdev->family == CHIP_RV200) || (rdev->family == CHIP_RS100) ||
  777. (rdev->family == CHIP_RS200)) {
  778. DRM_INFO("Loading R100 Microcode\n");
  779. fw_name = FIRMWARE_R100;
  780. } else if ((rdev->family == CHIP_R200) ||
  781. (rdev->family == CHIP_RV250) ||
  782. (rdev->family == CHIP_RV280) ||
  783. (rdev->family == CHIP_RS300)) {
  784. DRM_INFO("Loading R200 Microcode\n");
  785. fw_name = FIRMWARE_R200;
  786. } else if ((rdev->family == CHIP_R300) ||
  787. (rdev->family == CHIP_R350) ||
  788. (rdev->family == CHIP_RV350) ||
  789. (rdev->family == CHIP_RV380) ||
  790. (rdev->family == CHIP_RS400) ||
  791. (rdev->family == CHIP_RS480)) {
  792. DRM_INFO("Loading R300 Microcode\n");
  793. fw_name = FIRMWARE_R300;
  794. } else if ((rdev->family == CHIP_R420) ||
  795. (rdev->family == CHIP_R423) ||
  796. (rdev->family == CHIP_RV410)) {
  797. DRM_INFO("Loading R400 Microcode\n");
  798. fw_name = FIRMWARE_R420;
  799. } else if ((rdev->family == CHIP_RS690) ||
  800. (rdev->family == CHIP_RS740)) {
  801. DRM_INFO("Loading RS690/RS740 Microcode\n");
  802. fw_name = FIRMWARE_RS690;
  803. } else if (rdev->family == CHIP_RS600) {
  804. DRM_INFO("Loading RS600 Microcode\n");
  805. fw_name = FIRMWARE_RS600;
  806. } else if ((rdev->family == CHIP_RV515) ||
  807. (rdev->family == CHIP_R520) ||
  808. (rdev->family == CHIP_RV530) ||
  809. (rdev->family == CHIP_R580) ||
  810. (rdev->family == CHIP_RV560) ||
  811. (rdev->family == CHIP_RV570)) {
  812. DRM_INFO("Loading R500 Microcode\n");
  813. fw_name = FIRMWARE_R520;
  814. }
  815. err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
  816. platform_device_unregister(pdev);
  817. if (err) {
  818. printk(KERN_ERR "radeon_cp: Failed to load firmware \"%s\"\n",
  819. fw_name);
  820. } else if (rdev->me_fw->size % 8) {
  821. printk(KERN_ERR
  822. "radeon_cp: Bogus length %zu in firmware \"%s\"\n",
  823. rdev->me_fw->size, fw_name);
  824. err = -EINVAL;
  825. release_firmware(rdev->me_fw);
  826. rdev->me_fw = NULL;
  827. }
  828. return err;
  829. }
  830. static void r100_cp_load_microcode(struct radeon_device *rdev)
  831. {
  832. const __be32 *fw_data;
  833. int i, size;
  834. if (r100_gui_wait_for_idle(rdev)) {
  835. printk(KERN_WARNING "Failed to wait GUI idle while "
  836. "programming pipes. Bad things might happen.\n");
  837. }
  838. if (rdev->me_fw) {
  839. size = rdev->me_fw->size / 4;
  840. fw_data = (const __be32 *)&rdev->me_fw->data[0];
  841. WREG32(RADEON_CP_ME_RAM_ADDR, 0);
  842. for (i = 0; i < size; i += 2) {
  843. WREG32(RADEON_CP_ME_RAM_DATAH,
  844. be32_to_cpup(&fw_data[i]));
  845. WREG32(RADEON_CP_ME_RAM_DATAL,
  846. be32_to_cpup(&fw_data[i + 1]));
  847. }
  848. }
  849. }
  850. int r100_cp_init(struct radeon_device *rdev, unsigned ring_size)
  851. {
  852. unsigned rb_bufsz;
  853. unsigned rb_blksz;
  854. unsigned max_fetch;
  855. unsigned pre_write_timer;
  856. unsigned pre_write_limit;
  857. unsigned indirect2_start;
  858. unsigned indirect1_start;
  859. uint32_t tmp;
  860. int r;
  861. if (r100_debugfs_cp_init(rdev)) {
  862. DRM_ERROR("Failed to register debugfs file for CP !\n");
  863. }
  864. if (!rdev->me_fw) {
  865. r = r100_cp_init_microcode(rdev);
  866. if (r) {
  867. DRM_ERROR("Failed to load firmware!\n");
  868. return r;
  869. }
  870. }
  871. /* Align ring size */
  872. rb_bufsz = drm_order(ring_size / 8);
  873. ring_size = (1 << (rb_bufsz + 1)) * 4;
  874. r100_cp_load_microcode(rdev);
  875. r = radeon_ring_init(rdev, ring_size);
  876. if (r) {
  877. return r;
  878. }
  879. /* Each time the cp read 1024 bytes (16 dword/quadword) update
  880. * the rptr copy in system ram */
  881. rb_blksz = 9;
  882. /* cp will read 128bytes at a time (4 dwords) */
  883. max_fetch = 1;
  884. rdev->cp.align_mask = 16 - 1;
  885. /* Write to CP_RB_WPTR will be delayed for pre_write_timer clocks */
  886. pre_write_timer = 64;
  887. /* Force CP_RB_WPTR write if written more than one time before the
  888. * delay expire
  889. */
  890. pre_write_limit = 0;
  891. /* Setup the cp cache like this (cache size is 96 dwords) :
  892. * RING 0 to 15
  893. * INDIRECT1 16 to 79
  894. * INDIRECT2 80 to 95
  895. * So ring cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords))
  896. * indirect1 cache size is 64dwords (> (2 * max_fetch = 2 * 4dwords))
  897. * indirect2 cache size is 16dwords (> (2 * max_fetch = 2 * 4dwords))
  898. * Idea being that most of the gpu cmd will be through indirect1 buffer
  899. * so it gets the bigger cache.
  900. */
  901. indirect2_start = 80;
  902. indirect1_start = 16;
  903. /* cp setup */
  904. WREG32(0x718, pre_write_timer | (pre_write_limit << 28));
  905. tmp = (REG_SET(RADEON_RB_BUFSZ, rb_bufsz) |
  906. REG_SET(RADEON_RB_BLKSZ, rb_blksz) |
  907. REG_SET(RADEON_MAX_FETCH, max_fetch));
  908. #ifdef __BIG_ENDIAN
  909. tmp |= RADEON_BUF_SWAP_32BIT;
  910. #endif
  911. WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_NO_UPDATE);
  912. /* Set ring address */
  913. DRM_INFO("radeon: ring at 0x%016lX\n", (unsigned long)rdev->cp.gpu_addr);
  914. WREG32(RADEON_CP_RB_BASE, rdev->cp.gpu_addr);
  915. /* Force read & write ptr to 0 */
  916. WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA | RADEON_RB_NO_UPDATE);
  917. WREG32(RADEON_CP_RB_RPTR_WR, 0);
  918. rdev->cp.wptr = 0;
  919. WREG32(RADEON_CP_RB_WPTR, rdev->cp.wptr);
  920. /* set the wb address whether it's enabled or not */
  921. WREG32(R_00070C_CP_RB_RPTR_ADDR,
  922. S_00070C_RB_RPTR_ADDR((rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET) >> 2));
  923. WREG32(R_000774_SCRATCH_ADDR, rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET);
  924. if (rdev->wb.enabled)
  925. WREG32(R_000770_SCRATCH_UMSK, 0xff);
  926. else {
  927. tmp |= RADEON_RB_NO_UPDATE;
  928. WREG32(R_000770_SCRATCH_UMSK, 0);
  929. }
  930. WREG32(RADEON_CP_RB_CNTL, tmp);
  931. udelay(10);
  932. rdev->cp.rptr = RREG32(RADEON_CP_RB_RPTR);
  933. /* Set cp mode to bus mastering & enable cp*/
  934. WREG32(RADEON_CP_CSQ_MODE,
  935. REG_SET(RADEON_INDIRECT2_START, indirect2_start) |
  936. REG_SET(RADEON_INDIRECT1_START, indirect1_start));
  937. WREG32(RADEON_CP_RB_WPTR_DELAY, 0);
  938. WREG32(RADEON_CP_CSQ_MODE, 0x00004D4D);
  939. WREG32(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIBM_INDBM);
  940. radeon_ring_start(rdev);
  941. r = radeon_ring_test(rdev);
  942. if (r) {
  943. DRM_ERROR("radeon: cp isn't working (%d).\n", r);
  944. return r;
  945. }
  946. rdev->cp.ready = true;
  947. radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
  948. return 0;
  949. }
  950. void r100_cp_fini(struct radeon_device *rdev)
  951. {
  952. if (r100_cp_wait_for_idle(rdev)) {
  953. DRM_ERROR("Wait for CP idle timeout, shutting down CP.\n");
  954. }
  955. /* Disable ring */
  956. r100_cp_disable(rdev);
  957. radeon_ring_fini(rdev);
  958. DRM_INFO("radeon: cp finalized\n");
  959. }
  960. void r100_cp_disable(struct radeon_device *rdev)
  961. {
  962. /* Disable ring */
  963. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  964. rdev->cp.ready = false;
  965. WREG32(RADEON_CP_CSQ_MODE, 0);
  966. WREG32(RADEON_CP_CSQ_CNTL, 0);
  967. WREG32(R_000770_SCRATCH_UMSK, 0);
  968. if (r100_gui_wait_for_idle(rdev)) {
  969. printk(KERN_WARNING "Failed to wait GUI idle while "
  970. "programming pipes. Bad things might happen.\n");
  971. }
  972. }
  973. void r100_cp_commit(struct radeon_device *rdev)
  974. {
  975. WREG32(RADEON_CP_RB_WPTR, rdev->cp.wptr);
  976. (void)RREG32(RADEON_CP_RB_WPTR);
  977. }
  978. /*
  979. * CS functions
  980. */
  981. int r100_cs_parse_packet0(struct radeon_cs_parser *p,
  982. struct radeon_cs_packet *pkt,
  983. const unsigned *auth, unsigned n,
  984. radeon_packet0_check_t check)
  985. {
  986. unsigned reg;
  987. unsigned i, j, m;
  988. unsigned idx;
  989. int r;
  990. idx = pkt->idx + 1;
  991. reg = pkt->reg;
  992. /* Check that register fall into register range
  993. * determined by the number of entry (n) in the
  994. * safe register bitmap.
  995. */
  996. if (pkt->one_reg_wr) {
  997. if ((reg >> 7) > n) {
  998. return -EINVAL;
  999. }
  1000. } else {
  1001. if (((reg + (pkt->count << 2)) >> 7) > n) {
  1002. return -EINVAL;
  1003. }
  1004. }
  1005. for (i = 0; i <= pkt->count; i++, idx++) {
  1006. j = (reg >> 7);
  1007. m = 1 << ((reg >> 2) & 31);
  1008. if (auth[j] & m) {
  1009. r = check(p, pkt, idx, reg);
  1010. if (r) {
  1011. return r;
  1012. }
  1013. }
  1014. if (pkt->one_reg_wr) {
  1015. if (!(auth[j] & m)) {
  1016. break;
  1017. }
  1018. } else {
  1019. reg += 4;
  1020. }
  1021. }
  1022. return 0;
  1023. }
  1024. void r100_cs_dump_packet(struct radeon_cs_parser *p,
  1025. struct radeon_cs_packet *pkt)
  1026. {
  1027. volatile uint32_t *ib;
  1028. unsigned i;
  1029. unsigned idx;
  1030. ib = p->ib->ptr;
  1031. idx = pkt->idx;
  1032. for (i = 0; i <= (pkt->count + 1); i++, idx++) {
  1033. DRM_INFO("ib[%d]=0x%08X\n", idx, ib[idx]);
  1034. }
  1035. }
  1036. /**
  1037. * r100_cs_packet_parse() - parse cp packet and point ib index to next packet
  1038. * @parser: parser structure holding parsing context.
  1039. * @pkt: where to store packet informations
  1040. *
  1041. * Assume that chunk_ib_index is properly set. Will return -EINVAL
  1042. * if packet is bigger than remaining ib size. or if packets is unknown.
  1043. **/
  1044. int r100_cs_packet_parse(struct radeon_cs_parser *p,
  1045. struct radeon_cs_packet *pkt,
  1046. unsigned idx)
  1047. {
  1048. struct radeon_cs_chunk *ib_chunk = &p->chunks[p->chunk_ib_idx];
  1049. uint32_t header;
  1050. if (idx >= ib_chunk->length_dw) {
  1051. DRM_ERROR("Can not parse packet at %d after CS end %d !\n",
  1052. idx, ib_chunk->length_dw);
  1053. return -EINVAL;
  1054. }
  1055. header = radeon_get_ib_value(p, idx);
  1056. pkt->idx = idx;
  1057. pkt->type = CP_PACKET_GET_TYPE(header);
  1058. pkt->count = CP_PACKET_GET_COUNT(header);
  1059. switch (pkt->type) {
  1060. case PACKET_TYPE0:
  1061. pkt->reg = CP_PACKET0_GET_REG(header);
  1062. pkt->one_reg_wr = CP_PACKET0_GET_ONE_REG_WR(header);
  1063. break;
  1064. case PACKET_TYPE3:
  1065. pkt->opcode = CP_PACKET3_GET_OPCODE(header);
  1066. break;
  1067. case PACKET_TYPE2:
  1068. pkt->count = -1;
  1069. break;
  1070. default:
  1071. DRM_ERROR("Unknown packet type %d at %d !\n", pkt->type, idx);
  1072. return -EINVAL;
  1073. }
  1074. if ((pkt->count + 1 + pkt->idx) >= ib_chunk->length_dw) {
  1075. DRM_ERROR("Packet (%d:%d:%d) end after CS buffer (%d) !\n",
  1076. pkt->idx, pkt->type, pkt->count, ib_chunk->length_dw);
  1077. return -EINVAL;
  1078. }
  1079. return 0;
  1080. }
  1081. /**
  1082. * r100_cs_packet_next_vline() - parse userspace VLINE packet
  1083. * @parser: parser structure holding parsing context.
  1084. *
  1085. * Userspace sends a special sequence for VLINE waits.
  1086. * PACKET0 - VLINE_START_END + value
  1087. * PACKET0 - WAIT_UNTIL +_value
  1088. * RELOC (P3) - crtc_id in reloc.
  1089. *
  1090. * This function parses this and relocates the VLINE START END
  1091. * and WAIT UNTIL packets to the correct crtc.
  1092. * It also detects a switched off crtc and nulls out the
  1093. * wait in that case.
  1094. */
  1095. int r100_cs_packet_parse_vline(struct radeon_cs_parser *p)
  1096. {
  1097. struct drm_mode_object *obj;
  1098. struct drm_crtc *crtc;
  1099. struct radeon_crtc *radeon_crtc;
  1100. struct radeon_cs_packet p3reloc, waitreloc;
  1101. int crtc_id;
  1102. int r;
  1103. uint32_t header, h_idx, reg;
  1104. volatile uint32_t *ib;
  1105. ib = p->ib->ptr;
  1106. /* parse the wait until */
  1107. r = r100_cs_packet_parse(p, &waitreloc, p->idx);
  1108. if (r)
  1109. return r;
  1110. /* check its a wait until and only 1 count */
  1111. if (waitreloc.reg != RADEON_WAIT_UNTIL ||
  1112. waitreloc.count != 0) {
  1113. DRM_ERROR("vline wait had illegal wait until segment\n");
  1114. return -EINVAL;
  1115. }
  1116. if (radeon_get_ib_value(p, waitreloc.idx + 1) != RADEON_WAIT_CRTC_VLINE) {
  1117. DRM_ERROR("vline wait had illegal wait until\n");
  1118. return -EINVAL;
  1119. }
  1120. /* jump over the NOP */
  1121. r = r100_cs_packet_parse(p, &p3reloc, p->idx + waitreloc.count + 2);
  1122. if (r)
  1123. return r;
  1124. h_idx = p->idx - 2;
  1125. p->idx += waitreloc.count + 2;
  1126. p->idx += p3reloc.count + 2;
  1127. header = radeon_get_ib_value(p, h_idx);
  1128. crtc_id = radeon_get_ib_value(p, h_idx + 5);
  1129. reg = CP_PACKET0_GET_REG(header);
  1130. obj = drm_mode_object_find(p->rdev->ddev, crtc_id, DRM_MODE_OBJECT_CRTC);
  1131. if (!obj) {
  1132. DRM_ERROR("cannot find crtc %d\n", crtc_id);
  1133. return -EINVAL;
  1134. }
  1135. crtc = obj_to_crtc(obj);
  1136. radeon_crtc = to_radeon_crtc(crtc);
  1137. crtc_id = radeon_crtc->crtc_id;
  1138. if (!crtc->enabled) {
  1139. /* if the CRTC isn't enabled - we need to nop out the wait until */
  1140. ib[h_idx + 2] = PACKET2(0);
  1141. ib[h_idx + 3] = PACKET2(0);
  1142. } else if (crtc_id == 1) {
  1143. switch (reg) {
  1144. case AVIVO_D1MODE_VLINE_START_END:
  1145. header &= ~R300_CP_PACKET0_REG_MASK;
  1146. header |= AVIVO_D2MODE_VLINE_START_END >> 2;
  1147. break;
  1148. case RADEON_CRTC_GUI_TRIG_VLINE:
  1149. header &= ~R300_CP_PACKET0_REG_MASK;
  1150. header |= RADEON_CRTC2_GUI_TRIG_VLINE >> 2;
  1151. break;
  1152. default:
  1153. DRM_ERROR("unknown crtc reloc\n");
  1154. return -EINVAL;
  1155. }
  1156. ib[h_idx] = header;
  1157. ib[h_idx + 3] |= RADEON_ENG_DISPLAY_SELECT_CRTC1;
  1158. }
  1159. return 0;
  1160. }
  1161. /**
  1162. * r100_cs_packet_next_reloc() - parse next packet which should be reloc packet3
  1163. * @parser: parser structure holding parsing context.
  1164. * @data: pointer to relocation data
  1165. * @offset_start: starting offset
  1166. * @offset_mask: offset mask (to align start offset on)
  1167. * @reloc: reloc informations
  1168. *
  1169. * Check next packet is relocation packet3, do bo validation and compute
  1170. * GPU offset using the provided start.
  1171. **/
  1172. int r100_cs_packet_next_reloc(struct radeon_cs_parser *p,
  1173. struct radeon_cs_reloc **cs_reloc)
  1174. {
  1175. struct radeon_cs_chunk *relocs_chunk;
  1176. struct radeon_cs_packet p3reloc;
  1177. unsigned idx;
  1178. int r;
  1179. if (p->chunk_relocs_idx == -1) {
  1180. DRM_ERROR("No relocation chunk !\n");
  1181. return -EINVAL;
  1182. }
  1183. *cs_reloc = NULL;
  1184. relocs_chunk = &p->chunks[p->chunk_relocs_idx];
  1185. r = r100_cs_packet_parse(p, &p3reloc, p->idx);
  1186. if (r) {
  1187. return r;
  1188. }
  1189. p->idx += p3reloc.count + 2;
  1190. if (p3reloc.type != PACKET_TYPE3 || p3reloc.opcode != PACKET3_NOP) {
  1191. DRM_ERROR("No packet3 for relocation for packet at %d.\n",
  1192. p3reloc.idx);
  1193. r100_cs_dump_packet(p, &p3reloc);
  1194. return -EINVAL;
  1195. }
  1196. idx = radeon_get_ib_value(p, p3reloc.idx + 1);
  1197. if (idx >= relocs_chunk->length_dw) {
  1198. DRM_ERROR("Relocs at %d after relocations chunk end %d !\n",
  1199. idx, relocs_chunk->length_dw);
  1200. r100_cs_dump_packet(p, &p3reloc);
  1201. return -EINVAL;
  1202. }
  1203. /* FIXME: we assume reloc size is 4 dwords */
  1204. *cs_reloc = p->relocs_ptr[(idx / 4)];
  1205. return 0;
  1206. }
  1207. static int r100_get_vtx_size(uint32_t vtx_fmt)
  1208. {
  1209. int vtx_size;
  1210. vtx_size = 2;
  1211. /* ordered according to bits in spec */
  1212. if (vtx_fmt & RADEON_SE_VTX_FMT_W0)
  1213. vtx_size++;
  1214. if (vtx_fmt & RADEON_SE_VTX_FMT_FPCOLOR)
  1215. vtx_size += 3;
  1216. if (vtx_fmt & RADEON_SE_VTX_FMT_FPALPHA)
  1217. vtx_size++;
  1218. if (vtx_fmt & RADEON_SE_VTX_FMT_PKCOLOR)
  1219. vtx_size++;
  1220. if (vtx_fmt & RADEON_SE_VTX_FMT_FPSPEC)
  1221. vtx_size += 3;
  1222. if (vtx_fmt & RADEON_SE_VTX_FMT_FPFOG)
  1223. vtx_size++;
  1224. if (vtx_fmt & RADEON_SE_VTX_FMT_PKSPEC)
  1225. vtx_size++;
  1226. if (vtx_fmt & RADEON_SE_VTX_FMT_ST0)
  1227. vtx_size += 2;
  1228. if (vtx_fmt & RADEON_SE_VTX_FMT_ST1)
  1229. vtx_size += 2;
  1230. if (vtx_fmt & RADEON_SE_VTX_FMT_Q1)
  1231. vtx_size++;
  1232. if (vtx_fmt & RADEON_SE_VTX_FMT_ST2)
  1233. vtx_size += 2;
  1234. if (vtx_fmt & RADEON_SE_VTX_FMT_Q2)
  1235. vtx_size++;
  1236. if (vtx_fmt & RADEON_SE_VTX_FMT_ST3)
  1237. vtx_size += 2;
  1238. if (vtx_fmt & RADEON_SE_VTX_FMT_Q3)
  1239. vtx_size++;
  1240. if (vtx_fmt & RADEON_SE_VTX_FMT_Q0)
  1241. vtx_size++;
  1242. /* blend weight */
  1243. if (vtx_fmt & (0x7 << 15))
  1244. vtx_size += (vtx_fmt >> 15) & 0x7;
  1245. if (vtx_fmt & RADEON_SE_VTX_FMT_N0)
  1246. vtx_size += 3;
  1247. if (vtx_fmt & RADEON_SE_VTX_FMT_XY1)
  1248. vtx_size += 2;
  1249. if (vtx_fmt & RADEON_SE_VTX_FMT_Z1)
  1250. vtx_size++;
  1251. if (vtx_fmt & RADEON_SE_VTX_FMT_W1)
  1252. vtx_size++;
  1253. if (vtx_fmt & RADEON_SE_VTX_FMT_N1)
  1254. vtx_size++;
  1255. if (vtx_fmt & RADEON_SE_VTX_FMT_Z)
  1256. vtx_size++;
  1257. return vtx_size;
  1258. }
  1259. static int r100_packet0_check(struct radeon_cs_parser *p,
  1260. struct radeon_cs_packet *pkt,
  1261. unsigned idx, unsigned reg)
  1262. {
  1263. struct radeon_cs_reloc *reloc;
  1264. struct r100_cs_track *track;
  1265. volatile uint32_t *ib;
  1266. uint32_t tmp;
  1267. int r;
  1268. int i, face;
  1269. u32 tile_flags = 0;
  1270. u32 idx_value;
  1271. ib = p->ib->ptr;
  1272. track = (struct r100_cs_track *)p->track;
  1273. idx_value = radeon_get_ib_value(p, idx);
  1274. switch (reg) {
  1275. case RADEON_CRTC_GUI_TRIG_VLINE:
  1276. r = r100_cs_packet_parse_vline(p);
  1277. if (r) {
  1278. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1279. idx, reg);
  1280. r100_cs_dump_packet(p, pkt);
  1281. return r;
  1282. }
  1283. break;
  1284. /* FIXME: only allow PACKET3 blit? easier to check for out of
  1285. * range access */
  1286. case RADEON_DST_PITCH_OFFSET:
  1287. case RADEON_SRC_PITCH_OFFSET:
  1288. r = r100_reloc_pitch_offset(p, pkt, idx, reg);
  1289. if (r)
  1290. return r;
  1291. break;
  1292. case RADEON_RB3D_DEPTHOFFSET:
  1293. r = r100_cs_packet_next_reloc(p, &reloc);
  1294. if (r) {
  1295. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1296. idx, reg);
  1297. r100_cs_dump_packet(p, pkt);
  1298. return r;
  1299. }
  1300. track->zb.robj = reloc->robj;
  1301. track->zb.offset = idx_value;
  1302. track->zb_dirty = true;
  1303. ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
  1304. break;
  1305. case RADEON_RB3D_COLOROFFSET:
  1306. r = r100_cs_packet_next_reloc(p, &reloc);
  1307. if (r) {
  1308. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1309. idx, reg);
  1310. r100_cs_dump_packet(p, pkt);
  1311. return r;
  1312. }
  1313. track->cb[0].robj = reloc->robj;
  1314. track->cb[0].offset = idx_value;
  1315. track->cb_dirty = true;
  1316. ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
  1317. break;
  1318. case RADEON_PP_TXOFFSET_0:
  1319. case RADEON_PP_TXOFFSET_1:
  1320. case RADEON_PP_TXOFFSET_2:
  1321. i = (reg - RADEON_PP_TXOFFSET_0) / 24;
  1322. r = r100_cs_packet_next_reloc(p, &reloc);
  1323. if (r) {
  1324. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1325. idx, reg);
  1326. r100_cs_dump_packet(p, pkt);
  1327. return r;
  1328. }
  1329. ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
  1330. track->textures[i].robj = reloc->robj;
  1331. track->tex_dirty = true;
  1332. break;
  1333. case RADEON_PP_CUBIC_OFFSET_T0_0:
  1334. case RADEON_PP_CUBIC_OFFSET_T0_1:
  1335. case RADEON_PP_CUBIC_OFFSET_T0_2:
  1336. case RADEON_PP_CUBIC_OFFSET_T0_3:
  1337. case RADEON_PP_CUBIC_OFFSET_T0_4:
  1338. i = (reg - RADEON_PP_CUBIC_OFFSET_T0_0) / 4;
  1339. r = r100_cs_packet_next_reloc(p, &reloc);
  1340. if (r) {
  1341. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1342. idx, reg);
  1343. r100_cs_dump_packet(p, pkt);
  1344. return r;
  1345. }
  1346. track->textures[0].cube_info[i].offset = idx_value;
  1347. ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
  1348. track->textures[0].cube_info[i].robj = reloc->robj;
  1349. track->tex_dirty = true;
  1350. break;
  1351. case RADEON_PP_CUBIC_OFFSET_T1_0:
  1352. case RADEON_PP_CUBIC_OFFSET_T1_1:
  1353. case RADEON_PP_CUBIC_OFFSET_T1_2:
  1354. case RADEON_PP_CUBIC_OFFSET_T1_3:
  1355. case RADEON_PP_CUBIC_OFFSET_T1_4:
  1356. i = (reg - RADEON_PP_CUBIC_OFFSET_T1_0) / 4;
  1357. r = r100_cs_packet_next_reloc(p, &reloc);
  1358. if (r) {
  1359. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1360. idx, reg);
  1361. r100_cs_dump_packet(p, pkt);
  1362. return r;
  1363. }
  1364. track->textures[1].cube_info[i].offset = idx_value;
  1365. ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
  1366. track->textures[1].cube_info[i].robj = reloc->robj;
  1367. track->tex_dirty = true;
  1368. break;
  1369. case RADEON_PP_CUBIC_OFFSET_T2_0:
  1370. case RADEON_PP_CUBIC_OFFSET_T2_1:
  1371. case RADEON_PP_CUBIC_OFFSET_T2_2:
  1372. case RADEON_PP_CUBIC_OFFSET_T2_3:
  1373. case RADEON_PP_CUBIC_OFFSET_T2_4:
  1374. i = (reg - RADEON_PP_CUBIC_OFFSET_T2_0) / 4;
  1375. r = r100_cs_packet_next_reloc(p, &reloc);
  1376. if (r) {
  1377. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1378. idx, reg);
  1379. r100_cs_dump_packet(p, pkt);
  1380. return r;
  1381. }
  1382. track->textures[2].cube_info[i].offset = idx_value;
  1383. ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
  1384. track->textures[2].cube_info[i].robj = reloc->robj;
  1385. track->tex_dirty = true;
  1386. break;
  1387. case RADEON_RE_WIDTH_HEIGHT:
  1388. track->maxy = ((idx_value >> 16) & 0x7FF);
  1389. track->cb_dirty = true;
  1390. track->zb_dirty = true;
  1391. break;
  1392. case RADEON_RB3D_COLORPITCH:
  1393. r = r100_cs_packet_next_reloc(p, &reloc);
  1394. if (r) {
  1395. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1396. idx, reg);
  1397. r100_cs_dump_packet(p, pkt);
  1398. return r;
  1399. }
  1400. if (reloc->lobj.tiling_flags & RADEON_TILING_MACRO)
  1401. tile_flags |= RADEON_COLOR_TILE_ENABLE;
  1402. if (reloc->lobj.tiling_flags & RADEON_TILING_MICRO)
  1403. tile_flags |= RADEON_COLOR_MICROTILE_ENABLE;
  1404. tmp = idx_value & ~(0x7 << 16);
  1405. tmp |= tile_flags;
  1406. ib[idx] = tmp;
  1407. track->cb[0].pitch = idx_value & RADEON_COLORPITCH_MASK;
  1408. track->cb_dirty = true;
  1409. break;
  1410. case RADEON_RB3D_DEPTHPITCH:
  1411. track->zb.pitch = idx_value & RADEON_DEPTHPITCH_MASK;
  1412. track->zb_dirty = true;
  1413. break;
  1414. case RADEON_RB3D_CNTL:
  1415. switch ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f) {
  1416. case 7:
  1417. case 8:
  1418. case 9:
  1419. case 11:
  1420. case 12:
  1421. track->cb[0].cpp = 1;
  1422. break;
  1423. case 3:
  1424. case 4:
  1425. case 15:
  1426. track->cb[0].cpp = 2;
  1427. break;
  1428. case 6:
  1429. track->cb[0].cpp = 4;
  1430. break;
  1431. default:
  1432. DRM_ERROR("Invalid color buffer format (%d) !\n",
  1433. ((idx_value >> RADEON_RB3D_COLOR_FORMAT_SHIFT) & 0x1f));
  1434. return -EINVAL;
  1435. }
  1436. track->z_enabled = !!(idx_value & RADEON_Z_ENABLE);
  1437. track->cb_dirty = true;
  1438. track->zb_dirty = true;
  1439. break;
  1440. case RADEON_RB3D_ZSTENCILCNTL:
  1441. switch (idx_value & 0xf) {
  1442. case 0:
  1443. track->zb.cpp = 2;
  1444. break;
  1445. case 2:
  1446. case 3:
  1447. case 4:
  1448. case 5:
  1449. case 9:
  1450. case 11:
  1451. track->zb.cpp = 4;
  1452. break;
  1453. default:
  1454. break;
  1455. }
  1456. track->zb_dirty = true;
  1457. break;
  1458. case RADEON_RB3D_ZPASS_ADDR:
  1459. r = r100_cs_packet_next_reloc(p, &reloc);
  1460. if (r) {
  1461. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1462. idx, reg);
  1463. r100_cs_dump_packet(p, pkt);
  1464. return r;
  1465. }
  1466. ib[idx] = idx_value + ((u32)reloc->lobj.gpu_offset);
  1467. break;
  1468. case RADEON_PP_CNTL:
  1469. {
  1470. uint32_t temp = idx_value >> 4;
  1471. for (i = 0; i < track->num_texture; i++)
  1472. track->textures[i].enabled = !!(temp & (1 << i));
  1473. track->tex_dirty = true;
  1474. }
  1475. break;
  1476. case RADEON_SE_VF_CNTL:
  1477. track->vap_vf_cntl = idx_value;
  1478. break;
  1479. case RADEON_SE_VTX_FMT:
  1480. track->vtx_size = r100_get_vtx_size(idx_value);
  1481. break;
  1482. case RADEON_PP_TEX_SIZE_0:
  1483. case RADEON_PP_TEX_SIZE_1:
  1484. case RADEON_PP_TEX_SIZE_2:
  1485. i = (reg - RADEON_PP_TEX_SIZE_0) / 8;
  1486. track->textures[i].width = (idx_value & RADEON_TEX_USIZE_MASK) + 1;
  1487. track->textures[i].height = ((idx_value & RADEON_TEX_VSIZE_MASK) >> RADEON_TEX_VSIZE_SHIFT) + 1;
  1488. track->tex_dirty = true;
  1489. break;
  1490. case RADEON_PP_TEX_PITCH_0:
  1491. case RADEON_PP_TEX_PITCH_1:
  1492. case RADEON_PP_TEX_PITCH_2:
  1493. i = (reg - RADEON_PP_TEX_PITCH_0) / 8;
  1494. track->textures[i].pitch = idx_value + 32;
  1495. track->tex_dirty = true;
  1496. break;
  1497. case RADEON_PP_TXFILTER_0:
  1498. case RADEON_PP_TXFILTER_1:
  1499. case RADEON_PP_TXFILTER_2:
  1500. i = (reg - RADEON_PP_TXFILTER_0) / 24;
  1501. track->textures[i].num_levels = ((idx_value & RADEON_MAX_MIP_LEVEL_MASK)
  1502. >> RADEON_MAX_MIP_LEVEL_SHIFT);
  1503. tmp = (idx_value >> 23) & 0x7;
  1504. if (tmp == 2 || tmp == 6)
  1505. track->textures[i].roundup_w = false;
  1506. tmp = (idx_value >> 27) & 0x7;
  1507. if (tmp == 2 || tmp == 6)
  1508. track->textures[i].roundup_h = false;
  1509. track->tex_dirty = true;
  1510. break;
  1511. case RADEON_PP_TXFORMAT_0:
  1512. case RADEON_PP_TXFORMAT_1:
  1513. case RADEON_PP_TXFORMAT_2:
  1514. i = (reg - RADEON_PP_TXFORMAT_0) / 24;
  1515. if (idx_value & RADEON_TXFORMAT_NON_POWER2) {
  1516. track->textures[i].use_pitch = 1;
  1517. } else {
  1518. track->textures[i].use_pitch = 0;
  1519. track->textures[i].width = 1 << ((idx_value >> RADEON_TXFORMAT_WIDTH_SHIFT) & RADEON_TXFORMAT_WIDTH_MASK);
  1520. track->textures[i].height = 1 << ((idx_value >> RADEON_TXFORMAT_HEIGHT_SHIFT) & RADEON_TXFORMAT_HEIGHT_MASK);
  1521. }
  1522. if (idx_value & RADEON_TXFORMAT_CUBIC_MAP_ENABLE)
  1523. track->textures[i].tex_coord_type = 2;
  1524. switch ((idx_value & RADEON_TXFORMAT_FORMAT_MASK)) {
  1525. case RADEON_TXFORMAT_I8:
  1526. case RADEON_TXFORMAT_RGB332:
  1527. case RADEON_TXFORMAT_Y8:
  1528. track->textures[i].cpp = 1;
  1529. track->textures[i].compress_format = R100_TRACK_COMP_NONE;
  1530. break;
  1531. case RADEON_TXFORMAT_AI88:
  1532. case RADEON_TXFORMAT_ARGB1555:
  1533. case RADEON_TXFORMAT_RGB565:
  1534. case RADEON_TXFORMAT_ARGB4444:
  1535. case RADEON_TXFORMAT_VYUY422:
  1536. case RADEON_TXFORMAT_YVYU422:
  1537. case RADEON_TXFORMAT_SHADOW16:
  1538. case RADEON_TXFORMAT_LDUDV655:
  1539. case RADEON_TXFORMAT_DUDV88:
  1540. track->textures[i].cpp = 2;
  1541. track->textures[i].compress_format = R100_TRACK_COMP_NONE;
  1542. break;
  1543. case RADEON_TXFORMAT_ARGB8888:
  1544. case RADEON_TXFORMAT_RGBA8888:
  1545. case RADEON_TXFORMAT_SHADOW32:
  1546. case RADEON_TXFORMAT_LDUDUV8888:
  1547. track->textures[i].cpp = 4;
  1548. track->textures[i].compress_format = R100_TRACK_COMP_NONE;
  1549. break;
  1550. case RADEON_TXFORMAT_DXT1:
  1551. track->textures[i].cpp = 1;
  1552. track->textures[i].compress_format = R100_TRACK_COMP_DXT1;
  1553. break;
  1554. case RADEON_TXFORMAT_DXT23:
  1555. case RADEON_TXFORMAT_DXT45:
  1556. track->textures[i].cpp = 1;
  1557. track->textures[i].compress_format = R100_TRACK_COMP_DXT35;
  1558. break;
  1559. }
  1560. track->textures[i].cube_info[4].width = 1 << ((idx_value >> 16) & 0xf);
  1561. track->textures[i].cube_info[4].height = 1 << ((idx_value >> 20) & 0xf);
  1562. track->tex_dirty = true;
  1563. break;
  1564. case RADEON_PP_CUBIC_FACES_0:
  1565. case RADEON_PP_CUBIC_FACES_1:
  1566. case RADEON_PP_CUBIC_FACES_2:
  1567. tmp = idx_value;
  1568. i = (reg - RADEON_PP_CUBIC_FACES_0) / 4;
  1569. for (face = 0; face < 4; face++) {
  1570. track->textures[i].cube_info[face].width = 1 << ((tmp >> (face * 8)) & 0xf);
  1571. track->textures[i].cube_info[face].height = 1 << ((tmp >> ((face * 8) + 4)) & 0xf);
  1572. }
  1573. track->tex_dirty = true;
  1574. break;
  1575. default:
  1576. printk(KERN_ERR "Forbidden register 0x%04X in cs at %d\n",
  1577. reg, idx);
  1578. return -EINVAL;
  1579. }
  1580. return 0;
  1581. }
  1582. int r100_cs_track_check_pkt3_indx_buffer(struct radeon_cs_parser *p,
  1583. struct radeon_cs_packet *pkt,
  1584. struct radeon_bo *robj)
  1585. {
  1586. unsigned idx;
  1587. u32 value;
  1588. idx = pkt->idx + 1;
  1589. value = radeon_get_ib_value(p, idx + 2);
  1590. if ((value + 1) > radeon_bo_size(robj)) {
  1591. DRM_ERROR("[drm] Buffer too small for PACKET3 INDX_BUFFER "
  1592. "(need %u have %lu) !\n",
  1593. value + 1,
  1594. radeon_bo_size(robj));
  1595. return -EINVAL;
  1596. }
  1597. return 0;
  1598. }
  1599. static int r100_packet3_check(struct radeon_cs_parser *p,
  1600. struct radeon_cs_packet *pkt)
  1601. {
  1602. struct radeon_cs_reloc *reloc;
  1603. struct r100_cs_track *track;
  1604. unsigned idx;
  1605. volatile uint32_t *ib;
  1606. int r;
  1607. ib = p->ib->ptr;
  1608. idx = pkt->idx + 1;
  1609. track = (struct r100_cs_track *)p->track;
  1610. switch (pkt->opcode) {
  1611. case PACKET3_3D_LOAD_VBPNTR:
  1612. r = r100_packet3_load_vbpntr(p, pkt, idx);
  1613. if (r)
  1614. return r;
  1615. break;
  1616. case PACKET3_INDX_BUFFER:
  1617. r = r100_cs_packet_next_reloc(p, &reloc);
  1618. if (r) {
  1619. DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode);
  1620. r100_cs_dump_packet(p, pkt);
  1621. return r;
  1622. }
  1623. ib[idx+1] = radeon_get_ib_value(p, idx+1) + ((u32)reloc->lobj.gpu_offset);
  1624. r = r100_cs_track_check_pkt3_indx_buffer(p, pkt, reloc->robj);
  1625. if (r) {
  1626. return r;
  1627. }
  1628. break;
  1629. case 0x23:
  1630. /* 3D_RNDR_GEN_INDX_PRIM on r100/r200 */
  1631. r = r100_cs_packet_next_reloc(p, &reloc);
  1632. if (r) {
  1633. DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode);
  1634. r100_cs_dump_packet(p, pkt);
  1635. return r;
  1636. }
  1637. ib[idx] = radeon_get_ib_value(p, idx) + ((u32)reloc->lobj.gpu_offset);
  1638. track->num_arrays = 1;
  1639. track->vtx_size = r100_get_vtx_size(radeon_get_ib_value(p, idx + 2));
  1640. track->arrays[0].robj = reloc->robj;
  1641. track->arrays[0].esize = track->vtx_size;
  1642. track->max_indx = radeon_get_ib_value(p, idx+1);
  1643. track->vap_vf_cntl = radeon_get_ib_value(p, idx+3);
  1644. track->immd_dwords = pkt->count - 1;
  1645. r = r100_cs_track_check(p->rdev, track);
  1646. if (r)
  1647. return r;
  1648. break;
  1649. case PACKET3_3D_DRAW_IMMD:
  1650. if (((radeon_get_ib_value(p, idx + 1) >> 4) & 0x3) != 3) {
  1651. DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
  1652. return -EINVAL;
  1653. }
  1654. track->vtx_size = r100_get_vtx_size(radeon_get_ib_value(p, idx + 0));
  1655. track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
  1656. track->immd_dwords = pkt->count - 1;
  1657. r = r100_cs_track_check(p->rdev, track);
  1658. if (r)
  1659. return r;
  1660. break;
  1661. /* triggers drawing using in-packet vertex data */
  1662. case PACKET3_3D_DRAW_IMMD_2:
  1663. if (((radeon_get_ib_value(p, idx) >> 4) & 0x3) != 3) {
  1664. DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
  1665. return -EINVAL;
  1666. }
  1667. track->vap_vf_cntl = radeon_get_ib_value(p, idx);
  1668. track->immd_dwords = pkt->count;
  1669. r = r100_cs_track_check(p->rdev, track);
  1670. if (r)
  1671. return r;
  1672. break;
  1673. /* triggers drawing using in-packet vertex data */
  1674. case PACKET3_3D_DRAW_VBUF_2:
  1675. track->vap_vf_cntl = radeon_get_ib_value(p, idx);
  1676. r = r100_cs_track_check(p->rdev, track);
  1677. if (r)
  1678. return r;
  1679. break;
  1680. /* triggers drawing of vertex buffers setup elsewhere */
  1681. case PACKET3_3D_DRAW_INDX_2:
  1682. track->vap_vf_cntl = radeon_get_ib_value(p, idx);
  1683. r = r100_cs_track_check(p->rdev, track);
  1684. if (r)
  1685. return r;
  1686. break;
  1687. /* triggers drawing using indices to vertex buffer */
  1688. case PACKET3_3D_DRAW_VBUF:
  1689. track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
  1690. r = r100_cs_track_check(p->rdev, track);
  1691. if (r)
  1692. return r;
  1693. break;
  1694. /* triggers drawing of vertex buffers setup elsewhere */
  1695. case PACKET3_3D_DRAW_INDX:
  1696. track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
  1697. r = r100_cs_track_check(p->rdev, track);
  1698. if (r)
  1699. return r;
  1700. break;
  1701. /* triggers drawing using indices to vertex buffer */
  1702. case PACKET3_3D_CLEAR_HIZ:
  1703. case PACKET3_3D_CLEAR_ZMASK:
  1704. if (p->rdev->hyperz_filp != p->filp)
  1705. return -EINVAL;
  1706. break;
  1707. case PACKET3_NOP:
  1708. break;
  1709. default:
  1710. DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
  1711. return -EINVAL;
  1712. }
  1713. return 0;
  1714. }
  1715. int r100_cs_parse(struct radeon_cs_parser *p)
  1716. {
  1717. struct radeon_cs_packet pkt;
  1718. struct r100_cs_track *track;
  1719. int r;
  1720. track = kzalloc(sizeof(*track), GFP_KERNEL);
  1721. r100_cs_track_clear(p->rdev, track);
  1722. p->track = track;
  1723. do {
  1724. r = r100_cs_packet_parse(p, &pkt, p->idx);
  1725. if (r) {
  1726. return r;
  1727. }
  1728. p->idx += pkt.count + 2;
  1729. switch (pkt.type) {
  1730. case PACKET_TYPE0:
  1731. if (p->rdev->family >= CHIP_R200)
  1732. r = r100_cs_parse_packet0(p, &pkt,
  1733. p->rdev->config.r100.reg_safe_bm,
  1734. p->rdev->config.r100.reg_safe_bm_size,
  1735. &r200_packet0_check);
  1736. else
  1737. r = r100_cs_parse_packet0(p, &pkt,
  1738. p->rdev->config.r100.reg_safe_bm,
  1739. p->rdev->config.r100.reg_safe_bm_size,
  1740. &r100_packet0_check);
  1741. break;
  1742. case PACKET_TYPE2:
  1743. break;
  1744. case PACKET_TYPE3:
  1745. r = r100_packet3_check(p, &pkt);
  1746. break;
  1747. default:
  1748. DRM_ERROR("Unknown packet type %d !\n",
  1749. pkt.type);
  1750. return -EINVAL;
  1751. }
  1752. if (r) {
  1753. return r;
  1754. }
  1755. } while (p->idx < p->chunks[p->chunk_ib_idx].length_dw);
  1756. return 0;
  1757. }
  1758. /*
  1759. * Global GPU functions
  1760. */
  1761. void r100_errata(struct radeon_device *rdev)
  1762. {
  1763. rdev->pll_errata = 0;
  1764. if (rdev->family == CHIP_RV200 || rdev->family == CHIP_RS200) {
  1765. rdev->pll_errata |= CHIP_ERRATA_PLL_DUMMYREADS;
  1766. }
  1767. if (rdev->family == CHIP_RV100 ||
  1768. rdev->family == CHIP_RS100 ||
  1769. rdev->family == CHIP_RS200) {
  1770. rdev->pll_errata |= CHIP_ERRATA_PLL_DELAY;
  1771. }
  1772. }
  1773. /* Wait for vertical sync on primary CRTC */
  1774. void r100_gpu_wait_for_vsync(struct radeon_device *rdev)
  1775. {
  1776. uint32_t crtc_gen_cntl, tmp;
  1777. int i;
  1778. crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL);
  1779. if ((crtc_gen_cntl & RADEON_CRTC_DISP_REQ_EN_B) ||
  1780. !(crtc_gen_cntl & RADEON_CRTC_EN)) {
  1781. return;
  1782. }
  1783. /* Clear the CRTC_VBLANK_SAVE bit */
  1784. WREG32(RADEON_CRTC_STATUS, RADEON_CRTC_VBLANK_SAVE_CLEAR);
  1785. for (i = 0; i < rdev->usec_timeout; i++) {
  1786. tmp = RREG32(RADEON_CRTC_STATUS);
  1787. if (tmp & RADEON_CRTC_VBLANK_SAVE) {
  1788. return;
  1789. }
  1790. DRM_UDELAY(1);
  1791. }
  1792. }
  1793. /* Wait for vertical sync on secondary CRTC */
  1794. void r100_gpu_wait_for_vsync2(struct radeon_device *rdev)
  1795. {
  1796. uint32_t crtc2_gen_cntl, tmp;
  1797. int i;
  1798. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  1799. if ((crtc2_gen_cntl & RADEON_CRTC2_DISP_REQ_EN_B) ||
  1800. !(crtc2_gen_cntl & RADEON_CRTC2_EN))
  1801. return;
  1802. /* Clear the CRTC_VBLANK_SAVE bit */
  1803. WREG32(RADEON_CRTC2_STATUS, RADEON_CRTC2_VBLANK_SAVE_CLEAR);
  1804. for (i = 0; i < rdev->usec_timeout; i++) {
  1805. tmp = RREG32(RADEON_CRTC2_STATUS);
  1806. if (tmp & RADEON_CRTC2_VBLANK_SAVE) {
  1807. return;
  1808. }
  1809. DRM_UDELAY(1);
  1810. }
  1811. }
  1812. int r100_rbbm_fifo_wait_for_entry(struct radeon_device *rdev, unsigned n)
  1813. {
  1814. unsigned i;
  1815. uint32_t tmp;
  1816. for (i = 0; i < rdev->usec_timeout; i++) {
  1817. tmp = RREG32(RADEON_RBBM_STATUS) & RADEON_RBBM_FIFOCNT_MASK;
  1818. if (tmp >= n) {
  1819. return 0;
  1820. }
  1821. DRM_UDELAY(1);
  1822. }
  1823. return -1;
  1824. }
  1825. int r100_gui_wait_for_idle(struct radeon_device *rdev)
  1826. {
  1827. unsigned i;
  1828. uint32_t tmp;
  1829. if (r100_rbbm_fifo_wait_for_entry(rdev, 64)) {
  1830. printk(KERN_WARNING "radeon: wait for empty RBBM fifo failed !"
  1831. " Bad things might happen.\n");
  1832. }
  1833. for (i = 0; i < rdev->usec_timeout; i++) {
  1834. tmp = RREG32(RADEON_RBBM_STATUS);
  1835. if (!(tmp & RADEON_RBBM_ACTIVE)) {
  1836. return 0;
  1837. }
  1838. DRM_UDELAY(1);
  1839. }
  1840. return -1;
  1841. }
  1842. int r100_mc_wait_for_idle(struct radeon_device *rdev)
  1843. {
  1844. unsigned i;
  1845. uint32_t tmp;
  1846. for (i = 0; i < rdev->usec_timeout; i++) {
  1847. /* read MC_STATUS */
  1848. tmp = RREG32(RADEON_MC_STATUS);
  1849. if (tmp & RADEON_MC_IDLE) {
  1850. return 0;
  1851. }
  1852. DRM_UDELAY(1);
  1853. }
  1854. return -1;
  1855. }
  1856. void r100_gpu_lockup_update(struct r100_gpu_lockup *lockup, struct radeon_cp *cp)
  1857. {
  1858. lockup->last_cp_rptr = cp->rptr;
  1859. lockup->last_jiffies = jiffies;
  1860. }
  1861. /**
  1862. * r100_gpu_cp_is_lockup() - check if CP is lockup by recording information
  1863. * @rdev: radeon device structure
  1864. * @lockup: r100_gpu_lockup structure holding CP lockup tracking informations
  1865. * @cp: radeon_cp structure holding CP information
  1866. *
  1867. * We don't need to initialize the lockup tracking information as we will either
  1868. * have CP rptr to a different value of jiffies wrap around which will force
  1869. * initialization of the lockup tracking informations.
  1870. *
  1871. * A possible false positivie is if we get call after while and last_cp_rptr ==
  1872. * the current CP rptr, even if it's unlikely it might happen. To avoid this
  1873. * if the elapsed time since last call is bigger than 2 second than we return
  1874. * false and update the tracking information. Due to this the caller must call
  1875. * r100_gpu_cp_is_lockup several time in less than 2sec for lockup to be reported
  1876. * the fencing code should be cautious about that.
  1877. *
  1878. * Caller should write to the ring to force CP to do something so we don't get
  1879. * false positive when CP is just gived nothing to do.
  1880. *
  1881. **/
  1882. bool r100_gpu_cp_is_lockup(struct radeon_device *rdev, struct r100_gpu_lockup *lockup, struct radeon_cp *cp)
  1883. {
  1884. unsigned long cjiffies, elapsed;
  1885. cjiffies = jiffies;
  1886. if (!time_after(cjiffies, lockup->last_jiffies)) {
  1887. /* likely a wrap around */
  1888. lockup->last_cp_rptr = cp->rptr;
  1889. lockup->last_jiffies = jiffies;
  1890. return false;
  1891. }
  1892. if (cp->rptr != lockup->last_cp_rptr) {
  1893. /* CP is still working no lockup */
  1894. lockup->last_cp_rptr = cp->rptr;
  1895. lockup->last_jiffies = jiffies;
  1896. return false;
  1897. }
  1898. elapsed = jiffies_to_msecs(cjiffies - lockup->last_jiffies);
  1899. if (elapsed >= 10000) {
  1900. dev_err(rdev->dev, "GPU lockup CP stall for more than %lumsec\n", elapsed);
  1901. return true;
  1902. }
  1903. /* give a chance to the GPU ... */
  1904. return false;
  1905. }
  1906. bool r100_gpu_is_lockup(struct radeon_device *rdev)
  1907. {
  1908. u32 rbbm_status;
  1909. int r;
  1910. rbbm_status = RREG32(R_000E40_RBBM_STATUS);
  1911. if (!G_000E40_GUI_ACTIVE(rbbm_status)) {
  1912. r100_gpu_lockup_update(&rdev->config.r100.lockup, &rdev->cp);
  1913. return false;
  1914. }
  1915. /* force CP activities */
  1916. r = radeon_ring_lock(rdev, 2);
  1917. if (!r) {
  1918. /* PACKET2 NOP */
  1919. radeon_ring_write(rdev, 0x80000000);
  1920. radeon_ring_write(rdev, 0x80000000);
  1921. radeon_ring_unlock_commit(rdev);
  1922. }
  1923. rdev->cp.rptr = RREG32(RADEON_CP_RB_RPTR);
  1924. return r100_gpu_cp_is_lockup(rdev, &rdev->config.r100.lockup, &rdev->cp);
  1925. }
  1926. void r100_bm_disable(struct radeon_device *rdev)
  1927. {
  1928. u32 tmp;
  1929. u16 tmp16;
  1930. /* disable bus mastering */
  1931. tmp = RREG32(R_000030_BUS_CNTL);
  1932. WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000044);
  1933. mdelay(1);
  1934. WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000042);
  1935. mdelay(1);
  1936. WREG32(R_000030_BUS_CNTL, (tmp & 0xFFFFFFFF) | 0x00000040);
  1937. tmp = RREG32(RADEON_BUS_CNTL);
  1938. mdelay(1);
  1939. pci_read_config_word(rdev->pdev, 0x4, &tmp16);
  1940. pci_write_config_word(rdev->pdev, 0x4, tmp16 & 0xFFFB);
  1941. mdelay(1);
  1942. }
  1943. int r100_asic_reset(struct radeon_device *rdev)
  1944. {
  1945. struct r100_mc_save save;
  1946. u32 status, tmp;
  1947. int ret = 0;
  1948. status = RREG32(R_000E40_RBBM_STATUS);
  1949. if (!G_000E40_GUI_ACTIVE(status)) {
  1950. return 0;
  1951. }
  1952. r100_mc_stop(rdev, &save);
  1953. status = RREG32(R_000E40_RBBM_STATUS);
  1954. dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
  1955. /* stop CP */
  1956. WREG32(RADEON_CP_CSQ_CNTL, 0);
  1957. tmp = RREG32(RADEON_CP_RB_CNTL);
  1958. WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA);
  1959. WREG32(RADEON_CP_RB_RPTR_WR, 0);
  1960. WREG32(RADEON_CP_RB_WPTR, 0);
  1961. WREG32(RADEON_CP_RB_CNTL, tmp);
  1962. /* save PCI state */
  1963. pci_save_state(rdev->pdev);
  1964. /* disable bus mastering */
  1965. r100_bm_disable(rdev);
  1966. WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_SE(1) |
  1967. S_0000F0_SOFT_RESET_RE(1) |
  1968. S_0000F0_SOFT_RESET_PP(1) |
  1969. S_0000F0_SOFT_RESET_RB(1));
  1970. RREG32(R_0000F0_RBBM_SOFT_RESET);
  1971. mdelay(500);
  1972. WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
  1973. mdelay(1);
  1974. status = RREG32(R_000E40_RBBM_STATUS);
  1975. dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
  1976. /* reset CP */
  1977. WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_CP(1));
  1978. RREG32(R_0000F0_RBBM_SOFT_RESET);
  1979. mdelay(500);
  1980. WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
  1981. mdelay(1);
  1982. status = RREG32(R_000E40_RBBM_STATUS);
  1983. dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
  1984. /* restore PCI & busmastering */
  1985. pci_restore_state(rdev->pdev);
  1986. r100_enable_bm(rdev);
  1987. /* Check if GPU is idle */
  1988. if (G_000E40_SE_BUSY(status) || G_000E40_RE_BUSY(status) ||
  1989. G_000E40_TAM_BUSY(status) || G_000E40_PB_BUSY(status)) {
  1990. dev_err(rdev->dev, "failed to reset GPU\n");
  1991. rdev->gpu_lockup = true;
  1992. ret = -1;
  1993. } else
  1994. dev_info(rdev->dev, "GPU reset succeed\n");
  1995. r100_mc_resume(rdev, &save);
  1996. return ret;
  1997. }
  1998. void r100_set_common_regs(struct radeon_device *rdev)
  1999. {
  2000. struct drm_device *dev = rdev->ddev;
  2001. bool force_dac2 = false;
  2002. u32 tmp;
  2003. /* set these so they don't interfere with anything */
  2004. WREG32(RADEON_OV0_SCALE_CNTL, 0);
  2005. WREG32(RADEON_SUBPIC_CNTL, 0);
  2006. WREG32(RADEON_VIPH_CONTROL, 0);
  2007. WREG32(RADEON_I2C_CNTL_1, 0);
  2008. WREG32(RADEON_DVI_I2C_CNTL_1, 0);
  2009. WREG32(RADEON_CAP0_TRIG_CNTL, 0);
  2010. WREG32(RADEON_CAP1_TRIG_CNTL, 0);
  2011. /* always set up dac2 on rn50 and some rv100 as lots
  2012. * of servers seem to wire it up to a VGA port but
  2013. * don't report it in the bios connector
  2014. * table.
  2015. */
  2016. switch (dev->pdev->device) {
  2017. /* RN50 */
  2018. case 0x515e:
  2019. case 0x5969:
  2020. force_dac2 = true;
  2021. break;
  2022. /* RV100*/
  2023. case 0x5159:
  2024. case 0x515a:
  2025. /* DELL triple head servers */
  2026. if ((dev->pdev->subsystem_vendor == 0x1028 /* DELL */) &&
  2027. ((dev->pdev->subsystem_device == 0x016c) ||
  2028. (dev->pdev->subsystem_device == 0x016d) ||
  2029. (dev->pdev->subsystem_device == 0x016e) ||
  2030. (dev->pdev->subsystem_device == 0x016f) ||
  2031. (dev->pdev->subsystem_device == 0x0170) ||
  2032. (dev->pdev->subsystem_device == 0x017d) ||
  2033. (dev->pdev->subsystem_device == 0x017e) ||
  2034. (dev->pdev->subsystem_device == 0x0183) ||
  2035. (dev->pdev->subsystem_device == 0x018a) ||
  2036. (dev->pdev->subsystem_device == 0x019a)))
  2037. force_dac2 = true;
  2038. break;
  2039. }
  2040. if (force_dac2) {
  2041. u32 disp_hw_debug = RREG32(RADEON_DISP_HW_DEBUG);
  2042. u32 tv_dac_cntl = RREG32(RADEON_TV_DAC_CNTL);
  2043. u32 dac2_cntl = RREG32(RADEON_DAC_CNTL2);
  2044. /* For CRT on DAC2, don't turn it on if BIOS didn't
  2045. enable it, even it's detected.
  2046. */
  2047. /* force it to crtc0 */
  2048. dac2_cntl &= ~RADEON_DAC2_DAC_CLK_SEL;
  2049. dac2_cntl |= RADEON_DAC2_DAC2_CLK_SEL;
  2050. disp_hw_debug |= RADEON_CRT2_DISP1_SEL;
  2051. /* set up the TV DAC */
  2052. tv_dac_cntl &= ~(RADEON_TV_DAC_PEDESTAL |
  2053. RADEON_TV_DAC_STD_MASK |
  2054. RADEON_TV_DAC_RDACPD |
  2055. RADEON_TV_DAC_GDACPD |
  2056. RADEON_TV_DAC_BDACPD |
  2057. RADEON_TV_DAC_BGADJ_MASK |
  2058. RADEON_TV_DAC_DACADJ_MASK);
  2059. tv_dac_cntl |= (RADEON_TV_DAC_NBLANK |
  2060. RADEON_TV_DAC_NHOLD |
  2061. RADEON_TV_DAC_STD_PS2 |
  2062. (0x58 << 16));
  2063. WREG32(RADEON_TV_DAC_CNTL, tv_dac_cntl);
  2064. WREG32(RADEON_DISP_HW_DEBUG, disp_hw_debug);
  2065. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  2066. }
  2067. /* switch PM block to ACPI mode */
  2068. tmp = RREG32_PLL(RADEON_PLL_PWRMGT_CNTL);
  2069. tmp &= ~RADEON_PM_MODE_SEL;
  2070. WREG32_PLL(RADEON_PLL_PWRMGT_CNTL, tmp);
  2071. }
  2072. /*
  2073. * VRAM info
  2074. */
  2075. static void r100_vram_get_type(struct radeon_device *rdev)
  2076. {
  2077. uint32_t tmp;
  2078. rdev->mc.vram_is_ddr = false;
  2079. if (rdev->flags & RADEON_IS_IGP)
  2080. rdev->mc.vram_is_ddr = true;
  2081. else if (RREG32(RADEON_MEM_SDRAM_MODE_REG) & RADEON_MEM_CFG_TYPE_DDR)
  2082. rdev->mc.vram_is_ddr = true;
  2083. if ((rdev->family == CHIP_RV100) ||
  2084. (rdev->family == CHIP_RS100) ||
  2085. (rdev->family == CHIP_RS200)) {
  2086. tmp = RREG32(RADEON_MEM_CNTL);
  2087. if (tmp & RV100_HALF_MODE) {
  2088. rdev->mc.vram_width = 32;
  2089. } else {
  2090. rdev->mc.vram_width = 64;
  2091. }
  2092. if (rdev->flags & RADEON_SINGLE_CRTC) {
  2093. rdev->mc.vram_width /= 4;
  2094. rdev->mc.vram_is_ddr = true;
  2095. }
  2096. } else if (rdev->family <= CHIP_RV280) {
  2097. tmp = RREG32(RADEON_MEM_CNTL);
  2098. if (tmp & RADEON_MEM_NUM_CHANNELS_MASK) {
  2099. rdev->mc.vram_width = 128;
  2100. } else {
  2101. rdev->mc.vram_width = 64;
  2102. }
  2103. } else {
  2104. /* newer IGPs */
  2105. rdev->mc.vram_width = 128;
  2106. }
  2107. }
  2108. static u32 r100_get_accessible_vram(struct radeon_device *rdev)
  2109. {
  2110. u32 aper_size;
  2111. u8 byte;
  2112. aper_size = RREG32(RADEON_CONFIG_APER_SIZE);
  2113. /* Set HDP_APER_CNTL only on cards that are known not to be broken,
  2114. * that is has the 2nd generation multifunction PCI interface
  2115. */
  2116. if (rdev->family == CHIP_RV280 ||
  2117. rdev->family >= CHIP_RV350) {
  2118. WREG32_P(RADEON_HOST_PATH_CNTL, RADEON_HDP_APER_CNTL,
  2119. ~RADEON_HDP_APER_CNTL);
  2120. DRM_INFO("Generation 2 PCI interface, using max accessible memory\n");
  2121. return aper_size * 2;
  2122. }
  2123. /* Older cards have all sorts of funny issues to deal with. First
  2124. * check if it's a multifunction card by reading the PCI config
  2125. * header type... Limit those to one aperture size
  2126. */
  2127. pci_read_config_byte(rdev->pdev, 0xe, &byte);
  2128. if (byte & 0x80) {
  2129. DRM_INFO("Generation 1 PCI interface in multifunction mode\n");
  2130. DRM_INFO("Limiting VRAM to one aperture\n");
  2131. return aper_size;
  2132. }
  2133. /* Single function older card. We read HDP_APER_CNTL to see how the BIOS
  2134. * have set it up. We don't write this as it's broken on some ASICs but
  2135. * we expect the BIOS to have done the right thing (might be too optimistic...)
  2136. */
  2137. if (RREG32(RADEON_HOST_PATH_CNTL) & RADEON_HDP_APER_CNTL)
  2138. return aper_size * 2;
  2139. return aper_size;
  2140. }
  2141. void r100_vram_init_sizes(struct radeon_device *rdev)
  2142. {
  2143. u64 config_aper_size;
  2144. /* work out accessible VRAM */
  2145. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  2146. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  2147. rdev->mc.visible_vram_size = r100_get_accessible_vram(rdev);
  2148. /* FIXME we don't use the second aperture yet when we could use it */
  2149. if (rdev->mc.visible_vram_size > rdev->mc.aper_size)
  2150. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  2151. config_aper_size = RREG32(RADEON_CONFIG_APER_SIZE);
  2152. if (rdev->flags & RADEON_IS_IGP) {
  2153. uint32_t tom;
  2154. /* read NB_TOM to get the amount of ram stolen for the GPU */
  2155. tom = RREG32(RADEON_NB_TOM);
  2156. rdev->mc.real_vram_size = (((tom >> 16) - (tom & 0xffff) + 1) << 16);
  2157. WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size);
  2158. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  2159. } else {
  2160. rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
  2161. /* Some production boards of m6 will report 0
  2162. * if it's 8 MB
  2163. */
  2164. if (rdev->mc.real_vram_size == 0) {
  2165. rdev->mc.real_vram_size = 8192 * 1024;
  2166. WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size);
  2167. }
  2168. /* Fix for RN50, M6, M7 with 8/16/32(??) MBs of VRAM -
  2169. * Novell bug 204882 + along with lots of ubuntu ones
  2170. */
  2171. if (rdev->mc.aper_size > config_aper_size)
  2172. config_aper_size = rdev->mc.aper_size;
  2173. if (config_aper_size > rdev->mc.real_vram_size)
  2174. rdev->mc.mc_vram_size = config_aper_size;
  2175. else
  2176. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  2177. }
  2178. }
  2179. void r100_vga_set_state(struct radeon_device *rdev, bool state)
  2180. {
  2181. uint32_t temp;
  2182. temp = RREG32(RADEON_CONFIG_CNTL);
  2183. if (state == false) {
  2184. temp &= ~RADEON_CFG_VGA_RAM_EN;
  2185. temp |= RADEON_CFG_VGA_IO_DIS;
  2186. } else {
  2187. temp &= ~RADEON_CFG_VGA_IO_DIS;
  2188. }
  2189. WREG32(RADEON_CONFIG_CNTL, temp);
  2190. }
  2191. void r100_mc_init(struct radeon_device *rdev)
  2192. {
  2193. u64 base;
  2194. r100_vram_get_type(rdev);
  2195. r100_vram_init_sizes(rdev);
  2196. base = rdev->mc.aper_base;
  2197. if (rdev->flags & RADEON_IS_IGP)
  2198. base = (RREG32(RADEON_NB_TOM) & 0xffff) << 16;
  2199. radeon_vram_location(rdev, &rdev->mc, base);
  2200. rdev->mc.gtt_base_align = 0;
  2201. if (!(rdev->flags & RADEON_IS_AGP))
  2202. radeon_gtt_location(rdev, &rdev->mc);
  2203. radeon_update_bandwidth_info(rdev);
  2204. }
  2205. /*
  2206. * Indirect registers accessor
  2207. */
  2208. void r100_pll_errata_after_index(struct radeon_device *rdev)
  2209. {
  2210. if (rdev->pll_errata & CHIP_ERRATA_PLL_DUMMYREADS) {
  2211. (void)RREG32(RADEON_CLOCK_CNTL_DATA);
  2212. (void)RREG32(RADEON_CRTC_GEN_CNTL);
  2213. }
  2214. }
  2215. static void r100_pll_errata_after_data(struct radeon_device *rdev)
  2216. {
  2217. /* This workarounds is necessary on RV100, RS100 and RS200 chips
  2218. * or the chip could hang on a subsequent access
  2219. */
  2220. if (rdev->pll_errata & CHIP_ERRATA_PLL_DELAY) {
  2221. udelay(5000);
  2222. }
  2223. /* This function is required to workaround a hardware bug in some (all?)
  2224. * revisions of the R300. This workaround should be called after every
  2225. * CLOCK_CNTL_INDEX register access. If not, register reads afterward
  2226. * may not be correct.
  2227. */
  2228. if (rdev->pll_errata & CHIP_ERRATA_R300_CG) {
  2229. uint32_t save, tmp;
  2230. save = RREG32(RADEON_CLOCK_CNTL_INDEX);
  2231. tmp = save & ~(0x3f | RADEON_PLL_WR_EN);
  2232. WREG32(RADEON_CLOCK_CNTL_INDEX, tmp);
  2233. tmp = RREG32(RADEON_CLOCK_CNTL_DATA);
  2234. WREG32(RADEON_CLOCK_CNTL_INDEX, save);
  2235. }
  2236. }
  2237. uint32_t r100_pll_rreg(struct radeon_device *rdev, uint32_t reg)
  2238. {
  2239. uint32_t data;
  2240. WREG8(RADEON_CLOCK_CNTL_INDEX, reg & 0x3f);
  2241. r100_pll_errata_after_index(rdev);
  2242. data = RREG32(RADEON_CLOCK_CNTL_DATA);
  2243. r100_pll_errata_after_data(rdev);
  2244. return data;
  2245. }
  2246. void r100_pll_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  2247. {
  2248. WREG8(RADEON_CLOCK_CNTL_INDEX, ((reg & 0x3f) | RADEON_PLL_WR_EN));
  2249. r100_pll_errata_after_index(rdev);
  2250. WREG32(RADEON_CLOCK_CNTL_DATA, v);
  2251. r100_pll_errata_after_data(rdev);
  2252. }
  2253. void r100_set_safe_registers(struct radeon_device *rdev)
  2254. {
  2255. if (ASIC_IS_RN50(rdev)) {
  2256. rdev->config.r100.reg_safe_bm = rn50_reg_safe_bm;
  2257. rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(rn50_reg_safe_bm);
  2258. } else if (rdev->family < CHIP_R200) {
  2259. rdev->config.r100.reg_safe_bm = r100_reg_safe_bm;
  2260. rdev->config.r100.reg_safe_bm_size = ARRAY_SIZE(r100_reg_safe_bm);
  2261. } else {
  2262. r200_set_safe_registers(rdev);
  2263. }
  2264. }
  2265. /*
  2266. * Debugfs info
  2267. */
  2268. #if defined(CONFIG_DEBUG_FS)
  2269. static int r100_debugfs_rbbm_info(struct seq_file *m, void *data)
  2270. {
  2271. struct drm_info_node *node = (struct drm_info_node *) m->private;
  2272. struct drm_device *dev = node->minor->dev;
  2273. struct radeon_device *rdev = dev->dev_private;
  2274. uint32_t reg, value;
  2275. unsigned i;
  2276. seq_printf(m, "RBBM_STATUS 0x%08x\n", RREG32(RADEON_RBBM_STATUS));
  2277. seq_printf(m, "RBBM_CMDFIFO_STAT 0x%08x\n", RREG32(0xE7C));
  2278. seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT));
  2279. for (i = 0; i < 64; i++) {
  2280. WREG32(RADEON_RBBM_CMDFIFO_ADDR, i | 0x100);
  2281. reg = (RREG32(RADEON_RBBM_CMDFIFO_DATA) - 1) >> 2;
  2282. WREG32(RADEON_RBBM_CMDFIFO_ADDR, i);
  2283. value = RREG32(RADEON_RBBM_CMDFIFO_DATA);
  2284. seq_printf(m, "[0x%03X] 0x%04X=0x%08X\n", i, reg, value);
  2285. }
  2286. return 0;
  2287. }
  2288. static int r100_debugfs_cp_ring_info(struct seq_file *m, void *data)
  2289. {
  2290. struct drm_info_node *node = (struct drm_info_node *) m->private;
  2291. struct drm_device *dev = node->minor->dev;
  2292. struct radeon_device *rdev = dev->dev_private;
  2293. uint32_t rdp, wdp;
  2294. unsigned count, i, j;
  2295. radeon_ring_free_size(rdev);
  2296. rdp = RREG32(RADEON_CP_RB_RPTR);
  2297. wdp = RREG32(RADEON_CP_RB_WPTR);
  2298. count = (rdp + rdev->cp.ring_size - wdp) & rdev->cp.ptr_mask;
  2299. seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT));
  2300. seq_printf(m, "CP_RB_WPTR 0x%08x\n", wdp);
  2301. seq_printf(m, "CP_RB_RPTR 0x%08x\n", rdp);
  2302. seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw);
  2303. seq_printf(m, "%u dwords in ring\n", count);
  2304. for (j = 0; j <= count; j++) {
  2305. i = (rdp + j) & rdev->cp.ptr_mask;
  2306. seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]);
  2307. }
  2308. return 0;
  2309. }
  2310. static int r100_debugfs_cp_csq_fifo(struct seq_file *m, void *data)
  2311. {
  2312. struct drm_info_node *node = (struct drm_info_node *) m->private;
  2313. struct drm_device *dev = node->minor->dev;
  2314. struct radeon_device *rdev = dev->dev_private;
  2315. uint32_t csq_stat, csq2_stat, tmp;
  2316. unsigned r_rptr, r_wptr, ib1_rptr, ib1_wptr, ib2_rptr, ib2_wptr;
  2317. unsigned i;
  2318. seq_printf(m, "CP_STAT 0x%08x\n", RREG32(RADEON_CP_STAT));
  2319. seq_printf(m, "CP_CSQ_MODE 0x%08x\n", RREG32(RADEON_CP_CSQ_MODE));
  2320. csq_stat = RREG32(RADEON_CP_CSQ_STAT);
  2321. csq2_stat = RREG32(RADEON_CP_CSQ2_STAT);
  2322. r_rptr = (csq_stat >> 0) & 0x3ff;
  2323. r_wptr = (csq_stat >> 10) & 0x3ff;
  2324. ib1_rptr = (csq_stat >> 20) & 0x3ff;
  2325. ib1_wptr = (csq2_stat >> 0) & 0x3ff;
  2326. ib2_rptr = (csq2_stat >> 10) & 0x3ff;
  2327. ib2_wptr = (csq2_stat >> 20) & 0x3ff;
  2328. seq_printf(m, "CP_CSQ_STAT 0x%08x\n", csq_stat);
  2329. seq_printf(m, "CP_CSQ2_STAT 0x%08x\n", csq2_stat);
  2330. seq_printf(m, "Ring rptr %u\n", r_rptr);
  2331. seq_printf(m, "Ring wptr %u\n", r_wptr);
  2332. seq_printf(m, "Indirect1 rptr %u\n", ib1_rptr);
  2333. seq_printf(m, "Indirect1 wptr %u\n", ib1_wptr);
  2334. seq_printf(m, "Indirect2 rptr %u\n", ib2_rptr);
  2335. seq_printf(m, "Indirect2 wptr %u\n", ib2_wptr);
  2336. /* FIXME: 0, 128, 640 depends on fifo setup see cp_init_kms
  2337. * 128 = indirect1_start * 8 & 640 = indirect2_start * 8 */
  2338. seq_printf(m, "Ring fifo:\n");
  2339. for (i = 0; i < 256; i++) {
  2340. WREG32(RADEON_CP_CSQ_ADDR, i << 2);
  2341. tmp = RREG32(RADEON_CP_CSQ_DATA);
  2342. seq_printf(m, "rfifo[%04d]=0x%08X\n", i, tmp);
  2343. }
  2344. seq_printf(m, "Indirect1 fifo:\n");
  2345. for (i = 256; i <= 512; i++) {
  2346. WREG32(RADEON_CP_CSQ_ADDR, i << 2);
  2347. tmp = RREG32(RADEON_CP_CSQ_DATA);
  2348. seq_printf(m, "ib1fifo[%04d]=0x%08X\n", i, tmp);
  2349. }
  2350. seq_printf(m, "Indirect2 fifo:\n");
  2351. for (i = 640; i < ib1_wptr; i++) {
  2352. WREG32(RADEON_CP_CSQ_ADDR, i << 2);
  2353. tmp = RREG32(RADEON_CP_CSQ_DATA);
  2354. seq_printf(m, "ib2fifo[%04d]=0x%08X\n", i, tmp);
  2355. }
  2356. return 0;
  2357. }
  2358. static int r100_debugfs_mc_info(struct seq_file *m, void *data)
  2359. {
  2360. struct drm_info_node *node = (struct drm_info_node *) m->private;
  2361. struct drm_device *dev = node->minor->dev;
  2362. struct radeon_device *rdev = dev->dev_private;
  2363. uint32_t tmp;
  2364. tmp = RREG32(RADEON_CONFIG_MEMSIZE);
  2365. seq_printf(m, "CONFIG_MEMSIZE 0x%08x\n", tmp);
  2366. tmp = RREG32(RADEON_MC_FB_LOCATION);
  2367. seq_printf(m, "MC_FB_LOCATION 0x%08x\n", tmp);
  2368. tmp = RREG32(RADEON_BUS_CNTL);
  2369. seq_printf(m, "BUS_CNTL 0x%08x\n", tmp);
  2370. tmp = RREG32(RADEON_MC_AGP_LOCATION);
  2371. seq_printf(m, "MC_AGP_LOCATION 0x%08x\n", tmp);
  2372. tmp = RREG32(RADEON_AGP_BASE);
  2373. seq_printf(m, "AGP_BASE 0x%08x\n", tmp);
  2374. tmp = RREG32(RADEON_HOST_PATH_CNTL);
  2375. seq_printf(m, "HOST_PATH_CNTL 0x%08x\n", tmp);
  2376. tmp = RREG32(0x01D0);
  2377. seq_printf(m, "AIC_CTRL 0x%08x\n", tmp);
  2378. tmp = RREG32(RADEON_AIC_LO_ADDR);
  2379. seq_printf(m, "AIC_LO_ADDR 0x%08x\n", tmp);
  2380. tmp = RREG32(RADEON_AIC_HI_ADDR);
  2381. seq_printf(m, "AIC_HI_ADDR 0x%08x\n", tmp);
  2382. tmp = RREG32(0x01E4);
  2383. seq_printf(m, "AIC_TLB_ADDR 0x%08x\n", tmp);
  2384. return 0;
  2385. }
  2386. static struct drm_info_list r100_debugfs_rbbm_list[] = {
  2387. {"r100_rbbm_info", r100_debugfs_rbbm_info, 0, NULL},
  2388. };
  2389. static struct drm_info_list r100_debugfs_cp_list[] = {
  2390. {"r100_cp_ring_info", r100_debugfs_cp_ring_info, 0, NULL},
  2391. {"r100_cp_csq_fifo", r100_debugfs_cp_csq_fifo, 0, NULL},
  2392. };
  2393. static struct drm_info_list r100_debugfs_mc_info_list[] = {
  2394. {"r100_mc_info", r100_debugfs_mc_info, 0, NULL},
  2395. };
  2396. #endif
  2397. int r100_debugfs_rbbm_init(struct radeon_device *rdev)
  2398. {
  2399. #if defined(CONFIG_DEBUG_FS)
  2400. return radeon_debugfs_add_files(rdev, r100_debugfs_rbbm_list, 1);
  2401. #else
  2402. return 0;
  2403. #endif
  2404. }
  2405. int r100_debugfs_cp_init(struct radeon_device *rdev)
  2406. {
  2407. #if defined(CONFIG_DEBUG_FS)
  2408. return radeon_debugfs_add_files(rdev, r100_debugfs_cp_list, 2);
  2409. #else
  2410. return 0;
  2411. #endif
  2412. }
  2413. int r100_debugfs_mc_info_init(struct radeon_device *rdev)
  2414. {
  2415. #if defined(CONFIG_DEBUG_FS)
  2416. return radeon_debugfs_add_files(rdev, r100_debugfs_mc_info_list, 1);
  2417. #else
  2418. return 0;
  2419. #endif
  2420. }
  2421. int r100_set_surface_reg(struct radeon_device *rdev, int reg,
  2422. uint32_t tiling_flags, uint32_t pitch,
  2423. uint32_t offset, uint32_t obj_size)
  2424. {
  2425. int surf_index = reg * 16;
  2426. int flags = 0;
  2427. if (rdev->family <= CHIP_RS200) {
  2428. if ((tiling_flags & (RADEON_TILING_MACRO|RADEON_TILING_MICRO))
  2429. == (RADEON_TILING_MACRO|RADEON_TILING_MICRO))
  2430. flags |= RADEON_SURF_TILE_COLOR_BOTH;
  2431. if (tiling_flags & RADEON_TILING_MACRO)
  2432. flags |= RADEON_SURF_TILE_COLOR_MACRO;
  2433. } else if (rdev->family <= CHIP_RV280) {
  2434. if (tiling_flags & (RADEON_TILING_MACRO))
  2435. flags |= R200_SURF_TILE_COLOR_MACRO;
  2436. if (tiling_flags & RADEON_TILING_MICRO)
  2437. flags |= R200_SURF_TILE_COLOR_MICRO;
  2438. } else {
  2439. if (tiling_flags & RADEON_TILING_MACRO)
  2440. flags |= R300_SURF_TILE_MACRO;
  2441. if (tiling_flags & RADEON_TILING_MICRO)
  2442. flags |= R300_SURF_TILE_MICRO;
  2443. }
  2444. if (tiling_flags & RADEON_TILING_SWAP_16BIT)
  2445. flags |= RADEON_SURF_AP0_SWP_16BPP | RADEON_SURF_AP1_SWP_16BPP;
  2446. if (tiling_flags & RADEON_TILING_SWAP_32BIT)
  2447. flags |= RADEON_SURF_AP0_SWP_32BPP | RADEON_SURF_AP1_SWP_32BPP;
  2448. /* when we aren't tiling the pitch seems to needs to be furtherdivided down. - tested on power5 + rn50 server */
  2449. if (tiling_flags & (RADEON_TILING_SWAP_16BIT | RADEON_TILING_SWAP_32BIT)) {
  2450. if (!(tiling_flags & (RADEON_TILING_MACRO | RADEON_TILING_MICRO)))
  2451. if (ASIC_IS_RN50(rdev))
  2452. pitch /= 16;
  2453. }
  2454. /* r100/r200 divide by 16 */
  2455. if (rdev->family < CHIP_R300)
  2456. flags |= pitch / 16;
  2457. else
  2458. flags |= pitch / 8;
  2459. DRM_DEBUG_KMS("writing surface %d %d %x %x\n", reg, flags, offset, offset+obj_size-1);
  2460. WREG32(RADEON_SURFACE0_INFO + surf_index, flags);
  2461. WREG32(RADEON_SURFACE0_LOWER_BOUND + surf_index, offset);
  2462. WREG32(RADEON_SURFACE0_UPPER_BOUND + surf_index, offset + obj_size - 1);
  2463. return 0;
  2464. }
  2465. void r100_clear_surface_reg(struct radeon_device *rdev, int reg)
  2466. {
  2467. int surf_index = reg * 16;
  2468. WREG32(RADEON_SURFACE0_INFO + surf_index, 0);
  2469. }
  2470. void r100_bandwidth_update(struct radeon_device *rdev)
  2471. {
  2472. fixed20_12 trcd_ff, trp_ff, tras_ff, trbs_ff, tcas_ff;
  2473. fixed20_12 sclk_ff, mclk_ff, sclk_eff_ff, sclk_delay_ff;
  2474. fixed20_12 peak_disp_bw, mem_bw, pix_clk, pix_clk2, temp_ff, crit_point_ff;
  2475. uint32_t temp, data, mem_trcd, mem_trp, mem_tras;
  2476. fixed20_12 memtcas_ff[8] = {
  2477. dfixed_init(1),
  2478. dfixed_init(2),
  2479. dfixed_init(3),
  2480. dfixed_init(0),
  2481. dfixed_init_half(1),
  2482. dfixed_init_half(2),
  2483. dfixed_init(0),
  2484. };
  2485. fixed20_12 memtcas_rs480_ff[8] = {
  2486. dfixed_init(0),
  2487. dfixed_init(1),
  2488. dfixed_init(2),
  2489. dfixed_init(3),
  2490. dfixed_init(0),
  2491. dfixed_init_half(1),
  2492. dfixed_init_half(2),
  2493. dfixed_init_half(3),
  2494. };
  2495. fixed20_12 memtcas2_ff[8] = {
  2496. dfixed_init(0),
  2497. dfixed_init(1),
  2498. dfixed_init(2),
  2499. dfixed_init(3),
  2500. dfixed_init(4),
  2501. dfixed_init(5),
  2502. dfixed_init(6),
  2503. dfixed_init(7),
  2504. };
  2505. fixed20_12 memtrbs[8] = {
  2506. dfixed_init(1),
  2507. dfixed_init_half(1),
  2508. dfixed_init(2),
  2509. dfixed_init_half(2),
  2510. dfixed_init(3),
  2511. dfixed_init_half(3),
  2512. dfixed_init(4),
  2513. dfixed_init_half(4)
  2514. };
  2515. fixed20_12 memtrbs_r4xx[8] = {
  2516. dfixed_init(4),
  2517. dfixed_init(5),
  2518. dfixed_init(6),
  2519. dfixed_init(7),
  2520. dfixed_init(8),
  2521. dfixed_init(9),
  2522. dfixed_init(10),
  2523. dfixed_init(11)
  2524. };
  2525. fixed20_12 min_mem_eff;
  2526. fixed20_12 mc_latency_sclk, mc_latency_mclk, k1;
  2527. fixed20_12 cur_latency_mclk, cur_latency_sclk;
  2528. fixed20_12 disp_latency, disp_latency_overhead, disp_drain_rate,
  2529. disp_drain_rate2, read_return_rate;
  2530. fixed20_12 time_disp1_drop_priority;
  2531. int c;
  2532. int cur_size = 16; /* in octawords */
  2533. int critical_point = 0, critical_point2;
  2534. /* uint32_t read_return_rate, time_disp1_drop_priority; */
  2535. int stop_req, max_stop_req;
  2536. struct drm_display_mode *mode1 = NULL;
  2537. struct drm_display_mode *mode2 = NULL;
  2538. uint32_t pixel_bytes1 = 0;
  2539. uint32_t pixel_bytes2 = 0;
  2540. radeon_update_display_priority(rdev);
  2541. if (rdev->mode_info.crtcs[0]->base.enabled) {
  2542. mode1 = &rdev->mode_info.crtcs[0]->base.mode;
  2543. pixel_bytes1 = rdev->mode_info.crtcs[0]->base.fb->bits_per_pixel / 8;
  2544. }
  2545. if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
  2546. if (rdev->mode_info.crtcs[1]->base.enabled) {
  2547. mode2 = &rdev->mode_info.crtcs[1]->base.mode;
  2548. pixel_bytes2 = rdev->mode_info.crtcs[1]->base.fb->bits_per_pixel / 8;
  2549. }
  2550. }
  2551. min_mem_eff.full = dfixed_const_8(0);
  2552. /* get modes */
  2553. if ((rdev->disp_priority == 2) && ASIC_IS_R300(rdev)) {
  2554. uint32_t mc_init_misc_lat_timer = RREG32(R300_MC_INIT_MISC_LAT_TIMER);
  2555. mc_init_misc_lat_timer &= ~(R300_MC_DISP1R_INIT_LAT_MASK << R300_MC_DISP1R_INIT_LAT_SHIFT);
  2556. mc_init_misc_lat_timer &= ~(R300_MC_DISP0R_INIT_LAT_MASK << R300_MC_DISP0R_INIT_LAT_SHIFT);
  2557. /* check crtc enables */
  2558. if (mode2)
  2559. mc_init_misc_lat_timer |= (1 << R300_MC_DISP1R_INIT_LAT_SHIFT);
  2560. if (mode1)
  2561. mc_init_misc_lat_timer |= (1 << R300_MC_DISP0R_INIT_LAT_SHIFT);
  2562. WREG32(R300_MC_INIT_MISC_LAT_TIMER, mc_init_misc_lat_timer);
  2563. }
  2564. /*
  2565. * determine is there is enough bw for current mode
  2566. */
  2567. sclk_ff = rdev->pm.sclk;
  2568. mclk_ff = rdev->pm.mclk;
  2569. temp = (rdev->mc.vram_width / 8) * (rdev->mc.vram_is_ddr ? 2 : 1);
  2570. temp_ff.full = dfixed_const(temp);
  2571. mem_bw.full = dfixed_mul(mclk_ff, temp_ff);
  2572. pix_clk.full = 0;
  2573. pix_clk2.full = 0;
  2574. peak_disp_bw.full = 0;
  2575. if (mode1) {
  2576. temp_ff.full = dfixed_const(1000);
  2577. pix_clk.full = dfixed_const(mode1->clock); /* convert to fixed point */
  2578. pix_clk.full = dfixed_div(pix_clk, temp_ff);
  2579. temp_ff.full = dfixed_const(pixel_bytes1);
  2580. peak_disp_bw.full += dfixed_mul(pix_clk, temp_ff);
  2581. }
  2582. if (mode2) {
  2583. temp_ff.full = dfixed_const(1000);
  2584. pix_clk2.full = dfixed_const(mode2->clock); /* convert to fixed point */
  2585. pix_clk2.full = dfixed_div(pix_clk2, temp_ff);
  2586. temp_ff.full = dfixed_const(pixel_bytes2);
  2587. peak_disp_bw.full += dfixed_mul(pix_clk2, temp_ff);
  2588. }
  2589. mem_bw.full = dfixed_mul(mem_bw, min_mem_eff);
  2590. if (peak_disp_bw.full >= mem_bw.full) {
  2591. DRM_ERROR("You may not have enough display bandwidth for current mode\n"
  2592. "If you have flickering problem, try to lower resolution, refresh rate, or color depth\n");
  2593. }
  2594. /* Get values from the EXT_MEM_CNTL register...converting its contents. */
  2595. temp = RREG32(RADEON_MEM_TIMING_CNTL);
  2596. if ((rdev->family == CHIP_RV100) || (rdev->flags & RADEON_IS_IGP)) { /* RV100, M6, IGPs */
  2597. mem_trcd = ((temp >> 2) & 0x3) + 1;
  2598. mem_trp = ((temp & 0x3)) + 1;
  2599. mem_tras = ((temp & 0x70) >> 4) + 1;
  2600. } else if (rdev->family == CHIP_R300 ||
  2601. rdev->family == CHIP_R350) { /* r300, r350 */
  2602. mem_trcd = (temp & 0x7) + 1;
  2603. mem_trp = ((temp >> 8) & 0x7) + 1;
  2604. mem_tras = ((temp >> 11) & 0xf) + 4;
  2605. } else if (rdev->family == CHIP_RV350 ||
  2606. rdev->family <= CHIP_RV380) {
  2607. /* rv3x0 */
  2608. mem_trcd = (temp & 0x7) + 3;
  2609. mem_trp = ((temp >> 8) & 0x7) + 3;
  2610. mem_tras = ((temp >> 11) & 0xf) + 6;
  2611. } else if (rdev->family == CHIP_R420 ||
  2612. rdev->family == CHIP_R423 ||
  2613. rdev->family == CHIP_RV410) {
  2614. /* r4xx */
  2615. mem_trcd = (temp & 0xf) + 3;
  2616. if (mem_trcd > 15)
  2617. mem_trcd = 15;
  2618. mem_trp = ((temp >> 8) & 0xf) + 3;
  2619. if (mem_trp > 15)
  2620. mem_trp = 15;
  2621. mem_tras = ((temp >> 12) & 0x1f) + 6;
  2622. if (mem_tras > 31)
  2623. mem_tras = 31;
  2624. } else { /* RV200, R200 */
  2625. mem_trcd = (temp & 0x7) + 1;
  2626. mem_trp = ((temp >> 8) & 0x7) + 1;
  2627. mem_tras = ((temp >> 12) & 0xf) + 4;
  2628. }
  2629. /* convert to FF */
  2630. trcd_ff.full = dfixed_const(mem_trcd);
  2631. trp_ff.full = dfixed_const(mem_trp);
  2632. tras_ff.full = dfixed_const(mem_tras);
  2633. /* Get values from the MEM_SDRAM_MODE_REG register...converting its */
  2634. temp = RREG32(RADEON_MEM_SDRAM_MODE_REG);
  2635. data = (temp & (7 << 20)) >> 20;
  2636. if ((rdev->family == CHIP_RV100) || rdev->flags & RADEON_IS_IGP) {
  2637. if (rdev->family == CHIP_RS480) /* don't think rs400 */
  2638. tcas_ff = memtcas_rs480_ff[data];
  2639. else
  2640. tcas_ff = memtcas_ff[data];
  2641. } else
  2642. tcas_ff = memtcas2_ff[data];
  2643. if (rdev->family == CHIP_RS400 ||
  2644. rdev->family == CHIP_RS480) {
  2645. /* extra cas latency stored in bits 23-25 0-4 clocks */
  2646. data = (temp >> 23) & 0x7;
  2647. if (data < 5)
  2648. tcas_ff.full += dfixed_const(data);
  2649. }
  2650. if (ASIC_IS_R300(rdev) && !(rdev->flags & RADEON_IS_IGP)) {
  2651. /* on the R300, Tcas is included in Trbs.
  2652. */
  2653. temp = RREG32(RADEON_MEM_CNTL);
  2654. data = (R300_MEM_NUM_CHANNELS_MASK & temp);
  2655. if (data == 1) {
  2656. if (R300_MEM_USE_CD_CH_ONLY & temp) {
  2657. temp = RREG32(R300_MC_IND_INDEX);
  2658. temp &= ~R300_MC_IND_ADDR_MASK;
  2659. temp |= R300_MC_READ_CNTL_CD_mcind;
  2660. WREG32(R300_MC_IND_INDEX, temp);
  2661. temp = RREG32(R300_MC_IND_DATA);
  2662. data = (R300_MEM_RBS_POSITION_C_MASK & temp);
  2663. } else {
  2664. temp = RREG32(R300_MC_READ_CNTL_AB);
  2665. data = (R300_MEM_RBS_POSITION_A_MASK & temp);
  2666. }
  2667. } else {
  2668. temp = RREG32(R300_MC_READ_CNTL_AB);
  2669. data = (R300_MEM_RBS_POSITION_A_MASK & temp);
  2670. }
  2671. if (rdev->family == CHIP_RV410 ||
  2672. rdev->family == CHIP_R420 ||
  2673. rdev->family == CHIP_R423)
  2674. trbs_ff = memtrbs_r4xx[data];
  2675. else
  2676. trbs_ff = memtrbs[data];
  2677. tcas_ff.full += trbs_ff.full;
  2678. }
  2679. sclk_eff_ff.full = sclk_ff.full;
  2680. if (rdev->flags & RADEON_IS_AGP) {
  2681. fixed20_12 agpmode_ff;
  2682. agpmode_ff.full = dfixed_const(radeon_agpmode);
  2683. temp_ff.full = dfixed_const_666(16);
  2684. sclk_eff_ff.full -= dfixed_mul(agpmode_ff, temp_ff);
  2685. }
  2686. /* TODO PCIE lanes may affect this - agpmode == 16?? */
  2687. if (ASIC_IS_R300(rdev)) {
  2688. sclk_delay_ff.full = dfixed_const(250);
  2689. } else {
  2690. if ((rdev->family == CHIP_RV100) ||
  2691. rdev->flags & RADEON_IS_IGP) {
  2692. if (rdev->mc.vram_is_ddr)
  2693. sclk_delay_ff.full = dfixed_const(41);
  2694. else
  2695. sclk_delay_ff.full = dfixed_const(33);
  2696. } else {
  2697. if (rdev->mc.vram_width == 128)
  2698. sclk_delay_ff.full = dfixed_const(57);
  2699. else
  2700. sclk_delay_ff.full = dfixed_const(41);
  2701. }
  2702. }
  2703. mc_latency_sclk.full = dfixed_div(sclk_delay_ff, sclk_eff_ff);
  2704. if (rdev->mc.vram_is_ddr) {
  2705. if (rdev->mc.vram_width == 32) {
  2706. k1.full = dfixed_const(40);
  2707. c = 3;
  2708. } else {
  2709. k1.full = dfixed_const(20);
  2710. c = 1;
  2711. }
  2712. } else {
  2713. k1.full = dfixed_const(40);
  2714. c = 3;
  2715. }
  2716. temp_ff.full = dfixed_const(2);
  2717. mc_latency_mclk.full = dfixed_mul(trcd_ff, temp_ff);
  2718. temp_ff.full = dfixed_const(c);
  2719. mc_latency_mclk.full += dfixed_mul(tcas_ff, temp_ff);
  2720. temp_ff.full = dfixed_const(4);
  2721. mc_latency_mclk.full += dfixed_mul(tras_ff, temp_ff);
  2722. mc_latency_mclk.full += dfixed_mul(trp_ff, temp_ff);
  2723. mc_latency_mclk.full += k1.full;
  2724. mc_latency_mclk.full = dfixed_div(mc_latency_mclk, mclk_ff);
  2725. mc_latency_mclk.full += dfixed_div(temp_ff, sclk_eff_ff);
  2726. /*
  2727. HW cursor time assuming worst case of full size colour cursor.
  2728. */
  2729. temp_ff.full = dfixed_const((2 * (cur_size - (rdev->mc.vram_is_ddr + 1))));
  2730. temp_ff.full += trcd_ff.full;
  2731. if (temp_ff.full < tras_ff.full)
  2732. temp_ff.full = tras_ff.full;
  2733. cur_latency_mclk.full = dfixed_div(temp_ff, mclk_ff);
  2734. temp_ff.full = dfixed_const(cur_size);
  2735. cur_latency_sclk.full = dfixed_div(temp_ff, sclk_eff_ff);
  2736. /*
  2737. Find the total latency for the display data.
  2738. */
  2739. disp_latency_overhead.full = dfixed_const(8);
  2740. disp_latency_overhead.full = dfixed_div(disp_latency_overhead, sclk_ff);
  2741. mc_latency_mclk.full += disp_latency_overhead.full + cur_latency_mclk.full;
  2742. mc_latency_sclk.full += disp_latency_overhead.full + cur_latency_sclk.full;
  2743. if (mc_latency_mclk.full > mc_latency_sclk.full)
  2744. disp_latency.full = mc_latency_mclk.full;
  2745. else
  2746. disp_latency.full = mc_latency_sclk.full;
  2747. /* setup Max GRPH_STOP_REQ default value */
  2748. if (ASIC_IS_RV100(rdev))
  2749. max_stop_req = 0x5c;
  2750. else
  2751. max_stop_req = 0x7c;
  2752. if (mode1) {
  2753. /* CRTC1
  2754. Set GRPH_BUFFER_CNTL register using h/w defined optimal values.
  2755. GRPH_STOP_REQ <= MIN[ 0x7C, (CRTC_H_DISP + 1) * (bit depth) / 0x10 ]
  2756. */
  2757. stop_req = mode1->hdisplay * pixel_bytes1 / 16;
  2758. if (stop_req > max_stop_req)
  2759. stop_req = max_stop_req;
  2760. /*
  2761. Find the drain rate of the display buffer.
  2762. */
  2763. temp_ff.full = dfixed_const((16/pixel_bytes1));
  2764. disp_drain_rate.full = dfixed_div(pix_clk, temp_ff);
  2765. /*
  2766. Find the critical point of the display buffer.
  2767. */
  2768. crit_point_ff.full = dfixed_mul(disp_drain_rate, disp_latency);
  2769. crit_point_ff.full += dfixed_const_half(0);
  2770. critical_point = dfixed_trunc(crit_point_ff);
  2771. if (rdev->disp_priority == 2) {
  2772. critical_point = 0;
  2773. }
  2774. /*
  2775. The critical point should never be above max_stop_req-4. Setting
  2776. GRPH_CRITICAL_CNTL = 0 will thus force high priority all the time.
  2777. */
  2778. if (max_stop_req - critical_point < 4)
  2779. critical_point = 0;
  2780. if (critical_point == 0 && mode2 && rdev->family == CHIP_R300) {
  2781. /* some R300 cards have problem with this set to 0, when CRTC2 is enabled.*/
  2782. critical_point = 0x10;
  2783. }
  2784. temp = RREG32(RADEON_GRPH_BUFFER_CNTL);
  2785. temp &= ~(RADEON_GRPH_STOP_REQ_MASK);
  2786. temp |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT);
  2787. temp &= ~(RADEON_GRPH_START_REQ_MASK);
  2788. if ((rdev->family == CHIP_R350) &&
  2789. (stop_req > 0x15)) {
  2790. stop_req -= 0x10;
  2791. }
  2792. temp |= (stop_req << RADEON_GRPH_START_REQ_SHIFT);
  2793. temp |= RADEON_GRPH_BUFFER_SIZE;
  2794. temp &= ~(RADEON_GRPH_CRITICAL_CNTL |
  2795. RADEON_GRPH_CRITICAL_AT_SOF |
  2796. RADEON_GRPH_STOP_CNTL);
  2797. /*
  2798. Write the result into the register.
  2799. */
  2800. WREG32(RADEON_GRPH_BUFFER_CNTL, ((temp & ~RADEON_GRPH_CRITICAL_POINT_MASK) |
  2801. (critical_point << RADEON_GRPH_CRITICAL_POINT_SHIFT)));
  2802. #if 0
  2803. if ((rdev->family == CHIP_RS400) ||
  2804. (rdev->family == CHIP_RS480)) {
  2805. /* attempt to program RS400 disp regs correctly ??? */
  2806. temp = RREG32(RS400_DISP1_REG_CNTL);
  2807. temp &= ~(RS400_DISP1_START_REQ_LEVEL_MASK |
  2808. RS400_DISP1_STOP_REQ_LEVEL_MASK);
  2809. WREG32(RS400_DISP1_REQ_CNTL1, (temp |
  2810. (critical_point << RS400_DISP1_START_REQ_LEVEL_SHIFT) |
  2811. (critical_point << RS400_DISP1_STOP_REQ_LEVEL_SHIFT)));
  2812. temp = RREG32(RS400_DMIF_MEM_CNTL1);
  2813. temp &= ~(RS400_DISP1_CRITICAL_POINT_START_MASK |
  2814. RS400_DISP1_CRITICAL_POINT_STOP_MASK);
  2815. WREG32(RS400_DMIF_MEM_CNTL1, (temp |
  2816. (critical_point << RS400_DISP1_CRITICAL_POINT_START_SHIFT) |
  2817. (critical_point << RS400_DISP1_CRITICAL_POINT_STOP_SHIFT)));
  2818. }
  2819. #endif
  2820. DRM_DEBUG_KMS("GRPH_BUFFER_CNTL from to %x\n",
  2821. /* (unsigned int)info->SavedReg->grph_buffer_cntl, */
  2822. (unsigned int)RREG32(RADEON_GRPH_BUFFER_CNTL));
  2823. }
  2824. if (mode2) {
  2825. u32 grph2_cntl;
  2826. stop_req = mode2->hdisplay * pixel_bytes2 / 16;
  2827. if (stop_req > max_stop_req)
  2828. stop_req = max_stop_req;
  2829. /*
  2830. Find the drain rate of the display buffer.
  2831. */
  2832. temp_ff.full = dfixed_const((16/pixel_bytes2));
  2833. disp_drain_rate2.full = dfixed_div(pix_clk2, temp_ff);
  2834. grph2_cntl = RREG32(RADEON_GRPH2_BUFFER_CNTL);
  2835. grph2_cntl &= ~(RADEON_GRPH_STOP_REQ_MASK);
  2836. grph2_cntl |= (stop_req << RADEON_GRPH_STOP_REQ_SHIFT);
  2837. grph2_cntl &= ~(RADEON_GRPH_START_REQ_MASK);
  2838. if ((rdev->family == CHIP_R350) &&
  2839. (stop_req > 0x15)) {
  2840. stop_req -= 0x10;
  2841. }
  2842. grph2_cntl |= (stop_req << RADEON_GRPH_START_REQ_SHIFT);
  2843. grph2_cntl |= RADEON_GRPH_BUFFER_SIZE;
  2844. grph2_cntl &= ~(RADEON_GRPH_CRITICAL_CNTL |
  2845. RADEON_GRPH_CRITICAL_AT_SOF |
  2846. RADEON_GRPH_STOP_CNTL);
  2847. if ((rdev->family == CHIP_RS100) ||
  2848. (rdev->family == CHIP_RS200))
  2849. critical_point2 = 0;
  2850. else {
  2851. temp = (rdev->mc.vram_width * rdev->mc.vram_is_ddr + 1)/128;
  2852. temp_ff.full = dfixed_const(temp);
  2853. temp_ff.full = dfixed_mul(mclk_ff, temp_ff);
  2854. if (sclk_ff.full < temp_ff.full)
  2855. temp_ff.full = sclk_ff.full;
  2856. read_return_rate.full = temp_ff.full;
  2857. if (mode1) {
  2858. temp_ff.full = read_return_rate.full - disp_drain_rate.full;
  2859. time_disp1_drop_priority.full = dfixed_div(crit_point_ff, temp_ff);
  2860. } else {
  2861. time_disp1_drop_priority.full = 0;
  2862. }
  2863. crit_point_ff.full = disp_latency.full + time_disp1_drop_priority.full + disp_latency.full;
  2864. crit_point_ff.full = dfixed_mul(crit_point_ff, disp_drain_rate2);
  2865. crit_point_ff.full += dfixed_const_half(0);
  2866. critical_point2 = dfixed_trunc(crit_point_ff);
  2867. if (rdev->disp_priority == 2) {
  2868. critical_point2 = 0;
  2869. }
  2870. if (max_stop_req - critical_point2 < 4)
  2871. critical_point2 = 0;
  2872. }
  2873. if (critical_point2 == 0 && rdev->family == CHIP_R300) {
  2874. /* some R300 cards have problem with this set to 0 */
  2875. critical_point2 = 0x10;
  2876. }
  2877. WREG32(RADEON_GRPH2_BUFFER_CNTL, ((grph2_cntl & ~RADEON_GRPH_CRITICAL_POINT_MASK) |
  2878. (critical_point2 << RADEON_GRPH_CRITICAL_POINT_SHIFT)));
  2879. if ((rdev->family == CHIP_RS400) ||
  2880. (rdev->family == CHIP_RS480)) {
  2881. #if 0
  2882. /* attempt to program RS400 disp2 regs correctly ??? */
  2883. temp = RREG32(RS400_DISP2_REQ_CNTL1);
  2884. temp &= ~(RS400_DISP2_START_REQ_LEVEL_MASK |
  2885. RS400_DISP2_STOP_REQ_LEVEL_MASK);
  2886. WREG32(RS400_DISP2_REQ_CNTL1, (temp |
  2887. (critical_point2 << RS400_DISP1_START_REQ_LEVEL_SHIFT) |
  2888. (critical_point2 << RS400_DISP1_STOP_REQ_LEVEL_SHIFT)));
  2889. temp = RREG32(RS400_DISP2_REQ_CNTL2);
  2890. temp &= ~(RS400_DISP2_CRITICAL_POINT_START_MASK |
  2891. RS400_DISP2_CRITICAL_POINT_STOP_MASK);
  2892. WREG32(RS400_DISP2_REQ_CNTL2, (temp |
  2893. (critical_point2 << RS400_DISP2_CRITICAL_POINT_START_SHIFT) |
  2894. (critical_point2 << RS400_DISP2_CRITICAL_POINT_STOP_SHIFT)));
  2895. #endif
  2896. WREG32(RS400_DISP2_REQ_CNTL1, 0x105DC1CC);
  2897. WREG32(RS400_DISP2_REQ_CNTL2, 0x2749D000);
  2898. WREG32(RS400_DMIF_MEM_CNTL1, 0x29CA71DC);
  2899. WREG32(RS400_DISP1_REQ_CNTL1, 0x28FBC3AC);
  2900. }
  2901. DRM_DEBUG_KMS("GRPH2_BUFFER_CNTL from to %x\n",
  2902. (unsigned int)RREG32(RADEON_GRPH2_BUFFER_CNTL));
  2903. }
  2904. }
  2905. static inline void r100_cs_track_texture_print(struct r100_cs_track_texture *t)
  2906. {
  2907. DRM_ERROR("pitch %d\n", t->pitch);
  2908. DRM_ERROR("use_pitch %d\n", t->use_pitch);
  2909. DRM_ERROR("width %d\n", t->width);
  2910. DRM_ERROR("width_11 %d\n", t->width_11);
  2911. DRM_ERROR("height %d\n", t->height);
  2912. DRM_ERROR("height_11 %d\n", t->height_11);
  2913. DRM_ERROR("num levels %d\n", t->num_levels);
  2914. DRM_ERROR("depth %d\n", t->txdepth);
  2915. DRM_ERROR("bpp %d\n", t->cpp);
  2916. DRM_ERROR("coordinate type %d\n", t->tex_coord_type);
  2917. DRM_ERROR("width round to power of 2 %d\n", t->roundup_w);
  2918. DRM_ERROR("height round to power of 2 %d\n", t->roundup_h);
  2919. DRM_ERROR("compress format %d\n", t->compress_format);
  2920. }
  2921. static int r100_track_compress_size(int compress_format, int w, int h)
  2922. {
  2923. int block_width, block_height, block_bytes;
  2924. int wblocks, hblocks;
  2925. int min_wblocks;
  2926. int sz;
  2927. block_width = 4;
  2928. block_height = 4;
  2929. switch (compress_format) {
  2930. case R100_TRACK_COMP_DXT1:
  2931. block_bytes = 8;
  2932. min_wblocks = 4;
  2933. break;
  2934. default:
  2935. case R100_TRACK_COMP_DXT35:
  2936. block_bytes = 16;
  2937. min_wblocks = 2;
  2938. break;
  2939. }
  2940. hblocks = (h + block_height - 1) / block_height;
  2941. wblocks = (w + block_width - 1) / block_width;
  2942. if (wblocks < min_wblocks)
  2943. wblocks = min_wblocks;
  2944. sz = wblocks * hblocks * block_bytes;
  2945. return sz;
  2946. }
  2947. static int r100_cs_track_cube(struct radeon_device *rdev,
  2948. struct r100_cs_track *track, unsigned idx)
  2949. {
  2950. unsigned face, w, h;
  2951. struct radeon_bo *cube_robj;
  2952. unsigned long size;
  2953. unsigned compress_format = track->textures[idx].compress_format;
  2954. for (face = 0; face < 5; face++) {
  2955. cube_robj = track->textures[idx].cube_info[face].robj;
  2956. w = track->textures[idx].cube_info[face].width;
  2957. h = track->textures[idx].cube_info[face].height;
  2958. if (compress_format) {
  2959. size = r100_track_compress_size(compress_format, w, h);
  2960. } else
  2961. size = w * h;
  2962. size *= track->textures[idx].cpp;
  2963. size += track->textures[idx].cube_info[face].offset;
  2964. if (size > radeon_bo_size(cube_robj)) {
  2965. DRM_ERROR("Cube texture offset greater than object size %lu %lu\n",
  2966. size, radeon_bo_size(cube_robj));
  2967. r100_cs_track_texture_print(&track->textures[idx]);
  2968. return -1;
  2969. }
  2970. }
  2971. return 0;
  2972. }
  2973. static int r100_cs_track_texture_check(struct radeon_device *rdev,
  2974. struct r100_cs_track *track)
  2975. {
  2976. struct radeon_bo *robj;
  2977. unsigned long size;
  2978. unsigned u, i, w, h, d;
  2979. int ret;
  2980. for (u = 0; u < track->num_texture; u++) {
  2981. if (!track->textures[u].enabled)
  2982. continue;
  2983. if (track->textures[u].lookup_disable)
  2984. continue;
  2985. robj = track->textures[u].robj;
  2986. if (robj == NULL) {
  2987. DRM_ERROR("No texture bound to unit %u\n", u);
  2988. return -EINVAL;
  2989. }
  2990. size = 0;
  2991. for (i = 0; i <= track->textures[u].num_levels; i++) {
  2992. if (track->textures[u].use_pitch) {
  2993. if (rdev->family < CHIP_R300)
  2994. w = (track->textures[u].pitch / track->textures[u].cpp) / (1 << i);
  2995. else
  2996. w = track->textures[u].pitch / (1 << i);
  2997. } else {
  2998. w = track->textures[u].width;
  2999. if (rdev->family >= CHIP_RV515)
  3000. w |= track->textures[u].width_11;
  3001. w = w / (1 << i);
  3002. if (track->textures[u].roundup_w)
  3003. w = roundup_pow_of_two(w);
  3004. }
  3005. h = track->textures[u].height;
  3006. if (rdev->family >= CHIP_RV515)
  3007. h |= track->textures[u].height_11;
  3008. h = h / (1 << i);
  3009. if (track->textures[u].roundup_h)
  3010. h = roundup_pow_of_two(h);
  3011. if (track->textures[u].tex_coord_type == 1) {
  3012. d = (1 << track->textures[u].txdepth) / (1 << i);
  3013. if (!d)
  3014. d = 1;
  3015. } else {
  3016. d = 1;
  3017. }
  3018. if (track->textures[u].compress_format) {
  3019. size += r100_track_compress_size(track->textures[u].compress_format, w, h) * d;
  3020. /* compressed textures are block based */
  3021. } else
  3022. size += w * h * d;
  3023. }
  3024. size *= track->textures[u].cpp;
  3025. switch (track->textures[u].tex_coord_type) {
  3026. case 0:
  3027. case 1:
  3028. break;
  3029. case 2:
  3030. if (track->separate_cube) {
  3031. ret = r100_cs_track_cube(rdev, track, u);
  3032. if (ret)
  3033. return ret;
  3034. } else
  3035. size *= 6;
  3036. break;
  3037. default:
  3038. DRM_ERROR("Invalid texture coordinate type %u for unit "
  3039. "%u\n", track->textures[u].tex_coord_type, u);
  3040. return -EINVAL;
  3041. }
  3042. if (size > radeon_bo_size(robj)) {
  3043. DRM_ERROR("Texture of unit %u needs %lu bytes but is "
  3044. "%lu\n", u, size, radeon_bo_size(robj));
  3045. r100_cs_track_texture_print(&track->textures[u]);
  3046. return -EINVAL;
  3047. }
  3048. }
  3049. return 0;
  3050. }
  3051. int r100_cs_track_check(struct radeon_device *rdev, struct r100_cs_track *track)
  3052. {
  3053. unsigned i;
  3054. unsigned long size;
  3055. unsigned prim_walk;
  3056. unsigned nverts;
  3057. unsigned num_cb = track->cb_dirty ? track->num_cb : 0;
  3058. if (num_cb && !track->zb_cb_clear && !track->color_channel_mask &&
  3059. !track->blend_read_enable)
  3060. num_cb = 0;
  3061. for (i = 0; i < num_cb; i++) {
  3062. if (track->cb[i].robj == NULL) {
  3063. DRM_ERROR("[drm] No buffer for color buffer %d !\n", i);
  3064. return -EINVAL;
  3065. }
  3066. size = track->cb[i].pitch * track->cb[i].cpp * track->maxy;
  3067. size += track->cb[i].offset;
  3068. if (size > radeon_bo_size(track->cb[i].robj)) {
  3069. DRM_ERROR("[drm] Buffer too small for color buffer %d "
  3070. "(need %lu have %lu) !\n", i, size,
  3071. radeon_bo_size(track->cb[i].robj));
  3072. DRM_ERROR("[drm] color buffer %d (%u %u %u %u)\n",
  3073. i, track->cb[i].pitch, track->cb[i].cpp,
  3074. track->cb[i].offset, track->maxy);
  3075. return -EINVAL;
  3076. }
  3077. }
  3078. track->cb_dirty = false;
  3079. if (track->zb_dirty && track->z_enabled) {
  3080. if (track->zb.robj == NULL) {
  3081. DRM_ERROR("[drm] No buffer for z buffer !\n");
  3082. return -EINVAL;
  3083. }
  3084. size = track->zb.pitch * track->zb.cpp * track->maxy;
  3085. size += track->zb.offset;
  3086. if (size > radeon_bo_size(track->zb.robj)) {
  3087. DRM_ERROR("[drm] Buffer too small for z buffer "
  3088. "(need %lu have %lu) !\n", size,
  3089. radeon_bo_size(track->zb.robj));
  3090. DRM_ERROR("[drm] zbuffer (%u %u %u %u)\n",
  3091. track->zb.pitch, track->zb.cpp,
  3092. track->zb.offset, track->maxy);
  3093. return -EINVAL;
  3094. }
  3095. }
  3096. track->zb_dirty = false;
  3097. if (track->aa_dirty && track->aaresolve) {
  3098. if (track->aa.robj == NULL) {
  3099. DRM_ERROR("[drm] No buffer for AA resolve buffer %d !\n", i);
  3100. return -EINVAL;
  3101. }
  3102. /* I believe the format comes from colorbuffer0. */
  3103. size = track->aa.pitch * track->cb[0].cpp * track->maxy;
  3104. size += track->aa.offset;
  3105. if (size > radeon_bo_size(track->aa.robj)) {
  3106. DRM_ERROR("[drm] Buffer too small for AA resolve buffer %d "
  3107. "(need %lu have %lu) !\n", i, size,
  3108. radeon_bo_size(track->aa.robj));
  3109. DRM_ERROR("[drm] AA resolve buffer %d (%u %u %u %u)\n",
  3110. i, track->aa.pitch, track->cb[0].cpp,
  3111. track->aa.offset, track->maxy);
  3112. return -EINVAL;
  3113. }
  3114. }
  3115. track->aa_dirty = false;
  3116. prim_walk = (track->vap_vf_cntl >> 4) & 0x3;
  3117. if (track->vap_vf_cntl & (1 << 14)) {
  3118. nverts = track->vap_alt_nverts;
  3119. } else {
  3120. nverts = (track->vap_vf_cntl >> 16) & 0xFFFF;
  3121. }
  3122. switch (prim_walk) {
  3123. case 1:
  3124. for (i = 0; i < track->num_arrays; i++) {
  3125. size = track->arrays[i].esize * track->max_indx * 4;
  3126. if (track->arrays[i].robj == NULL) {
  3127. DRM_ERROR("(PW %u) Vertex array %u no buffer "
  3128. "bound\n", prim_walk, i);
  3129. return -EINVAL;
  3130. }
  3131. if (size > radeon_bo_size(track->arrays[i].robj)) {
  3132. dev_err(rdev->dev, "(PW %u) Vertex array %u "
  3133. "need %lu dwords have %lu dwords\n",
  3134. prim_walk, i, size >> 2,
  3135. radeon_bo_size(track->arrays[i].robj)
  3136. >> 2);
  3137. DRM_ERROR("Max indices %u\n", track->max_indx);
  3138. return -EINVAL;
  3139. }
  3140. }
  3141. break;
  3142. case 2:
  3143. for (i = 0; i < track->num_arrays; i++) {
  3144. size = track->arrays[i].esize * (nverts - 1) * 4;
  3145. if (track->arrays[i].robj == NULL) {
  3146. DRM_ERROR("(PW %u) Vertex array %u no buffer "
  3147. "bound\n", prim_walk, i);
  3148. return -EINVAL;
  3149. }
  3150. if (size > radeon_bo_size(track->arrays[i].robj)) {
  3151. dev_err(rdev->dev, "(PW %u) Vertex array %u "
  3152. "need %lu dwords have %lu dwords\n",
  3153. prim_walk, i, size >> 2,
  3154. radeon_bo_size(track->arrays[i].robj)
  3155. >> 2);
  3156. return -EINVAL;
  3157. }
  3158. }
  3159. break;
  3160. case 3:
  3161. size = track->vtx_size * nverts;
  3162. if (size != track->immd_dwords) {
  3163. DRM_ERROR("IMMD draw %u dwors but needs %lu dwords\n",
  3164. track->immd_dwords, size);
  3165. DRM_ERROR("VAP_VF_CNTL.NUM_VERTICES %u, VTX_SIZE %u\n",
  3166. nverts, track->vtx_size);
  3167. return -EINVAL;
  3168. }
  3169. break;
  3170. default:
  3171. DRM_ERROR("[drm] Invalid primitive walk %d for VAP_VF_CNTL\n",
  3172. prim_walk);
  3173. return -EINVAL;
  3174. }
  3175. if (track->tex_dirty) {
  3176. track->tex_dirty = false;
  3177. return r100_cs_track_texture_check(rdev, track);
  3178. }
  3179. return 0;
  3180. }
  3181. void r100_cs_track_clear(struct radeon_device *rdev, struct r100_cs_track *track)
  3182. {
  3183. unsigned i, face;
  3184. track->cb_dirty = true;
  3185. track->zb_dirty = true;
  3186. track->tex_dirty = true;
  3187. track->aa_dirty = true;
  3188. if (rdev->family < CHIP_R300) {
  3189. track->num_cb = 1;
  3190. if (rdev->family <= CHIP_RS200)
  3191. track->num_texture = 3;
  3192. else
  3193. track->num_texture = 6;
  3194. track->maxy = 2048;
  3195. track->separate_cube = 1;
  3196. } else {
  3197. track->num_cb = 4;
  3198. track->num_texture = 16;
  3199. track->maxy = 4096;
  3200. track->separate_cube = 0;
  3201. track->aaresolve = false;
  3202. track->aa.robj = NULL;
  3203. }
  3204. for (i = 0; i < track->num_cb; i++) {
  3205. track->cb[i].robj = NULL;
  3206. track->cb[i].pitch = 8192;
  3207. track->cb[i].cpp = 16;
  3208. track->cb[i].offset = 0;
  3209. }
  3210. track->z_enabled = true;
  3211. track->zb.robj = NULL;
  3212. track->zb.pitch = 8192;
  3213. track->zb.cpp = 4;
  3214. track->zb.offset = 0;
  3215. track->vtx_size = 0x7F;
  3216. track->immd_dwords = 0xFFFFFFFFUL;
  3217. track->num_arrays = 11;
  3218. track->max_indx = 0x00FFFFFFUL;
  3219. for (i = 0; i < track->num_arrays; i++) {
  3220. track->arrays[i].robj = NULL;
  3221. track->arrays[i].esize = 0x7F;
  3222. }
  3223. for (i = 0; i < track->num_texture; i++) {
  3224. track->textures[i].compress_format = R100_TRACK_COMP_NONE;
  3225. track->textures[i].pitch = 16536;
  3226. track->textures[i].width = 16536;
  3227. track->textures[i].height = 16536;
  3228. track->textures[i].width_11 = 1 << 11;
  3229. track->textures[i].height_11 = 1 << 11;
  3230. track->textures[i].num_levels = 12;
  3231. if (rdev->family <= CHIP_RS200) {
  3232. track->textures[i].tex_coord_type = 0;
  3233. track->textures[i].txdepth = 0;
  3234. } else {
  3235. track->textures[i].txdepth = 16;
  3236. track->textures[i].tex_coord_type = 1;
  3237. }
  3238. track->textures[i].cpp = 64;
  3239. track->textures[i].robj = NULL;
  3240. /* CS IB emission code makes sure texture unit are disabled */
  3241. track->textures[i].enabled = false;
  3242. track->textures[i].lookup_disable = false;
  3243. track->textures[i].roundup_w = true;
  3244. track->textures[i].roundup_h = true;
  3245. if (track->separate_cube)
  3246. for (face = 0; face < 5; face++) {
  3247. track->textures[i].cube_info[face].robj = NULL;
  3248. track->textures[i].cube_info[face].width = 16536;
  3249. track->textures[i].cube_info[face].height = 16536;
  3250. track->textures[i].cube_info[face].offset = 0;
  3251. }
  3252. }
  3253. }
  3254. int r100_ring_test(struct radeon_device *rdev)
  3255. {
  3256. uint32_t scratch;
  3257. uint32_t tmp = 0;
  3258. unsigned i;
  3259. int r;
  3260. r = radeon_scratch_get(rdev, &scratch);
  3261. if (r) {
  3262. DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
  3263. return r;
  3264. }
  3265. WREG32(scratch, 0xCAFEDEAD);
  3266. r = radeon_ring_lock(rdev, 2);
  3267. if (r) {
  3268. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  3269. radeon_scratch_free(rdev, scratch);
  3270. return r;
  3271. }
  3272. radeon_ring_write(rdev, PACKET0(scratch, 0));
  3273. radeon_ring_write(rdev, 0xDEADBEEF);
  3274. radeon_ring_unlock_commit(rdev);
  3275. for (i = 0; i < rdev->usec_timeout; i++) {
  3276. tmp = RREG32(scratch);
  3277. if (tmp == 0xDEADBEEF) {
  3278. break;
  3279. }
  3280. DRM_UDELAY(1);
  3281. }
  3282. if (i < rdev->usec_timeout) {
  3283. DRM_INFO("ring test succeeded in %d usecs\n", i);
  3284. } else {
  3285. DRM_ERROR("radeon: ring test failed (scratch(0x%04X)=0x%08X)\n",
  3286. scratch, tmp);
  3287. r = -EINVAL;
  3288. }
  3289. radeon_scratch_free(rdev, scratch);
  3290. return r;
  3291. }
  3292. void r100_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  3293. {
  3294. radeon_ring_write(rdev, PACKET0(RADEON_CP_IB_BASE, 1));
  3295. radeon_ring_write(rdev, ib->gpu_addr);
  3296. radeon_ring_write(rdev, ib->length_dw);
  3297. }
  3298. int r100_ib_test(struct radeon_device *rdev)
  3299. {
  3300. struct radeon_ib *ib;
  3301. uint32_t scratch;
  3302. uint32_t tmp = 0;
  3303. unsigned i;
  3304. int r;
  3305. r = radeon_scratch_get(rdev, &scratch);
  3306. if (r) {
  3307. DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
  3308. return r;
  3309. }
  3310. WREG32(scratch, 0xCAFEDEAD);
  3311. r = radeon_ib_get(rdev, &ib);
  3312. if (r) {
  3313. return r;
  3314. }
  3315. ib->ptr[0] = PACKET0(scratch, 0);
  3316. ib->ptr[1] = 0xDEADBEEF;
  3317. ib->ptr[2] = PACKET2(0);
  3318. ib->ptr[3] = PACKET2(0);
  3319. ib->ptr[4] = PACKET2(0);
  3320. ib->ptr[5] = PACKET2(0);
  3321. ib->ptr[6] = PACKET2(0);
  3322. ib->ptr[7] = PACKET2(0);
  3323. ib->length_dw = 8;
  3324. r = radeon_ib_schedule(rdev, ib);
  3325. if (r) {
  3326. radeon_scratch_free(rdev, scratch);
  3327. radeon_ib_free(rdev, &ib);
  3328. return r;
  3329. }
  3330. r = radeon_fence_wait(ib->fence, false);
  3331. if (r) {
  3332. return r;
  3333. }
  3334. for (i = 0; i < rdev->usec_timeout; i++) {
  3335. tmp = RREG32(scratch);
  3336. if (tmp == 0xDEADBEEF) {
  3337. break;
  3338. }
  3339. DRM_UDELAY(1);
  3340. }
  3341. if (i < rdev->usec_timeout) {
  3342. DRM_INFO("ib test succeeded in %u usecs\n", i);
  3343. } else {
  3344. DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
  3345. scratch, tmp);
  3346. r = -EINVAL;
  3347. }
  3348. radeon_scratch_free(rdev, scratch);
  3349. radeon_ib_free(rdev, &ib);
  3350. return r;
  3351. }
  3352. void r100_ib_fini(struct radeon_device *rdev)
  3353. {
  3354. radeon_ib_pool_fini(rdev);
  3355. }
  3356. int r100_ib_init(struct radeon_device *rdev)
  3357. {
  3358. int r;
  3359. r = radeon_ib_pool_init(rdev);
  3360. if (r) {
  3361. dev_err(rdev->dev, "failed initializing IB pool (%d).\n", r);
  3362. r100_ib_fini(rdev);
  3363. return r;
  3364. }
  3365. r = r100_ib_test(rdev);
  3366. if (r) {
  3367. dev_err(rdev->dev, "failed testing IB (%d).\n", r);
  3368. r100_ib_fini(rdev);
  3369. return r;
  3370. }
  3371. return 0;
  3372. }
  3373. void r100_mc_stop(struct radeon_device *rdev, struct r100_mc_save *save)
  3374. {
  3375. /* Shutdown CP we shouldn't need to do that but better be safe than
  3376. * sorry
  3377. */
  3378. rdev->cp.ready = false;
  3379. WREG32(R_000740_CP_CSQ_CNTL, 0);
  3380. /* Save few CRTC registers */
  3381. save->GENMO_WT = RREG8(R_0003C2_GENMO_WT);
  3382. save->CRTC_EXT_CNTL = RREG32(R_000054_CRTC_EXT_CNTL);
  3383. save->CRTC_GEN_CNTL = RREG32(R_000050_CRTC_GEN_CNTL);
  3384. save->CUR_OFFSET = RREG32(R_000260_CUR_OFFSET);
  3385. if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
  3386. save->CRTC2_GEN_CNTL = RREG32(R_0003F8_CRTC2_GEN_CNTL);
  3387. save->CUR2_OFFSET = RREG32(R_000360_CUR2_OFFSET);
  3388. }
  3389. /* Disable VGA aperture access */
  3390. WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & save->GENMO_WT);
  3391. /* Disable cursor, overlay, crtc */
  3392. WREG32(R_000260_CUR_OFFSET, save->CUR_OFFSET | S_000260_CUR_LOCK(1));
  3393. WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL |
  3394. S_000054_CRTC_DISPLAY_DIS(1));
  3395. WREG32(R_000050_CRTC_GEN_CNTL,
  3396. (C_000050_CRTC_CUR_EN & save->CRTC_GEN_CNTL) |
  3397. S_000050_CRTC_DISP_REQ_EN_B(1));
  3398. WREG32(R_000420_OV0_SCALE_CNTL,
  3399. C_000420_OV0_OVERLAY_EN & RREG32(R_000420_OV0_SCALE_CNTL));
  3400. WREG32(R_000260_CUR_OFFSET, C_000260_CUR_LOCK & save->CUR_OFFSET);
  3401. if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
  3402. WREG32(R_000360_CUR2_OFFSET, save->CUR2_OFFSET |
  3403. S_000360_CUR2_LOCK(1));
  3404. WREG32(R_0003F8_CRTC2_GEN_CNTL,
  3405. (C_0003F8_CRTC2_CUR_EN & save->CRTC2_GEN_CNTL) |
  3406. S_0003F8_CRTC2_DISPLAY_DIS(1) |
  3407. S_0003F8_CRTC2_DISP_REQ_EN_B(1));
  3408. WREG32(R_000360_CUR2_OFFSET,
  3409. C_000360_CUR2_LOCK & save->CUR2_OFFSET);
  3410. }
  3411. }
  3412. void r100_mc_resume(struct radeon_device *rdev, struct r100_mc_save *save)
  3413. {
  3414. /* Update base address for crtc */
  3415. WREG32(R_00023C_DISPLAY_BASE_ADDR, rdev->mc.vram_start);
  3416. if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
  3417. WREG32(R_00033C_CRTC2_DISPLAY_BASE_ADDR, rdev->mc.vram_start);
  3418. }
  3419. /* Restore CRTC registers */
  3420. WREG8(R_0003C2_GENMO_WT, save->GENMO_WT);
  3421. WREG32(R_000054_CRTC_EXT_CNTL, save->CRTC_EXT_CNTL);
  3422. WREG32(R_000050_CRTC_GEN_CNTL, save->CRTC_GEN_CNTL);
  3423. if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
  3424. WREG32(R_0003F8_CRTC2_GEN_CNTL, save->CRTC2_GEN_CNTL);
  3425. }
  3426. }
  3427. void r100_vga_render_disable(struct radeon_device *rdev)
  3428. {
  3429. u32 tmp;
  3430. tmp = RREG8(R_0003C2_GENMO_WT);
  3431. WREG8(R_0003C2_GENMO_WT, C_0003C2_VGA_RAM_EN & tmp);
  3432. }
  3433. static void r100_debugfs(struct radeon_device *rdev)
  3434. {
  3435. int r;
  3436. r = r100_debugfs_mc_info_init(rdev);
  3437. if (r)
  3438. dev_warn(rdev->dev, "Failed to create r100_mc debugfs file.\n");
  3439. }
  3440. static void r100_mc_program(struct radeon_device *rdev)
  3441. {
  3442. struct r100_mc_save save;
  3443. /* Stops all mc clients */
  3444. r100_mc_stop(rdev, &save);
  3445. if (rdev->flags & RADEON_IS_AGP) {
  3446. WREG32(R_00014C_MC_AGP_LOCATION,
  3447. S_00014C_MC_AGP_START(rdev->mc.gtt_start >> 16) |
  3448. S_00014C_MC_AGP_TOP(rdev->mc.gtt_end >> 16));
  3449. WREG32(R_000170_AGP_BASE, lower_32_bits(rdev->mc.agp_base));
  3450. if (rdev->family > CHIP_RV200)
  3451. WREG32(R_00015C_AGP_BASE_2,
  3452. upper_32_bits(rdev->mc.agp_base) & 0xff);
  3453. } else {
  3454. WREG32(R_00014C_MC_AGP_LOCATION, 0x0FFFFFFF);
  3455. WREG32(R_000170_AGP_BASE, 0);
  3456. if (rdev->family > CHIP_RV200)
  3457. WREG32(R_00015C_AGP_BASE_2, 0);
  3458. }
  3459. /* Wait for mc idle */
  3460. if (r100_mc_wait_for_idle(rdev))
  3461. dev_warn(rdev->dev, "Wait for MC idle timeout.\n");
  3462. /* Program MC, should be a 32bits limited address space */
  3463. WREG32(R_000148_MC_FB_LOCATION,
  3464. S_000148_MC_FB_START(rdev->mc.vram_start >> 16) |
  3465. S_000148_MC_FB_TOP(rdev->mc.vram_end >> 16));
  3466. r100_mc_resume(rdev, &save);
  3467. }
  3468. void r100_clock_startup(struct radeon_device *rdev)
  3469. {
  3470. u32 tmp;
  3471. if (radeon_dynclks != -1 && radeon_dynclks)
  3472. radeon_legacy_set_clock_gating(rdev, 1);
  3473. /* We need to force on some of the block */
  3474. tmp = RREG32_PLL(R_00000D_SCLK_CNTL);
  3475. tmp |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
  3476. if ((rdev->family == CHIP_RV250) || (rdev->family == CHIP_RV280))
  3477. tmp |= S_00000D_FORCE_DISP1(1) | S_00000D_FORCE_DISP2(1);
  3478. WREG32_PLL(R_00000D_SCLK_CNTL, tmp);
  3479. }
  3480. static int r100_startup(struct radeon_device *rdev)
  3481. {
  3482. int r;
  3483. /* set common regs */
  3484. r100_set_common_regs(rdev);
  3485. /* program mc */
  3486. r100_mc_program(rdev);
  3487. /* Resume clock */
  3488. r100_clock_startup(rdev);
  3489. /* Initialize GART (initialize after TTM so we can allocate
  3490. * memory through TTM but finalize after TTM) */
  3491. r100_enable_bm(rdev);
  3492. if (rdev->flags & RADEON_IS_PCI) {
  3493. r = r100_pci_gart_enable(rdev);
  3494. if (r)
  3495. return r;
  3496. }
  3497. /* allocate wb buffer */
  3498. r = radeon_wb_init(rdev);
  3499. if (r)
  3500. return r;
  3501. /* Enable IRQ */
  3502. r100_irq_set(rdev);
  3503. rdev->config.r100.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  3504. /* 1M ring buffer */
  3505. r = r100_cp_init(rdev, 1024 * 1024);
  3506. if (r) {
  3507. dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
  3508. return r;
  3509. }
  3510. r = r100_ib_init(rdev);
  3511. if (r) {
  3512. dev_err(rdev->dev, "failed initializing IB (%d).\n", r);
  3513. return r;
  3514. }
  3515. return 0;
  3516. }
  3517. int r100_resume(struct radeon_device *rdev)
  3518. {
  3519. /* Make sur GART are not working */
  3520. if (rdev->flags & RADEON_IS_PCI)
  3521. r100_pci_gart_disable(rdev);
  3522. /* Resume clock before doing reset */
  3523. r100_clock_startup(rdev);
  3524. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  3525. if (radeon_asic_reset(rdev)) {
  3526. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  3527. RREG32(R_000E40_RBBM_STATUS),
  3528. RREG32(R_0007C0_CP_STAT));
  3529. }
  3530. /* post */
  3531. radeon_combios_asic_init(rdev->ddev);
  3532. /* Resume clock after posting */
  3533. r100_clock_startup(rdev);
  3534. /* Initialize surface registers */
  3535. radeon_surface_init(rdev);
  3536. return r100_startup(rdev);
  3537. }
  3538. int r100_suspend(struct radeon_device *rdev)
  3539. {
  3540. r100_cp_disable(rdev);
  3541. radeon_wb_disable(rdev);
  3542. r100_irq_disable(rdev);
  3543. if (rdev->flags & RADEON_IS_PCI)
  3544. r100_pci_gart_disable(rdev);
  3545. return 0;
  3546. }
  3547. void r100_fini(struct radeon_device *rdev)
  3548. {
  3549. r100_cp_fini(rdev);
  3550. radeon_wb_fini(rdev);
  3551. r100_ib_fini(rdev);
  3552. radeon_gem_fini(rdev);
  3553. if (rdev->flags & RADEON_IS_PCI)
  3554. r100_pci_gart_fini(rdev);
  3555. radeon_agp_fini(rdev);
  3556. radeon_irq_kms_fini(rdev);
  3557. radeon_fence_driver_fini(rdev);
  3558. radeon_bo_fini(rdev);
  3559. radeon_atombios_fini(rdev);
  3560. kfree(rdev->bios);
  3561. rdev->bios = NULL;
  3562. }
  3563. /*
  3564. * Due to how kexec works, it can leave the hw fully initialised when it
  3565. * boots the new kernel. However doing our init sequence with the CP and
  3566. * WB stuff setup causes GPU hangs on the RN50 at least. So at startup
  3567. * do some quick sanity checks and restore sane values to avoid this
  3568. * problem.
  3569. */
  3570. void r100_restore_sanity(struct radeon_device *rdev)
  3571. {
  3572. u32 tmp;
  3573. tmp = RREG32(RADEON_CP_CSQ_CNTL);
  3574. if (tmp) {
  3575. WREG32(RADEON_CP_CSQ_CNTL, 0);
  3576. }
  3577. tmp = RREG32(RADEON_CP_RB_CNTL);
  3578. if (tmp) {
  3579. WREG32(RADEON_CP_RB_CNTL, 0);
  3580. }
  3581. tmp = RREG32(RADEON_SCRATCH_UMSK);
  3582. if (tmp) {
  3583. WREG32(RADEON_SCRATCH_UMSK, 0);
  3584. }
  3585. }
  3586. int r100_init(struct radeon_device *rdev)
  3587. {
  3588. int r;
  3589. /* Register debugfs file specific to this group of asics */
  3590. r100_debugfs(rdev);
  3591. /* Disable VGA */
  3592. r100_vga_render_disable(rdev);
  3593. /* Initialize scratch registers */
  3594. radeon_scratch_init(rdev);
  3595. /* Initialize surface registers */
  3596. radeon_surface_init(rdev);
  3597. /* sanity check some register to avoid hangs like after kexec */
  3598. r100_restore_sanity(rdev);
  3599. /* TODO: disable VGA need to use VGA request */
  3600. /* BIOS*/
  3601. if (!radeon_get_bios(rdev)) {
  3602. if (ASIC_IS_AVIVO(rdev))
  3603. return -EINVAL;
  3604. }
  3605. if (rdev->is_atom_bios) {
  3606. dev_err(rdev->dev, "Expecting combios for RS400/RS480 GPU\n");
  3607. return -EINVAL;
  3608. } else {
  3609. r = radeon_combios_init(rdev);
  3610. if (r)
  3611. return r;
  3612. }
  3613. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  3614. if (radeon_asic_reset(rdev)) {
  3615. dev_warn(rdev->dev,
  3616. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  3617. RREG32(R_000E40_RBBM_STATUS),
  3618. RREG32(R_0007C0_CP_STAT));
  3619. }
  3620. /* check if cards are posted or not */
  3621. if (radeon_boot_test_post_card(rdev) == false)
  3622. return -EINVAL;
  3623. /* Set asic errata */
  3624. r100_errata(rdev);
  3625. /* Initialize clocks */
  3626. radeon_get_clock_info(rdev->ddev);
  3627. /* initialize AGP */
  3628. if (rdev->flags & RADEON_IS_AGP) {
  3629. r = radeon_agp_init(rdev);
  3630. if (r) {
  3631. radeon_agp_disable(rdev);
  3632. }
  3633. }
  3634. /* initialize VRAM */
  3635. r100_mc_init(rdev);
  3636. /* Fence driver */
  3637. r = radeon_fence_driver_init(rdev);
  3638. if (r)
  3639. return r;
  3640. r = radeon_irq_kms_init(rdev);
  3641. if (r)
  3642. return r;
  3643. /* Memory manager */
  3644. r = radeon_bo_init(rdev);
  3645. if (r)
  3646. return r;
  3647. if (rdev->flags & RADEON_IS_PCI) {
  3648. r = r100_pci_gart_init(rdev);
  3649. if (r)
  3650. return r;
  3651. }
  3652. r100_set_safe_registers(rdev);
  3653. rdev->accel_working = true;
  3654. r = r100_startup(rdev);
  3655. if (r) {
  3656. /* Somethings want wront with the accel init stop accel */
  3657. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  3658. r100_cp_fini(rdev);
  3659. radeon_wb_fini(rdev);
  3660. r100_ib_fini(rdev);
  3661. radeon_irq_kms_fini(rdev);
  3662. if (rdev->flags & RADEON_IS_PCI)
  3663. r100_pci_gart_fini(rdev);
  3664. rdev->accel_working = false;
  3665. }
  3666. return 0;
  3667. }