misc.c

来自「适合KS8695X」· C语言 代码 · 共 548 行 · 第 1/2 页

C
548
字号
/*
 * (C) Copyright 2002 ELTEC Elektronik AG
 * Frank Gottschling <fgottschling@eltec.de>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

/* includes */
#include <common.h>
#include <linux/ctype.h>
#include <pci.h>
#include <net.h>
#include <mpc106.h>
#include <w83c553f.h>
#include "srom.h"

/* imports  */
extern char console_buffer[CFG_CBSIZE];
extern int l2_cache_enable (int l2control);
extern void *nvram_read (void *dest, const short src, size_t count);
extern void nvram_write (short dest, const void *src, size_t count);

/* globals */
unsigned int ata_reset_time = 60;
unsigned int scsi_reset_time = 10;
unsigned int eltec_board;

/* BAB750 uses SYM53C875(default) and BAB740 uses SYM53C860
 * values fixed after board identification
 */
unsigned short scsi_dev_id = PCI_DEVICE_ID_NCR_53C875;
unsigned int   scsi_max_scsi_id = 15;
unsigned char  scsi_sym53c8xx_ccf = 0x13;

/*----------------------------------------------------------------------------*/
/*
 * handle sroms on BAB740/750
 * fix ether address
 * L2 cache initialization
 * ide dma control
 */
