28b61206d314da6f66f1eddb101e0ba27455b757
[openwrt.git] / target / linux / adm5120 / files / arch / mips / adm5120 / prom / cfe.c
1 /*
2  *  $Id$
3  *
4  *  Broadcom's CFE specific prom routines
5  *
6  *  Copyright (C) 2007 OpenWrt.org
7  *  Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
8  *
9  *  This program is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU General Public License
11  *  as published by the Free Software Foundation; either version 2
12  *  of the License, or (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the
21  *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  *  Boston, MA  02110-1301, USA.
23  */
24
25 #include <linux/types.h>
26 #include <linux/init.h>
27
28 #include <asm/bootinfo.h>
29 #include <asm/addrspace.h>
30
31 #include <prom/cfe.h>
32 #include "prom_read.h"
33
34 /*
35  * CFE based boards
36  */
37 #define CFE_EPTSEAL     0x43464531 /* CFE1 is the magic number to recognize CFE
38 from other bootloaders */
39
40 static int cfe_found;
41
42 static u32 cfe_handle;
43 static u32 cfe_entry;
44 static u32 cfe_seal;
45
46 int __init cfe_present(void)
47 {
48         /*
49          * This method only works, when we are booted directly from the CFE.
50          */
51         u32 a1 = (u32) fw_arg1;
52
53         if (cfe_found)
54                 return 1;
55
56         cfe_handle = (u32) fw_arg0;
57         cfe_entry = (u32) fw_arg2;
58         cfe_seal = (u32) fw_arg3;
59
60         /* Check for CFE by finding the CFE magic number */
61         if (cfe_seal != CFE_EPTSEAL)
62                 return 0;
63
64         /* cfe_a1_val must be 0, because only one CPU present in the ADM5120 */
65         if (a1 != 0)
66                 return 0;
67
68         /* The cfe_handle, and the cfe_entry must be kernel mode addresses */
69         if ((cfe_handle < KSEG0) || (cfe_entry < KSEG0))
70                 return 0;
71
72         cfe_found = 1;
73         return 1;
74 }
75
76 char *cfe_getenv(char *envname)
77 {
78         if (cfe_found == 0)
79                 return NULL;
80
81         return NULL;
82 }