Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / minix / board.h @ 14

History | View | Annotate | Download (6.8 KB)

1
#ifndef __BOARD_H__
2
#define __BOARD_H__
3
#include <string.h>
4
/* 
5
  Utility functions to access/parse the board_id defined in the machine
6
  struct in include/minix/type.h.
7

8
   Identifier for the board 
9
     [31:28] Architecture.  (MINIX_BOARD_ARCH)
10
     [27:24] Architecture variant (MINIX_BOARD_ARCH_VARIANT) VERSION e.g. ARMV7 
11
     [23:16] Vendor/Soc (EG TI )  (MINIX_BOARD_VENDOR) 
12
     [15:8]  Board      (EG Beagle bone , beagle board ) (MINIX_BOARD)
13
     [7:0]   Board variant (EG BealgeBone white v.s. BeagleBone black ) (MINIX_BOARD_VARIANT)
14
*/
15

    
16
#define MINIX_BOARD_ARCH_SHIFT         (28)
17
#define MINIX_BOARD_ARCH_VARIANT_SHIFT (24)
18
#define MINIX_BOARD_VENDOR_SHIFT       (16)
19
#define MINIX_BOARD_SHIFT              (8)
20
#define MINIX_BOARD_VARIANT_SHIFT      (0)
21

    
22
/* 4 bits */
23
#define MINIX_BOARD_ARCH_MASK \
24
        (0XF << MINIX_BOARD_ARCH_SHIFT)
25
/* 4 bits */
26
#define MINIX_BOARD_ARCH_VARIANT_MASK \
27
        (0XF << MINIX_BOARD_ARCH_VARIANT_SHIFT)
28
/* 8 bits */
29
#define MINIX_BOARD_VENDOR_MASK \
30
        (0XFF << MINIX_BOARD_VENDOR_SHIFT)
31
/* 8 bits */
32
#define MINIX_BOARD_MASK \
33
        (0XFF << MINIX_BOARD_SHIFT)
34
/* 8 bits */
35
#define MINIX_BOARD_VARIANT_MASK \
36
        (0XFF << MINIX_BOARD_VARIANT_SHIFT)
37

    
38
#define MINIX_MK_BOARD_ARCH(v) \
39
        ((v << MINIX_BOARD_ARCH_SHIFT ) & MINIX_BOARD_ARCH_MASK)
40
#define MINIX_MK_BOARD_ARCH_VARIANT(v) \
41
        (( v << MINIX_BOARD_ARCH_VARIANT_SHIFT) & MINIX_BOARD_ARCH_VARIANT_MASK )
42
#define MINIX_MK_BOARD_VENDOR(v) \
43
        (( v << MINIX_BOARD_VENDOR_SHIFT) & MINIX_BOARD_VENDOR_MASK )
44
#define MINIX_MK_BOARD(v) \
45
        (( v << MINIX_BOARD_SHIFT) & MINIX_BOARD_MASK )
46
#define MINIX_MK_BOARD_VARIANT(v) \
47
        (( v << MINIX_BOARD_VARIANT_SHIFT) & MINIX_BOARD_VARIANT_MASK )
48

    
49
#define MINIX_BOARD_ARCH(v) \
50
        ((v & MINIX_BOARD_ARCH_MASK) >> MINIX_BOARD_ARCH_SHIFT )
51
#define MINIX_BOARD_ARCH_VARIANT(v) \
52
        (( v & MINIX_BOARD_ARCH_VARIANT_MASK) >> MINIX_BOARD_ARCH_VARIANT_SHIFT)
53
#define MINIX_BOARD_VENDOR(v) \
54
        (( v & MINIX_BOARD_VENDOR_MASK) >> MINIX_BOARD_VENDOR_SHIFT)
55
#define MINIX_BOARD(v) \
56
        (( v & MINIX_BOARD_MASK) >> MINIX_BOARD_SHIFT)
57
#define MINIX_BOARD_VARIANT(v) \
58
        (( v & MINIX_BOARD_VARIANT_MASK) >> MINIX_BOARD_VARIANT_SHIFT)
