orphan
[debian/elilo] / chooser.c
1 /*
2  *  Copyright (C) 2001-2003 Hewlett-Packard Co.
3  *      Contributed by Stephane Eranian <eranian@hpl.hp.com>
4  *
5  * This file is part of the ELILO, the EFI Linux boot loader.
6  *
7  *  ELILO is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  ELILO is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with ELILO; see the file COPYING.  If not, write to the Free
19  *  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20  *  02111-1307, USA.
21  *
22  * Please check out the elilo.txt for complete documentation on how
23  * to use this program.
24  */
25
26 #include <efi.h>
27 #include <efilib.h>
28
29 #include "elilo.h"
30
31 #ifdef CONFIG_CHOOSER_SIMPLE
32 #include "choosers/simple.h"
33 #endif
34
35 #ifdef CONFIG_CHOOSER_TEXTMENU
36 #include "choosers/textmenu.h"
37 #endif
38
39 static chooser_t *choosers_tab[]={
40 #ifdef CONFIG_CHOOSER_SIMPLE
41         &simple_chooser,
42 #endif
43 #ifdef CONFIG_CHOOSER_TEXTMENU
44         &textmenu_chooser,
45 #endif
46         NULL
47 };
48 /*
49  * The intent of this module is to provide a mechanism by which alternate
50  * choosers can be installed. Developers can write new choosers and
51  * add them to the list. They will be probe and the best match
52  * will be started first. It should be possible to switch to another
53  * chooser using a key combination. There is a default simple text-based
54  * chooser that must always be present.
55  *
56  * Currently you can specify a chooser via "-c name" when you invoke elilo,
57  * or via "chooser=name" in the config file.  If the specified chooser
58  * probes ok it will be selected, otherwise the first one that probes ok
59  * will be used.
60  *
61  * XXX: at this time, not all chooser functionalities are implemented.
62  *
63  */
64 chooser_func_t *kernel_chooser;
65
66 INTN
67 init_chooser(EFI_HANDLE dev)
68 {
69         chooser_t **p;
70         CHAR16 *chooser_name = L"none";
71
72         kernel_chooser = NULL;
73
74         for (p=choosers_tab; *p; p++) {
75
76                 VERB_PRT(4, Print(L"trying chooser %s\n", (*p)->chooser_name));
77
78                 if ((*p)->chooser_probe(dev) == 0) {
79                         /*
80                          * if that's the one we asked for, then go for it
81                          */
82                         if (!StrCmp(elilo_opt.chooser, (*p)->chooser_name)) {
83                                 kernel_chooser = (*p)->chooser_func;
84                                 chooser_name = (*p)->chooser_name;
85                                 break;
86                         }
87
88                         if (kernel_chooser == NULL) {
89                                 kernel_chooser = (*p)->chooser_func;
90                                 chooser_name = (*p)->chooser_name;
91                         }
92                 }
93         }
94
95         if (kernel_chooser) {
96                 VERB_PRT(2, Print(L"selected chooser %s\n", chooser_name));
97                 return 0;
98         }
99
100         ERR_PRT((L"No chooser selected. Impossible to proceed"));
101         return -1;
102 }
103
104 INTN
105 exist_chooser(CHAR16 *name)
106 {
107         chooser_t **p;
108
109         for (p=choosers_tab; *p; p++) {
110                 if (!StrCmp(name, (*p)->chooser_name)) return 0;
111         }
112         return -1;
113 }
114