[coreboot] GENFADT and GENDSDT

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Wed Feb 6 14:12:33 CET 2008


On 06.02.2008 06:10, Corey Osgood wrote:
> On Feb 6, 2008 12:08 AM, Corey Osgood <corey.osgood at gmail.com> wrote:
>
>   
>> On Jan 29, 2008 9:37 AM, Uwe Hermann <uwe at hermann-uwe.de> wrote:
>>
>>     
>>> On Tue, Jan 29, 2008 at 11:46:42AM +0100, Carl-Daniel Hailfinger wrote:
>>>       
>>>> On 28.01.2008 23:16, Urbez Santana Roma wrote:
>>>>         
>>>>> Ok. The changes are done. Here the attachments.
>>>>>
>>>>>           
>>>> Great, thanks! I'd like to have them committed as soon as possible.
>>>>
>>>> Where do we want to store these utilities? util/gen_dt or separate
>>>> directories for both of them?
>>>>         
>>> I'd personally merge them into one tool as they're very small programs.
>>> Then invoke the different functionalities with two --foo / --bar
>>> switches.
>>>       
>> Here's a very dumb combination of the two utilities, it hardcodes
>> /proc/acpi/xxx, since I can't think of any reason they'd be different, and
>>     

I'd like to avoid the hardcode. That way, you can work on copies of
these virtual files. This is especially useful if you can't run genacpi
on the machine you want to dump.

>> also the fadt.c/dsdt.c. No switches yet, but I think we can just add all
>> that stuff later. I've also tried to clean everything up, tabs, etc, etc.
>> I've changed the dsdt line comments to use /**/ style, so the output can be
>> compared with iasl's, but to get a meaning full diff you need to run iasl
>> with optimizations disabled.
>>     
>
> And now for the attachment! I also haven't added myself as a copyright
> holder, since all I did was cleanup and add a trivial function. Here's a
> sign-off anyway:
> Signed-off-by: Corey Osgood <corey.osgood at gmail.com>
>   

Thanks for working on the merge! A few comments:

> /*
>  * This file is part of the coreboot project.
>  *
>  * Copyright (C) 2008 Urbez Santana <urbez at linuxupc.upc.edu>
>  *
>  * This program is free software; you can redistribute it and/or modify
>  * it under the terms of the GNU General Public License as published by
>  * the Free Software Foundation; either version 2 of the License, or
>  * (at your option) any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
>  */
>
> #include <stdio.h>
> #include <string.h>
>
> typedef unsigned char u8;
> typedef unsigned long u32;
>   

unsigned long is 64bit on 64bit architectures. You either want unsigned
int or you do something like this:
typedef uint32_t u32;

