radeon.h 45 KB

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