Acpi userland: adapt to 20110211 upgrade and sync with FreeBSD 8.0
authorMagliano Andrea <masterblaster@tiscali.it>
Thu, 3 Mar 2011 05:00:33 +0000 (06:00 +0100)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sun, 27 Mar 2011 10:34:01 +0000 (18:34 +0800)
* acpiconf: show V/A battery units
* acpidump: add SRAT table support (FreebSD sync), untested

usr.sbin/acpi/acpiconf/acpiconf.c
usr.sbin/acpi/acpidb/Makefile
usr.sbin/acpi/acpidb/acpidb.c
usr.sbin/acpi/acpidump/acpi.c
usr.sbin/acpi/acpidump/acpidump.h
usr.sbin/acpi/iasl/Makefile

index fac18f5..7e0d84d 100644 (file)
@@ -85,7 +85,8 @@ acpi_battinfo(int num)
 {
        union acpi_battery_ioctl_arg battio;
        const char *pwr_units;
-       int hours, min;
+       int hours, min, amp;
+    uint32_t volt;
 
        if (num < 0 || num > 64)
                err(EX_USAGE, "invalid battery %d", num);
@@ -94,10 +95,8 @@ acpi_battinfo(int num)
        battio.unit = num;
        if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) == -1)
                err(EX_IOERR, "get battery info (%d) failed", num);
-       if (battio.bif.units == 0)
-               pwr_units = "mW";
-       else
-               pwr_units = "mA";
+    amp = battio.bif.units;
+    pwr_units = amp ? "mA" : "mW";
 
        if (battio.bif.dcap == UNKNOWN_CAP)
                printf("Design capacity:\tunknown\n");
@@ -124,6 +123,14 @@ acpi_battinfo(int num)
        printf("Type:\t\t\t%s\n", battio.bif.type);
        printf("OEM info:\t\t%s\n", battio.bif.oeminfo);
 
+    /* Fetch battery voltage information. */
+    volt = UNKNOWN_VOLTAGE;
+    battio.unit = num;
+    if (ioctl(acpifd, ACPIIO_BATT_GET_BST, &battio) == -1)
+        err(EX_IOERR, "get battery status (%d) failed", num);
+    if (battio.bst.state != ACPI_BATT_STAT_NOT_PRESENT)
+        volt = battio.bst.volt;
+
        /* Print current battery state information. */
        battio.unit = num;
        if (ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio) == -1)
@@ -153,7 +160,11 @@ acpi_battinfo(int num)
                }
                if (battio.battinfo.rate == -1)
                        printf("Present rate:\t\tunknown\n");
-               else
+        else if (amp && volt != UNKNOWN_VOLTAGE) {
+            printf("Present rate:\t\t%d mA (%d mW)\n",
+                   battio.battinfo.rate,
+                   battio.battinfo.rate * volt / 1000);
+        } else
                        printf("Present rate:\t\t%d %s\n",
                            battio.battinfo.rate, pwr_units);
        } else
index ea24d07..ebd3324 100644 (file)
@@ -5,25 +5,25 @@ PROG= acpidb
 SRCS+= acpidb.c
 SRCS+= osunixxf.c
 SRCS+= aehandlers.c aetables.c dbcmds.c dbdisply.c dbexec.c dbfileio.c \
-       dbhistry.c dbinput.c dbstats.c dbutils.c \
+       dbhistry.c dbinput.c dbstats.c dbutils.c dbmethod.c dbnames.c \
        dbxface.c dmbuffer.c dmnames.c dmobject.c \
        dmopcode.c dmresrc.c dmresrcl.c dmresrcs.c \
-       dmutils.c dmwalk.c dsfield.c dsinit.c \
-       dsmethod.c dsmthdat.c dsobject.c dsopcode.c \
-       dsutils.c dswexec.c dswload.c dswscope.c dswstate.c \
-       evevent.c evgpe.c evgpeblk.c evmisc.c \
-       evregion.c evrgnini.c evsci.c evxface.c \
+       dmutils.c dmwalk.c dsfield.c dsinit.c dscontrol.c \
+       dsmethod.c dsmthdat.c dsobject.c dsopcode.c dsargs.c \
+       dsutils.c dswexec.c dswload.c dswload2.c dswscope.c dswstate.c \
+       evevent.c evgpe.c evgpeutil.c evgpeinit.c evgpeblk.c evmisc.c \
+       evregion.c evrgnini.c evsci.c evxface.c evxfgpe.c \
        evxfevnt.c evxfregn.c exconfig.c exconvrt.c \
