arm:add board_id to machine to enable runtime configuration.

Modified the machine struct in include/minix/type.h to have an
additional field called board_id. This fields can be read out
by userland and drivers at runtime to enable automatic
configuration. The board_id field contains information about
the hardware architecture / board and such.

Change-Id: Ib12bc0d43fc9dbdb80ee0751c721ee516de1d2d6
This commit is contained in:
Kees Jongenburger 2013-11-29 14:19:42 +01:00
parent d1c3755dd4
commit 4127817d7b
6 changed files with 209 additions and 1 deletions

View file

@ -1150,6 +1150,7 @@
./usr/include/minix/acpi.h minix-sys
./usr/include/minix/audio_fw.h minix-sys
./usr/include/minix/bdev.h minix-sys
./usr/include/minix/board.h minix-sys
./usr/include/minix/bitmap.h minix-sys
./usr/include/minix/blockdriver.h minix-sys
./usr/include/minix/blockdriver_mt.h minix-sys

View file

@ -5,7 +5,7 @@ INCSDIR= /usr/include/minix
INCS+= dirent.h paths.h param.h
INCS+= acpi.h audio_fw.h bitmap.h \
bdev.h blockdriver.h blockdriver_mt.h \
btrace.h \
board.h btrace.h \
callnr.h chardriver.h clkconf.h com.h \
config.h const.h cpufeature.h \
debug.h devio.h devman.h dmap.h \

193
include/minix/board.h Normal file
View file

