s_pri.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 568 行 · 第 1/2 页
C
568 行
/* * 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_pri.h"#include "dsp_defs.h"/*****************************************************************************/#define MAX_XLOG_SIZE (64 * 1024)/* ------------------------------------------------------------------------- Does return offset between ADAPTER->ram and real begin of memory ------------------------------------------------------------------------- */static dword pri_ram_offset (ADAPTER* a) { return ((dword)MP_SHARED_RAM_OFFSET);}/* ------------------------------------------------------------------------- Recovery XLOG buffer from the card ------------------------------------------------------------------------- */static void pri_cpu_trapped (PISDN_ADAPTER IoAdapter) { byte *base ; word *Xlog ; dword regs[4], TrapID, size ; Xdesc xlogDesc ;/* * check for trapped MIPS 46xx CPU, dump exception frame */ base = DIVA_OS_MEM_ATTACH_ADDRESS(IoAdapter); TrapID = READ_DWORD(&base[0x80]) ; if ( (TrapID == 0x99999999) || (TrapID == 0x99999901) ) { dump_trap_frame (IoAdapter, &base[0x90]) ; IoAdapter->trapped = 1 ; } regs[0] = READ_DWORD(&base[MP_PROTOCOL_OFFSET + 0x70]); regs[1] = READ_DWORD(&base[MP_PROTOCOL_OFFSET + 0x74]); regs[2] = READ_DWORD(&base[MP_PROTOCOL_OFFSET + 0x78]); regs[3] = READ_DWORD(&base[MP_PROTOCOL_OFFSET + 0x7c]); regs[0] &= IoAdapter->MemorySize - 1 ; if ( (regs[0] < IoAdapter->MemorySize - 1) ) { if ( !(Xlog = (word *)diva_os_malloc (0, MAX_XLOG_SIZE)) ) { DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, base); return ; } size = IoAdapter->MemorySize - regs[0] ; if ( size > MAX_XLOG_SIZE ) size = MAX_XLOG_SIZE ; memcpy (Xlog, &base[regs[0]], size) ; xlogDesc.buf = Xlog ; xlogDesc.cnt = READ_WORD(&base[regs[1] & (IoAdapter->MemorySize - 1)]) ; xlogDesc.out = READ_WORD(&base[regs[2] & (IoAdapter->MemorySize - 1)]) ; dump_xlog_buffer (IoAdapter, &xlogDesc) ; diva_os_free (0, Xlog) ; IoAdapter->trapped = 2 ; } DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, base);}/* ------------------------------------------------------------------------- Hardware reset of PRI card ------------------------------------------------------------------------- */static void reset_pri_hardware (PISDN_ADAPTER IoAdapter) { byte *p = DIVA_OS_MEM_ATTACH_RESET(IoAdapter); *p = _MP_RISC_RESET | _MP_LED1 | _MP_LED2 ; diva_os_wait (50) ; *p = 0x00 ; diva_os_wait (50) ; DIVA_OS_MEM_DETACH_RESET(IoAdapter, p);}/* ------------------------------------------------------------------------- Stop Card Hardware ------------------------------------------------------------------------- */static void stop_pri_hardware (PISDN_ADAPTER IoAdapter) { dword i; byte *p; dword volatile *cfgReg = (dword volatile *)DIVA_OS_MEM_ATTACH_CFG(IoAdapter); cfgReg[3] = 0x00000000 ; cfgReg[1] = 0x00000000 ; DIVA_OS_MEM_DETACH_CFG(IoAdapter, cfgReg); IoAdapter->a.ram_out (&IoAdapter->a, &RAM->SWReg, SWREG_HALT_CPU) ; i = 0 ; while ( (i < 100) && (IoAdapter->a.ram_in (&IoAdapter->a, &RAM->SWReg) != 0) ) { diva_os_wait (1) ; i++ ; } DBG_TRC(("%s: PRI stopped (%d)", IoAdapter->Name, i)) cfgReg = (dword volatile *)DIVA_OS_MEM_ATTACH_CFG(IoAdapter); WRITE_DWORD(&cfgReg[0],((dword)(~0x03E00000))); DIVA_OS_MEM_DETACH_CFG(IoAdapter, cfgReg); diva_os_wait (1) ; p = DIVA_OS_MEM_ATTACH_RESET(IoAdapter); *p = _MP_RISC_RESET | _MP_LED1 | _MP_LED2 ; DIVA_OS_MEM_DETACH_RESET(IoAdapter, p);}#if !defined(DIVA_USER_MODE_CARD_CONFIG) /* { *//* ------------------------------------------------------------------------- Load protocol code to the PRI Card ------------------------------------------------------------------------- */#define DOWNLOAD_ADDR(IoAdapter) (IoAdapter->downloadAddr & (IoAdapter->MemorySize - 1))static int pri_protocol_load (PISDN_ADAPTER IoAdapter) { dword FileLength ; dword *File ; dword *sharedRam ; dword Addr ; byte *p; if (!(File = (dword *)xdiLoadArchive (IoAdapter, &FileLength, 0))) { return (0) ; } 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 = (MP_UNCACHED_ADDR (IoAdapter->MemorySize) - 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_VOIP ) IoAdapter->MaxDspCodeSize = MP_VOIP_MAX_DSP_CODE_SIZE ; else if ( IoAdapter->features & PROTCAP_V90D ) IoAdapter->MaxDspCodeSize = MP_V90D_MAX_DSP_CODE_SIZE ; else IoAdapter->MaxDspCodeSize = MP_ORG_MAX_DSP_CODE_SIZE ; IoAdapter->DspCodeBaseAddr = MP_CACHED_ADDR (IoAdapter->MemorySize - IoAdapter->MaxDspCodeSize) ; IoAdapter->InitialDspInfo = (IoAdapter->MaxDspCodeSize - MP_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 - MP_CACHED_ADDR (MP_PROTOCOL_OFFSET)) & (IoAdapter->MemorySize - 1)) ) { xdiFreeFile (File); DBG_FTL(("Protocol code '%s' too long (%ld)", &IoAdapter->Protocol[0], FileLength)) return (0) ; } IoAdapter->downloadAddr = MP_UNCACHED_ADDR (MP_PROTOCOL_OFFSET) ; p = DIVA_OS_MEM_ATTACH_RAM(IoAdapter); sharedRam = (dword *)(&p[DOWNLOAD_ADDR(IoAdapter)]); memcpy (sharedRam, File, FileLength) ; if ( memcmp (sharedRam, File, FileLength) ) { DIVA_OS_MEM_DETACH_RAM(IoAdapter, p); DBG_FTL(("%s: Memory test failed!", IoAdapter->Properties.Name)) xdiFreeFile (File); return (0) ; } DIVA_OS_MEM_DETACH_RAM(IoAdapter, p); xdiFreeFile (File); return (1) ;}/******************************************************************************//*------------------------------------------------------------------ Dsp related definitions ------------------------------------------------------------------ */#define DSP_SIGNATURE_PROBE_WORD 0x5a5a/*** Checks presence of DSP on board*/static intdsp_check_presence (volatile byte* addr, volatile byte* data, int dsp){ word pattern; *(volatile word*)addr = 0x4000; *(volatile word*)data = DSP_SIGNATURE_PROBE_WORD; *(volatile word*)addr = 0x4000; pattern = *(volatile word*)data; if (pattern != DSP_SIGNATURE_PROBE_WORD) { DBG_TRC(("W: DSP[%d] %04x(is) != %04x(should)", dsp, pattern, DSP_SIGNATURE_PROBE_WORD)) return (-1); } *(volatile word*)addr = 0x4000; *(volatile word*)data = ~DSP_SIGNATURE_PROBE_WORD; *(volatile word*)addr = 0x4000; pattern = *(volatile word*)data; if (pattern != (word)~DSP_SIGNATURE_PROBE_WORD) { DBG_ERR(("A: DSP[%d] %04x(is) != %04x(should)", dsp, pattern, (word)~DSP_SIGNATURE_PROBE_WORD)) return (-2); } DBG_TRC (("DSP[%d] present", dsp)) return (0);}/*** Check if DSP's are present and operating** Information about detected DSP's is returned as bit mask** Bit 0 - DSP1** ...** ...** ...** Bit 29 - DSP30*/static dworddiva_pri_detect_dsps (PISDN_ADAPTER IoAdapter){ byte* base; byte* p; dword ret = 0, DspCount = 0 ; dword row_offset[] = { 0x00000000, 0x00000800, /* 1 - ROW 1 */ 0x00000840, /* 2 - ROW 2 */ 0x00001000, /* 3 - ROW 3 */ 0x00001040, /* 4 - ROW 4 */ 0x00000000 /* 5 - ROW 0 */ }; byte *dsp_addr_port, *dsp_data_port, row_state; int dsp_row = 0, dsp_index, dsp_num; IoAdapter->InitialDspInfo &= 0xffff ; p = DIVA_OS_MEM_ATTACH_RESET(IoAdapter); if (!p) { DIVA_OS_MEM_DETACH_RESET(IoAdapter, p); return (0); } *(volatile byte*)(p) = _MP_RISC_RESET | _MP_DSP_RESET; DIVA_OS_MEM_DETACH_RESET(IoAdapter, p); diva_os_wait (5) ; base = DIVA_OS_MEM_ATTACH_CONTROL(IoAdapter); for (dsp_num = 0; dsp_num < 30; dsp_num++) { dsp_row = dsp_num / 7 + 1; dsp_index = dsp_num % 7; dsp_data_port = base; dsp_addr_port = base; dsp_data_port += row_offset[dsp_row]; dsp_addr_port += row_offset[dsp_row]; dsp_data_port += (dsp_index * 8); dsp_addr_port += (dsp_index * 8) + 0x80; if (!dsp_check_presence (dsp_addr_port, dsp_data_port, dsp_num+1)) { ret |= (1 << dsp_num); DspCount++ ; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?