summaryrefslogtreecommitdiff
path: root/EDK/Foundation/Efi/Include/EfiApi.h
blob: 828950c5beb6378d04ea396cc82752e6ee3821ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
/*++

Copyright (c) 2004 - 2007, 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:

  EfiApi.h

Abstract:

  EFI intrinsic definitions. This includes all EFI 1.0 boot and runtime
  services APIs.

  Drivers and applications are passed in a pointer to the EFI system table.
  The EFI system table contains pointers to the boot and runtime services
  tables.

--*/

#ifndef _EFI_API_H_
#define _EFI_API_H_

#include EFI_PROTOCOL_DEFINITION (DevicePath)
#include EFI_PROTOCOL_DEFINITION (SimpleTextIn)
#include EFI_PROTOCOL_DEFINITION (SimpleTextOut)

#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
#include "EfiCapsule.h"
#else
#include "EfiStatusCode.h"
#endif

//
// Declare forward referenced data structures
//
EFI_FORWARD_DECLARATION (EFI_SYSTEM_TABLE);

//
// EFI Memory
//
typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_ALLOCATE_PAGES) (
  IN EFI_ALLOCATE_TYPE            Type,
  IN EFI_MEMORY_TYPE              MemoryType,
  IN UINTN                        NoPages,
  OUT EFI_PHYSICAL_ADDRESS        * Memory
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_FREE_PAGES) (
  IN EFI_PHYSICAL_ADDRESS         Memory,
  IN UINTN                        NoPages
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_GET_MEMORY_MAP) (
  IN OUT UINTN                    *MemoryMapSize,
  IN OUT EFI_MEMORY_DESCRIPTOR    * MemoryMap,
  OUT UINTN                       *MapKey,
  OUT UINTN                       *DescriptorSize,
  OUT UINT32                      *DescriptorVersion
  );

#define NextMemoryDescriptor(_Ptr, _Size)   ((EFI_MEMORY_DESCRIPTOR *) (((UINT8 *) (_Ptr)) + (_Size)))
#define NEXT_MEMORY_DESCRIPTOR(_Ptr, _Size) NextMemoryDescriptor (_Ptr, _Size)

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_ALLOCATE_POOL) (
  IN EFI_MEMORY_TYPE              PoolType,
  IN UINTN                        Size,
  OUT VOID                        **Buffer
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_FREE_POOL) (
  IN VOID                         *Buffer
  );

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP) (
  IN UINTN                        MemoryMapSize,
  IN UINTN                        DescriptorSize,
  IN UINT32                       DescriptorVersion,
  IN EFI_MEMORY_DESCRIPTOR        * VirtualMap
  );

typedef
EFI_BOOTSERVICE11
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
  );

typedef
EFI_BOOTSERVICE11
EFI_STATUS
(EFIAPI *EFI_DISCONNECT_CONTROLLER) (
  IN EFI_HANDLE                              ControllerHandle,
  IN EFI_HANDLE                              DriverImageHandle, OPTIONAL
  IN EFI_HANDLE                              ChildHandle        OPTIONAL
  );

//
// ConvertPointer DebugDisposition type.
//
#define EFI_OPTIONAL_POINTER  0x00000001

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_CONVERT_POINTER) (
  IN UINTN                        DebugDisposition,
  IN OUT VOID                     **Address
  );

//
// EFI Event Types
//
#define EFI_EVENT_TIMER                         0x80000000
#define EFI_EVENT_RUNTIME                       0x40000000
#define EFI_EVENT_RUNTIME_CONTEXT               0x20000000

#define EFI_EVENT_NOTIFY_WAIT                   0x00000100
#define EFI_EVENT_NOTIFY_SIGNAL                 0x00000200

#define EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES     0x00000201
#define EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202

#define EFI_EVENT_EFI_SIGNAL_MASK               0x000000FF
#define EFI_EVENT_EFI_SIGNAL_MAX                4

typedef
VOID
(EFIAPI *EFI_EVENT_NOTIFY) (
  IN EFI_EVENT                Event,
  IN VOID                     *Context
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_CREATE_EVENT) (
  IN UINT32                       Type,
  IN EFI_TPL                      NotifyTpl,
  IN EFI_EVENT_NOTIFY             NotifyFunction,
  IN VOID                         *NotifyContext,
  OUT EFI_EVENT                   * Event
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_CREATE_EVENT_EX) (
  IN UINT32                 Type,
  IN EFI_TPL                NotifyTpl      OPTIONAL,
  IN EFI_EVENT_NOTIFY       NotifyFunction OPTIONAL,
  IN CONST VOID             *NotifyContext OPTIONAL,
  IN CONST EFI_GUID         *EventGroup    OPTIONAL,
  OUT EFI_EVENT             *Event
  );

