Rev 2339 | Rev 2342 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2325 | Serge | 1 | /* i915_drv.c -- i830,i845,i855,i865,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 | |||
2330 | Serge | 30 | //#include |
31 | #include "drmP.h" |
||
32 | #include "drm.h" |
||
33 | #include "i915_drm.h" |
||
34 | #include "i915_drv.h" |
||
35 | #include "intel_drv.h" |
||
2325 | Serge | 36 | |
2330 | Serge | 37 | |
2325 | Serge | 38 | #include |
39 | #include |
||
40 | #include |
||
41 | #include |
||
42 | #include |
||
43 | |||
44 | #include |
||
45 | |||
2330 | Serge | 46 | #define __read_mostly |
2327 | Serge | 47 | |
2338 | Serge | 48 | int init_display_kms(struct drm_device *dev); |
2330 | Serge | 49 | |
2340 | Serge | 50 | struct drm_device *main_device; |
2338 | Serge | 51 | |
2332 | Serge | 52 | int i915_panel_ignore_lid __read_mostly = 0; |
2330 | Serge | 53 | |
2332 | Serge | 54 | unsigned int i915_powersave __read_mostly = 0; |
2330 | Serge | 55 | |
2332 | Serge | 56 | unsigned int i915_enable_rc6 __read_mostly = 0; |
2330 | Serge | 57 | |
2336 | Serge | 58 | unsigned int i915_enable_fbc __read_mostly = 0; |
2330 | Serge | 59 | |
60 | unsigned int i915_lvds_downclock __read_mostly = 0; |
||
61 | |||
2332 | Serge | 62 | unsigned int i915_panel_use_ssc __read_mostly = 1; |
2330 | Serge | 63 | |
2332 | Serge | 64 | int i915_vbt_sdvo_panel_type __read_mostly = -1; |
2330 | Serge | 65 | |
2326 | Serge | 66 | #define PCI_VENDOR_ID_INTEL 0x8086 |
67 | |||
2325 | Serge | 68 | #define INTEL_VGA_DEVICE(id, info) { \ |
69 | .class = PCI_CLASS_DISPLAY_VGA << 8, \ |
||
70 | .class_mask = 0xff0000, \ |
||
71 | .vendor = 0x8086, \ |
||
72 | .device = id, \ |
||
73 | .subvendor = PCI_ANY_ID, \ |
||
74 | .subdevice = PCI_ANY_ID, \ |
||
75 | .driver_data = (unsigned long) info } |
||
76 | |||
2339 | Serge | 77 | static const struct intel_device_info intel_i830_info = { |
78 | .gen = 2, .is_mobile = 1, .cursor_needs_physical = 1, |
||
79 | .has_overlay = 1, .overlay_needs_physical = 1, |
||
80 | }; |
||
81 | |||
82 | static const struct intel_device_info intel_845g_info = { |
||
83 | .gen = 2, |
||
84 | .has_overlay = 1, .overlay_needs_physical = 1, |
||
85 | }; |
||
86 | |||
87 | static const struct intel_device_info intel_i85x_info = { |
||
88 | .gen = 2, .is_i85x = 1, .is_mobile = 1, |
||
89 | .cursor_needs_physical = 1, |
||
90 | .has_overlay = 1, .overlay_needs_physical = 1, |
||
91 | }; |
||
92 | |||
93 | static const struct intel_device_info intel_i865g_info = { |
||
94 | .gen = 2, |
||
95 | .has_overlay = 1, .overlay_needs_physical = 1, |
||
96 | }; |
||
97 | |||
98 | static const struct intel_device_info intel_i915g_info = { |
||
99 | .gen = 3, .is_i915g = 1, .cursor_needs_physical = 1, |
||
100 | .has_overlay = 1, .overlay_needs_physical = 1, |
||
101 | }; |
||
102 | static const struct intel_device_info intel_i915gm_info = { |
||
103 | .gen = 3, .is_mobile = 1, |
||
104 | .cursor_needs_physical = 1, |
||
105 | .has_overlay = 1, .overlay_needs_physical = 1, |
||
106 | .supports_tv = 1, |
||
107 | }; |
||
108 | static const struct intel_device_info intel_i945g_info = { |
||
109 | .gen = 3, .has_hotplug = 1, .cursor_needs_physical = 1, |
||
110 | .has_overlay = 1, .overlay_needs_physical = 1, |
||
111 | }; |
||
112 | static const struct intel_device_info intel_i945gm_info = { |
||
113 | .gen = 3, .is_i945gm = 1, .is_mobile = 1, |
||
114 | .has_hotplug = 1, .cursor_needs_physical = 1, |
||
115 | .has_overlay = 1, .overlay_needs_physical = 1, |
||
116 | .supports_tv = 1, |
||
117 | }; |
||
118 | |||
119 | static const struct intel_device_info intel_i965g_info = { |
||
120 | .gen = 4, .is_broadwater = 1, |
||
121 | .has_hotplug = 1, |
||
122 | .has_overlay = 1, |
||
123 | }; |
||
124 | |||
125 | static const struct intel_device_info intel_i965gm_info = { |
||
126 | .gen = 4, .is_crestline = 1, |
||
127 | .is_mobile = 1, .has_fbc = 1, .has_hotplug = 1, |
||
128 | .has_overlay = 1, |
||
129 | .supports_tv = 1, |
||
130 | }; |
||
131 | |||
132 | static const struct intel_device_info intel_g33_info = { |
||
133 | .gen = 3, .is_g33 = 1, |
||
134 | .need_gfx_hws = 1, .has_hotplug = 1, |
||
135 | .has_overlay = 1, |
||
136 | }; |
||
137 | |||
138 | static const struct intel_device_info intel_g45_info = { |
||
139 | .gen = 4, .is_g4x = 1, .need_gfx_hws = 1, |
||
140 | .has_pipe_cxsr = 1, .has_hotplug = 1, |
||
141 | .has_bsd_ring = 1, |
||
142 | }; |
||
143 | |||
144 | static const struct intel_device_info intel_gm45_info = { |
||
145 | .gen = 4, .is_g4x = 1, |
||
146 | .is_mobile = 1, .need_gfx_hws = 1, .has_fbc = 1, |
||
147 | .has_pipe_cxsr = 1, .has_hotplug = 1, |
||
148 | .supports_tv = 1, |
||
149 | .has_bsd_ring = 1, |
||
150 | }; |
||
151 | |||
152 | static const struct intel_device_info intel_pineview_info = { |
||
153 | .gen = 3, .is_g33 = 1, .is_pineview = 1, .is_mobile = 1, |
||
154 | .need_gfx_hws = 1, .has_hotplug = 1, |
||
155 | .has_overlay = 1, |
||
156 | }; |
||
157 | |||
158 | static const struct intel_device_info intel_ironlake_d_info = { |
||
159 | .gen = 5, |
||
160 | .need_gfx_hws = 1, .has_pipe_cxsr = 1, .has_hotplug = 1, |
||
161 | .has_bsd_ring = 1, |
||
162 | }; |
||
163 | |||
164 | static const struct intel_device_info intel_ironlake_m_info = { |
||
165 | .gen = 5, .is_mobile = 1, |
||
166 | .need_gfx_hws = 1, .has_hotplug = 1, |
||
167 | .has_fbc = 1, |
||
168 | .has_bsd_ring = 1, |
||
169 | }; |
||
170 | |||
2325 | Serge | 171 | static const struct intel_device_info intel_sandybridge_d_info = { |
172 | .gen = 6, |
||
2330 | Serge | 173 | .need_gfx_hws = 1, .has_hotplug = 1, |
2325 | Serge | 174 | .has_bsd_ring = 1, |
175 | .has_blt_ring = 1, |
||
176 | }; |
||
177 | |||
178 | static const struct intel_device_info intel_sandybridge_m_info = { |
||
2330 | Serge | 179 | .gen = 6, .is_mobile = 1, |
180 | .need_gfx_hws = 1, .has_hotplug = 1, |
||
2325 | Serge | 181 | .has_fbc = 1, |
182 | .has_bsd_ring = 1, |
||
183 | .has_blt_ring = 1, |
||
184 | }; |
||
185 | |||
2339 | Serge | 186 | static const struct intel_device_info intel_ivybridge_d_info = { |
187 | .is_ivybridge = 1, .gen = 7, |
||
188 | .need_gfx_hws = 1, .has_hotplug = 1, |
||
189 | .has_bsd_ring = 1, |
||
190 | .has_blt_ring = 1, |
||
191 | }; |
||
2325 | Serge | 192 | |
2339 | Serge | 193 | static const struct intel_device_info intel_ivybridge_m_info = { |
194 | .is_ivybridge = 1, .gen = 7, .is_mobile = 1, |
||
195 | .need_gfx_hws = 1, .has_hotplug = 1, |
||
196 | .has_fbc = 0, /* FBC is not enabled on Ivybridge mobile yet */ |
||
197 | .has_bsd_ring = 1, |
||
198 | .has_blt_ring = 1, |
||
199 | }; |
||
200 | |||
2325 | Serge | 201 | static const struct pci_device_id pciidlist[] = { /* aka */ |
2339 | Serge | 202 | INTEL_VGA_DEVICE(0x2582, &intel_i915g_info), /* I915_G */ |
203 | INTEL_VGA_DEVICE(0x258a, &intel_i915g_info), /* E7221_G */ |
||
204 | INTEL_VGA_DEVICE(0x2592, &intel_i915gm_info), /* I915_GM */ |
||
205 | INTEL_VGA_DEVICE(0x2772, &intel_i945g_info), /* I945_G */ |
||
206 | INTEL_VGA_DEVICE(0x27a2, &intel_i945gm_info), /* I945_GM */ |
||
207 | INTEL_VGA_DEVICE(0x27ae, &intel_i945gm_info), /* I945_GME */ |
||
208 | INTEL_VGA_DEVICE(0x2972, &intel_i965g_info), /* I946_GZ */ |
||
209 | INTEL_VGA_DEVICE(0x2982, &intel_i965g_info), /* G35_G */ |
||
210 | INTEL_VGA_DEVICE(0x2992, &intel_i965g_info), /* I965_Q */ |
||
211 | INTEL_VGA_DEVICE(0x29a2, &intel_i965g_info), /* I965_G */ |
||
212 | INTEL_VGA_DEVICE(0x29b2, &intel_g33_info), /* Q35_G */ |
||
213 | INTEL_VGA_DEVICE(0x29c2, &intel_g33_info), /* G33_G */ |
||
214 | INTEL_VGA_DEVICE(0x29d2, &intel_g33_info), /* Q33_G */ |
||
215 | INTEL_VGA_DEVICE(0x2a02, &intel_i965gm_info), /* I965_GM */ |
||
216 | INTEL_VGA_DEVICE(0x2a12, &intel_i965gm_info), /* I965_GME */ |
||
217 | INTEL_VGA_DEVICE(0x2a42, &intel_gm45_info), /* GM45_G */ |
||
218 | INTEL_VGA_DEVICE(0x2e02, &intel_g45_info), /* IGD_E_G */ |
||
219 | INTEL_VGA_DEVICE(0x2e12, &intel_g45_info), /* Q45_G */ |
||
220 | INTEL_VGA_DEVICE(0x2e22, &intel_g45_info), /* G45_G */ |
||
221 | INTEL_VGA_DEVICE(0x2e32, &intel_g45_info), /* G41_G */ |
||
222 | INTEL_VGA_DEVICE(0x2e42, &intel_g45_info), /* B43_G */ |
||
223 | INTEL_VGA_DEVICE(0x2e92, &intel_g45_info), /* B43_G.1 */ |
||
224 | INTEL_VGA_DEVICE(0xa001, &intel_pineview_info), |
||
225 | INTEL_VGA_DEVICE(0xa011, &intel_pineview_info), |
||
226 | INTEL_VGA_DEVICE(0x0042, &intel_ironlake_d_info), |
||
227 | INTEL_VGA_DEVICE(0x0046, &intel_ironlake_m_info), |
||
2325 | Serge | 228 | INTEL_VGA_DEVICE(0x0102, &intel_sandybridge_d_info), |
229 | INTEL_VGA_DEVICE(0x0112, &intel_sandybridge_d_info), |
||
230 | INTEL_VGA_DEVICE(0x0122, &intel_sandybridge_d_info), |
||
231 | INTEL_VGA_DEVICE(0x0106, &intel_sandybridge_m_info), |
||
232 | INTEL_VGA_DEVICE(0x0116, &intel_sandybridge_m_info), |
||
233 | INTEL_VGA_DEVICE(0x0126, &intel_sandybridge_m_info), |
||
234 | INTEL_VGA_DEVICE(0x010A, &intel_sandybridge_d_info), |
||
2339 | Serge | 235 | INTEL_VGA_DEVICE(0x0156, &intel_ivybridge_m_info), /* GT1 mobile */ |
236 | INTEL_VGA_DEVICE(0x0166, &intel_ivybridge_m_info), /* GT2 mobile */ |
||
237 | INTEL_VGA_DEVICE(0x0152, &intel_ivybridge_d_info), /* GT1 desktop */ |
||
238 | INTEL_VGA_DEVICE(0x0162, &intel_ivybridge_d_info), /* GT2 desktop */ |
||
239 | INTEL_VGA_DEVICE(0x015a, &intel_ivybridge_d_info), /* GT1 server */ |
||
2325 | Serge | 240 | {0, 0, 0} |
241 | }; |
||
242 | |||
2326 | Serge | 243 | #define INTEL_PCH_DEVICE_ID_MASK 0xff00 |
244 | #define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00 |
||
245 | #define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00 |
||
246 | #define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00 |
||
2325 | Serge | 247 | |
2326 | Serge | 248 | void intel_detect_pch (struct drm_device *dev) |
249 | { |
||
250 | struct drm_i915_private *dev_priv = dev->dev_private; |
||
251 | struct pci_dev *pch; |
||
252 | |||
253 | /* |
||
254 | * The reason to probe ISA bridge instead of Dev31:Fun0 is to |
||
255 | * make graphics device passthrough work easy for VMM, that only |
||
256 | * need to expose ISA bridge to let driver know the real hardware |
||
257 | * underneath. This is a requirement from virtualization team. |
||
258 | */ |
||
259 | pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL); |
||
260 | if (pch) { |
||
261 | if (pch->vendor == PCI_VENDOR_ID_INTEL) { |
||
262 | int id; |
||
263 | id = pch->device & INTEL_PCH_DEVICE_ID_MASK; |
||
264 | |||
265 | if (id == INTEL_PCH_IBX_DEVICE_ID_TYPE) { |
||
266 | dev_priv->pch_type = PCH_IBX; |
||
267 | DRM_DEBUG_KMS("Found Ibex Peak PCH\n"); |
||
268 | } else if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) { |
||
269 | dev_priv->pch_type = PCH_CPT; |
||
270 | DRM_DEBUG_KMS("Found CougarPoint PCH\n"); |
||
271 | } else if (id == INTEL_PCH_PPT_DEVICE_ID_TYPE) { |
||
272 | /* PantherPoint is CPT compatible */ |
||
273 | dev_priv->pch_type = PCH_CPT; |
||
274 | DRM_DEBUG_KMS("Found PatherPoint PCH\n"); |
||
275 | } |
||
276 | } |
||
277 | } |
||
278 | } |
||
279 | |||
280 | static void __gen6_gt_force_wake_get(struct drm_i915_private *dev_priv) |
||
281 | { |
||
282 | int count; |
||
283 | |||
284 | count = 0; |
||
285 | while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1)) |
||
286 | udelay(10); |
||
287 | |||
288 | I915_WRITE_NOTRACE(FORCEWAKE, 1); |
||
289 | POSTING_READ(FORCEWAKE); |
||
290 | |||
291 | count = 0; |
||
292 | while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1) == 0) |
||
293 | udelay(10); |
||
294 | } |
||
295 | |||
296 | /* |
||
297 | * Generally this is called implicitly by the register read function. However, |
||
298 | * if some sequence requires the GT to not power down then this function should |
||
299 | * be called at the beginning of the sequence followed by a call to |
||
300 | * gen6_gt_force_wake_put() at the end of the sequence. |
||
301 | */ |
||
302 | void gen6_gt_force_wake_get(struct drm_i915_private *dev_priv) |
||
303 | { |
||
304 | // WARN_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex)); |
||
305 | |||
306 | /* Forcewake is atomic in case we get in here without the lock */ |
||
307 | if (atomic_add_return(1, &dev_priv->forcewake_count) == 1) |
||
308 | __gen6_gt_force_wake_get(dev_priv); |
||
309 | } |
||
310 | |||
311 | static void __gen6_gt_force_wake_put(struct drm_i915_private *dev_priv) |
||
312 | { |
||
313 | I915_WRITE_NOTRACE(FORCEWAKE, 0); |
||
314 | POSTING_READ(FORCEWAKE); |
||
315 | } |
||
316 | |||
317 | /* |
||
318 | * see gen6_gt_force_wake_get() |
||
319 | */ |
||
320 | void gen6_gt_force_wake_put(struct drm_i915_private *dev_priv) |
||
321 | { |
||
322 | // WARN_ON(!mutex_is_locked(&dev_priv->dev->struct_mutex)); |
||
323 | |||
324 | if (atomic_dec_and_test(&dev_priv->forcewake_count)) |
||
325 | __gen6_gt_force_wake_put(dev_priv); |
||
326 | } |
||
327 | |||
328 | void __gen6_gt_wait_for_fifo(struct drm_i915_private *dev_priv) |
||
329 | { |
||
330 | if (dev_priv->gt_fifo_count < GT_FIFO_NUM_RESERVED_ENTRIES ) { |
||
331 | int loop = 500; |
||
332 | u32 fifo = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES); |
||
333 | while (fifo <= GT_FIFO_NUM_RESERVED_ENTRIES && loop--) { |
||
334 | udelay(10); |
||
335 | fifo = I915_READ_NOTRACE(GT_FIFO_FREE_ENTRIES); |
||
336 | } |
||
337 | // WARN_ON(loop < 0 && fifo <= GT_FIFO_NUM_RESERVED_ENTRIES); |
||
338 | dev_priv->gt_fifo_count = fifo; |
||
339 | } |
||
340 | dev_priv->gt_fifo_count--; |
||
341 | } |
||
342 | |||
343 | |||
344 | |||
345 | |||
346 | |||
2325 | Serge | 347 | int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent); |
348 | |||
349 | int i915_init(void) |
||
350 | { |
||
351 | static pci_dev_t device; |
||
352 | const struct pci_device_id *ent; |
||
353 | int err; |
||
354 | |||
355 | if( init_agp() != 0) |
||
356 | { |
||
357 | DRM_ERROR("drm/i915 can't work without intel_agp module!\n"); |
||
358 | return 0; |
||
359 | }; |
||
360 | |||
361 | ent = find_pci_device(&device, pciidlist); |
||
362 | |||
363 | if( unlikely(ent == NULL) ) |
||
364 | { |
||
365 | dbgprintf("device not found\n"); |
||
366 | return 0; |
||
367 | }; |
||
368 | |||
369 | dbgprintf("device %x:%x\n", device.pci_dev.vendor, |
||
370 | device.pci_dev.device); |
||
371 | |||
372 | err = drm_get_dev(&device.pci_dev, ent); |
||
373 | |||
374 | return err; |
||
375 | } |
||
376 | |||
377 | int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent) |
||
378 | { |
||
2340 | Serge | 379 | struct drm_device *dev; |
2325 | Serge | 380 | int ret; |
381 | |||
382 | ENTER(); |
||
383 | |||
384 | dev = kzalloc(sizeof(*dev), 0); |
||
385 | if (!dev) |
||
386 | return -ENOMEM; |
||
387 | |||
388 | // ret = pci_enable_device(pdev); |
||
389 | // if (ret) |
||
390 | // goto err_g1; |
||
391 | |||
392 | // pci_set_master(pdev); |
||
393 | |||
394 | // if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) { |
||
395 | // printk(KERN_ERR "DRM: Fill_in_dev failed.\n"); |
||
396 | // goto err_g2; |
||
397 | // } |
||
398 | |||
399 | dev->pdev = pdev; |
||
400 | dev->pci_device = pdev->device; |
||
401 | dev->pci_vendor = pdev->vendor; |
||
402 | |||
403 | INIT_LIST_HEAD(&dev->filelist); |
||
404 | INIT_LIST_HEAD(&dev->ctxlist); |
||
405 | INIT_LIST_HEAD(&dev->vmalist); |
||
406 | INIT_LIST_HEAD(&dev->maplist); |
||
407 | |||
408 | spin_lock_init(&dev->count_lock); |
||
409 | mutex_init(&dev->struct_mutex); |
||
410 | mutex_init(&dev->ctxlist_mutex); |
||
411 | |||
2336 | Serge | 412 | ret = i915_driver_load(dev, ent->driver_data ); |
2325 | Serge | 413 | |
2338 | Serge | 414 | if (ret) |
415 | goto err_g4; |
||
2330 | Serge | 416 | |
2338 | Serge | 417 | ret = init_display_kms(dev); |
2336 | Serge | 418 | |
2338 | Serge | 419 | if (ret) |
420 | goto err_g4; |
||
2336 | Serge | 421 | |
2340 | Serge | 422 | main_device = dev; |
2336 | Serge | 423 | |
2325 | Serge | 424 | LEAVE(); |
425 | |||
426 | return 0; |
||
427 | |||
428 | err_g4: |
||
429 | // drm_put_minor(&dev->primary); |
||
430 | //err_g3: |
||
431 | // if (drm_core_check_feature(dev, DRIVER_MODESET)) |
||
432 | // drm_put_minor(&dev->control); |
||
433 | //err_g2: |
||
434 | // pci_disable_device(pdev); |
||
435 | //err_g1: |
||
436 | free(dev); |
||
437 | |||
438 | LEAVE(); |
||
439 | |||
440 | return ret; |
||
441 | }=>>=>>>>><>><> |
||
442 |