> typedef unsigned short u16;
>
> typedef struct acpi_gen_regaddr {
> 	u8  space_id;
> 	u8  bit_width;
> 	u8  bit_offset;
> 	u8  resv;
> 	u32 addrl;
> 	u32 addrh;
> } __attribute__ ((packed)) acpi_addr_t;
>
> /* Generic ACPI Header, provided by (almost) all tables */
>
> typedef struct acpi_table_header	/* ACPI common table header */
> {
> 	char signature [4];		/* ACPI signature (4 ASCII characters) */\
> 	u32 length;			/* Length of table, in bytes, including header */\
> 	u8 revision;			/* ACPI Specification minor version # */\
> 	u8 checksum;			/* To make sum of entire table == 0 */\
> 	char oem_id [6];		/* OEM identification */\
> 	char oem_table_id [8];		/* OEM table identification */\
> 	u32 oem_revision;		/* OEM revision number */\
> 	char asl_compiler_id [4];	/* ASL compiler vendor ID */\
> 	u32 asl_compiler_revision;	/* ASL compiler revision number */
> } __attribute__ ((packed)) acpi_header_t;
>
>
> typedef struct acpi_fadt {
> 	struct acpi_table_header header;
> 	u32 firmware_ctrl;
> 	u32 dsdt;
> 	u8 res1;
> 	u8 preferred_pm_profile;
> 	u16 sci_int;
> 	u32 smi_cmd;
> 	u8 acpi_enable;
> 	u8 acpi_disable;
> 	u8 s4bios_req;
> 	u8 pstate_cnt;
> 	u32 pm1a_evt_blk;
> 	u32 pm1b_evt_blk;
> 	u32 pm1a_cnt_blk;
> 	u32 pm1b_cnt_blk;
> 	u32 pm2_cnt_blk;
> 	u32 pm_tmr_blk;
> 	u32 gpe0_blk;
> 	u32 gpe1_blk;
> 	u8 pm1_evt_len;
> 	u8 pm1_cnt_len;
> 	u8 pm2_cnt_len;
> 	u8 pm_tmr_len;
> 	u8 gpe0_blk_len;
> 	u8 gpe1_blk_len;
> 	u8 gpe1_base;
> 	u8 cst_cnt;
> 	u16 p_lvl2_lat;
> 	u16 p_lvl3_lat;
> 	u16 flush_size;
> 	u16 flush_stride;
> 	u8 duty_offset;
> 	u8 duty_width;
> 	u8 day_alrm;
> 	u8 mon_alrm;
> 	u8 century;
> 	u16 iapc_boot_arch;
> 	u8 res2;
> 	u32 flags;
> 	struct acpi_gen_regaddr reset_reg;
> 	u8 reset_value;
> 	u8 res3;
> 	u8 res4;
> 	u8 res5;
> 	u32 x_firmware_ctl_l;
> 	u32 x_firmware_ctl_h;
> 	u32 x_dsdt_l;
> 	u32 x_dsdt_h;
> 	struct acpi_gen_regaddr x_pm1a_evt_blk;
> 	struct acpi_gen_regaddr x_pm1b_evt_blk;
> 	struct acpi_gen_regaddr x_pm1a_cnt_blk;
> 	struct acpi_gen_regaddr	x_pm1b_cnt_blk;
> 	struct acpi_gen_regaddr x_pm2_cnt_blk;
> 	struct acpi_gen_regaddr x_pm_tmr_blk;
> 	struct acpi_gen_regaddr x_gpe0_blk;
> 	struct acpi_gen_regaddr x_gpe1_blk;
> } __attribute__ ((packed)) acpi_fadt_t;
>
> struct acpi_fadt FADT;
>
> char strn[64];
> char *stri(int i, const char *str)
> {
> 	strncpy(strn, str, i);
> 	strn[i] = 0;
> 	return strn;
> }
>
> void print_u8(FILE *w, char *name, u8 val)
> {
> 	fprintf(w, "	%s = 0x%02x;\n", name, (int)val);
> }
>
> void print_u16(FILE *w,char *name, u16 val)
> {
> 	fprintf(w, "	%s = 0x%04x;\n", name, (int)val);
> }
>
> void print_u32(FILE *w, char *name, u32 val)
> {
> 	fprintf(w, "	%s = 0x%08lx;\n", name, val);
> }
>
>
> void print_acpi_gen_regaddr(FILE *w, char *name, acpi_addr_t val)
> {
> 	char name2[256];
> 	sprintf(name2, "%s.space_id", name);
> 	print_u8(w, name2, val.space_id);
> 	sprintf(name2, "%s.bit_width", name);
> 	print_u8(w, name2, val.bit_width);
> 	sprintf(name2, "%s.bit_offset", name);
> 	print_u8(w, name2, val.bit_offset);
> 	sprintf(name2, "%s.resv", name);
> 	print_u8(w, name2, val.resv);
> 	sprintf(name2, "%s.addrl", name);
> 	print_u32(w, name2, val.addrl);
> 	sprintf(name2, "%s.addrh", name);
> 	print_u32(w, name2, val.addrh);
> }
>
> void print_acpi_header(FILE *w,char *name,acpi_header_t val)
>   

Space after comma? Same in other places.

