Initial cleanup of the linuxbios tables code. Now it seems we need

resource .c functions -- sigh -- this will be next. 

fix types, fix some usage, but we do not yet generate pirqi, mptables,
or acpi. This will be next. 

This code will be called from phase6 in stage 2, and probably 
attached to a cpu. Or, it will be inline in the stage2.c code, since 
the need for tables is generic. 

I'm also going to move the cryptic usage of lgdt from here to stage 2,
phase 2, of the cpu code. The device model improvements are making it
easier to think about when things happen, we are finding. 

I'm going to get lunch and go see some of brussels. It's a miserable day
but ... 

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Acked-by: Ronald G. Minnich <rminnich@gmail.com>
Acked-by: Stefan Reinauer <stepan@coresystems.de>




git-svn-id: svn://coreboot.org/repository/LinuxBIOSv3@130 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
Ronald G. Minnich 2007-02-26 11:45:51 +00:00
commit 4282d12cdc
5 changed files with 109 additions and 93 deletions

View file

@ -119,7 +119,7 @@ $(obj)/linuxbios.stage2: $(obj)/stage0.init $(obj)/statictree.o
$(Q)echo -n "Building linuxbios.stage2... "
$(Q)# main
$(Q)$(CC) $(INITCFLAGS) -c $(src)/arch/x86/archtables.c -o $(obj)/archtables.o
$(Q)$(CC) $(INITCFLAGS) -c $(src)/arch/x86/linuxbios_tables.c -o $(obj)/linuxbios_tables.o
$(Q)$(CC) $(INITCFLAGS) -c $(src)/arch/x86/linuxbios_table.c -o $(obj)/linuxbios_table.o
$(Q)$(CC) $(INITCFLAGS) -c $(src)/device/device.c -o $(obj)/device.o
$(Q)$(CC) $(INITCFLAGS) -c $(src)/device/device_util.c -o $(obj)/device_util.o
$(Q)$(CC) $(INITCFLAGS) -c $(src)/device/root_device.c -o $(obj)/root_device.o
@ -134,7 +134,7 @@ $(obj)/linuxbios.stage2: $(obj)/stage0.init $(obj)/statictree.o
$(Q)# leave a .o with full symbols in it for debugging.
$(Q)cd $(obj); $(LD) -R $(obj)/stage0.o -Ttext 0x1000 \
--entry=stage2 -o $(obj)/linuxbios.stage2.o \
archtables.o linuxbios_tables.o device.o device_util.o root_device.o \
archtables.o linuxbios_table.o device.o device_util.o root_device.o \
clog2.o mem.o malloc.o mainboard.o stage2.o tables.o\
statictree.o
$(Q)objcopy -O binary $(obj)/linuxbios.stage2.o $(obj)/linuxbios.stage2

View file

