i915_drv.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
  2. */
  3. /*
  4. *
  5. * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
  6. * All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the
  10. * "Software"), to deal in the Software without restriction, including
  11. * without limitation the rights to use, copy, modify, merge, publish,
  12. * distribute, sub license, and/or sell copies of the Software, and to
  13. * permit persons to whom the Software is furnished to do so, subject to
  14. * the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the
  17. * next paragraph) shall be included in all copies or substantial portions
  18. * of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  23. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  24. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  25. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  26. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. *
  28. */
  29. #ifndef _I915_DRV_H_
  30. #define _I915_DRV_H_
  31. #include "i915_reg.h"
  32. #include <linux/io-mapping.h>
  33. /* General customization:
  34. */
  35. #define DRIVER_AUTHOR "Tungsten Graphics, Inc."
  36. #define DRIVER_NAME "i915"
  37. #define DRIVER_DESC "Intel Graphics"
  38. #define DRIVER_DATE "20080730"
  39. enum pipe {
  40. PIPE_A = 0,
  41. PIPE_B,
  42. };
  43. /* Interface history:
  44. *
  45. * 1.1: Original.
  46. * 1.2: Add Power Management
  47. * 1.3: Add vblank support
  48. * 1.4: Fix cmdbuffer path, add heap destroy
  49. * 1.5: Add vblank pipe configuration
  50. * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
  51. * - Support vertical blank on secondary display pipe
  52. */
  53. #define DRIVER_MAJOR 1
  54. #define DRIVER_MINOR 6
  55. #define DRIVER_PATCHLEVEL 0
  56. #define WATCH_COHERENCY 0
  57. #define WATCH_BUF 0
  58. #define WATCH_EXEC 0
  59. #define WATCH_LRU 0
  60. #define WATCH_RELOC 0
  61. #define WATCH_INACTIVE 0
  62. #define WATCH_PWRITE 0
  63. typedef struct _drm_i915_ring_buffer {
  64. int tail_mask;
  65. unsigned long Size;
  66. u8 *virtual_start;
  67. int head;
  68. int tail;
  69. int space;
  70. drm_local_map_t map;
  71. struct drm_gem_object *ring_obj;
  72. } drm_i915_ring_buffer_t;
  73. struct mem_block {
  74. struct mem_block *next;
  75. struct mem_block *prev;
  76. int start;
  77. int size;
  78. struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
  79. };
  80. typedef struct _drm_i915_vbl_swap {
  81. struct list_head head;
  82. drm_drawable_t drw_id;
  83. unsigned int pipe;
  84. unsigned int sequence;
  85. } drm_i915_vbl_swap_t;
  86. struct opregion_header;
  87. struct opregion_acpi;
  88. struct opregion_swsci;
  89. struct opregion_asle;
  90. struct intel_opregion {
  91. struct opregion_header *header;
  92. struct opregion_acpi *acpi;
  93. struct opregion_swsci *swsci;
  94. struct opregion_asle *asle;
  95. int enabled;
  96. };
  97. typedef struct drm_i915_private {
  98. struct drm_device *dev;
  99. void __iomem *regs;
  100. drm_local_map_t *sarea;
  101. drm_i915_sarea_t *sarea_priv;
  102. drm_i915_ring_buffer_t ring;
  103. drm_dma_handle_t *status_page_dmah;
  104. void *hw_status_page;
  105. dma_addr_t dma_status_page;
  106. uint32_t counter;
  107. unsigned int status_gfx_addr;
  108. drm_local_map_t hws_map;
  109. struct drm_gem_object *hws_obj;
  110. unsigned int cpp;
  111. int back_offset;
  112. int front_offset;
  113. int current_page;
  114. int page_flipping;
  115. wait_queue_head_t irq_queue;
  116. atomic_t irq_received;
  117. /** Protects user_irq_refcount and irq_mask_reg */
  118. spinlock_t user_irq_lock;
  119. /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
  120. int user_irq_refcount;
  121. /** Cached value of IMR to avoid reads in updating the bitfield */
  122. u32 irq_mask_reg;
  123. int tex_lru_log_granularity;
  124. int allow_batchbuffer;
  125. struct mem_block *agp_heap;
  126. unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
  127. int vblank_pipe;
  128. spinlock_t swaps_lock;
  129. drm_i915_vbl_swap_t vbl_swaps;
  130. unsigned int swaps_pending;
  131. struct intel_opregion opregion;
  132. /* Register state */
  133. u8 saveLBB;
  134. u32 saveDSPACNTR;
  135. u32 saveDSPBCNTR;
  136. u32 saveDSPARB;
  137. u32 savePIPEACONF;
  138. u32 savePIPEBCONF;
  139. u32 savePIPEASRC;
  140. u32 savePIPEBSRC;
  141. u32 saveFPA0;
  142. u32 saveFPA1;
  143. u32 saveDPLL_A;
  144. u32 saveDPLL_A_MD;
  145. u32 saveHTOTAL_A;
  146. u32 saveHBLANK_A;
  147. u32 saveHSYNC_A;
  148. u32 saveVTOTAL_A;
  149. u32 saveVBLANK_A;
  150. u32 saveVSYNC_A;
  151. u32 saveBCLRPAT_A;
  152. u32 savePIPEASTAT;
  153. u32 saveDSPASTRIDE;
  154. u32 saveDSPASIZE;
  155. u32 saveDSPAPOS;
  156. u32 saveDSPAADDR;
  157. u32 saveDSPASURF;
  158. u32 saveDSPATILEOFF;
  159. u32 savePFIT_PGM_RATIOS;
  160. u32 saveBLC_PWM_CTL;
  161. u32 saveBLC_PWM_CTL2;
  162. u32 saveFPB0;
  163. u32 saveFPB1;
  164. u32 saveDPLL_B;
  165. u32 saveDPLL_B_MD;
  166. u32 saveHTOTAL_B;
  167. u32 saveHBLANK_B;
  168. u32 saveHSYNC_B;
  169. u32 saveVTOTAL_B;
  170. u32 saveVBLANK_B;
  171. u32 saveVSYNC_B;
  172. u32 saveBCLRPAT_B;
  173. u32 savePIPEBSTAT;
  174. u32 saveDSPBSTRIDE;
  175. u32 saveDSPBSIZE;
  176. u32 saveDSPBPOS;
  177. u32 saveDSPBADDR;
  178. u32 saveDSPBSURF;
  179. u32 saveDSPBTILEOFF;
  180. u32 saveVGA0;
  181. u32 saveVGA1;
  182. u32 saveVGA_PD;
  183. u32 saveVGACNTRL;
  184. u32 saveADPA;
  185. u32 saveLVDS;
  186. u32 savePP_ON_DELAYS;
  187. u32 savePP_OFF_DELAYS;
  188. u32 saveDVOA;
  189. u32 saveDVOB;
  190. u32 saveDVOC;
  191. u32 savePP_ON;
  192. u32 savePP_OFF;
  193. u32 savePP_CONTROL;
  194. u32 savePP_DIVISOR;
  195. u32 savePFIT_CONTROL;
  196. u32 save_palette_a[256];
  197. u32 save_palette_b[256];
  198. u32 saveFBC_CFB_BASE;
  199. u32 saveFBC_LL_BASE;
  200. u32 saveFBC_CONTROL;
  201. u32 saveFBC_CONTROL2;
  202. u32 saveIER;
  203. u32 saveIIR;
  204. u32 saveIMR;
  205. u32 saveCACHE_MODE_0;
  206. u32 saveD_STATE;
  207. u32 saveCG_2D_DIS;
  208. u32 saveMI_ARB_STATE;
  209. u32 saveSWF0[16];
  210. u32 saveSWF1[16];
  211. u32 saveSWF2[3];
  212. u8 saveMSR;
  213. u8 saveSR[8];
  214. u8 saveGR[25];
  215. u8 saveAR_INDEX;
  216. u8 saveAR[21];
  217. u8 saveDACMASK;
  218. u8 saveDACDATA[256*3]; /* 256 3-byte colors */
  219. u8 saveCR[37];
  220. /** Work task for vblank-related ring access */
  221. struct work_struct vblank_work;
  222. struct {
  223. struct drm_mm gtt_space;
  224. struct io_mapping *gtt_mapping;
  225. /**
  226. * List of objects currently involved in rendering from the
  227. * ringbuffer.
  228. *
  229. * A reference is held on the buffer while on this list.
  230. */
  231. struct list_head active_list;
  232. /**
  233. * List of objects which are not in the ringbuffer but which
  234. * still have a write_domain which needs to be flushed before
  235. * unbinding.
  236. *
  237. * A reference is held on the buffer while on this list.
  238. */
  239. struct list_head flushing_list;
  240. /**
  241. * LRU list of objects which are not in the ringbuffer and
  242. * are ready to unbind, but are still in the GTT.
  243. *
  244. * A reference is not held on the buffer while on this list,
  245. * as merely being GTT-bound shouldn't prevent its being
  246. * freed, and we'll pull it off the list in the free path.
  247. */
  248. struct list_head inactive_list;
  249. /**
  250. * List of breadcrumbs associated with GPU requests currently
  251. * outstanding.
  252. */
  253. struct list_head request_list;
  254. /**
  255. * We leave the user IRQ off as much as possible,
  256. * but this means that requests will finish and never
  257. * be retired once the system goes idle. Set a timer to
  258. * fire periodically while the ring is running. When it
  259. * fires, go retire requests.
  260. */
  261. struct delayed_work retire_work;
  262. uint32_t next_gem_seqno;
  263. /**
  264. * Waiting sequence number, if any
  265. */
  266. uint32_t waiting_gem_seqno;
  267. /**
  268. * Last seq seen at irq time
  269. */
  270. uint32_t irq_gem_seqno;
  271. /**
  272. * Flag if the X Server, and thus DRM, is not currently in
  273. * control of the device.
  274. *
  275. * This is set between LeaveVT and EnterVT. It needs to be
  276. * replaced with a semaphore. It also needs to be
  277. * transitioned away from for kernel modesetting.
  278. */
  279. int suspended;
  280. /**
  281. * Flag if the hardware appears to be wedged.
  282. *
  283. * This is set when attempts to idle the device timeout.
  284. * It prevents command submission from occuring and makes
  285. * every pending request fail
  286. */
  287. int wedged;
  288. /** Bit 6 swizzling required for X tiling */
  289. uint32_t bit_6_swizzle_x;
  290. /** Bit 6 swizzling required for Y tiling */
  291. uint32_t bit_6_swizzle_y;
  292. } mm;
  293. } drm_i915_private_t;
  294. /** driver private structure attached to each drm_gem_object */
  295. struct drm_i915_gem_object {
  296. struct drm_gem_object *obj;
  297. /** Current space allocated to this object in the GTT, if any. */
  298. struct drm_mm_node *gtt_space;
  299. /** This object's place on the active/flushing/inactive lists */
  300. struct list_head list;
  301. /**
  302. * This is set if the object is on the active or flushing lists
  303. * (has pending rendering), and is not set if it's on inactive (ready
  304. * to be unbound).
  305. */
  306. int active;
  307. /**
  308. * This is set if the object has been written to since last bound
  309. * to the GTT
  310. */
  311. int dirty;
  312. /** AGP memory structure for our GTT binding. */
  313. DRM_AGP_MEM *agp_mem;
  314. struct page **page_list;
  315. /**
  316. * Current offset of the object in GTT space.
  317. *
  318. * This is the same as gtt_space->start
  319. */
  320. uint32_t gtt_offset;
  321. /** Boolean whether this object has a valid gtt offset. */
  322. int gtt_bound;
  323. /** How many users have pinned this object in GTT space */
  324. int pin_count;
  325. /** Breadcrumb of last rendering to the buffer. */
  326. uint32_t last_rendering_seqno;
  327. /** Current tiling mode for the object. */
  328. uint32_t tiling_mode;
  329. /** AGP mapping type (AGP_USER_MEMORY or AGP_USER_CACHED_MEMORY */
  330. uint32_t agp_type;
  331. /**
  332. * Flagging of which individual pages are valid in GEM_DOMAIN_CPU when
  333. * GEM_DOMAIN_CPU is not in the object's read domain.
  334. */
  335. uint8_t *page_cpu_valid;
  336. };
  337. /**
  338. * Request queue structure.
  339. *
  340. * The request queue allows us to note sequence numbers that have been emitted
  341. * and may be associated with active buffers to be retired.
  342. *
  343. * By keeping this list, we can avoid having to do questionable
  344. * sequence-number comparisons on buffer last_rendering_seqnos, and associate
  345. * an emission time with seqnos for tracking how far ahead of the GPU we are.
  346. */
  347. struct drm_i915_gem_request {
  348. /** GEM sequence number associated with this request. */
  349. uint32_t seqno;
  350. /** Time at which this request was emitted, in jiffies. */
  351. unsigned long emitted_jiffies;
  352. /** Cache domains that were flushed at the start of the request. */
  353. uint32_t flush_domains;
  354. struct list_head list;
  355. };
  356. struct drm_i915_file_private {
  357. struct {
  358. uint32_t last_gem_seqno;
  359. uint32_t last_gem_throttle_seqno;
  360. } mm;
  361. };
  362. extern struct drm_ioctl_desc i915_ioctls[];
  363. extern int i915_max_ioctl;
  364. /* i915_dma.c */
  365. extern void i915_kernel_lost_context(struct drm_device * dev);
  366. extern int i915_driver_load(struct drm_device *, unsigned long flags);
  367. extern int i915_driver_unload(struct drm_device *);
  368. extern int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv);
  369. extern void i915_driver_lastclose(struct drm_device * dev);
  370. extern void i915_driver_preclose(struct drm_device *dev,
  371. struct drm_file *file_priv);
  372. extern void i915_driver_postclose(struct drm_device *dev,
  373. struct drm_file *file_priv);
  374. extern int i915_driver_device_is_agp(struct drm_device * dev);
  375. extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
  376. unsigned long arg);
  377. extern int i915_emit_box(struct drm_device *dev,
  378. struct drm_clip_rect __user *boxes,
  379. int i, int DR1, int DR4);
  380. /* i915_irq.c */
  381. extern int i915_irq_emit(struct drm_device *dev, void *data,
  382. struct drm_file *file_priv);
  383. extern int i915_irq_wait(struct drm_device *dev, void *data,
  384. struct drm_file *file_priv);
  385. void i915_user_irq_get(struct drm_device *dev);
  386. void i915_user_irq_put(struct drm_device *dev);
  387. extern void i915_vblank_work_handler(struct work_struct *work);
  388. extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
  389. extern void i915_driver_irq_preinstall(struct drm_device * dev);
  390. extern int i915_driver_irq_postinstall(struct drm_device *dev);
  391. extern void i915_driver_irq_uninstall(struct drm_device * dev);
  392. extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
  393. struct drm_file *file_priv);
  394. extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
  395. struct drm_file *file_priv);
  396. extern int i915_enable_vblank(struct drm_device *dev, int crtc);
  397. extern void i915_disable_vblank(struct drm_device *dev, int crtc);
  398. extern u32 i915_get_vblank_counter(struct drm_device *dev, int crtc);
  399. extern int i915_vblank_swap(struct drm_device *dev, void *data,
  400. struct drm_file *file_priv);
  401. extern void i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask);
  402. /* i915_mem.c */
  403. extern int i915_mem_alloc(struct drm_device *dev, void *data,
  404. struct drm_file *file_priv);
  405. extern int i915_mem_free(struct drm_device *dev, void *data,
  406. struct drm_file *file_priv);
  407. extern int i915_mem_init_heap(struct drm_device *dev, void *data,
  408. struct drm_file *file_priv);
  409. extern int i915_mem_destroy_heap(struct drm_device *dev, void *data,
  410. struct drm_file *file_priv);
  411. extern void i915_mem_takedown(struct mem_block **heap);
  412. extern void i915_mem_release(struct drm_device * dev,
  413. struct drm_file *file_priv, struct mem_block *heap);
  414. /* i915_gem.c */
  415. int i915_gem_init_ioctl(struct drm_device *dev, void *data,
  416. struct drm_file *file_priv);
  417. int i915_gem_create_ioctl(struct drm_device *dev, void *data,
  418. struct drm_file *file_priv);
  419. int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
  420. struct drm_file *file_priv);
  421. int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
  422. struct drm_file *file_priv);
  423. int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
  424. struct drm_file *file_priv);
  425. int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
  426. struct drm_file *file_priv);
  427. int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
  428. struct drm_file *file_priv);
  429. int i915_gem_execbuffer(struct drm_device *dev, void *data,
  430. struct drm_file *file_priv);
  431. int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
  432. struct drm_file *file_priv);
  433. int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
  434. struct drm_file *file_priv);
  435. int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
  436. struct drm_file *file_priv);
  437. int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
  438. struct drm_file *file_priv);
  439. int i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
  440. struct drm_file *file_priv);
  441. int i915_gem_leavevt_ioctl(struct drm_device *dev, void *data,
  442. struct drm_file *file_priv);
  443. int i915_gem_set_tiling(struct drm_device *dev, void *data,
  444. struct drm_file *file_priv);
  445. int i915_gem_get_tiling(struct drm_device *dev, void *data,
  446. struct drm_file *file_priv);
  447. int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
  448. struct drm_file *file_priv);
  449. void i915_gem_load(struct drm_device *dev);
  450. int i915_gem_proc_init(struct drm_minor *minor);
  451. void i915_gem_proc_cleanup(struct drm_minor *minor);
  452. int i915_gem_init_object(struct drm_gem_object *obj);
  453. void i915_gem_free_object(struct drm_gem_object *obj);
  454. int i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment);
  455. void i915_gem_object_unpin(struct drm_gem_object *obj);
  456. void i915_gem_lastclose(struct drm_device *dev);
  457. uint32_t i915_get_gem_seqno(struct drm_device *dev);
  458. void i915_gem_retire_requests(struct drm_device *dev);
  459. void i915_gem_retire_work_handler(struct work_struct *work);
  460. void i915_gem_clflush_object(struct drm_gem_object *obj);
  461. /* i915_gem_tiling.c */
  462. void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
  463. /* i915_gem_debug.c */
  464. void i915_gem_dump_object(struct drm_gem_object *obj, int len,
  465. const char *where, uint32_t mark);
  466. #if WATCH_INACTIVE
  467. void i915_verify_inactive(struct drm_device *dev, char *file, int line);
  468. #else
  469. #define i915_verify_inactive(dev, file, line)
  470. #endif
  471. void i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle);
  472. void i915_gem_dump_object(struct drm_gem_object *obj, int len,
  473. const char *where, uint32_t mark);
  474. void i915_dump_lru(struct drm_device *dev, const char *where);
  475. /* i915_suspend.c */
  476. extern int i915_save_state(struct drm_device *dev);
  477. extern int i915_restore_state(struct drm_device *dev);
  478. /* i915_suspend.c */
  479. extern int i915_save_state(struct drm_device *dev);
  480. extern int i915_restore_state(struct drm_device *dev);
  481. #ifdef CONFIG_ACPI
  482. /* i915_opregion.c */
  483. extern int intel_opregion_init(struct drm_device *dev);
  484. extern void intel_opregion_free(struct drm_device *dev);
  485. extern void opregion_asle_intr(struct drm_device *dev);
  486. extern void opregion_enable_asle(struct drm_device *dev);
  487. #else
  488. static inline int intel_opregion_init(struct drm_device *dev) { return 0; }
  489. static inline void intel_opregion_free(struct drm_device *dev) { return; }
  490. static inline void opregion_asle_intr(struct drm_device *dev) { return; }
  491. static inline void opregion_enable_asle(struct drm_device *dev) { return; }
  492. #endif
  493. /**
  494. * Lock test for when it's just for synchronization of ring access.
  495. *
  496. * In that case, we don't need to do it when GEM is initialized as nobody else
  497. * has access to the ring.
  498. */
  499. #define RING_LOCK_TEST_WITH_RETURN(dev, file_priv) do { \
  500. if (((drm_i915_private_t *)dev->dev_private)->ring.ring_obj == NULL) \
  501. LOCK_TEST_WITH_RETURN(dev, file_priv); \
  502. } while (0)
  503. #define I915_READ(reg) readl(dev_priv->regs + (reg))
  504. #define I915_WRITE(reg, val) writel(val, dev_priv->regs + (reg))
  505. #define I915_READ16(reg) readw(dev_priv->regs + (reg))
  506. #define I915_WRITE16(reg, val) writel(val, dev_priv->regs + (reg))
  507. #define I915_READ8(reg) readb(dev_priv->regs + (reg))
  508. #define I915_WRITE8(reg, val) writeb(val, dev_priv->regs + (reg))
  509. #define I915_VERBOSE 0
  510. #define RING_LOCALS unsigned int outring, ringmask, outcount; \
  511. volatile char *virt;
  512. #define BEGIN_LP_RING(n) do { \
  513. if (I915_VERBOSE) \
  514. DRM_DEBUG("BEGIN_LP_RING(%d)\n", (n)); \
  515. if (dev_priv->ring.space < (n)*4) \
  516. i915_wait_ring(dev, (n)*4, __func__); \
  517. outcount = 0; \
  518. outring = dev_priv->ring.tail; \
  519. ringmask = dev_priv->ring.tail_mask; \
  520. virt = dev_priv->ring.virtual_start; \
  521. } while (0)
  522. #define OUT_RING(n) do { \
  523. if (I915_VERBOSE) DRM_DEBUG(" OUT_RING %x\n", (int)(n)); \
  524. *(volatile unsigned int *)(virt + outring) = (n); \
  525. outcount++; \
  526. outring += 4; \
  527. outring &= ringmask; \
  528. } while (0)
  529. #define ADVANCE_LP_RING() do { \
  530. if (I915_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING %x\n", outring); \
  531. dev_priv->ring.tail = outring; \
  532. dev_priv->ring.space -= outcount * 4; \
  533. I915_WRITE(PRB0_TAIL, outring); \
  534. } while(0)
  535. /**
  536. * Reads a dword out of the status page, which is written to from the command
  537. * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
  538. * MI_STORE_DATA_IMM.
  539. *
  540. * The following dwords have a reserved meaning:
  541. * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
  542. * 0x04: ring 0 head pointer
  543. * 0x05: ring 1 head pointer (915-class)
  544. * 0x06: ring 2 head pointer (915-class)
  545. * 0x10-0x1b: Context status DWords (GM45)
  546. * 0x1f: Last written status offset. (GM45)
  547. *
  548. * The area from dword 0x20 to 0x3ff is available for driver usage.
  549. */
  550. #define READ_HWSP(dev_priv, reg) (((volatile u32*)(dev_priv->hw_status_page))[reg])
  551. #define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, 5)
  552. #define I915_GEM_HWS_INDEX 0x20
  553. extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
  554. #define IS_I830(dev) ((dev)->pci_device == 0x3577)
  555. #define IS_845G(dev) ((dev)->pci_device == 0x2562)
  556. #define IS_I85X(dev) ((dev)->pci_device == 0x3582)
  557. #define IS_I855(dev) ((dev)->pci_device == 0x3582)
  558. #define IS_I865G(dev) ((dev)->pci_device == 0x2572)
  559. #define IS_I915G(dev) ((dev)->pci_device == 0x2582 || (dev)->pci_device == 0x258a)
  560. #define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
  561. #define IS_I945G(dev) ((dev)->pci_device == 0x2772)
  562. #define IS_I945GM(dev) ((dev)->pci_device == 0x27A2 ||\
  563. (dev)->pci_device == 0x27AE)
  564. #define IS_I965G(dev) ((dev)->pci_device == 0x2972 || \
  565. (dev)->pci_device == 0x2982 || \
  566. (dev)->pci_device == 0x2992 || \
  567. (dev)->pci_device == 0x29A2 || \
  568. (dev)->pci_device == 0x2A02 || \
  569. (dev)->pci_device == 0x2A12 || \
  570. (dev)->pci_device == 0x2A42 || \
  571. (dev)->pci_device == 0x2E02 || \
  572. (dev)->pci_device == 0x2E12 || \
  573. (dev)->pci_device == 0x2E22)
  574. #define IS_I965GM(dev) ((dev)->pci_device == 0x2A02)
  575. #define IS_GM45(dev) ((dev)->pci_device == 0x2A42)
  576. #define IS_G4X(dev) ((dev)->pci_device == 0x2E02 || \
  577. (dev)->pci_device == 0x2E12 || \
  578. (dev)->pci_device == 0x2E22)
  579. #define IS_G33(dev) ((dev)->pci_device == 0x29C2 || \
  580. (dev)->pci_device == 0x29B2 || \
  581. (dev)->pci_device == 0x29D2)
  582. #define IS_I9XX(dev) (IS_I915G(dev) || IS_I915GM(dev) || IS_I945G(dev) || \
  583. IS_I945GM(dev) || IS_I965G(dev) || IS_G33(dev))
  584. #define IS_MOBILE(dev) (IS_I830(dev) || IS_I85X(dev) || IS_I915GM(dev) || \
  585. IS_I945GM(dev) || IS_I965GM(dev) || IS_GM45(dev))
  586. #define I915_NEED_GFX_HWS(dev) (IS_G33(dev) || IS_GM45(dev) || IS_G4X(dev))
  587. #define PRIMARY_RINGBUFFER_SIZE (128*1024)
  588. #endif