@ -0,0 +1,193 @@
#ifndef __BOARD_H__
#define __BOARD_H__
#include <string.h>
/*
Utility functions to access/parse the board_id defined in the machine
struct in include/minix/type.h.
Identifier for the board
[31:28] Architecture. (MINIX_BOARD_ARCH)
[27:24] Architecture variant (MINIX_BOARD_ARCH_VARIANT) VERSION e.g. ARMV7
[23:16] Vendor/Soc (EG TI ) (MINIX_BOARD_VENDOR)
[15:8] Board (EG Beagle bone , beagle board ) (MINIX_BOARD)
[7:0] Board variant (EG BealgeBone white v.s. BeagleBone black ) (MINIX_BOARD_VARIANT)
*/
#define MINIX_BOARD_ARCH_SHIFT (28)
#define MINIX_BOARD_ARCH_VARIANT_SHIFT (24)
#define MINIX_BOARD_VENDOR_SHIFT (16)
#define MINIX_BOARD_SHIFT (8)
#define MINIX_BOARD_VARIANT_SHIFT (0)
/* 8 bits */
#define MINIX_BOARD_ARCH_MASK \
(0XFF << MINIX_BOARD_ARCH_SHIFT)
/* 4 bits */
#define MINIX_BOARD_ARCH_VARIANT_MASK \
(0XF << MINIX_BOARD_ARCH_VARIANT_SHIFT)
/* 8 bits */
#define MINIX_BOARD_VENDOR_MASK \
(0XFF << MINIX_BOARD_VENDOR_SHIFT)
/* 8 bits */
#define MINIX_BOARD_MASK \
(0XFF << MINIX_BOARD_SHIFT)
/* 8 bits */
#define MINIX_BOARD_VARIANT_MASK \
(0XFF << MINIX_BOARD_VARIANT_SHIFT)
#define MINIX_MK_BOARD_ARCH(v) \
((v << MINIX_BOARD_ARCH_SHIFT ) & MINIX_BOARD_ARCH_MASK)
#define MINIX_MK_BOARD_ARCH_VARIANT(v) \
(( v << MINIX_BOARD_ARCH_VARIANT_SHIFT) & MINIX_BOARD_ARCH_VARIANT_MASK )
#define MINIX_MK_BOARD_VENDOR(v) \
(( v << MINIX_BOARD_VENDOR_SHIFT) & MINIX_BOARD_VENDOR_MASK )
#define MINIX_MK_BOARD(v) \
(( v << MINIX_BOARD_SHIFT) & MINIX_BOARD_MASK )
#define MINIX_MK_BOARD_VARIANT(v) \
(( v << MINIX_BOARD_VARIANT_SHIFT) & MINIX_BOARD_VARIANT_MASK )
#define MINIX_BOARD_ARCH(v) \
((v & MINIX_BOARD_ARCH_MASK) >> MINIX_BOARD_ARCH_SHIFT )
#define MINIX_BOARD_ARCH_VARIANT(v) \
(( v & MINIX_BOARD_ARCH_VARIANT_MASK) >> MINIX_BOARD_ARCH_VARIANT_SHIFT)
#define MINIX_BOARD_VENDOR(v) \
(( v & MINIX_BOARD_VENDOR_MASK) >> MINIX_BOARD_VENDOR_SHIFT)
#define MINIX_BOARD(v) \
(( v & MINIX_BOARD_MASK) >> MINIX_BOARD_SHIFT)
#define MINIX_BOARD_VARIANT(v) \
(( v & MINIX_BOARD_VARIANT_MASK) >> MINIX_BOARD_VARIANT_SHIFT)
/* We want to make it possible to use masks and therefore only try to use bits */
#define MINIX_BOARD_ARCH_X86 MINIX_MK_BOARD_ARCH(1 << 0)
#define MINIX_BOARD_ARCH_ARM MINIX_MK_BOARD_ARCH(1 << 1)
#define MINIX_BOARD_ARCH_VARIANT_X86_GENERIC MINIX_MK_BOARD_ARCH_VARIANT(1<<0)
#define MINIX_BOARD_ARCH_VARIANT_ARM_ARMV6 MINIX_MK_BOARD_ARCH_VARIANT(1<<1)
#define MINIX_BOARD_ARCH_VARIANT_ARM_ARMV7 MINIX_MK_BOARD_ARCH_VARIANT(1<<2)
#define MINIX_BOARD_VENDOR_INTEL MINIX_MK_BOARD_VENDOR(1<<0)
#define MINIX_BOARD_VENDOR_TI MINIX_MK_BOARD_VENDOR(1<<1)
#define MINIX_BOARD_GENERIC MINIX_MK_BOARD(1<<0)
/* BeagleBoard XM */
#define MINIX_BOARD_BBXM MINIX_MK_BOARD(1<<1)
/* BeagleBone (Black and* white) */
#define MINIX_BOARD_BB MINIX_MK_BOARD(1<<2)
/* Only one of a kind */
#define MINIX_BOARD_VARIANT_GENERIC MINIX_MK_BOARD_VARIANT(1<<0)
/* BeagleBone White */
#define MINIX_BOARD_VARIANT_BBW MINIX_MK_BOARD_VARIANT(1<<1)
/* BeagleBone Black */
#define MINIX_BOARD_VARIANT_BBB MINIX_MK_BOARD_VARIANT(1<<2)
#define BOARD_ID_INTEL \
( MINIX_BOARD_ARCH_X86 \
| MINIX_BOARD_ARCH_VARIANT_X86_GENERIC \
| MINIX_BOARD_VENDOR_INTEL \
| MINIX_BOARD_GENERIC \
| MINIX_BOARD_VARIANT_GENERIC\
)
#define BOARD_ID_BBXM \
( MINIX_BOARD_ARCH_ARM \
| MINIX_BOARD_ARCH_VARIANT_ARM_ARMV7 \
| MINIX_BOARD_VENDOR_TI \
| MINIX_BOARD_BBXM \
| MINIX_BOARD_VARIANT_GENERIC\
)
#define BOARD_ID_BBW \
( MINIX_BOARD_ARCH_ARM \
| MINIX_BOARD_ARCH_VARIANT_ARM_ARMV7 \
| MINIX_BOARD_VENDOR_TI \
| MINIX_BOARD_BB \
| MINIX_BOARD_VARIANT_BBW\
)
#define BOARD_ID_BBB \
( MINIX_BOARD_ARCH_ARM \
| MINIX_BOARD_ARCH_VARIANT_ARM_ARMV7 \
| MINIX_BOARD_VENDOR_TI \
| MINIX_BOARD_BB \
| MINIX_BOARD_VARIANT_BBB\
)
#define BOARD_IS_BBXM(v) \
( (BOARD_ID_BBXM & ~MINIX_BOARD_VARIANT_MASK) == (v & ~MINIX_BOARD_VARIANT_MASK))
/* Either one of the known BeagleBones */
#define BOARD_IS_BB(v) \
( (BOARD_ID_BBW & ~MINIX_BOARD_VARIANT_MASK) == (v & ~MINIX_BOARD_VARIANT_MASK))
#define BOARD_IS_BBW(v) ( v == BOARD_ID_BBW)
#define BOARD_IS_BBB(v) ( v == BOARD_ID_BBB)
#define BOARD_FILTER_BBXM_VALUE (BOARD_ID_BBXM)
#define BOARD_FILTER_BBXM_MASK \
(MINIX_BOARD_ARCH_MASK \
| MINIX_BOARD_ARCH_VARIANT_MASK \
| MINIX_BOARD_VENDOR_MASK \
| MINIX_BOARD_MASK \
| MINIX_BOARD_VARIANT_MASK)
#define BOARD_FILTER_BB_VALUE (BOARD_ID_BBW & ~MINIX_BOARD_VARIANT_MASK)
#define BOARD_FILTER_BB_MASK \
(MINIX_BOARD_ARCH_MASK \
| MINIX_BOARD_ARCH_VARIANT_MASK \
| MINIX_BOARD_VENDOR_MASK \
| MINIX_BOARD_MASK )
struct shortname2id
{
const char name[15];
unsigned int id;
};
/* mapping from fields given by the bootloader to board id's */
static struct shortname2id shortname2id[] = {
{.name = "BBXM",.id = BOARD_ID_BBXM},
{.name = "A335BONE",.id = BOARD_ID_BBW},
{.name = "BBB",.id = BOARD_ID_BBB},
};
struct board_id2name
{
unsigned int id;
const char name[40];
};
/* how to convert a BOARD id to a board name */
static struct board_id2name board_id2name[] = {
{.id = BOARD_ID_INTEL,.name = "X86-I586-GENERIC-GENERIC-GENERIC"},
{.id = BOARD_ID_BBXM,.name = "ARM-ARMV7-TI-BBXM-GENERIC"},
{.id = BOARD_ID_BBW,.name = "ARM-ARMV7-TI-BB-WHITE"},
{.id = BOARD_ID_BBB,.name = "ARM-ARMV7-TI-BB-BLACK"},
};
/* returns 0 if no board was found that match that id */
static int
get_board_id_by_short_name(const char *name)
{
int x;
for (x = 0; x < sizeof(shortname2id) / sizeof(shortname2id[0]); x++) {
if (strncmp(name, shortname2id[x].name, 15) == 0) {
return shortname2id[x].id;
}
}
return 0;
}
/* convert a board id to a board name to use later
returns NULL if no board was found that match that id */
static const char *
get_board_name(unsigned int id)
{
int x;
for (x = 0; x < sizeof(board_id2name) / sizeof(board_id2name[0]); x++) {
if (board_id2name[x].id == id) {
return board_id2name[x].name;
}
}
return NULL;
}
#endif

