int main(int argc, char **argv) { if (nva_init()) { fprintf (stderr, "PCI init failure!\n"); return 1; } int c; int cnum =0; while ((c = getopt (argc, argv, "c:")) != -1) switch (c) { case 'c': sscanf(optarg, "%d", &cnum); break; } if (cnum >= nva_cardsnum) { if (nva_cardsnum) fprintf (stderr, "No such card.\n"); else fprintf (stderr, "No cards found.\n"); return 1; } int32_t a, b = 1, i; if (optind >= argc) { fprintf (stderr, "No address specified.\n"); return 1; } sscanf (argv[optind], "%x", &a); if (optind + 1 < argc) sscanf (argv[optind + 1], "%x", &b); int ls = 1; while (b > 0) { uint8_t z[16]; int s = 0; for (i = 0; i < 16 && i < b; i++) if (z[i] = nva_rd8(cnum, a+i)) s = 1; if (s) { ls = 1; printf ("%08x:", a); for (i = 0; i < 16 && i < b; i++) { printf (" %02x", z[i]); } printf ("\n"); } else { if (ls) printf ("...\n"), ls = 0; } a+=16; b-=16; } return 0; }
int main(int argc, char **argv) { if (nva_init()) { fprintf (stderr, "PCI init failure!\n"); return 1; } int c; int cnum =0; while ((c = getopt (argc, argv, "c:")) != -1) switch (c) { case 'c': sscanf(optarg, "%d", &cnum); break; } if (cnum >= nva_cardsnum) { if (nva_cardsnum) fprintf (stderr, "No such card.\n"); else fprintf (stderr, "No cards found.\n"); return 1; } uint32_t a, b; if (optind >= argc) { fprintf (stderr, "No address specified.\n"); return 1; } if (optind + 1 >= argc) { fprintf (stderr, "No length specified.\n"); return 1; } FILE *file = stdout; if (optind + 2 < argc) { file = fopen(argv[optind+2], "wb"); if (!file) { perror("fopen"); return 1; } } sscanf (argv[optind], "%x", &a); sscanf (argv[optind+1], "%x", &b); b += a; while (a != b) { nva_wr32(cnum, 0x1700, a >> 16); int c = nva_rd8(cnum, 0x700000 | (a&0xffff)); putc(c, file); a++; } return 0; }
/* vbios should at least be NV_PROM_SIZE bytes long */ int vbios_extract_prom(int cnum, uint8_t *vbios, int *length) { uint32_t pci_cfg_50 = 0; uint32_t ret = EUNK; int i; fprintf(stderr, "Attempt to extract the vbios from card %i (nv%02x) using PROM\n", cnum, nva_cards[cnum].chipset); int32_t prom_offset; int32_t prom_size; int32_t pbus_offset = 0; if (nva_cards[cnum].chipset < 0x03) { prom_offset = 0x610000; prom_size = NV01_PROM_SIZE; } else if (nva_cards[cnum].chipset < 0x04) { prom_offset = 0x110000; prom_size = NV03_PROM_SIZE; } else { if (nva_cards[cnum].chipset < 0x40) pbus_offset = 0x1800; else pbus_offset = 0x88000; prom_offset = 0x300000; prom_size = NV_PROM_SIZE; pci_cfg_50 = nva_rd32(cnum, pbus_offset + 0x50); nva_wr32(cnum, pbus_offset + 0x50, 0); } /* on some 6600GT/6800LE prom reads are messed up. nvclock alleges a * a good read may be obtained by waiting or re-reading (cargocult: 5x) * each byte. we'll hope pramin has something usable instead */ for (i = 0; i < prom_size; i++) vbios[i] = nva_rd8(cnum, prom_offset + i); ret = nv_ckbios(vbios, length); if (nva_cards[cnum].chipset >= 0x04) { nva_wr32(cnum, pbus_offset + 0x50, pci_cfg_50); } return ret; }