radeon.h 61 KB

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