int misc_init_r (void)
{
    revinfo eerev;
    u_char *ptr;
    u_int  i, l, initSrom, copyNv;
    char buf[256];
    char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
	     0, 0, 0, 0, 10, 11, 12, 13, 14, 15 };
    pci_dev_t bdf;

    char sromSYM[] = {
#ifdef TULIP_BUG
    /* 10BaseT, 100BaseTx no full duplex modes */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x08,
    0x02, 0x86, 0x02, 0x00, 0xaf, 0x08, 0xa5, 0x00,
    0x88, 0x04, 0x03, 0x27, 0x08, 0x25, 0x00, 0x61,
    0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xe8
#endif
    /* 10BaseT, 10BaseT-FD, 100BaseTx, 100BaseTx-FD */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x08,
    0x04, 0x86, 0x02, 0x00, 0xaf, 0x08, 0xa5, 0x00,
    0x86, 0x02, 0x04, 0xaf, 0x08, 0xa5, 0x00, 0x88,
    0x04, 0x03, 0x27, 0x08, 0x25, 0x00, 0x61, 0x80,
    0x88, 0x04, 0x05, 0x27, 0x08, 0x25, 0x00, 0x61,
    0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x77
    };

    char sromMII[] = {
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x5b, 0x00,
    0x2e, 0x4d, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x08,
    0x01, 0x95, 0x03, 0x00, 0x00, 0x04, 0x01, 0x08,
    0x00, 0x00, 0x02, 0x08, 0x02, 0x00, 0x00, 0x78,
    0xe0, 0x01, 0x00, 0x50, 0x00, 0x18, 0x80, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x41
    };

    /*
     * Check/Remake revision info
     */
    initSrom = 0;
    copyNv   = 0;

    /* read out current revision srom contens */
    el_srom_load (0x0000, (u_char*)&eerev, sizeof(revinfo),
		SECOND_DEVICE, FIRST_BLOCK);

    /* read out current nvram shadow image */
    nvram_read (buf, CFG_NV_SROM_COPY_ADDR, CFG_SROM_SIZE);

    if (strcmp (eerev.magic, "ELTEC") != 0)
    {
	/* srom is not initialized -> create a default revision info */
	for (i = 0, ptr = (u_char *)&eerev; i < sizeof(revinfo); i++)
	    *ptr++ = 0x00;
	strcpy(eerev.magic, "ELTEC");
	eerev.revrev[0] = 1;
	eerev.revrev[1] = 0;
	eerev.size = 0x00E0;
	eerev.category[0] = 0x01;

	/* node id from dead e128 as default */
	eerev.etheraddr[0] = 0x00;
	eerev.etheraddr[1] = 0x00;
	eerev.etheraddr[2] = 0x5B;
	eerev.etheraddr[3] = 0x00;
	eerev.etheraddr[4] = 0x2E;
	eerev.etheraddr[5] = 0x4D;

	/* cache config word for bab750 */
	*(int*)&eerev.res[0] = CLK2P0TO1_1MB_PB_0P5DH;

	initSrom = 1;  /* force dialog */
	copyNv   = 1;  /* copy to nvram */
    }

    if ((copyNv == 0) &&   (el_srom_checksum((u_char*)&eerev, CFG_SROM_SIZE) !=
		el_srom_checksum((u_char*)buf, CFG_SROM_SIZE)))
    {
	printf ("Invalid revision info copy in nvram !\n");
	printf ("Press key:\n  <c> to copy current revision info to nvram.\n");
	printf ("  <r> to reenter revision info.\n");
	printf ("=> ");
	if (0 != readline (NULL))
	{
	    switch ((char)toupper(console_buffer[0]))
	    {
	    case 'C':
		copyNv = 1;
		break;
	    case 'R':
		copyNv = 1;
		initSrom = 1;
		break;
	    }
	}
    }

    if (initSrom)
    {
	memcpy (buf, &eerev.revision[0][0], 14);     /* save all revision info */
	printf ("Enter revision number (0-9): %c  ", eerev.revision[0][0]);
	if (0 != readline (NULL))
	{
	    eerev.revision[0][0] = (char)toupper(console_buffer[0]);
	    memcpy (&eerev.revision[1][0], buf, 12); /* shift rest of rev info */
	}

	printf ("Enter revision character (A-Z): %c  ", eerev.revision[0][1]);
	if (1 == readline (NULL))
	{
	    eerev.revision[0][1] = (char)toupper(console_buffer[0]);
	}

	printf ("Enter board name (V-XXXX-XXXX): %s  ", (char *)&eerev.board);
	if (11 == readline (NULL))
	{
	    for (i=0; i<11; i++)
		eerev.board[i] =  (char)toupper(console_buffer[i]);
	    eerev.board[11] = '\0';
	}

	printf ("Enter serial number: %s ", (char *)&eerev.serial );
	if (6 == readline (NULL))
	{
	    for (i=0; i<6; i++)
		eerev.serial[i] = console_buffer[i];
	    eerev.serial[6] = '\0';
	}

	printf ("Enter ether node ID with leading zero (HEX): %02x%02x%02x%02x%02x%02x  ",
	    eerev.etheraddr[0], eerev.etheraddr[1],
	    eerev.etheraddr[2], eerev.etheraddr[3],
	    eerev.etheraddr[4], eerev.etheraddr[5]);
	if (12 == readline (NULL))
	{
	    for (i=0; i<12; i+=2)
	    eerev.etheraddr[i>>1] = (char)(16*hex[toupper(console_buffer[i])-'0'] +
			       hex[toupper(console_buffer[i+1])-'0']);
	}

	l = strlen ((char *)&eerev.text);
	printf("Add to text section (max 64 chr): %s ", (char *)&eerev.text );
	if (0 != readline (NULL))
	{
	    for (i = l; i<63; i++)
		eerev.text[i] = console_buffer[i-l];
	    eerev.text[63] = '\0';
	}

	if (strstr ((char *)&eerev.board, "75") != NULL)
	    eltec_board = 750;
	else
	    eltec_board = 740;

	if (eltec_board == 750)
	{
	    if (CPU_TYPE == CPU_TYPE_750)
		*(int*)&eerev.res[0] = CLK2P0TO1_1MB_PB_0P5DH;
		else
		*(int*)&eerev.res[0] = CLK2P5TO1_1MB_PB_0P5DH;

	    printf("Enter L2Cache config word with leading zero (HEX): %08X  ",
		    *(int*)&eerev.res[0] );
	    if (0 != readline (NULL))
	    {
		for (i=0; i<7; i+=2)
		{
		    eerev.res[i>>1] =
		    (char)(16*hex[toupper(console_buffer[i])-'0'] +
		    hex[toupper(console_buffer[i+1])-'0']);
		}
	    }

	    /* prepare network eeprom */
	    sromMII[20] = eerev.etheraddr[0];
	    sromMII[21] = eerev.etheraddr[1];
	    sromMII[22] = eerev.etheraddr[2];
	    sromMII[23] = eerev.etheraddr[3];
	    sromMII[24] = eerev.etheraddr[4];
	    sromMII[25] = eerev.etheraddr[5];
	    printf("\nSRom:  Writing DEC21143 MII info .. ");

	    if (dc_srom_store ((u_short *)sromMII) == -1)
		printf("FAILED\n");
	    else

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?