Linux: Add stub implementation of ACPICA 64-bit mathematics.

This patch adds default 64-bit mathematics in aclinux.h using do_div(). As
do_div() can be used for all Linux architectures, this can also be used as
stub macros for ACPICA 64-bit mathematics.

But this is not a performance friendly way, as ACPICA's architecture
specific division OSL only requires a dividing 64-bit number with a 32-bit
number implementation, while Linux __div64_32() is not available for all
build environments. So currently, if an architecture really wants to
support ACPICA, it must implement its own division OSL.

This is required by the ACPICA header stub support. ACPICA header stubs are
useful to protect CONFIG_ACPI=n Linux kernel builds where ACPICA headers
are included. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Linux: Add support to exclude <asm/acenv.h> inclusion.

The forthcoming patch will make <acpi/acpi.h> to be visible to all kernel
source code. Thus for the architectures that do not support ACPI and
haven't implemented <asm/acenv.h>, we need to make it excluded. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Linux: Add support to force header inclusion rules for <acpi/acpi.h>.

As there is only CONFIG_ACPI=n processing in the <linux/acpi.h>, it is not
safe to include <acpi/acpi.h> directly for source out of Linux ACPI
subsystems.

This patch adds error messaging to warn developers of such wrong
inclusions. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Executer: Fix a link error for 64-bit division in the Debug object timestamp generation.

ACPICA should not use 64-bit division directly. This triggers the following
build error on Linux i386 kernel builds:
  drivers/built-in.o: In function `acpi_ex_do_debug_object':
  (.text+0x4e1a4): undefined reference to `__udivdi3'

This is introduced by the following commit:
  Commit: a4060d7fcfffff15a3e1d3aee7ccfd5cf00b50a0
  Subject: Debug object: Add current value of Timer() to debug line prefix.

Since the following 2 statements are equivalent as 0x03FFFFFF masking
keeps lower bits of num/12, and num/10 should have contained all valid bits
for 0x03FFFFFF masking no matter whether num is 32-bit or 64-bit:
 (UINT32) (num64 / 10) & 0x03FFFFFF;
 ((UINT32) num64 / 10) & 0x03FFFFFF;
This patch fixes this using the latter form statement to avoid 64-bit
division. Lv Zheng.

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

Acpica 1407
Linuxize: Add upstream commit ID in the generated patches.

This patch adds support to add ACPICA upstream Commit ID/Author in the
generated linuxized patches. This format follows Linux stable material
format. The modifications include:
1. distiguish COMMITTER, AUTHOR, MAINTAINER:
   1. COMMITTER is automatically extracted using "git config --get";
   2. AUTHOR is automatically extracted using "git log --format=%aN <%aE>";
   3. MAINTAINER is fixed in make-patches.sh, currently it is
      "Bob Moore <robert.moore@intel.com>".
2. add AUTHOR and COMMIT ID information to form the ACPICA release patch
   header.
3. automatically correct "Robert Moore <Robert.Moore@intel.com>" to
   "Bob Moore <bob.moore@intel.com>".
4. automatically remove last empty lines in the patch description.
5. automatically append unique Signed-off-by for AUTHOR, NAINTAINER and
   COMMITTER.
6. automatically add commit URL before SOBs and add "-l" option to be ready
   for changing the host of the repo.
The generated patch format is ACKed by the Linux ACPI maintainer. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Events: Fix an issue that OriginallyEnabled check is not paired.

The OriginallyEnabled check is not paired between AcpiInstallGpeHandler()
and AcpiRemoveGpeHandler(). This patch contains the code that is already in
the Linux upstream. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Events: Fix an issue that GPE APIs cannot be invoked in atomic context.

The GPE APIs should be invoked inside of an IRQ context GPE handler or in
the task context with a driver provided lock held. This driver provided
lock should be safe to be held in the GPE handler by the driver.

While currently we cannot do this, thus we can only use the GPE APIs for
limitted cases.

This patch adds reference counting for ACPI_GPE_HANDLER_INFO. Then the GPE
handler can be safely invoked without holding the GPE lock, thus
facilitates GPE APIs to be invoked in any atomic environment. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Events: Fix an issue that GPE APIs cannot be invoked in deferred handlers.

The AcpiOsWaitEventsComplete() is used for flushing the deferred executed
handlers, invoking it for GPE interrupt handlers doesn't help to protect
GPE handler callback.  On the contrary, it prevents GPE APIs from being
invoked in the deferred notify handlers.

Actually, the GPE interrupt handlers' invocation is protected by the
previous implemented reference counting mechanism.

This patch fixes this GPE APIs invocation issue in a seperate commit other
than the reference counting one, so that if any regressions are reported,
this patch can be temporarily reverted before the regressions are root
caused. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Events: Fix an issue that AcpiSetGpe() cannot unconditionally enable GPEs.

For AcpiSetGpe()/AcpiEnableGpe(), our target is to purify them to be APIs
can be used for request based driver handling code, so we need them to be
pure GPE enabling APIs. IRQ enabling/disabling has 2 use cases:
1. Driver may permanently enable/disable IRQs according to the usage
   counts.
   1. When upper layers (the users of the driver) submit requests to the
      driver, it means they care about the underlying hardware. IRQ need
      to be enabled for the first request submission and disabled for the
      last request completion.
   2. When the IRQ is shared between 2+ silicon logics. IRQ need to be
      enabled for either silicon logic's driver and disabled when all of
      the drivers are not started.
   For these cases, AcpiEnableGpe()/AcpiDisableGpe() should be used. When
   the usage count is increased from 0 to 1, the IRQ is enabled and it is
   disabled when the usage count is decrased from 1 to 0.
