r600_cp.c 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660
  1. /*
  2. * Copyright 2008-2009 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * 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) AND/OR ITS SUPPLIERS 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 OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors:
  25. * Dave Airlie <airlied@redhat.com>
  26. * Alex Deucher <alexander.deucher@amd.com>
  27. *
  28. * ------------------------ This file is DEPRECATED! -------------------------
  29. */
  30. #include <linux/module.h>
  31. #include <drm/drmP.h>
  32. #include <drm/radeon_drm.h>
  33. #include "radeon_drv.h"
  34. #define PFP_UCODE_SIZE 576
  35. #define PM4_UCODE_SIZE 1792
  36. #define R700_PFP_UCODE_SIZE 848
  37. #define R700_PM4_UCODE_SIZE 1360
  38. /* Firmware Names */
  39. MODULE_FIRMWARE("radeon/R600_pfp.bin");
  40. MODULE_FIRMWARE("radeon/R600_me.bin");
  41. MODULE_FIRMWARE("radeon/RV610_pfp.bin");
  42. MODULE_FIRMWARE("radeon/RV610_me.bin");
  43. MODULE_FIRMWARE("radeon/RV630_pfp.bin");
  44. MODULE_FIRMWARE("radeon/RV630_me.bin");
  45. MODULE_FIRMWARE("radeon/RV620_pfp.bin");
  46. MODULE_FIRMWARE("radeon/RV620_me.bin");
  47. MODULE_FIRMWARE("radeon/RV635_pfp.bin");
  48. MODULE_FIRMWARE("radeon/RV635_me.bin");
  49. MODULE_FIRMWARE("radeon/RV670_pfp.bin");
  50. MODULE_FIRMWARE("radeon/RV670_me.bin");
  51. MODULE_FIRMWARE("radeon/RS780_pfp.bin");
  52. MODULE_FIRMWARE("radeon/RS780_me.bin");
  53. MODULE_FIRMWARE("radeon/RV770_pfp.bin");
  54. MODULE_FIRMWARE("radeon/RV770_me.bin");
  55. MODULE_FIRMWARE("radeon/RV730_pfp.bin");
  56. MODULE_FIRMWARE("radeon/RV730_me.bin");
  57. MODULE_FIRMWARE("radeon/RV710_pfp.bin");
  58. MODULE_FIRMWARE("radeon/RV710_me.bin");
  59. int r600_cs_legacy(struct drm_device *dev, void *data, struct drm_file *filp,
  60. unsigned family, u32 *ib, int *l);
  61. void r600_cs_legacy_init(void);
  62. # define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */
  63. # define ATI_PCIGART_PAGE_MASK (~(ATI_PCIGART_PAGE_SIZE-1))
  64. #define R600_PTE_VALID (1 << 0)
  65. #define R600_PTE_SYSTEM (1 << 1)
  66. #define R600_PTE_SNOOPED (1 << 2)
  67. #define R600_PTE_READABLE (1 << 5)
  68. #define R600_PTE_WRITEABLE (1 << 6)
  69. /* MAX values used for gfx init */
  70. #define R6XX_MAX_SH_GPRS 256
  71. #define R6XX_MAX_TEMP_GPRS 16
  72. #define R6XX_MAX_SH_THREADS 256
  73. #define R6XX_MAX_SH_STACK_ENTRIES 4096
  74. #define R6XX_MAX_BACKENDS 8
  75. #define R6XX_MAX_BACKENDS_MASK 0xff
  76. #define R6XX_MAX_SIMDS 8
  77. #define R6XX_MAX_SIMDS_MASK 0xff
  78. #define R6XX_MAX_PIPES 8
  79. #define R6XX_MAX_PIPES_MASK 0xff
  80. #define R7XX_MAX_SH_GPRS 256
  81. #define R7XX_MAX_TEMP_GPRS 16
  82. #define R7XX_MAX_SH_THREADS 256
  83. #define R7XX_MAX_SH_STACK_ENTRIES 4096
  84. #define R7XX_MAX_BACKENDS 8
  85. #define R7XX_MAX_BACKENDS_MASK 0xff
  86. #define R7XX_MAX_SIMDS 16
  87. #define R7XX_MAX_SIMDS_MASK 0xffff
  88. #define R7XX_MAX_PIPES 8
  89. #define R7XX_MAX_PIPES_MASK 0xff
  90. static int r600_do_wait_for_fifo(drm_radeon_private_t *dev_priv, int entries)
  91. {
  92. int i;
  93. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  94. for (i = 0; i < dev_priv->usec_timeout; i++) {
  95. int slots;
  96. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770)
  97. slots = (RADEON_READ(R600_GRBM_STATUS)
  98. & R700_CMDFIFO_AVAIL_MASK);
  99. else
  100. slots = (RADEON_READ(R600_GRBM_STATUS)
  101. & R600_CMDFIFO_AVAIL_MASK);
  102. if (slots >= entries)
  103. return 0;
  104. DRM_UDELAY(1);
  105. }
  106. DRM_INFO("wait for fifo failed status : 0x%08X 0x%08X\n",
  107. RADEON_READ(R600_GRBM_STATUS),
  108. RADEON_READ(R600_GRBM_STATUS2));
  109. return -EBUSY;
  110. }
  111. static int r600_do_wait_for_idle(drm_radeon_private_t *dev_priv)
  112. {
  113. int i, ret;
  114. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  115. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770)
  116. ret = r600_do_wait_for_fifo(dev_priv, 8);
  117. else
  118. ret = r600_do_wait_for_fifo(dev_priv, 16);
  119. if (ret)
  120. return ret;
  121. for (i = 0; i < dev_priv->usec_timeout; i++) {
  122. if (!(RADEON_READ(R600_GRBM_STATUS) & R600_GUI_ACTIVE))
  123. return 0;
  124. DRM_UDELAY(1);
  125. }
  126. DRM_INFO("wait idle failed status : 0x%08X 0x%08X\n",
  127. RADEON_READ(R600_GRBM_STATUS),
  128. RADEON_READ(R600_GRBM_STATUS2));
  129. return -EBUSY;
  130. }
  131. void r600_page_table_cleanup(struct drm_device *dev, struct drm_ati_pcigart_info *gart_info)
  132. {
  133. struct drm_sg_mem *entry = dev->sg;
  134. int max_pages;
  135. int pages;
  136. int i;
  137. if (!entry)
  138. return;
  139. if (gart_info->bus_addr) {
  140. max_pages = (gart_info->table_size / sizeof(u64));
  141. pages = (entry->pages <= max_pages)
  142. ? entry->pages : max_pages;
  143. for (i = 0; i < pages; i++) {
  144. if (!entry->busaddr[i])
  145. break;
  146. pci_unmap_page(dev->pdev, entry->busaddr[i],
  147. PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  148. }
  149. if (gart_info->gart_table_location == DRM_ATI_GART_MAIN)
  150. gart_info->bus_addr = 0;
  151. }
  152. }
  153. /* R600 has page table setup */
  154. int r600_page_table_init(struct drm_device *dev)
  155. {
  156. drm_radeon_private_t *dev_priv = dev->dev_private;
  157. struct drm_ati_pcigart_info *gart_info = &dev_priv->gart_info;
  158. struct drm_local_map *map = &gart_info->mapping;
  159. struct drm_sg_mem *entry = dev->sg;
  160. int ret = 0;
  161. int i, j;
  162. int pages;
  163. u64 page_base;
  164. dma_addr_t entry_addr;
  165. int max_ati_pages, max_real_pages, gart_idx;
  166. /* okay page table is available - lets rock */
  167. max_ati_pages = (gart_info->table_size / sizeof(u64));
  168. max_real_pages = max_ati_pages / (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE);
  169. pages = (entry->pages <= max_real_pages) ?
  170. entry->pages : max_real_pages;
  171. memset_io((void __iomem *)map->handle, 0, max_ati_pages * sizeof(u64));
  172. gart_idx = 0;
  173. for (i = 0; i < pages; i++) {
  174. entry->busaddr[i] = pci_map_page(dev->pdev,
  175. entry->pagelist[i], 0,
  176. PAGE_SIZE,
  177. PCI_DMA_BIDIRECTIONAL);
  178. if (pci_dma_mapping_error(dev->pdev, entry->busaddr[i])) {
  179. DRM_ERROR("unable to map PCIGART pages!\n");
  180. r600_page_table_cleanup(dev, gart_info);
  181. goto done;
  182. }
  183. entry_addr = entry->busaddr[i];
  184. for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
  185. page_base = (u64) entry_addr & ATI_PCIGART_PAGE_MASK;
  186. page_base |= R600_PTE_VALID | R600_PTE_SYSTEM | R600_PTE_SNOOPED;
  187. page_base |= R600_PTE_READABLE | R600_PTE_WRITEABLE;
  188. DRM_WRITE64(map, gart_idx * sizeof(u64), page_base);
  189. gart_idx++;
  190. if ((i % 128) == 0)
  191. DRM_DEBUG("page entry %d: 0x%016llx\n",
  192. i, (unsigned long long)page_base);
  193. entry_addr += ATI_PCIGART_PAGE_SIZE;
  194. }
  195. }
  196. ret = 1;
  197. done:
  198. return ret;
  199. }
  200. static void r600_vm_flush_gart_range(struct drm_device *dev)
  201. {
  202. drm_radeon_private_t *dev_priv = dev->dev_private;
  203. u32 resp, countdown = 1000;
  204. RADEON_WRITE(R600_VM_CONTEXT0_INVALIDATION_LOW_ADDR, dev_priv->gart_vm_start >> 12);
  205. RADEON_WRITE(R600_VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (dev_priv->gart_vm_start + dev_priv->gart_size - 1) >> 12);
  206. RADEON_WRITE(R600_VM_CONTEXT0_REQUEST_RESPONSE, 2);
  207. do {
  208. resp = RADEON_READ(R600_VM_CONTEXT0_REQUEST_RESPONSE);
  209. countdown--;
  210. DRM_UDELAY(1);
  211. } while (((resp & 0xf0) == 0) && countdown);
  212. }
  213. static void r600_vm_init(struct drm_device *dev)
  214. {
  215. drm_radeon_private_t *dev_priv = dev->dev_private;
  216. /* initialise the VM to use the page table we constructed up there */
  217. u32 vm_c0, i;
  218. u32 mc_rd_a;
  219. u32 vm_l2_cntl, vm_l2_cntl3;
  220. /* okay set up the PCIE aperture type thingo */
  221. RADEON_WRITE(R600_MC_VM_SYSTEM_APERTURE_LOW_ADDR, dev_priv->gart_vm_start >> 12);
  222. RADEON_WRITE(R600_MC_VM_SYSTEM_APERTURE_HIGH_ADDR, (dev_priv->gart_vm_start + dev_priv->gart_size - 1) >> 12);
  223. RADEON_WRITE(R600_MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0);
  224. /* setup MC RD a */
  225. mc_rd_a = R600_MCD_L1_TLB | R600_MCD_L1_FRAG_PROC | R600_MCD_SYSTEM_ACCESS_MODE_IN_SYS |
  226. R600_MCD_SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU | R600_MCD_EFFECTIVE_L1_TLB_SIZE(5) |
  227. R600_MCD_EFFECTIVE_L1_QUEUE_SIZE(5) | R600_MCD_WAIT_L2_QUERY;
  228. RADEON_WRITE(R600_MCD_RD_A_CNTL, mc_rd_a);
  229. RADEON_WRITE(R600_MCD_RD_B_CNTL, mc_rd_a);
  230. RADEON_WRITE(R600_MCD_WR_A_CNTL, mc_rd_a);
  231. RADEON_WRITE(R600_MCD_WR_B_CNTL, mc_rd_a);
  232. RADEON_WRITE(R600_MCD_RD_GFX_CNTL, mc_rd_a);
  233. RADEON_WRITE(R600_MCD_WR_GFX_CNTL, mc_rd_a);
  234. RADEON_WRITE(R600_MCD_RD_SYS_CNTL, mc_rd_a);
  235. RADEON_WRITE(R600_MCD_WR_SYS_CNTL, mc_rd_a);
  236. RADEON_WRITE(R600_MCD_RD_HDP_CNTL, mc_rd_a | R600_MCD_L1_STRICT_ORDERING);
  237. RADEON_WRITE(R600_MCD_WR_HDP_CNTL, mc_rd_a /*| R600_MCD_L1_STRICT_ORDERING*/);
  238. RADEON_WRITE(R600_MCD_RD_PDMA_CNTL, mc_rd_a);
  239. RADEON_WRITE(R600_MCD_WR_PDMA_CNTL, mc_rd_a);
  240. RADEON_WRITE(R600_MCD_RD_SEM_CNTL, mc_rd_a | R600_MCD_SEMAPHORE_MODE);
  241. RADEON_WRITE(R600_MCD_WR_SEM_CNTL, mc_rd_a);
  242. vm_l2_cntl = R600_VM_L2_CACHE_EN | R600_VM_L2_FRAG_PROC | R600_VM_ENABLE_PTE_CACHE_LRU_W;
  243. vm_l2_cntl |= R600_VM_L2_CNTL_QUEUE_SIZE(7);
  244. RADEON_WRITE(R600_VM_L2_CNTL, vm_l2_cntl);
  245. RADEON_WRITE(R600_VM_L2_CNTL2, 0);
  246. vm_l2_cntl3 = (R600_VM_L2_CNTL3_BANK_SELECT_0(0) |
  247. R600_VM_L2_CNTL3_BANK_SELECT_1(1) |
  248. R600_VM_L2_CNTL3_CACHE_UPDATE_MODE(2));
  249. RADEON_WRITE(R600_VM_L2_CNTL3, vm_l2_cntl3);
  250. vm_c0 = R600_VM_ENABLE_CONTEXT | R600_VM_PAGE_TABLE_DEPTH_FLAT;
  251. RADEON_WRITE(R600_VM_CONTEXT0_CNTL, vm_c0);
  252. vm_c0 &= ~R600_VM_ENABLE_CONTEXT;
  253. /* disable all other contexts */
  254. for (i = 1; i < 8; i++)
  255. RADEON_WRITE(R600_VM_CONTEXT0_CNTL + (i * 4), vm_c0);
  256. RADEON_WRITE(R600_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, dev_priv->gart_info.bus_addr >> 12);
  257. RADEON_WRITE(R600_VM_CONTEXT0_PAGE_TABLE_START_ADDR, dev_priv->gart_vm_start >> 12);
  258. RADEON_WRITE(R600_VM_CONTEXT0_PAGE_TABLE_END_ADDR, (dev_priv->gart_vm_start + dev_priv->gart_size - 1) >> 12);
  259. r600_vm_flush_gart_range(dev);
  260. }
  261. static int r600_cp_init_microcode(drm_radeon_private_t *dev_priv)
  262. {
  263. struct platform_device *pdev;
  264. const char *chip_name;
  265. size_t pfp_req_size, me_req_size;
  266. char fw_name[30];
  267. int err;
  268. pdev = platform_device_register_simple("r600_cp", 0, NULL, 0);
  269. err = IS_ERR(pdev);
  270. if (err) {
  271. printk(KERN_ERR "r600_cp: Failed to register firmware\n");
  272. return -EINVAL;
  273. }
  274. switch (dev_priv->flags & RADEON_FAMILY_MASK) {
  275. case CHIP_R600: chip_name = "R600"; break;
  276. case CHIP_RV610: chip_name = "RV610"; break;
  277. case CHIP_RV630: chip_name = "RV630"; break;
  278. case CHIP_RV620: chip_name = "RV620"; break;
  279. case CHIP_RV635: chip_name = "RV635"; break;
  280. case CHIP_RV670: chip_name = "RV670"; break;
  281. case CHIP_RS780:
  282. case CHIP_RS880: chip_name = "RS780"; break;
  283. case CHIP_RV770: chip_name = "RV770"; break;
  284. case CHIP_RV730:
  285. case CHIP_RV740: chip_name = "RV730"; break;
  286. case CHIP_RV710: chip_name = "RV710"; break;
  287. default: BUG();
  288. }
  289. if ((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770) {
  290. pfp_req_size = R700_PFP_UCODE_SIZE * 4;
  291. me_req_size = R700_PM4_UCODE_SIZE * 4;
  292. } else {
  293. pfp_req_size = PFP_UCODE_SIZE * 4;
  294. me_req_size = PM4_UCODE_SIZE * 12;
  295. }
  296. DRM_INFO("Loading %s CP Microcode\n", chip_name);
  297. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  298. err = request_firmware(&dev_priv->pfp_fw, fw_name, &pdev->dev);
  299. if (err)
  300. goto out;
  301. if (dev_priv->pfp_fw->size != pfp_req_size) {
  302. printk(KERN_ERR
  303. "r600_cp: Bogus length %zu in firmware \"%s\"\n",
  304. dev_priv->pfp_fw->size, fw_name);
  305. err = -EINVAL;
  306. goto out;
  307. }
  308. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  309. err = request_firmware(&dev_priv->me_fw, fw_name, &pdev->dev);
  310. if (err)
  311. goto out;
  312. if (dev_priv->me_fw->size != me_req_size) {
  313. printk(KERN_ERR
  314. "r600_cp: Bogus length %zu in firmware \"%s\"\n",
  315. dev_priv->me_fw->size, fw_name);
  316. err = -EINVAL;
  317. }
  318. out:
  319. platform_device_unregister(pdev);
  320. if (err) {
  321. if (err != -EINVAL)
  322. printk(KERN_ERR
  323. "r600_cp: Failed to load firmware \"%s\"\n",
  324. fw_name);
  325. release_firmware(dev_priv->pfp_fw);
  326. dev_priv->pfp_fw = NULL;
  327. release_firmware(dev_priv->me_fw);
  328. dev_priv->me_fw = NULL;
  329. }
  330. return err;
  331. }
  332. static void r600_cp_load_microcode(drm_radeon_private_t *dev_priv)
  333. {
  334. const __be32 *fw_data;
  335. int i;
  336. if (!dev_priv->me_fw || !dev_priv->pfp_fw)
  337. return;
  338. r600_do_cp_stop(dev_priv);
  339. RADEON_WRITE(R600_CP_RB_CNTL,
  340. #ifdef __BIG_ENDIAN
  341. R600_BUF_SWAP_32BIT |
  342. #endif
  343. R600_RB_NO_UPDATE |
  344. R600_RB_BLKSZ(15) |
  345. R600_RB_BUFSZ(3));
  346. RADEON_WRITE(R600_GRBM_SOFT_RESET, R600_SOFT_RESET_CP);
  347. RADEON_READ(R600_GRBM_SOFT_RESET);
  348. mdelay(15);
  349. RADEON_WRITE(R600_GRBM_SOFT_RESET, 0);
  350. fw_data = (const __be32 *)dev_priv->me_fw->data;
  351. RADEON_WRITE(R600_CP_ME_RAM_WADDR, 0);
  352. for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
  353. RADEON_WRITE(R600_CP_ME_RAM_DATA,
  354. be32_to_cpup(fw_data++));
  355. fw_data = (const __be32 *)dev_priv->pfp_fw->data;
  356. RADEON_WRITE(R600_CP_PFP_UCODE_ADDR, 0);
  357. for (i = 0; i < PFP_UCODE_SIZE; i++)
  358. RADEON_WRITE(R600_CP_PFP_UCODE_DATA,
  359. be32_to_cpup(fw_data++));
  360. RADEON_WRITE(R600_CP_PFP_UCODE_ADDR, 0);
  361. RADEON_WRITE(R600_CP_ME_RAM_WADDR, 0);
  362. RADEON_WRITE(R600_CP_ME_RAM_RADDR, 0);
  363. }
  364. static void r700_vm_init(struct drm_device *dev)
  365. {
  366. drm_radeon_private_t *dev_priv = dev->dev_private;
  367. /* initialise the VM to use the page table we constructed up there */
  368. u32 vm_c0, i;
  369. u32 mc_vm_md_l1;
  370. u32 vm_l2_cntl, vm_l2_cntl3;
  371. /* okay set up the PCIE aperture type thingo */
  372. RADEON_WRITE(R700_MC_VM_SYSTEM_APERTURE_LOW_ADDR, dev_priv->gart_vm_start >> 12);
  373. RADEON_WRITE(R700_MC_VM_SYSTEM_APERTURE_HIGH_ADDR, (dev_priv->gart_vm_start + dev_priv->gart_size - 1) >> 12);
  374. RADEON_WRITE(R700_MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0);
  375. mc_vm_md_l1 = R700_ENABLE_L1_TLB |
  376. R700_ENABLE_L1_FRAGMENT_PROCESSING |
  377. R700_SYSTEM_ACCESS_MODE_IN_SYS |
  378. R700_SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU |
  379. R700_EFFECTIVE_L1_TLB_SIZE(5) |
  380. R700_EFFECTIVE_L1_QUEUE_SIZE(5);
  381. RADEON_WRITE(R700_MC_VM_MD_L1_TLB0_CNTL, mc_vm_md_l1);
  382. RADEON_WRITE(R700_MC_VM_MD_L1_TLB1_CNTL, mc_vm_md_l1);
  383. RADEON_WRITE(R700_MC_VM_MD_L1_TLB2_CNTL, mc_vm_md_l1);
  384. RADEON_WRITE(R700_MC_VM_MB_L1_TLB0_CNTL, mc_vm_md_l1);
  385. RADEON_WRITE(R700_MC_VM_MB_L1_TLB1_CNTL, mc_vm_md_l1);
  386. RADEON_WRITE(R700_MC_VM_MB_L1_TLB2_CNTL, mc_vm_md_l1);
  387. RADEON_WRITE(R700_MC_VM_MB_L1_TLB3_CNTL, mc_vm_md_l1);
  388. vm_l2_cntl = R600_VM_L2_CACHE_EN | R600_VM_L2_FRAG_PROC | R600_VM_ENABLE_PTE_CACHE_LRU_W;
  389. vm_l2_cntl |= R700_VM_L2_CNTL_QUEUE_SIZE(7);
  390. RADEON_WRITE(R600_VM_L2_CNTL, vm_l2_cntl);
  391. RADEON_WRITE(R600_VM_L2_CNTL2, 0);
  392. vm_l2_cntl3 = R700_VM_L2_CNTL3_BANK_SELECT(0) | R700_VM_L2_CNTL3_CACHE_UPDATE_MODE(2);
  393. RADEON_WRITE(R600_VM_L2_CNTL3, vm_l2_cntl3);
  394. vm_c0 = R600_VM_ENABLE_CONTEXT | R600_VM_PAGE_TABLE_DEPTH_FLAT;
  395. RADEON_WRITE(R600_VM_CONTEXT0_CNTL, vm_c0);
  396. vm_c0 &= ~R600_VM_ENABLE_CONTEXT;
  397. /* disable all other contexts */
  398. for (i = 1; i < 8; i++)
  399. RADEON_WRITE(R600_VM_CONTEXT0_CNTL + (i * 4), vm_c0);
  400. RADEON_WRITE(R700_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, dev_priv->gart_info.bus_addr >> 12);
  401. RADEON_WRITE(R700_VM_CONTEXT0_PAGE_TABLE_START_ADDR, dev_priv->gart_vm_start >> 12);
  402. RADEON_WRITE(R700_VM_CONTEXT0_PAGE_TABLE_END_ADDR, (dev_priv->gart_vm_start + dev_priv->gart_size - 1) >> 12);
  403. r600_vm_flush_gart_range(dev);
  404. }
  405. static void r700_cp_load_microcode(drm_radeon_private_t *dev_priv)
  406. {
  407. const __be32 *fw_data;
  408. int i;
  409. if (!dev_priv->me_fw || !dev_priv->pfp_fw)
  410. return;
  411. r600_do_cp_stop(dev_priv);
  412. RADEON_WRITE(R600_CP_RB_CNTL,
  413. #ifdef __BIG_ENDIAN
  414. R600_BUF_SWAP_32BIT |
  415. #endif
  416. R600_RB_NO_UPDATE |
  417. R600_RB_BLKSZ(15) |
  418. R600_RB_BUFSZ(3));
  419. RADEON_WRITE(R600_GRBM_SOFT_RESET, R600_SOFT_RESET_CP);
  420. RADEON_READ(R600_GRBM_SOFT_RESET);
  421. mdelay(15);
  422. RADEON_WRITE(R600_GRBM_SOFT_RESET, 0);
  423. fw_data = (const __be32 *)dev_priv->pfp_fw->data;
  424. RADEON_WRITE(R600_CP_PFP_UCODE_ADDR, 0);
  425. for (i = 0; i < R700_PFP_UCODE_SIZE; i++)
  426. RADEON_WRITE(R600_CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  427. RADEON_WRITE(R600_CP_PFP_UCODE_ADDR, 0);
  428. fw_data = (const __be32 *)dev_priv->me_fw->data;
  429. RADEON_WRITE(R600_CP_ME_RAM_WADDR, 0);
  430. for (i = 0; i < R700_PM4_UCODE_SIZE; i++)
  431. RADEON_WRITE(R600_CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  432. RADEON_WRITE(R600_CP_ME_RAM_WADDR, 0);
  433. RADEON_WRITE(R600_CP_PFP_UCODE_ADDR, 0);
  434. RADEON_WRITE(R600_CP_ME_RAM_WADDR, 0);
  435. RADEON_WRITE(R600_CP_ME_RAM_RADDR, 0);
  436. }
  437. static void r600_test_writeback(drm_radeon_private_t *dev_priv)
  438. {
  439. u32 tmp;
  440. /* Start with assuming that writeback doesn't work */
  441. dev_priv->writeback_works = 0;
  442. /* Writeback doesn't seem to work everywhere, test it here and possibly
  443. * enable it if it appears to work
  444. */
  445. radeon_write_ring_rptr(dev_priv, R600_SCRATCHOFF(1), 0);
  446. RADEON_WRITE(R600_SCRATCH_REG1, 0xdeadbeef);
  447. for (tmp = 0; tmp < dev_priv->usec_timeout; tmp++) {
  448. u32 val;
  449. val = radeon_read_ring_rptr(dev_priv, R600_SCRATCHOFF(1));
  450. if (val == 0xdeadbeef)
  451. break;
  452. DRM_UDELAY(1);
  453. }
  454. if (tmp < dev_priv->usec_timeout) {
  455. dev_priv->writeback_works = 1;
  456. DRM_INFO("writeback test succeeded in %d usecs\n", tmp);
  457. } else {
  458. dev_priv->writeback_works = 0;
  459. DRM_INFO("writeback test failed\n");
  460. }
  461. if (radeon_no_wb == 1) {
  462. dev_priv->writeback_works = 0;
  463. DRM_INFO("writeback forced off\n");
  464. }
  465. if (!dev_priv->writeback_works) {
  466. /* Disable writeback to avoid unnecessary bus master transfer */
  467. RADEON_WRITE(R600_CP_RB_CNTL,
  468. #ifdef __BIG_ENDIAN
  469. R600_BUF_SWAP_32BIT |
  470. #endif
  471. RADEON_READ(R600_CP_RB_CNTL) |
  472. R600_RB_NO_UPDATE);
  473. RADEON_WRITE(R600_SCRATCH_UMSK, 0);
  474. }
  475. }
  476. int r600_do_engine_reset(struct drm_device *dev)
  477. {
  478. drm_radeon_private_t *dev_priv = dev->dev_private;
  479. u32 cp_ptr, cp_me_cntl, cp_rb_cntl;
  480. DRM_INFO("Resetting GPU\n");
  481. cp_ptr = RADEON_READ(R600_CP_RB_WPTR);
  482. cp_me_cntl = RADEON_READ(R600_CP_ME_CNTL);
  483. RADEON_WRITE(R600_CP_ME_CNTL, R600_CP_ME_HALT);
  484. RADEON_WRITE(R600_GRBM_SOFT_RESET, 0x7fff);
  485. RADEON_READ(R600_GRBM_SOFT_RESET);
  486. DRM_UDELAY(50);
  487. RADEON_WRITE(R600_GRBM_SOFT_RESET, 0);
  488. RADEON_READ(R600_GRBM_SOFT_RESET);
  489. RADEON_WRITE(R600_CP_RB_WPTR_DELAY, 0);
  490. cp_rb_cntl = RADEON_READ(R600_CP_RB_CNTL);
  491. RADEON_WRITE(R600_CP_RB_CNTL,
  492. #ifdef __BIG_ENDIAN
  493. R600_BUF_SWAP_32BIT |
  494. #endif
  495. R600_RB_RPTR_WR_ENA);
  496. RADEON_WRITE(R600_CP_RB_RPTR_WR, cp_ptr);
  497. RADEON_WRITE(R600_CP_RB_WPTR, cp_ptr);
  498. RADEON_WRITE(R600_CP_RB_CNTL, cp_rb_cntl);
  499. RADEON_WRITE(R600_CP_ME_CNTL, cp_me_cntl);
  500. /* Reset the CP ring */
  501. r600_do_cp_reset(dev_priv);
  502. /* The CP is no longer running after an engine reset */
  503. dev_priv->cp_running = 0;
  504. /* Reset any pending vertex, indirect buffers */
  505. radeon_freelist_reset(dev);
  506. return 0;
  507. }
  508. static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes,
  509. u32 num_backends,
  510. u32 backend_disable_mask)
  511. {
  512. u32 backend_map = 0;
  513. u32 enabled_backends_mask;
  514. u32 enabled_backends_count;
  515. u32 cur_pipe;
  516. u32 swizzle_pipe[R6XX_MAX_PIPES];
  517. u32 cur_backend;
  518. u32 i;
  519. if (num_tile_pipes > R6XX_MAX_PIPES)
  520. num_tile_pipes = R6XX_MAX_PIPES;
  521. if (num_tile_pipes < 1)
  522. num_tile_pipes = 1;
  523. if (num_backends > R6XX_MAX_BACKENDS)
  524. num_backends = R6XX_MAX_BACKENDS;
  525. if (num_backends < 1)
  526. num_backends = 1;
  527. enabled_backends_mask = 0;
  528. enabled_backends_count = 0;
  529. for (i = 0; i < R6XX_MAX_BACKENDS; ++i) {
  530. if (((backend_disable_mask >> i) & 1) == 0) {
  531. enabled_backends_mask |= (1 << i);
  532. ++enabled_backends_count;
  533. }
  534. if (enabled_backends_count == num_backends)
  535. break;
  536. }
  537. if (enabled_backends_count == 0) {
  538. enabled_backends_mask = 1;
  539. enabled_backends_count = 1;
  540. }
  541. if (enabled_backends_count != num_backends)
  542. num_backends = enabled_backends_count;
  543. memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
  544. switch (num_tile_pipes) {
  545. case 1:
  546. swizzle_pipe[0] = 0;
  547. break;
  548. case 2:
  549. swizzle_pipe[0] = 0;
  550. swizzle_pipe[1] = 1;
  551. break;
  552. case 3:
  553. swizzle_pipe[0] = 0;
  554. swizzle_pipe[1] = 1;
  555. swizzle_pipe[2] = 2;
  556. break;
  557. case 4:
  558. swizzle_pipe[0] = 0;
  559. swizzle_pipe[1] = 1;
  560. swizzle_pipe[2] = 2;
  561. swizzle_pipe[3] = 3;
  562. break;
  563. case 5:
  564. swizzle_pipe[0] = 0;
  565. swizzle_pipe[1] = 1;
  566. swizzle_pipe[2] = 2;
  567. swizzle_pipe[3] = 3;
  568. swizzle_pipe[4] = 4;
  569. break;
  570. case 6:
  571. swizzle_pipe[0] = 0;
  572. swizzle_pipe[1] = 2;
  573. swizzle_pipe[2] = 4;
  574. swizzle_pipe[3] = 5;
  575. swizzle_pipe[4] = 1;
  576. swizzle_pipe[5] = 3;
  577. break;
  578. case 7:
  579. swizzle_pipe[0] = 0;
  580. swizzle_pipe[1] = 2;
  581. swizzle_pipe[2] = 4;
  582. swizzle_pipe[3] = 6;
  583. swizzle_pipe[4] = 1;
  584. swizzle_pipe[5] = 3;
  585. swizzle_pipe[6] = 5;
  586. break;
  587. case 8:
  588. swizzle_pipe[0] = 0;
  589. swizzle_pipe[1] = 2;
  590. swizzle_pipe[2] = 4;
  591. swizzle_pipe[3] = 6;
  592. swizzle_pipe[4] = 1;
  593. swizzle_pipe[5] = 3;
  594. swizzle_pipe[6] = 5;
  595. swizzle_pipe[7] = 7;
  596. break;
  597. }
  598. cur_backend = 0;
  599. for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
  600. while (((1 << cur_backend) & enabled_backends_mask) == 0)
  601. cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
  602. backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
  603. cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
  604. }
  605. return backend_map;
  606. }
  607. static int r600_count_pipe_bits(uint32_t val)
  608. {
  609. return hweight32(val);
  610. }
  611. static void r600_gfx_init(struct drm_device *dev,
  612. drm_radeon_private_t *dev_priv)
  613. {
  614. int i, j, num_qd_pipes;
  615. u32 sx_debug_1;
  616. u32 tc_cntl;
  617. u32 arb_pop;
  618. u32 num_gs_verts_per_thread;
  619. u32 vgt_gs_per_es;
  620. u32 gs_prim_buffer_depth = 0;
  621. u32 sq_ms_fifo_sizes;
  622. u32 sq_config;
  623. u32 sq_gpr_resource_mgmt_1 = 0;
  624. u32 sq_gpr_resource_mgmt_2 = 0;
  625. u32 sq_thread_resource_mgmt = 0;
  626. u32 sq_stack_resource_mgmt_1 = 0;
  627. u32 sq_stack_resource_mgmt_2 = 0;
  628. u32 hdp_host_path_cntl;
  629. u32 backend_map;
  630. u32 gb_tiling_config = 0;
  631. u32 cc_rb_backend_disable;
  632. u32 cc_gc_shader_pipe_config;
  633. u32 ramcfg;
  634. /* setup chip specs */
  635. switch (dev_priv->flags & RADEON_FAMILY_MASK) {
  636. case CHIP_R600:
  637. dev_priv->r600_max_pipes = 4;
  638. dev_priv->r600_max_tile_pipes = 8;
  639. dev_priv->r600_max_simds = 4;
  640. dev_priv->r600_max_backends = 4;
  641. dev_priv->r600_max_gprs = 256;
  642. dev_priv->r600_max_threads = 192;
  643. dev_priv->r600_max_stack_entries = 256;
  644. dev_priv->r600_max_hw_contexts = 8;
  645. dev_priv->r600_max_gs_threads = 16;
  646. dev_priv->r600_sx_max_export_size = 128;
  647. dev_priv->r600_sx_max_export_pos_size = 16;
  648. dev_priv->r600_sx_max_export_smx_size = 128;
  649. dev_priv->r600_sq_num_cf_insts = 2;
  650. break;
  651. case CHIP_RV630:
  652. case CHIP_RV635:
  653. dev_priv->r600_max_pipes = 2;
  654. dev_priv->r600_max_tile_pipes = 2;
  655. dev_priv->r600_max_simds = 3;
  656. dev_priv->r600_max_backends = 1;
  657. dev_priv->r600_max_gprs = 128;
  658. dev_priv->r600_max_threads = 192;
  659. dev_priv->r600_max_stack_entries = 128;
  660. dev_priv->r600_max_hw_contexts = 8;
  661. dev_priv->r600_max_gs_threads = 4;
  662. dev_priv->r600_sx_max_export_size = 128;
  663. dev_priv->r600_sx_max_export_pos_size = 16;
  664. dev_priv->r600_sx_max_export_smx_size = 128;
  665. dev_priv->r600_sq_num_cf_insts = 2;
  666. break;
  667. case CHIP_RV610:
  668. case CHIP_RS780:
  669. case CHIP_RS880:
  670. case CHIP_RV620:
  671. dev_priv->r600_max_pipes = 1;
  672. dev_priv->r600_max_tile_pipes = 1;
  673. dev_priv->r600_max_simds = 2;
  674. dev_priv->r600_max_backends = 1;
  675. dev_priv->r600_max_gprs = 128;
  676. dev_priv->r600_max_threads = 192;
  677. dev_priv->r600_max_stack_entries = 128;
  678. dev_priv->r600_max_hw_contexts = 4;
  679. dev_priv->r600_max_gs_threads = 4;
  680. dev_priv->r600_sx_max_export_size = 128;
  681. dev_priv->r600_sx_max_export_pos_size = 16;
  682. dev_priv->r600_sx_max_export_smx_size = 128;
  683. dev_priv->r600_sq_num_cf_insts = 1;
  684. break;
  685. case CHIP_RV670:
  686. dev_priv->r600_max_pipes = 4;
  687. dev_priv->r600_max_tile_pipes = 4;
  688. dev_priv->r600_max_simds = 4;
  689. dev_priv->r600_max_backends = 4;
  690. dev_priv->r600_max_gprs = 192;
  691. dev_priv->r600_max_threads = 192;
  692. dev_priv->r600_max_stack_entries = 256;
  693. dev_priv->r600_max_hw_contexts = 8;
  694. dev_priv->r600_max_gs_threads = 16;
  695. dev_priv->r600_sx_max_export_size = 128;
  696. dev_priv->r600_sx_max_export_pos_size = 16;
  697. dev_priv->r600_sx_max_export_smx_size = 128;
  698. dev_priv->r600_sq_num_cf_insts = 2;
  699. break;
  700. default:
  701. break;
  702. }
  703. /* Initialize HDP */
  704. j = 0;
  705. for (i = 0; i < 32; i++) {
  706. RADEON_WRITE((0x2c14 + j), 0x00000000);
  707. RADEON_WRITE((0x2c18 + j), 0x00000000);
  708. RADEON_WRITE((0x2c1c + j), 0x00000000);
  709. RADEON_WRITE((0x2c20 + j), 0x00000000);
  710. RADEON_WRITE((0x2c24 + j), 0x00000000);
  711. j += 0x18;
  712. }
  713. RADEON_WRITE(R600_GRBM_CNTL, R600_GRBM_READ_TIMEOUT(0xff));
  714. /* setup tiling, simd, pipe config */
  715. ramcfg = RADEON_READ(R600_RAMCFG);
  716. switch (dev_priv->r600_max_tile_pipes) {
  717. case 1:
  718. gb_tiling_config |= R600_PIPE_TILING(0);
  719. break;
  720. case 2:
  721. gb_tiling_config |= R600_PIPE_TILING(1);
  722. break;
  723. case 4:
  724. gb_tiling_config |= R600_PIPE_TILING(2);
  725. break;
  726. case 8:
  727. gb_tiling_config |= R600_PIPE_TILING(3);
  728. break;
  729. default:
  730. break;
  731. }
  732. gb_tiling_config |= R600_BANK_TILING((ramcfg >> R600_NOOFBANK_SHIFT) & R600_NOOFBANK_MASK);
  733. gb_tiling_config |= R600_GROUP_SIZE(0);
  734. if (((ramcfg >> R600_NOOFROWS_SHIFT) & R600_NOOFROWS_MASK) > 3) {
  735. gb_tiling_config |= R600_ROW_TILING(3);
  736. gb_tiling_config |= R600_SAMPLE_SPLIT(3);
  737. } else {
  738. gb_tiling_config |=
  739. R600_ROW_TILING(((ramcfg >> R600_NOOFROWS_SHIFT) & R600_NOOFROWS_MASK));
  740. gb_tiling_config |=
  741. R600_SAMPLE_SPLIT(((ramcfg >> R600_NOOFROWS_SHIFT) & R600_NOOFROWS_MASK));
  742. }
  743. gb_tiling_config |= R600_BANK_SWAPS(1);
  744. cc_rb_backend_disable = RADEON_READ(R600_CC_RB_BACKEND_DISABLE) & 0x00ff0000;
  745. cc_rb_backend_disable |=
  746. R600_BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << dev_priv->r600_max_backends) & R6XX_MAX_BACKENDS_MASK);
  747. cc_gc_shader_pipe_config = RADEON_READ(R600_CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
  748. cc_gc_shader_pipe_config |=
  749. R600_INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << dev_priv->r600_max_pipes) & R6XX_MAX_PIPES_MASK);
  750. cc_gc_shader_pipe_config |=
  751. R600_INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << dev_priv->r600_max_simds) & R6XX_MAX_SIMDS_MASK);
  752. backend_map = r600_get_tile_pipe_to_backend_map(dev_priv->r600_max_tile_pipes,
  753. (R6XX_MAX_BACKENDS -
  754. r600_count_pipe_bits((cc_rb_backend_disable &
  755. R6XX_MAX_BACKENDS_MASK) >> 16)),
  756. (cc_rb_backend_disable >> 16));
  757. gb_tiling_config |= R600_BACKEND_MAP(backend_map);
  758. RADEON_WRITE(R600_GB_TILING_CONFIG, gb_tiling_config);
  759. RADEON_WRITE(R600_DCP_TILING_CONFIG, (gb_tiling_config & 0xffff));
  760. RADEON_WRITE(R600_HDP_TILING_CONFIG, (gb_tiling_config & 0xffff));
  761. if (gb_tiling_config & 0xc0) {
  762. dev_priv->r600_group_size = 512;
  763. } else {
  764. dev_priv->r600_group_size = 256;
  765. }
  766. dev_priv->r600_npipes = 1 << ((gb_tiling_config >> 1) & 0x7);
  767. if (gb_tiling_config & 0x30) {
  768. dev_priv->r600_nbanks = 8;
  769. } else {
  770. dev_priv->r600_nbanks = 4;
  771. }
  772. RADEON_WRITE(R600_CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
  773. RADEON_WRITE(R600_CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  774. RADEON_WRITE(R600_GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  775. num_qd_pipes =
  776. R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & R600_INACTIVE_QD_PIPES_MASK) >> 8);
  777. RADEON_WRITE(R600_VGT_OUT_DEALLOC_CNTL, (num_qd_pipes * 4) & R600_DEALLOC_DIST_MASK);
  778. RADEON_WRITE(R600_VGT_VERTEX_REUSE_BLOCK_CNTL, ((num_qd_pipes * 4) - 2) & R600_VTX_REUSE_DEPTH_MASK);
  779. /* set HW defaults for 3D engine */
  780. RADEON_WRITE(R600_CP_QUEUE_THRESHOLDS, (R600_ROQ_IB1_START(0x16) |
  781. R600_ROQ_IB2_START(0x2b)));
  782. RADEON_WRITE(R600_CP_MEQ_THRESHOLDS, (R600_MEQ_END(0x40) |
  783. R600_ROQ_END(0x40)));
  784. RADEON_WRITE(R600_TA_CNTL_AUX, (R600_DISABLE_CUBE_ANISO |
  785. R600_SYNC_GRADIENT |
  786. R600_SYNC_WALKER |
  787. R600_SYNC_ALIGNER));
  788. if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV670)
  789. RADEON_WRITE(R600_ARB_GDEC_RD_CNTL, 0x00000021);
  790. sx_debug_1 = RADEON_READ(R600_SX_DEBUG_1);
  791. sx_debug_1 |= R600_SMX_EVENT_RELEASE;
  792. if (((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_R600))
  793. sx_debug_1 |= R600_ENABLE_NEW_SMX_ADDRESS;
  794. RADEON_WRITE(R600_SX_DEBUG_1, sx_debug_1);
  795. if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R600) ||
  796. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV630) ||
  797. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV610) ||
  798. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV620) ||
  799. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS780) ||
  800. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS880))
  801. RADEON_WRITE(R600_DB_DEBUG, R600_PREZ_MUST_WAIT_FOR_POSTZ_DONE);
  802. else
  803. RADEON_WRITE(R600_DB_DEBUG, 0);
  804. RADEON_WRITE(R600_DB_WATERMARKS, (R600_DEPTH_FREE(4) |
  805. R600_DEPTH_FLUSH(16) |
  806. R600_DEPTH_PENDING_FREE(4) |
  807. R600_DEPTH_CACHELINE_FREE(16)));
  808. RADEON_WRITE(R600_PA_SC_MULTI_CHIP_CNTL, 0);
  809. RADEON_WRITE(R600_VGT_NUM_INSTANCES, 0);
  810. RADEON_WRITE(R600_SPI_CONFIG_CNTL, R600_GPR_WRITE_PRIORITY(0));
  811. RADEON_WRITE(R600_SPI_CONFIG_CNTL_1, R600_VTX_DONE_DELAY(0));
  812. sq_ms_fifo_sizes = RADEON_READ(R600_SQ_MS_FIFO_SIZES);
  813. if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV610) ||
  814. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV620) ||
  815. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS780) ||
  816. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS880)) {
  817. sq_ms_fifo_sizes = (R600_CACHE_FIFO_SIZE(0xa) |
  818. R600_FETCH_FIFO_HIWATER(0xa) |
  819. R600_DONE_FIFO_HIWATER(0xe0) |
  820. R600_ALU_UPDATE_FIFO_HIWATER(0x8));
  821. } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R600) ||
  822. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV630)) {
  823. sq_ms_fifo_sizes &= ~R600_DONE_FIFO_HIWATER(0xff);
  824. sq_ms_fifo_sizes |= R600_DONE_FIFO_HIWATER(0x4);
  825. }
  826. RADEON_WRITE(R600_SQ_MS_FIFO_SIZES, sq_ms_fifo_sizes);
  827. /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
  828. * should be adjusted as needed by the 2D/3D drivers. This just sets default values
  829. */
  830. sq_config = RADEON_READ(R600_SQ_CONFIG);
  831. sq_config &= ~(R600_PS_PRIO(3) |
  832. R600_VS_PRIO(3) |
  833. R600_GS_PRIO(3) |
  834. R600_ES_PRIO(3));
  835. sq_config |= (R600_DX9_CONSTS |
  836. R600_VC_ENABLE |
  837. R600_PS_PRIO(0) |
  838. R600_VS_PRIO(1) |
  839. R600_GS_PRIO(2) |
  840. R600_ES_PRIO(3));
  841. if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_R600) {
  842. sq_gpr_resource_mgmt_1 = (R600_NUM_PS_GPRS(124) |
  843. R600_NUM_VS_GPRS(124) |
  844. R600_NUM_CLAUSE_TEMP_GPRS(4));
  845. sq_gpr_resource_mgmt_2 = (R600_NUM_GS_GPRS(0) |
  846. R600_NUM_ES_GPRS(0));
  847. sq_thread_resource_mgmt = (R600_NUM_PS_THREADS(136) |
  848. R600_NUM_VS_THREADS(48) |
  849. R600_NUM_GS_THREADS(4) |
  850. R600_NUM_ES_THREADS(4));
  851. sq_stack_resource_mgmt_1 = (R600_NUM_PS_STACK_ENTRIES(128) |
  852. R600_NUM_VS_STACK_ENTRIES(128));
  853. sq_stack_resource_mgmt_2 = (R600_NUM_GS_STACK_ENTRIES(0) |
  854. R600_NUM_ES_STACK_ENTRIES(0));
  855. } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV610) ||
  856. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV620) ||
  857. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS780) ||
  858. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS880)) {
  859. /* no vertex cache */
  860. sq_config &= ~R600_VC_ENABLE;
  861. sq_gpr_resource_mgmt_1 = (R600_NUM_PS_GPRS(44) |
  862. R600_NUM_VS_GPRS(44) |
  863. R600_NUM_CLAUSE_TEMP_GPRS(2));
  864. sq_gpr_resource_mgmt_2 = (R600_NUM_GS_GPRS(17) |
  865. R600_NUM_ES_GPRS(17));
  866. sq_thread_resource_mgmt = (R600_NUM_PS_THREADS(79) |
  867. R600_NUM_VS_THREADS(78) |
  868. R600_NUM_GS_THREADS(4) |
  869. R600_NUM_ES_THREADS(31));
  870. sq_stack_resource_mgmt_1 = (R600_NUM_PS_STACK_ENTRIES(40) |
  871. R600_NUM_VS_STACK_ENTRIES(40));
  872. sq_stack_resource_mgmt_2 = (R600_NUM_GS_STACK_ENTRIES(32) |
  873. R600_NUM_ES_STACK_ENTRIES(16));
  874. } else if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV630) ||
  875. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV635)) {
  876. sq_gpr_resource_mgmt_1 = (R600_NUM_PS_GPRS(44) |
  877. R600_NUM_VS_GPRS(44) |
  878. R600_NUM_CLAUSE_TEMP_GPRS(2));
  879. sq_gpr_resource_mgmt_2 = (R600_NUM_GS_GPRS(18) |
  880. R600_NUM_ES_GPRS(18));
  881. sq_thread_resource_mgmt = (R600_NUM_PS_THREADS(79) |
  882. R600_NUM_VS_THREADS(78) |
  883. R600_NUM_GS_THREADS(4) |
  884. R600_NUM_ES_THREADS(31));
  885. sq_stack_resource_mgmt_1 = (R600_NUM_PS_STACK_ENTRIES(40) |
  886. R600_NUM_VS_STACK_ENTRIES(40));
  887. sq_stack_resource_mgmt_2 = (R600_NUM_GS_STACK_ENTRIES(32) |
  888. R600_NUM_ES_STACK_ENTRIES(16));
  889. } else if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV670) {
  890. sq_gpr_resource_mgmt_1 = (R600_NUM_PS_GPRS(44) |
  891. R600_NUM_VS_GPRS(44) |
  892. R600_NUM_CLAUSE_TEMP_GPRS(2));
  893. sq_gpr_resource_mgmt_2 = (R600_NUM_GS_GPRS(17) |
  894. R600_NUM_ES_GPRS(17));
  895. sq_thread_resource_mgmt = (R600_NUM_PS_THREADS(79) |
  896. R600_NUM_VS_THREADS(78) |
  897. R600_NUM_GS_THREADS(4) |
  898. R600_NUM_ES_THREADS(31));
  899. sq_stack_resource_mgmt_1 = (R600_NUM_PS_STACK_ENTRIES(64) |
  900. R600_NUM_VS_STACK_ENTRIES(64));
  901. sq_stack_resource_mgmt_2 = (R600_NUM_GS_STACK_ENTRIES(64) |
  902. R600_NUM_ES_STACK_ENTRIES(64));
  903. }
  904. RADEON_WRITE(R600_SQ_CONFIG, sq_config);
  905. RADEON_WRITE(R600_SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
  906. RADEON_WRITE(R600_SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
  907. RADEON_WRITE(R600_SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  908. RADEON_WRITE(R600_SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
  909. RADEON_WRITE(R600_SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
  910. if (((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV610) ||
  911. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV620) ||
  912. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS780) ||
  913. ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RS880))
  914. RADEON_WRITE(R600_VGT_CACHE_INVALIDATION, R600_CACHE_INVALIDATION(R600_TC_ONLY));
  915. else
  916. RADEON_WRITE(R600_VGT_CACHE_INVALIDATION, R600_CACHE_INVALIDATION(R600_VC_AND_TC));
  917. RADEON_WRITE(R600_PA_SC_AA_SAMPLE_LOCS_2S, (R600_S0_X(0xc) |
  918. R600_S0_Y(0x4) |
  919. R600_S1_X(0x4) |
  920. R600_S1_Y(0xc)));
  921. RADEON_WRITE(R600_PA_SC_AA_SAMPLE_LOCS_4S, (R600_S0_X(0xe) |
  922. R600_S0_Y(0xe) |
  923. R600_S1_X(0x2) |
  924. R600_S1_Y(0x2) |
  925. R600_S2_X(0xa) |
  926. R600_S2_Y(0x6) |
  927. R600_S3_X(0x6) |
  928. R600_S3_Y(0xa)));
  929. RADEON_WRITE(R600_PA_SC_AA_SAMPLE_LOCS_8S_WD0, (R600_S0_X(0xe) |
  930. R600_S0_Y(0xb) |
  931. R600_S1_X(0x4) |
  932. R600_S1_Y(0xc) |
  933. R600_S2_X(0x1) |
  934. R600_S2_Y(0x6) |
  935. R600_S3_X(0xa) |
  936. R600_S3_Y(0xe)));
  937. RADEON_WRITE(R600_PA_SC_AA_SAMPLE_LOCS_8S_WD1, (R600_S4_X(0x6) |
  938. R600_S4_Y(0x1) |
  939. R600_S5_X(0x0) |
  940. R600_S5_Y(0x0) |
  941. R600_S6_X(0xb) |
  942. R600_S6_Y(0x4) |
  943. R600_S7_X(0x7) |
  944. R600_S7_Y(0x8)));
  945. switch (dev_priv->flags & RADEON_FAMILY_MASK) {
  946. case CHIP_R600:
  947. case CHIP_RV630:
  948. case CHIP_RV635:
  949. gs_prim_buffer_depth = 0;
  950. break;
  951. case CHIP_RV610:
  952. case CHIP_RS780:
  953. case CHIP_RS880:
  954. case CHIP_RV620:
  955. gs_prim_buffer_depth = 32;
  956. break;
  957. case CHIP_RV670:
  958. gs_prim_buffer_depth = 128;
  959. break;
  960. default:
  961. break;
  962. }
  963. num_gs_verts_per_thread = dev_priv->r600_max_pipes * 16;
  964. vgt_gs_per_es = gs_prim_buffer_depth + num_gs_verts_per_thread;
  965. /* Max value for this is 256 */
  966. if (vgt_gs_per_es > 256)
  967. vgt_gs_per_es = 256;
  968. RADEON_WRITE(R600_VGT_ES_PER_GS, 128);
  969. RADEON_WRITE(R600_VGT_GS_PER_ES, vgt_gs_per_es);
  970. RADEON_WRITE(R600_VGT_GS_PER_VS, 2);
  971. RADEON_WRITE(R600_VGT_GS_VERTEX_REUSE, 16);
  972. /* more default values. 2D/3D driver should adjust as needed */
  973. RADEON_WRITE(R600_PA_SC_LINE_STIPPLE_STATE, 0);
  974. RADEON_WRITE(R600_VGT_STRMOUT_EN, 0);
  975. RADEON_WRITE(R600_SX_MISC, 0);
  976. RADEON_WRITE(R600_PA_SC_MODE_CNTL, 0);
  977. RADEON_WRITE(R600_PA_SC_AA_CONFIG, 0);
  978. RADEON_WRITE(R600_PA_SC_LINE_STIPPLE, 0);
  979. RADEON_WRITE(R600_SPI_INPUT_Z, 0);
  980. RADEON_WRITE(R600_SPI_PS_IN_CONTROL_0, R600_NUM_INTERP(2));
  981. RADEON_WRITE(R600_CB_COLOR7_FRAG, 0);
  982. /* clear render buffer base addresses */
  983. RADEON_WRITE(R600_CB_COLOR0_BASE, 0);
  984. RADEON_WRITE(R600_CB_COLOR1_BASE, 0);
  985. RADEON_WRITE(R600_CB_COLOR2_BASE, 0);
  986. RADEON_WRITE(R600_CB_COLOR3_BASE, 0);
  987. RADEON_WRITE(R600_CB_COLOR4_BASE, 0);
  988. RADEON_WRITE(R600_CB_COLOR5_BASE, 0);
  989. RADEON_WRITE(R600_CB_COLOR6_BASE, 0);
  990. RADEON_WRITE(R600_CB_COLOR7_BASE, 0);
  991. switch (dev_priv->flags & RADEON_FAMILY_MASK) {
  992. case CHIP_RV610:
  993. case CHIP_RS780:
  994. case CHIP_RS880:
  995. case CHIP_RV620:
  996. tc_cntl = R600_TC_L2_SIZE(8);
  997. break;
  998. case CHIP_RV630:
  999. case CHIP_RV635:
  1000. tc_cntl = R600_TC_L2_SIZE(4);
  1001. break;
  1002. case CHIP_R600:
  1003. tc_cntl = R600_TC_L2_SIZE(0) | R600_L2_DISABLE_LATE_HIT;
  1004. break;
  1005. default:
  1006. tc_cntl = R600_TC_L2_SIZE(0);
  1007. break;
  1008. }
  1009. RADEON_WRITE(R600_TC_CNTL, tc_cntl);
  1010. hdp_host_path_cntl = RADEON_READ(R600_HDP_HOST_PATH_CNTL);
  1011. RADEON_WRITE(R600_HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  1012. arb_pop = RADEON_READ(R600_ARB_POP);
  1013. arb_pop |= R600_ENABLE_TC128;
  1014. RADEON_WRITE(R600_ARB_POP, arb_pop);
  1015. RADEON_WRITE(R600_PA_SC_MULTI_CHIP_CNTL, 0);
  1016. RADEON_WRITE(R600_PA_CL_ENHANCE, (R600_CLIP_VTX_REORDER_ENA |
  1017. R600_NUM_CLIP_SEQ(3)));
  1018. RADEON_WRITE(R600_PA_SC_ENHANCE, R600_FORCE_EOV_MAX_CLK_CNT(4095));
  1019. }
  1020. static u32 r700_get_tile_pipe_to_backend_map(drm_radeon_private_t *dev_priv,
  1021. u32 num_tile_pipes,
  1022. u32 num_backends,
  1023. u32 backend_disable_mask)
  1024. {
  1025. u32 backend_map = 0;
  1026. u32 enabled_backends_mask;
  1027. u32 enabled_backends_count;
  1028. u32 cur_pipe;
  1029. u32 swizzle_pipe[R7XX_MAX_PIPES];
  1030. u32 cur_backend;
  1031. u32 i;
  1032. bool force_no_swizzle;
  1033. if (num_tile_pipes > R7XX_MAX_PIPES)
  1034. num_tile_pipes = R7XX_MAX_PIPES;
  1035. if (num_tile_pipes < 1)
  1036. num_tile_pipes = 1;
  1037. if (num_backends > R7XX_MAX_BACKENDS)
  1038. num_backends = R7XX_MAX_BACKENDS;
  1039. if (num_backends < 1)
  1040. num_backends = 1;
  1041. enabled_backends_mask = 0;
  1042. enabled_backends_count = 0;
  1043. for (i = 0; i < R7XX_MAX_BACKENDS; ++i) {
  1044. if (((backend_disable_mask >> i) & 1) == 0) {
  1045. enabled_backends_mask |= (1 << i);
  1046. ++enabled_backends_count;
  1047. }
  1048. if (enabled_backends_count == num_backends)
  1049. break;
  1050. }
  1051. if (enabled_backends_count == 0) {
  1052. enabled_backends_mask = 1;
  1053. enabled_backends_count = 1;
  1054. }
  1055. if (enabled_backends_count != num_backends)
  1056. num_backends = enabled_backends_count;
  1057. switch (dev_priv->flags & RADEON_FAMILY_MASK) {
  1058. case CHIP_RV770:
  1059. case CHIP_RV730:
  1060. force_no_swizzle = false;
  1061. break;
  1062. case CHIP_RV710:
  1063. case CHIP_RV740:
  1064. default:
  1065. force_no_swizzle = true;
  1066. break;
  1067. }
  1068. memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R7XX_MAX_PIPES);
  1069. switch (num_tile_pipes) {
  1070. case 1:
  1071. swizzle_pipe[0] = 0;
  1072. break;
  1073. case 2:
  1074. swizzle_pipe[0] = 0;
  1075. swizzle_pipe[1] = 1;
  1076. break;
  1077. case 3:
  1078. if (force_no_swizzle) {
  1079. swizzle_pipe[0] = 0;
  1080. swizzle_pipe[1] = 1;
  1081. swizzle_pipe[2] = 2;
  1082. } else {
  1083. swizzle_pipe[0] = 0;
  1084. swizzle_pipe[1] = 2;
  1085. swizzle_pipe[2] = 1;
  1086. }
  1087. break;
  1088. case 4:
  1089. if (force_no_swizzle) {
  1090. swizzle_pipe[0] = 0;
  1091. swizzle_pipe[1] = 1;
  1092. swizzle_pipe[2] = 2;
  1093. swizzle_pipe[3] = 3;
  1094. } else {
  1095. swizzle_pipe[0] = 0;
  1096. swizzle_pipe[1] = 2;
  1097. swizzle_pipe[2] = 3;
  1098. swizzle_pipe[3] = 1;
  1099. }
  1100. break;
  1101. case 5:
  1102. if (force_no_swizzle) {
  1103. swizzle_pipe[0] = 0;
  1104. swizzle_pipe[1] = 1;
  1105. swizzle_pipe[2] = 2;
  1106. swizzle_pipe[3] = 3;
  1107. swizzle_pipe[4] = 4;
  1108. } else {
  1109. swizzle_pipe[0] = 0;
  1110. swizzle_pipe[1] = 2;
  1111. swizzle_pipe[2] = 4;
  1112. swizzle_pipe[3] = 1;
  1113. swizzle_pipe[4] = 3;
  1114. }
  1115. break;
  1116. case 6:
  1117. if (force_no_swizzle) {
  1118. swizzle_pipe[0] = 0;
  1119. swizzle_pipe[1] = 1;
  1120. swizzle_pipe[2] = 2;
  1121. swizzle_pipe[3] = 3;
  1122. swizzle_pipe[4] = 4;
  1123. swizzle_pipe[5] = 5;
  1124. } else {
  1125. swizzle_pipe[0] = 0;
  1126. swizzle_pipe[1] = 2;
  1127. swizzle_pipe[2] = 4;
  1128. swizzle_pipe[3] = 5;
  1129. swizzle_pipe[4] = 3;
  1130. swizzle_pipe[5] = 1;
  1131. }
  1132. break;
  1133. case 7:
  1134. if (force_no_swizzle) {
  1135. swizzle_pipe[0] = 0;
  1136. swizzle_pipe[1] = 1;
  1137. swizzle_pipe[2] = 2;
  1138. swizzle_pipe[3] = 3;
  1139. swizzle_pipe[4] = 4;
  1140. swizzle_pipe[5] = 5;
  1141. swizzle_pipe[6] = 6;
  1142. } else {
  1143. swizzle_pipe[0] = 0;
  1144. swizzle_pipe[1] = 2;
  1145. swizzle_pipe[2] = 4;
  1146. swizzle_pipe[3] = 6;
  1147. swizzle_pipe[4] = 3;
  1148. swizzle_pipe[5] = 1;
  1149. swizzle_pipe[6] = 5;
  1150. }
  1151. break;
  1152. case 8:
  1153. if (force_no_swizzle) {
  1154. swizzle_pipe[0] = 0;
  1155. swizzle_pipe[1] = 1;
  1156. swizzle_pipe[2] = 2;
  1157. swizzle_pipe[3] = 3;
  1158. swizzle_pipe[4] = 4;
  1159. swizzle_pipe[5] = 5;
  1160. swizzle_pipe[6] = 6;
  1161. swizzle_pipe[7] = 7;
  1162. } else {
  1163. swizzle_pipe[0] = 0;
  1164. swizzle_pipe[1] = 2;
  1165. swizzle_pipe[2] = 4;
  1166. swizzle_pipe[3] = 6;
  1167. swizzle_pipe[4] = 3;
  1168. swizzle_pipe[5] = 1;
  1169. swizzle_pipe[6] = 7;
  1170. swizzle_pipe[7] = 5;
  1171. }
  1172. break;
  1173. }
  1174. cur_backend = 0;
  1175. for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
  1176. while (((1 << cur_backend) & enabled_backends_mask) == 0)
  1177. cur_backend = (cur_backend + 1) % R7XX_MAX_BACKENDS;
  1178. backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
  1179. cur_backend = (cur_backend + 1) % R7XX_MAX_BACKENDS;
  1180. }
  1181. return backend_map;
  1182. }
  1183. static void r700_gfx_init(struct drm_device *dev,
  1184. drm_radeon_private_t *dev_priv)
  1185. {
  1186. int i, j, num_qd_pipes;
  1187. u32 ta_aux_cntl;
  1188. u32 sx_debug_1;
  1189. u32 smx_dc_ctl0;
  1190. u32 db_debug3;
  1191. u32 num_gs_verts_per_thread;
  1192. u32 vgt_gs_per_es;
  1193. u32 gs_prim_buffer_depth = 0;
  1194. u32 sq_ms_fifo_sizes;
  1195. u32 sq_config;
  1196. u32 sq_thread_resource_mgmt;
  1197. u32 hdp_host_path_cntl;
  1198. u32 sq_dyn_gpr_size_simd_ab_0;
  1199. u32 backend_map;
  1200. u32 gb_tiling_config = 0;
  1201. u32 cc_rb_backend_disable;
  1202. u32 cc_gc_shader_pipe_config;
  1203. u32 mc_arb_ramcfg;
  1204. u32 db_debug4;
  1205. /* setup chip specs */
  1206. switch (dev_priv->flags & RADEON_FAMILY_MASK) {
  1207. case CHIP_RV770:
  1208. dev_priv->r600_max_pipes = 4;
  1209. dev_priv->r600_max_tile_pipes = 8;
  1210. dev_priv->r600_max_simds = 10;
  1211. dev_priv->r600_max_backends = 4;
  1212. dev_priv->r600_max_gprs = 256;
  1213. dev_priv->r600_max_threads = 248;
  1214. dev_priv->r600_max_stack_entries = 512;
  1215. dev_priv->r600_max_hw_contexts = 8;
  1216. dev_priv->r600_max_gs_threads = 16 * 2;
  1217. dev_priv->r600_sx_max_export_size = 128;
  1218. dev_priv->r600_sx_max_export_pos_size = 16;
  1219. dev_priv->r600_sx_max_export_smx_size = 112;
  1220. dev_priv->r600_sq_num_cf_insts = 2;
  1221. dev_priv->r700_sx_num_of_sets = 7;
  1222. dev_priv->r700_sc_prim_fifo_size = 0xF9;
  1223. dev_priv->r700_sc_hiz_tile_fifo_size = 0x30;
  1224. dev_priv->r700_sc_earlyz_tile_fifo_fize = 0x130;
  1225. break;
  1226. case CHIP_RV730:
  1227. dev_priv->r600_max_pipes = 2;
  1228. dev_priv->r600_max_tile_pipes = 4;
  1229. dev_priv->r600_max_simds = 8;
  1230. dev_priv->r600_max_backends = 2;
  1231. dev_priv->r600_max_gprs = 128;
  1232. dev_priv->r600_max_threads = 248;
  1233. dev_priv->r600_max_stack_entries = 256;
  1234. dev_priv->r600_max_hw_contexts = 8;
  1235. dev_priv->r600_max_gs_threads = 16 * 2;
  1236. dev_priv->r600_sx_max_export_size = 256;
  1237. dev_priv->r600_sx_max_export_pos_size = 32;
  1238. dev_priv->r600_sx_max_export_smx_size = 224;
  1239. dev_priv->r600_sq_num_cf_insts = 2;
  1240. dev_priv->r700_sx_num_of_sets = 7;
  1241. dev_priv->r700_sc_prim_fifo_size = 0xf9;
  1242. dev_priv->r700_sc_hiz_tile_fifo_size = 0x30;
  1243. dev_priv->r700_sc_earlyz_tile_fifo_fize = 0x130;
  1244. if (dev_priv->r600_sx_max_export_pos_size > 16) {
  1245. dev_priv->r600_sx_max_export_pos_size -= 16;
  1246. dev_priv->r600_sx_max_export_smx_size += 16;
  1247. }
  1248. break;
  1249. case CHIP_RV710:
  1250. dev_priv->r600_max_pipes = 2;
  1251. dev_priv->r600_max_tile_pipes = 2;
  1252. dev_priv->r600_max_simds = 2;
  1253. dev_priv->r600_max_backends = 1;
  1254. dev_priv->r600_max_gprs = 256;
  1255. dev_priv->r600_max_threads = 192;
  1256. dev_priv->r600_max_stack_entries = 256;
  1257. dev_priv->r600_max_hw_contexts = 4;
  1258. dev_priv->r600_max_gs_threads = 8 * 2;
  1259. dev_priv->r600_sx_max_export_size = 128;
  1260. dev_priv->r600_sx_max_export_pos_size = 16;
  1261. dev_priv->r600_sx_max_export_smx_size = 112;
  1262. dev_priv->r600_sq_num_cf_insts = 1;
  1263. dev_priv->r700_sx_num_of_sets = 7;
  1264. dev_priv->r700_sc_prim_fifo_size = 0x40;
  1265. dev_priv->r700_sc_hiz_tile_fifo_size = 0x30;
  1266. dev_priv->r700_sc_earlyz_tile_fifo_fize = 0x130;
  1267. break;
  1268. case CHIP_RV740:
  1269. dev_priv->r600_max_pipes = 4;
  1270. dev_priv->r600_max_tile_pipes = 4;
  1271. dev_priv->r600_max_simds = 8;
  1272. dev_priv->r600_max_backends = 4;
  1273. dev_priv->r600_max_gprs = 256;
  1274. dev_priv->r600_max_threads = 248;
  1275. dev_priv->r600_max_stack_entries = 512;
  1276. dev_priv->r600_max_hw_contexts = 8;
  1277. dev_priv->r600_max_gs_threads = 16 * 2;
  1278. dev_priv->r600_sx_max_export_size = 256;
  1279. dev_priv->r600_sx_max_export_pos_size = 32;
  1280. dev_priv->r600_sx_max_export_smx_size = 224;
  1281. dev_priv->r600_sq_num_cf_insts = 2;
  1282. dev_priv->r700_sx_num_of_sets = 7;
  1283. dev_priv->r700_sc_prim_fifo_size = 0x100;
  1284. dev_priv->r700_sc_hiz_tile_fifo_size = 0x30;
  1285. dev_priv->r700_sc_earlyz_tile_fifo_fize = 0x130;
  1286. if (dev_priv->r600_sx_max_export_pos_size > 16) {
  1287. dev_priv->r600_sx_max_export_pos_size -= 16;
  1288. dev_priv->r600_sx_max_export_smx_size += 16;
  1289. }
  1290. break;
  1291. default:
  1292. break;
  1293. }
  1294. /* Initialize HDP */
  1295. j = 0;
  1296. for (i = 0; i < 32; i++) {
  1297. RADEON_WRITE((0x2c14 + j), 0x00000000);
  1298. RADEON_WRITE((0x2c18 + j), 0x00000000);
  1299. RADEON_WRITE((0x2c1c + j), 0x00000000);
  1300. RADEON_WRITE((0x2c20 + j), 0x00000000);
  1301. RADEON_WRITE((0x2c24 + j), 0x00000000);
  1302. j += 0x18;
  1303. }
  1304. RADEON_WRITE(R600_GRBM_CNTL, R600_GRBM_READ_TIMEOUT(0xff));
  1305. /* setup tiling, simd, pipe config */
  1306. mc_arb_ramcfg = RADEON_READ(R700_MC_ARB_RAMCFG);
  1307. switch (dev_priv->r600_max_tile_pipes) {
  1308. case 1:
  1309. gb_tiling_config |= R600_PIPE_TILING(0);
  1310. break;
  1311. case 2:
  1312. gb_tiling_config |= R600_PIPE_TILING(1);
  1313. break;
  1314. case 4:
  1315. gb_tiling_config |= R600_PIPE_TILING(2);
  1316. break;
  1317. case 8:
  1318. gb_tiling_config |= R600_PIPE_TILING(3);
  1319. break;
  1320. default:
  1321. break;
  1322. }
  1323. if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV770)
  1324. gb_tiling_config |= R600_BANK_TILING(1);
  1325. else
  1326. gb_tiling_config |= R600_BANK_TILING((mc_arb_ramcfg >> R700_NOOFBANK_SHIFT) & R700_NOOFBANK_MASK);
  1327. gb_tiling_config |= R600_GROUP_SIZE(0);
  1328. if (((mc_arb_ramcfg >> R700_NOOFROWS_SHIFT) & R700_NOOFROWS_MASK) > 3) {
  1329. gb_tiling_config |= R600_ROW_TILING(3);
  1330. gb_tiling_config |= R600_SAMPLE_SPLIT(3);
  1331. } else {
  1332. gb_tiling_config |=
  1333. R600_ROW_TILING(((mc_arb_ramcfg >> R700_NOOFROWS_SHIFT) & R700_NOOFROWS_MASK));
  1334. gb_tiling_config |=
  1335. R600_SAMPLE_SPLIT(((mc_arb_ramcfg >> R700_NOOFROWS_SHIFT) & R700_NOOFROWS_MASK));
  1336. }
  1337. gb_tiling_config |= R600_BANK_SWAPS(1);
  1338. cc_rb_backend_disable = RADEON_READ(R600_CC_RB_BACKEND_DISABLE) & 0x00ff0000;
  1339. cc_rb_backend_disable |=
  1340. R600_BACKEND_DISABLE((R7XX_MAX_BACKENDS_MASK << dev_priv->r600_max_backends) & R7XX_MAX_BACKENDS_MASK);
  1341. cc_gc_shader_pipe_config = RADEON_READ(R600_CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
  1342. cc_gc_shader_pipe_config |=
  1343. R600_INACTIVE_QD_PIPES((R7XX_MAX_PIPES_MASK << dev_priv->r600_max_pipes) & R7XX_MAX_PIPES_MASK);
  1344. cc_gc_shader_pipe_config |=
  1345. R600_INACTIVE_SIMDS((R7XX_MAX_SIMDS_MASK << dev_priv->r600_max_simds) & R7XX_MAX_SIMDS_MASK);
  1346. if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV740)
  1347. backend_map = 0x28;
  1348. else
  1349. backend_map = r700_get_tile_pipe_to_backend_map(dev_priv,
  1350. dev_priv->r600_max_tile_pipes,
  1351. (R7XX_MAX_BACKENDS -
  1352. r600_count_pipe_bits((cc_rb_backend_disable &
  1353. R7XX_MAX_BACKENDS_MASK) >> 16)),
  1354. (cc_rb_backend_disable >> 16));
  1355. gb_tiling_config |= R600_BACKEND_MAP(backend_map);
  1356. RADEON_WRITE(R600_GB_TILING_CONFIG, gb_tiling_config);
  1357. RADEON_WRITE(R600_DCP_TILING_CONFIG, (gb_tiling_config & 0xffff));
  1358. RADEON_WRITE(R600_HDP_TILING_CONFIG, (gb_tiling_config & 0xffff));
  1359. if (gb_tiling_config & 0xc0) {
  1360. dev_priv->r600_group_size = 512;
  1361. } else {
  1362. dev_priv->r600_group_size = 256;
  1363. }
  1364. dev_priv->r600_npipes = 1 << ((gb_tiling_config >> 1) & 0x7);
  1365. if (gb_tiling_config & 0x30) {
  1366. dev_priv->r600_nbanks = 8;
  1367. } else {
  1368. dev_priv->r600_nbanks = 4;
  1369. }
  1370. RADEON_WRITE(R600_CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
  1371. RADEON_WRITE(R600_CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  1372. RADEON_WRITE(R600_GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  1373. RADEON_WRITE(R700_CC_SYS_RB_BACKEND_DISABLE, cc_rb_backend_disable);
  1374. RADEON_WRITE(R700_CGTS_SYS_TCC_DISABLE, 0);
  1375. RADEON_WRITE(R700_CGTS_TCC_DISABLE, 0);
  1376. RADEON_WRITE(R700_CGTS_USER_SYS_TCC_DISABLE, 0);
  1377. RADEON_WRITE(R700_CGTS_USER_TCC_DISABLE, 0);
  1378. num_qd_pipes =
  1379. R7XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & R600_INACTIVE_QD_PIPES_MASK) >> 8);
  1380. RADEON_WRITE(R600_VGT_OUT_DEALLOC_CNTL, (num_qd_pipes * 4) & R600_DEALLOC_DIST_MASK);
  1381. RADEON_WRITE(R600_VGT_VERTEX_REUSE_BLOCK_CNTL, ((num_qd_pipes * 4) - 2) & R600_VTX_REUSE_DEPTH_MASK);
  1382. /* set HW defaults for 3D engine */
  1383. RADEON_WRITE(R600_CP_QUEUE_THRESHOLDS, (R600_ROQ_IB1_START(0x16) |
  1384. R600_ROQ_IB2_START(0x2b)));
  1385. RADEON_WRITE(R600_CP_MEQ_THRESHOLDS, R700_STQ_SPLIT(0x30));
  1386. ta_aux_cntl = RADEON_READ(R600_TA_CNTL_AUX);
  1387. RADEON_WRITE(R600_TA_CNTL_AUX, ta_aux_cntl | R600_DISABLE_CUBE_ANISO);
  1388. sx_debug_1 = RADEON_READ(R700_SX_DEBUG_1);
  1389. sx_debug_1 |= R700_ENABLE_NEW_SMX_ADDRESS;
  1390. RADEON_WRITE(R700_SX_DEBUG_1, sx_debug_1);
  1391. smx_dc_ctl0 = RADEON_READ(R600_SMX_DC_CTL0);
  1392. smx_dc_ctl0 &= ~R700_CACHE_DEPTH(0x1ff);
  1393. smx_dc_ctl0 |= R700_CACHE_DEPTH((dev_priv->r700_sx_num_of_sets * 64) - 1);
  1394. RADEON_WRITE(R600_SMX_DC_CTL0, smx_dc_ctl0);
  1395. if ((dev_priv->flags & RADEON_FAMILY_MASK) != CHIP_RV740)
  1396. RADEON_WRITE(R700_SMX_EVENT_CTL, (R700_ES_FLUSH_CTL(4) |
  1397. R700_GS_FLUSH_CTL(4) |
  1398. R700_ACK_FLUSH_CTL(3) |
  1399. R700_SYNC_FLUSH_CTL));
  1400. db_debug3 = RADEON_READ(R700_DB_DEBUG3);
  1401. db_debug3 &= ~R700_DB_CLK_OFF_DELAY(0x1f);
  1402. switch (dev_priv->flags & RADEON_FAMILY_MASK) {
  1403. case CHIP_RV770:
  1404. case CHIP_RV740:
  1405. db_debug3 |= R700_DB_CLK_OFF_DELAY(0x1f);
  1406. break;
  1407. case CHIP_RV710:
  1408. case CHIP_RV730:
  1409. default:
  1410. db_debug3 |= R700_DB_CLK_OFF_DELAY(2);
  1411. break;
  1412. }
  1413. RADEON_WRITE(R700_DB_DEBUG3, db_debug3);
  1414. if ((dev_priv->flags & RADEON_FAMILY_MASK) != CHIP_RV770) {
  1415. db_debug4 = RADEON_READ(RV700_DB_DEBUG4);
  1416. db_debug4 |= RV700_DISABLE_TILE_COVERED_FOR_PS_ITER;
  1417. RADEON_WRITE(RV700_DB_DEBUG4, db_debug4);
  1418. }
  1419. RADEON_WRITE(R600_SX_EXPORT_BUFFER_SIZES, (R600_COLOR_BUFFER_SIZE((dev_priv->r600_sx_max_export_size / 4) - 1) |
  1420. R600_POSITION_BUFFER_SIZE((dev_priv->r600_sx_max_export_pos_size / 4) - 1) |
  1421. R600_SMX_BUFFER_SIZE((dev_priv->r600_sx_max_export_smx_size / 4) - 1)));
  1422. RADEON_WRITE(R700_PA_SC_FIFO_SIZE_R7XX, (R700_SC_PRIM_FIFO_SIZE(dev_priv->r700_sc_prim_fifo_size) |
  1423. R700_SC_HIZ_TILE_FIFO_SIZE(dev_priv->r700_sc_hiz_tile_fifo_size) |
  1424. R700_SC_EARLYZ_TILE_FIFO_SIZE(dev_priv->r700_sc_earlyz_tile_fifo_fize)));
  1425. RADEON_WRITE(R600_PA_SC_MULTI_CHIP_CNTL, 0);
  1426. RADEON_WRITE(R600_VGT_NUM_INSTANCES, 1);
  1427. RADEON_WRITE(R600_SPI_CONFIG_CNTL, R600_GPR_WRITE_PRIORITY(0));
  1428. RADEON_WRITE(R600_SPI_CONFIG_CNTL_1, R600_VTX_DONE_DELAY(4));
  1429. RADEON_WRITE(R600_CP_PERFMON_CNTL, 0);
  1430. sq_ms_fifo_sizes = (R600_CACHE_FIFO_SIZE(16 * dev_priv->r600_sq_num_cf_insts) |
  1431. R600_DONE_FIFO_HIWATER(0xe0) |
  1432. R600_ALU_UPDATE_FIFO_HIWATER(0x8));
  1433. switch (dev_priv->flags & RADEON_FAMILY_MASK) {
  1434. case CHIP_RV770:
  1435. case CHIP_RV730:
  1436. case CHIP_RV710:
  1437. sq_ms_fifo_sizes |= R600_FETCH_FIFO_HIWATER(0x1);
  1438. break;
  1439. case CHIP_RV740:
  1440. default:
  1441. sq_ms_fifo_sizes |= R600_FETCH_FIFO_HIWATER(0x4);
  1442. break;
  1443. }
  1444. RADEON_WRITE(R600_SQ_MS_FIFO_SIZES, sq_ms_fifo_sizes);
  1445. /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
  1446. * should be adjusted as needed by the 2D/3D drivers. This just sets default values
  1447. */
  1448. sq_config = RADEON_READ(R600_SQ_CONFIG);
  1449. sq_config &= ~(R600_PS_PRIO(3) |
  1450. R600_VS_PRIO(3) |
  1451. R600_GS_PRIO(3) |
  1452. R600_ES_PRIO(3));
  1453. sq_config |= (R600_DX9_CONSTS |
  1454. R600_VC_ENABLE |
  1455. R600_EXPORT_SRC_C |
  1456. R600_PS_PRIO(0) |
  1457. R600_VS_PRIO(1) |
  1458. R600_GS_PRIO(2) |
  1459. R600_ES_PRIO(3));
  1460. if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV710)
  1461. /* no vertex cache */
  1462. sq_config &= ~R600_VC_ENABLE;
  1463. RADEON_WRITE(R600_SQ_CONFIG, sq_config);
  1464. RADEON_WRITE(R600_SQ_GPR_RESOURCE_MGMT_1, (R600_NUM_PS_GPRS((dev_priv->r600_max_gprs * 24)/64) |
  1465. R600_NUM_VS_GPRS((dev_priv->r600_max_gprs * 24)/64) |
  1466. R600_NUM_CLAUSE_TEMP_GPRS(((dev_priv->r600_max_gprs * 24)/64)/2)));
  1467. RADEON_WRITE(R600_SQ_GPR_RESOURCE_MGMT_2, (R600_NUM_GS_GPRS((dev_priv->r600_max_gprs * 7)/64) |
  1468. R600_NUM_ES_GPRS((dev_priv->r600_max_gprs * 7)/64)));
  1469. sq_thread_resource_mgmt = (R600_NUM_PS_THREADS((dev_priv->r600_max_threads * 4)/8) |
  1470. R600_NUM_VS_THREADS((dev_priv->r600_max_threads * 2)/8) |
  1471. R600_NUM_ES_THREADS((dev_priv->r600_max_threads * 1)/8));
  1472. if (((dev_priv->r600_max_threads * 1) / 8) > dev_priv->r600_max_gs_threads)
  1473. sq_thread_resource_mgmt |= R600_NUM_GS_THREADS(dev_priv->r600_max_gs_threads);
  1474. else
  1475. sq_thread_resource_mgmt |= R600_NUM_GS_THREADS((dev_priv->r600_max_gs_threads * 1)/8);
  1476. RADEON_WRITE(R600_SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  1477. RADEON_WRITE(R600_SQ_STACK_RESOURCE_MGMT_1, (R600_NUM_PS_STACK_ENTRIES((dev_priv->r600_max_stack_entries * 1)/4) |
  1478. R600_NUM_VS_STACK_ENTRIES((dev_priv->r600_max_stack_entries * 1)/4)));
  1479. RADEON_WRITE(R600_SQ_STACK_RESOURCE_MGMT_2, (R600_NUM_GS_STACK_ENTRIES((dev_priv->r600_max_stack_entries * 1)/4) |
  1480. R600_NUM_ES_STACK_ENTRIES((dev_priv->r600_max_stack_entries * 1)/4)));
  1481. sq_dyn_gpr_size_simd_ab_0 = (R700_SIMDA_RING0((dev_priv->r600_max_gprs * 38)/64) |
  1482. R700_SIMDA_RING1((dev_priv->r600_max_gprs * 38)/64) |
  1483. R700_SIMDB_RING0((dev_priv->r600_max_gprs * 38)/64) |
  1484. R700_SIMDB_RING1((dev_priv->r600_max_gprs * 38)/64));
  1485. RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_0, sq_dyn_gpr_size_simd_ab_0);
  1486. RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_1, sq_dyn_gpr_size_simd_ab_0);
  1487. RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_2, sq_dyn_gpr_size_simd_ab_0);
  1488. RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_3, sq_dyn_gpr_size_simd_ab_0);
  1489. RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_4, sq_dyn_gpr_size_simd_ab_0);
  1490. RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_5, sq_dyn_gpr_size_simd_ab_0);
  1491. RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_6, sq_dyn_gpr_size_simd_ab_0);
  1492. RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_7, sq_dyn_gpr_size_simd_ab_0);
  1493. RADEON_WRITE(R700_PA_SC_FORCE_EOV_MAX_CNTS, (R700_FORCE_EOV_MAX_CLK_CNT(4095) |
  1494. R700_FORCE_EOV_MAX_REZ_CNT(255)));
  1495. if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV710)
  1496. RADEON_WRITE(R600_VGT_CACHE_INVALIDATION, (R600_CACHE_INVALIDATION(R600_TC_ONLY) |
  1497. R700_AUTO_INVLD_EN(R700_ES_AND_GS_AUTO)));
  1498. else
  1499. RADEON_WRITE(R600_VGT_CACHE_INVALIDATION, (R600_CACHE_INVALIDATION(R600_VC_AND_TC) |
  1500. R700_AUTO_INVLD_EN(R700_ES_AND_GS_AUTO)));
  1501. switch (dev_priv->flags & RADEON_FAMILY_MASK) {
  1502. case CHIP_RV770:
  1503. case CHIP_RV730:
  1504. case CHIP_RV740:
  1505. gs_prim_buffer_depth = 384;
  1506. break;
  1507. case CHIP_RV710:
  1508. gs_prim_buffer_depth = 128;
  1509. break;
  1510. default:
  1511. break;
  1512. }
  1513. num_gs_verts_per_thread = dev_priv->r600_max_pipes * 16;
  1514. vgt_gs_per_es = gs_prim_buffer_depth + num_gs_verts_per_thread;
  1515. /* Max value for this is 256 */
  1516. if (vgt_gs_per_es > 256)
  1517. vgt_gs_per_es = 256;
  1518. RADEON_WRITE(R600_VGT_ES_PER_GS, 128);
  1519. RADEON_WRITE(R600_VGT_GS_PER_ES, vgt_gs_per_es);
  1520. RADEON_WRITE(R600_VGT_GS_PER_VS, 2);
  1521. /* more default values. 2D/3D driver should adjust as needed */
  1522. RADEON_WRITE(R600_VGT_GS_VERTEX_REUSE, 16);
  1523. RADEON_WRITE(R600_PA_SC_LINE_STIPPLE_STATE, 0);
  1524. RADEON_WRITE(R600_VGT_STRMOUT_EN, 0);
  1525. RADEON_WRITE(R600_SX_MISC, 0);
  1526. RADEON_WRITE(R600_PA_SC_MODE_CNTL, 0);
  1527. RADEON_WRITE(R700_PA_SC_EDGERULE, 0xaaaaaaaa);
  1528. RADEON_WRITE(R600_PA_SC_AA_CONFIG, 0);
  1529. RADEON_WRITE(R600_PA_SC_CLIPRECT_RULE, 0xffff);
  1530. RADEON_WRITE(R600_PA_SC_LINE_STIPPLE, 0);
  1531. RADEON_WRITE(R600_SPI_INPUT_Z, 0);
  1532. RADEON_WRITE(R600_SPI_PS_IN_CONTROL_0, R600_NUM_INTERP(2));
  1533. RADEON_WRITE(R600_CB_COLOR7_FRAG, 0);
  1534. /* clear render buffer base addresses */
  1535. RADEON_WRITE(R600_CB_COLOR0_BASE, 0);
  1536. RADEON_WRITE(R600_CB_COLOR1_BASE, 0);
  1537. RADEON_WRITE(R600_CB_COLOR2_BASE, 0);
  1538. RADEON_WRITE(R600_CB_COLOR3_BASE, 0);
  1539. RADEON_WRITE(R600_CB_COLOR4_BASE, 0);
  1540. RADEON_WRITE(R600_CB_COLOR5_BASE, 0);
  1541. RADEON_WRITE(R600_CB_COLOR6_BASE, 0);
  1542. RADEON_WRITE(R600_CB_COLOR7_BASE, 0);
  1543. RADEON_WRITE(R700_TCP_CNTL, 0);
  1544. hdp_host_path_cntl = RADEON_READ(R600_HDP_HOST_PATH_CNTL);
  1545. RADEON_WRITE(R600_HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  1546. RADEON_WRITE(R600_PA_SC_MULTI_CHIP_CNTL, 0);
  1547. RADEON_WRITE(R600_PA_CL_ENHANCE, (R600_CLIP_VTX_REORDER_ENA |
  1548. R600_NUM_CLIP_SEQ(3)));
  1549. }
  1550. static void r600_cp_init_ring_buffer(struct drm_device *dev,
  1551. drm_radeon_private_t *dev_priv,
  1552. struct drm_file *file_priv)
  1553. {
  1554. struct drm_radeon_master_private *master_priv;
  1555. u32 ring_start;
  1556. u64 rptr_addr;
  1557. if (((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770))
  1558. r700_gfx_init(dev, dev_priv);
  1559. else
  1560. r600_gfx_init(dev, dev_priv);
  1561. RADEON_WRITE(R600_GRBM_SOFT_RESET, R600_SOFT_RESET_CP);
  1562. RADEON_READ(R600_GRBM_SOFT_RESET);
  1563. mdelay(15);
  1564. RADEON_WRITE(R600_GRBM_SOFT_RESET, 0);
  1565. /* Set ring buffer size */
  1566. #ifdef __BIG_ENDIAN
  1567. RADEON_WRITE(R600_CP_RB_CNTL,
  1568. R600_BUF_SWAP_32BIT |
  1569. R600_RB_NO_UPDATE |
  1570. (dev_priv->ring.rptr_update_l2qw << 8) |
  1571. dev_priv->ring.size_l2qw);
  1572. #else
  1573. RADEON_WRITE(R600_CP_RB_CNTL,
  1574. RADEON_RB_NO_UPDATE |
  1575. (dev_priv->ring.rptr_update_l2qw << 8) |
  1576. dev_priv->ring.size_l2qw);
  1577. #endif
  1578. RADEON_WRITE(R600_CP_SEM_WAIT_TIMER, 0x0);
  1579. /* Set the write pointer delay */
  1580. RADEON_WRITE(R600_CP_RB_WPTR_DELAY, 0);
  1581. #ifdef __BIG_ENDIAN
  1582. RADEON_WRITE(R600_CP_RB_CNTL,
  1583. R600_BUF_SWAP_32BIT |
  1584. R600_RB_NO_UPDATE |
  1585. R600_RB_RPTR_WR_ENA |
  1586. (dev_priv->ring.rptr_update_l2qw << 8) |
  1587. dev_priv->ring.size_l2qw);
  1588. #else
  1589. RADEON_WRITE(R600_CP_RB_CNTL,
  1590. R600_RB_NO_UPDATE |
  1591. R600_RB_RPTR_WR_ENA |
  1592. (dev_priv->ring.rptr_update_l2qw << 8) |
  1593. dev_priv->ring.size_l2qw);
  1594. #endif
  1595. /* Initialize the ring buffer's read and write pointers */
  1596. RADEON_WRITE(R600_CP_RB_RPTR_WR, 0);
  1597. RADEON_WRITE(R600_CP_RB_WPTR, 0);
  1598. SET_RING_HEAD(dev_priv, 0);
  1599. dev_priv->ring.tail = 0;
  1600. #if IS_ENABLED(CONFIG_AGP)
  1601. if (dev_priv->flags & RADEON_IS_AGP) {
  1602. rptr_addr = dev_priv->ring_rptr->offset
  1603. - dev->agp->base +
  1604. dev_priv->gart_vm_start;
  1605. } else
  1606. #endif
  1607. {
  1608. rptr_addr = dev_priv->ring_rptr->offset
  1609. - ((unsigned long) dev->sg->virtual)
  1610. + dev_priv->gart_vm_start;
  1611. }
  1612. RADEON_WRITE(R600_CP_RB_RPTR_ADDR, (rptr_addr & 0xfffffffc));
  1613. RADEON_WRITE(R600_CP_RB_RPTR_ADDR_HI, upper_32_bits(rptr_addr));
  1614. #ifdef __BIG_ENDIAN
  1615. RADEON_WRITE(R600_CP_RB_CNTL,
  1616. RADEON_BUF_SWAP_32BIT |
  1617. (dev_priv->ring.rptr_update_l2qw << 8) |
  1618. dev_priv->ring.size_l2qw);
  1619. #else
  1620. RADEON_WRITE(R600_CP_RB_CNTL,
  1621. (dev_priv->ring.rptr_update_l2qw << 8) |
  1622. dev_priv->ring.size_l2qw);
  1623. #endif
  1624. #if IS_ENABLED(CONFIG_AGP)
  1625. if (dev_priv->flags & RADEON_IS_AGP) {
  1626. /* XXX */
  1627. radeon_write_agp_base(dev_priv, dev->agp->base);
  1628. /* XXX */
  1629. radeon_write_agp_location(dev_priv,
  1630. (((dev_priv->gart_vm_start - 1 +
  1631. dev_priv->gart_size) & 0xffff0000) |
  1632. (dev_priv->gart_vm_start >> 16)));
  1633. ring_start = (dev_priv->cp_ring->offset
  1634. - dev->agp->base
  1635. + dev_priv->gart_vm_start);
  1636. } else
  1637. #endif
  1638. ring_start = (dev_priv->cp_ring->offset
  1639. - (unsigned long)dev->sg->virtual
  1640. + dev_priv->gart_vm_start);
  1641. RADEON_WRITE(R600_CP_RB_BASE, ring_start >> 8);
  1642. RADEON_WRITE(R600_CP_ME_CNTL, 0xff);
  1643. RADEON_WRITE(R600_CP_DEBUG, (1 << 27) | (1 << 28));
  1644. /* Initialize the scratch register pointer. This will cause
  1645. * the scratch register values to be written out to memory
  1646. * whenever they are updated.
  1647. *
  1648. * We simply put this behind the ring read pointer, this works
  1649. * with PCI GART as well as (whatever kind of) AGP GART
  1650. */
  1651. {
  1652. u64 scratch_addr;
  1653. scratch_addr = RADEON_READ(R600_CP_RB_RPTR_ADDR) & 0xFFFFFFFC;
  1654. scratch_addr |= ((u64)RADEON_READ(R600_CP_RB_RPTR_ADDR_HI)) << 32;
  1655. scratch_addr += R600_SCRATCH_REG_OFFSET;
  1656. scratch_addr >>= 8;
  1657. scratch_addr &= 0xffffffff;
  1658. RADEON_WRITE(R600_SCRATCH_ADDR, (uint32_t)scratch_addr);
  1659. }
  1660. RADEON_WRITE(R600_SCRATCH_UMSK, 0x7);
  1661. /* Turn on bus mastering */
  1662. radeon_enable_bm(dev_priv);
  1663. radeon_write_ring_rptr(dev_priv, R600_SCRATCHOFF(0), 0);
  1664. RADEON_WRITE(R600_LAST_FRAME_REG, 0);
  1665. radeon_write_ring_rptr(dev_priv, R600_SCRATCHOFF(1), 0);
  1666. RADEON_WRITE(R600_LAST_DISPATCH_REG, 0);
  1667. radeon_write_ring_rptr(dev_priv, R600_SCRATCHOFF(2), 0);
  1668. RADEON_WRITE(R600_LAST_CLEAR_REG, 0);
  1669. /* reset sarea copies of these */
  1670. master_priv = file_priv->master->driver_priv;
  1671. if (master_priv->sarea_priv) {
  1672. master_priv->sarea_priv->last_frame = 0;
  1673. master_priv->sarea_priv->last_dispatch = 0;
  1674. master_priv->sarea_priv->last_clear = 0;
  1675. }
  1676. r600_do_wait_for_idle(dev_priv);
  1677. }
  1678. int r600_do_cleanup_cp(struct drm_device *dev)
  1679. {
  1680. drm_radeon_private_t *dev_priv = dev->dev_private;
  1681. DRM_DEBUG("\n");
  1682. /* Make sure interrupts are disabled here because the uninstall ioctl
  1683. * may not have been called from userspace and after dev_private
  1684. * is freed, it's too late.
  1685. */
  1686. if (dev->irq_enabled)
  1687. drm_irq_uninstall(dev);
  1688. #if IS_ENABLED(CONFIG_AGP)
  1689. if (dev_priv->flags & RADEON_IS_AGP) {
  1690. if (dev_priv->cp_ring != NULL) {
  1691. drm_legacy_ioremapfree(dev_priv->cp_ring, dev);
  1692. dev_priv->cp_ring = NULL;
  1693. }
  1694. if (dev_priv->ring_rptr != NULL) {
  1695. drm_legacy_ioremapfree(dev_priv->ring_rptr, dev);
  1696. dev_priv->ring_rptr = NULL;
  1697. }
  1698. if (dev->agp_buffer_map != NULL) {
  1699. drm_legacy_ioremapfree(dev->agp_buffer_map, dev);
  1700. dev->agp_buffer_map = NULL;
  1701. }
  1702. } else
  1703. #endif
  1704. {
  1705. if (dev_priv->gart_info.bus_addr)
  1706. r600_page_table_cleanup(dev, &dev_priv->gart_info);
  1707. if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB) {
  1708. drm_legacy_ioremapfree(&dev_priv->gart_info.mapping, dev);
  1709. dev_priv->gart_info.addr = NULL;
  1710. }
  1711. }
  1712. /* only clear to the start of flags */
  1713. memset(dev_priv, 0, offsetof(drm_radeon_private_t, flags));
  1714. return 0;
  1715. }
  1716. int r600_do_init_cp(struct drm_device *dev, drm_radeon_init_t *init,
  1717. struct drm_file *file_priv)
  1718. {
  1719. drm_radeon_private_t *dev_priv = dev->dev_private;
  1720. struct drm_radeon_master_private *master_priv = file_priv->master->driver_priv;
  1721. DRM_DEBUG("\n");
  1722. mutex_init(&dev_priv->cs_mutex);
  1723. r600_cs_legacy_init();
  1724. /* if we require new memory map but we don't have it fail */
  1725. if ((dev_priv->flags & RADEON_NEW_MEMMAP) && !dev_priv->new_memmap) {
  1726. DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX for 3D\n");
  1727. r600_do_cleanup_cp(dev);
  1728. return -EINVAL;
  1729. }
  1730. if (init->is_pci && (dev_priv->flags & RADEON_IS_AGP)) {
  1731. DRM_DEBUG("Forcing AGP card to PCI mode\n");
  1732. dev_priv->flags &= ~RADEON_IS_AGP;
  1733. /* The writeback test succeeds, but when writeback is enabled,
  1734. * the ring buffer read ptr update fails after first 128 bytes.
  1735. */
  1736. radeon_no_wb = 1;
  1737. } else if (!(dev_priv->flags & (RADEON_IS_AGP | RADEON_IS_PCI | RADEON_IS_PCIE))
  1738. && !init->is_pci) {
  1739. DRM_DEBUG("Restoring AGP flag\n");
  1740. dev_priv->flags |= RADEON_IS_AGP;
  1741. }
  1742. dev_priv->usec_timeout = init->usec_timeout;
  1743. if (dev_priv->usec_timeout < 1 ||
  1744. dev_priv->usec_timeout > RADEON_MAX_USEC_TIMEOUT) {
  1745. DRM_DEBUG("TIMEOUT problem!\n");
  1746. r600_do_cleanup_cp(dev);
  1747. return -EINVAL;
  1748. }
  1749. /* Enable vblank on CRTC1 for older X servers
  1750. */
  1751. dev_priv->vblank_crtc = DRM_RADEON_VBLANK_CRTC1;
  1752. dev_priv->do_boxes = 0;
  1753. dev_priv->cp_mode = init->cp_mode;
  1754. /* We don't support anything other than bus-mastering ring mode,
  1755. * but the ring can be in either AGP or PCI space for the ring
  1756. * read pointer.
  1757. */
  1758. if ((init->cp_mode != RADEON_CSQ_PRIBM_INDDIS) &&
  1759. (init->cp_mode != RADEON_CSQ_PRIBM_INDBM)) {
  1760. DRM_DEBUG("BAD cp_mode (%x)!\n", init->cp_mode);
  1761. r600_do_cleanup_cp(dev);
  1762. return -EINVAL;
  1763. }
  1764. switch (init->fb_bpp) {
  1765. case 16:
  1766. dev_priv->color_fmt = RADEON_COLOR_FORMAT_RGB565;
  1767. break;
  1768. case 32:
  1769. default:
  1770. dev_priv->color_fmt = RADEON_COLOR_FORMAT_ARGB8888;
  1771. break;
  1772. }
  1773. dev_priv->front_offset = init->front_offset;
  1774. dev_priv->front_pitch = init->front_pitch;
  1775. dev_priv->back_offset = init->back_offset;
  1776. dev_priv->back_pitch = init->back_pitch;
  1777. dev_priv->ring_offset = init->ring_offset;
  1778. dev_priv->ring_rptr_offset = init->ring_rptr_offset;
  1779. dev_priv->buffers_offset = init->buffers_offset;
  1780. dev_priv->gart_textures_offset = init->gart_textures_offset;
  1781. master_priv->sarea = drm_legacy_getsarea(dev);
  1782. if (!master_priv->sarea) {
  1783. DRM_ERROR("could not find sarea!\n");
  1784. r600_do_cleanup_cp(dev);
  1785. return -EINVAL;
  1786. }
  1787. dev_priv->cp_ring = drm_legacy_findmap(dev, init->ring_offset);
  1788. if (!dev_priv->cp_ring) {
  1789. DRM_ERROR("could not find cp ring region!\n");
  1790. r600_do_cleanup_cp(dev);
  1791. return -EINVAL;
  1792. }
  1793. dev_priv->ring_rptr = drm_legacy_findmap(dev, init->ring_rptr_offset);
  1794. if (!dev_priv->ring_rptr) {
  1795. DRM_ERROR("could not find ring read pointer!\n");
  1796. r600_do_cleanup_cp(dev);
  1797. return -EINVAL;
  1798. }
  1799. dev->agp_buffer_token = init->buffers_offset;
  1800. dev->agp_buffer_map = drm_legacy_findmap(dev, init->buffers_offset);
  1801. if (!dev->agp_buffer_map) {
  1802. DRM_ERROR("could not find dma buffer region!\n");
  1803. r600_do_cleanup_cp(dev);
  1804. return -EINVAL;
  1805. }
  1806. if (init->gart_textures_offset) {
  1807. dev_priv->gart_textures =
  1808. drm_legacy_findmap(dev, init->gart_textures_offset);
  1809. if (!dev_priv->gart_textures) {
  1810. DRM_ERROR("could not find GART texture region!\n");
  1811. r600_do_cleanup_cp(dev);
  1812. return -EINVAL;
  1813. }
  1814. }
  1815. #if IS_ENABLED(CONFIG_AGP)
  1816. /* XXX */
  1817. if (dev_priv->flags & RADEON_IS_AGP) {
  1818. drm_legacy_ioremap_wc(dev_priv->cp_ring, dev);
  1819. drm_legacy_ioremap_wc(dev_priv->ring_rptr, dev);
  1820. drm_legacy_ioremap_wc(dev->agp_buffer_map, dev);
  1821. if (!dev_priv->cp_ring->handle ||
  1822. !dev_priv->ring_rptr->handle ||
  1823. !dev->agp_buffer_map->handle) {
  1824. DRM_ERROR("could not find ioremap agp regions!\n");
  1825. r600_do_cleanup_cp(dev);
  1826. return -EINVAL;
  1827. }
  1828. } else
  1829. #endif
  1830. {
  1831. dev_priv->cp_ring->handle = (void *)(unsigned long)dev_priv->cp_ring->offset;
  1832. dev_priv->ring_rptr->handle =
  1833. (void *)(unsigned long)dev_priv->ring_rptr->offset;
  1834. dev->agp_buffer_map->handle =
  1835. (void *)(unsigned long)dev->agp_buffer_map->offset;
  1836. DRM_DEBUG("dev_priv->cp_ring->handle %p\n",
  1837. dev_priv->cp_ring->handle);
  1838. DRM_DEBUG("dev_priv->ring_rptr->handle %p\n",
  1839. dev_priv->ring_rptr->handle);
  1840. DRM_DEBUG("dev->agp_buffer_map->handle %p\n",
  1841. dev->agp_buffer_map->handle);
  1842. }
  1843. dev_priv->fb_location = (radeon_read_fb_location(dev_priv) & 0xffff) << 24;
  1844. dev_priv->fb_size =
  1845. (((radeon_read_fb_location(dev_priv) & 0xffff0000u) << 8) + 0x1000000)
  1846. - dev_priv->fb_location;
  1847. dev_priv->front_pitch_offset = (((dev_priv->front_pitch / 64) << 22) |
  1848. ((dev_priv->front_offset
  1849. + dev_priv->fb_location) >> 10));
  1850. dev_priv->back_pitch_offset = (((dev_priv->back_pitch / 64) << 22) |
  1851. ((dev_priv->back_offset
  1852. + dev_priv->fb_location) >> 10));
  1853. dev_priv->depth_pitch_offset = (((dev_priv->depth_pitch / 64) << 22) |
  1854. ((dev_priv->depth_offset
  1855. + dev_priv->fb_location) >> 10));
  1856. dev_priv->gart_size = init->gart_size;
  1857. /* New let's set the memory map ... */
  1858. if (dev_priv->new_memmap) {
  1859. u32 base = 0;
  1860. DRM_INFO("Setting GART location based on new memory map\n");
  1861. /* If using AGP, try to locate the AGP aperture at the same
  1862. * location in the card and on the bus, though we have to
  1863. * align it down.
  1864. */
  1865. #if IS_ENABLED(CONFIG_AGP)
  1866. /* XXX */
  1867. if (dev_priv->flags & RADEON_IS_AGP) {
  1868. base = dev->agp->base;
  1869. /* Check if valid */
  1870. if ((base + dev_priv->gart_size - 1) >= dev_priv->fb_location &&
  1871. base < (dev_priv->fb_location + dev_priv->fb_size - 1)) {
  1872. DRM_INFO("Can't use AGP base @0x%08lx, won't fit\n",
  1873. dev->agp->base);
  1874. base = 0;
  1875. }
  1876. }
  1877. #endif
  1878. /* If not or if AGP is at 0 (Macs), try to put it elsewhere */
  1879. if (base == 0) {
  1880. base = dev_priv->fb_location + dev_priv->fb_size;
  1881. if (base < dev_priv->fb_location ||
  1882. ((base + dev_priv->gart_size) & 0xfffffffful) < base)
  1883. base = dev_priv->fb_location
  1884. - dev_priv->gart_size;
  1885. }
  1886. dev_priv->gart_vm_start = base & 0xffc00000u;
  1887. if (dev_priv->gart_vm_start != base)
  1888. DRM_INFO("GART aligned down from 0x%08x to 0x%08x\n",
  1889. base, dev_priv->gart_vm_start);
  1890. }
  1891. #if IS_ENABLED(CONFIG_AGP)
  1892. /* XXX */
  1893. if (dev_priv->flags & RADEON_IS_AGP)
  1894. dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
  1895. - dev->agp->base
  1896. + dev_priv->gart_vm_start);
  1897. else
  1898. #endif
  1899. dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
  1900. - (unsigned long)dev->sg->virtual
  1901. + dev_priv->gart_vm_start);
  1902. DRM_DEBUG("fb 0x%08x size %d\n",
  1903. (unsigned int) dev_priv->fb_location,
  1904. (unsigned int) dev_priv->fb_size);
  1905. DRM_DEBUG("dev_priv->gart_size %d\n", dev_priv->gart_size);
  1906. DRM_DEBUG("dev_priv->gart_vm_start 0x%08x\n",
  1907. (unsigned int) dev_priv->gart_vm_start);
  1908. DRM_DEBUG("dev_priv->gart_buffers_offset 0x%08lx\n",
  1909. dev_priv->gart_buffers_offset);
  1910. dev_priv->ring.start = (u32 *) dev_priv->cp_ring->handle;
  1911. dev_priv->ring.end = ((u32 *) dev_priv->cp_ring->handle
  1912. + init->ring_size / sizeof(u32));
  1913. dev_priv->ring.size = init->ring_size;
  1914. dev_priv->ring.size_l2qw = order_base_2(init->ring_size / 8);
  1915. dev_priv->ring.rptr_update = /* init->rptr_update */ 4096;
  1916. dev_priv->ring.rptr_update_l2qw = order_base_2(/* init->rptr_update */ 4096 / 8);
  1917. dev_priv->ring.fetch_size = /* init->fetch_size */ 32;
  1918. dev_priv->ring.fetch_size_l2ow = order_base_2(/* init->fetch_size */ 32 / 16);
  1919. dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1;
  1920. dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK;
  1921. #if IS_ENABLED(CONFIG_AGP)
  1922. if (dev_priv->flags & RADEON_IS_AGP) {
  1923. /* XXX turn off pcie gart */
  1924. } else
  1925. #endif
  1926. {
  1927. dev_priv->gart_info.table_mask = DMA_BIT_MASK(32);
  1928. /* if we have an offset set from userspace */
  1929. if (!dev_priv->pcigart_offset_set) {
  1930. DRM_ERROR("Need gart offset from userspace\n");
  1931. r600_do_cleanup_cp(dev);
  1932. return -EINVAL;
  1933. }
  1934. DRM_DEBUG("Using gart offset 0x%08lx\n", dev_priv->pcigart_offset);
  1935. dev_priv->gart_info.bus_addr =
  1936. dev_priv->pcigart_offset + dev_priv->fb_location;
  1937. dev_priv->gart_info.mapping.offset =
  1938. dev_priv->pcigart_offset + dev_priv->fb_aper_offset;
  1939. dev_priv->gart_info.mapping.size =
  1940. dev_priv->gart_info.table_size;
  1941. drm_legacy_ioremap_wc(&dev_priv->gart_info.mapping, dev);
  1942. if (!dev_priv->gart_info.mapping.handle) {
  1943. DRM_ERROR("ioremap failed.\n");
  1944. r600_do_cleanup_cp(dev);
  1945. return -EINVAL;
  1946. }
  1947. dev_priv->gart_info.addr =
  1948. dev_priv->gart_info.mapping.handle;
  1949. DRM_DEBUG("Setting phys_pci_gart to %p %08lX\n",
  1950. dev_priv->gart_info.addr,
  1951. dev_priv->pcigart_offset);
  1952. if (!r600_page_table_init(dev)) {
  1953. DRM_ERROR("Failed to init GART table\n");
  1954. r600_do_cleanup_cp(dev);
  1955. return -EINVAL;
  1956. }
  1957. if (((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770))
  1958. r700_vm_init(dev);
  1959. else
  1960. r600_vm_init(dev);
  1961. }
  1962. if (!dev_priv->me_fw || !dev_priv->pfp_fw) {
  1963. int err = r600_cp_init_microcode(dev_priv);
  1964. if (err) {
  1965. DRM_ERROR("Failed to load firmware!\n");
  1966. r600_do_cleanup_cp(dev);
  1967. return err;
  1968. }
  1969. }
  1970. if (((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770))
  1971. r700_cp_load_microcode(dev_priv);
  1972. else
  1973. r600_cp_load_microcode(dev_priv);
  1974. r600_cp_init_ring_buffer(dev, dev_priv, file_priv);
  1975. dev_priv->last_buf = 0;
  1976. r600_do_engine_reset(dev);
  1977. r600_test_writeback(dev_priv);
  1978. return 0;
  1979. }
  1980. int r600_do_resume_cp(struct drm_device *dev, struct drm_file *file_priv)
  1981. {
  1982. drm_radeon_private_t *dev_priv = dev->dev_private;
  1983. DRM_DEBUG("\n");
  1984. if (((dev_priv->flags & RADEON_FAMILY_MASK) >= CHIP_RV770)) {
  1985. r700_vm_init(dev);
  1986. r700_cp_load_microcode(dev_priv);
  1987. } else {
  1988. r600_vm_init(dev);
  1989. r600_cp_load_microcode(dev_priv);
  1990. }
  1991. r600_cp_init_ring_buffer(dev, dev_priv, file_priv);
  1992. r600_do_engine_reset(dev);
  1993. return 0;
  1994. }
  1995. /* Wait for the CP to go idle.
  1996. */
  1997. int r600_do_cp_idle(drm_radeon_private_t *dev_priv)
  1998. {
  1999. RING_LOCALS;
  2000. DRM_DEBUG("\n");
  2001. BEGIN_RING(5);
  2002. OUT_RING(CP_PACKET3(R600_IT_EVENT_WRITE, 0));
  2003. OUT_RING(R600_CACHE_FLUSH_AND_INV_EVENT);
  2004. /* wait for 3D idle clean */
  2005. OUT_RING(CP_PACKET3(R600_IT_SET_CONFIG_REG, 1));
  2006. OUT_RING((R600_WAIT_UNTIL - R600_SET_CONFIG_REG_OFFSET) >> 2);
  2007. OUT_RING(RADEON_WAIT_3D_IDLE | RADEON_WAIT_3D_IDLECLEAN);
  2008. ADVANCE_RING();
  2009. COMMIT_RING();
  2010. return r600_do_wait_for_idle(dev_priv);
  2011. }
  2012. /* Start the Command Processor.
  2013. */
  2014. void r600_do_cp_start(drm_radeon_private_t *dev_priv)
  2015. {
  2016. u32 cp_me;
  2017. RING_LOCALS;
  2018. DRM_DEBUG("\n");
  2019. BEGIN_RING(7);
  2020. OUT_RING(CP_PACKET3(R600_IT_ME_INITIALIZE, 5));
  2021. OUT_RING(0x00000001);
  2022. if (((dev_priv->flags & RADEON_FAMILY_MASK) < CHIP_RV770))
  2023. OUT_RING(0x00000003);
  2024. else
  2025. OUT_RING(0x00000000);
  2026. OUT_RING((dev_priv->r600_max_hw_contexts - 1));
  2027. OUT_RING(R600_ME_INITIALIZE_DEVICE_ID(1));
  2028. OUT_RING(0x00000000);
  2029. OUT_RING(0x00000000);
  2030. ADVANCE_RING();
  2031. COMMIT_RING();
  2032. /* set the mux and reset the halt bit */
  2033. cp_me = 0xff;
  2034. RADEON_WRITE(R600_CP_ME_CNTL, cp_me);
  2035. dev_priv->cp_running = 1;
  2036. }
  2037. void r600_do_cp_reset(drm_radeon_private_t *dev_priv)
  2038. {
  2039. u32 cur_read_ptr;
  2040. DRM_DEBUG("\n");
  2041. cur_read_ptr = RADEON_READ(R600_CP_RB_RPTR);
  2042. RADEON_WRITE(R600_CP_RB_WPTR, cur_read_ptr);
  2043. SET_RING_HEAD(dev_priv, cur_read_ptr);
  2044. dev_priv->ring.tail = cur_read_ptr;
  2045. }
  2046. void r600_do_cp_stop(drm_radeon_private_t *dev_priv)
  2047. {
  2048. uint32_t cp_me;
  2049. DRM_DEBUG("\n");
  2050. cp_me = 0xff | R600_CP_ME_HALT;
  2051. RADEON_WRITE(R600_CP_ME_CNTL, cp_me);
  2052. dev_priv->cp_running = 0;
  2053. }
  2054. int r600_cp_dispatch_indirect(struct drm_device *dev,
  2055. struct drm_buf *buf, int start, int end)
  2056. {
  2057. drm_radeon_private_t *dev_priv = dev->dev_private;
  2058. RING_LOCALS;
  2059. if (start != end) {
  2060. unsigned long offset = (dev_priv->gart_buffers_offset
  2061. + buf->offset + start);
  2062. int dwords = (end - start + 3) / sizeof(u32);
  2063. DRM_DEBUG("dwords:%d\n", dwords);
  2064. DRM_DEBUG("offset 0x%lx\n", offset);
  2065. /* Indirect buffer data must be a multiple of 16 dwords.
  2066. * pad the data with a Type-2 CP packet.
  2067. */
  2068. while (dwords & 0xf) {
  2069. u32 *data = (u32 *)
  2070. ((char *)dev->agp_buffer_map->handle
  2071. + buf->offset + start);
  2072. data[dwords++] = RADEON_CP_PACKET2;
  2073. }
  2074. /* Fire off the indirect buffer */
  2075. BEGIN_RING(4);
  2076. OUT_RING(CP_PACKET3(R600_IT_INDIRECT_BUFFER, 2));
  2077. OUT_RING((offset & 0xfffffffc));
  2078. OUT_RING((upper_32_bits(offset) & 0xff));
  2079. OUT_RING(dwords);
  2080. ADVANCE_RING();
  2081. }
  2082. return 0;
  2083. }
  2084. void r600_cp_dispatch_swap(struct drm_device *dev, struct drm_file *file_priv)
  2085. {
  2086. drm_radeon_private_t *dev_priv = dev->dev_private;
  2087. struct drm_master *master = file_priv->master;
  2088. struct drm_radeon_master_private *master_priv = master->driver_priv;
  2089. drm_radeon_sarea_t *sarea_priv = master_priv->sarea_priv;
  2090. int nbox = sarea_priv->nbox;
  2091. struct drm_clip_rect *pbox = sarea_priv->boxes;
  2092. int i, cpp, src_pitch, dst_pitch;
  2093. uint64_t src, dst;
  2094. RING_LOCALS;
  2095. DRM_DEBUG("\n");
  2096. if (dev_priv->color_fmt == RADEON_COLOR_FORMAT_ARGB8888)
  2097. cpp = 4;
  2098. else
  2099. cpp = 2;
  2100. if (sarea_priv->pfCurrentPage == 0) {
  2101. src_pitch = dev_priv->back_pitch;
  2102. dst_pitch = dev_priv->front_pitch;
  2103. src = dev_priv->back_offset + dev_priv->fb_location;
  2104. dst = dev_priv->front_offset + dev_priv->fb_location;
  2105. } else {
  2106. src_pitch = dev_priv->front_pitch;
  2107. dst_pitch = dev_priv->back_pitch;
  2108. src = dev_priv->front_offset + dev_priv->fb_location;
  2109. dst = dev_priv->back_offset + dev_priv->fb_location;
  2110. }
  2111. if (r600_prepare_blit_copy(dev, file_priv)) {
  2112. DRM_ERROR("unable to allocate vertex buffer for swap buffer\n");
  2113. return;
  2114. }
  2115. for (i = 0; i < nbox; i++) {
  2116. int x = pbox[i].x1;
  2117. int y = pbox[i].y1;
  2118. int w = pbox[i].x2 - x;
  2119. int h = pbox[i].y2 - y;
  2120. DRM_DEBUG("%d,%d-%d,%d\n", x, y, w, h);
  2121. r600_blit_swap(dev,
  2122. src, dst,
  2123. x, y, x, y, w, h,
  2124. src_pitch, dst_pitch, cpp);
  2125. }
  2126. r600_done_blit_copy(dev);
  2127. /* Increment the frame counter. The client-side 3D driver must
  2128. * throttle the framerate by waiting for this value before
  2129. * performing the swapbuffer ioctl.
  2130. */
  2131. sarea_priv->last_frame++;
  2132. BEGIN_RING(3);
  2133. R600_FRAME_AGE(sarea_priv->last_frame);
  2134. ADVANCE_RING();
  2135. }
  2136. int r600_cp_dispatch_texture(struct drm_device *dev,
  2137. struct drm_file *file_priv,
  2138. drm_radeon_texture_t *tex,
  2139. drm_radeon_tex_image_t *image)
  2140. {
  2141. drm_radeon_private_t *dev_priv = dev->dev_private;
  2142. struct drm_buf *buf;
  2143. u32 *buffer;
  2144. const u8 __user *data;
  2145. unsigned int size, pass_size;
  2146. u64 src_offset, dst_offset;
  2147. if (!radeon_check_offset(dev_priv, tex->offset)) {
  2148. DRM_ERROR("Invalid destination offset\n");
  2149. return -EINVAL;
  2150. }
  2151. /* this might fail for zero-sized uploads - are those illegal? */
  2152. if (!radeon_check_offset(dev_priv, tex->offset + tex->height * tex->pitch - 1)) {
  2153. DRM_ERROR("Invalid final destination offset\n");
  2154. return -EINVAL;
  2155. }
  2156. size = tex->height * tex->pitch;
  2157. if (size == 0)
  2158. return 0;
  2159. dst_offset = tex->offset;
  2160. if (r600_prepare_blit_copy(dev, file_priv)) {
  2161. DRM_ERROR("unable to allocate vertex buffer for swap buffer\n");
  2162. return -EAGAIN;
  2163. }
  2164. do {
  2165. data = (const u8 __user *)image->data;
  2166. pass_size = size;
  2167. buf = radeon_freelist_get(dev);
  2168. if (!buf) {
  2169. DRM_DEBUG("EAGAIN\n");
  2170. if (copy_to_user(tex->image, image, sizeof(*image)))
  2171. return -EFAULT;
  2172. return -EAGAIN;
  2173. }
  2174. if (pass_size > buf->total)
  2175. pass_size = buf->total;
  2176. /* Dispatch the indirect buffer.
  2177. */
  2178. buffer =
  2179. (u32 *) ((char *)dev->agp_buffer_map->handle + buf->offset);
  2180. if (copy_from_user(buffer, data, pass_size)) {
  2181. DRM_ERROR("EFAULT on pad, %d bytes\n", pass_size);
  2182. return -EFAULT;
  2183. }
  2184. buf->file_priv = file_priv;
  2185. buf->used = pass_size;
  2186. src_offset = dev_priv->gart_buffers_offset + buf->offset;
  2187. r600_blit_copy(dev, src_offset, dst_offset, pass_size);
  2188. radeon_cp_discard_buffer(dev, file_priv->master, buf);
  2189. /* Update the input parameters for next time */
  2190. image->data = (const u8 __user *)image->data + pass_size;
  2191. dst_offset += pass_size;
  2192. size -= pass_size;
  2193. } while (size > 0);
  2194. r600_done_blit_copy(dev);
  2195. return 0;
  2196. }
  2197. /*
  2198. * Legacy cs ioctl
  2199. */
  2200. static u32 radeon_cs_id_get(struct drm_radeon_private *radeon)
  2201. {
  2202. /* FIXME: check if wrap affect last reported wrap & sequence */
  2203. radeon->cs_id_scnt = (radeon->cs_id_scnt + 1) & 0x00FFFFFF;
  2204. if (!radeon->cs_id_scnt) {
  2205. /* increment wrap counter */
  2206. radeon->cs_id_wcnt += 0x01000000;
  2207. /* valid sequence counter start at 1 */
  2208. radeon->cs_id_scnt = 1;
  2209. }
  2210. return (radeon->cs_id_scnt | radeon->cs_id_wcnt);
  2211. }
  2212. static void r600_cs_id_emit(drm_radeon_private_t *dev_priv, u32 *id)
  2213. {
  2214. RING_LOCALS;
  2215. *id = radeon_cs_id_get(dev_priv);
  2216. /* SCRATCH 2 */
  2217. BEGIN_RING(3);
  2218. R600_CLEAR_AGE(*id);
  2219. ADVANCE_RING();
  2220. COMMIT_RING();
  2221. }
  2222. static int r600_ib_get(struct drm_device *dev,
  2223. struct drm_file *fpriv,
  2224. struct drm_buf **buffer)
  2225. {
  2226. struct drm_buf *buf;
  2227. *buffer = NULL;
  2228. buf = radeon_freelist_get(dev);
  2229. if (!buf) {
  2230. return -EBUSY;
  2231. }
  2232. buf->file_priv = fpriv;
  2233. *buffer = buf;
  2234. return 0;
  2235. }
  2236. static void r600_ib_free(struct drm_device *dev, struct drm_buf *buf,
  2237. struct drm_file *fpriv, int l, int r)
  2238. {
  2239. drm_radeon_private_t *dev_priv = dev->dev_private;
  2240. if (buf) {
  2241. if (!r)
  2242. r600_cp_dispatch_indirect(dev, buf, 0, l * 4);
  2243. radeon_cp_discard_buffer(dev, fpriv->master, buf);
  2244. COMMIT_RING();
  2245. }
  2246. }
  2247. int r600_cs_legacy_ioctl(struct drm_device *dev, void *data, struct drm_file *fpriv)
  2248. {
  2249. struct drm_radeon_private *dev_priv = dev->dev_private;
  2250. struct drm_radeon_cs *cs = data;
  2251. struct drm_buf *buf;
  2252. unsigned family;
  2253. int l, r = 0;
  2254. u32 *ib, cs_id = 0;
  2255. if (dev_priv == NULL) {
  2256. DRM_ERROR("called with no initialization\n");
  2257. return -EINVAL;
  2258. }
  2259. family = dev_priv->flags & RADEON_FAMILY_MASK;
  2260. if (family < CHIP_R600) {
  2261. DRM_ERROR("cs ioctl valid only for R6XX & R7XX in legacy mode\n");
  2262. return -EINVAL;
  2263. }
  2264. mutex_lock(&dev_priv->cs_mutex);
  2265. /* get ib */
  2266. r = r600_ib_get(dev, fpriv, &buf);
  2267. if (r) {
  2268. DRM_ERROR("ib_get failed\n");
  2269. goto out;
  2270. }
  2271. ib = dev->agp_buffer_map->handle + buf->offset;
  2272. /* now parse command stream */
  2273. r = r600_cs_legacy(dev, data, fpriv, family, ib, &l);
  2274. if (r) {
  2275. goto out;
  2276. }
  2277. out:
  2278. r600_ib_free(dev, buf, fpriv, l, r);
  2279. /* emit cs id sequence */
  2280. r600_cs_id_emit(dev_priv, &cs_id);
  2281. cs->cs_id = cs_id;
  2282. mutex_unlock(&dev_priv->cs_mutex);
  2283. return r;
  2284. }
  2285. void r600_cs_legacy_get_tiling_conf(struct drm_device *dev, u32 *npipes, u32 *nbanks, u32 *group_size)
  2286. {
  2287. struct drm_radeon_private *dev_priv = dev->dev_private;
  2288. *npipes = dev_priv->r600_npipes;
  2289. *nbanks = dev_priv->r600_nbanks;
  2290. *group_size = dev_priv->r600_group_size;
  2291. }