typedef enum {
  TimerCancel,
  TimerPeriodic,
  TimerRelative,
  TimerTypeMax
} EFI_TIMER_DELAY;

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_SET_TIMER) (
  IN EFI_EVENT                Event,
  IN EFI_TIMER_DELAY          Type,
  IN UINT64                   TriggerTime
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_SIGNAL_EVENT) (
  IN EFI_EVENT                Event
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_WAIT_FOR_EVENT) (
  IN UINTN                    NumberOfEvents,
  IN EFI_EVENT                * Event,
  OUT UINTN                   *Index
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_CLOSE_EVENT) (
  IN EFI_EVENT                Event
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_CHECK_EVENT) (
  IN EFI_EVENT                Event
  );

//
// Task priority level
//
#define EFI_TPL_APPLICATION 4
#define EFI_TPL_CALLBACK    8
#define EFI_TPL_NOTIFY      16
#define EFI_TPL_HIGH_LEVEL  31

typedef
EFI_BOOTSERVICE
EFI_TPL
(EFIAPI *EFI_RAISE_TPL) (
  IN EFI_TPL      NewTpl
  );

typedef
EFI_BOOTSERVICE
VOID
(EFIAPI *EFI_RESTORE_TPL) (
  IN EFI_TPL      OldTpl
  );

//
// Variable attributes
//
#define EFI_VARIABLE_NON_VOLATILE       0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS     0x00000004

#if (EFI_SPECIFICATION_VERSION >= 0x0002000A)
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008
#endif

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_GET_VARIABLE) (
  IN CHAR16                       *VariableName,
  IN EFI_GUID                     * VendorGuid,
  OUT UINT32                      *Attributes OPTIONAL,
  IN OUT UINTN                    *DataSize,
  OUT VOID                        *Data
  );

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_GET_NEXT_VARIABLE_NAME) (
  IN OUT UINTN                    *VariableNameSize,
  IN OUT CHAR16                   *VariableName,
  IN OUT EFI_GUID                 * VendorGuid
  );

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_SET_VARIABLE) (
  IN CHAR16                       *VariableName,
  IN EFI_GUID                     * VendorGuid,
  IN UINT32                       Attributes,
  IN UINTN                        DataSize,
  IN VOID                         *Data
  );

//
// EFI Time
//
typedef struct {
  UINT32  Resolution;
  UINT32  Accuracy;
  BOOLEAN SetsToZero;
} EFI_TIME_CAPABILITIES;

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_GET_TIME) (
  OUT EFI_TIME                    * Time,
  OUT EFI_TIME_CAPABILITIES       * Capabilities OPTIONAL
  );

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_SET_TIME) (
  IN EFI_TIME                     * Time
  );

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_GET_WAKEUP_TIME) (
  OUT BOOLEAN                     *Enabled,
  OUT BOOLEAN                     *Pending,
  OUT EFI_TIME                    * Time
  );

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_SET_WAKEUP_TIME) (
  IN BOOLEAN                      Enable,
  IN EFI_TIME                     * Time OPTIONAL
  );

//
// Image Entry prototype
//
typedef
EFI_STATUS
(EFIAPI *EFI_IMAGE_ENTRY_POINT) (
  IN EFI_HANDLE                   ImageHandle,
  IN EFI_SYSTEM_TABLE             * SystemTable
  );

//
// Image functions
//
typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_IMAGE_LOAD) (
  IN BOOLEAN                      BootPolicy,
  IN EFI_HANDLE                   ParentImageHandle,
  IN EFI_DEVICE_PATH_PROTOCOL     * FilePath,
  IN VOID                         *SourceBuffer OPTIONAL,
  IN UINTN                        SourceSize,
  OUT EFI_HANDLE                  * ImageHandle
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_IMAGE_START) (
  IN EFI_HANDLE                   ImageHandle,
  OUT UINTN                       *ExitDataSize,
  OUT CHAR16                      **ExitData OPTIONAL
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_EXIT) (
  IN EFI_HANDLE                   ImageHandle,
  IN EFI_STATUS                   ExitStatus,
  IN UINTN                        ExitDataSize,
  IN CHAR16                       *ExitData OPTIONAL
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_IMAGE_UNLOAD) (
  IN EFI_HANDLE                   ImageHandle
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_EXIT_BOOT_SERVICES) (
  IN EFI_HANDLE                   ImageHandle,
  IN UINTN                        MapKey
  );

