radeon.h 80 KB

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