Browse Source

Initial commit.

coderain 7 years ago
commit
6556847b55
100 changed files with 38981 additions and 0 deletions
  1. 12 0
      .gitignore
  2. 661 0
      COPYING
  3. 22 0
      Makefile
  4. 42 0
      README
  5. 3 0
      grub.cfg
  6. 10 0
      kernel/.gitignore
  7. 88 0
      kernel/Makefile
  8. 226 0
      kernel/include/acpica/acapps.h
  9. 255 0
      kernel/include/acpica/acbuffer.h
  10. 167 0
      kernel/include/acpica/acclib.h
  11. 67 0
      kernel/include/acpica/accommon.h
  12. 252 0
      kernel/include/acpica/acconfig.h
  13. 498 0
      kernel/include/acpica/acdebug.h
  14. 1091 0
      kernel/include/acpica/acdisasm.h
  15. 474 0
      kernel/include/acpica/acdispat.h
  16. 366 0
      kernel/include/acpica/acevents.h
  17. 354 0
      kernel/include/acpica/acexcep.h
  18. 405 0
      kernel/include/acpica/acglobal.h
  19. 227 0
      kernel/include/acpica/achware.h
  20. 756 0
      kernel/include/acpica/acinterp.h
  21. 1438 0
      kernel/include/acpica/aclocal.h
  22. 423 0
      kernel/include/acpica/acmacros.h
  23. 92 0
      kernel/include/acpica/acnames.h
  24. 555 0
      kernel/include/acpica/acnamesp.h
  25. 591 0
      kernel/include/acpica/acobject.h
  26. 331 0
      kernel/include/acpica/acopcode.h
  27. 496 0
      kernel/include/acpica/acoutput.h
  28. 364 0
      kernel/include/acpica/acparser.h
  29. 67 0
      kernel/include/acpica/acpi.h
  30. 613 0
      kernel/include/acpica/acpiosxf.h
  31. 1258 0
      kernel/include/acpica/acpixf.h
  32. 1119 0
      kernel/include/acpica/acpredef.h
  33. 442 0
      kernel/include/acpica/acresrc.h
  34. 714 0
      kernel/include/acpica/acrestyp.h
  35. 269 0
      kernel/include/acpica/acstruct.h
  36. 261 0
      kernel/include/acpica/actables.h
  37. 452 0
      kernel/include/acpica/actbl.h
  38. 1420 0
      kernel/include/acpica/actbl1.h
  39. 1692 0
      kernel/include/acpica/actbl2.h
  40. 894 0
      kernel/include/acpica/actbl3.h
  41. 1404 0
      kernel/include/acpica/actypes.h
  42. 1086 0
      kernel/include/acpica/acutils.h
  43. 90 0
      kernel/include/acpica/acuuid.h
  44. 514 0
      kernel/include/acpica/amlcode.h
  45. 631 0
      kernel/include/acpica/amlresrc.h
  46. 347 0
      kernel/include/acpica/platform/acenv.h
  47. 58 0
      kernel/include/acpica/platform/acenvex.h
  48. 82 0
      kernel/include/acpica/platform/acgcc.h
  49. 17 0
      kernel/include/acpica/platform/acmnlth.h
  50. 40 0
      kernel/include/avl_tree.h
  51. 94 0
      kernel/include/block_device.h
  52. 63 0
      kernel/include/boot/multiboot.h
  53. 59 0
      kernel/include/cache.h
  54. 75 0
      kernel/include/char_device.h
  55. 58 0
      kernel/include/clock.h
  56. 248 0
      kernel/include/common.h
  57. 65 0
      kernel/include/cpu.h
  58. 77 0
      kernel/include/exception.h
  59. 60 0
      kernel/include/exec/aout.h
  60. 144 0
      kernel/include/filesystem.h
  61. 65 0
      kernel/include/heap.h
  62. 80 0
      kernel/include/interrupt.h
  63. 53 0
      kernel/include/irq.h
  64. 45 0
      kernel/include/isa_dma.h
  65. 299 0
      kernel/include/list.h
  66. 228 0
      kernel/include/memory.h
  67. 70 0
      kernel/include/object.h
  68. 118 0
      kernel/include/pci.h
  69. 49 0
      kernel/include/pipe.h
  70. 35 0
      kernel/include/power.h
  71. 108 0
      kernel/include/process.h
  72. 87 0
      kernel/include/segments.h
  73. 55 0
      kernel/include/sync.h
  74. 113 0
      kernel/include/syscalls.h
  75. 155 0
      kernel/include/thread.h
  76. 38 0
      kernel/include/timer.h
  77. 123 0
      kernel/include/user.h
  78. 160 0
      kernel/include/video.h
  79. 60 0
      kernel/include/vm86.h
  80. 31 0
      kernel/link.ld
  81. 438 0
      kernel/src/acpica/dispatcher/dsargs.c
  82. 417 0
      kernel/src/acpica/dispatcher/dscontrol.c
  83. 250 0
      kernel/src/acpica/dispatcher/dsdebug.c
  84. 839 0
      kernel/src/acpica/dispatcher/dsfield.c
  85. 280 0
      kernel/src/acpica/dispatcher/dsinit.c
  86. 907 0
      kernel/src/acpica/dispatcher/dsmethod.c
  87. 777 0
      kernel/src/acpica/dispatcher/dsmthdat.c
  88. 864 0
      kernel/src/acpica/dispatcher/dsobject.c
  89. 817 0
      kernel/src/acpica/dispatcher/dsopcode.c
  90. 945 0
      kernel/src/acpica/dispatcher/dsutils.c
  91. 789 0
      kernel/src/acpica/dispatcher/dswexec.c
  92. 593 0
      kernel/src/acpica/dispatcher/dswload.c
  93. 757 0
      kernel/src/acpica/dispatcher/dswload2.c
  94. 236 0
      kernel/src/acpica/dispatcher/dswscope.c
  95. 842 0
      kernel/src/acpica/dispatcher/dswstate.c
  96. 336 0
      kernel/src/acpica/events/evevent.c
  97. 379 0
      kernel/src/acpica/events/evglock.c
  98. 843 0
      kernel/src/acpica/events/evgpe.c
  99. 555 0
      kernel/src/acpica/events/evgpeblk.c
  100. 466 0
      kernel/src/acpica/events/evgpeinit.c

+ 12 - 0
.gitignore

@@ -0,0 +1,12 @@
+*
+
+# Include the following files:
+!.gitignore
+!COPYING
+!README
+!grub.cfg
+!Makefile
+!kernel
+!kernel/*
+!library
+!library/*

+ 661 - 0
COPYING

@@ -0,0 +1,661 @@
+                    GNU AFFERO GENERAL PUBLIC LICENSE
+                       Version 3, 19 November 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU Affero General Public License is a free, copyleft license for
+software and other kinds of works, specifically designed to ensure
+cooperation with the community in the case of network server software.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+our General Public Licenses are intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  Developers that use our General Public Licenses protect your rights
+with two steps: (1) assert copyright on the software, and (2) offer
+you this License which gives you legal permission to copy, distribute
+and/or modify the software.
+
+  A secondary benefit of defending all users' freedom is that
+improvements made in alternate versions of the program, if they
+receive widespread use, become available for other developers to
+incorporate.  Many developers of free software are heartened and
+encouraged by the resulting cooperation.  However, in the case of
+software used on network servers, this result may fail to come about.
+The GNU General Public License permits making a modified version and
+letting the public access it on a server without ever releasing its
+source code to the public.
+
+  The GNU Affero General Public License is designed specifically to
+ensure that, in such cases, the modified source code becomes available
+to the community.  It requires the operator of a network server to
+provide the source code of the modified version running there to the
+users of that server.  Therefore, public use of a modified version, on
+a publicly accessible server, gives the public access to the source
+code of the modified version.
+
+  An older license, called the Affero General Public License and
+published by Affero, was designed to accomplish similar goals.  This is
+a different license, not a version of the Affero GPL, but Affero has
+released a new version of the Affero GPL which permits relicensing under
+this license.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU Affero General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Remote Network Interaction; Use with the GNU General Public License.
+
+  Notwithstanding any other provision of this License, if you modify the
+Program, your modified version must prominently offer all users
+interacting with it remotely through a computer network (if your version
+supports such interaction) an opportunity to receive the Corresponding
+Source of your version by providing access to the Corresponding Source
+from a network server at no charge, through some standard or customary
+means of facilitating copying of software.  This Corresponding Source
+shall include the Corresponding Source for any work covered by version 3
+of the GNU General Public License that is incorporated pursuant to the
+following paragraph.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the work with which it is combined will remain governed by version
+3 of the GNU General Public License.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU Affero General Public License from time to time.  Such new versions
+will be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU Affero General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU Affero General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU Affero General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If your software can interact with users remotely through a computer
+network, you should also make sure that it provides a way for users to
+get its source.  For example, if your program is a web application, its
+interface could display a "Source" link that leads users to an archive
+of the code.  There are many ways you could offer source, and different
+solutions will be better for different programs; see section 13 for the
+specific requirements.
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU AGPL, see
+<http://www.gnu.org/licenses/>.

+ 22 - 0
Makefile

@@ -0,0 +1,22 @@
+.PHONY: all clean kernel library
+
+all: livecd.iso
+
+kernel:
+	$(MAKE) -C kernel all
+
+library: kernel
+	$(MAKE) -C library all
+
+livecd.iso: kernel library
+	mkdir -p livecd
+	mkdir -p livecd/boot
+	cp kernel/monolithium livecd/boot/monolithium
+	mkdir -p livecd/boot/grub
+	cp grub.cfg livecd/boot/grub/grub.cfg
+	grub-mkrescue -o $@ livecd
+
+clean:
+	$(MAKE) -C kernel clean
+	$(MAKE) -C library clean
+	rm livecd.iso

+ 42 - 0
README

@@ -0,0 +1,42 @@
+********************************************************************************
+              __  ___                  ___ __  __    _               
+             /  |/  /___  ____  ____  / (_) /_/ /_  (_)_  ______ ___ 
+            / /|_/ / __ \/ __ \/ __ \/ / / __/ __ \/ / / / / __ `__ \
+           / /  / / /_/ / / / / /_/ / / / /_/ / / / / /_/ / / / / / /
+          /_/  /_/\____/_/ /_/\____/_/_/\__/_/ /_/_/\__,_/_/ /_/ /_/ 
+
+********************************************************************************
+
+Monolithium is a 32-bit operating system for x86 PCs. It is not a Unix-like
+system, and shares almost nothing with the Unix architecture. Written
+completely from scratch, it is completely incompatible with other operating
+systems. Currently, only the Monolithium kernel is implemented. The other major
+components, the "system library" and "system manager", are still missing.
+
+Monolithium wasn't implemented according to any existing design, it was more or
+less designed as it was implemented, so the current interface may not be
+consistent. During this phase of its development, its kernel module interface
+and application programming interface are not stable and subject to major
+changes.
+
+FREQUENTLY ASKED QUESTIONS
+
+1) Why write another OS from scratch?
+
+Most software development today is focused on assembling software from existing
+"building blocks", using libraries and high-level programming languages, which
+are designed to be complex and generic because they need to cover a lot of use
+cases. Simplicity is a very useful trait that is often overlooked. Monolithium
+is one of the few operating system projects with simplicity as its primary goal.
+
+2) Why is there no development history?
+
+I started this project in 2011, before I understood how VCS systems work and why
+they're important. I made backups at regular intervals, but since I didn't use
+git, there are no commits before the first release.
+
+3) Will the interface ever become stable?
+
+Having a stable interface, which will not change to the extent that later
+versions break software running in userspace, is one of the end goals of
+the project.

+ 3 - 0
grub.cfg

@@ -0,0 +1,3 @@
+menuentry "Monolithium OS" {
+    multiboot /boot/monolithium manager:Floppy0/MANAGER
+}

+ 10 - 0
kernel/.gitignore

@@ -0,0 +1,10 @@
+*
+
+# Include the following files:
+!.gitignore
+!Makefile
+!link.ld
+!include
+!include/**
+!src
+!src/**

+ 88 - 0
kernel/Makefile

@@ -0,0 +1,88 @@
+#
+# Makefile
+#
+# Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# Settings
+DEBUG  = yes
+ACPICA = yes
+
+# Compilers and tools
+CC = i686-elf-gcc
+ASM = nasm
+LINK = i686-elf-ld
+
+# Directories
+SRCDIR = src
+OBJDIR = obj
+DEPDIR = dep
+
+LIBGCC_DIR = $(shell $(CC) -print-file-name=)
+
+# Flags
+CFLAGS = -Wall -Werror -Wno-strict-aliasing -ffreestanding -nostdlib -I include
+ASMFLAGS = -felf
+LDFLAGS = -T link.ld -L $(LIBGCC_DIR) -lgcc
+
+ifeq ($(DEBUG), yes)
+    CFLAGS += -g
+else
+    CFLAGS += -O3
+endif
+
+# Input and output files
+SOURCES =  $(wildcard $(SRCDIR)/*.c)
+SOURCES += $(wildcard $(SRCDIR)/exec/*.c)
+SOURCES += $(shell find $(SRCDIR)/drivers -type f -name \*.c)
+SOURCES += $(wildcard $(SRCDIR)/*.asm)
+
+ifeq ($(ACPICA), yes)
+    CFLAGS += -I include/acpica -D ACPICA
+    SOURCES += $(shell find $(SRCDIR)/acpica -type f -name \*.c)
+endif
+
+DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
+OBJECTS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%.o, $(SOURCES)))
+
+.PHONY: all clean
+
+all: $(OBJDIR) $(DEPDIR) monolithium
+
+clean:
+	find $(OBJDIR) -name \*.o -delete
+	find $(DEPDIR) -name \*.d -delete
+	rm monolithium
+
+-include $(DEPENDS)
+
+$(OBJDIR):
+	mkdir -p $(OBJDIR)
+
+$(DEPDIR):
+	mkdir -p $(DEPDIR)
+
+$(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
+	mkdir -p $(dir $@)
+	mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
+	$(CC) $(CFLAGS) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) -o $@ -c $<
+
+$(OBJDIR)/%.o: $(SRCDIR)/%.asm
+	mkdir -p $(dir $@)
+	$(ASM) $(ASMFLAGS) -o $@ $<
+
+monolithium: $(OBJDIR)/boot/boot.o $(OBJECTS)
+	$(LINK) -o $@ $(OBJECTS) $(LDFLAGS)

+ 226 - 0
kernel/include/acpica/acapps.h

@@ -0,0 +1,226 @@
+/******************************************************************************
+ *
+ * Module Name: acapps - common include for ACPI applications/tools
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 _ACAPPS
+#define _ACAPPS
+
+#include <stdio.h>
+
+#ifdef _MSC_VER                 /* disable some level-4 warnings */
+#pragma warning(disable:4100)   /* warning C4100: unreferenced formal parameter */
+#endif
+
+/* Common info for tool signons */
+
+#define ACPICA_NAME                 "Intel ACPI Component Architecture"
+#define ACPICA_COPYRIGHT            "Copyright (c) 2000 - 2015 Intel Corporation"
+
+#if ACPI_MACHINE_WIDTH == 64
+#define ACPI_WIDTH          "-64"
+
+#elif ACPI_MACHINE_WIDTH == 32
+#define ACPI_WIDTH          "-32"
+
+#else
+#error unknown ACPI_MACHINE_WIDTH
+#define ACPI_WIDTH          "-??"
+
+#endif
+
+/* Macros for signons and file headers */
+
+#define ACPI_COMMON_SIGNON(UtilityName) \
+    "\n%s\n%s version %8.8X%s\n%s\n\n", \
+    ACPICA_NAME, \
+    UtilityName, ((UINT32) ACPI_CA_VERSION), ACPI_WIDTH, \
+    ACPICA_COPYRIGHT
+
+#define ACPI_COMMON_HEADER(UtilityName, Prefix) \
+    "%s%s\n%s%s version %8.8X%s\n%s%s\n%s\n", \
+    Prefix, ACPICA_NAME, \
+    Prefix, UtilityName, ((UINT32) ACPI_CA_VERSION), ACPI_WIDTH, \
+    Prefix, ACPICA_COPYRIGHT, \
+    Prefix
+
+/* Macros for usage messages */
+
+#define ACPI_USAGE_HEADER(Usage) \
+    AcpiOsPrintf ("Usage: %s\nOptions:\n", Usage);
+
+#define ACPI_USAGE_TEXT(Description) \
+    AcpiOsPrintf (Description);
+
+#define ACPI_OPTION(Name, Description) \
+    AcpiOsPrintf ("  %-20s%s\n", Name, Description);
+
+
+/* Check for unexpected exceptions */
+
+#define ACPI_CHECK_STATUS(Name, Status, Expected) \
+    if (Status != Expected) \
+    { \
+        AcpiOsPrintf ("Unexpected %s from %s (%s-%d)\n", \
+            AcpiFormatException (Status), #Name, _AcpiModuleName, __LINE__); \
+    }
+
+/* Check for unexpected non-AE_OK errors */
+
+
+#define ACPI_CHECK_OK(Name, Status)   ACPI_CHECK_STATUS (Name, Status, AE_OK);
+
+#define FILE_SUFFIX_DISASSEMBLY     "dsl"
+#define FILE_SUFFIX_BINARY_TABLE    ".dat" /* Needs the dot */
+
+
+/* acfileio */
+
+ACPI_STATUS
+AcGetAllTablesFromFile (
+    char                    *Filename,
+    UINT8                   GetOnlyAmlTables,
+    ACPI_NEW_TABLE_DESC     **ReturnListHead);
+
+BOOLEAN
+AcIsFileBinary (
+    FILE                    *File);
+
+ACPI_STATUS
+AcValidateTableHeader (
+    FILE                    *File,
+    long                    TableOffset);
+
+
+/* Values for GetOnlyAmlTables */
+
+#define ACPI_GET_ONLY_AML_TABLES    TRUE
+#define ACPI_GET_ALL_TABLES         FALSE
+
+
+/*
+ * getopt
+ */
+int
+AcpiGetopt(
+    int                     argc,
+    char                    **argv,
+    char                    *opts);
+
+int
+AcpiGetoptArgument (
+    int                     argc,
+    char                    **argv);
+
+extern int                  AcpiGbl_Optind;
+extern int                  AcpiGbl_Opterr;
+extern int                  AcpiGbl_SubOptChar;
+extern char                 *AcpiGbl_Optarg;
+
+
+/*
+ * cmfsize - Common get file size function
+ */
+UINT32
+CmGetFileSize (
+    ACPI_FILE               File);
+
+
+/*
+ * adwalk
+ */
+void
+AcpiDmCrossReferenceNamespace (
+    ACPI_PARSE_OBJECT       *ParseTreeRoot,
+    ACPI_NAMESPACE_NODE     *NamespaceRoot,
+    ACPI_OWNER_ID           OwnerId);
+
+void
+AcpiDmDumpTree (
+    ACPI_PARSE_OBJECT       *Origin);
+
+void
+AcpiDmFindOrphanMethods (
+    ACPI_PARSE_OBJECT       *Origin);
+
+void
+AcpiDmFinishNamespaceLoad (
+    ACPI_PARSE_OBJECT       *ParseTreeRoot,
+    ACPI_NAMESPACE_NODE     *NamespaceRoot,
+    ACPI_OWNER_ID           OwnerId);
+
+void
+AcpiDmConvertResourceIndexes (
+    ACPI_PARSE_OBJECT       *ParseTreeRoot,
+    ACPI_NAMESPACE_NODE     *NamespaceRoot);
+
+
+/*
+ * adfile
+ */
+ACPI_STATUS
+AdInitialize (
+    void);
+
+char *
+FlGenerateFilename (
+    char                    *InputFilename,
+    char                    *Suffix);
+
+ACPI_STATUS
+FlSplitInputPathname (
+    char                    *InputPath,
+    char                    **OutDirectoryPath,
+    char                    **OutFilename);
+
+char *
+AdGenerateFilename (
+    char                    *Prefix,
+    char                    *TableId);
+
+void
+AdWriteTable (
+    ACPI_TABLE_HEADER       *Table,
+    UINT32                  Length,
+    char                    *TableName,
+    char                    *OemTableId);
+
+#endif /* _ACAPPS */

+ 255 - 0
kernel/include/acpica/acbuffer.h

@@ -0,0 +1,255 @@
+/******************************************************************************
+ *
+ * Name: acbuffer.h - Support for buffers returned by ACPI predefined names
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACBUFFER_H__
+#define __ACBUFFER_H__
+
+/*
+ * Contains buffer structures for these predefined names:
+ * _FDE, _GRT, _GTM, _PLD, _SRT
+ */
+
+/*
+ * Note: C bitfields are not used for this reason:
+ *
+ * "Bitfields are great and easy to read, but unfortunately the C language
+ * does not specify the layout of bitfields in memory, which means they are
+ * essentially useless for dealing with packed data in on-disk formats or
+ * binary wire protocols." (Or ACPI tables and buffers.) "If you ask me,
+ * this decision was a design error in C. Ritchie could have picked an order
+ * and stuck with it." Norman Ramsey.
+ * See http://stackoverflow.com/a/1053662/41661
+ */
+
+
+/* _FDE return value */
+
+typedef struct acpi_fde_info
+{
+    UINT32              Floppy0;
+    UINT32              Floppy1;
+    UINT32              Floppy2;
+    UINT32              Floppy3;
+    UINT32              Tape;
+
+} ACPI_FDE_INFO;
+
+/*
+ * _GRT return value
+ * _SRT input value
+ */
+typedef struct acpi_grt_info
+{
+    UINT16              Year;
+    UINT8               Month;
+    UINT8               Day;
+    UINT8               Hour;
+    UINT8               Minute;
+    UINT8               Second;
+    UINT8               Valid;
+    UINT16              Milliseconds;
+    UINT16              Timezone;
+    UINT8               Daylight;
+    UINT8               Reserved[3];
+
+} ACPI_GRT_INFO;
+
+/* _GTM return value */
+
+typedef struct acpi_gtm_info
+{
+    UINT32              PioSpeed0;
+    UINT32              DmaSpeed0;
+    UINT32              PioSpeed1;
+    UINT32              DmaSpeed1;
+    UINT32              Flags;
+
+} ACPI_GTM_INFO;
+
+/*
+ * Formatted _PLD return value. The minimum size is a package containing
+ * one buffer.
+ * Revision 1: Buffer is 16 bytes (128 bits)
+ * Revision 2: Buffer is 20 bytes (160 bits)
+ *
+ * Note: This structure is returned from the AcpiDecodePldBuffer
+ * interface.
+ */
+typedef struct acpi_pld_info
+{
+    UINT8               Revision;
+    UINT8               IgnoreColor;
+    UINT8               Red;
+    UINT8               Green;
+    UINT8               Blue;
+    UINT16              Width;
+    UINT16              Height;
+    UINT8               UserVisible;
+    UINT8               Dock;
+    UINT8               Lid;
+    UINT8               Panel;
+    UINT8               VerticalPosition;
+    UINT8               HorizontalPosition;
+    UINT8               Shape;
+    UINT8               GroupOrientation;
+    UINT8               GroupToken;
+    UINT8               GroupPosition;
+    UINT8               Bay;
+    UINT8               Ejectable;
+    UINT8               OspmEjectRequired;
+    UINT8               CabinetNumber;
+    UINT8               CardCageNumber;
+    UINT8               Reference;
+    UINT8               Rotation;
+    UINT8               Order;
+    UINT8               Reserved;
+    UINT16              VerticalOffset;
+    UINT16              HorizontalOffset;
+
+} ACPI_PLD_INFO;
+
+
+/*
+ * Macros to:
+ *     1) Convert a _PLD buffer to internal ACPI_PLD_INFO format - ACPI_PLD_GET*
+ *        (Used by AcpiDecodePldBuffer)
+ *     2) Construct a _PLD buffer - ACPI_PLD_SET*
+ *        (Intended for BIOS use only)
+ */
+#define ACPI_PLD_REV1_BUFFER_SIZE               16 /* For Revision 1 of the buffer (From ACPI spec) */
+#define ACPI_PLD_REV2_BUFFER_SIZE               20 /* For Revision 2 of the buffer (From ACPI spec) */
+#define ACPI_PLD_BUFFER_SIZE                    20 /* For Revision 2 of the buffer (From ACPI spec) */
+
+/* First 32-bit dword, bits 0:32 */
+
+#define ACPI_PLD_GET_REVISION(dword)            ACPI_GET_BITS (dword, 0, ACPI_7BIT_MASK)
+#define ACPI_PLD_SET_REVISION(dword,value)      ACPI_SET_BITS (dword, 0, ACPI_7BIT_MASK, value)     /* Offset 0, Len 7 */
+
+#define ACPI_PLD_GET_IGNORE_COLOR(dword)        ACPI_GET_BITS (dword, 7, ACPI_1BIT_MASK)
+#define ACPI_PLD_SET_IGNORE_COLOR(dword,value)  ACPI_SET_BITS (dword, 7, ACPI_1BIT_MASK, value)     /* Offset 7, Len 1 */
+
+#define ACPI_PLD_GET_RED(dword)                 ACPI_GET_BITS (dword, 8, ACPI_8BIT_MASK)
+#define ACPI_PLD_SET_RED(dword,value)           ACPI_SET_BITS (dword, 8, ACPI_8BIT_MASK, value)    /* Offset 8, Len 8 */
+
+#define ACPI_PLD_GET_GREEN(dword)               ACPI_GET_BITS (dword, 16, ACPI_8BIT_MASK)
+#define ACPI_PLD_SET_GREEN(dword,value)         ACPI_SET_BITS (dword, 16, ACPI_8BIT_MASK, value)    /* Offset 16, Len 8 */
+
+#define ACPI_PLD_GET_BLUE(dword)                ACPI_GET_BITS (dword, 24, ACPI_8BIT_MASK)
+#define ACPI_PLD_SET_BLUE(dword,value)          ACPI_SET_BITS (dword, 24, ACPI_8BIT_MASK, value)    /* Offset 24, Len 8 */
+
+/* Second 32-bit dword, bits 33:63 */
+
+#define ACPI_PLD_GET_WIDTH(dword)               ACPI_GET_BITS (dword, 0, ACPI_16BIT_MASK)
+#define ACPI_PLD_SET_WIDTH(dword,value)         ACPI_SET_BITS (dword, 0, ACPI_16BIT_MASK, value)    /* Offset 32+0=32, Len 16 */
+
+#define ACPI_PLD_GET_HEIGHT(dword)              ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
+#define ACPI_PLD_SET_HEIGHT(dword,value)        ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)   /* Offset 32+16=48, Len 16 */
+
+/* Third 32-bit dword, bits 64:95 */
+
+#define ACPI_PLD_GET_USER_VISIBLE(dword)        ACPI_GET_BITS (dword, 0, ACPI_1BIT_MASK)
+#define ACPI_PLD_SET_USER_VISIBLE(dword,value)  ACPI_SET_BITS (dword, 0, ACPI_1BIT_MASK, value)     /* Offset 64+0=64, Len 1 */
+
+#define ACPI_PLD_GET_DOCK(dword)                ACPI_GET_BITS (dword, 1, ACPI_1BIT_MASK)
+#define ACPI_PLD_SET_DOCK(dword,value)          ACPI_SET_BITS (dword, 1, ACPI_1BIT_MASK, value)     /* Offset 64+1=65, Len 1 */
+
+#define ACPI_PLD_GET_LID(dword)                 ACPI_GET_BITS (dword, 2, ACPI_1BIT_MASK)
+#define ACPI_PLD_SET_LID(dword,value)           ACPI_SET_BITS (dword, 2, ACPI_1BIT_MASK, value)     /* Offset 64+2=66, Len 1 */
+
+#define ACPI_PLD_GET_PANEL(dword)               ACPI_GET_BITS (dword, 3, ACPI_3BIT_MASK)
+#define ACPI_PLD_SET_PANEL(dword,value)         ACPI_SET_BITS (dword, 3, ACPI_3BIT_MASK, value)     /* Offset 64+3=67, Len 3 */
+
+#define ACPI_PLD_GET_VERTICAL(dword)            ACPI_GET_BITS (dword, 6, ACPI_2BIT_MASK)
+#define ACPI_PLD_SET_VERTICAL(dword,value)      ACPI_SET_BITS (dword, 6, ACPI_2BIT_MASK, value)     /* Offset 64+6=70, Len 2 */
+
+#define ACPI_PLD_GET_HORIZONTAL(dword)          ACPI_GET_BITS (dword, 8, ACPI_2BIT_MASK)
+#define ACPI_PLD_SET_HORIZONTAL(dword,value)    ACPI_SET_BITS (dword, 8, ACPI_2BIT_MASK, value)     /* Offset 64+8=72, Len 2 */
+
+#define ACPI_PLD_GET_SHAPE(dword)               ACPI_GET_BITS (dword, 10, ACPI_4BIT_MASK)
+#define ACPI_PLD_SET_SHAPE(dword,value)         ACPI_SET_BITS (dword, 10, ACPI_4BIT_MASK, value)    /* Offset 64+10=74, Len 4 */
+
+#define ACPI_PLD_GET_ORIENTATION(dword)         ACPI_GET_BITS (dword, 14, ACPI_1BIT_MASK)
+#define ACPI_PLD_SET_ORIENTATION(dword,value)   ACPI_SET_BITS (dword, 14, ACPI_1BIT_MASK, value)    /* Offset 64+14=78, Len 1 */
+
+#define ACPI_PLD_GET_TOKEN(dword)               ACPI_GET_BITS (dword, 15, ACPI_8BIT_MASK)
+#define ACPI_PLD_SET_TOKEN(dword,value)         ACPI_SET_BITS (dword, 15, ACPI_8BIT_MASK, value)    /* Offset 64+15=79, Len 8 */
+
+#define ACPI_PLD_GET_POSITION(dword)            ACPI_GET_BITS (dword, 23, ACPI_8BIT_MASK)
+#define ACPI_PLD_SET_POSITION(dword,value)      ACPI_SET_BITS (dword, 23, ACPI_8BIT_MASK, value)    /* Offset 64+23=87, Len 8 */
+
+#define ACPI_PLD_GET_BAY(dword)                 ACPI_GET_BITS (dword, 31, ACPI_1BIT_MASK)
+#define ACPI_PLD_SET_BAY(dword,value)           ACPI_SET_BITS (dword, 31, ACPI_1BIT_MASK, value)    /* Offset 64+31=95, Len 1 */
+
+/* Fourth 32-bit dword, bits 96:127 */
+
+#define ACPI_PLD_GET_EJECTABLE(dword)           ACPI_GET_BITS (dword, 0, ACPI_1BIT_MASK)
+#define ACPI_PLD_SET_EJECTABLE(dword,value)     ACPI_SET_BITS (dword, 0, ACPI_1BIT_MASK, value)     /* Offset 96+0=96, Len 1 */
+
+#define ACPI_PLD_GET_OSPM_EJECT(dword)          ACPI_GET_BITS (dword, 1, ACPI_1BIT_MASK)
+#define ACPI_PLD_SET_OSPM_EJECT(dword,value)    ACPI_SET_BITS (dword, 1, ACPI_1BIT_MASK, value)     /* Offset 96+1=97, Len 1 */
+
+#define ACPI_PLD_GET_CABINET(dword)             ACPI_GET_BITS (dword, 2, ACPI_8BIT_MASK)
+#define ACPI_PLD_SET_CABINET(dword,value)       ACPI_SET_BITS (dword, 2, ACPI_8BIT_MASK, value)     /* Offset 96+2=98, Len 8 */
+
+#define ACPI_PLD_GET_CARD_CAGE(dword)           ACPI_GET_BITS (dword, 10, ACPI_8BIT_MASK)
+#define ACPI_PLD_SET_CARD_CAGE(dword,value)     ACPI_SET_BITS (dword, 10, ACPI_8BIT_MASK, value)    /* Offset 96+10=106, Len 8 */
+
+#define ACPI_PLD_GET_REFERENCE(dword)           ACPI_GET_BITS (dword, 18, ACPI_1BIT_MASK)
+#define ACPI_PLD_SET_REFERENCE(dword,value)     ACPI_SET_BITS (dword, 18, ACPI_1BIT_MASK, value)    /* Offset 96+18=114, Len 1 */
+
+#define ACPI_PLD_GET_ROTATION(dword)            ACPI_GET_BITS (dword, 19, ACPI_4BIT_MASK)
+#define ACPI_PLD_SET_ROTATION(dword,value)      ACPI_SET_BITS (dword, 19, ACPI_4BIT_MASK, value)    /* Offset 96+19=115, Len 4 */
+
+#define ACPI_PLD_GET_ORDER(dword)               ACPI_GET_BITS (dword, 23, ACPI_5BIT_MASK)
+#define ACPI_PLD_SET_ORDER(dword,value)         ACPI_SET_BITS (dword, 23, ACPI_5BIT_MASK, value)    /* Offset 96+23=119, Len 5 */
+
+/* Fifth 32-bit dword, bits 128:159 (Revision 2 of _PLD only) */
+
+#define ACPI_PLD_GET_VERT_OFFSET(dword)         ACPI_GET_BITS (dword, 0, ACPI_16BIT_MASK)
+#define ACPI_PLD_SET_VERT_OFFSET(dword,value)   ACPI_SET_BITS (dword, 0, ACPI_16BIT_MASK, value)    /* Offset 128+0=128, Len 16 */
+
+#define ACPI_PLD_GET_HORIZ_OFFSET(dword)        ACPI_GET_BITS (dword, 16, ACPI_16BIT_MASK)
+#define ACPI_PLD_SET_HORIZ_OFFSET(dword,value)  ACPI_SET_BITS (dword, 16, ACPI_16BIT_MASK, value)   /* Offset 128+16=144, Len 16 */
+
+
+#endif /* ACBUFFER_H */

+ 167 - 0
kernel/include/acpica/acclib.h

@@ -0,0 +1,167 @@
+/******************************************************************************
+ *
+ * Name: acclib.h -- C library support. Prototypes for the (optional) local
+ *                   implementations of required C library functions.
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 _ACCLIB_H
+#define _ACCLIB_H
+
+
+/*
+ * Prototypes and macros for local implementations of C library functions
+ */
+
+/* is* functions. The AcpiGbl_Ctypes array is defined in utclib.c */
+
+extern const UINT8 AcpiGbl_Ctypes[];
+
+#define _ACPI_XA     0x00    /* extra alphabetic - not supported */
+#define _ACPI_XS     0x40    /* extra space */
+#define _ACPI_BB     0x00    /* BEL, BS, etc. - not supported */
+#define _ACPI_CN     0x20    /* CR, FF, HT, NL, VT */
+#define _ACPI_DI     0x04    /* '0'-'9' */
+#define _ACPI_LO     0x02    /* 'a'-'z' */
+#define _ACPI_PU     0x10    /* punctuation */
+#define _ACPI_SP     0x08    /* space, tab, CR, LF, VT, FF */
+#define _ACPI_UP     0x01    /* 'A'-'Z' */
+#define _ACPI_XD     0x80    /* '0'-'9', 'A'-'F', 'a'-'f' */
+
+#define isdigit(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_DI))
+#define isspace(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_SP))
+#define isxdigit(c) (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_XD))
+#define isupper(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_UP))
+#define islower(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO))
+#define isprint(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP | _ACPI_DI | _ACPI_XS | _ACPI_PU))
+#define isalpha(c)  (AcpiGbl_Ctypes[(unsigned char)(c)] & (_ACPI_LO | _ACPI_UP))
+
+
+/* Strings */
+
+char *
+strcat (
+    char                    *DstString,
+    const char              *SrcString);
+
+char *
+strchr (
+    const char              *String,
+    int                     ch);
+
+char *
+strcpy (
+    char                    *DstString,
+    const char              *SrcString);
+
+int
+strcmp (
+    const char              *String1,
+    const char              *String2);
+
+ACPI_SIZE
+strlen (
+    const char              *String);
+
+char *
+strncat (
+    char                    *DstString,
+    const char              *SrcString,
+    ACPI_SIZE               Count);
+
+int
+strncmp (
+    const char              *String1,
+    const char              *String2,
+    ACPI_SIZE               Count);
+
+char *
+strncpy (
+    char                    *DstString,
+    const char              *SrcString,
+    ACPI_SIZE               Count);
+
+char *
+strstr (
+    char                    *String1,
+    char                    *String2);
+
+
+/* Conversion */
+
+UINT32
+strtoul (
+    const char              *String,
+    char                    **Terminator,
+    UINT32                  Base);
+
+
+/* Memory */
+
+int
+memcmp (
+    void                    *Buffer1,
+    void                    *Buffer2,
+    ACPI_SIZE               Count);
+
+void *
+memcpy (
+    void                    *Dest,
+    const void              *Src,
+    ACPI_SIZE               Count);
+
+void *
+memset (
+    void                    *Dest,
+    int                     Value,
+    ACPI_SIZE               Count);
+
+
+/* upper/lower case */
+
+int
+tolower (
+    int                     c);
+
+int
+toupper (
+    int                     c);
+
+#endif /* _ACCLIB_H */

+ 67 - 0
kernel/include/acpica/accommon.h

@@ -0,0 +1,67 @@
+/******************************************************************************
+ *
+ * Name: accommon.h - Common include files for generation of ACPICA source
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACCOMMON_H__
+#define __ACCOMMON_H__
+
+/*
+ * Common set of includes for all ACPICA source files.
+ * We put them here because we don't want to duplicate them
+ * in the the source code again and again.
+ *
+ * Note: The order of these include files is important.
+ */
+#include "acconfig.h"           /* Global configuration constants */
+#include "acmacros.h"           /* C macros */
+#include "aclocal.h"            /* Internal data types */
+#include "acobject.h"           /* ACPI internal object */
+#include "acstruct.h"           /* Common structures */
+#include "acglobal.h"           /* All global variables */
+#include "achware.h"            /* Hardware defines and interfaces */
+#include "acutils.h"            /* Utility interfaces */
+#ifndef ACPI_USE_SYSTEM_CLIBRARY
+#include "acclib.h"             /* C library interfaces */
+#endif /* !ACPI_USE_SYSTEM_CLIBRARY */
+
+
+#endif /* __ACCOMMON_H__ */

+ 252 - 0
kernel/include/acpica/acconfig.h

@@ -0,0 +1,252 @@
+/******************************************************************************
+ *
+ * Name: acconfig.h - Global configuration constants
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 _ACCONFIG_H
+#define _ACCONFIG_H
+
+
+/******************************************************************************
+ *
+ * Configuration options
+ *
+ *****************************************************************************/
+
+/*
+ * ACPI_DEBUG_OUTPUT    - This switch enables all the debug facilities of the
+ *                        ACPI subsystem. This includes the DEBUG_PRINT output
+ *                        statements. When disabled, all DEBUG_PRINT
+ *                        statements are compiled out.
+ *
+ * ACPI_APPLICATION     - Use this switch if the subsystem is going to be run
+ *                        at the application level.
+ *
+ */
+
+/*
+ * OS name, used for the _OS object. The _OS object is essentially obsolete,
+ * but there is a large base of ASL/AML code in existing machines that check
+ * for the string below. The use of this string usually guarantees that
+ * the ASL will execute down the most tested code path. Also, there is some
+ * code that will not execute the _OSI method unless _OS matches the string
+ * below. Therefore, change this string at your own risk.
+ */
+#define ACPI_OS_NAME                    "Microsoft Windows NT"
+
+/* Maximum objects in the various object caches */
+
+#define ACPI_MAX_STATE_CACHE_DEPTH      96          /* State objects */
+#define ACPI_MAX_PARSE_CACHE_DEPTH      96          /* Parse tree objects */
+#define ACPI_MAX_EXTPARSE_CACHE_DEPTH   96          /* Parse tree objects */
+#define ACPI_MAX_OBJECT_CACHE_DEPTH     96          /* Interpreter operand objects */
+#define ACPI_MAX_NAMESPACE_CACHE_DEPTH  96          /* Namespace objects */
+
+/*
+ * Should the subsystem abort the loading of an ACPI table if the
+ * table checksum is incorrect?
+ */
+#ifndef ACPI_CHECKSUM_ABORT
+#define ACPI_CHECKSUM_ABORT             FALSE
+#endif
+
+/*
+ * Generate a version of ACPICA that only supports "reduced hardware"
+ * platforms (as defined in ACPI 5.0). Set to TRUE to generate a specialized
+ * version of ACPICA that ONLY supports the ACPI 5.0 "reduced hardware"
+ * model. In other words, no ACPI hardware is supported.
+ *
+ * If TRUE, this means no support for the following:
+ *      PM Event and Control registers
+ *      SCI interrupt (and handler)
+ *      Fixed Events
+ *      General Purpose Events (GPEs)
+ *      Global Lock
+ *      ACPI PM timer
+ *      FACS table (Waking vectors and Global Lock)
+ */
+#ifndef ACPI_REDUCED_HARDWARE
+#define ACPI_REDUCED_HARDWARE           FALSE
+#endif
+
+
+/******************************************************************************
+ *
+ * Subsystem Constants
+ *
+ *****************************************************************************/
+
+/* Version of ACPI supported */
+
+#define ACPI_CA_SUPPORT_LEVEL           5
+
+/* Maximum count for a semaphore object */
+
+#define ACPI_MAX_SEMAPHORE_COUNT        256
+
+/* Maximum object reference count (detects object deletion issues) */
+
+#define ACPI_MAX_REFERENCE_COUNT        0x800
+
+/* Default page size for use in mapping memory for operation regions */
+
+#define ACPI_DEFAULT_PAGE_SIZE          4096    /* Must be power of 2 */
+
+/* OwnerId tracking. 8 entries allows for 255 OwnerIds */
+
+#define ACPI_NUM_OWNERID_MASKS          8
+
+/* Size of the root table array is increased by this increment */
+
+#define ACPI_ROOT_TABLE_SIZE_INCREMENT  4
+
+/* Maximum sleep allowed via Sleep() operator */
+
+#define ACPI_MAX_SLEEP                  2000    /* 2000 millisec == two seconds */
+
+/* Address Range lists are per-SpaceId (Memory and I/O only) */
+
+#define ACPI_ADDRESS_RANGE_MAX          2
+
+
+/******************************************************************************
+ *
+ * ACPI Specification constants (Do not change unless the specification changes)
+ *
+ *****************************************************************************/
+
+/* Method info (in WALK_STATE), containing local variables and argumetns */
+
+#define ACPI_METHOD_NUM_LOCALS          8
+#define ACPI_METHOD_MAX_LOCAL           7
+
+#define ACPI_METHOD_NUM_ARGS            7
+#define ACPI_METHOD_MAX_ARG             6
+
+/*
+ * Operand Stack (in WALK_STATE), Must be large enough to contain METHOD_MAX_ARG
+ */
+#define ACPI_OBJ_NUM_OPERANDS           8
+#define ACPI_OBJ_MAX_OPERAND            7
+
+/* Number of elements in the Result Stack frame, can be an arbitrary value */
+
+#define ACPI_RESULTS_FRAME_OBJ_NUM      8
+
+/*
+ * Maximal number of elements the Result Stack can contain,
+ * it may be an arbitray value not exceeding the types of
+ * ResultSize and ResultCount (now UINT8).
+ */
+#define ACPI_RESULTS_OBJ_NUM_MAX        255
+
+/* Constants used in searching for the RSDP in low memory */
+
+#define ACPI_EBDA_PTR_LOCATION          0x0000040E     /* Physical Address */
+#define ACPI_EBDA_PTR_LENGTH            2
+#define ACPI_EBDA_WINDOW_SIZE           1024
+#define ACPI_HI_RSDP_WINDOW_BASE        0x000E0000     /* Physical Address */
+#define ACPI_HI_RSDP_WINDOW_SIZE        0x00020000
+#define ACPI_RSDP_SCAN_STEP             16
+
+/* Operation regions */
+
+#define ACPI_USER_REGION_BEGIN          0x80
+
+/* Maximum SpaceIds for Operation Regions */
+
+#define ACPI_MAX_ADDRESS_SPACE          255
+#define ACPI_NUM_DEFAULT_SPACES         4
+
+/* Array sizes. Used for range checking also */
+
+#define ACPI_MAX_MATCH_OPCODE           5
+
+/* RSDP checksums */
+
+#define ACPI_RSDP_CHECKSUM_LENGTH       20
+#define ACPI_RSDP_XCHECKSUM_LENGTH      36
+
+/* SMBus, GSBus and IPMI bidirectional buffer size */
+
+#define ACPI_SMBUS_BUFFER_SIZE          34
+#define ACPI_GSBUS_BUFFER_SIZE          34
+#define ACPI_IPMI_BUFFER_SIZE           66
+
+/* _SxD and _SxW control methods */
+
+#define ACPI_NUM_SxD_METHODS            4
+#define ACPI_NUM_SxW_METHODS            5
+
+
+/******************************************************************************
+ *
+ * Miscellaneous constants
+ *
+ *****************************************************************************/
+
+/* UUID constants */
+
+#define UUID_BUFFER_LENGTH          16 /* Length of UUID in memory */
+#define UUID_STRING_LENGTH          36 /* Total length of a UUID string */
+
+/* Positions for required hyphens (dashes) in UUID strings */
+
+#define UUID_HYPHEN1_OFFSET         8
+#define UUID_HYPHEN2_OFFSET         13
+#define UUID_HYPHEN3_OFFSET         18
+#define UUID_HYPHEN4_OFFSET         23
+
+
+/******************************************************************************
+ *
+ * ACPI AML Debugger
+ *
+ *****************************************************************************/
+
+#define ACPI_DEBUGGER_MAX_ARGS          ACPI_METHOD_NUM_ARGS + 4 /* Max command line arguments */
+#define ACPI_DB_LINE_BUFFER_SIZE        512
+
+#define ACPI_DEBUGGER_COMMAND_PROMPT    '-'
+#define ACPI_DEBUGGER_EXECUTE_PROMPT    '%'
+
+
+#endif /* _ACCONFIG_H */

+ 498 - 0
kernel/include/acpica/acdebug.h

@@ -0,0 +1,498 @@
+/******************************************************************************
+ *
+ * Name: acdebug.h - ACPI/AML debugger
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACDEBUG_H__
+#define __ACDEBUG_H__
+
+/* The debugger is used in conjunction with the disassembler most of time */
+
+#ifdef ACPI_DISASSEMBLER
+#include "acdisasm.h"
+#endif
+
+
+#define ACPI_DEBUG_BUFFER_SIZE  0x4000      /* 16K buffer for return objects */
+
+typedef struct acpi_db_command_info
+{
+    char                    *Name;          /* Command Name */
+    UINT8                   MinArgs;        /* Minimum arguments required */
+
+} ACPI_DB_COMMAND_INFO;
+
+typedef struct acpi_db_command_help
+{
+    UINT8                   LineCount;      /* Number of help lines */
+    char                    *Invocation;    /* Command Invocation */
+    char                    *Description;   /* Command Description */
+
+} ACPI_DB_COMMAND_HELP;
+
+typedef struct acpi_db_argument_info
+{
+    char                    *Name;          /* Argument Name */
+
+} ACPI_DB_ARGUMENT_INFO;
+
+typedef struct acpi_db_execute_walk
+{
+    UINT32                  Count;
+    UINT32                  MaxCount;
+
+} ACPI_DB_EXECUTE_WALK;
+
+
+#define PARAM_LIST(pl)                  pl
+
+#define EX_NO_SINGLE_STEP               1
+#define EX_SINGLE_STEP                  2
+
+
+/*
+ * dbxface - external debugger interfaces
+ */
+ACPI_DBR_DEPENDENT_RETURN_OK (
+ACPI_STATUS
+AcpiDbSingleStep (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    UINT32                  OpType))
+
+ACPI_DBR_DEPENDENT_RETURN_VOID (
+void
+AcpiDbSignalBreakPoint (
+    ACPI_WALK_STATE         *WalkState))
+
+
+/*
+ * dbcmds - debug commands and output routines
+ */
+ACPI_NAMESPACE_NODE *
+AcpiDbConvertToNode (
+    char                    *InString);
+
+void
+AcpiDbDisplayTableInfo (
+    char                    *TableArg);
+
+void
+AcpiDbDisplayTemplate (
+    char                    *BufferArg);
+
+void
+AcpiDbUnloadAcpiTable (
+    char                    *Name);
+
+void
+AcpiDbSendNotify (
+    char                    *Name,
+    UINT32                  Value);
+
+void
+AcpiDbDisplayInterfaces (
+    char                    *ActionArg,
+    char                    *InterfaceNameArg);
+
+ACPI_STATUS
+AcpiDbSleep (
+    char                    *ObjectArg);
+
+void
+AcpiDbTrace (
+    char                    *EnableArg,
+    char                    *MethodArg,
+    char                    *OnceArg);
+
+void
+AcpiDbDisplayLocks (
+    void);
+
+void
+AcpiDbDisplayResources (
+    char                    *ObjectArg);
+
+ACPI_HW_DEPENDENT_RETURN_VOID (
+void
+AcpiDbDisplayGpes (
+    void))
+
+void
+AcpiDbDisplayHandlers (
+    void);
+
+ACPI_HW_DEPENDENT_RETURN_VOID (
+void
+AcpiDbGenerateGpe (
+    char                    *GpeArg,
+    char                    *BlockArg))
+
+ACPI_HW_DEPENDENT_RETURN_VOID (
+void
+AcpiDbGenerateSci (
+    void))
+
+void
+AcpiDbExecuteTest (
+    char                    *TypeArg);
+
+
+/*
+ * dbconvert - miscellaneous conversion routines
+ */
+ACPI_STATUS
+AcpiDbHexCharToValue (
+    int                     HexChar,
+    UINT8                   *ReturnValue);
+
+ACPI_STATUS
+AcpiDbConvertToPackage (
+    char                    *String,
+    ACPI_OBJECT             *Object);
+
+ACPI_STATUS
+AcpiDbConvertToObject (
+    ACPI_OBJECT_TYPE        Type,
+    char                    *String,
+    ACPI_OBJECT             *Object);
+
+UINT8 *
+AcpiDbEncodePldBuffer (
+    ACPI_PLD_INFO           *PldInfo);
+
+void
+AcpiDbDumpPldBuffer (
+    ACPI_OBJECT             *ObjDesc);
+
+
+/*
+ * dbmethod - control method commands
+ */
+void
+AcpiDbSetMethodBreakpoint (
+    char                    *Location,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDbSetMethodCallBreakpoint (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDbSetMethodData (
+    char                    *TypeArg,
+    char                    *IndexArg,
+    char                    *ValueArg);
+
+ACPI_STATUS
+AcpiDbDisassembleMethod (
+    char                    *Name);
+
+void
+AcpiDbDisassembleAml (
+    char                    *Statements,
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDbBatchExecute (
+    char                    *CountArg);
+
+
+/*
+ * dbnames - namespace commands
+ */
+void
+AcpiDbSetScope (
+    char                    *Name);
+
+void
+AcpiDbDumpNamespace (
+    char                    *StartArg,
+    char                    *DepthArg);
+
+void
+AcpiDbDumpNamespacePaths (
+    void);
+
+void
+AcpiDbDumpNamespaceByOwner (
+    char                    *OwnerArg,
+    char                    *DepthArg);
+
+ACPI_STATUS
+AcpiDbFindNameInNamespace (
+    char                    *NameArg);
+
+void
+AcpiDbCheckPredefinedNames (
+    void);
+
+ACPI_STATUS
+AcpiDbDisplayObjects (
+    char                    *ObjTypeArg,
+    char                    *DisplayCountArg);
+
+void
+AcpiDbCheckIntegrity (
+    void);
+
+void
+AcpiDbFindReferences (
+    char                    *ObjectArg);
+
+void
+AcpiDbGetBusInfo (
+    void);
+
+
+/*
+ * dbdisply - debug display commands
+ */
+void
+AcpiDbDisplayMethodInfo (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDbDecodeAndDisplayObject (
+    char                    *Target,
+    char                    *OutputType);
+
+ACPI_DBR_DEPENDENT_RETURN_VOID (
+void
+AcpiDbDisplayResultObject (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_WALK_STATE         *WalkState))
+
+ACPI_STATUS
+AcpiDbDisplayAllMethods (
+    char                    *DisplayCountArg);
+
+void
+AcpiDbDisplayArguments (
+    void);
+
+void
+AcpiDbDisplayLocals (
+    void);
+
+void
+AcpiDbDisplayResults (
+    void);
+
+void
+AcpiDbDisplayCallingTree (
+    void);
+
+void
+AcpiDbDisplayObjectType (
+    char                    *ObjectArg);
+
+ACPI_DBR_DEPENDENT_RETURN_VOID (
+void
+AcpiDbDisplayArgumentObject (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_WALK_STATE         *WalkState))
+
+
+/*
+ * dbexec - debugger control method execution
+ */
+void
+AcpiDbExecute (
+    char                    *Name,
+    char                    **Args,
+    ACPI_OBJECT_TYPE        *Types,
+    UINT32                  Flags);
+
+void
+AcpiDbCreateExecutionThreads (
+    char                    *NumThreadsArg,
+    char                    *NumLoopsArg,
+    char                    *MethodNameArg);
+
+void
+AcpiDbDeleteObjects (
+    UINT32                  Count,
+    ACPI_OBJECT             *Objects);
+
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+UINT32
+AcpiDbGetCacheInfo (
+    ACPI_MEMORY_LIST        *Cache);
+#endif
+
+
+/*
+ * dbfileio - Debugger file I/O commands
+ */
+ACPI_OBJECT_TYPE
+AcpiDbMatchArgument (
+    char                    *UserArgument,
+    ACPI_DB_ARGUMENT_INFO   *Arguments);
+
+void
+AcpiDbCloseDebugFile (
+    void);
+
+void
+AcpiDbOpenDebugFile (
+    char                    *Name);
+
+ACPI_STATUS
+AcpiDbLoadAcpiTable (
+    char                    *Filename);
+
+ACPI_STATUS
+AcpiDbLoadTables (
+    ACPI_NEW_TABLE_DESC     *ListHead);
+
+
+/*
+ * dbhistry - debugger HISTORY command
+ */
+void
+AcpiDbAddToHistory (
+    char                    *CommandLine);
+
+void
+AcpiDbDisplayHistory (
+    void);
+
+char *
+AcpiDbGetFromHistory (
+    char                    *CommandNumArg);
+
+char *
+AcpiDbGetHistoryByIndex (
+    UINT32                  CommanddNum);
+
+
+/*
+ * dbinput - user front-end to the AML debugger
+ */
+ACPI_STATUS
+AcpiDbCommandDispatch (
+    char                    *InputBuffer,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+void ACPI_SYSTEM_XFACE
+AcpiDbExecuteThread (
+    void                    *Context);
+
+ACPI_STATUS
+AcpiDbUserCommands (
+    char                    Prompt,
+    ACPI_PARSE_OBJECT       *Op);
+
+char *
+AcpiDbGetNextToken (
+    char                    *String,
+    char                    **Next,
+    ACPI_OBJECT_TYPE        *ReturnType);
+
+
+/*
+ * dbobject
+ */
+void
+AcpiDbDecodeInternalObject (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+void
+AcpiDbDisplayInternalObject (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiDbDecodeArguments (
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiDbDecodeLocals (
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiDbDumpMethodInfo (
+    ACPI_STATUS             Status,
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * dbstats - Generation and display of ACPI table statistics
+ */
+void
+AcpiDbGenerateStatistics (
+    ACPI_PARSE_OBJECT       *Root,
+    BOOLEAN                 IsMethod);
+
+ACPI_STATUS
+AcpiDbDisplayStatistics (
+    char                    *TypeArg);
+
+
+/*
+ * dbutils - AML debugger utilities
+ */
+void
+AcpiDbSetOutputDestination (
+    UINT32                  Where);
+
+void
+AcpiDbDumpExternalObject (
+    ACPI_OBJECT             *ObjDesc,
+    UINT32                  Level);
+
+void
+AcpiDbPrepNamestring (
+    char                    *Name);
+
+ACPI_NAMESPACE_NODE *
+AcpiDbLocalNsLookup (
+    char                    *Name);
+
+void
+AcpiDbUint32ToHexString (
+    UINT32                  Value,
+    char                    *Buffer);
+
+#endif  /* __ACDEBUG_H__ */

+ 1091 - 0
kernel/include/acpica/acdisasm.h

@@ -0,0 +1,1091 @@
+/******************************************************************************
+ *
+ * Name: acdisasm.h - AML disassembler
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACDISASM_H__
+#define __ACDISASM_H__
+
+#include "amlresrc.h"
+
+
+#define BLOCK_NONE              0
+#define BLOCK_PAREN             1
+#define BLOCK_BRACE             2
+#define BLOCK_COMMA_LIST        4
+#define ACPI_DEFAULT_RESNAME    *(UINT32 *) "__RD"
+
+/*
+ * Raw table data header. Used by disassembler and data table compiler.
+ * Do not change.
+ */
+#define ACPI_RAW_TABLE_DATA_HEADER      "Raw Table Data"
+
+
+typedef struct acpi_dmtable_info
+{
+    UINT8                       Opcode;
+    UINT16                      Offset;
+    char                        *Name;
+    UINT8                       Flags;
+
+} ACPI_DMTABLE_INFO;
+
+/* Values for Flags field above */
+
+#define DT_LENGTH                       0x01    /* Field is a subtable length */
+#define DT_FLAG                         0x02    /* Field is a flag value */
+#define DT_NON_ZERO                     0x04    /* Field must be non-zero */
+#define DT_OPTIONAL                     0x08    /* Field is optional */
+#define DT_DESCRIBES_OPTIONAL           0x10    /* Field describes an optional field (length, etc.) */
+#define DT_COUNT                        0x20    /* Currently not used */
+
+/*
+ * Values for Opcode above.
+ * Note: 0-7 must not change, they are used as a flag shift value. Other
+ * than those, new values can be added wherever appropriate.
+ */
+typedef enum
+{
+    /* Simple Data Types */
+
+    ACPI_DMT_FLAG0          = 0,
+    ACPI_DMT_FLAG1          = 1,
+    ACPI_DMT_FLAG2          = 2,
+    ACPI_DMT_FLAG3          = 3,
+    ACPI_DMT_FLAG4          = 4,
+    ACPI_DMT_FLAG5          = 5,
+    ACPI_DMT_FLAG6          = 6,
+    ACPI_DMT_FLAG7          = 7,
+    ACPI_DMT_FLAGS0,
+    ACPI_DMT_FLAGS1,
+    ACPI_DMT_FLAGS2,
+    ACPI_DMT_FLAGS4,
+    ACPI_DMT_UINT8,
+    ACPI_DMT_UINT16,
+    ACPI_DMT_UINT24,
+    ACPI_DMT_UINT32,
+    ACPI_DMT_UINT40,
+    ACPI_DMT_UINT48,
+    ACPI_DMT_UINT56,
+    ACPI_DMT_UINT64,
+    ACPI_DMT_BUF7,
+    ACPI_DMT_BUF10,
+    ACPI_DMT_BUF16,
+    ACPI_DMT_BUF128,
+    ACPI_DMT_SIG,
+    ACPI_DMT_STRING,
+    ACPI_DMT_NAME4,
+    ACPI_DMT_NAME6,
+    ACPI_DMT_NAME8,
+
+    /* Types that are decoded to strings and miscellaneous */
+
+    ACPI_DMT_ACCWIDTH,
+    ACPI_DMT_CHKSUM,
+    ACPI_DMT_GAS,
+    ACPI_DMT_SPACEID,
+    ACPI_DMT_UNICODE,
+    ACPI_DMT_UUID,
+
+    /* Types used only for the Data Table Compiler */
+
+    ACPI_DMT_BUFFER,
+    ACPI_DMT_RAW_BUFFER,  /* Large, multiple line buffer */
+    ACPI_DMT_DEVICE_PATH,
+    ACPI_DMT_LABEL,
+    ACPI_DMT_PCI_PATH,
+
+    /* Types that are specific to particular ACPI tables */
+
+    ACPI_DMT_ASF,
+    ACPI_DMT_DMAR,
+    ACPI_DMT_DMAR_SCOPE,
+    ACPI_DMT_EINJACT,
+    ACPI_DMT_EINJINST,
+    ACPI_DMT_ERSTACT,
+    ACPI_DMT_ERSTINST,
+    ACPI_DMT_FADTPM,
+    ACPI_DMT_GTDT,
+    ACPI_DMT_HEST,
+    ACPI_DMT_HESTNTFY,
+    ACPI_DMT_HESTNTYP,
+    ACPI_DMT_IORTMEM,
+    ACPI_DMT_IVRS,
+    ACPI_DMT_LPIT,
+    ACPI_DMT_MADT,
+    ACPI_DMT_NFIT,
+    ACPI_DMT_PCCT,
+    ACPI_DMT_PMTT,
+    ACPI_DMT_SLIC,
+    ACPI_DMT_SRAT,
+
+    /* Special opcodes */
+
+    ACPI_DMT_EXTRA_TEXT,
+    ACPI_DMT_EXIT
+
+} ACPI_ENTRY_TYPES;
+
+typedef
+void (*ACPI_DMTABLE_HANDLER) (
+    ACPI_TABLE_HEADER       *Table);
+
+typedef
+ACPI_STATUS (*ACPI_CMTABLE_HANDLER) (
+    void                    **PFieldList);
+
+typedef struct acpi_dmtable_data
+{
+    char                    *Signature;
+    ACPI_DMTABLE_INFO       *TableInfo;
+    ACPI_DMTABLE_HANDLER    TableHandler;
+    ACPI_CMTABLE_HANDLER    CmTableHandler;
+    const unsigned char     *Template;
+
+} ACPI_DMTABLE_DATA;
+
+
+typedef struct acpi_op_walk_info
+{
+    ACPI_WALK_STATE         *WalkState;
+    ACPI_PARSE_OBJECT       *MappingOp;
+    UINT8                   *PreviousAml;
+    UINT8                   *StartAml;
+    UINT32                  Level;
+    UINT32                  LastLevel;
+    UINT32                  Count;
+    UINT32                  BitOffset;
+    UINT32                  Flags;
+    UINT32                  AmlOffset;
+
+} ACPI_OP_WALK_INFO;
+
+/*
+ * TBD - another copy of this is in asltypes.h, fix
+ */
+#ifndef ASL_WALK_CALLBACK_DEFINED
+typedef
+ACPI_STATUS (*ASL_WALK_CALLBACK) (
+    ACPI_PARSE_OBJECT           *Op,
+    UINT32                      Level,
+    void                        *Context);
+#define ASL_WALK_CALLBACK_DEFINED
+#endif
+
+typedef
+void (*ACPI_RESOURCE_HANDLER) (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+typedef struct acpi_resource_tag
+{
+    UINT32                  BitIndex;
+    char                    *Tag;
+
+} ACPI_RESOURCE_TAG;
+
+/* Strings used for decoding flags to ASL keywords */
+
+extern const char               *AcpiGbl_WordDecode[];
+extern const char               *AcpiGbl_IrqDecode[];
+extern const char               *AcpiGbl_LockRule[];
+extern const char               *AcpiGbl_AccessTypes[];
+extern const char               *AcpiGbl_UpdateRules[];
+extern const char               *AcpiGbl_MatchOps[];
+
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoAsf0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoAsf1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoAsf1a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoAsf2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoAsf2a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoAsf3[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoAsf4[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoAsfHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoBoot[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoBert[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoBgrt[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoCpep[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoCpep0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoCsrt0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoCsrt1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoCsrt2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoCsrt2a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDbg2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDbg2Device[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDbg2Addr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDbg2Size[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDbg2Name[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDbg2OemData[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDbgp[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDmar[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDmarHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDmarScope[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDmar0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDmar1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDmar2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDmar3[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDmar4[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDrtm[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDrtm0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDrtm0a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDrtm1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDrtm1a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoDrtm2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoEcdt[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoEinj[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoEinj0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoErst[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoErst0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoFacs[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoFadt1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoFadt2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoFadt3[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoFadt5[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoFadt6[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoFpdt[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoFpdtHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoFpdt0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoFpdt1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoGas[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoGtdt[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoGtdtHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoGtdt0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoGtdt0a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoGtdt1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHeader[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHest[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHest0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHest1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHest2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHest6[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHest7[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHest8[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHest9[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHestNotify[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHestBank[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoHpet[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoLpitHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoLpit0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoLpit1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIort[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIort0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIort0a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIort1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIort1a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIort2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIort3[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIort3a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIort3b[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIort3c[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIortAcc[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIortHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIortMap[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIortPad[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIvrs[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIvrs0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIvrs1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIvrs4[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIvrs8a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIvrs8b[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIvrs8c[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoIvrsHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt3[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt4[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt5[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt6[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt7[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt8[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt9[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt10[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt11[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt12[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt13[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt14[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadt15[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMadtHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMcfg[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMcfg0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMchi[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMpst[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMpst0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMpst0A[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMpst0B[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMpst1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMpst2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMsct[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMsct0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMtmr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoMtmr0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfitHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit2a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit3[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit3a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit4[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit5[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit6[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoNfit6a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoPmtt[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoPmtt0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoPmtt1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoPmtt1a[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoPmtt2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoPmttHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoPcct[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoPcctHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoPcct0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoPcct1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoRsdp1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoRsdp2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoS3pt[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoS3ptHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoS3pt0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoS3pt1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSbst[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSlic[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSlit[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSpcr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSpmi[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSrat[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSratHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSrat0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSrat1[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSrat2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoSrat3[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoStao[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoStaoStr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoTcpaHdr[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoTcpaClient[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoTcpaServer[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoTpm2[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoUefi[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoVrtc[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoVrtc0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoWaet[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoWdat[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoWdat0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoWddt[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoWdrt[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoWpbt[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoWpbt0[];
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoXenv[];
+
+extern ACPI_DMTABLE_INFO        AcpiDmTableInfoGeneric[][2];
+
+/*
+ * dmtable and ahtable
+ */
+extern const ACPI_DMTABLE_DATA  AcpiDmTableData[];
+extern const AH_TABLE           AcpiSupportedTables[];
+
+UINT8
+AcpiDmGenerateChecksum (
+    void                    *Table,
+    UINT32                  Length,
+    UINT8                   OriginalChecksum);
+
+const ACPI_DMTABLE_DATA *
+AcpiDmGetTableData (
+    char                    *Signature);
+
+void
+AcpiDmDumpDataTable (
+    ACPI_TABLE_HEADER       *Table);
+
+ACPI_STATUS
+AcpiDmDumpTable (
+    UINT32                  TableLength,
+    UINT32                  TableOffset,
+    void                    *Table,
+    UINT32                  SubTableLength,
+    ACPI_DMTABLE_INFO        *Info);
+
+void
+AcpiDmLineHeader (
+    UINT32                  Offset,
+    UINT32                  ByteLength,
+    char                    *Name);
+
+void
+AcpiDmLineHeader2 (
+    UINT32                  Offset,
+    UINT32                  ByteLength,
+    char                    *Name,
+    UINT32                  Value);
+
+
+/*
+ * dmtbdump
+ */
+void
+AcpiDmDumpBuffer (
+    void                    *Table,
+    UINT32                  BufferOffset,
+    UINT32                  Length,
+    UINT32                  AbsoluteOffset,
+    char                    *Header);
+
+void
+AcpiDmDumpUnicode (
+    void                    *Table,
+    UINT32                  BufferOffset,
+    UINT32                  ByteLength);
+
+void
+AcpiDmDumpAsf (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpCpep (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpCsrt (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpDbg2 (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpDmar (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpDrtm (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpEinj (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpErst (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpFadt (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpFpdt (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpGtdt (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpHest (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpIort (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpIvrs (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpLpit (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpMadt (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpMcfg (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpMpst (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpMsct (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpMtmr (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpNfit (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpPcct (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpPmtt (
+    ACPI_TABLE_HEADER       *Table);
+
+UINT32
+AcpiDmDumpRsdp (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpRsdt (
+    ACPI_TABLE_HEADER       *Table);
+
+UINT32
+AcpiDmDumpS3pt (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpSlic (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpSlit (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpSrat (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpStao (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpTcpa (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpVrtc (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpWdat (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpWpbt (
+    ACPI_TABLE_HEADER       *Table);
+
+void
+AcpiDmDumpXsdt (
+    ACPI_TABLE_HEADER       *Table);
+
+
+/*
+ * dmwalk
+ */
+void
+AcpiDmDisassemble (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Origin,
+    UINT32                  NumOpcodes);
+
+void
+AcpiDmWalkParseTree (
+    ACPI_PARSE_OBJECT       *Op,
+    ASL_WALK_CALLBACK       DescendingCallback,
+    ASL_WALK_CALLBACK       AscendingCallback,
+    void                    *Context);
+
+
+/*
+ * dmopcode
+ */
+void
+AcpiDmDisassembleOneOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OP_WALK_INFO       *Info,
+    ACPI_PARSE_OBJECT       *Op);
+
+UINT32
+AcpiDmListType (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmMethodFlags (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmDisplayTargetPathname (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmNotifyDescription (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmPredefinedDescription (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmFieldPredefinedDescription (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmFieldFlags (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmAddressSpace (
+    UINT8                   SpaceId);
+
+void
+AcpiDmRegionFlags (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmMatchOp (
+    ACPI_PARSE_OBJECT       *Op);
+
+
+/*
+ * dmnames
+ */
+UINT32
+AcpiDmDumpName (
+    UINT32                  Name);
+
+ACPI_STATUS
+AcpiPsDisplayObjectPathname (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmNamestring (
+    char                    *Name);
+
+
+/*
+ * dmbuffer
+ */
+void
+AcpiDmDisasmByteList (
+    UINT32                  Level,
+    UINT8                   *ByteData,
+    UINT32                  ByteCount);
+
+void
+AcpiDmByteList (
+    ACPI_OP_WALK_INFO       *Info,
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmCheckForHardwareId (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmDecompressEisaId (
+    UINT32                  EncodedId);
+
+BOOLEAN
+AcpiDmIsUuidBuffer (
+    ACPI_PARSE_OBJECT       *Op);
+
+BOOLEAN
+AcpiDmIsUnicodeBuffer (
+    ACPI_PARSE_OBJECT       *Op);
+
+BOOLEAN
+AcpiDmIsStringBuffer (
+    ACPI_PARSE_OBJECT       *Op);
+
+BOOLEAN
+AcpiDmIsPldBuffer (
+    ACPI_PARSE_OBJECT       *Op);
+
+
+/*
+ * dmdeferred
+ */
+ACPI_STATUS
+AcpiDmParseDeferredOps (
+    ACPI_PARSE_OBJECT       *Root);
+
+
+/*
+ * dmextern
+ */
+ACPI_STATUS
+AcpiDmAddToExternalFileList (
+    char                    *PathList);
+
+void
+AcpiDmClearExternalFileList (
+    void);
+
+void
+AcpiDmAddOpToExternalList (
+    ACPI_PARSE_OBJECT       *Op,
+    char                    *Path,
+    UINT8                   Type,
+    UINT32                  Value,
+    UINT16                  Flags);
+
+void
+AcpiDmAddNodeToExternalList (
+    ACPI_NAMESPACE_NODE     *Node,
+    UINT8                   Type,
+    UINT32                  Value,
+    UINT16                  Flags);
+
+void
+AcpiDmAddExternalsToNamespace (
+    void);
+
+UINT32
+AcpiDmGetExternalMethodCount (
+    void);
+
+void
+AcpiDmClearExternalList (
+    void);
+
+void
+AcpiDmEmitExternals (
+    void);
+
+void
+AcpiDmUnresolvedWarning (
+    UINT8                   Type);
+
+void
+AcpiDmGetExternalsFromFile (
+    void);
+
+/*
+ * dmresrc
+ */
+void
+AcpiDmDumpInteger8 (
+    UINT8                   Value,
+    char                    *Name);
+
+void
+AcpiDmDumpInteger16 (
+    UINT16                  Value,
+    char                    *Name);
+
+void
+AcpiDmDumpInteger32 (
+    UINT32                  Value,
+    char                    *Name);
+
+void
+AcpiDmDumpInteger64 (
+    UINT64                  Value,
+    char                    *Name);
+
+void
+AcpiDmResourceTemplate (
+    ACPI_OP_WALK_INFO       *Info,
+    ACPI_PARSE_OBJECT       *Op,
+    UINT8                   *ByteData,
+    UINT32                  ByteCount);
+
+ACPI_STATUS
+AcpiDmIsResourceTemplate (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmBitList (
+    UINT16                  Mask);
+
+void
+AcpiDmDescriptorName (
+    void);
+
+
+/*
+ * dmresrcl
+ */
+void
+AcpiDmWordDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmDwordDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmExtendedDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmQwordDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmMemory24Descriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmMemory32Descriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmFixedMemory32Descriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmGenericRegisterDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmInterruptDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmVendorLargeDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmGpioDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmSerialBusDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmVendorCommon (
+    char                    *Name,
+    UINT8                   *ByteData,
+    UINT32                  Length,
+    UINT32                  Level);
+
+
+/*
+ * dmresrcs
+ */
+void
+AcpiDmIrqDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmDmaDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmFixedDmaDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmIoDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmFixedIoDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmStartDependentDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmEndDependentDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+void
+AcpiDmVendorSmallDescriptor (
+    ACPI_OP_WALK_INFO       *Info,
+    AML_RESOURCE            *Resource,
+    UINT32                  Length,
+    UINT32                  Level);
+
+
+/*
+ * dmutils
+ */
+void
+AcpiDmDecodeAttribute (
+    UINT8                   Attribute);
+
+void
+AcpiDmIndent (
+    UINT32                  Level);
+
+BOOLEAN
+AcpiDmCommaIfListMember (
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiDmCommaIfFieldMember (
+    ACPI_PARSE_OBJECT       *Op);
+
+
+/*
+ * dmrestag
+ */
+void
+AcpiDmFindResources (
+    ACPI_PARSE_OBJECT       *Root);
+
+void
+AcpiDmCheckResourceReference (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * dmcstyle
+ */
+BOOLEAN
+AcpiDmCheckForSymbolicOpcode (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_OP_WALK_INFO       *Info);
+
+void
+AcpiDmCloseOperator (
+    ACPI_PARSE_OBJECT       *Op);
+
+
+/*
+ * dmtables
+ */
+void
+AdDisassemblerHeader (
+    char                    *Filename,
+    UINT8                   TableType);
+
+#define ACPI_IS_AML_TABLE   0
+#define ACPI_IS_DATA_TABLE  1
+
+
+/*
+ * adisasm
+ */
+ACPI_STATUS
+AdAmlDisassemble (
+    BOOLEAN                 OutToFile,
+    char                    *Filename,
+    char                    *Prefix,
+    char                    **OutFilename);
+
+ACPI_STATUS
+AdGetLocalTables (
+    void);
+
+ACPI_STATUS
+AdParseTable (
+    ACPI_TABLE_HEADER       *Table,
+    ACPI_OWNER_ID           *OwnerId,
+    BOOLEAN                 LoadTable,
+    BOOLEAN                 External);
+
+ACPI_STATUS
+AdDisplayTables (
+    char                    *Filename,
+    ACPI_TABLE_HEADER       *Table);
+
+ACPI_STATUS
+AdDisplayStatistics (
+    void);
+
+#endif  /* __ACDISASM_H__ */

+ 474 - 0
kernel/include/acpica/acdispat.h

@@ -0,0 +1,474 @@
+/******************************************************************************
+ *
+ * Name: acdispat.h - dispatcher (parser to interpreter interface)
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 _ACDISPAT_H_
+#define _ACDISPAT_H_
+
+
+#define NAMEOF_LOCAL_NTE    "__L0"
+#define NAMEOF_ARG_NTE      "__A0"
+
+
+/*
+ * dsargs - execution of dynamic arguments for static objects
+ */
+ACPI_STATUS
+AcpiDsGetBufferFieldArguments (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiDsGetBankFieldArguments (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiDsGetRegionArguments (
+    ACPI_OPERAND_OBJECT     *RgnDesc);
+
+ACPI_STATUS
+AcpiDsGetBufferArguments (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiDsGetPackageArguments (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+
+/*
+ * dscontrol - support for execution control opcodes
+ */
+ACPI_STATUS
+AcpiDsExecBeginControlOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+ACPI_STATUS
+AcpiDsExecEndControlOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+
+/*
+ * dsopcode - support for late operand evaluation
+ */
+ACPI_STATUS
+AcpiDsEvalBufferFieldOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+ACPI_STATUS
+AcpiDsEvalRegionOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+ACPI_STATUS
+AcpiDsEvalTableRegionOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+ACPI_STATUS
+AcpiDsEvalDataObjectOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiDsEvalBankFieldOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+ACPI_STATUS
+AcpiDsInitializeRegion (
+    ACPI_HANDLE             ObjHandle);
+
+
+/*
+ * dsexec - Parser/Interpreter interface, method execution callbacks
+ */
+ACPI_STATUS
+AcpiDsGetPredicateValue (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OPERAND_OBJECT     *ResultObj);
+
+ACPI_STATUS
+AcpiDsExecBeginOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       **OutOp);
+
+ACPI_STATUS
+AcpiDsExecEndOp (
+    ACPI_WALK_STATE         *State);
+
+
+/*
+ * dsfield - Parser/Interpreter interface for AML fields
+ */
+ACPI_STATUS
+AcpiDsCreateField (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_NAMESPACE_NODE     *RegionNode,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsCreateBankField (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_NAMESPACE_NODE     *RegionNode,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsCreateIndexField (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_NAMESPACE_NODE     *RegionNode,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsCreateBufferField (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsInitFieldObjects (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * dsload - Parser/Interpreter interface
+ */
+ACPI_STATUS
+AcpiDsInitCallbacks (
+    ACPI_WALK_STATE         *WalkState,
+    UINT32                  PassNumber);
+
+/* dsload - pass 1 namespace load callbacks */
+
+ACPI_STATUS
+AcpiDsLoad1BeginOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       **OutOp);
+
+ACPI_STATUS
+AcpiDsLoad1EndOp (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/* dsload - pass 2 namespace load callbacks */
+
+ACPI_STATUS
+AcpiDsLoad2BeginOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       **OutOp);
+
+ACPI_STATUS
+AcpiDsLoad2EndOp (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * dsmthdat - method data (locals/args)
+ */
+ACPI_STATUS
+AcpiDsStoreObjectToLocal (
+    UINT8                   Type,
+    UINT32                  Index,
+    ACPI_OPERAND_OBJECT     *SrcDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsMethodDataGetEntry (
+    UINT16                  Opcode,
+    UINT32                  Index,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OPERAND_OBJECT     ***Node);
+
+void
+AcpiDsMethodDataDeleteAll (
+    ACPI_WALK_STATE         *WalkState);
+
+BOOLEAN
+AcpiDsIsMethodValue (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiDsMethodDataGetValue (
+    UINT8                   Type,
+    UINT32                  Index,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OPERAND_OBJECT     **DestDesc);
+
+ACPI_STATUS
+AcpiDsMethodDataInitArgs (
+    ACPI_OPERAND_OBJECT     **Params,
+    UINT32                  MaxParamCount,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsMethodDataGetNode (
+    UINT8                   Type,
+    UINT32                  Index,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_NAMESPACE_NODE     **Node);
+
+void
+AcpiDsMethodDataInit (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * dsmethod - Parser/Interpreter interface - control method parsing
+ */
+ACPI_STATUS
+AcpiDsAutoSerializeMethod (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiDsCallControlMethod (
+    ACPI_THREAD_STATE       *Thread,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+ACPI_STATUS
+AcpiDsRestartControlMethod (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OPERAND_OBJECT     *ReturnDesc);
+
+void
+AcpiDsTerminateControlMethod (
+    ACPI_OPERAND_OBJECT     *MethodDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsBeginMethodExecution (
+    ACPI_NAMESPACE_NODE     *MethodNode,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsMethodError (
+    ACPI_STATUS             Status,
+    ACPI_WALK_STATE         *WalkState);
+
+/*
+ * dsinit
+ */
+ACPI_STATUS
+AcpiDsInitializeObjects (
+    UINT32                  TableIndex,
+    ACPI_NAMESPACE_NODE     *StartNode);
+
+
+/*
+ * dsobject - Parser/Interpreter interface - object initialization and conversion
+ */
+ACPI_STATUS
+AcpiDsBuildInternalBufferObj (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    UINT32                  BufferLength,
+    ACPI_OPERAND_OBJECT     **ObjDescPtr);
+
+ACPI_STATUS
+AcpiDsBuildInternalPackageObj (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *op,
+    UINT32                  PackageLength,
+    ACPI_OPERAND_OBJECT     **ObjDesc);
+
+ACPI_STATUS
+AcpiDsInitObjectFromOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    UINT16                  Opcode,
+    ACPI_OPERAND_OBJECT     **ObjDesc);
+
+ACPI_STATUS
+AcpiDsCreateNode (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_PARSE_OBJECT       *Op);
+
+
+/*
+ * dsutils - Parser/Interpreter interface utility routines
+ */
+void
+AcpiDsClearImplicitReturn (
+    ACPI_WALK_STATE         *WalkState);
+
+BOOLEAN
+AcpiDsDoImplicitReturn (
+    ACPI_OPERAND_OBJECT     *ReturnDesc,
+    ACPI_WALK_STATE         *WalkState,
+    BOOLEAN                 AddReference);
+
+BOOLEAN
+AcpiDsIsResultUsed (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiDsDeleteResultIfNotUsed (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_OPERAND_OBJECT     *ResultObj,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsCreateOperand (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Arg,
+    UINT32                  ArgsRemaining);
+
+ACPI_STATUS
+AcpiDsCreateOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *FirstArg);
+
+ACPI_STATUS
+AcpiDsResolveOperands (
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiDsClearOperands (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsEvaluateNamePath (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * dswscope - Scope Stack manipulation
+ */
+ACPI_STATUS
+AcpiDsScopeStackPush (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_OBJECT_TYPE        Type,
+    ACPI_WALK_STATE         *WalkState);
+
+
+ACPI_STATUS
+AcpiDsScopeStackPop (
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiDsScopeStackClear (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * dswstate - parser WALK_STATE management routines
+ */
+ACPI_STATUS
+AcpiDsObjStackPush (
+    void                    *Object,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsObjStackPop (
+    UINT32                  PopCount,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_WALK_STATE *
+AcpiDsCreateWalkState (
+    ACPI_OWNER_ID           OwnerId,
+    ACPI_PARSE_OBJECT       *Origin,
+    ACPI_OPERAND_OBJECT     *MthDesc,
+    ACPI_THREAD_STATE       *Thread);
+
+ACPI_STATUS
+AcpiDsInitAmlWalk (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_NAMESPACE_NODE     *MethodNode,
+    UINT8                   *AmlStart,
+    UINT32                  AmlLength,
+    ACPI_EVALUATE_INFO      *Info,
+    UINT8                   PassNumber);
+
+void
+AcpiDsObjStackPopAndDelete (
+    UINT32                  PopCount,
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiDsDeleteWalkState (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_WALK_STATE *
+AcpiDsPopWalkState (
+    ACPI_THREAD_STATE       *Thread);
+
+void
+AcpiDsPushWalkState (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_THREAD_STATE       *Thread);
+
+ACPI_STATUS
+AcpiDsResultStackClear (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_WALK_STATE *
+AcpiDsGetCurrentWalkState (
+    ACPI_THREAD_STATE       *Thread);
+
+ACPI_STATUS
+AcpiDsResultPop (
+    ACPI_OPERAND_OBJECT     **Object,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiDsResultPush (
+    ACPI_OPERAND_OBJECT     *Object,
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * dsdebug - parser debugging routines
+ */
+void
+AcpiDsDumpMethodStack (
+    ACPI_STATUS             Status,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+#endif /* _ACDISPAT_H_ */

+ 366 - 0
kernel/include/acpica/acevents.h

@@ -0,0 +1,366 @@
+/******************************************************************************
+ *
+ * Name: acevents.h - Event subcomponent prototypes and defines
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACEVENTS_H__
+#define __ACEVENTS_H__
+
+
+/*
+ * evevent
+ */
+ACPI_STATUS
+AcpiEvInitializeEvents (
+    void);
+
+ACPI_STATUS
+AcpiEvInstallXruptHandlers (
+    void);
+
+UINT32
+AcpiEvFixedEventDetect (
+    void);
+
+
+/*
+ * evmisc
+ */
+BOOLEAN
+AcpiEvIsNotifyObject (
+    ACPI_NAMESPACE_NODE     *Node);
+
+UINT32
+AcpiEvGetGpeNumberIndex (
+    UINT32                  GpeNumber);
+
+ACPI_STATUS
+AcpiEvQueueNotifyRequest (
+    ACPI_NAMESPACE_NODE     *Node,
+    UINT32                  NotifyValue);
+
+
+/*
+ * evglock - Global Lock support
+ */
+ACPI_STATUS
+AcpiEvInitGlobalLockHandler (
+    void);
+
+ACPI_HW_DEPENDENT_RETURN_OK (
+ACPI_STATUS
+AcpiEvAcquireGlobalLock(
+    UINT16                  Timeout))
+
+ACPI_HW_DEPENDENT_RETURN_OK (
+ACPI_STATUS
+AcpiEvReleaseGlobalLock(
+    void))
+
+ACPI_STATUS
+AcpiEvRemoveGlobalLockHandler (
+    void);
+
+
+/*
+ * evgpe - Low-level GPE support
+ */
+UINT32
+AcpiEvGpeDetect (
+    ACPI_GPE_XRUPT_INFO     *GpeXruptList);
+
+ACPI_STATUS
+AcpiEvUpdateGpeEnableMask (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo);
+
+ACPI_STATUS
+AcpiEvEnableGpe (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo);
+
+ACPI_STATUS
+AcpiEvAddGpeReference (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo);
+
+ACPI_STATUS
+AcpiEvRemoveGpeReference (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo);
+
+ACPI_GPE_EVENT_INFO *
+AcpiEvGetGpeEventInfo (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber);
+
+ACPI_GPE_EVENT_INFO *
+AcpiEvLowGetGpeInfo (
+    UINT32                  GpeNumber,
+    ACPI_GPE_BLOCK_INFO     *GpeBlock);
+
+ACPI_STATUS
+AcpiEvFinishGpe (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo);
+
+
+/*
+ * evgpeblk - Upper-level GPE block support
+ */
+ACPI_STATUS
+AcpiEvCreateGpeBlock (
+    ACPI_NAMESPACE_NODE     *GpeDevice,
+    UINT64                  Address,
+    UINT8                   SpaceId,
+    UINT32                  RegisterCount,
+    UINT16                  GpeBlockBaseNumber,
+    UINT32                  InterruptNumber,
+    ACPI_GPE_BLOCK_INFO     **ReturnGpeBlock);
+
+ACPI_STATUS
+AcpiEvInitializeGpeBlock (
+    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
+    ACPI_GPE_BLOCK_INFO     *GpeBlock,
+    void                    *Context);
+
+ACPI_HW_DEPENDENT_RETURN_OK (
+ACPI_STATUS
+AcpiEvDeleteGpeBlock (
+    ACPI_GPE_BLOCK_INFO     *GpeBlock))
+
+UINT32
+AcpiEvGpeDispatch (
+    ACPI_NAMESPACE_NODE     *GpeDevice,
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo,
+    UINT32                  GpeNumber);
+
+
+/*
+ * evgpeinit - GPE initialization and update
+ */
+ACPI_STATUS
+AcpiEvGpeInitialize (
+    void);
+
+ACPI_HW_DEPENDENT_RETURN_VOID (
+void
+AcpiEvUpdateGpes (
+    ACPI_OWNER_ID           TableOwnerId))
+
+ACPI_STATUS
+AcpiEvMatchGpeMethod (
+    ACPI_HANDLE             ObjHandle,
+    UINT32                  Level,
+    void                    *Context,
+    void                    **ReturnValue);
+
+
+/*
+ * evgpeutil - GPE utilities
+ */
+ACPI_STATUS
+AcpiEvWalkGpeList (
+    ACPI_GPE_CALLBACK       GpeWalkCallback,
+    void                    *Context);
+
+ACPI_STATUS
+AcpiEvGetGpeDevice (
+    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
+    ACPI_GPE_BLOCK_INFO     *GpeBlock,
+    void                    *Context);
+
+ACPI_STATUS
+AcpiEvGetGpeXruptBlock (
+    UINT32                  InterruptNumber,
+    ACPI_GPE_XRUPT_INFO     **GpeXruptBlock);
+
+ACPI_STATUS
+AcpiEvDeleteGpeXrupt (
+    ACPI_GPE_XRUPT_INFO     *GpeXrupt);
+
+ACPI_STATUS
+AcpiEvDeleteGpeHandlers (
+    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
+    ACPI_GPE_BLOCK_INFO     *GpeBlock,
+    void                    *Context);
+
+
+/*
+ * evhandler - Address space handling
+ */
+ACPI_OPERAND_OBJECT *
+AcpiEvFindRegionHandler (
+    ACPI_ADR_SPACE_TYPE     SpaceId,
+    ACPI_OPERAND_OBJECT     *HandlerObj);
+
+BOOLEAN
+AcpiEvHasDefaultHandler (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_ADR_SPACE_TYPE     SpaceId);
+
+ACPI_STATUS
+AcpiEvInstallRegionHandlers (
+    void);
+
+ACPI_STATUS
+AcpiEvInstallSpaceHandler (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_ADR_SPACE_TYPE     SpaceId,
+    ACPI_ADR_SPACE_HANDLER  Handler,
+    ACPI_ADR_SPACE_SETUP    Setup,
+    void                    *Context);
+
+
+/*
+ * evregion - Operation region support
+ */
+ACPI_STATUS
+AcpiEvInitializeOpRegions (
+    void);
+
+ACPI_STATUS
+AcpiEvAddressSpaceDispatch (
+    ACPI_OPERAND_OBJECT     *RegionObj,
+    ACPI_OPERAND_OBJECT     *FieldObj,
+    UINT32                  Function,
+    UINT32                  RegionOffset,
+    UINT32                  BitWidth,
+    UINT64                  *Value);
+
+ACPI_STATUS
+AcpiEvAttachRegion (
+    ACPI_OPERAND_OBJECT     *HandlerObj,
+    ACPI_OPERAND_OBJECT     *RegionObj,
+    BOOLEAN                 AcpiNsIsLocked);
+
+void
+AcpiEvDetachRegion (
+    ACPI_OPERAND_OBJECT     *RegionObj,
+    BOOLEAN                 AcpiNsIsLocked);
+
+void
+AcpiEvAssociateRegMethod (
+    ACPI_OPERAND_OBJECT     *RegionObj);
+
+void
+AcpiEvExecuteRegMethods (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_ADR_SPACE_TYPE     SpaceId,
+    UINT32                  Function);
+
+ACPI_STATUS
+AcpiEvExecuteRegMethod (
+    ACPI_OPERAND_OBJECT     *RegionObj,
+    UINT32                  Function);
+
+
+/*
+ * evregini - Region initialization and setup
+ */
+ACPI_STATUS
+AcpiEvSystemMemoryRegionSetup (
+    ACPI_HANDLE             Handle,
+    UINT32                  Function,
+    void                    *HandlerContext,
+    void                    **RegionContext);
+
+ACPI_STATUS
+AcpiEvIoSpaceRegionSetup (
+    ACPI_HANDLE             Handle,
+    UINT32                  Function,
+    void                    *HandlerContext,
+    void                    **RegionContext);
+
+ACPI_STATUS
+AcpiEvPciConfigRegionSetup (
+    ACPI_HANDLE             Handle,
+    UINT32                  Function,
+    void                    *HandlerContext,
+    void                    **RegionContext);
+
+ACPI_STATUS
+AcpiEvCmosRegionSetup (
+    ACPI_HANDLE             Handle,
+    UINT32                  Function,
+    void                    *HandlerContext,
+    void                    **RegionContext);
+
+ACPI_STATUS
+AcpiEvPciBarRegionSetup (
+    ACPI_HANDLE             Handle,
+    UINT32                  Function,
+    void                    *HandlerContext,
+    void                    **RegionContext);
+
+ACPI_STATUS
+AcpiEvDefaultRegionSetup (
+    ACPI_HANDLE             Handle,
+    UINT32                  Function,
+    void                    *HandlerContext,
+    void                    **RegionContext);
+
+ACPI_STATUS
+AcpiEvInitializeRegion (
+    ACPI_OPERAND_OBJECT     *RegionObj,
+    BOOLEAN                 AcpiNsLocked);
+
+
+/*
+ * evsci - SCI (System Control Interrupt) handling/dispatch
+ */
+UINT32 ACPI_SYSTEM_XFACE
+AcpiEvGpeXruptHandler (
+    void                    *Context);
+
+UINT32
+AcpiEvSciDispatch (
+    void);
+
+UINT32
+AcpiEvInstallSciHandler (
+    void);
+
+ACPI_STATUS
+AcpiEvRemoveAllSciHandlers (
+    void);
+
+ACPI_HW_DEPENDENT_RETURN_VOID (
+void
+AcpiEvTerminate (
+    void))
+
+#endif  /* __ACEVENTS_H__  */

+ 354 - 0
kernel/include/acpica/acexcep.h

@@ -0,0 +1,354 @@
+/******************************************************************************
+ *
+ * Name: acexcep.h - Exception codes returned by the ACPI subsystem
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACEXCEP_H__
+#define __ACEXCEP_H__
+
+
+/* This module contains all possible exception codes for ACPI_STATUS */
+
+/*
+ * Exception code classes
+ */
+#define AE_CODE_ENVIRONMENTAL           0x0000 /* General ACPICA environment */
+#define AE_CODE_PROGRAMMER              0x1000 /* External ACPICA interface caller */
+#define AE_CODE_ACPI_TABLES             0x2000 /* ACPI tables */
+#define AE_CODE_AML                     0x3000 /* From executing AML code */
+#define AE_CODE_CONTROL                 0x4000 /* Internal control codes */
+
+#define AE_CODE_MAX                     0x4000
+#define AE_CODE_MASK                    0xF000
+
+/*
+ * Macros to insert the exception code classes
+ */
+#define EXCEP_ENV(code)                 ((ACPI_STATUS) (code | AE_CODE_ENVIRONMENTAL))
+#define EXCEP_PGM(code)                 ((ACPI_STATUS) (code | AE_CODE_PROGRAMMER))
+#define EXCEP_TBL(code)                 ((ACPI_STATUS) (code | AE_CODE_ACPI_TABLES))
+#define EXCEP_AML(code)                 ((ACPI_STATUS) (code | AE_CODE_AML))
+#define EXCEP_CTL(code)                 ((ACPI_STATUS) (code | AE_CODE_CONTROL))
+
+/*
+ * Exception info table. The "Description" field is used only by the
+ * ACPICA help application (acpihelp).
+ */
+typedef struct acpi_exception_info
+{
+    char                *Name;
+
+#ifdef ACPI_HELP_APP
+    char                *Description;
+#endif
+} ACPI_EXCEPTION_INFO;
+
+#ifdef ACPI_HELP_APP
+#define EXCEP_TXT(Name,Description)     {Name, Description}
+#else
+#define EXCEP_TXT(Name,Description)     {Name}
+#endif
+
+
+/*
+ * Success is always zero, failure is non-zero
+ */
+#define ACPI_SUCCESS(a)                 (!(a))
+#define ACPI_FAILURE(a)                 (a)
+
+#define AE_OK                           (ACPI_STATUS) 0x0000
+
+/*
+ * Environmental exceptions
+ */
+#define AE_ERROR                        EXCEP_ENV (0x0001)
+#define AE_NO_ACPI_TABLES               EXCEP_ENV (0x0002)
+#define AE_NO_NAMESPACE                 EXCEP_ENV (0x0003)
+#define AE_NO_MEMORY                    EXCEP_ENV (0x0004)
+#define AE_NOT_FOUND                    EXCEP_ENV (0x0005)
+#define AE_NOT_EXIST                    EXCEP_ENV (0x0006)
+#define AE_ALREADY_EXISTS               EXCEP_ENV (0x0007)
+#define AE_TYPE                         EXCEP_ENV (0x0008)
+#define AE_NULL_OBJECT                  EXCEP_ENV (0x0009)
+#define AE_NULL_ENTRY                   EXCEP_ENV (0x000A)
+#define AE_BUFFER_OVERFLOW              EXCEP_ENV (0x000B)
+#define AE_STACK_OVERFLOW               EXCEP_ENV (0x000C)
+#define AE_STACK_UNDERFLOW              EXCEP_ENV (0x000D)
+#define AE_NOT_IMPLEMENTED              EXCEP_ENV (0x000E)
+#define AE_SUPPORT                      EXCEP_ENV (0x000F)
+#define AE_LIMIT                        EXCEP_ENV (0x0010)
+#define AE_TIME                         EXCEP_ENV (0x0011)
+#define AE_ACQUIRE_DEADLOCK             EXCEP_ENV (0x0012)
+#define AE_RELEASE_DEADLOCK             EXCEP_ENV (0x0013)
+#define AE_NOT_ACQUIRED                 EXCEP_ENV (0x0014)
+#define AE_ALREADY_ACQUIRED             EXCEP_ENV (0x0015)
+#define AE_NO_HARDWARE_RESPONSE         EXCEP_ENV (0x0016)
+#define AE_NO_GLOBAL_LOCK               EXCEP_ENV (0x0017)
+#define AE_ABORT_METHOD                 EXCEP_ENV (0x0018)
+#define AE_SAME_HANDLER                 EXCEP_ENV (0x0019)
+#define AE_NO_HANDLER                   EXCEP_ENV (0x001A)
+#define AE_OWNER_ID_LIMIT               EXCEP_ENV (0x001B)
+#define AE_NOT_CONFIGURED               EXCEP_ENV (0x001C)
+#define AE_ACCESS                       EXCEP_ENV (0x001D)
+#define AE_IO_ERROR                     EXCEP_ENV (0x001E)
+
+#define AE_CODE_ENV_MAX                 0x001E
+
+
+/*
+ * Programmer exceptions
+ */
+#define AE_BAD_PARAMETER                EXCEP_PGM (0x0001)
+#define AE_BAD_CHARACTER                EXCEP_PGM (0x0002)
+#define AE_BAD_PATHNAME                 EXCEP_PGM (0x0003)
+#define AE_BAD_DATA                     EXCEP_PGM (0x0004)
+#define AE_BAD_HEX_CONSTANT             EXCEP_PGM (0x0005)
+#define AE_BAD_OCTAL_CONSTANT           EXCEP_PGM (0x0006)
+#define AE_BAD_DECIMAL_CONSTANT         EXCEP_PGM (0x0007)
+#define AE_MISSING_ARGUMENTS            EXCEP_PGM (0x0008)
+#define AE_BAD_ADDRESS                  EXCEP_PGM (0x0009)
+
+#define AE_CODE_PGM_MAX                 0x0009
+
+
+/*
+ * Acpi table exceptions
+ */
+#define AE_BAD_SIGNATURE                EXCEP_TBL (0x0001)
+#define AE_BAD_HEADER                   EXCEP_TBL (0x0002)
+#define AE_BAD_CHECKSUM                 EXCEP_TBL (0x0003)
+#define AE_BAD_VALUE                    EXCEP_TBL (0x0004)
+#define AE_INVALID_TABLE_LENGTH         EXCEP_TBL (0x0005)
+
+#define AE_CODE_TBL_MAX                 0x0005
+
+
+/*
+ * AML exceptions. These are caused by problems with
+ * the actual AML byte stream
+ */
+#define AE_AML_BAD_OPCODE               EXCEP_AML (0x0001)
+#define AE_AML_NO_OPERAND               EXCEP_AML (0x0002)
+#define AE_AML_OPERAND_TYPE             EXCEP_AML (0x0003)
+#define AE_AML_OPERAND_VALUE            EXCEP_AML (0x0004)
+#define AE_AML_UNINITIALIZED_LOCAL      EXCEP_AML (0x0005)
+#define AE_AML_UNINITIALIZED_ARG        EXCEP_AML (0x0006)
+#define AE_AML_UNINITIALIZED_ELEMENT    EXCEP_AML (0x0007)
+#define AE_AML_NUMERIC_OVERFLOW         EXCEP_AML (0x0008)
+#define AE_AML_REGION_LIMIT             EXCEP_AML (0x0009)
+#define AE_AML_BUFFER_LIMIT             EXCEP_AML (0x000A)
+#define AE_AML_PACKAGE_LIMIT            EXCEP_AML (0x000B)
+#define AE_AML_DIVIDE_BY_ZERO           EXCEP_AML (0x000C)
+#define AE_AML_BAD_NAME                 EXCEP_AML (0x000D)
+#define AE_AML_NAME_NOT_FOUND           EXCEP_AML (0x000E)
+#define AE_AML_INTERNAL                 EXCEP_AML (0x000F)
+#define AE_AML_INVALID_SPACE_ID         EXCEP_AML (0x0010)
+#define AE_AML_STRING_LIMIT             EXCEP_AML (0x0011)
+#define AE_AML_NO_RETURN_VALUE          EXCEP_AML (0x0012)
+#define AE_AML_METHOD_LIMIT             EXCEP_AML (0x0013)
+#define AE_AML_NOT_OWNER                EXCEP_AML (0x0014)
+#define AE_AML_MUTEX_ORDER              EXCEP_AML (0x0015)
+#define AE_AML_MUTEX_NOT_ACQUIRED       EXCEP_AML (0x0016)
+#define AE_AML_INVALID_RESOURCE_TYPE    EXCEP_AML (0x0017)
+#define AE_AML_INVALID_INDEX            EXCEP_AML (0x0018)
+#define AE_AML_REGISTER_LIMIT           EXCEP_AML (0x0019)
+#define AE_AML_NO_WHILE                 EXCEP_AML (0x001A)
+#define AE_AML_ALIGNMENT                EXCEP_AML (0x001B)
+#define AE_AML_NO_RESOURCE_END_TAG      EXCEP_AML (0x001C)
+#define AE_AML_BAD_RESOURCE_VALUE       EXCEP_AML (0x001D)
+#define AE_AML_CIRCULAR_REFERENCE       EXCEP_AML (0x001E)
+#define AE_AML_BAD_RESOURCE_LENGTH      EXCEP_AML (0x001F)
+#define AE_AML_ILLEGAL_ADDRESS          EXCEP_AML (0x0020)
+#define AE_AML_INFINITE_LOOP            EXCEP_AML (0x0021)
+#define AE_AML_UNINITIALIZED_NODE       EXCEP_AML (0x0022)
+#define AE_AML_TARGET_TYPE              EXCEP_AML (0x0023)
+
+#define AE_CODE_AML_MAX                 0x0023
+
+
+/*
+ * Internal exceptions used for control
+ */
+#define AE_CTRL_RETURN_VALUE            EXCEP_CTL (0x0001)
+#define AE_CTRL_PENDING                 EXCEP_CTL (0x0002)
+#define AE_CTRL_TERMINATE               EXCEP_CTL (0x0003)
+#define AE_CTRL_TRUE                    EXCEP_CTL (0x0004)
+#define AE_CTRL_FALSE                   EXCEP_CTL (0x0005)
+#define AE_CTRL_DEPTH                   EXCEP_CTL (0x0006)
+#define AE_CTRL_END                     EXCEP_CTL (0x0007)
+#define AE_CTRL_TRANSFER                EXCEP_CTL (0x0008)
+#define AE_CTRL_BREAK                   EXCEP_CTL (0x0009)
+#define AE_CTRL_CONTINUE                EXCEP_CTL (0x000A)
+#define AE_CTRL_SKIP                    EXCEP_CTL (0x000B)
+#define AE_CTRL_PARSE_CONTINUE          EXCEP_CTL (0x000C)
+#define AE_CTRL_PARSE_PENDING           EXCEP_CTL (0x000D)
+
+#define AE_CODE_CTRL_MAX                0x000D
+
+
+/* Exception strings for AcpiFormatException */
+
+#ifdef ACPI_DEFINE_EXCEPTION_TABLE
+
+/*
+ * String versions of the exception codes above
+ * These strings must match the corresponding defines exactly
+ */
+static const ACPI_EXCEPTION_INFO    AcpiGbl_ExceptionNames_Env[] =
+{
+    EXCEP_TXT ("AE_OK",                         "No error"),
+    EXCEP_TXT ("AE_ERROR",                      "Unspecified error"),
+    EXCEP_TXT ("AE_NO_ACPI_TABLES",             "ACPI tables could not be found"),
+    EXCEP_TXT ("AE_NO_NAMESPACE",               "A namespace has not been loaded"),
+    EXCEP_TXT ("AE_NO_MEMORY",                  "Insufficient dynamic memory"),
+    EXCEP_TXT ("AE_NOT_FOUND",                  "A requested entity is not found"),
+    EXCEP_TXT ("AE_NOT_EXIST",                  "A required entity does not exist"),
+    EXCEP_TXT ("AE_ALREADY_EXISTS",             "An entity already exists"),
+    EXCEP_TXT ("AE_TYPE",                       "The object type is incorrect"),
+    EXCEP_TXT ("AE_NULL_OBJECT",                "A required object was missing"),
+    EXCEP_TXT ("AE_NULL_ENTRY",                 "The requested object does not exist"),
+    EXCEP_TXT ("AE_BUFFER_OVERFLOW",            "The buffer provided is too small"),
+    EXCEP_TXT ("AE_STACK_OVERFLOW",             "An internal stack overflowed"),
+    EXCEP_TXT ("AE_STACK_UNDERFLOW",            "An internal stack underflowed"),
+    EXCEP_TXT ("AE_NOT_IMPLEMENTED",            "The feature is not implemented"),
+    EXCEP_TXT ("AE_SUPPORT",                    "The feature is not supported"),
+    EXCEP_TXT ("AE_LIMIT",                      "A predefined limit was exceeded"),
+    EXCEP_TXT ("AE_TIME",                       "A time limit or timeout expired"),
+    EXCEP_TXT ("AE_ACQUIRE_DEADLOCK",           "Internal error, attempt was made to acquire a mutex in improper order"),
+    EXCEP_TXT ("AE_RELEASE_DEADLOCK",           "Internal error, attempt was made to release a mutex in improper order"),
+    EXCEP_TXT ("AE_NOT_ACQUIRED",               "An attempt to release a mutex or Global Lock without a previous acquire"),
+    EXCEP_TXT ("AE_ALREADY_ACQUIRED",           "Internal error, attempt was made to acquire a mutex twice"),
+    EXCEP_TXT ("AE_NO_HARDWARE_RESPONSE",       "Hardware did not respond after an I/O operation"),
+    EXCEP_TXT ("AE_NO_GLOBAL_LOCK",             "There is no FACS Global Lock"),
+    EXCEP_TXT ("AE_ABORT_METHOD",               "A control method was aborted"),
+    EXCEP_TXT ("AE_SAME_HANDLER",               "Attempt was made to install the same handler that is already installed"),
+    EXCEP_TXT ("AE_NO_HANDLER",                 "A handler for the operation is not installed"),
+    EXCEP_TXT ("AE_OWNER_ID_LIMIT",             "There are no more Owner IDs available for ACPI tables or control methods"),
+    EXCEP_TXT ("AE_NOT_CONFIGURED",             "The interface is not part of the current subsystem configuration"),
+    EXCEP_TXT ("AE_ACCESS",                     "Permission denied for the requested operation"),
+    EXCEP_TXT ("AE_IO_ERROR",                   "An I/O error occurred")
+};
+
+static const ACPI_EXCEPTION_INFO    AcpiGbl_ExceptionNames_Pgm[] =
+{
+    EXCEP_TXT (NULL, NULL),
+    EXCEP_TXT ("AE_BAD_PARAMETER",              "A parameter is out of range or invalid"),
+    EXCEP_TXT ("AE_BAD_CHARACTER",              "An invalid character was found in a name"),
+    EXCEP_TXT ("AE_BAD_PATHNAME",               "An invalid character was found in a pathname"),
+    EXCEP_TXT ("AE_BAD_DATA",                   "A package or buffer contained incorrect data"),
+    EXCEP_TXT ("AE_BAD_HEX_CONSTANT",           "Invalid character in a Hex constant"),
+    EXCEP_TXT ("AE_BAD_OCTAL_CONSTANT",         "Invalid character in an Octal constant"),
+    EXCEP_TXT ("AE_BAD_DECIMAL_CONSTANT",       "Invalid character in a Decimal constant"),
+    EXCEP_TXT ("AE_MISSING_ARGUMENTS",          "Too few arguments were passed to a control method"),
+    EXCEP_TXT ("AE_BAD_ADDRESS",                "An illegal null I/O address")
+};
+
+static const ACPI_EXCEPTION_INFO    AcpiGbl_ExceptionNames_Tbl[] =
+{
+    EXCEP_TXT (NULL, NULL),
+    EXCEP_TXT ("AE_BAD_SIGNATURE",              "An ACPI table has an invalid signature"),
+    EXCEP_TXT ("AE_BAD_HEADER",                 "Invalid field in an ACPI table header"),
+    EXCEP_TXT ("AE_BAD_CHECKSUM",               "An ACPI table checksum is not correct"),
+    EXCEP_TXT ("AE_BAD_VALUE",                  "An invalid value was found in a table"),
+    EXCEP_TXT ("AE_INVALID_TABLE_LENGTH",       "The FADT or FACS has improper length")
+};
+
+static const ACPI_EXCEPTION_INFO    AcpiGbl_ExceptionNames_Aml[] =
+{
+    EXCEP_TXT (NULL, NULL),
+    EXCEP_TXT ("AE_AML_BAD_OPCODE",             "Invalid AML opcode encountered"),
+    EXCEP_TXT ("AE_AML_NO_OPERAND",             "A required operand is missing"),
+    EXCEP_TXT ("AE_AML_OPERAND_TYPE",           "An operand of an incorrect type was encountered"),
+    EXCEP_TXT ("AE_AML_OPERAND_VALUE",          "The operand had an inappropriate or invalid value"),
+    EXCEP_TXT ("AE_AML_UNINITIALIZED_LOCAL",    "Method tried to use an uninitialized local variable"),
+    EXCEP_TXT ("AE_AML_UNINITIALIZED_ARG",      "Method tried to use an uninitialized argument"),
+    EXCEP_TXT ("AE_AML_UNINITIALIZED_ELEMENT",  "Method tried to use an empty package element"),
+    EXCEP_TXT ("AE_AML_NUMERIC_OVERFLOW",       "Overflow during BCD conversion or other"),
+    EXCEP_TXT ("AE_AML_REGION_LIMIT",           "Tried to access beyond the end of an Operation Region"),
+    EXCEP_TXT ("AE_AML_BUFFER_LIMIT",           "Tried to access beyond the end of a buffer"),
+    EXCEP_TXT ("AE_AML_PACKAGE_LIMIT",          "Tried to access beyond the end of a package"),
+    EXCEP_TXT ("AE_AML_DIVIDE_BY_ZERO",         "During execution of AML Divide operator"),
+    EXCEP_TXT ("AE_AML_BAD_NAME",               "An ACPI name contains invalid character(s)"),
+    EXCEP_TXT ("AE_AML_NAME_NOT_FOUND",         "Could not resolve a named reference"),
+    EXCEP_TXT ("AE_AML_INTERNAL",               "An internal error within the interprete"),
+    EXCEP_TXT ("AE_AML_INVALID_SPACE_ID",       "An Operation Region SpaceID is invalid"),
+    EXCEP_TXT ("AE_AML_STRING_LIMIT",           "String is longer than 200 characters"),
+    EXCEP_TXT ("AE_AML_NO_RETURN_VALUE",        "A method did not return a required value"),
+    EXCEP_TXT ("AE_AML_METHOD_LIMIT",           "A control method reached the maximum reentrancy limit of 255"),
+    EXCEP_TXT ("AE_AML_NOT_OWNER",              "A thread tried to release a mutex that it does not own"),
+    EXCEP_TXT ("AE_AML_MUTEX_ORDER",            "Mutex SyncLevel release mismatch"),
+    EXCEP_TXT ("AE_AML_MUTEX_NOT_ACQUIRED",     "Attempt to release a mutex that was not previously acquired"),
+    EXCEP_TXT ("AE_AML_INVALID_RESOURCE_TYPE",  "Invalid resource type in resource list"),
+    EXCEP_TXT ("AE_AML_INVALID_INDEX",          "Invalid Argx or Localx (x too large)"),
+    EXCEP_TXT ("AE_AML_REGISTER_LIMIT",         "Bank value or Index value beyond range of register"),
+    EXCEP_TXT ("AE_AML_NO_WHILE",               "Break or Continue without a While"),
+    EXCEP_TXT ("AE_AML_ALIGNMENT",              "Non-aligned memory transfer on platform that does not support this"),
+    EXCEP_TXT ("AE_AML_NO_RESOURCE_END_TAG",    "No End Tag in a resource list"),
+    EXCEP_TXT ("AE_AML_BAD_RESOURCE_VALUE",     "Invalid value of a resource element"),
+    EXCEP_TXT ("AE_AML_CIRCULAR_REFERENCE",     "Two references refer to each other"),
+    EXCEP_TXT ("AE_AML_BAD_RESOURCE_LENGTH",    "The length of a Resource Descriptor in the AML is incorrect"),
+    EXCEP_TXT ("AE_AML_ILLEGAL_ADDRESS",        "A memory, I/O, or PCI configuration address is invalid"),
+    EXCEP_TXT ("AE_AML_INFINITE_LOOP",          "An apparent infinite AML While loop, method was aborted"),
+    EXCEP_TXT ("AE_AML_UNINITIALIZED_NODE",     "A namespace node is uninitialized or unresolved"),
+    EXCEP_TXT ("AE_AML_TARGET_TYPE",            "A target operand of an incorrect type was encountered")
+};
+
+static const ACPI_EXCEPTION_INFO    AcpiGbl_ExceptionNames_Ctrl[] =
+{
+    EXCEP_TXT (NULL, NULL),
+    EXCEP_TXT ("AE_CTRL_RETURN_VALUE",          "A Method returned a value"),
+    EXCEP_TXT ("AE_CTRL_PENDING",               "Method is calling another method"),
+    EXCEP_TXT ("AE_CTRL_TERMINATE",             "Terminate the executing method"),
+    EXCEP_TXT ("AE_CTRL_TRUE",                  "An If or While predicate result"),
+    EXCEP_TXT ("AE_CTRL_FALSE",                 "An If or While predicate result"),
+    EXCEP_TXT ("AE_CTRL_DEPTH",                 "Maximum search depth has been reached"),
+    EXCEP_TXT ("AE_CTRL_END",                   "An If or While predicate is false"),
+    EXCEP_TXT ("AE_CTRL_TRANSFER",              "Transfer control to called method"),
+    EXCEP_TXT ("AE_CTRL_BREAK",                 "A Break has been executed"),
+    EXCEP_TXT ("AE_CTRL_CONTINUE",              "A Continue has been executed"),
+    EXCEP_TXT ("AE_CTRL_SKIP",                  "Not currently used"),
+    EXCEP_TXT ("AE_CTRL_PARSE_CONTINUE",        "Used to skip over bad opcodes"),
+    EXCEP_TXT ("AE_CTRL_PARSE_PENDING",         "Used to implement AML While loops")
+};
+
+#endif /* EXCEPTION_TABLE */
+
+#endif /* __ACEXCEP_H__ */

+ 405 - 0
kernel/include/acpica/acglobal.h

@@ -0,0 +1,405 @@
+/******************************************************************************
+ *
+ * Name: acglobal.h - Declarations for global variables
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACGLOBAL_H__
+#define __ACGLOBAL_H__
+
+
+/*****************************************************************************
+ *
+ * Globals related to the ACPI tables
+ *
+ ****************************************************************************/
+
+/* Master list of all ACPI tables that were found in the RSDT/XSDT */
+
+ACPI_GLOBAL (ACPI_TABLE_LIST,           AcpiGbl_RootTableList);
+
+/* DSDT information. Used to check for DSDT corruption */
+
+ACPI_GLOBAL (ACPI_TABLE_HEADER *,       AcpiGbl_DSDT);
+ACPI_GLOBAL (ACPI_TABLE_HEADER,         AcpiGbl_OriginalDsdtHeader);
+ACPI_INIT_GLOBAL (UINT32,               AcpiGbl_DsdtIndex, ACPI_INVALID_TABLE_INDEX);
+ACPI_INIT_GLOBAL (UINT32,               AcpiGbl_FacsIndex, ACPI_INVALID_TABLE_INDEX);
+ACPI_INIT_GLOBAL (UINT32,               AcpiGbl_XFacsIndex, ACPI_INVALID_TABLE_INDEX);
+ACPI_INIT_GLOBAL (UINT32,               AcpiGbl_FadtIndex, ACPI_INVALID_TABLE_INDEX);
+
+#if (!ACPI_REDUCED_HARDWARE)
+ACPI_GLOBAL (ACPI_TABLE_FACS *,         AcpiGbl_FACS);
+
+#endif /* !ACPI_REDUCED_HARDWARE */
+
+/* These addresses are calculated from the FADT Event Block addresses */
+
+ACPI_GLOBAL (ACPI_GENERIC_ADDRESS,      AcpiGbl_XPm1aStatus);
+ACPI_GLOBAL (ACPI_GENERIC_ADDRESS,      AcpiGbl_XPm1aEnable);
+
+ACPI_GLOBAL (ACPI_GENERIC_ADDRESS,      AcpiGbl_XPm1bStatus);
+ACPI_GLOBAL (ACPI_GENERIC_ADDRESS,      AcpiGbl_XPm1bEnable);
+
+/*
+ * Handle both ACPI 1.0 and ACPI 2.0+ Integer widths. The integer width is
+ * determined by the revision of the DSDT: If the DSDT revision is less than
+ * 2, use only the lower 32 bits of the internal 64-bit Integer.
+ */
+ACPI_GLOBAL (UINT8,                     AcpiGbl_IntegerBitWidth);
+ACPI_GLOBAL (UINT8,                     AcpiGbl_IntegerByteWidth);
+ACPI_GLOBAL (UINT8,                     AcpiGbl_IntegerNybbleWidth);
+
+ACPI_INIT_GLOBAL (UINT8,                AcpiGbl_GroupModuleLevelCode, FALSE);
+
+
+/*****************************************************************************
+ *
+ * Mutual exclusion within ACPICA subsystem
+ *
+ ****************************************************************************/
+
+/*
+ * Predefined mutex objects. This array contains the
+ * actual OS mutex handles, indexed by the local ACPI_MUTEX_HANDLEs.
+ * (The table maps local handles to the real OS handles)
+ */
+ACPI_GLOBAL (ACPI_MUTEX_INFO,           AcpiGbl_MutexInfo[ACPI_NUM_MUTEX]);
+
+/*
+ * Global lock mutex is an actual AML mutex object
+ * Global lock semaphore works in conjunction with the actual global lock
+ * Global lock spinlock is used for "pending" handshake
+ */
+ACPI_GLOBAL (ACPI_OPERAND_OBJECT *,     AcpiGbl_GlobalLockMutex);
+ACPI_GLOBAL (ACPI_SEMAPHORE,            AcpiGbl_GlobalLockSemaphore);
+ACPI_GLOBAL (ACPI_SPINLOCK,             AcpiGbl_GlobalLockPendingLock);
+ACPI_GLOBAL (UINT16,                    AcpiGbl_GlobalLockHandle);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_GlobalLockAcquired);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_GlobalLockPresent);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_GlobalLockPending);
+
+/*
+ * Spinlocks are used for interfaces that can be possibly called at
+ * interrupt level
+ */
+ACPI_GLOBAL (ACPI_SPINLOCK,             AcpiGbl_GpeLock);       /* For GPE data structs and registers */
+ACPI_GLOBAL (ACPI_SPINLOCK,             AcpiGbl_HardwareLock);  /* For ACPI H/W except GPE registers */
+ACPI_GLOBAL (ACPI_SPINLOCK,             AcpiGbl_ReferenceCountLock);
+
+/* Mutex for _OSI support */
+
+ACPI_GLOBAL (ACPI_MUTEX,                AcpiGbl_OsiMutex);
+
+/* Reader/Writer lock is used for namespace walk and dynamic table unload */
+
+ACPI_GLOBAL (ACPI_RW_LOCK,              AcpiGbl_NamespaceRwLock);
+
+
+/*****************************************************************************
+ *
+ * Miscellaneous globals
+ *
+ ****************************************************************************/
+
+/* Object caches */
+
+ACPI_GLOBAL (ACPI_CACHE_T *,            AcpiGbl_NamespaceCache);
+ACPI_GLOBAL (ACPI_CACHE_T *,            AcpiGbl_StateCache);
+ACPI_GLOBAL (ACPI_CACHE_T *,            AcpiGbl_PsNodeCache);
+ACPI_GLOBAL (ACPI_CACHE_T *,            AcpiGbl_PsNodeExtCache);
+ACPI_GLOBAL (ACPI_CACHE_T *,            AcpiGbl_OperandCache);
+
+/* System */
+
+ACPI_INIT_GLOBAL (UINT32,               AcpiGbl_StartupFlags, 0);
+ACPI_INIT_GLOBAL (BOOLEAN,              AcpiGbl_Shutdown, TRUE);
+ACPI_INIT_GLOBAL (BOOLEAN,              AcpiGbl_EarlyInitialization, TRUE);
+
+/* Global handlers */
+
+ACPI_GLOBAL (ACPI_GLOBAL_NOTIFY_HANDLER,AcpiGbl_GlobalNotify[2]);
+ACPI_GLOBAL (ACPI_EXCEPTION_HANDLER,    AcpiGbl_ExceptionHandler);
+ACPI_GLOBAL (ACPI_INIT_HANDLER,         AcpiGbl_InitHandler);
+ACPI_GLOBAL (ACPI_TABLE_HANDLER,        AcpiGbl_TableHandler);
+ACPI_GLOBAL (void *,                    AcpiGbl_TableHandlerContext);
+ACPI_GLOBAL (ACPI_INTERFACE_HANDLER,    AcpiGbl_InterfaceHandler);
+ACPI_GLOBAL (ACPI_SCI_HANDLER_INFO *,   AcpiGbl_SciHandlerList);
+
+/* Owner ID support */
+
+ACPI_GLOBAL (UINT32,                    AcpiGbl_OwnerIdMask[ACPI_NUM_OWNERID_MASKS]);
+ACPI_GLOBAL (UINT8,                     AcpiGbl_LastOwnerIdIndex);
+ACPI_GLOBAL (UINT8,                     AcpiGbl_NextOwnerIdOffset);
+
+/* Initialization sequencing */
+
+ACPI_INIT_GLOBAL (BOOLEAN,              AcpiGbl_RegMethodsEnabled, FALSE);
+
+/* Misc */
+
+ACPI_GLOBAL (UINT32,                    AcpiGbl_OriginalMode);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_NsLookupCount);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_PsFindCount);
+ACPI_GLOBAL (UINT16,                    AcpiGbl_Pm1EnableRegisterSave);
+ACPI_GLOBAL (UINT8,                     AcpiGbl_DebuggerConfiguration);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_StepToNextCall);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_AcpiHardwarePresent);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_EventsInitialized);
+ACPI_GLOBAL (ACPI_INTERFACE_INFO *,     AcpiGbl_SupportedInterfaces);
+ACPI_GLOBAL (ACPI_ADDRESS_RANGE *,      AcpiGbl_AddressRangeList[ACPI_ADDRESS_RANGE_MAX]);
+
+/* Other miscellaneous, declared and initialized in utglobal */
+
+extern const char                      *AcpiGbl_SleepStateNames[ACPI_S_STATE_COUNT];
+extern const char                      *AcpiGbl_LowestDstateNames[ACPI_NUM_SxW_METHODS];
+extern const char                      *AcpiGbl_HighestDstateNames[ACPI_NUM_SxD_METHODS];
+extern const char                      *AcpiGbl_RegionTypes[ACPI_NUM_PREDEFINED_REGIONS];
+extern const ACPI_OPCODE_INFO           AcpiGbl_AmlOpInfo[AML_NUM_OPCODES];
+
+
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+
+/* Lists for tracking memory allocations (debug only) */
+
+ACPI_GLOBAL (ACPI_MEMORY_LIST *,        AcpiGbl_GlobalList);
+ACPI_GLOBAL (ACPI_MEMORY_LIST *,        AcpiGbl_NsNodeList);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_DisplayFinalMemStats);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_DisableMemTracking);
+#endif
+
+
+/*****************************************************************************
+ *
+ * Namespace globals
+ *
+ ****************************************************************************/
+
+#if !defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY)
+#define NUM_PREDEFINED_NAMES            10
+#else
+#define NUM_PREDEFINED_NAMES            9
+#endif
+
+ACPI_GLOBAL (ACPI_NAMESPACE_NODE,       AcpiGbl_RootNodeStruct);
+ACPI_GLOBAL (ACPI_NAMESPACE_NODE *,     AcpiGbl_RootNode);
+ACPI_GLOBAL (ACPI_NAMESPACE_NODE *,     AcpiGbl_FadtGpeDevice);
+ACPI_GLOBAL (ACPI_OPERAND_OBJECT *,     AcpiGbl_ModuleCodeList);
+
+
+extern const UINT8                      AcpiGbl_NsProperties [ACPI_NUM_NS_TYPES];
+extern const ACPI_PREDEFINED_NAMES      AcpiGbl_PreDefinedNames [NUM_PREDEFINED_NAMES];
+
+#ifdef ACPI_DEBUG_OUTPUT
+ACPI_GLOBAL (UINT32,                    AcpiGbl_CurrentNodeCount);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_CurrentNodeSize);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_MaxConcurrentNodeCount);
+ACPI_GLOBAL (ACPI_SIZE *,               AcpiGbl_EntryStackPointer);
+ACPI_GLOBAL (ACPI_SIZE *,               AcpiGbl_LowestStackPointer);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_DeepestNesting);
+ACPI_INIT_GLOBAL (UINT32,               AcpiGbl_NestingLevel, 0);
+#endif
+
+
+/*****************************************************************************
+ *
+ * Interpreter globals
+ *
+ ****************************************************************************/
+
+ACPI_GLOBAL (ACPI_THREAD_STATE *,       AcpiGbl_CurrentWalkList);
+
+/* Maximum number of While() loop iterations before forced abort */
+
+ACPI_GLOBAL (UINT16,                    AcpiGbl_MaxLoopIterations);
+
+/* Control method single step flag */
+
+ACPI_GLOBAL (UINT8,                     AcpiGbl_CmSingleStep);
+
+
+/*****************************************************************************
+ *
+ * Hardware globals
+ *
+ ****************************************************************************/
+
+extern ACPI_BIT_REGISTER_INFO           AcpiGbl_BitRegisterInfo[ACPI_NUM_BITREG];
+
+ACPI_GLOBAL (UINT8,                     AcpiGbl_SleepTypeA);
+ACPI_GLOBAL (UINT8,                     AcpiGbl_SleepTypeB);
+
+
+/*****************************************************************************
+ *
+ * Event and GPE globals
+ *
+ ****************************************************************************/
+
+#if (!ACPI_REDUCED_HARDWARE)
+
+ACPI_GLOBAL (UINT8,                     AcpiGbl_AllGpesInitialized);
+ACPI_GLOBAL (ACPI_GPE_XRUPT_INFO *,     AcpiGbl_GpeXruptListHead);
+ACPI_GLOBAL (ACPI_GPE_BLOCK_INFO *,     AcpiGbl_GpeFadtBlocks[ACPI_MAX_GPE_BLOCKS]);
+ACPI_GLOBAL (ACPI_GBL_EVENT_HANDLER,    AcpiGbl_GlobalEventHandler);
+ACPI_GLOBAL (void *,                    AcpiGbl_GlobalEventHandlerContext);
+ACPI_GLOBAL (ACPI_FIXED_EVENT_HANDLER,  AcpiGbl_FixedEventHandlers[ACPI_NUM_FIXED_EVENTS]);
+
+extern ACPI_FIXED_EVENT_INFO            AcpiGbl_FixedEventInfo[ACPI_NUM_FIXED_EVENTS];
+
+#endif /* !ACPI_REDUCED_HARDWARE */
+
+/*****************************************************************************
+ *
+ * Debug support
+ *
+ ****************************************************************************/
+
+/* Event counters */
+
+ACPI_GLOBAL (UINT32,                    AcpiMethodCount);
+ACPI_GLOBAL (UINT32,                    AcpiGpeCount);
+ACPI_GLOBAL (UINT32,                    AcpiSciCount);
+ACPI_GLOBAL (UINT32,                    AcpiFixedEventCount[ACPI_NUM_FIXED_EVENTS]);
+
+/* Support for dynamic control method tracing mechanism */
+
+ACPI_GLOBAL (UINT32,                    AcpiGbl_OriginalDbgLevel);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_OriginalDbgLayer);
+
+
+/*****************************************************************************
+ *
+ * Debugger and Disassembler globals
+ *
+ ****************************************************************************/
+
+ACPI_INIT_GLOBAL (UINT8,                AcpiGbl_DbOutputFlags, ACPI_DB_CONSOLE_OUTPUT);
+
+#ifdef ACPI_DISASSEMBLER
+
+/* Do not disassemble buffers to resource descriptors */
+
+ACPI_INIT_GLOBAL (UINT8,                AcpiGbl_NoResourceDisassembly, FALSE);
+ACPI_INIT_GLOBAL (BOOLEAN,              AcpiGbl_IgnoreNoopOperator, FALSE);
+ACPI_INIT_GLOBAL (BOOLEAN,              AcpiGbl_CstyleDisassembly, TRUE);
+ACPI_INIT_GLOBAL (BOOLEAN,              AcpiGbl_ForceAmlDisassembly, FALSE);
+ACPI_INIT_GLOBAL (BOOLEAN,              AcpiGbl_DmOpt_Verbose, TRUE);
+
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_DmOpt_Disasm);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_DmOpt_Listing);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_NumExternalMethods);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_ResolvedExternalMethods);
+ACPI_GLOBAL (ACPI_EXTERNAL_LIST *,      AcpiGbl_ExternalList);
+ACPI_GLOBAL (ACPI_EXTERNAL_FILE *,      AcpiGbl_ExternalFileList);
+#endif
+
+#ifdef ACPI_DEBUGGER
+
+ACPI_INIT_GLOBAL (BOOLEAN,              AcpiGbl_AbortMethod, FALSE);
+ACPI_INIT_GLOBAL (BOOLEAN,              AcpiGbl_MethodExecuting, FALSE);
+ACPI_INIT_GLOBAL (ACPI_THREAD_ID,       AcpiGbl_DbThreadId, ACPI_INVALID_THREAD_ID);
+
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_DbOpt_NoIniMethods);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_DbOpt_NoRegionSupport);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_DbOutputToFile);
+ACPI_GLOBAL (char *,                    AcpiGbl_DbBuffer);
+ACPI_GLOBAL (char *,                    AcpiGbl_DbFilename);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_DbDebugLevel);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_DbConsoleDebugLevel);
+ACPI_GLOBAL (ACPI_NAMESPACE_NODE *,     AcpiGbl_DbScopeNode);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_DbTerminateLoop);
+ACPI_GLOBAL (BOOLEAN,                   AcpiGbl_DbThreadsTerminated);
+
+ACPI_GLOBAL (char *,                    AcpiGbl_DbArgs[ACPI_DEBUGGER_MAX_ARGS]);
+ACPI_GLOBAL (ACPI_OBJECT_TYPE,          AcpiGbl_DbArgTypes[ACPI_DEBUGGER_MAX_ARGS]);
+
+/* These buffers should all be the same size */
+
+ACPI_GLOBAL (char,                      AcpiGbl_DbLineBuf[ACPI_DB_LINE_BUFFER_SIZE]);
+ACPI_GLOBAL (char,                      AcpiGbl_DbParsedBuf[ACPI_DB_LINE_BUFFER_SIZE]);
+ACPI_GLOBAL (char,                      AcpiGbl_DbScopeBuf[ACPI_DB_LINE_BUFFER_SIZE]);
+ACPI_GLOBAL (char,                      AcpiGbl_DbDebugFilename[ACPI_DB_LINE_BUFFER_SIZE]);
+
+/*
+ * Statistic globals
+ */
+ACPI_GLOBAL (UINT16,                    AcpiGbl_ObjTypeCount[ACPI_TOTAL_TYPES]);
+ACPI_GLOBAL (UINT16,                    AcpiGbl_NodeTypeCount[ACPI_TOTAL_TYPES]);
+ACPI_GLOBAL (UINT16,                    AcpiGbl_ObjTypeCountMisc);
+ACPI_GLOBAL (UINT16,                    AcpiGbl_NodeTypeCountMisc);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_NumNodes);
+ACPI_GLOBAL (UINT32,                    AcpiGbl_NumObjects);
+
+ACPI_GLOBAL (ACPI_MUTEX,                AcpiGbl_DbCommandReady);
+ACPI_GLOBAL (ACPI_MUTEX,                AcpiGbl_DbCommandComplete);
+
+#endif /* ACPI_DEBUGGER */
+
+
+/*****************************************************************************
+ *
+ * Application globals
+ *
+ ****************************************************************************/
+
+#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 */
+
+
+/*****************************************************************************
+ *
+ * Info/help support
+ *
+ ****************************************************************************/
+
+extern const AH_PREDEFINED_NAME         AslPredefinedInfo[];
+extern const AH_DEVICE_ID               AslDeviceIds[];
+
+
+#endif /* __ACGLOBAL_H__ */

+ 227 - 0
kernel/include/acpica/achware.h

@@ -0,0 +1,227 @@
+/******************************************************************************
+ *
+ * Name: achware.h -- hardware specific interfaces
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACHWARE_H__
+#define __ACHWARE_H__
+
+
+/* Values for the _SST predefined method */
+
+#define ACPI_SST_INDICATOR_OFF  0
+#define ACPI_SST_WORKING        1
+#define ACPI_SST_WAKING         2
+#define ACPI_SST_SLEEPING       3
+#define ACPI_SST_SLEEP_CONTEXT  4
+
+
+/*
+ * hwacpi - high level functions
+ */
+ACPI_STATUS
+AcpiHwSetMode (
+    UINT32                  Mode);
+
+UINT32
+AcpiHwGetMode (
+    void);
+
+
+/*
+ * hwregs - ACPI Register I/O
+ */
+ACPI_STATUS
+AcpiHwValidateRegister (
+    ACPI_GENERIC_ADDRESS    *Reg,
+    UINT8                   MaxBitWidth,
+    UINT64                  *Address);
+
+ACPI_STATUS
+AcpiHwRead (
+    UINT32                  *Value,
+    ACPI_GENERIC_ADDRESS    *Reg);
+
+ACPI_STATUS
+AcpiHwWrite (
+    UINT32                  Value,
+    ACPI_GENERIC_ADDRESS    *Reg);
+
+ACPI_BIT_REGISTER_INFO *
+AcpiHwGetBitRegisterInfo (
+    UINT32                  RegisterId);
+
+ACPI_STATUS
+AcpiHwWritePm1Control (
+    UINT32                  Pm1aControl,
+    UINT32                  Pm1bControl);
+
+ACPI_STATUS
+AcpiHwRegisterRead (
+    UINT32                  RegisterId,
+    UINT32                  *ReturnValue);
+
+ACPI_STATUS
+AcpiHwRegisterWrite (
+    UINT32                  RegisterId,
+    UINT32                  Value);
+
+ACPI_STATUS
+AcpiHwClearAcpiStatus (
+    void);
+
+
+/*
+ * hwsleep - sleep/wake support (Legacy sleep registers)
+ */
+ACPI_STATUS
+AcpiHwLegacySleep (
+    UINT8                   SleepState);
+
+ACPI_STATUS
+AcpiHwLegacyWakePrep (
+    UINT8                   SleepState);
+
+ACPI_STATUS
+AcpiHwLegacyWake (
+    UINT8                   SleepState);
+
+
+/*
+ * hwesleep - sleep/wake support (Extended FADT-V5 sleep registers)
+ */
+void
+AcpiHwExecuteSleepMethod (
+    char                    *MethodName,
+    UINT32                  IntegerArgument);
+
+ACPI_STATUS
+AcpiHwExtendedSleep (
+    UINT8                   SleepState);
+
+ACPI_STATUS
+AcpiHwExtendedWakePrep (
+    UINT8                   SleepState);
+
+ACPI_STATUS
+AcpiHwExtendedWake (
+    UINT8                   SleepState);
+
+
+/*
+ * hwvalid - Port I/O with validation
+ */
+ACPI_STATUS
+AcpiHwReadPort (
+    ACPI_IO_ADDRESS         Address,
+    UINT32                  *Value,
+    UINT32                  Width);
+
+ACPI_STATUS
+AcpiHwWritePort (
+    ACPI_IO_ADDRESS         Address,
+    UINT32                  Value,
+    UINT32                  Width);
+
+
+/*
+ * hwgpe - GPE support
+ */
+UINT32
+AcpiHwGetGpeRegisterBit (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo);
+
+ACPI_STATUS
+AcpiHwLowSetGpe (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo,
+    UINT32                  Action);
+
+ACPI_STATUS
+AcpiHwDisableGpeBlock (
+    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
+    ACPI_GPE_BLOCK_INFO     *GpeBlock,
+    void                    *Context);
+
+ACPI_STATUS
+AcpiHwClearGpe (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo);
+
+ACPI_STATUS
+AcpiHwClearGpeBlock (
+    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
+    ACPI_GPE_BLOCK_INFO     *GpeBlock,
+    void                    *Context);
+
+ACPI_STATUS
+AcpiHwGetGpeStatus (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo,
+    ACPI_EVENT_STATUS       *EventStatus);
+
+ACPI_STATUS
+AcpiHwDisableAllGpes (
+    void);
+
+ACPI_STATUS
+AcpiHwEnableAllRuntimeGpes (
+    void);
+
+ACPI_STATUS
+AcpiHwEnableAllWakeupGpes (
+    void);
+
+ACPI_STATUS
+AcpiHwEnableRuntimeGpeBlock (
+    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
+    ACPI_GPE_BLOCK_INFO     *GpeBlock,
+    void                    *Context);
+
+
+/*
+ * hwpci - PCI configuration support
+ */
+ACPI_STATUS
+AcpiHwDerivePciId (
+    ACPI_PCI_ID             *PciId,
+    ACPI_HANDLE             RootPciDevice,
+    ACPI_HANDLE             PciRegion);
+
+
+#endif /* __ACHWARE_H__ */

+ 756 - 0
kernel/include/acpica/acinterp.h

@@ -0,0 +1,756 @@
+/******************************************************************************
+ *
+ * Name: acinterp.h - Interpreter subcomponent prototypes and defines
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACINTERP_H__
+#define __ACINTERP_H__
+
+
+#define ACPI_WALK_OPERANDS          (&(WalkState->Operands [WalkState->NumOperands -1]))
+
+/* Macros for tables used for debug output */
+
+#define ACPI_EXD_OFFSET(f)          (UINT8) ACPI_OFFSET (ACPI_OPERAND_OBJECT,f)
+#define ACPI_EXD_NSOFFSET(f)        (UINT8) ACPI_OFFSET (ACPI_NAMESPACE_NODE,f)
+#define ACPI_EXD_TABLE_SIZE(name)   (sizeof(name) / sizeof (ACPI_EXDUMP_INFO))
+
+/*
+ * If possible, pack the following structures to byte alignment, since we
+ * don't care about performance for debug output. Two cases where we cannot
+ * pack the structures:
+ *
+ * 1) Hardware does not support misaligned memory transfers
+ * 2) Compiler does not support pointers within packed structures
+ */
+#if (!defined(ACPI_MISALIGNMENT_NOT_SUPPORTED) && !defined(ACPI_PACKED_POINTERS_NOT_SUPPORTED))
+#pragma pack(1)
+#endif
+
+typedef const struct acpi_exdump_info
+{
+    UINT8                   Opcode;
+    UINT8                   Offset;
+    char                    *Name;
+
+} ACPI_EXDUMP_INFO;
+
+/* Values for the Opcode field above */
+
+#define ACPI_EXD_INIT                   0
+#define ACPI_EXD_TYPE                   1
+#define ACPI_EXD_UINT8                  2
+#define ACPI_EXD_UINT16                 3
+#define ACPI_EXD_UINT32                 4
+#define ACPI_EXD_UINT64                 5
+#define ACPI_EXD_LITERAL                6
+#define ACPI_EXD_POINTER                7
+#define ACPI_EXD_ADDRESS                8
+#define ACPI_EXD_STRING                 9
+#define ACPI_EXD_BUFFER                 10
+#define ACPI_EXD_PACKAGE                11
+#define ACPI_EXD_FIELD                  12
+#define ACPI_EXD_REFERENCE              13
+#define ACPI_EXD_LIST                   14 /* Operand object list */
+#define ACPI_EXD_HDLR_LIST              15 /* Address Handler list */
+#define ACPI_EXD_RGN_LIST               16 /* Region list */
+#define ACPI_EXD_NODE                   17 /* Namespace Node */
+
+/* restore default alignment */
+
+#pragma pack()
+
+
+/*
+ * exconvrt - object conversion
+ */
+ACPI_STATUS
+AcpiExConvertToInteger (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     **ResultDesc,
+    UINT32                  Flags);
+
+ACPI_STATUS
+AcpiExConvertToBuffer (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     **ResultDesc);
+
+ACPI_STATUS
+AcpiExConvertToString (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     **ResultDesc,
+    UINT32                  Type);
+
+/* Types for ->String conversion */
+
+#define ACPI_EXPLICIT_BYTE_COPY         0x00000000
+#define ACPI_EXPLICIT_CONVERT_HEX       0x00000001
+#define ACPI_IMPLICIT_CONVERT_HEX       0x00000002
+#define ACPI_EXPLICIT_CONVERT_DECIMAL   0x00000003
+
+ACPI_STATUS
+AcpiExConvertToTargetType (
+    ACPI_OBJECT_TYPE        DestinationType,
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_OPERAND_OBJECT     **ResultDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * exdebug - AML debug object
+ */
+void
+AcpiExDoDebugObject (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    UINT32                  Level,
+    UINT32                  Index);
+
+void
+AcpiExStartTraceMethod (
+    ACPI_NAMESPACE_NODE     *MethodNode,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiExStopTraceMethod (
+    ACPI_NAMESPACE_NODE     *MethodNode,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiExStartTraceOpcode (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiExStopTraceOpcode (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiExTracePoint (
+    ACPI_TRACE_EVENT_TYPE   Type,
+    BOOLEAN                 Begin,
+    UINT8                   *Aml,
+    char                    *Pathname);
+
+
+/*
+ * exfield - ACPI AML (p-code) execution - field manipulation
+ */
+ACPI_STATUS
+AcpiExCommonBufferSetup (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    UINT32                  BufferLength,
+    UINT32                  *DatumCount);
+
+ACPI_STATUS
+AcpiExWriteWithUpdateRule (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    UINT64                  Mask,
+    UINT64                  FieldValue,
+    UINT32                  FieldDatumByteOffset);
+
+void
+AcpiExGetBufferDatum(
+    UINT64                  *Datum,
+    void                    *Buffer,
+    UINT32                  BufferLength,
+    UINT32                  ByteGranularity,
+    UINT32                  BufferOffset);
+
+void
+AcpiExSetBufferDatum (
+    UINT64                  MergedDatum,
+    void                    *Buffer,
+    UINT32                  BufferLength,
+    UINT32                  ByteGranularity,
+    UINT32                  BufferOffset);
+
+ACPI_STATUS
+AcpiExReadDataFromField (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     **RetBufferDesc);
+
+ACPI_STATUS
+AcpiExWriteDataToField (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     **ResultDesc);
+
+
+/*
+ * exfldio - low level field I/O
+ */
+ACPI_STATUS
+AcpiExExtractFromField (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    void                    *Buffer,
+    UINT32                  BufferLength);
+
+ACPI_STATUS
+AcpiExInsertIntoField (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    void                    *Buffer,
+    UINT32                  BufferLength);
+
+ACPI_STATUS
+AcpiExAccessRegion (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    UINT32                  FieldDatumByteOffset,
+    UINT64                  *Value,
+    UINT32                  ReadWrite);
+
+
+/*
+ * exmisc - misc support routines
+ */
+ACPI_STATUS
+AcpiExGetObjectReference (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     **ReturnDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExConcatTemplate (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     *ObjDesc2,
+    ACPI_OPERAND_OBJECT     **ActualReturnDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExDoConcatenate (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     *ObjDesc2,
+    ACPI_OPERAND_OBJECT     **ActualReturnDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExDoLogicalNumericOp (
+    UINT16                  Opcode,
+    UINT64                  Integer0,
+    UINT64                  Integer1,
+    BOOLEAN                 *LogicalResult);
+
+ACPI_STATUS
+AcpiExDoLogicalOp (
+    UINT16                  Opcode,
+    ACPI_OPERAND_OBJECT     *Operand0,
+    ACPI_OPERAND_OBJECT     *Operand1,
+    BOOLEAN                 *LogicalResult);
+
+UINT64
+AcpiExDoMathOp (
+    UINT16                  Opcode,
+    UINT64                  Operand0,
+    UINT64                  Operand1);
+
+ACPI_STATUS
+AcpiExCreateMutex (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExCreateProcessor (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExCreatePowerResource (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExCreateRegion (
+    UINT8                   *AmlStart,
+    UINT32                  AmlLength,
+    UINT8                   RegionSpace,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExCreateEvent (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExCreateAlias (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExCreateMethod (
+    UINT8                   *AmlStart,
+    UINT32                  AmlLength,
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * exconfig - dynamic table load/unload
+ */
+ACPI_STATUS
+AcpiExLoadOp (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     *Target,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExLoadTableOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OPERAND_OBJECT     **ReturnDesc);
+
+ACPI_STATUS
+AcpiExUnloadTable (
+    ACPI_OPERAND_OBJECT     *DdbHandle);
+
+
+/*
+ * exmutex - mutex support
+ */
+ACPI_STATUS
+AcpiExAcquireMutex (
+    ACPI_OPERAND_OBJECT     *TimeDesc,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExAcquireMutexObject (
+    UINT16                  Timeout,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_THREAD_ID          ThreadId);
+
+ACPI_STATUS
+AcpiExReleaseMutex (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExReleaseMutexObject (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+void
+AcpiExReleaseAllMutexes (
+    ACPI_THREAD_STATE       *Thread);
+
+void
+AcpiExUnlinkMutex (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+
+/*
+ * exprep - ACPI AML execution - prep utilities
+ */
+ACPI_STATUS
+AcpiExPrepCommonFieldObject (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    UINT8                   FieldFlags,
+    UINT8                   FieldAttribute,
+    UINT32                  FieldBitPosition,
+    UINT32                  FieldBitLength);
+
+ACPI_STATUS
+AcpiExPrepFieldValue (
+    ACPI_CREATE_FIELD_INFO  *Info);
+
+
+/*
+ * exsystem - Interface to OS services
+ */
+ACPI_STATUS
+AcpiExSystemDoNotifyOp (
+    ACPI_OPERAND_OBJECT     *Value,
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiExSystemDoSleep(
+    UINT64                  Time);
+
+ACPI_STATUS
+AcpiExSystemDoStall (
+    UINT32                  Time);
+
+ACPI_STATUS
+AcpiExSystemSignalEvent(
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiExSystemWaitEvent(
+    ACPI_OPERAND_OBJECT     *Time,
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiExSystemResetEvent(
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiExSystemWaitSemaphore (
+    ACPI_SEMAPHORE          Semaphore,
+    UINT16                  Timeout);
+
+ACPI_STATUS
+AcpiExSystemWaitMutex (
+    ACPI_MUTEX              Mutex,
+    UINT16                  Timeout);
+
+/*
+ * exoparg1 - ACPI AML execution, 1 operand
+ */
+ACPI_STATUS
+AcpiExOpcode_0A_0T_1R (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExOpcode_1A_0T_0R (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExOpcode_1A_0T_1R (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExOpcode_1A_1T_1R (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExOpcode_1A_1T_0R (
+    ACPI_WALK_STATE         *WalkState);
+
+/*
+ * exoparg2 - ACPI AML execution, 2 operands
+ */
+ACPI_STATUS
+AcpiExOpcode_2A_0T_0R (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExOpcode_2A_0T_1R (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExOpcode_2A_1T_1R (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExOpcode_2A_2T_1R (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * exoparg3 - ACPI AML execution, 3 operands
+ */
+ACPI_STATUS
+AcpiExOpcode_3A_0T_0R (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExOpcode_3A_1T_1R (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * exoparg6 - ACPI AML execution, 6 operands
+ */
+ACPI_STATUS
+AcpiExOpcode_6A_0T_1R (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * exresolv - Object resolution and get value functions
+ */
+ACPI_STATUS
+AcpiExResolveToValue (
+    ACPI_OPERAND_OBJECT     **StackPtr,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExResolveMultiple (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OPERAND_OBJECT     *Operand,
+    ACPI_OBJECT_TYPE        *ReturnType,
+    ACPI_OPERAND_OBJECT     **ReturnDesc);
+
+
+/*
+ * exresnte - resolve namespace node
+ */
+ACPI_STATUS
+AcpiExResolveNodeToValue (
+    ACPI_NAMESPACE_NODE     **StackPtr,
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * exresop - resolve operand to value
+ */
+ACPI_STATUS
+AcpiExResolveOperands (
+    UINT16                  Opcode,
+    ACPI_OPERAND_OBJECT     **StackPtr,
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * exdump - Interpreter debug output routines
+ */
+void
+AcpiExDumpOperand (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    UINT32                  Depth);
+
+void
+AcpiExDumpOperands (
+    ACPI_OPERAND_OBJECT     **Operands,
+    const char              *OpcodeName,
+    UINT32                  NumOpcodes);
+
+void
+AcpiExDumpObjectDescriptor (
+    ACPI_OPERAND_OBJECT     *Object,
+    UINT32                  Flags);
+
+void
+AcpiExDumpNamespaceNode (
+    ACPI_NAMESPACE_NODE     *Node,
+    UINT32                  Flags);
+
+
+/*
+ * exnames - AML namestring support
+ */
+ACPI_STATUS
+AcpiExGetNameString (
+    ACPI_OBJECT_TYPE        DataType,
+    UINT8                   *InAmlAddress,
+    char                    **OutNameString,
+    UINT32                  *OutNameLength);
+
+
+/*
+ * exstore - Object store support
+ */
+ACPI_STATUS
+AcpiExStore (
+    ACPI_OPERAND_OBJECT     *ValDesc,
+    ACPI_OPERAND_OBJECT     *DestDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExStoreObjectToNode (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_WALK_STATE         *WalkState,
+    UINT8                   ImplicitConversion);
+
+#define ACPI_IMPLICIT_CONVERSION        TRUE
+#define ACPI_NO_IMPLICIT_CONVERSION     FALSE
+
+
+/*
+ * exstoren - resolve/store object
+ */
+ACPI_STATUS
+AcpiExResolveObject (
+    ACPI_OPERAND_OBJECT     **SourceDescPtr,
+    ACPI_OBJECT_TYPE        TargetType,
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiExStoreObjectToObject (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_OPERAND_OBJECT     *DestDesc,
+    ACPI_OPERAND_OBJECT     **NewDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * exstorob - store object - buffer/string
+ */
+ACPI_STATUS
+AcpiExStoreBufferToBuffer (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_OPERAND_OBJECT     *TargetDesc);
+
+ACPI_STATUS
+AcpiExStoreStringToString (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_OPERAND_OBJECT     *TargetDesc);
+
+
+/*
+ * excopy - object copy
+ */
+ACPI_STATUS
+AcpiExCopyIntegerToIndexField (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_OPERAND_OBJECT     *TargetDesc);
+
+ACPI_STATUS
+AcpiExCopyIntegerToBankField (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_OPERAND_OBJECT     *TargetDesc);
+
+ACPI_STATUS
+AcpiExCopyDataToNamedField (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_NAMESPACE_NODE     *Node);
+
+ACPI_STATUS
+AcpiExCopyIntegerToBufferField (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_OPERAND_OBJECT     *TargetDesc);
+
+
+/*
+ * exutils - interpreter/scanner utilities
+ */
+void
+AcpiExEnterInterpreter (
+    void);
+
+void
+AcpiExExitInterpreter (
+    void);
+
+BOOLEAN
+AcpiExTruncateFor32bitTable (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+void
+AcpiExAcquireGlobalLock (
+    UINT32                  Rule);
+
+void
+AcpiExReleaseGlobalLock (
+    UINT32                  Rule);
+
+void
+AcpiExEisaIdToString (
+    char                    *Dest,
+    UINT64                  CompressedId);
+
+void
+AcpiExIntegerToString (
+    char                    *Dest,
+    UINT64                  Value);
+
+void
+AcpiExPciClsToString (
+    char                    *Dest,
+    UINT8                   ClassCode[3]);
+
+BOOLEAN
+AcpiIsValidSpaceId (
+    UINT8                   SpaceId);
+
+
+/*
+ * exregion - default OpRegion handlers
+ */
+ACPI_STATUS
+AcpiExSystemMemorySpaceHandler (
+    UINT32                  Function,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT32                  BitWidth,
+    UINT64                  *Value,
+    void                    *HandlerContext,
+    void                    *RegionContext);
+
+ACPI_STATUS
+AcpiExSystemIoSpaceHandler (
+    UINT32                  Function,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT32                  BitWidth,
+    UINT64                  *Value,
+    void                    *HandlerContext,
+    void                    *RegionContext);
+
+ACPI_STATUS
+AcpiExPciConfigSpaceHandler (
+    UINT32                  Function,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT32                  BitWidth,
+    UINT64                  *Value,
+    void                    *HandlerContext,
+    void                    *RegionContext);
+
+ACPI_STATUS
+AcpiExCmosSpaceHandler (
+    UINT32                  Function,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT32                  BitWidth,
+    UINT64                  *Value,
+    void                    *HandlerContext,
+    void                    *RegionContext);
+
+ACPI_STATUS
+AcpiExPciBarSpaceHandler (
+    UINT32                  Function,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT32                  BitWidth,
+    UINT64                  *Value,
+    void                    *HandlerContext,
+    void                    *RegionContext);
+
+ACPI_STATUS
+AcpiExEmbeddedControllerSpaceHandler (
+    UINT32                  Function,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT32                  BitWidth,
+    UINT64                  *Value,
+    void                    *HandlerContext,
+    void                    *RegionContext);
+
+ACPI_STATUS
+AcpiExSmBusSpaceHandler (
+    UINT32                  Function,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT32                  BitWidth,
+    UINT64                  *Value,
+    void                    *HandlerContext,
+    void                    *RegionContext);
+
+
+ACPI_STATUS
+AcpiExDataTableSpaceHandler (
+    UINT32                  Function,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT32                  BitWidth,
+    UINT64                  *Value,
+    void                    *HandlerContext,
+    void                    *RegionContext);
+
+#endif /* __INTERP_H__ */

+ 1438 - 0
kernel/include/acpica/aclocal.h

@@ -0,0 +1,1438 @@
+/******************************************************************************
+ *
+ * Name: aclocal.h - Internal data types used across the ACPI subsystem
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACLOCAL_H__
+#define __ACLOCAL_H__
+
+
+/* acpisrc:StructDefs -- for acpisrc conversion */
+
+#define ACPI_SERIALIZED                 0xFF
+
+typedef UINT32                          ACPI_MUTEX_HANDLE;
+#define ACPI_GLOBAL_LOCK                (ACPI_SEMAPHORE) (-1)
+
+/* Total number of aml opcodes defined */
+
+#define AML_NUM_OPCODES                 0x82
+
+
+/* Forward declarations */
+
+struct acpi_walk_state;
+struct acpi_obj_mutex;
+union acpi_parse_object;
+
+
+/*****************************************************************************
+ *
+ * Mutex typedefs and structs
+ *
+ ****************************************************************************/
+
+
+/*
+ * Predefined handles for the mutex objects used within the subsystem
+ * All mutex objects are automatically created by AcpiUtMutexInitialize.
+ *
+ * The acquire/release ordering protocol is implied via this list. Mutexes
+ * with a lower value must be acquired before mutexes with a higher value.
+ *
+ * NOTE: any changes here must be reflected in the AcpiGbl_MutexNames
+ * table below also!
+ */
+#define ACPI_MTX_INTERPRETER            0   /* AML Interpreter, main lock */
+#define ACPI_MTX_NAMESPACE              1   /* ACPI Namespace */
+#define ACPI_MTX_TABLES                 2   /* Data for ACPI tables */
+#define ACPI_MTX_EVENTS                 3   /* Data for ACPI events */
+#define ACPI_MTX_CACHES                 4   /* Internal caches, general purposes */
+#define ACPI_MTX_MEMORY                 5   /* Debug memory tracking lists */
+
+#define ACPI_MAX_MUTEX                  5
+#define ACPI_NUM_MUTEX                  ACPI_MAX_MUTEX+1
+
+
+/* Lock structure for reader/writer interfaces */
+
+typedef struct acpi_rw_lock
+{
+    ACPI_MUTEX              WriterMutex;
+    ACPI_MUTEX              ReaderMutex;
+    UINT32                  NumReaders;
+
+} ACPI_RW_LOCK;
+
+
+/*
+ * Predefined handles for spinlocks used within the subsystem.
+ * These spinlocks are created by AcpiUtMutexInitialize
+ */
+#define ACPI_LOCK_GPES                  0
+#define ACPI_LOCK_HARDWARE              1
+
+#define ACPI_MAX_LOCK                   1
+#define ACPI_NUM_LOCK                   ACPI_MAX_LOCK+1
+
+
+/* This Thread ID means that the mutex is not in use (unlocked) */
+
+#define ACPI_MUTEX_NOT_ACQUIRED         (ACPI_THREAD_ID) -1
+
+/* This Thread ID means an invalid thread ID */
+
+#ifdef ACPI_OS_INVALID_THREAD_ID
+#define ACPI_INVALID_THREAD_ID          ACPI_OS_INVALID_THREAD_ID
+#else
+#define ACPI_INVALID_THREAD_ID          ((ACPI_THREAD_ID) 0xFFFFFFFF)
+#endif
+
+/* Table for the global mutexes */
+
+typedef struct acpi_mutex_info
+{
+    ACPI_MUTEX                      Mutex;
+    UINT32                          UseCount;
+    ACPI_THREAD_ID                  ThreadId;
+
+} ACPI_MUTEX_INFO;
+
+
+/* Lock flag parameter for various interfaces */
+
+#define ACPI_MTX_DO_NOT_LOCK            0
+#define ACPI_MTX_LOCK                   1
+
+
+/* Field access granularities */
+
+#define ACPI_FIELD_BYTE_GRANULARITY     1
+#define ACPI_FIELD_WORD_GRANULARITY     2
+#define ACPI_FIELD_DWORD_GRANULARITY    4
+#define ACPI_FIELD_QWORD_GRANULARITY    8
+
+
+#define ACPI_ENTRY_NOT_FOUND            NULL
+
+
+/*****************************************************************************
+ *
+ * Namespace typedefs and structs
+ *
+ ****************************************************************************/
+
+/* Operational modes of the AML interpreter/scanner */
+
+typedef enum
+{
+    ACPI_IMODE_LOAD_PASS1           = 0x01,
+    ACPI_IMODE_LOAD_PASS2           = 0x02,
+    ACPI_IMODE_EXECUTE              = 0x03
+
+} ACPI_INTERPRETER_MODE;
+
+
+/*
+ * The Namespace Node describes a named object that appears in the AML.
+ * DescriptorType is used to differentiate between internal descriptors.
+ *
+ * The node is optimized for both 32-bit and 64-bit platforms:
+ * 20 bytes for the 32-bit case, 32 bytes for the 64-bit case.
+ *
+ * Note: The DescriptorType and Type fields must appear in the identical
+ * position in both the ACPI_NAMESPACE_NODE and ACPI_OPERAND_OBJECT
+ * structures.
+ */
+typedef struct acpi_namespace_node
+{
+    union acpi_operand_object       *Object;        /* Interpreter object */
+    UINT8                           DescriptorType; /* Differentiate object descriptor types */
+    UINT8                           Type;           /* ACPI Type associated with this name */
+    UINT8                           Flags;          /* Miscellaneous flags */
+    ACPI_OWNER_ID                   OwnerId;        /* Node creator */
+    ACPI_NAME_UNION                 Name;           /* ACPI Name, always 4 chars per ACPI spec */
+    struct acpi_namespace_node      *Parent;        /* Parent node */
+    struct acpi_namespace_node      *Child;         /* First child */
+    struct acpi_namespace_node      *Peer;          /* First peer */
+
+    /*
+     * The following fields are used by the ASL compiler and disassembler only
+     */
+#ifdef ACPI_LARGE_NAMESPACE_NODE
+    union acpi_parse_object         *Op;
+    void                            *MethodLocals;
+    void                            *MethodArgs;
+    UINT32                          Value;
+    UINT32                          Length;
+    UINT8                           ArgCount;
+
+#endif
+
+} ACPI_NAMESPACE_NODE;
+
+
+/* Namespace Node flags */
+
+#define ANOBJ_RESERVED                  0x01    /* Available for use */
+#define ANOBJ_TEMPORARY                 0x02    /* Node is create by a method and is temporary */
+#define ANOBJ_METHOD_ARG                0x04    /* Node is a method argument */
+#define ANOBJ_METHOD_LOCAL              0x08    /* Node is a method local */
+#define ANOBJ_SUBTREE_HAS_INI           0x10    /* Used to optimize device initialization */
+#define ANOBJ_EVALUATED                 0x20    /* Set on first evaluation of node */
+#define ANOBJ_ALLOCATED_BUFFER          0x40    /* Method AML buffer is dynamic (InstallMethod) */
+
+#define ANOBJ_IS_EXTERNAL               0x08    /* iASL only: This object created via External() */
+#define ANOBJ_METHOD_NO_RETVAL          0x10    /* iASL only: Method has no return value */
+#define ANOBJ_METHOD_SOME_NO_RETVAL     0x20    /* iASL only: Method has at least one return value */
+#define ANOBJ_IS_REFERENCED             0x80    /* iASL only: Object was referenced */
+
+
+/* Internal ACPI table management - master table list */
+
+typedef struct acpi_table_list
+{
+    ACPI_TABLE_DESC                 *Tables;            /* Table descriptor array */
+    UINT32                          CurrentTableCount;  /* Tables currently in the array */
+    UINT32                          MaxTableCount;      /* Max tables array will hold */
+    UINT8                           Flags;
+
+} ACPI_TABLE_LIST;
+
+/* Flags for above */
+
+#define ACPI_ROOT_ORIGIN_UNKNOWN        (0)     /* ~ORIGIN_ALLOCATED */
+#define ACPI_ROOT_ORIGIN_ALLOCATED      (1)
+#define ACPI_ROOT_ALLOW_RESIZE          (2)
+
+
+/* List to manage incoming ACPI tables */
+
+typedef struct acpi_new_table_desc
+{
+    ACPI_TABLE_HEADER               *Table;
+    struct acpi_new_table_desc      *Next;
+
+} ACPI_NEW_TABLE_DESC;
+
+
+/* Predefined table indexes */
+
+#define ACPI_INVALID_TABLE_INDEX        (0xFFFFFFFF)
+
+
+typedef struct acpi_find_context
+{
+    char                            *SearchFor;
+    ACPI_HANDLE                     *List;
+    UINT32                          *Count;
+
+} ACPI_FIND_CONTEXT;
+
+
+typedef struct acpi_ns_search_data
+{
+    ACPI_NAMESPACE_NODE             *Node;
+
+} ACPI_NS_SEARCH_DATA;
+
+
+/* Object types used during package copies */
+
+#define ACPI_COPY_TYPE_SIMPLE           0
+#define ACPI_COPY_TYPE_PACKAGE          1
+
+
+/* Info structure used to convert external<->internal namestrings */
+
+typedef struct acpi_namestring_info
+{
+    const char                      *ExternalName;
+    const char                      *NextExternalChar;
+    char                            *InternalName;
+    UINT32                          Length;
+    UINT32                          NumSegments;
+    UINT32                          NumCarats;
+    BOOLEAN                         FullyQualified;
+
+} ACPI_NAMESTRING_INFO;
+
+
+/* Field creation info */
+
+typedef struct acpi_create_field_info
+{
+    ACPI_NAMESPACE_NODE             *RegionNode;
+    ACPI_NAMESPACE_NODE             *FieldNode;
+    ACPI_NAMESPACE_NODE             *RegisterNode;
+    ACPI_NAMESPACE_NODE             *DataRegisterNode;
+    ACPI_NAMESPACE_NODE             *ConnectionNode;
+    UINT8                           *ResourceBuffer;
+    UINT32                          BankValue;
+    UINT32                          FieldBitPosition;
+    UINT32                          FieldBitLength;
+    UINT16                          ResourceLength;
+    UINT16                          PinNumberIndex;
+    UINT8                           FieldFlags;
+    UINT8                           Attribute;
+    UINT8                           FieldType;
+    UINT8                           AccessLength;
+
+} ACPI_CREATE_FIELD_INFO;
+
+
+typedef
+ACPI_STATUS (*ACPI_INTERNAL_METHOD) (
+    struct acpi_walk_state          *WalkState);
+
+
+/*
+ * Bitmapped ACPI types. Used internally only
+ */
+#define ACPI_BTYPE_ANY                  0x00000000
+#define ACPI_BTYPE_INTEGER              0x00000001
+#define ACPI_BTYPE_STRING               0x00000002
+#define ACPI_BTYPE_BUFFER               0x00000004
+#define ACPI_BTYPE_PACKAGE              0x00000008
+#define ACPI_BTYPE_FIELD_UNIT           0x00000010
+#define ACPI_BTYPE_DEVICE               0x00000020
+#define ACPI_BTYPE_EVENT                0x00000040
+#define ACPI_BTYPE_METHOD               0x00000080
+#define ACPI_BTYPE_MUTEX                0x00000100
+#define ACPI_BTYPE_REGION               0x00000200
+#define ACPI_BTYPE_POWER                0x00000400
+#define ACPI_BTYPE_PROCESSOR            0x00000800
+#define ACPI_BTYPE_THERMAL              0x00001000
+#define ACPI_BTYPE_BUFFER_FIELD         0x00002000
+#define ACPI_BTYPE_DDB_HANDLE           0x00004000
+#define ACPI_BTYPE_DEBUG_OBJECT         0x00008000
+#define ACPI_BTYPE_REFERENCE_OBJECT     0x00010000 /* From Index(), RefOf(), etc (Type6Opcodes) */
+#define ACPI_BTYPE_RESOURCE             0x00020000
+#define ACPI_BTYPE_NAMED_REFERENCE      0x00040000 /* Generic unresolved Name or Namepath */
+
+#define ACPI_BTYPE_COMPUTE_DATA         (ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER)
+
+#define ACPI_BTYPE_DATA                 (ACPI_BTYPE_COMPUTE_DATA  | ACPI_BTYPE_PACKAGE)
+
+    /* Used by Copy, DeRefOf, Store, Printf, Fprintf */
+
+#define ACPI_BTYPE_DATA_REFERENCE       (ACPI_BTYPE_DATA | ACPI_BTYPE_REFERENCE_OBJECT | ACPI_BTYPE_DDB_HANDLE)
+#define ACPI_BTYPE_DEVICE_OBJECTS       (ACPI_BTYPE_DEVICE | ACPI_BTYPE_THERMAL | ACPI_BTYPE_PROCESSOR)
+#define ACPI_BTYPE_OBJECTS_AND_REFS     0x0001FFFF  /* ARG or LOCAL */
+#define ACPI_BTYPE_ALL_OBJECTS          0x0000FFFF
+
+#pragma pack(1)
+
+/*
+ * Information structure for ACPI predefined names.
+ * Each entry in the table contains the following items:
+ *
+ * Name                 - The ACPI reserved name
+ * ParamCount           - Number of arguments to the method
+ * ExpectedReturnBtypes - Allowed type(s) for the return value
+ */
+typedef struct acpi_name_info
+{
+    char                        Name[ACPI_NAME_SIZE];
+    UINT16                      ArgumentList;
+    UINT8                       ExpectedBtypes;
+
+} ACPI_NAME_INFO;
+
+/*
+ * Secondary information structures for ACPI predefined objects that return
+ * package objects. This structure appears as the next entry in the table
+ * after the NAME_INFO structure above.
+ *
+ * The reason for this is to minimize the size of the predefined name table.
+ */
+
+/*
+ * Used for ACPI_PTYPE1_FIXED, ACPI_PTYPE1_VAR, ACPI_PTYPE2,
+ * ACPI_PTYPE2_MIN, ACPI_PTYPE2_PKG_COUNT, ACPI_PTYPE2_COUNT,
+ * ACPI_PTYPE2_FIX_VAR
+ */
+typedef struct acpi_package_info
+{
+    UINT8                       Type;
+    UINT8                       ObjectType1;
+    UINT8                       Count1;
+    UINT8                       ObjectType2;
+    UINT8                       Count2;
+    UINT16                      Reserved;
+
+} ACPI_PACKAGE_INFO;
+
+/* Used for ACPI_PTYPE2_FIXED */
+
+typedef struct acpi_package_info2
+{
+    UINT8                       Type;
+    UINT8                       Count;
+    UINT8                       ObjectType[4];
+    UINT8                       Reserved;
+
+} ACPI_PACKAGE_INFO2;
+
+/* Used for ACPI_PTYPE1_OPTION */
+
+typedef struct acpi_package_info3
+{
+    UINT8                       Type;
+    UINT8                       Count;
+    UINT8                       ObjectType[2];
+    UINT8                       TailObjectType;
+    UINT16                      Reserved;
+
+} ACPI_PACKAGE_INFO3;
+
+typedef struct acpi_package_info4
+{
+    UINT8                       Type;
+    UINT8                       ObjectType1;
+    UINT8                       Count1;
+    UINT8                       SubObjectTypes;
+    UINT8                       PkgCount;
+    UINT16                      Reserved;
+
+} ACPI_PACKAGE_INFO4;
+
+typedef union acpi_predefined_info
+{
+    ACPI_NAME_INFO              Info;
+    ACPI_PACKAGE_INFO           RetInfo;
+    ACPI_PACKAGE_INFO2          RetInfo2;
+    ACPI_PACKAGE_INFO3          RetInfo3;
+    ACPI_PACKAGE_INFO4          RetInfo4;
+
+} ACPI_PREDEFINED_INFO;
+
+/* Reset to default packing */
+
+#pragma pack()
+
+
+/* Return object auto-repair info */
+
+typedef ACPI_STATUS (*ACPI_OBJECT_CONVERTER) (
+    struct acpi_namespace_node  *Scope,
+    union acpi_operand_object   *OriginalObject,
+    union acpi_operand_object   **ConvertedObject);
+
+typedef struct acpi_simple_repair_info
+{
+    char                        Name[ACPI_NAME_SIZE];
+    UINT32                      UnexpectedBtypes;
+    UINT32                      PackageIndex;
+    ACPI_OBJECT_CONVERTER       ObjectConverter;
+
+} ACPI_SIMPLE_REPAIR_INFO;
+
+
+/*
+ * Bitmapped return value types
+ * Note: the actual data types must be contiguous, a loop in nspredef.c
+ * depends on this.
+ */
+#define ACPI_RTYPE_ANY                  0x00
+#define ACPI_RTYPE_NONE                 0x01
+#define ACPI_RTYPE_INTEGER              0x02
+#define ACPI_RTYPE_STRING               0x04
+#define ACPI_RTYPE_BUFFER               0x08
+#define ACPI_RTYPE_PACKAGE              0x10
+#define ACPI_RTYPE_REFERENCE            0x20
+#define ACPI_RTYPE_ALL                  0x3F
+
+#define ACPI_NUM_RTYPES                 5   /* Number of actual object types */
+
+
+/* Info for running the _REG methods */
+
+typedef struct acpi_reg_walk_info
+{
+    ACPI_ADR_SPACE_TYPE     SpaceId;
+    UINT32                  Function;
+    UINT32                  RegRunCount;
+
+} ACPI_REG_WALK_INFO;
+
+
+/*****************************************************************************
+ *
+ * Event typedefs and structs
+ *
+ ****************************************************************************/
+
+/* Dispatch info for each host-installed SCI handler */
+
+typedef struct acpi_sci_handler_info
+{
+    struct acpi_sci_handler_info    *Next;
+    ACPI_SCI_HANDLER                Address;        /* Address of handler */
+    void                            *Context;       /* Context to be passed to handler */
+
+} ACPI_SCI_HANDLER_INFO;
+
+/* Dispatch info for each GPE -- either a method or handler, cannot be both */
+
+typedef struct acpi_gpe_handler_info
+{
+    ACPI_GPE_HANDLER                Address;        /* Address of handler, if any */
+    void                            *Context;       /* Context to be passed to handler */
+    ACPI_NAMESPACE_NODE             *MethodNode;    /* Method node for this GPE level (saved) */
+    UINT8                           OriginalFlags;  /* Original (pre-handler) GPE info */
+    BOOLEAN                         OriginallyEnabled; /* True if GPE was originally enabled */
+
+} ACPI_GPE_HANDLER_INFO;
+
+/* Notify info for implicit notify, multiple device objects */
+
+typedef struct acpi_gpe_notify_info
+{
+    ACPI_NAMESPACE_NODE             *DeviceNode;    /* Device to be notified */
+    struct acpi_gpe_notify_info     *Next;
+
+} ACPI_GPE_NOTIFY_INFO;
+
+/*
+ * GPE dispatch info. At any time, the GPE can have at most one type
+ * of dispatch - Method, Handler, or Implicit Notify.
+ */
+typedef union acpi_gpe_dispatch_info
+{
+    ACPI_NAMESPACE_NODE             *MethodNode;    /* Method node for this GPE level */
+    ACPI_GPE_HANDLER_INFO           *Handler;       /* Installed GPE handler */
+    ACPI_GPE_NOTIFY_INFO            *NotifyList;    /* List of _PRW devices for implicit notifies */
+
+} ACPI_GPE_DISPATCH_INFO;
+
+/*
+ * Information about a GPE, one per each GPE in an array.
+ * NOTE: Important to keep this struct as small as possible.
+ */
+typedef struct acpi_gpe_event_info
+{
+    union acpi_gpe_dispatch_info    Dispatch;       /* Either Method, Handler, or NotifyList */
+    struct acpi_gpe_register_info   *RegisterInfo;  /* Backpointer to register info */
+    UINT8                           Flags;          /* Misc info about this GPE */
+    UINT8                           GpeNumber;      /* This GPE */
+    UINT8                           RuntimeCount;   /* References to a run GPE */
+
+} ACPI_GPE_EVENT_INFO;
+
+/* Information about a GPE register pair, one per each status/enable pair in an array */
+
+typedef struct acpi_gpe_register_info
+{
+    ACPI_GENERIC_ADDRESS            StatusAddress;  /* Address of status reg */
+    ACPI_GENERIC_ADDRESS            EnableAddress;  /* Address of enable reg */
+    UINT16                          BaseGpeNumber;  /* Base GPE number for this register */
+    UINT8                           EnableForWake;  /* GPEs to keep enabled when sleeping */
+    UINT8                           EnableForRun;   /* GPEs to keep enabled when running */
+    UINT8                           EnableMask;     /* Current mask of enabled GPEs */
+
+} ACPI_GPE_REGISTER_INFO;
+
+/*
+ * Information about a GPE register block, one per each installed block --
+ * GPE0, GPE1, and one per each installed GPE Block Device.
+ */
+typedef struct acpi_gpe_block_info
+{
+    ACPI_NAMESPACE_NODE             *Node;
+    struct acpi_gpe_block_info      *Previous;
+    struct acpi_gpe_block_info      *Next;
+    struct acpi_gpe_xrupt_info      *XruptBlock;    /* Backpointer to interrupt block */
+    ACPI_GPE_REGISTER_INFO          *RegisterInfo;  /* One per GPE register pair */
+    ACPI_GPE_EVENT_INFO             *EventInfo;     /* One for each GPE */
+    UINT64                          Address;        /* Base address of the block */
+    UINT32                          RegisterCount;  /* Number of register pairs in block */
+    UINT16                          GpeCount;       /* Number of individual GPEs in block */
+    UINT16                          BlockBaseNumber;/* Base GPE number for this block */
+    UINT8                           SpaceId;
+    BOOLEAN                         Initialized;    /* TRUE if this block is initialized */
+
+} ACPI_GPE_BLOCK_INFO;
+
+/* Information about GPE interrupt handlers, one per each interrupt level used for GPEs */
+
+typedef struct acpi_gpe_xrupt_info
+{
+    struct acpi_gpe_xrupt_info      *Previous;
+    struct acpi_gpe_xrupt_info      *Next;
+    ACPI_GPE_BLOCK_INFO             *GpeBlockListHead;  /* List of GPE blocks for this xrupt */
+    UINT32                          InterruptNumber;    /* System interrupt number */
+
+} ACPI_GPE_XRUPT_INFO;
+
+typedef struct acpi_gpe_walk_info
+{
+    ACPI_NAMESPACE_NODE             *GpeDevice;
+    ACPI_GPE_BLOCK_INFO             *GpeBlock;
+    UINT16                          Count;
+    ACPI_OWNER_ID                   OwnerId;
+    BOOLEAN                         ExecuteByOwnerId;
+
+} ACPI_GPE_WALK_INFO;
+
+typedef struct acpi_gpe_device_info
+{
+    UINT32                          Index;
+    UINT32                          NextBlockBaseIndex;
+    ACPI_STATUS                     Status;
+    ACPI_NAMESPACE_NODE             *GpeDevice;
+
+} ACPI_GPE_DEVICE_INFO;
+
+typedef ACPI_STATUS (*ACPI_GPE_CALLBACK) (
+    ACPI_GPE_XRUPT_INFO             *GpeXruptInfo,
+    ACPI_GPE_BLOCK_INFO             *GpeBlock,
+    void                            *Context);
+
+
+/* Information about each particular fixed event */
+
+typedef struct acpi_fixed_event_handler
+{
+    ACPI_EVENT_HANDLER              Handler;        /* Address of handler. */
+    void                            *Context;       /* Context to be passed to handler */
+
+} ACPI_FIXED_EVENT_HANDLER;
+
+typedef struct acpi_fixed_event_info
+{
+    UINT8                           StatusRegisterId;
+    UINT8                           EnableRegisterId;
+    UINT16                          StatusBitMask;
+    UINT16                          EnableBitMask;
+
+} ACPI_FIXED_EVENT_INFO;
+
+/* Information used during field processing */
+
+typedef struct acpi_field_info
+{
+    UINT8                           SkipField;
+    UINT8                           FieldFlag;
+    UINT32                          PkgLength;
+
+} ACPI_FIELD_INFO;
+
+
+/*****************************************************************************
+ *
+ * Generic "state" object for stacks
+ *
+ ****************************************************************************/
+
+#define ACPI_CONTROL_NORMAL                  0xC0
+#define ACPI_CONTROL_CONDITIONAL_EXECUTING   0xC1
+#define ACPI_CONTROL_PREDICATE_EXECUTING     0xC2
+#define ACPI_CONTROL_PREDICATE_FALSE         0xC3
+#define ACPI_CONTROL_PREDICATE_TRUE          0xC4
+
+
+#define ACPI_STATE_COMMON \
+    void                            *Next; \
+    UINT8                           DescriptorType; /* To differentiate various internal objs */\
+    UINT8                           Flags; \
+    UINT16                          Value; \
+    UINT16                          State;
+
+    /* There are 2 bytes available here until the next natural alignment boundary */
+
+typedef struct acpi_common_state
+{
+    ACPI_STATE_COMMON
+} ACPI_COMMON_STATE;
+
+
+/*
+ * Update state - used to traverse complex objects such as packages
+ */
+typedef struct acpi_update_state
+{
+    ACPI_STATE_COMMON
+    union acpi_operand_object       *Object;
+
+} ACPI_UPDATE_STATE;
+
+
+/*
+ * Pkg state - used to traverse nested package structures
+ */
+typedef struct acpi_pkg_state
+{
+    ACPI_STATE_COMMON
+    UINT16                          Index;
+    union acpi_operand_object       *SourceObject;
+    union acpi_operand_object       *DestObject;
+    struct acpi_walk_state          *WalkState;
+    void                            *ThisTargetObj;
+    UINT32                          NumPackages;
+
+} ACPI_PKG_STATE;
+
+
+/*
+ * Control state - one per if/else and while constructs.
+ * Allows nesting of these constructs
+ */
+typedef struct acpi_control_state
+{
+    ACPI_STATE_COMMON
+    UINT16                          Opcode;
+    union acpi_parse_object         *PredicateOp;
+    UINT8                           *AmlPredicateStart;     /* Start of if/while predicate */
+    UINT8                           *PackageEnd;            /* End of if/while block */
+    UINT32                          LoopCount;              /* While() loop counter */
+
+} ACPI_CONTROL_STATE;
+
+
+/*
+ * Scope state - current scope during namespace lookups
+ */
+typedef struct acpi_scope_state
+{
+    ACPI_STATE_COMMON
+    ACPI_NAMESPACE_NODE             *Node;
+
+} ACPI_SCOPE_STATE;
+
+
+typedef struct acpi_pscope_state
+{
+    ACPI_STATE_COMMON
+    UINT32                          ArgCount;               /* Number of fixed arguments */
+    union acpi_parse_object         *Op;                    /* Current op being parsed */
+    UINT8                           *ArgEnd;                /* Current argument end */
+    UINT8                           *PkgEnd;                /* Current package end */
+    UINT32                          ArgList;                /* Next argument to parse */
+
+} ACPI_PSCOPE_STATE;
+
+
+/*
+ * Thread state - one per thread across multiple walk states. Multiple walk
+ * states are created when there are nested control methods executing.
+ */
+typedef struct acpi_thread_state
+{
+    ACPI_STATE_COMMON
+    UINT8                           CurrentSyncLevel;       /* Mutex Sync (nested acquire) level */
+    struct acpi_walk_state          *WalkStateList;         /* Head of list of WalkStates for this thread */
+    union acpi_operand_object       *AcquiredMutexList;     /* List of all currently acquired mutexes */
+    ACPI_THREAD_ID                  ThreadId;               /* Running thread ID */
+
+} ACPI_THREAD_STATE;
+
+
+/*
+ * Result values - used to accumulate the results of nested
+ * AML arguments
+ */
+typedef struct acpi_result_values
+{
+    ACPI_STATE_COMMON
+    union acpi_operand_object       *ObjDesc [ACPI_RESULTS_FRAME_OBJ_NUM];
+
+} ACPI_RESULT_VALUES;
+
+
+typedef
+ACPI_STATUS (*ACPI_PARSE_DOWNWARDS) (
+    struct acpi_walk_state          *WalkState,
+    union acpi_parse_object         **OutOp);
+
+typedef
+ACPI_STATUS (*ACPI_PARSE_UPWARDS) (
+    struct acpi_walk_state          *WalkState);
+
+
+/* Global handlers for AML Notifies */
+
+typedef struct acpi_global_notify_handler
+{
+    ACPI_NOTIFY_HANDLER             Handler;
+    void                            *Context;
+
+} ACPI_GLOBAL_NOTIFY_HANDLER;
+
+/*
+ * Notify info - used to pass info to the deferred notify
+ * handler/dispatcher.
+ */
+typedef struct acpi_notify_info
+{
+    ACPI_STATE_COMMON
+    UINT8                           HandlerListId;
+    ACPI_NAMESPACE_NODE             *Node;
+    union acpi_operand_object       *HandlerListHead;
+    ACPI_GLOBAL_NOTIFY_HANDLER      *Global;
+
+} ACPI_NOTIFY_INFO;
+
+
+/* Generic state is union of structs above */
+
+typedef union acpi_generic_state
+{
+    ACPI_COMMON_STATE               Common;
+    ACPI_CONTROL_STATE              Control;
+    ACPI_UPDATE_STATE               Update;
+    ACPI_SCOPE_STATE                Scope;
+    ACPI_PSCOPE_STATE               ParseScope;
+    ACPI_PKG_STATE                  Pkg;
+    ACPI_THREAD_STATE               Thread;
+    ACPI_RESULT_VALUES              Results;
+    ACPI_NOTIFY_INFO                Notify;
+
+} ACPI_GENERIC_STATE;
+
+
+/*****************************************************************************
+ *
+ * Interpreter typedefs and structs
+ *
+ ****************************************************************************/
+
+typedef
+ACPI_STATUS (*ACPI_EXECUTE_OP) (
+    struct acpi_walk_state          *WalkState);
+
+/* Address Range info block */
+
+typedef struct acpi_address_range
+{
+    struct acpi_address_range   *Next;
+    ACPI_NAMESPACE_NODE         *RegionNode;
+    ACPI_PHYSICAL_ADDRESS       StartAddress;
+    ACPI_PHYSICAL_ADDRESS       EndAddress;
+
+} ACPI_ADDRESS_RANGE;
+
+
+/*****************************************************************************
+ *
+ * Parser typedefs and structs
+ *
+ ****************************************************************************/
+
+/*
+ * AML opcode, name, and argument layout
+ */
+typedef struct acpi_opcode_info
+{
+#if defined(ACPI_DISASSEMBLER) || defined(ACPI_DEBUG_OUTPUT)
+    char                            *Name;          /* Opcode name (disassembler/debug only) */
+#endif
+    UINT32                          ParseArgs;      /* Grammar/Parse time arguments */
+    UINT32                          RuntimeArgs;    /* Interpret time arguments */
+    UINT16                          Flags;          /* Misc flags */
+    UINT8                           ObjectType;     /* Corresponding internal object type */
+    UINT8                           Class;          /* Opcode class */
+    UINT8                           Type;           /* Opcode type */
+
+} ACPI_OPCODE_INFO;
+
+/* Structure for Resource Tag information */
+
+typedef struct acpi_tag_info
+{
+    UINT32                          BitOffset;
+    UINT32                          BitLength;
+
+} ACPI_TAG_INFO;
+
+/* Value associated with the parse object */
+
+typedef union acpi_parse_value
+{
+    UINT64                          Integer;        /* Integer constant (Up to 64 bits) */
+    UINT32                          Size;           /* bytelist or field size */
+    char                            *String;        /* NULL terminated string */
+    UINT8                           *Buffer;        /* buffer or string */
+    char                            *Name;          /* NULL terminated string */
+    union acpi_parse_object         *Arg;           /* arguments and contained ops */
+    ACPI_TAG_INFO                   Tag;            /* Resource descriptor tag info  */
+
+} ACPI_PARSE_VALUE;
+
+
+#if defined(ACPI_DISASSEMBLER) || defined(ACPI_DEBUG_OUTPUT)
+#define ACPI_DISASM_ONLY_MEMBERS(a)     a;
+#else
+#define ACPI_DISASM_ONLY_MEMBERS(a)
+#endif
+
+#define ACPI_PARSE_COMMON \
+    union acpi_parse_object         *Parent;        /* Parent op */\
+    UINT8                           DescriptorType; /* To differentiate various internal objs */\
+    UINT8                           Flags;          /* Type of Op */\
+    UINT16                          AmlOpcode;      /* AML opcode */\
+    UINT8                           *Aml;           /* Address of declaration in AML */\
+    union acpi_parse_object         *Next;          /* Next op */\
+    ACPI_NAMESPACE_NODE             *Node;          /* For use by interpreter */\
+    ACPI_PARSE_VALUE                Value;          /* Value or args associated with the opcode */\
+    UINT8                           ArgListLength;  /* Number of elements in the arg list */\
+    ACPI_DISASM_ONLY_MEMBERS (\
+    UINT8                           DisasmFlags;    /* Used during AML disassembly */\
+    UINT8                           DisasmOpcode;   /* Subtype used for disassembly */\
+    char                            *OperatorSymbol;/* Used for C-style operator name strings */\
+    char                            AmlOpName[16])  /* Op name (debug only) */
+
+
+/* Flags for DisasmFlags field  above */
+
+#define ACPI_DASM_BUFFER                0x00        /* Buffer is a simple data buffer */
+#define ACPI_DASM_RESOURCE              0x01        /* Buffer is a Resource Descriptor */
+#define ACPI_DASM_STRING                0x02        /* Buffer is a ASCII string */
+#define ACPI_DASM_UNICODE               0x03        /* Buffer is a Unicode string */
+#define ACPI_DASM_PLD_METHOD            0x04        /* Buffer is a _PLD method bit-packed buffer */
+#define ACPI_DASM_UUID                  0x05        /* Buffer is a UUID/GUID */
+#define ACPI_DASM_EISAID                0x06        /* Integer is an EISAID */
+#define ACPI_DASM_MATCHOP               0x07        /* Parent opcode is a Match() operator */
+#define ACPI_DASM_LNOT_PREFIX           0x08        /* Start of a LNotEqual (etc.) pair of opcodes */
+#define ACPI_DASM_LNOT_SUFFIX           0x09        /* End  of a LNotEqual (etc.) pair of opcodes */
+#define ACPI_DASM_HID_STRING            0x0A        /* String is a _HID or _CID */
+#define ACPI_DASM_IGNORE                0x0B        /* Not used at this time */
+
+/*
+ * Generic operation (for example:  If, While, Store)
+ */
+typedef struct acpi_parse_obj_common
+{
+    ACPI_PARSE_COMMON
+} ACPI_PARSE_OBJ_COMMON;
+
+
+/*
+ * Extended Op for named ops (Scope, Method, etc.), deferred ops (Methods and OpRegions),
+ * and bytelists.
+ */
+typedef struct acpi_parse_obj_named
+{
+    ACPI_PARSE_COMMON
+    UINT8                           *Path;
+    UINT8                           *Data;          /* AML body or bytelist data */
+    UINT32                          Length;         /* AML length */
+    UINT32                          Name;           /* 4-byte name or zero if no name */
+
+} ACPI_PARSE_OBJ_NAMED;
+
+
+/* This version is used by the iASL compiler only */
+
+#define ACPI_MAX_PARSEOP_NAME   20
+
+typedef struct acpi_parse_obj_asl
+{
+    ACPI_PARSE_COMMON
+    union acpi_parse_object         *Child;
+    union acpi_parse_object         *ParentMethod;
+    char                            *Filename;
+    char                            *ExternalName;
+    char                            *Namepath;
+    char                            NameSeg[4];
+    UINT32                          ExtraValue;
+    UINT32                          Column;
+    UINT32                          LineNumber;
+    UINT32                          LogicalLineNumber;
+    UINT32                          LogicalByteOffset;
+    UINT32                          EndLine;
+    UINT32                          EndLogicalLine;
+    UINT32                          AcpiBtype;
+    UINT32                          AmlLength;
+    UINT32                          AmlSubtreeLength;
+    UINT32                          FinalAmlLength;
+    UINT32                          FinalAmlOffset;
+    UINT32                          CompileFlags;
+    UINT16                          ParseOpcode;
+    UINT8                           AmlOpcodeLength;
+    UINT8                           AmlPkgLenBytes;
+    UINT8                           Extra;
+    char                            ParseOpName[ACPI_MAX_PARSEOP_NAME];
+
+} ACPI_PARSE_OBJ_ASL;
+
+typedef union acpi_parse_object
+{
+    ACPI_PARSE_OBJ_COMMON           Common;
+    ACPI_PARSE_OBJ_NAMED            Named;
+    ACPI_PARSE_OBJ_ASL              Asl;
+
+} ACPI_PARSE_OBJECT;
+
+
+/*
+ * Parse state - one state per parser invocation and each control
+ * method.
+ */
+typedef struct acpi_parse_state
+{
+    UINT8                           *AmlStart;      /* First AML byte */
+    UINT8                           *Aml;           /* Next AML byte */
+    UINT8                           *AmlEnd;        /* (last + 1) AML byte */
+    UINT8                           *PkgStart;      /* Current package begin */
+    UINT8                           *PkgEnd;        /* Current package end */
+    union acpi_parse_object         *StartOp;       /* Root of parse tree */
+    struct acpi_namespace_node      *StartNode;
+    union acpi_generic_state        *Scope;         /* Current scope */
+    union acpi_parse_object         *StartScope;
+    UINT32                          AmlSize;
+
+} ACPI_PARSE_STATE;
+
+
+/* Parse object flags */
+
+#define ACPI_PARSEOP_GENERIC            0x01
+#define ACPI_PARSEOP_NAMED              0x02
+#define ACPI_PARSEOP_DEFERRED           0x04
+#define ACPI_PARSEOP_BYTELIST           0x08
+#define ACPI_PARSEOP_IN_STACK           0x10
+#define ACPI_PARSEOP_TARGET             0x20
+#define ACPI_PARSEOP_IN_CACHE           0x80
+
+/* Parse object DisasmFlags */
+
+#define ACPI_PARSEOP_IGNORE             0x01
+#define ACPI_PARSEOP_PARAMLIST          0x02
+#define ACPI_PARSEOP_EMPTY_TERMLIST     0x04
+#define ACPI_PARSEOP_PREDEF_CHECKED     0x08
+#define ACPI_PARSEOP_CLOSING_PAREN      0x10
+#define ACPI_PARSEOP_COMPOUND           0x20
+#define ACPI_PARSEOP_ASSIGNMENT         0x40
+#define ACPI_PARSEOP_ELSEIF             0x80
+
+
+/*****************************************************************************
+ *
+ * Hardware (ACPI registers) and PNP
+ *
+ ****************************************************************************/
+
+typedef struct acpi_bit_register_info
+{
+    UINT8                           ParentRegister;
+    UINT8                           BitPosition;
+    UINT16                          AccessBitMask;
+
+} ACPI_BIT_REGISTER_INFO;
+
+
+/*
+ * Some ACPI registers have bits that must be ignored -- meaning that they
+ * must be preserved.
+ */
+#define ACPI_PM1_STATUS_PRESERVED_BITS          0x0800  /* Bit 11 */
+
+/* Write-only bits must be zeroed by software */
+
+#define ACPI_PM1_CONTROL_WRITEONLY_BITS         0x2004  /* Bits 13, 2 */
+
+/* For control registers, both ignored and reserved bits must be preserved */
+
+/*
+ * For PM1 control, the SCI enable bit (bit 0, SCI_EN) is defined by the
+ * ACPI specification to be a "preserved" bit - "OSPM always preserves this
+ * bit position", section 4.7.3.2.1. However, on some machines the OS must
+ * write a one to this bit after resume for the machine to work properly.
+ * To enable this, we no longer attempt to preserve this bit. No machines
+ * are known to fail if the bit is not preserved. (May 2009)
+ */
+#define ACPI_PM1_CONTROL_IGNORED_BITS           0x0200  /* Bit 9 */
+#define ACPI_PM1_CONTROL_RESERVED_BITS          0xC1F8  /* Bits 14-15, 3-8 */
+#define ACPI_PM1_CONTROL_PRESERVED_BITS \
+         (ACPI_PM1_CONTROL_IGNORED_BITS | ACPI_PM1_CONTROL_RESERVED_BITS)
+
+#define ACPI_PM2_CONTROL_PRESERVED_BITS         0xFFFFFFFE /* All except bit 0 */
+
+/*
+ * Register IDs
+ * These are the full ACPI registers
+ */
+#define ACPI_REGISTER_PM1_STATUS                0x01
+#define ACPI_REGISTER_PM1_ENABLE                0x02
+#define ACPI_REGISTER_PM1_CONTROL               0x03
+#define ACPI_REGISTER_PM2_CONTROL               0x04
+#define ACPI_REGISTER_PM_TIMER                  0x05
+#define ACPI_REGISTER_PROCESSOR_BLOCK           0x06
+#define ACPI_REGISTER_SMI_COMMAND_BLOCK         0x07
+
+
+/* Masks used to access the BitRegisters */
+
+#define ACPI_BITMASK_TIMER_STATUS               0x0001
+#define ACPI_BITMASK_BUS_MASTER_STATUS          0x0010
+#define ACPI_BITMASK_GLOBAL_LOCK_STATUS         0x0020
+#define ACPI_BITMASK_POWER_BUTTON_STATUS        0x0100
+#define ACPI_BITMASK_SLEEP_BUTTON_STATUS        0x0200
+#define ACPI_BITMASK_RT_CLOCK_STATUS            0x0400
+#define ACPI_BITMASK_PCIEXP_WAKE_STATUS         0x4000    /* ACPI 3.0 */
+#define ACPI_BITMASK_WAKE_STATUS                0x8000
+
+#define ACPI_BITMASK_ALL_FIXED_STATUS           (\
+    ACPI_BITMASK_TIMER_STATUS          | \
+    ACPI_BITMASK_BUS_MASTER_STATUS     | \
+    ACPI_BITMASK_GLOBAL_LOCK_STATUS    | \
+    ACPI_BITMASK_POWER_BUTTON_STATUS   | \
+    ACPI_BITMASK_SLEEP_BUTTON_STATUS   | \
+    ACPI_BITMASK_RT_CLOCK_STATUS       | \
+    ACPI_BITMASK_PCIEXP_WAKE_STATUS    | \
+    ACPI_BITMASK_WAKE_STATUS)
+
+#define ACPI_BITMASK_TIMER_ENABLE               0x0001
+#define ACPI_BITMASK_GLOBAL_LOCK_ENABLE         0x0020
+#define ACPI_BITMASK_POWER_BUTTON_ENABLE        0x0100
+#define ACPI_BITMASK_SLEEP_BUTTON_ENABLE        0x0200
+#define ACPI_BITMASK_RT_CLOCK_ENABLE            0x0400
+#define ACPI_BITMASK_PCIEXP_WAKE_DISABLE        0x4000    /* ACPI 3.0 */
+
+#define ACPI_BITMASK_SCI_ENABLE                 0x0001
+#define ACPI_BITMASK_BUS_MASTER_RLD             0x0002
+#define ACPI_BITMASK_GLOBAL_LOCK_RELEASE        0x0004
+#define ACPI_BITMASK_SLEEP_TYPE                 0x1C00
+#define ACPI_BITMASK_SLEEP_ENABLE               0x2000
+
+#define ACPI_BITMASK_ARB_DISABLE                0x0001
+
+
+/* Raw bit position of each BitRegister */
+
+#define ACPI_BITPOSITION_TIMER_STATUS           0x00
+#define ACPI_BITPOSITION_BUS_MASTER_STATUS      0x04
+#define ACPI_BITPOSITION_GLOBAL_LOCK_STATUS     0x05
+#define ACPI_BITPOSITION_POWER_BUTTON_STATUS    0x08
+#define ACPI_BITPOSITION_SLEEP_BUTTON_STATUS    0x09
+#define ACPI_BITPOSITION_RT_CLOCK_STATUS        0x0A
+#define ACPI_BITPOSITION_PCIEXP_WAKE_STATUS     0x0E    /* ACPI 3.0 */
+#define ACPI_BITPOSITION_WAKE_STATUS            0x0F
+
+#define ACPI_BITPOSITION_TIMER_ENABLE           0x00
+#define ACPI_BITPOSITION_GLOBAL_LOCK_ENABLE     0x05
+#define ACPI_BITPOSITION_POWER_BUTTON_ENABLE    0x08
+#define ACPI_BITPOSITION_SLEEP_BUTTON_ENABLE    0x09
+#define ACPI_BITPOSITION_RT_CLOCK_ENABLE        0x0A
+#define ACPI_BITPOSITION_PCIEXP_WAKE_DISABLE    0x0E    /* ACPI 3.0 */
+
+#define ACPI_BITPOSITION_SCI_ENABLE             0x00
+#define ACPI_BITPOSITION_BUS_MASTER_RLD         0x01
+#define ACPI_BITPOSITION_GLOBAL_LOCK_RELEASE    0x02
+#define ACPI_BITPOSITION_SLEEP_TYPE             0x0A
+#define ACPI_BITPOSITION_SLEEP_ENABLE           0x0D
+
+#define ACPI_BITPOSITION_ARB_DISABLE            0x00
+
+
+/* Structs and definitions for _OSI support and I/O port validation */
+
+#define ACPI_ALWAYS_ILLEGAL             0x00
+
+typedef struct acpi_interface_info
+{
+    char                        *Name;
+    struct acpi_interface_info  *Next;
+    UINT8                       Flags;
+    UINT8                       Value;
+
+} ACPI_INTERFACE_INFO;
+
+#define ACPI_OSI_INVALID                0x01
+#define ACPI_OSI_DYNAMIC                0x02
+#define ACPI_OSI_FEATURE                0x04
+#define ACPI_OSI_DEFAULT_INVALID        0x08
+#define ACPI_OSI_OPTIONAL_FEATURE       (ACPI_OSI_FEATURE | ACPI_OSI_DEFAULT_INVALID | ACPI_OSI_INVALID)
+
+typedef struct acpi_port_info
+{
+    char                    *Name;
+    UINT16                  Start;
+    UINT16                  End;
+    UINT8                   OsiDependency;
+
+} ACPI_PORT_INFO;
+
+
+/*****************************************************************************
+ *
+ * Resource descriptors
+ *
+ ****************************************************************************/
+
+/* ResourceType values */
+
+#define ACPI_ADDRESS_TYPE_MEMORY_RANGE          0
+#define ACPI_ADDRESS_TYPE_IO_RANGE              1
+#define ACPI_ADDRESS_TYPE_BUS_NUMBER_RANGE      2
+
+/* Resource descriptor types and masks */
+
+#define ACPI_RESOURCE_NAME_LARGE                0x80
+#define ACPI_RESOURCE_NAME_SMALL                0x00
+
+#define ACPI_RESOURCE_NAME_SMALL_MASK           0x78 /* Bits 6:3 contain the type */
+#define ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK    0x07 /* Bits 2:0 contain the length */
+#define ACPI_RESOURCE_NAME_LARGE_MASK           0x7F /* Bits 6:0 contain the type */
+
+
+/*
+ * Small resource descriptor "names" as defined by the ACPI specification.
+ * Note: Bits 2:0 are used for the descriptor length
+ */
+#define ACPI_RESOURCE_NAME_IRQ                  0x20
+#define ACPI_RESOURCE_NAME_DMA                  0x28
+#define ACPI_RESOURCE_NAME_START_DEPENDENT      0x30
+#define ACPI_RESOURCE_NAME_END_DEPENDENT        0x38
+#define ACPI_RESOURCE_NAME_IO                   0x40
+#define ACPI_RESOURCE_NAME_FIXED_IO             0x48
+#define ACPI_RESOURCE_NAME_FIXED_DMA            0x50
+#define ACPI_RESOURCE_NAME_RESERVED_S2          0x58
+#define ACPI_RESOURCE_NAME_RESERVED_S3          0x60
+#define ACPI_RESOURCE_NAME_RESERVED_S4          0x68
+#define ACPI_RESOURCE_NAME_VENDOR_SMALL         0x70
+#define ACPI_RESOURCE_NAME_END_TAG              0x78
+
+/*
+ * Large resource descriptor "names" as defined by the ACPI specification.
+ * Note: includes the Large Descriptor bit in bit[7]
+ */
+#define ACPI_RESOURCE_NAME_MEMORY24             0x81
+#define ACPI_RESOURCE_NAME_GENERIC_REGISTER     0x82
+#define ACPI_RESOURCE_NAME_RESERVED_L1          0x83
+#define ACPI_RESOURCE_NAME_VENDOR_LARGE         0x84
+#define ACPI_RESOURCE_NAME_MEMORY32             0x85
+#define ACPI_RESOURCE_NAME_FIXED_MEMORY32       0x86
+#define ACPI_RESOURCE_NAME_ADDRESS32            0x87
+#define ACPI_RESOURCE_NAME_ADDRESS16            0x88
+#define ACPI_RESOURCE_NAME_EXTENDED_IRQ         0x89
+#define ACPI_RESOURCE_NAME_ADDRESS64            0x8A
+#define ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64   0x8B
+#define ACPI_RESOURCE_NAME_GPIO                 0x8C
+#define ACPI_RESOURCE_NAME_SERIAL_BUS           0x8E
+#define ACPI_RESOURCE_NAME_LARGE_MAX            0x8E
+
+
+/*****************************************************************************
+ *
+ * Miscellaneous
+ *
+ ****************************************************************************/
+
+#define ACPI_ASCII_ZERO                 0x30
+
+
+/*****************************************************************************
+ *
+ * Disassembler
+ *
+ ****************************************************************************/
+
+typedef struct acpi_external_list
+{
+    char                        *Path;
+    char                        *InternalPath;
+    struct acpi_external_list   *Next;
+    UINT32                      Value;
+    UINT16                      Length;
+    UINT16                      Flags;
+    UINT8                       Type;
+
+} ACPI_EXTERNAL_LIST;
+
+/* Values for Flags field above */
+
+#define ACPI_EXT_RESOLVED_REFERENCE         0x01    /* Object was resolved during cross ref */
+#define ACPI_EXT_ORIGIN_FROM_FILE           0x02    /* External came from a file */
+#define ACPI_EXT_INTERNAL_PATH_ALLOCATED    0x04    /* Deallocate internal path on completion */
+#define ACPI_EXT_EXTERNAL_EMITTED           0x08    /* External() statement has been emitted */
+
+
+typedef struct acpi_external_file
+{
+    char                        *Path;
+    struct acpi_external_file   *Next;
+
+} ACPI_EXTERNAL_FILE;
+
+
+/*****************************************************************************
+ *
+ * Debugger
+ *
+ ****************************************************************************/
+
+typedef struct acpi_db_method_info
+{
+    ACPI_HANDLE                     Method;
+    ACPI_HANDLE                     MainThreadGate;
+    ACPI_HANDLE                     ThreadCompleteGate;
+    ACPI_HANDLE                     InfoGate;
+    ACPI_THREAD_ID                  *Threads;
+    UINT32                          NumThreads;
+    UINT32                          NumCreated;
+    UINT32                          NumCompleted;
+
+    char                            *Name;
+    UINT32                          Flags;
+    UINT32                          NumLoops;
+    char                            Pathname[ACPI_DB_LINE_BUFFER_SIZE];
+    char                            **Args;
+    ACPI_OBJECT_TYPE                *Types;
+
+    /*
+     * Arguments to be passed to method for the command
+     * Threads -
+     *   the Number of threads, ID of current thread and
+     *   Index of current thread inside all them created.
+     */
+    char                            InitArgs;
+#ifdef ACPI_DEBUGGER
+    ACPI_OBJECT_TYPE                ArgTypes[4];
+#endif
+    char                            *Arguments[4];
+    char                            NumThreadsStr[11];
+    char                            IdOfThreadStr[11];
+    char                            IndexOfThreadStr[11];
+
+} ACPI_DB_METHOD_INFO;
+
+typedef struct acpi_integrity_info
+{
+    UINT32                          Nodes;
+    UINT32                          Objects;
+
+} ACPI_INTEGRITY_INFO;
+
+
+#define ACPI_DB_DISABLE_OUTPUT          0x00
+#define ACPI_DB_REDIRECTABLE_OUTPUT     0x01
+#define ACPI_DB_CONSOLE_OUTPUT          0x02
+#define ACPI_DB_DUPLICATE_OUTPUT        0x03
+
+
+typedef struct acpi_object_info
+{
+    UINT32                  Types[ACPI_TOTAL_TYPES];
+
+} ACPI_OBJECT_INFO;
+
+
+/*****************************************************************************
+ *
+ * Debug
+ *
+ ****************************************************************************/
+
+/* Entry for a memory allocation (debug only) */
+
+#define ACPI_MEM_MALLOC                 0
+#define ACPI_MEM_CALLOC                 1
+#define ACPI_MAX_MODULE_NAME            16
+
+#define ACPI_COMMON_DEBUG_MEM_HEADER \
+    struct acpi_debug_mem_block     *Previous; \
+    struct acpi_debug_mem_block     *Next; \
+    UINT32                          Size; \
+    UINT32                          Component; \
+    UINT32                          Line; \
+    char                            Module[ACPI_MAX_MODULE_NAME]; \
+    UINT8                           AllocType;
+
+typedef struct acpi_debug_mem_header
+{
+    ACPI_COMMON_DEBUG_MEM_HEADER
+
+} ACPI_DEBUG_MEM_HEADER;
+
+typedef struct acpi_debug_mem_block
+{
+    ACPI_COMMON_DEBUG_MEM_HEADER
+    UINT64                          UserSpace;
+
+} ACPI_DEBUG_MEM_BLOCK;
+
+
+#define ACPI_MEM_LIST_GLOBAL            0
+#define ACPI_MEM_LIST_NSNODE            1
+#define ACPI_MEM_LIST_MAX               1
+#define ACPI_NUM_MEM_LISTS              2
+
+
+/*****************************************************************************
+ *
+ * Info/help support
+ *
+ ****************************************************************************/
+
+typedef struct ah_predefined_name
+{
+    char            *Name;
+    char            *Description;
+#ifndef ACPI_ASL_COMPILER
+    char            *Action;
+#endif
+
+} AH_PREDEFINED_NAME;
+
+typedef struct ah_device_id
+{
+    char            *Name;
+    char            *Description;
+
+} AH_DEVICE_ID;
+
+typedef struct ah_uuid
+{
+    char            *Description;
+    char            *String;
+
+} AH_UUID;
+
+typedef struct ah_table
+{
+    char                    *Signature;
+    char                    *Description;
+
+} AH_TABLE;
+
+#endif /* __ACLOCAL_H__ */

+ 423 - 0
kernel/include/acpica/acmacros.h

@@ -0,0 +1,423 @@
+/******************************************************************************
+ *
+ * Name: acmacros.h - C macros for the entire subsystem.
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACMACROS_H__
+#define __ACMACROS_H__
+
+
+/*
+ * Extract data using a pointer. Any more than a byte and we
+ * get into potential aligment issues -- see the STORE macros below.
+ * Use with care.
+ */
+#define ACPI_CAST8(ptr)                 ACPI_CAST_PTR (UINT8, (ptr))
+#define ACPI_CAST16(ptr)                ACPI_CAST_PTR (UINT16, (ptr))
+#define ACPI_CAST32(ptr)                ACPI_CAST_PTR (UINT32, (ptr))
+#define ACPI_CAST64(ptr)                ACPI_CAST_PTR (UINT64, (ptr))
+#define ACPI_GET8(ptr)                  (*ACPI_CAST8 (ptr))
+#define ACPI_GET16(ptr)                 (*ACPI_CAST16 (ptr))
+#define ACPI_GET32(ptr)                 (*ACPI_CAST32 (ptr))
+#define ACPI_GET64(ptr)                 (*ACPI_CAST64 (ptr))
+#define ACPI_SET8(ptr, val)             (*ACPI_CAST8 (ptr) = (UINT8) (val))
+#define ACPI_SET16(ptr, val)            (*ACPI_CAST16 (ptr) = (UINT16) (val))
+#define ACPI_SET32(ptr, val)            (*ACPI_CAST32 (ptr) = (UINT32) (val))
+#define ACPI_SET64(ptr, val)            (*ACPI_CAST64 (ptr) = (UINT64) (val))
+
+/*
+ * printf() format helper. This macros is a workaround for the difficulties
+ * with emitting 64-bit integers and 64-bit pointers with the same code
+ * for both 32-bit and 64-bit hosts.
+ */
+#define ACPI_FORMAT_UINT64(i)           ACPI_HIDWORD(i), ACPI_LODWORD(i)
+
+
+/*
+ * Macros for moving data around to/from buffers that are possibly unaligned.
+ * If the hardware supports the transfer of unaligned data, just do the store.
+ * Otherwise, we have to move one byte at a time.
+ */
+#ifdef ACPI_BIG_ENDIAN
+/*
+ * Macros for big-endian machines
+ */
+
+/* These macros reverse the bytes during the move, converting little-endian to big endian */
+
+                                                     /* Big Endian      <==        Little Endian */
+                                                     /*  Hi...Lo                     Lo...Hi     */
+/* 16-bit source, 16/32/64 destination */
+
+#define ACPI_MOVE_16_TO_16(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[1];\
+                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[0];}
+
+#define ACPI_MOVE_16_TO_32(d, s)        {(*(UINT32 *)(void *)(d))=0;\
+                                           ((UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
+                                           ((UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
+
+#define ACPI_MOVE_16_TO_64(d, s)        {(*(UINT64 *)(void *)(d))=0;\
+                                           ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
+                                           ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
+
+/* 32-bit source, 16/32/64 destination */
+
+#define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
+
+#define ACPI_MOVE_32_TO_32(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[3];\
+                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[2];\
+                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[1];\
+                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[0];}
+
+#define ACPI_MOVE_32_TO_64(d, s)        {(*(UINT64 *)(void *)(d))=0;\
+                                           ((UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
+                                           ((UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
+                                           ((UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
+                                           ((UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
+
+/* 64-bit source, 16/32/64 destination */
+
+#define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
+
+#define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
+
+#define ACPI_MOVE_64_TO_64(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[7];\
+                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[6];\
+                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[5];\
+                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[4];\
+                                         ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[3];\
+                                         ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[2];\
+                                         ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[1];\
+                                         ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[0];}
+#else
+/*
+ * Macros for little-endian machines
+ */
+
+#ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
+
+/* The hardware supports unaligned transfers, just do the little-endian move */
+
+/* 16-bit source, 16/32/64 destination */
+
+#define ACPI_MOVE_16_TO_16(d, s)        *(UINT16 *)(void *)(d) = *(UINT16 *)(void *)(s)
+#define ACPI_MOVE_16_TO_32(d, s)        *(UINT32 *)(void *)(d) = *(UINT16 *)(void *)(s)
+#define ACPI_MOVE_16_TO_64(d, s)        *(UINT64 *)(void *)(d) = *(UINT16 *)(void *)(s)
+
+/* 32-bit source, 16/32/64 destination */
+
+#define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
+#define ACPI_MOVE_32_TO_32(d, s)        *(UINT32 *)(void *)(d) = *(UINT32 *)(void *)(s)
+#define ACPI_MOVE_32_TO_64(d, s)        *(UINT64 *)(void *)(d) = *(UINT32 *)(void *)(s)
+
+/* 64-bit source, 16/32/64 destination */
+
+#define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
+#define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
+#define ACPI_MOVE_64_TO_64(d, s)        *(UINT64 *)(void *)(d) = *(UINT64 *)(void *)(s)
+
+#else
+/*
+ * The hardware does not support unaligned transfers. We must move the
+ * data one byte at a time. These macros work whether the source or
+ * the destination (or both) is/are unaligned. (Little-endian move)
+ */
+
+/* 16-bit source, 16/32/64 destination */
+
+#define ACPI_MOVE_16_TO_16(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
+                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];}
+
+#define ACPI_MOVE_16_TO_32(d, s)        {(*(UINT32 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);}
+#define ACPI_MOVE_16_TO_64(d, s)        {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_16_TO_16(d, s);}
+
+/* 32-bit source, 16/32/64 destination */
+
+#define ACPI_MOVE_32_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
+
+#define ACPI_MOVE_32_TO_32(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
+                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
+                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
+                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];}
+
+#define ACPI_MOVE_32_TO_64(d, s)        {(*(UINT64 *)(void *)(d)) = 0; ACPI_MOVE_32_TO_32(d, s);}
+
+/* 64-bit source, 16/32/64 destination */
+
+#define ACPI_MOVE_64_TO_16(d, s)        ACPI_MOVE_16_TO_16(d, s)    /* Truncate to 16 */
+#define ACPI_MOVE_64_TO_32(d, s)        ACPI_MOVE_32_TO_32(d, s)    /* Truncate to 32 */
+#define ACPI_MOVE_64_TO_64(d, s)        {((  UINT8 *)(void *)(d))[0] = ((UINT8 *)(void *)(s))[0];\
+                                         ((  UINT8 *)(void *)(d))[1] = ((UINT8 *)(void *)(s))[1];\
+                                         ((  UINT8 *)(void *)(d))[2] = ((UINT8 *)(void *)(s))[2];\
+                                         ((  UINT8 *)(void *)(d))[3] = ((UINT8 *)(void *)(s))[3];\
+                                         ((  UINT8 *)(void *)(d))[4] = ((UINT8 *)(void *)(s))[4];\
+                                         ((  UINT8 *)(void *)(d))[5] = ((UINT8 *)(void *)(s))[5];\
+                                         ((  UINT8 *)(void *)(d))[6] = ((UINT8 *)(void *)(s))[6];\
+                                         ((  UINT8 *)(void *)(d))[7] = ((UINT8 *)(void *)(s))[7];}
+#endif
+#endif
+
+
+/*
+ * Fast power-of-two math macros for non-optimized compilers
+ */
+#define _ACPI_DIV(value, PowerOf2)      ((UINT32) ((value) >> (PowerOf2)))
+#define _ACPI_MUL(value, PowerOf2)      ((UINT32) ((value) << (PowerOf2)))
+#define _ACPI_MOD(value, Divisor)       ((UINT32) ((value) & ((Divisor) -1)))
+
+#define ACPI_DIV_2(a)                   _ACPI_DIV(a, 1)
+#define ACPI_MUL_2(a)                   _ACPI_MUL(a, 1)
+#define ACPI_MOD_2(a)                   _ACPI_MOD(a, 2)
+
+#define ACPI_DIV_4(a)                   _ACPI_DIV(a, 2)
+#define ACPI_MUL_4(a)                   _ACPI_MUL(a, 2)
+#define ACPI_MOD_4(a)                   _ACPI_MOD(a, 4)
+
+#define ACPI_DIV_8(a)                   _ACPI_DIV(a, 3)
+#define ACPI_MUL_8(a)                   _ACPI_MUL(a, 3)
+#define ACPI_MOD_8(a)                   _ACPI_MOD(a, 8)
+
+#define ACPI_DIV_16(a)                  _ACPI_DIV(a, 4)
+#define ACPI_MUL_16(a)                  _ACPI_MUL(a, 4)
+#define ACPI_MOD_16(a)                  _ACPI_MOD(a, 16)
+
+#define ACPI_DIV_32(a)                  _ACPI_DIV(a, 5)
+#define ACPI_MUL_32(a)                  _ACPI_MUL(a, 5)
+#define ACPI_MOD_32(a)                  _ACPI_MOD(a, 32)
+
+/* Test for ASCII character */
+
+#define ACPI_IS_ASCII(c)                ((c) < 0x80)
+
+/* Signed integers */
+
+#define ACPI_SIGN_POSITIVE              0
+#define ACPI_SIGN_NEGATIVE              1
+
+
+/*
+ * Rounding macros (Power of two boundaries only)
+ */
+#define ACPI_ROUND_DOWN(value, boundary)    (((ACPI_SIZE)(value)) & \
+                                                (~(((ACPI_SIZE) boundary)-1)))
+
+#define ACPI_ROUND_UP(value, boundary)      ((((ACPI_SIZE)(value)) + \
+                                                (((ACPI_SIZE) boundary)-1)) & \
+                                                (~(((ACPI_SIZE) boundary)-1)))
+
+/* Note: sizeof(ACPI_SIZE) evaluates to either 4 or 8 (32- vs 64-bit mode) */
+
+#define ACPI_ROUND_DOWN_TO_32BIT(a)         ACPI_ROUND_DOWN(a, 4)
+#define ACPI_ROUND_DOWN_TO_64BIT(a)         ACPI_ROUND_DOWN(a, 8)
+#define ACPI_ROUND_DOWN_TO_NATIVE_WORD(a)   ACPI_ROUND_DOWN(a, sizeof(ACPI_SIZE))
+
+#define ACPI_ROUND_UP_TO_32BIT(a)           ACPI_ROUND_UP(a, 4)
+#define ACPI_ROUND_UP_TO_64BIT(a)           ACPI_ROUND_UP(a, 8)
+#define ACPI_ROUND_UP_TO_NATIVE_WORD(a)     ACPI_ROUND_UP(a, sizeof(ACPI_SIZE))
+
+#define ACPI_ROUND_BITS_UP_TO_BYTES(a)      ACPI_DIV_8((a) + 7)
+#define ACPI_ROUND_BITS_DOWN_TO_BYTES(a)    ACPI_DIV_8((a))
+
+#define ACPI_ROUND_UP_TO_1K(a)              (((a) + 1023) >> 10)
+
+/* Generic (non-power-of-two) rounding */
+
+#define ACPI_ROUND_UP_TO(value, boundary)   (((value) + ((boundary)-1)) / (boundary))
+
+#define ACPI_IS_MISALIGNED(value)           (((ACPI_SIZE) value) & (sizeof(ACPI_SIZE)-1))
+
+/*
+ * Bitmask creation
+ * Bit positions start at zero.
+ * MASK_BITS_ABOVE creates a mask starting AT the position and above
+ * MASK_BITS_BELOW creates a mask starting one bit BELOW the position
+ */
+#define ACPI_MASK_BITS_ABOVE(position)      (~((ACPI_UINT64_MAX) << ((UINT32) (position))))
+#define ACPI_MASK_BITS_BELOW(position)      ((ACPI_UINT64_MAX) << ((UINT32) (position)))
+
+/* Bitfields within ACPI registers */
+
+#define ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask) \
+    ((Val << Pos) & Mask)
+
+#define ACPI_REGISTER_INSERT_VALUE(Reg, Pos, Mask, Val) \
+    Reg = (Reg & (~(Mask))) | ACPI_REGISTER_PREPARE_BITS(Val, Pos, Mask)
+
+#define ACPI_INSERT_BITS(Target, Mask, Source) \
+    Target = ((Target & (~(Mask))) | (Source & Mask))
+
+/* Generic bitfield macros and masks */
+
+#define ACPI_GET_BITS(SourcePtr, Position, Mask) \
+    ((*SourcePtr >> Position) & Mask)
+
+#define ACPI_SET_BITS(TargetPtr, Position, Mask, Value) \
+    (*TargetPtr |= ((Value & Mask) << Position))
+
+#define ACPI_1BIT_MASK      0x00000001
+#define ACPI_2BIT_MASK      0x00000003
+#define ACPI_3BIT_MASK      0x00000007
+#define ACPI_4BIT_MASK      0x0000000F
+#define ACPI_5BIT_MASK      0x0000001F
+#define ACPI_6BIT_MASK      0x0000003F
+#define ACPI_7BIT_MASK      0x0000007F
+#define ACPI_8BIT_MASK      0x000000FF
+#define ACPI_16BIT_MASK     0x0000FFFF
+#define ACPI_24BIT_MASK     0x00FFFFFF
+
+/* Macros to extract flag bits from position zero */
+
+#define ACPI_GET_1BIT_FLAG(Value)                   ((Value) & ACPI_1BIT_MASK)
+#define ACPI_GET_2BIT_FLAG(Value)                   ((Value) & ACPI_2BIT_MASK)
+#define ACPI_GET_3BIT_FLAG(Value)                   ((Value) & ACPI_3BIT_MASK)
+#define ACPI_GET_4BIT_FLAG(Value)                   ((Value) & ACPI_4BIT_MASK)
+
+/* Macros to extract flag bits from position one and above */
+
+#define ACPI_EXTRACT_1BIT_FLAG(Field, Position)     (ACPI_GET_1BIT_FLAG ((Field) >> Position))
+#define ACPI_EXTRACT_2BIT_FLAG(Field, Position)     (ACPI_GET_2BIT_FLAG ((Field) >> Position))
+#define ACPI_EXTRACT_3BIT_FLAG(Field, Position)     (ACPI_GET_3BIT_FLAG ((Field) >> Position))
+#define ACPI_EXTRACT_4BIT_FLAG(Field, Position)     (ACPI_GET_4BIT_FLAG ((Field) >> Position))
+
+/* ACPI Pathname helpers */
+
+#define ACPI_IS_ROOT_PREFIX(c)      ((c) == (UINT8) 0x5C) /* Backslash */
+#define ACPI_IS_PARENT_PREFIX(c)    ((c) == (UINT8) 0x5E) /* Carat */
+#define ACPI_IS_PATH_SEPARATOR(c)   ((c) == (UINT8) 0x2E) /* Period (dot) */
+
+/*
+ * An object of type ACPI_NAMESPACE_NODE can appear in some contexts
+ * where a pointer to an object of type ACPI_OPERAND_OBJECT can also
+ * appear. This macro is used to distinguish them.
+ *
+ * The "DescriptorType" field is the second field in both structures.
+ */
+#define ACPI_GET_DESCRIPTOR_PTR(d)      (((ACPI_DESCRIPTOR *)(void *)(d))->Common.CommonPointer)
+#define ACPI_SET_DESCRIPTOR_PTR(d, p)   (((ACPI_DESCRIPTOR *)(void *)(d))->Common.CommonPointer = (p))
+#define ACPI_GET_DESCRIPTOR_TYPE(d)     (((ACPI_DESCRIPTOR *)(void *)(d))->Common.DescriptorType)
+#define ACPI_SET_DESCRIPTOR_TYPE(d, t)  (((ACPI_DESCRIPTOR *)(void *)(d))->Common.DescriptorType = (t))
+
+/*
+ * Macros for the master AML opcode table
+ */
+#if defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUG_OUTPUT)
+#define ACPI_OP(Name, PArgs, IArgs, ObjType, Class, Type, Flags) \
+    {Name, (UINT32)(PArgs), (UINT32)(IArgs), (UINT32)(Flags), ObjType, Class, Type}
+#else
+#define ACPI_OP(Name, PArgs, IArgs, ObjType, Class, Type, Flags) \
+    {(UINT32)(PArgs), (UINT32)(IArgs), (UINT32)(Flags), ObjType, Class, Type}
+#endif
+
+#define ARG_TYPE_WIDTH                  5
+#define ARG_1(x)                        ((UINT32)(x))
+#define ARG_2(x)                        ((UINT32)(x) << (1 * ARG_TYPE_WIDTH))
+#define ARG_3(x)                        ((UINT32)(x) << (2 * ARG_TYPE_WIDTH))
+#define ARG_4(x)                        ((UINT32)(x) << (3 * ARG_TYPE_WIDTH))
+#define ARG_5(x)                        ((UINT32)(x) << (4 * ARG_TYPE_WIDTH))
+#define ARG_6(x)                        ((UINT32)(x) << (5 * ARG_TYPE_WIDTH))
+
+#define ARGI_LIST1(a)                   (ARG_1(a))
+#define ARGI_LIST2(a, b)                (ARG_1(b)|ARG_2(a))
+#define ARGI_LIST3(a, b, c)             (ARG_1(c)|ARG_2(b)|ARG_3(a))
+#define ARGI_LIST4(a, b, c, d)          (ARG_1(d)|ARG_2(c)|ARG_3(b)|ARG_4(a))
+#define ARGI_LIST5(a, b, c, d, e)       (ARG_1(e)|ARG_2(d)|ARG_3(c)|ARG_4(b)|ARG_5(a))
+#define ARGI_LIST6(a, b, c, d, e, f)    (ARG_1(f)|ARG_2(e)|ARG_3(d)|ARG_4(c)|ARG_5(b)|ARG_6(a))
+
+#define ARGP_LIST1(a)                   (ARG_1(a))
+#define ARGP_LIST2(a, b)                (ARG_1(a)|ARG_2(b))
+#define ARGP_LIST3(a, b, c)             (ARG_1(a)|ARG_2(b)|ARG_3(c))
+#define ARGP_LIST4(a, b, c, d)          (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d))
+#define ARGP_LIST5(a, b, c, d, e)       (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e))
+#define ARGP_LIST6(a, b, c, d, e, f)    (ARG_1(a)|ARG_2(b)|ARG_3(c)|ARG_4(d)|ARG_5(e)|ARG_6(f))
+
+#define GET_CURRENT_ARG_TYPE(List)      (List & ((UINT32) 0x1F))
+#define INCREMENT_ARG_LIST(List)        (List >>= ((UINT32) ARG_TYPE_WIDTH))
+
+/*
+ * Ascii error messages can be configured out
+ */
+#ifndef ACPI_NO_ERROR_MESSAGES
+/*
+ * Error reporting. Callers module and line number are inserted by AE_INFO,
+ * the plist contains a set of parens to allow variable-length lists.
+ * These macros are used for both the debug and non-debug versions of the code.
+ */
+#define ACPI_ERROR_NAMESPACE(s, e)          AcpiUtNamespaceError (AE_INFO, s, e);
+#define ACPI_ERROR_METHOD(s, n, p, e)       AcpiUtMethodError (AE_INFO, s, n, p, e);
+#define ACPI_WARN_PREDEFINED(plist)         AcpiUtPredefinedWarning plist
+#define ACPI_INFO_PREDEFINED(plist)         AcpiUtPredefinedInfo plist
+#define ACPI_BIOS_ERROR_PREDEFINED(plist)   AcpiUtPredefinedBiosError plist
+
+#else
+
+/* No error messages */
+
+#define ACPI_ERROR_NAMESPACE(s, e)
+#define ACPI_ERROR_METHOD(s, n, p, e)
+#define ACPI_WARN_PREDEFINED(plist)
+#define ACPI_INFO_PREDEFINED(plist)
+#define ACPI_BIOS_ERROR_PREDEFINED(plist)
+
+#endif /* ACPI_NO_ERROR_MESSAGES */
+
+#if (!ACPI_REDUCED_HARDWARE)
+#define ACPI_HW_OPTIONAL_FUNCTION(addr)     addr
+#else
+#define ACPI_HW_OPTIONAL_FUNCTION(addr)     NULL
+#endif
+
+
+/*
+ * Macros used for ACPICA utilities only
+ */
+
+/* Generate a UUID */
+
+#define ACPI_INIT_UUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
+    (a) & 0xFF, ((a) >> 8) & 0xFF, ((a) >> 16) & 0xFF, ((a) >> 24) & 0xFF, \
+    (b) & 0xFF, ((b) >> 8) & 0xFF, \
+    (c) & 0xFF, ((c) >> 8) & 0xFF, \
+    (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)
+
+#define ACPI_IS_OCTAL_DIGIT(d)              (((char)(d) >= '0') && ((char)(d) <= '7'))
+
+
+#endif /* ACMACROS_H */

+ 92 - 0
kernel/include/acpica/acnames.h

@@ -0,0 +1,92 @@
+/******************************************************************************
+ *
+ * Name: acnames.h - Global names and strings
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACNAMES_H__
+#define __ACNAMES_H__
+
+/* Method names - these methods can appear anywhere in the namespace */
+
+#define METHOD_NAME__ADR        "_ADR"
+#define METHOD_NAME__AEI        "_AEI"
+#define METHOD_NAME__BBN        "_BBN"
+#define METHOD_NAME__CBA        "_CBA"
+#define METHOD_NAME__CID        "_CID"
+#define METHOD_NAME__CLS        "_CLS"
+#define METHOD_NAME__CRS        "_CRS"
+#define METHOD_NAME__DDN        "_DDN"
+#define METHOD_NAME__HID        "_HID"
+#define METHOD_NAME__INI        "_INI"
+#define METHOD_NAME__PLD        "_PLD"
+#define METHOD_NAME__DSD        "_DSD"
+#define METHOD_NAME__PRS        "_PRS"
+#define METHOD_NAME__PRT        "_PRT"
+#define METHOD_NAME__PRW        "_PRW"
+#define METHOD_NAME__PS0        "_PS0"
+#define METHOD_NAME__PS1        "_PS1"
+#define METHOD_NAME__PS2        "_PS2"
+#define METHOD_NAME__PS3        "_PS3"
+#define METHOD_NAME__REG        "_REG"
+#define METHOD_NAME__SB_        "_SB_"
+#define METHOD_NAME__SEG        "_SEG"
+#define METHOD_NAME__SRS        "_SRS"
+#define METHOD_NAME__STA        "_STA"
+#define METHOD_NAME__SUB        "_SUB"
+#define METHOD_NAME__UID        "_UID"
+
+/* Method names - these methods must appear at the namespace root */
+
+#define METHOD_PATHNAME__PTS    "\\_PTS"
+#define METHOD_PATHNAME__SST    "\\_SI._SST"
+#define METHOD_PATHNAME__WAK    "\\_WAK"
+
+/* Definitions of the predefined namespace names  */
+
+#define ACPI_UNKNOWN_NAME       (UINT32) 0x3F3F3F3F     /* Unknown name is "????" */
+#define ACPI_ROOT_NAME          (UINT32) 0x5F5F5F5C     /* Root name is    "\___" */
+
+#define ACPI_PREFIX_MIXED       (UINT32) 0x69706341     /* "Acpi" */
+#define ACPI_PREFIX_LOWER       (UINT32) 0x69706361     /* "acpi" */
+
+#define ACPI_NS_ROOT_PATH       "\\"
+
+#endif  /* __ACNAMES_H__  */

+ 555 - 0
kernel/include/acpica/acnamesp.h

@@ -0,0 +1,555 @@
+/******************************************************************************
+ *
+ * Name: acnamesp.h - Namespace subcomponent prototypes and defines
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACNAMESP_H__
+#define __ACNAMESP_H__
+
+
+/* To search the entire name space, pass this as SearchBase */
+
+#define ACPI_NS_ALL                 ((ACPI_HANDLE)0)
+
+/*
+ * Elements of AcpiNsProperties are bit significant
+ * and should be one-to-one with values of ACPI_OBJECT_TYPE
+ */
+#define ACPI_NS_NORMAL              0
+#define ACPI_NS_NEWSCOPE            1   /* a definition of this type opens a name scope */
+#define ACPI_NS_LOCAL               2   /* suppress search of enclosing scopes */
+
+/* Flags for AcpiNsLookup, AcpiNsSearchAndEnter */
+
+#define ACPI_NS_NO_UPSEARCH         0
+#define ACPI_NS_SEARCH_PARENT       0x01
+#define ACPI_NS_DONT_OPEN_SCOPE     0x02
+#define ACPI_NS_NO_PEER_SEARCH      0x04
+#define ACPI_NS_ERROR_IF_FOUND      0x08
+#define ACPI_NS_PREFIX_IS_SCOPE     0x10
+#define ACPI_NS_EXTERNAL            0x20
+#define ACPI_NS_TEMPORARY           0x40
+#define ACPI_NS_OVERRIDE_IF_FOUND   0x80
+
+/* Flags for AcpiNsWalkNamespace */
+
+#define ACPI_NS_WALK_NO_UNLOCK      0
+#define ACPI_NS_WALK_UNLOCK         0x01
+#define ACPI_NS_WALK_TEMP_NODES     0x02
+
+/* Object is not a package element */
+
+#define ACPI_NOT_PACKAGE_ELEMENT    ACPI_UINT32_MAX
+#define ACPI_ALL_PACKAGE_ELEMENTS   (ACPI_UINT32_MAX-1)
+
+/* Always emit warning message, not dependent on node flags */
+
+#define ACPI_WARN_ALWAYS            0
+
+
+/*
+ * nsinit - Namespace initialization
+ */
+ACPI_STATUS
+AcpiNsInitializeObjects (
+    void);
+
+ACPI_STATUS
+AcpiNsInitializeDevices (
+    void);
+
+
+/*
+ * nsload -  Namespace loading
+ */
+ACPI_STATUS
+AcpiNsLoadNamespace (
+    void);
+
+ACPI_STATUS
+AcpiNsLoadTable (
+    UINT32                  TableIndex,
+    ACPI_NAMESPACE_NODE     *Node);
+
+
+/*
+ * nswalk - walk the namespace
+ */
+ACPI_STATUS
+AcpiNsWalkNamespace (
+    ACPI_OBJECT_TYPE        Type,
+    ACPI_HANDLE             StartObject,
+    UINT32                  MaxDepth,
+    UINT32                  Flags,
+    ACPI_WALK_CALLBACK      DescendingCallback,
+    ACPI_WALK_CALLBACK      AscendingCallback,
+    void                    *Context,
+    void                    **ReturnValue);
+
+ACPI_NAMESPACE_NODE *
+AcpiNsGetNextNode (
+    ACPI_NAMESPACE_NODE     *Parent,
+    ACPI_NAMESPACE_NODE     *Child);
+
+ACPI_NAMESPACE_NODE *
+AcpiNsGetNextNodeTyped (
+    ACPI_OBJECT_TYPE        Type,
+    ACPI_NAMESPACE_NODE     *Parent,
+    ACPI_NAMESPACE_NODE     *Child);
+
+/*
+ * nsparse - table parsing
+ */
+ACPI_STATUS
+AcpiNsParseTable (
+    UINT32                  TableIndex,
+    ACPI_NAMESPACE_NODE     *StartNode);
+
+ACPI_STATUS
+AcpiNsOneCompleteParse (
+    UINT32                  PassNumber,
+    UINT32                  TableIndex,
+    ACPI_NAMESPACE_NODE     *StartNode);
+
+
+/*
+ * nsaccess - Top-level namespace access
+ */
+ACPI_STATUS
+AcpiNsRootInitialize (
+    void);
+
+ACPI_STATUS
+AcpiNsLookup (
+    ACPI_GENERIC_STATE      *ScopeInfo,
+    char                    *Name,
+    ACPI_OBJECT_TYPE        Type,
+    ACPI_INTERPRETER_MODE   InterpreterMode,
+    UINT32                  Flags,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_NAMESPACE_NODE     **RetNode);
+
+
+/*
+ * nsalloc - Named object allocation/deallocation
+ */
+ACPI_NAMESPACE_NODE *
+AcpiNsCreateNode (
+    UINT32                  Name);
+
+void
+AcpiNsDeleteNode (
+    ACPI_NAMESPACE_NODE     *Node);
+
+void
+AcpiNsRemoveNode (
+    ACPI_NAMESPACE_NODE     *Node);
+
+void
+AcpiNsDeleteNamespaceSubtree (
+    ACPI_NAMESPACE_NODE     *ParentHandle);
+
+void
+AcpiNsDeleteNamespaceByOwner (
+    ACPI_OWNER_ID           OwnerId);
+
+void
+AcpiNsDetachObject (
+    ACPI_NAMESPACE_NODE     *Node);
+
+void
+AcpiNsDeleteChildren (
+    ACPI_NAMESPACE_NODE     *Parent);
+
+int
+AcpiNsCompareNames (
+    char                    *Name1,
+    char                    *Name2);
+
+
+/*
+ * nsconvert - Dynamic object conversion routines
+ */
+ACPI_STATUS
+AcpiNsConvertToInteger (
+    ACPI_OPERAND_OBJECT     *OriginalObject,
+    ACPI_OPERAND_OBJECT     **ReturnObject);
+
+ACPI_STATUS
+AcpiNsConvertToString (
+    ACPI_OPERAND_OBJECT     *OriginalObject,
+    ACPI_OPERAND_OBJECT     **ReturnObject);
+
+ACPI_STATUS
+AcpiNsConvertToBuffer (
+    ACPI_OPERAND_OBJECT     *OriginalObject,
+    ACPI_OPERAND_OBJECT     **ReturnObject);
+
+ACPI_STATUS
+AcpiNsConvertToUnicode (
+    ACPI_NAMESPACE_NODE     *Scope,
+    ACPI_OPERAND_OBJECT     *OriginalObject,
+    ACPI_OPERAND_OBJECT     **ReturnObject);
+
+ACPI_STATUS
+AcpiNsConvertToResource (
+    ACPI_NAMESPACE_NODE     *Scope,
+    ACPI_OPERAND_OBJECT     *OriginalObject,
+    ACPI_OPERAND_OBJECT     **ReturnObject);
+
+ACPI_STATUS
+AcpiNsConvertToReference (
+    ACPI_NAMESPACE_NODE     *Scope,
+    ACPI_OPERAND_OBJECT     *OriginalObject,
+    ACPI_OPERAND_OBJECT     **ReturnObject);
+
+
+/*
+ * nsdump - Namespace dump/print utilities
+ */
+void
+AcpiNsDumpTables (
+    ACPI_HANDLE             SearchBase,
+    UINT32                  MaxDepth);
+
+void
+AcpiNsDumpEntry (
+    ACPI_HANDLE             Handle,
+    UINT32                  DebugLevel);
+
+void
+AcpiNsDumpPathname (
+    ACPI_HANDLE             Handle,
+    char                    *Msg,
+    UINT32                  Level,
+    UINT32                  Component);
+
+void
+AcpiNsPrintPathname (
+    UINT32                  NumSegments,
+    char                    *Pathname);
+
+ACPI_STATUS
+AcpiNsDumpOneObject (
+    ACPI_HANDLE             ObjHandle,
+    UINT32                  Level,
+    void                    *Context,
+    void                    **ReturnValue);
+
+void
+AcpiNsDumpObjects (
+    ACPI_OBJECT_TYPE        Type,
+    UINT8                   DisplayType,
+    UINT32                  MaxDepth,
+    ACPI_OWNER_ID           OwnerId,
+    ACPI_HANDLE             StartHandle);
+
+void
+AcpiNsDumpObjectPaths (
+    ACPI_OBJECT_TYPE        Type,
+    UINT8                   DisplayType,
+    UINT32                  MaxDepth,
+    ACPI_OWNER_ID           OwnerId,
+    ACPI_HANDLE             StartHandle);
+
+
+/*
+ * nseval - Namespace evaluation functions
+ */
+ACPI_STATUS
+AcpiNsEvaluate (
+    ACPI_EVALUATE_INFO      *Info);
+
+void
+AcpiNsExecModuleCodeList (
+    void);
+
+
+/*
+ * nsarguments - Argument count/type checking for predefined/reserved names
+ */
+void
+AcpiNsCheckArgumentCount (
+    char                        *Pathname,
+    ACPI_NAMESPACE_NODE         *Node,
+    UINT32                      UserParamCount,
+    const ACPI_PREDEFINED_INFO  *Info);
+
+void
+AcpiNsCheckAcpiCompliance (
+    char                        *Pathname,
+    ACPI_NAMESPACE_NODE         *Node,
+    const ACPI_PREDEFINED_INFO  *Predefined);
+
+void
+AcpiNsCheckArgumentTypes (
+    ACPI_EVALUATE_INFO          *Info);
+
+
+/*
+ * nspredef - Return value checking for predefined/reserved names
+ */
+ACPI_STATUS
+AcpiNsCheckReturnValue (
+    ACPI_NAMESPACE_NODE         *Node,
+    ACPI_EVALUATE_INFO          *Info,
+    UINT32                      UserParamCount,
+    ACPI_STATUS                 ReturnStatus,
+    ACPI_OPERAND_OBJECT         **ReturnObject);
+
+ACPI_STATUS
+AcpiNsCheckObjectType (
+    ACPI_EVALUATE_INFO          *Info,
+    ACPI_OPERAND_OBJECT         **ReturnObjectPtr,
+    UINT32                      ExpectedBtypes,
+    UINT32                      PackageIndex);
+
+
+/*
+ * nsprepkg - Validation of predefined name packages
+ */
+ACPI_STATUS
+AcpiNsCheckPackage (
+    ACPI_EVALUATE_INFO          *Info,
+    ACPI_OPERAND_OBJECT         **ReturnObjectPtr);
+
+
+/*
+ * nsnames - Name and Scope manipulation
+ */
+UINT32
+AcpiNsOpensScope (
+    ACPI_OBJECT_TYPE        Type);
+
+char *
+AcpiNsGetExternalPathname (
+    ACPI_NAMESPACE_NODE     *Node);
+
+UINT32
+AcpiNsBuildNormalizedPath (
+    ACPI_NAMESPACE_NODE     *Node,
+    char                    *FullPath,
+    UINT32                  PathSize,
+    BOOLEAN                 NoTrailing);
+
+char *
+AcpiNsGetNormalizedPathname (
+    ACPI_NAMESPACE_NODE     *Node,
+    BOOLEAN                 NoTrailing);
+
+char *
+AcpiNsNameOfCurrentScope (
+    ACPI_WALK_STATE         *WalkState);
+
+ACPI_STATUS
+AcpiNsHandleToPathname (
+    ACPI_HANDLE             TargetHandle,
+    ACPI_BUFFER             *Buffer,
+    BOOLEAN                 NoTrailing);
+
+BOOLEAN
+AcpiNsPatternMatch (
+    ACPI_NAMESPACE_NODE     *ObjNode,
+    char                    *SearchFor);
+
+ACPI_STATUS
+AcpiNsGetNode (
+    ACPI_NAMESPACE_NODE     *PrefixNode,
+    const char              *ExternalPathname,
+    UINT32                  Flags,
+    ACPI_NAMESPACE_NODE     **OutNode);
+
+ACPI_SIZE
+AcpiNsGetPathnameLength (
+    ACPI_NAMESPACE_NODE     *Node);
+
+
+/*
+ * nsobject - Object management for namespace nodes
+ */
+ACPI_STATUS
+AcpiNsAttachObject (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_OPERAND_OBJECT     *Object,
+    ACPI_OBJECT_TYPE        Type);
+
+ACPI_OPERAND_OBJECT *
+AcpiNsGetAttachedObject (
+    ACPI_NAMESPACE_NODE     *Node);
+
+ACPI_OPERAND_OBJECT *
+AcpiNsGetSecondaryObject (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+ACPI_STATUS
+AcpiNsAttachData (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_OBJECT_HANDLER     Handler,
+    void                    *Data);
+
+ACPI_STATUS
+AcpiNsDetachData (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_OBJECT_HANDLER     Handler);
+
+ACPI_STATUS
+AcpiNsGetAttachedData (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_OBJECT_HANDLER     Handler,
+    void                    **Data);
+
+
+/*
+ * nsrepair - General return object repair for all
+ * predefined methods/objects
+ */
+ACPI_STATUS
+AcpiNsSimpleRepair (
+    ACPI_EVALUATE_INFO      *Info,
+    UINT32                  ExpectedBtypes,
+    UINT32                  PackageIndex,
+    ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
+
+ACPI_STATUS
+AcpiNsWrapWithPackage (
+    ACPI_EVALUATE_INFO      *Info,
+    ACPI_OPERAND_OBJECT     *OriginalObject,
+    ACPI_OPERAND_OBJECT     **ObjDescPtr);
+
+ACPI_STATUS
+AcpiNsRepairNullElement (
+    ACPI_EVALUATE_INFO      *Info,
+    UINT32                  ExpectedBtypes,
+    UINT32                  PackageIndex,
+    ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
+
+void
+AcpiNsRemoveNullElements (
+    ACPI_EVALUATE_INFO      *Info,
+    UINT8                   PackageType,
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+
+/*
+ * nsrepair2 - Return object repair for specific
+ * predefined methods/objects
+ */
+ACPI_STATUS
+AcpiNsComplexRepairs (
+    ACPI_EVALUATE_INFO      *Info,
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_STATUS             ValidateStatus,
+    ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
+
+
+/*
+ * nssearch - Namespace searching and entry
+ */
+ACPI_STATUS
+AcpiNsSearchAndEnter (
+    UINT32                  EntryName,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_INTERPRETER_MODE   InterpreterMode,
+    ACPI_OBJECT_TYPE        Type,
+    UINT32                  Flags,
+    ACPI_NAMESPACE_NODE     **RetNode);
+
+ACPI_STATUS
+AcpiNsSearchOneScope (
+    UINT32                  EntryName,
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_OBJECT_TYPE        Type,
+    ACPI_NAMESPACE_NODE     **RetNode);
+
+void
+AcpiNsInstallNode (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_NAMESPACE_NODE     *ParentNode,
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_OBJECT_TYPE        Type);
+
+
+/*
+ * nsutils - Utility functions
+ */
+ACPI_OBJECT_TYPE
+AcpiNsGetType (
+    ACPI_NAMESPACE_NODE     *Node);
+
+UINT32
+AcpiNsLocal (
+    ACPI_OBJECT_TYPE        Type);
+
+void
+AcpiNsPrintNodePathname (
+    ACPI_NAMESPACE_NODE     *Node,
+    const char              *Msg);
+
+ACPI_STATUS
+AcpiNsBuildInternalName (
+    ACPI_NAMESTRING_INFO    *Info);
+
+void
+AcpiNsGetInternalNameLength (
+    ACPI_NAMESTRING_INFO    *Info);
+
+ACPI_STATUS
+AcpiNsInternalizeName (
+    const char              *DottedName,
+    char                    **ConvertedName);
+
+ACPI_STATUS
+AcpiNsExternalizeName (
+    UINT32                  InternalNameLength,
+    const char              *InternalName,
+    UINT32                  *ConvertedNameLength,
+    char                    **ConvertedName);
+
+ACPI_NAMESPACE_NODE *
+AcpiNsValidateHandle (
+    ACPI_HANDLE             Handle);
+
+void
+AcpiNsTerminate (
+    void);
+
+#endif /* __ACNAMESP_H__ */

+ 591 - 0
kernel/include/acpica/acobject.h

@@ -0,0 +1,591 @@
+/******************************************************************************
+ *
+ * Name: acobject.h - Definition of ACPI_OPERAND_OBJECT  (Internal object only)
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 _ACOBJECT_H
+#define _ACOBJECT_H
+
+/* acpisrc:StructDefs -- for acpisrc conversion */
+
+
+/*
+ * The ACPI_OPERAND_OBJECT is used to pass AML operands from the dispatcher
+ * to the interpreter, and to keep track of the various handlers such as
+ * address space handlers and notify handlers. The object is a constant
+ * size in order to allow it to be cached and reused.
+ *
+ * Note: The object is optimized to be aligned and will not work if it is
+ * byte-packed.
+ */
+#if ACPI_MACHINE_WIDTH == 64
+#pragma pack(8)
+#else
+#pragma pack(4)
+#endif
+
+/*******************************************************************************
+ *
+ * Common Descriptors
+ *
+ ******************************************************************************/
+
+/*
+ * Common area for all objects.
+ *
+ * DescriptorType is used to differentiate between internal descriptors, and
+ * must be in the same place across all descriptors
+ *
+ * Note: The DescriptorType and Type fields must appear in the identical
+ * position in both the ACPI_NAMESPACE_NODE and ACPI_OPERAND_OBJECT
+ * structures.
+ */
+#define ACPI_OBJECT_COMMON_HEADER \
+    union acpi_operand_object       *NextObject;        /* Objects linked to parent NS node */\
+    UINT8                           DescriptorType;     /* To differentiate various internal objs */\
+    UINT8                           Type;               /* ACPI_OBJECT_TYPE */\
+    UINT16                          ReferenceCount;     /* For object deletion management */\
+    UINT8                           Flags;
+    /*
+     * Note: There are 3 bytes available here before the
+     * next natural alignment boundary (for both 32/64 cases)
+     */
+
+/* Values for Flag byte above */
+
+#define AOPOBJ_AML_CONSTANT         0x01    /* Integer is an AML constant */
+#define AOPOBJ_STATIC_POINTER       0x02    /* Data is part of an ACPI table, don't delete */
+#define AOPOBJ_DATA_VALID           0x04    /* Object is initialized and data is valid */
+#define AOPOBJ_OBJECT_INITIALIZED   0x08    /* Region is initialized */
+#define AOPOBJ_REG_CONNECTED        0x10    /* _REG was run */
+#define AOPOBJ_SETUP_COMPLETE       0x20    /* Region setup is complete */
+#define AOPOBJ_INVALID              0x40    /* Host OS won't allow a Region address */
+
+
+/******************************************************************************
+ *
+ * Basic data types
+ *
+ *****************************************************************************/
+
+typedef struct acpi_object_common
+{
+    ACPI_OBJECT_COMMON_HEADER
+
+} ACPI_OBJECT_COMMON;
+
+
+typedef struct acpi_object_integer
+{
+    ACPI_OBJECT_COMMON_HEADER
+    UINT8                           Fill[3];            /* Prevent warning on some compilers */
+    UINT64                          Value;
+
+} ACPI_OBJECT_INTEGER;
+
+
+/*
+ * Note: The String and Buffer object must be identical through the
+ * pointer and length elements. There is code that depends on this.
+ *
+ * Fields common to both Strings and Buffers
+ */
+#define ACPI_COMMON_BUFFER_INFO(_Type) \
+    _Type                           *Pointer; \
+    UINT32                          Length;
+
+
+typedef struct acpi_object_string   /* Null terminated, ASCII characters only */
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_BUFFER_INFO         (char)              /* String in AML stream or allocated string */
+
+} ACPI_OBJECT_STRING;
+
+
+typedef struct acpi_object_buffer
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_BUFFER_INFO         (UINT8)             /* Buffer in AML stream or allocated buffer */
+    UINT32                          AmlLength;
+    UINT8                           *AmlStart;
+    ACPI_NAMESPACE_NODE             *Node;              /* Link back to parent node */
+
+} ACPI_OBJECT_BUFFER;
+
+
+typedef struct acpi_object_package
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_NAMESPACE_NODE             *Node;              /* Link back to parent node */
+    union acpi_operand_object       **Elements;         /* Array of pointers to AcpiObjects */
+    UINT8                           *AmlStart;
+    UINT32                          AmlLength;
+    UINT32                          Count;              /* # of elements in package */
+
+} ACPI_OBJECT_PACKAGE;
+
+
+/******************************************************************************
+ *
+ * Complex data types
+ *
+ *****************************************************************************/
+
+typedef struct acpi_object_event
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_SEMAPHORE                  OsSemaphore;        /* Actual OS synchronization object */
+
+} ACPI_OBJECT_EVENT;
+
+
+typedef struct acpi_object_mutex
+{
+    ACPI_OBJECT_COMMON_HEADER
+    UINT8                           SyncLevel;          /* 0-15, specified in Mutex() call */
+    UINT16                          AcquisitionDepth;   /* Allow multiple Acquires, same thread */
+    ACPI_MUTEX                      OsMutex;            /* Actual OS synchronization object */
+    ACPI_THREAD_ID                  ThreadId;           /* Current owner of the mutex */
+    struct acpi_thread_state        *OwnerThread;       /* Current owner of the mutex */
+    union acpi_operand_object       *Prev;              /* Link for list of acquired mutexes */
+    union acpi_operand_object       *Next;              /* Link for list of acquired mutexes */
+    ACPI_NAMESPACE_NODE             *Node;              /* Containing namespace node */
+    UINT8                           OriginalSyncLevel;  /* Owner's original sync level (0-15) */
+
+} ACPI_OBJECT_MUTEX;
+
+
+typedef struct acpi_object_region
+{
+    ACPI_OBJECT_COMMON_HEADER
+    UINT8                           SpaceId;
+    ACPI_NAMESPACE_NODE             *Node;              /* Containing namespace node */
+    union acpi_operand_object       *Handler;           /* Handler for region access */
+    union acpi_operand_object       *Next;
+    ACPI_PHYSICAL_ADDRESS           Address;
+    UINT32                          Length;
+
+} ACPI_OBJECT_REGION;
+
+
+typedef struct acpi_object_method
+{
+    ACPI_OBJECT_COMMON_HEADER
+    UINT8                           InfoFlags;
+    UINT8                           ParamCount;
+    UINT8                           SyncLevel;
+    union acpi_operand_object       *Mutex;
+    union acpi_operand_object       *Node;
+    UINT8                           *AmlStart;
+    union
+    {
+        ACPI_INTERNAL_METHOD            Implementation;
+        union acpi_operand_object       *Handler;
+    } Dispatch;
+
+    UINT32                          AmlLength;
+    UINT8                           ThreadCount;
+    ACPI_OWNER_ID                   OwnerId;
+
+} ACPI_OBJECT_METHOD;
+
+/* Flags for InfoFlags field above */
+
+#define ACPI_METHOD_MODULE_LEVEL        0x01    /* Method is actually module-level code */
+#define ACPI_METHOD_INTERNAL_ONLY       0x02    /* Method is implemented internally (_OSI) */
+#define ACPI_METHOD_SERIALIZED          0x04    /* Method is serialized */
+#define ACPI_METHOD_SERIALIZED_PENDING  0x08    /* Method is to be marked serialized */
+#define ACPI_METHOD_IGNORE_SYNC_LEVEL   0x10    /* Method was auto-serialized at table load time */
+#define ACPI_METHOD_MODIFIED_NAMESPACE  0x20    /* Method modified the namespace */
+
+
+/******************************************************************************
+ *
+ * Objects that can be notified. All share a common NotifyInfo area.
+ *
+ *****************************************************************************/
+
+/*
+ * Common fields for objects that support ASL notifications
+ */
+#define ACPI_COMMON_NOTIFY_INFO \
+    union acpi_operand_object       *NotifyList[2];     /* Handlers for system/device notifies */\
+    union acpi_operand_object       *Handler;           /* Handler for Address space */
+
+
+typedef struct acpi_object_notify_common    /* COMMON NOTIFY for POWER, PROCESSOR, DEVICE, and THERMAL */
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_NOTIFY_INFO
+
+} ACPI_OBJECT_NOTIFY_COMMON;
+
+
+typedef struct acpi_object_device
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_NOTIFY_INFO
+    ACPI_GPE_BLOCK_INFO             *GpeBlock;
+
+} ACPI_OBJECT_DEVICE;
+
+
+typedef struct acpi_object_power_resource
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_NOTIFY_INFO
+    UINT32                          SystemLevel;
+    UINT32                          ResourceOrder;
+
+} ACPI_OBJECT_POWER_RESOURCE;
+
+
+typedef struct acpi_object_processor
+{
+    ACPI_OBJECT_COMMON_HEADER
+
+    /* The next two fields take advantage of the 3-byte space before NOTIFY_INFO */
+
+    UINT8                           ProcId;
+    UINT8                           Length;
+    ACPI_COMMON_NOTIFY_INFO
+    ACPI_IO_ADDRESS                 Address;
+
+} ACPI_OBJECT_PROCESSOR;
+
+
+typedef struct acpi_object_thermal_zone
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_NOTIFY_INFO
+
+} ACPI_OBJECT_THERMAL_ZONE;
+
+
+/******************************************************************************
+ *
+ * Fields. All share a common header/info field.
+ *
+ *****************************************************************************/
+
+/*
+ * Common bitfield for the field objects
+ * "Field Datum"  -- a datum from the actual field object
+ * "Buffer Datum" -- a datum from a user buffer, read from or to be written to the field
+ */
+#define ACPI_COMMON_FIELD_INFO \
+    UINT8                           FieldFlags;         /* Access, update, and lock bits */\
+    UINT8                           Attribute;          /* From AccessAs keyword */\
+    UINT8                           AccessByteWidth;    /* Read/Write size in bytes */\
+    ACPI_NAMESPACE_NODE             *Node;              /* Link back to parent node */\
+    UINT32                          BitLength;          /* Length of field in bits */\
+    UINT32                          BaseByteOffset;     /* Byte offset within containing object */\
+    UINT32                          Value;              /* Value to store into the Bank or Index register */\
+    UINT8                           StartFieldBitOffset;/* Bit offset within first field datum (0-63) */\
+    UINT8                           AccessLength;       /* For serial regions/fields */
+
+
+typedef struct acpi_object_field_common                 /* COMMON FIELD (for BUFFER, REGION, BANK, and INDEX fields) */
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_FIELD_INFO
+    union acpi_operand_object       *RegionObj;         /* Parent Operation Region object (REGION/BANK fields only) */
+
+} ACPI_OBJECT_FIELD_COMMON;
+
+
+typedef struct acpi_object_region_field
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_FIELD_INFO
+    UINT16                          ResourceLength;
+    union acpi_operand_object       *RegionObj;         /* Containing OpRegion object */
+    UINT8                           *ResourceBuffer;    /* ResourceTemplate for serial regions/fields */
+    UINT16                          PinNumberIndex;     /* Index relative to previous Connection/Template */
+
+} ACPI_OBJECT_REGION_FIELD;
+
+
+typedef struct acpi_object_bank_field
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_FIELD_INFO
+    union acpi_operand_object       *RegionObj;         /* Containing OpRegion object */
+    union acpi_operand_object       *BankObj;           /* BankSelect Register object */
+
+} ACPI_OBJECT_BANK_FIELD;
+
+
+typedef struct acpi_object_index_field
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_FIELD_INFO
+
+    /*
+     * No "RegionObj" pointer needed since the Index and Data registers
+     * are each field definitions unto themselves.
+     */
+    union acpi_operand_object       *IndexObj;          /* Index register */
+    union acpi_operand_object       *DataObj;           /* Data register */
+
+} ACPI_OBJECT_INDEX_FIELD;
+
+
+/* The BufferField is different in that it is part of a Buffer, not an OpRegion */
+
+typedef struct acpi_object_buffer_field
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_COMMON_FIELD_INFO
+    union acpi_operand_object       *BufferObj;         /* Containing Buffer object */
+
+} ACPI_OBJECT_BUFFER_FIELD;
+
+
+/******************************************************************************
+ *
+ * Objects for handlers
+ *
+ *****************************************************************************/
+
+typedef struct acpi_object_notify_handler
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_NAMESPACE_NODE             *Node;              /* Parent device */
+    UINT32                          HandlerType;        /* Type: Device/System/Both */
+    ACPI_NOTIFY_HANDLER             Handler;            /* Handler address */
+    void                            *Context;
+    union acpi_operand_object       *Next[2];           /* Device and System handler lists */
+
+} ACPI_OBJECT_NOTIFY_HANDLER;
+
+
+typedef struct acpi_object_addr_handler
+{
+    ACPI_OBJECT_COMMON_HEADER
+    UINT8                           SpaceId;
+    UINT8                           HandlerFlags;
+    ACPI_ADR_SPACE_HANDLER          Handler;
+    ACPI_NAMESPACE_NODE             *Node;              /* Parent device */
+    void                            *Context;
+    ACPI_ADR_SPACE_SETUP            Setup;
+    union acpi_operand_object       *RegionList;        /* Regions using this handler */
+    union acpi_operand_object       *Next;
+
+} ACPI_OBJECT_ADDR_HANDLER;
+
+/* Flags for address handler (HandlerFlags) */
+
+#define ACPI_ADDR_HANDLER_DEFAULT_INSTALLED  0x01
+
+
+/******************************************************************************
+ *
+ * Special internal objects
+ *
+ *****************************************************************************/
+
+/*
+ * The Reference object is used for these opcodes:
+ * Arg[0-6], Local[0-7], IndexOp, NameOp, RefOfOp, LoadOp, LoadTableOp, DebugOp
+ * The Reference.Class differentiates these types.
+ */
+typedef struct acpi_object_reference
+{
+    ACPI_OBJECT_COMMON_HEADER
+    UINT8                           Class;              /* Reference Class */
+    UINT8                           TargetType;         /* Used for Index Op */
+    UINT8                           Reserved;
+    void                            *Object;            /* NameOp=>HANDLE to obj, IndexOp=>ACPI_OPERAND_OBJECT */
+    ACPI_NAMESPACE_NODE             *Node;              /* RefOf or Namepath */
+    union acpi_operand_object       **Where;            /* Target of Index */
+    UINT8                           *IndexPointer;      /* Used for Buffers and Strings */
+    UINT32                          Value;              /* Used for Local/Arg/Index/DdbHandle */
+
+} ACPI_OBJECT_REFERENCE;
+
+/* Values for Reference.Class above */
+
+typedef enum
+{
+    ACPI_REFCLASS_LOCAL             = 0,        /* Method local */
+    ACPI_REFCLASS_ARG               = 1,        /* Method argument */
+    ACPI_REFCLASS_REFOF             = 2,        /* Result of RefOf() TBD: Split to Ref/Node and Ref/OperandObj? */
+    ACPI_REFCLASS_INDEX             = 3,        /* Result of Index() */
+    ACPI_REFCLASS_TABLE             = 4,        /* DdbHandle - Load(), LoadTable() */
+    ACPI_REFCLASS_NAME              = 5,        /* Reference to a named object */
+    ACPI_REFCLASS_DEBUG             = 6,        /* Debug object */
+
+    ACPI_REFCLASS_MAX               = 6
+
+} ACPI_REFERENCE_CLASSES;
+
+
+/*
+ * Extra object is used as additional storage for types that
+ * have AML code in their declarations (TermArgs) that must be
+ * evaluated at run time.
+ *
+ * Currently: Region and FieldUnit types
+ */
+typedef struct acpi_object_extra
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_NAMESPACE_NODE             *Method_REG;        /* _REG method for this region (if any) */
+    ACPI_NAMESPACE_NODE             *ScopeNode;
+    void                            *RegionContext;     /* Region-specific data */
+    UINT8                           *AmlStart;
+    UINT32                          AmlLength;
+
+} ACPI_OBJECT_EXTRA;
+
+
+/* Additional data that can be attached to namespace nodes */
+
+typedef struct acpi_object_data
+{
+    ACPI_OBJECT_COMMON_HEADER
+    ACPI_OBJECT_HANDLER             Handler;
+    void                            *Pointer;
+
+} ACPI_OBJECT_DATA;
+
+
+/* Structure used when objects are cached for reuse */
+
+typedef struct acpi_object_cache_list
+{
+    ACPI_OBJECT_COMMON_HEADER
+    union acpi_operand_object       *Next;              /* Link for object cache and internal lists*/
+
+} ACPI_OBJECT_CACHE_LIST;
+
+
+/******************************************************************************
+ *
+ * ACPI_OPERAND_OBJECT Descriptor - a giant union of all of the above
+ *
+ *****************************************************************************/
+
+typedef union acpi_operand_object
+{
+    ACPI_OBJECT_COMMON                  Common;
+    ACPI_OBJECT_INTEGER                 Integer;
+    ACPI_OBJECT_STRING                  String;
+    ACPI_OBJECT_BUFFER                  Buffer;
+    ACPI_OBJECT_PACKAGE                 Package;
+    ACPI_OBJECT_EVENT                   Event;
+    ACPI_OBJECT_METHOD                  Method;
+    ACPI_OBJECT_MUTEX                   Mutex;
+    ACPI_OBJECT_REGION                  Region;
+    ACPI_OBJECT_NOTIFY_COMMON           CommonNotify;
+    ACPI_OBJECT_DEVICE                  Device;
+    ACPI_OBJECT_POWER_RESOURCE          PowerResource;
+    ACPI_OBJECT_PROCESSOR               Processor;
+    ACPI_OBJECT_THERMAL_ZONE            ThermalZone;
+    ACPI_OBJECT_FIELD_COMMON            CommonField;
+    ACPI_OBJECT_REGION_FIELD            Field;
+    ACPI_OBJECT_BUFFER_FIELD            BufferField;
+    ACPI_OBJECT_BANK_FIELD              BankField;
+    ACPI_OBJECT_INDEX_FIELD             IndexField;
+    ACPI_OBJECT_NOTIFY_HANDLER          Notify;
+    ACPI_OBJECT_ADDR_HANDLER            AddressSpace;
+    ACPI_OBJECT_REFERENCE               Reference;
+    ACPI_OBJECT_EXTRA                   Extra;
+    ACPI_OBJECT_DATA                    Data;
+    ACPI_OBJECT_CACHE_LIST              Cache;
+
+    /*
+     * Add namespace node to union in order to simplify code that accepts both
+     * ACPI_OPERAND_OBJECTs and ACPI_NAMESPACE_NODEs. The structures share
+     * a common DescriptorType field in order to differentiate them.
+     */
+    ACPI_NAMESPACE_NODE                 Node;
+
+} ACPI_OPERAND_OBJECT;
+
+
+/******************************************************************************
+ *
+ * ACPI_DESCRIPTOR - objects that share a common descriptor identifier
+ *
+ *****************************************************************************/
+
+/* Object descriptor types */
+
+#define ACPI_DESC_TYPE_CACHED           0x01        /* Used only when object is cached */
+#define ACPI_DESC_TYPE_STATE            0x02
+#define ACPI_DESC_TYPE_STATE_UPDATE     0x03
+#define ACPI_DESC_TYPE_STATE_PACKAGE    0x04
+#define ACPI_DESC_TYPE_STATE_CONTROL    0x05
+#define ACPI_DESC_TYPE_STATE_RPSCOPE    0x06
+#define ACPI_DESC_TYPE_STATE_PSCOPE     0x07
+#define ACPI_DESC_TYPE_STATE_WSCOPE     0x08
+#define ACPI_DESC_TYPE_STATE_RESULT     0x09
+#define ACPI_DESC_TYPE_STATE_NOTIFY     0x0A
+#define ACPI_DESC_TYPE_STATE_THREAD     0x0B
+#define ACPI_DESC_TYPE_WALK             0x0C
+#define ACPI_DESC_TYPE_PARSER           0x0D
+#define ACPI_DESC_TYPE_OPERAND          0x0E
+#define ACPI_DESC_TYPE_NAMED            0x0F
+#define ACPI_DESC_TYPE_MAX              0x0F
+
+
+typedef struct acpi_common_descriptor
+{
+    void                            *CommonPointer;
+    UINT8                           DescriptorType; /* To differentiate various internal objs */
+
+} ACPI_COMMON_DESCRIPTOR;
+
+typedef union acpi_descriptor
+{
+    ACPI_COMMON_DESCRIPTOR          Common;
+    ACPI_OPERAND_OBJECT             Object;
+    ACPI_NAMESPACE_NODE             Node;
+    ACPI_PARSE_OBJECT               Op;
+
+} ACPI_DESCRIPTOR;
+
+#pragma pack()
+
+#endif /* _ACOBJECT_H */

+ 331 - 0
kernel/include/acpica/acopcode.h

@@ -0,0 +1,331 @@
+/******************************************************************************
+ *
+ * Name: acopcode.h - AML opcode information for the AML parser and interpreter
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACOPCODE_H__
+#define __ACOPCODE_H__
+
+#define MAX_EXTENDED_OPCODE         0x88
+#define NUM_EXTENDED_OPCODE         (MAX_EXTENDED_OPCODE + 1)
+#define MAX_INTERNAL_OPCODE
+#define NUM_INTERNAL_OPCODE         (MAX_INTERNAL_OPCODE + 1)
+
+/* Used for non-assigned opcodes */
+
+#define _UNK                        0x6B
+
+/*
+ * Reserved ASCII characters. Do not use any of these for
+ * internal opcodes, since they are used to differentiate
+ * name strings from AML opcodes
+ */
+#define _ASC                        0x6C
+#define _NAM                        0x6C
+#define _PFX                        0x6D
+
+
+/*
+ * All AML opcodes and the parse-time arguments for each. Used by the AML
+ * parser  Each list is compressed into a 32-bit number and stored in the
+ * master opcode table (in psopcode.c).
+ */
+#define ARGP_ACCESSFIELD_OP             ARGP_LIST1 (ARGP_NAMESTRING)
+#define ARGP_ACQUIRE_OP                 ARGP_LIST2 (ARGP_SUPERNAME,  ARGP_WORDDATA)
+#define ARGP_ADD_OP                     ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_ALIAS_OP                   ARGP_LIST2 (ARGP_NAMESTRING, ARGP_NAME)
+#define ARGP_ARG0                       ARG_NONE
+#define ARGP_ARG1                       ARG_NONE
+#define ARGP_ARG2                       ARG_NONE
+#define ARGP_ARG3                       ARG_NONE
+#define ARGP_ARG4                       ARG_NONE
+#define ARGP_ARG5                       ARG_NONE
+#define ARGP_ARG6                       ARG_NONE
+#define ARGP_BANK_FIELD_OP              ARGP_LIST6 (ARGP_PKGLENGTH,  ARGP_NAMESTRING,    ARGP_NAMESTRING,ARGP_TERMARG,   ARGP_BYTEDATA,  ARGP_FIELDLIST)
+#define ARGP_BIT_AND_OP                 ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_BIT_NAND_OP                ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_BIT_NOR_OP                 ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_BIT_NOT_OP                 ARGP_LIST2 (ARGP_TERMARG,    ARGP_TARGET)
+#define ARGP_BIT_OR_OP                  ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_BIT_XOR_OP                 ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_BREAK_OP                   ARG_NONE
+#define ARGP_BREAK_POINT_OP             ARG_NONE
+#define ARGP_BUFFER_OP                  ARGP_LIST3 (ARGP_PKGLENGTH,  ARGP_TERMARG,       ARGP_BYTELIST)
+#define ARGP_BYTE_OP                    ARGP_LIST1 (ARGP_BYTEDATA)
+#define ARGP_BYTELIST_OP                ARGP_LIST1 (ARGP_NAMESTRING)
+#define ARGP_CONCAT_OP                  ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_CONCAT_RES_OP              ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_COND_REF_OF_OP             ARGP_LIST2 (ARGP_NAME_OR_REF,ARGP_TARGET)
+#define ARGP_CONNECTFIELD_OP            ARGP_LIST1 (ARGP_NAMESTRING)
+#define ARGP_CONTINUE_OP                ARG_NONE
+#define ARGP_COPY_OP                    ARGP_LIST2 (ARGP_TERMARG,    ARGP_SIMPLENAME)
+#define ARGP_CREATE_BIT_FIELD_OP        ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_NAME)
+#define ARGP_CREATE_BYTE_FIELD_OP       ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_NAME)
+#define ARGP_CREATE_DWORD_FIELD_OP      ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_NAME)
+#define ARGP_CREATE_FIELD_OP            ARGP_LIST4 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TERMARG,   ARGP_NAME)
+#define ARGP_CREATE_QWORD_FIELD_OP      ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_NAME)
+#define ARGP_CREATE_WORD_FIELD_OP       ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_NAME)
+#define ARGP_DATA_REGION_OP             ARGP_LIST4 (ARGP_NAME,       ARGP_TERMARG,       ARGP_TERMARG,   ARGP_TERMARG)
+#define ARGP_DEBUG_OP                   ARG_NONE
+#define ARGP_DECREMENT_OP               ARGP_LIST1 (ARGP_SUPERNAME)
+#define ARGP_DEREF_OF_OP                ARGP_LIST1 (ARGP_TERMARG)
+#define ARGP_DEVICE_OP                  ARGP_LIST3 (ARGP_PKGLENGTH,  ARGP_NAME,          ARGP_OBJLIST)
+#define ARGP_DIVIDE_OP                  ARGP_LIST4 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET,    ARGP_TARGET)
+#define ARGP_DWORD_OP                   ARGP_LIST1 (ARGP_DWORDDATA)
+#define ARGP_ELSE_OP                    ARGP_LIST2 (ARGP_PKGLENGTH,  ARGP_TERMLIST)
+#define ARGP_EVENT_OP                   ARGP_LIST1 (ARGP_NAME)
+#define ARGP_EXTERNAL_OP                ARGP_LIST3 (ARGP_NAMESTRING, ARGP_BYTEDATA,      ARGP_BYTEDATA)
+#define ARGP_FATAL_OP                   ARGP_LIST3 (ARGP_BYTEDATA,   ARGP_DWORDDATA,     ARGP_TERMARG)
+#define ARGP_FIELD_OP                   ARGP_LIST4 (ARGP_PKGLENGTH,  ARGP_NAMESTRING,    ARGP_BYTEDATA,  ARGP_FIELDLIST)
+#define ARGP_FIND_SET_LEFT_BIT_OP       ARGP_LIST2 (ARGP_TERMARG,    ARGP_TARGET)
+#define ARGP_FIND_SET_RIGHT_BIT_OP      ARGP_LIST2 (ARGP_TERMARG,    ARGP_TARGET)
+#define ARGP_FROM_BCD_OP                ARGP_LIST2 (ARGP_TERMARG,    ARGP_TARGET)
+#define ARGP_IF_OP                      ARGP_LIST3 (ARGP_PKGLENGTH,  ARGP_TERMARG,       ARGP_TERMLIST)
+#define ARGP_INCREMENT_OP               ARGP_LIST1 (ARGP_SUPERNAME)
+#define ARGP_INDEX_FIELD_OP             ARGP_LIST5 (ARGP_PKGLENGTH,  ARGP_NAMESTRING,    ARGP_NAMESTRING,ARGP_BYTEDATA,  ARGP_FIELDLIST)
+#define ARGP_INDEX_OP                   ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_LAND_OP                    ARGP_LIST2 (ARGP_TERMARG,    ARGP_TERMARG)
+#define ARGP_LEQUAL_OP                  ARGP_LIST2 (ARGP_TERMARG,    ARGP_TERMARG)
+#define ARGP_LGREATER_OP                ARGP_LIST2 (ARGP_TERMARG,    ARGP_TERMARG)
+#define ARGP_LGREATEREQUAL_OP           ARGP_LIST2 (ARGP_TERMARG,    ARGP_TERMARG)
+#define ARGP_LLESS_OP                   ARGP_LIST2 (ARGP_TERMARG,    ARGP_TERMARG)
+#define ARGP_LLESSEQUAL_OP              ARGP_LIST2 (ARGP_TERMARG,    ARGP_TERMARG)
+#define ARGP_LNOT_OP                    ARGP_LIST1 (ARGP_TERMARG)
+#define ARGP_LNOTEQUAL_OP               ARGP_LIST2 (ARGP_TERMARG,    ARGP_TERMARG)
+#define ARGP_LOAD_OP                    ARGP_LIST2 (ARGP_NAMESTRING, ARGP_SUPERNAME)
+#define ARGP_LOAD_TABLE_OP              ARGP_LIST6 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TERMARG,   ARGP_TERMARG,  ARGP_TERMARG,   ARGP_TERMARG)
+#define ARGP_LOCAL0                     ARG_NONE
+#define ARGP_LOCAL1                     ARG_NONE
+#define ARGP_LOCAL2                     ARG_NONE
+#define ARGP_LOCAL3                     ARG_NONE
+#define ARGP_LOCAL4                     ARG_NONE
+#define ARGP_LOCAL5                     ARG_NONE
+#define ARGP_LOCAL6                     ARG_NONE
+#define ARGP_LOCAL7                     ARG_NONE
+#define ARGP_LOR_OP                     ARGP_LIST2 (ARGP_TERMARG,    ARGP_TERMARG)
+#define ARGP_MATCH_OP                   ARGP_LIST6 (ARGP_TERMARG,    ARGP_BYTEDATA,      ARGP_TERMARG,   ARGP_BYTEDATA,  ARGP_TERMARG,   ARGP_TERMARG)
+#define ARGP_METHOD_OP                  ARGP_LIST4 (ARGP_PKGLENGTH,  ARGP_NAME,          ARGP_BYTEDATA,  ARGP_TERMLIST)
+#define ARGP_METHODCALL_OP              ARGP_LIST1 (ARGP_NAMESTRING)
+#define ARGP_MID_OP                     ARGP_LIST4 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TERMARG,   ARGP_TARGET)
+#define ARGP_MOD_OP                     ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_MULTIPLY_OP                ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_MUTEX_OP                   ARGP_LIST2 (ARGP_NAME,       ARGP_BYTEDATA)
+#define ARGP_NAME_OP                    ARGP_LIST2 (ARGP_NAME,       ARGP_DATAOBJ)
+#define ARGP_NAMEDFIELD_OP              ARGP_LIST1 (ARGP_NAMESTRING)
+#define ARGP_NAMEPATH_OP                ARGP_LIST1 (ARGP_NAMESTRING)
+#define ARGP_NOOP_OP                    ARG_NONE
+#define ARGP_NOTIFY_OP                  ARGP_LIST2 (ARGP_SUPERNAME,  ARGP_TERMARG)
+#define ARGP_OBJECT_TYPE_OP             ARGP_LIST1 (ARGP_NAME_OR_REF)
+#define ARGP_ONE_OP                     ARG_NONE
+#define ARGP_ONES_OP                    ARG_NONE
+#define ARGP_PACKAGE_OP                 ARGP_LIST3 (ARGP_PKGLENGTH,  ARGP_BYTEDATA,      ARGP_DATAOBJLIST)
+#define ARGP_POWER_RES_OP               ARGP_LIST5 (ARGP_PKGLENGTH,  ARGP_NAME,          ARGP_BYTEDATA,  ARGP_WORDDATA,  ARGP_OBJLIST)
+#define ARGP_PROCESSOR_OP               ARGP_LIST6 (ARGP_PKGLENGTH,  ARGP_NAME,          ARGP_BYTEDATA,  ARGP_DWORDDATA, ARGP_BYTEDATA,  ARGP_OBJLIST)
+#define ARGP_QWORD_OP                   ARGP_LIST1 (ARGP_QWORDDATA)
+#define ARGP_REF_OF_OP                  ARGP_LIST1 (ARGP_NAME_OR_REF)
+#define ARGP_REGION_OP                  ARGP_LIST4 (ARGP_NAME,       ARGP_BYTEDATA,      ARGP_TERMARG,   ARGP_TERMARG)
+#define ARGP_RELEASE_OP                 ARGP_LIST1 (ARGP_SUPERNAME)
+#define ARGP_RESERVEDFIELD_OP           ARGP_LIST1 (ARGP_NAMESTRING)
+#define ARGP_RESET_OP                   ARGP_LIST1 (ARGP_SUPERNAME)
+#define ARGP_RETURN_OP                  ARGP_LIST1 (ARGP_TERMARG)
+#define ARGP_REVISION_OP                ARG_NONE
+#define ARGP_SCOPE_OP                   ARGP_LIST3 (ARGP_PKGLENGTH,  ARGP_NAME,          ARGP_TERMLIST)
+#define ARGP_SERIALFIELD_OP             ARGP_LIST1 (ARGP_NAMESTRING)
+#define ARGP_SHIFT_LEFT_OP              ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_SHIFT_RIGHT_OP             ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_SIGNAL_OP                  ARGP_LIST1 (ARGP_SUPERNAME)
+#define ARGP_SIZE_OF_OP                 ARGP_LIST1 (ARGP_SUPERNAME)
+#define ARGP_SLEEP_OP                   ARGP_LIST1 (ARGP_TERMARG)
+#define ARGP_STALL_OP                   ARGP_LIST1 (ARGP_TERMARG)
+#define ARGP_STATICSTRING_OP            ARGP_LIST1 (ARGP_NAMESTRING)
+#define ARGP_STORE_OP                   ARGP_LIST2 (ARGP_TERMARG,    ARGP_SUPERNAME)
+#define ARGP_STRING_OP                  ARGP_LIST1 (ARGP_CHARLIST)
+#define ARGP_SUBTRACT_OP                ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_THERMAL_ZONE_OP            ARGP_LIST3 (ARGP_PKGLENGTH,  ARGP_NAME,          ARGP_OBJLIST)
+#define ARGP_TIMER_OP                   ARG_NONE
+#define ARGP_TO_BCD_OP                  ARGP_LIST2 (ARGP_TERMARG,    ARGP_TARGET)
+#define ARGP_TO_BUFFER_OP               ARGP_LIST2 (ARGP_TERMARG,    ARGP_TARGET)
+#define ARGP_TO_DEC_STR_OP              ARGP_LIST2 (ARGP_TERMARG,    ARGP_TARGET)
+#define ARGP_TO_HEX_STR_OP              ARGP_LIST2 (ARGP_TERMARG,    ARGP_TARGET)
+#define ARGP_TO_INTEGER_OP              ARGP_LIST2 (ARGP_TERMARG,    ARGP_TARGET)
+#define ARGP_TO_STRING_OP               ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
+#define ARGP_UNLOAD_OP                  ARGP_LIST1 (ARGP_SUPERNAME)
+#define ARGP_VAR_PACKAGE_OP             ARGP_LIST3 (ARGP_PKGLENGTH,  ARGP_TERMARG,       ARGP_DATAOBJLIST)
+#define ARGP_WAIT_OP                    ARGP_LIST2 (ARGP_SUPERNAME,  ARGP_TERMARG)
+#define ARGP_WHILE_OP                   ARGP_LIST3 (ARGP_PKGLENGTH,  ARGP_TERMARG,       ARGP_TERMLIST)
+#define ARGP_WORD_OP                    ARGP_LIST1 (ARGP_WORDDATA)
+#define ARGP_ZERO_OP                    ARG_NONE
+
+
+/*
+ * All AML opcodes and the runtime arguments for each. Used by the AML
+ * interpreter  Each list is compressed into a 32-bit number and stored
+ * in the master opcode table (in psopcode.c).
+ *
+ * (Used by PrepOperands procedure and the ASL Compiler)
+ */
+#define ARGI_ACCESSFIELD_OP             ARGI_INVALID_OPCODE
+#define ARGI_ACQUIRE_OP                 ARGI_LIST2 (ARGI_MUTEX,      ARGI_INTEGER)
+#define ARGI_ADD_OP                     ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_ALIAS_OP                   ARGI_INVALID_OPCODE
+#define ARGI_ARG0                       ARG_NONE
+#define ARGI_ARG1                       ARG_NONE
+#define ARGI_ARG2                       ARG_NONE
+#define ARGI_ARG3                       ARG_NONE
+#define ARGI_ARG4                       ARG_NONE
+#define ARGI_ARG5                       ARG_NONE
+#define ARGI_ARG6                       ARG_NONE
+#define ARGI_BANK_FIELD_OP              ARGI_LIST1 (ARGI_INTEGER)
+#define ARGI_BIT_AND_OP                 ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_BIT_NAND_OP                ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_BIT_NOR_OP                 ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_BIT_NOT_OP                 ARGI_LIST2 (ARGI_INTEGER,    ARGI_TARGETREF)
+#define ARGI_BIT_OR_OP                  ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_BIT_XOR_OP                 ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_BREAK_OP                   ARG_NONE
+#define ARGI_BREAK_POINT_OP             ARG_NONE
+#define ARGI_BUFFER_OP                  ARGI_LIST1 (ARGI_INTEGER)
+#define ARGI_BYTE_OP                    ARGI_INVALID_OPCODE
+#define ARGI_BYTELIST_OP                ARGI_INVALID_OPCODE
+#define ARGI_CONCAT_OP                  ARGI_LIST3 (ARGI_ANYTYPE,    ARGI_ANYTYPE,       ARGI_TARGETREF)
+#define ARGI_CONCAT_RES_OP              ARGI_LIST3 (ARGI_BUFFER,     ARGI_BUFFER,        ARGI_TARGETREF)
+#define ARGI_COND_REF_OF_OP             ARGI_LIST2 (ARGI_OBJECT_REF, ARGI_TARGETREF)
+#define ARGI_CONNECTFIELD_OP            ARGI_INVALID_OPCODE
+#define ARGI_CONTINUE_OP                ARGI_INVALID_OPCODE
+#define ARGI_COPY_OP                    ARGI_LIST2 (ARGI_ANYTYPE,    ARGI_SIMPLE_TARGET)
+#define ARGI_CREATE_BIT_FIELD_OP        ARGI_LIST3 (ARGI_BUFFER,     ARGI_INTEGER,       ARGI_REFERENCE)
+#define ARGI_CREATE_BYTE_FIELD_OP       ARGI_LIST3 (ARGI_BUFFER,     ARGI_INTEGER,       ARGI_REFERENCE)
+#define ARGI_CREATE_DWORD_FIELD_OP      ARGI_LIST3 (ARGI_BUFFER,     ARGI_INTEGER,       ARGI_REFERENCE)
+#define ARGI_CREATE_FIELD_OP            ARGI_LIST4 (ARGI_BUFFER,     ARGI_INTEGER,       ARGI_INTEGER,      ARGI_REFERENCE)
+#define ARGI_CREATE_QWORD_FIELD_OP      ARGI_LIST3 (ARGI_BUFFER,     ARGI_INTEGER,       ARGI_REFERENCE)
+#define ARGI_CREATE_WORD_FIELD_OP       ARGI_LIST3 (ARGI_BUFFER,     ARGI_INTEGER,       ARGI_REFERENCE)
+#define ARGI_DATA_REGION_OP             ARGI_LIST3 (ARGI_STRING,     ARGI_STRING,        ARGI_STRING)
+#define ARGI_DEBUG_OP                   ARG_NONE
+#define ARGI_DECREMENT_OP               ARGI_LIST1 (ARGI_TARGETREF)
+#define ARGI_DEREF_OF_OP                ARGI_LIST1 (ARGI_REF_OR_STRING)
+#define ARGI_DEVICE_OP                  ARGI_INVALID_OPCODE
+#define ARGI_DIVIDE_OP                  ARGI_LIST4 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF,    ARGI_TARGETREF)
+#define ARGI_DWORD_OP                   ARGI_INVALID_OPCODE
+#define ARGI_ELSE_OP                    ARGI_INVALID_OPCODE
+#define ARGI_EVENT_OP                   ARGI_INVALID_OPCODE
+#define ARGI_EXTERNAL_OP                ARGI_LIST3 (ARGI_STRING,     ARGI_INTEGER,       ARGI_INTEGER)
+#define ARGI_FATAL_OP                   ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_INTEGER)
+#define ARGI_FIELD_OP                   ARGI_INVALID_OPCODE
+#define ARGI_FIND_SET_LEFT_BIT_OP       ARGI_LIST2 (ARGI_INTEGER,    ARGI_TARGETREF)
+#define ARGI_FIND_SET_RIGHT_BIT_OP      ARGI_LIST2 (ARGI_INTEGER,    ARGI_TARGETREF)
+#define ARGI_FROM_BCD_OP                ARGI_LIST2 (ARGI_INTEGER,    ARGI_FIXED_TARGET)
+#define ARGI_IF_OP                      ARGI_INVALID_OPCODE
+#define ARGI_INCREMENT_OP               ARGI_LIST1 (ARGI_TARGETREF)
+#define ARGI_INDEX_FIELD_OP             ARGI_INVALID_OPCODE
+#define ARGI_INDEX_OP                   ARGI_LIST3 (ARGI_COMPLEXOBJ, ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_LAND_OP                    ARGI_LIST2 (ARGI_INTEGER,    ARGI_INTEGER)
+#define ARGI_LEQUAL_OP                  ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
+#define ARGI_LGREATER_OP                ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
+#define ARGI_LGREATEREQUAL_OP           ARGI_INVALID_OPCODE
+#define ARGI_LLESS_OP                   ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_COMPUTEDATA)
+#define ARGI_LLESSEQUAL_OP              ARGI_INVALID_OPCODE
+#define ARGI_LNOT_OP                    ARGI_LIST1 (ARGI_INTEGER)
+#define ARGI_LNOTEQUAL_OP               ARGI_INVALID_OPCODE
+#define ARGI_LOAD_OP                    ARGI_LIST2 (ARGI_REGION_OR_BUFFER,ARGI_TARGETREF)
+#define ARGI_LOAD_TABLE_OP              ARGI_LIST6 (ARGI_STRING,     ARGI_STRING,        ARGI_STRING,       ARGI_STRING,    ARGI_STRING, ARGI_ANYTYPE)
+#define ARGI_LOCAL0                     ARG_NONE
+#define ARGI_LOCAL1                     ARG_NONE
+#define ARGI_LOCAL2                     ARG_NONE
+#define ARGI_LOCAL3                     ARG_NONE
+#define ARGI_LOCAL4                     ARG_NONE
+#define ARGI_LOCAL5                     ARG_NONE
+#define ARGI_LOCAL6                     ARG_NONE
+#define ARGI_LOCAL7                     ARG_NONE
+#define ARGI_LOR_OP                     ARGI_LIST2 (ARGI_INTEGER,    ARGI_INTEGER)
+#define ARGI_MATCH_OP                   ARGI_LIST6 (ARGI_PACKAGE,    ARGI_INTEGER,   ARGI_COMPUTEDATA,      ARGI_INTEGER,ARGI_COMPUTEDATA,ARGI_INTEGER)
+#define ARGI_METHOD_OP                  ARGI_INVALID_OPCODE
+#define ARGI_METHODCALL_OP              ARGI_INVALID_OPCODE
+#define ARGI_MID_OP                     ARGI_LIST4 (ARGI_BUFFER_OR_STRING,ARGI_INTEGER,  ARGI_INTEGER,      ARGI_TARGETREF)
+#define ARGI_MOD_OP                     ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_MULTIPLY_OP                ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_MUTEX_OP                   ARGI_INVALID_OPCODE
+#define ARGI_NAME_OP                    ARGI_INVALID_OPCODE
+#define ARGI_NAMEDFIELD_OP              ARGI_INVALID_OPCODE
+#define ARGI_NAMEPATH_OP                ARGI_INVALID_OPCODE
+#define ARGI_NOOP_OP                    ARG_NONE
+#define ARGI_NOTIFY_OP                  ARGI_LIST2 (ARGI_DEVICE_REF, ARGI_INTEGER)
+#define ARGI_OBJECT_TYPE_OP             ARGI_LIST1 (ARGI_ANYTYPE)
+#define ARGI_ONE_OP                     ARG_NONE
+#define ARGI_ONES_OP                    ARG_NONE
+#define ARGI_PACKAGE_OP                 ARGI_LIST1 (ARGI_INTEGER)
+#define ARGI_POWER_RES_OP               ARGI_INVALID_OPCODE
+#define ARGI_PROCESSOR_OP               ARGI_INVALID_OPCODE
+#define ARGI_QWORD_OP                   ARGI_INVALID_OPCODE
+#define ARGI_REF_OF_OP                  ARGI_LIST1 (ARGI_OBJECT_REF)
+#define ARGI_REGION_OP                  ARGI_LIST2 (ARGI_INTEGER,    ARGI_INTEGER)
+#define ARGI_RELEASE_OP                 ARGI_LIST1 (ARGI_MUTEX)
+#define ARGI_RESERVEDFIELD_OP           ARGI_INVALID_OPCODE
+#define ARGI_RESET_OP                   ARGI_LIST1 (ARGI_EVENT)
+#define ARGI_RETURN_OP                  ARGI_INVALID_OPCODE
+#define ARGI_REVISION_OP                ARG_NONE
+#define ARGI_SCOPE_OP                   ARGI_INVALID_OPCODE
+#define ARGI_SERIALFIELD_OP             ARGI_INVALID_OPCODE
+#define ARGI_SHIFT_LEFT_OP              ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_SHIFT_RIGHT_OP             ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_SIGNAL_OP                  ARGI_LIST1 (ARGI_EVENT)
+#define ARGI_SIZE_OF_OP                 ARGI_LIST1 (ARGI_DATAOBJECT)
+#define ARGI_SLEEP_OP                   ARGI_LIST1 (ARGI_INTEGER)
+#define ARGI_STALL_OP                   ARGI_LIST1 (ARGI_INTEGER)
+#define ARGI_STATICSTRING_OP            ARGI_INVALID_OPCODE
+#define ARGI_STORE_OP                   ARGI_LIST2 (ARGI_DATAREFOBJ, ARGI_STORE_TARGET)
+#define ARGI_STRING_OP                  ARGI_INVALID_OPCODE
+#define ARGI_SUBTRACT_OP                ARGI_LIST3 (ARGI_INTEGER,    ARGI_INTEGER,       ARGI_TARGETREF)
+#define ARGI_THERMAL_ZONE_OP            ARGI_INVALID_OPCODE
+#define ARGI_TIMER_OP                   ARG_NONE
+#define ARGI_TO_BCD_OP                  ARGI_LIST2 (ARGI_INTEGER,    ARGI_FIXED_TARGET)
+#define ARGI_TO_BUFFER_OP               ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
+#define ARGI_TO_DEC_STR_OP              ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
+#define ARGI_TO_HEX_STR_OP              ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
+#define ARGI_TO_INTEGER_OP              ARGI_LIST2 (ARGI_COMPUTEDATA,ARGI_FIXED_TARGET)
+#define ARGI_TO_STRING_OP               ARGI_LIST3 (ARGI_BUFFER,     ARGI_INTEGER,       ARGI_FIXED_TARGET)
+#define ARGI_UNLOAD_OP                  ARGI_LIST1 (ARGI_DDBHANDLE)
+#define ARGI_VAR_PACKAGE_OP             ARGI_LIST1 (ARGI_INTEGER)
+#define ARGI_WAIT_OP                    ARGI_LIST2 (ARGI_EVENT,      ARGI_INTEGER)
+#define ARGI_WHILE_OP                   ARGI_INVALID_OPCODE
+#define ARGI_WORD_OP                    ARGI_INVALID_OPCODE
+#define ARGI_ZERO_OP                    ARG_NONE
+
+#endif /* __ACOPCODE_H__ */

+ 496 - 0
kernel/include/acpica/acoutput.h

@@ -0,0 +1,496 @@
+/******************************************************************************
+ *
+ * Name: acoutput.h -- debug output
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACOUTPUT_H__
+#define __ACOUTPUT_H__
+
+/*
+ * Debug levels and component IDs. These are used to control the
+ * granularity of the output of the ACPI_DEBUG_PRINT macro -- on a
+ * per-component basis and a per-exception-type basis.
+ */
+
+/* Component IDs are used in the global "DebugLayer" */
+
+#define ACPI_UTILITIES              0x00000001
+#define ACPI_HARDWARE               0x00000002
+#define ACPI_EVENTS                 0x00000004
+#define ACPI_TABLES                 0x00000008
+#define ACPI_NAMESPACE              0x00000010
+#define ACPI_PARSER                 0x00000020
+#define ACPI_DISPATCHER             0x00000040
+#define ACPI_EXECUTER               0x00000080
+#define ACPI_RESOURCES              0x00000100
+#define ACPI_CA_DEBUGGER            0x00000200
+#define ACPI_OS_SERVICES            0x00000400
+#define ACPI_CA_DISASSEMBLER        0x00000800
+
+/* Component IDs for ACPI tools and utilities */
+
+#define ACPI_COMPILER               0x00001000
+#define ACPI_TOOLS                  0x00002000
+#define ACPI_EXAMPLE                0x00004000
+#define ACPI_DRIVER                 0x00008000
+#define DT_COMPILER                 0x00010000
+#define ASL_PREPROCESSOR            0x00020000
+
+#define ACPI_ALL_COMPONENTS         0x0001FFFF
+#define ACPI_COMPONENT_DEFAULT      (ACPI_ALL_COMPONENTS)
+
+/* Component IDs reserved for ACPI drivers */
+
+#define ACPI_ALL_DRIVERS            0xFFFF0000
+
+
+/*
+ * Raw debug output levels, do not use these in the ACPI_DEBUG_PRINT macros
+ */
+#define ACPI_LV_INIT                0x00000001
+#define ACPI_LV_DEBUG_OBJECT        0x00000002
+#define ACPI_LV_INFO                0x00000004
+#define ACPI_LV_REPAIR              0x00000008
+#define ACPI_LV_TRACE_POINT         0x00000010
+#define ACPI_LV_ALL_EXCEPTIONS      0x0000001F
+
+/* Trace verbosity level 1 [Standard Trace Level] */
+
+#define ACPI_LV_INIT_NAMES          0x00000020
+#define ACPI_LV_PARSE               0x00000040
+#define ACPI_LV_LOAD                0x00000080
+#define ACPI_LV_DISPATCH            0x00000100
+#define ACPI_LV_EXEC                0x00000200
+#define ACPI_LV_NAMES               0x00000400
+#define ACPI_LV_OPREGION            0x00000800
+#define ACPI_LV_BFIELD              0x00001000
+#define ACPI_LV_TABLES              0x00002000
+#define ACPI_LV_VALUES              0x00004000
+#define ACPI_LV_OBJECTS             0x00008000
+#define ACPI_LV_RESOURCES           0x00010000
+#define ACPI_LV_USER_REQUESTS       0x00020000
+#define ACPI_LV_PACKAGE             0x00040000
+#define ACPI_LV_VERBOSITY1          0x0007FF40 | ACPI_LV_ALL_EXCEPTIONS
+
+/* Trace verbosity level 2 [Function tracing and memory allocation] */
+
+#define ACPI_LV_ALLOCATIONS         0x00100000
+#define ACPI_LV_FUNCTIONS           0x00200000
+#define ACPI_LV_OPTIMIZATIONS       0x00400000
+#define ACPI_LV_VERBOSITY2          0x00700000 | ACPI_LV_VERBOSITY1
+#define ACPI_LV_ALL                 ACPI_LV_VERBOSITY2
+
+/* Trace verbosity level 3 [Threading, I/O, and Interrupts] */
+
+#define ACPI_LV_MUTEX               0x01000000
+#define ACPI_LV_THREADS             0x02000000
+#define ACPI_LV_IO                  0x04000000
+#define ACPI_LV_INTERRUPTS          0x08000000
+#define ACPI_LV_VERBOSITY3          0x0F000000 | ACPI_LV_VERBOSITY2
+
+/* Exceptionally verbose output -- also used in the global "DebugLevel"  */
+
+#define ACPI_LV_AML_DISASSEMBLE     0x10000000
+#define ACPI_LV_VERBOSE_INFO        0x20000000
+#define ACPI_LV_FULL_TABLES         0x40000000
+#define ACPI_LV_EVENTS              0x80000000
+#define ACPI_LV_VERBOSE             0xF0000000
+
+
+/*
+ * Debug level macros that are used in the DEBUG_PRINT macros
+ */
+#define ACPI_DEBUG_LEVEL(dl)        (UINT32) dl,ACPI_DEBUG_PARAMETERS
+
+/*
+ * Exception level -- used in the global "DebugLevel"
+ *
+ * Note: For errors, use the ACPI_ERROR or ACPI_EXCEPTION interfaces.
+ * For warnings, use ACPI_WARNING.
+ */
+#define ACPI_DB_INIT                ACPI_DEBUG_LEVEL (ACPI_LV_INIT)
+#define ACPI_DB_DEBUG_OBJECT        ACPI_DEBUG_LEVEL (ACPI_LV_DEBUG_OBJECT)
+#define ACPI_DB_INFO                ACPI_DEBUG_LEVEL (ACPI_LV_INFO)
+#define ACPI_DB_REPAIR              ACPI_DEBUG_LEVEL (ACPI_LV_REPAIR)
+#define ACPI_DB_TRACE_POINT         ACPI_DEBUG_LEVEL (ACPI_LV_TRACE_POINT)
+#define ACPI_DB_ALL_EXCEPTIONS      ACPI_DEBUG_LEVEL (ACPI_LV_ALL_EXCEPTIONS)
+
+/* Trace level -- also used in the global "DebugLevel" */
+
+#define ACPI_DB_INIT_NAMES          ACPI_DEBUG_LEVEL (ACPI_LV_INIT_NAMES)
+#define ACPI_DB_THREADS             ACPI_DEBUG_LEVEL (ACPI_LV_THREADS)
+#define ACPI_DB_PARSE               ACPI_DEBUG_LEVEL (ACPI_LV_PARSE)
+#define ACPI_DB_DISPATCH            ACPI_DEBUG_LEVEL (ACPI_LV_DISPATCH)
+#define ACPI_DB_LOAD                ACPI_DEBUG_LEVEL (ACPI_LV_LOAD)
+#define ACPI_DB_EXEC                ACPI_DEBUG_LEVEL (ACPI_LV_EXEC)
+#define ACPI_DB_NAMES               ACPI_DEBUG_LEVEL (ACPI_LV_NAMES)
+#define ACPI_DB_OPREGION            ACPI_DEBUG_LEVEL (ACPI_LV_OPREGION)
+#define ACPI_DB_BFIELD              ACPI_DEBUG_LEVEL (ACPI_LV_BFIELD)
+#define ACPI_DB_TABLES              ACPI_DEBUG_LEVEL (ACPI_LV_TABLES)
+#define ACPI_DB_FUNCTIONS           ACPI_DEBUG_LEVEL (ACPI_LV_FUNCTIONS)
+#define ACPI_DB_OPTIMIZATIONS       ACPI_DEBUG_LEVEL (ACPI_LV_OPTIMIZATIONS)
+#define ACPI_DB_VALUES              ACPI_DEBUG_LEVEL (ACPI_LV_VALUES)
+#define ACPI_DB_OBJECTS             ACPI_DEBUG_LEVEL (ACPI_LV_OBJECTS)
+#define ACPI_DB_ALLOCATIONS         ACPI_DEBUG_LEVEL (ACPI_LV_ALLOCATIONS)
+#define ACPI_DB_RESOURCES           ACPI_DEBUG_LEVEL (ACPI_LV_RESOURCES)
+#define ACPI_DB_IO                  ACPI_DEBUG_LEVEL (ACPI_LV_IO)
+#define ACPI_DB_INTERRUPTS          ACPI_DEBUG_LEVEL (ACPI_LV_INTERRUPTS)
+#define ACPI_DB_USER_REQUESTS       ACPI_DEBUG_LEVEL (ACPI_LV_USER_REQUESTS)
+#define ACPI_DB_PACKAGE             ACPI_DEBUG_LEVEL (ACPI_LV_PACKAGE)
+#define ACPI_DB_MUTEX               ACPI_DEBUG_LEVEL (ACPI_LV_MUTEX)
+#define ACPI_DB_EVENTS              ACPI_DEBUG_LEVEL (ACPI_LV_EVENTS)
+
+#define ACPI_DB_ALL                 ACPI_DEBUG_LEVEL (ACPI_LV_ALL)
+
+/* Defaults for DebugLevel, debug and normal */
+
+#define ACPI_DEBUG_DEFAULT          (ACPI_LV_INIT | ACPI_LV_DEBUG_OBJECT | ACPI_LV_REPAIR)
+#define ACPI_NORMAL_DEFAULT         (ACPI_LV_INIT | ACPI_LV_DEBUG_OBJECT | ACPI_LV_REPAIR)
+#define ACPI_DEBUG_ALL              (ACPI_LV_AML_DISASSEMBLE | ACPI_LV_ALL_EXCEPTIONS | ACPI_LV_ALL)
+
+
+/*
+ * Global trace flags
+ */
+#define ACPI_TRACE_ENABLED          ((UINT32) 4)
+#define ACPI_TRACE_ONESHOT          ((UINT32) 2)
+#define ACPI_TRACE_OPCODE           ((UINT32) 1)
+
+/* Defaults for trace debugging level/layer */
+
+#define ACPI_TRACE_LEVEL_ALL        ACPI_LV_ALL
+#define ACPI_TRACE_LAYER_ALL        0x000001FF
+#define ACPI_TRACE_LEVEL_DEFAULT    ACPI_LV_TRACE_POINT
+#define ACPI_TRACE_LAYER_DEFAULT    ACPI_EXECUTER
+
+
+#if defined (ACPI_DEBUG_OUTPUT) || !defined (ACPI_NO_ERROR_MESSAGES)
+/*
+ * The module name is used primarily for error and debug messages.
+ * The __FILE__ macro is not very useful for this, because it
+ * usually includes the entire pathname to the module making the
+ * debug output difficult to read.
+ */
+#define ACPI_MODULE_NAME(Name)          static const char ACPI_UNUSED_VAR _AcpiModuleName[] = Name;
+#else
+/*
+ * For the no-debug and no-error-msg cases, we must at least define
+ * a null module name.
+ */
+#define ACPI_MODULE_NAME(Name)
+#define _AcpiModuleName ""
+#endif
+
+/*
+ * Ascii error messages can be configured out
+ */
+#ifndef ACPI_NO_ERROR_MESSAGES
+#define AE_INFO                         _AcpiModuleName, __LINE__
+
+/*
+ * Error reporting. Callers module and line number are inserted by AE_INFO,
+ * the plist contains a set of parens to allow variable-length lists.
+ * These macros are used for both the debug and non-debug versions of the code.
+ */
+#define ACPI_INFO(plist)                AcpiInfo plist
+#define ACPI_WARNING(plist)             AcpiWarning plist
+#define ACPI_EXCEPTION(plist)           AcpiException plist
+#define ACPI_ERROR(plist)               AcpiError plist
+#define ACPI_BIOS_WARNING(plist)        AcpiBiosWarning plist
+#define ACPI_BIOS_ERROR(plist)          AcpiBiosError plist
+#define ACPI_DEBUG_OBJECT(obj,l,i)      AcpiExDoDebugObject(obj,l,i)
+
+#else
+
+/* No error messages */
+
+#define ACPI_INFO(plist)
+#define ACPI_WARNING(plist)
+#define ACPI_EXCEPTION(plist)
+#define ACPI_ERROR(plist)
+#define ACPI_BIOS_WARNING(plist)
+#define ACPI_BIOS_ERROR(plist)
+#define ACPI_DEBUG_OBJECT(obj,l,i)
+
+#endif /* ACPI_NO_ERROR_MESSAGES */
+
+
+/*
+ * Debug macros that are conditionally compiled
+ */
+#ifdef ACPI_DEBUG_OUTPUT
+
+/*
+ * If ACPI_GET_FUNCTION_NAME was not defined in the compiler-dependent header,
+ * define it now. This is the case where there the compiler does not support
+ * a __FUNCTION__ macro or equivalent.
+ */
+#ifndef ACPI_GET_FUNCTION_NAME
+#define ACPI_GET_FUNCTION_NAME          _AcpiFunctionName
+
+/*
+ * The Name parameter should be the procedure name as a quoted string.
+ * The function name is also used by the function exit macros below.
+ * Note: (const char) is used to be compatible with the debug interfaces
+ * and macros such as __FUNCTION__.
+ */
+#define ACPI_FUNCTION_NAME(Name)        static const char _AcpiFunctionName[] = #Name;
+
+#else
+/* Compiler supports __FUNCTION__ (or equivalent) -- Ignore this macro */
+
+#define ACPI_FUNCTION_NAME(Name)
+#endif /* ACPI_GET_FUNCTION_NAME */
+
+/*
+ * Common parameters used for debug output functions:
+ * line number, function name, module(file) name, component ID
+ */
+#define ACPI_DEBUG_PARAMETERS \
+    __LINE__, ACPI_GET_FUNCTION_NAME, _AcpiModuleName, _COMPONENT
+
+/* Check if debug output is currently dynamically enabled */
+
+#define ACPI_IS_DEBUG_ENABLED(Level, Component) \
+    ((Level & AcpiDbgLevel) && (Component & AcpiDbgLayer))
+
+/*
+ * Master debug print macros
+ * Print message if and only if:
+ *    1) Debug print for the current component is enabled
+ *    2) Debug error level or trace level for the print statement is enabled
+ *
+ * November 2012: Moved the runtime check for whether to actually emit the
+ * debug message outside of the print function itself. This improves overall
+ * performance at a relatively small code cost. Implementation involves the
+ * use of variadic macros supported by C99.
+ *
+ * Note: the ACPI_DO_WHILE0 macro is used to prevent some compilers from
+ * complaining about these constructs. On other compilers the do...while
+ * adds some extra code, so this feature is optional.
+ */
+#ifdef ACPI_USE_DO_WHILE_0
+#define ACPI_DO_WHILE0(a)               do a while(0)
+#else
+#define ACPI_DO_WHILE0(a)               a
+#endif
+
+/* DEBUG_PRINT functions */
+
+#ifndef COMPILER_VA_MACRO
+
+#define ACPI_DEBUG_PRINT(plist)         AcpiDebugPrint plist
+#define ACPI_DEBUG_PRINT_RAW(plist)     AcpiDebugPrintRaw plist
+
+#else
+
+/* Helper macros for DEBUG_PRINT */
+
+#define ACPI_DO_DEBUG_PRINT(Function, Level, Line, Filename, Modulename, Component, ...) \
+    ACPI_DO_WHILE0 ({ \
+        if (ACPI_IS_DEBUG_ENABLED (Level, Component)) \
+        { \
+            Function (Level, Line, Filename, Modulename, Component, __VA_ARGS__); \
+        } \
+    })
+
+#define ACPI_ACTUAL_DEBUG(Level, Line, Filename, Modulename, Component, ...) \
+    ACPI_DO_DEBUG_PRINT (AcpiDebugPrint, Level, Line, \
+        Filename, Modulename, Component, __VA_ARGS__)
+
+#define ACPI_ACTUAL_DEBUG_RAW(Level, Line, Filename, Modulename, Component, ...) \
+    ACPI_DO_DEBUG_PRINT (AcpiDebugPrintRaw, Level, Line, \
+        Filename, Modulename, Component, __VA_ARGS__)
+
+#define ACPI_DEBUG_PRINT(plist)         ACPI_ACTUAL_DEBUG plist
+#define ACPI_DEBUG_PRINT_RAW(plist)     ACPI_ACTUAL_DEBUG_RAW plist
+
+#endif
+
+
+/*
+ * Function entry tracing
+ *
+ * The name of the function is emitted as a local variable that is
+ * intended to be used by both the entry trace and the exit trace.
+ */
+
+/* Helper macro */
+
+#define ACPI_TRACE_ENTRY(Name, Function, Type, Param) \
+    ACPI_FUNCTION_NAME (Name) \
+    Function (ACPI_DEBUG_PARAMETERS, (Type) (Param))
+
+/* The actual entry trace macros */
+
+#define ACPI_FUNCTION_TRACE(Name) \
+    ACPI_FUNCTION_NAME(Name) \
+    AcpiUtTrace (ACPI_DEBUG_PARAMETERS)
+
+#define ACPI_FUNCTION_TRACE_PTR(Name, Pointer) \
+    ACPI_TRACE_ENTRY (Name, AcpiUtTracePtr, void *, Pointer)
+
+#define ACPI_FUNCTION_TRACE_U32(Name, Value) \
+    ACPI_TRACE_ENTRY (Name, AcpiUtTraceU32, UINT32, Value)
+
+#define ACPI_FUNCTION_TRACE_STR(Name, String) \
+    ACPI_TRACE_ENTRY (Name, AcpiUtTraceStr, char *, String)
+
+#define ACPI_FUNCTION_ENTRY() \
+    AcpiUtTrackStackPtr()
+
+
+/*
+ * Function exit tracing
+ *
+ * These macros include a return statement. This is usually considered
+ * bad form, but having a separate exit macro before the actual return
+ * is very ugly and difficult to maintain.
+ *
+ * One of the FUNCTION_TRACE macros above must be used in conjunction
+ * with these macros so that "_AcpiFunctionName" is defined.
+ *
+ * There are two versions of most of the return macros. The default version is
+ * safer, since it avoids side-effects by guaranteeing that the argument will
+ * not be evaluated twice.
+ *
+ * A less-safe version of the macros is provided for optional use if the
+ * compiler uses excessive CPU stack (for example, this may happen in the
+ * debug case if code optimzation is disabled.)
+ */
+
+/* Exit trace helper macro */
+
+#ifndef ACPI_SIMPLE_RETURN_MACROS
+
+#define ACPI_TRACE_EXIT(Function, Type, Param) \
+    ACPI_DO_WHILE0 ({ \
+        register Type _Param = (Type) (Param); \
+        Function (ACPI_DEBUG_PARAMETERS, _Param); \
+        return (_Param); \
+    })
+
+#else /* Use original less-safe macros */
+
+#define ACPI_TRACE_EXIT(Function, Type, Param) \
+    ACPI_DO_WHILE0 ({ \
+        Function (ACPI_DEBUG_PARAMETERS, (Type) (Param)); \
+        return (Param); \
+    })
+
+#endif /* ACPI_SIMPLE_RETURN_MACROS */
+
+/* The actual exit macros */
+
+#define return_VOID \
+    ACPI_DO_WHILE0 ({ \
+        AcpiUtExit (ACPI_DEBUG_PARAMETERS); \
+        return; \
+    })
+
+#define return_ACPI_STATUS(Status) \
+    ACPI_TRACE_EXIT (AcpiUtStatusExit, ACPI_STATUS, Status)
+
+#define return_PTR(Pointer) \
+    ACPI_TRACE_EXIT (AcpiUtPtrExit, void *, Pointer)
+
+#define return_VALUE(Value) \
+    ACPI_TRACE_EXIT (AcpiUtValueExit, UINT64, Value)
+
+#define return_UINT32(Value) \
+    ACPI_TRACE_EXIT (AcpiUtValueExit, UINT32, Value)
+
+#define return_UINT8(Value) \
+    ACPI_TRACE_EXIT (AcpiUtValueExit, UINT8, Value)
+
+/* Conditional execution */
+
+#define ACPI_DEBUG_EXEC(a)              a
+#define ACPI_DEBUG_ONLY_MEMBERS(a)      a;
+#define _VERBOSE_STRUCTURES
+
+
+/* Various object display routines for debug */
+
+#define ACPI_DUMP_STACK_ENTRY(a)        AcpiExDumpOperand((a), 0)
+#define ACPI_DUMP_OPERANDS(a, b ,c)     AcpiExDumpOperands(a, b, c)
+#define ACPI_DUMP_ENTRY(a, b)           AcpiNsDumpEntry (a, b)
+#define ACPI_DUMP_PATHNAME(a, b, c, d)  AcpiNsDumpPathname(a, b, c, d)
+#define ACPI_DUMP_BUFFER(a, b)          AcpiUtDebugDumpBuffer((UINT8 *) a, b, DB_BYTE_DISPLAY, _COMPONENT)
+
+#define ACPI_TRACE_POINT(a, b, c, d)    AcpiTracePoint (a, b, c, d)
+
+#else /* ACPI_DEBUG_OUTPUT */
+/*
+ * This is the non-debug case -- make everything go away,
+ * leaving no executable debug code!
+ */
+#define ACPI_DEBUG_PRINT(pl)
+#define ACPI_DEBUG_PRINT_RAW(pl)
+#define ACPI_DEBUG_EXEC(a)
+#define ACPI_DEBUG_ONLY_MEMBERS(a)
+#define ACPI_FUNCTION_NAME(a)
+#define ACPI_FUNCTION_TRACE(a)
+#define ACPI_FUNCTION_TRACE_PTR(a, b)
+#define ACPI_FUNCTION_TRACE_U32(a, b)
+#define ACPI_FUNCTION_TRACE_STR(a, b)
+#define ACPI_FUNCTION_ENTRY()
+#define ACPI_DUMP_STACK_ENTRY(a)
+#define ACPI_DUMP_OPERANDS(a, b, c)
+#define ACPI_DUMP_ENTRY(a, b)
+#define ACPI_DUMP_PATHNAME(a, b, c, d)
+#define ACPI_DUMP_BUFFER(a, b)
+#define ACPI_IS_DEBUG_ENABLED(Level, Component) 0
+#define ACPI_TRACE_POINT(a, b, c, d)
+
+/* Return macros must have a return statement at the minimum */
+
+#define return_VOID                     return
+#define return_ACPI_STATUS(s)           return(s)
+#define return_PTR(s)                   return(s)
+#define return_VALUE(s)                 return(s)
+#define return_UINT8(s)                 return(s)
+#define return_UINT32(s)                return(s)
+
+#endif /* ACPI_DEBUG_OUTPUT */
+
+
+#endif /* __ACOUTPUT_H__ */

+ 364 - 0
kernel/include/acpica/acparser.h

@@ -0,0 +1,364 @@
+/******************************************************************************
+ *
+ * Module Name: acparser.h - AML Parser subcomponent prototypes and defines
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACPARSER_H__
+#define __ACPARSER_H__
+
+
+#define OP_HAS_RETURN_VALUE             1
+
+/* Variable number of arguments. This field must be 32 bits */
+
+#define ACPI_VAR_ARGS                   ACPI_UINT32_MAX
+
+
+#define ACPI_PARSE_DELETE_TREE          0x0001
+#define ACPI_PARSE_NO_TREE_DELETE       0x0000
+#define ACPI_PARSE_TREE_MASK            0x0001
+
+#define ACPI_PARSE_LOAD_PASS1           0x0010
+#define ACPI_PARSE_LOAD_PASS2           0x0020
+#define ACPI_PARSE_EXECUTE              0x0030
+#define ACPI_PARSE_MODE_MASK            0x0030
+
+#define ACPI_PARSE_DEFERRED_OP          0x0100
+#define ACPI_PARSE_DISASSEMBLE          0x0200
+
+#define ACPI_PARSE_MODULE_LEVEL         0x0400
+
+/******************************************************************************
+ *
+ * Parser interfaces
+ *
+ *****************************************************************************/
+
+extern const UINT8      AcpiGbl_ShortOpIndex[];
+extern const UINT8      AcpiGbl_LongOpIndex[];
+
+
+/*
+ * psxface - Parser external interfaces
+ */
+ACPI_STATUS
+AcpiPsExecuteMethod (
+    ACPI_EVALUATE_INFO      *Info);
+
+
+/*
+ * psargs - Parse AML opcode arguments
+ */
+UINT8 *
+AcpiPsGetNextPackageEnd (
+    ACPI_PARSE_STATE        *ParserState);
+
+char *
+AcpiPsGetNextNamestring (
+    ACPI_PARSE_STATE        *ParserState);
+
+void
+AcpiPsGetNextSimpleArg (
+    ACPI_PARSE_STATE        *ParserState,
+    UINT32                  ArgType,
+    ACPI_PARSE_OBJECT       *Arg);
+
+ACPI_STATUS
+AcpiPsGetNextNamepath (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_STATE        *ParserState,
+    ACPI_PARSE_OBJECT       *Arg,
+    BOOLEAN                 PossibleMethodCall);
+
+/* Values for BOOLEAN above */
+
+#define ACPI_NOT_METHOD_CALL            FALSE
+#define ACPI_POSSIBLE_METHOD_CALL       TRUE
+
+ACPI_STATUS
+AcpiPsGetNextArg (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_STATE        *ParserState,
+    UINT32                  ArgType,
+    ACPI_PARSE_OBJECT       **ReturnArg);
+
+
+/*
+ * psfind
+ */
+ACPI_PARSE_OBJECT *
+AcpiPsFindName (
+    ACPI_PARSE_OBJECT       *Scope,
+    UINT32                  Name,
+    UINT32                  Opcode);
+
+ACPI_PARSE_OBJECT*
+AcpiPsGetParent (
+    ACPI_PARSE_OBJECT       *Op);
+
+
+/*
+ * psobject - support for parse object processing
+ */
+ACPI_STATUS
+AcpiPsBuildNamedOp (
+    ACPI_WALK_STATE         *WalkState,
+    UINT8                   *AmlOpStart,
+    ACPI_PARSE_OBJECT       *UnnamedOp,
+    ACPI_PARSE_OBJECT       **Op);
+
+ACPI_STATUS
+AcpiPsCreateOp (
+    ACPI_WALK_STATE         *WalkState,
+    UINT8                   *AmlOpStart,
+    ACPI_PARSE_OBJECT       **NewOp);
+
+ACPI_STATUS
+AcpiPsCompleteOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       **Op,
+    ACPI_STATUS             Status);
+
+ACPI_STATUS
+AcpiPsCompleteFinalOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_STATUS             Status);
+
+
+/*
+ * psopinfo - AML Opcode information
+ */
+const ACPI_OPCODE_INFO *
+AcpiPsGetOpcodeInfo (
+    UINT16                  Opcode);
+
+char *
+AcpiPsGetOpcodeName (
+    UINT16                  Opcode);
+
+UINT8
+AcpiPsGetArgumentCount (
+    UINT32                  OpType);
+
+
+/*
+ * psparse - top level parsing routines
+ */
+ACPI_STATUS
+AcpiPsParseAml (
+    ACPI_WALK_STATE         *WalkState);
+
+UINT32
+AcpiPsGetOpcodeSize (
+    UINT32                  Opcode);
+
+UINT16
+AcpiPsPeekOpcode (
+    ACPI_PARSE_STATE        *state);
+
+ACPI_STATUS
+AcpiPsCompleteThisOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op);
+
+ACPI_STATUS
+AcpiPsNextParseState (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_STATUS             CallbackStatus);
+
+
+/*
+ * psloop - main parse loop
+ */
+ACPI_STATUS
+AcpiPsParseLoop (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * psscope - Scope stack management routines
+ */
+ACPI_STATUS
+AcpiPsInitScope (
+    ACPI_PARSE_STATE        *ParserState,
+    ACPI_PARSE_OBJECT       *Root);
+
+ACPI_PARSE_OBJECT *
+AcpiPsGetParentScope (
+    ACPI_PARSE_STATE        *state);
+
+BOOLEAN
+AcpiPsHasCompletedScope (
+    ACPI_PARSE_STATE        *ParserState);
+
+void
+AcpiPsPopScope (
+    ACPI_PARSE_STATE        *ParserState,
+    ACPI_PARSE_OBJECT       **Op,
+    UINT32                  *ArgList,
+    UINT32                  *ArgCount);
+
+ACPI_STATUS
+AcpiPsPushScope (
+    ACPI_PARSE_STATE        *ParserState,
+    ACPI_PARSE_OBJECT       *Op,
+    UINT32                  RemainingArgs,
+    UINT32                  ArgCount);
+
+void
+AcpiPsCleanupScope (
+    ACPI_PARSE_STATE        *state);
+
+
+/*
+ * pstree - parse tree manipulation routines
+ */
+void
+AcpiPsAppendArg(
+    ACPI_PARSE_OBJECT       *op,
+    ACPI_PARSE_OBJECT       *arg);
+
+ACPI_PARSE_OBJECT*
+AcpiPsFind (
+    ACPI_PARSE_OBJECT       *Scope,
+    char                    *Path,
+    UINT16                  Opcode,
+    UINT32                  Create);
+
+ACPI_PARSE_OBJECT *
+AcpiPsGetArg(
+    ACPI_PARSE_OBJECT       *op,
+    UINT32                   argn);
+
+ACPI_PARSE_OBJECT *
+AcpiPsGetDepthNext (
+    ACPI_PARSE_OBJECT       *Origin,
+    ACPI_PARSE_OBJECT       *Op);
+
+
+/*
+ * pswalk - parse tree walk routines
+ */
+ACPI_STATUS
+AcpiPsWalkParsedAml (
+    ACPI_PARSE_OBJECT       *StartOp,
+    ACPI_PARSE_OBJECT       *EndOp,
+    ACPI_OPERAND_OBJECT     *MthDesc,
+    ACPI_NAMESPACE_NODE     *StartNode,
+    ACPI_OPERAND_OBJECT     **Params,
+    ACPI_OPERAND_OBJECT     **CallerReturnDesc,
+    ACPI_OWNER_ID           OwnerId,
+    ACPI_PARSE_DOWNWARDS    DescendingCallback,
+    ACPI_PARSE_UPWARDS      AscendingCallback);
+
+ACPI_STATUS
+AcpiPsGetNextWalkOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_PARSE_UPWARDS      AscendingCallback);
+
+ACPI_STATUS
+AcpiPsDeleteCompletedOp (
+    ACPI_WALK_STATE         *WalkState);
+
+void
+AcpiPsDeleteParseTree (
+    ACPI_PARSE_OBJECT       *root);
+
+
+/*
+ * psutils - parser utilities
+ */
+ACPI_PARSE_OBJECT *
+AcpiPsCreateScopeOp (
+    UINT8                   *Aml);
+
+void
+AcpiPsInitOp (
+    ACPI_PARSE_OBJECT       *op,
+    UINT16                  opcode);
+
+ACPI_PARSE_OBJECT *
+AcpiPsAllocOp (
+    UINT16                  Opcode,
+    UINT8                   *Aml);
+
+void
+AcpiPsFreeOp (
+    ACPI_PARSE_OBJECT       *Op);
+
+BOOLEAN
+AcpiPsIsLeadingChar (
+    UINT32                  c);
+
+UINT32
+AcpiPsGetName(
+    ACPI_PARSE_OBJECT       *op);
+
+void
+AcpiPsSetName(
+    ACPI_PARSE_OBJECT       *op,
+    UINT32                  name);
+
+
+/*
+ * psdump - display parser tree
+ */
+UINT32
+AcpiPsSprintPath (
+    char                    *BufferStart,
+    UINT32                  BufferSize,
+    ACPI_PARSE_OBJECT       *Op);
+
+UINT32
+AcpiPsSprintOp (
+    char                    *BufferStart,
+    UINT32                  BufferSize,
+    ACPI_PARSE_OBJECT       *Op);
+
+void
+AcpiPsShow (
+    ACPI_PARSE_OBJECT       *op);
+
+
+#endif /* __ACPARSER_H__ */

+ 67 - 0
kernel/include/acpica/acpi.h

@@ -0,0 +1,67 @@
+/******************************************************************************
+ *
+ * Name: acpi.h - Master public include file used to interface to ACPICA
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACPI_H__
+#define __ACPI_H__
+
+/*
+ * Public include files for use by code that will interface to ACPICA.
+ *
+ * Information includes the ACPICA data types, names, exceptions, and
+ * external interface prototypes. Also included are the definitions for
+ * all ACPI tables (FADT, MADT, etc.)
+ *
+ * Note: The order of these include files is important.
+ */
+#include "platform/acenv.h"     /* Environment-specific items */
+#include "acnames.h"            /* Common ACPI names and strings */
+#include "actypes.h"            /* ACPICA data types and structures */
+#include "acexcep.h"            /* ACPICA exceptions */
+#include "actbl.h"              /* ACPI table definitions */
+#include "acoutput.h"           /* Error output and Debug macros */
+#include "acrestyp.h"           /* Resource Descriptor structs */
+#include "acpiosxf.h"           /* OSL interfaces (ACPICA-to-OS) */
+#include "acpixf.h"             /* ACPI core subsystem external interfaces */
+#include "platform/acenvex.h"   /* Extra environment-specific items */
+
+#endif /* __ACPI_H__ */

+ 613 - 0
kernel/include/acpica/acpiosxf.h

@@ -0,0 +1,613 @@
+/******************************************************************************
+ *
+ * Name: acpiosxf.h - All interfaces to the OS Services Layer (OSL). These
+ *                    interfaces must be implemented by OSL to interface the
+ *                    ACPI components to the host operating system.
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACPIOSXF_H__
+#define __ACPIOSXF_H__
+
+#include "platform/acenv.h"
+#include "actypes.h"
+
+
+/* Types for AcpiOsExecute */
+
+typedef enum
+{
+    OSL_GLOBAL_LOCK_HANDLER,
+    OSL_NOTIFY_HANDLER,
+    OSL_GPE_HANDLER,
+    OSL_DEBUGGER_MAIN_THREAD,
+    OSL_DEBUGGER_EXEC_THREAD,
+    OSL_EC_POLL_HANDLER,
+    OSL_EC_BURST_HANDLER
+
+} ACPI_EXECUTE_TYPE;
+
+#define ACPI_NO_UNIT_LIMIT          ((UINT32) -1)
+#define ACPI_MUTEX_SEM              1
+
+
+/* Functions for AcpiOsSignal */
+
+#define ACPI_SIGNAL_FATAL           0
+#define ACPI_SIGNAL_BREAKPOINT      1
+
+typedef struct acpi_signal_fatal_info
+{
+    UINT32                  Type;
+    UINT32                  Code;
+    UINT32                  Argument;
+
+} ACPI_SIGNAL_FATAL_INFO;
+
+
+/*
+ * OSL Initialization and shutdown primitives
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsInitialize
+ACPI_STATUS
+AcpiOsInitialize (
+    void);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTerminate
+ACPI_STATUS
+AcpiOsTerminate (
+    void);
+#endif
+
+
+/*
+ * ACPI Table interfaces
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetRootPointer
+ACPI_PHYSICAL_ADDRESS
+AcpiOsGetRootPointer (
+    void);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsPredefinedOverride
+ACPI_STATUS
+AcpiOsPredefinedOverride (
+    const ACPI_PREDEFINED_NAMES *InitVal,
+    ACPI_STRING                 *NewVal);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTableOverride
+ACPI_STATUS
+AcpiOsTableOverride (
+    ACPI_TABLE_HEADER       *ExistingTable,
+    ACPI_TABLE_HEADER       **NewTable);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsPhysicalTableOverride
+ACPI_STATUS
+AcpiOsPhysicalTableOverride (
+    ACPI_TABLE_HEADER       *ExistingTable,
+    ACPI_PHYSICAL_ADDRESS   *NewAddress,
+    UINT32                  *NewTableLength);
+#endif
+
+
+/*
+ * Spinlock primitives
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCreateLock
+ACPI_STATUS
+AcpiOsCreateLock (
+    ACPI_SPINLOCK           *OutHandle);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsDeleteLock
+void
+AcpiOsDeleteLock (
+    ACPI_SPINLOCK           Handle);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAcquireLock
+ACPI_CPU_FLAGS
+AcpiOsAcquireLock (
+    ACPI_SPINLOCK           Handle);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReleaseLock
+void
+AcpiOsReleaseLock (
+    ACPI_SPINLOCK           Handle,
+    ACPI_CPU_FLAGS          Flags);
+#endif
+
+
+/*
+ * Semaphore primitives
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCreateSemaphore
+ACPI_STATUS
+AcpiOsCreateSemaphore (
+    UINT32                  MaxUnits,
+    UINT32                  InitialUnits,
+    ACPI_SEMAPHORE          *OutHandle);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsDeleteSemaphore
+ACPI_STATUS
+AcpiOsDeleteSemaphore (
+    ACPI_SEMAPHORE          Handle);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWaitSemaphore
+ACPI_STATUS
+AcpiOsWaitSemaphore (
+    ACPI_SEMAPHORE          Handle,
+    UINT32                  Units,
+    UINT16                  Timeout);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsSignalSemaphore
+ACPI_STATUS
+AcpiOsSignalSemaphore (
+    ACPI_SEMAPHORE          Handle,
+    UINT32                  Units);
+#endif
+
+
+/*
+ * Mutex primitives. May be configured to use semaphores instead via
+ * ACPI_MUTEX_TYPE (see platform/acenv.h)
+ */
+#if (ACPI_MUTEX_TYPE != ACPI_BINARY_SEMAPHORE)
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCreateMutex
+ACPI_STATUS
+AcpiOsCreateMutex (
+    ACPI_MUTEX              *OutHandle);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsDeleteMutex
+void
+AcpiOsDeleteMutex (
+    ACPI_MUTEX              Handle);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAcquireMutex
+ACPI_STATUS
+AcpiOsAcquireMutex (
+    ACPI_MUTEX              Handle,
+    UINT16                  Timeout);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReleaseMutex
+void
+AcpiOsReleaseMutex (
+    ACPI_MUTEX              Handle);
+#endif
+
+#endif
+
+
+/*
+ * Memory allocation and mapping
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocate
+void *
+AcpiOsAllocate (
+    ACPI_SIZE               Size);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAllocateZeroed
+void *
+AcpiOsAllocateZeroed (
+    ACPI_SIZE               Size);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsFree
+void
+AcpiOsFree (
+    void *                  Memory);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsMapMemory
+void *
+AcpiOsMapMemory (
+    ACPI_PHYSICAL_ADDRESS   Where,
+    ACPI_SIZE               Length);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsUnmapMemory
+void
+AcpiOsUnmapMemory (
+    void                    *LogicalAddress,
+    ACPI_SIZE               Size);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetPhysicalAddress
+ACPI_STATUS
+AcpiOsGetPhysicalAddress (
+    void                    *LogicalAddress,
+    ACPI_PHYSICAL_ADDRESS   *PhysicalAddress);
+#endif
+
+
+/*
+ * Memory/Object Cache
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCreateCache
+ACPI_STATUS
+AcpiOsCreateCache (
+    char                    *CacheName,
+    UINT16                  ObjectSize,
+    UINT16                  MaxDepth,
+    ACPI_CACHE_T            **ReturnCache);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsDeleteCache
+ACPI_STATUS
+AcpiOsDeleteCache (
+    ACPI_CACHE_T            *Cache);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsPurgeCache
+ACPI_STATUS
+AcpiOsPurgeCache (
+    ACPI_CACHE_T            *Cache);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsAcquireObject
+void *
+AcpiOsAcquireObject (
+    ACPI_CACHE_T            *Cache);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReleaseObject
+ACPI_STATUS
+AcpiOsReleaseObject (
+    ACPI_CACHE_T            *Cache,
+    void                    *Object);
+#endif
+
+
+/*
+ * Interrupt handlers
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsInstallInterruptHandler
+ACPI_STATUS
+AcpiOsInstallInterruptHandler (
+    UINT32                  InterruptNumber,
+    ACPI_OSD_HANDLER        ServiceRoutine,
+    void                    *Context);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsRemoveInterruptHandler
+ACPI_STATUS
+AcpiOsRemoveInterruptHandler (
+    UINT32                  InterruptNumber,
+    ACPI_OSD_HANDLER        ServiceRoutine);
+#endif
+
+
+/*
+ * Threads and Scheduling
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetThreadId
+ACPI_THREAD_ID
+AcpiOsGetThreadId (
+    void);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsExecute
+ACPI_STATUS
+AcpiOsExecute (
+    ACPI_EXECUTE_TYPE       Type,
+    ACPI_OSD_EXEC_CALLBACK  Function,
+    void                    *Context);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWaitEventsComplete
+void
+AcpiOsWaitEventsComplete (
+    void);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsSleep
+void
+AcpiOsSleep (
+    UINT64                  Milliseconds);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsStall
+void
+AcpiOsStall (
+    UINT32                  Microseconds);
+#endif
+
+
+/*
+ * Platform and hardware-independent I/O interfaces
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadPort
+ACPI_STATUS
+AcpiOsReadPort (
+    ACPI_IO_ADDRESS         Address,
+    UINT32                  *Value,
+    UINT32                  Width);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWritePort
+ACPI_STATUS
+AcpiOsWritePort (
+    ACPI_IO_ADDRESS         Address,
+    UINT32                  Value,
+    UINT32                  Width);
+#endif
+
+
+/*
+ * Platform and hardware-independent physical memory interfaces
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadMemory
+ACPI_STATUS
+AcpiOsReadMemory (
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT64                  *Value,
+    UINT32                  Width);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWriteMemory
+ACPI_STATUS
+AcpiOsWriteMemory (
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT64                  Value,
+    UINT32                  Width);
+#endif
+
+
+/*
+ * Platform and hardware-independent PCI configuration space access
+ * Note: Can't use "Register" as a parameter, changed to "Reg" --
+ * certain compilers complain.
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadPciConfiguration
+ACPI_STATUS
+AcpiOsReadPciConfiguration (
+    ACPI_PCI_ID             *PciId,
+    UINT32                  Reg,
+    UINT64                  *Value,
+    UINT32                  Width);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWritePciConfiguration
+ACPI_STATUS
+AcpiOsWritePciConfiguration (
+    ACPI_PCI_ID             *PciId,
+    UINT32                  Reg,
+    UINT64                  Value,
+    UINT32                  Width);
+#endif
+
+
+/*
+ * Miscellaneous
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsReadable
+BOOLEAN
+AcpiOsReadable (
+    void                    *Pointer,
+    ACPI_SIZE               Length);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsWritable
+BOOLEAN
+AcpiOsWritable (
+    void                    *Pointer,
+    ACPI_SIZE               Length);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTimer
+UINT64
+AcpiOsGetTimer (
+    void);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsSignal
+ACPI_STATUS
+AcpiOsSignal (
+    UINT32                  Function,
+    void                    *Info);
+#endif
+
+
+/*
+ * Debug print routines
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsPrintf
+void ACPI_INTERNAL_VAR_XFACE
+AcpiOsPrintf (
+    const char              *Format,
+    ...);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsVprintf
+void
+AcpiOsVprintf (
+    const char              *Format,
+    va_list                 Args);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsRedirectOutput
+void
+AcpiOsRedirectOutput (
+    void                    *Destination);
+#endif
+
+
+/*
+ * Debug input
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetLine
+ACPI_STATUS
+AcpiOsGetLine (
+    char                    *Buffer,
+    UINT32                  BufferLength,
+    UINT32                  *BytesRead);
+#endif
+
+
+/*
+ * Obtain ACPI table(s)
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByName
+ACPI_STATUS
+AcpiOsGetTableByName (
+    char                    *Signature,
+    UINT32                  Instance,
+    ACPI_TABLE_HEADER       **Table,
+    ACPI_PHYSICAL_ADDRESS   *Address);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByIndex
+ACPI_STATUS
+AcpiOsGetTableByIndex (
+    UINT32                  Index,
+    ACPI_TABLE_HEADER       **Table,
+    UINT32                  *Instance,
+    ACPI_PHYSICAL_ADDRESS   *Address);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetTableByAddress
+ACPI_STATUS
+AcpiOsGetTableByAddress (
+    ACPI_PHYSICAL_ADDRESS   Address,
+    ACPI_TABLE_HEADER       **Table);
+#endif
+
+
+/*
+ * Directory manipulation
+ */
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsOpenDirectory
+void *
+AcpiOsOpenDirectory (
+    char                    *Pathname,
+    char                    *WildcardSpec,
+    char                    RequestedFileType);
+#endif
+
+/* RequesteFileType values */
+
+#define REQUEST_FILE_ONLY                   0
+#define REQUEST_DIR_ONLY                    1
+
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsGetNextFilename
+char *
+AcpiOsGetNextFilename (
+    void                    *DirHandle);
+#endif
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsCloseDirectory
+void
+AcpiOsCloseDirectory (
+    void                    *DirHandle);
+#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
+
+#ifndef ACPI_USE_ALTERNATE_PROTOTYPE_AcpiOsTracePoint
+void
+AcpiOsTracePoint (
+    ACPI_TRACE_EVENT_TYPE   Type,
+    BOOLEAN                 Begin,
+    UINT8                   *Aml,
+    char                    *Pathname);
+#endif
+
+
+#endif /* __ACPIOSXF_H__ */

+ 1258 - 0
kernel/include/acpica/acpixf.h

@@ -0,0 +1,1258 @@
+/******************************************************************************
+ *
+ * Name: acpixf.h - External interfaces to the ACPI subsystem
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACXFACE_H__
+#define __ACXFACE_H__
+
+#pragma GCC diagnostic ignored "-Wunused-function"
+
+/* Current ACPICA subsystem version in YYYYMMDD format */
+
+#define ACPI_CA_VERSION                 0x20151218
+
+#include "acconfig.h"
+#include "actypes.h"
+#include "actbl.h"
+#include "acbuffer.h"
+
+
+/*****************************************************************************
+ *
+ * Macros used for ACPICA globals and configuration
+ *
+ ****************************************************************************/
+
+/*
+ * Ensure that global variables are defined and initialized only once.
+ *
+ * The use of these macros allows for a single list of globals (here)
+ * in order to simplify maintenance of the code.
+ */
+#ifdef DEFINE_ACPI_GLOBALS
+#define ACPI_GLOBAL(type,name) \
+    extern type name; \
+    type name
+
+#define ACPI_INIT_GLOBAL(type,name,value) \
+    type name=value
+
+#else
+#ifndef ACPI_GLOBAL
+#define ACPI_GLOBAL(type,name) \
+    extern type name
+#endif
+
+#ifndef ACPI_INIT_GLOBAL
+#define ACPI_INIT_GLOBAL(type,name,value) \
+    extern type name
+#endif
+#endif
+
+/*
+ * These macros configure the various ACPICA interfaces. They are
+ * useful for generating stub inline functions for features that are
+ * configured out of the current kernel or ACPICA application.
+ */
+#ifndef ACPI_EXTERNAL_RETURN_STATUS
+#define ACPI_EXTERNAL_RETURN_STATUS(Prototype) \
+    Prototype;
+#endif
+
+#ifndef ACPI_EXTERNAL_RETURN_OK
+#define ACPI_EXTERNAL_RETURN_OK(Prototype) \
+    Prototype;
+#endif
+
+#ifndef ACPI_EXTERNAL_RETURN_VOID
+#define ACPI_EXTERNAL_RETURN_VOID(Prototype) \
+    Prototype;
+#endif
+
+#ifndef ACPI_EXTERNAL_RETURN_UINT32
+#define ACPI_EXTERNAL_RETURN_UINT32(Prototype) \
+    Prototype;
+#endif
+
+#ifndef ACPI_EXTERNAL_RETURN_PTR
+#define ACPI_EXTERNAL_RETURN_PTR(Prototype) \
+    Prototype;
+#endif
+
+
+/*****************************************************************************
+ *
+ * Public globals and runtime configuration options
+ *
+ ****************************************************************************/
+
+/*
+ * Enable "slack mode" of the AML interpreter?  Default is FALSE, and the
+ * interpreter strictly follows the ACPI specification. Setting to TRUE
+ * allows the interpreter to ignore certain errors and/or bad AML constructs.
+ *
+ * Currently, these features are enabled by this flag:
+ *
+ * 1) Allow "implicit return" of last value in a control method
+ * 2) Allow access beyond the end of an operation region
+ * 3) Allow access to uninitialized locals/args (auto-init to integer 0)
+ * 4) Allow ANY object type to be a source operand for the Store() operator
+ * 5) Allow unresolved references (invalid target name) in package objects
+ * 6) Enable warning messages for behavior that is not ACPI spec compliant
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_EnableInterpreterSlack, FALSE);
+
+/*
+ * Automatically serialize all methods that create named objects? Default
+ * is TRUE, meaning that all NonSerialized methods are scanned once at
+ * table load time to determine those that create named objects. Methods
+ * that create named objects are marked Serialized in order to prevent
+ * possible run-time problems if they are entered by more than one thread.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_AutoSerializeMethods, TRUE);
+
+/*
+ * Create the predefined _OSI method in the namespace? Default is TRUE
+ * because ACPICA is fully compatible with other ACPI implementations.
+ * Changing this will revert ACPICA (and machine ASL) to pre-OSI behavior.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_CreateOsiMethod, TRUE);
+
+/*
+ * Optionally use default values for the ACPI register widths. Set this to
+ * TRUE to use the defaults, if an FADT contains incorrect widths/lengths.
+ */
+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.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_EnableAmlDebugObject, FALSE);
+
+/*
+ * Optionally copy the entire DSDT to local memory (instead of simply
+ * mapping it.) There are some BIOSs that corrupt or replace the original
+ * DSDT, creating the need for this option. Default is FALSE, do not copy
+ * the DSDT.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_CopyDsdtLocally, FALSE);
+
+/*
+ * Optionally ignore an XSDT if present and use the RSDT instead.
+ * Although the ACPI specification requires that an XSDT be used instead
+ * of the RSDT, the XSDT has been found to be corrupt or ill-formed on
+ * some machines. Default behavior is to use the XSDT if present.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_DoNotUseXsdt, FALSE);
+
+/*
+ * Optionally allow default region handlers to be overridden.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_OverrideDefaultRegionHandlers, FALSE);
+
+/*
+ * Optionally use 32-bit FADT addresses if and when there is a conflict
+ * (address mismatch) between the 32-bit and 64-bit versions of the
+ * address. Although ACPICA adheres to the ACPI specification which
+ * requires the use of the corresponding 64-bit address if it is non-zero,
+ * some machines have been found to have a corrupted non-zero 64-bit
+ * address. Default is FALSE, do not favor the 32-bit addresses.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_Use32BitFadtAddresses, FALSE);
+
+/*
+ * Optionally use 32-bit FACS table addresses.
+ * It is reported that some platforms fail to resume from system suspending
+ * if 64-bit FACS table address is selected:
+ * https://bugzilla.kernel.org/show_bug.cgi?id=74021
+ * Default is TRUE, favor the 32-bit addresses.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_Use32BitFacsAddresses, TRUE);
+
+/*
+ * Optionally truncate I/O addresses to 16 bits. Provides compatibility
+ * with other ACPI implementations. NOTE: During ACPICA initialization,
+ * this value is set to TRUE if any Windows OSI strings have been
+ * requested by the BIOS.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_TruncateIoAddresses, FALSE);
+
+/*
+ * Disable runtime checking and repair of values returned by control methods.
+ * Use only if the repair is causing a problem on a particular machine.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_DisableAutoRepair, FALSE);
+
+/*
+ * Optionally do not install any SSDTs from the RSDT/XSDT during initialization.
+ * This can be useful for debugging ACPI problems on some machines.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_DisableSsdtTableInstall, FALSE);
+
+/*
+ * Optionally enable runtime namespace override.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_RuntimeNamespaceOverride, TRUE);
+
+/*
+ * We keep track of the latest version of Windows that has been requested by
+ * the BIOS. ACPI 5.0.
+ */
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_OsiData, 0);
+
+/*
+ * ACPI 5.0 introduces the concept of a "reduced hardware platform", meaning
+ * that the ACPI hardware is no longer required. A flag in the FADT indicates
+ * a reduced HW machine, and that flag is duplicated here for convenience.
+ */
+ACPI_INIT_GLOBAL (BOOLEAN,          AcpiGbl_ReducedHardware, FALSE);
+
+/*
+ * This mechanism is used to trace a specified AML method. The method is
+ * traced each time it is executed.
+ */
+ACPI_INIT_GLOBAL (UINT32,           AcpiGbl_TraceFlags, 0);
+ACPI_INIT_GLOBAL (const char *,     AcpiGbl_TraceMethodName, NULL);
+ACPI_INIT_GLOBAL (UINT32,           AcpiGbl_TraceDbgLevel, ACPI_TRACE_LEVEL_DEFAULT);
+ACPI_INIT_GLOBAL (UINT32,           AcpiGbl_TraceDbgLayer, ACPI_TRACE_LAYER_DEFAULT);
+
+/*
+ * Runtime configuration of debug output control masks. We want the debug
+ * switches statically initialized so they are already set when the debugger
+ * is entered.
+ */
+#ifdef ACPI_DEBUG_OUTPUT
+ACPI_INIT_GLOBAL (UINT32,           AcpiDbgLevel, ACPI_DEBUG_DEFAULT);
+#else
+ACPI_INIT_GLOBAL (UINT32,           AcpiDbgLevel, ACPI_NORMAL_DEFAULT);
+#endif
+ACPI_INIT_GLOBAL (UINT32,           AcpiDbgLayer, ACPI_COMPONENT_DEFAULT);
+
+/* Optionally enable timer output with Debug Object output */
+
+ACPI_INIT_GLOBAL (UINT8,            AcpiGbl_DisplayDebugTimer, FALSE);
+
+/*
+ * Other miscellaneous globals
+ */
+ACPI_GLOBAL (ACPI_TABLE_FADT,       AcpiGbl_FADT);
+ACPI_GLOBAL (UINT32,                AcpiCurrentGpeCount);
+ACPI_GLOBAL (BOOLEAN,               AcpiGbl_SystemAwakeAndRunning);
+
+
+/*****************************************************************************
+ *
+ * ACPICA public interface configuration.
+ *
+ * Interfaces that are configured out of the ACPICA build are replaced
+ * by inlined stubs by default.
+ *
+ ****************************************************************************/
+
+/*
+ * Hardware-reduced prototypes (default: Not hardware reduced).
+ *
+ * All ACPICA hardware-related interfaces that use these macros will be
+ * configured out of the ACPICA build if the ACPI_REDUCED_HARDWARE flag
+ * is set to TRUE.
+ *
+ * Note: This static build option for reduced hardware is intended to
+ * reduce ACPICA code size if desired or necessary. However, even if this
+ * option is not specified, the runtime behavior of ACPICA is dependent
+ * on the actual FADT reduced hardware flag (HW_REDUCED_ACPI). If set,
+ * the flag will enable similar behavior -- ACPICA will not attempt
+ * to access any ACPI-relate hardware (SCI, GPEs, Fixed Events, etc.)
+ */
+#if (!ACPI_REDUCED_HARDWARE)
+#define ACPI_HW_DEPENDENT_RETURN_STATUS(Prototype) \
+    ACPI_EXTERNAL_RETURN_STATUS(Prototype)
+
+#define ACPI_HW_DEPENDENT_RETURN_OK(Prototype) \
+    ACPI_EXTERNAL_RETURN_OK(Prototype)
+
+#define ACPI_HW_DEPENDENT_RETURN_VOID(Prototype) \
+    ACPI_EXTERNAL_RETURN_VOID(Prototype)
+
+#else
+#define ACPI_HW_DEPENDENT_RETURN_STATUS(Prototype) \
+    static ACPI_INLINE Prototype {return(AE_NOT_CONFIGURED);}
+
+#define ACPI_HW_DEPENDENT_RETURN_OK(Prototype) \
+    static ACPI_INLINE Prototype {return(AE_OK);}
+
+#define ACPI_HW_DEPENDENT_RETURN_VOID(Prototype) \
+    static ACPI_INLINE Prototype {return;}
+
+#endif /* !ACPI_REDUCED_HARDWARE */
+
+
+/*
+ * Error message prototypes (default: error messages enabled).
+ *
+ * All interfaces related to error and warning messages
+ * will be configured out of the ACPICA build if the
+ * ACPI_NO_ERROR_MESSAGE flag is defined.
+ */
+#ifndef ACPI_NO_ERROR_MESSAGES
+#define ACPI_MSG_DEPENDENT_RETURN_VOID(Prototype) \
+    Prototype;
+
+#else
+#define ACPI_MSG_DEPENDENT_RETURN_VOID(Prototype) \
+    static ACPI_INLINE Prototype {return;}
+
+#endif /* ACPI_NO_ERROR_MESSAGES */
+
+
+/*
+ * Debugging output prototypes (default: no debug output).
+ *
+ * All interfaces related to debug output messages
+ * will be configured out of the ACPICA build unless the
+ * ACPI_DEBUG_OUTPUT flag is defined.
+ */
+#ifdef ACPI_DEBUG_OUTPUT
+#define ACPI_DBG_DEPENDENT_RETURN_VOID(Prototype) \
+    Prototype;
+
+#else
+#define ACPI_DBG_DEPENDENT_RETURN_VOID(Prototype) \
+    static ACPI_INLINE Prototype {return;}
+
+#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 */
+
+
+/*
+ * Debugger prototypes
+ *
+ * All interfaces used by debugger will be configured
+ * out of the ACPICA build unless the ACPI_DEBUGGER
+ * flag is defined.
+ */
+#ifdef ACPI_DEBUGGER
+#define ACPI_DBR_DEPENDENT_RETURN_OK(Prototype) \
+    ACPI_EXTERNAL_RETURN_OK(Prototype)
+
+#define ACPI_DBR_DEPENDENT_RETURN_VOID(Prototype) \
+    ACPI_EXTERNAL_RETURN_VOID(Prototype)
+
+#else
+#define ACPI_DBR_DEPENDENT_RETURN_OK(Prototype) \
+    static ACPI_INLINE Prototype {return(AE_OK);}
+
+#define ACPI_DBR_DEPENDENT_RETURN_VOID(Prototype) \
+    static ACPI_INLINE Prototype {return;}
+
+#endif /* ACPI_DEBUGGER */
+
+
+/*****************************************************************************
+ *
+ * ACPICA public interface prototypes
+ *
+ ****************************************************************************/
+
+/*
+ * Initialization
+ */
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInitializeTables (
+    ACPI_TABLE_DESC         *InitialStorage,
+    UINT32                  InitialTableCount,
+    BOOLEAN                 AllowResize))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInitializeSubsystem (
+    void))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiEnableSubsystem (
+    UINT32                  Flags))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInitializeObjects (
+    UINT32                  Flags))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiTerminate (
+    void))
+
+
+/*
+ * Miscellaneous global interfaces
+ */
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiEnable (
+    void))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiDisable (
+    void))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiSubsystemStatus (
+    void))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetSystemInfo (
+    ACPI_BUFFER             *RetBuffer))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetStatistics (
+    ACPI_STATISTICS         *Stats))
+
+ACPI_EXTERNAL_RETURN_PTR (
+const char *
+AcpiFormatException (
+    ACPI_STATUS             Exception))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiPurgeCachedObjects (
+    void))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallInterface (
+    ACPI_STRING             InterfaceName))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiRemoveInterface (
+    ACPI_STRING             InterfaceName))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiUpdateInterfaces (
+    UINT8                   Action))
+
+ACPI_EXTERNAL_RETURN_UINT32 (
+UINT32
+AcpiCheckAddressRange (
+    ACPI_ADR_SPACE_TYPE     SpaceId,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    ACPI_SIZE               Length,
+    BOOLEAN                 Warn))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiDecodePldBuffer (
+    UINT8                   *InBuffer,
+    ACPI_SIZE               Length,
+    ACPI_PLD_INFO           **ReturnBuffer))
+
+
+/*
+ * ACPI table load/unload interfaces
+ */
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallTable (
+    ACPI_PHYSICAL_ADDRESS   Address,
+    BOOLEAN                 Physical))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiLoadTable (
+    ACPI_TABLE_HEADER       *Table))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiUnloadParentTable (
+    ACPI_HANDLE             Object))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiLoadTables (
+    void))
+
+
+/*
+ * ACPI table manipulation interfaces
+ */
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiReallocateRootTable (
+    void))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiFindRootPointer (
+    ACPI_PHYSICAL_ADDRESS   *RsdpAddress))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetTableHeader (
+    ACPI_STRING             Signature,
+    UINT32                  Instance,
+    ACPI_TABLE_HEADER       *OutTableHeader))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetTable (
+    ACPI_STRING             Signature,
+    UINT32                  Instance,
+    ACPI_TABLE_HEADER       **OutTable))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetTableByIndex (
+    UINT32                  TableIndex,
+    ACPI_TABLE_HEADER       **OutTable))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallTableHandler (
+    ACPI_TABLE_HANDLER      Handler,
+    void                    *Context))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiRemoveTableHandler (
+    ACPI_TABLE_HANDLER      Handler))
+
+
+/*
+ * Namespace and name interfaces
+ */
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiWalkNamespace (
+    ACPI_OBJECT_TYPE        Type,
+    ACPI_HANDLE             StartObject,
+    UINT32                  MaxDepth,
+    ACPI_WALK_CALLBACK      DescendingCallback,
+    ACPI_WALK_CALLBACK      AscendingCallback,
+    void                    *Context,
+    void                    **ReturnValue))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetDevices (
+    char                    *HID,
+    ACPI_WALK_CALLBACK      UserFunction,
+    void                    *Context,
+    void                    **ReturnValue))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetName (
+    ACPI_HANDLE             Object,
+    UINT32                  NameType,
+    ACPI_BUFFER             *RetPathPtr))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetHandle (
+    ACPI_HANDLE             Parent,
+    ACPI_STRING             Pathname,
+    ACPI_HANDLE             *RetHandle))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiAttachData (
+    ACPI_HANDLE             Object,
+    ACPI_OBJECT_HANDLER     Handler,
+    void                    *Data))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiDetachData (
+    ACPI_HANDLE             Object,
+    ACPI_OBJECT_HANDLER     Handler))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetData (
+    ACPI_HANDLE             Object,
+    ACPI_OBJECT_HANDLER     Handler,
+    void                    **Data))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiDebugTrace (
+    const char              *Name,
+    UINT32                  DebugLevel,
+    UINT32                  DebugLayer,
+    UINT32                  Flags))
+
+
+/*
+ * Object manipulation and enumeration
+ */
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiEvaluateObject (
+    ACPI_HANDLE             Object,
+    ACPI_STRING             Pathname,
+    ACPI_OBJECT_LIST        *ParameterObjects,
+    ACPI_BUFFER             *ReturnObjectBuffer))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiEvaluateObjectTyped (
+    ACPI_HANDLE             Object,
+    ACPI_STRING             Pathname,
+    ACPI_OBJECT_LIST        *ExternalParams,
+    ACPI_BUFFER             *ReturnBuffer,
+    ACPI_OBJECT_TYPE        ReturnType))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetObjectInfo (
+    ACPI_HANDLE             Object,
+    ACPI_DEVICE_INFO        **ReturnBuffer))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallMethod (
+    UINT8                   *Buffer))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetNextObject (
+    ACPI_OBJECT_TYPE        Type,
+    ACPI_HANDLE             Parent,
+    ACPI_HANDLE             Child,
+    ACPI_HANDLE             *OutHandle))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetType (
+    ACPI_HANDLE             Object,
+    ACPI_OBJECT_TYPE        *OutType))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetParent (
+    ACPI_HANDLE             Object,
+    ACPI_HANDLE             *OutHandle))
+
+
+/*
+ * Handler interfaces
+ */
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallInitializationHandler (
+    ACPI_INIT_HANDLER       Handler,
+    UINT32                  Function))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallSciHandler (
+    ACPI_SCI_HANDLER        Address,
+    void                    *Context))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiRemoveSciHandler (
+    ACPI_SCI_HANDLER        Address))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallGlobalEventHandler (
+    ACPI_GBL_EVENT_HANDLER  Handler,
+    void                    *Context))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallFixedEventHandler (
+    UINT32                  AcpiEvent,
+    ACPI_EVENT_HANDLER      Handler,
+    void                    *Context))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiRemoveFixedEventHandler (
+    UINT32                  AcpiEvent,
+    ACPI_EVENT_HANDLER      Handler))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallGpeHandler (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber,
+    UINT32                  Type,
+    ACPI_GPE_HANDLER        Address,
+    void                    *Context))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallGpeRawHandler (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber,
+    UINT32                  Type,
+    ACPI_GPE_HANDLER        Address,
+    void                    *Context))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiRemoveGpeHandler (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber,
+    ACPI_GPE_HANDLER        Address))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallNotifyHandler (
+    ACPI_HANDLE             Device,
+    UINT32                  HandlerType,
+    ACPI_NOTIFY_HANDLER     Handler,
+    void                    *Context))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiRemoveNotifyHandler (
+    ACPI_HANDLE             Device,
+    UINT32                  HandlerType,
+    ACPI_NOTIFY_HANDLER     Handler))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallAddressSpaceHandler (
+    ACPI_HANDLE             Device,
+    ACPI_ADR_SPACE_TYPE     SpaceId,
+    ACPI_ADR_SPACE_HANDLER  Handler,
+    ACPI_ADR_SPACE_SETUP    Setup,
+    void                    *Context))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiRemoveAddressSpaceHandler (
+    ACPI_HANDLE             Device,
+    ACPI_ADR_SPACE_TYPE     SpaceId,
+    ACPI_ADR_SPACE_HANDLER  Handler))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallExceptionHandler (
+    ACPI_EXCEPTION_HANDLER  Handler))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallInterfaceHandler (
+    ACPI_INTERFACE_HANDLER  Handler))
+
+
+/*
+ * Global Lock interfaces
+ */
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiAcquireGlobalLock (
+    UINT16                  Timeout,
+    UINT32                  *Handle))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiReleaseGlobalLock (
+    UINT32                  Handle))
+
+
+/*
+ * Interfaces to AML mutex objects
+ */
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiAcquireMutex (
+    ACPI_HANDLE             Handle,
+    ACPI_STRING             Pathname,
+    UINT16                  Timeout))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiReleaseMutex (
+    ACPI_HANDLE             Handle,
+    ACPI_STRING             Pathname))
+
+
+/*
+ * Fixed Event interfaces
+ */
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiEnableEvent (
+    UINT32                  Event,
+    UINT32                  Flags))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiDisableEvent (
+    UINT32                  Event,
+    UINT32                  Flags))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiClearEvent (
+    UINT32                  Event))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetEventStatus (
+    UINT32                  Event,
+    ACPI_EVENT_STATUS       *EventStatus))
+
+
+/*
+ * General Purpose Event (GPE) Interfaces
+ */
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiUpdateAllGpes (
+    void))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiEnableGpe (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiDisableGpe (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiClearGpe (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiSetGpe (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber,
+    UINT8                   Action))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiFinishGpe (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiMarkGpeForWake (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiSetupGpeForWake (
+    ACPI_HANDLE             ParentDevice,
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiSetGpeWakeMask (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber,
+    UINT8                   Action))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetGpeStatus (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber,
+    ACPI_EVENT_STATUS       *EventStatus))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiDisableAllGpes (
+    void))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiEnableAllRuntimeGpes (
+    void))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiEnableAllWakeupGpes (
+    void))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetGpeDevice (
+    UINT32                  GpeIndex,
+    ACPI_HANDLE             *GpeDevice))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiInstallGpeBlock (
+    ACPI_HANDLE             GpeDevice,
+    ACPI_GENERIC_ADDRESS    *GpeBlockAddress,
+    UINT32                  RegisterCount,
+    UINT32                  InterruptNumber))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiRemoveGpeBlock (
+    ACPI_HANDLE             GpeDevice))
+
+
+/*
+ * Resource interfaces
+ */
+typedef
+ACPI_STATUS (*ACPI_WALK_RESOURCE_CALLBACK) (
+    ACPI_RESOURCE           *Resource,
+    void                    *Context);
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetVendorResource (
+    ACPI_HANDLE             Device,
+    char                    *Name,
+    ACPI_VENDOR_UUID        *Uuid,
+    ACPI_BUFFER             *RetBuffer))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetCurrentResources (
+    ACPI_HANDLE             Device,
+    ACPI_BUFFER             *RetBuffer))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetPossibleResources (
+    ACPI_HANDLE             Device,
+    ACPI_BUFFER             *RetBuffer))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetEventResources (
+    ACPI_HANDLE             DeviceHandle,
+    ACPI_BUFFER             *RetBuffer))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiWalkResourceBuffer (
+    ACPI_BUFFER                 *Buffer,
+    ACPI_WALK_RESOURCE_CALLBACK UserFunction,
+    void                        *Context))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiWalkResources (
+    ACPI_HANDLE                 Device,
+    char                        *Name,
+    ACPI_WALK_RESOURCE_CALLBACK UserFunction,
+    void                        *Context))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiSetCurrentResources (
+    ACPI_HANDLE             Device,
+    ACPI_BUFFER             *InBuffer))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetIrqRoutingTable (
+    ACPI_HANDLE             Device,
+    ACPI_BUFFER             *RetBuffer))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiResourceToAddress64 (
+    ACPI_RESOURCE           *Resource,
+    ACPI_RESOURCE_ADDRESS64 *Out))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiBufferToResource (
+    UINT8                   *AmlBuffer,
+    UINT16                  AmlBufferLength,
+    ACPI_RESOURCE           **ResourcePtr))
+
+
+/*
+ * Hardware (ACPI device) interfaces
+ */
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiReset (
+    void))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiRead (
+    UINT64                  *Value,
+    ACPI_GENERIC_ADDRESS    *Reg))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiWrite (
+    UINT64                  Value,
+    ACPI_GENERIC_ADDRESS    *Reg))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiReadBitRegister (
+    UINT32                  RegisterId,
+    UINT32                  *ReturnValue))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiWriteBitRegister (
+    UINT32                  RegisterId,
+    UINT32                  Value))
+
+
+/*
+ * Sleep/Wake interfaces
+ */
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetSleepTypeData (
+    UINT8                   SleepState,
+    UINT8                   *Slp_TypA,
+    UINT8                   *Slp_TypB))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiEnterSleepStatePrep (
+    UINT8                   SleepState))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiEnterSleepState (
+    UINT8                   SleepState))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiEnterSleepStateS4bios (
+    void))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiLeaveSleepStatePrep (
+    UINT8                   SleepState))
+
+ACPI_EXTERNAL_RETURN_STATUS (
+ACPI_STATUS
+AcpiLeaveSleepState (
+    UINT8                   SleepState))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiSetFirmwareWakingVector (
+    ACPI_PHYSICAL_ADDRESS   PhysicalAddress,
+    ACPI_PHYSICAL_ADDRESS   PhysicalAddress64))
+
+
+/*
+ * ACPI Timer interfaces
+ */
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetTimerResolution (
+    UINT32                  *Resolution))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetTimer (
+    UINT32                  *Ticks))
+
+ACPI_HW_DEPENDENT_RETURN_STATUS (
+ACPI_STATUS
+AcpiGetTimerDuration (
+    UINT32                  StartTicks,
+    UINT32                  EndTicks,
+    UINT32                  *TimeElapsed))
+
+
+/*
+ * Error/Warning output
+ */
+ACPI_MSG_DEPENDENT_RETURN_VOID (
+ACPI_PRINTF_LIKE(3)
+void ACPI_INTERNAL_VAR_XFACE
+AcpiError (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    const char              *Format,
+    ...))
+
+ACPI_MSG_DEPENDENT_RETURN_VOID (
+ACPI_PRINTF_LIKE(4)
+void  ACPI_INTERNAL_VAR_XFACE
+AcpiException (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    ACPI_STATUS             Status,
+    const char              *Format,
+    ...))
+
+ACPI_MSG_DEPENDENT_RETURN_VOID (
+ACPI_PRINTF_LIKE(3)
+void ACPI_INTERNAL_VAR_XFACE
+AcpiWarning (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    const char              *Format,
+    ...))
+
+ACPI_MSG_DEPENDENT_RETURN_VOID (
+ACPI_PRINTF_LIKE(3)
+void ACPI_INTERNAL_VAR_XFACE
+AcpiInfo (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    const char              *Format,
+    ...))
+
+ACPI_MSG_DEPENDENT_RETURN_VOID (
+ACPI_PRINTF_LIKE(3)
+void ACPI_INTERNAL_VAR_XFACE
+AcpiBiosError (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    const char              *Format,
+    ...))
+
+ACPI_MSG_DEPENDENT_RETURN_VOID (
+ACPI_PRINTF_LIKE(3)
+void ACPI_INTERNAL_VAR_XFACE
+AcpiBiosWarning (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    const char              *Format,
+    ...))
+
+
+/*
+ * Debug output
+ */
+ACPI_DBG_DEPENDENT_RETURN_VOID (
+ACPI_PRINTF_LIKE(6)
+void ACPI_INTERNAL_VAR_XFACE
+AcpiDebugPrint (
+    UINT32                  RequestedDebugLevel,
+    UINT32                  LineNumber,
+    const char              *FunctionName,
+    const char              *ModuleName,
+    UINT32                  ComponentId,
+    const char              *Format,
+    ...))
+
+ACPI_DBG_DEPENDENT_RETURN_VOID (
+ACPI_PRINTF_LIKE(6)
+void ACPI_INTERNAL_VAR_XFACE
+AcpiDebugPrintRaw (
+    UINT32                  RequestedDebugLevel,
+    UINT32                  LineNumber,
+    const char              *FunctionName,
+    const char              *ModuleName,
+    UINT32                  ComponentId,
+    const char              *Format,
+    ...))
+
+ACPI_DBG_DEPENDENT_RETURN_VOID (
+void
+AcpiTracePoint (
+    ACPI_TRACE_EVENT_TYPE   Type,
+    BOOLEAN                 Begin,
+    UINT8                   *Aml,
+    char                    *Pathname))
+
+ACPI_APP_DEPENDENT_RETURN_VOID (
+ACPI_PRINTF_LIKE(1)
+void ACPI_INTERNAL_VAR_XFACE
+AcpiLogError (
+    const char              *Format,
+    ...))
+
+ACPI_STATUS
+AcpiInitializeDebugger (
+    void);
+
+void
+AcpiTerminateDebugger (
+    void);
+
+void
+AcpiSetDebuggerThreadId (
+    ACPI_THREAD_ID          ThreadId);
+
+#endif /* __ACXFACE_H__ */

+ 1119 - 0
kernel/include/acpica/acpredef.h

@@ -0,0 +1,1119 @@
+/******************************************************************************
+ *
+ * Name: acpredef - Information table for ACPI predefined methods and objects
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACPREDEF_H__
+#define __ACPREDEF_H__
+
+
+/******************************************************************************
+ *
+ * Return Package types
+ *
+ * 1) PTYPE1 packages do not contain subpackages.
+ *
+ * ACPI_PTYPE1_FIXED: Fixed-length length, 1 or 2 object types:
+ *      object type
+ *      count
+ *      object type
+ *      count
+ *
+ * ACPI_PTYPE1_VAR: Variable-length length. Zero-length package is allowed:
+ *      object type (Int/Buf/Ref)
+ *
+ * ACPI_PTYPE1_OPTION: Package has some required and some optional elements
+ *      (Used for _PRW)
+ *
+ *
+ * 2) PTYPE2 packages contain a Variable-length number of subpackages. Each
+ *    of the different types describe the contents of each of the subpackages.
+ *
+ * ACPI_PTYPE2: Each subpackage contains 1 or 2 object types. Zero-length
+ *      parent package is allowed:
+ *      object type
+ *      count
+ *      object type
+ *      count
+ *      (Used for _ALR,_MLS,_PSS,_TRT,_TSS)
+ *
+ * ACPI_PTYPE2_COUNT: Each subpackage has a count as first element.
+ *      Zero-length parent package is allowed:
+ *      object type
+ *      (Used for _CSD,_PSD,_TSD)
+ *
+ * ACPI_PTYPE2_PKG_COUNT: Count of subpackages at start, 1 or 2 object types:
+ *      object type
+ *      count
+ *      object type
+ *      count
+ *      (Used for _CST)
+ *
+ * ACPI_PTYPE2_FIXED: Each subpackage is of Fixed-length. Zero-length
+ *      parent package is allowed.
+ *      (Used for _PRT)
+ *
+ * ACPI_PTYPE2_MIN: Each subpackage has a Variable-length but minimum length.
+ *      Zero-length parent package is allowed:
+ *      (Used for _HPX)
+ *
+ * ACPI_PTYPE2_REV_FIXED: Revision at start, each subpackage is Fixed-length
+ *      (Used for _ART, _FPS)
+ *
+ * ACPI_PTYPE2_FIX_VAR: Each subpackage consists of some fixed-length elements
+ *      followed by an optional element. Zero-length parent package is allowed.
+ *      object type
+ *      count
+ *      object type
+ *      count = 0 (optional)
+ *      (Used for _DLM)
+ *
+ * ACPI_PTYPE2_VAR_VAR: Variable number of subpackages, each of either a
+ *      constant or variable length. The subpackages are preceded by a
+ *      constant number of objects.
+ *      (Used for _LPI, _RDI)
+ *
+ * ACPI_PTYPE2_UUID_PAIR: Each subpackage is preceded by a UUID Buffer. The UUID
+ *      defines the format of the package. Zero-length parent package is
+ *      allowed.
+ *      (Used for _DSD)
+ *
+ *****************************************************************************/
+
+enum AcpiReturnPackageTypes
+{
+    ACPI_PTYPE1_FIXED       = 1,
+    ACPI_PTYPE1_VAR         = 2,
+    ACPI_PTYPE1_OPTION      = 3,
+    ACPI_PTYPE2             = 4,
+    ACPI_PTYPE2_COUNT       = 5,
+    ACPI_PTYPE2_PKG_COUNT   = 6,
+    ACPI_PTYPE2_FIXED       = 7,
+    ACPI_PTYPE2_MIN         = 8,
+    ACPI_PTYPE2_REV_FIXED   = 9,
+    ACPI_PTYPE2_FIX_VAR     = 10,
+    ACPI_PTYPE2_VAR_VAR     = 11,
+    ACPI_PTYPE2_UUID_PAIR   = 12
+};
+
+
+/* Support macros for users of the predefined info table */
+
+#define METHOD_PREDEF_ARGS_MAX          4
+#define METHOD_ARG_BIT_WIDTH            3
+#define METHOD_ARG_MASK                 0x0007
+#define ARG_COUNT_IS_MINIMUM            0x8000
+#define METHOD_MAX_ARG_TYPE             ACPI_TYPE_PACKAGE
+
+#define METHOD_GET_ARG_COUNT(ArgList)   ((ArgList) & METHOD_ARG_MASK)
+#define METHOD_GET_NEXT_TYPE(ArgList)   (((ArgList) >>= METHOD_ARG_BIT_WIDTH) & METHOD_ARG_MASK)
+
+/* Macros used to build the predefined info table */
+
+#define METHOD_0ARGS                    0
+#define METHOD_1ARGS(a1)                (1 | (a1 << 3))
+#define METHOD_2ARGS(a1,a2)             (2 | (a1 << 3) | (a2 << 6))
+#define METHOD_3ARGS(a1,a2,a3)          (3 | (a1 << 3) | (a2 << 6) | (a3 << 9))
+#define METHOD_4ARGS(a1,a2,a3,a4)       (4 | (a1 << 3) | (a2 << 6) | (a3 << 9) | (a4 << 12))
+
+#define METHOD_RETURNS(type)            (type)
+#define METHOD_NO_RETURN_VALUE          0
+
+#define PACKAGE_INFO(a,b,c,d,e,f)       {{{(a),(b),(c),(d)}, ((((UINT16)(f)) << 8) | (e)), 0}}
+
+
+/* Support macros for the resource descriptor info table */
+
+#define WIDTH_1                         0x0001
+#define WIDTH_2                         0x0002
+#define WIDTH_3                         0x0004
+#define WIDTH_8                         0x0008
+#define WIDTH_16                        0x0010
+#define WIDTH_32                        0x0020
+#define WIDTH_64                        0x0040
+#define VARIABLE_DATA                   0x0080
+#define NUM_RESOURCE_WIDTHS             8
+
+#define WIDTH_ADDRESS                   WIDTH_16 | WIDTH_32 | WIDTH_64
+
+
+#ifdef ACPI_CREATE_PREDEFINED_TABLE
+/******************************************************************************
+ *
+ * Predefined method/object information table.
+ *
+ * These are the names that can actually be evaluated via AcpiEvaluateObject.
+ * Not present in this table are the following:
+ *
+ *      1) Predefined/Reserved names that are not usually evaluated via
+ *         AcpiEvaluateObject:
+ *              _Lxx and _Exx GPE methods
+ *              _Qxx EC methods
+ *              _T_x compiler temporary variables
+ *              _Wxx wake events
+ *
+ *      2) Predefined names that never actually exist within the AML code:
+ *              Predefined resource descriptor field names
+ *
+ *      3) Predefined names that are implemented within ACPICA:
+ *              _OSI
+ *
+ * The main entries in the table each contain the following items:
+ *
+ * Name                 - The ACPI reserved name
+ * ArgumentList         - Contains (in 16 bits), the number of required
+ *                        arguments to the method (3 bits), and a 3-bit type
+ *                        field for each argument (up to 4 arguments). The
+ *                        METHOD_?ARGS macros generate the correct packed data.
+ * ExpectedBtypes       - Allowed type(s) for the return value.
+ *                        0 means that no return value is expected.
+ *
+ * For methods that return packages, the next entry in the table contains
+ * information about the expected structure of the package. This information
+ * is saved here (rather than in a separate table) in order to minimize the
+ * overall size of the stored data.
+ *
+ * Note: The additional braces are intended to promote portability.
+ *
+ * Note2: Table is used by the kernel-resident subsystem, the iASL compiler,
+ * and the AcpiHelp utility.
+ *
+ * TBD: _PRT - currently ignore reversed entries. Attempt to fix in nsrepair.
+ * Possibly fixing package elements like _BIF, etc.
+ *
+ *****************************************************************************/
+
+const ACPI_PREDEFINED_INFO          AcpiGbl_PredefinedMethods[] =
+{
+    {{"_AC0",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_AC1",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_AC2",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_AC3",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_AC4",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_AC5",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_AC6",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_AC7",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_AC8",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_AC9",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_ADR",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_AEI",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_AL0",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_AL1",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_AL2",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_AL3",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_AL4",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_AL5",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_AL6",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_AL7",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_AL8",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_AL9",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_ALC",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_ALI",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_ALP",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_ALR",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each 2 (Ints) */
+                    PACKAGE_INFO (ACPI_PTYPE2, ACPI_RTYPE_INTEGER, 2,0,0,0),
+
+    {{"_ALT",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_ART",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (1 Int(rev), n Pkg (2 Ref/11 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE2_REV_FIXED, ACPI_RTYPE_REFERENCE, 2, ACPI_RTYPE_INTEGER, 11,0),
+
+    {{"_BBN",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_BCL",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Ints) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER, 0,0,0,0),
+
+    {{"_BCM",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_BCT",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_BDN",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_BFS",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_BIF",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (9 Int),(4 Str) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 9, ACPI_RTYPE_STRING, 4,0),
+
+    {{"_BIX",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (16 Int),(4 Str) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 16, ACPI_RTYPE_STRING, 4,0),
+
+    {{"_BLT",   METHOD_3ARGS (ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_BMA",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_BMC",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_BMD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (5 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 5,0,0,0),
+
+    {{"_BMS",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_BQC",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_BST",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (4 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 4,0,0,0),
+
+    {{"_BTH",   METHOD_1ARGS (ACPI_TYPE_INTEGER),      /* ACPI 6.0 */
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_BTM",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_BTP",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_CBA",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}}, /* See PCI firmware spec 3.0 */
+
+    {{"_CCA",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}}, /* ACPI 5.1 */
+
+    {{"_CDM",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_CID",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Ints/Strs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING, 0,0,0,0),
+
+    {{"_CLS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (3 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 3,0,0,0),
+
+    {{"_CPC",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Ints/Bufs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER | ACPI_RTYPE_BUFFER, 0,0,0,0),
+
+    {{"_CR3",   METHOD_0ARGS,                          /* ACPI 6.0 */
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_CRS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_CRT",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_CSD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (1 Int(n), n-1 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE2_COUNT, ACPI_RTYPE_INTEGER, 0,0,0,0),
+
+    {{"_CST",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (1 Int(n), n Pkg (1 Buf/3 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE2_PKG_COUNT,ACPI_RTYPE_BUFFER, 1, ACPI_RTYPE_INTEGER, 3,0),
+
+    {{"_CWS",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_DCK",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_DCS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_DDC",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER | ACPI_RTYPE_BUFFER)}},
+
+    {{"_DDN",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_STRING)}},
+
+    {{"_DEP",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_DGS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_DIS",   METHOD_0ARGS,
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_DLM",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each (1 Ref, 0/1 Optional Buf/Ref) */
+                    PACKAGE_INFO (ACPI_PTYPE2_FIX_VAR, ACPI_RTYPE_REFERENCE, 1, ACPI_RTYPE_REFERENCE | ACPI_RTYPE_BUFFER, 0,0),
+
+    {{"_DMA",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_DOD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Ints) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER, 0,0,0,0),
+
+    {{"_DOS",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_DSD",   METHOD_0ARGS,                          /* ACPI 6.0 */
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each: 1 Buf, 1 Pkg */
+                    PACKAGE_INFO (ACPI_PTYPE2_UUID_PAIR, ACPI_RTYPE_BUFFER, 1, ACPI_RTYPE_PACKAGE, 1,0),
+
+    {{"_DSM",   METHOD_4ARGS (ACPI_TYPE_BUFFER, ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER, ACPI_TYPE_PACKAGE),
+                METHOD_RETURNS (ACPI_RTYPE_ALL)}}, /* Must return a value, but it can be of any type */
+
+    {{"_DSS",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_DSW",   METHOD_3ARGS (ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_DTI",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_EC_",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_EDL",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs)*/
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_EJ0",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_EJ1",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_EJ2",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_EJ3",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_EJ4",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_EJD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_STRING)}},
+
+    {{"_ERR",   METHOD_3ARGS (ACPI_TYPE_INTEGER, ACPI_TYPE_STRING, ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}}, /* Internal use only, used by ACPICA test suites */
+
+    {{"_EVT",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_FDE",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_FDI",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (16 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 16,0,0,0),
+
+    {{"_FDM",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_FIF",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (4 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 4,0,0,0),
+
+    {{"_FIX",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Ints) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER, 0,0,0,0),
+
+    {{"_FPS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (1 Int(rev), n Pkg (5 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE2_REV_FIXED,ACPI_RTYPE_INTEGER, 5, 0,0,0),
+
+    {{"_FSL",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_FST",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (3 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 3,0,0,0),
+
+    {{"_GAI",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_GCP",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_GHL",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_GLK",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_GPD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_GPE",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}}, /* _GPE method, not _GPE scope */
+
+    {{"_GRT",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_GSB",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_GTF",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_GTM",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_GTS",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_GWS",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_HID",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING)}},
+
+    {{"_HOT",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_HPP",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (4 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 4,0,0,0),
+
+    /*
+     * For _HPX, a single package is returned, containing a variable-length number
+     * of subpackages. Each subpackage contains a PCI record setting.
+     * There are several different type of record settings, of different
+     * lengths, but all elements of all settings are Integers.
+     */
+    {{"_HPX",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each (var Ints) */
+                    PACKAGE_INFO (ACPI_PTYPE2_MIN, ACPI_RTYPE_INTEGER, 5,0,0,0),
+
+    {{"_HRV",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_IFT",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}}, /* See IPMI spec */
+
+    {{"_INI",   METHOD_0ARGS,
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_IRC",   METHOD_0ARGS,
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_LCK",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_LID",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_LPD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (1 Int(rev), n Pkg (2 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE2_REV_FIXED, ACPI_RTYPE_INTEGER, 2,0,0,0),
+
+    {{"_LPI",   METHOD_0ARGS,                          /* ACPI 6.0 */
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (3 Int, n Pkg (10 Int/Buf) */
+                    PACKAGE_INFO (ACPI_PTYPE2_VAR_VAR, ACPI_RTYPE_INTEGER, 3,
+                    ACPI_RTYPE_INTEGER | ACPI_RTYPE_BUFFER | ACPI_RTYPE_STRING, 10,0),
+
+    {{"_MAT",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_MBM",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (8 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 8,0,0,0),
+
+    {{"_MLS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each (1 Str/1 Buf) */
+                    PACKAGE_INFO (ACPI_PTYPE2, ACPI_RTYPE_STRING, 1, ACPI_RTYPE_BUFFER, 1,0),
+
+    {{"_MSG",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_MSM",   METHOD_4ARGS (ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_MTL",   METHOD_0ARGS,                          /* ACPI 6.0 */
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_NTT",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_OFF",   METHOD_0ARGS,
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_ON_",   METHOD_0ARGS,
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_OS_",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_STRING)}},
+
+    {{"_OSC",   METHOD_4ARGS (ACPI_TYPE_BUFFER, ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER, ACPI_TYPE_BUFFER),
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_OST",   METHOD_3ARGS (ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER, ACPI_TYPE_BUFFER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_PAI",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_PCL",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_PCT",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (2 Buf) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_BUFFER, 2,0,0,0),
+
+    {{"_PDC",   METHOD_1ARGS (ACPI_TYPE_BUFFER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_PDL",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_PIC",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_PIF",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (3 Int),(3 Str) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 3, ACPI_RTYPE_STRING, 3,0),
+
+    {{"_PLD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Bufs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_BUFFER, 0,0,0,0),
+
+    {{"_PMC",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (11 Int),(3 Str) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 11, ACPI_RTYPE_STRING, 3,0),
+
+    {{"_PMD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_PMM",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_PPC",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_PPE",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}}, /* See dig64 spec */
+
+    {{"_PR0",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_PR1",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_PR2",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_PR3",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_PRE",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_PRL",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_PRR",   METHOD_0ARGS,                          /* ACPI 6.0 */
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (1 Ref) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_REFERENCE, 1,0,0,0),
+
+    {{"_PRS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    /*
+     * For _PRT, many BIOSs reverse the 3rd and 4th Package elements (Source
+     * and SourceIndex). This bug is so prevalent that there is code in the
+     * ACPICA Resource Manager to detect this and switch them back. For now,
+     * do not allow and issue a warning. To allow this and eliminate the
+     * warning, add the ACPI_RTYPE_REFERENCE type to the 4th element (index 3)
+     * in the statement below.
+     */
+    {{"_PRT",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each (4): Int,Int,Int/Ref,Int */
+                    PACKAGE_INFO (ACPI_PTYPE2_FIXED, 4, ACPI_RTYPE_INTEGER, ACPI_RTYPE_INTEGER,
+                                  ACPI_RTYPE_INTEGER | ACPI_RTYPE_REFERENCE, ACPI_RTYPE_INTEGER),
+
+    {{"_PRW",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each: Pkg/Int,Int,[Variable-length Refs] (Pkg is Ref/Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_OPTION, 2, ACPI_RTYPE_INTEGER | ACPI_RTYPE_PACKAGE,
+                                  ACPI_RTYPE_INTEGER, ACPI_RTYPE_REFERENCE, 0),
+
+    {{"_PS0",   METHOD_0ARGS,
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_PS1",   METHOD_0ARGS,
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_PS2",   METHOD_0ARGS,
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_PS3",   METHOD_0ARGS,
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_PSC",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_PSD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each (5 Int) with count */
+                    PACKAGE_INFO (ACPI_PTYPE2_COUNT, ACPI_RTYPE_INTEGER, 0,0,0,0),
+
+    {{"_PSE",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_PSL",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_PSR",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_PSS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each (6 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE2, ACPI_RTYPE_INTEGER, 6,0,0,0),
+
+    {{"_PSV",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_PSW",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_PTC",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (2 Buf) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_BUFFER, 2,0,0,0),
+
+    {{"_PTP",   METHOD_2ARGS (ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_PTS",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_PUR",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (2 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 2,0,0,0),
+
+    {{"_PXM",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_RDI",   METHOD_0ARGS,                          /* ACPI 6.0 */
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (1 Int, n Pkg (m Ref)) */
+                    PACKAGE_INFO (ACPI_PTYPE2_VAR_VAR, ACPI_RTYPE_INTEGER, 1,
+                    ACPI_RTYPE_REFERENCE,0,0),
+
+    {{"_REG",   METHOD_2ARGS (ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_REV",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_RMV",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_ROM",   METHOD_2ARGS (ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_RST",   METHOD_0ARGS,                          /* ACPI 6.0 */
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_RTV",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    /*
+     * For _S0_ through _S5_, the ACPI spec defines a return Package
+     * containing 1 Integer, but most DSDTs have it wrong - 2,3, or 4 integers.
+     * Allow this by making the objects "Variable-length length", but all elements
+     * must be Integers.
+     */
+    {{"_S0_",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (1 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER, 1,0,0,0),
+
+    {{"_S1_",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (1 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER, 1,0,0,0),
+
+    {{"_S2_",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (1 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER, 1,0,0,0),
+
+    {{"_S3_",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (1 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER, 1,0,0,0),
+
+    {{"_S4_",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (1 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER, 1,0,0,0),
+
+    {{"_S5_",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (1 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_INTEGER, 1,0,0,0),
+
+    {{"_S1D",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_S2D",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_S3D",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_S4D",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_S0W",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_S1W",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_S2W",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_S3W",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_S4W",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_SBS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_SCP",   METHOD_1ARGS (ACPI_TYPE_INTEGER) | ARG_COUNT_IS_MINIMUM,
+                METHOD_NO_RETURN_VALUE}},   /* Acpi 1.0 allowed 1 integer arg. Acpi 3.0 expanded to 3 args. Allow both. */
+
+    {{"_SDD",   METHOD_1ARGS (ACPI_TYPE_BUFFER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_SEG",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_SHL",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_SLI",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_SPD",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_SRS",   METHOD_1ARGS (ACPI_TYPE_BUFFER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_SRT",   METHOD_1ARGS (ACPI_TYPE_BUFFER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_SRV",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}}, /* See IPMI spec */
+
+    {{"_SST",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_STA",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_STM",   METHOD_3ARGS (ACPI_TYPE_BUFFER, ACPI_TYPE_BUFFER, ACPI_TYPE_BUFFER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_STP",   METHOD_2ARGS (ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_STR",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_STV",   METHOD_2ARGS (ACPI_TYPE_INTEGER, ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_SUB",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_STRING)}},
+
+    {{"_SUN",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_SWS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TC1",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TC2",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TDL",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TFP",   METHOD_0ARGS,                          /* ACPI 6.0 */
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TIP",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TIV",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TMP",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TPC",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TPT",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_TRT",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each 2 Ref/6 Int */
+                    PACKAGE_INFO (ACPI_PTYPE2, ACPI_RTYPE_REFERENCE, 2, ACPI_RTYPE_INTEGER, 6, 0),
+
+    {{"_TSD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each 5 Int with count */
+                    PACKAGE_INFO (ACPI_PTYPE2_COUNT,ACPI_RTYPE_INTEGER, 5,0,0,0),
+
+    {{"_TSN",   METHOD_0ARGS,                          /* ACPI 6.0 */
+                METHOD_RETURNS (ACPI_RTYPE_REFERENCE)}},
+
+    {{"_TSP",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TSS",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Pkgs) each 5 Int */
+                    PACKAGE_INFO (ACPI_PTYPE2, ACPI_RTYPE_INTEGER, 5,0,0,0),
+
+    {{"_TST",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_TTS",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_NO_RETURN_VALUE}},
+
+    {{"_TZD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Variable-length (Refs) */
+                    PACKAGE_INFO (ACPI_PTYPE1_VAR, ACPI_RTYPE_REFERENCE, 0,0,0,0),
+
+    {{"_TZM",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_REFERENCE)}},
+
+    {{"_TZP",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_UID",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING)}},
+
+    {{"_UPC",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_PACKAGE)}}, /* Fixed-length (4 Int) */
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 4,0,0,0),
+
+    {{"_UPD",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_UPP",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    {{"_VPO",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER)}},
+
+    /* Acpi 1.0 defined _WAK with no return value. Later, it was changed to return a package */
+
+    {{"_WAK",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_NONE | ACPI_RTYPE_INTEGER | ACPI_RTYPE_PACKAGE)}},
+                    PACKAGE_INFO (ACPI_PTYPE1_FIXED, ACPI_RTYPE_INTEGER, 2,0,0,0), /* Fixed-length (2 Int), but is optional */
+
+    /* _WDG/_WED are MS extensions defined by "Windows Instrumentation" */
+
+    {{"_WDG",   METHOD_0ARGS,
+                METHOD_RETURNS (ACPI_RTYPE_BUFFER)}},
+
+    {{"_WED",   METHOD_1ARGS (ACPI_TYPE_INTEGER),
+                METHOD_RETURNS (ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER)}},
+
+    PACKAGE_INFO (0,0,0,0,0,0) /* Table terminator */
+};
+#else
+extern const ACPI_PREDEFINED_INFO       AcpiGbl_PredefinedMethods[];
+#endif
+
+
+#if (defined ACPI_CREATE_RESOURCE_TABLE && defined ACPI_APPLICATION)
+/******************************************************************************
+ *
+ * Predefined names for use in Resource Descriptors. These names do not
+ * appear in the global Predefined Name table (since these names never
+ * appear in actual AML byte code, only in the original ASL)
+ *
+ * Note: Used by iASL compiler and AcpiHelp utility only.
+ *
+ *****************************************************************************/
+
+const ACPI_PREDEFINED_INFO      AcpiGbl_ResourceNames[] =
+{
+    {{"_ADR",   WIDTH_16 | WIDTH_64,            0}},
+    {{"_ALN",   WIDTH_8 | WIDTH_16 | WIDTH_32,  0}},
+    {{"_ASI",   WIDTH_8,                        0}},
+    {{"_ASZ",   WIDTH_8,                        0}},
+    {{"_ATT",   WIDTH_64,                       0}},
+    {{"_BAS",   WIDTH_16 | WIDTH_32,            0}},
+    {{"_BM_",   WIDTH_1,                        0}},
+    {{"_DBT",   WIDTH_16,                       0}},  /* Acpi 5.0 */
+    {{"_DEC",   WIDTH_1,                        0}},
+    {{"_DMA",   WIDTH_8,                        0}},
+    {{"_DPL",   WIDTH_1,                        0}},  /* Acpi 5.0 */
+    {{"_DRS",   WIDTH_16,                       0}},  /* Acpi 5.0 */
+    {{"_END",   WIDTH_1,                        0}},  /* Acpi 5.0 */
+    {{"_FLC",   WIDTH_2,                        0}},  /* Acpi 5.0 */
+    {{"_GRA",   WIDTH_ADDRESS,                  0}},
+    {{"_HE_",   WIDTH_1,                        0}},
+    {{"_INT",   WIDTH_16 | WIDTH_32,            0}},
+    {{"_IOR",   WIDTH_2,                        0}},  /* Acpi 5.0 */
+    {{"_LEN",   WIDTH_8 | WIDTH_ADDRESS,        0}},
+    {{"_LIN",   WIDTH_8,                        0}},  /* Acpi 5.0 */
+    {{"_LL_",   WIDTH_1,                        0}},
+    {{"_MAF",   WIDTH_1,                        0}},
+    {{"_MAX",   WIDTH_ADDRESS,                  0}},
+    {{"_MEM",   WIDTH_2,                        0}},
+    {{"_MIF",   WIDTH_1,                        0}},
+    {{"_MIN",   WIDTH_ADDRESS,                  0}},
+    {{"_MOD",   WIDTH_1,                        0}},  /* Acpi 5.0 */
+    {{"_MTP",   WIDTH_2,                        0}},
+    {{"_PAR",   WIDTH_8,                        0}},  /* Acpi 5.0 */
+    {{"_PHA",   WIDTH_1,                        0}},  /* Acpi 5.0 */
+    {{"_PIN",   WIDTH_16,                       0}},  /* Acpi 5.0 */
+    {{"_PPI",   WIDTH_8,                        0}},  /* Acpi 5.0 */
+    {{"_POL",   WIDTH_1 | WIDTH_2,              0}},  /* Acpi 5.0 */
+    {{"_RBO",   WIDTH_8,                        0}},
+    {{"_RBW",   WIDTH_8,                        0}},
+    {{"_RNG",   WIDTH_1,                        0}},
+    {{"_RT_",   WIDTH_8,                        0}},  /* Acpi 3.0 */
+    {{"_RW_",   WIDTH_1,                        0}},
+    {{"_RXL",   WIDTH_16,                       0}},  /* Acpi 5.0 */
+    {{"_SHR",   WIDTH_2,                        0}},
+    {{"_SIZ",   WIDTH_2,                        0}},
+    {{"_SLV",   WIDTH_1,                        0}},  /* Acpi 5.0 */
+    {{"_SPE",   WIDTH_32,                       0}},  /* Acpi 5.0 */
+    {{"_STB",   WIDTH_2,                        0}},  /* Acpi 5.0 */
+    {{"_TRA",   WIDTH_ADDRESS,                  0}},
+    {{"_TRS",   WIDTH_1,                        0}},
+    {{"_TSF",   WIDTH_8,                        0}},  /* Acpi 3.0 */
+    {{"_TTP",   WIDTH_1,                        0}},
+    {{"_TXL",   WIDTH_16,                       0}},  /* Acpi 5.0 */
+    {{"_TYP",   WIDTH_2 | WIDTH_16,             0}},
+    {{"_VEN",   VARIABLE_DATA,                  0}},  /* Acpi 5.0 */
+    PACKAGE_INFO (0,0,0,0,0,0) /* Table terminator */
+};
+
+static const ACPI_PREDEFINED_INFO      AcpiGbl_ScopeNames[] = {
+    {{"_GPE",     0,      0}},
+    {{"_PR_",     0,      0}},
+    {{"_SB_",     0,      0}},
+    {{"_SI_",     0,      0}},
+    {{"_TZ_",     0,      0}},
+    PACKAGE_INFO (0,0,0,0,0,0) /* Table terminator */
+};
+#else
+extern const ACPI_PREDEFINED_INFO      AcpiGbl_ResourceNames[];
+#endif
+
+#endif

+ 442 - 0
kernel/include/acpica/acresrc.h

@@ -0,0 +1,442 @@
+/******************************************************************************
+ *
+ * Name: acresrc.h - Resource Manager function prototypes
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACRESRC_H__
+#define __ACRESRC_H__
+
+/* Need the AML resource descriptor structs */
+
+#include "amlresrc.h"
+
+
+/*
+ * If possible, pack the following structures to byte alignment, since we
+ * don't care about performance for debug output. Two cases where we cannot
+ * pack the structures:
+ *
+ * 1) Hardware does not support misaligned memory transfers
+ * 2) Compiler does not support pointers within packed structures
+ */
+#if (!defined(ACPI_MISALIGNMENT_NOT_SUPPORTED) && !defined(ACPI_PACKED_POINTERS_NOT_SUPPORTED))
+#pragma pack(1)
+#endif
+
+/*
+ * Individual entry for the resource conversion tables
+ */
+typedef const struct acpi_rsconvert_info
+{
+    UINT8                   Opcode;
+    UINT8                   ResourceOffset;
+    UINT8                   AmlOffset;
+    UINT8                   Value;
+
+} ACPI_RSCONVERT_INFO;
+
+/* Resource conversion opcodes */
+
+typedef enum
+{
+    ACPI_RSC_INITGET        = 0,
+    ACPI_RSC_INITSET,
+    ACPI_RSC_FLAGINIT,
+    ACPI_RSC_1BITFLAG,
+    ACPI_RSC_2BITFLAG,
+    ACPI_RSC_3BITFLAG,
+    ACPI_RSC_ADDRESS,
+    ACPI_RSC_BITMASK,
+    ACPI_RSC_BITMASK16,
+    ACPI_RSC_COUNT,
+    ACPI_RSC_COUNT16,
+    ACPI_RSC_COUNT_GPIO_PIN,
+    ACPI_RSC_COUNT_GPIO_RES,
+    ACPI_RSC_COUNT_GPIO_VEN,
+    ACPI_RSC_COUNT_SERIAL_RES,
+    ACPI_RSC_COUNT_SERIAL_VEN,
+    ACPI_RSC_DATA8,
+    ACPI_RSC_EXIT_EQ,
+    ACPI_RSC_EXIT_LE,
+    ACPI_RSC_EXIT_NE,
+    ACPI_RSC_LENGTH,
+    ACPI_RSC_MOVE_GPIO_PIN,
+    ACPI_RSC_MOVE_GPIO_RES,
+    ACPI_RSC_MOVE_SERIAL_RES,
+    ACPI_RSC_MOVE_SERIAL_VEN,
+    ACPI_RSC_MOVE8,
+    ACPI_RSC_MOVE16,
+    ACPI_RSC_MOVE32,
+    ACPI_RSC_MOVE64,
+    ACPI_RSC_SET8,
+    ACPI_RSC_SOURCE,
+    ACPI_RSC_SOURCEX
+
+} ACPI_RSCONVERT_OPCODES;
+
+/* Resource Conversion sub-opcodes */
+
+#define ACPI_RSC_COMPARE_AML_LENGTH     0
+#define ACPI_RSC_COMPARE_VALUE          1
+
+#define ACPI_RSC_TABLE_SIZE(d)          (sizeof (d) / sizeof (ACPI_RSCONVERT_INFO))
+
+#define ACPI_RS_OFFSET(f)               (UINT8) ACPI_OFFSET (ACPI_RESOURCE,f)
+#define AML_OFFSET(f)                   (UINT8) ACPI_OFFSET (AML_RESOURCE,f)
+
+
+/*
+ * Individual entry for the resource dump tables
+ */
+typedef const struct acpi_rsdump_info
+{
+    UINT8                   Opcode;
+    UINT8                   Offset;
+    char                    *Name;
+    const char              **Pointer;
+
+} ACPI_RSDUMP_INFO;
+
+/* Values for the Opcode field above */
+
+typedef enum
+{
+    ACPI_RSD_TITLE          = 0,
+    ACPI_RSD_1BITFLAG,
+    ACPI_RSD_2BITFLAG,
+    ACPI_RSD_3BITFLAG,
+    ACPI_RSD_ADDRESS,
+    ACPI_RSD_DWORDLIST,
+    ACPI_RSD_LITERAL,
+    ACPI_RSD_LONGLIST,
+    ACPI_RSD_SHORTLIST,
+    ACPI_RSD_SHORTLISTX,
+    ACPI_RSD_SOURCE,
+    ACPI_RSD_STRING,
+    ACPI_RSD_UINT8,
+    ACPI_RSD_UINT16,
+    ACPI_RSD_UINT32,
+    ACPI_RSD_UINT64,
+    ACPI_RSD_WORDLIST
+
+} ACPI_RSDUMP_OPCODES;
+
+/* restore default alignment */
+
+#pragma pack()
+
+
+/* Resource tables indexed by internal resource type */
+
+extern const UINT8              AcpiGbl_AmlResourceSizes[];
+extern const UINT8              AcpiGbl_AmlResourceSerialBusSizes[];
+extern ACPI_RSCONVERT_INFO      *AcpiGbl_SetResourceDispatch[];
+
+/* Resource tables indexed by raw AML resource descriptor type */
+
+extern const UINT8              AcpiGbl_ResourceStructSizes[];
+extern const UINT8              AcpiGbl_ResourceStructSerialBusSizes[];
+extern ACPI_RSCONVERT_INFO      *AcpiGbl_GetResourceDispatch[];
+
+extern ACPI_RSCONVERT_INFO      *AcpiGbl_ConvertResourceSerialBusDispatch[];
+
+typedef struct acpi_vendor_walk_info
+{
+    ACPI_VENDOR_UUID        *Uuid;
+    ACPI_BUFFER             *Buffer;
+    ACPI_STATUS             Status;
+
+} ACPI_VENDOR_WALK_INFO;
+
+
+/*
+ * rscreate
+ */
+ACPI_STATUS
+AcpiRsCreateResourceList (
+    ACPI_OPERAND_OBJECT     *AmlBuffer,
+    ACPI_BUFFER             *OutputBuffer);
+
+ACPI_STATUS
+AcpiRsCreateAmlResources (
+    ACPI_BUFFER             *ResourceList,
+    ACPI_BUFFER             *OutputBuffer);
+
+ACPI_STATUS
+AcpiRsCreatePciRoutingTable (
+    ACPI_OPERAND_OBJECT     *PackageObject,
+    ACPI_BUFFER             *OutputBuffer);
+
+
+/*
+ * rsutils
+ */
+ACPI_STATUS
+AcpiRsGetPrtMethodData (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_BUFFER             *RetBuffer);
+
+ACPI_STATUS
+AcpiRsGetCrsMethodData (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_BUFFER             *RetBuffer);
+
+ACPI_STATUS
+AcpiRsGetPrsMethodData (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_BUFFER             *RetBuffer);
+
+ACPI_STATUS
+AcpiRsGetMethodData (
+    ACPI_HANDLE             Handle,
+    char                    *Path,
+    ACPI_BUFFER             *RetBuffer);
+
+ACPI_STATUS
+AcpiRsSetSrsMethodData (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_BUFFER             *RetBuffer);
+
+ACPI_STATUS
+AcpiRsGetAeiMethodData (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_BUFFER             *RetBuffer);
+
+/*
+ * rscalc
+ */
+ACPI_STATUS
+AcpiRsGetListLength (
+    UINT8                   *AmlBuffer,
+    UINT32                  AmlBufferLength,
+    ACPI_SIZE               *SizeNeeded);
+
+ACPI_STATUS
+AcpiRsGetAmlLength (
+    ACPI_RESOURCE           *ResourceList,
+    ACPI_SIZE               ResourceListSize,
+    ACPI_SIZE               *SizeNeeded);
+
+ACPI_STATUS
+AcpiRsGetPciRoutingTableLength (
+    ACPI_OPERAND_OBJECT     *PackageObject,
+    ACPI_SIZE               *BufferSizeNeeded);
+
+ACPI_STATUS
+AcpiRsConvertAmlToResources (
+    UINT8                   *Aml,
+    UINT32                  Length,
+    UINT32                  Offset,
+    UINT8                   ResourceIndex,
+    void                    **Context);
+
+ACPI_STATUS
+AcpiRsConvertResourcesToAml (
+    ACPI_RESOURCE           *Resource,
+    ACPI_SIZE               AmlSizeNeeded,
+    UINT8                   *OutputBuffer);
+
+
+/*
+ * rsaddr
+ */
+void
+AcpiRsSetAddressCommon (
+    AML_RESOURCE            *Aml,
+    ACPI_RESOURCE           *Resource);
+
+BOOLEAN
+AcpiRsGetAddressCommon (
+    ACPI_RESOURCE           *Resource,
+    AML_RESOURCE            *Aml);
+
+
+/*
+ * rsmisc
+ */
+ACPI_STATUS
+AcpiRsConvertAmlToResource (
+    ACPI_RESOURCE           *Resource,
+    AML_RESOURCE            *Aml,
+    ACPI_RSCONVERT_INFO     *Info);
+
+ACPI_STATUS
+AcpiRsConvertResourceToAml (
+    ACPI_RESOURCE           *Resource,
+    AML_RESOURCE            *Aml,
+    ACPI_RSCONVERT_INFO     *Info);
+
+
+/*
+ * rsutils
+ */
+void
+AcpiRsMoveData (
+    void                    *Destination,
+    void                    *Source,
+    UINT16                  ItemCount,
+    UINT8                   MoveType);
+
+UINT8
+AcpiRsDecodeBitmask (
+    UINT16                  Mask,
+    UINT8                   *List);
+
+UINT16
+AcpiRsEncodeBitmask (
+    UINT8                   *List,
+    UINT8                   Count);
+
+ACPI_RS_LENGTH
+AcpiRsGetResourceSource (
+    ACPI_RS_LENGTH          ResourceLength,
+    ACPI_RS_LENGTH          MinimumLength,
+    ACPI_RESOURCE_SOURCE    *ResourceSource,
+    AML_RESOURCE            *Aml,
+    char                    *StringPtr);
+
+ACPI_RSDESC_SIZE
+AcpiRsSetResourceSource (
+    AML_RESOURCE            *Aml,
+    ACPI_RS_LENGTH          MinimumLength,
+    ACPI_RESOURCE_SOURCE    *ResourceSource);
+
+void
+AcpiRsSetResourceHeader (
+    UINT8                   DescriptorType,
+    ACPI_RSDESC_SIZE        TotalLength,
+    AML_RESOURCE            *Aml);
+
+void
+AcpiRsSetResourceLength (
+    ACPI_RSDESC_SIZE        TotalLength,
+    AML_RESOURCE            *Aml);
+
+
+/*
+ * rsdump - Debugger support
+ */
+#ifdef ACPI_DEBUGGER
+void
+AcpiRsDumpResourceList (
+    ACPI_RESOURCE           *Resource);
+
+void
+AcpiRsDumpIrqList (
+    UINT8                   *RouteTable);
+#endif
+
+
+/*
+ * Resource conversion tables
+ */
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertDma[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertEndDpf[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertIo[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertFixedIo[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertEndTag[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertMemory24[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertGenericReg[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertMemory32[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertFixedMemory32[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertAddress32[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertAddress16[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertExtIrq[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertAddress64[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertExtAddress64[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertGpio[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertFixedDma[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertI2cSerialBus[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertSpiSerialBus[];
+extern ACPI_RSCONVERT_INFO      AcpiRsConvertUartSerialBus[];
+
+/* These resources require separate get/set tables */
+
+extern ACPI_RSCONVERT_INFO      AcpiRsGetIrq[];
+extern ACPI_RSCONVERT_INFO      AcpiRsGetStartDpf[];
+extern ACPI_RSCONVERT_INFO      AcpiRsGetVendorSmall[];
+extern ACPI_RSCONVERT_INFO      AcpiRsGetVendorLarge[];
+
+extern ACPI_RSCONVERT_INFO      AcpiRsSetIrq[];
+extern ACPI_RSCONVERT_INFO      AcpiRsSetStartDpf[];
+extern ACPI_RSCONVERT_INFO      AcpiRsSetVendor[];
+
+
+#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
+/*
+ * rsinfo
+ */
+extern ACPI_RSDUMP_INFO         *AcpiGbl_DumpResourceDispatch[];
+extern ACPI_RSDUMP_INFO         *AcpiGbl_DumpSerialBusDispatch[];
+
+/*
+ * rsdumpinfo
+ */
+extern ACPI_RSDUMP_INFO         AcpiRsDumpIrq[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpPrt[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpDma[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpStartDpf[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpEndDpf[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpIo[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpIoFlags[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpFixedIo[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpVendor[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpEndTag[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpMemory24[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpMemory32[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpMemoryFlags[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpFixedMemory32[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpAddress16[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpAddress32[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpAddress64[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpExtAddress64[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpExtIrq[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpGenericReg[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpGpio[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpFixedDma[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpCommonSerialBus[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpI2cSerialBus[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpSpiSerialBus[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpUartSerialBus[];
+extern ACPI_RSDUMP_INFO         AcpiRsDumpGeneralFlags[];
+#endif
+
+#endif  /* __ACRESRC_H__ */

+ 714 - 0
kernel/include/acpica/acrestyp.h

@@ -0,0 +1,714 @@
+/******************************************************************************
+ *
+ * Name: acrestyp.h - Defines, types, and structures for resource descriptors
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACRESTYP_H__
+#define __ACRESTYP_H__
+
+
+/*
+ * Definitions for Resource Attributes
+ */
+typedef UINT16                          ACPI_RS_LENGTH;    /* Resource Length field is fixed at 16 bits */
+typedef UINT32                          ACPI_RSDESC_SIZE;  /* Max Resource Descriptor size is (Length+3) = (64K-1)+3 */
+
+/*
+ * Memory Attributes
+ */
+#define ACPI_READ_ONLY_MEMORY           (UINT8) 0x00
+#define ACPI_READ_WRITE_MEMORY          (UINT8) 0x01
+
+#define ACPI_NON_CACHEABLE_MEMORY       (UINT8) 0x00
+#define ACPI_CACHABLE_MEMORY            (UINT8) 0x01
+#define ACPI_WRITE_COMBINING_MEMORY     (UINT8) 0x02
+#define ACPI_PREFETCHABLE_MEMORY        (UINT8) 0x03
+
+/*! [Begin] no source code translation */
+/*
+ * IO Attributes
+ * The ISA IO ranges are:     n000-n0FFh,  n400-n4FFh, n800-n8FFh, nC00-nCFFh.
+ * The non-ISA IO ranges are: n100-n3FFh,  n500-n7FFh, n900-nBFFh, nCD0-nFFFh.
+ */
+/*! [End] no source code translation !*/
+
+#define ACPI_NON_ISA_ONLY_RANGES        (UINT8) 0x01
+#define ACPI_ISA_ONLY_RANGES            (UINT8) 0x02
+#define ACPI_ENTIRE_RANGE               (ACPI_NON_ISA_ONLY_RANGES | ACPI_ISA_ONLY_RANGES)
+
+/* Type of translation - 1=Sparse, 0=Dense */
+
+#define ACPI_SPARSE_TRANSLATION         (UINT8) 0x01
+
+/*
+ * IO Port Descriptor Decode
+ */
+#define ACPI_DECODE_10                  (UINT8) 0x00    /* 10-bit IO address decode */
+#define ACPI_DECODE_16                  (UINT8) 0x01    /* 16-bit IO address decode */
+
+/*
+ * Interrupt attributes - used in multiple descriptors
+ */
+
+/* Triggering */
+
+#define ACPI_LEVEL_SENSITIVE            (UINT8) 0x00
+#define ACPI_EDGE_SENSITIVE             (UINT8) 0x01
+
+/* Polarity */
+
+#define ACPI_ACTIVE_HIGH                (UINT8) 0x00
+#define ACPI_ACTIVE_LOW                 (UINT8) 0x01
+#define ACPI_ACTIVE_BOTH                (UINT8) 0x02
+
+/* Sharing */
+
+#define ACPI_EXCLUSIVE                  (UINT8) 0x00
+#define ACPI_SHARED                     (UINT8) 0x01
+
+/* Wake */
+
+#define ACPI_NOT_WAKE_CAPABLE           (UINT8) 0x00
+#define ACPI_WAKE_CAPABLE               (UINT8) 0x01
+
+/*
+ * DMA Attributes
+ */
+#define ACPI_COMPATIBILITY              (UINT8) 0x00
+#define ACPI_TYPE_A                     (UINT8) 0x01
+#define ACPI_TYPE_B                     (UINT8) 0x02
+#define ACPI_TYPE_F                     (UINT8) 0x03
+
+#define ACPI_NOT_BUS_MASTER             (UINT8) 0x00
+#define ACPI_BUS_MASTER                 (UINT8) 0x01
+
+#define ACPI_TRANSFER_8                 (UINT8) 0x00
+#define ACPI_TRANSFER_8_16              (UINT8) 0x01
+#define ACPI_TRANSFER_16                (UINT8) 0x02
+
+/*
+ * Start Dependent Functions Priority definitions
+ */
+#define ACPI_GOOD_CONFIGURATION         (UINT8) 0x00
+#define ACPI_ACCEPTABLE_CONFIGURATION   (UINT8) 0x01
+#define ACPI_SUB_OPTIMAL_CONFIGURATION  (UINT8) 0x02
+
+/*
+ * 16, 32 and 64-bit Address Descriptor resource types
+ */
+#define ACPI_MEMORY_RANGE               (UINT8) 0x00
+#define ACPI_IO_RANGE                   (UINT8) 0x01
+#define ACPI_BUS_NUMBER_RANGE           (UINT8) 0x02
+
+#define ACPI_ADDRESS_NOT_FIXED          (UINT8) 0x00
+#define ACPI_ADDRESS_FIXED              (UINT8) 0x01
+
+#define ACPI_POS_DECODE                 (UINT8) 0x00
+#define ACPI_SUB_DECODE                 (UINT8) 0x01
+
+/* Producer/Consumer */
+
+#define ACPI_PRODUCER                   (UINT8) 0x00
+#define ACPI_CONSUMER                   (UINT8) 0x01
+
+
+/*
+ * If possible, pack the following structures to byte alignment
+ */
+#ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
+#pragma pack(1)
+#endif
+
+/* UUID data structures for use in vendor-defined resource descriptors */
+
+typedef struct acpi_uuid
+{
+    UINT8                           Data[ACPI_UUID_LENGTH];
+} ACPI_UUID;
+
+typedef struct acpi_vendor_uuid
+{
+    UINT8                           Subtype;
+    UINT8                           Data[ACPI_UUID_LENGTH];
+
+} ACPI_VENDOR_UUID;
+
+/*
+ * Structures used to describe device resources
+ */
+typedef struct acpi_resource_irq
+{
+    UINT8                           DescriptorLength;
+    UINT8                           Triggering;
+    UINT8                           Polarity;
+    UINT8                           Sharable;
+    UINT8                           WakeCapable;
+    UINT8                           InterruptCount;
+    UINT8                           Interrupts[1];
+
+} ACPI_RESOURCE_IRQ;
+
+typedef struct acpi_resource_dma
+{
+    UINT8                           Type;
+    UINT8                           BusMaster;
+    UINT8                           Transfer;
+    UINT8                           ChannelCount;
+    UINT8                           Channels[1];
+
+} ACPI_RESOURCE_DMA;
+
+typedef struct acpi_resource_start_dependent
+{
+    UINT8                           DescriptorLength;
+    UINT8                           CompatibilityPriority;
+    UINT8                           PerformanceRobustness;
+
+} ACPI_RESOURCE_START_DEPENDENT;
+
+
+/*
+ * The END_DEPENDENT_FUNCTIONS_RESOURCE struct is not
+ * needed because it has no fields
+ */
+
+
+typedef struct acpi_resource_io
+{
+    UINT8                           IoDecode;
+    UINT8                           Alignment;
+    UINT8                           AddressLength;
+    UINT16                          Minimum;
+    UINT16                          Maximum;
+
+} ACPI_RESOURCE_IO;
+
+typedef struct acpi_resource_fixed_io
+{
+    UINT16                          Address;
+    UINT8                           AddressLength;
+
+} ACPI_RESOURCE_FIXED_IO;
+
+typedef struct acpi_resource_fixed_dma
+{
+    UINT16                          RequestLines;
+    UINT16                          Channels;
+    UINT8                           Width;
+
+} ACPI_RESOURCE_FIXED_DMA;
+
+/* Values for Width field above */
+
+#define ACPI_DMA_WIDTH8                         0
+#define ACPI_DMA_WIDTH16                        1
+#define ACPI_DMA_WIDTH32                        2
+#define ACPI_DMA_WIDTH64                        3
+#define ACPI_DMA_WIDTH128                       4
+#define ACPI_DMA_WIDTH256                       5
+
+
+typedef struct acpi_resource_vendor
+{
+    UINT16                          ByteLength;
+    UINT8                           ByteData[1];
+
+} ACPI_RESOURCE_VENDOR;
+
+/* Vendor resource with UUID info (introduced in ACPI 3.0) */
+
+typedef struct acpi_resource_vendor_typed
+{
+    UINT16                          ByteLength;
+    UINT8                           UuidSubtype;
+    UINT8                           Uuid[ACPI_UUID_LENGTH];
+    UINT8                           ByteData[1];
+
+} ACPI_RESOURCE_VENDOR_TYPED;
+
+typedef struct acpi_resource_end_tag
+{
+    UINT8                           Checksum;
+
+} ACPI_RESOURCE_END_TAG;
+
+typedef struct acpi_resource_memory24
+{
+    UINT8                           WriteProtect;
+    UINT16                          Minimum;
+    UINT16                          Maximum;
+    UINT16                          Alignment;
+    UINT16                          AddressLength;
+
+} ACPI_RESOURCE_MEMORY24;
+
+typedef struct acpi_resource_memory32
+{
+    UINT8                           WriteProtect;
+    UINT32                          Minimum;
+    UINT32                          Maximum;
+    UINT32                          Alignment;
+    UINT32                          AddressLength;
+
+} ACPI_RESOURCE_MEMORY32;
+
+typedef struct acpi_resource_fixed_memory32
+{
+    UINT8                           WriteProtect;
+    UINT32                          Address;
+    UINT32                          AddressLength;
+
+} ACPI_RESOURCE_FIXED_MEMORY32;
+
+typedef struct acpi_memory_attribute
+{
+    UINT8                           WriteProtect;
+    UINT8                           Caching;
+    UINT8                           RangeType;
+    UINT8                           Translation;
+
+} ACPI_MEMORY_ATTRIBUTE;
+
+typedef struct acpi_io_attribute
+{
+    UINT8                           RangeType;
+    UINT8                           Translation;
+    UINT8                           TranslationType;
+    UINT8                           Reserved1;
+
+} ACPI_IO_ATTRIBUTE;
+
+typedef union acpi_resource_attribute
+{
+    ACPI_MEMORY_ATTRIBUTE           Mem;
+    ACPI_IO_ATTRIBUTE               Io;
+
+    /* Used for the *WordSpace macros */
+
+    UINT8                           TypeSpecific;
+
+} ACPI_RESOURCE_ATTRIBUTE;
+
+typedef struct acpi_resource_source
+{
+    UINT8                           Index;
+    UINT16                          StringLength;
+    char                            *StringPtr;
+
+} ACPI_RESOURCE_SOURCE;
+
+/* Fields common to all address descriptors, 16/32/64 bit */
+
+#define ACPI_RESOURCE_ADDRESS_COMMON \
+    UINT8                           ResourceType; \
+    UINT8                           ProducerConsumer; \
+    UINT8                           Decode; \
+    UINT8                           MinAddressFixed; \
+    UINT8                           MaxAddressFixed; \
+    ACPI_RESOURCE_ATTRIBUTE         Info;
+
+typedef struct acpi_address16_attribute
+{
+    UINT16                          Granularity;
+    UINT16                          Minimum;
+    UINT16                          Maximum;
+    UINT16                          TranslationOffset;
+    UINT16                          AddressLength;
+
+} ACPI_ADDRESS16_ATTRIBUTE;
+
+typedef struct acpi_address32_attribute
+{
+    UINT32                          Granularity;
+    UINT32                          Minimum;
+    UINT32                          Maximum;
+    UINT32                          TranslationOffset;
+    UINT32                          AddressLength;
+
+} ACPI_ADDRESS32_ATTRIBUTE;
+
+typedef struct acpi_address64_attribute
+{
+    UINT64                          Granularity;
+    UINT64                          Minimum;
+    UINT64                          Maximum;
+    UINT64                          TranslationOffset;
+    UINT64                          AddressLength;
+
+} ACPI_ADDRESS64_ATTRIBUTE;
+
+typedef struct acpi_resource_address
+{
+    ACPI_RESOURCE_ADDRESS_COMMON
+
+} ACPI_RESOURCE_ADDRESS;
+
+typedef struct acpi_resource_address16
+{
+    ACPI_RESOURCE_ADDRESS_COMMON
+    ACPI_ADDRESS16_ATTRIBUTE        Address;
+    ACPI_RESOURCE_SOURCE            ResourceSource;
+
+} ACPI_RESOURCE_ADDRESS16;
+
+typedef struct acpi_resource_address32
+{
+    ACPI_RESOURCE_ADDRESS_COMMON
+    ACPI_ADDRESS32_ATTRIBUTE        Address;
+    ACPI_RESOURCE_SOURCE            ResourceSource;
+
+} ACPI_RESOURCE_ADDRESS32;
+
+typedef struct acpi_resource_address64
+{
+    ACPI_RESOURCE_ADDRESS_COMMON
+    ACPI_ADDRESS64_ATTRIBUTE        Address;
+    ACPI_RESOURCE_SOURCE            ResourceSource;
+
+} ACPI_RESOURCE_ADDRESS64;
+
+typedef struct acpi_resource_extended_address64
+{
+    ACPI_RESOURCE_ADDRESS_COMMON
+    UINT8                           RevisionID;
+    ACPI_ADDRESS64_ATTRIBUTE        Address;
+    UINT64                          TypeSpecific;
+
+} ACPI_RESOURCE_EXTENDED_ADDRESS64;
+
+typedef struct acpi_resource_extended_irq
+{
+    UINT8                           ProducerConsumer;
+    UINT8                           Triggering;
+    UINT8                           Polarity;
+    UINT8                           Sharable;
+    UINT8                           WakeCapable;
+    UINT8                           InterruptCount;
+    ACPI_RESOURCE_SOURCE            ResourceSource;
+    UINT32                          Interrupts[1];
+
+} ACPI_RESOURCE_EXTENDED_IRQ;
+
+typedef struct acpi_resource_generic_register
+{
+    UINT8                           SpaceId;
+    UINT8                           BitWidth;
+    UINT8                           BitOffset;
+    UINT8                           AccessSize;
+    UINT64                          Address;
+
+} ACPI_RESOURCE_GENERIC_REGISTER;
+
+typedef struct acpi_resource_gpio
+{
+    UINT8                           RevisionId;
+    UINT8                           ConnectionType;
+    UINT8                           ProducerConsumer;   /* For values, see Producer/Consumer above */
+    UINT8                           PinConfig;
+    UINT8                           Sharable;           /* For values, see Interrupt Attributes above */
+    UINT8                           WakeCapable;        /* For values, see Interrupt Attributes above */
+    UINT8                           IoRestriction;
+    UINT8                           Triggering;         /* For values, see Interrupt Attributes above */
+    UINT8                           Polarity;           /* For values, see Interrupt Attributes above */
+    UINT16                          DriveStrength;
+    UINT16                          DebounceTimeout;
+    UINT16                          PinTableLength;
+    UINT16                          VendorLength;
+    ACPI_RESOURCE_SOURCE            ResourceSource;
+    UINT16                          *PinTable;
+    UINT8                           *VendorData;
+
+} ACPI_RESOURCE_GPIO;
+
+/* Values for GPIO ConnectionType field above */
+
+#define ACPI_RESOURCE_GPIO_TYPE_INT             0
+#define ACPI_RESOURCE_GPIO_TYPE_IO              1
+
+/* Values for PinConfig field above */
+
+#define ACPI_PIN_CONFIG_DEFAULT                 0
+#define ACPI_PIN_CONFIG_PULLUP                  1
+#define ACPI_PIN_CONFIG_PULLDOWN                2
+#define ACPI_PIN_CONFIG_NOPULL                  3
+
+/* Values for IoRestriction field above */
+
+#define ACPI_IO_RESTRICT_NONE                   0
+#define ACPI_IO_RESTRICT_INPUT                  1
+#define ACPI_IO_RESTRICT_OUTPUT                 2
+#define ACPI_IO_RESTRICT_NONE_PRESERVE          3
+
+
+/* Common structure for I2C, SPI, and UART serial descriptors */
+
+#define ACPI_RESOURCE_SERIAL_COMMON \
+    UINT8                           RevisionId; \
+    UINT8                           Type; \
+    UINT8                           ProducerConsumer;    /* For values, see Producer/Consumer above */\
+    UINT8                           SlaveMode; \
+    UINT8                           TypeRevisionId; \
+    UINT16                          TypeDataLength; \
+    UINT16                          VendorLength; \
+    ACPI_RESOURCE_SOURCE            ResourceSource; \
+    UINT8                           *VendorData;
+
+typedef struct acpi_resource_common_serialbus
+{
+    ACPI_RESOURCE_SERIAL_COMMON
+
+} ACPI_RESOURCE_COMMON_SERIALBUS;
+
+/* Values for the Type field above */
+
+#define ACPI_RESOURCE_SERIAL_TYPE_I2C           1
+#define ACPI_RESOURCE_SERIAL_TYPE_SPI           2
+#define ACPI_RESOURCE_SERIAL_TYPE_UART          3
+
+/* Values for SlaveMode field above */
+
+#define ACPI_CONTROLLER_INITIATED               0
+#define ACPI_DEVICE_INITIATED                   1
+
+
+typedef struct acpi_resource_i2c_serialbus
+{
+    ACPI_RESOURCE_SERIAL_COMMON
+    UINT8                           AccessMode;
+    UINT16                          SlaveAddress;
+    UINT32                          ConnectionSpeed;
+
+} ACPI_RESOURCE_I2C_SERIALBUS;
+
+/* Values for AccessMode field above */
+
+#define ACPI_I2C_7BIT_MODE                      0
+#define ACPI_I2C_10BIT_MODE                     1
+
+
+typedef struct acpi_resource_spi_serialbus
+{
+    ACPI_RESOURCE_SERIAL_COMMON
+    UINT8                           WireMode;
+    UINT8                           DevicePolarity;
+    UINT8                           DataBitLength;
+    UINT8                           ClockPhase;
+    UINT8                           ClockPolarity;
+    UINT16                          DeviceSelection;
+    UINT32                          ConnectionSpeed;
+
+} ACPI_RESOURCE_SPI_SERIALBUS;
+
+/* Values for WireMode field above */
+
+#define ACPI_SPI_4WIRE_MODE                     0
+#define ACPI_SPI_3WIRE_MODE                     1
+
+/* Values for DevicePolarity field above */
+
+#define ACPI_SPI_ACTIVE_LOW                     0
+#define ACPI_SPI_ACTIVE_HIGH                    1
+
+/* Values for ClockPhase field above */
+
+#define ACPI_SPI_FIRST_PHASE                    0
+#define ACPI_SPI_SECOND_PHASE                   1
+
+/* Values for ClockPolarity field above */
+
+#define ACPI_SPI_START_LOW                      0
+#define ACPI_SPI_START_HIGH                     1
+
+
+typedef struct acpi_resource_uart_serialbus
+{
+    ACPI_RESOURCE_SERIAL_COMMON
+    UINT8                           Endian;
+    UINT8                           DataBits;
+    UINT8                           StopBits;
+    UINT8                           FlowControl;
+    UINT8                           Parity;
+    UINT8                           LinesEnabled;
+    UINT16                          RxFifoSize;
+    UINT16                          TxFifoSize;
+    UINT32                          DefaultBaudRate;
+
+} ACPI_RESOURCE_UART_SERIALBUS;
+
+/* Values for Endian field above */
+
+#define ACPI_UART_LITTLE_ENDIAN                 0
+#define ACPI_UART_BIG_ENDIAN                    1
+
+/* Values for DataBits field above */
+
+#define ACPI_UART_5_DATA_BITS                   0
+#define ACPI_UART_6_DATA_BITS                   1
+#define ACPI_UART_7_DATA_BITS                   2
+#define ACPI_UART_8_DATA_BITS                   3
+#define ACPI_UART_9_DATA_BITS                   4
+
+/* Values for StopBits field above */
+
+#define ACPI_UART_NO_STOP_BITS                  0
+#define ACPI_UART_1_STOP_BIT                    1
+#define ACPI_UART_1P5_STOP_BITS                 2
+#define ACPI_UART_2_STOP_BITS                   3
+
+/* Values for FlowControl field above */
+
+#define ACPI_UART_FLOW_CONTROL_NONE             0
+#define ACPI_UART_FLOW_CONTROL_HW               1
+#define ACPI_UART_FLOW_CONTROL_XON_XOFF         2
+
+/* Values for Parity field above */
+
+#define ACPI_UART_PARITY_NONE                   0
+#define ACPI_UART_PARITY_EVEN                   1
+#define ACPI_UART_PARITY_ODD                    2
+#define ACPI_UART_PARITY_MARK                   3
+#define ACPI_UART_PARITY_SPACE                  4
+
+/* Values for LinesEnabled bitfield above */
+
+#define ACPI_UART_CARRIER_DETECT                (1<<2)
+#define ACPI_UART_RING_INDICATOR                (1<<3)
+#define ACPI_UART_DATA_SET_READY                (1<<4)
+#define ACPI_UART_DATA_TERMINAL_READY           (1<<5)
+#define ACPI_UART_CLEAR_TO_SEND                 (1<<6)
+#define ACPI_UART_REQUEST_TO_SEND               (1<<7)
+
+
+/* ACPI_RESOURCE_TYPEs */
+
+#define ACPI_RESOURCE_TYPE_IRQ                  0
+#define ACPI_RESOURCE_TYPE_DMA                  1
+#define ACPI_RESOURCE_TYPE_START_DEPENDENT      2
+#define ACPI_RESOURCE_TYPE_END_DEPENDENT        3
+#define ACPI_RESOURCE_TYPE_IO                   4
+#define ACPI_RESOURCE_TYPE_FIXED_IO             5
+#define ACPI_RESOURCE_TYPE_VENDOR               6
+#define ACPI_RESOURCE_TYPE_END_TAG              7
+#define ACPI_RESOURCE_TYPE_MEMORY24             8
+#define ACPI_RESOURCE_TYPE_MEMORY32             9
+#define ACPI_RESOURCE_TYPE_FIXED_MEMORY32       10
+#define ACPI_RESOURCE_TYPE_ADDRESS16            11
+#define ACPI_RESOURCE_TYPE_ADDRESS32            12
+#define ACPI_RESOURCE_TYPE_ADDRESS64            13
+#define ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64   14  /* ACPI 3.0 */
+#define ACPI_RESOURCE_TYPE_EXTENDED_IRQ         15
+#define ACPI_RESOURCE_TYPE_GENERIC_REGISTER     16
+#define ACPI_RESOURCE_TYPE_GPIO                 17  /* ACPI 5.0 */
+#define ACPI_RESOURCE_TYPE_FIXED_DMA            18  /* ACPI 5.0 */
+#define ACPI_RESOURCE_TYPE_SERIAL_BUS           19  /* ACPI 5.0 */
+#define ACPI_RESOURCE_TYPE_MAX                  19
+
+/* Master union for resource descriptors */
+
+typedef union acpi_resource_data
+{
+    ACPI_RESOURCE_IRQ                       Irq;
+    ACPI_RESOURCE_DMA                       Dma;
+    ACPI_RESOURCE_START_DEPENDENT           StartDpf;
+    ACPI_RESOURCE_IO                        Io;
+    ACPI_RESOURCE_FIXED_IO                  FixedIo;
+    ACPI_RESOURCE_FIXED_DMA                 FixedDma;
+    ACPI_RESOURCE_VENDOR                    Vendor;
+    ACPI_RESOURCE_VENDOR_TYPED              VendorTyped;
+    ACPI_RESOURCE_END_TAG                   EndTag;
+    ACPI_RESOURCE_MEMORY24                  Memory24;
+    ACPI_RESOURCE_MEMORY32                  Memory32;
+    ACPI_RESOURCE_FIXED_MEMORY32            FixedMemory32;
+    ACPI_RESOURCE_ADDRESS16                 Address16;
+    ACPI_RESOURCE_ADDRESS32                 Address32;
+    ACPI_RESOURCE_ADDRESS64                 Address64;
+    ACPI_RESOURCE_EXTENDED_ADDRESS64        ExtAddress64;
+    ACPI_RESOURCE_EXTENDED_IRQ              ExtendedIrq;
+    ACPI_RESOURCE_GENERIC_REGISTER          GenericReg;
+    ACPI_RESOURCE_GPIO                      Gpio;
+    ACPI_RESOURCE_I2C_SERIALBUS             I2cSerialBus;
+    ACPI_RESOURCE_SPI_SERIALBUS             SpiSerialBus;
+    ACPI_RESOURCE_UART_SERIALBUS            UartSerialBus;
+    ACPI_RESOURCE_COMMON_SERIALBUS          CommonSerialBus;
+
+    /* Common fields */
+
+    ACPI_RESOURCE_ADDRESS                   Address;        /* Common 16/32/64 address fields */
+
+} ACPI_RESOURCE_DATA;
+
+
+/* Common resource header */
+
+typedef struct acpi_resource
+{
+    UINT32                          Type;
+    UINT32                          Length;
+    ACPI_RESOURCE_DATA              Data;
+
+} ACPI_RESOURCE;
+
+/* restore default alignment */
+
+#pragma pack()
+
+
+#define ACPI_RS_SIZE_NO_DATA                8       /* Id + Length fields */
+#define ACPI_RS_SIZE_MIN                    (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (12)
+#define ACPI_RS_SIZE(Type)                  (UINT32) (ACPI_RS_SIZE_NO_DATA + sizeof (Type))
+
+/* Macro for walking resource templates with multiple descriptors */
+
+#define ACPI_NEXT_RESOURCE(Res) \
+    ACPI_ADD_PTR (ACPI_RESOURCE, (Res), (Res)->Length)
+
+
+typedef struct acpi_pci_routing_table
+{
+    UINT32                          Length;
+    UINT32                          Pin;
+    UINT64                          Address;        /* here for 64-bit alignment */
+    UINT32                          SourceIndex;
+    char                            Source[4];      /* pad to 64 bits so sizeof() works in all cases */
+
+} ACPI_PCI_ROUTING_TABLE;
+
+#endif /* __ACRESTYP_H__ */

+ 269 - 0
kernel/include/acpica/acstruct.h

@@ -0,0 +1,269 @@
+/******************************************************************************
+ *
+ * Name: acstruct.h - Internal structs
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACSTRUCT_H__
+#define __ACSTRUCT_H__
+
+/* acpisrc:StructDefs -- for acpisrc conversion */
+
+/*****************************************************************************
+ *
+ * Tree walking typedefs and structs
+ *
+ ****************************************************************************/
+
+
+/*
+ * Walk state - current state of a parse tree walk. Used for both a leisurely
+ * stroll through the tree (for whatever reason), and for control method
+ * execution.
+ */
+#define ACPI_NEXT_OP_DOWNWARD       1
+#define ACPI_NEXT_OP_UPWARD         2
+
+/*
+ * Groups of definitions for WalkType used for different implementations of
+ * walkers (never simultaneously) - flags for interpreter:
+ */
+#define ACPI_WALK_NON_METHOD        0
+#define ACPI_WALK_METHOD            0x01
+#define ACPI_WALK_METHOD_RESTART    0x02
+
+
+typedef struct acpi_walk_state
+{
+    struct acpi_walk_state          *Next;              /* Next WalkState in list */
+    UINT8                           DescriptorType;     /* To differentiate various internal objs */
+    UINT8                           WalkType;
+    UINT16                          Opcode;             /* Current AML opcode */
+    UINT8                           NextOpInfo;         /* Info about NextOp */
+    UINT8                           NumOperands;        /* Stack pointer for Operands[] array */
+    UINT8                           OperandIndex;       /* Index into operand stack, to be used by AcpiDsObjStackPush */
+    ACPI_OWNER_ID                   OwnerId;            /* Owner of objects created during the walk */
+    BOOLEAN                         LastPredicate;      /* Result of last predicate */
+    UINT8                           CurrentResult;
+    UINT8                           ReturnUsed;
+    UINT8                           ScopeDepth;
+    UINT8                           PassNumber;         /* Parse pass during table load */
+    BOOLEAN                         NamespaceOverride;  /* Override existing objects */
+    UINT8                           ResultSize;         /* Total elements for the result stack */
+    UINT8                           ResultCount;        /* Current number of occupied elements of result stack */
+    UINT8                           *Aml;
+    UINT32                          ArgTypes;
+    UINT32                          MethodBreakpoint;   /* For single stepping */
+    UINT32                          UserBreakpoint;     /* User AML breakpoint */
+    UINT32                          ParseFlags;
+
+    ACPI_PARSE_STATE                ParserState;        /* Current state of parser */
+    UINT32                          PrevArgTypes;
+    UINT32                          ArgCount;           /* push for fixed or var args */
+
+    struct acpi_namespace_node      Arguments[ACPI_METHOD_NUM_ARGS];        /* Control method arguments */
+    struct acpi_namespace_node      LocalVariables[ACPI_METHOD_NUM_LOCALS]; /* Control method locals */
+    union acpi_operand_object       *Operands[ACPI_OBJ_NUM_OPERANDS + 1];   /* Operands passed to the interpreter (+1 for NULL terminator) */
+    union acpi_operand_object       **Params;
+
+    UINT8                           *AmlLastWhile;
+    union acpi_operand_object       **CallerReturnDesc;
+    ACPI_GENERIC_STATE              *ControlState;      /* List of control states (nested IFs) */
+    struct acpi_namespace_node      *DeferredNode;      /* Used when executing deferred opcodes */
+    union acpi_operand_object       *ImplicitReturnObj;
+    struct acpi_namespace_node      *MethodCallNode;    /* Called method Node*/
+    ACPI_PARSE_OBJECT               *MethodCallOp;      /* MethodCall Op if running a method */
+    union acpi_operand_object       *MethodDesc;        /* Method descriptor if running a method */
+    struct acpi_namespace_node      *MethodNode;        /* Method node if running a method. */
+    ACPI_PARSE_OBJECT               *Op;                /* Current parser op */
+    const ACPI_OPCODE_INFO          *OpInfo;            /* Info on current opcode */
+    ACPI_PARSE_OBJECT               *Origin;            /* Start of walk [Obsolete] */
+    union acpi_operand_object       *ResultObj;
+    ACPI_GENERIC_STATE              *Results;           /* Stack of accumulated results */
+    union acpi_operand_object       *ReturnDesc;        /* Return object, if any */
+    ACPI_GENERIC_STATE              *ScopeInfo;         /* Stack of nested scopes */
+    ACPI_PARSE_OBJECT               *PrevOp;            /* Last op that was processed */
+    ACPI_PARSE_OBJECT               *NextOp;            /* next op to be processed */
+    ACPI_THREAD_STATE               *Thread;
+    ACPI_PARSE_DOWNWARDS            DescendingCallback;
+    ACPI_PARSE_UPWARDS              AscendingCallback;
+
+} ACPI_WALK_STATE;
+
+
+/* Info used by AcpiNsInitializeObjects and AcpiDsInitializeObjects */
+
+typedef struct acpi_init_walk_info
+{
+    UINT32                          TableIndex;
+    UINT32                          ObjectCount;
+    UINT32                          MethodCount;
+    UINT32                          SerialMethodCount;
+    UINT32                          NonSerialMethodCount;
+    UINT32                          SerializedMethodCount;
+    UINT32                          DeviceCount;
+    UINT32                          OpRegionCount;
+    UINT32                          FieldCount;
+    UINT32                          BufferCount;
+    UINT32                          PackageCount;
+    UINT32                          OpRegionInit;
+    UINT32                          FieldInit;
+    UINT32                          BufferInit;
+    UINT32                          PackageInit;
+    ACPI_OWNER_ID                   OwnerId;
+
+} ACPI_INIT_WALK_INFO;
+
+
+typedef struct acpi_get_devices_info
+{
+    ACPI_WALK_CALLBACK              UserFunction;
+    void                            *Context;
+    char                            *Hid;
+
+} ACPI_GET_DEVICES_INFO;
+
+
+typedef union acpi_aml_operands
+{
+    ACPI_OPERAND_OBJECT             *Operands[7];
+
+    struct
+    {
+        ACPI_OBJECT_INTEGER             *Type;
+        ACPI_OBJECT_INTEGER             *Code;
+        ACPI_OBJECT_INTEGER             *Argument;
+
+    } Fatal;
+
+    struct
+    {
+        ACPI_OPERAND_OBJECT             *Source;
+        ACPI_OBJECT_INTEGER             *Index;
+        ACPI_OPERAND_OBJECT             *Target;
+
+    } Index;
+
+    struct
+    {
+        ACPI_OPERAND_OBJECT             *Source;
+        ACPI_OBJECT_INTEGER             *Index;
+        ACPI_OBJECT_INTEGER             *Length;
+        ACPI_OPERAND_OBJECT             *Target;
+
+    } Mid;
+
+} ACPI_AML_OPERANDS;
+
+
+/*
+ * Structure used to pass object evaluation information and parameters.
+ * Purpose is to reduce CPU stack use.
+ */
+typedef struct acpi_evaluate_info
+{
+    /* The first 3 elements are passed by the caller to AcpiNsEvaluate */
+
+    ACPI_NAMESPACE_NODE             *PrefixNode;        /* Input: starting node */
+    char                            *RelativePathname;  /* Input: path relative to PrefixNode */
+    ACPI_OPERAND_OBJECT             **Parameters;       /* Input: argument list */
+
+    ACPI_NAMESPACE_NODE             *Node;              /* Resolved node (PrefixNode:RelativePathname) */
+    ACPI_OPERAND_OBJECT             *ObjDesc;           /* Object attached to the resolved node */
+    char                            *FullPathname;      /* Full pathname of the resolved node */
+
+    const ACPI_PREDEFINED_INFO      *Predefined;        /* Used if Node is a predefined name */
+    ACPI_OPERAND_OBJECT             *ReturnObject;      /* Object returned from the evaluation */
+    union acpi_operand_object       *ParentPackage;     /* Used if return object is a Package */
+
+    UINT32                          ReturnFlags;        /* Used for return value analysis */
+    UINT32                          ReturnBtype;        /* Bitmapped type of the returned object */
+    UINT16                          ParamCount;         /* Count of the input argument list */
+    UINT8                           PassNumber;         /* Parser pass number */
+    UINT8                           ReturnObjectType;   /* Object type of the returned object */
+    UINT8                           NodeFlags;          /* Same as Node->Flags */
+    UINT8                           Flags;              /* General flags */
+
+} ACPI_EVALUATE_INFO;
+
+/* Values for Flags above */
+
+#define ACPI_IGNORE_RETURN_VALUE    1
+
+/* Defines for ReturnFlags field above */
+
+#define ACPI_OBJECT_REPAIRED        1
+#define ACPI_OBJECT_WRAPPED         2
+
+
+/* Info used by AcpiNsInitializeDevices */
+
+typedef struct acpi_device_walk_info
+{
+    ACPI_TABLE_DESC                 *TableDesc;
+    ACPI_EVALUATE_INFO              *EvaluateInfo;
+    UINT32                          DeviceCount;
+    UINT32                          Num_STA;
+    UINT32                          Num_INI;
+
+} ACPI_DEVICE_WALK_INFO;
+
+
+/* TBD: [Restructure] Merge with struct above */
+
+typedef struct acpi_walk_info
+{
+    UINT32                          DebugLevel;
+    UINT32                          Count;
+    ACPI_OWNER_ID                   OwnerId;
+    UINT8                           DisplayType;
+
+} ACPI_WALK_INFO;
+
+/* Display Types */
+
+#define ACPI_DISPLAY_SUMMARY        (UINT8) 0
+#define ACPI_DISPLAY_OBJECTS        (UINT8) 1
+#define ACPI_DISPLAY_MASK           (UINT8) 1
+
+#define ACPI_DISPLAY_SHORT          (UINT8) 2
+
+
+#endif

+ 261 - 0
kernel/include/acpica/actables.h

@@ -0,0 +1,261 @@
+/******************************************************************************
+ *
+ * Name: actables.h - ACPI table management
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACTABLES_H__
+#define __ACTABLES_H__
+
+
+ACPI_STATUS
+AcpiAllocateRootTable (
+    UINT32                  InitialTableCount);
+
+/*
+ * tbxfroot - Root pointer utilities
+ */
+UINT32
+AcpiTbGetRsdpLength (
+    ACPI_TABLE_RSDP         *Rsdp);
+
+ACPI_STATUS
+AcpiTbValidateRsdp (
+    ACPI_TABLE_RSDP         *Rsdp);
+
+UINT8 *
+AcpiTbScanMemoryForRsdp (
+    UINT8                   *StartAddress,
+    UINT32                  Length);
+
+
+/*
+ * tbdata - table data structure management
+ */
+ACPI_STATUS
+AcpiTbGetNextTableDescriptor (
+    UINT32                  *TableIndex,
+    ACPI_TABLE_DESC         **TableDesc);
+
+void
+AcpiTbInitTableDescriptor (
+    ACPI_TABLE_DESC         *TableDesc,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT8                   Flags,
+    ACPI_TABLE_HEADER       *Table);
+
+ACPI_STATUS
+AcpiTbAcquireTempTable (
+    ACPI_TABLE_DESC         *TableDesc,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT8                   Flags);
+
+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);
+
+void
+AcpiTbSetTableLoadedFlag (
+    UINT32                  TableIndex,
+    BOOLEAN                 IsLoaded);
+
+
+/*
+ * tbfadt - FADT parse/convert/validate
+ */
+void
+AcpiTbParseFadt (
+    void);
+
+void
+AcpiTbCreateLocalFadt (
+    ACPI_TABLE_HEADER       *Table,
+    UINT32                  Length);
+
+
+/*
+ * tbfind - find ACPI table
+ */
+ACPI_STATUS
+AcpiTbFindTable (
+    char                    *Signature,
+    char                    *OemId,
+    char                    *OemTableId,
+    UINT32                  *TableIndex);
+
+
+/*
+ * tbinstal - Table removal and deletion
+ */
+ACPI_STATUS
+AcpiTbResizeRootTableList (
+    void);
+
+ACPI_STATUS
+AcpiTbValidateTable (
+    ACPI_TABLE_DESC         *TableDesc);
+
+void
+AcpiTbInvalidateTable (
+    ACPI_TABLE_DESC         *TableDesc);
+
+void
+AcpiTbOverrideTable (
+    ACPI_TABLE_DESC         *OldTableDesc);
+
+ACPI_STATUS
+AcpiTbAcquireTable (
+    ACPI_TABLE_DESC         *TableDesc,
+    ACPI_TABLE_HEADER       **TablePtr,
+    UINT32                  *TableLength,
+    UINT8                   *TableFlags);
+
+void
+AcpiTbReleaseTable (
+    ACPI_TABLE_HEADER       *Table,
+    UINT32                  TableLength,
+    UINT8                   TableFlags);
+
+ACPI_STATUS
+AcpiTbInstallStandardTable (
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT8                   Flags,
+    BOOLEAN                 Reload,
+    BOOLEAN                 Override,
+    UINT32                  *TableIndex);
+
+void
+AcpiTbUninstallTable (
+    ACPI_TABLE_DESC        *TableDesc);
+
+void
+AcpiTbTerminate (
+    void);
+
+ACPI_STATUS
+AcpiTbDeleteNamespaceByOwner (
+    UINT32                  TableIndex);
+
+ACPI_STATUS
+AcpiTbAllocateOwnerId (
+    UINT32                  TableIndex);
+
+ACPI_STATUS
+AcpiTbReleaseOwnerId (
+    UINT32                  TableIndex);
+
+ACPI_STATUS
+AcpiTbGetOwnerId (
+    UINT32                  TableIndex,
+    ACPI_OWNER_ID           *OwnerId);
+
+
+/*
+ * tbutils - table manager utilities
+ */
+ACPI_STATUS
+AcpiTbInitializeFacs (
+    void);
+
+void
+AcpiTbPrintTableHeader(
+    ACPI_PHYSICAL_ADDRESS   Address,
+    ACPI_TABLE_HEADER       *Header);
+
+UINT8
+AcpiTbChecksum (
+    UINT8                   *Buffer,
+    UINT32                  Length);
+
+ACPI_STATUS
+AcpiTbVerifyChecksum (
+    ACPI_TABLE_HEADER       *Table,
+    UINT32                  Length);
+
+void
+AcpiTbCheckDsdtHeader (
+    void);
+
+ACPI_TABLE_HEADER *
+AcpiTbCopyDsdt (
+    UINT32                  TableIndex);
+
+void
+AcpiTbInstallTableWithOverride (
+    ACPI_TABLE_DESC         *NewTableDesc,
+    BOOLEAN                 Override,
+    UINT32                  *TableIndex);
+
+ACPI_STATUS
+AcpiTbInstallFixedTable (
+    ACPI_PHYSICAL_ADDRESS   Address,
+    char                    *Signature,
+    UINT32                  *TableIndex);
+
+ACPI_STATUS
+AcpiTbParseRootTable (
+    ACPI_PHYSICAL_ADDRESS   RsdpAddress);
+
+BOOLEAN
+AcpiIsValidSignature (
+    char                    *Signature);
+
+
+/*
+ * tbxfload
+ */
+ACPI_STATUS
+AcpiTbLoadNamespace (
+    void);
+
+#endif /* __ACTABLES_H__ */

+ 452 - 0
kernel/include/acpica/actbl.h

@@ -0,0 +1,452 @@
+/******************************************************************************
+ *
+ * Name: actbl.h - Basic ACPI Table Definitions
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACTBL_H__
+#define __ACTBL_H__
+
+
+/*******************************************************************************
+ *
+ * Fundamental ACPI tables
+ *
+ * This file contains definitions for the ACPI tables that are directly consumed
+ * by ACPICA. All other tables are consumed by the OS-dependent ACPI-related
+ * device drivers and other OS support code.
+ *
+ * The RSDP and FACS do not use the common ACPI table header. All other ACPI
+ * tables use the header.
+ *
+ ******************************************************************************/
+
+
+/*
+ * Values for description table header signatures for tables defined in this
+ * file. Useful because they make it more difficult to inadvertently type in
+ * the wrong signature.
+ */
+#define ACPI_SIG_DSDT           "DSDT"      /* Differentiated System Description Table */
+#define ACPI_SIG_FADT           "FACP"      /* Fixed ACPI Description Table */
+#define ACPI_SIG_FACS           "FACS"      /* Firmware ACPI Control Structure */
+#define ACPI_SIG_OSDT           "OSDT"      /* Override System Description Table */
+#define ACPI_SIG_PSDT           "PSDT"      /* Persistent System Description Table */
+#define ACPI_SIG_RSDP           "RSD PTR "  /* Root System Description Pointer */
+#define ACPI_SIG_RSDT           "RSDT"      /* Root System Description Table */
+#define ACPI_SIG_XSDT           "XSDT"      /* Extended  System Description Table */
+#define ACPI_SIG_SSDT           "SSDT"      /* Secondary System Description Table */
+#define ACPI_RSDP_NAME          "RSDP"      /* Short name for RSDP, not signature */
+
+
+/*
+ * All tables and structures must be byte-packed to match the ACPI
+ * specification, since the tables are provided by the system BIOS
+ */
+#pragma pack(1)
+
+/*
+ * Note: C bitfields are not used for this reason:
+ *
+ * "Bitfields are great and easy to read, but unfortunately the C language
+ * does not specify the layout of bitfields in memory, which means they are
+ * essentially useless for dealing with packed data in on-disk formats or
+ * binary wire protocols." (Or ACPI tables and buffers.) "If you ask me,
+ * this decision was a design error in C. Ritchie could have picked an order
+ * and stuck with it." Norman Ramsey.
+ * See http://stackoverflow.com/a/1053662/41661
+ */
+
+
+/*******************************************************************************
+ *
+ * Master ACPI Table Header. This common header is used by all ACPI tables
+ * except the RSDP and FACS.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_header
+{
+    char                    Signature[ACPI_NAME_SIZE];          /* ASCII table signature */
+    UINT32                  Length;                             /* Length of table in bytes, including this header */
+    UINT8                   Revision;                           /* ACPI Specification minor version number */
+    UINT8                   Checksum;                           /* To make sum of entire table == 0 */
+    char                    OemId[ACPI_OEM_ID_SIZE];            /* ASCII OEM identification */
+    char                    OemTableId[ACPI_OEM_TABLE_ID_SIZE]; /* ASCII OEM table identification */
+    UINT32                  OemRevision;                        /* OEM revision number */
+    char                    AslCompilerId[ACPI_NAME_SIZE];      /* ASCII ASL compiler vendor ID */
+    UINT32                  AslCompilerRevision;                /* ASL compiler version */
+
+} ACPI_TABLE_HEADER;
+
+
+/*******************************************************************************
+ *
+ * GAS - Generic Address Structure (ACPI 2.0+)
+ *
+ * Note: Since this structure is used in the ACPI tables, it is byte aligned.
+ * If misaligned access is not supported by the hardware, accesses to the
+ * 64-bit Address field must be performed with care.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_generic_address
+{
+    UINT8                   SpaceId;                /* Address space where struct or register exists */
+    UINT8                   BitWidth;               /* Size in bits of given register */
+    UINT8                   BitOffset;              /* Bit offset within the register */
+    UINT8                   AccessWidth;            /* Minimum Access size (ACPI 3.0) */
+    UINT64                  Address;                /* 64-bit address of struct or register */
+
+} ACPI_GENERIC_ADDRESS;
+
+
+/*******************************************************************************
+ *
+ * RSDP - Root System Description Pointer (Signature is "RSD PTR ")
+ *        Version 2
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_rsdp
+{
+    char                    Signature[8];               /* ACPI signature, contains "RSD PTR " */
+    UINT8                   Checksum;                   /* ACPI 1.0 checksum */
+    char                    OemId[ACPI_OEM_ID_SIZE];    /* OEM identification */
+    UINT8                   Revision;                   /* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */
+    UINT32                  RsdtPhysicalAddress;        /* 32-bit physical address of the RSDT */
+    UINT32                  Length;                     /* Table length in bytes, including header (ACPI 2.0+) */
+    UINT64                  XsdtPhysicalAddress;        /* 64-bit physical address of the XSDT (ACPI 2.0+) */
+    UINT8                   ExtendedChecksum;           /* Checksum of entire table (ACPI 2.0+) */
+    UINT8                   Reserved[3];                /* Reserved, must be zero */
+
+} ACPI_TABLE_RSDP;
+
+/* Standalone struct for the ACPI 1.0 RSDP */
+
+typedef struct acpi_rsdp_common
+{
+    char                    Signature[8];
+    UINT8                   Checksum;
+    char                    OemId[ACPI_OEM_ID_SIZE];
+    UINT8                   Revision;
+    UINT32                  RsdtPhysicalAddress;
+
+} ACPI_RSDP_COMMON;
+
+/* Standalone struct for the extended part of the RSDP (ACPI 2.0+) */
+
+typedef struct acpi_rsdp_extension
+{
+    UINT32                  Length;
+    UINT64                  XsdtPhysicalAddress;
+    UINT8                   ExtendedChecksum;
+    UINT8                   Reserved[3];
+
+} ACPI_RSDP_EXTENSION;
+
+
+/*******************************************************************************
+ *
+ * RSDT/XSDT - Root System Description Tables
+ *             Version 1 (both)
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_rsdt
+{
+    ACPI_TABLE_HEADER       Header;                 /* Common ACPI table header */
+    UINT32                  TableOffsetEntry[1];    /* Array of pointers to ACPI tables */
+
+} ACPI_TABLE_RSDT;
+
+typedef struct acpi_table_xsdt
+{
+    ACPI_TABLE_HEADER       Header;                 /* Common ACPI table header */
+    UINT64                  TableOffsetEntry[1];    /* Array of pointers to ACPI tables */
+
+} ACPI_TABLE_XSDT;
+
+#define ACPI_RSDT_ENTRY_SIZE        (sizeof (UINT32))
+#define ACPI_XSDT_ENTRY_SIZE        (sizeof (UINT64))
+
+
+/*******************************************************************************
+ *
+ * FACS - Firmware ACPI Control Structure (FACS)
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_facs
+{
+    char                    Signature[4];           /* ASCII table signature */
+    UINT32                  Length;                 /* Length of structure, in bytes */
+    UINT32                  HardwareSignature;      /* Hardware configuration signature */
+    UINT32                  FirmwareWakingVector;   /* 32-bit physical address of the Firmware Waking Vector */
+    UINT32                  GlobalLock;             /* Global Lock for shared hardware resources */
+    UINT32                  Flags;
+    UINT64                  XFirmwareWakingVector;  /* 64-bit version of the Firmware Waking Vector (ACPI 2.0+) */
+    UINT8                   Version;                /* Version of this table (ACPI 2.0+) */
+    UINT8                   Reserved[3];            /* Reserved, must be zero */
+    UINT32                  OspmFlags;              /* Flags to be set by OSPM (ACPI 4.0) */
+    UINT8                   Reserved1[24];          /* Reserved, must be zero */
+
+} ACPI_TABLE_FACS;
+
+/* Masks for GlobalLock flag field above */
+
+#define ACPI_GLOCK_PENDING          (1)             /* 00: Pending global lock ownership */
+#define ACPI_GLOCK_OWNED            (1<<1)          /* 01: Global lock is owned */
+
+/* Masks for Flags field above  */
+
+#define ACPI_FACS_S4_BIOS_PRESENT   (1)             /* 00: S4BIOS support is present */
+#define ACPI_FACS_64BIT_WAKE        (1<<1)          /* 01: 64-bit wake vector supported (ACPI 4.0) */
+
+/* Masks for OspmFlags field above */
+
+#define ACPI_FACS_64BIT_ENVIRONMENT (1)             /* 00: 64-bit wake environment is required (ACPI 4.0) */
+
+
+/*******************************************************************************
+ *
+ * FADT - Fixed ACPI Description Table (Signature "FACP")
+ *        Version 4
+ *
+ ******************************************************************************/
+
+/* Fields common to all versions of the FADT */
+
+typedef struct acpi_table_fadt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  Facs;               /* 32-bit physical address of FACS */
+    UINT32                  Dsdt;               /* 32-bit physical address of DSDT */
+    UINT8                   Model;              /* System Interrupt Model (ACPI 1.0) - not used in ACPI 2.0+ */
+    UINT8                   PreferredProfile;   /* Conveys preferred power management profile to OSPM. */
+    UINT16                  SciInterrupt;       /* System vector of SCI interrupt */
+    UINT32                  SmiCommand;         /* 32-bit Port address of SMI command port */
+    UINT8                   AcpiEnable;         /* Value to write to SMI_CMD to enable ACPI */
+    UINT8                   AcpiDisable;        /* Value to write to SMI_CMD to disable ACPI */
+    UINT8                   S4BiosRequest;      /* Value to write to SMI_CMD to enter S4BIOS state */
+    UINT8                   PstateControl;      /* Processor performance state control*/
+    UINT32                  Pm1aEventBlock;     /* 32-bit port address of Power Mgt 1a Event Reg Blk */
+    UINT32                  Pm1bEventBlock;     /* 32-bit port address of Power Mgt 1b Event Reg Blk */
+    UINT32                  Pm1aControlBlock;   /* 32-bit port address of Power Mgt 1a Control Reg Blk */
+    UINT32                  Pm1bControlBlock;   /* 32-bit port address of Power Mgt 1b Control Reg Blk */
+    UINT32                  Pm2ControlBlock;    /* 32-bit port address of Power Mgt 2 Control Reg Blk */
+    UINT32                  PmTimerBlock;       /* 32-bit port address of Power Mgt Timer Ctrl Reg Blk */
+    UINT32                  Gpe0Block;          /* 32-bit port address of General Purpose Event 0 Reg Blk */
+    UINT32                  Gpe1Block;          /* 32-bit port address of General Purpose Event 1 Reg Blk */
+    UINT8                   Pm1EventLength;     /* Byte Length of ports at Pm1xEventBlock */
+    UINT8                   Pm1ControlLength;   /* Byte Length of ports at Pm1xControlBlock */
+    UINT8                   Pm2ControlLength;   /* Byte Length of ports at Pm2ControlBlock */
+    UINT8                   PmTimerLength;      /* Byte Length of ports at PmTimerBlock */
+    UINT8                   Gpe0BlockLength;    /* Byte Length of ports at Gpe0Block */
+    UINT8                   Gpe1BlockLength;    /* Byte Length of ports at Gpe1Block */
+    UINT8                   Gpe1Base;           /* Offset in GPE number space where GPE1 events start */
+    UINT8                   CstControl;         /* Support for the _CST object and C-States change notification */
+    UINT16                  C2Latency;          /* Worst case HW latency to enter/exit C2 state */
+    UINT16                  C3Latency;          /* Worst case HW latency to enter/exit C3 state */
+    UINT16                  FlushSize;          /* Processor memory cache line width, in bytes */
+    UINT16                  FlushStride;        /* Number of flush strides that need to be read */
+    UINT8                   DutyOffset;         /* Processor duty cycle index in processor P_CNT reg */
+    UINT8                   DutyWidth;          /* Processor duty cycle value bit width in P_CNT register */
+    UINT8                   DayAlarm;           /* Index to day-of-month alarm in RTC CMOS RAM */
+    UINT8                   MonthAlarm;         /* Index to month-of-year alarm in RTC CMOS RAM */
+    UINT8                   Century;            /* Index to century in RTC CMOS RAM */
+    UINT16                  BootFlags;          /* IA-PC Boot Architecture Flags (see below for individual flags) */
+    UINT8                   Reserved;           /* Reserved, must be zero */
+    UINT32                  Flags;              /* Miscellaneous flag bits (see below for individual flags) */
+    ACPI_GENERIC_ADDRESS    ResetRegister;      /* 64-bit address of the Reset register */
+    UINT8                   ResetValue;         /* Value to write to the ResetRegister port to reset the system */
+    UINT16                  ArmBootFlags;       /* ARM-Specific Boot Flags (see below for individual flags) (ACPI 5.1) */
+    UINT8                   MinorRevision;      /* FADT Minor Revision (ACPI 5.1) */
+    UINT64                  XFacs;              /* 64-bit physical address of FACS */
+    UINT64                  XDsdt;              /* 64-bit physical address of DSDT */
+    ACPI_GENERIC_ADDRESS    XPm1aEventBlock;    /* 64-bit Extended Power Mgt 1a Event Reg Blk address */
+    ACPI_GENERIC_ADDRESS    XPm1bEventBlock;    /* 64-bit Extended Power Mgt 1b Event Reg Blk address */
+    ACPI_GENERIC_ADDRESS    XPm1aControlBlock;  /* 64-bit Extended Power Mgt 1a Control Reg Blk address */
+    ACPI_GENERIC_ADDRESS    XPm1bControlBlock;  /* 64-bit Extended Power Mgt 1b Control Reg Blk address */
+    ACPI_GENERIC_ADDRESS    XPm2ControlBlock;   /* 64-bit Extended Power Mgt 2 Control Reg Blk address */
+    ACPI_GENERIC_ADDRESS    XPmTimerBlock;      /* 64-bit Extended Power Mgt Timer Ctrl Reg Blk address */
+    ACPI_GENERIC_ADDRESS    XGpe0Block;         /* 64-bit Extended General Purpose Event 0 Reg Blk address */
+    ACPI_GENERIC_ADDRESS    XGpe1Block;         /* 64-bit Extended General Purpose Event 1 Reg Blk address */
+    ACPI_GENERIC_ADDRESS    SleepControl;       /* 64-bit Sleep Control register (ACPI 5.0) */
+    ACPI_GENERIC_ADDRESS    SleepStatus;        /* 64-bit Sleep Status register (ACPI 5.0) */
+    UINT64                  HypervisorId;       /* Hypervisor Vendor ID (ACPI 6.0) */
+
+} ACPI_TABLE_FADT;
+
+
+/* Masks for FADT IA-PC Boot Architecture Flags (boot_flags) [Vx]=Introduced in this FADT revision */
+
+#define ACPI_FADT_LEGACY_DEVICES    (1)         /* 00: [V2] System has LPC or ISA bus devices */
+#define ACPI_FADT_8042              (1<<1)      /* 01: [V3] System has an 8042 controller on port 60/64 */
+#define ACPI_FADT_NO_VGA            (1<<2)      /* 02: [V4] It is not safe to probe for VGA hardware */
+#define ACPI_FADT_NO_MSI            (1<<3)      /* 03: [V4] Message Signaled Interrupts (MSI) must not be enabled */
+#define ACPI_FADT_NO_ASPM           (1<<4)      /* 04: [V4] PCIe ASPM control must not be enabled */
+#define ACPI_FADT_NO_CMOS_RTC       (1<<5)      /* 05: [V5] No CMOS real-time clock present */
+
+/* Masks for FADT ARM Boot Architecture Flags (arm_boot_flags) ACPI 5.1 */
+
+#define ACPI_FADT_PSCI_COMPLIANT    (1)         /* 00: [V5+] PSCI 0.2+ is implemented */
+#define ACPI_FADT_PSCI_USE_HVC      (1<<1)      /* 01: [V5+] HVC must be used instead of SMC as the PSCI conduit */
+
+/* Masks for FADT flags */
+
+#define ACPI_FADT_WBINVD            (1)         /* 00: [V1] The WBINVD instruction works properly */
+#define ACPI_FADT_WBINVD_FLUSH      (1<<1)      /* 01: [V1] WBINVD flushes but does not invalidate caches */
+#define ACPI_FADT_C1_SUPPORTED      (1<<2)      /* 02: [V1] All processors support C1 state */
+#define ACPI_FADT_C2_MP_SUPPORTED   (1<<3)      /* 03: [V1] C2 state works on MP system */
+#define ACPI_FADT_POWER_BUTTON      (1<<4)      /* 04: [V1] Power button is handled as a control method device */
+#define ACPI_FADT_SLEEP_BUTTON      (1<<5)      /* 05: [V1] Sleep button is handled as a control method device */
+#define ACPI_FADT_FIXED_RTC         (1<<6)      /* 06: [V1] RTC wakeup status is not in fixed register space */
+#define ACPI_FADT_S4_RTC_WAKE       (1<<7)      /* 07: [V1] RTC alarm can wake system from S4 */
+#define ACPI_FADT_32BIT_TIMER       (1<<8)      /* 08: [V1] ACPI timer width is 32-bit (0=24-bit) */
+#define ACPI_FADT_DOCKING_SUPPORTED (1<<9)      /* 09: [V1] Docking supported */
+#define ACPI_FADT_RESET_REGISTER    (1<<10)     /* 10: [V2] System reset via the FADT RESET_REG supported */
+#define ACPI_FADT_SEALED_CASE       (1<<11)     /* 11: [V3] No internal expansion capabilities and case is sealed */
+#define ACPI_FADT_HEADLESS          (1<<12)     /* 12: [V3] No local video capabilities or local input devices */
+#define ACPI_FADT_SLEEP_TYPE        (1<<13)     /* 13: [V3] Must execute native instruction after writing  SLP_TYPx register */
+#define ACPI_FADT_PCI_EXPRESS_WAKE  (1<<14)     /* 14: [V4] System supports PCIEXP_WAKE (STS/EN) bits (ACPI 3.0) */
+#define ACPI_FADT_PLATFORM_CLOCK    (1<<15)     /* 15: [V4] OSPM should use platform-provided timer (ACPI 3.0) */
+#define ACPI_FADT_S4_RTC_VALID      (1<<16)     /* 16: [V4] Contents of RTC_STS valid after S4 wake (ACPI 3.0) */
+#define ACPI_FADT_REMOTE_POWER_ON   (1<<17)     /* 17: [V4] System is compatible with remote power on (ACPI 3.0) */
+#define ACPI_FADT_APIC_CLUSTER      (1<<18)     /* 18: [V4] All local APICs must use cluster model (ACPI 3.0) */
+#define ACPI_FADT_APIC_PHYSICAL     (1<<19)     /* 19: [V4] All local xAPICs must use physical dest mode (ACPI 3.0) */
+#define ACPI_FADT_HW_REDUCED        (1<<20)     /* 20: [V5] ACPI hardware is not implemented (ACPI 5.0) */
+#define ACPI_FADT_LOW_POWER_S0      (1<<21)     /* 21: [V5] S0 power savings are equal or better than S3 (ACPI 5.0) */
+
+
+/* Values for PreferredProfile (Preferred Power Management Profiles) */
+
+enum AcpiPreferredPmProfiles
+{
+    PM_UNSPECIFIED          = 0,
+    PM_DESKTOP              = 1,
+    PM_MOBILE               = 2,
+    PM_WORKSTATION          = 3,
+    PM_ENTERPRISE_SERVER    = 4,
+    PM_SOHO_SERVER          = 5,
+    PM_APPLIANCE_PC         = 6,
+    PM_PERFORMANCE_SERVER   = 7,
+    PM_TABLET               = 8
+};
+
+/* Values for SleepStatus and SleepControl registers (V5+ FADT) */
+
+#define ACPI_X_WAKE_STATUS          0x80
+#define ACPI_X_SLEEP_TYPE_MASK      0x1C
+#define ACPI_X_SLEEP_TYPE_POSITION  0x02
+#define ACPI_X_SLEEP_ENABLE         0x20
+
+
+/* Reset to default packing */
+
+#pragma pack()
+
+
+/*
+ * Internal table-related structures
+ */
+typedef union acpi_name_union
+{
+    UINT32                          Integer;
+    char                            Ascii[4];
+
+} ACPI_NAME_UNION;
+
+
+/* Internal ACPI Table Descriptor. One per ACPI table. */
+
+typedef struct acpi_table_desc
+{
+    ACPI_PHYSICAL_ADDRESS           Address;
+    ACPI_TABLE_HEADER               *Pointer;
+    UINT32                          Length;     /* Length fixed at 32 bits (fixed in table header) */
+    ACPI_NAME_UNION                 Signature;
+    ACPI_OWNER_ID                   OwnerId;
+    UINT8                           Flags;
+
+} ACPI_TABLE_DESC;
+
+/* Masks for Flags field above */
+
+#define ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL  (0) /* Virtual address, external maintained */
+#define ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL (1) /* Physical address, internally mapped */
+#define ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL  (2) /* Virtual address, internallly allocated */
+#define ACPI_TABLE_ORIGIN_MASK              (3)
+#define ACPI_TABLE_IS_LOADED                (8)
+
+
+/*
+ * Get the remaining ACPI tables
+ */
+#include "actbl1.h"
+#include "actbl2.h"
+#include "actbl3.h"
+
+/* Macros used to generate offsets to specific table fields */
+
+#define ACPI_FADT_OFFSET(f)             (UINT16) ACPI_OFFSET (ACPI_TABLE_FADT, f)
+
+/*
+ * Sizes of the various flavors of FADT. We need to look closely
+ * at the FADT length because the version number essentially tells
+ * us nothing because of many BIOS bugs where the version does not
+ * match the expected length. In other words, the length of the
+ * FADT is the bottom line as to what the version really is.
+ *
+ * For reference, the values below are as follows:
+ *     FADT V1 size: 0x074
+ *     FADT V2 size: 0x084
+ *     FADT V3 size: 0x0F4
+ *     FADT V4 size: 0x0F4
+ *     FADT V5 size: 0x10C
+ *     FADT V6 size: 0x114
+ */
+#define ACPI_FADT_V1_SIZE       (UINT32) (ACPI_FADT_OFFSET (Flags) + 4)
+#define ACPI_FADT_V2_SIZE       (UINT32) (ACPI_FADT_OFFSET (MinorRevision) + 1)
+#define ACPI_FADT_V3_SIZE       (UINT32) (ACPI_FADT_OFFSET (SleepControl))
+#define ACPI_FADT_V5_SIZE       (UINT32) (ACPI_FADT_OFFSET (HypervisorId))
+#define ACPI_FADT_V6_SIZE       (UINT32) (sizeof (ACPI_TABLE_FADT))
+
+#endif /* __ACTBL_H__ */

+ 1420 - 0
kernel/include/acpica/actbl1.h

@@ -0,0 +1,1420 @@
+/******************************************************************************
+ *
+ * Name: actbl1.h - Additional ACPI table definitions
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACTBL1_H__
+#define __ACTBL1_H__
+
+
+/*******************************************************************************
+ *
+ * Additional ACPI Tables (1)
+ *
+ * These tables are not consumed directly by the ACPICA subsystem, but are
+ * included here to support device drivers and the AML disassembler.
+ *
+ * The tables in this file are fully defined within the ACPI specification.
+ *
+ ******************************************************************************/
+
+
+/*
+ * Values for description table header signatures for tables defined in this
+ * file. Useful because they make it more difficult to inadvertently type in
+ * the wrong signature.
+ */
+#define ACPI_SIG_BERT           "BERT"      /* Boot Error Record Table */
+#define ACPI_SIG_CPEP           "CPEP"      /* Corrected Platform Error Polling table */
+#define ACPI_SIG_ECDT           "ECDT"      /* Embedded Controller Boot Resources Table */
+#define ACPI_SIG_EINJ           "EINJ"      /* Error Injection table */
+#define ACPI_SIG_ERST           "ERST"      /* Error Record Serialization Table */
+#define ACPI_SIG_HEST           "HEST"      /* Hardware Error Source Table */
+#define ACPI_SIG_MADT           "APIC"      /* Multiple APIC Description Table */
+#define ACPI_SIG_MSCT           "MSCT"      /* Maximum System Characteristics Table */
+#define ACPI_SIG_SBST           "SBST"      /* Smart Battery Specification Table */
+#define ACPI_SIG_SLIT           "SLIT"      /* System Locality Distance Information Table */
+#define ACPI_SIG_SRAT           "SRAT"      /* System Resource Affinity Table */
+#define ACPI_SIG_NFIT           "NFIT"      /* NVDIMM Firmware Interface Table */
+
+
+/*
+ * All tables must be byte-packed to match the ACPI specification, since
+ * the tables are provided by the system BIOS.
+ */
+#pragma pack(1)
+
+/*
+ * Note: C bitfields are not used for this reason:
+ *
+ * "Bitfields are great and easy to read, but unfortunately the C language
+ * does not specify the layout of bitfields in memory, which means they are
+ * essentially useless for dealing with packed data in on-disk formats or
+ * binary wire protocols." (Or ACPI tables and buffers.) "If you ask me,
+ * this decision was a design error in C. Ritchie could have picked an order
+ * and stuck with it." Norman Ramsey.
+ * See http://stackoverflow.com/a/1053662/41661
+ */
+
+
+/*******************************************************************************
+ *
+ * Common subtable headers
+ *
+ ******************************************************************************/
+
+/* Generic subtable header (used in MADT, SRAT, etc.) */
+
+typedef struct acpi_subtable_header
+{
+    UINT8                   Type;
+    UINT8                   Length;
+
+} ACPI_SUBTABLE_HEADER;
+
+
+/* Subtable header for WHEA tables (EINJ, ERST, WDAT) */
+
+typedef struct acpi_whea_header
+{
+    UINT8                   Action;
+    UINT8                   Instruction;
+    UINT8                   Flags;
+    UINT8                   Reserved;
+    ACPI_GENERIC_ADDRESS    RegisterRegion;
+    UINT64                  Value;              /* Value used with Read/Write register */
+    UINT64                  Mask;               /* Bitmask required for this register instruction */
+
+} ACPI_WHEA_HEADER;
+
+
+/*******************************************************************************
+ *
+ * BERT - Boot Error Record Table (ACPI 4.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_bert
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  RegionLength;       /* Length of the boot error region */
+    UINT64                  Address;            /* Physical address of the error region */
+
+} ACPI_TABLE_BERT;
+
+
+/* Boot Error Region (not a subtable, pointed to by Address field above) */
+
+typedef struct acpi_bert_region
+{
+    UINT32                  BlockStatus;        /* Type of error information */
+    UINT32                  RawDataOffset;      /* Offset to raw error data */
+    UINT32                  RawDataLength;      /* Length of raw error data */
+    UINT32                  DataLength;         /* Length of generic error data */
+    UINT32                  ErrorSeverity;      /* Severity code */
+
+} ACPI_BERT_REGION;
+
+/* Values for BlockStatus flags above */
+
+#define ACPI_BERT_UNCORRECTABLE             (1)
+#define ACPI_BERT_CORRECTABLE               (1<<1)
+#define ACPI_BERT_MULTIPLE_UNCORRECTABLE    (1<<2)
+#define ACPI_BERT_MULTIPLE_CORRECTABLE      (1<<3)
+#define ACPI_BERT_ERROR_ENTRY_COUNT         (0xFF<<4) /* 8 bits, error count */
+
+/* Values for ErrorSeverity above */
+
+enum AcpiBertErrorSeverity
+{
+    ACPI_BERT_ERROR_CORRECTABLE     = 0,
+    ACPI_BERT_ERROR_FATAL           = 1,
+    ACPI_BERT_ERROR_CORRECTED       = 2,
+    ACPI_BERT_ERROR_NONE            = 3,
+    ACPI_BERT_ERROR_RESERVED        = 4     /* 4 and greater are reserved */
+};
+
+/*
+ * Note: The generic error data that follows the ErrorSeverity field above
+ * uses the ACPI_HEST_GENERIC_DATA defined under the HEST table below
+ */
+
+
+/*******************************************************************************
+ *
+ * CPEP - Corrected Platform Error Polling table (ACPI 4.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_cpep
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT64                  Reserved;
+
+} ACPI_TABLE_CPEP;
+
+
+/* Subtable */
+
+typedef struct acpi_cpep_polling
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT8                   Id;                 /* Processor ID */
+    UINT8                   Eid;                /* Processor EID */
+    UINT32                  Interval;           /* Polling interval (msec) */
+
+} ACPI_CPEP_POLLING;
+
+
+/*******************************************************************************
+ *
+ * ECDT - Embedded Controller Boot Resources Table
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_ecdt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    ACPI_GENERIC_ADDRESS    Control;            /* Address of EC command/status register */
+    ACPI_GENERIC_ADDRESS    Data;               /* Address of EC data register */
+    UINT32                  Uid;                /* Unique ID - must be same as the EC _UID method */
+    UINT8                   Gpe;                /* The GPE for the EC */
+    UINT8                   Id[1];              /* Full namepath of the EC in the ACPI namespace */
+
+} ACPI_TABLE_ECDT;
+
+
+/*******************************************************************************
+ *
+ * EINJ - Error Injection Table (ACPI 4.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_einj
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  HeaderLength;
+    UINT8                   Flags;
+    UINT8                   Reserved[3];
+    UINT32                  Entries;
+
+} ACPI_TABLE_EINJ;
+
+
+/* EINJ Injection Instruction Entries (actions) */
+
+typedef struct acpi_einj_entry
+{
+    ACPI_WHEA_HEADER        WheaHeader;         /* Common header for WHEA tables */
+
+} ACPI_EINJ_ENTRY;
+
+/* Masks for Flags field above */
+
+#define ACPI_EINJ_PRESERVE          (1)
+
+/* Values for Action field above */
+
+enum AcpiEinjActions
+{
+    ACPI_EINJ_BEGIN_OPERATION               = 0,
+    ACPI_EINJ_GET_TRIGGER_TABLE             = 1,
+    ACPI_EINJ_SET_ERROR_TYPE                = 2,
+    ACPI_EINJ_GET_ERROR_TYPE                = 3,
+    ACPI_EINJ_END_OPERATION                 = 4,
+    ACPI_EINJ_EXECUTE_OPERATION             = 5,
+    ACPI_EINJ_CHECK_BUSY_STATUS             = 6,
+    ACPI_EINJ_GET_COMMAND_STATUS            = 7,
+    ACPI_EINJ_SET_ERROR_TYPE_WITH_ADDRESS   = 8,
+    ACPI_EINJ_ACTION_RESERVED               = 9,     /* 9 and greater are reserved */
+    ACPI_EINJ_TRIGGER_ERROR                 = 0xFF   /* Except for this value */
+};
+
+/* Values for Instruction field above */
+
+enum AcpiEinjInstructions
+{
+    ACPI_EINJ_READ_REGISTER         = 0,
+    ACPI_EINJ_READ_REGISTER_VALUE   = 1,
+    ACPI_EINJ_WRITE_REGISTER        = 2,
+    ACPI_EINJ_WRITE_REGISTER_VALUE  = 3,
+    ACPI_EINJ_NOOP                  = 4,
+    ACPI_EINJ_FLUSH_CACHELINE       = 5,
+    ACPI_EINJ_INSTRUCTION_RESERVED  = 6     /* 6 and greater are reserved */
+};
+
+typedef struct acpi_einj_error_type_with_addr
+{
+    UINT32                  ErrorType;
+    UINT32                  VendorStructOffset;
+    UINT32                  Flags;
+    UINT32                  ApicId;
+    UINT64                  Address;
+    UINT64                  Range;
+    UINT32                  PcieId;
+
+} ACPI_EINJ_ERROR_TYPE_WITH_ADDR;
+
+typedef struct acpi_einj_vendor
+{
+    UINT32                  Length;
+    UINT32                  PcieId;
+    UINT16                  VendorId;
+    UINT16                  DeviceId;
+    UINT8                   RevisionId;
+    UINT8                   Reserved[3];
+
+} ACPI_EINJ_VENDOR;
+
+
+/* EINJ Trigger Error Action Table */
+
+typedef struct acpi_einj_trigger
+{
+    UINT32                  HeaderSize;
+    UINT32                  Revision;
+    UINT32                  TableSize;
+    UINT32                  EntryCount;
+
+} ACPI_EINJ_TRIGGER;
+
+/* Command status return values */
+
+enum AcpiEinjCommandStatus
+{
+    ACPI_EINJ_SUCCESS               = 0,
+    ACPI_EINJ_FAILURE               = 1,
+    ACPI_EINJ_INVALID_ACCESS        = 2,
+    ACPI_EINJ_STATUS_RESERVED       = 3     /* 3 and greater are reserved */
+};
+
+
+/* Error types returned from ACPI_EINJ_GET_ERROR_TYPE (bitfield) */
+
+#define ACPI_EINJ_PROCESSOR_CORRECTABLE     (1)
+#define ACPI_EINJ_PROCESSOR_UNCORRECTABLE   (1<<1)
+#define ACPI_EINJ_PROCESSOR_FATAL           (1<<2)
+#define ACPI_EINJ_MEMORY_CORRECTABLE        (1<<3)
+#define ACPI_EINJ_MEMORY_UNCORRECTABLE      (1<<4)
+#define ACPI_EINJ_MEMORY_FATAL              (1<<5)
+#define ACPI_EINJ_PCIX_CORRECTABLE          (1<<6)
+#define ACPI_EINJ_PCIX_UNCORRECTABLE        (1<<7)
+#define ACPI_EINJ_PCIX_FATAL                (1<<8)
+#define ACPI_EINJ_PLATFORM_CORRECTABLE      (1<<9)
+#define ACPI_EINJ_PLATFORM_UNCORRECTABLE    (1<<10)
+#define ACPI_EINJ_PLATFORM_FATAL            (1<<11)
+#define ACPI_EINJ_VENDOR_DEFINED            (1<<31)
+
+
+/*******************************************************************************
+ *
+ * ERST - Error Record Serialization Table (ACPI 4.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_erst
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  HeaderLength;
+    UINT32                  Reserved;
+    UINT32                  Entries;
+
+} ACPI_TABLE_ERST;
+
+
+/* ERST Serialization Entries (actions) */
+
+typedef struct acpi_erst_entry
+{
+    ACPI_WHEA_HEADER        WheaHeader;         /* Common header for WHEA tables */
+
+} ACPI_ERST_ENTRY;
+
+/* Masks for Flags field above */
+
+#define ACPI_ERST_PRESERVE          (1)
+
+/* Values for Action field above */
+
+enum AcpiErstActions
+{
+    ACPI_ERST_BEGIN_WRITE           = 0,
+    ACPI_ERST_BEGIN_READ            = 1,
+    ACPI_ERST_BEGIN_CLEAR           = 2,
+    ACPI_ERST_END                   = 3,
+    ACPI_ERST_SET_RECORD_OFFSET     = 4,
+    ACPI_ERST_EXECUTE_OPERATION     = 5,
+    ACPI_ERST_CHECK_BUSY_STATUS     = 6,
+    ACPI_ERST_GET_COMMAND_STATUS    = 7,
+    ACPI_ERST_GET_RECORD_ID         = 8,
+    ACPI_ERST_SET_RECORD_ID         = 9,
+    ACPI_ERST_GET_RECORD_COUNT      = 10,
+    ACPI_ERST_BEGIN_DUMMY_WRIITE    = 11,
+    ACPI_ERST_NOT_USED              = 12,
+    ACPI_ERST_GET_ERROR_RANGE       = 13,
+    ACPI_ERST_GET_ERROR_LENGTH      = 14,
+    ACPI_ERST_GET_ERROR_ATTRIBUTES  = 15,
+    ACPI_ERST_ACTION_RESERVED       = 16    /* 16 and greater are reserved */
+};
+
+/* Values for Instruction field above */
+
+enum AcpiErstInstructions
+{
+    ACPI_ERST_READ_REGISTER         = 0,
+    ACPI_ERST_READ_REGISTER_VALUE   = 1,
+    ACPI_ERST_WRITE_REGISTER        = 2,
+    ACPI_ERST_WRITE_REGISTER_VALUE  = 3,
+    ACPI_ERST_NOOP                  = 4,
+    ACPI_ERST_LOAD_VAR1             = 5,
+    ACPI_ERST_LOAD_VAR2             = 6,
+    ACPI_ERST_STORE_VAR1            = 7,
+    ACPI_ERST_ADD                   = 8,
+    ACPI_ERST_SUBTRACT              = 9,
+    ACPI_ERST_ADD_VALUE             = 10,
+    ACPI_ERST_SUBTRACT_VALUE        = 11,
+    ACPI_ERST_STALL                 = 12,
+    ACPI_ERST_STALL_WHILE_TRUE      = 13,
+    ACPI_ERST_SKIP_NEXT_IF_TRUE     = 14,
+    ACPI_ERST_GOTO                  = 15,
+    ACPI_ERST_SET_SRC_ADDRESS_BASE  = 16,
+    ACPI_ERST_SET_DST_ADDRESS_BASE  = 17,
+    ACPI_ERST_MOVE_DATA             = 18,
+    ACPI_ERST_INSTRUCTION_RESERVED  = 19    /* 19 and greater are reserved */
+};
+
+/* Command status return values */
+
+enum AcpiErstCommandStatus
+{
+    ACPI_ERST_SUCESS                = 0,
+    ACPI_ERST_NO_SPACE              = 1,
+    ACPI_ERST_NOT_AVAILABLE         = 2,
+    ACPI_ERST_FAILURE               = 3,
+    ACPI_ERST_RECORD_EMPTY          = 4,
+    ACPI_ERST_NOT_FOUND             = 5,
+    ACPI_ERST_STATUS_RESERVED       = 6     /* 6 and greater are reserved */
+};
+
+
+/* Error Record Serialization Information */
+
+typedef struct acpi_erst_info
+{
+    UINT16                  Signature;          /* Should be "ER" */
+    UINT8                   Data[48];
+
+} ACPI_ERST_INFO;
+
+
+/*******************************************************************************
+ *
+ * HEST - Hardware Error Source Table (ACPI 4.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_hest
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  ErrorSourceCount;
+
+} ACPI_TABLE_HEST;
+
+
+/* HEST subtable header */
+
+typedef struct acpi_hest_header
+{
+    UINT16                  Type;
+    UINT16                  SourceId;
+
+} ACPI_HEST_HEADER;
+
+
+/* Values for Type field above for subtables */
+
+enum AcpiHestTypes
+{
+    ACPI_HEST_TYPE_IA32_CHECK           = 0,
+    ACPI_HEST_TYPE_IA32_CORRECTED_CHECK = 1,
+    ACPI_HEST_TYPE_IA32_NMI             = 2,
+    ACPI_HEST_TYPE_NOT_USED3            = 3,
+    ACPI_HEST_TYPE_NOT_USED4            = 4,
+    ACPI_HEST_TYPE_NOT_USED5            = 5,
+    ACPI_HEST_TYPE_AER_ROOT_PORT        = 6,
+    ACPI_HEST_TYPE_AER_ENDPOINT         = 7,
+    ACPI_HEST_TYPE_AER_BRIDGE           = 8,
+    ACPI_HEST_TYPE_GENERIC_ERROR        = 9,
+    ACPI_HEST_TYPE_RESERVED             = 10    /* 10 and greater are reserved */
+};
+
+
+/*
+ * HEST substructures contained in subtables
+ */
+
+/*
+ * IA32 Error Bank(s) - Follows the ACPI_HEST_IA_MACHINE_CHECK and
+ * ACPI_HEST_IA_CORRECTED structures.
+ */
+typedef struct acpi_hest_ia_error_bank
+{
+    UINT8                   BankNumber;
+    UINT8                   ClearStatusOnInit;
+    UINT8                   StatusFormat;
+    UINT8                   Reserved;
+    UINT32                  ControlRegister;
+    UINT64                  ControlData;
+    UINT32                  StatusRegister;
+    UINT32                  AddressRegister;
+    UINT32                  MiscRegister;
+
+} ACPI_HEST_IA_ERROR_BANK;
+
+
+/* Common HEST sub-structure for PCI/AER structures below (6,7,8) */
+
+typedef struct acpi_hest_aer_common
+{
+    UINT16                  Reserved1;
+    UINT8                   Flags;
+    UINT8                   Enabled;
+    UINT32                  RecordsToPreallocate;
+    UINT32                  MaxSectionsPerRecord;
+    UINT32                  Bus;                    /* Bus and Segment numbers */
+    UINT16                  Device;
+    UINT16                  Function;
+    UINT16                  DeviceControl;
+    UINT16                  Reserved2;
+    UINT32                  UncorrectableMask;
+    UINT32                  UncorrectableSeverity;
+    UINT32                  CorrectableMask;
+    UINT32                  AdvancedCapabilities;
+
+} ACPI_HEST_AER_COMMON;
+
+/* Masks for HEST Flags fields */
+
+#define ACPI_HEST_FIRMWARE_FIRST        (1)
+#define ACPI_HEST_GLOBAL                (1<<1)
+
+/*
+ * Macros to access the bus/segment numbers in Bus field above:
+ *  Bus number is encoded in bits 7:0
+ *  Segment number is encoded in bits 23:8
+ */
+#define ACPI_HEST_BUS(Bus)              ((Bus) & 0xFF)
+#define ACPI_HEST_SEGMENT(Bus)          (((Bus) >> 8) & 0xFFFF)
+
+
+/* Hardware Error Notification */
+
+typedef struct acpi_hest_notify
+{
+    UINT8                   Type;
+    UINT8                   Length;
+    UINT16                  ConfigWriteEnable;
+    UINT32                  PollInterval;
+    UINT32                  Vector;
+    UINT32                  PollingThresholdValue;
+    UINT32                  PollingThresholdWindow;
+    UINT32                  ErrorThresholdValue;
+    UINT32                  ErrorThresholdWindow;
+
+} ACPI_HEST_NOTIFY;
+
+/* Values for Notify Type field above */
+
+enum AcpiHestNotifyTypes
+{
+    ACPI_HEST_NOTIFY_POLLED     = 0,
+    ACPI_HEST_NOTIFY_EXTERNAL   = 1,
+    ACPI_HEST_NOTIFY_LOCAL      = 2,
+    ACPI_HEST_NOTIFY_SCI        = 3,
+    ACPI_HEST_NOTIFY_NMI        = 4,
+    ACPI_HEST_NOTIFY_CMCI       = 5,    /* ACPI 5.0 */
+    ACPI_HEST_NOTIFY_MCE        = 6,    /* ACPI 5.0 */
+    ACPI_HEST_NOTIFY_RESERVED   = 7     /* 7 and greater are reserved */
+};
+
+/* Values for ConfigWriteEnable bitfield above */
+
+#define ACPI_HEST_TYPE                  (1)
+#define ACPI_HEST_POLL_INTERVAL         (1<<1)
+#define ACPI_HEST_POLL_THRESHOLD_VALUE  (1<<2)
+#define ACPI_HEST_POLL_THRESHOLD_WINDOW (1<<3)
+#define ACPI_HEST_ERR_THRESHOLD_VALUE   (1<<4)
+#define ACPI_HEST_ERR_THRESHOLD_WINDOW  (1<<5)
+
+
+/*
+ * HEST subtables
+ */
+
+/* 0: IA32 Machine Check Exception */
+
+typedef struct acpi_hest_ia_machine_check
+{
+    ACPI_HEST_HEADER        Header;
+    UINT16                  Reserved1;
+    UINT8                   Flags;
+    UINT8                   Enabled;
+    UINT32                  RecordsToPreallocate;
+    UINT32                  MaxSectionsPerRecord;
+    UINT64                  GlobalCapabilityData;
+    UINT64                  GlobalControlData;
+    UINT8                   NumHardwareBanks;
+    UINT8                   Reserved3[7];
+
+} ACPI_HEST_IA_MACHINE_CHECK;
+
+
+/* 1: IA32 Corrected Machine Check */
+
+typedef struct acpi_hest_ia_corrected
+{
+    ACPI_HEST_HEADER        Header;
+    UINT16                  Reserved1;
+    UINT8                   Flags;
+    UINT8                   Enabled;
+    UINT32                  RecordsToPreallocate;
+    UINT32                  MaxSectionsPerRecord;
+    ACPI_HEST_NOTIFY        Notify;
+    UINT8                   NumHardwareBanks;
+    UINT8                   Reserved2[3];
+
+} ACPI_HEST_IA_CORRECTED;
+
+
+/* 2: IA32 Non-Maskable Interrupt */
+
+typedef struct acpi_hest_ia_nmi
+{
+    ACPI_HEST_HEADER        Header;
+    UINT32                  Reserved;
+    UINT32                  RecordsToPreallocate;
+    UINT32                  MaxSectionsPerRecord;
+    UINT32                  MaxRawDataLength;
+
+} ACPI_HEST_IA_NMI;
+
+
+/* 3,4,5: Not used */
+
+/* 6: PCI Express Root Port AER */
+
+typedef struct acpi_hest_aer_root
+{
+    ACPI_HEST_HEADER        Header;
+    ACPI_HEST_AER_COMMON    Aer;
+    UINT32                  RootErrorCommand;
+
+} ACPI_HEST_AER_ROOT;
+
+
+/* 7: PCI Express AER (AER Endpoint) */
+
+typedef struct acpi_hest_aer
+{
+    ACPI_HEST_HEADER        Header;
+    ACPI_HEST_AER_COMMON    Aer;
+
+} ACPI_HEST_AER;
+
+
+/* 8: PCI Express/PCI-X Bridge AER */
+
+typedef struct acpi_hest_aer_bridge
+{
+    ACPI_HEST_HEADER        Header;
+    ACPI_HEST_AER_COMMON    Aer;
+    UINT32                  UncorrectableMask2;
+    UINT32                  UncorrectableSeverity2;
+    UINT32                  AdvancedCapabilities2;
+
+} ACPI_HEST_AER_BRIDGE;
+
+
+/* 9: Generic Hardware Error Source */
+
+typedef struct acpi_hest_generic
+{
+    ACPI_HEST_HEADER        Header;
+    UINT16                  RelatedSourceId;
+    UINT8                   Reserved;
+    UINT8                   Enabled;
+    UINT32                  RecordsToPreallocate;
+    UINT32                  MaxSectionsPerRecord;
+    UINT32                  MaxRawDataLength;
+    ACPI_GENERIC_ADDRESS    ErrorStatusAddress;
+    ACPI_HEST_NOTIFY        Notify;
+    UINT32                  ErrorBlockLength;
+
+} ACPI_HEST_GENERIC;
+
+
+/* Generic Error Status block */
+
+typedef struct acpi_hest_generic_status
+{
+    UINT32                  BlockStatus;
+    UINT32                  RawDataOffset;
+    UINT32                  RawDataLength;
+    UINT32                  DataLength;
+    UINT32                  ErrorSeverity;
+
+} ACPI_HEST_GENERIC_STATUS;
+
+/* Values for BlockStatus flags above */
+
+#define ACPI_HEST_UNCORRECTABLE             (1)
+#define ACPI_HEST_CORRECTABLE               (1<<1)
+#define ACPI_HEST_MULTIPLE_UNCORRECTABLE    (1<<2)
+#define ACPI_HEST_MULTIPLE_CORRECTABLE      (1<<3)
+#define ACPI_HEST_ERROR_ENTRY_COUNT         (0xFF<<4) /* 8 bits, error count */
+
+
+/* Generic Error Data entry */
+
+typedef struct acpi_hest_generic_data
+{
+    UINT8                   SectionType[16];
+    UINT32                  ErrorSeverity;
+    UINT16                  Revision;
+    UINT8                   ValidationBits;
+    UINT8                   Flags;
+    UINT32                  ErrorDataLength;
+    UINT8                   FruId[16];
+    UINT8                   FruText[20];
+
+} ACPI_HEST_GENERIC_DATA;
+
+
+/*******************************************************************************
+ *
+ * MADT - Multiple APIC Description Table
+ *        Version 3
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_madt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  Address;            /* Physical address of local APIC */
+    UINT32                  Flags;
+
+} ACPI_TABLE_MADT;
+
+/* Masks for Flags field above */
+
+#define ACPI_MADT_PCAT_COMPAT       (1)         /* 00: System also has dual 8259s */
+
+/* Values for PCATCompat flag */
+
+#define ACPI_MADT_DUAL_PIC          0
+#define ACPI_MADT_MULTIPLE_APIC     1
+
+
+/* Values for MADT subtable type in ACPI_SUBTABLE_HEADER */
+
+enum AcpiMadtType
+{
+    ACPI_MADT_TYPE_LOCAL_APIC               = 0,
+    ACPI_MADT_TYPE_IO_APIC                  = 1,
+    ACPI_MADT_TYPE_INTERRUPT_OVERRIDE       = 2,
+    ACPI_MADT_TYPE_NMI_SOURCE               = 3,
+    ACPI_MADT_TYPE_LOCAL_APIC_NMI           = 4,
+    ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE      = 5,
+    ACPI_MADT_TYPE_IO_SAPIC                 = 6,
+    ACPI_MADT_TYPE_LOCAL_SAPIC              = 7,
+    ACPI_MADT_TYPE_INTERRUPT_SOURCE         = 8,
+    ACPI_MADT_TYPE_LOCAL_X2APIC             = 9,
+    ACPI_MADT_TYPE_LOCAL_X2APIC_NMI         = 10,
+    ACPI_MADT_TYPE_GENERIC_INTERRUPT        = 11,
+    ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR      = 12,
+    ACPI_MADT_TYPE_GENERIC_MSI_FRAME        = 13,
+    ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR    = 14,
+    ACPI_MADT_TYPE_GENERIC_TRANSLATOR       = 15,
+    ACPI_MADT_TYPE_RESERVED                 = 16    /* 16 and greater are reserved */
+};
+
+
+/*
+ * MADT Subtables, correspond to Type in ACPI_SUBTABLE_HEADER
+ */
+
+/* 0: Processor Local APIC */
+
+typedef struct acpi_madt_local_apic
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT8                   ProcessorId;        /* ACPI processor id */
+    UINT8                   Id;                 /* Processor's local APIC id */
+    UINT32                  LapicFlags;
+
+} ACPI_MADT_LOCAL_APIC;
+
+
+/* 1: IO APIC */
+
+typedef struct acpi_madt_io_apic
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT8                   Id;                 /* I/O APIC ID */
+    UINT8                   Reserved;           /* Reserved - must be zero */
+    UINT32                  Address;            /* APIC physical address */
+    UINT32                  GlobalIrqBase;      /* Global system interrupt where INTI lines start */
+
+} ACPI_MADT_IO_APIC;
+
+
+/* 2: Interrupt Override */
+
+typedef struct acpi_madt_interrupt_override
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT8                   Bus;                /* 0 - ISA */
+    UINT8                   SourceIrq;          /* Interrupt source (IRQ) */
+    UINT32                  GlobalIrq;          /* Global system interrupt */
+    UINT16                  IntiFlags;
+
+} ACPI_MADT_INTERRUPT_OVERRIDE;
+
+
+/* 3: NMI Source */
+
+typedef struct acpi_madt_nmi_source
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  IntiFlags;
+    UINT32                  GlobalIrq;          /* Global system interrupt */
+
+} ACPI_MADT_NMI_SOURCE;
+
+
+/* 4: Local APIC NMI */
+
+typedef struct acpi_madt_local_apic_nmi
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT8                   ProcessorId;        /* ACPI processor id */
+    UINT16                  IntiFlags;
+    UINT8                   Lint;               /* LINTn to which NMI is connected */
+
+} ACPI_MADT_LOCAL_APIC_NMI;
+
+
+/* 5: Address Override */
+
+typedef struct acpi_madt_local_apic_override
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  Reserved;           /* Reserved, must be zero */
+    UINT64                  Address;            /* APIC physical address */
+
+} ACPI_MADT_LOCAL_APIC_OVERRIDE;
+
+
+/* 6: I/O Sapic */
+
+typedef struct acpi_madt_io_sapic
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT8                   Id;                 /* I/O SAPIC ID */
+    UINT8                   Reserved;           /* Reserved, must be zero */
+    UINT32                  GlobalIrqBase;      /* Global interrupt for SAPIC start */
+    UINT64                  Address;            /* SAPIC physical address */
+
+} ACPI_MADT_IO_SAPIC;
+
+
+/* 7: Local Sapic */
+
+typedef struct acpi_madt_local_sapic
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT8                   ProcessorId;        /* ACPI processor id */
+    UINT8                   Id;                 /* SAPIC ID */
+    UINT8                   Eid;                /* SAPIC EID */
+    UINT8                   Reserved[3];        /* Reserved, must be zero */
+    UINT32                  LapicFlags;
+    UINT32                  Uid;                /* Numeric UID - ACPI 3.0 */
+    char                    UidString[1];       /* String UID  - ACPI 3.0 */
+
+} ACPI_MADT_LOCAL_SAPIC;
+
+
+/* 8: Platform Interrupt Source */
+
+typedef struct acpi_madt_interrupt_source
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  IntiFlags;
+    UINT8                   Type;               /* 1=PMI, 2=INIT, 3=corrected */
+    UINT8                   Id;                 /* Processor ID */
+    UINT8                   Eid;                /* Processor EID */
+    UINT8                   IoSapicVector;      /* Vector value for PMI interrupts */
+    UINT32                  GlobalIrq;          /* Global system interrupt */
+    UINT32                  Flags;              /* Interrupt Source Flags */
+
+} ACPI_MADT_INTERRUPT_SOURCE;
+
+/* Masks for Flags field above */
+
+#define ACPI_MADT_CPEI_OVERRIDE     (1)
+
+
+/* 9: Processor Local X2APIC (ACPI 4.0) */
+
+typedef struct acpi_madt_local_x2apic
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  Reserved;           /* Reserved - must be zero */
+    UINT32                  LocalApicId;        /* Processor x2APIC ID  */
+    UINT32                  LapicFlags;
+    UINT32                  Uid;                /* ACPI processor UID */
+
+} ACPI_MADT_LOCAL_X2APIC;
+
+
+/* 10: Local X2APIC NMI (ACPI 4.0) */
+
+typedef struct acpi_madt_local_x2apic_nmi
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  IntiFlags;
+    UINT32                  Uid;                /* ACPI processor UID */
+    UINT8                   Lint;               /* LINTn to which NMI is connected */
+    UINT8                   Reserved[3];        /* Reserved - must be zero */
+
+} ACPI_MADT_LOCAL_X2APIC_NMI;
+
+
+/* 11: Generic Interrupt (ACPI 5.0 + ACPI 6.0 changes) */
+
+typedef struct acpi_madt_generic_interrupt
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  Reserved;           /* Reserved - must be zero */
+    UINT32                  CpuInterfaceNumber;
+    UINT32                  Uid;
+    UINT32                  Flags;
+    UINT32                  ParkingVersion;
+    UINT32                  PerformanceInterrupt;
+    UINT64                  ParkedAddress;
+    UINT64                  BaseAddress;
+    UINT64                  GicvBaseAddress;
+    UINT64                  GichBaseAddress;
+    UINT32                  VgicInterrupt;
+    UINT64                  GicrBaseAddress;
+    UINT64                  ArmMpidr;
+    UINT8                   EfficiencyClass;
+    UINT8                   Reserved2[3];
+
+} ACPI_MADT_GENERIC_INTERRUPT;
+
+/* Masks for Flags field above */
+
+/* ACPI_MADT_ENABLED                    (1)      Processor is usable if set */
+#define ACPI_MADT_PERFORMANCE_IRQ_MODE  (1<<1)  /* 01: Performance Interrupt Mode */
+#define ACPI_MADT_VGIC_IRQ_MODE         (1<<2)  /* 02: VGIC Maintenance Interrupt mode */
+
+
+/* 12: Generic Distributor (ACPI 5.0 + ACPI 6.0 changes) */
+
+typedef struct acpi_madt_generic_distributor
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  Reserved;           /* Reserved - must be zero */
+    UINT32                  GicId;
+    UINT64                  BaseAddress;
+    UINT32                  GlobalIrqBase;
+    UINT8                   Version;
+    UINT8                   Reserved2[3];       /* Reserved - must be zero */
+
+} ACPI_MADT_GENERIC_DISTRIBUTOR;
+
+/* Values for Version field above */
+
+enum AcpiMadtGicVersion
+{
+    ACPI_MADT_GIC_VERSION_NONE          = 0,
+    ACPI_MADT_GIC_VERSION_V1            = 1,
+    ACPI_MADT_GIC_VERSION_V2            = 2,
+    ACPI_MADT_GIC_VERSION_V3            = 3,
+    ACPI_MADT_GIC_VERSION_V4            = 4,
+    ACPI_MADT_GIC_VERSION_RESERVED      = 5     /* 5 and greater are reserved */
+};
+
+
+/* 13: Generic MSI Frame (ACPI 5.1) */
+
+typedef struct acpi_madt_generic_msi_frame
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  Reserved;           /* Reserved - must be zero */
+    UINT32                  MsiFrameId;
+    UINT64                  BaseAddress;
+    UINT32                  Flags;
+    UINT16                  SpiCount;
+    UINT16                  SpiBase;
+
+} ACPI_MADT_GENERIC_MSI_FRAME;
+
+/* Masks for Flags field above */
+
+#define ACPI_MADT_OVERRIDE_SPI_VALUES   (1)
+
+
+/* 14: Generic Redistributor (ACPI 5.1) */
+
+typedef struct acpi_madt_generic_redistributor
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  Reserved;           /* reserved - must be zero */
+    UINT64                  BaseAddress;
+    UINT32                  Length;
+
+} ACPI_MADT_GENERIC_REDISTRIBUTOR;
+
+
+/* 15: Generic Translator (ACPI 6.0) */
+
+typedef struct acpi_madt_generic_translator
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  Reserved;           /* reserved - must be zero */
+    UINT32                  TranslationId;
+    UINT64                  BaseAddress;
+    UINT32                  Reserved2;
+
+} ACPI_MADT_GENERIC_TRANSLATOR;
+
+
+/*
+ * Common flags fields for MADT subtables
+ */
+
+/* MADT Local APIC flags */
+
+#define ACPI_MADT_ENABLED           (1)         /* 00: Processor is usable if set */
+
+/* MADT MPS INTI flags (IntiFlags) */
+
+#define ACPI_MADT_POLARITY_MASK     (3)         /* 00-01: Polarity of APIC I/O input signals */
+#define ACPI_MADT_TRIGGER_MASK      (3<<2)      /* 02-03: Trigger mode of APIC input signals */
+
+/* Values for MPS INTI flags */
+
+#define ACPI_MADT_POLARITY_CONFORMS       0
+#define ACPI_MADT_POLARITY_ACTIVE_HIGH    1
+#define ACPI_MADT_POLARITY_RESERVED       2
+#define ACPI_MADT_POLARITY_ACTIVE_LOW     3
+
+#define ACPI_MADT_TRIGGER_CONFORMS        (0)
+#define ACPI_MADT_TRIGGER_EDGE            (1<<2)
+#define ACPI_MADT_TRIGGER_RESERVED        (2<<2)
+#define ACPI_MADT_TRIGGER_LEVEL           (3<<2)
+
+
+/*******************************************************************************
+ *
+ * MSCT - Maximum System Characteristics Table (ACPI 4.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_msct
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  ProximityOffset;    /* Location of proximity info struct(s) */
+    UINT32                  MaxProximityDomains;/* Max number of proximity domains */
+    UINT32                  MaxClockDomains;    /* Max number of clock domains */
+    UINT64                  MaxAddress;         /* Max physical address in system */
+
+} ACPI_TABLE_MSCT;
+
+
+/* Subtable - Maximum Proximity Domain Information. Version 1 */
+
+typedef struct acpi_msct_proximity
+{
+    UINT8                   Revision;
+    UINT8                   Length;
+    UINT32                  RangeStart;         /* Start of domain range */
+    UINT32                  RangeEnd;           /* End of domain range */
+    UINT32                  ProcessorCapacity;
+    UINT64                  MemoryCapacity;     /* In bytes */
+
+} ACPI_MSCT_PROXIMITY;
+
+
+/*******************************************************************************
+ *
+ * NFIT - NVDIMM Interface Table (ACPI 6.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_nfit
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  Reserved;           /* Reserved, must be zero */
+
+} ACPI_TABLE_NFIT;
+
+/* Subtable header for NFIT */
+
+typedef struct acpi_nfit_header
+{
+    UINT16                   Type;
+    UINT16                   Length;
+
+} ACPI_NFIT_HEADER;
+
+
+/* Values for subtable type in ACPI_NFIT_HEADER */
+
+enum AcpiNfitType
+{
+    ACPI_NFIT_TYPE_SYSTEM_ADDRESS       = 0,
+    ACPI_NFIT_TYPE_MEMORY_MAP           = 1,
+    ACPI_NFIT_TYPE_INTERLEAVE           = 2,
+    ACPI_NFIT_TYPE_SMBIOS               = 3,
+    ACPI_NFIT_TYPE_CONTROL_REGION       = 4,
+    ACPI_NFIT_TYPE_DATA_REGION          = 5,
+    ACPI_NFIT_TYPE_FLUSH_ADDRESS        = 6,
+    ACPI_NFIT_TYPE_RESERVED             = 7     /* 7 and greater are reserved */
+};
+
+/*
+ * NFIT Subtables
+ */
+
+/* 0: System Physical Address Range Structure */
+
+typedef struct acpi_nfit_system_address
+{
+    ACPI_NFIT_HEADER        Header;
+    UINT16                  RangeIndex;
+    UINT16                  Flags;
+    UINT32                  Reserved;           /* Reseved, must be zero */
+    UINT32                  ProximityDomain;
+    UINT8                   RangeGuid[16];
+    UINT64                  Address;
+    UINT64                  Length;
+    UINT64                  MemoryMapping;
+
+} ACPI_NFIT_SYSTEM_ADDRESS;
+
+/* Flags */
+
+#define ACPI_NFIT_ADD_ONLINE_ONLY       (1)     /* 00: Add/Online Operation Only */
+#define ACPI_NFIT_PROXIMITY_VALID       (1<<1)  /* 01: Proximity Domain Valid */
+
+/* Range Type GUIDs appear in the include/acuuid.h file */
+
+
+/* 1: Memory Device to System Address Range Map Structure */
+
+typedef struct acpi_nfit_memory_map
+{
+    ACPI_NFIT_HEADER        Header;
+    UINT32                  DeviceHandle;
+    UINT16                  PhysicalId;
+    UINT16                  RegionId;
+    UINT16                  RangeIndex;
+    UINT16                  RegionIndex;
+    UINT64                  RegionSize;
+    UINT64                  RegionOffset;
+    UINT64                  Address;
+    UINT16                  InterleaveIndex;
+    UINT16                  InterleaveWays;
+    UINT16                  Flags;
+    UINT16                  Reserved;           /* Reserved, must be zero */
+
+} ACPI_NFIT_MEMORY_MAP;
+
+/* Flags */
+
+#define ACPI_NFIT_MEM_SAVE_FAILED       (1)     /* 00: Last SAVE to Memory Device failed */
+#define ACPI_NFIT_MEM_RESTORE_FAILED    (1<<1)  /* 01: Last RESTORE from Memory Device failed */
+#define ACPI_NFIT_MEM_FLUSH_FAILED      (1<<2)  /* 02: Platform flush failed */
+#define ACPI_NFIT_MEM_NOT_ARMED         (1<<3)  /* 03: Memory Device is not armed */
+#define ACPI_NFIT_MEM_HEALTH_OBSERVED   (1<<4)  /* 04: Memory Device observed SMART/health events */
+#define ACPI_NFIT_MEM_HEALTH_ENABLED    (1<<5)  /* 05: SMART/health events enabled */
+
+
+/* 2: Interleave Structure */
+
+typedef struct acpi_nfit_interleave
+{
+    ACPI_NFIT_HEADER        Header;
+    UINT16                  InterleaveIndex;
+    UINT16                  Reserved;           /* Reserved, must be zero */
+    UINT32                  LineCount;
+    UINT32                  LineSize;
+    UINT32                  LineOffset[1];      /* Variable length */
+
+} ACPI_NFIT_INTERLEAVE;
+
+
+/* 3: SMBIOS Management Information Structure */
+
+typedef struct acpi_nfit_smbios
+{
+    ACPI_NFIT_HEADER        Header;
+    UINT32                  Reserved;           /* Reserved, must be zero */
+    UINT8                   Data[1];            /* Variable length */
+
+} ACPI_NFIT_SMBIOS;
+
+
+/* 4: NVDIMM Control Region Structure */
+
+typedef struct acpi_nfit_control_region
+{
+    ACPI_NFIT_HEADER        Header;
+    UINT16                  RegionIndex;
+    UINT16                  VendorId;
+    UINT16                  DeviceId;
+    UINT16                  RevisionId;
+    UINT16                  SubsystemVendorId;
+    UINT16                  SubsystemDeviceId;
+    UINT16                  SubsystemRevisionId;
+    UINT8                   Reserved[6];        /* Reserved, must be zero */
+    UINT32                  SerialNumber;
+    UINT16                  Code;
+    UINT16                  Windows;
+    UINT64                  WindowSize;
+    UINT64                  CommandOffset;
+    UINT64                  CommandSize;
+    UINT64                  StatusOffset;
+    UINT64                  StatusSize;
+    UINT16                  Flags;
+    UINT8                   Reserved1[6];       /* Reserved, must be zero */
+
+} ACPI_NFIT_CONTROL_REGION;
+
+/* Flags */
+
+#define ACPI_NFIT_CONTROL_BUFFERED      (1)     /* Block Data Windows implementation is buffered */
+
+
+/* 5: NVDIMM Block Data Window Region Structure */
+
+typedef struct acpi_nfit_data_region
+{
+    ACPI_NFIT_HEADER        Header;
+    UINT16                  RegionIndex;
+    UINT16                  Windows;
+    UINT64                  Offset;
+    UINT64                  Size;
+    UINT64                  Capacity;
+    UINT64                  StartAddress;
+
+} ACPI_NFIT_DATA_REGION;
+
+
+/* 6: Flush Hint Address Structure */
+
+typedef struct acpi_nfit_flush_address
+{
+    ACPI_NFIT_HEADER        Header;
+    UINT32                  DeviceHandle;
+    UINT16                  HintCount;
+    UINT8                   Reserved[6];        /* Reserved, must be zero */
+    UINT64                  HintAddress[1];     /* Variable length */
+
+} ACPI_NFIT_FLUSH_ADDRESS;
+
+
+/*******************************************************************************
+ *
+ * SBST - Smart Battery Specification Table
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_sbst
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  WarningLevel;
+    UINT32                  LowLevel;
+    UINT32                  CriticalLevel;
+
+} ACPI_TABLE_SBST;
+
+
+/*******************************************************************************
+ *
+ * SLIT - System Locality Distance Information Table
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_slit
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT64                  LocalityCount;
+    UINT8                   Entry[1];           /* Real size = localities^2 */
+
+} ACPI_TABLE_SLIT;
+
+
+/*******************************************************************************
+ *
+ * SRAT - System Resource Affinity Table
+ *        Version 3
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_srat
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  TableRevision;      /* Must be value '1' */
+    UINT64                  Reserved;           /* Reserved, must be zero */
+
+} ACPI_TABLE_SRAT;
+
+/* Values for subtable type in ACPI_SUBTABLE_HEADER */
+
+enum AcpiSratType
+{
+    ACPI_SRAT_TYPE_CPU_AFFINITY         = 0,
+    ACPI_SRAT_TYPE_MEMORY_AFFINITY      = 1,
+    ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY  = 2,
+    ACPI_SRAT_TYPE_GICC_AFFINITY        = 3,
+    ACPI_SRAT_TYPE_RESERVED             = 4     /* 4 and greater are reserved */
+};
+
+/*
+ * SRAT Subtables, correspond to Type in ACPI_SUBTABLE_HEADER
+ */
+
+/* 0: Processor Local APIC/SAPIC Affinity */
+
+typedef struct acpi_srat_cpu_affinity
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT8                   ProximityDomainLo;
+    UINT8                   ApicId;
+    UINT32                  Flags;
+    UINT8                   LocalSapicEid;
+    UINT8                   ProximityDomainHi[3];
+    UINT32                  ClockDomain;
+
+} ACPI_SRAT_CPU_AFFINITY;
+
+/* Flags */
+
+#define ACPI_SRAT_CPU_USE_AFFINITY  (1)         /* 00: Use affinity structure */
+
+
+/* 1: Memory Affinity */
+
+typedef struct acpi_srat_mem_affinity
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT32                  ProximityDomain;
+    UINT16                  Reserved;           /* Reserved, must be zero */
+    UINT64                  BaseAddress;
+    UINT64                  Length;
+    UINT32                  Reserved1;
+    UINT32                  Flags;
+    UINT64                  Reserved2;          /* Reserved, must be zero */
+
+} ACPI_SRAT_MEM_AFFINITY;
+
+/* Flags */
+
+#define ACPI_SRAT_MEM_ENABLED       (1)         /* 00: Use affinity structure */
+#define ACPI_SRAT_MEM_HOT_PLUGGABLE (1<<1)      /* 01: Memory region is hot pluggable */
+#define ACPI_SRAT_MEM_NON_VOLATILE  (1<<2)      /* 02: Memory region is non-volatile */
+
+
+/* 2: Processor Local X2_APIC Affinity (ACPI 4.0) */
+
+typedef struct acpi_srat_x2apic_cpu_affinity
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT16                  Reserved;           /* Reserved, must be zero */
+    UINT32                  ProximityDomain;
+    UINT32                  ApicId;
+    UINT32                  Flags;
+    UINT32                  ClockDomain;
+    UINT32                  Reserved2;
+
+} ACPI_SRAT_X2APIC_CPU_AFFINITY;
+
+/* Flags for ACPI_SRAT_CPU_AFFINITY and ACPI_SRAT_X2APIC_CPU_AFFINITY */
+
+#define ACPI_SRAT_CPU_ENABLED       (1)         /* 00: Use affinity structure */
+
+
+/* 3: GICC Affinity (ACPI 5.1) */
+
+typedef struct acpi_srat_gicc_affinity
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT32                  ProximityDomain;
+    UINT32                  AcpiProcessorUid;
+    UINT32                  Flags;
+    UINT32                  ClockDomain;
+
+} ACPI_SRAT_GICC_AFFINITY;
+
+/* Flags for ACPI_SRAT_GICC_AFFINITY */
+
+#define ACPI_SRAT_GICC_ENABLED     (1)         /* 00: Use affinity structure */
+
+
+/* Reset to default packing */
+
+#pragma pack()
+
+#endif /* __ACTBL1_H__ */

+ 1692 - 0
kernel/include/acpica/actbl2.h

@@ -0,0 +1,1692 @@
+/******************************************************************************
+ *
+ * Name: actbl2.h - ACPI Table Definitions (tables not in ACPI spec)
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACTBL2_H__
+#define __ACTBL2_H__
+
+
+/*******************************************************************************
+ *
+ * Additional ACPI Tables (2)
+ *
+ * These tables are not consumed directly by the ACPICA subsystem, but are
+ * included here to support device drivers and the AML disassembler.
+ *
+ * Generally, the tables in this file are defined by third-party specifications,
+ * and are not defined directly by the ACPI specification itself.
+ *
+ ******************************************************************************/
+
+
+/*
+ * Values for description table header signatures for tables defined in this
+ * file. Useful because they make it more difficult to inadvertently type in
+ * the wrong signature.
+ */
+#define ACPI_SIG_ASF            "ASF!"      /* Alert Standard Format table */
+#define ACPI_SIG_BOOT           "BOOT"      /* Simple Boot Flag Table */
+#define ACPI_SIG_CSRT           "CSRT"      /* Core System Resource Table */
+#define ACPI_SIG_DBG2           "DBG2"      /* Debug Port table type 2 */
+#define ACPI_SIG_DBGP           "DBGP"      /* Debug Port table */
+#define ACPI_SIG_DMAR           "DMAR"      /* DMA Remapping table */
+#define ACPI_SIG_HPET           "HPET"      /* High Precision Event Timer table */
+#define ACPI_SIG_IBFT           "IBFT"      /* iSCSI Boot Firmware Table */
+#define ACPI_SIG_IORT           "IORT"      /* IO Remapping Table */
+#define ACPI_SIG_IVRS           "IVRS"      /* I/O Virtualization Reporting Structure */
+#define ACPI_SIG_LPIT           "LPIT"      /* Low Power Idle Table */
+#define ACPI_SIG_MCFG           "MCFG"      /* PCI Memory Mapped Configuration table */
+#define ACPI_SIG_MCHI           "MCHI"      /* Management Controller Host Interface table */
+#define ACPI_SIG_MSDM           "MSDM"      /* Microsoft Data Management Table */
+#define ACPI_SIG_MTMR           "MTMR"      /* MID Timer table */
+#define ACPI_SIG_SLIC           "SLIC"      /* Software Licensing Description Table */
+#define ACPI_SIG_SPCR           "SPCR"      /* Serial Port Console Redirection table */
+#define ACPI_SIG_SPMI           "SPMI"      /* Server Platform Management Interface table */
+#define ACPI_SIG_TCPA           "TCPA"      /* Trusted Computing Platform Alliance table */
+#define ACPI_SIG_TPM2           "TPM2"      /* Trusted Platform Module 2.0 H/W interface table */
+#define ACPI_SIG_UEFI           "UEFI"      /* Uefi Boot Optimization Table */
+#define ACPI_SIG_VRTC           "VRTC"      /* Virtual Real Time Clock Table */
+#define ACPI_SIG_WAET           "WAET"      /* Windows ACPI Emulated devices Table */
+#define ACPI_SIG_WDAT           "WDAT"      /* Watchdog Action Table */
+#define ACPI_SIG_WDDT           "WDDT"      /* Watchdog Timer Description Table */
+#define ACPI_SIG_WDRT           "WDRT"      /* Watchdog Resource Table */
+
+#ifdef ACPI_UNDEFINED_TABLES
+/*
+ * These tables have been seen in the field, but no definition has been found
+ */
+#define ACPI_SIG_ATKG           "ATKG"
+#define ACPI_SIG_GSCI           "GSCI"      /* GMCH SCI table */
+#define ACPI_SIG_IEIT           "IEIT"
+#endif
+
+/*
+ * All tables must be byte-packed to match the ACPI specification, since
+ * the tables are provided by the system BIOS.
+ */
+#pragma pack(1)
+
+/*
+ * Note: C bitfields are not used for this reason:
+ *
+ * "Bitfields are great and easy to read, but unfortunately the C language
+ * does not specify the layout of bitfields in memory, which means they are
+ * essentially useless for dealing with packed data in on-disk formats or
+ * binary wire protocols." (Or ACPI tables and buffers.) "If you ask me,
+ * this decision was a design error in C. Ritchie could have picked an order
+ * and stuck with it." Norman Ramsey.
+ * See http://stackoverflow.com/a/1053662/41661
+ */
+
+
+/*******************************************************************************
+ *
+ * ASF - Alert Standard Format table (Signature "ASF!")
+ *       Revision 0x10
+ *
+ * Conforms to the Alert Standard Format Specification V2.0, 23 April 2003
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_asf
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+
+} ACPI_TABLE_ASF;
+
+
+/* ASF subtable header */
+
+typedef struct acpi_asf_header
+{
+    UINT8                   Type;
+    UINT8                   Reserved;
+    UINT16                  Length;
+
+} ACPI_ASF_HEADER;
+
+
+/* Values for Type field above */
+
+enum AcpiAsfType
+{
+    ACPI_ASF_TYPE_INFO          = 0,
+    ACPI_ASF_TYPE_ALERT         = 1,
+    ACPI_ASF_TYPE_CONTROL       = 2,
+    ACPI_ASF_TYPE_BOOT          = 3,
+    ACPI_ASF_TYPE_ADDRESS       = 4,
+    ACPI_ASF_TYPE_RESERVED      = 5
+};
+
+/*
+ * ASF subtables
+ */
+
+/* 0: ASF Information */
+
+typedef struct acpi_asf_info
+{
+    ACPI_ASF_HEADER         Header;
+    UINT8                   MinResetValue;
+    UINT8                   MinPollInterval;
+    UINT16                  SystemId;
+    UINT32                  MfgId;
+    UINT8                   Flags;
+    UINT8                   Reserved2[3];
+
+} ACPI_ASF_INFO;
+
+/* Masks for Flags field above */
+
+#define ACPI_ASF_SMBUS_PROTOCOLS    (1)
+
+
+/* 1: ASF Alerts */
+
+typedef struct acpi_asf_alert
+{
+    ACPI_ASF_HEADER         Header;
+    UINT8                   AssertMask;
+    UINT8                   DeassertMask;
+    UINT8                   Alerts;
+    UINT8                   DataLength;
+
+} ACPI_ASF_ALERT;
+
+typedef struct acpi_asf_alert_data
+{
+    UINT8                   Address;
+    UINT8                   Command;
+    UINT8                   Mask;
+    UINT8                   Value;
+    UINT8                   SensorType;
+    UINT8                   Type;
+    UINT8                   Offset;
+    UINT8                   SourceType;
+    UINT8                   Severity;
+    UINT8                   SensorNumber;
+    UINT8                   Entity;
+    UINT8                   Instance;
+
+} ACPI_ASF_ALERT_DATA;
+
+
+/* 2: ASF Remote Control */
+
+typedef struct acpi_asf_remote
+{
+    ACPI_ASF_HEADER         Header;
+    UINT8                   Controls;
+    UINT8                   DataLength;
+    UINT16                  Reserved2;
+
+} ACPI_ASF_REMOTE;
+
+typedef struct acpi_asf_control_data
+{
+    UINT8                   Function;
+    UINT8                   Address;
+    UINT8                   Command;
+    UINT8                   Value;
+
+} ACPI_ASF_CONTROL_DATA;
+
+
+/* 3: ASF RMCP Boot Options */
+
+typedef struct acpi_asf_rmcp
+{
+    ACPI_ASF_HEADER         Header;
+    UINT8                   Capabilities[7];
+    UINT8                   CompletionCode;
+    UINT32                  EnterpriseId;
+    UINT8                   Command;
+    UINT16                  Parameter;
+    UINT16                  BootOptions;
+    UINT16                  OemParameters;
+
+} ACPI_ASF_RMCP;
+
+
+/* 4: ASF Address */
+
+typedef struct acpi_asf_address
+{
+    ACPI_ASF_HEADER         Header;
+    UINT8                   EpromAddress;
+    UINT8                   Devices;
+
+} ACPI_ASF_ADDRESS;
+
+
+/*******************************************************************************
+ *
+ * BOOT - Simple Boot Flag Table
+ *        Version 1
+ *
+ * Conforms to the "Simple Boot Flag Specification", Version 2.1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_boot
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   CmosIndex;          /* Index in CMOS RAM for the boot register */
+    UINT8                   Reserved[3];
+
+} ACPI_TABLE_BOOT;
+
+
+/*******************************************************************************
+ *
+ * CSRT - Core System Resource Table
+ *        Version 0
+ *
+ * Conforms to the "Core System Resource Table (CSRT)", November 14, 2011
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_csrt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+
+} ACPI_TABLE_CSRT;
+
+
+/* Resource Group subtable */
+
+typedef struct acpi_csrt_group
+{
+    UINT32                  Length;
+    UINT32                  VendorId;
+    UINT32                  SubvendorId;
+    UINT16                  DeviceId;
+    UINT16                  SubdeviceId;
+    UINT16                  Revision;
+    UINT16                  Reserved;
+    UINT32                  SharedInfoLength;
+
+    /* Shared data immediately follows (Length = SharedInfoLength) */
+
+} ACPI_CSRT_GROUP;
+
+/* Shared Info subtable */
+
+typedef struct acpi_csrt_shared_info
+{
+    UINT16                  MajorVersion;
+    UINT16                  MinorVersion;
+    UINT32                  MmioBaseLow;
+    UINT32                  MmioBaseHigh;
+    UINT32                  GsiInterrupt;
+    UINT8                   InterruptPolarity;
+    UINT8                   InterruptMode;
+    UINT8                   NumChannels;
+    UINT8                   DmaAddressWidth;
+    UINT16                  BaseRequestLine;
+    UINT16                  NumHandshakeSignals;
+    UINT32                  MaxBlockSize;
+
+    /* Resource descriptors immediately follow (Length = Group Length - SharedInfoLength) */
+
+} ACPI_CSRT_SHARED_INFO;
+
+/* Resource Descriptor subtable */
+
+typedef struct acpi_csrt_descriptor
+{
+    UINT32                  Length;
+    UINT16                  Type;
+    UINT16                  Subtype;
+    UINT32                  Uid;
+
+    /* Resource-specific information immediately follows */
+
+} ACPI_CSRT_DESCRIPTOR;
+
+
+/* Resource Types */
+
+#define ACPI_CSRT_TYPE_INTERRUPT    0x0001
+#define ACPI_CSRT_TYPE_TIMER        0x0002
+#define ACPI_CSRT_TYPE_DMA          0x0003
+
+/* Resource Subtypes */
+
+#define ACPI_CSRT_XRUPT_LINE        0x0000
+#define ACPI_CSRT_XRUPT_CONTROLLER  0x0001
+#define ACPI_CSRT_TIMER             0x0000
+#define ACPI_CSRT_DMA_CHANNEL       0x0000
+#define ACPI_CSRT_DMA_CONTROLLER    0x0001
+
+
+/*******************************************************************************
+ *
+ * DBG2 - Debug Port Table 2
+ *        Version 0 (Both main table and subtables)
+ *
+ * Conforms to "Microsoft Debug Port Table 2 (DBG2)", May 22 2012.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_dbg2
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  InfoOffset;
+    UINT32                  InfoCount;
+
+} ACPI_TABLE_DBG2;
+
+
+typedef struct acpi_dbg2_header
+{
+    UINT32                  InfoOffset;
+    UINT32                  InfoCount;
+
+} ACPI_DBG2_HEADER;
+
+
+/* Debug Device Information Subtable */
+
+typedef struct acpi_dbg2_device
+{
+    UINT8                   Revision;
+    UINT16                  Length;
+    UINT8                   RegisterCount;      /* Number of BaseAddress registers */
+    UINT16                  NamepathLength;
+    UINT16                  NamepathOffset;
+    UINT16                  OemDataLength;
+    UINT16                  OemDataOffset;
+    UINT16                  PortType;
+    UINT16                  PortSubtype;
+    UINT16                  Reserved;
+    UINT16                  BaseAddressOffset;
+    UINT16                  AddressSizeOffset;
+    /*
+     * Data that follows:
+     *    BaseAddress (required) - Each in 12-byte Generic Address Structure format.
+     *    AddressSize (required) - Array of UINT32 sizes corresponding to each BaseAddress register.
+     *    Namepath    (required) - Null terminated string. Single dot if not supported.
+     *    OemData     (optional) - Length is OemDataLength.
+     */
+} ACPI_DBG2_DEVICE;
+
+/* Types for PortType field above */
+
+#define ACPI_DBG2_SERIAL_PORT       0x8000
+#define ACPI_DBG2_1394_PORT         0x8001
+#define ACPI_DBG2_USB_PORT          0x8002
+#define ACPI_DBG2_NET_PORT          0x8003
+
+/* Subtypes for PortSubtype field above */
+
+#define ACPI_DBG2_16550_COMPATIBLE  0x0000
+#define ACPI_DBG2_16550_SUBSET      0x0001
+
+#define ACPI_DBG2_1394_STANDARD     0x0000
+
+#define ACPI_DBG2_USB_XHCI          0x0000
+#define ACPI_DBG2_USB_EHCI          0x0001
+
+
+/*******************************************************************************
+ *
+ * DBGP - Debug Port table
+ *        Version 1
+ *
+ * Conforms to the "Debug Port Specification", Version 1.00, 2/9/2000
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_dbgp
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   Type;               /* 0=full 16550, 1=subset of 16550 */
+    UINT8                   Reserved[3];
+    ACPI_GENERIC_ADDRESS    DebugPort;
+
+} ACPI_TABLE_DBGP;
+
+
+/*******************************************************************************
+ *
+ * DMAR - DMA Remapping table
+ *        Version 1
+ *
+ * Conforms to "Intel Virtualization Technology for Directed I/O",
+ * Version 2.2, Sept. 2013
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_dmar
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   Width;              /* Host Address Width */
+    UINT8                   Flags;
+    UINT8                   Reserved[10];
+
+} ACPI_TABLE_DMAR;
+
+/* Masks for Flags field above */
+
+#define ACPI_DMAR_INTR_REMAP        (1)
+
+
+/* DMAR subtable header */
+
+typedef struct acpi_dmar_header
+{
+    UINT16                  Type;
+    UINT16                  Length;
+
+} ACPI_DMAR_HEADER;
+
+/* Values for subtable type in ACPI_DMAR_HEADER */
+
+enum AcpiDmarType
+{
+    ACPI_DMAR_TYPE_HARDWARE_UNIT        = 0,
+    ACPI_DMAR_TYPE_RESERVED_MEMORY      = 1,
+    ACPI_DMAR_TYPE_ROOT_ATS             = 2,
+    ACPI_DMAR_TYPE_HARDWARE_AFFINITY    = 3,
+    ACPI_DMAR_TYPE_NAMESPACE            = 4,
+    ACPI_DMAR_TYPE_RESERVED             = 5     /* 5 and greater are reserved */
+};
+
+
+/* DMAR Device Scope structure */
+
+typedef struct acpi_dmar_device_scope
+{
+    UINT8                   EntryType;
+    UINT8                   Length;
+    UINT16                  Reserved;
+    UINT8                   EnumerationId;
+    UINT8                   Bus;
+
+} ACPI_DMAR_DEVICE_SCOPE;
+
+/* Values for EntryType in ACPI_DMAR_DEVICE_SCOPE - device types */
+
+enum AcpiDmarScopeType
+{
+    ACPI_DMAR_SCOPE_TYPE_NOT_USED       = 0,
+    ACPI_DMAR_SCOPE_TYPE_ENDPOINT       = 1,
+    ACPI_DMAR_SCOPE_TYPE_BRIDGE         = 2,
+    ACPI_DMAR_SCOPE_TYPE_IOAPIC         = 3,
+    ACPI_DMAR_SCOPE_TYPE_HPET           = 4,
+    ACPI_DMAR_SCOPE_TYPE_NAMESPACE      = 5,
+    ACPI_DMAR_SCOPE_TYPE_RESERVED       = 6     /* 6 and greater are reserved */
+};
+
+typedef struct acpi_dmar_pci_path
+{
+    UINT8                   Device;
+    UINT8                   Function;
+
+} ACPI_DMAR_PCI_PATH;
+
+
+/*
+ * DMAR Subtables, correspond to Type in ACPI_DMAR_HEADER
+ */
+
+/* 0: Hardware Unit Definition */
+
+typedef struct acpi_dmar_hardware_unit
+{
+    ACPI_DMAR_HEADER        Header;
+    UINT8                   Flags;
+    UINT8                   Reserved;
+    UINT16                  Segment;
+    UINT64                  Address;            /* Register Base Address */
+
+} ACPI_DMAR_HARDWARE_UNIT;
+
+/* Masks for Flags field above */
+
+#define ACPI_DMAR_INCLUDE_ALL       (1)
+
+
+/* 1: Reserved Memory Defininition */
+
+typedef struct acpi_dmar_reserved_memory
+{
+    ACPI_DMAR_HEADER        Header;
+    UINT16                  Reserved;
+    UINT16                  Segment;
+    UINT64                  BaseAddress;        /* 4K aligned base address */
+    UINT64                  EndAddress;         /* 4K aligned limit address */
+
+} ACPI_DMAR_RESERVED_MEMORY;
+
+/* Masks for Flags field above */
+
+#define ACPI_DMAR_ALLOW_ALL         (1)
+
+
+/* 2: Root Port ATS Capability Reporting Structure */
+
+typedef struct acpi_dmar_atsr
+{
+    ACPI_DMAR_HEADER        Header;
+    UINT8                   Flags;
+    UINT8                   Reserved;
+    UINT16                  Segment;
+
+} ACPI_DMAR_ATSR;
+
+/* Masks for Flags field above */
+
+#define ACPI_DMAR_ALL_PORTS         (1)
+
+
+/* 3: Remapping Hardware Static Affinity Structure */
+
+typedef struct acpi_dmar_rhsa
+{
+    ACPI_DMAR_HEADER        Header;
+    UINT32                  Reserved;
+    UINT64                  BaseAddress;
+    UINT32                  ProximityDomain;
+
+} ACPI_DMAR_RHSA;
+
+
+/* 4: ACPI Namespace Device Declaration Structure */
+
+typedef struct acpi_dmar_andd
+{
+    ACPI_DMAR_HEADER        Header;
+    UINT8                   Reserved[3];
+    UINT8                   DeviceNumber;
+    char                    DeviceName[1];
+
+} ACPI_DMAR_ANDD;
+
+
+/*******************************************************************************
+ *
+ * HPET - High Precision Event Timer table
+ *        Version 1
+ *
+ * Conforms to "IA-PC HPET (High Precision Event Timers) Specification",
+ * Version 1.0a, October 2004
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_hpet
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  Id;                 /* Hardware ID of event timer block */
+    ACPI_GENERIC_ADDRESS    Address;            /* Address of event timer block */
+    UINT8                   Sequence;           /* HPET sequence number */
+    UINT16                  MinimumTick;        /* Main counter min tick, periodic mode */
+    UINT8                   Flags;
+
+} ACPI_TABLE_HPET;
+
+/* Masks for Flags field above */
+
+#define ACPI_HPET_PAGE_PROTECT_MASK (3)
+
+/* Values for Page Protect flags */
+
+enum AcpiHpetPageProtect
+{
+    ACPI_HPET_NO_PAGE_PROTECT       = 0,
+    ACPI_HPET_PAGE_PROTECT4         = 1,
+    ACPI_HPET_PAGE_PROTECT64        = 2
+};
+
+
+/*******************************************************************************
+ *
+ * IBFT - Boot Firmware Table
+ *        Version 1
+ *
+ * Conforms to "iSCSI Boot Firmware Table (iBFT) as Defined in ACPI 3.0b
+ * Specification", Version 1.01, March 1, 2007
+ *
+ * Note: It appears that this table is not intended to appear in the RSDT/XSDT.
+ * Therefore, it is not currently supported by the disassembler.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_ibft
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   Reserved[12];
+
+} ACPI_TABLE_IBFT;
+
+
+/* IBFT common subtable header */
+
+typedef struct acpi_ibft_header
+{
+    UINT8                   Type;
+    UINT8                   Version;
+    UINT16                  Length;
+    UINT8                   Index;
+    UINT8                   Flags;
+
+} ACPI_IBFT_HEADER;
+
+/* Values for Type field above */
+
+enum AcpiIbftType
+{
+    ACPI_IBFT_TYPE_NOT_USED         = 0,
+    ACPI_IBFT_TYPE_CONTROL          = 1,
+    ACPI_IBFT_TYPE_INITIATOR        = 2,
+    ACPI_IBFT_TYPE_NIC              = 3,
+    ACPI_IBFT_TYPE_TARGET           = 4,
+    ACPI_IBFT_TYPE_EXTENSIONS       = 5,
+    ACPI_IBFT_TYPE_RESERVED         = 6     /* 6 and greater are reserved */
+};
+
+
+/* IBFT subtables */
+
+typedef struct acpi_ibft_control
+{
+    ACPI_IBFT_HEADER        Header;
+    UINT16                  Extensions;
+    UINT16                  InitiatorOffset;
+    UINT16                  Nic0Offset;
+    UINT16                  Target0Offset;
+    UINT16                  Nic1Offset;
+    UINT16                  Target1Offset;
+
+} ACPI_IBFT_CONTROL;
+
+typedef struct acpi_ibft_initiator
+{
+    ACPI_IBFT_HEADER        Header;
+    UINT8                   SnsServer[16];
+    UINT8                   SlpServer[16];
+    UINT8                   PrimaryServer[16];
+    UINT8                   SecondaryServer[16];
+    UINT16                  NameLength;
+    UINT16                  NameOffset;
+
+} ACPI_IBFT_INITIATOR;
+
+typedef struct acpi_ibft_nic
+{
+    ACPI_IBFT_HEADER        Header;
+    UINT8                   IpAddress[16];
+    UINT8                   SubnetMaskPrefix;
+    UINT8                   Origin;
+    UINT8                   Gateway[16];
+    UINT8                   PrimaryDns[16];
+    UINT8                   SecondaryDns[16];
+    UINT8                   Dhcp[16];
+    UINT16                  Vlan;
+    UINT8                   MacAddress[6];
+    UINT16                  PciAddress;
+    UINT16                  NameLength;
+    UINT16                  NameOffset;
+
+} ACPI_IBFT_NIC;
+
+typedef struct acpi_ibft_target
+{
+    ACPI_IBFT_HEADER        Header;
+    UINT8                   TargetIpAddress[16];
+    UINT16                  TargetIpSocket;
+    UINT8                   TargetBootLun[8];
+    UINT8                   ChapType;
+    UINT8                   NicAssociation;
+    UINT16                  TargetNameLength;
+    UINT16                  TargetNameOffset;
+    UINT16                  ChapNameLength;
+    UINT16                  ChapNameOffset;
+    UINT16                  ChapSecretLength;
+    UINT16                  ChapSecretOffset;
+    UINT16                  ReverseChapNameLength;
+    UINT16                  ReverseChapNameOffset;
+    UINT16                  ReverseChapSecretLength;
+    UINT16                  ReverseChapSecretOffset;
+
+} ACPI_IBFT_TARGET;
+
+
+/*******************************************************************************
+ *
+ * IORT - IO Remapping Table
+ *
+ * Conforms to "IO Remapping Table System Software on ARM Platforms",
+ * Document number: ARM DEN 0049A, 2015
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_iort
+{
+    ACPI_TABLE_HEADER       Header;
+    UINT32                  NodeCount;
+    UINT32                  NodeOffset;
+    UINT32                  Reserved;
+
+} ACPI_TABLE_IORT;
+
+
+/*
+ * IORT subtables
+ */
+typedef struct acpi_iort_node
+{
+    UINT8                   Type;
+    UINT16                  Length;
+    UINT8                   Revision;
+    UINT32                  Reserved;
+    UINT32                  MappingCount;
+    UINT32                  MappingOffset;
+    char                    NodeData[1];
+
+} ACPI_IORT_NODE;
+
+/* Values for subtable Type above */
+
+enum AcpiIortNodeType
+{
+    ACPI_IORT_NODE_ITS_GROUP            = 0x00,
+    ACPI_IORT_NODE_NAMED_COMPONENT      = 0x01,
+    ACPI_IORT_NODE_PCI_ROOT_COMPLEX     = 0x02,
+    ACPI_IORT_NODE_SMMU                 = 0x03
+};
+
+
+typedef struct acpi_iort_id_mapping
+{
+    UINT32                  InputBase;          /* Lowest value in input range */
+    UINT32                  IdCount;            /* Number of IDs */
+    UINT32                  OutputBase;         /* Lowest value in output range */
+    UINT32                  OutputReference;    /* A reference to the output node */
+    UINT32                  Flags;
+
+} ACPI_IORT_ID_MAPPING;
+
+/* Masks for Flags field above for IORT subtable */
+
+#define ACPI_IORT_ID_SINGLE_MAPPING (1)
+
+
+typedef struct acpi_iort_memory_access
+{
+    UINT32                  CacheCoherency;
+    UINT8                   Hints;
+    UINT16                  Reserved;
+    UINT8                   MemoryFlags;
+
+} ACPI_IORT_MEMORY_ACCESS;
+
+/* Values for CacheCoherency field above */
+
+#define ACPI_IORT_NODE_COHERENT         0x00000001  /* The device node is fully coherent */
+#define ACPI_IORT_NODE_NOT_COHERENT     0x00000000  /* The device node is not coherent */
+
+/* Masks for Hints field above */
+
+#define ACPI_IORT_HT_TRANSIENT          (1)
+#define ACPI_IORT_HT_WRITE              (1<<1)
+#define ACPI_IORT_HT_READ               (1<<2)
+#define ACPI_IORT_HT_OVERRIDE           (1<<3)
+
+/* Masks for MemoryFlags field above */
+
+#define ACPI_IORT_MF_COHERENCY          (1)
+#define ACPI_IORT_MF_ATTRIBUTES         (1<<1)
+
+
+/*
+ * IORT node specific subtables
+ */
+typedef struct acpi_iort_its_group
+{
+    UINT32                  ItsCount;
+    UINT32                  Identifiers[1];         /* GIC ITS identifier arrary */
+
+} ACPI_IORT_ITS_GROUP;
+
+
+typedef struct acpi_iort_named_component
+{
+    UINT32                  NodeFlags;
+    UINT64                  MemoryProperties;       /* Memory access properties */
+    UINT8                   MemoryAddressLimit;     /* Memory address size limit */
+    char                    DeviceName[1];          /* Path of namespace object */
+
+} ACPI_IORT_NAMED_COMPONENT;
+
+
+typedef struct acpi_iort_root_complex
+{
+    UINT64                  MemoryProperties;       /* Memory access properties */
+    UINT32                  AtsAttribute;
+    UINT32                  PciSegmentNumber;
+
+} ACPI_IORT_ROOT_COMPLEX;
+
+/* Values for AtsAttribute field above */
+
+#define ACPI_IORT_ATS_SUPPORTED         0x00000001  /* The root complex supports ATS */
+#define ACPI_IORT_ATS_UNSUPPORTED       0x00000000  /* The root complex doesn't support ATS */
+
+
+typedef struct acpi_iort_smmu
+{
+    UINT64                  BaseAddress;            /* SMMU base address */
+    UINT64                  Span;                   /* Length of memory range */
+    UINT32                  Model;
+    UINT32                  Flags;
+    UINT32                  GlobalInterruptOffset;
+    UINT32                  ContextInterruptCount;
+    UINT32                  ContextInterruptOffset;
+    UINT32                  PmuInterruptCount;
+    UINT32                  PmuInterruptOffset;
+    UINT64                  Interrupts[1];          /* Interrupt array */
+
+} ACPI_IORT_SMMU;
+
+/* Values for Model field above */
+
+#define ACPI_IORT_SMMU_V1               0x00000000  /* Generic SMMUv1 */
+#define ACPI_IORT_SMMU_V2               0x00000001  /* Generic SMMUv2 */
+#define ACPI_IORT_SMMU_CORELINK_MMU400  0x00000002  /* ARM Corelink MMU-400 */
+#define ACPI_IORT_SMMU_CORELINK_MMU500  0x00000003  /* ARM Corelink MMU-500 */
+
+/* Masks for Flags field above */
+
+#define ACPI_IORT_SMMU_DVM_SUPPORTED    (1)
+#define ACPI_IORT_SMMU_COHERENT_WALK    (1<<1)
+
+
+/*******************************************************************************
+ *
+ * IVRS - I/O Virtualization Reporting Structure
+ *        Version 1
+ *
+ * Conforms to "AMD I/O Virtualization Technology (IOMMU) Specification",
+ * Revision 1.26, February 2009.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_ivrs
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  Info;               /* Common virtualization info */
+    UINT64                  Reserved;
+
+} ACPI_TABLE_IVRS;
+
+/* Values for Info field above */
+
+#define ACPI_IVRS_PHYSICAL_SIZE     0x00007F00  /* 7 bits, physical address size */
+#define ACPI_IVRS_VIRTUAL_SIZE      0x003F8000  /* 7 bits, virtual address size */
+#define ACPI_IVRS_ATS_RESERVED      0x00400000  /* ATS address translation range reserved */
+
+
+/* IVRS subtable header */
+
+typedef struct acpi_ivrs_header
+{
+    UINT8                   Type;               /* Subtable type */
+    UINT8                   Flags;
+    UINT16                  Length;             /* Subtable length */
+    UINT16                  DeviceId;           /* ID of IOMMU */
+
+} ACPI_IVRS_HEADER;
+
+/* Values for subtable Type above */
+
+enum AcpiIvrsType
+{
+    ACPI_IVRS_TYPE_HARDWARE         = 0x10,
+    ACPI_IVRS_TYPE_MEMORY1          = 0x20,
+    ACPI_IVRS_TYPE_MEMORY2          = 0x21,
+    ACPI_IVRS_TYPE_MEMORY3          = 0x22
+};
+
+/* Masks for Flags field above for IVHD subtable */
+
+#define ACPI_IVHD_TT_ENABLE         (1)
+#define ACPI_IVHD_PASS_PW           (1<<1)
+#define ACPI_IVHD_RES_PASS_PW       (1<<2)
+#define ACPI_IVHD_ISOC              (1<<3)
+#define ACPI_IVHD_IOTLB             (1<<4)
+
+/* Masks for Flags field above for IVMD subtable */
+
+#define ACPI_IVMD_UNITY             (1)
+#define ACPI_IVMD_READ              (1<<1)
+#define ACPI_IVMD_WRITE             (1<<2)
+#define ACPI_IVMD_EXCLUSION_RANGE   (1<<3)
+
+
+/*
+ * IVRS subtables, correspond to Type in ACPI_IVRS_HEADER
+ */
+
+/* 0x10: I/O Virtualization Hardware Definition Block (IVHD) */
+
+typedef struct acpi_ivrs_hardware
+{
+    ACPI_IVRS_HEADER        Header;
+    UINT16                  CapabilityOffset;   /* Offset for IOMMU control fields */
+    UINT64                  BaseAddress;        /* IOMMU control registers */
+    UINT16                  PciSegmentGroup;
+    UINT16                  Info;               /* MSI number and unit ID */
+    UINT32                  Reserved;
+
+} ACPI_IVRS_HARDWARE;
+
+/* Masks for Info field above */
+
+#define ACPI_IVHD_MSI_NUMBER_MASK   0x001F      /* 5 bits, MSI message number */
+#define ACPI_IVHD_UNIT_ID_MASK      0x1F00      /* 5 bits, UnitID */
+
+
+/*
+ * Device Entries for IVHD subtable, appear after ACPI_IVRS_HARDWARE structure.
+ * Upper two bits of the Type field are the (encoded) length of the structure.
+ * Currently, only 4 and 8 byte entries are defined. 16 and 32 byte entries
+ * are reserved for future use but not defined.
+ */
+typedef struct acpi_ivrs_de_header
+{
+    UINT8                   Type;
+    UINT16                  Id;
+    UINT8                   DataSetting;
+
+} ACPI_IVRS_DE_HEADER;
+
+/* Length of device entry is in the top two bits of Type field above */
+
+#define ACPI_IVHD_ENTRY_LENGTH      0xC0
+
+/* Values for device entry Type field above */
+
+enum AcpiIvrsDeviceEntryType
+{
+    /* 4-byte device entries, all use ACPI_IVRS_DEVICE4 */
+
+    ACPI_IVRS_TYPE_PAD4             = 0,
+    ACPI_IVRS_TYPE_ALL              = 1,
+    ACPI_IVRS_TYPE_SELECT           = 2,
+    ACPI_IVRS_TYPE_START            = 3,
+    ACPI_IVRS_TYPE_END              = 4,
+
+    /* 8-byte device entries */
+
+    ACPI_IVRS_TYPE_PAD8             = 64,
+    ACPI_IVRS_TYPE_NOT_USED         = 65,
+    ACPI_IVRS_TYPE_ALIAS_SELECT     = 66, /* Uses ACPI_IVRS_DEVICE8A */
+    ACPI_IVRS_TYPE_ALIAS_START      = 67, /* Uses ACPI_IVRS_DEVICE8A */
+    ACPI_IVRS_TYPE_EXT_SELECT       = 70, /* Uses ACPI_IVRS_DEVICE8B */
+    ACPI_IVRS_TYPE_EXT_START        = 71, /* Uses ACPI_IVRS_DEVICE8B */
+    ACPI_IVRS_TYPE_SPECIAL          = 72  /* Uses ACPI_IVRS_DEVICE8C */
+};
+
+/* Values for Data field above */
+
+#define ACPI_IVHD_INIT_PASS         (1)
+#define ACPI_IVHD_EINT_PASS         (1<<1)
+#define ACPI_IVHD_NMI_PASS          (1<<2)
+#define ACPI_IVHD_SYSTEM_MGMT       (3<<4)
+#define ACPI_IVHD_LINT0_PASS        (1<<6)
+#define ACPI_IVHD_LINT1_PASS        (1<<7)
+
+
+/* Types 0-4: 4-byte device entry */
+
+typedef struct acpi_ivrs_device4
+{
+    ACPI_IVRS_DE_HEADER     Header;
+
+} ACPI_IVRS_DEVICE4;
+
+/* Types 66-67: 8-byte device entry */
+
+typedef struct acpi_ivrs_device8a
+{
+    ACPI_IVRS_DE_HEADER     Header;
+    UINT8                   Reserved1;
+    UINT16                  UsedId;
+    UINT8                   Reserved2;
+
+} ACPI_IVRS_DEVICE8A;
+
+/* Types 70-71: 8-byte device entry */
+
+typedef struct acpi_ivrs_device8b
+{
+    ACPI_IVRS_DE_HEADER     Header;
+    UINT32                  ExtendedData;
+
+} ACPI_IVRS_DEVICE8B;
+
+/* Values for ExtendedData above */
+
+#define ACPI_IVHD_ATS_DISABLED      (1<<31)
+
+/* Type 72: 8-byte device entry */
+
+typedef struct acpi_ivrs_device8c
+{
+    ACPI_IVRS_DE_HEADER     Header;
+    UINT8                   Handle;
+    UINT16                  UsedId;
+    UINT8                   Variety;
+
+} ACPI_IVRS_DEVICE8C;
+
+/* Values for Variety field above */
+
+#define ACPI_IVHD_IOAPIC            1
+#define ACPI_IVHD_HPET              2
+
+
+/* 0x20, 0x21, 0x22: I/O Virtualization Memory Definition Block (IVMD) */
+
+typedef struct acpi_ivrs_memory
+{
+    ACPI_IVRS_HEADER        Header;
+    UINT16                  AuxData;
+    UINT64                  Reserved;
+    UINT64                  StartAddress;
+    UINT64                  MemoryLength;
+
+} ACPI_IVRS_MEMORY;
+
+
+/*******************************************************************************
+ *
+ * LPIT - Low Power Idle Table
+ *
+ * Conforms to "ACPI Low Power Idle Table (LPIT)" July 2014.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_lpit
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+
+} ACPI_TABLE_LPIT;
+
+
+/* LPIT subtable header */
+
+typedef struct acpi_lpit_header
+{
+    UINT32                  Type;               /* Subtable type */
+    UINT32                  Length;             /* Subtable length */
+    UINT16                  UniqueId;
+    UINT16                  Reserved;
+    UINT32                  Flags;
+
+} ACPI_LPIT_HEADER;
+
+/* Values for subtable Type above */
+
+enum AcpiLpitType
+{
+    ACPI_LPIT_TYPE_NATIVE_CSTATE    = 0x00,
+    ACPI_LPIT_TYPE_RESERVED         = 0x01      /* 1 and above are reserved */
+};
+
+/* Masks for Flags field above  */
+
+#define ACPI_LPIT_STATE_DISABLED    (1)
+#define ACPI_LPIT_NO_COUNTER        (1<<1)
+
+/*
+ * LPIT subtables, correspond to Type in ACPI_LPIT_HEADER
+ */
+
+/* 0x00: Native C-state instruction based LPI structure */
+
+typedef struct acpi_lpit_native
+{
+    ACPI_LPIT_HEADER        Header;
+    ACPI_GENERIC_ADDRESS    EntryTrigger;
+    UINT32                  Residency;
+    UINT32                  Latency;
+    ACPI_GENERIC_ADDRESS    ResidencyCounter;
+    UINT64                  CounterFrequency;
+
+} ACPI_LPIT_NATIVE;
+
+
+/*******************************************************************************
+ *
+ * MCFG - PCI Memory Mapped Configuration table and subtable
+ *        Version 1
+ *
+ * Conforms to "PCI Firmware Specification", Revision 3.0, June 20, 2005
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_mcfg
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   Reserved[8];
+
+} ACPI_TABLE_MCFG;
+
+
+/* Subtable */
+
+typedef struct acpi_mcfg_allocation
+{
+    UINT64                  Address;            /* Base address, processor-relative */
+    UINT16                  PciSegment;         /* PCI segment group number */
+    UINT8                   StartBusNumber;     /* Starting PCI Bus number */
+    UINT8                   EndBusNumber;       /* Final PCI Bus number */
+    UINT32                  Reserved;
+
+} ACPI_MCFG_ALLOCATION;
+
+
+/*******************************************************************************
+ *
+ * MCHI - Management Controller Host Interface Table
+ *        Version 1
+ *
+ * Conforms to "Management Component Transport Protocol (MCTP) Host
+ * Interface Specification", Revision 1.0.0a, October 13, 2009
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_mchi
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   InterfaceType;
+    UINT8                   Protocol;
+    UINT64                  ProtocolData;
+    UINT8                   InterruptType;
+    UINT8                   Gpe;
+    UINT8                   PciDeviceFlag;
+    UINT32                  GlobalInterrupt;
+    ACPI_GENERIC_ADDRESS    ControlRegister;
+    UINT8                   PciSegment;
+    UINT8                   PciBus;
+    UINT8                   PciDevice;
+    UINT8                   PciFunction;
+
+} ACPI_TABLE_MCHI;
+
+
+/*******************************************************************************
+ *
+ * MSDM - Microsoft Data Management table
+ *
+ * Conforms to "Microsoft Software Licensing Tables (SLIC and MSDM)",
+ * November 29, 2011. Copyright 2011 Microsoft
+ *
+ ******************************************************************************/
+
+/* Basic MSDM table is only the common ACPI header */
+
+typedef struct acpi_table_msdm
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+
+} ACPI_TABLE_MSDM;
+
+
+/*******************************************************************************
+ *
+ * MTMR - MID Timer Table
+ *        Version 1
+ *
+ * Conforms to "Simple Firmware Interface Specification",
+ * Draft 0.8.2, Oct 19, 2010
+ * NOTE: The ACPI MTMR is equivalent to the SFI MTMR table.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_mtmr
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+
+} ACPI_TABLE_MTMR;
+
+/* MTMR entry */
+
+typedef struct acpi_mtmr_entry
+{
+    ACPI_GENERIC_ADDRESS    PhysicalAddress;
+    UINT32                  Frequency;
+    UINT32                  Irq;
+
+} ACPI_MTMR_ENTRY;
+
+
+/*******************************************************************************
+ *
+ * SLIC - Software Licensing Description Table
+ *
+ * Conforms to "Microsoft Software Licensing Tables (SLIC and MSDM)",
+ * November 29, 2011. Copyright 2011 Microsoft
+ *
+ ******************************************************************************/
+
+/* Basic SLIC table is only the common ACPI header */
+
+typedef struct acpi_table_slic
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+
+} ACPI_TABLE_SLIC;
+
+
+/*******************************************************************************
+ *
+ * SPCR - Serial Port Console Redirection table
+ *        Version 1
+ *
+ * Conforms to "Serial Port Console Redirection Table",
+ * Version 1.00, January 11, 2002
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_spcr
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   InterfaceType;      /* 0=full 16550, 1=subset of 16550 */
+    UINT8                   Reserved[3];
+    ACPI_GENERIC_ADDRESS    SerialPort;
+    UINT8                   InterruptType;
+    UINT8                   PcInterrupt;
+    UINT32                  Interrupt;
+    UINT8                   BaudRate;
+    UINT8                   Parity;
+    UINT8                   StopBits;
+    UINT8                   FlowControl;
+    UINT8                   TerminalType;
+    UINT8                   Reserved1;
+    UINT16                  PciDeviceId;
+    UINT16                  PciVendorId;
+    UINT8                   PciBus;
+    UINT8                   PciDevice;
+    UINT8                   PciFunction;
+    UINT32                  PciFlags;
+    UINT8                   PciSegment;
+    UINT32                  Reserved2;
+
+} ACPI_TABLE_SPCR;
+
+/* Masks for PciFlags field above */
+
+#define ACPI_SPCR_DO_NOT_DISABLE    (1)
+
+
+/*******************************************************************************
+ *
+ * SPMI - Server Platform Management Interface table
+ *        Version 5
+ *
+ * Conforms to "Intelligent Platform Management Interface Specification
+ * Second Generation v2.0", Document Revision 1.0, February 12, 2004 with
+ * June 12, 2009 markup.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_spmi
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   InterfaceType;
+    UINT8                   Reserved;           /* Must be 1 */
+    UINT16                  SpecRevision;       /* Version of IPMI */
+    UINT8                   InterruptType;
+    UINT8                   GpeNumber;          /* GPE assigned */
+    UINT8                   Reserved1;
+    UINT8                   PciDeviceFlag;
+    UINT32                  Interrupt;
+    ACPI_GENERIC_ADDRESS    IpmiRegister;
+    UINT8                   PciSegment;
+    UINT8                   PciBus;
+    UINT8                   PciDevice;
+    UINT8                   PciFunction;
+    UINT8                   Reserved2;
+
+} ACPI_TABLE_SPMI;
+
+/* Values for InterfaceType above */
+
+enum AcpiSpmiInterfaceTypes
+{
+    ACPI_SPMI_NOT_USED              = 0,
+    ACPI_SPMI_KEYBOARD              = 1,
+    ACPI_SPMI_SMI                   = 2,
+    ACPI_SPMI_BLOCK_TRANSFER        = 3,
+    ACPI_SPMI_SMBUS                 = 4,
+    ACPI_SPMI_RESERVED              = 5         /* 5 and above are reserved */
+};
+
+
+/*******************************************************************************
+ *
+ * TCPA - Trusted Computing Platform Alliance table
+ *        Version 2
+ *
+ * Conforms to "TCG ACPI Specification, Family 1.2 and 2.0",
+ * December 19, 2014
+ *
+ * NOTE: There are two versions of the table with the same signature --
+ * the client version and the server version. The common PlatformClass
+ * field is used to differentiate the two types of tables.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_tcpa_hdr
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT16                  PlatformClass;
+
+} ACPI_TABLE_TCPA_HDR;
+
+/*
+ * Values for PlatformClass above.
+ * This is how the client and server subtables are differentiated
+ */
+#define ACPI_TCPA_CLIENT_TABLE          0
+#define ACPI_TCPA_SERVER_TABLE          1
+
+
+typedef struct acpi_table_tcpa_client
+{
+    UINT32                  MinimumLogLength;   /* Minimum length for the event log area */
+    UINT64                  LogAddress;         /* Address of the event log area */
+
+} ACPI_TABLE_TCPA_CLIENT;
+
+typedef struct acpi_table_tcpa_server
+{
+    UINT16                  Reserved;
+    UINT64                  MinimumLogLength;   /* Minimum length for the event log area */
+    UINT64                  LogAddress;         /* Address of the event log area */
+    UINT16                  SpecRevision;
+    UINT8                   DeviceFlags;
+    UINT8                   InterruptFlags;
+    UINT8                   GpeNumber;
+    UINT8                   Reserved2[3];
+    UINT32                  GlobalInterrupt;
+    ACPI_GENERIC_ADDRESS    Address;
+    UINT32                  Reserved3;
+    ACPI_GENERIC_ADDRESS    ConfigAddress;
+    UINT8                   Group;
+    UINT8                   Bus;                /* PCI Bus/Segment/Function numbers */
+    UINT8                   Device;
+    UINT8                   Function;
+
+} ACPI_TABLE_TCPA_SERVER;
+
+/* Values for DeviceFlags above */
+
+#define ACPI_TCPA_PCI_DEVICE            (1)
+#define ACPI_TCPA_BUS_PNP               (1<<1)
+#define ACPI_TCPA_ADDRESS_VALID         (1<<2)
+
+/* Values for InterruptFlags above */
+
+#define ACPI_TCPA_INTERRUPT_MODE        (1)
+#define ACPI_TCPA_INTERRUPT_POLARITY    (1<<1)
+#define ACPI_TCPA_SCI_VIA_GPE           (1<<2)
+#define ACPI_TCPA_GLOBAL_INTERRUPT      (1<<3)
+
+
+/*******************************************************************************
+ *
+ * TPM2 - Trusted Platform Module (TPM) 2.0 Hardware Interface Table
+ *        Version 4
+ *
+ * Conforms to "TCG ACPI Specification, Family 1.2 and 2.0",
+ * December 19, 2014
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_tpm2
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT16                  PlatformClass;
+    UINT16                  Reserved;
+    UINT64                  ControlAddress;
+    UINT32                  StartMethod;
+
+    /* Platform-specific data follows */
+
+} ACPI_TABLE_TPM2;
+
+/* Values for StartMethod above */
+
+#define ACPI_TPM2_NOT_ALLOWED                       0
+#define ACPI_TPM2_START_METHOD                      2
+#define ACPI_TPM2_MEMORY_MAPPED                     6
+#define ACPI_TPM2_COMMAND_BUFFER                    7
+#define ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD  8
+
+
+/*******************************************************************************
+ *
+ * UEFI - UEFI Boot optimization Table
+ *        Version 1
+ *
+ * Conforms to "Unified Extensible Firmware Interface Specification",
+ * Version 2.3, May 8, 2009
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_uefi
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   Identifier[16];     /* UUID identifier */
+    UINT16                  DataOffset;         /* Offset of remaining data in table */
+
+} ACPI_TABLE_UEFI;
+
+
+/*******************************************************************************
+ *
+ * VRTC - Virtual Real Time Clock Table
+ *        Version 1
+ *
+ * Conforms to "Simple Firmware Interface Specification",
+ * Draft 0.8.2, Oct 19, 2010
+ * NOTE: The ACPI VRTC is equivalent to The SFI MRTC table.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_vrtc
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+
+} ACPI_TABLE_VRTC;
+
+/* VRTC entry */
+
+typedef struct acpi_vrtc_entry
+{
+    ACPI_GENERIC_ADDRESS    PhysicalAddress;
+    UINT32                  Irq;
+
+} ACPI_VRTC_ENTRY;
+
+
+/*******************************************************************************
+ *
+ * WAET - Windows ACPI Emulated devices Table
+ *        Version 1
+ *
+ * Conforms to "Windows ACPI Emulated Devices Table", version 1.0, April 6, 2009
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_waet
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  Flags;
+
+} ACPI_TABLE_WAET;
+
+/* Masks for Flags field above */
+
+#define ACPI_WAET_RTC_NO_ACK        (1)         /* RTC requires no int acknowledge */
+#define ACPI_WAET_TIMER_ONE_READ    (1<<1)      /* PM timer requires only one read */
+
+
+/*******************************************************************************
+ *
+ * WDAT - Watchdog Action Table
+ *        Version 1
+ *
+ * Conforms to "Hardware Watchdog Timers Design Specification",
+ * Copyright 2006 Microsoft Corporation.
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_wdat
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  HeaderLength;       /* Watchdog Header Length */
+    UINT16                  PciSegment;         /* PCI Segment number */
+    UINT8                   PciBus;             /* PCI Bus number */
+    UINT8                   PciDevice;          /* PCI Device number */
+    UINT8                   PciFunction;        /* PCI Function number */
+    UINT8                   Reserved[3];
+    UINT32                  TimerPeriod;        /* Period of one timer count (msec) */
+    UINT32                  MaxCount;           /* Maximum counter value supported */
+    UINT32                  MinCount;           /* Minimum counter value */
+    UINT8                   Flags;
+    UINT8                   Reserved2[3];
+    UINT32                  Entries;            /* Number of watchdog entries that follow */
+
+} ACPI_TABLE_WDAT;
+
+/* Masks for Flags field above */
+
+#define ACPI_WDAT_ENABLED           (1)
+#define ACPI_WDAT_STOPPED           0x80
+
+
+/* WDAT Instruction Entries (actions) */
+
+typedef struct acpi_wdat_entry
+{
+    UINT8                   Action;
+    UINT8                   Instruction;
+    UINT16                  Reserved;
+    ACPI_GENERIC_ADDRESS    RegisterRegion;
+    UINT32                  Value;              /* Value used with Read/Write register */
+    UINT32                  Mask;               /* Bitmask required for this register instruction */
+
+} ACPI_WDAT_ENTRY;
+
+/* Values for Action field above */
+
+enum AcpiWdatActions
+{
+    ACPI_WDAT_RESET                 = 1,
+    ACPI_WDAT_GET_CURRENT_COUNTDOWN = 4,
+    ACPI_WDAT_GET_COUNTDOWN         = 5,
+    ACPI_WDAT_SET_COUNTDOWN         = 6,
+    ACPI_WDAT_GET_RUNNING_STATE     = 8,
+    ACPI_WDAT_SET_RUNNING_STATE     = 9,
+    ACPI_WDAT_GET_STOPPED_STATE     = 10,
+    ACPI_WDAT_SET_STOPPED_STATE     = 11,
+    ACPI_WDAT_GET_REBOOT            = 16,
+    ACPI_WDAT_SET_REBOOT            = 17,
+    ACPI_WDAT_GET_SHUTDOWN          = 18,
+    ACPI_WDAT_SET_SHUTDOWN          = 19,
+    ACPI_WDAT_GET_STATUS            = 32,
+    ACPI_WDAT_SET_STATUS            = 33,
+    ACPI_WDAT_ACTION_RESERVED       = 34    /* 34 and greater are reserved */
+};
+
+/* Values for Instruction field above */
+
+enum AcpiWdatInstructions
+{
+    ACPI_WDAT_READ_VALUE            = 0,
+    ACPI_WDAT_READ_COUNTDOWN        = 1,
+    ACPI_WDAT_WRITE_VALUE           = 2,
+    ACPI_WDAT_WRITE_COUNTDOWN       = 3,
+    ACPI_WDAT_INSTRUCTION_RESERVED  = 4,    /* 4 and greater are reserved */
+    ACPI_WDAT_PRESERVE_REGISTER     = 0x80  /* Except for this value */
+};
+
+
+/*******************************************************************************
+ *
+ * WDDT - Watchdog Descriptor Table
+ *        Version 1
+ *
+ * Conforms to "Using the Intel ICH Family Watchdog Timer (WDT)",
+ * Version 001, September 2002
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_wddt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT16                  SpecVersion;
+    UINT16                  TableVersion;
+    UINT16                  PciVendorId;
+    ACPI_GENERIC_ADDRESS    Address;
+    UINT16                  MaxCount;           /* Maximum counter value supported */
+    UINT16                  MinCount;           /* Minimum counter value supported */
+    UINT16                  Period;
+    UINT16                  Status;
+    UINT16                  Capability;
+
+} ACPI_TABLE_WDDT;
+
+/* Flags for Status field above */
+
+#define ACPI_WDDT_AVAILABLE     (1)
+#define ACPI_WDDT_ACTIVE        (1<<1)
+#define ACPI_WDDT_TCO_OS_OWNED  (1<<2)
+#define ACPI_WDDT_USER_RESET    (1<<11)
+#define ACPI_WDDT_WDT_RESET     (1<<12)
+#define ACPI_WDDT_POWER_FAIL    (1<<13)
+#define ACPI_WDDT_UNKNOWN_RESET (1<<14)
+
+/* Flags for Capability field above */
+
+#define ACPI_WDDT_AUTO_RESET    (1)
+#define ACPI_WDDT_ALERT_SUPPORT (1<<1)
+
+
+/*******************************************************************************
+ *
+ * WDRT - Watchdog Resource Table
+ *        Version 1
+ *
+ * Conforms to "Watchdog Timer Hardware Requirements for Windows Server 2003",
+ * Version 1.01, August 28, 2006
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_wdrt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    ACPI_GENERIC_ADDRESS    ControlRegister;
+    ACPI_GENERIC_ADDRESS    CountRegister;
+    UINT16                  PciDeviceId;
+    UINT16                  PciVendorId;
+    UINT8                   PciBus;             /* PCI Bus number */
+    UINT8                   PciDevice;          /* PCI Device number */
+    UINT8                   PciFunction;        /* PCI Function number */
+    UINT8                   PciSegment;         /* PCI Segment number */
+    UINT16                  MaxCount;           /* Maximum counter value supported */
+    UINT8                   Units;
+
+} ACPI_TABLE_WDRT;
+
+
+/* Reset to default packing */
+
+#pragma pack()
+
+#endif /* __ACTBL2_H__ */

+ 894 - 0
kernel/include/acpica/actbl3.h

@@ -0,0 +1,894 @@
+/******************************************************************************
+ *
+ * Name: actbl3.h - ACPI Table Definitions
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACTBL3_H__
+#define __ACTBL3_H__
+
+
+/*******************************************************************************
+ *
+ * Additional ACPI Tables (3)
+ *
+ * These tables are not consumed directly by the ACPICA subsystem, but are
+ * included here to support device drivers and the AML disassembler.
+ *
+ * In general, the tables in this file are fully defined within the ACPI
+ * specification.
+ *
+ ******************************************************************************/
+
+
+/*
+ * Values for description table header signatures for tables defined in this
+ * file. Useful because they make it more difficult to inadvertently type in
+ * the wrong signature.
+ */
+#define ACPI_SIG_BGRT           "BGRT"      /* Boot Graphics Resource Table */
+#define ACPI_SIG_DRTM           "DRTM"      /* Dynamic Root of Trust for Measurement table */
+#define ACPI_SIG_FPDT           "FPDT"      /* Firmware Performance Data Table */
+#define ACPI_SIG_GTDT           "GTDT"      /* Generic Timer Description Table */
+#define ACPI_SIG_MPST           "MPST"      /* Memory Power State Table */
+#define ACPI_SIG_PCCT           "PCCT"      /* Platform Communications Channel Table */
+#define ACPI_SIG_PMTT           "PMTT"      /* Platform Memory Topology Table */
+#define ACPI_SIG_RASF           "RASF"      /* RAS Feature table */
+#define ACPI_SIG_STAO           "STAO"      /* Status Override table */
+#define ACPI_SIG_WPBT           "WPBT"      /* Windows Platform Binary Table */
+#define ACPI_SIG_XENV           "XENV"      /* Xen Environment table */
+
+#define ACPI_SIG_S3PT           "S3PT"      /* S3 Performance (sub)Table */
+#define ACPI_SIG_PCCS           "PCC"       /* PCC Shared Memory Region */
+
+/* Reserved table signatures */
+
+#define ACPI_SIG_MATR           "MATR"      /* Memory Address Translation Table */
+#define ACPI_SIG_MSDM           "MSDM"      /* Microsoft Data Management Table */
+
+/*
+ * All tables must be byte-packed to match the ACPI specification, since
+ * the tables are provided by the system BIOS.
+ */
+#pragma pack(1)
+
+/*
+ * Note: C bitfields are not used for this reason:
+ *
+ * "Bitfields are great and easy to read, but unfortunately the C language
+ * does not specify the layout of bitfields in memory, which means they are
+ * essentially useless for dealing with packed data in on-disk formats or
+ * binary wire protocols." (Or ACPI tables and buffers.) "If you ask me,
+ * this decision was a design error in C. Ritchie could have picked an order
+ * and stuck with it." Norman Ramsey.
+ * See http://stackoverflow.com/a/1053662/41661
+ */
+
+
+/*******************************************************************************
+ *
+ * BGRT - Boot Graphics Resource Table (ACPI 5.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_bgrt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT16                  Version;
+    UINT8                   Status;
+    UINT8                   ImageType;
+    UINT64                  ImageAddress;
+    UINT32                  ImageOffsetX;
+    UINT32                  ImageOffsetY;
+
+} ACPI_TABLE_BGRT;
+
+
+/*******************************************************************************
+ *
+ * DRTM - Dynamic Root of Trust for Measurement table
+ * Conforms to "TCG D-RTM Architecture" June 17 2013, Version 1.0.0
+ * Table version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_drtm
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT64                  EntryBaseAddress;
+    UINT64                  EntryLength;
+    UINT32                  EntryAddress32;
+    UINT64                  EntryAddress64;
+    UINT64                  ExitAddress;
+    UINT64                  LogAreaAddress;
+    UINT32                  LogAreaLength;
+    UINT64                  ArchDependentAddress;
+    UINT32                  Flags;
+
+} ACPI_TABLE_DRTM;
+
+/* Flag Definitions for above */
+
+#define ACPI_DRTM_ACCESS_ALLOWED            (1)
+#define ACPI_DRTM_ENABLE_GAP_CODE           (1<<1)
+#define ACPI_DRTM_INCOMPLETE_MEASUREMENTS   (1<<2)
+#define ACPI_DRTM_AUTHORITY_ORDER           (1<<3)
+
+
+/* 1) Validated Tables List (64-bit addresses) */
+
+typedef struct acpi_drtm_vtable_list
+{
+    UINT32                  ValidatedTableCount;
+    UINT64                  ValidatedTables[1];
+
+} ACPI_DRTM_VTABLE_LIST;
+
+/* 2) Resources List (of Resource Descriptors) */
+
+/* Resource Descriptor */
+
+typedef struct acpi_drtm_resource
+{
+    UINT8                   Size[7];
+    UINT8                   Type;
+    UINT64                  Address;
+
+} ACPI_DRTM_RESOURCE;
+
+typedef struct acpi_drtm_resource_list
+{
+    UINT32                  ResourceCount;
+    ACPI_DRTM_RESOURCE      Resources[1];
+
+} ACPI_DRTM_RESOURCE_LIST;
+
+/* 3) Platform-specific Identifiers List */
+
+typedef struct acpi_drtm_dps_id
+{
+    UINT32                  DpsIdLength;
+    UINT8                   DpsId[16];
+
+} ACPI_DRTM_DPS_ID;
+
+
+/*******************************************************************************
+ *
+ * FPDT - Firmware Performance Data Table (ACPI 5.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_fpdt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+
+} ACPI_TABLE_FPDT;
+
+
+/* FPDT subtable header */
+
+typedef struct acpi_fpdt_header
+{
+    UINT16                  Type;
+    UINT8                   Length;
+    UINT8                   Revision;
+
+} ACPI_FPDT_HEADER;
+
+/* Values for Type field above */
+
+enum AcpiFpdtType
+{
+    ACPI_FPDT_TYPE_BOOT                 = 0,
+    ACPI_FPDT_TYPE_S3PERF               = 1
+};
+
+
+/*
+ * FPDT subtables
+ */
+
+/* 0: Firmware Basic Boot Performance Record */
+
+typedef struct acpi_fpdt_boot
+{
+    ACPI_FPDT_HEADER        Header;
+    UINT8                   Reserved[4];
+    UINT64                  ResetEnd;
+    UINT64                  LoadStart;
+    UINT64                  StartupStart;
+    UINT64                  ExitServicesEntry;
+    UINT64                  ExitServicesExit;
+
+} ACPI_FPDT_BOOT;
+
+
+/* 1: S3 Performance Table Pointer Record */
+
+typedef struct acpi_fpdt_s3pt_ptr
+{
+    ACPI_FPDT_HEADER        Header;
+    UINT8                   Reserved[4];
+    UINT64                  Address;
+
+} ACPI_FPDT_S3PT_PTR;
+
+
+/*
+ * S3PT - S3 Performance Table. This table is pointed to by the
+ * FPDT S3 Pointer Record above.
+ */
+typedef struct acpi_table_s3pt
+{
+    UINT8                   Signature[4]; /* "S3PT" */
+    UINT32                  Length;
+
+} ACPI_TABLE_S3PT;
+
+
+/*
+ * S3PT Subtables
+ */
+typedef struct acpi_s3pt_header
+{
+    UINT16                  Type;
+    UINT8                   Length;
+    UINT8                   Revision;
+
+} ACPI_S3PT_HEADER;
+
+/* Values for Type field above */
+
+enum AcpiS3ptType
+{
+    ACPI_S3PT_TYPE_RESUME               = 0,
+    ACPI_S3PT_TYPE_SUSPEND              = 1
+};
+
+typedef struct acpi_s3pt_resume
+{
+    ACPI_S3PT_HEADER        Header;
+    UINT32                  ResumeCount;
+    UINT64                  FullResume;
+    UINT64                  AverageResume;
+
+} ACPI_S3PT_RESUME;
+
+typedef struct acpi_s3pt_suspend
+{
+    ACPI_S3PT_HEADER        Header;
+    UINT64                  SuspendStart;
+    UINT64                  SuspendEnd;
+
+} ACPI_S3PT_SUSPEND;
+
+
+/*******************************************************************************
+ *
+ * GTDT - Generic Timer Description Table (ACPI 5.1)
+ *        Version 2
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_gtdt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT64                  CounterBlockAddresss;
+    UINT32                  Reserved;
+    UINT32                  SecureEl1Interrupt;
+    UINT32                  SecureEl1Flags;
+    UINT32                  NonSecureEl1Interrupt;
+    UINT32                  NonSecureEl1Flags;
+    UINT32                  VirtualTimerInterrupt;
+    UINT32                  VirtualTimerFlags;
+    UINT32                  NonSecureEl2Interrupt;
+    UINT32                  NonSecureEl2Flags;
+    UINT64                  CounterReadBlockAddress;
+    UINT32                  PlatformTimerCount;
+    UINT32                  PlatformTimerOffset;
+
+} ACPI_TABLE_GTDT;
+
+/* Flag Definitions: Timer Block Physical Timers and Virtual timers */
+
+#define ACPI_GTDT_INTERRUPT_MODE        (1)
+#define ACPI_GTDT_INTERRUPT_POLARITY    (1<<1)
+#define ACPI_GTDT_ALWAYS_ON             (1<<2)
+
+
+/* Common GTDT subtable header */
+
+typedef struct acpi_gtdt_header
+{
+    UINT8                   Type;
+    UINT16                  Length;
+
+} ACPI_GTDT_HEADER;
+
+/* Values for GTDT subtable type above */
+
+enum AcpiGtdtType
+{
+    ACPI_GTDT_TYPE_TIMER_BLOCK      = 0,
+    ACPI_GTDT_TYPE_WATCHDOG         = 1,
+    ACPI_GTDT_TYPE_RESERVED         = 2    /* 2 and greater are reserved */
+};
+
+
+/* GTDT Subtables, correspond to Type in acpi_gtdt_header */
+
+/* 0: Generic Timer Block */
+
+typedef struct acpi_gtdt_timer_block
+{
+    ACPI_GTDT_HEADER        Header;
+    UINT8                   Reserved;
+    UINT64                  BlockAddress;
+    UINT32                  TimerCount;
+    UINT32                  TimerOffset;
+
+} ACPI_GTDT_TIMER_BLOCK;
+
+/* Timer Sub-Structure, one per timer */
+
+typedef struct acpi_gtdt_timer_entry
+{
+    UINT8                   FrameNumber;
+    UINT8                   Reserved[3];
+    UINT64                  BaseAddress;
+    UINT64                  El0BaseAddress;
+    UINT32                  TimerInterrupt;
+    UINT32                  TimerFlags;
+    UINT32                  VirtualTimerInterrupt;
+    UINT32                  VirtualTimerFlags;
+    UINT32                  CommonFlags;
+
+} ACPI_GTDT_TIMER_ENTRY;
+
+/* Flag Definitions: TimerFlags and VirtualTimerFlags above */
+
+#define ACPI_GTDT_GT_IRQ_MODE               (1)
+#define ACPI_GTDT_GT_IRQ_POLARITY           (1<<1)
+
+/* Flag Definitions: CommonFlags above */
+
+#define ACPI_GTDT_GT_IS_SECURE_TIMER        (1)
+#define ACPI_GTDT_GT_ALWAYS_ON              (1<<1)
+
+
+/* 1: SBSA Generic Watchdog Structure */
+
+typedef struct acpi_gtdt_watchdog
+{
+    ACPI_GTDT_HEADER        Header;
+    UINT8                   Reserved;
+    UINT64                  RefreshFrameAddress;
+    UINT64                  ControlFrameAddress;
+    UINT32                  TimerInterrupt;
+    UINT32                  TimerFlags;
+
+} ACPI_GTDT_WATCHDOG;
+
+/* Flag Definitions: TimerFlags above */
+
+#define ACPI_GTDT_WATCHDOG_IRQ_MODE         (1)
+#define ACPI_GTDT_WATCHDOG_IRQ_POLARITY     (1<<1)
+#define ACPI_GTDT_WATCHDOG_SECURE           (1<<2)
+
+
+/*******************************************************************************
+ *
+ * MPST - Memory Power State Table (ACPI 5.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+#define ACPI_MPST_CHANNEL_INFO \
+    UINT8                   ChannelId; \
+    UINT8                   Reserved1[3]; \
+    UINT16                  PowerNodeCount; \
+    UINT16                  Reserved2;
+
+/* Main table */
+
+typedef struct acpi_table_mpst
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    ACPI_MPST_CHANNEL_INFO                      /* Platform Communication Channel */
+
+} ACPI_TABLE_MPST;
+
+
+/* Memory Platform Communication Channel Info */
+
+typedef struct acpi_mpst_channel
+{
+    ACPI_MPST_CHANNEL_INFO                      /* Platform Communication Channel */
+
+} ACPI_MPST_CHANNEL;
+
+
+/* Memory Power Node Structure */
+
+typedef struct acpi_mpst_power_node
+{
+    UINT8                   Flags;
+    UINT8                   Reserved1;
+    UINT16                  NodeId;
+    UINT32                  Length;
+    UINT64                  RangeAddress;
+    UINT64                  RangeLength;
+    UINT32                  NumPowerStates;
+    UINT32                  NumPhysicalComponents;
+
+} ACPI_MPST_POWER_NODE;
+
+/* Values for Flags field above */
+
+#define ACPI_MPST_ENABLED               1
+#define ACPI_MPST_POWER_MANAGED         2
+#define ACPI_MPST_HOT_PLUG_CAPABLE      4
+
+
+/* Memory Power State Structure (follows POWER_NODE above) */
+
+typedef struct acpi_mpst_power_state
+{
+    UINT8                   PowerState;
+    UINT8                   InfoIndex;
+
+} ACPI_MPST_POWER_STATE;
+
+
+/* Physical Component ID Structure (follows POWER_STATE above) */
+
+typedef struct acpi_mpst_component
+{
+    UINT16                  ComponentId;
+
+} ACPI_MPST_COMPONENT;
+
+
+/* Memory Power State Characteristics Structure (follows all POWER_NODEs) */
+
+typedef struct acpi_mpst_data_hdr
+{
+    UINT16                  CharacteristicsCount;
+    UINT16                  Reserved;
+
+} ACPI_MPST_DATA_HDR;
+
+typedef struct acpi_mpst_power_data
+{
+    UINT8                   StructureId;
+    UINT8                   Flags;
+    UINT16                  Reserved1;
+    UINT32                  AveragePower;
+    UINT32                  PowerSaving;
+    UINT64                  ExitLatency;
+    UINT64                  Reserved2;
+
+} ACPI_MPST_POWER_DATA;
+
+/* Values for Flags field above */
+
+#define ACPI_MPST_PRESERVE              1
+#define ACPI_MPST_AUTOENTRY             2
+#define ACPI_MPST_AUTOEXIT              4
+
+
+/* Shared Memory Region (not part of an ACPI table) */
+
+typedef struct acpi_mpst_shared
+{
+    UINT32                  Signature;
+    UINT16                  PccCommand;
+    UINT16                  PccStatus;
+    UINT32                  CommandRegister;
+    UINT32                  StatusRegister;
+    UINT32                  PowerStateId;
+    UINT32                  PowerNodeId;
+    UINT64                  EnergyConsumed;
+    UINT64                  AveragePower;
+
+} ACPI_MPST_SHARED;
+
+
+/*******************************************************************************
+ *
+ * PCCT - Platform Communications Channel Table (ACPI 5.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_pcct
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  Flags;
+    UINT64                  Reserved;
+
+} ACPI_TABLE_PCCT;
+
+/* Values for Flags field above */
+
+#define ACPI_PCCT_DOORBELL              1
+
+/* Values for subtable type in ACPI_SUBTABLE_HEADER */
+
+enum AcpiPcctType
+{
+    ACPI_PCCT_TYPE_GENERIC_SUBSPACE     = 0,
+    ACPI_PCCT_TYPE_HW_REDUCED_SUBSPACE  = 1,
+    ACPI_PCCT_TYPE_RESERVED             = 2     /* 2 and greater are reserved */
+};
+
+/*
+ * PCCT Subtables, correspond to Type in ACPI_SUBTABLE_HEADER
+ */
+
+/* 0: Generic Communications Subspace */
+
+typedef struct acpi_pcct_subspace
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT8                   Reserved[6];
+    UINT64                  BaseAddress;
+    UINT64                  Length;
+    ACPI_GENERIC_ADDRESS    DoorbellRegister;
+    UINT64                  PreserveMask;
+    UINT64                  WriteMask;
+    UINT32                  Latency;
+    UINT32                  MaxAccessRate;
+    UINT16                  MinTurnaroundTime;
+
+} ACPI_PCCT_SUBSPACE;
+
+
+/* 1: HW-reduced Communications Subspace (ACPI 5.1) */
+
+typedef struct acpi_pcct_hw_reduced
+{
+    ACPI_SUBTABLE_HEADER    Header;
+    UINT32                  DoorbellInterrupt;
+    UINT8                   Flags;
+    UINT8                   Reserved;
+    UINT64                  BaseAddress;
+    UINT64                  Length;
+    ACPI_GENERIC_ADDRESS    DoorbellRegister;
+    UINT64                  PreserveMask;
+    UINT64                  WriteMask;
+    UINT32                  Latency;
+    UINT32                  MaxAccessRate;
+    UINT16                  MinTurnaroundTime;
+
+} ACPI_PCCT_HW_REDUCED;
+
+/* Values for doorbell flags above */
+
+#define ACPI_PCCT_INTERRUPT_POLARITY    (1)
+#define ACPI_PCCT_INTERRUPT_MODE        (1<<1)
+
+
+/*
+ * PCC memory structures (not part of the ACPI table)
+ */
+
+/* Shared Memory Region */
+
+typedef struct acpi_pcct_shared_memory
+{
+    UINT32                  Signature;
+    UINT16                  Command;
+    UINT16                  Status;
+
+} ACPI_PCCT_SHARED_MEMORY;
+
+
+/*******************************************************************************
+ *
+ * PMTT - Platform Memory Topology Table (ACPI 5.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_pmtt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  Reserved;
+
+} ACPI_TABLE_PMTT;
+
+
+/* Common header for PMTT subtables that follow main table */
+
+typedef struct acpi_pmtt_header
+{
+    UINT8                   Type;
+    UINT8                   Reserved1;
+    UINT16                  Length;
+    UINT16                  Flags;
+    UINT16                  Reserved2;
+
+} ACPI_PMTT_HEADER;
+
+/* Values for Type field above */
+
+#define ACPI_PMTT_TYPE_SOCKET           0
+#define ACPI_PMTT_TYPE_CONTROLLER       1
+#define ACPI_PMTT_TYPE_DIMM             2
+#define ACPI_PMTT_TYPE_RESERVED         3 /* 0x03-0xFF are reserved */
+
+/* Values for Flags field above */
+
+#define ACPI_PMTT_TOP_LEVEL             0x0001
+#define ACPI_PMTT_PHYSICAL              0x0002
+#define ACPI_PMTT_MEMORY_TYPE           0x000C
+
+
+/*
+ * PMTT subtables, correspond to Type in acpi_pmtt_header
+ */
+
+
+/* 0: Socket Structure */
+
+typedef struct acpi_pmtt_socket
+{
+    ACPI_PMTT_HEADER        Header;
+    UINT16                  SocketId;
+    UINT16                  Reserved;
+
+} ACPI_PMTT_SOCKET;
+
+
+/* 1: Memory Controller subtable */
+
+typedef struct acpi_pmtt_controller
+{
+    ACPI_PMTT_HEADER        Header;
+    UINT32                  ReadLatency;
+    UINT32                  WriteLatency;
+    UINT32                  ReadBandwidth;
+    UINT32                  WriteBandwidth;
+    UINT16                  AccessWidth;
+    UINT16                  Alignment;
+    UINT16                  Reserved;
+    UINT16                  DomainCount;
+
+} ACPI_PMTT_CONTROLLER;
+
+/* 1a: Proximity Domain substructure */
+
+typedef struct acpi_pmtt_domain
+{
+    UINT32                  ProximityDomain;
+
+} ACPI_PMTT_DOMAIN;
+
+
+/* 2: Physical Component Identifier (DIMM) */
+
+typedef struct acpi_pmtt_physical_component
+{
+    ACPI_PMTT_HEADER        Header;
+    UINT16                  ComponentId;
+    UINT16                  Reserved;
+    UINT32                  MemorySize;
+    UINT32                  BiosHandle;
+
+} ACPI_PMTT_PHYSICAL_COMPONENT;
+
+
+/*******************************************************************************
+ *
+ * RASF - RAS Feature Table (ACPI 5.0)
+ *        Version 1
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_rasf
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   ChannelId[12];
+
+} ACPI_TABLE_RASF;
+
+/* RASF Platform Communication Channel Shared Memory Region */
+
+typedef struct acpi_rasf_shared_memory
+{
+    UINT32                  Signature;
+    UINT16                  Command;
+    UINT16                  Status;
+    UINT16                  Version;
+    UINT8                   Capabilities[16];
+    UINT8                   SetCapabilities[16];
+    UINT16                  NumParameterBlocks;
+    UINT32                  SetCapabilitiesStatus;
+
+} ACPI_RASF_SHARED_MEMORY;
+
+/* RASF Parameter Block Structure Header */
+
+typedef struct acpi_rasf_parameter_block
+{
+    UINT16                  Type;
+    UINT16                  Version;
+    UINT16                  Length;
+
+} ACPI_RASF_PARAMETER_BLOCK;
+
+/* RASF Parameter Block Structure for PATROL_SCRUB */
+
+typedef struct acpi_rasf_patrol_scrub_parameter
+{
+    ACPI_RASF_PARAMETER_BLOCK   Header;
+    UINT16                      PatrolScrubCommand;
+    UINT64                      RequestedAddressRange[2];
+    UINT64                      ActualAddressRange[2];
+    UINT16                      Flags;
+    UINT8                       RequestedSpeed;
+
+} ACPI_RASF_PATROL_SCRUB_PARAMETER;
+
+/* Masks for Flags and Speed fields above */
+
+#define ACPI_RASF_SCRUBBER_RUNNING      1
+#define ACPI_RASF_SPEED                 (7<<1)
+#define ACPI_RASF_SPEED_SLOW            (0<<1)
+#define ACPI_RASF_SPEED_MEDIUM          (4<<1)
+#define ACPI_RASF_SPEED_FAST            (7<<1)
+
+/* Channel Commands */
+
+enum AcpiRasfCommands
+{
+    ACPI_RASF_EXECUTE_RASF_COMMAND      = 1
+};
+
+/* Platform RAS Capabilities */
+
+enum AcpiRasfCapabiliities
+{
+    ACPI_HW_PATROL_SCRUB_SUPPORTED      = 0,
+    ACPI_SW_PATROL_SCRUB_EXPOSED        = 1
+};
+
+/* Patrol Scrub Commands */
+
+enum AcpiRasfPatrolScrubCommands
+{
+    ACPI_RASF_GET_PATROL_PARAMETERS     = 1,
+    ACPI_RASF_START_PATROL_SCRUBBER     = 2,
+    ACPI_RASF_STOP_PATROL_SCRUBBER      = 3
+};
+
+/* Channel Command flags */
+
+#define ACPI_RASF_GENERATE_SCI          (1<<15)
+
+/* Status values */
+
+enum AcpiRasfStatus
+{
+    ACPI_RASF_SUCCESS                   = 0,
+    ACPI_RASF_NOT_VALID                 = 1,
+    ACPI_RASF_NOT_SUPPORTED             = 2,
+    ACPI_RASF_BUSY                      = 3,
+    ACPI_RASF_FAILED                    = 4,
+    ACPI_RASF_ABORTED                   = 5,
+    ACPI_RASF_INVALID_DATA              = 6
+};
+
+/* Status flags */
+
+#define ACPI_RASF_COMMAND_COMPLETE      (1)
+#define ACPI_RASF_SCI_DOORBELL          (1<<1)
+#define ACPI_RASF_ERROR                 (1<<2)
+#define ACPI_RASF_STATUS                (0x1F<<3)
+
+
+/*******************************************************************************
+ *
+ * STAO - Status Override Table (_STA override) - ACPI 6.0
+ *        Version 1
+ *
+ * Conforms to "ACPI Specification for Status Override Table"
+ * 6 January 2015
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_stao
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT8                   IgnoreUart;
+
+} ACPI_TABLE_STAO;
+
+
+/*******************************************************************************
+ *
+ * WPBT - Windows Platform Environment Table (ACPI 6.0)
+ *        Version 1
+ *
+ * Conforms to "Windows Platform Binary Table (WPBT)" 29 November 2011
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_wpbt
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT32                  HandoffSize;
+    UINT64                  HandoffAddress;
+    UINT8                   Layout;
+    UINT8                   Type;
+    UINT16                  ArgumentsLength;
+
+} ACPI_TABLE_WPBT;
+
+
+/*******************************************************************************
+ *
+ * XENV - Xen Environment Table (ACPI 6.0)
+ *        Version 1
+ *
+ * Conforms to "ACPI Specification for Xen Environment Table" 4 January 2015
+ *
+ ******************************************************************************/
+
+typedef struct acpi_table_xenv
+{
+    ACPI_TABLE_HEADER       Header;             /* Common ACPI table header */
+    UINT64                  GrantTableAddress;
+    UINT64                  GrantTableSize;
+    UINT32                  EventInterrupt;
+    UINT8                   EventFlags;
+
+} ACPI_TABLE_XENV;
+
+
+/* Reset to default packing */
+
+#pragma pack()
+
+#endif /* __ACTBL3_H__ */

+ 1404 - 0
kernel/include/acpica/actypes.h

@@ -0,0 +1,1404 @@
+/******************************************************************************
+ *
+ * Name: actypes.h - Common data types for the entire ACPI subsystem
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACTYPES_H__
+#define __ACTYPES_H__
+
+/* acpisrc:StructDefs -- for acpisrc conversion */
+
+/*
+ * ACPI_MACHINE_WIDTH must be specified in an OS- or compiler-dependent header
+ * and must be either 32 or 64. 16-bit ACPICA is no longer supported, as of
+ * 12/2006.
+ */
+#ifndef ACPI_MACHINE_WIDTH
+#error ACPI_MACHINE_WIDTH not defined
+#endif
+
+/*
+ * Data type ranges
+ * Note: These macros are designed to be compiler independent as well as
+ * working around problems that some 32-bit compilers have with 64-bit
+ * constants.
+ */
+#define ACPI_UINT8_MAX                  (UINT8) (~((UINT8)  0)) /* 0xFF               */
+#define ACPI_UINT16_MAX                 (UINT16)(~((UINT16) 0)) /* 0xFFFF             */
+#define ACPI_UINT32_MAX                 (UINT32)(~((UINT32) 0)) /* 0xFFFFFFFF         */
+#define ACPI_UINT64_MAX                 (UINT64)(~((UINT64) 0)) /* 0xFFFFFFFFFFFFFFFF */
+#define ACPI_ASCII_MAX                  0x7F
+
+
+/*
+ * Architecture-specific ACPICA Subsystem Data Types
+ *
+ * The goal of these types is to provide source code portability across
+ * 16-bit, 32-bit, and 64-bit targets.
+ *
+ * 1) The following types are of fixed size for all targets (16/32/64):
+ *
+ * BOOLEAN      Logical boolean
+ *
+ * UINT8        8-bit  (1 byte) unsigned value
+ * UINT16       16-bit (2 byte) unsigned value
+ * UINT32       32-bit (4 byte) unsigned value
+ * UINT64       64-bit (8 byte) unsigned value
+ *
+ * INT16        16-bit (2 byte) signed value
+ * INT32        32-bit (4 byte) signed value
+ * INT64        64-bit (8 byte) signed value
+ *
+ * COMPILER_DEPENDENT_UINT64/INT64 - These types are defined in the
+ * compiler-dependent header(s) and were introduced because there is no common
+ * 64-bit integer type across the various compilation models, as shown in
+ * the table below.
+ *
+ * Datatype  LP64 ILP64 LLP64 ILP32 LP32 16bit
+ * char      8    8     8     8     8    8
+ * short     16   16    16    16    16   16
+ * _int32         32
+ * int       32   64    32    32    16   16
+ * long      64   64    32    32    32   32
+ * long long            64    64
+ * pointer   64   64    64    32    32   32
+ *
+ * Note: ILP64 and LP32 are currently not supported.
+ *
+ *
+ * 2) These types represent the native word size of the target mode of the
+ * processor, and may be 16-bit, 32-bit, or 64-bit as required. They are
+ * usually used for memory allocation, efficient loop counters, and array
+ * indexes. The types are similar to the size_t type in the C library and are
+ * required because there is no C type that consistently represents the native
+ * data width. ACPI_SIZE is needed because there is no guarantee that a
+ * kernel-level C library is present.
+ *
+ * ACPI_SIZE        16/32/64-bit unsigned value
+ * ACPI_NATIVE_INT  16/32/64-bit signed value
+ */
+
+/*******************************************************************************
+ *
+ * Common types for all compilers, all targets
+ *
+ ******************************************************************************/
+
+#ifndef ACPI_USE_SYSTEM_INTTYPES
+
+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;
+
+#endif /* ACPI_USE_SYSTEM_INTTYPES */
+
+/*
+ * Value returned by AcpiOsGetThreadId. There is no standard "thread_id"
+ * across operating systems or even the various UNIX systems. Since ACPICA
+ * only needs the thread ID as a unique thread identifier, we use a UINT64
+ * as the only common data type - it will accommodate any type of pointer or
+ * any type of integer. It is up to the host-dependent OSL to cast the
+ * native thread ID type to a UINT64 (in AcpiOsGetThreadId).
+ */
+#define ACPI_THREAD_ID                  UINT64
+
+
+/*******************************************************************************
+ *
+ * Types specific to 64-bit targets
+ *
+ ******************************************************************************/
+
+#if ACPI_MACHINE_WIDTH == 64
+
+#ifndef ACPI_USE_SYSTEM_INTTYPES
+
+typedef unsigned int                    UINT32;
+typedef int                             INT32;
+
+#endif /* ACPI_USE_SYSTEM_INTTYPES */
+
+
+typedef INT64                           ACPI_NATIVE_INT;
+typedef UINT64                          ACPI_SIZE;
+typedef UINT64                          ACPI_IO_ADDRESS;
+typedef UINT64                          ACPI_PHYSICAL_ADDRESS;
+
+#define ACPI_MAX_PTR                    ACPI_UINT64_MAX
+#define ACPI_SIZE_MAX                   ACPI_UINT64_MAX
+#define ACPI_USE_NATIVE_DIVIDE          /* Has native 64-bit integer support */
+
+/*
+ * In the case of the Itanium Processor Family (IPF), the hardware does not
+ * support misaligned memory transfers. Set the MISALIGNMENT_NOT_SUPPORTED flag
+ * to indicate that special precautions must be taken to avoid alignment faults.
+ * (IA64 or ia64 is currently used by existing compilers to indicate IPF.)
+ *
+ * Note: EM64T and other X86-64 processors support misaligned transfers,
+ * so there is no need to define this flag.
+ */
+#if defined (__IA64__) || defined (__ia64__)
+#define ACPI_MISALIGNMENT_NOT_SUPPORTED
+#endif
+
+
+/*******************************************************************************
+ *
+ * Types specific to 32-bit targets
+ *
+ ******************************************************************************/
+
+#elif ACPI_MACHINE_WIDTH == 32
+
+#ifndef ACPI_USE_SYSTEM_INTTYPES
+
+typedef unsigned int                    UINT32;
+typedef int                             INT32;
+
+#endif /* ACPI_USE_SYSTEM_INTTYPES */
+
+
+typedef INT32                           ACPI_NATIVE_INT;
+typedef UINT32                          ACPI_SIZE;
+
+#ifdef ACPI_32BIT_PHYSICAL_ADDRESS
+
+/*
+ * OSPMs can define this to shrink the size of the structures for 32-bit
+ * none PAE environment. ASL compiler may always define this to generate
+ * 32-bit OSPM compliant tables.
+ */
+typedef UINT32                          ACPI_IO_ADDRESS;
+typedef UINT32                          ACPI_PHYSICAL_ADDRESS;
+
+#else /* ACPI_32BIT_PHYSICAL_ADDRESS */
+
+/*
+ * It is reported that, after some calculations, the physical addresses can
+ * wrap over the 32-bit boundary on 32-bit PAE environment.
+ * https://bugzilla.kernel.org/show_bug.cgi?id=87971
+ */
+typedef UINT64                          ACPI_IO_ADDRESS;
+typedef UINT64                          ACPI_PHYSICAL_ADDRESS;
+
+#endif /* ACPI_32BIT_PHYSICAL_ADDRESS */
+
+#define ACPI_MAX_PTR                    ACPI_UINT32_MAX
+#define ACPI_SIZE_MAX                   ACPI_UINT32_MAX
+
+#else
+
+/* ACPI_MACHINE_WIDTH must be either 64 or 32 */
+
+#error unknown ACPI_MACHINE_WIDTH
+#endif
+
+
+/*******************************************************************************
+ *
+ * OS-dependent types
+ *
+ * If the defaults below are not appropriate for the host system, they can
+ * be defined in the OS-specific header, and this will take precedence.
+ *
+ ******************************************************************************/
+
+/* Flags for AcpiOsAcquireLock/AcpiOsReleaseLock */
+
+#ifndef ACPI_CPU_FLAGS
+#define ACPI_CPU_FLAGS                  ACPI_SIZE
+#endif
+
+/* Object returned from AcpiOsCreateCache */
+
+#ifndef ACPI_CACHE_T
+#ifdef ACPI_USE_LOCAL_CACHE
+#define ACPI_CACHE_T                    ACPI_MEMORY_LIST
+#else
+#define ACPI_CACHE_T                    void *
+#endif
+#endif
+
+/*
+ * Synchronization objects - Mutexes, Semaphores, and SpinLocks
+ */
+#if (ACPI_MUTEX_TYPE == ACPI_BINARY_SEMAPHORE)
+/*
+ * These macros are used if the host OS does not support a mutex object.
+ * Map the OSL Mutex interfaces to binary semaphores.
+ */
+#define ACPI_MUTEX                      ACPI_SEMAPHORE
+#define AcpiOsCreateMutex(OutHandle)    AcpiOsCreateSemaphore (1, 1, OutHandle)
+#define AcpiOsDeleteMutex(Handle)       (void) AcpiOsDeleteSemaphore (Handle)
+#define AcpiOsAcquireMutex(Handle,Time) AcpiOsWaitSemaphore (Handle, 1, Time)
+#define AcpiOsReleaseMutex(Handle)      (void) AcpiOsSignalSemaphore (Handle, 1)
+#endif
+
+/* Configurable types for synchronization objects */
+
+#ifndef ACPI_SPINLOCK
+#define ACPI_SPINLOCK                   void *
+#endif
+
+#ifndef ACPI_SEMAPHORE
+#define ACPI_SEMAPHORE                  void *
+#endif
+
+#ifndef ACPI_MUTEX
+#define ACPI_MUTEX                      void *
+#endif
+
+
+/*******************************************************************************
+ *
+ * Compiler-dependent types
+ *
+ * If the defaults below are not appropriate for the host compiler, they can
+ * be defined in the compiler-specific header, and this will take precedence.
+ *
+ ******************************************************************************/
+
+/* Use C99 uintptr_t for pointer casting if available, "void *" otherwise */
+
+#ifndef ACPI_UINTPTR_T
+#define ACPI_UINTPTR_T                  void *
+#endif
+
+/*
+ * ACPI_PRINTF_LIKE is used to tag functions as "printf-like" because
+ * some compilers can catch printf format string problems
+ */
+#ifndef ACPI_PRINTF_LIKE
+#define ACPI_PRINTF_LIKE(c)
+#endif
+
+/*
+ * Some compilers complain about unused variables. Sometimes we don't want to
+ * use all the variables (for example, _AcpiModuleName). This allows us
+ * to tell the compiler in a per-variable manner that a variable
+ * is unused
+ */
+#ifndef ACPI_UNUSED_VAR
+#define ACPI_UNUSED_VAR
+#endif
+
+/*
+ * All ACPICA external functions that are available to the rest of the kernel
+ * are tagged with thes macros which can be defined as appropriate for the host.
+ *
+ * Notes:
+ * ACPI_EXPORT_SYMBOL_INIT is used for initialization and termination
+ * interfaces that may need special processing.
+ * ACPI_EXPORT_SYMBOL is used for all other public external functions.
+ */
+#ifndef ACPI_EXPORT_SYMBOL_INIT
+#define ACPI_EXPORT_SYMBOL_INIT(Symbol)
+#endif
+
+#ifndef ACPI_EXPORT_SYMBOL
+#define ACPI_EXPORT_SYMBOL(Symbol)
+#endif
+
+/*
+ * Compiler/Clibrary-dependent debug initialization. Used for ACPICA
+ * utilities only.
+ */
+#ifndef ACPI_DEBUG_INITIALIZE
+#define ACPI_DEBUG_INITIALIZE()
+#endif
+
+
+/*******************************************************************************
+ *
+ * Configuration
+ *
+ ******************************************************************************/
+
+#ifdef ACPI_NO_MEM_ALLOCATIONS
+
+#define ACPI_ALLOCATE(a)                NULL
+#define ACPI_ALLOCATE_ZEROED(a)         NULL
+#define ACPI_FREE(a)
+#define ACPI_MEM_TRACKING(a)
+
+#else /* ACPI_NO_MEM_ALLOCATIONS */
+
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+/*
+ * Memory allocation tracking (used by AcpiExec to detect memory leaks)
+ */
+#define ACPI_MEM_PARAMETERS             _COMPONENT, _AcpiModuleName, __LINE__
+#define ACPI_ALLOCATE(a)                AcpiUtAllocateAndTrack ((ACPI_SIZE) (a), ACPI_MEM_PARAMETERS)
+#define ACPI_ALLOCATE_ZEROED(a)         AcpiUtAllocateZeroedAndTrack ((ACPI_SIZE) (a), ACPI_MEM_PARAMETERS)
+#define ACPI_FREE(a)                    AcpiUtFreeAndTrack (a, ACPI_MEM_PARAMETERS)
+#define ACPI_MEM_TRACKING(a)            a
+
+#else
+/*
+ * Normal memory allocation directly via the OS services layer
+ */
+#define ACPI_ALLOCATE(a)                AcpiOsAllocate ((ACPI_SIZE) (a))
+#define ACPI_ALLOCATE_ZEROED(a)         AcpiOsAllocateZeroed ((ACPI_SIZE) (a))
+#define ACPI_FREE(a)                    AcpiOsFree (a)
+#define ACPI_MEM_TRACKING(a)
+
+#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
+
+#endif /* ACPI_NO_MEM_ALLOCATIONS */
+
+
+/******************************************************************************
+ *
+ * ACPI Specification constants (Do not change unless the specification changes)
+ *
+ *****************************************************************************/
+
+/* Number of distinct FADT-based GPE register blocks (GPE0 and GPE1) */
+
+#define ACPI_MAX_GPE_BLOCKS             2
+
+/* Default ACPI register widths */
+
+#define ACPI_GPE_REGISTER_WIDTH         8
+#define ACPI_PM1_REGISTER_WIDTH         16
+#define ACPI_PM2_REGISTER_WIDTH         8
+#define ACPI_PM_TIMER_WIDTH             32
+#define ACPI_RESET_REGISTER_WIDTH       8
+
+/* Names within the namespace are 4 bytes long */
+
+#define ACPI_NAME_SIZE                  4
+#define ACPI_PATH_SEGMENT_LENGTH        5           /* 4 chars for name + 1 char for separator */
+#define ACPI_PATH_SEPARATOR             '.'
+
+/* Sizes for ACPI table headers */
+
+#define ACPI_OEM_ID_SIZE                6
+#define ACPI_OEM_TABLE_ID_SIZE          8
+
+/* ACPI/PNP hardware IDs */
+
+#define PCI_ROOT_HID_STRING             "PNP0A03"
+#define PCI_EXPRESS_ROOT_HID_STRING     "PNP0A08"
+
+/* PM Timer ticks per second (HZ) */
+
+#define ACPI_PM_TIMER_FREQUENCY         3579545
+
+
+/*******************************************************************************
+ *
+ * Independent types
+ *
+ ******************************************************************************/
+
+/* Logical defines and NULL */
+
+#ifdef FALSE
+#undef FALSE
+#endif
+#define FALSE                           (1 == 0)
+
+#ifdef TRUE
+#undef TRUE
+#endif
+#define TRUE                            (1 == 1)
+
+#ifndef NULL
+#define NULL                            (void *) 0
+#endif
+
+
+/*
+ * Miscellaneous types
+ */
+typedef UINT32                          ACPI_STATUS;    /* All ACPI Exceptions */
+typedef UINT32                          ACPI_NAME;      /* 4-byte ACPI name */
+typedef char *                          ACPI_STRING;    /* Null terminated ASCII string */
+typedef void *                          ACPI_HANDLE;    /* Actually a ptr to a NS Node */
+
+
+/* Time constants for timer calculations */
+
+#define ACPI_MSEC_PER_SEC               1000L
+
+#define ACPI_USEC_PER_MSEC              1000L
+#define ACPI_USEC_PER_SEC               1000000L
+
+#define ACPI_100NSEC_PER_USEC           10L
+#define ACPI_100NSEC_PER_MSEC           10000L
+#define ACPI_100NSEC_PER_SEC            10000000L
+
+#define ACPI_NSEC_PER_USEC              1000L
+#define ACPI_NSEC_PER_MSEC              1000000L
+#define ACPI_NSEC_PER_SEC               1000000000L
+
+
+/* Owner IDs are used to track namespace nodes for selective deletion */
+
+typedef UINT8                           ACPI_OWNER_ID;
+#define ACPI_OWNER_ID_MAX               0xFF
+
+
+#define ACPI_INTEGER_BIT_SIZE           64
+#define ACPI_MAX_DECIMAL_DIGITS         20  /* 2^64 = 18,446,744,073,709,551,616 */
+#define ACPI_MAX64_DECIMAL_DIGITS       20
+#define ACPI_MAX32_DECIMAL_DIGITS       10
+#define ACPI_MAX16_DECIMAL_DIGITS        5
+#define ACPI_MAX8_DECIMAL_DIGITS         3
+
+/*
+ * Constants with special meanings
+ */
+#define ACPI_ROOT_OBJECT                ACPI_ADD_PTR (ACPI_HANDLE, NULL, ACPI_MAX_PTR)
+#define ACPI_WAIT_FOREVER               0xFFFF  /* UINT16, as per ACPI spec */
+#define ACPI_DO_NOT_WAIT                0
+
+/*
+ * Obsolete: Acpi integer width. In ACPI version 1 (1996), integers are 32 bits.
+ * In ACPI version 2 (2000) and later, integers are 64 bits. Note that this
+ * pertains to the ACPI integer type only, not to other integers used in the
+ * implementation of the ACPICA subsystem.
+ *
+ * 01/2010: This type is obsolete and has been removed from the entire ACPICA
+ * code base. It remains here for compatibility with device drivers that use
+ * the type. However, it will be removed in the future.
+ */
+typedef UINT64                          ACPI_INTEGER;
+#define ACPI_INTEGER_MAX                ACPI_UINT64_MAX
+
+
+/*******************************************************************************
+ *
+ * Commonly used macros
+ *
+ ******************************************************************************/
+
+/* Data manipulation */
+
+#define ACPI_LOBYTE(Integer)            ((UINT8)   (UINT16)(Integer))
+#define ACPI_HIBYTE(Integer)            ((UINT8) (((UINT16)(Integer)) >> 8))
+#define ACPI_LOWORD(Integer)            ((UINT16)  (UINT32)(Integer))
+#define ACPI_HIWORD(Integer)            ((UINT16)(((UINT32)(Integer)) >> 16))
+#define ACPI_LODWORD(Integer64)         ((UINT32)  (UINT64)(Integer64))
+#define ACPI_HIDWORD(Integer64)         ((UINT32)(((UINT64)(Integer64)) >> 32))
+
+#define ACPI_SET_BIT(target,bit)        ((target) |= (bit))
+#define ACPI_CLEAR_BIT(target,bit)      ((target) &= ~(bit))
+#define ACPI_MIN(a,b)                   (((a)<(b))?(a):(b))
+#define ACPI_MAX(a,b)                   (((a)>(b))?(a):(b))
+
+/* Size calculation */
+
+#define ACPI_ARRAY_LENGTH(x)            (sizeof(x) / sizeof((x)[0]))
+
+/* Pointer manipulation */
+
+#define ACPI_CAST_PTR(t, p)             ((t *) (ACPI_UINTPTR_T) (p))
+#define ACPI_CAST_INDIRECT_PTR(t, p)    ((t **) (ACPI_UINTPTR_T) (p))
+#define ACPI_ADD_PTR(t, a, b)           ACPI_CAST_PTR (t, (ACPI_CAST_PTR (UINT8, (a)) + (ACPI_SIZE)(b)))
+#define ACPI_SUB_PTR(t, a, b)           ACPI_CAST_PTR (t, (ACPI_CAST_PTR (UINT8, (a)) - (ACPI_SIZE)(b)))
+#define ACPI_PTR_DIFF(a, b)             (ACPI_SIZE) (ACPI_CAST_PTR (UINT8, (a)) - ACPI_CAST_PTR (UINT8, (b)))
+
+/* Pointer/Integer type conversions */
+
+#define ACPI_TO_POINTER(i)              ACPI_ADD_PTR (void, (void *) NULL,(ACPI_SIZE) i)
+#define ACPI_TO_INTEGER(p)              ACPI_PTR_DIFF (p, (void *) NULL)
+#define ACPI_OFFSET(d, f)               ACPI_PTR_DIFF (&(((d *) 0)->f), (void *) NULL)
+#define ACPI_PHYSADDR_TO_PTR(i)         ACPI_TO_POINTER(i)
+#define ACPI_PTR_TO_PHYSADDR(i)         ACPI_TO_INTEGER(i)
+
+/* Optimizations for 4-character (32-bit) ACPI_NAME manipulation */
+
+#ifndef ACPI_MISALIGNMENT_NOT_SUPPORTED
+#define ACPI_COMPARE_NAME(a,b)          (*ACPI_CAST_PTR (UINT32, (a)) == *ACPI_CAST_PTR (UINT32, (b)))
+#define ACPI_MOVE_NAME(dest,src)        (*ACPI_CAST_PTR (UINT32, (dest)) = *ACPI_CAST_PTR (UINT32, (src)))
+#else
+#define ACPI_COMPARE_NAME(a,b)          (!strncmp (ACPI_CAST_PTR (char, (a)), ACPI_CAST_PTR (char, (b)), ACPI_NAME_SIZE))
+#define ACPI_MOVE_NAME(dest,src)        (strncpy (ACPI_CAST_PTR (char, (dest)), ACPI_CAST_PTR (char, (src)), ACPI_NAME_SIZE))
+#endif
+
+/* Support for the special RSDP signature (8 characters) */
+
+#define ACPI_VALIDATE_RSDP_SIG(a)       (!strncmp (ACPI_CAST_PTR (char, (a)), ACPI_SIG_RSDP, 8))
+#define ACPI_MAKE_RSDP_SIG(dest)        (memcpy (ACPI_CAST_PTR (char, (dest)), ACPI_SIG_RSDP, 8))
+
+
+/*******************************************************************************
+ *
+ * Miscellaneous constants
+ *
+ ******************************************************************************/
+
+/*
+ * Initialization sequence
+ */
+#define ACPI_FULL_INITIALIZATION        0x00
+#define ACPI_NO_ADDRESS_SPACE_INIT      0x01
+#define ACPI_NO_HARDWARE_INIT           0x02
+#define ACPI_NO_EVENT_INIT              0x04
+#define ACPI_NO_HANDLER_INIT            0x08
+#define ACPI_NO_ACPI_ENABLE             0x10
+#define ACPI_NO_DEVICE_INIT             0x20
+#define ACPI_NO_OBJECT_INIT             0x40
+#define ACPI_NO_FACS_INIT               0x80
+
+/*
+ * Initialization state
+ */
+#define ACPI_SUBSYSTEM_INITIALIZE       0x01
+#define ACPI_INITIALIZED_OK             0x02
+
+/*
+ * Power state values
+ */
+#define ACPI_STATE_UNKNOWN              (UINT8) 0xFF
+
+#define ACPI_STATE_S0                   (UINT8) 0
+#define ACPI_STATE_S1                   (UINT8) 1
+#define ACPI_STATE_S2                   (UINT8) 2
+#define ACPI_STATE_S3                   (UINT8) 3
+#define ACPI_STATE_S4                   (UINT8) 4
+#define ACPI_STATE_S5                   (UINT8) 5
+#define ACPI_S_STATES_MAX               ACPI_STATE_S5
+#define ACPI_S_STATE_COUNT              6
+
+#define ACPI_STATE_D0                   (UINT8) 0
+#define ACPI_STATE_D1                   (UINT8) 1
+#define ACPI_STATE_D2                   (UINT8) 2
+#define ACPI_STATE_D3                   (UINT8) 3
+#define ACPI_D_STATES_MAX               ACPI_STATE_D3
+#define ACPI_D_STATE_COUNT              4
+
+#define ACPI_STATE_C0                   (UINT8) 0
+#define ACPI_STATE_C1                   (UINT8) 1
+#define ACPI_STATE_C2                   (UINT8) 2
+#define ACPI_STATE_C3                   (UINT8) 3
+#define ACPI_C_STATES_MAX               ACPI_STATE_C3
+#define ACPI_C_STATE_COUNT              4
+
+/*
+ * Sleep type invalid value
+ */
+#define ACPI_SLEEP_TYPE_MAX             0x7
+#define ACPI_SLEEP_TYPE_INVALID         0xFF
+
+/*
+ * Standard notify values
+ */
+#define ACPI_NOTIFY_BUS_CHECK           (UINT8) 0x00
+#define ACPI_NOTIFY_DEVICE_CHECK        (UINT8) 0x01
+#define ACPI_NOTIFY_DEVICE_WAKE         (UINT8) 0x02
+#define ACPI_NOTIFY_EJECT_REQUEST       (UINT8) 0x03
+#define ACPI_NOTIFY_DEVICE_CHECK_LIGHT  (UINT8) 0x04
+#define ACPI_NOTIFY_FREQUENCY_MISMATCH  (UINT8) 0x05
+#define ACPI_NOTIFY_BUS_MODE_MISMATCH   (UINT8) 0x06
+#define ACPI_NOTIFY_POWER_FAULT         (UINT8) 0x07
+#define ACPI_NOTIFY_CAPABILITIES_CHECK  (UINT8) 0x08
+#define ACPI_NOTIFY_DEVICE_PLD_CHECK    (UINT8) 0x09
+#define ACPI_NOTIFY_RESERVED            (UINT8) 0x0A
+#define ACPI_NOTIFY_LOCALITY_UPDATE     (UINT8) 0x0B
+#define ACPI_NOTIFY_SHUTDOWN_REQUEST    (UINT8) 0x0C
+#define ACPI_NOTIFY_AFFINITY_UPDATE     (UINT8) 0x0D
+
+#define ACPI_NOTIFY_MAX                 0x0D
+
+/*
+ * Types associated with ACPI names and objects. The first group of
+ * values (up to ACPI_TYPE_EXTERNAL_MAX) correspond to the definition
+ * of the ACPI ObjectType() operator (See the ACPI Spec). Therefore,
+ * only add to the first group if the spec changes.
+ *
+ * NOTE: Types must be kept in sync with the global AcpiNsProperties
+ * and AcpiNsTypeNames arrays.
+ */
+typedef UINT32                          ACPI_OBJECT_TYPE;
+
+#define ACPI_TYPE_ANY                   0x00
+#define ACPI_TYPE_INTEGER               0x01  /* Byte/Word/Dword/Zero/One/Ones */
+#define ACPI_TYPE_STRING                0x02
+#define ACPI_TYPE_BUFFER                0x03
+#define ACPI_TYPE_PACKAGE               0x04  /* ByteConst, multiple DataTerm/Constant/SuperName */
+#define ACPI_TYPE_FIELD_UNIT            0x05
+#define ACPI_TYPE_DEVICE                0x06  /* Name, multiple Node */
+#define ACPI_TYPE_EVENT                 0x07
+#define ACPI_TYPE_METHOD                0x08  /* Name, ByteConst, multiple Code */
+#define ACPI_TYPE_MUTEX                 0x09
+#define ACPI_TYPE_REGION                0x0A
+#define ACPI_TYPE_POWER                 0x0B  /* Name,ByteConst,WordConst,multi Node */
+#define ACPI_TYPE_PROCESSOR             0x0C  /* Name,ByteConst,DWordConst,ByteConst,multi NmO */
+#define ACPI_TYPE_THERMAL               0x0D  /* Name, multiple Node */
+#define ACPI_TYPE_BUFFER_FIELD          0x0E
+#define ACPI_TYPE_DDB_HANDLE            0x0F
+#define ACPI_TYPE_DEBUG_OBJECT          0x10
+
+#define ACPI_TYPE_EXTERNAL_MAX          0x10
+#define ACPI_NUM_TYPES                  (ACPI_TYPE_EXTERNAL_MAX + 1)
+
+/*
+ * These are object types that do not map directly to the ACPI
+ * ObjectType() operator. They are used for various internal purposes only.
+ * If new predefined ACPI_TYPEs are added (via the ACPI specification), these
+ * internal types must move upwards. (There is code that depends on these
+ * values being contiguous with the external types above.)
+ */
+#define ACPI_TYPE_LOCAL_REGION_FIELD    0x11
+#define ACPI_TYPE_LOCAL_BANK_FIELD      0x12
+#define ACPI_TYPE_LOCAL_INDEX_FIELD     0x13
+#define ACPI_TYPE_LOCAL_REFERENCE       0x14  /* Arg#, Local#, Name, Debug, RefOf, Index */
+#define ACPI_TYPE_LOCAL_ALIAS           0x15
+#define ACPI_TYPE_LOCAL_METHOD_ALIAS    0x16
+#define ACPI_TYPE_LOCAL_NOTIFY          0x17
+#define ACPI_TYPE_LOCAL_ADDRESS_HANDLER 0x18
+#define ACPI_TYPE_LOCAL_RESOURCE        0x19
+#define ACPI_TYPE_LOCAL_RESOURCE_FIELD  0x1A
+#define ACPI_TYPE_LOCAL_SCOPE           0x1B  /* 1 Name, multiple ObjectList Nodes */
+
+#define ACPI_TYPE_NS_NODE_MAX           0x1B  /* Last typecode used within a NS Node */
+#define ACPI_TOTAL_TYPES                (ACPI_TYPE_NS_NODE_MAX + 1)
+
+/*
+ * These are special object types that never appear in
+ * a Namespace node, only in an object of ACPI_OPERAND_OBJECT
+ */
+#define ACPI_TYPE_LOCAL_EXTRA           0x1C
+#define ACPI_TYPE_LOCAL_DATA            0x1D
+
+#define ACPI_TYPE_LOCAL_MAX             0x1D
+
+/* All types above here are invalid */
+
+#define ACPI_TYPE_INVALID               0x1E
+#define ACPI_TYPE_NOT_FOUND             0xFF
+
+#define ACPI_NUM_NS_TYPES               (ACPI_TYPE_INVALID + 1)
+
+
+/*
+ * All I/O
+ */
+#define ACPI_READ                       0
+#define ACPI_WRITE                      1
+#define ACPI_IO_MASK                    1
+
+/*
+ * Event Types: Fixed & General Purpose
+ */
+typedef UINT32                          ACPI_EVENT_TYPE;
+
+/*
+ * Fixed events
+ */
+#define ACPI_EVENT_PMTIMER              0
+#define ACPI_EVENT_GLOBAL               1
+#define ACPI_EVENT_POWER_BUTTON         2
+#define ACPI_EVENT_SLEEP_BUTTON         3
+#define ACPI_EVENT_RTC                  4
+#define ACPI_EVENT_MAX                  4
+#define ACPI_NUM_FIXED_EVENTS           ACPI_EVENT_MAX + 1
+
+/*
+ * Event Status - Per event
+ * -------------
+ * The encoding of ACPI_EVENT_STATUS is illustrated below.
+ * Note that a set bit (1) indicates the property is TRUE
+ * (e.g. if bit 0 is set then the event is enabled).
+ * +-------------+-+-+-+-+-+
+ * |   Bits 31:5 |4|3|2|1|0|
+ * +-------------+-+-+-+-+-+
+ *          |     | | | | |
+ *          |     | | | | +- Enabled?
+ *          |     | | | +--- Enabled for wake?
+ *          |     | | +----- Status bit set?
+ *          |     | +------- Enable bit set?
+ *          |     +--------- Has a handler?
+ *          +--------------- <Reserved>
+ */
+typedef UINT32                          ACPI_EVENT_STATUS;
+
+#define ACPI_EVENT_FLAG_DISABLED        (ACPI_EVENT_STATUS) 0x00
+#define ACPI_EVENT_FLAG_ENABLED         (ACPI_EVENT_STATUS) 0x01
+#define ACPI_EVENT_FLAG_WAKE_ENABLED    (ACPI_EVENT_STATUS) 0x02
+#define ACPI_EVENT_FLAG_STATUS_SET      (ACPI_EVENT_STATUS) 0x04
+#define ACPI_EVENT_FLAG_ENABLE_SET      (ACPI_EVENT_STATUS) 0x08
+#define ACPI_EVENT_FLAG_HAS_HANDLER     (ACPI_EVENT_STATUS) 0x10
+#define ACPI_EVENT_FLAG_SET             ACPI_EVENT_FLAG_STATUS_SET
+
+/* Actions for AcpiSetGpe, AcpiGpeWakeup, AcpiHwLowSetGpe */
+
+#define ACPI_GPE_ENABLE                 0
+#define ACPI_GPE_DISABLE                1
+#define ACPI_GPE_CONDITIONAL_ENABLE     2
+
+/*
+ * GPE info flags - Per GPE
+ * +-------+-+-+---+
+ * |  7:5  |4|3|2:0|
+ * +-------+-+-+---+
+ *     |    | |  |
+ *     |    | |  +-- Type of dispatch:to method, handler, notify, or none
+ *     |    | +----- Interrupt type: edge or level triggered
+ *     |    +------- Is a Wake GPE
+ *     +------------ <Reserved>
+ */
+#define ACPI_GPE_DISPATCH_NONE          (UINT8) 0x00
+#define ACPI_GPE_DISPATCH_METHOD        (UINT8) 0x01
+#define ACPI_GPE_DISPATCH_HANDLER       (UINT8) 0x02
+#define ACPI_GPE_DISPATCH_NOTIFY        (UINT8) 0x03
+#define ACPI_GPE_DISPATCH_RAW_HANDLER   (UINT8) 0x04
+#define ACPI_GPE_DISPATCH_MASK          (UINT8) 0x07
+#define ACPI_GPE_DISPATCH_TYPE(flags)   ((UINT8) ((flags) & ACPI_GPE_DISPATCH_MASK))
+
+#define ACPI_GPE_LEVEL_TRIGGERED        (UINT8) 0x08
+#define ACPI_GPE_EDGE_TRIGGERED         (UINT8) 0x00
+#define ACPI_GPE_XRUPT_TYPE_MASK        (UINT8) 0x08
+
+#define ACPI_GPE_CAN_WAKE               (UINT8) 0x10
+
+/*
+ * Flags for GPE and Lock interfaces
+ */
+#define ACPI_NOT_ISR                    0x1
+#define ACPI_ISR                        0x0
+
+
+/* Notify types */
+
+#define ACPI_SYSTEM_NOTIFY              0x1
+#define ACPI_DEVICE_NOTIFY              0x2
+#define ACPI_ALL_NOTIFY                 (ACPI_SYSTEM_NOTIFY | ACPI_DEVICE_NOTIFY)
+#define ACPI_MAX_NOTIFY_HANDLER_TYPE    0x3
+#define ACPI_NUM_NOTIFY_TYPES           2
+
+#define ACPI_MAX_SYS_NOTIFY             0x7F
+#define ACPI_MAX_DEVICE_SPECIFIC_NOTIFY 0xBF
+
+#define ACPI_SYSTEM_HANDLER_LIST        0 /* Used as index, must be SYSTEM_NOTIFY -1 */
+#define ACPI_DEVICE_HANDLER_LIST        1 /* Used as index, must be DEVICE_NOTIFY -1 */
+
+
+/* Address Space (Operation Region) Types */
+
+typedef UINT8                           ACPI_ADR_SPACE_TYPE;
+
+#define ACPI_ADR_SPACE_SYSTEM_MEMORY    (ACPI_ADR_SPACE_TYPE) 0
+#define ACPI_ADR_SPACE_SYSTEM_IO        (ACPI_ADR_SPACE_TYPE) 1
+#define ACPI_ADR_SPACE_PCI_CONFIG       (ACPI_ADR_SPACE_TYPE) 2
+#define ACPI_ADR_SPACE_EC               (ACPI_ADR_SPACE_TYPE) 3
+#define ACPI_ADR_SPACE_SMBUS            (ACPI_ADR_SPACE_TYPE) 4
+#define ACPI_ADR_SPACE_CMOS             (ACPI_ADR_SPACE_TYPE) 5
+#define ACPI_ADR_SPACE_PCI_BAR_TARGET   (ACPI_ADR_SPACE_TYPE) 6
+#define ACPI_ADR_SPACE_IPMI             (ACPI_ADR_SPACE_TYPE) 7
+#define ACPI_ADR_SPACE_GPIO             (ACPI_ADR_SPACE_TYPE) 8
+#define ACPI_ADR_SPACE_GSBUS            (ACPI_ADR_SPACE_TYPE) 9
+#define ACPI_ADR_SPACE_PLATFORM_COMM    (ACPI_ADR_SPACE_TYPE) 10
+
+#define ACPI_NUM_PREDEFINED_REGIONS     11
+
+/*
+ * Special Address Spaces
+ *
+ * Note: A Data Table region is a special type of operation region
+ * that has its own AML opcode. However, internally, the AML
+ * interpreter simply creates an operation region with an an address
+ * space type of ACPI_ADR_SPACE_DATA_TABLE.
+ */
+#define ACPI_ADR_SPACE_DATA_TABLE       (ACPI_ADR_SPACE_TYPE) 0x7E /* Internal to ACPICA only */
+#define ACPI_ADR_SPACE_FIXED_HARDWARE   (ACPI_ADR_SPACE_TYPE) 0x7F
+
+/* Values for _REG connection code */
+
+#define ACPI_REG_DISCONNECT             0
+#define ACPI_REG_CONNECT                1
+
+/*
+ * BitRegister IDs
+ *
+ * These values are intended to be used by the hardware interfaces
+ * and are mapped to individual bitfields defined within the ACPI
+ * registers. See the AcpiGbl_BitRegisterInfo global table in utglobal.c
+ * for this mapping.
+ */
+
+/* PM1 Status register */
+
+#define ACPI_BITREG_TIMER_STATUS                0x00
+#define ACPI_BITREG_BUS_MASTER_STATUS           0x01
+#define ACPI_BITREG_GLOBAL_LOCK_STATUS          0x02
+#define ACPI_BITREG_POWER_BUTTON_STATUS         0x03
+#define ACPI_BITREG_SLEEP_BUTTON_STATUS         0x04
+#define ACPI_BITREG_RT_CLOCK_STATUS             0x05
+#define ACPI_BITREG_WAKE_STATUS                 0x06
+#define ACPI_BITREG_PCIEXP_WAKE_STATUS          0x07
+
+/* PM1 Enable register */
+
+#define ACPI_BITREG_TIMER_ENABLE                0x08
+#define ACPI_BITREG_GLOBAL_LOCK_ENABLE          0x09
+#define ACPI_BITREG_POWER_BUTTON_ENABLE         0x0A
+#define ACPI_BITREG_SLEEP_BUTTON_ENABLE         0x0B
+#define ACPI_BITREG_RT_CLOCK_ENABLE             0x0C
+#define ACPI_BITREG_PCIEXP_WAKE_DISABLE         0x0D
+
+/* PM1 Control register */
+
+#define ACPI_BITREG_SCI_ENABLE                  0x0E
+#define ACPI_BITREG_BUS_MASTER_RLD              0x0F
+#define ACPI_BITREG_GLOBAL_LOCK_RELEASE         0x10
+#define ACPI_BITREG_SLEEP_TYPE                  0x11
+#define ACPI_BITREG_SLEEP_ENABLE                0x12
+
+/* PM2 Control register */
+
+#define ACPI_BITREG_ARB_DISABLE                 0x13
+
+#define ACPI_BITREG_MAX                         0x13
+#define ACPI_NUM_BITREG                         ACPI_BITREG_MAX + 1
+
+
+/* Status register values. A 1 clears a status bit. 0 = no effect */
+
+#define ACPI_CLEAR_STATUS                       1
+
+/* Enable and Control register values */
+
+#define ACPI_ENABLE_EVENT                       1
+#define ACPI_DISABLE_EVENT                      0
+
+
+/* Sleep function dispatch */
+
+typedef ACPI_STATUS (*ACPI_SLEEP_FUNCTION) (
+    UINT8                   SleepState);
+
+typedef struct acpi_sleep_functions
+{
+    ACPI_SLEEP_FUNCTION     LegacyFunction;
+    ACPI_SLEEP_FUNCTION     ExtendedFunction;
+
+} ACPI_SLEEP_FUNCTIONS;
+
+
+/*
+ * External ACPI object definition
+ */
+
+/*
+ * Note: Type == ACPI_TYPE_ANY (0) is used to indicate a NULL package element
+ * or an unresolved named reference.
+ */
+typedef union acpi_object
+{
+    ACPI_OBJECT_TYPE                Type;   /* See definition of AcpiNsType for values */
+    struct
+    {
+        ACPI_OBJECT_TYPE                Type;       /* ACPI_TYPE_INTEGER */
+        UINT64                          Value;      /* The actual number */
+    } Integer;
+
+    struct
+    {
+        ACPI_OBJECT_TYPE                Type;       /* ACPI_TYPE_STRING */
+        UINT32                          Length;     /* # of bytes in string, excluding trailing null */
+        char                            *Pointer;   /* points to the string value */
+    } String;
+
+    struct
+    {
+        ACPI_OBJECT_TYPE                Type;       /* ACPI_TYPE_BUFFER */
+        UINT32                          Length;     /* # of bytes in buffer */
+        UINT8                           *Pointer;   /* points to the buffer */
+    } Buffer;
+
+    struct
+    {
+        ACPI_OBJECT_TYPE                Type;       /* ACPI_TYPE_PACKAGE */
+        UINT32                          Count;      /* # of elements in package */
+        union acpi_object               *Elements;  /* Pointer to an array of ACPI_OBJECTs */
+    } Package;
+
+    struct
+    {
+        ACPI_OBJECT_TYPE                Type;       /* ACPI_TYPE_LOCAL_REFERENCE */
+        ACPI_OBJECT_TYPE                ActualType; /* Type associated with the Handle */
+        ACPI_HANDLE                     Handle;     /* object reference */
+    } Reference;
+
+    struct
+    {
+        ACPI_OBJECT_TYPE                Type;       /* ACPI_TYPE_PROCESSOR */
+        UINT32                          ProcId;
+        ACPI_IO_ADDRESS                 PblkAddress;
+        UINT32                          PblkLength;
+    } Processor;
+
+    struct
+    {
+        ACPI_OBJECT_TYPE                Type;       /* ACPI_TYPE_POWER */
+        UINT32                          SystemLevel;
+        UINT32                          ResourceOrder;
+    } PowerResource;
+
+} ACPI_OBJECT;
+
+
+/*
+ * List of objects, used as a parameter list for control method evaluation
+ */
+typedef struct acpi_object_list
+{
+    UINT32                          Count;
+    ACPI_OBJECT                     *Pointer;
+
+} ACPI_OBJECT_LIST;
+
+
+/*
+ * Miscellaneous common Data Structures used by the interfaces
+ */
+#define ACPI_NO_BUFFER              0
+
+#ifdef ACPI_NO_MEM_ALLOCATIONS
+
+#define ACPI_ALLOCATE_BUFFER        (ACPI_SIZE) (0)
+#define ACPI_ALLOCATE_LOCAL_BUFFER  (ACPI_SIZE) (0)
+
+#else /* ACPI_NO_MEM_ALLOCATIONS */
+
+#define ACPI_ALLOCATE_BUFFER        (ACPI_SIZE) (-1)    /* Let ACPICA allocate buffer */
+#define ACPI_ALLOCATE_LOCAL_BUFFER  (ACPI_SIZE) (-2)    /* For internal use only (enables tracking) */
+
+#endif /* ACPI_NO_MEM_ALLOCATIONS */
+
+typedef struct acpi_buffer
+{
+    ACPI_SIZE                       Length;         /* Length in bytes of the buffer */
+    void                            *Pointer;       /* pointer to buffer */
+
+} ACPI_BUFFER;
+
+
+/*
+ * NameType for AcpiGetName
+ */
+#define ACPI_FULL_PATHNAME              0
+#define ACPI_SINGLE_NAME                1
+#define ACPI_FULL_PATHNAME_NO_TRAILING  2
+#define ACPI_NAME_TYPE_MAX              2
+
+
+/*
+ * Predefined Namespace items
+ */
+typedef struct acpi_predefined_names
+{
+    char                            *Name;
+    UINT8                           Type;
+    char                            *Val;
+
+} ACPI_PREDEFINED_NAMES;
+
+
+/*
+ * Structure and flags for AcpiGetSystemInfo
+ */
+#define ACPI_SYS_MODE_UNKNOWN           0x0000
+#define ACPI_SYS_MODE_ACPI              0x0001
+#define ACPI_SYS_MODE_LEGACY            0x0002
+#define ACPI_SYS_MODES_MASK             0x0003
+
+
+/*
+ * System info returned by AcpiGetSystemInfo()
+ */
+typedef struct acpi_system_info
+{
+    UINT32                          AcpiCaVersion;
+    UINT32                          Flags;
+    UINT32                          TimerResolution;
+    UINT32                          Reserved1;
+    UINT32                          Reserved2;
+    UINT32                          DebugLevel;
+    UINT32                          DebugLayer;
+
+} ACPI_SYSTEM_INFO;
+
+
+/*
+ * System statistics returned by AcpiGetStatistics()
+ */
+typedef struct acpi_statistics
+{
+    UINT32                          SciCount;
+    UINT32                          GpeCount;
+    UINT32                          FixedEventCount[ACPI_NUM_FIXED_EVENTS];
+    UINT32                          MethodCount;
+
+} ACPI_STATISTICS;
+
+
+/* Table Event Types */
+
+#define ACPI_TABLE_EVENT_LOAD           0x0
+#define ACPI_TABLE_EVENT_UNLOAD         0x1
+#define ACPI_NUM_TABLE_EVENTS           2
+
+
+/*
+ * Types specific to the OS service interfaces
+ */
+typedef UINT32
+(ACPI_SYSTEM_XFACE *ACPI_OSD_HANDLER) (
+    void                            *Context);
+
+typedef void
+(ACPI_SYSTEM_XFACE *ACPI_OSD_EXEC_CALLBACK) (
+    void                            *Context);
+
+/*
+ * Various handlers and callback procedures
+ */
+typedef
+UINT32 (*ACPI_SCI_HANDLER) (
+    void                            *Context);
+
+typedef
+void (*ACPI_GBL_EVENT_HANDLER) (
+    UINT32                          EventType,
+    ACPI_HANDLE                     Device,
+    UINT32                          EventNumber,
+    void                            *Context);
+
+#define ACPI_EVENT_TYPE_GPE         0
+#define ACPI_EVENT_TYPE_FIXED       1
+
+typedef
+UINT32 (*ACPI_EVENT_HANDLER) (
+    void                            *Context);
+
+typedef
+UINT32 (*ACPI_GPE_HANDLER) (
+    ACPI_HANDLE                     GpeDevice,
+    UINT32                          GpeNumber,
+    void                            *Context);
+
+typedef
+void (*ACPI_NOTIFY_HANDLER) (
+    ACPI_HANDLE                     Device,
+    UINT32                          Value,
+    void                            *Context);
+
+typedef
+void (*ACPI_OBJECT_HANDLER) (
+    ACPI_HANDLE                     Object,
+    void                            *Data);
+
+typedef
+ACPI_STATUS (*ACPI_INIT_HANDLER) (
+    ACPI_HANDLE                     Object,
+    UINT32                          Function);
+
+#define ACPI_INIT_DEVICE_INI        1
+
+typedef
+ACPI_STATUS (*ACPI_EXCEPTION_HANDLER) (
+    ACPI_STATUS                     AmlStatus,
+    ACPI_NAME                       Name,
+    UINT16                          Opcode,
+    UINT32                          AmlOffset,
+    void                            *Context);
+
+/* Table Event handler (Load, LoadTable, etc.) and types */
+
+typedef
+ACPI_STATUS (*ACPI_TABLE_HANDLER) (
+    UINT32                          Event,
+    void                            *Table,
+    void                            *Context);
+
+#define ACPI_TABLE_LOAD             0x0
+#define ACPI_TABLE_UNLOAD           0x1
+#define ACPI_NUM_TABLE_EVENTS       2
+
+
+/* Address Spaces (For Operation Regions) */
+
+typedef
+ACPI_STATUS (*ACPI_ADR_SPACE_HANDLER) (
+    UINT32                          Function,
+    ACPI_PHYSICAL_ADDRESS           Address,
+    UINT32                          BitWidth,
+    UINT64                          *Value,
+    void                            *HandlerContext,
+    void                            *RegionContext);
+
+#define ACPI_DEFAULT_HANDLER            NULL
+
+/* Special Context data for GenericSerialBus/GeneralPurposeIo (ACPI 5.0) */
+
+typedef struct acpi_connection_info
+{
+    UINT8                           *Connection;
+    UINT16                          Length;
+    UINT8                           AccessLength;
+
+} ACPI_CONNECTION_INFO;
+
+
+typedef
+ACPI_STATUS (*ACPI_ADR_SPACE_SETUP) (
+    ACPI_HANDLE                     RegionHandle,
+    UINT32                          Function,
+    void                            *HandlerContext,
+    void                            **RegionContext);
+
+#define ACPI_REGION_ACTIVATE    0
+#define ACPI_REGION_DEACTIVATE  1
+
+typedef
+ACPI_STATUS (*ACPI_WALK_CALLBACK) (
+    ACPI_HANDLE                     Object,
+    UINT32                          NestingLevel,
+    void                            *Context,
+    void                            **ReturnValue);
+
+typedef
+UINT32 (*ACPI_INTERFACE_HANDLER) (
+    ACPI_STRING                     InterfaceName,
+    UINT32                          Supported);
+
+
+/* Interrupt handler return values */
+
+#define ACPI_INTERRUPT_NOT_HANDLED      0x00
+#define ACPI_INTERRUPT_HANDLED          0x01
+
+/* GPE handler return values */
+
+#define ACPI_REENABLE_GPE               0x80
+
+
+/* Length of 32-bit EISAID values when converted back to a string */
+
+#define ACPI_EISAID_STRING_SIZE         8   /* Includes null terminator */
+
+/* Length of UUID (string) values */
+
+#define ACPI_UUID_LENGTH                16
+
+/* Length of 3-byte PCI class code values when converted back to a string */
+
+#define ACPI_PCICLS_STRING_SIZE         7   /* Includes null terminator */
+
+
+/* Structures used for device/processor HID, UID, CID */
+
+typedef struct acpi_pnp_device_id
+{
+    UINT32                          Length;             /* Length of string + null */
+    char                            *String;
+
+} ACPI_PNP_DEVICE_ID;
+
+typedef struct acpi_pnp_device_id_list
+{
+    UINT32                          Count;              /* Number of IDs in Ids array */
+    UINT32                          ListSize;           /* Size of list, including ID strings */
+    ACPI_PNP_DEVICE_ID              Ids[1];             /* ID array */
+
+} ACPI_PNP_DEVICE_ID_LIST;
+
+/*
+ * Structure returned from AcpiGetObjectInfo.
+ * Optimized for both 32- and 64-bit builds
+ */
+typedef struct acpi_device_info
+{
+    UINT32                          InfoSize;           /* Size of info, including ID strings */
+    UINT32                          Name;               /* ACPI object Name */
+    ACPI_OBJECT_TYPE                Type;               /* ACPI object Type */
+    UINT8                           ParamCount;         /* If a method, required parameter count */
+    UINT16                          Valid;              /* Indicates which optional fields are valid */
+    UINT8                           Flags;              /* Miscellaneous info */
+    UINT8                           HighestDstates[4];  /* _SxD values: 0xFF indicates not valid */
+    UINT8                           LowestDstates[5];   /* _SxW values: 0xFF indicates not valid */
+    UINT32                          CurrentStatus;      /* _STA value */
+    UINT64                          Address;            /* _ADR value */
+    ACPI_PNP_DEVICE_ID              HardwareId;         /* _HID value */
+    ACPI_PNP_DEVICE_ID              UniqueId;           /* _UID value */
+    ACPI_PNP_DEVICE_ID              ClassCode;          /* _CLS value */
+    ACPI_PNP_DEVICE_ID_LIST         CompatibleIdList;   /* _CID list <must be last> */
+
+} ACPI_DEVICE_INFO;
+
+/* Values for Flags field above (AcpiGetObjectInfo) */
+
+#define ACPI_PCI_ROOT_BRIDGE            0x01
+
+/* Flags for Valid field above (AcpiGetObjectInfo) */
+
+#define ACPI_VALID_STA                  0x0001
+#define ACPI_VALID_ADR                  0x0002
+#define ACPI_VALID_HID                  0x0004
+#define ACPI_VALID_UID                  0x0008
+#define ACPI_VALID_CID                  0x0020
+#define ACPI_VALID_CLS                  0x0040
+#define ACPI_VALID_SXDS                 0x0100
+#define ACPI_VALID_SXWS                 0x0200
+
+/* Flags for _STA method */
+
+#define ACPI_STA_DEVICE_PRESENT         0x01
+#define ACPI_STA_DEVICE_ENABLED         0x02
+#define ACPI_STA_DEVICE_UI              0x04
+#define ACPI_STA_DEVICE_FUNCTIONING     0x08
+#define ACPI_STA_DEVICE_OK              0x08 /* Synonym */
+#define ACPI_STA_BATTERY_PRESENT        0x10
+
+
+/* Context structs for address space handlers */
+
+typedef struct acpi_pci_id
+{
+    UINT16                          Segment;
+    UINT16                          Bus;
+    UINT16                          Device;
+    UINT16                          Function;
+
+} ACPI_PCI_ID;
+
+typedef struct acpi_mem_space_context
+{
+    UINT32                          Length;
+    ACPI_PHYSICAL_ADDRESS           Address;
+    ACPI_PHYSICAL_ADDRESS           MappedPhysicalAddress;
+    UINT8                           *MappedLogicalAddress;
+    ACPI_SIZE                       MappedLength;
+
+} ACPI_MEM_SPACE_CONTEXT;
+
+
+/*
+ * ACPI_MEMORY_LIST is used only if the ACPICA local cache is enabled
+ */
+typedef struct acpi_memory_list
+{
+    char                            *ListName;
+    void                            *ListHead;
+    UINT16                          ObjectSize;
+    UINT16                          MaxDepth;
+    UINT16                          CurrentDepth;
+
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+
+    /* Statistics for debug memory tracking only */
+
+    UINT32                          TotalAllocated;
+    UINT32                          TotalFreed;
+    UINT32                          MaxOccupied;
+    UINT32                          TotalSize;
+    UINT32                          CurrentTotalSize;
+    UINT32                          Requests;
+    UINT32                          Hits;
+#endif
+
+} ACPI_MEMORY_LIST;
+
+
+/* Definitions of trace event types */
+
+typedef enum
+{
+    ACPI_TRACE_AML_METHOD,
+    ACPI_TRACE_AML_OPCODE,
+    ACPI_TRACE_AML_REGION
+
+} ACPI_TRACE_EVENT_TYPE;
+
+
+/* Definitions of _OSI support */
+
+#define ACPI_VENDOR_STRINGS                 0x01
+#define ACPI_FEATURE_STRINGS                0x02
+#define ACPI_ENABLE_INTERFACES              0x00
+#define ACPI_DISABLE_INTERFACES             0x04
+
+#define ACPI_DISABLE_ALL_VENDOR_STRINGS     (ACPI_DISABLE_INTERFACES | ACPI_VENDOR_STRINGS)
+#define ACPI_DISABLE_ALL_FEATURE_STRINGS    (ACPI_DISABLE_INTERFACES | ACPI_FEATURE_STRINGS)
+#define ACPI_DISABLE_ALL_STRINGS            (ACPI_DISABLE_INTERFACES | ACPI_VENDOR_STRINGS | ACPI_FEATURE_STRINGS)
+#define ACPI_ENABLE_ALL_VENDOR_STRINGS      (ACPI_ENABLE_INTERFACES | ACPI_VENDOR_STRINGS)
+#define ACPI_ENABLE_ALL_FEATURE_STRINGS     (ACPI_ENABLE_INTERFACES | ACPI_FEATURE_STRINGS)
+#define ACPI_ENABLE_ALL_STRINGS             (ACPI_ENABLE_INTERFACES | ACPI_VENDOR_STRINGS | ACPI_FEATURE_STRINGS)
+
+#define ACPI_OSI_WIN_2000               0x01
+#define ACPI_OSI_WIN_XP                 0x02
+#define ACPI_OSI_WIN_XP_SP1             0x03
+#define ACPI_OSI_WINSRV_2003            0x04
+#define ACPI_OSI_WIN_XP_SP2             0x05
+#define ACPI_OSI_WINSRV_2003_SP1        0x06
+#define ACPI_OSI_WIN_VISTA              0x07
+#define ACPI_OSI_WINSRV_2008            0x08
+#define ACPI_OSI_WIN_VISTA_SP1          0x09
+#define ACPI_OSI_WIN_VISTA_SP2          0x0A
+#define ACPI_OSI_WIN_7                  0x0B
+#define ACPI_OSI_WIN_8                  0x0C
+#define ACPI_OSI_WIN_10                 0x0D
+
+
+/* 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__ */

+ 1086 - 0
kernel/include/acpica/acutils.h

@@ -0,0 +1,1086 @@
+/******************************************************************************
+ *
+ * Name: acutils.h -- prototypes for the common (subsystem-wide) procedures
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 _ACUTILS_H
+#define _ACUTILS_H
+
+
+extern const UINT8                      AcpiGbl_ResourceAmlSizes[];
+extern const UINT8                      AcpiGbl_ResourceAmlSerialBusSizes[];
+
+/* Strings used by the disassembler and debugger resource dump routines */
+
+#if defined(ACPI_DEBUG_OUTPUT) || defined (ACPI_DISASSEMBLER) || defined (ACPI_DEBUGGER)
+
+extern const char                       *AcpiGbl_BmDecode[];
+extern const char                       *AcpiGbl_ConfigDecode[];
+extern const char                       *AcpiGbl_ConsumeDecode[];
+extern const char                       *AcpiGbl_DecDecode[];
+extern const char                       *AcpiGbl_HeDecode[];
+extern const char                       *AcpiGbl_IoDecode[];
+extern const char                       *AcpiGbl_LlDecode[];
+extern const char                       *AcpiGbl_MaxDecode[];
+extern const char                       *AcpiGbl_MemDecode[];
+extern const char                       *AcpiGbl_MinDecode[];
+extern const char                       *AcpiGbl_MtpDecode[];
+extern const char                       *AcpiGbl_RngDecode[];
+extern const char                       *AcpiGbl_RwDecode[];
+extern const char                       *AcpiGbl_ShrDecode[];
+extern const char                       *AcpiGbl_SizDecode[];
+extern const char                       *AcpiGbl_TrsDecode[];
+extern const char                       *AcpiGbl_TtpDecode[];
+extern const char                       *AcpiGbl_TypDecode[];
+extern const char                       *AcpiGbl_PpcDecode[];
+extern const char                       *AcpiGbl_IorDecode[];
+extern const char                       *AcpiGbl_DtsDecode[];
+extern const char                       *AcpiGbl_CtDecode[];
+extern const char                       *AcpiGbl_SbtDecode[];
+extern const char                       *AcpiGbl_AmDecode[];
+extern const char                       *AcpiGbl_SmDecode[];
+extern const char                       *AcpiGbl_WmDecode[];
+extern const char                       *AcpiGbl_CphDecode[];
+extern const char                       *AcpiGbl_CpoDecode[];
+extern const char                       *AcpiGbl_DpDecode[];
+extern const char                       *AcpiGbl_EdDecode[];
+extern const char                       *AcpiGbl_BpbDecode[];
+extern const char                       *AcpiGbl_SbDecode[];
+extern const char                       *AcpiGbl_FcDecode[];
+extern const char                       *AcpiGbl_PtDecode[];
+#endif
+
+/*
+ * For the iASL compiler case, the output is redirected to stderr so that
+ * any of the various ACPI errors and warnings do not appear in the output
+ * files, for either the compiler or disassembler portions of the tool.
+ */
+#ifdef ACPI_ASL_COMPILER
+
+#include <stdio.h>
+
+#define ACPI_MSG_REDIRECT_BEGIN \
+    FILE                    *OutputFile = AcpiGbl_OutputFile; \
+    AcpiOsRedirectOutput (stderr);
+
+#define ACPI_MSG_REDIRECT_END \
+    AcpiOsRedirectOutput (OutputFile);
+
+#else
+/*
+ * non-iASL case - no redirection, nothing to do
+ */
+#define ACPI_MSG_REDIRECT_BEGIN
+#define ACPI_MSG_REDIRECT_END
+#endif
+
+/*
+ * Common error message prefixes
+ */
+#define ACPI_MSG_ERROR          "ACPI Error: "
+#define ACPI_MSG_EXCEPTION      "ACPI Exception: "
+#define ACPI_MSG_WARNING        "ACPI Warning: "
+#define ACPI_MSG_INFO           "ACPI: "
+
+#define ACPI_MSG_BIOS_ERROR     "ACPI BIOS Error (bug): "
+#define ACPI_MSG_BIOS_WARNING   "ACPI BIOS Warning (bug): "
+
+/*
+ * Common message suffix
+ */
+#define ACPI_MSG_SUFFIX \
+    AcpiOsPrintf (" (%8.8X/%s-%u)\n", ACPI_CA_VERSION, ModuleName, LineNumber)
+
+
+/* Types for Resource descriptor entries */
+
+#define ACPI_INVALID_RESOURCE           0
+#define ACPI_FIXED_LENGTH               1
+#define ACPI_VARIABLE_LENGTH            2
+#define ACPI_SMALL_VARIABLE_LENGTH      3
+
+typedef
+ACPI_STATUS (*ACPI_WALK_AML_CALLBACK) (
+    UINT8                   *Aml,
+    UINT32                  Length,
+    UINT32                  Offset,
+    UINT8                   ResourceIndex,
+    void                    **Context);
+
+typedef
+ACPI_STATUS (*ACPI_PKG_CALLBACK) (
+    UINT8                   ObjectType,
+    ACPI_OPERAND_OBJECT     *SourceObject,
+    ACPI_GENERIC_STATE      *State,
+    void                    *Context);
+
+typedef struct acpi_pkg_info
+{
+    UINT8                   *FreeSpace;
+    ACPI_SIZE               Length;
+    UINT32                  ObjectSpace;
+    UINT32                  NumPackages;
+
+} ACPI_PKG_INFO;
+
+/* Object reference counts */
+
+#define REF_INCREMENT       (UINT16) 0
+#define REF_DECREMENT       (UINT16) 1
+
+/* AcpiUtDumpBuffer */
+
+#define DB_BYTE_DISPLAY     1
+#define DB_WORD_DISPLAY     2
+#define DB_DWORD_DISPLAY    4
+#define DB_QWORD_DISPLAY    8
+
+
+/*
+ * utnonansi - Non-ANSI C library functions
+ */
+void
+AcpiUtStrupr (
+    char                    *SrcString);
+
+void
+AcpiUtStrlwr (
+    char                    *SrcString);
+
+int
+AcpiUtStricmp (
+    char                    *String1,
+    char                    *String2);
+
+ACPI_STATUS
+AcpiUtStrtoul64 (
+    char                    *String,
+    UINT32                  Base,
+    UINT64                  *RetInteger);
+
+
+/*
+ * utglobal - Global data structures and procedures
+ */
+ACPI_STATUS
+AcpiUtInitGlobals (
+    void);
+
+#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
+
+const char *
+AcpiUtGetMutexName (
+    UINT32                  MutexId);
+
+const char *
+AcpiUtGetNotifyName (
+    UINT32                  NotifyValue,
+    ACPI_OBJECT_TYPE        Type);
+#endif
+
+const char *
+AcpiUtGetTypeName (
+    ACPI_OBJECT_TYPE        Type);
+
+const char *
+AcpiUtGetNodeName (
+    void                    *Object);
+
+const char *
+AcpiUtGetDescriptorName (
+    void                    *Object);
+
+const char *
+AcpiUtGetReferenceName (
+    ACPI_OPERAND_OBJECT     *Object);
+
+const char *
+AcpiUtGetObjectTypeName (
+    ACPI_OPERAND_OBJECT     *ObjDesc);
+
+const char *
+AcpiUtGetRegionName (
+    UINT8                   SpaceId);
+
+const char *
+AcpiUtGetEventName (
+    UINT32                  EventId);
+
+char
+AcpiUtHexToAsciiChar (
+    UINT64                  Integer,
+    UINT32                  Position);
+
+UINT8
+AcpiUtAsciiCharToHex (
+    int                     HexChar);
+
+BOOLEAN
+AcpiUtValidObjectType (
+    ACPI_OBJECT_TYPE        Type);
+
+
+/*
+ * utinit - miscellaneous initialization and shutdown
+ */
+ACPI_STATUS
+AcpiUtHardwareInitialize (
+    void);
+
+void
+AcpiUtSubsystemShutdown (
+    void);
+
+
+/*
+ * utcopy - Object construction and conversion interfaces
+ */
+ACPI_STATUS
+AcpiUtBuildSimpleObject(
+    ACPI_OPERAND_OBJECT     *Obj,
+    ACPI_OBJECT             *UserObj,
+    UINT8                   *DataSpace,
+    UINT32                  *BufferSpaceUsed);
+
+ACPI_STATUS
+AcpiUtBuildPackageObject (
+    ACPI_OPERAND_OBJECT     *Obj,
+    UINT8                   *Buffer,
+    UINT32                  *SpaceUsed);
+
+ACPI_STATUS
+AcpiUtCopyIobjectToEobject (
+    ACPI_OPERAND_OBJECT     *Obj,
+    ACPI_BUFFER             *RetBuffer);
+
+ACPI_STATUS
+AcpiUtCopyEobjectToIobject (
+    ACPI_OBJECT             *Obj,
+    ACPI_OPERAND_OBJECT     **InternalObj);
+
+ACPI_STATUS
+AcpiUtCopyISimpleToIsimple (
+    ACPI_OPERAND_OBJECT     *SourceObj,
+    ACPI_OPERAND_OBJECT     *DestObj);
+
+ACPI_STATUS
+AcpiUtCopyIobjectToIobject (
+    ACPI_OPERAND_OBJECT     *SourceDesc,
+    ACPI_OPERAND_OBJECT     **DestDesc,
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * utcreate - Object creation
+ */
+ACPI_STATUS
+AcpiUtUpdateObjectReference (
+    ACPI_OPERAND_OBJECT     *Object,
+    UINT16                  Action);
+
+
+/*
+ * utdebug - Debug interfaces
+ */
+void
+AcpiUtInitStackPtrTrace (
+    void);
+
+void
+AcpiUtTrackStackPtr (
+    void);
+
+void
+AcpiUtTrace (
+    UINT32                  LineNumber,
+    const char              *FunctionName,
+    const char              *ModuleName,
+    UINT32                  ComponentId);
+
+void
+AcpiUtTracePtr (
+    UINT32                  LineNumber,
+    const char              *FunctionName,
+    const char              *ModuleName,
+    UINT32                  ComponentId,
+    void                    *Pointer);
+
+void
+AcpiUtTraceU32 (
+    UINT32                  LineNumber,
+    const char              *FunctionName,
+    const char              *ModuleName,
+    UINT32                  ComponentId,
+    UINT32                  Integer);
+
+void
+AcpiUtTraceStr (
+    UINT32                  LineNumber,
+    const char              *FunctionName,
+    const char              *ModuleName,
+    UINT32                  ComponentId,
+    char                    *String);
+
+void
+AcpiUtExit (
+    UINT32                  LineNumber,
+    const char              *FunctionName,
+    const char              *ModuleName,
+    UINT32                  ComponentId);
+
+void
+AcpiUtStatusExit (
+    UINT32                  LineNumber,
+    const char              *FunctionName,
+    const char              *ModuleName,
+    UINT32                  ComponentId,
+    ACPI_STATUS             Status);
+
+void
+AcpiUtValueExit (
+    UINT32                  LineNumber,
+    const char              *FunctionName,
+    const char              *ModuleName,
+    UINT32                  ComponentId,
+    UINT64                  Value);
+
+void
+AcpiUtPtrExit (
+    UINT32                  LineNumber,
+    const char              *FunctionName,
+    const char              *ModuleName,
+    UINT32                  ComponentId,
+    UINT8                   *Ptr);
+
+void
+AcpiUtDebugDumpBuffer (
+    UINT8                   *Buffer,
+    UINT32                  Count,
+    UINT32                  Display,
+    UINT32                  ComponentId);
+
+void
+AcpiUtDumpBuffer (
+    UINT8                   *Buffer,
+    UINT32                  Count,
+    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,
+    UINT32                  LineNumber);
+
+void
+AcpiUtReportInfo (
+    char                    *ModuleName,
+    UINT32                  LineNumber);
+
+void
+AcpiUtReportWarning (
+    char                    *ModuleName,
+    UINT32                  LineNumber);
+
+
+/*
+ * utdelete - Object deletion and reference counts
+ */
+void
+AcpiUtAddReference (
+    ACPI_OPERAND_OBJECT     *Object);
+
+void
+AcpiUtRemoveReference (
+    ACPI_OPERAND_OBJECT     *Object);
+
+void
+AcpiUtDeleteInternalPackageObject (
+    ACPI_OPERAND_OBJECT     *Object);
+
+void
+AcpiUtDeleteInternalSimpleObject (
+    ACPI_OPERAND_OBJECT     *Object);
+
+void
+AcpiUtDeleteInternalObjectList (
+    ACPI_OPERAND_OBJECT     **ObjList);
+
+
+/*
+ * uteval - object evaluation
+ */
+ACPI_STATUS
+AcpiUtEvaluateObject (
+    ACPI_NAMESPACE_NODE     *PrefixNode,
+    char                    *Path,
+    UINT32                  ExpectedReturnBtypes,
+    ACPI_OPERAND_OBJECT     **ReturnDesc);
+
+ACPI_STATUS
+AcpiUtEvaluateNumericObject (
+    char                    *ObjectName,
+    ACPI_NAMESPACE_NODE     *DeviceNode,
+    UINT64                  *Value);
+
+ACPI_STATUS
+AcpiUtExecute_STA (
+    ACPI_NAMESPACE_NODE     *DeviceNode,
+    UINT32                  *StatusFlags);
+
+ACPI_STATUS
+AcpiUtExecutePowerMethods (
+    ACPI_NAMESPACE_NODE     *DeviceNode,
+    const char              **MethodNames,
+    UINT8                   MethodCount,
+    UINT8                   *OutValues);
+
+
+/*
+ * utids - device ID support
+ */
+ACPI_STATUS
+AcpiUtExecute_HID (
+    ACPI_NAMESPACE_NODE     *DeviceNode,
+    ACPI_PNP_DEVICE_ID      **ReturnId);
+
+ACPI_STATUS
+AcpiUtExecute_UID (
+    ACPI_NAMESPACE_NODE     *DeviceNode,
+    ACPI_PNP_DEVICE_ID      **ReturnId);
+
+ACPI_STATUS
+AcpiUtExecute_CID (
+    ACPI_NAMESPACE_NODE     *DeviceNode,
+    ACPI_PNP_DEVICE_ID_LIST **ReturnCidList);
+
+ACPI_STATUS
+AcpiUtExecute_CLS (
+    ACPI_NAMESPACE_NODE     *DeviceNode,
+    ACPI_PNP_DEVICE_ID      **ReturnId);
+
+
+/*
+ * utlock - reader/writer locks
+ */
+ACPI_STATUS
+AcpiUtCreateRwLock (
+    ACPI_RW_LOCK            *Lock);
+
+void
+AcpiUtDeleteRwLock (
+    ACPI_RW_LOCK            *Lock);
+
+ACPI_STATUS
+AcpiUtAcquireReadLock (
+    ACPI_RW_LOCK            *Lock);
+
+ACPI_STATUS
+AcpiUtReleaseReadLock (
+    ACPI_RW_LOCK            *Lock);
+
+ACPI_STATUS
+AcpiUtAcquireWriteLock (
+    ACPI_RW_LOCK            *Lock);
+
+void
+AcpiUtReleaseWriteLock (
+    ACPI_RW_LOCK            *Lock);
+
+
+/*
+ * utobject - internal object create/delete/cache routines
+ */
+ACPI_OPERAND_OBJECT  *
+AcpiUtCreateInternalObjectDbg (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    UINT32                  ComponentId,
+    ACPI_OBJECT_TYPE        Type);
+
+void *
+AcpiUtAllocateObjectDescDbg (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    UINT32                  ComponentId);
+
+#define AcpiUtCreateInternalObject(t)   AcpiUtCreateInternalObjectDbg (_AcpiModuleName,__LINE__,_COMPONENT,t)
+#define AcpiUtAllocateObjectDesc()      AcpiUtAllocateObjectDescDbg (_AcpiModuleName,__LINE__,_COMPONENT)
+
+void
+AcpiUtDeleteObjectDesc (
+    ACPI_OPERAND_OBJECT     *Object);
+
+BOOLEAN
+AcpiUtValidInternalObject (
+    void                    *Object);
+
+ACPI_OPERAND_OBJECT *
+AcpiUtCreatePackageObject (
+    UINT32                  Count);
+
+ACPI_OPERAND_OBJECT *
+AcpiUtCreateIntegerObject (
+    UINT64                  Value);
+
+ACPI_OPERAND_OBJECT *
+AcpiUtCreateBufferObject (
+    ACPI_SIZE               BufferSize);
+
+ACPI_OPERAND_OBJECT *
+AcpiUtCreateStringObject (
+    ACPI_SIZE               StringSize);
+
+ACPI_STATUS
+AcpiUtGetObjectSize(
+    ACPI_OPERAND_OBJECT     *Obj,
+    ACPI_SIZE               *ObjLength);
+
+
+/*
+ * utosi - Support for the _OSI predefined control method
+ */
+ACPI_STATUS
+AcpiUtInitializeInterfaces (
+    void);
+
+ACPI_STATUS
+AcpiUtInterfaceTerminate (
+    void);
+
+ACPI_STATUS
+AcpiUtInstallInterface (
+    ACPI_STRING             InterfaceName);
+
+ACPI_STATUS
+AcpiUtRemoveInterface (
+    ACPI_STRING             InterfaceName);
+
+ACPI_STATUS
+AcpiUtUpdateInterfaces (
+    UINT8                   Action);
+
+ACPI_INTERFACE_INFO *
+AcpiUtGetInterface (
+    ACPI_STRING             InterfaceName);
+
+ACPI_STATUS
+AcpiUtOsiImplementation (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*
+ * utpredef - support for predefined names
+ */
+const ACPI_PREDEFINED_INFO *
+AcpiUtGetNextPredefinedMethod (
+    const ACPI_PREDEFINED_INFO  *ThisName);
+
+const ACPI_PREDEFINED_INFO *
+AcpiUtMatchPredefinedMethod (
+    char                        *Name);
+
+void
+AcpiUtGetExpectedReturnTypes (
+    char                    *Buffer,
+    UINT32                  ExpectedBtypes);
+
+#if (defined ACPI_ASL_COMPILER || defined ACPI_HELP_APP)
+const ACPI_PREDEFINED_INFO *
+AcpiUtMatchResourceName (
+    char                        *Name);
+
+void
+AcpiUtDisplayPredefinedMethod (
+    char                        *Buffer,
+    const ACPI_PREDEFINED_INFO  *ThisName,
+    BOOLEAN                     MultiLine);
+
+UINT32
+AcpiUtGetResourceBitWidth (
+    char                    *Buffer,
+    UINT16                  Types);
+#endif
+
+
+/*
+ * utstate - Generic state creation/cache routines
+ */
+void
+AcpiUtPushGenericState (
+    ACPI_GENERIC_STATE      **ListHead,
+    ACPI_GENERIC_STATE      *State);
+
+ACPI_GENERIC_STATE *
+AcpiUtPopGenericState (
+    ACPI_GENERIC_STATE      **ListHead);
+
+
+ACPI_GENERIC_STATE *
+AcpiUtCreateGenericState (
+    void);
+
+ACPI_THREAD_STATE *
+AcpiUtCreateThreadState (
+    void);
+
+ACPI_GENERIC_STATE *
+AcpiUtCreateUpdateState (
+    ACPI_OPERAND_OBJECT     *Object,
+    UINT16                  Action);
+
+ACPI_GENERIC_STATE *
+AcpiUtCreatePkgState (
+    void                    *InternalObject,
+    void                    *ExternalObject,
+    UINT16                  Index);
+
+ACPI_STATUS
+AcpiUtCreateUpdateStateAndPush (
+    ACPI_OPERAND_OBJECT     *Object,
+    UINT16                  Action,
+    ACPI_GENERIC_STATE      **StateList);
+
+ACPI_GENERIC_STATE *
+AcpiUtCreateControlState (
+    void);
+
+void
+AcpiUtDeleteGenericState (
+    ACPI_GENERIC_STATE      *State);
+
+
+/*
+ * utmath
+ */
+ACPI_STATUS
+AcpiUtDivide (
+    UINT64                  InDividend,
+    UINT64                  InDivisor,
+    UINT64                  *OutQuotient,
+    UINT64                  *OutRemainder);
+
+ACPI_STATUS
+AcpiUtShortDivide (
+    UINT64                  InDividend,
+    UINT32                  Divisor,
+    UINT64                  *OutQuotient,
+    UINT32                  *OutRemainder);
+
+
+/*
+ * utmisc
+ */
+const ACPI_EXCEPTION_INFO *
+AcpiUtValidateException (
+    ACPI_STATUS             Status);
+
+BOOLEAN
+AcpiUtIsPciRootBridge (
+    char                    *Id);
+
+#if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_NAMES_APP)
+BOOLEAN
+AcpiUtIsAmlTable (
+    ACPI_TABLE_HEADER       *Table);
+#endif
+
+ACPI_STATUS
+AcpiUtWalkPackageTree (
+    ACPI_OPERAND_OBJECT     *SourceObject,
+    void                    *TargetObject,
+    ACPI_PKG_CALLBACK       WalkCallback,
+    void                    *Context);
+
+/* Values for Base above (16=Hex, 10=Decimal) */
+
+#define ACPI_ANY_BASE        0
+
+
+UINT32
+AcpiUtDwordByteSwap (
+    UINT32                  Value);
+
+void
+AcpiUtSetIntegerWidth (
+    UINT8                   Revision);
+
+#ifdef ACPI_DEBUG_OUTPUT
+void
+AcpiUtDisplayInitPathname (
+    UINT8                   Type,
+    ACPI_NAMESPACE_NODE     *ObjHandle,
+    char                    *Path);
+#endif
+
+
+/*
+ * utownerid - Support for Table/Method Owner IDs
+ */
+ACPI_STATUS
+AcpiUtAllocateOwnerId (
+    ACPI_OWNER_ID           *OwnerId);
+
+void
+AcpiUtReleaseOwnerId (
+    ACPI_OWNER_ID           *OwnerId);
+
+
+/*
+ * utresrc
+ */
+ACPI_STATUS
+AcpiUtWalkAmlResources (
+    ACPI_WALK_STATE         *WalkState,
+    UINT8                   *Aml,
+    ACPI_SIZE               AmlLength,
+    ACPI_WALK_AML_CALLBACK  UserFunction,
+    void                    **Context);
+
+ACPI_STATUS
+AcpiUtValidateResource (
+    ACPI_WALK_STATE         *WalkState,
+    void                    *Aml,
+    UINT8                   *ReturnIndex);
+
+UINT32
+AcpiUtGetDescriptorLength (
+    void                    *Aml);
+
+UINT16
+AcpiUtGetResourceLength (
+    void                    *Aml);
+
+UINT8
+AcpiUtGetResourceHeaderLength (
+    void                    *Aml);
+
+UINT8
+AcpiUtGetResourceType (
+    void                    *Aml);
+
+ACPI_STATUS
+AcpiUtGetResourceEndTag (
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    UINT8                   **EndTag);
+
+
+/*
+ * utstring - String and character utilities
+ */
+void
+AcpiUtPrintString (
+    char                    *String,
+    UINT16                  MaxLength);
+
+#if defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP
+void
+UtConvertBackslashes (
+    char                    *Pathname);
+#endif
+
+BOOLEAN
+AcpiUtValidAcpiName (
+    char                    *Name);
+
+BOOLEAN
+AcpiUtValidAcpiChar (
+    char                    Character,
+    UINT32                  Position);
+
+void
+AcpiUtRepairName (
+    char                    *Name);
+
+#if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION)
+BOOLEAN
+AcpiUtSafeStrcpy (
+    char                    *Dest,
+    ACPI_SIZE               DestSize,
+    char                    *Source);
+
+BOOLEAN
+AcpiUtSafeStrcat (
+    char                    *Dest,
+    ACPI_SIZE               DestSize,
+    char                    *Source);
+
+BOOLEAN
+AcpiUtSafeStrncat (
+    char                    *Dest,
+    ACPI_SIZE               DestSize,
+    char                    *Source,
+    ACPI_SIZE               MaxTransferLength);
+#endif
+
+
+/*
+ * utmutex - mutex support
+ */
+ACPI_STATUS
+AcpiUtMutexInitialize (
+    void);
+
+void
+AcpiUtMutexTerminate (
+    void);
+
+ACPI_STATUS
+AcpiUtAcquireMutex (
+    ACPI_MUTEX_HANDLE       MutexId);
+
+ACPI_STATUS
+AcpiUtReleaseMutex (
+    ACPI_MUTEX_HANDLE       MutexId);
+
+
+/*
+ * utalloc - memory allocation and object caching
+ */
+ACPI_STATUS
+AcpiUtCreateCaches (
+    void);
+
+ACPI_STATUS
+AcpiUtDeleteCaches (
+    void);
+
+ACPI_STATUS
+AcpiUtValidateBuffer (
+    ACPI_BUFFER             *Buffer);
+
+ACPI_STATUS
+AcpiUtInitializeBuffer (
+    ACPI_BUFFER             *Buffer,
+    ACPI_SIZE               RequiredLength);
+
+#ifdef ACPI_DBG_TRACK_ALLOCATIONS
+void *
+AcpiUtAllocateAndTrack (
+    ACPI_SIZE               Size,
+    UINT32                  Component,
+    const char              *Module,
+    UINT32                  Line);
+
+void *
+AcpiUtAllocateZeroedAndTrack (
+    ACPI_SIZE               Size,
+    UINT32                  Component,
+    const char              *Module,
+    UINT32                  Line);
+
+void
+AcpiUtFreeAndTrack (
+    void                    *Address,
+    UINT32                  Component,
+    const char              *Module,
+    UINT32                  Line);
+
+void
+AcpiUtDumpAllocationInfo (
+    void);
+
+void
+AcpiUtDumpAllocations (
+    UINT32                  Component,
+    const char              *Module);
+
+ACPI_STATUS
+AcpiUtCreateList (
+    char                    *ListName,
+    UINT16                  ObjectSize,
+    ACPI_MEMORY_LIST        **ReturnCache);
+
+#endif /* ACPI_DBG_TRACK_ALLOCATIONS */
+
+
+/*
+ * utaddress - address range check
+ */
+ACPI_STATUS
+AcpiUtAddAddressRange (
+    ACPI_ADR_SPACE_TYPE     SpaceId,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT32                  Length,
+    ACPI_NAMESPACE_NODE     *RegionNode);
+
+void
+AcpiUtRemoveAddressRange (
+    ACPI_ADR_SPACE_TYPE     SpaceId,
+    ACPI_NAMESPACE_NODE     *RegionNode);
+
+UINT32
+AcpiUtCheckAddressRange (
+    ACPI_ADR_SPACE_TYPE     SpaceId,
+    ACPI_PHYSICAL_ADDRESS   Address,
+    UINT32                  Length,
+    BOOLEAN                 Warn);
+
+void
+AcpiUtDeleteAddressLists (
+    void);
+
+
+/*
+ * utxferror - various error/warning output functions
+ */
+void ACPI_INTERNAL_VAR_XFACE
+AcpiUtPredefinedWarning (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    char                    *Pathname,
+    UINT8                   NodeFlags,
+    const char              *Format,
+    ...);
+
+void ACPI_INTERNAL_VAR_XFACE
+AcpiUtPredefinedInfo (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    char                    *Pathname,
+    UINT8                   NodeFlags,
+    const char              *Format,
+    ...);
+
+void ACPI_INTERNAL_VAR_XFACE
+AcpiUtPredefinedBiosError (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    char                    *Pathname,
+    UINT8                   NodeFlags,
+    const char              *Format,
+    ...);
+
+void
+AcpiUtNamespaceError (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    const char              *InternalName,
+    ACPI_STATUS             LookupStatus);
+
+void
+AcpiUtMethodError (
+    const char              *ModuleName,
+    UINT32                  LineNumber,
+    const char              *Message,
+    ACPI_NAMESPACE_NODE     *Node,
+    const char              *Path,
+    ACPI_STATUS             LookupStatus);
+
+
+/*
+ * Utility functions for ACPI names and IDs
+ */
+const AH_PREDEFINED_NAME *
+AcpiAhMatchPredefinedName (
+    char                    *Nameseg);
+
+const AH_DEVICE_ID *
+AcpiAhMatchHardwareId (
+    char                    *Hid);
+
+const char *
+AcpiAhMatchUuid (
+    UINT8                   *Data);
+
+
+/*
+ * 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
+
+
+/*
+ * utuuid -- UUID support functions
+ */
+#if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_HELP_APP)
+void
+AcpiUtConvertStringToUuid (
+    char                    *InString,
+    UINT8                   *UuidBuffer);
+#endif
+
+#endif /* _ACUTILS_H */

+ 90 - 0
kernel/include/acpica/acuuid.h

@@ -0,0 +1,90 @@
+/******************************************************************************
+ *
+ * Name: acuuid.h - ACPI-related UUID/GUID definitions
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACUUID_H__
+#define __ACUUID_H__
+
+/*
+ * Note1: UUIDs and GUIDs are defined to be identical in ACPI.
+ *
+ * Note2: This file is standalone and should remain that way.
+ */
+
+/* Controllers */
+
+#define UUID_GPIO_CONTROLLER            "4f248f40-d5e2-499f-834c-27758ea1cd3f"
+#define UUID_USB_CONTROLLER             "ce2ee385-00e6-48cb-9f05-2edb927c4899"
+#define UUID_SATA_CONTROLLER            "e4db149b-fcfe-425b-a6d8-92357d78fc7f"
+
+/* Devices */
+
+#define UUID_PCI_HOST_BRIDGE            "33db4d5b-1ff7-401c-9657-7441c03dd766"
+#define UUID_I2C_DEVICE                 "3cdff6f7-4267-4555-ad05-b30a3d8938de"
+#define UUID_POWER_BUTTON               "dfbcf3c5-e7a5-44e6-9c1f-29c76f6e059c"
+
+/* Interfaces */
+
+#define UUID_DEVICE_LABELING            "e5c937d0-3553-4d7a-9117-ea4d19c3434d"
+#define UUID_PHYSICAL_PRESENCE          "3dddfaa6-361b-4eb4-a424-8d10089d1653"
+
+/* NVDIMM - NFIT table */
+
+#define UUID_VOLATILE_MEMORY            "7305944f-fdda-44e3-b16c-3f22d252e5d0"
+#define UUID_PERSISTENT_MEMORY          "66f0d379-b4f3-4074-ac43-0d3318b78cdb"
+#define UUID_CONTROL_REGION             "92f701f6-13b4-405d-910b-299367e8234c"
+#define UUID_DATA_REGION                "91af0530-5d86-470e-a6b0-0a2db9408249"
+#define UUID_VOLATILE_VIRTUAL_DISK      "77ab535a-45fc-624b-5560-f7b281d1f96e"
+#define UUID_VOLATILE_VIRTUAL_CD        "3d5abd30-4175-87ce-6d64-d2ade523c4bb"
+#define UUID_PERSISTENT_VIRTUAL_DISK    "5cea02c9-4d07-69d3-269f-4496fbe096f9"
+#define UUID_PERSISTENT_VIRTUAL_CD      "08018188-42cd-bb48-100f-5387d53ded3d"
+
+/* Miscellaneous */
+
+#define UUID_PLATFORM_CAPABILITIES      "0811b06e-4a27-44f9-8d60-3cbbc22e7b48"
+#define UUID_DYNAMIC_ENUMERATION        "d8c1a3a6-be9b-4c9b-91bf-c3cb81fc5daf"
+#define UUID_BATTERY_THERMAL_LIMIT      "4c2067e3-887d-475c-9720-4af1d3ed602e"
+#define UUID_THERMAL_EXTENSIONS         "14d399cd-7a27-4b18-8fb4-7cb7b9f4e500"
+#define UUID_DEVICE_PROPERTIES          "daffd814-6eba-4d8c-8a91-bc9bbf4aa301"
+
+
+#endif /* __AUUID_H__ */

+ 514 - 0
kernel/include/acpica/amlcode.h

@@ -0,0 +1,514 @@
+/******************************************************************************
+ *
+ * Name: amlcode.h - Definitions for AML, as included in "definition blocks"
+ *                   Declarations and definitions contained herein are derived
+ *                   directly from the ACPI specification.
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __AMLCODE_H__
+#define __AMLCODE_H__
+
+/* primary opcodes */
+
+#define AML_NULL_CHAR               (UINT16) 0x00
+
+#define AML_ZERO_OP                 (UINT16) 0x00
+#define AML_ONE_OP                  (UINT16) 0x01
+#define AML_UNASSIGNED              (UINT16) 0x02
+#define AML_ALIAS_OP                (UINT16) 0x06
+#define AML_NAME_OP                 (UINT16) 0x08
+#define AML_BYTE_OP                 (UINT16) 0x0a
+#define AML_WORD_OP                 (UINT16) 0x0b
+#define AML_DWORD_OP                (UINT16) 0x0c
+#define AML_STRING_OP               (UINT16) 0x0d
+#define AML_QWORD_OP                (UINT16) 0x0e     /* ACPI 2.0 */
+#define AML_SCOPE_OP                (UINT16) 0x10
+#define AML_BUFFER_OP               (UINT16) 0x11
+#define AML_PACKAGE_OP              (UINT16) 0x12
+#define AML_VAR_PACKAGE_OP          (UINT16) 0x13     /* ACPI 2.0 */
+#define AML_METHOD_OP               (UINT16) 0x14
+#define AML_EXTERNAL_OP             (UINT16) 0x15     /* ACPI 6.0 */
+#define AML_DUAL_NAME_PREFIX        (UINT16) 0x2e
+#define AML_MULTI_NAME_PREFIX_OP    (UINT16) 0x2f
+#define AML_NAME_CHAR_SUBSEQ        (UINT16) 0x30
+#define AML_NAME_CHAR_FIRST         (UINT16) 0x41
+#define AML_EXTENDED_OP_PREFIX      (UINT16) 0x5b
+#define AML_ROOT_PREFIX             (UINT16) 0x5c
+#define AML_PARENT_PREFIX           (UINT16) 0x5e
+#define AML_LOCAL_OP                (UINT16) 0x60
+#define AML_LOCAL0                  (UINT16) 0x60
+#define AML_LOCAL1                  (UINT16) 0x61
+#define AML_LOCAL2                  (UINT16) 0x62
+#define AML_LOCAL3                  (UINT16) 0x63
+#define AML_LOCAL4                  (UINT16) 0x64
+#define AML_LOCAL5                  (UINT16) 0x65
+#define AML_LOCAL6                  (UINT16) 0x66
+#define AML_LOCAL7                  (UINT16) 0x67
+#define AML_ARG_OP                  (UINT16) 0x68
+#define AML_ARG0                    (UINT16) 0x68
+#define AML_ARG1                    (UINT16) 0x69
+#define AML_ARG2                    (UINT16) 0x6a
+#define AML_ARG3                    (UINT16) 0x6b
+#define AML_ARG4                    (UINT16) 0x6c
+#define AML_ARG5                    (UINT16) 0x6d
+#define AML_ARG6                    (UINT16) 0x6e
+#define AML_STORE_OP                (UINT16) 0x70
+#define AML_REF_OF_OP               (UINT16) 0x71
+#define AML_ADD_OP                  (UINT16) 0x72
+#define AML_CONCAT_OP               (UINT16) 0x73
+#define AML_SUBTRACT_OP             (UINT16) 0x74
+#define AML_INCREMENT_OP            (UINT16) 0x75
+#define AML_DECREMENT_OP            (UINT16) 0x76
+#define AML_MULTIPLY_OP             (UINT16) 0x77
+#define AML_DIVIDE_OP               (UINT16) 0x78
+#define AML_SHIFT_LEFT_OP           (UINT16) 0x79
+#define AML_SHIFT_RIGHT_OP          (UINT16) 0x7a
+#define AML_BIT_AND_OP              (UINT16) 0x7b
+#define AML_BIT_NAND_OP             (UINT16) 0x7c
+#define AML_BIT_OR_OP               (UINT16) 0x7d
+#define AML_BIT_NOR_OP              (UINT16) 0x7e
+#define AML_BIT_XOR_OP              (UINT16) 0x7f
+#define AML_BIT_NOT_OP              (UINT16) 0x80
+#define AML_FIND_SET_LEFT_BIT_OP    (UINT16) 0x81
+#define AML_FIND_SET_RIGHT_BIT_OP   (UINT16) 0x82
+#define AML_DEREF_OF_OP             (UINT16) 0x83
+#define AML_CONCAT_RES_OP           (UINT16) 0x84     /* ACPI 2.0 */
+#define AML_MOD_OP                  (UINT16) 0x85     /* ACPI 2.0 */
+#define AML_NOTIFY_OP               (UINT16) 0x86
+#define AML_SIZE_OF_OP              (UINT16) 0x87
+#define AML_INDEX_OP                (UINT16) 0x88
+#define AML_MATCH_OP                (UINT16) 0x89
+#define AML_CREATE_DWORD_FIELD_OP   (UINT16) 0x8a
+#define AML_CREATE_WORD_FIELD_OP    (UINT16) 0x8b
+#define AML_CREATE_BYTE_FIELD_OP    (UINT16) 0x8c
+#define AML_CREATE_BIT_FIELD_OP     (UINT16) 0x8d
+#define AML_OBJECT_TYPE_OP          (UINT16) 0x8e
+#define AML_CREATE_QWORD_FIELD_OP   (UINT16) 0x8f     /* ACPI 2.0 */
+#define AML_LAND_OP                 (UINT16) 0x90
+#define AML_LOR_OP                  (UINT16) 0x91
+#define AML_LNOT_OP                 (UINT16) 0x92
+#define AML_LEQUAL_OP               (UINT16) 0x93
+#define AML_LGREATER_OP             (UINT16) 0x94
+#define AML_LLESS_OP                (UINT16) 0x95
+#define AML_TO_BUFFER_OP            (UINT16) 0x96     /* ACPI 2.0 */
+#define AML_TO_DECSTRING_OP         (UINT16) 0x97     /* ACPI 2.0 */
+#define AML_TO_HEXSTRING_OP         (UINT16) 0x98     /* ACPI 2.0 */
+#define AML_TO_INTEGER_OP           (UINT16) 0x99     /* ACPI 2.0 */
+#define AML_TO_STRING_OP            (UINT16) 0x9c     /* ACPI 2.0 */
+#define AML_COPY_OP                 (UINT16) 0x9d     /* ACPI 2.0 */
+#define AML_MID_OP                  (UINT16) 0x9e     /* ACPI 2.0 */
+#define AML_CONTINUE_OP             (UINT16) 0x9f     /* ACPI 2.0 */
+#define AML_IF_OP                   (UINT16) 0xa0
+#define AML_ELSE_OP                 (UINT16) 0xa1
+#define AML_WHILE_OP                (UINT16) 0xa2
+#define AML_NOOP_OP                 (UINT16) 0xa3
+#define AML_RETURN_OP               (UINT16) 0xa4
+#define AML_BREAK_OP                (UINT16) 0xa5
+#define AML_BREAK_POINT_OP          (UINT16) 0xcc
+#define AML_ONES_OP                 (UINT16) 0xff
+
+/* prefixed opcodes */
+
+#define AML_EXTENDED_OPCODE         (UINT16) 0x5b00     /* prefix for 2-byte opcodes */
+
+#define AML_MUTEX_OP                (UINT16) 0x5b01
+#define AML_EVENT_OP                (UINT16) 0x5b02
+#define AML_SHIFT_RIGHT_BIT_OP      (UINT16) 0x5b10
+#define AML_SHIFT_LEFT_BIT_OP       (UINT16) 0x5b11
+#define AML_COND_REF_OF_OP          (UINT16) 0x5b12
+#define AML_CREATE_FIELD_OP         (UINT16) 0x5b13
+#define AML_LOAD_TABLE_OP           (UINT16) 0x5b1f     /* ACPI 2.0 */
+#define AML_LOAD_OP                 (UINT16) 0x5b20
+#define AML_STALL_OP                (UINT16) 0x5b21
+#define AML_SLEEP_OP                (UINT16) 0x5b22
+#define AML_ACQUIRE_OP              (UINT16) 0x5b23
+#define AML_SIGNAL_OP               (UINT16) 0x5b24
+#define AML_WAIT_OP                 (UINT16) 0x5b25
+#define AML_RESET_OP                (UINT16) 0x5b26
+#define AML_RELEASE_OP              (UINT16) 0x5b27
+#define AML_FROM_BCD_OP             (UINT16) 0x5b28
+#define AML_TO_BCD_OP               (UINT16) 0x5b29
+#define AML_UNLOAD_OP               (UINT16) 0x5b2a
+#define AML_REVISION_OP             (UINT16) 0x5b30
+#define AML_DEBUG_OP                (UINT16) 0x5b31
+#define AML_FATAL_OP                (UINT16) 0x5b32
+#define AML_TIMER_OP                (UINT16) 0x5b33     /* ACPI 3.0 */
+#define AML_REGION_OP               (UINT16) 0x5b80
+#define AML_FIELD_OP                (UINT16) 0x5b81
+#define AML_DEVICE_OP               (UINT16) 0x5b82
+#define AML_PROCESSOR_OP            (UINT16) 0x5b83
+#define AML_POWER_RES_OP            (UINT16) 0x5b84
+#define AML_THERMAL_ZONE_OP         (UINT16) 0x5b85
+#define AML_INDEX_FIELD_OP          (UINT16) 0x5b86
+#define AML_BANK_FIELD_OP           (UINT16) 0x5b87
+#define AML_DATA_REGION_OP          (UINT16) 0x5b88     /* ACPI 2.0 */
+
+
+/*
+ * Combination opcodes (actually two one-byte opcodes)
+ * Used by the disassembler and iASL compiler
+ */
+#define AML_LGREATEREQUAL_OP        (UINT16) 0x9295
+#define AML_LLESSEQUAL_OP           (UINT16) 0x9294
+#define AML_LNOTEQUAL_OP            (UINT16) 0x9293
+
+
+/*
+ * Opcodes for "Field" operators
+ */
+#define AML_FIELD_OFFSET_OP         (UINT8) 0x00
+#define AML_FIELD_ACCESS_OP         (UINT8) 0x01
+#define AML_FIELD_CONNECTION_OP     (UINT8) 0x02        /* ACPI 5.0 */
+#define AML_FIELD_EXT_ACCESS_OP     (UINT8) 0x03        /* ACPI 5.0 */
+
+
+/*
+ * Internal opcodes
+ * Use only "Unknown" AML opcodes, don't attempt to use
+ * any valid ACPI ASCII values (A-Z, 0-9, '-')
+ */
+#define AML_INT_NAMEPATH_OP         (UINT16) 0x002d
+#define AML_INT_NAMEDFIELD_OP       (UINT16) 0x0030
+#define AML_INT_RESERVEDFIELD_OP    (UINT16) 0x0031
+#define AML_INT_ACCESSFIELD_OP      (UINT16) 0x0032
+#define AML_INT_BYTELIST_OP         (UINT16) 0x0033
+#define AML_INT_METHODCALL_OP       (UINT16) 0x0035
+#define AML_INT_RETURN_VALUE_OP     (UINT16) 0x0036
+#define AML_INT_EVAL_SUBTREE_OP     (UINT16) 0x0037
+#define AML_INT_CONNECTION_OP       (UINT16) 0x0038
+#define AML_INT_EXTACCESSFIELD_OP   (UINT16) 0x0039
+
+#define ARG_NONE                    0x0
+
+/*
+ * Argument types for the AML Parser
+ * Each field in the ArgTypes UINT32 is 5 bits, allowing for a maximum of 6 arguments.
+ * There can be up to 31 unique argument types
+ * Zero is reserved as end-of-list indicator
+ */
+#define ARGP_BYTEDATA               0x01
+#define ARGP_BYTELIST               0x02
+#define ARGP_CHARLIST               0x03
+#define ARGP_DATAOBJ                0x04
+#define ARGP_DATAOBJLIST            0x05
+#define ARGP_DWORDDATA              0x06
+#define ARGP_FIELDLIST              0x07
+#define ARGP_NAME                   0x08
+#define ARGP_NAMESTRING             0x09
+#define ARGP_OBJLIST                0x0A
+#define ARGP_PKGLENGTH              0x0B
+#define ARGP_SUPERNAME              0x0C
+#define ARGP_TARGET                 0x0D
+#define ARGP_TERMARG                0x0E
+#define ARGP_TERMLIST               0x0F
+#define ARGP_WORDDATA               0x10
+#define ARGP_QWORDDATA              0x11
+#define ARGP_SIMPLENAME             0x12 /* NameString | LocalTerm | ArgTerm */
+#define ARGP_NAME_OR_REF            0x13 /* For ObjectType only */
+
+/*
+ * Resolved argument types for the AML Interpreter
+ * Each field in the ArgTypes UINT32 is 5 bits, allowing for a maximum of 6 arguments.
+ * There can be up to 31 unique argument types (0 is end-of-arg-list indicator)
+ *
+ * Note1: These values are completely independent from the ACPI_TYPEs
+ *        i.e., ARGI_INTEGER != ACPI_TYPE_INTEGER
+ *
+ * Note2: If and when 5 bits becomes insufficient, it would probably be best
+ * to convert to a 6-byte array of argument types, allowing 8 bits per argument.
+ */
+
+/* Single, simple types */
+
+#define ARGI_ANYTYPE                0x01    /* Don't care */
+#define ARGI_PACKAGE                0x02
+#define ARGI_EVENT                  0x03
+#define ARGI_MUTEX                  0x04
+#define ARGI_DDBHANDLE              0x05
+
+/* Interchangeable types (via implicit conversion) */
+
+#define ARGI_INTEGER                0x06
+#define ARGI_STRING                 0x07
+#define ARGI_BUFFER                 0x08
+#define ARGI_BUFFER_OR_STRING       0x09    /* Used by MID op only */
+#define ARGI_COMPUTEDATA            0x0A    /* Buffer, String, or Integer */
+
+/* Reference objects */
+
+#define ARGI_INTEGER_REF            0x0B
+#define ARGI_OBJECT_REF             0x0C
+#define ARGI_DEVICE_REF             0x0D
+#define ARGI_REFERENCE              0x0E
+#define ARGI_TARGETREF              0x0F    /* Target, subject to implicit conversion */
+#define ARGI_FIXED_TARGET           0x10    /* Target, no implicit conversion */
+#define ARGI_SIMPLE_TARGET          0x11    /* Name, Local, Arg -- no implicit conversion */
+#define ARGI_STORE_TARGET           0x12    /* Target for store is TARGETREF + package objects */
+
+/* Multiple/complex types */
+
+#define ARGI_DATAOBJECT             0x13    /* Buffer, String, package or reference to a Node - Used only by SizeOf operator*/
+#define ARGI_COMPLEXOBJ             0x14    /* Buffer, String, or package (Used by INDEX op only) */
+#define ARGI_REF_OR_STRING          0x15    /* Reference or String (Used by DEREFOF op only) */
+#define ARGI_REGION_OR_BUFFER       0x16    /* Used by LOAD op only */
+#define ARGI_DATAREFOBJ             0x17
+
+/* Note: types above can expand to 0x1F maximum */
+
+#define ARGI_INVALID_OPCODE         0xFFFFFFFF
+
+
+/*
+ * hash offsets
+ */
+#define AML_EXTOP_HASH_OFFSET       22
+#define AML_LNOT_HASH_OFFSET        19
+
+
+/*
+ * opcode groups and types
+ */
+#define OPGRP_NAMED                 0x01
+#define OPGRP_FIELD                 0x02
+#define OPGRP_BYTELIST              0x04
+
+
+/*
+ * Opcode information
+ */
+
+/* Opcode flags */
+
+#define AML_LOGICAL                 0x0001
+#define AML_LOGICAL_NUMERIC         0x0002
+#define AML_MATH                    0x0004
+#define AML_CREATE                  0x0008
+#define AML_FIELD                   0x0010
+#define AML_DEFER                   0x0020
+#define AML_NAMED                   0x0040
+#define AML_NSNODE                  0x0080
+#define AML_NSOPCODE                0x0100
+#define AML_NSOBJECT                0x0200
+#define AML_HAS_RETVAL              0x0400
+#define AML_HAS_TARGET              0x0800
+#define AML_HAS_ARGS                0x1000
+#define AML_CONSTANT                0x2000
+#define AML_NO_OPERAND_RESOLVE      0x4000
+
+/* Convenient flag groupings */
+
+#define AML_FLAGS_EXEC_0A_0T_1R                                     AML_HAS_RETVAL
+#define AML_FLAGS_EXEC_1A_0T_0R     AML_HAS_ARGS                                   /* Monadic1  */
+#define AML_FLAGS_EXEC_1A_0T_1R     AML_HAS_ARGS |                  AML_HAS_RETVAL /* Monadic2  */
+#define AML_FLAGS_EXEC_1A_1T_0R     AML_HAS_ARGS | AML_HAS_TARGET
+#define AML_FLAGS_EXEC_1A_1T_1R     AML_HAS_ARGS | AML_HAS_TARGET | AML_HAS_RETVAL /* Monadic2R */
+#define AML_FLAGS_EXEC_2A_0T_0R     AML_HAS_ARGS                                   /* Dyadic1   */
+#define AML_FLAGS_EXEC_2A_0T_1R     AML_HAS_ARGS |                  AML_HAS_RETVAL /* Dyadic2   */
+#define AML_FLAGS_EXEC_2A_1T_1R     AML_HAS_ARGS | AML_HAS_TARGET | AML_HAS_RETVAL /* Dyadic2R  */
+#define AML_FLAGS_EXEC_2A_2T_1R     AML_HAS_ARGS | AML_HAS_TARGET | AML_HAS_RETVAL
+#define AML_FLAGS_EXEC_3A_0T_0R     AML_HAS_ARGS
+#define AML_FLAGS_EXEC_3A_1T_1R     AML_HAS_ARGS | AML_HAS_TARGET | AML_HAS_RETVAL
+#define AML_FLAGS_EXEC_6A_0T_1R     AML_HAS_ARGS |                  AML_HAS_RETVAL
+
+
+/*
+ * The opcode Type is used in a dispatch table, do not change
+ * without updating the table.
+ */
+#define AML_TYPE_EXEC_0A_0T_1R      0x00
+#define AML_TYPE_EXEC_1A_0T_0R      0x01 /* Monadic1  */
+#define AML_TYPE_EXEC_1A_0T_1R      0x02 /* Monadic2  */
+#define AML_TYPE_EXEC_1A_1T_0R      0x03
+#define AML_TYPE_EXEC_1A_1T_1R      0x04 /* Monadic2R */
+#define AML_TYPE_EXEC_2A_0T_0R      0x05 /* Dyadic1   */
+#define AML_TYPE_EXEC_2A_0T_1R      0x06 /* Dyadic2   */
+#define AML_TYPE_EXEC_2A_1T_1R      0x07 /* Dyadic2R  */
+#define AML_TYPE_EXEC_2A_2T_1R      0x08
+#define AML_TYPE_EXEC_3A_0T_0R      0x09
+#define AML_TYPE_EXEC_3A_1T_1R      0x0A
+#define AML_TYPE_EXEC_6A_0T_1R      0x0B
+/* End of types used in dispatch table */
+
+#define AML_TYPE_LITERAL            0x0B
+#define AML_TYPE_CONSTANT           0x0C
+#define AML_TYPE_METHOD_ARGUMENT    0x0D
+#define AML_TYPE_LOCAL_VARIABLE     0x0E
+#define AML_TYPE_DATA_TERM          0x0F
+
+/* Generic for an op that returns a value */
+
+#define AML_TYPE_METHOD_CALL        0x10
+
+/* Misc */
+
+#define AML_TYPE_CREATE_FIELD       0x11
+#define AML_TYPE_CREATE_OBJECT      0x12
+#define AML_TYPE_CONTROL            0x13
+#define AML_TYPE_NAMED_NO_OBJ       0x14
+#define AML_TYPE_NAMED_FIELD        0x15
+#define AML_TYPE_NAMED_SIMPLE       0x16
+#define AML_TYPE_NAMED_COMPLEX      0x17
+#define AML_TYPE_RETURN             0x18
+
+#define AML_TYPE_UNDEFINED          0x19
+#define AML_TYPE_BOGUS              0x1A
+
+/* AML Package Length encodings */
+
+#define ACPI_AML_PACKAGE_TYPE1      0x40
+#define ACPI_AML_PACKAGE_TYPE2      0x4000
+#define ACPI_AML_PACKAGE_TYPE3      0x400000
+#define ACPI_AML_PACKAGE_TYPE4      0x40000000
+
+/*
+ * Opcode classes
+ */
+#define AML_CLASS_EXECUTE           0x00
+#define AML_CLASS_CREATE            0x01
+#define AML_CLASS_ARGUMENT          0x02
+#define AML_CLASS_NAMED_OBJECT      0x03
+#define AML_CLASS_CONTROL           0x04
+#define AML_CLASS_ASCII             0x05
+#define AML_CLASS_PREFIX            0x06
+#define AML_CLASS_INTERNAL          0x07
+#define AML_CLASS_RETURN_VALUE      0x08
+#define AML_CLASS_METHOD_CALL       0x09
+#define AML_CLASS_UNKNOWN           0x0A
+
+
+/* Comparison operation codes for MatchOp operator */
+
+typedef enum
+{
+    MATCH_MTR                       = 0,
+    MATCH_MEQ                       = 1,
+    MATCH_MLE                       = 2,
+    MATCH_MLT                       = 3,
+    MATCH_MGE                       = 4,
+    MATCH_MGT                       = 5
+
+} AML_MATCH_OPERATOR;
+
+#define MAX_MATCH_OPERATOR          5
+
+
+/*
+ * FieldFlags
+ *
+ * This byte is extracted from the AML and includes three separate
+ * pieces of information about the field:
+ * 1) The field access type
+ * 2) The field update rule
+ * 3) The lock rule for the field
+ *
+ * Bits 00 - 03 : AccessType (AnyAcc, ByteAcc, etc.)
+ *      04      : LockRule (1 == Lock)
+ *      05 - 06 : UpdateRule
+ */
+#define AML_FIELD_ACCESS_TYPE_MASK  0x0F
+#define AML_FIELD_LOCK_RULE_MASK    0x10
+#define AML_FIELD_UPDATE_RULE_MASK  0x60
+
+
+/* 1) Field Access Types */
+
+typedef enum
+{
+    AML_FIELD_ACCESS_ANY            = 0x00,
+    AML_FIELD_ACCESS_BYTE           = 0x01,
+    AML_FIELD_ACCESS_WORD           = 0x02,
+    AML_FIELD_ACCESS_DWORD          = 0x03,
+    AML_FIELD_ACCESS_QWORD          = 0x04,    /* ACPI 2.0 */
+    AML_FIELD_ACCESS_BUFFER         = 0x05     /* ACPI 2.0 */
+
+} AML_ACCESS_TYPE;
+
+
+/* 2) Field Lock Rules */
+
+typedef enum
+{
+    AML_FIELD_LOCK_NEVER            = 0x00,
+    AML_FIELD_LOCK_ALWAYS           = 0x10
+
+} AML_LOCK_RULE;
+
+
+/* 3) Field Update Rules */
+
+typedef enum
+{
+    AML_FIELD_UPDATE_PRESERVE       = 0x00,
+    AML_FIELD_UPDATE_WRITE_AS_ONES  = 0x20,
+    AML_FIELD_UPDATE_WRITE_AS_ZEROS = 0x40
+
+} AML_UPDATE_RULE;
+
+
+/*
+ * Field Access Attributes.
+ * This byte is extracted from the AML via the
+ * AccessAs keyword
+ */
+typedef enum
+{
+    AML_FIELD_ATTRIB_QUICK          = 0x02,
+    AML_FIELD_ATTRIB_SEND_RCV       = 0x04,
+    AML_FIELD_ATTRIB_BYTE           = 0x06,
+    AML_FIELD_ATTRIB_WORD           = 0x08,
+    AML_FIELD_ATTRIB_BLOCK          = 0x0A,
+    AML_FIELD_ATTRIB_MULTIBYTE      = 0x0B,
+    AML_FIELD_ATTRIB_WORD_CALL      = 0x0C,
+    AML_FIELD_ATTRIB_BLOCK_CALL     = 0x0D,
+    AML_FIELD_ATTRIB_RAW_BYTES      = 0x0E,
+    AML_FIELD_ATTRIB_RAW_PROCESS    = 0x0F
+
+} AML_ACCESS_ATTRIBUTE;
+
+
+/* Bit fields in the AML MethodFlags byte */
+
+#define AML_METHOD_ARG_COUNT        0x07
+#define AML_METHOD_SERIALIZED       0x08
+#define AML_METHOD_SYNC_LEVEL       0xF0
+
+
+#endif /* __AMLCODE_H__ */

+ 631 - 0
kernel/include/acpica/amlresrc.h

@@ -0,0 +1,631 @@
+/******************************************************************************
+ *
+ * Module Name: amlresrc.h - AML resource descriptors
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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.
+ */
+
+/* acpisrc:StructDefs -- for acpisrc conversion */
+
+#ifndef __AMLRESRC_H
+#define __AMLRESRC_H
+
+
+/*
+ * Resource descriptor tags, as defined in the ACPI specification.
+ * Used to symbolically reference fields within a descriptor.
+ */
+#define ACPI_RESTAG_ADDRESS                     "_ADR"
+#define ACPI_RESTAG_ALIGNMENT                   "_ALN"
+#define ACPI_RESTAG_ADDRESSSPACE                "_ASI"
+#define ACPI_RESTAG_ACCESSSIZE                  "_ASZ"
+#define ACPI_RESTAG_TYPESPECIFICATTRIBUTES      "_ATT"
+#define ACPI_RESTAG_BASEADDRESS                 "_BAS"
+#define ACPI_RESTAG_BUSMASTER                   "_BM_"  /* Master(1), Slave(0) */
+#define ACPI_RESTAG_DEBOUNCETIME                "_DBT"
+#define ACPI_RESTAG_DECODE                      "_DEC"
+#define ACPI_RESTAG_DEVICEPOLARITY              "_DPL"
+#define ACPI_RESTAG_DMA                         "_DMA"
+#define ACPI_RESTAG_DMATYPE                     "_TYP"  /* Compatible(0), A(1), B(2), F(3) */
+#define ACPI_RESTAG_DRIVESTRENGTH               "_DRS"
+#define ACPI_RESTAG_ENDIANNESS                  "_END"
+#define ACPI_RESTAG_FLOWCONTROL                 "_FLC"
+#define ACPI_RESTAG_GRANULARITY                 "_GRA"
+#define ACPI_RESTAG_INTERRUPT                   "_INT"
+#define ACPI_RESTAG_INTERRUPTLEVEL              "_LL_"  /* ActiveLo(1), ActiveHi(0) */
+#define ACPI_RESTAG_INTERRUPTSHARE              "_SHR"  /* Shareable(1), NoShare(0) */
+#define ACPI_RESTAG_INTERRUPTTYPE               "_HE_"  /* Edge(1), Level(0) */
+#define ACPI_RESTAG_IORESTRICTION               "_IOR"
+#define ACPI_RESTAG_LENGTH                      "_LEN"
+#define ACPI_RESTAG_LINE                        "_LIN"
+#define ACPI_RESTAG_MEMATTRIBUTES               "_MTP"  /* Memory(0), Reserved(1), ACPI(2), NVS(3) */
+#define ACPI_RESTAG_MEMTYPE                     "_MEM"  /* NonCache(0), Cacheable(1) Cache+combine(2), Cache+prefetch(3) */
+#define ACPI_RESTAG_MAXADDR                     "_MAX"
+#define ACPI_RESTAG_MINADDR                     "_MIN"
+#define ACPI_RESTAG_MAXTYPE                     "_MAF"
+#define ACPI_RESTAG_MINTYPE                     "_MIF"
+#define ACPI_RESTAG_MODE                        "_MOD"
+#define ACPI_RESTAG_PARITY                      "_PAR"
+#define ACPI_RESTAG_PHASE                       "_PHA"
+#define ACPI_RESTAG_PIN                         "_PIN"
+#define ACPI_RESTAG_PINCONFIG                   "_PPI"
+#define ACPI_RESTAG_POLARITY                    "_POL"
+#define ACPI_RESTAG_REGISTERBITOFFSET           "_RBO"
+#define ACPI_RESTAG_REGISTERBITWIDTH            "_RBW"
+#define ACPI_RESTAG_RANGETYPE                   "_RNG"
+#define ACPI_RESTAG_READWRITETYPE               "_RW_"  /* ReadOnly(0), Writeable (1) */
+#define ACPI_RESTAG_LENGTH_RX                   "_RXL"
+#define ACPI_RESTAG_LENGTH_TX                   "_TXL"
+#define ACPI_RESTAG_SLAVEMODE                   "_SLV"
+#define ACPI_RESTAG_SPEED                       "_SPE"
+#define ACPI_RESTAG_STOPBITS                    "_STB"
+#define ACPI_RESTAG_TRANSLATION                 "_TRA"
+#define ACPI_RESTAG_TRANSTYPE                   "_TRS"  /* Sparse(1), Dense(0) */
+#define ACPI_RESTAG_TYPE                        "_TTP"  /* Translation(1), Static (0) */
+#define ACPI_RESTAG_XFERTYPE                    "_SIZ"  /* 8(0), 8And16(1), 16(2) */
+#define ACPI_RESTAG_VENDORDATA                  "_VEN"
+
+
+/* Default sizes for "small" resource descriptors */
+
+#define ASL_RDESC_IRQ_SIZE                      0x02
+#define ASL_RDESC_DMA_SIZE                      0x02
+#define ASL_RDESC_ST_DEPEND_SIZE                0x00
+#define ASL_RDESC_END_DEPEND_SIZE               0x00
+#define ASL_RDESC_IO_SIZE                       0x07
+#define ASL_RDESC_FIXED_IO_SIZE                 0x03
+#define ASL_RDESC_FIXED_DMA_SIZE                0x05
+#define ASL_RDESC_END_TAG_SIZE                  0x01
+
+
+typedef struct asl_resource_node
+{
+    UINT32                          BufferLength;
+    void                            *Buffer;
+    struct asl_resource_node        *Next;
+
+} ASL_RESOURCE_NODE;
+
+typedef struct asl_resource_info
+{
+    ACPI_PARSE_OBJECT               *DescriptorTypeOp;  /* Resource descriptor parse node */
+    ACPI_PARSE_OBJECT               *MappingOp;         /* Used for mapfile support */
+    UINT32                          CurrentByteOffset;  /* Offset in resource template */
+
+} ASL_RESOURCE_INFO;
+
+
+/* Macros used to generate AML resource length fields */
+
+#define ACPI_AML_SIZE_LARGE(r)      (sizeof (r) - sizeof (AML_RESOURCE_LARGE_HEADER))
+#define ACPI_AML_SIZE_SMALL(r)      (sizeof (r) - sizeof (AML_RESOURCE_SMALL_HEADER))
+
+/*
+ * Resource descriptors defined in the ACPI specification.
+ *
+ * Packing/alignment must be BYTE because these descriptors
+ * are used to overlay the raw AML byte stream.
+ */
+#pragma pack(1)
+
+/*
+ * SMALL descriptors
+ */
+#define AML_RESOURCE_SMALL_HEADER_COMMON \
+    UINT8                           DescriptorType;
+
+typedef struct aml_resource_small_header
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+
+} AML_RESOURCE_SMALL_HEADER;
+
+
+typedef struct aml_resource_irq
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+    UINT16                          IrqMask;
+    UINT8                           Flags;
+
+} AML_RESOURCE_IRQ;
+
+
+typedef struct aml_resource_irq_noflags
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+    UINT16                          IrqMask;
+
+} AML_RESOURCE_IRQ_NOFLAGS;
+
+
+typedef struct aml_resource_dma
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+    UINT8                           DmaChannelMask;
+    UINT8                           Flags;
+
+} AML_RESOURCE_DMA;
+
+
+typedef struct aml_resource_start_dependent
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+    UINT8                           Flags;
+
+} AML_RESOURCE_START_DEPENDENT;
+
+
+typedef struct aml_resource_start_dependent_noprio
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+
+} AML_RESOURCE_START_DEPENDENT_NOPRIO;
+
+
+typedef struct aml_resource_end_dependent
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+
+} AML_RESOURCE_END_DEPENDENT;
+
+
+typedef struct aml_resource_io
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+    UINT8                           Flags;
+    UINT16                          Minimum;
+    UINT16                          Maximum;
+    UINT8                           Alignment;
+    UINT8                           AddressLength;
+
+} AML_RESOURCE_IO;
+
+
+typedef struct aml_resource_fixed_io
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+    UINT16                          Address;
+    UINT8                           AddressLength;
+
+} AML_RESOURCE_FIXED_IO;
+
+
+typedef struct aml_resource_vendor_small
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+
+} AML_RESOURCE_VENDOR_SMALL;
+
+
+typedef struct aml_resource_end_tag
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+    UINT8                           Checksum;
+
+} AML_RESOURCE_END_TAG;
+
+
+typedef struct aml_resource_fixed_dma
+{
+    AML_RESOURCE_SMALL_HEADER_COMMON
+    UINT16                          RequestLines;
+    UINT16                          Channels;
+    UINT8                           Width;
+
+} AML_RESOURCE_FIXED_DMA;
+
+
+/*
+ * LARGE descriptors
+ */
+#define AML_RESOURCE_LARGE_HEADER_COMMON \
+    UINT8                           DescriptorType;\
+    UINT16                          ResourceLength;
+
+typedef struct aml_resource_large_header
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+
+} AML_RESOURCE_LARGE_HEADER;
+
+
+/* General Flags for address space resource descriptors */
+
+#define ACPI_RESOURCE_FLAG_DEC      2
+#define ACPI_RESOURCE_FLAG_MIF      4
+#define ACPI_RESOURCE_FLAG_MAF      8
+
+typedef struct aml_resource_memory24
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    UINT8                           Flags;
+    UINT16                          Minimum;
+    UINT16                          Maximum;
+    UINT16                          Alignment;
+    UINT16                          AddressLength;
+
+} AML_RESOURCE_MEMORY24;
+
+
+typedef struct aml_resource_vendor_large
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+
+} AML_RESOURCE_VENDOR_LARGE;
+
+
+typedef struct aml_resource_memory32
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    UINT8                           Flags;
+    UINT32                          Minimum;
+    UINT32                          Maximum;
+    UINT32                          Alignment;
+    UINT32                          AddressLength;
+
+} AML_RESOURCE_MEMORY32;
+
+
+typedef struct aml_resource_fixed_memory32
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    UINT8                           Flags;
+    UINT32                          Address;
+    UINT32                          AddressLength;
+
+} AML_RESOURCE_FIXED_MEMORY32;
+
+
+#define AML_RESOURCE_ADDRESS_COMMON \
+    UINT8                           ResourceType; \
+    UINT8                           Flags; \
+    UINT8                           SpecificFlags;
+
+
+typedef struct aml_resource_address
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    AML_RESOURCE_ADDRESS_COMMON
+
+} AML_RESOURCE_ADDRESS;
+
+
+typedef struct aml_resource_extended_address64
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    AML_RESOURCE_ADDRESS_COMMON
+    UINT8                           RevisionID;
+    UINT8                           Reserved;
+    UINT64                          Granularity;
+    UINT64                          Minimum;
+    UINT64                          Maximum;
+    UINT64                          TranslationOffset;
+    UINT64                          AddressLength;
+    UINT64                          TypeSpecific;
+
+} AML_RESOURCE_EXTENDED_ADDRESS64;
+
+#define AML_RESOURCE_EXTENDED_ADDRESS_REVISION          1       /* ACPI 3.0 */
+
+
+typedef struct aml_resource_address64
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    AML_RESOURCE_ADDRESS_COMMON
+    UINT64                          Granularity;
+    UINT64                          Minimum;
+    UINT64                          Maximum;
+    UINT64                          TranslationOffset;
+    UINT64                          AddressLength;
+
+} AML_RESOURCE_ADDRESS64;
+
+
+typedef struct aml_resource_address32
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    AML_RESOURCE_ADDRESS_COMMON
+    UINT32                          Granularity;
+    UINT32                          Minimum;
+    UINT32                          Maximum;
+    UINT32                          TranslationOffset;
+    UINT32                          AddressLength;
+
+} AML_RESOURCE_ADDRESS32;
+
+
+typedef struct aml_resource_address16
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    AML_RESOURCE_ADDRESS_COMMON
+    UINT16                          Granularity;
+    UINT16                          Minimum;
+    UINT16                          Maximum;
+    UINT16                          TranslationOffset;
+    UINT16                          AddressLength;
+
+} AML_RESOURCE_ADDRESS16;
+
+
+typedef struct aml_resource_extended_irq
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    UINT8                           Flags;
+    UINT8                           InterruptCount;
+    UINT32                          Interrupts[1];
+    /* ResSourceIndex, ResSource optional fields follow */
+
+} AML_RESOURCE_EXTENDED_IRQ;
+
+
+typedef struct aml_resource_generic_register
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    UINT8                           AddressSpaceId;
+    UINT8                           BitWidth;
+    UINT8                           BitOffset;
+    UINT8                           AccessSize; /* ACPI 3.0, was previously Reserved */
+    UINT64                          Address;
+
+} AML_RESOURCE_GENERIC_REGISTER;
+
+
+/* Common descriptor for GpioInt and GpioIo (ACPI 5.0) */
+
+typedef struct aml_resource_gpio
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    UINT8                           RevisionId;
+    UINT8                           ConnectionType;
+    UINT16                          Flags;
+    UINT16                          IntFlags;
+    UINT8                           PinConfig;
+    UINT16                          DriveStrength;
+    UINT16                          DebounceTimeout;
+    UINT16                          PinTableOffset;
+    UINT8                           ResSourceIndex;
+    UINT16                          ResSourceOffset;
+    UINT16                          VendorOffset;
+    UINT16                          VendorLength;
+    /*
+     * Optional fields follow immediately:
+     * 1) PIN list (Words)
+     * 2) Resource Source String
+     * 3) Vendor Data bytes
+     */
+
+} AML_RESOURCE_GPIO;
+
+#define AML_RESOURCE_GPIO_REVISION              1       /* ACPI 5.0 */
+
+/* Values for ConnectionType above */
+
+#define AML_RESOURCE_GPIO_TYPE_INT              0
+#define AML_RESOURCE_GPIO_TYPE_IO               1
+#define AML_RESOURCE_MAX_GPIOTYPE               1
+
+
+/* Common preamble for all serial descriptors (ACPI 5.0) */
+
+#define AML_RESOURCE_SERIAL_COMMON \
+    UINT8                           RevisionId; \
+    UINT8                           ResSourceIndex; \
+    UINT8                           Type; \
+    UINT8                           Flags; \
+    UINT16                          TypeSpecificFlags; \
+    UINT8                           TypeRevisionId; \
+    UINT16                          TypeDataLength; \
+
+/* Values for the type field above */
+
+#define AML_RESOURCE_I2C_SERIALBUSTYPE          1
+#define AML_RESOURCE_SPI_SERIALBUSTYPE          2
+#define AML_RESOURCE_UART_SERIALBUSTYPE         3
+#define AML_RESOURCE_MAX_SERIALBUSTYPE          3
+#define AML_RESOURCE_VENDOR_SERIALBUSTYPE       192 /* Vendor defined is 0xC0-0xFF (NOT SUPPORTED) */
+
+typedef struct aml_resource_common_serialbus
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    AML_RESOURCE_SERIAL_COMMON
+
+} AML_RESOURCE_COMMON_SERIALBUS;
+
+typedef struct aml_resource_i2c_serialbus
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    AML_RESOURCE_SERIAL_COMMON
+    UINT32                          ConnectionSpeed;
+    UINT16                          SlaveAddress;
+    /*
+     * Optional fields follow immediately:
+     * 1) Vendor Data bytes
+     * 2) Resource Source String
+     */
+
+} AML_RESOURCE_I2C_SERIALBUS;
+
+#define AML_RESOURCE_I2C_REVISION               1       /* ACPI 5.0 */
+#define AML_RESOURCE_I2C_TYPE_REVISION          1       /* ACPI 5.0 */
+#define AML_RESOURCE_I2C_MIN_DATA_LEN           6
+
+typedef struct aml_resource_spi_serialbus
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    AML_RESOURCE_SERIAL_COMMON
+    UINT32                          ConnectionSpeed;
+    UINT8                           DataBitLength;
+    UINT8                           ClockPhase;
+    UINT8                           ClockPolarity;
+    UINT16                          DeviceSelection;
+    /*
+     * Optional fields follow immediately:
+     * 1) Vendor Data bytes
+     * 2) Resource Source String
+     */
+
+} AML_RESOURCE_SPI_SERIALBUS;
+
+#define AML_RESOURCE_SPI_REVISION               1       /* ACPI 5.0 */
+#define AML_RESOURCE_SPI_TYPE_REVISION          1       /* ACPI 5.0 */
+#define AML_RESOURCE_SPI_MIN_DATA_LEN           9
+
+
+typedef struct aml_resource_uart_serialbus
+{
+    AML_RESOURCE_LARGE_HEADER_COMMON
+    AML_RESOURCE_SERIAL_COMMON
+    UINT32                          DefaultBaudRate;
+    UINT16                          RxFifoSize;
+    UINT16                          TxFifoSize;
+    UINT8                           Parity;
+    UINT8                           LinesEnabled;
+    /*
+     * Optional fields follow immediately:
+     * 1) Vendor Data bytes
+     * 2) Resource Source String
+     */
+
+} AML_RESOURCE_UART_SERIALBUS;
+
+#define AML_RESOURCE_UART_REVISION              1       /* ACPI 5.0 */
+#define AML_RESOURCE_UART_TYPE_REVISION         1       /* ACPI 5.0 */
+#define AML_RESOURCE_UART_MIN_DATA_LEN          10
+
+
+/* restore default alignment */
+
+#pragma pack()
+
+/* Union of all resource descriptors, so we can allocate the worst case */
+
+typedef union aml_resource
+{
+    /* Descriptor headers */
+
+    UINT8                                   DescriptorType;
+    AML_RESOURCE_SMALL_HEADER               SmallHeader;
+    AML_RESOURCE_LARGE_HEADER               LargeHeader;
+
+    /* Small resource descriptors */
+
+    AML_RESOURCE_IRQ                        Irq;
+    AML_RESOURCE_DMA                        Dma;
+    AML_RESOURCE_START_DEPENDENT            StartDpf;
+    AML_RESOURCE_END_DEPENDENT              EndDpf;
+    AML_RESOURCE_IO                         Io;
+    AML_RESOURCE_FIXED_IO                   FixedIo;
+    AML_RESOURCE_FIXED_DMA                  FixedDma;
+    AML_RESOURCE_VENDOR_SMALL               VendorSmall;
+    AML_RESOURCE_END_TAG                    EndTag;
+
+    /* Large resource descriptors */
+
+    AML_RESOURCE_MEMORY24                   Memory24;
+    AML_RESOURCE_GENERIC_REGISTER           GenericReg;
+    AML_RESOURCE_VENDOR_LARGE               VendorLarge;
+    AML_RESOURCE_MEMORY32                   Memory32;
+    AML_RESOURCE_FIXED_MEMORY32             FixedMemory32;
+    AML_RESOURCE_ADDRESS16                  Address16;
+    AML_RESOURCE_ADDRESS32                  Address32;
+    AML_RESOURCE_ADDRESS64                  Address64;
+    AML_RESOURCE_EXTENDED_ADDRESS64         ExtAddress64;
+    AML_RESOURCE_EXTENDED_IRQ               ExtendedIrq;
+    AML_RESOURCE_GPIO                       Gpio;
+    AML_RESOURCE_I2C_SERIALBUS              I2cSerialBus;
+    AML_RESOURCE_SPI_SERIALBUS              SpiSerialBus;
+    AML_RESOURCE_UART_SERIALBUS             UartSerialBus;
+    AML_RESOURCE_COMMON_SERIALBUS           CommonSerialBus;
+
+    /* Utility overlays */
+
+    AML_RESOURCE_ADDRESS                    Address;
+    UINT32                                  DwordItem;
+    UINT16                                  WordItem;
+    UINT8                                   ByteItem;
+
+} AML_RESOURCE;
+
+
+/* Interfaces used by both the disassembler and compiler */
+
+void
+MpSaveGpioInfo (
+    ACPI_PARSE_OBJECT       *Op,
+    AML_RESOURCE            *Resource,
+    UINT32                  PinCount,
+    UINT16                  *PinList,
+    char                    *DeviceName);
+
+void
+MpSaveSerialInfo (
+    ACPI_PARSE_OBJECT       *Op,
+    AML_RESOURCE            *Resource,
+    char                    *DeviceName);
+
+char *
+MpGetHidFromParseTree (
+    ACPI_NAMESPACE_NODE     *HidNode);
+
+char *
+MpGetHidViaNamestring (
+    char                    *DeviceName);
+
+char *
+MpGetConnectionInfo (
+    ACPI_PARSE_OBJECT       *Op,
+    UINT32                  PinIndex,
+    ACPI_NAMESPACE_NODE     **TargetNode,
+    char                    **TargetName);
+
+char *
+MpGetParentDeviceHid (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_NAMESPACE_NODE     **TargetNode,
+    char                    **ParentDeviceName);
+
+char *
+MpGetDdnValue (
+    char                    *DeviceName);
+
+char *
+MpGetHidValue (
+    ACPI_NAMESPACE_NODE     *DeviceNode);
+
+#endif

+ 347 - 0
kernel/include/acpica/platform/acenv.h

@@ -0,0 +1,347 @@
+/******************************************************************************
+ *
+ * Name: acenv.h - Host and compiler configuration
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACENV_H__
+#define __ACENV_H__
+
+/*
+ * Environment configuration. The purpose of this file is to interface ACPICA
+ * to the local environment. This includes compiler-specific, OS-specific,
+ * and machine-specific configuration.
+ */
+
+/* Types for ACPI_MUTEX_TYPE */
+
+#define ACPI_BINARY_SEMAPHORE       0
+#define ACPI_OSL_MUTEX              1
+
+/* Types for DEBUGGER_THREADING */
+
+#define DEBUGGER_SINGLE_THREADED    0
+#define DEBUGGER_MULTI_THREADED     1
+
+
+/******************************************************************************
+ *
+ * Configuration for ACPI tools and utilities
+ *
+ *****************************************************************************/
+
+/* iASL configuration */
+
+#ifdef ACPI_ASL_COMPILER
+#define ACPI_APPLICATION
+#define ACPI_DEBUG_OUTPUT
+#define ACPI_CONSTANT_EVAL_ONLY
+#define ACPI_LARGE_NAMESPACE_NODE
+#define ACPI_DATA_TABLE_DISASSEMBLY
+#define ACPI_SINGLE_THREADED
+#define ACPI_32BIT_PHYSICAL_ADDRESS
+
+#define ACPI_DISASSEMBLER 1
+#endif
+
+/* AcpiExec configuration. Multithreaded with full AML debugger */
+
+#ifdef ACPI_EXEC_APP
+#define ACPI_APPLICATION
+#define ACPI_FULL_DEBUG
+#define ACPI_MUTEX_DEBUG
+#define ACPI_DBG_TRACK_ALLOCATIONS
+#endif
+
+/*
+ * 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)
+#define ACPI_APPLICATION
+#define ACPI_SINGLE_THREADED
+#endif
+
+/* AcpiHelp configuration. Error messages disabled. */
+
+#ifdef ACPI_HELP_APP
+#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 provided by the host */
+
+#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
+#define ACPI_USE_LOCAL_CACHE
+#define ACPI_FULL_DEBUG
+#endif
+
+/* Common for all ACPICA applications */
+
+#ifdef ACPI_APPLICATION
+#define ACPI_USE_SYSTEM_CLIBRARY
+#define ACPI_USE_LOCAL_CACHE
+#endif
+
+/* Common debug/disassembler support */
+
+#ifdef ACPI_FULL_DEBUG
+#define ACPI_DEBUG_OUTPUT
+#define ACPI_DEBUGGER 1
+#define ACPI_DISASSEMBLER 1
+#endif
+
+/*! [Begin] no source code translation */
+
+/* Monolithium */
+#include "acmnlth.h"
+
+/*! [End] no source code translation !*/
+
+
+/******************************************************************************
+ *
+ * Setup defaults for the required symbols that were not defined in one of
+ * the host/compiler files above.
+ *
+ *****************************************************************************/
+
+/* 64-bit data types */
+
+#ifndef COMPILER_DEPENDENT_INT64
+#define COMPILER_DEPENDENT_INT64   long long
+#endif
+
+#ifndef COMPILER_DEPENDENT_UINT64
+#define COMPILER_DEPENDENT_UINT64  unsigned long long
+#endif
+
+/* Type of mutex supported by host. Default is binary semaphores. */
+
+#ifndef ACPI_MUTEX_TYPE
+#define ACPI_MUTEX_TYPE             ACPI_BINARY_SEMAPHORE
+#endif
+
+/* Global Lock acquire/release */
+
+#ifndef ACPI_ACQUIRE_GLOBAL_LOCK
+#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acquired) Acquired = 1
+#endif
+
+#ifndef ACPI_RELEASE_GLOBAL_LOCK
+#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Pending) Pending = 0
+#endif
+
+/* Flush CPU cache - used when going to sleep. Wbinvd or similar. */
+
+#ifndef ACPI_FLUSH_CPU_CACHE
+#define ACPI_FLUSH_CPU_CACHE()
+#endif
+
+/* "inline" keywords - configurable since inline is not standardized */
+
+#ifndef ACPI_INLINE
+#define ACPI_INLINE
+#endif
+
+/*
+ * Configurable 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
+ */
+#ifndef ACPI_SYSTEM_XFACE
+#define ACPI_SYSTEM_XFACE
+#endif
+
+#ifndef ACPI_EXTERNAL_XFACE
+#define ACPI_EXTERNAL_XFACE
+#endif
+
+#ifndef ACPI_INTERNAL_XFACE
+#define ACPI_INTERNAL_XFACE
+#endif
+
+#ifndef ACPI_INTERNAL_VAR_XFACE
+#define ACPI_INTERNAL_VAR_XFACE
+#endif
+
+
+/*
+ * Debugger threading model
+ * Use single threaded if the entire subsystem is contained in an application
+ * Use multiple threaded when the subsystem is running in the kernel.
+ *
+ * By default the model is single threaded if ACPI_APPLICATION is set,
+ * multi-threaded if ACPI_APPLICATION is not set.
+ */
+#ifndef DEBUGGER_THREADING
+#if !defined (ACPI_APPLICATION) || defined (ACPI_EXEC_APP)
+#define DEBUGGER_THREADING          DEBUGGER_MULTI_THREADED
+
+#else
+#define DEBUGGER_THREADING          DEBUGGER_SINGLE_THREADED
+#endif
+#endif /* !DEBUGGER_THREADING */
+
+
+/******************************************************************************
+ *
+ * C library configuration
+ *
+ *****************************************************************************/
+
+/*
+ * ACPI_USE_SYSTEM_CLIBRARY - Define this if linking to an actual C library.
+ *      Otherwise, local versions of string/memory functions will be used.
+ * ACPI_USE_STANDARD_HEADERS - Define this if linking to a C library and
+ *      the standard header files may be used.
+ *
+ * The ACPICA subsystem only uses low level C library functions that do not
+ * call operating system services and may therefore be inlined in the code.
+ *
+ * It may be necessary to tailor these include files to the target
+ * generation environment.
+ */
+#ifdef ACPI_USE_SYSTEM_CLIBRARY
+
+/* Use the standard C library headers. We want to keep these to a minimum. */
+
+#ifdef ACPI_USE_STANDARD_HEADERS
+
+/* Use the standard headers from the standard locations */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#endif /* ACPI_USE_STANDARD_HEADERS */
+
+/* We will be linking to the standard Clib functions */
+
+#else
+
+/******************************************************************************
+ *
+ * Not using native C library, use local implementations
+ *
+ *****************************************************************************/
+
+/*
+ * Use local definitions of C library macros and functions. These function
+ * implementations may not be as efficient as an inline or assembly code
+ * implementation provided by a native C library, but they are functionally
+ * equivalent.
+ */
+#ifndef va_arg
+
+#ifndef _VALIST
+#define _VALIST
+typedef char *va_list;
+#endif /* _VALIST */
+
+/* Storage alignment properties */
+
+#define  _AUPBND                (sizeof (ACPI_NATIVE_INT) - 1)
+#define  _ADNBND                (sizeof (ACPI_NATIVE_INT) - 1)
+
+/* Variable argument list macro definitions */
+
+#define _Bnd(X, bnd)            (((sizeof (X)) + (bnd)) & (~(bnd)))
+#define va_arg(ap, T)           (*(T *)(((ap) += (_Bnd (T, _AUPBND))) - (_Bnd (T,_ADNBND))))
+#define va_end(ap)              (ap = (va_list) NULL)
+#define va_start(ap, A)         (void) ((ap) = (((char *) &(A)) + (_Bnd (A,_AUPBND))))
+
+#endif /* va_arg */
+
+/* Use the local (ACPICA) definitions of the clib functions */
+
+#endif /* ACPI_USE_SYSTEM_CLIBRARY */
+
+#ifndef ACPI_FILE
+#ifdef ACPI_APPLICATION
+#include <stdio.h>
+#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 */
+
+#endif /* __ACENV_H__ */

+ 58 - 0
kernel/include/acpica/platform/acenvex.h

@@ -0,0 +1,58 @@
+/******************************************************************************
+ *
+ * Name: acenvex.h - Extra host and compiler configuration
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACENVEX_H__
+#define __ACENVEX_H__
+
+/*! [Begin] no source code translation */
+
+/******************************************************************************
+ *
+ * Extra host configuration files. All ACPICA headers are included before
+ * including these files.
+ *
+ *****************************************************************************/
+
+/*! [End] no source code translation !*/
+
+#endif /* __ACENVEX_H__ */

+ 82 - 0
kernel/include/acpica/platform/acgcc.h

@@ -0,0 +1,82 @@
+/******************************************************************************
+ *
+ * Name: acgcc.h - GCC specific defines, etc.
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 __ACGCC_H__
+#define __ACGCC_H__
+
+#define ACPI_INLINE             __inline__
+
+/* Function name is used for debug output. Non-ANSI, compiler-dependent */
+
+#define ACPI_GET_FUNCTION_NAME          __func__
+
+/*
+ * This macro is used to tag functions as "printf-like" because
+ * some compilers (like GCC) can catch printf format string problems.
+ */
+#define ACPI_PRINTF_LIKE(c) __attribute__ ((__format__ (__printf__, c, c+1)))
+
+/*
+ * Some compilers complain about unused variables. Sometimes we don't want to
+ * use all the variables (for example, _AcpiModuleName). This allows us
+ * to tell the compiler warning in a per-variable manner that a variable
+ * is unused.
+ */
+#define ACPI_UNUSED_VAR __attribute__ ((unused))
+
+/*
+ * Some versions of gcc implement strchr() with a buggy macro. So,
+ * undef it here. Prevents error messages of this form (usually from the
+ * file getopt.c):
+ *
+ * error: logical '&&' with non-zero constant will always evaluate as true
+ */
+#ifdef strchr
+#undef strchr
+#endif
+
+/* GCC supports __VA_ARGS__ in macros */
+
+#define COMPILER_VA_MACRO               1
+
+#endif /* __ACGCC_H__ */

+ 17 - 0
kernel/include/acpica/platform/acmnlth.h

@@ -0,0 +1,17 @@
+#ifndef __ACMNLTH__
+#define __ACMNLTH__
+
+#define ACPI_UNUSED_VAR __attribute__((unused))
+
+#define ACPI_MACHINE_WIDTH          32
+#define COMPILER_DEPENDENT_INT64    long long
+#define COMPILER_DEPENDENT_UINT64   unsigned long long
+#define ACPI_USE_NATIVE_DIVIDE
+
+#define ACPI_CACHE T ACPI_MEMORY_LIST
+#define ACPI_USE_LOCAL_CACHE
+
+#define ACPI_USE_SYSTEM_CLIBRARY
+#include <common.h>
+
+#endif

+ 40 - 0
kernel/include/avl_tree.h

@@ -0,0 +1,40 @@
+/*
+ * avl_tree.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _AVL_TREE_H_
+#define _AVL_TREE_H_
+
+#include <common.h>
+
+typedef struct _avl_tree_t
+{
+    struct _avl_tree_t *parent, *left, *right, *next_equal;
+    qword_t key;
+} avl_tree_t;
+
+void avl_tree_insert(avl_tree_t **tree, avl_tree_t *node);
+avl_tree_t *avl_tree_lookup(avl_tree_t *tree, qword_t key);
+bool_t avl_tree_remove(avl_tree_t **tree, avl_tree_t *node);
+avl_tree_t *avl_tree_lower_bound(avl_tree_t *tree, qword_t key);
+avl_tree_t *avl_tree_upper_bound(avl_tree_t *tree, qword_t key);
+bool_t avl_tree_change_key(avl_tree_t **tree, avl_tree_t *node, qword_t new_key);
+avl_tree_t *avl_get_next_node(avl_tree_t *node);
+avl_tree_t *avl_get_previous_node(avl_tree_t *node);
+
+#endif

+ 94 - 0
kernel/include/block_device.h

@@ -0,0 +1,94 @@
+/*
+ * block_device.h
+ * 
+ * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _BLOCK_DEVICE_H_
+#define _BLOCK_DEVICE_H_
+
+#include <common.h>
+#include <sync.h>
+#include <list.h>
+#include <cache.h>
+
+#define MAX_BLOCK_DEV_NAME 32
+
+#define BLOCK_DEVICE_REMOVABLE_MEDIA  (1 << 0)
+
+#define IOCTL_BLOCK_DEV_INFO        0xB0000000
+#define IOCTL_BLOCK_DEV_MEDIA_INFO  0xB0000001
+#define IOCTL_BLOCK_DEV_MEDIA_LOAD  0xB0000002
+#define IOCTL_BLOCK_DEV_MEDIA_EJECT 0xB0000003
+
+#ifndef BLOCK_DEVICE_TYPEDEF
+#define BLOCK_DEVICE_TYPEDEF
+typedef struct block_device block_device_t;
+#endif
+
+typedef dword_t (*block_dev_init_proc_t)(void);
+typedef dword_t (*block_dev_cleanup_proc_t)(void);
+typedef dword_t (*block_dev_read_proc_t)(block_device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
+typedef dword_t (*block_dev_write_proc_t)(block_device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
+typedef dword_t (*block_dev_ioctl_proc_t)(
+    block_device_t *device,
+    dword_t control_code,
+    const void *in_buffer,
+    size_t in_length,
+    void *out_buffer,
+    size_t out_length
+);
+
+typedef struct
+{
+    list_entry_t list;
+    dword_t mounted_devices;
+    block_dev_init_proc_t init_proc;
+    block_dev_cleanup_proc_t cleanup_proc;
+    block_dev_read_proc_t read_proc;
+    block_dev_write_proc_t write_proc;
+    block_dev_ioctl_proc_t ioctl_proc;
+} block_dev_driver_t;
+
+struct block_device
+{
+    list_entry_t list;
+    dword_t flags;
+    block_dev_driver_t *driver;
+    char name[MAX_BLOCK_DEV_NAME];
+    qword_t capacity;
+    resource_t resource;
+};
+
+typedef struct
+{
+    dword_t heads;
+    dword_t tracks;
+    dword_t sectors_per_track;
+    dword_t bytes_per_sector;
+} block_dev_media_info_t;
+
+dword_t register_block_dev_driver(block_dev_driver_t *driver);
+dword_t unregister_block_dev_driver(block_dev_driver_t *driver);
+block_device_t *get_block_device(const char *name);
+dword_t register_block_device(block_device_t *device);
+dword_t unregister_block_device(block_device_t *device);
+dword_t enum_block_devices(char *device_names, size_t *size);
+dword_t block_device_read(const char *name, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
+dword_t block_device_write(const char *name, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
+dword_t block_device_ioctl(const char *name, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
+
+#endif

+ 63 - 0
kernel/include/boot/multiboot.h

@@ -0,0 +1,63 @@
+/*
+ * multiboot.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MULTIBOOT_H_
+#define _MULTIBOOT_H_
+
+#include "../common.h"
+
+typedef struct
+{
+    dword_t flags;
+    dword_t mem_lower, mem_upper;
+    dword_t boot_device;
+    dword_t cmdline;
+    dword_t mods_count, mods_addr;
+    dword_t syms[4];
+    dword_t mmap_length, mmap_addr;
+    dword_t drives_length, drives_addr;
+    dword_t config_table;
+    dword_t boot_loader_name;
+    dword_t apm_table;
+    dword_t vbe_control_info, vbe_mode_info, vbe_mode, vbe_interface_seg, vbe_interface_off, vbe_interface_len;
+} multiboot_header_t;
+
+typedef struct
+{
+    dword_t size;
+    union
+    {
+        struct
+        {
+            dword_t base_low, base_high;
+        };
+        qword_t base;
+    };
+    union
+    {
+        struct
+        {
+            dword_t length_low, length_high;
+        };
+        qword_t length;
+    };
+    dword_t type;
+} multiboot_mmap_t;
+
+#endif

+ 59 - 0
kernel/include/cache.h

@@ -0,0 +1,59 @@
+/*
+ * cache.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _CACHE_H_
+#define _CACHE_H_
+
+#include <common.h>
+#include <sync.h>
+#include <avl_tree.h>
+#include <block_device.h>
+
+#define CACHE_WRITE_THROUGH (1 << 0)
+
+typedef dword_t (*read_write_buffer_proc_t)(void *context, void *buffer, qword_t offset, size_t length, size_t *bytes_read_or_written);
+
+typedef struct
+{
+    avl_tree_t tree;
+    bool_t dirty;
+    byte_t data[VARIABLE_SIZE];
+} cache_entry_t;
+
+#ifndef BLOCK_DEVICE_TYPEDEF
+#define BLOCK_DEVICE_TYPEDEF
+typedef struct block_device block_device_t;
+#endif
+
+typedef struct
+{
+    bool_t enabled;
+    resource_t resource;
+    dword_t flags;
+    dword_t block_size;
+    read_write_buffer_proc_t read_proc, write_proc;
+    avl_tree_t *root;
+} cache_descriptor_t;
+
+dword_t cleanup_cache(cache_descriptor_t *cache);
+dword_t read_cache(cache_descriptor_t *cache, void *context, byte_t *buffer, qword_t offset, dword_t length, dword_t *bytes_read);
+dword_t write_cache(cache_descriptor_t *cache, void *context, const byte_t *buffer, qword_t offset, dword_t length, dword_t *bytes_written);
+dword_t flush_cache(cache_descriptor_t *cache, void *context);
+
+#endif

+ 75 - 0
kernel/include/char_device.h

@@ -0,0 +1,75 @@
+/*
+ * char_device.h
+ * 
+ * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _CHAR_DEVICE_H_
+#define _CHAR_DEVICE_H_
+
+#include <common.h>
+#include <list.h>
+#include <sync.h>
+
+#define MAX_CHAR_DEV_NAME 32
+
+#define IOCTL_CHAR_DEV_CHECK_INPUT  0xC0000000
+#define IOCTL_CHAR_DEV_CHECK_OUTPUT 0xC0000001
+
+typedef struct _char_device_t char_device_t;
+
+typedef dword_t (*char_dev_init_proc_t)(void);
+typedef dword_t (*char_dev_cleanup_proc_t)(void);
+typedef dword_t (*char_dev_read_proc_t)(char_device_t *device, void *buffer, size_t length, size_t *bytes_read);
+typedef dword_t (*char_dev_write_proc_t)(char_device_t *device, const void *buffer, size_t length, size_t *bytes_written);
+typedef dword_t (*char_dev_ioctl_proc_t)(
+    char_device_t *device,
+    dword_t control_code,
+    const void *in_buffer,
+    size_t in_length,
+    void *out_buffer,
+    size_t out_length
+);
+
+typedef struct
+{
+    list_entry_t list;
+    char_dev_init_proc_t init_proc;
+    char_dev_cleanup_proc_t cleanup_proc;
+    char_dev_read_proc_t read_proc;
+    char_dev_write_proc_t write_proc;
+    char_dev_ioctl_proc_t ioctl_proc;
+} char_dev_driver_t;
+
+struct _char_device_t
+{
+    list_entry_t list;
+    char_dev_driver_t *driver;
+    char name[MAX_CHAR_DEV_NAME];
+    resource_t resource;
+};
+
+dword_t register_char_dev_driver(char_dev_driver_t *driver);
+dword_t unregister_char_dev_driver(char_dev_driver_t *driver);
+char_device_t *get_char_device(const char *name);
+dword_t register_char_device(char_device_t *device);
+dword_t unregister_char_device(char_device_t *device);
+dword_t enum_char_devices(char *device_names, size_t *size);
+dword_t char_device_read(const char *name, void *buffer, size_t length, size_t *bytes_read);
+dword_t char_device_write(const char *name, const void *buffer, size_t length, size_t *bytes_written);
+dword_t char_device_ioctl(const char *name, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length);
+
+#endif

+ 58 - 0
kernel/include/clock.h

@@ -0,0 +1,58 @@
+/*
+ * clock.h
+ * 
+ * Copyright 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _CLOCK_H_
+#define _CLOCK_H_
+
+#include <common.h>
+
+#define CLOCK_IRQ 8
+#define CLOCK_PM_BIT (1 << 7)
+
+#define CLOCK_DAYLIGHT_SAVINGS (1 << 0)
+#define CLOCK_24HOUR_MODE (1 << 1)
+#define CLOCK_BINARY_MODE (1 << 2)
+#define CLOCK_SQUARE_WAVE (1 << 3)
+#define CLOCK_UPDATE_INT (1 << 4)
+#define CLOCK_ALARM_INT (1 << 5)
+#define CLOCK_PERIODIC_INT (1 << 6)
+#define CLOCK_DISABLE (1 << 7)
+
+#define CMOS_RTC_SECONDS_REG 0x00
+#define CMOS_RTC_MINUTES_REG 0x02
+#define CMOS_RTC_HOURS_REG 0x04
+#define CMOS_RTC_DAY_REG 0x07
+#define CMOS_RTC_MONTH_REG 0x08
+#define CMOS_RTC_YEAR_REG 0x09
+#define CMOS_RTC_STA_REG 0x0A
+#define CMOS_RTC_STB_REG 0x0B
+#define CMOS_RTC_STC_REG 0x0C
+
+typedef struct
+{
+    word_t year;
+    byte_t day, month, hours, minutes, seconds;
+} clock_time_t;
+
+void clock_init();
+dword_t clock_get_time(clock_time_t *time);
+bool_t clock_check_time(clock_time_t *time);
+dword_t clock_set_time(clock_time_t *time);
+
+#endif

+ 248 - 0
kernel/include/common.h

@@ -0,0 +1,248 @@
+/*
+ * common.h
+ * 
+ * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+#define NULL (void*)0
+#define FALSE 0
+#define TRUE 1
+
+#define VARIABLE_SIZE 0
+
+#define CHAR_MIN  -128
+#define CHAR_MAX  127
+#define BYTE_MIN  0
+#define BYTE_MAX  0xFF
+#define SHORT_MIN -32768
+#define SHORT_MAX 32767
+#define WORD_MIN  0
+#define WORD_MAX  0xFFFF
+#define INT_MIN   -2147483648
+#define INT_MAX   2147483647
+#define DWORD_MIN 0
+#define DWORD_MAX 0xFFFFFFFF
+#define QWORD_MIN 0ULL
+#define QWORD_MAX 0xFFFFFFFFFFFFFFFFULL
+
+#define ERR_SUCCESS   0x00000000
+#define ERR_NOTFOUND  0xE0000001
+#define ERR_FORBIDDEN 0xE0000002
+#define ERR_INVALID   0xE0000003
+#define ERR_EXISTS    0xE0000004
+#define ERR_NOMEMORY  0xE0000005
+#define ERR_HARDWARE  0xE0000006
+#define ERR_BUSY      0xE0000007
+#define ERR_NOMEDIA   0xE0000008
+#define ERR_NOTRESP   0xE0000009
+#define ERR_WRITEPROT 0xE000000A
+#define ERR_NOSYSCALL 0xE000000B
+#define ERR_TIMEOUT   0xE000000C
+#define ERR_BADPTR    0xE000000D
+#define ERR_CANCELED  0xE000000E
+#define ERR_ISDIR     0xE000000F
+#define ERR_ISNOTDIR  0xE0000010
+#define ERR_DISKFULL  0xE0000011
+#define ERR_MEDIACHG  0xE0000012
+#define ERR_BEYOND    0xE0000013
+#define ERR_SMALLBUF  0xE0000014
+#define ERR_NOMORE    0xE0000015
+#define MAX_ERR       0xE0000016
+
+#define CMOS_CMD_PORT 0x70
+#define CMOS_DATA_PORT 0x71
+
+#define va_start(v,l) __builtin_va_start(v,l)
+#define va_arg(v,l) __builtin_va_arg(v,l)
+#define va_end(v) __builtin_va_end(v)
+#define va_copy(d,s) __builtin_va_copy(d,s)
+
+#define UNUSED_PARAMETER(x) (x)=(x)
+#define SEGMENT_RPL(x) ((x) & 0x03)
+#define OFFSET_OF(type, field) ((dword_t)(&((type*)NULL)->field))
+#define CONTAINER_OF(ptr, type, field) ((type*)((dword_t)(ptr) - OFFSET_OF(type, field)))
+
+#define MAX_PATH 16384
+
+#define VIDEO_MEMORY 0xF0000000
+#define TEXT_VIDEO_MEMORY 0xB8000
+#define TEXT_COLOR_BLUE  0x01
+#define TEXT_COLOR_GREEN 0x02
+#define TEXT_COLOR_RED   0x04
+#define TEXT_COLOR_STRONG 0x08
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+typedef unsigned char bool_t;
+typedef __builtin_va_list va_list;
+typedef unsigned char byte_t;
+typedef unsigned short word_t;
+typedef unsigned int dword_t;
+typedef unsigned long long qword_t;
+typedef bool_t critical_t;
+typedef char int8_t;
+typedef short int16_t;
+typedef long int32_t;
+typedef long long int64_t;
+
+typedef int32_t intptr_t;
+typedef dword_t uintptr_t;
+
+typedef uintptr_t size_t;
+
+static inline byte_t inportb(word_t port)
+{
+    byte_t byte;
+    asm volatile ("inb %1, %0" : "=a"(byte) : "Nd"(port));
+    return byte;
+}
+
+static inline void outportb(word_t port, byte_t byte)
+{
+    asm volatile ("outb %0, %1" :: "a"(byte), "Nd"(port));
+}
+
+static inline word_t inportw(unsigned short port)
+{
+    word_t word;
+    asm volatile ("inw %1, %0" : "=a"(word) : "Nd"(port));
+    return word;
+}
+
+static inline void outportw(word_t port, unsigned short word)
+{
+    asm volatile ("outw %0, %1" :: "a"(word), "Nd"(port));
+}
+
+static inline dword_t inportl(word_t port)
+{
+    dword_t dword;
+    asm volatile ("inl %1, %0" : "=a"(dword) : "Nd"(port));
+    return dword;
+}
+
+static inline void outportl(word_t port, dword_t dword)
+{
+    asm volatile ("outl %0, %1" :: "a"(dword), "Nd"(port));
+}
+
+static inline void enable_ints()
+{
+    asm volatile ("sti");
+}
+
+static inline void disable_ints()
+{
+    asm volatile ("cli");
+}
+
+static inline bool_t check_ints()
+{
+    dword_t eflags;
+    asm volatile ("pushfl\npopl %0" : "=g"(eflags));
+    return (eflags & 0x200) != 0 ? TRUE : FALSE;
+}
+
+static inline void halt()
+{
+    asm volatile ("hlt");
+}
+
+static inline void enable_nmi()
+{
+    outportb(0x70, inportb(0x70) & 0x7F);
+}
+
+static inline void disable_nmi()
+{
+    outportb(0x70, inportb(0x70) | 0x80);
+}
+
+static inline void set_bit(dword_t *bitfield, dword_t bit)
+{
+    bitfield[bit >> 5] |= 1 << (bit & 0x1F);
+}
+
+static inline void clear_bit(dword_t *bitfield, dword_t bit)
+{
+    bitfield[bit >> 5] &= ~(1 << (bit & 0x1F));
+}
+
+static inline bool_t test_bit(dword_t *bitfield, dword_t bit)
+{
+    return (bitfield[bit >> 5] & (1 << (bit & 0x1F))) ? TRUE : FALSE;
+}
+
+static inline void push_to_stack(uintptr_t *stack, uintptr_t value)
+{
+    *stack -= sizeof(uintptr_t);
+    *((uintptr_t*)(*stack)) = value;
+}
+
+static inline uintptr_t pop_from_stack(uintptr_t *stack)
+{
+    uintptr_t value = *((uintptr_t*)(*stack));
+    *stack += sizeof(uintptr_t);
+    return value;
+}
+
+void enter_critical(critical_t *critical);
+void leave_critical(critical_t *critical);
+int strlen(const char *str);
+void strrev(char *str);
+char *strcpy(char *destination, const char *source);
+char *strcat(char *destination, const char *source);
+char *strncpy(char *destination, const char *source, dword_t num);
+int strcmp(const char *str1, const char *str2);
+char *strchr(const char *str, char c);
+char *strrchr(const char *str, char c);
+int strncmp(const char *str1, const char *str2, int length);
+char *strtok(char *str, const char *delimiters, char **endptr);
+dword_t strtoul(const char *str, char **endptr, int base);
+qword_t strtoull(const char *str, char **endptr, int base);
+char *strdup(const char *source);
+int isprint(int c);
+int isdigit(int c);
+int isxdigit(int c);
+int isspace(int c);
+char tolower(char c);
+char toupper(char c);
+void memset(void *ptr, byte_t value, dword_t size);
+int memcmp(const void *mem1, const void *mem2, dword_t size);
+void memcpy(void *destination, const void *source, dword_t size);
+void memmove(void *destination, const void *source, dword_t size);
+char *itoa(int value, char *str, int base);
+void putchar(char character);
+void puts(const char *string);
+void clearscreen();
+void set_text_color(byte_t color);
+int vsnprintf(char *output, dword_t count, const char *format, va_list args);
+int vsprintf(char *output, const char *format, va_list args);
+int snprintf(char *output, dword_t count, const char *format, ...);
+int vprintf(const char *format, va_list args);
+int printf(const char *format, ...);
+int sprintf(char *output, const char *format, ...);
+const char *get_error_string(dword_t err_code);
+int max(int a, int b);
+int min(int a, int b);
+void qsort(void *base, dword_t nmemb, dword_t size, int (*compare)(const void*, const void*));
+void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compare)(const void*, const void*));
+
+#endif

+ 65 - 0
kernel/include/cpu.h

@@ -0,0 +1,65 @@
+/*
+ * cpu.h
+ * 
+ * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _CPU_H_
+#define _CPU_H_
+
+#include <common.h>
+
+#define CPU_FEATURE_FPU   (1 << 0)
+#define CPU_FEATURE_VME   (1 << 1)
+#define CPU_FEATURE_DE    (1 << 2)
+#define CPU_FEATURE_PSE   (1 << 3)
+#define CPU_FEATURE_TSC   (1 << 4)
+#define CPU_FEATURE_MSR   (1 << 5)
+#define CPU_FEATURE_PAE   (1 << 6)
+#define CPU_FEATURE_MCE   (1 << 7)
+#define CPU_FEATURE_CX8   (1 << 8)
+#define CPU_FEATURE_APIC  (1 << 9)
+#define CPU_FEATURE_SEP   (1 << 11)
+#define CPU_FEATURE_MTRR  (1 << 12)
+#define CPU_FEATURE_PGE   (1 << 13)
+#define CPU_FEATURE_MCA   (1 << 14)
+#define CPU_FEATURE_CMOV  (1 << 15)
+#define CPU_FEATURE_PAT   (1 << 16)
+#define CPU_FEATURE_PSE36 (1 << 17)
+#define CPU_FEATURE_PSN   (1 << 18)
+#define CPU_FEATURE_CLFL  (1 << 19)
+#define CPU_FEATURE_DTES  (1 << 21)
+#define CPU_FEATURE_ACPI  (1 << 22)
+#define CPU_FEATURE_MMX   (1 << 23)
+#define CPU_FEATURE_FXSR  (1 << 24)
+#define CPU_FEATURE_SSE   (1 << 25)
+#define CPU_FEATURE_SSE2  (1 << 26)
+#define CPU_FEATURE_SS    (1 << 27)
+#define CPU_FEATURE_HTT   (1 << 28)
+#define CPU_FEATURE_TM1   (1 << 29)
+#define CPU_FEATURE_IA64  (1 << 30)
+#define CPU_FEATURE_PBE   (1 << 31)
+
+extern void cpu_init(void);
+extern void cpu_measure_speed(void);
+extern void fpu_save(byte_t *data);
+extern void fpu_restore(byte_t *data);
+extern void stall(dword_t microseconds);
+
+extern char cpu_vendor[13];
+extern dword_t cpu_features[2];
+
+#endif

+ 77 - 0
kernel/include/exception.h

@@ -0,0 +1,77 @@
+/*
+ * exception.h
+ * 
+ * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _EXCEPTION_H_
+#define _EXCEPTION_H_
+
+#include <common.h>
+#include <interrupt.h>
+
+typedef registers_t exception_handler_t;
+
+typedef struct
+{
+    dword_t number;
+    dword_t parameters[15];
+} exception_info_t;
+
+#include <thread.h>
+
+#define KERNEL_CRASH(message) kernel_crash((message), NULL, __FILE__, __LINE__)
+#define KERNEL_CRASH_WITH_REGS(message, regs) kernel_crash((message), (regs), __FILE__, __LINE__)
+#define ASSERT(test) (test) ? 0 : KERNEL_CRASH("Assertion \"" #test "\" failed");
+
+#define EH_TRY if (get_current_thread() != NULL) { exception_handler_t ___handler; if (save_kernel_handler(&___handler) == 0)
+#define EH_CATCH else
+#define EH_DONE syscall(SYSCALL_RESTORE_EXCEPTION_HANDLER, &___handler); }
+#define EH_ESCAPE(x) do { syscall(SYSCALL_RESTORE_EXCEPTION_HANDLER, &___handler); x; } while (FALSE)
+
+enum
+{
+    EXCEPTION_DIVISION_BY_ZERO,
+    EXCEPTION_DEBUG_INT,
+    EXCEPTION_NMI,
+    EXCEPTION_BREAKPOINT,
+    EXCEPTION_OVERFLOW,
+    EXCEPTION_BOUND_RANGE,
+    EXCEPTION_INVALID_OPCODE,
+    EXCEPTION_NO_FPU,
+    EXCEPTION_DOUBLE_FAULT,
+    EXCEPTION_FPU_SEGMENT,
+    EXCEPTION_BAD_TSS,
+    EXCEPTION_NO_SEGMENT,
+    EXCEPTION_STACK_OVERFLOW,
+    EXCEPTION_GPF,
+    EXCEPTION_PAGE_FAULT,
+    EXCEPTION_ALIGNMENT,
+    EXCEPTION_HARDWARE,
+    NUM_EXCEPTIONS
+};
+
+extern void __attribute__((noreturn)) exception_return(registers_t regs);
+extern int __attribute__((returns_twice)) save_kernel_handler(exception_handler_t *old_handler);
+
+dword_t get_exception_info(exception_info_t *info);
+dword_t raise_exception(exception_info_t *info);
+void __attribute__((noreturn)) kernel_crash(const char *message, registers_t *regs, const char *filename, int line);
+int save_exception_handler(exception_handler_t *old_handler);
+dword_t restore_exception_handler(exception_handler_t *old_handler);
+void exceptions_init();
+
+#endif

+ 60 - 0
kernel/include/exec/aout.h

@@ -0,0 +1,60 @@
+/*
+ * aout.h
+ * 
+ * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _AOUT_H_
+#define _AOUT_H_
+
+#include <common.h>
+#include <thread.h>
+#include <filesystem.h>
+#include <process.h>
+
+#define OMAGIC 0x0107
+#define NMAGIC 0x0108
+#define ZMAGIC 0x010B
+#define QMAGIC 0x00CC
+
+typedef struct
+{
+    dword_t midmag;
+    dword_t text_size;
+    dword_t data_size;
+    dword_t bss_size;
+    dword_t sym_size;
+    dword_t entry_point;
+    dword_t text_reloc_size;
+    dword_t data_reloc_size;
+} aout_header_t;
+
+typedef struct
+{
+    dword_t address;
+    dword_t symbol_num  : 24;
+    dword_t pc_relative : 1;
+    dword_t length      : 2;
+    dword_t external    : 1;
+    dword_t base_rel    : 1;
+    dword_t jump_table  : 1;
+    dword_t relative    : 1;
+    dword_t copy        : 1;
+} aout_reloc;
+
+dword_t load_aout(handle_t file, process_params_t *parameters, thread_state_t *initial_state);
+
+#endif

+ 144 - 0
kernel/include/filesystem.h

@@ -0,0 +1,144 @@
+/*
+ * filesystem.h
+ * 
+ * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _FILESYSTEM_H_
+#define _FILESYSTEM_H_
+
+#include <common.h>
+#include <object.h>
+#include <list.h>
+#include <block_device.h>
+#include <clock.h>
+
+#define PATH_DELIMITER_CHAR   '/'
+#define PATH_DELIMITER_STRING "/"
+
+#define FILE_MODE_READ            (1 << 0)
+#define FILE_MODE_WRITE           (1 << 1)
+#define FILE_MODE_SHARE_READ      (1 << 2)
+#define FILE_MODE_SHARE_WRITE     (1 << 3)
+#define FILE_MODE_NO_CACHE        (1 << 4)
+#define FILE_MODE_DELETE_ON_CLOSE (1 << 29)
+#define FILE_MODE_CREATE          (1 << 30)
+#define FILE_MODE_TRUNCATE        (1 << 31)
+
+#define FILE_ATTR_DIRECTORY      (1 << 0)
+#define FILE_ATTR_OWNER_READABLE (1 << 1)
+#define FILE_ATTR_OWNER_WRITABLE (1 << 2)
+#define FILE_ATTR_WORLD_READABLE (1 << 3)
+#define FILE_ATTR_WORLD_WRITABLE (1 << 4)
+#define FILE_ATTR_DELETED        (1 << 31)
+
+#define MOUNT_FLAG_READONLY (1 << 0)
+
+typedef struct mounted_volume mounted_volume_t;
+typedef struct file file_t;
+typedef struct file_instance file_instance_t;
+
+typedef dword_t (*fs_mount_proc_t)(const char *device, dword_t flags);
+typedef dword_t (*fs_unmount_proc_t)(mounted_volume_t *volume);
+typedef dword_t (*fs_load_proc_t)(file_t **file);
+typedef dword_t (*fs_unload_proc_t)(file_t *file);
+typedef dword_t (*fs_open_proc_t)(file_instance_t **instance);
+typedef dword_t (*fs_close_proc_t)(file_instance_t *instance);
+typedef dword_t (*fs_delete_proc_t)(mounted_volume_t *volume, const char *path, bool_t purge);
+typedef dword_t (*fs_read_proc_t)(file_instance_t *file, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
+typedef dword_t (*fs_write_proc_t)(file_instance_t *file, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
+typedef dword_t (*fs_list_dir_proc_t)(file_instance_t *directory, char *filename, bool_t continue_scan);
+typedef dword_t (*fs_set_proc_t)(file_t *file, dword_t info_type, const void *buffer, size_t size);
+
+typedef enum
+{
+    FILE_INFO_ATTRIBUTES,
+    FILE_INFO_NAME,
+    FILE_INFO_TIME,
+    FILE_INFO_SIZE,
+    FILE_INFO_OWNER,
+} file_info_type_t;
+
+typedef struct
+{
+    list_entry_t list;
+    char name[16];
+    fs_mount_proc_t mount;
+    fs_unmount_proc_t unmount;
+    fs_load_proc_t load_file;
+    fs_unload_proc_t unload_file;
+    fs_open_proc_t open_file;
+    fs_close_proc_t close_file;
+    fs_delete_proc_t delete_file;
+    fs_read_proc_t read_file;
+    fs_write_proc_t write_file;
+    fs_list_dir_proc_t list_dir;
+    fs_set_proc_t set_file;
+} fs_driver_t;
+
+struct mounted_volume
+{
+    list_entry_t list;
+    dword_t flags;
+    resource_t resource;
+    block_device_t *device;
+    qword_t open_files;
+    fs_driver_t *driver;
+};
+
+typedef struct
+{
+    clock_time_t creation_time;
+    clock_time_t modification_time;
+    clock_time_t last_access_time;
+} file_time_info_t;
+
+struct file
+{
+    object_t header;
+    mounted_volume_t *volume;
+    char *path;
+    dword_t global_mode;
+    dword_t attributes;
+    qword_t size;
+    dword_t owner_uid;
+};
+
+struct file_instance
+{
+    object_t header;
+    file_t *global;
+    dword_t mode;
+};
+
+void register_filesystem_driver(fs_driver_t *driver);
+bool_t unregister_filesystem_driver(fs_driver_t *driver);
+mounted_volume_t *get_mounted_volume(const char *name);
+dword_t register_mounted_volume(mounted_volume_t *volume);
+dword_t unregister_mounted_volume(mounted_volume_t *volume);
+dword_t normalize_path(const char *path, mounted_volume_t **volume, char *normalized_path);
+dword_t open_file_internal(const char *path, file_instance_t **instance, dword_t mode, dword_t attributes);
+dword_t open_file(const char *path, handle_t *handle, dword_t mode, dword_t attributes);
+dword_t delete_file(const char *path);
+dword_t query_file(handle_t handle, file_info_type_t info_type, void *buffer, size_t size);
+dword_t set_file(handle_t handle, file_info_type_t set_type, void *buffer, size_t size);
+dword_t list_directory(handle_t handle, char *filename, bool_t continue_scan);
+dword_t read_file(handle_t handle, void *buffer, qword_t offset, size_t size, size_t *bytes_read);
+dword_t write_file(handle_t handle, const void *buffer, qword_t offset, size_t size, size_t *bytes_written);
+dword_t mount(const char *device, const char *filesystem, dword_t flags);
+dword_t unmount(const char *device);
+
+#endif

+ 65 - 0
kernel/include/heap.h

@@ -0,0 +1,65 @@
+/*
+ * heap.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _HEAP_H_
+#define _HEAP_H_
+
+#include <common.h>
+
+#define SYSTEM_HEAP_START    KERNEL_POOL_START
+#define SYSTEM_HEAP_END      (EVICTABLE_HEAP_START - 1)
+#define EVICTABLE_HEAP_START 0xA0000000
+#define EVICTABLE_HEAP_END   KERNEL_POOL_END
+
+#define SYSTEM_HEAP_MAGIC    0x74737953 // Syst
+#define EVICTABLE_HEAP_MAGIC 0x63697645 // Evic
+
+#define HEAP_ZEROFILL  (1 << 0)
+#define HEAP_EVICTABLE (1 << 1)
+
+typedef struct _heap_header_t
+{
+    dword_t length;
+    bool_t free;
+    dword_t magic;
+} heap_header_t;
+
+typedef struct
+{
+    uintptr_t start;
+    uintptr_t end;
+    uintptr_t max_end;
+    dword_t flags;
+    dword_t magic;
+} heap_t;
+
+extern heap_t system_heap;
+extern heap_t evictable_heap;
+
+void *heap_alloc(heap_t *heap, uintptr_t size);
+void heap_free(heap_t *heap, void *ptr);
+void *heap_realloc(heap_t *heap, void *ptr, uintptr_t size);
+dword_t heap_create(heap_t *heap, uintptr_t start, uintptr_t end, dword_t flags, dword_t magic);
+dword_t heap_destroy(heap_t *heap);
+void *malloc(uintptr_t size);
+void free(void *ptr);
+void *realloc(void *ptr, uintptr_t size);
+void heap_init(void);
+
+#endif

+ 80 - 0
kernel/include/interrupt.h

@@ -0,0 +1,80 @@
+/*
+ * interrupt.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _INTERRUPT_H_
+#define _INTERRUPT_H_
+
+#include <common.h>
+#include <list.h>
+
+#define IDT_NUM_INTERRUPTS 256
+#define ISR_STUB_SIZE 64
+#define HAS_ERROR_CODE(x) (((x) == 8) || ((x) >= 10 && (x) <= 14))
+#define IDT_GATE_KERNEL 0x8E
+#define IDT_GATE_USER 0xEE
+#define CONTEXT_SWITCH_MAGIC 0xDEADBEEF
+
+#pragma pack(push, 1)
+typedef struct
+{
+    word_t offset;
+    word_t selector;
+    byte_t zero;
+    byte_t type;
+    word_t offset_high;
+} idt_entry_t;
+#pragma pack(pop)
+
+typedef struct
+{
+    dword_t data_selector;
+    dword_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
+    dword_t error_code;
+    dword_t eip, cs, eflags;
+} registers_t;
+
+typedef struct
+{
+    dword_t data_selector;
+    dword_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
+    dword_t error_code;
+    dword_t eip, cs, eflags, esp3, ss;
+} registers_ext_t;
+
+typedef struct
+{
+    dword_t data_selector;
+    dword_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
+    dword_t error_code;
+    dword_t eip, cs, eflags, esp3, ss, es, ds, fs, gs;
+} registers_ext_vm86_t;
+
+typedef void (*isr_proc_t)(registers_t *regs, byte_t interrupt_num);
+
+typedef struct
+{
+    isr_proc_t procedure;
+    bool_t interrupts;
+} interrupt_handler_t;
+
+void interrupt_init(void);
+dword_t set_int_handler(byte_t interrupt_num, isr_proc_t proc, bool_t interrupts, bool_t usermode);
+dword_t remove_int_handler(byte_t interrupt_num);
+
+#endif

+ 53 - 0
kernel/include/irq.h

@@ -0,0 +1,53 @@
+/*
+ * irq.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _IRQ_H_
+#define _IRQ_H_
+
+#include <common.h>
+#include <interrupt.h>
+
+#define IRQ_INT_BASE 0x20
+#define MAX_IRQ_COUNT 16
+#define PRIMARY_IRQ_INT IRQ_INT_BASE
+#define SECONDARY_IRQ_INT (IRQ_INT_BASE + 8)
+#define PRIMARY_PIC_CMD 0x20
+#define SECONDARY_PIC_CMD 0xA0
+#define PRIMARY_PIC_DATA 0x21
+#define SECONDARY_PIC_DATA 0xA1
+#define PRIMARY_PIC_CASCADE_IRQ 2
+#define SECONDARY_PIC_CASCADE_IRQ 1
+#define PIC_8086_MODE 0x01
+
+typedef void (*irq_handler_proc_t)(registers_t *regs, byte_t irq_num);
+
+typedef struct
+{
+    list_entry_t list;
+    irq_handler_proc_t procedure;
+    bool_t exclusive;
+} irq_handler_t;
+
+dword_t register_irq_handler(byte_t irq_num, irq_handler_proc_t handler_proc, bool_t exclusive);
+dword_t unregister_irq_handler(byte_t irq_num, irq_handler_proc_t handler_proc);
+byte_t alloc_irq();
+void free_irq(byte_t number);
+void irq_init();
+
+#endif

+ 45 - 0
kernel/include/isa_dma.h

@@ -0,0 +1,45 @@
+/*
+ * isa_dma.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+
+#define ISA_DMA_MEM_START 0x200000
+#define ISA_DMA_MEM_END 0x280000
+#define ISA_DMA_MEM_ALIGNMENT 0x10000
+#define ISA_DMA_MEM_BLOCKS ((ISA_DMA_MEM_END - ISA_DMA_MEM_START) / ISA_DMA_MEM_ALIGNMENT)
+
+#define ISA_DMA_MASK_ON (1 << 2)
+
+#define ISA_DMA_SAR(x) (((x) < 4) ? ((x) << 1) : (0xC0 + (((x) - 4) << 2)))
+#define ISA_DMA_CNT(x) (((x) < 4) ? (((x) << 1) + 1) : (0xC2 + (((x) - 4) << 2)))
+#define ISA_DMA_FIRST_PAR(x) (((x) == 0) ? 0x87 : (((x) == 1) ? 0x83 : (0x7F + (x))))
+#define ISA_DMA_PAR(x) (((x) < 4) ? ISA_DMA_FIRST_PAR(x) : (ISA_DMA_FIRST_PAR((x) - 4) | 0x08))
+#define ISA_DMA_STATUS_REG(x) (((x) < 4) ? 0x08 : 0xD0)
+#define ISA_DMA_COMMAND_REG(x) (((x) < 4) ? 0x08 : 0xD0)
+#define ISA_DMA_SINGLE_MASK_REG(x) (((x) < 4) ? 0x0A : 0xD4)
+#define ISA_DMA_MODE_REG(x) (((x) < 4) ? 0x0B : 0xD6)
+#define ISA_DMA_FF_RESET_REG(x) (((x) < 4) ? 0x0C : 0xD8)
+#define ISA_DMA_MASTER_RESET_REG(x) (((x) < 4) ? 0x0D : 0xDA)
+#define ISA_DMA_MASK_RESET_REG(x) (((x) < 4) ? 0x0E : 0xDC)
+#define ISA_DMA_MULTI_MASK_REG(x) (((x) < 4) ? 0x0F : 0xDE)
+
+void *isa_dma_alloc(void);
+void isa_dma_free(void *dma_buffer);
+void isa_dma_read(dword_t channel, void *buffer, word_t count);
+void isa_dma_write(dword_t channel, void *buffer, dword_t count);

+ 299 - 0
kernel/include/list.h

@@ -0,0 +1,299 @@
+/*
+ * list.h
+ * 
+ * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _LIST_H_
+#define _LIST_H_
+
+#include <common.h>
+
+#define INITIALIZERS1(name) LIST_INITIALIZER(name[0])
+#define INITIALIZERS2(name) INITIALIZERS1(name), LIST_INITIALIZER(name[1])
+#define INITIALIZERS3(name) INITIALIZERS2(name), LIST_INITIALIZER(name[2])
+#define INITIALIZERS4(name) INITIALIZERS3(name), LIST_INITIALIZER(name[3])
+#define INITIALIZERS5(name) INITIALIZERS4(name), LIST_INITIALIZER(name[4])
+#define INITIALIZERS6(name) INITIALIZERS5(name), LIST_INITIALIZER(name[5])
+#define INITIALIZERS7(name) INITIALIZERS6(name), LIST_INITIALIZER(name[6])
+#define INITIALIZERS8(name) INITIALIZERS7(name), LIST_INITIALIZER(name[7])
+#define INITIALIZERS9(name) INITIALIZERS8(name), LIST_INITIALIZER(name[8])
+#define INITIALIZERS10(name) INITIALIZERS9(name), LIST_INITIALIZER(name[9])
+#define INITIALIZERS11(name) INITIALIZERS10(name), LIST_INITIALIZER(name[10])
+#define INITIALIZERS12(name) INITIALIZERS11(name), LIST_INITIALIZER(name[11])
+#define INITIALIZERS13(name) INITIALIZERS12(name), LIST_INITIALIZER(name[12])
+#define INITIALIZERS14(name) INITIALIZERS13(name), LIST_INITIALIZER(name[13])
+#define INITIALIZERS15(name) INITIALIZERS14(name), LIST_INITIALIZER(name[14])
+#define INITIALIZERS16(name) INITIALIZERS15(name), LIST_INITIALIZER(name[15])
+#define INITIALIZERS17(name) INITIALIZERS16(name), LIST_INITIALIZER(name[16])
+#define INITIALIZERS18(name) INITIALIZERS17(name), LIST_INITIALIZER(name[17])
+#define INITIALIZERS19(name) INITIALIZERS18(name), LIST_INITIALIZER(name[18])
+#define INITIALIZERS20(name) INITIALIZERS19(name), LIST_INITIALIZER(name[19])
+#define INITIALIZERS21(name) INITIALIZERS20(name), LIST_INITIALIZER(name[20])
+#define INITIALIZERS22(name) INITIALIZERS21(name), LIST_INITIALIZER(name[21])
+#define INITIALIZERS23(name) INITIALIZERS22(name), LIST_INITIALIZER(name[22])
+#define INITIALIZERS24(name) INITIALIZERS23(name), LIST_INITIALIZER(name[23])
+#define INITIALIZERS25(name) INITIALIZERS24(name), LIST_INITIALIZER(name[24])
+#define INITIALIZERS26(name) INITIALIZERS25(name), LIST_INITIALIZER(name[25])
+#define INITIALIZERS27(name) INITIALIZERS26(name), LIST_INITIALIZER(name[26])
+#define INITIALIZERS28(name) INITIALIZERS27(name), LIST_INITIALIZER(name[27])
+#define INITIALIZERS29(name) INITIALIZERS28(name), LIST_INITIALIZER(name[28])
+#define INITIALIZERS30(name) INITIALIZERS29(name), LIST_INITIALIZER(name[29])
+#define INITIALIZERS31(name) INITIALIZERS30(name), LIST_INITIALIZER(name[30])
+#define INITIALIZERS32(name) INITIALIZERS31(name), LIST_INITIALIZER(name[31])
+#define INITIALIZERS33(name) INITIALIZERS32(name), LIST_INITIALIZER(name[32])
+#define INITIALIZERS34(name) INITIALIZERS33(name), LIST_INITIALIZER(name[33])
+#define INITIALIZERS35(name) INITIALIZERS34(name), LIST_INITIALIZER(name[34])
+#define INITIALIZERS36(name) INITIALIZERS35(name), LIST_INITIALIZER(name[35])
+#define INITIALIZERS37(name) INITIALIZERS36(name), LIST_INITIALIZER(name[36])
+#define INITIALIZERS38(name) INITIALIZERS37(name), LIST_INITIALIZER(name[37])
+#define INITIALIZERS39(name) INITIALIZERS38(name), LIST_INITIALIZER(name[38])
+#define INITIALIZERS40(name) INITIALIZERS39(name), LIST_INITIALIZER(name[39])
+#define INITIALIZERS41(name) INITIALIZERS40(name), LIST_INITIALIZER(name[40])
+#define INITIALIZERS42(name) INITIALIZERS41(name), LIST_INITIALIZER(name[41])
+#define INITIALIZERS43(name) INITIALIZERS42(name), LIST_INITIALIZER(name[42])
+#define INITIALIZERS44(name) INITIALIZERS43(name), LIST_INITIALIZER(name[43])
+#define INITIALIZERS45(name) INITIALIZERS44(name), LIST_INITIALIZER(name[44])
+#define INITIALIZERS46(name) INITIALIZERS45(name), LIST_INITIALIZER(name[45])
+#define INITIALIZERS47(name) INITIALIZERS46(name), LIST_INITIALIZER(name[46])
+#define INITIALIZERS48(name) INITIALIZERS47(name), LIST_INITIALIZER(name[47])
+#define INITIALIZERS49(name) INITIALIZERS48(name), LIST_INITIALIZER(name[48])
+#define INITIALIZERS50(name) INITIALIZERS49(name), LIST_INITIALIZER(name[49])
+#define INITIALIZERS51(name) INITIALIZERS50(name), LIST_INITIALIZER(name[50])
+#define INITIALIZERS52(name) INITIALIZERS51(name), LIST_INITIALIZER(name[51])
+#define INITIALIZERS53(name) INITIALIZERS52(name), LIST_INITIALIZER(name[52])
+#define INITIALIZERS54(name) INITIALIZERS53(name), LIST_INITIALIZER(name[53])
+#define INITIALIZERS55(name) INITIALIZERS54(name), LIST_INITIALIZER(name[54])
+#define INITIALIZERS56(name) INITIALIZERS55(name), LIST_INITIALIZER(name[55])
+#define INITIALIZERS57(name) INITIALIZERS56(name), LIST_INITIALIZER(name[56])
+#define INITIALIZERS58(name) INITIALIZERS57(name), LIST_INITIALIZER(name[57])
+#define INITIALIZERS59(name) INITIALIZERS58(name), LIST_INITIALIZER(name[58])
+#define INITIALIZERS60(name) INITIALIZERS59(name), LIST_INITIALIZER(name[59])
+#define INITIALIZERS61(name) INITIALIZERS60(name), LIST_INITIALIZER(name[60])
+#define INITIALIZERS62(name) INITIALIZERS61(name), LIST_INITIALIZER(name[61])
+#define INITIALIZERS63(name) INITIALIZERS62(name), LIST_INITIALIZER(name[62])
+#define INITIALIZERS64(name) INITIALIZERS63(name), LIST_INITIALIZER(name[63])
+#define INITIALIZERS65(name) INITIALIZERS64(name), LIST_INITIALIZER(name[64])
+#define INITIALIZERS66(name) INITIALIZERS65(name), LIST_INITIALIZER(name[65])
+#define INITIALIZERS67(name) INITIALIZERS66(name), LIST_INITIALIZER(name[66])
+#define INITIALIZERS68(name) INITIALIZERS67(name), LIST_INITIALIZER(name[67])
+#define INITIALIZERS69(name) INITIALIZERS68(name), LIST_INITIALIZER(name[68])
+#define INITIALIZERS70(name) INITIALIZERS69(name), LIST_INITIALIZER(name[69])
+#define INITIALIZERS71(name) INITIALIZERS70(name), LIST_INITIALIZER(name[70])
+#define INITIALIZERS72(name) INITIALIZERS71(name), LIST_INITIALIZER(name[71])
+#define INITIALIZERS73(name) INITIALIZERS72(name), LIST_INITIALIZER(name[72])
+#define INITIALIZERS74(name) INITIALIZERS73(name), LIST_INITIALIZER(name[73])
+#define INITIALIZERS75(name) INITIALIZERS74(name), LIST_INITIALIZER(name[74])
+#define INITIALIZERS76(name) INITIALIZERS75(name), LIST_INITIALIZER(name[75])
+#define INITIALIZERS77(name) INITIALIZERS76(name), LIST_INITIALIZER(name[76])
+#define INITIALIZERS78(name) INITIALIZERS77(name), LIST_INITIALIZER(name[77])
+#define INITIALIZERS79(name) INITIALIZERS78(name), LIST_INITIALIZER(name[78])
+#define INITIALIZERS80(name) INITIALIZERS79(name), LIST_INITIALIZER(name[79])
+#define INITIALIZERS81(name) INITIALIZERS80(name), LIST_INITIALIZER(name[80])
+#define INITIALIZERS82(name) INITIALIZERS81(name), LIST_INITIALIZER(name[81])
+#define INITIALIZERS83(name) INITIALIZERS82(name), LIST_INITIALIZER(name[82])
+#define INITIALIZERS84(name) INITIALIZERS83(name), LIST_INITIALIZER(name[83])
+#define INITIALIZERS85(name) INITIALIZERS84(name), LIST_INITIALIZER(name[84])
+#define INITIALIZERS86(name) INITIALIZERS85(name), LIST_INITIALIZER(name[85])
+#define INITIALIZERS87(name) INITIALIZERS86(name), LIST_INITIALIZER(name[86])
+#define INITIALIZERS88(name) INITIALIZERS87(name), LIST_INITIALIZER(name[87])
+#define INITIALIZERS89(name) INITIALIZERS88(name), LIST_INITIALIZER(name[88])
+#define INITIALIZERS90(name) INITIALIZERS89(name), LIST_INITIALIZER(name[89])
+#define INITIALIZERS91(name) INITIALIZERS90(name), LIST_INITIALIZER(name[90])
+#define INITIALIZERS92(name) INITIALIZERS91(name), LIST_INITIALIZER(name[91])
+#define INITIALIZERS93(name) INITIALIZERS92(name), LIST_INITIALIZER(name[92])
+#define INITIALIZERS94(name) INITIALIZERS93(name), LIST_INITIALIZER(name[93])
+#define INITIALIZERS95(name) INITIALIZERS94(name), LIST_INITIALIZER(name[94])
+#define INITIALIZERS96(name) INITIALIZERS95(name), LIST_INITIALIZER(name[95])
+#define INITIALIZERS97(name) INITIALIZERS96(name), LIST_INITIALIZER(name[96])
+#define INITIALIZERS98(name) INITIALIZERS97(name), LIST_INITIALIZER(name[97])
+#define INITIALIZERS99(name) INITIALIZERS98(name), LIST_INITIALIZER(name[98])
+#define INITIALIZERS100(name) INITIALIZERS99(name), LIST_INITIALIZER(name[99])
+#define INITIALIZERS101(name) INITIALIZERS100(name), LIST_INITIALIZER(name[100])
+#define INITIALIZERS102(name) INITIALIZERS101(name), LIST_INITIALIZER(name[101])
+#define INITIALIZERS103(name) INITIALIZERS102(name), LIST_INITIALIZER(name[102])
+#define INITIALIZERS104(name) INITIALIZERS103(name), LIST_INITIALIZER(name[103])
+#define INITIALIZERS105(name) INITIALIZERS104(name), LIST_INITIALIZER(name[104])
+#define INITIALIZERS106(name) INITIALIZERS105(name), LIST_INITIALIZER(name[105])
+#define INITIALIZERS107(name) INITIALIZERS106(name), LIST_INITIALIZER(name[106])
+#define INITIALIZERS108(name) INITIALIZERS107(name), LIST_INITIALIZER(name[107])
+#define INITIALIZERS109(name) INITIALIZERS108(name), LIST_INITIALIZER(name[108])
+#define INITIALIZERS110(name) INITIALIZERS109(name), LIST_INITIALIZER(name[109])
+#define INITIALIZERS111(name) INITIALIZERS110(name), LIST_INITIALIZER(name[110])
+#define INITIALIZERS112(name) INITIALIZERS111(name), LIST_INITIALIZER(name[111])
+#define INITIALIZERS113(name) INITIALIZERS112(name), LIST_INITIALIZER(name[112])
+#define INITIALIZERS114(name) INITIALIZERS113(name), LIST_INITIALIZER(name[113])
+#define INITIALIZERS115(name) INITIALIZERS114(name), LIST_INITIALIZER(name[114])
+#define INITIALIZERS116(name) INITIALIZERS115(name), LIST_INITIALIZER(name[115])
+#define INITIALIZERS117(name) INITIALIZERS116(name), LIST_INITIALIZER(name[116])
+#define INITIALIZERS118(name) INITIALIZERS117(name), LIST_INITIALIZER(name[117])
+#define INITIALIZERS119(name) INITIALIZERS118(name), LIST_INITIALIZER(name[118])
+#define INITIALIZERS120(name) INITIALIZERS119(name), LIST_INITIALIZER(name[119])
+#define INITIALIZERS121(name) INITIALIZERS120(name), LIST_INITIALIZER(name[120])
+#define INITIALIZERS122(name) INITIALIZERS121(name), LIST_INITIALIZER(name[121])
+#define INITIALIZERS123(name) INITIALIZERS122(name), LIST_INITIALIZER(name[122])
+#define INITIALIZERS124(name) INITIALIZERS123(name), LIST_INITIALIZER(name[123])
+#define INITIALIZERS125(name) INITIALIZERS124(name), LIST_INITIALIZER(name[124])
+#define INITIALIZERS126(name) INITIALIZERS125(name), LIST_INITIALIZER(name[125])
+#define INITIALIZERS127(name) INITIALIZERS126(name), LIST_INITIALIZER(name[126])
+#define INITIALIZERS128(name) INITIALIZERS127(name), LIST_INITIALIZER(name[127])
+#define INITIALIZERS129(name) INITIALIZERS128(name), LIST_INITIALIZER(name[128])
+#define INITIALIZERS130(name) INITIALIZERS129(name), LIST_INITIALIZER(name[129])
+#define INITIALIZERS131(name) INITIALIZERS130(name), LIST_INITIALIZER(name[130])
+#define INITIALIZERS132(name) INITIALIZERS131(name), LIST_INITIALIZER(name[131])
+#define INITIALIZERS133(name) INITIALIZERS132(name), LIST_INITIALIZER(name[132])
+#define INITIALIZERS134(name) INITIALIZERS133(name), LIST_INITIALIZER(name[133])
+#define INITIALIZERS135(name) INITIALIZERS134(name), LIST_INITIALIZER(name[134])
+#define INITIALIZERS136(name) INITIALIZERS135(name), LIST_INITIALIZER(name[135])
+#define INITIALIZERS137(name) INITIALIZERS136(name), LIST_INITIALIZER(name[136])
+#define INITIALIZERS138(name) INITIALIZERS137(name), LIST_INITIALIZER(name[137])
+#define INITIALIZERS139(name) INITIALIZERS138(name), LIST_INITIALIZER(name[138])
+#define INITIALIZERS140(name) INITIALIZERS139(name), LIST_INITIALIZER(name[139])
+#define INITIALIZERS141(name) INITIALIZERS140(name), LIST_INITIALIZER(name[140])
+#define INITIALIZERS142(name) INITIALIZERS141(name), LIST_INITIALIZER(name[141])
+#define INITIALIZERS143(name) INITIALIZERS142(name), LIST_INITIALIZER(name[142])
+#define INITIALIZERS144(name) INITIALIZERS143(name), LIST_INITIALIZER(name[143])
+#define INITIALIZERS145(name) INITIALIZERS144(name), LIST_INITIALIZER(name[144])
+#define INITIALIZERS146(name) INITIALIZERS145(name), LIST_INITIALIZER(name[145])
+#define INITIALIZERS147(name) INITIALIZERS146(name), LIST_INITIALIZER(name[146])
+#define INITIALIZERS148(name) INITIALIZERS147(name), LIST_INITIALIZER(name[147])
+#define INITIALIZERS149(name) INITIALIZERS148(name), LIST_INITIALIZER(name[148])
+#define INITIALIZERS150(name) INITIALIZERS149(name), LIST_INITIALIZER(name[149])
+#define INITIALIZERS151(name) INITIALIZERS150(name), LIST_INITIALIZER(name[150])
+#define INITIALIZERS152(name) INITIALIZERS151(name), LIST_INITIALIZER(name[151])
+#define INITIALIZERS153(name) INITIALIZERS152(name), LIST_INITIALIZER(name[152])
+#define INITIALIZERS154(name) INITIALIZERS153(name), LIST_INITIALIZER(name[153])
+#define INITIALIZERS155(name) INITIALIZERS154(name), LIST_INITIALIZER(name[154])
+#define INITIALIZERS156(name) INITIALIZERS155(name), LIST_INITIALIZER(name[155])
+#define INITIALIZERS157(name) INITIALIZERS156(name), LIST_INITIALIZER(name[156])
+#define INITIALIZERS158(name) INITIALIZERS157(name), LIST_INITIALIZER(name[157])
+#define INITIALIZERS159(name) INITIALIZERS158(name), LIST_INITIALIZER(name[158])
+#define INITIALIZERS160(name) INITIALIZERS159(name), LIST_INITIALIZER(name[159])
+#define INITIALIZERS161(name) INITIALIZERS160(name), LIST_INITIALIZER(name[160])
+#define INITIALIZERS162(name) INITIALIZERS161(name), LIST_INITIALIZER(name[161])
+#define INITIALIZERS163(name) INITIALIZERS162(name), LIST_INITIALIZER(name[162])
+#define INITIALIZERS164(name) INITIALIZERS163(name), LIST_INITIALIZER(name[163])
+#define INITIALIZERS165(name) INITIALIZERS164(name), LIST_INITIALIZER(name[164])
+#define INITIALIZERS166(name) INITIALIZERS165(name), LIST_INITIALIZER(name[165])
+#define INITIALIZERS167(name) INITIALIZERS166(name), LIST_INITIALIZER(name[166])
+#define INITIALIZERS168(name) INITIALIZERS167(name), LIST_INITIALIZER(name[167])
+#define INITIALIZERS169(name) INITIALIZERS168(name), LIST_INITIALIZER(name[168])
+#define INITIALIZERS170(name) INITIALIZERS169(name), LIST_INITIALIZER(name[169])
+#define INITIALIZERS171(name) INITIALIZERS170(name), LIST_INITIALIZER(name[170])
+#define INITIALIZERS172(name) INITIALIZERS171(name), LIST_INITIALIZER(name[171])
+#define INITIALIZERS173(name) INITIALIZERS172(name), LIST_INITIALIZER(name[172])
+#define INITIALIZERS174(name) INITIALIZERS173(name), LIST_INITIALIZER(name[173])
+#define INITIALIZERS175(name) INITIALIZERS174(name), LIST_INITIALIZER(name[174])
+#define INITIALIZERS176(name) INITIALIZERS175(name), LIST_INITIALIZER(name[175])
+#define INITIALIZERS177(name) INITIALIZERS176(name), LIST_INITIALIZER(name[176])
+#define INITIALIZERS178(name) INITIALIZERS177(name), LIST_INITIALIZER(name[177])
+#define INITIALIZERS179(name) INITIALIZERS178(name), LIST_INITIALIZER(name[178])
+#define INITIALIZERS180(name) INITIALIZERS179(name), LIST_INITIALIZER(name[179])
+#define INITIALIZERS181(name) INITIALIZERS180(name), LIST_INITIALIZER(name[180])
+#define INITIALIZERS182(name) INITIALIZERS181(name), LIST_INITIALIZER(name[181])
+#define INITIALIZERS183(name) INITIALIZERS182(name), LIST_INITIALIZER(name[182])
+#define INITIALIZERS184(name) INITIALIZERS183(name), LIST_INITIALIZER(name[183])
+#define INITIALIZERS185(name) INITIALIZERS184(name), LIST_INITIALIZER(name[184])
+#define INITIALIZERS186(name) INITIALIZERS185(name), LIST_INITIALIZER(name[185])
+#define INITIALIZERS187(name) INITIALIZERS186(name), LIST_INITIALIZER(name[186])
+#define INITIALIZERS188(name) INITIALIZERS187(name), LIST_INITIALIZER(name[187])
+#define INITIALIZERS189(name) INITIALIZERS188(name), LIST_INITIALIZER(name[188])
+#define INITIALIZERS190(name) INITIALIZERS189(name), LIST_INITIALIZER(name[189])
+#define INITIALIZERS191(name) INITIALIZERS190(name), LIST_INITIALIZER(name[190])
+#define INITIALIZERS192(name) INITIALIZERS191(name), LIST_INITIALIZER(name[191])
+#define INITIALIZERS193(name) INITIALIZERS192(name), LIST_INITIALIZER(name[192])
+#define INITIALIZERS194(name) INITIALIZERS193(name), LIST_INITIALIZER(name[193])
+#define INITIALIZERS195(name) INITIALIZERS194(name), LIST_INITIALIZER(name[194])
+#define INITIALIZERS196(name) INITIALIZERS195(name), LIST_INITIALIZER(name[195])
+#define INITIALIZERS197(name) INITIALIZERS196(name), LIST_INITIALIZER(name[196])
+#define INITIALIZERS198(name) INITIALIZERS197(name), LIST_INITIALIZER(name[197])
+#define INITIALIZERS199(name) INITIALIZERS198(name), LIST_INITIALIZER(name[198])
+#define INITIALIZERS200(name) INITIALIZERS199(name), LIST_INITIALIZER(name[199])
+#define INITIALIZERS201(name) INITIALIZERS200(name), LIST_INITIALIZER(name[200])
+#define INITIALIZERS202(name) INITIALIZERS201(name), LIST_INITIALIZER(name[201])
+#define INITIALIZERS203(name) INITIALIZERS202(name), LIST_INITIALIZER(name[202])
+#define INITIALIZERS204(name) INITIALIZERS203(name), LIST_INITIALIZER(name[203])
+#define INITIALIZERS205(name) INITIALIZERS204(name), LIST_INITIALIZER(name[204])
+#define INITIALIZERS206(name) INITIALIZERS205(name), LIST_INITIALIZER(name[205])
+#define INITIALIZERS207(name) INITIALIZERS206(name), LIST_INITIALIZER(name[206])
+#define INITIALIZERS208(name) INITIALIZERS207(name), LIST_INITIALIZER(name[207])
+#define INITIALIZERS209(name) INITIALIZERS208(name), LIST_INITIALIZER(name[208])
+#define INITIALIZERS210(name) INITIALIZERS209(name), LIST_INITIALIZER(name[209])
+#define INITIALIZERS211(name) INITIALIZERS210(name), LIST_INITIALIZER(name[210])
+#define INITIALIZERS212(name) INITIALIZERS211(name), LIST_INITIALIZER(name[211])
+#define INITIALIZERS213(name) INITIALIZERS212(name), LIST_INITIALIZER(name[212])
+#define INITIALIZERS214(name) INITIALIZERS213(name), LIST_INITIALIZER(name[213])
+#define INITIALIZERS215(name) INITIALIZERS214(name), LIST_INITIALIZER(name[214])
+#define INITIALIZERS216(name) INITIALIZERS215(name), LIST_INITIALIZER(name[215])
+#define INITIALIZERS217(name) INITIALIZERS216(name), LIST_INITIALIZER(name[216])
+#define INITIALIZERS218(name) INITIALIZERS217(name), LIST_INITIALIZER(name[217])
+#define INITIALIZERS219(name) INITIALIZERS218(name), LIST_INITIALIZER(name[218])
+#define INITIALIZERS220(name) INITIALIZERS219(name), LIST_INITIALIZER(name[219])
+#define INITIALIZERS221(name) INITIALIZERS220(name), LIST_INITIALIZER(name[220])
+#define INITIALIZERS222(name) INITIALIZERS221(name), LIST_INITIALIZER(name[221])
+#define INITIALIZERS223(name) INITIALIZERS222(name), LIST_INITIALIZER(name[222])
+#define INITIALIZERS224(name) INITIALIZERS223(name), LIST_INITIALIZER(name[223])
+#define INITIALIZERS225(name) INITIALIZERS224(name), LIST_INITIALIZER(name[224])
+#define INITIALIZERS226(name) INITIALIZERS225(name), LIST_INITIALIZER(name[225])
+#define INITIALIZERS227(name) INITIALIZERS226(name), LIST_INITIALIZER(name[226])
+#define INITIALIZERS228(name) INITIALIZERS227(name), LIST_INITIALIZER(name[227])
+#define INITIALIZERS229(name) INITIALIZERS228(name), LIST_INITIALIZER(name[228])
+#define INITIALIZERS230(name) INITIALIZERS229(name), LIST_INITIALIZER(name[229])
+#define INITIALIZERS231(name) INITIALIZERS230(name), LIST_INITIALIZER(name[230])
+#define INITIALIZERS232(name) INITIALIZERS231(name), LIST_INITIALIZER(name[231])
+#define INITIALIZERS233(name) INITIALIZERS232(name), LIST_INITIALIZER(name[232])
+#define INITIALIZERS234(name) INITIALIZERS233(name), LIST_INITIALIZER(name[233])
+#define INITIALIZERS235(name) INITIALIZERS234(name), LIST_INITIALIZER(name[234])
+#define INITIALIZERS236(name) INITIALIZERS235(name), LIST_INITIALIZER(name[235])
+#define INITIALIZERS237(name) INITIALIZERS236(name), LIST_INITIALIZER(name[236])
+#define INITIALIZERS238(name) INITIALIZERS237(name), LIST_INITIALIZER(name[237])
+#define INITIALIZERS239(name) INITIALIZERS238(name), LIST_INITIALIZER(name[238])
+#define INITIALIZERS240(name) INITIALIZERS239(name), LIST_INITIALIZER(name[239])
+#define INITIALIZERS241(name) INITIALIZERS240(name), LIST_INITIALIZER(name[240])
+#define INITIALIZERS242(name) INITIALIZERS241(name), LIST_INITIALIZER(name[241])
+#define INITIALIZERS243(name) INITIALIZERS242(name), LIST_INITIALIZER(name[242])
+#define INITIALIZERS244(name) INITIALIZERS243(name), LIST_INITIALIZER(name[243])
+#define INITIALIZERS245(name) INITIALIZERS244(name), LIST_INITIALIZER(name[244])
+#define INITIALIZERS246(name) INITIALIZERS245(name), LIST_INITIALIZER(name[245])
+#define INITIALIZERS247(name) INITIALIZERS246(name), LIST_INITIALIZER(name[246])
+#define INITIALIZERS248(name) INITIALIZERS247(name), LIST_INITIALIZER(name[247])
+#define INITIALIZERS249(name) INITIALIZERS248(name), LIST_INITIALIZER(name[248])
+#define INITIALIZERS250(name) INITIALIZERS249(name), LIST_INITIALIZER(name[249])
+#define INITIALIZERS251(name) INITIALIZERS250(name), LIST_INITIALIZER(name[250])
+#define INITIALIZERS252(name) INITIALIZERS251(name), LIST_INITIALIZER(name[251])
+#define INITIALIZERS253(name) INITIALIZERS252(name), LIST_INITIALIZER(name[252])
+#define INITIALIZERS254(name) INITIALIZERS253(name), LIST_INITIALIZER(name[253])
+#define INITIALIZERS255(name) INITIALIZERS254(name), LIST_INITIALIZER(name[254])
+#define INITIALIZERS256(name) INITIALIZERS255(name), LIST_INITIALIZER(name[255])
+
+#define LIST_INITIALIZER(name) { &name, &name }
+#define DECLARE_LIST(name) list_entry_t name = LIST_INITIALIZER(name)
+#define DECLARE_LIST_ARRAY(name, size) list_entry_t name[size] = { INITIALIZERS##size(name) }
+
+#define list_put_after  list_prepend
+#define list_put_before list_append
+
+typedef struct _list_entry_t
+{
+    struct _list_entry_t *next, *prev;
+} list_entry_t;
+
+void list_prepend(list_entry_t *list, list_entry_t *entry);
+void list_append(list_entry_t *list, list_entry_t *entry);
+void list_remove(list_entry_t *entry);
+void list_init(list_entry_t *list);
+
+#endif

+ 228 - 0
kernel/include/memory.h

@@ -0,0 +1,228 @@
+/*
+ * memory.h
+ * 
+ * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MEMORY_H_
+#define _MEMORY_H_
+
+#include <common.h>
+#include <interrupt.h>
+#include <boot/multiboot.h>
+#include <avl_tree.h>
+#include <object.h>
+#include <filesystem.h>
+
+#define MEMORY_BLOCK_ACCESSIBLE    (1 << 0)
+#define MEMORY_BLOCK_WRITABLE      (1 << 1)
+#define MEMORY_BLOCK_EXECUTABLE    (1 << 2)
+#define MEMORY_BLOCK_USERMODE      (1 << 3)
+#define MEMORY_BLOCK_EVICTABLE     (1 << 29)
+#define MEMORY_BLOCK_COPY_ON_WRITE (1 << 30)
+#define MEMORY_BLOCK_FREE          (1 << 31)
+
+#define PAGE_SIZE      4096
+#define PAGE_PRESENT   (1 << 0)
+#define PAGE_WRITABLE  (1 << 1)
+#define PAGE_USERMODE  (1 << 2)
+#define PAGE_ACCESSED  (1 << 5)
+#define PAGE_DIRTY     (1 << 6)
+#define PAGE_GLOBAL    (1 << 8)
+#define PAGE_EVICTABLE (1 << 9)
+
+#define PAGE_ERROR_PRESENT_FLAG  (1 << 0)
+#define PAGE_ERROR_WRITE_FLAG    (1 << 1)
+#define PAGE_ERROR_USERMODE_FLAG (1 << 2)
+
+#define ADDR_TO_PDE(x)   ((x) >> 22)
+#define ADDR_TO_PTE(x)   (((x) >> 12) & 0x3FF)
+#define PAGE_ALIGN(x)    ((x) & 0xFFFFF000)
+#define PAGE_ALIGN_UP(x) (((x) + 0xFFF) & 0xFFFFF000)
+#define PAGE_OFFSET(x)   ((x) & 0x00000FFF)
+#define PAGE_NUMBER(x)   ((x) >> 12)
+
+#define KERNEL_AREA_START 0x80000000
+#define KERNEL_AREA_END   0xFFFFFFFF
+#define KERNEL_POOL_START 0x81000000
+#define KERNEL_POOL_END   0xBFFFFFFF
+#define MAPPING_START     0xC8000000
+#define MAPPING_END       0xFFFFFFFF
+#define USER_AREA_START   0x00000000
+#define USER_AREA_END     0x7FFFFFFF
+#define KERNEL_PAGE_START ADDR_TO_PDE(KERNEL_AREA_START)
+#define KERNEL_PAGE_END   ADDR_TO_PDE(KERNEL_AREA_END)
+#define USER_PAGE_START   ADDR_TO_PDE(USER_AREA_START)
+#define USER_PAGE_END     ADDR_TO_PDE(USER_AREA_END)
+
+#define PAGEDIR_SELF_ENTRY  768
+#define PAGE_DIRECTORY_ADDR ((PAGEDIR_SELF_ENTRY << 22) + (PAGEDIR_SELF_ENTRY << 12))
+#define PAGE_TABLE_ADDR     (PAGEDIR_SELF_ENTRY << 22)
+
+#define INVALID_PAGE        ((void*)-1)
+#define TOTAL_PAGES         1048576
+#define MEM_FIRST_PHYS_ADDR 0x400000
+#define MEM_STACK_VIRT_ADDR 0xC0400000
+#define MEM_TREE_BLOCKS     0xC0800000
+#define TEMPORARY_PAGES     256
+#define TEMPORARY_ADDR      (0xC8000000 - TEMPORARY_PAGES * PAGE_SIZE)
+#define EVICTION_THRESHOLD  128
+
+#define INVALID_STORE_NUMBER        ((dword_t)-1)
+#define PAGE_STORE_ENTRY_PRESENT    (1 << 31)
+
+#define MEMORY_SECTION_WRITABLE     (1 << 0)
+#define MEMORY_SECTION_DIRECT_WRITE (1 << 1)
+
+typedef struct memory_block memory_block_t;
+
+typedef struct
+{
+    uintptr_t phys_addr;
+    uintptr_t ref_count;
+} page_t;
+
+typedef struct
+{
+    uintptr_t used_virtual;
+    uintptr_t committed;
+    uintptr_t evicted;
+    uintptr_t shared;
+} memory_stats_t;
+
+typedef struct
+{
+    list_entry_t link;
+    void *page_directory;
+    void *pool_address;
+    uintptr_t pool_size;
+    avl_tree_t *by_addr_tree_root;
+    avl_tree_t *by_size_tree_root;
+    resource_t resource;
+    list_entry_t evictable_blocks;
+    list_entry_t *evict_blk_ptr;
+    uintptr_t evict_page_num;
+    memory_stats_t stats;
+} memory_address_space_t;
+
+typedef struct
+{
+    list_entry_t link;
+    void *physical;
+    uintptr_t offset;
+} shared_page_t;
+
+typedef struct
+{
+    object_t header;
+    dword_t flags;
+    list_entry_t page_list;
+    size_t size;
+    file_instance_t *file;
+} memory_section_t;
+
+struct memory_block
+{
+    avl_tree_t by_addr_tree;
+    avl_tree_t by_size_tree;
+    list_entry_t evict_link;
+    dword_t flags;
+    memory_address_space_t *address_space;
+    memory_section_t *section;
+    qword_t section_offset;
+};
+
+typedef struct
+{
+    qword_t address;
+    qword_t size;
+    dword_t flags;
+} memory_block_info_t;
+
+typedef struct
+{
+    list_entry_t link;
+    dword_t num_entries;
+    dword_t max_entries;
+    handle_t file_handle;
+    dword_t *bitmap;
+    list_entry_t entry_list;
+} page_store_t;
+
+typedef struct
+{
+    list_entry_t link;
+    void *address;
+    memory_address_space_t *address_space;
+    dword_t number;
+    void *physical;
+} page_store_entry_t;
+
+typedef enum
+{
+    PAGE_ERROR_NOTPRESENT,
+    PAGE_ERROR_READONLY,
+    PAGE_ERROR_UNPRIVILEGED
+} page_error_t;
+
+void set_page_directory(void *phys_addr);
+void *get_page_directory();
+void *get_physical_address(void *virtual);
+dword_t map_memory_internal(void *physical, void *virtual, size_t size, dword_t page_flags);
+void unmap_memory_internal(void *virtual, size_t size);
+dword_t read_physical(void *physical, void *buffer, size_t size);
+dword_t write_physical(void *physical, void *buffer, size_t size);
+dword_t map_memory_in_address_space(memory_address_space_t *address_space,
+                                    void *physical,
+                                    void **virtual,
+                                    uintptr_t size,
+                                    dword_t block_flags);
+dword_t unmap_memory_in_address_space(memory_address_space_t *address_space, void *virtual);
+dword_t pin_memory(const void *virtual, void **pinned, size_t size, bool_t lock_contents);
+dword_t map_memory(void *physical, void **virtual, size_t size, dword_t page_flags);
+dword_t unmap_memory(void *virtual);
+dword_t alloc_memory_in_address_space(
+    memory_address_space_t *address_space,
+    void **address,
+    size_t size,
+    dword_t block_flags,
+    memory_section_t *section,
+    qword_t section_offset);
+dword_t free_memory_in_address_space(memory_address_space_t *address_space, void *address);
+dword_t commit_pages(void *address, size_t size);
+dword_t uncommit_pages(void *address, size_t size);
+dword_t alloc_memory(handle_t process, void **address, size_t size, dword_t block_flags);
+dword_t free_memory(handle_t process, void *address);
+dword_t commit_memory(handle_t process, void *address, dword_t size);
+dword_t uncommit_memory(handle_t process, void *address, dword_t size);
+dword_t set_memory_flags(handle_t process, void *address, dword_t flags);
+dword_t query_memory(handle_t process, void *address, memory_block_info_t *info);
+dword_t read_memory(handle_t process, void *address, void *buffer, dword_t size);
+dword_t write_memory(handle_t process, void *address, void *buffer, dword_t size);
+void *alloc_pool(void *address, size_t size, dword_t block_flags);
+void free_pool(void *address);
+dword_t create_address_space(void *base_address, dword_t page_count, memory_address_space_t *mem_space);
+dword_t clone_address_space(memory_address_space_t *original, memory_address_space_t *clone);
+void bump_address_space(memory_address_space_t *mem_space);
+void delete_address_space(memory_address_space_t *mem_space);
+bool_t memory_fault_handler(void *address, registers_t *regs);
+void memory_init(multiboot_mmap_t *mmap_addr, dword_t mmap_length);
+dword_t create_memory_section(const char *name, handle_t file, size_t size, dword_t flags, handle_t *handle);
+dword_t open_memory_section(const char *name, handle_t *handle);
+dword_t map_memory_section(handle_t process, handle_t section, void **address, qword_t offset, size_t size, dword_t flags);
+dword_t flush_memory_section(handle_t process, void *address);
+
+#endif

+ 70 - 0
kernel/include/object.h

@@ -0,0 +1,70 @@
+/*
+ * object.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _OBJECT_H_
+#define _OBJECT_H_
+
+#include <common.h>
+#include <list.h>
+
+#define INVALID_HANDLE (handle_t)-1
+
+typedef dword_t handle_t;
+
+typedef enum
+{
+    OBJECT_FILE,
+    OBJECT_FILE_INSTANCE,
+    OBJECT_PIPE,
+    OBJECT_PROCESS,
+    OBJECT_THREAD,
+    OBJECT_MEMORY,
+    OBJECT_SEMAPHORE,
+    OBJECT_TYPE_MAX
+} object_type_t;
+
+typedef enum
+{
+    HANDLE_INFO_NAME,
+    HANDLE_INFO_TYPE,
+} handle_info_type_t;
+
+typedef struct
+{
+    list_entry_t list;
+    char *name;
+    qword_t ref_count, open_count;
+    object_type_t type;
+} object_t;
+
+typedef void (*object_cleanup_proc_t)(object_t *obj);
+
+dword_t create_object(object_t *object);
+void reference(object_t *object);
+void dereference(object_t *object);
+bool_t reference_by_name(const char *name, object_type_t type, object_t **object);
+bool_t reference_by_handle(handle_t handle, object_type_t type, object_t **object);
+dword_t open_object(object_t *obj, handle_t *handle);
+dword_t open_object_by_name(const char *name, object_type_t type, handle_t *handle);
+void close_object_internal(object_t *obj);
+dword_t close_object(handle_t handle);
+dword_t query_handle(handle_t handle, handle_info_type_t type, void *buffer, size_t size);
+dword_t duplicate_handle(handle_t source_process, handle_t handle, handle_t dest_process, handle_t *duplicate);
+
+#endif

+ 118 - 0
kernel/include/pci.h

@@ -0,0 +1,118 @@
+/*
+ * pci.h
+ * 
+ * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _PCI_H_
+#define _PCI_H_
+
+#include <common.h>
+#include <list.h>
+
+#pragma pack(push, 1)
+
+typedef struct
+{
+    word_t vendor_id;
+    word_t device_id;
+    word_t command;
+    word_t status;
+    byte_t revision_id;
+    byte_t prog_if;
+    byte_t subclass;
+    byte_t class;
+    byte_t cache_line_size;
+    byte_t latency_timer;
+    byte_t header_type;
+    byte_t bist;
+} pci_header_t;
+
+typedef struct
+{
+    pci_header_t header;
+    dword_t bar[6];
+    dword_t cardbus_ptr;
+    word_t subsys_vendor_id;
+    word_t subsys_id;
+    dword_t expansion_rom_addr;
+    byte_t capabilities;
+    byte_t reserved[7];
+    byte_t interrupt_line;
+    byte_t interrupt_pin;
+    byte_t min_grant;
+    byte_t max_latency;
+} pci_standard_header_t;
+
+typedef struct
+{
+    pci_header_t header;
+    dword_t bar[2];
+    byte_t primary_bus_num;
+    byte_t secondary_bus_num;
+    byte_t subordinate_bus_num;
+    byte_t secondary_latency_timer;
+    byte_t io_base;
+    byte_t io_limit;
+    word_t secondary_status;
+    word_t prefetchable_mem_base;
+    word_t prefetchable_mem_limit;
+    dword_t prefetchable_base_high;
+    dword_t prefetchable_limit_high;
+    word_t io_base_high;
+    word_t io_limit_high;
+    byte_t capabilities;
+    byte_t reserved[3];
+    dword_t expansion_rom_addr;
+    byte_t interrupt_line;
+    byte_t interrupt_pin;
+    word_t bridge_control;
+} pci_bridge_header_t;
+
+#pragma pack(pop)
+
+typedef struct _pci_device_t
+{
+    list_entry_t list;
+    dword_t bus, slot, function;
+    dword_t class, subclass, prog_if;
+    bool_t in_use;
+} pci_device_t;
+
+enum
+{
+    PCI_LEGACY_DEVICE,
+    PCI_MASS_STORAGE_DEVICE,
+    PCI_NETWORK_DEVICE,
+    PCI_DISPLAY_DEVICE,
+    PCI_MULTIMEDIA_DEVICE,
+    PCI_BRIDGE_DEVICE,
+    PCI_COMMUNICATION_DEVICE,
+    PCI_PERIPHERAL_DEVICE,
+    PCI_INPUT_DEVICE,
+    PCI_DOCKING_STATION,
+    PCI_PROCESSOR,
+    PCI_WIRELESS_DEVICE
+};
+
+extern const char *pci_device_classes[];
+
+void pci_init(void);
+list_entry_t *get_pci_device_list_head(void);
+dword_t pci_read(pci_device_t *device, dword_t reg);
+void pci_write(pci_device_t *device, dword_t reg, dword_t data);
+
+#endif

+ 49 - 0
kernel/include/pipe.h

@@ -0,0 +1,49 @@
+/*
+ * pipe.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _PIPE_H_
+#define _PIPE_H_
+
+#include <common.h>
+#include <object.h>
+#include <sync.h>
+
+#define PIPE_BLOCK_SIZE 256
+
+typedef struct
+{
+    list_entry_t list;
+    dword_t start, end;
+    bool_t full;
+    byte_t data[PIPE_BLOCK_SIZE];
+} pipe_fifo_entry_t;
+
+typedef struct
+{
+    object_t header;
+    lock_t lock;
+    list_entry_t fifo;
+} pipe_t;
+
+dword_t create_pipe(const char *name, handle_t *handle);
+dword_t open_pipe(const char *name, handle_t *handle);
+dword_t read_pipe(handle_t handle, void *buffer, dword_t size, dword_t timeout);
+dword_t write_pipe(handle_t handle, void *buffer, dword_t size);
+
+#endif

+ 35 - 0
kernel/include/power.h

@@ -0,0 +1,35 @@
+/*
+ * power.h
+ * 
+ * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _POWER_H_
+#define _POWER_H_
+
+#include <common.h>
+
+typedef enum
+{
+    POWER_COMMAND_HALT,
+    POWER_COMMAND_REBOOT,
+    POWER_COMMAND_SHUTDOWN
+} power_command_t;
+
+dword_t power_init(void);
+dword_t power_control(power_command_t command);
+
+#endif

+ 108 - 0
kernel/include/process.h

@@ -0,0 +1,108 @@
+/*
+ * process.h
+ * 
+ * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _PROCESS_H_
+#define _PROCESS_H_
+
+#include <common.h>
+#include <object.h>
+#include <memory.h>
+#include <clock.h>
+#include <pipe.h>
+#include <thread.h>
+#include <vm86.h>
+#include <user.h>
+
+#define MAX_PROCESSES 2097152
+#define PROCESS_POOL_ADDRESS NULL
+#define PROCESS_POOL_SIZE 524288
+#define STARTUP_HANDLE_TABLE_SIZE (256 * sizeof(void*))
+
+#define CLONE_MAGIC 0x79706F43
+
+#define PROCESS_CREATE_NO_INHERIT    (1 << 0)
+#define PROCESS_CREATE_NO_THREADS    (1 << 1)
+#define PROCESS_CREATE_FROZEN_THREAD (1 << 2)
+
+typedef enum
+{
+    PROCESS_PID_INFO,
+    PROCESS_NAME_INFO,
+    PROCESS_START_TIME_INFO,
+    PROCESS_MEMORY_INFO,
+    PROCESS_EXIT_CODE_INFO,
+    PROCESS_USER_INFO,
+    PROCESS_THREAD_INFO,
+    PROCESS_HANDLE_INFO,
+} process_info_t;
+
+#ifndef THREAD_TYPEDEF
+#define THREAD_TYPEDEF
+typedef struct thread thread_t;
+#endif
+
+struct process
+{
+    object_t header;
+    list_entry_t list;
+    dword_t pid;
+    char *name;
+    memory_address_space_t memory_space;
+    dword_t exit_code;
+    bool_t terminating;
+    dword_t terminated;
+    clock_time_t start_time;
+    clock_time_t end_time;
+    list_entry_t threads;
+    resource_t thread_list_res;
+    object_t **handle_table;
+    dword_t handle_count, handle_table_size;
+    resource_t handle_table_res;
+    user_t *original_user, *current_user;
+};
+
+#ifndef PROCESS_TYPEDEF
+#define PROCESS_TYPEDEF
+typedef struct process process_t;
+#endif
+
+typedef struct
+{
+    char *command_line;
+    handle_t standard_input;
+    handle_t standard_output;
+    handle_t standard_error;
+} process_params_t;
+
+extern process_t *kernel_process;
+
+process_t *get_current_process();
+dword_t open_process(dword_t pid, handle_t *handle);
+dword_t create_process(const char *path, dword_t flags, process_params_t *parameters, handle_t *process_handle, handle_t *thread_handle);
+void process_cleanup(object_t *proc);
+void destroy_process(process_t *process);
+dword_t terminate(handle_t handle, dword_t exit_code);
+dword_t get_process_id();
+dword_t query_process(handle_t handle, process_info_t info_type, void *buffer, dword_t size);
+dword_t enum_processes(dword_t *pid_array, dword_t *count);
+dword_t wait_process(handle_t handle, dword_t timeout);
+process_t *switch_process(process_t *new_process);
+void process_init();
+
+#endif

+ 87 - 0
kernel/include/segments.h

@@ -0,0 +1,87 @@
+/*
+ * segments.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _SEGMENTS_H_
+#define _SEGMENTS_H_
+
+#include <common.h>
+
+#define GDT_MAX_ENTRIES 8
+
+#pragma pack(push, 1)
+typedef struct
+{
+    dword_t limit : 16;
+    dword_t base : 24;
+    dword_t accessed : 1;
+    dword_t readwrite : 1;
+    dword_t dirconf : 1;
+    dword_t executable : 1;
+    dword_t standard : 1;
+    dword_t rpl : 2;
+    dword_t present : 1;
+    dword_t limit_high : 4;
+    dword_t always_zero : 2;
+    dword_t size : 1;
+    dword_t granularity : 1;
+    dword_t base_high : 8;
+} gdt_descriptor_t;
+#pragma pack(pop)
+
+typedef struct
+{
+    dword_t link;
+    dword_t esp0;
+    dword_t ss0;
+    dword_t esp1;
+    dword_t ss1;
+    dword_t esp2;
+    dword_t ss2;
+    dword_t cr3;
+    dword_t eip;
+    dword_t eflags;
+    dword_t eax;
+    dword_t ecx;
+    dword_t edx;
+    dword_t ebx;
+    dword_t esp;
+    dword_t ebp;
+    dword_t esi;
+    dword_t edi;
+    dword_t es;
+    dword_t cs;
+    dword_t ss;
+    dword_t ds;
+    dword_t fs;
+    dword_t gs;
+    dword_t ldtr;
+    dword_t iopb;
+} tss_entry_t;
+
+void segments_init(void);
+dword_t get_kernel_esp(void);
+void set_kernel_esp(dword_t esp);
+word_t get_kernel_code_selector(void);
+word_t get_kernel_data_selector(void);
+word_t get_user_code_selector(void);
+word_t get_user_data_selector(void);
+word_t gdt_create_segment(dword_t base, dword_t limit, bool_t executable, byte_t priv_level, bool_t readwrite, bool_t dirconf, bool_t large);
+word_t gdt_create_tss(tss_entry_t *base, dword_t limit);
+
+#endif

+ 55 - 0
kernel/include/sync.h

@@ -0,0 +1,55 @@
+/*
+ * sync.h
+ * 
+ * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _SYNC_H_
+#define _SYNC_H_
+
+#include <common.h>
+#include <object.h>
+
+#define NO_TIMEOUT 0xFFFFFFFF
+
+#define init_mutex(m, i) init_semaphore((m), (i), 1)
+#define wait_mutex(m, t) wait_semaphore((m), 1, (t))
+#define release_mutex(m) release_semaphore((m), 1)
+
+typedef volatile uintptr_t lock_t;
+typedef volatile uintptr_t resource_t;
+
+typedef struct
+{
+    object_t header;
+    dword_t count;
+    dword_t max_count;
+} semaphore_t, mutex_t;
+
+void acquire_lock(lock_t *lock);
+void release_lock(lock_t *lock);
+void acquire_resource_shared(resource_t *res);
+void acquire_resource_exclusive(resource_t *res);
+void release_resource(resource_t *res);
+void init_semaphore(semaphore_t *semaphore, dword_t init_count, dword_t max_count);
+dword_t create_semaphore(const char *name, dword_t init_count, dword_t max_count, handle_t *handle);
+dword_t open_semaphore(const char *name, handle_t *handle);
+dword_t wait_semaphore(semaphore_t *semaphore, dword_t count, dword_t timeout);
+dword_t release_semaphore(semaphore_t *semaphore, dword_t count);
+dword_t wait_semaphore_by_handle(handle_t semaphore, dword_t count, dword_t timeout);
+dword_t release_semaphore_by_handle(handle_t semaphore, dword_t count);
+
+#endif

+ 113 - 0
kernel/include/syscalls.h

@@ -0,0 +1,113 @@
+/*
+ * syscalls.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _SYSCALLS_H_
+#define _SYSCALLS_H_
+
+#include <common.h>
+
+#define MAX_PARAMETERS 16
+#define SYSCALL_INTERRUPT 0xE5
+
+typedef enum
+{
+    SYSCALL_ALLOC_MEMORY,
+    SYSCALL_BLOCK_DEVICE_IOCTL,
+    SYSCALL_BLOCK_DEVICE_READ,
+    SYSCALL_BLOCK_DEVICE_WRITE,
+    SYSCALL_CHAR_DEVICE_IOCTL,
+    SYSCALL_CHAR_DEVICE_READ,
+    SYSCALL_CHAR_DEVICE_WRITE,
+    SYSCALL_CLOCK_GET_TIME,
+    SYSCALL_CLOCK_SET_TIME,
+    SYSCALL_CLOSE_OBJECT,
+    SYSCALL_COMMIT_MEMORY,
+    SYSCALL_CREATE_MEMORY_SECTION,
+    SYSCALL_CREATE_PROCESS,
+    SYSCALL_CREATE_SEMAPHORE,
+    SYSCALL_CREATE_THREAD,
+    SYSCALL_CREATE_USER,
+    SYSCALL_DELETE_FILE,
+    SYSCALL_DELETE_USER,
+    SYSCALL_DUPLICATE_HANDLE,
+    SYSCALL_ENUM_BLOCK_DEVICES,
+    SYSCALL_ENUM_CHAR_DEVICES,
+    SYSCALL_ENUM_PROCESSES,
+    SYSCALL_FLUSH_MEMORY_SECTION,
+    SYSCALL_FREE_MEMORY,
+    SYSCALL_GET_EXCEPTION_INFO,
+    SYSCALL_GET_MILLISECONDS,
+    SYSCALL_GET_NANOSECONDS,
+    SYSCALL_GET_PROCESS_ID,
+    SYSCALL_GET_THREAD_ID,
+    SYSCALL_GET_USER_ID,
+    SYSCALL_LIST_DIRECTORY,
+    SYSCALL_LOGON_USER,
+    SYSCALL_MAP_MEMORY_SECTION,
+    SYSCALL_MOUNT,
+    SYSCALL_OPEN_FILE,
+    SYSCALL_OPEN_MEMORY_SECTION,
+    SYSCALL_OPEN_PIPE,
+    SYSCALL_OPEN_PROCESS,
+    SYSCALL_OPEN_THREAD,
+    SYSCALL_POWER_CONTROL,
+    SYSCALL_QUERY_FILE,
+    SYSCALL_QUERY_HANDLE,
+    SYSCALL_QUERY_PROCESS,
+    SYSCALL_QUERY_THREAD,
+    SYSCALL_QUERY_USER,
+    SYSCALL_RAISE_EXCEPTION,
+    SYSCALL_READ_FILE,
+    SYSCALL_READ_MEMORY,
+    SYSCALL_READ_PIPE,
+    SYSCALL_RELEASE_SEMAPHORE,
+    SYSCALL_RESTORE_EXCEPTION_HANDLER,
+    SYSCALL_REVERT_USER,
+    SYSCALL_SAVE_EXCEPTION_HANDLER,
+    SYSCALL_SET_MEMORY_FLAGS,
+    SYSCALL_SET_USER_ID,
+    SYSCALL_SLEEP,
+    SYSCALL_TERMINATE,
+    SYSCALL_TERMINATE_THREAD,
+    SYSCALL_UNCOMMIT_MEMORY,
+    SYSCALL_UNMOUNT,
+    SYSCALL_WAIT_PROCESS,
+    SYSCALL_WAIT_SEMAPHORE,
+    SYSCALL_WAIT_THREAD,
+    SYSCALL_WRITE_FILE,
+    SYSCALL_WRITE_MEMORY,
+    SYSCALL_WRITE_PIPE,
+    SYSCALL_YIELD_QUANTUM,
+
+    SERVICE_COUNT
+} syscall_number_t;
+
+typedef enum
+{
+    KERNEL_MODE = 0,
+    USER_MODE = 1
+} processor_mode_t;
+
+char *copy_user_string(const char *string);
+processor_mode_t get_previous_mode();
+bool_t check_usermode(const void *pointer, dword_t size);
+qword_t syscall(dword_t num, ...);
+void syscalls_init();
+
+#endif

+ 155 - 0
kernel/include/thread.h

@@ -0,0 +1,155 @@
+/*
+ * thread.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _THREAD_H_
+#define _THREAD_H_
+
+#include <common.h>
+#include <object.h>
+#include <exception.h>
+#include <list.h>
+#include <sync.h>
+#include <interrupt.h>
+#include <syscalls.h>
+
+#define QUANTUM 30
+#define MAX_THREADS 2097152
+#define KERNEL_STACK_SIZE 262144
+
+#define THREAD_CREATE_FROZEN (1 << 0)
+
+#define SAFE_EFLAGS_MASK 0x00000CD5
+
+typedef dword_t (*thread_procedure_t)(void*);
+typedef dword_t priority_t;
+typedef qword_t affinity_t;
+
+typedef enum
+{
+    THREAD_TID_INFO,
+    THREAD_FROZEN_INFO,
+    THREAD_CPU_STATE_INFO,
+    THREAD_PRIORITY_INFO,
+    THREAD_AFFINITY_INFO,
+} thread_info_t;
+
+typedef enum
+{
+    WAIT_NEVER,
+    WAIT_ALWAYS,
+    WAIT_UNTIL_EQUAL,
+    WAIT_UNTIL_NOT_EQUAL,
+    WAIT_UNTIL_LESS,
+    WAIT_UNTIL_NOT_LESS,
+    WAIT_UNTIL_GREATER,
+    WAIT_UNTIL_NOT_GREATER
+} wait_condition_t;
+
+typedef enum
+{
+    WAIT_TIMED_OUT,
+    WAIT_CONDITION_HIT,
+    WAIT_CANCELED
+} wait_result_t;
+
+enum
+{
+    THREAD_PRIORITY_HIGH,
+    THREAD_PRIORITY_MID,
+    THREAD_PRIORITY_LOW,
+    THREAD_PRIORITY_IDLE,
+
+    THREAD_PRIORITY_MAX
+};
+
+typedef struct
+{
+    registers_t regs;
+    byte_t fpu_state[512];
+} thread_state_t;
+
+#ifndef PROCESS_TYPEDEF
+#define PROCESS_TYPEDEF
+typedef struct process process_t;
+#endif
+
+struct thread
+{
+    object_t header;
+    list_entry_t in_queue_list;
+    list_entry_t in_process_list;
+    dword_t tid;
+    priority_t priority;
+    dword_t affinity;
+    thread_state_t state;
+    dword_t exit_code;
+    dword_t quantum;
+    qword_t running_ticks;
+    process_t *owner_process;
+    dword_t terminated;
+    int32_t frozen;
+
+    void *kernel_stack;
+    uintptr_t kernel_esp;
+
+    lock_t syscall_lock;
+    registers_t *syscall_regs;
+    bool_t cancel_io;
+    processor_mode_t previous_mode;
+
+    wait_condition_t wait_condition;
+    wait_result_t wait_result;
+    qword_t wait_timestamp;
+    dword_t wait_timeout;
+    dword_t *wait_pointer;
+    dword_t wait_value;
+
+    exception_handler_t kernel_handler;
+    exception_info_t kernel_exception_info;
+    exception_handler_t user_handler;
+    exception_info_t user_exception_info;
+};
+
+#ifndef THREAD_TYPEDEF
+#define THREAD_TYPEDEF
+typedef struct thread thread_t;
+#endif
+
+extern bool_t scheduler_enabled;
+
+thread_t *get_current_thread();
+dword_t get_thread_id();
+dword_t open_thread(dword_t tid, handle_t *handle);
+dword_t create_thread_internal(process_t *proc, thread_state_t *initial_state, dword_t flags, priority_t priority, void *kernel_stack, thread_t **new_thread);
+dword_t create_thread(handle_t process, thread_state_t *initial_state, dword_t flags, priority_t priority, handle_t *new_thread);
+dword_t terminate_thread_internal(thread_t *thread, dword_t return_value);
+dword_t terminate_thread(handle_t thread, dword_t return_value);
+dword_t freeze_thread(handle_t handle);
+dword_t thaw_thread(handle_t handle);
+void scheduler(registers_t *regs);
+wait_result_t scheduler_wait(wait_condition_t condition, dword_t timeout, uintptr_t *pointer, uintptr_t value);
+void sleep(qword_t milliseconds);
+void yield_quantum();
+dword_t query_thread(handle_t handle, thread_info_t info_type, void *buffer, size_t size);
+dword_t set_thread(handle_t handle, thread_info_t info_type, const void *buffer, size_t size);
+dword_t wait_thread(handle_t handle, dword_t timeout);
+dword_t create_system_thread(thread_procedure_t routine, dword_t flags, priority_t priority, dword_t stack_size, void *param, thread_t **new_thread);
+void thread_init(void);
+
+#endif

+ 38 - 0
kernel/include/timer.h

@@ -0,0 +1,38 @@
+/*
+ * timer.h
+ * 
+ * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _TIMER_H_
+#define _TIMER_H_
+
+#include <irq.h>
+
+#define TIMER_IRQ 0
+#define TIMER_CHANNEL_PORT(x) (0x40 + (x))
+#define TIMER_CMD_PORT 0x43
+#define TIMER_FREQUENCY 1000
+#define TIMER_BASE_FREQUENCY 1193182
+
+#define TIMER_RATE_GENERATOR(x) (((x) << 6) | 0x34)
+#define TIMER_SQUARE_WAVE(x) (((x) << 6) | 0x36)
+
+qword_t get_milliseconds(void);
+qword_t get_nanoseconds(void);
+void timer_init(void);
+
+#endif

+ 123 - 0
kernel/include/user.h

@@ -0,0 +1,123 @@
+/*
+ * user.h
+ * 
+ * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _USER_H_
+#define _USER_H_
+
+#include <common.h>
+#include <list.h>
+
+#define MAX_USERNAME_LENGTH 32
+#define LOGIN_ATTEMPT_TIMEOUT 3000
+
+#define PRIVILEGE_LOGON_USER       (1ULL << 0)
+#define PRIVILEGE_NETWORK_ACCESS   (1ULL << 1)
+#define PRIVILEGE_MOUNT_UNMOUNT    (1ULL << 2)
+#define PRIVILEGE_UNNAMED3         (1ULL << 3)
+#define PRIVILEGE_UNNAMED4         (1ULL << 4)
+#define PRIVILEGE_UNNAMED5         (1ULL << 5)
+#define PRIVILEGE_UNNAMED6         (1ULL << 6)
+#define PRIVILEGE_UNNAMED7         (1ULL << 7)
+#define PRIVILEGE_UNNAMED8         (1ULL << 8)
+#define PRIVILEGE_UNNAMED9         (1ULL << 9)
+#define PRIVILEGE_UNNAMED10        (1ULL << 10)
+#define PRIVILEGE_UNNAMED11        (1ULL << 11)
+#define PRIVILEGE_UNNAMED12        (1ULL << 12)
+#define PRIVILEGE_UNNAMED13        (1ULL << 13)
+#define PRIVILEGE_UNNAMED14        (1ULL << 14)
+#define PRIVILEGE_UNNAMED15        (1ULL << 15)
+#define PRIVILEGE_UNNAMED16        (1ULL << 16)
+#define PRIVILEGE_UNNAMED17        (1ULL << 17)
+#define PRIVILEGE_UNNAMED18        (1ULL << 18)
+#define PRIVILEGE_UNNAMED19        (1ULL << 19)
+#define PRIVILEGE_UNNAMED20        (1ULL << 20)
+#define PRIVILEGE_UNNAMED21        (1ULL << 21)
+#define PRIVILEGE_UNNAMED22        (1ULL << 22)
+#define PRIVILEGE_UNNAMED23        (1ULL << 23)
+#define PRIVILEGE_UNNAMED24        (1ULL << 24)
+#define PRIVILEGE_UNNAMED25        (1ULL << 25)
+#define PRIVILEGE_UNNAMED26        (1ULL << 26)
+#define PRIVILEGE_UNNAMED27        (1ULL << 27)
+#define PRIVILEGE_UNNAMED28        (1ULL << 28)
+#define PRIVILEGE_UNNAMED29        (1ULL << 29)
+#define PRIVILEGE_UNNAMED30        (1ULL << 30)
+#define PRIVILEGE_SET_TIME         (1ULL << 31)
+#define PRIVILEGE_CHARACTER_DEVICE (1ULL << 32)
+#define PRIVILEGE_BLOCK_DEVICE     (1ULL << 33)
+#define PRIVILEGE_UNNAMED34        (1ULL << 34)
+#define PRIVILEGE_UNNAMED35        (1ULL << 35)
+#define PRIVILEGE_UNNAMED36        (1ULL << 36)
+#define PRIVILEGE_UNNAMED37        (1ULL << 37)
+#define PRIVILEGE_UNNAMED38        (1ULL << 38)
+#define PRIVILEGE_UNNAMED39        (1ULL << 39)
+#define PRIVILEGE_UNNAMED40        (1ULL << 40)
+#define PRIVILEGE_UNNAMED41        (1ULL << 41)
+#define PRIVILEGE_UNNAMED42        (1ULL << 42)
+#define PRIVILEGE_UNNAMED43        (1ULL << 43)
+#define PRIVILEGE_UNNAMED44        (1ULL << 44)
+#define PRIVILEGE_UNNAMED45        (1ULL << 45)
+#define PRIVILEGE_UNNAMED46        (1ULL << 46)
+#define PRIVILEGE_UNNAMED47        (1ULL << 47)
+#define PRIVILEGE_UNNAMED48        (1ULL << 48)
+#define PRIVILEGE_UNNAMED49        (1ULL << 49)
+#define PRIVILEGE_UNNAMED50        (1ULL << 50)
+#define PRIVILEGE_UNNAMED51        (1ULL << 51)
+#define PRIVILEGE_UNNAMED52        (1ULL << 52)
+#define PRIVILEGE_UNNAMED53        (1ULL << 53)
+#define PRIVILEGE_UNNAMED54        (1ULL << 54)
+#define PRIVILEGE_UNNAMED55        (1ULL << 55)
+#define PRIVILEGE_UNNAMED56        (1ULL << 56)
+#define PRIVILEGE_UNNAMED57        (1ULL << 57)
+#define PRIVILEGE_UNNAMED58        (1ULL << 58)
+#define PRIVILEGE_MANAGE_USERS     (1ULL << 59)
+#define PRIVILEGE_PROCESS_CONTROL  (1ULL << 60)
+#define PRIVILEGE_SET_PAGE_FILE    (1ULL << 61)
+#define PRIVILEGE_POWER_CONTROL    (1ULL << 62)
+#define PRIVILEGE_CHANGE_UID       (1ULL << 63)
+
+#define ALL_PRIVILEGES 0xFFFFFFFFFFFFFFFFULL
+
+typedef struct
+{
+    list_entry_t list;
+    dword_t uid;
+    qword_t privileges;
+    char name[MAX_USERNAME_LENGTH];
+    dword_t password_hash[64];
+    qword_t last_login_attempt;
+} user_t;
+
+typedef enum
+{
+    USER_NAME_INFO,
+    USER_PRIVILEGE_INFO,
+} user_info_t;
+
+bool_t check_privileges(qword_t privilege_mask);
+dword_t create_user(dword_t uid, const char *name, dword_t *password_hash, qword_t privileges);
+dword_t delete_user(dword_t uid);
+dword_t get_user_id(void);
+dword_t set_user_id(dword_t uid);
+dword_t revert_user(void);
+dword_t logon_user(dword_t uid, const char *password);
+dword_t logoff_user(dword_t uid);
+dword_t query_user(dword_t uid, user_info_t, void *buffer, dword_t size);
+void user_init(void);
+
+#endif

+ 160 - 0
kernel/include/video.h

@@ -0,0 +1,160 @@
+/*
+ * video.h
+ * 
+ * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _VIDEO_H_
+#define _VIDEO_H_
+
+#include <common.h>
+#include <pci.h>
+#include <char_device.h>
+
+#define TEXT_HEIGHT 25
+#define TEXT_WIDTH 80
+#define VGA_AC_INDEX 0x3C0
+#define VGA_AC_WRITE 0x3C0
+#define VGA_AC_READ 0x3C1
+#define VGA_MISC_WRITE 0x3C2
+#define VGA_SEQ_INDEX 0x3C4
+#define VGA_SEQ_DATA 0x3C5
+#define VGA_DAC_READ_INDEX 0x3C7
+#define VGA_DEC_WRITE_INDEX 0x3C8
+#define VGA_DAC_DATA 0x3C9
+#define VGA_MISC_READ 0x3CC
+#define VGA_MISC_WRITE 0x3C2
+#define VGA_CRTC_INDEX 0x3D4
+#define VGA_CRTC_DATA 0x3D5
+#define VGA_GC_INDEX 0x3CE
+#define VGA_GC_DATA 0x3CF
+
+#define VIDEO_MODE_ALPHANUMERIC     (1 << 0)
+#define VIDEO_MODE_USES_PALETTE     (1 << 1)
+
+#define IOCTL_VIDEO_GET_MODE        0xC9000000
+#define IOCTL_VIDEO_SET_MODE        0xC9000001
+#define IOCTL_VIDEO_LIST_MODES      0xC9000002
+#define IOCTL_VIDEO_QUERY_MODE      0xC9000003
+#define IOCTL_VIDEO_MAP_FRAMEBUFFER 0xC9000004
+#define IOCTL_VIDEO_BITBLT          0xC9000005
+#define IOCTL_VIDEO_READ_PALETTE    0xC9000006
+#define IOCTL_VIDEO_WRITE_PALETTE   0xC9000007
+#define IOCTL_VIDEO_READ_FONT       0xC9000008
+#define IOCTL_VIDEO_WRITE_FONT      0xC9000009
+#define IOCTL_VIDEO_SET_TEXT_CURSOR 0xC900000A
+
+#define BITBLT_RESULT_INVERT        (1 << 2)
+#define BITBLT_SOURCE_INVERT        (1 << 3)
+#define BITBLT_DEST_INVERT          (1 << 4)
+#define BITBLT_SOURCE_ENABLED       (1 << 30)
+#define BITBLT_DEST_ENABLED         (1 << 31)
+
+enum
+{
+    BITBLT_OPERATION_NONE,
+    BITBLT_OPERATION_AND,
+    BITBLT_OPERATION_OR,
+    BITBLT_OPERATION_XOR,
+};
+
+typedef struct
+{
+    dword_t source_x;
+    dword_t source_y;
+    dword_t dest_x;
+    dword_t dest_y;
+    dword_t width;
+    dword_t height;
+    dword_t operation;
+} video_bitblt_parameters_t;
+
+typedef struct
+{
+    void *address;
+    uintptr_t offset;
+    size_t size;
+} video_map_framebuffer_t;
+
+typedef struct
+{
+    dword_t row;
+    dword_t column;
+} video_cursor_location_t;
+
+typedef struct video_device video_device_t;
+
+typedef dword_t (*video_init_proc_t)(list_entry_t *video_devices);
+typedef dword_t (*video_cleanup_proc_t)(void);
+
+typedef dword_t (*video_control_proc_t)(
+    video_device_t *device,
+    dword_t control_code,
+    const void *in_buffer,
+    size_t in_length,
+    void *out_buffer,
+    size_t out_length
+);
+
+typedef struct
+{
+    video_init_proc_t init_proc;
+    video_cleanup_proc_t cleanup_proc;
+    video_control_proc_t control_proc;
+} video_driver_t;
+
+typedef struct
+{
+    dword_t number;
+    dword_t flags;
+    dword_t width;
+    dword_t height;
+    dword_t bpp;
+    dword_t scanline_size;
+    uintptr_t framebuffer_phys;
+    byte_t red_mask_size;
+    byte_t red_field_pos;
+    byte_t green_mask_size;
+    byte_t green_field_pos;
+    byte_t blue_mask_size;
+    byte_t blue_field_pos;
+    byte_t reserved_mask_size;
+    byte_t reserved_field_pos;
+} video_mode_t;
+
+struct video_device
+{
+    char_device_t header;
+    list_entry_t list;
+    pci_device_t *pci_device;
+    video_driver_t *driver;
+    video_mode_t current_mode;
+};
+
+dword_t video_default_control(
+    video_device_t *device,
+    dword_t control_code,
+    const void *in_buffer,
+    size_t in_length,
+    void *out_buffer,
+    size_t out_length
+);
+
+dword_t register_video_driver(video_driver_t *driver);
+dword_t unregister_video_driver(video_driver_t *driver);
+void video_init();
+
+#endif

+ 60 - 0
kernel/include/vm86.h

@@ -0,0 +1,60 @@
+/*
+ * vm86.h
+ * 
+ * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _VM86_H_
+#define _VM86_H_
+
+#include <common.h>
+#include <thread.h>
+#include <interrupt.h>
+
+#define EFLAGS_VM (1<<17)
+#define EFLAGS_IF (1<<9)
+#define EFLAGS_DF (1<<10)
+#define PREFIX_LOCK (1<<0)
+#define PREFIX_OPSIZE (1<<1)
+#define PREFIX_ADDRSIZE (1<<2)
+#define PREFIX_REP (1<<3)
+#define PREFIX_REPNZ (1<<4)
+#define PREFIX_ES (1<<5)
+#define PREFIX_SS (1<<6)
+#define PREFIX_FS (1<<7)
+#define PREFIX_GS (1<<8)
+
+#define VM86_MEM_START 0x10000
+#define VM86_MEM_END 0x90000
+#define VM86_MEM_PARAGRAPHS ((VM86_MEM_END - VM86_MEM_START) >> 4)
+
+#define VM86_TRAMPOLINE_CS 0x0000
+#define VM86_TRAMPOLINE_IP 0xE000
+#define VM86_TRAMPOLINE_SS 0x0000
+#define VM86_TRAMPOLINE_SP 0xDFFA
+
+typedef struct
+{
+    dword_t edi, esi, ebp, unused, ebx, edx, ecx, eax;
+    dword_t eip, cs, eflags, esp, ss, es, ds, fs, gs;
+} vm86_registers_t;
+
+word_t vm86_alloc(word_t size);
+void vm86_free(word_t paragraph);
+void vm86_handler(registers_ext_vm86_t *regs);
+dword_t vm86_interrupt(byte_t number, vm86_registers_t *regs);
+
+#endif

+ 31 - 0
kernel/link.ld

@@ -0,0 +1,31 @@
+ENTRY(start)
+STARTUP(obj/boot/boot.o)
+
+SECTIONS
+{
+   . = 0x80000000;
+
+   .code : AT(ADDR(.code) - 0x7FF00000)
+   {
+       code = .; _code = .; __code = .;
+       *(.text)
+       . = ALIGN(4096);
+   }
+
+   .data : AT(ADDR(.data) - 0x7FF00000)
+   {
+       data = .; _data = .; __data = .;
+       *(.data)
+       *(.rodata)
+       . = ALIGN(4096);
+   }
+
+   .bss : AT(ADDR(.bss) - 0x7FF00000)
+   {
+       bss = .; _bss = .; __bss = .;
+       *(.bss)
+       . = ALIGN(4096);
+   }
+   
+   end = .; _end = .; __end = .;
+}

+ 438 - 0
kernel/src/acpica/dispatcher/dsargs.c

@@ -0,0 +1,438 @@
+/******************************************************************************
+ *
+ * Module Name: dsargs - Support for execution of dynamic arguments for static
+ *                       objects (regions, fields, buffer fields, etc.)
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acparser.h"
+#include "amlcode.h"
+#include "acdispat.h"
+#include "acnamesp.h"
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dsargs")
+
+/* Local prototypes */
+
+static ACPI_STATUS
+AcpiDsExecuteArguments (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_NAMESPACE_NODE     *ScopeNode,
+    UINT32                  AmlLength,
+    UINT8                   *AmlStart);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsExecuteArguments
+ *
+ * PARAMETERS:  Node                - Object NS node
+ *              ScopeNode           - Parent NS node
+ *              AmlLength           - Length of executable AML
+ *              AmlStart            - Pointer to the AML
+ *
+ * RETURN:      Status.
+ *
+ * DESCRIPTION: Late (deferred) execution of region or field arguments
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsExecuteArguments (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_NAMESPACE_NODE     *ScopeNode,
+    UINT32                  AmlLength,
+    UINT8                   *AmlStart)
+{
+    ACPI_STATUS             Status;
+    ACPI_PARSE_OBJECT       *Op;
+    ACPI_WALK_STATE         *WalkState;
+
+
+    ACPI_FUNCTION_TRACE (DsExecuteArguments);
+
+
+    /* Allocate a new parser op to be the root of the parsed tree */
+
+    Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP, AmlStart);
+    if (!Op)
+    {
+        return_ACPI_STATUS (AE_NO_MEMORY);
+    }
+
+    /* Save the Node for use in AcpiPsParseAml */
+
+    Op->Common.Node = ScopeNode;
+
+    /* Create and initialize a new parser state */
+
+    WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
+    if (!WalkState)
+    {
+        Status = AE_NO_MEMORY;
+        goto Cleanup;
+    }
+
+    Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
+        AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
+    if (ACPI_FAILURE (Status))
+    {
+        AcpiDsDeleteWalkState (WalkState);
+        goto Cleanup;
+    }
+
+    /* Mark this parse as a deferred opcode */
+
+    WalkState->ParseFlags = ACPI_PARSE_DEFERRED_OP;
+    WalkState->DeferredNode = Node;
+
+    /* Pass1: Parse the entire declaration */
+
+    Status = AcpiPsParseAml (WalkState);
+    if (ACPI_FAILURE (Status))
+    {
+        goto Cleanup;
+    }
+
+    /* Get and init the Op created above */
+
+    Op->Common.Node = Node;
+    AcpiPsDeleteParseTree (Op);
+
+    /* Evaluate the deferred arguments */
+
+    Op = AcpiPsAllocOp (AML_INT_EVAL_SUBTREE_OP, AmlStart);
+    if (!Op)
+    {
+        return_ACPI_STATUS (AE_NO_MEMORY);
+    }
+
+    Op->Common.Node = ScopeNode;
+
+    /* Create and initialize a new parser state */
+
+    WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
+    if (!WalkState)
+    {
+        Status = AE_NO_MEMORY;
+        goto Cleanup;
+    }
+
+    /* Execute the opcode and arguments */
+
+    Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, AmlStart,
+        AmlLength, NULL, ACPI_IMODE_EXECUTE);
+    if (ACPI_FAILURE (Status))
+    {
+        AcpiDsDeleteWalkState (WalkState);
+        goto Cleanup;
+    }
+
+    /* Mark this execution as a deferred opcode */
+
+    WalkState->DeferredNode = Node;
+    Status = AcpiPsParseAml (WalkState);
+
+Cleanup:
+    AcpiPsDeleteParseTree (Op);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsGetBufferFieldArguments
+ *
+ * PARAMETERS:  ObjDesc         - A valid BufferField object
+ *
+ * RETURN:      Status.
+ *
+ * DESCRIPTION: Get BufferField Buffer and Index. This implements the late
+ *              evaluation of these field attributes.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsGetBufferFieldArguments (
+    ACPI_OPERAND_OBJECT     *ObjDesc)
+{
+    ACPI_OPERAND_OBJECT     *ExtraDesc;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsGetBufferFieldArguments, ObjDesc);
+
+
+    if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Get the AML pointer (method object) and BufferField node */
+
+    ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
+    Node = ObjDesc->BufferField.Node;
+
+    ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
+        ACPI_TYPE_BUFFER_FIELD, Node, NULL));
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BufferField Arg Init\n",
+        AcpiUtGetNodeName (Node)));
+
+    /* Execute the AML code for the TermArg arguments */
+
+    Status = AcpiDsExecuteArguments (Node, Node->Parent,
+        ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsGetBankFieldArguments
+ *
+ * PARAMETERS:  ObjDesc         - A valid BankField object
+ *
+ * RETURN:      Status.
+ *
+ * DESCRIPTION: Get BankField BankValue. This implements the late
+ *              evaluation of these field attributes.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsGetBankFieldArguments (
+    ACPI_OPERAND_OBJECT     *ObjDesc)
+{
+    ACPI_OPERAND_OBJECT     *ExtraDesc;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsGetBankFieldArguments, ObjDesc);
+
+
+    if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Get the AML pointer (method object) and BankField node */
+
+    ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
+    Node = ObjDesc->BankField.Node;
+
+    ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
+        ACPI_TYPE_LOCAL_BANK_FIELD, Node, NULL));
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] BankField Arg Init\n",
+        AcpiUtGetNodeName (Node)));
+
+    /* Execute the AML code for the TermArg arguments */
+
+    Status = AcpiDsExecuteArguments (Node, Node->Parent,
+        ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsGetBufferArguments
+ *
+ * PARAMETERS:  ObjDesc         - A valid Buffer object
+ *
+ * RETURN:      Status.
+ *
+ * DESCRIPTION: Get Buffer length and initializer byte list. This implements
+ *              the late evaluation of these attributes.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsGetBufferArguments (
+    ACPI_OPERAND_OBJECT     *ObjDesc)
+{
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsGetBufferArguments, ObjDesc);
+
+
+    if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Get the Buffer node */
+
+    Node = ObjDesc->Buffer.Node;
+    if (!Node)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "No pointer back to namespace node in buffer object %p",
+            ObjDesc));
+        return_ACPI_STATUS (AE_AML_INTERNAL);
+    }
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n"));
+
+    /* Execute the AML code for the TermArg arguments */
+
+    Status = AcpiDsExecuteArguments (Node, Node,
+        ObjDesc->Buffer.AmlLength, ObjDesc->Buffer.AmlStart);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsGetPackageArguments
+ *
+ * PARAMETERS:  ObjDesc         - A valid Package object
+ *
+ * RETURN:      Status.
+ *
+ * DESCRIPTION: Get Package length and initializer byte list. This implements
+ *              the late evaluation of these attributes.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsGetPackageArguments (
+    ACPI_OPERAND_OBJECT     *ObjDesc)
+{
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsGetPackageArguments, ObjDesc);
+
+
+    if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Get the Package node */
+
+    Node = ObjDesc->Package.Node;
+    if (!Node)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "No pointer back to namespace node in package %p", ObjDesc));
+        return_ACPI_STATUS (AE_AML_INTERNAL);
+    }
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n"));
+
+    /* Execute the AML code for the TermArg arguments */
+
+    Status = AcpiDsExecuteArguments (Node, Node,
+        ObjDesc->Package.AmlLength, ObjDesc->Package.AmlStart);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsGetRegionArguments
+ *
+ * PARAMETERS:  ObjDesc         - A valid region object
+ *
+ * RETURN:      Status.
+ *
+ * DESCRIPTION: Get region address and length. This implements the late
+ *              evaluation of these region attributes.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsGetRegionArguments (
+    ACPI_OPERAND_OBJECT     *ObjDesc)
+{
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_STATUS             Status;
+    ACPI_OPERAND_OBJECT     *ExtraDesc;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsGetRegionArguments, ObjDesc);
+
+
+    if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    ExtraDesc = AcpiNsGetSecondaryObject (ObjDesc);
+    if (!ExtraDesc)
+    {
+        return_ACPI_STATUS (AE_NOT_EXIST);
+    }
+
+    /* Get the Region node */
+
+    Node = ObjDesc->Region.Node;
+
+    ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
+        ACPI_TYPE_REGION, Node, NULL));
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+        "[%4.4s] OpRegion Arg Init at AML %p\n",
+        AcpiUtGetNodeName (Node), ExtraDesc->Extra.AmlStart));
+
+    /* Execute the argument AML */
+
+    Status = AcpiDsExecuteArguments (Node, ExtraDesc->Extra.ScopeNode,
+        ExtraDesc->Extra.AmlLength, ExtraDesc->Extra.AmlStart);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    Status = AcpiUtAddAddressRange (ObjDesc->Region.SpaceId,
+        ObjDesc->Region.Address, ObjDesc->Region.Length, Node);
+    return_ACPI_STATUS (Status);
+}

+ 417 - 0
kernel/src/acpica/dispatcher/dscontrol.c

@@ -0,0 +1,417 @@
+/******************************************************************************
+ *
+ * Module Name: dscontrol - Support for execution control opcodes -
+ *                          if/else/while/return
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "amlcode.h"
+#include "acdispat.h"
+#include "acinterp.h"
+#include "acdebug.h"
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dscontrol")
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsExecBeginControlOp
+ *
+ * PARAMETERS:  WalkList        - The list that owns the walk stack
+ *              Op              - The control Op
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Handles all control ops encountered during control method
+ *              execution.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsExecBeginControlOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op)
+{
+    ACPI_STATUS             Status = AE_OK;
+    ACPI_GENERIC_STATE      *ControlState;
+
+
+    ACPI_FUNCTION_NAME (DsExecBeginControlOp);
+
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n",
+        Op, Op->Common.AmlOpcode, WalkState));
+
+    switch (Op->Common.AmlOpcode)
+    {
+    case AML_WHILE_OP:
+        /*
+         * If this is an additional iteration of a while loop, continue.
+         * There is no need to allocate a new control state.
+         */
+        if (WalkState->ControlState)
+        {
+            if (WalkState->ControlState->Control.AmlPredicateStart ==
+                (WalkState->ParserState.Aml - 1))
+            {
+                /* Reset the state to start-of-loop */
+
+                WalkState->ControlState->Common.State =
+                    ACPI_CONTROL_CONDITIONAL_EXECUTING;
+                break;
+            }
+        }
+
+        /*lint -fallthrough */
+
+    case AML_IF_OP:
+        /*
+         * IF/WHILE: Create a new control state to manage these
+         * constructs. We need to manage these as a stack, in order
+         * to handle nesting.
+         */
+        ControlState = AcpiUtCreateControlState ();
+        if (!ControlState)
+        {
+            Status = AE_NO_MEMORY;
+            break;
+        }
+        /*
+         * Save a pointer to the predicate for multiple executions
+         * of a loop
+         */
+        ControlState->Control.AmlPredicateStart =
+            WalkState->ParserState.Aml - 1;
+        ControlState->Control.PackageEnd =
+            WalkState->ParserState.PkgEnd;
+        ControlState->Control.Opcode =
+            Op->Common.AmlOpcode;
+
+
+        /* Push the control state on this walk's control stack */
+
+        AcpiUtPushGenericState (&WalkState->ControlState, ControlState);
+        break;
+
+    case AML_ELSE_OP:
+
+        /* Predicate is in the state object */
+        /* If predicate is true, the IF was executed, ignore ELSE part */
+
+        if (WalkState->LastPredicate)
+        {
+            Status = AE_CTRL_TRUE;
+        }
+
+        break;
+
+    case AML_RETURN_OP:
+
+        break;
+
+    default:
+
+        break;
+    }
+
+    return (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsExecEndControlOp
+ *
+ * PARAMETERS:  WalkList        - The list that owns the walk stack
+ *              Op              - The control Op
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Handles all control ops encountered during control method
+ *              execution.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsExecEndControlOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op)
+{
+    ACPI_STATUS             Status = AE_OK;
+    ACPI_GENERIC_STATE      *ControlState;
+
+
+    ACPI_FUNCTION_NAME (DsExecEndControlOp);
+
+
+    switch (Op->Common.AmlOpcode)
+    {
+    case AML_IF_OP:
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", Op));
+
+        /*
+         * Save the result of the predicate in case there is an
+         * ELSE to come
+         */
+        WalkState->LastPredicate =
+            (BOOLEAN) WalkState->ControlState->Common.Value;
+
+        /*
+         * Pop the control state that was created at the start
+         * of the IF and free it
+         */
+        ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
+        AcpiUtDeleteGenericState (ControlState);
+        break;
+
+    case AML_ELSE_OP:
+
+        break;
+
+    case AML_WHILE_OP:
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", Op));
+
+        ControlState = WalkState->ControlState;
+        if (ControlState->Common.Value)
+        {
+            /* Predicate was true, the body of the loop was just executed */
+
+            /*
+             * This loop counter mechanism allows the interpreter to escape
+             * possibly infinite loops. This can occur in poorly written AML
+             * when the hardware does not respond within a while loop and the
+             * loop does not implement a timeout.
+             */
+            ControlState->Control.LoopCount++;
+            if (ControlState->Control.LoopCount > AcpiGbl_MaxLoopIterations)
+            {
+                Status = AE_AML_INFINITE_LOOP;
+                break;
+            }
+
+            /*
+             * Go back and evaluate the predicate and maybe execute the loop
+             * another time
+             */
+            Status = AE_CTRL_PENDING;
+            WalkState->AmlLastWhile =
+                ControlState->Control.AmlPredicateStart;
+            break;
+        }
+
+        /* Predicate was false, terminate this while loop */
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "[WHILE_OP] termination! Op=%p\n",Op));
+
+        /* Pop this control state and free it */
+
+        ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
+        AcpiUtDeleteGenericState (ControlState);
+        break;
+
+    case AML_RETURN_OP:
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "[RETURN_OP] Op=%p Arg=%p\n",Op, Op->Common.Value.Arg));
+
+        /*
+         * One optional operand -- the return value
+         * It can be either an immediate operand or a result that
+         * has been bubbled up the tree
+         */
+        if (Op->Common.Value.Arg)
+        {
+            /* Since we have a real Return(), delete any implicit return */
+
+            AcpiDsClearImplicitReturn (WalkState);
+
+            /* Return statement has an immediate operand */
+
+            Status = AcpiDsCreateOperands (WalkState, Op->Common.Value.Arg);
+            if (ACPI_FAILURE (Status))
+            {
+                return (Status);
+            }
+
+            /*
+             * If value being returned is a Reference (such as
+             * an arg or local), resolve it now because it may
+             * cease to exist at the end of the method.
+             */
+            Status = AcpiExResolveToValue (
+                &WalkState->Operands [0], WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                return (Status);
+            }
+
+            /*
+             * Get the return value and save as the last result
+             * value. This is the only place where WalkState->ReturnDesc
+             * is set to anything other than zero!
+             */
+            WalkState->ReturnDesc = WalkState->Operands[0];
+        }
+        else if (WalkState->ResultCount)
+        {
+            /* Since we have a real Return(), delete any implicit return */
+
+            AcpiDsClearImplicitReturn (WalkState);
+
+            /*
+             * The return value has come from a previous calculation.
+             *
+             * If value being returned is a Reference (such as
+             * an arg or local), resolve it now because it may
+             * cease to exist at the end of the method.
+             *
+             * Allow references created by the Index operator to return
+             * unchanged.
+             */
+            if ((ACPI_GET_DESCRIPTOR_TYPE (WalkState->Results->Results.ObjDesc[0]) ==
+                    ACPI_DESC_TYPE_OPERAND) &&
+                ((WalkState->Results->Results.ObjDesc [0])->Common.Type ==
+                    ACPI_TYPE_LOCAL_REFERENCE) &&
+                ((WalkState->Results->Results.ObjDesc [0])->Reference.Class !=
+                    ACPI_REFCLASS_INDEX))
+            {
+                Status = AcpiExResolveToValue (
+                    &WalkState->Results->Results.ObjDesc [0], WalkState);
+                if (ACPI_FAILURE (Status))
+                {
+                    return (Status);
+                }
+            }
+
+            WalkState->ReturnDesc = WalkState->Results->Results.ObjDesc [0];
+        }
+        else
+        {
+            /* No return operand */
+
+            if (WalkState->NumOperands)
+            {
+                AcpiUtRemoveReference (WalkState->Operands [0]);
+            }
+
+            WalkState->Operands[0] = NULL;
+            WalkState->NumOperands = 0;
+            WalkState->ReturnDesc = NULL;
+        }
+
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "Completed RETURN_OP State=%p, RetVal=%p\n",
+            WalkState, WalkState->ReturnDesc));
+
+        /* End the control method execution right now */
+
+        Status = AE_CTRL_TERMINATE;
+        break;
+
+    case AML_NOOP_OP:
+
+        /* Just do nothing! */
+
+        break;
+
+    case AML_BREAK_POINT_OP:
+
+        AcpiDbSignalBreakPoint (WalkState);
+
+        /* Call to the OSL in case OS wants a piece of the action */
+
+        Status = AcpiOsSignal (ACPI_SIGNAL_BREAKPOINT,
+            "Executed AML Breakpoint opcode");
+        break;
+
+    case AML_BREAK_OP:
+    case AML_CONTINUE_OP: /* ACPI 2.0 */
+
+        /* Pop and delete control states until we find a while */
+
+        while (WalkState->ControlState &&
+                (WalkState->ControlState->Control.Opcode != AML_WHILE_OP))
+        {
+            ControlState = AcpiUtPopGenericState (&WalkState->ControlState);
+            AcpiUtDeleteGenericState (ControlState);
+        }
+
+        /* No while found? */
+
+        if (!WalkState->ControlState)
+        {
+            return (AE_AML_NO_WHILE);
+        }
+
+        /* Was: WalkState->AmlLastWhile = WalkState->ControlState->Control.AmlPredicateStart; */
+
+        WalkState->AmlLastWhile =
+            WalkState->ControlState->Control.PackageEnd;
+
+        /* Return status depending on opcode */
+
+        if (Op->Common.AmlOpcode == AML_BREAK_OP)
+        {
+            Status = AE_CTRL_BREAK;
+        }
+        else
+        {
+            Status = AE_CTRL_CONTINUE;
+        }
+        break;
+
+    default:
+
+        ACPI_ERROR ((AE_INFO, "Unknown control opcode=0x%X Op=%p",
+            Op->Common.AmlOpcode, Op));
+
+        Status = AE_AML_BAD_OPCODE;
+        break;
+    }
+
+    return (Status);
+}

+ 250 - 0
kernel/src/acpica/dispatcher/dsdebug.c

@@ -0,0 +1,250 @@
+/******************************************************************************
+ *
+ * Module Name: dsdebug - Parser/Interpreter interface - debugging
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acdispat.h"
+#include "acnamesp.h"
+#include "acdisasm.h"
+#include "acinterp.h"
+
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dsdebug")
+
+
+#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
+
+/* Local prototypes */
+
+static void
+AcpiDsPrintNodePathname (
+    ACPI_NAMESPACE_NODE     *Node,
+    const char              *Message);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsPrintNodePathname
+ *
+ * PARAMETERS:  Node            - Object
+ *              Message         - Prefix message
+ *
+ * DESCRIPTION: Print an object's full namespace pathname
+ *              Manages allocation/freeing of a pathname buffer
+ *
+ ******************************************************************************/
+
+static void
+AcpiDsPrintNodePathname (
+    ACPI_NAMESPACE_NODE     *Node,
+    const char              *Message)
+{
+    ACPI_BUFFER             Buffer;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE (DsPrintNodePathname);
+
+    if (!Node)
+    {
+        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "[NULL NAME]"));
+        return_VOID;
+    }
+
+    /* Convert handle to full pathname and print it (with supplied message) */
+
+    Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
+
+    Status = AcpiNsHandleToPathname (Node, &Buffer, TRUE);
+    if (ACPI_SUCCESS (Status))
+    {
+        if (Message)
+        {
+            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "%s ", Message));
+        }
+
+        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "[%s] (Node %p)",
+            (char *) Buffer.Pointer, Node));
+        ACPI_FREE (Buffer.Pointer);
+    }
+
+    return_VOID;
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsDumpMethodStack
+ *
+ * PARAMETERS:  Status          - Method execution status
+ *              WalkState       - Current state of the parse tree walk
+ *              Op              - Executing parse op
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Called when a method has been aborted because of an error.
+ *              Dumps the method execution stack.
+ *
+ ******************************************************************************/
+
+void
+AcpiDsDumpMethodStack (
+    ACPI_STATUS             Status,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op)
+{
+    ACPI_PARSE_OBJECT       *Next;
+    ACPI_THREAD_STATE       *Thread;
+    ACPI_WALK_STATE         *NextWalkState;
+    ACPI_NAMESPACE_NODE     *PreviousMethod = NULL;
+    ACPI_OPERAND_OBJECT     *MethodDesc;
+
+
+    ACPI_FUNCTION_TRACE (DsDumpMethodStack);
+
+    /* Ignore control codes, they are not errors */
+
+    if ((Status & AE_CODE_MASK) == AE_CODE_CONTROL)
+    {
+        return_VOID;
+    }
+
+    /* We may be executing a deferred opcode */
+
+    if (WalkState->DeferredNode)
+    {
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "Executing subtree for Buffer/Package/Region\n"));
+        return_VOID;
+    }
+
+    /*
+     * If there is no Thread, we are not actually executing a method.
+     * This can happen when the iASL compiler calls the interpreter
+     * to perform constant folding.
+     */
+    Thread = WalkState->Thread;
+    if (!Thread)
+    {
+        return_VOID;
+    }
+
+    /* Display exception and method name */
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "\n**** Exception %s during execution of method ",
+        AcpiFormatException (Status)));
+
+    AcpiDsPrintNodePathname (WalkState->MethodNode, NULL);
+
+    /* Display stack of executing methods */
+
+    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH,
+        "\n\nMethod Execution Stack:\n"));
+    NextWalkState = Thread->WalkStateList;
+
+    /* Walk list of linked walk states */
+
+    while (NextWalkState)
+    {
+        MethodDesc = NextWalkState->MethodDesc;
+        if (MethodDesc)
+        {
+            AcpiExStopTraceMethod (
+                (ACPI_NAMESPACE_NODE *) MethodDesc->Method.Node,
+                MethodDesc, WalkState);
+        }
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "    Method [%4.4s] executing: ",
+            AcpiUtGetNodeName (NextWalkState->MethodNode)));
+
+        /* First method is the currently executing method */
+
+        if (NextWalkState == WalkState)
+        {
+            if (Op)
+            {
+                /* Display currently executing ASL statement */
+
+                Next = Op->Common.Next;
+                Op->Common.Next = NULL;
+
+#ifdef ACPI_DISASSEMBLER
+                AcpiDmDisassemble (NextWalkState, Op, ACPI_UINT32_MAX);
+#endif
+                Op->Common.Next = Next;
+            }
+        }
+        else
+        {
+            /*
+             * This method has called another method
+             * NOTE: the method call parse subtree is already deleted at
+             * this point, so we cannot disassemble the method invocation.
+             */
+            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "Call to method "));
+            AcpiDsPrintNodePathname (PreviousMethod, NULL);
+        }
+
+        PreviousMethod = NextWalkState->MethodNode;
+        NextWalkState = NextWalkState->Next;
+        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DISPATCH, "\n"));
+    }
+
+    return_VOID;
+}
+
+#else
+
+void
+AcpiDsDumpMethodStack (
+    ACPI_STATUS             Status,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op)
+{
+    return;
+}
+
+#endif

+ 839 - 0
kernel/src/acpica/dispatcher/dsfield.c

@@ -0,0 +1,839 @@
+/******************************************************************************
+ *
+ * Module Name: dsfield - Dispatcher field routines
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "amlcode.h"
+#include "acdispat.h"
+#include "acinterp.h"
+#include "acnamesp.h"
+#include "acparser.h"
+
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dsfield")
+
+/* Local prototypes */
+
+#ifdef ACPI_ASL_COMPILER
+#include "acdisasm.h"
+
+static ACPI_STATUS
+AcpiDsCreateExternalRegion (
+    ACPI_STATUS             LookupStatus,
+    ACPI_PARSE_OBJECT       *Op,
+    char                    *Path,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_NAMESPACE_NODE     **Node);
+#endif
+
+static ACPI_STATUS
+AcpiDsGetFieldNames (
+    ACPI_CREATE_FIELD_INFO  *Info,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Arg);
+
+
+#ifdef ACPI_ASL_COMPILER
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCreateExternalRegion (iASL Disassembler only)
+ *
+ * PARAMETERS:  LookupStatus    - Status from NsLookup operation
+ *              Op              - Op containing the Field definition and args
+ *              Path            - Pathname of the region
+ *  `           WalkState       - Current method state
+ *              Node            - Where the new region node is returned
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
+ *              region node/object.
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsCreateExternalRegion (
+    ACPI_STATUS             LookupStatus,
+    ACPI_PARSE_OBJECT       *Op,
+    char                    *Path,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_NAMESPACE_NODE     **Node)
+{
+    ACPI_STATUS             Status;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+
+
+    if (LookupStatus != AE_NOT_FOUND)
+    {
+        return (LookupStatus);
+    }
+
+    /*
+     * Table disassembly:
+     * OperationRegion not found. Generate an External for it, and
+     * insert the name into the namespace.
+     */
+    AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_REGION, 0, 0);
+
+    Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_REGION,
+       ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, Node);
+    if (ACPI_FAILURE (Status))
+    {
+        return (Status);
+    }
+
+    /* Must create and install a region object for the new node */
+
+    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
+    if (!ObjDesc)
+    {
+        return (AE_NO_MEMORY);
+    }
+
+    ObjDesc->Region.Node = *Node;
+    Status = AcpiNsAttachObject (*Node, ObjDesc, ACPI_TYPE_REGION);
+    return (Status);
+}
+#endif
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCreateBufferField
+ *
+ * PARAMETERS:  Op                  - Current parse op (CreateXXField)
+ *              WalkState           - Current state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Execute the CreateField operators:
+ *              CreateBitFieldOp,
+ *              CreateByteFieldOp,
+ *              CreateWordFieldOp,
+ *              CreateDwordFieldOp,
+ *              CreateQwordFieldOp,
+ *              CreateFieldOp       (all of which define a field in a buffer)
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsCreateBufferField (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_PARSE_OBJECT       *Arg;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_STATUS             Status;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
+    UINT32                  Flags;
+
+
+    ACPI_FUNCTION_TRACE (DsCreateBufferField);
+
+
+    /*
+     * Get the NameString argument (name of the new BufferField)
+     */
+    if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
+    {
+        /* For CreateField, name is the 4th argument */
+
+        Arg = AcpiPsGetArg (Op, 3);
+    }
+    else
+    {
+        /* For all other CreateXXXField operators, name is the 3rd argument */
+
+        Arg = AcpiPsGetArg (Op, 2);
+    }
+
+    if (!Arg)
+    {
+        return_ACPI_STATUS (AE_AML_NO_OPERAND);
+    }
+
+    if (WalkState->DeferredNode)
+    {
+        Node = WalkState->DeferredNode;
+        Status = AE_OK;
+    }
+    else
+    {
+        /* Execute flag should always be set when this function is entered */
+
+        if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
+        {
+            return_ACPI_STATUS (AE_AML_INTERNAL);
+        }
+
+        /* Creating new namespace node, should not already exist */
+
+        Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
+            ACPI_NS_ERROR_IF_FOUND;
+
+        /*
+         * Mark node temporary if we are executing a normal control
+         * method. (Don't mark if this is a module-level code method)
+         */
+        if (WalkState->MethodNode &&
+            !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
+        {
+            Flags |= ACPI_NS_TEMPORARY;
+        }
+
+        /* Enter the NameString into the namespace */
+
+        Status = AcpiNsLookup (WalkState->ScopeInfo,
+            Arg->Common.Value.String, ACPI_TYPE_ANY,
+            ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
+            return_ACPI_STATUS (Status);
+        }
+    }
+
+    /*
+     * We could put the returned object (Node) on the object stack for later,
+     * but for now, we will put it in the "op" object that the parser uses,
+     * so we can get it again at the end of this scope.
+     */
+    Op->Common.Node = Node;
+
+    /*
+     * If there is no object attached to the node, this node was just created
+     * and we need to create the field object. Otherwise, this was a lookup
+     * of an existing node and we don't want to create the field object again.
+     */
+    ObjDesc = AcpiNsGetAttachedObject (Node);
+    if (ObjDesc)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /*
+     * The Field definition is not fully parsed at this time.
+     * (We must save the address of the AML for the buffer and index operands)
+     */
+
+    /* Create the buffer field object */
+
+    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
+    if (!ObjDesc)
+    {
+        Status = AE_NO_MEMORY;
+        goto Cleanup;
+    }
+
+    /*
+     * Remember location in AML stream of the field unit opcode and operands
+     * -- since the buffer and index operands must be evaluated.
+     */
+    SecondDesc = ObjDesc->Common.NextObject;
+    SecondDesc->Extra.AmlStart = Op->Named.Data;
+    SecondDesc->Extra.AmlLength = Op->Named.Length;
+    ObjDesc->BufferField.Node = Node;
+
+    /* Attach constructed field descriptors to parent node */
+
+    Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
+    if (ACPI_FAILURE (Status))
+    {
+        goto Cleanup;
+    }
+
+
+Cleanup:
+
+    /* Remove local reference to the object */
+
+    AcpiUtRemoveReference (ObjDesc);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsGetFieldNames
+ *
+ * PARAMETERS:  Info            - CreateField info structure
+ *  `           WalkState       - Current method state
+ *              Arg             - First parser arg for the field name list
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Process all named fields in a field declaration. Names are
+ *              entered into the namespace.
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsGetFieldNames (
+    ACPI_CREATE_FIELD_INFO  *Info,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Arg)
+{
+    ACPI_STATUS             Status;
+    UINT64                  Position;
+    ACPI_PARSE_OBJECT       *Child;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);
+
+
+    /* First field starts at bit zero */
+
+    Info->FieldBitPosition = 0;
+
+    /* Process all elements in the field list (of parse nodes) */
+
+    while (Arg)
+    {
+        /*
+         * Four types of field elements are handled:
+         * 1) Name - Enters a new named field into the namespace
+         * 2) Offset - specifies a bit offset
+         * 3) AccessAs - changes the access mode/attributes
+         * 4) Connection - Associate a resource template with the field
+         */
+        switch (Arg->Common.AmlOpcode)
+        {
+        case AML_INT_RESERVEDFIELD_OP:
+
+            Position = (UINT64) Info->FieldBitPosition +
+                (UINT64) Arg->Common.Value.Size;
+
+            if (Position > ACPI_UINT32_MAX)
+            {
+                ACPI_ERROR ((AE_INFO,
+                    "Bit offset within field too large (> 0xFFFFFFFF)"));
+                return_ACPI_STATUS (AE_SUPPORT);
+            }
+
+            Info->FieldBitPosition = (UINT32) Position;
+            break;
+
+        case AML_INT_ACCESSFIELD_OP:
+        case AML_INT_EXTACCESSFIELD_OP:
+            /*
+             * Get new AccessType, AccessAttribute, and AccessLength fields
+             * -- to be used for all field units that follow, until the
+             * end-of-field or another AccessAs keyword is encountered.
+             * NOTE. These three bytes are encoded in the integer value
+             * of the parseop for convenience.
+             *
+             * In FieldFlags, preserve the flag bits other than the
+             * ACCESS_TYPE bits.
+             */
+
+            /* AccessType (ByteAcc, WordAcc, etc.) */
+
+            Info->FieldFlags = (UINT8)
+                ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
+                ((UINT8) ((UINT32) (Arg->Common.Value.Integer & 0x07))));
+
+            /* AccessAttribute (AttribQuick, AttribByte, etc.) */
+
+            Info->Attribute = (UINT8)
+                ((Arg->Common.Value.Integer >> 8) & 0xFF);
+
+            /* AccessLength (for serial/buffer protocols) */
+
+            Info->AccessLength = (UINT8)
+                ((Arg->Common.Value.Integer >> 16) & 0xFF);
+            break;
+
+        case AML_INT_CONNECTION_OP:
+            /*
+             * Clear any previous connection. New connection is used for all
+             * fields that follow, similar to AccessAs
+             */
+            Info->ResourceBuffer = NULL;
+            Info->ConnectionNode = NULL;
+            Info->PinNumberIndex = 0;
+
+            /*
+             * A Connection() is either an actual resource descriptor (buffer)
+             * or a named reference to a resource template
+             */
+            Child = Arg->Common.Value.Arg;
+            if (Child->Common.AmlOpcode == AML_INT_BYTELIST_OP)
+            {
+                Info->ResourceBuffer = Child->Named.Data;
+                Info->ResourceLength = (UINT16) Child->Named.Value.Integer;
+            }
+            else
+            {
+                /* Lookup the Connection() namepath, it should already exist */
+
+                Status = AcpiNsLookup (WalkState->ScopeInfo,
+                    Child->Common.Value.Name, ACPI_TYPE_ANY,
+                    ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
+                    WalkState, &Info->ConnectionNode);
+                if (ACPI_FAILURE (Status))
+                {
+                    ACPI_ERROR_NAMESPACE (Child->Common.Value.Name, Status);
+                    return_ACPI_STATUS (Status);
+                }
+            }
+            break;
+
+        case AML_INT_NAMEDFIELD_OP:
+
+            /* Lookup the name, it should already exist */
+
+            Status = AcpiNsLookup (WalkState->ScopeInfo,
+                (char *) &Arg->Named.Name, Info->FieldType,
+                ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
+                WalkState, &Info->FieldNode);
+            if (ACPI_FAILURE (Status))
+            {
+                ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
+                return_ACPI_STATUS (Status);
+            }
+            else
+            {
+                Arg->Common.Node = Info->FieldNode;
+                Info->FieldBitLength = Arg->Common.Value.Size;
+
+                /*
+                 * If there is no object attached to the node, this node was
+                 * just created and we need to create the field object.
+                 * Otherwise, this was a lookup of an existing node and we
+                 * don't want to create the field object again.
+                 */
+                if (!AcpiNsGetAttachedObject (Info->FieldNode))
+                {
+                    Status = AcpiExPrepFieldValue (Info);
+                    if (ACPI_FAILURE (Status))
+                    {
+                        return_ACPI_STATUS (Status);
+                    }
+                }
+            }
+
+            /* Keep track of bit position for the next field */
+
+            Position = (UINT64) Info->FieldBitPosition +
+                (UINT64) Arg->Common.Value.Size;
+
+            if (Position > ACPI_UINT32_MAX)
+            {
+                ACPI_ERROR ((AE_INFO,
+                    "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
+                    ACPI_CAST_PTR (char, &Info->FieldNode->Name)));
+                return_ACPI_STATUS (AE_SUPPORT);
+            }
+
+            Info->FieldBitPosition += Info->FieldBitLength;
+            Info->PinNumberIndex++; /* Index relative to previous Connection() */
+            break;
+
+        default:
+
+            ACPI_ERROR ((AE_INFO,
+                "Invalid opcode in field list: 0x%X",
+                Arg->Common.AmlOpcode));
+            return_ACPI_STATUS (AE_AML_BAD_OPCODE);
+        }
+
+        Arg = Arg->Common.Next;
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCreateField
+ *
+ * PARAMETERS:  Op              - Op containing the Field definition and args
+ *              RegionNode      - Object for the containing Operation Region
+ *  `           WalkState       - Current method state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Create a new field in the specified operation region
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsCreateField (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_NAMESPACE_NODE     *RegionNode,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status;
+    ACPI_PARSE_OBJECT       *Arg;
+    ACPI_CREATE_FIELD_INFO  Info;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);
+
+
+    /* First arg is the name of the parent OpRegion (must already exist) */
+
+    Arg = Op->Common.Value.Arg;
+
+    if (!RegionNode)
+    {
+        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
+            ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
+            ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
+#ifdef ACPI_ASL_COMPILER
+        Status = AcpiDsCreateExternalRegion (Status, Arg,
+            Arg->Common.Value.Name, WalkState, &RegionNode);
+#endif
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
+            return_ACPI_STATUS (Status);
+        }
+    }
+
+    memset (&Info, 0, sizeof (ACPI_CREATE_FIELD_INFO));
+
+    /* Second arg is the field flags */
+
+    Arg = Arg->Common.Next;
+    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
+    Info.Attribute = 0;
+
+    /* Each remaining arg is a Named Field */
+
+    Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
+    Info.RegionNode = RegionNode;
+
+    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsInitFieldObjects
+ *
+ * PARAMETERS:  Op              - Op containing the Field definition and args
+ *  `           WalkState       - Current method state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: For each "Field Unit" name in the argument list that is
+ *              part of the field declaration, enter the name into the
+ *              namespace.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsInitFieldObjects (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status;
+    ACPI_PARSE_OBJECT       *Arg = NULL;
+    ACPI_NAMESPACE_NODE     *Node;
+    UINT8                   Type = 0;
+    UINT32                  Flags;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);
+
+
+    /* Execute flag should always be set when this function is entered */
+
+    if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
+    {
+        if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)
+        {
+            /* BankField Op is deferred, just return OK */
+
+            return_ACPI_STATUS (AE_OK);
+        }
+
+        return_ACPI_STATUS (AE_AML_INTERNAL);
+    }
+
+    /*
+     * Get the FieldList argument for this opcode. This is the start of the
+     * list of field elements.
+     */
+    switch (WalkState->Opcode)
+    {
+    case AML_FIELD_OP:
+
+        Arg = AcpiPsGetArg (Op, 2);
+        Type = ACPI_TYPE_LOCAL_REGION_FIELD;
+        break;
+
+    case AML_BANK_FIELD_OP:
+
+        Arg = AcpiPsGetArg (Op, 4);
+        Type = ACPI_TYPE_LOCAL_BANK_FIELD;
+        break;
+
+    case AML_INDEX_FIELD_OP:
+
+        Arg = AcpiPsGetArg (Op, 3);
+        Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
+        break;
+
+    default:
+
+        return_ACPI_STATUS (AE_BAD_PARAMETER);
+    }
+
+    /* Creating new namespace node(s), should not already exist */
+
+    Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
+        ACPI_NS_ERROR_IF_FOUND;
+
+    /*
+     * Mark node(s) temporary if we are executing a normal control
+     * method. (Don't mark if this is a module-level code method)
+     */
+    if (WalkState->MethodNode &&
+        !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
+    {
+        Flags |= ACPI_NS_TEMPORARY;
+    }
+
+    /*
+     * Walk the list of entries in the FieldList
+     * Note: FieldList can be of zero length. In this case, Arg will be NULL.
+     */
+    while (Arg)
+    {
+        /*
+         * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
+         * in the field names in order to enter them into the namespace.
+         */
+        if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
+        {
+            Status = AcpiNsLookup (WalkState->ScopeInfo,
+                (char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,
+                Flags, WalkState, &Node);
+            if (ACPI_FAILURE (Status))
+            {
+                ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
+                if (Status != AE_ALREADY_EXISTS)
+                {
+                    return_ACPI_STATUS (Status);
+                }
+
+                /* Name already exists, just ignore this error */
+
+                Status = AE_OK;
+            }
+
+            Arg->Common.Node = Node;
+        }
+
+        /* Get the next field element in the list */
+
+        Arg = Arg->Common.Next;
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCreateBankField
+ *
+ * PARAMETERS:  Op              - Op containing the Field definition and args
+ *              RegionNode      - Object for the containing Operation Region
+ *              WalkState       - Current method state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Create a new bank field in the specified operation region
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsCreateBankField (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_NAMESPACE_NODE     *RegionNode,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status;
+    ACPI_PARSE_OBJECT       *Arg;
+    ACPI_CREATE_FIELD_INFO  Info;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);
+
+
+    /* First arg is the name of the parent OpRegion (must already exist) */
+
+    Arg = Op->Common.Value.Arg;
+    if (!RegionNode)
+    {
+        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
+            ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
+            ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
+#ifdef ACPI_ASL_COMPILER
+        Status = AcpiDsCreateExternalRegion (Status, Arg,
+            Arg->Common.Value.Name, WalkState, &RegionNode);
+#endif
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
+            return_ACPI_STATUS (Status);
+        }
+    }
+
+    /* Second arg is the Bank Register (Field) (must already exist) */
+
+    Arg = Arg->Common.Next;
+    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
+        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
+        ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
+        return_ACPI_STATUS (Status);
+    }
+
+    /*
+     * Third arg is the BankValue
+     * This arg is a TermArg, not a constant
+     * It will be evaluated later, by AcpiDsEvalBankFieldOperands
+     */
+    Arg = Arg->Common.Next;
+
+    /* Fourth arg is the field flags */
+
+    Arg = Arg->Common.Next;
+    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
+
+    /* Each remaining arg is a Named Field */
+
+    Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
+    Info.RegionNode = RegionNode;
+
+    /*
+     * Use Info.DataRegisterNode to store BankField Op
+     * It's safe because DataRegisterNode will never be used when create
+     * bank field \we store AmlStart and AmlLength in the BankField Op for
+     * late evaluation. Used in AcpiExPrepFieldValue(Info)
+     *
+     * TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like
+     * "void *ParentOp"?
+     */
+    Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;
+
+    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCreateIndexField
+ *
+ * PARAMETERS:  Op              - Op containing the Field definition and args
+ *              RegionNode      - Object for the containing Operation Region
+ *  `           WalkState       - Current method state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Create a new index field in the specified operation region
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsCreateIndexField (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_NAMESPACE_NODE     *RegionNode,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status;
+    ACPI_PARSE_OBJECT       *Arg;
+    ACPI_CREATE_FIELD_INFO  Info;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);
+
+
+    /* First arg is the name of the Index register (must already exist) */
+
+    Arg = Op->Common.Value.Arg;
+    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
+        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
+        ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Second arg is the data register (must already exist) */
+
+    Arg = Arg->Common.Next;
+    Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
+        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
+        ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Next arg is the field flags */
+
+    Arg = Arg->Common.Next;
+    Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
+
+    /* Each remaining arg is a Named Field */
+
+    Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
+    Info.RegionNode = RegionNode;
+
+    Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
+    return_ACPI_STATUS (Status);
+}

+ 280 - 0
kernel/src/acpica/dispatcher/dsinit.c

@@ -0,0 +1,280 @@
+/******************************************************************************
+ *
+ * Module Name: dsinit - Object initialization namespace walk
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acdispat.h"
+#include "acnamesp.h"
+#include "actables.h"
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dsinit")
+
+
+/* Local prototypes */
+
+static ACPI_STATUS
+AcpiDsInitOneObject (
+    ACPI_HANDLE             ObjHandle,
+    UINT32                  Level,
+    void                    *Context,
+    void                    **ReturnValue);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsInitOneObject
+ *
+ * PARAMETERS:  ObjHandle       - Node for the object
+ *              Level           - Current nesting level
+ *              Context         - Points to a init info struct
+ *              ReturnValue     - Not used
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
+ *              within the namespace.
+ *
+ *              Currently, the only objects that require initialization are:
+ *              1) Methods
+ *              2) Operation Regions
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsInitOneObject (
+    ACPI_HANDLE             ObjHandle,
+    UINT32                  Level,
+    void                    *Context,
+    void                    **ReturnValue)
+{
+    ACPI_INIT_WALK_INFO     *Info = (ACPI_INIT_WALK_INFO *) Context;
+    ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
+    ACPI_STATUS             Status;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+
+
+    ACPI_FUNCTION_ENTRY ();
+
+
+    /*
+     * We are only interested in NS nodes owned by the table that
+     * was just loaded
+     */
+    if (Node->OwnerId != Info->OwnerId)
+    {
+        return (AE_OK);
+    }
+
+    Info->ObjectCount++;
+
+    /* And even then, we are only interested in a few object types */
+
+    switch (AcpiNsGetType (ObjHandle))
+    {
+    case ACPI_TYPE_REGION:
+
+        Status = AcpiDsInitializeRegion (ObjHandle);
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_EXCEPTION ((AE_INFO, Status,
+                "During Region initialization %p [%4.4s]",
+                ObjHandle, AcpiUtGetNodeName (ObjHandle)));
+        }
+
+        Info->OpRegionCount++;
+        break;
+
+    case ACPI_TYPE_METHOD:
+        /*
+         * Auto-serialization support. We will examine each method that is
+         * NotSerialized to determine if it creates any Named objects. If
+         * it does, it will be marked serialized to prevent problems if
+         * the method is entered by two or more threads and an attempt is
+         * made to create the same named object twice -- which results in
+         * an AE_ALREADY_EXISTS exception and method abort.
+         */
+        Info->MethodCount++;
+        ObjDesc = AcpiNsGetAttachedObject (Node);
+        if (!ObjDesc)
+        {
+            break;
+        }
+
+        /* Ignore if already serialized */
+
+        if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
+        {
+            Info->SerialMethodCount++;
+            break;
+        }
+
+        if (AcpiGbl_AutoSerializeMethods)
+        {
+            /* Parse/scan method and serialize it if necessary */
+
+            AcpiDsAutoSerializeMethod (Node, ObjDesc);
+            if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
+            {
+                /* Method was just converted to Serialized */
+
+                Info->SerialMethodCount++;
+                Info->SerializedMethodCount++;
+                break;
+            }
+        }
+
+        Info->NonSerialMethodCount++;
+        break;
+
+    case ACPI_TYPE_DEVICE:
+
+        Info->DeviceCount++;
+        break;
+
+    default:
+
+        break;
+    }
+
+    /*
+     * We ignore errors from above, and always return OK, since
+     * we don't want to abort the walk on a single error.
+     */
+    return (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsInitializeObjects
+ *
+ * PARAMETERS:  TableDesc       - Descriptor for parent ACPI table
+ *              StartNode       - Root of subtree to be initialized.
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Walk the namespace starting at "StartNode" and perform any
+ *              necessary initialization on the objects found therein
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsInitializeObjects (
+    UINT32                  TableIndex,
+    ACPI_NAMESPACE_NODE     *StartNode)
+{
+    ACPI_STATUS             Status;
+    ACPI_INIT_WALK_INFO     Info;
+    ACPI_TABLE_HEADER       *Table;
+    ACPI_OWNER_ID           OwnerId;
+
+
+    ACPI_FUNCTION_TRACE (DsInitializeObjects);
+
+
+    Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "**** Starting initialization of namespace objects ****\n"));
+
+    /* Set all init info to zero */
+
+    memset (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
+
+    Info.OwnerId = OwnerId;
+    Info.TableIndex = TableIndex;
+
+    /* Walk entire namespace from the supplied root */
+
+    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /*
+     * We don't use AcpiWalkNamespace since we do not want to acquire
+     * the namespace reader lock.
+     */
+    Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, StartNode, ACPI_UINT32_MAX,
+        ACPI_NS_WALK_UNLOCK, AcpiDsInitOneObject, NULL, &Info, NULL);
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
+    }
+    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
+
+    Status = AcpiGetTableByIndex (TableIndex, &Table);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /* DSDT is always the first AML table */
+
+    if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
+    {
+        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
+            "\nInitializing Namespace objects:\n"));
+    }
+
+    /* Summary of objects initialized */
+
+    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
+        "Table [%4.4s: %-8.8s] (id %.2X) - %4u Objects with %3u Devices, "
+        "%3u Regions, %4u Methods (%u/%u/%u Serial/Non/Cvt)\n",
+        Table->Signature, Table->OemTableId, OwnerId, Info.ObjectCount,
+        Info.DeviceCount,Info.OpRegionCount, Info.MethodCount,
+        Info.SerialMethodCount, Info.NonSerialMethodCount,
+        Info.SerializedMethodCount));
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "%u Methods, %u Regions\n",
+        Info.MethodCount, Info.OpRegionCount));
+
+    return_ACPI_STATUS (AE_OK);
+}

+ 907 - 0
kernel/src/acpica/dispatcher/dsmethod.c

@@ -0,0 +1,907 @@
+/******************************************************************************
+ *
+ * Module Name: dsmethod - Parser/Interpreter interface - control method parsing
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acdispat.h"
+#include "acinterp.h"
+#include "acnamesp.h"
+#include "acparser.h"
+#include "amlcode.h"
+#include "acdebug.h"
+
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dsmethod")
+
+/* Local prototypes */
+
+static ACPI_STATUS
+AcpiDsDetectNamedOpcodes (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       **OutOp);
+
+static ACPI_STATUS
+AcpiDsCreateMethodMutex (
+    ACPI_OPERAND_OBJECT     *MethodDesc);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsAutoSerializeMethod
+ *
+ * PARAMETERS:  Node                        - Namespace Node of the method
+ *              ObjDesc                     - Method object attached to node
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Parse a control method AML to scan for control methods that
+ *              need serialization due to the creation of named objects.
+ *
+ * NOTE: It is a bit of overkill to mark all such methods serialized, since
+ * there is only a problem if the method actually blocks during execution.
+ * A blocking operation is, for example, a Sleep() operation, or any access
+ * to an operation region. However, it is probably not possible to easily
+ * detect whether a method will block or not, so we simply mark all suspicious
+ * methods as serialized.
+ *
+ * NOTE2: This code is essentially a generic routine for parsing a single
+ * control method.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsAutoSerializeMethod (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_OPERAND_OBJECT     *ObjDesc)
+{
+    ACPI_STATUS             Status;
+    ACPI_PARSE_OBJECT       *Op = NULL;
+    ACPI_WALK_STATE         *WalkState;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsAutoSerializeMethod, Node);
+
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
+        "Method auto-serialization parse [%4.4s] %p\n",
+        AcpiUtGetNodeName (Node), Node));
+
+    /* Create/Init a root op for the method parse tree */
+
+    Op = AcpiPsAllocOp (AML_METHOD_OP, ObjDesc->Method.AmlStart);
+    if (!Op)
+    {
+        return_ACPI_STATUS (AE_NO_MEMORY);
+    }
+
+    AcpiPsSetName (Op, Node->Name.Integer);
+    Op->Common.Node = Node;
+
+    /* Create and initialize a new walk state */
+
+    WalkState = AcpiDsCreateWalkState (Node->OwnerId, NULL, NULL, NULL);
+    if (!WalkState)
+    {
+        AcpiPsFreeOp (Op);
+        return_ACPI_STATUS (AE_NO_MEMORY);
+    }
+
+    Status = AcpiDsInitAmlWalk (WalkState, Op, Node,
+        ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength, NULL, 0);
+    if (ACPI_FAILURE (Status))
+    {
+        AcpiDsDeleteWalkState (WalkState);
+        AcpiPsFreeOp (Op);
+        return_ACPI_STATUS (Status);
+    }
+
+    WalkState->DescendingCallback = AcpiDsDetectNamedOpcodes;
+
+    /* Parse the method, scan for creation of named objects */
+
+    Status = AcpiPsParseAml (WalkState);
+
+    AcpiPsDeleteParseTree (Op);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsDetectNamedOpcodes
+ *
+ * PARAMETERS:  WalkState       - Current state of the parse tree walk
+ *              OutOp           - Unused, required for parser interface
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Descending callback used during the loading of ACPI tables.
+ *              Currently used to detect methods that must be marked serialized
+ *              in order to avoid problems with the creation of named objects.
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsDetectNamedOpcodes (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       **OutOp)
+{
+
+    ACPI_FUNCTION_NAME (AcpiDsDetectNamedOpcodes);
+
+
+    /* We are only interested in opcodes that create a new name */
+
+    if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_CREATE | AML_FIELD)))
+    {
+        return (AE_OK);
+    }
+
+    /*
+     * At this point, we know we have a Named object opcode.
+     * Mark the method as serialized. Later code will create a mutex for
+     * this method to enforce serialization.
+     *
+     * Note, ACPI_METHOD_IGNORE_SYNC_LEVEL flag means that we will ignore the
+     * Sync Level mechanism for this method, even though it is now serialized.
+     * Otherwise, there can be conflicts with existing ASL code that actually
+     * uses sync levels.
+     */
+    WalkState->MethodDesc->Method.SyncLevel = 0;
+    WalkState->MethodDesc->Method.InfoFlags |=
+        (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
+        "Method serialized [%4.4s] %p - [%s] (%4.4X)\n",
+        WalkState->MethodNode->Name.Ascii, WalkState->MethodNode,
+        WalkState->OpInfo->Name, WalkState->Opcode));
+
+    /* Abort the parse, no need to examine this method any further */
+
+    return (AE_CTRL_TERMINATE);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsMethodError
+ *
+ * PARAMETERS:  Status          - Execution status
+ *              WalkState       - Current state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Called on method error. Invoke the global exception handler if
+ *              present, dump the method data if the debugger is configured
+ *
+ *              Note: Allows the exception handler to change the status code
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsMethodError (
+    ACPI_STATUS             Status,
+    ACPI_WALK_STATE         *WalkState)
+{
+    UINT32                  AmlOffset;
+
+
+    ACPI_FUNCTION_ENTRY ();
+
+
+    /* Ignore AE_OK and control exception codes */
+
+    if (ACPI_SUCCESS (Status) ||
+        (Status & AE_CODE_CONTROL))
+    {
+        return (Status);
+    }
+
+    /* Invoke the global exception handler */
+
+    if (AcpiGbl_ExceptionHandler)
+    {
+        /* Exit the interpreter, allow handler to execute methods */
+
+        AcpiExExitInterpreter ();
+
+        /*
+         * Handler can map the exception code to anything it wants, including
+         * AE_OK, in which case the executing method will not be aborted.
+         */
+        AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml,
+            WalkState->ParserState.AmlStart);
+
+        Status = AcpiGbl_ExceptionHandler (Status,
+            WalkState->MethodNode ?
+                WalkState->MethodNode->Name.Integer : 0,
+            WalkState->Opcode, AmlOffset, NULL);
+        AcpiExEnterInterpreter ();
+    }
+
+    AcpiDsClearImplicitReturn (WalkState);
+
+    if (ACPI_FAILURE (Status))
+    {
+        AcpiDsDumpMethodStack (Status, WalkState, WalkState->Op);
+
+        /* Display method locals/args if debugger is present */
+
+#ifdef ACPI_DEBUGGER
+        AcpiDbDumpMethodInfo (Status, WalkState);
+#endif
+    }
+
+    return (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCreateMethodMutex
+ *
+ * PARAMETERS:  ObjDesc             - The method object
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Create a mutex object for a serialized control method
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsCreateMethodMutex (
+    ACPI_OPERAND_OBJECT     *MethodDesc)
+{
+    ACPI_OPERAND_OBJECT     *MutexDesc;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE (DsCreateMethodMutex);
+
+
+    /* Create the new mutex object */
+
+    MutexDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX);
+    if (!MutexDesc)
+    {
+        return_ACPI_STATUS (AE_NO_MEMORY);
+    }
+
+    /* Create the actual OS Mutex */
+
+    Status = AcpiOsCreateMutex (&MutexDesc->Mutex.OsMutex);
+    if (ACPI_FAILURE (Status))
+    {
+        AcpiUtDeleteObjectDesc (MutexDesc);
+        return_ACPI_STATUS (Status);
+    }
+
+    MutexDesc->Mutex.SyncLevel = MethodDesc->Method.SyncLevel;
+    MethodDesc->Method.Mutex = MutexDesc;
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsBeginMethodExecution
+ *
+ * PARAMETERS:  MethodNode          - Node of the method
+ *              ObjDesc             - The method object
+ *              WalkState           - current state, NULL if not yet executing
+ *                                    a method.
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Prepare a method for execution. Parses the method if necessary,
+ *              increments the thread count, and waits at the method semaphore
+ *              for clearance to execute.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsBeginMethodExecution (
+    ACPI_NAMESPACE_NODE     *MethodNode,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status = AE_OK;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsBeginMethodExecution, MethodNode);
+
+
+    if (!MethodNode)
+    {
+        return_ACPI_STATUS (AE_NULL_ENTRY);
+    }
+
+    AcpiExStartTraceMethod (MethodNode, ObjDesc, WalkState);
+
+    /* Prevent wraparound of thread count */
+
+    if (ObjDesc->Method.ThreadCount == ACPI_UINT8_MAX)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "Method reached maximum reentrancy limit (255)"));
+        return_ACPI_STATUS (AE_AML_METHOD_LIMIT);
+    }
+
+    /*
+     * If this method is serialized, we need to acquire the method mutex.
+     */
+    if (ObjDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED)
+    {
+        /*
+         * Create a mutex for the method if it is defined to be Serialized
+         * and a mutex has not already been created. We defer the mutex creation
+         * until a method is actually executed, to minimize the object count
+         */
+        if (!ObjDesc->Method.Mutex)
+        {
+            Status = AcpiDsCreateMethodMutex (ObjDesc);
+            if (ACPI_FAILURE (Status))
+            {
+                return_ACPI_STATUS (Status);
+            }
+        }
+
+        /*
+         * The CurrentSyncLevel (per-thread) must be less than or equal to
+         * the sync level of the method. This mechanism provides some
+         * deadlock prevention.
+         *
+         * If the method was auto-serialized, we just ignore the sync level
+         * mechanism, because auto-serialization of methods can interfere
+         * with ASL code that actually uses sync levels.
+         *
+         * Top-level method invocation has no walk state at this point
+         */
+        if (WalkState &&
+            (!(ObjDesc->Method.InfoFlags & ACPI_METHOD_IGNORE_SYNC_LEVEL)) &&
+            (WalkState->Thread->CurrentSyncLevel >
+                ObjDesc->Method.Mutex->Mutex.SyncLevel))
+        {
+            ACPI_ERROR ((AE_INFO,
+                "Cannot acquire Mutex for method [%4.4s]"
+                ", current SyncLevel is too large (%u)",
+                AcpiUtGetNodeName (MethodNode),
+                WalkState->Thread->CurrentSyncLevel));
+
+            return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
+        }
+
+        /*
+         * Obtain the method mutex if necessary. Do not acquire mutex for a
+         * recursive call.
+         */
+        if (!WalkState ||
+            !ObjDesc->Method.Mutex->Mutex.ThreadId ||
+            (WalkState->Thread->ThreadId !=
+                ObjDesc->Method.Mutex->Mutex.ThreadId))
+        {
+            /*
+             * Acquire the method mutex. This releases the interpreter if we
+             * block (and reacquires it before it returns)
+             */
+            Status = AcpiExSystemWaitMutex (
+                ObjDesc->Method.Mutex->Mutex.OsMutex, ACPI_WAIT_FOREVER);
+            if (ACPI_FAILURE (Status))
+            {
+                return_ACPI_STATUS (Status);
+            }
+
+            /* Update the mutex and walk info and save the original SyncLevel */
+
+            if (WalkState)
+            {
+                ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
+                    WalkState->Thread->CurrentSyncLevel;
+
+                ObjDesc->Method.Mutex->Mutex.ThreadId =
+                    WalkState->Thread->ThreadId;
+
+                /*
+                 * Update the current SyncLevel only if this is not an auto-
+                 * serialized method. In the auto case, we have to ignore
+                 * the sync level for the method mutex (created for the
+                 * auto-serialization) because we have no idea of what the
+                 * sync level should be. Therefore, just ignore it.
+                 */
+                if (!(ObjDesc->Method.InfoFlags &
+                    ACPI_METHOD_IGNORE_SYNC_LEVEL))
+                {
+                    WalkState->Thread->CurrentSyncLevel =
+                        ObjDesc->Method.SyncLevel;
+                }
+            }
+            else
+            {
+                ObjDesc->Method.Mutex->Mutex.OriginalSyncLevel =
+                    ObjDesc->Method.Mutex->Mutex.SyncLevel;
+            }
+        }
+
+        /* Always increase acquisition depth */
+
+        ObjDesc->Method.Mutex->Mutex.AcquisitionDepth++;
+    }
+
+    /*
+     * Allocate an Owner ID for this method, only if this is the first thread
+     * to begin concurrent execution. We only need one OwnerId, even if the
+     * method is invoked recursively.
+     */
+    if (!ObjDesc->Method.OwnerId)
+    {
+        Status = AcpiUtAllocateOwnerId (&ObjDesc->Method.OwnerId);
+        if (ACPI_FAILURE (Status))
+        {
+            goto Cleanup;
+        }
+    }
+
+    /*
+     * Increment the method parse tree thread count since it has been
+     * reentered one more time (even if it is the same thread)
+     */
+    ObjDesc->Method.ThreadCount++;
+    AcpiMethodCount++;
+    return_ACPI_STATUS (Status);
+
+
+Cleanup:
+    /* On error, must release the method mutex (if present) */
+
+    if (ObjDesc->Method.Mutex)
+    {
+        AcpiOsReleaseMutex (ObjDesc->Method.Mutex->Mutex.OsMutex);
+    }
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCallControlMethod
+ *
+ * PARAMETERS:  Thread              - Info for this thread
+ *              ThisWalkState       - Current walk state
+ *              Op                  - Current Op to be walked
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Transfer execution to a called control method
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsCallControlMethod (
+    ACPI_THREAD_STATE       *Thread,
+    ACPI_WALK_STATE         *ThisWalkState,
+    ACPI_PARSE_OBJECT       *Op)
+{
+    ACPI_STATUS             Status;
+    ACPI_NAMESPACE_NODE     *MethodNode;
+    ACPI_WALK_STATE         *NextWalkState = NULL;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_EVALUATE_INFO      *Info;
+    UINT32                  i;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsCallControlMethod, ThisWalkState);
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "Calling method %p, currentstate=%p\n",
+        ThisWalkState->PrevOp, ThisWalkState));
+
+    /*
+     * Get the namespace entry for the control method we are about to call
+     */
+    MethodNode = ThisWalkState->MethodCallNode;
+    if (!MethodNode)
+    {
+        return_ACPI_STATUS (AE_NULL_ENTRY);
+    }
+
+    ObjDesc = AcpiNsGetAttachedObject (MethodNode);
+    if (!ObjDesc)
+    {
+        return_ACPI_STATUS (AE_NULL_OBJECT);
+    }
+
+    /* Init for new method, possibly wait on method mutex */
+
+    Status = AcpiDsBeginMethodExecution (
+        MethodNode, ObjDesc, ThisWalkState);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Begin method parse/execution. Create a new walk state */
+
+    NextWalkState = AcpiDsCreateWalkState (
+        ObjDesc->Method.OwnerId, NULL, ObjDesc, Thread);
+    if (!NextWalkState)
+    {
+        Status = AE_NO_MEMORY;
+        goto Cleanup;
+    }
+
+    /*
+     * The resolved arguments were put on the previous walk state's operand
+     * stack. Operands on the previous walk state stack always
+     * start at index 0. Also, null terminate the list of arguments
+     */
+    ThisWalkState->Operands [ThisWalkState->NumOperands] = NULL;
+
+    /*
+     * Allocate and initialize the evaluation information block
+     * TBD: this is somewhat inefficient, should change interface to
+     * DsInitAmlWalk. For now, keeps this struct off the CPU stack
+     */
+    Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
+    if (!Info)
+    {
+        Status = AE_NO_MEMORY;
+        goto Cleanup;
+    }
+
+    Info->Parameters = &ThisWalkState->Operands[0];
+
+    Status = AcpiDsInitAmlWalk (NextWalkState, NULL, MethodNode,
+        ObjDesc->Method.AmlStart, ObjDesc->Method.AmlLength,
+        Info, ACPI_IMODE_EXECUTE);
+
+    ACPI_FREE (Info);
+    if (ACPI_FAILURE (Status))
+    {
+        goto Cleanup;
+    }
+
+    /*
+     * Delete the operands on the previous walkstate operand stack
+     * (they were copied to new objects)
+     */
+    for (i = 0; i < ObjDesc->Method.ParamCount; i++)
+    {
+        AcpiUtRemoveReference (ThisWalkState->Operands [i]);
+        ThisWalkState->Operands [i] = NULL;
+    }
+
+    /* Clear the operand stack */
+
+    ThisWalkState->NumOperands = 0;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "**** Begin nested execution of [%4.4s] **** WalkState=%p\n",
+        MethodNode->Name.Ascii, NextWalkState));
+
+    /* Invoke an internal method if necessary */
+
+    if (ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY)
+    {
+        Status = ObjDesc->Method.Dispatch.Implementation (NextWalkState);
+        if (Status == AE_OK)
+        {
+            Status = AE_CTRL_TERMINATE;
+        }
+    }
+
+    return_ACPI_STATUS (Status);
+
+
+Cleanup:
+
+    /* On error, we must terminate the method properly */
+
+    AcpiDsTerminateControlMethod (ObjDesc, NextWalkState);
+    AcpiDsDeleteWalkState (NextWalkState);
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsRestartControlMethod
+ *
+ * PARAMETERS:  WalkState           - State for preempted method (caller)
+ *              ReturnDesc          - Return value from the called method
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Restart a method that was preempted by another (nested) method
+ *              invocation. Handle the return value (if any) from the callee.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsRestartControlMethod (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OPERAND_OBJECT     *ReturnDesc)
+{
+    ACPI_STATUS             Status;
+    int                     SameAsImplicitReturn;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsRestartControlMethod, WalkState);
+
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "****Restart [%4.4s] Op %p ReturnValueFromCallee %p\n",
+        AcpiUtGetNodeName (WalkState->MethodNode),
+        WalkState->MethodCallOp, ReturnDesc));
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "    ReturnFromThisMethodUsed?=%X ResStack %p Walk %p\n",
+        WalkState->ReturnUsed,
+        WalkState->Results, WalkState));
+
+    /* Did the called method return a value? */
+
+    if (ReturnDesc)
+    {
+        /* Is the implicit return object the same as the return desc? */
+
+        SameAsImplicitReturn = (WalkState->ImplicitReturnObj == ReturnDesc);
+
+        /* Are we actually going to use the return value? */
+
+        if (WalkState->ReturnUsed)
+        {
+            /* Save the return value from the previous method */
+
+            Status = AcpiDsResultPush (ReturnDesc, WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                AcpiUtRemoveReference (ReturnDesc);
+                return_ACPI_STATUS (Status);
+            }
+
+            /*
+             * Save as THIS method's return value in case it is returned
+             * immediately to yet another method
+             */
+            WalkState->ReturnDesc = ReturnDesc;
+        }
+
+        /*
+         * The following code is the optional support for the so-called
+         * "implicit return". Some AML code assumes that the last value of the
+         * method is "implicitly" returned to the caller, in the absence of an
+         * explicit return value.
+         *
+         * Just save the last result of the method as the return value.
+         *
+         * NOTE: this is optional because the ASL language does not actually
+         * support this behavior.
+         */
+        else if (!AcpiDsDoImplicitReturn (ReturnDesc, WalkState, FALSE) ||
+                 SameAsImplicitReturn)
+        {
+            /*
+             * Delete the return value if it will not be used by the
+             * calling method or remove one reference if the explicit return
+             * is the same as the implicit return value.
+             */
+            AcpiUtRemoveReference (ReturnDesc);
+        }
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsTerminateControlMethod
+ *
+ * PARAMETERS:  MethodDesc          - Method object
+ *              WalkState           - State associated with the method
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Terminate a control method. Delete everything that the method
+ *              created, delete all locals and arguments, and delete the parse
+ *              tree if requested.
+ *
+ * MUTEX:       Interpreter is locked
+ *
+ ******************************************************************************/
+
+void
+AcpiDsTerminateControlMethod (
+    ACPI_OPERAND_OBJECT     *MethodDesc,
+    ACPI_WALK_STATE         *WalkState)
+{
+
+    ACPI_FUNCTION_TRACE_PTR (DsTerminateControlMethod, WalkState);
+
+
+    /* MethodDesc is required, WalkState is optional */
+
+    if (!MethodDesc)
+    {
+        return_VOID;
+    }
+
+    if (WalkState)
+    {
+        /* Delete all arguments and locals */
+
+        AcpiDsMethodDataDeleteAll (WalkState);
+
+        /*
+         * If method is serialized, release the mutex and restore the
+         * current sync level for this thread
+         */
+        if (MethodDesc->Method.Mutex)
+        {
+            /* Acquisition Depth handles recursive calls */
+
+            MethodDesc->Method.Mutex->Mutex.AcquisitionDepth--;
+            if (!MethodDesc->Method.Mutex->Mutex.AcquisitionDepth)
+            {
+                WalkState->Thread->CurrentSyncLevel =
+                    MethodDesc->Method.Mutex->Mutex.OriginalSyncLevel;
+
+                AcpiOsReleaseMutex (
+                    MethodDesc->Method.Mutex->Mutex.OsMutex);
+                MethodDesc->Method.Mutex->Mutex.ThreadId = 0;
+            }
+        }
+
+        /*
+         * Delete any namespace objects created anywhere within the
+         * namespace by the execution of this method. Unless:
+         * 1) This method is a module-level executable code method, in which
+         *    case we want make the objects permanent.
+         * 2) There are other threads executing the method, in which case we
+         *    will wait until the last thread has completed.
+         */
+        if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL) &&
+             (MethodDesc->Method.ThreadCount == 1))
+        {
+            /* Delete any direct children of (created by) this method */
+
+            AcpiNsDeleteNamespaceSubtree (WalkState->MethodNode);
+
+            /*
+             * Delete any objects that were created by this method
+             * elsewhere in the namespace (if any were created).
+             * Use of the ACPI_METHOD_MODIFIED_NAMESPACE optimizes the
+             * deletion such that we don't have to perform an entire
+             * namespace walk for every control method execution.
+             */
+            if (MethodDesc->Method.InfoFlags & ACPI_METHOD_MODIFIED_NAMESPACE)
+            {
+                AcpiNsDeleteNamespaceByOwner (MethodDesc->Method.OwnerId);
+                MethodDesc->Method.InfoFlags &=
+                    ~ACPI_METHOD_MODIFIED_NAMESPACE;
+            }
+        }
+    }
+
+    /* Decrement the thread count on the method */
+
+    if (MethodDesc->Method.ThreadCount)
+    {
+        MethodDesc->Method.ThreadCount--;
+    }
+    else
+    {
+        ACPI_ERROR ((AE_INFO,
+            "Invalid zero thread count in method"));
+    }
+
+    /* Are there any other threads currently executing this method? */
+
+    if (MethodDesc->Method.ThreadCount)
+    {
+        /*
+         * Additional threads. Do not release the OwnerId in this case,
+         * we immediately reuse it for the next thread executing this method
+         */
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "*** Completed execution of one thread, %u threads remaining\n",
+            MethodDesc->Method.ThreadCount));
+    }
+    else
+    {
+        /* This is the only executing thread for this method */
+
+        /*
+         * Support to dynamically change a method from NotSerialized to
+         * Serialized if it appears that the method is incorrectly written and
+         * does not support multiple thread execution. The best example of this
+         * is if such a method creates namespace objects and blocks. A second
+         * thread will fail with an AE_ALREADY_EXISTS exception.
+         *
+         * This code is here because we must wait until the last thread exits
+         * before marking the method as serialized.
+         */
+        if (MethodDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED_PENDING)
+        {
+            if (WalkState)
+            {
+                ACPI_INFO ((AE_INFO,
+                    "Marking method %4.4s as Serialized "
+                    "because of AE_ALREADY_EXISTS error",
+                    WalkState->MethodNode->Name.Ascii));
+            }
+
+            /*
+             * Method tried to create an object twice and was marked as
+             * "pending serialized". The probable cause is that the method
+             * cannot handle reentrancy.
+             *
+             * The method was created as NotSerialized, but it tried to create
+             * a named object and then blocked, causing the second thread
+             * entrance to begin and then fail. Workaround this problem by
+             * marking the method permanently as Serialized when the last
+             * thread exits here.
+             */
+            MethodDesc->Method.InfoFlags &=
+                ~ACPI_METHOD_SERIALIZED_PENDING;
+
+            MethodDesc->Method.InfoFlags |=
+                (ACPI_METHOD_SERIALIZED | ACPI_METHOD_IGNORE_SYNC_LEVEL);
+            MethodDesc->Method.SyncLevel = 0;
+        }
+
+        /* No more threads, we can free the OwnerId */
+
+        if (!(MethodDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL))
+        {
+            AcpiUtReleaseOwnerId (&MethodDesc->Method.OwnerId);
+        }
+    }
+
+    AcpiExStopTraceMethod ((ACPI_NAMESPACE_NODE *) MethodDesc->Method.Node,
+        MethodDesc, WalkState);
+
+    return_VOID;
+}

+ 777 - 0
kernel/src/acpica/dispatcher/dsmthdat.c

@@ -0,0 +1,777 @@
+/*******************************************************************************
+ *
+ * Module Name: dsmthdat - control method arguments and local variables
+ *
+ ******************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acdispat.h"
+#include "acnamesp.h"
+#include "acinterp.h"
+
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dsmthdat")
+
+/* Local prototypes */
+
+static void
+AcpiDsMethodDataDeleteValue (
+    UINT8                   Type,
+    UINT32                  Index,
+    ACPI_WALK_STATE         *WalkState);
+
+static ACPI_STATUS
+AcpiDsMethodDataSetValue (
+    UINT8                   Type,
+    UINT32                  Index,
+    ACPI_OPERAND_OBJECT     *Object,
+    ACPI_WALK_STATE         *WalkState);
+
+#ifdef ACPI_OBSOLETE_FUNCTIONS
+ACPI_OBJECT_TYPE
+AcpiDsMethodDataGetType (
+    UINT16                  Opcode,
+    UINT32                  Index,
+    ACPI_WALK_STATE         *WalkState);
+#endif
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsMethodDataInit
+ *
+ * PARAMETERS:  WalkState           - Current walk state object
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Initialize the data structures that hold the method's arguments
+ *              and locals. The data struct is an array of namespace nodes for
+ *              each - this allows RefOf and DeRefOf to work properly for these
+ *              special data types.
+ *
+ * NOTES:       WalkState fields are initialized to zero by the
+ *              ACPI_ALLOCATE_ZEROED().
+ *
+ *              A pseudo-Namespace Node is assigned to each argument and local
+ *              so that RefOf() can return a pointer to the Node.
+ *
+ ******************************************************************************/
+
+void
+AcpiDsMethodDataInit (
+    ACPI_WALK_STATE         *WalkState)
+{
+    UINT32                  i;
+
+
+    ACPI_FUNCTION_TRACE (DsMethodDataInit);
+
+
+    /* Init the method arguments */
+
+    for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
+    {
+        ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name,
+            NAMEOF_ARG_NTE);
+
+        WalkState->Arguments[i].Name.Integer |= (i << 24);
+        WalkState->Arguments[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
+        WalkState->Arguments[i].Type = ACPI_TYPE_ANY;
+        WalkState->Arguments[i].Flags = ANOBJ_METHOD_ARG;
+    }
+
+    /* Init the method locals */
+
+    for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
+    {
+        ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name,
+            NAMEOF_LOCAL_NTE);
+
+        WalkState->LocalVariables[i].Name.Integer |= (i << 24);
+        WalkState->LocalVariables[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
+        WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY;
+        WalkState->LocalVariables[i].Flags = ANOBJ_METHOD_LOCAL;
+    }
+
+    return_VOID;
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsMethodDataDeleteAll
+ *
+ * PARAMETERS:  WalkState           - Current walk state object
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Delete method locals and arguments. Arguments are only
+ *              deleted if this method was called from another method.
+ *
+ ******************************************************************************/
+
+void
+AcpiDsMethodDataDeleteAll (
+    ACPI_WALK_STATE         *WalkState)
+{
+    UINT32                  Index;
+
+
+    ACPI_FUNCTION_TRACE (DsMethodDataDeleteAll);
+
+
+    /* Detach the locals */
+
+    for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
+    {
+        if (WalkState->LocalVariables[Index].Object)
+        {
+            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%u=%p\n",
+                Index, WalkState->LocalVariables[Index].Object));
+
+            /* Detach object (if present) and remove a reference */
+
+            AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
+        }
+    }
+
+    /* Detach the arguments */
+
+    for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
+    {
+        if (WalkState->Arguments[Index].Object)
+        {
+            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%u=%p\n",
+                Index, WalkState->Arguments[Index].Object));
+
+            /* Detach object (if present) and remove a reference */
+
+            AcpiNsDetachObject (&WalkState->Arguments[Index]);
+        }
+    }
+
+    return_VOID;
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsMethodDataInitArgs
+ *
+ * PARAMETERS:  *Params         - Pointer to a parameter list for the method
+ *              MaxParamCount   - The arg count for this method
+ *              WalkState       - Current walk state object
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
+ *              of ACPI operand objects, either null terminated or whose length
+ *              is defined by MaxParamCount.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsMethodDataInitArgs (
+    ACPI_OPERAND_OBJECT     **Params,
+    UINT32                  MaxParamCount,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status;
+    UINT32                  Index = 0;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsMethodDataInitArgs, Params);
+
+
+    if (!Params)
+    {
+        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+            "No parameter list passed to method\n"));
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Copy passed parameters into the new method stack frame */
+
+    while ((Index < ACPI_METHOD_NUM_ARGS) &&
+           (Index < MaxParamCount)        &&
+            Params[Index])
+    {
+        /*
+         * A valid parameter.
+         * Store the argument in the method/walk descriptor.
+         * Do not copy the arg in order to implement call by reference
+         */
+        Status = AcpiDsMethodDataSetValue (
+            ACPI_REFCLASS_ARG, Index, Params[Index], WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            return_ACPI_STATUS (Status);
+        }
+
+        Index++;
+    }
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%u args passed to method\n", Index));
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsMethodDataGetNode
+ *
+ * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
+ *                                    ACPI_REFCLASS_ARG
+ *              Index               - Which Local or Arg whose type to get
+ *              WalkState           - Current walk state object
+ *              Node                - Where the node is returned.
+ *
+ * RETURN:      Status and node
+ *
+ * DESCRIPTION: Get the Node associated with a local or arg.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsMethodDataGetNode (
+    UINT8                   Type,
+    UINT32                  Index,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_NAMESPACE_NODE     **Node)
+{
+    ACPI_FUNCTION_TRACE (DsMethodDataGetNode);
+
+
+    /*
+     * Method Locals and Arguments are supported
+     */
+    switch (Type)
+    {
+    case ACPI_REFCLASS_LOCAL:
+
+        if (Index > ACPI_METHOD_MAX_LOCAL)
+        {
+            ACPI_ERROR ((AE_INFO,
+                "Local index %u is invalid (max %u)",
+                Index, ACPI_METHOD_MAX_LOCAL));
+            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
+        }
+
+        /* Return a pointer to the pseudo-node */
+
+        *Node = &WalkState->LocalVariables[Index];
+        break;
+
+    case ACPI_REFCLASS_ARG:
+
+        if (Index > ACPI_METHOD_MAX_ARG)
+        {
+            ACPI_ERROR ((AE_INFO,
+                "Arg index %u is invalid (max %u)",
+                Index, ACPI_METHOD_MAX_ARG));
+            return_ACPI_STATUS (AE_AML_INVALID_INDEX);
+        }
+
+        /* Return a pointer to the pseudo-node */
+
+        *Node = &WalkState->Arguments[Index];
+        break;
+
+    default:
+
+        ACPI_ERROR ((AE_INFO, "Type %u is invalid", Type));
+        return_ACPI_STATUS (AE_TYPE);
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsMethodDataSetValue
+ *
+ * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
+ *                                    ACPI_REFCLASS_ARG
+ *              Index               - Which Local or Arg to get
+ *              Object              - Object to be inserted into the stack entry
+ *              WalkState           - Current walk state object
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
+ *              Note: There is no "implicit conversion" for locals.
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsMethodDataSetValue (
+    UINT8                   Type,
+    UINT32                  Index,
+    ACPI_OPERAND_OBJECT     *Object,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status;
+    ACPI_NAMESPACE_NODE     *Node;
+
+
+    ACPI_FUNCTION_TRACE (DsMethodDataSetValue);
+
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+        "NewObj %p Type %2.2X, Refs=%u [%s]\n", Object,
+        Type, Object->Common.ReferenceCount,
+        AcpiUtGetTypeName (Object->Common.Type)));
+
+    /* Get the namespace node for the arg/local */
+
+    Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /*
+     * Increment ref count so object can't be deleted while installed.
+     * NOTE: We do not copy the object in order to preserve the call by
+     * reference semantics of ACPI Control Method invocation.
+     * (See ACPI Specification 2.0C)
+     */
+    AcpiUtAddReference (Object);
+
+    /* Install the object */
+
+    Node->Object = Object;
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsMethodDataGetValue
+ *
+ * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
+ *                                    ACPI_REFCLASS_ARG
+ *              Index               - Which localVar or argument to get
+ *              WalkState           - Current walk state object
+ *              DestDesc            - Where Arg or Local value is returned
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Retrieve value of selected Arg or Local for this method
+ *              Used only in AcpiExResolveToValue().
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsMethodDataGetValue (
+    UINT8                   Type,
+    UINT32                  Index,
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OPERAND_OBJECT     **DestDesc)
+{
+    ACPI_STATUS             Status;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_OPERAND_OBJECT     *Object;
+
+
+    ACPI_FUNCTION_TRACE (DsMethodDataGetValue);
+
+
+    /* Validate the object descriptor */
+
+    if (!DestDesc)
+    {
+        ACPI_ERROR ((AE_INFO, "Null object descriptor pointer"));
+        return_ACPI_STATUS (AE_BAD_PARAMETER);
+    }
+
+    /* Get the namespace node for the arg/local */
+
+    Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Get the object from the node */
+
+    Object = Node->Object;
+
+    /* Examine the returned object, it must be valid. */
+
+    if (!Object)
+    {
+        /*
+         * Index points to uninitialized object.
+         * This means that either 1) The expected argument was
+         * not passed to the method, or 2) A local variable
+         * was referenced by the method (via the ASL)
+         * before it was initialized. Either case is an error.
+         */
+
+        /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */
+
+        if (AcpiGbl_EnableInterpreterSlack)
+        {
+            Object = AcpiUtCreateIntegerObject ((UINT64) 0);
+            if (!Object)
+            {
+                return_ACPI_STATUS (AE_NO_MEMORY);
+            }
+
+            Node->Object = Object;
+        }
+
+        /* Otherwise, return the error */
+
+        else switch (Type)
+        {
+        case ACPI_REFCLASS_ARG:
+
+            ACPI_ERROR ((AE_INFO,
+                "Uninitialized Arg[%u] at node %p",
+                Index, Node));
+
+            return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
+
+        case ACPI_REFCLASS_LOCAL:
+            /*
+             * No error message for this case, will be trapped again later to
+             * detect and ignore cases of Store(LocalX,LocalX)
+             */
+            return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
+
+        default:
+
+            ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: 0x%X", Type));
+            return_ACPI_STATUS (AE_AML_INTERNAL);
+        }
+    }
+
+    /*
+     * The Index points to an initialized and valid object.
+     * Return an additional reference to the object
+     */
+    *DestDesc = Object;
+    AcpiUtAddReference (Object);
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsMethodDataDeleteValue
+ *
+ * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
+ *                                    ACPI_REFCLASS_ARG
+ *              Index               - Which localVar or argument to delete
+ *              WalkState           - Current walk state object
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
+ *              a null into the stack slot after the object is deleted.
+ *
+ ******************************************************************************/
+
+static void
+AcpiDsMethodDataDeleteValue (
+    UINT8                   Type,
+    UINT32                  Index,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_OPERAND_OBJECT     *Object;
+
+
+    ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue);
+
+
+    /* Get the namespace node for the arg/local */
+
+    Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
+    if (ACPI_FAILURE (Status))
+    {
+        return_VOID;
+    }
+
+    /* Get the associated object */
+
+    Object = AcpiNsGetAttachedObject (Node);
+
+    /*
+     * Undefine the Arg or Local by setting its descriptor
+     * pointer to NULL. Locals/Args can contain both
+     * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
+     */
+    Node->Object = NULL;
+
+    if ((Object) &&
+        (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
+    {
+        /*
+         * There is a valid object.
+         * Decrement the reference count by one to balance the
+         * increment when the object was stored.
+         */
+        AcpiUtRemoveReference (Object);
+    }
+
+    return_VOID;
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsStoreObjectToLocal
+ *
+ * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
+ *                                    ACPI_REFCLASS_ARG
+ *              Index               - Which Local or Arg to set
+ *              ObjDesc             - Value to be stored
+ *              WalkState           - Current walk state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed
+ *              as the new value for the Arg or Local and the reference count
+ *              for ObjDesc is incremented.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsStoreObjectToLocal (
+    UINT8                   Type,
+    UINT32                  Index,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_OPERAND_OBJECT     *CurrentObjDesc;
+    ACPI_OPERAND_OBJECT     *NewObjDesc;
+
+
+    ACPI_FUNCTION_TRACE (DsStoreObjectToLocal);
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n",
+        Type, Index, ObjDesc));
+
+    /* Parameter validation */
+
+    if (!ObjDesc)
+    {
+        return_ACPI_STATUS (AE_BAD_PARAMETER);
+    }
+
+    /* Get the namespace node for the arg/local */
+
+    Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    CurrentObjDesc = AcpiNsGetAttachedObject (Node);
+    if (CurrentObjDesc == ObjDesc)
+    {
+        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
+            ObjDesc));
+        return_ACPI_STATUS (Status);
+    }
+
+    /*
+     * If the reference count on the object is more than one, we must
+     * take a copy of the object before we store. A reference count
+     * of exactly 1 means that the object was just created during the
+     * evaluation of an expression, and we can safely use it since it
+     * is not used anywhere else.
+     */
+    NewObjDesc = ObjDesc;
+    if (ObjDesc->Common.ReferenceCount > 1)
+    {
+        Status = AcpiUtCopyIobjectToIobject (
+            ObjDesc, &NewObjDesc, WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            return_ACPI_STATUS (Status);
+        }
+    }
+
+    /*
+     * If there is an object already in this slot, we either
+     * have to delete it, or if this is an argument and there
+     * is an object reference stored there, we have to do
+     * an indirect store!
+     */
+    if (CurrentObjDesc)
+    {
+        /*
+         * Check for an indirect store if an argument
+         * contains an object reference (stored as an Node).
+         * We don't allow this automatic dereferencing for
+         * locals, since a store to a local should overwrite
+         * anything there, including an object reference.
+         *
+         * If both Arg0 and Local0 contain RefOf (Local4):
+         *
+         * Store (1, Arg0)             - Causes indirect store to local4
+         * Store (1, Local0)           - Stores 1 in local0, overwriting
+         *                                  the reference to local4
+         * Store (1, DeRefof (Local0)) - Causes indirect store to local4
+         *
+         * Weird, but true.
+         */
+        if (Type == ACPI_REFCLASS_ARG)
+        {
+            /*
+             * If we have a valid reference object that came from RefOf(),
+             * do the indirect store
+             */
+            if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) ==
+                    ACPI_DESC_TYPE_OPERAND) &&
+                (CurrentObjDesc->Common.Type ==
+                    ACPI_TYPE_LOCAL_REFERENCE) &&
+                (CurrentObjDesc->Reference.Class ==
+                    ACPI_REFCLASS_REFOF))
+            {
+                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+                    "Arg (%p) is an ObjRef(Node), storing in node %p\n",
+                    NewObjDesc, CurrentObjDesc));
+
+                /*
+                 * Store this object to the Node (perform the indirect store)
+                 * NOTE: No implicit conversion is performed, as per the ACPI
+                 * specification rules on storing to Locals/Args.
+                 */
+                Status = AcpiExStoreObjectToNode (NewObjDesc,
+                    CurrentObjDesc->Reference.Object, WalkState,
+                    ACPI_NO_IMPLICIT_CONVERSION);
+
+                /* Remove local reference if we copied the object above */
+
+                if (NewObjDesc != ObjDesc)
+                {
+                    AcpiUtRemoveReference (NewObjDesc);
+                }
+
+                return_ACPI_STATUS (Status);
+            }
+        }
+
+        /* Delete the existing object before storing the new one */
+
+        AcpiDsMethodDataDeleteValue (Type, Index, WalkState);
+    }
+
+    /*
+     * Install the Obj descriptor (*NewObjDesc) into
+     * the descriptor for the Arg or Local.
+     * (increments the object reference count by one)
+     */
+    Status = AcpiDsMethodDataSetValue (Type, Index, NewObjDesc, WalkState);
+
+    /* Remove local reference if we copied the object above */
+
+    if (NewObjDesc != ObjDesc)
+    {
+        AcpiUtRemoveReference (NewObjDesc);
+    }
+
+    return_ACPI_STATUS (Status);
+}
+
+
+#ifdef ACPI_OBSOLETE_FUNCTIONS
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsMethodDataGetType
+ *
+ * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
+ *              Index               - Which Local or Arg whose type to get
+ *              WalkState           - Current walk state object
+ *
+ * RETURN:      Data type of current value of the selected Arg or Local
+ *
+ * DESCRIPTION: Get the type of the object stored in the Local or Arg
+ *
+ ******************************************************************************/
+
+ACPI_OBJECT_TYPE
+AcpiDsMethodDataGetType (
+    UINT16                  Opcode,
+    UINT32                  Index,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_OPERAND_OBJECT     *Object;
+
+
+    ACPI_FUNCTION_TRACE (DsMethodDataGetType);
+
+
+    /* Get the namespace node for the arg/local */
+
+    Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
+    if (ACPI_FAILURE (Status))
+    {
+        return_VALUE ((ACPI_TYPE_NOT_FOUND));
+    }
+
+    /* Get the object */
+
+    Object = AcpiNsGetAttachedObject (Node);
+    if (!Object)
+    {
+        /* Uninitialized local/arg, return TYPE_ANY */
+
+        return_VALUE (ACPI_TYPE_ANY);
+    }
+
+    /* Get the object type */
+
+    return_VALUE (Object->Type);
+}
+#endif

+ 864 - 0
kernel/src/acpica/dispatcher/dsobject.c

@@ -0,0 +1,864 @@
+/******************************************************************************
+ *
+ * Module Name: dsobject - Dispatcher object management routines
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acparser.h"
+#include "amlcode.h"
+#include "acdispat.h"
+#include "acnamesp.h"
+#include "acinterp.h"
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dsobject")
+
+/* Local prototypes */
+
+static ACPI_STATUS
+AcpiDsBuildInternalObject (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_OPERAND_OBJECT     **ObjDescPtr);
+
+
+#ifndef ACPI_NO_METHOD_EXECUTION
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsBuildInternalObject
+ *
+ * PARAMETERS:  WalkState       - Current walk state
+ *              Op              - Parser object to be translated
+ *              ObjDescPtr      - Where the ACPI internal object is returned
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
+ *              Simple objects are any objects other than a package object!
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsBuildInternalObject (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_OPERAND_OBJECT     **ObjDescPtr)
+{
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_STATUS             Status;
+    ACPI_OBJECT_TYPE        Type;
+
+
+    ACPI_FUNCTION_TRACE (DsBuildInternalObject);
+
+
+    *ObjDescPtr = NULL;
+    if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
+    {
+        /*
+         * This is a named object reference. If this name was
+         * previously looked up in the namespace, it was stored in this op.
+         * Otherwise, go ahead and look it up now
+         */
+        if (!Op->Common.Node)
+        {
+            Status = AcpiNsLookup (WalkState->ScopeInfo,
+                Op->Common.Value.String,
+                ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
+                ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL,
+                ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &(Op->Common.Node)));
+            if (ACPI_FAILURE (Status))
+            {
+                /* Check if we are resolving a named reference within a package */
+
+                if ((Status == AE_NOT_FOUND) && (AcpiGbl_EnableInterpreterSlack) &&
+
+                    ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
+                     (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
+                {
+                    /*
+                     * We didn't find the target and we are populating elements
+                     * of a package - ignore if slack enabled. Some ASL code
+                     * contains dangling invalid references in packages and
+                     * expects that no exception will be issued. Leave the
+                     * element as a null element. It cannot be used, but it
+                     * can be overwritten by subsequent ASL code - this is
+                     * typically the case.
+                     */
+                    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
+                        "Ignoring unresolved reference in package [%4.4s]\n",
+                        WalkState->ScopeInfo->Scope.Node->Name.Ascii));
+
+                    return_ACPI_STATUS (AE_OK);
+                }
+                else
+                {
+                    ACPI_ERROR_NAMESPACE (Op->Common.Value.String, Status);
+                }
+
+                return_ACPI_STATUS (Status);
+            }
+        }
+
+        /* Special object resolution for elements of a package */
+
+        if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
+            (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
+        {
+            /*
+             * Attempt to resolve the node to a value before we insert it into
+             * the package. If this is a reference to a common data type,
+             * resolve it immediately. According to the ACPI spec, package
+             * elements can only be "data objects" or method references.
+             * Attempt to resolve to an Integer, Buffer, String or Package.
+             * If cannot, return the named reference (for things like Devices,
+             * Methods, etc.) Buffer Fields and Fields will resolve to simple
+             * objects (int/buf/str/pkg).
+             *
+             * NOTE: References to things like Devices, Methods, Mutexes, etc.
+             * will remain as named references. This behavior is not described
+             * in the ACPI spec, but it appears to be an oversight.
+             */
+            ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Op->Common.Node);
+
+            Status = AcpiExResolveNodeToValue (
+                ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc),
+                WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                return_ACPI_STATUS (Status);
+            }
+
+            /*
+             * Special handling for Alias objects. We need to setup the type
+             * and the Op->Common.Node to point to the Alias target. Note,
+             * Alias has at most one level of indirection internally.
+             */
+            Type = Op->Common.Node->Type;
+            if (Type == ACPI_TYPE_LOCAL_ALIAS)
+            {
+                Type = ObjDesc->Common.Type;
+                Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE,
+                    Op->Common.Node->Object);
+            }
+
+            switch (Type)
+            {
+            /*
+             * For these types, we need the actual node, not the subobject.
+             * However, the subobject did not get an extra reference count above.
+             *
+             * TBD: should ExResolveNodeToValue be changed to fix this?
+             */
+            case ACPI_TYPE_DEVICE:
+            case ACPI_TYPE_THERMAL:
+
+                AcpiUtAddReference (Op->Common.Node->Object);
+
+                /*lint -fallthrough */
+            /*
+             * For these types, we need the actual node, not the subobject.
+             * The subobject got an extra reference count in ExResolveNodeToValue.
+             */
+            case ACPI_TYPE_MUTEX:
+            case ACPI_TYPE_METHOD:
+            case ACPI_TYPE_POWER:
+            case ACPI_TYPE_PROCESSOR:
+            case ACPI_TYPE_EVENT:
+            case ACPI_TYPE_REGION:
+
+                /* We will create a reference object for these types below */
+                break;
+
+            default:
+                /*
+                 * All other types - the node was resolved to an actual
+                 * object, we are done.
+                 */
+                goto Exit;
+            }
+        }
+    }
+
+    /* Create and init a new internal ACPI object */
+
+    ObjDesc = AcpiUtCreateInternalObject (
+        (AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode))->ObjectType);
+    if (!ObjDesc)
+    {
+        return_ACPI_STATUS (AE_NO_MEMORY);
+    }
+
+    Status = AcpiDsInitObjectFromOp (
+        WalkState, Op, Op->Common.AmlOpcode, &ObjDesc);
+    if (ACPI_FAILURE (Status))
+    {
+        AcpiUtRemoveReference (ObjDesc);
+        return_ACPI_STATUS (Status);
+    }
+
+Exit:
+    *ObjDescPtr = ObjDesc;
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsBuildInternalBufferObj
+ *
+ * PARAMETERS:  WalkState       - Current walk state
+ *              Op              - Parser object to be translated
+ *              BufferLength    - Length of the buffer
+ *              ObjDescPtr      - Where the ACPI internal object is returned
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Translate a parser Op package object to the equivalent
+ *              namespace object
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsBuildInternalBufferObj (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    UINT32                  BufferLength,
+    ACPI_OPERAND_OBJECT     **ObjDescPtr)
+{
+    ACPI_PARSE_OBJECT       *Arg;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_PARSE_OBJECT       *ByteList;
+    UINT32                  ByteListLength = 0;
+
+
+    ACPI_FUNCTION_TRACE (DsBuildInternalBufferObj);
+
+
+    /*
+     * If we are evaluating a Named buffer object "Name (xxxx, Buffer)".
+     * The buffer object already exists (from the NS node), otherwise it must
+     * be created.
+     */
+    ObjDesc = *ObjDescPtr;
+    if (!ObjDesc)
+    {
+        /* Create a new buffer object */
+
+        ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
+        *ObjDescPtr = ObjDesc;
+        if (!ObjDesc)
+        {
+            return_ACPI_STATUS (AE_NO_MEMORY);
+        }
+    }
+
+    /*
+     * Second arg is the buffer data (optional) ByteList can be either
+     * individual bytes or a string initializer. In either case, a
+     * ByteList appears in the AML.
+     */
+    Arg = Op->Common.Value.Arg;         /* skip first arg */
+
+    ByteList = Arg->Named.Next;
+    if (ByteList)
+    {
+        if (ByteList->Common.AmlOpcode != AML_INT_BYTELIST_OP)
+        {
+            ACPI_ERROR ((AE_INFO,
+                "Expecting bytelist, found AML opcode 0x%X in op %p",
+                ByteList->Common.AmlOpcode, ByteList));
+
+            AcpiUtRemoveReference (ObjDesc);
+            return (AE_TYPE);
+        }
+
+        ByteListLength = (UINT32) ByteList->Common.Value.Integer;
+    }
+
+    /*
+     * The buffer length (number of bytes) will be the larger of:
+     * 1) The specified buffer length and
+     * 2) The length of the initializer byte list
+     */
+    ObjDesc->Buffer.Length = BufferLength;
+    if (ByteListLength > BufferLength)
+    {
+        ObjDesc->Buffer.Length = ByteListLength;
+    }
+
+    /* Allocate the buffer */
+
+    if (ObjDesc->Buffer.Length == 0)
+    {
+        ObjDesc->Buffer.Pointer = NULL;
+        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+            "Buffer defined with zero length in AML, creating\n"));
+    }
+    else
+    {
+        ObjDesc->Buffer.Pointer =
+            ACPI_ALLOCATE_ZEROED (ObjDesc->Buffer.Length);
+        if (!ObjDesc->Buffer.Pointer)
+        {
+            AcpiUtDeleteObjectDesc (ObjDesc);
+            return_ACPI_STATUS (AE_NO_MEMORY);
+        }
+
+        /* Initialize buffer from the ByteList (if present) */
+
+        if (ByteList)
+        {
+            memcpy (ObjDesc->Buffer.Pointer, ByteList->Named.Data,
+                ByteListLength);
+        }
+    }
+
+    ObjDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
+    Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsBuildInternalPackageObj
+ *
+ * PARAMETERS:  WalkState       - Current walk state
+ *              Op              - Parser object to be translated
+ *              ElementCount    - Number of elements in the package - this is
+ *                                the NumElements argument to Package()
+ *              ObjDescPtr      - Where the ACPI internal object is returned
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Translate a parser Op package object to the equivalent
+ *              namespace object
+ *
+ * NOTE: The number of elements in the package will be always be the NumElements
+ * count, regardless of the number of elements in the package list. If
+ * NumElements is smaller, only that many package list elements are used.
+ * if NumElements is larger, the Package object is padded out with
+ * objects of type Uninitialized (as per ACPI spec.)
+ *
+ * Even though the ASL compilers do not allow NumElements to be smaller
+ * than the Package list length (for the fixed length package opcode), some
+ * BIOS code modifies the AML on the fly to adjust the NumElements, and
+ * this code compensates for that. This also provides compatibility with
+ * other AML interpreters.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsBuildInternalPackageObj (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    UINT32                  ElementCount,
+    ACPI_OPERAND_OBJECT     **ObjDescPtr)
+{
+    ACPI_PARSE_OBJECT       *Arg;
+    ACPI_PARSE_OBJECT       *Parent;
+    ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
+    ACPI_STATUS             Status = AE_OK;
+    UINT32                  i;
+    UINT16                  Index;
+    UINT16                  ReferenceCount;
+
+
+    ACPI_FUNCTION_TRACE (DsBuildInternalPackageObj);
+
+
+    /* Find the parent of a possibly nested package */
+
+    Parent = Op->Common.Parent;
+    while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
+           (Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
+    {
+        Parent = Parent->Common.Parent;
+    }
+
+    /*
+     * If we are evaluating a Named package object "Name (xxxx, Package)",
+     * the package object already exists, otherwise it must be created.
+     */
+    ObjDesc = *ObjDescPtr;
+    if (!ObjDesc)
+    {
+        ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
+        *ObjDescPtr = ObjDesc;
+        if (!ObjDesc)
+        {
+            return_ACPI_STATUS (AE_NO_MEMORY);
+        }
+
+        ObjDesc->Package.Node = Parent->Common.Node;
+    }
+
+    /*
+     * Allocate the element array (array of pointers to the individual
+     * objects) based on the NumElements parameter. Add an extra pointer slot
+     * so that the list is always null terminated.
+     */
+    ObjDesc->Package.Elements = ACPI_ALLOCATE_ZEROED (
+        ((ACPI_SIZE) ElementCount + 1) * sizeof (void *));
+
+    if (!ObjDesc->Package.Elements)
+    {
+        AcpiUtDeleteObjectDesc (ObjDesc);
+        return_ACPI_STATUS (AE_NO_MEMORY);
+    }
+
+    ObjDesc->Package.Count = ElementCount;
+
+    /*
+     * Initialize the elements of the package, up to the NumElements count.
+     * Package is automatically padded with uninitialized (NULL) elements
+     * if NumElements is greater than the package list length. Likewise,
+     * Package is truncated if NumElements is less than the list length.
+     */
+    Arg = Op->Common.Value.Arg;
+    Arg = Arg->Common.Next;
+    for (i = 0; Arg && (i < ElementCount); i++)
+    {
+        if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
+        {
+            if (Arg->Common.Node->Type == ACPI_TYPE_METHOD)
+            {
+                /*
+                 * A method reference "looks" to the parser to be a method
+                 * invocation, so we special case it here
+                 */
+                Arg->Common.AmlOpcode = AML_INT_NAMEPATH_OP;
+                Status = AcpiDsBuildInternalObject (
+                    WalkState, Arg, &ObjDesc->Package.Elements[i]);
+            }
+            else
+            {
+                /* This package element is already built, just get it */
+
+                ObjDesc->Package.Elements[i] =
+                    ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
+            }
+        }
+        else
+        {
+            Status = AcpiDsBuildInternalObject (
+                WalkState, Arg, &ObjDesc->Package.Elements[i]);
+        }
+
+        if (*ObjDescPtr)
+        {
+            /* Existing package, get existing reference count */
+
+            ReferenceCount = (*ObjDescPtr)->Common.ReferenceCount;
+            if (ReferenceCount > 1)
+            {
+                /* Make new element ref count match original ref count */
+
+                for (Index = 0; Index < (ReferenceCount - 1); Index++)
+                {
+                    AcpiUtAddReference ((ObjDesc->Package.Elements[i]));
+                }
+            }
+        }
+
+        Arg = Arg->Common.Next;
+    }
+
+    /* Check for match between NumElements and actual length of PackageList */
+
+    if (Arg)
+    {
+        /*
+         * NumElements was exhausted, but there are remaining elements in the
+         * PackageList. Truncate the package to NumElements.
+         *
+         * Note: technically, this is an error, from ACPI spec: "It is an error
+         * for NumElements to be less than the number of elements in the
+         * PackageList". However, we just print a message and
+         * no exception is returned. This provides Windows compatibility. Some
+         * BIOSs will alter the NumElements on the fly, creating this type
+         * of ill-formed package object.
+         */
+        while (Arg)
+        {
+            /*
+             * We must delete any package elements that were created earlier
+             * and are not going to be used because of the package truncation.
+             */
+            if (Arg->Common.Node)
+            {
+                AcpiUtRemoveReference (
+                    ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node));
+                Arg->Common.Node = NULL;
+            }
+
+            /* Find out how many elements there really are */
+
+            i++;
+            Arg = Arg->Common.Next;
+        }
+
+        ACPI_INFO ((AE_INFO,
+            "Actual Package length (%u) is larger than "
+            "NumElements field (%u), truncated",
+            i, ElementCount));
+    }
+    else if (i < ElementCount)
+    {
+        /*
+         * Arg list (elements) was exhausted, but we did not reach NumElements count.
+         * Note: this is not an error, the package is padded out with NULLs.
+         */
+        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
+            "Package List length (%u) smaller than NumElements "
+            "count (%u), padded with null elements\n",
+            i, ElementCount));
+    }
+
+    ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
+    Op->Common.Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjDesc);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCreateNode
+ *
+ * PARAMETERS:  WalkState       - Current walk state
+ *              Node            - NS Node to be initialized
+ *              Op              - Parser object to be translated
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Create the object to be associated with a namespace node
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsCreateNode (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_PARSE_OBJECT       *Op)
+{
+    ACPI_STATUS             Status;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsCreateNode, Op);
+
+
+    /*
+     * Because of the execution pass through the non-control-method
+     * parts of the table, we can arrive here twice. Only init
+     * the named object node the first time through
+     */
+    if (AcpiNsGetAttachedObject (Node))
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    if (!Op->Common.Value.Arg)
+    {
+        /* No arguments, there is nothing to do */
+
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Build an internal object for the argument(s) */
+
+    Status = AcpiDsBuildInternalObject (
+        WalkState, Op->Common.Value.Arg, &ObjDesc);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Re-type the object according to its argument */
+
+    Node->Type = ObjDesc->Common.Type;
+
+    /* Attach obj to node */
+
+    Status = AcpiNsAttachObject (Node, ObjDesc, Node->Type);
+
+    /* Remove local reference to the object */
+
+    AcpiUtRemoveReference (ObjDesc);
+    return_ACPI_STATUS (Status);
+}
+
+#endif /* ACPI_NO_METHOD_EXECUTION */
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsInitObjectFromOp
+ *
+ * PARAMETERS:  WalkState       - Current walk state
+ *              Op              - Parser op used to init the internal object
+ *              Opcode          - AML opcode associated with the object
+ *              RetObjDesc      - Namespace object to be initialized
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Initialize a namespace object from a parser Op and its
+ *              associated arguments. The namespace object is a more compact
+ *              representation of the Op and its arguments.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsInitObjectFromOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    UINT16                  Opcode,
+    ACPI_OPERAND_OBJECT     **RetObjDesc)
+{
+    const ACPI_OPCODE_INFO  *OpInfo;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_STATUS             Status = AE_OK;
+
+
+    ACPI_FUNCTION_TRACE (DsInitObjectFromOp);
+
+
+    ObjDesc = *RetObjDesc;
+    OpInfo = AcpiPsGetOpcodeInfo (Opcode);
+    if (OpInfo->Class == AML_CLASS_UNKNOWN)
+    {
+        /* Unknown opcode */
+
+        return_ACPI_STATUS (AE_TYPE);
+    }
+
+    /* Perform per-object initialization */
+
+    switch (ObjDesc->Common.Type)
+    {
+    case ACPI_TYPE_BUFFER:
+        /*
+         * Defer evaluation of Buffer TermArg operand
+         */
+        ObjDesc->Buffer.Node = ACPI_CAST_PTR (
+            ACPI_NAMESPACE_NODE, WalkState->Operands[0]);
+        ObjDesc->Buffer.AmlStart = Op->Named.Data;
+        ObjDesc->Buffer.AmlLength = Op->Named.Length;
+        break;
+
+    case ACPI_TYPE_PACKAGE:
+        /*
+         * Defer evaluation of Package TermArg operand
+         */
+        ObjDesc->Package.Node = ACPI_CAST_PTR (
+            ACPI_NAMESPACE_NODE, WalkState->Operands[0]);
+        ObjDesc->Package.AmlStart = Op->Named.Data;
+        ObjDesc->Package.AmlLength = Op->Named.Length;
+        break;
+
+    case ACPI_TYPE_INTEGER:
+
+        switch (OpInfo->Type)
+        {
+        case AML_TYPE_CONSTANT:
+            /*
+             * Resolve AML Constants here - AND ONLY HERE!
+             * All constants are integers.
+             * We mark the integer with a flag that indicates that it started
+             * life as a constant -- so that stores to constants will perform
+             * as expected (noop). ZeroOp is used as a placeholder for optional
+             * target operands.
+             */
+            ObjDesc->Common.Flags = AOPOBJ_AML_CONSTANT;
+
+            switch (Opcode)
+            {
+            case AML_ZERO_OP:
+
+                ObjDesc->Integer.Value = 0;
+                break;
+
+            case AML_ONE_OP:
+
+                ObjDesc->Integer.Value = 1;
+                break;
+
+            case AML_ONES_OP:
+
+                ObjDesc->Integer.Value = ACPI_UINT64_MAX;
+
+                /* Truncate value if we are executing from a 32-bit ACPI table */
+
+#ifndef ACPI_NO_METHOD_EXECUTION
+                (void) AcpiExTruncateFor32bitTable (ObjDesc);
+#endif
+                break;
+
+            case AML_REVISION_OP:
+
+                ObjDesc->Integer.Value = ACPI_CA_VERSION;
+                break;
+
+            default:
+
+                ACPI_ERROR ((AE_INFO,
+                    "Unknown constant opcode 0x%X", Opcode));
+                Status = AE_AML_OPERAND_TYPE;
+                break;
+            }
+            break;
+
+        case AML_TYPE_LITERAL:
+
+            ObjDesc->Integer.Value = Op->Common.Value.Integer;
+
+#ifndef ACPI_NO_METHOD_EXECUTION
+            if (AcpiExTruncateFor32bitTable (ObjDesc))
+            {
+                /* Warn if we found a 64-bit constant in a 32-bit table */
+
+                ACPI_WARNING ((AE_INFO,
+                    "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X",
+                    ACPI_FORMAT_UINT64 (Op->Common.Value.Integer),
+                    (UINT32) ObjDesc->Integer.Value));
+            }
+#endif
+            break;
+
+        default:
+
+            ACPI_ERROR ((AE_INFO, "Unknown Integer type 0x%X",
+                OpInfo->Type));
+            Status = AE_AML_OPERAND_TYPE;
+            break;
+        }
+        break;
+
+    case ACPI_TYPE_STRING:
+
+        ObjDesc->String.Pointer = Op->Common.Value.String;
+        ObjDesc->String.Length = (UINT32) strlen (Op->Common.Value.String);
+
+        /*
+         * The string is contained in the ACPI table, don't ever try
+         * to delete it
+         */
+        ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
+        break;
+
+    case ACPI_TYPE_METHOD:
+        break;
+
+    case ACPI_TYPE_LOCAL_REFERENCE:
+
+        switch (OpInfo->Type)
+        {
+        case AML_TYPE_LOCAL_VARIABLE:
+
+            /* Local ID (0-7) is (AML opcode - base AML_LOCAL_OP) */
+
+            ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_LOCAL_OP;
+            ObjDesc->Reference.Class = ACPI_REFCLASS_LOCAL;
+
+#ifndef ACPI_NO_METHOD_EXECUTION
+            Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_LOCAL,
+                ObjDesc->Reference.Value, WalkState,
+                ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
+                    &ObjDesc->Reference.Object));
+#endif
+            break;
+
+        case AML_TYPE_METHOD_ARGUMENT:
+
+            /* Arg ID (0-6) is (AML opcode - base AML_ARG_OP) */
+
+            ObjDesc->Reference.Value = ((UINT32) Opcode) - AML_ARG_OP;
+            ObjDesc->Reference.Class = ACPI_REFCLASS_ARG;
+
+#ifndef ACPI_NO_METHOD_EXECUTION
+            Status = AcpiDsMethodDataGetNode (ACPI_REFCLASS_ARG,
+                ObjDesc->Reference.Value, WalkState,
+                ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE,
+                    &ObjDesc->Reference.Object));
+#endif
+            break;
+
+        default: /* Object name or Debug object */
+
+            switch (Op->Common.AmlOpcode)
+            {
+            case AML_INT_NAMEPATH_OP:
+
+                /* Node was saved in Op */
+
+                ObjDesc->Reference.Node = Op->Common.Node;
+                ObjDesc->Reference.Object = Op->Common.Node->Object;
+                ObjDesc->Reference.Class = ACPI_REFCLASS_NAME;
+                break;
+
+            case AML_DEBUG_OP:
+
+                ObjDesc->Reference.Class = ACPI_REFCLASS_DEBUG;
+                break;
+
+            default:
+
+                ACPI_ERROR ((AE_INFO,
+                    "Unimplemented reference type for AML opcode: 0x%4.4X", Opcode));
+                return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
+            }
+            break;
+        }
+        break;
+
+    default:
+
+        ACPI_ERROR ((AE_INFO, "Unimplemented data type: 0x%X",
+            ObjDesc->Common.Type));
+
+        Status = AE_AML_OPERAND_TYPE;
+        break;
+    }
+
+    return_ACPI_STATUS (Status);
+}

+ 817 - 0
kernel/src/acpica/dispatcher/dsopcode.c

@@ -0,0 +1,817 @@
+/******************************************************************************
+ *
+ * Module Name: dsopcode - Dispatcher support for regions and fields
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acparser.h"
+#include "amlcode.h"
+#include "acdispat.h"
+#include "acinterp.h"
+#include "acnamesp.h"
+#include "acevents.h"
+#include "actables.h"
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dsopcode")
+
+/* Local prototypes */
+
+static ACPI_STATUS
+AcpiDsInitBufferField (
+    UINT16                  AmlOpcode,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     *BufferDesc,
+    ACPI_OPERAND_OBJECT     *OffsetDesc,
+    ACPI_OPERAND_OBJECT     *LengthDesc,
+    ACPI_OPERAND_OBJECT     *ResultDesc);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsInitializeRegion
+ *
+ * PARAMETERS:  ObjHandle       - Region namespace node
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Front end to EvInitializeRegion
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsInitializeRegion (
+    ACPI_HANDLE             ObjHandle)
+{
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_STATUS             Status;
+
+
+    ObjDesc = AcpiNsGetAttachedObject (ObjHandle);
+
+    /* Namespace is NOT locked */
+
+    Status = AcpiEvInitializeRegion (ObjDesc, FALSE);
+    return (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsInitBufferField
+ *
+ * PARAMETERS:  AmlOpcode       - CreateXxxField
+ *              ObjDesc         - BufferField object
+ *              BufferDesc      - Host Buffer
+ *              OffsetDesc      - Offset into buffer
+ *              LengthDesc      - Length of field (CREATE_FIELD_OP only)
+ *              ResultDesc      - Where to store the result
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Perform actual initialization of a buffer field
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsInitBufferField (
+    UINT16                  AmlOpcode,
+    ACPI_OPERAND_OBJECT     *ObjDesc,
+    ACPI_OPERAND_OBJECT     *BufferDesc,
+    ACPI_OPERAND_OBJECT     *OffsetDesc,
+    ACPI_OPERAND_OBJECT     *LengthDesc,
+    ACPI_OPERAND_OBJECT     *ResultDesc)
+{
+    UINT32                  Offset;
+    UINT32                  BitOffset;
+    UINT32                  BitCount;
+    UINT8                   FieldFlags;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsInitBufferField, ObjDesc);
+
+
+    /* Host object must be a Buffer */
+
+    if (BufferDesc->Common.Type != ACPI_TYPE_BUFFER)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "Target of Create Field is not a Buffer object - %s",
+            AcpiUtGetObjectTypeName (BufferDesc)));
+
+        Status = AE_AML_OPERAND_TYPE;
+        goto Cleanup;
+    }
+
+    /*
+     * The last parameter to all of these opcodes (ResultDesc) started
+     * out as a NameString, and should therefore now be a NS node
+     * after resolution in AcpiExResolveOperands().
+     */
+    if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc) != ACPI_DESC_TYPE_NAMED)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "(%s) destination not a NS Node [%s]",
+            AcpiPsGetOpcodeName (AmlOpcode),
+            AcpiUtGetDescriptorName (ResultDesc)));
+
+        Status = AE_AML_OPERAND_TYPE;
+        goto Cleanup;
+    }
+
+    Offset = (UINT32) OffsetDesc->Integer.Value;
+
+    /*
+     * Setup the Bit offsets and counts, according to the opcode
+     */
+    switch (AmlOpcode)
+    {
+    case AML_CREATE_FIELD_OP:
+
+        /* Offset is in bits, count is in bits */
+
+        FieldFlags = AML_FIELD_ACCESS_BYTE;
+        BitOffset  = Offset;
+        BitCount   = (UINT32) LengthDesc->Integer.Value;
+
+        /* Must have a valid (>0) bit count */
+
+        if (BitCount == 0)
+        {
+            ACPI_ERROR ((AE_INFO,
+                "Attempt to CreateField of length zero"));
+            Status = AE_AML_OPERAND_VALUE;
+            goto Cleanup;
+        }
+        break;
+
+    case AML_CREATE_BIT_FIELD_OP:
+
+        /* Offset is in bits, Field is one bit */
+
+        BitOffset  = Offset;
+        BitCount   = 1;
+        FieldFlags = AML_FIELD_ACCESS_BYTE;
+        break;
+
+    case AML_CREATE_BYTE_FIELD_OP:
+
+        /* Offset is in bytes, field is one byte */
+
+        BitOffset  = 8 * Offset;
+        BitCount   = 8;
+        FieldFlags = AML_FIELD_ACCESS_BYTE;
+        break;
+
+    case AML_CREATE_WORD_FIELD_OP:
+
+        /* Offset is in bytes, field is one word */
+
+        BitOffset  = 8 * Offset;
+        BitCount   = 16;
+        FieldFlags = AML_FIELD_ACCESS_WORD;
+        break;
+
+    case AML_CREATE_DWORD_FIELD_OP:
+
+        /* Offset is in bytes, field is one dword */
+
+        BitOffset  = 8 * Offset;
+        BitCount   = 32;
+        FieldFlags = AML_FIELD_ACCESS_DWORD;
+        break;
+
+    case AML_CREATE_QWORD_FIELD_OP:
+
+        /* Offset is in bytes, field is one qword */
+
+        BitOffset  = 8 * Offset;
+        BitCount   = 64;
+        FieldFlags = AML_FIELD_ACCESS_QWORD;
+        break;
+
+    default:
+
+        ACPI_ERROR ((AE_INFO,
+            "Unknown field creation opcode 0x%02X",
+            AmlOpcode));
+        Status = AE_AML_BAD_OPCODE;
+        goto Cleanup;
+    }
+
+    /* Entire field must fit within the current length of the buffer */
+
+    if ((BitOffset + BitCount) >
+        (8 * (UINT32) BufferDesc->Buffer.Length))
+    {
+        ACPI_ERROR ((AE_INFO,
+            "Field [%4.4s] at %u exceeds Buffer [%4.4s] size %u (bits)",
+            AcpiUtGetNodeName (ResultDesc),
+            BitOffset + BitCount,
+            AcpiUtGetNodeName (BufferDesc->Buffer.Node),
+            8 * (UINT32) BufferDesc->Buffer.Length));
+        Status = AE_AML_BUFFER_LIMIT;
+        goto Cleanup;
+    }
+
+    /*
+     * Initialize areas of the field object that are common to all fields
+     * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK),
+     * UPDATE_RULE = 0 (UPDATE_PRESERVE)
+     */
+    Status = AcpiExPrepCommonFieldObject (
+        ObjDesc, FieldFlags, 0, BitOffset, BitCount);
+    if (ACPI_FAILURE (Status))
+    {
+        goto Cleanup;
+    }
+
+    ObjDesc->BufferField.BufferObj = BufferDesc;
+
+    /* Reference count for BufferDesc inherits ObjDesc count */
+
+    BufferDesc->Common.ReferenceCount = (UINT16)
+        (BufferDesc->Common.ReferenceCount + ObjDesc->Common.ReferenceCount);
+
+
+Cleanup:
+
+    /* Always delete the operands */
+
+    AcpiUtRemoveReference (OffsetDesc);
+    AcpiUtRemoveReference (BufferDesc);
+
+    if (AmlOpcode == AML_CREATE_FIELD_OP)
+    {
+        AcpiUtRemoveReference (LengthDesc);
+    }
+
+    /* On failure, delete the result descriptor */
+
+    if (ACPI_FAILURE (Status))
+    {
+        AcpiUtRemoveReference (ResultDesc);     /* Result descriptor */
+    }
+    else
+    {
+        /* Now the address and length are valid for this BufferField */
+
+        ObjDesc->BufferField.Flags |= AOPOBJ_DATA_VALID;
+    }
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsEvalBufferFieldOperands
+ *
+ * PARAMETERS:  WalkState       - Current walk
+ *              Op              - A valid BufferField Op object
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Get BufferField Buffer and Index
+ *              Called from AcpiDsExecEndOp during BufferField parse tree walk
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsEvalBufferFieldOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op)
+{
+    ACPI_STATUS             Status;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_PARSE_OBJECT       *NextOp;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsEvalBufferFieldOperands, Op);
+
+
+    /*
+     * This is where we evaluate the address and length fields of the
+     * CreateXxxField declaration
+     */
+    Node =  Op->Common.Node;
+
+    /* NextOp points to the op that holds the Buffer */
+
+    NextOp = Op->Common.Value.Arg;
+
+    /* Evaluate/create the address and length operands */
+
+    Status = AcpiDsCreateOperands (WalkState, NextOp);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    ObjDesc = AcpiNsGetAttachedObject (Node);
+    if (!ObjDesc)
+    {
+        return_ACPI_STATUS (AE_NOT_EXIST);
+    }
+
+    /* Resolve the operands */
+
+    Status = AcpiExResolveOperands (
+        Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_ERROR ((AE_INFO, "(%s) bad operand(s), status 0x%X",
+            AcpiPsGetOpcodeName (Op->Common.AmlOpcode), Status));
+
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Initialize the Buffer Field */
+
+    if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
+    {
+        /* NOTE: Slightly different operands for this opcode */
+
+        Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
+            WalkState->Operands[0], WalkState->Operands[1],
+            WalkState->Operands[2], WalkState->Operands[3]);
+    }
+    else
+    {
+        /* All other, CreateXxxField opcodes */
+
+        Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
+            WalkState->Operands[0], WalkState->Operands[1],
+            NULL, WalkState->Operands[2]);
+    }
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsEvalRegionOperands
+ *
+ * PARAMETERS:  WalkState       - Current walk
+ *              Op              - A valid region Op object
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Get region address and length
+ *              Called from AcpiDsExecEndOp during OpRegion parse tree walk
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsEvalRegionOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op)
+{
+    ACPI_STATUS             Status;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_OPERAND_OBJECT     *OperandDesc;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_PARSE_OBJECT       *NextOp;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsEvalRegionOperands, Op);
+
+
+    /*
+     * This is where we evaluate the address and length fields of the
+     * OpRegion declaration
+     */
+    Node =  Op->Common.Node;
+
+    /* NextOp points to the op that holds the SpaceID */
+
+    NextOp = Op->Common.Value.Arg;
+
+    /* NextOp points to address op */
+
+    NextOp = NextOp->Common.Next;
+
+    /* Evaluate/create the address and length operands */
+
+    Status = AcpiDsCreateOperands (WalkState, NextOp);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Resolve the length and address operands to numbers */
+
+    Status = AcpiExResolveOperands (
+        Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    ObjDesc = AcpiNsGetAttachedObject (Node);
+    if (!ObjDesc)
+    {
+        return_ACPI_STATUS (AE_NOT_EXIST);
+    }
+
+    /*
+     * Get the length operand and save it
+     * (at Top of stack)
+     */
+    OperandDesc = WalkState->Operands[WalkState->NumOperands - 1];
+
+    ObjDesc->Region.Length = (UINT32) OperandDesc->Integer.Value;
+    AcpiUtRemoveReference (OperandDesc);
+
+    /*
+     * Get the address and save it
+     * (at top of stack - 1)
+     */
+    OperandDesc = WalkState->Operands[WalkState->NumOperands - 2];
+
+    ObjDesc->Region.Address = (ACPI_PHYSICAL_ADDRESS)
+        OperandDesc->Integer.Value;
+    AcpiUtRemoveReference (OperandDesc);
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
+        ObjDesc, ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
+        ObjDesc->Region.Length));
+
+    /* Now the address and length are valid for this opregion */
+
+    ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsEvalTableRegionOperands
+ *
+ * PARAMETERS:  WalkState       - Current walk
+ *              Op              - A valid region Op object
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Get region address and length.
+ *              Called from AcpiDsExecEndOp during DataTableRegion parse
+ *              tree walk.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsEvalTableRegionOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op)
+{
+    ACPI_STATUS             Status;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_OPERAND_OBJECT     **Operand;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_PARSE_OBJECT       *NextOp;
+    ACPI_TABLE_HEADER       *Table;
+    UINT32                  TableIndex;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsEvalTableRegionOperands, Op);
+
+
+    /*
+     * This is where we evaluate the Signature string, OemId string,
+     * and OemTableId string of the Data Table Region declaration
+     */
+    Node =  Op->Common.Node;
+
+    /* NextOp points to Signature string op */
+
+    NextOp = Op->Common.Value.Arg;
+
+    /*
+     * Evaluate/create the Signature string, OemId string,
+     * and OemTableId string operands
+     */
+    Status = AcpiDsCreateOperands (WalkState, NextOp);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    Operand = &WalkState->Operands[0];
+
+    /*
+     * Resolve the Signature string, OemId string,
+     * and OemTableId string operands
+     */
+    Status = AcpiExResolveOperands (
+        Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
+    if (ACPI_FAILURE (Status))
+    {
+        goto Cleanup;
+    }
+
+    /* Find the ACPI table */
+
+    Status = AcpiTbFindTable (
+        Operand[0]->String.Pointer,
+        Operand[1]->String.Pointer,
+        Operand[2]->String.Pointer, &TableIndex);
+    if (ACPI_FAILURE (Status))
+    {
+        if (Status == AE_NOT_FOUND)
+        {
+            ACPI_ERROR ((AE_INFO,
+                "ACPI Table [%4.4s] OEM:(%s, %s) not found in RSDT/XSDT",
+                Operand[0]->String.Pointer,
+                Operand[1]->String.Pointer,
+                Operand[2]->String.Pointer));
+        }
+        goto Cleanup;
+    }
+
+    Status = AcpiGetTableByIndex (TableIndex, &Table);
+    if (ACPI_FAILURE (Status))
+    {
+        goto Cleanup;
+    }
+
+    ObjDesc = AcpiNsGetAttachedObject (Node);
+    if (!ObjDesc)
+    {
+        Status = AE_NOT_EXIST;
+        goto Cleanup;
+    }
+
+    ObjDesc->Region.Address = ACPI_PTR_TO_PHYSADDR (Table);
+    ObjDesc->Region.Length = Table->Length;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
+        ObjDesc, ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
+        ObjDesc->Region.Length));
+
+    /* Now the address and length are valid for this opregion */
+
+    ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
+
+Cleanup:
+    AcpiUtRemoveReference (Operand[0]);
+    AcpiUtRemoveReference (Operand[1]);
+    AcpiUtRemoveReference (Operand[2]);
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsEvalDataObjectOperands
+ *
+ * PARAMETERS:  WalkState       - Current walk
+ *              Op              - A valid DataObject Op object
+ *              ObjDesc         - DataObject
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Get the operands and complete the following data object types:
+ *              Buffer, Package.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsEvalDataObjectOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_OPERAND_OBJECT     *ObjDesc)
+{
+    ACPI_STATUS             Status;
+    ACPI_OPERAND_OBJECT     *ArgDesc;
+    UINT32                  Length;
+
+
+    ACPI_FUNCTION_TRACE (DsEvalDataObjectOperands);
+
+
+    /* The first operand (for all of these data objects) is the length */
+
+    /*
+     * Set proper index into operand stack for AcpiDsObjStackPush
+     * invoked inside AcpiDsCreateOperand.
+     */
+    WalkState->OperandIndex = WalkState->NumOperands;
+
+    Status = AcpiDsCreateOperand (WalkState, Op->Common.Value.Arg, 1);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    Status = AcpiExResolveOperands (WalkState->Opcode,
+        &(WalkState->Operands [WalkState->NumOperands -1]),
+        WalkState);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Extract length operand */
+
+    ArgDesc = WalkState->Operands [WalkState->NumOperands - 1];
+    Length = (UINT32) ArgDesc->Integer.Value;
+
+    /* Cleanup for length operand */
+
+    Status = AcpiDsObjStackPop (1, WalkState);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    AcpiUtRemoveReference (ArgDesc);
+
+    /*
+     * Create the actual data object
+     */
+    switch (Op->Common.AmlOpcode)
+    {
+    case AML_BUFFER_OP:
+
+        Status = AcpiDsBuildInternalBufferObj (
+            WalkState, Op, Length, &ObjDesc);
+        break;
+
+    case AML_PACKAGE_OP:
+    case AML_VAR_PACKAGE_OP:
+
+        Status = AcpiDsBuildInternalPackageObj (
+            WalkState, Op, Length, &ObjDesc);
+        break;
+
+    default:
+
+        return_ACPI_STATUS (AE_AML_BAD_OPCODE);
+    }
+
+    if (ACPI_SUCCESS (Status))
+    {
+        /*
+         * Return the object in the WalkState, unless the parent is a package -
+         * in this case, the return object will be stored in the parse tree
+         * for the package.
+         */
+        if ((!Op->Common.Parent) ||
+            ((Op->Common.Parent->Common.AmlOpcode != AML_PACKAGE_OP) &&
+             (Op->Common.Parent->Common.AmlOpcode != AML_VAR_PACKAGE_OP) &&
+             (Op->Common.Parent->Common.AmlOpcode != AML_NAME_OP)))
+        {
+            WalkState->ResultObj = ObjDesc;
+        }
+    }
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsEvalBankFieldOperands
+ *
+ * PARAMETERS:  WalkState       - Current walk
+ *              Op              - A valid BankField Op object
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Get BankField BankValue
+ *              Called from AcpiDsExecEndOp during BankField parse tree walk
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsEvalBankFieldOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op)
+{
+    ACPI_STATUS             Status;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_OPERAND_OBJECT     *OperandDesc;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_PARSE_OBJECT       *NextOp;
+    ACPI_PARSE_OBJECT       *Arg;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsEvalBankFieldOperands, Op);
+
+
+    /*
+     * This is where we evaluate the BankValue field of the
+     * BankField declaration
+     */
+
+    /* NextOp points to the op that holds the Region */
+
+    NextOp = Op->Common.Value.Arg;
+
+    /* NextOp points to the op that holds the Bank Register */
+
+    NextOp = NextOp->Common.Next;
+
+    /* NextOp points to the op that holds the Bank Value */
+
+    NextOp = NextOp->Common.Next;
+
+    /*
+     * Set proper index into operand stack for AcpiDsObjStackPush
+     * invoked inside AcpiDsCreateOperand.
+     *
+     * We use WalkState->Operands[0] to store the evaluated BankValue
+     */
+    WalkState->OperandIndex = 0;
+
+    Status = AcpiDsCreateOperand (WalkState, NextOp, 0);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    Status = AcpiExResolveToValue (&WalkState->Operands[0], WalkState);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS,
+        AcpiPsGetOpcodeName (Op->Common.AmlOpcode), 1);
+    /*
+     * Get the BankValue operand and save it
+     * (at Top of stack)
+     */
+    OperandDesc = WalkState->Operands[0];
+
+    /* Arg points to the start Bank Field */
+
+    Arg = AcpiPsGetArg (Op, 4);
+    while (Arg)
+    {
+        /* Ignore OFFSET and ACCESSAS terms here */
+
+        if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
+        {
+            Node = Arg->Common.Node;
+
+            ObjDesc = AcpiNsGetAttachedObject (Node);
+            if (!ObjDesc)
+            {
+                return_ACPI_STATUS (AE_NOT_EXIST);
+            }
+
+            ObjDesc->BankField.Value = (UINT32) OperandDesc->Integer.Value;
+        }
+
+        /* Move to next field in the list */
+
+        Arg = Arg->Common.Next;
+    }
+
+    AcpiUtRemoveReference (OperandDesc);
+    return_ACPI_STATUS (Status);
+}

+ 945 - 0
kernel/src/acpica/dispatcher/dsutils.c

@@ -0,0 +1,945 @@
+/*******************************************************************************
+ *
+ * Module Name: dsutils - Dispatcher utilities
+ *
+ ******************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acparser.h"
+#include "amlcode.h"
+#include "acdispat.h"
+#include "acinterp.h"
+#include "acnamesp.h"
+#include "acdebug.h"
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dsutils")
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsClearImplicitReturn
+ *
+ * PARAMETERS:  WalkState           - Current State
+ *
+ * RETURN:      None.
+ *
+ * DESCRIPTION: Clear and remove a reference on an implicit return value. Used
+ *              to delete "stale" return values (if enabled, the return value
+ *              from every operator is saved at least momentarily, in case the
+ *              parent method exits.)
+ *
+ ******************************************************************************/
+
+void
+AcpiDsClearImplicitReturn (
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_FUNCTION_NAME (DsClearImplicitReturn);
+
+
+    /*
+     * Slack must be enabled for this feature
+     */
+    if (!AcpiGbl_EnableInterpreterSlack)
+    {
+        return;
+    }
+
+    if (WalkState->ImplicitReturnObj)
+    {
+        /*
+         * Delete any "stale" implicit return. However, in
+         * complex statements, the implicit return value can be
+         * bubbled up several levels.
+         */
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "Removing reference on stale implicit return obj %p\n",
+            WalkState->ImplicitReturnObj));
+
+        AcpiUtRemoveReference (WalkState->ImplicitReturnObj);
+        WalkState->ImplicitReturnObj = NULL;
+    }
+}
+
+
+#ifndef ACPI_NO_METHOD_EXECUTION
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsDoImplicitReturn
+ *
+ * PARAMETERS:  ReturnDesc          - The return value
+ *              WalkState           - Current State
+ *              AddReference        - True if a reference should be added to the
+ *                                    return object
+ *
+ * RETURN:      TRUE if implicit return enabled, FALSE otherwise
+ *
+ * DESCRIPTION: Implements the optional "implicit return".  We save the result
+ *              of every ASL operator and control method invocation in case the
+ *              parent method exit. Before storing a new return value, we
+ *              delete the previous return value.
+ *
+ ******************************************************************************/
+
+BOOLEAN
+AcpiDsDoImplicitReturn (
+    ACPI_OPERAND_OBJECT     *ReturnDesc,
+    ACPI_WALK_STATE         *WalkState,
+    BOOLEAN                 AddReference)
+{
+    ACPI_FUNCTION_NAME (DsDoImplicitReturn);
+
+
+    /*
+     * Slack must be enabled for this feature, and we must
+     * have a valid return object
+     */
+    if ((!AcpiGbl_EnableInterpreterSlack) ||
+        (!ReturnDesc))
+    {
+        return (FALSE);
+    }
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "Result %p will be implicitly returned; Prev=%p\n",
+        ReturnDesc,
+        WalkState->ImplicitReturnObj));
+
+    /*
+     * Delete any "stale" implicit return value first. However, in
+     * complex statements, the implicit return value can be
+     * bubbled up several levels, so we don't clear the value if it
+     * is the same as the ReturnDesc.
+     */
+    if (WalkState->ImplicitReturnObj)
+    {
+        if (WalkState->ImplicitReturnObj == ReturnDesc)
+        {
+            return (TRUE);
+        }
+        AcpiDsClearImplicitReturn (WalkState);
+    }
+
+    /* Save the implicit return value, add a reference if requested */
+
+    WalkState->ImplicitReturnObj = ReturnDesc;
+    if (AddReference)
+    {
+        AcpiUtAddReference (ReturnDesc);
+    }
+
+    return (TRUE);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsIsResultUsed
+ *
+ * PARAMETERS:  Op                  - Current Op
+ *              WalkState           - Current State
+ *
+ * RETURN:      TRUE if result is used, FALSE otherwise
+ *
+ * DESCRIPTION: Check if a result object will be used by the parent
+ *
+ ******************************************************************************/
+
+BOOLEAN
+AcpiDsIsResultUsed (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_WALK_STATE         *WalkState)
+{
+    const ACPI_OPCODE_INFO  *ParentInfo;
+
+    ACPI_FUNCTION_TRACE_PTR (DsIsResultUsed, Op);
+
+
+    /* Must have both an Op and a Result Object */
+
+    if (!Op)
+    {
+        ACPI_ERROR ((AE_INFO, "Null Op"));
+        return_UINT8 (TRUE);
+    }
+
+    /*
+     * We know that this operator is not a
+     * Return() operator (would not come here.) The following code is the
+     * optional support for a so-called "implicit return". Some AML code
+     * assumes that the last value of the method is "implicitly" returned
+     * to the caller. Just save the last result as the return value.
+     * NOTE: this is optional because the ASL language does not actually
+     * support this behavior.
+     */
+    (void) AcpiDsDoImplicitReturn (WalkState->ResultObj, WalkState, TRUE);
+
+    /*
+     * Now determine if the parent will use the result
+     *
+     * If there is no parent, or the parent is a ScopeOp, we are executing
+     * at the method level. An executing method typically has no parent,
+     * since each method is parsed separately. A method invoked externally
+     * via ExecuteControlMethod has a ScopeOp as the parent.
+     */
+    if ((!Op->Common.Parent) ||
+        (Op->Common.Parent->Common.AmlOpcode == AML_SCOPE_OP))
+    {
+        /* No parent, the return value cannot possibly be used */
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "At Method level, result of [%s] not used\n",
+            AcpiPsGetOpcodeName (Op->Common.AmlOpcode)));
+        return_UINT8 (FALSE);
+    }
+
+    /* Get info on the parent. The RootOp is AML_SCOPE */
+
+    ParentInfo = AcpiPsGetOpcodeInfo (Op->Common.Parent->Common.AmlOpcode);
+    if (ParentInfo->Class == AML_CLASS_UNKNOWN)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "Unknown parent opcode Op=%p", Op));
+        return_UINT8 (FALSE);
+    }
+
+    /*
+     * Decide what to do with the result based on the parent. If
+     * the parent opcode will not use the result, delete the object.
+     * Otherwise leave it as is, it will be deleted when it is used
+     * as an operand later.
+     */
+    switch (ParentInfo->Class)
+    {
+    case AML_CLASS_CONTROL:
+
+        switch (Op->Common.Parent->Common.AmlOpcode)
+        {
+        case AML_RETURN_OP:
+
+            /* Never delete the return value associated with a return opcode */
+
+            goto ResultUsed;
+
+        case AML_IF_OP:
+        case AML_WHILE_OP:
+            /*
+             * If we are executing the predicate AND this is the predicate op,
+             * we will use the return value
+             */
+            if ((WalkState->ControlState->Common.State ==
+                    ACPI_CONTROL_PREDICATE_EXECUTING) &&
+                (WalkState->ControlState->Control.PredicateOp == Op))
+            {
+                goto ResultUsed;
+            }
+            break;
+
+        default:
+
+            /* Ignore other control opcodes */
+
+            break;
+        }
+
+        /* The general control opcode returns no result */
+
+        goto ResultNotUsed;
+
+    case AML_CLASS_CREATE:
+        /*
+         * These opcodes allow TermArg(s) as operands and therefore
+         * the operands can be method calls. The result is used.
+         */
+        goto ResultUsed;
+
+    case AML_CLASS_NAMED_OBJECT:
+
+        if ((Op->Common.Parent->Common.AmlOpcode == AML_REGION_OP)       ||
+            (Op->Common.Parent->Common.AmlOpcode == AML_DATA_REGION_OP)  ||
+            (Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP)      ||
+            (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)  ||
+            (Op->Common.Parent->Common.AmlOpcode == AML_BUFFER_OP)       ||
+            (Op->Common.Parent->Common.AmlOpcode == AML_INT_EVAL_SUBTREE_OP) ||
+            (Op->Common.Parent->Common.AmlOpcode == AML_BANK_FIELD_OP))
+        {
+            /*
+             * These opcodes allow TermArg(s) as operands and therefore
+             * the operands can be method calls. The result is used.
+             */
+            goto ResultUsed;
+        }
+
+        goto ResultNotUsed;
+
+    default:
+        /*
+         * In all other cases. the parent will actually use the return
+         * object, so keep it.
+         */
+        goto ResultUsed;
+    }
+
+
+ResultUsed:
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "Result of [%s] used by Parent [%s] Op=%p\n",
+        AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
+        AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op));
+
+    return_UINT8 (TRUE);
+
+
+ResultNotUsed:
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "Result of [%s] not used by Parent [%s] Op=%p\n",
+        AcpiPsGetOpcodeName (Op->Common.AmlOpcode),
+        AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), Op));
+
+    return_UINT8 (FALSE);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsDeleteResultIfNotUsed
+ *
+ * PARAMETERS:  Op              - Current parse Op
+ *              ResultObj       - Result of the operation
+ *              WalkState       - Current state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
+ *              result descriptor, check if the parent opcode will actually use
+ *              this result. If not, delete the result now so that it will
+ *              not become orphaned.
+ *
+ ******************************************************************************/
+
+void
+AcpiDsDeleteResultIfNotUsed (
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_OPERAND_OBJECT     *ResultObj,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsDeleteResultIfNotUsed, ResultObj);
+
+
+    if (!Op)
+    {
+        ACPI_ERROR ((AE_INFO, "Null Op"));
+        return_VOID;
+    }
+
+    if (!ResultObj)
+    {
+        return_VOID;
+    }
+
+    if (!AcpiDsIsResultUsed (Op, WalkState))
+    {
+        /* Must pop the result stack (ObjDesc should be equal to ResultObj) */
+
+        Status = AcpiDsResultPop (&ObjDesc, WalkState);
+        if (ACPI_SUCCESS (Status))
+        {
+            AcpiUtRemoveReference (ResultObj);
+        }
+    }
+
+    return_VOID;
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsResolveOperands
+ *
+ * PARAMETERS:  WalkState           - Current walk state with operands on stack
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Resolve all operands to their values. Used to prepare
+ *              arguments to a control method invocation (a call from one
+ *              method to another.)
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsResolveOperands (
+    ACPI_WALK_STATE         *WalkState)
+{
+    UINT32                  i;
+    ACPI_STATUS             Status = AE_OK;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsResolveOperands, WalkState);
+
+
+    /*
+     * Attempt to resolve each of the valid operands
+     * Method arguments are passed by reference, not by value. This means
+     * that the actual objects are passed, not copies of the objects.
+     */
+    for (i = 0; i < WalkState->NumOperands; i++)
+    {
+        Status = AcpiExResolveToValue (&WalkState->Operands[i], WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            break;
+        }
+    }
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsClearOperands
+ *
+ * PARAMETERS:  WalkState           - Current walk state with operands on stack
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Clear all operands on the current walk state operand stack.
+ *
+ ******************************************************************************/
+
+void
+AcpiDsClearOperands (
+    ACPI_WALK_STATE         *WalkState)
+{
+    UINT32                  i;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsClearOperands, WalkState);
+
+
+    /* Remove a reference on each operand on the stack */
+
+    for (i = 0; i < WalkState->NumOperands; i++)
+    {
+        /*
+         * Remove a reference to all operands, including both
+         * "Arguments" and "Targets".
+         */
+        AcpiUtRemoveReference (WalkState->Operands[i]);
+        WalkState->Operands[i] = NULL;
+    }
+
+    WalkState->NumOperands = 0;
+    return_VOID;
+}
+#endif
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCreateOperand
+ *
+ * PARAMETERS:  WalkState       - Current walk state
+ *              Arg             - Parse object for the argument
+ *              ArgIndex        - Which argument (zero based)
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Translate a parse tree object that is an argument to an AML
+ *              opcode to the equivalent interpreter object. This may include
+ *              looking up a name or entering a new name into the internal
+ *              namespace.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsCreateOperand (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Arg,
+    UINT32                  ArgIndex)
+{
+    ACPI_STATUS             Status = AE_OK;
+    char                    *NameString;
+    UINT32                  NameLength;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_PARSE_OBJECT       *ParentOp;
+    UINT16                  Opcode;
+    ACPI_INTERPRETER_MODE   InterpreterMode;
+    const ACPI_OPCODE_INFO  *OpInfo;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsCreateOperand, Arg);
+
+
+    /* A valid name must be looked up in the namespace */
+
+    if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
+        (Arg->Common.Value.String) &&
+        !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
+    {
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", Arg));
+
+        /* Get the entire name string from the AML stream */
+
+        Status = AcpiExGetNameString (ACPI_TYPE_ANY,
+            Arg->Common.Value.Buffer, &NameString, &NameLength);
+
+        if (ACPI_FAILURE (Status))
+        {
+            return_ACPI_STATUS (Status);
+        }
+
+        /* All prefixes have been handled, and the name is in NameString */
+
+        /*
+         * Special handling for BufferField declarations. This is a deferred
+         * opcode that unfortunately defines the field name as the last
+         * parameter instead of the first. We get here when we are performing
+         * the deferred execution, so the actual name of the field is already
+         * in the namespace. We don't want to attempt to look it up again
+         * because we may be executing in a different scope than where the
+         * actual opcode exists.
+         */
+        if ((WalkState->DeferredNode) &&
+            (WalkState->DeferredNode->Type == ACPI_TYPE_BUFFER_FIELD) &&
+            (ArgIndex == (UINT32)
+                ((WalkState->Opcode == AML_CREATE_FIELD_OP) ? 3 : 2)))
+        {
+            ObjDesc = ACPI_CAST_PTR (
+                ACPI_OPERAND_OBJECT, WalkState->DeferredNode);
+            Status = AE_OK;
+        }
+        else    /* All other opcodes */
+        {
+            /*
+             * Differentiate between a namespace "create" operation
+             * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
+             * IMODE_EXECUTE) in order to support the creation of
+             * namespace objects during the execution of control methods.
+             */
+            ParentOp = Arg->Common.Parent;
+            OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);
+
+            if ((OpInfo->Flags & AML_NSNODE) &&
+                (ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&
+                (ParentOp->Common.AmlOpcode != AML_REGION_OP) &&
+                (ParentOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP))
+            {
+                /* Enter name into namespace if not found */
+
+                InterpreterMode = ACPI_IMODE_LOAD_PASS2;
+            }
+            else
+            {
+                /* Return a failure if name not found */
+
+                InterpreterMode = ACPI_IMODE_EXECUTE;
+            }
+
+            Status = AcpiNsLookup (WalkState->ScopeInfo, NameString,
+                ACPI_TYPE_ANY, InterpreterMode,
+                ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, WalkState,
+                ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, &ObjDesc));
+            /*
+             * The only case where we pass through (ignore) a NOT_FOUND
+             * error is for the CondRefOf opcode.
+             */
+            if (Status == AE_NOT_FOUND)
+            {
+                if (ParentOp->Common.AmlOpcode == AML_COND_REF_OF_OP)
+                {
+                    /*
+                     * For the Conditional Reference op, it's OK if
+                     * the name is not found;  We just need a way to
+                     * indicate this to the interpreter, set the
+                     * object to the root
+                     */
+                    ObjDesc = ACPI_CAST_PTR (
+                        ACPI_OPERAND_OBJECT, AcpiGbl_RootNode);
+                    Status = AE_OK;
+                }
+                else if (ParentOp->Common.AmlOpcode == AML_EXTERNAL_OP)
+                {
+                    /* TBD: May only be temporary */
+
+                    ObjDesc = AcpiUtCreateStringObject ((ACPI_SIZE) NameLength);
+
+                    strncpy (ObjDesc->String.Pointer, NameString, NameLength);
+                    Status = AE_OK;
+                }
+                else
+                {
+                    /*
+                     * We just plain didn't find it -- which is a
+                     * very serious error at this point
+                     */
+                    Status = AE_AML_NAME_NOT_FOUND;
+                }
+            }
+
+            if (ACPI_FAILURE (Status))
+            {
+                ACPI_ERROR_NAMESPACE (NameString, Status);
+            }
+        }
+
+        /* Free the namestring created above */
+
+        ACPI_FREE (NameString);
+
+        /* Check status from the lookup */
+
+        if (ACPI_FAILURE (Status))
+        {
+            return_ACPI_STATUS (Status);
+        }
+
+        /* Put the resulting object onto the current object stack */
+
+        Status = AcpiDsObjStackPush (ObjDesc, WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            return_ACPI_STATUS (Status);
+        }
+
+        AcpiDbDisplayArgumentObject (ObjDesc, WalkState);
+    }
+    else
+    {
+        /* Check for null name case */
+
+        if ((Arg->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
+            !(Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
+        {
+            /*
+             * If the name is null, this means that this is an
+             * optional result parameter that was not specified
+             * in the original ASL. Create a Zero Constant for a
+             * placeholder. (Store to a constant is a Noop.)
+             */
+            Opcode = AML_ZERO_OP;       /* Has no arguments! */
+
+            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+                "Null namepath: Arg=%p\n", Arg));
+        }
+        else
+        {
+            Opcode = Arg->Common.AmlOpcode;
+        }
+
+        /* Get the object type of the argument */
+
+        OpInfo = AcpiPsGetOpcodeInfo (Opcode);
+        if (OpInfo->ObjectType == ACPI_TYPE_INVALID)
+        {
+            return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
+        }
+
+        if ((OpInfo->Flags & AML_HAS_RETVAL) ||
+            (Arg->Common.Flags & ACPI_PARSEOP_IN_STACK))
+        {
+            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+                "Argument previously created, already stacked\n"));
+
+            AcpiDbDisplayArgumentObject (
+                WalkState->Operands [WalkState->NumOperands - 1], WalkState);
+
+            /*
+             * Use value that was already previously returned
+             * by the evaluation of this argument
+             */
+            Status = AcpiDsResultPop (&ObjDesc, WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                /*
+                 * Only error is underflow, and this indicates
+                 * a missing or null operand!
+                 */
+                ACPI_EXCEPTION ((AE_INFO, Status,
+                    "Missing or null operand"));
+                return_ACPI_STATUS (Status);
+            }
+        }
+        else
+        {
+            /* Create an ACPI_INTERNAL_OBJECT for the argument */
+
+            ObjDesc = AcpiUtCreateInternalObject (OpInfo->ObjectType);
+            if (!ObjDesc)
+            {
+                return_ACPI_STATUS (AE_NO_MEMORY);
+            }
+
+            /* Initialize the new object */
+
+            Status = AcpiDsInitObjectFromOp (
+                WalkState, Arg, Opcode, &ObjDesc);
+            if (ACPI_FAILURE (Status))
+            {
+                AcpiUtDeleteObjectDesc (ObjDesc);
+                return_ACPI_STATUS (Status);
+            }
+        }
+
+        /* Put the operand object on the object stack */
+
+        Status = AcpiDsObjStackPush (ObjDesc, WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            return_ACPI_STATUS (Status);
+        }
+
+        AcpiDbDisplayArgumentObject (ObjDesc, WalkState);
+    }
+
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCreateOperands
+ *
+ * PARAMETERS:  WalkState           - Current state
+ *              FirstArg            - First argument of a parser argument tree
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Convert an operator's arguments from a parse tree format to
+ *              namespace objects and place those argument object on the object
+ *              stack in preparation for evaluation by the interpreter.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsCreateOperands (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *FirstArg)
+{
+    ACPI_STATUS             Status = AE_OK;
+    ACPI_PARSE_OBJECT       *Arg;
+    ACPI_PARSE_OBJECT       *Arguments[ACPI_OBJ_NUM_OPERANDS];
+    UINT32                  ArgCount = 0;
+    UINT32                  Index = WalkState->NumOperands;
+    UINT32                  i;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsCreateOperands, FirstArg);
+
+
+    /* Get all arguments in the list */
+
+    Arg = FirstArg;
+    while (Arg)
+    {
+        if (Index >= ACPI_OBJ_NUM_OPERANDS)
+        {
+            return_ACPI_STATUS (AE_BAD_DATA);
+        }
+
+        Arguments[Index] = Arg;
+        WalkState->Operands [Index] = NULL;
+
+        /* Move on to next argument, if any */
+
+        Arg = Arg->Common.Next;
+        ArgCount++;
+        Index++;
+    }
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "NumOperands %d, ArgCount %d, Index %d\n",
+        WalkState->NumOperands, ArgCount, Index));
+
+    /* Create the interpreter arguments, in reverse order */
+
+    Index--;
+    for (i = 0; i < ArgCount; i++)
+    {
+        Arg = Arguments[Index];
+        WalkState->OperandIndex = (UINT8) Index;
+
+        Status = AcpiDsCreateOperand (WalkState, Arg, Index);
+        if (ACPI_FAILURE (Status))
+        {
+            goto Cleanup;
+        }
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "Created Arg #%u (%p) %u args total\n",
+            Index, Arg, ArgCount));
+        Index--;
+    }
+
+    return_ACPI_STATUS (Status);
+
+
+Cleanup:
+    /*
+     * We must undo everything done above; meaning that we must
+     * pop everything off of the operand stack and delete those
+     * objects
+     */
+    AcpiDsObjStackPopAndDelete (ArgCount, WalkState);
+
+    ACPI_EXCEPTION ((AE_INFO, Status, "While creating Arg %u", Index));
+    return_ACPI_STATUS (Status);
+}
+
+
+/*****************************************************************************
+ *
+ * FUNCTION:    AcpiDsEvaluateNamePath
+ *
+ * PARAMETERS:  WalkState       - Current state of the parse tree walk,
+ *                                the opcode of current operation should be
+ *                                AML_INT_NAMEPATH_OP
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Translate the -NamePath- parse tree object to the equivalent
+ *              interpreter object, convert it to value, if needed, duplicate
+ *              it, if needed, and push it onto the current result stack.
+ *
+ ****************************************************************************/
+
+ACPI_STATUS
+AcpiDsEvaluateNamePath (
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_STATUS             Status = AE_OK;
+    ACPI_PARSE_OBJECT       *Op = WalkState->Op;
+    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
+    ACPI_OPERAND_OBJECT     *NewObjDesc;
+    UINT8                   Type;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsEvaluateNamePath, WalkState);
+
+
+    if (!Op->Common.Parent)
+    {
+        /* This happens after certain exception processing */
+
+        goto Exit;
+    }
+
+    if ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
+        (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP) ||
+        (Op->Common.Parent->Common.AmlOpcode == AML_REF_OF_OP))
+    {
+        /* TBD: Should we specify this feature as a bit of OpInfo->Flags of these opcodes? */
+
+        goto Exit;
+    }
+
+    Status = AcpiDsCreateOperand (WalkState, Op, 0);
+    if (ACPI_FAILURE (Status))
+    {
+        goto Exit;
+    }
+
+    if (Op->Common.Flags & ACPI_PARSEOP_TARGET)
+    {
+        NewObjDesc = *Operand;
+        goto PushResult;
+    }
+
+    Type = (*Operand)->Common.Type;
+
+    Status = AcpiExResolveToValue (Operand, WalkState);
+    if (ACPI_FAILURE (Status))
+    {
+        goto Exit;
+    }
+
+    if (Type == ACPI_TYPE_INTEGER)
+    {
+        /* It was incremented by AcpiExResolveToValue */
+
+        AcpiUtRemoveReference (*Operand);
+
+        Status = AcpiUtCopyIobjectToIobject (
+            *Operand, &NewObjDesc, WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            goto Exit;
+        }
+    }
+    else
+    {
+        /*
+         * The object either was anew created or is
+         * a Namespace node - don't decrement it.
+         */
+        NewObjDesc = *Operand;
+    }
+
+    /* Cleanup for name-path operand */
+
+    Status = AcpiDsObjStackPop (1, WalkState);
+    if (ACPI_FAILURE (Status))
+    {
+        WalkState->ResultObj = NewObjDesc;
+        goto Exit;
+    }
+
+PushResult:
+
+    WalkState->ResultObj = NewObjDesc;
+
+    Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
+    if (ACPI_SUCCESS (Status))
+    {
+        /* Force to take it from stack */
+
+        Op->Common.Flags |= ACPI_PARSEOP_IN_STACK;
+    }
+
+Exit:
+
+    return_ACPI_STATUS (Status);
+}

+ 789 - 0
kernel/src/acpica/dispatcher/dswexec.c

@@ -0,0 +1,789 @@
+/******************************************************************************
+ *
+ * Module Name: dswexec - Dispatcher method execution callbacks;
+ *                        dispatch to interpreter.
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acparser.h"
+#include "amlcode.h"
+#include "acdispat.h"
+#include "acinterp.h"
+#include "acnamesp.h"
+#include "acdebug.h"
+
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dswexec")
+
+/*
+ * Dispatch table for opcode classes
+ */
+static ACPI_EXECUTE_OP      AcpiGbl_OpTypeDispatch [] =
+{
+    AcpiExOpcode_0A_0T_1R,
+    AcpiExOpcode_1A_0T_0R,
+    AcpiExOpcode_1A_0T_1R,
+    AcpiExOpcode_1A_1T_0R,
+    AcpiExOpcode_1A_1T_1R,
+    AcpiExOpcode_2A_0T_0R,
+    AcpiExOpcode_2A_0T_1R,
+    AcpiExOpcode_2A_1T_1R,
+    AcpiExOpcode_2A_2T_1R,
+    AcpiExOpcode_3A_0T_0R,
+    AcpiExOpcode_3A_1T_1R,
+    AcpiExOpcode_6A_0T_1R
+};
+
+
+/*****************************************************************************
+ *
+ * FUNCTION:    AcpiDsGetPredicateValue
+ *
+ * PARAMETERS:  WalkState       - Current state of the parse tree walk
+ *              ResultObj       - if non-zero, pop result from result stack
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Get the result of a predicate evaluation
+ *
+ ****************************************************************************/
+
+ACPI_STATUS
+AcpiDsGetPredicateValue (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_OPERAND_OBJECT     *ResultObj)
+{
+    ACPI_STATUS             Status = AE_OK;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_OPERAND_OBJECT     *LocalObjDesc = NULL;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsGetPredicateValue, WalkState);
+
+
+    WalkState->ControlState->Common.State = 0;
+
+    if (ResultObj)
+    {
+        Status = AcpiDsResultPop (&ObjDesc, WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_EXCEPTION ((AE_INFO, Status,
+                "Could not get result from predicate evaluation"));
+
+            return_ACPI_STATUS (Status);
+        }
+    }
+    else
+    {
+        Status = AcpiDsCreateOperand (WalkState, WalkState->Op, 0);
+        if (ACPI_FAILURE (Status))
+        {
+            return_ACPI_STATUS (Status);
+        }
+
+        Status = AcpiExResolveToValue (&WalkState->Operands [0], WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            return_ACPI_STATUS (Status);
+        }
+
+        ObjDesc = WalkState->Operands [0];
+    }
+
+    if (!ObjDesc)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "No predicate ObjDesc=%p State=%p",
+            ObjDesc, WalkState));
+
+        return_ACPI_STATUS (AE_AML_NO_OPERAND);
+    }
+
+    /*
+     * Result of predicate evaluation must be an Integer
+     * object. Implicitly convert the argument if necessary.
+     */
+    Status = AcpiExConvertToInteger (ObjDesc, &LocalObjDesc, 16);
+    if (ACPI_FAILURE (Status))
+    {
+        goto Cleanup;
+    }
+
+    if (LocalObjDesc->Common.Type != ACPI_TYPE_INTEGER)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "Bad predicate (not an integer) ObjDesc=%p State=%p Type=0x%X",
+            ObjDesc, WalkState, ObjDesc->Common.Type));
+
+        Status = AE_AML_OPERAND_TYPE;
+        goto Cleanup;
+    }
+
+    /* Truncate the predicate to 32-bits if necessary */
+
+    (void) AcpiExTruncateFor32bitTable (LocalObjDesc);
+
+    /*
+     * Save the result of the predicate evaluation on
+     * the control stack
+     */
+    if (LocalObjDesc->Integer.Value)
+    {
+        WalkState->ControlState->Common.Value = TRUE;
+    }
+    else
+    {
+        /*
+         * Predicate is FALSE, we will just toss the
+         * rest of the package
+         */
+        WalkState->ControlState->Common.Value = FALSE;
+        Status = AE_CTRL_FALSE;
+    }
+
+    /* Predicate can be used for an implicit return value */
+
+    (void) AcpiDsDoImplicitReturn (LocalObjDesc, WalkState, TRUE);
+
+
+Cleanup:
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+        "Completed a predicate eval=%X Op=%p\n",
+        WalkState->ControlState->Common.Value, WalkState->Op));
+
+    /* Break to debugger to display result */
+
+    AcpiDbDisplayResultObject (LocalObjDesc, WalkState);
+
+    /*
+     * Delete the predicate result object (we know that
+     * we don't need it anymore)
+     */
+    if (LocalObjDesc != ObjDesc)
+    {
+        AcpiUtRemoveReference (LocalObjDesc);
+    }
+    AcpiUtRemoveReference (ObjDesc);
+
+    WalkState->ControlState->Common.State = ACPI_CONTROL_NORMAL;
+    return_ACPI_STATUS (Status);
+}
+
+
+/*****************************************************************************
+ *
+ * FUNCTION:    AcpiDsExecBeginOp
+ *
+ * PARAMETERS:  WalkState       - Current state of the parse tree walk
+ *              OutOp           - Where to return op if a new one is created
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Descending callback used during the execution of control
+ *              methods. This is where most operators and operands are
+ *              dispatched to the interpreter.
+ *
+ ****************************************************************************/
+
+ACPI_STATUS
+AcpiDsExecBeginOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       **OutOp)
+{
+    ACPI_PARSE_OBJECT       *Op;
+    ACPI_STATUS             Status = AE_OK;
+    UINT32                  OpcodeClass;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsExecBeginOp, WalkState);
+
+
+    Op = WalkState->Op;
+    if (!Op)
+    {
+        Status = AcpiDsLoad2BeginOp (WalkState, OutOp);
+        if (ACPI_FAILURE (Status))
+        {
+            goto ErrorExit;
+        }
+
+        Op = *OutOp;
+        WalkState->Op = Op;
+        WalkState->Opcode = Op->Common.AmlOpcode;
+        WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
+
+        if (AcpiNsOpensScope (WalkState->OpInfo->ObjectType))
+        {
+            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+                "(%s) Popping scope for Op %p\n",
+                AcpiUtGetTypeName (WalkState->OpInfo->ObjectType), Op));
+
+            Status = AcpiDsScopeStackPop (WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                goto ErrorExit;
+            }
+        }
+    }
+
+    if (Op == WalkState->Origin)
+    {
+        if (OutOp)
+        {
+            *OutOp = Op;
+        }
+
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /*
+     * If the previous opcode was a conditional, this opcode
+     * must be the beginning of the associated predicate.
+     * Save this knowledge in the current scope descriptor
+     */
+    if ((WalkState->ControlState) &&
+        (WalkState->ControlState->Common.State ==
+            ACPI_CONTROL_CONDITIONAL_EXECUTING))
+    {
+        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+            "Exec predicate Op=%p State=%p\n",
+            Op, WalkState));
+
+        WalkState->ControlState->Common.State =
+            ACPI_CONTROL_PREDICATE_EXECUTING;
+
+        /* Save start of predicate */
+
+        WalkState->ControlState->Control.PredicateOp = Op;
+    }
+
+
+    OpcodeClass = WalkState->OpInfo->Class;
+
+    /* We want to send namepaths to the load code */
+
+    if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
+    {
+        OpcodeClass = AML_CLASS_NAMED_OBJECT;
+    }
+
+    /*
+     * Handle the opcode based upon the opcode type
+     */
+    switch (OpcodeClass)
+    {
+    case AML_CLASS_CONTROL:
+
+        Status = AcpiDsExecBeginControlOp (WalkState, Op);
+        break;
+
+    case AML_CLASS_NAMED_OBJECT:
+
+        if (WalkState->WalkType & ACPI_WALK_METHOD)
+        {
+            /*
+             * Found a named object declaration during method execution;
+             * we must enter this object into the namespace. The created
+             * object is temporary and will be deleted upon completion of
+             * the execution of this method.
+             *
+             * Note 10/2010: Except for the Scope() op. This opcode does
+             * not actually create a new object, it refers to an existing
+             * object. However, for Scope(), we want to indeed open a
+             * new scope.
+             */
+            if (Op->Common.AmlOpcode != AML_SCOPE_OP)
+            {
+                Status = AcpiDsLoad2BeginOp (WalkState, NULL);
+            }
+            else
+            {
+                Status = AcpiDsScopeStackPush (
+                    Op->Named.Node, Op->Named.Node->Type, WalkState);
+                if (ACPI_FAILURE (Status))
+                {
+                    return_ACPI_STATUS (Status);
+                }
+            }
+        }
+        break;
+
+    case AML_CLASS_EXECUTE:
+    case AML_CLASS_CREATE:
+
+        break;
+
+    default:
+
+        break;
+    }
+
+    /* Nothing to do here during method execution */
+
+    return_ACPI_STATUS (Status);
+
+
+ErrorExit:
+    Status = AcpiDsMethodError (Status, WalkState);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*****************************************************************************
+ *
+ * FUNCTION:    AcpiDsExecEndOp
+ *
+ * PARAMETERS:  WalkState       - Current state of the parse tree walk
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Ascending callback used during the execution of control
+ *              methods. The only thing we really need to do here is to
+ *              notice the beginning of IF, ELSE, and WHILE blocks.
+ *
+ ****************************************************************************/
+
+ACPI_STATUS
+AcpiDsExecEndOp (
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_PARSE_OBJECT       *Op;
+    ACPI_STATUS             Status = AE_OK;
+    UINT32                  OpType;
+    UINT32                  OpClass;
+    ACPI_PARSE_OBJECT       *NextOp;
+    ACPI_PARSE_OBJECT       *FirstArg;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsExecEndOp, WalkState);
+
+
+    Op = WalkState->Op;
+    OpType = WalkState->OpInfo->Type;
+    OpClass = WalkState->OpInfo->Class;
+
+    if (OpClass == AML_CLASS_UNKNOWN)
+    {
+        ACPI_ERROR ((AE_INFO, "Unknown opcode 0x%X", Op->Common.AmlOpcode));
+        return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
+    }
+
+    FirstArg = Op->Common.Value.Arg;
+
+    /* Init the walk state */
+
+    WalkState->NumOperands = 0;
+    WalkState->OperandIndex = 0;
+    WalkState->ReturnDesc = NULL;
+    WalkState->ResultObj = NULL;
+
+    /* Call debugger for single step support (DEBUG build only) */
+
+    Status = AcpiDbSingleStep (WalkState, Op, OpClass);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Decode the Opcode Class */
+
+    switch (OpClass)
+    {
+    case AML_CLASS_ARGUMENT:    /* Constants, literals, etc. */
+
+        if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
+        {
+            Status = AcpiDsEvaluateNamePath (WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                goto Cleanup;
+            }
+        }
+        break;
+
+    case AML_CLASS_EXECUTE:     /* Most operators with arguments */
+
+        /* Build resolved operand stack */
+
+        Status = AcpiDsCreateOperands (WalkState, FirstArg);
+        if (ACPI_FAILURE (Status))
+        {
+            goto Cleanup;
+        }
+
+        /*
+         * All opcodes require operand resolution, with the only exceptions
+         * being the ObjectType and SizeOf operators.
+         */
+        if (!(WalkState->OpInfo->Flags & AML_NO_OPERAND_RESOLVE))
+        {
+            /* Resolve all operands */
+
+            Status = AcpiExResolveOperands (WalkState->Opcode,
+                &(WalkState->Operands [WalkState->NumOperands -1]),
+                WalkState);
+        }
+
+        if (ACPI_SUCCESS (Status))
+        {
+            /*
+             * Dispatch the request to the appropriate interpreter handler
+             * routine. There is one routine per opcode "type" based upon the
+             * number of opcode arguments and return type.
+             */
+            Status = AcpiGbl_OpTypeDispatch[OpType] (WalkState);
+        }
+        else
+        {
+            /*
+             * Treat constructs of the form "Store(LocalX,LocalX)" as noops when the
+             * Local is uninitialized.
+             */
+            if  ((Status == AE_AML_UNINITIALIZED_LOCAL) &&
+                (WalkState->Opcode == AML_STORE_OP) &&
+                (WalkState->Operands[0]->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
+                (WalkState->Operands[1]->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
+                (WalkState->Operands[0]->Reference.Class ==
+                 WalkState->Operands[1]->Reference.Class) &&
+                (WalkState->Operands[0]->Reference.Value ==
+                 WalkState->Operands[1]->Reference.Value))
+            {
+                Status = AE_OK;
+            }
+            else
+            {
+                ACPI_EXCEPTION ((AE_INFO, Status,
+                    "While resolving operands for [%s]",
+                    AcpiPsGetOpcodeName (WalkState->Opcode)));
+            }
+        }
+
+        /* Always delete the argument objects and clear the operand stack */
+
+        AcpiDsClearOperands (WalkState);
+
+        /*
+         * If a result object was returned from above, push it on the
+         * current result stack
+         */
+        if (ACPI_SUCCESS (Status) &&
+            WalkState->ResultObj)
+        {
+            Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
+        }
+        break;
+
+    default:
+
+        switch (OpType)
+        {
+        case AML_TYPE_CONTROL:    /* Type 1 opcode, IF/ELSE/WHILE/NOOP */
+
+            /* 1 Operand, 0 ExternalResult, 0 InternalResult */
+
+            Status = AcpiDsExecEndControlOp (WalkState, Op);
+
+            break;
+
+        case AML_TYPE_METHOD_CALL:
+            /*
+             * If the method is referenced from within a package
+             * declaration, it is not a invocation of the method, just
+             * a reference to it.
+             */
+            if ((Op->Asl.Parent) &&
+               ((Op->Asl.Parent->Asl.AmlOpcode == AML_PACKAGE_OP) ||
+                (Op->Asl.Parent->Asl.AmlOpcode == AML_VAR_PACKAGE_OP)))
+            {
+                ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+                    "Method Reference in a Package, Op=%p\n", Op));
+
+                Op->Common.Node = (ACPI_NAMESPACE_NODE *)
+                    Op->Asl.Value.Arg->Asl.Node;
+                AcpiUtAddReference (Op->Asl.Value.Arg->Asl.Node->Object);
+                return_ACPI_STATUS (AE_OK);
+            }
+
+            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+                "Method invocation, Op=%p\n", Op));
+
+            /*
+             * (AML_METHODCALL) Op->Asl.Value.Arg->Asl.Node contains
+             * the method Node pointer
+             */
+            /* NextOp points to the op that holds the method name */
+
+            NextOp = FirstArg;
+
+            /* NextOp points to first argument op */
+
+            NextOp = NextOp->Common.Next;
+
+            /*
+             * Get the method's arguments and put them on the operand stack
+             */
+            Status = AcpiDsCreateOperands (WalkState, NextOp);
+            if (ACPI_FAILURE (Status))
+            {
+                break;
+            }
+
+            /*
+             * Since the operands will be passed to another control method,
+             * we must resolve all local references here (Local variables,
+             * arguments to *this* method, etc.)
+             */
+            Status = AcpiDsResolveOperands (WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                /* On error, clear all resolved operands */
+
+                AcpiDsClearOperands (WalkState);
+                break;
+            }
+
+            /*
+             * Tell the walk loop to preempt this running method and
+             * execute the new method
+             */
+            Status = AE_CTRL_TRANSFER;
+
+            /*
+             * Return now; we don't want to disturb anything,
+             * especially the operand count!
+             */
+            return_ACPI_STATUS (Status);
+
+        case AML_TYPE_CREATE_FIELD:
+
+            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+                "Executing CreateField Buffer/Index Op=%p\n", Op));
+
+            Status = AcpiDsLoad2EndOp (WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                break;
+            }
+
+            Status = AcpiDsEvalBufferFieldOperands (WalkState, Op);
+            break;
+
+
+        case AML_TYPE_CREATE_OBJECT:
+
+            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+                "Executing CreateObject (Buffer/Package) Op=%p\n", Op));
+
+            switch (Op->Common.Parent->Common.AmlOpcode)
+            {
+            case AML_NAME_OP:
+                /*
+                 * Put the Node on the object stack (Contains the ACPI Name
+                 * of this object)
+                 */
+                WalkState->Operands[0] = (void *)
+                    Op->Common.Parent->Common.Node;
+                WalkState->NumOperands = 1;
+
+                Status = AcpiDsCreateNode (WalkState,
+                    Op->Common.Parent->Common.Node, Op->Common.Parent);
+                if (ACPI_FAILURE (Status))
+                {
+                    break;
+                }
+
+                /* Fall through */
+                /*lint -fallthrough */
+
+            case AML_INT_EVAL_SUBTREE_OP:
+
+                Status = AcpiDsEvalDataObjectOperands (WalkState, Op,
+                    AcpiNsGetAttachedObject (Op->Common.Parent->Common.Node));
+                break;
+
+            default:
+
+                Status = AcpiDsEvalDataObjectOperands (WalkState, Op, NULL);
+                break;
+            }
+
+            /*
+             * If a result object was returned from above, push it on the
+             * current result stack
+             */
+            if (WalkState->ResultObj)
+            {
+                Status = AcpiDsResultPush (WalkState->ResultObj, WalkState);
+            }
+            break;
+
+        case AML_TYPE_NAMED_FIELD:
+        case AML_TYPE_NAMED_COMPLEX:
+        case AML_TYPE_NAMED_SIMPLE:
+        case AML_TYPE_NAMED_NO_OBJ:
+
+            Status = AcpiDsLoad2EndOp (WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                break;
+            }
+
+            if (Op->Common.AmlOpcode == AML_REGION_OP)
+            {
+                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+                    "Executing OpRegion Address/Length Op=%p\n", Op));
+
+                Status = AcpiDsEvalRegionOperands (WalkState, Op);
+                if (ACPI_FAILURE (Status))
+                {
+                    break;
+                }
+            }
+            else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
+            {
+                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+                    "Executing DataTableRegion Strings Op=%p\n", Op));
+
+                Status = AcpiDsEvalTableRegionOperands (WalkState, Op);
+                if (ACPI_FAILURE (Status))
+                {
+                    break;
+                }
+            }
+            else if (Op->Common.AmlOpcode == AML_BANK_FIELD_OP)
+            {
+                ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+                    "Executing BankField Op=%p\n", Op));
+
+                Status = AcpiDsEvalBankFieldOperands (WalkState, Op);
+                if (ACPI_FAILURE (Status))
+                {
+                    break;
+                }
+            }
+            break;
+
+        case AML_TYPE_UNDEFINED:
+
+            ACPI_ERROR ((AE_INFO,
+                "Undefined opcode type Op=%p", Op));
+            return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
+
+        case AML_TYPE_BOGUS:
+
+            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+                "Internal opcode=%X type Op=%p\n",
+                WalkState->Opcode, Op));
+            break;
+
+        default:
+
+            ACPI_ERROR ((AE_INFO,
+                "Unimplemented opcode, class=0x%X "
+                "type=0x%X Opcode=0x%X Op=%p",
+                OpClass, OpType, Op->Common.AmlOpcode, Op));
+
+            Status = AE_NOT_IMPLEMENTED;
+            break;
+        }
+    }
+
+    /*
+     * ACPI 2.0 support for 64-bit integers: Truncate numeric
+     * result value if we are executing from a 32-bit ACPI table
+     */
+    (void) AcpiExTruncateFor32bitTable (WalkState->ResultObj);
+
+    /*
+     * Check if we just completed the evaluation of a
+     * conditional predicate
+     */
+    if ((ACPI_SUCCESS (Status)) &&
+        (WalkState->ControlState) &&
+        (WalkState->ControlState->Common.State ==
+            ACPI_CONTROL_PREDICATE_EXECUTING) &&
+        (WalkState->ControlState->Control.PredicateOp == Op))
+    {
+        Status = AcpiDsGetPredicateValue (WalkState, WalkState->ResultObj);
+        WalkState->ResultObj = NULL;
+    }
+
+
+Cleanup:
+
+    if (WalkState->ResultObj)
+    {
+        /* Break to debugger to display result */
+
+        AcpiDbDisplayResultObject (WalkState->ResultObj,WalkState);
+
+        /*
+         * Delete the result op if and only if:
+         * Parent will not use the result -- such as any
+         * non-nested type2 op in a method (parent will be method)
+         */
+        AcpiDsDeleteResultIfNotUsed (Op, WalkState->ResultObj, WalkState);
+    }
+
+#ifdef _UNDER_DEVELOPMENT
+
+    if (WalkState->ParserState.Aml == WalkState->ParserState.AmlEnd)
+    {
+        AcpiDbMethodEnd (WalkState);
+    }
+#endif
+
+    /* Invoke exception handler on error */
+
+    if (ACPI_FAILURE (Status))
+    {
+        Status = AcpiDsMethodError (Status, WalkState);
+    }
+
+    /* Always clear the object stack */
+
+    WalkState->NumOperands = 0;
+    return_ACPI_STATUS (Status);
+}

+ 593 - 0
kernel/src/acpica/dispatcher/dswload.c

@@ -0,0 +1,593 @@
+/******************************************************************************
+ *
+ * Module Name: dswload - Dispatcher first pass namespace load callbacks
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acparser.h"
+#include "amlcode.h"
+#include "acdispat.h"
+#include "acinterp.h"
+#include "acnamesp.h"
+
+#ifdef ACPI_ASL_COMPILER
+#include "acdisasm.h"
+#endif
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dswload")
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsInitCallbacks
+ *
+ * PARAMETERS:  WalkState       - Current state of the parse tree walk
+ *              PassNumber      - 1, 2, or 3
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Init walk state callbacks
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsInitCallbacks (
+    ACPI_WALK_STATE         *WalkState,
+    UINT32                  PassNumber)
+{
+
+    switch (PassNumber)
+    {
+    case 0:
+
+        /* Parse only - caller will setup callbacks */
+
+        WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
+                                        ACPI_PARSE_DELETE_TREE |
+                                        ACPI_PARSE_DISASSEMBLE;
+        WalkState->DescendingCallback = NULL;
+        WalkState->AscendingCallback  = NULL;
+        break;
+
+    case 1:
+
+        /* Load pass 1 */
+
+        WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
+                                        ACPI_PARSE_DELETE_TREE;
+        WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
+        WalkState->AscendingCallback  = AcpiDsLoad1EndOp;
+        break;
+
+    case 2:
+
+        /* Load pass 2 */
+
+        WalkState->ParseFlags         = ACPI_PARSE_LOAD_PASS1 |
+                                        ACPI_PARSE_DELETE_TREE;
+        WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
+        WalkState->AscendingCallback  = AcpiDsLoad2EndOp;
+        break;
+
+    case 3:
+
+        /* Execution pass */
+
+#ifndef ACPI_NO_METHOD_EXECUTION
+        WalkState->ParseFlags        |= ACPI_PARSE_EXECUTE  |
+                                        ACPI_PARSE_DELETE_TREE;
+        WalkState->DescendingCallback = AcpiDsExecBeginOp;
+        WalkState->AscendingCallback  = AcpiDsExecEndOp;
+#endif
+        break;
+
+    default:
+
+        return (AE_BAD_PARAMETER);
+    }
+
+    return (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsLoad1BeginOp
+ *
+ * PARAMETERS:  WalkState       - Current state of the parse tree walk
+ *              OutOp           - Where to return op if a new one is created
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Descending callback used during the loading of ACPI tables.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsLoad1BeginOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       **OutOp)
+{
+    ACPI_PARSE_OBJECT       *Op;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_STATUS             Status;
+    ACPI_OBJECT_TYPE        ObjectType;
+    char                    *Path;
+    UINT32                  Flags;
+
+
+    ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
+
+
+    Op = WalkState->Op;
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
+
+    /* We are only interested in opcodes that have an associated name */
+
+    if (Op)
+    {
+        if (!(WalkState->OpInfo->Flags & AML_NAMED))
+        {
+            *OutOp = Op;
+            return_ACPI_STATUS (AE_OK);
+        }
+
+        /* Check if this object has already been installed in the namespace */
+
+        if (Op->Common.Node)
+        {
+            *OutOp = Op;
+            return_ACPI_STATUS (AE_OK);
+        }
+    }
+
+    Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
+
+    /* Map the raw opcode into an internal object type */
+
+    ObjectType = WalkState->OpInfo->ObjectType;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "State=%p Op=%p [%s]\n", WalkState, Op,
+        AcpiUtGetTypeName (ObjectType)));
+
+    switch (WalkState->Opcode)
+    {
+    case AML_SCOPE_OP:
+        /*
+         * The target name of the Scope() operator must exist at this point so
+         * that we can actually open the scope to enter new names underneath it.
+         * Allow search-to-root for single namesegs.
+         */
+        Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
+            ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
+#ifdef ACPI_ASL_COMPILER
+        if (Status == AE_NOT_FOUND)
+        {
+            /*
+             * Table disassembly:
+             * Target of Scope() not found. Generate an External for it, and
+             * insert the name into the namespace.
+             */
+            AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0, 0);
+            Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
+               ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
+               WalkState, &Node);
+        }
+#endif
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_ERROR_NAMESPACE (Path, Status);
+            return_ACPI_STATUS (Status);
+        }
+
+        /*
+         * Check to make sure that the target is
+         * one of the opcodes that actually opens a scope
+         */
+        switch (Node->Type)
+        {
+        case ACPI_TYPE_ANY:
+        case ACPI_TYPE_LOCAL_SCOPE:         /* Scope  */
+        case ACPI_TYPE_DEVICE:
+        case ACPI_TYPE_POWER:
+        case ACPI_TYPE_PROCESSOR:
+        case ACPI_TYPE_THERMAL:
+
+            /* These are acceptable types */
+            break;
+
+        case ACPI_TYPE_INTEGER:
+        case ACPI_TYPE_STRING:
+        case ACPI_TYPE_BUFFER:
+            /*
+             * These types we will allow, but we will change the type.
+             * This enables some existing code of the form:
+             *
+             *  Name (DEB, 0)
+             *  Scope (DEB) { ... }
+             *
+             * Note: silently change the type here. On the second pass,
+             * we will report a warning
+             */
+            ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
+                "Type override - [%4.4s] had invalid type (%s) "
+                "for Scope operator, changed to type ANY\n",
+                AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
+
+            Node->Type = ACPI_TYPE_ANY;
+            WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
+            break;
+
+        case ACPI_TYPE_METHOD:
+            /*
+             * Allow scope change to root during execution of module-level
+             * code. Root is typed METHOD during this time.
+             */
+            if ((Node == AcpiGbl_RootNode) &&
+                (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
+            {
+                break;
+            }
+
+            /*lint -fallthrough */
+
+        default:
+
+            /* All other types are an error */
+
+            ACPI_ERROR ((AE_INFO,
+                "Invalid type (%s) for target of "
+                "Scope operator [%4.4s] (Cannot override)",
+                AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
+
+            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
+        }
+        break;
+
+    default:
+        /*
+         * For all other named opcodes, we will enter the name into
+         * the namespace.
+         *
+         * Setup the search flags.
+         * Since we are entering a name into the namespace, we do not want to
+         * enable the search-to-root upsearch.
+         *
+         * There are only two conditions where it is acceptable that the name
+         * already exists:
+         *    1) the Scope() operator can reopen a scoping object that was
+         *       previously defined (Scope, Method, Device, etc.)
+         *    2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
+         *       BufferField, or Package), the name of the object is already
+         *       in the namespace.
+         */
+        if (WalkState->DeferredNode)
+        {
+            /* This name is already in the namespace, get the node */
+
+            Node = WalkState->DeferredNode;
+            Status = AE_OK;
+            break;
+        }
+
+        /*
+         * If we are executing a method, do not create any namespace objects
+         * during the load phase, only during execution.
+         */
+        if (WalkState->MethodNode)
+        {
+            Node = NULL;
+            Status = AE_OK;
+            break;
+        }
+
+        Flags = ACPI_NS_NO_UPSEARCH;
+        if ((WalkState->Opcode != AML_SCOPE_OP) &&
+            (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
+        {
+            if (WalkState->NamespaceOverride)
+            {
+                Flags |= ACPI_NS_OVERRIDE_IF_FOUND;
+                ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Override allowed\n",
+                    AcpiUtGetTypeName (ObjectType)));
+            }
+            else
+            {
+                Flags |= ACPI_NS_ERROR_IF_FOUND;
+                ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
+                    AcpiUtGetTypeName (ObjectType)));
+            }
+        }
+        else
+        {
+            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+                "[%s] Both Find or Create allowed\n",
+                AcpiUtGetTypeName (ObjectType)));
+        }
+
+        /*
+         * Enter the named type into the internal namespace. We enter the name
+         * as we go downward in the parse tree. Any necessary subobjects that
+         * involve arguments to the opcode must be created as we go back up the
+         * parse tree later.
+         */
+        Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
+            ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
+        if (ACPI_FAILURE (Status))
+        {
+            if (Status == AE_ALREADY_EXISTS)
+            {
+                /* The name already exists in this scope */
+
+                if (Node->Flags & ANOBJ_IS_EXTERNAL)
+                {
+                    /*
+                     * Allow one create on an object or segment that was
+                     * previously declared External
+                     */
+                    Node->Flags &= ~ANOBJ_IS_EXTERNAL;
+                    Node->Type = (UINT8) ObjectType;
+
+                    /* Just retyped a node, probably will need to open a scope */
+
+                    if (AcpiNsOpensScope (ObjectType))
+                    {
+                        Status = AcpiDsScopeStackPush (
+                            Node, ObjectType, WalkState);
+                        if (ACPI_FAILURE (Status))
+                        {
+                            return_ACPI_STATUS (Status);
+                        }
+                    }
+
+                    Status = AE_OK;
+                }
+            }
+
+            if (ACPI_FAILURE (Status))
+            {
+                ACPI_ERROR_NAMESPACE (Path, Status);
+                return_ACPI_STATUS (Status);
+            }
+        }
+        break;
+    }
+
+    /* Common exit */
+
+    if (!Op)
+    {
+        /* Create a new op */
+
+        Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml);
+        if (!Op)
+        {
+            return_ACPI_STATUS (AE_NO_MEMORY);
+        }
+    }
+
+    /* Initialize the op */
+
+#if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
+    Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
+#endif
+
+    if (Node)
+    {
+        /*
+         * Put the Node in the "op" object that the parser uses, so we
+         * can get it again quickly when this scope is closed
+         */
+        Op->Common.Node = Node;
+        Op->Named.Name = Node->Name.Integer;
+    }
+
+    AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
+    *OutOp = Op;
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsLoad1EndOp
+ *
+ * PARAMETERS:  WalkState       - Current state of the parse tree walk
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Ascending callback used during the loading of the namespace,
+ *              both control methods and everything else.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsLoad1EndOp (
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_PARSE_OBJECT       *Op;
+    ACPI_OBJECT_TYPE        ObjectType;
+    ACPI_STATUS             Status = AE_OK;
+
+
+    ACPI_FUNCTION_TRACE (DsLoad1EndOp);
+
+
+    Op = WalkState->Op;
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
+
+    /* We are only interested in opcodes that have an associated name */
+
+    if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Get the object type to determine if we should pop the scope */
+
+    ObjectType = WalkState->OpInfo->ObjectType;
+
+#ifndef ACPI_NO_METHOD_EXECUTION
+    if (WalkState->OpInfo->Flags & AML_FIELD)
+    {
+        /*
+         * If we are executing a method, do not create any namespace objects
+         * during the load phase, only during execution.
+         */
+        if (!WalkState->MethodNode)
+        {
+            if (WalkState->Opcode == AML_FIELD_OP          ||
+                WalkState->Opcode == AML_BANK_FIELD_OP     ||
+                WalkState->Opcode == AML_INDEX_FIELD_OP)
+            {
+                Status = AcpiDsInitFieldObjects (Op, WalkState);
+            }
+        }
+        return_ACPI_STATUS (Status);
+    }
+
+    /*
+     * If we are executing a method, do not create any namespace objects
+     * during the load phase, only during execution.
+     */
+    if (!WalkState->MethodNode)
+    {
+        if (Op->Common.AmlOpcode == AML_REGION_OP)
+        {
+            Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
+                (ACPI_ADR_SPACE_TYPE)
+                    ((Op->Common.Value.Arg)->Common.Value.Integer),
+                WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                return_ACPI_STATUS (Status);
+            }
+        }
+        else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
+        {
+            Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
+                ACPI_ADR_SPACE_DATA_TABLE, WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                return_ACPI_STATUS (Status);
+            }
+        }
+    }
+#endif
+
+    if (Op->Common.AmlOpcode == AML_NAME_OP)
+    {
+        /* For Name opcode, get the object type from the argument */
+
+        if (Op->Common.Value.Arg)
+        {
+            ObjectType = (AcpiPsGetOpcodeInfo (
+                (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
+
+            /* Set node type if we have a namespace node */
+
+            if (Op->Common.Node)
+            {
+                Op->Common.Node->Type = (UINT8) ObjectType;
+            }
+        }
+    }
+
+    /*
+     * If we are executing a method, do not create any namespace objects
+     * during the load phase, only during execution.
+     */
+    if (!WalkState->MethodNode)
+    {
+        if (Op->Common.AmlOpcode == AML_METHOD_OP)
+        {
+            /*
+             * MethodOp PkgLength NameString MethodFlags TermList
+             *
+             * Note: We must create the method node/object pair as soon as we
+             * see the method declaration. This allows later pass1 parsing
+             * of invocations of the method (need to know the number of
+             * arguments.)
+             */
+            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+                "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
+                WalkState, Op, Op->Named.Node));
+
+            if (!AcpiNsGetAttachedObject (Op->Named.Node))
+            {
+                WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
+                WalkState->NumOperands = 1;
+
+                Status = AcpiDsCreateOperands (
+                    WalkState, Op->Common.Value.Arg);
+                if (ACPI_SUCCESS (Status))
+                {
+                    Status = AcpiExCreateMethod (Op->Named.Data,
+                        Op->Named.Length, WalkState);
+                }
+
+                WalkState->Operands[0] = NULL;
+                WalkState->NumOperands = 0;
+
+                if (ACPI_FAILURE (Status))
+                {
+                    return_ACPI_STATUS (Status);
+                }
+            }
+        }
+    }
+
+    /* Pop the scope stack (only if loading a table) */
+
+    if (!WalkState->MethodNode &&
+        AcpiNsOpensScope (ObjectType))
+    {
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
+            AcpiUtGetTypeName (ObjectType), Op));
+
+        Status = AcpiDsScopeStackPop (WalkState);
+    }
+
+    return_ACPI_STATUS (Status);
+}

+ 757 - 0
kernel/src/acpica/dispatcher/dswload2.c

@@ -0,0 +1,757 @@
+/******************************************************************************
+ *
+ * Module Name: dswload2 - Dispatcher second pass namespace load callbacks
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acparser.h"
+#include "amlcode.h"
+#include "acdispat.h"
+#include "acinterp.h"
+#include "acnamesp.h"
+#include "acevents.h"
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dswload2")
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsLoad2BeginOp
+ *
+ * PARAMETERS:  WalkState       - Current state of the parse tree walk
+ *              OutOp           - Wher to return op if a new one is created
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Descending callback used during the loading of ACPI tables.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsLoad2BeginOp (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       **OutOp)
+{
+    ACPI_PARSE_OBJECT       *Op;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_STATUS             Status;
+    ACPI_OBJECT_TYPE        ObjectType;
+    char                    *BufferPtr;
+    UINT32                  Flags;
+
+
+    ACPI_FUNCTION_TRACE (DsLoad2BeginOp);
+
+
+    Op = WalkState->Op;
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
+
+    if (Op)
+    {
+        if ((WalkState->ControlState) &&
+            (WalkState->ControlState->Common.State ==
+                ACPI_CONTROL_CONDITIONAL_EXECUTING))
+        {
+            /* We are executing a while loop outside of a method */
+
+            Status = AcpiDsExecBeginOp (WalkState, OutOp);
+            return_ACPI_STATUS (Status);
+        }
+
+        /* We only care about Namespace opcodes here */
+
+        if ((!(WalkState->OpInfo->Flags & AML_NSOPCODE)   &&
+              (WalkState->Opcode != AML_INT_NAMEPATH_OP)) ||
+            (!(WalkState->OpInfo->Flags & AML_NAMED)))
+        {
+            return_ACPI_STATUS (AE_OK);
+        }
+
+        /* Get the name we are going to enter or lookup in the namespace */
+
+        if (WalkState->Opcode == AML_INT_NAMEPATH_OP)
+        {
+            /* For Namepath op, get the path string */
+
+            BufferPtr = Op->Common.Value.String;
+            if (!BufferPtr)
+            {
+                /* No name, just exit */
+
+                return_ACPI_STATUS (AE_OK);
+            }
+        }
+        else
+        {
+            /* Get name from the op */
+
+            BufferPtr = ACPI_CAST_PTR (char, &Op->Named.Name);
+        }
+    }
+    else
+    {
+        /* Get the namestring from the raw AML */
+
+        BufferPtr = AcpiPsGetNextNamestring (&WalkState->ParserState);
+    }
+
+    /* Map the opcode into an internal object type */
+
+    ObjectType = WalkState->OpInfo->ObjectType;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "State=%p Op=%p Type=%X\n", WalkState, Op, ObjectType));
+
+    switch (WalkState->Opcode)
+    {
+    case AML_FIELD_OP:
+    case AML_BANK_FIELD_OP:
+    case AML_INDEX_FIELD_OP:
+
+        Node = NULL;
+        Status = AE_OK;
+        break;
+
+    case AML_INT_NAMEPATH_OP:
+        /*
+         * The NamePath is an object reference to an existing object.
+         * Don't enter the name into the namespace, but look it up
+         * for use later.
+         */
+        Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
+            ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
+            WalkState, &(Node));
+        break;
+
+    case AML_SCOPE_OP:
+
+        /* Special case for Scope(\) -> refers to the Root node */
+
+        if (Op && (Op->Named.Node == AcpiGbl_RootNode))
+        {
+            Node = Op->Named.Node;
+
+            Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                return_ACPI_STATUS (Status);
+            }
+        }
+        else
+        {
+            /*
+             * The Path is an object reference to an existing object.
+             * Don't enter the name into the namespace, but look it up
+             * for use later.
+             */
+            Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
+                ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
+                WalkState, &(Node));
+            if (ACPI_FAILURE (Status))
+            {
+#ifdef ACPI_ASL_COMPILER
+                if (Status == AE_NOT_FOUND)
+                {
+                    Status = AE_OK;
+                }
+                else
+                {
+                    ACPI_ERROR_NAMESPACE (BufferPtr, Status);
+                }
+#else
+                ACPI_ERROR_NAMESPACE (BufferPtr, Status);
+#endif
+                return_ACPI_STATUS (Status);
+            }
+        }
+
+        /*
+         * We must check to make sure that the target is
+         * one of the opcodes that actually opens a scope
+         */
+        switch (Node->Type)
+        {
+        case ACPI_TYPE_ANY:
+        case ACPI_TYPE_LOCAL_SCOPE:         /* Scope */
+        case ACPI_TYPE_DEVICE:
+        case ACPI_TYPE_POWER:
+        case ACPI_TYPE_PROCESSOR:
+        case ACPI_TYPE_THERMAL:
+
+            /* These are acceptable types */
+            break;
+
+        case ACPI_TYPE_INTEGER:
+        case ACPI_TYPE_STRING:
+        case ACPI_TYPE_BUFFER:
+
+            /*
+             * These types we will allow, but we will change the type.
+             * This enables some existing code of the form:
+             *
+             *  Name (DEB, 0)
+             *  Scope (DEB) { ... }
+             */
+            ACPI_WARNING ((AE_INFO,
+                "Type override - [%4.4s] had invalid type (%s) "
+                "for Scope operator, changed to type ANY",
+                AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
+
+            Node->Type = ACPI_TYPE_ANY;
+            WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
+            break;
+
+        case ACPI_TYPE_METHOD:
+
+            /*
+             * Allow scope change to root during execution of module-level
+             * code. Root is typed METHOD during this time.
+             */
+            if ((Node == AcpiGbl_RootNode) &&
+                (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
+            {
+                break;
+            }
+
+            /*lint -fallthrough */
+
+        default:
+
+            /* All other types are an error */
+
+            ACPI_ERROR ((AE_INFO,
+                "Invalid type (%s) for target of "
+                "Scope operator [%4.4s] (Cannot override)",
+                AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
+
+            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
+        }
+        break;
+
+    default:
+
+        /* All other opcodes */
+
+        if (Op && Op->Common.Node)
+        {
+            /* This op/node was previously entered into the namespace */
+
+            Node = Op->Common.Node;
+
+            if (AcpiNsOpensScope (ObjectType))
+            {
+                Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState);
+                if (ACPI_FAILURE (Status))
+                {
+                    return_ACPI_STATUS (Status);
+                }
+            }
+
+            return_ACPI_STATUS (AE_OK);
+        }
+
+        /*
+         * Enter the named type into the internal namespace. We enter the name
+         * as we go downward in the parse tree. Any necessary subobjects that
+         * involve arguments to the opcode must be created as we go back up the
+         * parse tree later.
+         *
+         * Note: Name may already exist if we are executing a deferred opcode.
+         */
+        if (WalkState->DeferredNode)
+        {
+            /* This name is already in the namespace, get the node */
+
+            Node = WalkState->DeferredNode;
+            Status = AE_OK;
+            break;
+        }
+
+        Flags = ACPI_NS_NO_UPSEARCH;
+        if (WalkState->PassNumber == ACPI_IMODE_EXECUTE)
+        {
+            /* Execution mode, node cannot already exist, node is temporary */
+
+            Flags |= ACPI_NS_ERROR_IF_FOUND;
+
+            if (!(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
+            {
+                Flags |= ACPI_NS_TEMPORARY;
+            }
+        }
+
+        /* Add new entry or lookup existing entry */
+
+        Status = AcpiNsLookup (WalkState->ScopeInfo, BufferPtr, ObjectType,
+            ACPI_IMODE_LOAD_PASS2, Flags, WalkState, &Node);
+
+        if (ACPI_SUCCESS (Status) && (Flags & ACPI_NS_TEMPORARY))
+        {
+            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+                "***New Node [%4.4s] %p is temporary\n",
+                AcpiUtGetNodeName (Node), Node));
+        }
+        break;
+    }
+
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_ERROR_NAMESPACE (BufferPtr, Status);
+        return_ACPI_STATUS (Status);
+    }
+
+    if (!Op)
+    {
+        /* Create a new op */
+
+        Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml);
+        if (!Op)
+        {
+            return_ACPI_STATUS (AE_NO_MEMORY);
+        }
+
+        /* Initialize the new op */
+
+        if (Node)
+        {
+            Op->Named.Name = Node->Name.Integer;
+        }
+        *OutOp = Op;
+    }
+
+    /*
+     * Put the Node in the "op" object that the parser uses, so we
+     * can get it again quickly when this scope is closed
+     */
+    Op->Common.Node = Node;
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsLoad2EndOp
+ *
+ * PARAMETERS:  WalkState       - Current state of the parse tree walk
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Ascending callback used during the loading of the namespace,
+ *              both control methods and everything else.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsLoad2EndOp (
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_PARSE_OBJECT       *Op;
+    ACPI_STATUS             Status = AE_OK;
+    ACPI_OBJECT_TYPE        ObjectType;
+    ACPI_NAMESPACE_NODE     *Node;
+    ACPI_PARSE_OBJECT       *Arg;
+    ACPI_NAMESPACE_NODE     *NewNode;
+#ifndef ACPI_NO_METHOD_EXECUTION
+    UINT32                  i;
+    UINT8                   RegionSpace;
+#endif
+
+
+    ACPI_FUNCTION_TRACE (DsLoad2EndOp);
+
+    Op = WalkState->Op;
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Opcode [%s] Op %p State %p\n",
+        WalkState->OpInfo->Name, Op, WalkState));
+
+    /* Check if opcode had an associated namespace object */
+
+    if (!(WalkState->OpInfo->Flags & AML_NSOBJECT))
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    if (Op->Common.AmlOpcode == AML_SCOPE_OP)
+    {
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "Ending scope Op=%p State=%p\n", Op, WalkState));
+    }
+
+    ObjectType = WalkState->OpInfo->ObjectType;
+
+    /*
+     * Get the Node/name from the earlier lookup
+     * (It was saved in the *op structure)
+     */
+    Node = Op->Common.Node;
+
+    /*
+     * Put the Node on the object stack (Contains the ACPI Name of
+     * this object)
+     */
+    WalkState->Operands[0] = (void *) Node;
+    WalkState->NumOperands = 1;
+
+    /* Pop the scope stack */
+
+    if (AcpiNsOpensScope (ObjectType) &&
+       (Op->Common.AmlOpcode != AML_INT_METHODCALL_OP))
+    {
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s) Popping scope for Op %p\n",
+            AcpiUtGetTypeName (ObjectType), Op));
+
+        Status = AcpiDsScopeStackPop (WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            goto Cleanup;
+        }
+    }
+
+    /*
+     * Named operations are as follows:
+     *
+     * AML_ALIAS
+     * AML_BANKFIELD
+     * AML_CREATEBITFIELD
+     * AML_CREATEBYTEFIELD
+     * AML_CREATEDWORDFIELD
+     * AML_CREATEFIELD
+     * AML_CREATEQWORDFIELD
+     * AML_CREATEWORDFIELD
+     * AML_DATA_REGION
+     * AML_DEVICE
+     * AML_EVENT
+     * AML_FIELD
+     * AML_INDEXFIELD
+     * AML_METHOD
+     * AML_METHODCALL
+     * AML_MUTEX
+     * AML_NAME
+     * AML_NAMEDFIELD
+     * AML_OPREGION
+     * AML_POWERRES
+     * AML_PROCESSOR
+     * AML_SCOPE
+     * AML_THERMALZONE
+     */
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+        "Create-Load [%s] State=%p Op=%p NamedObj=%p\n",
+        AcpiPsGetOpcodeName (Op->Common.AmlOpcode), WalkState, Op, Node));
+
+    /* Decode the opcode */
+
+    Arg = Op->Common.Value.Arg;
+
+    switch (WalkState->OpInfo->Type)
+    {
+#ifndef ACPI_NO_METHOD_EXECUTION
+
+    case AML_TYPE_CREATE_FIELD:
+        /*
+         * Create the field object, but the field buffer and index must
+         * be evaluated later during the execution phase
+         */
+        Status = AcpiDsCreateBufferField (Op, WalkState);
+        break;
+
+     case AML_TYPE_NAMED_FIELD:
+        /*
+         * If we are executing a method, initialize the field
+         */
+        if (WalkState->MethodNode)
+        {
+            Status = AcpiDsInitFieldObjects (Op, WalkState);
+        }
+
+        switch (Op->Common.AmlOpcode)
+        {
+        case AML_INDEX_FIELD_OP:
+
+            Status = AcpiDsCreateIndexField (
+                Op, (ACPI_HANDLE) Arg->Common.Node, WalkState);
+            break;
+
+        case AML_BANK_FIELD_OP:
+
+            Status = AcpiDsCreateBankField (Op, Arg->Common.Node, WalkState);
+            break;
+
+        case AML_FIELD_OP:
+
+            Status = AcpiDsCreateField (Op, Arg->Common.Node, WalkState);
+            break;
+
+        default:
+
+            /* All NAMED_FIELD opcodes must be handled above */
+            break;
+        }
+        break;
+
+     case AML_TYPE_NAMED_SIMPLE:
+
+        Status = AcpiDsCreateOperands (WalkState, Arg);
+        if (ACPI_FAILURE (Status))
+        {
+            goto Cleanup;
+        }
+
+        switch (Op->Common.AmlOpcode)
+        {
+        case AML_PROCESSOR_OP:
+
+            Status = AcpiExCreateProcessor (WalkState);
+            break;
+
+        case AML_POWER_RES_OP:
+
+            Status = AcpiExCreatePowerResource (WalkState);
+            break;
+
+        case AML_MUTEX_OP:
+
+            Status = AcpiExCreateMutex (WalkState);
+            break;
+
+        case AML_EVENT_OP:
+
+            Status = AcpiExCreateEvent (WalkState);
+            break;
+
+        case AML_ALIAS_OP:
+
+            Status = AcpiExCreateAlias (WalkState);
+            break;
+
+        default:
+
+            /* Unknown opcode */
+
+            Status = AE_OK;
+            goto Cleanup;
+        }
+
+        /* Delete operands */
+
+        for (i = 1; i < WalkState->NumOperands; i++)
+        {
+            AcpiUtRemoveReference (WalkState->Operands[i]);
+            WalkState->Operands[i] = NULL;
+        }
+
+        break;
+#endif /* ACPI_NO_METHOD_EXECUTION */
+
+    case AML_TYPE_NAMED_COMPLEX:
+
+        switch (Op->Common.AmlOpcode)
+        {
+#ifndef ACPI_NO_METHOD_EXECUTION
+        case AML_REGION_OP:
+        case AML_DATA_REGION_OP:
+
+            if (Op->Common.AmlOpcode == AML_REGION_OP)
+            {
+                RegionSpace = (ACPI_ADR_SPACE_TYPE)
+                    ((Op->Common.Value.Arg)->Common.Value.Integer);
+            }
+            else
+            {
+                RegionSpace = ACPI_ADR_SPACE_DATA_TABLE;
+            }
+
+            /*
+             * The OpRegion is not fully parsed at this time. The only valid
+             * argument is the SpaceId. (We must save the address of the
+             * AML of the address and length operands)
+             *
+             * If we have a valid region, initialize it. The namespace is
+             * unlocked at this point.
+             *
+             * Need to unlock interpreter if it is locked (if we are running
+             * a control method), in order to allow _REG methods to be run
+             * during AcpiEvInitializeRegion.
+             */
+            if (WalkState->MethodNode)
+            {
+                /*
+                 * Executing a method: initialize the region and unlock
+                 * the interpreter
+                 */
+                Status = AcpiExCreateRegion (Op->Named.Data,
+                    Op->Named.Length, RegionSpace, WalkState);
+                if (ACPI_FAILURE (Status))
+                {
+                    return_ACPI_STATUS (Status);
+                }
+
+                AcpiExExitInterpreter ();
+            }
+
+            Status = AcpiEvInitializeRegion (
+                AcpiNsGetAttachedObject (Node), FALSE);
+            if (WalkState->MethodNode)
+            {
+                AcpiExEnterInterpreter ();
+            }
+
+            if (ACPI_FAILURE (Status))
+            {
+                /*
+                 *  If AE_NOT_EXIST is returned, it is not fatal
+                 *  because many regions get created before a handler
+                 *  is installed for said region.
+                 */
+                if (AE_NOT_EXIST == Status)
+                {
+                    Status = AE_OK;
+                }
+            }
+            break;
+
+        case AML_NAME_OP:
+
+            Status = AcpiDsCreateNode (WalkState, Node, Op);
+            break;
+
+        case AML_METHOD_OP:
+            /*
+             * MethodOp PkgLength NameString MethodFlags TermList
+             *
+             * Note: We must create the method node/object pair as soon as we
+             * see the method declaration. This allows later pass1 parsing
+             * of invocations of the method (need to know the number of
+             * arguments.)
+             */
+            ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+                "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
+                WalkState, Op, Op->Named.Node));
+
+            if (!AcpiNsGetAttachedObject (Op->Named.Node))
+            {
+                WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
+                WalkState->NumOperands = 1;
+
+                Status = AcpiDsCreateOperands (
+                    WalkState, Op->Common.Value.Arg);
+                if (ACPI_SUCCESS (Status))
+                {
+                    Status = AcpiExCreateMethod (
+                        Op->Named.Data, Op->Named.Length, WalkState);
+                }
+
+                WalkState->Operands[0] = NULL;
+                WalkState->NumOperands = 0;
+
+                if (ACPI_FAILURE (Status))
+                {
+                    return_ACPI_STATUS (Status);
+                }
+            }
+            break;
+
+#endif /* ACPI_NO_METHOD_EXECUTION */
+
+        default:
+
+            /* All NAMED_COMPLEX opcodes must be handled above */
+            break;
+        }
+        break;
+
+    case AML_CLASS_INTERNAL:
+
+        /* case AML_INT_NAMEPATH_OP: */
+        break;
+
+    case AML_CLASS_METHOD_CALL:
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
+            "RESOLVING-MethodCall: State=%p Op=%p NamedObj=%p\n",
+            WalkState, Op, Node));
+
+        /*
+         * Lookup the method name and save the Node
+         */
+        Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
+            ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS2,
+            ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
+            WalkState, &(NewNode));
+        if (ACPI_SUCCESS (Status))
+        {
+            /*
+             * Make sure that what we found is indeed a method
+             * We didn't search for a method on purpose, to see if the name
+             * would resolve
+             */
+            if (NewNode->Type != ACPI_TYPE_METHOD)
+            {
+                Status = AE_AML_OPERAND_TYPE;
+            }
+
+            /* We could put the returned object (Node) on the object stack for
+             * later, but for now, we will put it in the "op" object that the
+             * parser uses, so we can get it again at the end of this scope
+             */
+            Op->Common.Node = NewNode;
+        }
+        else
+        {
+            ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
+        }
+        break;
+
+
+    default:
+
+        break;
+    }
+
+Cleanup:
+
+    /* Remove the Node pushed at the very beginning */
+
+    WalkState->Operands[0] = NULL;
+    WalkState->NumOperands = 0;
+    return_ACPI_STATUS (Status);
+}

+ 236 - 0
kernel/src/acpica/dispatcher/dswscope.c

@@ -0,0 +1,236 @@
+/******************************************************************************
+ *
+ * Module Name: dswscope - Scope stack manipulation
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acdispat.h"
+
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dswscope")
+
+
+/****************************************************************************
+ *
+ * FUNCTION:    AcpiDsScopeStackClear
+ *
+ * PARAMETERS:  WalkState       - Current state
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Pop (and free) everything on the scope stack except the
+ *              root scope object (which remains at the stack top.)
+ *
+ ***************************************************************************/
+
+void
+AcpiDsScopeStackClear (
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_GENERIC_STATE      *ScopeInfo;
+
+    ACPI_FUNCTION_NAME (DsScopeStackClear);
+
+
+    while (WalkState->ScopeInfo)
+    {
+        /* Pop a scope off the stack */
+
+        ScopeInfo = WalkState->ScopeInfo;
+        WalkState->ScopeInfo = ScopeInfo->Scope.Next;
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+            "Popped object type (%s)\n",
+            AcpiUtGetTypeName (ScopeInfo->Common.Value)));
+
+        AcpiUtDeleteGenericState (ScopeInfo);
+    }
+}
+
+
+/****************************************************************************
+ *
+ * FUNCTION:    AcpiDsScopeStackPush
+ *
+ * PARAMETERS:  Node            - Name to be made current
+ *              Type            - Type of frame being pushed
+ *              WalkState       - Current state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Push the current scope on the scope stack, and make the
+ *              passed Node current.
+ *
+ ***************************************************************************/
+
+ACPI_STATUS
+AcpiDsScopeStackPush (
+    ACPI_NAMESPACE_NODE     *Node,
+    ACPI_OBJECT_TYPE        Type,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_GENERIC_STATE      *ScopeInfo;
+    ACPI_GENERIC_STATE      *OldScopeInfo;
+
+
+    ACPI_FUNCTION_TRACE (DsScopeStackPush);
+
+
+    if (!Node)
+    {
+        /* Invalid scope   */
+
+        ACPI_ERROR ((AE_INFO, "Null scope parameter"));
+        return_ACPI_STATUS (AE_BAD_PARAMETER);
+    }
+
+    /* Make sure object type is valid */
+
+    if (!AcpiUtValidObjectType (Type))
+    {
+        ACPI_WARNING ((AE_INFO,
+            "Invalid object type: 0x%X", Type));
+    }
+
+    /* Allocate a new scope object */
+
+    ScopeInfo = AcpiUtCreateGenericState ();
+    if (!ScopeInfo)
+    {
+        return_ACPI_STATUS (AE_NO_MEMORY);
+    }
+
+    /* Init new scope object */
+
+    ScopeInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_WSCOPE;
+    ScopeInfo->Scope.Node = Node;
+    ScopeInfo->Common.Value = (UINT16) Type;
+
+    WalkState->ScopeDepth++;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+        "[%.2d] Pushed scope ", (UINT32) WalkState->ScopeDepth));
+
+    OldScopeInfo = WalkState->ScopeInfo;
+    if (OldScopeInfo)
+    {
+        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
+            "[%4.4s] (%s)",
+            AcpiUtGetNodeName (OldScopeInfo->Scope.Node),
+            AcpiUtGetTypeName (OldScopeInfo->Common.Value)));
+    }
+    else
+    {
+        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
+            "[\\___] (%s)", "ROOT"));
+    }
+
+    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
+        ", New scope -> [%4.4s] (%s)\n",
+        AcpiUtGetNodeName (ScopeInfo->Scope.Node),
+        AcpiUtGetTypeName (ScopeInfo->Common.Value)));
+
+    /* Push new scope object onto stack */
+
+    AcpiUtPushGenericState (&WalkState->ScopeInfo, ScopeInfo);
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/****************************************************************************
+ *
+ * FUNCTION:    AcpiDsScopeStackPop
+ *
+ * PARAMETERS:  WalkState       - Current state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Pop the scope stack once.
+ *
+ ***************************************************************************/
+
+ACPI_STATUS
+AcpiDsScopeStackPop (
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_GENERIC_STATE      *ScopeInfo;
+    ACPI_GENERIC_STATE      *NewScopeInfo;
+
+
+    ACPI_FUNCTION_TRACE (DsScopeStackPop);
+
+
+    /*
+     * Pop scope info object off the stack.
+     */
+    ScopeInfo = AcpiUtPopGenericState (&WalkState->ScopeInfo);
+    if (!ScopeInfo)
+    {
+        return_ACPI_STATUS (AE_STACK_UNDERFLOW);
+    }
+
+    WalkState->ScopeDepth--;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+        "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
+        (UINT32) WalkState->ScopeDepth,
+        AcpiUtGetNodeName (ScopeInfo->Scope.Node),
+        AcpiUtGetTypeName (ScopeInfo->Common.Value)));
+
+    NewScopeInfo = WalkState->ScopeInfo;
+    if (NewScopeInfo)
+    {
+        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
+            "[%4.4s] (%s)\n",
+            AcpiUtGetNodeName (NewScopeInfo->Scope.Node),
+            AcpiUtGetTypeName (NewScopeInfo->Common.Value)));
+    }
+    else
+    {
+        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
+            "[\\___] (ROOT)\n"));
+    }
+
+    AcpiUtDeleteGenericState (ScopeInfo);
+    return_ACPI_STATUS (AE_OK);
+}

+ 842 - 0
kernel/src/acpica/dispatcher/dswstate.c

@@ -0,0 +1,842 @@
+/******************************************************************************
+ *
+ * Module Name: dswstate - Dispatcher parse tree walk management routines
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acparser.h"
+#include "acdispat.h"
+#include "acnamesp.h"
+
+#define _COMPONENT          ACPI_DISPATCHER
+        ACPI_MODULE_NAME    ("dswstate")
+
+/* Local prototypes */
+
+static ACPI_STATUS
+AcpiDsResultStackPush (
+    ACPI_WALK_STATE         *WalkState);
+
+static ACPI_STATUS
+AcpiDsResultStackPop (
+    ACPI_WALK_STATE         *WalkState);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsResultPop
+ *
+ * PARAMETERS:  Object              - Where to return the popped object
+ *              WalkState           - Current Walk state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Pop an object off the top of this walk's result stack
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsResultPop (
+    ACPI_OPERAND_OBJECT     **Object,
+    ACPI_WALK_STATE         *WalkState)
+{
+    UINT32                  Index;
+    ACPI_GENERIC_STATE      *State;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_NAME (DsResultPop);
+
+
+    State = WalkState->Results;
+
+    /* Incorrect state of result stack */
+
+    if (State && !WalkState->ResultCount)
+    {
+        ACPI_ERROR ((AE_INFO, "No results on result stack"));
+        return (AE_AML_INTERNAL);
+    }
+
+    if (!State && WalkState->ResultCount)
+    {
+        ACPI_ERROR ((AE_INFO, "No result state for result stack"));
+        return (AE_AML_INTERNAL);
+    }
+
+    /* Empty result stack */
+
+    if (!State)
+    {
+        ACPI_ERROR ((AE_INFO, "Result stack is empty! State=%p", WalkState));
+        return (AE_AML_NO_RETURN_VALUE);
+    }
+
+    /* Return object of the top element and clean that top element result stack */
+
+    WalkState->ResultCount--;
+    Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
+
+    *Object = State->Results.ObjDesc [Index];
+    if (!*Object)
+    {
+        ACPI_ERROR ((AE_INFO, "No result objects on result stack, State=%p",
+            WalkState));
+        return (AE_AML_NO_RETURN_VALUE);
+    }
+
+    State->Results.ObjDesc [Index] = NULL;
+    if (Index == 0)
+    {
+        Status = AcpiDsResultStackPop (WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            return (Status);
+        }
+    }
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+        "Obj=%p [%s] Index=%X State=%p Num=%X\n", *Object,
+        AcpiUtGetObjectTypeName (*Object),
+        Index, WalkState, WalkState->ResultCount));
+
+    return (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsResultPush
+ *
+ * PARAMETERS:  Object              - Where to return the popped object
+ *              WalkState           - Current Walk state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Push an object onto the current result stack
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsResultPush (
+    ACPI_OPERAND_OBJECT     *Object,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_GENERIC_STATE      *State;
+    ACPI_STATUS             Status;
+    UINT32                  Index;
+
+
+    ACPI_FUNCTION_NAME (DsResultPush);
+
+
+    if (WalkState->ResultCount > WalkState->ResultSize)
+    {
+        ACPI_ERROR ((AE_INFO, "Result stack is full"));
+        return (AE_AML_INTERNAL);
+    }
+    else if (WalkState->ResultCount == WalkState->ResultSize)
+    {
+        /* Extend the result stack */
+
+        Status = AcpiDsResultStackPush (WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_ERROR ((AE_INFO, "Failed to extend the result stack"));
+            return (Status);
+        }
+    }
+
+    if (!(WalkState->ResultCount < WalkState->ResultSize))
+    {
+        ACPI_ERROR ((AE_INFO, "No free elements in result stack"));
+        return (AE_AML_INTERNAL);
+    }
+
+    State = WalkState->Results;
+    if (!State)
+    {
+        ACPI_ERROR ((AE_INFO, "No result stack frame during push"));
+        return (AE_AML_INTERNAL);
+    }
+
+    if (!Object)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "Null Object! Obj=%p State=%p Num=%u",
+            Object, WalkState, WalkState->ResultCount));
+        return (AE_BAD_PARAMETER);
+    }
+
+    /* Assign the address of object to the top free element of result stack */
+
+    Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;
+    State->Results.ObjDesc [Index] = Object;
+    WalkState->ResultCount++;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",
+        Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
+        WalkState, WalkState->ResultCount, WalkState->CurrentResult));
+
+    return (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsResultStackPush
+ *
+ * PARAMETERS:  WalkState           - Current Walk state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Push an object onto the WalkState result stack
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsResultStackPush (
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_GENERIC_STATE      *State;
+
+
+    ACPI_FUNCTION_NAME (DsResultStackPush);
+
+
+    /* Check for stack overflow */
+
+    if (((UINT32) WalkState->ResultSize + ACPI_RESULTS_FRAME_OBJ_NUM) >
+        ACPI_RESULTS_OBJ_NUM_MAX)
+    {
+        ACPI_ERROR ((AE_INFO, "Result stack overflow: State=%p Num=%u",
+            WalkState, WalkState->ResultSize));
+        return (AE_STACK_OVERFLOW);
+    }
+
+    State = AcpiUtCreateGenericState ();
+    if (!State)
+    {
+        return (AE_NO_MEMORY);
+    }
+
+    State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RESULT;
+    AcpiUtPushGenericState (&WalkState->Results, State);
+
+    /* Increase the length of the result stack by the length of frame */
+
+    WalkState->ResultSize += ACPI_RESULTS_FRAME_OBJ_NUM;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",
+        State, WalkState));
+
+    return (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsResultStackPop
+ *
+ * PARAMETERS:  WalkState           - Current Walk state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Pop an object off of the WalkState result stack
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiDsResultStackPop (
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_GENERIC_STATE      *State;
+
+
+    ACPI_FUNCTION_NAME (DsResultStackPop);
+
+
+    /* Check for stack underflow */
+
+    if (WalkState->Results == NULL)
+    {
+        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+            "Result stack underflow - State=%p\n", WalkState));
+        return (AE_AML_NO_OPERAND);
+    }
+
+    if (WalkState->ResultSize < ACPI_RESULTS_FRAME_OBJ_NUM)
+    {
+        ACPI_ERROR ((AE_INFO, "Insufficient result stack size"));
+        return (AE_AML_INTERNAL);
+    }
+
+    State = AcpiUtPopGenericState (&WalkState->Results);
+    AcpiUtDeleteGenericState (State);
+
+    /* Decrease the length of result stack by the length of frame */
+
+    WalkState->ResultSize -= ACPI_RESULTS_FRAME_OBJ_NUM;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+        "Result=%p RemainingResults=%X State=%p\n",
+        State, WalkState->ResultCount, WalkState));
+
+    return (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsObjStackPush
+ *
+ * PARAMETERS:  Object              - Object to push
+ *              WalkState           - Current Walk state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Push an object onto this walk's object/operand stack
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsObjStackPush (
+    void                    *Object,
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_FUNCTION_NAME (DsObjStackPush);
+
+
+    /* Check for stack overflow */
+
+    if (WalkState->NumOperands >= ACPI_OBJ_NUM_OPERANDS)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "Object stack overflow! Obj=%p State=%p #Ops=%u",
+            Object, WalkState, WalkState->NumOperands));
+        return (AE_STACK_OVERFLOW);
+    }
+
+    /* Put the object onto the stack */
+
+    WalkState->Operands [WalkState->OperandIndex] = Object;
+    WalkState->NumOperands++;
+
+    /* For the usual order of filling the operand stack */
+
+    WalkState->OperandIndex++;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",
+        Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),
+        WalkState, WalkState->NumOperands));
+
+    return (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsObjStackPop
+ *
+ * PARAMETERS:  PopCount            - Number of objects/entries to pop
+ *              WalkState           - Current Walk state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT
+ *              deleted by this routine.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsObjStackPop (
+    UINT32                  PopCount,
+    ACPI_WALK_STATE         *WalkState)
+{
+    UINT32                  i;
+
+
+    ACPI_FUNCTION_NAME (DsObjStackPop);
+
+
+    for (i = 0; i < PopCount; i++)
+    {
+        /* Check for stack underflow */
+
+        if (WalkState->NumOperands == 0)
+        {
+            ACPI_ERROR ((AE_INFO,
+                "Object stack underflow! Count=%X State=%p #Ops=%u",
+                PopCount, WalkState, WalkState->NumOperands));
+            return (AE_STACK_UNDERFLOW);
+        }
+
+        /* Just set the stack entry to null */
+
+        WalkState->NumOperands--;
+        WalkState->Operands [WalkState->NumOperands] = NULL;
+    }
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",
+        PopCount, WalkState, WalkState->NumOperands));
+
+    return (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsObjStackPopAndDelete
+ *
+ * PARAMETERS:  PopCount            - Number of objects/entries to pop
+ *              WalkState           - Current Walk state
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Pop this walk's object stack and delete each object that is
+ *              popped off.
+ *
+ ******************************************************************************/
+
+void
+AcpiDsObjStackPopAndDelete (
+    UINT32                  PopCount,
+    ACPI_WALK_STATE         *WalkState)
+{
+    INT32                   i;
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+
+
+    ACPI_FUNCTION_NAME (DsObjStackPopAndDelete);
+
+
+    if (PopCount == 0)
+    {
+        return;
+    }
+
+    for (i = (INT32) PopCount - 1; i >= 0; i--)
+    {
+        if (WalkState->NumOperands == 0)
+        {
+            return;
+        }
+
+        /* Pop the stack and delete an object if present in this stack entry */
+
+        WalkState->NumOperands--;
+        ObjDesc = WalkState->Operands [i];
+        if (ObjDesc)
+        {
+            AcpiUtRemoveReference (WalkState->Operands [i]);
+            WalkState->Operands [i] = NULL;
+        }
+    }
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
+        PopCount, WalkState, WalkState->NumOperands));
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsGetCurrentWalkState
+ *
+ * PARAMETERS:  Thread          - Get current active state for this Thread
+ *
+ * RETURN:      Pointer to the current walk state
+ *
+ * DESCRIPTION: Get the walk state that is at the head of the list (the "current"
+ *              walk state.)
+ *
+ ******************************************************************************/
+
+ACPI_WALK_STATE *
+AcpiDsGetCurrentWalkState (
+    ACPI_THREAD_STATE       *Thread)
+{
+    ACPI_FUNCTION_NAME (DsGetCurrentWalkState);
+
+
+    if (!Thread)
+    {
+        return (NULL);
+    }
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current WalkState %p\n",
+        Thread->WalkStateList));
+
+    return (Thread->WalkStateList);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsPushWalkState
+ *
+ * PARAMETERS:  WalkState       - State to push
+ *              Thread          - Thread state object
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Place the Thread state at the head of the state list
+ *
+ ******************************************************************************/
+
+void
+AcpiDsPushWalkState (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_THREAD_STATE       *Thread)
+{
+    ACPI_FUNCTION_TRACE (DsPushWalkState);
+
+
+    WalkState->Next = Thread->WalkStateList;
+    Thread->WalkStateList = WalkState;
+
+    return_VOID;
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsPopWalkState
+ *
+ * PARAMETERS:  Thread      - Current thread state
+ *
+ * RETURN:      A WalkState object popped from the thread's stack
+ *
+ * DESCRIPTION: Remove and return the walkstate object that is at the head of
+ *              the walk stack for the given walk list. NULL indicates that
+ *              the list is empty.
+ *
+ ******************************************************************************/
+
+ACPI_WALK_STATE *
+AcpiDsPopWalkState (
+    ACPI_THREAD_STATE       *Thread)
+{
+    ACPI_WALK_STATE         *WalkState;
+
+
+    ACPI_FUNCTION_TRACE (DsPopWalkState);
+
+
+    WalkState = Thread->WalkStateList;
+
+    if (WalkState)
+    {
+        /* Next walk state becomes the current walk state */
+
+        Thread->WalkStateList = WalkState->Next;
+
+        /*
+         * Don't clear the NEXT field, this serves as an indicator
+         * that there is a parent WALK STATE
+         * Do Not: WalkState->Next = NULL;
+         */
+    }
+
+    return_PTR (WalkState);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsCreateWalkState
+ *
+ * PARAMETERS:  OwnerId         - ID for object creation
+ *              Origin          - Starting point for this walk
+ *              MethodDesc      - Method object
+ *              Thread          - Current thread state
+ *
+ * RETURN:      Pointer to the new walk state.
+ *
+ * DESCRIPTION: Allocate and initialize a new walk state. The current walk
+ *              state is set to this new state.
+ *
+ ******************************************************************************/
+
+ACPI_WALK_STATE *
+AcpiDsCreateWalkState (
+    ACPI_OWNER_ID           OwnerId,
+    ACPI_PARSE_OBJECT       *Origin,
+    ACPI_OPERAND_OBJECT     *MethodDesc,
+    ACPI_THREAD_STATE       *Thread)
+{
+    ACPI_WALK_STATE         *WalkState;
+
+
+    ACPI_FUNCTION_TRACE (DsCreateWalkState);
+
+
+    WalkState = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_WALK_STATE));
+    if (!WalkState)
+    {
+        return_PTR (NULL);
+    }
+
+    WalkState->DescriptorType = ACPI_DESC_TYPE_WALK;
+    WalkState->MethodDesc = MethodDesc;
+    WalkState->OwnerId = OwnerId;
+    WalkState->Origin = Origin;
+    WalkState->Thread = Thread;
+
+    WalkState->ParserState.StartOp = Origin;
+
+    /* Init the method args/local */
+
+#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
+    AcpiDsMethodDataInit (WalkState);
+#endif
+
+    /* Put the new state at the head of the walk list */
+
+    if (Thread)
+    {
+        AcpiDsPushWalkState (WalkState, Thread);
+    }
+
+    return_PTR (WalkState);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsInitAmlWalk
+ *
+ * PARAMETERS:  WalkState       - New state to be initialized
+ *              Op              - Current parse op
+ *              MethodNode      - Control method NS node, if any
+ *              AmlStart        - Start of AML
+ *              AmlLength       - Length of AML
+ *              Info            - Method info block (params, etc.)
+ *              PassNumber      - 1, 2, or 3
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiDsInitAmlWalk (
+    ACPI_WALK_STATE         *WalkState,
+    ACPI_PARSE_OBJECT       *Op,
+    ACPI_NAMESPACE_NODE     *MethodNode,
+    UINT8                   *AmlStart,
+    UINT32                  AmlLength,
+    ACPI_EVALUATE_INFO      *Info,
+    UINT8                   PassNumber)
+{
+    ACPI_STATUS             Status;
+    ACPI_PARSE_STATE        *ParserState = &WalkState->ParserState;
+    ACPI_PARSE_OBJECT       *ExtraOp;
+
+
+    ACPI_FUNCTION_TRACE (DsInitAmlWalk);
+
+
+    WalkState->ParserState.Aml =
+    WalkState->ParserState.AmlStart = AmlStart;
+    WalkState->ParserState.AmlEnd =
+    WalkState->ParserState.PkgEnd = AmlStart + AmlLength;
+
+    /* The NextOp of the NextWalk will be the beginning of the method */
+
+    WalkState->NextOp = NULL;
+    WalkState->PassNumber = PassNumber;
+
+    if (Info)
+    {
+        WalkState->Params = Info->Parameters;
+        WalkState->CallerReturnDesc = &Info->ReturnObject;
+    }
+
+    Status = AcpiPsInitScope (&WalkState->ParserState, Op);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    if (MethodNode)
+    {
+        WalkState->ParserState.StartNode = MethodNode;
+        WalkState->WalkType = ACPI_WALK_METHOD;
+        WalkState->MethodNode = MethodNode;
+        WalkState->MethodDesc = AcpiNsGetAttachedObject (MethodNode);
+
+        /* Push start scope on scope stack and make it current  */
+
+        Status = AcpiDsScopeStackPush (
+            MethodNode, ACPI_TYPE_METHOD, WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            return_ACPI_STATUS (Status);
+        }
+
+        /* Init the method arguments */
+
+        Status = AcpiDsMethodDataInitArgs (WalkState->Params,
+                    ACPI_METHOD_NUM_ARGS, WalkState);
+        if (ACPI_FAILURE (Status))
+        {
+            return_ACPI_STATUS (Status);
+        }
+    }
+    else
+    {
+        /*
+         * Setup the current scope.
+         * Find a Named Op that has a namespace node associated with it.
+         * search upwards from this Op. Current scope is the first
+         * Op with a namespace node.
+         */
+        ExtraOp = ParserState->StartOp;
+        while (ExtraOp && !ExtraOp->Common.Node)
+        {
+            ExtraOp = ExtraOp->Common.Parent;
+        }
+
+        if (!ExtraOp)
+        {
+            ParserState->StartNode = NULL;
+        }
+        else
+        {
+            ParserState->StartNode = ExtraOp->Common.Node;
+        }
+
+        if (ParserState->StartNode)
+        {
+            /* Push start scope on scope stack and make it current  */
+
+            Status = AcpiDsScopeStackPush (ParserState->StartNode,
+                ParserState->StartNode->Type, WalkState);
+            if (ACPI_FAILURE (Status))
+            {
+                return_ACPI_STATUS (Status);
+            }
+        }
+    }
+
+    Status = AcpiDsInitCallbacks (WalkState, PassNumber);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiDsDeleteWalkState
+ *
+ * PARAMETERS:  WalkState       - State to delete
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Delete a walk state including all internal data structures
+ *
+ ******************************************************************************/
+
+void
+AcpiDsDeleteWalkState (
+    ACPI_WALK_STATE         *WalkState)
+{
+    ACPI_GENERIC_STATE      *State;
+
+
+    ACPI_FUNCTION_TRACE_PTR (DsDeleteWalkState, WalkState);
+
+
+    if (!WalkState)
+    {
+        return_VOID;
+    }
+
+    if (WalkState->DescriptorType != ACPI_DESC_TYPE_WALK)
+    {
+        ACPI_ERROR ((AE_INFO, "%p is not a valid walk state",
+            WalkState));
+        return_VOID;
+    }
+
+    /* There should not be any open scopes */
+
+    if (WalkState->ParserState.Scope)
+    {
+        ACPI_ERROR ((AE_INFO, "%p walk still has a scope list",
+            WalkState));
+        AcpiPsCleanupScope (&WalkState->ParserState);
+    }
+
+    /* Always must free any linked control states */
+
+    while (WalkState->ControlState)
+    {
+        State = WalkState->ControlState;
+        WalkState->ControlState = State->Common.Next;
+
+        AcpiUtDeleteGenericState (State);
+    }
+
+    /* Always must free any linked parse states */
+
+    while (WalkState->ScopeInfo)
+    {
+        State = WalkState->ScopeInfo;
+        WalkState->ScopeInfo = State->Common.Next;
+
+        AcpiUtDeleteGenericState (State);
+    }
+
+    /* Always must free any stacked result states */
+
+    while (WalkState->Results)
+    {
+        State = WalkState->Results;
+        WalkState->Results = State->Common.Next;
+
+        AcpiUtDeleteGenericState (State);
+    }
+
+    ACPI_FREE (WalkState);
+    return_VOID;
+}

+ 336 - 0
kernel/src/acpica/events/evevent.c

@@ -0,0 +1,336 @@
+/******************************************************************************
+ *
+ * Module Name: evevent - Fixed Event handling and dispatch
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acevents.h"
+
+#define _COMPONENT          ACPI_EVENTS
+        ACPI_MODULE_NAME    ("evevent")
+
+#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
+
+/* Local prototypes */
+
+static ACPI_STATUS
+AcpiEvFixedEventInitialize (
+    void);
+
+static UINT32
+AcpiEvFixedEventDispatch (
+    UINT32                  Event);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvInitializeEvents
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Initialize global data structures for ACPI events (Fixed, GPE)
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvInitializeEvents (
+    void)
+{
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE (EvInitializeEvents);
+
+
+    /* If Hardware Reduced flag is set, there are no fixed events */
+
+    if (AcpiGbl_ReducedHardware)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /*
+     * Initialize the Fixed and General Purpose Events. This is done prior to
+     * enabling SCIs to prevent interrupts from occurring before the handlers
+     * are installed.
+     */
+    Status = AcpiEvFixedEventInitialize ();
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_EXCEPTION ((AE_INFO, Status,
+            "Unable to initialize fixed events"));
+        return_ACPI_STATUS (Status);
+    }
+
+    Status = AcpiEvGpeInitialize ();
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_EXCEPTION ((AE_INFO, Status,
+            "Unable to initialize general purpose events"));
+        return_ACPI_STATUS (Status);
+    }
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvInstallXruptHandlers
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Install interrupt handlers for the SCI and Global Lock
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvInstallXruptHandlers (
+    void)
+{
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE (EvInstallXruptHandlers);
+
+
+    /* If Hardware Reduced flag is set, there is no ACPI h/w */
+
+    if (AcpiGbl_ReducedHardware)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Install the SCI handler */
+
+    Status = AcpiEvInstallSciHandler ();
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_EXCEPTION ((AE_INFO, Status,
+            "Unable to install System Control Interrupt handler"));
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Install the handler for the Global Lock */
+
+    Status = AcpiEvInitGlobalLockHandler ();
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_EXCEPTION ((AE_INFO, Status,
+            "Unable to initialize Global Lock handler"));
+        return_ACPI_STATUS (Status);
+    }
+
+    AcpiGbl_EventsInitialized = TRUE;
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvFixedEventInitialize
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Install the fixed event handlers and disable all fixed events.
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiEvFixedEventInitialize (
+    void)
+{
+    UINT32                  i;
+    ACPI_STATUS             Status;
+
+
+    /*
+     * Initialize the structure that keeps track of fixed event handlers and
+     * enable the fixed events.
+     */
+    for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
+    {
+        AcpiGbl_FixedEventHandlers[i].Handler = NULL;
+        AcpiGbl_FixedEventHandlers[i].Context = NULL;
+
+        /* Disable the fixed event */
+
+        if (AcpiGbl_FixedEventInfo[i].EnableRegisterId != 0xFF)
+        {
+            Status = AcpiWriteBitRegister (
+                AcpiGbl_FixedEventInfo[i].EnableRegisterId,
+                ACPI_DISABLE_EVENT);
+            if (ACPI_FAILURE (Status))
+            {
+                return (Status);
+            }
+        }
+    }
+
+    return (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvFixedEventDetect
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
+ *
+ * DESCRIPTION: Checks the PM status register for active fixed events
+ *
+ ******************************************************************************/
+
+UINT32
+AcpiEvFixedEventDetect (
+    void)
+{
+    UINT32                  IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
+    UINT32                  FixedStatus;
+    UINT32                  FixedEnable;
+    UINT32                  i;
+
+
+    ACPI_FUNCTION_NAME (EvFixedEventDetect);
+
+
+    /*
+     * Read the fixed feature status and enable registers, as all the cases
+     * depend on their values. Ignore errors here.
+     */
+    (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_STATUS, &FixedStatus);
+    (void) AcpiHwRegisterRead (ACPI_REGISTER_PM1_ENABLE, &FixedEnable);
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
+        "Fixed Event Block: Enable %08X Status %08X\n",
+        FixedEnable, FixedStatus));
+
+    /*
+     * Check for all possible Fixed Events and dispatch those that are active
+     */
+    for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
+    {
+        /* Both the status and enable bits must be on for this event */
+
+        if ((FixedStatus & AcpiGbl_FixedEventInfo[i].StatusBitMask) &&
+            (FixedEnable & AcpiGbl_FixedEventInfo[i].EnableBitMask))
+        {
+            /*
+             * Found an active (signalled) event. Invoke global event
+             * handler if present.
+             */
+            AcpiFixedEventCount[i]++;
+            if (AcpiGbl_GlobalEventHandler)
+            {
+                AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_FIXED, NULL,
+                     i, AcpiGbl_GlobalEventHandlerContext);
+            }
+
+            IntStatus |= AcpiEvFixedEventDispatch (i);
+        }
+    }
+
+    return (IntStatus);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvFixedEventDispatch
+ *
+ * PARAMETERS:  Event               - Event type
+ *
+ * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
+ *
+ * DESCRIPTION: Clears the status bit for the requested event, calls the
+ *              handler that previously registered for the event.
+ *              NOTE: If there is no handler for the event, the event is
+ *              disabled to prevent further interrupts.
+ *
+ ******************************************************************************/
+
+static UINT32
+AcpiEvFixedEventDispatch (
+    UINT32                  Event)
+{
+
+    ACPI_FUNCTION_ENTRY ();
+
+
+    /* Clear the status bit */
+
+    (void) AcpiWriteBitRegister (
+        AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
+        ACPI_CLEAR_STATUS);
+
+    /*
+     * Make sure that a handler exists. If not, report an error
+     * and disable the event to prevent further interrupts.
+     */
+    if (!AcpiGbl_FixedEventHandlers[Event].Handler)
+    {
+        (void) AcpiWriteBitRegister (
+            AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
+            ACPI_DISABLE_EVENT);
+
+        ACPI_ERROR ((AE_INFO,
+            "No installed handler for fixed event - %s (%u), disabling",
+            AcpiUtGetEventName (Event), Event));
+
+        return (ACPI_INTERRUPT_NOT_HANDLED);
+    }
+
+    /* Invoke the Fixed Event handler */
+
+    return ((AcpiGbl_FixedEventHandlers[Event].Handler)(
+        AcpiGbl_FixedEventHandlers[Event].Context));
+}
+
+#endif /* !ACPI_REDUCED_HARDWARE */

+ 379 - 0
kernel/src/acpica/events/evglock.c

@@ -0,0 +1,379 @@
+/******************************************************************************
+ *
+ * Module Name: evglock - Global Lock support
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acevents.h"
+#include "acinterp.h"
+
+#define _COMPONENT          ACPI_EVENTS
+        ACPI_MODULE_NAME    ("evglock")
+
+#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
+
+/* Local prototypes */
+
+static UINT32
+AcpiEvGlobalLockHandler (
+    void                    *Context);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvInitGlobalLockHandler
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Install a handler for the global lock release event
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvInitGlobalLockHandler (
+    void)
+{
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE (EvInitGlobalLockHandler);
+
+
+    /* If Hardware Reduced flag is set, there is no global lock */
+
+    if (AcpiGbl_ReducedHardware)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Attempt installation of the global lock handler */
+
+    Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL,
+        AcpiEvGlobalLockHandler, NULL);
+
+    /*
+     * If the global lock does not exist on this platform, the attempt to
+     * enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick).
+     * Map to AE_OK, but mark global lock as not present. Any attempt to
+     * actually use the global lock will be flagged with an error.
+     */
+    AcpiGbl_GlobalLockPresent = FALSE;
+    if (Status == AE_NO_HARDWARE_RESPONSE)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "No response from Global Lock hardware, disabling lock"));
+
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    Status = AcpiOsCreateLock (&AcpiGbl_GlobalLockPendingLock);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    AcpiGbl_GlobalLockPending = FALSE;
+    AcpiGbl_GlobalLockPresent = TRUE;
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvRemoveGlobalLockHandler
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Remove the handler for the Global Lock
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvRemoveGlobalLockHandler (
+    void)
+{
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE (EvRemoveGlobalLockHandler);
+
+
+    AcpiGbl_GlobalLockPresent = FALSE;
+    Status = AcpiRemoveFixedEventHandler (ACPI_EVENT_GLOBAL,
+        AcpiEvGlobalLockHandler);
+
+    AcpiOsDeleteLock (AcpiGbl_GlobalLockPendingLock);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvGlobalLockHandler
+ *
+ * PARAMETERS:  Context         - From thread interface, not used
+ *
+ * RETURN:      ACPI_INTERRUPT_HANDLED
+ *
+ * DESCRIPTION: Invoked directly from the SCI handler when a global lock
+ *              release interrupt occurs. If there is actually a pending
+ *              request for the lock, signal the waiting thread.
+ *
+ ******************************************************************************/
+
+static UINT32
+AcpiEvGlobalLockHandler (
+    void                    *Context)
+{
+    ACPI_STATUS             Status;
+    ACPI_CPU_FLAGS          Flags;
+
+
+    Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
+
+    /*
+     * If a request for the global lock is not actually pending,
+     * we are done. This handles "spurious" global lock interrupts
+     * which are possible (and have been seen) with bad BIOSs.
+     */
+    if (!AcpiGbl_GlobalLockPending)
+    {
+        goto CleanupAndExit;
+    }
+
+    /*
+     * Send a unit to the global lock semaphore. The actual acquisition
+     * of the global lock will be performed by the waiting thread.
+     */
+    Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 1);
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_ERROR ((AE_INFO, "Could not signal Global Lock semaphore"));
+    }
+
+    AcpiGbl_GlobalLockPending = FALSE;
+
+
+CleanupAndExit:
+
+    AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
+    return (ACPI_INTERRUPT_HANDLED);
+}
+
+
+/******************************************************************************
+ *
+ * FUNCTION:    AcpiEvAcquireGlobalLock
+ *
+ * PARAMETERS:  Timeout         - Max time to wait for the lock, in millisec.
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Attempt to gain ownership of the Global Lock.
+ *
+ * MUTEX:       Interpreter must be locked
+ *
+ * Note: The original implementation allowed multiple threads to "acquire" the
+ * Global Lock, and the OS would hold the lock until the last thread had
+ * released it. However, this could potentially starve the BIOS out of the
+ * lock, especially in the case where there is a tight handshake between the
+ * Embedded Controller driver and the BIOS. Therefore, this implementation
+ * allows only one thread to acquire the HW Global Lock at a time, and makes
+ * the global lock appear as a standard mutex on the OS side.
+ *
+ *****************************************************************************/
+
+ACPI_STATUS
+AcpiEvAcquireGlobalLock (
+    UINT16                  Timeout)
+{
+    ACPI_CPU_FLAGS          Flags;
+    ACPI_STATUS             Status;
+    BOOLEAN                 Acquired = FALSE;
+
+
+    ACPI_FUNCTION_TRACE (EvAcquireGlobalLock);
+
+
+    /*
+     * Only one thread can acquire the GL at a time, the GlobalLockMutex
+     * enforces this. This interface releases the interpreter if we must wait.
+     */
+    Status = AcpiExSystemWaitMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex,
+                Timeout);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /*
+     * Update the global lock handle and check for wraparound. The handle is
+     * only used for the external global lock interfaces, but it is updated
+     * here to properly handle the case where a single thread may acquire the
+     * lock via both the AML and the AcpiAcquireGlobalLock interfaces. The
+     * handle is therefore updated on the first acquire from a given thread
+     * regardless of where the acquisition request originated.
+     */
+    AcpiGbl_GlobalLockHandle++;
+    if (AcpiGbl_GlobalLockHandle == 0)
+    {
+        AcpiGbl_GlobalLockHandle = 1;
+    }
+
+    /*
+     * Make sure that a global lock actually exists. If not, just
+     * treat the lock as a standard mutex.
+     */
+    if (!AcpiGbl_GlobalLockPresent)
+    {
+        AcpiGbl_GlobalLockAcquired = TRUE;
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
+
+    do
+    {
+        /* Attempt to acquire the actual hardware lock */
+
+        ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_FACS, Acquired);
+        if (Acquired)
+        {
+            AcpiGbl_GlobalLockAcquired = TRUE;
+            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+                "Acquired hardware Global Lock\n"));
+            break;
+        }
+
+        /*
+         * Did not get the lock. The pending bit was set above, and
+         * we must now wait until we receive the global lock
+         * released interrupt.
+         */
+        AcpiGbl_GlobalLockPending = TRUE;
+        AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
+            "Waiting for hardware Global Lock\n"));
+
+        /*
+         * Wait for handshake with the global lock interrupt handler.
+         * This interface releases the interpreter if we must wait.
+         */
+        Status = AcpiExSystemWaitSemaphore (
+            AcpiGbl_GlobalLockSemaphore, ACPI_WAIT_FOREVER);
+
+        Flags = AcpiOsAcquireLock (AcpiGbl_GlobalLockPendingLock);
+
+    } while (ACPI_SUCCESS (Status));
+
+    AcpiGbl_GlobalLockPending = FALSE;
+    AcpiOsReleaseLock (AcpiGbl_GlobalLockPendingLock, Flags);
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvReleaseGlobalLock
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Releases ownership of the Global Lock.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvReleaseGlobalLock (
+    void)
+{
+    BOOLEAN                 Pending = FALSE;
+    ACPI_STATUS             Status = AE_OK;
+
+
+    ACPI_FUNCTION_TRACE (EvReleaseGlobalLock);
+
+
+    /* Lock must be already acquired */
+
+    if (!AcpiGbl_GlobalLockAcquired)
+    {
+        ACPI_WARNING ((AE_INFO,
+            "Cannot release the ACPI Global Lock, it has not been acquired"));
+        return_ACPI_STATUS (AE_NOT_ACQUIRED);
+    }
+
+    if (AcpiGbl_GlobalLockPresent)
+    {
+        /* Allow any thread to release the lock */
+
+        ACPI_RELEASE_GLOBAL_LOCK (AcpiGbl_FACS, Pending);
+
+        /*
+         * If the pending bit was set, we must write GBL_RLS to the control
+         * register
+         */
+        if (Pending)
+        {
+            Status = AcpiWriteBitRegister (
+                ACPI_BITREG_GLOBAL_LOCK_RELEASE, ACPI_ENABLE_EVENT);
+        }
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Released hardware Global Lock\n"));
+    }
+
+    AcpiGbl_GlobalLockAcquired = FALSE;
+
+    /* Release the local GL mutex */
+
+    AcpiOsReleaseMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex);
+    return_ACPI_STATUS (Status);
+}
+
+#endif /* !ACPI_REDUCED_HARDWARE */

+ 843 - 0
kernel/src/acpica/events/evgpe.c

@@ -0,0 +1,843 @@
+/******************************************************************************
+ *
+ * Module Name: evgpe - General Purpose Event handling and dispatch
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acevents.h"
+#include "acnamesp.h"
+
+#define _COMPONENT          ACPI_EVENTS
+        ACPI_MODULE_NAME    ("evgpe")
+
+#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
+
+/* Local prototypes */
+
+static void ACPI_SYSTEM_XFACE
+AcpiEvAsynchExecuteGpeMethod (
+    void                    *Context);
+
+static void ACPI_SYSTEM_XFACE
+AcpiEvAsynchEnableGpe (
+    void                    *Context);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvUpdateGpeEnableMask
+ *
+ * PARAMETERS:  GpeEventInfo            - GPE to update
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Updates GPE register enable mask based upon whether there are
+ *              runtime references to this GPE
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvUpdateGpeEnableMask (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo)
+{
+    ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
+    UINT32                  RegisterBit;
+
+
+    ACPI_FUNCTION_TRACE (EvUpdateGpeEnableMask);
+
+
+    GpeRegisterInfo = GpeEventInfo->RegisterInfo;
+    if (!GpeRegisterInfo)
+    {
+        return_ACPI_STATUS (AE_NOT_EXIST);
+    }
+
+    RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
+
+    /* Clear the run bit up front */
+
+    ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
+
+    /* Set the mask bit only if there are references to this GPE */
+
+    if (GpeEventInfo->RuntimeCount)
+    {
+        ACPI_SET_BIT (GpeRegisterInfo->EnableForRun, (UINT8) RegisterBit);
+    }
+
+    GpeRegisterInfo->EnableMask = GpeRegisterInfo->EnableForRun;
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvEnableGpe
+ *
+ * PARAMETERS:  GpeEventInfo            - GPE to enable
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Clear a GPE of stale events and enable it.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvEnableGpe (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo)
+{
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE (EvEnableGpe);
+
+
+    /* Clear the GPE (of stale events) */
+
+    Status = AcpiHwClearGpe (GpeEventInfo);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Enable the requested GPE */
+
+    Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvAddGpeReference
+ *
+ * PARAMETERS:  GpeEventInfo            - Add a reference to this GPE
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
+ *              hardware-enabled.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvAddGpeReference (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo)
+{
+    ACPI_STATUS             Status = AE_OK;
+
+
+    ACPI_FUNCTION_TRACE (EvAddGpeReference);
+
+
+    if (GpeEventInfo->RuntimeCount == ACPI_UINT8_MAX)
+    {
+        return_ACPI_STATUS (AE_LIMIT);
+    }
+
+    GpeEventInfo->RuntimeCount++;
+    if (GpeEventInfo->RuntimeCount == 1)
+    {
+        /* Enable on first reference */
+
+        Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);
+        if (ACPI_SUCCESS (Status))
+        {
+            Status = AcpiEvEnableGpe (GpeEventInfo);
+        }
+
+        if (ACPI_FAILURE (Status))
+        {
+            GpeEventInfo->RuntimeCount--;
+        }
+    }
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvRemoveGpeReference
+ *
+ * PARAMETERS:  GpeEventInfo            - Remove a reference to this GPE
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Remove a reference to a GPE. When the last reference is
+ *              removed, the GPE is hardware-disabled.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvRemoveGpeReference (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo)
+{
+    ACPI_STATUS             Status = AE_OK;
+
+
+    ACPI_FUNCTION_TRACE (EvRemoveGpeReference);
+
+
+    if (!GpeEventInfo->RuntimeCount)
+    {
+        return_ACPI_STATUS (AE_LIMIT);
+    }
+
+    GpeEventInfo->RuntimeCount--;
+    if (!GpeEventInfo->RuntimeCount)
+    {
+        /* Disable on last reference */
+
+        Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);
+        if (ACPI_SUCCESS (Status))
+        {
+            Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
+        }
+
+        if (ACPI_FAILURE (Status))
+        {
+            GpeEventInfo->RuntimeCount++;
+        }
+    }
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvLowGetGpeInfo
+ *
+ * PARAMETERS:  GpeNumber           - Raw GPE number
+ *              GpeBlock            - A GPE info block
+ *
+ * RETURN:      A GPE EventInfo struct. NULL if not a valid GPE (The GpeNumber
+ *              is not within the specified GPE block)
+ *
+ * DESCRIPTION: Returns the EventInfo struct associated with this GPE. This is
+ *              the low-level implementation of EvGetGpeEventInfo.
+ *
+ ******************************************************************************/
+
+ACPI_GPE_EVENT_INFO *
+AcpiEvLowGetGpeInfo (
+    UINT32                  GpeNumber,
+    ACPI_GPE_BLOCK_INFO     *GpeBlock)
+{
+    UINT32                  GpeIndex;
+
+
+    /*
+     * Validate that the GpeNumber is within the specified GpeBlock.
+     * (Two steps)
+     */
+    if (!GpeBlock ||
+        (GpeNumber < GpeBlock->BlockBaseNumber))
+    {
+        return (NULL);
+    }
+
+    GpeIndex = GpeNumber - GpeBlock->BlockBaseNumber;
+    if (GpeIndex >= GpeBlock->GpeCount)
+    {
+        return (NULL);
+    }
+
+    return (&GpeBlock->EventInfo[GpeIndex]);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvGetGpeEventInfo
+ *
+ * PARAMETERS:  GpeDevice           - Device node. NULL for GPE0/GPE1
+ *              GpeNumber           - Raw GPE number
+ *
+ * RETURN:      A GPE EventInfo struct. NULL if not a valid GPE
+ *
+ * DESCRIPTION: Returns the EventInfo struct associated with this GPE.
+ *              Validates the GpeBlock and the GpeNumber
+ *
+ *              Should be called only when the GPE lists are semaphore locked
+ *              and not subject to change.
+ *
+ ******************************************************************************/
+
+ACPI_GPE_EVENT_INFO *
+AcpiEvGetGpeEventInfo (
+    ACPI_HANDLE             GpeDevice,
+    UINT32                  GpeNumber)
+{
+    ACPI_OPERAND_OBJECT     *ObjDesc;
+    ACPI_GPE_EVENT_INFO     *GpeInfo;
+    UINT32                  i;
+
+
+    ACPI_FUNCTION_ENTRY ();
+
+
+    /* A NULL GpeDevice means use the FADT-defined GPE block(s) */
+
+    if (!GpeDevice)
+    {
+        /* Examine GPE Block 0 and 1 (These blocks are permanent) */
+
+        for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++)
+        {
+            GpeInfo = AcpiEvLowGetGpeInfo (GpeNumber,
+                AcpiGbl_GpeFadtBlocks[i]);
+            if (GpeInfo)
+            {
+                return (GpeInfo);
+            }
+        }
+
+        /* The GpeNumber was not in the range of either FADT GPE block */
+
+        return (NULL);
+    }
+
+    /* A Non-NULL GpeDevice means this is a GPE Block Device */
+
+    ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) GpeDevice);
+    if (!ObjDesc ||
+        !ObjDesc->Device.GpeBlock)
+    {
+        return (NULL);
+    }
+
+    return (AcpiEvLowGetGpeInfo (GpeNumber, ObjDesc->Device.GpeBlock));
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvGpeDetect
+ *
+ * PARAMETERS:  GpeXruptList        - Interrupt block for this interrupt.
+ *                                    Can have multiple GPE blocks attached.
+ *
+ * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
+ *
+ * DESCRIPTION: Detect if any GP events have occurred. This function is
+ *              executed at interrupt level.
+ *
+ ******************************************************************************/
+
+UINT32
+AcpiEvGpeDetect (
+    ACPI_GPE_XRUPT_INFO     *GpeXruptList)
+{
+    ACPI_STATUS             Status;
+    ACPI_GPE_BLOCK_INFO     *GpeBlock;
+    ACPI_NAMESPACE_NODE     *GpeDevice;
+    ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
+    UINT32                  GpeNumber;
+    ACPI_GPE_HANDLER_INFO   *GpeHandlerInfo;
+    UINT32                  IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
+    UINT8                   EnabledStatusByte;
+    UINT32                  StatusReg;
+    UINT32                  EnableReg;
+    ACPI_CPU_FLAGS          Flags;
+    UINT32                  i;
+    UINT32                  j;
+
+
+    ACPI_FUNCTION_NAME (EvGpeDetect);
+
+    /* Check for the case where there are no GPEs */
+
+    if (!GpeXruptList)
+    {
+        return (IntStatus);
+    }
+
+    /*
+     * We need to obtain the GPE lock for both the data structs and registers
+     * Note: Not necessary to obtain the hardware lock, since the GPE
+     * registers are owned by the GpeLock.
+     */
+    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
+
+    /* Examine all GPE blocks attached to this interrupt level */
+
+    GpeBlock = GpeXruptList->GpeBlockListHead;
+    while (GpeBlock)
+    {
+        GpeDevice = GpeBlock->Node;
+
+        /*
+         * Read all of the 8-bit GPE status and enable registers in this GPE
+         * block, saving all of them. Find all currently active GP events.
+         */
+        for (i = 0; i < GpeBlock->RegisterCount; i++)
+        {
+            /* Get the next status/enable pair */
+
+            GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
+
+            /*
+             * Optimization: If there are no GPEs enabled within this
+             * register, we can safely ignore the entire register.
+             */
+            if (!(GpeRegisterInfo->EnableForRun |
+                  GpeRegisterInfo->EnableForWake))
+            {
+                ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
+                    "Ignore disabled registers for GPE %02X-%02X: "
+                    "RunEnable=%02X, WakeEnable=%02X\n",
+                    GpeRegisterInfo->BaseGpeNumber,
+                    GpeRegisterInfo->BaseGpeNumber + (ACPI_GPE_REGISTER_WIDTH - 1),
+                    GpeRegisterInfo->EnableForRun,
+                    GpeRegisterInfo->EnableForWake));
+                continue;
+            }
+
+            /* Read the Status Register */
+
+            Status = AcpiHwRead (&StatusReg, &GpeRegisterInfo->StatusAddress);
+            if (ACPI_FAILURE (Status))
+            {
+                goto UnlockAndExit;
+            }
+
+            /* Read the Enable Register */
+
+            Status = AcpiHwRead (&EnableReg, &GpeRegisterInfo->EnableAddress);
+            if (ACPI_FAILURE (Status))
+            {
+                goto UnlockAndExit;
+            }
+
+            ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
+                "Read registers for GPE %02X-%02X: Status=%02X, Enable=%02X, "
+                "RunEnable=%02X, WakeEnable=%02X\n",
+                GpeRegisterInfo->BaseGpeNumber,
+                GpeRegisterInfo->BaseGpeNumber + (ACPI_GPE_REGISTER_WIDTH - 1),
+                StatusReg, EnableReg,
+                GpeRegisterInfo->EnableForRun,
+                GpeRegisterInfo->EnableForWake));
+
+            /* Check if there is anything active at all in this register */
+
+            EnabledStatusByte = (UINT8) (StatusReg & EnableReg);
+            if (!EnabledStatusByte)
+            {
+                /* No active GPEs in this register, move on */
+
+                continue;
+            }
+
+            /* Now look at the individual GPEs in this byte register */
+
+            for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
+            {
+                /* Examine one GPE bit */
+
+                GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *
+                    ACPI_GPE_REGISTER_WIDTH) + j];
+                GpeNumber = j + GpeRegisterInfo->BaseGpeNumber;
+
+                if (EnabledStatusByte & (1 << j))
+                {
+                    /* Invoke global event handler if present */
+
+                    AcpiGpeCount++;
+                    if (AcpiGbl_GlobalEventHandler)
+                    {
+                        AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_GPE,
+                            GpeDevice, GpeNumber,
+                            AcpiGbl_GlobalEventHandlerContext);
+                    }
+
+                    /* Found an active GPE */
+
+                    if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
+                        ACPI_GPE_DISPATCH_RAW_HANDLER)
+                    {
+                        /* Dispatch the event to a raw handler */
+
+                        GpeHandlerInfo = GpeEventInfo->Dispatch.Handler;
+
+                        /*
+                         * There is no protection around the namespace node
+                         * and the GPE handler to ensure a safe destruction
+                         * because:
+                         * 1. The namespace node is expected to always
+                         *    exist after loading a table.
+                         * 2. The GPE handler is expected to be flushed by
+                         *    AcpiOsWaitEventsComplete() before the
+                         *    destruction.
+                         */
+                        AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
+                        IntStatus |= GpeHandlerInfo->Address (
+                            GpeDevice, GpeNumber, GpeHandlerInfo->Context);
+                        Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
+                    }
+                    else
+                    {
+                        /*
+                         * Dispatch the event to a standard handler or
+                         * method.
+                         */
+                        IntStatus |= AcpiEvGpeDispatch (GpeDevice,
+                            GpeEventInfo, GpeNumber);
+                    }
+                }
+            }
+        }
+
+        GpeBlock = GpeBlock->Next;
+    }
+
+UnlockAndExit:
+
+    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
+    return (IntStatus);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvAsynchExecuteGpeMethod
+ *
+ * PARAMETERS:  Context (GpeEventInfo) - Info for this GPE
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Perform the actual execution of a GPE control method. This
+ *              function is called from an invocation of AcpiOsExecute and
+ *              therefore does NOT execute at interrupt level - so that
+ *              the control method itself is not executed in the context of
+ *              an interrupt handler.
+ *
+ ******************************************************************************/
+
+static void ACPI_SYSTEM_XFACE
+AcpiEvAsynchExecuteGpeMethod (
+    void                    *Context)
+{
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo = Context;
+    ACPI_STATUS             Status = AE_OK;
+    ACPI_EVALUATE_INFO      *Info;
+    ACPI_GPE_NOTIFY_INFO    *Notify;
+
+
+    ACPI_FUNCTION_TRACE (EvAsynchExecuteGpeMethod);
+
+
+    /* Do the correct dispatch - normal method or implicit notify */
+
+    switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))
+    {
+    case ACPI_GPE_DISPATCH_NOTIFY:
+        /*
+         * Implicit notify.
+         * Dispatch a DEVICE_WAKE notify to the appropriate handler.
+         * NOTE: the request is queued for execution after this method
+         * completes. The notify handlers are NOT invoked synchronously
+         * from this thread -- because handlers may in turn run other
+         * control methods.
+         *
+         * June 2012: Expand implicit notify mechanism to support
+         * notifies on multiple device objects.
+         */
+        Notify = GpeEventInfo->Dispatch.NotifyList;
+        while (ACPI_SUCCESS (Status) && Notify)
+        {
+            Status = AcpiEvQueueNotifyRequest (
+                Notify->DeviceNode, ACPI_NOTIFY_DEVICE_WAKE);
+
+            Notify = Notify->Next;
+        }
+        break;
+
+    case ACPI_GPE_DISPATCH_METHOD:
+
+        /* Allocate the evaluation information block */
+
+        Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
+        if (!Info)
+        {
+            Status = AE_NO_MEMORY;
+        }
+        else
+        {
+            /*
+             * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the
+             * _Lxx/_Exx control method that corresponds to this GPE
+             */
+            Info->PrefixNode = GpeEventInfo->Dispatch.MethodNode;
+            Info->Flags = ACPI_IGNORE_RETURN_VALUE;
+
+            Status = AcpiNsEvaluate (Info);
+            ACPI_FREE (Info);
+        }
+
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_EXCEPTION ((AE_INFO, Status,
+                "while evaluating GPE method [%4.4s]",
+                AcpiUtGetNodeName (GpeEventInfo->Dispatch.MethodNode)));
+        }
+        break;
+
+    default:
+
+        goto ErrorExit; /* Should never happen */
+    }
+
+    /* Defer enabling of GPE until all notify handlers are done */
+
+    Status = AcpiOsExecute (OSL_NOTIFY_HANDLER,
+        AcpiEvAsynchEnableGpe, GpeEventInfo);
+    if (ACPI_SUCCESS (Status))
+    {
+        return_VOID;
+    }
+
+ErrorExit:
+    AcpiEvAsynchEnableGpe (GpeEventInfo);
+    return_VOID;
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvAsynchEnableGpe
+ *
+ * PARAMETERS:  Context (GpeEventInfo) - Info for this GPE
+ *              Callback from AcpiOsExecute
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to
+ *              complete (i.e., finish execution of Notify)
+ *
+ ******************************************************************************/
+
+static void ACPI_SYSTEM_XFACE
+AcpiEvAsynchEnableGpe (
+    void                    *Context)
+{
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo = Context;
+    ACPI_CPU_FLAGS          Flags;
+
+
+    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
+    (void) AcpiEvFinishGpe (GpeEventInfo);
+    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
+
+    return;
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvFinishGpe
+ *
+ * PARAMETERS:  GpeEventInfo        - Info for this GPE
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Clear/Enable a GPE. Common code that is used after execution
+ *              of a GPE method or a synchronous or asynchronous GPE handler.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvFinishGpe (
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo)
+{
+    ACPI_STATUS             Status;
+
+
+    if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
+            ACPI_GPE_LEVEL_TRIGGERED)
+    {
+        /*
+         * GPE is level-triggered, we clear the GPE status bit after
+         * handling the event.
+         */
+        Status = AcpiHwClearGpe (GpeEventInfo);
+        if (ACPI_FAILURE (Status))
+        {
+            return (Status);
+        }
+    }
+
+    /*
+     * Enable this GPE, conditionally. This means that the GPE will
+     * only be physically enabled if the EnableMask bit is set
+     * in the EventInfo.
+     */
+    (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_CONDITIONAL_ENABLE);
+    return (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvGpeDispatch
+ *
+ * PARAMETERS:  GpeDevice           - Device node. NULL for GPE0/GPE1
+ *              GpeEventInfo        - Info for this GPE
+ *              GpeNumber           - Number relative to the parent GPE block
+ *
+ * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
+ *
+ * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
+ *              or method (e.g. _Lxx/_Exx) handler.
+ *
+ *              This function executes at interrupt level.
+ *
+ ******************************************************************************/
+
+UINT32
+AcpiEvGpeDispatch (
+    ACPI_NAMESPACE_NODE     *GpeDevice,
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo,
+    UINT32                  GpeNumber)
+{
+    ACPI_STATUS             Status;
+    UINT32                  ReturnValue;
+
+
+    ACPI_FUNCTION_TRACE (EvGpeDispatch);
+
+
+    /*
+     * Always disable the GPE so that it does not keep firing before
+     * any asynchronous activity completes (either from the execution
+     * of a GPE method or an asynchronous GPE handler.)
+     *
+     * If there is no handler or method to run, just disable the
+     * GPE and leave it disabled permanently to prevent further such
+     * pointless events from firing.
+     */
+    Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_EXCEPTION ((AE_INFO, Status,
+            "Unable to disable GPE %02X", GpeNumber));
+        return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
+    }
+
+    /*
+     * If edge-triggered, clear the GPE status bit now. Note that
+     * level-triggered events are cleared after the GPE is serviced.
+     */
+    if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
+            ACPI_GPE_EDGE_TRIGGERED)
+    {
+        Status = AcpiHwClearGpe (GpeEventInfo);
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_EXCEPTION ((AE_INFO, Status,
+                "Unable to clear GPE %02X", GpeNumber));
+            (void) AcpiHwLowSetGpe (
+                GpeEventInfo, ACPI_GPE_CONDITIONAL_ENABLE);
+            return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
+        }
+    }
+
+    /*
+     * Dispatch the GPE to either an installed handler or the control
+     * method associated with this GPE (_Lxx or _Exx). If a handler
+     * exists, we invoke it and do not attempt to run the method.
+     * If there is neither a handler nor a method, leave the GPE
+     * disabled.
+     */
+    switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))
+    {
+    case ACPI_GPE_DISPATCH_HANDLER:
+
+        /* Invoke the installed handler (at interrupt level) */
+
+        ReturnValue = GpeEventInfo->Dispatch.Handler->Address (
+            GpeDevice, GpeNumber,
+            GpeEventInfo->Dispatch.Handler->Context);
+
+        /* If requested, clear (if level-triggered) and reenable the GPE */
+
+        if (ReturnValue & ACPI_REENABLE_GPE)
+        {
+            (void) AcpiEvFinishGpe (GpeEventInfo);
+        }
+        break;
+
+    case ACPI_GPE_DISPATCH_METHOD:
+    case ACPI_GPE_DISPATCH_NOTIFY:
+        /*
+         * Execute the method associated with the GPE
+         * NOTE: Level-triggered GPEs are cleared after the method completes.
+         */
+        Status = AcpiOsExecute (OSL_GPE_HANDLER,
+            AcpiEvAsynchExecuteGpeMethod, GpeEventInfo);
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_EXCEPTION ((AE_INFO, Status,
+                "Unable to queue handler for GPE %02X - event disabled",
+                GpeNumber));
+        }
+        break;
+
+    default:
+        /*
+         * No handler or method to run!
+         * 03/2010: This case should no longer be possible. We will not allow
+         * a GPE to be enabled if it has no handler or method.
+         */
+        ACPI_ERROR ((AE_INFO,
+            "No handler or method for GPE %02X, disabling event",
+            GpeNumber));
+        break;
+    }
+
+    return_UINT32 (ACPI_INTERRUPT_HANDLED);
+}
+
+#endif /* !ACPI_REDUCED_HARDWARE */

+ 555 - 0
kernel/src/acpica/events/evgpeblk.c

@@ -0,0 +1,555 @@
+/******************************************************************************
+ *
+ * Module Name: evgpeblk - GPE block creation and initialization.
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acevents.h"
+#include "acnamesp.h"
+
+#define _COMPONENT          ACPI_EVENTS
+        ACPI_MODULE_NAME    ("evgpeblk")
+
+#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
+
+/* Local prototypes */
+
+static ACPI_STATUS
+AcpiEvInstallGpeBlock (
+    ACPI_GPE_BLOCK_INFO     *GpeBlock,
+    UINT32                  InterruptNumber);
+
+static ACPI_STATUS
+AcpiEvCreateGpeInfoBlocks (
+    ACPI_GPE_BLOCK_INFO     *GpeBlock);
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvInstallGpeBlock
+ *
+ * PARAMETERS:  GpeBlock                - New GPE block
+ *              InterruptNumber         - Xrupt to be associated with this
+ *                                        GPE block
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Install new GPE block with mutex support
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiEvInstallGpeBlock (
+    ACPI_GPE_BLOCK_INFO     *GpeBlock,
+    UINT32                  InterruptNumber)
+{
+    ACPI_GPE_BLOCK_INFO     *NextGpeBlock;
+    ACPI_GPE_XRUPT_INFO     *GpeXruptBlock;
+    ACPI_STATUS             Status;
+    ACPI_CPU_FLAGS          Flags;
+
+
+    ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
+
+
+    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    Status = AcpiEvGetGpeXruptBlock (InterruptNumber, &GpeXruptBlock);
+    if (ACPI_FAILURE (Status))
+    {
+        goto UnlockAndExit;
+    }
+
+    /* Install the new block at the end of the list with lock */
+
+    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
+    if (GpeXruptBlock->GpeBlockListHead)
+    {
+        NextGpeBlock = GpeXruptBlock->GpeBlockListHead;
+        while (NextGpeBlock->Next)
+        {
+            NextGpeBlock = NextGpeBlock->Next;
+        }
+
+        NextGpeBlock->Next = GpeBlock;
+        GpeBlock->Previous = NextGpeBlock;
+    }
+    else
+    {
+        GpeXruptBlock->GpeBlockListHead = GpeBlock;
+    }
+
+    GpeBlock->XruptBlock = GpeXruptBlock;
+    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
+
+
+UnlockAndExit:
+    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvDeleteGpeBlock
+ *
+ * PARAMETERS:  GpeBlock            - Existing GPE block
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Remove a GPE block
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvDeleteGpeBlock (
+    ACPI_GPE_BLOCK_INFO     *GpeBlock)
+{
+    ACPI_STATUS             Status;
+    ACPI_CPU_FLAGS          Flags;
+
+
+    ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
+
+
+    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Disable all GPEs in this block */
+
+    Status = AcpiHwDisableGpeBlock (GpeBlock->XruptBlock, GpeBlock, NULL);
+
+    if (!GpeBlock->Previous && !GpeBlock->Next)
+    {
+        /* This is the last GpeBlock on this interrupt */
+
+        Status = AcpiEvDeleteGpeXrupt (GpeBlock->XruptBlock);
+        if (ACPI_FAILURE (Status))
+        {
+            goto UnlockAndExit;
+        }
+    }
+    else
+    {
+        /* Remove the block on this interrupt with lock */
+
+        Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
+        if (GpeBlock->Previous)
+        {
+            GpeBlock->Previous->Next = GpeBlock->Next;
+        }
+        else
+        {
+            GpeBlock->XruptBlock->GpeBlockListHead = GpeBlock->Next;
+        }
+
+        if (GpeBlock->Next)
+        {
+            GpeBlock->Next->Previous = GpeBlock->Previous;
+        }
+
+        AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
+    }
+
+    AcpiCurrentGpeCount -= GpeBlock->GpeCount;
+
+    /* Free the GpeBlock */
+
+    ACPI_FREE (GpeBlock->RegisterInfo);
+    ACPI_FREE (GpeBlock->EventInfo);
+    ACPI_FREE (GpeBlock);
+
+UnlockAndExit:
+    Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvCreateGpeInfoBlocks
+ *
+ * PARAMETERS:  GpeBlock    - New GPE block
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
+ *
+ ******************************************************************************/
+
+static ACPI_STATUS
+AcpiEvCreateGpeInfoBlocks (
+    ACPI_GPE_BLOCK_INFO     *GpeBlock)
+{
+    ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo = NULL;
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo = NULL;
+    ACPI_GPE_EVENT_INFO     *ThisEvent;
+    ACPI_GPE_REGISTER_INFO  *ThisRegister;
+    UINT32                  i;
+    UINT32                  j;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE (EvCreateGpeInfoBlocks);
+
+
+    /* Allocate the GPE register information block */
+
+    GpeRegisterInfo = ACPI_ALLOCATE_ZEROED (
+        (ACPI_SIZE) GpeBlock->RegisterCount *
+        sizeof (ACPI_GPE_REGISTER_INFO));
+    if (!GpeRegisterInfo)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "Could not allocate the GpeRegisterInfo table"));
+        return_ACPI_STATUS (AE_NO_MEMORY);
+    }
+
+    /*
+     * Allocate the GPE EventInfo block. There are eight distinct GPEs
+     * per register. Initialization to zeros is sufficient.
+     */
+    GpeEventInfo = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) GpeBlock->GpeCount *
+        sizeof (ACPI_GPE_EVENT_INFO));
+    if (!GpeEventInfo)
+    {
+        ACPI_ERROR ((AE_INFO,
+            "Could not allocate the GpeEventInfo table"));
+        Status = AE_NO_MEMORY;
+        goto ErrorExit;
+    }
+
+    /* Save the new Info arrays in the GPE block */
+
+    GpeBlock->RegisterInfo = GpeRegisterInfo;
+    GpeBlock->EventInfo = GpeEventInfo;
+
+    /*
+     * Initialize the GPE Register and Event structures. A goal of these
+     * tables is to hide the fact that there are two separate GPE register
+     * sets in a given GPE hardware block, the status registers occupy the
+     * first half, and the enable registers occupy the second half.
+     */
+    ThisRegister = GpeRegisterInfo;
+    ThisEvent = GpeEventInfo;
+
+    for (i = 0; i < GpeBlock->RegisterCount; i++)
+    {
+        /* Init the RegisterInfo for this GPE register (8 GPEs) */
+
+        ThisRegister->BaseGpeNumber = (UINT16)
+            (GpeBlock->BlockBaseNumber + (i * ACPI_GPE_REGISTER_WIDTH));
+
+        ThisRegister->StatusAddress.Address =
+            GpeBlock->Address + i;
+
+        ThisRegister->EnableAddress.Address =
+            GpeBlock->Address + i + GpeBlock->RegisterCount;
+
+        ThisRegister->StatusAddress.SpaceId   = GpeBlock->SpaceId;
+        ThisRegister->EnableAddress.SpaceId   = GpeBlock->SpaceId;
+        ThisRegister->StatusAddress.BitWidth  = ACPI_GPE_REGISTER_WIDTH;
+        ThisRegister->EnableAddress.BitWidth  = ACPI_GPE_REGISTER_WIDTH;
+        ThisRegister->StatusAddress.BitOffset = 0;
+        ThisRegister->EnableAddress.BitOffset = 0;
+
+        /* Init the EventInfo for each GPE within this register */
+
+        for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
+        {
+            ThisEvent->GpeNumber = (UINT8) (ThisRegister->BaseGpeNumber + j);
+            ThisEvent->RegisterInfo = ThisRegister;
+            ThisEvent++;
+        }
+
+        /* Disable all GPEs within this register */
+
+        Status = AcpiHwWrite (0x00, &ThisRegister->EnableAddress);
+        if (ACPI_FAILURE (Status))
+        {
+            goto ErrorExit;
+        }
+
+        /* Clear any pending GPE events within this register */
+
+        Status = AcpiHwWrite (0xFF, &ThisRegister->StatusAddress);
+        if (ACPI_FAILURE (Status))
+        {
+            goto ErrorExit;
+        }
+
+        ThisRegister++;
+    }
+
+    return_ACPI_STATUS (AE_OK);
+
+
+ErrorExit:
+    if (GpeRegisterInfo)
+    {
+        ACPI_FREE (GpeRegisterInfo);
+    }
+    if (GpeEventInfo)
+    {
+        ACPI_FREE (GpeEventInfo);
+    }
+
+    return_ACPI_STATUS (Status);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvCreateGpeBlock
+ *
+ * PARAMETERS:  GpeDevice           - Handle to the parent GPE block
+ *              GpeBlockAddress     - Address and SpaceID
+ *              RegisterCount       - Number of GPE register pairs in the block
+ *              GpeBlockBaseNumber  - Starting GPE number for the block
+ *              InterruptNumber     - H/W interrupt for the block
+ *              ReturnGpeBlock      - Where the new block descriptor is returned
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
+ *              the block are disabled at exit.
+ *              Note: Assumes namespace is locked.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvCreateGpeBlock (
+    ACPI_NAMESPACE_NODE     *GpeDevice,
+    UINT64                  Address,
+    UINT8                   SpaceId,
+    UINT32                  RegisterCount,
+    UINT16                  GpeBlockBaseNumber,
+    UINT32                  InterruptNumber,
+    ACPI_GPE_BLOCK_INFO     **ReturnGpeBlock)
+{
+    ACPI_STATUS             Status;
+    ACPI_GPE_BLOCK_INFO     *GpeBlock;
+    ACPI_GPE_WALK_INFO      WalkInfo;
+
+
+    ACPI_FUNCTION_TRACE (EvCreateGpeBlock);
+
+
+    if (!RegisterCount)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Allocate a new GPE block */
+
+    GpeBlock = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_BLOCK_INFO));
+    if (!GpeBlock)
+    {
+        return_ACPI_STATUS (AE_NO_MEMORY);
+    }
+
+    /* Initialize the new GPE block */
+
+    GpeBlock->Address = Address;
+    GpeBlock->SpaceId = SpaceId;
+    GpeBlock->Node = GpeDevice;
+    GpeBlock->GpeCount = (UINT16) (RegisterCount * ACPI_GPE_REGISTER_WIDTH);
+    GpeBlock->Initialized = FALSE;
+    GpeBlock->RegisterCount = RegisterCount;
+    GpeBlock->BlockBaseNumber = GpeBlockBaseNumber;
+
+    /*
+     * Create the RegisterInfo and EventInfo sub-structures
+     * Note: disables and clears all GPEs in the block
+     */
+    Status = AcpiEvCreateGpeInfoBlocks (GpeBlock);
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_FREE (GpeBlock);
+        return_ACPI_STATUS (Status);
+    }
+
+    /* Install the new block in the global lists */
+
+    Status = AcpiEvInstallGpeBlock (GpeBlock, InterruptNumber);
+    if (ACPI_FAILURE (Status))
+    {
+        ACPI_FREE (GpeBlock->RegisterInfo);
+        ACPI_FREE (GpeBlock->EventInfo);
+        ACPI_FREE (GpeBlock);
+        return_ACPI_STATUS (Status);
+    }
+
+    AcpiGbl_AllGpesInitialized = FALSE;
+
+    /* Find all GPE methods (_Lxx or_Exx) for this block */
+
+    WalkInfo.GpeBlock = GpeBlock;
+    WalkInfo.GpeDevice = GpeDevice;
+    WalkInfo.ExecuteByOwnerId = FALSE;
+
+    Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, GpeDevice,
+        ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
+        AcpiEvMatchGpeMethod, NULL, &WalkInfo, NULL);
+
+    /* Return the new block */
+
+    if (ReturnGpeBlock)
+    {
+        (*ReturnGpeBlock) = GpeBlock;
+    }
+
+    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
+        "    Initialized GPE %02X to %02X [%4.4s] %u regs on interrupt 0x%X%s\n",
+        (UINT32) GpeBlock->BlockBaseNumber,
+        (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1)),
+        GpeDevice->Name.Ascii, GpeBlock->RegisterCount, InterruptNumber,
+        InterruptNumber == AcpiGbl_FADT.SciInterrupt ? " (SCI)" : ""));
+
+    /* Update global count of currently available GPEs */
+
+    AcpiCurrentGpeCount += GpeBlock->GpeCount;
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvInitializeGpeBlock
+ *
+ * PARAMETERS:  ACPI_GPE_CALLBACK
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Initialize and enable a GPE block. Enable GPEs that have
+ *              associated methods.
+ *              Note: Assumes namespace is locked.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvInitializeGpeBlock (
+    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
+    ACPI_GPE_BLOCK_INFO     *GpeBlock,
+    void                    *Ignored)
+{
+    ACPI_STATUS             Status;
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
+    UINT32                  GpeEnabledCount;
+    UINT32                  GpeIndex;
+    UINT32                  i;
+    UINT32                  j;
+
+
+    ACPI_FUNCTION_TRACE (EvInitializeGpeBlock);
+
+
+    /*
+     * Ignore a null GPE block (e.g., if no GPE block 1 exists), and
+     * any GPE blocks that have been initialized already.
+     */
+    if (!GpeBlock || GpeBlock->Initialized)
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /*
+     * Enable all GPEs that have a corresponding method and have the
+     * ACPI_GPE_CAN_WAKE flag unset. Any other GPEs within this block
+     * must be enabled via the acpi_enable_gpe() interface.
+     */
+    GpeEnabledCount = 0;
+
+    for (i = 0; i < GpeBlock->RegisterCount; i++)
+    {
+        for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
+        {
+            /* Get the info block for this particular GPE */
+
+            GpeIndex = (i * ACPI_GPE_REGISTER_WIDTH) + j;
+            GpeEventInfo = &GpeBlock->EventInfo[GpeIndex];
+
+            /*
+             * Ignore GPEs that have no corresponding _Lxx/_Exx method
+             * and GPEs that are used to wake the system
+             */
+            if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == ACPI_GPE_DISPATCH_NONE) ||
+                (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == ACPI_GPE_DISPATCH_HANDLER) ||
+                (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) == ACPI_GPE_DISPATCH_RAW_HANDLER) ||
+                (GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
+            {
+                continue;
+            }
+
+            Status = AcpiEvAddGpeReference (GpeEventInfo);
+            if (ACPI_FAILURE (Status))
+            {
+                ACPI_EXCEPTION ((AE_INFO, Status,
+                    "Could not enable GPE 0x%02X",
+                    GpeIndex + GpeBlock->BlockBaseNumber));
+                continue;
+            }
+
+            GpeEnabledCount++;
+        }
+    }
+
+    if (GpeEnabledCount)
+    {
+        ACPI_INFO ((AE_INFO,
+            "Enabled %u GPEs in block %02X to %02X", GpeEnabledCount,
+            (UINT32) GpeBlock->BlockBaseNumber,
+            (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1))));
+    }
+
+    GpeBlock->Initialized = TRUE;
+    return_ACPI_STATUS (AE_OK);
+}
+
+#endif /* !ACPI_REDUCED_HARDWARE */

+ 466 - 0
kernel/src/acpica/events/evgpeinit.c

@@ -0,0 +1,466 @@
+/******************************************************************************
+ *
+ * Module Name: evgpeinit - System GPE initialization and update
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2015, 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 "acevents.h"
+#include "acnamesp.h"
+
+#define _COMPONENT          ACPI_EVENTS
+        ACPI_MODULE_NAME    ("evgpeinit")
+
+#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
+
+/*
+ * Note: History of _PRW support in ACPICA
+ *
+ * Originally (2000 - 2010), the GPE initialization code performed a walk of
+ * the entire namespace to execute the _PRW methods and detect all GPEs
+ * capable of waking the system.
+ *
+ * As of 10/2010, the _PRW method execution has been removed since it is
+ * actually unnecessary. The host OS must in fact execute all _PRW methods
+ * in order to identify the device/power-resource dependencies. We now put
+ * the onus on the host OS to identify the wake GPEs as part of this process
+ * and to inform ACPICA of these GPEs via the AcpiSetupGpeForWake interface. This
+ * not only reduces the complexity of the ACPICA initialization code, but in
+ * some cases (on systems with very large namespaces) it should reduce the
+ * kernel boot time as well.
+ */
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvGpeInitialize
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvGpeInitialize (
+    void)
+{
+    UINT32                  RegisterCount0 = 0;
+    UINT32                  RegisterCount1 = 0;
+    UINT32                  GpeNumberMax = 0;
+    ACPI_STATUS             Status;
+
+
+    ACPI_FUNCTION_TRACE (EvGpeInitialize);
+
+
+    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
+        "Initializing General Purpose Events (GPEs):\n"));
+
+    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
+    if (ACPI_FAILURE (Status))
+    {
+        return_ACPI_STATUS (Status);
+    }
+
+    /*
+     * Initialize the GPE Block(s) defined in the FADT
+     *
+     * Why the GPE register block lengths are divided by 2:  From the ACPI
+     * Spec, section "General-Purpose Event Registers", we have:
+     *
+     * "Each register block contains two registers of equal length
+     *  GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
+     *  GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
+     *  The length of the GPE1_STS and GPE1_EN registers is equal to
+     *  half the GPE1_LEN. If a generic register block is not supported
+     *  then its respective block pointer and block length values in the
+     *  FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
+     *  to be the same size."
+     */
+
+    /*
+     * Determine the maximum GPE number for this machine.
+     *
+     * Note: both GPE0 and GPE1 are optional, and either can exist without
+     * the other.
+     *
+     * If EITHER the register length OR the block address are zero, then that
+     * particular block is not supported.
+     */
+    if (AcpiGbl_FADT.Gpe0BlockLength &&
+        AcpiGbl_FADT.XGpe0Block.Address)
+    {
+        /* GPE block 0 exists (has both length and address > 0) */
+
+        RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
+        GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
+
+        /* Install GPE Block 0 */
+
+        Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
+            AcpiGbl_FADT.XGpe0Block.Address,
+            AcpiGbl_FADT.XGpe0Block.SpaceId,
+            RegisterCount0, 0,
+            AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
+
+        if (ACPI_FAILURE (Status))
+        {
+            ACPI_EXCEPTION ((AE_INFO, Status,
+                "Could not create GPE Block 0"));
+        }
+    }
+
+    if (AcpiGbl_FADT.Gpe1BlockLength &&
+        AcpiGbl_FADT.XGpe1Block.Address)
+    {
+        /* GPE block 1 exists (has both length and address > 0) */
+
+        RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
+
+        /* Check for GPE0/GPE1 overlap (if both banks exist) */
+
+        if ((RegisterCount0) &&
+            (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
+        {
+            ACPI_ERROR ((AE_INFO,
+                "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
+                "(GPE %u to %u) - Ignoring GPE1",
+                GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
+                AcpiGbl_FADT.Gpe1Base +
+                ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
+
+            /* Ignore GPE1 block by setting the register count to zero */
+
+            RegisterCount1 = 0;
+        }
+        else
+        {
+            /* Install GPE Block 1 */
+
+            Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
+                AcpiGbl_FADT.XGpe1Block.Address,
+                AcpiGbl_FADT.XGpe1Block.SpaceId,
+                RegisterCount1,
+                AcpiGbl_FADT.Gpe1Base,
+                AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
+
+            if (ACPI_FAILURE (Status))
+            {
+                ACPI_EXCEPTION ((AE_INFO, Status,
+                    "Could not create GPE Block 1"));
+            }
+
+            /*
+             * GPE0 and GPE1 do not have to be contiguous in the GPE number
+             * space. However, GPE0 always starts at GPE number zero.
+             */
+            GpeNumberMax = AcpiGbl_FADT.Gpe1Base +
+                ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
+        }
+    }
+
+    /* Exit if there are no GPE registers */
+
+    if ((RegisterCount0 + RegisterCount1) == 0)
+    {
+        /* GPEs are not required by ACPI, this is OK */
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
+            "There are no GPE blocks defined in the FADT\n"));
+        Status = AE_OK;
+        goto Cleanup;
+    }
+
+
+Cleanup:
+    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
+    return_ACPI_STATUS (AE_OK);
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvUpdateGpes
+ *
+ * PARAMETERS:  TableOwnerId        - ID of the newly-loaded ACPI table
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
+ *              result of a Load() or LoadTable() operation. If new GPE
+ *              methods have been installed, register the new methods.
+ *
+ ******************************************************************************/
+
+void
+AcpiEvUpdateGpes (
+    ACPI_OWNER_ID           TableOwnerId)
+{
+    ACPI_GPE_XRUPT_INFO     *GpeXruptInfo;
+    ACPI_GPE_BLOCK_INFO     *GpeBlock;
+    ACPI_GPE_WALK_INFO      WalkInfo;
+    ACPI_STATUS             Status = AE_OK;
+
+
+    /*
+     * Find any _Lxx/_Exx GPE methods that have just been loaded.
+     *
+     * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
+     * enabled.
+     *
+     * Examine the namespace underneath each GpeDevice within the
+     * GpeBlock lists.
+     */
+    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
+    if (ACPI_FAILURE (Status))
+    {
+        return;
+    }
+
+    WalkInfo.Count = 0;
+    WalkInfo.OwnerId = TableOwnerId;
+    WalkInfo.ExecuteByOwnerId = TRUE;
+
+    /* Walk the interrupt level descriptor list */
+
+    GpeXruptInfo = AcpiGbl_GpeXruptListHead;
+    while (GpeXruptInfo)
+    {
+        /* Walk all Gpe Blocks attached to this interrupt level */
+
+        GpeBlock = GpeXruptInfo->GpeBlockListHead;
+        while (GpeBlock)
+        {
+            WalkInfo.GpeBlock = GpeBlock;
+            WalkInfo.GpeDevice = GpeBlock->Node;
+
+            Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD,
+                WalkInfo.GpeDevice, ACPI_UINT32_MAX,
+                ACPI_NS_WALK_NO_UNLOCK, AcpiEvMatchGpeMethod,
+                NULL, &WalkInfo, NULL);
+            if (ACPI_FAILURE (Status))
+            {
+                ACPI_EXCEPTION ((AE_INFO, Status,
+                    "While decoding _Lxx/_Exx methods"));
+            }
+
+            GpeBlock = GpeBlock->Next;
+        }
+
+        GpeXruptInfo = GpeXruptInfo->Next;
+    }
+
+    if (WalkInfo.Count)
+    {
+        ACPI_INFO ((AE_INFO, "Enabled %u new GPEs", WalkInfo.Count));
+    }
+
+    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
+    return;
+}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION:    AcpiEvMatchGpeMethod
+ *
+ * PARAMETERS:  Callback from WalkNamespace
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
+ *              control method under the _GPE portion of the namespace.
+ *              Extract the name and GPE type from the object, saving this
+ *              information for quick lookup during GPE dispatch. Allows a
+ *              per-OwnerId evaluation if ExecuteByOwnerId is TRUE in the
+ *              WalkInfo parameter block.
+ *
+ *              The name of each GPE control method is of the form:
+ *              "_Lxx" or "_Exx", where:
+ *                  L      - means that the GPE is level triggered
+ *                  E      - means that the GPE is edge triggered
+ *                  xx     - is the GPE number [in HEX]
+ *
+ * If WalkInfo->ExecuteByOwnerId is TRUE, we only execute examine GPE methods
+ * with that owner.
+ *
+ ******************************************************************************/
+
+ACPI_STATUS
+AcpiEvMatchGpeMethod (
+    ACPI_HANDLE             ObjHandle,
+    UINT32                  Level,
+    void                    *Context,
+    void                    **ReturnValue)
+{
+    ACPI_NAMESPACE_NODE     *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
+    ACPI_GPE_WALK_INFO      *WalkInfo = ACPI_CAST_PTR (ACPI_GPE_WALK_INFO, Context);
+    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
+    UINT32                  GpeNumber;
+    char                    Name[ACPI_NAME_SIZE + 1];
+    UINT8                   Type;
+
+
+    ACPI_FUNCTION_TRACE (EvMatchGpeMethod);
+
+
+    /* Check if requested OwnerId matches this OwnerId */
+
+    if ((WalkInfo->ExecuteByOwnerId) &&
+        (MethodNode->OwnerId != WalkInfo->OwnerId))
+    {
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /*
+     * Match and decode the _Lxx and _Exx GPE method names
+     *
+     * 1) Extract the method name and null terminate it
+     */
+    ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer);
+    Name[ACPI_NAME_SIZE] = 0;
+
+    /* 2) Name must begin with an underscore */
+
+    if (Name[0] != '_')
+    {
+        return_ACPI_STATUS (AE_OK); /* Ignore this method */
+    }
+
+    /*
+     * 3) Edge/Level determination is based on the 2nd character
+     *    of the method name
+     */
+    switch (Name[1])
+    {
+    case 'L':
+
+        Type = ACPI_GPE_LEVEL_TRIGGERED;
+        break;
+
+    case 'E':
+
+        Type = ACPI_GPE_EDGE_TRIGGERED;
+        break;
+
+    default:
+
+        /* Unknown method type, just ignore it */
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
+            "Ignoring unknown GPE method type: %s "
+            "(name not of form _Lxx or _Exx)", Name));
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* 4) The last two characters of the name are the hex GPE Number */
+
+    GpeNumber = strtoul (&Name[2], NULL, 16);
+    if (GpeNumber == ACPI_UINT32_MAX)
+    {
+        /* Conversion failed; invalid method, just ignore it */
+
+        ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
+            "Could not extract GPE number from name: %s "
+            "(name is not of form _Lxx or _Exx)", Name));
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Ensure that we have a valid GPE number for this GPE block */
+
+    GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, WalkInfo->GpeBlock);
+    if (!GpeEventInfo)
+    {
+        /*
+         * This GpeNumber is not valid for this GPE block, just ignore it.
+         * However, it may be valid for a different GPE block, since GPE0
+         * and GPE1 methods both appear under \_GPE.
+         */
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
+            ACPI_GPE_DISPATCH_HANDLER) ||
+        (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
+            ACPI_GPE_DISPATCH_RAW_HANDLER))
+    {
+        /* If there is already a handler, ignore this GPE method */
+
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
+        ACPI_GPE_DISPATCH_METHOD)
+    {
+        /*
+         * If there is already a method, ignore this method. But check
+         * for a type mismatch (if both the _Lxx AND _Exx exist)
+         */
+        if (Type != (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
+        {
+            ACPI_ERROR ((AE_INFO,
+                "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
+                GpeNumber, GpeNumber, GpeNumber));
+        }
+        return_ACPI_STATUS (AE_OK);
+    }
+
+    /* Disable the GPE in case it's been enabled already. */
+
+    (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
+
+    /*
+     * Add the GPE information from above to the GpeEventInfo block for
+     * use during dispatch of this GPE.
+     */
+    GpeEventInfo->Flags &= ~(ACPI_GPE_DISPATCH_MASK);
+    GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_METHOD);
+    GpeEventInfo->Dispatch.MethodNode = MethodNode;
+
+    ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
+        "Registered GPE method %s as GPE number 0x%.2X\n",
+        Name, GpeNumber));
+    return_ACPI_STATUS (AE_OK);
+}
+
+#endif /* !ACPI_REDUCED_HARDWARE */

Some files were not shown because too many files changed in this diff