//
// Misc
//
typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_STALL) (
  IN UINTN                    Microseconds
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_SET_WATCHDOG_TIMER) (
  IN UINTN                    Timeout,
  IN UINT64                   WatchdogCode,
  IN UINTN                    DataSize,
  IN CHAR16                   *WatchdogData OPTIONAL
  );

typedef enum {
  EfiResetCold,
  EfiResetWarm,
  EfiResetShutdown,

#if ((TIANO_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))
  EfiResetUpdate
#endif

} EFI_RESET_TYPE;

typedef
EFI_RUNTIMESERVICE
VOID
(EFIAPI *EFI_RESET_SYSTEM) (
  IN EFI_RESET_TYPE           ResetType,
  IN EFI_STATUS               ResetStatus,
  IN UINTN                    DataSize,
  IN CHAR16                   *ResetData OPTIONAL
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT) (
  OUT UINT64                  *Count
  );

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT) (
  OUT UINT32                  *HighCount
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_CALCULATE_CRC32) (
  IN  VOID                              *Data,
  IN  UINTN                             DataSize,
  OUT UINT32                            *Crc32
  );

typedef
EFI_BOOTSERVICE
VOID
(EFIAPI *EFI_COPY_MEM) (
  IN VOID     *Destination,
  IN VOID     *Source,
  IN UINTN    Length
  );

typedef
EFI_BOOTSERVICE
VOID
(EFIAPI *EFI_SET_MEM) (
  IN VOID     *Buffer,
  IN UINTN    Size,
  IN UINT8    Value
  );

//
// Protocol handler functions
//
typedef enum {
  EFI_NATIVE_INTERFACE
} EFI_INTERFACE_TYPE;

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_INSTALL_PROTOCOL_INTERFACE) (
  IN OUT EFI_HANDLE           * Handle,
  IN EFI_GUID                 * Protocol,
  IN EFI_INTERFACE_TYPE       InterfaceType,
  IN VOID                     *Interface
  );

typedef
EFI_BOOTSERVICE11
EFI_STATUS
(EFIAPI *EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) (
  IN OUT EFI_HANDLE           * Handle,
  ...
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_REINSTALL_PROTOCOL_INTERFACE) (
  IN EFI_HANDLE               Handle,
  IN EFI_GUID                 * Protocol,
  IN VOID                     *OldInterface,
  IN VOID                     *NewInterface
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_UNINSTALL_PROTOCOL_INTERFACE) (
  IN EFI_HANDLE               Handle,
  IN EFI_GUID                 * Protocol,
  IN VOID                     *Interface
  );

typedef
EFI_BOOTSERVICE11
EFI_STATUS
(EFIAPI *EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) (
  IN EFI_HANDLE           Handle,
  ...
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_HANDLE_PROTOCOL) (
  IN EFI_HANDLE               Handle,
  IN EFI_GUID                 * Protocol,
  OUT VOID                    **Interface
  );

#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL  0x00000001
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL        0x00000002
#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL       0x00000004
#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
#define EFI_OPEN_PROTOCOL_BY_DRIVER           0x00000010
#define EFI_OPEN_PROTOCOL_EXCLUSIVE           0x00000020

