Home | History | Annotate | Download | only in EfiScriptLib
      1 /*++
      2 
      3 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
      4 This program and the accompanying materials
      5 are licensed and made available under the terms and conditions of the BSD License
      6 which accompanies this distribution.  The full text of the license may be found at
      7 http://opensource.org/licenses/bsd-license.php
      8 
      9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     11 
     12 Module Name:
     13 
     14     EfiScriptLib.c
     15 
     16 Abstract:
     17 
     18   Support for EFI script.
     19 
     20 --*/
     21 
     22 #include "EfiScriptLib.h"
     23 
     24 EFI_BOOT_SCRIPT_SAVE_PROTOCOL *mBootScriptSave;
     25 
     26 UINTN
     27 EfiScriptLibAsciiStrLen (
     28   IN CHAR8   *String
     29   )
     30 /*++
     31 
     32 Routine Description:
     33   Return the number of Ascii characters in String. This is not the same as
     34   the length of the string in bytes.
     35 
     36 Arguments:
     37   String - String to process
     38 
     39 Returns:
     40   Number of Ascii characters in String
     41 
     42 --*/
     43 {
     44   UINTN Length;
     45 
     46   for (Length=0; *String; String++, Length++);
     47   return Length;
     48 }
     49 
     50 UINTN
     51 EfiScriptLibStrLen (
     52   IN CHAR16   *String
     53   )
     54 /*++
     55 
     56 Routine Description:
     57   Return the number of Unicode characters in String. This is not the same as
     58   the length of the string in bytes.
     59 
     60 Arguments:
     61   String - String to process
     62 
     63 Returns:
     64   Number of Unicode characters in String
     65 
     66 --*/
     67 {
     68   UINTN Length;
     69 
     70   for (Length=0; *String; String++, Length++);
     71   return Length;
     72 }
     73 
     74 EFI_STATUS
     75 EFIAPI
     76 BootScriptSaveInitialize (
     77   IN EFI_HANDLE           ImageHandle,
     78   IN EFI_SYSTEM_TABLE     *SystemTable
     79   )
     80 /*++
     81 
     82 Routine Description:
     83 
     84   Intialize Boot Script Lib if it has not yet been initialized.
     85 
     86 Arguments:
     87 
     88   (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
     89 
     90 Returns:
     91 
     92   EFI_STATUS always returns EFI_SUCCESS
     93 
     94 --*/
     95 // GC_TODO:    ImageHandle - add argument and description to function comment
     96 // GC_TODO:    SystemTable - add argument and description to function comment
     97 {
     98   EFI_STATUS        Status;
     99   EFI_BOOT_SERVICES *BS;
    100 
    101   BS      = SystemTable->BootServices;
    102 
    103   Status  = BS->LocateProtocol (&gEfiBootScriptSaveGuid, NULL, (VOID **)&mBootScriptSave);
    104   if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
    105     mBootScriptSave = NULL;
    106   }
    107 
    108   return EFI_SUCCESS;
    109 }
    110 
    111 EFI_STATUS
    112 EFIAPI
    113 BootScriptSaveIoWrite (
    114   IN  UINT16                            TableName,
    115   IN  EFI_BOOT_SCRIPT_WIDTH             Width,
    116   IN  UINT64                            Address,
    117   IN  UINTN                             Count,
    118   IN  VOID                              *Buffer
    119   )
    120 /*++
    121 
    122 Routine Description:
    123 
    124   Save I/O write to boot script
    125 
    126 Arguments:
    127 
    128   TableName - Desired boot script table
    129 
    130   (Standard EFI IO write script parameter)
    131 
    132 Returns:
    133 
    134   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    135 
    136   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    137 
    138 --*/
    139 // GC_TODO:    Width - add argument and description to function comment
    140 // GC_TODO:    Address - add argument and description to function comment
    141 // GC_TODO:    Count - add argument and description to function comment
    142 // GC_TODO:    Buffer - add argument and description to function comment
    143 {
    144   if (mBootScriptSave == NULL) {
    145     return EFI_NOT_FOUND;
    146   }
    147 
    148   mBootScriptSave->Write (
    149                     mBootScriptSave,
    150                     TableName,
    151                     EFI_BOOT_SCRIPT_IO_WRITE_OPCODE,
    152                     Width,
    153                     Address,
    154                     Count,
    155                     Buffer
    156                     );
    157 
    158   return EFI_SUCCESS;
    159 }
    160 
    161 EFI_STATUS
    162 EFIAPI
    163 BootScriptSaveIoReadWrite (
    164   IN  UINT16                            TableName,
    165   IN  EFI_BOOT_SCRIPT_WIDTH             Width,
    166   IN  UINT64                            Address,
    167   IN  VOID                              *Data,
    168   IN  VOID                              *DataMask
    169   )
    170 /*++
    171 
    172 Routine Description:
    173 
    174   Save I/O write to boot script
    175 
    176 Arguments:
    177 
    178   TableName - Desired boot script table
    179 
    180   (Standard EFI IO read write script parameter)
    181 
    182 Returns:
    183 
    184   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    185 
    186   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    187 
    188 --*/
    189 // GC_TODO:    Width - add argument and description to function comment
    190 // GC_TODO:    Address - add argument and description to function comment
    191 // GC_TODO:    Data - add argument and description to function comment
    192 // GC_TODO:    DataMask - add argument and description to function comment
    193 {
    194   if (mBootScriptSave == NULL) {
    195     return EFI_NOT_FOUND;
    196   }
    197 
    198   mBootScriptSave->Write (
    199                     mBootScriptSave,
    200                     TableName,
    201                     EFI_BOOT_SCRIPT_IO_READ_WRITE_OPCODE,
    202                     Width,
    203                     Address,
    204                     Data,
    205                     DataMask
    206                     );
    207 
    208   return EFI_SUCCESS;
    209 }
    210 
    211 EFI_STATUS
    212 EFIAPI
    213 BootScriptSaveMemWrite (
    214   IN  UINT16                            TableName,
    215   IN  EFI_BOOT_SCRIPT_WIDTH             Width,
    216   IN  UINT64                            Address,
    217   IN  UINTN                             Count,
    218   IN  VOID                              *Buffer
    219   )
    220 /*++
    221 
    222 Routine Description:
    223 
    224   Save I/O write to boot script
    225 
    226 Arguments:
    227 
    228   TableName - Desired boot script table
    229 
    230   (Standard EFI MEM write script parameter)
    231 
    232 Returns:
    233 
    234   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    235 
    236   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    237 
    238 --*/
    239 // GC_TODO:    Width - add argument and description to function comment
    240 // GC_TODO:    Address - add argument and description to function comment
    241 // GC_TODO:    Count - add argument and description to function comment
    242 // GC_TODO:    Buffer - add argument and description to function comment
    243 {
    244   if (mBootScriptSave == NULL) {
    245     return EFI_NOT_FOUND;
    246   }
    247 
    248   mBootScriptSave->Write (
    249                     mBootScriptSave,
    250                     TableName,
    251                     EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE,
    252                     Width,
    253                     Address,
    254                     Count,
    255                     Buffer
    256                     );
    257 
    258   return EFI_SUCCESS;
    259 }
    260 
    261 EFI_STATUS
    262 EFIAPI
    263 BootScriptSaveMemReadWrite (
    264   IN  UINT16                            TableName,
    265   IN  EFI_BOOT_SCRIPT_WIDTH             Width,
    266   IN  UINT64                            Address,
    267   IN  VOID                              *Data,
    268   IN  VOID                              *DataMask
    269   )
    270 /*++
    271 
    272 Routine Description:
    273 
    274   Save I/O write to boot script
    275 
    276 Arguments:
    277 
    278   TableName - Desired boot script table
    279 
    280   (Standard EFI MEM read write script parameter)
    281 
    282 Returns:
    283 
    284   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    285 
    286   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    287 
    288 --*/
    289 // GC_TODO:    Width - add argument and description to function comment
    290 // GC_TODO:    Address - add argument and description to function comment
    291 // GC_TODO:    Data - add argument and description to function comment
    292 // GC_TODO:    DataMask - add argument and description to function comment
    293 {
    294   if (mBootScriptSave == NULL) {
    295     return EFI_NOT_FOUND;
    296   }
    297 
    298   mBootScriptSave->Write (
    299                     mBootScriptSave,
    300                     TableName,
    301                     EFI_BOOT_SCRIPT_MEM_READ_WRITE_OPCODE,
    302                     Width,
    303                     Address,
    304                     Data,
    305                     DataMask
    306                     );
    307 
    308   return EFI_SUCCESS;
    309 }
    310 
    311 EFI_STATUS
    312 EFIAPI
    313 BootScriptSavePciCfgWrite (
    314   IN  UINT16                            TableName,
    315   IN  EFI_BOOT_SCRIPT_WIDTH             Width,
    316   IN  UINT64                            Address,
    317   IN  UINTN                             Count,
    318   IN  VOID                              *Buffer
    319   )
    320 /*++
    321 
    322 Routine Description:
    323 
    324   Save I/O write to boot script
    325 
    326 Arguments:
    327 
    328   TableName - Desired boot script table
    329 
    330   (Standard EFI PCI write script parameter)
    331 
    332 Returns:
    333 
    334   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    335 
    336   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    337 
    338 --*/
    339 // GC_TODO:    Width - add argument and description to function comment
    340 // GC_TODO:    Address - add argument and description to function comment
    341 // GC_TODO:    Count - add argument and description to function comment
    342 // GC_TODO:    Buffer - add argument and description to function comment
    343 {
    344   if (mBootScriptSave == NULL) {
    345     return EFI_NOT_FOUND;
    346   }
    347 
    348   mBootScriptSave->Write (
    349                     mBootScriptSave,
    350                     TableName,
    351                     EFI_BOOT_SCRIPT_PCI_CONFIG_WRITE_OPCODE,
    352                     Width,
    353                     Address,
    354                     Count,
    355                     Buffer
    356                     );
    357 
    358   return EFI_SUCCESS;
    359 }
    360 
    361 EFI_STATUS
    362 EFIAPI
    363 BootScriptSavePciCfgReadWrite (
    364   IN  UINT16                            TableName,
    365   IN  EFI_BOOT_SCRIPT_WIDTH             Width,
    366   IN  UINT64                            Address,
    367   IN  VOID                              *Data,
    368   IN  VOID                              *DataMask
    369   )
    370 /*++
    371 
    372 Routine Description:
    373 
    374   Save I/O write to boot script
    375 
    376 Arguments:
    377 
    378   TableName - Desired boot script table
    379 
    380   (Standard EFI PCI read write script parameter)
    381 
    382 Returns:
    383 
    384   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    385 
    386   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    387 
    388 --*/
    389 // GC_TODO:    Width - add argument and description to function comment
    390 // GC_TODO:    Address - add argument and description to function comment
    391 // GC_TODO:    Data - add argument and description to function comment
    392 // GC_TODO:    DataMask - add argument and description to function comment
    393 {
    394   if (mBootScriptSave == NULL) {
    395     return EFI_NOT_FOUND;
    396   }
    397 
    398   mBootScriptSave->Write (
    399                     mBootScriptSave,
    400                     TableName,
    401                     EFI_BOOT_SCRIPT_PCI_CONFIG_READ_WRITE_OPCODE,
    402                     Width,
    403                     Address,
    404                     Data,
    405                     DataMask
    406                     );
    407 
    408   return EFI_SUCCESS;
    409 }
    410 
    411 EFI_STATUS
    412 EFIAPI
    413 BootScriptSaveSmbusExecute (
    414   IN  UINT16                            TableName,
    415   IN  EFI_SMBUS_DEVICE_ADDRESS          SlaveAddress,
    416   IN  EFI_SMBUS_DEVICE_COMMAND          Command,
    417   IN  EFI_SMBUS_OPERATION               Operation,
    418   IN  BOOLEAN                           PecCheck,
    419   IN  UINTN                             *Length,
    420   IN  VOID                              *Buffer
    421   )
    422 /*++
    423 
    424 Routine Description:
    425 
    426   Save I/O write to boot script
    427 
    428 Arguments:
    429 
    430   TableName - Desired boot script table
    431 
    432   (Standard EFI Smbus execute script parameter)
    433 
    434 Returns:
    435 
    436   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    437 
    438   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    439 
    440 --*/
    441 // GC_TODO:    SlaveAddress - add argument and description to function comment
    442 // GC_TODO:    Command - add argument and description to function comment
    443 // GC_TODO:    Operation - add argument and description to function comment
    444 // GC_TODO:    PecCheck - add argument and description to function comment
    445 // GC_TODO:    Length - add argument and description to function comment
    446 // GC_TODO:    Buffer - add argument and description to function comment
    447 {
    448   if (mBootScriptSave == NULL) {
    449     return EFI_NOT_FOUND;
    450   }
    451 
    452   mBootScriptSave->Write (
    453                     mBootScriptSave,
    454                     TableName,
    455                     EFI_BOOT_SCRIPT_SMBUS_EXECUTE_OPCODE,
    456                     SlaveAddress,
    457                     Command,
    458                     Operation,
    459                     PecCheck,
    460                     Length,
    461                     Buffer
    462                     );
    463 
    464   return EFI_SUCCESS;
    465 }
    466 
    467 EFI_STATUS
    468 EFIAPI
    469 BootScriptSaveStall (
    470   IN  UINT16                            TableName,
    471   IN  UINTN                             Duration
    472   )
    473 /*++
    474 
    475 Routine Description:
    476 
    477   Save I/O write to boot script
    478 
    479 Arguments:
    480 
    481   TableName - Desired boot script table
    482 
    483   (Standard EFI stall script parameter)
    484 
    485 Returns:
    486 
    487   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    488 
    489   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    490 
    491 --*/
    492 // GC_TODO:    Duration - add argument and description to function comment
    493 {
    494   if (mBootScriptSave == NULL) {
    495     return EFI_NOT_FOUND;
    496   }
    497 
    498   mBootScriptSave->Write (
    499                     mBootScriptSave,
    500                     TableName,
    501                     EFI_BOOT_SCRIPT_STALL_OPCODE,
    502                     Duration
    503                     );
    504 
    505   return EFI_SUCCESS;
    506 }
    507 
    508 EFI_STATUS
    509 EFIAPI
    510 BootScriptSaveDispatch (
    511   IN  UINT16                            TableName,
    512   IN  EFI_PHYSICAL_ADDRESS              EntryPoint
    513   )
    514 /*++
    515 
    516 Routine Description:
    517 
    518   GC_TODO: Add function description
    519 
    520 Arguments:
    521 
    522   TableName   - GC_TODO: add argument description
    523   EntryPoint  - GC_TODO: add argument description
    524 
    525 Returns:
    526 
    527   EFI_NOT_FOUND - GC_TODO: Add description for return value
    528   EFI_SUCCESS - GC_TODO: Add description for return value
    529 
    530 --*/
    531 {
    532   if (mBootScriptSave == NULL) {
    533     return EFI_NOT_FOUND;
    534   }
    535 
    536   mBootScriptSave->Write (
    537                     mBootScriptSave,
    538                     TableName,
    539                     EFI_BOOT_SCRIPT_DISPATCH_OPCODE,
    540                     EntryPoint
    541                     );
    542 
    543   return EFI_SUCCESS;
    544 
    545 }
    546 
    547 EFI_STATUS
    548 EFIAPI
    549 BootScriptMemPoll (
    550   IN  UINT16                            TableName,
    551   IN  EFI_BOOT_SCRIPT_WIDTH             Width,
    552   IN  UINT64                            Address,
    553   IN  VOID                              *BitMask,
    554   IN  VOID                              *BitValue,
    555   IN  UINTN                             Duration,
    556   IN  UINTN                             LoopTimes
    557   )
    558 /*++
    559 
    560 Routine Description:
    561 
    562   Save I/O write to boot script
    563 
    564 Arguments:
    565   TableName - Desired boot script table
    566 
    567   Width     - The width of the memory operations.
    568 
    569   Address   - The base address of the memory operations.
    570 
    571   BitMask   - A pointer to the bit mask to be AND-ed with the data read from the register.
    572 
    573   BitValue  - A pointer to the data value after to be Masked.
    574 
    575   Duration  - Duration in microseconds of the stall.
    576 
    577   LoopTimes - The times of the register polling.
    578 
    579 Returns:
    580 
    581   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    582 
    583   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    584 
    585 --*/
    586 {
    587   mBootScriptSave->Write (
    588                     mBootScriptSave,
    589                     TableName,
    590                     EFI_BOOT_SCRIPT_MEM_POLL_OPCODE,
    591                     Width,
    592                     Address,
    593                     BitMask,
    594                     BitValue,
    595                     Duration,
    596                     LoopTimes
    597                     );
    598 
    599   return EFI_SUCCESS;
    600 }
    601 
    602 EFI_STATUS
    603 EFIAPI
    604 BootScriptSaveInformation (
    605   IN  UINT16                                 TableName,
    606   IN  UINT32                                 Length,
    607   IN  EFI_PHYSICAL_ADDRESS                   Buffer
    608   )
    609 /*++
    610 
    611 Routine Description:
    612 
    613   Save a Information Opcode record in table specified with TableName
    614 
    615 Arguments:
    616 
    617   TableName   - Desired boot script table
    618   Length         - Length of information in bytes
    619   Buffer          - Content of information that will be saved in script table
    620 
    621 Returns:
    622 
    623   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    624 
    625   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    626 
    627 --*/
    628 {
    629   if (mBootScriptSave == NULL) {
    630     return EFI_NOT_FOUND;
    631   }
    632 
    633   mBootScriptSave->Write (
    634                     mBootScriptSave,
    635                     TableName,
    636                     EFI_BOOT_SCRIPT_INFORMATION_OPCODE,
    637                     Length,
    638                     Buffer
    639                     );
    640 
    641   return EFI_SUCCESS;
    642 
    643 }
    644 
    645 EFI_STATUS
    646 EFIAPI
    647 BootScriptSaveInformationUnicodeString (
    648   IN        UINT16              TableName,
    649   IN        CHAR16              *String
    650   )
    651 /*++
    652 
    653 Routine Description:
    654 
    655   Save a Information Opcode record in table specified with TableName, the information
    656   is a unicode string.
    657 
    658 Arguments:
    659 
    660   TableName   - Desired boot script table
    661   String          - The string that will be saved in script table
    662 
    663 Returns:
    664 
    665   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    666 
    667   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    668 
    669 --*/
    670 {
    671   return BootScriptSaveInformation (
    672            TableName,
    673            (UINT32) EfiScriptLibStrLen (String) * 2 + 2,
    674            (EFI_PHYSICAL_ADDRESS) (UINTN) String
    675            );
    676 }
    677 
    678 EFI_STATUS
    679 EFIAPI
    680 BootScriptSaveInformationAsciiString (
    681   IN        UINT16              TableName,
    682   IN        CHAR8               *String
    683   )
    684 /*++
    685 
    686 Routine Description:
    687 
    688   Save a Information Opcode record in table specified with TableName, the information
    689   is a ascii string.
    690 
    691 Arguments:
    692 
    693   TableName   - Desired boot script table
    694   String          - The string that will be saved in script table
    695 
    696 Returns:
    697 
    698   EFI_NOT_FOUND - BootScriptSave Protocol not exist.
    699 
    700   EFI_STATUS - BootScriptSave Protocol exist, always returns EFI_SUCCESS
    701 
    702 --*/
    703 {
    704   return BootScriptSaveInformation (
    705            TableName,
    706            (UINT32) EfiScriptLibAsciiStrLen (String) + 1,
    707            (EFI_PHYSICAL_ADDRESS) (UINTN) String
    708            );
    709 }
    710 
    711