ConnectController() Recurive 举例分析 如果要在硬盘上读到内容,以下是协议栈, FAT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL connect 其实在connect controller, 以上面为例,如果recursive 带TRUE, 那就会把下面的节点都connect 起来。 TRUE FALSE 看的具体实现: Recursively connect each child handle 递归 即 传进来的参数 和函数里面调用的都是ControllerHandle 下面举两个例子,以次为TRUE和 FALSE ConnectAllUsbHostController 意思就是说,我想要把所有的usb controller 都找出来。 DPRINTF_DEV (“ConnectAllUsbHostController:n”); // ConnectAllPciDevices (); // 把各个pci device 长出来。 // for (UsbIndex = 0; UsbIndex < sizeof (UsbIP)/sizeof (UINT16); UsbIndex++) { HandleIndex = 0; Status = PciIo->Pci.Read ( // if ((UsbClassCReg.BaseCode == PCI_CLASS_SERIAL) && DPRINTF_DEV (” Handle 0x%x belongs to %x Type USB device Path.n”, HandleIndex++; SafeFreePool (HandleBuffer); return SCT_STATUS_SUCCESS; EFI_STATUS Index = 0; DPRINTF_LIB (“ConnectAllPciDevices n”); if (mAllPciDeviceStarted) { gBS->LocateHandleBuffer ( if (NumHandles == 0) { for (Index = 0; Index < NumHandles; Index++) { // FreePool (HandleBuffer); return Status; } // ConnectAllPciDevices
Recursive 是一个重要参数, BIOS 对开机时间在是非常在意的,如果每个controller 都以 Recursive 带TRUE,
那就会非常耗时。
EFI_STATUS
(EFIAPI *EFI_CONNECT_CONTROLLER)(
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE *DriverImageHandle, OPTIONAL
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath, OPTIONAL
IN BOOLEAN Recursive
);
DiskIoDxe EFI_DISK_IO_PROTOCOL
PartitionDxe EFI_BLOCK_IO_PROTOCOL
DiskIoDxe EFI_DISK_IO_PROTOCOL
AhciBusDxe EFI_BLOCK_IO_PROTOCOL
AtaAtaPassThruDxe EFI_ATA_PASS_THRU_PROTOCOL
SataController EFI_IDE_CONTROLLER_INIT_PROTOCOL
PciBusDxe EFI_PCI_IO_PROTOCOL
PciHostBridgeDxe EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
ConnectController() is called recursively until the entire tree of
controllers below the controller specified by ControllerHandle have been created.
The tree of controllers is only expanded one level.
// // Fill in a handle buffer with ControllerHandle's children // for (Link = Handle->Protocols.ForwardLink, ChildHandleCount = 0; Link != &Handle->Protocols; Link = Link->ForwardLink) { Prot = CR(Link, PROTOCOL_INTERFACE, Link, PROTOCOL_INTERFACE_SIGNATURE); for (ProtLink = Prot->OpenList.ForwardLink; ProtLink != &Prot->OpenList; ProtLink = ProtLink->ForwardLink) { OpenData = CR (ProtLink, OPEN_PROTOCOL_DATA, Link, OPEN_PROTOCOL_DATA_SIGNATURE); if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) { ChildHandleBuffer[ChildHandleCount] = OpenData->ControllerHandle; ChildHandleCount++; } } } // // Release the protocol lock on the handle database // CoreReleaseProtocolLock (); // // Recursively connect each child handle // for (Index = 0; Index < ChildHandleCount; Index++) { CoreConnectController ( ChildHandleBuffer[Index], NULL, NULL, TRUE ); }
所有的,不外乎就是 xhci, ehci, ohci, uhci
STATUS
EFIAPI
ConnectAllUsbHostController (VOID)
{
SCT_STATUS Status;
EFI_PCI_IO_PROTOCOL *PciIo;
USB_CLASSC UsbClassCReg;
UINTN NumberOfHandles;
EFI_HANDLE *HandleBuffer;
UINTN UsbIndex;
UINT16 HandleIndex;
UINT16 UsbIP[] = {PCI_IF_XHCI, // 3.0
PCI_IF_EHCI, // 2.0
PCI_IF_OHCI, // 1.0
PCI_IF_UHCI};
// Connect first layer of PCI device.
//
只有ConnectAllPciDevices 才能找到 pciio protocol
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiPciIoProtocolGuid, // 每一个pci device , 都有pciio protocol
NULL,
&NumberOfHandles,
&HandleBuffer);
// Connect USB device path according to its type, the ordering is:
// 1.XHCI 2.EHCI 3.OHCI 4.UCHI
//
while (HandleIndex < NumberOfHandles) {
Status = gBS->HandleProtocol (
HandleBuffer [HandleIndex],
&gEfiPciIoProtocolGuid,
&PciIo);
if (EFI_ERROR (Status)) {
HandleIndex++;
continue;
}
PciIo,
EfiPciIoWidthUint8,
PCI_CLASSCODE_OFFSET,
sizeof (USB_CLASSC) / sizeof (UINT8),
&UsbClassCReg);
if (EFI_ERROR (Status)) {
HandleIndex++;
continue;
}
// Test whether the controller belongs to USB type.
//
(UsbClassCReg.SubClassCode == PCI_CLASS_SERIAL_USB) &&
(UsbClassCReg.PI == UsbIP[UsbIndex])) {
HandleBuffer [HandleIndex], UsbIP[UsbIndex]);
Status = gBS->ConnectController (
HandleBuffer [HandleIndex],
mContextOverrideDriver,
NULL,
TRUE); 逐层递归连接,直到没有新的设备句柄产生,逐层连接,我们才能使用usb设备。
if (!EFI_ERROR(Status)) {
DPRINTF_DEV (” Connection success.n”);
}
}
}
}
} // ConnectAllUsbHostController
EFIAPI
ConnectAllPciDevices (VOID)
{
UINTN Index;
UINTN NumHandles;
EFI_STATUS Status;
EFI_HANDLE *HandleBuffer;
HandleBuffer = NULL;
Status = EFI_NOT_FOUND;
DPRINTF_LIB (” Already happened n”);
return EFI_SUCCESS;
}
ByProtocol,
&gEfiPciRootBridgeIoProtocolGuid, // RootBridge 只有一个
NULL,
&NumHandles,
&HandleBuffer);
DPRINTF_LIB (” Could not find any Pci Root Bridge devices.n”);
return EFI_NOT_FOUND;
}
Status = gBS->ConnectController (
HandleBuffer [Index],
NULL,
NULL,
FALSE); // 此时,我们只需要找一层,找到device ,能使用pci io 即可。
DPRINTF_LIB (” ConnectController return %r.n”, Status);
}
// Finally, freed the resource.
//
mAllPciDeviceStarted = TRUE;
DUMP_ALL_DEVICE_PATHS
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算