-       excreate.c exdump.c exfield.c exfldio.c \
+       excreate.c exdump.c exdebug.c exfield.c exfldio.c \
        exmisc.c exmutex.c exnames.c exoparg1.c \
        exoparg2.c exoparg3.c exoparg6.c exprep.c \
        exregion.c exresnte.c exresolv.c exresop.c \
        exstore.c exstoren.c exstorob.c exsystem.c exutils.c \
-       hwacpi.c hwgpe.c hwregs.c hwsleep.c hwvalid.c hwxface.c \
+       hwacpi.c hwgpe.c hwregs.c hwsleep.c hwvalid.c hwxface.c hwpci.c \
        nsaccess.c nsalloc.c nsdump.c nseval.c \
        nsinit.c nsload.c nsnames.c nsobject.c \
        nsparse.c nspredef.c nssearch.c nsutils.c nswalk.c \
-       nsxfeval.c nsxfname.c nsxfobj.c \
+       nsxfeval.c nsxfname.c nsxfobj.c nsrepair.c nsrepair2.c\
        psargs.c psloop.c psopcode.c psparse.c psscope.c \
        pstree.c psutils.c pswalk.c psxface.c \
        rsaddr.c rscalc.c rscreate.c rsdump.c rsinfo.c \
@@ -32,7 +32,8 @@ SRCS+=        aehandlers.c aetables.c dbcmds.c dbdisply.c dbexec.c dbfileio.c \
        tbfadt.c tbfind.c tbinstal.c tbutils.c tbxface.c tbxfroot.c \
        utalloc.c utcache.c utcopy.c utdebug.c utdelete.c \
        uteval.c utglobal.c utinit.c utlock.c utmath.c \
-       utmisc.c utmutex.c utobject.c utresrc.c utstate.c utxface.c
+       utmisc.c utmutex.c utobject.c utresrc.c utstate.c utxface.c utxferror.c \
+       utdecode.c utids.c utosi.c
 
 SRCS+= aeexec.c
 
