Re: [PATCH v3] ACPI: D3 states cleanup

From: huang ying
Date: Fri Apr 27 2012 - 03:48:46 EST


Hi, Ming,

On Mon, Apr 23, 2012 at 9:03 AM, Lin Ming <ming.m.lin@xxxxxxxxx> wrote:
> There are two ACPI D3 states defined now:
> ACPI_STATE_D3 and ACPI_STATE_D3_COLD.
>
> But the uses of these states are not clear/correct in some code.
> For example, some code refer ACPI_STATE_D3 as D3hot and others refer
> it as D3cold.
>
> This patch introduces ACPI_STATE_D3_HOT to refer to ACPI D3hot state.
> D3hot is only valid if _PR3 present.
> And changes ACPI_STATE_D3 to refer to ACPI D3cold state only.
> Also redefines ACPI_STATE_D3_COLD the same as ACPI_STATE_D3.

The changelog should say why we make the change instead of how we make
the change. The code itself can tell me how we have done well. I
prefer to see the description about

- the history of ACPI_STATE_D3, ACPI_STATE_D3_HOT, ACPI_STATE_D3_COLD
- if no _PR3, _PS3 may put device into D3_HOT or D3_COLD, decided by
platform. But we will assume _PS3 will put device into D3_COLD,
because it is safe to treat device in D3_HOT as D3_COLD, but not in
contrary way.

And I think it will be more clear if we list the power state
supporting under various combination, for example,

- has _PS3, no _PR3
- Valid states: D3_COLD
- Set power state
- D3_COLD: exec _PS3

