Skip to content

Commit

Permalink
nvbios: parse D bit table
Browse files Browse the repository at this point in the history
  • Loading branch information
karolherbst committed Nov 20, 2016
1 parent 9603141 commit 7f21141
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions nvbios/CMakeLists.txt
Expand Up @@ -6,6 +6,7 @@ add_library(envybios
bit.c info.c dacload.c iunk.c
i2cscript.c
dcb.c dunk.c i2c.c gpio.c extdev.c conn.c mem.c mux.c power.c
D.c
)

add_executable(nvbios nvbios.c)
Expand Down
96 changes: 96 additions & 0 deletions nvbios/D.c
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2016 Karol Herbst
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include "bios.h"

struct D_known_tables {
uint8_t offset;
uint16_t *ptr;
const char *name;
};

static int
parse_at(struct envy_bios *bios, unsigned int idx, const char **name)
{
struct envy_bios_D *d = &bios->D;
struct D_known_tables tbls[] = {
{ 0x0, &d->unk0.offset, "UNK0" },
{ 0x2, &d->unk2.offset, "UNK2 TABLE" },
};
int entries_count = (sizeof(tbls) / sizeof(struct D_known_tables));

/* check the index */
if (idx >= entries_count)
return -ENOENT;

/* check the table has the right size */
if (tbls[idx].offset + 2 > d->bit->t_len)
return -ENOENT;

if (name)
*name = tbls[idx].name;

return bios_u16(bios, d->bit->t_offset + tbls[idx].offset, tbls[idx].ptr);
}

int
envy_bios_parse_bit_D(struct envy_bios *bios, struct envy_bios_bit_entry *bit)
{
struct envy_bios_D *d = &bios->D;
unsigned int idx = 0;

d->bit = bit;

while (!parse_at(bios, idx, NULL))
idx++;

/* parse tables */

return 0;
}

void
envy_bios_print_bit_D(struct envy_bios *bios, FILE *out, unsigned mask)
{
struct envy_bios_D *d = &bios->D;
uint16_t addr;
int ret = 0, i = 0;

if (!d->bit || !(mask & ENVY_BIOS_PRINT_D))
return;

fprintf(out, "BIT table 'D' at 0x%x, version %i\n",
d->bit->offset, d->bit->version);

for (i = 0; i * 2 < d->bit->t_len; ++i) {
ret = bios_u16(bios, d->bit->t_offset + (i * 2), &addr);
if (!ret && addr) {
const char *name;
ret = parse_at(bios, i, &name);
fprintf(out, "0x%02x: 0x%x => D %s\n", i * 2, addr, name);
}
}

fprintf(out, "\n");
}
42 changes: 42 additions & 0 deletions nvbios/bios.h
Expand Up @@ -1368,6 +1368,43 @@ struct envy_bios_power {
struct envy_bios_power_unk98 unk98;
};

struct envy_bios_D_unk0_entry {
uint16_t offset;
};

struct envy_bios_D_unk0 {
uint16_t offset;
uint8_t valid;
uint8_t version;
uint8_t hlen;
uint8_t entriesnum;
uint8_t rlen;

struct envy_bios_D_unk0_entry *entries;
};

struct envy_bios_D_unk2_entry {
uint16_t offset;
};

struct envy_bios_D_unk2 {
uint16_t offset;
uint8_t valid;
uint8_t version;
uint8_t hlen;
uint8_t entriesnum;
uint8_t rlen;

struct envy_bios_D_unk2_entry *entries;
};

struct envy_bios_D {
struct envy_bios_bit_entry *bit;

struct envy_bios_D_unk0 unk0;
struct envy_bios_D_unk2 unk2;
};

struct envy_bios_block {
unsigned int start;
unsigned int len;
Expand Down Expand Up @@ -1443,6 +1480,7 @@ struct envy_bios {
struct envy_bios_mux mux;
struct envy_bios_power power;
struct envy_bios_mem mem;
struct envy_bios_D D;

struct envy_bios_block *blocks;
int blocksnum;
Expand Down Expand Up @@ -1504,6 +1542,7 @@ static inline int bios_string(struct envy_bios *bios, unsigned int offs, char *r
#define ENVY_BIOS_PRINT_PERF 0x00000400
#define ENVY_BIOS_PRINT_I2CSCRIPT 0x00000800
#define ENVY_BIOS_PRINT_MEM 0x00001000
#define ENVY_BIOS_PRINT_D 0x00002000
#define ENVY_BIOS_PRINT_HWSQ 0x00008000
#define ENVY_BIOS_PRINT_DCB 0x00010000
#define ENVY_BIOS_PRINT_GPIO 0x00020000
Expand Down Expand Up @@ -1580,6 +1619,9 @@ void envy_bios_print_mem_train_ptrn(struct envy_bios *bios, FILE *out, unsigned
void envy_bios_print_mem_type(struct envy_bios *bios, FILE *out, unsigned mask);
void envy_bios_print_mem_unk0d(struct envy_bios *bios, FILE *out, unsigned mask);

int envy_bios_parse_bit_D (struct envy_bios *, struct envy_bios_bit_entry *);
void envy_bios_print_bit_D (struct envy_bios *, FILE *out, unsigned mask);

int envy_bios_parse_dcb (struct envy_bios *bios);
void envy_bios_print_dcb (struct envy_bios *bios, FILE *out, unsigned mask);
void envy_bios_print_odcb (struct envy_bios *bios, FILE *out, unsigned mask);
Expand Down
1 change: 1 addition & 0 deletions nvbios/bit.c
Expand Up @@ -46,6 +46,7 @@ static const struct {
{ 'P', 2, envy_bios_parse_bit_P }, /* Power v2 */
{ 'M', 1, envy_bios_parse_bit_M }, /* Mem v1 */
{ 'M', 2, envy_bios_parse_bit_M }, /* Mem v2 */
{ 'D', 1, envy_bios_parse_bit_D }, /* D? */
{ 0 },
};

Expand Down
1 change: 1 addition & 0 deletions nvbios/nvbios.c
Expand Up @@ -93,6 +93,7 @@ struct {
{ "mem", ENVY_BIOS_PRINT_MEM },
{ "ram", ENVY_BIOS_PRINT_RAM },
{ "perf", ENVY_BIOS_PRINT_PERF },
{ "D", ENVY_BIOS_PRINT_D },
{ "i2cscript", ENVY_BIOS_PRINT_I2CSCRIPT },
{ "dcball", ENVY_BIOS_PRINT_DCB_ALL },
{ "dcb", ENVY_BIOS_PRINT_DCB },
Expand Down
1 change: 1 addition & 0 deletions nvbios/print.c
Expand Up @@ -397,6 +397,7 @@ void envy_bios_print (struct envy_bios *bios, FILE *out, unsigned mask) {
envy_bios_print_info(bios, stdout, mask);
envy_bios_print_bit_P(bios, stdout, mask);
envy_bios_print_bit_M(bios, stdout, mask);
envy_bios_print_bit_D(bios, stdout, mask);

envy_bios_print_dacload(bios, stdout, mask);
envy_bios_print_iunk21(bios, stdout, mask);
Expand Down

0 comments on commit 7f21141

Please sign in to comment.