1 /*++
2 
3 Copyright (c) 2004 - 2007, 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   EfiApi.h
15 
16 Abstract:
17 
18   EFI intrinsic definitions. This includes all EFI 1.0 boot and runtime
19   services APIs.
20 
21   Drivers and applications are passed in a pointer to the EFI system table.
22   The EFI system table contains pointers to the boot and runtime services
23   tables.
24 
25 --*/
26 
27 #ifndef _EFI_API_H_
28 #define _EFI_API_H_
29 
30 #include EFI_PROTOCOL_DEFINITION (DevicePath)
31 #include EFI_PROTOCOL_DEFINITION (SimpleTextIn)
32 #include EFI_PROTOCOL_DEFINITION (SimpleTextOut)
33 
34 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
35 #include "EfiCapsule.h"
36 #else
37 #include "EfiStatusCode.h"
38 #endif
39 
40 //
41 // Declare forward referenced data structures
42 //
43 EFI_FORWARD_DECLARATION (EFI_SYSTEM_TABLE);
44 
45 //
46 // EFI Memory
47 //
48 typedef
49 EFI_BOOTSERVICE
50 EFI_STATUS
51 (EFIAPI *EFI_ALLOCATE_PAGES) (
52   IN EFI_ALLOCATE_TYPE            Type,
53   IN EFI_MEMORY_TYPE              MemoryType,
54   IN UINTN                        NoPages,
55   OUT EFI_PHYSICAL_ADDRESS        * Memory
56   );
57 
58 typedef
59 EFI_BOOTSERVICE
60 EFI_STATUS
61 (EFIAPI *EFI_FREE_PAGES) (
62   IN EFI_PHYSICAL_ADDRESS         Memory,
63   IN UINTN                        NoPages
64   );
65 
66 typedef
67 EFI_BOOTSERVICE
68 EFI_STATUS
69 (EFIAPI *EFI_GET_MEMORY_MAP) (
70   IN OUT UINTN                    *MemoryMapSize,
71   IN OUT EFI_MEMORY_DESCRIPTOR    * MemoryMap,
72   OUT UINTN                       *MapKey,
73   OUT UINTN                       *DescriptorSize,
74   OUT UINT32                      *DescriptorVersion
75   );
76 
77 #define NextMemoryDescriptor(_Ptr, _Size)   ((EFI_MEMORY_DESCRIPTOR *) (((UINT8 *) (_Ptr)) + (_Size)))
78 #define NEXT_MEMORY_DESCRIPTOR(_Ptr, _Size) NextMemoryDescriptor (_Ptr, _Size)
79 
80 typedef
81 EFI_BOOTSERVICE
82 EFI_STATUS
83 (EFIAPI *EFI_ALLOCATE_POOL) (
84   IN EFI_MEMORY_TYPE              PoolType,
85   IN UINTN                        Size,
86   OUT VOID                        **Buffer
87   );
88 
89 typedef
90 EFI_BOOTSERVICE
91 EFI_STATUS
92 (EFIAPI *EFI_FREE_POOL) (
93   IN VOID                         *Buffer
94   );
95 
96 typedef
97 EFI_RUNTIMESERVICE
98 EFI_STATUS
99 (EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP) (
100   IN UINTN                        MemoryMapSize,
101   IN UINTN                        DescriptorSize,
102   IN UINT32                       DescriptorVersion,
103   IN EFI_MEMORY_DESCRIPTOR        * VirtualMap
104   );
105 
106 typedef
107 EFI_BOOTSERVICE11
108 EFI_STATUS
109 (EFIAPI *EFI_CONNECT_CONTROLLER) (
110   IN  EFI_HANDLE                    ControllerHandle,
111   IN  EFI_HANDLE                    * DriverImageHandle OPTIONAL,
112   IN  EFI_DEVICE_PATH_PROTOCOL      * RemainingDevicePath OPTIONAL,
113   IN  BOOLEAN                       Recursive
114   );
115 
116 typedef
117 EFI_BOOTSERVICE11
118 EFI_STATUS
119 (EFIAPI *EFI_DISCONNECT_CONTROLLER) (
120   IN EFI_HANDLE                              ControllerHandle,
121   IN EFI_HANDLE                              DriverImageHandle, OPTIONAL
122   IN EFI_HANDLE                              ChildHandle        OPTIONAL
123   );
124 
125 //
126 // ConvertPointer DebugDisposition type.
127 //
128 #define EFI_OPTIONAL_POINTER  0x00000001
129 
130 typedef
131 EFI_RUNTIMESERVICE
132 EFI_STATUS
133 (EFIAPI *EFI_CONVERT_POINTER) (
134   IN UINTN                        DebugDisposition,
135   IN OUT VOID                     **Address
136   );
137 
138 //
139 // EFI Event Types
140 //
141 #define EFI_EVENT_TIMER                         0x80000000
142 #define EFI_EVENT_RUNTIME                       0x40000000
143 #define EFI_EVENT_RUNTIME_CONTEXT               0x20000000
144 
145 #define EFI_EVENT_NOTIFY_WAIT                   0x00000100
146 #define EFI_EVENT_NOTIFY_SIGNAL                 0x00000200
147 
148 #define EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES     0x00000201
149 #define EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
150 
151 #define EFI_EVENT_EFI_SIGNAL_MASK               0x000000FF
152 #define EFI_EVENT_EFI_SIGNAL_MAX                4
153 
154 typedef
155 VOID
156 (EFIAPI *EFI_EVENT_NOTIFY) (
157   IN EFI_EVENT                Event,
158   IN VOID                     *Context
159   );
160 
161 typedef
162 EFI_BOOTSERVICE
163 EFI_STATUS
164 (EFIAPI *EFI_CREATE_EVENT) (
165   IN UINT32                       Type,
166   IN EFI_TPL                      NotifyTpl,
167   IN EFI_EVENT_NOTIFY             NotifyFunction,
168   IN VOID                         *NotifyContext,
169   OUT EFI_EVENT                   * Event
170   );
171 
172 typedef
173 EFI_BOOTSERVICE
174 EFI_STATUS
175 (EFIAPI *EFI_CREATE_EVENT_EX) (
176   IN UINT32                 Type,
177   IN EFI_TPL                NotifyTpl      OPTIONAL,
178   IN EFI_EVENT_NOTIFY       NotifyFunction OPTIONAL,
179   IN CONST VOID             *NotifyContext OPTIONAL,
180   IN CONST EFI_GUID         *EventGroup    OPTIONAL,
181   OUT EFI_EVENT             *Event
182   );
183 
184 typedef enum {
185   TimerCancel,
186   TimerPeriodic,
187   TimerRelative,
188   TimerTypeMax
189 } EFI_TIMER_DELAY;
190 
191 typedef
192 EFI_BOOTSERVICE
193 EFI_STATUS
194 (EFIAPI *EFI_SET_TIMER) (
195   IN EFI_EVENT                Event,
196   IN EFI_TIMER_DELAY          Type,
197   IN UINT64                   TriggerTime
198   );
199 
200 typedef
201 EFI_BOOTSERVICE
202 EFI_STATUS
203 (EFIAPI *EFI_SIGNAL_EVENT) (
204   IN EFI_EVENT                Event
205   );
206 
207 typedef
208 EFI_BOOTSERVICE
209 EFI_STATUS
210 (EFIAPI *EFI_WAIT_FOR_EVENT) (
211   IN UINTN                    NumberOfEvents,
212   IN EFI_EVENT                * Event,
213   OUT UINTN                   *Index
214   );
215 
216 typedef
217 EFI_BOOTSERVICE
218 EFI_STATUS
219 (EFIAPI *EFI_CLOSE_EVENT) (
220   IN EFI_EVENT                Event
221   );
222 
223 typedef
224 EFI_BOOTSERVICE
225 EFI_STATUS
226 (EFIAPI *EFI_CHECK_EVENT) (
227   IN EFI_EVENT                Event
228   );
229 
230 //
231 // Task priority level
232 //
233 #define EFI_TPL_APPLICATION 4
234 #define EFI_TPL_CALLBACK    8
235 #define EFI_TPL_NOTIFY      16
236 #define EFI_TPL_HIGH_LEVEL  31
237 
238 typedef
239 EFI_BOOTSERVICE
240 EFI_TPL
241 (EFIAPI *EFI_RAISE_TPL) (
242   IN EFI_TPL      NewTpl
243   );
244 
245 typedef
246 EFI_BOOTSERVICE
247 VOID
248 (EFIAPI *EFI_RESTORE_TPL) (
249   IN EFI_TPL      OldTpl
250   );
251 
252 //
253 // Variable attributes
254 //
255 #define EFI_VARIABLE_NON_VOLATILE       0x00000001
256 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
257 #define EFI_VARIABLE_RUNTIME_ACCESS     0x00000004
258 
259 #if (EFI_SPECIFICATION_VERSION >= 0x0002000A)
260 #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008
261 #endif
262 
263 typedef
264 EFI_RUNTIMESERVICE
265 EFI_STATUS
266 (EFIAPI *EFI_GET_VARIABLE) (
267   IN CHAR16                       *VariableName,
268   IN EFI_GUID                     * VendorGuid,
269   OUT UINT32                      *Attributes OPTIONAL,
270   IN OUT UINTN                    *DataSize,
271   OUT VOID                        *Data
272   );
273 
274 typedef
275 EFI_RUNTIMESERVICE
276 EFI_STATUS
277 (EFIAPI *EFI_GET_NEXT_VARIABLE_NAME) (
278   IN OUT UINTN                    *VariableNameSize,
279   IN OUT CHAR16                   *VariableName,
280   IN OUT EFI_GUID                 * VendorGuid
281   );
282 
283 typedef
284 EFI_RUNTIMESERVICE
285 EFI_STATUS
286 (EFIAPI *EFI_SET_VARIABLE) (
287   IN CHAR16                       *VariableName,
288   IN EFI_GUID                     * VendorGuid,
289   IN UINT32                       Attributes,
290   IN UINTN                        DataSize,
291   IN VOID                         *Data
292   );
293 
294 //
295 // EFI Time
296 //
297 typedef struct {
298   UINT32  Resolution;
299   UINT32  Accuracy;
300   BOOLEAN SetsToZero;
301 } EFI_TIME_CAPABILITIES;
302 
303 typedef
304 EFI_RUNTIMESERVICE
305 EFI_STATUS
306 (EFIAPI *EFI_GET_TIME) (
307   OUT EFI_TIME                    * Time,
308   OUT EFI_TIME_CAPABILITIES       * Capabilities OPTIONAL
309   );
310 
311 typedef
312 EFI_RUNTIMESERVICE
313 EFI_STATUS
314 (EFIAPI *EFI_SET_TIME) (
315   IN EFI_TIME                     * Time
316   );
317 
318 typedef
319 EFI_RUNTIMESERVICE
320 EFI_STATUS
321 (EFIAPI *EFI_GET_WAKEUP_TIME) (
322   OUT BOOLEAN                     *Enabled,
323   OUT BOOLEAN                     *Pending,
324   OUT EFI_TIME                    * Time
325   );
326 
327 typedef
328 EFI_RUNTIMESERVICE
329 EFI_STATUS
330 (EFIAPI *EFI_SET_WAKEUP_TIME) (
331   IN BOOLEAN                      Enable,
332   IN EFI_TIME                     * Time OPTIONAL
333   );
334 
335 //
336 // Image Entry prototype
337 //
338 typedef
339 EFI_STATUS
340 (EFIAPI *EFI_IMAGE_ENTRY_POINT) (
341   IN EFI_HANDLE                   ImageHandle,
342   IN EFI_SYSTEM_TABLE             * SystemTable
343   );
344 
345 //
346 // Image functions
347 //
348 typedef
349 EFI_BOOTSERVICE
350 EFI_STATUS
351 (EFIAPI *EFI_IMAGE_LOAD) (
352   IN BOOLEAN                      BootPolicy,
353   IN EFI_HANDLE                   ParentImageHandle,
354   IN EFI_DEVICE_PATH_PROTOCOL     * FilePath,
355   IN VOID                         *SourceBuffer OPTIONAL,
356   IN UINTN                        SourceSize,
357   OUT EFI_HANDLE                  * ImageHandle
358   );
359 
360 typedef
361 EFI_BOOTSERVICE
362 EFI_STATUS
363 (EFIAPI *EFI_IMAGE_START) (
364   IN EFI_HANDLE                   ImageHandle,
365   OUT UINTN                       *ExitDataSize,
366   OUT CHAR16                      **ExitData OPTIONAL
367   );
368 
369 typedef
370 EFI_BOOTSERVICE
371 EFI_STATUS
372 (EFIAPI *EFI_EXIT) (
373   IN EFI_HANDLE                   ImageHandle,
374   IN EFI_STATUS                   ExitStatus,
375   IN UINTN                        ExitDataSize,
376   IN CHAR16                       *ExitData OPTIONAL
377   );
378 
379 typedef
380 EFI_BOOTSERVICE
381 EFI_STATUS
382 (EFIAPI *EFI_IMAGE_UNLOAD) (
383   IN EFI_HANDLE                   ImageHandle
384   );
385 
386 typedef
387 EFI_BOOTSERVICE
388 EFI_STATUS
389 (EFIAPI *EFI_EXIT_BOOT_SERVICES) (
390   IN EFI_HANDLE                   ImageHandle,
391   IN UINTN                        MapKey
392   );
393 
394 //
395 // Misc
396 //
397 typedef
398 EFI_BOOTSERVICE
399 EFI_STATUS
400 (EFIAPI *EFI_STALL) (
401   IN UINTN                    Microseconds
402   );
403 
404 typedef
405 EFI_BOOTSERVICE
406 EFI_STATUS
407 (EFIAPI *EFI_SET_WATCHDOG_TIMER) (
408   IN UINTN                    Timeout,
409   IN UINT64                   WatchdogCode,
410   IN UINTN                    DataSize,
411   IN CHAR16                   *WatchdogData OPTIONAL
412   );
413 
414 typedef enum {
415   EfiResetCold,
416   EfiResetWarm,
417   EfiResetShutdown
418 
419 #if ((TIANO_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))
420   , EfiResetUpdate
421 #endif
422 
423 } EFI_RESET_TYPE;
424 
425 typedef
426 EFI_RUNTIMESERVICE
427 VOID
428 (EFIAPI *EFI_RESET_SYSTEM) (
429   IN EFI_RESET_TYPE           ResetType,
430   IN EFI_STATUS               ResetStatus,
431   IN UINTN                    DataSize,
432   IN CHAR16                   *ResetData OPTIONAL
433   );
434 
435 typedef
436 EFI_BOOTSERVICE
437 EFI_STATUS
438 (EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT) (
439   OUT UINT64                  *Count
440   );
441 
442 typedef
443 EFI_RUNTIMESERVICE
444 EFI_STATUS
445 (EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT) (
446   OUT UINT32                  *HighCount
447   );
448 
449 typedef
450 EFI_BOOTSERVICE
451 EFI_STATUS
452 (EFIAPI *EFI_CALCULATE_CRC32) (
453   IN  VOID                              *Data,
454   IN  UINTN                             DataSize,
455   OUT UINT32                            *Crc32
456   );
457 
458 typedef
459 EFI_BOOTSERVICE
460 VOID
461 (EFIAPI *EFI_COPY_MEM) (
462   IN VOID     *Destination,
463   IN VOID     *Source,
464   IN UINTN    Length
465   );
466 
467 typedef
468 EFI_BOOTSERVICE
469 VOID
470 (EFIAPI *EFI_SET_MEM) (
471   IN VOID     *Buffer,
472   IN UINTN    Size,
473   IN UINT8    Value
474   );
475 
476 //
477 // Protocol handler functions
478 //
479 typedef enum {
480   EFI_NATIVE_INTERFACE
481 } EFI_INTERFACE_TYPE;
482 
483 typedef
484 EFI_BOOTSERVICE
485 EFI_STATUS
486 (EFIAPI *EFI_INSTALL_PROTOCOL_INTERFACE) (
487   IN OUT EFI_HANDLE           * Handle,
488   IN EFI_GUID                 * Protocol,
489   IN EFI_INTERFACE_TYPE       InterfaceType,
490   IN VOID                     *Interface
491   );
492 
493 typedef
494 EFI_BOOTSERVICE11
495 EFI_STATUS
496 (EFIAPI *EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) (
497   IN OUT EFI_HANDLE           * Handle,
498   ...
499   );
500 
501 typedef
502 EFI_BOOTSERVICE
503 EFI_STATUS
504 (EFIAPI *EFI_REINSTALL_PROTOCOL_INTERFACE) (
505   IN EFI_HANDLE               Handle,
506   IN EFI_GUID                 * Protocol,
507   IN VOID                     *OldInterface,
508   IN VOID                     *NewInterface
509   );
510 
511 typedef
512 EFI_BOOTSERVICE
513 EFI_STATUS
514 (EFIAPI *EFI_UNINSTALL_PROTOCOL_INTERFACE) (
515   IN EFI_HANDLE               Handle,
516   IN EFI_GUID                 * Protocol,
517   IN VOID                     *Interface
518   );
519 
520 typedef
521 EFI_BOOTSERVICE11
522 EFI_STATUS
523 (EFIAPI *EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) (
524   IN EFI_HANDLE           Handle,
525   ...
526   );
527 
528 typedef
529 EFI_BOOTSERVICE
530 EFI_STATUS
531 (EFIAPI *EFI_HANDLE_PROTOCOL) (
532   IN EFI_HANDLE               Handle,
533   IN EFI_GUID                 * Protocol,
534   OUT VOID                    **Interface
535   );
536 
537 #define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL  0x00000001
538 #define EFI_OPEN_PROTOCOL_GET_PROTOCOL        0x00000002
539 #define EFI_OPEN_PROTOCOL_TEST_PROTOCOL       0x00000004
540 #define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
541 #define EFI_OPEN_PROTOCOL_BY_DRIVER           0x00000010
542 #define EFI_OPEN_PROTOCOL_EXCLUSIVE           0x00000020
543 
544 //
545 // ///////////////////////////////////////////////////////////////////////////////////////////////
546 // OpenProtocol() Attribute Values
547 /////////////////////////////////////////////////////////////////////////////////////////////////
548 // BY_HANDLE_PROTOCOL    - Used by EFI 1.0 Drivers and Applications
549 //                         May not actually add an elemnt to the open list in a production build
550 //
551 // GET_PROTOCOL          - Used by EFI 1.1 Drivers to get a protocol interface
552 //                         May not actually add an elemnt to the open list in a production build
553 //
554 // TEST_PROTOCOL         - Used by EFI 1.1 Drivers to test for the existence of a protocol interface
555 //                         The interface is not returned, and it is an optional parameter tham may be NULL.
556 //                         May not actually add an elemnt to the open list in a production build
557 //
558 // BY_DRIVER             - Used by EFI 1.1 Drivers that are able to share a protocol with other
559 //                         agents other than its children.  A driver is always able to share
560 //                         a protocol with its children, since the driver is in control of the
561 //                         parent controller's and the child controller's use of the protocol.
562 //
563 // BY_DRIVER | EXCLUSIVE - Used by EFI 1.1 Drivers that will not share a protocol with any other
564 //                         agents except its children.  A driver is always able to share
565 //                         a protocol with its children, since the driver is in control of the
566 //                         parent controller's and the child controller's use of the protocol.
567 //                         This attribute will force all other drivers to disconnect from the protocol
568 //                         before this driver attaches.  When this driver closes the handle, the other
569 //                         drivers will reconnect to the protocol.
570 //
571 //
572 // BY_CHILD_CONTROLLER   - Used by EFI 1.1 Driver to show that a protocol is consumed by a child
573 //                         of the driver.  This is information used by DisconnectController() to
574 //                         determine the list of children that a protocol has.  It has
575 //                         no affect on the OpenProtocol()/ClosePrototocol() behavior.
576 //
577 // EXCLUSIVE             - Used by EFI 1.1 Applications to gain exclusive access to a protocol.
578 //                         All drivers are disconnected from the handle while the application has
579 //                         the handle open.  These drivers are reconnected when the application
580 //                         closes the handle.
581 //
582 /////////////////////////////////////////////////////////////////////////////////////////////////
583 // OpenProtocol() behavior based on Attribute values
584 /////////////////////////////////////////////////////////////////////////////////////////////////
585 //
586 // OpenProtocol (Handle, Protocol, Interface, ImageHandle, DeviceHandle, Attributes)
587 // * EFI_UNSUPPORTED        if Protocol does not exist on Handle
588 // * EFI_INVALID_PARAMETER  if Handle is not a valid handle.
589 // * EFI_INVALID_PARAMETER  if Protocol is NULL or not a valid GUID
590 // * EFI_INVALID_PARAMETER  if Interface is NULL
591 // * EFI_INVALID_PARAMETER  if Attributes is not one of the following values:
592 //                            BY_HANDLE_PROTOCOL
593 //                            GET_PROTOCOL
594 //                            TEST_PROTOCOL
595 //                            BY_CHILD_CONTROLLER
596 //                            BY_DRIVER
597 //                            BY_DRIVER | EXCLUSIVE
598 //                            EXCLUSIVE
599 // * EFI_INVALID_PARAMETER  if Attributes BY_CHILD_CONTROLLER and ImageHandle is not a valid handle
600 // * EFI_INVALID_PARAMETER  if Attributes BY_CHILD_CONTROLLER and DeviceHandle is not a valid handle
601 // * EFI_INVALID_PARAMETER  if Attributes BY_CHILD_CONTROLLER and Handle == DeviceHandle
602 // * EFI_INVALID_PARAMETER  if Attributes BY_DRIVER and ImageHandle is not a valid handle
603 // * EFI_INVALID_PARAMETER  if Attributes BY_DRIVER and DeviceHandle is not a valid handle
604 // * EFI_INVALID_PARAMETER  if Attributes BY_DRIVER | EXCLUSIVE and ImageHandle is not a valid handle
605 // * EFI_INVALID_PARAMETER  if Attributes BY_DRIVER | EXCLUSIVE and DeviceHandle is not a valid handle
606 // * EFI_INVALID_PARAMETER  if Attributes EXCLUSIVE and ImageHandle is not a valid handle
607 //
608 // OpenProtocol() Attributes = BY_HANDLE_PROTOCOL, GET_PROTOCOL, TEST_PROTOCOL, BY_CHILD_CONTROLLER
609 // * EFI_SUCCESS      if Protocol exists on the Handle
610 //
611 // OpenProtocol() Attributes = BY_DRIVER
612 // * EFI_SUCCESS        if there are no items in the Open List for (Handle, Protocol)
613 // * EFI_SUCCESS        if there are only items in the Open List for (Handle, Protocol)
614 //                      that have the one of the following Attributes
615 //                        BY_HANDLE_PROTOCOL
616 //                        GET_PROTOCOL
617 //                        TEST_PROTOCOL
618 //                        BY_CHILD_CONTROLLER
619 // * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
620 //                      that have the one of the following Attributes
621 //                        BY_DRIVER
622 //                      AND ImageHandle != OpenListItem.IH
623 // * EFI_ALREADY_STARTED if there are any items in the Open List for (Handle, Protocol)
624 //                       that have the one of the following Attributes
625 //                         BY_DRIVER
626 //                       AND ImageHandle == OpenListItem.IH
627 // * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
628 //                      that have the one of the following Attributes
629 //                        BY_DRIVER | EXCLUSIVE
630 //                        EXCLUSIVE
631 //
632 // OpenProtocol() Attributes = BY_DRIVER | EXCLUSIVE
633 // * EFI_SUCCESS        if there are no items in the Open List for (Handle, Protocol)
634 // * EFI_SUCCESS        if there are only items in the Open List for (Handle, Protocol)
635 //                      that have the one of the following Attributes
636 //                        BY_HANDLE_PROTOCOL
637 //                        GET_PROTOCOL
638 //                        TEST_PROTOCOL
639 //                        BY_CHILD_CONTROLLER
640 // * EFI_SUCCESS        if there are any items in the Open List for (Handle, Protocol)
641 //                      that have the one of the following Attributes
642 //                        BY_DRIVER
643 //                      AND the driver is removed by DisconnectController(IH,DH)
644 // * EFI_ALREADY_STARTED if there are any items in the Open List for (Handle, Protocol)
645 //                       that have the one of the following Attributes
646 //                         BY_DRIVER | EXCLUSIVE
647 //                       AND ImageHandle == OpenListItem.IH
648 // * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
649 //                      that have the one of the following Attributes
650 //                        BY_DRIVER
651 //                      AND the driver can not be removed by DisconnectController(IH,DH)
652 // * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
653 //                      that have the one of the following Attributes
654 //                        BY_DRIVER | EXCLUSIVE
655 //                        EXCLUSIVE
656 //
657 // OpenProtocol() Attributes = EXCLUSIVE
658 // * EFI_SUCCESS        if there are no items in the Open List for (Handle, Protocol)
659 // * EFI_SUCCESS        if there are only items in the Open List for (Handle, Protocol)
660 //                      that have the one of the following Attributes
661 //                        BY_HANDLE_PROTOCOL
662 //                        GET_PROTOCOL
663 //                        TEST_PROTOCOL
664 //                        BY_CHILD_CONTROLLER
665 // * EFI_SUCCESS        if there are any items in the Open List for (Handle, Protocol)
666 //                      that have the one of the following Attributes
667 //                        BY_DRIVER
668 //                      AND the driver is removed by DisconnectController(IH,DH)
669 // * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
670 //                      that have the one of the following Attributes
671 //                        BY_DRIVER
672 //                      AND the driver can not be removed by DisconnectController(IH,DH)
673 // * EFI_ACCESS_DENIED  if there are any items in the Open List for (Handle, Protocol)
674 //                      that have the one of the following Attributes
675 //                        BY_DRIVER | EXCLUSIVE
676 //                        EXCLUSIVE
677 //
678 /////////////////////////////////////////////////////////////////////////////////////////////////
679 // CloseProtocol() Behavior based on the Attributes of the item being closed and the items
680 //                 remaining on the Open List
681 /////////////////////////////////////////////////////////////////////////////////////////////////
682 // CloseProtocol(Handle, Protocol, ImageHandle, DeviceHandle)
683 // CloseProtocol() Attributes of item = BY_HANDLE_PROTOCOL,
684 //                                      GET_PROTOCOL
685 //                                      TEST_PROTOCOL
686 //                                      BY_CHILD_CONTROLLER,
687 //                                      BY_DRIVER
688 //                                      BY_DRIVER | EXCLUSIVE
689 //                                      EXCLUSIVE
690 //   EFI_NOT_FOUND          if Protocol does not exist on Handle
691 //   EFI_INVALID_PARAMETER  if Handle is not a valid handle.
692 //   EFI_INVALID_PARAMETER  if Protocol is NULL or not a valid GUID
693 //   EFI_INVALID_PARAMETER  if ImageHandle is not a valid handle
694 //   EFI_INVALID_PARAMETER  if DeviceHandle is not a valid handle
695 //   EFI_NOT_FOUND      if (ImageHandle, DeviceHandle) is not present in the Open List
696 //                      for (Handle, Protocol)
697 //   EFI_ACCESS_DENIED  if (ImageHandle, DeviceHandle) is present in the Open List
698 //                      for (Handle, Protocol), but the item can not be removed.
699 //   EFI_SUCCESS        if (ImageHandle, DeviceHandle) is present in the Open List
700 //                      for (Handle, Protocol), and the item can be removed.
701 //
702 /////////////////////////////////////////////////////////////////////////////////////////////////
703 // UninstallProtocolInterface() behavior
704 /////////////////////////////////////////////////////////////////////////////////////////////////
705 //
706 // UninstallProtocolInterface (Handle, Protocol, Interface)
707 //
708 //   EFI_INVALID_PARAMETER if Handle is not a valid handle.
709 //   EFI_INVALID_PARAMETER if Protocol is not a vlaid GUID
710 //   EFI_NOT_FOUND         if Handle doe not support Protocol
711 //   EFI_NOT_FOUND         if the interface for (Handle, Protocol) does not match Interface
712 //   EFI_ACCESS_DENIED     if the list of Open Items for (Handle, Protocol) can not be removed
713 //   EFI_SUCCESS           if the list of Open Items is empty, and Protocol is removed from Handle
714 //
715 // Algorithm to remove Open Item List:
716 //
717 // Loop through all Open Item List entries
718 //   if (OpenItem.Attributes & BY_DRIVER) then
719 //     DisconnectController (OpenItem.IH, OpenItem.DH)
720 //   end if
721 // end loop
722 // Loop through all Open Item List entries
723 //   if (OpenItem.Attributes & BY_HANDLE_PROTOCOL or GET_PROTOCOL or TEST_PROTOCOL) then
724 //     CloseProtocol (Handle, Protocol, OpenItem.IH, OpenItem.DH)
725 //   end if
726 // end loop
727 // if Open Item List is empty then remove Protocol from Handle and return EFI_SUCCESS
728 // if Open Item List is not empty then return EFI_ACCESS_DENIED
729 //
730 /////////////////////////////////////////////////////////////////////////////////////////////////
731 typedef
732 EFI_BOOTSERVICE11
733 EFI_STATUS
734 (EFIAPI *EFI_OPEN_PROTOCOL) (
735   IN EFI_HANDLE                 Handle,
736   IN EFI_GUID                   * Protocol,
737   OUT VOID                      **Interface,
738   IN  EFI_HANDLE                ImageHandle,
739   IN  EFI_HANDLE                ControllerHandle, OPTIONAL
740   IN  UINT32                    Attributes
741   );
742 
743 typedef
744 EFI_BOOTSERVICE11
745 EFI_STATUS
746 (EFIAPI *EFI_CLOSE_PROTOCOL) (
747   IN EFI_HANDLE               Handle,
748   IN EFI_GUID                 * Protocol,
749   IN EFI_HANDLE               ImageHandle,
750   IN EFI_HANDLE               DeviceHandle
751   );
752 
753 typedef struct {
754   EFI_HANDLE  AgentHandle;
755   EFI_HANDLE  ControllerHandle;
756   UINT32      Attributes;
757   UINT32      OpenCount;
758 } EFI_OPEN_PROTOCOL_INFORMATION_ENTRY;
759 
760 typedef
761 EFI_BOOTSERVICE11
762 EFI_STATUS
763 (EFIAPI *EFI_OPEN_PROTOCOL_INFORMATION) (
764   IN  EFI_HANDLE                          UserHandle,
765   IN  EFI_GUID                            * Protocol,
766   IN  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer,
767   OUT UINTN                               *EntryCount
768   );
769 
770 typedef
771 EFI_BOOTSERVICE11
772 EFI_STATUS
773 (EFIAPI *EFI_PROTOCOLS_PER_HANDLE) (
774   IN EFI_HANDLE       UserHandle,
775   OUT EFI_GUID        ***ProtocolBuffer,
776   OUT UINTN           *ProtocolBufferCount
777   );
778 
779 typedef
780 EFI_BOOTSERVICE
781 EFI_STATUS
782 (EFIAPI *EFI_REGISTER_PROTOCOL_NOTIFY) (
783   IN EFI_GUID                 * Protocol,
784   IN EFI_EVENT                Event,
785   OUT VOID                    **Registration
786   );
787 
788 typedef enum {
789   AllHandles,
790   ByRegisterNotify,
791   ByProtocol
792 } EFI_LOCATE_SEARCH_TYPE;
793 
794 typedef
795 EFI_BOOTSERVICE
796 EFI_STATUS
797 (EFIAPI *EFI_LOCATE_HANDLE) (
798   IN EFI_LOCATE_SEARCH_TYPE   SearchType,
799   IN EFI_GUID                 * Protocol OPTIONAL,
800   IN VOID                     *SearchKey OPTIONAL,
801   IN OUT UINTN                *BufferSize,
802   OUT EFI_HANDLE              * Buffer
803   );
804 
805 typedef
806 EFI_BOOTSERVICE
807 EFI_STATUS
808 (EFIAPI *EFI_LOCATE_DEVICE_PATH) (
809   IN EFI_GUID                         * Protocol,
810   IN OUT EFI_DEVICE_PATH_PROTOCOL     **DevicePath,
811   OUT EFI_HANDLE                      * Device
812   );
813 
814 typedef
815 EFI_BOOTSERVICE
816 EFI_STATUS
817 (EFIAPI *EFI_INSTALL_CONFIGURATION_TABLE) (
818   IN EFI_GUID                 * Guid,
819   IN VOID                     *Table
820   );
821 
822 typedef
823 EFI_BOOTSERVICE
824 EFI_STATUS
825 (EFIAPI *EFI_RESERVED_SERVICE) (
826   VOID
827   );
828 
829 typedef
830 EFI_BOOTSERVICE11
831 EFI_STATUS
832 (EFIAPI *EFI_LOCATE_HANDLE_BUFFER) (
833   IN EFI_LOCATE_SEARCH_TYPE       SearchType,
834   IN EFI_GUID                     * Protocol OPTIONAL,
835   IN VOID                         *SearchKey OPTIONAL,
836   IN OUT UINTN                    *NumberHandles,
837   OUT EFI_HANDLE                  **Buffer
838   );
839 
840 typedef
841 EFI_BOOTSERVICE11
842 EFI_STATUS
843 (EFIAPI *EFI_LOCATE_PROTOCOL) (
844   EFI_GUID  * Protocol,
845   VOID      *Registration, OPTIONAL
846   VOID      **Interface
847   );
848 
849 //
850 // Definition of Status Code extended data header
851 //
852 //  HeaderSize    The size of the architecture. This is specified to enable
853 //                the future expansion
854 //
855 //  Size          The size of the data in bytes. This does not include the size
856 //                of the header structure.
857 //
858 //  Type          A GUID defining the type of the data
859 //
860 //
861 #if ((TIANO_RELEASE_VERSION != 0) && (EFI_SPECIFICATION_VERSION < 0x00020000))
862 
863 typedef
864 EFI_RUNTIMESERVICE
865 EFI_STATUS
866 (EFIAPI *EFI_REPORT_STATUS_CODE) (
867   IN EFI_STATUS_CODE_TYPE     Type,
868   IN EFI_STATUS_CODE_VALUE    Value,
869   IN UINT32                   Instance,
870   IN EFI_GUID                 * CallerId OPTIONAL,
871   IN EFI_STATUS_CODE_DATA     * Data OPTIONAL
872   );
873 
874 #endif
875 
876 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
877 
878 typedef
879 EFI_RUNTIMESERVICE
880 EFI_STATUS
881 (EFIAPI *EFI_UPDATE_CAPSULE) (
882   IN EFI_CAPSULE_HEADER     **CapsuleHeaderArray,
883   IN UINTN                  CapsuleCount,
884   IN EFI_PHYSICAL_ADDRESS   ScatterGatherList OPTIONAL
885  );
886 
887 
888 typedef
889 EFI_RUNTIMESERVICE
890 EFI_STATUS
891 (EFIAPI *EFI_QUERY_CAPSULE_CAPABILITIES) (
892   IN  EFI_CAPSULE_HEADER   **CapsuleHeaderArray,
893   IN  UINTN                CapsuleCount,
894   OUT UINT64               *MaximumCapsuleSize,
895   OUT EFI_RESET_TYPE       *ResetType
896 );
897 
898 typedef
899 EFI_RUNTIMESERVICE
900 EFI_STATUS
901 (EFIAPI *EFI_QUERY_VARIABLE_INFO) (
902   IN UINT32           Attributes,
903   OUT UINT64          *MaximumVariableStorageSize,
904   OUT UINT64          *RemainingVariableStorageSize,
905   OUT UINT64          *MaximumVariableSize
906   );
907 
908 #endif
909 
910 //
911 // EFI Runtime Services Table
912 //
913 #define EFI_RUNTIME_SERVICES_SIGNATURE  0x56524553544e5552ULL
914 #define EFI_RUNTIME_SERVICES_REVISION   EFI_SPECIFICATION_VERSION
915 
916 typedef struct {
917   EFI_TABLE_HEADER              Hdr;
918 
919   //
920   // Time services
921   //
922   EFI_GET_TIME                  GetTime;
923   EFI_SET_TIME                  SetTime;
924   EFI_GET_WAKEUP_TIME           GetWakeupTime;
925   EFI_SET_WAKEUP_TIME           SetWakeupTime;
926 
927   //
928   // Virtual memory services
929   //
930   EFI_SET_VIRTUAL_ADDRESS_MAP   SetVirtualAddressMap;
931   EFI_CONVERT_POINTER           ConvertPointer;
932 
933   //
934   // Variable services
935   //
936   EFI_GET_VARIABLE              GetVariable;
937   EFI_GET_NEXT_VARIABLE_NAME    GetNextVariableName;
938   EFI_SET_VARIABLE              SetVariable;
939 
940   //
941   // Misc
942   //
943   EFI_GET_NEXT_HIGH_MONO_COUNT  GetNextHighMonotonicCount;
944   EFI_RESET_SYSTEM              ResetSystem;
945 
946 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
947   //
948   // New Boot Service added by UEFI 2.0
949   //
950   EFI_UPDATE_CAPSULE             UpdateCapsule;
951   EFI_QUERY_CAPSULE_CAPABILITIES QueryCapsuleCapabilities;
952   EFI_QUERY_VARIABLE_INFO        QueryVariableInfo;
953 #elif (TIANO_RELEASE_VERSION != 0)
954   //
955   // Tiano extension to EFI 1.10 runtime table
956   // It was moved to a protocol to not conflict with UEFI 2.0
957   // If Tiano is disabled, this item is not enabled for EFI1.10
958   //
959   EFI_REPORT_STATUS_CODE        ReportStatusCode;
960 #endif
961 
962 } EFI_RUNTIME_SERVICES;
963 
964 //
965 // EFI Boot Services Table
966 //
967 #define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42ULL
968 #define EFI_BOOT_SERVICES_REVISION  EFI_SPECIFICATION_VERSION
969 
970 typedef struct {
971   EFI_TABLE_HEADER                            Hdr;
972 
973   //
974   // Task priority functions
975   //
976   EFI_RAISE_TPL                               RaiseTPL;
977   EFI_RESTORE_TPL                             RestoreTPL;
978 
979   //
980   // Memory functions
981   //
982   EFI_ALLOCATE_PAGES                          AllocatePages;
983   EFI_FREE_PAGES                              FreePages;
984   EFI_GET_MEMORY_MAP                          GetMemoryMap;
985   EFI_ALLOCATE_POOL                           AllocatePool;
986   EFI_FREE_POOL                               FreePool;
987 
988   //
989   // Event & timer functions
990   //
991   EFI_CREATE_EVENT                            CreateEvent;
992   EFI_SET_TIMER                               SetTimer;
993   EFI_WAIT_FOR_EVENT                          WaitForEvent;
994   EFI_SIGNAL_EVENT                            SignalEvent;
995   EFI_CLOSE_EVENT                             CloseEvent;
996   EFI_CHECK_EVENT                             CheckEvent;
997 
998   //
999   // Protocol handler functions
1000   //
1001   EFI_INSTALL_PROTOCOL_INTERFACE              InstallProtocolInterface;
1002   EFI_REINSTALL_PROTOCOL_INTERFACE            ReinstallProtocolInterface;
1003   EFI_UNINSTALL_PROTOCOL_INTERFACE            UninstallProtocolInterface;
1004   EFI_HANDLE_PROTOCOL                         HandleProtocol;
1005   VOID                                        *Reserved;
1006   EFI_REGISTER_PROTOCOL_NOTIFY                RegisterProtocolNotify;
1007   EFI_LOCATE_HANDLE                           LocateHandle;
1008   EFI_LOCATE_DEVICE_PATH                      LocateDevicePath;
1009   EFI_INSTALL_CONFIGURATION_TABLE             InstallConfigurationTable;
1010 
1011   //
1012   // Image functions
1013   //
1014   EFI_IMAGE_LOAD                              LoadImage;
1015   EFI_IMAGE_START                             StartImage;
1016   EFI_EXIT                                    Exit;
1017   EFI_IMAGE_UNLOAD                            UnloadImage;
1018   EFI_EXIT_BOOT_SERVICES                      ExitBootServices;
1019 
1020   //
1021   // Misc functions
1022   //
1023   EFI_GET_NEXT_MONOTONIC_COUNT                GetNextMonotonicCount;
1024   EFI_STALL                                   Stall;
1025   EFI_SET_WATCHDOG_TIMER                      SetWatchdogTimer;
1026 
1027   //
1028   // ////////////////////////////////////////////////////
1029   // EFI 1.1 Services
1030     //////////////////////////////////////////////////////
1031   //
1032   // DriverSupport Services
1033   //
1034   EFI_CONNECT_CONTROLLER                      ConnectController;
1035   EFI_DISCONNECT_CONTROLLER                   DisconnectController;
1036 
1037   //
1038   // Added Open and Close protocol for the new driver model
1039   //
1040   EFI_OPEN_PROTOCOL                           OpenProtocol;
1041   EFI_CLOSE_PROTOCOL                          CloseProtocol;
1042   EFI_OPEN_PROTOCOL_INFORMATION               OpenProtocolInformation;
1043 
1044   //
1045   // Added new services to EFI 1.1 as Lib to reduce code size.
1046   //
1047   EFI_PROTOCOLS_PER_HANDLE                    ProtocolsPerHandle;
1048   EFI_LOCATE_HANDLE_BUFFER                    LocateHandleBuffer;
1049   EFI_LOCATE_PROTOCOL                         LocateProtocol;
1050 
1051   EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES    InstallMultipleProtocolInterfaces;
1052   EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES  UninstallMultipleProtocolInterfaces;
1053 
1054   //
1055   // CRC32 services
1056   //
1057   EFI_CALCULATE_CRC32                         CalculateCrc32;
1058 
1059   //
1060   // Memory Utility Services
1061   //
1062   EFI_COPY_MEM                                CopyMem;
1063   EFI_SET_MEM                                 SetMem;
1064 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
1065   //
1066   // UEFI 2.0 Extension to the table
1067   //
1068   EFI_CREATE_EVENT_EX                         CreateEventEx;
1069 #endif
1070 
1071 } EFI_BOOT_SERVICES;
1072 
1073 //
1074 // EFI Configuration Table
1075 //
1076 typedef struct {
1077   EFI_GUID  VendorGuid;
1078   VOID      *VendorTable;
1079 } EFI_CONFIGURATION_TABLE;
1080 
1081 //
1082 // EFI System Table
1083 //
1084 #define EFI_SYSTEM_TABLE_SIGNATURE      0x5453595320494249ULL
1085 #define EFI_SYSTEM_TABLE_REVISION       EFI_SPECIFICATION_VERSION
1086 #define EFI_1_02_SYSTEM_TABLE_REVISION  ((1 << 16) | 02)
1087 #define EFI_1_10_SYSTEM_TABLE_REVISION  ((1 << 16) | 10)
1088 #define EFI_2_00_SYSTEM_TABLE_REVISION  ((2 << 16) | 00)
1089 #define EFI_2_10_SYSTEM_TABLE_REVISION  ((2 << 16) | 10)
1090 
1091 struct _EFI_SYSTEM_TABLE {
1092   EFI_TABLE_HEADER              Hdr;
1093 
1094   CHAR16                        *FirmwareVendor;
1095   UINT32                        FirmwareRevision;
1096 
1097   EFI_HANDLE                    ConsoleInHandle;
1098   EFI_SIMPLE_TEXT_IN_PROTOCOL   *ConIn;
1099 
1100   EFI_HANDLE                    ConsoleOutHandle;
1101   EFI_SIMPLE_TEXT_OUT_PROTOCOL  *ConOut;
1102 
1103   EFI_HANDLE                    StandardErrorHandle;
1104   EFI_SIMPLE_TEXT_OUT_PROTOCOL  *StdErr;
1105 
1106   EFI_RUNTIME_SERVICES          *RuntimeServices;
1107   EFI_BOOT_SERVICES             *BootServices;
1108 
1109   UINTN                         NumberOfTableEntries;
1110   EFI_CONFIGURATION_TABLE       *ConfigurationTable;
1111 
1112 };
1113 
1114 #endif
1115