> Acked-by: Rafael J. Wysocki <rjw@xxxxxxx>
> Signed-off-by: Lin Ming <ming.m.lin@xxxxxxxxx>
> ---
>
> v3: D3hot is only valid if _PR3 present
>
> Âdrivers/acpi/power.c  |  Â2 +-
> Âdrivers/acpi/scan.c  Â|  17 +++++++----------
> Âdrivers/pci/pci-acpi.c | Â Â4 ++--
> Âinclude/acpi/actypes.h | Â Â7 ++++---
> Â4 files changed, 14 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
> index 7049a7d..330bb4d 100644
> --- a/drivers/acpi/power.c
> +++ b/drivers/acpi/power.c
> @@ -631,7 +631,7 @@ int acpi_power_get_inferred_state(struct acpi_device *device, int *state)
> Â Â Â Â * We know a device's inferred power state when all the resources
> Â Â Â Â * required for a given D-state are 'on'.
> Â Â Â Â */
> - Â Â Â for (i = ACPI_STATE_D0; i < ACPI_STATE_D3; i++) {
> + Â Â Â for (i = ACPI_STATE_D0; i < ACPI_STATE_D3_HOT; i++) {
> Â Â Â Â Â Â Â Âlist = &device->power.states[i].resources;
> Â Â Â Â Â Â Â Âif (list->count < 1)
> Â Â Â Â Â Â Â Â Â Â Â Âcontinue;
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 767e2dc..7417267 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -869,7 +869,7 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
> Â Â Â Â/*
> Â Â Â Â * Enumerate supported power management states
> Â Â Â Â */
> - Â Â Â for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
> + Â Â Â for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
> Â Â Â Â Â Â Â Âstruct acpi_device_power_state *ps = &device->power.states[i];
> Â Â Â Â Â Â Â Âchar object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
>
> @@ -884,21 +884,18 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âacpi_bus_add_power_resource(ps->resources.handles[j]);
> Â Â Â Â Â Â Â Â}
>
> - Â Â Â Â Â Â Â /* The exist of _PR3 indicates D3Cold support */
> - Â Â Â Â Â Â Â if (i == ACPI_STATE_D3) {
> - Â Â Â Â Â Â Â Â Â Â Â status = acpi_get_handle(device->handle, object_name, &handle);
> - Â Â Â Â Â Â Â Â Â Â Â if (ACPI_SUCCESS(status))
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
> - Â Â Â Â Â Â Â }
> -
> Â Â Â Â Â Â Â Â/* Evaluate "_PSx" to see if we can do explicit sets */
> Â Â Â Â Â Â Â Âobject_name[2] = 'S';
> Â Â Â Â Â Â Â Âstatus = acpi_get_handle(device->handle, object_name, &handle);
> Â Â Â Â Â Â Â Âif (ACPI_SUCCESS(status))
> Â Â Â Â Â Â Â Â Â Â Â Âps->flags.explicit_set = 1;
>
> - Â Â Â Â Â Â Â /* State is valid if we have some power control */
> - Â Â Â Â Â Â Â if (ps->resources.count || ps->flags.explicit_set)
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* State is valid if there are means to put the device into it.
> + Â Â Â Â Â Â Â Â* D3hot is only valid if _PR3 present.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â if (ps->resources.count ||
> + Â Â Â Â Â Â Â Â Â (ps->flags.explicit_set && i < ACPI_STATE_D3_HOT))
> Â Â Â Â Â Â Â Â Â Â Â Âps->flags.valid = 1;

I think we should add some comments here about why we do that. Why
D3_HOT is not valid if only _PS3 presents.

> Â Â Â Â Â Â Â Âps->power = -1; /* Unknown - driver assigned */
> diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
> index 0f150f2..1929c0c 100644
> --- a/drivers/pci/pci-acpi.c
> +++ b/drivers/pci/pci-acpi.c
> @@ -200,7 +200,7 @@ static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
> Â Â Â Â Â Â Â Âreturn PCI_D1;
> Â Â Â Âcase ACPI_STATE_D2:
> Â Â Â Â Â Â Â Âreturn PCI_D2;
> - Â Â Â case ACPI_STATE_D3:
> + Â Â Â case ACPI_STATE_D3_HOT:
> Â Â Â Â Â Â Â Âreturn PCI_D3hot;
> Â Â Â Âcase ACPI_STATE_D3_COLD:
> Â Â Â Â Â Â Â Âreturn PCI_D3cold;
> @@ -223,7 +223,7 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
> Â Â Â Â Â Â Â Â[PCI_D0] = ACPI_STATE_D0,
> Â Â Â Â Â Â Â Â[PCI_D1] = ACPI_STATE_D1,
> Â Â Â Â Â Â Â Â[PCI_D2] = ACPI_STATE_D2,
> - Â Â Â Â Â Â Â [PCI_D3hot] = ACPI_STATE_D3,
> + Â Â Â Â Â Â Â [PCI_D3hot] = ACPI_STATE_D3_HOT,
> Â Â Â Â Â Â Â Â[PCI_D3cold] = ACPI_STATE_D3
> Â Â Â Â};
> Â Â Â Âint error = -EINVAL;
> diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
> index eba6604..e8bcc47 100644
> --- a/include/acpi/actypes.h
> +++ b/include/acpi/actypes.h
> @@ -499,9 +499,10 @@ typedef u64 acpi_integer;
> Â#define ACPI_STATE_D0 Â Â Â Â Â Â Â Â Â (u8) 0
> Â#define ACPI_STATE_D1 Â Â Â Â Â Â Â Â Â (u8) 1
> Â#define ACPI_STATE_D2 Â Â Â Â Â Â Â Â Â (u8) 2
> -#define ACPI_STATE_D3 Â Â Â Â Â Â Â Â Â (u8) 3
> -#define ACPI_STATE_D3_COLD Â Â Â Â Â Â Â(u8) 4
> -#define ACPI_D_STATES_MAX Â Â Â Â Â Â Â ACPI_STATE_D3_COLD
> +#define ACPI_STATE_D3_HOT Â Â Â Â Â Â Â (u8) 3
> +#define ACPI_STATE_D3 Â Â Â Â Â Â Â Â Â (u8) 4
> +#define ACPI_STATE_D3_COLD Â Â Â Â Â Â ÂACPI_STATE_D3
> +#define ACPI_D_STATES_MAX Â Â Â Â Â Â Â ACPI_STATE_D3
> Â#define ACPI_D_STATE_COUNT Â Â Â Â Â Â Â5
>
> Â#define ACPI_STATE_C0 Â Â Â Â Â Â Â Â Â (u8) 0

Best Regards,
Huang Ying
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/