📄 syscon.c
字号:
/************************************************************************
*
* syscon.c
*
* SYSCON module, generic parts (except TTY related parts)
*
*
* ######################################################################
*
* Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved.
*
* Unpublished rights reserved under the Copyright Laws of the United States of
* America.
*
* This document contains information that is proprietary to MIPS Technologies,
* Inc. ("MIPS Technologies"). Any copying, modifying or use of this information
* (in whole or in part) which is not expressly permitted in writing by MIPS
* Technologies or a contractually-authorized third party is strictly
* prohibited. At a minimum, this information is protected under unfair
* competition laws and the expression of the information contained herein is
* protected under federal copyright laws. Violations thereof may result in
* criminal penalties and fines.
* MIPS Technologies or any contractually-authorized third party reserves the
* right to change the information contained in this document to improve
* function, design or otherwise. MIPS Technologies does not assume any
* liability arising out of the application or use of this information. Any
* license under patent rights or any other intellectual property rights owned
* by MIPS Technologies or third parties shall be conveyed by MIPS Technologies
* or any contractually-authorized third party in a separate license agreement
* between the parties.
* The information contained in this document constitutes one or more of the
* following: commercial computer software, commercial computer software
* documentation or other commercial items. If the user of this information, or
* any related documentation of any kind, including related technical data or
* manuals, is an agency, department, or other entity of the United States
* government ("Government"), the use, duplication, reproduction, release,
* modification, disclosure, or transfer of this information, or any related
* documentation of any kind, is restricted in accordance with Federal
* Acquisition Regulation 12.212 for civilian agencies and Defense Federal
* Acquisition Regulation Supplement 227.7202 for military agencies. The use of
* this information by the Government is further restricted in accordance with
* the terms of the license agreement(s) and/or applicable contract terms and
* conditions covering this information from MIPS Technologies or any
* contractually-authorized third party.
*
************************************************************************/
/************************************************************************
* Include files
************************************************************************/
#include <string.h>
#include <stdio.h>
#include <sysdefs.h>
#include <sysdev.h>
#include <syscon_api.h>
#include <syscon.h>
#include <sys_api.h>
#include <syserror.h>
#include <string.h>
#include <product.h>
#include <sysenv_api.h>
#include <env_api.h>
#include <eeprom_api.h>
#include <io_api.h>
#include <spd.h>
#include <shell_api.h>
#include <net_api.h>
/************************************************************************
* Definitions
************************************************************************/
/************************************************************************
* Public variables
************************************************************************/
/************************************************************************
* Static variables
************************************************************************/
/* Constant used for determining endianness */
static const UINT32 endian_test = 0x12345678;
/* Reset value of CP0 config register */
static UINT32 config_init;
/* Memory allocation pointers */
static void *SYSCON_free;
static void *SYSCON_last;
/* Keeps the memory chunk, to be allocated dynamically during
* system initialization.
*/
static UINT8 SYSCON_dynamic_memory[SYS_MALLOC_DYNAMIC_MEMORY_SIZE];
/* Used for generic error string formatting */
static UINT8 syscon_generic_error_string[200] ;
/* Keeps the registered sys_error lookup function per subsystem */
static t_sys_error_lookup registered_lookup[SYSERROR_DOMAIN_COUNT] ;
/* Syscon error strings */
static char* syscon_error_string[] =
{
/* ERROR_SYSCON_OUT_OF_MEMORY */ "Internal: Out of memory (SYSCON)",
/* ERROR_SYSCON_UNKNOWN_PARAM */ "Internal: Invalid ID (SYSCON)",
/* ERROR_SYSCON_IP_UNKNOWN */ "IP address unknown",
/* ERROR_SYSCON_SUBNET_UNKNOWN */ "Subnetmask unknown",
/* ERROR_SYSCON_GATEWAY_UNKNOWN */ "Default gateway unknown",
/* ERROR_SYSCON_READ_ONLY_ID */ "Internal: Read-only ID (SYSCON)",
/* ERROR_SYSCON_WRITE_ONLY_ID */ "Internal: Write-only ID (SYSCON)",
/* ERROR_SYSCON_ENV_VAR_TOO_BIG */ "Internal: Size of env. var too big (SYSCON)",
/* ERROR_SYSCON_INVALID_CHAR_POS */ "Internal: Invalid character position (SYSCON)"
};
/* Array for the SYSCON objects */
static t_syscon_obj syscon_objects[SYSCON_OBJ_COUNT];
/************************************************************************
* Static function prototypes
************************************************************************/
static INT32
spd_read(
UINT32 minor, /* Minor device number */
UINT32 offset, /* Byte position */
UINT32 length, /* Byte count */
void *user_variable ); /* Buffer for data */
/************************************************************************
* Implementation : Static functions
************************************************************************/
/************************************************************************
*
* spd_read
* Description :
* -------------
*
* Read SPD eeprom data by calling EEPROM driver
*
* Return values :
* ---------------
*
* Driver return value (OK in case of no error)
*
************************************************************************/
static INT32
spd_read(
UINT32 minor, /* Minor device number */
UINT32 offset, /* Byte position */
UINT32 length, /* Byte count */
void *user_variable ) /* Buffer for data */
{
t_EEPROM_read_descriptor readbuf;
readbuf.offset = offset;
readbuf.length = length;
readbuf.buffer = user_variable;
return IO_read( SYS_MAJOR_EEPROM_IIC, minor, &readbuf );
}
/************************************************************************
* Implementation : Static functions registered for handling particular
* SYSCON objects for particular platform(s)
************************************************************************/
/************************************************************************
* board_sn_generic_read
************************************************************************/
static UINT32
board_sn_generic_read(
void *param,
void *data )
{
t_sn_bcd *sn;
char *msg = (char *)param;
UINT8 number[3];
UINT32 i;
syscon_get_eeprom_data( NULL, &sn );
if( sn != NULL )
{
msg[0] = '\0';
for( i=0; i < SYS_SN_BCD_SIZE; i++ )
{
sprintf( number, "%d%d", (*sn)[i] >> 4, (*sn)[i] & 0xF );
strcat( msg, number );
}
return OK;
}
else
return ERROR_SYSCON_UNKNOWN_PARAM;
}
/************************************************************************
* com_en0_mac_addr_generic_read
************************************************************************/
static UINT32
com_en0_mac_addr_generic_read(
void *param,
void *data )
{
if(env_get("ethaddr", NULL, param, sizeof(t_mac_addr)) )
return OK;
else
{
printf("error reading MAC address");
return ERROR_SYSCON_UNKNOWN_PARAM;
}
#if 0
t_mac_addr *mac_addr;
t_mac_addr mac_addr_buffer;
if( sys_platform == PRODUCT_PB1000_ID)
{
/* PBUpdate - TThis will need to be updated so that each board can have
unique identifier */
mac_addr_buffer[0] = 0x00;
mac_addr_buffer[1] = 0x50;
mac_addr_buffer[2] = 0xc2;
mac_addr_buffer[3] = 0x0c;
mac_addr_buffer[4] = 0x20;
mac_addr_buffer[5] = 0x00;
mac_addr = &mac_addr_buffer;
}
else
syscon_get_eeprom_data( &mac_addr, NULL );
if( mac_addr != NULL )
{
memcpy( param, mac_addr, sizeof(t_mac_addr) );
return OK;
}
else
return ERROR_SYSCON_UNKNOWN_PARAM;
#endif
}
/************************************************************************
* com_en0_ip_addr_generic_read
************************************************************************/
static UINT32
com_en0_ip_addr_generic_read(
void *param,
void *data )
{
return
env_get( "ipaddr", NULL, param, sizeof(UINT32) ) ?
OK : ERROR_SYSCON_IP_UNKNOWN;
}
/************************************************************************
* com_en0_ip_subnetmask_generic_read
************************************************************************/
static UINT32
com_en0_ip_subnetmask_generic_read(
void *param,
void *data )
{
return
env_get( "subnetmask", NULL, param, sizeof(UINT32) ) ?
OK : ERROR_SYSCON_SUBNET_UNKNOWN;
}
/************************************************************************
* com_en0_ip_gatewayaddr_generic_read
************************************************************************/
static UINT32
com_en0_ip_gatewayaddr_generic_read(
void *param,
void *data )
{
return
env_get( "gateway", NULL, param, sizeof(UINT32) ) ?
OK : ERROR_SYSCON_GATEWAY_UNKNOWN;
}
/************************************************************************
* com_en0_enable
************************************************************************/
static UINT32
com_en0_enable(
void *param,
void *data )
{
shell_arch_dma( TRUE ) ;
return( OK ) ;
}
/************************************************************************
* com_en0_disable
************************************************************************/
static UINT32
com_en0_disable(
void *param,
void *data )
{
shell_arch_dma( FALSE ) ;
return( OK ) ;
}
/************************************************************************
* board_malloc_generic_read
************************************************************************/
static UINT32
board_malloc_generic_read(
void *param,
void *data )
{
t_sys_malloc *p_mem = param;
unsigned fraction, number;
*(p_mem->memory) = SYSCON_free;
fraction = (unsigned) SYSCON_free % (unsigned) p_mem->boundary;
number = (unsigned) SYSCON_free / (unsigned) p_mem->boundary;
if(fraction != 0)
{
/* align pointer */
*(p_mem->memory) = (void*)((number + 1) * p_mem->boundary);
}
/* Check fullfillment of memory request */
if((unsigned)((*(p_mem->memory)) + p_mem->size) > (unsigned) SYSCON_last)
{
p_mem->memory = NULL;
return ERROR_SYSCON_OUT_OF_MEMORY;
}
else
{
/* allocate memory */
SYSCON_free = (*(p_mem->memory)) + p_mem->size;
return OK;
}
}
/************************************************************************
* board_free_mem_generic_read
************************************************************************/
static UINT32
board_free_mem_generic_read(
void *param,
void *data )
{
*(UINT32 *)param = sys_freemem;
return OK;
}
/************************************************************************
* board_productid_generic_read
************************************************************************/
static UINT32
board_productid_generic_read(
void *param,
void *data )
{
*(UINT32 *)param = PRODUCT_PB1000_ID;
return OK;
}
/************************************************************************
* board_productrev_generic_read
************************************************************************/
static UINT32
board_productrev_generic_read(
void *param,
void *data )
{
*(UINT32 *)param = 0;
return OK;
}
/************************************************************************
* board_appl_stack_size_generic_read
************************************************************************/
static UINT32
board_appl_stack_size_generic_read(
void *param,
void *data )
{
*(UINT32 *)param = SYS_APPL_STACK_SIZE;
return OK;
}
/************************************************************************
* board_stack_size_generic_read
************************************************************************/
static UINT32
board_stack_size_generic_read(
void *param,
void *data )
{
*(UINT32 *)param = SYS_STACK_SIZE;
return OK;
}
/************************************************************************
* board_revision_generic_read
************************************************************************/
static UINT32
board_revision_generic_read(
void *param,
void *data )
{
*(UINT32 *)param = MIPS_REVISION;
return OK;
}
/************************************************************************
* board_cpu_clock_freq_generic_read
************************************************************************/
static UINT32
board_cpu_clock_freq_generic_read(
void *param,
void *data )
{
*(UINT32 *)param = sys_cpufreq_hz;
return OK;
}
/************************************************************************
* board_cpu_clock_freq_generic_write
************************************************************************/
static UINT32
board_cpu_clock_freq_generic_write(
void *param,
void *data )
{
sys_cpufreq_hz = *(UINT32 *)param;
return OK;
}
/************************************************************************
* board_bus_clock_freq_generic_read
************************************************************************/
static UINT32
board_bus_clock_freq_generic_read(
void *param,
void *data )
{
*(UINT32 *)param = sys_busfreq_hz;
return OK;
}
/************************************************************************
* board_bus_clock_freq_generic_write
************************************************************************/
static UINT32
board_bus_clock_freq_generic_write(
void *param,
void *data )
{
sys_busfreq_hz = *(UINT32 *)param;
return OK;
}
/************************************************************************
* cpu_icache_size_generic_read
************************************************************************/
static UINT32
cpu_icache_size_generic_read(
void *param,
void *data )
{
*(UINT32 *)param = sys_icache_linesize * sys_icache_lines;
return OK;
}
/************************************************************************
* cpu_icache_linesize_generic_read
************************************************************************/
static UINT32
cpu_icache_linesize_generic_read(
void *param,
void *data )
{
*(UINT32 *)param = sys_icache_linesize;
return OK;
}
/************************************************************************
* cpu_icache_assoc_generic_read
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -