radeon.h 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971
  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. /*
  93. * Copy from radeon_drv.h so we don't have to include both and have conflicting
  94. * symbol;
  95. */
  96. #define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  97. #define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  98. /* RADEON_IB_POOL_SIZE must be a power of 2 */
  99. #define RADEON_IB_POOL_SIZE 16
  100. #define RADEON_DEBUGFS_MAX_COMPONENTS 32
  101. #define RADEONFB_CONN_LIMIT 4
  102. #define RADEON_BIOS_NUM_SCRATCH 8
  103. /* max number of rings */
  104. #define RADEON_NUM_RINGS 5
  105. /* fence seq are set to this number when signaled */
  106. #define RADEON_FENCE_SIGNALED_SEQ 0LL
  107. /* internal ring indices */
  108. /* r1xx+ has gfx CP ring */
  109. #define RADEON_RING_TYPE_GFX_INDEX 0
  110. /* cayman has 2 compute CP rings */
  111. #define CAYMAN_RING_TYPE_CP1_INDEX 1
  112. #define CAYMAN_RING_TYPE_CP2_INDEX 2
  113. /* R600+ has an async dma ring */
  114. #define R600_RING_TYPE_DMA_INDEX 3
  115. /* cayman add a second async dma ring */
  116. #define CAYMAN_RING_TYPE_DMA1_INDEX 4
  117. /* hardcode those limit for now */
  118. #define RADEON_VA_IB_OFFSET (1 << 20)
  119. #define RADEON_VA_RESERVED_SIZE (8 << 20)
  120. #define RADEON_IB_VM_MAX_SIZE (64 << 10)
  121. /*
  122. * Errata workarounds.
  123. */
  124. enum radeon_pll_errata {
  125. CHIP_ERRATA_R300_CG = 0x00000001,
  126. CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
  127. CHIP_ERRATA_PLL_DELAY = 0x00000004
  128. };
  129. struct radeon_device;
  130. /*
  131. * BIOS.
  132. */
  133. bool radeon_get_bios(struct radeon_device *rdev);
  134. /*
  135. * Dummy page
  136. */
  137. struct radeon_dummy_page {
  138. struct page *page;
  139. dma_addr_t addr;
  140. };
  141. int radeon_dummy_page_init(struct radeon_device *rdev);
  142. void radeon_dummy_page_fini(struct radeon_device *rdev);
  143. /*
  144. * Clocks
  145. */
  146. struct radeon_clock {
  147. struct radeon_pll p1pll;
  148. struct radeon_pll p2pll;
  149. struct radeon_pll dcpll;
  150. struct radeon_pll spll;
  151. struct radeon_pll mpll;
  152. /* 10 Khz units */
  153. uint32_t default_mclk;
  154. uint32_t default_sclk;
  155. uint32_t default_dispclk;
  156. uint32_t dp_extclk;
  157. uint32_t max_pixel_clock;
  158. };
  159. /*
  160. * Power management
  161. */
  162. int radeon_pm_init(struct radeon_device *rdev);
  163. void radeon_pm_fini(struct radeon_device *rdev);
  164. void radeon_pm_compute_clocks(struct radeon_device *rdev);
  165. void radeon_pm_suspend(struct radeon_device *rdev);
  166. void radeon_pm_resume(struct radeon_device *rdev);
  167. void radeon_combios_get_power_modes(struct radeon_device *rdev);
  168. void radeon_atombios_get_power_modes(struct radeon_device *rdev);
  169. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
  170. void rs690_pm_info(struct radeon_device *rdev);
  171. extern int rv6xx_get_temp(struct radeon_device *rdev);
  172. extern int rv770_get_temp(struct radeon_device *rdev);
  173. extern int evergreen_get_temp(struct radeon_device *rdev);
  174. extern int sumo_get_temp(struct radeon_device *rdev);
  175. extern int si_get_temp(struct radeon_device *rdev);
  176. extern void evergreen_tiling_fields(unsigned tiling_flags, unsigned *bankw,
  177. unsigned *bankh, unsigned *mtaspect,
  178. unsigned *tile_split);
  179. /*
  180. * Fences.
  181. */
  182. struct radeon_fence_driver {
  183. uint32_t scratch_reg;
  184. uint64_t gpu_addr;
  185. volatile uint32_t *cpu_addr;
  186. /* sync_seq is protected by ring emission lock */
  187. uint64_t sync_seq[RADEON_NUM_RINGS];
  188. atomic64_t last_seq;
  189. unsigned long last_activity;
  190. bool initialized;
  191. };
  192. struct radeon_fence {
  193. struct radeon_device *rdev;
  194. struct kref kref;
  195. /* protected by radeon_fence.lock */
  196. uint64_t seq;
  197. /* RB, DMA, etc. */
  198. unsigned ring;
  199. };
  200. int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring);
  201. int radeon_fence_driver_init(struct radeon_device *rdev);
  202. void radeon_fence_driver_fini(struct radeon_device *rdev);
  203. void radeon_fence_driver_force_completion(struct radeon_device *rdev);
  204. int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence **fence, int ring);
  205. void radeon_fence_process(struct radeon_device *rdev, int ring);
  206. bool radeon_fence_signaled(struct radeon_fence *fence);
  207. int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
  208. int radeon_fence_wait_next_locked(struct radeon_device *rdev, int ring);
  209. int radeon_fence_wait_empty_locked(struct radeon_device *rdev, int ring);
  210. int radeon_fence_wait_any(struct radeon_device *rdev,
  211. struct radeon_fence **fences,
  212. bool intr);
  213. struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
  214. void radeon_fence_unref(struct radeon_fence **fence);
  215. unsigned radeon_fence_count_emitted(struct radeon_device *rdev, int ring);
  216. bool radeon_fence_need_sync(struct radeon_fence *fence, int ring);
  217. void radeon_fence_note_sync(struct radeon_fence *fence, int ring);
  218. static inline struct radeon_fence *radeon_fence_later(struct radeon_fence *a,
  219. struct radeon_fence *b)
  220. {
  221. if (!a) {
  222. return b;
  223. }
  224. if (!b) {
  225. return a;
  226. }
  227. BUG_ON(a->ring != b->ring);
  228. if (a->seq > b->seq) {
  229. return a;
  230. } else {
  231. return b;
  232. }
  233. }
  234. static inline bool radeon_fence_is_earlier(struct radeon_fence *a,
  235. struct radeon_fence *b)
  236. {
  237. if (!a) {
  238. return false;
  239. }
  240. if (!b) {
  241. return true;
  242. }
  243. BUG_ON(a->ring != b->ring);
  244. return a->seq < b->seq;
  245. }
  246. /*
  247. * Tiling registers
  248. */
  249. struct radeon_surface_reg {
  250. struct radeon_bo *bo;
  251. };
  252. #define RADEON_GEM_MAX_SURFACES 8
  253. /*
  254. * TTM.
  255. */
  256. struct radeon_mman {
  257. struct ttm_bo_global_ref bo_global_ref;
  258. struct drm_global_reference mem_global_ref;
  259. struct ttm_bo_device bdev;
  260. bool mem_global_referenced;
  261. bool initialized;
  262. };
  263. /* bo virtual address in a specific vm */
  264. struct radeon_bo_va {
  265. /* protected by bo being reserved */
  266. struct list_head bo_list;
  267. uint64_t soffset;
  268. uint64_t eoffset;
  269. uint32_t flags;
  270. bool valid;
  271. unsigned ref_count;
  272. /* protected by vm mutex */
  273. struct list_head vm_list;
  274. /* constant after initialization */
  275. struct radeon_vm *vm;
  276. struct radeon_bo *bo;
  277. };
  278. struct radeon_bo {
  279. /* Protected by gem.mutex */
  280. struct list_head list;
  281. /* Protected by tbo.reserved */
  282. u32 placements[3];
  283. u32 busy_placements[3];
  284. struct ttm_placement placement;
  285. struct ttm_buffer_object tbo;
  286. struct ttm_bo_kmap_obj kmap;
  287. unsigned pin_count;
  288. void *kptr;
  289. u32 tiling_flags;
  290. u32 pitch;
  291. int surface_reg;
  292. /* list of all virtual address to which this bo
  293. * is associated to
  294. */
  295. struct list_head va;
  296. /* Constant after initialization */
  297. struct radeon_device *rdev;
  298. struct drm_gem_object gem_base;
  299. struct ttm_bo_kmap_obj dma_buf_vmap;
  300. int vmapping_count;
  301. };
  302. #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
  303. struct radeon_bo_list {
  304. struct ttm_validate_buffer tv;
  305. struct radeon_bo *bo;
  306. uint64_t gpu_offset;
  307. unsigned rdomain;
  308. unsigned wdomain;
  309. u32 tiling_flags;
  310. };
  311. /* sub-allocation manager, it has to be protected by another lock.
  312. * By conception this is an helper for other part of the driver
  313. * like the indirect buffer or semaphore, which both have their
  314. * locking.
  315. *
  316. * Principe is simple, we keep a list of sub allocation in offset
  317. * order (first entry has offset == 0, last entry has the highest
  318. * offset).
  319. *
  320. * When allocating new object we first check if there is room at
  321. * the end total_size - (last_object_offset + last_object_size) >=
  322. * alloc_size. If so we allocate new object there.
  323. *
  324. * When there is not enough room at the end, we start waiting for
  325. * each sub object until we reach object_offset+object_size >=
  326. * alloc_size, this object then become the sub object we return.
  327. *
  328. * Alignment can't be bigger than page size.
  329. *
  330. * Hole are not considered for allocation to keep things simple.
  331. * Assumption is that there won't be hole (all object on same
  332. * alignment).
  333. */
  334. struct radeon_sa_manager {
  335. wait_queue_head_t wq;
  336. struct radeon_bo *bo;
  337. struct list_head *hole;
  338. struct list_head flist[RADEON_NUM_RINGS];
  339. struct list_head olist;
  340. unsigned size;
  341. uint64_t gpu_addr;
  342. void *cpu_ptr;
  343. uint32_t domain;
  344. };
  345. struct radeon_sa_bo;
  346. /* sub-allocation buffer */
  347. struct radeon_sa_bo {
  348. struct list_head olist;
  349. struct list_head flist;
  350. struct radeon_sa_manager *manager;
  351. unsigned soffset;
  352. unsigned eoffset;
  353. struct radeon_fence *fence;
  354. };
  355. /*
  356. * GEM objects.
  357. */
  358. struct radeon_gem {
  359. struct mutex mutex;
  360. struct list_head objects;
  361. };
  362. int radeon_gem_init(struct radeon_device *rdev);
  363. void radeon_gem_fini(struct radeon_device *rdev);
  364. int radeon_gem_object_create(struct radeon_device *rdev, int size,
  365. int alignment, int initial_domain,
  366. bool discardable, bool kernel,
  367. struct drm_gem_object **obj);
  368. int radeon_mode_dumb_create(struct drm_file *file_priv,
  369. struct drm_device *dev,
  370. struct drm_mode_create_dumb *args);
  371. int radeon_mode_dumb_mmap(struct drm_file *filp,
  372. struct drm_device *dev,
  373. uint32_t handle, uint64_t *offset_p);
  374. int radeon_mode_dumb_destroy(struct drm_file *file_priv,
  375. struct drm_device *dev,
  376. uint32_t handle);
  377. /*
  378. * Semaphores.
  379. */
  380. /* everything here is constant */
  381. struct radeon_semaphore {
  382. struct radeon_sa_bo *sa_bo;
  383. signed waiters;
  384. uint64_t gpu_addr;
  385. };
  386. int radeon_semaphore_create(struct radeon_device *rdev,
  387. struct radeon_semaphore **semaphore);
  388. void radeon_semaphore_emit_signal(struct radeon_device *rdev, int ring,
  389. struct radeon_semaphore *semaphore);
  390. void radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
  391. struct radeon_semaphore *semaphore);
  392. int radeon_semaphore_sync_rings(struct radeon_device *rdev,
  393. struct radeon_semaphore *semaphore,
  394. int signaler, int waiter);
  395. void radeon_semaphore_free(struct radeon_device *rdev,
  396. struct radeon_semaphore **semaphore,
  397. struct radeon_fence *fence);
  398. /*
  399. * GART structures, functions & helpers
  400. */
  401. struct radeon_mc;
  402. #define RADEON_GPU_PAGE_SIZE 4096
  403. #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
  404. #define RADEON_GPU_PAGE_SHIFT 12
  405. #define RADEON_GPU_PAGE_ALIGN(a) (((a) + RADEON_GPU_PAGE_MASK) & ~RADEON_GPU_PAGE_MASK)
  406. struct radeon_gart {
  407. dma_addr_t table_addr;
  408. struct radeon_bo *robj;
  409. void *ptr;
  410. unsigned num_gpu_pages;
  411. unsigned num_cpu_pages;
  412. unsigned table_size;
  413. struct page **pages;
  414. dma_addr_t *pages_addr;
  415. bool ready;
  416. };
  417. int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
  418. void radeon_gart_table_ram_free(struct radeon_device *rdev);
  419. int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
  420. void radeon_gart_table_vram_free(struct radeon_device *rdev);
  421. int radeon_gart_table_vram_pin(struct radeon_device *rdev);
  422. void radeon_gart_table_vram_unpin(struct radeon_device *rdev);
  423. int radeon_gart_init(struct radeon_device *rdev);
  424. void radeon_gart_fini(struct radeon_device *rdev);
  425. void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
  426. int pages);
  427. int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
  428. int pages, struct page **pagelist,
  429. dma_addr_t *dma_addr);
  430. void radeon_gart_restore(struct radeon_device *rdev);
  431. /*
  432. * GPU MC structures, functions & helpers
  433. */
  434. struct radeon_mc {
  435. resource_size_t aper_size;
  436. resource_size_t aper_base;
  437. resource_size_t agp_base;
  438. /* for some chips with <= 32MB we need to lie
  439. * about vram size near mc fb location */
  440. u64 mc_vram_size;
  441. u64 visible_vram_size;
  442. u64 gtt_size;
  443. u64 gtt_start;
  444. u64 gtt_end;
  445. u64 vram_start;
  446. u64 vram_end;
  447. unsigned vram_width;
  448. u64 real_vram_size;
  449. int vram_mtrr;
  450. bool vram_is_ddr;
  451. bool igp_sideport_enabled;
  452. u64 gtt_base_align;
  453. };
  454. bool radeon_combios_sideport_present(struct radeon_device *rdev);
  455. bool radeon_atombios_sideport_present(struct radeon_device *rdev);
  456. /*
  457. * GPU scratch registers structures, functions & helpers
  458. */
  459. struct radeon_scratch {
  460. unsigned num_reg;
  461. uint32_t reg_base;
  462. bool free[32];
  463. uint32_t reg[32];
  464. };
  465. int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
  466. void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
  467. /*
  468. * IRQS.
  469. */
  470. struct radeon_unpin_work {
  471. struct work_struct work;
  472. struct radeon_device *rdev;
  473. int crtc_id;
  474. struct radeon_fence *fence;
  475. struct drm_pending_vblank_event *event;
  476. struct radeon_bo *old_rbo;
  477. u64 new_crtc_base;
  478. };
  479. struct r500_irq_stat_regs {
  480. u32 disp_int;
  481. u32 hdmi0_status;
  482. };
  483. struct r600_irq_stat_regs {
  484. u32 disp_int;
  485. u32 disp_int_cont;
  486. u32 disp_int_cont2;
  487. u32 d1grph_int;
  488. u32 d2grph_int;
  489. u32 hdmi0_status;
  490. u32 hdmi1_status;
  491. };
  492. struct evergreen_irq_stat_regs {
  493. u32 disp_int;
  494. u32 disp_int_cont;
  495. u32 disp_int_cont2;
  496. u32 disp_int_cont3;
  497. u32 disp_int_cont4;
  498. u32 disp_int_cont5;
  499. u32 d1grph_int;
  500. u32 d2grph_int;
  501. u32 d3grph_int;
  502. u32 d4grph_int;
  503. u32 d5grph_int;
  504. u32 d6grph_int;
  505. u32 afmt_status1;
  506. u32 afmt_status2;
  507. u32 afmt_status3;
  508. u32 afmt_status4;
  509. u32 afmt_status5;
  510. u32 afmt_status6;
  511. };
  512. union radeon_irq_stat_regs {
  513. struct r500_irq_stat_regs r500;
  514. struct r600_irq_stat_regs r600;
  515. struct evergreen_irq_stat_regs evergreen;
  516. };
  517. #define RADEON_MAX_HPD_PINS 6
  518. #define RADEON_MAX_CRTCS 6
  519. #define RADEON_MAX_AFMT_BLOCKS 6
  520. struct radeon_irq {
  521. bool installed;
  522. spinlock_t lock;
  523. atomic_t ring_int[RADEON_NUM_RINGS];
  524. bool crtc_vblank_int[RADEON_MAX_CRTCS];
  525. atomic_t pflip[RADEON_MAX_CRTCS];
  526. wait_queue_head_t vblank_queue;
  527. bool hpd[RADEON_MAX_HPD_PINS];
  528. bool afmt[RADEON_MAX_AFMT_BLOCKS];
  529. union radeon_irq_stat_regs stat_regs;
  530. };
  531. int radeon_irq_kms_init(struct radeon_device *rdev);
  532. void radeon_irq_kms_fini(struct radeon_device *rdev);
  533. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev, int ring);
  534. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev, int ring);
  535. void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
  536. void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
  537. void radeon_irq_kms_enable_afmt(struct radeon_device *rdev, int block);
  538. void radeon_irq_kms_disable_afmt(struct radeon_device *rdev, int block);
  539. void radeon_irq_kms_enable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
  540. void radeon_irq_kms_disable_hpd(struct radeon_device *rdev, unsigned hpd_mask);
  541. /*
  542. * CP & rings.
  543. */
  544. struct radeon_ib {
  545. struct radeon_sa_bo *sa_bo;
  546. uint32_t length_dw;
  547. uint64_t gpu_addr;
  548. uint32_t *ptr;
  549. int ring;
  550. struct radeon_fence *fence;
  551. struct radeon_vm *vm;
  552. bool is_const_ib;
  553. struct radeon_fence *sync_to[RADEON_NUM_RINGS];
  554. struct radeon_semaphore *semaphore;
  555. };
  556. struct radeon_ring {
  557. struct radeon_bo *ring_obj;
  558. volatile uint32_t *ring;
  559. unsigned rptr;
  560. unsigned rptr_offs;
  561. unsigned rptr_reg;
  562. unsigned rptr_save_reg;
  563. u64 next_rptr_gpu_addr;
  564. volatile u32 *next_rptr_cpu_addr;
  565. unsigned wptr;
  566. unsigned wptr_old;
  567. unsigned wptr_reg;
  568. unsigned ring_size;
  569. unsigned ring_free_dw;
  570. int count_dw;
  571. unsigned long last_activity;
  572. unsigned last_rptr;
  573. uint64_t gpu_addr;
  574. uint32_t align_mask;
  575. uint32_t ptr_mask;
  576. bool ready;
  577. u32 ptr_reg_shift;
  578. u32 ptr_reg_mask;
  579. u32 nop;
  580. u32 idx;
  581. };
  582. /*
  583. * VM
  584. */
  585. /* maximum number of VMIDs */
  586. #define RADEON_NUM_VM 16
  587. /* defines number of bits in page table versus page directory,
  588. * a page is 4KB so we have 12 bits offset, 9 bits in the page
  589. * table and the remaining 19 bits are in the page directory */
  590. #define RADEON_VM_BLOCK_SIZE 9
  591. /* number of entries in page table */
  592. #define RADEON_VM_PTE_COUNT (1 << RADEON_VM_BLOCK_SIZE)
  593. struct radeon_vm {
  594. struct list_head list;
  595. struct list_head va;
  596. unsigned id;
  597. /* contains the page directory */
  598. struct radeon_sa_bo *page_directory;
  599. uint64_t pd_gpu_addr;
  600. /* array of page tables, one for each page directory entry */
  601. struct radeon_sa_bo **page_tables;
  602. struct mutex mutex;
  603. /* last fence for cs using this vm */
  604. struct radeon_fence *fence;
  605. /* last flush or NULL if we still need to flush */
  606. struct radeon_fence *last_flush;
  607. };
  608. struct radeon_vm_manager {
  609. struct mutex lock;
  610. struct list_head lru_vm;
  611. struct radeon_fence *active[RADEON_NUM_VM];
  612. struct radeon_sa_manager sa_manager;
  613. uint32_t max_pfn;
  614. /* number of VMIDs */
  615. unsigned nvm;
  616. /* vram base address for page table entry */
  617. u64 vram_base_offset;
  618. /* is vm enabled? */
  619. bool enabled;
  620. };
  621. /*
  622. * file private structure
  623. */
  624. struct radeon_fpriv {
  625. struct radeon_vm vm;
  626. };
  627. /*
  628. * R6xx+ IH ring
  629. */
  630. struct r600_ih {
  631. struct radeon_bo *ring_obj;
  632. volatile uint32_t *ring;
  633. unsigned rptr;
  634. unsigned ring_size;
  635. uint64_t gpu_addr;
  636. uint32_t ptr_mask;
  637. atomic_t lock;
  638. bool enabled;
  639. };
  640. struct r600_blit_cp_primitives {
  641. void (*set_render_target)(struct radeon_device *rdev, int format,
  642. int w, int h, u64 gpu_addr);
  643. void (*cp_set_surface_sync)(struct radeon_device *rdev,
  644. u32 sync_type, u32 size,
  645. u64 mc_addr);
  646. void (*set_shaders)(struct radeon_device *rdev);
  647. void (*set_vtx_resource)(struct radeon_device *rdev, u64 gpu_addr);
  648. void (*set_tex_resource)(struct radeon_device *rdev,
  649. int format, int w, int h, int pitch,
  650. u64 gpu_addr, u32 size);
  651. void (*set_scissors)(struct radeon_device *rdev, int x1, int y1,
  652. int x2, int y2);
  653. void (*draw_auto)(struct radeon_device *rdev);
  654. void (*set_default_state)(struct radeon_device *rdev);
  655. };
  656. struct r600_blit {
  657. struct radeon_bo *shader_obj;
  658. struct r600_blit_cp_primitives primitives;
  659. int max_dim;
  660. int ring_size_common;
  661. int ring_size_per_loop;
  662. u64 shader_gpu_addr;
  663. u32 vs_offset, ps_offset;
  664. u32 state_offset;
  665. u32 state_len;
  666. };
  667. /*
  668. * SI RLC stuff
  669. */
  670. struct si_rlc {
  671. /* for power gating */
  672. struct radeon_bo *save_restore_obj;
  673. uint64_t save_restore_gpu_addr;
  674. /* for clear state */
  675. struct radeon_bo *clear_state_obj;
  676. uint64_t clear_state_gpu_addr;
  677. };
  678. int radeon_ib_get(struct radeon_device *rdev, int ring,
  679. struct radeon_ib *ib, struct radeon_vm *vm,
  680. unsigned size);
  681. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib);
  682. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib,
  683. struct radeon_ib *const_ib);
  684. int radeon_ib_pool_init(struct radeon_device *rdev);
  685. void radeon_ib_pool_fini(struct radeon_device *rdev);
  686. int radeon_ib_ring_tests(struct radeon_device *rdev);
  687. /* Ring access between begin & end cannot sleep */
  688. bool radeon_ring_supports_scratch_reg(struct radeon_device *rdev,
  689. struct radeon_ring *ring);
  690. void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
  691. int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  692. int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  693. void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  694. void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  695. void radeon_ring_undo(struct radeon_ring *ring);
  696. void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
  697. int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
  698. void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring);
  699. void radeon_ring_lockup_update(struct radeon_ring *ring);
  700. bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring);
  701. unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring,
  702. uint32_t **data);
  703. int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
  704. unsigned size, uint32_t *data);
  705. int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
  706. unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg,
  707. u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop);
  708. void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
  709. /* r600 async dma */
  710. void r600_dma_stop(struct radeon_device *rdev);
  711. int r600_dma_resume(struct radeon_device *rdev);
  712. void r600_dma_fini(struct radeon_device *rdev);
  713. void cayman_dma_stop(struct radeon_device *rdev);
  714. int cayman_dma_resume(struct radeon_device *rdev);
  715. void cayman_dma_fini(struct radeon_device *rdev);
  716. /*
  717. * CS.
  718. */
  719. struct radeon_cs_reloc {
  720. struct drm_gem_object *gobj;
  721. struct radeon_bo *robj;
  722. struct radeon_bo_list lobj;
  723. uint32_t handle;
  724. uint32_t flags;
  725. };
  726. struct radeon_cs_chunk {
  727. uint32_t chunk_id;
  728. uint32_t length_dw;
  729. int kpage_idx[2];
  730. uint32_t *kpage[2];
  731. uint32_t *kdata;
  732. void __user *user_ptr;
  733. int last_copied_page;
  734. int last_page_index;
  735. };
  736. struct radeon_cs_parser {
  737. struct device *dev;
  738. struct radeon_device *rdev;
  739. struct drm_file *filp;
  740. /* chunks */
  741. unsigned nchunks;
  742. struct radeon_cs_chunk *chunks;
  743. uint64_t *chunks_array;
  744. /* IB */
  745. unsigned idx;
  746. /* relocations */
  747. unsigned nrelocs;
  748. struct radeon_cs_reloc *relocs;
  749. struct radeon_cs_reloc **relocs_ptr;
  750. struct list_head validated;
  751. unsigned dma_reloc_idx;
  752. /* indices of various chunks */
  753. int chunk_ib_idx;
  754. int chunk_relocs_idx;
  755. int chunk_flags_idx;
  756. int chunk_const_ib_idx;
  757. struct radeon_ib ib;
  758. struct radeon_ib const_ib;
  759. void *track;
  760. unsigned family;
  761. int parser_error;
  762. u32 cs_flags;
  763. u32 ring;
  764. s32 priority;
  765. };
  766. extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
  767. extern u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx);
  768. struct radeon_cs_packet {
  769. unsigned idx;
  770. unsigned type;
  771. unsigned reg;
  772. unsigned opcode;
  773. int count;
  774. unsigned one_reg_wr;
  775. };
  776. typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
  777. struct radeon_cs_packet *pkt,
  778. unsigned idx, unsigned reg);
  779. typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
  780. struct radeon_cs_packet *pkt);
  781. /*
  782. * AGP
  783. */
  784. int radeon_agp_init(struct radeon_device *rdev);
  785. void radeon_agp_resume(struct radeon_device *rdev);
  786. void radeon_agp_suspend(struct radeon_device *rdev);
  787. void radeon_agp_fini(struct radeon_device *rdev);
  788. /*
  789. * Writeback
  790. */
  791. struct radeon_wb {
  792. struct radeon_bo *wb_obj;
  793. volatile uint32_t *wb;
  794. uint64_t gpu_addr;
  795. bool enabled;
  796. bool use_event;
  797. };
  798. #define RADEON_WB_SCRATCH_OFFSET 0
  799. #define RADEON_WB_RING0_NEXT_RPTR 256
  800. #define RADEON_WB_CP_RPTR_OFFSET 1024
  801. #define RADEON_WB_CP1_RPTR_OFFSET 1280
  802. #define RADEON_WB_CP2_RPTR_OFFSET 1536
  803. #define R600_WB_DMA_RPTR_OFFSET 1792
  804. #define R600_WB_IH_WPTR_OFFSET 2048
  805. #define CAYMAN_WB_DMA1_RPTR_OFFSET 2304
  806. #define R600_WB_EVENT_OFFSET 3072
  807. /**
  808. * struct radeon_pm - power management datas
  809. * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
  810. * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
  811. * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
  812. * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
  813. * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
  814. * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
  815. * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
  816. * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
  817. * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
  818. * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
  819. * @needed_bandwidth: current bandwidth needs
  820. *
  821. * It keeps track of various data needed to take powermanagement decision.
  822. * Bandwidth need is used to determine minimun clock of the GPU and memory.
  823. * Equation between gpu/memory clock and available bandwidth is hw dependent
  824. * (type of memory, bus size, efficiency, ...)
  825. */
  826. enum radeon_pm_method {
  827. PM_METHOD_PROFILE,
  828. PM_METHOD_DYNPM,
  829. };
  830. enum radeon_dynpm_state {
  831. DYNPM_STATE_DISABLED,
  832. DYNPM_STATE_MINIMUM,
  833. DYNPM_STATE_PAUSED,
  834. DYNPM_STATE_ACTIVE,
  835. DYNPM_STATE_SUSPENDED,
  836. };
  837. enum radeon_dynpm_action {
  838. DYNPM_ACTION_NONE,
  839. DYNPM_ACTION_MINIMUM,
  840. DYNPM_ACTION_DOWNCLOCK,
  841. DYNPM_ACTION_UPCLOCK,
  842. DYNPM_ACTION_DEFAULT
  843. };
  844. enum radeon_voltage_type {
  845. VOLTAGE_NONE = 0,
  846. VOLTAGE_GPIO,
  847. VOLTAGE_VDDC,
  848. VOLTAGE_SW
  849. };
  850. enum radeon_pm_state_type {
  851. POWER_STATE_TYPE_DEFAULT,
  852. POWER_STATE_TYPE_POWERSAVE,
  853. POWER_STATE_TYPE_BATTERY,
  854. POWER_STATE_TYPE_BALANCED,
  855. POWER_STATE_TYPE_PERFORMANCE,
  856. };
  857. enum radeon_pm_profile_type {
  858. PM_PROFILE_DEFAULT,
  859. PM_PROFILE_AUTO,
  860. PM_PROFILE_LOW,
  861. PM_PROFILE_MID,
  862. PM_PROFILE_HIGH,
  863. };
  864. #define PM_PROFILE_DEFAULT_IDX 0
  865. #define PM_PROFILE_LOW_SH_IDX 1
  866. #define PM_PROFILE_MID_SH_IDX 2
  867. #define PM_PROFILE_HIGH_SH_IDX 3
  868. #define PM_PROFILE_LOW_MH_IDX 4
  869. #define PM_PROFILE_MID_MH_IDX 5
  870. #define PM_PROFILE_HIGH_MH_IDX 6
  871. #define PM_PROFILE_MAX 7
  872. struct radeon_pm_profile {
  873. int dpms_off_ps_idx;
  874. int dpms_on_ps_idx;
  875. int dpms_off_cm_idx;
  876. int dpms_on_cm_idx;
  877. };
  878. enum radeon_int_thermal_type {
  879. THERMAL_TYPE_NONE,
  880. THERMAL_TYPE_RV6XX,
  881. THERMAL_TYPE_RV770,
  882. THERMAL_TYPE_EVERGREEN,
  883. THERMAL_TYPE_SUMO,
  884. THERMAL_TYPE_NI,
  885. THERMAL_TYPE_SI,
  886. };
  887. struct radeon_voltage {
  888. enum radeon_voltage_type type;
  889. /* gpio voltage */
  890. struct radeon_gpio_rec gpio;
  891. u32 delay; /* delay in usec from voltage drop to sclk change */
  892. bool active_high; /* voltage drop is active when bit is high */
  893. /* VDDC voltage */
  894. u8 vddc_id; /* index into vddc voltage table */
  895. u8 vddci_id; /* index into vddci voltage table */
  896. bool vddci_enabled;
  897. /* r6xx+ sw */
  898. u16 voltage;
  899. /* evergreen+ vddci */
  900. u16 vddci;
  901. };
  902. /* clock mode flags */
  903. #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
  904. struct radeon_pm_clock_info {
  905. /* memory clock */
  906. u32 mclk;
  907. /* engine clock */
  908. u32 sclk;
  909. /* voltage info */
  910. struct radeon_voltage voltage;
  911. /* standardized clock flags */
  912. u32 flags;
  913. };
  914. /* state flags */
  915. #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
  916. struct radeon_power_state {
  917. enum radeon_pm_state_type type;
  918. struct radeon_pm_clock_info *clock_info;
  919. /* number of valid clock modes in this power state */
  920. int num_clock_modes;
  921. struct radeon_pm_clock_info *default_clock_mode;
  922. /* standardized state flags */
  923. u32 flags;
  924. u32 misc; /* vbios specific flags */
  925. u32 misc2; /* vbios specific flags */
  926. int pcie_lanes; /* pcie lanes */
  927. };
  928. /*
  929. * Some modes are overclocked by very low value, accept them
  930. */
  931. #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
  932. struct radeon_pm {
  933. struct mutex mutex;
  934. /* write locked while reprogramming mclk */
  935. struct rw_semaphore mclk_lock;
  936. u32 active_crtcs;
  937. int active_crtc_count;
  938. int req_vblank;
  939. bool vblank_sync;
  940. fixed20_12 max_bandwidth;
  941. fixed20_12 igp_sideport_mclk;
  942. fixed20_12 igp_system_mclk;
  943. fixed20_12 igp_ht_link_clk;
  944. fixed20_12 igp_ht_link_width;
  945. fixed20_12 k8_bandwidth;
  946. fixed20_12 sideport_bandwidth;
  947. fixed20_12 ht_bandwidth;
  948. fixed20_12 core_bandwidth;
  949. fixed20_12 sclk;
  950. fixed20_12 mclk;
  951. fixed20_12 needed_bandwidth;
  952. struct radeon_power_state *power_state;
  953. /* number of valid power states */
  954. int num_power_states;
  955. int current_power_state_index;
  956. int current_clock_mode_index;
  957. int requested_power_state_index;
  958. int requested_clock_mode_index;
  959. int default_power_state_index;
  960. u32 current_sclk;
  961. u32 current_mclk;
  962. u16 current_vddc;
  963. u16 current_vddci;
  964. u32 default_sclk;
  965. u32 default_mclk;
  966. u16 default_vddc;
  967. u16 default_vddci;
  968. struct radeon_i2c_chan *i2c_bus;
  969. /* selected pm method */
  970. enum radeon_pm_method pm_method;
  971. /* dynpm power management */
  972. struct delayed_work dynpm_idle_work;
  973. enum radeon_dynpm_state dynpm_state;
  974. enum radeon_dynpm_action dynpm_planned_action;
  975. unsigned long dynpm_action_timeout;
  976. bool dynpm_can_upclock;
  977. bool dynpm_can_downclock;
  978. /* profile-based power management */
  979. enum radeon_pm_profile_type profile;
  980. int profile_index;
  981. struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  982. /* internal thermal controller on rv6xx+ */
  983. enum radeon_int_thermal_type int_thermal_type;
  984. struct device *int_hwmon_dev;
  985. };
  986. int radeon_pm_get_type_index(struct radeon_device *rdev,
  987. enum radeon_pm_state_type ps_type,
  988. int instance);
  989. struct r600_audio {
  990. int channels;
  991. int rate;
  992. int bits_per_sample;
  993. u8 status_bits;
  994. u8 category_code;
  995. };
  996. /*
  997. * Benchmarking
  998. */
  999. void radeon_benchmark(struct radeon_device *rdev, int test_number);
  1000. /*
  1001. * Testing
  1002. */
  1003. void radeon_test_moves(struct radeon_device *rdev);
  1004. void radeon_test_ring_sync(struct radeon_device *rdev,
  1005. struct radeon_ring *cpA,
  1006. struct radeon_ring *cpB);
  1007. void radeon_test_syncing(struct radeon_device *rdev);
  1008. /*
  1009. * Debugfs
  1010. */
  1011. struct radeon_debugfs {
  1012. struct drm_info_list *files;
  1013. unsigned num_files;
  1014. };
  1015. int radeon_debugfs_add_files(struct radeon_device *rdev,
  1016. struct drm_info_list *files,
  1017. unsigned nfiles);
  1018. int radeon_debugfs_fence_init(struct radeon_device *rdev);
  1019. /*
  1020. * ASIC specific functions.
  1021. */
  1022. struct radeon_asic {
  1023. int (*init)(struct radeon_device *rdev);
  1024. void (*fini)(struct radeon_device *rdev);
  1025. int (*resume)(struct radeon_device *rdev);
  1026. int (*suspend)(struct radeon_device *rdev);
  1027. void (*vga_set_state)(struct radeon_device *rdev, bool state);
  1028. int (*asic_reset)(struct radeon_device *rdev);
  1029. /* ioctl hw specific callback. Some hw might want to perform special
  1030. * operation on specific ioctl. For instance on wait idle some hw
  1031. * might want to perform and HDP flush through MMIO as it seems that
  1032. * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  1033. * through ring.
  1034. */
  1035. void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  1036. /* check if 3D engine is idle */
  1037. bool (*gui_idle)(struct radeon_device *rdev);
  1038. /* wait for mc_idle */
  1039. int (*mc_wait_for_idle)(struct radeon_device *rdev);
  1040. /* gart */
  1041. struct {
  1042. void (*tlb_flush)(struct radeon_device *rdev);
  1043. int (*set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  1044. } gart;
  1045. struct {
  1046. int (*init)(struct radeon_device *rdev);
  1047. void (*fini)(struct radeon_device *rdev);
  1048. u32 pt_ring_index;
  1049. void (*set_page)(struct radeon_device *rdev, uint64_t pe,
  1050. uint64_t addr, unsigned count,
  1051. uint32_t incr, uint32_t flags);
  1052. } vm;
  1053. /* ring specific callbacks */
  1054. struct {
  1055. void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  1056. int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
  1057. void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
  1058. void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
  1059. struct radeon_semaphore *semaphore, bool emit_wait);
  1060. int (*cs_parse)(struct radeon_cs_parser *p);
  1061. void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
  1062. int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1063. int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1064. bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
  1065. void (*vm_flush)(struct radeon_device *rdev, int ridx, struct radeon_vm *vm);
  1066. } ring[RADEON_NUM_RINGS];
  1067. /* irqs */
  1068. struct {
  1069. int (*set)(struct radeon_device *rdev);
  1070. int (*process)(struct radeon_device *rdev);
  1071. } irq;
  1072. /* displays */
  1073. struct {
  1074. /* display watermarks */
  1075. void (*bandwidth_update)(struct radeon_device *rdev);
  1076. /* get frame count */
  1077. u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  1078. /* wait for vblank */
  1079. void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
  1080. /* set backlight level */
  1081. void (*set_backlight_level)(struct radeon_encoder *radeon_encoder, u8 level);
  1082. /* get backlight level */
  1083. u8 (*get_backlight_level)(struct radeon_encoder *radeon_encoder);
  1084. } display;
  1085. /* copy functions for bo handling */
  1086. struct {
  1087. int (*blit)(struct radeon_device *rdev,
  1088. uint64_t src_offset,
  1089. uint64_t dst_offset,
  1090. unsigned num_gpu_pages,
  1091. struct radeon_fence **fence);
  1092. u32 blit_ring_index;
  1093. int (*dma)(struct radeon_device *rdev,
  1094. uint64_t src_offset,
  1095. uint64_t dst_offset,
  1096. unsigned num_gpu_pages,
  1097. struct radeon_fence **fence);
  1098. u32 dma_ring_index;
  1099. /* method used for bo copy */
  1100. int (*copy)(struct radeon_device *rdev,
  1101. uint64_t src_offset,
  1102. uint64_t dst_offset,
  1103. unsigned num_gpu_pages,
  1104. struct radeon_fence **fence);
  1105. /* ring used for bo copies */
  1106. u32 copy_ring_index;
  1107. } copy;
  1108. /* surfaces */
  1109. struct {
  1110. int (*set_reg)(struct radeon_device *rdev, int reg,
  1111. uint32_t tiling_flags, uint32_t pitch,
  1112. uint32_t offset, uint32_t obj_size);
  1113. void (*clear_reg)(struct radeon_device *rdev, int reg);
  1114. } surface;
  1115. /* hotplug detect */
  1116. struct {
  1117. void (*init)(struct radeon_device *rdev);
  1118. void (*fini)(struct radeon_device *rdev);
  1119. bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1120. void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1121. } hpd;
  1122. /* power management */
  1123. struct {
  1124. void (*misc)(struct radeon_device *rdev);
  1125. void (*prepare)(struct radeon_device *rdev);
  1126. void (*finish)(struct radeon_device *rdev);
  1127. void (*init_profile)(struct radeon_device *rdev);
  1128. void (*get_dynpm_state)(struct radeon_device *rdev);
  1129. uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  1130. void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  1131. uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  1132. void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  1133. int (*get_pcie_lanes)(struct radeon_device *rdev);
  1134. void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  1135. void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  1136. } pm;
  1137. /* pageflipping */
  1138. struct {
  1139. void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  1140. u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  1141. void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  1142. } pflip;
  1143. };
  1144. /*
  1145. * Asic structures
  1146. */
  1147. struct r100_asic {
  1148. const unsigned *reg_safe_bm;
  1149. unsigned reg_safe_bm_size;
  1150. u32 hdp_cntl;
  1151. };
  1152. struct r300_asic {
  1153. const unsigned *reg_safe_bm;
  1154. unsigned reg_safe_bm_size;
  1155. u32 resync_scratch;
  1156. u32 hdp_cntl;
  1157. };
  1158. struct r600_asic {
  1159. unsigned max_pipes;
  1160. unsigned max_tile_pipes;
  1161. unsigned max_simds;
  1162. unsigned max_backends;
  1163. unsigned max_gprs;
  1164. unsigned max_threads;
  1165. unsigned max_stack_entries;
  1166. unsigned max_hw_contexts;
  1167. unsigned max_gs_threads;
  1168. unsigned sx_max_export_size;
  1169. unsigned sx_max_export_pos_size;
  1170. unsigned sx_max_export_smx_size;
  1171. unsigned sq_num_cf_insts;
  1172. unsigned tiling_nbanks;
  1173. unsigned tiling_npipes;
  1174. unsigned tiling_group_size;
  1175. unsigned tile_config;
  1176. unsigned backend_map;
  1177. };
  1178. struct rv770_asic {
  1179. unsigned max_pipes;
  1180. unsigned max_tile_pipes;
  1181. unsigned max_simds;
  1182. unsigned max_backends;
  1183. unsigned max_gprs;
  1184. unsigned max_threads;
  1185. unsigned max_stack_entries;
  1186. unsigned max_hw_contexts;
  1187. unsigned max_gs_threads;
  1188. unsigned sx_max_export_size;
  1189. unsigned sx_max_export_pos_size;
  1190. unsigned sx_max_export_smx_size;
  1191. unsigned sq_num_cf_insts;
  1192. unsigned sx_num_of_sets;
  1193. unsigned sc_prim_fifo_size;
  1194. unsigned sc_hiz_tile_fifo_size;
  1195. unsigned sc_earlyz_tile_fifo_fize;
  1196. unsigned tiling_nbanks;
  1197. unsigned tiling_npipes;
  1198. unsigned tiling_group_size;
  1199. unsigned tile_config;
  1200. unsigned backend_map;
  1201. };
  1202. struct evergreen_asic {
  1203. unsigned num_ses;
  1204. unsigned max_pipes;
  1205. unsigned max_tile_pipes;
  1206. unsigned max_simds;
  1207. unsigned max_backends;
  1208. unsigned max_gprs;
  1209. unsigned max_threads;
  1210. unsigned max_stack_entries;
  1211. unsigned max_hw_contexts;
  1212. unsigned max_gs_threads;
  1213. unsigned sx_max_export_size;
  1214. unsigned sx_max_export_pos_size;
  1215. unsigned sx_max_export_smx_size;
  1216. unsigned sq_num_cf_insts;
  1217. unsigned sx_num_of_sets;
  1218. unsigned sc_prim_fifo_size;
  1219. unsigned sc_hiz_tile_fifo_size;
  1220. unsigned sc_earlyz_tile_fifo_size;
  1221. unsigned tiling_nbanks;
  1222. unsigned tiling_npipes;
  1223. unsigned tiling_group_size;
  1224. unsigned tile_config;
  1225. unsigned backend_map;
  1226. };
  1227. struct cayman_asic {
  1228. unsigned max_shader_engines;
  1229. unsigned max_pipes_per_simd;
  1230. unsigned max_tile_pipes;
  1231. unsigned max_simds_per_se;
  1232. unsigned max_backends_per_se;
  1233. unsigned max_texture_channel_caches;
  1234. unsigned max_gprs;
  1235. unsigned max_threads;
  1236. unsigned max_gs_threads;
  1237. unsigned max_stack_entries;
  1238. unsigned sx_num_of_sets;
  1239. unsigned sx_max_export_size;
  1240. unsigned sx_max_export_pos_size;
  1241. unsigned sx_max_export_smx_size;
  1242. unsigned max_hw_contexts;
  1243. unsigned sq_num_cf_insts;
  1244. unsigned sc_prim_fifo_size;
  1245. unsigned sc_hiz_tile_fifo_size;
  1246. unsigned sc_earlyz_tile_fifo_size;
  1247. unsigned num_shader_engines;
  1248. unsigned num_shader_pipes_per_simd;
  1249. unsigned num_tile_pipes;
  1250. unsigned num_simds_per_se;
  1251. unsigned num_backends_per_se;
  1252. unsigned backend_disable_mask_per_asic;
  1253. unsigned backend_map;
  1254. unsigned num_texture_channel_caches;
  1255. unsigned mem_max_burst_length_bytes;
  1256. unsigned mem_row_size_in_kb;
  1257. unsigned shader_engine_tile_size;
  1258. unsigned num_gpus;
  1259. unsigned multi_gpu_tile_size;
  1260. unsigned tile_config;
  1261. };
  1262. struct si_asic {
  1263. unsigned max_shader_engines;
  1264. unsigned max_tile_pipes;
  1265. unsigned max_cu_per_sh;
  1266. unsigned max_sh_per_se;
  1267. unsigned max_backends_per_se;
  1268. unsigned max_texture_channel_caches;
  1269. unsigned max_gprs;
  1270. unsigned max_gs_threads;
  1271. unsigned max_hw_contexts;
  1272. unsigned sc_prim_fifo_size_frontend;
  1273. unsigned sc_prim_fifo_size_backend;
  1274. unsigned sc_hiz_tile_fifo_size;
  1275. unsigned sc_earlyz_tile_fifo_size;
  1276. unsigned num_tile_pipes;
  1277. unsigned num_backends_per_se;
  1278. unsigned backend_disable_mask_per_asic;
  1279. unsigned backend_map;
  1280. unsigned num_texture_channel_caches;
  1281. unsigned mem_max_burst_length_bytes;
  1282. unsigned mem_row_size_in_kb;
  1283. unsigned shader_engine_tile_size;
  1284. unsigned num_gpus;
  1285. unsigned multi_gpu_tile_size;
  1286. unsigned tile_config;
  1287. };
  1288. union radeon_asic_config {
  1289. struct r300_asic r300;
  1290. struct r100_asic r100;
  1291. struct r600_asic r600;
  1292. struct rv770_asic rv770;
  1293. struct evergreen_asic evergreen;
  1294. struct cayman_asic cayman;
  1295. struct si_asic si;
  1296. };
  1297. /*
  1298. * asic initizalization from radeon_asic.c
  1299. */
  1300. void radeon_agp_disable(struct radeon_device *rdev);
  1301. int radeon_asic_init(struct radeon_device *rdev);
  1302. /*
  1303. * IOCTL.
  1304. */
  1305. int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
  1306. struct drm_file *filp);
  1307. int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
  1308. struct drm_file *filp);
  1309. int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
  1310. struct drm_file *file_priv);
  1311. int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1312. struct drm_file *file_priv);
  1313. int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1314. struct drm_file *file_priv);
  1315. int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
  1316. struct drm_file *file_priv);
  1317. int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1318. struct drm_file *filp);
  1319. int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1320. struct drm_file *filp);
  1321. int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
  1322. struct drm_file *filp);
  1323. int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1324. struct drm_file *filp);
  1325. int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
  1326. struct drm_file *filp);
  1327. int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1328. int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  1329. struct drm_file *filp);
  1330. int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  1331. struct drm_file *filp);
  1332. /* VRAM scratch page for HDP bug, default vram page */
  1333. struct r600_vram_scratch {
  1334. struct radeon_bo *robj;
  1335. volatile uint32_t *ptr;
  1336. u64 gpu_addr;
  1337. };
  1338. /*
  1339. * ACPI
  1340. */
  1341. struct radeon_atif_notification_cfg {
  1342. bool enabled;
  1343. int command_code;
  1344. };
  1345. struct radeon_atif_notifications {
  1346. bool display_switch;
  1347. bool expansion_mode_change;
  1348. bool thermal_state;
  1349. bool forced_power_state;
  1350. bool system_power_state;
  1351. bool display_conf_change;
  1352. bool px_gfx_switch;
  1353. bool brightness_change;
  1354. bool dgpu_display_event;
  1355. };
  1356. struct radeon_atif_functions {
  1357. bool system_params;
  1358. bool sbios_requests;
  1359. bool select_active_disp;
  1360. bool lid_state;
  1361. bool get_tv_standard;
  1362. bool set_tv_standard;
  1363. bool get_panel_expansion_mode;
  1364. bool set_panel_expansion_mode;
  1365. bool temperature_change;
  1366. bool graphics_device_types;
  1367. };
  1368. struct radeon_atif {
  1369. struct radeon_atif_notifications notifications;
  1370. struct radeon_atif_functions functions;
  1371. struct radeon_atif_notification_cfg notification_cfg;
  1372. struct radeon_encoder *encoder_for_bl;
  1373. };
  1374. struct radeon_atcs_functions {
  1375. bool get_ext_state;
  1376. bool pcie_perf_req;
  1377. bool pcie_dev_rdy;
  1378. bool pcie_bus_width;
  1379. };
  1380. struct radeon_atcs {
  1381. struct radeon_atcs_functions functions;
  1382. };
  1383. /*
  1384. * Core structure, functions and helpers.
  1385. */
  1386. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1387. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1388. struct radeon_device {
  1389. struct device *dev;
  1390. struct drm_device *ddev;
  1391. struct pci_dev *pdev;
  1392. struct rw_semaphore exclusive_lock;
  1393. /* ASIC */
  1394. union radeon_asic_config config;
  1395. enum radeon_family family;
  1396. unsigned long flags;
  1397. int usec_timeout;
  1398. enum radeon_pll_errata pll_errata;
  1399. int num_gb_pipes;
  1400. int num_z_pipes;
  1401. int disp_priority;
  1402. /* BIOS */
  1403. uint8_t *bios;
  1404. bool is_atom_bios;
  1405. uint16_t bios_header_start;
  1406. struct radeon_bo *stollen_vga_memory;
  1407. /* Register mmio */
  1408. resource_size_t rmmio_base;
  1409. resource_size_t rmmio_size;
  1410. /* protects concurrent MM_INDEX/DATA based register access */
  1411. spinlock_t mmio_idx_lock;
  1412. void __iomem *rmmio;
  1413. radeon_rreg_t mc_rreg;
  1414. radeon_wreg_t mc_wreg;
  1415. radeon_rreg_t pll_rreg;
  1416. radeon_wreg_t pll_wreg;
  1417. uint32_t pcie_reg_mask;
  1418. radeon_rreg_t pciep_rreg;
  1419. radeon_wreg_t pciep_wreg;
  1420. /* io port */
  1421. void __iomem *rio_mem;
  1422. resource_size_t rio_mem_size;
  1423. struct radeon_clock clock;
  1424. struct radeon_mc mc;
  1425. struct radeon_gart gart;
  1426. struct radeon_mode_info mode_info;
  1427. struct radeon_scratch scratch;
  1428. struct radeon_mman mman;
  1429. struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS];
  1430. wait_queue_head_t fence_queue;
  1431. struct mutex ring_lock;
  1432. struct radeon_ring ring[RADEON_NUM_RINGS];
  1433. bool ib_pool_ready;
  1434. struct radeon_sa_manager ring_tmp_bo;
  1435. struct radeon_irq irq;
  1436. struct radeon_asic *asic;
  1437. struct radeon_gem gem;
  1438. struct radeon_pm pm;
  1439. uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1440. struct radeon_wb wb;
  1441. struct radeon_dummy_page dummy_page;
  1442. bool shutdown;
  1443. bool suspend;
  1444. bool need_dma32;
  1445. bool accel_working;
  1446. struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1447. const struct firmware *me_fw; /* all family ME firmware */
  1448. const struct firmware *pfp_fw; /* r6/700 PFP firmware */
  1449. const struct firmware *rlc_fw; /* r6/700 RLC firmware */
  1450. const struct firmware *mc_fw; /* NI MC firmware */
  1451. const struct firmware *ce_fw; /* SI CE firmware */
  1452. struct r600_blit r600_blit;
  1453. struct r600_vram_scratch vram_scratch;
  1454. int msi_enabled; /* msi enabled */
  1455. struct r600_ih ih; /* r6/700 interrupt ring */
  1456. struct si_rlc rlc;
  1457. struct work_struct hotplug_work;
  1458. struct work_struct audio_work;
  1459. int num_crtc; /* number of crtcs */
  1460. struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1461. bool audio_enabled;
  1462. struct r600_audio audio_status; /* audio stuff */
  1463. struct notifier_block acpi_nb;
  1464. /* only one userspace can use Hyperz features or CMASK at a time */
  1465. struct drm_file *hyperz_filp;
  1466. struct drm_file *cmask_filp;
  1467. /* i2c buses */
  1468. struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1469. /* debugfs */
  1470. struct radeon_debugfs debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
  1471. unsigned debugfs_count;
  1472. /* virtual memory */
  1473. struct radeon_vm_manager vm_manager;
  1474. struct mutex gpu_clock_mutex;
  1475. /* ACPI interface */
  1476. struct radeon_atif atif;
  1477. struct radeon_atcs atcs;
  1478. };
  1479. int radeon_device_init(struct radeon_device *rdev,
  1480. struct drm_device *ddev,
  1481. struct pci_dev *pdev,
  1482. uint32_t flags);
  1483. void radeon_device_fini(struct radeon_device *rdev);
  1484. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  1485. uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg,
  1486. bool always_indirect);
  1487. void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v,
  1488. bool always_indirect);
  1489. u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
  1490. void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
  1491. /*
  1492. * Cast helper
  1493. */
  1494. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  1495. /*
  1496. * Registers read & write functions.
  1497. */
  1498. #define RREG8(reg) readb((rdev->rmmio) + (reg))
  1499. #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
  1500. #define RREG16(reg) readw((rdev->rmmio) + (reg))
  1501. #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
  1502. #define RREG32(reg) r100_mm_rreg(rdev, (reg), false)
  1503. #define RREG32_IDX(reg) r100_mm_rreg(rdev, (reg), true)
  1504. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg), false))
  1505. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v), false)
  1506. #define WREG32_IDX(reg, v) r100_mm_wreg(rdev, (reg), (v), true)
  1507. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1508. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1509. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  1510. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  1511. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  1512. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  1513. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  1514. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  1515. #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
  1516. #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  1517. #define WREG32_P(reg, val, mask) \
  1518. do { \
  1519. uint32_t tmp_ = RREG32(reg); \
  1520. tmp_ &= (mask); \
  1521. tmp_ |= ((val) & ~(mask)); \
  1522. WREG32(reg, tmp_); \
  1523. } while (0)
  1524. #define WREG32_PLL_P(reg, val, mask) \
  1525. do { \
  1526. uint32_t tmp_ = RREG32_PLL(reg); \
  1527. tmp_ &= (mask); \
  1528. tmp_ |= ((val) & ~(mask)); \
  1529. WREG32_PLL(reg, tmp_); \
  1530. } while (0)
  1531. #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg), false))
  1532. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  1533. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  1534. /*
  1535. * Indirect registers accessor
  1536. */
  1537. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  1538. {
  1539. uint32_t r;
  1540. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1541. r = RREG32(RADEON_PCIE_DATA);
  1542. return r;
  1543. }
  1544. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1545. {
  1546. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1547. WREG32(RADEON_PCIE_DATA, (v));
  1548. }
  1549. void r100_pll_errata_after_index(struct radeon_device *rdev);
  1550. /*
  1551. * ASICs helpers.
  1552. */
  1553. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  1554. (rdev->pdev->device == 0x5969))
  1555. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  1556. (rdev->family == CHIP_RV200) || \
  1557. (rdev->family == CHIP_RS100) || \
  1558. (rdev->family == CHIP_RS200) || \
  1559. (rdev->family == CHIP_RV250) || \
  1560. (rdev->family == CHIP_RV280) || \
  1561. (rdev->family == CHIP_RS300))
  1562. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
  1563. (rdev->family == CHIP_RV350) || \
  1564. (rdev->family == CHIP_R350) || \
  1565. (rdev->family == CHIP_RV380) || \
  1566. (rdev->family == CHIP_R420) || \
  1567. (rdev->family == CHIP_R423) || \
  1568. (rdev->family == CHIP_RV410) || \
  1569. (rdev->family == CHIP_RS400) || \
  1570. (rdev->family == CHIP_RS480))
  1571. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  1572. (rdev->ddev->pdev->device == 0x9443) || \
  1573. (rdev->ddev->pdev->device == 0x944B) || \
  1574. (rdev->ddev->pdev->device == 0x9506) || \
  1575. (rdev->ddev->pdev->device == 0x9509) || \
  1576. (rdev->ddev->pdev->device == 0x950F) || \
  1577. (rdev->ddev->pdev->device == 0x689C) || \
  1578. (rdev->ddev->pdev->device == 0x689D))
  1579. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  1580. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
  1581. (rdev->family == CHIP_RS690) || \
  1582. (rdev->family == CHIP_RS740) || \
  1583. (rdev->family >= CHIP_R600))
  1584. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  1585. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  1586. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  1587. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  1588. (rdev->flags & RADEON_IS_IGP))
  1589. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  1590. #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
  1591. #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
  1592. (rdev->flags & RADEON_IS_IGP))
  1593. /*
  1594. * BIOS helpers.
  1595. */
  1596. #define RBIOS8(i) (rdev->bios[i])
  1597. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1598. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1599. int radeon_combios_init(struct radeon_device *rdev);
  1600. void radeon_combios_fini(struct radeon_device *rdev);
  1601. int radeon_atombios_init(struct radeon_device *rdev);
  1602. void radeon_atombios_fini(struct radeon_device *rdev);
  1603. /*
  1604. * RING helpers.
  1605. */
  1606. #if DRM_DEBUG_CODE == 0
  1607. static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
  1608. {
  1609. ring->ring[ring->wptr++] = v;
  1610. ring->wptr &= ring->ptr_mask;
  1611. ring->count_dw--;
  1612. ring->ring_free_dw--;
  1613. }
  1614. #else
  1615. /* With debugging this is just too big to inline */
  1616. void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
  1617. #endif
  1618. /*
  1619. * ASICs macro.
  1620. */
  1621. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  1622. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  1623. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  1624. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  1625. #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)].cs_parse((p))
  1626. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  1627. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  1628. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
  1629. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
  1630. #define radeon_asic_vm_init(rdev) (rdev)->asic->vm.init((rdev))
  1631. #define radeon_asic_vm_fini(rdev) (rdev)->asic->vm.fini((rdev))
  1632. #define radeon_asic_vm_set_page(rdev, pe, addr, count, incr, flags) ((rdev)->asic->vm.set_page((rdev), (pe), (addr), (count), (incr), (flags)))
  1633. #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)].ring_start((rdev), (cp))
  1634. #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)].ring_test((rdev), (cp))
  1635. #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp))
  1636. #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)].ib_execute((rdev), (ib))
  1637. #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)].ib_parse((rdev), (ib))
  1638. #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)].is_lockup((rdev), (cp))
  1639. #define radeon_ring_vm_flush(rdev, r, vm) (rdev)->asic->ring[(r)].vm_flush((rdev), (r), (vm))
  1640. #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
  1641. #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
  1642. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
  1643. #define radeon_set_backlight_level(rdev, e, l) (rdev)->asic->display.set_backlight_level((e), (l))
  1644. #define radeon_get_backlight_level(rdev, e) (rdev)->asic->display.get_backlight_level((e))
  1645. #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)].emit_fence((rdev), (fence))
  1646. #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)].emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
  1647. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
  1648. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (f))
  1649. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (f))
  1650. #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
  1651. #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
  1652. #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
  1653. #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
  1654. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
  1655. #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
  1656. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
  1657. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
  1658. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
  1659. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
  1660. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
  1661. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
  1662. #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
  1663. #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
  1664. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
  1665. #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
  1666. #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
  1667. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  1668. #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
  1669. #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
  1670. #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
  1671. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
  1672. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
  1673. #define radeon_pre_page_flip(rdev, crtc) (rdev)->asic->pflip.pre_page_flip((rdev), (crtc))
  1674. #define radeon_page_flip(rdev, crtc, base) (rdev)->asic->pflip.page_flip((rdev), (crtc), (base))
  1675. #define radeon_post_page_flip(rdev, crtc) (rdev)->asic->pflip.post_page_flip((rdev), (crtc))
  1676. #define radeon_wait_for_vblank(rdev, crtc) (rdev)->asic->display.wait_for_vblank((rdev), (crtc))
  1677. #define radeon_mc_wait_for_idle(rdev) (rdev)->asic->mc_wait_for_idle((rdev))
  1678. /* Common functions */
  1679. /* AGP */
  1680. extern int radeon_gpu_reset(struct radeon_device *rdev);
  1681. extern void radeon_agp_disable(struct radeon_device *rdev);
  1682. extern int radeon_modeset_init(struct radeon_device *rdev);
  1683. extern void radeon_modeset_fini(struct radeon_device *rdev);
  1684. extern bool radeon_card_posted(struct radeon_device *rdev);
  1685. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  1686. extern void radeon_update_display_priority(struct radeon_device *rdev);
  1687. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  1688. extern void radeon_scratch_init(struct radeon_device *rdev);
  1689. extern void radeon_wb_fini(struct radeon_device *rdev);
  1690. extern int radeon_wb_init(struct radeon_device *rdev);
  1691. extern void radeon_wb_disable(struct radeon_device *rdev);
  1692. extern void radeon_surface_init(struct radeon_device *rdev);
  1693. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  1694. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  1695. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  1696. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  1697. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  1698. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  1699. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  1700. extern int radeon_resume_kms(struct drm_device *dev);
  1701. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  1702. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  1703. /*
  1704. * vm
  1705. */
  1706. int radeon_vm_manager_init(struct radeon_device *rdev);
  1707. void radeon_vm_manager_fini(struct radeon_device *rdev);
  1708. void radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
  1709. void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
  1710. int radeon_vm_alloc_pt(struct radeon_device *rdev, struct radeon_vm *vm);
  1711. void radeon_vm_add_to_lru(struct radeon_device *rdev, struct radeon_vm *vm);
  1712. struct radeon_fence *radeon_vm_grab_id(struct radeon_device *rdev,
  1713. struct radeon_vm *vm, int ring);
  1714. void radeon_vm_fence(struct radeon_device *rdev,
  1715. struct radeon_vm *vm,
  1716. struct radeon_fence *fence);
  1717. uint64_t radeon_vm_map_gart(struct radeon_device *rdev, uint64_t addr);
  1718. int radeon_vm_bo_update_pte(struct radeon_device *rdev,
  1719. struct radeon_vm *vm,
  1720. struct radeon_bo *bo,
  1721. struct ttm_mem_reg *mem);
  1722. void radeon_vm_bo_invalidate(struct radeon_device *rdev,
  1723. struct radeon_bo *bo);
  1724. struct radeon_bo_va *radeon_vm_bo_find(struct radeon_vm *vm,
  1725. struct radeon_bo *bo);
  1726. struct radeon_bo_va *radeon_vm_bo_add(struct radeon_device *rdev,
  1727. struct radeon_vm *vm,
  1728. struct radeon_bo *bo);
  1729. int radeon_vm_bo_set_addr(struct radeon_device *rdev,
  1730. struct radeon_bo_va *bo_va,
  1731. uint64_t offset,
  1732. uint32_t flags);
  1733. int radeon_vm_bo_rmv(struct radeon_device *rdev,
  1734. struct radeon_bo_va *bo_va);
  1735. /* audio */
  1736. void r600_audio_update_hdmi(struct work_struct *work);
  1737. /*
  1738. * R600 vram scratch functions
  1739. */
  1740. int r600_vram_scratch_init(struct radeon_device *rdev);
  1741. void r600_vram_scratch_fini(struct radeon_device *rdev);
  1742. /*
  1743. * r600 cs checking helper
  1744. */
  1745. unsigned r600_mip_minify(unsigned size, unsigned level);
  1746. bool r600_fmt_is_valid_color(u32 format);
  1747. bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
  1748. int r600_fmt_get_blocksize(u32 format);
  1749. int r600_fmt_get_nblocksx(u32 format, u32 w);
  1750. int r600_fmt_get_nblocksy(u32 format, u32 h);
  1751. /*
  1752. * r600 functions used by radeon_encoder.c
  1753. */
  1754. struct radeon_hdmi_acr {
  1755. u32 clock;
  1756. int n_32khz;
  1757. int cts_32khz;
  1758. int n_44_1khz;
  1759. int cts_44_1khz;
  1760. int n_48khz;
  1761. int cts_48khz;
  1762. };
  1763. extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
  1764. extern void r600_hdmi_enable(struct drm_encoder *encoder);
  1765. extern void r600_hdmi_disable(struct drm_encoder *encoder);
  1766. extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1767. extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
  1768. u32 tiling_pipe_num,
  1769. u32 max_rb_num,
  1770. u32 total_max_rb_num,
  1771. u32 enabled_rb_mask);
  1772. /*
  1773. * evergreen functions used by radeon_encoder.c
  1774. */
  1775. extern void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1776. extern int ni_init_microcode(struct radeon_device *rdev);
  1777. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  1778. /* radeon_acpi.c */
  1779. #if defined(CONFIG_ACPI)
  1780. extern int radeon_acpi_init(struct radeon_device *rdev);
  1781. extern void radeon_acpi_fini(struct radeon_device *rdev);
  1782. #else
  1783. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  1784. static inline void radeon_acpi_fini(struct radeon_device *rdev) { }
  1785. #endif
  1786. #include "radeon_object.h"
  1787. #endif