radeon.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  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. /*
  91. * Copy from radeon_drv.h so we don't have to include both and have conflicting
  92. * symbol;
  93. */
  94. #define RADEON_MAX_USEC_TIMEOUT 100000 /* 100 ms */
  95. #define RADEON_FENCE_JIFFIES_TIMEOUT (HZ / 2)
  96. /* RADEON_IB_POOL_SIZE must be a power of 2 */
  97. #define RADEON_IB_POOL_SIZE 16
  98. #define RADEON_DEBUGFS_MAX_NUM_FILES 32
  99. #define RADEONFB_CONN_LIMIT 4
  100. #define RADEON_BIOS_NUM_SCRATCH 8
  101. /*
  102. * Errata workarounds.
  103. */
  104. enum radeon_pll_errata {
  105. CHIP_ERRATA_R300_CG = 0x00000001,
  106. CHIP_ERRATA_PLL_DUMMYREADS = 0x00000002,
  107. CHIP_ERRATA_PLL_DELAY = 0x00000004
  108. };
  109. struct radeon_device;
  110. /*
  111. * BIOS.
  112. */
  113. #define ATRM_BIOS_PAGE 4096
  114. #if defined(CONFIG_VGA_SWITCHEROO)
  115. bool radeon_atrm_supported(struct pci_dev *pdev);
  116. int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len);
  117. #else
  118. static inline bool radeon_atrm_supported(struct pci_dev *pdev)
  119. {
  120. return false;
  121. }
  122. static inline int radeon_atrm_get_bios_chunk(uint8_t *bios, int offset, int len){
  123. return -EINVAL;
  124. }
  125. #endif
  126. bool radeon_get_bios(struct radeon_device *rdev);
  127. /*
  128. * Dummy page
  129. */
  130. struct radeon_dummy_page {
  131. struct page *page;
  132. dma_addr_t addr;
  133. };
  134. int radeon_dummy_page_init(struct radeon_device *rdev);
  135. void radeon_dummy_page_fini(struct radeon_device *rdev);
  136. /*
  137. * Clocks
  138. */
  139. struct radeon_clock {
  140. struct radeon_pll p1pll;
  141. struct radeon_pll p2pll;
  142. struct radeon_pll dcpll;
  143. struct radeon_pll spll;
  144. struct radeon_pll mpll;
  145. /* 10 Khz units */
  146. uint32_t default_mclk;
  147. uint32_t default_sclk;
  148. uint32_t default_dispclk;
  149. uint32_t dp_extclk;
  150. uint32_t max_pixel_clock;
  151. };
  152. /*
  153. * Power management
  154. */
  155. int radeon_pm_init(struct radeon_device *rdev);
  156. void radeon_pm_fini(struct radeon_device *rdev);
  157. void radeon_pm_compute_clocks(struct radeon_device *rdev);
  158. void radeon_pm_suspend(struct radeon_device *rdev);
  159. void radeon_pm_resume(struct radeon_device *rdev);
  160. void radeon_combios_get_power_modes(struct radeon_device *rdev);
  161. void radeon_atombios_get_power_modes(struct radeon_device *rdev);
  162. void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type);
  163. int radeon_atom_get_max_vddc(struct radeon_device *rdev, u16 *voltage);
  164. void rs690_pm_info(struct radeon_device *rdev);
  165. extern int rv6xx_get_temp(struct radeon_device *rdev);
  166. extern int rv770_get_temp(struct radeon_device *rdev);
  167. extern int evergreen_get_temp(struct radeon_device *rdev);
  168. extern int sumo_get_temp(struct radeon_device *rdev);
  169. /*
  170. * Fences.
  171. */
  172. struct radeon_fence_driver {
  173. uint32_t scratch_reg;
  174. atomic_t seq;
  175. uint32_t last_seq;
  176. unsigned long last_jiffies;
  177. unsigned long last_timeout;
  178. wait_queue_head_t queue;
  179. rwlock_t lock;
  180. struct list_head created;
  181. struct list_head emited;
  182. struct list_head signaled;
  183. bool initialized;
  184. };
  185. struct radeon_fence {
  186. struct radeon_device *rdev;
  187. struct kref kref;
  188. struct list_head list;
  189. /* protected by radeon_fence.lock */
  190. uint32_t seq;
  191. bool emited;
  192. bool signaled;
  193. };
  194. int radeon_fence_driver_init(struct radeon_device *rdev);
  195. void radeon_fence_driver_fini(struct radeon_device *rdev);
  196. int radeon_fence_create(struct radeon_device *rdev, struct radeon_fence **fence);
  197. int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence);
  198. void radeon_fence_process(struct radeon_device *rdev);
  199. bool radeon_fence_signaled(struct radeon_fence *fence);
  200. int radeon_fence_wait(struct radeon_fence *fence, bool interruptible);
  201. int radeon_fence_wait_next(struct radeon_device *rdev);
  202. int radeon_fence_wait_last(struct radeon_device *rdev);
  203. struct radeon_fence *radeon_fence_ref(struct radeon_fence *fence);
  204. void radeon_fence_unref(struct radeon_fence **fence);
  205. /*
  206. * Tiling registers
  207. */
  208. struct radeon_surface_reg {
  209. struct radeon_bo *bo;
  210. };
  211. #define RADEON_GEM_MAX_SURFACES 8
  212. /*
  213. * TTM.
  214. */
  215. struct radeon_mman {
  216. struct ttm_bo_global_ref bo_global_ref;
  217. struct drm_global_reference mem_global_ref;
  218. struct ttm_bo_device bdev;
  219. bool mem_global_referenced;
  220. bool initialized;
  221. };
  222. struct radeon_bo {
  223. /* Protected by gem.mutex */
  224. struct list_head list;
  225. /* Protected by tbo.reserved */
  226. u32 placements[3];
  227. struct ttm_placement placement;
  228. struct ttm_buffer_object tbo;
  229. struct ttm_bo_kmap_obj kmap;
  230. unsigned pin_count;
  231. void *kptr;
  232. u32 tiling_flags;
  233. u32 pitch;
  234. int surface_reg;
  235. /* Constant after initialization */
  236. struct radeon_device *rdev;
  237. struct drm_gem_object gem_base;
  238. };
  239. #define gem_to_radeon_bo(gobj) container_of((gobj), struct radeon_bo, gem_base)
  240. struct radeon_bo_list {
  241. struct ttm_validate_buffer tv;
  242. struct radeon_bo *bo;
  243. uint64_t gpu_offset;
  244. unsigned rdomain;
  245. unsigned wdomain;
  246. u32 tiling_flags;
  247. };
  248. /*
  249. * GEM objects.
  250. */
  251. struct radeon_gem {
  252. struct mutex mutex;
  253. struct list_head objects;
  254. };
  255. int radeon_gem_init(struct radeon_device *rdev);
  256. void radeon_gem_fini(struct radeon_device *rdev);
  257. int radeon_gem_object_create(struct radeon_device *rdev, int size,
  258. int alignment, int initial_domain,
  259. bool discardable, bool kernel,
  260. struct drm_gem_object **obj);
  261. int radeon_gem_object_pin(struct drm_gem_object *obj, uint32_t pin_domain,
  262. uint64_t *gpu_addr);
  263. void radeon_gem_object_unpin(struct drm_gem_object *obj);
  264. int radeon_mode_dumb_create(struct drm_file *file_priv,
  265. struct drm_device *dev,
  266. struct drm_mode_create_dumb *args);
  267. int radeon_mode_dumb_mmap(struct drm_file *filp,
  268. struct drm_device *dev,
  269. uint32_t handle, uint64_t *offset_p);
  270. int radeon_mode_dumb_destroy(struct drm_file *file_priv,
  271. struct drm_device *dev,
  272. uint32_t handle);
  273. /*
  274. * GART structures, functions & helpers
  275. */
  276. struct radeon_mc;
  277. struct radeon_gart_table_ram {
  278. volatile uint32_t *ptr;
  279. };
  280. struct radeon_gart_table_vram {
  281. struct radeon_bo *robj;
  282. volatile uint32_t *ptr;
  283. };
  284. union radeon_gart_table {
  285. struct radeon_gart_table_ram ram;
  286. struct radeon_gart_table_vram vram;
  287. };
  288. #define RADEON_GPU_PAGE_SIZE 4096
  289. #define RADEON_GPU_PAGE_MASK (RADEON_GPU_PAGE_SIZE - 1)
  290. struct radeon_gart {
  291. dma_addr_t table_addr;
  292. unsigned num_gpu_pages;
  293. unsigned num_cpu_pages;
  294. unsigned table_size;
  295. union radeon_gart_table table;
  296. struct page **pages;
  297. dma_addr_t *pages_addr;
  298. bool *ttm_alloced;
  299. bool ready;
  300. };
  301. int radeon_gart_table_ram_alloc(struct radeon_device *rdev);
  302. void radeon_gart_table_ram_free(struct radeon_device *rdev);
  303. int radeon_gart_table_vram_alloc(struct radeon_device *rdev);
  304. void radeon_gart_table_vram_free(struct radeon_device *rdev);
  305. int radeon_gart_init(struct radeon_device *rdev);
  306. void radeon_gart_fini(struct radeon_device *rdev);
  307. void radeon_gart_unbind(struct radeon_device *rdev, unsigned offset,
  308. int pages);
  309. int radeon_gart_bind(struct radeon_device *rdev, unsigned offset,
  310. int pages, struct page **pagelist,
  311. dma_addr_t *dma_addr);
  312. /*
  313. * GPU MC structures, functions & helpers
  314. */
  315. struct radeon_mc {
  316. resource_size_t aper_size;
  317. resource_size_t aper_base;
  318. resource_size_t agp_base;
  319. /* for some chips with <= 32MB we need to lie
  320. * about vram size near mc fb location */
  321. u64 mc_vram_size;
  322. u64 visible_vram_size;
  323. u64 gtt_size;
  324. u64 gtt_start;
  325. u64 gtt_end;
  326. u64 vram_start;
  327. u64 vram_end;
  328. unsigned vram_width;
  329. u64 real_vram_size;
  330. int vram_mtrr;
  331. bool vram_is_ddr;
  332. bool igp_sideport_enabled;
  333. u64 gtt_base_align;
  334. };
  335. bool radeon_combios_sideport_present(struct radeon_device *rdev);
  336. bool radeon_atombios_sideport_present(struct radeon_device *rdev);
  337. /*
  338. * GPU scratch registers structures, functions & helpers
  339. */
  340. struct radeon_scratch {
  341. unsigned num_reg;
  342. uint32_t reg_base;
  343. bool free[32];
  344. uint32_t reg[32];
  345. };
  346. int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg);
  347. void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg);
  348. /*
  349. * IRQS.
  350. */
  351. struct radeon_unpin_work {
  352. struct work_struct work;
  353. struct radeon_device *rdev;
  354. int crtc_id;
  355. struct radeon_fence *fence;
  356. struct drm_pending_vblank_event *event;
  357. struct radeon_bo *old_rbo;
  358. u64 new_crtc_base;
  359. };
  360. struct r500_irq_stat_regs {
  361. u32 disp_int;
  362. };
  363. struct r600_irq_stat_regs {
  364. u32 disp_int;
  365. u32 disp_int_cont;
  366. u32 disp_int_cont2;
  367. u32 d1grph_int;
  368. u32 d2grph_int;
  369. };
  370. struct evergreen_irq_stat_regs {
  371. u32 disp_int;
  372. u32 disp_int_cont;
  373. u32 disp_int_cont2;
  374. u32 disp_int_cont3;
  375. u32 disp_int_cont4;
  376. u32 disp_int_cont5;
  377. u32 d1grph_int;
  378. u32 d2grph_int;
  379. u32 d3grph_int;
  380. u32 d4grph_int;
  381. u32 d5grph_int;
  382. u32 d6grph_int;
  383. };
  384. union radeon_irq_stat_regs {
  385. struct r500_irq_stat_regs r500;
  386. struct r600_irq_stat_regs r600;
  387. struct evergreen_irq_stat_regs evergreen;
  388. };
  389. struct radeon_irq {
  390. bool installed;
  391. bool sw_int;
  392. /* FIXME: use a define max crtc rather than hardcode it */
  393. bool crtc_vblank_int[6];
  394. bool pflip[6];
  395. wait_queue_head_t vblank_queue;
  396. /* FIXME: use defines for max hpd/dacs */
  397. bool hpd[6];
  398. bool gui_idle;
  399. bool gui_idle_acked;
  400. wait_queue_head_t idle_queue;
  401. /* FIXME: use defines for max HDMI blocks */
  402. bool hdmi[2];
  403. spinlock_t sw_lock;
  404. int sw_refcount;
  405. union radeon_irq_stat_regs stat_regs;
  406. spinlock_t pflip_lock[6];
  407. int pflip_refcount[6];
  408. };
  409. int radeon_irq_kms_init(struct radeon_device *rdev);
  410. void radeon_irq_kms_fini(struct radeon_device *rdev);
  411. void radeon_irq_kms_sw_irq_get(struct radeon_device *rdev);
  412. void radeon_irq_kms_sw_irq_put(struct radeon_device *rdev);
  413. void radeon_irq_kms_pflip_irq_get(struct radeon_device *rdev, int crtc);
  414. void radeon_irq_kms_pflip_irq_put(struct radeon_device *rdev, int crtc);
  415. /*
  416. * CP & ring.
  417. */
  418. struct radeon_ib {
  419. struct list_head list;
  420. unsigned idx;
  421. uint64_t gpu_addr;
  422. struct radeon_fence *fence;
  423. uint32_t *ptr;
  424. uint32_t length_dw;
  425. bool free;
  426. };
  427. /*
  428. * locking -
  429. * mutex protects scheduled_ibs, ready, alloc_bm
  430. */
  431. struct radeon_ib_pool {
  432. struct mutex mutex;
  433. struct radeon_bo *robj;
  434. struct list_head bogus_ib;
  435. struct radeon_ib ibs[RADEON_IB_POOL_SIZE];
  436. bool ready;
  437. unsigned head_id;
  438. };
  439. struct radeon_cp {
  440. struct radeon_bo *ring_obj;
  441. volatile uint32_t *ring;
  442. unsigned rptr;
  443. unsigned wptr;
  444. unsigned wptr_old;
  445. unsigned ring_size;
  446. unsigned ring_free_dw;
  447. int count_dw;
  448. uint64_t gpu_addr;
  449. uint32_t align_mask;
  450. uint32_t ptr_mask;
  451. struct mutex mutex;
  452. bool ready;
  453. };
  454. /*
  455. * R6xx+ IH ring
  456. */
  457. struct r600_ih {
  458. struct radeon_bo *ring_obj;
  459. volatile uint32_t *ring;
  460. unsigned rptr;
  461. unsigned wptr;
  462. unsigned wptr_old;
  463. unsigned ring_size;
  464. uint64_t gpu_addr;
  465. uint32_t ptr_mask;
  466. spinlock_t lock;
  467. bool enabled;
  468. };
  469. struct r600_blit {
  470. struct mutex mutex;
  471. struct radeon_bo *shader_obj;
  472. u64 shader_gpu_addr;
  473. u32 vs_offset, ps_offset;
  474. u32 state_offset;
  475. u32 state_len;
  476. u32 vb_used, vb_total;
  477. struct radeon_ib *vb_ib;
  478. };
  479. int radeon_ib_get(struct radeon_device *rdev, struct radeon_ib **ib);
  480. void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib **ib);
  481. int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib);
  482. int radeon_ib_pool_init(struct radeon_device *rdev);
  483. void radeon_ib_pool_fini(struct radeon_device *rdev);
  484. int radeon_ib_test(struct radeon_device *rdev);
  485. extern void radeon_ib_bogus_add(struct radeon_device *rdev, struct radeon_ib *ib);
  486. /* Ring access between begin & end cannot sleep */
  487. void radeon_ring_free_size(struct radeon_device *rdev);
  488. int radeon_ring_alloc(struct radeon_device *rdev, unsigned ndw);
  489. int radeon_ring_lock(struct radeon_device *rdev, unsigned ndw);
  490. void radeon_ring_commit(struct radeon_device *rdev);
  491. void radeon_ring_unlock_commit(struct radeon_device *rdev);
  492. void radeon_ring_unlock_undo(struct radeon_device *rdev);
  493. int radeon_ring_test(struct radeon_device *rdev);
  494. int radeon_ring_init(struct radeon_device *rdev, unsigned ring_size);
  495. void radeon_ring_fini(struct radeon_device *rdev);
  496. /*
  497. * CS.
  498. */
  499. struct radeon_cs_reloc {
  500. struct drm_gem_object *gobj;
  501. struct radeon_bo *robj;
  502. struct radeon_bo_list lobj;
  503. uint32_t handle;
  504. uint32_t flags;
  505. };
  506. struct radeon_cs_chunk {
  507. uint32_t chunk_id;
  508. uint32_t length_dw;
  509. int kpage_idx[2];
  510. uint32_t *kpage[2];
  511. uint32_t *kdata;
  512. void __user *user_ptr;
  513. int last_copied_page;
  514. int last_page_index;
  515. };
  516. struct radeon_cs_parser {
  517. struct device *dev;
  518. struct radeon_device *rdev;
  519. struct drm_file *filp;
  520. /* chunks */
  521. unsigned nchunks;
  522. struct radeon_cs_chunk *chunks;
  523. uint64_t *chunks_array;
  524. /* IB */
  525. unsigned idx;
  526. /* relocations */
  527. unsigned nrelocs;
  528. struct radeon_cs_reloc *relocs;
  529. struct radeon_cs_reloc **relocs_ptr;
  530. struct list_head validated;
  531. /* indices of various chunks */
  532. int chunk_ib_idx;
  533. int chunk_relocs_idx;
  534. struct radeon_ib *ib;
  535. void *track;
  536. unsigned family;
  537. int parser_error;
  538. };
  539. extern int radeon_cs_update_pages(struct radeon_cs_parser *p, int pg_idx);
  540. extern int radeon_cs_finish_pages(struct radeon_cs_parser *p);
  541. static inline u32 radeon_get_ib_value(struct radeon_cs_parser *p, int idx)
  542. {
  543. struct radeon_cs_chunk *ibc = &p->chunks[p->chunk_ib_idx];
  544. u32 pg_idx, pg_offset;
  545. u32 idx_value = 0;
  546. int new_page;
  547. pg_idx = (idx * 4) / PAGE_SIZE;
  548. pg_offset = (idx * 4) % PAGE_SIZE;
  549. if (ibc->kpage_idx[0] == pg_idx)
  550. return ibc->kpage[0][pg_offset/4];
  551. if (ibc->kpage_idx[1] == pg_idx)
  552. return ibc->kpage[1][pg_offset/4];
  553. new_page = radeon_cs_update_pages(p, pg_idx);
  554. if (new_page < 0) {
  555. p->parser_error = new_page;
  556. return 0;
  557. }
  558. idx_value = ibc->kpage[new_page][pg_offset/4];
  559. return idx_value;
  560. }
  561. struct radeon_cs_packet {
  562. unsigned idx;
  563. unsigned type;
  564. unsigned reg;
  565. unsigned opcode;
  566. int count;
  567. unsigned one_reg_wr;
  568. };
  569. typedef int (*radeon_packet0_check_t)(struct radeon_cs_parser *p,
  570. struct radeon_cs_packet *pkt,
  571. unsigned idx, unsigned reg);
  572. typedef int (*radeon_packet3_check_t)(struct radeon_cs_parser *p,
  573. struct radeon_cs_packet *pkt);
  574. /*
  575. * AGP
  576. */
  577. int radeon_agp_init(struct radeon_device *rdev);
  578. void radeon_agp_resume(struct radeon_device *rdev);
  579. void radeon_agp_suspend(struct radeon_device *rdev);
  580. void radeon_agp_fini(struct radeon_device *rdev);
  581. /*
  582. * Writeback
  583. */
  584. struct radeon_wb {
  585. struct radeon_bo *wb_obj;
  586. volatile uint32_t *wb;
  587. uint64_t gpu_addr;
  588. bool enabled;
  589. bool use_event;
  590. };
  591. #define RADEON_WB_SCRATCH_OFFSET 0
  592. #define RADEON_WB_CP_RPTR_OFFSET 1024
  593. #define RADEON_WB_CP1_RPTR_OFFSET 1280
  594. #define RADEON_WB_CP2_RPTR_OFFSET 1536
  595. #define R600_WB_IH_WPTR_OFFSET 2048
  596. #define R600_WB_EVENT_OFFSET 3072
  597. /**
  598. * struct radeon_pm - power management datas
  599. * @max_bandwidth: maximum bandwidth the gpu has (MByte/s)
  600. * @igp_sideport_mclk: sideport memory clock Mhz (rs690,rs740,rs780,rs880)
  601. * @igp_system_mclk: system clock Mhz (rs690,rs740,rs780,rs880)
  602. * @igp_ht_link_clk: ht link clock Mhz (rs690,rs740,rs780,rs880)
  603. * @igp_ht_link_width: ht link width in bits (rs690,rs740,rs780,rs880)
  604. * @k8_bandwidth: k8 bandwidth the gpu has (MByte/s) (IGP)
  605. * @sideport_bandwidth: sideport bandwidth the gpu has (MByte/s) (IGP)
  606. * @ht_bandwidth: ht bandwidth the gpu has (MByte/s) (IGP)
  607. * @core_bandwidth: core GPU bandwidth the gpu has (MByte/s) (IGP)
  608. * @sclk: GPU clock Mhz (core bandwidth depends of this clock)
  609. * @needed_bandwidth: current bandwidth needs
  610. *
  611. * It keeps track of various data needed to take powermanagement decision.
  612. * Bandwidth need is used to determine minimun clock of the GPU and memory.
  613. * Equation between gpu/memory clock and available bandwidth is hw dependent
  614. * (type of memory, bus size, efficiency, ...)
  615. */
  616. enum radeon_pm_method {
  617. PM_METHOD_PROFILE,
  618. PM_METHOD_DYNPM,
  619. };
  620. enum radeon_dynpm_state {
  621. DYNPM_STATE_DISABLED,
  622. DYNPM_STATE_MINIMUM,
  623. DYNPM_STATE_PAUSED,
  624. DYNPM_STATE_ACTIVE,
  625. DYNPM_STATE_SUSPENDED,
  626. };
  627. enum radeon_dynpm_action {
  628. DYNPM_ACTION_NONE,
  629. DYNPM_ACTION_MINIMUM,
  630. DYNPM_ACTION_DOWNCLOCK,
  631. DYNPM_ACTION_UPCLOCK,
  632. DYNPM_ACTION_DEFAULT
  633. };
  634. enum radeon_voltage_type {
  635. VOLTAGE_NONE = 0,
  636. VOLTAGE_GPIO,
  637. VOLTAGE_VDDC,
  638. VOLTAGE_SW
  639. };
  640. enum radeon_pm_state_type {
  641. POWER_STATE_TYPE_DEFAULT,
  642. POWER_STATE_TYPE_POWERSAVE,
  643. POWER_STATE_TYPE_BATTERY,
  644. POWER_STATE_TYPE_BALANCED,
  645. POWER_STATE_TYPE_PERFORMANCE,
  646. };
  647. enum radeon_pm_profile_type {
  648. PM_PROFILE_DEFAULT,
  649. PM_PROFILE_AUTO,
  650. PM_PROFILE_LOW,
  651. PM_PROFILE_MID,
  652. PM_PROFILE_HIGH,
  653. };
  654. #define PM_PROFILE_DEFAULT_IDX 0
  655. #define PM_PROFILE_LOW_SH_IDX 1
  656. #define PM_PROFILE_MID_SH_IDX 2
  657. #define PM_PROFILE_HIGH_SH_IDX 3
  658. #define PM_PROFILE_LOW_MH_IDX 4
  659. #define PM_PROFILE_MID_MH_IDX 5
  660. #define PM_PROFILE_HIGH_MH_IDX 6
  661. #define PM_PROFILE_MAX 7
  662. struct radeon_pm_profile {
  663. int dpms_off_ps_idx;
  664. int dpms_on_ps_idx;
  665. int dpms_off_cm_idx;
  666. int dpms_on_cm_idx;
  667. };
  668. enum radeon_int_thermal_type {
  669. THERMAL_TYPE_NONE,
  670. THERMAL_TYPE_RV6XX,
  671. THERMAL_TYPE_RV770,
  672. THERMAL_TYPE_EVERGREEN,
  673. THERMAL_TYPE_SUMO,
  674. THERMAL_TYPE_NI,
  675. };
  676. struct radeon_voltage {
  677. enum radeon_voltage_type type;
  678. /* gpio voltage */
  679. struct radeon_gpio_rec gpio;
  680. u32 delay; /* delay in usec from voltage drop to sclk change */
  681. bool active_high; /* voltage drop is active when bit is high */
  682. /* VDDC voltage */
  683. u8 vddc_id; /* index into vddc voltage table */
  684. u8 vddci_id; /* index into vddci voltage table */
  685. bool vddci_enabled;
  686. /* r6xx+ sw */
  687. u16 voltage;
  688. /* evergreen+ vddci */
  689. u16 vddci;
  690. };
  691. /* clock mode flags */
  692. #define RADEON_PM_MODE_NO_DISPLAY (1 << 0)
  693. struct radeon_pm_clock_info {
  694. /* memory clock */
  695. u32 mclk;
  696. /* engine clock */
  697. u32 sclk;
  698. /* voltage info */
  699. struct radeon_voltage voltage;
  700. /* standardized clock flags */
  701. u32 flags;
  702. };
  703. /* state flags */
  704. #define RADEON_PM_STATE_SINGLE_DISPLAY_ONLY (1 << 0)
  705. struct radeon_power_state {
  706. enum radeon_pm_state_type type;
  707. /* XXX: use a define for num clock modes */
  708. struct radeon_pm_clock_info clock_info[8];
  709. /* number of valid clock modes in this power state */
  710. int num_clock_modes;
  711. struct radeon_pm_clock_info *default_clock_mode;
  712. /* standardized state flags */
  713. u32 flags;
  714. u32 misc; /* vbios specific flags */
  715. u32 misc2; /* vbios specific flags */
  716. int pcie_lanes; /* pcie lanes */
  717. };
  718. /*
  719. * Some modes are overclocked by very low value, accept them
  720. */
  721. #define RADEON_MODE_OVERCLOCK_MARGIN 500 /* 5 MHz */
  722. struct radeon_pm {
  723. struct mutex mutex;
  724. u32 active_crtcs;
  725. int active_crtc_count;
  726. int req_vblank;
  727. bool vblank_sync;
  728. bool gui_idle;
  729. fixed20_12 max_bandwidth;
  730. fixed20_12 igp_sideport_mclk;
  731. fixed20_12 igp_system_mclk;
  732. fixed20_12 igp_ht_link_clk;
  733. fixed20_12 igp_ht_link_width;
  734. fixed20_12 k8_bandwidth;
  735. fixed20_12 sideport_bandwidth;
  736. fixed20_12 ht_bandwidth;
  737. fixed20_12 core_bandwidth;
  738. fixed20_12 sclk;
  739. fixed20_12 mclk;
  740. fixed20_12 needed_bandwidth;
  741. struct radeon_power_state *power_state;
  742. /* number of valid power states */
  743. int num_power_states;
  744. int current_power_state_index;
  745. int current_clock_mode_index;
  746. int requested_power_state_index;
  747. int requested_clock_mode_index;
  748. int default_power_state_index;
  749. u32 current_sclk;
  750. u32 current_mclk;
  751. u16 current_vddc;
  752. u16 current_vddci;
  753. u32 default_sclk;
  754. u32 default_mclk;
  755. u16 default_vddc;
  756. u16 default_vddci;
  757. struct radeon_i2c_chan *i2c_bus;
  758. /* selected pm method */
  759. enum radeon_pm_method pm_method;
  760. /* dynpm power management */
  761. struct delayed_work dynpm_idle_work;
  762. enum radeon_dynpm_state dynpm_state;
  763. enum radeon_dynpm_action dynpm_planned_action;
  764. unsigned long dynpm_action_timeout;
  765. bool dynpm_can_upclock;
  766. bool dynpm_can_downclock;
  767. /* profile-based power management */
  768. enum radeon_pm_profile_type profile;
  769. int profile_index;
  770. struct radeon_pm_profile profiles[PM_PROFILE_MAX];
  771. /* internal thermal controller on rv6xx+ */
  772. enum radeon_int_thermal_type int_thermal_type;
  773. struct device *int_hwmon_dev;
  774. };
  775. /*
  776. * Benchmarking
  777. */
  778. void radeon_benchmark(struct radeon_device *rdev);
  779. /*
  780. * Testing
  781. */
  782. void radeon_test_moves(struct radeon_device *rdev);
  783. /*
  784. * Debugfs
  785. */
  786. int radeon_debugfs_add_files(struct radeon_device *rdev,
  787. struct drm_info_list *files,
  788. unsigned nfiles);
  789. int radeon_debugfs_fence_init(struct radeon_device *rdev);
  790. /*
  791. * ASIC specific functions.
  792. */
  793. struct radeon_asic {
  794. int (*init)(struct radeon_device *rdev);
  795. void (*fini)(struct radeon_device *rdev);
  796. int (*resume)(struct radeon_device *rdev);
  797. int (*suspend)(struct radeon_device *rdev);
  798. void (*vga_set_state)(struct radeon_device *rdev, bool state);
  799. bool (*gpu_is_lockup)(struct radeon_device *rdev);
  800. int (*asic_reset)(struct radeon_device *rdev);
  801. void (*gart_tlb_flush)(struct radeon_device *rdev);
  802. int (*gart_set_page)(struct radeon_device *rdev, int i, uint64_t addr);
  803. int (*cp_init)(struct radeon_device *rdev, unsigned ring_size);
  804. void (*cp_fini)(struct radeon_device *rdev);
  805. void (*cp_disable)(struct radeon_device *rdev);
  806. void (*cp_commit)(struct radeon_device *rdev);
  807. void (*ring_start)(struct radeon_device *rdev);
  808. int (*ring_test)(struct radeon_device *rdev);
  809. void (*ring_ib_execute)(struct radeon_device *rdev, struct radeon_ib *ib);
  810. int (*irq_set)(struct radeon_device *rdev);
  811. int (*irq_process)(struct radeon_device *rdev);
  812. u32 (*get_vblank_counter)(struct radeon_device *rdev, int crtc);
  813. void (*fence_ring_emit)(struct radeon_device *rdev, struct radeon_fence *fence);
  814. int (*cs_parse)(struct radeon_cs_parser *p);
  815. int (*copy_blit)(struct radeon_device *rdev,
  816. uint64_t src_offset,
  817. uint64_t dst_offset,
  818. unsigned num_pages,
  819. struct radeon_fence *fence);
  820. int (*copy_dma)(struct radeon_device *rdev,
  821. uint64_t src_offset,
  822. uint64_t dst_offset,
  823. unsigned num_pages,
  824. struct radeon_fence *fence);
  825. int (*copy)(struct radeon_device *rdev,
  826. uint64_t src_offset,
  827. uint64_t dst_offset,
  828. unsigned num_pages,
  829. struct radeon_fence *fence);
  830. uint32_t (*get_engine_clock)(struct radeon_device *rdev);
  831. void (*set_engine_clock)(struct radeon_device *rdev, uint32_t eng_clock);
  832. uint32_t (*get_memory_clock)(struct radeon_device *rdev);
  833. void (*set_memory_clock)(struct radeon_device *rdev, uint32_t mem_clock);
  834. int (*get_pcie_lanes)(struct radeon_device *rdev);
  835. void (*set_pcie_lanes)(struct radeon_device *rdev, int lanes);
  836. void (*set_clock_gating)(struct radeon_device *rdev, int enable);
  837. int (*set_surface_reg)(struct radeon_device *rdev, int reg,
  838. uint32_t tiling_flags, uint32_t pitch,
  839. uint32_t offset, uint32_t obj_size);
  840. void (*clear_surface_reg)(struct radeon_device *rdev, int reg);
  841. void (*bandwidth_update)(struct radeon_device *rdev);
  842. void (*hpd_init)(struct radeon_device *rdev);
  843. void (*hpd_fini)(struct radeon_device *rdev);
  844. bool (*hpd_sense)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  845. void (*hpd_set_polarity)(struct radeon_device *rdev, enum radeon_hpd_id hpd);
  846. /* ioctl hw specific callback. Some hw might want to perform special
  847. * operation on specific ioctl. For instance on wait idle some hw
  848. * might want to perform and HDP flush through MMIO as it seems that
  849. * some R6XX/R7XX hw doesn't take HDP flush into account if programmed
  850. * through ring.
  851. */
  852. void (*ioctl_wait_idle)(struct radeon_device *rdev, struct radeon_bo *bo);
  853. bool (*gui_idle)(struct radeon_device *rdev);
  854. /* power management */
  855. void (*pm_misc)(struct radeon_device *rdev);
  856. void (*pm_prepare)(struct radeon_device *rdev);
  857. void (*pm_finish)(struct radeon_device *rdev);
  858. void (*pm_init_profile)(struct radeon_device *rdev);
  859. void (*pm_get_dynpm_state)(struct radeon_device *rdev);
  860. /* pageflipping */
  861. void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
  862. u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
  863. void (*post_page_flip)(struct radeon_device *rdev, int crtc);
  864. };
  865. /*
  866. * Asic structures
  867. */
  868. struct r100_gpu_lockup {
  869. unsigned long last_jiffies;
  870. u32 last_cp_rptr;
  871. };
  872. struct r100_asic {
  873. const unsigned *reg_safe_bm;
  874. unsigned reg_safe_bm_size;
  875. u32 hdp_cntl;
  876. struct r100_gpu_lockup lockup;
  877. };
  878. struct r300_asic {
  879. const unsigned *reg_safe_bm;
  880. unsigned reg_safe_bm_size;
  881. u32 resync_scratch;
  882. u32 hdp_cntl;
  883. struct r100_gpu_lockup lockup;
  884. };
  885. struct r600_asic {
  886. unsigned max_pipes;
  887. unsigned max_tile_pipes;
  888. unsigned max_simds;
  889. unsigned max_backends;
  890. unsigned max_gprs;
  891. unsigned max_threads;
  892. unsigned max_stack_entries;
  893. unsigned max_hw_contexts;
  894. unsigned max_gs_threads;
  895. unsigned sx_max_export_size;
  896. unsigned sx_max_export_pos_size;
  897. unsigned sx_max_export_smx_size;
  898. unsigned sq_num_cf_insts;
  899. unsigned tiling_nbanks;
  900. unsigned tiling_npipes;
  901. unsigned tiling_group_size;
  902. unsigned tile_config;
  903. unsigned backend_map;
  904. struct r100_gpu_lockup lockup;
  905. };
  906. struct rv770_asic {
  907. unsigned max_pipes;
  908. unsigned max_tile_pipes;
  909. unsigned max_simds;
  910. unsigned max_backends;
  911. unsigned max_gprs;
  912. unsigned max_threads;
  913. unsigned max_stack_entries;
  914. unsigned max_hw_contexts;
  915. unsigned max_gs_threads;
  916. unsigned sx_max_export_size;
  917. unsigned sx_max_export_pos_size;
  918. unsigned sx_max_export_smx_size;
  919. unsigned sq_num_cf_insts;
  920. unsigned sx_num_of_sets;
  921. unsigned sc_prim_fifo_size;
  922. unsigned sc_hiz_tile_fifo_size;
  923. unsigned sc_earlyz_tile_fifo_fize;
  924. unsigned tiling_nbanks;
  925. unsigned tiling_npipes;
  926. unsigned tiling_group_size;
  927. unsigned tile_config;
  928. unsigned backend_map;
  929. struct r100_gpu_lockup lockup;
  930. };
  931. struct evergreen_asic {
  932. unsigned num_ses;
  933. unsigned max_pipes;
  934. unsigned max_tile_pipes;
  935. unsigned max_simds;
  936. unsigned max_backends;
  937. unsigned max_gprs;
  938. unsigned max_threads;
  939. unsigned max_stack_entries;
  940. unsigned max_hw_contexts;
  941. unsigned max_gs_threads;
  942. unsigned sx_max_export_size;
  943. unsigned sx_max_export_pos_size;
  944. unsigned sx_max_export_smx_size;
  945. unsigned sq_num_cf_insts;
  946. unsigned sx_num_of_sets;
  947. unsigned sc_prim_fifo_size;
  948. unsigned sc_hiz_tile_fifo_size;
  949. unsigned sc_earlyz_tile_fifo_size;
  950. unsigned tiling_nbanks;
  951. unsigned tiling_npipes;
  952. unsigned tiling_group_size;
  953. unsigned tile_config;
  954. unsigned backend_map;
  955. struct r100_gpu_lockup lockup;
  956. };
  957. struct cayman_asic {
  958. unsigned max_shader_engines;
  959. unsigned max_pipes_per_simd;
  960. unsigned max_tile_pipes;
  961. unsigned max_simds_per_se;
  962. unsigned max_backends_per_se;
  963. unsigned max_texture_channel_caches;
  964. unsigned max_gprs;
  965. unsigned max_threads;
  966. unsigned max_gs_threads;
  967. unsigned max_stack_entries;
  968. unsigned sx_num_of_sets;
  969. unsigned sx_max_export_size;
  970. unsigned sx_max_export_pos_size;
  971. unsigned sx_max_export_smx_size;
  972. unsigned max_hw_contexts;
  973. unsigned sq_num_cf_insts;
  974. unsigned sc_prim_fifo_size;
  975. unsigned sc_hiz_tile_fifo_size;
  976. unsigned sc_earlyz_tile_fifo_size;
  977. unsigned num_shader_engines;
  978. unsigned num_shader_pipes_per_simd;
  979. unsigned num_tile_pipes;
  980. unsigned num_simds_per_se;
  981. unsigned num_backends_per_se;
  982. unsigned backend_disable_mask_per_asic;
  983. unsigned backend_map;
  984. unsigned num_texture_channel_caches;
  985. unsigned mem_max_burst_length_bytes;
  986. unsigned mem_row_size_in_kb;
  987. unsigned shader_engine_tile_size;
  988. unsigned num_gpus;
  989. unsigned multi_gpu_tile_size;
  990. unsigned tile_config;
  991. struct r100_gpu_lockup lockup;
  992. };
  993. union radeon_asic_config {
  994. struct r300_asic r300;
  995. struct r100_asic r100;
  996. struct r600_asic r600;
  997. struct rv770_asic rv770;
  998. struct evergreen_asic evergreen;
  999. struct cayman_asic cayman;
  1000. };
  1001. /*
  1002. * asic initizalization from radeon_asic.c
  1003. */
  1004. void radeon_agp_disable(struct radeon_device *rdev);
  1005. int radeon_asic_init(struct radeon_device *rdev);
  1006. /*
  1007. * IOCTL.
  1008. */
  1009. int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
  1010. struct drm_file *filp);
  1011. int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
  1012. struct drm_file *filp);
  1013. int radeon_gem_pin_ioctl(struct drm_device *dev, void *data,
  1014. struct drm_file *file_priv);
  1015. int radeon_gem_unpin_ioctl(struct drm_device *dev, void *data,
  1016. struct drm_file *file_priv);
  1017. int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  1018. struct drm_file *file_priv);
  1019. int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
  1020. struct drm_file *file_priv);
  1021. int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  1022. struct drm_file *filp);
  1023. int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
  1024. struct drm_file *filp);
  1025. int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
  1026. struct drm_file *filp);
  1027. int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
  1028. struct drm_file *filp);
  1029. int radeon_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
  1030. int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
  1031. struct drm_file *filp);
  1032. int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
  1033. struct drm_file *filp);
  1034. /* VRAM scratch page for HDP bug */
  1035. struct r700_vram_scratch {
  1036. struct radeon_bo *robj;
  1037. volatile uint32_t *ptr;
  1038. };
  1039. /*
  1040. * Core structure, functions and helpers.
  1041. */
  1042. typedef uint32_t (*radeon_rreg_t)(struct radeon_device*, uint32_t);
  1043. typedef void (*radeon_wreg_t)(struct radeon_device*, uint32_t, uint32_t);
  1044. struct radeon_device {
  1045. struct device *dev;
  1046. struct drm_device *ddev;
  1047. struct pci_dev *pdev;
  1048. /* ASIC */
  1049. union radeon_asic_config config;
  1050. enum radeon_family family;
  1051. unsigned long flags;
  1052. int usec_timeout;
  1053. enum radeon_pll_errata pll_errata;
  1054. int num_gb_pipes;
  1055. int num_z_pipes;
  1056. int disp_priority;
  1057. /* BIOS */
  1058. uint8_t *bios;
  1059. bool is_atom_bios;
  1060. uint16_t bios_header_start;
  1061. struct radeon_bo *stollen_vga_memory;
  1062. /* Register mmio */
  1063. resource_size_t rmmio_base;
  1064. resource_size_t rmmio_size;
  1065. void __iomem *rmmio;
  1066. radeon_rreg_t mc_rreg;
  1067. radeon_wreg_t mc_wreg;
  1068. radeon_rreg_t pll_rreg;
  1069. radeon_wreg_t pll_wreg;
  1070. uint32_t pcie_reg_mask;
  1071. radeon_rreg_t pciep_rreg;
  1072. radeon_wreg_t pciep_wreg;
  1073. /* io port */
  1074. void __iomem *rio_mem;
  1075. resource_size_t rio_mem_size;
  1076. struct radeon_clock clock;
  1077. struct radeon_mc mc;
  1078. struct radeon_gart gart;
  1079. struct radeon_mode_info mode_info;
  1080. struct radeon_scratch scratch;
  1081. struct radeon_mman mman;
  1082. struct radeon_fence_driver fence_drv;
  1083. struct radeon_cp cp;
  1084. /* cayman compute rings */
  1085. struct radeon_cp cp1;
  1086. struct radeon_cp cp2;
  1087. struct radeon_ib_pool ib_pool;
  1088. struct radeon_irq irq;
  1089. struct radeon_asic *asic;
  1090. struct radeon_gem gem;
  1091. struct radeon_pm pm;
  1092. uint32_t bios_scratch[RADEON_BIOS_NUM_SCRATCH];
  1093. struct mutex cs_mutex;
  1094. struct radeon_wb wb;
  1095. struct radeon_dummy_page dummy_page;
  1096. bool gpu_lockup;
  1097. bool shutdown;
  1098. bool suspend;
  1099. bool need_dma32;
  1100. bool accel_working;
  1101. struct radeon_surface_reg surface_regs[RADEON_GEM_MAX_SURFACES];
  1102. const struct firmware *me_fw; /* all family ME firmware */
  1103. const struct firmware *pfp_fw; /* r6/700 PFP firmware */
  1104. const struct firmware *rlc_fw; /* r6/700 RLC firmware */
  1105. const struct firmware *mc_fw; /* NI MC firmware */
  1106. struct r600_blit r600_blit;
  1107. struct r700_vram_scratch vram_scratch;
  1108. int msi_enabled; /* msi enabled */
  1109. struct r600_ih ih; /* r6/700 interrupt ring */
  1110. struct work_struct hotplug_work;
  1111. int num_crtc; /* number of crtcs */
  1112. struct mutex dc_hw_i2c_mutex; /* display controller hw i2c mutex */
  1113. struct mutex vram_mutex;
  1114. /* audio stuff */
  1115. bool audio_enabled;
  1116. struct timer_list audio_timer;
  1117. int audio_channels;
  1118. int audio_rate;
  1119. int audio_bits_per_sample;
  1120. uint8_t audio_status_bits;
  1121. uint8_t audio_category_code;
  1122. struct notifier_block acpi_nb;
  1123. /* only one userspace can use Hyperz features or CMASK at a time */
  1124. struct drm_file *hyperz_filp;
  1125. struct drm_file *cmask_filp;
  1126. /* i2c buses */
  1127. struct radeon_i2c_chan *i2c_bus[RADEON_MAX_I2C_BUS];
  1128. };
  1129. int radeon_device_init(struct radeon_device *rdev,
  1130. struct drm_device *ddev,
  1131. struct pci_dev *pdev,
  1132. uint32_t flags);
  1133. void radeon_device_fini(struct radeon_device *rdev);
  1134. int radeon_gpu_wait_for_idle(struct radeon_device *rdev);
  1135. static inline uint32_t r100_mm_rreg(struct radeon_device *rdev, uint32_t reg)
  1136. {
  1137. if (reg < rdev->rmmio_size)
  1138. return readl((rdev->rmmio) + reg);
  1139. else {
  1140. writel(reg, (rdev->rmmio) + RADEON_MM_INDEX);
  1141. return readl((rdev->rmmio) + RADEON_MM_DATA);
  1142. }
  1143. }
  1144. static inline void r100_mm_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1145. {
  1146. if (reg < rdev->rmmio_size)
  1147. writel(v, (rdev->rmmio) + reg);
  1148. else {
  1149. writel(reg, (rdev->rmmio) + RADEON_MM_INDEX);
  1150. writel(v, (rdev->rmmio) + RADEON_MM_DATA);
  1151. }
  1152. }
  1153. static inline u32 r100_io_rreg(struct radeon_device *rdev, u32 reg)
  1154. {
  1155. if (reg < rdev->rio_mem_size)
  1156. return ioread32(rdev->rio_mem + reg);
  1157. else {
  1158. iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
  1159. return ioread32(rdev->rio_mem + RADEON_MM_DATA);
  1160. }
  1161. }
  1162. static inline void r100_io_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  1163. {
  1164. if (reg < rdev->rio_mem_size)
  1165. iowrite32(v, rdev->rio_mem + reg);
  1166. else {
  1167. iowrite32(reg, rdev->rio_mem + RADEON_MM_INDEX);
  1168. iowrite32(v, rdev->rio_mem + RADEON_MM_DATA);
  1169. }
  1170. }
  1171. /*
  1172. * Cast helper
  1173. */
  1174. #define to_radeon_fence(p) ((struct radeon_fence *)(p))
  1175. /*
  1176. * Registers read & write functions.
  1177. */
  1178. #define RREG8(reg) readb((rdev->rmmio) + (reg))
  1179. #define WREG8(reg, v) writeb(v, (rdev->rmmio) + (reg))
  1180. #define RREG16(reg) readw((rdev->rmmio) + (reg))
  1181. #define WREG16(reg, v) writew(v, (rdev->rmmio) + (reg))
  1182. #define RREG32(reg) r100_mm_rreg(rdev, (reg))
  1183. #define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", r100_mm_rreg(rdev, (reg)))
  1184. #define WREG32(reg, v) r100_mm_wreg(rdev, (reg), (v))
  1185. #define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1186. #define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
  1187. #define RREG32_PLL(reg) rdev->pll_rreg(rdev, (reg))
  1188. #define WREG32_PLL(reg, v) rdev->pll_wreg(rdev, (reg), (v))
  1189. #define RREG32_MC(reg) rdev->mc_rreg(rdev, (reg))
  1190. #define WREG32_MC(reg, v) rdev->mc_wreg(rdev, (reg), (v))
  1191. #define RREG32_PCIE(reg) rv370_pcie_rreg(rdev, (reg))
  1192. #define WREG32_PCIE(reg, v) rv370_pcie_wreg(rdev, (reg), (v))
  1193. #define RREG32_PCIE_P(reg) rdev->pciep_rreg(rdev, (reg))
  1194. #define WREG32_PCIE_P(reg, v) rdev->pciep_wreg(rdev, (reg), (v))
  1195. #define WREG32_P(reg, val, mask) \
  1196. do { \
  1197. uint32_t tmp_ = RREG32(reg); \
  1198. tmp_ &= (mask); \
  1199. tmp_ |= ((val) & ~(mask)); \
  1200. WREG32(reg, tmp_); \
  1201. } while (0)
  1202. #define WREG32_PLL_P(reg, val, mask) \
  1203. do { \
  1204. uint32_t tmp_ = RREG32_PLL(reg); \
  1205. tmp_ &= (mask); \
  1206. tmp_ |= ((val) & ~(mask)); \
  1207. WREG32_PLL(reg, tmp_); \
  1208. } while (0)
  1209. #define DREG32_SYS(sqf, rdev, reg) seq_printf((sqf), #reg " : 0x%08X\n", r100_mm_rreg((rdev), (reg)))
  1210. #define RREG32_IO(reg) r100_io_rreg(rdev, (reg))
  1211. #define WREG32_IO(reg, v) r100_io_wreg(rdev, (reg), (v))
  1212. /*
  1213. * Indirect registers accessor
  1214. */
  1215. static inline uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  1216. {
  1217. uint32_t r;
  1218. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1219. r = RREG32(RADEON_PCIE_DATA);
  1220. return r;
  1221. }
  1222. static inline void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  1223. {
  1224. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  1225. WREG32(RADEON_PCIE_DATA, (v));
  1226. }
  1227. void r100_pll_errata_after_index(struct radeon_device *rdev);
  1228. /*
  1229. * ASICs helpers.
  1230. */
  1231. #define ASIC_IS_RN50(rdev) ((rdev->pdev->device == 0x515e) || \
  1232. (rdev->pdev->device == 0x5969))
  1233. #define ASIC_IS_RV100(rdev) ((rdev->family == CHIP_RV100) || \
  1234. (rdev->family == CHIP_RV200) || \
  1235. (rdev->family == CHIP_RS100) || \
  1236. (rdev->family == CHIP_RS200) || \
  1237. (rdev->family == CHIP_RV250) || \
  1238. (rdev->family == CHIP_RV280) || \
  1239. (rdev->family == CHIP_RS300))
  1240. #define ASIC_IS_R300(rdev) ((rdev->family == CHIP_R300) || \
  1241. (rdev->family == CHIP_RV350) || \
  1242. (rdev->family == CHIP_R350) || \
  1243. (rdev->family == CHIP_RV380) || \
  1244. (rdev->family == CHIP_R420) || \
  1245. (rdev->family == CHIP_R423) || \
  1246. (rdev->family == CHIP_RV410) || \
  1247. (rdev->family == CHIP_RS400) || \
  1248. (rdev->family == CHIP_RS480))
  1249. #define ASIC_IS_X2(rdev) ((rdev->ddev->pdev->device == 0x9441) || \
  1250. (rdev->ddev->pdev->device == 0x9443) || \
  1251. (rdev->ddev->pdev->device == 0x944B) || \
  1252. (rdev->ddev->pdev->device == 0x9506) || \
  1253. (rdev->ddev->pdev->device == 0x9509) || \
  1254. (rdev->ddev->pdev->device == 0x950F) || \
  1255. (rdev->ddev->pdev->device == 0x689C) || \
  1256. (rdev->ddev->pdev->device == 0x689D))
  1257. #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600))
  1258. #define ASIC_IS_DCE2(rdev) ((rdev->family == CHIP_RS600) || \
  1259. (rdev->family == CHIP_RS690) || \
  1260. (rdev->family == CHIP_RS740) || \
  1261. (rdev->family >= CHIP_R600))
  1262. #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620))
  1263. #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730))
  1264. #define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR))
  1265. #define ASIC_IS_DCE41(rdev) ((rdev->family >= CHIP_PALM) && \
  1266. (rdev->flags & RADEON_IS_IGP))
  1267. #define ASIC_IS_DCE5(rdev) ((rdev->family >= CHIP_BARTS))
  1268. /*
  1269. * BIOS helpers.
  1270. */
  1271. #define RBIOS8(i) (rdev->bios[i])
  1272. #define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
  1273. #define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
  1274. int radeon_combios_init(struct radeon_device *rdev);
  1275. void radeon_combios_fini(struct radeon_device *rdev);
  1276. int radeon_atombios_init(struct radeon_device *rdev);
  1277. void radeon_atombios_fini(struct radeon_device *rdev);
  1278. /*
  1279. * RING helpers.
  1280. */
  1281. static inline void radeon_ring_write(struct radeon_device *rdev, uint32_t v)
  1282. {
  1283. #if DRM_DEBUG_CODE
  1284. if (rdev->cp.count_dw <= 0) {
  1285. DRM_ERROR("radeon: writting more dword to ring than expected !\n");
  1286. }
  1287. #endif
  1288. rdev->cp.ring[rdev->cp.wptr++] = v;
  1289. rdev->cp.wptr &= rdev->cp.ptr_mask;
  1290. rdev->cp.count_dw--;
  1291. rdev->cp.ring_free_dw--;
  1292. }
  1293. /*
  1294. * ASICs macro.
  1295. */
  1296. #define radeon_init(rdev) (rdev)->asic->init((rdev))
  1297. #define radeon_fini(rdev) (rdev)->asic->fini((rdev))
  1298. #define radeon_resume(rdev) (rdev)->asic->resume((rdev))
  1299. #define radeon_suspend(rdev) (rdev)->asic->suspend((rdev))
  1300. #define radeon_cs_parse(p) rdev->asic->cs_parse((p))
  1301. #define radeon_vga_set_state(rdev, state) (rdev)->asic->vga_set_state((rdev), (state))
  1302. #define radeon_gpu_is_lockup(rdev) (rdev)->asic->gpu_is_lockup((rdev))
  1303. #define radeon_asic_reset(rdev) (rdev)->asic->asic_reset((rdev))
  1304. #define radeon_gart_tlb_flush(rdev) (rdev)->asic->gart_tlb_flush((rdev))
  1305. #define radeon_gart_set_page(rdev, i, p) (rdev)->asic->gart_set_page((rdev), (i), (p))
  1306. #define radeon_cp_commit(rdev) (rdev)->asic->cp_commit((rdev))
  1307. #define radeon_ring_start(rdev) (rdev)->asic->ring_start((rdev))
  1308. #define radeon_ring_test(rdev) (rdev)->asic->ring_test((rdev))
  1309. #define radeon_ring_ib_execute(rdev, ib) (rdev)->asic->ring_ib_execute((rdev), (ib))
  1310. #define radeon_irq_set(rdev) (rdev)->asic->irq_set((rdev))
  1311. #define radeon_irq_process(rdev) (rdev)->asic->irq_process((rdev))
  1312. #define radeon_get_vblank_counter(rdev, crtc) (rdev)->asic->get_vblank_counter((rdev), (crtc))
  1313. #define radeon_fence_ring_emit(rdev, fence) (rdev)->asic->fence_ring_emit((rdev), (fence))
  1314. #define radeon_copy_blit(rdev, s, d, np, f) (rdev)->asic->copy_blit((rdev), (s), (d), (np), (f))
  1315. #define radeon_copy_dma(rdev, s, d, np, f) (rdev)->asic->copy_dma((rdev), (s), (d), (np), (f))
  1316. #define radeon_copy(rdev, s, d, np, f) (rdev)->asic->copy((rdev), (s), (d), (np), (f))
  1317. #define radeon_get_engine_clock(rdev) (rdev)->asic->get_engine_clock((rdev))
  1318. #define radeon_set_engine_clock(rdev, e) (rdev)->asic->set_engine_clock((rdev), (e))
  1319. #define radeon_get_memory_clock(rdev) (rdev)->asic->get_memory_clock((rdev))
  1320. #define radeon_set_memory_clock(rdev, e) (rdev)->asic->set_memory_clock((rdev), (e))
  1321. #define radeon_get_pcie_lanes(rdev) (rdev)->asic->get_pcie_lanes((rdev))
  1322. #define radeon_set_pcie_lanes(rdev, l) (rdev)->asic->set_pcie_lanes((rdev), (l))
  1323. #define radeon_set_clock_gating(rdev, e) (rdev)->asic->set_clock_gating((rdev), (e))
  1324. #define radeon_set_surface_reg(rdev, r, f, p, o, s) ((rdev)->asic->set_surface_reg((rdev), (r), (f), (p), (o), (s)))
  1325. #define radeon_clear_surface_reg(rdev, r) ((rdev)->asic->clear_surface_reg((rdev), (r)))
  1326. #define radeon_bandwidth_update(rdev) (rdev)->asic->bandwidth_update((rdev))
  1327. #define radeon_hpd_init(rdev) (rdev)->asic->hpd_init((rdev))
  1328. #define radeon_hpd_fini(rdev) (rdev)->asic->hpd_fini((rdev))
  1329. #define radeon_hpd_sense(rdev, hpd) (rdev)->asic->hpd_sense((rdev), (hpd))
  1330. #define radeon_hpd_set_polarity(rdev, hpd) (rdev)->asic->hpd_set_polarity((rdev), (hpd))
  1331. #define radeon_gui_idle(rdev) (rdev)->asic->gui_idle((rdev))
  1332. #define radeon_pm_misc(rdev) (rdev)->asic->pm_misc((rdev))
  1333. #define radeon_pm_prepare(rdev) (rdev)->asic->pm_prepare((rdev))
  1334. #define radeon_pm_finish(rdev) (rdev)->asic->pm_finish((rdev))
  1335. #define radeon_pm_init_profile(rdev) (rdev)->asic->pm_init_profile((rdev))
  1336. #define radeon_pm_get_dynpm_state(rdev) (rdev)->asic->pm_get_dynpm_state((rdev))
  1337. #define radeon_pre_page_flip(rdev, crtc) rdev->asic->pre_page_flip((rdev), (crtc))
  1338. #define radeon_page_flip(rdev, crtc, base) rdev->asic->page_flip((rdev), (crtc), (base))
  1339. #define radeon_post_page_flip(rdev, crtc) rdev->asic->post_page_flip((rdev), (crtc))
  1340. /* Common functions */
  1341. /* AGP */
  1342. extern int radeon_gpu_reset(struct radeon_device *rdev);
  1343. extern void radeon_agp_disable(struct radeon_device *rdev);
  1344. extern int radeon_gart_table_vram_pin(struct radeon_device *rdev);
  1345. extern void radeon_gart_restore(struct radeon_device *rdev);
  1346. extern int radeon_modeset_init(struct radeon_device *rdev);
  1347. extern void radeon_modeset_fini(struct radeon_device *rdev);
  1348. extern bool radeon_card_posted(struct radeon_device *rdev);
  1349. extern void radeon_update_bandwidth_info(struct radeon_device *rdev);
  1350. extern void radeon_update_display_priority(struct radeon_device *rdev);
  1351. extern bool radeon_boot_test_post_card(struct radeon_device *rdev);
  1352. extern void radeon_scratch_init(struct radeon_device *rdev);
  1353. extern void radeon_wb_fini(struct radeon_device *rdev);
  1354. extern int radeon_wb_init(struct radeon_device *rdev);
  1355. extern void radeon_wb_disable(struct radeon_device *rdev);
  1356. extern void radeon_surface_init(struct radeon_device *rdev);
  1357. extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
  1358. extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
  1359. extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
  1360. extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
  1361. extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
  1362. extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
  1363. extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
  1364. extern int radeon_resume_kms(struct drm_device *dev);
  1365. extern int radeon_suspend_kms(struct drm_device *dev, pm_message_t state);
  1366. extern void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size);
  1367. /*
  1368. * r600 functions used by radeon_encoder.c
  1369. */
  1370. extern void r600_hdmi_enable(struct drm_encoder *encoder);
  1371. extern void r600_hdmi_disable(struct drm_encoder *encoder);
  1372. extern void r600_hdmi_setmode(struct drm_encoder *encoder, struct drm_display_mode *mode);
  1373. extern int ni_init_microcode(struct radeon_device *rdev);
  1374. extern int ni_mc_load_microcode(struct radeon_device *rdev);
  1375. /* radeon_acpi.c */
  1376. #if defined(CONFIG_ACPI)
  1377. extern int radeon_acpi_init(struct radeon_device *rdev);
  1378. #else
  1379. static inline int radeon_acpi_init(struct radeon_device *rdev) { return 0; }
  1380. #endif
  1381. #include "radeon_object.h"
  1382. #endif