blob: ed1edcf8704fdf021720c0ecc8f6c2e073f6df1a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
2 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Dave Airliebc54fd12005-06-23 22:46:46 +10004 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10007 *
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 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110028 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#ifndef _I915_DRV_H_
31#define _I915_DRV_H_
32
Jesse Barnes585fb112008-07-29 11:54:06 -070033#include "i915_reg.h"
Keith Packard0839ccb2008-10-30 19:38:48 -070034#include <linux/io-mapping.h>
Jesse Barnes585fb112008-07-29 11:54:06 -070035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036/* General customization:
37 */
38
39#define DRIVER_AUTHOR "Tungsten Graphics, Inc."
40
41#define DRIVER_NAME "i915"
42#define DRIVER_DESC "Intel Graphics"
Eric Anholt673a3942008-07-30 12:06:12 -070043#define DRIVER_DATE "20080730"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Jesse Barnes317c35d2008-08-25 15:11:06 -070045enum pipe {
46 PIPE_A = 0,
47 PIPE_B,
48};
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/* Interface history:
51 *
52 * 1.1: Original.
Dave Airlie0d6aa602006-01-02 20:14:23 +110053 * 1.2: Add Power Management
54 * 1.3: Add vblank support
Dave Airliede227f52006-01-25 15:31:43 +110055 * 1.4: Fix cmdbuffer path, add heap destroy
Dave Airlie702880f2006-06-24 17:07:34 +100056 * 1.5: Add vblank pipe configuration
=?utf-8?q?Michel_D=C3=A4nzer?=2228ed62006-10-25 01:05:09 +100057 * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
58 * - Support vertical blank on secondary display pipe
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 */
60#define DRIVER_MAJOR 1
=?utf-8?q?Michel_D=C3=A4nzer?=2228ed62006-10-25 01:05:09 +100061#define DRIVER_MINOR 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#define DRIVER_PATCHLEVEL 0
63
Eric Anholt673a3942008-07-30 12:06:12 -070064#define WATCH_COHERENCY 0
65#define WATCH_BUF 0
66#define WATCH_EXEC 0
67#define WATCH_LRU 0
68#define WATCH_RELOC 0
69#define WATCH_INACTIVE 0
70#define WATCH_PWRITE 0
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072typedef struct _drm_i915_ring_buffer {
73 int tail_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 unsigned long Size;
75 u8 *virtual_start;
76 int head;
77 int tail;
78 int space;
79 drm_local_map_t map;
Eric Anholt673a3942008-07-30 12:06:12 -070080 struct drm_gem_object *ring_obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081} drm_i915_ring_buffer_t;
82
83struct mem_block {
84 struct mem_block *next;
85 struct mem_block *prev;
86 int start;
87 int size;
Eric Anholt6c340ea2007-08-25 20:23:09 +100088 struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089};
90
Jesse Barnes0a3e67a2008-09-30 12:14:26 -070091struct opregion_header;
92struct opregion_acpi;
93struct opregion_swsci;
94struct opregion_asle;
95
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +010096struct intel_opregion {
97 struct opregion_header *header;
98 struct opregion_acpi *acpi;
99 struct opregion_swsci *swsci;
100 struct opregion_asle *asle;
101 int enabled;
102};
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104typedef struct drm_i915_private {
Eric Anholt673a3942008-07-30 12:06:12 -0700105 struct drm_device *dev;
106
Eric Anholt3043c602008-10-02 12:24:47 -0700107 void __iomem *regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 drm_local_map_t *sarea;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 drm_i915_sarea_t *sarea_priv;
111 drm_i915_ring_buffer_t ring;
112
Dave Airlie9c8da5e2005-07-10 15:38:56 +1000113 drm_dma_handle_t *status_page_dmah;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 void *hw_status_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 dma_addr_t dma_status_page;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700116 uint32_t counter;
Wang Zhenyudc7a9312007-06-10 15:58:19 +1000117 unsigned int status_gfx_addr;
118 drm_local_map_t hws_map;
Eric Anholt673a3942008-07-30 12:06:12 -0700119 struct drm_gem_object *hws_obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000121 unsigned int cpp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 int back_offset;
123 int front_offset;
124 int current_page;
125 int page_flipping;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 wait_queue_head_t irq_queue;
128 atomic_t irq_received;
Eric Anholted4cb412008-07-29 12:10:39 -0700129 /** Protects user_irq_refcount and irq_mask_reg */
130 spinlock_t user_irq_lock;
131 /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
132 int user_irq_refcount;
133 /** Cached value of IMR to avoid reads in updating the bitfield */
134 u32 irq_mask_reg;
Keith Packard7c463582008-11-04 02:03:27 -0800135 u32 pipestat[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 int tex_lru_log_granularity;
138 int allow_batchbuffer;
139 struct mem_block *agp_heap;
Dave Airlie0d6aa602006-01-02 20:14:23 +1100140 unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
Dave Airlie702880f2006-06-24 17:07:34 +1000141 int vblank_pipe;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000142
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +0100143 struct intel_opregion opregion;
144
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000145 /* Register state */
146 u8 saveLBB;
147 u32 saveDSPACNTR;
148 u32 saveDSPBCNTR;
Keith Packarde948e992008-05-07 12:27:53 +1000149 u32 saveDSPARB;
Keith Packard881ee982008-11-02 23:08:44 -0800150 u32 saveRENDERSTANDBY;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000151 u32 savePIPEACONF;
152 u32 savePIPEBCONF;
153 u32 savePIPEASRC;
154 u32 savePIPEBSRC;
155 u32 saveFPA0;
156 u32 saveFPA1;
157 u32 saveDPLL_A;
158 u32 saveDPLL_A_MD;
159 u32 saveHTOTAL_A;
160 u32 saveHBLANK_A;
161 u32 saveHSYNC_A;
162 u32 saveVTOTAL_A;
163 u32 saveVBLANK_A;
164 u32 saveVSYNC_A;
165 u32 saveBCLRPAT_A;
Jesse Barnes0da3ea12008-02-20 09:39:58 +1000166 u32 savePIPEASTAT;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000167 u32 saveDSPASTRIDE;
168 u32 saveDSPASIZE;
169 u32 saveDSPAPOS;
Jesse Barnes585fb112008-07-29 11:54:06 -0700170 u32 saveDSPAADDR;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000171 u32 saveDSPASURF;
172 u32 saveDSPATILEOFF;
173 u32 savePFIT_PGM_RATIOS;
174 u32 saveBLC_PWM_CTL;
175 u32 saveBLC_PWM_CTL2;
176 u32 saveFPB0;
177 u32 saveFPB1;
178 u32 saveDPLL_B;
179 u32 saveDPLL_B_MD;
180 u32 saveHTOTAL_B;
181 u32 saveHBLANK_B;
182 u32 saveHSYNC_B;
183 u32 saveVTOTAL_B;
184 u32 saveVBLANK_B;
185 u32 saveVSYNC_B;
186 u32 saveBCLRPAT_B;
Jesse Barnes0da3ea12008-02-20 09:39:58 +1000187 u32 savePIPEBSTAT;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000188 u32 saveDSPBSTRIDE;
189 u32 saveDSPBSIZE;
190 u32 saveDSPBPOS;
Jesse Barnes585fb112008-07-29 11:54:06 -0700191 u32 saveDSPBADDR;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000192 u32 saveDSPBSURF;
193 u32 saveDSPBTILEOFF;
Jesse Barnes585fb112008-07-29 11:54:06 -0700194 u32 saveVGA0;
195 u32 saveVGA1;
196 u32 saveVGA_PD;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000197 u32 saveVGACNTRL;
198 u32 saveADPA;
199 u32 saveLVDS;
Jesse Barnes585fb112008-07-29 11:54:06 -0700200 u32 savePP_ON_DELAYS;
201 u32 savePP_OFF_DELAYS;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000202 u32 saveDVOA;
203 u32 saveDVOB;
204 u32 saveDVOC;
205 u32 savePP_ON;
206 u32 savePP_OFF;
207 u32 savePP_CONTROL;
Jesse Barnes585fb112008-07-29 11:54:06 -0700208 u32 savePP_DIVISOR;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000209 u32 savePFIT_CONTROL;
210 u32 save_palette_a[256];
211 u32 save_palette_b[256];
212 u32 saveFBC_CFB_BASE;
213 u32 saveFBC_LL_BASE;
214 u32 saveFBC_CONTROL;
215 u32 saveFBC_CONTROL2;
Jesse Barnes0da3ea12008-02-20 09:39:58 +1000216 u32 saveIER;
217 u32 saveIIR;
218 u32 saveIMR;
Keith Packard1f84e552008-02-16 19:19:29 -0800219 u32 saveCACHE_MODE_0;
Keith Packarde948e992008-05-07 12:27:53 +1000220 u32 saveD_STATE;
Jesse Barnes585fb112008-07-29 11:54:06 -0700221 u32 saveCG_2D_DIS;
Keith Packard1f84e552008-02-16 19:19:29 -0800222 u32 saveMI_ARB_STATE;
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000223 u32 saveSWF0[16];
224 u32 saveSWF1[16];
225 u32 saveSWF2[3];
226 u8 saveMSR;
227 u8 saveSR[8];
Jesse Barnes123f7942008-02-07 11:15:20 -0800228 u8 saveGR[25];
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000229 u8 saveAR_INDEX;
Jesse Barnesa59e1222008-05-07 12:25:46 +1000230 u8 saveAR[21];
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000231 u8 saveDACMASK;
232 u8 saveDACDATA[256*3]; /* 256 3-byte colors */
Jesse Barnesa59e1222008-05-07 12:25:46 +1000233 u8 saveCR[37];
Eric Anholt673a3942008-07-30 12:06:12 -0700234
235 struct {
236 struct drm_mm gtt_space;
237
Keith Packard0839ccb2008-10-30 19:38:48 -0700238 struct io_mapping *gtt_mapping;
239
Eric Anholt673a3942008-07-30 12:06:12 -0700240 /**
241 * List of objects currently involved in rendering from the
242 * ringbuffer.
243 *
244 * A reference is held on the buffer while on this list.
245 */
246 struct list_head active_list;
247
248 /**
249 * List of objects which are not in the ringbuffer but which
250 * still have a write_domain which needs to be flushed before
251 * unbinding.
252 *
253 * A reference is held on the buffer while on this list.
254 */
255 struct list_head flushing_list;
256
257 /**
258 * LRU list of objects which are not in the ringbuffer and
259 * are ready to unbind, but are still in the GTT.
260 *
261 * A reference is not held on the buffer while on this list,
262 * as merely being GTT-bound shouldn't prevent its being
263 * freed, and we'll pull it off the list in the free path.
264 */
265 struct list_head inactive_list;
266
267 /**
268 * List of breadcrumbs associated with GPU requests currently
269 * outstanding.
270 */
271 struct list_head request_list;
272
273 /**
274 * We leave the user IRQ off as much as possible,
275 * but this means that requests will finish and never
276 * be retired once the system goes idle. Set a timer to
277 * fire periodically while the ring is running. When it
278 * fires, go retire requests.
279 */
280 struct delayed_work retire_work;
281
282 uint32_t next_gem_seqno;
283
284 /**
285 * Waiting sequence number, if any
286 */
287 uint32_t waiting_gem_seqno;
288
289 /**
290 * Last seq seen at irq time
291 */
292 uint32_t irq_gem_seqno;
293
294 /**
295 * Flag if the X Server, and thus DRM, is not currently in
296 * control of the device.
297 *
298 * This is set between LeaveVT and EnterVT. It needs to be
299 * replaced with a semaphore. It also needs to be
300 * transitioned away from for kernel modesetting.
301 */
302 int suspended;
303
304 /**
305 * Flag if the hardware appears to be wedged.
306 *
307 * This is set when attempts to idle the device timeout.
308 * It prevents command submission from occuring and makes
309 * every pending request fail
310 */
311 int wedged;
312
313 /** Bit 6 swizzling required for X tiling */
314 uint32_t bit_6_swizzle_x;
315 /** Bit 6 swizzling required for Y tiling */
316 uint32_t bit_6_swizzle_y;
317 } mm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318} drm_i915_private_t;
319
Eric Anholt673a3942008-07-30 12:06:12 -0700320/** driver private structure attached to each drm_gem_object */
321struct drm_i915_gem_object {
322 struct drm_gem_object *obj;
323
324 /** Current space allocated to this object in the GTT, if any. */
325 struct drm_mm_node *gtt_space;
326
327 /** This object's place on the active/flushing/inactive lists */
328 struct list_head list;
329
330 /**
331 * This is set if the object is on the active or flushing lists
332 * (has pending rendering), and is not set if it's on inactive (ready
333 * to be unbound).
334 */
335 int active;
336
337 /**
338 * This is set if the object has been written to since last bound
339 * to the GTT
340 */
341 int dirty;
342
343 /** AGP memory structure for our GTT binding. */
344 DRM_AGP_MEM *agp_mem;
345
346 struct page **page_list;
347
348 /**
349 * Current offset of the object in GTT space.
350 *
351 * This is the same as gtt_space->start
352 */
353 uint32_t gtt_offset;
354
355 /** Boolean whether this object has a valid gtt offset. */
356 int gtt_bound;
357
358 /** How many users have pinned this object in GTT space */
359 int pin_count;
360
361 /** Breadcrumb of last rendering to the buffer. */
362 uint32_t last_rendering_seqno;
363
364 /** Current tiling mode for the object. */
365 uint32_t tiling_mode;
366
Keith Packardba1eb1d2008-10-14 19:55:10 -0700367 /** AGP mapping type (AGP_USER_MEMORY or AGP_USER_CACHED_MEMORY */
368 uint32_t agp_type;
369
Eric Anholt673a3942008-07-30 12:06:12 -0700370 /**
371 * Flagging of which individual pages are valid in GEM_DOMAIN_CPU when
372 * GEM_DOMAIN_CPU is not in the object's read domain.
373 */
374 uint8_t *page_cpu_valid;
375};
376
377/**
378 * Request queue structure.
379 *
380 * The request queue allows us to note sequence numbers that have been emitted
381 * and may be associated with active buffers to be retired.
382 *
383 * By keeping this list, we can avoid having to do questionable
384 * sequence-number comparisons on buffer last_rendering_seqnos, and associate
385 * an emission time with seqnos for tracking how far ahead of the GPU we are.
386 */
387struct drm_i915_gem_request {
388 /** GEM sequence number associated with this request. */
389 uint32_t seqno;
390
391 /** Time at which this request was emitted, in jiffies. */
392 unsigned long emitted_jiffies;
393
394 /** Cache domains that were flushed at the start of the request. */
395 uint32_t flush_domains;
396
397 struct list_head list;
398};
399
400struct drm_i915_file_private {
401 struct {
402 uint32_t last_gem_seqno;
403 uint32_t last_gem_throttle_seqno;
404 } mm;
405};
406
Eric Anholtc153f452007-09-03 12:06:45 +1000407extern struct drm_ioctl_desc i915_ioctls[];
Dave Airlieb3a83632005-09-30 18:37:36 +1000408extern int i915_max_ioctl;
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 /* i915_dma.c */
Dave Airlie84b1fd12007-07-11 15:53:27 +1000411extern void i915_kernel_lost_context(struct drm_device * dev);
Dave Airlie22eae942005-11-10 22:16:34 +1100412extern int i915_driver_load(struct drm_device *, unsigned long flags);
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000413extern int i915_driver_unload(struct drm_device *);
Eric Anholt673a3942008-07-30 12:06:12 -0700414extern int i915_driver_open(struct drm_device *dev, struct drm_file *file_priv);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000415extern void i915_driver_lastclose(struct drm_device * dev);
Eric Anholt6c340ea2007-08-25 20:23:09 +1000416extern void i915_driver_preclose(struct drm_device *dev,
417 struct drm_file *file_priv);
Eric Anholt673a3942008-07-30 12:06:12 -0700418extern void i915_driver_postclose(struct drm_device *dev,
419 struct drm_file *file_priv);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000420extern int i915_driver_device_is_agp(struct drm_device * dev);
Dave Airlie0d6aa602006-01-02 20:14:23 +1100421extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
422 unsigned long arg);
Eric Anholt673a3942008-07-30 12:06:12 -0700423extern int i915_emit_box(struct drm_device *dev,
424 struct drm_clip_rect __user *boxes,
425 int i, int DR1, int DR4);
Dave Airlieaf6061a2008-05-07 12:15:39 +1000426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427/* i915_irq.c */
Eric Anholtc153f452007-09-03 12:06:45 +1000428extern int i915_irq_emit(struct drm_device *dev, void *data,
429 struct drm_file *file_priv);
430extern int i915_irq_wait(struct drm_device *dev, void *data,
431 struct drm_file *file_priv);
Eric Anholt673a3942008-07-30 12:06:12 -0700432void i915_user_irq_get(struct drm_device *dev);
433void i915_user_irq_put(struct drm_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000436extern void i915_driver_irq_preinstall(struct drm_device * dev);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700437extern int i915_driver_irq_postinstall(struct drm_device *dev);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000438extern void i915_driver_irq_uninstall(struct drm_device * dev);
Eric Anholtc153f452007-09-03 12:06:45 +1000439extern int i915_vblank_pipe_set(struct drm_device *dev, void *data,
440 struct drm_file *file_priv);
441extern int i915_vblank_pipe_get(struct drm_device *dev, void *data,
442 struct drm_file *file_priv);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700443extern int i915_enable_vblank(struct drm_device *dev, int crtc);
444extern void i915_disable_vblank(struct drm_device *dev, int crtc);
445extern u32 i915_get_vblank_counter(struct drm_device *dev, int crtc);
Eric Anholtc153f452007-09-03 12:06:45 +1000446extern int i915_vblank_swap(struct drm_device *dev, void *data,
447 struct drm_file *file_priv);
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +0100448extern void i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Keith Packard7c463582008-11-04 02:03:27 -0800450void
451i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask);
452
453void
454i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask);
455
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457/* i915_mem.c */
Eric Anholtc153f452007-09-03 12:06:45 +1000458extern int i915_mem_alloc(struct drm_device *dev, void *data,
459 struct drm_file *file_priv);
460extern int i915_mem_free(struct drm_device *dev, void *data,
461 struct drm_file *file_priv);
462extern int i915_mem_init_heap(struct drm_device *dev, void *data,
463 struct drm_file *file_priv);
464extern int i915_mem_destroy_heap(struct drm_device *dev, void *data,
465 struct drm_file *file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466extern void i915_mem_takedown(struct mem_block **heap);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000467extern void i915_mem_release(struct drm_device * dev,
Eric Anholt6c340ea2007-08-25 20:23:09 +1000468 struct drm_file *file_priv, struct mem_block *heap);
Eric Anholt673a3942008-07-30 12:06:12 -0700469/* i915_gem.c */
470int i915_gem_init_ioctl(struct drm_device *dev, void *data,
471 struct drm_file *file_priv);
472int i915_gem_create_ioctl(struct drm_device *dev, void *data,
473 struct drm_file *file_priv);
474int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
475 struct drm_file *file_priv);
476int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
477 struct drm_file *file_priv);
478int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
479 struct drm_file *file_priv);
480int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
481 struct drm_file *file_priv);
482int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
483 struct drm_file *file_priv);
484int i915_gem_execbuffer(struct drm_device *dev, void *data,
485 struct drm_file *file_priv);
486int i915_gem_pin_ioctl(struct drm_device *dev, void *data,
487 struct drm_file *file_priv);
488int i915_gem_unpin_ioctl(struct drm_device *dev, void *data,
489 struct drm_file *file_priv);
490int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
491 struct drm_file *file_priv);
492int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
493 struct drm_file *file_priv);
494int i915_gem_entervt_ioctl(struct drm_device *dev, void *data,
495 struct drm_file *file_priv);
496int i915_gem_leavevt_ioctl(struct drm_device *dev, void *data,
497 struct drm_file *file_priv);
498int i915_gem_set_tiling(struct drm_device *dev, void *data,
499 struct drm_file *file_priv);
500int i915_gem_get_tiling(struct drm_device *dev, void *data,
501 struct drm_file *file_priv);
Eric Anholt5a125c32008-10-22 21:40:13 -0700502int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
503 struct drm_file *file_priv);
Eric Anholt673a3942008-07-30 12:06:12 -0700504void i915_gem_load(struct drm_device *dev);
505int i915_gem_proc_init(struct drm_minor *minor);
506void i915_gem_proc_cleanup(struct drm_minor *minor);
507int i915_gem_init_object(struct drm_gem_object *obj);
508void i915_gem_free_object(struct drm_gem_object *obj);
509int i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment);
510void i915_gem_object_unpin(struct drm_gem_object *obj);
511void i915_gem_lastclose(struct drm_device *dev);
512uint32_t i915_get_gem_seqno(struct drm_device *dev);
513void i915_gem_retire_requests(struct drm_device *dev);
514void i915_gem_retire_work_handler(struct work_struct *work);
515void i915_gem_clflush_object(struct drm_gem_object *obj);
516
517/* i915_gem_tiling.c */
518void i915_gem_detect_bit_6_swizzle(struct drm_device *dev);
519
520/* i915_gem_debug.c */
521void i915_gem_dump_object(struct drm_gem_object *obj, int len,
522 const char *where, uint32_t mark);
523#if WATCH_INACTIVE
524void i915_verify_inactive(struct drm_device *dev, char *file, int line);
525#else
526#define i915_verify_inactive(dev, file, line)
527#endif
528void i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle);
529void i915_gem_dump_object(struct drm_gem_object *obj, int len,
530 const char *where, uint32_t mark);
531void i915_dump_lru(struct drm_device *dev, const char *where);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Jesse Barnes317c35d2008-08-25 15:11:06 -0700533/* i915_suspend.c */
534extern int i915_save_state(struct drm_device *dev);
535extern int i915_restore_state(struct drm_device *dev);
536
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700537/* i915_suspend.c */
538extern int i915_save_state(struct drm_device *dev);
539extern int i915_restore_state(struct drm_device *dev);
540
Len Brown65e082c2008-10-24 17:18:10 -0400541#ifdef CONFIG_ACPI
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +0100542/* i915_opregion.c */
543extern int intel_opregion_init(struct drm_device *dev);
544extern void intel_opregion_free(struct drm_device *dev);
545extern void opregion_asle_intr(struct drm_device *dev);
546extern void opregion_enable_asle(struct drm_device *dev);
Len Brown65e082c2008-10-24 17:18:10 -0400547#else
548static inline int intel_opregion_init(struct drm_device *dev) { return 0; }
549static inline void intel_opregion_free(struct drm_device *dev) { return; }
550static inline void opregion_asle_intr(struct drm_device *dev) { return; }
551static inline void opregion_enable_asle(struct drm_device *dev) { return; }
552#endif
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +0100553
Eric Anholt546b0972008-09-01 16:45:29 -0700554/**
555 * Lock test for when it's just for synchronization of ring access.
556 *
557 * In that case, we don't need to do it when GEM is initialized as nobody else
558 * has access to the ring.
559 */
560#define RING_LOCK_TEST_WITH_RETURN(dev, file_priv) do { \
561 if (((drm_i915_private_t *)dev->dev_private)->ring.ring_obj == NULL) \
562 LOCK_TEST_WITH_RETURN(dev, file_priv); \
563} while (0)
564
Eric Anholt3043c602008-10-02 12:24:47 -0700565#define I915_READ(reg) readl(dev_priv->regs + (reg))
566#define I915_WRITE(reg, val) writel(val, dev_priv->regs + (reg))
567#define I915_READ16(reg) readw(dev_priv->regs + (reg))
568#define I915_WRITE16(reg, val) writel(val, dev_priv->regs + (reg))
569#define I915_READ8(reg) readb(dev_priv->regs + (reg))
570#define I915_WRITE8(reg, val) writeb(val, dev_priv->regs + (reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572#define I915_VERBOSE 0
573
574#define RING_LOCALS unsigned int outring, ringmask, outcount; \
575 volatile char *virt;
576
577#define BEGIN_LP_RING(n) do { \
578 if (I915_VERBOSE) \
Márton Németh3e684ea2008-01-24 15:58:57 +1000579 DRM_DEBUG("BEGIN_LP_RING(%d)\n", (n)); \
580 if (dev_priv->ring.space < (n)*4) \
Harvey Harrisonbf9d8922008-04-30 00:55:10 -0700581 i915_wait_ring(dev, (n)*4, __func__); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 outcount = 0; \
583 outring = dev_priv->ring.tail; \
584 ringmask = dev_priv->ring.tail_mask; \
585 virt = dev_priv->ring.virtual_start; \
586} while (0)
587
588#define OUT_RING(n) do { \
589 if (I915_VERBOSE) DRM_DEBUG(" OUT_RING %x\n", (int)(n)); \
Alan Hourihanec29b6692006-08-12 16:29:24 +1000590 *(volatile unsigned int *)(virt + outring) = (n); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 outcount++; \
592 outring += 4; \
593 outring &= ringmask; \
594} while (0)
595
596#define ADVANCE_LP_RING() do { \
597 if (I915_VERBOSE) DRM_DEBUG("ADVANCE_LP_RING %x\n", outring); \
598 dev_priv->ring.tail = outring; \
599 dev_priv->ring.space -= outcount * 4; \
Jesse Barnes585fb112008-07-29 11:54:06 -0700600 I915_WRITE(PRB0_TAIL, outring); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601} while(0)
602
Jesse Barnes585fb112008-07-29 11:54:06 -0700603/**
604 * Reads a dword out of the status page, which is written to from the command
605 * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
606 * MI_STORE_DATA_IMM.
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000607 *
Jesse Barnes585fb112008-07-29 11:54:06 -0700608 * The following dwords have a reserved meaning:
Keith Packard0cdad7e2008-10-14 17:19:38 -0700609 * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
610 * 0x04: ring 0 head pointer
611 * 0x05: ring 1 head pointer (915-class)
612 * 0x06: ring 2 head pointer (915-class)
613 * 0x10-0x1b: Context status DWords (GM45)
614 * 0x1f: Last written status offset. (GM45)
Jesse Barnes585fb112008-07-29 11:54:06 -0700615 *
Keith Packard0cdad7e2008-10-14 17:19:38 -0700616 * The area from dword 0x20 to 0x3ff is available for driver usage.
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000617 */
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000618#define READ_HWSP(dev_priv, reg) (((volatile u32*)(dev_priv->hw_status_page))[reg])
Keith Packard0baf8232008-11-08 11:44:14 +1000619#define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, I915_BREADCRUMB_INDEX)
Keith Packard0cdad7e2008-10-14 17:19:38 -0700620#define I915_GEM_HWS_INDEX 0x20
Keith Packard0baf8232008-11-08 11:44:14 +1000621#define I915_BREADCRUMB_INDEX 0x21
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000622
Jesse Barnes585fb112008-07-29 11:54:06 -0700623extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller);
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000624
625#define IS_I830(dev) ((dev)->pci_device == 0x3577)
626#define IS_845G(dev) ((dev)->pci_device == 0x2562)
627#define IS_I85X(dev) ((dev)->pci_device == 0x3582)
628#define IS_I855(dev) ((dev)->pci_device == 0x3582)
629#define IS_I865G(dev) ((dev)->pci_device == 0x2572)
630
Carlos Martín4d1f7882008-01-23 16:41:17 +1000631#define IS_I915G(dev) ((dev)->pci_device == 0x2582 || (dev)->pci_device == 0x258a)
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000632#define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
633#define IS_I945G(dev) ((dev)->pci_device == 0x2772)
Jesse Barnes3bf48462008-04-06 11:55:04 -0700634#define IS_I945GM(dev) ((dev)->pci_device == 0x27A2 ||\
635 (dev)->pci_device == 0x27AE)
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000636#define IS_I965G(dev) ((dev)->pci_device == 0x2972 || \
637 (dev)->pci_device == 0x2982 || \
638 (dev)->pci_device == 0x2992 || \
639 (dev)->pci_device == 0x29A2 || \
640 (dev)->pci_device == 0x2A02 || \
Zhenyu Wang5f5f9d42008-01-24 16:46:36 +1000641 (dev)->pci_device == 0x2A12 || \
Zhenyu Wangd3adbc02008-06-20 12:12:56 +1000642 (dev)->pci_device == 0x2A42 || \
643 (dev)->pci_device == 0x2E02 || \
644 (dev)->pci_device == 0x2E12 || \
645 (dev)->pci_device == 0x2E22)
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000646
647#define IS_I965GM(dev) ((dev)->pci_device == 0x2A02)
648
Jesse Barnesb9bfdfe2008-08-25 15:16:19 -0700649#define IS_GM45(dev) ((dev)->pci_device == 0x2A42)
Zhenyu Wang5f5f9d42008-01-24 16:46:36 +1000650
Zhenyu Wangd3adbc02008-06-20 12:12:56 +1000651#define IS_G4X(dev) ((dev)->pci_device == 0x2E02 || \
652 (dev)->pci_device == 0x2E12 || \
653 (dev)->pci_device == 0x2E22)
654
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000655#define IS_G33(dev) ((dev)->pci_device == 0x29C2 || \
656 (dev)->pci_device == 0x29B2 || \
657 (dev)->pci_device == 0x29D2)
658
659#define IS_I9XX(dev) (IS_I915G(dev) || IS_I915GM(dev) || IS_I945G(dev) || \
660 IS_I945GM(dev) || IS_I965G(dev) || IS_G33(dev))
661
662#define IS_MOBILE(dev) (IS_I830(dev) || IS_I85X(dev) || IS_I915GM(dev) || \
Jesse Barnesb9bfdfe2008-08-25 15:16:19 -0700663 IS_I945GM(dev) || IS_I965GM(dev) || IS_GM45(dev))
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000664
Jesse Barnesb9bfdfe2008-08-25 15:16:19 -0700665#define I915_NEED_GFX_HWS(dev) (IS_G33(dev) || IS_GM45(dev) || IS_G4X(dev))
Zhenyu Wangb39d50e2008-02-19 20:59:09 +1000666
Jesse Barnesba8bbcf2007-11-22 14:14:14 +1000667#define PRIMARY_RINGBUFFER_SIZE (128*1024)
Dave Airlie0d6aa602006-01-02 20:14:23 +1100668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669#endif