radeon.h 57 KB

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