radeon.h 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574
  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. };
  1221. void radeon_dpm_enable_power_state(struct radeon_device *rdev,
  1222. enum radeon_pm_state_type dpm_state);
  1223. struct radeon_pm {
  1224. struct mutex mutex;
  1225. /* write locked while reprogramming mclk */
  1226. struct rw_semaphore mclk_lock;
  1227. u32 active_crtcs;
  1228. int active_crtc_count;
  1229. int req_vblank;
  1230. bool vblank_sync;
  1231. fixed20_12 max_bandwidth;
  1232. fixed20_12 igp_sideport_mclk;
  1233. fixed20_12 igp_system_mclk;
  1234. fixed20_12 igp_ht_link_clk;
  1235. fixed20_12 igp_ht_link_width;
  1236. fixed20_12 k8_bandwidth;
  1237. fixed20_12 sideport_bandwidth;
  1238. fixed20_12 ht_bandwidth;
  1239. fixed20_12 core_bandwidth;
  1240. fixed20_12 sclk;
  1241. fixed20_12 mclk;
  1242. fixed20_12 needed_bandwidth;
  1243. struct radeon_power_state *power_state;
  1244. /* number of valid power states */
  1245. int num_power_states;
  1246. int current_power_state_index;
  1247. int current_clock_mode_index;
  1248. int requested_power_state_index;
  1249. int requested_clock_mode_index;
  1250. int default_power_state_index;
  1251. u32 current_sclk;
  1252. u32 current_mclk;
  1253. u16 current_vddc;
  1254. u16 current_vddci;
  1255. u32 default_sclk;
  1256. u32 default_mclk;
  1257. u16 default_vddc;
  1258. u16 default_vddci;
  1259. struct radeon_i2c_chan *i2c_bus;
  1260. /* selected pm method */
  1261. enum radeon_pm_method pm_method;
  1262. /* dynpm power management */
  1263. struct delayed_work dynpm_idle_work;
  1264. enum radeon_dynpm_state dynpm_state;
  1265. enum radeon_dynpm_action dynpm_planned_action;
  1266. unsigned long dynpm_action_timeout;
  1267. bool dynpm_can_upclock;
  1268. bool dynpm_can_downclock;
  1269. /* profile-based power management */
  1270. enum radeon_pm_profile_type profile;
  1271. int profile_index;
  1272. struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  1273. /* internal thermal controller on rv6xx+ */
  1274. enum radeon_int_thermal_type int_thermal_type;
  1275. struct device *int_hwmon_dev;
  1276. /* dpm */
  1277. bool dpm_enabled;
  1278. struct radeon_dpm dpm;
  1279. };
  1280. int radeon_pm_get_type_index(struct radeon_device *rdev,
  1281. enum radeon_pm_state_type ps_type,
  1282. int instance);
  1283. /*
  1284. * UVD
  1285. */
  1286. #define RADEON_MAX_UVD_HANDLES 10
  1287. #define RADEON_UVD_STACK_SIZE (1024*1024)
  1288. #define RADEON_UVD_HEAP_SIZE (1024*1024)
  1289. struct radeon_uvd {
  1290. struct radeon_bo *vcpu_bo;
  1291. void *cpu_addr;
  1292. uint64_t gpu_addr;
  1293. void *saved_bo;
  1294. atomic_t handles[RADEON_MAX_UVD_HANDLES];
  1295. struct drm_file *filp[RADEON_MAX_UVD_HANDLES];
  1296. struct delayed_work idle_work;
  1297. };
  1298. int radeon_uvd_init(struct radeon_device *rdev);
  1299. void radeon_uvd_fini(struct radeon_device *rdev);
  1300. int radeon_uvd_suspend(struct radeon_device *rdev);
  1301. int radeon_uvd_resume(struct radeon_device *rdev);
  1302. int radeon_uvd_get_create_msg(struct radeon_device *rdev, int ring,
  1303. uint32_t handle, struct radeon_fence **fence);
  1304. int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring,
  1305. uint32_t handle, struct radeon_fence **fence);
  1306. void radeon_uvd_force_into_uvd_segment(struct radeon_bo *rbo);
  1307. void radeon_uvd_free_handles(struct radeon_device *rdev,
  1308. struct drm_file *filp);
  1309. int radeon_uvd_cs_parse(struct radeon_cs_parser *parser);
  1310. void radeon_uvd_note_usage(struct radeon_device *rdev);
  1311. int radeon_uvd_calc_upll_dividers(struct radeon_device *rdev,
  1312. unsigned vclk, unsigned dclk,
  1313. unsigned vco_min, unsigned vco_max,
  1314. unsigned fb_factor, unsigned fb_mask,
  1315. unsigned pd_min, unsigned pd_max,
  1316. unsigned pd_even,
  1317. unsigned *optimal_fb_div,
  1318. unsigned *optimal_vclk_div,
  1319. unsigned *optimal_dclk_div);
  1320. int radeon_uvd_send_upll_ctlreq(struct radeon_device *rdev,
  1321. unsigned cg_upll_func_cntl);
  1322. struct r600_audio {
  1323. int channels;
  1324. int rate;
  1325. int bits_per_sample;
  1326. u8 status_bits;
  1327. u8 category_code;
  1328. };
  1329. /*
  1330. * Benchmarking
  1331. */
  1332. void radeon_benchmark(struct radeon_device *rdev, int test_number);
  1333. /*
  1334. * Testing
  1335. */
  1336. void radeon_test_moves(struct radeon_device *rdev);
  1337. void radeon_test_ring_sync(struct radeon_device *rdev,
  1338. struct radeon_ring *cpA,
  1339. struct radeon_ring *cpB);
  1340. void radeon_test_syncing(struct radeon_device *rdev);
  1341. /*
  1342. * Debugfs
  1343. */
  1344. struct radeon_debugfs {
  1345. struct drm_info_list *files;
  1346. unsigned num_files;
  1347. };
  1348. int radeon_debugfs_add_files(struct radeon_device *rdev,
  1349. struct drm_info_list *files,
  1350. unsigned nfiles);
  1351. int radeon_debugfs_fence_init(struct radeon_device *rdev);
  1352. /*
  1353. * ASIC specific functions.
  1354. */
  1355. struct radeon_asic {
  1356. int (*init)(struct radeon_device *rdev);
  1357. void (*fini)(struct radeon_device *rdev);
  1358. int (*resume)(struct radeon_device *rdev);
  1359. int (*suspend)(struct radeon_device *rdev);
  1360. void (*vga_set_state)(struct radeon_device *rdev, bool state);
  1361. int (*asic_reset)(struct radeon_device *rdev);
  1362. /* ioctl hw specific callback. Some hw might want to perform special
  1363. * operation on specific ioctl. For instance on wait idle some hw
  1364. * might want to perform and HDP flush through MMIO as it seems that
  1365. * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  1366. * through ring.
  1367. */
  1368. void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  1369. /* check if 3D engine is idle */
  1370. bool (*gui_idle)(struct radeon_device *rdev);
  1371. /* wait for mc_idle */
  1372. int (*mc_wait_for_idle)(struct radeon_device *rdev);
  1373. /* get the reference clock */
  1374. u32 (*get_xclk)(struct radeon_device *rdev);
  1375. /* get the gpu clock counter */
  1376. uint64_t (*get_gpu_clock_counter)(struct radeon_device *rdev);
  1377. /* gart */
  1378. struct {
  1379. void (*tlb_flush)(struct radeon_device *rdev);
  1380. int (*set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  1381. } gart;
  1382. struct {
  1383. int (*init)(struct radeon_device *rdev);
  1384. void (*fini)(struct radeon_device *rdev);
  1385. u32 pt_ring_index;
  1386. void (*set_page)(struct radeon_device *rdev,
  1387. struct radeon_ib *ib,
  1388. uint64_t pe,
  1389. uint64_t addr, unsigned count,
  1390. uint32_t incr, uint32_t flags);
  1391. } vm;
  1392. /* ring specific callbacks */
  1393. struct {
  1394. void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  1395. int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
  1396. void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
  1397. void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
  1398. struct radeon_semaphore *semaphore, bool emit_wait);
  1399. int (*cs_parse)(struct radeon_cs_parser *p);
  1400. void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
  1401. int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1402. int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1403. bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
  1404. void (*vm_flush)(struct radeon_device *rdev, int ridx, struct radeon_vm *vm);
  1405. u32 (*get_rptr)(struct radeon_device *rdev, struct radeon_ring *ring);
  1406. u32 (*get_wptr)(struct radeon_device *rdev, struct radeon_ring *ring);
  1407. void (*set_wptr)(struct radeon_device *rdev, struct radeon_ring *ring);
  1408. } ring[RADEON_NUM_RINGS];
  1409. /* irqs */
  1410. struct {
  1411. int (*set)(struct radeon_device *rdev);
  1412. int (*process)(struct radeon_device *rdev);
  1413. } irq;
  1414. /* displays */
  1415. struct {
  1416. /* display watermarks */
  1417. void (*bandwidth_update)(struct radeon_device *rdev);
  1418. /* get frame count */
  1419. u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  1420. /* wait for vblank */
  1421. void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
  1422. /* set backlight level */
  1423. void (*set_backlight_level)(struct radeon_encoder *radeon_encoder, u8 level);
  1424. /* get backlight level */
  1425. u8 (*get_backlight_level)(struct radeon_encoder *radeon_encoder);
  1426. /* audio callbacks */
  1427. void (*hdmi_enable)(struct drm_encoder *encoder, bool enable);
  1428. void (*hdmi_setmode)(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1429. } display;
  1430. /* copy functions for bo handling */
  1431. struct {
  1432. int (*blit)(struct radeon_device *rdev,
  1433. uint64_t src_offset,
  1434. uint64_t dst_offset,
  1435. unsigned num_gpu_pages,
  1436. struct radeon_fence **fence);
  1437. u32 blit_ring_index;
  1438. int (*dma)(struct radeon_device *rdev,
  1439. uint64_t src_offset,
  1440. uint64_t dst_offset,
  1441. unsigned num_gpu_pages,
  1442. struct radeon_fence **fence);
  1443. u32 dma_ring_index;
  1444. /* method used for bo copy */
  1445. int (*copy)(struct radeon_device *rdev,
  1446. uint64_t src_offset,
  1447. uint64_t dst_offset,
  1448. unsigned num_gpu_pages,
  1449. struct radeon_fence **fence);
  1450. /* ring used for bo copies */
  1451. u32 copy_ring_index;
  1452. } copy;
  1453. /* surfaces */
  1454. struct {
  1455. int (*set_reg)(struct radeon_device *rdev, int reg,
  1456. uint32_t tiling_flags, uint32_t pitch,
  1457. uint32_t offset, uint32_t obj_size);
  1458. void (*clear_reg)(struct radeon_device *rdev, int reg);
  1459. } surface;
  1460. /* hotplug detect */
  1461. struct {
  1462. void (*init)(struct radeon_device *rdev);
  1463. void (*fini)(struct radeon_device *rdev);
  1464. bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1465. void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1466. } hpd;
  1467. /* static power management */
  1468. struct {
  1469. void (*misc)(struct radeon_device *rdev);
  1470. void (*prepare)(struct radeon_device *rdev);
  1471. void (*finish)(struct radeon_device *rdev);
  1472. void (*init_profile)(struct radeon_device *rdev);
  1473. void (*get_dynpm_state)(struct radeon_device *rdev);
  1474. uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  1475. void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  1476. uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  1477. void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  1478. int (*get_pcie_lanes)(struct radeon_device *rdev);
  1479. void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  1480. void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  1481. int (*set_uvd_clocks)(struct radeon_device *rdev, u32 vclk, u32 dclk);
  1482. int (*get_temperature)(struct radeon_device *rdev);
  1483. } pm;
  1484. /* dynamic power management */
  1485. struct {
  1486. int (*init)(struct radeon_device *rdev);
  1487. void (*setup_asic)(struct radeon_device *rdev);
  1488. int (*enable)(struct radeon_device *rdev);
  1489. void (*disable)(struct radeon_device *rdev);
  1490. int (*pre_set_power_state)(struct radeon_device *rdev);
  1491. int (*set_power_state)(struct radeon_device *rdev);
  1492. void (*post_set_power_state)(struct radeon_device *rdev);
  1493. void (*display_configuration_changed)(struct radeon_device *rdev);
  1494. void (*fini)(struct radeon_device *rdev);
  1495. u32 (*get_sclk)(struct radeon_device *rdev, bool low);
  1496. u32 (*get_mclk)(struct radeon_device *rdev, bool low);
  1497. void (*print_power_state)(struct radeon_device *rdev, struct radeon_ps *ps);
  1498. void (*debugfs_print_current_performance_level)(struct radeon_device *rdev, struct seq_file *m);
  1499. int (*force_performance_level)(struct radeon_device *rdev, enum radeon_dpm_forced_level level);
  1500. bool (*vblank_too_short)(struct radeon_device *rdev);
  1501. } dpm;
  1502. /* pageflipping */
  1503. struct {
  1504. void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  1505. u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  1506. void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  1507. } pflip;
  1508. };
  1509. /*
  1510. * Asic structures
  1511. */
  1512. struct r100_asic {
  1513. const unsigned *reg_safe_bm;
  1514. unsigned reg_safe_bm_size;
  1515. u32 hdp_cntl;
  1516. };
  1517. struct r300_asic {
  1518. const unsigned *reg_safe_bm;
  1519. unsigned reg_safe_bm_size;
  1520. u32 resync_scratch;
  1521. u32 hdp_cntl;
  1522. };
  1523. struct r600_asic {
  1524. unsigned max_pipes;
  1525. unsigned max_tile_pipes;
  1526. unsigned max_simds;
  1527. unsigned max_backends;
  1528. unsigned max_gprs;
  1529. unsigned max_threads;
  1530. unsigned max_stack_entries;
  1531. unsigned max_hw_contexts;
  1532. unsigned max_gs_threads;
  1533. unsigned sx_max_export_size;
  1534. unsigned sx_max_export_pos_size;
  1535. unsigned sx_max_export_smx_size;
  1536. unsigned sq_num_cf_insts;
  1537. unsigned tiling_nbanks;
  1538. unsigned tiling_npipes;
  1539. unsigned tiling_group_size;
  1540. unsigned tile_config;
  1541. unsigned backend_map;
  1542. };
  1543. struct rv770_asic {
  1544. unsigned max_pipes;
  1545. unsigned max_tile_pipes;
  1546. unsigned max_simds;
  1547. unsigned max_backends;
  1548. unsigned max_gprs;
  1549. unsigned max_threads;
  1550. unsigned max_stack_entries;
  1551. unsigned max_hw_contexts;
  1552. unsigned max_gs_threads;
  1553. unsigned sx_max_export_size;
  1554. unsigned sx_max_export_pos_size;
  1555. unsigned sx_max_export_smx_size;
  1556. unsigned sq_num_cf_insts;
  1557. unsigned sx_num_of_sets;
  1558. unsigned sc_prim_fifo_size;
  1559. unsigned sc_hiz_tile_fifo_size;
  1560. unsigned sc_earlyz_tile_fifo_fize;
  1561. unsigned tiling_nbanks;
  1562. unsigned tiling_npipes;
  1563. unsigned tiling_group_size;
  1564. unsigned tile_config;
  1565. unsigned backend_map;
  1566. };
  1567. struct evergreen_asic {
  1568. unsigned num_ses;
  1569. unsigned max_pipes;
  1570. unsigned max_tile_pipes;
  1571. unsigned max_simds;
  1572. unsigned max_backends;
  1573. unsigned max_gprs;
  1574. unsigned max_threads;
  1575. unsigned max_stack_entries;
  1576. unsigned max_hw_contexts;
  1577. unsigned max_gs_threads;
  1578. unsigned sx_max_export_size;
  1579. unsigned sx_max_export_pos_size;
  1580. unsigned sx_max_export_smx_size;
  1581. unsigned sq_num_cf_insts;
  1582. unsigned sx_num_of_sets;
  1583. unsigned sc_prim_fifo_size;
  1584. unsigned sc_hiz_tile_fifo_size;
  1585. unsigned sc_earlyz_tile_fifo_size;
  1586. unsigned tiling_nbanks;
  1587. unsigned tiling_npipes;
  1588. unsigned tiling_group_size;
  1589. unsigned tile_config;
  1590. unsigned backend_map;
  1591. };
  1592. struct cayman_asic {
  1593. unsigned max_shader_engines;
  1594. unsigned max_pipes_per_simd;
  1595. unsigned max_tile_pipes;
  1596. unsigned max_simds_per_se;
  1597. unsigned max_backends_per_se;
  1598. unsigned max_texture_channel_caches;
  1599. unsigned max_gprs;
  1600. unsigned max_threads;
  1601. unsigned max_gs_threads;
  1602. unsigned max_stack_entries;
  1603. unsigned sx_num_of_sets;
  1604. unsigned sx_max_export_size;
  1605. unsigned sx_max_export_pos_size;
  1606. unsigned sx_max_export_smx_size;
  1607. unsigned max_hw_contexts;
  1608. unsigned sq_num_cf_insts;
  1609. unsigned sc_prim_fifo_size;
  1610. unsigned sc_hiz_tile_fifo_size;
  1611. unsigned sc_earlyz_tile_fifo_size;
  1612. unsigned num_shader_engines;
  1613. unsigned num_shader_pipes_per_simd;
  1614. unsigned num_tile_pipes;
  1615. unsigned num_simds_per_se;
  1616. unsigned num_backends_per_se;
  1617. unsigned backend_disable_mask_per_asic;
  1618. unsigned backend_map;
  1619. unsigned num_texture_channel_caches;
  1620. unsigned mem_max_burst_length_bytes;
  1621. unsigned mem_row_size_in_kb;
  1622. unsigned shader_engine_tile_size;
  1623. unsigned num_gpus;
  1624. unsigned multi_gpu_tile_size;
  1625. unsigned tile_config;
  1626. };
  1627. struct si_asic {
  1628. unsigned max_shader_engines;
  1629. unsigned max_tile_pipes;
  1630. unsigned max_cu_per_sh;
  1631. unsigned max_sh_per_se;
  1632. unsigned max_backends_per_se;
  1633. unsigned max_texture_channel_caches;
  1634. unsigned max_gprs;
  1635. unsigned max_gs_threads;
  1636. unsigned max_hw_contexts;
  1637. unsigned sc_prim_fifo_size_frontend;
  1638. unsigned sc_prim_fifo_size_backend;
  1639. unsigned sc_hiz_tile_fifo_size;
  1640. unsigned sc_earlyz_tile_fifo_size;
  1641. unsigned num_tile_pipes;
  1642. unsigned num_backends_per_se;
  1643. unsigned backend_disable_mask_per_asic;
  1644. unsigned backend_map;
  1645. unsigned num_texture_channel_caches;
  1646. unsigned mem_max_burst_length_bytes;
  1647. unsigned mem_row_size_in_kb;
  1648. unsigned shader_engine_tile_size;
  1649. unsigned num_gpus;
  1650. unsigned multi_gpu_tile_size;
  1651. unsigned tile_config;
  1652. uint32_t tile_mode_array[32];
  1653. };
  1654. struct cik_asic {
  1655. unsigned max_shader_engines;
  1656. unsigned max_tile_pipes;
  1657. unsigned max_cu_per_sh;
  1658. unsigned max_sh_per_se;
  1659. unsigned max_backends_per_se;
  1660. unsigned max_texture_channel_caches;
  1661. unsigned max_gprs;
  1662. unsigned max_gs_threads;
  1663. unsigned max_hw_contexts;
  1664. unsigned sc_prim_fifo_size_frontend;
  1665. unsigned sc_prim_fifo_size_backend;
  1666. unsigned sc_hiz_tile_fifo_size;
  1667. unsigned sc_earlyz_tile_fifo_size;
  1668. unsigned num_tile_pipes;
  1669. unsigned num_backends_per_se;
  1670. unsigned backend_disable_mask_per_asic;
  1671. unsigned backend_map;
  1672. unsigned num_texture_channel_caches;
  1673. unsigned mem_max_burst_length_bytes;
  1674. unsigned mem_row_size_in_kb;
  1675. unsigned shader_engine_tile_size;
  1676. unsigned num_gpus;
  1677. unsigned multi_gpu_tile_size;
  1678. unsigned tile_config;
  1679. uint32_t tile_mode_array[32];
  1680. };
  1681. union radeon_asic_config {
  1682. struct r300_asic r300;
  1683. struct r100_asic r100;
  1684. struct r600_asic r600;
  1685. struct rv770_asic rv770;
  1686. struct evergreen_asic evergreen;
  1687. struct cayman_asic cayman;
  1688. struct si_asic si;
  1689. struct cik_asic cik;
  1690. };
  1691. /*
  1692. * asic initizalization from radeon_asic.c
  1693. */
  1694. void radeon_agp_disable(struct radeon_device *rdev);
  1695. int radeon_asic_init(struct radeon_device *rdev);
  1696. /*
  1697. * IOCTL.
  1698. */
  1699. int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
  1700. struct drm_file *filp);
  1701. int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
  1702. struct drm_file *filp);
  1703. int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
  1704. struct drm_file *file_priv);
  1705. int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1706. struct drm_file *file_priv);
  1707. int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1708. struct drm_file *file_priv);
  1709. int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
  1710. struct drm_file *file_priv);
  1711. int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1712. struct drm_file *filp);
  1713. int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1714. struct drm_file *filp);
  1715. int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
  1716. struct drm_file *filp);
  1717. int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1718. struct drm_file *filp);
  1719. int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
  1720. struct drm_file *filp);
  1721. int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1722. int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  1723. struct drm_file *filp);
  1724. int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  1725. struct drm_file *filp);
  1726. /* VRAM scratch page for HDP bug, default vram page */
  1727. struct r600_vram_scratch {
  1728. struct radeon_bo *robj;
  1729. volatile uint32_t *ptr;
  1730. u64 gpu_addr;
  1731. };
  1732. /*
  1733. * ACPI
  1734. */
  1735. struct radeon_atif_notification_cfg {
  1736. bool enabled;
  1737. int command_code;
  1738. };
  1739. struct radeon_atif_notifications {
  1740. bool display_switch;
  1741. bool expansion_mode_change;
  1742. bool thermal_state;
  1743. bool forced_power_state;
  1744. bool system_power_state;
  1745. bool display_conf_change;
  1746. bool px_gfx_switch;
  1747. bool brightness_change;
  1748. bool dgpu_display_event;
  1749. };
  1750. struct radeon_atif_functions {
  1751. bool system_params;
  1752. bool sbios_requests;
  1753. bool select_active_disp;
  1754. bool lid_state;
  1755. bool get_tv_standard;
  1756. bool set_tv_standard;
  1757. bool get_panel_expansion_mode;
  1758. bool set_panel_expansion_mode;
  1759. bool temperature_change;
  1760. bool graphics_device_types;
  1761. };
  1762. struct radeon_atif {
  1763. struct radeon_atif_notifications notifications;
  1764. struct radeon_atif_functions functions;
  1765. struct radeon_atif_notification_cfg notification_cfg;
  1766. struct radeon_encoder *encoder_for_bl;
  1767. };
  1768. struct radeon_atcs_functions {
  1769. bool get_ext_state;
  1770. bool pcie_perf_req;
  1771. bool pcie_dev_rdy;
  1772. bool pcie_bus_width;
  1773. };
  1774. struct radeon_atcs {
  1775. struct radeon_atcs_functions functions;
  1776. };
  1777. /*
  1778. * Core structure, functions and helpers.
  1779. */
  1780. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1781. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1782. struct radeon_device {
  1783. struct device *dev;
  1784. struct drm_device *ddev;
  1785. struct pci_dev *pdev;
  1786. struct rw_semaphore exclusive_lock;
  1787. /* ASIC */
  1788. union radeon_asic_config config;
  1789. enum radeon_family family;
  1790. unsigned long flags;
  1791. int usec_timeout;
  1792. enum radeon_pll_errata pll_errata;
  1793. int num_gb_pipes;
  1794. int num_z_pipes;
  1795. int disp_priority;
  1796. /* BIOS */
  1797. uint8_t *bios;
  1798. bool is_atom_bios;
  1799. uint16_t bios_header_start;
  1800. struct radeon_bo *stollen_vga_memory;
  1801. /* Register mmio */
  1802. resource_size_t rmmio_base;
  1803. resource_size_t rmmio_size;
  1804. /* protects concurrent MM_INDEX/DATA based register access */
  1805. spinlock_t mmio_idx_lock;
  1806. void __iomem *rmmio;
  1807. radeon_rreg_t mc_rreg;
  1808. radeon_wreg_t mc_wreg;
  1809. radeon_rreg_t pll_rreg;
  1810. radeon_wreg_t pll_wreg;
  1811. uint32_t pcie_reg_mask;
  1812. radeon_rreg_t pciep_rreg;
  1813. radeon_wreg_t pciep_wreg;
  1814. /* io port */
  1815. void __iomem *rio_mem;
  1816. resource_size_t rio_mem_size;
  1817. struct radeon_clock clock;
  1818. struct radeon_mc mc;
  1819. struct radeon_gart gart;
  1820. struct radeon_mode_info mode_info;
  1821. struct radeon_scratch scratch;
  1822. struct radeon_doorbell doorbell;
  1823. struct radeon_mman mman;
  1824. struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS];
  1825. wait_queue_head_t fence_queue;
  1826. struct mutex ring_lock;
  1827. struct radeon_ring ring[RADEON_NUM_RINGS];
  1828. bool ib_pool_ready;
  1829. struct radeon_sa_manager ring_tmp_bo;
  1830. struct radeon_irq irq;
  1831. struct radeon_asic *asic;
  1832. struct radeon_gem gem;
  1833. struct radeon_pm pm;
  1834. struct radeon_uvd uvd;
  1835. uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1836. struct radeon_wb wb;
  1837. struct radeon_dummy_page dummy_page;
  1838. bool shutdown;
  1839. bool suspend;
  1840. bool need_dma32;
  1841. bool accel_working;
  1842. bool fastfb_working; /* IGP feature*/
  1843. struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1844. const struct firmware *me_fw; /* all family ME firmware */
  1845. const struct firmware *pfp_fw; /* r6/700 PFP firmware */
  1846. const struct firmware *rlc_fw; /* r6/700 RLC firmware */
  1847. const struct firmware *mc_fw; /* NI MC firmware */
  1848. const struct firmware *ce_fw; /* SI CE firmware */
  1849. const struct firmware *mec_fw; /* CIK MEC firmware */
  1850. const struct firmware *sdma_fw; /* CIK SDMA firmware */
  1851. const struct firmware *smc_fw; /* SMC firmware */
  1852. const struct firmware *uvd_fw; /* UVD firmware */
  1853. struct r600_vram_scratch vram_scratch;
  1854. int msi_enabled; /* msi enabled */
  1855. struct r600_ih ih; /* r6/700 interrupt ring */
  1856. struct radeon_rlc rlc;
  1857. struct radeon_mec mec;
  1858. struct work_struct hotplug_work;
  1859. struct work_struct audio_work;
  1860. struct work_struct reset_work;
  1861. int num_crtc; /* number of crtcs */
  1862. struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1863. bool audio_enabled;
  1864. bool has_uvd;
  1865. struct r600_audio audio_status; /* audio stuff */
  1866. struct notifier_block acpi_nb;
  1867. /* only one userspace can use Hyperz features or CMASK at a time */
  1868. struct drm_file *hyperz_filp;
  1869. struct drm_file *cmask_filp;
  1870. /* i2c buses */
  1871. struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1872. /* debugfs */
  1873. struct radeon_debugfs debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
  1874. unsigned debugfs_count;
  1875. /* virtual memory */
  1876. struct radeon_vm_manager vm_manager;
  1877. struct mutex gpu_clock_mutex;
  1878. /* ACPI interface */
  1879. struct radeon_atif atif;
  1880. struct radeon_atcs atcs;
  1881. /* srbm instance registers */
  1882. struct mutex srbm_mutex;
  1883. };
  1884. int radeon_device_init(struct radeon_device *rdev,
  1885. struct drm_device *ddev,
  1886. struct pci_dev *pdev,
  1887. uint32_t flags);
  1888. void radeon_device_fini(struct radeon_device *rdev);
  1889. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  1890. uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg,
  1891. bool always_indirect);
  1892. void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v,
  1893. bool always_indirect);
  1894. u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
  1895. void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
  1896. u32 cik_mm_rdoorbell(struct radeon_device *rdev, u32 offset);
  1897. void cik_mm_wdoorbell(struct radeon_device *rdev, u32 offset, u32 v);
  1898. /*
  1899. * Cast helper
  1900. */
  1901. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  1902. /*
  1903. * Registers read & write functions.
  1904. */
  1905. #define RREG8(reg) readb((rdev->rmmio) + (reg))
  1906. #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
  1907. #define RREG16(reg) readw((rdev->rmmio) + (reg))
  1908. #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
  1909. #define RREG32(reg) r100_mm_rreg(rdev, (reg), false)
  1910. #define RREG32_IDX(reg) r100_mm_rreg(rdev, (reg), true)
  1911. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg), false))
  1912. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v), false)
  1913. #define WREG32_IDX(reg, v) r100_mm_wreg(rdev, (reg), (v), true)
  1914. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1915. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1916. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  1917. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  1918. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  1919. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  1920. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  1921. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  1922. #define RREG32_PCIE_PORT(reg) rdev->pciep_rreg(rdev, (reg))
  1923. #define WREG32_PCIE_PORT(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  1924. #define RREG32_SMC(reg) tn_smc_rreg(rdev, (reg))
  1925. #define WREG32_SMC(reg, v) tn_smc_wreg(rdev, (reg), (v))
  1926. #define RREG32_RCU(reg) r600_rcu_rreg(rdev, (reg))
  1927. #define WREG32_RCU(reg, v) r600_rcu_wreg(rdev, (reg), (v))
  1928. #define RREG32_CG(reg) eg_cg_rreg(rdev, (reg))
  1929. #define WREG32_CG(reg, v) eg_cg_wreg(rdev, (reg), (v))
  1930. #define RREG32_PIF_PHY0(reg) eg_pif_phy0_rreg(rdev, (reg))
  1931. #define WREG32_PIF_PHY0(reg, v) eg_pif_phy0_wreg(rdev, (reg), (v))
  1932. #define RREG32_PIF_PHY1(reg) eg_pif_phy1_rreg(rdev, (reg))
  1933. #define WREG32_PIF_PHY1(reg, v) eg_pif_phy1_wreg(rdev, (reg), (v))
  1934. #define RREG32_UVD_CTX(reg) r600_uvd_ctx_rreg(rdev, (reg))
  1935. #define WREG32_UVD_CTX(reg, v) r600_uvd_ctx_wreg(rdev, (reg), (v))
  1936. #define WREG32_P(reg, val, mask) \
  1937. do { \
  1938. uint32_t tmp_ = RREG32(reg); \
  1939. tmp_ &= (mask); \
  1940. tmp_ |= ((val) & ~(mask)); \
  1941. WREG32(reg, tmp_); \
  1942. } while (0)
  1943. #define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
  1944. #define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
  1945. #define WREG32_PLL_P(reg, val, mask) \
  1946. do { \
  1947. uint32_t tmp_ = RREG32_PLL(reg); \
  1948. tmp_ &= (mask); \
  1949. tmp_ |= ((val) & ~(mask)); \
  1950. WREG32_PLL(reg, tmp_); \
  1951. } while (0)
  1952. #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg), false))
  1953. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  1954. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  1955. #define RDOORBELL32(offset) cik_mm_rdoorbell(rdev, (offset))
  1956. #define WDOORBELL32(offset, v) cik_mm_wdoorbell(rdev, (offset), (v))
  1957. /*
  1958. * Indirect registers accessor
  1959. */
  1960. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  1961. {
  1962. uint32_t r;
  1963. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1964. r = RREG32(RADEON_PCIE_DATA);
  1965. return r;
  1966. }
  1967. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1968. {
  1969. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1970. WREG32(RADEON_PCIE_DATA, (v));
  1971. }
  1972. static inline u32 tn_smc_rreg(struct radeon_device *rdev, u32 reg)
  1973. {
  1974. u32 r;
  1975. WREG32(TN_SMC_IND_INDEX_0, (reg));
  1976. r = RREG32(TN_SMC_IND_DATA_0);
  1977. return r;
  1978. }
  1979. static inline void tn_smc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  1980. {
  1981. WREG32(TN_SMC_IND_INDEX_0, (reg));
  1982. WREG32(TN_SMC_IND_DATA_0, (v));
  1983. }
  1984. static inline u32 r600_rcu_rreg(struct radeon_device *rdev, u32 reg)
  1985. {
  1986. u32 r;
  1987. WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
  1988. r = RREG32(R600_RCU_DATA);
  1989. return r;
  1990. }
  1991. static inline void r600_rcu_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  1992. {
  1993. WREG32(R600_RCU_INDEX, ((reg) & 0x1fff));
  1994. WREG32(R600_RCU_DATA, (v));
  1995. }
  1996. static inline u32 eg_cg_rreg(struct radeon_device *rdev, u32 reg)
  1997. {
  1998. u32 r;
  1999. WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
  2000. r = RREG32(EVERGREEN_CG_IND_DATA);
  2001. return r;
  2002. }
  2003. static inline void eg_cg_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2004. {
  2005. WREG32(EVERGREEN_CG_IND_ADDR, ((reg) & 0xffff));
  2006. WREG32(EVERGREEN_CG_IND_DATA, (v));
  2007. }
  2008. static inline u32 eg_pif_phy0_rreg(struct radeon_device *rdev, u32 reg)
  2009. {
  2010. u32 r;
  2011. WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
  2012. r = RREG32(EVERGREEN_PIF_PHY0_DATA);
  2013. return r;
  2014. }
  2015. static inline void eg_pif_phy0_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2016. {
  2017. WREG32(EVERGREEN_PIF_PHY0_INDEX, ((reg) & 0xffff));
  2018. WREG32(EVERGREEN_PIF_PHY0_DATA, (v));
  2019. }
  2020. static inline u32 eg_pif_phy1_rreg(struct radeon_device *rdev, u32 reg)
  2021. {
  2022. u32 r;
  2023. WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
  2024. r = RREG32(EVERGREEN_PIF_PHY1_DATA);
  2025. return r;
  2026. }
  2027. static inline void eg_pif_phy1_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2028. {
  2029. WREG32(EVERGREEN_PIF_PHY1_INDEX, ((reg) & 0xffff));
  2030. WREG32(EVERGREEN_PIF_PHY1_DATA, (v));
  2031. }
  2032. static inline u32 r600_uvd_ctx_rreg(struct radeon_device *rdev, u32 reg)
  2033. {
  2034. u32 r;
  2035. WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
  2036. r = RREG32(R600_UVD_CTX_DATA);
  2037. return r;
  2038. }
  2039. static inline void r600_uvd_ctx_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  2040. {
  2041. WREG32(R600_UVD_CTX_INDEX, ((reg) & 0x1ff));
  2042. WREG32(R600_UVD_CTX_DATA, (v));
  2043. }
  2044. void r100_pll_errata_after_index(struct radeon_device *rdev);
  2045. /*
  2046. * ASICs helpers.
  2047. */
  2048. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  2049. (rdev->pdev->device == 0x5969))
  2050. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  2051. (rdev->family == CHIP_RV200) || \
  2052. (rdev->family == CHIP_RS100) || \
  2053. (rdev->family == CHIP_RS200) || \
  2054. (rdev->family == CHIP_RV250) || \
  2055. (rdev->family == CHIP_RV280) || \
  2056. (rdev->family == CHIP_RS300))
  2057. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
  2058. (rdev->family == CHIP_RV350) || \
  2059. (rdev->family == CHIP_R350) || \
  2060. (rdev->family == CHIP_RV380) || \
  2061. (rdev->family == CHIP_R420) || \
  2062. (rdev->family == CHIP_R423) || \
  2063. (rdev->family == CHIP_RV410) || \
  2064. (rdev->family == CHIP_RS400) || \
  2065. (rdev->family == CHIP_RS480))
  2066. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  2067. (rdev->ddev->pdev->device == 0x9443) || \
  2068. (rdev->ddev->pdev->device == 0x944B) || \
  2069. (rdev->ddev->pdev->device == 0x9506) || \
  2070. (rdev->ddev->pdev->device == 0x9509) || \
  2071. (rdev->ddev->pdev->device == 0x950F) || \
  2072. (rdev->ddev->pdev->device == 0x689C) || \
  2073. (rdev->ddev->pdev->device == 0x689D))
  2074. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  2075. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
  2076. (rdev->family == CHIP_RS690) || \
  2077. (rdev->family == CHIP_RS740) || \
  2078. (rdev->family >= CHIP_R600))
  2079. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  2080. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  2081. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  2082. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  2083. (rdev->flags & RADEON_IS_IGP))
  2084. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  2085. #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
  2086. #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
  2087. (rdev->flags & RADEON_IS_IGP))
  2088. #define ASIC_IS_DCE64(rdev) ((rdev->family == CHIP_OLAND))
  2089. #define ASIC_IS_NODCE(rdev) ((rdev->family == CHIP_HAINAN))
  2090. #define ASIC_IS_DCE8(rdev) ((rdev->family >= CHIP_BONAIRE))
  2091. #define ASIC_IS_LOMBOK(rdev) ((rdev->ddev->pdev->device == 0x6849) || \
  2092. (rdev->ddev->pdev->device == 0x6850) || \
  2093. (rdev->ddev->pdev->device == 0x6858) || \
  2094. (rdev->ddev->pdev->device == 0x6859) || \
  2095. (rdev->ddev->pdev->device == 0x6840) || \
  2096. (rdev->ddev->pdev->device == 0x6841) || \
  2097. (rdev->ddev->pdev->device == 0x6842) || \
  2098. (rdev->ddev->pdev->device == 0x6843))
  2099. /*
  2100. * BIOS helpers.
  2101. */
  2102. #define RBIOS8(i) (rdev->bios[i])
  2103. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  2104. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  2105. int radeon_combios_init(struct radeon_device *rdev);
  2106. void radeon_combios_fini(struct radeon_device *rdev);
  2107. int radeon_atombios_init(struct radeon_device *rdev);
  2108. void radeon_atombios_fini(struct radeon_device *rdev);
  2109. /*
  2110. * RING helpers.
  2111. */
  2112. #if DRM_DEBUG_CODE == 0
  2113. static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
  2114. {
  2115. ring->ring[ring->wptr++] = v;
  2116. ring->wptr &= ring->ptr_mask;
  2117. ring->count_dw--;
  2118. ring->ring_free_dw--;
  2119. }
  2120. #else
  2121. /* With debugging this is just too big to inline */
  2122. void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
  2123. #endif
  2124. /*
  2125. * ASICs macro.
  2126. */
  2127. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  2128. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  2129. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  2130. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  2131. #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)].cs_parse((p))
  2132. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  2133. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  2134. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
  2135. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
  2136. #define radeon_asic_vm_init(rdev) (rdev)->asic->vm.init((rdev))
  2137. #define radeon_asic_vm_fini(rdev) (rdev)->asic->vm.fini((rdev))
  2138. #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)))
  2139. #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)].ring_start((rdev), (cp))
  2140. #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)].ring_test((rdev), (cp))
  2141. #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp))
  2142. #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)].ib_execute((rdev), (ib))
  2143. #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)].ib_parse((rdev), (ib))
  2144. #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)].is_lockup((rdev), (cp))
  2145. #define radeon_ring_vm_flush(rdev, r, vm) (rdev)->asic->ring[(r)].vm_flush((rdev), (r), (vm))
  2146. #define radeon_ring_get_rptr(rdev, r) (rdev)->asic->ring[(r)->idx].get_rptr((rdev), (r))
  2147. #define radeon_ring_get_wptr(rdev, r) (rdev)->asic->ring[(r)->idx].get_wptr((rdev), (r))
  2148. #define radeon_ring_set_wptr(rdev, r) (rdev)->asic->ring[(r)->idx].set_wptr((rdev), (r))
  2149. #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
  2150. #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
  2151. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
  2152. #define radeon_set_backlight_level(rdev, e, l) (rdev)->asic->display.set_backlight_level((e), (l))
  2153. #define radeon_get_backlight_level(rdev, e) (rdev)->asic->display.get_backlight_level((e))
  2154. #define radeon_hdmi_enable(rdev, e, b) (rdev)->asic->display.hdmi_enable((e), (b))
  2155. #define radeon_hdmi_setmode(rdev, e, m) (rdev)->asic->display.hdmi_setmode((e), (m))
  2156. #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)].emit_fence((rdev), (fence))
  2157. #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)].emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
  2158. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
  2159. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (f))
  2160. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (f))
  2161. #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
  2162. #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
  2163. #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
  2164. #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
  2165. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
  2166. #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
  2167. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
  2168. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
  2169. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
  2170. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
  2171. #define radeon_set_uvd_clocks(rdev, v, d) (rdev)->asic->pm.set_uvd_clocks((rdev), (v), (d))
  2172. #define radeon_get_temperature(rdev) (rdev)->asic->pm.get_temperature((rdev))
  2173. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
  2174. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
  2175. #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
  2176. #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
  2177. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
  2178. #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
  2179. #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
  2180. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  2181. #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
  2182. #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
  2183. #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
  2184. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
  2185. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
  2186. #define radeon_pre_page_flip(rdev, crtc) (rdev)->asic->pflip.pre_page_flip((rdev), (crtc))
  2187. #define radeon_page_flip(rdev, crtc, base) (rdev)->asic->pflip.page_flip((rdev), (crtc), (base))
  2188. #define radeon_post_page_flip(rdev, crtc) (rdev)->asic->pflip.post_page_flip((rdev), (crtc))
  2189. #define radeon_wait_for_vblank(rdev, crtc) (rdev)->asic->display.wait_for_vblank((rdev), (crtc))
  2190. #define radeon_mc_wait_for_idle(rdev) (rdev)->asic->mc_wait_for_idle((rdev))
  2191. #define radeon_get_xclk(rdev) (rdev)->asic->get_xclk((rdev))
  2192. #define radeon_get_gpu_clock_counter(rdev) (rdev)->asic->get_gpu_clock_counter((rdev))
  2193. #define radeon_dpm_init(rdev) rdev->asic->dpm.init((rdev))
  2194. #define radeon_dpm_setup_asic(rdev) rdev->asic->dpm.setup_asic((rdev))
  2195. #define radeon_dpm_enable(rdev) rdev->asic->dpm.enable((rdev))
  2196. #define radeon_dpm_disable(rdev) rdev->asic->dpm.disable((rdev))
  2197. #define radeon_dpm_pre_set_power_state(rdev) rdev->asic->dpm.pre_set_power_state((rdev))
  2198. #define radeon_dpm_set_power_state(rdev) rdev->asic->dpm.set_power_state((rdev))
  2199. #define radeon_dpm_post_set_power_state(rdev) rdev->asic->dpm.post_set_power_state((rdev))
  2200. #define radeon_dpm_display_configuration_changed(rdev) rdev->asic->dpm.display_configuration_changed((rdev))
  2201. #define radeon_dpm_fini(rdev) rdev->asic->dpm.fini((rdev))
  2202. #define radeon_dpm_get_sclk(rdev, l) rdev->asic->dpm.get_sclk((rdev), (l))
  2203. #define radeon_dpm_get_mclk(rdev, l) rdev->asic->dpm.get_mclk((rdev), (l))
  2204. #define radeon_dpm_print_power_state(rdev, ps) rdev->asic->dpm.print_power_state((rdev), (ps))
  2205. #define radeon_dpm_debugfs_print_current_performance_level(rdev, m) rdev->asic->dpm.debugfs_print_current_performance_level((rdev), (m))
  2206. #define radeon_dpm_force_performance_level(rdev, l) rdev->asic->dpm.force_performance_level((rdev), (l))
  2207. #define radeon_dpm_vblank_too_short(rdev) rdev->asic->dpm.vblank_too_short((rdev))
  2208. /* Common functions */
  2209. /* AGP */
  2210. extern int radeon_gpu_reset(struct radeon_device *rdev);
  2211. extern void r600_set_bios_scratch_engine_hung(struct radeon_device *rdev, bool hung);
  2212. extern void radeon_agp_disable(struct radeon_device *rdev);
  2213. extern int radeon_modeset_init(struct radeon_device *rdev);
  2214. extern void radeon_modeset_fini(struct radeon_device *rdev);
  2215. extern bool radeon_card_posted(struct radeon_device *rdev);
  2216. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  2217. extern void radeon_update_display_priority(struct radeon_device *rdev);
  2218. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  2219. extern void radeon_scratch_init(struct radeon_device *rdev);
  2220. extern void radeon_wb_fini(struct radeon_device *rdev);
  2221. extern int radeon_wb_init(struct radeon_device *rdev);
  2222. extern void radeon_wb_disable(struct radeon_device *rdev);
  2223. extern void radeon_surface_init(struct radeon_device *rdev);
  2224. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  2225. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  2226. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  2227. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  2228. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  2229. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  2230. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  2231. extern int radeon_resume_kms(struct drm_device *dev);
  2232. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  2233. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  2234. extern void radeon_program_register_sequence(struct radeon_device *rdev,
  2235. const u32 *registers,
  2236. const u32 array_size);
  2237. /*
  2238. * vm
  2239. */
  2240. int radeon_vm_manager_init(struct radeon_device *rdev);
  2241. void radeon_vm_manager_fini(struct radeon_device *rdev);
  2242. void radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
  2243. void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
  2244. int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm);
  2245. void radeon_vm_add_to_lru(struct radeon_device *rdev, struct radeon_vm *vm);
  2246. struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev,
  2247. struct radeon_vm *vm, int ring);
  2248. void radeon_vm_fence(struct radeon_device *rdev,
  2249. struct radeon_vm *vm,
  2250. struct radeon_fence *fence);
  2251. uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
  2252. int radeon_vm_bo_update_pte(struct radeon_device *rdev,
  2253. struct radeon_vm *vm,
  2254. struct radeon_bo *bo,
  2255. struct ttm_mem_reg *mem);
  2256. void radeon_vm_bo_invalidate(struct radeon_device *rdev,
  2257. struct radeon_bo *bo);
  2258. struct radeon_bo_va *radeon_vm_bo_find(struct radeon_vm *vm,
  2259. struct radeon_bo *bo);
  2260. struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev,
  2261. struct radeon_vm *vm,
  2262. struct radeon_bo *bo);
  2263. int radeon_vm_bo_set_addr(struct radeon_device *rdev,
  2264. struct radeon_bo_va *bo_va,
  2265. uint64_t offset,
  2266. uint32_t flags);
  2267. int radeon_vm_bo_rmv(struct radeon_device *rdev,
  2268. struct radeon_bo_va *bo_va);
  2269. /* audio */
  2270. void r600_audio_update_hdmi(struct work_struct *work);
  2271. /*
  2272. * R600 vram scratch functions
  2273. */
  2274. int r600_vram_scratch_init(struct radeon_device *rdev);
  2275. void r600_vram_scratch_fini(struct radeon_device *rdev);
  2276. /*
  2277. * r600 cs checking helper
  2278. */
  2279. unsigned r600_mip_minify(unsigned size, unsigned level);
  2280. bool r600_fmt_is_valid_color(u32 format);
  2281. bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
  2282. int r600_fmt_get_blocksize(u32 format);
  2283. int r600_fmt_get_nblocksx(u32 format, u32 w);
  2284. int r600_fmt_get_nblocksy(u32 format, u32 h);
  2285. /*
  2286. * r600 functions used by radeon_encoder.c
  2287. */
  2288. struct radeon_hdmi_acr {
  2289. u32 clock;
  2290. int n_32khz;
  2291. int cts_32khz;
  2292. int n_44_1khz;
  2293. int cts_44_1khz;
  2294. int n_48khz;
  2295. int cts_48khz;
  2296. };
  2297. extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
  2298. extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
  2299. u32 tiling_pipe_num,
  2300. u32 max_rb_num,
  2301. u32 total_max_rb_num,
  2302. u32 enabled_rb_mask);
  2303. /*
  2304. * evergreen functions used by radeon_encoder.c
  2305. */
  2306. extern int ni_init_microcode(struct radeon_device *rdev);
  2307. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  2308. /* radeon_acpi.c */
  2309. #if defined(CONFIG_ACPI)
  2310. extern int radeon_acpi_init(struct radeon_device *rdev);
  2311. extern void radeon_acpi_fini(struct radeon_device *rdev);
  2312. extern bool radeon_acpi_is_pcie_performance_request_supported(struct radeon_device *rdev);
  2313. extern int radeon_acpi_pcie_performance_request(struct radeon_device *rdev,
  2314. u8 perf_req, bool advertise);
  2315. extern int radeon_acpi_pcie_notify_device_ready(struct radeon_device *rdev);
  2316. #else
  2317. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  2318. static inline void radeon_acpi_fini(struct radeon_device *rdev) { }
  2319. #endif
  2320. int radeon_cs_packet_parse(struct radeon_cs_parser *p,
  2321. struct radeon_cs_packet *pkt,
  2322. unsigned idx);
  2323. bool radeon_cs_packet_next_is_pkt3_nop(struct radeon_cs_parser *p);
  2324. void radeon_cs_dump_packet(struct radeon_cs_parser *p,
  2325. struct radeon_cs_packet *pkt);
  2326. int radeon_cs_packet_next_reloc(struct radeon_cs_parser *p,
  2327. struct radeon_cs_reloc **cs_reloc,
  2328. int nomm);
  2329. int r600_cs_common_vline_parse(struct radeon_cs_parser *p,
  2330. uint32_t *vline_start_end,
  2331. uint32_t *vline_status);
  2332. #include "radeon_object.h"
  2333. #endif