//
// ///////////////////////////////////////////////////////////////////////////////////////////////
// OpenProtocol() Attribute Values
/////////////////////////////////////////////////////////////////////////////////////////////////
// BY_HANDLE_PROTOCOL    - Used by EFI 1.0 Drivers and Applications
//                         May not actually add an elemnt to the open list in a production build
//
// GET_PROTOCOL          - Used by EFI 1.1 Drivers to get a protocol interface
//                         May not actually add an elemnt to the open list in a production build
//
// TEST_PROTOCOL         - Used by EFI 1.1 Drivers to test for the existence of a protocol interface
//                         The interface is not returned, and it is an optional parameter tham may be NULL.
//                         May not actually add an elemnt to the open list in a production build
//
// BY_DRIVER             - Used by EFI 1.1 Drivers that are able to share a protocol with other
//                         agents other than its children.  A driver is always able to share
//                         a protocol with its children, since the driver is in control of the
//                         parent controller's and the child controller's use of the protocol.
//
// BY_DRIVER | EXCLUSIVE - Used by EFI 1.1 Drivers that will not share a protocol with any other
//                         agents except its children.  A driver is always able to share
//                         a protocol with its children, since the driver is in control of the
//                         parent controller's and the child controller's use of the protocol.
//                         This attribute will force all other drivers to disconnect from the protocol
//                         before this driver attaches.  When this driver closes the handle, the other
//                         drivers will reconnect to the protocol.
//
//
// BY_CHILD_CONTROLLER   - Used by EFI 1.1 Driver to show that a protocol is consumed by a child
//                         of the driver.  This is information used by DisconnectController() to
//                         determine the list of children that a protocol has.  It has
//                         no affect on the OpenProtocol()/ClosePrototocol() behavior.
//
// EXCLUSIVE             - Used by EFI 1.1 Applications to gain exclusive access to a protocol.
//                         All drivers are disconnected from the handle while the application has
//                         the handle open.  These drivers are reconnected when the application
//                         closes the handle.
//
/////////////////////////////////////////////////////////////////////////////////////////////////
// OpenProtocol() behavior based on Attribute values
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// OpenProtocol (Handle, Protocol, Interface, ImageHandle, DeviceHandle, Attributes)
// * EFI_UNSUPPORTED        if Protocol does not exist on Handle
// * EFI_INVALID_PARAMETER  if Handle is not a valid handle.
// * EFI_INVALID_PARAMETER  if Protocol is NULL or not a valid GUID
// * EFI_INVALID_PARAMETER  if Interface is NULL
// * EFI_INVALID_PARAMETER  if Attributes is not one of the following values:
//                            BY_HANDLE_PROTOCOL
//                            GET_PROTOCOL
//                            TEST_PROTOCOL
//                            BY_CHILD_CONTROLLER
//                            BY_DRIVER
//                            BY_DRIVER | EXCLUSIVE
//                            EXCLUSIVE
// * EFI_INVALID_PARAMETER  if Attributes BY_CHILD_CONTROLLER and ImageHandle is not a valid handle
// * EFI_INVALID_PARAMETER  if Attributes BY_CHILD_CONTROLLER and DeviceHandle is not a valid handle
// * EFI_INVALID_PARAMETER  if Attributes BY_CHILD_CONTROLLER and Handle == DeviceHandle
// * EFI_INVALID_PARAMETER  if Attributes BY_DRIVER and ImageHandle is not a valid handle
// * EFI_INVALID_PARAMETER  if Attributes BY_DRIVER and DeviceHandle is not a valid handle
// * EFI_INVALID_PARAMETER  if Attributes BY_DRIVER | EXCLUSIVE and ImageHandle is not a valid handle
// * EFI_INVALID_PARAMETER  if Attributes BY_DRIVER | EXCLUSIVE and DeviceHandle is not a valid handle
// * EFI_INVALID_PARAMETER  if Attributes EXCLUSIVE and ImageHandle is not a valid handle
//
// OpenProtocol() Attributes = BY_HANDLE_PROTOCOL, GET_PROTOCOL, TEST_PROTOCOL, BY_CHILD_CONTROLLER
// * EFI_SUCCESS      if Protocol exists on the Handle
//
// OpenProtocol() Attributes = BY_DRIVER
// * EFI_SUCCESS        if there are no items in the Open List for (Handle, Protocol)
// * EFI_SUCCESS        if there are only items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_HANDLE_PROTOCOL
//                        GET_PROTOCOL
//                        TEST_PROTOCOL
//                        BY_CHILD_CONTROLLER
// * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_DRIVER
//                      AND ImageHandle != OpenListItem.IH
// * EFI_ALREADY_STARTED if there are any items in the Open List for (Handle, Protocol)
//                       that have the one of the following Attributes
//                         BY_DRIVER
//                       AND ImageHandle == OpenListItem.IH
// * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_DRIVER | EXCLUSIVE
//                        EXCLUSIVE
//
// OpenProtocol() Attributes = BY_DRIVER | EXCLUSIVE
// * EFI_SUCCESS        if there are no items in the Open List for (Handle, Protocol)
// * EFI_SUCCESS        if there are only items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_HANDLE_PROTOCOL
//                        GET_PROTOCOL
//                        TEST_PROTOCOL
//                        BY_CHILD_CONTROLLER
// * EFI_SUCCESS        if there are any items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_DRIVER
//                      AND the driver is removed by DisconnectController(IH,DH)
// * EFI_ALREADY_STARTED if there are any items in the Open List for (Handle, Protocol)
//                       that have the one of the following Attributes
//                         BY_DRIVER | EXCLUSIVE
//                       AND ImageHandle == OpenListItem.IH
// * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_DRIVER
//                      AND the driver can not be removed by DisconnectController(IH,DH)
// * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_DRIVER | EXCLUSIVE
//                        EXCLUSIVE
//
// OpenProtocol() Attributes = EXCLUSIVE
// * EFI_SUCCESS        if there are no items in the Open List for (Handle, Protocol)
// * EFI_SUCCESS        if there are only items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_HANDLE_PROTOCOL
//                        GET_PROTOCOL
//                        TEST_PROTOCOL
//                        BY_CHILD_CONTROLLER
// * EFI_SUCCESS        if there are any items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_DRIVER
//                      AND the driver is removed by DisconnectController(IH,DH)
// * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_DRIVER
//                      AND the driver can not be removed by DisconnectController(IH,DH)
// * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
//                      that have the one of the following Attributes
//                        BY_DRIVER | EXCLUSIVE
//                        EXCLUSIVE
//
/////////////////////////////////////////////////////////////////////////////////////////////////
// CloseProtocol() Behavior based on the Attributes of the item being closed and the items
//                 remaining on the Open List
/////////////////////////////////////////////////////////////////////////////////////////////////
// CloseProtocol(Handle, Protocol, ImageHandle, DeviceHandle)
// CloseProtocol() Attributes of item = BY_HANDLE_PROTOCOL,
//                                      GET_PROTOCOL
//                                      TEST_PROTOCOL
//                                      BY_CHILD_CONTROLLER,
//                                      BY_DRIVER
//                                      BY_DRIVER | EXCLUSIVE
//                                      EXCLUSIVE
//   EFI_NOT_FOUND          if Protocol does not exist on Handle
//   EFI_INVALID_PARAMETER  if Handle is not a valid handle.
//   EFI_INVALID_PARAMETER  if Protocol is NULL or not a valid GUID
//   EFI_INVALID_PARAMETER  if ImageHandle is not a valid handle
//   EFI_INVALID_PARAMETER  if DeviceHandle is not a valid handle
//   EFI_NOT_FOUND      if (ImageHandle, DeviceHandle) is not present in the Open List
//                      for (Handle, Protocol)
//   EFI_ACCESS_DENIED  if (ImageHandle, DeviceHandle) is present in the Open List
//                      for (Handle, Protocol), but the item can not be removed.
//   EFI_SUCCESS        if (ImageHandle, DeviceHandle) is present in the Open List
//                      for (Handle, Protocol), and the item can be removed.
//
/////////////////////////////////////////////////////////////////////////////////////////////////
// UninstallProtocolInterface() behavior
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// UninstallProtocolInterface (Handle, Protocol, Interface)
//
//   EFI_INVALID_PARAMETER if Handle is not a valid handle.
//   EFI_INVALID_PARAMETER if Protocol is not a vlaid GUID
//   EFI_NOT_FOUND         if Handle doe not support Protocol
//   EFI_NOT_FOUND         if the interface for (Handle, Protocol) does not match Interface
//   EFI_ACCESS_DENIED     if the list of Open Items for (Handle, Protocol) can not be removed
//   EFI_SUCCESS           if the list of Open Items is empty, and Protocol is removed from Handle
//
// Algorithm to remove Open Item List:
//
// Loop through all Open Item List entries
//   if (OpenItem.Attributes & BY_DRIVER) then
//     DisconnectController (OpenItem.IH, OpenItem.DH)
//   end if
// end loop
// Loop through all Open Item List entries
//   if (OpenItem.Attributes & BY_HANDLE_PROTOCOL or GET_PROTOCOL or TEST_PROTOCOL) then
//     CloseProtocol (Handle, Protocol, OpenItem.IH, OpenItem.DH)
//   end if
// end loop
// if Open Item List is empty then remove Protocol from Handle and return EFI_SUCCESS
// if Open Item List is not empty then return EFI_ACCESS_DENIED
//
/////////////////////////////////////////////////////////////////////////////////////////////////
typedef
EFI_BOOTSERVICE11
EFI_STATUS
(EFIAPI *EFI_OPEN_PROTOCOL) (
  IN EFI_HANDLE                 Handle,
  IN EFI_GUID                   * Protocol,
  OUT VOID                      **Interface,
  IN  EFI_HANDLE                ImageHandle,
  IN  EFI_HANDLE                ControllerHandle, OPTIONAL
  IN  UINT32                    Attributes
  );

