[readline] Extend maximum read line length to 1024 characters
[ipxe.git] / src / interface / efi / efiprefix.c
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 */
42 EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle,
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 */
58 efi_watchdog_start();
59
60 /* Call to main() */
61 if ( ( rc = main() ) != 0 ) {
62 efirc = EFIRC ( rc );
63 goto err_main;
64 }
65
66 err_main:
67 efi_watchdog_stop();
68 efi_snp_release();
69 efi_loaded_image->Unload ( image_handle );
70 efi_driver_reconnect_all();
71 err_init:
72 return efirc;
73 }
74
75 /**
76 * Initialise EFI application
77 *
78 */
79 static void efi_init_application ( void ) {
80 EFI_HANDLE device = efi_loaded_image->DeviceHandle;
81
82 /* Identify autoboot device, if any */
83 efi_set_autoboot_ll_addr ( device );
84
85 /* Store cached DHCP packet, if any */
86 efi_cachedhcp_record ( device );
87
88 /* Load autoexec script, if any */
89 efi_autoexec_load ( device );
90 }
91
92 /** EFI application initialisation function */
93 struct init_fn efi_init_application_fn __init_fn ( INIT_NORMAL ) = {
94 .initialise = efi_init_application,
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 */
119 efi_driver_disconnect_all();
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 };