acpiexamples: Enable notify/region examples.

The patch is generated in the purposes of:
1. AcpiOsPrintf()/AcpiOsVprintf() need to be linked by applications;
2. utglobal.o linkage is prefered than defining DEFINE_ACPI_GLOBALS for
   applications, then applications that have already linked to utinit.o
   need to be updated, especially, their stubs need to be updated.

The acpiexamples loads tables and invokes control methods, waiting for
notifications, possibly in the future we can add region demonstrations.
Thus it makes senses to link acpiexamples to all of the following
components:
  tables
  namespace
  dispatcher
  executer
  parser
  events (notify/region part)

This patch updates acpiexamples in the way of:
1. Linking all namespace/utilities objects and deleting stubs of
   AcpiUt/AcpiNs functions from exstubs.c;
2. Linking all region/notify objects and deleting relevent stubs of AcpiEv
   functions from exstubs.c;
3. Adding region/notify examples in the DSDT.
4. Converting AcpiOsExecute() into a direct callback invocation.
5. Linking hwpci.c, the file has nothing to do with hardware, it is more
   suitable to be utpci.c;
6. Since no hardware samples are demonstrated in acpiexamples, defining
   ACPI_REDUCED_HARDWARE to 1 and deleting relevent stubs of AcpiHw
   functions from exstubs.c.

This patch thus updates exstubs.c with such minimal efforts. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
acpinames: Cleanup stubs by linking some utilities objects.

This patch tries to reduce stubs for acpinames by adding some utilities
objects to link.

By doing so, we have to create stubs for AcpiEvTerminate(). While
definining ACPI_REDUCED_HARDWARED can eliminate such requirements
permanently. Then we are able to delete some AcpiHwXXX() AcpiEvXXX() stubs
from anstubs.c

It also makes senses to link exsystem.o and exmutex.o because they've
already been made no-op by underlying OSL. By doing so, we can reduce some
AcpiExXXX() stubs.

Linking utids.o and uteval.o can help to reduce lots of stubs. It's safe to
do so as such functions are not invoked by acpinames.

This is the minimal effort to removing stubs from acpinames. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Utilities: Cleanup DEFINE_ACPI_GLOBALS by moving AcpiUtInitGlobal() from utglobal.c to utinit.c.

The utglobal.c is used to define and initialize global variables.  It makes
sense if just adding utglobal.o to applications that are using such
variables. But AcpiUtInitGlobals() is preventing us from doing so as this
initialization function references other components' initializations code,
which leads to the requirement that many files should also get linked if
one wants to link utglobal.o.

By eliminating the stubs for acpiexamples, acpinames, iasl, now it is
possible to just move AcpiUtInitGlobal() to utinit.c for applications that
require this function to link.

By linking utglobal.o, we can stop defining DEFINE_ACPI_GLOBALS for
applications (currently only acpidump is affected). Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
OSL: Cleanup AcpiOsPrintf()/AcpiOsVprintf() stubs.

This patch is mainly for acpidump where there are redundant
AcpiOsPrintf()/AcpiOsVprintf() stubs implemented. This patch cleans up such
specific implementation by linking acpidump to osunixxf.c/oswinxf.c.

To make AcpiOsPrintf() exported by osunixxf.c/oswinxf.c to behave as the
old acpidump specific ones, applications need to:
1. Initialize AcpiGbl_DbOutputFlags to ACPI_DB_CONSOLE_OUTPUT.
   This is automatically done by ACPI_INIT_GLOBAL(), applications need to
   link utglobal.o to utilize this mechanism.
2. Initialize AcpiGbl_OutputFile to stdout.
   For GCC, assigning stdout to AcpiGbl_OutputFile using ACPI_INIT_GLOBAL()
   is not possible as stdout is not a constant in GCC environment. As an
   alternative solution, stdout assignment is put into AcpiOsInitialize().
   Thus AcpiOsInitialize() need to be invoked very early by the
   applications to initialize the default output of AcpiOsPrintf().

