s_bri.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 539 行 · 第 1/2 页

C
539
字号
/* *  Copyright (c) Eicon Networks, 2002. *  This source file is supplied for the use with  Eicon Networks range of DIVA Server Adapters. *  Eicon File Revision :    2.1 *  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, or (at your option)  any later version. *  This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY  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., 675 Mass Ave, Cambridge, MA 02139, USA. * */#include "platform.h"#include "di_defs.h"#include "pc.h"#include "pr_pc.h"#include "di.h"#include "mi_pc.h"#include "pc_maint.h"#include "divasync.h"#include "io.h"#include "helpers.h"#include "dsrv_bri.h"#include "dsp_defs.h"/*****************************************************************************/#define MAX_XLOG_SIZE (64 * 1024)/* --------------------------------------------------------------------------  Investigate card state, recovery trace buffer  -------------------------------------------------------------------------- */static void bri_cpu_trapped (PISDN_ADAPTER IoAdapter) { byte  *addrHi, *addrLo, *ioaddr ; word *Xlog ; dword   regs[4], i, size ; Xdesc   xlogDesc ; byte *Port;/* * first read pointers and trap frame */ if ( !(Xlog = (word *)diva_os_malloc (0, MAX_XLOG_SIZE)) )  return ; Port = DIVA_OS_MEM_ATTACH_PORT(IoAdapter); addrHi =   Port + ((IoAdapter->Properties.Bus == BUS_PCI) ? M_PCI_ADDRH : ADDRH) ; addrLo = Port + ADDR ; ioaddr = Port + DATA ; outpp (addrHi,  0) ; outppw (addrLo, 0) ; for ( i = 0 ; i < 0x100 ; Xlog[i++] = inppw(ioaddr) ) ;/* * check for trapped MIPS 3xxx CPU, dump only exception frame */ if ( READ_DWORD(&Xlog[0x80 / sizeof(Xlog[0])]) == 0x99999999 ) {  dump_trap_frame (IoAdapter, &((byte *)Xlog)[0x90]) ;  IoAdapter->trapped = 1 ; } regs[0] = READ_DWORD(&((byte *)Xlog)[0x70]); regs[1] = READ_DWORD(&((byte *)Xlog)[0x74]); regs[2] = READ_DWORD(&((byte *)Xlog)[0x78]); regs[3] = READ_DWORD(&((byte *)Xlog)[0x7c]); outpp (addrHi, (regs[1] >> 16) & 0x7F) ; outppw (addrLo, regs[1] & 0xFFFF) ; xlogDesc.cnt = inppw(ioaddr) ; outpp (addrHi, (regs[2] >> 16) & 0x7F) ; outppw (addrLo, regs[2] & 0xFFFF) ; xlogDesc.out = inppw(ioaddr) ; xlogDesc.buf = Xlog ; regs[0] &= IoAdapter->MemorySize - 1 ; if ( (regs[0] < IoAdapter->MemorySize - 1) ) {  size = IoAdapter->MemorySize - regs[0] ;  if ( size > MAX_XLOG_SIZE )   size = MAX_XLOG_SIZE ;  for ( i = 0 ; i < (size / sizeof(*Xlog)) ; regs[0] += 2 )  {   outpp (addrHi, (regs[0] >> 16) & 0x7F) ;   outppw (addrLo, regs[0] & 0xFFFF) ;   Xlog[i++] = inppw(ioaddr) ;  }  dump_xlog_buffer (IoAdapter, &xlogDesc) ;  diva_os_free (0, Xlog) ;  IoAdapter->trapped = 2 ; } outpp  (addrHi, (byte)((BRI_UNCACHED_ADDR (IoAdapter->MemoryBase + IoAdapter->MemorySize -                                            BRI_SHARED_RAM_SIZE)) >> 16)) ; outppw (addrLo, 0x00) ; DIVA_OS_MEM_DETACH_PORT(IoAdapter, Port);}/* ---------------------------------------------------------------------   Reset hardware  --------------------------------------------------------------------- */static void reset_bri_hardware (PISDN_ADAPTER IoAdapter) { byte *p = DIVA_OS_MEM_ATTACH_CTLREG(IoAdapter); outpp (p, 0x00) ; DIVA_OS_MEM_DETACH_CTLREG(IoAdapter, p);}/* ---------------------------------------------------------------------   Halt system  --------------------------------------------------------------------- */static void stop_bri_hardware (PISDN_ADAPTER IoAdapter) { byte *p = DIVA_OS_MEM_ATTACH_RESET(IoAdapter); if (p) {  outpp (p, 0x00) ; /* disable interrupts ! */ } DIVA_OS_MEM_DETACH_RESET(IoAdapter, p); p = DIVA_OS_MEM_ATTACH_CTLREG(IoAdapter); outpp (p, 0x00) ;    /* clear int, halt cpu */ DIVA_OS_MEM_DETACH_CTLREG(IoAdapter, p);}#if !defined(DIVA_USER_MODE_CARD_CONFIG) /* { *//* ---------------------------------------------------------------------  Load protocol on the card  --------------------------------------------------------------------- */static dword bri_protocol_load (PISDN_ADAPTER IoAdapter) { dword   FileLength ; word    test, *File = NULL ; byte*  addrHi, *addrLo, *ioaddr ; char   *FileName = &IoAdapter->Protocol[0] ; dword   Addr, i ; byte *Port; /* -------------------------------------------------------------------   Try to load protocol code. 'File' points to memory location   that does contain entire protocol code   ------------------------------------------------------------------- */ if ( !(File = (word *)xdiLoadArchive (IoAdapter, &FileLength, 0)) )  return (0) ; /* -------------------------------------------------------------------   Get protocol features and calculate load addresses   ------------------------------------------------------------------- */ IoAdapter->features = diva_get_protocol_file_features ((byte*)File,                     OFFS_PROTOCOL_ID_STRING,                     IoAdapter->ProtocolIdString,                     sizeof(IoAdapter->ProtocolIdString)); IoAdapter->a.protocol_capabilities = IoAdapter->features ; DBG_LOG(("Loading %s", IoAdapter->ProtocolIdString)) Addr = ((dword)(((byte *) File)[OFFS_PROTOCOL_END_ADDR]))   | (((dword)(((byte *) File)[OFFS_PROTOCOL_END_ADDR + 1])) << 8)   | (((dword)(((byte *) File)[OFFS_PROTOCOL_END_ADDR + 2])) << 16)   | (((dword)(((byte *) File)[OFFS_PROTOCOL_END_ADDR + 3])) << 24) ;        if ( Addr != 0 ) {  IoAdapter->DspCodeBaseAddr = (Addr + 3) & (~3) ;  IoAdapter->MaxDspCodeSize = (BRI_UNCACHED_ADDR (IoAdapter->MemoryBase + IoAdapter->MemorySize -                                                  BRI_SHARED_RAM_SIZE)                            - IoAdapter->DspCodeBaseAddr) & (IoAdapter->MemorySize - 1) ;  Addr = IoAdapter->DspCodeBaseAddr ;  ((byte *) File)[OFFS_DSP_CODE_BASE_ADDR] = (byte) Addr ;  ((byte *) File)[OFFS_DSP_CODE_BASE_ADDR + 1] = (byte)(Addr >> 8) ;  ((byte *) File)[OFFS_DSP_CODE_BASE_ADDR + 2] = (byte)(Addr >> 16) ;  ((byte *) File)[OFFS_DSP_CODE_BASE_ADDR + 3] = (byte)(Addr >> 24) ;  IoAdapter->InitialDspInfo = 0x80 ; } else {  if ( IoAdapter->features & PROTCAP_V90D )   IoAdapter->MaxDspCodeSize = BRI_V90D_MAX_DSP_CODE_SIZE ;  else   IoAdapter->MaxDspCodeSize = BRI_ORG_MAX_DSP_CODE_SIZE ;  IoAdapter->DspCodeBaseAddr = BRI_CACHED_ADDR (IoAdapter->MemoryBase + IoAdapter->MemorySize -                                                BRI_SHARED_RAM_SIZE - IoAdapter->MaxDspCodeSize);  IoAdapter->InitialDspInfo = (IoAdapter->MaxDspCodeSize - BRI_ORG_MAX_DSP_CODE_SIZE) >> 14 ; } DBG_LOG(("DSP code base 0x%08lx, max size 0x%08lx (%08lx,%02x)",      IoAdapter->DspCodeBaseAddr, IoAdapter->MaxDspCodeSize,      Addr, IoAdapter->InitialDspInfo)) if ( FileLength > ((IoAdapter->DspCodeBaseAddr -                     BRI_CACHED_ADDR (IoAdapter->MemoryBase)) & (IoAdapter->MemorySize - 1)) ) {  xdiFreeFile (File);  DBG_FTL(("Protocol code '%s' too big (%ld)", FileName, FileLength))  return (0) ; } Port = DIVA_OS_MEM_ATTACH_PORT(IoAdapter); addrHi =   Port + ((IoAdapter->Properties.Bus == BUS_PCI) ? M_PCI_ADDRH : ADDRH) ; addrLo = Port + ADDR ; ioaddr = Port + DATA ;/* * set start address for download (use autoincrement mode !) */ outpp  (addrHi, 0) ; outppw (addrLo, 0) ; for ( i = 0 ; i < FileLength ; i += 2 ) {  if ( (i & 0x0000FFFF) == 0 )  {   outpp (addrHi, (byte)(i >> 16)) ;  }  outppw (ioaddr, File[i/2]) ; }/* * memory test without second load of file */ outpp  (addrHi, 0) ; outppw (addrLo, 0) ; for ( i = 0 ; i < FileLength ; i += 2 ) {  if ( (i & 0x0000FFFF) == 0 )  {   outpp (addrHi, (byte)(i >> 16)) ;  }  test = inppw (ioaddr) ;  if ( test != File[i/2] )  {   DIVA_OS_MEM_DETACH_PORT(IoAdapter, Port);   DBG_FTL(("%s: Memory test failed! (%d - 0x%04X/0x%04X)",            IoAdapter->Properties.Name, i, test, File[i/2]))   xdiFreeFile (File);   return (0) ;  } } DIVA_OS_MEM_DETACH_PORT(IoAdapter, Port); xdiFreeFile (File); return (FileLength) ;}/******************************************************************************/typedef struct{ PISDN_ADAPTER IoAdapter ; byte*        AddrLo ; byte*        AddrHi ; word*       Data ; dword         DownloadPos ;} bri_download_info ;static long bri_download_buffer (OsFileHandle *fp, long length, void **addr) { int        buffer_size = 2048*sizeof(word); word       *buffer = (word*)diva_os_malloc (0, buffer_size); bri_download_info *info ; word       test ; long       i, len, page ; if (!buffer) {  DBG_ERR(("A: out of memory, s_bri at %d", __LINE__))  return (-1); } info = (bri_download_info *)fp->sysLoadDesc ; *addr = (void *)info->DownloadPos ; if ( ((dword) length) > info->IoAdapter->DspCodeBaseAddr +                         info->IoAdapter->MaxDspCodeSize - info->DownloadPos ) {  DBG_FTL(("%s: out of card memory during DSP download (0x%X)",           info->IoAdapter->Properties.Name,           info->DownloadPos + length))  diva_os_free (0, buffer);  return (-1) ; } for ( len = 0 ; length > 0 ; length -= len ) {  len = (length > buffer_size ? buffer_size : length) ;  page = ((long)(info->DownloadPos) + len) & 0xFFFF0000 ;  if ( page != (long)(info->DownloadPos & 0xFFFF0000) )  {   len = 0x00010000 - (((long)info->DownloadPos) & 0x0000FFFF) ;  }  if ( fp->sysFileRead (fp, &buffer[0], len) != len ) {   diva_os_free (0, buffer);   return (-1) ;  }  outpp (info->AddrHi, (byte)(info->DownloadPos >> 16)) ;  outppw (info->AddrLo, (word)info->DownloadPos) ;

⌨️ 快捷键说明

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