radeon.h 47 KB

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