59

    
60
/* We want to make it possible to use masks and therefore only try to use bits */
61
#define MINIX_BOARD_ARCH_X86 MINIX_MK_BOARD_ARCH(1 << 0)
62
#define MINIX_BOARD_ARCH_ARM MINIX_MK_BOARD_ARCH(1 << 1)
63

    
64
#define MINIX_BOARD_ARCH_VARIANT_X86_GENERIC MINIX_MK_BOARD_ARCH_VARIANT(1<<0)
65
#define MINIX_BOARD_ARCH_VARIANT_ARM_ARMV6 MINIX_MK_BOARD_ARCH_VARIANT(1<<1)
66
#define MINIX_BOARD_ARCH_VARIANT_ARM_ARMV7 MINIX_MK_BOARD_ARCH_VARIANT(1<<2)
67

    
68
#define MINIX_BOARD_VENDOR_INTEL MINIX_MK_BOARD_VENDOR(1<<0)
69
#define MINIX_BOARD_VENDOR_TI MINIX_MK_BOARD_VENDOR(1<<1)
70

    
71
#define MINIX_BOARD_GENERIC MINIX_MK_BOARD(1<<0)
72
/* BeagleBoard XM */
73
#define MINIX_BOARD_BBXM MINIX_MK_BOARD(1<<1)
74
/* BeagleBone (Black and* white) */
75
#define MINIX_BOARD_BB MINIX_MK_BOARD(1<<2)
76

    
77
/* Only  one  of a kind */
78
#define MINIX_BOARD_VARIANT_GENERIC MINIX_MK_BOARD_VARIANT(1<<0)
79
/* BeagleBone White */
80
#define MINIX_BOARD_VARIANT_BBW MINIX_MK_BOARD_VARIANT(1<<1)
81
/* BeagleBone Black */
82
#define MINIX_BOARD_VARIANT_BBB MINIX_MK_BOARD_VARIANT(1<<2)
83

    
84
#define BOARD_ID_INTEL \
85
        ( MINIX_BOARD_ARCH_X86 \
86
        | MINIX_BOARD_ARCH_VARIANT_X86_GENERIC \
87
        | MINIX_BOARD_VENDOR_INTEL \
88
        | MINIX_BOARD_GENERIC \
89
        | MINIX_BOARD_VARIANT_GENERIC\
90
        )
91

    
92
#define BOARD_ID_BBXM \
93
        ( MINIX_BOARD_ARCH_ARM \
94
        | MINIX_BOARD_ARCH_VARIANT_ARM_ARMV7 \
95
        | MINIX_BOARD_VENDOR_TI \
96
        | MINIX_BOARD_BBXM \
97
        | MINIX_BOARD_VARIANT_GENERIC\
98
        )
99

    
100
#define BOARD_ID_BBW \
101
        ( MINIX_BOARD_ARCH_ARM \
102
        | MINIX_BOARD_ARCH_VARIANT_ARM_ARMV7 \
103
        | MINIX_BOARD_VENDOR_TI \
104
        | MINIX_BOARD_BB \
105
        | MINIX_BOARD_VARIANT_BBW\
106
        )
107

    
108
#define BOARD_ID_BBB \
109
        ( MINIX_BOARD_ARCH_ARM \
110
        | MINIX_BOARD_ARCH_VARIANT_ARM_ARMV7 \
111
        | MINIX_BOARD_VENDOR_TI \
112
        | MINIX_BOARD_BB \
113
        | MINIX_BOARD_VARIANT_BBB\
114
        )
115

    
116
#define BOARD_IS_BBXM(v) \
117
                ( (BOARD_ID_BBXM & ~MINIX_BOARD_VARIANT_MASK) == (v & ~MINIX_BOARD_VARIANT_MASK))
118
/* Either one of the known BeagleBones */
119
#define BOARD_IS_BB(v)   \
120
                ( (BOARD_ID_BBW & ~MINIX_BOARD_VARIANT_MASK) == (v & ~MINIX_BOARD_VARIANT_MASK))
121
#define BOARD_IS_BBW(v)  ( v == BOARD_ID_BBW)
122
#define BOARD_IS_BBB(v)  ( v == BOARD_ID_BBB)
123

    
124
#define BOARD_FILTER_BBXM_VALUE (BOARD_ID_BBXM)
125
#define BOARD_FILTER_BBXM_MASK  \
126
                (MINIX_BOARD_ARCH_MASK \
127
                | MINIX_BOARD_ARCH_VARIANT_MASK \
128
                | MINIX_BOARD_VENDOR_MASK \
129
                | MINIX_BOARD_MASK \
130
                | MINIX_BOARD_VARIANT_MASK)
