Skip to content

Commit

Permalink
nva: Use the common pmc_id parsing function.
Browse files Browse the repository at this point in the history
  • Loading branch information
mwkmwkmwk committed Jan 9, 2014
1 parent de57843 commit c39ccbb
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 146 deletions.
4 changes: 2 additions & 2 deletions hwtest/hwtest.c
Expand Up @@ -79,8 +79,8 @@ int main(int argc, char **argv) {
fprintf (stderr, "No cards found.\n");
return 1;
}
ctx->chipset = nva_cards[ctx->cnum].chipset;
ctx->card_type = nva_cards[ctx->cnum].card_type;
ctx->chipset = nva_cards[ctx->cnum].chipset.chipset;
ctx->card_type = nva_cards[ctx->cnum].chipset.card_type;
if (pci_device_has_kernel_driver(nva_cards[ctx->cnum].pci)) {
if (force) {
fprintf(stderr, "WARNING: Kernel driver in use.\n");
Expand Down
12 changes: 6 additions & 6 deletions hwtest/nv10_tile.c
Expand Up @@ -351,24 +351,24 @@ static int test_comp_size(struct hwtest_ctx *ctx) {
}

static uint32_t comp_seek(int cnum, int part, int addr) {
if (nva_cards[cnum].chipset == 0x20) {
if (nva_cards[cnum].chipset.chipset == 0x20) {
nva_wr32(cnum, 0x1000f0, 0x1300000 |
(part << 16) | (addr & 0x1fc0));
return 0x100100 + (addr & 0x3c);
} else if (nva_cards[cnum].chipset < 0x30) {
} else if (nva_cards[cnum].chipset.chipset < 0x30) {
nva_wr32(cnum, 0x1000f0, 0x2380000 |
((addr << 6) & 0x40000) |
(part << 16) | (addr & 0xfc0));
return 0x100100 + (addr & 0x3c);
} else if (nva_cards[cnum].chipset < 0x35) {
} else if (nva_cards[cnum].chipset.chipset < 0x35) {
nva_wr32(cnum, 0x1000f0, 0x2380000 |
(part << 16) | (addr & 0x7fc0));
return 0x100100 + (addr & 0x3c);
} else if (nva_cards[cnum].chipset < 0x36) {
} else if (nva_cards[cnum].chipset.chipset < 0x36) {
nva_wr32(cnum, 0x1000f0, 0x2380000 | (addr & 4) << 16 |
(part << 16) | (addr >> 1 & 0x7fc0));
return 0x100100 + (addr >> 1 & 0x3c);
} else if (nva_cards[cnum].chipset < 0x40) {
} else if (nva_cards[cnum].chipset.chipset < 0x40) {
nva_wr32(cnum, 0x1000f0, 0x2380000 | (addr & 0xc) << 15 |
(part << 16) | (addr >> 2 & 0x7fc0));
return 0x100100 + (addr >> 2 & 0x3c);
Expand Down Expand Up @@ -396,7 +396,7 @@ void comp_wr32(int cnum, int part, int addr, uint32_t v) {
void clear_comp(int cnum) {
uint32_t size = (nva_rd32(cnum, 0x100320) + 1) / 8;
int i, j;
for (i = 0; i < get_maxparts(nva_cards[cnum].chipset); i++) {
for (i = 0; i < get_maxparts(nva_cards[cnum].chipset.chipset); i++) {
for (j = 0; j < size; j += 0x4)
comp_wr32(cnum, i, j, 0);
}
Expand Down
12 changes: 6 additions & 6 deletions hwtest/vram.c
Expand Up @@ -26,11 +26,11 @@
#include "nva.h"

uint32_t vram_rd32(int card, uint64_t addr) {
if (nva_cards[card].card_type < 3) {
if (nva_cards[card].chipset.card_type < 3) {
return nva_rd32(card, 0x1000000 + addr);
} else if (nva_cards[card].card_type < 0x30) {
} else if (nva_cards[card].chipset.card_type < 0x30) {
return nva_grd32(nva_cards[card].bar1, addr);
} else if (nva_cards[card].card_type < 0x50) {
} else if (nva_cards[card].chipset.card_type < 0x50) {
nva_wr32(card, 0x1570, addr);
return nva_rd32(card, 0x1574);
} else {
Expand All @@ -43,11 +43,11 @@ uint32_t vram_rd32(int card, uint64_t addr) {
}

void vram_wr32(int card, uint64_t addr, uint32_t val) {
if (nva_cards[card].card_type < 3) {
if (nva_cards[card].chipset.card_type < 3) {
nva_wr32(card, 0x1000000 + addr, val);
} else if (nva_cards[card].card_type < 0x30) {
} else if (nva_cards[card].chipset.card_type < 0x30) {
nva_gwr32(nva_cards[card].bar1, addr, val);
} else if (nva_cards[card].card_type < 0x50) {
} else if (nva_cards[card].chipset.card_type < 0x50) {
nva_wr32(card, 0x1570, addr);
nva_wr32(card, 0x1574, val);
} else {
Expand Down
6 changes: 2 additions & 4 deletions include/nva.h
Expand Up @@ -26,13 +26,11 @@
#define NVA_H
#include <stdint.h>
#include <stddef.h>
#include "nvhw.h"

struct nva_card {
struct pci_device *pci;
uint32_t boot0;
int chipset;
int card_type;
int is_nv03t;
struct chipset_info chipset;
void *bar0;
size_t bar0len;
int hasbar1;
Expand Down
2 changes: 1 addition & 1 deletion nva/CMakeLists.txt
Expand Up @@ -17,7 +17,7 @@ if (NOT DISABLE_NVA)
link_directories(${PC_PCIACCESS_LIBRARY_DIRS})

add_library(nva nva.c regspace.c)
target_link_libraries(nva ${PC_PCIACCESS_LIBRARIES})
target_link_libraries(nva nvhw ${PC_PCIACCESS_LIBRARIES})

SET(NVA_PROGS
nvalist
Expand Down
6 changes: 3 additions & 3 deletions nva/evotiming.c
Expand Up @@ -45,16 +45,16 @@ int evosend (int cnum, int c, int m, int d)
{
uint32_t ctrl;

if (nva_cards[cnum].chipset >= 0xd0) {
if (nva_cards[cnum].chipset.chipset >= 0xd0) {
ctrl = nva_rd32(cnum, 0x610700 + (c * 8));
nva_wr32(cnum, 0x610700 + (c * 8), ctrl | 1);
nva_wr32(cnum, 0x610704 + (c * 8), d);
nva_wr32(cnum, 0x610700 + (c * 8), 0x80000001 | m);
while (nva_rd32(cnum, 0x610700 + (c * 8)) & 0x80000000);
nva_wr32(cnum, 0x610700 + (c * 8), ctrl);
} else
if (nva_cards[cnum].chipset == 0x50 ||
nva_cards[cnum].chipset >= 0x84) {
if (nva_cards[cnum].chipset.chipset == 0x50 ||
nva_cards[cnum].chipset.chipset >= 0x84) {
ctrl = nva_rd32(cnum, 0x610300 + (c * 8));
nva_wr32(cnum, 0x610300 + (c * 8), ctrl | 1);
nva_wr32(cnum, 0x610304 + (c * 8), d);
Expand Down
38 changes: 2 additions & 36 deletions nva/nva.c
Expand Up @@ -134,42 +134,8 @@ int nva_init() {
nva_cards[i].bar2 = 0;
}
}
nva_cards[i].boot0 = nva_rd32(i, 0);
nva_cards[i].chipset = nva_cards[i].boot0 >> 20 & 0xff;
if (nva_cards[i].chipset < 0x10) {
if ((nva_cards[i].boot0 & 0xfff00000) == 0x10800000) {
nva_cards[i].chipset = 0x108;
} else if (nva_cards[i].boot0 & 0xf000) {
if (nva_cards[i].boot0 & 0xf00000)
nva_cards[i].chipset = 5;
else
nva_cards[i].chipset = 4;
} else {
nva_cards[i].chipset = nva_cards[i].boot0 >> 16 & 0xf;
if ((nva_cards[i].boot0 & 0xff) >= 0x20)
nva_cards[i].is_nv03t = 1;
}
}
if (dev->vendor_id == 0x104a && dev->device_id == 0x0009)
nva_cards[i].chipset = 0x01;

if (nva_cards[i].chipset < 0x04)
nva_cards[i].card_type = nva_cards[i].chipset;
else if (nva_cards[i].chipset < 0x10)
nva_cards[i].card_type = 0x04;
else if (nva_cards[i].chipset < 0x20)
nva_cards[i].card_type = 0x10;
else if (nva_cards[i].chipset < 0x30)
nva_cards[i].card_type = 0x20;
else if (nva_cards[i].chipset < 0x40)
nva_cards[i].card_type = 0x30;
else if (nva_cards[i].chipset < 0x50 ||
(nva_cards[i].chipset & 0xf0) == 0x60)
nva_cards[i].card_type = 0x40;
else if (nva_cards[i].chipset < 0xc0)
nva_cards[i].card_type = 0x50;
else
nva_cards[i].card_type = 0xc0;
uint32_t pmc_id = nva_rd32(i, 0);
parse_pmc_id(pmc_id, &nva_cards[i].chipset);
}
return (nva_cardsnum == 0);
}
8 changes: 4 additions & 4 deletions nva/nvacounter.c
Expand Up @@ -566,18 +566,18 @@ int main(int argc, char **argv)
return 1;
}

if (nva_cards[cnum].chipset < 0x10 ||
nva_cards[cnum].chipset >= 0xc0)
if (nva_cards[cnum].chipset.chipset < 0x10 ||
nva_cards[cnum].chipset.chipset >= 0xc0)
{
fprintf(stderr, "The chipset nv%x isn't currently supported\n",
nva_cards[cnum].chipset);
nva_cards[cnum].chipset.chipset);
return 1;
}

/* Init */
nva_wr32(cnum, 0x200, 0xffffffff);

printf("Chipset nv%x:\n\n", nva_cards[cnum].chipset);
printf("Chipset nv%x:\n\n", nva_cards[cnum].chipset.chipset);

poll_signals(cnum, signals_ref);
find_counter_noise(cnum);
Expand Down
6 changes: 3 additions & 3 deletions nva/nvaevo.c
Expand Up @@ -58,16 +58,16 @@ int main(int argc, char **argv) {
sscanf (argv[optind + 1], "%x", &m);
sscanf (argv[optind + 2], "%x", &d);

if (nva_cards[cnum].chipset >= 0xd0) {
if (nva_cards[cnum].chipset.chipset >= 0xd0) {
ctrl = nva_rd32(cnum, 0x610700 + (c * 8));
nva_wr32(cnum, 0x610700 + (c * 8), ctrl | 1);
nva_wr32(cnum, 0x610704 + (c * 8), d);
nva_wr32(cnum, 0x610700 + (c * 8), 0x80000001 | m);
while (nva_rd32(cnum, 0x610700 + (c * 8)) & 0x80000000);
nva_wr32(cnum, 0x610700 + (c * 8), ctrl);
} else
if (nva_cards[cnum].chipset == 0x50 ||
nva_cards[cnum].chipset >= 0x84) {
if (nva_cards[cnum].chipset.chipset == 0x50 ||
nva_cards[cnum].chipset.chipset >= 0x84) {
ctrl = nva_rd32(cnum, 0x610300 + (c * 8));
nva_wr32(cnum, 0x610300 + (c * 8), ctrl | 1);
nva_wr32(cnum, 0x610304 + (c * 8), d);
Expand Down
8 changes: 4 additions & 4 deletions nva/nvafakebios.c
Expand Up @@ -66,17 +66,17 @@ int vbios_upload_pramin(int cnum, uint8_t *vbios, int length)
uint32_t ret = EUNK;
int i = 0;

if (nva_cards[cnum].chipset < 0x04) {
if (nva_cards[cnum].chipset.chipset < 0x04) {
return ECARD;
}

/* Update the checksum */
chksum(vbios, length);

fprintf(stderr, "Attempt to upload the vbios to card %i (nv%02x) using PRAMIN\n",
cnum, nva_cards[cnum].chipset);
cnum, nva_cards[cnum].chipset.chipset);

if (nva_cards[cnum].card_type >= 0x50) {
if (nva_cards[cnum].chipset.card_type >= 0x50) {
uint64_t vbios_vram = (uint64_t)(nva_rd32(cnum, 0x619f04) & ~0xff) << 8;

if (!vbios_vram)
Expand All @@ -93,7 +93,7 @@ int vbios_upload_pramin(int cnum, uint8_t *vbios, int length)

ret = EOK;

if (nva_cards[cnum].card_type >= 0x50)
if (nva_cards[cnum].chipset.card_type >= 0x50)
nva_wr32(cnum, 0x1700, old_bar0_pramin);

return ret;
Expand Down
22 changes: 11 additions & 11 deletions nva/nvagetbios.c
Expand Up @@ -124,20 +124,20 @@ int vbios_extract_prom(int cnum, uint8_t *vbios, int *length)
int i;

fprintf(stderr, "Attempt to extract the vbios from card %i (nv%02x) using PROM\n",
cnum, nva_cards[cnum].chipset);
cnum, nva_cards[cnum].chipset.chipset);

int32_t prom_offset;
int32_t prom_size;
int32_t pbus_offset = 0;

if (nva_cards[cnum].chipset < 0x03) {
if (nva_cards[cnum].chipset.chipset < 0x03) {
prom_offset = 0x610000;
prom_size = NV01_PROM_SIZE;
} else if (nva_cards[cnum].chipset < 0x04) {
} else if (nva_cards[cnum].chipset.chipset < 0x04) {
prom_offset = 0x110000;
prom_size = NV03_PROM_SIZE;
} else {
if (nva_cards[cnum].chipset < 0x40)
if (nva_cards[cnum].chipset.chipset < 0x40)
pbus_offset = 0x1800;
else
pbus_offset = 0x88000;
Expand All @@ -156,7 +156,7 @@ int vbios_extract_prom(int cnum, uint8_t *vbios, int *length)
vbios[i] = nva_rd32(cnum, prom_offset + (i & ~3)) >> (i & 3) * 8;

ret = nv_ckbios(vbios);
if (nva_cards[cnum].chipset >= 0x04) {
if (nva_cards[cnum].chipset.chipset >= 0x04) {
nva_wr32(cnum, pbus_offset + 0x50, pci_cfg_50);
}
*length = prom_size;
Expand All @@ -170,16 +170,16 @@ int vbios_extract_pramin(int cnum, uint8_t *vbios, int *length)
uint32_t ret = EUNK;
int i;

if (nva_cards[cnum].chipset < 0x04) {
if (nva_cards[cnum].chipset.chipset < 0x04) {
fprintf(stderr, "Card %i (nv%02x) does not support PRAMIN!\n",
cnum, nva_cards[cnum].chipset);
cnum, nva_cards[cnum].chipset.chipset);
return ECARD;
}

fprintf(stderr, "Attempt to extract the vbios from card %i (nv%02x) using PRAMIN\n",
cnum, nva_cards[cnum].chipset);
cnum, nva_cards[cnum].chipset.chipset);

if (nva_cards[cnum].card_type >= 0x50) {
if (nva_cards[cnum].chipset.card_type >= 0x50) {
uint64_t vbios_vram = (uint64_t)(nva_rd32(cnum, 0x619f04) & ~0xff) << 8;

if (!vbios_vram)
Expand All @@ -196,7 +196,7 @@ int vbios_extract_pramin(int cnum, uint8_t *vbios, int *length)
vbios[i] = nva_rd8(cnum, NV_PRAMIN_OFFSET + i);

ret = nv_ckbios(vbios);
if (nva_cards[cnum].card_type >= 0x50)
if (nva_cards[cnum].chipset.card_type >= 0x50)
nva_wr32(cnum, 0x1700, old_bar0_pramin);

return ret;
Expand Down Expand Up @@ -245,7 +245,7 @@ int main(int argc, char **argv) {
}

if (source == NULL) {
if (nva_cards[cnum].chipset < 4)
if (nva_cards[cnum].chipset.chipset < 4)
source = "PROM";
else
source = "PRAMIN";
Expand Down
4 changes: 2 additions & 2 deletions nva/nvalist.c
Expand Up @@ -33,8 +33,8 @@ int main() {
}
int i;
for (i = 0; i < nva_cardsnum; i++)
printf ("%d: %04x:%02x:%02x.%x NV%02X%s %08x\n", i,
printf ("%d: %04x:%02x:%02x.%x %s %08x\n", i,
nva_cards[i].pci->domain, nva_cards[i].pci->bus, nva_cards[i].pci->dev, nva_cards[i].pci->func,
nva_cards[i].chipset, (nva_cards[i].is_nv03t?"T":""), nva_cards[i].boot0);
nva_cards[i].chipset.name, nva_cards[i].chipset.pmc_id);
return 0;
}
2 changes: 1 addition & 1 deletion nva/nvapms.c
Expand Up @@ -78,7 +78,7 @@ pms_launch(int cnum, struct pms_ucode* pms, ptime_t *wall_time)
struct timeval wall_start, wall_end;
int i;

if (nva_cards[cnum].chipset < 0x90) {
if (nva_cards[cnum].chipset.chipset < 0x90) {
pms_data = 0x001400;
pms_kick = 0x00000003;
} else {
Expand Down
19 changes: 12 additions & 7 deletions nva/nvapy.pyx
@@ -1,9 +1,13 @@
cdef extern from "nva.h":
struct nva_card:
unsigned boot0
cdef extern from "nvhw.h":
struct chipset_info:
unsigned pmc_id
int chipset
int card_type
int is_nv03t

cdef extern from "nva.h":
struct nva_card:
chipset_info chipset
void *bar0
void *bar1
void *bar2
Expand Down Expand Up @@ -62,10 +66,11 @@ cdef NvaCard_ nva_wrapcard(nva_card *ccard):
card.bar0 = nva_wrapbar(ccard.bar0, ccard.bar0len)
card.bar1 = nva_wrapbar(ccard.bar1, ccard.bar1len) if ccard.hasbar1 else None
card.bar2 = nva_wrapbar(ccard.bar2, ccard.bar2len) if ccard.hasbar2 else None
card.chipset = ccard.chipset
card.boot0 = ccard.boot0
card.card_type = ccard.card_type
card.is_nv03t = ccard.is_nv03t
# XXX clean up?
card.chipset = ccard.chipset.chipset
card.pmc_id = ccard.chipset.pmc_id
card.card_type = ccard.chipset.card_type
card.is_nv03t = ccard.chipset.is_nv03t
return card

if nva_init():
Expand Down
4 changes: 2 additions & 2 deletions nva/nvaspyi2c.c
Expand Up @@ -252,10 +252,10 @@ int main(int argc, char **argv)
}
sscanf (argv[optind], "%i", &port);

if (nva_cards[cnum].chipset < 0xd9 && port >= 4) {
if (nva_cards[cnum].chipset.chipset < 0xd9 && port >= 4) {
printf("Invalid port number: This chipset has 4 ports\n");
return 1;
} else if (nva_cards[cnum].chipset >= 0xd9 && port >= 10) {
} else if (nva_cards[cnum].chipset.chipset >= 0xd9 && port >= 10) {
printf("Invalid port number: NVD9+ chipsets have 10 ports\n");
return 1;
}
Expand Down

0 comments on commit c39ccbb

Please sign in to comment.