NULL\r
};\r
\r
-DEBUGPORT_DEVICE *gDebugPortDevice;\r
+DEBUGPORT_DEVICE mDebugPortDevice = {\r
+ DEBUGPORT_DEVICE_SIGNATURE,\r
+ (EFI_HANDLE) 0,\r
+ (EFI_HANDLE) 0,\r
+ (VOID *) NULL,\r
+ (EFI_DEVICE_PATH_PROTOCOL *) NULL,\r
+ {\r
+ DebugPortReset,\r
+ DebugPortRead, \r
+ DebugPortWrite, \r
+ DebugPortPoll \r
+ },\r
+ (EFI_HANDLE) 0,\r
+ (EFI_SERIAL_IO_PROTOCOL *) NULL,\r
+ DEBUGPORT_UART_DEFAULT_BAUDRATE,\r
+ DEBUGPORT_UART_DEFAULT_FIFO_DEPTH,\r
+ DEBUGPORT_UART_DEFAULT_TIMEOUT,\r
+ (EFI_PARITY_TYPE) DEBUGPORT_UART_DEFAULT_PARITY,\r
+ DEBUGPORT_UART_DEFAULT_DATA_BITS,\r
+ (EFI_STOP_BITS_TYPE) DEBUGPORT_UART_DEFAULT_STOP_BITS\r
+};\r
\r
/**\r
Local worker function to obtain device path information from DebugPort variable.\r
\r
Records requested settings in DebugPort device structure.\r
- \r
- @param DebugPortDevice Pointer to instance of dubug port device.\r
\r
**/\r
VOID\r
GetDebugPortVariable (\r
- DEBUGPORT_DEVICE *DebugPortDevice\r
+ VOID\r
)\r
{\r
UINTN DataSize;\r
&gEfiDebugPortVariableGuid,\r
NULL,\r
&DataSize,\r
- DebugPortDevice->DebugPortVariable\r
+ mDebugPortDevice.DebugPortVariable\r
);\r
\r
if (Status == EFI_BUFFER_TOO_SMALL) {\r
- if (gDebugPortDevice->DebugPortVariable != NULL) {\r
- FreePool (gDebugPortDevice->DebugPortVariable);\r
+ if (mDebugPortDevice.DebugPortVariable != NULL) {\r
+ FreePool (mDebugPortDevice.DebugPortVariable);\r
}\r
\r
- DebugPortDevice->DebugPortVariable = AllocatePool (DataSize);\r
- if (DebugPortDevice->DebugPortVariable != NULL) {\r
+ mDebugPortDevice.DebugPortVariable = AllocatePool (DataSize);\r
+ if (mDebugPortDevice.DebugPortVariable != NULL) {\r
gRT->GetVariable (\r
(CHAR16 *) EFI_DEBUGPORT_VARIABLE_NAME,\r
&gEfiDebugPortVariableGuid,\r
NULL,\r
&DataSize,\r
- DebugPortDevice->DebugPortVariable\r
+ mDebugPortDevice.DebugPortVariable\r
);\r
- DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) DebugPortDevice->DebugPortVariable;\r
+ DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable;\r
while (!IsDevicePathEnd (DevicePath) && !IS_UART_DEVICEPATH (DevicePath)) {\r
DevicePath = NextDevicePathNode (DevicePath);\r
}\r
\r
if (IsDevicePathEnd (DevicePath)) {\r
- FreePool (gDebugPortDevice->DebugPortVariable);\r
- DebugPortDevice->DebugPortVariable = NULL;\r
+ FreePool (mDebugPortDevice.DebugPortVariable);\r
+ mDebugPortDevice.DebugPortVariable = NULL;\r
} else {\r
CopyMem (\r
- &DebugPortDevice->BaudRate,\r
+ &mDebugPortDevice.BaudRate,\r
&((UART_DEVICE_PATH *) DevicePath)->BaudRate,\r
sizeof (((UART_DEVICE_PATH *) DevicePath)->BaudRate)\r
);\r
- DebugPortDevice->ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;\r
- DebugPortDevice->Timeout = DEBUGPORT_UART_DEFAULT_TIMEOUT;\r
+ mDebugPortDevice.ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;\r
+ mDebugPortDevice.Timeout = DEBUGPORT_UART_DEFAULT_TIMEOUT;\r
CopyMem (\r
- &DebugPortDevice->Parity,\r
+ &mDebugPortDevice.Parity,\r
&((UART_DEVICE_PATH *) DevicePath)->Parity,\r
sizeof (((UART_DEVICE_PATH *) DevicePath)->Parity)\r
);\r
CopyMem (\r
- &DebugPortDevice->DataBits,\r
+ &mDebugPortDevice.DataBits,\r
&((UART_DEVICE_PATH *) DevicePath)->DataBits,\r
sizeof (((UART_DEVICE_PATH *) DevicePath)->DataBits)\r
);\r
CopyMem (\r
- &DebugPortDevice->StopBits,\r
+ &mDebugPortDevice.StopBits,\r
&((UART_DEVICE_PATH *) DevicePath)->StopBits,\r
sizeof (((UART_DEVICE_PATH *) DevicePath)->StopBits)\r
);\r
}\r
}\r
\r
-\r
-//\r
-// implementation code\r
-//\r
-\r
/**\r
Debug Port Driver entry point. \r
\r
&gDebugPortComponentName2\r
);\r
ASSERT_EFI_ERROR (Status);\r
- //\r
- // Allocate and Initialize dev structure\r
- //\r
- gDebugPortDevice = AllocateZeroPool (sizeof (DEBUGPORT_DEVICE));\r
- if (gDebugPortDevice == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- //\r
- // Fill in static and default pieces of device structure first.\r
- //\r
- gDebugPortDevice->Signature = DEBUGPORT_DEVICE_SIGNATURE;\r
-\r
- gDebugPortDevice->DebugPortInterface.Reset = DebugPortReset;\r
- gDebugPortDevice->DebugPortInterface.Read = DebugPortRead;\r
- gDebugPortDevice->DebugPortInterface.Write = DebugPortWrite;\r
- gDebugPortDevice->DebugPortInterface.Poll = DebugPortPoll;\r
-\r
- gDebugPortDevice->BaudRate = DEBUGPORT_UART_DEFAULT_BAUDRATE;\r
- gDebugPortDevice->ReceiveFifoDepth = DEBUGPORT_UART_DEFAULT_FIFO_DEPTH;\r
- gDebugPortDevice->Timeout = DEBUGPORT_UART_DEFAULT_TIMEOUT;\r
- gDebugPortDevice->Parity = (EFI_PARITY_TYPE) DEBUGPORT_UART_DEFAULT_PARITY;\r
- gDebugPortDevice->DataBits = DEBUGPORT_UART_DEFAULT_DATA_BITS;\r
- gDebugPortDevice->StopBits = (EFI_STOP_BITS_TYPE) DEBUGPORT_UART_DEFAULT_STOP_BITS;\r
\r
return EFI_SUCCESS;\r
}\r
\r
//\r
// Check to see that there's not a debugport protocol already published\r
+ // Question: Why do we prevent debugport protocol published on more one device?\r
//\r
if (gBS->LocateProtocol (&gEfiDebugPortProtocolGuid, NULL, (VOID **) &DebugPortInterface) != EFI_NOT_FOUND) {\r
return EFI_UNSUPPORTED;\r
//\r
// Read DebugPort variable to determine debug port selection and parameters\r
//\r
- GetDebugPortVariable (gDebugPortDevice);\r
+ GetDebugPortVariable ();\r
\r
- if (gDebugPortDevice->DebugPortVariable != NULL) {\r
+ if (mDebugPortDevice.DebugPortVariable != NULL) {\r
//\r
// There's a DEBUGPORT variable, so do LocateDevicePath and check to see if\r
// the closest matching handle matches the controller handle, and if it does,\r
// check to see that the remaining device path has the DebugPort GUIDed messaging\r
// device path only. Otherwise, it's a mismatch and EFI_UNSUPPORTED is returned.\r
//\r
- Dp1 = DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) gDebugPortDevice->DebugPortVariable);\r
+ Dp1 = DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) mDebugPortDevice.DebugPortVariable);\r
if (Dp1 == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
Status = EFI_UNSUPPORTED;\r
}\r
\r
- if (Status == EFI_SUCCESS && (Dp2->Type != 3 || Dp2->SubType != 10 || *((UINT16 *) Dp2->Length) != 20)) {\r
+ if (Status == EFI_SUCCESS && \r
+ (Dp2->Type != MESSAGING_DEVICE_PATH ||\r
+ Dp2->SubType != MSG_VENDOR_DP || \r
+ *((UINT16 *) Dp2->Length) != sizeof (VENDOR_DEVICE_PATH))) {\r
+\r
Status = EFI_UNSUPPORTED;\r
}\r
\r
Status = gBS->OpenProtocol (\r
ControllerHandle,\r
&gEfiSerialIoProtocolGuid,\r
- (VOID **) &gDebugPortDevice->SerialIoBinding,\r
+ (VOID **) &mDebugPortDevice.SerialIoBinding,\r
This->DriverBindingHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE\r
return Status;\r
}\r
\r
- gDebugPortDevice->SerialIoDeviceHandle = ControllerHandle;\r
+ mDebugPortDevice.SerialIoDeviceHandle = ControllerHandle;\r
\r
//\r
// Initialize the Serial Io interface...\r
//\r
- Status = gDebugPortDevice->SerialIoBinding->SetAttributes (\r
- gDebugPortDevice->SerialIoBinding,\r
- gDebugPortDevice->BaudRate,\r
- gDebugPortDevice->ReceiveFifoDepth,\r
- gDebugPortDevice->Timeout,\r
- gDebugPortDevice->Parity,\r
- gDebugPortDevice->DataBits,\r
- gDebugPortDevice->StopBits\r
+ Status = mDebugPortDevice.SerialIoBinding->SetAttributes (\r
+ mDebugPortDevice.SerialIoBinding,\r
+ mDebugPortDevice.BaudRate,\r
+ mDebugPortDevice.ReceiveFifoDepth,\r
+ mDebugPortDevice.Timeout,\r
+ mDebugPortDevice.Parity,\r
+ mDebugPortDevice.DataBits,\r
+ mDebugPortDevice.StopBits\r
);\r
if (EFI_ERROR (Status)) {\r
- gDebugPortDevice->BaudRate = 0;\r
- gDebugPortDevice->Parity = DefaultParity;\r
- gDebugPortDevice->DataBits = 0;\r
- gDebugPortDevice->StopBits = DefaultStopBits;\r
- gDebugPortDevice->ReceiveFifoDepth = 0;\r
- Status = gDebugPortDevice->SerialIoBinding->SetAttributes (\r
- gDebugPortDevice->SerialIoBinding,\r
- gDebugPortDevice->BaudRate,\r
- gDebugPortDevice->ReceiveFifoDepth,\r
- gDebugPortDevice->Timeout,\r
- gDebugPortDevice->Parity,\r
- gDebugPortDevice->DataBits,\r
- gDebugPortDevice->StopBits\r
+ mDebugPortDevice.BaudRate = 0;\r
+ mDebugPortDevice.Parity = DefaultParity;\r
+ mDebugPortDevice.DataBits = 0;\r
+ mDebugPortDevice.StopBits = DefaultStopBits;\r
+ mDebugPortDevice.ReceiveFifoDepth = 0;\r
+ Status = mDebugPortDevice.SerialIoBinding->SetAttributes (\r
+ mDebugPortDevice.SerialIoBinding,\r
+ mDebugPortDevice.BaudRate,\r
+ mDebugPortDevice.ReceiveFifoDepth,\r
+ mDebugPortDevice.Timeout,\r
+ mDebugPortDevice.Parity,\r
+ mDebugPortDevice.DataBits,\r
+ mDebugPortDevice.StopBits\r
);\r
if (EFI_ERROR (Status)) {\r
gBS->CloseProtocol (\r
}\r
}\r
\r
- gDebugPortDevice->SerialIoBinding->Reset (gDebugPortDevice->SerialIoBinding);\r
+ mDebugPortDevice.SerialIoBinding->Reset (mDebugPortDevice.SerialIoBinding);\r
\r
//\r
// Create device path instance for DebugPort\r
SetDevicePathEndNode (Dp1);\r
}\r
\r
- gDebugPortDevice->DebugPortDevicePath = AppendDevicePathNode (Dp1, (EFI_DEVICE_PATH_PROTOCOL *) &DebugPortDP);\r
- if (gDebugPortDevice->DebugPortDevicePath == NULL) {\r
+ mDebugPortDevice.DebugPortDevicePath = AppendDevicePathNode (Dp1, (EFI_DEVICE_PATH_PROTOCOL *) &DebugPortDP);\r
+ if (mDebugPortDevice.DebugPortDevicePath == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
//\r
// Publish DebugPort and Device Path protocols\r
//\r
Status = gBS->InstallMultipleProtocolInterfaces (\r
- &gDebugPortDevice->DebugPortDeviceHandle,\r
+ &mDebugPortDevice.DebugPortDeviceHandle,\r
&gEfiDevicePathProtocolGuid,\r
- gDebugPortDevice->DebugPortDevicePath,\r
+ mDebugPortDevice.DebugPortDevicePath,\r
&gEfiDebugPortProtocolGuid,\r
- &gDebugPortDevice->DebugPortInterface,\r
+ &mDebugPortDevice.DebugPortInterface,\r
NULL\r
);\r
\r
Status = gBS->OpenProtocol (\r
ControllerHandle,\r
&gEfiSerialIoProtocolGuid,\r
- (VOID **) &gDebugPortDevice->SerialIoBinding,\r
+ (VOID **) &mDebugPortDevice.SerialIoBinding,\r
This->DriverBindingHandle,\r
- gDebugPortDevice->DebugPortDeviceHandle,\r
+ mDebugPortDevice.DebugPortDeviceHandle,\r
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
);\r
\r
\r
BufferSize = 48;\r
DebugPortWrite (\r
- &gDebugPortDevice->DebugPortInterface,\r
+ &mDebugPortDevice.DebugPortInterface,\r
0,\r
&BufferSize,\r
"DebugPort driver failed to open child controller\n\n"\r
}\r
\r
DEBUG_CODE_BEGIN ();\r
- UINTN BufferSize;\r
+ UINTN BufferSize;\r
\r
BufferSize = 38;\r
DebugPortWrite (\r
- &gDebugPortDevice->DebugPortInterface,\r
+ &mDebugPortDevice.DebugPortInterface,\r
0,\r
&BufferSize,\r
"Hello World from the DebugPort driver\n\n"\r
);\r
+\r
DEBUG_CODE_END ();\r
\r
return EFI_SUCCESS;\r
ControllerHandle\r
);\r
\r
- gDebugPortDevice->SerialIoBinding = NULL;\r
+ mDebugPortDevice.SerialIoBinding = NULL;\r
\r
gBS->CloseProtocol (\r
ControllerHandle,\r
ControllerHandle\r
);\r
\r
- FreePool (gDebugPortDevice->DebugPortDevicePath);\r
+ FreePool (mDebugPortDevice.DebugPortDevicePath);\r
\r
return EFI_SUCCESS;\r
} else {\r
// Disconnect SerialIo child handle\r
//\r
Status = gBS->CloseProtocol (\r
- gDebugPortDevice->SerialIoDeviceHandle,\r
+ mDebugPortDevice.SerialIoDeviceHandle,\r
&gEfiSerialIoProtocolGuid,\r
This->DriverBindingHandle,\r
- gDebugPortDevice->DebugPortDeviceHandle\r
+ mDebugPortDevice.DebugPortDeviceHandle\r
);\r
\r
if (EFI_ERROR (Status)) {\r
// Unpublish our protocols (DevicePath, DebugPort)\r
//\r
Status = gBS->UninstallMultipleProtocolInterfaces (\r
- gDebugPortDevice->DebugPortDeviceHandle,\r
+ mDebugPortDevice.DebugPortDeviceHandle,\r
&gEfiDevicePathProtocolGuid,\r
- gDebugPortDevice->DebugPortDevicePath,\r
+ mDebugPortDevice.DebugPortDevicePath,\r
&gEfiDebugPortProtocolGuid,\r
- &gDebugPortDevice->DebugPortInterface,\r
+ &mDebugPortDevice.DebugPortInterface,\r
NULL\r
);\r
\r
gBS->OpenProtocol (\r
ControllerHandle,\r
&gEfiSerialIoProtocolGuid,\r
- (VOID **) &gDebugPortDevice->SerialIoBinding,\r
+ (VOID **) &mDebugPortDevice.SerialIoBinding,\r
This->DriverBindingHandle,\r
- gDebugPortDevice->DebugPortDeviceHandle,\r
+ mDebugPortDevice.DebugPortDeviceHandle,\r
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
);\r
} else {\r
- gDebugPortDevice->DebugPortDeviceHandle = NULL;\r
+ mDebugPortDevice.DebugPortDeviceHandle = NULL;\r
}\r
}\r
\r
DebugPortDevice = DEBUGPORT_DEVICE_FROM_THIS (This);\r
BufferPtr = Buffer;\r
LocalBufferSize = *BufferSize;\r
+\r
do {\r
Status = DebugPortDevice->SerialIoBinding->Read (\r
DebugPortDevice->SerialIoBinding,\r
\r
@retval EFI_SUCCESS Unload Debug Port driver successfully.\r
@retval EFI_ABORTED Serial IO is still binding.\r
- @retval others Fails to unload Debug Port driver.\r
\r
**/\r
EFI_STATUS\r
EFI_HANDLE ImageHandle\r
)\r
{\r
- EFI_STATUS Status;\r
-\r
- if (gDebugPortDevice->SerialIoBinding != NULL) {\r
+ if (mDebugPortDevice.SerialIoBinding != NULL) {\r
return EFI_ABORTED;\r
}\r
\r
- Status = gBS->UninstallMultipleProtocolInterfaces (\r
- ImageHandle,\r
- &gEfiDriverBindingProtocolGuid,\r
- &gDebugPortDevice->DriverBindingInterface,\r
- &gEfiComponentNameProtocolGuid,\r
- &gDebugPortDevice->ComponentNameInterface,\r
- NULL\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
//\r
// Clean up allocations\r
//\r
- if (gDebugPortDevice->DebugPortVariable != NULL) {\r
- FreePool (gDebugPortDevice->DebugPortVariable);\r
+ if (mDebugPortDevice.DebugPortVariable != NULL) {\r
+ FreePool (mDebugPortDevice.DebugPortVariable);\r
}\r
\r
- FreePool (gDebugPortDevice);\r
-\r
return EFI_SUCCESS;\r
}\r