diff options
author | Eric Anholt <eric@anholt.net> | 2006-09-22 09:51:45 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2006-09-22 10:52:04 -0700 |
commit | 965609f6fa63e28e5a28128f5bc44f8c4d7b9f68 (patch) | |
tree | e298d751dba2f63dcf1b45d333e01a10d6ef4c85 /src | |
parent | c52242c22779a51aa12b18a7a589080ce44c8484 (diff) |
Restructure i830_bios.c so we don't leak a copy of the BIOS per generation.
Diffstat (limited to 'src')
-rw-r--r-- | src/i830.h | 2 | ||||
-rw-r--r-- | src/i830_bios.c | 76 |
2 files changed, 39 insertions, 39 deletions
@@ -442,8 +442,6 @@ typedef struct _I830Rec { Bool panel_wants_dither; - unsigned char *VBIOS; - CARD32 saveDSPACNTR; CARD32 saveDSPBCNTR; CARD32 savePIPEACONF; diff --git a/src/i830_bios.c b/src/i830_bios.c index 14e354ed..07dd67d4 100644 --- a/src/i830_bios.c +++ b/src/i830_bios.c @@ -38,21 +38,20 @@ #include "i830_bios.h" #include "edid.h" -#define INTEL_BIOS_8(_addr) (pI830->VBIOS[_addr]) -#define INTEL_BIOS_16(_addr) (pI830->VBIOS[_addr] | \ - (pI830->VBIOS[_addr + 1] << 8)) -#define INTEL_BIOS_32(_addr) (pI830->VBIOS[_addr] | \ - (pI830->VBIOS[_addr + 1] << 8) \ - (pI830->VBIOS[_addr + 2] << 16) \ - (pI830->VBIOS[_addr + 3] << 24)) +#define INTEL_BIOS_8(_addr) (bios[_addr]) +#define INTEL_BIOS_16(_addr) (bios[_addr] | \ + (bios[_addr + 1] << 8)) +#define INTEL_BIOS_32(_addr) (bios[_addr] | \ + (bios[_addr + 1] << 8) \ + (bios[_addr + 2] << 16) \ + (bios[_addr + 3] << 24)) /* XXX */ #define INTEL_VBIOS_SIZE (64 * 1024) static void -i830DumpBIOSToFile(ScrnInfoPtr pScrn) +i830DumpBIOSToFile(ScrnInfoPtr pScrn, unsigned char *bios) { - I830Ptr pI830 = I830PTR(pScrn); const char *filename = "/tmp/xf86-video-intel-VBIOS"; FILE *f; @@ -61,7 +60,7 @@ i830DumpBIOSToFile(ScrnInfoPtr pScrn) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Couldn't open %s\n", filename); return; } - if (fwrite(pI830->VBIOS, INTEL_VBIOS_SIZE, 1, f) != 1) { + if (fwrite(bios, INTEL_VBIOS_SIZE, 1, f) != 1) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Couldn't write BIOS data\n"); } @@ -78,48 +77,46 @@ i830DumpBIOSToFile(ScrnInfoPtr pScrn) * feed an updated VBT back through that, compared to what we'll fetch using * this method of groping around in the BIOS data. */ -static Bool +static unsigned char * i830GetBIOS(ScrnInfoPtr pScrn) { I830Ptr pI830 = I830PTR(pScrn); struct vbt_header *vbt; int vbt_off; + unsigned char *bios; - if (pI830->VBIOS != NULL) - return TRUE; - - pI830->VBIOS = xalloc(INTEL_VBIOS_SIZE); - if (pI830->VBIOS == NULL) - return FALSE; + bios = xalloc(INTEL_VBIOS_SIZE); + if (bios == NULL) + return NULL; if (pI830->pVbe != NULL) { - memcpy(pI830->VBIOS, xf86int10Addr(pI830->pVbe->pInt10, + memcpy(bios, xf86int10Addr(pI830->pVbe->pInt10, pI830->pVbe->pInt10->BIOSseg << 4), INTEL_VBIOS_SIZE); } else { - xf86ReadPciBIOS(0, pI830->PciTag, 0, pI830->VBIOS, INTEL_VBIOS_SIZE); + xf86ReadPciBIOS(0, pI830->PciTag, 0, bios, INTEL_VBIOS_SIZE); } if (0) - i830DumpBIOSToFile(pScrn); + i830DumpBIOSToFile(pScrn, bios); vbt_off = INTEL_BIOS_16(0x1a); if (vbt_off >= INTEL_VBIOS_SIZE) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Bad VBT offset: 0x%x\n", vbt_off); - xfree(pI830->VBIOS); - return FALSE; + xfree(bios); + return NULL; } - vbt = (struct vbt_header *)(pI830->VBIOS + vbt_off); + vbt = (struct vbt_header *)(bios + vbt_off); if (memcmp(vbt->signature, "$VBT", 4) != 0) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Bad VBT signature\n"); - xfree(pI830->VBIOS); - return FALSE; + xfree(bios); + return NULL; } - return TRUE; + return bios; } Bool @@ -130,18 +127,22 @@ i830GetLVDSInfoFromBIOS(ScrnInfoPtr pScrn) struct bdb_header *bdb; int vbt_off, bdb_off, bdb_block_off, block_size; int panel_type = -1; + unsigned char *bios; Bool found_panel_info = FALSE; - if (!i830GetBIOS(pScrn)) + bios = i830GetBIOS(pScrn); + + if (bios == NULL) return FALSE; vbt_off = INTEL_BIOS_16(0x1a); - vbt = (struct vbt_header *)(pI830->VBIOS + vbt_off); + vbt = (struct vbt_header *)(bios + vbt_off); bdb_off = vbt_off + vbt->bdb_offset; - bdb = (struct bdb_header *)(pI830->VBIOS + bdb_off); + bdb = (struct bdb_header *)(bios + bdb_off); if (memcmp(bdb->signature, "BIOS_DATA_BLOCK ", 16) != 0) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Bad BDB signature\n"); + xfree(bios); return FALSE; } @@ -161,7 +162,7 @@ i830GetLVDSInfoFromBIOS(ScrnInfoPtr pScrn) xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Found BDB block type %d\n", id); switch (id) { case 40: - lvds1 = (struct lvds_bdb_1 *)(pI830->VBIOS + start); + lvds1 = (struct lvds_bdb_1 *)(bios + start); panel_type = lvds1->panel_type; if (lvds1->caps & LVDS_CAP_DITHER) pI830->panel_wants_dither = TRUE; @@ -170,23 +171,23 @@ i830GetLVDSInfoFromBIOS(ScrnInfoPtr pScrn) if (panel_type == -1) break; - lvds2 = (struct lvds_bdb_2 *)(pI830->VBIOS + start); - fpparam = (struct lvds_bdb_2_fp_params *)(pI830->VBIOS + + lvds2 = (struct lvds_bdb_2 *)(bios + start); + fpparam = (struct lvds_bdb_2_fp_params *)(bios + bdb_off + lvds2->panels[panel_type].fp_params_offset); - fptiming = (struct lvds_bdb_2_fp_edid_dtd *)(pI830->VBIOS + + fptiming = (struct lvds_bdb_2_fp_edid_dtd *)(bios + bdb_off + lvds2->panels[panel_type].fp_edid_dtd_offset); - timing_ptr = pI830->VBIOS + bdb_off + + timing_ptr = bios + bdb_off + lvds2->panels[panel_type].fp_edid_dtd_offset; if (fpparam->terminator != 0xffff) { /* Apparently the offsets are wrong for some BIOSes, so we * try the other offsets if we find a bad terminator. */ - fpparam = (struct lvds_bdb_2_fp_params *)(pI830->VBIOS + + fpparam = (struct lvds_bdb_2_fp_params *)(bios + bdb_off + lvds2->panels[panel_type].fp_params_offset + 8); - fptiming = (struct lvds_bdb_2_fp_edid_dtd *)(pI830->VBIOS + + fptiming = (struct lvds_bdb_2_fp_edid_dtd *)(bios + bdb_off + lvds2->panels[panel_type].fp_edid_dtd_offset + 8); - timing_ptr = pI830->VBIOS + bdb_off + + timing_ptr = bios + bdb_off + lvds2->panels[panel_type].fp_edid_dtd_offset + 8; if (fpparam->terminator != 0xffff) @@ -218,5 +219,6 @@ i830GetLVDSInfoFromBIOS(ScrnInfoPtr pScrn) } } + xfree(bios); return found_panel_info; } |