@ -22,6 +22,7 @@
/* 2006.1 yhlu add mptable cross 0x467 processing */
#include <console/console.h>
#include <string.h>
//#include <cpu/cpu.h>
//#include <boot/tables.h>
//#include <boot/linuxbios_tables.h>
@ -31,8 +32,8 @@
#include <tables.h>
// Global Descriptor Table, defined in c_start.S
extern uint8_t gdt;
extern uint8_t gdt_end;
extern u8 gdt;
extern u8 gdt_end;
/* i386 lgdt argument */
struct gdtarg {
@ -45,15 +46,15 @@ struct gdtarg {
// Ported from Etherboot to LinuxBIOS 2005-08 by Steve Magnani
void move_gdt(unsigned long newgdt)
{
uint16_t num_gdt_bytes = &gdt_end - &gdt;
u16 num_gdt_bytes = &gdt_end - &gdt;
struct gdtarg gdtarg;
printk_debug("Moving GDT to %#lx...", newgdt);
printk(BIOS_DEBUG,"Moving GDT to %#lx...", newgdt);
memcpy((void*)newgdt, &gdt, num_gdt_bytes);
gdtarg.base = newgdt;
gdtarg.limit = num_gdt_bytes - 1;
__asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg));
printk_debug("ok\n");
printk(BIOS_DEBUG,"ok\n");
}
struct lb_memory *write_tables(void)
@ -72,23 +73,23 @@ struct lb_memory *write_tables(void)
post_code(0x9a);
/* This table must be betweeen 0xf0000 & 0x100000 */
rom_table_end = write_pirq_routing_table(rom_table_end);
rom_table_end = (rom_table_end + 1023) & ~1023;
// rom_table_end = write_pirq_routing_table(rom_table_end);
// rom_table_end = (rom_table_end + 1023) & ~1023;
/* Write ACPI tables */
/* write them in the rom area because DSDT can be large (8K on epia-m) which
* pushes linuxbios table out of first 4K if set up in low table area
*/
rom_table_end = write_acpi_tables(rom_table_end);
rom_table_end = (rom_table_end+1023) & ~1023;
// rom_table_end = write_acpi_tables(rom_table_end);
// rom_table_end = (rom_table_end+1023) & ~1023;
/* copy the smp block to address 0 */
post_code(0x96);
/* The smp table must be in 0-1K, 639K-640K, or 960K-1M */
new_low_table_end = write_smp_table(low_table_end);
// new_low_table_end = write_smp_table(low_table_end);
#if 0
#if HAVE_MP_TABLE==1
/* Don't write anything in the traditional x86 BIOS data segment,
* for example the linux kernel smp need to use 0x467 to pass reset vector
@ -98,7 +99,7 @@ struct lb_memory *write_tables(void)
/* We can not put mptable here, we need to copy them to somewhere else*/
if((rom_table_end+mptable_size)<0x100000) {
/* We can copy mptable on rom_table, and leave low space for lbtable */
printk_debug("move mptable to 0x%0x\n", rom_table_end);
printk(BIOS_DEBUG,"move mptable to 0x%0x\n", rom_table_end);
memcpy((unsigned char *)rom_table_end, (unsigned char *)(low_table_end+SMP_FLOATING_TABLE_LEN), mptable_size);
memset((unsigned char *)low_table_end, '\0', mptable_size + SMP_FLOATING_TABLE_LEN);
smp_write_floating_table_physaddr(low_table_end, rom_table_end);
@ -107,7 +108,7 @@ struct lb_memory *write_tables(void)
rom_table_end = (rom_table_end+1023) & ~1023;
} else {
/* We can need to put mptable low and from 0x500 */
printk_debug("move mptable to 0x%0x\n", 0x500);
printk(BIOS_DEBUG,"move mptable to 0x%0x\n", 0x500);
memcpy((unsigned char *)0x500, (unsigned char *)(low_table_end+SMP_FLOATING_TABLE_LEN), mptable_size);
memset((unsigned char *)low_table_end, '\0', 0x500-low_table_end);
smp_write_floating_table_physaddr(low_table_end, 0x500);
@ -115,6 +116,7 @@ struct lb_memory *write_tables(void)
}
}
#endif
#endif
/* Don't write anything in the traditional x86 BIOS data segment */
if (low_table_end < 0x500) {

View file

@ -21,11 +21,15 @@
#include <console/console.h>
//#include <ip_checksum.h>
#include <tables.h>
#include <string.h>
#include <version.h>
#include <device/device.h>
#include <stdlib.h>
//#include <cpu/cpu.h>
//#include <boot/tables.h>
//#include <boot/linuxbios_tables.h>
//#include <arch/pirq_routing.h>
//#include <arch/smp/mpspec.h>
//#include <arch/acpi.h>
#include <tables.h>
struct lb_header *lb_table_init(unsigned long addr)
{
@ -98,6 +102,7 @@ struct lb_mainboard *lb_mainboard(struct lb_header *header)
{
struct lb_record *rec;
struct lb_mainboard *mainboard;
extern char *mainboard_vendor, *mainboard_part_number;
rec = lb_new_record(header);
mainboard = (struct lb_mainboard *)rec;
mainboard->tag = LB_TAG_MAINBOARD;
@ -127,21 +132,25 @@ struct cmos_checksum *lb_cmos_checksum(struct lb_header *header)
cmos_checksum->tag = LB_TAG_OPTION_CHECKSUM;
cmos_checksum->size = (sizeof(*cmos_checksum));
/*
cmos_checksum->range_start = LB_CKS_RANGE_START * 8;
cmos_checksum->range_end = ( LB_CKS_RANGE_END * 8 ) + 7;
cmos_checksum->location = LB_CKS_LOC * 8;
cmos_checksum->type = CHECKSUM_PCBIOS;
*/
#warning "Fix up LBCKSUM in linuxbios_table.c"
return cmos_checksum;
}
void lb_strings(struct lb_header *header)
{
#warning "Fill in the strings in lb_strings -- needs Makefile changes"
static const struct {
uint32_t tag;
const uint8_t *string;
u32 tag;
const u8 *string;
} strings[] = {
{ LB_TAG_VERSION, "3 -- FIXME", },
/*
{ LB_TAG_VERSION, linuxbios_version, },
{ LB_TAG_EXTRA_VERSION, linuxbios_extra_version, },
{ LB_TAG_BUILD, linuxbios_build, },
@ -152,6 +161,7 @@ void lb_strings(struct lb_header *header)
{ LB_TAG_COMPILER, linuxbios_compiler, },
{ LB_TAG_LINKER, linuxbios_linker, },
{ LB_TAG_ASSEMBLER, linuxbios_assembler, },
*/
};
unsigned int i;
for(i = 0; i < sizeof(strings)/sizeof(strings[0]); i++) {
@ -167,7 +177,7 @@ void lb_strings(struct lb_header *header)
}
void lb_memory_range(struct lb_memory *mem,
uint32_t type, uint64_t start, uint64_t size)
u32 type, u64 start, u64 size)
{
int entries;
entries = (mem->size - sizeof(*mem))/sizeof(mem->map[0]);
@ -181,8 +191,8 @@ static void lb_reserve_table_memory(struct lb_header *head)
{
struct lb_record *last_rec;
struct lb_memory *mem;
uint64_t start;
uint64_t end;
u64 start;
u64 end;
int i, entries;
last_rec = lb_last_record(head);
@ -195,8 +205,8 @@ static void lb_reserve_table_memory(struct lb_header *head)
* setup so that is all we need to do.
*/
for(i = 0; i < entries; i++ ) {
uint64_t map_start = unpack_lb64(mem->map[i].start);
uint64_t map_end = map_start + unpack_lb64(mem->map[i].size);
u64 map_start = unpack_lb64(mem->map[i].start);
u64 map_end = map_start + unpack_lb64(mem->map[i].size);
/* Does this area need to be expanded? */
if (map_end == start) {
mem->map[i].size = pack_lb64(end - map_start);
@ -221,7 +231,7 @@ unsigned long lb_table_fini(struct lb_header *head)
head->table_checksum = 0; //compute_ip_checksum(first_rec, head->table_bytes);
head->header_checksum = 0;
head->header_checksum = 0; //compute_ip_checksum(head, sizeof(*head));
printk_debug("Wrote linuxbios table at: %p - %p checksum %lx\n",
printk(BIOS_DEBUG,"Wrote linuxbios table at: %p - %p checksum %lx\n",
head, rec, head->table_checksum);
return (unsigned long)rec;
}
@ -234,9 +244,9 @@ static void lb_cleanup_memory_ranges(struct lb_memory *mem)
/* Sort the lb memory ranges */
for(i = 0; i < entries; i++) {
uint64_t entry_start = unpack_lb64(mem->map[i].start);
u64 entry_start = unpack_lb64(mem->map[i].start);
for(j = i; j < entries; j++) {
uint64_t temp_start = unpack_lb64(mem->map[j].start);
u64 temp_start = unpack_lb64(mem->map[j].start);
if (temp_start < entry_start) {
struct lb_memory_range tmp;
tmp = mem->map[i];
@ -248,7 +258,7 @@ static void lb_cleanup_memory_ranges(struct lb_memory *mem)
/* Merge adjacent entries */
for(i = 0; (i + 1) < entries; i++) {
uint64_t start, end, nstart, nend;
u64 start, end, nstart, nend;
if (mem->map[i].type != mem->map[i + 1].type) {
continue;
}
@ -279,9 +289,9 @@ static void lb_cleanup_memory_ranges(struct lb_memory *mem)
}
static void lb_remove_memory_range(struct lb_memory *mem,
uint64_t start, uint64_t size)
u64 start, u64 size)
{
uint64_t end;
u64 end;
int entries;
int i;
@ -290,8 +300,8 @@ static void lb_remove_memory_range(struct lb_memory *mem,
/* Remove a reserved area from the memory map */
for(i = 0; i < entries; i++) {
uint64_t map_start = unpack_lb64(mem->map[i].start);
uint64_t map_end = map_start + unpack_lb64(mem->map[i].size);
u64 map_start = unpack_lb64(mem->map[i].start);
u64 map_end = map_start + unpack_lb64(mem->map[i].size);
if ((start <= map_start) && (end >= map_end)) {
/* Remove the completely covered range */
memmove(&mem->map[i], &mem->map[i + 1],
@ -328,7 +338,7 @@ static void lb_remove_memory_range(struct lb_memory *mem,
}
static void lb_add_memory_range(struct lb_memory *mem,
uint32_t type, uint64_t start, uint64_t size)
u32 type, u64 start, u64 size)
{
lb_remove_memory_range(mem, start, size);
lb_memory_range(mem, type, start, size);
@ -384,7 +394,7 @@ unsigned long write_linuxbios_table(
head = lb_table_init(low_table_end);
low_table_end = (unsigned long)head;
}
#if 0
if (HAVE_OPTION_TABLE == 1) {
struct lb_record *rec_dest, *rec_src;
/* Write the option config table... */
@ -394,6 +404,7 @@ unsigned long write_linuxbios_table(
/* Create cmos checksum entry in linuxbios table */
lb_cmos_checksum(head);
}
#endif
/* Record where RAM is located */
mem = build_lb_mem(head);

View file

@ -56,7 +56,7 @@ struct lb_memory *write_tables(void);
/* Since LinuxBIOS is usually compiled 32bit, gcc will align 64bit
* types to 32bit boundaries. If the LinuxBIOS table is dumped on a
* 64bit system, a uint64_t would be aligned to 64bit boundaries,
* 64bit system, a u64 would be aligned to 64bit boundaries,
* breaking the table format.
*
* lb_uint64 will keep 64bit LinuxBIOS table values aligned to 32bit
@ -67,19 +67,19 @@ struct lb_memory *write_tables(void);
*/
struct lb_uint64 {
uint32_t lo;
uint32_t hi;
u32 lo;
u32 hi;
};
static inline uint64_t unpack_lb64(struct lb_uint64 value)
static inline u64 unpack_lb64(struct lb_uint64 value)
{
uint64_t result;
u64 result;
result = value.hi;
result = (result << 32) + value.lo;
return result;
}
static inline struct lb_uint64 pack_lb64(uint64_t value)
static inline struct lb_uint64 pack_lb64(u64 value)
{
struct lb_uint64 result;
result.lo = (value >> 0) & 0xffffffff;
@ -91,12 +91,12 @@ static inline struct lb_uint64 pack_lb64(uint64_t value)
struct lb_header
{
uint8_t signature[4]; /* LBIO */
uint32_t header_bytes;
uint32_t header_checksum;
uint32_t table_bytes;
uint32_t table_checksum;
uint32_t table_entries;
u8 signature[4]; /* LBIO */
u32 header_bytes;
u32 header_checksum;
u32 table_bytes;
u32 table_checksum;
u32 table_entries;
};
/* Every entry in the boot enviroment list will correspond to a boot
@ -106,8 +106,8 @@ struct lb_header
* forward compatibility with records not yet defined.
*/
struct lb_record {
uint32_t tag; /* tag ID */
uint32_t size; /* size of record (in bytes) */
u32 tag; /* tag ID */
u32 size; /* size of record (in bytes) */
};
#define LB_TAG_UNUSED 0x0000
@ -117,32 +117,32 @@ struct lb_record {
struct lb_memory_range {
struct lb_uint64 start;
struct lb_uint64 size;
uint32_t type;
u32 type;
#define LB_MEM_RAM 1 /* Memory anyone can use */
#define LB_MEM_RESERVED 2 /* Don't use this memory region */
#define LB_MEM_TABLE 16 /* Ram configuration tables are kept in */
};
struct lb_memory {
uint32_t tag;
uint32_t size;
u32 tag;
u32 size;
struct lb_memory_range map[0];
};
#define LB_TAG_HWRPB 0x0002
struct lb_hwrpb {
uint32_t tag;
uint32_t size;
uint64_t hwrpb;
u32 tag;
u32 size;
u64 hwrpb;
};
#define LB_TAG_MAINBOARD 0x0003
struct lb_mainboard {
uint32_t tag;
uint32_t size;
uint8_t vendor_idx;
uint8_t part_number_idx;
uint8_t strings[0];
u32 tag;
u32 size;
u8 vendor_idx;
u8 part_number_idx;
u8 strings[0];
};
#define LB_TAG_VERSION 0x0004
@ -156,18 +156,18 @@ struct lb_mainboard {
#define LB_TAG_LINKER 0x000c
#define LB_TAG_ASSEMBLER 0x000d
struct lb_string {
uint32_t tag;
uint32_t size;
uint8_t string[0];
u32 tag;
u32 size;
u8 string[0];
};
/* The following structures are for the cmos definitions table */
#define LB_TAG_CMOS_OPTION_TABLE 200
/* cmos header record */
struct cmos_option_table {
uint32_t tag; /* CMOS definitions table type */
uint32_t size; /* size of the entire table */
uint32_t header_length; /* length of header */
u32 tag; /* CMOS definitions table type */
u32 size; /* size of the entire table */
u32 header_length; /* length of header */
};
/* cmos entry record
@ -179,14 +179,14 @@ struct cmos_option_table {
*/
#define LB_TAG_OPTION 201
struct cmos_entries {
uint32_t tag; /* entry type */
uint32_t size; /* length of this record */
uint32_t bit; /* starting bit from start of image */
uint32_t length; /* length of field in bits */
uint32_t config; /* e=enumeration, h=hex, r=reserved */
uint32_t config_id; /* a number linking to an enumeration record */
u32 tag; /* entry type */
u32 size; /* length of this record */
u32 bit; /* starting bit from start of image */
u32 length; /* length of field in bits */
u32 config; /* e=enumeration, h=hex, r=reserved */
u32 config_id; /* a number linking to an enumeration record */
#define CMOS_MAX_NAME_LENGTH 32
uint8_t name[CMOS_MAX_NAME_LENGTH]; /* name of entry in ascii,
u8 name[CMOS_MAX_NAME_LENGTH]; /* name of entry in ascii,
variable length int aligned */
};
@ -197,12 +197,12 @@ struct cmos_entries {
*/
#define LB_TAG_OPTION_ENUM 202
struct cmos_enums {
uint32_t tag; /* enumeration type */
uint32_t size; /* length of this record */
uint32_t config_id; /* a number identifying the config id */
uint32_t value; /* the value associated with the text */
u32 tag; /* enumeration type */
u32 size; /* length of this record */
u32 config_id; /* a number identifying the config id */
u32 value; /* the value associated with the text */
#define CMOS_MAX_TEXT_LENGTH 32
uint8_t text[CMOS_MAX_TEXT_LENGTH]; /* enum description in ascii,
u8 text[CMOS_MAX_TEXT_LENGTH]; /* enum description in ascii,
variable length int aligned */
};
@ -211,25 +211,25 @@ struct cmos_enums {
*/
#define LB_TAG_OPTION_DEFAULTS 203
struct cmos_defaults {
uint32_t tag; /* default type */
uint32_t size; /* length of this record */
uint32_t name_length; /* length of the following name field */
uint8_t name[CMOS_MAX_NAME_LENGTH]; /* name identifying the default */
u32 tag; /* default type */
u32 size; /* length of this record */
u32 name_length; /* length of the following name field */
u8 name[CMOS_MAX_NAME_LENGTH]; /* name identifying the default */
#define CMOS_IMAGE_BUFFER_SIZE 128
uint8_t default_set[CMOS_IMAGE_BUFFER_SIZE]; /* default settings */
u8 default_set[CMOS_IMAGE_BUFFER_SIZE]; /* default settings */
};
#define LB_TAG_OPTION_CHECKSUM 204
struct cmos_checksum {
uint32_t tag;
uint32_t size;
u32 tag;
u32 size;
/* In practice everything is byte aligned, but things are measured
* in bits to be consistent.
*/
uint32_t range_start; /* First bit that is checksummed (byte aligned) */
uint32_t range_end; /* Last bit that is checksummed (byte aligned) */
uint32_t location; /* First bit of the checksum (byte aligned) */
uint32_t type; /* Checksum algorithm that is used */
u32 range_start; /* First bit that is checksummed (byte aligned) */
u32 range_end; /* Last bit that is checksummed (byte aligned) */
u32 location; /* First bit of the checksum (byte aligned) */
u32 type; /* Checksum algorithm that is used */
#define CHECKSUM_NONE 0
#define CHECKSUM_PCBIOS 1
};
@ -245,7 +245,7 @@ struct lb_record *lb_next_record(struct lb_record *rec);
struct lb_record *lb_new_record(struct lb_header *header);
struct lb_memory *lb_memory(struct lb_header *header);
void lb_memory_range(struct lb_memory *mem,
uint32_t type, uint64_t start, uint64_t size);
u32 type, u64 start, u64 size);
struct lb_mainboard *lb_mainboard(struct lb_header *header);
unsigned long lb_table_fini(struct lb_header *header);

View file

@ -22,6 +22,9 @@
#include <arch/types.h>
// #include "dtc.h"
char *mainboard_vendor = "emulation";
char *mainboard_part_number = "qemu-x86";
static void enable_dev(struct device *dev){
printk(BIOS_INFO, "qemu-i386 enable_dev done\n");
}