index 67683bd..7b38116 100644 (file)
@@ -65,6 +65,8 @@ ACPI_TABLE_HEADER     dummy_dsdt_table = {
 
 int    aml_debug_prompt = 1;
 
+UINT8  AcpiGbl_RegionFillValue = 0;
+
 struct ACPIRegionContent {
        TAILQ_ENTRY(ACPIRegionContent) links;
        int                     regtype;
index 576f044..840e9ec 100644 (file)
@@ -57,8 +57,8 @@ static void   acpi_print_io_apic(u_char apic_id, u_int32_t int_base,
                                   u_int64_t apic_addr);
 static void    acpi_print_mps_flags(u_int16_t flags);
 static void    acpi_print_intr(u_int32_t intr, u_int16_t mps_flags);
-static void    acpi_print_apic(struct MADT_APIC *mp);
-static void    acpi_handle_apic(struct ACPIsdt *sdp);
+static void    acpi_print_madt(struct MADT_APIC *mp);
+static void    acpi_handle_madt(struct ACPIsdt *sdp);
 static void    acpi_handle_hpet(struct ACPIsdt *sdp);
 static void    acpi_print_sdt(struct ACPIsdt *sdp);
 static void    acpi_print_fadt(struct ACPIsdt *sdp);
@@ -112,6 +112,9 @@ acpi_print_gas(struct ACPIgas *gas)
                printf("0x%x:%u[%u] (SMBus)", (uint16_t)gas->address,
                       gas->bit_offset, gas->bit_width);
                break;
+    case ACPI_GAS_CMOS:
+    case ACPI_GAS_PCIBAR:
+    case ACPI_GAS_DATATABLE:
        case ACPI_GAS_FIXED:
        default:
                printf("0x%08lx (?)", (u_long)gas->address);
@@ -256,7 +259,7 @@ const char *platform_int_types[] = { "PMI", "INIT",
                                     "Corrected Platform Error" };
 
 static void
-acpi_print_apic(struct MADT_APIC *mp)
+acpi_print_madt(struct MADT_APIC *mp)
 {
 
        printf("\tType=%s\n", apic_types[mp->type]);
@@ -315,7 +318,7 @@ acpi_print_apic(struct MADT_APIC *mp)
 }
 
 static void
-acpi_handle_apic(struct ACPIsdt *sdp)
+acpi_handle_madt(struct ACPIsdt *sdp)
 {
        struct MADTbody *madtp;
        struct MADT_APIC *madt_apicp;
@@ -331,7 +334,7 @@ acpi_handle_apic(struct ACPIsdt *sdp)
        madt_apicp = (struct MADT_APIC *)madtp->body;
        while (((uintptr_t)madt_apicp) - ((uintptr_t)sdp) < sdp->len) {
                printf("\n");
-               acpi_print_apic(madt_apicp);
+               acpi_print_madt(madt_apicp);
                madt_apicp = (struct MADT_APIC *) ((char *)madt_apicp +
                    madt_apicp->len);
        }
@@ -401,6 +404,84 @@ acpi_handle_mcfg(struct ACPIsdt *sdp)
        printf(END_COMMENT);
 }
 
+static void
+acpi_print_srat_memory(struct SRAT_mem_affinity *mp)
+{
+
+    printf("\tFlags={");
+    printf(mp->flags & ACPI_SRAT_FLAG_MEM_ENABLED ? "ENABLED" : "DISABLED");
+    if (mp->flags & ACPI_SRAT_FLAG_MEM_HOT_PLUGGABLE)
+        printf(",HOT_PLUGGABLE");
+    if (mp->flags & ACPI_SRAT_FLAG_MEM_NON_VOLATILE)
+        printf(",NON_VOLATILE");
+    printf("}\n");
+    printf("\tBase Address=0x%016jx\n", (uintmax_t)mp->base_address);
+    printf("\tLength=0x%016jx\n", (uintmax_t)mp->length);
+    printf("\tProximity Domain=%d\n", mp->proximity_domain);
+}
+
+static void
+acpi_print_srat_cpu(uint32_t apic_id, uint32_t pd, uint32_t flags)
+{
+    printf("\tFlags={");
+    printf(flags & ACPI_SRAT_FLAG_CPU_ENABLED ? "ENABLED": "DISABLED");
+    printf("}\n");
+    printf("\tAPIC ID=%d\n", apic_id);
+    printf("\tProximity Domain=%d\n", pd);
+}
+
+static void
+acpi_print_srat_cpu_affinity(struct SRAT_cpu_affinity *cpu)
+{
+    uint32_t pd =
+        cpu->proximity_domain_hi[2] << 24 | cpu->proximity_domain_hi[1] << 16 |
+        cpu->proximity_domain_hi[0] << 0 | cpu->proximity_domain_lo;
+    acpi_print_srat_cpu(cpu->apic_id, pd, cpu->flags);
+}
+
+static void
+acpi_print_srat(struct SRAT_APIC *sp)
+{
+    const char *srat_types[] = { "CPU", "Memory", "X2APIC" };
+    const unsigned char srat_types_n =
+        sizeof(srat_types) / sizeof(srat_types[0]);
+
+    printf("\tType(%d)=%s\n", sp->type,
+           sp->type < srat_types_n ? srat_types[sp->type] : "(unknown)");
+
+    switch (sp->type) {
+    case ACPI_SRAT_APIC_TYPE_CPU_AFFINITY:
+        acpi_print_srat_cpu_affinity((struct SRAT_cpu_affinity *) &sp->body);
+        break;
+    case ACPI_SRAT_APIC_TYPE_MEMORY_AFFINITY:
+        acpi_print_srat_memory((struct SRAT_mem_affinity *) &sp->body);
+        break;
+    case ACPI_SRAT_APIC_TYPE_X2APIC_CPU_AFFINITY: {
+        struct SRAT_x2apic_cpu_affinity *cpu =
+            (struct SRAT_x2apic_cpu_affinity *) &sp->body;
+        acpi_print_srat_cpu(cpu->apic_id, cpu->proximity_domain, cpu->flags);
+    } break;
+    }
+}
+
+static void
+acpi_handle_srat(struct ACPIsdt *sdp)
+{
+    struct SRATbody *srat = (struct SRATbody *) sdp->body;
+    struct SRAT_APIC *apic = (struct SRAT_APIC *)srat->body;
+
+    printf(BEGIN_COMMENT);
+    acpi_print_sdt(sdp);
+    printf("\tRevision=0x%04x\n", srat->revision);
+
+    for (; ((uintptr_t) apic) - ((uintptr_t) sdp) < sdp->len;
+         apic = (struct SRAT_APIC *) ((char *) apic + apic->len)) {
+        printf("\n");
+        acpi_print_srat(apic);
+    }
+    printf(END_COMMENT);
+}
+
 static void
 acpi_print_sdt(struct ACPIsdt *sdp)
 {
@@ -548,6 +629,12 @@ acpi_print_fadt(struct ACPIsdt *sdp)
        PRINTFLAG(fadt->flags, SEALED_CASE);
        PRINTFLAG(fadt->flags, HEADLESS);
        PRINTFLAG(fadt->flags, CPU_SW_SLP);
+    PRINTFLAG(fadt->flags, PCI_EXPRESS_WAKE);
+    PRINTFLAG(fadt->flags, PLATFORM_CLOCK);
+    PRINTFLAG(fadt->flags, S4_RTC_VALID);
+    PRINTFLAG(fadt->flags, REMOTE_POWER_ON);
+    PRINTFLAG(fadt->flags, APIC_CLUSTER);
+    PRINTFLAG(fadt->flags, APIC_PHYSICAL);
        if (fadt->flags != 0)
                printf("}\n");
 
@@ -703,13 +790,15 @@ acpi_handle_rsdt(struct ACPIsdt *rsdp)
                if (!memcmp(sdp->signature, "FACP", 4))
                        acpi_handle_fadt(sdp);
                else if (!memcmp(sdp->signature, "APIC", 4))
-                       acpi_handle_apic(sdp);
+                       acpi_handle_madt(sdp);
                else if (!memcmp(sdp->signature, "HPET", 4))
                        acpi_handle_hpet(sdp);
                else if (!memcmp(sdp->signature, "ECDT", 4))
                        acpi_handle_ecdt(sdp);
                else if (!memcmp(sdp->signature, "MCFG", 4))
                        acpi_handle_mcfg(sdp);
+        else if (!memcmp(sdp->signature, "SRAT", 4))
+            acpi_handle_srat(sdp);
                else {
                        printf(BEGIN_COMMENT);
                        acpi_print_sdt(sdp);
index eb057d3..9417ec3 100644 (file)
 struct ACPIgas {
        u_int8_t        address_space_id;
 #define ACPI_GAS_MEMORY                0
-#define ACPI_GAS_IO            1
+#define ACPI_GAS_IO            1
 #define ACPI_GAS_PCI           2
 #define ACPI_GAS_EMBEDDED      3
 #define ACPI_GAS_SMBUS         4
+#define ACPI_GAS_CMOS       5
+#define ACPI_GAS_PCIBAR     6
+#define ACPI_GAS_DATATABLE  7
 #define ACPI_GAS_FIXED         0x7f
        u_int8_t        bit_width;
        u_int8_t        bit_offset;
@@ -70,8 +73,8 @@ struct ACPIsdt {
        u_int32_t       oemrev;
        u_char          creator[4];
        u_int32_t       crerev;
-#define SIZEOF_SDT_HDR 36      /* struct size except body */
-       u_int32_t       body[1];/* This member should be casted */
+#define SIZEOF_SDT_HDR 36 /* struct size except body */
+       u_int32_t       body[1]; /* This member should be casted */
 } __packed;
 
 /* Fixed ACPI Description Table (body) */
@@ -132,6 +135,12 @@ struct FADTbody {
 #define FADT_FLAG_SEALED_CASE  2048    /* Case cannot be opened */
 #define FADT_FLAG_HEADLESS     4096    /* No monitor */
 #define FADT_FLAG_CPU_SW_SLP   8192    /* Supports CPU software sleep */
+#define FADT_FLAG_PCI_EXPRESS_WAKE (1<<14) /* PCIEXP_WAKE (STS/EN) bits */
+#define FADT_FLAG_PLATFORM_CLOCK (1<<15) /* OSPM should use platform-provided tmr */
+#define FADT_FLAG_S4_RTC_VALID (1<<16) /* RTC_STS valid after S4 wake */
+#define FADT_FLAG_REMOTE_POWER_ON (1<<17) /* System is compat. with remote pwr on */
+#define FADT_FLAG_APIC_CLUSTER (1<<18) /* All local APICs must use cluster model */
+#define FADT_FLAG_APIC_PHYSICAL (1<<19) /*All local xAPICs must use phys dest mode*/
        struct ACPIgas  reset_reg;
        u_int8_t        reset_value;
        u_int8_t        reserved5[3];
@@ -306,6 +315,64 @@ struct MCFGbody {
        } s[1] __packed;
 } __packed;
 
+/*  SRAT - System Resource Affinity Table */
+
+struct SRAT_cpu_affinity {
+    uint8_t proximity_domain_lo;
+    uint8_t apic_id;
+    uint32_t flags;
+    uint8_t local_sapic_eid;
+    uint8_t proximity_domain_hi[3];
+    uint32_t reserved; /* must be zero */
+};
+
+#define ACPI_SRAT_FLAG_CPU_ENABLED 1
+
+struct SRAT_mem_affinity
+{
+    uint32_t proximity_domain;
+    uint16_t reserved; /* must be zero */
+    uint64_t base_address;
+    uint64_t length;
+    uint32_t reserved1;
+#define ACPI_SRAT_FLAG_MEM_ENABLED 1
+#define ACPI_SRAT_FLAG_MEM_HOT_PLUGGABLE 2
+#define ACPI_SRAT_FLAG_MEM_NON_VOLATILE 4
+    uint32_t flags;
+    uint64_t reserved2; /* must be zero */
+
+};
+
+struct SRAT_x2apic_cpu_affinity
+{
+    uint16_t reserved; /* must be zero */
+    uint32_t proximity_domain;
+    uint32_t apic_id;
+    uint32_t flags;
+    uint32_t clock_domain;
+    uint32_t reserved2;
+};
+
+struct SRAT_APIC {
+    u_char type;
+#define ACPI_SRAT_APIC_TYPE_CPU_AFFINITY 0
+#define ACPI_SRAT_APIC_TYPE_MEMORY_AFFINITY 1
+#define ACPI_SRAT_APIC_TYPE_X2APIC_CPU_AFFINITY 2
+#define ACPI_SRAT_APIC_TYPE_RESERVED 3
+    u_char len;
+    union {
+        struct SRAT_cpu_affinity cpu_affinity;
+        struct SRAT_mem_affinity mem_affinity;
+        struct SRAT_x2apic_cpu_affinity x2apic_cpu_affinity;
+    } body;
+} __packed;
+
+struct SRATbody {
+    u_int32_t revision;
+    u_int64_t reserved;
+    u_char body[1];
+} __packed;
+
 /*
  * Addresses to scan on ia32 for the RSD PTR.  According to section 5.2.2
  * of the ACPI spec, we only consider two regions for the base address:
index f8b66a0..c6e4913 100644 (file)
@@ -3,17 +3,20 @@
 
 PROG=  iasl
 SRCS=  aslcompiler.y.h aslcompilerlex.l aslcompilerparse.y \
-       aslanalyze.c aslcodegen.c \
+       aslanalyze.c aslbtypes.c aslwalks.c aslcodegen.c \
        aslcompile.c aslerror.c aslfiles.c asllength.c \
        asllisting.c aslload.c asllookup.c aslmain.c \
        aslmap.c aslopcodes.c asloperands.c aslstartup.c aslresource.c \
        aslrestype1.c aslrestype2.c asltree.c aslutils.c \
-       asltransform.c aslfold.c aslstubs.c aslopt.c
+       asltransform.c aslfold.c aslstubs.c aslopt.c \
+       aslpredef.c asluuid.c aslrestype1i.c aslrestype2d.c aslrestype2e.c \
+       aslrestype2q.c aslrestype2w.c
+
 SRCS+= adisasm.c getopt.c osunixxf.c
 SRCS+= dbfileio.c dmbuffer.c dmnames.c dmopcode.c dmobject.c \
-        dmresrc.c dmresrcl.c dmresrcs.c dmutils.c dmwalk.c \
-        dsopcode.c dsutils.c dswexec.c dswload.c \
-       dswscope.c dswstate.c dsfield.c dsobject.c \
+        dmresrc.c dmresrcl.c dmresrcs.c dmutils.c dmwalk.c dmextern.c \
+        dsopcode.c dsargs.c dscontrol.c dsutils.c dswexec.c dswload.c \
+       dswscope.c dswstate.c dsfield.c dsobject.c dswload2.c \
         exconvrt.c excreate.c exdump.c exmisc.c \
         exmutex.c exnames.c exoparg1.c exoparg2.c \
         exoparg3.c exoparg6.c exprep.c exregion.c \
@@ -25,7 +28,9 @@ SRCS+=        dbfileio.c dmbuffer.c dmnames.c dmopcode.c dmobject.c \
         pstree.c psutils.c pswalk.c \
         tbfadt.c tbinstal.c tbutils.c tbxface.c \
        utalloc.c utcopy.c utdebug.c utdelete.c utinit.c \
-        utglobal.c utobject.c utlock.c utmisc.c utmath.c utxface.c
+        utglobal.c utobject.c utlock.c utmisc.c utmath.c utdecode.c \
+               utxface.c utxferror.c \
+       dttemplate.c dtcompile.c dtsubtable.c dtutils.c dtfield.c dtio.c dttable.c dtexpress.c
 
 SRCS+= adfile.c adwalk.c dmrestag.c dmtbdump.c dmtbinfo.c dmtable.c psloop.c utcache.c utmutex.c utresrc.c utstate.c