View file

@ -146,6 +146,7 @@
#define SERVARNAME "cttyline"
#define ARCHVARNAME "arch"
#define BOARDVARNAME "board"
#define SERBAUDVARNAME "cttybaud"
/* Bits for s_flags in the privilege structure. */

View file

@ -94,6 +94,9 @@ struct machine {
int padding; /* used to be protected */
int apic_enabled; /* does the kernel use APIC or not? */
phys_bytes acpi_rsdp; /* where is the acpi RSDP */
unsigned int board_id; /* Identifier for the board see */
/* include/minix/board.h for more */
/* information. */
};
struct io_range

View file

@ -16,6 +16,7 @@
#include <minix/endpoint.h>
#include <machine/vmparam.h>
#include <minix/u64.h>
#include <minix/board.h>
#include <minix/type.h>
#include <minix/reboot.h>
#include "clock.h"
@ -104,6 +105,7 @@ void bsp_finish_booting(void)
machine.bsp_id = 0;
#endif
/* Kernel may no longer use bits of memory as VM will be running soon */
kernel_may_alloc = 0;
@ -129,6 +131,14 @@ void kmain(kinfo_t *local_cbi)
memcpy(&kinfo, local_cbi, sizeof(kinfo));
memcpy(&kmess, kinfo.kmess, sizeof(kmess));
/* The following will be replaced with code getting this information from the
bootloader */
#ifdef DM37XX
machine.board_id = BOARD_ID_BBXM;
#endif
#ifdef AM335X
machine.board_id = BOARD_ID_BBW;
#endif
#ifdef __arm__
/* We want to initialize serial before we do any output */
omap3_ser_init();