intel_extreme: fixed warnings.

* And also most coding style violations.
This commit is contained in:
Axel Dörfler 2014-06-04 00:58:54 +02:00
parent 27843c6ffd
commit 5336a8d11e

View File

@ -4,14 +4,16 @@
*/ */
#include <KernelExport.h>
#include "intel_extreme.h"
#include <string.h> #include <string.h>
#include <KernelExport.h>
#define TRACE_BIOS 1 #include "intel_extreme.h"
#define TRACE_BIOS
#ifdef TRACE_BIOS #ifdef TRACE_BIOS
# define TRACE(x) dprintf x # define TRACE(x) dprintf x
#else #else
# define TRACE(x) ; # define TRACE(x) ;
#endif #endif
@ -98,19 +100,20 @@ struct lvds_bdb2_lfp_info {
static struct vbios { static struct vbios {
area_id area; area_id area;
uint8* memory; uint8* memory;
display_mode *shared_info; display_mode* shared_info;
struct { struct {
uint16 hsync_start; uint16 hsync_start;
uint16 hsync_end; uint16 hsync_end;
uint16 hsync_total; uint16 hsync_total;
uint16 vsync_start; uint16 vsync_start;
uint16 vsync_end; uint16 vsync_end;
uint16 vsync_total; uint16 vsync_total;
} timings_common; } timings_common;
uint16_t ReadWord(off_t address) { uint16_t ReadWord(off_t address)
{
return memory[address] | memory[address + 1] << 8; return memory[address] | memory[address + 1] << 8;
} }
} vbios; } vbios;
@ -118,45 +121,40 @@ static struct vbios {
/* TODO: move code to accelerant, if possible */ /* TODO: move code to accelerant, if possible */
/* this is reimplementation, Haiku uses BIOS call and gets most current panel /*! This is reimplementation, Haiku uses BIOS call and gets most current panel
info, we're, otherwise, digging in VBIOS memory and parsing VBT tables to get info, we're, otherwise, digging in VBIOS memory and parsing VBT tables to
native panel timings. This will allow to get non-updated, PROM-programmed get native panel timings. This will allow to get non-updated,
timings info when compensation mode is off on your machine */ PROM-programmed timings info when compensation mode is off on your machine.
*/
static bool static bool
get_bios(void) get_bios(void)
{ {
static const uint64_t kVBIOSAddress = 0xc0000; static const uint64_t kVBIOSAddress = 0xc0000;
static const size_t kVBIOSSize = 64 * 1024; static const int kVBIOSSize = 64 * 1024;
// FIXME: is this the same for all cards? // FIXME: is this the same for all cards?
int vbt_offset;
struct vbt_header *vbt;
/* !!!DANGER!!!: mapping of BIOS using legacy location for now, /* !!!DANGER!!!: mapping of BIOS using legacy location for now,
hence, if panel mode will be set using info from VBT, it will hence, if panel mode will be set using info from VBT, it will
be taken from primary card's VBIOS */ be taken from primary card's VBIOS */
vbios.area = map_physical_memory("VBIOS mapping", vbios.area = map_physical_memory("VBIOS mapping", kVBIOSAddress,
kVBIOSAddress, kVBIOSSize, B_ANY_KERNEL_ADDRESS, kVBIOSSize, B_ANY_KERNEL_ADDRESS, B_READ_AREA, (void**)&vbios.memory);
B_READ_AREA, (void**)&(vbios.memory));
if (vbios.area < 0) if (vbios.area < 0)
return false; return false;
TRACE((DEVICE_NAME ": mapping VBIOS: 0x%x -> %p\n", TRACE((DEVICE_NAME ": mapping VBIOS: 0x%" B_PRIx64 " -> %p\n",
kVBIOSAddress, vbios.memory)); kVBIOSAddress, vbios.memory));
vbt_offset = vbios.ReadWord(kVbtPointer); int vbtOffset = vbios.ReadWord(kVbtPointer);
if (vbt_offset >= kVBIOSSize) { if (vbtOffset >= kVBIOSSize) {
TRACE((DEVICE_NAME": bad VBT offset : 0x%x\n", TRACE((DEVICE_NAME": bad VBT offset : 0x%x\n", vbtOffset));
vbt_offset));
delete_area(vbios.area); delete_area(vbios.area);
return false; return false;
} }
vbt = (struct vbt_header *)(vbios.memory + vbt_offset); struct vbt_header* vbt = (struct vbt_header*)(vbios.memory + vbtOffset);
if (memcmp(vbt->signature, "$VBT", 4) != 0) { if (memcmp(vbt->signature, "$VBT", 4) != 0) {
TRACE((DEVICE_NAME": bad VBT signature: %20s\n", TRACE((DEVICE_NAME": bad VBT signature: %20s\n", vbt->signature));
vbt->signature));
delete_area(vbios.area); delete_area(vbios.area);
return false; return false;
} }
@ -172,30 +170,25 @@ feed_shared_info(uint8* data)
/* handle bogus h/vtotal values, if got such */ /* handle bogus h/vtotal values, if got such */
if (vbios.timings_common.hsync_end > vbios.timings_common.hsync_total) { if (vbios.timings_common.hsync_end > vbios.timings_common.hsync_total) {
vbios.timings_common.hsync_total vbios.timings_common.hsync_total = vbios.timings_common.hsync_end + 1;
= vbios.timings_common.hsync_end + 1;
bogus = true; bogus = true;
TRACE((DEVICE_NAME": got bogus htotal. Fixing\n")); TRACE((DEVICE_NAME": got bogus htotal. Fixing\n"));
} }
if (vbios.timings_common.vsync_end > vbios.timings_common.vsync_total) { if (vbios.timings_common.vsync_end > vbios.timings_common.vsync_total) {
vbios.timings_common.vsync_total vbios.timings_common.vsync_total = vbios.timings_common.vsync_end + 1;
= vbios.timings_common.vsync_end + 1;
bogus = true; bogus = true;
TRACE((DEVICE_NAME": got bogus vtotal. Fixing\n")); TRACE((DEVICE_NAME": got bogus vtotal. Fixing\n"));
} }
/* */
if (bogus) { if (bogus) {
TRACE((DEVICE_NAME": adjusted LFP modeline: x%d Hz,\t" TRACE((DEVICE_NAME": adjusted LFP modeline: x%d Hz,\t"
"%d %d %d %d %d %d %d %d\n", "%d %d %d %d %d %d %d %d\n",
_PIXEL_CLOCK(data) / ((_H_ACTIVE(data) + _H_BLANK(data)) _PIXEL_CLOCK(data) / ((_H_ACTIVE(data) + _H_BLANK(data))
* (_V_ACTIVE(data) + _V_BLANK(data))), * (_V_ACTIVE(data) + _V_BLANK(data))),
_H_ACTIVE(data), _H_ACTIVE(data), vbios.timings_common.hsync_start,
vbios.timings_common.hsync_start, vbios.timings_common.hsync_end, vbios.timings_common.hsync_total,
vbios.timings_common.hsync_end, _V_ACTIVE(data), vbios.timings_common.vsync_start,
vbios.timings_common.hsync_total, vbios.timings_common.vsync_end, vbios.timings_common.vsync_total));
_V_ACTIVE(data), vbios.timings_common.vsync_start,
vbios.timings_common.vsync_end,
vbios.timings_common.vsync_total));
} }
/* TODO: add retrieved info to edid info struct, not fixed mode struct */ /* TODO: add retrieved info to edid info struct, not fixed mode struct */
@ -220,60 +213,58 @@ feed_shared_info(uint8* data)
bool bool
get_lvds_mode_from_bios(display_mode *shared_info) get_lvds_mode_from_bios(display_mode* sharedInfo)
{ {
struct vbt_header *vbt;
struct bdb_header *bdb;
int vbt_offset, bdb_offset, bdb_block_offset, block_size;
int panel_type = -1;
if (!get_bios()) if (!get_bios())
return false; return false;
vbt_offset = vbios.ReadWord(kVbtPointer); int vbtOffset = vbios.ReadWord(kVbtPointer);
vbt = (struct vbt_header *)(vbios.memory + vbt_offset); struct vbt_header* vbt = (struct vbt_header*)(vbios.memory + vbtOffset);
bdb_offset = vbt_offset + vbt->bdb_offset; int bdbOffset = vbtOffset + vbt->bdb_offset;
bdb = (struct bdb_header *)(vbios.memory + bdb_offset); struct bdb_header* bdb = (struct bdb_header*)(vbios.memory + bdbOffset);
if (memcmp(bdb->signature, "BIOS_DATA_BLOCK ", 16) != 0) { if (memcmp(bdb->signature, "BIOS_DATA_BLOCK ", 16) != 0) {
TRACE((DEVICE_NAME": bad BDB signature\n")); TRACE((DEVICE_NAME": bad BDB signature\n"));
delete_area(vbios.area); delete_area(vbios.area);
} }
TRACE((DEVICE_NAME": parsing BDB blocks\n")); TRACE((DEVICE_NAME": parsing BDB blocks\n"));
for (bdb_block_offset = bdb->header_size; bdb_block_offset < bdb->bdb_size; int blockSize;
bdb_block_offset += block_size) { int panelType = -1;
int start = bdb_offset + bdb_block_offset;
for (int bdbBlockOffset = bdb->header_size; bdbBlockOffset < bdb->bdb_size;
bdbBlockOffset += blockSize) {
int start = bdbOffset + bdbBlockOffset;
int id = vbios.memory[start]; int id = vbios.memory[start];
block_size = vbios.ReadWord(start + 1) + 3; blockSize = vbios.ReadWord(start + 1) + 3;
// TRACE((DEVICE_NAME": found BDB block type %d\n", id)); // TRACE((DEVICE_NAME": found BDB block type %d\n", id));
switch (id) { switch (id) {
case 40: // FIXME magic numbers case 40: // FIXME magic numbers
{ {
struct lvds_bdb1 *lvds1; struct lvds_bdb1 *lvds1;
lvds1 = (struct lvds_bdb1 *)(vbios.memory + start); lvds1 = (struct lvds_bdb1 *)(vbios.memory + start);
panel_type = lvds1->panel_type; panelType = lvds1->panel_type;
break; break;
} }
case 41: case 41:
{ {
if (panel_type == -1) if (panelType == -1)
break; break;
struct lvds_bdb2 *lvds2; struct lvds_bdb2 *lvds2;
struct lvds_bdb2_lfp_info *lvds2_lfp_info; struct lvds_bdb2_lfp_info *lvds2_lfp_info;
lvds2 = (struct lvds_bdb2 *)(vbios.memory + start); lvds2 = (struct lvds_bdb2 *)(vbios.memory + start);
lvds2_lfp_info = (struct lvds_bdb2_lfp_info *) lvds2_lfp_info = (struct lvds_bdb2_lfp_info *)
(vbios.memory + bdb_offset (vbios.memory + bdbOffset
+ lvds2->panels[panel_type].lfp_info_offset); + lvds2->panels[panelType].lfp_info_offset);
/* found bad one terminator */ /* found bad one terminator */
if (lvds2_lfp_info->terminator != 0xffff) { if (lvds2_lfp_info->terminator != 0xffff) {
delete_area(vbios.area); delete_area(vbios.area);
return false; return false;
} }
uint8_t* timing_data = vbios.memory + bdb_offset uint8_t* timing_data = vbios.memory + bdbOffset
+ lvds2->panels[panel_type].lfp_edid_dtd_offset; + lvds2->panels[panelType].lfp_edid_dtd_offset;
TRACE((DEVICE_NAME": found LFP of size %d x %d " TRACE((DEVICE_NAME": found LFP of size %d x %d "
"in BIOS VBT tables\n", "in BIOS VBT tables\n",
lvds2_lfp_info->x_res, lvds2_lfp_info->y_res)); lvds2_lfp_info->x_res, lvds2_lfp_info->y_res));
@ -293,7 +284,7 @@ get_lvds_mode_from_bios(display_mode *shared_info)
vbios.timings_common.vsync_total = _V_ACTIVE(timing_data) vbios.timings_common.vsync_total = _V_ACTIVE(timing_data)
+ _V_BLANK(timing_data); + _V_BLANK(timing_data);
vbios.shared_info = shared_info; vbios.shared_info = sharedInfo;
return feed_shared_info(timing_data); return feed_shared_info(timing_data);
} }
} }