typedef
EFI_BOOTSERVICE11
EFI_STATUS
(EFIAPI *EFI_CLOSE_PROTOCOL) (
  IN EFI_HANDLE               Handle,
  IN EFI_GUID                 * Protocol,
  IN EFI_HANDLE               ImageHandle,
  IN EFI_HANDLE               DeviceHandle
  );

typedef struct {
  EFI_HANDLE  AgentHandle;
  EFI_HANDLE  ControllerHandle;
  UINT32      Attributes;
  UINT32      OpenCount;
} EFI_OPEN_PROTOCOL_INFORMATION_ENTRY;

typedef
EFI_BOOTSERVICE11
EFI_STATUS
(EFIAPI *EFI_OPEN_PROTOCOL_INFORMATION) (
  IN  EFI_HANDLE                          UserHandle,
  IN  EFI_GUID                            * Protocol,
  IN  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer,
  OUT UINTN                               *EntryCount
  );

typedef
EFI_BOOTSERVICE11
EFI_STATUS
(EFIAPI *EFI_PROTOCOLS_PER_HANDLE) (
  IN EFI_HANDLE       UserHandle,
  OUT EFI_GUID        ***ProtocolBuffer,
  OUT UINTN           *ProtocolBufferCount
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_REGISTER_PROTOCOL_NOTIFY) (
  IN EFI_GUID                 * Protocol,
  IN EFI_EVENT                Event,
  OUT VOID                    **Registration
  );

