1*f439973dSWarner Losh /** @file 2*f439973dSWarner Losh The Decompress Protocol Interface as defined in UEFI spec 3*f439973dSWarner Losh 4*f439973dSWarner Losh Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> 5*f439973dSWarner Losh SPDX-License-Identifier: BSD-2-Clause-Patent 6*f439973dSWarner Losh 7*f439973dSWarner Losh **/ 8*f439973dSWarner Losh 9*f439973dSWarner Losh #ifndef __DECOMPRESS_H__ 10*f439973dSWarner Losh #define __DECOMPRESS_H__ 11*f439973dSWarner Losh 12*f439973dSWarner Losh #define EFI_DECOMPRESS_PROTOCOL_GUID \ 13*f439973dSWarner Losh { \ 14*f439973dSWarner Losh 0xd8117cfe, 0x94a6, 0x11d4, {0x9a, 0x3a, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \ 15*f439973dSWarner Losh } 16*f439973dSWarner Losh 17*f439973dSWarner Losh typedef struct _EFI_DECOMPRESS_PROTOCOL EFI_DECOMPRESS_PROTOCOL; 18*f439973dSWarner Losh 19*f439973dSWarner Losh /** 20*f439973dSWarner Losh The GetInfo() function retrieves the size of the uncompressed buffer 21*f439973dSWarner Losh and the temporary scratch buffer required to decompress the buffer 22*f439973dSWarner Losh specified by Source and SourceSize. If the size of the uncompressed 23*f439973dSWarner Losh buffer or the size of the scratch buffer cannot be determined from 24*f439973dSWarner Losh the compressed data specified by Source and SourceData, then 25*f439973dSWarner Losh EFI_INVALID_PARAMETER is returned. Otherwise, the size of the uncompressed 26*f439973dSWarner Losh buffer is returned in DestinationSize, the size of the scratch buffer is 27*f439973dSWarner Losh returned in ScratchSize, and EFI_SUCCESS is returned. 28*f439973dSWarner Losh 29*f439973dSWarner Losh The GetInfo() function does not have a scratch buffer available to perform 30*f439973dSWarner Losh a thorough checking of the validity of the source data. It just retrieves 31*f439973dSWarner Losh the 'Original Size' field from the beginning bytes of the source data and 32*f439973dSWarner Losh output it as DestinationSize. And ScratchSize is specific to the decompression 33*f439973dSWarner Losh implementation. 34*f439973dSWarner Losh 35*f439973dSWarner Losh @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance. 36*f439973dSWarner Losh @param Source The source buffer containing the compressed data. 37*f439973dSWarner Losh @param SourceSize The size, in bytes, of source buffer. 38*f439973dSWarner Losh @param DestinationSize A pointer to the size, in bytes, of the uncompressed buffer 39*f439973dSWarner Losh that will be generated when the compressed buffer specified 40*f439973dSWarner Losh by Source and SourceSize is decompressed. 41*f439973dSWarner Losh @param ScratchSize A pointer to the size, in bytes, of the scratch buffer that 42*f439973dSWarner Losh is required to decompress the compressed buffer specified by 43*f439973dSWarner Losh Source and SourceSize. 44*f439973dSWarner Losh 45*f439973dSWarner Losh @retval EFI_SUCCESS The size of the uncompressed data was returned in DestinationSize 46*f439973dSWarner Losh and the size of the scratch buffer was returned in ScratchSize. 47*f439973dSWarner Losh @retval EFI_INVALID_PARAMETER The size of the uncompressed data or the size of the scratch 48*f439973dSWarner Losh buffer cannot be determined from the compressed data specified by 49*f439973dSWarner Losh Source and SourceData. 50*f439973dSWarner Losh 51*f439973dSWarner Losh **/ 52*f439973dSWarner Losh typedef 53*f439973dSWarner Losh EFI_STATUS 54*f439973dSWarner Losh (EFIAPI *EFI_DECOMPRESS_GET_INFO)( 55*f439973dSWarner Losh IN EFI_DECOMPRESS_PROTOCOL *This, 56*f439973dSWarner Losh IN VOID *Source, 57*f439973dSWarner Losh IN UINT32 SourceSize, 58*f439973dSWarner Losh OUT UINT32 *DestinationSize, 59*f439973dSWarner Losh OUT UINT32 *ScratchSize 60*f439973dSWarner Losh ); 61*f439973dSWarner Losh 62*f439973dSWarner Losh /** 63*f439973dSWarner Losh The Decompress() function extracts decompressed data to its original form. 64*f439973dSWarner Losh 65*f439973dSWarner Losh This protocol is designed so that the decompression algorithm can be 66*f439973dSWarner Losh implemented without using any memory services. As a result, the 67*f439973dSWarner Losh Decompress() function is not allowed to call AllocatePool() or 68*f439973dSWarner Losh AllocatePages() in its implementation. It is the caller's responsibility 69*f439973dSWarner Losh to allocate and free the Destination and Scratch buffers. 70*f439973dSWarner Losh 71*f439973dSWarner Losh If the compressed source data specified by Source and SourceSize is 72*f439973dSWarner Losh successfully decompressed into Destination, then EFI_SUCCESS is returned. 73*f439973dSWarner Losh If the compressed source data specified by Source and SourceSize is not in 74*f439973dSWarner Losh a valid compressed data format, then EFI_INVALID_PARAMETER is returned. 75*f439973dSWarner Losh 76*f439973dSWarner Losh @param This A pointer to the EFI_DECOMPRESS_PROTOCOL instance. 77*f439973dSWarner Losh @param Source The source buffer containing the compressed data. 78*f439973dSWarner Losh @param SourceSize The size of source data. 79*f439973dSWarner Losh @param Destination On output, the destination buffer that contains 80*f439973dSWarner Losh the uncompressed data. 81*f439973dSWarner Losh @param DestinationSize The size of destination buffer. The size of destination 82*f439973dSWarner Losh buffer needed is obtained from GetInfo(). 83*f439973dSWarner Losh @param Scratch A temporary scratch buffer that is used to perform the 84*f439973dSWarner Losh decompression. 85*f439973dSWarner Losh @param ScratchSize The size of scratch buffer. The size of scratch buffer needed 86*f439973dSWarner Losh is obtained from GetInfo(). 87*f439973dSWarner Losh 88*f439973dSWarner Losh @retval EFI_SUCCESS Decompression completed successfully, and the uncompressed 89*f439973dSWarner Losh buffer is returned in Destination. 90*f439973dSWarner Losh @retval EFI_INVALID_PARAMETER The source buffer specified by Source and SourceSize is 91*f439973dSWarner Losh corrupted (not in a valid compressed format). 92*f439973dSWarner Losh 93*f439973dSWarner Losh **/ 94*f439973dSWarner Losh typedef 95*f439973dSWarner Losh EFI_STATUS 96*f439973dSWarner Losh (EFIAPI *EFI_DECOMPRESS_DECOMPRESS)( 97*f439973dSWarner Losh IN EFI_DECOMPRESS_PROTOCOL *This, 98*f439973dSWarner Losh IN VOID *Source, 99*f439973dSWarner Losh IN UINT32 SourceSize, 100*f439973dSWarner Losh IN OUT VOID *Destination, 101*f439973dSWarner Losh IN UINT32 DestinationSize, 102*f439973dSWarner Losh IN OUT VOID *Scratch, 103*f439973dSWarner Losh IN UINT32 ScratchSize 104*f439973dSWarner Losh ); 105*f439973dSWarner Losh 106*f439973dSWarner Losh /// 107*f439973dSWarner Losh /// Provides a decompression service. 108*f439973dSWarner Losh /// 109*f439973dSWarner Losh struct _EFI_DECOMPRESS_PROTOCOL { 110*f439973dSWarner Losh EFI_DECOMPRESS_GET_INFO GetInfo; 111*f439973dSWarner Losh EFI_DECOMPRESS_DECOMPRESS Decompress; 112*f439973dSWarner Losh }; 113*f439973dSWarner Losh 114*f439973dSWarner Losh extern EFI_GUID gEfiDecompressProtocolGuid; 115*f439973dSWarner Losh 116*f439973dSWarner Losh #endif 117