init.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 1,186 行 · 第 1/3 页
C
1,186 行
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
init.c
Abstract:
Initialization functions for EFI UNDI32 driver
Revision History
--*/
#include "undi32.h"
//
// Global Variables
//
PXE_SW_UNDI *pxe; // 3.0 entry point
PXE_SW_UNDI *pxe_31; // 3.1 entry
UNDI32_DEV *UNDI32DeviceList[MAX_NIC_INTERFACES];
NII_TABLE *UnidiDataPointer=NULL;
//
// external Global Variables
//
extern UNDI_CALL_TABLE api_table[];
//
// function prototypes
//
EFI_STATUS
InstallConfigTable (
IN VOID
);
EFI_STATUS
EFIAPI
InitializeUNDIDriver (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
VOID
UNDI_notify_virtual (
EFI_EVENT event,
VOID *context
);
VOID
EFIAPI
UndiNotifyExitBs (
EFI_EVENT Event,
VOID *Context
);
EFI_STATUS
EFIAPI
UndiDriverSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
UndiDriverStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
UndiDriverStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
EFI_STATUS
AppendMac2DevPath (
IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPtr,
IN EFI_DEVICE_PATH_PROTOCOL *BaseDevPtr,
IN NIC_DATA_INSTANCE *AdapterInfo
);
//
// end function prototypes
//
VOID
EFIAPI
UndiNotifyVirtual (
EFI_EVENT Event,
VOID *Context
)
/*++
Routine Description:
When address mapping changes to virtual this should make the appropriate
address conversions.
Arguments:
(Standard Event handler)
Returns:
None
--*/
// TODO: Context - add argument and description to function comment
{
UINT16 Index;
VOID *Pxe31Pointer;
if (pxe_31 != NULL) {
Pxe31Pointer = (VOID *) pxe_31;
EfiConvertPointer (
EFI_INTERNAL_POINTER | EFI_OPTIONAL_POINTER,
(void **) &Pxe31Pointer
);
//
// UNDI32DeviceList is an array of pointers
//
for (Index = 0; Index < pxe_31->IFcnt; Index++) {
UNDI32DeviceList[Index]->NIIProtocol_31.ID = (UINT64) Pxe31Pointer;
EfiConvertPointer (
EFI_INTERNAL_POINTER | EFI_OPTIONAL_POINTER,
(void **) &(UNDI32DeviceList[Index])
);
}
EfiConvertPointer (
EFI_INTERNAL_POINTER | EFI_OPTIONAL_POINTER,
(void **) &(pxe_31->EntryPoint)
);
pxe_31 = Pxe31Pointer;
}
for (Index = 0; Index <= PXE_OPCODE_LAST_VALID; Index++) {
EfiConvertPointer (
EFI_INTERNAL_POINTER | EFI_OPTIONAL_POINTER,
(void **) &api_table[Index].api_ptr
);
}
}
VOID
EFIAPI
UndiNotifyExitBs (
EFI_EVENT Event,
VOID *Context
)
/*++
Routine Description:
When EFI is shuting down the boot services, we need to install a
configuration table for UNDI to work at runtime!
Arguments:
(Standard Event handler)
Returns:
None
--*/
// TODO: Context - add argument and description to function comment
{
InstallConfigTable ();
}
//
// UNDI Class Driver Global Variables
//
static EFI_DRIVER_BINDING_PROTOCOL mUndiDriverBinding = {
UndiDriverSupported,
UndiDriverStart,
UndiDriverStop,
0x10,
NULL,
NULL
};
EFI_DRIVER_ENTRY_POINT (InitializeUNDIDriver)
EFI_STATUS
EFIAPI
InitializeUNDIDriver (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Register Driver Binding protocol for this driver.
Arguments:
ImageHandle - Image Handle
SystemTable - Pointer to system table
Returns:
EFI_SUCCESS - Driver loaded.
other - Driver not loaded.
--*/
{
EFI_STATUS Status;
EFI_EVENT Event;
//
// Initialize the EFI Driver Library
//
EfiInitializeRuntimeDriverLib (ImageHandle, SystemTable, UndiNotifyVirtual);
mUndiDriverBinding.ImageHandle = ImageHandle;
mUndiDriverBinding.DriverBindingHandle = ImageHandle;
Status = gBS->InstallProtocolInterface (
&ImageHandle,
&gEfiDriverBindingProtocolGuid,
EFI_NATIVE_INTERFACE,
&mUndiDriverBinding
);
Status = gBS->CreateEvent (
EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,
EFI_TPL_NOTIFY,
UndiNotifyExitBs,
NULL,
&Event
);
if (EFI_ERROR (Status)) {
gBS->UninstallProtocolInterface (
ImageHandle,
&gEfiDriverBindingProtocolGuid,
&mUndiDriverBinding
);
}
return Status;
}
EFI_STATUS
EFIAPI
UndiDriverSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Test to see if this driver supports ControllerHandle. Any ControllerHandle
than contains a DevicePath, PciIo protocol, Class code of 2, Vendor ID of 0x8086,
and DeviceId of (D100_DEVICE_ID || D102_DEVICE_ID || ICH3_DEVICE_ID_1 ||
ICH3_DEVICE_ID_2 || ICH3_DEVICE_ID_3 || ICH3_DEVICE_ID_4 || ICH3_DEVICE_ID_5 ||
ICH3_DEVICE_ID_6 || ICH3_DEVICE_ID_7 || ICH3_DEVICE_ID_8) can be supported.
Arguments:
This - Protocol instance pointer.
Controller - Handle of device to test.
RemainingDevicePath - Not used.
Returns:
EFI_SUCCESS - This driver supports this device.
other - This driver does not support this device.
--*/
{
EFI_STATUS Status;
EFI_PCI_IO_PROTOCOL *PciIo;
PCI_TYPE00 Pci;
Status = gBS->OpenProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
NULL,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->OpenProtocol (
Controller,
&gEfiPciIoProtocolGuid,
(VOID **) &PciIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = PciIo->Pci.Read (
PciIo,
EfiPciIoWidthUint8,
0,
sizeof (PCI_CONFIG_HEADER),
&Pci
);
if (!EFI_ERROR (Status)) {
Status = EFI_UNSUPPORTED;
if (Pci.Hdr.ClassCode[2] == 0x02 && Pci.Hdr.VendorId == PCI_VENDOR_ID_INTEL) {
switch (Pci.Hdr.DeviceId) {
case D100_DEVICE_ID:
case D102_DEVICE_ID:
case ICH3_DEVICE_ID_1:
case ICH3_DEVICE_ID_2:
case ICH3_DEVICE_ID_3:
case ICH3_DEVICE_ID_4:
case ICH3_DEVICE_ID_5:
case ICH3_DEVICE_ID_6:
case ICH3_DEVICE_ID_7:
case ICH3_DEVICE_ID_8:
case 0x1039:
case 0x103A:
case 0x103B:
case 0x103C:
case 0x103D:
case 0x103E:
case 0x1050:
case 0x1051:
case 0x1052:
case 0x1053:
case 0x1054:
case 0x1055:
case 0x1056:
case 0x1057:
case 0x1059:
case 0x1064:
Status = EFI_SUCCESS;
}
}
}
gBS->CloseProtocol (
Controller,
&gEfiPciIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
EFI_STATUS
EFIAPI
UndiDriverStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Start this driver on Controller by opening PciIo and DevicePath protocol.
Initialize PXE structures, create a copy of the Controller Device Path with the
NIC's MAC address appended to it, install the NetworkInterfaceIdentifier protocol
on the newly created Device Path.
Arguments:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?