⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_pri.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Id: os_pri.c,v 1.32 2004/03/21 17:26:01 armin Exp $ */#include "platform.h"#include "debuglib.h"#include "cardtype.h"#include "pc.h"#include "pr_pc.h"#include "di_defs.h"#include "dsp_defs.h"#include "di.h"#include "io.h"#include "xdi_msg.h"#include "xdi_adapter.h"#include "os_pri.h"#include "diva_pci.h"#include "mi_pc.h"#include "pc_maint.h"#include "dsp_tst.h"#include "diva_dma.h"/* --------------------------------------------------------------------------   OS Dependent part of XDI driver for DIVA PRI Adapter   DSP detection/validation by Anthony Booth (Eicon Networks, www.eicon.com)-------------------------------------------------------------------------- */#define DIVA_PRI_NO_PCI_BIOS_WORKAROUND 1extern int diva_card_read_xlog(diva_os_xdi_adapter_t * a);/***  IMPORTS*/extern void prepare_pri_functions(PISDN_ADAPTER IoAdapter);extern void prepare_pri2_functions(PISDN_ADAPTER IoAdapter);extern void diva_xdi_display_adapter_features(int card);static int diva_pri_cleanup_adapter(diva_os_xdi_adapter_t * a);static int diva_pri_cmd_card_proc(struct _diva_os_xdi_adapter *a,				  diva_xdi_um_cfg_cmd_t * cmd, int length);static int pri_get_serial_number(diva_os_xdi_adapter_t * a);static int diva_pri_stop_adapter(diva_os_xdi_adapter_t * a);static dword diva_pri_detect_dsps(diva_os_xdi_adapter_t * a);/***  Check card revision*/static int pri_is_rev_2_card(int card_ordinal){	switch (card_ordinal) {	case CARDTYPE_DIVASRV_P_30M_V2_PCI:	case CARDTYPE_DIVASRV_VOICE_P_30M_V2_PCI:		return (1);	}	return (0);}static void diva_pri_set_addresses(diva_os_xdi_adapter_t * a){	a->resources.pci.mem_type_id[MEM_TYPE_ADDRESS] = 0;	a->resources.pci.mem_type_id[MEM_TYPE_CONTROL] = 2;	a->resources.pci.mem_type_id[MEM_TYPE_CONFIG] = 4;	a->resources.pci.mem_type_id[MEM_TYPE_RAM] = 0;	a->resources.pci.mem_type_id[MEM_TYPE_RESET] = 2;	a->resources.pci.mem_type_id[MEM_TYPE_CFG] = 4;	a->resources.pci.mem_type_id[MEM_TYPE_PROM] = 3;		a->xdi_adapter.Address = a->resources.pci.addr[0];	a->xdi_adapter.Control = a->resources.pci.addr[2];	a->xdi_adapter.Config = a->resources.pci.addr[4];	a->xdi_adapter.ram = a->resources.pci.addr[0];	a->xdi_adapter.ram += MP_SHARED_RAM_OFFSET;	a->xdi_adapter.reset = a->resources.pci.addr[2];	a->xdi_adapter.reset += MP_RESET;	a->xdi_adapter.cfg = a->resources.pci.addr[4];	a->xdi_adapter.cfg += MP_IRQ_RESET;	a->xdi_adapter.sdram_bar = a->resources.pci.bar[0];	a->xdi_adapter.prom = a->resources.pci.addr[3];}/***  BAR0 - SDRAM, MP_MEMORY_SIZE, MP2_MEMORY_SIZE by Rev.2**  BAR1 - DEVICES,				0x1000**  BAR2 - CONTROL (REG), 0x2000**  BAR3 - FLASH (REG),		0x8000**  BAR4 - CONFIG (CFG),	0x1000*/int diva_pri_init_card(diva_os_xdi_adapter_t * a){	int bar = 0;	int pri_rev_2;	unsigned long bar_length[5] = {		MP_MEMORY_SIZE,		0x1000,		0x2000,		0x8000,		0x1000	};	pri_rev_2 = pri_is_rev_2_card(a->CardOrdinal);	if (pri_rev_2) {		bar_length[0] = MP2_MEMORY_SIZE;	}	/*	   Set properties	 */	a->xdi_adapter.Properties = CardProperties[a->CardOrdinal];	DBG_LOG(("Load %s", a->xdi_adapter.Properties.Name))	/*	   First initialization step: get and check hardware resoures.	   Do not map resources and do not acecess card at this step	 */	for (bar = 0; bar < 5; bar++) {		a->resources.pci.bar[bar] =		    divasa_get_pci_bar(a->resources.pci.bus,				       a->resources.pci.func, bar,				       a->resources.pci.hdev);		if (!a->resources.pci.bar[bar]		    || (a->resources.pci.bar[bar] == 0xFFFFFFF0)) {			DBG_ERR(("A: invalid bar[%d]=%08x", bar,				 a->resources.pci.bar[bar]))			return (-1);		}	}	a->resources.pci.irq =	    (byte) divasa_get_pci_irq(a->resources.pci.bus,				      a->resources.pci.func,				      a->resources.pci.hdev);	if (!a->resources.pci.irq) {		DBG_ERR(("A: invalid irq"));		return (-1);	}	/*	   Map all BAR's	 */	for (bar = 0; bar < 5; bar++) {		a->resources.pci.addr[bar] =		    divasa_remap_pci_bar(a, bar, a->resources.pci.bar[bar],					 bar_length[bar]);		if (!a->resources.pci.addr[bar]) {			DBG_ERR(("A: A(%d), can't map bar[%d]",				 a->controller, bar))			diva_pri_cleanup_adapter(a);			return (-1);		}	}	/*	   Set all memory areas	 */	diva_pri_set_addresses(a);	/*	   Get Serial Number of this adapter	 */	if (pri_get_serial_number(a)) {		dword serNo;		serNo = a->resources.pci.bar[1] & 0xffff0000;		serNo |= ((dword) a->resources.pci.bus) << 8;		serNo += (a->resources.pci.func + a->controller + 1);		a->xdi_adapter.serialNo = serNo & ~0xFF000000;		DBG_ERR(("A: A(%d) can't get Serial Number, generated serNo=%ld",			 a->controller, a->xdi_adapter.serialNo))	}	/*	   Initialize os objects	 */	if (diva_os_initialize_spin_lock(&a->xdi_adapter.isr_spin_lock, "isr")) {		diva_pri_cleanup_adapter(a);		return (-1);	}	if (diva_os_initialize_spin_lock	    (&a->xdi_adapter.data_spin_lock, "data")) {		diva_pri_cleanup_adapter(a);		return (-1);	}	strcpy(a->xdi_adapter.req_soft_isr.dpc_thread_name, "kdivasprid");	if (diva_os_initialize_soft_isr(&a->xdi_adapter.req_soft_isr,					DIDpcRoutine, &a->xdi_adapter)) {		diva_pri_cleanup_adapter(a);		return (-1);	}	/*	   Do not initialize second DPC - only one thread will be created	 */	a->xdi_adapter.isr_soft_isr.object =	    a->xdi_adapter.req_soft_isr.object;	/*	   Next step of card initialization:	   set up all interface pointers	 */	a->xdi_adapter.Channels = CardProperties[a->CardOrdinal].Channels;	a->xdi_adapter.e_max = CardProperties[a->CardOrdinal].E_info;	a->xdi_adapter.e_tbl =	    diva_os_malloc(0, a->xdi_adapter.e_max * sizeof(E_INFO));	if (!a->xdi_adapter.e_tbl) {		diva_pri_cleanup_adapter(a);		return (-1);	}	memset(a->xdi_adapter.e_tbl, 0x00, a->xdi_adapter.e_max * sizeof(E_INFO));	a->xdi_adapter.a.io = &a->xdi_adapter;	a->xdi_adapter.DIRequest = request;	a->interface.cleanup_adapter_proc = diva_pri_cleanup_adapter;	a->interface.cmd_proc = diva_pri_cmd_card_proc;	if (pri_rev_2) {		prepare_pri2_functions(&a->xdi_adapter);	} else {		prepare_pri_functions(&a->xdi_adapter);	}	a->dsp_mask = diva_pri_detect_dsps(a);	/*	   Allocate DMA map	 */	if (pri_rev_2) {		diva_init_dma_map(a->resources.pci.hdev,				  (struct _diva_dma_map_entry **) &a->xdi_adapter.dma_map, 32);	}	/*	   Set IRQ handler	 */	a->xdi_adapter.irq_info.irq_nr = a->resources.pci.irq;	sprintf(a->xdi_adapter.irq_info.irq_name,		"DIVA PRI %ld", (long) a->xdi_adapter.serialNo);	if (diva_os_register_irq(a, a->xdi_adapter.irq_info.irq_nr,				 a->xdi_adapter.irq_info.irq_name)) {		diva_pri_cleanup_adapter(a);		return (-1);	}	a->xdi_adapter.irq_info.registered = 1;	diva_log_info("%s IRQ:%d SerNo:%d", a->xdi_adapter.Properties.Name,		      a->resources.pci.irq, a->xdi_adapter.serialNo);	return (0);}static int diva_pri_cleanup_adapter(diva_os_xdi_adapter_t * a){	int bar = 0;	/*	   Stop Adapter if adapter is running	 */	if (a->xdi_adapter.Initialized) {		diva_pri_stop_adapter(a);	}	/*	   Remove ISR Handler	 */	if (a->xdi_adapter.irq_info.registered) {		diva_os_remove_irq(a, a->xdi_adapter.irq_info.irq_nr);	}	a->xdi_adapter.irq_info.registered = 0;	/*	   Step 1: unmap all BAR's, if any was mapped	 */	for (bar = 0; bar < 5; bar++) {		if (a->resources.pci.bar[bar]		    && a->resources.pci.addr[bar]) {			divasa_unmap_pci_bar(a->resources.pci.addr[bar]);			a->resources.pci.bar[bar] = 0;			a->resources.pci.addr[bar] = NULL;		}	}	/*	   Free OS objects	 */	diva_os_cancel_soft_isr(&a->xdi_adapter.isr_soft_isr);	diva_os_cancel_soft_isr(&a->xdi_adapter.req_soft_isr);	diva_os_remove_soft_isr(&a->xdi_adapter.req_soft_isr);	a->xdi_adapter.isr_soft_isr.object = NULL;	diva_os_destroy_spin_lock(&a->xdi_adapter.isr_spin_lock, "rm");	diva_os_destroy_spin_lock(&a->xdi_adapter.data_spin_lock, "rm");	/*	   Free memory accupied by XDI adapter	 */	if (a->xdi_adapter.e_tbl) {		diva_os_free(0, a->xdi_adapter.e_tbl);		a->xdi_adapter.e_tbl = NULL;	}	a->xdi_adapter.Channels = 0;	a->xdi_adapter.e_max = 0;	/*	   Free adapter DMA map	 */	diva_free_dma_map(a->resources.pci.hdev,			  (struct _diva_dma_map_entry *) a->xdi_adapter.			  dma_map);	a->xdi_adapter.dma_map = NULL;	/*	   Detach this adapter from debug driver	 */	return (0);}/***  Activate On Board Boot Loader*/static int diva_pri_reset_adapter(PISDN_ADAPTER IoAdapter){	dword i;	struct mp_load __iomem *boot;	if (!IoAdapter->Address || !IoAdapter->reset) {		return (-1);	}	if (IoAdapter->Initialized) {		DBG_ERR(("A: A(%d) can't reset PRI adapter - please stop first",			 IoAdapter->ANum))		return (-1);	}	boot = (struct mp_load __iomem *) DIVA_OS_MEM_ATTACH_ADDRESS(IoAdapter);	WRITE_DWORD(&boot->err, 0);	DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, boot);	IoAdapter->rstFnc(IoAdapter);	diva_os_wait(10);	boot = (struct mp_load __iomem *) DIVA_OS_MEM_ATTACH_ADDRESS(IoAdapter);	i = READ_DWORD(&boot->live);	diva_os_wait(10);	if (i == READ_DWORD(&boot->live)) {		DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, boot);		DBG_ERR(("A: A(%d) CPU on PRI %ld is not alive!",			 IoAdapter->ANum, IoAdapter->serialNo))		return (-1);	}	if (READ_DWORD(&boot->err)) {		DBG_ERR(("A: A(%d) PRI %ld Board Selftest failed, error=%08lx",			 IoAdapter->ANum, IoAdapter->serialNo,			 READ_DWORD(&boot->err)))		DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, boot);		return (-1);	}	DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, boot);	/*	   Forget all outstanding entities	 */	IoAdapter->e_count = 0;	if (IoAdapter->e_tbl) {		memset(IoAdapter->e_tbl, 0x00,		       IoAdapter->e_max * sizeof(E_INFO));	}	IoAdapter->head = 0;	IoAdapter->tail = 0;	IoAdapter->assign = 0;	IoAdapter->trapped = 0;	memset(&IoAdapter->a.IdTable[0], 0x00,	       sizeof(IoAdapter->a.IdTable));	memset(&IoAdapter->a.IdTypeTable[0], 0x00,	       sizeof(IoAdapter->a.IdTypeTable));	memset(&IoAdapter->a.FlowControlIdTable[0], 0x00,	       sizeof(IoAdapter->a.FlowControlIdTable));	memset(&IoAdapter->a.FlowControlSkipTable[0], 0x00,	       sizeof(IoAdapter->a.FlowControlSkipTable));	memset(&IoAdapter->a.misc_flags_table[0], 0x00,	       sizeof(IoAdapter->a.misc_flags_table));	memset(&IoAdapter->a.rx_stream[0], 0x00,	       sizeof(IoAdapter->a.rx_stream));	memset(&IoAdapter->a.tx_stream[0], 0x00,	       sizeof(IoAdapter->a.tx_stream));	memset(&IoAdapter->a.tx_pos[0], 0x00, sizeof(IoAdapter->a.tx_pos));	memset(&IoAdapter->a.rx_pos[0], 0x00, sizeof(IoAdapter->a.rx_pos));	return (0);}static intdiva_pri_write_sdram_block(PISDN_ADAPTER IoAdapter,			   dword address,			   const byte * data, dword length, dword limit){	byte __iomem *p = DIVA_OS_MEM_ATTACH_ADDRESS(IoAdapter);	byte __iomem *mem = p;	if (((address + length) >= limit) || !mem) {		DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, p);		DBG_ERR(("A: A(%d) write PRI address=0x%08lx",			 IoAdapter->ANum, address + length))		return (-1);	}	mem += address;	/* memcpy_toio(), maybe? */	while (length--) {		WRITE_BYTE(mem++, *data++);	}	DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, p);	return (0);}static intdiva_pri_start_adapter(PISDN_ADAPTER IoAdapter,		       dword start_address, dword features){	dword i;	int started = 0;	byte __iomem *p;	struct mp_load __iomem *boot = (struct mp_load __iomem *) DIVA_OS_MEM_ATTACH_ADDRESS(IoAdapter);	ADAPTER *a = &IoAdapter->a;	if (IoAdapter->Initialized) {		DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, boot);		DBG_ERR(("A: A(%d) pri_start_adapter, adapter already running",			 IoAdapter->ANum))		return (-1);	}	if (!boot) {		DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, boot);		DBG_ERR(("A: PRI %ld can't start, adapter not mapped",			 IoAdapter->serialNo))		return (-1);	}	sprintf(IoAdapter->Name, "A(%d)", (int) IoAdapter->ANum);	DBG_LOG(("A(%d) start PRI at 0x%08lx", IoAdapter->ANum,		 start_address))	WRITE_DWORD(&boot->addr, start_address);	WRITE_DWORD(&boot->cmd, 3);	for (i = 0; i < 300; ++i) {		diva_os_wait(10);		if ((READ_DWORD(&boot->signature) >> 16) == 0x4447) {			DBG_LOG(("A(%d) Protocol startup time %d.%02d seconds",				 IoAdapter->ANum, (i / 100), (i % 100)))			started = 1;			break;		}	}	if (!started) {		byte __iomem *p = (byte __iomem *)boot;		dword TrapId;		dword debug;		TrapId = READ_DWORD(&p[0x80]);		debug = READ_DWORD(&p[0x1c]);		DBG_ERR(("A(%d) Adapter start failed 0x%08lx, TrapId=%08lx, debug=%08lx",			 IoAdapter->ANum, READ_DWORD(&boot->signature),			 TrapId, debug))		DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, boot);		if (IoAdapter->trapFnc) {			(*(IoAdapter->trapFnc)) (IoAdapter);		}		IoAdapter->stop(IoAdapter);		return (-1);	}	DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, boot);	IoAdapter->Initialized = TRUE;	/*	   Check Interrupt	 */	IoAdapter->IrqCount = 0;	p = DIVA_OS_MEM_ATTACH_CFG(IoAdapter);	WRITE_DWORD(p, (dword) ~ 0x03E00000);	DIVA_OS_MEM_DETACH_CFG(IoAdapter, p);	a->ReadyInt = 1;	a->ram_out(a, &PR_RAM->ReadyInt, 1);	for (i = 100; !IoAdapter->IrqCount && (i-- > 0); diva_os_wait(10));	if (!IoAdapter->IrqCount) {		DBG_ERR(("A: A(%d) interrupt test failed",			 IoAdapter->ANum))		IoAdapter->Initialized = FALSE;		IoAdapter->stop(IoAdapter);		return (-1);	}	IoAdapter->Properties.Features = (word) features;	diva_xdi_display_adapter_features(IoAdapter->ANum);	DBG_LOG(("A(%d) PRI adapter successfull started", IoAdapter->ANum))	/*	   Register with DIDD	 */	diva_xdi_didd_register_adapter(IoAdapter->ANum);	return (0);}static void diva_pri_clear_interrupts(diva_os_xdi_adapter_t * a){	PISDN_ADAPTER IoAdapter = &a->xdi_adapter;

⌨️ 快捷键说明

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