Example #1
0
extern BOOL HcdPdd_Deinit(DWORD hDeviceContext)
{
	SOhcdPdd * pPddObject = (SOhcdPdd *)hDeviceContext;

	USBH_MSG((_T("[USBH] HcdPdd_Deinit()\n\r")));

	if(pPddObject->lpvOhcdMddObject)
	{
		HcdMdd_DestroyHcdObject(pPddObject->lpvOhcdMddObject);
	}

	if(pPddObject->lpvMemoryObject)
	{
		HcdMdd_DestroyMemoryObject(pPddObject->lpvMemoryObject);
	}

	if(pPddObject->pvVirtualAddress)
	{
		HalFreeCommonBuffer(&pPddObject->AdapterObject, pPddObject->dwPhysicalMemSize, pPddObject->LogicalAddress, pPddObject->pvVirtualAddress, FALSE);
	}

	if (pPddObject->IsrHandle)
	{
		FreeIntChainHandler(pPddObject->IsrHandle);
		pPddObject->IsrHandle = NULL;
	}

	if (pPddObject->hParentBusHandle)
	{
		CloseBusAccessHandle(pPddObject->hParentBusHandle);
	}

	free(pPddObject);

	if (g_pSysConReg)
	{
		//-----------------------
		// Deitialize Clock
		// HCLK, SCLK gate Mask
		//-----------------------
		g_pSysConReg->HCLK_GATE &= ~(0x1<<29);		// HCLK_UHOST Mask (EVT1)
		g_pSysConReg->SCLK_GATE &= ~(0x1<<30);		// SCLK_UHOST Mask

		DrvLib_UnmapIoSpace((PVOID)g_pSysConReg);
		g_pSysConReg = NULL;
	}

	return TRUE;
}
Example #2
0
BOOL 
CSDHCBase::DeinitializeHardware(
                                )
{
    DEBUGCHK(m_hBusAccess);
    PREFAST_DEBUGCHK(m_pSlotInfos);
    ValidateSlotCount();

    for (DWORD dwSlot = 0; dwSlot < m_cSlots; ++dwSlot) {
        PVOID pvRegisters = (PVOID) m_pSlotInfos[dwSlot].pucRegisters;
        DWORD dwLen = m_pSlotInfos[dwSlot].dwExtraInfo;
        if (pvRegisters) MmUnmapIoSpace(pvRegisters, dwLen);
    }

    if (m_hISRHandler) FreeIntChainHandler(m_hISRHandler);

    return TRUE;
}
Example #3
0
A_STATUS
CF_MaskInterrupt(CF_DEVICE_HANDLE cfHandle) {
    CF_DEVICE    *cfDevice;

    HIF_DEBUG_PRINTF(ATH_LOG_TRC,
                        "CF_MaskInterrupt \n");

    cfDevice = (CF_DEVICE *)cfHandle;
#ifdef POLL
    stopPollThread(cfDevice);
#else
    NdisMDeregisterInterrupt(&cfDevice->interruptObject);

#ifdef SHARED_INTERRUPTS
    if (isrHandler) {
        FreeIntChainHandler(isrHandler);
    }
#endif // SHARED_INTERRUPTS
#endif
    
    return A_OK;
}
Example #4
0
BOOL LED_Deinit(DWORD dwContext)
{
	PDRVCONTEXT pDrv = (PDRVCONTEXT)dwContext;
	
	RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Deinit++ dwContext: %x\r\n"), dwContext));

	// Verify that the context handle is valid
	if(pDrv && (pDrv->dwSize != sizeof(DRVCONTEXT))){
		return 0;
	}

	// terminate thread
	KillFlag = true;
	SetEvent(pDrv->hEvent);

	FreeIntChainHandler(pDrv->hIsrHandle);
	InterruptDisable(pDrv->dwSysIntr);
	KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &pDrv->dwSysIntr, sizeof(DWORD), NULL, 0, NULL);
	CloseHandle(pDrv->hEvent);
	DeleteStaticMapping((LPVOID)isr_info.pGPIORegs, sizeof(GPIOREG));

	return true;
}
Example #5
0
//=======================================================================
// LED_Init - Driver initialization function
//
DWORD LED_Init(LPCSTR pContext, DWORD dwBusContext){
	PDRVCONTEXT pDrv;
	RETAILMSG(RETAIL_ON, (TEXT("Test debug output without context \r\n")));
	RETAILMSG(RETAIL_ON, (TEXT("LED_Init++ dwContext: %x\r\n"), pContext));

	// Allocate a driver instance structure - required if we want to manage
	// more instances
	pDrv = (PDRVCONTEXT)LocalAlloc(LPTR, sizeof(DRVCONTEXT));

	if(pDrv){
		// initialize structure
		memset((PBYTE) pDrv, 0, sizeof(DRVCONTEXT));
		pDrv->dwSize = sizeof(DRVCONTEXT);

		// read registry to determine the size of the disk
		// GetConfigData((DWORD)pContext);
	}else{
		RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. Out of memory\r\n"), pContext));
	}

	DWORD dwGpio = 15;
	DWORD dwIrq = 0;	
	DWORD dwEdge = GPIO_EDGE_RISING;

	if (!KernelIoControl(IOCTL_HAL_GPIO2IRQ, &dwGpio, sizeof(DWORD), &dwIrq, sizeof(DWORD), NULL))
	{
		RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. IOCTL_HAL_GPIO2IRQ\r\n"), pContext));
		return 0;
	}

	if (!KernelIoControl(IOCTL_HAL_IRQEDGE, &dwIrq, sizeof(BYTE), &dwEdge, sizeof(BYTE), NULL))
	{
		RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. IOCTL_HAL_IRQEDGE\r\n"), pContext));
		return 0;
	}

	if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwIrq, sizeof(DWORD), &(pDrv->dwSysIntr), sizeof(DWORD), NULL))
	{
		RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. IOCTL_HAL_REQUEST_SYSINTR\r\n"), pContext));
		return 0;
	}

	pDrv->hEvent = CreateEvent(NULL, false, false, TEXT("ISTEvent"));
	if (!(pDrv->hEvent))
	{
		RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. Create Event failed.\r\n"), pContext));
		return 0;
	}

	if (!InterruptInitialize(pDrv->dwSysIntr, pDrv->hEvent, NULL, 0))
	{
		RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. InterruptInitialize failed.\r\n"), pContext));
		return 0;
	}

	pDrv->hIsrHandle = LoadIntChainHandler(TEXT("\\Program Files\\Drivers\\ISRDll.dll"), TEXT("ISRHandler"), dwIrq);
	if (!pDrv->hIsrHandle)
	{
		RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. LoadIntChainHandler failed.\r\n"), pContext));
		return 0;
	}

	isr_info.SysIntr = pDrv->dwSysIntr;

	isr_info.pGPIORegs = (GPIOREG*)CreateStaticMapping(GPIO_BASE >> 8, sizeof(GPIOREG));
	if (!isr_info.pGPIORegs)
	{
		RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. CreateStaticMapping failed.\r\n"), pContext));
		return 0;
	}

	if (!KernelLibIoControl(pDrv->hIsrHandle, IOCTL_ISR_INFO, &isr_info, sizeof(isr_info), NULL, 0, NULL))
	{
		RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. IOCTL_HAL_RELEASE_SYSINTR failed.\r\n"), pContext));
		return 0;
	}

	pDrv->hIntThread = CreateThread(NULL, 0, ISTFunction, pDrv->hEvent, 0, NULL);
	if (!pDrv->hIntThread)
	{
		RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. CreateThread failed.\r\n"), pContext));
		return 0;
	}


	RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init-- pDrv: %x\r\n"), pDrv));

	return (DWORD)pDrv;