typedef enum {
  AllHandles,
  ByRegisterNotify,
  ByProtocol
} EFI_LOCATE_SEARCH_TYPE;

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_LOCATE_HANDLE) (
  IN EFI_LOCATE_SEARCH_TYPE   SearchType,
  IN EFI_GUID                 * Protocol OPTIONAL,
  IN VOID                     *SearchKey OPTIONAL,
  IN OUT UINTN                *BufferSize,
  OUT EFI_HANDLE              * Buffer
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_LOCATE_DEVICE_PATH) (
  IN EFI_GUID                         * Protocol,
  IN OUT EFI_DEVICE_PATH_PROTOCOL     **DevicePath,
  OUT EFI_HANDLE                      * Device
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_INSTALL_CONFIGURATION_TABLE) (
  IN EFI_GUID                 * Guid,
  IN VOID                     *Table
  );

typedef
EFI_BOOTSERVICE
EFI_STATUS
(EFIAPI *EFI_RESERVED_SERVICE) (
  VOID
  );

typedef
EFI_BOOTSERVICE11
EFI_STATUS
(EFIAPI *EFI_LOCATE_HANDLE_BUFFER) (
  IN EFI_LOCATE_SEARCH_TYPE       SearchType,
  IN EFI_GUID                     * Protocol OPTIONAL,
  IN VOID                         *SearchKey OPTIONAL,
  IN OUT UINTN                    *NumberHandles,
  OUT EFI_HANDLE                  **Buffer
  );

typedef
EFI_BOOTSERVICE11
EFI_STATUS
(EFIAPI *EFI_LOCATE_PROTOCOL) (
  EFI_GUID  * Protocol,
  VOID      *Registration, OPTIONAL
  VOID      **Interface
  );

//
// Definition of Status Code extended data header
//
//  HeaderSize    The size of the architecture. This is specified to enable
//                the future expansion
//
//  Size          The size of the data in bytes. This does not include the size
//                of the header structure.
//
//  Type          A GUID defining the type of the data
//
//
#if ((TIANO_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_REPORT_STATUS_CODE) (
  IN EFI_STATUS_CODE_TYPE     Type,
  IN EFI_STATUS_CODE_VALUE    Value,
  IN UINT32                   Instance,
  IN EFI_GUID                 * CallerId OPTIONAL,
  IN EFI_STATUS_CODE_DATA     * Data OPTIONAL
  );

#endif

