示例#1
0
EFI_STATUS EFIAPI
OvrFreePool(
	IN VOID				*Buffer
)
{
	EFI_STATUS			Status;
	
	Status = gOrgBS.FreePool(Buffer);
	// do not print to console - requires FreePool - recursion
	// do not print to serial - too many calls from UEFI
	//DebugPrint(1, "->FreePool(%p) = %r\n", Buffer, Status);
	return Status;
}
示例#2
0
文件: nii.c 项目: baloo/ipxe
/**
 * Open PCI I/O protocol and identify BARs
 *
 * @v nii		NII NIC
 * @ret rc		Return status code
 */
static int nii_pci_open ( struct nii_nic *nii ) {
	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
	EFI_HANDLE device = nii->efidev->device;
	EFI_HANDLE pci_device;
	union {
		EFI_PCI_IO_PROTOCOL *pci_io;
		void *interface;
	} pci_io;
	union {
		EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *acpi;
		void *resource;
	} desc;
	unsigned int bar;
	EFI_STATUS efirc;
	int rc;

	/* Locate PCI I/O protocol */
	if ( ( rc = efi_locate_device ( device, &efi_pci_io_protocol_guid,
					&pci_device ) ) != 0 ) {
		DBGC ( nii, "NII %s could not locate PCI I/O protocol: %s\n",
		       nii->dev.name, strerror ( rc ) );
		goto err_locate;
	}
	nii->pci_device = pci_device;

	/* Open PCI I/O protocol */
	if ( ( efirc = bs->OpenProtocol ( pci_device, &efi_pci_io_protocol_guid,
					  &pci_io.interface, efi_image_handle,
					  device,
					  EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){
		rc = -EEFI ( efirc );
		DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n",
		       nii->dev.name, strerror ( rc ) );
		goto err_open;
	}
	nii->pci_io = pci_io.pci_io;

	/* Identify memory and I/O BARs */
	nii->mem_bar = PCI_MAX_BAR;
	nii->io_bar = PCI_MAX_BAR;
	for ( bar = 0 ; bar < PCI_MAX_BAR ; bar++ ) {
		efirc = nii->pci_io->GetBarAttributes ( nii->pci_io, bar, NULL,
							&desc.resource );
		if ( efirc == EFI_UNSUPPORTED ) {
			/* BAR not present; ignore */
			continue;
		}
		if ( efirc != 0 ) {
			rc = -EEFI ( efirc );
			DBGC ( nii, "NII %s could not get BAR %d attributes: "
			       "%s\n", nii->dev.name, bar, strerror ( rc ) );
			goto err_get_bar_attributes;
		}
		if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM ) {
			nii->mem_bar = bar;
		} else if ( desc.acpi->ResType == ACPI_ADDRESS_SPACE_TYPE_IO ) {
			nii->io_bar = bar;
		}
		bs->FreePool ( desc.resource );
	}
	DBGC ( nii, "NII %s has ", nii->dev.name );
	if ( nii->mem_bar < PCI_MAX_BAR ) {
		DBGC ( nii, "memory BAR %d and ", nii->mem_bar );
	} else {
		DBGC ( nii, "no memory BAR and " );
	}
	if ( nii->io_bar < PCI_MAX_BAR ) {
		DBGC ( nii, "I/O BAR %d\n", nii->io_bar );
	} else {
		DBGC ( nii, "no I/O BAR\n" );
	}

	return 0;

 err_get_bar_attributes:
	bs->CloseProtocol ( pci_device, &efi_pci_io_protocol_guid,
			    efi_image_handle, device );
 err_open:
 err_locate:
	return rc;
}
示例#3
0
EFI_STATUS LoadFile(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* systab,
		CHAR16* filename, VOID** dataPtr, UINTN* size,
		EFI_DEVICE_PATH_PROTOCOL** dev_path)
{
	EFI_GUID LoadedImageProtocolGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
	EFI_GUID FileInfoGuid = EFI_FILE_INFO_ID;
	EFI_GUID FileSystemGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
	EFI_STATUS res;

	EFI_BOOT_SERVICES* BS = systab->BootServices;

	//get image info
	EFI_LOADED_IMAGE_PROTOCOL* img_proto;
	res = BS->HandleProtocol(ImageHandle, &LoadedImageProtocolGuid,
			(void**) &img_proto);

	if (res)
	{
		ErrorPrint(L"Failed to get image protocol. (Error %d)\r\n", res);
		return EFI_LOAD_ERROR ;
	}

	EFI_HANDLE img_device_handle = img_proto->DeviceHandle;

	//Get filesystem protocol from device
	EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs_proto;
	res = BS->HandleProtocol(img_device_handle, &FileSystemGuid,
			(VOID**) &fs_proto);

	if (res)
	{
		ErrorPrint(L"Failed to get file system protocol. (Error %d)\r\n", res);
		return EFI_LOAD_ERROR ;
	}

	//open volume
	EFI_FILE_PROTOCOL* volume;
	res = fs_proto->OpenVolume(fs_proto, &volume);

	if (res)
	{
		ErrorPrint(L"Failed to open file volume. (Error %d)\r\n", res);
		return EFI_LOAD_ERROR ;
	}

	//open file
	EFI_FILE_PROTOCOL* file;
	res = volume->Open(volume, &file, filename, EFI_FILE_MODE_READ, 0);

	if (res)
	{
		//don't print error here
		//ErrorPrint(L"Failed to open file '%s'. (Error %d)\r\n", filename, res);
		return EFI_NOT_FOUND ;
	}

	//get file info, two try process
	EFI_FILE_INFO* file_info = NULL;
	UINTN file_info_size = 0;
	res = file->GetInfo(file, &FileInfoGuid, &file_info_size, NULL );

	if (res != EFI_BUFFER_TOO_SMALL )
	{
		ErrorPrint(L"Failed to stat file '%s'. (Error %d)\r\n", filename, res);
		return EFI_NOT_FOUND ;
	}

	res = BS->AllocatePool(EfiLoaderData, file_info_size, (void**) &file_info);

	if (res)
	{
		ErrorPrint(L"Failed to allocate file info memory. (Error %d)\r\n", res);
		return EFI_OUT_OF_RESOURCES ;
	}

	res = file->GetInfo(file, &FileInfoGuid, &file_info_size,
			(void*) file_info);

	if (res)
	{
		BS->FreePool(file_info);
		ErrorPrint(L"Failed to stat file '%s'. (Error %d)\r\n", filename, res);
		return EFI_NOT_FOUND ;
	}

	if (dev_path != NULL )
	{
		*dev_path = FileDevicePath(img_device_handle, filename);
	}

	UINT64 file_size = file_info->FileSize;

	BS->FreePool(file_info);
	file_info = NULL;

	void* data = NULL;
	res = BS->AllocatePool(EfiLoaderData, file_size, (void**) &data);

	if (res)
	{
		ErrorPrint(L"Failed to allocate file data memory. (Error %d)\r\n", res);
		return EFI_OUT_OF_RESOURCES ;
	}

	//read the file
	res = file->Read(file, &file_size, (void*) data);

	if (res)
	{
		BS->FreePool(data);
		ErrorPrint(L"Failed to read file '%s'. (Error %d)\r\n", filename, res);
		return EFI_NOT_FOUND ;
	}

	//close the file
	file->Close(file);
	volume->Close(volume);

	//set the pointer and data size
	*dataPtr = data;
	*size = file_size;

	//return success
	return EFI_SUCCESS;
}
示例#4
-5
/**
 * Locate EFI PCI root bridge I/O protocol
 *
 * @v pci		PCI device
 * @ret handle		EFI PCI root bridge handle
 * @ret root		EFI PCI root bridge I/O protocol, or NULL if not found
 * @ret rc		Return status code
 */
