drm/nouveau/bios: rework vbios shadowing
[cascardo/linux.git] / drivers / gpu / drm / nouveau / nouveau_bios.h
1 /*
2  * Copyright 2007-2008 Nouveau Project
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23
24 #ifndef __NOUVEAU_BIOS_H__
25 #define __NOUVEAU_BIOS_H__
26
27 #include "nvreg.h"
28 #include "nouveau_i2c.h"
29
30 #define DCB_MAX_NUM_ENTRIES 16
31 #define DCB_MAX_NUM_I2C_ENTRIES 16
32 #define DCB_MAX_NUM_GPIO_ENTRIES 32
33 #define DCB_MAX_NUM_CONNECTOR_ENTRIES 16
34
35 #define DCB_LOC_ON_CHIP 0
36
37 #define ROM16(x) le16_to_cpu(*(u16 *)&(x))
38 #define ROM32(x) le32_to_cpu(*(u32 *)&(x))
39 #define ROM48(x) ({ u8 *p = &(x); (u64)ROM16(p[4]) << 32 | ROM32(p[0]); })
40 #define ROM64(x) le64_to_cpu(*(u64 *)&(x))
41 #define ROMPTR(d,x) ({            \
42         struct drm_nouveau_private *dev_priv = (d)->dev_private; \
43         ROM16(x) ? &dev_priv->vbios.data[ROM16(x)] : NULL; \
44 })
45
46 struct bit_entry {
47         uint8_t  id;
48         uint8_t  version;
49         uint16_t length;
50         uint16_t offset;
51         uint8_t *data;
52 };
53
54 int bit_table(struct drm_device *, u8 id, struct bit_entry *);
55
56 enum dcb_gpio_tag {
57         DCB_GPIO_PANEL_POWER = 0x01,
58         DCB_GPIO_TVDAC0 = 0x0c,
59         DCB_GPIO_TVDAC1 = 0x2d,
60         DCB_GPIO_PWM_FAN = 0x09,
61         DCB_GPIO_FAN_SENSE = 0x3d,
62         DCB_GPIO_UNUSED = 0xff
63 };
64
65 enum dcb_connector_type {
66         DCB_CONNECTOR_VGA = 0x00,
67         DCB_CONNECTOR_TV_0 = 0x10,
68         DCB_CONNECTOR_TV_1 = 0x11,
69         DCB_CONNECTOR_TV_3 = 0x13,
70         DCB_CONNECTOR_DVI_I = 0x30,
71         DCB_CONNECTOR_DVI_D = 0x31,
72         DCB_CONNECTOR_LVDS = 0x40,
73         DCB_CONNECTOR_LVDS_SPWG = 0x41,
74         DCB_CONNECTOR_DP = 0x46,
75         DCB_CONNECTOR_eDP = 0x47,
76         DCB_CONNECTOR_HDMI_0 = 0x60,
77         DCB_CONNECTOR_HDMI_1 = 0x61,
78         DCB_CONNECTOR_DMS59_DP0 = 0x64,
79         DCB_CONNECTOR_DMS59_DP1 = 0x65,
80         DCB_CONNECTOR_NONE = 0xff
81 };
82
83 enum dcb_type {
84         OUTPUT_ANALOG = 0,
85         OUTPUT_TV = 1,
86         OUTPUT_TMDS = 2,
87         OUTPUT_LVDS = 3,
88         OUTPUT_DP = 6,
89         OUTPUT_EOL = 14, /* DCB 4.0+, appears to be end-of-list */
90         OUTPUT_UNUSED = 15,
91         OUTPUT_ANY = -1
92 };
93
94 struct dcb_entry {
95         int index;      /* may not be raw dcb index if merging has happened */
96         enum dcb_type type;
97         uint8_t i2c_index;
98         uint8_t heads;
99         uint8_t connector;
100         uint8_t bus;
101         uint8_t location;
102         uint8_t or;
103         bool duallink_possible;
104         union {
105                 struct sor_conf {
106                         int link;
107                 } sorconf;
108                 struct {
109                         int maxfreq;
110                 } crtconf;
111                 struct {
112                         struct sor_conf sor;
113                         bool use_straps_for_mode;
114                         bool use_acpi_for_edid;
115                         bool use_power_scripts;
116                 } lvdsconf;
117                 struct {
118                         bool has_component_output;
119                 } tvconf;
120                 struct {
121                         struct sor_conf sor;
122                         int link_nr;
123                         int link_bw;
124                 } dpconf;
125                 struct {
126                         struct sor_conf sor;
127                         int slave_addr;
128                 } tmdsconf;
129         };
130         bool i2c_upper_default;
131 };
132
133 struct dcb_table {
134         uint8_t version;
135         int entries;
136         struct dcb_entry entry[DCB_MAX_NUM_ENTRIES];
137 };
138
139 enum nouveau_or {
140         OUTPUT_A = (1 << 0),
141         OUTPUT_B = (1 << 1),
142         OUTPUT_C = (1 << 2)
143 };
144
145 enum LVDS_script {
146         /* Order *does* matter here */
147         LVDS_INIT = 1,
148         LVDS_RESET,
149         LVDS_BACKLIGHT_ON,
150         LVDS_BACKLIGHT_OFF,
151         LVDS_PANEL_ON,
152         LVDS_PANEL_OFF
153 };
154
155 /* these match types in pll limits table version 0x40,
156  * nouveau uses them on all chipsets internally where a
157  * specific pll needs to be referenced, but the exact
158  * register isn't known.
159  */
160 enum pll_types {
161         PLL_CORE   = 0x01,
162         PLL_SHADER = 0x02,
163         PLL_UNK03  = 0x03,
164         PLL_MEMORY = 0x04,
165         PLL_VDEC   = 0x05,
166         PLL_UNK40  = 0x40,
167         PLL_UNK41  = 0x41,
168         PLL_UNK42  = 0x42,
169         PLL_VPLL0  = 0x80,
170         PLL_VPLL1  = 0x81,
171         PLL_MAX    = 0xff
172 };
173
174 struct pll_lims {
175         u32 reg;
176
177         struct {
178                 int minfreq;
179                 int maxfreq;
180                 int min_inputfreq;
181                 int max_inputfreq;
182
183                 uint8_t min_m;
184                 uint8_t max_m;
185                 uint8_t min_n;
186                 uint8_t max_n;
187         } vco1, vco2;
188
189         uint8_t max_log2p;
190         /*
191          * for most pre nv50 cards setting a log2P of 7 (the common max_log2p
192          * value) is no different to 6 (at least for vplls) so allowing the MNP
193          * calc to use 7 causes the generated clock to be out by a factor of 2.
194          * however, max_log2p cannot be fixed-up during parsing as the
195          * unmodified max_log2p value is still needed for setting mplls, hence
196          * an additional max_usable_log2p member
197          */
198         uint8_t max_usable_log2p;
199         uint8_t log2p_bias;
200
201         uint8_t min_p;
202         uint8_t max_p;
203
204         int refclk;
205 };
206
207 struct nvbios {
208         struct drm_device *dev;
209         enum {
210                 NVBIOS_BMP,
211                 NVBIOS_BIT
212         } type;
213         uint16_t offset;
214         uint32_t length;
215         uint8_t *data;
216
217         uint8_t chip_version;
218
219         uint32_t dactestval;
220         uint32_t tvdactestval;
221         uint8_t digital_min_front_porch;
222         bool fp_no_ddc;
223
224         spinlock_t lock;
225
226         bool execute;
227
228         uint8_t major_version;
229         uint8_t feature_byte;
230         bool is_mobile;
231
232         uint32_t fmaxvco, fminvco;
233
234         bool old_style_init;
235         uint16_t init_script_tbls_ptr;
236         uint16_t extra_init_script_tbl_ptr;
237         uint16_t macro_index_tbl_ptr;
238         uint16_t macro_tbl_ptr;
239         uint16_t condition_tbl_ptr;
240         uint16_t io_condition_tbl_ptr;
241         uint16_t io_flag_condition_tbl_ptr;
242         uint16_t init_function_tbl_ptr;
243
244         uint16_t pll_limit_tbl_ptr;
245         uint16_t ram_restrict_tbl_ptr;
246         uint8_t ram_restrict_group_count;
247
248         uint16_t some_script_ptr; /* BIT I + 14 */
249         uint16_t init96_tbl_ptr; /* BIT I + 16 */
250
251         struct dcb_table dcb;
252
253         struct {
254                 int crtchead;
255         } state;
256
257         struct {
258                 struct dcb_entry *output;
259                 int crtc;
260                 uint16_t script_table_ptr;
261         } display;
262
263         struct {
264                 uint16_t fptablepointer;        /* also used by tmds */
265                 uint16_t fpxlatetableptr;
266                 int xlatwidth;
267                 uint16_t lvdsmanufacturerpointer;
268                 uint16_t fpxlatemanufacturertableptr;
269                 uint16_t mode_ptr;
270                 uint16_t xlated_entry;
271                 bool power_off_for_reset;
272                 bool reset_after_pclk_change;
273                 bool dual_link;
274                 bool link_c_increment;
275                 bool if_is_24bit;
276                 int duallink_transition_clk;
277                 uint8_t strapless_is_24bit;
278                 uint8_t *edid;
279
280                 /* will need resetting after suspend */
281                 int last_script_invoc;
282                 bool lvds_init_run;
283         } fp;
284
285         struct {
286                 uint16_t output0_script_ptr;
287                 uint16_t output1_script_ptr;
288         } tmds;
289
290         struct {
291                 uint16_t mem_init_tbl_ptr;
292                 uint16_t sdr_seq_tbl_ptr;
293                 uint16_t ddr_seq_tbl_ptr;
294
295                 struct {
296                         uint8_t crt, tv, panel;
297                 } i2c_indices;
298
299                 uint16_t lvds_single_a_script_ptr;
300         } legacy;
301 };
302
303 void *dcb_table(struct drm_device *);
304 void *dcb_outp(struct drm_device *, u8 idx);
305 int dcb_outp_foreach(struct drm_device *, void *data,
306                      int (*)(struct drm_device *, void *, int idx, u8 *outp));
307 u8 *dcb_conntab(struct drm_device *);
308 u8 *dcb_conn(struct drm_device *, u8 idx);
309
310 #endif