radeon.h 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #ifndef __RADEON_H__
  29. #define __RADEON_H__
  30. /* TODO: Here are things that needs to be done :
  31. * - surface allocator & initializer : (bit like scratch reg) should
  32. * initialize HDP_ stuff on RS600, R600, R700 hw, well anythings
  33. * related to surface
  34. * - WB : write back stuff (do it bit like scratch reg things)
  35. * - Vblank : look at Jesse's rework and what we should do
  36. * - r600/r700: gart & cp
  37. * - cs : clean cs ioctl use bitmap & things like that.
  38. * - power management stuff
  39. * - Barrier in gart code
  40. * - Unmappabled vram ?
  41. * - TESTING, TESTING, TESTING
  42. */
  43. /* Initialization path:
  44. * We expect that acceleration initialization might fail for various
  45. * reasons even thought we work hard to make it works on most
  46. * configurations. In order to still have a working userspace in such
  47. * situation the init path must succeed up to the memory controller
  48. * initialization point. Failure before this point are considered as
  49. * fatal error. Here is the init callchain :
  50. * radeon_device_init perform common structure, mutex initialization
  51. * asic_init setup the GPU memory layout and perform all
  52. * one time initialization (failure in this
  53. * function are considered fatal)
  54. * asic_startup setup the GPU acceleration, in order to
  55. * follow guideline the first thing this
  56. * function should do is setting the GPU
  57. * memory controller (only MC setup failure
  58. * are considered as fatal)
  59. */
  60. #include <linux/atomic.h>
  61. #include <linux/wait.h>
  62. #include <linux/list.h>
  63. #include <linux/kref.h>
  64. #include <ttm/ttm_bo_api.h>
  65. #include <ttm/ttm_bo_driver.h>
  66. #include <ttm/ttm_placement.h>
  67. #include <ttm/ttm_module.h>
  68. #include <ttm/ttm_execbuf_util.h>
  69. #include "radeon_family.h"
  70. #include "radeon_mode.h"
  71. #include "radeon_reg.h"
  72. /*
  73. * Modules parameters.
  74. */
  75. extern int radeon_no_wb;
  76. extern int radeon_modeset;
  77. extern int radeon_dynclks;
  78. extern int radeon_r4xx_atom;
  79. extern int radeon_agpmode;
  80. extern int radeon_vram_limit;
  81. extern int radeon_gart_size;
  82. extern int radeon_benchmarking;
  83. extern int radeon_testing;
  84. extern int radeon_connector_table;
  85. extern int radeon_tv;
  86. extern int radeon_audio;
  87. extern int radeon_disp_priority;
  88. extern int radeon_hw_i2c;
  89. extern int radeon_pcie_gen2;
  90. extern int radeon_msi;
  91. extern int radeon_lockup_timeout;
  92. extern int radeon_fastfb;
  93. extern int radeon_dpm;
  94. extern int radeon_aspm;
  95. /*
  96. * Copy from radeon_drv.h so we don't have to include both and have conflicting
  97. * symbol;
  98. */
  99. #define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  100. #define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  101. /* RADEON_IB_POOL_SIZE must be a power of 2 */
  102. #define RADEON_IB_POOL_SIZE 16
  103. #define RADEON_DEBUGFS_MAX_COMPONENTS 32
  104. #define RADEONFB_CONN_LIMIT 4
  105. #define RADEON_BIOS_NUM_SCRATCH 8
  106. /* max number of rings */
  107. #define RADEON_NUM_RINGS 6
  108. /* fence seq are set to this number when signaled */
  109. #define RADEON_FENCE_SIGNALED_SEQ 0LL
  110. /* internal ring indices */
  111. /* r1xx+ has gfx CP ring */
  112. #define RADEON_RING_TYPE_GFX_INDEX 0
  113. /* cayman has 2 compute CP rings */
  114. #define CAYMAN_RING_TYPE_CP1_INDEX 1
  115. #define CAYMAN_RING_TYPE_CP2_INDEX 2
  116. /* R600+ has an async dma ring */
  117. #define R600_RING_TYPE_DMA_INDEX 3
  118. /* cayman add a second async dma ring */
  119. #define CAYMAN_RING_TYPE_DMA1_INDEX 4
  120. /* R600+ */
  121. #define R600_RING_TYPE_UVD_INDEX 5
  122. /* hardcode those limit for now */
  123. #define RADEON_VA_IB_OFFSET (1 << 20)
  124. #define RADEON_VA_RESERVED_SIZE (8 << 20)
  125. #define RADEON_IB_VM_MAX_SIZE (64 << 10)
  126. /* reset flags */
  127. #define RADEON_RESET_GFX (1 << 0)
  128. #define RADEON_RESET_COMPUTE (1 << 1)
  129. #define RADEON_RESET_DMA (1 << 2)
  130. #define RADEON_RESET_CP (1 << 3)
  131. #define RADEON_RESET_GRBM (1 << 4)
  132. #define RADEON_RESET_DMA1 (1 << 5)
  133. #define RADEON_RESET_RLC (1 << 6)
  134. #define RADEON_RESET_SEM (1 << 7)
  135. #define RADEON_RESET_IH (1 << 8)
  136. #define RADEON_RESET_VMC (1 << 9)
  137. #define RADEON_RESET_MC (1 << 10)
  138. #define RADEON_RESET_DISPLAY (1 << 11)
  139. /* CG block flags */
  140. #define RADEON_CG_BLOCK_GFX (1 << 0)
  141. #define RADEON_CG_BLOCK_MC (1 << 1)
  142. #define RADEON_CG_BLOCK_SDMA (1 << 2)
  143. #define RADEON_CG_BLOCK_UVD (1 << 3)
  144. #define RADEON_CG_BLOCK_VCE (1 << 4)
  145. #define RADEON_CG_BLOCK_HDP (1 << 5)
  146. #define RADEON_CG_BLOCK_BIF (1 << 6)
  147. /* CG flags */
  148. #define RADEON_CG_SUPPORT_GFX_MGCG (1 << 0)
  149. #define RADEON_CG_SUPPORT_GFX_MGLS (1 << 1)
  150. #define RADEON_CG_SUPPORT_GFX_CGCG (1 << 2)
  151. #define RADEON_CG_SUPPORT_GFX_CGLS (1 << 3)
  152. #define RADEON_CG_SUPPORT_GFX_CGTS (1 << 4)
  153. #define RADEON_CG_SUPPORT_GFX_CGTS_LS (1 << 5)
  154. #define RADEON_CG_SUPPORT_GFX_CP_LS (1 << 6)
  155. #define RADEON_CG_SUPPORT_GFX_RLC_LS (1 << 7)
  156. #define RADEON_CG_SUPPORT_MC_LS (1 << 8)
  157. #define RADEON_CG_SUPPORT_MC_MGCG (1 << 9)
  158. #define RADEON_CG_SUPPORT_SDMA_LS (1 << 10)
  159. #define RADEON_CG_SUPPORT_SDMA_MGCG (1 << 11)
  160. #define RADEON_CG_SUPPORT_BIF_LS (1 << 12)
  161. #define RADEON_CG_SUPPORT_UVD_MGCG (1 << 13)
  162. #define RADEON_CG_SUPPORT_VCE_MGCG (1 << 14)
  163. #define RADEON_CG_SUPPORT_HDP_LS (1 << 15)
  164. #define RADEON_CG_SUPPORT_HDP_MGCG (1 << 16)
  165. /* PG flags */
  166. #define RADEON_PG_SUPPORT_GFX_CG (1 << 0)
  167. #define RADEON_PG_SUPPORT_GFX_SMG (1 << 1)
  168. #define RADEON_PG_SUPPORT_GFX_DMG (1 << 2)
  169. #define RADEON_PG_SUPPORT_UVD (1 << 3)
  170. #define RADEON_PG_SUPPORT_VCE (1 << 4)
  171. #define RADEON_PG_SUPPORT_CP (1 << 5)
  172. #define RADEON_PG_SUPPORT_GDS (1 << 6)
  173. #define RADEON_PG_SUPPORT_RLC_SMU_HS (1 << 7)
  174. #define RADEON_PG_SUPPORT_SDMA (1 << 8)
  175. #define RADEON_PG_SUPPORT_ACP (1 << 9)
  176. #define RADEON_PG_SUPPORT_SAMU (1 << 10)
  177. /* max cursor sizes (in pixels) */
  178. #define CURSOR_WIDTH 64
  179. #define CURSOR_HEIGHT 64
  180. #define CIK_CURSOR_WIDTH 128
  181. #define CIK_CURSOR_HEIGHT 128
  182. /*
  183. * Errata workarounds.
  184. */
  185. enum radeon_pll_errata {
  186. CHIP_ERRATA_R300_CG = 0x00000001,
  187. CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
  188. CHIP_ERRATA_PLL_DELAY = 0x00000004
  189. };
  190. struct radeon_device;
  191. /*
  192. * BIOS.
  193. */
  194. bool radeon_get_bios(struct radeon_device *rdev);
  195. /*
  196. * Dummy page
  197. */
  198. struct radeon_dummy_page {
  199. struct page *page;
  200. dma_addr_t addr;
  201. };
  202. int radeon_dummy_page_init(struct radeon_device *rdev);
  203. void radeon_dummy_page_fini(struct radeon_device *rdev);
  204. /*
  205. * Clocks
  206. */
  207. struct radeon_clock {
  208. struct radeon_pll p1pll;
  209. struct radeon_pll p2pll;
  210. struct radeon_pll dcpll;
  211. struct radeon_pll spll;
  212. struct radeon_pll mpll;
  213. /* 10 Khz units */
  214. uint32_t default_mclk;
  215. uint32_t default_sclk;
  216. uint32_t default_dispclk;
  217. uint32_t current_dispclk;
  218. uint32_t dp_extclk;
  219. uint32_t max_pixel_clock;
  220. };
  221. /*
  222. * Power management
  223. */
  224. int radeon_pm_init(struct radeon_device *rdev);
  225. void radeon_pm_fini(struct radeon_device *rdev);
  226. void radeon_pm_compute_clocks(struct radeon_device *rdev);
  227. void radeon_pm_suspend(struct radeon_device *rdev);
  228. void radeon_pm_resume(struct radeon_device *rdev);
  229. void radeon_combios_get_power_modes(struct radeon_device *rdev);
  230. void radeon_atombios_get_power_modes(struct radeon_device *rdev);
  231. int radeon_atom_get_clock_dividers(struct radeon_device *rdev,
  232. u8 clock_type,
  233. u32 clock,
  234. bool strobe_mode,
  235. struct atom_clock_dividers *dividers);
  236. int radeon_atom_get_memory_pll_dividers(struct radeon_device *rdev,
  237. u32 clock,
  238. bool strobe_mode,
  239. struct atom_mpll_param *mpll_param);
  240. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
  241. int radeon_atom_get_voltage_gpio_settings(struct radeon_device *rdev,
  242. u16 voltage_level, u8 voltage_type,
  243. u32 *gpio_value, u32 *gpio_mask);
  244. void radeon_atom_set_engine_dram_timings(struct radeon_device *rdev,
  245. u32 eng_clock, u32 mem_clock);
  246. int radeon_atom_get_voltage_step(struct radeon_device *rdev,
  247. u8 voltage_type, u16 *voltage_step);
  248. int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
  249. u16 voltage_id, u16 *voltage);
  250. int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device *rdev,
  251. u16 *voltage,
  252. u16 leakage_idx);
  253. int radeon_atom_get_leakage_id_from_vbios(struct radeon_device *rdev,
  254. u16 *leakage_id);
  255. int radeon_atom_get_leakage_vddc_based_on_leakage_params(struct radeon_device *rdev,
  256. u16 *vddc, u16 *vddci,
  257. u16 virtual_voltage_id,
  258. u16 vbios_voltage_id);
  259. int radeon_atom_round_to_true_voltage(struct radeon_device *rdev,
  260. u8 voltage_type,
  261. u16 nominal_voltage,
  262. u16 *true_voltage);
  263. int radeon_atom_get_min_voltage(struct radeon_device *rdev,
  264. u8 voltage_type, u16 *min_voltage);
  265. int radeon_atom_get_max_voltage(struct radeon_device *rdev,
  266. u8 voltage_type, u16 *max_voltage);
  267. int radeon_atom_get_voltage_table(struct radeon_device *rdev,
  268. u8 voltage_type, u8 voltage_mode,
  269. struct atom_voltage_table *voltage_table);
  270. bool radeon_atom_is_voltage_gpio(struct radeon_device *rdev,
  271. u8 voltage_type, u8 voltage_mode);
  272. void radeon_atom_update_memory_dll(struct radeon_device *rdev,
  273. u32 mem_clock);
  274. void radeon_atom_set_ac_timing(struct radeon_device *rdev,
  275. u32 mem_clock);
  276. int radeon_atom_init_mc_reg_table(struct radeon_device *rdev,
  277. u8 module_index,
  278. struct atom_mc_reg_table *reg_table);
  279. int radeon_atom_get_memory_info(struct radeon_device *rdev,
  280. u8 module_index, struct atom_memory_info *mem_info);
  281. int radeon_atom_get_mclk_range_table(struct radeon_device *rdev,
  282. bool gddr5, u8 module_index,
  283. struct atom_memory_clock_range_table *mclk_range_table);
  284. int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
  285. u16 voltage_id, u16 *voltage);
  286. void rs690_pm_info(struct radeon_device *rdev);
  287. extern void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
  288. unsigned *bankh, unsigned *mtaspect,
  289. unsigned *tile_split);
  290. /*
  291. * Fences.
  292. */
  293. struct radeon_fence_driver {
  294. uint32_t scratch_reg;
  295. uint64_t gpu_addr;
  296. volatile uint32_t *cpu_addr;
  297. /* sync_seq is protected by ring emission lock */
  298. uint64_t sync_seq[RADEON_NUM_RINGS];
  299. atomic64_t last_seq;
  300. unsigned long last_activity;
  301. bool initialized;
  302. };
  303. struct radeon_fence {
  304. struct radeon_device *rdev;
  305. struct kref kref;
  306. /* protected by radeon_fence.lock */
  307. uint64_t seq;
  308. /* RB, DMA, etc. */
  309. unsigned ring;
  310. };
  311. int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
  312. int radeon_fence_driver_init(struct radeon_device *rdev);
  313. void radeon_fence_driver_fini(struct radeon_device *rdev);
  314. void radeon_fence_driver_force_completion(struct radeon_device *rdev);
  315. int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
  316. void radeon_fence_process(struct radeon_device *rdev, int ring);
  317. bool radeon_fence_signaled(struct radeon_fence *fence);
  318. int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
  319. int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
  320. int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
  321. int radeon_fence_wait_any(struct radeon_device *rdev,
  322. struct radeon_fence **fences,
  323. bool intr);
  324. struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
  325. void radeon_fence_unref(struct radeon_fence **fence);
  326. unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
  327. bool radeon_fence_need_sync(struct radeon_fence *fence, int ring);
  328. void radeon_fence_note_sync(struct radeon_fence *fence, int ring);
  329. static inline struct radeon_fence *radeon_fence_later(struct radeon_fence *a,
  330. struct radeon_fence *b)
  331. {
  332. if (!a) {
  333. return b;
  334. }
  335. if (!b) {
  336. return a;
  337. }
  338. BUG_ON(a->ring != b->ring);
  339. if (a->seq > b->seq) {
  340. return a;
  341. } else {
  342. return b;
  343. }
  344. }
  345. static inline bool radeon_fence_is_earlier(struct radeon_fence *a,
  346. struct radeon_fence *b)
  347. {
  348. if (!a) {
  349. return false;
  350. }
  351. if (!b) {
  352. return true;
  353. }
  354. BUG_ON(a->ring != b->ring);
  355. return a->seq < b->seq;
  356. }
  357. /*
  358. * Tiling registers
  359. */
  360. struct radeon_surface_reg {
  361. struct radeon_bo *bo;
  362. };
  363. #define RADEON_GEM_MAX_SURFACES 8
  364. /*
  365. * TTM.
  366. */
  367. struct radeon_mman {
  368. struct ttm_bo_global_ref bo_global_ref;
  369. struct drm_global_reference mem_global_ref;
  370. struct ttm_bo_device bdev;
  371. bool mem_global_referenced;
  372. bool initialized;
  373. };
  374. /* bo virtual address in a specific vm */
  375. struct radeon_bo_va {
  376. /* protected by bo being reserved */
  377. struct list_head bo_list;
  378. uint64_t soffset;
  379. uint64_t eoffset;
  380. uint32_t flags;
  381. bool valid;
  382. unsigned ref_count;
  383. /* protected by vm mutex */
  384. struct list_head vm_list;
  385. /* constant after initialization */
  386. struct radeon_vm *vm;
  387. struct radeon_bo *bo;
  388. };
  389. struct radeon_bo {
  390. /* Protected by gem.mutex */
  391. struct list_head list;
  392. /* Protected by tbo.reserved */
  393. u32 placements[3];
  394. struct ttm_placement placement;
  395. struct ttm_buffer_object tbo;
  396. struct ttm_bo_kmap_obj kmap;
  397. unsigned pin_count;
  398. void *kptr;
  399. u32 tiling_flags;
  400. u32 pitch;
  401. int surface_reg;
  402. /* list of all virtual address to which this bo
  403. * is associated to
  404. */
  405. struct list_head va;
  406. /* Constant after initialization */
  407. struct radeon_device *rdev;
  408. struct drm_gem_object gem_base;
  409. struct ttm_bo_kmap_obj dma_buf_vmap;
  410. pid_t pid;
  411. };
  412. #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
  413. struct radeon_bo_list {
  414. struct ttm_validate_buffer tv;
  415. struct radeon_bo *bo;
  416. uint64_t gpu_offset;
  417. bool written;
  418. unsigned domain;
  419. unsigned alt_domain;
  420. u32 tiling_flags;
  421. };
  422. int radeon_gem_debugfs_init(struct radeon_device *rdev);
  423. /* sub-allocation manager, it has to be protected by another lock.
  424. * By conception this is an helper for other part of the driver
  425. * like the indirect buffer or semaphore, which both have their
  426. * locking.
  427. *
  428. * Principe is simple, we keep a list of sub allocation in offset
  429. * order (first entry has offset == 0, last entry has the highest
  430. * offset).
  431. *
  432. * When allocating new object we first check if there is room at
  433. * the end total_size - (last_object_offset + last_object_size) >=
  434. * alloc_size. If so we allocate new object there.
  435. *
  436. * When there is not enough room at the end, we start waiting for
  437. * each sub object until we reach object_offset+object_size >=
  438. * alloc_size, this object then become the sub object we return.
  439. *
  440. * Alignment can't be bigger than page size.
  441. *
  442. * Hole are not considered for allocation to keep things simple.
  443. * Assumption is that there won't be hole (all object on same
  444. * alignment).
  445. */
  446. struct radeon_sa_manager {
  447. wait_queue_head_t wq;
  448. struct radeon_bo *bo;
  449. struct list_head *hole;
  450. struct list_head flist[RADEON_NUM_RINGS];
  451. struct list_head olist;
  452. unsigned size;
  453. uint64_t gpu_addr;
  454. void *cpu_ptr;
  455. uint32_t domain;
  456. uint32_t align;
  457. };
  458. struct radeon_sa_bo;
  459. /* sub-allocation buffer */
  460. struct radeon_sa_bo {
  461. struct list_head olist;
  462. struct list_head flist;
  463. struct radeon_sa_manager *manager;
  464. unsigned soffset;
  465. unsigned eoffset;
  466. struct radeon_fence *fence;
  467. };
  468. /*
  469. * GEM objects.
  470. */
  471. struct radeon_gem {
  472. struct mutex mutex;
  473. struct list_head objects;
  474. };
  475. int radeon_gem_init(struct radeon_device *rdev);
  476. void radeon_gem_fini(struct radeon_device *rdev);
  477. int radeon_gem_object_create(struct radeon_device *rdev, int size,
  478. int alignment, int initial_domain,
  479. bool discardable, bool kernel,
  480. struct drm_gem_object **obj);
  481. int radeon_mode_dumb_create(struct drm_file *file_priv,
  482. struct drm_device *dev,
  483. struct drm_mode_create_dumb *args);
  484. int radeon_mode_dumb_mmap(struct drm_file *filp,
  485. struct drm_device *dev,
  486. uint32_t handle, uint64_t *offset_p);
  487. /*
  488. * Semaphores.
  489. */
  490. /* everything here is constant */
  491. struct radeon_semaphore {
  492. struct radeon_sa_bo *sa_bo;
  493. signed waiters;
  494. uint64_t gpu_addr;
  495. };
  496. int radeon_semaphore_create(struct radeon_device *rdev,
  497. struct radeon_semaphore **semaphore);
  498. void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
  499. struct radeon_semaphore *semaphore);
  500. void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
  501. struct radeon_semaphore *semaphore);
  502. int radeon_semaphore_sync_rings(struct radeon_device *rdev,
  503. struct radeon_semaphore *semaphore,
  504. int signaler, int waiter);
  505. void radeon_semaphore_free(struct radeon_device *rdev,
  506. struct radeon_semaphore **semaphore,
  507. struct radeon_fence *fence);
  508. /*
  509. * GART structures, functions & helpers
  510. */
  511. struct radeon_mc;
  512. #define RADEON_GPU_PAGE_SIZE 4096
  513. #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
  514. #define RADEON_GPU_PAGE_SHIFT 12
  515. #define RADEON_GPU_PAGE_ALIGN(a) (((a) + RADEON_GPU_PAGE_MASK) & ~RADEON_GPU_PAGE_MASK)
  516. struct radeon_gart {
  517. dma_addr_t table_addr;
  518. struct radeon_bo *robj;
  519. void *ptr;
  520. unsigned num_gpu_pages;
  521. unsigned num_cpu_pages;
  522. unsigned table_size;
  523. struct page **pages;
  524. dma_addr_t *pages_addr;
  525. bool ready;
  526. };
  527. int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
  528. void radeon_gart_table_ram_free(struct radeon_device *rdev);
  529. int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
  530. void radeon_gart_table_vram_free(struct radeon_device *rdev);
  531. int radeon_gart_table_vram_pin(struct radeon_device *rdev);
  532. void radeon_gart_table_vram_unpin(struct radeon_device *rdev);
  533. int radeon_gart_init(struct radeon_device *rdev);
  534. void radeon_gart_fini(struct radeon_device *rdev);
  535. void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
  536. int pages);
  537. int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
  538. int pages, struct page **pagelist,
  539. dma_addr_t *dma_addr);
  540. void radeon_gart_restore(struct radeon_device *rdev);
  541. /*
  542. * GPU MC structures, functions & helpers
  543. */
  544. struct radeon_mc {
  545. resource_size_t aper_size;
  546. resource_size_t aper_base;
  547. resource_size_t agp_base;
  548. /* for some chips with <= 32MB we need to lie
  549. * about vram size near mc fb location */
  550. u64 mc_vram_size;
  551. u64 visible_vram_size;
  552. u64 gtt_size;
  553. u64 gtt_start;
  554. u64 gtt_end;
  555. u64 vram_start;
  556. u64 vram_end;
  557. unsigned vram_width;
  558. u64 real_vram_size;
  559. int vram_mtrr;
  560. bool vram_is_ddr;
  561. bool igp_sideport_enabled;
  562. u64 gtt_base_align;
  563. u64 mc_mask;
  564. };
  565. bool radeon_combios_sideport_present(struct radeon_device *rdev);
  566. bool radeon_atombios_sideport_present(struct radeon_device *rdev);
  567. /*
  568. * GPU scratch registers structures, functions & helpers
  569. */
  570. struct radeon_scratch {
  571. unsigned num_reg;
  572. uint32_t reg_base;
  573. bool free[32];
  574. uint32_t reg[32];
  575. };
  576. int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
  577. void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
  578. /*
  579. * GPU doorbell structures, functions & helpers
  580. */
  581. struct radeon_doorbell {
  582. u32 num_pages;
  583. bool free[1024];
  584. /* doorbell mmio */
  585. resource_size_t base;
  586. resource_size_t size;
  587. void __iomem *ptr;
  588. };
  589. int radeon_doorbell_get(struct radeon_device *rdev, u32 *page);
  590. void radeon_doorbell_free(struct radeon_device *rdev, u32 doorbell);
  591. /*
  592. * IRQS.
  593. */
  594. struct radeon_unpin_work {
  595. struct work_struct work;
  596. struct radeon_device *rdev;
  597. int crtc_id;
  598. struct radeon_fence *fence;
  599. struct drm_pending_vblank_event *event;
  600. struct radeon_bo *old_rbo;
  601. u64 new_crtc_base;
  602. };
  603. struct r500_irq_stat_regs {
  604. u32 disp_int;
  605. u32 hdmi0_status;
  606. };
  607. struct r600_irq_stat_regs {
  608. u32 disp_int;
  609. u32 disp_int_cont;
  610. u32 disp_int_cont2;
  611. u32 d1grph_int;
  612. u32 d2grph_int;
  613. u32 hdmi0_status;
  614. u32 hdmi1_status;
  615. };
  616. struct evergreen_irq_stat_regs {
  617. u32 disp_int;
  618. u32 disp_int_cont;
  619. u32 disp_int_cont2;
  620. u32 disp_int_cont3;
  621. u32 disp_int_cont4;
  622. u32 disp_int_cont5;
  623. u32 d1grph_int;
  624. u32 d2grph_int;
  625. u32 d3grph_int;
  626. u32 d4grph_int;
  627. u32 d5grph_int;
  628. u32 d6grph_int;
  629. u32 afmt_status1;
  630. u32 afmt_status2;
  631. u32 afmt_status3;
  632. u32 afmt_status4;
  633. u32 afmt_status5;
  634. u32 afmt_status6;
  635. };
  636. struct cik_irq_stat_regs {
  637. u32 disp_int;
  638. u32 disp_int_cont;
  639. u32 disp_int_cont2;
  640. u32 disp_int_cont3;
  641. u32 disp_int_cont4;
  642. u32 disp_int_cont5;
  643. u32 disp_int_cont6;
  644. };
  645. union radeon_irq_stat_regs {
  646. struct r500_irq_stat_regs r500;
  647. struct r600_irq_stat_regs r600;
  648. struct evergreen_irq_stat_regs evergreen;
  649. struct cik_irq_stat_regs cik;
  650. };
  651. #define RADEON_MAX_HPD_PINS 6
  652. #define RADEON_MAX_CRTCS 6
  653. #define RADEON_MAX_AFMT_BLOCKS 7
  654. struct radeon_irq {
  655. bool installed;
  656. spinlock_t lock;
  657. atomic_t ring_int[RADEON_NUM_RINGS];
  658. bool crtc_vblank_int[RADEON_MAX_CRTCS];
  659. atomic_t pflip[RADEON_MAX_CRTCS];
  660. wait_queue_head_t vblank_queue;
  661. bool hpd[RADEON_MAX_HPD_PINS];
  662. bool afmt[RADEON_MAX_AFMT_BLOCKS];
  663. union radeon_irq_stat_regs stat_regs;
  664. bool dpm_thermal;
  665. };
  666. int radeon_irq_kms_init(struct radeon_device *rdev);
  667. void radeon_irq_kms_fini(struct radeon_device *rdev);
  668. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring);
  669. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring);
  670. void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
  671. void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
  672. void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block);
  673. void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block);
  674. void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
  675. void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
  676. /*
  677. * CP & rings.
  678. */
  679. struct radeon_ib {
  680. struct radeon_sa_bo *sa_bo;
  681. uint32_t length_dw;
  682. uint64_t gpu_addr;
  683. uint32_t *ptr;
  684. int ring;
  685. struct radeon_fence *fence;
  686. struct radeon_vm *vm;
  687. bool is_const_ib;
  688. struct radeon_fence *sync_to[RADEON_NUM_RINGS];
  689. struct radeon_semaphore *semaphore;
  690. };
  691. struct radeon_ring {
  692. struct radeon_bo *ring_obj;
  693. volatile uint32_t *ring;
  694. unsigned rptr;
  695. unsigned rptr_offs;
  696. unsigned rptr_reg;
  697. unsigned rptr_save_reg;
  698. u64 next_rptr_gpu_addr;
  699. volatile u32 *next_rptr_cpu_addr;
  700. unsigned wptr;
  701. unsigned wptr_old;
  702. unsigned wptr_reg;
  703. unsigned ring_size;
  704. unsigned ring_free_dw;
  705. int count_dw;
  706. unsigned long last_activity;
  707. unsigned last_rptr;
  708. uint64_t gpu_addr;
  709. uint32_t align_mask;
  710. uint32_t ptr_mask;
  711. bool ready;
  712. u32 nop;
  713. u32 idx;
  714. u64 last_semaphore_signal_addr;
  715. u64 last_semaphore_wait_addr;
  716. /* for CIK queues */
  717. u32 me;
  718. u32 pipe;
  719. u32 queue;
  720. struct radeon_bo *mqd_obj;
  721. u32 doorbell_page_num;
  722. u32 doorbell_offset;
  723. unsigned wptr_offs;
  724. };
  725. struct radeon_mec {
  726. struct radeon_bo *hpd_eop_obj;
  727. u64 hpd_eop_gpu_addr;
  728. u32 num_pipe;
  729. u32 num_mec;
  730. u32 num_queue;
  731. };
  732. /*
  733. * VM
  734. */
  735. /* maximum number of VMIDs */
  736. #define RADEON_NUM_VM 16
  737. /* defines number of bits in page table versus page directory,
  738. * a page is 4KB so we have 12 bits offset, 9 bits in the page
  739. * table and the remaining 19 bits are in the page directory */
  740. #define RADEON_VM_BLOCK_SIZE 9
  741. /* number of entries in page table */
  742. #define RADEON_VM_PTE_COUNT (1 << RADEON_VM_BLOCK_SIZE)
  743. /* PTBs (Page Table Blocks) need to be aligned to 32K */
  744. #define RADEON_VM_PTB_ALIGN_SIZE 32768
  745. #define RADEON_VM_PTB_ALIGN_MASK (RADEON_VM_PTB_ALIGN_SIZE - 1)
  746. #define RADEON_VM_PTB_ALIGN(a) (((a) + RADEON_VM_PTB_ALIGN_MASK) & ~RADEON_VM_PTB_ALIGN_MASK)
  747. struct radeon_vm {
  748. struct list_head list;
  749. struct list_head va;
  750. unsigned id;
  751. /* contains the page directory */
  752. struct radeon_sa_bo *page_directory;
  753. uint64_t pd_gpu_addr;
  754. /* array of page tables, one for each page directory entry */
  755. struct radeon_sa_bo **page_tables;
  756. struct mutex mutex;
  757. /* last fence for cs using this vm */
  758. struct radeon_fence *fence;
  759. /* last flush or NULL if we still need to flush */
  760. struct radeon_fence *last_flush;
  761. };
  762. struct radeon_vm_manager {
  763. struct mutex lock;
  764. struct list_head lru_vm;
  765. struct radeon_fence *active[RADEON_NUM_VM];
  766. struct radeon_sa_manager sa_manager;
  767. uint32_t max_pfn;
  768. /* number of VMIDs */
  769. unsigned nvm;
  770. /* vram base address for page table entry */
  771. u64 vram_base_offset;
  772. /* is vm enabled? */
  773. bool enabled;
  774. };
  775. /*
  776. * file private structure
  777. */
  778. struct radeon_fpriv {
  779. struct radeon_vm vm;
  780. };
  781. /*
  782. * R6xx+ IH ring
  783. */
  784. struct r600_ih {
  785. struct radeon_bo *ring_obj;
  786. volatile uint32_t *ring;
  787. unsigned rptr;
  788. unsigned ring_size;
  789. uint64_t gpu_addr;
  790. uint32_t ptr_mask;
  791. atomic_t lock;
  792. bool enabled;
  793. };
  794. /*
  795. * RLC stuff
  796. */
  797. #include "clearstate_defs.h"
  798. struct radeon_rlc {
  799. /* for power gating */
  800. struct radeon_bo *save_restore_obj;
  801. uint64_t save_restore_gpu_addr;
  802. volatile uint32_t *sr_ptr;
  803. const u32 *reg_list;
  804. u32 reg_list_size;
  805. /* for clear state */
  806. struct radeon_bo *clear_state_obj;
  807. uint64_t clear_state_gpu_addr;
  808. volatile uint32_t *cs_ptr;
  809. const struct cs_section_def *cs_data;
  810. u32 clear_state_size;
  811. /* for cp tables */
  812. struct radeon_bo *cp_table_obj;
  813. uint64_t cp_table_gpu_addr;
  814. volatile uint32_t *cp_table_ptr;
  815. u32 cp_table_size;
  816. };
  817. int radeon_ib_get(struct radeon_device *rdev, int ring,
  818. struct radeon_ib *ib, struct radeon_vm *vm,
  819. unsigned size);
  820. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib);
  821. void radeon_ib_sync_to(struct radeon_ib *ib, struct radeon_fence *fence);
  822. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib,
  823. struct radeon_ib *const_ib);
  824. int radeon_ib_pool_init(struct radeon_device *rdev);
  825. void radeon_ib_pool_fini(struct radeon_device *rdev);
  826. int radeon_ib_ring_tests(struct radeon_device *rdev);
  827. /* Ring access between begin & end cannot sleep */
  828. bool radeon_ring_supports_scratch_reg(struct radeon_device *rdev,
  829. struct radeon_ring *ring);
  830. void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
  831. int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  832. int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  833. void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  834. void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  835. void radeon_ring_undo(struct radeon_ring *ring);
  836. void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
  837. int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
  838. void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring);
  839. void radeon_ring_lockup_update(struct radeon_ring *ring);
  840. bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring);
  841. unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring,
  842. uint32_t **data);
  843. int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
  844. unsigned size, uint32_t *data);
  845. int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
  846. unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg, u32 nop);
  847. void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
  848. /* r600 async dma */
  849. void r600_dma_stop(struct radeon_device *rdev);
  850. int r600_dma_resume(struct radeon_device *rdev);
  851. void r600_dma_fini(struct radeon_device *rdev);
  852. void cayman_dma_stop(struct radeon_device *rdev);
  853. int cayman_dma_resume(struct radeon_device *rdev);
  854. void cayman_dma_fini(struct radeon_device *rdev);
  855. /*
  856. * CS.
  857. */
  858. struct radeon_cs_reloc {
  859. struct drm_gem_object *gobj;
  860. struct radeon_bo *robj;
  861. struct radeon_bo_list lobj;
  862. uint32_t handle;
  863. uint32_t flags;
  864. };
  865. struct radeon_cs_chunk {
  866. uint32_t chunk_id;
  867. uint32_t length_dw;
  868. int kpage_idx[2];
  869. uint32_t *kpage[2];
  870. uint32_t *kdata;
  871. void __user *user_ptr;
  872. int last_copied_page;
  873. int last_page_index;
  874. };
  875. struct radeon_cs_parser {
  876. struct device *dev;
  877. struct radeon_device *rdev;
  878. struct drm_file *filp;
  879. /* chunks */
  880. unsigned nchunks;
  881. struct radeon_cs_chunk *chunks;
  882. uint64_t *chunks_array;
  883. /* IB */
  884. unsigned idx;
  885. /* relocations */
  886. unsigned nrelocs;
  887. struct radeon_cs_reloc *relocs;
  888. struct radeon_cs_reloc **relocs_ptr;
  889. struct list_head validated;
  890. unsigned dma_reloc_idx;
  891. /* indices of various chunks */
  892. int chunk_ib_idx;
  893. int chunk_relocs_idx;
  894. int chunk_flags_idx;
  895. int chunk_const_ib_idx;
  896. struct radeon_ib ib;
  897. struct radeon_ib const_ib;
  898. void *track;
  899. unsigned family;
  900. int parser_error;
  901. u32 cs_flags;
  902. u32 ring;
  903. s32 priority;
  904. struct ww_acquire_ctx ticket;
  905. };
  906. extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
  907. extern u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx);
  908. struct radeon_cs_packet {
  909. unsigned idx;
  910. unsigned type;
  911. unsigned reg;
  912. unsigned opcode;
  913. int count;
  914. unsigned one_reg_wr;
  915. };
  916. typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
  917. struct radeon_cs_packet *pkt,
  918. unsigned idx, unsigned reg);
  919. typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
  920. struct radeon_cs_packet *pkt);
  921. /*
  922. * AGP
  923. */
  924. int radeon_agp_init(struct radeon_device *rdev);
  925. void radeon_agp_resume(struct radeon_device *rdev);
  926. void radeon_agp_suspend(struct radeon_device *rdev);
  927. void radeon_agp_fini(struct radeon_device *rdev);
  928. /*
  929. * Writeback
  930. */
  931. struct radeon_wb {
  932. struct radeon_bo *wb_obj;
  933. volatile uint32_t *wb;
  934. uint64_t gpu_addr;
  935. bool enabled;
  936. bool use_event;
  937. };
  938. #define RADEON_WB_SCRATCH_OFFSET 0
  939. #define RADEON_WB_RING0_NEXT_RPTR 256
  940. #define RADEON_WB_CP_RPTR_OFFSET 1024
  941. #define RADEON_WB_CP1_RPTR_OFFSET 1280
  942. #define RADEON_WB_CP2_RPTR_OFFSET 1536
  943. #define R600_WB_DMA_RPTR_OFFSET 1792
  944. #define R600_WB_IH_WPTR_OFFSET 2048
  945. #define CAYMAN_WB_DMA1_RPTR_OFFSET 2304
  946. #define R600_WB_EVENT_OFFSET 3072
  947. #define CIK_WB_CP1_WPTR_OFFSET 3328
  948. #define CIK_WB_CP2_WPTR_OFFSET 3584
  949. /**
  950. * struct radeon_pm - power management datas
  951. * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
  952. * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
  953. * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
  954. * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
  955. * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
  956. * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
  957. * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
  958. * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
  959. * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
  960. * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
  961. * @needed_bandwidth: current bandwidth needs
  962. *
  963. * It keeps track of various data needed to take powermanagement decision.
  964. * Bandwidth need is used to determine minimun clock of the GPU and memory.
  965. * Equation between gpu/memory clock and available bandwidth is hw dependent
  966. * (type of memory, bus size, efficiency, ...)
  967. */
  968. enum radeon_pm_method {
  969. PM_METHOD_PROFILE,
  970. PM_METHOD_DYNPM,
  971. PM_METHOD_DPM,
  972. };
  973. enum radeon_dynpm_state {
  974. DYNPM_STATE_DISABLED,
  975. DYNPM_STATE_MINIMUM,
  976. DYNPM_STATE_PAUSED,
  977. DYNPM_STATE_ACTIVE,
  978. DYNPM_STATE_SUSPENDED,
  979. };
  980. enum radeon_dynpm_action {
  981. DYNPM_ACTION_NONE,
  982. DYNPM_ACTION_MINIMUM,
  983. DYNPM_ACTION_DOWNCLOCK,
  984. DYNPM_ACTION_UPCLOCK,
  985. DYNPM_ACTION_DEFAULT
  986. };
  987. enum radeon_voltage_type {
  988. VOLTAGE_NONE = 0,
  989. VOLTAGE_GPIO,
  990. VOLTAGE_VDDC,
  991. VOLTAGE_SW
  992. };
  993. enum radeon_pm_state_type {
  994. /* not used for dpm */
  995. POWER_STATE_TYPE_DEFAULT,
  996. POWER_STATE_TYPE_POWERSAVE,
  997. /* user selectable states */
  998. POWER_STATE_TYPE_BATTERY,
  999. POWER_STATE_TYPE_BALANCED,
  1000. POWER_STATE_TYPE_PERFORMANCE,
  1001. /* internal states */
  1002. POWER_STATE_TYPE_INTERNAL_UVD,
  1003. POWER_STATE_TYPE_INTERNAL_UVD_SD,
  1004. POWER_STATE_TYPE_INTERNAL_UVD_HD,
  1005. POWER_STATE_TYPE_INTERNAL_UVD_HD2,
  1006. POWER_STATE_TYPE_INTERNAL_UVD_MVC,
  1007. POWER_STATE_TYPE_INTERNAL_BOOT,
  1008. POWER_STATE_TYPE_INTERNAL_THERMAL,
  1009. POWER_STATE_TYPE_INTERNAL_ACPI,
  1010. POWER_STATE_TYPE_INTERNAL_ULV,
  1011. POWER_STATE_TYPE_INTERNAL_3DPERF,
  1012. };
  1013. enum radeon_pm_profile_type {
  1014. PM_PROFILE_DEFAULT,
  1015. PM_PROFILE_AUTO,
  1016. PM_PROFILE_LOW,
  1017. PM_PROFILE_MID,
  1018. PM_PROFILE_HIGH,
  1019. };
  1020. #define PM_PROFILE_DEFAULT_IDX 0
  1021. #define PM_PROFILE_LOW_SH_IDX 1
  1022. #define PM_PROFILE_MID_SH_IDX 2
  1023. #define PM_PROFILE_HIGH_SH_IDX 3
  1024. #define PM_PROFILE_LOW_MH_IDX 4
  1025. #define PM_PROFILE_MID_MH_IDX 5
  1026. #define PM_PROFILE_HIGH_MH_IDX 6
  1027. #define PM_PROFILE_MAX 7
  1028. struct radeon_pm_profile {
  1029. int dpms_off_ps_idx;
  1030. int dpms_on_ps_idx;
  1031. int dpms_off_cm_idx;
  1032. int dpms_on_cm_idx;
  1033. };
  1034. enum radeon_int_thermal_type {
  1035. THERMAL_TYPE_NONE,
  1036. THERMAL_TYPE_EXTERNAL,
  1037. THERMAL_TYPE_EXTERNAL_GPIO,
  1038. THERMAL_TYPE_RV6XX,
  1039. THERMAL_TYPE_RV770,
  1040. THERMAL_TYPE_ADT7473_WITH_INTERNAL,
  1041. THERMAL_TYPE_EVERGREEN,
  1042. THERMAL_TYPE_SUMO,
  1043. THERMAL_TYPE_NI,
  1044. THERMAL_TYPE_SI,
  1045. THERMAL_TYPE_EMC2103_WITH_INTERNAL,
  1046. THERMAL_TYPE_CI,
  1047. THERMAL_TYPE_KV,
  1048. };
  1049. struct radeon_voltage {
  1050. enum radeon_voltage_type type;
  1051. /* gpio voltage */
  1052. struct radeon_gpio_rec gpio;
  1053. u32 delay; /* delay in usec from voltage drop to sclk change */
  1054. bool active_high; /* voltage drop is active when bit is high */
  1055. /* VDDC voltage */
  1056. u8 vddc_id; /* index into vddc voltage table */
  1057. u8 vddci_id; /* index into vddci voltage table */
  1058. bool vddci_enabled;
  1059. /* r6xx+ sw */
  1060. u16 voltage;
  1061. /* evergreen+ vddci */
  1062. u16 vddci;
  1063. };
  1064. /* clock mode flags */
  1065. #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
  1066. struct radeon_pm_clock_info {
  1067. /* memory clock */
  1068. u32 mclk;
  1069. /* engine clock */
  1070. u32 sclk;
  1071. /* voltage info */
  1072. struct radeon_voltage voltage;
  1073. /* standardized clock flags */
  1074. u32 flags;
  1075. };
  1076. /* state flags */
  1077. #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
  1078. struct radeon_power_state {
  1079. enum radeon_pm_state_type type;
  1080. struct radeon_pm_clock_info *clock_info;
  1081. /* number of valid clock modes in this power state */
  1082. int num_clock_modes;
  1083. struct radeon_pm_clock_info *default_clock_mode;
  1084. /* standardized state flags */
  1085. u32 flags;
  1086. u32 misc; /* vbios specific flags */
  1087. u32 misc2; /* vbios specific flags */
  1088. int pcie_lanes; /* pcie lanes */
  1089. };
  1090. /*
  1091. * Some modes are overclocked by very low value, accept them
  1092. */
  1093. #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
  1094. enum radeon_dpm_auto_throttle_src {
  1095. RADEON_DPM_AUTO_THROTTLE_SRC_THERMAL,
  1096. RADEON_DPM_AUTO_THROTTLE_SRC_EXTERNAL
  1097. };
  1098. enum radeon_dpm_event_src {
  1099. RADEON_DPM_EVENT_SRC_ANALOG = 0,
  1100. RADEON_DPM_EVENT_SRC_EXTERNAL = 1,
  1101. RADEON_DPM_EVENT_SRC_DIGITAL = 2,
  1102. RADEON_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
  1103. RADEON_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
  1104. };
  1105. struct radeon_ps {
  1106. u32 caps; /* vbios flags */
  1107. u32 class; /* vbios flags */
  1108. u32 class2; /* vbios flags */
  1109. /* UVD clocks */
  1110. u32 vclk;
  1111. u32 dclk;
  1112. /* VCE clocks */
  1113. u32 evclk;
  1114. u32 ecclk;
  1115. /* asic priv */
  1116. void *ps_priv;
  1117. };
  1118. struct radeon_dpm_thermal {
  1119. /* thermal interrupt work */
  1120. struct work_struct work;
  1121. /* low temperature threshold */
  1122. int min_temp;
  1123. /* high temperature threshold */
  1124. int max_temp;
  1125. /* was interrupt low to high or high to low */
  1126. bool high_to_low;
  1127. };
  1128. enum radeon_clk_action
  1129. {
  1130. RADEON_SCLK_UP = 1,
  1131. RADEON_SCLK_DOWN
  1132. };
  1133. struct radeon_blacklist_clocks
  1134. {
  1135. u32 sclk;
  1136. u32 mclk;
  1137. enum radeon_clk_action action;
  1138. };
  1139. struct radeon_clock_and_voltage_limits {
  1140. u32 sclk;
  1141. u32 mclk;
  1142. u32 vddc;
  1143. u32 vddci;
  1144. };
  1145. struct radeon_clock_array {
  1146. u32 count;
  1147. u32 *values;
  1148. };
  1149. struct radeon_clock_voltage_dependency_entry {
  1150. u32 clk;
  1151. u16 v;
  1152. };
  1153. struct radeon_clock_voltage_dependency_table {
  1154. u32 count;
  1155. struct radeon_clock_voltage_dependency_entry *entries;
  1156. };
  1157. union radeon_cac_leakage_entry {
  1158. struct {
  1159. u16 vddc;
  1160. u32 leakage;
  1161. };
  1162. struct {
  1163. u16 vddc1;
  1164. u16 vddc2;
  1165. u16 vddc3;
  1166. };
  1167. };
  1168. struct radeon_cac_leakage_table {
  1169. u32 count;
  1170. union radeon_cac_leakage_entry *entries;
  1171. };
  1172. struct radeon_phase_shedding_limits_entry {
  1173. u16 voltage;
  1174. u32 sclk;
  1175. u32 mclk;
  1176. };
  1177. struct radeon_phase_shedding_limits_table {
  1178. u32 count;
  1179. struct radeon_phase_shedding_limits_entry *entries;
  1180. };
  1181. struct radeon_uvd_clock_voltage_dependency_entry {
  1182. u32 vclk;
  1183. u32 dclk;
  1184. u16 v;
  1185. };
  1186. struct radeon_uvd_clock_voltage_dependency_table {
  1187. u8 count;
  1188. struct radeon_uvd_clock_voltage_dependency_entry *entries;
  1189. };
  1190. struct radeon_vce_clock_voltage_dependency_entry {
  1191. u32 ecclk;
  1192. u32 evclk;
  1193. u16 v;
  1194. };
  1195. struct radeon_vce_clock_voltage_dependency_table {
  1196. u8 count;
  1197. struct radeon_vce_clock_voltage_dependency_entry *entries;
  1198. };
  1199. struct radeon_ppm_table {
  1200. u8 ppm_design;
  1201. u16 cpu_core_number;
  1202. u32 platform_tdp;
  1203. u32 small_ac_platform_tdp;
  1204. u32 platform_tdc;
  1205. u32 small_ac_platform_tdc;
  1206. u32 apu_tdp;
  1207. u32 dgpu_tdp;
  1208. u32 dgpu_ulv_power;
  1209. u32 tj_max;
  1210. };
  1211. struct radeon_cac_tdp_table {
  1212. u16 tdp;
  1213. u16 configurable_tdp;
  1214. u16 tdc;
  1215. u16 battery_power_limit;
  1216. u16 small_power_limit;
  1217. u16 low_cac_leakage;
  1218. u16 high_cac_leakage;
  1219. u16 maximum_power_delivery_limit;
  1220. };
  1221. struct radeon_dpm_dynamic_state {
  1222. struct radeon_clock_voltage_dependency_table vddc_dependency_on_sclk;
  1223. struct radeon_clock_voltage_dependency_table vddci_dependency_on_mclk;
  1224. struct radeon_clock_voltage_dependency_table vddc_dependency_on_mclk;
  1225. struct radeon_clock_voltage_dependency_table mvdd_dependency_on_mclk;
  1226. struct radeon_clock_voltage_dependency_table vddc_dependency_on_dispclk;
  1227. struct radeon_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
  1228. struct radeon_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
  1229. struct radeon_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
  1230. struct radeon_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
  1231. struct radeon_clock_array valid_sclk_values;
  1232. struct radeon_clock_array valid_mclk_values;
  1233. struct radeon_clock_and_voltage_limits max_clock_voltage_on_dc;
  1234. struct radeon_clock_and_voltage_limits max_clock_voltage_on_ac;
  1235. u32 mclk_sclk_ratio;
  1236. u32 sclk_mclk_delta;
  1237. u16 vddc_vddci_delta;
  1238. u16 min_vddc_for_pcie_gen2;
  1239. struct radeon_cac_leakage_table cac_leakage_table;
  1240. struct radeon_phase_shedding_limits_table phase_shedding_limits_table;
  1241. struct radeon_ppm_table *ppm_table;
  1242. struct radeon_cac_tdp_table *cac_tdp_table;
  1243. };
  1244. struct radeon_dpm_fan {
  1245. u16 t_min;
  1246. u16 t_med;
  1247. u16 t_high;
  1248. u16 pwm_min;
  1249. u16 pwm_med;
  1250. u16 pwm_high;
  1251. u8 t_hyst;
  1252. u32 cycle_delay;
  1253. u16 t_max;
  1254. bool ucode_fan_control;
  1255. };
  1256. enum radeon_pcie_gen {
  1257. RADEON_PCIE_GEN1 = 0,
  1258. RADEON_PCIE_GEN2 = 1,
  1259. RADEON_PCIE_GEN3 = 2,
  1260. RADEON_PCIE_GEN_INVALID = 0xffff
  1261. };
  1262. enum radeon_dpm_forced_level {
  1263. RADEON_DPM_FORCED_LEVEL_AUTO = 0,
  1264. RADEON_DPM_FORCED_LEVEL_LOW = 1,
  1265. RADEON_DPM_FORCED_LEVEL_HIGH = 2,
  1266. };
  1267. struct radeon_dpm {
  1268. struct radeon_ps *ps;
  1269. /* number of valid power states */
  1270. int num_ps;
  1271. /* current power state that is active */
  1272. struct radeon_ps *current_ps;
  1273. /* requested power state */
  1274. struct radeon_ps *requested_ps;
  1275. /* boot up power state */
  1276. struct radeon_ps *boot_ps;
  1277. /* default uvd power state */
  1278. struct radeon_ps *uvd_ps;
  1279. enum radeon_pm_state_type state;
  1280. enum radeon_pm_state_type user_state;
  1281. u32 platform_caps;
  1282. u32 voltage_response_time;
  1283. u32 backbias_response_time;
  1284. void *priv;
  1285. u32 new_active_crtcs;
  1286. int new_active_crtc_count;
  1287. u32 current_active_crtcs;
  1288. int current_active_crtc_count;
  1289. struct radeon_dpm_dynamic_state dyn_state;
  1290. struct radeon_dpm_fan fan;
  1291. u32 tdp_limit;
  1292. u32 near_tdp_limit;
  1293. u32 near_tdp_limit_adjusted;
  1294. u32 sq_ramping_threshold;
  1295. u32 cac_leakage;
  1296. u16 tdp_od_limit;
  1297. u32 tdp_adjustment;
  1298. u16 load_line_slope;
  1299. bool power_control;
  1300. bool ac_power;
  1301. /* special states active */
  1302. bool thermal_active;
  1303. bool uvd_active;
  1304. /* thermal handling */
  1305. struct radeon_dpm_thermal thermal;
  1306. /* forced levels */
  1307. enum radeon_dpm_forced_level forced_level;
  1308. /* track UVD streams */
  1309. unsigned sd;
  1310. unsigned hd;
  1311. };
  1312. void radeon_dpm_enable_uvd(struct radeon_device *rdev, bool enable);
  1313. struct radeon_pm {
  1314. struct mutex mutex;
  1315. /* write locked while reprogramming mclk */
  1316. struct rw_semaphore mclk_lock;
  1317. u32 active_crtcs;
  1318. int active_crtc_count;
  1319. int req_vblank;
  1320. bool vblank_sync;
  1321. fixed20_12 max_bandwidth;
  1322. fixed20_12 igp_sideport_mclk;
  1323. fixed20_12 igp_system_mclk;
  1324. fixed20_12 igp_ht_link_clk;
  1325. fixed20_12 igp_ht_link_width;
  1326. fixed20_12 k8_bandwidth;
  1327. fixed20_12 sideport_bandwidth;
  1328. fixed20_12 ht_bandwidth;
  1329. fixed20_12 core_bandwidth;
  1330. fixed20_12 sclk;
  1331. fixed20_12 mclk;
  1332. fixed20_12 needed_bandwidth;
  1333. struct radeon_power_state *power_state;
  1334. /* number of valid power states */
  1335. int num_power_states;
  1336. int current_power_state_index;
  1337. int current_clock_mode_index;
  1338. int requested_power_state_index;
  1339. int requested_clock_mode_index;
  1340. int default_power_state_index;
  1341. u32 current_sclk;
  1342. u32 current_mclk;
  1343. u16 current_vddc;
  1344. u16 current_vddci;
  1345. u32 default_sclk;
  1346. u32 default_mclk;
  1347. u16 default_vddc;
  1348. u16 default_vddci;
  1349. struct radeon_i2c_chan *i2c_bus;
  1350. /* selected pm method */
  1351. enum radeon_pm_method pm_method;
  1352. /* dynpm power management */
  1353. struct delayed_work dynpm_idle_work;
  1354. enum radeon_dynpm_state dynpm_state;
  1355. enum radeon_dynpm_action dynpm_planned_action;
  1356. unsigned long dynpm_action_timeout;
  1357. bool dynpm_can_upclock;
  1358. bool dynpm_can_downclock;
  1359. /* profile-based power management */
  1360. enum radeon_pm_profile_type profile;
  1361. int profile_index;
  1362. struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  1363. /* internal thermal controller on rv6xx+ */
  1364. enum radeon_int_thermal_type int_thermal_type;
  1365. struct device *int_hwmon_dev;
  1366. /* dpm */
  1367. bool dpm_enabled;
  1368. struct radeon_dpm dpm;
  1369. };
  1370. int radeon_pm_get_type_index(struct radeon_device *rdev,
  1371. enum radeon_pm_state_type ps_type,
  1372. int instance);
  1373. /*
  1374. * UVD
  1375. */
  1376. #define RADEON_MAX_UVD_HANDLES 10
  1377. #define RADEON_UVD_STACK_SIZE (1024*1024)
  1378. #define RADEON_UVD_HEAP_SIZE (1024*1024)
  1379. struct radeon_uvd {
  1380. struct radeon_bo *vcpu_bo;
  1381. void *cpu_addr;
  1382. uint64_t gpu_addr;
  1383. void *saved_bo;
  1384. atomic_t handles[RADEON_MAX_UVD_HANDLES];
  1385. struct drm_file *filp[RADEON_MAX_UVD_HANDLES];
  1386. unsigned img_size[RADEON_MAX_UVD_HANDLES];
  1387. struct delayed_work idle_work;
  1388. };
  1389. int radeon_uvd_init(struct radeon_device *rdev);
  1390. void radeon_uvd_fini(struct radeon_device *rdev);
  1391. int radeon_uvd_suspend(struct radeon_device *rdev);
  1392. int radeon_uvd_resume(struct radeon_device *rdev);
  1393. int radeon_uvd_get_create_msg(struct radeon_device *rdev, int ring,
  1394. uint32_t handle, struct radeon_fence **fence);
  1395. int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring,
  1396. uint32_t handle, struct radeon_fence **fence);
  1397. void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo);
  1398. void radeon_uvd_free_handles(struct radeon_device *rdev,
  1399. struct drm_file *filp);
  1400. int radeon_uvd_cs_parse(struct radeon_cs_parser *parser);
  1401. void radeon_uvd_note_usage(struct radeon_device *rdev);
  1402. int radeon_uvd_calc_upll_dividers(struct radeon_device *rdev,
  1403. unsigned vclk, unsigned dclk,
  1404. unsigned vco_min, unsigned vco_max,
  1405. unsigned fb_factor, unsigned fb_mask,
  1406. unsigned pd_min, unsigned pd_max,
  1407. unsigned pd_even,
  1408. unsigned *optimal_fb_div,
  1409. unsigned *optimal_vclk_div,
  1410. unsigned *optimal_dclk_div);
  1411. int radeon_uvd_send_upll_ctlreq(struct radeon_device *rdev,
  1412. unsigned cg_upll_func_cntl);
  1413. struct r600_audio_pin {
  1414. int channels;
  1415. int rate;
  1416. int bits_per_sample;
  1417. u8 status_bits;
  1418. u8 category_code;
  1419. u32 offset;
  1420. bool connected;
  1421. u32 id;
  1422. };
  1423. struct r600_audio {
  1424. bool enabled;
  1425. struct r600_audio_pin pin[RADEON_MAX_AFMT_BLOCKS];
  1426. int num_pins;
  1427. };
  1428. /*
  1429. * Benchmarking
  1430. */
  1431. void radeon_benchmark(struct radeon_device *rdev, int test_number);
  1432. /*
  1433. * Testing
  1434. */
  1435. void radeon_test_moves(struct radeon_device *rdev);
  1436. void radeon_test_ring_sync(struct radeon_device *rdev,
  1437. struct radeon_ring *cpA,
  1438. struct radeon_ring *cpB);
  1439. void radeon_test_syncing(struct radeon_device *rdev);
  1440. /*
  1441. * Debugfs
  1442. */
  1443. struct radeon_debugfs {
  1444. struct drm_info_list *files;
  1445. unsigned num_files;
  1446. };
  1447. int radeon_debugfs_add_files(struct radeon_device *rdev,
  1448. struct drm_info_list *files,
  1449. unsigned nfiles);
  1450. int radeon_debugfs_fence_init(struct radeon_device *rdev);
  1451. /*
  1452. * ASIC ring specific functions.
  1453. */
  1454. struct radeon_asic_ring {
  1455. /* ring read/write ptr handling */
  1456. u32 (*get_rptr)(struct radeon_device *rdev, struct radeon_ring *ring);
  1457. u32 (*get_wptr)(struct radeon_device *rdev, struct radeon_ring *ring);
  1458. void (*set_wptr)(struct radeon_device *rdev, struct radeon_ring *ring);
  1459. /* validating and patching of IBs */
  1460. int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
  1461. int (*cs_parse)(struct radeon_cs_parser *p);
  1462. /* command emmit functions */
  1463. void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  1464. void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
  1465. void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
  1466. struct radeon_semaphore *semaphore, bool emit_wait);
  1467. void (*vm_flush)(struct radeon_device *rdev, int ridx, struct radeon_vm *vm);
  1468. /* testing functions */
  1469. int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1470. int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1471. bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
  1472. /* deprecated */
  1473. void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
  1474. };
  1475. /*
  1476. * ASIC specific functions.
  1477. */
  1478. struct radeon_asic {
  1479. int (*init)(struct radeon_device *rdev);
  1480. void (*fini)(struct radeon_device *rdev);
  1481. int (*resume)(struct radeon_device *rdev);
  1482. int (*suspend)(struct radeon_device *rdev);
  1483. void (*vga_set_state)(struct radeon_device *rdev, bool state);
  1484. int (*asic_reset)(struct radeon_device *rdev);
  1485. /* ioctl hw specific callback. Some hw might want to perform special
  1486. * operation on specific ioctl. For instance on wait idle some hw
  1487. * might want to perform and HDP flush through MMIO as it seems that
  1488. * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  1489. * through ring.
  1490. */
  1491. void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  1492. /* check if 3D engine is idle */
  1493. bool (*gui_idle)(struct radeon_device *rdev);
  1494. /* wait for mc_idle */
  1495. int (*mc_wait_for_idle)(struct radeon_device *rdev);
  1496. /* get the reference clock */
  1497. u32 (*get_xclk)(struct radeon_device *rdev);
  1498. /* get the gpu clock counter */
  1499. uint64_t (*get_gpu_clock_counter)(struct radeon_device *rdev);
  1500. /* gart */
  1501. struct {
  1502. void (*tlb_flush)(struct radeon_device *rdev);
  1503. int (*set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  1504. } gart;
  1505. struct {
  1506. int (*init)(struct radeon_device *rdev);
  1507. void (*fini)(struct radeon_device *rdev);
  1508. u32 pt_ring_index;
  1509. void (*set_page)(struct radeon_device *rdev,
  1510. struct radeon_ib *ib,
  1511. uint64_t pe,
  1512. uint64_t addr, unsigned count,
  1513. uint32_t incr, uint32_t flags);
  1514. } vm;
  1515. /* ring specific callbacks */
  1516. struct radeon_asic_ring *ring[RADEON_NUM_RINGS];
  1517. /* irqs */
  1518. struct {
  1519. int (*set)(struct radeon_device *rdev);
  1520. int (*process)(struct radeon_device *rdev);
  1521. } irq;
  1522. /* displays */
  1523. struct {
  1524. /* display watermarks */
  1525. void (*bandwidth_update)(struct radeon_device *rdev);
  1526. /* get frame count */
  1527. u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  1528. /* wait for vblank */
  1529. void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
  1530. /* set backlight level */
  1531. void (*set_backlight_level)(struct radeon_encoder *radeon_encoder, u8 level);
  1532. /* get backlight level */
  1533. u8 (*get_backlight_level)(struct radeon_encoder *radeon_encoder);
  1534. /* audio callbacks */
  1535. void (*hdmi_enable)(struct drm_encoder *encoder, bool enable);
  1536. void (*hdmi_setmode)(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1537. } display;
  1538. /* copy functions for bo handling */
  1539. struct {
  1540. int (*blit)(struct radeon_device *rdev,
  1541. uint64_t src_offset,
  1542. uint64_t dst_offset,
  1543. unsigned num_gpu_pages,
  1544. struct radeon_fence **fence);
  1545. u32 blit_ring_index;
  1546. int (*dma)(struct radeon_device *rdev,
  1547. uint64_t src_offset,
  1548. uint64_t dst_offset,
  1549. unsigned num_gpu_pages,
  1550. struct radeon_fence **fence);
  1551. u32 dma_ring_index;
  1552. /* method used for bo copy */
  1553. int (*copy)(struct radeon_device *rdev,
  1554. uint64_t src_offset,
  1555. uint64_t dst_offset,
  1556. unsigned num_gpu_pages,
  1557. struct radeon_fence **fence);
  1558. /* ring used for bo copies */
  1559. u32 copy_ring_index;
  1560. } copy;
  1561. /* surfaces */
  1562. struct {
  1563. int (*set_reg)(struct radeon_device *rdev, int reg,
  1564. uint32_t tiling_flags, uint32_t pitch,
  1565. uint32_t offset, uint32_t obj_size);
  1566. void (*clear_reg)(struct radeon_device *rdev, int reg);
  1567. } surface;
  1568. /* hotplug detect */
  1569. struct {
  1570. void (*init)(struct radeon_device *rdev);
  1571. void (*fini)(struct radeon_device *rdev);
  1572. bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1573. void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1574. } hpd;
  1575. /* static power management */
  1576. struct {
  1577. void (*misc)(struct radeon_device *rdev);
  1578. void (*prepare)(struct radeon_device *rdev);
  1579. void (*finish)(struct radeon_device *rdev);
  1580. void (*init_profile)(struct radeon_device *rdev);
  1581. void (*get_dynpm_state)(struct radeon_device *rdev);
  1582. uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  1583. void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  1584. uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  1585. void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  1586. int (*get_pcie_lanes)(struct radeon_device *rdev);
  1587. void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  1588. void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  1589. int (*set_uvd_clocks)(struct radeon_device *rdev, u32 vclk, u32 dclk);
  1590. int (*get_temperature)(struct radeon_device *rdev);
  1591. } pm;
  1592. /* dynamic power management */
  1593. struct {
  1594. int (*init)(struct radeon_device *rdev);
  1595. void (*setup_asic)(struct radeon_device *rdev);
  1596. int (*enable)(struct radeon_device *rdev);
  1597. void (*disable)(struct radeon_device *rdev);
  1598. int (*pre_set_power_state)(struct radeon_device *rdev);
  1599. int (*set_power_state)(struct radeon_device *rdev);
  1600. void (*post_set_power_state)(struct radeon_device *rdev);
  1601. void (*display_configuration_changed)(struct radeon_device *rdev);
  1602. void (*fini)(struct radeon_device *rdev);
  1603. u32 (*get_sclk)(struct radeon_device *rdev, bool low);
  1604. u32 (*get_mclk)(struct radeon_device *rdev, bool low);
  1605. void (*print_power_state)(struct radeon_device *rdev, struct radeon_ps *ps);
  1606. void (*debugfs_print_current_performance_level)(struct radeon_device *rdev, struct seq_file *m);
  1607. int (*force_performance_level)(struct radeon_device *rdev, enum radeon_dpm_forced_level level);
  1608. bool (*vblank_too_short)(struct radeon_device *rdev);
  1609. void (*powergate_uvd)(struct radeon_device *rdev, bool gate);
  1610. } dpm;
  1611. /* pageflipping */
  1612. struct {
  1613. void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  1614. u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  1615. void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  1616. } pflip;
  1617. };
  1618. /*
  1619. * Asic structures
  1620. */
  1621. struct r100_asic {
  1622. const unsigned *reg_safe_bm;
  1623. unsigned reg_safe_bm_size;
  1624. u32 hdp_cntl;
  1625. };
  1626. struct r300_asic {
  1627. const unsigned *reg_safe_bm;
  1628. unsigned reg_safe_bm_size;
  1629. u32 resync_scratch;
  1630. u32 hdp_cntl;
  1631. };
  1632. struct r600_asic {
  1633. unsigned max_pipes;
  1634. unsigned max_tile_pipes;
  1635. unsigned max_simds;
  1636. unsigned max_backends;
  1637. unsigned max_gprs;
  1638. unsigned max_threads;
  1639. unsigned max_stack_entries;
  1640. unsigned max_hw_contexts;
  1641. unsigned max_gs_threads;
  1642. unsigned sx_max_export_size;
  1643. unsigned sx_max_export_pos_size;
  1644. unsigned sx_max_export_smx_size;
  1645. unsigned sq_num_cf_insts;
  1646. unsigned tiling_nbanks;
  1647. unsigned tiling_npipes;
  1648. unsigned tiling_group_size;
  1649. unsigned tile_config;
  1650. unsigned backend_map;
  1651. };
  1652. struct rv770_asic {
  1653. unsigned max_pipes;
  1654. unsigned max_tile_pipes;
  1655. unsigned max_simds;
  1656. unsigned max_backends;
  1657. unsigned max_gprs;
  1658. unsigned max_threads;
  1659. unsigned max_stack_entries;
  1660. unsigned max_hw_contexts;
  1661. unsigned max_gs_threads;
  1662. unsigned sx_max_export_size;
  1663. unsigned sx_max_export_pos_size;
  1664. unsigned sx_max_export_smx_size;
  1665. unsigned sq_num_cf_insts;
  1666. unsigned sx_num_of_sets;
  1667. unsigned sc_prim_fifo_size;
  1668. unsigned sc_hiz_tile_fifo_size;
  1669. unsigned sc_earlyz_tile_fifo_fize;
  1670. unsigned tiling_nbanks;
  1671. unsigned tiling_npipes;
  1672. unsigned tiling_group_size;
  1673. unsigned tile_config;
  1674. unsigned backend_map;
  1675. };
  1676. struct evergreen_asic {
  1677. unsigned num_ses;
  1678. unsigned max_pipes;
  1679. unsigned max_tile_pipes;
  1680. unsigned max_simds;
  1681. unsigned max_backends;
  1682. unsigned max_gprs;
  1683. unsigned max_threads;
  1684. unsigned max_stack_entries;
  1685. unsigned max_hw_contexts;
  1686. unsigned max_gs_threads;
  1687. unsigned sx_max_export_size;
  1688. unsigned sx_max_export_pos_size;
  1689. unsigned sx_max_export_smx_size;
  1690. unsigned sq_num_cf_insts;
  1691. unsigned sx_num_of_sets;
  1692. unsigned sc_prim_fifo_size;
  1693. unsigned sc_hiz_tile_fifo_size;
  1694. unsigned sc_earlyz_tile_fifo_size;
  1695. unsigned tiling_nbanks;
  1696. unsigned tiling_npipes;
  1697. unsigned tiling_group_size;
  1698. unsigned tile_config;
  1699. unsigned backend_map;
  1700. };
  1701. struct cayman_asic {
  1702. unsigned max_shader_engines;
  1703. unsigned max_pipes_per_simd;
  1704. unsigned max_tile_pipes;
  1705. unsigned max_simds_per_se;
  1706. unsigned max_backends_per_se;
  1707. unsigned max_texture_channel_caches;
  1708. unsigned max_gprs;
  1709. unsigned max_threads;
  1710. unsigned max_gs_threads;
  1711. unsigned max_stack_entries;
  1712. unsigned sx_num_of_sets;
  1713. unsigned sx_max_export_size;
  1714. unsigned sx_max_export_pos_size;
  1715. unsigned sx_max_export_smx_size;
  1716. unsigned max_hw_contexts;
  1717. unsigned sq_num_cf_insts;
  1718. unsigned sc_prim_fifo_size;
  1719. unsigned sc_hiz_tile_fifo_size;
  1720. unsigned sc_earlyz_tile_fifo_size;
  1721. unsigned num_shader_engines;
  1722. unsigned num_shader_pipes_per_simd;
  1723. unsigned num_tile_pipes;
  1724. unsigned num_simds_per_se;
  1725. unsigned num_backends_per_se;
  1726. unsigned backend_disable_mask_per_asic;
  1727. unsigned backend_map;
  1728. unsigned num_texture_channel_caches;
  1729. unsigned mem_max_burst_length_bytes;
  1730. unsigned mem_row_size_in_kb;
  1731. unsigned shader_engine_tile_size;
  1732. unsigned num_gpus;
  1733. unsigned multi_gpu_tile_size;
  1734. unsigned tile_config;
  1735. };
  1736. struct si_asic {
  1737. unsigned max_shader_engines;
  1738. unsigned max_tile_pipes;
  1739. unsigned max_cu_per_sh;
  1740. unsigned max_sh_per_se;
  1741. unsigned max_backends_per_se;
  1742. unsigned max_texture_channel_caches;
  1743. unsigned max_gprs;
  1744. unsigned max_gs_threads;
  1745. unsigned max_hw_contexts;
  1746. unsigned sc_prim_fifo_size_frontend;
  1747. unsigned sc_prim_fifo_size_backend;
  1748. unsigned sc_hiz_tile_fifo_size;
  1749. unsigned sc_earlyz_tile_fifo_size;
  1750. unsigned num_tile_pipes;
  1751. unsigned num_backends_per_se;
  1752. unsigned backend_disable_mask_per_asic;
  1753. unsigned backend_map;
  1754. unsigned num_texture_channel_caches;
  1755. unsigned mem_max_burst_length_bytes;
  1756. unsigned mem_row_size_in_kb;
  1757. unsigned shader_engine_tile_size;
  1758. unsigned num_gpus;
  1759. unsigned multi_gpu_tile_size;
  1760. unsigned tile_config;
  1761. uint32_t tile_mode_array[32];
  1762. };
  1763. struct cik_asic {
  1764. unsigned max_shader_engines;
  1765. unsigned max_tile_pipes;
  1766. unsigned max_cu_per_sh;
  1767. unsigned max_sh_per_se;
  1768. unsigned max_backends_per_se;
  1769. unsigned max_texture_channel_caches;
  1770. unsigned max_gprs;
  1771. unsigned max_gs_threads;
  1772. unsigned max_hw_contexts;
  1773. unsigned sc_prim_fifo_size_frontend;
  1774. unsigned sc_prim_fifo_size_backend;
  1775. unsigned sc_hiz_tile_fifo_size;
  1776. unsigned sc_earlyz_tile_fifo_size;
  1777. unsigned num_tile_pipes;
  1778. unsigned num_backends_per_se;
  1779. unsigned backend_disable_mask_per_asic;
  1780. unsigned backend_map;
  1781. unsigned num_texture_channel_caches;
  1782. unsigned mem_max_burst_length_bytes;
  1783. unsigned mem_row_size_in_kb;
  1784. unsigned shader_engine_tile_size;
  1785. unsigned num_gpus;
  1786. unsigned multi_gpu_tile_size;
  1787. unsigned tile_config;
  1788. uint32_t tile_mode_array[32];
  1789. };
  1790. union radeon_asic_config {
  1791. struct r300_asic r300;
  1792. struct r100_asic r100;
  1793. struct r600_asic r600;
  1794. struct rv770_asic rv770;
  1795. struct evergreen_asic evergreen;
  1796. struct cayman_asic cayman;
  1797. struct si_asic si;
  1798. struct cik_asic cik;
  1799. };
  1800. /*
  1801. * asic initizalization from radeon_asic.c
  1802. */
  1803. void radeon_agp_disable(struct radeon_device *rdev);
  1804. int radeon_asic_init(struct radeon_device *rdev);
  1805. /*
  1806. * IOCTL.
  1807. */
  1808. int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
  1809. struct drm_file *filp);
  1810. int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
  1811. struct drm_file *filp);
  1812. int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
  1813. struct drm_file *file_priv);
  1814. int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1815. struct drm_file *file_priv);
  1816. int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1817. struct drm_file *file_priv);
  1818. int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
  1819. struct drm_file *file_priv);
  1820. int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1821. struct drm_file *filp);
  1822. int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1823. struct drm_file *filp);
  1824. int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
  1825. struct drm_file *filp);
  1826. int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1827. struct drm_file *filp);
  1828. int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
  1829. struct drm_file *filp);
  1830. int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1831. int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  1832. struct drm_file *filp);
  1833. int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  1834. struct drm_file *filp);
  1835. /* VRAM scratch page for HDP bug, default vram page */
  1836. struct r600_vram_scratch {
  1837. struct radeon_bo *robj;
  1838. volatile uint32_t *ptr;
  1839. u64 gpu_addr;
  1840. };
  1841. /*
  1842. * ACPI
  1843. */
  1844. struct radeon_atif_notification_cfg {
  1845. bool enabled;
  1846. int command_code;
  1847. };
  1848. struct radeon_atif_notifications {
  1849. bool display_switch;
  1850. bool expansion_mode_change;
  1851. bool thermal_state;
  1852. bool forced_power_state;
  1853. bool system_power_state;
  1854. bool display_conf_change;
  1855. bool px_gfx_switch;
  1856. bool brightness_change;
  1857. bool dgpu_display_event;
  1858. };
  1859. struct radeon_atif_functions {
  1860. bool system_params;
  1861. bool sbios_requests;
  1862. bool select_active_disp;
  1863. bool lid_state;
  1864. bool get_tv_standard;
  1865. bool set_tv_standard;
  1866. bool get_panel_expansion_mode;
  1867. bool set_panel_expansion_mode;
  1868. bool temperature_change;
  1869. bool graphics_device_types;
  1870. };
  1871. struct radeon_atif {
  1872. struct radeon_atif_notifications notifications;
  1873. struct radeon_atif_functions functions;
  1874. struct radeon_atif_notification_cfg notification_cfg;
  1875. struct radeon_encoder *encoder_for_bl;
  1876. };
  1877. struct radeon_atcs_functions {
  1878. bool get_ext_state;
  1879. bool pcie_perf_req;
  1880. bool pcie_dev_rdy;
  1881. bool pcie_bus_width;
  1882. };
  1883. struct radeon_atcs {
  1884. struct radeon_atcs_functions functions;
  1885. };
  1886. /*
  1887. * Core structure, functions and helpers.
  1888. */
  1889. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1890. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1891. struct radeon_device {
  1892. struct device *dev;
  1893. struct drm_device *ddev;
  1894. struct pci_dev *pdev;
  1895. struct rw_semaphore exclusive_lock;
  1896. /* ASIC */
  1897. union radeon_asic_config config;
  1898. enum radeon_family family;
  1899. unsigned long flags;
  1900. int usec_timeout;
  1901. enum radeon_pll_errata pll_errata;
  1902. int num_gb_pipes;
  1903. int num_z_pipes;
  1904. int disp_priority;
  1905. /* BIOS */
  1906. uint8_t *bios;
  1907. bool is_atom_bios;
  1908. uint16_t bios_header_start;
  1909. struct radeon_bo *stollen_vga_memory;
  1910. /* Register mmio */
  1911. resource_size_t rmmio_base;
  1912. resource_size_t rmmio_size;
  1913. /* protects concurrent MM_INDEX/DATA based register access */
  1914. spinlock_t mmio_idx_lock;
  1915. void __iomem *rmmio;
  1916. radeon_rreg_t mc_rreg;
  1917. radeon_wreg_t mc_wreg;
  1918. radeon_rreg_t pll_rreg;
  1919. radeon_wreg_t pll_wreg;
  1920. uint32_t pcie_reg_mask;
  1921. radeon_rreg_t pciep_rreg;
  1922. radeon_wreg_t pciep_wreg;
  1923. /* io port */
  1924. void __iomem *rio_mem;
  1925. resource_size_t rio_mem_size;
  1926. struct radeon_clock clock;
  1927. struct radeon_mc mc;
  1928. struct radeon_gart gart;
  1929. struct radeon_mode_info mode_info;
  1930. struct radeon_scratch scratch;
  1931. struct radeon_doorbell doorbell;
  1932. struct radeon_mman mman;
  1933. struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS];
  1934. wait_queue_head_t fence_queue;
  1935. struct mutex ring_lock;
  1936. struct radeon_ring ring[RADEON_NUM_RINGS];
  1937. bool ib_pool_ready;
  1938. struct radeon_sa_manager ring_tmp_bo;
  1939. struct radeon_irq irq;
  1940. struct radeon_asic *asic;
  1941. struct radeon_gem gem;
  1942. struct radeon_pm pm;
  1943. struct radeon_uvd uvd;
  1944. uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1945. struct radeon_wb wb;
  1946. struct radeon_dummy_page dummy_page;
  1947. bool shutdown;
  1948. bool suspend;
  1949. bool need_dma32;
  1950. bool accel_working;
  1951. bool fastfb_working; /* IGP feature*/
  1952. struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1953. const struct firmware *me_fw; /* all family ME firmware */
  1954. const struct firmware *pfp_fw; /* r6/700 PFP firmware */
  1955. const struct firmware *rlc_fw; /* r6/700 RLC firmware */
  1956. const struct firmware *mc_fw; /* NI MC firmware */
  1957. const struct firmware *ce_fw; /* SI CE firmware */
  1958. const struct firmware *mec_fw; /* CIK MEC firmware */
  1959. const struct firmware *sdma_fw; /* CIK SDMA firmware */
  1960. const struct firmware *smc_fw; /* SMC firmware */
  1961. const struct firmware *uvd_fw; /* UVD firmware */
  1962. struct r600_vram_scratch vram_scratch;
  1963. int msi_enabled; /* msi enabled */
  1964. struct r600_ih ih; /* r6/700 interrupt ring */
  1965. struct radeon_rlc rlc;
  1966. struct radeon_mec mec;
  1967. struct work_struct hotplug_work;
  1968. struct work_struct audio_work;
  1969. struct work_struct reset_work;
  1970. int num_crtc; /* number of crtcs */
  1971. struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1972. bool has_uvd;
  1973. struct r600_audio audio; /* audio stuff */
  1974. struct notifier_block acpi_nb;
  1975. /* only one userspace can use Hyperz features or CMASK at a time */
  1976. struct drm_file *hyperz_filp;
  1977. struct drm_file *cmask_filp;
  1978. /* i2c buses */
  1979. struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1980. /* debugfs */
  1981. struct radeon_debugfs debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
  1982. unsigned debugfs_count;
  1983. /* virtual memory */
  1984. struct radeon_vm_manager vm_manager;
  1985. struct mutex gpu_clock_mutex;
  1986. /* ACPI interface */
  1987. struct radeon_atif atif;
  1988. struct radeon_atcs atcs;
  1989. /* srbm instance registers */
  1990. struct mutex srbm_mutex;
  1991. /* clock, powergating flags */
  1992. u32 cg_flags;
  1993. u32 pg_flags;
  1994. };
  1995. int radeon_device_init(struct radeon_device *rdev,
  1996. struct drm_device *ddev,
  1997. struct pci_dev *pdev,
  1998. uint32_t flags);
  1999. void radeon_device_fini(struct radeon_device *rdev);
  2000. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  2001. uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg,
  2002. bool always_indirect);
  2003. void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v,
  2004. bool always_indirect);
  2005. u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
  2006. void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
  2007. u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 offset);
  2008. void cik_mm_wdoorbell(struct radeon_device *rdev, u32 offset, u32 v);
  2009. /*
  2010. * Cast helper
  2011. */
  2012. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  2013. /*
  2014. * Registers read & write functions.
  2015. */
  2016. #define RREG8(reg) readb((rdev->rmmio) + (reg))
  2017. #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
  2018. #define RREG16(reg) readw((rdev->rmmio) + (reg))
  2019. #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
  2020. #define RREG32(reg) r100_mm_rreg(rdev, (reg), false)
  2021. #define RREG32_IDX(reg) r100_mm_rreg(rdev, (reg), true)
  2022. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg), false))
  2023. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v), false)
  2024. #define WREG32_IDX(reg, v) r100_mm_wreg(rdev, (reg), (v), true)
  2025. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  2026. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  2027. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  2028. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  2029. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  2030. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  2031. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  2032. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  2033. #define RREG32_PCIE_PORT(reg) rdev->pciep_rreg(rdev, (reg))
  2034. #define WREG32_PCIE_PORT(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  2035. #define RREG32_SMC(reg) tn_smc_rreg(rdev, (reg))
  2036. #define WREG32_SMC(reg, v) tn_smc_wreg(rdev, (reg), (v))
  2037. #define RREG32_RCU(reg) r600_rcu_rreg(rdev, (reg))
  2038. #define WREG32_RCU(reg, v) r600_rcu_wreg(rdev, (reg), (v))
  2039. #define RREG32_CG(reg) eg_cg_rreg(rdev, (reg))
  2040. #define WREG32_CG(reg, v) eg_cg_wreg(rdev, (reg), (v))
  2041. #define RREG32_PIF_PHY0(reg) eg_pif_phy0_rreg(rdev, (reg))
  2042. #define WREG32_PIF_PHY0(reg, v) eg_pif_phy0_wreg(rdev, (reg), (v))
  2043. #define RREG32_PIF_PHY1(reg) eg_pif_phy1_rreg(rdev, (reg))
  2044. #define WREG32_PIF_PHY1(reg, v) eg_pif_phy1_wreg(rdev, (reg), (v))
  2045. #define RREG32_UVD_CTX(reg) r600_uvd_ctx_rreg(rdev, (reg))
  2046. #define WREG32_UVD_CTX(reg, v) r600_uvd_ctx_wreg(rdev, (reg), (v))
  2047. #define RREG32_DIDT(reg) cik_didt_rreg(rdev, (reg))
  2048. #define WREG32_DIDT(reg, v) cik_didt_wreg(rdev, (reg), (v))
  2049. #define WREG32_P(reg, val, mask) \
  2050. do { \
  2051. uint32_t tmp_ = RREG32(reg); \
  2052. tmp_ &= (mask); \
  2053. tmp_ |= ((val) & ~(mask)); \
  2054. WREG32(reg, tmp_); \
  2055. } while (0)
  2056. #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
  2057. #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
  2058. #define WREG32_PLL_P(reg, val, mask) \
  2059. do { \
  2060. uint32_t tmp_ = RREG32_PLL(reg); \
  2061. tmp_ &= (mask); \
  2062. tmp_ |= ((val) & ~(mask)); \
  2063. WREG32_PLL(reg, tmp_); \
  2064. } while (0)
  2065. #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg), false))
  2066. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  2067. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  2068. #define RDOORBELL32(offset) cik_mm_rdoorbell(rdev, (offset))
  2069. #define WDOORBELL32(offset, v) cik_mm_wdoorbell(rdev, (offset), (v))
  2070. /*
  2071. * Indirect registers accessor
  2072. */
  2073. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  2074. {
  2075. uint32_t r;
  2076. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  2077. r = RREG32(RADEON_PCIE_DATA);
  2078. return r;
  2079. }
  2080. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  2081. {
  2082. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  2083. WREG32(RADEON_PCIE_DATA, (v));
  2084. }
  2085. static inline u32 tn_smc_rreg(struct radeon_device *rdev, u32 reg)
  2086. {
  2087. u32 r;
  2088. WREG32(TN_SMC_IND_INDEX_0, (reg));
  2089. r = RREG32(TN_SMC_IND_DATA_0);
  2090. return r;
  2091. }
  2092. static inline void tn_smc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2093. {
  2094. WREG32(TN_SMC_IND_INDEX_0, (reg));
  2095. WREG32(TN_SMC_IND_DATA_0, (v));
  2096. }
  2097. static inline u32 r600_rcu_rreg(struct radeon_device *rdev, u32 reg)
  2098. {
  2099. u32 r;
  2100. WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
  2101. r = RREG32(R600_RCU_DATA);
  2102. return r;
  2103. }
  2104. static inline void r600_rcu_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2105. {
  2106. WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
  2107. WREG32(R600_RCU_DATA, (v));
  2108. }
  2109. static inline u32 eg_cg_rreg(struct radeon_device *rdev, u32 reg)
  2110. {
  2111. u32 r;
  2112. WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
  2113. r = RREG32(EVERGREEN_CG_IND_DATA);
  2114. return r;
  2115. }
  2116. static inline void eg_cg_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2117. {
  2118. WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
  2119. WREG32(EVERGREEN_CG_IND_DATA, (v));
  2120. }
  2121. static inline u32 eg_pif_phy0_rreg(struct radeon_device *rdev, u32 reg)
  2122. {
  2123. u32 r;
  2124. WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
  2125. r = RREG32(EVERGREEN_PIF_PHY0_DATA);
  2126. return r;
  2127. }
  2128. static inline void eg_pif_phy0_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2129. {
  2130. WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
  2131. WREG32(EVERGREEN_PIF_PHY0_DATA, (v));
  2132. }
  2133. static inline u32 eg_pif_phy1_rreg(struct radeon_device *rdev, u32 reg)
  2134. {
  2135. u32 r;
  2136. WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
  2137. r = RREG32(EVERGREEN_PIF_PHY1_DATA);
  2138. return r;
  2139. }
  2140. static inline void eg_pif_phy1_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2141. {
  2142. WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
  2143. WREG32(EVERGREEN_PIF_PHY1_DATA, (v));
  2144. }
  2145. static inline u32 r600_uvd_ctx_rreg(struct radeon_device *rdev, u32 reg)
  2146. {
  2147. u32 r;
  2148. WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
  2149. r = RREG32(R600_UVD_CTX_DATA);
  2150. return r;
  2151. }
  2152. static inline void r600_uvd_ctx_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2153. {
  2154. WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
  2155. WREG32(R600_UVD_CTX_DATA, (v));
  2156. }
  2157. static inline u32 cik_didt_rreg(struct radeon_device *rdev, u32 reg)
  2158. {
  2159. u32 r;
  2160. WREG32(CIK_DIDT_IND_INDEX, (reg));
  2161. r = RREG32(CIK_DIDT_IND_DATA);
  2162. return r;
  2163. }
  2164. static inline void cik_didt_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2165. {
  2166. WREG32(CIK_DIDT_IND_INDEX, (reg));
  2167. WREG32(CIK_DIDT_IND_DATA, (v));
  2168. }
  2169. void r100_pll_errata_after_index(struct radeon_device *rdev);
  2170. /*
  2171. * ASICs helpers.
  2172. */
  2173. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  2174. (rdev->pdev->device == 0x5969))
  2175. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  2176. (rdev->family == CHIP_RV200) || \
  2177. (rdev->family == CHIP_RS100) || \
  2178. (rdev->family == CHIP_RS200) || \
  2179. (rdev->family == CHIP_RV250) || \
  2180. (rdev->family == CHIP_RV280) || \
  2181. (rdev->family == CHIP_RS300))
  2182. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
  2183. (rdev->family == CHIP_RV350) || \
  2184. (rdev->family == CHIP_R350) || \
  2185. (rdev->family == CHIP_RV380) || \
  2186. (rdev->family == CHIP_R420) || \
  2187. (rdev->family == CHIP_R423) || \
  2188. (rdev->family == CHIP_RV410) || \
  2189. (rdev->family == CHIP_RS400) || \
  2190. (rdev->family == CHIP_RS480))
  2191. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  2192. (rdev->ddev->pdev->device == 0x9443) || \
  2193. (rdev->ddev->pdev->device == 0x944B) || \
  2194. (rdev->ddev->pdev->device == 0x9506) || \
  2195. (rdev->ddev->pdev->device == 0x9509) || \
  2196. (rdev->ddev->pdev->device == 0x950F) || \
  2197. (rdev->ddev->pdev->device == 0x689C) || \
  2198. (rdev->ddev->pdev->device == 0x689D))
  2199. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  2200. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
  2201. (rdev->family == CHIP_RS690) || \
  2202. (rdev->family == CHIP_RS740) || \
  2203. (rdev->family >= CHIP_R600))
  2204. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  2205. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  2206. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  2207. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  2208. (rdev->flags & RADEON_IS_IGP))
  2209. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  2210. #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
  2211. #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
  2212. (rdev->flags & RADEON_IS_IGP))
  2213. #define ASIC_IS_DCE64(rdev) ((rdev->family == CHIP_OLAND))
  2214. #define ASIC_IS_NODCE(rdev) ((rdev->family == CHIP_HAINAN))
  2215. #define ASIC_IS_DCE8(rdev) ((rdev->family >= CHIP_BONAIRE))
  2216. #define ASIC_IS_LOMBOK(rdev) ((rdev->ddev->pdev->device == 0x6849) || \
  2217. (rdev->ddev->pdev->device == 0x6850) || \
  2218. (rdev->ddev->pdev->device == 0x6858) || \
  2219. (rdev->ddev->pdev->device == 0x6859) || \
  2220. (rdev->ddev->pdev->device == 0x6840) || \
  2221. (rdev->ddev->pdev->device == 0x6841) || \
  2222. (rdev->ddev->pdev->device == 0x6842) || \
  2223. (rdev->ddev->pdev->device == 0x6843))
  2224. /*
  2225. * BIOS helpers.
  2226. */
  2227. #define RBIOS8(i) (rdev->bios[i])
  2228. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  2229. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  2230. int radeon_combios_init(struct radeon_device *rdev);
  2231. void radeon_combios_fini(struct radeon_device *rdev);
  2232. int radeon_atombios_init(struct radeon_device *rdev);
  2233. void radeon_atombios_fini(struct radeon_device *rdev);
  2234. /*
  2235. * RING helpers.
  2236. */
  2237. #if DRM_DEBUG_CODE == 0
  2238. static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
  2239. {
  2240. ring->ring[ring->wptr++] = v;
  2241. ring->wptr &= ring->ptr_mask;
  2242. ring->count_dw--;
  2243. ring->ring_free_dw--;
  2244. }
  2245. #else
  2246. /* With debugging this is just too big to inline */
  2247. void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
  2248. #endif
  2249. /*
  2250. * ASICs macro.
  2251. */
  2252. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  2253. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  2254. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  2255. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  2256. #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)]->cs_parse((p))
  2257. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  2258. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  2259. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
  2260. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
  2261. #define radeon_asic_vm_init(rdev) (rdev)->asic->vm.init((rdev))
  2262. #define radeon_asic_vm_fini(rdev) (rdev)->asic->vm.fini((rdev))
  2263. #define radeon_asic_vm_set_page(rdev, ib, pe, addr, count, incr, flags) ((rdev)->asic->vm.set_page((rdev), (ib), (pe), (addr), (count), (incr), (flags)))
  2264. #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)]->ring_start((rdev), (cp))
  2265. #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)]->ring_test((rdev), (cp))
  2266. #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)]->ib_test((rdev), (cp))
  2267. #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)]->ib_execute((rdev), (ib))
  2268. #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)]->ib_parse((rdev), (ib))
  2269. #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)]->is_lockup((rdev), (cp))
  2270. #define radeon_ring_vm_flush(rdev, r, vm) (rdev)->asic->ring[(r)]->vm_flush((rdev), (r), (vm))
  2271. #define radeon_ring_get_rptr(rdev, r) (rdev)->asic->ring[(r)->idx]->get_rptr((rdev), (r))
  2272. #define radeon_ring_get_wptr(rdev, r) (rdev)->asic->ring[(r)->idx]->get_wptr((rdev), (r))
  2273. #define radeon_ring_set_wptr(rdev, r) (rdev)->asic->ring[(r)->idx]->set_wptr((rdev), (r))
  2274. #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
  2275. #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
  2276. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
  2277. #define radeon_set_backlight_level(rdev, e, l) (rdev)->asic->display.set_backlight_level((e), (l))
  2278. #define radeon_get_backlight_level(rdev, e) (rdev)->asic->display.get_backlight_level((e))
  2279. #define radeon_hdmi_enable(rdev, e, b) (rdev)->asic->display.hdmi_enable((e), (b))
  2280. #define radeon_hdmi_setmode(rdev, e, m) (rdev)->asic->display.hdmi_setmode((e), (m))
  2281. #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)]->emit_fence((rdev), (fence))
  2282. #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)]->emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
  2283. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
  2284. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (f))
  2285. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (f))
  2286. #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
  2287. #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
  2288. #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
  2289. #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
  2290. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
  2291. #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
  2292. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
  2293. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
  2294. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
  2295. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
  2296. #define radeon_set_uvd_clocks(rdev, v, d) (rdev)->asic->pm.set_uvd_clocks((rdev), (v), (d))
  2297. #define radeon_get_temperature(rdev) (rdev)->asic->pm.get_temperature((rdev))
  2298. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
  2299. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
  2300. #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
  2301. #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
  2302. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
  2303. #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
  2304. #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
  2305. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  2306. #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
  2307. #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
  2308. #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
  2309. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
  2310. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
  2311. #define radeon_pre_page_flip(rdev, crtc) (rdev)->asic->pflip.pre_page_flip((rdev), (crtc))
  2312. #define radeon_page_flip(rdev, crtc, base) (rdev)->asic->pflip.page_flip((rdev), (crtc), (base))
  2313. #define radeon_post_page_flip(rdev, crtc) (rdev)->asic->pflip.post_page_flip((rdev), (crtc))
  2314. #define radeon_wait_for_vblank(rdev, crtc) (rdev)->asic->display.wait_for_vblank((rdev), (crtc))
  2315. #define radeon_mc_wait_for_idle(rdev) (rdev)->asic->mc_wait_for_idle((rdev))
  2316. #define radeon_get_xclk(rdev) (rdev)->asic->get_xclk((rdev))
  2317. #define radeon_get_gpu_clock_counter(rdev) (rdev)->asic->get_gpu_clock_counter((rdev))
  2318. #define radeon_dpm_init(rdev) rdev->asic->dpm.init((rdev))
  2319. #define radeon_dpm_setup_asic(rdev) rdev->asic->dpm.setup_asic((rdev))
  2320. #define radeon_dpm_enable(rdev) rdev->asic->dpm.enable((rdev))
  2321. #define radeon_dpm_disable(rdev) rdev->asic->dpm.disable((rdev))
  2322. #define radeon_dpm_pre_set_power_state(rdev) rdev->asic->dpm.pre_set_power_state((rdev))
  2323. #define radeon_dpm_set_power_state(rdev) rdev->asic->dpm.set_power_state((rdev))
  2324. #define radeon_dpm_post_set_power_state(rdev) rdev->asic->dpm.post_set_power_state((rdev))
  2325. #define radeon_dpm_display_configuration_changed(rdev) rdev->asic->dpm.display_configuration_changed((rdev))
  2326. #define radeon_dpm_fini(rdev) rdev->asic->dpm.fini((rdev))
  2327. #define radeon_dpm_get_sclk(rdev, l) rdev->asic->dpm.get_sclk((rdev), (l))
  2328. #define radeon_dpm_get_mclk(rdev, l) rdev->asic->dpm.get_mclk((rdev), (l))
  2329. #define radeon_dpm_print_power_state(rdev, ps) rdev->asic->dpm.print_power_state((rdev), (ps))
  2330. #define radeon_dpm_debugfs_print_current_performance_level(rdev, m) rdev->asic->dpm.debugfs_print_current_performance_level((rdev), (m))
  2331. #define radeon_dpm_force_performance_level(rdev, l) rdev->asic->dpm.force_performance_level((rdev), (l))
  2332. #define radeon_dpm_vblank_too_short(rdev) rdev->asic->dpm.vblank_too_short((rdev))
  2333. #define radeon_dpm_powergate_uvd(rdev, g) rdev->asic->dpm.powergate_uvd((rdev), (g))
  2334. /* Common functions */
  2335. /* AGP */
  2336. extern int radeon_gpu_reset(struct radeon_device *rdev);
  2337. extern void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung);
  2338. extern void radeon_agp_disable(struct radeon_device *rdev);
  2339. extern int radeon_modeset_init(struct radeon_device *rdev);
  2340. extern void radeon_modeset_fini(struct radeon_device *rdev);
  2341. extern bool radeon_card_posted(struct radeon_device *rdev);
  2342. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  2343. extern void radeon_update_display_priority(struct radeon_device *rdev);
  2344. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  2345. extern void radeon_scratch_init(struct radeon_device *rdev);
  2346. extern void radeon_wb_fini(struct radeon_device *rdev);
  2347. extern int radeon_wb_init(struct radeon_device *rdev);
  2348. extern void radeon_wb_disable(struct radeon_device *rdev);
  2349. extern void radeon_surface_init(struct radeon_device *rdev);
  2350. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  2351. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  2352. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  2353. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  2354. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  2355. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  2356. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  2357. extern int radeon_resume_kms(struct drm_device *dev);
  2358. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  2359. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  2360. extern void radeon_program_register_sequence(struct radeon_device *rdev,
  2361. const u32 *registers,
  2362. const u32 array_size);
  2363. /*
  2364. * vm
  2365. */
  2366. int radeon_vm_manager_init(struct radeon_device *rdev);
  2367. void radeon_vm_manager_fini(struct radeon_device *rdev);
  2368. void radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
  2369. void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
  2370. int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm);
  2371. void radeon_vm_add_to_lru(struct radeon_device *rdev, struct radeon_vm *vm);
  2372. struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev,
  2373. struct radeon_vm *vm, int ring);
  2374. void radeon_vm_fence(struct radeon_device *rdev,
  2375. struct radeon_vm *vm,
  2376. struct radeon_fence *fence);
  2377. uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
  2378. int radeon_vm_bo_update_pte(struct radeon_device *rdev,
  2379. struct radeon_vm *vm,
  2380. struct radeon_bo *bo,
  2381. struct ttm_mem_reg *mem);
  2382. void radeon_vm_bo_invalidate(struct radeon_device *rdev,
  2383. struct radeon_bo *bo);
  2384. struct radeon_bo_va *radeon_vm_bo_find(struct radeon_vm *vm,
  2385. struct radeon_bo *bo);
  2386. struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev,
  2387. struct radeon_vm *vm,
  2388. struct radeon_bo *bo);
  2389. int radeon_vm_bo_set_addr(struct radeon_device *rdev,
  2390. struct radeon_bo_va *bo_va,
  2391. uint64_t offset,
  2392. uint32_t flags);
  2393. int radeon_vm_bo_rmv(struct radeon_device *rdev,
  2394. struct radeon_bo_va *bo_va);
  2395. /* audio */
  2396. void r600_audio_update_hdmi(struct work_struct *work);
  2397. struct r600_audio_pin *r600_audio_get_pin(struct radeon_device *rdev);
  2398. struct r600_audio_pin *dce6_audio_get_pin(struct radeon_device *rdev);
  2399. /*
  2400. * R600 vram scratch functions
  2401. */
  2402. int r600_vram_scratch_init(struct radeon_device *rdev);
  2403. void r600_vram_scratch_fini(struct radeon_device *rdev);
  2404. /*
  2405. * r600 cs checking helper
  2406. */
  2407. unsigned r600_mip_minify(unsigned size, unsigned level);
  2408. bool r600_fmt_is_valid_color(u32 format);
  2409. bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
  2410. int r600_fmt_get_blocksize(u32 format);
  2411. int r600_fmt_get_nblocksx(u32 format, u32 w);
  2412. int r600_fmt_get_nblocksy(u32 format, u32 h);
  2413. /*
  2414. * r600 functions used by radeon_encoder.c
  2415. */
  2416. struct radeon_hdmi_acr {
  2417. u32 clock;
  2418. int n_32khz;
  2419. int cts_32khz;
  2420. int n_44_1khz;
  2421. int cts_44_1khz;
  2422. int n_48khz;
  2423. int cts_48khz;
  2424. };
  2425. extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
  2426. extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
  2427. u32 tiling_pipe_num,
  2428. u32 max_rb_num,
  2429. u32 total_max_rb_num,
  2430. u32 enabled_rb_mask);
  2431. /*
  2432. * evergreen functions used by radeon_encoder.c
  2433. */
  2434. extern int ni_init_microcode(struct radeon_device *rdev);
  2435. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  2436. /* radeon_acpi.c */
  2437. #if defined(CONFIG_ACPI)
  2438. extern int radeon_acpi_init(struct radeon_device *rdev);
  2439. extern void radeon_acpi_fini(struct radeon_device *rdev);
  2440. extern bool radeon_acpi_is_pcie_performance_request_supported(struct radeon_device *rdev);
  2441. extern int radeon_acpi_pcie_performance_request(struct radeon_device *rdev,
  2442. u8 perf_req, bool advertise);
  2443. extern int radeon_acpi_pcie_notify_device_ready(struct radeon_device *rdev);
  2444. #else
  2445. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  2446. static inline void radeon_acpi_fini(struct radeon_device *rdev) { }
  2447. #endif
  2448. int radeon_cs_packet_parse(struct radeon_cs_parser *p,
  2449. struct radeon_cs_packet *pkt,
  2450. unsigned idx);
  2451. bool radeon_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p);
  2452. void radeon_cs_dump_packet(struct radeon_cs_parser *p,
  2453. struct radeon_cs_packet *pkt);
  2454. int radeon_cs_packet_next_reloc(struct radeon_cs_parser *p,
  2455. struct radeon_cs_reloc **cs_reloc,
  2456. int nomm);
  2457. int r600_cs_common_vline_parse(struct radeon_cs_parser *p,
  2458. uint32_t *vline_start_end,
  2459. uint32_t *vline_status);
  2460. #include "radeon_object.h"
  2461. #endif