mirror of
https://github.com/86Box/probing-tools.git
synced 2026-02-21 09:05:34 -07:00
Global clang-format
This commit is contained in:
246
ac97/ac97.c
246
ac97/ac97.c
@@ -24,82 +24,97 @@
|
||||
#include <string.h>
|
||||
#include "clib.h"
|
||||
|
||||
|
||||
uint8_t first = 1, silent = 0, bus, dev, func;
|
||||
uint8_t first = 1, silent = 0, bus, dev, func;
|
||||
uint16_t i, io_base, alt_io_base;
|
||||
|
||||
|
||||
static void
|
||||
codec_probe(uint16_t (*codec_read)(uint8_t reg),
|
||||
void (*codec_write)(uint8_t reg, uint16_t val))
|
||||
void (*codec_write)(uint8_t reg, uint16_t val))
|
||||
{
|
||||
uint8_t cur_reg = 0;
|
||||
uint8_t cur_reg = 0;
|
||||
uint16_t regs[64], *regp = regs;
|
||||
char buf[13];
|
||||
FILE *f;
|
||||
char buf[13];
|
||||
FILE *f;
|
||||
|
||||
/* Reset codec. */
|
||||
if (!silent) printf("\nResetting codec...");
|
||||
if (!silent)
|
||||
printf("\nResetting codec...");
|
||||
codec_write(0x00, 0xffff);
|
||||
if (!silent) printf(" done.\n");
|
||||
if (!silent)
|
||||
printf(" done.\n");
|
||||
|
||||
/* Set all optional registers/bits. */
|
||||
if (!silent) printf("Setting optional bits [Master");
|
||||
if (!silent)
|
||||
printf("Setting optional bits [Master");
|
||||
codec_write(0x02, 0xbf3f);
|
||||
if (!silent) printf(" AuxOut");
|
||||
if (!silent)
|
||||
printf(" AuxOut");
|
||||
codec_write(0x04, 0xbf3f);
|
||||
if (!silent) printf(" MonoOut");
|
||||
if (!silent)
|
||||
printf(" MonoOut");
|
||||
codec_write(0x06, 0x803f);
|
||||
if (!silent) printf(" PCBeep");
|
||||
if (!silent)
|
||||
printf(" PCBeep");
|
||||
codec_write(0x0a, 0x9ffe);
|
||||
if (!silent) printf(" Phone");
|
||||
if (!silent)
|
||||
printf(" Phone");
|
||||
codec_write(0x0c, 0x801f);
|
||||
if (!silent) printf(" Video");
|
||||
if (!silent)
|
||||
printf(" Video");
|
||||
codec_write(0x14, 0x9f1f);
|
||||
if (!silent) printf(" AuxIn");
|
||||
if (!silent)
|
||||
printf(" AuxIn");
|
||||
codec_write(0x16, 0x9f1f);
|
||||
if (!silent) printf(" GP");
|
||||
if (!silent)
|
||||
printf(" GP");
|
||||
codec_write(0x20, 0xf380);
|
||||
if (!silent) printf(" 3D");
|
||||
if (!silent)
|
||||
printf(" 3D");
|
||||
codec_write(0x22, 0xffff);
|
||||
if (!silent) printf(" EAID");
|
||||
if (!silent)
|
||||
printf(" EAID");
|
||||
codec_write(0x28, codec_read(0x28) | 0x0030);
|
||||
if (!silent) printf(" C/LFE");
|
||||
if (!silent)
|
||||
printf(" C/LFE");
|
||||
codec_write(0x36, 0xbfbf);
|
||||
if (!silent) printf(" Surround");
|
||||
if (!silent)
|
||||
printf(" Surround");
|
||||
codec_write(0x38, 0xbfbf);
|
||||
|
||||
/* Dump registers. */
|
||||
if (!silent) {
|
||||
printf("] then dumping registers:\n ");
|
||||
for (i = 0x0; i <= 0xf; i += 2) {
|
||||
if (i == 0x8)
|
||||
putchar(' ');
|
||||
printf(" %X", i);
|
||||
}
|
||||
putchar('\n');
|
||||
printf("] then dumping registers:\n ");
|
||||
for (i = 0x0; i <= 0xf; i += 2) {
|
||||
if (i == 0x8)
|
||||
putchar(' ');
|
||||
printf(" %X", i);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
do {
|
||||
/* Print row header. */
|
||||
if (!silent) printf("%02X:", cur_reg);
|
||||
/* Print row header. */
|
||||
if (!silent)
|
||||
printf("%02X:", cur_reg);
|
||||
|
||||
/* Iterate through register words on this range. */
|
||||
do {
|
||||
/* Add spacing at the halfway point. */
|
||||
if (!silent && ((cur_reg & 0x0f) == 0x08))
|
||||
putchar(' ');
|
||||
/* Iterate through register words on this range. */
|
||||
do {
|
||||
/* Add spacing at the halfway point. */
|
||||
if (!silent && ((cur_reg & 0x0f) == 0x08))
|
||||
putchar(' ');
|
||||
|
||||
/* Read and print the word value. */
|
||||
*regp = codec_read(cur_reg);
|
||||
if (!silent) printf(" %04X", *regp);
|
||||
regp++;
|
||||
/* Read and print the word value. */
|
||||
*regp = codec_read(cur_reg);
|
||||
if (!silent)
|
||||
printf(" %04X", *regp);
|
||||
regp++;
|
||||
|
||||
cur_reg += 2;
|
||||
} while (cur_reg & 0x0f);
|
||||
cur_reg += 2;
|
||||
} while (cur_reg & 0x0f);
|
||||
|
||||
/* Move on to the next line. */
|
||||
if (!silent) putchar('\n');
|
||||
/* Move on to the next line. */
|
||||
if (!silent)
|
||||
putchar('\n');
|
||||
} while (cur_reg < 0x80);
|
||||
|
||||
/* Generate and print dump file name. */
|
||||
@@ -109,32 +124,30 @@ codec_probe(uint16_t (*codec_read)(uint8_t reg),
|
||||
/* Write dump file. */
|
||||
f = fopen(buf, "wb");
|
||||
if (!f) {
|
||||
printf("File creation failed\n");
|
||||
return;
|
||||
printf("File creation failed\n");
|
||||
return;
|
||||
}
|
||||
if (fwrite(regs, 1, sizeof(regs), f) < sizeof(regs)) {
|
||||
fclose(f);
|
||||
printf("File write failed\n");
|
||||
return;
|
||||
fclose(f);
|
||||
printf("File write failed\n");
|
||||
return;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
audiopci_codec_wait(multi_t *regval)
|
||||
{
|
||||
/* Wait for WIP to be cleared. */
|
||||
for (i = 1; i; i++) {
|
||||
regval->u32 = inl(io_base | 0x14);
|
||||
if (!(regval->u16[1] & 0x4000))
|
||||
break;
|
||||
regval->u32 = inl(io_base | 0x14);
|
||||
if (!(regval->u16[1] & 0x4000))
|
||||
break;
|
||||
}
|
||||
if (!i)
|
||||
printf("[!]");
|
||||
printf("[!]");
|
||||
}
|
||||
|
||||
|
||||
static uint16_t
|
||||
audiopci_codec_read(uint8_t reg)
|
||||
{
|
||||
@@ -156,7 +169,6 @@ audiopci_codec_read(uint8_t reg)
|
||||
return regval.u16[0];
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
audiopci_codec_write(uint8_t reg, uint16_t val)
|
||||
{
|
||||
@@ -166,7 +178,7 @@ audiopci_codec_write(uint8_t reg, uint16_t val)
|
||||
audiopci_codec_wait(®val);
|
||||
|
||||
/* Set address and data. */
|
||||
regval.u8[2] = reg;
|
||||
regval.u8[2] = reg;
|
||||
regval.u16[0] = val;
|
||||
|
||||
/* Perform write. */
|
||||
@@ -176,7 +188,6 @@ audiopci_codec_write(uint8_t reg, uint16_t val)
|
||||
audiopci_codec_wait(®val);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
audiopci_probe(uint16_t dev_id)
|
||||
{
|
||||
@@ -192,7 +203,7 @@ audiopci_probe(uint16_t dev_id)
|
||||
/* Get I/O BAR. */
|
||||
io_base = pci_get_io_bar(bus, dev, func, 0x10, 64, "Main");
|
||||
if (!io_base)
|
||||
return;
|
||||
return;
|
||||
|
||||
printf("GPIO readout [%02X]\n", inb(io_base | 0x02));
|
||||
|
||||
@@ -200,7 +211,6 @@ audiopci_probe(uint16_t dev_id)
|
||||
codec_probe(audiopci_codec_read, audiopci_codec_write);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
via_codec_wait(multi_t *regval, uint16_t additional)
|
||||
{
|
||||
@@ -209,15 +219,14 @@ via_codec_wait(multi_t *regval, uint16_t additional)
|
||||
/* Wait for Controller Busy to be cleared and additional bits to be set. */
|
||||
mask |= additional;
|
||||
for (i = 1; i; i++) {
|
||||
regval->u32 = inl(io_base | 0x80);
|
||||
if ((regval->u16[1] & mask) == additional)
|
||||
break;
|
||||
regval->u32 = inl(io_base | 0x80);
|
||||
if ((regval->u16[1] & mask) == additional)
|
||||
break;
|
||||
}
|
||||
if (!i)
|
||||
printf("[!]");
|
||||
printf("[!]");
|
||||
}
|
||||
|
||||
|
||||
static uint16_t
|
||||
via_codec_read(uint8_t reg)
|
||||
{
|
||||
@@ -242,7 +251,6 @@ via_codec_read(uint8_t reg)
|
||||
return regval.u16[0];
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
via_codec_write(uint8_t reg, uint16_t val)
|
||||
{
|
||||
@@ -255,7 +263,7 @@ via_codec_write(uint8_t reg, uint16_t val)
|
||||
regval.u8[3] = 0x02;
|
||||
|
||||
/* Set address and data. */
|
||||
regval.u8[2] = reg;
|
||||
regval.u8[2] = reg;
|
||||
regval.u16[0] = val;
|
||||
|
||||
/* Perform write. */
|
||||
@@ -265,83 +273,80 @@ via_codec_write(uint8_t reg, uint16_t val)
|
||||
via_codec_wait(®val, 0);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
via_probe(uint16_t dev_id)
|
||||
{
|
||||
uint8_t rev, base_rev;
|
||||
|
||||
/* Print controller information. */
|
||||
rev = pci_readb(bus, dev, func, 0x08);
|
||||
rev = pci_readb(bus, dev, func, 0x08);
|
||||
base_rev = pci_readb(bus, dev, 0, 0x08);
|
||||
printf("Found VIA %04X revision %02X (base %02X) at bus %02X device %02X function %d\n", dev_id, rev, base_rev, bus, dev, func);
|
||||
|
||||
/* Get SGD I/O BAR. */
|
||||
io_base = pci_get_io_bar(bus, dev, func, 0x10, 256, "SGD");
|
||||
if (!io_base)
|
||||
return;
|
||||
return;
|
||||
|
||||
/* Set up AC-Link interface. */
|
||||
printf("Waking codec up... ");
|
||||
pci_writeb(bus, dev, func, 0x41, (dev_id == 0x3058) ? 0xc4 : 0xc0);
|
||||
for (i = 1; i; i++) {
|
||||
if (pci_readb(bus, dev, func, 0x40) & 0x01)
|
||||
break;
|
||||
if (pci_readb(bus, dev, func, 0x40) & 0x01)
|
||||
break;
|
||||
}
|
||||
if (!i) {
|
||||
printf("timed out!\n");
|
||||
return;
|
||||
printf("timed out!\n");
|
||||
return;
|
||||
}
|
||||
printf("done.\n");
|
||||
|
||||
/* Test Codec Shadow I/O BAR on 686. */
|
||||
if (dev_id == 0x3058) {
|
||||
alt_io_base = pci_get_io_bar(bus, dev, func, 0x1c, 256, "Codec Shadow");
|
||||
alt_io_base = pci_get_io_bar(bus, dev, func, 0x1c, 256, "Codec Shadow");
|
||||
|
||||
/* Perform tests if the BAR is set. */
|
||||
if (alt_io_base) {
|
||||
/* Reset codec. */
|
||||
via_codec_write(0x00, 0xffff);
|
||||
/* Perform tests if the BAR is set. */
|
||||
if (alt_io_base) {
|
||||
/* Reset codec. */
|
||||
via_codec_write(0x00, 0xffff);
|
||||
|
||||
/* Test shadow behavior. */
|
||||
printf("Testing Codec Shadow:");
|
||||
/* Test shadow behavior. */
|
||||
printf("Testing Codec Shadow:");
|
||||
|
||||
i = via_codec_read(0x02);
|
||||
printf(" Read[%04X %04X]", i, inw(alt_io_base | 0x02));
|
||||
i = via_codec_read(0x02);
|
||||
printf(" Read[%04X %04X]", i, inw(alt_io_base | 0x02));
|
||||
|
||||
via_codec_write(0x02, 0xffff);
|
||||
printf(" Write[%04X %04X]", 0xffff, inw(alt_io_base | 0x02));
|
||||
via_codec_write(0x02, 0xffff);
|
||||
printf(" Write[%04X %04X]", 0xffff, inw(alt_io_base | 0x02));
|
||||
|
||||
via_codec_write(0x02, 0xffff);
|
||||
i = via_codec_read(0x02);
|
||||
printf(" WriteRead[%04X %04X]", i, inw(alt_io_base | 0x02));
|
||||
via_codec_write(0x02, 0xffff);
|
||||
i = via_codec_read(0x02);
|
||||
printf(" WriteRead[%04X %04X]", i, inw(alt_io_base | 0x02));
|
||||
|
||||
outw(alt_io_base | 0x02, 0x0000);
|
||||
i = inw(alt_io_base | 0x02);
|
||||
printf("\n DirectWrite[%04X %04X]", i, via_codec_read(0x02));
|
||||
}
|
||||
outw(alt_io_base | 0x02, 0x0000);
|
||||
i = inw(alt_io_base | 0x02);
|
||||
printf("\n DirectWrite[%04X %04X]", i, via_codec_read(0x02));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* Perform codec probe. */
|
||||
codec_probe(via_codec_read, via_codec_write);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
intel_codec_wait()
|
||||
{
|
||||
/* Wait for CAS to be cleared. */
|
||||
for (i = 1; i; i++) {
|
||||
if (!(inb(alt_io_base | 0x34) & 0x01))
|
||||
break;
|
||||
if (!(inb(alt_io_base | 0x34) & 0x01))
|
||||
break;
|
||||
}
|
||||
if (!i)
|
||||
printf("[!]");
|
||||
printf("[!]");
|
||||
}
|
||||
|
||||
|
||||
static uint16_t
|
||||
intel_codec_read(uint8_t reg)
|
||||
{
|
||||
@@ -352,7 +357,6 @@ intel_codec_read(uint8_t reg)
|
||||
return inw(io_base | reg);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
intel_codec_write(uint8_t reg, uint16_t val)
|
||||
{
|
||||
@@ -363,7 +367,6 @@ intel_codec_write(uint8_t reg, uint16_t val)
|
||||
outw(io_base | reg, val);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
intel_probe(uint16_t dev_id)
|
||||
{
|
||||
@@ -376,26 +379,26 @@ intel_probe(uint16_t dev_id)
|
||||
/* Get Mixer I/O BAR. */
|
||||
io_base = pci_get_io_bar(bus, dev, func, 0x10, 256, "Mixer");
|
||||
if (!io_base)
|
||||
return;
|
||||
return;
|
||||
|
||||
/* Get Bus Master I/O BAR. */
|
||||
alt_io_base = pci_get_io_bar(bus, dev, func, 0x14, 256, "Bus Master");
|
||||
if (!alt_io_base)
|
||||
return;
|
||||
return;
|
||||
|
||||
/* Set up AC-Link interface. */
|
||||
printf("Waking codec up... ");
|
||||
outl(alt_io_base | 0x2c, inl(alt_io_base | 0x2c) & ~0x00000002);
|
||||
for (i = 1; i; i++) /* unknown delay required */
|
||||
inb(0xeb);
|
||||
inb(0xeb);
|
||||
outl(alt_io_base | 0x2c, inl(alt_io_base | 0x2c) | 0x00000002);
|
||||
for (i = 1; i; i++) {
|
||||
if (inl(alt_io_base | 0x30) & 0x00000100)
|
||||
break;
|
||||
if (inl(alt_io_base | 0x30) & 0x00000100)
|
||||
break;
|
||||
}
|
||||
if (!i) {
|
||||
printf("timed out!\n");
|
||||
return;
|
||||
printf("timed out!\n");
|
||||
return;
|
||||
}
|
||||
printf("done.\n");
|
||||
|
||||
@@ -403,40 +406,37 @@ intel_probe(uint16_t dev_id)
|
||||
codec_probe(intel_codec_read, intel_codec_write);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
print_spacer()
|
||||
{
|
||||
if (first)
|
||||
first = 0;
|
||||
first = 0;
|
||||
else if (silent)
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
else
|
||||
printf("\n\n");
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
pci_scan_callback(uint8_t this_bus, uint8_t this_dev, uint8_t this_func,
|
||||
uint16_t ven_id, uint16_t dev_id)
|
||||
uint16_t ven_id, uint16_t dev_id)
|
||||
{
|
||||
bus = this_bus;
|
||||
dev = this_dev;
|
||||
bus = this_bus;
|
||||
dev = this_dev;
|
||||
func = this_func;
|
||||
|
||||
if ((ven_id == 0x1274) && (dev_id != 0x5000)) {
|
||||
print_spacer();
|
||||
audiopci_probe(dev_id);
|
||||
print_spacer();
|
||||
audiopci_probe(dev_id);
|
||||
} else if ((ven_id == 0x1106) && ((dev_id == 0x3058) || (dev_id == 0x3059))) {
|
||||
print_spacer();
|
||||
via_probe(dev_id);
|
||||
print_spacer();
|
||||
via_probe(dev_id);
|
||||
} else if ((ven_id == 0x8086) && ((dev_id == 0x2415) || (dev_id == 0x2425) || (dev_id == 0x2445) || (dev_id == 0x2485) || (dev_id == 0x24c5) || (dev_id == 0x24d5) || (dev_id == 0x25a6) || (dev_id == 0x266e) || (dev_id == 0x27de) || (dev_id == 0x7195))) {
|
||||
print_spacer();
|
||||
intel_probe(dev_id);
|
||||
print_spacer();
|
||||
intel_probe(dev_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@@ -447,11 +447,11 @@ main(int argc, char **argv)
|
||||
|
||||
/* Initialize PCI, and exit in case of failure. */
|
||||
if (!pci_init())
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
/* Set silent mode. */
|
||||
if ((argc >= 1) && !strcmp(argv[1], "-s"))
|
||||
silent = 1;
|
||||
silent = 1;
|
||||
|
||||
/* Scan PCI bus 0. */
|
||||
pci_scan_bus(0, pci_scan_callback);
|
||||
|
||||
148
acpi/acpi.c
148
acpi/acpi.c
@@ -23,12 +23,11 @@
|
||||
#include <stdio.h>
|
||||
#include "clib.h"
|
||||
|
||||
|
||||
static void
|
||||
try_sleep()
|
||||
{
|
||||
unsigned int port, type;
|
||||
char dummy_buf[256];
|
||||
char dummy_buf[256];
|
||||
|
||||
/* Prompt for port address. */
|
||||
printf("Enter port address to try: ");
|
||||
@@ -45,11 +44,10 @@ try_sleep()
|
||||
printf("Nothing?\n");
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
probe_intel(uint8_t dev, uint8_t func)
|
||||
{
|
||||
uint8_t status;
|
||||
uint8_t status;
|
||||
uint16_t acpi_base, port, devctl;
|
||||
|
||||
/* Read and print ACPI I/O base and PMCNTRL value. */
|
||||
@@ -60,80 +58,78 @@ probe_intel(uint8_t dev, uint8_t func)
|
||||
|
||||
/* Read and print SMI trap status, ports and values. */
|
||||
devctl = inl(acpi_base + 0x2e);
|
||||
port = pci_readw(0, dev, func, 0x60);
|
||||
port = pci_readw(0, dev, func, 0x60);
|
||||
status = pci_readb(0, dev, func, 0x62);
|
||||
printf("SMI traps: Dev9 = %04X+%X Decode[%c] Trap[%c] Val[%04X]\n", port, status & 0x0f,
|
||||
(status & 0x20) ? '√' : ' ', (devctl & 0x0008) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, func, 0x64);
|
||||
(status & 0x20) ? '√' : ' ', (devctl & 0x0008) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, func, 0x64);
|
||||
status = pci_readb(0, dev, func, 0x66);
|
||||
printf(" Dev10 = %04X+%X Decode[%c] Trap[%c] Val[%04X]\n", port, status & 0x0f,
|
||||
(status & 0x20) ? '√' : ' ', (devctl & 0x0020) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, func, 0x68);
|
||||
(status & 0x20) ? '√' : ' ', (devctl & 0x0020) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, func, 0x68);
|
||||
status = pci_readb(0, dev, func, 0x6a);
|
||||
printf(" Dev12 = %04X+%X Decode[%c] Trap[%c] Val[%04X]\n", port, status & 0x0f,
|
||||
(status & 0x10) ? '√' : ' ', (devctl & 0x0100) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, func, 0x70);
|
||||
(status & 0x10) ? '√' : ' ', (devctl & 0x0100) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, func, 0x70);
|
||||
status = pci_readb(0, dev, func, 0x72);
|
||||
printf(" Dev13 = %04X+%X Decode[%c] Trap[%c] Val[%04X]\n", port, status & 0x0f,
|
||||
(status & 0x10) ? '√' : ' ', (devctl & 0x0200) ? '√' : ' ', inw(port));
|
||||
(status & 0x10) ? '√' : ' ', (devctl & 0x0200) ? '√' : ' ', inw(port));
|
||||
|
||||
/* Run interactive sequence. */
|
||||
try_sleep();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
probe_via(uint8_t dev, uint8_t func, uint16_t dev_id)
|
||||
{
|
||||
uint8_t mask;
|
||||
uint8_t mask;
|
||||
uint16_t acpi_base, port, glben, status;
|
||||
|
||||
/* Read and print ACPI I/O base and PMCNTRL value. */
|
||||
acpi_base = pci_readw(0, dev, func, (dev_id == 0x3040) ? 0x20 : 0x48);
|
||||
port = acpi_base & ((dev_id == 0x3040) ? 0xff00 : 0xff80);
|
||||
port = acpi_base & ((dev_id == 0x3040) ? 0xff00 : 0xff80);
|
||||
printf("ACPI base register = %04X PMCNTRL[%04X] Val[%04X]\n", acpi_base, port | 0x04, inw(port | 0x04));
|
||||
acpi_base = port;
|
||||
|
||||
/* Read and print SMI trap status, ports and values. */
|
||||
if (dev_id >= 0x3050) {
|
||||
glben = inw(acpi_base + 0x2a);
|
||||
mask = pci_readb(0, dev, 0, 0x80);
|
||||
if (dev_id == 0x3050) {
|
||||
status = pci_readw(0, dev, 0, 0x76);
|
||||
port = pci_readw(0, dev, 0, 0x78);
|
||||
printf("SMI traps: PCS0 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, mask & 0x0f,
|
||||
(status & 0x0010) ? '√' : ' ', (status & 0x1000) ? '√' : ' ', (glben & 0x4000) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, 0, 0x7a);
|
||||
printf(" PCS1 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, (mask >> 4) & 0x0f,
|
||||
(status & 0x0020) ? '√' : ' ', (status & 0x2000) ? '√' : ' ', (glben & 0x8000) ? '√' : ' ', inw(port));
|
||||
} else {
|
||||
status = pci_readw(0, dev, 0, 0x8b);
|
||||
port = pci_readw(0, dev, 0, 0x78);
|
||||
printf("SMI traps: PCS0 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, mask & 0x0f,
|
||||
(status & 0x0100) ? '√' : ' ', (status & 0x1000) ? '√' : ' ', (glben & 0x4000) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, 0, 0x7a);
|
||||
printf(" PCS1 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, (mask >> 4) & 0x0f,
|
||||
(status & 0x0200) ? '√' : ' ', (status & 0x2000) ? '√' : ' ', (glben & 0x8000) ? '√' : ' ', inw(port));
|
||||
glben = inw(acpi_base + 0x42); /* extended I/O traps */
|
||||
mask = pci_readb(0, dev, 0, 0x8a);
|
||||
port = pci_readw(0, dev, 0, 0x8c);
|
||||
printf(" PCS2 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, mask & 0x0f,
|
||||
(status & 0x0400) ? '√' : ' ', (status & 0x4000) ? '√' : ' ', (glben & 0x0001) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, 0, 0x8e);
|
||||
printf(" PCS3 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, (mask >> 4) & 0x0f,
|
||||
(status & 0x0800) ? '√' : ' ', (status & 0x8000) ? '√' : ' ', (glben & 0x0002) ? '√' : ' ', inw(port));
|
||||
}
|
||||
glben = inw(acpi_base + 0x2a);
|
||||
mask = pci_readb(0, dev, 0, 0x80);
|
||||
if (dev_id == 0x3050) {
|
||||
status = pci_readw(0, dev, 0, 0x76);
|
||||
port = pci_readw(0, dev, 0, 0x78);
|
||||
printf("SMI traps: PCS0 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, mask & 0x0f,
|
||||
(status & 0x0010) ? '√' : ' ', (status & 0x1000) ? '√' : ' ', (glben & 0x4000) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, 0, 0x7a);
|
||||
printf(" PCS1 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, (mask >> 4) & 0x0f,
|
||||
(status & 0x0020) ? '√' : ' ', (status & 0x2000) ? '√' : ' ', (glben & 0x8000) ? '√' : ' ', inw(port));
|
||||
} else {
|
||||
status = pci_readw(0, dev, 0, 0x8b);
|
||||
port = pci_readw(0, dev, 0, 0x78);
|
||||
printf("SMI traps: PCS0 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, mask & 0x0f,
|
||||
(status & 0x0100) ? '√' : ' ', (status & 0x1000) ? '√' : ' ', (glben & 0x4000) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, 0, 0x7a);
|
||||
printf(" PCS1 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, (mask >> 4) & 0x0f,
|
||||
(status & 0x0200) ? '√' : ' ', (status & 0x2000) ? '√' : ' ', (glben & 0x8000) ? '√' : ' ', inw(port));
|
||||
glben = inw(acpi_base + 0x42); /* extended I/O traps */
|
||||
mask = pci_readb(0, dev, 0, 0x8a);
|
||||
port = pci_readw(0, dev, 0, 0x8c);
|
||||
printf(" PCS2 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, mask & 0x0f,
|
||||
(status & 0x0400) ? '√' : ' ', (status & 0x4000) ? '√' : ' ', (glben & 0x0001) ? '√' : ' ', inw(port));
|
||||
port = pci_readw(0, dev, 0, 0x8e);
|
||||
printf(" PCS3 = %04X+%X Decode[%c] IntIO[%c] Trap[%c] Val[%04X]\n", port, (mask >> 4) & 0x0f,
|
||||
(status & 0x0800) ? '√' : ' ', (status & 0x8000) ? '√' : ' ', (glben & 0x0002) ? '√' : ' ', inw(port));
|
||||
}
|
||||
}
|
||||
|
||||
/* Run interactive sequence. */
|
||||
try_sleep();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
uint8_t dev, func;
|
||||
uint8_t dev, func;
|
||||
uint16_t ven_id, dev_id;
|
||||
uint32_t cf8;
|
||||
|
||||
@@ -142,42 +138,42 @@ main(int argc, char **argv)
|
||||
|
||||
/* Initialize PCI, and exit in case of failure. */
|
||||
if (!pci_init())
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
/* Scan PCI bus 0. */
|
||||
for (dev = 0; dev < 32; dev++) {
|
||||
/* Single-function devices are definitely not the southbridge. */
|
||||
if (!(pci_readb(0, dev, 0, 0x0e) & 0x80))
|
||||
continue;
|
||||
/* Single-function devices are definitely not the southbridge. */
|
||||
if (!(pci_readb(0, dev, 0, 0x0e) & 0x80))
|
||||
continue;
|
||||
|
||||
/* Determine and execute southbridge-specific function. */
|
||||
ven_id = pci_readw(0, dev, 3, 0x00);
|
||||
dev_id = pci_readw(0, dev, 3, 0x02);
|
||||
if ((ven_id == 0x8086) && (dev_id == 0x7113)) {
|
||||
printf("Found PIIX4 ACPI revision %02X at device %02X function %d\n", pci_readb(0, dev, 3, 0x08), dev, 3);
|
||||
probe_intel(dev, 3);
|
||||
return 0;
|
||||
} else if ((ven_id == 0x1055) && (dev_id == 0x9463)) {
|
||||
printf("Found SLC90E66 ACPI revision %02X at device %02X function %d\n", pci_readb(0, dev, 3, 0x08), dev, 3);
|
||||
probe_intel(dev, 3);
|
||||
return 0;
|
||||
} else if ((ven_id == 0x1106) && (dev_id == 0x3040)) {
|
||||
printf("Found VT82C586 ACPI revision %02X at device %02X function %d\n", pci_readb(0, dev, 3, 0x08), dev, 3);
|
||||
probe_via(dev, 3, dev_id);
|
||||
return 0;
|
||||
} else if ((ven_id == 0x1106) && (dev_id == 0x3050)) {
|
||||
printf("Found VT82C596 ACPI revision %02X at device %02X function %d\n", pci_readb(0, dev, 3, 0x08), dev, 3);
|
||||
probe_via(dev, 3, dev_id);
|
||||
return 0;
|
||||
} else {
|
||||
ven_id = pci_readw(0, dev, 4, 0);
|
||||
dev_id = pci_readw(0, dev, 4, 2);
|
||||
if ((ven_id == 0x1106) && (dev_id == 0x3057)) {
|
||||
printf("Found VT82C686 ACPI revision %02X at device %02X function %d\n", pci_readb(0, dev, 4, 0x08), dev, 4);
|
||||
probe_via(dev, 4, dev_id);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* Determine and execute southbridge-specific function. */
|
||||
ven_id = pci_readw(0, dev, 3, 0x00);
|
||||
dev_id = pci_readw(0, dev, 3, 0x02);
|
||||
if ((ven_id == 0x8086) && (dev_id == 0x7113)) {
|
||||
printf("Found PIIX4 ACPI revision %02X at device %02X function %d\n", pci_readb(0, dev, 3, 0x08), dev, 3);
|
||||
probe_intel(dev, 3);
|
||||
return 0;
|
||||
} else if ((ven_id == 0x1055) && (dev_id == 0x9463)) {
|
||||
printf("Found SLC90E66 ACPI revision %02X at device %02X function %d\n", pci_readb(0, dev, 3, 0x08), dev, 3);
|
||||
probe_intel(dev, 3);
|
||||
return 0;
|
||||
} else if ((ven_id == 0x1106) && (dev_id == 0x3040)) {
|
||||
printf("Found VT82C586 ACPI revision %02X at device %02X function %d\n", pci_readb(0, dev, 3, 0x08), dev, 3);
|
||||
probe_via(dev, 3, dev_id);
|
||||
return 0;
|
||||
} else if ((ven_id == 0x1106) && (dev_id == 0x3050)) {
|
||||
printf("Found VT82C596 ACPI revision %02X at device %02X function %d\n", pci_readb(0, dev, 3, 0x08), dev, 3);
|
||||
probe_via(dev, 3, dev_id);
|
||||
return 0;
|
||||
} else {
|
||||
ven_id = pci_readw(0, dev, 4, 0);
|
||||
dev_id = pci_readw(0, dev, 4, 2);
|
||||
if ((ven_id == 0x1106) && (dev_id == 0x3057)) {
|
||||
printf("Found VT82C686 ACPI revision %02X at device %02X function %d\n", pci_readb(0, dev, 4, 0x08), dev, 4);
|
||||
probe_via(dev, 4, dev_id);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Nothing of interest found. */
|
||||
|
||||
@@ -18,12 +18,11 @@
|
||||
#include <string.h>
|
||||
#include "clib.h"
|
||||
|
||||
|
||||
/* Dummy comment. */
|
||||
static int
|
||||
dump_range(uint32_t base, uint32_t size, const char *id)
|
||||
{
|
||||
char fn[13];
|
||||
char fn[13];
|
||||
FILE *f;
|
||||
|
||||
/* Output the range being dumped. */
|
||||
@@ -35,15 +34,15 @@ dump_range(uint32_t base, uint32_t size, const char *id)
|
||||
/* Open the dump file. */
|
||||
f = fopen(fn, "wb");
|
||||
if (!f) {
|
||||
printf("FAILURE\n");
|
||||
return 1;
|
||||
printf("FAILURE\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Write the dump. */
|
||||
if (fwrite((char *) base, 1, size, f) != size) {
|
||||
printf("FAILURE\n");
|
||||
fclose(f);
|
||||
return 2;
|
||||
printf("FAILURE\n");
|
||||
fclose(f);
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Finish the dump. */
|
||||
@@ -53,7 +52,6 @@ dump_range(uint32_t base, uint32_t size, const char *id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
#ifdef STANDARD_MAIN
|
||||
main(int argc, char *argv[])
|
||||
@@ -68,11 +66,11 @@ main(void)
|
||||
|
||||
/* Dump ranges. */
|
||||
if ((ret = dump_range(0x000c0000, 0x00040000, "low")))
|
||||
return ret;
|
||||
return ret;
|
||||
if ((ret = dump_range(0x00fe0000, 0x00020000, "mid")))
|
||||
return 2 + ret;
|
||||
return 2 + ret;
|
||||
if ((ret = dump_range(0xfff80000, 0x00080000, "high")))
|
||||
return 4 + ret;
|
||||
return 4 + ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
482
clib/clib.c
482
clib/clib.c
@@ -16,71 +16,66 @@
|
||||
*
|
||||
*/
|
||||
#ifdef __POSIX_UEFI__
|
||||
# include <uefi.h>
|
||||
# include <uefi.h>
|
||||
#else
|
||||
# include <inttypes.h>
|
||||
# include <stdint.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# ifdef __WATCOMC__
|
||||
# include <dos.h>
|
||||
# include <graph.h>
|
||||
# endif
|
||||
# include <inttypes.h>
|
||||
# include <stdint.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# ifdef __WATCOMC__
|
||||
# include <dos.h>
|
||||
# include <graph.h>
|
||||
# endif
|
||||
#endif
|
||||
#include "clib.h"
|
||||
|
||||
|
||||
uint8_t pci_mechanism = 0, pci_device_count = 0;
|
||||
uint8_t pci_mechanism = 0, pci_device_count = 0;
|
||||
|
||||
#ifdef __WATCOMC__
|
||||
static union REGPACK rp; /* things break if this is not a global variable... */
|
||||
#endif
|
||||
|
||||
|
||||
/* String functions. */
|
||||
int
|
||||
parse_hex_u8(char *val, uint8_t *dest)
|
||||
{
|
||||
uint32_t dest32;
|
||||
int ret = parse_hex_u32(val, &dest32);
|
||||
*dest = dest32;
|
||||
int ret = parse_hex_u32(val, &dest32);
|
||||
*dest = dest32;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
parse_hex_u16(char *val, uint16_t *dest)
|
||||
{
|
||||
uint32_t dest32;
|
||||
int ret = parse_hex_u32(val, &dest32);
|
||||
*dest = dest32;
|
||||
int ret = parse_hex_u32(val, &dest32);
|
||||
*dest = dest32;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
parse_hex_u32(char *val, uint32_t *dest)
|
||||
{
|
||||
int i, len = strlen(val);
|
||||
int i, len = strlen(val);
|
||||
uint8_t digit;
|
||||
|
||||
*dest = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if ((val[i] >= 0x30) && (val[i] <= 0x39))
|
||||
digit = val[i] - 0x30;
|
||||
else if ((val[i] >= 0x41) && (val[i] <= 0x46))
|
||||
digit = val[i] - 0x37;
|
||||
else if ((val[i] >= 0x61) && (val[i] <= 0x66))
|
||||
digit = val[i] - 0x57;
|
||||
else
|
||||
return 0;
|
||||
*dest = (*dest << 4) | digit;
|
||||
if ((val[i] >= 0x30) && (val[i] <= 0x39))
|
||||
digit = val[i] - 0x30;
|
||||
else if ((val[i] >= 0x41) && (val[i] <= 0x46))
|
||||
digit = val[i] - 0x37;
|
||||
else if ((val[i] >= 0x61) && (val[i] <= 0x66))
|
||||
digit = val[i] - 0x57;
|
||||
else
|
||||
return 0;
|
||||
*dest = (*dest << 4) | digit;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Comparator functions. */
|
||||
int
|
||||
comp_ui8(const void *elem1, const void *elem2)
|
||||
@@ -90,7 +85,6 @@ comp_ui8(const void *elem1, const void *elem2)
|
||||
return ((a < b) ? -1 : ((a > b) ? 1 : 0));
|
||||
}
|
||||
|
||||
|
||||
/* System functions. */
|
||||
#ifdef __WATCOMC__
|
||||
/* Defined in header. */
|
||||
@@ -101,7 +95,6 @@ cli()
|
||||
__asm__("cli");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sti()
|
||||
{
|
||||
@@ -113,14 +106,12 @@ cli()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sti()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Terminal functions. */
|
||||
#ifdef __WATCOMC__
|
||||
int
|
||||
@@ -131,7 +122,6 @@ term_get_size_x()
|
||||
return vc.numtextcols;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
term_get_size_y()
|
||||
{
|
||||
@@ -140,7 +130,6 @@ term_get_size_y()
|
||||
return vc.numtextrows;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
term_get_cursor_pos(uint8_t *x, uint8_t *y)
|
||||
{
|
||||
@@ -152,7 +141,6 @@ term_get_cursor_pos(uint8_t *x, uint8_t *y)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
term_set_cursor_pos(uint8_t x, uint8_t y)
|
||||
{
|
||||
@@ -163,14 +151,12 @@ term_set_cursor_pos(uint8_t x, uint8_t y)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
term_unbuffer_stdout()
|
||||
{
|
||||
setbuf(stdout, NULL);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
term_final_linebreak()
|
||||
{
|
||||
@@ -183,34 +169,29 @@ term_get_size_x()
|
||||
return 80;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
term_get_size_y()
|
||||
{
|
||||
return 25;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
term_get_cursor_pos(uint8_t *x, uint8_t *y)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
term_set_cursor_pos(uint8_t x, uint8_t y)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
term_unbuffer_stdout()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
term_final_linebreak()
|
||||
{
|
||||
@@ -218,7 +199,6 @@ term_final_linebreak()
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Port I/O functions. */
|
||||
#ifdef __WATCOMC__
|
||||
/* Defined in header. */
|
||||
@@ -227,47 +207,54 @@ uint8_t
|
||||
inb(uint16_t port)
|
||||
{
|
||||
uint8_t ret;
|
||||
__asm__ __volatile__("inb %1, %0" : "=a" (ret) : "Nd" (port));
|
||||
__asm__ __volatile__("inb %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(port));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
outb(uint16_t port, uint8_t val)
|
||||
{
|
||||
__asm__ __volatile__("outb %0, %1" : : "a" (val), "Nd" (port));
|
||||
__asm__ __volatile__("outb %0, %1"
|
||||
:
|
||||
: "a"(val), "Nd"(port));
|
||||
}
|
||||
|
||||
|
||||
uint16_t
|
||||
inw(uint16_t port)
|
||||
{
|
||||
uint16_t ret;
|
||||
__asm__ __volatile__("inw %1, %0" : "=a" (ret) : "Nd" (port));
|
||||
__asm__ __volatile__("inw %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(port));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
outw(uint16_t port, uint16_t val)
|
||||
{
|
||||
__asm__ __volatile__("outw %0, %1" : : "a" (val), "Nd" (port));
|
||||
__asm__ __volatile__("outw %0, %1"
|
||||
:
|
||||
: "a"(val), "Nd"(port));
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
inl(uint16_t port)
|
||||
{
|
||||
uint32_t ret;
|
||||
__asm__ __volatile__("inl %1, %0" : "=a" (ret) : "Nd" (port));
|
||||
__asm__ __volatile__("inl %1, %0"
|
||||
: "=a"(ret)
|
||||
: "Nd"(port));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
outl(uint16_t port, uint32_t val)
|
||||
{
|
||||
__asm__ __volatile__("outl %0, %1" : : "a" (val), "Nd" (port));
|
||||
__asm__ __volatile__("outl %0, %1"
|
||||
:
|
||||
: "a"(val), "Nd"(port));
|
||||
}
|
||||
#else
|
||||
uint8_t
|
||||
@@ -276,71 +263,63 @@ inb(uint16_t port)
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
outb(uint16_t port, uint8_t val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
uint16_t
|
||||
inw(uint16_t port)
|
||||
{
|
||||
return 0xffff;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
outw(uint16_t port, uint16_t val)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
inl(uint16_t port)
|
||||
{
|
||||
return 0xffffffff;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
outl(uint16_t port, uint32_t val)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
uint16_t
|
||||
io_find_range(uint16_t size)
|
||||
{
|
||||
uint16_t base;
|
||||
|
||||
for (base = 0x1000; base >= 0x1000; base += size) {
|
||||
/* Test first and last words only, as poking through the entire space
|
||||
can lead to trouble (VIA ACPI has magic reads that hang the CPU). */
|
||||
if ((inw(base) == 0xffff) && (inw(base + size - 2) == 0xffff))
|
||||
return base;
|
||||
/* Test first and last words only, as poking through the entire space
|
||||
can lead to trouble (VIA ACPI has magic reads that hang the CPU). */
|
||||
if ((inw(base) == 0xffff) && (inw(base + size - 2) == 0xffff))
|
||||
return base;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* PCI functions. */
|
||||
uint32_t
|
||||
pci_cf8(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
|
||||
{
|
||||
/* Generate a PCI port CF8h dword. */
|
||||
multi_t ret;
|
||||
ret.u8[3] = 0x80;
|
||||
ret.u8[2] = bus;
|
||||
ret.u8[1] = dev << 3;
|
||||
ret.u8[3] = 0x80;
|
||||
ret.u8[2] = bus;
|
||||
ret.u8[1] = dev << 3;
|
||||
ret.u8[1] |= func & 7;
|
||||
ret.u8[0] = reg & 0xfc;
|
||||
ret.u8[0] = reg & 0xfc;
|
||||
return ret.u32;
|
||||
}
|
||||
|
||||
|
||||
uint16_t
|
||||
pci_get_io_bar(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint16_t size, const char *name)
|
||||
{
|
||||
@@ -351,41 +330,40 @@ pci_get_io_bar(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint16_t siz
|
||||
/* Read BAR register. */
|
||||
ret = pci_readw(bus, dev, func, reg);
|
||||
if (!(ret & 0x0001) || (ret == 0xffff)) {
|
||||
temp = pci_readw(bus, dev, func, reg | 0x2);
|
||||
printf("invalid! (%04X%04X)", temp, ret);
|
||||
ret = 0;
|
||||
temp = pci_readw(bus, dev, func, reg | 0x2);
|
||||
printf("invalid! (%04X%04X)", temp, ret);
|
||||
ret = 0;
|
||||
} else {
|
||||
/* Assign BAR if unassigned. */
|
||||
ret &= ~(size - 1);
|
||||
if (ret) {
|
||||
printf("assigned to %04X", ret);
|
||||
} else {
|
||||
printf("unassigned ");
|
||||
/* Assign BAR if unassigned. */
|
||||
ret &= ~(size - 1);
|
||||
if (ret) {
|
||||
printf("assigned to %04X", ret);
|
||||
} else {
|
||||
printf("unassigned ");
|
||||
|
||||
/* Find I/O range for the BAR. */
|
||||
ret = io_find_range(size);
|
||||
if (ret) {
|
||||
/* Assign and check value. */
|
||||
pci_writew(bus, dev, func, reg, ret | 0x0001);
|
||||
temp = pci_readw(bus, dev, func, reg);
|
||||
if ((temp & ~(size - 1)) == ret) {
|
||||
printf("(assigning to %04X)", ret);
|
||||
} else {
|
||||
ret = pci_readw(bus, dev, func, reg | 0x2);
|
||||
printf("and not responding! (%04X%04X)", ret, temp);
|
||||
ret = 0;
|
||||
}
|
||||
} else {
|
||||
printf("and no suitable range was found!");
|
||||
}
|
||||
}
|
||||
/* Find I/O range for the BAR. */
|
||||
ret = io_find_range(size);
|
||||
if (ret) {
|
||||
/* Assign and check value. */
|
||||
pci_writew(bus, dev, func, reg, ret | 0x0001);
|
||||
temp = pci_readw(bus, dev, func, reg);
|
||||
if ((temp & ~(size - 1)) == ret) {
|
||||
printf("(assigning to %04X)", ret);
|
||||
} else {
|
||||
ret = pci_readw(bus, dev, func, reg | 0x2);
|
||||
printf("and not responding! (%04X%04X)", ret, temp);
|
||||
ret = 0;
|
||||
}
|
||||
} else {
|
||||
printf("and no suitable range was found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#ifdef IS_32BIT
|
||||
uint32_t
|
||||
pci_get_mem_bar(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t size, const char *name)
|
||||
@@ -397,15 +375,15 @@ pci_get_mem_bar(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t si
|
||||
/* Read BAR register. */
|
||||
ret = pci_readl(bus, dev, func, reg);
|
||||
if ((ret & 0x00000001) || (ret == 0xffffffff)) {
|
||||
printf("invalid! (%08X)", ret);
|
||||
ret = 0;
|
||||
printf("invalid! (%08X)", ret);
|
||||
ret = 0;
|
||||
} else {
|
||||
/* Don't even try to find a valid memory range if the BAR is unassigned. */
|
||||
ret &= ~(size - 1);
|
||||
if (ret)
|
||||
printf("assigned to %08X", ret);
|
||||
else
|
||||
printf("unassigned!");
|
||||
/* Don't even try to find a valid memory range if the BAR is unassigned. */
|
||||
ret &= ~(size - 1);
|
||||
if (ret)
|
||||
printf("assigned to %08X", ret);
|
||||
else
|
||||
printf("unassigned!");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
@@ -413,7 +391,6 @@ pci_get_mem_bar(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t si
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int
|
||||
pci_init()
|
||||
{
|
||||
@@ -425,55 +402,53 @@ pci_init()
|
||||
outl(0xcf8, cf8.u32);
|
||||
cf8.u32 = inl(0xcf8);
|
||||
if (cf8.u32 == 0x80001234) {
|
||||
pci_mechanism = 1;
|
||||
pci_device_count = 32;
|
||||
pci_mechanism = 1;
|
||||
pci_device_count = 32;
|
||||
} else {
|
||||
outb(0xcf8, 0x00);
|
||||
outb(0xcfa, 0x00);
|
||||
if ((inb(0xcf8) == 0x00) && (inb(0xcfa) == 0x00)) {
|
||||
pci_mechanism = 2;
|
||||
pci_device_count = 16;
|
||||
}
|
||||
outb(0xcf8, 0x00);
|
||||
outb(0xcfa, 0x00);
|
||||
if ((inb(0xcf8) == 0x00) && (inb(0xcfa) == 0x00)) {
|
||||
pci_mechanism = 2;
|
||||
pci_device_count = 16;
|
||||
}
|
||||
}
|
||||
sti();
|
||||
if (pci_mechanism == 0)
|
||||
printf("Failed to probe PCI configuration mechanism (%04X%04X). Is this a PCI system?\n", cf8.u16[1], cf8.u16[0]);
|
||||
printf("Failed to probe PCI configuration mechanism (%04X%04X). Is this a PCI system?\n", cf8.u16[1], cf8.u16[0]);
|
||||
|
||||
return pci_mechanism;
|
||||
}
|
||||
|
||||
|
||||
uint8_t
|
||||
pci_readb(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
|
||||
{
|
||||
uint8_t ret;
|
||||
uint8_t ret;
|
||||
uint16_t data_port;
|
||||
uint32_t cf8;
|
||||
|
||||
switch (pci_mechanism) {
|
||||
case 1:
|
||||
data_port = 0xcfc | (reg & 0x03);
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
ret = inb(data_port);
|
||||
sti();
|
||||
break;
|
||||
case 1:
|
||||
data_port = 0xcfc | (reg & 0x03);
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
ret = inb(data_port);
|
||||
sti();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
cf8 = pci_readl(bus, dev, func, reg);
|
||||
ret = cf8 >> ((reg & 0x03) << 3);
|
||||
break;
|
||||
case 2:
|
||||
cf8 = pci_readl(bus, dev, func, reg);
|
||||
ret = cf8 >> ((reg & 0x03) << 3);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = 0xff;
|
||||
break;
|
||||
default:
|
||||
ret = 0xff;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint16_t
|
||||
pci_readw(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
|
||||
{
|
||||
@@ -481,29 +456,28 @@ pci_readw(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
|
||||
uint32_t cf8;
|
||||
|
||||
switch (pci_mechanism) {
|
||||
case 1:
|
||||
data_port = 0xcfc | (reg & 0x02);
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
ret = inw(data_port);
|
||||
sti();
|
||||
break;
|
||||
case 1:
|
||||
data_port = 0xcfc | (reg & 0x02);
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
ret = inw(data_port);
|
||||
sti();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
cf8 = pci_readl(bus, dev, func, reg);
|
||||
ret = cf8 >> ((reg & 0x02) << 3);
|
||||
break;
|
||||
case 2:
|
||||
cf8 = pci_readl(bus, dev, func, reg);
|
||||
ret = cf8 >> ((reg & 0x02) << 3);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = 0xffff;
|
||||
break;
|
||||
default:
|
||||
ret = 0xffff;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
pci_readl(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
|
||||
{
|
||||
@@ -511,89 +485,86 @@ pci_readl(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg)
|
||||
uint32_t ret, cf8;
|
||||
|
||||
switch (pci_mechanism) {
|
||||
case 1:
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
ret = inl(0xcfc);
|
||||
sti();
|
||||
break;
|
||||
case 1:
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
ret = inl(0xcfc);
|
||||
sti();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
func = 0x80 | (func << 1);
|
||||
data_port = 0xc000 | (dev << 8) | (reg & 0xfc);
|
||||
cli();
|
||||
outb(0xcf8, func);
|
||||
outb(0xcfa, bus);
|
||||
ret = inl(data_port);
|
||||
sti();
|
||||
break;
|
||||
case 2:
|
||||
func = 0x80 | (func << 1);
|
||||
data_port = 0xc000 | (dev << 8) | (reg & 0xfc);
|
||||
cli();
|
||||
outb(0xcf8, func);
|
||||
outb(0xcfa, bus);
|
||||
ret = inl(data_port);
|
||||
sti();
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = 0xffffffff;
|
||||
break;
|
||||
default:
|
||||
ret = 0xffffffff;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
pci_writeb(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint8_t val)
|
||||
{
|
||||
uint8_t shift;
|
||||
uint8_t shift;
|
||||
uint16_t data_port;
|
||||
uint32_t cf8;
|
||||
|
||||
switch (pci_mechanism) {
|
||||
case 1:
|
||||
data_port = 0xcfc | (reg & 0x03);
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
outb(data_port, val);
|
||||
sti();
|
||||
break;
|
||||
case 1:
|
||||
data_port = 0xcfc | (reg & 0x03);
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
outb(data_port, val);
|
||||
sti();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
cf8 = pci_readl(bus, dev, func, reg);
|
||||
shift = (reg & 0x03) << 3;
|
||||
cf8 &= ~(0x000000ff << shift);
|
||||
cf8 |= val << shift;
|
||||
pci_writel(bus, dev, func, reg, cf8);
|
||||
break;
|
||||
case 2:
|
||||
cf8 = pci_readl(bus, dev, func, reg);
|
||||
shift = (reg & 0x03) << 3;
|
||||
cf8 &= ~(0x000000ff << shift);
|
||||
cf8 |= val << shift;
|
||||
pci_writel(bus, dev, func, reg, cf8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
pci_writew(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint16_t val)
|
||||
{
|
||||
uint8_t shift;
|
||||
uint8_t shift;
|
||||
uint16_t data_port;
|
||||
uint32_t cf8;
|
||||
|
||||
switch (pci_mechanism) {
|
||||
case 1:
|
||||
data_port = 0xcfc | (reg & 0x02);
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
outw(data_port, val);
|
||||
sti();
|
||||
break;
|
||||
case 1:
|
||||
data_port = 0xcfc | (reg & 0x02);
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
outw(data_port, val);
|
||||
sti();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
cf8 = pci_readl(bus, dev, func, reg);
|
||||
shift = (reg & 0x02) << 3;
|
||||
cf8 &= ~(0x0000ffff << shift);
|
||||
cf8 |= val << shift;
|
||||
pci_writel(bus, dev, func, reg, cf8);
|
||||
break;
|
||||
case 2:
|
||||
cf8 = pci_readl(bus, dev, func, reg);
|
||||
shift = (reg & 0x02) << 3;
|
||||
cf8 &= ~(0x0000ffff << shift);
|
||||
cf8 |= val << shift;
|
||||
pci_writel(bus, dev, func, reg, cf8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
pci_writel(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t val)
|
||||
{
|
||||
@@ -601,82 +572,81 @@ pci_writel(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t val)
|
||||
uint32_t cf8;
|
||||
|
||||
switch (pci_mechanism) {
|
||||
case 1:
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
outl(0xcfc, val);
|
||||
sti();
|
||||
break;
|
||||
case 1:
|
||||
cf8 = pci_cf8(bus, dev, func, reg);
|
||||
cli();
|
||||
outl(0xcf8, cf8);
|
||||
outl(0xcfc, val);
|
||||
sti();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
func = 0x80 | (func << 1);
|
||||
data_port = 0xc000 | (dev << 8) | (reg & 0xfc);
|
||||
cli();
|
||||
outb(0xcf8, func);
|
||||
outb(0xcfa, bus);
|
||||
outl(data_port, val);
|
||||
sti();
|
||||
break;
|
||||
case 2:
|
||||
func = 0x80 | (func << 1);
|
||||
data_port = 0xc000 | (dev << 8) | (reg & 0xfc);
|
||||
cli();
|
||||
outb(0xcf8, func);
|
||||
outb(0xcfa, bus);
|
||||
outl(data_port, val);
|
||||
sti();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
pci_scan_bus(uint8_t bus,
|
||||
void (*callback)(uint8_t bus, uint8_t dev, uint8_t func,
|
||||
uint16_t ven_id, uint16_t dev_id))
|
||||
void (*callback)(uint8_t bus, uint8_t dev, uint8_t func,
|
||||
uint16_t ven_id, uint16_t dev_id))
|
||||
{
|
||||
uint8_t dev, func, header_type;
|
||||
multi_t dev_id;
|
||||
|
||||
/* Iterate through devices. */
|
||||
for (dev = 0; dev < pci_device_count; dev++) {
|
||||
/* Iterate through functions. */
|
||||
for (func = 0; func < 8; func++) {
|
||||
/* Read vendor/device ID. */
|
||||
/* Iterate through functions. */
|
||||
for (func = 0; func < 8; func++) {
|
||||
/* Read vendor/device ID. */
|
||||
#ifdef DEBUG
|
||||
if ((bus < DEBUG) && (dev <= bus) && (func == 0)) {
|
||||
dev_id.u16[0] = rand();
|
||||
dev_id.u16[1] = rand();
|
||||
} else {
|
||||
dev_id.u32 = 0xffffffff;
|
||||
}
|
||||
if ((bus < DEBUG) && (dev <= bus) && (func == 0)) {
|
||||
dev_id.u16[0] = rand();
|
||||
dev_id.u16[1] = rand();
|
||||
} else {
|
||||
dev_id.u32 = 0xffffffff;
|
||||
}
|
||||
#else
|
||||
dev_id.u32 = pci_readl(bus, dev, func, 0x00);
|
||||
dev_id.u32 = pci_readl(bus, dev, func, 0x00);
|
||||
#endif
|
||||
|
||||
/* Callback if this is a valid ID. */
|
||||
if (dev_id.u32 && (dev_id.u32 != 0xffffffff)) {
|
||||
callback(bus, dev, func, dev_id.u16[0], dev_id.u16[1]);
|
||||
} else {
|
||||
/* Stop or move on to the next function if there's nothing here. */
|
||||
if (func)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
/* Callback if this is a valid ID. */
|
||||
if (dev_id.u32 && (dev_id.u32 != 0xffffffff)) {
|
||||
callback(bus, dev, func, dev_id.u16[0], dev_id.u16[1]);
|
||||
} else {
|
||||
/* Stop or move on to the next function if there's nothing here. */
|
||||
if (func)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read header type. */
|
||||
/* Read header type. */
|
||||
#ifdef DEBUG
|
||||
header_type = (bus < (DEBUG - 1)) ? 0x01 : 0x00;
|
||||
header_type = (bus < (DEBUG - 1)) ? 0x01 : 0x00;
|
||||
#else
|
||||
header_type = pci_readb(bus, dev, func, 0x0e);
|
||||
header_type = pci_readb(bus, dev, func, 0x0e);
|
||||
#endif
|
||||
|
||||
/* If this is a bridge, mark that we should probe its bus. */
|
||||
if (header_type & 0x7f) {
|
||||
/* Scan the secondary bus. */
|
||||
/* If this is a bridge, mark that we should probe its bus. */
|
||||
if (header_type & 0x7f) {
|
||||
/* Scan the secondary bus. */
|
||||
#ifdef DEBUG
|
||||
pci_scan_bus(bus + 1, callback);
|
||||
pci_scan_bus(bus + 1, callback);
|
||||
#else
|
||||
pci_scan_bus(pci_readb(bus, dev, func, 0x19), callback);
|
||||
pci_scan_bus(pci_readb(bus, dev, func, 0x19), callback);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* If we're at the first function, stop if this is not a multi-function device. */
|
||||
if ((func == 0) && !(header_type & 0x80))
|
||||
break;
|
||||
}
|
||||
/* If we're at the first function, stop if this is not a multi-function device. */
|
||||
if ((func == 0) && !(header_type & 0x80))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
152
clib/clib.h
152
clib/clib.h
@@ -16,129 +16,125 @@
|
||||
*
|
||||
*/
|
||||
#ifndef CLIB_H
|
||||
# define CLIB_H
|
||||
#define CLIB_H
|
||||
|
||||
/* Common macros. */
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define ABS(x) ((x) > 0 ? (x) : -(x))
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define ABS(x) ((x) > 0 ? (x) : -(x))
|
||||
|
||||
/* Compiler compatibility macros. */
|
||||
#ifdef __GNUC__
|
||||
# define PACKED __attribute__((packed))
|
||||
# define PACKED __attribute__((packed))
|
||||
#else
|
||||
# define PACKED
|
||||
# define PACKED
|
||||
#endif
|
||||
|
||||
/* Platform-specific macros. */
|
||||
#ifndef __POSIX_UEFI__
|
||||
# define FMT_FLOAT_SUPPORTED 1
|
||||
# define FMT_FLOAT_SUPPORTED 1
|
||||
#endif
|
||||
#if !defined(__WATCOMC__) || defined(M_I386)
|
||||
# define IS_32BIT 1
|
||||
# define IS_32BIT 1
|
||||
#endif
|
||||
|
||||
|
||||
#pragma pack(push, 0)
|
||||
/* Convenience type for breaking a dword value down into words and bytes. */
|
||||
typedef union {
|
||||
uint8_t u8[4];
|
||||
uint8_t u8[4];
|
||||
uint16_t u16[2];
|
||||
uint32_t u32;
|
||||
} multi_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
/* Global variables. */
|
||||
extern uint8_t pci_mechanism, pci_device_count;
|
||||
|
||||
extern uint8_t pci_mechanism, pci_device_count;
|
||||
|
||||
/* String functions. */
|
||||
extern int parse_hex_u8(char *val, uint8_t *dest);
|
||||
extern int parse_hex_u16(char *val, uint16_t *dest);
|
||||
extern int parse_hex_u32(char *val, uint32_t *dest);
|
||||
extern int parse_hex_u8(char *val, uint8_t *dest);
|
||||
extern int parse_hex_u16(char *val, uint16_t *dest);
|
||||
extern int parse_hex_u32(char *val, uint32_t *dest);
|
||||
|
||||
/* Comparator functions. */
|
||||
extern int comp_ui8(const void *elem1, const void *elem2);
|
||||
extern int comp_ui8(const void *elem1, const void *elem2);
|
||||
|
||||
/* System functions. */
|
||||
#ifdef __WATCOMC__
|
||||
void cli();
|
||||
# pragma aux cli = "cli";
|
||||
void sti();
|
||||
# pragma aux sti = "sti";
|
||||
void cli();
|
||||
# pragma aux cli = "cli";
|
||||
void sti();
|
||||
# pragma aux sti = "sti";
|
||||
#else
|
||||
extern void cli();
|
||||
extern void sti();
|
||||
extern void cli();
|
||||
extern void sti();
|
||||
#endif
|
||||
|
||||
/* Terminal functions. */
|
||||
extern int term_get_size_x();
|
||||
extern int term_get_size_y();
|
||||
extern int term_get_cursor_pos(uint8_t *x, uint8_t *y);
|
||||
extern int term_set_cursor_pos(uint8_t x, uint8_t y);
|
||||
extern void term_unbuffer_stdout();
|
||||
extern void term_final_linebreak();
|
||||
extern int term_get_size_x();
|
||||
extern int term_get_size_y();
|
||||
extern int term_get_cursor_pos(uint8_t *x, uint8_t *y);
|
||||
extern int term_set_cursor_pos(uint8_t x, uint8_t y);
|
||||
extern void term_unbuffer_stdout();
|
||||
extern void term_final_linebreak();
|
||||
|
||||
/* Port I/O functions. */
|
||||
#ifdef __WATCOMC__
|
||||
uint8_t inb(uint16_t port);
|
||||
# pragma aux inb = "in al, dx" parm [dx] value [al];
|
||||
void outb(uint16_t port, uint8_t data);
|
||||
# pragma aux outb = "out dx, al" parm [dx] [al];
|
||||
uint16_t inw(uint16_t port);
|
||||
# pragma aux inw = "in ax, dx" parm [dx] value [ax];
|
||||
void outw(uint16_t port, uint16_t data);
|
||||
# pragma aux outw = "out dx, ax" parm [dx] [ax];
|
||||
# ifdef M_I386
|
||||
uint32_t inl(uint16_t port);
|
||||
# pragma aux inl = "in eax, dx" parm [dx] value [eax];
|
||||
void outl(uint16_t port, uint32_t data);
|
||||
# pragma aux outl = "out dx, eax" parm [dx] [eax];
|
||||
# else
|
||||
uint8_t inb(uint16_t port);
|
||||
# pragma aux inb = "in al, dx" parm[dx] value[al];
|
||||
void outb(uint16_t port, uint8_t data);
|
||||
# pragma aux outb = "out dx, al" parm[dx][al];
|
||||
uint16_t inw(uint16_t port);
|
||||
# pragma aux inw = "in ax, dx" parm[dx] value[ax];
|
||||
void outw(uint16_t port, uint16_t data);
|
||||
# pragma aux outw = "out dx, ax" parm[dx][ax];
|
||||
# ifdef M_I386
|
||||
uint32_t inl(uint16_t port);
|
||||
# pragma aux inl = "in eax, dx" parm[dx] value[eax];
|
||||
void outl(uint16_t port, uint32_t data);
|
||||
# pragma aux outl = "out dx, eax" parm[dx][eax];
|
||||
# else
|
||||
/* Some manual prefixing trickery to perform 32-bit I/O and access
|
||||
the extended part of EAX in real mode. Exchanging is necessary
|
||||
due to Watcom ignoring the order registers are specified in... */
|
||||
uint32_t inl(uint16_t port);
|
||||
# pragma aux inl = "db 0x66" "in ax, dx" /* in eax, dx */ \
|
||||
"mov cx, ax" \
|
||||
"db 0x66, 0xc1, 0xe8, 0x10" /* shr eax, 16 */ \
|
||||
"xchg ax, cx" \
|
||||
parm [dx] \
|
||||
value [ax cx];
|
||||
void outl(uint16_t port, uint32_t data);
|
||||
# pragma aux outl = "xchg ax, cx" \
|
||||
"db 0x66, 0xc1, 0xe0, 0x10" /* shl eax, 16 */ \
|
||||
"mov ax, cx" \
|
||||
"db 0x66" "out dx, ax" /* out dx, eax */ \
|
||||
parm [dx] [ax cx] \
|
||||
modify [ax cx];
|
||||
# endif
|
||||
uint32_t inl(uint16_t port);
|
||||
# pragma aux inl = "db 0x66" \
|
||||
"in ax, dx" /* in eax, dx */ \
|
||||
"mov cx, ax" \
|
||||
"db 0x66, 0xc1, 0xe8, 0x10" /* shr eax, 16 */ \
|
||||
"xchg ax, cx" parm[dx] value[ax cx];
|
||||
void outl(uint16_t port, uint32_t data);
|
||||
# pragma aux outl = "xchg ax, cx" \
|
||||
"db 0x66, 0xc1, 0xe0, 0x10" /* shl eax, 16 */ \
|
||||
"mov ax, cx" \
|
||||
"db 0x66" \
|
||||
"out dx, ax" /* out dx, eax */ \
|
||||
parm[dx][ax cx] modify[ax cx];
|
||||
# endif
|
||||
#else
|
||||
extern uint8_t inb(uint16_t port);
|
||||
extern void outb(uint16_t port, uint8_t data);
|
||||
extern uint16_t inw(uint16_t port);
|
||||
extern void outw(uint16_t port, uint16_t data);
|
||||
extern uint32_t inl(uint16_t port);
|
||||
extern void outl(uint16_t port, uint32_t data);
|
||||
extern uint8_t inb(uint16_t port);
|
||||
extern void outb(uint16_t port, uint8_t data);
|
||||
extern uint16_t inw(uint16_t port);
|
||||
extern void outw(uint16_t port, uint16_t data);
|
||||
extern uint32_t inl(uint16_t port);
|
||||
extern void outl(uint16_t port, uint32_t data);
|
||||
#endif
|
||||
extern uint16_t io_find_range(uint16_t size);
|
||||
extern uint16_t io_find_range(uint16_t size);
|
||||
|
||||
/* PCI functions. */
|
||||
extern uint32_t pci_cf8(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg);
|
||||
extern uint16_t pci_get_io_bar(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint16_t size, const char *name);
|
||||
extern uint32_t pci_cf8(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg);
|
||||
extern uint16_t pci_get_io_bar(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint16_t size, const char *name);
|
||||
#ifdef IS_32BIT
|
||||
extern uint32_t pci_get_mem_bar(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t size, const char *name);
|
||||
extern uint32_t pci_get_mem_bar(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t size, const char *name);
|
||||
#endif
|
||||
extern int pci_init();
|
||||
extern uint8_t pci_readb(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg);
|
||||
extern uint16_t pci_readw(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg);
|
||||
extern uint32_t pci_readl(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg);
|
||||
extern void pci_writeb(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint8_t val);
|
||||
extern void pci_writew(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint16_t val);
|
||||
extern void pci_writel(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t val);
|
||||
extern void pci_scan_bus(uint8_t bus,
|
||||
void (*callback)(uint8_t bus, uint8_t dev, uint8_t func,
|
||||
uint16_t ven_id, uint16_t dev_id));
|
||||
extern int pci_init();
|
||||
extern uint8_t pci_readb(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg);
|
||||
extern uint16_t pci_readw(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg);
|
||||
extern uint32_t pci_readl(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg);
|
||||
extern void pci_writeb(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint8_t val);
|
||||
extern void pci_writew(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint16_t val);
|
||||
extern void pci_writel(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, uint32_t val);
|
||||
extern void pci_scan_bus(uint8_t bus,
|
||||
void (*callback)(uint8_t bus, uint8_t dev, uint8_t func,
|
||||
uint16_t ven_id, uint16_t dev_id));
|
||||
|
||||
#endif
|
||||
|
||||
130
cp437/cp437.c
130
cp437/cp437.c
@@ -18,33 +18,31 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/* This is the text renderer's CP437 character conversion table,
|
||||
with 09, 0A and 0D modified for text processing purposes. */
|
||||
static const char *cp437[] = {
|
||||
/* 00 */ " ", "\xE2\x98\xBA", "\xE2\x98\xBB", "\xE2\x99\xA5", "\xE2\x99\xA6", "\xE2\x99\xA3", "\xE2\x99\xA0", "\xE2\x80\xA2", "\xE2\x97\x98", "\t", "\n", "\xE2\x99\x82", "\xE2\x99\x80", "\r", "\xE2\x99\xAB", "\xE2\x98\xBC",
|
||||
/* 10 */ "\xE2\x96\xBA", "\xE2\x97\x84", "\xE2\x86\x95", "\xE2\x80\xBC", "\xC2\xB6", "\xC2\xA7", "\xE2\x96\xAC", "\xE2\x86\xA8", "\xE2\x86\x91", "\xE2\x86\x93", "\xE2\x86\x92", "\xE2\x86\x90", "\xE2\x88\x9F", "\xE2\x86\x94", "\xE2\x96\xB2", "\xE2\x96\xBC",
|
||||
/* 20 */ " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
|
||||
/* 30 */ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?",
|
||||
/* 40 */ "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
|
||||
/* 50 */ "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_",
|
||||
/* 60 */ "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
|
||||
/* 70 */ "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "\xE2\x8C\x82",
|
||||
/* 80 */ "\xC3\x87", "\xC3\xBC", "\xC3\xA9", "\xC3\xA2", "\xC3\xA4", "\xC3\xA0", "\xC3\xA5", "\xC3\xA7", "\xC3\xAA", "\xC3\xAB", "\xC3\xA8", "\xC3\xAF", "\xC3\xAE", "\xC3\xAC", "\xC3\x84", "\xC3\x85",
|
||||
/* 90 */ "\xC3\x89", "\xC3\xA6", "\xC3\x86", "\xC3\xB4", "\xC3\xB6", "\xC3\xB2", "\xC3\xBB", "\xC3\xB9", "\xC3\xBF", "\xC3\x96", "\xC3\x9C", "\xC2\xA2", "\xC2\xA3", "\xC2\xA5", "\xE2\x82\xA7", "\xC6\x92",
|
||||
/* A0 */ "\xC3\xA1", "\xC3\xAD", "\xC3\xB3", "\xC3\xBA", "\xC3\xB1", "\xC3\x91", "\xC2\xAA", "\xC2\xBA", "\xC2\xBF", "\xE2\x8C\x90", "\xC2\xAC", "\xC2\xBD", "\xC2\xBC", "\xC2\xA1", "\xC2\xAB", "\xC2\xBB",
|
||||
/* 00 */ " ", "\xE2\x98\xBA", "\xE2\x98\xBB", "\xE2\x99\xA5", "\xE2\x99\xA6", "\xE2\x99\xA3", "\xE2\x99\xA0", "\xE2\x80\xA2", "\xE2\x97\x98", "\t", "\n", "\xE2\x99\x82", "\xE2\x99\x80", "\r", "\xE2\x99\xAB", "\xE2\x98\xBC",
|
||||
/* 10 */ "\xE2\x96\xBA", "\xE2\x97\x84", "\xE2\x86\x95", "\xE2\x80\xBC", "\xC2\xB6", "\xC2\xA7", "\xE2\x96\xAC", "\xE2\x86\xA8", "\xE2\x86\x91", "\xE2\x86\x93", "\xE2\x86\x92", "\xE2\x86\x90", "\xE2\x88\x9F", "\xE2\x86\x94", "\xE2\x96\xB2", "\xE2\x96\xBC",
|
||||
/* 20 */ " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
|
||||
/* 30 */ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?",
|
||||
/* 40 */ "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O",
|
||||
/* 50 */ "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_",
|
||||
/* 60 */ "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
|
||||
/* 70 */ "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "\xE2\x8C\x82",
|
||||
/* 80 */ "\xC3\x87", "\xC3\xBC", "\xC3\xA9", "\xC3\xA2", "\xC3\xA4", "\xC3\xA0", "\xC3\xA5", "\xC3\xA7", "\xC3\xAA", "\xC3\xAB", "\xC3\xA8", "\xC3\xAF", "\xC3\xAE", "\xC3\xAC", "\xC3\x84", "\xC3\x85",
|
||||
/* 90 */ "\xC3\x89", "\xC3\xA6", "\xC3\x86", "\xC3\xB4", "\xC3\xB6", "\xC3\xB2", "\xC3\xBB", "\xC3\xB9", "\xC3\xBF", "\xC3\x96", "\xC3\x9C", "\xC2\xA2", "\xC2\xA3", "\xC2\xA5", "\xE2\x82\xA7", "\xC6\x92",
|
||||
/* A0 */ "\xC3\xA1", "\xC3\xAD", "\xC3\xB3", "\xC3\xBA", "\xC3\xB1", "\xC3\x91", "\xC2\xAA", "\xC2\xBA", "\xC2\xBF", "\xE2\x8C\x90", "\xC2\xAC", "\xC2\xBD", "\xC2\xBC", "\xC2\xA1", "\xC2\xAB", "\xC2\xBB",
|
||||
/* B0 */ "\xE2\x96\x91", "\xE2\x96\x92", "\xE2\x96\x93", "\xE2\x94\x82", "\xE2\x94\xA4", "\xE2\x95\xA1", "\xE2\x95\xA2", "\xE2\x95\x96", "\xE2\x95\x95", "\xE2\x95\xA3", "\xE2\x95\x91", "\xE2\x95\x97", "\xE2\x95\x9D", "\xE2\x95\x9C", "\xE2\x95\x9B", "\xE2\x94\x90",
|
||||
/* C0 */ "\xE2\x94\x94", "\xE2\x94\xB4", "\xE2\x94\xAC", "\xE2\x94\x9C", "\xE2\x94\x80", "\xE2\x94\xBC", "\xE2\x95\x9E", "\xE2\x95\x9F", "\xE2\x95\x9A", "\xE2\x95\x94", "\xE2\x95\xA9", "\xE2\x95\xA6", "\xE2\x95\xA0", "\xE2\x95\x90", "\xE2\x95\xAC", "\xE2\x95\xA7",
|
||||
/* D0 */ "\xE2\x95\xA8", "\xE2\x95\xA4", "\xE2\x95\xA5", "\xE2\x95\x99", "\xE2\x95\x98", "\xE2\x95\x92", "\xE2\x95\x93", "\xE2\x95\xAB", "\xE2\x95\xAA", "\xE2\x94\x98", "\xE2\x94\x8C", "\xE2\x96\x88", "\xE2\x96\x84", "\xE2\x96\x8C", "\xE2\x96\x90", "\xE2\x96\x80",
|
||||
/* E0 */ "\xCE\xB1", "\xC3\x9F", "\xCE\x93", "\xCF\x80", "\xCE\xA3", "\xCF\x83", "\xC2\xB5", "\xCF\x84", "\xCE\xA6", "\xCE\x98", "\xCE\xA9", "\xCE\xB4", "\xE2\x88\x9E", "\xCF\x86", "\xCE\xB5", "\xE2\x88\xA9",
|
||||
/* F0 */ "\xE2\x89\xA1", "\xC2\xB1", "\xE2\x89\xA5", "\xE2\x89\xA4", "\xE2\x8C\xA0", "\xE2\x8C\xA1", "\xC3\xB7", "\xE2\x89\x88", "\xC2\xB0", "\xE2\x88\x99", "\xC2\xB7", "\xE2\x88\x9A", "\xE2\x81\xBF", "\xC2\xB2", "\xE2\x96\xA0", "\xC2\xA0"
|
||||
/* E0 */ "\xCE\xB1", "\xC3\x9F", "\xCE\x93", "\xCF\x80", "\xCE\xA3", "\xCF\x83", "\xC2\xB5", "\xCF\x84", "\xCE\xA6", "\xCE\x98", "\xCE\xA9", "\xCE\xB4", "\xE2\x88\x9E", "\xCF\x86", "\xCE\xB5", "\xE2\x88\xA9",
|
||||
/* F0 */ "\xE2\x89\xA1", "\xC2\xB1", "\xE2\x89\xA5", "\xE2\x89\xA4", "\xE2\x8C\xA0", "\xE2\x8C\xA1", "\xC3\xB7", "\xE2\x89\x88", "\xC2\xB0", "\xE2\x88\x99", "\xC2\xB7", "\xE2\x88\x9A", "\xE2\x81\xBF", "\xC2\xB2", "\xE2\x96\xA0", "\xC2\xA0"
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i, j, success;
|
||||
int i, j, success;
|
||||
char *buf;
|
||||
FILE *fin, *fout;
|
||||
|
||||
@@ -54,71 +52,71 @@ main(int argc, char **argv)
|
||||
|
||||
/* Print usage if no input files were specified. */
|
||||
if (argc < 2) {
|
||||
printf("Usage:\n");
|
||||
printf("\n");
|
||||
printf("%s infile [infile...]\n", argv[0]);
|
||||
printf("- Converts UTF-8 input file(s) to CP437 output file(s) with .cp437 appended.\n");
|
||||
printf(" The new file names are also printed to stdout.\n");
|
||||
return 1;
|
||||
printf("Usage:\n");
|
||||
printf("\n");
|
||||
printf("%s infile [infile...]\n", argv[0]);
|
||||
printf("- Converts UTF-8 input file(s) to CP437 output file(s) with .cp437 appended.\n");
|
||||
printf(" The new file names are also printed to stdout.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Process input files. */
|
||||
success = 0;
|
||||
for (i = 1; i < argc; i++) {
|
||||
/* Open input file. */
|
||||
fin = fopen(argv[i], "rb");
|
||||
if (!fin) {
|
||||
fprintf(stderr, "Could not open input file \"%s\"\n", argv[i]);
|
||||
continue;
|
||||
}
|
||||
/* Open input file. */
|
||||
fin = fopen(argv[i], "rb");
|
||||
if (!fin) {
|
||||
fprintf(stderr, "Could not open input file \"%s\"\n", argv[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Generate output file name. */
|
||||
buf = malloc(strlen(argv[i]) + 7);
|
||||
sprintf(buf, "%s_cp437", argv[i]);
|
||||
/* Generate output file name. */
|
||||
buf = malloc(strlen(argv[i]) + 7);
|
||||
sprintf(buf, "%s_cp437", argv[i]);
|
||||
|
||||
/* Open output file. */
|
||||
fout = fopen(buf, "wb");
|
||||
if (!fout) {
|
||||
fclose(fin);
|
||||
fprintf(stderr, "Could not open output file \"%s\"\n", buf);
|
||||
continue;
|
||||
}
|
||||
/* Open output file. */
|
||||
fout = fopen(buf, "wb");
|
||||
if (!fout) {
|
||||
fclose(fin);
|
||||
fprintf(stderr, "Could not open output file \"%s\"\n", buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%s\n", buf);
|
||||
printf("%s\n", buf);
|
||||
|
||||
/* Perform the conversion. */
|
||||
while (!feof(fin)) {
|
||||
/* Read UTF-8 codepoint. */
|
||||
memset(buf, 0, 5);
|
||||
fread(buf, 1, 1, fin);
|
||||
if ((buf[0] & 0xe0) == 0xc0)
|
||||
fread(&buf[1], 1, 1, fin);
|
||||
else if ((buf[0] & 0xf0) == 0xe0)
|
||||
fread(&buf[1], 2, 1, fin);
|
||||
else if ((buf[0] & 0xf8) == 0xf0)
|
||||
fread(&buf[1], 3, 1, fin);
|
||||
/* Perform the conversion. */
|
||||
while (!feof(fin)) {
|
||||
/* Read UTF-8 codepoint. */
|
||||
memset(buf, 0, 5);
|
||||
fread(buf, 1, 1, fin);
|
||||
if ((buf[0] & 0xe0) == 0xc0)
|
||||
fread(&buf[1], 1, 1, fin);
|
||||
else if ((buf[0] & 0xf0) == 0xe0)
|
||||
fread(&buf[1], 2, 1, fin);
|
||||
else if ((buf[0] & 0xf8) == 0xf0)
|
||||
fread(&buf[1], 3, 1, fin);
|
||||
|
||||
for (j = 1; j < (sizeof(cp437) / sizeof(cp437[0])); j++) {
|
||||
if (!strcmp(buf, cp437[j])) {
|
||||
fputc(j, fout);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (j = 1; j < (sizeof(cp437) / sizeof(cp437[0])); j++) {
|
||||
if (!strcmp(buf, cp437[j])) {
|
||||
fputc(j, fout);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up. */
|
||||
free(buf);
|
||||
fclose(fin);
|
||||
fclose(fout);
|
||||
/* Clean up. */
|
||||
free(buf);
|
||||
fclose(fin);
|
||||
fclose(fout);
|
||||
|
||||
/* Increase success counter. */
|
||||
success++;
|
||||
/* Increase success counter. */
|
||||
success++;
|
||||
}
|
||||
|
||||
if (--i == success)
|
||||
return 0;
|
||||
return 0;
|
||||
else if (success > 0)
|
||||
return 1;
|
||||
return 1;
|
||||
else
|
||||
return 2;
|
||||
return 2;
|
||||
}
|
||||
|
||||
482
isapnp/isapnp.c
482
isapnp/isapnp.c
@@ -35,18 +35,15 @@
|
||||
#include <string.h>
|
||||
#include "clib.h"
|
||||
|
||||
|
||||
typedef struct _card_ {
|
||||
char id[8];
|
||||
char id[8];
|
||||
struct _card_ *next;
|
||||
} card_t;
|
||||
|
||||
|
||||
uint8_t buf[256], buf_pos;
|
||||
uint8_t buf[256], buf_pos;
|
||||
uint16_t rd_data;
|
||||
FILE *f;
|
||||
card_t *first_card = NULL;
|
||||
|
||||
FILE *f;
|
||||
card_t *first_card = NULL;
|
||||
|
||||
static inline void
|
||||
io_delay()
|
||||
@@ -54,16 +51,15 @@ io_delay()
|
||||
delay(1);
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
lfsr_advance(int lfsr, int bit) {
|
||||
register uint8_t next;
|
||||
next = lfsr >> 1;
|
||||
next |= (((lfsr ^ next) ^ bit)) << 7;
|
||||
return next;
|
||||
lfsr_advance(int lfsr, int bit)
|
||||
{
|
||||
register uint8_t next;
|
||||
next = lfsr >> 1;
|
||||
next |= (((lfsr ^ next) ^ bit)) << 7;
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
unlock()
|
||||
{
|
||||
@@ -81,12 +77,11 @@ unlock()
|
||||
/* Send key. */
|
||||
lfsr = 0x6a;
|
||||
for (i = 0; i < 32; i++) {
|
||||
outb(0x279, lfsr);
|
||||
lfsr = lfsr_advance(lfsr, 0);
|
||||
outb(0x279, lfsr);
|
||||
lfsr = lfsr_advance(lfsr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
checksum(uint8_t *identifier)
|
||||
{
|
||||
@@ -94,16 +89,15 @@ checksum(uint8_t *identifier)
|
||||
|
||||
lfsr = 0x6a;
|
||||
for (i = 0; i < 8; i++) {
|
||||
byte = identifier[i];
|
||||
for (j = 0; j < 8; j++) {
|
||||
lfsr = lfsr_advance(lfsr, byte);
|
||||
byte >>= 1;
|
||||
}
|
||||
byte = identifier[i];
|
||||
for (j = 0; j < 8; j++) {
|
||||
lfsr = lfsr_advance(lfsr, byte);
|
||||
byte >>= 1;
|
||||
}
|
||||
}
|
||||
return lfsr;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
parse_id(uint8_t *identifier, char *id)
|
||||
{
|
||||
@@ -111,13 +105,12 @@ parse_id(uint8_t *identifier, char *id)
|
||||
|
||||
vendor = (identifier[0] << 8) | identifier[1];
|
||||
sprintf(id, "%c%c%c%02X%02X",
|
||||
'@' + ((vendor >> 10) & 0x1f),
|
||||
'@' + ((vendor >> 5) & 0x1f),
|
||||
'@' + (vendor & 0x1f),
|
||||
identifier[2], identifier[3]);
|
||||
'@' + ((vendor >> 10) & 0x1f),
|
||||
'@' + ((vendor >> 5) & 0x1f),
|
||||
'@' + (vendor & 0x1f),
|
||||
identifier[2], identifier[3]);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
read_resource_data(uint8_t *byte)
|
||||
{
|
||||
@@ -125,21 +118,21 @@ read_resource_data(uint8_t *byte)
|
||||
|
||||
/* Read byte. */
|
||||
for (i = 0; i < 20; i++) {
|
||||
/* Read only if ready. */
|
||||
outb(0x279, 0x05);
|
||||
if (inb(rd_data) & 0x01) {
|
||||
outb(0x279, 0x04);
|
||||
*byte = inb(rd_data);
|
||||
break;
|
||||
}
|
||||
io_delay();
|
||||
/* Read only if ready. */
|
||||
outb(0x279, 0x05);
|
||||
if (inb(rd_data) & 0x01) {
|
||||
outb(0x279, 0x04);
|
||||
*byte = inb(rd_data);
|
||||
break;
|
||||
}
|
||||
io_delay();
|
||||
}
|
||||
|
||||
/* Return failure if the read timed out. */
|
||||
if (i == 20) {
|
||||
printf("\n> Read timed out at byte %d", ftell(f) + buf_pos + 1);
|
||||
*byte = 0xff;
|
||||
return 0;
|
||||
printf("\n> Read timed out at byte %d", ftell(f) + buf_pos + 1);
|
||||
*byte = 0xff;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Add byte to buffer. */
|
||||
@@ -147,48 +140,47 @@ read_resource_data(uint8_t *byte)
|
||||
|
||||
/* Flush buffer if full. */
|
||||
if (!buf_pos && (fwrite(buf, sizeof(buf), 1, f) < 1)) {
|
||||
printf("\n> File write failed");
|
||||
return 0;
|
||||
printf("\n> File write failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Return success. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static char
|
||||
dump_resource_data(char *id)
|
||||
{
|
||||
uint8_t identifier[9], byte, i, j;
|
||||
uint8_t identifier[9], byte, i, j;
|
||||
uint16_t data;
|
||||
card_t *card, *new_card;
|
||||
card_t *card, *new_card;
|
||||
|
||||
/* Sanitize parsed PnP ID for filename purposes. */
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (id[i] > 'Z')
|
||||
id[i] = '_';
|
||||
if (id[i] > 'Z')
|
||||
id[i] = '_';
|
||||
}
|
||||
|
||||
/* Determine this card's unique identifier. */
|
||||
i = 0;
|
||||
i = 0;
|
||||
card = first_card;
|
||||
while (card) {
|
||||
/* Increment unique identifier for each card
|
||||
already found with this sanitized parsed ID. */
|
||||
if (!strcmp(card->id, id))
|
||||
i++;
|
||||
card = card->next;
|
||||
/* Increment unique identifier for each card
|
||||
already found with this sanitized parsed ID. */
|
||||
if (!strcmp(card->id, id))
|
||||
i++;
|
||||
card = card->next;
|
||||
}
|
||||
new_card = malloc(sizeof(card_t));
|
||||
strcpy(new_card->id, id);
|
||||
new_card->next = NULL;
|
||||
if (!first_card) {
|
||||
first_card = new_card;
|
||||
first_card = new_card;
|
||||
} else {
|
||||
card = first_card;
|
||||
while (card->next)
|
||||
card = card->next;
|
||||
card->next = new_card;
|
||||
card = first_card;
|
||||
while (card->next)
|
||||
card = card->next;
|
||||
card->next = new_card;
|
||||
}
|
||||
|
||||
/* Generate a dump file name. */
|
||||
@@ -199,105 +191,104 @@ dump_resource_data(char *id)
|
||||
/* Open dump file. */
|
||||
f = fopen(id, "wb");
|
||||
if (f) {
|
||||
/* Dump resource data, starting with the header. */
|
||||
buf_pos = 0;
|
||||
for (j = 0; j < 9; j++)
|
||||
read_resource_data(&byte);
|
||||
/* Dump resource data, starting with the header. */
|
||||
buf_pos = 0;
|
||||
for (j = 0; j < 9; j++)
|
||||
read_resource_data(&byte);
|
||||
|
||||
/* Flush buffer. */
|
||||
if (fwrite(buf, buf_pos, 1, f) < 1)
|
||||
printf("\n> File write failed");
|
||||
buf_pos = 0;
|
||||
/* Flush buffer. */
|
||||
if (fwrite(buf, buf_pos, 1, f) < 1)
|
||||
printf("\n> File write failed");
|
||||
buf_pos = 0;
|
||||
|
||||
/* Check for invalid resource data. */
|
||||
if (!memcmp(buf, "\x00\x00\x00\x00\x00\x00\x00\x00\x00", 9) ||
|
||||
!memcmp(buf, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 9)) {
|
||||
printf("\n> Invalid header (all %02X)", buf[0]);
|
||||
goto done;
|
||||
} else {
|
||||
printf("\n> DEBUG: header: %02X %02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8]);
|
||||
}
|
||||
/* Check for invalid resource data. */
|
||||
if (!memcmp(buf, "\x00\x00\x00\x00\x00\x00\x00\x00\x00", 9) || !memcmp(buf, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 9)) {
|
||||
printf("\n> Invalid header (all %02X)", buf[0]);
|
||||
goto done;
|
||||
} else {
|
||||
printf("\n> DEBUG: header: %02X %02X %02X %02X %02X %02X %02X %02X %02X",
|
||||
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8]);
|
||||
}
|
||||
|
||||
/* Now dump the resources. */
|
||||
j = 0;
|
||||
while (read_resource_data(&byte)) {
|
||||
if ((byte == 0x00) || (byte == 0xff)) {
|
||||
printf("\n> DEBUG: %02X resource", byte);
|
||||
break;
|
||||
}
|
||||
/* Now dump the resources. */
|
||||
j = 0;
|
||||
while (read_resource_data(&byte)) {
|
||||
if ((byte == 0x00) || (byte == 0xff)) {
|
||||
printf("\n> DEBUG: %02X resource", byte);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Determine the amount of bytes to skip depending on resource type. */
|
||||
if (byte & 0x80) { /* large resource */
|
||||
read_resource_data((uint8_t *) &data);
|
||||
read_resource_data(((uint8_t *) &data) + 1);
|
||||
/* Determine the amount of bytes to skip depending on resource type. */
|
||||
if (byte & 0x80) { /* large resource */
|
||||
read_resource_data((uint8_t *) &data);
|
||||
read_resource_data(((uint8_t *) &data) + 1);
|
||||
|
||||
/* Handle ANSI strings. */
|
||||
byte &= 0x7f;
|
||||
if (byte == 0x02) {
|
||||
/* Output string. */
|
||||
if (!j)
|
||||
printf("\n>");
|
||||
printf(" \"");
|
||||
while (data--) {
|
||||
read_resource_data(&byte);
|
||||
if ((byte != 0x00) && (byte != '\r') && (byte != '\n'))
|
||||
putchar(byte);
|
||||
}
|
||||
printf("\"");
|
||||
data = 0;
|
||||
}
|
||||
} else { /* small resource */
|
||||
data = byte & 0x07;
|
||||
/* Handle ANSI strings. */
|
||||
byte &= 0x7f;
|
||||
if (byte == 0x02) {
|
||||
/* Output string. */
|
||||
if (!j)
|
||||
printf("\n>");
|
||||
printf(" \"");
|
||||
while (data--) {
|
||||
read_resource_data(&byte);
|
||||
if ((byte != 0x00) && (byte != '\r') && (byte != '\n'))
|
||||
putchar(byte);
|
||||
}
|
||||
printf("\"");
|
||||
data = 0;
|
||||
}
|
||||
} else { /* small resource */
|
||||
data = byte & 0x07;
|
||||
|
||||
/* Handle some resource types. */
|
||||
byte = (byte >> 3) & 0x0f;
|
||||
if ((byte == 0x02) && (data >= 4)) { /* logical device */
|
||||
/* Read logical device ID. */
|
||||
for (j = 0; j < 4; j++)
|
||||
read_resource_data(&identifier[j]);
|
||||
data -= j;
|
||||
/* Handle some resource types. */
|
||||
byte = (byte >> 3) & 0x0f;
|
||||
if ((byte == 0x02) && (data >= 4)) { /* logical device */
|
||||
/* Read logical device ID. */
|
||||
for (j = 0; j < 4; j++)
|
||||
read_resource_data(&identifier[j]);
|
||||
data -= j;
|
||||
|
||||
/* Output logical device ID. */
|
||||
parse_id(identifier, id);
|
||||
printf("\n> %s", id);
|
||||
} else if (byte == 0x0f) { /* end tag */
|
||||
/* Read the rest of this resource (including the checksum), then stop. */
|
||||
if (data == 0) /* just in case the checksum isn't covered */
|
||||
data++;
|
||||
while (data--)
|
||||
read_resource_data(&byte);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Output logical device ID. */
|
||||
parse_id(identifier, id);
|
||||
printf("\n> %s", id);
|
||||
} else if (byte == 0x0f) { /* end tag */
|
||||
/* Read the rest of this resource (including the checksum), then stop. */
|
||||
if (data == 0) /* just in case the checksum isn't covered */
|
||||
data++;
|
||||
while (data--)
|
||||
read_resource_data(&byte);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Skip bytes. */
|
||||
while (data--)
|
||||
read_resource_data(&byte);
|
||||
}
|
||||
/* Skip bytes. */
|
||||
while (data--)
|
||||
read_resource_data(&byte);
|
||||
}
|
||||
|
||||
/* Flush buffer if not empty. */
|
||||
if (buf_pos && (fwrite(buf, buf_pos, 1, f) < 1))
|
||||
printf("\n> File write failed");
|
||||
/* Flush buffer if not empty. */
|
||||
if (buf_pos && (fwrite(buf, buf_pos, 1, f) < 1))
|
||||
printf("\n> File write failed");
|
||||
|
||||
/* Finish the dump. */
|
||||
done: fclose(f);
|
||||
printf("\n");
|
||||
/* Finish the dump. */
|
||||
done:
|
||||
fclose(f);
|
||||
printf("\n");
|
||||
} else {
|
||||
printf("\n> File creation failed\n");
|
||||
printf("\n> File creation failed\n");
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
try_isolate()
|
||||
{
|
||||
char id[13];
|
||||
uint8_t identifier[9], byte, i, j, seen_55aa, seen_life;
|
||||
char id[13];
|
||||
uint8_t identifier[9], byte, i, j, seen_55aa, seen_life;
|
||||
uint16_t data;
|
||||
int csn;
|
||||
int csn;
|
||||
|
||||
printf("\rScanning on Read Data Port %04X...", rd_data);
|
||||
id[0] = 0;
|
||||
@@ -324,49 +315,49 @@ try_isolate()
|
||||
/* Check for and dump UMC Super I/O. */
|
||||
outb(0x108, 0xaa);
|
||||
if (inb(0x108) != 0xff) {
|
||||
outb(0x108, 0xc2);
|
||||
byte = inb(0x109);
|
||||
outb(0x108, 0x55);
|
||||
outb(0x108, 0xc2);
|
||||
printf("\nUMC Super I/O (C2U=%02X C2L=%02X)", byte, inb(0x109));
|
||||
outb(0x108, 0xc2);
|
||||
byte = inb(0x109);
|
||||
outb(0x108, 0x55);
|
||||
outb(0x108, 0xc2);
|
||||
printf("\nUMC Super I/O (C2U=%02X C2L=%02X)", byte, inb(0x109));
|
||||
|
||||
/* Enable ISAPnP mode. */
|
||||
outb(0x108, 0xaa);
|
||||
outb(0x108, 0xc1);
|
||||
byte = inb(0x109);
|
||||
outb(0x108, 0xaa);
|
||||
outb(0x108, 0xc1);
|
||||
outb(0x109, byte | 0x80);
|
||||
/* Enable ISAPnP mode. */
|
||||
outb(0x108, 0xaa);
|
||||
outb(0x108, 0xc1);
|
||||
byte = inb(0x109);
|
||||
outb(0x108, 0xaa);
|
||||
outb(0x108, 0xc1);
|
||||
outb(0x109, byte | 0x80);
|
||||
|
||||
/* Dump resource data. */
|
||||
sprintf(id, "UMCSIOP");
|
||||
i = dump_resource_data(id);
|
||||
/* Dump resource data. */
|
||||
sprintf(id, "UMCSIOP");
|
||||
i = dump_resource_data(id);
|
||||
|
||||
/* Dump registers. */
|
||||
sprintf(id, "UMCSIOR%c.BIN", i);
|
||||
printf("> Dumping registers to %s", id);
|
||||
f = fopen(id, "wb");
|
||||
if (f) {
|
||||
/* Dump registers to the buffer. */
|
||||
i = 0xc0;
|
||||
do {
|
||||
outb(0x108, 0xaa);
|
||||
outb(0x108, i);
|
||||
buf[i] = inb(0x109);
|
||||
} while (++i != 0xc0);
|
||||
/* Dump registers. */
|
||||
sprintf(id, "UMCSIOR%c.BIN", i);
|
||||
printf("> Dumping registers to %s", id);
|
||||
f = fopen(id, "wb");
|
||||
if (f) {
|
||||
/* Dump registers to the buffer. */
|
||||
i = 0xc0;
|
||||
do {
|
||||
outb(0x108, 0xaa);
|
||||
outb(0x108, i);
|
||||
buf[i] = inb(0x109);
|
||||
} while (++i != 0xc0);
|
||||
|
||||
/* Flush buffer. */
|
||||
if (fwrite(buf, sizeof(buf), 1, f) < 1)
|
||||
printf("\n> File write failed");
|
||||
/* Flush buffer. */
|
||||
if (fwrite(buf, sizeof(buf), 1, f) < 1)
|
||||
printf("\n> File write failed");
|
||||
|
||||
/* Finish the dump. */
|
||||
fclose(f);
|
||||
printf("\n");
|
||||
} else {
|
||||
printf("\n> File creation failed\n");
|
||||
}
|
||||
/* Finish the dump. */
|
||||
fclose(f);
|
||||
printf("\n");
|
||||
} else {
|
||||
printf("\n> File creation failed\n");
|
||||
}
|
||||
|
||||
/* Disable ISAPnP mode. */
|
||||
/* Disable ISAPnP mode. */
|
||||
#if 0
|
||||
outb(0x108, 0xaa);
|
||||
outb(0x108, 0xc1);
|
||||
@@ -375,77 +366,77 @@ try_isolate()
|
||||
outb(0x108, 0xc1);
|
||||
outb(0x109, byte & ~0x80);
|
||||
#endif
|
||||
outb(0x108, 0x55);
|
||||
outb(0x108, 0x55);
|
||||
}
|
||||
|
||||
/* Isolate cards. */
|
||||
csn = 0;
|
||||
while (1) {
|
||||
/* Put sleeping cards to Isolation. */
|
||||
outb(0x279, 0x01);
|
||||
io_delay();
|
||||
/* Put sleeping cards to Isolation. */
|
||||
outb(0x279, 0x01);
|
||||
io_delay();
|
||||
|
||||
/* Read serial identifier. */
|
||||
memset(identifier, 0, sizeof(identifier));
|
||||
seen_55aa = seen_life = 0;
|
||||
for (i = 0; i < sizeof(identifier); i++) {
|
||||
byte = 0;
|
||||
for (j = 0; j < 8; j++) {
|
||||
data = inb(rd_data);
|
||||
io_delay();
|
||||
data = (data << 8) | inb(rd_data);
|
||||
io_delay();
|
||||
byte >>= 1;
|
||||
if (data != 0xffff) {
|
||||
seen_life++;
|
||||
if (data == 0x55aa) {
|
||||
byte |= 0x80;
|
||||
seen_55aa++;
|
||||
}
|
||||
}
|
||||
}
|
||||
identifier[i] = byte;
|
||||
}
|
||||
/* Read serial identifier. */
|
||||
memset(identifier, 0, sizeof(identifier));
|
||||
seen_55aa = seen_life = 0;
|
||||
for (i = 0; i < sizeof(identifier); i++) {
|
||||
byte = 0;
|
||||
for (j = 0; j < 8; j++) {
|
||||
data = inb(rd_data);
|
||||
io_delay();
|
||||
data = (data << 8) | inb(rd_data);
|
||||
io_delay();
|
||||
byte >>= 1;
|
||||
if (data != 0xffff) {
|
||||
seen_life++;
|
||||
if (data == 0x55aa) {
|
||||
byte |= 0x80;
|
||||
seen_55aa++;
|
||||
}
|
||||
}
|
||||
}
|
||||
identifier[i] = byte;
|
||||
}
|
||||
|
||||
/* Stop if we didn't see any 55AA patterns. */
|
||||
if (!seen_55aa) {
|
||||
if (!csn && seen_life)
|
||||
csn = -1;
|
||||
break;
|
||||
}
|
||||
/* Stop if we didn't see any 55AA patterns. */
|
||||
if (!seen_55aa) {
|
||||
if (!csn && seen_life)
|
||||
csn = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Output ID. */
|
||||
if (!id[0])
|
||||
printf("\n");
|
||||
parse_id(identifier, id);
|
||||
printf("%s (%02X%02X%02X%02X)", id, identifier[7], identifier[6], identifier[5], identifier[4]);
|
||||
/* Output ID. */
|
||||
if (!id[0])
|
||||
printf("\n");
|
||||
parse_id(identifier, id);
|
||||
printf("%s (%02X%02X%02X%02X)", id, identifier[7], identifier[6], identifier[5], identifier[4]);
|
||||
|
||||
/* Stop if the checksum is invalid. */
|
||||
if (identifier[8] != checksum(identifier)) {
|
||||
printf(" - bad checksum (expected %02X got %02X), trying another port\n",
|
||||
checksum(identifier), identifier[8]);
|
||||
csn = -1;
|
||||
break;
|
||||
}
|
||||
/* Stop if the checksum is invalid. */
|
||||
if (identifier[8] != checksum(identifier)) {
|
||||
printf(" - bad checksum (expected %02X got %02X), trying another port\n",
|
||||
checksum(identifier), identifier[8]);
|
||||
csn = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Assign a CSN. */
|
||||
csn++;
|
||||
outb(0x279, 0x06);
|
||||
outb(0xa79, csn);
|
||||
io_delay();
|
||||
/* Assign a CSN. */
|
||||
csn++;
|
||||
outb(0x279, 0x06);
|
||||
outb(0xa79, csn);
|
||||
io_delay();
|
||||
|
||||
/* Wake this card by its CSN to reset the resource data pointer. */
|
||||
outb(0x279, 0x03);
|
||||
outb(0xa79, csn);
|
||||
io_delay();
|
||||
/* Wake this card by its CSN to reset the resource data pointer. */
|
||||
outb(0x279, 0x03);
|
||||
outb(0xa79, csn);
|
||||
io_delay();
|
||||
|
||||
/* Dump resource data. */
|
||||
dump_resource_data(id);
|
||||
/* Dump resource data. */
|
||||
dump_resource_data(id);
|
||||
|
||||
/* Put this card to Sleep and other cards to Isolation. */
|
||||
outb(0x279, 0x03);
|
||||
outb(0xa79, 0x00);
|
||||
io_delay();
|
||||
/* Put this card to Sleep and other cards to Isolation. */
|
||||
outb(0x279, 0x03);
|
||||
outb(0xa79, 0x00);
|
||||
io_delay();
|
||||
}
|
||||
|
||||
/* Put all cards to Wait for Key. */
|
||||
@@ -456,11 +447,10 @@ try_isolate()
|
||||
return csn;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int max_csn;
|
||||
int max_csn;
|
||||
card_t *card;
|
||||
|
||||
/* Disable stdout buffering. */
|
||||
@@ -470,28 +460,28 @@ main(int argc, char **argv)
|
||||
[213:3FF] with a hole at [280:380] for whatever safety reason. */
|
||||
max_csn = -1;
|
||||
for (rd_data = 0x213; rd_data <= 0x3ff; rd_data += 16) {
|
||||
if ((rd_data >= 0x280) && (rd_data <= 0x380))
|
||||
continue;
|
||||
if ((rd_data >= 0x280) && (rd_data <= 0x380))
|
||||
continue;
|
||||
|
||||
max_csn = try_isolate();
|
||||
if (max_csn >= 0)
|
||||
break;
|
||||
max_csn = try_isolate();
|
||||
if (max_csn >= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Free the card list. */
|
||||
while (first_card) {
|
||||
card = first_card->next;
|
||||
free(first_card);
|
||||
first_card = card;
|
||||
card = first_card->next;
|
||||
free(first_card);
|
||||
first_card = card;
|
||||
}
|
||||
|
||||
/* Nothing returned. */
|
||||
if (max_csn <= 0) {
|
||||
if (max_csn < 0)
|
||||
printf("\nNo good Read Data Ports found!\n");
|
||||
else
|
||||
printf("\nNo devices found!\n");
|
||||
return 1;
|
||||
if (max_csn < 0)
|
||||
printf("\nNo good Read Data Ports found!\n");
|
||||
else
|
||||
printf("\nNo devices found!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
1609
pcireg/pcireg.c
1609
pcireg/pcireg.c
File diff suppressed because it is too large
Load Diff
@@ -24,12 +24,11 @@
|
||||
#include <string.h>
|
||||
#include "clib.h"
|
||||
|
||||
|
||||
static void
|
||||
pci_scan_callback(uint8_t bus, uint8_t dev, uint8_t func,
|
||||
uint16_t ven_id, uint16_t dev_id)
|
||||
uint16_t ven_id, uint16_t dev_id)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t i;
|
||||
uint16_t j, start, end;
|
||||
#ifdef IS_32BIT
|
||||
uint32_t mmio_base, *mmio;
|
||||
@@ -37,102 +36,96 @@ pci_scan_callback(uint8_t bus, uint8_t dev, uint8_t func,
|
||||
|
||||
#ifdef IS_32BIT
|
||||
/* Disable southbridge I/O traps. */
|
||||
if ((ven_id == 0x8086) && (((dev_id >= 0x2640) && (dev_id <= 0x2642)) /* ICH6 */ ||
|
||||
((dev_id >= 0x27b0) && (dev_id <= 0x27bd)) /* ICH7 */ ||
|
||||
((dev_id >= 0x2810) && (dev_id <= 0x2815)) /* ICH8 */ ||
|
||||
((dev_id >= 0x2912) && (dev_id <= 0x2919)) /* ICH9 */ ||
|
||||
((dev_id >= 0x3a14) && (dev_id <= 0x3a1a)) /* ICH10 */)) {
|
||||
printf("Found ICH6-10 LPC bridge %04X at bus %02X device %02X function %d\n", dev_id, bus, dev, func);
|
||||
if ((ven_id == 0x8086) && (((dev_id >= 0x2640) && (dev_id <= 0x2642)) /* ICH6 */ || ((dev_id >= 0x27b0) && (dev_id <= 0x27bd)) /* ICH7 */ || ((dev_id >= 0x2810) && (dev_id <= 0x2815)) /* ICH8 */ || ((dev_id >= 0x2912) && (dev_id <= 0x2919)) /* ICH9 */ || ((dev_id >= 0x3a14) && (dev_id <= 0x3a1a)) /* ICH10 */)) {
|
||||
printf("Found ICH6-10 LPC bridge %04X at bus %02X device %02X function %d\n", dev_id, bus, dev, func);
|
||||
|
||||
/* Get RCBA. */
|
||||
printf("> RCBA is ");
|
||||
mmio_base = pci_readl(bus, dev, func, 0xf0);
|
||||
if ((mmio_base & 0x00000001) && (mmio_base != 0xffffffff)) {
|
||||
printf("assigned to %08X\n", mmio_base);
|
||||
mmio = (uint32_t *) (mmio_base & ~0x00003fff);
|
||||
/* Get RCBA. */
|
||||
printf("> RCBA is ");
|
||||
mmio_base = pci_readl(bus, dev, func, 0xf0);
|
||||
if ((mmio_base & 0x00000001) && (mmio_base != 0xffffffff)) {
|
||||
printf("assigned to %08X\n", mmio_base);
|
||||
mmio = (uint32_t *) (mmio_base & ~0x00003fff);
|
||||
|
||||
/* Disable all relevant I/O traps. */
|
||||
for (i = 0; i < 4; i++) {
|
||||
/* Check if the trap is enabled. */
|
||||
j = (0x1e80 | (i << 3)) >> 2;
|
||||
if (mmio[j] & 0x00000001) {
|
||||
start = mmio[j] & 0xfffc;
|
||||
end = (mmio[j] >> 16) & 0xfc; /* temporarily just the mask */
|
||||
printf("> Trap %d (%04X+%02X)", i, start, end);
|
||||
end += start; /* now the actual end */
|
||||
/* Disable all relevant I/O traps. */
|
||||
for (i = 0; i < 4; i++) {
|
||||
/* Check if the trap is enabled. */
|
||||
j = (0x1e80 | (i << 3)) >> 2;
|
||||
if (mmio[j] & 0x00000001) {
|
||||
start = mmio[j] & 0xfffc;
|
||||
end = (mmio[j] >> 16) & 0xfc; /* temporarily just the mask */
|
||||
printf("> Trap %d (%04X+%02X)", i, start, end);
|
||||
end += start; /* now the actual end */
|
||||
|
||||
/* Check if the trap covers the KBC ports. */
|
||||
if (((start <= 0x60) && (end >= 0x60)) ||
|
||||
((start <= 0x64) && (end >= 0x64))) {
|
||||
/* Clear TRSE bit. */
|
||||
mmio[j] &= ~0x00000001;
|
||||
/* Check if the trap covers the KBC ports. */
|
||||
if (((start <= 0x60) && (end >= 0x60)) || ((start <= 0x64) && (end >= 0x64))) {
|
||||
/* Clear TRSE bit. */
|
||||
mmio[j] &= ~0x00000001;
|
||||
|
||||
/* Check if the bit was actually cleared. */
|
||||
if (mmio[j] & 0x00000001)
|
||||
printf("enable bit stuck! (%08X%08X)\n", mmio[j | 1], mmio[j]);
|
||||
else
|
||||
printf("disabled\n");
|
||||
} else {
|
||||
printf("not relevant\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("unassigned! (%08X)\n", mmio_base);
|
||||
}
|
||||
/* Check if the bit was actually cleared. */
|
||||
if (mmio[j] & 0x00000001)
|
||||
printf("enable bit stuck! (%08X%08X)\n", mmio[j | 1], mmio[j]);
|
||||
else
|
||||
printf("disabled\n");
|
||||
} else {
|
||||
printf("not relevant\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf("unassigned! (%08X)\n", mmio_base);
|
||||
}
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Skip non-USB devices. */
|
||||
if (pci_readw(bus, dev, func, 0x0a) != 0x0c03)
|
||||
return;
|
||||
return;
|
||||
|
||||
/* Read progif code. */
|
||||
i = pci_readb(bus, dev, func, 0x09);
|
||||
|
||||
/* Act according to the device class. */
|
||||
if (i == 0x00) { /* UHCI */
|
||||
printf("Found UHCI USB controller at bus %02X device %02X function %d\n", bus, dev, func);
|
||||
printf("Found UHCI USB controller at bus %02X device %02X function %d\n", bus, dev, func);
|
||||
|
||||
/* Clear 60/64h trap/SMI R/W bits. */
|
||||
j = pci_readw(bus, dev, func, 0xc0);
|
||||
pci_writew(bus, dev, func, 0xc0, j & ~0x000f);
|
||||
/* Clear 60/64h trap/SMI R/W bits. */
|
||||
j = pci_readw(bus, dev, func, 0xc0);
|
||||
pci_writew(bus, dev, func, 0xc0, j & ~0x000f);
|
||||
|
||||
/* Check if the bits were actually cleared. */
|
||||
j = pci_readw(bus, dev, func, 0xc0);
|
||||
if (j & 0x000f)
|
||||
printf("> I/O trap bits stuck! (%04X)\n", j);
|
||||
else
|
||||
printf("> I/O traps disabled\n");
|
||||
/* Check if the bits were actually cleared. */
|
||||
j = pci_readw(bus, dev, func, 0xc0);
|
||||
if (j & 0x000f)
|
||||
printf("> I/O trap bits stuck! (%04X)\n", j);
|
||||
else
|
||||
printf("> I/O traps disabled\n");
|
||||
} else if (i == 0x10) { /* OHCI */
|
||||
printf("Found OHCI USB controller at bus %02X device %02X function %d\n", bus, dev, func);
|
||||
printf("Found OHCI USB controller at bus %02X device %02X function %d\n", bus, dev, func);
|
||||
|
||||
#ifdef IS_32BIT
|
||||
/* Get MMIO base address. */
|
||||
mmio_base = pci_get_mem_bar(bus, dev, func, 0x10, 4096, "> MMIO");
|
||||
if (mmio_base) {
|
||||
mmio = (uint32_t *) mmio_base;
|
||||
/* Get MMIO base address. */
|
||||
mmio_base = pci_get_mem_bar(bus, dev, func, 0x10, 4096, "> MMIO");
|
||||
if (mmio_base) {
|
||||
mmio = (uint32_t *) mmio_base;
|
||||
|
||||
/* Clear EmulationEnable bit. */
|
||||
mmio[0x100 >> 2] &= ~0x00000001;
|
||||
/* Clear EmulationEnable bit. */
|
||||
mmio[0x100 >> 2] &= ~0x00000001;
|
||||
|
||||
/* Check if the bit was actually cleared. */
|
||||
if (mmio[0x100 >> 2] & 0x00000001)
|
||||
printf("> Emulation bit stuck! (%08X)\n", mmio[0x100 >> 2]);
|
||||
else
|
||||
printf("> Emulation disabled\n");
|
||||
}
|
||||
/* Check if the bit was actually cleared. */
|
||||
if (mmio[0x100 >> 2] & 0x00000001)
|
||||
printf("> Emulation bit stuck! (%08X)\n", mmio[0x100 >> 2]);
|
||||
else
|
||||
printf("> Emulation disabled\n");
|
||||
}
|
||||
#else
|
||||
printf("> OHCI not supported on 16-bit build!\n");
|
||||
printf("> OHCI not supported on 16-bit build!\n");
|
||||
#endif
|
||||
} else if ((i != 0x20) && (i != 0x30)) { /* not EHCI or XHCI */
|
||||
printf("Found unknown USB controller type %02X at bus %02X device %02X function %d\n", i, bus, dev, func);
|
||||
printf("Found unknown USB controller type %02X at bus %02X device %02X function %d\n", i, bus, dev, func);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@@ -143,7 +136,7 @@ main(int argc, char **argv)
|
||||
|
||||
/* Initialize PCI, and exit in case of failure. */
|
||||
if (!pci_init())
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
/* Scan PCI bus 0. */
|
||||
pci_scan_bus(0, pci_scan_callback);
|
||||
|
||||
Reference in New Issue
Block a user