cbdc598928f8e072f70c42686905dadf347e841a
[openwrt.git] / target / linux / adm5120 / files / arch / mips / adm5120 / prom / bootbase.c
1 /*
2 * $Id$
3 *
4 * ZyXEL's Bootbase 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 modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 *
13 */
14
15 #include <linux/types.h>
16 #include <linux/autoconf.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/string.h>
20
21 #include <asm/bootinfo.h>
22 #include <asm/addrspace.h>
23 #include <asm/byteorder.h>
24
25 #include <adm5120_defs.h>
26 #include <prom/zynos.h>
27 #include "prom_read.h"
28
29 #define ZYNOS_INFO_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x3F90)
30 #define ZYNOS_HDBG_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x4000)
31 #define BOOTEXT_ADDR_MIN KSEG1ADDR(ADM5120_SRAM0_BASE)
32 #define BOOTEXT_ADDR_MAX (BOOTEXT_ADDR_MIN + (2*1024*1024))
33
34 static int bootbase_found;
35 static struct zynos_board_info *board_info;
36
37 struct bootbase_info bootbase_info;
38
39 static inline int bootbase_dbgarea_present(u8 *data)
40 {
41 u32 t;
42
43 t = prom_read_be32(data+5);
44 if (t != ZYNOS_MAGIC_DBGAREA1)
45 return 0;
46
47 t = prom_read_be32(data+9);
48 if (t != ZYNOS_MAGIC_DBGAREA2)
49 return 0;
50
51 return 1;
52 }
53
54 static inline u32 bootbase_get_bootext_addr(void)
55 {
56 return prom_read_be32(&board_info->bootext_addr);
57 }
58
59 static inline u16 bootbase_get_vendor_id(void)
60 {
61 #define CHECK_VENDOR(n) (strnicmp(board_info->vendor, (n), strlen(n)) == 0)
62 unsigned char vendor[ZYNOS_NAME_LEN];
63 int i;
64
65 for (i = 0; i < ZYNOS_NAME_LEN; i++)
66 vendor[i] = board_info->vendor[i];
67
68 if CHECK_VENDOR(ZYNOS_VENDOR_ZYXEL)
69 return ZYNOS_VENDOR_ID_ZYXEL;
70
71 if CHECK_VENDOR(ZYNOS_VENDOR_DLINK)
72 return ZYNOS_VENDOR_ID_DLINK;
73
74 if CHECK_VENDOR(ZYNOS_VENDOR_LUCENT)
75 return ZYNOS_VENDOR_ID_LUCENT;
76
77 if CHECK_VENDOR(ZYNOS_VENDOR_NETGEAR)
78 return ZYNOS_VENDOR_ID_NETGEAR;
79
80 return ZYNOS_VENDOR_ID_OTHER;
81 }
82
83 static inline u16 bootbase_get_board_id(void)
84 {
85 return prom_read_be16(&board_info->board_id);
86 }
87
88 int __init bootbase_present(void)
89 {
90 u32 t;
91
92 if (bootbase_found)
93 goto out;
94
95 /* check presence of the dbgarea */
96 if (bootbase_dbgarea_present((u8 *)ZYNOS_HDBG_ADDR) == 0)
97 goto out;
98
99 board_info = (struct zynos_board_info *)(ZYNOS_INFO_ADDR);
100
101 /* check for a valid BootExt address */
102 t = bootbase_get_bootext_addr();
103 if ((t < BOOTEXT_ADDR_MIN) || (t > BOOTEXT_ADDR_MAX))
104 goto out;
105
106 bootbase_info.vendor_id = bootbase_get_vendor_id();
107 bootbase_info.board_id = bootbase_get_board_id();
108
109 bootbase_found = 1;
110
111 out:
112 return bootbase_found;
113 }
114
This page took 0.04445 seconds and 3 git commands to generate.