Note that acpidump has been released to Linux kernel, after adding
osunixxf.c to generate/unix/acpidump/Makefile, libacpica.sh also need to be
updated to release osunixxf.c to Linux kernel. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
OSL: Add portable file IO to improve portability.

This patch adds portable file IO to generic OSL to improve the portability
of the applications.

A portable application may use different file IO interaces than the
standard C library ones. This patch thus introduces an abstract file IO
layer into the generic OSL.

Note that this patch does not introduce users of such interfaces, further
patches should introduce users one by one carefully with build tests
performed. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Utilities: Add formatted printing APIs.

This patch introduces formatted printing APIs to handle ACPICA specific
formatted print requirements.

The specific formatted printing APIs are useful to ACPICA as:
1. Some portable applications do not link standard C library, so they
   cannot use standard formatted print APIs directly.
2. Platform specific printing format may differ and thus not portable, for
   example, UINT64 is %ull for Linux kernel and is %uI64 for some MSVC
   versions.
3. Platform specific printing format may conflict with ACPICA's usages
   while it is not possible for ACPICA developers to test their code for
   all platforms. For example, developers may generate %pRxxx while Linux
   kernel treats %pR as structured resource printing and decodes variable
   argument as a "struct resource" pointer.
This patch solves above issues by introducing the new APIs.

Note that users of such APIs are not introduced in this patch. Users of
AcpiOsFileVprintf()/AcpiUtFilePrintf() need to invoke AcpiOsInitialize(),
this should be taken care by the further patches where such users are
introduced. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Utilities: Introduce AcpiLogError() to improve portability.

Invocations like fprintf(stderr) and perror() are not portable, this patch
introduces AcpiLogError() as a replacement, it is implemented using new
portable API - AcpiUtFileVprintf().

Some applications are already referencing utdebug.c, they now need to build
utlibcfs.c/utprint.c as well.

Note that though AcpiOsInitialize() need to be invoked prior than using
this new API, since no users are introduced in this patch, such invocations
are not added for applications that link utprint.c in this patch. Futher
patches that introduce users of AcpiLogError() should take care of this.
Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Application: Enhance ACPI_USAGE_xxx/ACPI_OPTION with AcpiOsPrintf() to improve portability.

This patch enhances ACPI_USAGE_xxx/ACPI_OPTION macros to use portable
AcpiOsPrintf() so that usage functions for applications no longer rely on
the printf() API.

To use AcpiOsPrintf() exported by osunixxf.c/oswinxf.c as a replacement of
printf, applications need to initialize AcpiGbl_OutputFile to stdout and
initialize AcpiGbl_DbOutputFlags to ACPI_DB_CONSOLE_OUTPUT. The latter is
automatically done by ACPI_INIT_GLOBAL(), applications need to link
utglobal.o to utilize this mechanism. For GCC, assigning stdout to
AcpiGbl_OutputFile using ACPI_INIT_GLOBAL() is not possible as stdout is
not a constant in GCC environment. As an alternative solution, stdout
assignment has been put into AcpiOsInitialize(). Thus AcpiOsInitialize()
need to be invoked very early by the applications to initialize the default
output of AcpiOsPrintf() to keep behavior consistency.

The details of AcpiOsInitialize() are as follows:
1. acpidump have already invoked AcpiOsInitialize(), thus no need to add.
2. acpiexamples/acpiexec/acpinames have already invoked
   AcpiInitializeSubsystem() very early, thus no need to add
   AcpiOsInitialize() for them.
3. iasl have already invoked AcpiOsInitialize(), but the invocation is not
   early enough to make its usage functioning proper. This patch adds an
   early AcpiOsInitialize() invocation for it.

Unix makefiles are also updated to include osunixxf.o/utglobal.o in this
patch.  The acpihelp/acpisrc/acpixtract applications are the only ones that
do not have the 2 object files linked. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Common: Enhance CmGetFileSize() to improve portability.

This patch uses abstract file IO and AcpiLogError() APIs to enhance
CmGetFileSize() so that applications that invoke this API could have
portability improved.

