radeon.h 80 KB

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