]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/nouveau_drv.h
drm/nouveau/backlight: remove dependence on nouveau_drv.h
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / nouveau_drv.h
1 /*
2  * Copyright 2005 Stephane Marchesin.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * 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  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS 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
25 #ifndef __NOUVEAU_DRV_H__
26 #define __NOUVEAU_DRV_H__
27
28 #define DRIVER_AUTHOR           "Stephane Marchesin"
29 #define DRIVER_EMAIL            "nouveau@lists.freedesktop.org"
30
31 #define DRIVER_NAME             "nouveau"
32 #define DRIVER_DESC             "nVidia Riva/TNT/GeForce"
33 #define DRIVER_DATE             "20120316"
34
35 #define DRIVER_MAJOR            1
36 #define DRIVER_MINOR            0
37 #define DRIVER_PATCHLEVEL       0
38
39 #define NOUVEAU_FAMILY   0x0000FFFF
40 #define NOUVEAU_FLAGS    0xFFFF0000
41
42 #include "ttm/ttm_bo_api.h"
43 #include "ttm/ttm_bo_driver.h"
44 #include "ttm/ttm_placement.h"
45 #include "ttm/ttm_memory.h"
46 #include "ttm/ttm_module.h"
47
48 #define XXX_THIS_IS_A_HACK
49 #include <subdev/vm.h>
50 #include <subdev/fb.h>
51 #include <core/gpuobj.h>
52
53 enum blah {
54         NV_MEM_TYPE_UNKNOWN = 0,
55         NV_MEM_TYPE_STOLEN,
56         NV_MEM_TYPE_SGRAM,
57         NV_MEM_TYPE_SDRAM,
58         NV_MEM_TYPE_DDR1,
59         NV_MEM_TYPE_DDR2,
60         NV_MEM_TYPE_DDR3,
61         NV_MEM_TYPE_GDDR2,
62         NV_MEM_TYPE_GDDR3,
63         NV_MEM_TYPE_GDDR4,
64         NV_MEM_TYPE_GDDR5
65 };
66
67 #include <nouveau_drm.h>
68 #include "nouveau_reg.h"
69 #include <nouveau_bios.h>
70
71 #include <subdev/bios/pll.h>
72 #include "nouveau_compat.h"
73
74 #define nouveau_gpuobj_new(d,c,s,a,f,o) \
75         _nouveau_gpuobj_new((d), NULL, (s), (a), (f), (o))
76
77 #define nouveau_vm_new(d,o,l,m,v) \
78         _nouveau_vm_new((d), (o), (l), (m), (v))
79
80 #define nv50_vm_flush_engine(d,e) \
81         _nv50_vm_flush_engine((d), (e))
82
83 #include "nouveau_bo.h"
84 #include "nouveau_gem.h"
85
86 struct nouveau_page_flip_state {
87         struct list_head head;
88         struct drm_pending_vblank_event *event;
89         int crtc, bpp, pitch, x, y;
90         uint64_t offset;
91 };
92
93 struct nouveau_display_engine {
94         void *priv;
95         int (*early_init)(struct drm_device *);
96         void (*late_takedown)(struct drm_device *);
97         int (*create)(struct drm_device *);
98         void (*destroy)(struct drm_device *);
99         int (*init)(struct drm_device *);
100         void (*fini)(struct drm_device *);
101
102         struct drm_property *dithering_mode;
103         struct drm_property *dithering_depth;
104         struct drm_property *underscan_property;
105         struct drm_property *underscan_hborder_property;
106         struct drm_property *underscan_vborder_property;
107         /* not really hue and saturation: */
108         struct drm_property *vibrant_hue_property;
109         struct drm_property *color_vibrance_property;
110 };
111
112 struct nouveau_pm_voltage_level {
113         u32 voltage; /* microvolts */
114         u8  vid;
115 };
116
117 struct nouveau_pm_voltage {
118         bool supported;
119         u8 version;
120         u8 vid_mask;
121
122         struct nouveau_pm_voltage_level *level;
123         int nr_level;
124 };
125
126 /* Exclusive upper limits */
127 #define NV_MEM_CL_DDR2_MAX 8
128 #define NV_MEM_WR_DDR2_MAX 9
129 #define NV_MEM_CL_DDR3_MAX 17
130 #define NV_MEM_WR_DDR3_MAX 17
131 #define NV_MEM_CL_GDDR3_MAX 16
132 #define NV_MEM_WR_GDDR3_MAX 18
133 #define NV_MEM_CL_GDDR5_MAX 21
134 #define NV_MEM_WR_GDDR5_MAX 20
135
136 struct nouveau_pm_memtiming {
137         int id;
138
139         u32 reg[9];
140         u32 mr[4];
141
142         u8 tCWL;
143
144         u8 odt;
145         u8 drive_strength;
146 };
147
148 struct nouveau_pm_tbl_header {
149         u8 version;
150         u8 header_len;
151         u8 entry_cnt;
152         u8 entry_len;
153 };
154
155 struct nouveau_pm_tbl_entry {
156         u8 tWR;
157         u8 tWTR;
158         u8 tCL;
159         u8 tRC;
160         u8 empty_4;
161         u8 tRFC;        /* Byte 5 */
162         u8 empty_6;
163         u8 tRAS;        /* Byte 7 */
164         u8 empty_8;
165         u8 tRP;         /* Byte 9 */
166         u8 tRCDRD;
167         u8 tRCDWR;
168         u8 tRRD;
169         u8 tUNK_13;
170         u8 RAM_FT1;             /* 14, a bitmask of random RAM features */
171         u8 empty_15;
172         u8 tUNK_16;
173         u8 empty_17;
174         u8 tUNK_18;
175         u8 tCWL;
176         u8 tUNK_20, tUNK_21;
177 };
178
179 struct nouveau_pm_profile;
180 struct nouveau_pm_profile_func {
181         void (*destroy)(struct nouveau_pm_profile *);
182         void (*init)(struct nouveau_pm_profile *);
183         void (*fini)(struct nouveau_pm_profile *);
184         struct nouveau_pm_level *(*select)(struct nouveau_pm_profile *);
185 };
186
187 struct nouveau_pm_profile {
188         const struct nouveau_pm_profile_func *func;
189         struct list_head head;
190         char name[8];
191 };
192
193 #define NOUVEAU_PM_MAX_LEVEL 8
194 struct nouveau_pm_level {
195         struct nouveau_pm_profile profile;
196         struct device_attribute dev_attr;
197         char name[32];
198         int id;
199
200         struct nouveau_pm_memtiming timing;
201         u32 memory;
202         u16 memscript;
203
204         u32 core;
205         u32 shader;
206         u32 rop;
207         u32 copy;
208         u32 daemon;
209         u32 vdec;
210         u32 dom6;
211         u32 unka0;      /* nva3:nvc0 */
212         u32 hub01;      /* nvc0- */
213         u32 hub06;      /* nvc0- */
214         u32 hub07;      /* nvc0- */
215
216         u32 volt_min; /* microvolts */
217         u32 volt_max;
218         u8  fanspeed;
219 };
220
221 struct nouveau_pm_temp_sensor_constants {
222         u16 offset_constant;
223         s16 offset_mult;
224         s16 offset_div;
225         s16 slope_mult;
226         s16 slope_div;
227 };
228
229 struct nouveau_pm_threshold_temp {
230         s16 critical;
231         s16 down_clock;
232         s16 fan_boost;
233 };
234
235 struct nouveau_pm_fan {
236         u32 percent;
237         u32 min_duty;
238         u32 max_duty;
239         u32 pwm_freq;
240         u32 pwm_divisor;
241 };
242
243 struct nouveau_pm_engine {
244         struct nouveau_pm_voltage voltage;
245         struct nouveau_pm_level perflvl[NOUVEAU_PM_MAX_LEVEL];
246         int nr_perflvl;
247         struct nouveau_pm_temp_sensor_constants sensor_constants;
248         struct nouveau_pm_threshold_temp threshold_temp;
249         struct nouveau_pm_fan fan;
250
251         struct nouveau_pm_profile *profile_ac;
252         struct nouveau_pm_profile *profile_dc;
253         struct nouveau_pm_profile *profile;
254         struct list_head profiles;
255
256         struct nouveau_pm_level boot;
257         struct nouveau_pm_level *cur;
258
259         struct device *hwmon;
260         struct notifier_block acpi_nb;
261
262         int  (*clocks_get)(struct drm_device *, struct nouveau_pm_level *);
263         void *(*clocks_pre)(struct drm_device *, struct nouveau_pm_level *);
264         int (*clocks_set)(struct drm_device *, void *);
265
266         int (*voltage_get)(struct drm_device *);
267         int (*voltage_set)(struct drm_device *, int voltage);
268         int (*pwm_get)(struct drm_device *, int line, u32*, u32*);
269         int (*pwm_set)(struct drm_device *, int line, u32, u32);
270         int (*temp_get)(struct drm_device *);
271 };
272
273 struct nouveau_engine {
274         struct nouveau_display_engine display;
275         struct nouveau_pm_engine      pm;
276 };
277
278 enum nouveau_card_type {
279         NV_04      = 0x04,
280         NV_10      = 0x10,
281         NV_20      = 0x20,
282         NV_30      = 0x30,
283         NV_40      = 0x40,
284         NV_50      = 0x50,
285         NV_C0      = 0xc0,
286         NV_D0      = 0xd0,
287         NV_E0      = 0xe0,
288 };
289
290 struct drm_nouveau_private {
291         struct drm_device *dev;
292
293         void *newpriv;
294
295         /* the card type, takes NV_* as values */
296         enum nouveau_card_type card_type;
297         /* exact chipset, derived from NV_PMC_BOOT_0 */
298         int chipset;
299         u32 crystal;
300
301         /* interrupt handling */
302         void (*irq_handler[32])(struct drm_device *);
303         bool msi_enabled;
304
305         struct nouveau_engine engine;
306
307         /* For PFIFO and PGRAPH. */
308         spinlock_t context_switch_lock;
309
310         struct nvbios vbios;
311 };
312
313 static inline struct drm_nouveau_private *
314 nouveau_private(struct drm_device *dev)
315 {
316         return dev->dev_private;
317 }
318
319 /* nouveau_drv.c */
320 extern int nouveau_modeset;
321 extern int nouveau_duallink;
322 extern int nouveau_uscript_lvds;
323 extern int nouveau_uscript_tmds;
324 extern int nouveau_vram_pushbuf;
325 extern int nouveau_vram_notify;
326 extern char *nouveau_vram_type;
327 extern int nouveau_fbpercrtc;
328 extern int nouveau_tv_disable;
329 extern char *nouveau_tv_norm;
330 extern int nouveau_ignorelid;
331 extern int nouveau_force_post;
332 extern int nouveau_override_conntype;
333 extern char *nouveau_perflvl;
334 extern int nouveau_perflvl_wr;
335 extern int nouveau_msi;
336 extern int nouveau_ctxfw;
337 extern int nouveau_mxmdcb;
338
339 extern int nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state);
340 extern int nouveau_pci_resume(struct pci_dev *pdev);
341
342 /* nouveau_state.c */
343 extern int  nouveau_load(struct drm_device *, unsigned long flags);
344 extern int  nouveau_firstopen(struct drm_device *);
345 extern void nouveau_lastclose(struct drm_device *);
346 extern int  nouveau_unload(struct drm_device *);
347 extern int  nouveau_card_init(struct drm_device *);
348
349 /* nouveau_mem.c */
350 extern int  nouveau_mem_timing_calc(struct drm_device *, u32 freq,
351                                     struct nouveau_pm_memtiming *);
352 extern void nouveau_mem_timing_read(struct drm_device *,
353                                     struct nouveau_pm_memtiming *);
354
355 /* nouveau_irq.c */
356 extern int         nouveau_irq_init(struct drm_device *);
357 extern void        nouveau_irq_fini(struct drm_device *);
358 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
359 extern void        nouveau_irq_register(struct drm_device *, int status_bit,
360                                         void (*)(struct drm_device *));
361 extern void        nouveau_irq_unregister(struct drm_device *, int status_bit);
362 extern void        nouveau_irq_preinstall(struct drm_device *);
363 extern int         nouveau_irq_postinstall(struct drm_device *);
364 extern void        nouveau_irq_uninstall(struct drm_device *);
365
366 /* nouveau_backlight.c */
367 #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
368 extern int nouveau_backlight_init(struct drm_device *);
369 extern void nouveau_backlight_exit(struct drm_device *);
370 #else
371 static inline int nouveau_backlight_init(struct drm_device *dev)
372 {
373         return 0;
374 }
375
376 static inline void nouveau_backlight_exit(struct drm_device *dev) { }
377 #endif
378
379 /* nouveau_bios.c */
380 extern int nouveau_bios_init(struct drm_device *);
381 extern void nouveau_bios_takedown(struct drm_device *dev);
382 extern int nouveau_run_vbios_init(struct drm_device *);
383 extern struct dcb_connector_table_entry *
384 nouveau_bios_connector_entry(struct drm_device *, int index);
385 extern int nouveau_bios_run_display_table(struct drm_device *, u16 id, int clk,
386                                           struct dcb_output *, int crtc);
387 extern bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *);
388 extern uint8_t *nouveau_bios_embedded_edid(struct drm_device *);
389 extern int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
390                                          bool *dl, bool *if_is_24bit);
391 extern int run_tmds_table(struct drm_device *, struct dcb_output *,
392                           int head, int pxclk);
393 extern int call_lvds_script(struct drm_device *, struct dcb_output *, int head,
394                             enum LVDS_script, int pxclk);
395 bool bios_encoder_match(struct dcb_output *, u32 hash);
396
397 /* nouveau_ttm.c */
398 int nouveau_ttm_global_init(struct drm_nouveau_private *);
399 void nouveau_ttm_global_release(struct drm_nouveau_private *);
400 int nouveau_ttm_mmap(struct file *, struct vm_area_struct *);
401
402 /* nouveau_hdmi.c */
403 void nouveau_hdmi_mode_set(struct drm_encoder *, struct drm_display_mode *);
404
405 /* nvd0_display.c */
406 extern int nvd0_display_create(struct drm_device *);
407 extern void nvd0_display_destroy(struct drm_device *);
408 extern int nvd0_display_init(struct drm_device *);
409 extern void nvd0_display_fini(struct drm_device *);
410 struct nouveau_bo *nvd0_display_crtc_sema(struct drm_device *, int crtc);
411 void nvd0_display_flip_stop(struct drm_crtc *);
412 int nvd0_display_flip_next(struct drm_crtc *, struct drm_framebuffer *,
413                            struct nouveau_channel *, u32 swap_interval);
414
415
416 /* nouveau_display.c */
417 int nouveau_display_create(struct drm_device *dev);
418 void nouveau_display_destroy(struct drm_device *dev);
419 int nouveau_display_init(struct drm_device *dev);
420 void nouveau_display_fini(struct drm_device *dev);
421 int nouveau_vblank_enable(struct drm_device *dev, int crtc);
422 void nouveau_vblank_disable(struct drm_device *dev, int crtc);
423 int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
424                            struct drm_pending_vblank_event *event);
425 int nouveau_finish_page_flip(struct nouveau_channel *,
426                              struct nouveau_page_flip_state *);
427 int nouveau_display_dumb_create(struct drm_file *, struct drm_device *,
428                                 struct drm_mode_create_dumb *args);
429 int nouveau_display_dumb_map_offset(struct drm_file *, struct drm_device *,
430                                     uint32_t handle, uint64_t *offset);
431 int nouveau_display_dumb_destroy(struct drm_file *, struct drm_device *,
432                                  uint32_t handle);
433
434 #ifndef ioread32_native
435 #ifdef __BIG_ENDIAN
436 #define ioread16_native ioread16be
437 #define iowrite16_native iowrite16be
438 #define ioread32_native  ioread32be
439 #define iowrite32_native iowrite32be
440 #else /* def __BIG_ENDIAN */
441 #define ioread16_native ioread16
442 #define iowrite16_native iowrite16
443 #define ioread32_native  ioread32
444 #define iowrite32_native iowrite32
445 #endif /* def __BIG_ENDIAN else */
446 #endif /* !ioread32_native */
447
448 /* register access */
449 #define nv_rd08 _nv_rd08
450 #define nv_wr08 _nv_wr08
451 #define nv_rd32 _nv_rd32
452 #define nv_wr32 _nv_wr32
453 #define nv_mask _nv_mask
454
455 #define nv_wait(dev, reg, mask, val) \
456         nouveau_wait_eq(dev, 2000000000ULL, (reg), (mask), (val))
457 #define nv_wait_ne(dev, reg, mask, val) \
458         nouveau_wait_ne(dev, 2000000000ULL, (reg), (mask), (val))
459 #define nv_wait_cb(dev, func, data) \
460         nouveau_wait_cb(dev, 2000000000ULL, (func), (data))
461
462 /*
463  * Logging
464  * Argument d is (struct drm_device *).
465  */
466 #define NV_PRINTK(level, d, fmt, arg...) \
467         printk(level "[" DRM_NAME "] " DRIVER_NAME " %s: " fmt, \
468                                         pci_name(d->pdev), ##arg)
469 #ifndef NV_DEBUG_NOTRACE
470 #define NV_DEBUG(d, fmt, arg...) do {                                          \
471         if (drm_debug & DRM_UT_DRIVER) {                                       \
472                 NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__,             \
473                           __LINE__, ##arg);                                    \
474         }                                                                      \
475 } while (0)
476 #define NV_DEBUG_KMS(d, fmt, arg...) do {                                      \
477         if (drm_debug & DRM_UT_KMS) {                                          \
478                 NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__,             \
479                           __LINE__, ##arg);                                    \
480         }                                                                      \
481 } while (0)
482 #else
483 #define NV_DEBUG(d, fmt, arg...) do {                                          \
484         if (drm_debug & DRM_UT_DRIVER)                                         \
485                 NV_PRINTK(KERN_DEBUG, d, fmt, ##arg);                          \
486 } while (0)
487 #define NV_DEBUG_KMS(d, fmt, arg...) do {                                      \
488         if (drm_debug & DRM_UT_KMS)                                            \
489                 NV_PRINTK(KERN_DEBUG, d, fmt, ##arg);                          \
490 } while (0)
491 #endif
492 #define NV_ERROR(d, fmt, arg...) NV_PRINTK(KERN_ERR, d, fmt, ##arg)
493 #define NV_INFO(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
494 #define NV_TRACEWARN(d, fmt, arg...) NV_PRINTK(KERN_NOTICE, d, fmt, ##arg)
495 #define NV_TRACE(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
496 #define NV_WARN(d, fmt, arg...) NV_PRINTK(KERN_WARNING, d, fmt, ##arg)
497 #define NV_WARNONCE(d, fmt, arg...) do {                                       \
498         static int _warned = 0;                                                \
499         if (!_warned) {                                                        \
500                 NV_WARN(d, fmt, ##arg);                                        \
501                 _warned = 1;                                                   \
502         }                                                                      \
503 } while(0)
504
505 static inline bool
506 nv_two_heads(struct drm_device *dev)
507 {
508         struct drm_nouveau_private *dev_priv = dev->dev_private;
509         const int impl = dev->pci_device & 0x0ff0;
510
511         if (dev_priv->card_type >= NV_10 && impl != 0x0100 &&
512             impl != 0x0150 && impl != 0x01a0 && impl != 0x0200)
513                 return true;
514
515         return false;
516 }
517
518 static inline bool
519 nv_gf4_disp_arch(struct drm_device *dev)
520 {
521         return nv_two_heads(dev) && (dev->pci_device & 0x0ff0) != 0x0110;
522 }
523
524 static inline bool
525 nv_two_reg_pll(struct drm_device *dev)
526 {
527         struct drm_nouveau_private *dev_priv = dev->dev_private;
528         const int impl = dev->pci_device & 0x0ff0;
529
530         if (impl == 0x0310 || impl == 0x0340 || dev_priv->card_type >= NV_40)
531                 return true;
532         return false;
533 }
534
535 static inline bool
536 nv_match_device(struct drm_device *dev, unsigned device,
537                 unsigned sub_vendor, unsigned sub_device)
538 {
539         return dev->pdev->device == device &&
540                 dev->pdev->subsystem_vendor == sub_vendor &&
541                 dev->pdev->subsystem_device == sub_device;
542 }
543
544 static inline struct nv04_display *
545 nv04_display(struct drm_device *dev)
546 {
547         struct drm_nouveau_private *dev_priv = dev->dev_private;
548         return dev_priv->engine.display.priv;
549 }
550
551 #endif /* __NOUVEAU_DRV_H__ */