diff --git a/distrib/sets/lists/minix/mi b/distrib/sets/lists/minix/mi index 7c83dfe9f..62c5dc3e9 100644 --- a/distrib/sets/lists/minix/mi +++ b/distrib/sets/lists/minix/mi @@ -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 diff --git a/include/minix/Makefile b/include/minix/Makefile index bf2cdd730..b8a3273bc 100644 --- a/include/minix/Makefile +++ b/include/minix/Makefile @@ -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 \ diff --git a/include/minix/board.h b/include/minix/board.h new file mode 100644 index 000000000..143859e1e --- /dev/null +++ b/include/minix/board.h @@ -0,0 +1,193 @@ +#ifndef __BOARD_H__ +#define __BOARD_H__ +#include +/* + 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 diff --git a/include/minix/const.h b/include/minix/const.h index 2c9a2ec94..a713e0549 100644 --- a/include/minix/const.h +++ b/include/minix/const.h @@ -146,6 +146,7 @@ #define SERVARNAME "cttyline" #define ARCHVARNAME "arch" +#define BOARDVARNAME "board" #define SERBAUDVARNAME "cttybaud" /* Bits for s_flags in the privilege structure. */ diff --git a/include/minix/type.h b/include/minix/type.h index b6ed40d44..2e415b84b 100644 --- a/include/minix/type.h +++ b/include/minix/type.h @@ -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 diff --git a/kernel/main.c b/kernel/main.c index 83da02c6b..9978b5b51 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include "clock.h" @@ -103,6 +104,7 @@ void bsp_finish_booting(void) machine.processors_count = 1; 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();