radeon.h 47 KB

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