📄 pciinit.c
字号:
//*****************************************************************************
//* Accton Technology Corpotation *
//* *
//* EN1207B-TX 4 EEPROM Programming Utility *
//* *
//* Author Pao-Sheng Lee *
//* *
//* Copyright 1997-1998 Accton Technology Corporation *
//* *
//* Tool: C800+MASM 6.10 *
//* *
//* Release Note: *
//* *
//* 98-03-12 V1.00 Pre-release *
//* *
//* 98-03-30 V1.01 Support PCI-to-PCI bridge *
//*****************************************************************************
//------------------------------- DEFINIIONS ----------------------------------
#define VERSION "1.01"
#define RELEASE_DATE "(03-30-98)"
#define ERROR 1
#define NOERROR 0
#define TRUE 1
#define FALSE 0
#define INTERVAL(_value, _lowerbound, _upperbound) \
(((_value) < (_lowerbound)) ? FALSE : \
(((_value) > (_upperbound)) ? FALSE : TRUE ))
//----------------------------- INCLUDE FILES ---------------------------------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <dos.h>
#include "pciinit.h"
#include "pcibus.h"
#include "message.h"
//------------------------------- PROTOTYPE -----------------------------------
unsigned char search_next_hex_num (char**);
unsigned char search_next_digit (char **);
unsigned long strto16 (char *);
unsigned char asc2num (char);
unsigned char num2asc (char);
void init_error_exit (char, const char * );
unsigned char process_info_file_content (FILE *, _PCI_CONTEXT *);
unsigned char process_bridge_file_content (FILE *, _BRIDGE_CONTEXT *);
//--------------------------- GLOABAL VARIABLES -------------------------------
//------------------------------- FUNCTIONS -----------------------------------
void main (int argc, char *argv[])
{
int error_flag = NOERROR;
_PCI_CONTEXT pci_context;
_BRIDGE_CONTEXT bridge_context;
FILE *info_file, *bridge_file;
unsigned char i;
unsigned int pci_bridge_handle, en1207_handle, instance=0,card=1;
unsigned char bus_no, device_no, function_no;
printf("Accton PCI Card Initialization Program V%s %s\n", VERSION, RELEASE_DATE);
printf("Copyright 1997-1998, Accton Technology Corporation\n");
VerifyPCIBusAccessMechanism();
find_device_using_class_code (PCI_TO_PCI_BRIDGE_CLASS_CODE, &pci_bridge_handle);
if (pci_bridge_handle !=0xffff) {
open_bridge_card (pci_bridge_handle, &bridge_context);
if (bridge_context.bridge_command & 0x07) {
if (bridge_context.bridge_bus_number) {
// Bridge resources are allocated, just save the information
bridge_file = fopen("bridge.dat","w");
fprintf (bridge_file, "command=%4x\n", bridge_context.bridge_command);
fprintf (bridge_file, "latency=%4x\n", bridge_context.bridge_latency);
fprintf (bridge_file, "bus_number=%8lx\n", bridge_context.bridge_bus_number);
fprintf (bridge_file, "iobase=%4x\n", bridge_context.bridge_iobase);
fprintf (bridge_file, "memory=%8lx\n", bridge_context.bridge_memory);
fprintf (bridge_file, "pmem=%8lx\n", bridge_context.bridge_prefetch_memory);
fprintf (bridge_file, "control=%4x\n", bridge_context.bridge_control);
fclose (bridge_file);
}
} else {
// BRIDGE resources are not allocated, read the orginal setting from
// BRIDGE.DAT and write these data to configuration space
if ( (bridge_file = fopen("bridge.dat","r")) == NULL) {
init_error_exit(0x1, BridgeFileNotFoundError);
}
if (!process_bridge_file_content(bridge_file, &bridge_context)) {
init_error_exit(0x4, BridgeInformationFileDataError);
}
fclose (info_file);
enable_bridge_card (pci_bridge_handle, &bridge_context);
}
}
//find_en1207_card (instance, &en1207_handle);
find_nic(&en1207_handle);
if (en1207_handle == 0xffff) {
init_error_exit(0x6, EN1207CardNotFoundError);
}
bus_no = (unsigned char) (en1207_handle >> 8);
device_no = (unsigned char) ((en1207_handle & 0xff) >> 3);
function_no = (unsigned char) (en1207_handle & 0x07);
open_en1207_card (en1207_handle, &pci_context);
if (pci_context.pci_command & 0x07) {
if ((pci_context.pci_irq >0) && (pci_context.pci_irq <16)) {
// PCI resources are allocated, just save the information
info_file = fopen("pciinit.dat","w");
fprintf (info_file, "command=%4x\n", pci_context.pci_command);
fprintf (info_file, "latency=%4x\n", pci_context.pci_latency);
fprintf (info_file, "ioport=%4x\n", pci_context.pci_ioport);
fprintf (info_file, "irq=%4x\n", pci_context.pci_irq);
fclose (info_file);
}
} else {
// PCI resources are not allocated, read the orginal setting from
// PCIINIT.DAT and write these data to configuration space
if ( (info_file = fopen("pciinit.dat","r")) == NULL) {
init_error_exit(0x1, TemplateFileNotFoundError);
}
if (!process_info_file_content(info_file, &pci_context)) {
init_error_exit(0x4, InformationFileDataError);
}
fclose (info_file);
enable_en1207_card (en1207_handle, &pci_context);
}
printf ("\nAdapter Instance %1d,", instance);
printf ("\n Bus Number : %4d", bus_no);
printf ("\n Device Number : %4d", device_no);
printf ("\n Function Number : %4d", function_no);
printf ("\n I/O Port : %4X", pci_context.pci_ioport);
printf ("\n IRQ Number : %4d", pci_context.pci_irq);
printf ("\n Latency Timer : %4x", pci_context.pci_latency >> 8);
printf ("\n\n ******* Resource Allocation Complete!! *******\n");
}
//*******************************
// search_next_hex_num *
//*******************************
unsigned char search_next_hex_num (char **hex_string)
{
while ((**hex_string) && (!isxdigit( (int) (char) **hex_string))) (*hex_string)++;
return **hex_string;
}
//*******************************
// search_next_digit() *
//*******************************
unsigned char search_next_digit (char **digit_string)
{
while ((**digit_string) && (!isdigit( (int) (char) **digit_string))) (*digit_string)++;
return **digit_string;
}
//*******************************
// strto16() *
//*******************************
unsigned long strto16 (char *hex_string)
{
unsigned long value = 0;
unsigned char len = 8;
while ((len--) && (isxdigit( (int) (char) *hex_string))) {
value = value*16 + asc2num(*hex_string++);
}
return value;
}
//*******************************
// asc2num() *
//*******************************
unsigned char asc2num(char xdigit)
{
return ((xdigit < 'A') ? (xdigit - 0x30) : (xdigit - 0x37));
}
//*******************************
// num2asc() *
//*******************************
unsigned char num2asc(char xdigit)
{
return ((xdigit < 0x0A) ? (xdigit + 0x30) : (xdigit + 0x37));
}
//*******************************
// init_error_exit() *
//*******************************
void init_error_exit (char errorcode, const char* errormsg)
{
printf("\n\n\t ***** ERROR-%2x: %s *****\n", errorcode, errormsg);
exit (1);
}
//*******************************
// process_info_file_content() *
//*******************************
unsigned char process_info_file_content (FILE *inffile, _PCI_CONTEXT *infdata)
{
char *command_string = "COMMAND=";
char *latency_string = "LATENCY=";
char *ioport_string = "IOPORT=";
char *irq_string = "IRQ=";
unsigned char buffer[80];
char *ptr, *ptr1;
unsigned char flag = TRUE;
unsigned int i;
while ( flag && (fgets(buffer, 80, inffile) != NULL) ) {
ptr = buffer;
strupr(ptr);
if (ptr1 = strstr(ptr, command_string)) {
ptr1 += strlen(command_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->pci_command = (unsigned int) strto16 (ptr1);
ptr1 += 4;
}
} else if (ptr1 = strstr(ptr, latency_string)) {
ptr1 += strlen(latency_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->pci_latency = (unsigned int) strto16 (ptr1);
ptr1 += 4;
}
} else if (ptr1 = strstr(ptr, ioport_string)) {
ptr1 += strlen(ioport_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->pci_ioport = strto16 (ptr1);
ptr1 += 4;
}
} else if (ptr1 = strstr(ptr, irq_string)) {
ptr1 += strlen(irq_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->pci_irq = (unsigned char) strto16 (ptr1);
ptr1 += 4;
}
}
}
return flag;
}
//*********************************
// process_bridge_file_content() *
//*********************************
unsigned char process_bridge_file_content (FILE *inffile, _BRIDGE_CONTEXT *infdata)
{
char *command_string = "COMMAND=";
char *latency_string = "LATENCY=";
char *bus_number_string = "BUS_NUMBER=";
char *iobase_string = "IOBASE=";
char *memory_string = "MEMORY=";
char *pmemory_string = "PMEM=";
char *control_string = "CONTROL=";
unsigned char buffer[80];
char *ptr, *ptr1;
unsigned char flag = TRUE;
unsigned int i;
while ( flag && (fgets(buffer, 80, inffile) != NULL) ) {
ptr = buffer;
strupr(ptr);
if (ptr1 = strstr(ptr, command_string)) {
ptr1 += strlen(command_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->bridge_command = (unsigned int) strto16 (ptr1);
ptr1 += 4;
}
} else if (ptr1 = strstr(ptr, latency_string)) {
ptr1 += strlen(latency_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->bridge_latency = (unsigned int) strto16 (ptr1);
ptr1 += 4;
}
} else if (ptr1 = strstr(ptr, bus_number_string)) {
ptr1 += strlen(bus_number_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->bridge_bus_number = strto16 (ptr1);
ptr1 += 8;
}
} else if (ptr1 = strstr(ptr, iobase_string)) {
ptr1 += strlen(iobase_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->bridge_iobase = (unsigned int) strto16 (ptr1);
ptr1 += 4;
}
} else if (ptr1 = strstr(ptr, memory_string)) {
ptr1 += strlen(memory_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->bridge_memory = strto16 (ptr1);
ptr1 += 8;
}
} else if (ptr1 = strstr(ptr, pmemory_string)) {
ptr1 += strlen(pmemory_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->bridge_prefetch_memory = strto16 (ptr1);
ptr1 += 8;
}
} else if (ptr1 = strstr(ptr, control_string)) {
ptr1 += strlen(control_string);
if (flag = search_next_hex_num (&ptr1)) {
infdata->bridge_control = (unsigned int) strto16 (ptr1);
ptr1 += 4;
}
}
}
return flag;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -