Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / x86 / prefix / 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/efi/efi.h>
26 #include <ipxe/efi/efi_driver.h>
27 #include <ipxe/efi/efi_snp.h>
28 #include <ipxe/efi/efi_autoboot.h>
29
30 /**
31  * EFI entry point
32  *
33  * @v image_handle      Image handle
34  * @v systab            System table
35  * @ret efirc           EFI return status code
36  */
37 EFI_STATUS EFIAPI _efi_start ( EFI_HANDLE image_handle,
38                                EFI_SYSTEM_TABLE *systab ) {
39         EFI_STATUS efirc;
40         int rc;
41
42         /* Initialise EFI environment */
43         if ( ( efirc = efi_init ( image_handle, systab ) ) != 0 )
44                 goto err_init;
45
46         /* Record autoboot device (if any) */
47         efi_set_autoboot();
48
49         /* Claim SNP devices for use by iPXE */
50         efi_snp_claim();
51
52         /* Call to main() */
53         if ( ( rc = main() ) != 0 ) {
54                 efirc = EFIRC ( rc );
55                 goto err_main;
56         }
57
58  err_main:
59         efi_snp_release();
60         efi_loaded_image->Unload ( image_handle );
61         efi_driver_reconnect_all();
62  err_init:
63         return efirc;
64 }
65
66 /**
67  * Probe EFI root bus
68  *
69  * @v rootdev           EFI root device
70  */
71 static int efi_probe ( struct root_device *rootdev __unused ) {
72
73         return efi_driver_connect_all();
74 }
75
76 /**
77  * Remove EFI root bus
78  *
79  * @v rootdev           EFI root device
80  */
81 static void efi_remove ( struct root_device *rootdev __unused ) {
82
83         efi_driver_disconnect_all();
84 }
85
86 /** EFI root device driver */
87 static struct root_driver efi_root_driver = {
88         .probe = efi_probe,
89         .remove = efi_remove,
90 };
91
92 /** EFI root device */
93 struct root_device efi_root_device __root_device = {
94         .dev = { .name = "EFI" },
95         .driver = &efi_root_driver,
96 };