From 32e6d213123a90463d92ffe47f4afa150d4af50a Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 27 Jun 2014 18:02:26 -0700 Subject: [PATCH 01/16] kernel - Fix pf-based NAT * Concurrency work on PF broke NAT. Fix NAT for IPV4 TCP. * This is not a complete fix, the NAT must be able to select from a range of local ports to replace sport to properly map the NAT onto the same cpu that the originating packet was forwarded to. * Not fixed for UDP yet. --- sys/net/pf/pf.c | 69 +++++++++++++++++++++++++++++++++++-------- sys/net/pf/pf_ioctl.c | 1 - 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/sys/net/pf/pf.c b/sys/net/pf/pf.c index 89aa8714bd..3b6355695f 100644 --- a/sys/net/pf/pf.c +++ b/sys/net/pf/pf.c @@ -100,6 +100,7 @@ #include #include #include +#include extern int ip_optcopy(struct ip *, struct ip *); extern int debug_pfugidhack; @@ -237,8 +238,10 @@ int pf_map_addr(u_int8_t, struct pf_rule *, struct pf_addr *, struct pf_addr *, struct pf_addr *, struct pf_src_node **); int pf_get_sport(sa_family_t, u_int8_t, struct pf_rule *, - struct pf_addr *, struct pf_addr *, u_int16_t, - struct pf_addr *, u_int16_t*, u_int16_t, u_int16_t, + struct pf_addr *, struct pf_addr *, + u_int16_t, u_int16_t, + struct pf_addr *, u_int16_t *, + u_int16_t, u_int16_t, struct pf_src_node **); void pf_route(struct mbuf **, struct pf_rule *, int, struct ifnet *, struct pf_state *, @@ -296,14 +299,14 @@ struct pf_pool_limit pf_pool_limits[PF_LIMIT_MAX] = { #define STATE_INC_COUNTERS(s) \ do { \ - s->rule.ptr->states_cur++; \ + atomic_add_int(&s->rule.ptr->states_cur, 1); \ s->rule.ptr->states_tot++; \ if (s->anchor.ptr != NULL) { \ - s->anchor.ptr->states_cur++; \ + atomic_add_int(&s->anchor.ptr->states_cur, 1); \ s->anchor.ptr->states_tot++; \ } \ if (s->nat_rule.ptr != NULL) { \ - s->nat_rule.ptr->states_cur++; \ + atomic_add_int(&s->nat_rule.ptr->states_cur, 1); \ s->nat_rule.ptr->states_tot++; \ } \ } while (0) @@ -311,10 +314,10 @@ struct pf_pool_limit pf_pool_limits[PF_LIMIT_MAX] = { #define STATE_DEC_COUNTERS(s) \ do { \ if (s->nat_rule.ptr != NULL) \ - s->nat_rule.ptr->states_cur--; \ + atomic_add_int(&s->nat_rule.ptr->states_cur, -1); \ if (s->anchor.ptr != NULL) \ - s->anchor.ptr->states_cur--; \ - s->rule.ptr->states_cur--; \ + atomic_add_int(&s->anchor.ptr->states_cur, -1); \ + atomic_add_int(&s->rule.ptr->states_cur, -1); \ } while (0) static MALLOC_DEFINE(M_PFSTATEPL, "pfstatepl", "pf state pool list"); @@ -508,7 +511,7 @@ pf_src_connlimit(struct pf_state **state) /* * Kill states from this source. (Only those * from the same rule if PF_FLUSH_GLOBAL is not - * set) + * set). (Only on current cpu). */ if (sk->af == (*state)->key[PF_SK_WIRE]->af && @@ -838,7 +841,11 @@ pf_state_key_setup(struct pf_pdesc *pd, struct pf_rule *nr, return (0); } - +/* + * Insert pf_state with one or two state keys (allowing a reverse path lookup + * which is used by NAT). In the NAT case skw is the initiator (?) and + * sks is the target. + */ int pf_state_insert(struct pfi_kif *kif, struct pf_state_key *skw, struct pf_state_key *sks, struct pf_state *s) @@ -2546,13 +2553,15 @@ pf_map_addr(sa_family_t af, struct pf_rule *r, struct pf_addr *saddr, int pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, - struct pf_addr *saddr, struct pf_addr *daddr, u_int16_t dport, + struct pf_addr *saddr, struct pf_addr *daddr, + u_int16_t sport, u_int16_t dport, struct pf_addr *naddr, u_int16_t *nport, u_int16_t low, u_int16_t high, struct pf_src_node **sn) { struct pf_state_key_cmp key; struct pf_addr init_addr; u_int16_t cut; + u_int32_t toeplitz_sport; bzero(&init_addr, sizeof(init_addr)); if (pf_map_addr(af, r, saddr, naddr, &init_addr, sn)) @@ -2570,9 +2579,31 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, PF_ACPY(&key.addr[0], naddr, key.af); key.port[1] = dport; + /* + * We want to select a port that calculates to a toeplitz hash + * that masks to the same cpu, otherwise the response may + * not see the new state. + */ + switch(af) { + case AF_INET: + toeplitz_sport = + toeplitz_piecemeal_port(sport) ^ + toeplitz_piecemeal_addr(saddr->v4.s_addr) ^ + toeplitz_piecemeal_addr(naddr->v4.s_addr); + break; + case AF_INET6: + /* XXX TODO XXX */ + default: + /* XXX TODO XXX */ + toeplitz_sport = 0; + break; + } + /* * port search; start random, step; * similar 2 portloop in in_pcbbind + * + * XXX fixed ports present a problem for cpu localization. */ if (!(proto == IPPROTO_TCP || proto == IPPROTO_UDP || proto == IPPROTO_ICMP)) { @@ -2602,6 +2633,10 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, /* low <= cut <= high */ for (tmp = cut; tmp <= high; ++(tmp)) { key.port[0] = htons(tmp); + if ((toeplitz_piecemeal_port(key.port[0]) ^ + toeplitz_sport) & ncpus2_mask) { + continue; + } if (pf_find_state_all(&key, PF_IN, NULL) == NULL && !in_baddynamic(tmp, proto)) { *nport = htons(tmp); @@ -2610,6 +2645,10 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, } for (tmp = cut - 1; tmp >= low; --(tmp)) { key.port[0] = htons(tmp); + if ((toeplitz_piecemeal_port(key.port[0]) ^ + toeplitz_sport) & ncpus2_mask) { + continue; + } if (pf_find_state_all(&key, PF_IN, NULL) == NULL && !in_baddynamic(tmp, proto)) { *nport = htons(tmp); @@ -2618,6 +2657,9 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, } } + /* + * Next address + */ switch (r->rpool.opts & PF_POOL_TYPEMASK) { case PF_POOL_RANDOM: case PF_POOL_ROUNDROBIN: @@ -2764,8 +2806,9 @@ pf_get_translation(struct pf_pdesc *pd, struct mbuf *m, int off, int direction, return (NULL); case PF_NAT: m->m_pkthdr.fw_flags &= ~BRIDGE_MBUF_TAGGED; - if (pf_get_sport(pd->af, pd->proto, r, saddr, - daddr, dport, naddr, nport, r->rpool.proxy_port[0], + if (pf_get_sport(pd->af, pd->proto, r, + saddr, daddr, sport, dport, + naddr, nport, r->rpool.proxy_port[0], r->rpool.proxy_port[1], sn)) { DPFPRINTF(PF_DEBUG_MISC, ("pf: NAT proxy port allocation " diff --git a/sys/net/pf/pf_ioctl.c b/sys/net/pf/pf_ioctl.c index 5242528e14..a525c69b9e 100644 --- a/sys/net/pf/pf_ioctl.c +++ b/sys/net/pf/pf_ioctl.c @@ -2001,7 +2001,6 @@ pfioctl(struct dev_ioctl_args *ap) TAILQ_FOREACH(altq, pf_altqs_active, entries) pa->nr++; pa->ticket = ticket_altqs_active; - kprintf("ALTQS: %d\n", pa->nr); break; } -- 2.41.0 From f72d5ff0d8dd6b9afab31a2e1d51d5539bf85b03 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 27 Jun 2014 19:05:33 -0700 Subject: [PATCH 02/16] pfctl - Change default keep-policy to bring more in-line with other BSDs * Change the default keep-policy to the equivalent of: set keep-policy keep state (pickups, sloppy) * This is being done because without keep state PF is simply going to be too inefficient for any reasonable set of rules, and we no longer want to make users set the keep-policy line when keep state is already the default in other BSD systems. * Note that we also set pickups and sloppy by default. This allows the router and/or PF to be restarted and allows packet routing to change mid-stream without causing all active TCP connections to drop. This may not be the default in other BSD systems but it should be. Being ultra strict here to improve security against ICMP-based attacks removes too much flexibility to be appropriate. Proper TCP implementations already do sequence space checks for RST packets. --- usr.sbin/pfctl/parse.y | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/usr.sbin/pfctl/parse.y b/usr.sbin/pfctl/parse.y index ebc88b0cfa..47cbc486ba 100644 --- a/usr.sbin/pfctl/parse.y +++ b/usr.sbin/pfctl/parse.y @@ -5778,6 +5778,49 @@ parse_config(char *filename, struct pfctl *xpf) blockpolicy = PFRULE_DROP; require_order = 1; + /* + * Default keep-polifcy is: + * + * set keep-policy keep state (pickups, sloppy) + * + * pickups - Allows TCP connections to be picked up mid-stream, + * meaning that router restarts and changes in packet + * routing will not destroy TCP connections already in + * progress. + * + * sloppy - Window scale options are only sent with SYN and SYN+ACK, + * when picking up a connection in the middle, such as when + * the router has been restarted or when multi-pathing + * occurs, PF will not understand the window scale. This + * tells PF to ignore the sequence space tests for this case. + * + * While it is true that ICMP attack vectors are easier with these + * options, the problem is that PF just has no business defaulting + * to strict enforcement because it completely destroys the system + * operator's ability to multi-path packets, to change packet routing, + * or to restart the router (or PF) without kicking *ALL* active TCP + * connections that were flowing through the router at the time. It + * unacceptable to kick active connections by default. + */ + { + struct node_state_opt *opt1 = calloc(1, sizeof(*opt1)); + struct node_state_opt *opt2 = calloc(1, sizeof(*opt2)); + + opt1->type = PF_STATE_OPT_PICKUPS; + opt1->data.pickup_mode = PF_PICKUPS_ENABLED; + opt1->next = NULL; + opt1->tail = opt1; + + opt2->type = PF_STATE_OPT_SLOPPY; + opt2->next = NULL; + opt2->tail = opt1; + + default_keeppolicy_action = PF_STATE_NORMAL; + default_keeppolicy_options = opt1; + opt1->next = opt2; + opt1->tail = opt2; + } + if ((file = pushfile(filename, 0)) == NULL) { warn("cannot open the main config file!"); return (-1); -- 2.41.0 From 9106f055277c19a99b4101347b85c370849f011e Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 27 Jun 2014 20:06:02 -0700 Subject: [PATCH 03/16] kernel - merge fixes from FreeBSD * Merge 8159278dbd8e019, fixes to pf_get_sport(). Primarily fixes the state key used to check whether a port is in-use or not. NAT could previously choose a port that was already in-use. * bzero() the state key to ensure that uninitialized fields are zero, otherwise the RB_FIND is likely to fail. * Cleanup the case where there is no port range or the protocol is not supported. In this situation, sport must be replicated on the host. --- sys/net/pf/pf.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/sys/net/pf/pf.c b/sys/net/pf/pf.c index 3b6355695f..8f6e307c7a 100644 --- a/sys/net/pf/pf.c +++ b/sys/net/pf/pf.c @@ -2572,12 +2572,14 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, high = 65535; } + bzero(&key, sizeof(key)); + key.af = af; + key.proto = proto; + key.port[0] = dport; + PF_ACPY(&key.addr[0], daddr, key.af); + do { - key.af = af; - key.proto = proto; - PF_ACPY(&key.addr[1], daddr, key.af); - PF_ACPY(&key.addr[0], naddr, key.af); - key.port[1] = dport; + PF_ACPY(&key.addr[1], naddr, key.af); /* * We want to select a port that calculates to a toeplitz hash @@ -2607,15 +2609,19 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, */ if (!(proto == IPPROTO_TCP || proto == IPPROTO_UDP || proto == IPPROTO_ICMP)) { - key.port[0] = dport; - if (pf_find_state_all(&key, PF_IN, NULL) == NULL) + key.port[1] = sport; + if (pf_find_state_all(&key, PF_IN, NULL) == NULL) { + *nport = sport; return (0); + } } else if (low == 0 && high == 0) { - key.port[0] = *nport; - if (pf_find_state_all(&key, PF_IN, NULL) == NULL) + key.port[1] = sport; + if (pf_find_state_all(&key, PF_IN, NULL) == NULL) { + *nport = sport; return (0); + } } else if (low == high) { - key.port[0] = htons(low); + key.port[1] = htons(low); if (pf_find_state_all(&key, PF_IN, NULL) == NULL) { *nport = htons(low); return (0); @@ -2632,8 +2638,8 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, cut = htonl(karc4random()) % (1 + high - low) + low; /* low <= cut <= high */ for (tmp = cut; tmp <= high; ++(tmp)) { - key.port[0] = htons(tmp); - if ((toeplitz_piecemeal_port(key.port[0]) ^ + key.port[1] = htons(tmp); + if ((toeplitz_piecemeal_port(key.port[1]) ^ toeplitz_sport) & ncpus2_mask) { continue; } @@ -2644,8 +2650,8 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, } } for (tmp = cut - 1; tmp >= low; --(tmp)) { - key.port[0] = htons(tmp); - if ((toeplitz_piecemeal_port(key.port[0]) ^ + key.port[1] = htons(tmp); + if ((toeplitz_piecemeal_port(key.port[1]) ^ toeplitz_sport) & ncpus2_mask) { continue; } -- 2.41.0 From 5f39c7e70ca0960d1868c75a449064df712dbb10 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 28 Jun 2014 13:14:15 +0200 Subject: [PATCH 04/16] kernel: Sync ACPICA with Intel's version 20140627. * Various bug fixes and enhancements (see changes.txt). * Use new local printf() like functions for the utilities. * Use new AcpiLogError for portability. This that are also changed/new but it don't affect DragonFly so far: * Support for ACPICA generation within the EFI environment. * New OSL file I/O interface. * New global AcpiGbl_VerifyTableChecksum. For a more detailed list, please see sys/contrib/dev/acpica/changes.txt. --- sys/contrib/dev/acpica/Makefile | 12 +- sys/contrib/dev/acpica/changes.txt | 101 ++ .../dev/acpica/generate/unix/acpibin/Makefile | 3 + .../acpica/generate/unix/acpidump/Makefile | 5 + .../generate/unix/acpiexamples/Makefile | 22 +- .../acpica/generate/unix/acpiexec/Makefile | 3 + .../acpica/generate/unix/acpihelp/Makefile | 11 +- .../acpica/generate/unix/acpinames/Makefile | 12 +- .../dev/acpica/generate/unix/acpisrc/Makefile | 13 +- .../acpica/generate/unix/acpixtract/Makefile | 14 +- .../dev/acpica/generate/unix/iasl/Makefile | 3 + .../dev/acpica/source/common/ahpredef.c | 1 - .../dev/acpica/source/common/cmfsize.c | 20 +- sys/contrib/dev/acpica/source/common/getopt.c | 14 +- .../dev/acpica/source/compiler/aslanalyze.c | 48 - .../dev/acpica/source/compiler/aslcompiler.h | 9 - .../dev/acpica/source/compiler/aslmain.c | 1 + .../dev/acpica/source/compiler/aslmessages.c | 1 - .../dev/acpica/source/compiler/aslmessages.h | 1 - .../dev/acpica/source/compiler/aslmethod.c | 20 - .../dev/acpica/source/compiler/asloptions.c | 2 +- .../dev/acpica/source/compiler/aslstubs.c | 25 - .../source/components/debugger/dbfileio.c | 316 +--- .../source/components/debugger/dbtest.c | 1 + .../source/components/disassembler/dmbuffer.c | 72 +- .../source/components/disassembler/dmwalk.c | 28 +- .../source/components/executer/exfield.c | 103 +- .../source/components/hardware/hwregs.c | 8 +- .../source/components/namespace/nsobject.c | 11 + .../acpica/source/components/tables/tbdata.c | 65 +- .../source/components/tables/tbinstal.c | 8 +- .../acpica/source/components/tables/tbutils.c | 4 - .../source/components/utilities/utbuffer.c | 135 ++ .../source/components/utilities/utclib.c | 6 +- .../source/components/utilities/utcopy.c | 7 + .../source/components/utilities/utdebug.c | 30 + .../dbfileio.c => utilities/utfileio.c} | 282 +--- .../source/components/utilities/utglobal.c | 157 -- .../source/components/utilities/utinit.c | 156 ++ .../source/components/utilities/utprint.c | 796 ++++++++++ .../dev/acpica/source/include/acapps.h | 9 +- .../dev/acpica/source/include/acdebug.h | 5 - .../dev/acpica/source/include/acglobal.h | 8 +- .../dev/acpica/source/include/acnames.h | 1 - sys/contrib/dev/acpica/source/include/acpi.h | 4 +- .../dev/acpica/source/include/acpiosxf.h | 49 + .../dev/acpica/source/include/acpixf.h | 36 +- .../dev/acpica/source/include/acpredef.h | 6 - .../dev/acpica/source/include/actables.h | 14 +- .../dev/acpica/source/include/actypes.h | 16 + .../dev/acpica/source/include/acutils.h | 70 +- .../acpica/source/include/platform/accygwin.h | 9 +- .../acpica/source/include/platform/acefi.h | 61 + .../acpica/source/include/platform/acenv.h | 53 +- .../include/platform/{acefi.h => acenvex.h} | 40 +- .../acpica/source/include/platform/aclinux.h | 194 +-- .../source/include/platform/aclinuxex.h | 137 ++ .../{oslinuxtbl.c => osefitbl.c} | 525 +------ .../os_specific/service_layers/osefixf.c | 1300 +++++++++++++++++ .../os_specific/service_layers/oslibcfs.c | 251 ++++ .../os_specific/service_layers/oslinuxtbl.c | 61 +- .../os_specific/service_layers/osunixxf.c | 66 +- .../os_specific/service_layers/oswinxf.c | 65 +- .../acpica/source/tools/acpibin/abcompare.c | 27 - .../dev/acpica/source/tools/acpibin/abmain.c | 2 +- .../acpica/source/tools/acpidump/acpidump.h | 3 +- .../dev/acpica/source/tools/acpidump/apdump.c | 76 +- .../acpica/source/tools/acpidump/apfiles.c | 89 +- .../dev/acpica/source/tools/acpidump/apmain.c | 80 +- .../acpica/source/tools/acpiexec/aehandlers.c | 16 +- .../dev/acpica/source/tools/acpiexec/aemain.c | 23 +- .../acpica/source/tools/acpiexec/aetables.c | 8 +- .../dev/acpica/source/tools/acpihelp/ahmain.c | 19 +- .../acpica/source/tools/acpinames/anmain.c | 26 +- .../acpica/source/tools/acpinames/anstubs.c | 174 --- .../acpica/source/tools/acpinames/antables.c | 8 +- .../dev/acpica/source/tools/acpisrc/asmain.c | 5 +- .../dev/acpica/source/tools/acpisrc/astable.c | 6 + .../acpica/source/tools/acpixtract/axmain.c | 7 +- .../acpica/source/tools/examples/examples.c | 61 + .../acpica/source/tools/examples/exstubs.c | 250 ---- .../acpica/source/tools/examples/extables.c | 41 +- usr.sbin/acpi/acpibin/Makefile | 3 + usr.sbin/acpi/acpidump/Makefile | 5 + usr.sbin/acpi/acpiexec/Makefile | 3 + usr.sbin/acpi/acpihelp/Makefile | 8 +- usr.sbin/acpi/acpinames/Makefile | 11 +- usr.sbin/acpi/acpixtract/Makefile | 10 +- usr.sbin/acpi/iasl/Makefile | 3 + 89 files changed, 4177 insertions(+), 2293 deletions(-) copy sys/contrib/dev/acpica/source/components/{debugger/dbfileio.c => utilities/utfileio.c} (60%) create mode 100644 sys/contrib/dev/acpica/source/components/utilities/utprint.c copy sys/contrib/dev/acpica/source/include/platform/{acefi.h => acenvex.h} (72%) create mode 100644 sys/contrib/dev/acpica/source/include/platform/aclinuxex.h copy sys/contrib/dev/acpica/source/os_specific/service_layers/{oslinuxtbl.c => osefitbl.c} (66%) create mode 100644 sys/contrib/dev/acpica/source/os_specific/service_layers/osefixf.c create mode 100644 sys/contrib/dev/acpica/source/os_specific/service_layers/oslibcfs.c diff --git a/sys/contrib/dev/acpica/Makefile b/sys/contrib/dev/acpica/Makefile index 5ee33d7342..80bf37959e 100644 --- a/sys/contrib/dev/acpica/Makefile +++ b/sys/contrib/dev/acpica/Makefile @@ -10,7 +10,13 @@ # code directories. This prevents collisions between different # compilations of the same source file with different compile options. # -BUILD_DIRECTORY_PATH = "generate/unix" -include generate/unix/Makefile.config -include generate/unix/Makefile.common +ifeq ($(OS),efi) + BUILD_DIRECTORY_PATH = "generate/efi" + include generate/efi/Makefile.config + include generate/efi/Makefile.common +else + BUILD_DIRECTORY_PATH = "generate/unix" + include generate/unix/Makefile.config + include generate/unix/Makefile.common +endif diff --git a/sys/contrib/dev/acpica/changes.txt b/sys/contrib/dev/acpica/changes.txt index e93fc4dc7b..3acf4fd281 100644 --- a/sys/contrib/dev/acpica/changes.txt +++ b/sys/contrib/dev/acpica/changes.txt @@ -1,3 +1,104 @@ +---------------------------------------- +27 June 2014. Summary of changes for version 20140627: + +1) ACPICA kernel-resident subsystem: + +Formatted Output: Implemented local versions of standard formatted output +utilities such as printf, etc. Over time, it has been discovered that +there are in fact many portability issues with printf, and the addition +of this feature will fix/prevent these issues once and for all. Some +known issues are summarized below: + +1) Output of 64-bit values is not portable. For example, UINT64 is %ull +for the Linux kernel and is %uI64 for some MSVC versions. +2) Invoking printf consistently in a manner that is portable across both +32-bit and 64-bit platforms is difficult at best in many situations. +3) The output format for pointers varies from system to system (leading +zeros especially), and leads to inconsistent output from ACPICA across +platforms. +4) Certain platform-specific printf formats may conflict with ACPICA use. +5) If there is no local C library available, ACPICA now has local support +for printf. + +-- To address these printf issues in a complete manner, ACPICA now +directly implements a small subset of printf format specifiers, only +those that it requires. Adds a new file, utilities/utprint.c. Lv Zheng. + +Implemented support for ACPICA generation within the EFI environment. +Initially, the AcpiDump utility is supported in the UEFI shell +environment. Lv Zheng. + +Added a new external interface, AcpiLogError, to improve ACPICA +portability. This allows the host to redirect error messages from the +ACPICA utilities. Lv Zheng. + +Added and deployed new OSL file I/O interfaces to improve ACPICA +portability: + AcpiOsOpenFile + AcpiOsCloseFile + AcpiOsReadFile + AcpiOsWriteFile + AcpiOsGetFileOffset + AcpiOsSetFileOffset +There are C library implementations of these functions in the new file +service_layers/oslibcfs.c -- however, the functions can be implemented by +the local host in any way necessary. Lv Zheng. + +Implemented a mechanism to disable/enable ACPI table checksum validation +at runtime. This can be useful when loading tables very early during OS +initialization when it may not be possible to map the entire table in +order to compute the checksum. Lv Zheng. + +Fixed a buffer allocation issue for the Generic Serial Bus support. +Originally, a fixed buffer length was used. This change allows for +variable-length buffers based upon the protocol indicated by the field +access attributes. Reported by Lan Tianyu. Lv Zheng. + +Fixed a problem where an object detached from a namespace node was not +properly terminated/cleared and could cause a circular list problem if +reattached. ACPICA BZ 1063. David Box. + +Fixed a possible recursive lock acquisition in hwregs.c. Rakib Mullick. + +Fixed a possible memory leak in an error return path within the function +AcpiUtCopyIobjectToIobject. ACPICA BZ 1087. Colin Ian King. + +Example Code and Data Size: These are the sizes for the OS-independent +acpica.lib produced by the Microsoft Visual C++ 9.0 32-bit compiler. The +debug version of the code includes the debug output trace mechanism and +has a much larger code and data size. + + Current Release: + Non-Debug Version: 98.7K Code, 27.2K Data, 125.9K Total + Debug Version: 191.7K Code, 79.6K Data, 271.3K Total + Previous Release: + Non-Debug Version: 96.8K Code, 27.2K Data, 124.0K Total + Debug Version: 189.5K Code, 79.7K Data, 269.2K Total + + +2) iASL Compiler/Disassembler and Tools: + +Disassembler: Add dump of ASCII equivalent text within a comment at the +end of each line of the output for the Buffer() ASL operator. + +AcpiDump: Miscellaneous changes: + Fixed repetitive table dump in -n mode. + For older EFI platforms, use the ACPI 1.0 GUID during RSDP search if +the ACPI 2.0 GUID fails. + +iASL: Fixed a problem where the compiler could fault if incorrectly given +an acpidump output file as input. ACPICA BZ 1088. David Box. + +AcpiExec/AcpiNames: Fixed a problem where these utilities could fault if +they are invoked without any arguments. + +Debugger: Fixed a possible memory leak in an error return path. ACPICA BZ +1086. Colin Ian King. + +Disassembler: Cleaned up a block of code that extracts a parent Op +object. Added a comment that explains that the parent is guaranteed to be +valid in this case. ACPICA BZ 1069. + ---------------------------------------- 24 April 2014. Summary of changes for version 20140424: diff --git a/sys/contrib/dev/acpica/generate/unix/acpibin/Makefile b/sys/contrib/dev/acpica/generate/unix/acpibin/Makefile index c33c085b3d..1be484d56c 100644 --- a/sys/contrib/dev/acpica/generate/unix/acpibin/Makefile +++ b/sys/contrib/dev/acpica/generate/unix/acpibin/Makefile @@ -34,6 +34,7 @@ OBJECTS = \ $(OBJDIR)/utalloc.o\ $(OBJDIR)/utbuffer.o\ $(OBJDIR)/utcache.o\ + $(OBJDIR)/utdebug.o\ $(OBJDIR)/utdecode.o\ $(OBJDIR)/utexcep.o\ $(OBJDIR)/utglobal.o\ @@ -41,9 +42,11 @@ OBJECTS = \ $(OBJDIR)/utmath.o\ $(OBJDIR)/utmisc.o\ $(OBJDIR)/utmutex.o\ + $(OBJDIR)/utprint.o\ $(OBJDIR)/utstate.o\ $(OBJDIR)/utstring.o\ $(OBJDIR)/utxferror.o\ + $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixxf.o # diff --git a/sys/contrib/dev/acpica/generate/unix/acpidump/Makefile b/sys/contrib/dev/acpica/generate/unix/acpidump/Makefile index 8a9cda5889..64256ea705 100644 --- a/sys/contrib/dev/acpica/generate/unix/acpidump/Makefile +++ b/sys/contrib/dev/acpica/generate/unix/acpidump/Makefile @@ -33,13 +33,18 @@ OBJECTS = \ $(OBJDIR)/apmain.o\ $(OBJDIR)/cmfsize.o\ $(OBJDIR)/getopt.o\ + $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixdir.o\ $(OBJDIR)/osunixmap.o\ + $(OBJDIR)/osunixxf.o\ $(OBJDIR)/tbprint.o\ $(OBJDIR)/tbxfroot.o\ $(OBJDIR)/utbuffer.o\ + $(OBJDIR)/utdebug.o\ $(OBJDIR)/utexcep.o\ + $(OBJDIR)/utglobal.o\ $(OBJDIR)/utmath.o\ + $(OBJDIR)/utprint.o\ $(OBJDIR)/utstring.o\ $(OBJDIR)/utxferror.o diff --git a/sys/contrib/dev/acpica/generate/unix/acpiexamples/Makefile b/sys/contrib/dev/acpica/generate/unix/acpiexamples/Makefile index c2f3c73f1a..8bcdb9ba0a 100644 --- a/sys/contrib/dev/acpica/generate/unix/acpiexamples/Makefile +++ b/sys/contrib/dev/acpica/generate/unix/acpiexamples/Makefile @@ -20,9 +20,10 @@ PROG = $(OBJDIR)/acpiexamples # vpath %.c \ $(ACPIEXAMPLES)\ - $(ACPICA_DEBUGGER)\ $(ACPICA_DISPATCHER)\ + $(ACPICA_EVENTS)\ $(ACPICA_EXECUTER)\ + $(ACPICA_HARDWARE)\ $(ACPICA_NAMESPACE)\ $(ACPICA_PARSER)\ $(ACPICA_TABLES)\ @@ -51,6 +52,12 @@ OBJECTS = \ $(OBJDIR)/dswload2.o\ $(OBJDIR)/dswscope.o\ $(OBJDIR)/dswstate.o\ + $(OBJDIR)/evhandler.o\ + $(OBJDIR)/evmisc.o\ + $(OBJDIR)/evregion.o\ + $(OBJDIR)/evrgnini.o\ + $(OBJDIR)/evxface.o\ + $(OBJDIR)/evxfregn.o\ $(OBJDIR)/exconfig.o\ $(OBJDIR)/exconvrt.o\ $(OBJDIR)/excreate.o\ @@ -75,8 +82,10 @@ OBJECTS = \ $(OBJDIR)/exstorob.o\ $(OBJDIR)/exsystem.o\ $(OBJDIR)/exutils.o\ + $(OBJDIR)/hwpci.o\ $(OBJDIR)/nsaccess.o\ $(OBJDIR)/nsalloc.o\ + $(OBJDIR)/nsarguments.o\ $(OBJDIR)/nsconvert.o\ $(OBJDIR)/nsdump.o\ $(OBJDIR)/nseval.o\ @@ -85,12 +94,17 @@ OBJECTS = \ $(OBJDIR)/nsnames.o\ $(OBJDIR)/nsobject.o\ $(OBJDIR)/nsparse.o\ + $(OBJDIR)/nspredef.o\ + $(OBJDIR)/nsprepkg.o\ + $(OBJDIR)/nsrepair.o\ + $(OBJDIR)/nsrepair2.o\ $(OBJDIR)/nssearch.o\ $(OBJDIR)/nsutils.o\ $(OBJDIR)/nswalk.o\ $(OBJDIR)/nsxfeval.o\ $(OBJDIR)/nsxfname.o\ $(OBJDIR)/nsxfobj.o\ + $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixxf.o\ $(OBJDIR)/psargs.o\ $(OBJDIR)/psloop.o\ @@ -121,8 +135,11 @@ OBJECTS = \ $(OBJDIR)/utdecode.o\ $(OBJDIR)/utdelete.o\ $(OBJDIR)/uterror.o\ + $(OBJDIR)/uteval.o\ $(OBJDIR)/utexcep.o\ $(OBJDIR)/utglobal.o\ + $(OBJDIR)/utids.o\ + $(OBJDIR)/utinit.o\ $(OBJDIR)/utlock.o\ $(OBJDIR)/utmath.o\ $(OBJDIR)/utmisc.o\ @@ -130,6 +147,9 @@ OBJECTS = \ $(OBJDIR)/utobject.o\ $(OBJDIR)/utosi.o\ $(OBJDIR)/utownerid.o\ + $(OBJDIR)/utpredef.o\ + $(OBJDIR)/utprint.o\ + $(OBJDIR)/utresrc.o\ $(OBJDIR)/utstate.o\ $(OBJDIR)/utstring.o\ $(OBJDIR)/utxface.o\ diff --git a/sys/contrib/dev/acpica/generate/unix/acpiexec/Makefile b/sys/contrib/dev/acpica/generate/unix/acpiexec/Makefile index 84cc97810f..6c5c63222b 100644 --- a/sys/contrib/dev/acpica/generate/unix/acpiexec/Makefile +++ b/sys/contrib/dev/acpica/generate/unix/acpiexec/Makefile @@ -155,6 +155,7 @@ OBJECTS = \ $(OBJDIR)/nsxfeval.o\ $(OBJDIR)/nsxfname.o\ $(OBJDIR)/nsxfobj.o\ + $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixxf.o\ $(OBJDIR)/psargs.o\ $(OBJDIR)/psloop.o\ @@ -201,6 +202,7 @@ OBJECTS = \ $(OBJDIR)/uterror.o\ $(OBJDIR)/uteval.o\ $(OBJDIR)/utexcep.o\ + $(OBJDIR)/utfileio.o\ $(OBJDIR)/utglobal.o\ $(OBJDIR)/utids.o\ $(OBJDIR)/utinit.o\ @@ -212,6 +214,7 @@ OBJECTS = \ $(OBJDIR)/utosi.o\ $(OBJDIR)/utownerid.o\ $(OBJDIR)/utpredef.o\ + $(OBJDIR)/utprint.o\ $(OBJDIR)/utresrc.o\ $(OBJDIR)/utstate.o\ $(OBJDIR)/utstring.o\ diff --git a/sys/contrib/dev/acpica/generate/unix/acpihelp/Makefile b/sys/contrib/dev/acpica/generate/unix/acpihelp/Makefile index da6ee49c99..25c8c0a3c4 100644 --- a/sys/contrib/dev/acpica/generate/unix/acpihelp/Makefile +++ b/sys/contrib/dev/acpica/generate/unix/acpihelp/Makefile @@ -21,7 +21,8 @@ PROG = $(OBJDIR)/acpihelp vpath %.c \ $(ACPIHELP)\ $(ACPICA_COMMON)\ - $(ACPICA_UTILITIES) + $(ACPICA_UTILITIES)\ + $(ACPICA_OSL) HEADERS = \ $(wildcard $(ACPIHELP)/*.h) @@ -35,8 +36,14 @@ OBJECTS = \ $(OBJDIR)/ahpredef.o\ $(OBJDIR)/ahmain.o\ $(OBJDIR)/getopt.o\ + $(OBJDIR)/oslibcfs.o\ + $(OBJDIR)/osunixxf.o\ + $(OBJDIR)/utdebug.o\ $(OBJDIR)/utexcep.o\ - $(OBJDIR)/utpredef.o + $(OBJDIR)/utglobal.o\ + $(OBJDIR)/utmath.o\ + $(OBJDIR)/utpredef.o\ + $(OBJDIR)/utprint.o # # Flags specific to acpihelp diff --git a/sys/contrib/dev/acpica/generate/unix/acpinames/Makefile b/sys/contrib/dev/acpica/generate/unix/acpinames/Makefile index 00a0026c2b..27c7b9579f 100644 --- a/sys/contrib/dev/acpica/generate/unix/acpinames/Makefile +++ b/sys/contrib/dev/acpica/generate/unix/acpinames/Makefile @@ -21,7 +21,6 @@ PROG = $(OBJDIR)/acpinames # vpath %.c \ $(ACPINAMES)\ - $(ACPICA_DEBUGGER)\ $(ACPICA_DISPATCHER)\ $(ACPICA_EXECUTER)\ $(ACPICA_NAMESPACE)\ @@ -39,7 +38,6 @@ OBJECTS = \ $(OBJDIR)/anstubs.o\ $(OBJDIR)/antables.o\ $(OBJDIR)/cmfsize.o\ - $(OBJDIR)/dbfileio.o\ $(OBJDIR)/dsfield.o\ $(OBJDIR)/dsmthdat.o\ $(OBJDIR)/dsobject.o\ @@ -49,9 +47,12 @@ OBJECTS = \ $(OBJDIR)/dswscope.o\ $(OBJDIR)/dswstate.o\ $(OBJDIR)/excreate.o\ + $(OBJDIR)/exdump.o\ + $(OBJDIR)/exmutex.o\ $(OBJDIR)/exnames.o\ $(OBJDIR)/exresnte.o\ $(OBJDIR)/exresolv.o\ + $(OBJDIR)/exsystem.o\ $(OBJDIR)/exutils.o\ $(OBJDIR)/getopt.o\ $(OBJDIR)/nsaccess.o\ @@ -68,6 +69,7 @@ OBJECTS = \ $(OBJDIR)/nsxfeval.o\ $(OBJDIR)/nsxfname.o\ $(OBJDIR)/nsxfobj.o\ + $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/osunixxf.o\ $(OBJDIR)/psargs.o\ $(OBJDIR)/psloop.o\ @@ -91,13 +93,18 @@ OBJECTS = \ $(OBJDIR)/tbxfroot.o\ $(OBJDIR)/utaddress.o\ $(OBJDIR)/utalloc.o\ + $(OBJDIR)/utbuffer.o\ $(OBJDIR)/utcache.o\ $(OBJDIR)/utdebug.o\ $(OBJDIR)/utdecode.o\ $(OBJDIR)/utdelete.o\ $(OBJDIR)/uterror.o\ + $(OBJDIR)/uteval.o\ $(OBJDIR)/utexcep.o\ + $(OBJDIR)/utfileio.o\ $(OBJDIR)/utglobal.o\ + $(OBJDIR)/utids.o\ + $(OBJDIR)/utinit.o\ $(OBJDIR)/utlock.o\ $(OBJDIR)/utmath.o\ $(OBJDIR)/utmisc.o\ @@ -105,6 +112,7 @@ OBJECTS = \ $(OBJDIR)/utobject.o\ $(OBJDIR)/utosi.o\ $(OBJDIR)/utownerid.o\ + $(OBJDIR)/utprint.o\ $(OBJDIR)/utstate.o\ $(OBJDIR)/utstring.o\ $(OBJDIR)/utxface.o\ diff --git a/sys/contrib/dev/acpica/generate/unix/acpisrc/Makefile b/sys/contrib/dev/acpica/generate/unix/acpisrc/Makefile index 50199cee63..5d40c095e9 100644 --- a/sys/contrib/dev/acpica/generate/unix/acpisrc/Makefile +++ b/sys/contrib/dev/acpica/generate/unix/acpisrc/Makefile @@ -19,6 +19,7 @@ PROG = $(OBJDIR)/acpisrc # vpath %.c \ $(ACPISRC)\ + $(ACPICA_UTILITIES)\ $(ACPICA_COMMON)\ $(ACPICA_OSL) @@ -33,9 +34,17 @@ OBJECTS = \ $(OBJDIR)/asremove.o\ $(OBJDIR)/astable.o\ $(OBJDIR)/asutils.o\ - $(OBJDIR)/cmfsize.o\ + $(OBJDIR)/cmfsize.o\ $(OBJDIR)/getopt.o \ - $(OBJDIR)/osunixdir.o + $(OBJDIR)/oslibcfs.o\ + $(OBJDIR)/osunixdir.o\ + $(OBJDIR)/osunixxf.o\ + $(OBJDIR)/utdebug.o\ + $(OBJDIR)/utexcep.o\ + $(OBJDIR)/utglobal.o\ + $(OBJDIR)/utmath.o\ + $(OBJDIR)/utprint.o\ + $(OBJDIR)/utxferror.o # # Compile flags specific to acpisrc diff --git a/sys/contrib/dev/acpica/generate/unix/acpixtract/Makefile b/sys/contrib/dev/acpica/generate/unix/acpixtract/Makefile index 1e5b1013d4..750583e521 100644 --- a/sys/contrib/dev/acpica/generate/unix/acpixtract/Makefile +++ b/sys/contrib/dev/acpica/generate/unix/acpixtract/Makefile @@ -19,7 +19,9 @@ PROG = $(OBJDIR)/acpixtract # vpath %.c \ $(ACPIXTRACT)\ - $(ACPICA_COMMON) + $(ACPICA_UTILITIES)\ + $(ACPICA_COMMON)\ + $(ACPICA_OSL) HEADERS = \ $(wildcard $(ACPIXTRACT)/*.h) @@ -27,7 +29,15 @@ HEADERS = \ OBJECTS = \ $(OBJDIR)/acpixtract.o\ $(OBJDIR)/axmain.o\ - $(OBJDIR)/getopt.o + $(OBJDIR)/getopt.o\ + $(OBJDIR)/oslibcfs.o\ + $(OBJDIR)/osunixxf.o\ + $(OBJDIR)/utdebug.o\ + $(OBJDIR)/utexcep.o\ + $(OBJDIR)/utglobal.o\ + $(OBJDIR)/utmath.o\ + $(OBJDIR)/utprint.o\ + $(OBJDIR)/utxferror.o # # Flags specific to acpixtract diff --git a/sys/contrib/dev/acpica/generate/unix/iasl/Makefile b/sys/contrib/dev/acpica/generate/unix/iasl/Makefile index 8cc8d814b7..7fd7bbe2a2 100644 --- a/sys/contrib/dev/acpica/generate/unix/iasl/Makefile +++ b/sys/contrib/dev/acpica/generate/unix/iasl/Makefile @@ -160,6 +160,7 @@ OBJECTS = \ $(OBJDIR)/nswalk.o\ $(OBJDIR)/nsxfobj.o\ $(OBJDIR)/osunixxf.o\ + $(OBJDIR)/oslibcfs.o\ $(OBJDIR)/prexpress.o\ $(OBJDIR)/prmacros.o\ $(OBJDIR)/prscan.o\ @@ -190,6 +191,7 @@ OBJECTS = \ $(OBJDIR)/utdelete.o\ $(OBJDIR)/uterror.o\ $(OBJDIR)/utexcep.o\ + $(OBJDIR)/utfileio.o\ $(OBJDIR)/utglobal.o\ $(OBJDIR)/utinit.o\ $(OBJDIR)/utlock.o\ @@ -199,6 +201,7 @@ OBJECTS = \ $(OBJDIR)/utobject.o\ $(OBJDIR)/utownerid.o\ $(OBJDIR)/utpredef.o\ + $(OBJDIR)/utprint.o\ $(OBJDIR)/utresrc.o\ $(OBJDIR)/utstate.o\ $(OBJDIR)/utstring.o\ diff --git a/sys/contrib/dev/acpica/source/common/ahpredef.c b/sys/contrib/dev/acpica/source/common/ahpredef.c index 2ac216fa2f..6f4258be57 100644 --- a/sys/contrib/dev/acpica/source/common/ahpredef.c +++ b/sys/contrib/dev/acpica/source/common/ahpredef.c @@ -217,7 +217,6 @@ const AH_PREDEFINED_NAME AslPredefinedInfo[] = AH_PREDEF ("_PR3", "Power Resources for D3hot", "Returns a list of dependent power resources to enter state D3hot"), AH_PREDEF ("_PRE", "Power Resources for Enumeration", "Returns a list of dependent power resources to enumerate devices on a bus"), AH_PREDEF ("_PRL", "Power Source Redundancy List", "Returns a list of power source devices in the same redundancy grouping"), - AH_PREDEF ("_PRP", "Device Properties", "Returns a list of device property information"), AH_PREDEF ("_PRS", "Possible Resource Settings", "Returns a list of a device's possible resource settings"), AH_PREDEF ("_PRT", "PCI Routing Table", "Returns a list of PCI interrupt mappings"), AH_PREDEF ("_PRW", "Power Resources for Wake", "Returns a list of dependent power resources for waking"), diff --git a/sys/contrib/dev/acpica/source/common/cmfsize.c b/sys/contrib/dev/acpica/source/common/cmfsize.c index c8d5a56b6f..904d7d8da8 100644 --- a/sys/contrib/dev/acpica/source/common/cmfsize.c +++ b/sys/contrib/dev/acpica/source/common/cmfsize.c @@ -59,33 +59,34 @@ * RETURN: File Size. On error, -1 (ACPI_UINT32_MAX) * * DESCRIPTION: Get the size of a file. Uses seek-to-EOF. File must be open. - * Does not disturb the current file pointer. Uses perror for - * error messages. + * Does not disturb the current file pointer. * ******************************************************************************/ UINT32 CmGetFileSize ( - FILE *File) + ACPI_FILE File) { long FileSize; long CurrentOffset; + ACPI_STATUS Status; /* Save the current file pointer, seek to EOF to obtain file size */ - CurrentOffset = ftell (File); + CurrentOffset = AcpiOsGetFileOffset (File); if (CurrentOffset < 0) { goto OffsetError; } - if (fseek (File, 0, SEEK_END)) + Status = AcpiOsSetFileOffset (File, 0, ACPI_FILE_END); + if (ACPI_FAILURE (Status)) { goto SeekError; } - FileSize = ftell (File); + FileSize = AcpiOsGetFileOffset (File); if (FileSize < 0) { goto OffsetError; @@ -93,7 +94,8 @@ CmGetFileSize ( /* Restore original file pointer */ - if (fseek (File, CurrentOffset, SEEK_SET)) + Status = AcpiOsSetFileOffset (File, CurrentOffset, ACPI_FILE_BEGIN); + if (ACPI_FAILURE (Status)) { goto SeekError; } @@ -102,10 +104,10 @@ CmGetFileSize ( OffsetError: - perror ("Could not get file offset"); + AcpiLogError ("Could not get file offset"); return (ACPI_UINT32_MAX); SeekError: - perror ("Could not seek file"); + AcpiLogError ("Could not set file offset"); return (ACPI_UINT32_MAX); } diff --git a/sys/contrib/dev/acpica/source/common/getopt.c b/sys/contrib/dev/acpica/source/common/getopt.c index bca9a6f3e7..5ae1e0aa43 100644 --- a/sys/contrib/dev/acpica/source/common/getopt.c +++ b/sys/contrib/dev/acpica/source/common/getopt.c @@ -51,14 +51,12 @@ * "f|" - Option has required single-char sub-options */ -#include -#include #include "acpi.h" #include "accommon.h" #include "acapps.h" #define ACPI_OPTION_ERROR(msg, badchar) \ - if (AcpiGbl_Opterr) {fprintf (stderr, "%s%c\n", msg, badchar);} + if (AcpiGbl_Opterr) {AcpiLogError ("%s%c\n", msg, badchar);} int AcpiGbl_Opterr = 1; @@ -123,7 +121,7 @@ AcpiGetoptArgument ( * PARAMETERS: argc, argv - from main * opts - options info list * - * RETURN: Option character or EOF + * RETURN: Option character or ACPI_OPT_END * * DESCRIPTION: Get the next option * @@ -145,12 +143,12 @@ AcpiGetopt( argv[AcpiGbl_Optind][0] != '-' || argv[AcpiGbl_Optind][1] == '\0') { - return (EOF); + return (ACPI_OPT_END); } - else if (strcmp (argv[AcpiGbl_Optind], "--") == 0) + else if (ACPI_STRCMP (argv[AcpiGbl_Optind], "--") == 0) { AcpiGbl_Optind++; - return (EOF); + return (ACPI_OPT_END); } } @@ -161,7 +159,7 @@ AcpiGetopt( /* Make sure that the option is legal */ if (CurrentChar == ':' || - (OptsPtr = strchr (opts, CurrentChar)) == NULL) + (OptsPtr = ACPI_STRCHR (opts, CurrentChar)) == NULL) { ACPI_OPTION_ERROR ("Illegal option: -", CurrentChar); diff --git a/sys/contrib/dev/acpica/source/compiler/aslanalyze.c b/sys/contrib/dev/acpica/source/compiler/aslanalyze.c index 940f220b94..112c121398 100644 --- a/sys/contrib/dev/acpica/source/compiler/aslanalyze.c +++ b/sys/contrib/dev/acpica/source/compiler/aslanalyze.c @@ -569,51 +569,3 @@ ApCheckRegMethod ( AslError (ASL_WARNING, ASL_MSG_NO_REGION, Op, NULL); } - - -/******************************************************************************* - * - * FUNCTION: ApFindNameInScope - * - * PARAMETERS: Name - Name to search for - * Op - Current parse op - * - * RETURN: TRUE if name found in the same scope as Op. - * - * DESCRIPTION: Determine if a name appears in the same scope as Op, as either - * a Method() or a Name(). - * - ******************************************************************************/ - -BOOLEAN -ApFindNameInScope ( - char *Name, - ACPI_PARSE_OBJECT *Op) -{ - ACPI_PARSE_OBJECT *Next; - ACPI_PARSE_OBJECT *Parent; - - - /* Get the start of the current scope */ - - Parent = Op->Asl.Parent; - Next = Parent->Asl.Child; - - /* Search entire scope for a match to the name */ - - while (Next) - { - if ((Next->Asl.ParseOpcode == PARSEOP_METHOD) || - (Next->Asl.ParseOpcode == PARSEOP_NAME)) - { - if (ACPI_COMPARE_NAME (Name, Next->Asl.NameSeg)) - { - return (TRUE); - } - } - - Next = Next->Asl.Next; - } - - return (FALSE); -} diff --git a/sys/contrib/dev/acpica/source/compiler/aslcompiler.h b/sys/contrib/dev/acpica/source/compiler/aslcompiler.h index 1f94245a44..40dcd69278 100644 --- a/sys/contrib/dev/acpica/source/compiler/aslcompiler.h +++ b/sys/contrib/dev/acpica/source/compiler/aslcompiler.h @@ -275,11 +275,6 @@ void ApCheckRegMethod ( ACPI_PARSE_OBJECT *Op); -BOOLEAN -ApFindNameInScope ( - char *Name, - ACPI_PARSE_OBJECT *Op); - /* * aslerror - error handling/reporting @@ -350,10 +345,6 @@ void AeClearErrorLog ( void); -ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( - void); - /* * asllisting - generate all "listing" type files diff --git a/sys/contrib/dev/acpica/source/compiler/aslmain.c b/sys/contrib/dev/acpica/source/compiler/aslmain.c index 6e92d53d54..3034281b3d 100644 --- a/sys/contrib/dev/acpica/source/compiler/aslmain.c +++ b/sys/contrib/dev/acpica/source/compiler/aslmain.c @@ -341,6 +341,7 @@ main ( return (-1); } + AcpiOsInitialize (); ACPI_DEBUG_INITIALIZE (); /* For debug version only */ /* Initialize preprocessor and compiler before command line processing */ diff --git a/sys/contrib/dev/acpica/source/compiler/aslmessages.c b/sys/contrib/dev/acpica/source/compiler/aslmessages.c index c9d196f170..926bc465cb 100644 --- a/sys/contrib/dev/acpica/source/compiler/aslmessages.c +++ b/sys/contrib/dev/acpica/source/compiler/aslmessages.c @@ -233,7 +233,6 @@ const char *AslCompilerMsgs [] = /* ASL_MSG_WRITE */ "Could not write file", /* ASL_MSG_RANGE */ "Constant out of range", /* ASL_MSG_BUFFER_ALLOCATION */ "Could not allocate line buffer", -/* ASL_MSG_MISSING_DEPENDENCY */ "Missing dependency" }; /* Table compiler */ diff --git a/sys/contrib/dev/acpica/source/compiler/aslmessages.h b/sys/contrib/dev/acpica/source/compiler/aslmessages.h index 48ebcbfc32..851d46c59c 100644 --- a/sys/contrib/dev/acpica/source/compiler/aslmessages.h +++ b/sys/contrib/dev/acpica/source/compiler/aslmessages.h @@ -235,7 +235,6 @@ typedef enum ASL_MSG_WRITE, ASL_MSG_RANGE, ASL_MSG_BUFFER_ALLOCATION, - ASL_MSG_MISSING_DEPENDENCY, /* These messages are used by the Data Table compiler only */ diff --git a/sys/contrib/dev/acpica/source/compiler/aslmethod.c b/sys/contrib/dev/acpica/source/compiler/aslmethod.c index 9b0a7a1a13..a9b0640827 100644 --- a/sys/contrib/dev/acpica/source/compiler/aslmethod.c +++ b/sys/contrib/dev/acpica/source/compiler/aslmethod.c @@ -108,17 +108,6 @@ MtMethodAnalysisWalkBegin ( WalkInfo->MethodStack = MethodInfo; - /* Special handling for _PRP, must have a _HID also */ - - if (!ACPI_STRCMP (METHOD_NAME__PRP, Op->Asl.NameSeg)) - { - if (!ApFindNameInScope (METHOD_NAME__HID, Op)) - { - AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, - "_PRP requires _HID in same scope"); - } - } - /* Get the name node */ Next = Op->Asl.Child; @@ -424,15 +413,6 @@ MtMethodAnalysisWalkBegin ( } } - else if (!ACPI_STRCMP (METHOD_NAME__PRP, Op->Asl.NameSeg)) - { - if (!ApFindNameInScope (METHOD_NAME__HID, Op)) - { - AslError (ASL_WARNING, ASL_MSG_MISSING_DEPENDENCY, Op, - "_PRP requires _HID in same scope"); - } - } - break; default: diff --git a/sys/contrib/dev/acpica/source/compiler/asloptions.c b/sys/contrib/dev/acpica/source/compiler/asloptions.c index 8d52826f1a..039fc7d3d4 100644 --- a/sys/contrib/dev/acpica/source/compiler/asloptions.c +++ b/sys/contrib/dev/acpica/source/compiler/asloptions.c @@ -168,7 +168,7 @@ AslDoOptions ( /* Get the command line options */ - while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j) + while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j) { case '@': /* Begin a response file */ diff --git a/sys/contrib/dev/acpica/source/compiler/aslstubs.c b/sys/contrib/dev/acpica/source/compiler/aslstubs.c index 589edb21c1..6bbb89ac34 100644 --- a/sys/contrib/dev/acpica/source/compiler/aslstubs.c +++ b/sys/contrib/dev/acpica/source/compiler/aslstubs.c @@ -57,13 +57,6 @@ * Things like Events, Global Lock, etc. are not used * by the compiler, so they are stubbed out here. */ -ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( - void) -{ - return (0); -} - void AcpiNsExecModuleCodeList ( void) @@ -232,21 +225,3 @@ AcpiTbFindTable ( { return (AE_SUPPORT); } - -/* OSL interfaces */ - -ACPI_THREAD_ID -AcpiOsGetThreadId ( - void) -{ - return (1); -} - -ACPI_STATUS -AcpiOsExecute ( - ACPI_EXECUTE_TYPE Type, - ACPI_OSD_EXEC_CALLBACK Function, - void *Context) -{ - return (AE_SUPPORT); -} diff --git a/sys/contrib/dev/acpica/source/components/debugger/dbfileio.c b/sys/contrib/dev/acpica/source/components/debugger/dbfileio.c index a09c1de8cb..ee4ba15f0f 100644 --- a/sys/contrib/dev/acpica/source/components/debugger/dbfileio.c +++ b/sys/contrib/dev/acpica/source/components/debugger/dbfileio.c @@ -46,14 +46,7 @@ #include "acpi.h" #include "accommon.h" #include "acdebug.h" - -#ifdef ACPI_APPLICATION #include "actables.h" -#endif - -#ifdef ACPI_ASL_COMPILER -#include "aslcompiler.h" -#endif #if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER) @@ -62,18 +55,6 @@ #ifdef ACPI_DEBUGGER -/* Local prototypes */ - -#ifdef ACPI_APPLICATION - -static ACPI_STATUS -AcpiDbCheckTextModeCorruption ( - UINT8 *Table, - UINT32 TableLength, - UINT32 FileLength); - -#endif - /******************************************************************************* * * FUNCTION: AcpiDbCloseDebugFile @@ -144,245 +125,6 @@ AcpiDbOpenDebugFile ( #ifdef ACPI_APPLICATION #include "acapps.h" -/******************************************************************************* - * - * FUNCTION: AcpiDbCheckTextModeCorruption - * - * PARAMETERS: Table - Table buffer - * TableLength - Length of table from the table header - * FileLength - Length of the file that contains the table - * - * RETURN: Status - * - * DESCRIPTION: Check table for text mode file corruption where all linefeed - * characters (LF) have been replaced by carriage return linefeed - * pairs (CR/LF). - * - ******************************************************************************/ - -static ACPI_STATUS -AcpiDbCheckTextModeCorruption ( - UINT8 *Table, - UINT32 TableLength, - UINT32 FileLength) -{ - UINT32 i; - UINT32 Pairs = 0; - - - if (TableLength != FileLength) - { - ACPI_WARNING ((AE_INFO, - "File length (0x%X) is not the same as the table length (0x%X)", - FileLength, TableLength)); - } - - /* Scan entire table to determine if each LF has been prefixed with a CR */ - - for (i = 1; i < FileLength; i++) - { - if (Table[i] == 0x0A) - { - if (Table[i - 1] != 0x0D) - { - /* The LF does not have a preceding CR, table not corrupted */ - - return (AE_OK); - } - else - { - /* Found a CR/LF pair */ - - Pairs++; - } - i++; - } - } - - if (!Pairs) - { - return (AE_OK); - } - - /* - * Entire table scanned, each CR is part of a CR/LF pair -- - * meaning that the table was treated as a text file somewhere. - * - * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the - * original table are left untouched by the text conversion process -- - * meaning that we cannot simply replace CR/LF pairs with LFs. - */ - AcpiOsPrintf ("Table has been corrupted by text mode conversion\n"); - AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs); - AcpiOsPrintf ("Table cannot be repaired!\n"); - return (AE_BAD_VALUE); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiDbReadTable - * - * PARAMETERS: fp - File that contains table - * Table - Return value, buffer with table - * TableLength - Return value, length of table - * - * RETURN: Status - * - * DESCRIPTION: Load the DSDT from the file pointer - * - ******************************************************************************/ - -static ACPI_STATUS -AcpiDbReadTable ( - FILE *fp, - ACPI_TABLE_HEADER **Table, - UINT32 *TableLength) -{ - ACPI_TABLE_HEADER TableHeader; - UINT32 Actual; - ACPI_STATUS Status; - UINT32 FileSize; - BOOLEAN StandardHeader = TRUE; - - - /* Get the file size */ - - FileSize = CmGetFileSize (fp); - if (FileSize == ACPI_UINT32_MAX) - { - return (AE_ERROR); - } - - if (FileSize < 4) - { - return (AE_BAD_HEADER); - } - - /* Read the signature */ - - if (fread (&TableHeader, 1, 4, fp) != 4) - { - AcpiOsPrintf ("Could not read the table signature\n"); - return (AE_BAD_HEADER); - } - - fseek (fp, 0, SEEK_SET); - - /* The RSDP table does not have standard ACPI header */ - - if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ")) - { - *TableLength = FileSize; - StandardHeader = FALSE; - } - else - { - /* Read the table header */ - - if (fread (&TableHeader, 1, sizeof (ACPI_TABLE_HEADER), fp) != - sizeof (ACPI_TABLE_HEADER)) - { - AcpiOsPrintf ("Could not read the table header\n"); - return (AE_BAD_HEADER); - } - -#if 0 - /* Validate the table header/length */ - - Status = AcpiTbValidateTableHeader (&TableHeader); - if (ACPI_FAILURE (Status)) - { - AcpiOsPrintf ("Table header is invalid!\n"); - return (Status); - } -#endif - - /* File size must be at least as long as the Header-specified length */ - - if (TableHeader.Length > FileSize) - { - AcpiOsPrintf ( - "TableHeader length [0x%X] greater than the input file size [0x%X]\n", - TableHeader.Length, FileSize); - -#ifdef ACPI_ASL_COMPILER - Status = FlCheckForAscii (fp, NULL, FALSE); - if (ACPI_SUCCESS (Status)) - { - AcpiOsPrintf ("File appears to be ASCII only, must be binary\n", - TableHeader.Length, FileSize); - } -#endif - return (AE_BAD_HEADER); - } - -#ifdef ACPI_OBSOLETE_CODE - /* We only support a limited number of table types */ - - if (!ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_DSDT) && - !ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_PSDT) && - !ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_SSDT)) - { - AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n", - (char *) TableHeader.Signature); - ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER)); - return (AE_ERROR); - } -#endif - - *TableLength = TableHeader.Length; - } - - /* Allocate a buffer for the table */ - - *Table = AcpiOsAllocate ((size_t) FileSize); - if (!*Table) - { - AcpiOsPrintf ( - "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n", - TableHeader.Signature, *TableLength); - return (AE_NO_MEMORY); - } - - /* Get the rest of the table */ - - fseek (fp, 0, SEEK_SET); - Actual = fread (*Table, 1, (size_t) FileSize, fp); - if (Actual == FileSize) - { - if (StandardHeader) - { - /* Now validate the checksum */ - - Status = AcpiTbVerifyChecksum ((void *) *Table, - ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length); - - if (Status == AE_BAD_CHECKSUM) - { - Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table, - FileSize, (*Table)->Length); - return (Status); - } - } - return (AE_OK); - } - - if (Actual > 0) - { - AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n", - FileSize, Actual); - return (AE_OK); - } - - AcpiOsPrintf ("Error - could not read the table file\n"); - AcpiOsFree (*Table); - *Table = NULL; - *TableLength = 0; - return (AE_ERROR); -} - - /******************************************************************************* * * FUNCTION: AeLocalLoadTable @@ -456,62 +198,6 @@ AeLocalLoadTable ( return_ACPI_STATUS (Status); } - - -/******************************************************************************* - * - * FUNCTION: AcpiDbReadTableFromFile - * - * PARAMETERS: Filename - File where table is located - * Table - Where a pointer to the table is returned - * - * RETURN: Status - * - * DESCRIPTION: Get an ACPI table from a file - * - ******************************************************************************/ - -ACPI_STATUS -AcpiDbReadTableFromFile ( - char *Filename, - ACPI_TABLE_HEADER **Table) -{ - FILE *File; - UINT32 FileSize; - UINT32 TableLength; - ACPI_STATUS Status = AE_ERROR; - - - /* Open the file, get current size */ - - File = fopen (Filename, "rb"); - if (!File) - { - perror ("Could not open input file"); - return (Status); - } - - FileSize = CmGetFileSize (File); - if (FileSize == ACPI_UINT32_MAX) - { - goto Exit; - } - - /* Get the entire file */ - - fprintf (stderr, "Loading Acpi table from file %10s - Length %.8u (%06X)\n", - Filename, FileSize, FileSize); - - Status = AcpiDbReadTable (File, Table, &TableLength); - if (ACPI_FAILURE (Status)) - { - AcpiOsPrintf ("Could not get table from the file\n"); - } - -Exit: - fclose(File); - return (Status); - } #endif @@ -539,7 +225,7 @@ AcpiDbGetTableFromFile ( BOOLEAN IsAmlTable = TRUE; - Status = AcpiDbReadTableFromFile (Filename, &Table); + Status = AcpiUtReadTableFromFile (Filename, &Table); if (ACPI_FAILURE (Status)) { return (Status); diff --git a/sys/contrib/dev/acpica/source/components/debugger/dbtest.c b/sys/contrib/dev/acpica/source/components/debugger/dbtest.c index d88372b925..33ee4e4421 100644 --- a/sys/contrib/dev/acpica/source/components/debugger/dbtest.c +++ b/sys/contrib/dev/acpica/source/components/debugger/dbtest.c @@ -1042,6 +1042,7 @@ AcpiDbEvaluateOnePredefinedName ( Status = AcpiGetObjectInfo (ObjHandle, &ObjInfo); if (ACPI_FAILURE (Status)) { + ACPI_FREE (Pathname); return (Status); } diff --git a/sys/contrib/dev/acpica/source/components/disassembler/dmbuffer.c b/sys/contrib/dev/acpica/source/components/disassembler/dmbuffer.c index 85f0618bbd..739fb44a18 100644 --- a/sys/contrib/dev/acpica/source/components/disassembler/dmbuffer.c +++ b/sys/contrib/dev/acpica/source/components/disassembler/dmbuffer.c @@ -71,6 +71,8 @@ AcpiDmPldBuffer ( UINT8 *ByteData, UINT32 ByteCount); +#define ACPI_BUFFER_BYTES_PER_LINE 8 + /******************************************************************************* * @@ -94,6 +96,9 @@ AcpiDmDisasmByteList ( UINT32 ByteCount) { UINT32 i; + UINT32 j; + UINT32 CurrentIndex; + UINT8 BufChar; if (!ByteCount) @@ -101,39 +106,68 @@ AcpiDmDisasmByteList ( return; } - /* Dump the byte list */ - - for (i = 0; i < ByteCount; i++) + for (i = 0; i < ByteCount; i += ACPI_BUFFER_BYTES_PER_LINE) { - /* New line every 8 bytes */ + /* Line indent and offset prefix for each new line */ + + AcpiDmIndent (Level); + if (ByteCount > ACPI_BUFFER_BYTES_PER_LINE) + { + AcpiOsPrintf ("/* %04X */ ", i); + } + + /* Dump the actual hex values */ - if (((i % 8) == 0) && (i < ByteCount)) + for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++) { - if (i > 0) + CurrentIndex = i + j; + if (CurrentIndex >= ByteCount) { - AcpiOsPrintf ("\n"); + /* Dump fill spaces */ + + AcpiOsPrintf (" "); + continue; } - AcpiDmIndent (Level); - if (ByteCount > 8) + AcpiOsPrintf (" 0x%2.2X", ByteData[CurrentIndex]); + + /* Add comma if there are more bytes to display */ + + if (CurrentIndex < (ByteCount - 1)) { - AcpiOsPrintf ("/* %04X */ ", i); + AcpiOsPrintf (","); + } + else + { + AcpiOsPrintf (" "); } } - AcpiOsPrintf (" 0x%2.2X", (UINT32) ByteData[i]); - - /* Add comma if there are more bytes to display */ + /* Dump the ASCII equivalents within a comment */ - if (i < (ByteCount -1)) + AcpiOsPrintf (" /* "); + for (j = 0; j < ACPI_BUFFER_BYTES_PER_LINE; j++) { - AcpiOsPrintf (","); + CurrentIndex = i + j; + if (CurrentIndex >= ByteCount) + { + break; + } + + BufChar = ByteData[CurrentIndex]; + if (ACPI_IS_PRINT (BufChar)) + { + AcpiOsPrintf ("%c", BufChar); + } + else + { + AcpiOsPrintf ("."); + } } - } - if (Level) - { - AcpiOsPrintf ("\n"); + /* Finished with this line */ + + AcpiOsPrintf (" */\n"); } } diff --git a/sys/contrib/dev/acpica/source/components/disassembler/dmwalk.c b/sys/contrib/dev/acpica/source/components/disassembler/dmwalk.c index 3cf74b38c4..0aa305282a 100644 --- a/sys/contrib/dev/acpica/source/components/disassembler/dmwalk.c +++ b/sys/contrib/dev/acpica/source/components/disassembler/dmwalk.c @@ -957,6 +957,13 @@ AcpiDmAscendingOp ( return (AE_OK); } + /* + * The parent Op is guaranteed to be valid because of the flag + * ACPI_PARSEOP_PARAMLIST -- which means that this op is part of + * a parameter list and thus has a valid parent. + */ + ParentOp = Op->Common.Parent; + /* * Just completed a parameter node for something like "Buffer (param)". * Close the paren and open up the term list block with a brace @@ -965,25 +972,24 @@ AcpiDmAscendingOp ( { AcpiOsPrintf (")"); - /* Emit description comment for Name() with a predefined ACPI name */ - - ParentOp = Op->Common.Parent; - if (ParentOp) + /* + * Emit a description comment for a Name() operator that is a + * predefined ACPI name. Must check the grandparent. + */ + ParentOp = ParentOp->Common.Parent; + if (ParentOp && + (ParentOp->Asl.AmlOpcode == AML_NAME_OP)) { - ParentOp = ParentOp->Common.Parent; - if (ParentOp && ParentOp->Asl.AmlOpcode == AML_NAME_OP) - { - AcpiDmPredefinedDescription (ParentOp); - } + AcpiDmPredefinedDescription (ParentOp); } + AcpiOsPrintf ("\n"); AcpiDmIndent (Level - 1); AcpiOsPrintf ("{\n"); } else { - Op->Common.Parent->Common.DisasmFlags |= - ACPI_PARSEOP_EMPTY_TERMLIST; + ParentOp->Common.DisasmFlags |= ACPI_PARSEOP_EMPTY_TERMLIST; AcpiOsPrintf (") {"); } } diff --git a/sys/contrib/dev/acpica/source/components/executer/exfield.c b/sys/contrib/dev/acpica/source/components/executer/exfield.c index aedc8d9fae..a1de0ca237 100644 --- a/sys/contrib/dev/acpica/source/components/executer/exfield.c +++ b/sys/contrib/dev/acpica/source/components/executer/exfield.c @@ -48,11 +48,80 @@ #include "accommon.h" #include "acdispat.h" #include "acinterp.h" +#include "amlcode.h" #define _COMPONENT ACPI_EXECUTER ACPI_MODULE_NAME ("exfield") +/* Local prototypes */ + +static UINT32 +AcpiExGetSerialAccessLength ( + UINT32 AccessorType, + UINT32 AccessLength); + + +/******************************************************************************* + * + * FUNCTION: AcpiExGetSerialAccessLength + * + * PARAMETERS: AccessorType - The type of the protocol indicated by region + * field access attributes + * AccessLength - The access length of the region field + * + * RETURN: Decoded access length + * + * DESCRIPTION: This routine returns the length of the GenericSerialBus + * protocol bytes + * + ******************************************************************************/ + +static UINT32 +AcpiExGetSerialAccessLength ( + UINT32 AccessorType, + UINT32 AccessLength) +{ + UINT32 Length; + + + switch (AccessorType) + { + case AML_FIELD_ATTRIB_QUICK: + + Length = 0; + break; + + case AML_FIELD_ATTRIB_SEND_RCV: + case AML_FIELD_ATTRIB_BYTE: + + Length = 1; + break; + + case AML_FIELD_ATTRIB_WORD: + case AML_FIELD_ATTRIB_WORD_CALL: + + Length = 2; + break; + + case AML_FIELD_ATTRIB_MULTIBYTE: + case AML_FIELD_ATTRIB_RAW_BYTES: + case AML_FIELD_ATTRIB_RAW_PROCESS: + + Length = AccessLength; + break; + + case AML_FIELD_ATTRIB_BLOCK: + case AML_FIELD_ATTRIB_BLOCK_CALL: + default: + + Length = ACPI_GSBUS_BUFFER_SIZE - 2; + break; + } + + return (Length); +} + /******************************************************************************* * @@ -80,6 +149,7 @@ AcpiExReadDataFromField ( ACPI_SIZE Length; void *Buffer; UINT32 Function; + UINT16 AccessorType; ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField, ObjDesc); @@ -129,8 +199,20 @@ AcpiExReadDataFromField ( } else if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS) { - Length = ACPI_GSBUS_BUFFER_SIZE; - Function = ACPI_READ | (ObjDesc->Field.Attribute << 16); + AccessorType = ObjDesc->Field.Attribute; + Length = AcpiExGetSerialAccessLength (AccessorType, + ObjDesc->Field.AccessLength); + + /* + * Add additional 2 bytes for modeled GenericSerialBus data buffer: + * typedef struct { + * BYTEStatus; // Byte 0 of the data buffer + * BYTELength; // Byte 1 of the data buffer + * BYTE[x-1]Data; // Bytes 2-x of the arbitrary length data buffer, + * } + */ + Length += 2; + Function = ACPI_READ | (AccessorType << 16); } else /* IPMI */ { @@ -251,6 +333,7 @@ AcpiExWriteDataToField ( void *Buffer; ACPI_OPERAND_OBJECT *BufferDesc; UINT32 Function; + UINT16 AccessorType; ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc); @@ -310,8 +393,20 @@ AcpiExWriteDataToField ( } else if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS) { - Length = ACPI_GSBUS_BUFFER_SIZE; - Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16); + AccessorType = ObjDesc->Field.Attribute; + Length = AcpiExGetSerialAccessLength (AccessorType, + ObjDesc->Field.AccessLength); + + /* + * Add additional 2 bytes for modeled GenericSerialBus data buffer: + * typedef struct { + * BYTEStatus; // Byte 0 of the data buffer + * BYTELength; // Byte 1 of the data buffer + * BYTE[x-1]Data; // Bytes 2-x of the arbitrary length data buffer, + * } + */ + Length += 2; + Function = ACPI_WRITE | (AccessorType << 16); } else /* IPMI */ { diff --git a/sys/contrib/dev/acpica/source/components/hardware/hwregs.c b/sys/contrib/dev/acpica/source/components/hardware/hwregs.c index a24fc5c8b1..94c508a84c 100644 --- a/sys/contrib/dev/acpica/source/components/hardware/hwregs.c +++ b/sys/contrib/dev/acpica/source/components/hardware/hwregs.c @@ -310,17 +310,19 @@ AcpiHwClearAcpiStatus ( Status = AcpiHwRegisterWrite (ACPI_REGISTER_PM1_STATUS, ACPI_BITMASK_ALL_FIXED_STATUS); + + AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags); + if (ACPI_FAILURE (Status)) { - goto UnlockAndExit; + goto Exit; } /* Clear the GPE Bits in all GPE registers in all GPE blocks */ Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL); -UnlockAndExit: - AcpiOsReleaseLock (AcpiGbl_HardwareLock, LockFlags); +Exit: return_ACPI_STATUS (Status); } diff --git a/sys/contrib/dev/acpica/source/components/namespace/nsobject.c b/sys/contrib/dev/acpica/source/components/namespace/nsobject.c index 3317591742..9221ac00aa 100644 --- a/sys/contrib/dev/acpica/source/components/namespace/nsobject.c +++ b/sys/contrib/dev/acpica/source/components/namespace/nsobject.c @@ -265,6 +265,17 @@ AcpiNsDetachObject ( } } + /* + * Detach the object from any data objects (which are still held by + * the namespace node) + */ + + if (ObjDesc->Common.NextObject && + ((ObjDesc->Common.NextObject)->Common.Type == ACPI_TYPE_LOCAL_DATA)) + { + ObjDesc->Common.NextObject = NULL; + } + /* Reset the node type to untyped */ Node->Type = ACPI_TYPE_ANY; diff --git a/sys/contrib/dev/acpica/source/components/tables/tbdata.c b/sys/contrib/dev/acpica/source/components/tables/tbdata.c index 549c5551bc..e0c5f3ae4b 100644 --- a/sys/contrib/dev/acpica/source/components/tables/tbdata.c +++ b/sys/contrib/dev/acpica/source/components/tables/tbdata.c @@ -352,7 +352,43 @@ AcpiTbInvalidateTable ( /****************************************************************************** * - * FUNCTION: AcpiTbVerifyTable + * FUNCTION: AcpiTbValidateTempTable + * + * PARAMETERS: TableDesc - Table descriptor + * + * RETURN: Status + * + * DESCRIPTION: This function is called to validate the table, the returned + * table descriptor is in "VALIDATED" state. + * + *****************************************************************************/ + +ACPI_STATUS +AcpiTbValidateTempTable ( + ACPI_TABLE_DESC *TableDesc) +{ + + if (!TableDesc->Pointer && !AcpiGbl_VerifyTableChecksum) + { + /* + * Only validates the header of the table. + * Note that Length contains the size of the mapping after invoking + * this work around, this value is required by + * AcpiTbReleaseTempTable(). + * We can do this because in AcpiInitTableDescriptor(), the Length + * field of the installed descriptor is filled with the actual + * table length obtaining from the table header. + */ + TableDesc->Length = sizeof (ACPI_TABLE_HEADER); + } + + return (AcpiTbValidateTable (TableDesc)); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiTbVerifyTempTable * * PARAMETERS: TableDesc - Table descriptor * Signature - Table signature to verify @@ -365,19 +401,19 @@ AcpiTbInvalidateTable ( *****************************************************************************/ ACPI_STATUS -AcpiTbVerifyTable ( +AcpiTbVerifyTempTable ( ACPI_TABLE_DESC *TableDesc, char *Signature) { ACPI_STATUS Status = AE_OK; - ACPI_FUNCTION_TRACE (TbVerifyTable); + ACPI_FUNCTION_TRACE (TbVerifyTempTable); /* Validate the table */ - Status = AcpiTbValidateTable (TableDesc); + Status = AcpiTbValidateTempTable (TableDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (AE_NO_MEMORY); @@ -397,16 +433,19 @@ AcpiTbVerifyTable ( /* Verify the checksum */ - Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length); - if (ACPI_FAILURE (Status)) + if (AcpiGbl_VerifyTableChecksum) { - ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY, - "%4.4s " ACPI_PRINTF_UINT - " Attempted table install failed", - AcpiUtValidAcpiName (TableDesc->Signature.Ascii) ? - TableDesc->Signature.Ascii : "????", - ACPI_FORMAT_TO_UINT (TableDesc->Address))); - goto InvalidateAndExit; + Status = AcpiTbVerifyChecksum (TableDesc->Pointer, TableDesc->Length); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY, + "%4.4s " ACPI_PRINTF_UINT + " Attempted table install failed", + AcpiUtValidAcpiName (TableDesc->Signature.Ascii) ? + TableDesc->Signature.Ascii : "????", + ACPI_FORMAT_TO_UINT (TableDesc->Address))); + goto InvalidateAndExit; + } } return_ACPI_STATUS (AE_OK); diff --git a/sys/contrib/dev/acpica/source/components/tables/tbinstal.c b/sys/contrib/dev/acpica/source/components/tables/tbinstal.c index 9dcaa9115c..791979ccd9 100644 --- a/sys/contrib/dev/acpica/source/components/tables/tbinstal.c +++ b/sys/contrib/dev/acpica/source/components/tables/tbinstal.c @@ -210,7 +210,7 @@ AcpiTbInstallFixedTable ( /* Validate and verify a table before installation */ - Status = AcpiTbVerifyTable (&NewTableDesc, Signature); + Status = AcpiTbVerifyTempTable (&NewTableDesc, Signature); if (ACPI_FAILURE (Status)) { goto ReleaseAndExit; @@ -290,7 +290,7 @@ AcpiTbInstallStandardTable ( /* Validate and verify a table before installation */ - Status = AcpiTbVerifyTable (&NewTableDesc, NULL); + Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL); if (ACPI_FAILURE (Status)) { goto ReleaseAndExit; @@ -455,7 +455,7 @@ FinishOverride: /* Validate and verify a table before overriding */ - Status = AcpiTbVerifyTable (&NewTableDesc, NULL); + Status = AcpiTbVerifyTempTable (&NewTableDesc, NULL); if (ACPI_FAILURE (Status)) { return; @@ -477,7 +477,7 @@ FinishOverride: */ AcpiTbInitTableDescriptor (OldTableDesc, NewTableDesc.Address, NewTableDesc.Flags, NewTableDesc.Pointer); - AcpiTbValidateTable (OldTableDesc); + AcpiTbValidateTempTable (OldTableDesc); /* Release the temporary table descriptor */ diff --git a/sys/contrib/dev/acpica/source/components/tables/tbutils.c b/sys/contrib/dev/acpica/source/components/tables/tbutils.c index 4b207d9369..56fd46dfca 100644 --- a/sys/contrib/dev/acpica/source/components/tables/tbutils.c +++ b/sys/contrib/dev/acpica/source/components/tables/tbutils.c @@ -427,10 +427,6 @@ NextTable: TableEntry += TableEntrySize; } - /* - * It is not possible to map more than one entry in some environments, - * so unmap the root table here before mapping other tables - */ AcpiOsUnmapMemory (Table, Length); return_ACPI_STATUS (AE_OK); diff --git a/sys/contrib/dev/acpica/source/components/utilities/utbuffer.c b/sys/contrib/dev/acpica/source/components/utilities/utbuffer.c index 6b110f5dd3..a946aabbe8 100644 --- a/sys/contrib/dev/acpica/source/components/utilities/utbuffer.c +++ b/sys/contrib/dev/acpica/source/components/utilities/utbuffer.c @@ -218,3 +218,138 @@ AcpiUtDebugDumpBuffer ( AcpiUtDumpBuffer (Buffer, Count, Display, 0); } + + +#ifdef ACPI_APPLICATION +/******************************************************************************* + * + * FUNCTION: AcpiUtDumpBufferToFile + * + * PARAMETERS: File - File descriptor + * Buffer - Buffer to dump + * Count - Amount to dump, in bytes + * Display - BYTE, WORD, DWORD, or QWORD display: + * DB_BYTE_DISPLAY + * DB_WORD_DISPLAY + * DB_DWORD_DISPLAY + * DB_QWORD_DISPLAY + * BaseOffset - Beginning buffer offset (display only) + * + * RETURN: None + * + * DESCRIPTION: Generic dump buffer in both hex and ascii to a file. + * + ******************************************************************************/ + +void +AcpiUtDumpBufferToFile ( + ACPI_FILE File, + UINT8 *Buffer, + UINT32 Count, + UINT32 Display, + UINT32 BaseOffset) +{ + UINT32 i = 0; + UINT32 j; + UINT32 Temp32; + UINT8 BufChar; + + + if (!Buffer) + { + AcpiUtFilePrintf (File, "Null Buffer Pointer in DumpBuffer!\n"); + return; + } + + if ((Count < 4) || (Count & 0x01)) + { + Display = DB_BYTE_DISPLAY; + } + + /* Nasty little dump buffer routine! */ + + while (i < Count) + { + /* Print current offset */ + + AcpiUtFilePrintf (File, "%6.4X: ", (BaseOffset + i)); + + /* Print 16 hex chars */ + + for (j = 0; j < 16;) + { + if (i + j >= Count) + { + /* Dump fill spaces */ + + AcpiUtFilePrintf (File, "%*s", ((Display * 2) + 1), " "); + j += Display; + continue; + } + + switch (Display) + { + case DB_BYTE_DISPLAY: + default: /* Default is BYTE display */ + + AcpiUtFilePrintf (File, "%02X ", Buffer[(ACPI_SIZE) i + j]); + break; + + case DB_WORD_DISPLAY: + + ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]); + AcpiUtFilePrintf (File, "%04X ", Temp32); + break; + + case DB_DWORD_DISPLAY: + + ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]); + AcpiUtFilePrintf (File, "%08X ", Temp32); + break; + + case DB_QWORD_DISPLAY: + + ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]); + AcpiUtFilePrintf (File, "%08X", Temp32); + + ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]); + AcpiUtFilePrintf (File, "%08X ", Temp32); + break; + } + + j += Display; + } + + /* + * Print the ASCII equivalent characters but watch out for the bad + * unprintable ones (printable chars are 0x20 through 0x7E) + */ + AcpiUtFilePrintf (File, " "); + for (j = 0; j < 16; j++) + { + if (i + j >= Count) + { + AcpiUtFilePrintf (File, "\n"); + return; + } + + BufChar = Buffer[(ACPI_SIZE) i + j]; + if (ACPI_IS_PRINT (BufChar)) + { + AcpiUtFilePrintf (File, "%c", BufChar); + } + else + { + AcpiUtFilePrintf (File, "."); + } + } + + /* Done with that line. */ + + AcpiUtFilePrintf (File, "\n"); + i += 16; + } + + return; +} +#endif diff --git a/sys/contrib/dev/acpica/source/components/utilities/utclib.c b/sys/contrib/dev/acpica/source/components/utilities/utclib.c index 33bf350572..7892df4c55 100644 --- a/sys/contrib/dev/acpica/source/components/utilities/utclib.c +++ b/sys/contrib/dev/acpica/source/components/utilities/utclib.c @@ -308,8 +308,6 @@ AcpiUtStrcmp ( } -#ifdef ACPI_FUTURE_IMPLEMENTATION -/* Not used at this time */ /******************************************************************************* * * FUNCTION: AcpiUtStrchr (strchr) @@ -334,13 +332,13 @@ AcpiUtStrchr ( { if ((*String) == (char) ch) { - return ((char *) String); + return (__DECONST(char *, String)); } } return (NULL); } -#endif + /******************************************************************************* * diff --git a/sys/contrib/dev/acpica/source/components/utilities/utcopy.c b/sys/contrib/dev/acpica/source/components/utilities/utcopy.c index 26eb878308..6ab870924a 100644 --- a/sys/contrib/dev/acpica/source/components/utilities/utcopy.c +++ b/sys/contrib/dev/acpica/source/components/utilities/utcopy.c @@ -1063,5 +1063,12 @@ AcpiUtCopyIobjectToIobject ( Status = AcpiUtCopySimpleObject (SourceDesc, *DestDesc); } + /* Delete the allocated object if copy failed */ + + if (ACPI_FAILURE (Status)) + { + AcpiUtRemoveReference(*DestDesc); + } + return_ACPI_STATUS (Status); } diff --git a/sys/contrib/dev/acpica/source/components/utilities/utdebug.c b/sys/contrib/dev/acpica/source/components/utilities/utdebug.c index 4a25fb2628..973d4ec66c 100644 --- a/sys/contrib/dev/acpica/source/components/utilities/utdebug.c +++ b/sys/contrib/dev/acpica/source/components/utilities/utdebug.c @@ -636,3 +636,33 @@ AcpiUtPtrExit ( } #endif + + +#ifdef ACPI_APPLICATION +/******************************************************************************* + * + * FUNCTION: AcpiLogError + * + * PARAMETERS: Format - Printf format field + * ... - Optional printf arguments + * + * RETURN: None + * + * DESCRIPTION: Print error message to the console, used by applications. + * + ******************************************************************************/ + +void ACPI_INTERNAL_VAR_XFACE +AcpiLogError ( + const char *Format, + ...) +{ + va_list Args; + + va_start (Args, Format); + (void) AcpiUtFileVprintf (ACPI_FILE_ERR, Format, Args); + va_end (Args); +} + +ACPI_EXPORT_SYMBOL (AcpiLogError) +#endif diff --git a/sys/contrib/dev/acpica/source/components/debugger/dbfileio.c b/sys/contrib/dev/acpica/source/components/utilities/utfileio.c similarity index 60% copy from sys/contrib/dev/acpica/source/components/debugger/dbfileio.c copy to sys/contrib/dev/acpica/source/components/utilities/utfileio.c index a09c1de8cb..1d9adbbb55 100644 --- a/sys/contrib/dev/acpica/source/components/debugger/dbfileio.c +++ b/sys/contrib/dev/acpica/source/components/utilities/utfileio.c @@ -1,7 +1,6 @@ /******************************************************************************* * - * Module Name: dbfileio - Debugger file I/O commands. These can't usually - * be used when running the debugger in Ring 0 (Kernel mode) + * Module Name: utfileio - simple file I/O routines * ******************************************************************************/ @@ -45,108 +44,38 @@ #include "acpi.h" #include "accommon.h" -#include "acdebug.h" - -#ifdef ACPI_APPLICATION #include "actables.h" -#endif +#include "acapps.h" #ifdef ACPI_ASL_COMPILER #include "aslcompiler.h" #endif -#if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER) #define _COMPONENT ACPI_CA_DEBUGGER - ACPI_MODULE_NAME ("dbfileio") - -#ifdef ACPI_DEBUGGER + ACPI_MODULE_NAME ("utfileio") -/* Local prototypes */ #ifdef ACPI_APPLICATION +/* Local prototypes */ + static ACPI_STATUS -AcpiDbCheckTextModeCorruption ( +AcpiUtCheckTextModeCorruption ( UINT8 *Table, UINT32 TableLength, UINT32 FileLength); -#endif - -/******************************************************************************* - * - * FUNCTION: AcpiDbCloseDebugFile - * - * PARAMETERS: None - * - * RETURN: None - * - * DESCRIPTION: If open, close the current debug output file - * - ******************************************************************************/ - -void -AcpiDbCloseDebugFile ( - void) -{ - -#ifdef ACPI_APPLICATION - - if (AcpiGbl_DebugFile) - { - fclose (AcpiGbl_DebugFile); - AcpiGbl_DebugFile = NULL; - AcpiGbl_DbOutputToFile = FALSE; - AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename); - } -#endif -} - - -/******************************************************************************* - * - * FUNCTION: AcpiDbOpenDebugFile - * - * PARAMETERS: Name - Filename to open - * - * RETURN: None - * - * DESCRIPTION: Open a file where debug output will be directed. - * - ******************************************************************************/ - -void -AcpiDbOpenDebugFile ( - char *Name) -{ - -#ifdef ACPI_APPLICATION - - AcpiDbCloseDebugFile (); - AcpiGbl_DebugFile = fopen (Name, "w+"); - if (!AcpiGbl_DebugFile) - { - AcpiOsPrintf ("Could not open debug file %s\n", Name); - return; - } - - AcpiOsPrintf ("Debug output file %s opened\n", Name); - ACPI_STRNCPY (AcpiGbl_DbDebugFilename, Name, - sizeof (AcpiGbl_DbDebugFilename)); - AcpiGbl_DbOutputToFile = TRUE; - -#endif -} -#endif - +static ACPI_STATUS +AcpiUtReadTable ( + FILE *fp, + ACPI_TABLE_HEADER **Table, + UINT32 *TableLength); -#ifdef ACPI_APPLICATION -#include "acapps.h" /******************************************************************************* * - * FUNCTION: AcpiDbCheckTextModeCorruption + * FUNCTION: AcpiUtCheckTextModeCorruption * * PARAMETERS: Table - Table buffer * TableLength - Length of table from the table header @@ -161,7 +90,7 @@ AcpiDbOpenDebugFile ( ******************************************************************************/ static ACPI_STATUS -AcpiDbCheckTextModeCorruption ( +AcpiUtCheckTextModeCorruption ( UINT8 *Table, UINT32 TableLength, UINT32 FileLength) @@ -221,7 +150,7 @@ AcpiDbCheckTextModeCorruption ( /******************************************************************************* * - * FUNCTION: AcpiDbReadTable + * FUNCTION: AcpiUtReadTable * * PARAMETERS: fp - File that contains table * Table - Return value, buffer with table @@ -234,7 +163,7 @@ AcpiDbCheckTextModeCorruption ( ******************************************************************************/ static ACPI_STATUS -AcpiDbReadTable ( +AcpiUtReadTable ( FILE *fp, ACPI_TABLE_HEADER **Table, UINT32 *TableLength) @@ -244,7 +173,7 @@ AcpiDbReadTable ( ACPI_STATUS Status; UINT32 FileSize; BOOLEAN StandardHeader = TRUE; - + INT32 Count; /* Get the file size */ @@ -261,31 +190,24 @@ AcpiDbReadTable ( /* Read the signature */ - if (fread (&TableHeader, 1, 4, fp) != 4) + fseek (fp, 0, SEEK_SET); + + Count = fread (&TableHeader, 1, sizeof (ACPI_TABLE_HEADER), fp); + if (Count != sizeof (ACPI_TABLE_HEADER)) { - AcpiOsPrintf ("Could not read the table signature\n"); + AcpiOsPrintf ("Could not read the table header\n"); return (AE_BAD_HEADER); } - fseek (fp, 0, SEEK_SET); - /* The RSDP table does not have standard ACPI header */ - if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ")) + if (ACPI_VALIDATE_RSDP_SIG (TableHeader.Signature)) { *TableLength = FileSize; StandardHeader = FALSE; } else { - /* Read the table header */ - - if (fread (&TableHeader, 1, sizeof (ACPI_TABLE_HEADER), fp) != - sizeof (ACPI_TABLE_HEADER)) - { - AcpiOsPrintf ("Could not read the table header\n"); - return (AE_BAD_HEADER); - } #if 0 /* Validate the table header/length */ @@ -360,7 +282,7 @@ AcpiDbReadTable ( if (Status == AE_BAD_CHECKSUM) { - Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table, + Status = AcpiUtCheckTextModeCorruption ((UINT8 *) *Table, FileSize, (*Table)->Length); return (Status); } @@ -385,82 +307,7 @@ AcpiDbReadTable ( /******************************************************************************* * - * FUNCTION: AeLocalLoadTable - * - * PARAMETERS: Table - pointer to a buffer containing the entire - * table to be loaded - * - * RETURN: Status - * - * DESCRIPTION: This function is called to load a table from the caller's - * buffer. The buffer must contain an entire ACPI Table including - * a valid header. The header fields will be verified, and if it - * is determined that the table is invalid, the call will fail. - * - ******************************************************************************/ - -static ACPI_STATUS -AeLocalLoadTable ( - ACPI_TABLE_HEADER *Table) -{ - ACPI_STATUS Status = AE_OK; -/* ACPI_TABLE_DESC TableInfo; */ - - - ACPI_FUNCTION_TRACE (AeLocalLoadTable); -#if 0 - - - if (!Table) - { - return_ACPI_STATUS (AE_BAD_PARAMETER); - } - - TableInfo.Pointer = Table; - Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL); - if (ACPI_FAILURE (Status)) - { - return_ACPI_STATUS (Status); - } - - /* Install the new table into the local data structures */ - - Status = AcpiTbInitTableDescriptor (&TableInfo); - if (ACPI_FAILURE (Status)) - { - if (Status == AE_ALREADY_EXISTS) - { - /* Table already exists, no error */ - - Status = AE_OK; - } - - /* Free table allocated by AcpiTbGetTable */ - - AcpiTbDeleteSingleTable (&TableInfo); - return_ACPI_STATUS (Status); - } - -#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) - - Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode); - if (ACPI_FAILURE (Status)) - { - /* Uninstall table and free the buffer */ - - AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT); - return_ACPI_STATUS (Status); - } -#endif -#endif - - return_ACPI_STATUS (Status); -} - - -/******************************************************************************* - * - * FUNCTION: AcpiDbReadTableFromFile + * FUNCTION: AcpiUtReadTableFromFile * * PARAMETERS: Filename - File where table is located * Table - Where a pointer to the table is returned @@ -472,7 +319,7 @@ AeLocalLoadTable ( ******************************************************************************/ ACPI_STATUS -AcpiDbReadTableFromFile ( +AcpiUtReadTableFromFile ( char *Filename, ACPI_TABLE_HEADER **Table) { @@ -502,7 +349,7 @@ AcpiDbReadTableFromFile ( fprintf (stderr, "Loading Acpi table from file %10s - Length %.8u (%06X)\n", Filename, FileSize, FileSize); - Status = AcpiDbReadTable (File, Table, &TableLength); + Status = AcpiUtReadTable (File, Table, &TableLength); if (ACPI_FAILURE (Status)) { AcpiOsPrintf ("Could not get table from the file\n"); @@ -511,81 +358,6 @@ AcpiDbReadTableFromFile ( Exit: fclose(File); return (Status); - } -#endif - - -/******************************************************************************* - * - * FUNCTION: AcpiDbGetTableFromFile - * - * PARAMETERS: Filename - File where table is located - * ReturnTable - Where a pointer to the table is returned - * - * RETURN: Status - * - * DESCRIPTION: Load an ACPI table from a file - * - ******************************************************************************/ - -ACPI_STATUS -AcpiDbGetTableFromFile ( - char *Filename, - ACPI_TABLE_HEADER **ReturnTable) -{ -#ifdef ACPI_APPLICATION - ACPI_STATUS Status; - ACPI_TABLE_HEADER *Table; - BOOLEAN IsAmlTable = TRUE; - - - Status = AcpiDbReadTableFromFile (Filename, &Table); - if (ACPI_FAILURE (Status)) - { - return (Status); - } - -#ifdef ACPI_DATA_TABLE_DISASSEMBLY - IsAmlTable = AcpiUtIsAmlTable (Table); -#endif - - if (IsAmlTable) - { - /* Attempt to recognize and install the table */ - - Status = AeLocalLoadTable (Table); - if (ACPI_FAILURE (Status)) - { - if (Status == AE_ALREADY_EXISTS) - { - AcpiOsPrintf ("Table %4.4s is already installed\n", - Table->Signature); - } - else - { - AcpiOsPrintf ("Could not install table, %s\n", - AcpiFormatException (Status)); - } - - return (Status); - } - - AcpiTbPrintTableHeader (0, Table); - - fprintf (stderr, - "Acpi table [%4.4s] successfully installed and loaded\n", - Table->Signature); - } - - AcpiGbl_AcpiHardwarePresent = FALSE; - if (ReturnTable) - { - *ReturnTable = Table; - } - - -#endif /* ACPI_APPLICATION */ - return (AE_OK); } -#endif /* ACPI_DEBUGGER */ +#endif diff --git a/sys/contrib/dev/acpica/source/components/utilities/utglobal.c b/sys/contrib/dev/acpica/source/components/utilities/utglobal.c index c89d414fa5..3504348d4e 100644 --- a/sys/contrib/dev/acpica/source/components/utilities/utglobal.c +++ b/sys/contrib/dev/acpica/source/components/utilities/utglobal.c @@ -173,163 +173,6 @@ ACPI_FIXED_EVENT_INFO AcpiGbl_FixedEventInfo[ACPI_NUM_FIXED_EVENTS] = }; #endif /* !ACPI_REDUCED_HARDWARE */ - -/******************************************************************************* - * - * FUNCTION: AcpiUtInitGlobals - * - * PARAMETERS: None - * - * RETURN: Status - * - * DESCRIPTION: Initialize ACPICA globals. All globals that require specific - * initialization should be initialized here. This allows for - * a warm restart. - * - ******************************************************************************/ - -ACPI_STATUS -AcpiUtInitGlobals ( - void) -{ - ACPI_STATUS Status; - UINT32 i; - - - ACPI_FUNCTION_TRACE (UtInitGlobals); - - - /* Create all memory caches */ - - Status = AcpiUtCreateCaches (); - if (ACPI_FAILURE (Status)) - { - return_ACPI_STATUS (Status); - } - - /* Address Range lists */ - - for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++) - { - AcpiGbl_AddressRangeList[i] = NULL; - } - - /* Mutex locked flags */ - - for (i = 0; i < ACPI_NUM_MUTEX; i++) - { - AcpiGbl_MutexInfo[i].Mutex = NULL; - AcpiGbl_MutexInfo[i].ThreadId = ACPI_MUTEX_NOT_ACQUIRED; - AcpiGbl_MutexInfo[i].UseCount = 0; - } - - for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++) - { - AcpiGbl_OwnerIdMask[i] = 0; - } - - /* Last OwnerID is never valid */ - - AcpiGbl_OwnerIdMask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000; - - /* Event counters */ - - AcpiMethodCount = 0; - AcpiSciCount = 0; - AcpiGpeCount = 0; - - for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) - { - AcpiFixedEventCount[i] = 0; - } - -#if (!ACPI_REDUCED_HARDWARE) - - /* GPE/SCI support */ - - AcpiGbl_AllGpesInitialized = FALSE; - AcpiGbl_GpeXruptListHead = NULL; - AcpiGbl_GpeFadtBlocks[0] = NULL; - AcpiGbl_GpeFadtBlocks[1] = NULL; - AcpiCurrentGpeCount = 0; - - AcpiGbl_GlobalEventHandler = NULL; - AcpiGbl_SciHandlerList = NULL; - -#endif /* !ACPI_REDUCED_HARDWARE */ - - /* Global handlers */ - - AcpiGbl_GlobalNotify[0].Handler = NULL; - AcpiGbl_GlobalNotify[1].Handler = NULL; - AcpiGbl_ExceptionHandler = NULL; - AcpiGbl_InitHandler = NULL; - AcpiGbl_TableHandler = NULL; - AcpiGbl_InterfaceHandler = NULL; - - /* Global Lock support */ - - AcpiGbl_GlobalLockSemaphore = NULL; - AcpiGbl_GlobalLockMutex = NULL; - AcpiGbl_GlobalLockAcquired = FALSE; - AcpiGbl_GlobalLockHandle = 0; - AcpiGbl_GlobalLockPresent = FALSE; - - /* Miscellaneous variables */ - - AcpiGbl_DSDT = NULL; - AcpiGbl_CmSingleStep = FALSE; - AcpiGbl_Shutdown = FALSE; - AcpiGbl_NsLookupCount = 0; - AcpiGbl_PsFindCount = 0; - AcpiGbl_AcpiHardwarePresent = TRUE; - AcpiGbl_LastOwnerIdIndex = 0; - AcpiGbl_NextOwnerIdOffset = 0; - AcpiGbl_TraceDbgLevel = 0; - AcpiGbl_TraceDbgLayer = 0; - AcpiGbl_DebuggerConfiguration = DEBUGGER_THREADING; - AcpiGbl_DbOutputFlags = ACPI_DB_CONSOLE_OUTPUT; - AcpiGbl_OsiMutex = NULL; - AcpiGbl_RegMethodsExecuted = FALSE; - - /* Hardware oriented */ - - AcpiGbl_EventsInitialized = FALSE; - AcpiGbl_SystemAwakeAndRunning = TRUE; - - /* Namespace */ - - AcpiGbl_ModuleCodeList = NULL; - AcpiGbl_RootNode = NULL; - AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME; - AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED; - AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE; - AcpiGbl_RootNodeStruct.Parent = NULL; - AcpiGbl_RootNodeStruct.Child = NULL; - AcpiGbl_RootNodeStruct.Peer = NULL; - AcpiGbl_RootNodeStruct.Object = NULL; - - -#ifdef ACPI_DISASSEMBLER - AcpiGbl_ExternalList = NULL; - AcpiGbl_NumExternalMethods = 0; - AcpiGbl_ResolvedExternalMethods = 0; -#endif - -#ifdef ACPI_DEBUG_OUTPUT - AcpiGbl_LowestStackPointer = ACPI_CAST_PTR (ACPI_SIZE, ACPI_SIZE_MAX); -#endif - -#ifdef ACPI_DBG_TRACK_ALLOCATIONS - AcpiGbl_DisplayFinalMemStats = FALSE; - AcpiGbl_DisableMemTracking = FALSE; -#endif - - ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = FALSE); - - return_ACPI_STATUS (AE_OK); -} - /* Public globals */ ACPI_EXPORT_SYMBOL (AcpiGbl_FADT) diff --git a/sys/contrib/dev/acpica/source/components/utilities/utinit.c b/sys/contrib/dev/acpica/source/components/utilities/utinit.c index f2de2257fd..17030be640 100644 --- a/sys/contrib/dev/acpica/source/components/utilities/utinit.c +++ b/sys/contrib/dev/acpica/source/components/utilities/utinit.c @@ -116,6 +116,162 @@ AcpiUtFreeGpeLists ( #endif /* !ACPI_REDUCED_HARDWARE */ +/******************************************************************************* + * + * FUNCTION: AcpiUtInitGlobals + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Initialize ACPICA globals. All globals that require specific + * initialization should be initialized here. This allows for + * a warm restart. + * + ******************************************************************************/ + +ACPI_STATUS +AcpiUtInitGlobals ( + void) +{ + ACPI_STATUS Status; + UINT32 i; + + + ACPI_FUNCTION_TRACE (UtInitGlobals); + + + /* Create all memory caches */ + + Status = AcpiUtCreateCaches (); + if (ACPI_FAILURE (Status)) + { + return_ACPI_STATUS (Status); + } + + /* Address Range lists */ + + for (i = 0; i < ACPI_ADDRESS_RANGE_MAX; i++) + { + AcpiGbl_AddressRangeList[i] = NULL; + } + + /* Mutex locked flags */ + + for (i = 0; i < ACPI_NUM_MUTEX; i++) + { + AcpiGbl_MutexInfo[i].Mutex = NULL; + AcpiGbl_MutexInfo[i].ThreadId = ACPI_MUTEX_NOT_ACQUIRED; + AcpiGbl_MutexInfo[i].UseCount = 0; + } + + for (i = 0; i < ACPI_NUM_OWNERID_MASKS; i++) + { + AcpiGbl_OwnerIdMask[i] = 0; + } + + /* Last OwnerID is never valid */ + + AcpiGbl_OwnerIdMask[ACPI_NUM_OWNERID_MASKS - 1] = 0x80000000; + + /* Event counters */ + + AcpiMethodCount = 0; + AcpiSciCount = 0; + AcpiGpeCount = 0; + + for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++) + { + AcpiFixedEventCount[i] = 0; + } + +#if (!ACPI_REDUCED_HARDWARE) + + /* GPE/SCI support */ + + AcpiGbl_AllGpesInitialized = FALSE; + AcpiGbl_GpeXruptListHead = NULL; + AcpiGbl_GpeFadtBlocks[0] = NULL; + AcpiGbl_GpeFadtBlocks[1] = NULL; + AcpiCurrentGpeCount = 0; + + AcpiGbl_GlobalEventHandler = NULL; + AcpiGbl_SciHandlerList = NULL; + +#endif /* !ACPI_REDUCED_HARDWARE */ + + /* Global handlers */ + + AcpiGbl_GlobalNotify[0].Handler = NULL; + AcpiGbl_GlobalNotify[1].Handler = NULL; + AcpiGbl_ExceptionHandler = NULL; + AcpiGbl_InitHandler = NULL; + AcpiGbl_TableHandler = NULL; + AcpiGbl_InterfaceHandler = NULL; + + /* Global Lock support */ + + AcpiGbl_GlobalLockSemaphore = NULL; + AcpiGbl_GlobalLockMutex = NULL; + AcpiGbl_GlobalLockAcquired = FALSE; + AcpiGbl_GlobalLockHandle = 0; + AcpiGbl_GlobalLockPresent = FALSE; + + /* Miscellaneous variables */ + + AcpiGbl_DSDT = NULL; + AcpiGbl_CmSingleStep = FALSE; + AcpiGbl_Shutdown = FALSE; + AcpiGbl_NsLookupCount = 0; + AcpiGbl_PsFindCount = 0; + AcpiGbl_AcpiHardwarePresent = TRUE; + AcpiGbl_LastOwnerIdIndex = 0; + AcpiGbl_NextOwnerIdOffset = 0; + AcpiGbl_TraceDbgLevel = 0; + AcpiGbl_TraceDbgLayer = 0; + AcpiGbl_DebuggerConfiguration = DEBUGGER_THREADING; + AcpiGbl_OsiMutex = NULL; + AcpiGbl_RegMethodsExecuted = FALSE; + + /* Hardware oriented */ + + AcpiGbl_EventsInitialized = FALSE; + AcpiGbl_SystemAwakeAndRunning = TRUE; + + /* Namespace */ + + AcpiGbl_ModuleCodeList = NULL; + AcpiGbl_RootNode = NULL; + AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME; + AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED; + AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE; + AcpiGbl_RootNodeStruct.Parent = NULL; + AcpiGbl_RootNodeStruct.Child = NULL; + AcpiGbl_RootNodeStruct.Peer = NULL; + AcpiGbl_RootNodeStruct.Object = NULL; + + +#ifdef ACPI_DISASSEMBLER + AcpiGbl_ExternalList = NULL; + AcpiGbl_NumExternalMethods = 0; + AcpiGbl_ResolvedExternalMethods = 0; +#endif + +#ifdef ACPI_DEBUG_OUTPUT + AcpiGbl_LowestStackPointer = ACPI_CAST_PTR (ACPI_SIZE, ACPI_SIZE_MAX); +#endif + +#ifdef ACPI_DBG_TRACK_ALLOCATIONS + AcpiGbl_DisplayFinalMemStats = FALSE; + AcpiGbl_DisableMemTracking = FALSE; +#endif + + ACPI_DEBUGGER_EXEC (AcpiGbl_DbTerminateThreads = FALSE); + + return_ACPI_STATUS (AE_OK); +} + + /****************************************************************************** * * FUNCTION: AcpiUtTerminate diff --git a/sys/contrib/dev/acpica/source/components/utilities/utprint.c b/sys/contrib/dev/acpica/source/components/utilities/utprint.c new file mode 100644 index 0000000000..0194d56115 --- /dev/null +++ b/sys/contrib/dev/acpica/source/components/utilities/utprint.c @@ -0,0 +1,796 @@ +/****************************************************************************** + * + * Module Name: utprint - Formatted printing routines + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2014, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpi.h" +#include "accommon.h" + +#define _COMPONENT ACPI_UTILITIES + ACPI_MODULE_NAME ("utprint") + + +#define ACPI_FORMAT_SIGN 0x01 +#define ACPI_FORMAT_SIGN_PLUS 0x02 +#define ACPI_FORMAT_SIGN_PLUS_SPACE 0x04 +#define ACPI_FORMAT_ZERO 0x08 +#define ACPI_FORMAT_LEFT 0x10 +#define ACPI_FORMAT_UPPER 0x20 +#define ACPI_FORMAT_PREFIX 0x40 + + +/* Local prototypes */ + +static ACPI_SIZE +AcpiUtBoundStringLength ( + const char *String, + ACPI_SIZE Count); + +static char * +AcpiUtBoundStringOutput ( + char *String, + const char *End, + char c); + +static char * +AcpiUtFormatNumber ( + char *String, + char *End, + UINT64 Number, + UINT8 Base, + INT32 Width, + INT32 Precision, + UINT8 Type); + +static char * +AcpiUtPutNumber ( + char *String, + UINT64 Number, + UINT8 Base, + BOOLEAN Upper); + + +/******************************************************************************* + * + * FUNCTION: AcpiUtBoundStringLength + * + * PARAMETERS: String - String with boundary + * Count - Boundary of the string + * + * RETURN: Length of the string. + * + * DESCRIPTION: Calculate the length of a string with boundary. + * + ******************************************************************************/ + +static ACPI_SIZE +AcpiUtBoundStringLength ( + const char *String, + ACPI_SIZE Count) +{ + UINT32 Length = 0; + + + while (*String && Count) + { + Length++; + String++; + Count--; + } + + return (Length); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiUtBoundStringOutput + * + * PARAMETERS: String - String with boundary + * End - Boundary of the string + * c - Character to be output to the string + * + * RETURN: Updated position for next valid character + * + * DESCRIPTION: Output a character into a string with boundary check. + * + ******************************************************************************/ + +static char * +AcpiUtBoundStringOutput ( + char *String, + const char *End, + char c) +{ + + if (String < End) + { + *String = c; + } + ++String; + + return (String); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiUtPutNumber + * + * PARAMETERS: String - Buffer to hold reverse-ordered string + * Number - Integer to be converted + * Base - Base of the integer + * Upper - Whether or not using upper cased digits + * + * RETURN: Updated position for next valid character + * + * DESCRIPTION: Convert an integer into a string, note that, the string holds a + * reversed ordered number without the trailing zero. + * + ******************************************************************************/ + +static char * +AcpiUtPutNumber ( + char *String, + UINT64 Number, + UINT8 Base, + BOOLEAN Upper) +{ + const char LowerDigits[] = "0123456789abcdef"; + const char UpperDigits[] = "0123456789ABCDEF"; + const char *Digits; + UINT64 DigitIndex; + char *Pos; + + + Pos = String; + Digits = Upper ? UpperDigits : LowerDigits; + + if (Number == 0) + { + *(Pos++) = '0'; + } + else + { + while (Number) + { + (void) AcpiUtDivide (Number, Base, &Number, &DigitIndex); + *(Pos++) = Digits[DigitIndex]; + } + } + /* *(Pos++) = '0'; */ + + return (Pos); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiUtScanNumber + * + * PARAMETERS: String - String buffer + * NumberPtr - Where the number is returned + * + * RETURN: Updated position for next valid character + * + * DESCRIPTION: Scan a string for a decimal integer. + * + ******************************************************************************/ + +const char * +AcpiUtScanNumber ( + const char *String, + UINT64 *NumberPtr) +{ + UINT64 Number = 0; + + + while (ACPI_IS_DIGIT (*String)) + { + Number *= 10; + Number += *(String++) - '0'; + } + *NumberPtr = Number; + + return (String); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiUtPrintNumber + * + * PARAMETERS: String - String buffer + * Number - The number to be converted + * + * RETURN: Updated position for next valid character + * + * DESCRIPTION: Print a decimal integer into a string. + * + ******************************************************************************/ + +const char * +AcpiUtPrintNumber ( + char *String, + UINT64 Number) +{ + char AsciiString[20]; + const char *Pos1; + char *Pos2; + + + Pos1 = AcpiUtPutNumber (AsciiString, Number, 10, FALSE); + Pos2 = String; + + while (Pos1 != AsciiString) + { + *(Pos2++) = *(--Pos1); + } + *Pos2 = 0; + + return (String); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiUtFormatNumber + * + * PARAMETERS: String - String buffer with boundary + * End - Boundary of the string + * Number - The number to be converted + * Base - Base of the integer + * Width - Field width + * Precision - Precision of the integer + * Type - Special printing flags + * + * RETURN: Updated position for next valid character + * + * DESCRIPTION: Print an integer into a string with any base and any precision. + * + ******************************************************************************/ + +static char * +AcpiUtFormatNumber ( + char *String, + char *End, + UINT64 Number, + UINT8 Base, + INT32 Width, + INT32 Precision, + UINT8 Type) +{ + char Sign; + char Zero; + BOOLEAN NeedPrefix; + BOOLEAN Upper; + INT32 i; + char ReversedString[66]; + + + /* Perform sanity checks */ + + if (Base < 2 || Base > 16) + { + return NULL; + } + if (Type & ACPI_FORMAT_LEFT) + { + Type &= ~ACPI_FORMAT_ZERO; + } + + NeedPrefix = ((Type & ACPI_FORMAT_PREFIX) && Base != 10) ? TRUE : FALSE; + Upper = (Type & ACPI_FORMAT_UPPER) ? TRUE : FALSE; + Zero = (Type & ACPI_FORMAT_ZERO) ? '0' : ' '; + + /* Calculate size according to sign and prefix */ + + Sign = '\0'; + if (Type & ACPI_FORMAT_SIGN) + { + if ((INT64) Number < 0) + { + Sign = '-'; + Number = - (INT64) Number; + Width--; + } + else if (Type & ACPI_FORMAT_SIGN_PLUS) + { + Sign = '+'; + Width--; + } + else if (Type & ACPI_FORMAT_SIGN_PLUS_SPACE) + { + Sign = ' '; + Width--; + } + } + if (NeedPrefix) + { + Width--; + if (Base == 16) + { + Width--; + } + } + + /* Generate full string in reverse order */ + + i = ACPI_PTR_DIFF ( + AcpiUtPutNumber (ReversedString, Number, Base, Upper), + ReversedString); + + /* Printing 100 using %2d gives "100", not "00" */ + + if (i > Precision) + { + Precision = i; + } + Width -= Precision; + + /* Output the string */ + + if (!(Type & (ACPI_FORMAT_ZERO | ACPI_FORMAT_LEFT))) + { + while (--Width >= 0) + { + String = AcpiUtBoundStringOutput (String, End, ' '); + } + } + if (Sign) + { + String = AcpiUtBoundStringOutput (String, End, Sign); + } + if (NeedPrefix) + { + String = AcpiUtBoundStringOutput (String, End, '0'); + if (Base == 16) + { + String = AcpiUtBoundStringOutput (String, End, + Upper ? 'X' : 'x'); + } + } + if (!(Type & ACPI_FORMAT_LEFT)) + { + while (--Width >= 0) + { + String = AcpiUtBoundStringOutput (String, End, Zero); + } + } + while (i <= --Precision) + { + String = AcpiUtBoundStringOutput (String, End, '0'); + } + while (--i >= 0) + { + String = AcpiUtBoundStringOutput (String, End, + ReversedString[i]); + } + while (--Width >= 0) + { + String = AcpiUtBoundStringOutput (String, End, ' '); + } + + return (String); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiUtVsnprintf + * + * PARAMETERS: String - String with boundary + * Size - Boundary of the string + * Format - Standard printf format + * Args - Argument list + * + * RETURN: Size of successfully output bytes + * + * DESCRIPTION: Formatted output to a string using argument list pointer. + * + ******************************************************************************/ + +int +AcpiUtVsnprintf ( + char *String, + ACPI_SIZE Size, + const char *Format, + va_list Args) +{ + UINT8 Base = 10; + UINT8 Type = 0; + INT32 Width = -1; + INT32 Precision = -1; + char Qualifier = 0; + UINT64 Number; + char *Pos; + char *End; + char c; + const char *s; + const void *p; + INT32 Length; + int i; + + + Pos = String; + End = String + Size; + + for (; *Format ; ++Format) + { + if (*Format != '%') + { + Pos = AcpiUtBoundStringOutput (Pos, End, *Format); + continue; + } + + /* Process sign */ + + do + { + ++Format; + if (*Format == '#') + { + Type |= ACPI_FORMAT_PREFIX; + } + else if (*Format == '0') + { + Type |= ACPI_FORMAT_ZERO; + } + else if (*Format == '+') + { + Type |= ACPI_FORMAT_SIGN_PLUS; + } + else if (*Format == ' ') + { + Type |= ACPI_FORMAT_SIGN_PLUS_SPACE; + } + else if (*Format == '-') + { + Type |= ACPI_FORMAT_LEFT; + } + else + { + break; + } + } while (1); + + /* Process width */ + + if (ACPI_IS_DIGIT (*Format)) + { + Format = AcpiUtScanNumber (Format, &Number); + Width = (INT32) Number; + } + else if (*Format == '*') + { + ++Format; + Width = va_arg(Args, int); + if (Width < 0) + { + Width = -Width; + Type |= ACPI_FORMAT_LEFT; + } + } + + /* Process precision */ + + if (*Format == '.') + { + ++Format; + if (ACPI_IS_DIGIT(*Format)) + { + Format = AcpiUtScanNumber (Format, &Number); + Precision = (INT32) Number; + } + else if (*Format == '*') + { + ++Format; + Precision = va_arg(Args, int); + } + if (Precision < 0) + { + Precision = 0; + } + } + + /* Process qualifier */ + + if (*Format == 'h' || *Format == 'l' || *Format == 'L') + { + Qualifier = *Format; + ++Format; + if (Qualifier == 'l' && *Format == 'l') + { + Qualifier = 'L'; + ++Format; + } + } + + switch (*Format) + { + case '%': + + Pos = AcpiUtBoundStringOutput (Pos, End, '%'); + continue; + + case 'c': + + if (!(Type & ACPI_FORMAT_LEFT)) + { + while (--Width > 0) + { + Pos = AcpiUtBoundStringOutput (Pos, End, ' '); + } + } + c = (char) va_arg (Args, int); + Pos = AcpiUtBoundStringOutput (Pos, End, c); + while (--Width > 0) + { + Pos = AcpiUtBoundStringOutput (Pos, End, ' '); + } + continue; + + case 's': + + s = va_arg (Args, char *); + if (!s) + { + s = ""; + } + Length = AcpiUtBoundStringLength (s, Precision); + if (!(Type & ACPI_FORMAT_LEFT)) + { + while (Length < Width--) + { + Pos = AcpiUtBoundStringOutput (Pos, End, ' '); + } + } + for (i = 0; i < Length; ++i) + { + Pos = AcpiUtBoundStringOutput (Pos, End, *s); + ++s; + } + while (Length < Width--) + { + Pos = AcpiUtBoundStringOutput (Pos, End, ' '); + } + continue; + + case 'o': + + Base = 8; + break; + + case 'X': + + Type |= ACPI_FORMAT_UPPER; + + case 'x': + + Base = 16; + break; + + case 'd': + case 'i': + + Type |= ACPI_FORMAT_SIGN; + + case 'u': + + break; + + case 'p': + + if (Width == -1) + { + Width = 2 * sizeof (void *); + Type |= ACPI_FORMAT_ZERO; + } + p = va_arg (Args, void *); + Pos = AcpiUtFormatNumber (Pos, End, + ACPI_TO_INTEGER (p), + 16, Width, Precision, Type); + continue; + + default: + + Pos = AcpiUtBoundStringOutput (Pos, End, '%'); + if (*Format) + { + Pos = AcpiUtBoundStringOutput (Pos, End, *Format); + } + else + { + --Format; + } + continue; + } + + if (Qualifier == 'L') + { + Number = va_arg (Args, UINT64); + if (Type & ACPI_FORMAT_SIGN) + { + Number = (INT64) Number; + } + } + else if (Qualifier == 'l') + { + Number = va_arg (Args, unsigned long); + if (Type & ACPI_FORMAT_SIGN) + { + Number = (INT32) Number; + } + } + else if (Qualifier == 'h') + { + Number = (UINT16) va_arg (Args, int); + if (Type & ACPI_FORMAT_SIGN) + { + Number = (INT16) Number; + } + } + else + { + Number = va_arg (Args, unsigned int); + if (Type & ACPI_FORMAT_SIGN) + { + Number = (signed int) Number; + } + } + Pos = AcpiUtFormatNumber(Pos, End, Number, Base, + Width, Precision, Type); + } + + if (Size > 0) + { + if (Pos < End) + { + *Pos = '\0'; + } + else + { + End[-1] = '\0'; + } + } + + return (ACPI_PTR_DIFF (Pos, String)); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiUtSnprintf + * + * PARAMETERS: String - String with boundary + * Size - Boundary of the string + * Format, ... - Standard printf format + * + * RETURN: Size of successfully output bytes + * + * DESCRIPTION: Formatted output to a string. + * + ******************************************************************************/ + +int +AcpiUtSnprintf ( + char *String, + ACPI_SIZE Size, + const char *Format, + ...) +{ + va_list Args; + int Length; + + + va_start (Args, Format); + Length = AcpiUtVsnprintf (String, Size, Format, Args); + va_end (Args); + + return (Length); +} + + +#ifdef ACPI_APPLICATION +/******************************************************************************* + * + * FUNCTION: AcpiUtFileVprintf + * + * PARAMETERS: File - File descriptor + * Format - Standard printf format + * Args - Argument list + * + * RETURN: Size of successfully output bytes + * + * DESCRIPTION: Formatted output to a file using argument list pointer. + * + ******************************************************************************/ + +int +AcpiUtFileVprintf ( + ACPI_FILE File, + const char *Format, + va_list Args) +{ + ACPI_CPU_FLAGS Flags; + int Length; + + + Flags = AcpiOsAcquireLock (AcpiGbl_PrintLock); + Length = AcpiUtVsnprintf(AcpiGbl_PrintBuffer, + sizeof (AcpiGbl_PrintBuffer), Format, Args); + (void) AcpiOsWriteFile (File, AcpiGbl_PrintBuffer, Length, 1); + AcpiOsReleaseLock (AcpiGbl_PrintLock, Flags); + + return (Length); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiUtFilePrintf + * + * PARAMETERS: File - File descriptor + * Format, ... - Standard printf format + * + * RETURN: Size of successfully output bytes + * + * DESCRIPTION: Formatted output to a file. + * + ******************************************************************************/ + +int +AcpiUtFilePrintf ( + ACPI_FILE File, + const char *Format, + ...) +{ + va_list Args; + int Length; + + + va_start (Args, Format); + Length = AcpiUtFileVprintf (File, Format, Args); + va_end (Args); + + return (Length); +} +#endif diff --git a/sys/contrib/dev/acpica/source/include/acapps.h b/sys/contrib/dev/acpica/source/include/acapps.h index fa8e3866db..f754789531 100644 --- a/sys/contrib/dev/acpica/source/include/acapps.h +++ b/sys/contrib/dev/acpica/source/include/acapps.h @@ -84,10 +84,13 @@ /* Macros for usage messages */ #define ACPI_USAGE_HEADER(Usage) \ - printf ("Usage: %s\nOptions:\n", Usage); + AcpiOsPrintf ("Usage: %s\nOptions:\n", Usage); + +#define ACPI_USAGE_TEXT(Description) \ + AcpiOsPrintf (Description); #define ACPI_OPTION(Name, Description) \ - printf (" %-18s%s\n", Name, Description); + AcpiOsPrintf (" %-18s%s\n", Name, Description); #define FILE_SUFFIX_DISASSEMBLY "dsl" @@ -119,7 +122,7 @@ extern char *AcpiGbl_Optarg; */ UINT32 CmGetFileSize ( - FILE *File); + ACPI_FILE File); #ifndef ACPI_DUMP_APP diff --git a/sys/contrib/dev/acpica/source/include/acdebug.h b/sys/contrib/dev/acpica/source/include/acdebug.h index f85ec01ac2..a85625731b 100644 --- a/sys/contrib/dev/acpica/source/include/acdebug.h +++ b/sys/contrib/dev/acpica/source/include/acdebug.h @@ -377,11 +377,6 @@ AcpiDbGetTableFromFile ( char *Filename, ACPI_TABLE_HEADER **Table); -ACPI_STATUS -AcpiDbReadTableFromFile ( - char *Filename, - ACPI_TABLE_HEADER **Table); - /* * dbhistry - debugger HISTORY command diff --git a/sys/contrib/dev/acpica/source/include/acglobal.h b/sys/contrib/dev/acpica/source/include/acglobal.h index 06225c1247..a83f8c34b0 100644 --- a/sys/contrib/dev/acpica/source/include/acglobal.h +++ b/sys/contrib/dev/acpica/source/include/acglobal.h @@ -301,7 +301,7 @@ ACPI_GLOBAL (UINT32, AcpiGbl_TraceDbgLayer); * ****************************************************************************/ -ACPI_GLOBAL (UINT8, AcpiGbl_DbOutputFlags); +ACPI_INIT_GLOBAL (UINT8, AcpiGbl_DbOutputFlags, ACPI_DB_CONSOLE_OUTPUT); #ifdef ACPI_DISASSEMBLER @@ -367,6 +367,12 @@ ACPI_GLOBAL (UINT32, AcpiGbl_NumObjects); #ifdef ACPI_APPLICATION ACPI_INIT_GLOBAL (ACPI_FILE, AcpiGbl_DebugFile, NULL); +ACPI_INIT_GLOBAL (ACPI_FILE, AcpiGbl_OutputFile, NULL); + +/* Print buffer */ + +ACPI_GLOBAL (ACPI_SPINLOCK, AcpiGbl_PrintLock); /* For print buffer */ +ACPI_GLOBAL (char, AcpiGbl_PrintBuffer[1024]); #endif /* ACPI_APPLICATION */ diff --git a/sys/contrib/dev/acpica/source/include/acnames.h b/sys/contrib/dev/acpica/source/include/acnames.h index 3db143cbbd..f5daaceb2f 100644 --- a/sys/contrib/dev/acpica/source/include/acnames.h +++ b/sys/contrib/dev/acpica/source/include/acnames.h @@ -55,7 +55,6 @@ #define METHOD_NAME__HID "_HID" #define METHOD_NAME__INI "_INI" #define METHOD_NAME__PLD "_PLD" -#define METHOD_NAME__PRP "_PRP" #define METHOD_NAME__PRS "_PRS" #define METHOD_NAME__PRT "_PRT" #define METHOD_NAME__PRW "_PRW" diff --git a/sys/contrib/dev/acpica/source/include/acpi.h b/sys/contrib/dev/acpica/source/include/acpi.h index 8c65613529..fb1f565e2f 100644 --- a/sys/contrib/dev/acpica/source/include/acpi.h +++ b/sys/contrib/dev/acpica/source/include/acpi.h @@ -62,8 +62,6 @@ #include "acrestyp.h" /* Resource Descriptor structs */ #include "acpiosxf.h" /* OSL interfaces (ACPICA-to-OS) */ #include "acpixf.h" /* ACPI core subsystem external interfaces */ -#ifdef ACPI_NATIVE_INTERFACE_HEADER -#include ACPI_NATIVE_INTERFACE_HEADER -#endif +#include "platform/acenvex.h" /* Extra environment-specific items */ #endif /* __ACPI_H__ */ diff --git a/sys/contrib/dev/acpica/source/include/acpiosxf.h b/sys/contrib/dev/acpica/source/include/acpiosxf.h index 3fb6ea579b..a006759451 100644 --- a/sys/contrib/dev/acpica/source/include/acpiosxf.h +++ b/sys/contrib/dev/acpica/source/include/acpiosxf.h @@ -582,4 +582,53 @@ AcpiOsCloseDirectory ( #endif +/* + * File I/O and related support + */ +#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsOpenFile +ACPI_FILE +AcpiOsOpenFile ( + const char *Path, + UINT8 Modes); +#endif + +#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCloseFile +void +AcpiOsCloseFile ( + ACPI_FILE File); +#endif + +#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadFile +int +AcpiOsReadFile ( + ACPI_FILE File, + void *Buffer, + ACPI_SIZE Size, + ACPI_SIZE Count); +#endif + +#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWriteFile +int +AcpiOsWriteFile ( + ACPI_FILE File, + void *Buffer, + ACPI_SIZE Size, + ACPI_SIZE Count); +#endif + +#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetFileOffset +long +AcpiOsGetFileOffset ( + ACPI_FILE File); +#endif + +#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsSetFileOffset +ACPI_STATUS +AcpiOsSetFileOffset ( + ACPI_FILE File, + long Offset, + UINT8 From); +#endif + + #endif /* __ACPIOSXF_H__ */ diff --git a/sys/contrib/dev/acpica/source/include/acpixf.h b/sys/contrib/dev/acpica/source/include/acpixf.h index 53d2c1fd0e..31adb7026a 100644 --- a/sys/contrib/dev/acpica/source/include/acpixf.h +++ b/sys/contrib/dev/acpica/source/include/acpixf.h @@ -46,7 +46,7 @@ /* Current ACPICA subsystem version in YYYYMMDD format */ -#define ACPI_CA_VERSION 0x20140424 +#define ACPI_CA_VERSION 0x20140627 #include "acconfig.h" #include "actypes.h" @@ -161,6 +161,15 @@ ACPI_INIT_GLOBAL (UINT8, AcpiGbl_CreateOsiMethod, TRUE); */ ACPI_INIT_GLOBAL (UINT8, AcpiGbl_UseDefaultRegisterWidths, TRUE); +/* + * Whether or not to verify the table checksum before installation. Set + * this to TRUE to verify the table checksum before install it to the table + * manager. Note that enabling this option causes errors to happen in some + * OSPMs during early initialization stages. Default behavior is to do such + * verification. + */ +ACPI_INIT_GLOBAL (UINT8, AcpiGbl_VerifyTableChecksum, TRUE); + /* * Optionally enable output from the AML Debug Object. */ @@ -334,6 +343,24 @@ ACPI_GLOBAL (BOOLEAN, AcpiGbl_SystemAwakeAndRunning); #endif /* ACPI_DEBUG_OUTPUT */ +/* + * Application prototypes + * + * All interfaces used by application will be configured + * out of the ACPICA build unless the ACPI_APPLICATION + * flag is defined. + */ +#ifdef ACPI_APPLICATION +#define ACPI_APP_DEPENDENT_RETURN_VOID(Prototype) \ + Prototype; + +#else +#define ACPI_APP_DEPENDENT_RETURN_VOID(Prototype) \ + static ACPI_INLINE Prototype {return;} + +#endif /* ACPI_APPLICATION */ + + /***************************************************************************** * * ACPICA public interface prototypes @@ -1136,4 +1163,11 @@ AcpiDebugPrintRaw ( const char *Format, ...)) +ACPI_APP_DEPENDENT_RETURN_VOID ( +ACPI_PRINTF_LIKE(1) +void ACPI_INTERNAL_VAR_XFACE +AcpiLogError ( + const char *Format, + ...)) + #endif /* __ACXFACE_H__ */ diff --git a/sys/contrib/dev/acpica/source/include/acpredef.h b/sys/contrib/dev/acpica/source/include/acpredef.h index d7af2db269..3ab4ae0a22 100644 --- a/sys/contrib/dev/acpica/source/include/acpredef.h +++ b/sys/contrib/dev/acpica/source/include/acpredef.h @@ -688,12 +688,6 @@ const ACPI_PREDEFINED_INFO AcpiGbl_PredefinedMethods[] = METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */ PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0), - {{"_PRP", METHOD_0ARGS, - METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each: 1 Str, 1 Int/Str/Pkg */ - PACKAGE_INFO (ACPI_PTYPE2, ACPI_RTYPE_STRING, 1, - ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | - ACPI_RTYPE_PACKAGE | ACPI_RTYPE_REFERENCE, 1,0), - {{"_PRS", METHOD_0ARGS, METHOD_RETURNS (ACPI_RTYPE_BUFFER)}}, diff --git a/sys/contrib/dev/acpica/source/include/actables.h b/sys/contrib/dev/acpica/source/include/actables.h index 672b6b4063..e266924b05 100644 --- a/sys/contrib/dev/acpica/source/include/actables.h +++ b/sys/contrib/dev/acpica/source/include/actables.h @@ -86,6 +86,15 @@ void AcpiTbReleaseTempTable ( ACPI_TABLE_DESC *TableDesc); +ACPI_STATUS +AcpiTbValidateTempTable ( + ACPI_TABLE_DESC *TableDesc); + +ACPI_STATUS +AcpiTbVerifyTempTable ( + ACPI_TABLE_DESC *TableDesc, + char *Signature); + BOOLEAN AcpiTbIsTableLoaded ( UINT32 TableIndex); @@ -135,11 +144,6 @@ void AcpiTbInvalidateTable ( ACPI_TABLE_DESC *TableDesc); -ACPI_STATUS -AcpiTbVerifyTable ( - ACPI_TABLE_DESC *TableDesc, - char *Signature); - void AcpiTbOverrideTable ( ACPI_TABLE_DESC *OldTableDesc); diff --git a/sys/contrib/dev/acpica/source/include/actypes.h b/sys/contrib/dev/acpica/source/include/actypes.h index 7a8d5c5c3b..5e1c307f46 100644 --- a/sys/contrib/dev/acpica/source/include/actypes.h +++ b/sys/contrib/dev/acpica/source/include/actypes.h @@ -127,6 +127,7 @@ typedef unsigned char BOOLEAN; typedef unsigned char UINT8; typedef unsigned short UINT16; +typedef short INT16; typedef COMPILER_DEPENDENT_UINT64 UINT64; typedef COMPILER_DEPENDENT_INT64 INT64; @@ -1336,4 +1337,19 @@ typedef struct acpi_memory_list #define ACPI_OSI_WIN_8 0x0C +/* Definitions of file IO */ + +#define ACPI_FILE_READING 0x01 +#define ACPI_FILE_WRITING 0x02 +#define ACPI_FILE_BINARY 0x04 + +#define ACPI_FILE_BEGIN 0x01 +#define ACPI_FILE_END 0x02 + + +/* Definitions of getopt */ + +#define ACPI_OPT_END -1 + + #endif /* __ACTYPES_H__ */ diff --git a/sys/contrib/dev/acpica/source/include/acutils.h b/sys/contrib/dev/acpica/source/include/acutils.h index 5c87313380..b006234063 100644 --- a/sys/contrib/dev/acpica/source/include/acutils.h +++ b/sys/contrib/dev/acpica/source/include/acutils.h @@ -96,7 +96,6 @@ extern const char *AcpiGbl_PtDecode[]; #ifdef ACPI_ASL_COMPILER #include -extern FILE *AcpiGbl_OutputFile; #define ACPI_MSG_REDIRECT_BEGIN \ FILE *OutputFile = AcpiGbl_OutputFile; \ @@ -252,6 +251,11 @@ ACPI_SIZE AcpiUtStrlen ( const char *String); +char * +AcpiUtStrchr ( + const char *String, + int ch); + char * AcpiUtStrcpy ( char *DstString, @@ -340,7 +344,7 @@ extern const UINT8 _acpi_ctype[]; #define ACPI_IS_XDIGIT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_XD)) #define ACPI_IS_UPPER(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_UP)) #define ACPI_IS_LOWER(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO)) -#define ACPI_IS_PRINT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_SP | _ACPI_PU)) +#define ACPI_IS_PRINT(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_XS | _ACPI_PU)) #define ACPI_IS_ALPHA(c) (_acpi_ctype[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP)) #endif /* !ACPI_USE_SYSTEM_CLIBRARY */ @@ -482,6 +486,16 @@ AcpiUtDumpBuffer ( UINT32 Display, UINT32 Offset); +#ifdef ACPI_APPLICATION +void +AcpiUtDumpBufferToFile ( + ACPI_FILE File, + UINT8 *Buffer, + UINT32 Count, + UINT32 Display, + UINT32 BaseOffset); +#endif + void AcpiUtReportError ( char *ModuleName, @@ -550,6 +564,17 @@ AcpiUtExecutePowerMethods ( UINT8 *OutValues); +/* + * utfileio - file operations + */ +#ifdef ACPI_APPLICATION +ACPI_STATUS +AcpiUtReadTableFromFile ( + char *Filename, + ACPI_TABLE_HEADER **Table); +#endif + + /* * utids - device ID support */ @@ -1110,4 +1135,45 @@ const AH_DEVICE_ID * AcpiAhMatchHardwareId ( char *Hid); +/* + * utprint - printf/vprintf output functions + */ +const char * +AcpiUtScanNumber ( + const char *String, + UINT64 *NumberPtr); + +const char * +AcpiUtPrintNumber ( + char *String, + UINT64 Number); + +int +AcpiUtVsnprintf ( + char *String, + ACPI_SIZE Size, + const char *Format, + va_list Args); + +int +AcpiUtSnprintf ( + char *String, + ACPI_SIZE Size, + const char *Format, + ...); + +#ifdef ACPI_APPLICATION +int +AcpiUtFileVprintf ( + ACPI_FILE File, + const char *Format, + va_list Args); + +int +AcpiUtFilePrintf ( + ACPI_FILE File, + const char *Format, + ...); +#endif + #endif /* _ACUTILS_H */ diff --git a/sys/contrib/dev/acpica/source/include/platform/accygwin.h b/sys/contrib/dev/acpica/source/include/platform/accygwin.h index cf8a2a33d7..09581c4a30 100644 --- a/sys/contrib/dev/acpica/source/include/platform/accygwin.h +++ b/sys/contrib/dev/acpica/source/include/platform/accygwin.h @@ -92,11 +92,14 @@ /* - * The vsnprintf function is defined by c99, but cygwin/gcc does not - * enable this prototype when the -ansi flag is set. Also related to - * __STRICT_ANSI__. So, we just declare the prototype here. + * The vsnprintf/snprintf functions are defined by c99, but cygwin/gcc + * does not enable this prototype when the -ansi flag is set. Also related + * to __STRICT_ANSI__. So, we just declare the prototype here. */ int vsnprintf (char *s, size_t n, const char *format, va_list ap); +int +snprintf (char *s, size_t n, const char *format, ...); + #endif /* __ACCYGWIN_H__ */ diff --git a/sys/contrib/dev/acpica/source/include/platform/acefi.h b/sys/contrib/dev/acpica/source/include/platform/acefi.h index 1fafeb483d..cc24fbb4bd 100644 --- a/sys/contrib/dev/acpica/source/include/platform/acefi.h +++ b/sys/contrib/dev/acpica/source/include/platform/acefi.h @@ -44,11 +44,20 @@ #ifndef __ACEFI_H__ #define __ACEFI_H__ +#include +#if defined(_GNU_EFI) +#include +#include +#endif #include #include #include +/* AED EFI definitions */ + +#if defined(_AED_EFI) + /* _int64 works for both IA32 and IA64 */ #define COMPILER_DEPENDENT_INT64 __int64 @@ -71,5 +80,57 @@ #pragma warning(disable:4142) +#endif + + +/* GNU EFI definitions */ + +#if defined(_GNU_EFI) + +/* Using GCC for GNU EFI */ + +#include "acgcc.h" + +#undef ACPI_USE_SYSTEM_CLIBRARY +#undef ACPI_USE_STANDARD_HEADERS +#undef ACPI_USE_NATIVE_DIVIDE +#define ACPI_USE_SYSTEM_INTTYPES + +#define ACPI_FILE SIMPLE_TEXT_OUTPUT_INTERFACE * +#define ACPI_FILE_OUT ST->ConOut +#define ACPI_FILE_ERR ST->ConOut + +/* + * Math helpers + */ +#define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \ + do { \ + UINT64 __n = ((UINT64) n_hi) << 32 | (n_lo); \ + (q32) = DivU64x32 ((__n), (d32), &(r32)); \ + } while (0) + +#define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \ + do { \ + (n_lo) >>= 1; \ + (n_lo) |= (((n_hi) & 1) << 31); \ + (n_hi) >>= 1; \ + } while (0) + +/* + * EFI specific prototypes + */ +EFI_STATUS +efi_main ( + EFI_HANDLE Image, + EFI_SYSTEM_TABLE *SystemTab); + +int +acpi_main ( + int argc, + char *argv[]); + + +#endif + #endif /* __ACEFI_H__ */ diff --git a/sys/contrib/dev/acpica/source/include/platform/acenv.h b/sys/contrib/dev/acpica/source/include/platform/acenv.h index 1a9ef386aa..a73d56f444 100644 --- a/sys/contrib/dev/acpica/source/include/platform/acenv.h +++ b/sys/contrib/dev/acpica/source/include/platform/acenv.h @@ -88,20 +88,14 @@ #define ACPI_DBG_TRACK_ALLOCATIONS #endif -/* AcpiNames configuration. Single threaded with debugger output enabled. */ - -#ifdef ACPI_NAMES_APP -#define ACPI_DEBUGGER -#define ACPI_APPLICATION -#define ACPI_SINGLE_THREADED -#endif - /* - * AcpiBin/AcpiDump/AcpiSrc/AcpiXtract/Example configuration. All single - * threaded, with no debug output. + * AcpiBin/AcpiDump/AcpiHelp/AcpiNames/AcpiSrc/AcpiXtract/Example configuration. + * All single threaded. */ #if (defined ACPI_BIN_APP) || \ (defined ACPI_DUMP_APP) || \ + (defined ACPI_HELP_APP) || \ + (defined ACPI_NAMES_APP) || \ (defined ACPI_SRC_APP) || \ (defined ACPI_XTRACT_APP) || \ (defined ACPI_EXAMPLE_APP) @@ -109,12 +103,40 @@ #define ACPI_SINGLE_THREADED #endif +/* AcpiHelp configuration. Error messages disabled. */ + #ifdef ACPI_HELP_APP -#define ACPI_APPLICATION -#define ACPI_SINGLE_THREADED #define ACPI_NO_ERROR_MESSAGES #endif +/* AcpiNames configuration. Debug output enabled. */ + +#ifdef ACPI_NAMES_APP +#define ACPI_DEBUG_OUTPUT +#endif + +/* AcpiExec/AcpiNames/Example configuration. Native RSDP used. */ + +#if (defined ACPI_EXEC_APP) || \ + (defined ACPI_EXAMPLE_APP) || \ + (defined ACPI_NAMES_APP) +#define ACPI_USE_NATIVE_RSDP_POINTER +#endif + +/* AcpiDump configuration. Native mapping used if provied by OSPMs */ + +#ifdef ACPI_DUMP_APP +#define ACPI_USE_NATIVE_MEMORY_MAPPING +#define USE_NATIVE_ALLOCATE_ZEROED +#endif + +/* AcpiNames/Example configuration. Hardware disabled */ + +#if (defined ACPI_EXAMPLE_APP) || \ + (defined ACPI_NAMES_APP) +#define ACPI_REDUCED_HARDWARE 1 +#endif + /* Linkable ACPICA library */ #ifdef ACPI_LIBRARY @@ -188,6 +210,9 @@ #elif defined(_AED_EFI) #include "acefi.h" +#elif defined(_GNU_EFI) +#include "acefi.h" + #elif defined(__HAIKU__) #include "achaiku.h" @@ -404,8 +429,12 @@ typedef char *va_list; #ifdef ACPI_APPLICATION #include #define ACPI_FILE FILE * +#define ACPI_FILE_OUT stdout +#define ACPI_FILE_ERR stderr #else #define ACPI_FILE void * +#define ACPI_FILE_OUT NULL +#define ACPI_FILE_ERR NULL #endif /* ACPI_APPLICATION */ #endif /* ACPI_FILE */ diff --git a/sys/contrib/dev/acpica/source/include/platform/acefi.h b/sys/contrib/dev/acpica/source/include/platform/acenvex.h similarity index 72% copy from sys/contrib/dev/acpica/source/include/platform/acefi.h copy to sys/contrib/dev/acpica/source/include/platform/acenvex.h index 1fafeb483d..a1de87ffee 100644 --- a/sys/contrib/dev/acpica/source/include/platform/acefi.h +++ b/sys/contrib/dev/acpica/source/include/platform/acenvex.h @@ -1,6 +1,6 @@ /****************************************************************************** * - * Name: acefi.h - OS specific defines, etc. + * Name: acenvex.h - Extra host and compiler configuration * *****************************************************************************/ @@ -41,35 +41,23 @@ * POSSIBILITY OF SUCH DAMAGES. */ -#ifndef __ACEFI_H__ -#define __ACEFI_H__ +#ifndef __ACENVEX_H__ +#define __ACENVEX_H__ -#include -#include -#include +/*! [Begin] no source code translation */ - -/* _int64 works for both IA32 and IA64 */ - -#define COMPILER_DEPENDENT_INT64 __int64 -#define COMPILER_DEPENDENT_UINT64 unsigned __int64 - -/* - * Calling conventions: +/****************************************************************************** * - * ACPI_SYSTEM_XFACE - Interfaces to host OS (handlers, threads) - * ACPI_EXTERNAL_XFACE - External ACPI interfaces - * ACPI_INTERNAL_XFACE - Internal ACPI interfaces - * ACPI_INTERNAL_VAR_XFACE - Internal variable-parameter list interfaces - */ -#define ACPI_SYSTEM_XFACE -#define ACPI_EXTERNAL_XFACE -#define ACPI_INTERNAL_XFACE -#define ACPI_INTERNAL_VAR_XFACE + * Extra host configuration files. All ACPICA headers are included before + * including these files. + * + *****************************************************************************/ -/* warn C4142: redefinition of type */ +#if defined(_LINUX) || defined(__linux__) +#include "aclinuxex.h" -#pragma warning(disable:4142) +#endif +/*! [End] no source code translation !*/ -#endif /* __ACEFI_H__ */ +#endif /* __ACENVEX_H__ */ diff --git a/sys/contrib/dev/acpica/source/include/platform/aclinux.h b/sys/contrib/dev/acpica/source/include/platform/aclinux.h index a57f7f00db..a51f28872b 100644 --- a/sys/contrib/dev/acpica/source/include/platform/aclinux.h +++ b/sys/contrib/dev/acpica/source/include/platform/aclinux.h @@ -48,13 +48,18 @@ #define ACPI_USE_SYSTEM_CLIBRARY #define ACPI_USE_DO_WHILE_0 -#define ACPI_MUTEX_TYPE ACPI_BINARY_SEMAPHORE #ifdef __KERNEL__ #define ACPI_USE_SYSTEM_INTTYPES +/* Compile for reduced hardware mode only with this kernel config */ + +#ifdef CONFIG_ACPI_REDUCED_HARDWARE_ONLY +#define ACPI_REDUCED_HARDWARE 1 +#endif + #include #include #include @@ -66,7 +71,7 @@ #ifdef EXPORT_ACPI_INTERFACES #include #endif -#include +#include #ifndef CONFIG_ACPI @@ -109,6 +114,42 @@ #define ACPI_SPINLOCK spinlock_t * #define ACPI_CPU_FLAGS unsigned long +/* Use native linux version of AcpiOsAllocateZeroed */ + +#define USE_NATIVE_ALLOCATE_ZEROED + +/* + * Overrides for in-kernel ACPICA + */ +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsInitialize +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTerminate +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocate +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocateZeroed +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsFree +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAcquireObject +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetThreadId +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCreateLock +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsMapMemory +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsUnmapMemory + +/* + * OSL interfaces used by debugger/disassembler + */ +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadable +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWritable + +/* + * OSL interfaces used by utilities + */ +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsRedirectOutput +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetLine +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByName +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByIndex +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByAddress +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsOpenDirectory +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetNextFilename +#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCloseDirectory + #else /* !__KERNEL__ */ #include @@ -154,153 +195,4 @@ #include "acgcc.h" - -#ifdef __KERNEL__ - -/* - * FIXME: Inclusion of actypes.h - * Linux kernel need this before defining inline OSL interfaces as - * actypes.h need to be included to find ACPICA type definitions. - * Since from ACPICA's perspective, the actypes.h should be included after - * acenv.h (aclinux.h), this leads to a inclusion mis-ordering issue. - */ -#include - -/* - * Overrides for in-kernel ACPICA - */ -ACPI_STATUS __init AcpiOsInitialize ( - void); -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsInitialize - -ACPI_STATUS AcpiOsTerminate ( - void); -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTerminate - -/* - * Memory allocation/deallocation - */ - -/* - * The irqs_disabled() check is for resume from RAM. - * Interrupts are off during resume, just like they are for boot. - * However, boot has (system_state != SYSTEM_RUNNING) - * to quiet __might_sleep() in kmalloc() and resume does not. - */ -static inline void * -AcpiOsAllocate ( - ACPI_SIZE Size) -{ - return kmalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL); -} -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocate - -/* Use native linux version of AcpiOsAllocateZeroed */ - -static inline void * -AcpiOsAllocateZeroed ( - ACPI_SIZE Size) -{ - return kzalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL); -} -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocateZeroed -#define USE_NATIVE_ALLOCATE_ZEROED - -static inline void -AcpiOsFree ( - void *Memory) -{ - kfree (Memory); -} -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsFree - -static inline void * -AcpiOsAcquireObject ( - ACPI_CACHE_T *Cache) -{ - return kmem_cache_zalloc (Cache, - irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL); -} -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAcquireObject - -static inline ACPI_THREAD_ID -AcpiOsGetThreadId ( - void) -{ - return (ACPI_THREAD_ID) (unsigned long) current; -} -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetThreadId - -#ifndef CONFIG_PREEMPT - -/* - * Used within ACPICA to show where it is safe to preempt execution - * when CONFIG_PREEMPT=n - */ -#define ACPI_PREEMPTION_POINT() \ - do { \ - if (!irqs_disabled()) \ - cond_resched(); \ - } while (0) - -#endif - -/* - * When lockdep is enabled, the spin_lock_init() macro stringifies it's - * argument and uses that as a name for the lock in debugging. - * By executing spin_lock_init() in a macro the key changes from "lock" for - * all locks to the name of the argument of acpi_os_create_lock(), which - * prevents lockdep from reporting false positives for ACPICA locks. - */ -#define AcpiOsCreateLock(__Handle) \ - ({ \ - spinlock_t *Lock = ACPI_ALLOCATE(sizeof(*Lock)); \ - if (Lock) { \ - *(__Handle) = Lock; \ - spin_lock_init(*(__Handle)); \ - } \ - Lock ? AE_OK : AE_NO_MEMORY; \ - }) -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCreateLock - -void __iomem * -AcpiOsMapMemory ( - ACPI_PHYSICAL_ADDRESS Where, - ACPI_SIZE Length); -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsMapMemory - -void -AcpiOsUnmapMemory ( - void __iomem *LogicalAddress, - ACPI_SIZE Size); -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsUnmapMemory - -/* - * OSL interfaces used by debugger/disassembler - */ -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadable -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWritable - -/* - * OSL interfaces used by utilities - */ -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsRedirectOutput -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetLine -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByName -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByIndex -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByAddress -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsOpenDirectory -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetNextFilename -#define ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCloseDirectory - -/* - * OSL interfaces added by Linux - */ -void -EarlyAcpiOsUnmapMemory ( - void __iomem *Virt, - ACPI_SIZE Size); - -#endif /* __KERNEL__ */ - #endif /* __ACLINUX_H__ */ diff --git a/sys/contrib/dev/acpica/source/include/platform/aclinuxex.h b/sys/contrib/dev/acpica/source/include/platform/aclinuxex.h new file mode 100644 index 0000000000..87d43910b2 --- /dev/null +++ b/sys/contrib/dev/acpica/source/include/platform/aclinuxex.h @@ -0,0 +1,137 @@ +/****************************************************************************** + * + * Name: aclinuxex.h - Extra OS specific defines, etc. for Linux + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2014, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#ifndef __ACLINUXEX_H__ +#define __ACLINUXEX_H__ + +#ifdef __KERNEL__ + +/* + * Overrides for in-kernel ACPICA + */ +ACPI_STATUS __init AcpiOsInitialize ( + void); + +ACPI_STATUS AcpiOsTerminate ( + void); + +/* + * The irqs_disabled() check is for resume from RAM. + * Interrupts are off during resume, just like they are for boot. + * However, boot has (system_state != SYSTEM_RUNNING) + * to quiet __might_sleep() in kmalloc() and resume does not. + */ +static inline void * +AcpiOsAllocate ( + ACPI_SIZE Size) +{ + return kmalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL); +} + +static inline void * +AcpiOsAllocateZeroed ( + ACPI_SIZE Size) +{ + return kzalloc (Size, irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL); +} + +static inline void +AcpiOsFree ( + void *Memory) +{ + kfree (Memory); +} + +static inline void * +AcpiOsAcquireObject ( + ACPI_CACHE_T *Cache) +{ + return kmem_cache_zalloc (Cache, + irqs_disabled () ? GFP_ATOMIC : GFP_KERNEL); +} + +static inline ACPI_THREAD_ID +AcpiOsGetThreadId ( + void) +{ + return (ACPI_THREAD_ID) (unsigned long) current; +} + +/* + * When lockdep is enabled, the spin_lock_init() macro stringifies it's + * argument and uses that as a name for the lock in debugging. + * By executing spin_lock_init() in a macro the key changes from "lock" for + * all locks to the name of the argument of acpi_os_create_lock(), which + * prevents lockdep from reporting false positives for ACPICA locks. + */ +#define AcpiOsCreateLock(__Handle) \ + ({ \ + spinlock_t *Lock = ACPI_ALLOCATE(sizeof(*Lock)); \ + if (Lock) { \ + *(__Handle) = Lock; \ + spin_lock_init(*(__Handle)); \ + } \ + Lock ? AE_OK : AE_NO_MEMORY; \ + }) + +void __iomem * +AcpiOsMapMemory ( + ACPI_PHYSICAL_ADDRESS Where, + ACPI_SIZE Length); + +void +AcpiOsUnmapMemory ( + void __iomem *LogicalAddress, + ACPI_SIZE Size); + +/* + * OSL interfaces added by Linux + */ +void +EarlyAcpiOsUnmapMemory ( + void __iomem *Virt, + ACPI_SIZE Size); + +#endif /* __KERNEL__ */ + +#endif /* __ACLINUXEX_H__ */ diff --git a/sys/contrib/dev/acpica/source/os_specific/service_layers/oslinuxtbl.c b/sys/contrib/dev/acpica/source/os_specific/service_layers/osefitbl.c similarity index 66% copy from sys/contrib/dev/acpica/source/os_specific/service_layers/oslinuxtbl.c copy to sys/contrib/dev/acpica/source/os_specific/service_layers/osefitbl.c index aee929e0ee..341f3ddd35 100644 --- a/sys/contrib/dev/acpica/source/os_specific/service_layers/oslinuxtbl.c +++ b/sys/contrib/dev/acpica/source/os_specific/service_layers/osefitbl.c @@ -1,6 +1,6 @@ /****************************************************************************** * - * Module Name: oslinuxtbl - Linux OSL for obtaining ACPI tables + * Module Name: osefitbl - EFI OSL for obtaining ACPI tables * *****************************************************************************/ @@ -45,7 +45,7 @@ #define _COMPONENT ACPI_OS_SERVICES - ACPI_MODULE_NAME ("oslinuxtbl") + ACPI_MODULE_NAME ("osefitbl") #ifndef PATH_MAX @@ -69,24 +69,11 @@ static ACPI_STATUS OslTableInitialize ( void); -static ACPI_STATUS -OslTableNameFromFile ( - char *Filename, - char *Signature, - UINT32 *Instance); - static ACPI_STATUS OslAddTableToList ( char *Signature, UINT32 Instance); -static ACPI_STATUS -OslReadTableFromFile ( - char *Filename, - ACPI_SIZE FileOffset, - char *Signature, - ACPI_TABLE_HEADER **Table); - static ACPI_STATUS OslMapTable ( ACPI_SIZE Address, @@ -97,52 +84,26 @@ static void OslUnmapTable ( ACPI_TABLE_HEADER *Table); -static ACPI_PHYSICAL_ADDRESS -OslFindRsdpViaEfi ( - void); - static ACPI_STATUS OslLoadRsdp ( void); static ACPI_STATUS -OslListCustomizedTables ( - char *Directory); - -static ACPI_STATUS -OslGetCustomizedTable ( - char *Pathname, - char *Signature, - UINT32 Instance, - ACPI_TABLE_HEADER **Table, - ACPI_PHYSICAL_ADDRESS *Address); - -static ACPI_STATUS -OslListBiosTables ( +OslListTables ( void); static ACPI_STATUS -OslGetBiosTable ( +OslGetTable ( char *Signature, UINT32 Instance, ACPI_TABLE_HEADER **Table, ACPI_PHYSICAL_ADDRESS *Address); -static ACPI_STATUS -OslGetLastStatus ( - ACPI_STATUS DefaultStatus); - /* File locations */ -#define DYNAMIC_TABLE_DIR "/sys/firmware/acpi/tables/dynamic" -#define STATIC_TABLE_DIR "/sys/firmware/acpi/tables" #define EFI_SYSTAB "/sys/firmware/efi/systab" -/* Should we get dynamically loaded SSDTs from DYNAMIC_TABLE_DIR? */ - -UINT8 Gbl_DumpDynamicTables = TRUE; - /* Initialization flags */ UINT8 Gbl_TableListInitialized = FALSE; @@ -167,45 +128,6 @@ OSL_TABLE_INFO *Gbl_TableListHead = NULL; UINT32 Gbl_TableCount = 0; -/****************************************************************************** - * - * FUNCTION: OslGetLastStatus - * - * PARAMETERS: DefaultStatus - Default error status to return - * - * RETURN: Status; Converted from errno. - * - * DESCRIPTION: Get last errno and conver it to ACPI_STATUS. - * - *****************************************************************************/ - -static ACPI_STATUS -OslGetLastStatus ( - ACPI_STATUS DefaultStatus) -{ - - switch (errno) - { - case EACCES: - case EPERM: - - return (AE_ACCESS); - - case ENOENT: - - return (AE_NOT_FOUND); - - case ENOMEM: - - return (AE_NO_MEMORY); - - default: - - return (DefaultStatus); - } -} - - /****************************************************************************** * * FUNCTION: AcpiOsGetTableByAddress @@ -256,7 +178,7 @@ AcpiOsGetTableByAddress ( goto Exit; } - LocalTable = calloc (1, TableLength); + LocalTable = ACPI_ALLOCATE_ZEROED (TableLength); if (!LocalTable) { Status = AE_NO_MEMORY; @@ -315,25 +237,13 @@ AcpiOsGetTableByName ( { /* Attempt to get the table from the memory */ - Status = OslGetBiosTable (Signature, Instance, Table, Address); + Status = OslGetTable (Signature, Instance, Table, Address); } else { /* Attempt to get the table from the static directory */ - Status = OslGetCustomizedTable (STATIC_TABLE_DIR, Signature, - Instance, Table, Address); - } - - if (ACPI_FAILURE (Status) && Status == AE_LIMIT) - { - if (Gbl_DumpDynamicTables) - { - /* Attempt to get a dynamic table */ - - Status = OslGetCustomizedTable (DYNAMIC_TABLE_DIR, Signature, - Instance, Table, Address); - } + Status = AE_SUPPORT; } return (Status); @@ -365,7 +275,7 @@ OslAddTableToList ( BOOLEAN Found = FALSE; - NewInfo = calloc (1, sizeof (OSL_TABLE_INFO)); + NewInfo = ACPI_ALLOCATE_ZEROED (sizeof (OSL_TABLE_INFO)); if (!NewInfo) { return (AE_NO_MEMORY); @@ -407,7 +317,7 @@ OslAddTableToList ( { if (Instance) { - fprintf (stderr, + AcpiLogError ( "%4.4s: Warning unmatched table instance %d, expected %d\n", Signature, Instance, NextInstance); } @@ -488,44 +398,6 @@ AcpiOsGetTableByIndex ( } -/****************************************************************************** - * - * FUNCTION: OslFindRsdpViaEfi - * - * PARAMETERS: None - * - * RETURN: RSDP address if found - * - * DESCRIPTION: Find RSDP address via EFI. - * - *****************************************************************************/ - -static ACPI_PHYSICAL_ADDRESS -OslFindRsdpViaEfi ( - void) -{ - FILE *File; - char Buffer[80]; - unsigned long Address = 0; - - - File = fopen (EFI_SYSTAB, "r"); - if (File) - { - while (fgets (Buffer, 80, File)) - { - if (sscanf (Buffer, "ACPI20=0x%lx", &Address) == 1) - { - break; - } - } - fclose (File); - } - - return ((ACPI_PHYSICAL_ADDRESS) (Address)); -} - - /****************************************************************************** * * FUNCTION: OslLoadRsdp @@ -557,7 +429,7 @@ OslLoadRsdp ( } else { - RsdpBase = OslFindRsdpViaEfi (); + RsdpBase = AcpiOsGetRootPointer (); } if (!RsdpBase) @@ -569,7 +441,7 @@ OslLoadRsdp ( RsdpAddress = AcpiOsMapMemory (RsdpBase, RsdpSize); if (!RsdpAddress) { - return (OslGetLastStatus (AE_BAD_ADDRESS)); + return (AE_BAD_ADDRESS); } /* Search low memory for the RSDP */ @@ -660,12 +532,12 @@ OslTableInitialize ( { if (Gbl_Xsdt) { - free (Gbl_Xsdt); + ACPI_FREE (Gbl_Xsdt); Gbl_Xsdt = NULL; } Gbl_Revision = 2; - Status = OslGetBiosTable (ACPI_SIG_XSDT, 0, + Status = OslGetTable (ACPI_SIG_XSDT, 0, ACPI_CAST_PTR (ACPI_TABLE_HEADER *, &Gbl_Xsdt), &Address); if (ACPI_FAILURE (Status)) { @@ -679,11 +551,11 @@ OslTableInitialize ( { if (Gbl_Rsdt) { - free (Gbl_Rsdt); + ACPI_FREE (Gbl_Rsdt); Gbl_Rsdt = NULL; } - Status = OslGetBiosTable (ACPI_SIG_RSDT, 0, + Status = OslGetTable (ACPI_SIG_RSDT, 0, ACPI_CAST_PTR (ACPI_TABLE_HEADER *, &Gbl_Rsdt), &Address); if (ACPI_FAILURE (Status)) { @@ -695,11 +567,11 @@ OslTableInitialize ( if (Gbl_Fadt) { - free (Gbl_Fadt); + ACPI_FREE (Gbl_Fadt); Gbl_Fadt = NULL; } - Status = OslGetBiosTable (ACPI_SIG_FADT, 0, + Status = OslGetTable (ACPI_SIG_FADT, 0, ACPI_CAST_PTR (ACPI_TABLE_HEADER *, &Gbl_Fadt), &Gbl_FadtAddress); if (ACPI_FAILURE (Status)) { @@ -745,7 +617,7 @@ OslTableInitialize ( /* Add all tables found in the memory */ - Status = OslListBiosTables (); + Status = OslListTables (); if (ACPI_FAILURE (Status)) { return (Status); @@ -755,22 +627,7 @@ OslTableInitialize ( { /* Add all tables found in the static directory */ - Status = OslListCustomizedTables (STATIC_TABLE_DIR); - if (ACPI_FAILURE (Status)) - { - return (Status); - } - } - - if (Gbl_DumpDynamicTables) - { - /* Add all dynamically loaded tables in the dynamic directory */ - - Status = OslListCustomizedTables (DYNAMIC_TABLE_DIR); - if (ACPI_FAILURE (Status)) - { - return (Status); - } + Status = AE_SUPPORT; } Gbl_TableListInitialized = TRUE; @@ -780,7 +637,7 @@ OslTableInitialize ( /****************************************************************************** * - * FUNCTION: OslListBiosTables + * FUNCTION: OslListTables * * PARAMETERS: None * @@ -788,13 +645,10 @@ OslTableInitialize ( * * DESCRIPTION: Add ACPI tables to the table list from memory. * - * NOTE: This works on Linux as table customization does not modify the - * addresses stored in RSDP/RSDT/XSDT/FADT. - * *****************************************************************************/ static ACPI_STATUS -OslListBiosTables ( +OslListTables ( void) { ACPI_TABLE_HEADER *MappedTable = NULL; @@ -861,7 +715,7 @@ OslListBiosTables ( /****************************************************************************** * - * FUNCTION: OslGetBiosTable + * FUNCTION: OslGetTable * * PARAMETERS: Signature - ACPI Signature for common table. Must be * a null terminated 4-character string. @@ -881,7 +735,7 @@ OslListBiosTables ( *****************************************************************************/ static ACPI_STATUS -OslGetBiosTable ( +OslGetTable ( char *Signature, UINT32 Instance, ACPI_TABLE_HEADER **Table, @@ -1050,7 +904,7 @@ OslGetBiosTable ( /* Copy table to local buffer and return it */ - LocalTable = calloc (1, TableLength); + LocalTable = ACPI_ALLOCATE_ZEROED (TableLength); if (!LocalTable) { Status = AE_NO_MEMORY; @@ -1067,66 +921,6 @@ Exit: } -/****************************************************************************** - * - * FUNCTION: OslListCustomizedTables - * - * PARAMETERS: Directory - Directory that contains the tables - * - * RETURN: Status; Table list is initialized if AE_OK. - * - * DESCRIPTION: Add ACPI tables to the table list from a directory. - * - *****************************************************************************/ - -static ACPI_STATUS -OslListCustomizedTables ( - char *Directory) -{ - void *TableDir; - UINT32 Instance; - char TempName[ACPI_NAME_SIZE]; - char *Filename; - ACPI_STATUS Status = AE_OK; - - - /* Open the requested directory */ - - TableDir = AcpiOsOpenDirectory (Directory, "*", REQUEST_FILE_ONLY); - if (!TableDir) - { - return (OslGetLastStatus (AE_NOT_FOUND)); - } - - /* Examine all entries in this directory */ - - while ((Filename = AcpiOsGetNextFilename (TableDir))) - { - /* Extract table name and instance number */ - - Status = OslTableNameFromFile (Filename, TempName, &Instance); - - /* Ignore meaningless files */ - - if (ACPI_FAILURE (Status)) - { - continue; - } - - /* Add new info node to global table list */ - - Status = OslAddTableToList (TempName, Instance); - if (ACPI_FAILURE (Status)) - { - break; - } - } - - AcpiOsCloseDirectory (TableDir); - return (Status); -} - - /****************************************************************************** * * FUNCTION: OslMapTable @@ -1168,9 +962,9 @@ OslMapTable ( MappedTable = AcpiOsMapMemory (Address, sizeof (ACPI_TABLE_HEADER)); if (!MappedTable) { - fprintf (stderr, "Could not map table header at 0x%8.8X%8.8X\n", + AcpiLogError ("Could not map table header at 0x%8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Address)); - return (OslGetLastStatus (AE_BAD_ADDRESS)); + return (AE_BAD_ADDRESS); } /* If specified, signature must match */ @@ -1204,9 +998,9 @@ OslMapTable ( MappedTable = AcpiOsMapMemory (Address, Length); if (!MappedTable) { - fprintf (stderr, "Could not map table at 0x%8.8X%8.8X length %8.8X\n", + AcpiLogError ("Could not map table at 0x%8.8X%8.8X length %8.8X\n", ACPI_FORMAT_UINT64 (Address), Length); - return (OslGetLastStatus (AE_INVALID_TABLE_LENGTH)); + return (AE_INVALID_TABLE_LENGTH); } (void) ApIsValidChecksum (MappedTable); @@ -1237,266 +1031,3 @@ OslUnmapTable ( AcpiOsUnmapMemory (Table, ApGetTableLength (Table)); } } - - -/****************************************************************************** - * - * FUNCTION: OslTableNameFromFile - * - * PARAMETERS: Filename - File that contains the desired table - * Signature - Pointer to 4-character buffer to store - * extracted table signature. - * Instance - Pointer to integer to store extracted - * table instance number. - * - * RETURN: Status; Table name is extracted if AE_OK. - * - * DESCRIPTION: Extract table signature and instance number from a table file - * name. - * - *****************************************************************************/ - -static ACPI_STATUS -OslTableNameFromFile ( - char *Filename, - char *Signature, - UINT32 *Instance) -{ - - /* Ignore meaningless files */ - - if (strlen (Filename) < ACPI_NAME_SIZE) - { - return (AE_BAD_SIGNATURE); - } - - /* Extract instance number */ - - if (isdigit ((int) Filename[ACPI_NAME_SIZE])) - { - sscanf (&Filename[ACPI_NAME_SIZE], "%d", Instance); - } - else if (strlen (Filename) != ACPI_NAME_SIZE) - { - return (AE_BAD_SIGNATURE); - } - else - { - *Instance = 0; - } - - /* Extract signature */ - - ACPI_MOVE_NAME (Signature, Filename); - return (AE_OK); -} - - -/****************************************************************************** - * - * FUNCTION: OslReadTableFromFile - * - * PARAMETERS: Filename - File that contains the desired table - * FileOffset - Offset of the table in file - * Signature - Optional ACPI Signature for desired table. - * A null terminated 4-character string. - * Table - Where a pointer to the table is returned - * - * RETURN: Status; Table buffer is returned if AE_OK. - * - * DESCRIPTION: Read a ACPI table from a file. - * - *****************************************************************************/ - -static ACPI_STATUS -OslReadTableFromFile ( - char *Filename, - ACPI_SIZE FileOffset, - char *Signature, - ACPI_TABLE_HEADER **Table) -{ - FILE *TableFile; - ACPI_TABLE_HEADER Header; - ACPI_TABLE_HEADER *LocalTable = NULL; - UINT32 TableLength; - INT32 Count; - ACPI_STATUS Status = AE_OK; - - - /* Open the file */ - - TableFile = fopen (Filename, "rb"); - if (TableFile == NULL) - { - fprintf (stderr, "Could not open table file: %s\n", Filename); - return (OslGetLastStatus (AE_NOT_FOUND)); - } - - fseek (TableFile, FileOffset, SEEK_SET); - - /* Read the Table header to get the table length */ - - Count = fread (&Header, 1, sizeof (ACPI_TABLE_HEADER), TableFile); - if (Count != sizeof (ACPI_TABLE_HEADER)) - { - fprintf (stderr, "Could not read table header: %s\n", Filename); - Status = AE_BAD_HEADER; - goto Exit; - } - - /* If signature is specified, it must match the table */ - - if (Signature) - { - if (ACPI_VALIDATE_RSDP_SIG (Signature)) - { - if (!ACPI_VALIDATE_RSDP_SIG (Header.Signature)) { - fprintf (stderr, "Incorrect RSDP signature: found %8.8s\n", - Header.Signature); - Status = AE_BAD_SIGNATURE; - goto Exit; - } - } - else if (!ACPI_COMPARE_NAME (Signature, Header.Signature)) - { - fprintf (stderr, "Incorrect signature: Expecting %4.4s, found %4.4s\n", - Signature, Header.Signature); - Status = AE_BAD_SIGNATURE; - goto Exit; - } - } - - TableLength = ApGetTableLength (&Header); - if (TableLength == 0) - { - Status = AE_BAD_HEADER; - goto Exit; - } - - /* Read the entire table into a local buffer */ - - LocalTable = calloc (1, TableLength); - if (!LocalTable) - { - fprintf (stderr, - "%4.4s: Could not allocate buffer for table of length %X\n", - Header.Signature, TableLength); - Status = AE_NO_MEMORY; - goto Exit; - } - - fseek (TableFile, FileOffset, SEEK_SET); - - Count = fread (LocalTable, 1, TableLength, TableFile); - if (Count != TableLength) - { - fprintf (stderr, "%4.4s: Could not read table content\n", - Header.Signature); - Status = AE_INVALID_TABLE_LENGTH; - goto Exit; - } - - /* Validate checksum */ - - (void) ApIsValidChecksum (LocalTable); - -Exit: - fclose (TableFile); - *Table = LocalTable; - return (Status); -} - - -/****************************************************************************** - * - * FUNCTION: OslGetCustomizedTable - * - * PARAMETERS: Pathname - Directory to find Linux customized table - * Signature - ACPI Signature for desired table. Must be - * a null terminated 4-character string. - * Instance - Multiple table support for SSDT/UEFI (0...n) - * Must be 0 for other tables. - * Table - Where a pointer to the table is returned - * Address - Where the table physical address is returned - * - * RETURN: Status; Table buffer is returned if AE_OK. - * AE_LIMIT: Instance is beyond valid limit - * AE_NOT_FOUND: A table with the signature was not found - * - * DESCRIPTION: Get an OS customized table. - * - *****************************************************************************/ - -static ACPI_STATUS -OslGetCustomizedTable ( - char *Pathname, - char *Signature, - UINT32 Instance, - ACPI_TABLE_HEADER **Table, - ACPI_PHYSICAL_ADDRESS *Address) -{ - void *TableDir; - UINT32 CurrentInstance = 0; - char TempName[ACPI_NAME_SIZE]; - char TableFilename[PATH_MAX]; - char *Filename; - ACPI_STATUS Status; - - - /* Open the directory for customized tables */ - - TableDir = AcpiOsOpenDirectory (Pathname, "*", REQUEST_FILE_ONLY); - if (!TableDir) - { - return (OslGetLastStatus (AE_NOT_FOUND)); - } - - /* Attempt to find the table in the directory */ - - while ((Filename = AcpiOsGetNextFilename (TableDir))) - { - /* Ignore meaningless files */ - - if (!ACPI_COMPARE_NAME (Filename, Signature)) - { - continue; - } - - /* Extract table name and instance number */ - - Status = OslTableNameFromFile (Filename, TempName, &CurrentInstance); - - /* Ignore meaningless files */ - - if (ACPI_FAILURE (Status) || CurrentInstance != Instance) - { - continue; - } - - /* Create the table pathname */ - - if (Instance != 0) - { - sprintf (TableFilename, "%s/%4.4s%d", Pathname, TempName, Instance); - } - else - { - sprintf (TableFilename, "%s/%4.4s", Pathname, TempName); - } - break; - } - - AcpiOsCloseDirectory (TableDir); - - if (!Filename) - { - return (AE_LIMIT); - } - - /* There is no physical address saved for customized tables, use zero */ - - *Address = 0; - Status = OslReadTableFromFile (TableFilename, 0, NULL, Table); - - return (Status); -} diff --git a/sys/contrib/dev/acpica/source/os_specific/service_layers/osefixf.c b/sys/contrib/dev/acpica/source/os_specific/service_layers/osefixf.c new file mode 100644 index 0000000000..3f6c5da335 --- /dev/null +++ b/sys/contrib/dev/acpica/source/os_specific/service_layers/osefixf.c @@ -0,0 +1,1300 @@ +/****************************************************************************** + * + * Module Name: osefixf - EFI OSL interfaces + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2014, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include "acpi.h" +#include "accommon.h" +#include "acapps.h" + + +/* Local definitions */ + +#define ACPI_EFI_PRINT_LENGTH 256 + + +/* Local definitions */ + +typedef struct acpi_efi_memory_descriptor { + EFI_MEMORY_DESCRIPTOR *Descriptor; + UINTN EntryCount; + UINTN EntrySize; + UINTN Cookie; + UINT32 Version; +} ACPI_EFI_MEMORY_DESCRIPTOR; + + +/* Local prototypes */ + +static void * +AcpiEfiAllocatePool ( + ACPI_SIZE Size); + +static ACPI_STATUS +AcpiEfiArgify ( + char *String, + int *ArgcPtr, + char ***ArgvPtr); + +static BOOLEAN +AcpiEfiCompareGuid ( + EFI_GUID *Guid1, + EFI_GUID *Guid2); + +static ACPI_STATUS +AcpiEfiConvertArgcv ( + CHAR16 *LoadOpt, + UINT32 LoadOptSize, + int *ArgcPtr, + char ***ArgvPtr, + char **BufferPtr); + +static ACPI_PHYSICAL_ADDRESS +AcpiEfiGetRsdpViaGuid ( + EFI_GUID *Guid); + +static CHAR16 * +AcpiEfiFlushFile ( + ACPI_FILE File, + CHAR16 *Begin, + CHAR16 *End, + CHAR16 *Pos, + BOOLEAN FlushAll); + +static void +AcpiEfiFreePool ( + void *Mem); + +static ACPI_STATUS +AcpiEfiInitializeMemoryMap ( + void); + +static void +AcpiEfiTerminateMemoryMap ( + void); + + +/* Local variables */ + +static EFI_FILE_HANDLE AcpiGbl_EfiCurrentVolume = NULL; +static ACPI_EFI_MEMORY_DESCRIPTOR AcpiGbl_EfiMemoryMap; +static BOOLEAN AcpiGbl_EfiMemoryInitialized = FALSE; +static UINTN AcpiGbl_EfiPoolAllocation = EfiBootServicesData; + + +/****************************************************************************** + * + * FUNCTION: AcpiEfiGetRsdpViaGuid + * + * PARAMETERS: Guid1 - GUID to compare + * Guid2 - GUID to compare + * + * RETURN: TRUE if Guid1 == Guid2 + * + * DESCRIPTION: Compares two GUIDs + * + *****************************************************************************/ + +static BOOLEAN +AcpiEfiCompareGuid ( + EFI_GUID *Guid1, + EFI_GUID *Guid2) +{ + INT32 *g1; + INT32 *g2; + INT32 r; + + + g1 = (INT32 *) Guid1; + g2 = (INT32 *) Guid2; + + r = g1[0] - g2[0]; + r |= g1[1] - g2[1]; + r |= g1[2] - g2[2]; + r |= g1[3] - g2[3]; + + return (r ? FALSE : TRUE); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiEfiInitializeMemoryMap + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Initialize EFI memory map. + * + *****************************************************************************/ + +static ACPI_STATUS +AcpiEfiInitializeMemoryMap ( + void) +{ + EFI_STATUS Status; + ACPI_EFI_MEMORY_DESCRIPTOR *Map; + UINT32 Length; + + + if (AcpiGbl_EfiMemoryInitialized) + { + return (AE_OK); + } + + /* Initialize */ + + Map = &AcpiGbl_EfiMemoryMap; + Length = sizeof (EFI_MEMORY_DESCRIPTOR); + Map->Descriptor = NULL; + Status = EFI_BUFFER_TOO_SMALL; + + /* Allocation and GetMemoryMap() loop */ + + while (!AcpiGbl_EfiMemoryInitialized && + Status == EFI_BUFFER_TOO_SMALL) + { + Map->Descriptor = AcpiEfiAllocatePool (Length); + if (!Map->Descriptor) + { + return (AE_NO_MEMORY); + } + Status = uefi_call_wrapper (BS->GetMemoryMap, 5, + &Length, Map->Descriptor, + &Map->Cookie, &Map->EntrySize, &Map->Version); + if (!EFI_ERROR (Status)) + { + AcpiGbl_EfiMemoryInitialized = TRUE; + } + else if (Status == EFI_BUFFER_TOO_SMALL) + { + AcpiEfiFreePool (Map->Descriptor); + } + } + + /* Finalize */ + + if (!AcpiGbl_EfiMemoryInitialized) + { + if (Map->Descriptor) + { + AcpiEfiFreePool (Map->Descriptor); + Map->Descriptor = NULL; + } + return (AE_ERROR); + } + else + { + Map->EntryCount = Length / sizeof (EFI_MEMORY_DESCRIPTOR); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiEfiTerminateMemoryMap + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Terminate EFI memory map. + * + *****************************************************************************/ + +static void +AcpiEfiTerminateMemoryMap ( + void) +{ + + if (AcpiGbl_EfiMemoryInitialized) + { + AcpiEfiFreePool (AcpiGbl_EfiMemoryMap.Descriptor); + AcpiGbl_EfiMemoryInitialized = FALSE; + } +} + + +/****************************************************************************** + * + * FUNCTION: AcpiEfiGetRsdpViaGuid + * + * PARAMETERS: None + * + * RETURN: RSDP address if found + * + * DESCRIPTION: Find RSDP address via EFI using specified GUID. + * + *****************************************************************************/ + +static ACPI_PHYSICAL_ADDRESS +AcpiEfiGetRsdpViaGuid ( + EFI_GUID *Guid) +{ + unsigned long Address = 0; + int i; + + + for (i = 0; i < ST->NumberOfTableEntries; i++) + { + if (AcpiEfiCompareGuid (&ST->ConfigurationTable[i].VendorGuid, Guid)) + { + Address = (ACPI_PHYSICAL_ADDRESS) + ST->ConfigurationTable[i].VendorTable; + break; + } + } + + return ((ACPI_PHYSICAL_ADDRESS) (Address)); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiEfiAllocatePool + * + * PARAMETERS: Size - Amount to allocate, in bytes + * + * RETURN: Pointer to the new allocation. Null on error. + * + * DESCRIPTION: Allocate pool memory. + * + *****************************************************************************/ + +static void * +AcpiEfiAllocatePool ( + ACPI_SIZE Size) +{ + EFI_STATUS EfiStatus; + void *Mem; + + + EfiStatus = uefi_call_wrapper (BS->AllocatePool, 3, + AcpiGbl_EfiPoolAllocation, Size, &Mem); + if (EFI_ERROR (EfiStatus)) + { + AcpiLogError ("EFI_BOOT_SERVICES->AllocatePool(EfiLoaderData) failure.\n"); + return (NULL); + } + + return (Mem); +} + +/****************************************************************************** + * + * FUNCTION: AcpiEfiFreePool + * + * PARAMETERS: Mem - Pointer to previously allocated memory + * + * RETURN: None + * + * DESCRIPTION: Free memory allocated via AcpiEfiAllocatePool + * + *****************************************************************************/ + +static void +AcpiEfiFreePool ( + void *Mem) +{ + + uefi_call_wrapper (BS->FreePool, 1, Mem); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiOsGetRootPointer + * + * PARAMETERS: None + * + * RETURN: RSDP physical address + * + * DESCRIPTION: Gets the ACPI root pointer (RSDP) + * + *****************************************************************************/ + +ACPI_PHYSICAL_ADDRESS +AcpiOsGetRootPointer ( + void) +{ + ACPI_PHYSICAL_ADDRESS Address; + EFI_GUID Guid10 = ACPI_TABLE_GUID; + EFI_GUID Guid20 = ACPI_20_TABLE_GUID; + + + Address = AcpiEfiGetRsdpViaGuid (&Guid20); + if (!Address) + { + Address = AcpiEfiGetRsdpViaGuid (&Guid10); + } + + return (Address); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiOsMapMemory + * + * PARAMETERS: where - Physical address of memory to be mapped + * length - How much memory to map + * + * RETURN: Pointer to mapped memory. Null on error. + * + * DESCRIPTION: Map physical memory into caller's address space + * + *****************************************************************************/ + +void * +AcpiOsMapMemory ( + ACPI_PHYSICAL_ADDRESS where, + ACPI_SIZE length) +{ + UINTN i; + EFI_MEMORY_DESCRIPTOR *p; + UINT64 Size; + EFI_PHYSICAL_ADDRESS End; + + + for (i = 0, p = AcpiGbl_EfiMemoryMap.Descriptor; + i < AcpiGbl_EfiMemoryMap.EntryCount; + i++, p = ACPI_ADD_PTR (EFI_MEMORY_DESCRIPTOR, p, AcpiGbl_EfiMemoryMap.EntrySize)) + { + Size = p->NumberOfPages << EFI_PAGE_SHIFT; + End = p->PhysicalStart + Size; + + if (!(p->Attribute & EFI_MEMORY_RUNTIME) || !p->VirtualStart) + { + continue; + } + + if (where >= p->PhysicalStart && where < End) + { + where += p->VirtualStart - p->PhysicalStart; + break; + } + } + + /* Default to use the physical address */ + + return (ACPI_TO_POINTER ((ACPI_SIZE) where)); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiOsUnmapMemory + * + * PARAMETERS: where - Logical address of memory to be unmapped + * length - How much memory to unmap + * + * RETURN: None + * + * DESCRIPTION: Delete a previously created mapping. Where and Length must + * correspond to a previous mapping exactly. + * + *****************************************************************************/ + +void +AcpiOsUnmapMemory ( + void *where, + ACPI_SIZE length) +{ + + return; +} + + +/****************************************************************************** + * + * FUNCTION: Spinlock interfaces + * + * DESCRIPTION: No-op on single threaded BIOS + * + *****************************************************************************/ + +ACPI_STATUS +AcpiOsCreateLock ( + ACPI_SPINLOCK *OutHandle) +{ + return (AE_OK); +} + +void +AcpiOsDeleteLock ( + ACPI_SPINLOCK Handle) +{ +} + +ACPI_CPU_FLAGS +AcpiOsAcquireLock ( + ACPI_SPINLOCK Handle) +{ + return (0); +} + +void +AcpiOsReleaseLock ( + ACPI_SPINLOCK Handle, + ACPI_CPU_FLAGS Flags) +{ +} + + +/****************************************************************************** + * + * FUNCTION: AcpiOsAllocate + * + * PARAMETERS: Size - Amount to allocate, in bytes + * + * RETURN: Pointer to the new allocation. Null on error. + * + * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS. + * + *****************************************************************************/ + +void * +AcpiOsAllocate ( + ACPI_SIZE Size) +{ + EFI_STATUS EfiStatus; + void *Mem; + + + EfiStatus = uefi_call_wrapper (BS->AllocatePool, 3, + EfiLoaderData, Size, &Mem); + if (EFI_ERROR (EfiStatus)) + { + AcpiLogError ("EFI_BOOT_SERVICES->AllocatePool(EfiLoaderData) failure.\n"); + return (NULL); + } + + return (Mem); +} + + +#ifdef USE_NATIVE_ALLOCATE_ZEROED +/****************************************************************************** + * + * FUNCTION: AcpiOsAllocateZeroed + * + * PARAMETERS: Size - Amount to allocate, in bytes + * + * RETURN: Pointer to the new allocation. Null on error. + * + * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS. + * + *****************************************************************************/ + +void * +AcpiOsAllocateZeroed ( + ACPI_SIZE Size) +{ + void *Mem; + + + Mem = AcpiOsAllocate (Size); + if (Mem) + { + ACPI_MEMSET (Mem, 0, Size); + } + + return (Mem); +} +#endif + + +/****************************************************************************** + * + * FUNCTION: AcpiOsFree + * + * PARAMETERS: Mem - Pointer to previously allocated memory + * + * RETURN: None + * + * DESCRIPTION: Free memory allocated via AcpiOsAllocate + * + *****************************************************************************/ + +void +AcpiOsFree ( + void *Mem) +{ + + uefi_call_wrapper (BS->FreePool, 1, Mem); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsOpenFile + * + * PARAMETERS: Path - File path + * Modes - File operation type + * + * RETURN: File descriptor + * + * DESCRIPTION: Open a file for reading (ACPI_FILE_READING) or/and writing + * (ACPI_FILE_WRITING). + * + ******************************************************************************/ + +ACPI_FILE +AcpiOsOpenFile ( + const char *Path, + UINT8 Modes) +{ + EFI_STATUS EfiStatus = EFI_SUCCESS; + UINT64 OpenModes; + EFI_FILE_HANDLE EfiFile = NULL; + CHAR16 *Path16 = NULL; + CHAR16 *Pos16; + const char *Pos; + INTN Count, i; + + + if (!Path) + { + return (NULL); + } + + /* Convert modes */ + + OpenModes = EFI_FILE_MODE_READ; + if (Modes & ACPI_FILE_WRITING) + { + OpenModes |= (EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE); + } + + /* Allocate path buffer */ + + Count = ACPI_STRLEN (Path); + Path16 = ACPI_ALLOCATE_ZEROED ((Count + 1) * sizeof (CHAR16)); + if (!Path16) + { + EfiStatus = EFI_BAD_BUFFER_SIZE; + goto ErrorExit; + } + Pos = Path; + Pos16 = Path16; + while (*Pos == '/' || *Pos == '\\') + { + Pos++; + Count--; + } + for (i = 0; i < Count; i++) + { + if (*Pos == '/') + { + *Pos16++ = '\\'; + Pos++; + } + else + { + *Pos16++ = *Pos++; + } + } + *Pos16 = '\0'; + + EfiStatus = uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Open, 5, + AcpiGbl_EfiCurrentVolume, &EfiFile, Path16, OpenModes, 0); + if (EFI_ERROR (EfiStatus)) + { + AcpiLogError ("EFI_FILE_HANDLE->Open() failure.\n"); + goto ErrorExit; + } + +ErrorExit: + + if (Path16) + { + ACPI_FREE (Path16); + } + + return ((ACPI_FILE) EfiFile); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsCloseFile + * + * PARAMETERS: File - File descriptor + * + * RETURN: None. + * + * DESCRIPTION: Close a file. + * + ******************************************************************************/ + +void +AcpiOsCloseFile ( + ACPI_FILE File) +{ + EFI_FILE_HANDLE EfiFile; + + + if (File == ACPI_FILE_OUT || + File == ACPI_FILE_ERR) + { + return; + } + EfiFile = (EFI_FILE_HANDLE) File; + (void) uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Close, 1, EfiFile); + + return; +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsReadFile + * + * PARAMETERS: File - File descriptor + * Buffer - Data buffer + * Size - Data block size + * Count - Number of data blocks + * + * RETURN: Size of successfully read buffer + * + * DESCRIPTION: Read from a file. + * + ******************************************************************************/ + +int +AcpiOsReadFile ( + ACPI_FILE File, + void *Buffer, + ACPI_SIZE Size, + ACPI_SIZE Count) +{ + int Length = -1; + EFI_FILE_HANDLE EfiFile; + UINTN ReadSize; + EFI_STATUS EfiStatus; + + + if (File == ACPI_FILE_OUT || + File == ACPI_FILE_ERR) + { + } + else + { + EfiFile = (EFI_FILE_HANDLE) File; + if (!EfiFile) + { + goto ErrorExit; + } + ReadSize = Size * Count; + + EfiStatus = uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Read, 3, + EfiFile, &ReadSize, Buffer); + if (EFI_ERROR (EfiStatus)) + { + AcpiLogError ("EFI_FILE_HANDLE->Read() failure.\n"); + goto ErrorExit; + } + Length = ReadSize; + } + +ErrorExit: + + return (Length); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiEfiFlushFile + * + * PARAMETERS: File - File descriptor + * Begin - String with boundary + * End - Boundary of the string + * Pos - Current position + * FlushAll - Whether checking boundary before flushing + * + * RETURN: Updated position + * + * DESCRIPTION: Flush cached buffer to the file. + * + ******************************************************************************/ + +static CHAR16 * +AcpiEfiFlushFile ( + ACPI_FILE File, + CHAR16 *Begin, + CHAR16 *End, + CHAR16 *Pos, + BOOLEAN FlushAll) +{ + + if (FlushAll || Pos >= (End - 1)) + { + *Pos = 0; + uefi_call_wrapper (File->OutputString, 2, File, Begin); + Pos = Begin; + } + + return (Pos); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsWriteFile + * + * PARAMETERS: File - File descriptor + * Buffer - Data buffer + * Size - Data block size + * Count - Number of data blocks + * + * RETURN: Size of successfully written buffer + * + * DESCRIPTION: Write to a file. + * + ******************************************************************************/ + +int +AcpiOsWriteFile ( + ACPI_FILE File, + void *Buffer, + ACPI_SIZE Size, + ACPI_SIZE Count) +{ + int Length = -1; + CHAR16 String[ACPI_EFI_PRINT_LENGTH]; + const char *Ascii; + CHAR16 *End; + CHAR16 *Pos; + int i, j; + EFI_FILE_HANDLE EfiFile; + UINTN WriteSize; + EFI_STATUS EfiStatus; + + + if (File == ACPI_FILE_OUT || + File == ACPI_FILE_ERR) + { + Pos = String; + End = String + ACPI_EFI_PRINT_LENGTH - 1; + Ascii = ACPI_CAST_PTR (const char, Buffer); + Length = 0; + + for (j = 0; j < Count; j++) + { + for (i = 0; i < Size; i++) + { + if (*Ascii == '\n') + { + *Pos++ = '\r'; + Pos = AcpiEfiFlushFile (File, String, + End, Pos, FALSE); + } + *Pos++ = *Ascii++; + Length++; + Pos = AcpiEfiFlushFile (File, String, + End, Pos, FALSE); + } + } + Pos = AcpiEfiFlushFile (File, String, End, Pos, TRUE); + } + else + { + EfiFile = (EFI_FILE_HANDLE) File; + if (!EfiFile) + { + goto ErrorExit; + } + WriteSize = Size * Count; + + EfiStatus = uefi_call_wrapper (AcpiGbl_EfiCurrentVolume->Write, 3, + EfiFile, &WriteSize, Buffer); + if (EFI_ERROR (EfiStatus)) + { + AcpiLogError ("EFI_FILE_HANDLE->Write() failure.\n"); + goto ErrorExit; + } + Length = WriteSize; + } + +ErrorExit: + + return (Length); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsGetFileOffset + * + * PARAMETERS: File - File descriptor + * + * RETURN: Size of current position + * + * DESCRIPTION: Get current file offset. + * + ******************************************************************************/ + +long +AcpiOsGetFileOffset ( + ACPI_FILE File) +{ + long Offset = -1; + + + return (Offset); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsSetFileOffset + * + * PARAMETERS: File - File descriptor + * Offset - File offset + * From - From begin/end of file + * + * RETURN: Status + * + * DESCRIPTION: Set current file offset. + * + ******************************************************************************/ + +ACPI_STATUS +AcpiOsSetFileOffset ( + ACPI_FILE File, + long Offset, + UINT8 From) +{ + + return (AE_SUPPORT); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiOsPrintf + * + * PARAMETERS: Format, ... - Standard printf format + * + * RETURN: None + * + * DESCRIPTION: Formatted output. + * + *****************************************************************************/ + +void ACPI_INTERNAL_VAR_XFACE +AcpiOsPrintf ( + const char *Format, + ...) +{ + va_list Args; + + + va_start (Args, Format); + AcpiOsVprintf (Format, Args); + va_end (Args); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiOsVprintf + * + * PARAMETERS: Format - Standard printf format + * Args - Argument list + * + * RETURN: None + * + * DESCRIPTION: Formatted output with arguments list pointer. + * + *****************************************************************************/ + +void +AcpiOsVprintf ( + const char *Format, + va_list Args) +{ + + (void) AcpiUtFileVprintf (ACPI_FILE_OUT, Format, Args); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiOsInitialize + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Initialize this module. + * + *****************************************************************************/ + +ACPI_STATUS +AcpiOsInitialize ( + void) +{ + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiEfiArgify + * + * PARAMETERS: String - Pointer to command line argument strings + * which are seperated with spaces + * ArgcPtr - Return number of the arguments + * ArgvPtr - Return vector of the arguments + * + * RETURN: Status + * + * DESCRIPTION: Convert EFI arguments into C arguments. + * + *****************************************************************************/ + +static ACPI_STATUS +AcpiEfiArgify ( + char *String, + int *ArgcPtr, + char ***ArgvPtr) +{ + char *CopyBuffer; + int MaxArgc = *ArgcPtr; + int Argc = 0; + char **Argv = *ArgvPtr; + char *Arg; + BOOLEAN IsSingleQuote = FALSE; + BOOLEAN IsDoubleQuote = FALSE; + BOOLEAN IsEscape = FALSE; + + + if (String == NULL) + { + return (AE_BAD_PARAMETER); + } + + CopyBuffer = String; + + while (*String != '\0') + { + while (ACPI_IS_SPACE (*String)) + { + *String++ = '\0'; + } + Arg = CopyBuffer; + while (*String != '\0') + { + if (ACPI_IS_SPACE (*String) && + !IsSingleQuote && !IsDoubleQuote && !IsEscape) + { + *Arg++ = '\0'; + String++; + break; + } + if (IsEscape) + { + IsEscape = FALSE; + *Arg++ = *String; + } + else if (*String == '\\') + { + IsEscape = TRUE; + } + else if (IsSingleQuote) + { + if (*String == '\'') + { + IsSingleQuote = FALSE; + *Arg++ = '\0'; + } + else + { + *Arg++ = *String; + } + } + else if (IsDoubleQuote) + { + if (*String == '"') + { + IsDoubleQuote = FALSE; + *Arg = '\0'; + } + else + { + *Arg++ = *String; + } + } + else + { + if (*String == '\'') + { + IsSingleQuote = TRUE; + } + else if (*String == '"') + { + IsDoubleQuote = TRUE; + } + else + { + *Arg++ = *String; + } + } + String++; + } + if (Argv && Argc < MaxArgc) + { + Argv[Argc] = CopyBuffer; + } + Argc++; + CopyBuffer = Arg; + } + if (Argv && Argc < MaxArgc) + { + Argv[Argc] = NULL; + } + + *ArgcPtr = Argc; + *ArgvPtr = Argv; + + return ((MaxArgc < Argc) ? AE_NO_MEMORY : AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: AcpiEfiConvertArgcv + * + * PARAMETERS: LoadOptions - Pointer to the EFI options buffer, which + * is NULL terminated + * LoadOptionsSize - Size of the EFI options buffer + * ArgcPtr - Return number of the arguments + * ArgvPtr - Return vector of the arguments + * BufferPtr - Buffer to contain the argument strings + * + * RETURN: Status + * + * DESCRIPTION: Convert EFI arguments into C arguments. + * + *****************************************************************************/ + +static ACPI_STATUS +AcpiEfiConvertArgcv ( + CHAR16 *LoadOptions, + UINT32 LoadOptionsSize, + int *ArgcPtr, + char ***ArgvPtr, + char **BufferPtr) +{ + ACPI_STATUS Status = AE_OK; + UINT32 Count = LoadOptionsSize / sizeof (CHAR16); + UINT32 i; + CHAR16 *From; + char *To; + int Argc = 0; + char **Argv = NULL; + char *Buffer; + + + /* Prepare a buffer to contain the argument strings */ + + Buffer = ACPI_ALLOCATE_ZEROED (Count); + if (!Buffer) + { + Status = AE_NO_MEMORY; + goto ErrorExit; + } + +TryAgain: + + /* Extend the argument vector */ + + if (Argv) + { + ACPI_FREE (Argv); + Argv = NULL; + } + if (Argc > 0) + { + Argv = ACPI_ALLOCATE_ZEROED (sizeof (char *) * (Argc + 1)); + if (!Argv) + { + Status = AE_NO_MEMORY; + goto ErrorExit; + } + } + + /* + * Note: As AcpiEfiArgify() will modify the content of the buffer, so + * we need to restore it each time before invoking + * AcpiEfiArgify(). + */ + From = LoadOptions; + To = ACPI_CAST_PTR (char, Buffer); + for (i = 0; i < Count; i++) + { + *To++ = (char) *From++; + } + + /* + * The "Buffer" will contain NULL terminated strings after invoking + * AcpiEfiArgify(). The number of the strings are saved in Argc and the + * pointers of the strings are saved in Argv. + */ + Status = AcpiEfiArgify (Buffer, &Argc, &Argv); + if (ACPI_FAILURE (Status)) + { + if (Status == AE_NO_MEMORY) + { + goto TryAgain; + } + } + +ErrorExit: + + if (ACPI_FAILURE (Status)) + { + ACPI_FREE (Buffer); + ACPI_FREE (Argv); + } + else + { + *ArgcPtr = Argc; + *ArgvPtr = Argv; + *BufferPtr = Buffer; + } + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: efi_main + * + * PARAMETERS: Image - EFI image handle + * SystemTab - EFI system table + * + * RETURN: EFI Status + * + * DESCRIPTION: Entry point of EFI executable + * + *****************************************************************************/ + +EFI_STATUS +efi_main ( + EFI_HANDLE Image, + EFI_SYSTEM_TABLE *SystemTab) +{ + EFI_LOADED_IMAGE *Info; + EFI_STATUS EfiStatus = EFI_SUCCESS; + ACPI_STATUS Status; + int argc; + char **argv = NULL; + char *OptBuffer = NULL; + EFI_FILE_IO_INTERFACE *Volume = NULL; + + + /* Initialize EFI library */ + + InitializeLib (Image, SystemTab); + + /* Retrieve image information */ + + EfiStatus = uefi_call_wrapper (BS->HandleProtocol, 3, + Image, &LoadedImageProtocol, ACPI_CAST_PTR (VOID, &Info)); + if (EFI_ERROR (EfiStatus)) + { + AcpiLogError ("EFI_BOOT_SERVICES->HandleProtocol(LoadedImageProtocol) failure.\n"); + return (EfiStatus); + } + AcpiGbl_EfiPoolAllocation = Info->ImageDataType; + EfiStatus = uefi_call_wrapper (BS->HandleProtocol, 3, + Info->DeviceHandle, &FileSystemProtocol, (void **) &Volume); + if (EFI_ERROR (EfiStatus)) + { + AcpiLogError ("EFI_BOOT_SERVICES->HandleProtocol(FileSystemProtocol) failure.\n"); + return (EfiStatus); + } + EfiStatus = uefi_call_wrapper (Volume->OpenVolume, 2, + Volume, &AcpiGbl_EfiCurrentVolume); + if (EFI_ERROR (EfiStatus)) + { + AcpiLogError ("EFI_FILE_IO_INTERFACE->OpenVolume() failure.\n"); + return (EfiStatus); + } + Status = AcpiEfiInitializeMemoryMap (); + if (ACPI_FAILURE (Status)) + { + EfiStatus = EFI_DEVICE_ERROR; + goto ErrorAlloc; + } + + Status = AcpiEfiConvertArgcv (Info->LoadOptions, + Info->LoadOptionsSize, &argc, &argv, &OptBuffer); + if (ACPI_FAILURE (Status)) + { + EfiStatus = EFI_DEVICE_ERROR; + goto ErrorAlloc; + } + + acpi_main (argc, argv); + +ErrorAlloc: + + if (argv) + { + ACPI_FREE (argv); + } + if (OptBuffer) + { + ACPI_FREE (OptBuffer); + } + AcpiEfiTerminateMemoryMap (); + + return (EfiStatus); +} diff --git a/sys/contrib/dev/acpica/source/os_specific/service_layers/oslibcfs.c b/sys/contrib/dev/acpica/source/os_specific/service_layers/oslibcfs.c new file mode 100644 index 0000000000..3bb55bb94c --- /dev/null +++ b/sys/contrib/dev/acpica/source/os_specific/service_layers/oslibcfs.c @@ -0,0 +1,251 @@ +/****************************************************************************** + * + * Module Name: oslibcfs - C library OSL for file IO + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2014, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include "acpi.h" +#include +#include + +#define _COMPONENT ACPI_OS_SERVICES + ACPI_MODULE_NAME ("oslibcfs") + + +/******************************************************************************* + * + * FUNCTION: AcpiOsOpenFile + * + * PARAMETERS: Path - File path + * Modes - File operation type + * + * RETURN: File descriptor. + * + * DESCRIPTION: Open a file for reading (ACPI_FILE_READING) or/and writing + * (ACPI_FILE_WRITING). + * + ******************************************************************************/ + +ACPI_FILE +AcpiOsOpenFile ( + const char *Path, + UINT8 Modes) +{ + ACPI_FILE File; + char ModesStr[4]; + UINT32 i = 0; + + if (Modes & ACPI_FILE_READING) + { + ModesStr[i++] = 'r'; + } + if (Modes & ACPI_FILE_WRITING) + { + ModesStr[i++] = 'w'; + } + if (Modes & ACPI_FILE_BINARY) + { + ModesStr[i++] = 'b'; + } + ModesStr[i++] = '\0'; + + File = fopen (Path, ModesStr); + if (!File) + { + perror ("Could not open file"); + } + + return (File); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsCloseFile + * + * PARAMETERS: File - File descriptor + * + * RETURN: None. + * + * DESCRIPTION: Close a file. + * + ******************************************************************************/ + +void +AcpiOsCloseFile ( + ACPI_FILE File) +{ + fclose (File); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsReadFile + * + * PARAMETERS: File - File descriptor + * Buffer - Data buffer + * Size - Data block size + * Count - Number of data blocks + * + * RETURN: Size of successfully read buffer. + * + * DESCRIPTION: Read a file. + * + ******************************************************************************/ + +int +AcpiOsReadFile ( + ACPI_FILE File, + void *Buffer, + ACPI_SIZE Size, + ACPI_SIZE Count) +{ + int Length; + + Length = fread (Buffer, Size, Count, File); + if (Length < 0) + { + perror ("Error reading file"); + } + + return (Length); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsWriteFile + * + * PARAMETERS: File - File descriptor + * Buffer - Data buffer + * Size - Data block size + * Count - Number of data blocks + * + * RETURN: Size of successfully written buffer. + * + * DESCRIPTION: Write a file. + * + ******************************************************************************/ + +int +AcpiOsWriteFile ( + ACPI_FILE File, + void *Buffer, + ACPI_SIZE Size, + ACPI_SIZE Count) +{ + int Length; + + Length = fwrite (Buffer, Size, Count, File); + if (Length < 0) + { + perror ("Error writing file"); + } + + return (Length); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsGetFileOffset + * + * PARAMETERS: File - File descriptor + * + * RETURN: Size of current position. + * + * DESCRIPTION: Get current file offset. + * + ******************************************************************************/ + +long +AcpiOsGetFileOffset ( + ACPI_FILE File) +{ + long Offset; + + Offset = ftell (File); + + return (Offset); +} + + +/******************************************************************************* + * + * FUNCTION: AcpiOsSetFileOffset + * + * PARAMETERS: File - File descriptor + * Offset - File offset + * From - From begin/end of file + * + * RETURN: Status + * + * DESCRIPTION: Set current file offset. + * + ******************************************************************************/ + +ACPI_STATUS +AcpiOsSetFileOffset ( + ACPI_FILE File, + long Offset, + UINT8 From) +{ + int Ret = 0; + + + if (From == ACPI_FILE_BEGIN) + { + Ret = fseek (File, Offset, SEEK_SET); + } + if (From == ACPI_FILE_END) + { + Ret = fseek (File, Offset, SEEK_END); + } + + if (Ret < 0) + { + return (AE_ERROR); + } + else + { + return (AE_OK); + } +} diff --git a/sys/contrib/dev/acpica/source/os_specific/service_layers/oslinuxtbl.c b/sys/contrib/dev/acpica/source/os_specific/service_layers/oslinuxtbl.c index aee929e0ee..aae93325ad 100644 --- a/sys/contrib/dev/acpica/source/os_specific/service_layers/oslinuxtbl.c +++ b/sys/contrib/dev/acpica/source/os_specific/service_layers/oslinuxtbl.c @@ -97,6 +97,11 @@ static void OslUnmapTable ( ACPI_TABLE_HEADER *Table); +static ACPI_PHYSICAL_ADDRESS +OslFindRsdpViaEfiByKeyword ( + FILE *File, + const char *Keyword); + static ACPI_PHYSICAL_ADDRESS OslFindRsdpViaEfi ( void); @@ -488,6 +493,44 @@ AcpiOsGetTableByIndex ( } +/****************************************************************************** + * + * FUNCTION: OslFindRsdpViaEfiByKeyword + * + * PARAMETERS: Keyword - Character string indicating ACPI GUID version + * in the EFI table + * + * RETURN: RSDP address if found + * + * DESCRIPTION: Find RSDP address via EFI using keyword indicating the ACPI + * GUID version. + * + *****************************************************************************/ + +static ACPI_PHYSICAL_ADDRESS +OslFindRsdpViaEfiByKeyword ( + FILE *File, + const char *Keyword) +{ + char Buffer[80]; + unsigned long long Address = 0; + char Format[32]; + + + snprintf (Format, 32, "%s=%s", Keyword, "%llx"); + fseek (File, 0, SEEK_SET); + while (fgets (Buffer, 80, File)) + { + if (sscanf (Buffer, Format, &Address) == 1) + { + break; + } + } + + return ((ACPI_PHYSICAL_ADDRESS) (Address)); +} + + /****************************************************************************** * * FUNCTION: OslFindRsdpViaEfi @@ -505,24 +548,21 @@ OslFindRsdpViaEfi ( void) { FILE *File; - char Buffer[80]; - unsigned long Address = 0; + ACPI_PHYSICAL_ADDRESS Address = 0; File = fopen (EFI_SYSTAB, "r"); if (File) { - while (fgets (Buffer, 80, File)) + Address = OslFindRsdpViaEfiByKeyword (File, "ACPI20"); + if (!Address) { - if (sscanf (Buffer, "ACPI20=0x%lx", &Address) == 1) - { - break; - } + Address = OslFindRsdpViaEfiByKeyword (File, "ACPI"); } fclose (File); } - return ((ACPI_PHYSICAL_ADDRESS) (Address)); + return (Address); } @@ -907,6 +947,11 @@ OslGetBiosTable ( ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT) || ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS)) { + if (Instance > 0) + { + return (AE_LIMIT); + } + /* * Get the appropriate address, either 32-bit or 64-bit. Be very * careful about the FADT length and validate table addresses. diff --git a/sys/contrib/dev/acpica/source/os_specific/service_layers/osunixxf.c b/sys/contrib/dev/acpica/source/os_specific/service_layers/osunixxf.c index dd151eee95..eb088b9dd1 100644 --- a/sys/contrib/dev/acpica/source/os_specific/service_layers/osunixxf.c +++ b/sys/contrib/dev/acpica/source/os_specific/service_layers/osunixxf.c @@ -65,16 +65,11 @@ ACPI_MODULE_NAME ("osunixxf") -FILE *AcpiGbl_OutputFile; BOOLEAN AcpiGbl_DebugTimeout = FALSE; /* Upcalls to AcpiExec */ -ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( - void); - void AeTableOverride ( ACPI_TABLE_HEADER *ExistingTable, @@ -214,10 +209,19 @@ ACPI_STATUS AcpiOsInitialize ( void) { + ACPI_STATUS Status; + AcpiGbl_OutputFile = stdout; OsEnterLineEditMode (); + + Status = AcpiOsCreateLock (&AcpiGbl_PrintLock); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + return (AE_OK); } @@ -231,6 +235,7 @@ AcpiOsTerminate ( } +#ifndef ACPI_USE_NATIVE_RSDP_POINTER /****************************************************************************** * * FUNCTION: AcpiOsGetRootPointer @@ -248,8 +253,9 @@ AcpiOsGetRootPointer ( void) { - return (AeLocalGetRootPointer ()); + return (0); } +#endif /****************************************************************************** @@ -548,6 +554,7 @@ AcpiOsGetLine ( #endif +#ifndef ACPI_USE_NATIVE_MEMORY_MAPPING /****************************************************************************** * * FUNCTION: AcpiOsMapMemory @@ -593,6 +600,7 @@ AcpiOsUnmapMemory ( return; } +#endif /****************************************************************************** @@ -619,6 +627,32 @@ AcpiOsAllocate ( } +#ifdef USE_NATIVE_ALLOCATE_ZEROED +/****************************************************************************** + * + * FUNCTION: AcpiOsAllocateZeroed + * + * PARAMETERS: Size - Amount to allocate, in bytes + * + * RETURN: Pointer to the new allocation. Null on error. + * + * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS. + * + *****************************************************************************/ + +void * +AcpiOsAllocateZeroed ( + ACPI_SIZE size) +{ + void *Mem; + + + Mem = (void *) calloc (1, (size_t) size); + return (Mem); +} +#endif + + /****************************************************************************** * * FUNCTION: AcpiOsFree @@ -1454,6 +1488,26 @@ AcpiOsExecute ( return (0); } +#else /* ACPI_SINGLE_THREADED */ +ACPI_THREAD_ID +AcpiOsGetThreadId ( + void) +{ + return (1); +} + +ACPI_STATUS +AcpiOsExecute ( + ACPI_EXECUTE_TYPE Type, + ACPI_OSD_EXEC_CALLBACK Function, + void *Context) +{ + + Function (Context); + + return (AE_OK); +} + #endif /* ACPI_SINGLE_THREADED */ diff --git a/sys/contrib/dev/acpica/source/os_specific/service_layers/oswinxf.c b/sys/contrib/dev/acpica/source/os_specific/service_layers/oswinxf.c index 667a9f9053..140bfdbb88 100644 --- a/sys/contrib/dev/acpica/source/os_specific/service_layers/oswinxf.c +++ b/sys/contrib/dev/acpica/source/os_specific/service_layers/oswinxf.c @@ -64,7 +64,6 @@ ACPI_MODULE_NAME ("oswinxf") -FILE *AcpiGbl_OutputFile; UINT64 TimerFrequency; char TableName[ACPI_NAME_SIZE + 1]; @@ -73,10 +72,6 @@ char TableName[ACPI_NAME_SIZE + 1]; /* Upcalls to AcpiExec application */ -ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( - void); - void AeTableOverride ( ACPI_TABLE_HEADER *ExistingTable, @@ -143,6 +138,7 @@ ACPI_STATUS AcpiOsInitialize ( void) { + ACPI_STATUS Status; LARGE_INTEGER LocalTimerFrequency; @@ -164,10 +160,17 @@ AcpiOsInitialize ( TimerFrequency = LocalTimerFrequency.QuadPart; } + Status = AcpiOsCreateLock (&AcpiGbl_PrintLock); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + return (AE_OK); } +#ifndef ACPI_USE_NATIVE_RSDP_POINTER /****************************************************************************** * * FUNCTION: AcpiOsGetRootPointer @@ -185,8 +188,9 @@ AcpiOsGetRootPointer ( void) { - return (AeLocalGetRootPointer ()); + return (0); } +#endif /****************************************************************************** @@ -554,6 +558,7 @@ AcpiOsGetLine ( } +#ifndef ACPI_USE_NATIVE_MEMORY_MAPPING /****************************************************************************** * * FUNCTION: AcpiOsMapMemory @@ -599,6 +604,7 @@ AcpiOsUnmapMemory ( return; } +#endif /****************************************************************************** @@ -626,6 +632,33 @@ AcpiOsAllocate ( } +#ifdef USE_NATIVE_ALLOCATE_ZEROED +/****************************************************************************** + * + * FUNCTION: AcpiOsAllocateZeroed + * + * PARAMETERS: Size - Amount to allocate, in bytes + * + * RETURN: Pointer to the new allocation. Null on error. + * + * DESCRIPTION: Allocate and zero memory. Algorithm is dependent on the OS. + * + *****************************************************************************/ + +void * +AcpiOsAllocateZeroed ( + ACPI_SIZE Size) +{ + void *Mem; + + + Mem = (void *) calloc (1, (size_t) Size); + + return (Mem); +} +#endif + + /****************************************************************************** * * FUNCTION: AcpiOsFree @@ -1486,6 +1519,26 @@ AcpiOsExecute ( return (0); } +#else /* ACPI_SINGLE_THREADED */ +ACPI_THREAD_ID +AcpiOsGetThreadId ( + void) +{ + return (1); +} + +ACPI_STATUS +AcpiOsExecute ( + ACPI_EXECUTE_TYPE Type, + ACPI_OSD_EXEC_CALLBACK Function, + void *Context) +{ + + Function (Context); + + return (AE_OK); +} + #endif /* ACPI_SINGLE_THREADED */ diff --git a/sys/contrib/dev/acpica/source/tools/acpibin/abcompare.c b/sys/contrib/dev/acpica/source/tools/acpibin/abcompare.c index d843400ffb..84eb3c27e2 100644 --- a/sys/contrib/dev/acpica/source/tools/acpibin/abcompare.c +++ b/sys/contrib/dev/acpica/source/tools/acpibin/abcompare.c @@ -77,10 +77,6 @@ AbPrintHeadersInfo ( ACPI_TABLE_HEADER *Header, ACPI_TABLE_HEADER *Header2); -ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( - void); - /****************************************************************************** * @@ -628,26 +624,3 @@ Exit1: * DESCRIPTION: For linkage * ******************************************************************************/ - -ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( - void) -{ - return (AE_OK); -} - -ACPI_THREAD_ID -AcpiOsGetThreadId ( - void) -{ - return (0xFFFF); -} - -ACPI_STATUS -AcpiOsExecute ( - ACPI_EXECUTE_TYPE Type, - ACPI_OSD_EXEC_CALLBACK Function, - void *Context) -{ - return (AE_SUPPORT); -} diff --git a/sys/contrib/dev/acpica/source/tools/acpibin/abmain.c b/sys/contrib/dev/acpica/source/tools/acpibin/abmain.c index d8c740cd75..d6b1acd7e9 100644 --- a/sys/contrib/dev/acpica/source/tools/acpibin/abmain.c +++ b/sys/contrib/dev/acpica/source/tools/acpibin/abmain.c @@ -119,7 +119,7 @@ main ( /* Command line options */ - while ((j = AcpiGetopt (argc, argv, AB_SUPPORTED_OPTIONS)) != EOF) switch(j) + while ((j = AcpiGetopt (argc, argv, AB_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch(j) { case 'c': /* Compare Files */ diff --git a/sys/contrib/dev/acpica/source/tools/acpidump/acpidump.h b/sys/contrib/dev/acpica/source/tools/acpidump/acpidump.h index 1064eb4c6c..f5c021a499 100644 --- a/sys/contrib/dev/acpica/source/tools/acpidump/acpidump.h +++ b/sys/contrib/dev/acpica/source/tools/acpidump/acpidump.h @@ -48,7 +48,6 @@ #ifdef _DECLARE_GLOBALS #define EXTERN #define INIT_GLOBAL(a,b) a=b -#define DEFINE_ACPI_GLOBALS 1 #else #define EXTERN extern #define INIT_GLOBAL(a,b) a @@ -71,7 +70,7 @@ EXTERN BOOLEAN INIT_GLOBAL (Gbl_VerboseMode, FALSE); EXTERN BOOLEAN INIT_GLOBAL (Gbl_BinaryMode, FALSE); EXTERN BOOLEAN INIT_GLOBAL (Gbl_DumpCustomizedTables, FALSE); EXTERN BOOLEAN INIT_GLOBAL (Gbl_DoNotDumpXsdt, FALSE); -EXTERN FILE INIT_GLOBAL (*Gbl_OutputFile, NULL); +EXTERN ACPI_FILE INIT_GLOBAL (Gbl_OutputFile, NULL); EXTERN char INIT_GLOBAL (*Gbl_OutputFilename, NULL); EXTERN UINT64 INIT_GLOBAL (Gbl_RsdpBase, 0); diff --git a/sys/contrib/dev/acpica/source/tools/acpidump/apdump.c b/sys/contrib/dev/acpica/source/tools/acpidump/apdump.c index 0bd0294988..ab5c32cde6 100644 --- a/sys/contrib/dev/acpica/source/tools/acpidump/apdump.c +++ b/sys/contrib/dev/acpica/source/tools/acpidump/apdump.c @@ -76,7 +76,7 @@ ApIsValidHeader ( if (!AcpiUtValidAcpiName (Table->Signature)) { - fprintf (stderr, "Table signature (0x%8.8X) is invalid\n", + AcpiLogError ("Table signature (0x%8.8X) is invalid\n", *(UINT32 *) Table->Signature); return (FALSE); } @@ -85,7 +85,7 @@ ApIsValidHeader ( if (Table->Length < sizeof (ACPI_TABLE_HEADER)) { - fprintf (stderr, "Table length (0x%8.8X) is invalid\n", + AcpiLogError ("Table length (0x%8.8X) is invalid\n", Table->Length); return (FALSE); } @@ -131,7 +131,7 @@ ApIsValidChecksum ( if (ACPI_FAILURE (Status)) { - fprintf (stderr, "%4.4s: Warning: wrong checksum in table\n", + AcpiLogError ("%4.4s: Warning: wrong checksum in table\n", Table->Signature); } @@ -223,12 +223,13 @@ ApDumpTableBuffer ( * Note: simplest to just always emit a 64-bit address. AcpiXtract * utility can handle this. */ - printf ("%4.4s @ 0x%8.8X%8.8X\n", Table->Signature, - ACPI_FORMAT_UINT64 (Address)); + AcpiUtFilePrintf (Gbl_OutputFile, "%4.4s @ 0x%8.8X%8.8X\n", + Table->Signature, ACPI_FORMAT_UINT64 (Address)); - AcpiUtDumpBuffer (ACPI_CAST_PTR (UINT8, Table), TableLength, + AcpiUtDumpBufferToFile (Gbl_OutputFile, + ACPI_CAST_PTR (UINT8, Table), TableLength, DB_BYTE_DISPLAY, 0); - printf ("\n"); + AcpiUtFilePrintf (Gbl_OutputFile, "\n"); return (0); } @@ -273,20 +274,20 @@ ApDumpAllTables ( } else if (i == 0) { - fprintf (stderr, "Could not get ACPI tables, %s\n", + AcpiLogError ("Could not get ACPI tables, %s\n", AcpiFormatException (Status)); return (-1); } else { - fprintf (stderr, "Could not get ACPI table at index %u, %s\n", + AcpiLogError ("Could not get ACPI table at index %u, %s\n", i, AcpiFormatException (Status)); continue; } } TableStatus = ApDumpTableBuffer (Table, Instance, Address); - free (Table); + ACPI_FREE (Table); if (TableStatus) { @@ -328,7 +329,7 @@ ApDumpTableByAddress ( Status = AcpiUtStrtoul64 (AsciiAddress, 0, &LongAddress); if (ACPI_FAILURE (Status)) { - fprintf (stderr, "%s: Could not convert to a physical address\n", + AcpiLogError ("%s: Could not convert to a physical address\n", AsciiAddress); return (-1); } @@ -337,14 +338,14 @@ ApDumpTableByAddress ( Status = AcpiOsGetTableByAddress (Address, &Table); if (ACPI_FAILURE (Status)) { - fprintf (stderr, "Could not get table at 0x%8.8X%8.8X, %s\n", + AcpiLogError ("Could not get table at 0x%8.8X%8.8X, %s\n", ACPI_FORMAT_UINT64 (Address), AcpiFormatException (Status)); return (-1); } TableStatus = ApDumpTableBuffer (Table, 0, Address); - free (Table); + ACPI_FREE (Table); return (TableStatus); } @@ -374,9 +375,9 @@ ApDumpTableByName ( int TableStatus; - if (strlen (Signature) != ACPI_NAME_SIZE) + if (ACPI_STRLEN (Signature) != ACPI_NAME_SIZE) { - fprintf (stderr, + AcpiLogError ( "Invalid table signature [%s]: must be exactly 4 characters\n", Signature); return (-1); @@ -384,18 +385,18 @@ ApDumpTableByName ( /* Table signatures are expected to be uppercase */ - strcpy (LocalSignature, Signature); + ACPI_STRCPY (LocalSignature, Signature); AcpiUtStrupr (LocalSignature); /* To be friendly, handle tables whose signatures do not match the name */ if (ACPI_COMPARE_NAME (LocalSignature, "FADT")) { - strcpy (LocalSignature, ACPI_SIG_FADT); + ACPI_STRCPY (LocalSignature, ACPI_SIG_FADT); } else if (ACPI_COMPARE_NAME (LocalSignature, "MADT")) { - strcpy (LocalSignature, ACPI_SIG_MADT); + ACPI_STRCPY (LocalSignature, ACPI_SIG_MADT); } /* Dump all instances of this signature (to handle multiple SSDTs) */ @@ -413,14 +414,14 @@ ApDumpTableByName ( return (0); } - fprintf (stderr, + AcpiLogError ( "Could not get ACPI table with signature [%s], %s\n", LocalSignature, AcpiFormatException (Status)); return (-1); } TableStatus = ApDumpTableBuffer (Table, Instance, Address); - free (Table); + ACPI_FREE (Table); if (TableStatus) { @@ -467,7 +468,7 @@ ApDumpTableFromFile ( if (Table->Length > FileSize) { - fprintf (stderr, + AcpiLogError ( "Table length (0x%X) is too large for input file (0x%X) %s\n", Table->Length, FileSize, Pathname); goto Exit; @@ -475,7 +476,7 @@ ApDumpTableFromFile ( if (Gbl_VerboseMode) { - fprintf (stderr, + AcpiLogError ( "Input file: %s contains table [%4.4s], 0x%X (%u) bytes\n", Pathname, Table->Signature, FileSize, FileSize); } @@ -483,35 +484,6 @@ ApDumpTableFromFile ( TableStatus = ApDumpTableBuffer (Table, 0, 0); Exit: - free (Table); + ACPI_FREE (Table); return (TableStatus); } - - -/****************************************************************************** - * - * FUNCTION: AcpiOs* print functions - * - * DESCRIPTION: Used for linkage with ACPICA modules - * - ******************************************************************************/ - -void ACPI_INTERNAL_VAR_XFACE -AcpiOsPrintf ( - const char *Fmt, - ...) -{ - va_list Args; - - va_start (Args, Fmt); - vfprintf (stdout, Fmt, Args); - va_end (Args); -} - -void -AcpiOsVprintf ( - const char *Fmt, - va_list Args) -{ - vfprintf (stdout, Fmt, Args); -} diff --git a/sys/contrib/dev/acpica/source/tools/acpidump/apfiles.c b/sys/contrib/dev/acpica/source/tools/acpidump/apfiles.c index 1588f2ef74..6633ce9040 100644 --- a/sys/contrib/dev/acpica/source/tools/acpidump/apfiles.c +++ b/sys/contrib/dev/acpica/source/tools/acpidump/apfiles.c @@ -45,6 +45,36 @@ #include "acapps.h" +/* Local prototypes */ + +static int +ApIsExistingFile ( + char *Pathname); + + +static int +ApIsExistingFile ( + char *Pathname) +{ +#ifndef _GNU_EFI + struct stat StatInfo; + + + if (!stat (Pathname, &StatInfo)) + { + AcpiLogError ("Target path already exists, overwrite? [y|n] "); + + if (getchar () != 'y') + { + return (-1); + } + } +#endif + + return 0; +} + + /****************************************************************************** * * FUNCTION: ApOpenOutputFile @@ -62,28 +92,22 @@ int ApOpenOutputFile ( char *Pathname) { - struct stat StatInfo; - FILE *File; + ACPI_FILE File; /* If file exists, prompt for overwrite */ - if (!stat (Pathname, &StatInfo)) + if (ApIsExistingFile (Pathname) != 0) { - fprintf (stderr, "Target path already exists, overwrite? [y|n] "); - - if (getchar () != 'y') - { - return (-1); - } + return (-1); } /* Point stdout to the file */ - File = freopen (Pathname, "w", stdout); + File = AcpiOsOpenFile (Pathname, ACPI_FILE_WRITING); if (!File) { - perror ("Could not open output file"); + AcpiLogError ("Could not open output file: %s\n", Pathname); return (-1); } @@ -116,7 +140,7 @@ ApWriteToBinaryFile ( { char Filename[ACPI_NAME_SIZE + 16]; char InstanceStr [16]; - FILE *File; + ACPI_FILE File; size_t Actual; UINT32 TableLength; @@ -145,37 +169,38 @@ ApWriteToBinaryFile ( if (Instance > 0) { - sprintf (InstanceStr, "%u", Instance); - strcat (Filename, InstanceStr); + AcpiUtSnprintf (InstanceStr, sizeof (InstanceStr), "%u", Instance); + ACPI_STRCAT (Filename, InstanceStr); } - strcat (Filename, ACPI_TABLE_FILE_SUFFIX); + ACPI_STRCAT (Filename, ACPI_TABLE_FILE_SUFFIX); if (Gbl_VerboseMode) { - fprintf (stderr, + AcpiLogError ( "Writing [%4.4s] to binary file: %s 0x%X (%u) bytes\n", Table->Signature, Filename, Table->Length, Table->Length); } /* Open the file and dump the entire table in binary mode */ - File = fopen (Filename, "wb"); + File = AcpiOsOpenFile (Filename, + ACPI_FILE_WRITING | ACPI_FILE_BINARY); if (!File) { - perror ("Could not open output file"); + AcpiLogError ("Could not open output file: %s\n", Filename); return (-1); } - Actual = fwrite (Table, 1, TableLength, File); + Actual = AcpiOsWriteFile (File, Table, 1, TableLength); if (Actual != TableLength) { - perror ("Error writing binary output file"); - fclose (File); + AcpiLogError ("Error writing binary output file: %s\n", Filename); + AcpiOsCloseFile (File); return (-1); } - fclose (File); + AcpiOsCloseFile (File); return (0); } @@ -199,17 +224,17 @@ ApGetTableFromFile ( UINT32 *OutFileSize) { ACPI_TABLE_HEADER *Buffer = NULL; - FILE *File; + ACPI_FILE File; UINT32 FileSize; size_t Actual; /* Must use binary mode */ - File = fopen (Pathname, "rb"); + File = AcpiOsOpenFile (Pathname, ACPI_FILE_READING | ACPI_FILE_BINARY); if (!File) { - perror ("Could not open input file"); + AcpiLogError ("Could not open input file: %s\n", Pathname); return (NULL); } @@ -218,29 +243,29 @@ ApGetTableFromFile ( FileSize = CmGetFileSize (File); if (FileSize == ACPI_UINT32_MAX) { - fprintf (stderr, + AcpiLogError ( "Could not get input file size: %s\n", Pathname); goto Cleanup; } /* Allocate a buffer for the entire file */ - Buffer = calloc (1, FileSize); + Buffer = ACPI_ALLOCATE_ZEROED (FileSize); if (!Buffer) { - fprintf (stderr, + AcpiLogError ( "Could not allocate file buffer of size: %u\n", FileSize); goto Cleanup; } /* Read the entire file */ - Actual = fread (Buffer, 1, FileSize, File); + Actual = AcpiOsReadFile (File, Buffer, 1, FileSize); if (Actual != FileSize) { - fprintf (stderr, + AcpiLogError ( "Could not read input file: %s\n", Pathname); - free (Buffer); + ACPI_FREE (Buffer); Buffer = NULL; goto Cleanup; } @@ -248,6 +273,6 @@ ApGetTableFromFile ( *OutFileSize = FileSize; Cleanup: - fclose (File); + AcpiOsCloseFile (File); return (Buffer); } diff --git a/sys/contrib/dev/acpica/source/tools/acpidump/apmain.c b/sys/contrib/dev/acpica/source/tools/acpidump/apmain.c index 8929b0fb0f..ffd1a2a40a 100644 --- a/sys/contrib/dev/acpica/source/tools/acpidump/apmain.c +++ b/sys/contrib/dev/acpica/source/tools/acpidump/apmain.c @@ -79,7 +79,7 @@ ApDoOptions ( int argc, char **argv); -static void +static int ApInsertAction ( char *Argument, UINT32 ToBeDone); @@ -119,7 +119,7 @@ ApDisplayUsage ( ACPI_OPTION ("-v", "Display version information"); ACPI_OPTION ("-z", "Verbose mode"); - printf ("\nTable Options:\n"); + ACPI_USAGE_TEXT ("\nTable Options:\n"); ACPI_OPTION ("-a
", "Get table via a physical address"); ACPI_OPTION ("-f ", "Get table via a binary file"); @@ -127,7 +127,7 @@ ApDisplayUsage ( ACPI_OPTION ("-x", "Do not use but dump XSDT"); ACPI_OPTION ("-x -x", "Do not use or dump XSDT"); - printf ( + ACPI_USAGE_TEXT ( "\n" "Invocation without parameters dumps all available tables\n" "Multiple mixed instances of -a, -f, and -n are supported\n\n"); @@ -141,13 +141,13 @@ ApDisplayUsage ( * PARAMETERS: Argument - Pointer to the argument for this action * ToBeDone - What to do to process this action * - * RETURN: None. Exits program if action table becomes full. + * RETURN: Status * * DESCRIPTION: Add an action item to the action table * ******************************************************************************/ -static void +static int ApInsertAction ( char *Argument, UINT32 ToBeDone) @@ -161,9 +161,11 @@ ApInsertAction ( CurrentAction++; if (CurrentAction > AP_MAX_ACTIONS) { - fprintf (stderr, "Too many table options (max %u)\n", AP_MAX_ACTIONS); - exit (-1); + AcpiLogError ("Too many table options (max %u)\n", AP_MAX_ACTIONS); + return (-1); } + + return (0); } @@ -191,7 +193,7 @@ ApDoOptions ( /* Command line options */ - while ((j = AcpiGetopt (argc, argv, AP_SUPPORTED_OPTIONS)) != EOF) switch (j) + while ((j = AcpiGetopt (argc, argv, AP_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j) { /* * Global options @@ -210,13 +212,13 @@ ApDoOptions ( case '?': ApDisplayUsage (); - exit (0); + return (1); case 'o': /* Redirect output to a single file */ if (ApOpenOutputFile (AcpiGbl_Optarg)) { - exit (-1); + return (-1); } continue; @@ -225,9 +227,9 @@ ApDoOptions ( Status = AcpiUtStrtoul64 (AcpiGbl_Optarg, 0, &Gbl_RsdpBase); if (ACPI_FAILURE (Status)) { - fprintf (stderr, "%s: Could not convert to a physical address\n", + AcpiLogError ("%s: Could not convert to a physical address\n", AcpiGbl_Optarg); - exit (-1); + return (-1); } continue; @@ -250,13 +252,13 @@ ApDoOptions ( case 'v': /* Revision/version */ - printf (ACPI_COMMON_SIGNON (AP_UTILITY_NAME)); - exit (0); + AcpiOsPrintf (ACPI_COMMON_SIGNON (AP_UTILITY_NAME)); + return (1); case 'z': /* Verbose mode */ Gbl_VerboseMode = TRUE; - fprintf (stderr, ACPI_COMMON_SIGNON (AP_UTILITY_NAME)); + AcpiLogError (ACPI_COMMON_SIGNON (AP_UTILITY_NAME)); continue; /* @@ -264,30 +266,42 @@ ApDoOptions ( */ case 'a': /* Get table by physical address */ - ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_ADDRESS); + if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_ADDRESS)) + { + return (-1); + } break; case 'f': /* Get table from a file */ - ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_FILE); + if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_FILE)) + { + return (-1); + } break; case 'n': /* Get table by input name (signature) */ - ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_NAME); + if (ApInsertAction (AcpiGbl_Optarg, AP_DUMP_TABLE_BY_NAME)) + { + return (-1); + } break; default: ApDisplayUsage (); - exit (-1); + return (-1); } /* If there are no actions, this means "get/dump all tables" */ if (CurrentAction == 0) { - ApInsertAction (NULL, AP_DUMP_ALL_TABLES); + if (ApInsertAction (NULL, AP_DUMP_ALL_TABLES)) + { + return (-1); + } } return (0); @@ -306,10 +320,17 @@ ApDoOptions ( * ******************************************************************************/ +#ifndef _GNU_EFI int ACPI_SYSTEM_XFACE main ( int argc, char *argv[]) +#else +int ACPI_SYSTEM_XFACE +acpi_main ( + int argc, + char *argv[]) +#endif { int Status = 0; AP_DUMP_ACTION *Action; @@ -318,12 +339,19 @@ main ( ACPI_DEBUG_INITIALIZE (); /* For debug version only */ + AcpiOsInitialize (); + Gbl_OutputFile = ACPI_FILE_OUT; /* Process command line options */ - if (ApDoOptions (argc, argv)) + Status = ApDoOptions (argc, argv); + if (Status > 0) { - return (-1); + return (0); + } + if (Status < 0) + { + return (Status); } /* Get/dump ACPI table(s) as requested */ @@ -355,7 +383,7 @@ main ( default: - fprintf (stderr, "Internal error, invalid action: 0x%X\n", + AcpiLogError ("Internal error, invalid action: 0x%X\n", Action->ToBeDone); return (-1); } @@ -366,18 +394,18 @@ main ( } } - if (Gbl_OutputFile) + if (Gbl_OutputFilename) { if (Gbl_VerboseMode) { /* Summary for the output file */ FileSize = CmGetFileSize (Gbl_OutputFile); - fprintf (stderr, "Output file %s contains 0x%X (%u) bytes\n\n", + AcpiLogError ("Output file %s contains 0x%X (%u) bytes\n\n", Gbl_OutputFilename, FileSize, FileSize); } - fclose (Gbl_OutputFile); + AcpiOsCloseFile (Gbl_OutputFile); } return (Status); diff --git a/sys/contrib/dev/acpica/source/tools/acpiexec/aehandlers.c b/sys/contrib/dev/acpica/source/tools/acpiexec/aehandlers.c index 5ad24e980c..1280ff6e64 100644 --- a/sys/contrib/dev/acpica/source/tools/acpiexec/aehandlers.c +++ b/sys/contrib/dev/acpica/source/tools/acpiexec/aehandlers.c @@ -1055,11 +1055,21 @@ AeInstallEarlyHandlers ( Status = AcpiDetachData (Handle, AeAttachedDataHandler); AE_CHECK_OK (AcpiDetachData, Status); - Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle); + /* Test attach data at the root object */ + + Status = AcpiAttachData (ACPI_ROOT_OBJECT, AeAttachedDataHandler, + AcpiGbl_RootNode); + AE_CHECK_OK (AcpiAttachData, Status); + + Status = AcpiAttachData (ACPI_ROOT_OBJECT, AeAttachedDataHandler2, + AcpiGbl_RootNode); AE_CHECK_OK (AcpiAttachData, Status); /* Test support for multiple attaches */ + Status = AcpiAttachData (Handle, AeAttachedDataHandler, Handle); + AE_CHECK_OK (AcpiAttachData, Status); + Status = AcpiAttachData (Handle, AeAttachedDataHandler2, Handle); AE_CHECK_OK (AcpiAttachData, Status); } @@ -1305,6 +1315,10 @@ AeRegionHandler ( switch (Function >> 16) { case AML_FIELD_ATTRIB_QUICK: + + Length = 0; + break; + case AML_FIELD_ATTRIB_SEND_RCV: case AML_FIELD_ATTRIB_BYTE: diff --git a/sys/contrib/dev/acpica/source/tools/acpiexec/aemain.c b/sys/contrib/dev/acpica/source/tools/acpiexec/aemain.c index 3aa9343af2..99dd1a27d3 100644 --- a/sys/contrib/dev/acpica/source/tools/acpiexec/aemain.c +++ b/sys/contrib/dev/acpica/source/tools/acpiexec/aemain.c @@ -166,7 +166,7 @@ AeDoOptions ( int j; - while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != EOF) switch (j) + while ((j = AcpiGetopt (argc, argv, AE_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j) { case 'b': @@ -375,22 +375,14 @@ main ( ACPI_DEBUG_INITIALIZE (); /* For debug version only */ - - printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME)); - if (argc < 2) - { - usage (); - return (0); - } - signal (SIGINT, AeCtrlCHandler); - /* Init globals */ + /* Init debug globals */ AcpiDbgLevel = ACPI_NORMAL_DEFAULT; AcpiDbgLayer = 0xFFFFFFFF; - /* Init ACPI and start debugger thread */ + /* Init ACPICA and start debugger thread */ Status = AcpiInitializeSubsystem (); AE_CHECK_OK (AcpiInitializeSubsystem, Status); @@ -399,6 +391,13 @@ main ( goto ErrorExit; } + printf (ACPI_COMMON_SIGNON (ACPIEXEC_NAME)); + if (argc < 2) + { + usage (); + return (0); + } + /* Get the command line options */ if (AeDoOptions (argc, argv)) @@ -422,7 +421,7 @@ main ( { /* Get one entire table */ - Status = AcpiDbReadTableFromFile (argv[AcpiGbl_Optind], &Table); + Status = AcpiUtReadTableFromFile (argv[AcpiGbl_Optind], &Table); if (ACPI_FAILURE (Status)) { printf ("**** Could not get table from file %s, %s\n", diff --git a/sys/contrib/dev/acpica/source/tools/acpiexec/aetables.c b/sys/contrib/dev/acpica/source/tools/acpiexec/aetables.c index e873b484d9..a9becc22fd 100644 --- a/sys/contrib/dev/acpica/source/tools/acpiexec/aetables.c +++ b/sys/contrib/dev/acpica/source/tools/acpiexec/aetables.c @@ -60,10 +60,6 @@ AeTableOverride ( ACPI_TABLE_HEADER *ExistingTable, ACPI_TABLE_HEADER **NewTable); -ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( - void); - /* User table (DSDT) */ static ACPI_TABLE_HEADER *DsdtToInstallOverride; @@ -545,7 +541,7 @@ AeInstallTables ( /****************************************************************************** * - * FUNCTION: AeLocalGetRootPointer + * FUNCTION: AcpiOsGetRootPointer * * PARAMETERS: Flags - not used * Address - Where the root pointer is returned @@ -558,7 +554,7 @@ AeInstallTables ( *****************************************************************************/ ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( +AcpiOsGetRootPointer ( void) { diff --git a/sys/contrib/dev/acpica/source/tools/acpihelp/ahmain.c b/sys/contrib/dev/acpica/source/tools/acpihelp/ahmain.c index a340598028..9be1f3b830 100644 --- a/sys/contrib/dev/acpica/source/tools/acpihelp/ahmain.c +++ b/sys/contrib/dev/acpica/source/tools/acpihelp/ahmain.c @@ -71,26 +71,26 @@ AhDisplayUsage ( ACPI_OPTION ("-h", "Display help"); ACPI_OPTION ("-v", "Display version information"); - printf ("\nAML (ACPI Machine Language) Names and Encodings:\n"); + ACPI_USAGE_TEXT ("\nAML (ACPI Machine Language) Names and Encodings:\n"); ACPI_OPTION ("-a [Name/Prefix]", "Find/Display both ASL operator and AML opcode name(s)"); ACPI_OPTION ("-m [Name/Prefix]", "Find/Display AML opcode name(s)"); - printf ("\nASL (ACPI Source Language) Names and Symbols:\n"); + ACPI_USAGE_TEXT ("\nASL (ACPI Source Language) Names and Symbols:\n"); ACPI_OPTION ("-k [Name/Prefix]", "Find/Display ASL non-operator keyword(s)"); ACPI_OPTION ("-p [Name/Prefix]", "Find/Display ASL predefined method name(s)"); ACPI_OPTION ("-s [Name/Prefix]", "Find/Display ASL operator name(s)"); - printf ("\nOther ACPI Names:\n"); + ACPI_USAGE_TEXT ("\nOther ACPI Names:\n"); ACPI_OPTION ("-i [Name/Prefix]", "Find/Display ACPI/PNP Hardware ID(s)"); - printf ("\nACPI Values:\n"); + ACPI_USAGE_TEXT ("\nACPI Values:\n"); ACPI_OPTION ("-e [HexValue]", "Decode ACPICA exception code"); ACPI_OPTION ("-o [HexValue]", "Decode hex AML opcode"); - printf ("\nName/Prefix or HexValue not specified means \"Display All\"\n"); - printf ("\nDefault search with valid Name/Prefix and no options:\n"); - printf (" Find ASL/AML operator names - if NamePrefix does not start with underscore\n"); - printf (" Find ASL predefined method names - if NamePrefix starts with underscore\n"); + ACPI_USAGE_TEXT ("\nName/Prefix or HexValue not specified means \"Display All\"\n"); + ACPI_USAGE_TEXT ("\nDefault search with valid Name/Prefix and no options:\n"); + ACPI_USAGE_TEXT (" Find ASL/AML operator names - if NamePrefix does not start with underscore\n"); + ACPI_USAGE_TEXT (" Find ASL predefined method names - if NamePrefix starts with underscore\n"); } @@ -112,6 +112,7 @@ main ( int j; + AcpiOsInitialize (); ACPI_DEBUG_INITIALIZE (); /* For debug version only */ printf (ACPI_COMMON_SIGNON (AH_UTILITY_NAME)); DecodeType = AH_DECODE_DEFAULT; @@ -124,7 +125,7 @@ main ( /* Command line options */ - while ((j = AcpiGetopt (argc, argv, AH_SUPPORTED_OPTIONS)) != EOF) switch (j) + while ((j = AcpiGetopt (argc, argv, AH_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j) { case 'a': diff --git a/sys/contrib/dev/acpica/source/tools/acpinames/anmain.c b/sys/contrib/dev/acpica/source/tools/acpinames/anmain.c index e65e6e9e48..a7ea9a9d5d 100644 --- a/sys/contrib/dev/acpica/source/tools/acpinames/anmain.c +++ b/sys/contrib/dev/acpica/source/tools/acpinames/anmain.c @@ -105,7 +105,7 @@ NsDumpEntireNamespace ( /* Open the binary AML file and read the entire table */ - Status = AcpiDbReadTableFromFile (AmlFilename, &Table); + Status = AcpiUtReadTableFromFile (AmlFilename, &Table); if (ACPI_FAILURE (Status)) { printf ("**** Could not get input table %s, %s\n", AmlFilename, @@ -241,25 +241,29 @@ main ( ACPI_DEBUG_INITIALIZE (); /* For debug version only */ - printf (ACPI_COMMON_SIGNON (AN_UTILITY_NAME)); - if (argc < 2) - { - usage (); - return (0); - } - - /* Init globals and ACPICA */ + /* Init debug globals and ACPICA */ - AcpiDbgLevel = ACPI_NORMAL_DEFAULT | ACPI_LV_TABLES; + AcpiDbgLevel = ACPI_LV_TABLES; AcpiDbgLayer = 0xFFFFFFFF; Status = AcpiInitializeSubsystem (); AE_CHECK_OK (AcpiInitializeSubsystem, Status); + if (ACPI_FAILURE (Status)) + { + return (-1); + } + + printf (ACPI_COMMON_SIGNON (AN_UTILITY_NAME)); + if (argc < 2) + { + usage (); + return (0); + } /* Get the command line options */ - while ((j = AcpiGetopt (argc, argv, AN_SUPPORTED_OPTIONS)) != EOF) switch(j) + while ((j = AcpiGetopt (argc, argv, AN_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch(j) { case 'v': /* -v: (Version): signon already emitted, just exit */ diff --git a/sys/contrib/dev/acpica/source/tools/acpinames/anstubs.c b/sys/contrib/dev/acpica/source/tools/acpinames/anstubs.c index dedc40fd2f..5933be331a 100644 --- a/sys/contrib/dev/acpica/source/tools/acpinames/anstubs.c +++ b/sys/contrib/dev/acpica/source/tools/acpinames/anstubs.c @@ -60,71 +60,6 @@ /* Utilities */ -void -AcpiUtSubsystemShutdown ( - void) -{ -} - -ACPI_STATUS -AcpiUtExecute_STA ( - ACPI_NAMESPACE_NODE *DeviceNode, - UINT32 *StatusFlags) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtExecute_HID ( - ACPI_NAMESPACE_NODE *DeviceNode, - ACPI_PNP_DEVICE_ID **ReturnId) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtExecute_CID ( - ACPI_NAMESPACE_NODE *DeviceNode, - ACPI_PNP_DEVICE_ID_LIST **ReturnCidList) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtExecute_UID ( - ACPI_NAMESPACE_NODE *DeviceNode, - ACPI_PNP_DEVICE_ID **ReturnId) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtExecute_SUB ( - ACPI_NAMESPACE_NODE *DeviceNode, - ACPI_PNP_DEVICE_ID **ReturnId) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtExecutePowerMethods ( - ACPI_NAMESPACE_NODE *DeviceNode, - const char **MethodNames, - UINT8 MethodCount, - UINT8 *OutValues) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtEvaluateNumericObject ( - char *ObjectName, - ACPI_NAMESPACE_NODE *DeviceNode, - UINT64 *Value) -{ - return (AE_NOT_IMPLEMENTED); -} - ACPI_STATUS AcpiUtCopyIobjectToEobject ( ACPI_OPERAND_OBJECT *Obj, @@ -151,32 +86,8 @@ AcpiUtCopyIobjectToIobject ( } -/* Hardware manager */ - -UINT32 -AcpiHwGetMode ( - void) -{ - return (0); -} - - /* Event manager */ -ACPI_STATUS -AcpiEvInstallXruptHandlers ( - void) -{ - return (AE_OK); -} - -ACPI_STATUS -AcpiEvInitializeEvents ( - void) -{ - return (AE_OK); -} - ACPI_STATUS AcpiEvInstallRegionHandlers ( void) @@ -199,37 +110,9 @@ AcpiEvInitializeRegion ( return (AE_OK); } -#if (!ACPI_REDUCED_HARDWARE) -ACPI_STATUS -AcpiEvDeleteGpeBlock ( - ACPI_GPE_BLOCK_INFO *GpeBlock) -{ - return (AE_OK); -} - -ACPI_STATUS -AcpiEnable ( - void) -{ - return (AE_OK); -} -#endif /* !ACPI_REDUCED_HARDWARE */ - /* AML Interpreter */ -void -AcpiExUnlinkMutex ( - ACPI_OPERAND_OBJECT *ObjDesc) -{ -} - -void -AcpiExReleaseAllMutexes ( - ACPI_THREAD_STATE *Thread) -{ -} - ACPI_STATUS AcpiExReadDataFromField ( ACPI_WALK_STATE *WalkState, @@ -255,22 +138,6 @@ AcpiExPrepFieldValue ( return (AE_OK); } -ACPI_STATUS -AcpiExAcquireMutexObject ( - UINT16 Timeout, - ACPI_OPERAND_OBJECT *ObjDesc, - ACPI_THREAD_ID ThreadId) -{ - return (AE_OK); -} - -ACPI_STATUS -AcpiExReleaseMutexObject ( - ACPI_OPERAND_OBJECT *ObjDesc) -{ - return (AE_OK); -} - ACPI_STATUS AcpiExStoreObjectToNode ( ACPI_OPERAND_OBJECT *SourceDesc, @@ -406,44 +273,3 @@ AcpiDsExecEndOp ( { return (AE_NOT_IMPLEMENTED); } - - -/* AML Debugger */ - -void -AcpiDbDisplayArgumentObject ( - ACPI_OPERAND_OBJECT *ObjDesc, - ACPI_WALK_STATE *WalkState) -{ -} - -ACPI_STATUS -AcpiDbInitialize ( - void) -{ - return (AE_OK); -} - -void -AcpiDbTerminate ( - void) -{ -} - -/* OSL interfaces */ - -ACPI_THREAD_ID -AcpiOsGetThreadId ( - void) -{ - return (0xFFFF); -} - -ACPI_STATUS -AcpiOsExecute ( - ACPI_EXECUTE_TYPE Type, - ACPI_OSD_EXEC_CALLBACK Function, - void *Context) -{ - return (AE_SUPPORT); -} diff --git a/sys/contrib/dev/acpica/source/tools/acpinames/antables.c b/sys/contrib/dev/acpica/source/tools/acpinames/antables.c index 8ad3c5c3dc..b91b425218 100644 --- a/sys/contrib/dev/acpica/source/tools/acpinames/antables.c +++ b/sys/contrib/dev/acpica/source/tools/acpinames/antables.c @@ -48,10 +48,6 @@ /* Local prototypes */ -ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( - void); - /* Non-AML tables that are constructed locally and installed */ static ACPI_TABLE_RSDP LocalRSDP; @@ -284,7 +280,7 @@ AeBuildLocalTables ( /****************************************************************************** * - * FUNCTION: AeLocalGetRootPointer + * FUNCTION: AcpiOsGetRootPointer * * PARAMETERS: None * @@ -296,7 +292,7 @@ AeBuildLocalTables ( *****************************************************************************/ ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( +AcpiOsGetRootPointer ( void) { diff --git a/sys/contrib/dev/acpica/source/tools/acpisrc/asmain.c b/sys/contrib/dev/acpica/source/tools/acpisrc/asmain.c index 8c75769c51..8b26ebcfcf 100644 --- a/sys/contrib/dev/acpica/source/tools/acpisrc/asmain.c +++ b/sys/contrib/dev/acpica/source/tools/acpisrc/asmain.c @@ -297,7 +297,7 @@ AsDisplayUsage ( ACPI_OPTION ("-l", "Generate Linux version of the source"); ACPI_OPTION ("-u", "Generate Custom source translation"); - printf ("\n"); + ACPI_USAGE_TEXT ("\n"); ACPI_OPTION ("-d", "Leave debug statements in code"); ACPI_OPTION ("-s", "Generate source statistics only"); ACPI_OPTION ("-v", "Display version information"); @@ -327,6 +327,7 @@ main ( ACPI_DEBUG_INITIALIZE (); /* For debug version only */ + AcpiOsInitialize (); printf (ACPI_COMMON_SIGNON (AS_UTILITY_NAME)); if (argc < 2) @@ -337,7 +338,7 @@ main ( /* Command line options */ - while ((j = AcpiGetopt (argc, argv, AS_SUPPORTED_OPTIONS)) != EOF) switch(j) + while ((j = AcpiGetopt (argc, argv, AS_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch(j) { case 'l': diff --git a/sys/contrib/dev/acpica/source/tools/acpisrc/astable.c b/sys/contrib/dev/acpica/source/tools/acpisrc/astable.c index 9e127a4942..7f25988b10 100644 --- a/sys/contrib/dev/acpica/source/tools/acpisrc/astable.c +++ b/sys/contrib/dev/acpica/source/tools/acpisrc/astable.c @@ -253,6 +253,9 @@ ACPI_TYPED_IDENTIFIER_TABLE AcpiIdentifiers[] = { {"ACPI_INTERPRETER_MODE", SRC_TYPE_SIMPLE}, {"ACPI_IO_ADDRESS", SRC_TYPE_SIMPLE}, {"ACPI_IO_ATTRIBUTE", SRC_TYPE_STRUCT}, + {"ACPI_LPIT_HEADER", SRC_TYPE_STRUCT}, + {"ACPI_LPIT_IO", SRC_TYPE_STRUCT}, + {"ACPI_LPIT_NATIVE", SRC_TYPE_STRUCT}, {"ACPI_MEM_SPACE_CONTEXT", SRC_TYPE_STRUCT}, {"ACPI_MEMORY_ATTRIBUTE", SRC_TYPE_STRUCT}, {"ACPI_MEMORY_LIST", SRC_TYPE_STRUCT}, @@ -400,6 +403,7 @@ ACPI_TYPED_IDENTIFIER_TABLE AcpiIdentifiers[] = { {"ACPI_TABLE_HEADER", SRC_TYPE_STRUCT}, {"ACPI_TABLE_INFO", SRC_TYPE_STRUCT}, {"ACPI_TABLE_LIST", SRC_TYPE_STRUCT}, + {"ACPI_TABLE_LPIT", SRC_TYPE_STRUCT}, {"ACPI_TABLE_MTMR", SRC_TYPE_STRUCT}, {"ACPI_TABLE_SUPPORT", SRC_TYPE_STRUCT}, {"ACPI_TABLE_TYPE", SRC_TYPE_SIMPLE}, @@ -720,8 +724,10 @@ ACPI_STRING_TABLE LinuxSpecialStrings[] = { {"\"actbl3.h\"", "", REPLACE_WHOLE_WORD}, {"\"actypes.h\"", "", REPLACE_WHOLE_WORD}, {"\"platform/acenv.h\"", "", REPLACE_WHOLE_WORD}, + {"\"platform/acenvex.h\"", "", REPLACE_WHOLE_WORD}, {"\"acgcc.h\"", "", REPLACE_WHOLE_WORD}, {"\"aclinux.h\"", "", REPLACE_WHOLE_WORD}, + {"\"aclinuxex.h\"", "", REPLACE_WHOLE_WORD}, {NULL, NULL, 0} }; diff --git a/sys/contrib/dev/acpica/source/tools/acpixtract/axmain.c b/sys/contrib/dev/acpica/source/tools/acpixtract/axmain.c index b1bdb8b6c4..ec0bd61f7b 100644 --- a/sys/contrib/dev/acpica/source/tools/acpixtract/axmain.c +++ b/sys/contrib/dev/acpica/source/tools/acpixtract/axmain.c @@ -98,8 +98,8 @@ DisplayUsage ( ACPI_OPTION ("-s ", "Extract all tables with "); ACPI_OPTION ("-v", "Display version information"); - printf ("\nExtract binary ACPI tables from text acpidump output\n"); - printf ("Default invocation extracts the DSDT and all SSDTs\n"); + ACPI_USAGE_TEXT ("\nExtract binary ACPI tables from text acpidump output\n"); + ACPI_USAGE_TEXT ("Default invocation extracts the DSDT and all SSDTs\n"); } @@ -122,6 +122,7 @@ main ( ACPI_DEBUG_INITIALIZE (); /* For debug version only */ + AcpiOsInitialize (); printf (ACPI_COMMON_SIGNON (AX_UTILITY_NAME)); if (argc < 2) @@ -132,7 +133,7 @@ main ( /* Command line options */ - while ((j = AcpiGetopt (argc, argv, AX_SUPPORTED_OPTIONS)) != EOF) switch (j) + while ((j = AcpiGetopt (argc, argv, AX_SUPPORTED_OPTIONS)) != ACPI_OPT_END) switch (j) { case 'a': diff --git a/sys/contrib/dev/acpica/source/tools/examples/examples.c b/sys/contrib/dev/acpica/source/tools/examples/examples.c index 8de3a0565e..762118a133 100644 --- a/sys/contrib/dev/acpica/source/tools/examples/examples.c +++ b/sys/contrib/dev/acpica/source/tools/examples/examples.c @@ -86,6 +86,22 @@ NotifyHandler ( UINT32 Value, void *Context); +static ACPI_STATUS +RegionHandler ( + UINT32 Function, + ACPI_PHYSICAL_ADDRESS Address, + UINT32 BitWidth, + UINT64 *Value, + void *HandlerContext, + void *RegionContext); + +static ACPI_STATUS +RegionInit ( + ACPI_HANDLE RegionHandle, + UINT32 Function, + void *HandlerContext, + void **RegionContext); + static void ExecuteMAIN (void); @@ -335,6 +351,43 @@ NotifyHandler ( } +static ACPI_STATUS +RegionInit ( + ACPI_HANDLE RegionHandle, + UINT32 Function, + void *HandlerContext, + void **RegionContext) +{ + + if (Function == ACPI_REGION_DEACTIVATE) + { + *RegionContext = NULL; + } + else + { + *RegionContext = RegionHandle; + } + + return (AE_OK); +} + + +static ACPI_STATUS +RegionHandler ( + UINT32 Function, + ACPI_PHYSICAL_ADDRESS Address, + UINT32 BitWidth, + UINT64 *Value, + void *HandlerContext, + void *RegionContext) +{ + + ACPI_INFO ((AE_INFO, "Received a region access")); + + return (AE_OK); +} + + static ACPI_STATUS InstallHandlers (void) { @@ -351,6 +404,14 @@ InstallHandlers (void) return (Status); } + Status = AcpiInstallAddressSpaceHandler (ACPI_ROOT_OBJECT, ACPI_ADR_SPACE_SYSTEM_MEMORY, + RegionHandler, RegionInit, NULL); + if (ACPI_FAILURE (Status)) + { + ACPI_EXCEPTION ((AE_INFO, Status, "While installing an OpRegion handler")); + return (Status); + } + return (AE_OK); } diff --git a/sys/contrib/dev/acpica/source/tools/examples/exstubs.c b/sys/contrib/dev/acpica/source/tools/examples/exstubs.c index df2ca25984..9d5b25bf93 100644 --- a/sys/contrib/dev/acpica/source/tools/examples/exstubs.c +++ b/sys/contrib/dev/acpica/source/tools/examples/exstubs.c @@ -58,91 +58,8 @@ *****************************************************************************/ -/* Utilities */ - -void -AcpiUtSubsystemShutdown ( - void) -{ -} - -ACPI_STATUS -AcpiUtExecute_STA ( - ACPI_NAMESPACE_NODE *DeviceNode, - UINT32 *StatusFlags) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtExecute_HID ( - ACPI_NAMESPACE_NODE *DeviceNode, - ACPI_PNP_DEVICE_ID **ReturnId) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtExecute_CID ( - ACPI_NAMESPACE_NODE *DeviceNode, - ACPI_PNP_DEVICE_ID_LIST **ReturnCidList) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtExecute_UID ( - ACPI_NAMESPACE_NODE *DeviceNode, - ACPI_PNP_DEVICE_ID **ReturnId) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtExecute_SUB ( - ACPI_NAMESPACE_NODE *DeviceNode, - ACPI_PNP_DEVICE_ID **ReturnId) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtExecutePowerMethods ( - ACPI_NAMESPACE_NODE *DeviceNode, - const char **MethodNames, - UINT8 MethodCount, - UINT8 *OutValues) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtEvaluateNumericObject ( - char *ObjectName, - ACPI_NAMESPACE_NODE *DeviceNode, - UINT64 *Value) -{ - return (AE_NOT_IMPLEMENTED); -} - -ACPI_STATUS -AcpiUtGetResourceEndTag ( - ACPI_OPERAND_OBJECT *ObjDesc, - UINT8 **EndTag) -{ - return (AE_OK); -} - - /* Hardware manager */ -UINT32 -AcpiHwGetMode ( - void) -{ - return (0); -} - ACPI_STATUS AcpiHwReadPort ( ACPI_IO_ADDRESS Address, @@ -164,176 +81,9 @@ AcpiHwWritePort ( /* Event manager */ -ACPI_STATUS -AcpiInstallNotifyHandler ( - ACPI_HANDLE Device, - UINT32 HandlerType, - ACPI_NOTIFY_HANDLER Handler, - void *Context) -{ - return (AE_OK); -} - -ACPI_STATUS -AcpiEvInstallXruptHandlers ( - void) -{ - return (AE_OK); -} - ACPI_STATUS AcpiEvInitializeEvents ( void) { return (AE_OK); } - -ACPI_STATUS -AcpiEvInstallRegionHandlers ( - void) -{ - return (AE_OK); -} - -ACPI_STATUS -AcpiEvInitializeOpRegions ( - void) -{ - return (AE_OK); -} - -ACPI_STATUS -AcpiEvInitializeRegion ( - ACPI_OPERAND_OBJECT *RegionObj, - BOOLEAN AcpiNsLocked) -{ - return (AE_OK); -} - -#if (!ACPI_REDUCED_HARDWARE) -ACPI_STATUS -AcpiEvDeleteGpeBlock ( - ACPI_GPE_BLOCK_INFO *GpeBlock) -{ - return (AE_OK); -} - -ACPI_STATUS -AcpiEnable ( - void) -{ - return (AE_OK); -} -#endif /* !ACPI_REDUCED_HARDWARE */ - -void -AcpiEvUpdateGpes ( - ACPI_OWNER_ID TableOwnerId) -{ -} - -ACPI_STATUS -AcpiEvAddressSpaceDispatch ( - ACPI_OPERAND_OBJECT *RegionObj, - ACPI_OPERAND_OBJECT *FieldObj, - UINT32 Function, - UINT32 RegionOffset, - UINT32 BitWidth, - UINT64 *Value) -{ - return (AE_OK); -} - -ACPI_STATUS -AcpiEvAcquireGlobalLock ( - UINT16 Timeout) -{ - return (AE_OK); -} - -ACPI_STATUS -AcpiEvReleaseGlobalLock ( - void) -{ - return (AE_OK); -} - -ACPI_STATUS -AcpiEvQueueNotifyRequest ( - ACPI_NAMESPACE_NODE *Node, - UINT32 NotifyValue) -{ - return (AE_OK); -} - -BOOLEAN -AcpiEvIsNotifyObject ( - ACPI_NAMESPACE_NODE *Node) -{ - return (TRUE); -} - - -/* Namespace manager */ - -ACPI_STATUS -AcpiNsCheckReturnValue ( - ACPI_NAMESPACE_NODE *Node, - ACPI_EVALUATE_INFO *Info, - UINT32 UserParamCount, - ACPI_STATUS ReturnStatus, - ACPI_OPERAND_OBJECT **ReturnObjectPtr) -{ - return (AE_OK); -} - -void -AcpiNsCheckArgumentTypes ( - ACPI_EVALUATE_INFO *Info) -{ - return; -} - -void -AcpiNsCheckArgumentCount ( - char *Pathname, - ACPI_NAMESPACE_NODE *Node, - UINT32 UserParamCount, - const ACPI_PREDEFINED_INFO *Predefined) -{ - return; -} - -void -AcpiNsCheckAcpiCompliance ( - char *Pathname, - ACPI_NAMESPACE_NODE *Node, - const ACPI_PREDEFINED_INFO *Predefined) -{ - return; -} - -const ACPI_PREDEFINED_INFO * -AcpiUtMatchPredefinedMethod ( - char *Name) -{ - return (NULL); -} - -/* OSL interfaces */ - -ACPI_THREAD_ID -AcpiOsGetThreadId ( - void) -{ - return (1); -} - -ACPI_STATUS -AcpiOsExecute ( - ACPI_EXECUTE_TYPE Type, - ACPI_OSD_EXEC_CALLBACK Function, - void *Context) -{ - return (AE_SUPPORT); -} diff --git a/sys/contrib/dev/acpica/source/tools/examples/extables.c b/sys/contrib/dev/acpica/source/tools/examples/extables.c index c33be9574c..aa5fc1fea8 100644 --- a/sys/contrib/dev/acpica/source/tools/examples/extables.c +++ b/sys/contrib/dev/acpica/source/tools/examples/extables.c @@ -49,10 +49,6 @@ #define _COMPONENT ACPI_EXAMPLE ACPI_MODULE_NAME ("extables") -ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( - void); - /****************************************************************************** * @@ -148,19 +144,24 @@ static unsigned char FacsCode[] = static unsigned char DsdtCode[] = { - 0x44,0x53,0x44,0x54,0x67,0x00,0x00,0x00, /* 00000000 "DSDTg..." */ - 0x02,0x97,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 "..Intel." */ + 0x44,0x53,0x44,0x54,0x8C,0x00,0x00,0x00, /* 00000000 "DSDT...." */ + 0x02,0x76,0x49,0x6E,0x74,0x65,0x6C,0x00, /* 00000008 ".vIntel." */ 0x54,0x65,0x6D,0x70,0x6C,0x61,0x74,0x65, /* 00000010 "Template" */ 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ - 0x15,0x11,0x13,0x20,0x14,0x42,0x04,0x4D, /* 00000020 "... .B.M" */ - 0x41,0x49,0x4E,0x01,0x70,0x73,0x0D,0x4D, /* 00000028 "AIN.ps.M" */ - 0x61,0x69,0x6E,0x2F,0x41,0x72,0x67,0x30, /* 00000030 "ain/Arg0" */ - 0x3A,0x20,0x00,0x68,0x00,0x5B,0x31,0xA4, /* 00000038 ": .h.[1." */ - 0x0D,0x4D,0x61,0x69,0x6E,0x20,0x73,0x75, /* 00000040 ".Main su" */ - 0x63,0x63,0x65,0x73,0x73,0x66,0x75,0x6C, /* 00000048 "ccessful" */ - 0x6C,0x79,0x20,0x63,0x6F,0x6D,0x70,0x6C, /* 00000050 "ly compl" */ - 0x65,0x74,0x65,0x64,0x20,0x65,0x78,0x65, /* 00000058 "eted exe" */ - 0x63,0x75,0x74,0x69,0x6F,0x6E,0x00 /* 00000060 "cution." */ + 0x24,0x04,0x14,0x20,0x5B,0x80,0x47,0x4E, /* 00000020 "$.. [.GN" */ + 0x56,0x53,0x00,0x0C,0x98,0xEE,0xBB,0xDF, /* 00000028 "VS......" */ + 0x0A,0x13,0x5B,0x81,0x0B,0x47,0x4E,0x56, /* 00000030 "..[..GNV" */ + 0x53,0x00,0x46,0x4C,0x44,0x31,0x08,0x14, /* 00000038 "S.FLD1.." */ + 0x4C,0x04,0x4D,0x41,0x49,0x4E,0x01,0x70, /* 00000040 "L.MAIN.p" */ + 0x73,0x0D,0x4D,0x61,0x69,0x6E,0x2F,0x41, /* 00000048 "s.Main/A" */ + 0x72,0x67,0x30,0x3A,0x20,0x00,0x68,0x00, /* 00000050 "rg0: .h." */ + 0x5B,0x31,0x70,0x00,0x46,0x4C,0x44,0x31, /* 00000058 "[1p.FLD1" */ + 0x86,0x5C,0x00,0x00,0xA4,0x0D,0x4D,0x61, /* 00000060 ".\....Ma" */ + 0x69,0x6E,0x20,0x73,0x75,0x63,0x63,0x65, /* 00000068 "in succe" */ + 0x73,0x73,0x66,0x75,0x6C,0x6C,0x79,0x20, /* 00000070 "ssfully " */ + 0x63,0x6F,0x6D,0x70,0x6C,0x65,0x74,0x65, /* 00000078 "complete" */ + 0x64,0x20,0x65,0x78,0x65,0x63,0x75,0x74, /* 00000080 "d execut" */ + 0x69,0x6F,0x6E,0x00 /* 00000088 "ion." */ }; @@ -232,7 +233,7 @@ ExInitializeAcpiTables ( *****************************************************************************/ ACPI_PHYSICAL_ADDRESS -AeLocalGetRootPointer ( +AcpiOsGetRootPointer ( void) { @@ -475,9 +476,17 @@ AeLocalGetRootPointer ( DefinitionBlock ("dsdt.aml", "DSDT", 2, "Intel", "Template", 0x00000001) { + OperationRegion (GNVS, SystemMemory, 0xDFBBEE98, 0x00000013) + Field (GNVS, AnyAcc, NoLock, Preserve) + { + FLD1, 8, + } + Method (MAIN, 1, NotSerialized) { Store (Concatenate ("Main/Arg0: ", Arg0), Debug) + Store (Zero, FLD1) + Notify (\, Zero) Return ("Main successfully completed execution") } } diff --git a/usr.sbin/acpi/acpibin/Makefile b/usr.sbin/acpi/acpibin/Makefile index 45bafcb182..ff609cd18e 100644 --- a/usr.sbin/acpi/acpibin/Makefile +++ b/usr.sbin/acpi/acpibin/Makefile @@ -19,6 +19,7 @@ SRCS+= \ utalloc.c \ utbuffer.c \ utcache.c \ + utdebug.c \ utdecode.c \ utexcep.c \ utglobal.c \ @@ -26,9 +27,11 @@ SRCS+= \ utmath.c \ utmisc.c \ utmutex.c \ + utprint.c \ utstate.c \ utstring.c \ utxferror.c \ + oslibcfs.c \ osunixxf.c CFLAGS+= \ diff --git a/usr.sbin/acpi/acpidump/Makefile b/usr.sbin/acpi/acpidump/Makefile index edd3dd0e62..f1a75f4927 100644 --- a/usr.sbin/acpi/acpidump/Makefile +++ b/usr.sbin/acpi/acpidump/Makefile @@ -17,13 +17,18 @@ SRCS= \ SRCS+= \ cmfsize.c \ getopt.c \ + oslibcfs.c \ osunixdir.c \ osunixmap.c \ + osunixxf.c \ tbprint.c \ tbxfroot.c \ utbuffer.c \ + utdebug.c \ utexcep.c \ + utglobal.c \ utmath.c \ + utprint.c \ utstring.c \ utxferror.c diff --git a/usr.sbin/acpi/acpiexec/Makefile b/usr.sbin/acpi/acpiexec/Makefile index 95df0d306e..04babaa5e9 100644 --- a/usr.sbin/acpi/acpiexec/Makefile +++ b/usr.sbin/acpi/acpiexec/Makefile @@ -130,6 +130,7 @@ SRCS+= \ nsxfeval.c \ nsxfname.c \ nsxfobj.c \ + oslibcfs.c \ osunixxf.c \ psargs.c \ psloop.c \ @@ -176,6 +177,7 @@ SRCS+= \ uterror.c \ uteval.c \ utexcep.c \ + utfileio.o \ utglobal.c \ utids.c \ utinit.c \ @@ -187,6 +189,7 @@ SRCS+= \ utosi.c \ utownerid.c \ utpredef.c \ + utprint.c \ utresrc.c \ utstate.c \ utstring.c \ diff --git a/usr.sbin/acpi/acpihelp/Makefile b/usr.sbin/acpi/acpihelp/Makefile index 176a6d5ac9..2a82866e07 100644 --- a/usr.sbin/acpi/acpihelp/Makefile +++ b/usr.sbin/acpi/acpihelp/Makefile @@ -21,8 +21,14 @@ SRCS= \ SRCS+= \ getopt.c \ + oslibcfs.c \ + osunixxf.c \ + utdebug.c \ utexcep.c \ - utpredef.c + utglobal.c \ + utmath.c \ + utpredef.c \ + utprint.c CFLAGS+= \ -DACPI_HELP_APP \ diff --git a/usr.sbin/acpi/acpinames/Makefile b/usr.sbin/acpi/acpinames/Makefile index c5767652e8..bebc743f42 100644 --- a/usr.sbin/acpi/acpinames/Makefile +++ b/usr.sbin/acpi/acpinames/Makefile @@ -18,7 +18,6 @@ SRCS= \ SRCS+= \ cmfsize.c \ - dbfileio.c \ dsfield.c \ dsmthdat.c \ dsobject.c \ @@ -28,9 +27,12 @@ SRCS+= \ dswscope.c \ dswstate.c \ excreate.c \ + exdump.c \ + exmutex.c \ exnames.c \ exresnte.c \ exresolv.c \ + exsystem.c \ exutils.c \ getopt.c \ nsaccess.c \ @@ -47,6 +49,7 @@ SRCS+= \ nsxfeval.c \ nsxfname.c \ nsxfobj.c \ + oslibcfs.c \ osunixxf.c \ psargs.c \ psloop.c \ @@ -70,13 +73,18 @@ SRCS+= \ tbxfroot.c \ utaddress.c \ utalloc.c \ + utbuffer.c \ utcache.c \ utdebug.c \ utdecode.c \ utdelete.c \ uterror.c \ + uteval.c \ utexcep.c \ + utfileio.c \ utglobal.c \ + utids.c \ + utinit.c \ utlock.c \ utmath.c \ utmisc.c \ @@ -84,6 +92,7 @@ SRCS+= \ utobject.c \ utosi.c \ utownerid.c \ + utprint.c \ utstate.c \ utstring.c \ utxface.c \ diff --git a/usr.sbin/acpi/acpixtract/Makefile b/usr.sbin/acpi/acpixtract/Makefile index 59cb563ad4..f61df0a152 100644 --- a/usr.sbin/acpi/acpixtract/Makefile +++ b/usr.sbin/acpi/acpixtract/Makefile @@ -14,7 +14,15 @@ SRCS= \ axmain.c SRCS+= \ - getopt.c + getopt.c \ + oslibcfs.c \ + osunixxf.c \ + utdebug.c \ + utexcep.c \ + utglobal.c \ + utmath.c \ + utprint.c \ + utxferror.c CFLAGS+= \ -DACPI_XTRACT_APP \ diff --git a/usr.sbin/acpi/iasl/Makefile b/usr.sbin/acpi/iasl/Makefile index 4ad781ac21..c1db27c1ac 100644 --- a/usr.sbin/acpi/iasl/Makefile +++ b/usr.sbin/acpi/iasl/Makefile @@ -136,6 +136,7 @@ SRCS= \ nswalk.c \ nsxfobj.c \ osunixxf.c \ + oslibcfs.c \ prexpress.c \ prmacros.c \ prscan.c \ @@ -166,6 +167,7 @@ SRCS= \ utdelete.c \ uterror.c \ utexcep.c \ + utfileio.c \ utglobal.c \ utinit.c \ utlock.c \ @@ -175,6 +177,7 @@ SRCS= \ utobject.c \ utownerid.c \ utpredef.c \ + utprint.c \ utresrc.c \ utstate.c \ utstring.c \ -- 2.41.0 From 735dae5b1c0a1eaa2744b6564bbe3aff02a12166 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 28 Jun 2014 13:43:04 +0200 Subject: [PATCH 05/16] acpi: Sync aapits Makefile with 20140627 ACPICA test suite. --- usr.sbin/acpi/aapits/Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/usr.sbin/acpi/aapits/Makefile b/usr.sbin/acpi/aapits/Makefile index 8f50f5347c..26cc6c41e0 100644 --- a/usr.sbin/acpi/aapits/Makefile +++ b/usr.sbin/acpi/aapits/Makefile @@ -23,12 +23,12 @@ SRCS= \ SRCS+= \ osunixxf.c \ + ahids.c \ + cmfsize.c \ + getopt.c \ hwtimer.c \ hwvalid.c \ hwxface.c \ - cmfsize.c \ - getopt.c \ - ahids.c \ dbcmds.c \ dbconvert.c \ dbdisply.c \ @@ -180,6 +180,7 @@ SRCS+= \ uterror.c \ uteval.c \ utexcep.c \ + utfileio.c \ utglobal.c \ utids.c \ utinit.c \ @@ -191,16 +192,19 @@ SRCS+= \ utosi.c \ utownerid.c \ utpredef.c \ + utprint.c \ utresrc.c \ utstate.c \ utstring.c \ uttrack.c \ utxface.c \ utxferror.c \ - utxfinit.c -# ../../source/components/osunixxf.c + utxfinit.c \ + oslibcfs.c +# osunixxf.c CFLAGS+= \ + -DACPI_APITS \ -DACPI_EXEC_APP \ -D__cdecl= -- 2.41.0 From 9c897caef7e3efb556775c0098f38399a5aa7aff Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 28 Jun 2014 13:58:48 +0200 Subject: [PATCH 06/16] kernel/acpi_thinkpad: Unlock properly before returning. --- sys/dev/acpica/acpi_thinkpad/acpi_thinkpad.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sys/dev/acpica/acpi_thinkpad/acpi_thinkpad.c b/sys/dev/acpica/acpi_thinkpad/acpi_thinkpad.c index 61fc9115ec..731f40985b 100644 --- a/sys/dev/acpica/acpi_thinkpad/acpi_thinkpad.c +++ b/sys/dev/acpica/acpi_thinkpad/acpi_thinkpad.c @@ -1220,7 +1220,7 @@ acpi_thinkpad_eventhandler(struct acpi_thinkpad_softc *sc, int arg) status = ACPI_EC_READ(sc->ec_dev, THINKPAD_EC_BRIGHTNESS, &val_ec, 1); if (ACPI_FAILURE(status)) - return; + goto done; val = val_ec & THINKPAD_EC_MASK_BRI; val = (arg == THINKPAD_EVENT_BRIGHTNESS_UP) ? val + 1 : val - 1; @@ -1236,7 +1236,7 @@ acpi_thinkpad_eventhandler(struct acpi_thinkpad_softc *sc, int arg) /* Read the current volume */ status = ACPI_EC_READ(sc->ec_dev, THINKPAD_EC_VOLUME, &val_ec, 1); if (ACPI_FAILURE(status)) - return; + goto done; val = val_ec & THINKPAD_EC_MASK_VOL; val = (arg == THINKPAD_EVENT_VOLUME_UP) ? val + 1 : val - 1; @@ -1247,7 +1247,7 @@ acpi_thinkpad_eventhandler(struct acpi_thinkpad_softc *sc, int arg) /* Read the current value */ status = ACPI_EC_READ(sc->ec_dev, THINKPAD_EC_VOLUME, &val_ec, 1); if (ACPI_FAILURE(status)) - return; + goto done; val = ((val_ec & THINKPAD_EC_MASK_MUTE) == THINKPAD_EC_MASK_MUTE); acpi_thinkpad_mute_set(sc, (val == 0)); @@ -1256,6 +1256,7 @@ acpi_thinkpad_eventhandler(struct acpi_thinkpad_softc *sc, int arg) default: break; } +done: ACPI_SERIAL_END(thinkpad); } -- 2.41.0 From d5a7158eca527110a20ffdf1b1db59be1300a679 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 28 Jun 2014 14:00:58 +0200 Subject: [PATCH 07/16] unlock_return.cocci: Add a check for ACPI_SERIAL_{BEGIN,END}. --- test/cocci/unlock_return.cocci | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/cocci/unlock_return.cocci b/test/cocci/unlock_return.cocci index 45f9495648..ecc380a51c 100644 --- a/test/cocci/unlock_return.cocci +++ b/test/cocci/unlock_return.cocci @@ -22,6 +22,26 @@ // (indefinitely?) on some files. // +// ACPI_SERIAL_BEGIN(...) / ACPI_SERIAL_END(...) +// +@rcu_ACPI_SERIAL_BEGIN exists@ +position p1; +expression E; +@@ + +ACPI_SERIAL_BEGIN@p1(E); +... +ACPI_SERIAL_END(E); + +@exists@ +position rcu_ACPI_SERIAL_BEGIN.p1; +expression E; +@@ + +*ACPI_SERIAL_BEGIN@p1(E); +... when != ACPI_SERIAL_END(E); +?*return ...; + // crit_enter() / crit_exit() // @rcu_crit_enter exists@ -- 2.41.0 From 2a979d810b3ef64e1bbd20c55e113d5e39db5362 Mon Sep 17 00:00:00 2001 From: Imre Vadasz Date: Fri, 27 Jun 2014 21:29:04 +0200 Subject: [PATCH 08/16] vga_pci: Improve vga boot display detection. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Check the "VGA Enable" bit on the parent bridge only if it is a PCI-to-PCI bridge. * Always check the "I/O" and "Memory address space decoding" bits on the video card itself. * Furthermore, vga_pci_attach() logs "Boot video device" if the card being attached is the Chosen One: vgapci0: [...] vgapci0: Boot video device This is FreeBSD's r259579. Tested-by: François Tigeot --- sys/bus/pci/vga_pci.c | 71 ++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/sys/bus/pci/vga_pci.c b/sys/bus/pci/vga_pci.c index facd72abee..eb433cdd70 100644 --- a/sys/bus/pci/vga_pci.c +++ b/sys/bus/pci/vga_pci.c @@ -78,16 +78,58 @@ SYSCTL_INT(_hw_pci, OID_AUTO, default_vgapci_unit, CTLFLAG_RD, int vga_pci_is_boot_display(device_t dev) { + int unit; + device_t pcib; + uint16_t config; + + /* Check that the given device is a video card */ + if ((pci_get_class(dev) != PCIC_DISPLAY && + (pci_get_class(dev) != PCIC_OLD || + pci_get_subclass(dev) != PCIS_OLD_VGA))) + return (0); + + unit = device_get_unit(dev); + + if (vga_pci_default_unit >= 0) { + /* + * The boot display device was determined by a previous + * call to this function, or the user forced it using + * the hw.pci.default_vgapci_unit tunable. + */ + return (vga_pci_default_unit == unit); + } /* - * Return true if the given device is the default display used - * at boot time. + * The primary video card used as a boot display must have the + * "I/O" and "Memory Address Space Decoding" bits set in its + * Command register. + * + * Furthermore, if the card is attached to a bridge, instead of + * the root PCI bus, the bridge must have the "VGA Enable" bit + * set in its Control register. */ - return ( - (pci_get_class(dev) == PCIC_DISPLAY || - (pci_get_class(dev) == PCIC_OLD && - pci_get_subclass(dev) == PCIS_OLD_VGA)) && - device_get_unit(dev) == vga_pci_default_unit); + + pcib = device_get_parent(device_get_parent(dev)); + if (device_get_devclass(device_get_parent(pcib)) == + devclass_find("pci")) { + /* + * The parent bridge is a PCI-to-PCI bridge: check the + * value of the "VGA Enable" bit. + */ + config = pci_read_config(pcib, PCIR_BRIDGECTL_1, 2); + if ((config & PCIB_BCR_VGA_ENABLE) == 0) + return (0); + } + + config = pci_read_config(dev, PCIR_COMMAND, 2); + if ((config & (PCIM_CMD_PORTEN | PCIM_CMD_MEMEN)) == 0) + return (0); + + /* This video card is the boot display: record its unit number. */ + vga_pci_default_unit = unit; + device_set_flags(dev, 1); + + return (1); } void * @@ -152,9 +194,6 @@ vga_pci_unmap_bios(device_t dev, void *bios) static int vga_pci_probe(device_t dev) { - device_t bdev; - int unit; - uint16_t bctl; switch (pci_get_class(dev)) { case PCIC_DISPLAY: @@ -168,13 +207,7 @@ vga_pci_probe(device_t dev) } /* Probe default display. */ - unit = device_get_unit(dev); - bdev = device_get_parent(device_get_parent(dev)); - bctl = pci_read_config(bdev, PCIR_BRIDGECTL_1, 2); - if (vga_pci_default_unit < 0 && (bctl & PCIB_BCR_VGA_ENABLE) != 0) - vga_pci_default_unit = unit; - if (vga_pci_default_unit == unit) - device_set_flags(dev, 1); + vga_pci_is_boot_display(dev); device_set_desc(dev, "VGA-compatible display"); return (BUS_PROBE_GENERIC); @@ -190,6 +223,10 @@ vga_pci_attach(device_t dev) device_add_child(dev, "drm", -1); device_add_child(dev, "drmn", -1); bus_generic_attach(dev); + + if (vga_pci_is_boot_display(dev)) + device_printf(dev, "Boot video device\n"); + return (0); } -- 2.41.0 From a645dd951b68e7c122d067842761d5074352f2be Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 28 Jun 2014 15:24:00 +0200 Subject: [PATCH 09/16] kernel/acpi: Fix a kprintf for ACPI_DEBUG_MEMMAP. --- sys/dev/acpica/Osd/OsdMemory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/dev/acpica/Osd/OsdMemory.c b/sys/dev/acpica/Osd/OsdMemory.c index e475cd7226..c76fa81d71 100644 --- a/sys/dev/acpica/Osd/OsdMemory.c +++ b/sys/dev/acpica/Osd/OsdMemory.c @@ -184,9 +184,9 @@ again: #ifdef ACPI_DEBUG_MEMMAP for (track = acpi_mapbase; track != NULL; track = track->next) { if (track->freed && track->base == LogicalAddress) { - kprintf("%s: unmapping: %p/%0*jx, mapped by %s:%d," + kprintf("%s: unmapping: %p/%08jx, mapped by %s:%d," "last unmapped by %s:%d\n", - __func__, LogicalAddress, sizeof(Length) * 2, (uintmax_t)Length, + __func__, LogicalAddress, (uintmax_t)Length, track->mapper.func, track->mapper.line, track->unmapper.func, track->unmapper.line ); -- 2.41.0 From 510bcfa42f5b3cb934688b3150a1f61dcf5e4b1b Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 28 Jun 2014 15:31:31 +0200 Subject: [PATCH 10/16] kernel/acpi: Solve ACPI_DEBUG_{CACHE,LOCKS,MEMMAP} building better. ACPICA 20140627 added a mechanism for having a platform dependent header that is included _after_ ACPICA headers are included. So we can now solve compilation with ACPI_DEBUG_{CACHE,LOCKS,MEMMAP} by adding a new acdragonflyex.h header for the prototypes of the debug flavors of AcpiOsReleaseObject(), AcpiOsAcquireLock(), AcpiOsMapMemory() and AcpiOsUnmapMemory() instead of having to put them into the vendor code (like I did in 3b92a84dc0def, which this commit reverts). --- .../dev/acpica/source/include/acpiosxf.h | 31 ------------ .../platform/{acenvex.h => acdragonflyex.h} | 49 +++++++++++++------ .../acpica/source/include/platform/acenvex.h | 3 ++ 3 files changed, 38 insertions(+), 45 deletions(-) copy sys/contrib/dev/acpica/source/include/platform/{acenvex.h => acdragonflyex.h} (73%) diff --git a/sys/contrib/dev/acpica/source/include/acpiosxf.h b/sys/contrib/dev/acpica/source/include/acpiosxf.h index a006759451..3888b488e9 100644 --- a/sys/contrib/dev/acpica/source/include/acpiosxf.h +++ b/sys/contrib/dev/acpica/source/include/acpiosxf.h @@ -150,14 +150,6 @@ AcpiOsAcquireLock ( ACPI_SPINLOCK Handle); #endif -#ifdef ACPI_DEBUG_LOCKS -ACPI_CPU_FLAGS -_AcpiOsAcquireLock ( - ACPI_SPINLOCK Handle, - const char *func, - int line); -#endif - #ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReleaseLock void AcpiOsReleaseLock ( @@ -268,21 +260,6 @@ AcpiOsUnmapMemory ( ACPI_SIZE Size); #endif -#ifdef ACPI_DEBUG_MEMMAP -void * -_AcpiOsMapMemory ( - ACPI_PHYSICAL_ADDRESS Where, - ACPI_SIZE Length, - const char *caller, - int line); -void -_AcpiOsUnmapMemory ( - void *LogicalAddress, - ACPI_SIZE Length, - const char *caller, - int line); -#endif - #ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetPhysicalAddress ACPI_STATUS AcpiOsGetPhysicalAddress ( @@ -328,14 +305,6 @@ AcpiOsReleaseObject ( void *Object); #endif -#ifdef ACPI_DEBUG_CACHE -ACPI_STATUS -_AcpiOsReleaseObject ( - ACPI_CACHE_T *Cache, - void *Object, - const char *func, - int line); -#endif /* * Interrupt handlers diff --git a/sys/contrib/dev/acpica/source/include/platform/acenvex.h b/sys/contrib/dev/acpica/source/include/platform/acdragonflyex.h similarity index 73% copy from sys/contrib/dev/acpica/source/include/platform/acenvex.h copy to sys/contrib/dev/acpica/source/include/platform/acdragonflyex.h index a1de87ffee..be66bc7f04 100644 --- a/sys/contrib/dev/acpica/source/include/platform/acenvex.h +++ b/sys/contrib/dev/acpica/source/include/platform/acdragonflyex.h @@ -1,6 +1,6 @@ /****************************************************************************** * - * Name: acenvex.h - Extra host and compiler configuration + * Name: acdragonflyex.h - Extra OS specific defines, etc. for DragonFly * *****************************************************************************/ @@ -41,23 +41,44 @@ * POSSIBILITY OF SUCH DAMAGES. */ -#ifndef __ACENVEX_H__ -#define __ACENVEX_H__ +#ifndef __ACDRAGONFLYEX_H__ +#define __ACDRAGONFLYEX_H__ -/*! [Begin] no source code translation */ +#ifdef _KERNEL -/****************************************************************************** - * - * Extra host configuration files. All ACPICA headers are included before - * including these files. - * - *****************************************************************************/ +#ifdef ACPI_DEBUG_CACHE +ACPI_STATUS +_AcpiOsReleaseObject ( + ACPI_CACHE_T *Cache, + void *Object, + const char *func, + int line); +#endif + +#ifdef ACPI_DEBUG_LOCKS +ACPI_CPU_FLAGS +_AcpiOsAcquireLock ( + ACPI_SPINLOCK Spin, + const char *func, + int line); +#endif -#if defined(_LINUX) || defined(__linux__) -#include "aclinuxex.h" +#ifdef ACPI_DEBUG_MEMMAP +void * +_AcpiOsMapMemory ( + ACPI_PHYSICAL_ADDRESS Where, + ACPI_SIZE Length, + const char *caller, + int line); +void +_AcpiOsUnmapMemory ( + void *LogicalAddress, + ACPI_SIZE Length, + const char *caller, + int line); #endif -/*! [End] no source code translation !*/ +#endif /* _KERNEL */ -#endif /* __ACENVEX_H__ */ +#endif /* __ACDRAGONFLYEX_H__ */ diff --git a/sys/contrib/dev/acpica/source/include/platform/acenvex.h b/sys/contrib/dev/acpica/source/include/platform/acenvex.h index a1de87ffee..f3ab5c03a4 100644 --- a/sys/contrib/dev/acpica/source/include/platform/acenvex.h +++ b/sys/contrib/dev/acpica/source/include/platform/acenvex.h @@ -56,6 +56,9 @@ #if defined(_LINUX) || defined(__linux__) #include "aclinuxex.h" +#elif defined(__DragonFly__) +#include "acdragonflyex.h" + #endif /*! [End] no source code translation !*/ -- 2.41.0 From f00b70b856b00db0e3dc90faec2439e76ad84561 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 28 Jun 2014 17:51:11 +0200 Subject: [PATCH 11/16] Chmod 644 a few scripts in the tree. As usual, 'make install' will take care about setting the wanted mode. --- sbin/mkinitrd/mkinitrd.sh | 0 tools/tools/hammer-backup/hammer-backup.sh | 0 usr.sbin/service/service.sh | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 sbin/mkinitrd/mkinitrd.sh mode change 100755 => 100644 tools/tools/hammer-backup/hammer-backup.sh mode change 100755 => 100644 usr.sbin/service/service.sh diff --git a/sbin/mkinitrd/mkinitrd.sh b/sbin/mkinitrd/mkinitrd.sh old mode 100755 new mode 100644 diff --git a/tools/tools/hammer-backup/hammer-backup.sh b/tools/tools/hammer-backup/hammer-backup.sh old mode 100755 new mode 100644 diff --git a/usr.sbin/service/service.sh b/usr.sbin/service/service.sh old mode 100755 new mode 100644 -- 2.41.0 From 36f372d98303d09b2353791a855a662b2b385c23 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 28 Jun 2014 09:38:38 -0700 Subject: [PATCH 12/16] kernel - add toeplitz_piecemeal_addr/port() * Add two more inlines to help PF calculate matching cpus for NAT port scans. --- sys/net/toeplitz2.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sys/net/toeplitz2.h b/sys/net/toeplitz2.h index 213c862766..5a804640a5 100644 --- a/sys/net/toeplitz2.h +++ b/sys/net/toeplitz2.h @@ -90,4 +90,27 @@ toeplitz_hash(uint32_t _rawhash) return (_rawhash & 0xffff); } +static __inline uint32_t +toeplitz_piecemeal_addr(in_addr_t _faddr) +{ + uint32_t _res; + + _res = toeplitz_cache[0][_faddr & 0xff]; + _res ^= toeplitz_cache[0][(_faddr >> 16) & 0xff]; + _res ^= toeplitz_cache[1][(_faddr >> 8) & 0xff]; + _res ^= toeplitz_cache[1][(_faddr >> 24) & 0xff]; + return _res; +} + +static __inline uint32_t +toeplitz_piecemeal_port(in_port_t _fport) +{ + uint32_t _res; + + _res = toeplitz_cache[0][_fport & 0xff]; + _res ^= toeplitz_cache[1][(_fport >> 8) & 0xff]; + + return _res; +} + #endif /* !_NET_TOEPLITZ2_H_ */ -- 2.41.0 From e398f1335dbd1927acc8bdd9ceee047678521545 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sat, 28 Jun 2014 22:10:48 +0200 Subject: [PATCH 13/16] kernel/pf: Check size of long at compile time (fixes i386 build). --- sys/net/pf/pf.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sys/net/pf/pf.c b/sys/net/pf/pf.c index 8f6e307c7a..ce47936895 100644 --- a/sys/net/pf/pf.c +++ b/sys/net/pf/pf.c @@ -873,13 +873,13 @@ pf_state_insert(struct pfi_kif *kif, struct pf_state_key *skw, if (s->id == 0 && s->creatorid == 0) { u_int64_t sid; - if (sizeof(long) == 8) { - sid = atomic_fetchadd_long(&pf_status.stateid, 1); - } else { - spin_lock(&pf_spin); - sid = pf_status.stateid++; - spin_unlock(&pf_spin); - } +#if __SIZEOF_LONG__ == 8 + sid = atomic_fetchadd_long(&pf_status.stateid, 1); +#else + spin_lock(&pf_spin); + sid = pf_status.stateid++; + spin_unlock(&pf_spin); +#endif s->id = htobe64(sid); s->creatorid = pf_status.hostid; } -- 2.41.0 From 32772c966878dab0489c85e891a13e58d28933db Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 28 Jun 2014 23:46:43 -0700 Subject: [PATCH 14/16] kernel - Fix pf-based NAT * NAT may not always be able to select a translated addr/port that is compatible with the source addr/port. In this situation return packets from the translated target won't be able to find the state structure. This occurs if static-port is used or if the port range is insufficent for PF to be able to find a hash-compatible addr/port. This also occurs for UDP because the toeplitz hash does not appear to include a port (so there's nothing PF NAT can do to make it hash-compatible). * In situations where PF believes a translation is not hash-compatible, the pf_state_key will be placed on a global RBTREE instead of the cpu-localized RBTREE. This tree is checked and modified with a separate lock (shared when doing lookups, exclusive when doing adjustments). The nominal pf_find_state*() code will now check the global RBTREE if the state cannot be found in the localized tree. * Modifications to the pf_state structure are now exclusively locked to handle the case where a state structure might be used by multiple cpu's at the same time. This can only occur for translations such as NAT. * The TCP code is not allowed to destroy state on connection reuse unless the state is cpu-local. If it is not cpu-local the TCP code will mark the state for an immediate purge (within the next second). * Add a TSO flag check to pf_route(), which is called via NAT. Locally originated packets may have been built with TSO. For PF NAT, we can only assume that the target interface will be compatible and allow the packet through (not try to fragment it, which won't work well anyway for TCP packets). --- sys/net/pf/if_pfsync.c | 1 + sys/net/pf/if_pfsync.h | 6 +- sys/net/pf/pf.c | 555 +++++++++++++++++++++++++++++------------ sys/net/pf/pf_ioctl.c | 2 + sys/net/pf/pfvar.h | 8 +- 5 files changed, 409 insertions(+), 163 deletions(-) diff --git a/sys/net/pf/if_pfsync.c b/sys/net/pf/if_pfsync.c index 442f4c365d..278fb07318 100644 --- a/sys/net/pf/if_pfsync.c +++ b/sys/net/pf/if_pfsync.c @@ -346,6 +346,7 @@ pfsync_state_import(struct pfsync_state *sp, u_int8_t flags) if ((st = kmalloc(sizeof(struct pf_state), M_PFSYNC, pool_flags)) == NULL) goto cleanup; + lockinit(&st->lk, "pfstlk", 0, 0); if ((skw = pf_alloc_state_key(pool_flags)) == NULL) goto cleanup; diff --git a/sys/net/pf/if_pfsync.h b/sys/net/pf/if_pfsync.h index cc8ea6a046..6b01f5e93c 100644 --- a/sys/net/pf/if_pfsync.h +++ b/sys/net/pf/if_pfsync.h @@ -252,13 +252,13 @@ int pfsync_state_import(struct pfsync_state *, u_int8_t); st->sync_flags &= ~PFSTATE_FROMSYNC; \ } while (0) #define pfsync_update_state(st) do { \ - if (!st->sync_flags) \ + if (!(st)->sync_flags) \ pfsync_pack_state(PFSYNC_ACT_UPD, (st), \ PFSYNC_FLAG_COMPRESS); \ - st->sync_flags &= ~PFSTATE_FROMSYNC; \ + (st)->sync_flags &= ~PFSTATE_FROMSYNC; \ } while (0) #define pfsync_delete_state(st) do { \ - if (!st->sync_flags) \ + if (!(st)->sync_flags) \ pfsync_pack_state(PFSYNC_ACT_DEL, (st), \ PFSYNC_FLAG_COMPRESS); \ } while (0) diff --git a/sys/net/pf/pf.c b/sys/net/pf/pf.c index ce47936895..68ec8a923f 100644 --- a/sys/net/pf/pf.c +++ b/sys/net/pf/pf.c @@ -105,12 +105,25 @@ extern int ip_optcopy(struct ip *, struct ip *); extern int debug_pfugidhack; +/* + * pf_token - shared lock for cpu-localized operations, + * exclusive lock otherwise. + * + * pf_gtoken- exclusive lock used for initialization. + * + * pf_spin - only used to atomically fetch and increment stateid + * on 32-bit systems. + */ struct lwkt_token pf_token = LWKT_TOKEN_INITIALIZER(pf_token); -struct lwkt_token pf_secret_token = LWKT_TOKEN_INITIALIZER(pf_secret_token); +struct lwkt_token pf_gtoken = LWKT_TOKEN_INITIALIZER(pf_gtoken); +#if __SIZEOF_LONG__ != 8 struct spinlock pf_spin = SPINLOCK_INITIALIZER(pf_spin); +#endif #define DPFPRINTF(n, x) if (pf_status.debug >= (n)) kprintf x +#define FAIL(code) { error = (code); goto done; } + /* * Global variables */ @@ -119,7 +132,7 @@ struct spinlock pf_spin = SPINLOCK_INITIALIZER(pf_spin); struct radix_node_head *pf_maskhead; /* state tables */ -struct pf_state_tree pf_statetbl[MAXCPU]; +struct pf_state_tree pf_statetbl[MAXCPU+1]; /* incls one global table */ struct pf_altqqueue pf_altqs[2]; struct pf_palist pf_pabuf; @@ -237,7 +250,8 @@ void pf_hash(struct pf_addr *, struct pf_addr *, int pf_map_addr(u_int8_t, struct pf_rule *, struct pf_addr *, struct pf_addr *, struct pf_addr *, struct pf_src_node **); -int pf_get_sport(sa_family_t, u_int8_t, struct pf_rule *, +int pf_get_sport(struct pf_pdesc *, + sa_family_t, u_int8_t, struct pf_rule *, struct pf_addr *, struct pf_addr *, u_int16_t, u_int16_t, struct pf_addr *, u_int16_t *, @@ -266,7 +280,7 @@ int pf_addr_wrap_neq(struct pf_addr_wrap *, struct pf_addr_wrap *); struct pf_state *pf_find_state(struct pfi_kif *, struct pf_state_key_cmp *, u_int, struct mbuf *); -int pf_src_connlimit(struct pf_state **); +int pf_src_connlimit(struct pf_state *); int pf_check_congestion(struct ifqueue *); extern int pf_end_threads; @@ -281,7 +295,7 @@ struct pf_pool_limit pf_pool_limits[PF_LIMIT_MAX] = { #define STATE_LOOKUP(i, k, d, s, m) \ do { \ - s = pf_find_state(i, k, d, m); \ + s = pf_find_state(i, k, d, m); \ if (s == NULL || (s)->timeout == PFTM_PURGE) \ return (PF_DROP); \ if (d == PF_OUT && \ @@ -444,64 +458,64 @@ pf_check_threshold(struct pf_threshold *threshold) } int -pf_src_connlimit(struct pf_state **state) +pf_src_connlimit(struct pf_state *state) { int bad = 0; int cpu = mycpu->gd_cpuid; - (*state)->src_node->conn++; - (*state)->src.tcp_est = 1; - pf_add_threshold(&(*state)->src_node->conn_rate); + state->src_node->conn++; + state->src.tcp_est = 1; + pf_add_threshold(&state->src_node->conn_rate); - if ((*state)->rule.ptr->max_src_conn && - (*state)->rule.ptr->max_src_conn < - (*state)->src_node->conn) { + if (state->rule.ptr->max_src_conn && + state->rule.ptr->max_src_conn < + state->src_node->conn) { pf_status.lcounters[LCNT_SRCCONN]++; bad++; } - if ((*state)->rule.ptr->max_src_conn_rate.limit && - pf_check_threshold(&(*state)->src_node->conn_rate)) { + if (state->rule.ptr->max_src_conn_rate.limit && + pf_check_threshold(&state->src_node->conn_rate)) { pf_status.lcounters[LCNT_SRCCONNRATE]++; bad++; } if (!bad) - return (0); + return 0; - if ((*state)->rule.ptr->overload_tbl) { + if (state->rule.ptr->overload_tbl) { struct pfr_addr p; u_int32_t killed = 0; pf_status.lcounters[LCNT_OVERLOAD_TABLE]++; if (pf_status.debug >= PF_DEBUG_MISC) { kprintf("pf_src_connlimit: blocking address "); - pf_print_host(&(*state)->src_node->addr, 0, - (*state)->key[PF_SK_WIRE]->af); + pf_print_host(&state->src_node->addr, 0, + state->key[PF_SK_WIRE]->af); } bzero(&p, sizeof(p)); - p.pfra_af = (*state)->key[PF_SK_WIRE]->af; - switch ((*state)->key[PF_SK_WIRE]->af) { + p.pfra_af = state->key[PF_SK_WIRE]->af; + switch (state->key[PF_SK_WIRE]->af) { #ifdef INET case AF_INET: p.pfra_net = 32; - p.pfra_ip4addr = (*state)->src_node->addr.v4; + p.pfra_ip4addr = state->src_node->addr.v4; break; #endif /* INET */ #ifdef INET6 case AF_INET6: p.pfra_net = 128; - p.pfra_ip6addr = (*state)->src_node->addr.v6; + p.pfra_ip6addr = state->src_node->addr.v6; break; #endif /* INET6 */ } - pfr_insert_kentry((*state)->rule.ptr->overload_tbl, + pfr_insert_kentry(state->rule.ptr->overload_tbl, &p, time_second); /* kill existing states if that's required. */ - if ((*state)->rule.ptr->flush) { + if (state->rule.ptr->flush) { struct pf_state_key *sk; struct pf_state *st; @@ -514,16 +528,16 @@ pf_src_connlimit(struct pf_state **state) * set). (Only on current cpu). */ if (sk->af == - (*state)->key[PF_SK_WIRE]->af && - (((*state)->direction == PF_OUT && - PF_AEQ(&(*state)->src_node->addr, + state->key[PF_SK_WIRE]->af && + ((state->direction == PF_OUT && + PF_AEQ(&state->src_node->addr, &sk->addr[0], sk->af)) || - ((*state)->direction == PF_IN && - PF_AEQ(&(*state)->src_node->addr, + (state->direction == PF_IN && + PF_AEQ(&state->src_node->addr, &sk->addr[1], sk->af))) && - ((*state)->rule.ptr->flush & + (state->rule.ptr->flush & PF_FLUSH_GLOBAL || - (*state)->rule.ptr == st->rule.ptr)) { + state->rule.ptr == st->rule.ptr)) { st->timeout = PFTM_PURGE; st->src.state = st->dst.state = TCPS_CLOSED; @@ -538,9 +552,10 @@ pf_src_connlimit(struct pf_state **state) } /* kill this state */ - (*state)->timeout = PFTM_PURGE; - (*state)->src.state = (*state)->dst.state = TCPS_CLOSED; - return (1); + state->timeout = PFTM_PURGE; + state->src.state = state->dst.state = TCPS_CLOSED; + + return 1; } int @@ -704,7 +719,21 @@ pf_state_key_attach(struct pf_state_key *sk, struct pf_state *s, int idx) { struct pf_state_item *si; struct pf_state_key *cur; - int cpu = mycpu->gd_cpuid; + int cpu; + int error; + + /* + * PFSTATE_STACK_GLOBAL is set for translations when the translated + * address/port is not localized to the same cpu that the untranslated + * address/port is on. The wire pf_state_key is managed on the global + * statetbl tree for this case. + */ + if ((s->state_flags & PFSTATE_STACK_GLOBAL) && idx == PF_SK_WIRE) { + cpu = MAXCPU; + lockmgr(&pf_global_statetbl_lock, LK_EXCLUSIVE); + } else { + cpu = mycpu->gd_cpuid; + } KKASSERT(s->key[idx] == NULL); /* XXX handle this? */ @@ -725,17 +754,21 @@ pf_state_key_attach(struct pf_state_key *sk, struct pf_state *s, int idx) kprintf("\n"); } kfree(sk, M_PFSTATEKEYPL); - return (-1); /* collision! */ + error = -1; + goto failed; /* collision! */ } kfree(sk, M_PFSTATEKEYPL); s->key[idx] = cur; - } else + } else { s->key[idx] = sk; + } - if ((si = kmalloc(sizeof(struct pf_state_item), M_PFSTATEITEMPL, M_NOWAIT)) == NULL) { + if ((si = kmalloc(sizeof(struct pf_state_item), + M_PFSTATEITEMPL, M_NOWAIT)) == NULL) { pf_state_key_detach(s, idx); - return (-1); + error = -1; + goto failed; /* collision! */ } si->s = s; @@ -744,9 +777,18 @@ pf_state_key_attach(struct pf_state_key *sk, struct pf_state *s, int idx) TAILQ_INSERT_TAIL(&s->key[idx]->states, si, entry); else TAILQ_INSERT_HEAD(&s->key[idx]->states, si, entry); - return (0); + + error = 0; +failed: + if ((s->state_flags & PFSTATE_STACK_GLOBAL) && idx == PF_SK_WIRE) + lockmgr(&pf_global_statetbl_lock, LK_RELEASE); + return error; } +/* + * NOTE: Can only be called indirectly via the purge thread with pf_token + * exclusively locked. + */ void pf_detach_state(struct pf_state *s) { @@ -760,15 +802,32 @@ pf_detach_state(struct pf_state *s) pf_state_key_detach(s, PF_SK_WIRE); } +/* + * NOTE: Can only be called indirectly via the purge thread with pf_token + * exclusively locked. + */ void pf_state_key_detach(struct pf_state *s, int idx) { struct pf_state_item *si; - int cpu = mycpu->gd_cpuid; + int cpu; + + /* + * PFSTATE_STACK_GLOBAL is set for translations when the translated + * address/port is not localized to the same cpu that the untranslated + * address/port is on. The wire pf_state_key is managed on the global + * statetbl tree for this case. + */ + if ((s->state_flags & PFSTATE_STACK_GLOBAL) && idx == PF_SK_WIRE) { + cpu = MAXCPU; + lockmgr(&pf_global_statetbl_lock, LK_EXCLUSIVE); + } else { + cpu = mycpu->gd_cpuid; + } si = TAILQ_FIRST(&s->key[idx]->states); while (si && si->s != s) - si = TAILQ_NEXT(si, entry); + si = TAILQ_NEXT(si, entry); if (si) { TAILQ_REMOVE(&s->key[idx]->states, si, entry); @@ -784,6 +843,9 @@ pf_state_key_detach(struct pf_state *s, int idx) kfree(s->key[idx], M_PFSTATEKEYPL); } s->key[idx] = NULL; + + if ((s->state_flags & PFSTATE_STACK_GLOBAL) && idx == PF_SK_WIRE) + lockmgr(&pf_global_statetbl_lock, LK_RELEASE); } struct pf_state_key * @@ -791,10 +853,10 @@ pf_alloc_state_key(int pool_flags) { struct pf_state_key *sk; - if ((sk = kmalloc(sizeof(struct pf_state_key), M_PFSTATEKEYPL, pool_flags)) == NULL) - return (NULL); - TAILQ_INIT(&sk->states); - + sk = kmalloc(sizeof(struct pf_state_key), M_PFSTATEKEYPL, pool_flags); + if (sk) { + TAILQ_INIT(&sk->states); + } return (sk); } @@ -920,75 +982,136 @@ pf_find_state_byid(struct pf_state_cmp *key) (struct pf_state *)key)); } +/* + * WARNING! May return a state structure that was localized to another cpu, + * destruction is typically protected by the callers pf_token. + * The element can only be destroyed + */ struct pf_state * pf_find_state(struct pfi_kif *kif, struct pf_state_key_cmp *key, u_int dir, - struct mbuf *m) + struct mbuf *m) { + struct pf_state_key *skey = (void *)key; struct pf_state_key *sk; struct pf_state_item *si; + struct pf_state *s; int cpu = mycpu->gd_cpuid; + int globalstl = 0; pf_status.fcounters[FCNT_STATE_SEARCH]++; if (dir == PF_OUT && m->m_pkthdr.pf.statekey && - ((struct pf_state_key *)m->m_pkthdr.pf.statekey)->reverse) + ((struct pf_state_key *)m->m_pkthdr.pf.statekey)->reverse) { sk = ((struct pf_state_key *)m->m_pkthdr.pf.statekey)->reverse; - else { - if ((sk = RB_FIND(pf_state_tree, &pf_statetbl[cpu], - (struct pf_state_key *)key)) == NULL) - return (NULL); + } else { + sk = RB_FIND(pf_state_tree, &pf_statetbl[cpu], skey); + if (sk == NULL) { + lockmgr(&pf_global_statetbl_lock, LK_SHARED); + sk = RB_FIND(pf_state_tree, &pf_statetbl[MAXCPU], skey); + if (sk == NULL) { + lockmgr(&pf_global_statetbl_lock, LK_RELEASE); + return (NULL); + } + globalstl = 1; + } if (dir == PF_OUT && m->m_pkthdr.pf.statekey) { ((struct pf_state_key *) m->m_pkthdr.pf.statekey)->reverse = sk; sk->reverse = m->m_pkthdr.pf.statekey; } } - if (dir == PF_OUT) m->m_pkthdr.pf.statekey = NULL; /* list is sorted, if-bound states before floating ones */ - TAILQ_FOREACH(si, &sk->states, entry) + TAILQ_FOREACH(si, &sk->states, entry) { if ((si->s->kif == pfi_all || si->s->kif == kif) && sk == (dir == PF_IN ? si->s->key[PF_SK_WIRE] : - si->s->key[PF_SK_STACK])) - return (si->s); + si->s->key[PF_SK_STACK])) { + break; + } + } - return (NULL); + /* + * Extract state before potentially releasing the global statetbl + * lock. Ignore the state if the create is still in-progress as + * it can be deleted out from under us by the owning localized cpu. + * However, if CREATEINPROG is not set, state can only be deleted + * by the purge thread which we are protected from via our shared + * pf_token. + */ + if (si) { + s = si->s; + if (s && (s->state_flags & PFSTATE_CREATEINPROG)) + s = NULL; + } else { + s = NULL; + } + if (globalstl) + lockmgr(&pf_global_statetbl_lock, LK_RELEASE); + return s; } +/* + * WARNING! May return a state structure that was localized to another cpu, + * destruction is typically protected by the callers pf_token. + */ struct pf_state * pf_find_state_all(struct pf_state_key_cmp *key, u_int dir, int *more) { + struct pf_state_key *skey = (void *)key; struct pf_state_key *sk; struct pf_state_item *si, *ret = NULL; + struct pf_state *s; int cpu = mycpu->gd_cpuid; + int globalstl = 0; pf_status.fcounters[FCNT_STATE_SEARCH]++; - sk = RB_FIND(pf_state_tree, &pf_statetbl[cpu], - (struct pf_state_key *)key); - + sk = RB_FIND(pf_state_tree, &pf_statetbl[cpu], skey); + if (sk == NULL) { + lockmgr(&pf_global_statetbl_lock, LK_SHARED); + sk = RB_FIND(pf_state_tree, &pf_statetbl[MAXCPU], skey); + globalstl = 1; + } if (sk != NULL) { TAILQ_FOREACH(si, &sk->states, entry) if (dir == PF_INOUT || (sk == (dir == PF_IN ? si->s->key[PF_SK_WIRE] : si->s->key[PF_SK_STACK]))) { - if (more == NULL) - return (si->s); - + if (more == NULL) { + ret = si; + break; + } if (ret) (*more)++; else ret = si; } } - return (ret ? ret->s : NULL); + + /* + * Extract state before potentially releasing the global statetbl + * lock. Ignore the state if the create is still in-progress as + * it can be deleted out from under us by the owning localized cpu. + * However, if CREATEINPROG is not set, state can only be deleted + * by the purge thread which we are protected from via our shared + * pf_token. + */ + if (ret) { + s = ret->s; + if (s && (s->state_flags & PFSTATE_CREATEINPROG)) + s = NULL; + } else { + s = NULL; + } + if (globalstl) + lockmgr(&pf_global_statetbl_lock, LK_RELEASE); + return s; } /* END state table stuff */ - void pf_purge_thread(void *v) { @@ -1149,9 +1272,10 @@ pf_src_tree_remove_state(struct pf_state *s) --s->src_node->conn; if (--s->src_node->states <= 0) { timeout = s->rule.ptr->timeout[PFTM_SRC_NODE]; - if (!timeout) + if (!timeout) { timeout = pf_default_rule.timeout[PFTM_SRC_NODE]; + } s->src_node->expire = time_second + timeout; } } @@ -1212,13 +1336,16 @@ pf_free_state(struct pf_state *cur) if (--cur->rule.ptr->states_cur <= 0 && cur->rule.ptr->src_nodes <= 0) pf_rm_rule(NULL, cur->rule.ptr); - if (cur->nat_rule.ptr != NULL) + if (cur->nat_rule.ptr != NULL) { if (--cur->nat_rule.ptr->states_cur <= 0 && - cur->nat_rule.ptr->src_nodes <= 0) + cur->nat_rule.ptr->src_nodes <= 0) { pf_rm_rule(NULL, cur->nat_rule.ptr); - if (cur->anchor.ptr != NULL) + } + } + if (cur->anchor.ptr != NULL) { if (--cur->anchor.ptr->states_cur <= 0) pf_rm_rule(NULL, cur->anchor.ptr); + } pf_normalize_tcp_cleanup(cur); pfi_kif_unref(cur->kif, PFI_KIF_REF_STATE); @@ -2552,11 +2679,12 @@ pf_map_addr(sa_family_t af, struct pf_rule *r, struct pf_addr *saddr, } int -pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, - struct pf_addr *saddr, struct pf_addr *daddr, - u_int16_t sport, u_int16_t dport, - struct pf_addr *naddr, u_int16_t *nport, u_int16_t low, u_int16_t high, - struct pf_src_node **sn) +pf_get_sport(struct pf_pdesc *pd, sa_family_t af, + u_int8_t proto, struct pf_rule *r, + struct pf_addr *saddr, struct pf_addr *daddr, + u_int16_t sport, u_int16_t dport, + struct pf_addr *naddr, u_int16_t *nport, + u_int16_t low, u_int16_t high, struct pf_src_node **sn) { struct pf_state_key_cmp key; struct pf_addr init_addr; @@ -2585,6 +2713,10 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, * We want to select a port that calculates to a toeplitz hash * that masks to the same cpu, otherwise the response may * not see the new state. + * + * We can still do this even if the kernel is disregarding + * the hash and vectoring the packets to a specific cpu, + * but it will reduce the number of ports we can use. */ switch(af) { case AF_INET: @@ -2605,28 +2737,53 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, * port search; start random, step; * similar 2 portloop in in_pcbbind * + * WARNING! We try to match such that the kernel will + * dispatch the translated host/port to the same + * cpu, but this might not be possible. + * + * In the case where the port is fixed, or for the + * UDP case (whos toeplitz does not incorporate the + * port), we set not_cpu_localized which ultimately + * causes the pf_state_tree element + * * XXX fixed ports present a problem for cpu localization. */ - if (!(proto == IPPROTO_TCP || proto == IPPROTO_UDP || - proto == IPPROTO_ICMP)) { + if (!(proto == IPPROTO_TCP || + proto == IPPROTO_UDP || + proto == IPPROTO_ICMP)) { + /* + * non-specific protocol, leave port intact. + */ key.port[1] = sport; if (pf_find_state_all(&key, PF_IN, NULL) == NULL) { *nport = sport; + pd->not_cpu_localized = 1; return (0); } } else if (low == 0 && high == 0) { + /* + * static-port same as originator. + */ key.port[1] = sport; if (pf_find_state_all(&key, PF_IN, NULL) == NULL) { *nport = sport; + pd->not_cpu_localized = 1; return (0); } } else if (low == high) { + /* + * specific port as specified. + */ key.port[1] = htons(low); if (pf_find_state_all(&key, PF_IN, NULL) == NULL) { *nport = htons(low); + pd->not_cpu_localized = 1; return (0); } } else { + /* + * normal dynamic port + */ u_int16_t tmp; if (low > high) { @@ -2645,6 +2802,8 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, } if (pf_find_state_all(&key, PF_IN, NULL) == NULL && !in_baddynamic(tmp, proto)) { + if (proto == IPPROTO_UDP) + pd->not_cpu_localized = 1; *nport = htons(tmp); return (0); } @@ -2657,6 +2816,8 @@ pf_get_sport(sa_family_t af, u_int8_t proto, struct pf_rule *r, } if (pf_find_state_all(&key, PF_IN, NULL) == NULL && !in_baddynamic(tmp, proto)) { + if (proto == IPPROTO_UDP) + pd->not_cpu_localized = 1; *nport = htons(tmp); return (0); } @@ -2773,7 +2934,6 @@ pf_get_translation(struct pf_pdesc *pd, struct mbuf *m, int off, int direction, { struct pf_rule *r = NULL; - if (direction == PF_OUT) { r = pf_match_translation(pd, m, off, direction, kif, saddr, sport, daddr, dport, PF_RULESET_BINAT); @@ -2812,7 +2972,7 @@ pf_get_translation(struct pf_pdesc *pd, struct mbuf *m, int off, int direction, return (NULL); case PF_NAT: m->m_pkthdr.fw_flags &= ~BRIDGE_MBUF_TAGGED; - if (pf_get_sport(pd->af, pd->proto, r, + if (pf_get_sport(pd, pd->af, pd->proto, r, saddr, daddr, sport, dport, naddr, nport, r->rpool.proxy_port[0], r->rpool.proxy_port[1], sn)) { @@ -3268,7 +3428,7 @@ pf_tcp_iss(struct pf_pdesc *pd) u_int32_t digest[4]; if (pf_tcp_secret_init == 0) { - lwkt_gettoken(&pf_secret_token); + lwkt_gettoken(&pf_gtoken); if (pf_tcp_secret_init == 0) { karc4rand(pf_tcp_secret, sizeof(pf_tcp_secret)); MD5Init(&pf_tcp_secret_ctx); @@ -3276,7 +3436,7 @@ pf_tcp_iss(struct pf_pdesc *pd) sizeof(pf_tcp_secret)); pf_tcp_secret_init = 1; } - lwkt_reltoken(&pf_secret_token); + lwkt_reltoken(&pf_gtoken); } ctx = pf_tcp_secret_ctx; @@ -3742,16 +3902,21 @@ pf_create_state(struct pf_rule *r, struct pf_rule *nr, struct pf_rule *a, REASON_SET(&reason, PFRES_MEMORY); goto csfailed; } + lockinit(&s->lk, "pfstlk", 0, 0); s->id = 0; /* XXX Do we really need that? not in OpenBSD */ s->creatorid = 0; s->rule.ptr = r; s->nat_rule.ptr = nr; s->anchor.ptr = a; + s->state_flags = PFSTATE_CREATEINPROG; STATE_INC_COUNTERS(s); if (r->allow_opts) s->state_flags |= PFSTATE_ALLOWOPTS; if (r->rule_flag & PFRULE_STATESLOPPY) s->state_flags |= PFSTATE_SLOPPY; + if (pd->not_cpu_localized) + s->state_flags |= PFSTATE_STACK_GLOBAL; + s->log = r->log & PF_LOG_ALL; if (nr != NULL) s->log |= nr->log & PF_LOG_ALL; @@ -3846,8 +4011,10 @@ pf_create_state(struct pf_rule *r, struct pf_rule *nr, struct pf_rule *a, s->direction = pd->dir; if (sk == NULL && pf_state_key_setup(pd, nr, &skw, &sks, &sk, &nk, - pd->src, pd->dst, sport, dport)) + pd->src, pd->dst, sport, dport)) { + REASON_SET(&reason, PFRES_MEMORY); goto csfailed; + } if (pf_state_insert(BOUND_IFACE(r, kif), skw, sks, s)) { if (pd->proto == IPPROTO_TCP) @@ -3891,13 +4058,15 @@ pf_create_state(struct pf_rule *r, struct pf_rule *nr, struct pf_rule *a, mss = pf_calc_mss(pd->src, pd->af, mss); mss = pf_calc_mss(pd->dst, pd->af, mss); s->src.mss = mss; + s->state_flags &= ~PFSTATE_CREATEINPROG; pf_send_tcp(r, pd->af, pd->dst, pd->src, th->th_dport, - th->th_sport, s->src.seqhi, ntohl(th->th_seq) + 1, - TH_SYN|TH_ACK, 0, s->src.mss, 0, 1, 0, NULL, NULL); + th->th_sport, s->src.seqhi, ntohl(th->th_seq) + 1, + TH_SYN|TH_ACK, 0, s->src.mss, 0, 1, 0, NULL, NULL); REASON_SET(&reason, PFRES_SYNPROXY); return (PF_SYNPROXY_DROP); } + s->state_flags &= ~PFSTATE_CREATEINPROG; return (PF_PASS); csfailed: @@ -3918,6 +4087,12 @@ csfailed: atomic_add_int(&pf_status.src_nodes, -1); kfree(nsn, M_PFSRCTREEPL); } + if (s) { + pf_src_tree_remove_state(s); + STATE_DEC_COUNTERS(s); + kfree(s, M_PFSTATEPL); + } + return (PF_DROP); } @@ -4007,6 +4182,9 @@ pf_test_fragment(struct pf_rule **rm, int direction, struct pfi_kif *kif, return (PF_PASS); } +/* + * Called with state locked + */ int pf_tcp_track_full(struct pf_state_peer *src, struct pf_state_peer *dst, struct pf_state **state, struct pfi_kif *kif, struct mbuf *m, int off, @@ -4197,7 +4375,7 @@ pf_tcp_track_full(struct pf_state_peer *src, struct pf_state_peer *dst, dst->state = TCPS_ESTABLISHED; if (src->state == TCPS_ESTABLISHED && (*state)->src_node != NULL && - pf_src_connlimit(state)) { + pf_src_connlimit(*state)) { REASON_SET(reason, PFRES_SRCLIMIT); return (PF_DROP); } @@ -4355,6 +4533,9 @@ pf_tcp_track_full(struct pf_state_peer *src, struct pf_state_peer *dst, return (PF_PASS); } +/* + * Called with state locked + */ int pf_tcp_track_sloppy(struct pf_state_peer *src, struct pf_state_peer *dst, struct pf_state **state, struct pf_pdesc *pd, u_short *reason) @@ -4372,7 +4553,7 @@ pf_tcp_track_sloppy(struct pf_state_peer *src, struct pf_state_peer *dst, dst->state = TCPS_ESTABLISHED; if (src->state == TCPS_ESTABLISHED && (*state)->src_node != NULL && - pf_src_connlimit(state)) { + pf_src_connlimit(*state)) { REASON_SET(reason, PFRES_SRCLIMIT); return (PF_DROP); } @@ -4388,7 +4569,7 @@ pf_tcp_track_sloppy(struct pf_state_peer *src, struct pf_state_peer *dst, */ dst->state = src->state = TCPS_ESTABLISHED; if ((*state)->src_node != NULL && - pf_src_connlimit(state)) { + pf_src_connlimit(*state)) { REASON_SET(reason, PFRES_SRCLIMIT); return (PF_DROP); } @@ -4426,14 +4607,18 @@ pf_tcp_track_sloppy(struct pf_state_peer *src, struct pf_state_peer *dst, return (PF_PASS); } +/* + * Test TCP connection state. Caller must hold the state locked. + */ int pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif, - struct mbuf *m, int off, void *h, struct pf_pdesc *pd, - u_short *reason) + struct mbuf *m, int off, void *h, struct pf_pdesc *pd, + u_short *reason) { struct pf_state_key_cmp key; struct tcphdr *th = pd->hdr.tcp; int copyback = 0; + int error; struct pf_state_peer *src, *dst; struct pf_state_key *sk; @@ -4452,6 +4637,7 @@ pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif, } STATE_LOOKUP(kif, &key, direction, *state, m); + lockmgr(&(*state)->lk, LK_EXCLUSIVE); if (direction == (*state)->direction) { src = &(*state)->src; @@ -4466,12 +4652,12 @@ pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif, if ((*state)->src.state == PF_TCPS_PROXY_SRC) { if (direction != (*state)->direction) { REASON_SET(reason, PFRES_SYNPROXY); - return (PF_SYNPROXY_DROP); + FAIL (PF_SYNPROXY_DROP); } if (th->th_flags & TH_SYN) { if (ntohl(th->th_seq) != (*state)->src.seqlo) { REASON_SET(reason, PFRES_SYNPROXY); - return (PF_DROP); + FAIL (PF_DROP); } pf_send_tcp((*state)->rule.ptr, pd->af, pd->dst, pd->src, th->th_dport, th->th_sport, @@ -4479,16 +4665,16 @@ pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif, TH_SYN|TH_ACK, 0, (*state)->src.mss, 0, 1, 0, NULL, NULL); REASON_SET(reason, PFRES_SYNPROXY); - return (PF_SYNPROXY_DROP); + FAIL (PF_SYNPROXY_DROP); } else if (!(th->th_flags & TH_ACK) || (ntohl(th->th_ack) != (*state)->src.seqhi + 1) || (ntohl(th->th_seq) != (*state)->src.seqlo + 1)) { REASON_SET(reason, PFRES_SYNPROXY); - return (PF_DROP); + FAIL (PF_DROP); } else if ((*state)->src_node != NULL && - pf_src_connlimit(state)) { + pf_src_connlimit(*state)) { REASON_SET(reason, PFRES_SRCLIMIT); - return (PF_DROP); + FAIL (PF_DROP); } else (*state)->src.state = PF_TCPS_PROXY_DST; } @@ -4498,7 +4684,7 @@ pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif, (ntohl(th->th_ack) != (*state)->src.seqhi + 1) || (ntohl(th->th_seq) != (*state)->src.seqlo + 1)) { REASON_SET(reason, PFRES_SYNPROXY); - return (PF_DROP); + FAIL (PF_DROP); } (*state)->src.max_win = MAX(ntohs(th->th_win), 1); if ((*state)->dst.seqhi == 1) @@ -4509,12 +4695,12 @@ pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif, (*state)->dst.seqhi, 0, TH_SYN, 0, (*state)->src.mss, 0, 0, (*state)->tag, NULL, NULL); REASON_SET(reason, PFRES_SYNPROXY); - return (PF_SYNPROXY_DROP); + FAIL (PF_SYNPROXY_DROP); } else if (((th->th_flags & (TH_SYN|TH_ACK)) != (TH_SYN|TH_ACK)) || (ntohl(th->th_ack) != (*state)->dst.seqhi + 1)) { REASON_SET(reason, PFRES_SYNPROXY); - return (PF_DROP); + FAIL (PF_DROP); } else { (*state)->dst.max_win = MAX(ntohs(th->th_win), 1); (*state)->dst.seqlo = ntohl(th->th_seq); @@ -4541,10 +4727,14 @@ pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif, (*state)->src.state = (*state)->dst.state = TCPS_ESTABLISHED; REASON_SET(reason, PFRES_SYNPROXY); - return (PF_SYNPROXY_DROP); + FAIL (PF_SYNPROXY_DROP); } } + /* + * Check for connection (addr+port pair) reuse. We can't actually + * unlink the state if we don't own it. + */ if (((th->th_flags & (TH_SYN|TH_ACK)) == TH_SYN) && dst->state >= TCPS_FIN_WAIT_2 && src->state >= TCPS_FIN_WAIT_2) { @@ -4556,18 +4746,25 @@ pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif, } /* XXX make sure it's the same direction ?? */ (*state)->src.state = (*state)->dst.state = TCPS_CLOSED; - pf_unlink_state(*state); - *state = NULL; - return (PF_DROP); + if ((*state)->cpuid == mycpu->gd_cpuid) { + pf_unlink_state(*state); + *state = NULL; + } else { + (*state)->timeout = PFTM_PURGE; + } + FAIL (PF_DROP); } if ((*state)->state_flags & PFSTATE_SLOPPY) { - if (pf_tcp_track_sloppy(src, dst, state, pd, reason) == PF_DROP) - return (PF_DROP); + if (pf_tcp_track_sloppy(src, dst, state, pd, + reason) == PF_DROP) { + FAIL (PF_DROP); + } } else { - if (pf_tcp_track_full(src, dst, state, kif, m, off, pd, reason, - ©back) == PF_DROP) - return (PF_DROP); + if (pf_tcp_track_full(src, dst, state, kif, m, off, pd, + reason, ©back) == PF_DROP) { + FAIL (PF_DROP); + } } /* translate source/destination address, if necessary */ @@ -4607,12 +4804,20 @@ pf_test_state_tcp(struct pf_state **state, int direction, struct pfi_kif *kif, if (copyback) m_copyback(m, off, sizeof(*th), (caddr_t)th); - return (PF_PASS); + pfsync_update_state(*state); + error = PF_PASS; +done: + if (*state) + lockmgr(&(*state)->lk, LK_RELEASE); + return (error); } +/* + * Test UDP connection state. Caller must hold the state locked. + */ int pf_test_state_udp(struct pf_state **state, int direction, struct pfi_kif *kif, - struct mbuf *m, int off, void *h, struct pf_pdesc *pd) + struct mbuf *m, int off, void *h, struct pf_pdesc *pd) { struct pf_state_peer *src, *dst; struct pf_state_key_cmp key; @@ -4633,6 +4838,7 @@ pf_test_state_udp(struct pf_state **state, int direction, struct pfi_kif *kif, } STATE_LOOKUP(kif, &key, direction, *state, m); + lockmgr(&(*state)->lk, LK_EXCLUSIVE); if (direction == (*state)->direction) { src = &(*state)->src; @@ -4688,17 +4894,24 @@ pf_test_state_udp(struct pf_state **state, int direction, struct pfi_kif *kif, m_copyback(m, off, sizeof(*uh), (caddr_t)uh); } + pfsync_update_state(*state); + lockmgr(&(*state)->lk, LK_RELEASE); return (PF_PASS); } +/* + * Test ICMP connection state. Caller must hold the state locked. + */ int pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, - struct mbuf *m, int off, void *h, struct pf_pdesc *pd, u_short *reason) + struct mbuf *m, int off, void *h, struct pf_pdesc *pd, + u_short *reason) { struct pf_addr *saddr = pd->src, *daddr = pd->dst; u_int16_t icmpid = 0, *icmpsum; u_int8_t icmptype; int state_icmp = 0; + int error; struct pf_state_key_cmp key; switch (pd->proto) { @@ -4749,6 +4962,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, } STATE_LOOKUP(kif, &key, direction, *state, m); + lockmgr(&(*state)->lk, LK_EXCLUSIVE); (*state)->expire = time_second; (*state)->timeout = PFTM_ICMP_ERROR_REPLY; @@ -4807,8 +5021,6 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, #endif /* INET6 */ } } - return (PF_PASS); - } else { /* * ICMP error message in response to a TCP/UDP packet. @@ -4826,6 +5038,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, int ipoff2; int off2; + pd2.not_cpu_localized = 1; pd2.af = pd->af; /* Payload packet is from the opposite direction. */ pd2.sidx = (direction == PF_IN) ? 1 : 0; @@ -4841,7 +5054,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, DPFPRINTF(PF_DEBUG_MISC, ("pf: ICMP error message too short " "(ip)\n")); - return (PF_DROP); + FAIL (PF_DROP); } /* * ICMP error messages don't refer to non-first @@ -4849,7 +5062,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, */ if (h2.ip_off & htons(IP_OFFMASK)) { REASON_SET(reason, PFRES_FRAG); - return (PF_DROP); + FAIL (PF_DROP); } /* offset of protocol header that follows h2 */ @@ -4870,7 +5083,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, DPFPRINTF(PF_DEBUG_MISC, ("pf: ICMP error message too short " "(ip6)\n")); - return (PF_DROP); + FAIL (PF_DROP); } pd2.proto = h2_6.ip6_nxt; pd2.src = (struct pf_addr *)&h2_6.ip6_src; @@ -4885,7 +5098,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, * non-first fragments */ REASON_SET(reason, PFRES_FRAG); - return (PF_DROP); + FAIL (PF_DROP); case IPPROTO_AH: case IPPROTO_HOPOPTS: case IPPROTO_ROUTING: @@ -4898,7 +5111,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, pd2.af)) { DPFPRINTF(PF_DEBUG_MISC, ("pf: ICMPv6 short opt\n")); - return (PF_DROP); + FAIL (PF_DROP); } if (pd2.proto == IPPROTO_AH) off2 += (opt6.ip6e_len + 2) * 4; @@ -4918,7 +5131,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, default: DPFPRINTF(PF_DEBUG_MISC, ("pf: ICMP AF %d unknown (ip6)\n", pd->af)); - return (PF_DROP); + FAIL (PF_DROP); break; } @@ -4940,7 +5153,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, DPFPRINTF(PF_DEBUG_MISC, ("pf: ICMP error message too short " "(tcp)\n")); - return (PF_DROP); + FAIL (PF_DROP); } key.af = pd2.af; @@ -4951,6 +5164,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, key.port[pd2.didx] = th.th_dport; STATE_LOOKUP(kif, &key, direction, *state, m); + lockmgr(&(*state)->lk, LK_EXCLUSIVE); if (direction == (*state)->direction) { src = &(*state)->dst; @@ -4987,7 +5201,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, kprintf(" seq=%u\n", seq); } REASON_SET(reason, PFRES_BADSTATE); - return (PF_DROP); + FAIL (PF_DROP); } else { if (pf_status.debug >= PF_DEBUG_MISC) { kprintf("pf: OK ICMP %d:%d ", @@ -5050,8 +5264,6 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, } m_copyback(m, off2, 8, (caddr_t)&th); } - - return (PF_PASS); break; } case IPPROTO_UDP: { @@ -5073,6 +5285,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, key.port[pd2.didx] = uh.uh_dport; STATE_LOOKUP(kif, &key, direction, *state, m); + lockmgr(&(*state)->lk, LK_EXCLUSIVE); /* translate source/destination address, if necessary */ if ((*state)->key[PF_SK_WIRE] != @@ -5119,8 +5332,6 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, } m_copyback(m, off2, sizeof(uh), (caddr_t)&uh); } - - return (PF_PASS); break; } #ifdef INET @@ -5142,6 +5353,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, key.port[0] = key.port[1] = iih.icmp_id; STATE_LOOKUP(kif, &key, direction, *state, m); + lockmgr(&(*state)->lk, LK_EXCLUSIVE); /* translate source/destination address, if necessary */ if ((*state)->key[PF_SK_WIRE] != @@ -5172,7 +5384,6 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, m_copyback(m, ipoff2, sizeof(h2), (caddr_t)&h2); m_copyback(m, off2, ICMP_MINLEN, (caddr_t)&iih); } - return (PF_PASS); break; } #endif /* INET */ @@ -5185,7 +5396,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, DPFPRINTF(PF_DEBUG_MISC, ("pf: ICMP error message too short " "(icmp6)\n")); - return (PF_DROP); + FAIL (PF_DROP); } key.af = pd2.af; @@ -5195,6 +5406,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, key.port[0] = key.port[1] = iih.icmp6_id; STATE_LOOKUP(kif, &key, direction, *state, m); + lockmgr(&(*state)->lk, LK_EXCLUSIVE); /* translate source/destination address, if necessary */ if ((*state)->key[PF_SK_WIRE] != @@ -5227,8 +5439,6 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, m_copyback(m, off2, sizeof(struct icmp6_hdr), (caddr_t)&iih); } - - return (PF_PASS); break; } #endif /* INET6 */ @@ -5240,6 +5450,7 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, key.port[0] = key.port[1] = 0; STATE_LOOKUP(kif, &key, direction, *state, m); + lockmgr(&(*state)->lk, LK_EXCLUSIVE); /* translate source/destination address, if necessary */ if ((*state)->key[PF_SK_WIRE] != @@ -5281,16 +5492,25 @@ pf_test_state_icmp(struct pf_state **state, int direction, struct pfi_kif *kif, #endif /* INET6 */ } } - return (PF_PASS); break; } } } + + pfsync_update_state(*state); + error = PF_PASS; +done: + if (*state) + lockmgr(&(*state)->lk, LK_RELEASE); + return (error); } +/* + * Test other connection state. Caller must hold the state locked. + */ int pf_test_state_other(struct pf_state **state, int direction, struct pfi_kif *kif, - struct mbuf *m, struct pf_pdesc *pd) + struct mbuf *m, struct pf_pdesc *pd) { struct pf_state_peer *src, *dst; struct pf_state_key_cmp key; @@ -5308,6 +5528,7 @@ pf_test_state_other(struct pf_state **state, int direction, struct pfi_kif *kif, } STATE_LOOKUP(kif, &key, direction, *state, m); + lockmgr(&(*state)->lk, LK_EXCLUSIVE); if (direction == (*state)->direction) { src = &(*state)->src; @@ -5366,6 +5587,9 @@ pf_test_state_other(struct pf_state **state, int direction, struct pfi_kif *kif, #endif /* INET6 */ } } + + pfsync_update_state(*state); + lockmgr(&(*state)->lk, LK_RELEASE); return (PF_PASS); } @@ -5656,8 +5880,15 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, m0->m_pkthdr.csum_flags &= ifp->if_hwassist; m0->m_pkthdr.csum_iphlen = (ip->ip_hl << 2); + /* + * WARNING! We cannot fragment if the packet was modified from an + * original which expected to be using TSO. In this + * situation we pray that the target interface is + * compatible with the originating interface. + */ if (ip->ip_len <= ifp->if_mtu || - (ifp->if_hwassist & CSUM_FRAGMENT && + (m0->m_pkthdr.csum_flags & CSUM_TSO) || + ((ifp->if_hwassist & CSUM_FRAGMENT) && (ip->ip_off & IP_DF) == 0)) { ip->ip_len = htons(ip->ip_len); ip->ip_off = htons(ip->ip_off); @@ -5685,7 +5916,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, ipstat.ips_cantfrag++; if (r->rt != PF_DUPTO) { icmp_error(m0, ICMP_UNREACH, ICMP_UNREACH_NEEDFRAG, 0, - ifp->if_mtu); + ifp->if_mtu); goto done; } else goto bad; @@ -6124,15 +6355,16 @@ pf_test(int dir, struct ifnet *ifp, struct mbuf **m0, if (action == PF_DROP) goto done; action = pf_test_state_tcp(&s, dir, kif, m, off, h, &pd, - &reason); + &reason); if (action == PF_PASS) { - pfsync_update_state(s); r = s->rule.ptr; a = s->anchor.ptr; log = s->log; - } else if (s == NULL) + } else if (s == NULL) { action = pf_test_rule(&r, &s, dir, kif, - m, off, h, &pd, &a, &ruleset, NULL, inp); + m, off, h, &pd, &a, + &ruleset, NULL, inp); + } break; } @@ -6154,13 +6386,14 @@ pf_test(int dir, struct ifnet *ifp, struct mbuf **m0, } action = pf_test_state_udp(&s, dir, kif, m, off, h, &pd); if (action == PF_PASS) { - pfsync_update_state(s); r = s->rule.ptr; a = s->anchor.ptr; log = s->log; - } else if (s == NULL) + } else if (s == NULL) { action = pf_test_rule(&r, &s, dir, kif, - m, off, h, &pd, &a, &ruleset, NULL, inp); + m, off, h, &pd, &a, + &ruleset, NULL, inp); + } break; } @@ -6174,28 +6407,29 @@ pf_test(int dir, struct ifnet *ifp, struct mbuf **m0, goto done; } action = pf_test_state_icmp(&s, dir, kif, m, off, h, &pd, - &reason); + &reason); if (action == PF_PASS) { - pfsync_update_state(s); r = s->rule.ptr; a = s->anchor.ptr; log = s->log; - } else if (s == NULL) + } else if (s == NULL) { action = pf_test_rule(&r, &s, dir, kif, - m, off, h, &pd, &a, &ruleset, NULL, inp); + m, off, h, &pd, &a, + &ruleset, NULL, inp); + } break; } default: action = pf_test_state_other(&s, dir, kif, m, &pd); if (action == PF_PASS) { - pfsync_update_state(s); r = s->rule.ptr; a = s->anchor.ptr; log = s->log; - } else if (s == NULL) + } else if (s == NULL) { action = pf_test_rule(&r, &s, dir, kif, m, off, h, - &pd, &a, &ruleset, NULL, inp); + &pd, &a, &ruleset, NULL, inp); + } break; } @@ -6511,15 +6745,16 @@ pf_test6(int dir, struct ifnet *ifp, struct mbuf **m0, if (action == PF_DROP) goto done; action = pf_test_state_tcp(&s, dir, kif, m, off, h, &pd, - &reason); + &reason); if (action == PF_PASS) { - pfsync_update_state(s); r = s->rule.ptr; a = s->anchor.ptr; log = s->log; - } else if (s == NULL) + } else if (s == NULL) { action = pf_test_rule(&r, &s, dir, kif, - m, off, h, &pd, &a, &ruleset, NULL, inp); + m, off, h, &pd, &a, + &ruleset, NULL, inp); + } break; } @@ -6541,13 +6776,14 @@ pf_test6(int dir, struct ifnet *ifp, struct mbuf **m0, } action = pf_test_state_udp(&s, dir, kif, m, off, h, &pd); if (action == PF_PASS) { - pfsync_update_state(s); r = s->rule.ptr; a = s->anchor.ptr; log = s->log; - } else if (s == NULL) + } else if (s == NULL) { action = pf_test_rule(&r, &s, dir, kif, - m, off, h, &pd, &a, &ruleset, NULL, inp); + m, off, h, &pd, &a, + &ruleset, NULL, inp); + } break; } @@ -6561,28 +6797,29 @@ pf_test6(int dir, struct ifnet *ifp, struct mbuf **m0, goto done; } action = pf_test_state_icmp(&s, dir, kif, - m, off, h, &pd, &reason); + m, off, h, &pd, &reason); if (action == PF_PASS) { - pfsync_update_state(s); r = s->rule.ptr; a = s->anchor.ptr; log = s->log; - } else if (s == NULL) + } else if (s == NULL) { action = pf_test_rule(&r, &s, dir, kif, - m, off, h, &pd, &a, &ruleset, NULL, inp); + m, off, h, &pd, &a, + &ruleset, NULL, inp); + } break; } default: action = pf_test_state_other(&s, dir, kif, m, &pd); if (action == PF_PASS) { - pfsync_update_state(s); r = s->rule.ptr; a = s->anchor.ptr; log = s->log; - } else if (s == NULL) + } else if (s == NULL) { action = pf_test_rule(&r, &s, dir, kif, m, off, h, - &pd, &a, &ruleset, NULL, inp); + &pd, &a, &ruleset, NULL, inp); + } break; } diff --git a/sys/net/pf/pf_ioctl.c b/sys/net/pf/pf_ioctl.c index a525c69b9e..64d4acdb5e 100644 --- a/sys/net/pf/pf_ioctl.c +++ b/sys/net/pf/pf_ioctl.c @@ -117,6 +117,7 @@ void pf_addr_copyout(struct pf_addr_wrap *); struct pf_rule pf_default_rule; struct lock pf_consistency_lock; +struct lock pf_global_statetbl_lock; #ifdef ALTQ static int pf_altq_running; #endif @@ -3309,6 +3310,7 @@ pf_load(void) pf_dev = make_dev(&pf_ops, 0, 0, 0, 0600, PF_NAME); pfattach(); lockinit(&pf_consistency_lock, "pfconslck", 0, LK_CANRECURSE); + lockinit(&pf_global_statetbl_lock, "pfglstlk", 0, 0); lwkt_reltoken(&pf_token); return (0); } diff --git a/sys/net/pf/pfvar.h b/sys/net/pf/pfvar.h index 0574fc4740..662aba0036 100644 --- a/sys/net/pf/pfvar.h +++ b/sys/net/pf/pfvar.h @@ -66,6 +66,7 @@ struct ip; struct ip6_hdr; extern struct lwkt_token pf_token; +extern struct lwkt_token pf_gtoken; #define PF_TCPS_PROXY_SRC ((TCP_NSTATES)+0) #define PF_TCPS_PROXY_DST ((TCP_NSTATES)+1) @@ -838,12 +839,15 @@ struct pf_state { u_int8_t state_flags; #define PFSTATE_ALLOWOPTS 0x01 #define PFSTATE_SLOPPY 0x02 +#define PFSTATE_STACK_GLOBAL 0x04 /* pf_state_key[1] is global */ +#define PFSTATE_CREATEINPROG 0x08 /* prevent find from finding it */ u_int8_t timeout; u_int8_t sync_flags; u_int8_t pickup_mode; #define PFSTATE_NOSYNC 0x01 #define PFSTATE_FROMSYNC 0x02 #define PFSTATE_STALE 0x04 + struct lock lk; }; /* @@ -1138,7 +1142,7 @@ TAILQ_HEAD(pfi_statehead, pfi_kif); RB_HEAD(pfi_ifhead, pfi_kif); /* state tables */ -extern struct pf_state_tree pf_statetbl[MAXCPU]; +extern struct pf_state_tree pf_statetbl[MAXCPU+1]; /* keep synced with pfi_kif, used in RB_FIND */ struct pfi_kif_cmp { @@ -1224,6 +1228,7 @@ struct pf_pdesc { u_int8_t dir; /* direction */ u_int8_t sidx; /* key index for source */ u_int8_t didx; /* key index for destination */ + u_int8_t not_cpu_localized; /* translation not localized */ }; /* flags for RDR options */ @@ -1918,6 +1923,7 @@ void pf_qid_unref(u_int32_t); extern struct pf_status pf_status; extern struct malloc_type *pf_frent_pl, *pf_frag_pl; extern struct lock pf_consistency_lock; +extern struct lock pf_global_statetbl_lock; struct pf_pool_limit { void *pp; -- 2.41.0 From 1b9f04afb3e401a06af9b3160ab77baac68c0441 Mon Sep 17 00:00:00 2001 From: Sepherosa Ziehau Date: Sun, 29 Jun 2014 20:33:38 +0800 Subject: [PATCH 15/16] inpcb: Rework insertion of local group Mainly to take possible malloc(9) blocking into consideration. This prepares tokenizing inpcb lists and tables for udp. --- sys/netinet/in_pcb.c | 114 ++++++++++++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 38 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 122c4a87fa..1118d55ac4 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1650,23 +1650,17 @@ inp_localgroup_alloc(u_char vflag, return grp; } -static struct inp_localgroup * -inp_localgroup_create(struct inp_localgrphead *hdr, u_char vflag, - uint16_t port, const union in_dependaddr *addr, int size) +static void +inp_localgroup_free(struct inp_localgroup *grp) { - struct inp_localgroup *grp; - - grp = inp_localgroup_alloc(vflag, port, addr, size); - LIST_INSERT_HEAD(hdr, grp, il_list); - - return grp; + kfree(grp, M_TEMP); } static void inp_localgroup_destroy(struct inp_localgroup *grp) { LIST_REMOVE(grp, il_list); - kfree(grp, M_TEMP); + inp_localgroup_free(grp); } static void @@ -1684,20 +1678,6 @@ inp_localgroup_copy(struct inp_localgroup *grp, grp->il_factor = old_grp->il_factor; } -static struct inp_localgroup * -inp_localgroup_resize(struct inp_localgrphead *hdr, - struct inp_localgroup *old_grp, int size) -{ - struct inp_localgroup *grp; - - grp = inp_localgroup_create(hdr, old_grp->il_vflag, - old_grp->il_lport, &old_grp->il_dependladdr, size); - inp_localgroup_copy(grp, old_grp); - inp_localgroup_destroy(old_grp); - - return grp; -} - static void inp_localgroup_factor(struct inp_localgroup *grp) { @@ -1711,7 +1691,7 @@ static void in_pcbinslocalgrphash_oncpu(struct inpcb *inp, struct inpcbinfo *pcbinfo) { struct inp_localgrphead *hdr; - struct inp_localgroup *grp; + struct inp_localgroup *grp, *grp_alloc = NULL; struct ucred *cred; if (pcbinfo->localgrphashbase == NULL) @@ -1740,6 +1720,7 @@ in_pcbinslocalgrphash_oncpu(struct inpcb *inp, struct inpcbinfo *pcbinfo) hdr = &pcbinfo->localgrphashbase[ INP_PCBLOCALGRPHASH(inp->inp_lport, pcbinfo->localgrphashmask)]; +again: LIST_FOREACH(grp, hdr, il_list) { if (grp->il_vflag == inp->inp_vflag && grp->il_lport == inp->inp_lport && @@ -1750,10 +1731,26 @@ in_pcbinslocalgrphash_oncpu(struct inpcb *inp, struct inpcbinfo *pcbinfo) } } if (grp == NULL) { - /* Create new local group */ - grp = inp_localgroup_create(hdr, inp->inp_vflag, - inp->inp_lport, &inp->inp_inc.inc_ie.ie_dependladdr, - INP_LOCALGROUP_SIZMIN); + /* + * Create a new local group + */ + if (grp_alloc == NULL) { + grp_alloc = inp_localgroup_alloc(inp->inp_vflag, + inp->inp_lport, &inp->inp_inc.inc_ie.ie_dependladdr, + INP_LOCALGROUP_SIZMIN); + /* + * Local group allocation could block and the + * local group w/ the same property might have + * been added by others when we were blocked; + * check again. + */ + goto again; + } else { + /* Local group has been allocated; link it */ + grp = grp_alloc; + grp_alloc = NULL; + LIST_INSERT_HEAD(hdr, grp, il_list); + } } else if (grp->il_inpcnt == grp->il_inpsiz) { if (grp->il_inpsiz >= INP_LOCALGROUP_SIZMAX) { static int limit_logged = 0; @@ -1763,11 +1760,59 @@ in_pcbinslocalgrphash_oncpu(struct inpcb *inp, struct inpcbinfo *pcbinfo) kprintf("local group port %d, " "limit reached\n", ntohs(grp->il_lport)); } + if (grp_alloc != NULL) { + /* + * This would happen if the local group + * w/ the same property was expanded when + * our local group allocation blocked. + */ + inp_localgroup_free(grp_alloc); + } return; } - /* Expand this local group */ - grp = inp_localgroup_resize(hdr, grp, grp->il_inpsiz * 2); + /* + * Expand this local group + */ + if (grp_alloc == NULL || + grp->il_inpcnt >= grp_alloc->il_inpsiz) { + if (grp_alloc != NULL) + inp_localgroup_free(grp_alloc); + grp_alloc = inp_localgroup_alloc(grp->il_vflag, + grp->il_lport, &grp->il_dependladdr, + grp->il_inpsiz * 2); + /* + * Local group allocation could block and the + * local group w/ the same property might have + * been expanded by others when we were blocked; + * check again. + */ + goto again; + } + + /* + * Save the old local group, link the new one, and then + * destroy the old local group + */ + inp_localgroup_copy(grp_alloc, grp); + LIST_INSERT_HEAD(hdr, grp_alloc, il_list); + inp_localgroup_destroy(grp); + + grp = grp_alloc; + grp_alloc = NULL; + } else { + /* + * Found the local group + */ + if (grp_alloc != NULL) { + /* + * This would happen if the local group w/ the + * same property was added or expanded when our + * local group allocation blocked. + */ + inp_localgroup_free(grp_alloc); + grp_alloc = NULL; + } } KASSERT(grp->il_inpcnt < grp->il_inpsiz, @@ -1839,13 +1884,6 @@ in_pcbremlocalgrphash_oncpu(struct inpcb *inp, struct inpcbinfo *pcbinfo) grp->il_inp[i] = grp->il_inp[i + 1]; grp->il_inpcnt--; inp_localgroup_factor(grp); - - if (grp->il_inpsiz > INP_LOCALGROUP_SIZMIN && - grp->il_inpcnt <= (grp->il_inpsiz / 4)) { - /* Shrink this local group */ - grp = inp_localgroup_resize(hdr, grp, - grp->il_inpsiz / 2); - } } return; } -- 2.41.0 From 56e2aaa4d1de560d06f713866ab834747982f839 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sun, 29 Jun 2014 16:57:33 +0200 Subject: [PATCH 16/16] Fix buildworld. Due to adding a struct lock to struct pf_state in one of the recent pf(4) commits, we have to define _KERNEL_STRUCTURES in everything which includes pfvar.h. --- contrib/libpcap/gencode.c | 3 +++ contrib/libpcap/grammar.y | 3 +++ contrib/tcpdump/print-pflog.c | 2 ++ sys/net/pf/pf_ruleset.c | 2 +- usr.bin/systat/pftop.c | 2 ++ usr.sbin/authpf/authpf.c | 1 + usr.sbin/ftp-proxy/filter.c | 1 + usr.sbin/ftp-proxy/ftp-proxy.c | 1 + usr.sbin/pfctl/parse.y | 1 + usr.sbin/pfctl/pf_print_state.c | 2 +- usr.sbin/pfctl/pfctl.c | 2 +- usr.sbin/pfctl/pfctl_altq.c | 1 + usr.sbin/pfctl/pfctl_optimize.c | 1 + usr.sbin/pfctl/pfctl_osfp.c | 1 + usr.sbin/pfctl/pfctl_qstats.c | 1 + usr.sbin/pfctl/pfctl_radix.c | 2 +- usr.sbin/pfctl/pfctl_table.c | 2 +- 17 files changed, 23 insertions(+), 5 deletions(-) diff --git a/contrib/libpcap/gencode.c b/contrib/libpcap/gencode.c index ca4c2726fa..79e2913db0 100644 --- a/contrib/libpcap/gencode.c +++ b/contrib/libpcap/gencode.c @@ -24,6 +24,8 @@ static const char rcsid[] _U_ = "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.309 2008-12-23 20:13:29 guy Exp $ (LBL)"; #endif +#define _KERNEL_STRUCTURES + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -92,6 +94,7 @@ static const char rcsid[] _U_ = #ifdef HAVE_NET_PFVAR_H #include #include +#include #include #include #endif diff --git a/contrib/libpcap/grammar.y b/contrib/libpcap/grammar.y index ac3f1bbcfd..1e3102296e 100644 --- a/contrib/libpcap/grammar.y +++ b/contrib/libpcap/grammar.y @@ -25,6 +25,8 @@ static const char rcsid[] _U_ = "@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.101 2007-11-18 02:03:52 guy Exp $ (LBL)"; #endif +#define _KERNEL_STRUCTURES + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -55,6 +57,7 @@ struct rtentry; #include "gencode.h" #ifdef HAVE_NET_PFVAR_H #include +#include #include #include #endif diff --git a/contrib/tcpdump/print-pflog.c b/contrib/tcpdump/print-pflog.c index ed569729ff..d0d8f6b0cc 100644 --- a/contrib/tcpdump/print-pflog.c +++ b/contrib/tcpdump/print-pflog.c @@ -24,6 +24,8 @@ static const char rcsid[] _U_ = "@(#) $Header: /tcpdump/master/tcpdump/print-pflog.c,v 1.16 2007-09-12 19:36:18 guy Exp $ (LBL)"; #endif +#define _KERNEL_STRUCTURES + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/sys/net/pf/pf_ruleset.c b/sys/net/pf/pf_ruleset.c index 49b9675c1c..ba076e914d 100644 --- a/sys/net/pf/pf_ruleset.c +++ b/sys/net/pf/pf_ruleset.c @@ -32,9 +32,9 @@ * Effort sponsored in part by the Defense Advanced Research Projects * Agency (DARPA) and Air Force Research Laboratory, Air Force * Materiel Command, USAF, under agreement number F30602-01-2-0537. - * */ +#define _KERNEL_STRUCTURES #include #include #ifdef _KERNEL diff --git a/usr.bin/systat/pftop.c b/usr.bin/systat/pftop.c index a4d22cc8cf..134e896c84 100644 --- a/usr.bin/systat/pftop.c +++ b/usr.bin/systat/pftop.c @@ -31,6 +31,8 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ + +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/authpf/authpf.c b/usr.sbin/authpf/authpf.c index 423d094879..4b11aad789 100644 --- a/usr.sbin/authpf/authpf.c +++ b/usr.sbin/authpf/authpf.c @@ -18,6 +18,7 @@ * $FreeBSD: head/contrib/pf/authpf/authpf.c 223637 2011-06-28 11:57:25Z bz $ */ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/ftp-proxy/filter.c b/usr.sbin/ftp-proxy/filter.c index 71cae84e09..1ca8f66f22 100644 --- a/usr.sbin/ftp-proxy/filter.c +++ b/usr.sbin/ftp-proxy/filter.c @@ -16,6 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/ftp-proxy/ftp-proxy.c b/usr.sbin/ftp-proxy/ftp-proxy.c index a6ccf35c12..95b758cb6e 100644 --- a/usr.sbin/ftp-proxy/ftp-proxy.c +++ b/usr.sbin/ftp-proxy/ftp-proxy.c @@ -16,6 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/pfctl/parse.y b/usr.sbin/pfctl/parse.y index 47cbc486ba..0e92a07fb4 100644 --- a/usr.sbin/pfctl/parse.y +++ b/usr.sbin/pfctl/parse.y @@ -27,6 +27,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ %{ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/pfctl/pf_print_state.c b/usr.sbin/pfctl/pf_print_state.c index d98d766179..b6915d4b5c 100644 --- a/usr.sbin/pfctl/pf_print_state.c +++ b/usr.sbin/pfctl/pf_print_state.c @@ -27,9 +27,9 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - * */ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/pfctl/pfctl.c b/usr.sbin/pfctl/pfctl.c index 37fa0b1de6..52bee282f9 100644 --- a/usr.sbin/pfctl/pfctl.c +++ b/usr.sbin/pfctl/pfctl.c @@ -28,9 +28,9 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - * */ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/pfctl/pfctl_altq.c b/usr.sbin/pfctl/pfctl_altq.c index de21e33055..e368bc492a 100644 --- a/usr.sbin/pfctl/pfctl_altq.c +++ b/usr.sbin/pfctl/pfctl_altq.c @@ -18,6 +18,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/pfctl/pfctl_optimize.c b/usr.sbin/pfctl/pfctl_optimize.c index b5e488728e..f3825cd2d3 100644 --- a/usr.sbin/pfctl/pfctl_optimize.c +++ b/usr.sbin/pfctl/pfctl_optimize.c @@ -16,6 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/pfctl/pfctl_osfp.c b/usr.sbin/pfctl/pfctl_osfp.c index 4e4f20349c..731efe5d93 100644 --- a/usr.sbin/pfctl/pfctl_osfp.c +++ b/usr.sbin/pfctl/pfctl_osfp.c @@ -16,6 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/pfctl/pfctl_qstats.c b/usr.sbin/pfctl/pfctl_qstats.c index 4a22c2fee8..f59ca46ebb 100644 --- a/usr.sbin/pfctl/pfctl_qstats.c +++ b/usr.sbin/pfctl/pfctl_qstats.c @@ -16,6 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/pfctl/pfctl_radix.c b/usr.sbin/pfctl/pfctl_radix.c index 9a50c18bbb..bf4aae50dd 100644 --- a/usr.sbin/pfctl/pfctl_radix.c +++ b/usr.sbin/pfctl/pfctl_radix.c @@ -27,9 +27,9 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - * */ +#define _KERNEL_STRUCTURES #include #include #include diff --git a/usr.sbin/pfctl/pfctl_table.c b/usr.sbin/pfctl/pfctl_table.c index 52821ed17e..9dfb8b252a 100644 --- a/usr.sbin/pfctl/pfctl_table.c +++ b/usr.sbin/pfctl/pfctl_table.c @@ -27,9 +27,9 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - * */ +#define _KERNEL_STRUCTURES #include #include #include -- 2.41.0