#if (EFI_SPECIFICATION_VERSION >= 0x00020000)

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_UPDATE_CAPSULE) (
  IN EFI_CAPSULE_HEADER     **CapsuleHeaderArray,
  IN UINTN                  CapsuleCount,
  IN EFI_PHYSICAL_ADDRESS   ScatterGatherList OPTIONAL
 );


typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_QUERY_CAPSULE_CAPABILITIES) (
  IN  EFI_CAPSULE_HEADER   **CapsuleHeaderArray,
  IN  UINTN                CapsuleCount,
  OUT UINT64               *MaxiumCapsuleSize,
  OUT EFI_RESET_TYPE       *ResetType
);

typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_QUERY_VARIABLE_INFO) (
  IN UINT32           Attributes,
  OUT UINT64          *MaximumVariableStorageSize,
  OUT UINT64          *RemainingVariableStorageSize,
  OUT UINT64          *MaximumVariableSize
  );

#endif

//
// EFI Runtime Services Table
//
#define EFI_RUNTIME_SERVICES_SIGNATURE  0x56524553544e5552
#define EFI_RUNTIME_SERVICES_REVISION   EFI_SPECIFICATION_VERSION

typedef struct {
  EFI_TABLE_HEADER              Hdr;

  //
  // Time services
  //
  EFI_GET_TIME                  GetTime;
  EFI_SET_TIME                  SetTime;
  EFI_GET_WAKEUP_TIME           GetWakeupTime;
  EFI_SET_WAKEUP_TIME           SetWakeupTime;

  //
  // Virtual memory services
  //
  EFI_SET_VIRTUAL_ADDRESS_MAP   SetVirtualAddressMap;
  EFI_CONVERT_POINTER           ConvertPointer;

  //
  // Variable services
  //
  EFI_GET_VARIABLE              GetVariable;
  EFI_GET_NEXT_VARIABLE_NAME    GetNextVariableName;
  EFI_SET_VARIABLE              SetVariable;

  //
  // Misc
  //
  EFI_GET_NEXT_HIGH_MONO_COUNT  GetNextHighMonotonicCount;
  EFI_RESET_SYSTEM              ResetSystem;

#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
  //
  // New Boot Service added by UEFI 2.0
  //
  EFI_UPDATE_CAPSULE             UpdateCapsule;
  EFI_QUERY_CAPSULE_CAPABILITIES QueryCapsuleCapabilities;
  EFI_QUERY_VARIABLE_INFO        QueryVariableInfo;
#elif (TIANO_RELEASE_VERSION != 0)
  //
  // Tiano extension to EFI 1.10 runtime table
  // It was moved to a protocol to not conflict with UEFI 2.0
  // If Tiano is disabled, this item is not enabled for EFI1.10
  //
  EFI_REPORT_STATUS_CODE        ReportStatusCode;
#endif

} EFI_RUNTIME_SERVICES;

//
// EFI Boot Services Table
//
#define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42
#define EFI_BOOT_SERVICES_REVISION  EFI_SPECIFICATION_VERSION