131

    
132
#define BOARD_FILTER_BB_VALUE   (BOARD_ID_BBW & ~MINIX_BOARD_VARIANT_MASK)
133
#define BOARD_FILTER_BB_MASK    \
134
                (MINIX_BOARD_ARCH_MASK \
135
                | MINIX_BOARD_ARCH_VARIANT_MASK \
136
                | MINIX_BOARD_VENDOR_MASK \
137
                | MINIX_BOARD_MASK )
138

    
139
struct shortname2id
140
{
141
        const char name[15];
142
        unsigned int id;
143
};
144

    
145

    
146
/* mapping from fields given by the bootloader to board id's */
147
static struct shortname2id shortname2id[] = {
148
        {.name = "BBXM",.id = BOARD_ID_BBXM},
149
        {.name = "A335BONE",.id = BOARD_ID_BBW},
150
        {.name = "A335BNLT",.id = BOARD_ID_BBB},
151
};
152

    
153
struct board_id2name
154
{
155
        unsigned int id;
156
        const char name[40];
157
};
158

    
159
/* how to convert a BOARD id to a board name */
160
static struct board_id2name board_id2name[] = {
161
        {.id = BOARD_ID_INTEL,.name = "X86-I586-GENERIC-GENERIC-GENERIC"},
162
        {.id = BOARD_ID_BBXM,.name = "ARM-ARMV7-TI-BBXM-GENERIC"},
163
        {.id = BOARD_ID_BBW,.name = "ARM-ARMV7-TI-BB-WHITE"},
164
        {.id = BOARD_ID_BBB,.name = "ARM-ARMV7-TI-BB-BLACK"},
165
};
166

    
167
struct board_arch2arch
168
{
169
        unsigned int board_arch;
170
        const char arch[40];
171
};
172
/* Mapping from board_arch to arch */
173
static struct board_arch2arch board_arch2arch[] = {
174
        {.board_arch = MINIX_BOARD_ARCH_ARM ,.arch = "earm"},
175
        {.board_arch = MINIX_BOARD_ARCH_X86 ,.arch = "i386"},
176
};
177

    
178
/* returns 0 if no board was found that match that id */
179
static int
180
get_board_id_by_short_name(const char *name)
181
{
182
        int x;
183
        for (x = 0; x < sizeof(shortname2id) / sizeof(shortname2id[0]); x++) {
184
                if (strncmp(name, shortname2id[x].name, 15) == 0) {
185
                        return shortname2id[x].id;
186
                }
187
        }
188
        return 0;
189
}
190

    
191
/* returns 0 if no board was found that match that id */
192
static int
193
get_board_id_by_name(const char *name)
194
{
195
        int x;
196
        for (x = 0; x < sizeof(board_id2name) / sizeof(board_id2name[0]); x++) {
197
                if (strncmp(name, board_id2name[x].name, 40) == 0) {
198
                        return board_id2name[x].id;
199
                }
200
        }
201
        return 0;
202
}
203

    
204
/* convert a board id to a board name to use later 
205
   returns NULL if no board was found that match that id */
206
static const char *
207
get_board_name(unsigned int id)
208
{
209
        int x;
210
        for (x = 0; x < sizeof(board_id2name) / sizeof(board_id2name[0]); x++) {
211
                if (board_id2name[x].id == id) {
212
                        return board_id2name[x].name;
213
                }
214
        }
215
        return NULL;
216
}
217

    
218
/* convert a board id to a board name to use later 
219
   returns NULL if no board was found that match that id */
220
static const char *
221
get_board_arch_name(unsigned int id)
222
{
223
        int x;
224
        for (x = 0; x < sizeof(board_arch2arch) / sizeof(board_arch2arch[0]); x++) {
225
                if (board_arch2arch[x].board_arch == (id & MINIX_BOARD_ARCH_MASK) ) {
226
                        return board_arch2arch[x].arch;
227
                }
228
        }
229
        return NULL;
230
}
231

    
232
#endif