iPXE
efiprefix.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 FILE_LICENCE ( GPL2_OR_LATER );
21 
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <ipxe/device.h>
25 #include <ipxe/init.h>
26 #include <ipxe/efi/efi.h>
27 #include <ipxe/efi/efi_driver.h>
28 #include <ipxe/efi/efi_snp.h>
29 #include <ipxe/efi/efi_autoboot.h>
30 #include <ipxe/efi/efi_autoexec.h>
31 #include <ipxe/efi/efi_cachedhcp.h>
32 #include <ipxe/efi/efi_watchdog.h>
33 #include <ipxe/efi/efi_veto.h>
34 
35 /**
36  * EFI entry point
37  *
38  * @v image_handle Image handle
39  * @v systab System table
40  * @ret efirc EFI return status code
41  */
43  EFI_SYSTEM_TABLE *systab ) {
44  EFI_STATUS efirc;
45  int rc;
46 
47  /* Initialise stack cookie */
48  efi_init_stack_guard ( image_handle );
49 
50  /* Initialise EFI environment */
51  if ( ( efirc = efi_init ( image_handle, systab ) ) != 0 )
52  goto err_init;
53 
54  /* Claim SNP devices for use by iPXE */
55  efi_snp_claim();
56 
57  /* Start watchdog holdoff timer */
59 
60  /* Call to main() */
61  if ( ( rc = main() ) != 0 ) {
62  efirc = EFIRC ( rc );
63  goto err_main;
64  }
65 
66  err_main:
69  efi_loaded_image->Unload ( image_handle );
71  err_init:
72  return efirc;
73 }
74 
75 /**
76  * Initialise EFI application
77  *
78  */
79 static void efi_init_application ( void ) {
81 
82  /* Identify autoboot device, if any */
84 
85  /* Store cached DHCP packet, if any */
87 
88  /* Load autoexec script, if any */
90 }
91 
92 /** EFI application initialisation function */
93 struct init_fn efi_init_application_fn __init_fn ( INIT_NORMAL ) = {
95 };
96 
97 /**
98  * Probe EFI root bus
99  *
100  * @v rootdev EFI root device
101  */
102 static int efi_probe ( struct root_device *rootdev __unused ) {
103 
104  /* Remove any vetoed drivers */
105  efi_veto();
106 
107  /* Connect our drivers */
108  return efi_driver_connect_all();
109 }
110 
111 /**
112  * Remove EFI root bus
113  *
114  * @v rootdev EFI root device
115  */
116 static void efi_remove ( struct root_device *rootdev __unused ) {
117 
118  /* Disconnect our drivers */
120 }
121 
122 /** EFI root device driver */
123 static struct root_driver efi_root_driver = {
124  .probe = efi_probe,
125  .remove = efi_remove,
126 };
127 
128 /** EFI root device */
129 struct root_device efi_root_device __root_device = {
130  .dev = { .name = "EFI" },
131  .driver = &efi_root_driver,
132 };
int efi_driver_connect_all(void)
Connect EFI driver to all possible devices.
Definition: efi_driver.c:573
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition: efi_init.c:36
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void efi_init_stack_guard(EFI_HANDLE handle)
Initialise stack cookie.
Definition: efi.h:322
int efi_cachedhcp_record(EFI_HANDLE device)
Record cached DHCP packet.
Definition: efi_cachedhcp.c:45
EFI driver interface.
void(* initialise)(void)
Definition: init.h:15
void efi_veto(void)
Remove any vetoed drivers.
Definition: efi_veto.c:561
Error codes.
static void efi_remove(struct root_device *rootdev __unused)
Remove EFI root bus.
Definition: efiprefix.c:116
struct root_device efi_root_device __root_device
EFI root device.
Definition: efiprefix.c:129
char name[40]
Name.
Definition: device.h:75
FILE_LICENCE(GPL2_OR_LATER)
A root device.
Definition: device.h:94
EFI driver vetoes.
static void efi_snp_claim(void)
Claim network devices for use by iPXE.
Definition: efi_snp.h:88
struct device dev
Device chain.
Definition: device.h:99
A hardware device.
Definition: device.h:73
#define INIT_NORMAL
Normal initialisation.
Definition: init.h:30
An initialisation function.
Definition: init.h:14
void efi_driver_reconnect_all(void)
Reconnect original EFI drivers to all possible devices.
Definition: efi_driver.c:595
static void efi_watchdog_start(void)
Start EFI watchdog holdoff timer.
Definition: efi_watchdog.h:17
static struct root_driver efi_root_driver
EFI root device driver.
Definition: efiprefix.c:123
static void efi_watchdog_stop(void)
Stop EFI watchdog holdoff timer.
Definition: efi_watchdog.h:26
struct init_fn efi_init_application_fn __init_fn(INIT_NORMAL)
EFI application initialisation function.
#define EFIAPI
EFI cached DHCP packet.
static void efi_init_application(void)
Initialise EFI application.
Definition: efiprefix.c:79
EFI autoboot device.
EFI_IMAGE_UNLOAD Unload
Definition: LoadedImage.h:79
EFI watchdog holdoff timer.
void efi_driver_disconnect_all(void)
Disconnect EFI driver from all possible devices.
Definition: efi_driver.c:584
A root device driver.
Definition: device.h:107
static void efi_snp_release(void)
Release network devices for use via SNP.
Definition: efi_snp.h:96
int efi_set_autoboot_ll_addr(EFI_HANDLE device)
Identify autoboot device.
Definition: efi_autoboot.c:45
EFI System Table.
Definition: UefiSpec.h:1949
int(* probe)(struct root_device *rootdev)
Add root device.
Definition: device.h:116
EFI API.
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
EFI_STATUS EFIAPI _efi_start(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
EFI entry point.
Definition: efiprefix.c:42
EFI autoexec script.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
Device model.
EFI_STATUS efi_init(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab)
Initialise EFI environment.
Definition: efi_init.c:170
static int efi_probe(struct root_device *rootdev __unused)
Probe EFI root bus.
Definition: efiprefix.c:102
iPXE EFI SNP interface
__asmcall int main(void)
Main entry point.
Definition: main.c:28
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:154
Definition: efi.h:50
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:61
int efi_autoexec_load(EFI_HANDLE device)
Load autoexec script.
Definition: efi_autoexec.c:59