radeon.h 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851
  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. int 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. spinlock_t lock;
  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 wptr;
  560. unsigned wptr_old;
  561. unsigned wptr_reg;
  562. unsigned ring_size;
  563. unsigned ring_free_dw;
  564. int count_dw;
  565. unsigned long last_activity;
  566. unsigned last_rptr;
  567. uint64_t gpu_addr;
  568. uint32_t align_mask;
  569. uint32_t ptr_mask;
  570. bool ready;
  571. u32 ptr_reg_shift;
  572. u32 ptr_reg_mask;
  573. u32 nop;
  574. };
  575. /*
  576. * VM
  577. */
  578. struct radeon_vm {
  579. struct list_head list;
  580. struct list_head va;
  581. int id;
  582. unsigned last_pfn;
  583. u64 pt_gpu_addr;
  584. u64 *pt;
  585. struct radeon_sa_bo *sa_bo;
  586. struct mutex mutex;
  587. /* last fence for cs using this vm */
  588. struct radeon_fence *fence;
  589. };
  590. struct radeon_vm_funcs {
  591. int (*init)(struct radeon_device *rdev);
  592. void (*fini)(struct radeon_device *rdev);
  593. /* cs mutex must be lock for schedule_ib */
  594. int (*bind)(struct radeon_device *rdev, struct radeon_vm *vm, int id);
  595. void (*unbind)(struct radeon_device *rdev, struct radeon_vm *vm);
  596. void (*tlb_flush)(struct radeon_device *rdev, struct radeon_vm *vm);
  597. uint32_t (*page_flags)(struct radeon_device *rdev,
  598. struct radeon_vm *vm,
  599. uint32_t flags);
  600. void (*set_page)(struct radeon_device *rdev, struct radeon_vm *vm,
  601. unsigned pfn, uint64_t addr, uint32_t flags);
  602. };
  603. struct radeon_vm_manager {
  604. struct mutex lock;
  605. struct list_head lru_vm;
  606. uint32_t use_bitmap;
  607. struct radeon_sa_manager sa_manager;
  608. uint32_t max_pfn;
  609. /* fields constant after init */
  610. const struct radeon_vm_funcs *funcs;
  611. /* number of VMIDs */
  612. unsigned nvm;
  613. /* vram base address for page table entry */
  614. u64 vram_base_offset;
  615. /* is vm enabled? */
  616. bool enabled;
  617. };
  618. /*
  619. * file private structure
  620. */
  621. struct radeon_fpriv {
  622. struct radeon_vm vm;
  623. };
  624. /*
  625. * R6xx+ IH ring
  626. */
  627. struct r600_ih {
  628. struct radeon_bo *ring_obj;
  629. volatile uint32_t *ring;
  630. unsigned rptr;
  631. unsigned ring_size;
  632. uint64_t gpu_addr;
  633. uint32_t ptr_mask;
  634. atomic_t lock;
  635. bool enabled;
  636. };
  637. struct r600_blit_cp_primitives {
  638. void (*set_render_target)(struct radeon_device *rdev, int format,
  639. int w, int h, u64 gpu_addr);
  640. void (*cp_set_surface_sync)(struct radeon_device *rdev,
  641. u32 sync_type, u32 size,
  642. u64 mc_addr);
  643. void (*set_shaders)(struct radeon_device *rdev);
  644. void (*set_vtx_resource)(struct radeon_device *rdev, u64 gpu_addr);
  645. void (*set_tex_resource)(struct radeon_device *rdev,
  646. int format, int w, int h, int pitch,
  647. u64 gpu_addr, u32 size);
  648. void (*set_scissors)(struct radeon_device *rdev, int x1, int y1,
  649. int x2, int y2);
  650. void (*draw_auto)(struct radeon_device *rdev);
  651. void (*set_default_state)(struct radeon_device *rdev);
  652. };
  653. struct r600_blit {
  654. struct radeon_bo *shader_obj;
  655. struct r600_blit_cp_primitives primitives;
  656. int max_dim;
  657. int ring_size_common;
  658. int ring_size_per_loop;
  659. u64 shader_gpu_addr;
  660. u32 vs_offset, ps_offset;
  661. u32 state_offset;
  662. u32 state_len;
  663. };
  664. void r600_blit_suspend(struct radeon_device *rdev);
  665. /*
  666. * SI RLC stuff
  667. */
  668. struct si_rlc {
  669. /* for power gating */
  670. struct radeon_bo *save_restore_obj;
  671. uint64_t save_restore_gpu_addr;
  672. /* for clear state */
  673. struct radeon_bo *clear_state_obj;
  674. uint64_t clear_state_gpu_addr;
  675. };
  676. int radeon_ib_get(struct radeon_device *rdev, int ring,
  677. struct radeon_ib *ib, unsigned size);
  678. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib);
  679. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
  680. int radeon_ib_pool_init(struct radeon_device *rdev);
  681. void radeon_ib_pool_fini(struct radeon_device *rdev);
  682. int radeon_ib_pool_start(struct radeon_device *rdev);
  683. int radeon_ib_pool_suspend(struct radeon_device *rdev);
  684. int radeon_ib_ring_tests(struct radeon_device *rdev);
  685. /* Ring access between begin & end cannot sleep */
  686. int radeon_ring_index(struct radeon_device *rdev, struct radeon_ring *cp);
  687. void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *cp);
  688. int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  689. int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ndw);
  690. void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  691. void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *cp);
  692. void radeon_ring_undo(struct radeon_ring *ring);
  693. void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *cp);
  694. int radeon_ring_test(struct radeon_device *rdev, struct radeon_ring *cp);
  695. void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring);
  696. void radeon_ring_lockup_update(struct radeon_ring *ring);
  697. bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring);
  698. int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *cp, unsigned ring_size,
  699. unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg,
  700. u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop);
  701. void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *cp);
  702. /*
  703. * CS.
  704. */
  705. struct radeon_cs_reloc {
  706. struct drm_gem_object *gobj;
  707. struct radeon_bo *robj;
  708. struct radeon_bo_list lobj;
  709. uint32_t handle;
  710. uint32_t flags;
  711. };
  712. struct radeon_cs_chunk {
  713. uint32_t chunk_id;
  714. uint32_t length_dw;
  715. int kpage_idx[2];
  716. uint32_t *kpage[2];
  717. uint32_t *kdata;
  718. void __user *user_ptr;
  719. int last_copied_page;
  720. int last_page_index;
  721. };
  722. struct radeon_cs_parser {
  723. struct device *dev;
  724. struct radeon_device *rdev;
  725. struct drm_file *filp;
  726. /* chunks */
  727. unsigned nchunks;
  728. struct radeon_cs_chunk *chunks;
  729. uint64_t *chunks_array;
  730. /* IB */
  731. unsigned idx;
  732. /* relocations */
  733. unsigned nrelocs;
  734. struct radeon_cs_reloc *relocs;
  735. struct radeon_cs_reloc **relocs_ptr;
  736. struct list_head validated;
  737. /* indices of various chunks */
  738. int chunk_ib_idx;
  739. int chunk_relocs_idx;
  740. int chunk_flags_idx;
  741. int chunk_const_ib_idx;
  742. struct radeon_ib ib;
  743. struct radeon_ib const_ib;
  744. void *track;
  745. unsigned family;
  746. int parser_error;
  747. u32 cs_flags;
  748. u32 ring;
  749. s32 priority;
  750. };
  751. extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
  752. extern u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx);
  753. struct radeon_cs_packet {
  754. unsigned idx;
  755. unsigned type;
  756. unsigned reg;
  757. unsigned opcode;
  758. int count;
  759. unsigned one_reg_wr;
  760. };
  761. typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
  762. struct radeon_cs_packet *pkt,
  763. unsigned idx, unsigned reg);
  764. typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
  765. struct radeon_cs_packet *pkt);
  766. /*
  767. * AGP
  768. */
  769. int radeon_agp_init(struct radeon_device *rdev);
  770. void radeon_agp_resume(struct radeon_device *rdev);
  771. void radeon_agp_suspend(struct radeon_device *rdev);
  772. void radeon_agp_fini(struct radeon_device *rdev);
  773. /*
  774. * Writeback
  775. */
  776. struct radeon_wb {
  777. struct radeon_bo *wb_obj;
  778. volatile uint32_t *wb;
  779. uint64_t gpu_addr;
  780. bool enabled;
  781. bool use_event;
  782. };
  783. #define RADEON_WB_SCRATCH_OFFSET 0
  784. #define RADEON_WB_CP_RPTR_OFFSET 1024
  785. #define RADEON_WB_CP1_RPTR_OFFSET 1280
  786. #define RADEON_WB_CP2_RPTR_OFFSET 1536
  787. #define R600_WB_IH_WPTR_OFFSET 2048
  788. #define R600_WB_EVENT_OFFSET 3072
  789. /**
  790. * struct radeon_pm - power management datas
  791. * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
  792. * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
  793. * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
  794. * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
  795. * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
  796. * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
  797. * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
  798. * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
  799. * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
  800. * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
  801. * @needed_bandwidth: current bandwidth needs
  802. *
  803. * It keeps track of various data needed to take powermanagement decision.
  804. * Bandwidth need is used to determine minimun clock of the GPU and memory.
  805. * Equation between gpu/memory clock and available bandwidth is hw dependent
  806. * (type of memory, bus size, efficiency, ...)
  807. */
  808. enum radeon_pm_method {
  809. PM_METHOD_PROFILE,
  810. PM_METHOD_DYNPM,
  811. };
  812. enum radeon_dynpm_state {
  813. DYNPM_STATE_DISABLED,
  814. DYNPM_STATE_MINIMUM,
  815. DYNPM_STATE_PAUSED,
  816. DYNPM_STATE_ACTIVE,
  817. DYNPM_STATE_SUSPENDED,
  818. };
  819. enum radeon_dynpm_action {
  820. DYNPM_ACTION_NONE,
  821. DYNPM_ACTION_MINIMUM,
  822. DYNPM_ACTION_DOWNCLOCK,
  823. DYNPM_ACTION_UPCLOCK,
  824. DYNPM_ACTION_DEFAULT
  825. };
  826. enum radeon_voltage_type {
  827. VOLTAGE_NONE = 0,
  828. VOLTAGE_GPIO,
  829. VOLTAGE_VDDC,
  830. VOLTAGE_SW
  831. };
  832. enum radeon_pm_state_type {
  833. POWER_STATE_TYPE_DEFAULT,
  834. POWER_STATE_TYPE_POWERSAVE,
  835. POWER_STATE_TYPE_BATTERY,
  836. POWER_STATE_TYPE_BALANCED,
  837. POWER_STATE_TYPE_PERFORMANCE,
  838. };
  839. enum radeon_pm_profile_type {
  840. PM_PROFILE_DEFAULT,
  841. PM_PROFILE_AUTO,
  842. PM_PROFILE_LOW,
  843. PM_PROFILE_MID,
  844. PM_PROFILE_HIGH,
  845. };
  846. #define PM_PROFILE_DEFAULT_IDX 0
  847. #define PM_PROFILE_LOW_SH_IDX 1
  848. #define PM_PROFILE_MID_SH_IDX 2
  849. #define PM_PROFILE_HIGH_SH_IDX 3
  850. #define PM_PROFILE_LOW_MH_IDX 4
  851. #define PM_PROFILE_MID_MH_IDX 5
  852. #define PM_PROFILE_HIGH_MH_IDX 6
  853. #define PM_PROFILE_MAX 7
  854. struct radeon_pm_profile {
  855. int dpms_off_ps_idx;
  856. int dpms_on_ps_idx;
  857. int dpms_off_cm_idx;
  858. int dpms_on_cm_idx;
  859. };
  860. enum radeon_int_thermal_type {
  861. THERMAL_TYPE_NONE,
  862. THERMAL_TYPE_RV6XX,
  863. THERMAL_TYPE_RV770,
  864. THERMAL_TYPE_EVERGREEN,
  865. THERMAL_TYPE_SUMO,
  866. THERMAL_TYPE_NI,
  867. THERMAL_TYPE_SI,
  868. };
  869. struct radeon_voltage {
  870. enum radeon_voltage_type type;
  871. /* gpio voltage */
  872. struct radeon_gpio_rec gpio;
  873. u32 delay; /* delay in usec from voltage drop to sclk change */
  874. bool active_high; /* voltage drop is active when bit is high */
  875. /* VDDC voltage */
  876. u8 vddc_id; /* index into vddc voltage table */
  877. u8 vddci_id; /* index into vddci voltage table */
  878. bool vddci_enabled;
  879. /* r6xx+ sw */
  880. u16 voltage;
  881. /* evergreen+ vddci */
  882. u16 vddci;
  883. };
  884. /* clock mode flags */
  885. #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
  886. struct radeon_pm_clock_info {
  887. /* memory clock */
  888. u32 mclk;
  889. /* engine clock */
  890. u32 sclk;
  891. /* voltage info */
  892. struct radeon_voltage voltage;
  893. /* standardized clock flags */
  894. u32 flags;
  895. };
  896. /* state flags */
  897. #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
  898. struct radeon_power_state {
  899. enum radeon_pm_state_type type;
  900. struct radeon_pm_clock_info *clock_info;
  901. /* number of valid clock modes in this power state */
  902. int num_clock_modes;
  903. struct radeon_pm_clock_info *default_clock_mode;
  904. /* standardized state flags */
  905. u32 flags;
  906. u32 misc; /* vbios specific flags */
  907. u32 misc2; /* vbios specific flags */
  908. int pcie_lanes; /* pcie lanes */
  909. };
  910. /*
  911. * Some modes are overclocked by very low value, accept them
  912. */
  913. #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
  914. struct radeon_pm {
  915. struct mutex mutex;
  916. /* write locked while reprogramming mclk */
  917. struct rw_semaphore mclk_lock;
  918. u32 active_crtcs;
  919. int active_crtc_count;
  920. int req_vblank;
  921. bool vblank_sync;
  922. fixed20_12 max_bandwidth;
  923. fixed20_12 igp_sideport_mclk;
  924. fixed20_12 igp_system_mclk;
  925. fixed20_12 igp_ht_link_clk;
  926. fixed20_12 igp_ht_link_width;
  927. fixed20_12 k8_bandwidth;
  928. fixed20_12 sideport_bandwidth;
  929. fixed20_12 ht_bandwidth;
  930. fixed20_12 core_bandwidth;
  931. fixed20_12 sclk;
  932. fixed20_12 mclk;
  933. fixed20_12 needed_bandwidth;
  934. struct radeon_power_state *power_state;
  935. /* number of valid power states */
  936. int num_power_states;
  937. int current_power_state_index;
  938. int current_clock_mode_index;
  939. int requested_power_state_index;
  940. int requested_clock_mode_index;
  941. int default_power_state_index;
  942. u32 current_sclk;
  943. u32 current_mclk;
  944. u16 current_vddc;
  945. u16 current_vddci;
  946. u32 default_sclk;
  947. u32 default_mclk;
  948. u16 default_vddc;
  949. u16 default_vddci;
  950. struct radeon_i2c_chan *i2c_bus;
  951. /* selected pm method */
  952. enum radeon_pm_method pm_method;
  953. /* dynpm power management */
  954. struct delayed_work dynpm_idle_work;
  955. enum radeon_dynpm_state dynpm_state;
  956. enum radeon_dynpm_action dynpm_planned_action;
  957. unsigned long dynpm_action_timeout;
  958. bool dynpm_can_upclock;
  959. bool dynpm_can_downclock;
  960. /* profile-based power management */
  961. enum radeon_pm_profile_type profile;
  962. int profile_index;
  963. struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  964. /* internal thermal controller on rv6xx+ */
  965. enum radeon_int_thermal_type int_thermal_type;
  966. struct device *int_hwmon_dev;
  967. };
  968. int radeon_pm_get_type_index(struct radeon_device *rdev,
  969. enum radeon_pm_state_type ps_type,
  970. int instance);
  971. struct r600_audio {
  972. int channels;
  973. int rate;
  974. int bits_per_sample;
  975. u8 status_bits;
  976. u8 category_code;
  977. };
  978. /*
  979. * Benchmarking
  980. */
  981. void radeon_benchmark(struct radeon_device *rdev, int test_number);
  982. /*
  983. * Testing
  984. */
  985. void radeon_test_moves(struct radeon_device *rdev);
  986. void radeon_test_ring_sync(struct radeon_device *rdev,
  987. struct radeon_ring *cpA,
  988. struct radeon_ring *cpB);
  989. void radeon_test_syncing(struct radeon_device *rdev);
  990. /*
  991. * Debugfs
  992. */
  993. struct radeon_debugfs {
  994. struct drm_info_list *files;
  995. unsigned num_files;
  996. };
  997. int radeon_debugfs_add_files(struct radeon_device *rdev,
  998. struct drm_info_list *files,
  999. unsigned nfiles);
  1000. int radeon_debugfs_fence_init(struct radeon_device *rdev);
  1001. /*
  1002. * ASIC specific functions.
  1003. */
  1004. struct radeon_asic {
  1005. int (*init)(struct radeon_device *rdev);
  1006. void (*fini)(struct radeon_device *rdev);
  1007. int (*resume)(struct radeon_device *rdev);
  1008. int (*suspend)(struct radeon_device *rdev);
  1009. void (*vga_set_state)(struct radeon_device *rdev, bool state);
  1010. int (*asic_reset)(struct radeon_device *rdev);
  1011. /* ioctl hw specific callback. Some hw might want to perform special
  1012. * operation on specific ioctl. For instance on wait idle some hw
  1013. * might want to perform and HDP flush through MMIO as it seems that
  1014. * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  1015. * through ring.
  1016. */
  1017. void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  1018. /* check if 3D engine is idle */
  1019. bool (*gui_idle)(struct radeon_device *rdev);
  1020. /* wait for mc_idle */
  1021. int (*mc_wait_for_idle)(struct radeon_device *rdev);
  1022. /* gart */
  1023. struct {
  1024. void (*tlb_flush)(struct radeon_device *rdev);
  1025. int (*set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  1026. } gart;
  1027. /* ring specific callbacks */
  1028. struct {
  1029. void (*ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  1030. int (*ib_parse)(struct radeon_device *rdev, struct radeon_ib *ib);
  1031. void (*emit_fence)(struct radeon_device *rdev, struct radeon_fence *fence);
  1032. void (*emit_semaphore)(struct radeon_device *rdev, struct radeon_ring *cp,
  1033. struct radeon_semaphore *semaphore, bool emit_wait);
  1034. int (*cs_parse)(struct radeon_cs_parser *p);
  1035. void (*ring_start)(struct radeon_device *rdev, struct radeon_ring *cp);
  1036. int (*ring_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1037. int (*ib_test)(struct radeon_device *rdev, struct radeon_ring *cp);
  1038. bool (*is_lockup)(struct radeon_device *rdev, struct radeon_ring *cp);
  1039. } ring[RADEON_NUM_RINGS];
  1040. /* irqs */
  1041. struct {
  1042. int (*set)(struct radeon_device *rdev);
  1043. int (*process)(struct radeon_device *rdev);
  1044. } irq;
  1045. /* displays */
  1046. struct {
  1047. /* display watermarks */
  1048. void (*bandwidth_update)(struct radeon_device *rdev);
  1049. /* get frame count */
  1050. u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  1051. /* wait for vblank */
  1052. void (*wait_for_vblank)(struct radeon_device *rdev, int crtc);
  1053. } display;
  1054. /* copy functions for bo handling */
  1055. struct {
  1056. int (*blit)(struct radeon_device *rdev,
  1057. uint64_t src_offset,
  1058. uint64_t dst_offset,
  1059. unsigned num_gpu_pages,
  1060. struct radeon_fence **fence);
  1061. u32 blit_ring_index;
  1062. int (*dma)(struct radeon_device *rdev,
  1063. uint64_t src_offset,
  1064. uint64_t dst_offset,
  1065. unsigned num_gpu_pages,
  1066. struct radeon_fence **fence);
  1067. u32 dma_ring_index;
  1068. /* method used for bo copy */
  1069. int (*copy)(struct radeon_device *rdev,
  1070. uint64_t src_offset,
  1071. uint64_t dst_offset,
  1072. unsigned num_gpu_pages,
  1073. struct radeon_fence **fence);
  1074. /* ring used for bo copies */
  1075. u32 copy_ring_index;
  1076. } copy;
  1077. /* surfaces */
  1078. struct {
  1079. int (*set_reg)(struct radeon_device *rdev, int reg,
  1080. uint32_t tiling_flags, uint32_t pitch,
  1081. uint32_t offset, uint32_t obj_size);
  1082. void (*clear_reg)(struct radeon_device *rdev, int reg);
  1083. } surface;
  1084. /* hotplug detect */
  1085. struct {
  1086. void (*init)(struct radeon_device *rdev);
  1087. void (*fini)(struct radeon_device *rdev);
  1088. bool (*sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1089. void (*set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  1090. } hpd;
  1091. /* power management */
  1092. struct {
  1093. void (*misc)(struct radeon_device *rdev);
  1094. void (*prepare)(struct radeon_device *rdev);
  1095. void (*finish)(struct radeon_device *rdev);
  1096. void (*init_profile)(struct radeon_device *rdev);
  1097. void (*get_dynpm_state)(struct radeon_device *rdev);
  1098. uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  1099. void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  1100. uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  1101. void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  1102. int (*get_pcie_lanes)(struct radeon_device *rdev);
  1103. void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  1104. void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  1105. } pm;
  1106. /* pageflipping */
  1107. struct {
  1108. void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  1109. u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  1110. void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  1111. } pflip;
  1112. };
  1113. /*
  1114. * Asic structures
  1115. */
  1116. struct r100_asic {
  1117. const unsigned *reg_safe_bm;
  1118. unsigned reg_safe_bm_size;
  1119. u32 hdp_cntl;
  1120. };
  1121. struct r300_asic {
  1122. const unsigned *reg_safe_bm;
  1123. unsigned reg_safe_bm_size;
  1124. u32 resync_scratch;
  1125. u32 hdp_cntl;
  1126. };
  1127. struct r600_asic {
  1128. unsigned max_pipes;
  1129. unsigned max_tile_pipes;
  1130. unsigned max_simds;
  1131. unsigned max_backends;
  1132. unsigned max_gprs;
  1133. unsigned max_threads;
  1134. unsigned max_stack_entries;
  1135. unsigned max_hw_contexts;
  1136. unsigned max_gs_threads;
  1137. unsigned sx_max_export_size;
  1138. unsigned sx_max_export_pos_size;
  1139. unsigned sx_max_export_smx_size;
  1140. unsigned sq_num_cf_insts;
  1141. unsigned tiling_nbanks;
  1142. unsigned tiling_npipes;
  1143. unsigned tiling_group_size;
  1144. unsigned tile_config;
  1145. unsigned backend_map;
  1146. };
  1147. struct rv770_asic {
  1148. unsigned max_pipes;
  1149. unsigned max_tile_pipes;
  1150. unsigned max_simds;
  1151. unsigned max_backends;
  1152. unsigned max_gprs;
  1153. unsigned max_threads;
  1154. unsigned max_stack_entries;
  1155. unsigned max_hw_contexts;
  1156. unsigned max_gs_threads;
  1157. unsigned sx_max_export_size;
  1158. unsigned sx_max_export_pos_size;
  1159. unsigned sx_max_export_smx_size;
  1160. unsigned sq_num_cf_insts;
  1161. unsigned sx_num_of_sets;
  1162. unsigned sc_prim_fifo_size;
  1163. unsigned sc_hiz_tile_fifo_size;
  1164. unsigned sc_earlyz_tile_fifo_fize;
  1165. unsigned tiling_nbanks;
  1166. unsigned tiling_npipes;
  1167. unsigned tiling_group_size;
  1168. unsigned tile_config;
  1169. unsigned backend_map;
  1170. };
  1171. struct evergreen_asic {
  1172. unsigned num_ses;
  1173. unsigned max_pipes;
  1174. unsigned max_tile_pipes;
  1175. unsigned max_simds;
  1176. unsigned max_backends;
  1177. unsigned max_gprs;
  1178. unsigned max_threads;
  1179. unsigned max_stack_entries;
  1180. unsigned max_hw_contexts;
  1181. unsigned max_gs_threads;
  1182. unsigned sx_max_export_size;
  1183. unsigned sx_max_export_pos_size;
  1184. unsigned sx_max_export_smx_size;
  1185. unsigned sq_num_cf_insts;
  1186. unsigned sx_num_of_sets;
  1187. unsigned sc_prim_fifo_size;
  1188. unsigned sc_hiz_tile_fifo_size;
  1189. unsigned sc_earlyz_tile_fifo_size;
  1190. unsigned tiling_nbanks;
  1191. unsigned tiling_npipes;
  1192. unsigned tiling_group_size;
  1193. unsigned tile_config;
  1194. unsigned backend_map;
  1195. };
  1196. struct cayman_asic {
  1197. unsigned max_shader_engines;
  1198. unsigned max_pipes_per_simd;
  1199. unsigned max_tile_pipes;
  1200. unsigned max_simds_per_se;
  1201. unsigned max_backends_per_se;
  1202. unsigned max_texture_channel_caches;
  1203. unsigned max_gprs;
  1204. unsigned max_threads;
  1205. unsigned max_gs_threads;
  1206. unsigned max_stack_entries;
  1207. unsigned sx_num_of_sets;
  1208. unsigned sx_max_export_size;
  1209. unsigned sx_max_export_pos_size;
  1210. unsigned sx_max_export_smx_size;
  1211. unsigned max_hw_contexts;
  1212. unsigned sq_num_cf_insts;
  1213. unsigned sc_prim_fifo_size;
  1214. unsigned sc_hiz_tile_fifo_size;
  1215. unsigned sc_earlyz_tile_fifo_size;
  1216. unsigned num_shader_engines;
  1217. unsigned num_shader_pipes_per_simd;
  1218. unsigned num_tile_pipes;
  1219. unsigned num_simds_per_se;
  1220. unsigned num_backends_per_se;
  1221. unsigned backend_disable_mask_per_asic;
  1222. unsigned backend_map;
  1223. unsigned num_texture_channel_caches;
  1224. unsigned mem_max_burst_length_bytes;
  1225. unsigned mem_row_size_in_kb;
  1226. unsigned shader_engine_tile_size;
  1227. unsigned num_gpus;
  1228. unsigned multi_gpu_tile_size;
  1229. unsigned tile_config;
  1230. };
  1231. struct si_asic {
  1232. unsigned max_shader_engines;
  1233. unsigned max_tile_pipes;
  1234. unsigned max_cu_per_sh;
  1235. unsigned max_sh_per_se;
  1236. unsigned max_backends_per_se;
  1237. unsigned max_texture_channel_caches;
  1238. unsigned max_gprs;
  1239. unsigned max_gs_threads;
  1240. unsigned max_hw_contexts;
  1241. unsigned sc_prim_fifo_size_frontend;
  1242. unsigned sc_prim_fifo_size_backend;
  1243. unsigned sc_hiz_tile_fifo_size;
  1244. unsigned sc_earlyz_tile_fifo_size;
  1245. unsigned num_tile_pipes;
  1246. unsigned num_backends_per_se;
  1247. unsigned backend_disable_mask_per_asic;
  1248. unsigned backend_map;
  1249. unsigned num_texture_channel_caches;
  1250. unsigned mem_max_burst_length_bytes;
  1251. unsigned mem_row_size_in_kb;
  1252. unsigned shader_engine_tile_size;
  1253. unsigned num_gpus;
  1254. unsigned multi_gpu_tile_size;
  1255. unsigned tile_config;
  1256. };
  1257. union radeon_asic_config {
  1258. struct r300_asic r300;
  1259. struct r100_asic r100;
  1260. struct r600_asic r600;
  1261. struct rv770_asic rv770;
  1262. struct evergreen_asic evergreen;
  1263. struct cayman_asic cayman;
  1264. struct si_asic si;
  1265. };
  1266. /*
  1267. * asic initizalization from radeon_asic.c
  1268. */
  1269. void radeon_agp_disable(struct radeon_device *rdev);
  1270. int radeon_asic_init(struct radeon_device *rdev);
  1271. /*
  1272. * IOCTL.
  1273. */
  1274. int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
  1275. struct drm_file *filp);
  1276. int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
  1277. struct drm_file *filp);
  1278. int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
  1279. struct drm_file *file_priv);
  1280. int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1281. struct drm_file *file_priv);
  1282. int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1283. struct drm_file *file_priv);
  1284. int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
  1285. struct drm_file *file_priv);
  1286. int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1287. struct drm_file *filp);
  1288. int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1289. struct drm_file *filp);
  1290. int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
  1291. struct drm_file *filp);
  1292. int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1293. struct drm_file *filp);
  1294. int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
  1295. struct drm_file *filp);
  1296. int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1297. int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  1298. struct drm_file *filp);
  1299. int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  1300. struct drm_file *filp);
  1301. /* VRAM scratch page for HDP bug, default vram page */
  1302. struct r600_vram_scratch {
  1303. struct radeon_bo *robj;
  1304. volatile uint32_t *ptr;
  1305. u64 gpu_addr;
  1306. };
  1307. /*
  1308. * Core structure, functions and helpers.
  1309. */
  1310. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1311. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1312. struct radeon_device {
  1313. struct device *dev;
  1314. struct drm_device *ddev;
  1315. struct pci_dev *pdev;
  1316. /* ASIC */
  1317. union radeon_asic_config config;
  1318. enum radeon_family family;
  1319. unsigned long flags;
  1320. int usec_timeout;
  1321. enum radeon_pll_errata pll_errata;
  1322. int num_gb_pipes;
  1323. int num_z_pipes;
  1324. int disp_priority;
  1325. /* BIOS */
  1326. uint8_t *bios;
  1327. bool is_atom_bios;
  1328. uint16_t bios_header_start;
  1329. struct radeon_bo *stollen_vga_memory;
  1330. /* Register mmio */
  1331. resource_size_t rmmio_base;
  1332. resource_size_t rmmio_size;
  1333. void __iomem *rmmio;
  1334. radeon_rreg_t mc_rreg;
  1335. radeon_wreg_t mc_wreg;
  1336. radeon_rreg_t pll_rreg;
  1337. radeon_wreg_t pll_wreg;
  1338. uint32_t pcie_reg_mask;
  1339. radeon_rreg_t pciep_rreg;
  1340. radeon_wreg_t pciep_wreg;
  1341. /* io port */
  1342. void __iomem *rio_mem;
  1343. resource_size_t rio_mem_size;
  1344. struct radeon_clock clock;
  1345. struct radeon_mc mc;
  1346. struct radeon_gart gart;
  1347. struct radeon_mode_info mode_info;
  1348. struct radeon_scratch scratch;
  1349. struct radeon_mman mman;
  1350. struct radeon_fence_driver fence_drv[RADEON_NUM_RINGS];
  1351. wait_queue_head_t fence_queue;
  1352. struct mutex ring_lock;
  1353. struct radeon_ring ring[RADEON_NUM_RINGS];
  1354. bool ib_pool_ready;
  1355. struct radeon_sa_manager ring_tmp_bo;
  1356. struct radeon_irq irq;
  1357. struct radeon_asic *asic;
  1358. struct radeon_gem gem;
  1359. struct radeon_pm pm;
  1360. uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1361. struct radeon_wb wb;
  1362. struct radeon_dummy_page dummy_page;
  1363. bool shutdown;
  1364. bool suspend;
  1365. bool need_dma32;
  1366. bool accel_working;
  1367. struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1368. const struct firmware *me_fw; /* all family ME firmware */
  1369. const struct firmware *pfp_fw; /* r6/700 PFP firmware */
  1370. const struct firmware *rlc_fw; /* r6/700 RLC firmware */
  1371. const struct firmware *mc_fw; /* NI MC firmware */
  1372. const struct firmware *ce_fw; /* SI CE firmware */
  1373. struct r600_blit r600_blit;
  1374. struct r600_vram_scratch vram_scratch;
  1375. int msi_enabled; /* msi enabled */
  1376. struct r600_ih ih; /* r6/700 interrupt ring */
  1377. struct si_rlc rlc;
  1378. struct work_struct hotplug_work;
  1379. struct work_struct audio_work;
  1380. int num_crtc; /* number of crtcs */
  1381. struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1382. bool audio_enabled;
  1383. struct r600_audio audio_status; /* audio stuff */
  1384. struct notifier_block acpi_nb;
  1385. /* only one userspace can use Hyperz features or CMASK at a time */
  1386. struct drm_file *hyperz_filp;
  1387. struct drm_file *cmask_filp;
  1388. /* i2c buses */
  1389. struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1390. /* debugfs */
  1391. struct radeon_debugfs debugfs[RADEON_DEBUGFS_MAX_COMPONENTS];
  1392. unsigned debugfs_count;
  1393. /* virtual memory */
  1394. struct radeon_vm_manager vm_manager;
  1395. };
  1396. int radeon_device_init(struct radeon_device *rdev,
  1397. struct drm_device *ddev,
  1398. struct pci_dev *pdev,
  1399. uint32_t flags);
  1400. void radeon_device_fini(struct radeon_device *rdev);
  1401. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  1402. uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg);
  1403. void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v);
  1404. u32 r100_io_rreg(struct radeon_device *rdev, u32 reg);
  1405. void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v);
  1406. /*
  1407. * Cast helper
  1408. */
  1409. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  1410. /*
  1411. * Registers read & write functions.
  1412. */
  1413. #define RREG8(reg) readb((rdev->rmmio) + (reg))
  1414. #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
  1415. #define RREG16(reg) readw((rdev->rmmio) + (reg))
  1416. #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
  1417. #define RREG32(reg) r100_mm_rreg(rdev, (reg))
  1418. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
  1419. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
  1420. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1421. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1422. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  1423. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  1424. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  1425. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  1426. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  1427. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  1428. #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
  1429. #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  1430. #define WREG32_P(reg, val, mask) \
  1431. do { \
  1432. uint32_t tmp_ = RREG32(reg); \
  1433. tmp_ &= (mask); \
  1434. tmp_ |= ((val) & ~(mask)); \
  1435. WREG32(reg, tmp_); \
  1436. } while (0)
  1437. #define WREG32_PLL_P(reg, val, mask) \
  1438. do { \
  1439. uint32_t tmp_ = RREG32_PLL(reg); \
  1440. tmp_ &= (mask); \
  1441. tmp_ |= ((val) & ~(mask)); \
  1442. WREG32_PLL(reg, tmp_); \
  1443. } while (0)
  1444. #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg)))
  1445. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  1446. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  1447. /*
  1448. * Indirect registers accessor
  1449. */
  1450. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  1451. {
  1452. uint32_t r;
  1453. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1454. r = RREG32(RADEON_PCIE_DATA);
  1455. return r;
  1456. }
  1457. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1458. {
  1459. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1460. WREG32(RADEON_PCIE_DATA, (v));
  1461. }
  1462. void r100_pll_errata_after_index(struct radeon_device *rdev);
  1463. /*
  1464. * ASICs helpers.
  1465. */
  1466. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  1467. (rdev->pdev->device == 0x5969))
  1468. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  1469. (rdev->family == CHIP_RV200) || \
  1470. (rdev->family == CHIP_RS100) || \
  1471. (rdev->family == CHIP_RS200) || \
  1472. (rdev->family == CHIP_RV250) || \
  1473. (rdev->family == CHIP_RV280) || \
  1474. (rdev->family == CHIP_RS300))
  1475. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
  1476. (rdev->family == CHIP_RV350) || \
  1477. (rdev->family == CHIP_R350) || \
  1478. (rdev->family == CHIP_RV380) || \
  1479. (rdev->family == CHIP_R420) || \
  1480. (rdev->family == CHIP_R423) || \
  1481. (rdev->family == CHIP_RV410) || \
  1482. (rdev->family == CHIP_RS400) || \
  1483. (rdev->family == CHIP_RS480))
  1484. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  1485. (rdev->ddev->pdev->device == 0x9443) || \
  1486. (rdev->ddev->pdev->device == 0x944B) || \
  1487. (rdev->ddev->pdev->device == 0x9506) || \
  1488. (rdev->ddev->pdev->device == 0x9509) || \
  1489. (rdev->ddev->pdev->device == 0x950F) || \
  1490. (rdev->ddev->pdev->device == 0x689C) || \
  1491. (rdev->ddev->pdev->device == 0x689D))
  1492. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  1493. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
  1494. (rdev->family == CHIP_RS690) || \
  1495. (rdev->family == CHIP_RS740) || \
  1496. (rdev->family >= CHIP_R600))
  1497. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  1498. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  1499. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  1500. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  1501. (rdev->flags & RADEON_IS_IGP))
  1502. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  1503. #define ASIC_IS_DCE6(rdev) ((rdev->family >= CHIP_ARUBA))
  1504. #define ASIC_IS_DCE61(rdev) ((rdev->family >= CHIP_ARUBA) && \
  1505. (rdev->flags & RADEON_IS_IGP))
  1506. /*
  1507. * BIOS helpers.
  1508. */
  1509. #define RBIOS8(i) (rdev->bios[i])
  1510. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1511. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1512. int radeon_combios_init(struct radeon_device *rdev);
  1513. void radeon_combios_fini(struct radeon_device *rdev);
  1514. int radeon_atombios_init(struct radeon_device *rdev);
  1515. void radeon_atombios_fini(struct radeon_device *rdev);
  1516. /*
  1517. * RING helpers.
  1518. */
  1519. #if DRM_DEBUG_CODE == 0
  1520. static inline void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
  1521. {
  1522. ring->ring[ring->wptr++] = v;
  1523. ring->wptr &= ring->ptr_mask;
  1524. ring->count_dw--;
  1525. ring->ring_free_dw--;
  1526. }
  1527. #else
  1528. /* With debugging this is just too big to inline */
  1529. void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
  1530. #endif
  1531. /*
  1532. * ASICs macro.
  1533. */
  1534. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  1535. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  1536. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  1537. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  1538. #define radeon_cs_parse(rdev, r, p) (rdev)->asic->ring[(r)].cs_parse((p))
  1539. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  1540. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  1541. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart.tlb_flush((rdev))
  1542. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart.set_page((rdev), (i), (p))
  1543. #define radeon_ring_start(rdev, r, cp) (rdev)->asic->ring[(r)].ring_start((rdev), (cp))
  1544. #define radeon_ring_test(rdev, r, cp) (rdev)->asic->ring[(r)].ring_test((rdev), (cp))
  1545. #define radeon_ib_test(rdev, r, cp) (rdev)->asic->ring[(r)].ib_test((rdev), (cp))
  1546. #define radeon_ring_ib_execute(rdev, r, ib) (rdev)->asic->ring[(r)].ib_execute((rdev), (ib))
  1547. #define radeon_ring_ib_parse(rdev, r, ib) (rdev)->asic->ring[(r)].ib_parse((rdev), (ib))
  1548. #define radeon_ring_is_lockup(rdev, r, cp) (rdev)->asic->ring[(r)].is_lockup((rdev), (cp))
  1549. #define radeon_irq_set(rdev) (rdev)->asic->irq.set((rdev))
  1550. #define radeon_irq_process(rdev) (rdev)->asic->irq.process((rdev))
  1551. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->display.get_vblank_counter((rdev), (crtc))
  1552. #define radeon_fence_ring_emit(rdev, r, fence) (rdev)->asic->ring[(r)].emit_fence((rdev), (fence))
  1553. #define radeon_semaphore_ring_emit(rdev, r, cp, semaphore, emit_wait) (rdev)->asic->ring[(r)].emit_semaphore((rdev), (cp), (semaphore), (emit_wait))
  1554. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy.blit((rdev), (s), (d), (np), (f))
  1555. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy.dma((rdev), (s), (d), (np), (f))
  1556. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy.copy((rdev), (s), (d), (np), (f))
  1557. #define radeon_copy_blit_ring_index(rdev) (rdev)->asic->copy.blit_ring_index
  1558. #define radeon_copy_dma_ring_index(rdev) (rdev)->asic->copy.dma_ring_index
  1559. #define radeon_copy_ring_index(rdev) (rdev)->asic->copy.copy_ring_index
  1560. #define radeon_get_engine_clock(rdev) (rdev)->asic->pm.get_engine_clock((rdev))
  1561. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->pm.set_engine_clock((rdev), (e))
  1562. #define radeon_get_memory_clock(rdev) (rdev)->asic->pm.get_memory_clock((rdev))
  1563. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->pm.set_memory_clock((rdev), (e))
  1564. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->pm.get_pcie_lanes((rdev))
  1565. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->pm.set_pcie_lanes((rdev), (l))
  1566. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->pm.set_clock_gating((rdev), (e))
  1567. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->surface.set_reg((rdev), (r), (f), (p), (o), (s)))
  1568. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->surface.clear_reg((rdev), (r)))
  1569. #define radeon_bandwidth_update(rdev) (rdev)->asic->display.bandwidth_update((rdev))
  1570. #define radeon_hpd_init(rdev) (rdev)->asic->hpd.init((rdev))
  1571. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd.fini((rdev))
  1572. #define radeon_hpd_sense(rdev, h) (rdev)->asic->hpd.sense((rdev), (h))
  1573. #define radeon_hpd_set_polarity(rdev, h) (rdev)->asic->hpd.set_polarity((rdev), (h))
  1574. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  1575. #define radeon_pm_misc(rdev) (rdev)->asic->pm.misc((rdev))
  1576. #define radeon_pm_prepare(rdev) (rdev)->asic->pm.prepare((rdev))
  1577. #define radeon_pm_finish(rdev) (rdev)->asic->pm.finish((rdev))
  1578. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm.init_profile((rdev))
  1579. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm.get_dynpm_state((rdev))
  1580. #define radeon_pre_page_flip(rdev, crtc) rdev->asic->pflip.pre_page_flip((rdev), (crtc))
  1581. #define radeon_page_flip(rdev, crtc, base) rdev->asic->pflip.page_flip((rdev), (crtc), (base))
  1582. #define radeon_post_page_flip(rdev, crtc) rdev->asic->pflip.post_page_flip((rdev), (crtc))
  1583. #define radeon_wait_for_vblank(rdev, crtc) rdev->asic->display.wait_for_vblank((rdev), (crtc))
  1584. #define radeon_mc_wait_for_idle(rdev) rdev->asic->mc_wait_for_idle((rdev))
  1585. /* Common functions */
  1586. /* AGP */
  1587. extern int radeon_gpu_reset(struct radeon_device *rdev);
  1588. extern void radeon_agp_disable(struct radeon_device *rdev);
  1589. extern int radeon_modeset_init(struct radeon_device *rdev);
  1590. extern void radeon_modeset_fini(struct radeon_device *rdev);
  1591. extern bool radeon_card_posted(struct radeon_device *rdev);
  1592. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  1593. extern void radeon_update_display_priority(struct radeon_device *rdev);
  1594. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  1595. extern void radeon_scratch_init(struct radeon_device *rdev);
  1596. extern void radeon_wb_fini(struct radeon_device *rdev);
  1597. extern int radeon_wb_init(struct radeon_device *rdev);
  1598. extern void radeon_wb_disable(struct radeon_device *rdev);
  1599. extern void radeon_surface_init(struct radeon_device *rdev);
  1600. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  1601. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  1602. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  1603. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  1604. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  1605. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  1606. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  1607. extern int radeon_resume_kms(struct drm_device *dev);
  1608. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  1609. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  1610. /*
  1611. * vm
  1612. */
  1613. int radeon_vm_manager_init(struct radeon_device *rdev);
  1614. void radeon_vm_manager_fini(struct radeon_device *rdev);
  1615. int radeon_vm_manager_start(struct radeon_device *rdev);
  1616. int radeon_vm_manager_suspend(struct radeon_device *rdev);
  1617. int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm);
  1618. void radeon_vm_fini(struct radeon_device *rdev, struct radeon_vm *vm);
  1619. int radeon_vm_bind(struct radeon_device *rdev, struct radeon_vm *vm);
  1620. void radeon_vm_unbind(struct radeon_device *rdev, struct radeon_vm *vm);
  1621. int radeon_vm_bo_update_pte(struct radeon_device *rdev,
  1622. struct radeon_vm *vm,
  1623. struct radeon_bo *bo,
  1624. struct ttm_mem_reg *mem);
  1625. void radeon_vm_bo_invalidate(struct radeon_device *rdev,
  1626. struct radeon_bo *bo);
  1627. int radeon_vm_bo_add(struct radeon_device *rdev,
  1628. struct radeon_vm *vm,
  1629. struct radeon_bo *bo,
  1630. uint64_t offset,
  1631. uint32_t flags);
  1632. int radeon_vm_bo_rmv(struct radeon_device *rdev,
  1633. struct radeon_vm *vm,
  1634. struct radeon_bo *bo);
  1635. /* audio */
  1636. void r600_audio_update_hdmi(struct work_struct *work);
  1637. /*
  1638. * R600 vram scratch functions
  1639. */
  1640. int r600_vram_scratch_init(struct radeon_device *rdev);
  1641. void r600_vram_scratch_fini(struct radeon_device *rdev);
  1642. /*
  1643. * r600 cs checking helper
  1644. */
  1645. unsigned r600_mip_minify(unsigned size, unsigned level);
  1646. bool r600_fmt_is_valid_color(u32 format);
  1647. bool r600_fmt_is_valid_texture(u32 format, enum radeon_family family);
  1648. int r600_fmt_get_blocksize(u32 format);
  1649. int r600_fmt_get_nblocksx(u32 format, u32 w);
  1650. int r600_fmt_get_nblocksy(u32 format, u32 h);
  1651. /*
  1652. * r600 functions used by radeon_encoder.c
  1653. */
  1654. struct radeon_hdmi_acr {
  1655. u32 clock;
  1656. int n_32khz;
  1657. int cts_32khz;
  1658. int n_44_1khz;
  1659. int cts_44_1khz;
  1660. int n_48khz;
  1661. int cts_48khz;
  1662. };
  1663. extern struct radeon_hdmi_acr r600_hdmi_acr(uint32_t clock);
  1664. extern void r600_hdmi_enable(struct drm_encoder *encoder);
  1665. extern void r600_hdmi_disable(struct drm_encoder *encoder);
  1666. extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1667. extern u32 r6xx_remap_render_backend(struct radeon_device *rdev,
  1668. u32 tiling_pipe_num,
  1669. u32 max_rb_num,
  1670. u32 total_max_rb_num,
  1671. u32 enabled_rb_mask);
  1672. /*
  1673. * evergreen functions used by radeon_encoder.c
  1674. */
  1675. extern void evergreen_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1676. extern int ni_init_microcode(struct radeon_device *rdev);
  1677. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  1678. /* radeon_acpi.c */
  1679. #if defined(CONFIG_ACPI)
  1680. extern int radeon_acpi_init(struct radeon_device *rdev);
  1681. #else
  1682. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  1683. #endif
  1684. #include "radeon_object.h"
  1685. #endif