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

📄 tmhal.c

📁 wince host 和 target PCI驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
TMStatus	halRestoreInterrupts ( 
	UInt32	HalHandle,
	UInt32* Saved );

TMStatus	halDisableIRQ ( 
	UInt32	HalHandle )
{
	HalObject*	Hal = (HalObject*)HalHandle;
	ULONG	InterruptControl;

	if ( objectValidate ( Hal, HalFourCC ) != True )
	{
		DPF(0,("tmman:halDisableIRQ:objectValidate:FAIL\n" ));
		return statusInvalidHandle;
	}
	InterruptControl = *(Hal->MMIOAddrKernel + INT_CTL);

	// here SelfInterrupt indicates PCI Interrupt A
	// INT#A = 0, INT#B = 1, INT#C = 2, INT#D = 3
	// disable interrupts from the target by INT_CTL->IE off.
	InterruptControl &= ~( 0x10 << ( Hal->SelfInterrupt ) );

	*(PULONG)(Hal->MMIOAddrKernel + INT_CTL) = InterruptControl;

	return statusSuccess;
}

TMStatus	halEnableIRQ ( 
	UInt32	HalHandle )
{
	HalObject*	Hal = (HalObject*)HalHandle;
	ULONG	InterruptControl;

	if ( objectValidate ( Hal, HalFourCC ) != True )
	{
		DPF(0,("tmman:halEnableIRQ:objectValidate:FAIL\n" ));
		return statusInvalidHandle;
	}
	InterruptControl = *(Hal->MMIOAddrKernel + INT_CTL);
	InterruptControl |= ( 0x10 << ( Hal->SelfInterrupt ) );
	*(PULONG)(Hal->MMIOAddrKernel + INT_CTL) = InterruptControl;

	return statusSuccess;
}

TMStatus	halGenerateInterrupt ( 
	UInt32	HalHandle )
{
	HalObject*	Hal = (HalObject*)HalHandle;
	if ( objectValidate ( Hal, HalFourCC ) != True )
	{
		DPF(0,("tmman:halGenerateInterrupt:objectValidate:FAIL\n" ));
		return statusInvalidHandle;
	}

	DPF(0,("tmman:halGenerateInterrupt1:IPENDING[%x]:ICLEAR[%x]:IMASK[%x]\n",
		*(PULONG)(Hal->MMIOAddrKernel + IPENDING),
		*(PULONG)(Hal->MMIOAddrKernel + ICLEAR),
		*(PULONG)(Hal->MMIOAddrKernel + IMASK ) ));	

	*(PULONG)(Hal->MMIOAddrKernel + IPENDING) = ( 1<< Hal->PeerInterrupt ); 

	DPF(0,("tmman:halGenerateInterrupt2:IPENDING[%x]:ICLEAR[%x]:IMASK[%x]\n",
		*(PULONG)(Hal->MMIOAddrKernel + IPENDING),
		*(PULONG)(Hal->MMIOAddrKernel + ICLEAR),
		*(PULONG)(Hal->MMIOAddrKernel + IMASK ) ));	

	return statusSuccess;
}

TMStatus	halAcknowledgeInterrupt (
	UInt32	HalHandle )
{
	HalObject*	Hal = (HalObject*)HalHandle;
	ULONG	InterruptControl;

	if ( objectValidate ( Hal, HalFourCC ) != True )
	{
		DPF(0,("tmman:halAcknowledgeInterrupt:objectValidate:FAIL\n" ));
		return statusInvalidHandle;
	}

	/* FOR TM1 */
	/*
		reset	MMIO->dwInterruptControl:INT(3..0)
		reset	MMIO->dwInterruptControl:IE(7..4)
	*/
	while ( 1 )
	{
		if ( halAccess32 ( HalHandle, 
			Hal->Control->TargetInterruptSpinLock  ) == False )
		{
			Hal->Control->HostInterruptSpinLock = 
				halAccess32 ( HalHandle, True  );

			if ( halAccess32 ( HalHandle, 
				Hal->Control->TargetInterruptSpinLock  ) == True )
			{
				Hal->Control->HostInterruptSpinLock = 
					halAccess32 ( HalHandle, False  );			
			}
			else
			{
				InterruptControl = *(Hal->MMIOAddrKernel + INT_CTL);

				// here SelfInterrupt indicates PCI Interrupt A
				// INT#A = 0, INT#B = 1, INT#C = 2, INT#D = 3
				InterruptControl &=
					( ~( 1 << ( Hal->SelfInterrupt ) )  &
					~( 0x10 << ( Hal->SelfInterrupt ) ) );

				*(PULONG)(Hal->MMIOAddrKernel + INT_CTL) = InterruptControl;

				Hal->Control->HostInterruptSpinLock = 
					halAccess32 ( HalHandle, False  );
				break;
			}

		}
	}

	return statusSuccess;
}

