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