2. Driver may temporarily disables the IRQ to enter an IRQ polling mode and
   wants to re-enable it later.
   1. Prevent IRQ storming: when a driver cannot fully solve the condition
      that triggered the IRQ in the IRQ context, in order not to trigger
      IRQ storm, driver has to disable IRQ to switch into the polling mode
      and re-enables it in the non-IRQ context after the storming condition
      is cleared.
   2. Meet throughput requirement: some IO drivers need to poll hardware
      again and again until nothing indicated instead of just handling once
      for one interruption, this need to be done in the polling mode or the
      IO flood may prevent the IRQ handler from returning.
   3. Meet realtime requirement: in order not to block CPU to handle higher
      realtime prioritized IRQs, lower priority IRQs can be handled in the
      polling mode.
   For these cases, AcpiSetGpe() should be used to switch to/from the
   polling mode.

This patch adds unconditional GPE enabling support into AcpiSetGpe() so
that this API can be used by the drivers to switch back from the GPE
polling mode unconditionally.

Originally this function includes GPE clearing logic in it.
First, the GPE clearing is typically used in the GPE handling code to:
1. Acknowledge the GPE when we know there is an edge triggered GPE raised
   and is about to handle it, otherwise the unexpected clearing may lead to
   a GPE loss;
2. Issue actions after we have handled a level triggered GPE, otherwise
   the unexpected clearing may trigger unwanted OSPM actions to the
   hardware (for example, clocking in out-dated write FIFO data).
Thus the GPE clearing is not suitable to be used in the GPE enabling APIs.
Second, the combination of acknowledging and enabling may also not be
expected by the hardware drivers. For GPE clearing, we have a seperate API
AcpiClearGpe(). There are cases drivers do want the 2 operations to be
split. So splitting these 2 operations could facilitates drivers the
maximum possibilities to achieve success. For a combined one, we already
have AcpiFinishGpe() ready to be invoked.

Given the fact that drivers should complete all outstanding requests before
putting themselves into the sleep states, as this API is executed for
outstanding requests, it should also have nothing to do with the
"RUN"/"WAKE" distinguishing. That's why the AcpiSetGpe(ACPI_GPE_ENABLE)
should not be implemented by AcpiHwLowSetGpe(ACPI_GPE_CONDITIONAL_ENABLE).

This patch thus converts AcpiSetGpe(ACPI_GPE_ENABLE) into
AcpiHwLowSetGpe(ACPI_GPE_ENABLE) to achieve a seperate GPE enabling API.
Drivers then are encouraged to use this API when they need to switch
to/from the IRQ polling mode. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Events: Remove duplicated sanity check in AcpiEvEnableGpe().

This patch deletes a sanity check from AcpiEvEnableGpe().

This kind of check is already done in
AcpiEnableGpe()/AcpiRemoveGpeHandler()/AcpiUpdateAllGpes() before invoking
AcpiEvEnableGpe():
1. AcpiEnableGpe(): same check (skip if DISPATCH_NONE) is now implemented.
2. AcpiRemoveGpeHandler(): a more strict check (skip if !DISPATCH_HANDLER)
                           is implemented.
3. AcpiUpdateAllGpes(): a more strict check (skip if DISPATCH_NONE ||
                        DISPATCH_HANDLER || CAN_WAKE)
4. AcpiSetGpe(): since it is invoked by the OSPM driver where the IRQ
                 handler is known to be available, such check isn't needed.
So we can simply remove this duplicated check from AcpiEvEnableGpe().
Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Events: Add a flag to disable internal auto GPE disabling.

The ACPI specification around the GPE handling is talking about an IRQ
handling code of IRQ polling mode (which is also known as the threaded IRQ
model in Linux) that is suitable for the control method execution. GPE is
disabled in the IRQ context and re-enabled in the IRQ polling context (the
task context of the polling thread) after the interrupt has been correctly
handled.

For IRQ handling code of IRQ interrupt mode (DISPATCH_HANDLER can only be
implemented in this mode), disabling IRQ is useless as further IRQs with
same IRQ no. are ensured to be blocked IRQ for the same CPU. There is no
hardware in the real world can trigger an IRQ on the same CPU to preempt
the handler of the same IRQ. There might be same IRQ handlers triggered on
different CPUs but disabling it in the IRQ handler cannot prevent this from
happening.

And the automatic IRQ disabling is harmful to request based low power IO
drivers where IRQ enabling/disabling is managed by the power references and
the storm conditions.
The IRQ disabling/enabling out of the drivers' control can mess up the IRQ
enabling state where:
1. Enabling IRQ means there is more than 1 requests and no storms;
2. Disabling IRQ means there is no request or there is a storm.

This patch adds a flag to control the ACPICA internal GPE disabling to
facilitate request based low power IO drivers to work in the GPE level.

Since we will have users for the new GPE flag to enable a runtime idle
style GPE driver, this patch also enables AcpiInstallGpeHandler() to
configure NO_AUTO_x flags. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Events: Add a flag to disable internal auto GPE clearing.

The GPE status clearing code should be invoked in the GPE handling code.
There are cases that the GPE is handled in the polling mode and the IRQ
mode handler is a no-op. For which, ACPICA internal clearing should be
bypassed.
Some silicon chips can implement special GPE status as R1C (read once
clear). For those case, the internal auto GPE clearing operations should
also be abandoned.

This flag facilitates such driver designs and implementations.

Note that drivers will need to invoke AcpiClearGpe() manually in a proper
position. Lv Zheng.

Signed-off-by: Lv Zheng <lv.zheng@intel.com>