DWORD WINAPI	halHardwareInterruptHandler ( PVOID ServiceContext  )
{
    // we should be getting the board handle from the IRQHandle
	HalObject*	Hal = (HalObject*)ServiceContext;
	UInt32	InterruptControl;
    // Increase thread priority
    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);

    // endless loop: wait for interrupt event
    while (TRUE)
    {
		DPF (0,("halHardwareInterruptHandler:BLOCK\n" ));
        // Wait on interrupt to happen...
        WaitForSingleObject ( Hal->InterruptEvent , INFINITE);

		DPF (0,("halHardwareInterruptHandler:UNBLOCK\n" ));

		InterruptControl = *(Hal->MMIOAddrKernel + INT_CTL);

		if ((InterruptControl & 0xf0) == 0xf0)
		{
			// test mode
			DPF (0,("TriMedia TEST interrupt was generated!!\nWARNING: it will not be handled!!\n"));
			
			DPF (0,("INT_CTL=0x%x\n", *(PULONG)(Hal->MMIOAddrKernel + INT_CTL)));

			*(PULONG)(Hal->MMIOAddrKernel + INT_CTL) = 0;
      
			InterruptDone(SYSINTR_TRIMEDIA);
			break;

		}


		// here SelfInterrupt indicates PCI Interrupt A
		// INT#A = 0, INT#B = 1, INT#C = 2, INT#D = 3

		if ( ( InterruptControl &
			( (1 << Hal->SelfInterrupt)  | (0x10 << Hal->SelfInterrupt) ) ) !=
			( (1 << Hal->SelfInterrupt)  | (0x10 << Hal->SelfInterrupt) ) )
		{
			DPF (8,("TRIMEDIA INTERRUPT ABORTED!! \n"));
			InterruptDone(SYSINTR_TRIMEDIA);
			break;
		}


		DPF(0,("tmman:halHardwareInterruptHandler:ServiceContext[%x]\n",
			ServiceContext ));	
		halAcknowledgeInterrupt ( (UInt32)Hal ); 


		Hal->Handler(Hal->Context);

		InterruptDone(SYSINTR_TRIMEDIA);

    } // while (TRUE)

    return TRUE;
}


UInt32	halAccess32( 
	UInt32	HalHandle,
	UInt32 volatile Value )
{
	UInt32	SwappedValue,TempValue;
	TempValue = Value;

	/* we don't validate the object for efficiency reasons */
	if ( ((HalObject*)HalHandle)->Swapping )
	{
		((UInt8*)&SwappedValue)[3] = ((UInt8*)&TempValue)[0];
		((UInt8*)&SwappedValue)[2] = ((UInt8*)&TempValue)[1];
		((UInt8*)&SwappedValue)[1] = ((UInt8*)&TempValue)[2];
		((UInt8*)&SwappedValue)[0] = ((UInt8*)&TempValue)[3];
/*		DPF(0,("[%x->%x]",TempValue, SwappedValue )); */
		return ( SwappedValue );
	}
	else
	{
		return Value;
	}
	
}

UInt16	halAccess16 ( 
	UInt32	HalHandle,
	UInt16 volatile Value )
{
	/* we don't validate the object for efficiency reasons */
	UInt16	SwappedValue,TempValue;
	TempValue = Value;

	if ( ((HalObject*)HalHandle)->Swapping )
	{
		((UInt8*)&SwappedValue)[1] = ((UInt8*)&TempValue)[0];
		((UInt8*)&SwappedValue)[0] = ((UInt8*)&TempValue)[1];
		/* DPF(0,("[%x->%x]",TempValue, SwappedValue )); */
		return ( SwappedValue );
	}
	else
	{
		return Value;
	}
	return Value;
}

void	halCopyback( Pointer CacheBlock, UInt32 BlockCount  )
{
	/*	no implementation for this platform */
}

void	halAccessEnable ( 
	UInt32	HalHandle )
{
	/*	no implementation for this platform */
}

void	halAccessDisable ( 
	UInt32	HalHandle )
{
	/*	no implementation for this platform */
}