FREECHAINHANDLER:
	FreeIntChainHandler(pDrv->hIsrHandle);
INTERRUPTDISABLE:
	InterruptDisable(pDrv->dwSysIntr);
KERNELIOCONTROL:
	KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &pDrv->dwSysIntr, sizeof(DWORD), NULL, 0, NULL);
CLOSEHANDLE:
	CloseHandle(pDrv->hEvent);
DELETESTATICMAPPING:
	DeleteStaticMapping((LPVOID)isr_info.pGPIORegs, sizeof(GPIOREG));
}
Example #6
0
/* InitializeOHCI
 *
 *  Configure and initialize OHCI card
 *
 * Return Value:
 *  Return TRUE if card could be located and configured, otherwise FALSE
 */
static BOOL
InitializeOHCI(
		SOhcdPdd * pPddObject,		// IN - Pointer to PDD structure
		LPCWSTR szDriverRegKey)	// IN - Pointer to active registry key string
{
	PUCHAR ioPortBase = NULL;
	DWORD dwAddrLen;
	DWORD dwIOSpace;
	BOOL InstallIsr = FALSE;
	BOOL fResult = FALSE;
	LPVOID pobMem = NULL;
	LPVOID pobOhcd = NULL;
	DWORD PhysAddr;
	DWORD dwHPPhysicalMemSize;
	HKEY hKey=NULL;

	DDKWINDOWINFO dwi;
	DDKISRINFO dii;

	USBH_MSG((_T("[USBH] ++InitializeOHCI()\n\r")));

	g_pSysConReg = (S3C6410_SYSCON_REG *)DrvLib_MapIoSpace(S3C6410_BASE_REG_PA_SYSCON, sizeof(S3C6410_SYSCON_REG), FALSE);
	if (g_pSysConReg == NULL)
	{
		USBH_ERR((_T("[USBH:ERR] InitializeOHCI() : DrvLib_MapIoSpace() Failed\n")));
		return FALSE;
	}

#ifdef	USE_SRCCLK_EPLL
	//-----------------------
	// Initialize Clock
	// ClkSrc = MOUT_EPLL (96MHz)
	// Divide by 2 (96/2=48MHz)
	// HCLK, SCLK gate pass
	//-----------------------
	g_pSysConReg->CLK_SRC = (g_pSysConReg->CLK_SRC & ~(0x3<<5)) | (0x1<<5);		// UHOST_SEL : MoutEPLL
	g_pSysConReg->CLK_DIV1 = (g_pSysConReg->CLK_DIV1 & ~(0xf<<20)) | (0x1<<20);	// UHOST_RATIO : 96 MHz / (1+1) = 48 MHz
#else
	//-----------------------
	// Initialize Clock
	// ClkSrc = USB_PHY(48MHz)
	// Divide by 1 (48/1=48MHz)
	// HCLK, SCLK gate pass
	//-----------------------
	g_pSysConReg->OTHERS |= (1<<16);	// Set SUB Signal Mask
	g_pSysConReg->CLK_SRC &= ~(0x3<<5);	// UHOST_SEL : 48MHz
	g_pSysConReg->CLK_DIV1 &= ~(0xf<<20);	// UHOST_RATIO : 48 MHz / (0+1) = 48 MHz
#endif

	g_pSysConReg->HCLK_GATE |= (0x1<<29);		// HCLK_UHOST Pass (EVT1)
	g_pSysConReg->SCLK_GATE |= (0x1<<30);		// SCLK_UHOST Pass

	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,szDriverRegKey,0,0,&hKey)!= ERROR_SUCCESS)
	{
		DEBUGMSG(ZONE_ERROR,(TEXT("InitializeOHCI:GetRegistryConfig RegOpenKeyEx(%s) failed\r\n"), szDriverRegKey));
		return FALSE;
	}

	dwi.cbSize=sizeof(dwi);
	dii.cbSize=sizeof(dii);
	if ( (DDKReg_GetWindowInfo(hKey, &dwi ) != ERROR_SUCCESS)
		|| (DDKReg_GetIsrInfo (hKey, &dii ) != ERROR_SUCCESS))
	{
		DEBUGMSG(ZONE_ERROR,(TEXT("InitializeOHCI:DDKReg_GetWindowInfo or  DDKReg_GetWindowInfo failed\r\n")));
		goto InitializeOHCI_Error;
	}

	if (dwi.dwNumMemWindows!=0)
	{
		PhysAddr = dwi.memWindows[0].dwBase;
		dwAddrLen= dwi.memWindows[0].dwLen;
		dwIOSpace = 0;
	}
	else if (dwi.dwNumIoWindows!=0)
	{
		PhysAddr= dwi.ioWindows[0].dwBase;
		dwAddrLen = dwi.ioWindows[0].dwLen;
		dwIOSpace = 1;
	}
	else
	{
		goto InitializeOHCI_Error;
	}

	DEBUGMSG(ZONE_INIT,(TEXT("OHCD: Read config from registry: Base Address: 0x%X, Length: 0x%X, I/O Port: %s, SysIntr: 0x%X, Interface Type: %u, Bus Number: %u\r\n"),
					PhysAddr, dwAddrLen, dwIOSpace ? L"YES" : L"NO", dii.dwSysintr, dwi.dwInterfaceType, dwi.dwBusNumber));

	ioPortBase = (PBYTE) PhysAddr;

	if (!(fResult = ConfigureOHCICard(pPddObject, &ioPortBase, dwAddrLen, dwIOSpace,(INTERFACE_TYPE)dwi.dwInterfaceType, dwi.dwBusNumber)))
	{
		goto InitializeOHCI_Error;
	}

	if (dii.szIsrDll[0] != 0 && dii.szIsrHandler[0]!=0 && dii.dwIrq<0xff && dii.dwIrq>0 )
	{
		// Install ISR handler
		pPddObject->IsrHandle = LoadIntChainHandler(dii.szIsrDll, dii.szIsrHandler, (BYTE)dii.dwIrq);

		if (!pPddObject->IsrHandle)
		{
			DEBUGMSG(ZONE_ERROR, (L"OHCD: Couldn't install ISR handler\r\n"));
		}
		else
		{
			GIISR_INFO Info;
			PHYSICAL_ADDRESS PortAddress = {PhysAddr, 0};

			DEBUGMSG(ZONE_INIT, (L"OHCD: Installed ISR handler, Dll = '%s', Handler = '%s', Irq = %d\r\n",
			dii.szIsrDll, dii.szIsrHandler, dii.dwIrq));

			if (!BusTransBusAddrToStatic(pPddObject->hParentBusHandle,(INTERFACE_TYPE)dwi.dwInterfaceType, dwi.dwBusNumber, PortAddress, dwAddrLen, &dwIOSpace, (PPVOID)&PhysAddr))
			{
				DEBUGMSG(ZONE_ERROR, (L"OHCD: Failed TransBusAddrToStatic\r\n"));
				goto InitializeOHCI_Error;
			}

			// Set up ISR handler
			Info.SysIntr = dii.dwSysintr;
			Info.CheckPort = TRUE;
			Info.PortIsIO = (dwIOSpace) ? TRUE : FALSE;
			Info.UseMaskReg = TRUE;
			Info.PortAddr = PhysAddr + 0x0C;
			Info.PortSize = sizeof(DWORD);
			Info.MaskAddr = PhysAddr + 0x10;

			if (!KernelLibIoControl(pPddObject->IsrHandle, IOCTL_GIISR_INFO, &Info, sizeof(Info), NULL, 0, NULL))
			{
				DEBUGMSG(ZONE_ERROR, (L"OHCD: KernelLibIoControl call failed.\r\n"));
			}
		}
	}

	// The PDD can supply a buffer of contiguous physical memory here, or can let the
	// MDD try to allocate the memory from system RAM.  We will use the HalAllocateCommonBuffer()
	// API to allocate the memory and bus controller physical addresses and pass this information
	// into the MDD.
	if (GetRegistryPhysicalMemSize(szDriverRegKey,&pPddObject->dwPhysicalMemSize))
	{
		// A quarter for High priority Memory.
		dwHPPhysicalMemSize = pPddObject->dwPhysicalMemSize/4;
		// Align with page size.
		pPddObject->dwPhysicalMemSize = (pPddObject->dwPhysicalMemSize + PAGE_SIZE -1) & ~(PAGE_SIZE -1);
		dwHPPhysicalMemSize = ((dwHPPhysicalMemSize +  PAGE_SIZE -1) & ~(PAGE_SIZE -1));
	}
	else
	{
		pPddObject->dwPhysicalMemSize=0;
		dwHPPhysicalMemSize = 0 ;
	}

	if (pPddObject->dwPhysicalMemSize<gcTotalAvailablePhysicalMemory)
	{
		// Setup Minimun requirement.
		pPddObject->dwPhysicalMemSize = gcTotalAvailablePhysicalMemory;
		dwHPPhysicalMemSize = gcHighPriorityPhysicalMemory;
	}

	pPddObject->AdapterObject.ObjectSize = sizeof(DMA_ADAPTER_OBJECT);
	pPddObject->AdapterObject.InterfaceType = dwi.dwInterfaceType;
	pPddObject->AdapterObject.BusNumber = dwi.dwBusNumber;
	if ((pPddObject->pvVirtualAddress = HalAllocateCommonBuffer(&pPddObject->AdapterObject, pPddObject->dwPhysicalMemSize, &pPddObject->LogicalAddress, FALSE)) == NULL)
	{
		goto InitializeOHCI_Error;
	}

	if (!(pobMem = HcdMdd_CreateMemoryObject(pPddObject->dwPhysicalMemSize, dwHPPhysicalMemSize, (PUCHAR) pPddObject->pvVirtualAddress, (PUCHAR) pPddObject->LogicalAddress.LowPart)))
	{
		goto InitializeOHCI_Error;
	}

	if (!(pobOhcd = HcdMdd_CreateHcdObject(pPddObject, pobMem, szDriverRegKey, ioPortBase, dii.dwSysintr)))
	{
		goto InitializeOHCI_Error;
	}

	pPddObject->lpvMemoryObject = pobMem;
	pPddObject->lpvOhcdMddObject = pobOhcd;
	_tcsncpy(pPddObject->szDriverRegKey, szDriverRegKey, MAX_PATH);
	pPddObject->ioPortBase = ioPortBase;
	pPddObject->dwSysIntr = dii.dwSysintr;

	// PCI OHCI support suspend and resume
	if ( hKey!=NULL)
	{
		DWORD dwCapability;
		DWORD dwType;
		DWORD dwLength = sizeof(DWORD);
		if (RegQueryValueEx(hKey, HCD_CAPABILITY_VALNAME, 0, &dwType, (PUCHAR)&dwCapability, &dwLength) == ERROR_SUCCESS)
		{
			HcdMdd_SetCapability(pobOhcd, dwCapability);
			USBH_INF((_T("[USBH:INF] InitializeOHCI() : USB Host Cap : 0x%08x\n"), dwCapability));
		}

		RegCloseKey(hKey);
	}

	USBH_MSG((_T("[USBH] --InitializeOHCI() : Success\n\r")));

	return TRUE;

InitializeOHCI_Error:

	if (g_pSysConReg != NULL)
	{
		DrvLib_UnmapIoSpace((PVOID)g_pSysConReg);
		g_pSysConReg = NULL;
	}

	if (pPddObject->IsrHandle)
	{
		FreeIntChainHandler(pPddObject->IsrHandle);
		pPddObject->IsrHandle = NULL;
	}

	if (pobOhcd)
	{
		HcdMdd_DestroyHcdObject(pobOhcd);
	}

	if (pobMem)
	{
		HcdMdd_DestroyMemoryObject(pobMem);
	}

	if(pPddObject->pvVirtualAddress)
	{
		HalFreeCommonBuffer(&pPddObject->AdapterObject, pPddObject->dwPhysicalMemSize, pPddObject->LogicalAddress, pPddObject->pvVirtualAddress, FALSE);
	}

	pPddObject->lpvMemoryObject = NULL;
	pPddObject->lpvOhcdMddObject = NULL;
	pPddObject->pvVirtualAddress = NULL;

	if ( hKey!=NULL)
	{
		RegCloseKey(hKey);
	}

	USBH_ERR((_T("[USBH:ERR] --InitializeOHCI() : Error\n\r")));

	return FALSE;
}