typedef struct {
  EFI_TABLE_HEADER                            Hdr;

  //
  // Task priority functions
  //
  EFI_RAISE_TPL                               RaiseTPL;
  EFI_RESTORE_TPL                             RestoreTPL;

  //
  // Memory functions
  //
  EFI_ALLOCATE_PAGES                          AllocatePages;
  EFI_FREE_PAGES                              FreePages;
  EFI_GET_MEMORY_MAP                          GetMemoryMap;
  EFI_ALLOCATE_POOL                           AllocatePool;
  EFI_FREE_POOL                               FreePool;

  //
  // Event & timer functions
  //
  EFI_CREATE_EVENT                            CreateEvent;
  EFI_SET_TIMER                               SetTimer;
  EFI_WAIT_FOR_EVENT                          WaitForEvent;
  EFI_SIGNAL_EVENT                            SignalEvent;
  EFI_CLOSE_EVENT                             CloseEvent;
  EFI_CHECK_EVENT                             CheckEvent;

  //
  // Protocol handler functions
  //
  EFI_INSTALL_PROTOCOL_INTERFACE              InstallProtocolInterface;
  EFI_REINSTALL_PROTOCOL_INTERFACE            ReinstallProtocolInterface;
  EFI_UNINSTALL_PROTOCOL_INTERFACE            UninstallProtocolInterface;
  EFI_HANDLE_PROTOCOL                         HandleProtocol;
  VOID                                        *Reserved;
  EFI_REGISTER_PROTOCOL_NOTIFY                RegisterProtocolNotify;
  EFI_LOCATE_HANDLE                           LocateHandle;
  EFI_LOCATE_DEVICE_PATH                      LocateDevicePath;
  EFI_INSTALL_CONFIGURATION_TABLE             InstallConfigurationTable;

  //
  // Image functions
  //
  EFI_IMAGE_LOAD                              LoadImage;
  EFI_IMAGE_START                             StartImage;
  EFI_EXIT                                    Exit;
  EFI_IMAGE_UNLOAD                            UnloadImage;
  EFI_EXIT_BOOT_SERVICES                      ExitBootServices;

  //
  // Misc functions
  //
  EFI_GET_NEXT_MONOTONIC_COUNT                GetNextMonotonicCount;
  EFI_STALL                                   Stall;
  EFI_SET_WATCHDOG_TIMER                      SetWatchdogTimer;

  //
  // ////////////////////////////////////////////////////
  // EFI 1.1 Services
    //////////////////////////////////////////////////////
  //
  // DriverSupport Services
  //
  EFI_CONNECT_CONTROLLER                      ConnectController;
  EFI_DISCONNECT_CONTROLLER                   DisconnectController;

  //
  // Added Open and Close protocol for the new driver model
  //
  EFI_OPEN_PROTOCOL                           OpenProtocol;
  EFI_CLOSE_PROTOCOL                          CloseProtocol;
  EFI_OPEN_PROTOCOL_INFORMATION               OpenProtocolInformation;

  //
  // Added new services to EFI 1.1 as Lib to reduce code size.
  //
  EFI_PROTOCOLS_PER_HANDLE                    ProtocolsPerHandle;
  EFI_LOCATE_HANDLE_BUFFER                    LocateHandleBuffer;
  EFI_LOCATE_PROTOCOL                         LocateProtocol;

  EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES    InstallMultipleProtocolInterfaces;
  EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES  UninstallMultipleProtocolInterfaces;

  //
  // CRC32 services
  //
  EFI_CALCULATE_CRC32                         CalculateCrc32;

  //
  // Memory Utility Services
  //
  EFI_COPY_MEM                                CopyMem;
  EFI_SET_MEM                                 SetMem;
#if (EFI_SPECIFICATION_VERSION >= 0x00020000)
  //
  // UEFI 2.0 Extension to the table
  //
  EFI_CREATE_EVENT_EX                         CreateEventEx;
#endif

} EFI_BOOT_SERVICES;

//
// EFI Configuration Table
//
typedef struct {
  EFI_GUID  VendorGuid;
  VOID      *VendorTable;
} EFI_CONFIGURATION_TABLE;

//
// EFI System Table
//
#define EFI_SYSTEM_TABLE_SIGNATURE      0x5453595320494249
#define EFI_SYSTEM_TABLE_REVISION       EFI_SPECIFICATION_VERSION
#define EFI_1_02_SYSTEM_TABLE_REVISION  ((1 << 16) | 02)
#define EFI_1_10_SYSTEM_TABLE_REVISION  ((1 << 16) | 10)
#define EFI_2_00_SYSTEM_TABLE_REVISION  ((2 << 16) | 00)
#define EFI_2_10_SYSTEM_TABLE_REVISION  ((2 << 16) | 10)

typedef struct _EFI_SYSTEM_TABLE {
  EFI_TABLE_HEADER              Hdr;

  CHAR16                        *FirmwareVendor;
  UINT32                        FirmwareRevision;

  EFI_HANDLE                    ConsoleInHandle;
  EFI_SIMPLE_TEXT_IN_PROTOCOL   *ConIn;

  EFI_HANDLE                    ConsoleOutHandle;
  EFI_SIMPLE_TEXT_OUT_PROTOCOL  *ConOut;

  EFI_HANDLE                    StandardErrorHandle;
  EFI_SIMPLE_TEXT_OUT_PROTOCOL  *StdErr;

  EFI_RUNTIME_SERVICES          *RuntimeServices;
  EFI_BOOT_SERVICES             *BootServices;

  UINTN                         NumberOfTableEntries;
  EFI_CONFIGURATION_TABLE       *ConfigurationTable;

} EFI_SYSTEM_TABLE;

#endif