static int efipci_root ( struct pci_device *pci, EFI_HANDLE *handle,
			 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root ) {
	EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
	EFI_HANDLE *handles;
	UINTN num_handles;
	union {
		void *interface;
		EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root;
	} u;
	EFI_STATUS efirc;
	UINTN i;
	int rc;

	/* Enumerate all handles */
	if ( ( efirc = bs->LocateHandleBuffer ( ByProtocol,
			&efi_pci_root_bridge_io_protocol_guid,
			NULL, &num_handles, &handles ) ) != 0 ) {
		rc = -EEFI ( efirc );
		DBGC ( pci, "EFIPCI " PCI_FMT " cannot locate root bridges: "
		       "%s\n", PCI_ARGS ( pci ), strerror ( rc ) );
		goto err_locate;
	}

	/* Look for matching root bridge I/O protocol */
	for ( i = 0 ; i < num_handles ; i++ ) {
		*handle = handles[i];
		if ( ( efirc = bs->OpenProtocol ( *handle,
				&efi_pci_root_bridge_io_protocol_guid,
				&u.interface, efi_image_handle, *handle,
				EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) {
			rc = -EEFI ( efirc );
			DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n",
			       PCI_ARGS ( pci ), efi_handle_name ( *handle ),
			       strerror ( rc ) );
			continue;
		}
		if ( u.root->SegmentNumber == PCI_SEG ( pci->busdevfn ) ) {
			*root = u.root;
			bs->FreePool ( handles );
			return 0;
		}
		bs->CloseProtocol ( *handle,
				    &efi_pci_root_bridge_io_protocol_guid,
				    efi_image_handle, *handle );
	}
	DBGC ( pci, "EFIPCI " PCI_FMT " found no root bridge\n",
	       PCI_ARGS ( pci ) );
	rc = -ENOENT;

	bs->FreePool ( handles );
 err_locate:
	return rc;
}