📄 usbohciroothubemulation.c
字号:
/* usbOhciRootHubEmulation.c - USB OHCI Root hub Emulation *//* Copyright 2004 - 2005 Wind River Systems, Inc. This software includes software licensed to Wind River Systems, Inc. by Wipro, Ltd. Wind River licensees may use this software according to the terms of their Wind River license agreement(s) applicable to this software.*//*modification history--------------------01e,28mar05,pdg non-PCI changes01d,02mar05,ami SPR #106373 (OHCI Max Controllers Issue)01c,22Jul03,gpd implemented the MIPS changes01b,27jun03,nld Changing the code to WRS standards01a,04may02,ssh Initial Version*//*DESCRIPTIONThis file defines the functions for implementing root hub emulationINCLUDE FILES: usbOhci.h, usbOhciRegisterInfo.h, usbOhciTransferManagement.h*//*INTERNAL ******************************************************************************* * Filename : OHCI_RootHubEmulation.c * * Copyright : * * THE COPYRIGHT IN THE CONTENTS OF THIS SOFTWARE VEST WITH WIPRO * LIMITED A COMPANY INCORPORATED UNDER THE LAWS OF INDIA AND HAVING * ITS REGISTERED OFFICE AT DODDAKANNELLI SARJAPUR ROAD BANGALORE * 560 035. DISTRIBUTION OR COPYING OF THIS SOFTWARE BY * ANY INDIVIDUAL OR ENTITY OTHER THAN THE ADDRESSEE IS STRICTLY * PROHIBITED AND MAY INCUR LEGAL LIABILITY. IF YOU ARE NOT THE * ADDRESSEE PLEASE NOTIFY US IMMEDIATELY BY PHONE OR BY RETURN EMAIL. * THE ADDRESSEE IS ADVISED TO MAINTAIN THE PROPRIETARY INTERESTS OF * THIS COPYRIGHT AS PER APPLICABLE LAWS. * * Description : This file defines the functions for implementing root * hub emulation. * * ******************************************************************************//* includes */#include "usb2/usbOsal.h"#include "usb2/usbOhci.h"#include "usb2/usbOhciRegisterInfo.h"#include "usb2/usbOhciTransferManagement.h"#include "usb2/usbHst.h"/* defines *//********************** MODULE SPECIFIC MACRO DEFINITION **********************//* * To hold the mask value within the SETUP::bmRequestType field to indicate * the recipient of the request. */#define USB_OHCI_CONTROL_TRANSFER_REQUEST_RECIPIENT_MASK 0x1F/* * To hold the mask value withing the SETUP::bmRequestType field to indicate * the type of request (standard, class specific, etc) */#define USB_OHCI_CONTROL_TRANSFER_REQUEST_TYPE_MASK 0x60/* To hold the mask value to indicate a class specific request */#define USB_OHCI_CLASS_SPECIFIC_REQUEST 0x20/* * To hold the offset of the descriptor type information in the * SETUP::wValue field of the GET_DESCRIPTOR request. */#define USB_OHCI_GET_DESCRIPTOR_TYPE_OFFSET 0x08/* To hold the length of the root hub device descriptor length */#define USB_OHCI_ROOT_HUB_DEVICE_DESCRIPTOR_LENGTH 0x12/* To hold the length of the root hub configuration descriptor length */#define USB_OHCI_ROOT_HUB_CONFIGURATION_DESCRIPTOR_LENGTH 0x19/* To hold the size of the response to the GET_STATUS request */#define USB_OHCI_GET_STATUS_REQUEST_RESPONSE_SIZE 0x02/* Features selectors for the GET_STATUS standard request (BEGIN) *//* To hold the value indicating the device is self powered */#define USB_OHCI_DEVICE_SELF_POWERED 0x0001/* To hold the value indicating the device is remoted wakeup enabled */#define USB_OHCI_DEVICE_REMOTE_WAKEUP_ENABLED 0x0002/* Features selectors for the GET_STATUS standard request (END) *//* To hold the size of the response to the GET_CONFIGURATION request */#define USB_OHCI_GET_CONFIGURATION_REQUEST_RESPONSE_SIZE 0x01/* To hold the size of the response to the GET_INTERFACE request */#define USB_OHCI_GET_INTERFACE_REQUEST_RESPONSE_SIZE 0x01/* To hold the device states for the root hub (BEGIN) *//* Root hub is in default state */#define USB_OHCI_DEVICE_DEFAULT_STATE 0x00/* Root hub is in addressed state */#define USB_OHCI_DEVICE_ADDRESS_STATE 0x01/* Root hub is in configured state */#define USB_OHCI_DEVICE_CONFIGURED_STATE 0x02/* To hold the device states for the root hub (END) *//* To hold the size of the response to the GET_HUB_STATUS request */#define USB_OHCI_GET_HUB_STATUS_REQUEST_RESPONSE_SIZE 0x04/* To hold the size of the response to the GET_PORT_STATUS request */#define USB_OHCI_GET_PORT_STATUS_REQUEST_RESPONSE_SIZE 0x04/* To hold the value of hub class descriptor type */#define USB_OHCI_HUB_CLASS_DESCRIPTOR_TYPE 0x29/* To hold the feature selectors for the hub class requests (BEGIN) *//* To hold the value of the hub local power change feature */#define USB_OHCI_C_HUB_LOCAL_POWER 0x00/* To hold the value of the hub over current change feature */#define USB_OHCI_C_HUB_OVER_CURRENT 0x01/* To hold the value of the port enable feature */#define USB_OHCI_PORT_ENABLE 0x01/* To hold the value of the port suspend feature */#define USB_OHCI_PORT_SUSPEND 0x02/* To hold the value of the port reset feature */#define USB_OHCI_PORT_RESET 0x04/* To hold the value of the port power feature */#define USB_OHCI_PORT_POWER 0x08/* To hold the value of the port connection change feature */#define USB_OHCI_C_PORT_CONNECTION 0x10/* To hold the value of the port enable change feature */#define USB_OHCI_C_PORT_ENABLE 0x11/* To hold the value of the port suspend change feature */#define USB_OHCI_C_PORT_SUSPEND 0x12/* To hold the value of the port over current change feature */#define USB_OHCI_C_PORT_OVER_CURRENT 0x13/* To hold the value of the port reset change feature */#define USB_OHCI_C_PORT_RESET 0x14/* To hold the feature selectors for the hub class requests (END) *//* typedefs *//****************** MODULE SPECIFIC DATA STRUCTURE DECLARATION ****************//* Structure to hold the configuration descriptor for the root hub */typedef struct usbOhciRootHubConfigurationDescriptor { USBHST_CONFIG_DESCRIPTOR configurationDescriptor; /* To hold the configuration descriptor information */ USBHST_INTERFACE_DESCRIPTOR interfaceDescriptor; /* To hold the interface descriptor information */ USBHST_ENDPOINT_DESCRIPTOR endpointDescriptor; /* To hold the endpoint descriptor information */ } __attribute__((__packed__)) USB_OHCI_ROOT_HUB_CONFIGURATION_DESCRIPTOR;typedef struct usbOhciRootHubConfigurationDescriptor * PUSB_OHCI_ROOT_HUB_CONFIGURATION_DESCRIPTOR;/* Structure to store the hub class descriptor for the device */typedef struct usbOhciHubClassDescriptor { UINT8 bDescLength; /* To hold the length of the descriptor */ UINT8 bDescriptorType; /* To hold the descriptor type */ UINT8 bNbrPorts; /* To hold the number of downstream ports */ UINT16 wHubCharacteristics;/* To hold the hub characteristics */ UINT8 bPwrOn2PwrGood; /* To hold the power on to power good time */ UINT8 bHubContrCurrent; /* To hold the maximum current required by */ /* the hub controller */ UINT8 deviceRemovable[1]; /* To hold the device removal information */ UINT8 portPwrCtrlMask[1]; /* To hold the port power control mask */ } __attribute__((__packed__)) USB_OHCI_HUB_CLASS_DESCRIPTOR; typedef struct usbOhciHubClassDescriptor * PUSB_OHCI_HUB_CLASS_DESCRIPTOR;/* locals *//******************* MODULE SPECIFIC VARIABLES DEFINITION *********************//* To hold the device descriptor for the root hub */LOCAL USBHST_DEVICE_DESCRIPTOR usbOhciRootHubDeviceDescriptor = { 0x12, /* Size of this descriptor */ 0x01, /* Descriptor type */ OS_UINT16_CPU_TO_LE(0x0110), /* BCD USB Specification Release Number */ 0x09, /* Device class code */ 0x00, /* Device sub class code */ 0x00, /* Device protocol code */ 0x40, /* Maximum packet size for endpoint zero */ 0x0000, /* Vendor ID of this interface */ 0x0000, /* Product ID of this interface */ 0x0000, /* BCD Device release number */ 0x00, /* Index of string descriptor describing manufacturer */ 0x00, /* Index of string descriptor describing product */ 0x00, /* Index of string descriptor describing the device's */ /* serial number */ 0x01 /* Number of possible configurations */ };/* To hold the configuration descriptor for the root hub */LOCAL USB_OHCI_ROOT_HUB_CONFIGURATION_DESCRIPTOR usbOhciRootHubConfigurationDescriptor = { /* Initialize the configuration descriptor */ { 0x09, /* Size of this descriptor */ 0x02, /* Descriptor type */ OS_UINT16_CPU_TO_LE(0x0019), /* Total length of the configuration descriptor */ 0x01, /* Number of interfaces in this configuration */ 0x01, /* Value to set this configuration */ 0x00, /* Index of the string describing this configuration */ 0xE0, /* Self powered, remote wakeup enabled */ 0x00 /* Maximum power consumption from the USB bus */ }, /* Initialize the interface descriptor */ { 0x09, /* Size of this descriptor */ 0x04, /* Descriptor type */ 0x00, /* Interface number */ 0x00, /* Alternate setting number */ 0x01, /* Number of endpoints in this interface */ 0x09, /* Interface class code */ 0x00, /* Interface sub class code */ 0x00, /* Interface protocol code */ 0x00 /* Index of the string descriptor describing this interface */ }, /* Initialize the endpoint descriptor */ { 0x07, /* Size of this descriptor */ 0x05, /* Descriptor type */ 0x81, /* Endpoint address */ 0x03, /* Interrupt endpoint */ OS_UINT16_CPU_TO_LE(0x0008), /* Maximum packet size for the endpoint */ 0xFF /* Polling interval for the endpoint */ } };/* forward declarations *//****************** MODULE SPECIFIC FUNCTIONS DECLARATION *********************//* Function to initialize the root hub emulation module */LOCAL USBHST_STATUS usbOhciRootHubEmulationInit (UINT8 uHostControllerIndex);/* Function to handle the request addressed to the root hub */LOCAL USBHST_STATUS usbOhciProcessRootHubRequest (UINT8 uHostControllerIndex, pUSBHST_URB pUrb);/* Function to process the control transfers addressed to the root hub */LOCAL USBHST_STATUS usbOhciProcessRootHubControlTransfer (UINT8 uHostControllerIndex, pUSBHST_URB pUrb);/* Function to process the interrpt transfers addressed to the root hub */LOCAL USBHST_STATUS usbOhciProcessRootHubInterruptTransfer (UINT8 uHostControllerIndex, pUSBHST_URB pUrb);/* Function to process the USB standard requests addressed to the root hub */LOCAL USBHST_STATUS usbOhciProcessRootHubStandardRequest (UINT8 uHostControllerIndex, pUSBHST_URB pUrb);/* Function to process hub class specific requests addressed to the root hub */LOCAL USBHST_STATUS usbOhciProcessRootHubClassSpecificRequest (UINT8 uHostControllerIndex, pUSBHST_URB pUrb);/* Function to process the status change on the root hub */LOCAL VOID usbOhciProcessRootHubStatusChange (UINT8 uHostControllerIndex);/* functions *//************************ GLOBAL FUNCTIONS DEFINITION *************************//******************* MODULE SPECIFIC FUNCTIONS DEFINITION *********************//***************************************************************************** usbOhciRootHubEmulationInit - Root Hub Emulation Initialisation** This function initializes the root hub emulation module ** PARAMETERS: <nHostControllerIndex (IN)> - Host controller index corresponding * to the host controller for which an interrupt has occurred.** RETURNS: USBHST_SUCCESS on success,* USBHST_INVALID_PARAMETER if the parameters are invalid** ERRNO:* None.** \NOMANUAL*/LOCAL USBHST_STATUS usbOhciRootHubEmulationInit ( UINT8 uHostControllerIndex ) { /* To hold the pointer to the host controller information */ PUSB_OHCI_INFORMATION pOhciControllerInfo = NULL; /* To hold the base address of the OHCI Controller */ UINT32 uBaseAddress = 0; /* To hold the value read from the registers */ UINT32 uRegisterValue = 0; /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Entering the function: usbOhciRootHubEmulationInit().\n", 0, 0, 0, 0); /* Check whether the host controller index is valid */ if (uHostControllerIndex >= maxOhciCount) { /* Invalid host controller index */ /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Exiting the function: usbOhciRootHubEmulationInit().\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* Obtain the pointer to the host controller information */ pOhciControllerInfo = &usbOhciControllerInfo[uHostControllerIndex]; /* Obtain the base address for the OHCI Controller */ uBaseAddress = usbOhciControllerInfo[uHostControllerIndex].uBaseAddress; /* Read the contents of the HcRhDescriptorA register */ uRegisterValue = USB_OHCI_REG_READ(uHostControllerIndex, uBaseAddress + USB_OHCI_RH_DESCRIPTOR_A_REGISTER_OFFSET); /* Update the number of downstream port supported by the root hub */ pOhciControllerInfo->uNumberOfDownStreamPorts = (uRegisterValue & USB_OHCI_RH_DESCRIPTOR_A_REGISTER_NDP_MASK); /* NOTE: Update the hub descriptors for endianess issues */ /* Debug print */ OS_LOG_MESSAGE_LOW( OHCD, "Exiting the function: usbOhciRootHubEmulationInit().\n", 0, 0, 0, 0); return USBHST_SUCCESS;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -