Ok. The changes are done. Here the attachments.
I start yet learning how to write in the wiki :)

Urbez.


El lun, 28-01-2008 a las 12:47 -0500, Corey Osgood escribió:
> Urbez Santana Roma wrote:
> > El lun, 28-01-2008 a las 10:41 +0100, Rudolf Marek escribió:
> >   
> >> Hi Urbez,
> >>
> >> Please can you add some notes on wiki?
> >>
> >> http://www.coreboot.org/ACPI_in_coreboot
> >>
> >> Thanks,
> >>
> >> Rudolf
> >>     
> >
> > Yes, i can try, but i have a ugly 'English',  :))))
> >
> > Must i complete the generated *.c files with a line of the follow
> > type???
> >
> > /*Not distribute this file if you haven't permission.*/
> >
> > I must add too if us will include these simple tools in the coreboot,
> > the preamble license.
> 
> Perhaps something more along the lines of
> 
> /* The content of this file is the intellectual property of its 
> respective owner.
>  * Do not distribute without the permission of the copyright holder. */
> 
> -Corey
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2008 Urbez Santana <[EMAIL PROTECTED]>
 *
 * 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>

int main(int argc,char **argv)
{
  FILE *r,*w;
  int len;
  int off;
  int i;
  unsigned char buf[8];
  if (argc<3)
  {
    printf("Usage ./gendsdt /proc/acpi/dsdt dsdt.c\n");
    return 0;
  }
  r=fopen(argv[1],"rb");
  if (!r) {printf("Could not open %s\n",argv[1]);return 0;}
  w=fopen(argv[2],"wb");
  if (!w) {printf("Could not write %s\n",argv[2]);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);
}
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2008 Urbez Santana <[EMAIL PROTECTED]>
 *
 * 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>

/* FADT */

typedef unsigned char u8;
typedef unsigned long 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)
{
	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 main(int argc,char **argv)
{
    FILE *r,*w;
    int len;
    int off;
    int i;
    unsigned char buf[8];
    if (argc<3)
    {
        printf("Usage ./genfadt /proc/acpi/fadt fadt.c\n");
        return 0;
    }
    r=fopen(argv[1],"rb");
    if (!r) {printf("Could not open %s\n",argv[1]);return 0;}
    w=fopen(argv[2],"wb");
    if (!w) {printf("Could not write %s\n",argv[2]);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);
}
-- 
coreboot mailing list
[email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to