void	halDumpObject (
 	UInt32	HalHandle )
{
	HalObject*	Hal = (HalObject*)HalHandle;

    DPF(8,("\ntmman:halDumpObject\n"));
	
    DPF(8,("[SelfInterrupt:%x]\n", Hal->SelfInterrupt));
	DPF(8,("[PeerInterrupt:%x]\n", Hal->PeerInterrupt));
	DPF(8,("[Handler:%x]\n", Hal->Handler));
	DPF(8,("[Context:%x]\n", Hal->Context));
	DPF(8,("[BusNumber:%x]\n", Hal->BusNumber));
	DPF(8,("[SlotNumber|DeviceNumber:%x|FunctionNumber:%x]\n",
		Hal->SlotNumber.u.bits.DeviceNumber, Hal->SlotNumber.u.bits.FunctionNumber));

	DPF(8,("[MMIOAddrPhysical|HighPart:%x|LowPart:%x]\n", 
		Hal->MMIOAddrPhysical.u.HighPart, Hal->MMIOAddrPhysical.u.LowPart));
	DPF(8,("[MMIOLength:%x]\n", Hal->MMIOLength));
	DPF(8,("[MMIOAddrKernel:%x]\n", Hal->MMIOAddrKernel));


	DPF(8,("[SDRAMAddrPhysical|HighPart:%x|LowPart:%x]\n", 
		Hal->SDRAMAddrPhysical.u.HighPart, Hal->SDRAMAddrPhysical.u.LowPart));
	DPF(8,("[SDRAMLength:%x]\n", Hal->SDRAMLength));
	DPF(8,("[SDRAMAddrKernel:%x]\n", Hal->SDRAMAddrKernel));

	DPF(8,("[MappedInterruptVector:%x]\n", Hal->MappedInterruptVector));
    DPF(8,("[Irql:%x]\n", Hal->Irql));

	DPF(8,("[DeviceObject:%x]\n", Hal->DeviceObject));
	DPF(8,("[DriverObject:%x]\n", Hal->DriverObject));
	DPF(8,("[TMManDeviceObject:%x]\n", Hal->TMManDeviceObject));
	DPF(8,("\n"));

}    


BOOLEAN	halMapSDRAM ( UInt32 HalHandle )
{
	HalObject*	Hal = (HalObject*)HalHandle;

	if ( TMManGlobal->MapSDRAM )
	{
		return TRUE;
	}

	if ( Hal->SDRAMMapCount != 0 )
	{
		Hal->SDRAMMapCount++;
		return TRUE;
	}

    if ((Hal->SDRAMAddrKernel=(char*)VirtualAlloc(
		0,
		Hal->SDRAMLength,
		MEM_RESERVE,
		PAGE_NOACCESS))==NULL)
	{
		DPF(0,("tmman:halMapSDRAM:VirtualAlloc:SDRAM:Size[0x%x]:FAIL\n",
			Hal->SDRAMLength ));
		return  FALSE;
	}

	if(!VirtualCopy(
		(void *)Hal->SDRAMAddrKernel,
		(void *)(Hal->SDRAMAddrPhysical.LowPart>>8),
		Hal->SDRAMLength,
		PAGE_READWRITE|PAGE_PHYSICAL|PAGE_NOCACHE))
	{

		DPF(0,("tmman:halMapSDRAM:VirtualCopy:SDRAM:AddrKernel[0x%x]:Size[0x%x]:FAIL\n",
			Hal->SDRAMAddrKernel, Hal->SDRAMLength ));
	    VirtualFree(Hal->SDRAMAddrKernel,0,MEM_RELEASE);
		return  FALSE;
	}

	Hal->SDRAMMapCount++;

	return TRUE;
}

BOOLEAN	halUnmapSDRAM ( UInt32 HalHandle )
{
	HalObject*	Hal = (HalObject*)HalHandle;

	if ( TMManGlobal->MapSDRAM )
	{
		return TRUE;
	}

	//unmatched Unmapping
	if ( Hal->SDRAMMapCount == 0 )
	{
		return FALSE;
	}

	if ( Hal->SDRAMMapCount > 1 )
	{
		Hal->SDRAMMapCount--;
		return TRUE;
	}

    VirtualFree(Hal->SDRAMAddrKernel,0,MEM_RELEASE);
	Hal->SDRAMMapCount = 0;

 	return TRUE;
}

///////////////////////////////////////////////////////////////////////////
/////				These Headers should be moved to platform.h 
///////////////////////////////////////////////////////////////////////////
/* Helper functions */


TMStatus	halSwapEndianess ( 
	UInt32	HalHandle,
	Bool	SwapEnable )
{
	HalObject*	Hal = (HalObject*)HalHandle;
	Hal->Swapping = SwapEnable;
	DPF(8,("tmman:halSwapEndianess:Swapping[%x]\n", SwapEnable )); 

	return statusSuccess;
}

TMStatus	halGetEndianess ( 
	UInt32	HalHandle,
	Bool*	SwapEnablePtr )
{
	HalObject*	Hal = (HalObject*)HalHandle;
	*SwapEnablePtr = Hal->Swapping;

	return statusSuccess;
}


UInt32	halTranslateTargetPhysicalAddress ( 
	UInt32 HalHandle, 
	UInt32 PhysicalAddress )
{
	HalObject*	Hal = (HalObject*)HalHandle;

	return ( PhysicalAddress);
}

⌨️ 快捷键说明

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