2 * Copyright 2012-2014, Artem Falcon <lomka@gero.in>
3 * Distributed under the terms of the MIT License.
9 #include <KernelExport.h>
11 #include "intel_extreme.h"
16 # define TRACE(x) dprintf x
22 static const off_t kVbtPointer
= 0x1A;
34 } __attribute__((packed
));
42 } __attribute__((packed
));
45 // FIXME the struct definition for the bdb_header is not complete, so we rely
46 // on direct access with hardcoded offsets to get the timings out of it.
47 #define _PIXEL_CLOCK(x) (x[0] + (x[1] << 8)) * 10000
48 #define _H_ACTIVE(x) (x[2] + ((x[4] & 0xF0) << 4))
49 #define _H_BLANK(x) (x[3] + ((x[4] & 0x0F) << 8))
50 #define _H_SYNC_OFF(x) (x[8] + ((x[11] & 0xC0) << 2))
51 #define _H_SYNC_WIDTH(x) (x[9] + ((x[11] & 0x30) << 4))
52 #define _V_ACTIVE(x) (x[5] + ((x[7] & 0xF0) << 4))
53 #define _V_BLANK(x) (x[6] + ((x[7] & 0x0F) << 8))
54 #define _V_SYNC_OFF(x) ((x[10] >> 4) + ((x[11] & 0x0C) << 2))
55 #define _V_SYNC_WIDTH(x) ((x[10] & 0x0F) + ((x[11] & 0x03) << 4))
64 } __attribute__((packed
));
67 struct lvds_bdb2_entry
{
68 uint16 lfp_info_offset
;
70 uint16 lfp_edid_dtd_offset
;
71 uint8 lfp_edid_dtd_size
;
72 uint16 lfp_edid_pid_offset
;
73 uint8 lfp_edid_pid_size
;
74 } __attribute__((packed
));
80 uint8 table_size
; /* unapproved */
81 struct lvds_bdb2_entry panels
[16];
82 } __attribute__((packed
));
85 struct lvds_bdb2_lfp_info
{
93 uint32 pp_off_reg_val
;
95 uint32 pp_cycle_reg_val
;
99 } __attribute__((packed
));
102 static struct vbios
{
105 display_mode
* shared_info
;
115 uint16_t ReadWord(off_t address
)
117 return memory
[address
] | memory
[address
+ 1] << 8;
122 /* TODO: move code to accelerant, if possible */
124 /*! This is reimplementation, Haiku uses BIOS call and gets most current panel
125 info, we're, otherwise, digging in VBIOS memory and parsing VBT tables to
126 get native panel timings. This will allow to get non-updated,
127 PROM-programmed timings info when compensation mode is off on your machine.
132 static const uint64_t kVBIOSAddress
= 0xc0000;
133 static const int kVBIOSSize
= 64 * 1024;
134 // FIXME: is this the same for all cards?
136 /* !!!DANGER!!!: mapping of BIOS using legacy location for now,
137 hence, if panel mode will be set using info from VBT, it will
138 be taken from primary card's VBIOS */
139 vbios
.area
= map_physical_memory("VBIOS mapping", kVBIOSAddress
,
140 kVBIOSSize
, B_ANY_KERNEL_ADDRESS
, B_READ_AREA
, (void**)&vbios
.memory
);
145 TRACE((DEVICE_NAME
": mapping VBIOS: 0x%" B_PRIx64
" -> %p\n",
146 kVBIOSAddress
, vbios
.memory
));
148 int vbtOffset
= vbios
.ReadWord(kVbtPointer
);
149 if (vbtOffset
>= kVBIOSSize
) {
150 TRACE((DEVICE_NAME
": bad VBT offset : 0x%x\n", vbtOffset
));
151 delete_area(vbios
.area
);
155 struct vbt_header
* vbt
= (struct vbt_header
*)(vbios
.memory
+ vbtOffset
);
156 if (memcmp(vbt
->signature
, "$VBT", 4) != 0) {
157 TRACE((DEVICE_NAME
": bad VBT signature: %20s\n", vbt
->signature
));
158 delete_area(vbios
.area
);
167 feed_shared_info(uint8
* data
)
171 /* handle bogus h/vtotal values, if got such */
172 if (vbios
.timings_common
.hsync_end
> vbios
.timings_common
.hsync_total
) {
173 vbios
.timings_common
.hsync_total
= vbios
.timings_common
.hsync_end
+ 1;
175 TRACE((DEVICE_NAME
": got bogus htotal. Fixing\n"));
177 if (vbios
.timings_common
.vsync_end
> vbios
.timings_common
.vsync_total
) {
178 vbios
.timings_common
.vsync_total
= vbios
.timings_common
.vsync_end
+ 1;
180 TRACE((DEVICE_NAME
": got bogus vtotal. Fixing\n"));
184 TRACE((DEVICE_NAME
": adjusted LFP modeline: x%d Hz,\t"
185 "%d %d %d %d %d %d %d %d\n",
186 _PIXEL_CLOCK(data
) / ((_H_ACTIVE(data
) + _H_BLANK(data
))
187 * (_V_ACTIVE(data
) + _V_BLANK(data
))),
188 _H_ACTIVE(data
), vbios
.timings_common
.hsync_start
,
189 vbios
.timings_common
.hsync_end
, vbios
.timings_common
.hsync_total
,
190 _V_ACTIVE(data
), vbios
.timings_common
.vsync_start
,
191 vbios
.timings_common
.vsync_end
, vbios
.timings_common
.vsync_total
));
194 /* TODO: add retrieved info to edid info struct, not fixed mode struct */
196 /* struct display_timing is not packed, so we have to set elements
198 vbios
.shared_info
->timing
.pixel_clock
= _PIXEL_CLOCK(data
) / 1000;
199 vbios
.shared_info
->timing
.h_display
= vbios
.shared_info
->virtual_width
201 vbios
.shared_info
->timing
.h_sync_start
= vbios
.timings_common
.hsync_start
;
202 vbios
.shared_info
->timing
.h_sync_end
= vbios
.timings_common
.hsync_end
;
203 vbios
.shared_info
->timing
.h_total
= vbios
.timings_common
.hsync_total
;
204 vbios
.shared_info
->timing
.v_display
= vbios
.shared_info
->virtual_height
206 vbios
.shared_info
->timing
.v_sync_start
= vbios
.timings_common
.vsync_start
;
207 vbios
.shared_info
->timing
.v_sync_end
= vbios
.timings_common
.vsync_end
;
208 vbios
.shared_info
->timing
.v_total
= vbios
.timings_common
.vsync_total
;
210 delete_area(vbios
.area
);
216 get_lvds_mode_from_bios(display_mode
* sharedInfo
)
221 int vbtOffset
= vbios
.ReadWord(kVbtPointer
);
222 struct vbt_header
* vbt
= (struct vbt_header
*)(vbios
.memory
+ vbtOffset
);
223 int bdbOffset
= vbtOffset
+ vbt
->bdb_offset
;
225 struct bdb_header
* bdb
= (struct bdb_header
*)(vbios
.memory
+ bdbOffset
);
226 if (memcmp(bdb
->signature
, "BIOS_DATA_BLOCK ", 16) != 0) {
227 TRACE((DEVICE_NAME
": bad BDB signature\n"));
228 delete_area(vbios
.area
);
231 TRACE((DEVICE_NAME
": parsing BDB blocks\n"));
235 for (int bdbBlockOffset
= bdb
->header_size
; bdbBlockOffset
< bdb
->bdb_size
;
236 bdbBlockOffset
+= blockSize
) {
237 int start
= bdbOffset
+ bdbBlockOffset
;
239 int id
= vbios
.memory
[start
];
240 blockSize
= vbios
.ReadWord(start
+ 1) + 3;
241 // TRACE((DEVICE_NAME": found BDB block type %d\n", id));
243 case 40: // FIXME magic numbers
245 struct lvds_bdb1
*lvds1
;
246 lvds1
= (struct lvds_bdb1
*)(vbios
.memory
+ start
);
247 panelType
= lvds1
->panel_type
;
254 struct lvds_bdb2
*lvds2
;
255 struct lvds_bdb2_lfp_info
*lvds2_lfp_info
;
257 lvds2
= (struct lvds_bdb2
*)(vbios
.memory
+ start
);
258 lvds2_lfp_info
= (struct lvds_bdb2_lfp_info
*)
259 (vbios
.memory
+ bdbOffset
260 + lvds2
->panels
[panelType
].lfp_info_offset
);
261 /* found bad one terminator */
262 if (lvds2_lfp_info
->terminator
!= 0xffff) {
263 delete_area(vbios
.area
);
266 uint8_t* timing_data
= vbios
.memory
+ bdbOffset
267 + lvds2
->panels
[panelType
].lfp_edid_dtd_offset
;
268 TRACE((DEVICE_NAME
": found LFP of size %d x %d "
269 "in BIOS VBT tables\n",
270 lvds2_lfp_info
->x_res
, lvds2_lfp_info
->y_res
));
272 vbios
.timings_common
.hsync_start
= _H_ACTIVE(timing_data
)
273 + _H_SYNC_OFF(timing_data
);
274 vbios
.timings_common
.hsync_end
275 = vbios
.timings_common
.hsync_start
276 + _H_SYNC_WIDTH(timing_data
);
277 vbios
.timings_common
.hsync_total
= _H_ACTIVE(timing_data
)
278 + _H_BLANK(timing_data
);
279 vbios
.timings_common
.vsync_start
= _V_ACTIVE(timing_data
)
280 + _V_SYNC_OFF(timing_data
);
281 vbios
.timings_common
.vsync_end
282 = vbios
.timings_common
.vsync_start
283 + _V_SYNC_WIDTH(timing_data
);
284 vbios
.timings_common
.vsync_total
= _V_ACTIVE(timing_data
)
285 + _V_BLANK(timing_data
);
287 vbios
.shared_info
= sharedInfo
;
288 return feed_shared_info(timing_data
);
293 delete_area(vbios
.area
);