> {
> 	char name2[256];
> 	fprintf(w, "	memcpy(header->signature, \"%s\", 4);\n", stri(4, val.signature));
> 	fprintf(w, "	header->length = 0x%08x;\n", val.length);
> 	fprintf(w, "	header->revision = 0x%02x;\n", (int)val.revision);
> 	fprintf(w, "	memcpy(header->oem_id, \"%s\", 6);\n", stri(6, val.oem_id));
> 	fprintf(w, "	memcpy(header->oem_table_id, \"%s\", 8);\n", stri(8, val.oem_table_id));
> 	fprintf(w, "	header->oem_revision = 0x%08x;\n", val.oem_revision);
> 	fprintf(w, "	memcpy(header->asl_compiler_id, \"%s\", 4);\n", stri(4,val.asl_compiler_id));
> 	fprintf(w, "	header->asl_compiler_revision = 0x%08x;\n", val.asl_compiler_revision);
> }
>
> int genfadt(void)
> {
> 	FILE *r,*w;
> 	int len;
> 	int off;
> 	int i;
> 	unsigned char buf[8];
>
> 	r = fopen("/proc/acpi/fadt", "rb");
> 	if(!r) {
> 		printf("Could not open /proc/acpi/dsdt, are you root?\n");
>   

You mean fadt here.

> 		return 0;
> 	}
> 	w = fopen("fadt.c", "wb");
> 	if(!w) {
> 		printf("Could not write fadt.c\n");
> 		return 0;
> 	}
> 	fprintf(w, "/* Intel ACPI Component Architecture\n"
> 		  " * File generated by genfadt\n"
> 		  " * The content of this file is the intellectual property of its \n"
> 		  " * respective owner.\n"
> 		  " * Do not distribute without the permission of the copyright holder.\n"
> 		  " */\n\n\n");
> 	len = fread(&FADT, 1, sizeof(FADT), r);
>
> 	fprintf(w, "#include <string.h>\n");
> 	fprintf(w, "#include <arch/acpi.h>\n\n");
> 	fprintf(w, "void acpi_create_fadt(acpi_fadt_t *fadt,acpi_facs_t *facs,void *dsdt) {\n\n");
> 	fprintf(w, "	acpi_header_t *header = &(fadt->header);\n\n");
> 	fprintf(w, "	memset((void *)fadt, 0, sizeof(acpi_fadt_t));\n");
>
> 	print_acpi_header(w, "fadt->header", FADT.header);
> 	fprintf(w, "\n	fadt->firmware_ctrl = facs;\n");
> 	fprintf(w, "	fadt->dsdt = dsdt;\n\n");
> 	print_u8(w, "fadt->res1", FADT.res1);
> 	print_u8(w, "fadt->preferred_pm_profile", FADT.preferred_pm_profile);
> 	print_u16(w, "fadt->sci_int", FADT.sci_int);
> 	print_u32(w, "fadt->smi_cmd", FADT.smi_cmd);
> 	print_u8(w, "fadt->acpi_enable", FADT.acpi_enable);
> 	print_u8(w, "fadt->acpi_disable", FADT.acpi_disable);
> 	print_u8(w, "fadt->s4bios_req", FADT.s4bios_req);
> 	print_u8(w, "fadt->pstate_cnt", FADT.pstate_cnt);
> 	print_u32(w, "fadt->pm1a_evt_blk", FADT.pm1a_evt_blk);
> 	print_u32(w, "fadt->pm1b_evt_blk", FADT.pm1b_evt_blk);
> 	print_u32(w, "fadt->pm1a_cnt_blk", FADT.pm1a_cnt_blk);
> 	print_u32(w, "fadt->pm1b_cnt_blk", FADT.pm1b_cnt_blk);
> 	print_u32(w, "fadt->pm2_cnt_blk", FADT.pm2_cnt_blk);
> 	print_u32(w, "fadt->pm_tmr_blk", FADT.pm_tmr_blk);
> 	print_u32(w, "fadt->gpe0_blk", FADT.gpe0_blk);
> 	print_u32(w, "fadt->gpe1_blk", FADT.gpe1_blk);
> 	print_u8(w, "fadt->pm1_evt_len", FADT.pm1_evt_len);
> 	print_u8(w, "fadt->pm1_cnt_len", FADT.pm1_cnt_len);
> 	print_u8(w, "fadt->pm2_cnt_len", FADT.pm2_cnt_len);
> 	print_u8(w, "fadt->pm_tmr_len", FADT.pm_tmr_len);
> 	print_u8(w, "fadt->gpe0_blk_len", FADT.gpe0_blk_len);
> 	print_u8(w, "fadt->gpe1_blk_len", FADT.gpe1_blk_len);
> 	print_u8(w, "fadt->gpe1_base", FADT.gpe1_base);
> 	print_u8(w, "fadt->cst_cnt", FADT.cst_cnt);
> 	print_u16(w, "fadt->p_lvl2_lat", FADT.p_lvl2_lat);
> 	print_u16(w, "fadt->p_lvl3_lat", FADT.p_lvl3_lat);
> 	print_u16(w, "fadt->flush_size", FADT.flush_size);
> 	print_u16(w, "fadt->flush_stride", FADT.flush_stride);
> 	print_u8(w, "fadt->duty_offset", FADT.duty_offset);
> 	print_u8(w, "fadt->duty_width", FADT.duty_width);
> 	print_u8(w, "fadt->day_alrm", FADT.day_alrm);
> 	print_u8(w, "fadt->mon_alrm", FADT.mon_alrm);
> 	print_u8(w, "fadt->century", FADT.century);
> 	print_u16(w, "fadt->iapc_boot_arch", FADT.iapc_boot_arch);
> 	print_u8(w, "fadt->res2", FADT.res2);
> 	print_u32(w, "fadt->flags", FADT.flags);
> 	print_acpi_gen_regaddr(w, "fadt->reset_reg", FADT.reset_reg);
> 	print_u8(w, "fadt->reset_value", FADT.reset_value);
> 	print_u8(w, "fadt->res3", FADT.res3);
> 	print_u8(w, "fadt->res4", FADT.res4);
> 	print_u8(w, "fadt->res5", FADT.res5);
> 	fprintf(w, "\n	fadt->x_firmware_ctl_l = facs;\n");
> 	fprintf(w, "	fadt->x_firmware_ctl_h = 0;\n");
> 	fprintf(w, "	fadt->x_dsdt_l = dsdt;\n");
> 	fprintf(w, "	fadt->x_dsdt_h = 0;\n\n");
> 	print_acpi_gen_regaddr(w, "fadt->x_pm1a_evt_blk", FADT.x_pm1a_evt_blk);
> 	print_acpi_gen_regaddr(w, "fadt->x_pm1b_evt_blk", FADT.x_pm1b_evt_blk);
> 	print_acpi_gen_regaddr(w, "fadt->x_pm1a_cnt_blk", FADT.x_pm1a_cnt_blk);
> 	print_acpi_gen_regaddr(w, "fadt->x_pm1b_cnt_blk", FADT.x_pm1b_cnt_blk);
> 	print_acpi_gen_regaddr(w, "fadt->x_pm2_cnt_blk", FADT.x_pm2_cnt_blk);
> 	print_acpi_gen_regaddr(w, "fadt->x_pm_tmr_blk", FADT.x_pm_tmr_blk);
> 	print_acpi_gen_regaddr(w, "fadt->x_gpe0_blk", FADT.x_gpe0_blk);
> 	print_acpi_gen_regaddr(w, "fadt->x_gpe1_blk", FADT.x_gpe1_blk);
>
> 	fprintf(w, "\n	header->checksum = acpi_checksum((void *)fadt, sizeof(acpi_fadt_t));\n}\n");
>
> 	fclose(w);
> 	fclose(r);
> 	return 1;
> }
>
>
>
>
> int gendsdt(void)
> {
> 	FILE *r,*w; //r = /proc/.. w = dsdt.c
> 	int len;
> 	int off;
> 	int i;
> 	unsigned char buf[8];
> 	
> 	r = fopen("/proc/acpi/dsdt", "rb");
> 	if(!r) {
> 		printf("Could not open /proc/acpi/dsdt, are you root?\n");
> 		return 0;
> 	}
> 	w = fopen("dsdt.c", "wb");
> 	if(!w) {
> 		printf("Could not write dsdt.c\n");
> 		return 0;
> 	}
>
> 	fprintf(w, "/* Intel ACPI Component Architecture\n"
> 		" * File generated by gendsdt\n"
> 		" * The content of this file is the intellectual property of its \n"
> 		" * respective owner.\n"
> 		" * Do not distribute without the permission of the copyright holder.\n"
> 		" */\n\n\n");
> 	fprintf(w, "unsigned char AmlCode[] =\n{\n");
>   	off = 0;
> 	while(!feof(r))
> 	{
> 		len = fread(buf, 1, 8, r);
> 		if (len <= 0)
> 			 break;
> 		fprintf(w, "	");
> 		for (i = 0; i < len; i++)
> 			fprintf(w, "0x%02x,", (int)buf[i]);
> 		fprintf(w, "  /*  %08x	\"", off);
> 		for (i = 0; i < len; i++)
> 			fprintf(w, "%c", (buf[i] >= 32 && buf[i] < 127) ? buf[i] : '.');	
> 		fprintf(w, "\" */\n");
> 		off += len;
> 	}
> 	fprintf(w, "};\n");
> 	fclose(w);
> 	fclose(r);
> 	return 1;
> }
>
> int main(void)
> {
> 	if(!gendsdt())
> 		return 0;
> 	if(!genfadt())
> 		return 0;
> }
>   

Regards,
Carl-Daniel




More information about the coreboot mailing list