With actual references added to abstract file IO and AcpiLogError(), the
applications need to link utlibcfs.o, utdebug.o, utexcep.o, utmath.o,
utprint.o and utxferror.o.
Though it is required to add AcpiOsInitialize() invocations if an
application starts to use AcpiLogError(), this doesn't appear in this
patch. A previous patch in the same series should have already added
AcpiOsInitialize() invocations for all applications. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Common: Enhance AcpiGetopt() to improve portability.

This patch enhances AcpiGetopt() by converting the standard C library
invocations into portable ACPI string APIs and AcpiLogError() to improve
portability.

With actual references added to AcpiLogError(), the applications need to
link utlibcfs.o, utdebug.o, utexcep.o, utmath.o, utprint.o and utxferror.o.
Though it is required to add AcpiOsInitialize() invocations if an
application starts to use AcpiLogError(), this doesn't appear in this
patch. A previous patch in the same series should have already added
AcpiOsInitialize() invocations for all applications. Lv Zheng.

With actual references added, some utilities need to add utlibcfs.o,
utdebug.o, utexcep.o, utmath.o, utprint.o and utxferror.o in order to
link. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
acpidump: Add memory/string OSL usage to improve portability.

This patch adds code to use generic OSL for acpidump to improve the
portability of this tool. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
acpidump: Remove exit() from generic layer to improve portability.

This patch removes exit() from generic acpidump code to improve the
portability of this tool. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
acpidump: Replace file IOs with new APIs to improve portability.

The new APIs are enabled to offer a portable layer to access files:
1. AcpiOsXXXFileXXX: Wrapper of fopen/fclose/fread/fwrite
2. AcpiOsPrintf: Wrapper of printf
3. AcpiLogError: Wrapper of fprintf(stderr)

This patch deploys such mechanisms to acpidump to improve the portability
of this tool. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
acpidump: Reduce freopen() invocations to improve portability.

This patch reduces the requirement of invoking freopen() in acpidump in order
to reduce the porting effort of acpidump.

This patch achieves this by turning all AcpiOsPrintf(stdout) into
AcpiUtFilePrintf(Gbl_OutputFile). Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
EFI: Add build environment support for GNU EFI development.

This patch adds build environment for GNU EFI shell development.

Note that only the Makefiles used by EFI development are created in this
patch, actual OSL is not implemented and ACPICA applications are enabled in
this patch. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
EFI: Add generic OSL support for GNU EFI development.

This patch adds generic OSL for GNU EFI shell development.

The following files are enhanced with GNU EFI builds:
1. os_specific/service_layers/osefixf.c
2. include/platform/acefi.h

Note that this patch only uses GNU EFI definitions and the following 2
implementations:
1. Linking GNU EFI entry point and we implements efi_main();
2. Linking DivU64x32 to perform division.
This is because:
1. We do not want to maintain architecture specific code in ACPICA, the
   entry point and division implementation are architecture specific;
2. We do not want to define all EFI structures/macros again to inflate our
   initial implementation. Since for non-architecture specific code, we
   should try our best to implement our own to be more portable, we may
   redefine these stuff in the future as they are not architecture
   specific.

Note that linking DivU64x32() to implement ACPI_DIV_64_BY_32() can produce
correct division result for AcpiUtDivide(), but it is not performance
friendly as the two APIs have different meanings. This definitely will slow
down the applications. There is no architecture specific API in GNU EFI
that has implemented the same meaning as ACPI_DIV_64_BY_32(), so we have no
choice. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
EFI: Add EFI support for acpidump.

This patch enables acpidump for EFI. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
UEFI: Add file IO support.

This patch enables UEFI OSL with file IO, thus it also enables "-o" and
"-b" for the EFI port of acpidump. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
EFI: Add memory map lookup support for AcpiOsMapMemory().

In EFI environment, there might be physical memory mapped and reported in
the memory map table. This patch uses the virtual addresses reported to
extend the accessibility of AcpiOsMapMemory(). Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Merge pull request #32 from zetalog/acpica-efi

Patches required to support better application portability and EFI environment support for acpidump.