2014-10-17 13:37:38

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 00/18] Introduce ACPI for ARM64 based on ACPI 5.1

ACPI 5.1 has some major changes for ARM platform and the following
tables which are essential for ARM platforms:
1) MADT table updates for GIC v2/v3.
2) FADT updates for PSCI
3) GTDT for arch timer

This patch set is the ARM64 ACPI core patches covered MADT, FADT
and GTDT, platform board specific drivers are not covered by this
patch set.

We first introduce acpi.c and its related head file which are needed
by ACPI core, and then get RSDP to extract all the ACPI boot-time tables.
When all the boot-time tables (FADT, MADT, GTDT) are ready, then
parse them to init the sytem when booted. Specifically,
a) we use FADT to init PSCI and use PSCI to boot SMP;
b) Use MADT for GIC init and SMP init;
c) GTDT for arch timer init.

This patch set is based on 3.17-rc4 and was tested by Graeme on Juno
and FVP base model boot with ACPI only OK, if you want to test them,
you can pull from acpi-5.1-v5 branch in leg/acpi repo:
git://git.linaro.org/leg/acpi/acpi.git

Updates since v4:
- ACPI uasge doc for ARM64 was updated a lot by Al
- Collect some ACKs from Grant, Olof, Mark
- address some comments from Olof and Catalin since last version

Updates since v3:
- Compile out sleep.c on ARM64 when ACPI enabled
- refactor the GIC init code to address the comments from Marc and
Arnd
- refactor the SMP init code to fix some logic problem when PSCI is
not present, also address some of Grant and Lorenzo's comments
- reorder the patch series and move ACPI table changes to the front
of patch set
- rebase on top of 3.17-rc4

Updates since v2:
- Refactor the code to make SMP/PSCI init with less sperated init
path by Tomasz
- make ACPI depend on EXPERT
- Address lots of comments from Catalin, Sudeep, Geoff
- Add Juno device ACPI driver patches for review

Updates since v1:
- Set ACPI default off on ARM64 suggested by Olof;
- Rebase the patch set on top of linux-next branch/linux-pm tree which
includes the ACPICA for full ACPI 5.1 support.
- Update the document as suggested;
- Adress lots of comments from Mark, Sudeep, Randy, Naresh, Olof, Geoff
and more...


Al Stone (3):
ARM64 / ACPI: Get RSDP and ACPI boot-time tables
ARM64 / ACPI: Introduce early_param for "acpi" and pass acpi=force to
enable ACPI
ARM64 / ACPI: Select ACPI_REDUCED_HARDWARE_ONLY if ACPI is enabled on
ARM64

Ashwin Chaugule (1):
ACPI / table: Add new function to get table entries

Graeme Gregory (4):
ARM64 / ACPI: Introduce sleep-arm.c
ARM64 / ACPI: If we chose to boot from acpi then disable FDT
ARM64 / ACPI: Enable ARM64 in Kconfig
Documentation: ACPI for ARM64

Hanjun Guo (8):
ARM64: Move the init of cpu_logical_map(0) before
unflatten_device_tree()
ARM64 / ACPI: Make PCI optional for ACPI on ARM64
ARM64 / ACPI: Parse FADT table to get PSCI flags for PSCI init
ACPI / table: Print GIC information when MADT is parsed
ARM64 / ACPI: Parse MADT for SMP initialization
ACPI / processor: Make it possible to get CPU hardware ID via GICC
ARM64 / ACPI: Introduce ACPI_IRQ_MODEL_GIC and register device's gsi
ARM64 / ACPI: Parse GTDT to initialize arch timer

Tomasz Nowicki (2):
ACPI / table: Count matched and successfully parsed entries without
specifying max entries
ARM64 / ACPI: Add GICv2 specific ACPI boot support

Documentation/arm64/arm-acpi.txt | 323 ++++++++++++++++++++++++++++++
Documentation/kernel-parameters.txt | 3 +-
arch/arm64/Kconfig | 3 +
arch/arm64/include/asm/acenv.h | 18 ++
arch/arm64/include/asm/acpi.h | 99 ++++++++++
arch/arm64/include/asm/cpu_ops.h | 1 +
arch/arm64/include/asm/pci.h | 11 ++
arch/arm64/include/asm/psci.h | 3 +-
arch/arm64/include/asm/smp.h | 5 +-
arch/arm64/kernel/Makefile | 1 +
arch/arm64/kernel/acpi.c | 356 ++++++++++++++++++++++++++++++++++
arch/arm64/kernel/cpu_ops.c | 4 +-
arch/arm64/kernel/psci.c | 78 +++++---
arch/arm64/kernel/setup.c | 25 ++-
arch/arm64/kernel/smp.c | 2 +-
arch/arm64/kernel/time.c | 7 +
drivers/acpi/Kconfig | 6 +-
drivers/acpi/Makefile | 6 +-
drivers/acpi/bus.c | 3 +
drivers/acpi/internal.h | 5 +
drivers/acpi/processor_core.c | 37 ++++
drivers/acpi/sleep-arm.c | 28 +++
drivers/acpi/tables.c | 115 +++++++++--
drivers/clocksource/arm_arch_timer.c | 117 +++++++++--
drivers/irqchip/irq-gic.c | 106 ++++++++++
drivers/irqchip/irqchip.c | 3 +
include/linux/acpi.h | 5 +
include/linux/clocksource.h | 6 +
include/linux/irqchip/arm-gic-acpi.h | 31 +++
include/linux/pci.h | 37 +++-
30 files changed, 1353 insertions(+), 91 deletions(-)
create mode 100644 Documentation/arm64/arm-acpi.txt
create mode 100644 arch/arm64/include/asm/acenv.h
create mode 100644 arch/arm64/include/asm/acpi.h
create mode 100644 arch/arm64/include/asm/pci.h
create mode 100644 arch/arm64/kernel/acpi.c
create mode 100644 drivers/acpi/sleep-arm.c
create mode 100644 include/linux/irqchip/arm-gic-acpi.h

--
1.7.9.5


2014-10-17 13:37:54

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 01/18] ARM64: Move the init of cpu_logical_map(0) before unflatten_device_tree()

It always make sense to initialize CPU0's logical map entry from the
hardware values, so move the initialization of cpu_logical_map(0)
before unflatten_device_tree() which is needed by ACPI code later.

Acked-by: Olof Johansson <[email protected]>
Acked-by: Mark Rutland <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
arch/arm64/kernel/setup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index edb146d..8f33f72 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -393,11 +393,11 @@ void __init setup_arch(char **cmdline_p)

efi_idmap_init();

+ cpu_logical_map(0) = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
unflatten_device_tree();

psci_init();

- cpu_logical_map(0) = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
cpu_read_bootcpu_ops();
#ifdef CONFIG_SMP
smp_init_cpus();
--
1.7.9.5

2014-10-17 13:38:07

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 02/18] ACPI / table: Add new function to get table entries

From: Ashwin Chaugule <[email protected]>

The acpi_table_parse() function has a callback that
passes a pointer to a table_header. Add a new function
which takes this pointer and parses its entries. This
eliminates the need to re-traverse all the tables for
each call. e.g. as in acpi_table_parse_madt() which is
normally called after acpi_table_parse().

Acked-by: Grant Likely <[email protected]>
Signed-off-by: Ashwin Chaugule <[email protected]>
Signed-off-by: Tomasz Nowicki <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
drivers/acpi/tables.c | 67 ++++++++++++++++++++++++++++++++++---------------
include/linux/acpi.h | 4 +++
2 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 6d5a6cd..21ae521 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -192,17 +192,14 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)


int __init
-acpi_table_parse_entries(char *id,
- unsigned long table_size,
- int entry_id,
- acpi_tbl_entry_handler handler,
- unsigned int max_entries)
+acpi_parse_entries(unsigned long table_size,
+ acpi_tbl_entry_handler handler,
+ struct acpi_table_header *table_header,
+ int entry_id, unsigned int max_entries)
{
- struct acpi_table_header *table_header = NULL;
struct acpi_subtable_header *entry;
- unsigned int count = 0;
+ int count = 0;
unsigned long table_end;
- acpi_size tbl_size;

if (acpi_disabled)
return -ENODEV;
@@ -210,13 +207,11 @@ acpi_table_parse_entries(char *id,
if (!handler)
return -EINVAL;

- if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
- acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
- else
- acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
+ if (!table_size)
+ return -EINVAL;

if (!table_header) {
- pr_warn("%4.4s not present\n", id);
+ pr_warn("Table header not present\n");
return -ENODEV;
}

@@ -232,30 +227,62 @@ acpi_table_parse_entries(char *id,
if (entry->type == entry_id
&& (!max_entries || count++ < max_entries))
if (handler(entry, table_end))
- goto err;
+ return -EINVAL;

/*
* If entry->length is 0, break from this loop to avoid
* infinite loop.
*/
if (entry->length == 0) {
- pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
- goto err;
+ pr_err("[0x%02x] Invalid zero length\n", entry_id);
+ return -EINVAL;
}

entry = (struct acpi_subtable_header *)
((unsigned long)entry + entry->length);
}
+
if (max_entries && count > max_entries) {
pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n",
- id, entry_id, count - max_entries, count);
+ table_header->signature, entry_id, count - max_entries,
+ count);
}

- early_acpi_os_unmap_memory((char *)table_header, tbl_size);
return count;
-err:
+}
+
+int __init
+acpi_table_parse_entries(char *id,
+ unsigned long table_size,
+ int entry_id,
+ acpi_tbl_entry_handler handler,
+ unsigned int max_entries)
+{
+ struct acpi_table_header *table_header = NULL;
+ acpi_size tbl_size;
+ int count;
+
+ if (acpi_disabled)
+ return -ENODEV;
+
+ if (!handler)
+ return -EINVAL;
+
+ if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
+ acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
+ else
+ acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
+
+ if (!table_header) {
+ pr_warn("%4.4s not present\n", id);
+ return -ENODEV;
+ }
+
+ count = acpi_parse_entries(table_size, handler, table_header,
+ entry_id, max_entries);
+
early_acpi_os_unmap_memory((char *)table_header, tbl_size);
- return -EINVAL;
+ return count;
}

int __init
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 807cbc4..36d5012 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -123,6 +123,10 @@ int acpi_numa_init (void);

int acpi_table_init (void);
int acpi_table_parse(char *id, acpi_tbl_table_handler handler);
+int __init acpi_parse_entries(unsigned long table_size,
+ acpi_tbl_entry_handler handler,
+ struct acpi_table_header *table_header,
+ int entry_id, unsigned int max_entries);
int __init acpi_table_parse_entries(char *id, unsigned long table_size,
int entry_id,
acpi_tbl_entry_handler handler,
--
1.7.9.5

2014-10-17 13:38:19

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 03/18] ACPI / table: Count matched and successfully parsed entries without specifying max entries

From: Tomasz Nowicki <[email protected]>

It is very useful to traverse all available table entries without max
number of expected entries type. Current acpi_parse_entries()
implementation gives that feature but it does not count those entries,
it returns 0 instead, so fix it to count matched and successfully
entries and return it.

NOTE: This change has no impact to x86 and ia64 archs since existing code
checks for error occurrence only (acpi_parse_entries(...,0) < 0).

Acked-by: Grant Likely <[email protected]>
Signed-off-by: Tomasz Nowicki <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
drivers/acpi/tables.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index 21ae521..b18e45e 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -225,10 +225,13 @@ acpi_parse_entries(unsigned long table_size,
while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
table_end) {
if (entry->type == entry_id
- && (!max_entries || count++ < max_entries))
+ && (!max_entries || count < max_entries)) {
if (handler(entry, table_end))
return -EINVAL;

+ count++;
+ }
+
/*
* If entry->length is 0, break from this loop to avoid
* infinite loop.
--
1.7.9.5

2014-10-17 13:38:35

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 04/18] ARM64 / ACPI: Get RSDP and ACPI boot-time tables

From: Al Stone <[email protected]>

As we want to get ACPI tables to parse and then use the information
for system initialization, we should get the RSDP (Root System
Description Pointer) first, it then locates Extended Root Description
Table (XSDT) which contains all the 64-bit physical address that
pointer to other boot-time tables.

Introduce acpi.c and its related head file in this patch to provide
fundamental needs of extern variables and functions for ACPI core,
and then get boot-time tables as needed.
- asm/acenv.h for arch specific ACPICA environments and
implementation, It is needed unconditionally by ACPI core;
- asm/acpi.h for arch specific variables and functions needed by
ACPI driver core;
- acpi.c for ARM64 related ACPI implementation for ACPI driver
core;

acpi_boot_table_init() is introduced to get RSDP and boot-time tables,
it will be called in setup_arch() before paging_init(), so we should
use eary_memremap() mechanism here to get the RSDP and all the table
pointers.

Signed-off-by: Al Stone <[email protected]>
Signed-off-by: Graeme Gregory <[email protected]>
Signed-off-by: Tomasz Nowicki <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
arch/arm64/include/asm/acenv.h | 18 +++++++++++
arch/arm64/include/asm/acpi.h | 45 ++++++++++++++++++++++++++
arch/arm64/kernel/Makefile | 1 +
arch/arm64/kernel/acpi.c | 69 ++++++++++++++++++++++++++++++++++++++++
arch/arm64/kernel/setup.c | 4 +++
5 files changed, 137 insertions(+)
create mode 100644 arch/arm64/include/asm/acenv.h
create mode 100644 arch/arm64/include/asm/acpi.h
create mode 100644 arch/arm64/kernel/acpi.c

diff --git a/arch/arm64/include/asm/acenv.h b/arch/arm64/include/asm/acenv.h
new file mode 100644
index 0000000..b49166f
--- /dev/null
+++ b/arch/arm64/include/asm/acenv.h
@@ -0,0 +1,18 @@
+/*
+ * ARM64 specific ACPICA environments and implementation
+ *
+ * Copyright (C) 2014, Linaro Ltd.
+ * Author: Hanjun Guo <[email protected]>
+ * Author: Graeme Gregory <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_ACENV_H
+#define _ASM_ACENV_H
+
+/* It is required unconditionally by ACPI core, update it when needed. */
+
+#endif /* _ASM_ACENV_H */
diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
new file mode 100644
index 0000000..8b837ab
--- /dev/null
+++ b/arch/arm64/include/asm/acpi.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013-2014, Linaro Ltd.
+ * Author: Al Stone <[email protected]>
+ * Author: Graeme Gregory <[email protected]>
+ * Author: Hanjun Guo <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ */
+
+#ifndef _ASM_ACPI_H
+#define _ASM_ACPI_H
+
+/* Basic configuration for ACPI */
+#ifdef CONFIG_ACPI
+#define acpi_strict 1 /* No out-of-spec workarounds on ARM64 */
+extern int acpi_disabled;
+extern int acpi_noirq;
+extern int acpi_pci_disabled;
+
+static inline void disable_acpi(void)
+{
+ acpi_disabled = 1;
+ acpi_pci_disabled = 1;
+ acpi_noirq = 1;
+}
+
+/*
+ * It's used from ACPI core in kdump to boot UP system with SMP kernel,
+ * with this check the ACPI core will not override the CPU index
+ * obtained from GICC with 0 and not print some error message as well.
+ * Since MADT must provide at least one GICC structure for GIC
+ * initialization, CPU will be always available in MADT on ARM64.
+ */
+static inline bool acpi_has_cpu_in_madt(void)
+{
+ return true;
+}
+
+static inline void arch_fix_phys_package_id(int num, u32 slot) { }
+
+#endif /* CONFIG_ACPI */
+
+#endif /*_ASM_ACPI_H*/
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index df7ef87..29ea7d6 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -29,6 +29,7 @@ arm64-obj-$(CONFIG_ARM64_CPU_SUSPEND) += sleep.o suspend.o
arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o
arm64-obj-$(CONFIG_KGDB) += kgdb.o
arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o
+arm64-obj-$(CONFIG_ACPI) += acpi.o

obj-y += $(arm64-obj-y) vdso/
obj-m += $(arm64-obj-m)
diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
new file mode 100644
index 0000000..9252f72
--- /dev/null
+++ b/arch/arm64/kernel/acpi.c
@@ -0,0 +1,69 @@
+/*
+ * ARM64 Specific Low-Level ACPI Boot Support
+ *
+ * Copyright (C) 2013-2014, Linaro Ltd.
+ * Author: Al Stone <[email protected]>
+ * Author: Graeme Gregory <[email protected]>
+ * Author: Hanjun Guo <[email protected]>
+ * Author: Tomasz Nowicki <[email protected]>
+ * Author: Naresh Bhat <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/acpi.h>
+#include <linux/cpumask.h>
+#include <linux/memblock.h>
+#include <linux/irq.h>
+#include <linux/irqdomain.h>
+#include <linux/bootmem.h>
+#include <linux/smp.h>
+
+int acpi_noirq; /* skip ACPI IRQ initialization */
+int acpi_disabled;
+EXPORT_SYMBOL(acpi_disabled);
+
+int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
+EXPORT_SYMBOL(acpi_pci_disabled);
+
+/*
+ * __acpi_map_table() will be called before page_init(), so early_ioremap()
+ * or early_memremap() should be called here to for ACPI table mapping.
+ */
+char *__init __acpi_map_table(unsigned long phys, unsigned long size)
+{
+ if (!phys || !size)
+ return NULL;
+
+ return early_memremap(phys, size);
+}
+
+void __init __acpi_unmap_table(char *map, unsigned long size)
+{
+ if (!map || !size)
+ return;
+
+ early_memunmap(map, size);
+}
+
+/*
+ * acpi_boot_table_init() called from setup_arch(), always.
+ * 1. find RSDP and get its address, and then find XSDT
+ * 2. extract all tables and checksums them all
+ *
+ * We can parse ACPI boot-time tables such as MADT after
+ * this function is called.
+ */
+void __init acpi_boot_table_init(void)
+{
+ /* If acpi_disabled, bail out */
+ if (acpi_disabled)
+ return;
+
+ /* Initialize the ACPI boot-time table parser. */
+ if (acpi_table_init())
+ disable_acpi();
+}
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 8f33f72..5b05227 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -43,6 +43,7 @@
#include <linux/of_fdt.h>
#include <linux/of_platform.h>
#include <linux/efi.h>
+#include <linux/acpi.h>

#include <asm/fixmap.h>
#include <asm/cpu.h>
@@ -388,6 +389,9 @@ void __init setup_arch(char **cmdline_p)
efi_init();
arm64_memblock_init();

+ /* Parse the ACPI tables for possible boot-time configuration */
+ acpi_boot_table_init();
+
paging_init();
request_standard_resources();

--
1.7.9.5

2014-10-17 13:38:44

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 05/18] ARM64 / ACPI: Introduce sleep-arm.c

From: Graeme Gregory <[email protected]>

ACPI 5.1 does not currently support S states for ARM64 hardware but
ACPI code will call acpi_target_system_state() for device power
managment, so introduce sleep-arm.c to allow other drivers to function
until S states are defined.

Signed-off-by: Graeme Gregory <[email protected]>
Signed-off-by: Tomasz Nowicki <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
drivers/acpi/Makefile | 4 ++++
drivers/acpi/sleep-arm.c | 28 ++++++++++++++++++++++++++++
2 files changed, 32 insertions(+)
create mode 100644 drivers/acpi/sleep-arm.c

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 505d4d7..89837f8 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -23,7 +23,11 @@ acpi-y += nvs.o

# Power management related files
acpi-y += wakeup.o
+ifeq ($(ARCH), arm64)
+acpi-y += sleep-arm.o
+else # X86, IA64
acpi-y += sleep.o
+endif
acpi-y += device_pm.o
acpi-$(CONFIG_ACPI_SLEEP) += proc.o

diff --git a/drivers/acpi/sleep-arm.c b/drivers/acpi/sleep-arm.c
new file mode 100644
index 0000000..54578ef
--- /dev/null
+++ b/drivers/acpi/sleep-arm.c
@@ -0,0 +1,28 @@
+/*
+ * ARM64 Specific Sleep Functionality
+ *
+ * Copyright (C) 2013-2014, Linaro Ltd.
+ * Author: Graeme Gregory <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/acpi.h>
+
+/*
+ * Currently the ACPI 5.1 standard does not define S states in a
+ * manner which is usable for ARM64. These two stubs are sufficient
+ * that system initialises and device PM works.
+ */
+u32 acpi_target_system_state(void)
+{
+ return ACPI_STATE_S0;
+}
+EXPORT_SYMBOL_GPL(acpi_target_system_state);
+
+int __init acpi_sleep_init(void)
+{
+ return -ENOSYS;
+}
--
1.7.9.5

2014-10-17 13:38:57

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 06/18] ARM64 / ACPI: Introduce early_param for "acpi" and pass acpi=force to enable ACPI

From: Al Stone <[email protected]>

Introduce one early parameters "off" and "force" for "acpi", acpi=off
will be the default behavior for ARM64, so introduce acpi=force to
enable ACPI on ARM64.

Disable ACPI before early parameters parsed, and enable it to pass
"acpi=force" if people want use ACPI on ARM64. This ensures DT be
the prefer one if ACPI table and DT both are provided at this moment.

Signed-off-by: Al Stone <[email protected]>
Signed-off-by: Graeme Gregory <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
Documentation/kernel-parameters.txt | 3 ++-
arch/arm64/include/asm/acpi.h | 9 +++++++++
arch/arm64/kernel/acpi.c | 17 +++++++++++++++++
arch/arm64/kernel/setup.c | 3 +++
4 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 5ae8608..2af0948 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -165,7 +165,7 @@ multipliers 'Kilo', 'Mega', and 'Giga', equalling 2^10, 2^20, and 2^30
bytes respectively. Such letter suffixes can also be entirely omitted.


- acpi= [HW,ACPI,X86]
+ acpi= [HW,ACPI,X86,ARM64]
Advanced Configuration and Power Interface
Format: { force | off | strict | noirq | rsdt }
force -- enable ACPI if default was off
@@ -175,6 +175,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
strictly ACPI specification compliant.
rsdt -- prefer RSDT over (default) XSDT
copy_dsdt -- copy DSDT to memory
+ For ARM64, ONLY "acpi=off" or "acpi=force" are available

See also Documentation/power/runtime_pm.txt, pci=noacpi

diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
index 8b837ab..496c33b 100644
--- a/arch/arm64/include/asm/acpi.h
+++ b/arch/arm64/include/asm/acpi.h
@@ -26,6 +26,13 @@ static inline void disable_acpi(void)
acpi_noirq = 1;
}

+static inline void enable_acpi(void)
+{
+ acpi_disabled = 0;
+ acpi_pci_disabled = 0;
+ acpi_noirq = 0;
+}
+
/*
* It's used from ACPI core in kdump to boot UP system with SMP kernel,
* with this check the ACPI core will not override the CPU index
@@ -40,6 +47,8 @@ static inline bool acpi_has_cpu_in_madt(void)

static inline void arch_fix_phys_package_id(int num, u32 slot) { }

+#else
+static inline void disable_acpi(void) { }
#endif /* CONFIG_ACPI */

#endif /*_ASM_ACPI_H*/
diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
index 9252f72..39a1655 100644
--- a/arch/arm64/kernel/acpi.c
+++ b/arch/arm64/kernel/acpi.c
@@ -67,3 +67,20 @@ void __init acpi_boot_table_init(void)
if (acpi_table_init())
disable_acpi();
}
+
+static int __init parse_acpi(char *arg)
+{
+ if (!arg)
+ return -EINVAL;
+
+ /* "acpi=off" disables both ACPI table parsing and interpreter */
+ if (strcmp(arg, "off") == 0)
+ disable_acpi();
+ else if (strcmp(arg, "force") == 0) /* force ACPI to be enabled */
+ enable_acpi();
+ else
+ return -EINVAL; /* Core will print when we return error */
+
+ return 0;
+}
+early_param("acpi", parse_acpi);
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 5b05227..15621b9 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -60,6 +60,7 @@
#include <asm/memblock.h>
#include <asm/psci.h>
#include <asm/efi.h>
+#include <asm/acpi.h>

unsigned int processor_id;
EXPORT_SYMBOL(processor_id);
@@ -384,6 +385,8 @@ void __init setup_arch(char **cmdline_p)

early_ioremap_init();

+ disable_acpi();
+
parse_early_param();

efi_init();
--
1.7.9.5

2014-10-17 13:39:08

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 07/18] ARM64 / ACPI: If we chose to boot from acpi then disable FDT

From: Graeme Gregory <[email protected]>

If the early boot methods of acpi are happy that we have valid ACPI
tables and acpi=force has been passed, then do not unflat devicetree
effectively disabling further hardware probing from DT.

Signed-off-by: Graeme Gregory <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
arch/arm64/kernel/setup.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 15621b9..e4f2576 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -401,7 +401,8 @@ void __init setup_arch(char **cmdline_p)
efi_idmap_init();

cpu_logical_map(0) = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
- unflatten_device_tree();
+ if (acpi_disabled)
+ unflatten_device_tree();

psci_init();

--
1.7.9.5

2014-10-17 13:39:20

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 08/18] ARM64 / ACPI: Make PCI optional for ACPI on ARM64

As PCI for ARM64 is not ready, so introduce some stub functions
to make PCI optional for ACPI, and make ACPI core run without
CONFIG_PCI on ARM64.

Since ACPI on X86 and IA64 depends on PCI and this patch only makes
PCI optional for ARM64, it will not break anything on X86 and IA64.

Signed-off-by: Hanjun Guo <[email protected]>
---
arch/arm64/include/asm/pci.h | 11 +++++++++++
drivers/acpi/Makefile | 2 +-
drivers/acpi/internal.h | 5 +++++
include/linux/pci.h | 37 +++++++++++++++++++++++++++----------
4 files changed, 44 insertions(+), 11 deletions(-)
create mode 100644 arch/arm64/include/asm/pci.h

diff --git a/arch/arm64/include/asm/pci.h b/arch/arm64/include/asm/pci.h
new file mode 100644
index 0000000..250cd24
--- /dev/null
+++ b/arch/arm64/include/asm/pci.h
@@ -0,0 +1,11 @@
+#ifndef __ASM_PCI_H
+#define __ASM_PCI_H
+#ifdef __KERNEL__
+
+/*
+ * PCI address space differs from physical memory address space
+ */
+#define PCI_DMA_BUS_IS_PHYS (0)
+
+#endif /* __KERNEL__ */
+#endif /* __ASM_PCI_H */
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 89837f8..6f3a74d 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -43,7 +43,7 @@ acpi-y += processor_core.o
acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
acpi-y += ec.o
acpi-$(CONFIG_ACPI_DOCK) += dock.o
-acpi-y += pci_root.o pci_link.o pci_irq.o
+acpi-$(CONFIG_PCI) += pci_root.o pci_link.o pci_irq.o
acpi-y += acpi_lpss.o
acpi-y += acpi_platform.o
acpi-y += acpi_pnp.o
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 4c5cf77..e1e6487 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -26,8 +26,13 @@
acpi_status acpi_os_initialize1(void);
int init_acpi_device_notify(void);
int acpi_scan_init(void);
+#ifdef CONFIG_PCI
void acpi_pci_root_init(void);
void acpi_pci_link_init(void);
+#else
+static inline void acpi_pci_root_init(void) {}
+static inline void acpi_pci_link_init(void) {}
+#endif
void acpi_processor_init(void);
void acpi_platform_init(void);
void acpi_pnp_init(void);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 61978a4..50fa750 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -558,15 +558,6 @@ struct pci_ops {
int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
};

-/*
- * ACPI needs to be able to access PCI config space before we've done a
- * PCI bus scan and created pci_bus structures.
- */
-int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
- int reg, int len, u32 *val);
-int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
- int reg, int len, u32 val);
-
struct pci_bus_region {
dma_addr_t start;
dma_addr_t end;
@@ -1293,6 +1284,16 @@ typedef int (*arch_set_vga_state_t)(struct pci_dev *pdev, bool decode,
unsigned int command_bits, u32 flags);
void pci_register_set_vga_state(arch_set_vga_state_t func);

+/*
+ * ACPI needs to be able to access PCI config space before we've done a
+ * PCI bus scan and created pci_bus structures.
+ */
+int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
+ int reg, int len, u32 *val);
+int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
+ int reg, int len, u32 val);
+void pcibios_penalize_isa_irq(int irq, int active);
+
#else /* CONFIG_PCI is not enabled */

/*
@@ -1394,6 +1395,23 @@ static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
unsigned int devfn)
{ return NULL; }

+static inline struct pci_bus *pci_find_bus(int domain, int busnr)
+{ return NULL; }
+
+static inline int pci_bus_write_config_byte(struct pci_bus *bus,
+ unsigned int devfn, int where, u8 val)
+{ return -ENOSYS; }
+
+static inline int raw_pci_read(unsigned int domain, unsigned int bus,
+ unsigned int devfn, int reg, int len, u32 *val)
+{ return -ENOSYS; }
+
+static inline int raw_pci_write(unsigned int domain, unsigned int bus,
+ unsigned int devfn, int reg, int len, u32 val)
+{ return -ENOSYS; }
+
+static inline void pcibios_penalize_isa_irq(int irq, int active) { }
+
static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
static inline struct pci_dev *pci_dev_get(struct pci_dev *dev) { return NULL; }

@@ -1607,7 +1625,6 @@ int pcibios_set_pcie_reset_state(struct pci_dev *dev,
enum pcie_reset_state state);
int pcibios_add_device(struct pci_dev *dev);
void pcibios_release_device(struct pci_dev *dev);
-void pcibios_penalize_isa_irq(int irq, int active);

#ifdef CONFIG_HIBERNATE_CALLBACKS
extern struct dev_pm_ops pcibios_pm_ops;
--
1.7.9.5

2014-10-17 13:39:36

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 09/18] ARM64 / ACPI: Parse FADT table to get PSCI flags for PSCI init

There are two flags: PSCI_COMPLIANT and PSCI_USE_HVC. When set,
the former signals to the OS that the firmware is PSCI compliant.
The latter selects the appropriate conduit for PSCI calls by
toggling between Hypervisor Calls (HVC) and Secure Monitor Calls
(SMC).

FADT table contains such information, parse FADT to get the flags
for PSCI init. Since ACPI 5.1 doesn't support self defined PSCI
function IDs, which means that only PSCI 0.2+ is supported in ACPI.

At the same time, only ACPI 5.1 or higher verison supports PSCI,
and FADT Major.Minor version was introduced in ACPI 5.1, so we
will check the version and only parse FADT table with version >= 5.1.

If firmware provides ACPI tables with ACPI version less than 5.1,
OS will be messed up with those information and have no way to init
smp and GIC, so disable ACPI if we get an FADT table with version
less that 5.1.

Signed-off-by: Hanjun Guo <[email protected]>
Signed-off-by: Graeme Gregory <[email protected]>
Signed-off-by: Tomasz Nowicki <[email protected]>
---
arch/arm64/include/asm/acpi.h | 14 ++++++++
arch/arm64/include/asm/psci.h | 3 +-
arch/arm64/kernel/acpi.c | 31 +++++++++++++++-
arch/arm64/kernel/psci.c | 78 ++++++++++++++++++++++++++++-------------
arch/arm64/kernel/setup.c | 8 +++--
5 files changed, 105 insertions(+), 29 deletions(-)

diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
index 496c33b..221ff15 100644
--- a/arch/arm64/include/asm/acpi.h
+++ b/arch/arm64/include/asm/acpi.h
@@ -19,6 +19,18 @@ extern int acpi_disabled;
extern int acpi_noirq;
extern int acpi_pci_disabled;

+/* 1 to indicate PSCI 0.2+ is implemented */
+static inline bool acpi_psci_present(void)
+{
+ return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_COMPLIANT;
+}
+
+/* 1 to indicate HVC must be used instead of SMC as the PSCI conduit */
+static inline bool acpi_psci_use_hvc(void)
+{
+ return acpi_gbl_FADT.arm_boot_flags & ACPI_FADT_PSCI_USE_HVC;
+}
+
static inline void disable_acpi(void)
{
acpi_disabled = 1;
@@ -49,6 +61,8 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) { }

#else
static inline void disable_acpi(void) { }
+static inline bool acpi_psci_present(void) { return false; }
+static inline bool acpi_psci_use_hvc(void) { return false; }
#endif /* CONFIG_ACPI */

#endif /*_ASM_ACPI_H*/
diff --git a/arch/arm64/include/asm/psci.h b/arch/arm64/include/asm/psci.h
index e5312ea..2454bc5 100644
--- a/arch/arm64/include/asm/psci.h
+++ b/arch/arm64/include/asm/psci.h
@@ -14,6 +14,7 @@
#ifndef __ASM_PSCI_H
#define __ASM_PSCI_H

-int psci_init(void);
+int psci_dt_init(void);
+int psci_acpi_init(void);

#endif /* __ASM_PSCI_H */
diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
index 39a1655..e713236 100644
--- a/arch/arm64/kernel/acpi.c
+++ b/arch/arm64/kernel/acpi.c
@@ -13,6 +13,8 @@
* published by the Free Software Foundation.
*/

+#define pr_fmt(fmt) "ACPI: " fmt
+
#include <linux/init.h>
#include <linux/acpi.h>
#include <linux/cpumask.h>
@@ -49,10 +51,32 @@ void __init __acpi_unmap_table(char *map, unsigned long size)
early_memunmap(map, size);
}

+static int __init acpi_parse_fadt(struct acpi_table_header *table)
+{
+ struct acpi_table_fadt *fadt = (struct acpi_table_fadt *)table;
+
+ /*
+ * Revision in table header is the FADT Major revision,
+ * and there is a minor revision of FADT which was introduced
+ * by ACPI 5.1, we only deal with ACPI 5.1 or newer revision
+ * to get arm boot flags, or we will disable ACPI.
+ */
+ if (table->revision > 5 ||
+ (table->revision == 5 && fadt->minor_revision >= 1))
+ return 0;
+
+ pr_warn("Unsupported FADT revision %d.%d, should be 5.1+, will disable ACPI\n",
+ table->revision, fadt->minor_revision);
+ disable_acpi();
+
+ return -EINVAL;
+}
+
/*
* acpi_boot_table_init() called from setup_arch(), always.
* 1. find RSDP and get its address, and then find XSDT
* 2. extract all tables and checksums them all
+ * 3. check ACPI FADT revisoin
*
* We can parse ACPI boot-time tables such as MADT after
* this function is called.
@@ -64,8 +88,13 @@ void __init acpi_boot_table_init(void)
return;

/* Initialize the ACPI boot-time table parser. */
- if (acpi_table_init())
+ if (acpi_table_init()) {
disable_acpi();
+ return;
+ }
+
+ if (acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt))
+ pr_err("Can't find FADT or error happened during parsing FADT\n");
}

static int __init parse_acpi(char *arg)
diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
index 5539547..15ba470 100644
--- a/arch/arm64/kernel/psci.c
+++ b/arch/arm64/kernel/psci.c
@@ -15,6 +15,7 @@

#define pr_fmt(fmt) "psci: " fmt

+#include <linux/acpi.h>
#include <linux/init.h>
#include <linux/of.h>
#include <linux/smp.h>
@@ -23,6 +24,7 @@
#include <linux/delay.h>
#include <uapi/linux/psci.h>

+#include <asm/acpi.h>
#include <asm/compiler.h>
#include <asm/cpu_ops.h>
#include <asm/errno.h>
@@ -231,6 +233,33 @@ static void psci_sys_poweroff(void)
invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);
}

+static void psci_0_2_set_functions(void)
+{
+ pr_info("Using standard PSCI v0.2 function IDs\n");
+ psci_function_id[PSCI_FN_CPU_SUSPEND] = PSCI_0_2_FN64_CPU_SUSPEND;
+ psci_ops.cpu_suspend = psci_cpu_suspend;
+
+ psci_function_id[PSCI_FN_CPU_OFF] = PSCI_0_2_FN_CPU_OFF;
+ psci_ops.cpu_off = psci_cpu_off;
+
+ psci_function_id[PSCI_FN_CPU_ON] = PSCI_0_2_FN64_CPU_ON;
+ psci_ops.cpu_on = psci_cpu_on;
+
+ psci_function_id[PSCI_FN_MIGRATE] = PSCI_0_2_FN64_MIGRATE;
+ psci_ops.migrate = psci_migrate;
+
+ psci_function_id[PSCI_FN_AFFINITY_INFO] = PSCI_0_2_FN64_AFFINITY_INFO;
+ psci_ops.affinity_info = psci_affinity_info;
+
+ psci_function_id[PSCI_FN_MIGRATE_INFO_TYPE] =
+ PSCI_0_2_FN_MIGRATE_INFO_TYPE;
+ psci_ops.migrate_info_type = psci_migrate_info_type;
+
+ arm_pm_restart = psci_sys_reset;
+
+ pm_power_off = psci_sys_poweroff;
+}
+
/*
* PSCI Function IDs for v0.2+ are well defined so use
* standard values.
@@ -264,29 +293,7 @@ static int __init psci_0_2_init(struct device_node *np)
}
}

- pr_info("Using standard PSCI v0.2 function IDs\n");
- psci_function_id[PSCI_FN_CPU_SUSPEND] = PSCI_0_2_FN64_CPU_SUSPEND;
- psci_ops.cpu_suspend = psci_cpu_suspend;
-
- psci_function_id[PSCI_FN_CPU_OFF] = PSCI_0_2_FN_CPU_OFF;
- psci_ops.cpu_off = psci_cpu_off;
-
- psci_function_id[PSCI_FN_CPU_ON] = PSCI_0_2_FN64_CPU_ON;
- psci_ops.cpu_on = psci_cpu_on;
-
- psci_function_id[PSCI_FN_MIGRATE] = PSCI_0_2_FN64_MIGRATE;
- psci_ops.migrate = psci_migrate;
-
- psci_function_id[PSCI_FN_AFFINITY_INFO] = PSCI_0_2_FN64_AFFINITY_INFO;
- psci_ops.affinity_info = psci_affinity_info;
-
- psci_function_id[PSCI_FN_MIGRATE_INFO_TYPE] =
- PSCI_0_2_FN_MIGRATE_INFO_TYPE;
- psci_ops.migrate_info_type = psci_migrate_info_type;
-
- arm_pm_restart = psci_sys_reset;
-
- pm_power_off = psci_sys_poweroff;
+ psci_0_2_set_functions();

out_put_node:
of_node_put(np);
@@ -339,7 +346,7 @@ static const struct of_device_id psci_of_match[] __initconst = {
{},
};

-int __init psci_init(void)
+int __init psci_dt_init(void)
{
struct device_node *np;
const struct of_device_id *matched_np;
@@ -354,6 +361,29 @@ int __init psci_init(void)
return init_fn(np);
}

+/*
+ * We use PSCI 0.2+ when ACPI is deployed on ARM64 and it's
+ * explicitly clarified in SBBR
+ */
+int __init psci_acpi_init(void)
+{
+ if (!acpi_psci_present()) {
+ pr_info("is not implemented in ACPI.\n");
+ return -EOPNOTSUPP;
+ }
+
+ pr_info("probing for conduit method from ACPI.\n");
+
+ if (acpi_psci_use_hvc())
+ invoke_psci_fn = __invoke_psci_fn_hvc;
+ else
+ invoke_psci_fn = __invoke_psci_fn_smc;
+
+ psci_0_2_set_functions();
+
+ return 0;
+}
+
#ifdef CONFIG_SMP

static int __init cpu_psci_cpu_init(struct device_node *dn, unsigned int cpu)
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index e4f2576..d448d6a 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -401,10 +401,12 @@ void __init setup_arch(char **cmdline_p)
efi_idmap_init();

cpu_logical_map(0) = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
- if (acpi_disabled)
+ if (acpi_disabled) {
unflatten_device_tree();
-
- psci_init();
+ psci_dt_init();
+ } else {
+ psci_acpi_init();
+ }

cpu_read_bootcpu_ops();
#ifdef CONFIG_SMP
--
1.7.9.5

2014-10-17 13:39:46

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 10/18] ACPI / table: Print GIC information when MADT is parsed

When MADT is parsed, print GIC information to make the boot
log look pretty:

ACPI: GICC (acpi_id[0x0000] address[00000000e112f000] MPDIR[0x0] enabled)
ACPI: GICC (acpi_id[0x0001] address[00000000e112f000] MPDIR[0x1] enabled)
...
ACPI: GICC (acpi_id[0x0201] address[00000000e112f000] MPDIR[0x201] enabled)

These information will be very helpful to bring up early systems to
see if acpi_id and MPIDR are matched or not as spec defined.

Signed-off-by: Hanjun Guo <[email protected]>
Signed-off-by: Tomasz Nowicki <[email protected]>
---
drivers/acpi/tables.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)

diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index b18e45e..47f36d4 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -183,6 +183,49 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
}
break;

+ case ACPI_MADT_TYPE_GENERIC_INTERRUPT:
+ {
+ struct acpi_madt_generic_interrupt *p =
+ (struct acpi_madt_generic_interrupt *)header;
+ pr_info("GICC (acpi_id[0x%04x] address[%p] MPDIR[0x%llx] %s)\n",
+ p->uid, (void *)(unsigned long)p->base_address,
+ p->arm_mpidr,
+ (p->flags & ACPI_MADT_ENABLED) ? "enabled" : "disabled");
+
+ }
+ break;
+
+ case ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR:
+ {
+ struct acpi_madt_generic_distributor *p =
+ (struct acpi_madt_generic_distributor *)header;
+ pr_info("GIC Distributor (gic_id[0x%04x] address[%p] gsi_base[%d])\n",
+ p->gic_id,
+ (void *)(unsigned long)p->base_address,
+ p->global_irq_base);
+ }
+ break;
+
+ case ACPI_MADT_TYPE_GENERIC_MSI_FRAME:
+ {
+ struct acpi_madt_generic_msi_frame *p =
+ (struct acpi_madt_generic_msi_frame *)header;
+ pr_info("GIC MSI Frame (msi_fame_id[%d] address[%p])\n",
+ p->msi_frame_id,
+ (void *)(unsigned long)p->base_address);
+ }
+ break;
+
+ case ACPI_MADT_TYPE_GENERIC_REDISTRIBUTOR:
+ {
+ struct acpi_madt_generic_redistributor *p =
+ (struct acpi_madt_generic_redistributor *)header;
+ pr_info("GIC Redistributor (address[%p] region_size[0x%x])\n",
+ (void *)(unsigned long)p->base_address,
+ p->length);
+ }
+ break;
+
default:
pr_warn("Found unsupported MADT entry (type = 0x%x)\n",
header->type);
--
1.7.9.5

2014-10-17 13:39:59

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 11/18] ARM64 / ACPI: Parse MADT for SMP initialization

MADT contains the information for MPIDR which is essential for
SMP initialization, parse the GIC cpu interface structures to
get the MPIDR value and map it to cpu_logical_map(), and add
enabled cpu with valid MPIDR into cpu_possible_map.

ACPI 5.1 only has two explicit methods to boot up SMP, PSCI and
Parking protocol, but the Parking protocol is only specified for
ARMv7 now, so make PSCI as the only way for the SMP boot protocol
before some updates for the ACPI spec or the Parking protocol spec.

Signed-off-by: Hanjun Guo <[email protected]>
Signed-off-by: Tomasz Nowicki <[email protected]>
---
arch/arm64/include/asm/acpi.h | 2 +
arch/arm64/include/asm/cpu_ops.h | 1 +
arch/arm64/include/asm/smp.h | 5 +-
arch/arm64/kernel/acpi.c | 150 +++++++++++++++++++++++++++++++++++++-
arch/arm64/kernel/cpu_ops.c | 4 +-
arch/arm64/kernel/setup.c | 7 +-
arch/arm64/kernel/smp.c | 2 +-
7 files changed, 162 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
index 221ff15..c82d4a1 100644
--- a/arch/arm64/include/asm/acpi.h
+++ b/arch/arm64/include/asm/acpi.h
@@ -58,11 +58,13 @@ static inline bool acpi_has_cpu_in_madt(void)
}

static inline void arch_fix_phys_package_id(int num, u32 slot) { }
+void __init acpi_smp_init_cpus(void);

#else
static inline void disable_acpi(void) { }
static inline bool acpi_psci_present(void) { return false; }
static inline bool acpi_psci_use_hvc(void) { return false; }
+static inline void acpi_smp_init_cpus(void) { }
#endif /* CONFIG_ACPI */

#endif /*_ASM_ACPI_H*/
diff --git a/arch/arm64/include/asm/cpu_ops.h b/arch/arm64/include/asm/cpu_ops.h
index d7b4b38..d149580 100644
--- a/arch/arm64/include/asm/cpu_ops.h
+++ b/arch/arm64/include/asm/cpu_ops.h
@@ -61,6 +61,7 @@ struct cpu_operations {
};

extern const struct cpu_operations *cpu_ops[NR_CPUS];
+const struct cpu_operations *cpu_get_ops(const char *name);
extern int __init cpu_read_ops(struct device_node *dn, int cpu);
extern void __init cpu_read_bootcpu_ops(void);

diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h
index a498f2c..c877adc 100644
--- a/arch/arm64/include/asm/smp.h
+++ b/arch/arm64/include/asm/smp.h
@@ -39,9 +39,10 @@ extern void show_ipi_list(struct seq_file *p, int prec);
extern void handle_IPI(int ipinr, struct pt_regs *regs);

/*
- * Setup the set of possible CPUs (via set_cpu_possible)
+ * Discover the set of possible CPUs and determine their
+ * SMP operations.
*/
-extern void smp_init_cpus(void);
+extern void of_smp_init_cpus(void);

/*
* Provide a function to raise an IPI cross call on CPUs in callmap.
diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
index e713236..34837e0 100644
--- a/arch/arm64/kernel/acpi.c
+++ b/arch/arm64/kernel/acpi.c
@@ -24,6 +24,10 @@
#include <linux/bootmem.h>
#include <linux/smp.h>

+#include <asm/smp_plat.h>
+#include <asm/cputype.h>
+#include <asm/cpu_ops.h>
+
int acpi_noirq; /* skip ACPI IRQ initialization */
int acpi_disabled;
EXPORT_SYMBOL(acpi_disabled);
@@ -31,6 +35,8 @@ EXPORT_SYMBOL(acpi_disabled);
int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */
EXPORT_SYMBOL(acpi_pci_disabled);

+static int enabled_cpus; /* Processors (GICC) with enabled flag in MADT */
+
/*
* __acpi_map_table() will be called before page_init(), so early_ioremap()
* or early_memremap() should be called here to for ACPI table mapping.
@@ -51,6 +57,134 @@ void __init __acpi_unmap_table(char *map, unsigned long size)
early_memunmap(map, size);
}

+/**
+ * acpi_map_gic_cpu_interface - generates a logical cpu number
+ * and map to MPIDR represented by GICC structure
+ * @mpidr: CPU's hardware id to register, MPIDR represented in MADT
+ * @enabled: this cpu is enabled or not
+ *
+ * Returns the logical cpu number which maps to MPIDR
+ */
+static int acpi_map_gic_cpu_interface(u64 mpidr, u8 enabled)
+{
+ int cpu;
+
+ if (mpidr == INVALID_HWID) {
+ pr_info("Skip MADT cpu entry with invalid MPIDR\n");
+ return -EINVAL;
+ }
+
+ total_cpus++;
+ if (!enabled)
+ return -EINVAL;
+
+ if (enabled_cpus >= NR_CPUS) {
+ pr_warn("NR_CPUS limit of %d reached, Processor %d/0x%llx ignored.\n",
+ NR_CPUS, total_cpus, mpidr);
+ return -EINVAL;
+ }
+
+ /* No need to check duplicate MPIDRs for the first CPU */
+ if (enabled_cpus) {
+ /*
+ * Duplicate MPIDRs are a recipe for disaster. Scan
+ * all initialized entries and check for
+ * duplicates. If any is found just ignore the CPU.
+ */
+ for_each_possible_cpu(cpu) {
+ if (cpu_logical_map(cpu) == mpidr) {
+ pr_err("Firmware bug, duplicate CPU MPIDR: 0x%llx in MADT\n",
+ mpidr);
+ return -EINVAL;
+ }
+ }
+
+ /* allocate a logical cpu id for the new comer */
+ cpu = cpumask_next_zero(-1, cpu_possible_mask);
+ } else {
+ /*
+ * First GICC entry must be BSP as ACPI spec said
+ * in section 5.2.12.15
+ */
+ if (cpu_logical_map(0) != mpidr) {
+ pr_err("First GICC entry with MPIDR 0x%llx is not BSP\n",
+ mpidr);
+ return -EINVAL;
+ }
+
+ /*
+ * boot_cpu_init() already hold bit 0 in cpu_present_mask
+ * for BSP, no need to allocate again.
+ */
+ cpu = 0;
+ }
+
+ /* CPU 0 was already initialized */
+ if (cpu) {
+ cpu_ops[cpu] = cpu_get_ops(acpi_psci_present() ? "psci" : NULL);
+ if (!cpu_ops[cpu])
+ return -EINVAL;
+
+ if (cpu_ops[cpu]->cpu_init(NULL, cpu))
+ return -EOPNOTSUPP;
+
+ /* map the logical cpu id to cpu MPIDR */
+ cpu_logical_map(cpu) = mpidr;
+
+ set_cpu_possible(cpu, true);
+ } else {
+ /* get cpu0's ops, no need to return if ops is null */
+ cpu_ops[0] = cpu_get_ops(acpi_psci_present() ? "psci" : NULL);
+ }
+
+ enabled_cpus++;
+ return cpu;
+}
+
+static int __init
+acpi_parse_gic_cpu_interface(struct acpi_subtable_header *header,
+ const unsigned long end)
+{
+ struct acpi_madt_generic_interrupt *processor;
+
+ processor = (struct acpi_madt_generic_interrupt *)header;
+
+ if (BAD_MADT_ENTRY(processor, end))
+ return -EINVAL;
+
+ acpi_table_print_madt_entry(header);
+
+ acpi_map_gic_cpu_interface(processor->arm_mpidr & MPIDR_HWID_BITMASK,
+ processor->flags & ACPI_MADT_ENABLED);
+
+ return 0;
+}
+
+/* Parse GIC cpu interface entries in MADT for SMP init */
+void __init acpi_smp_init_cpus(void)
+{
+ int count;
+
+ /*
+ * do a partial walk of MADT to determine how many CPUs
+ * we have including disabled CPUs, and get information
+ * we need for SMP init
+ */
+ count = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
+ acpi_parse_gic_cpu_interface, 0);
+
+ if (!count) {
+ pr_err("No GIC CPU interface entries present\n");
+ return;
+ } else if (count < 0) {
+ pr_err("Error parsing GIC CPU interface entry\n");
+ return;
+ }
+
+ /* Make boot-up look pretty */
+ pr_info("%d CPUs enabled, %d CPUs total\n", enabled_cpus, total_cpus);
+}
+
static int __init acpi_parse_fadt(struct acpi_table_header *table)
{
struct acpi_table_fadt *fadt = (struct acpi_table_fadt *)table;
@@ -62,8 +196,20 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
* to get arm boot flags, or we will disable ACPI.
*/
if (table->revision > 5 ||
- (table->revision == 5 && fadt->minor_revision >= 1))
- return 0;
+ (table->revision == 5 && fadt->minor_revision >= 1)) {
+ /*
+ * ACPI 5.1 only has two explicit methods to boot up SMP,
+ * PSCI and Parking protocol, but the Parking protocol is
+ * only specified for ARMv7 now, so make PSCI as the only
+ * way for the SMP boot protocol before some updates for
+ * the ACPI spec or the Parking protocol spec.
+ */
+ if (acpi_psci_present())
+ return 0;
+
+ pr_warn("No PSCI support, will not bring up secondary CPUs\n");
+ return -EOPNOTSUPP;
+ }

pr_warn("Unsupported FADT revision %d.%d, should be 5.1+, will disable ACPI\n",
table->revision, fadt->minor_revision);
diff --git a/arch/arm64/kernel/cpu_ops.c b/arch/arm64/kernel/cpu_ops.c
index cce9524..1a04deb 100644
--- a/arch/arm64/kernel/cpu_ops.c
+++ b/arch/arm64/kernel/cpu_ops.c
@@ -27,7 +27,7 @@ extern const struct cpu_operations cpu_psci_ops;

const struct cpu_operations *cpu_ops[NR_CPUS];

-static const struct cpu_operations *supported_cpu_ops[] __initconst = {
+static const struct cpu_operations *supported_cpu_ops[] = {
#ifdef CONFIG_SMP
&smp_spin_table_ops,
#endif
@@ -35,7 +35,7 @@ static const struct cpu_operations *supported_cpu_ops[] __initconst = {
NULL,
};

-static const struct cpu_operations * __init cpu_get_ops(const char *name)
+const struct cpu_operations *cpu_get_ops(const char *name)
{
const struct cpu_operations **ops = supported_cpu_ops;

diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index d448d6a..eb00f01 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -404,13 +404,16 @@ void __init setup_arch(char **cmdline_p)
if (acpi_disabled) {
unflatten_device_tree();
psci_dt_init();
+ cpu_read_bootcpu_ops();
+#ifdef CONFIG_SMP
+ of_smp_init_cpus();
+#endif
} else {
psci_acpi_init();
+ acpi_smp_init_cpus();
}

- cpu_read_bootcpu_ops();
#ifdef CONFIG_SMP
- smp_init_cpus();
smp_build_mpidr_hash();
#endif

diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index 4743397..4e390ac 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -321,7 +321,7 @@ void __init smp_prepare_boot_cpu(void)
* cpu logical map array containing MPIDR values related to logical
* cpus. Assumes that cpu_logical_map(0) has already been initialized.
*/
-void __init smp_init_cpus(void)
+void __init of_smp_init_cpus(void)
{
struct device_node *dn = NULL;
unsigned int i, cpu = 1;
--
1.7.9.5

2014-10-17 13:40:13

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 12/18] ACPI / processor: Make it possible to get CPU hardware ID via GICC

Introduce a new function map_gicc_mpidr() to allow MPIDRs to be obtained
from the GICC Structure introduced by ACPI 5.1.

MPIDR is the CPU hardware ID as local APIC ID on x86 platform, so we use
MPIDR not the GIC CPU interface ID to identify CPUs.

Signed-off-by: Hanjun Guo <[email protected]>
---
arch/arm64/include/asm/acpi.h | 29 +++++++++++++++++++++++++++++
arch/arm64/kernel/acpi.c | 1 -
drivers/acpi/processor_core.c | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
index c82d4a1..483ff45 100644
--- a/arch/arm64/include/asm/acpi.h
+++ b/arch/arm64/include/asm/acpi.h
@@ -12,6 +12,8 @@
#ifndef _ASM_ACPI_H
#define _ASM_ACPI_H

+#include <asm/smp_plat.h>
+
/* Basic configuration for ACPI */
#ifdef CONFIG_ACPI
#define acpi_strict 1 /* No out-of-spec workarounds on ARM64 */
@@ -45,6 +47,33 @@ static inline void enable_acpi(void)
acpi_noirq = 0;
}

+/* MPIDR value provided in GICC structure is 64 bits, but the
+ * existing apic_id (CPU hardware ID) using in acpi processor
+ * driver is 32-bit, to conform to the same datatype we need
+ * to repack the GICC structure MPIDR.
+ *
+ * Only 32 bits of MPIDR are used:
+ *
+ * Bits [0:7] Aff0;
+ * Bits [8:15] Aff1;
+ * Bits [16:23] Aff2;
+ * Bits [32:39] Aff3;
+ */
+static inline u32 pack_mpidr(u64 mpidr)
+{
+ return (u32) ((mpidr & 0xff00000000) >> 8) | mpidr;
+}
+
+/*
+ * The ACPI processor driver for ACPI core code needs this macro
+ * to find out this cpu was already mapped (mapping from CPU hardware
+ * ID to CPU logical ID) or not.
+ *
+ * cpu_logical_map(cpu) is the mapping of MPIDR and the logical cpu,
+ * and MPIDR is the cpu hardware ID we needed to pack.
+ */
+#define cpu_physical_id(cpu) pack_mpidr(cpu_logical_map(cpu))
+
/*
* It's used from ACPI core in kdump to boot UP system with SMP kernel,
* with this check the ACPI core will not override the CPU index
diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
index 34837e0..e91ec76 100644
--- a/arch/arm64/kernel/acpi.c
+++ b/arch/arm64/kernel/acpi.c
@@ -24,7 +24,6 @@
#include <linux/bootmem.h>
#include <linux/smp.h>

-#include <asm/smp_plat.h>
#include <asm/cputype.h>
#include <asm/cpu_ops.h>

diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index e32321c..4007313 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -64,6 +64,38 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,
return 0;
}

+/*
+ * On ARM platform, MPIDR value is the hardware ID as apic ID
+ * on Intel platforms
+ */
+static int map_gicc_mpidr(struct acpi_subtable_header *entry,
+ int device_declaration, u32 acpi_id, int *mpidr)
+{
+ struct acpi_madt_generic_interrupt *gicc =
+ container_of(entry, struct acpi_madt_generic_interrupt, header);
+
+ if (!(gicc->flags & ACPI_MADT_ENABLED))
+ return -ENODEV;
+
+ /* In the GIC interrupt model, logical processors are
+ * required to have a Processor Device object in the DSDT,
+ * so we should check device_declaration here
+ */
+ if (device_declaration && (gicc->uid == acpi_id)) {
+ /*
+ * Only bits [0:7] Aff0, bits [8:15] Aff1, bits [16:23] Aff2
+ * and bits [32:39] Aff3 are meaningful, so pack the Affx
+ * fields into a single 32 bit identifier to accommodate the
+ * acpi processor drivers.
+ */
+ *mpidr = ((gicc->arm_mpidr & 0xff00000000) >> 8)
+ | gicc->arm_mpidr;
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
static int map_madt_entry(int type, u32 acpi_id)
{
unsigned long madt_end, entry;
@@ -99,6 +131,9 @@ static int map_madt_entry(int type, u32 acpi_id)
} else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
if (!map_lsapic_id(header, type, acpi_id, &apic_id))
break;
+ } else if (header->type == ACPI_MADT_TYPE_GENERIC_INTERRUPT) {
+ if (!map_gicc_mpidr(header, type, acpi_id, &apic_id))
+ break;
}
entry += header->length;
}
@@ -131,6 +166,8 @@ static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
map_lsapic_id(header, type, acpi_id, &apic_id);
} else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) {
map_x2apic_id(header, type, acpi_id, &apic_id);
+ } else if (header->type == ACPI_MADT_TYPE_GENERIC_INTERRUPT) {
+ map_gicc_mpidr(header, type, acpi_id, &apic_id);
}

exit:
--
1.7.9.5

2014-10-17 13:40:24

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 13/18] ARM64 / ACPI: Introduce ACPI_IRQ_MODEL_GIC and register device's gsi

Introduce ACPI_IRQ_MODEL_GIC which is needed for ARM64 as GIC is
used, and then register device's gsi with the core IRQ subsystem.

acpi_register_gsi() is similar to DT based irq_of_parse_and_map(),
since gsi is unique in the system, so use hwirq number directly
for the mapping.

Originally-by: Amit Daniel Kachhap <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
arch/arm64/kernel/acpi.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++
drivers/acpi/bus.c | 3 ++
include/linux/acpi.h | 1 +
3 files changed, 77 insertions(+)

diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
index e91ec76..8526569 100644
--- a/arch/arm64/kernel/acpi.c
+++ b/arch/arm64/kernel/acpi.c
@@ -37,6 +37,12 @@ EXPORT_SYMBOL(acpi_pci_disabled);
static int enabled_cpus; /* Processors (GICC) with enabled flag in MADT */

/*
+ * Since we're on ARM, the default interrupt routing model
+ * clearly has to be GIC.
+ */
+enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_GIC;
+
+/*
* __acpi_map_table() will be called before page_init(), so early_ioremap()
* or early_memremap() should be called here to for ACPI table mapping.
*/
@@ -184,6 +190,73 @@ void __init acpi_smp_init_cpus(void)
pr_info("%d CPUs enabled, %d CPUs total\n", enabled_cpus, total_cpus);
}

+int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
+{
+ *irq = irq_find_mapping(NULL, gsi);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(acpi_gsi_to_irq);
+
+/*
+ * success: return IRQ number (>0)
+ * failure: return =< 0
+ */
+int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
+{
+ unsigned int irq;
+ unsigned int irq_type;
+
+ /*
+ * ACPI have no bindings to indicate SPI or PPI, so we
+ * use different mappings from DT in ACPI.
+ *
+ * For FDT
+ * PPI interrupt: in the range [0, 15];
+ * SPI interrupt: in the range [0, 987];
+ *
+ * For ACPI, GSI should be unique so using
+ * the hwirq directly for the mapping:
+ * PPI interrupt: in the range [16, 31];
+ * SPI interrupt: in the range [32, 1019];
+ */
+
+ if (trigger == ACPI_EDGE_SENSITIVE &&
+ polarity == ACPI_ACTIVE_LOW)
+ irq_type = IRQ_TYPE_EDGE_FALLING;
+ else if (trigger == ACPI_EDGE_SENSITIVE &&
+ polarity == ACPI_ACTIVE_HIGH)
+ irq_type = IRQ_TYPE_EDGE_RISING;
+ else if (trigger == ACPI_LEVEL_SENSITIVE &&
+ polarity == ACPI_ACTIVE_LOW)
+ irq_type = IRQ_TYPE_LEVEL_LOW;
+ else if (trigger == ACPI_LEVEL_SENSITIVE &&
+ polarity == ACPI_ACTIVE_HIGH)
+ irq_type = IRQ_TYPE_LEVEL_HIGH;
+ else
+ irq_type = IRQ_TYPE_NONE;
+
+ /*
+ * Since only one GIC is supported in ACPI 5.0, we can
+ * create mapping refer to the default domain
+ */
+ irq = irq_create_mapping(NULL, gsi);
+ if (!irq)
+ return irq;
+
+ /* Set irq type if specified and different than the current one */
+ if (irq_type != IRQ_TYPE_NONE &&
+ irq_type != irq_get_trigger_type(irq))
+ irq_set_irq_type(irq, irq_type);
+ return irq;
+}
+EXPORT_SYMBOL_GPL(acpi_register_gsi);
+
+void acpi_unregister_gsi(u32 gsi)
+{
+}
+EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
+
static int __init acpi_parse_fadt(struct acpi_table_header *table)
{
struct acpi_table_fadt *fadt = (struct acpi_table_fadt *)table;
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 8581f5b..d132c1b 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -458,6 +458,9 @@ static int __init acpi_bus_init_irq(void)
case ACPI_IRQ_MODEL_IOSAPIC:
message = "IOSAPIC";
break;
+ case ACPI_IRQ_MODEL_GIC:
+ message = "GIC";
+ break;
case ACPI_IRQ_MODEL_PLATFORM:
message = "platform specific model";
break;
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 36d5012..4615eb1 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -71,6 +71,7 @@ enum acpi_irq_model_id {
ACPI_IRQ_MODEL_IOAPIC,
ACPI_IRQ_MODEL_IOSAPIC,
ACPI_IRQ_MODEL_PLATFORM,
+ ACPI_IRQ_MODEL_GIC,
ACPI_IRQ_MODEL_COUNT
};

--
1.7.9.5

2014-10-17 13:40:34

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 14/18] ARM64 / ACPI: Add GICv2 specific ACPI boot support

From: Tomasz Nowicki <[email protected]>

ACPI kernel uses MADT table for proper GIC initialization. It needs to
parse GIC related subtables, collect CPU interface and distributor
addresses and call driver initialization function (which is hardware
abstraction agnostic). In a similar way, FDT initialize GICv1/2.

NOTE: This commit allow to initialize GICv1/2 basic functionality.
GICv2 vitalization extension, GICv3/4 and ITS are considered as next
steps.

Signed-off-by: Tomasz Nowicki <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
arch/arm64/kernel/acpi.c | 23 ++++++++
drivers/irqchip/irq-gic.c | 106 ++++++++++++++++++++++++++++++++++
drivers/irqchip/irqchip.c | 3 +
include/linux/irqchip/arm-gic-acpi.h | 31 ++++++++++
4 files changed, 163 insertions(+)
create mode 100644 include/linux/irqchip/arm-gic-acpi.h

diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
index 8526569..2c8afe8 100644
--- a/arch/arm64/kernel/acpi.c
+++ b/arch/arm64/kernel/acpi.c
@@ -23,6 +23,7 @@
#include <linux/irqdomain.h>
#include <linux/bootmem.h>
#include <linux/smp.h>
+#include <linux/irqchip/arm-gic-acpi.h>

#include <asm/cputype.h>
#include <asm/cpu_ops.h>
@@ -315,6 +316,28 @@ void __init acpi_boot_table_init(void)
pr_err("Can't find FADT or error happened during parsing FADT\n");
}

+void __init acpi_gic_init(void)
+{
+ struct acpi_table_header *table;
+ acpi_status status;
+ acpi_size tbl_size;
+ int err;
+
+ status = acpi_get_table_with_size(ACPI_SIG_MADT, 0, &table, &tbl_size);
+ if (ACPI_FAILURE(status)) {
+ const char *msg = acpi_format_exception(status);
+
+ pr_err("Failed to get MADT table, %s\n", msg);
+ return;
+ }
+
+ err = gic_v2_acpi_init(table);
+ if (err)
+ pr_err("Failed to initialize GIC IRQ controller");
+
+ early_acpi_os_unmap_memory((char *)table, tbl_size);
+}
+
static int __init parse_acpi(char *arg)
{
if (!arg)
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index 4b959e6..8aba096 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -33,12 +33,14 @@
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
+#include <linux/acpi.h>
#include <linux/irqdomain.h>
#include <linux/interrupt.h>
#include <linux/percpu.h>
#include <linux/slab.h>
#include <linux/irqchip/chained_irq.h>
#include <linux/irqchip/arm-gic.h>
+#include <linux/irqchip/arm-gic-acpi.h>

#include <asm/cputype.h>
#include <asm/irq.h>
@@ -1029,3 +1031,107 @@ IRQCHIP_DECLARE(msm_8660_qgic, "qcom,msm-8660-qgic", gic_of_init);
IRQCHIP_DECLARE(msm_qgic2, "qcom,msm-qgic2", gic_of_init);

#endif
+
+#ifdef CONFIG_ACPI
+static phys_addr_t dist_phy_base, cpu_phy_base;
+static int cpu_base_assigned;
+
+static int __init
+gic_acpi_parse_madt_cpu(struct acpi_subtable_header *header,
+ const unsigned long end)
+{
+ struct acpi_madt_generic_interrupt *processor;
+ phys_addr_t gic_cpu_base;
+
+ processor = (struct acpi_madt_generic_interrupt *)header;
+
+ if (BAD_MADT_ENTRY(processor, end))
+ return -EINVAL;
+
+ /*
+ * There is no support for non-banked GICv1/2 register in ACPI spec.
+ * All CPU interface addresses have to be the same.
+ */
+ gic_cpu_base = processor->base_address;
+ if (cpu_base_assigned && gic_cpu_base != cpu_phy_base)
+ return -EFAULT;
+
+ cpu_phy_base = gic_cpu_base;
+ cpu_base_assigned = 1;
+ return 0;
+}
+
+static int __init
+gic_acpi_parse_madt_distributor(struct acpi_subtable_header *header,
+ const unsigned long end)
+{
+ struct acpi_madt_generic_distributor *dist;
+
+ dist = (struct acpi_madt_generic_distributor *)header;
+
+ if (BAD_MADT_ENTRY(dist, end))
+ return -EINVAL;
+
+ dist_phy_base = dist->base_address;
+ return 0;
+}
+
+int __init
+gic_v2_acpi_init(struct acpi_table_header *table)
+{
+ void __iomem *cpu_base, *dist_base;
+ int count;
+
+ /* Collect CPU base addresses */
+ count = acpi_parse_entries(sizeof(struct acpi_table_madt),
+ gic_acpi_parse_madt_cpu, table,
+ ACPI_MADT_TYPE_GENERIC_INTERRUPT, 0);
+ if (count < 0) {
+ pr_err("Error during GICC entries parsing\n");
+ return -EFAULT;
+ } else if (!count) {
+ pr_err("No valid GICC entries exist\n");
+ return -EINVAL;
+ }
+
+ /*
+ * Find distributor base address. We expect one distributor entry since
+ * ACPI 5.1 spec neither support multi-GIC instances nor GIC cascade.
+ */
+ count = acpi_parse_entries(sizeof(struct acpi_table_madt),
+ gic_acpi_parse_madt_distributor, table,
+ ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR, 0);
+ if (count <= 0) {
+ pr_err("Error during GICD entries parsing\n");
+ return -EFAULT;
+ } else if (!count) {
+ pr_err("No valid GICD entries exist\n");
+ return -EINVAL;
+ } else if (count > 1) {
+ pr_err("More than one GICD entry detected\n");
+ return -EINVAL;
+ }
+
+ cpu_base = ioremap(cpu_phy_base, ACPI_GIC_CPU_IF_MEM_SIZE);
+ if (!cpu_base) {
+ pr_err("Unable to map GICC registers\n");
+ return -ENOMEM;
+ }
+
+ dist_base = ioremap(dist_phy_base, ACPI_GICV2_DIST_MEM_SIZE);
+ if (!dist_base) {
+ pr_err("Unable to map GICD registers\n");
+ iounmap(cpu_base);
+ return -ENOMEM;
+ }
+
+ /*
+ * Initialize zero GIC instance (no multi-GIC support). Also, set GIC
+ * as default IRQ domain to allow for GSI registration and GSI to IRQ
+ * number translation (see acpi_register_gsi() and acpi_gsi_to_irq()).
+ */
+ gic_init_bases(0, -1, dist_base, cpu_base, 0, NULL);
+ irq_set_default_host(gic_data[0].domain);
+ return 0;
+}
+#endif
diff --git a/drivers/irqchip/irqchip.c b/drivers/irqchip/irqchip.c
index 0fe2f71..9106c6d 100644
--- a/drivers/irqchip/irqchip.c
+++ b/drivers/irqchip/irqchip.c
@@ -11,6 +11,7 @@
#include <linux/init.h>
#include <linux/of_irq.h>
#include <linux/irqchip.h>
+#include <linux/irqchip/arm-gic-acpi.h>

/*
* This special of_device_id is the sentinel at the end of the
@@ -26,4 +27,6 @@ extern struct of_device_id __irqchip_of_table[];
void __init irqchip_init(void)
{
of_irq_init(__irqchip_of_table);
+
+ acpi_gic_init();
}
diff --git a/include/linux/irqchip/arm-gic-acpi.h b/include/linux/irqchip/arm-gic-acpi.h
new file mode 100644
index 0000000..ad5b577
--- /dev/null
+++ b/include/linux/irqchip/arm-gic-acpi.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014, Linaro Ltd.
+ * Author: Tomasz Nowicki <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef ARM_GIC_ACPI_H_
+#define ARM_GIC_ACPI_H_
+
+#ifdef CONFIG_ACPI
+
+/*
+ * Hard code here, we can not get memory size from MADT (but FDT does),
+ * Actually no need to do that, because this size can be inferred
+ * from GIC spec.
+ */
+#define ACPI_GICV2_DIST_MEM_SIZE (SZ_4K)
+#define ACPI_GIC_CPU_IF_MEM_SIZE (SZ_8K)
+
+struct acpi_table_header;
+
+void acpi_gic_init(void);
+int gic_v2_acpi_init(struct acpi_table_header *table);
+#else
+static inline void acpi_gic_init(void) { }
+#endif
+
+#endif /* ARM_GIC_ACPI_H_ */
--
1.7.9.5

2014-10-17 13:40:46

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 15/18] ARM64 / ACPI: Parse GTDT to initialize arch timer

Using the information presented by GTDT to initialize the arch
timer (not memory-mapped).

Originally-by: Amit Daniel Kachhap <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
arch/arm64/kernel/time.c | 7 ++
drivers/clocksource/arm_arch_timer.c | 117 ++++++++++++++++++++++++++++------
include/linux/clocksource.h | 6 ++
3 files changed, 111 insertions(+), 19 deletions(-)

diff --git a/arch/arm64/kernel/time.c b/arch/arm64/kernel/time.c
index 1a7125c..42f9195 100644
--- a/arch/arm64/kernel/time.c
+++ b/arch/arm64/kernel/time.c
@@ -35,6 +35,7 @@
#include <linux/delay.h>
#include <linux/clocksource.h>
#include <linux/clk-provider.h>
+#include <linux/acpi.h>

#include <clocksource/arm_arch_timer.h>

@@ -72,6 +73,12 @@ void __init time_init(void)

tick_setup_hrtimer_broadcast();

+ /*
+ * Since ACPI or FDT will only one be available in the system,
+ * we can use acpi_generic_timer_init() here safely
+ */
+ acpi_generic_timer_init();
+
arch_timer_rate = arch_timer_get_rate();
if (!arch_timer_rate)
panic("Unable to initialise architected timer.\n");
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 5163ec1..397783f 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -21,6 +21,7 @@
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/sched_clock.h>
+#include <linux/acpi.h>

#include <asm/arch_timer.h>
#include <asm/virt.h>
@@ -338,8 +339,12 @@ arch_timer_detect_rate(void __iomem *cntbase, struct device_node *np)
if (arch_timer_rate)
return;

- /* Try to determine the frequency from the device tree or CNTFRQ */
- if (of_property_read_u32(np, "clock-frequency", &arch_timer_rate)) {
+ /*
+ * Try to determine the frequency from the device tree or CNTFRQ,
+ * if ACPI is enabled, get the frequency from CNTFRQ ONLY.
+ */
+ if (!acpi_disabled ||
+ of_property_read_u32(np, "clock-frequency", &arch_timer_rate)) {
if (cntbase)
arch_timer_rate = readl_relaxed(cntbase + CNTFRQ);
else
@@ -635,20 +640,8 @@ static void __init arch_timer_common_init(void)
arch_timer_arch_init();
}

-static void __init arch_timer_init(struct device_node *np)
+static void __init arch_timer_init(void)
{
- int i;
-
- if (arch_timers_present & ARCH_CP15_TIMER) {
- pr_warn("arch_timer: multiple nodes in dt, skipping\n");
- return;
- }
-
- arch_timers_present |= ARCH_CP15_TIMER;
- for (i = PHYS_SECURE_PPI; i < MAX_TIMER_PPI; i++)
- arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
- arch_timer_detect_rate(NULL, np);
-
/*
* If HYP mode is available, we know that the physical timer
* has been configured to be accessible from PL1. Use it, so
@@ -667,13 +660,31 @@ static void __init arch_timer_init(struct device_node *np)
}
}

- arch_timer_c3stop = !of_property_read_bool(np, "always-on");
-
arch_timer_register();
arch_timer_common_init();
}
-CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_init);
-CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_init);
+
+static void __init arch_timer_of_init(struct device_node *np)
+{
+ int i;
+
+ if (arch_timers_present & ARCH_CP15_TIMER) {
+ pr_warn("arch_timer: multiple nodes in dt, skipping\n");
+ return;
+ }
+
+ arch_timers_present |= ARCH_CP15_TIMER;
+ for (i = PHYS_SECURE_PPI; i < MAX_TIMER_PPI; i++)
+ arch_timer_ppi[i] = irq_of_parse_and_map(np, i);
+
+ arch_timer_detect_rate(NULL, np);
+
+ arch_timer_c3stop = !of_property_read_bool(np, "always-on");
+
+ arch_timer_init();
+}
+CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init);
+CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init);

static void __init arch_timer_mem_init(struct device_node *np)
{
@@ -740,3 +751,71 @@ static void __init arch_timer_mem_init(struct device_node *np)
}
CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
arch_timer_mem_init);
+
+#ifdef CONFIG_ACPI
+static int __init
+map_generic_timer_interrupt(u32 interrupt, u32 flags)
+{
+ int trigger, polarity;
+
+ if (!interrupt)
+ return 0;
+
+ trigger = (flags & ACPI_GTDT_INTERRUPT_MODE) ? ACPI_EDGE_SENSITIVE
+ : ACPI_LEVEL_SENSITIVE;
+
+ polarity = (flags & ACPI_GTDT_INTERRUPT_POLARITY) ? ACPI_ACTIVE_LOW
+ : ACPI_ACTIVE_HIGH;
+
+ return acpi_register_gsi(NULL, interrupt, trigger, polarity);
+}
+
+/* Initialize per-processor generic timer */
+static int __init arch_timer_acpi_init(struct acpi_table_header *table)
+{
+ struct acpi_table_gtdt *gtdt;
+
+ if (arch_timers_present & ARCH_CP15_TIMER) {
+ pr_warn("arch_timer: already initialized, skipping\n");
+ return -EINVAL;
+ }
+
+ gtdt = container_of(table, struct acpi_table_gtdt, header);
+
+ arch_timers_present |= ARCH_CP15_TIMER;
+
+ arch_timer_ppi[PHYS_SECURE_PPI] =
+ map_generic_timer_interrupt(gtdt->secure_el1_interrupt,
+ gtdt->secure_el1_flags);
+
+ arch_timer_ppi[PHYS_NONSECURE_PPI] =
+ map_generic_timer_interrupt(gtdt->non_secure_el1_interrupt,
+ gtdt->non_secure_el1_flags);
+
+ arch_timer_ppi[VIRT_PPI] =
+ map_generic_timer_interrupt(gtdt->virtual_timer_interrupt,
+ gtdt->virtual_timer_flags);
+
+ arch_timer_ppi[HYP_PPI] =
+ map_generic_timer_interrupt(gtdt->non_secure_el2_interrupt,
+ gtdt->non_secure_el2_flags);
+
+ /* Get the frequency from CNTFRQ */
+ arch_timer_detect_rate(NULL, NULL);
+
+ /* Always-on capability */
+ arch_timer_c3stop = !(gtdt->non_secure_el1_flags & ACPI_GTDT_ALWAYS_ON);
+
+ arch_timer_init();
+ return 0;
+}
+
+/* Initialize all the generic timers presented in GTDT */
+void __init acpi_generic_timer_init(void)
+{
+ if (acpi_disabled)
+ return;
+
+ acpi_table_parse(ACPI_SIG_GTDT, arch_timer_acpi_init);
+}
+#endif
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 653f0e2..5839f98 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -346,4 +346,10 @@ extern void clocksource_of_init(void);
static inline void clocksource_of_init(void) {}
#endif

+#ifdef CONFIG_ACPI
+void acpi_generic_timer_init(void);
+#else
+static inline void acpi_generic_timer_init(void) {}
+#endif
+
#endif /* _LINUX_CLOCKSOURCE_H */
--
1.7.9.5

2014-10-17 13:40:58

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 16/18] ARM64 / ACPI: Select ACPI_REDUCED_HARDWARE_ONLY if ACPI is enabled on ARM64

From: Al Stone <[email protected]>

ACPI reduced hardware mode is disabled by default, but ARM64
can only run properly in ACPI hardware reduced mode, so select
ACPI_REDUCED_HARDWARE_ONLY if ACPI is enabled on ARM64.

Reviewed-by: Grant Likely <[email protected]>
Signed-off-by: Al Stone <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
arch/arm64/Kconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index fd4e81a..065438c 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -1,5 +1,6 @@
config ARM64
def_bool y
+ select ACPI_REDUCED_HARDWARE_ONLY if ACPI
select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
select ARCH_HAS_SG_CHAIN
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
--
1.7.9.5

2014-10-17 13:41:12

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 17/18] ARM64 / ACPI: Enable ARM64 in Kconfig

From: Graeme Gregory <[email protected]>

Add Kconfigs to build ACPI on ARM64, and make ACPI available on ARM64.

acpi_idle driver is x86/IA64 dependent now, so make CONFIG_ACPI_PROCESSOR
depend on X86 || IA64, and implement it on ARM64 in the future.

Reviewed-by: Grant Likely <[email protected]>
Signed-off-by: Graeme Gregory <[email protected]>
Signed-off-by: Al Stone <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
arch/arm64/Kconfig | 2 ++
drivers/acpi/Kconfig | 6 +++---
2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 065438c..8dabaeb 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -422,6 +422,8 @@ source "drivers/Kconfig"

source "drivers/firmware/Kconfig"

+source "drivers/acpi/Kconfig"
+
source "fs/Kconfig"

source "arch/arm64/kvm/Kconfig"
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index d0f3265..f935d2e 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -5,8 +5,7 @@
menuconfig ACPI
bool "ACPI (Advanced Configuration and Power Interface) Support"
depends on !IA64_HP_SIM
- depends on IA64 || X86
- depends on PCI
+ depends on ((IA64 || X86) && PCI) || (ARM64 && EXPERT)
select PNP
default y
help
@@ -163,6 +162,7 @@ config ACPI_PROCESSOR
tristate "Processor"
select THERMAL
select CPU_IDLE
+ depends on X86 || IA64
default y
help
This driver installs ACPI as the idle handler for Linux and uses
@@ -263,7 +263,7 @@ config ACPI_DEBUG

config ACPI_PCI_SLOT
bool "PCI slot detection driver"
- depends on SYSFS
+ depends on SYSFS && PCI
default n
help
This driver creates entries in /sys/bus/pci/slots/ for all PCI
--
1.7.9.5

2014-10-17 13:41:21

by Hanjun Guo

[permalink] [raw]
Subject: [PATCH v5 18/18] Documentation: ACPI for ARM64

From: Graeme Gregory <[email protected]>

Add documentation for the guidelines of how to use ACPI
on ARM64.

Signed-off-by: Graeme Gregory <[email protected]>
Signed-off-by: Al Stone <[email protected]>
Signed-off-by: Hanjun Guo <[email protected]>
---
Documentation/arm64/arm-acpi.txt | 323 ++++++++++++++++++++++++++++++++++++++
1 file changed, 323 insertions(+)
create mode 100644 Documentation/arm64/arm-acpi.txt

diff --git a/Documentation/arm64/arm-acpi.txt b/Documentation/arm64/arm-acpi.txt
new file mode 100644
index 0000000..17cf96d
--- /dev/null
+++ b/Documentation/arm64/arm-acpi.txt
@@ -0,0 +1,323 @@
+ACPI on ARMv8 Servers
+---------------------
+ACPI can be used for ARMv8 general purpose servers designed to follow
+the ARM SBSA (Server Base System Architecture) specification, currently
+available to those with an ARM login at http://silver.arm.com.
+
+The ARMv8 kernel implements the reduced hardware model of ACPI version
+5.1 and its corresponding errata. Links to the specification and all
+external documents it refers to are managed by the UEFI Forum. The
+specification is available at http://www.uefi.org/specifications and
+external documents can be found via http://www.uefi.org/acpi.
+
+If an ARMv8 system does not meet the requirements of the SBSA, or cannot
+be described using the mechanisms defined in the required ACPI specifications,
+then it is likely that Device Tree (DT) is more suitable than ACPI for the
+hardware.
+
+
+Relationship with Device Tree
+-----------------------------
+ACPI support in drivers and subsystems for ARMv8 should never be mutually
+exclusive with DT support at compile time.
+
+At boot time the kernel will only use one description method depending on
+parameters passed from the bootloader (including kernel bootargs).
+
+Regardless of whether DT or ACPI is used, the kernel must always be capable
+of booting with either scheme (in kernels with both schemes enabled at compile
+time).
+
+When booting using ACPI tables, the /chosen node in DT will still be parsed
+to extract the kernel command line and initrd path. No other section of the
+DT will be used.
+
+
+Booting using ACPI tables
+-------------------------
+The only defined method for passing ACPI tables to the kernel on ARMv8
+is via the UEFI system configuration table.
+
+Processing of ACPI tables may be disabled by passing acpi=off on the kernel
+command line; this is the default behavior. If acpi=force is used, the kernel
+will ONLY use device configuration information contained in the ACPI tables.
+
+In order for the kernel to load and use ACPI tables, the UEFI implementation
+MUST set the ACPI_20_TABLE_GUID to point to the RSDP table (the table with
+the ACPI signature "RSD PTR "). If this pointer is incorrect and acpi=force
+is used, the kernel will disable ACPI and try to use DT to boot.
+
+If the pointer to the RSDP table is correct, the table will be mapped into
+the kernel by the ACPI core, using the address provided by UEFI.
+
+The ACPI core will then locate and map in all other ACPI tables provided by
+using the addresses in the RSDP table to find the XSDT (eXtended System
+Description Table). The XSDT in turn provides the addresses to all other
+ACPI tables provided by the system firmware; the ACPI core will then traverse
+this table and map in the tables listed.
+
+The ACPI core will ignore any provided RSDT (Root System Description Table).
+RSDTs have been deprecated and are ignored on arm64 since they only allow
+for 32-bit addresses.
+
+Further, the ACPI core will only use the 64-bit address fields in the FADT
+(Fixed ACPI Description Table). Any 32-bit address fields in the FADT will
+be ignored on arm64.
+
+Hardware reduced mode (see Section 4.1 of the ACPI 5.1 specification) will
+be enforced by the ACPI core on arm64. Doing so allows the ACPI core to
+run less complex code since it no longer has to provide support for legacy
+hardware from other architectures.
+
+For the ACPI core to operate properly, and in turn provide the information
+the kernel needs to configure devices, it expects to find the following
+tables (all section numbers refer to the ACPI 5.1 specfication):
+
+ -- RSDP (Root System Description Pointer), section 5.2.5
+
+ -- XSDT (eXtended System Description Table), section 5.2.8
+
+ -- FACS (Firmware ACPI Control Structure), section 5.2.10
+
+ -- FADT (Fixed ACPI Description Table), section 5.2.9
+
+ -- DSDT (Differentiated System Description Table), section
+ 5.2.11.1
+
+ -- MADT (Multiple APIC Description Table), section 5.2.12
+
+ -- GTDT (Generic Timer Description Table), section 5.2.24
+
+ -- If PCI is supported, the MCFG (Memory mapped ConFiGuration
+ Table), section 5.2.6, specifically Table 5-31.
+
+If the above tables are not all present, the kernel may or may not be
+able to boot properly since it may not be able to configure all of the
+devices available.
+
+
+ACPI Detection
+--------------
+Drivers should determine their probe() type by checking for a null
+value for ACPI_HANDLE, or checking .of_node, or other information in
+the device structure. This is detailed further in the "Driver
+Recommendations" section.
+
+In non-driver code, if the presence of ACPI needs to be detected at
+runtime, then check the value of acpi_disabled. If CONFIG_ACPI is not
+set, acpi_disabled will always be 1.
+
+
+Device Enumeration
+------------------
+Device descriptions in ACPI should use standard recognized ACPI interfaces.
+These can contain less information than is typically provided via a Device
+Tree description for the same device. This is also one of the reasons that
+ACPI can be useful -- the driver takes into account that it may have less
+detailed information about the device and uses sensible defaults instead.
+If done properly in the driver, the hardware can change and improve over
+time without the driver having to change at all.
+
+Clocks provide an excellent example. In DT, clocks need to be specified
+and the drivers need to take them into account. In ACPI, the assumption
+is that UEFI will leave the device in a reasonable default state, including
+any clock settings. If for some reason the driver needs to change a clock
+value, this can be done in an ACPI method; all the driver needs to do is
+invoke the method and not concern itself with what the method needs to do
+to change the clock. Changing the hardware can then take place over time
+by changing what the ACPI method does, and not the driver.
+
+ACPI drivers should only look at one specific ASL object -- the _DSD object
+-- for device driver parameters (known in DT as "bindings", or "Device
+Properties" in ACPI). Not all DT bindings will be recognized. The UEFI
+Forum provides a mechanism for registering such bindings [URL TBD by ASWG]
+so that they may be used on any operating system supporting ACPI. Device
+properties that have not been registered with the UEFI Forum should not be
+used.
+
+Drivers should look for device properties in the _DSD object ONLY; the _DSD
+object is described in the ACPI specification section 6.2.5, but more
+specifically, use the _DSD Device Properties UUID:
+
+ -- UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301
+
+ -- http://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf)
+
+The kernel has an interface for looking up device properties in a manner
+independent of whether DT or ACPI is being used and that interface should
+be used; it can eliminate some duplication of code paths in driver probing
+functions and discourage divergence between DT bindings and ACPI device
+properties.
+
+ACPI tables are described with a formal language called ASL, the ACPI
+Source Language (section 19 of the specification). This means that there
+are always multiple ways to describe the same thing -- including device
+properties. For example, device properties could use an ASL construct
+that looks like this: Name(KEY0, "value0"). An ACPI device driver would
+then retrieve the value of the property by evaluating the KEY0 object.
+However, using Name() this way has multiple problems: (1) ACPI limits
+names ("KEY0") to four characters unlike DT; (2) there is no industry
+wide registry that maintains a list of names, minimzing re-use; (3)
+there is also no registry for the definition of property values ("value0"),
+again making re-use difficult; and (4) how does one maintain backward
+compatibility as new hardware comes out? The _DSD method was created
+to solve precisely these sorts of problems; Linux drivers should ALWAYS
+use the _DSD method for device properties and nothing else.
+
+The _DSM object (ACPI Section 9.14.1) could also be used for conveying
+device properties to a driver. Linux drivers should only expect it to
+be used if _DSD cannot represent the data required, and there is no way
+to create a new UUID for the _DSD object. Note that there is even less
+regulation of the use of _DSM than there is of _DSD. Drivers that depend
+on the contents of _DSM objects will be more difficult to maintain over
+time because of this.
+
+The _DSD object is a very flexible mechanism in ACPI, as are the registered
+Device Properties. This flexibility allows _DSD to cover more than just the
+generic server case and care should be taken in device drivers not to expect
+it to replicate highly specific embedded behaviour from DT.
+
+Both DT bindings and ACPI device properties for device drivers have review
+processes. Use them. And, before creating new device properties, check to
+be sure that they have not been defined before and either registered in the
+Linux kernel documentation or the UEFI Forum. If the device drivers supports
+ACPI and DT, please make sure the device properties are consistent in both
+places.
+
+
+Programmable Power Control Resources
+------------------------------------
+Programmable power control resources include such resources as voltage/current
+providers (regulators) and clock sources.
+
+The kernel assumes that power control of these resources is represented with
+Power Resource Objects (ACPI section 7.1). The ACPI core will then handle
+correctly enabling and disabling resources as they are needed. In order to
+get that to work, ACPI assumes each device has defined D-states and that these
+can be controlled through the optional ACPI methods _PS0, _PS1, _PS2, and _PS3;
+in ACPI, _PS0 is the method to invoke to turn a device full on, and _PS3 is for
+turning a device full off.
+
+The kernel ACPI code will also assume that the _PS? methods follow the normal
+ACPI rules for such methods:
+
+ -- If either _PS0 or _PS3 is implemented, then the other method must also
+ be implemented.
+
+ -- If a device requires usage or setup of a power resource when on, the ASL
+ should organize that it is allocated/enabled using the _PS0 method.
+
+ -- Resources allocated or enabled in the _PS0 method should be disabled
+ or de-allocated in the _PS3 method.
+
+ -- Firmware will leave the resources in a reasonable state before handing
+ over control to the kernel.
+
+Such code in _PS? methods will of course be very platform specific. But,
+this allows the driver to abstract out the interface for operating the device
+and avoid having to read special non-standard values from ACPI tables. Further,
+abstracting the use of these resources allows the hardware to change over time
+without requiring updates to the driver.
+
+
+Clocks
+------
+ACPI makes the assumption that clocks are initialized by the firmware --
+UEFI, in this case -- to some working value before control is handed over
+to the kernel. This has implications for devices such as UARTs, or SoC
+driven LCD displays, for example.
+
+When the kernel boots, the clock is assumed to be set to reasonable
+working value. If for some reason the frequency needs to change -- e.g.,
+throttling for power management -- the device driver should expect that
+process to be abstracted out into some ACPI method that can be invoked
+(please see the ACPI specification for further recommendations on standard
+methods to be expected). If is not, there is no direct way for ACPI to
+control the clocks.
+
+
+Driver Recommendations
+----------------------
+DO NOT remove any DT handling when adding ACPI support for a driver. The
+same device may be used on many different systems.
+
+DO try to structure the driver so that it is data driven. That is, set up
+a struct containing internal per-device state based on defaults and whatever
+else must be discovered by the driver probe function. Then, have the rest
+of the driver operate off of the contents of that struct. Doing so should
+allow most divergence between ACPI and DT functionality to be kept local to
+the probe function instead of being scattered throughout the driver. For
+example:
+
+static int device_probe_dt(struct platform_device *pdev)
+{
+ /* DT specific functionality */
+ ...
+}
+
+static int device_probe_acpi(struct platform_device *pdev)
+{
+ /* ACPI specific functionality */
+ ...
+}
+
+static int device_probe(stuct platform_device *pdev)
+{
+ ...
+ struct device_node node = pdev->dev.of_node;
+ ...
+
+ if (node)
+ ret = device_probe_dt(pdev);
+ else if (ACPI_HANDLE(&pdev->dev))
+ ret = device_probe_acpi(pdev);
+ else
+ /* other initialization */
+ ...
+ /* Continue with any generic probe operations */
+ ...
+}
+
+DO keep the MODULE_DEVICE_TABLE entries together in the driver to make it
+clear the different names the driver is probed for, both from DT and from
+ACPI:
+
+static struct of_device_id virtio_mmio_match[] = {
+ { .compatible = "virtio,mmio", },
+ { }
+};
+MODULE_DEVICE_TABLE(of, virtio_mmio_match);
+
+static const struct acpi_device_id virtio_mmio_acpi_match[] = {
+ { "LNRO0005", },
+ { }
+};
+MODULE_DEVICE_TABLE(acpi, virtio_mmio_acpi_match);
+
+
+ASWG
+----
+The following areas are not yet fully defined for ARM in the 5.1 version
+of the ACPI specification and are expected to be worked through in the
+UEFI ACPI Specification Working Group (ASWG):
+
+ -- ACPI based CPU topology
+ -- ACPI based Power management
+ -- CPU idle control based on PSCI
+ -- CPU performance control (CPPC)
+ -- ACPI based SMMU
+ -- ITS support for GIC in MADT
+
+Participation in this group is open to all UEFI members. Please see
+http://www.uefi.org/workinggroup for details on group membership.
+
+It is the intent of the ARMv8 ACPI kernel code to follow the ACPI specification
+as closely as possible, and to only implement functionality that complies with
+the released standards from UEFI ASWG. As a practical matter, there will be
+vendors that provide bad ACPI tables or violate the standards in some way.
+If this is because of errors, quirks and fixups may be necessary, but will
+be avoided if possible. If there are features missing from ACPI that preclude
+it from being used on a platform, ECRs (Engineering Change Requests) should be
+submitted to ASWG and go through the normal approval process; for those that
+are not UEFI members, many other members of the Linux community are and would
+likely be willing to assist in submitting ECRs.
--
1.7.9.5

2014-10-24 17:39:35

by Lorenzo Pieralisi

[permalink] [raw]
Subject: Re: [PATCH v5 12/18] ACPI / processor: Make it possible to get CPU hardware ID via GICC

On Fri, Oct 17, 2014 at 02:37:08PM +0100, Hanjun Guo wrote:
> Introduce a new function map_gicc_mpidr() to allow MPIDRs to be obtained
> from the GICC Structure introduced by ACPI 5.1.
>
> MPIDR is the CPU hardware ID as local APIC ID on x86 platform, so we use
> MPIDR not the GIC CPU interface ID to identify CPUs.
>
> Signed-off-by: Hanjun Guo <[email protected]>
> ---
> arch/arm64/include/asm/acpi.h | 29 +++++++++++++++++++++++++++++
> arch/arm64/kernel/acpi.c | 1 -
> drivers/acpi/processor_core.c | 37 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 66 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
> index c82d4a1..483ff45 100644
> --- a/arch/arm64/include/asm/acpi.h
> +++ b/arch/arm64/include/asm/acpi.h
> @@ -12,6 +12,8 @@
> #ifndef _ASM_ACPI_H
> #define _ASM_ACPI_H
>
> +#include <asm/smp_plat.h>
> +
> /* Basic configuration for ACPI */
> #ifdef CONFIG_ACPI
> #define acpi_strict 1 /* No out-of-spec workarounds on ARM64 */
> @@ -45,6 +47,33 @@ static inline void enable_acpi(void)
> acpi_noirq = 0;
> }
>
> +/* MPIDR value provided in GICC structure is 64 bits, but the
> + * existing apic_id (CPU hardware ID) using in acpi processor
> + * driver is 32-bit, to conform to the same datatype we need
> + * to repack the GICC structure MPIDR.
> + *
> + * Only 32 bits of MPIDR are used:
> + *
> + * Bits [0:7] Aff0;
> + * Bits [8:15] Aff1;
> + * Bits [16:23] Aff2;
> + * Bits [32:39] Aff3;
> + */
> +static inline u32 pack_mpidr(u64 mpidr)
> +{
> + return (u32) ((mpidr & 0xff00000000) >> 8) | mpidr;
> +}
> +
> +/*
> + * The ACPI processor driver for ACPI core code needs this macro
> + * to find out this cpu was already mapped (mapping from CPU hardware
> + * ID to CPU logical ID) or not.
> + *
> + * cpu_logical_map(cpu) is the mapping of MPIDR and the logical cpu,
> + * and MPIDR is the cpu hardware ID we needed to pack.
> + */
> +#define cpu_physical_id(cpu) pack_mpidr(cpu_logical_map(cpu))
> +
> /*
> * It's used from ACPI core in kdump to boot UP system with SMP kernel,
> * with this check the ACPI core will not override the CPU index
> diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
> index 34837e0..e91ec76 100644
> --- a/arch/arm64/kernel/acpi.c
> +++ b/arch/arm64/kernel/acpi.c
> @@ -24,7 +24,6 @@
> #include <linux/bootmem.h>
> #include <linux/smp.h>
>
> -#include <asm/smp_plat.h>
> #include <asm/cputype.h>
> #include <asm/cpu_ops.h>
>
> diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
> index e32321c..4007313 100644
> --- a/drivers/acpi/processor_core.c
> +++ b/drivers/acpi/processor_core.c
> @@ -64,6 +64,38 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,
> return 0;
> }
>
> +/*
> + * On ARM platform, MPIDR value is the hardware ID as apic ID
> + * on Intel platforms
> + */
> +static int map_gicc_mpidr(struct acpi_subtable_header *entry,
> + int device_declaration, u32 acpi_id, int *mpidr)
> +{
> + struct acpi_madt_generic_interrupt *gicc =
> + container_of(entry, struct acpi_madt_generic_interrupt, header);
> +
> + if (!(gicc->flags & ACPI_MADT_ENABLED))
> + return -ENODEV;
> +
> + /* In the GIC interrupt model, logical processors are
> + * required to have a Processor Device object in the DSDT,
> + * so we should check device_declaration here
> + */
> + if (device_declaration && (gicc->uid == acpi_id)) {
> + /*
> + * Only bits [0:7] Aff0, bits [8:15] Aff1, bits [16:23] Aff2
> + * and bits [32:39] Aff3 are meaningful, so pack the Affx
> + * fields into a single 32 bit identifier to accommodate the
> + * acpi processor drivers.
> + */
> + *mpidr = ((gicc->arm_mpidr & 0xff00000000) >> 8)
> + | gicc->arm_mpidr;

The simple fact that you define a function to pack the mpidr value and
you can't use it here because this is *generic* code is telling, and
a very bad omen. At the cost of sounding like a broken record, I do not
like this mpidr->apic->logical_cpu song and dance at all.
ACPI is peppered with code (eg hotplug is another example, CPUidle driver
even worse) that is supposed to be generic but contains x86 code to carry
out this cpuid conversion, I really think that in order to start an ARM64
ACPI port properly we should at least try to factor out this physical to
logical cpu id conversion, and it is not the first time that I mention this
on the lists.

I will also talk to Rafael about this at the earliest opportunity, I
guess that x86 code relies on apic-id because some ACPI versions could
not rely on the acpi-id or some other reasons I have to investigate.

Thanks,
Lorenzo

> + return 0;
> + }
> +
> + return -EINVAL;
> +}
> +
> static int map_madt_entry(int type, u32 acpi_id)
> {
> unsigned long madt_end, entry;
> @@ -99,6 +131,9 @@ static int map_madt_entry(int type, u32 acpi_id)
> } else if (header->type == ACPI_MADT_TYPE_LOCAL_SAPIC) {
> if (!map_lsapic_id(header, type, acpi_id, &apic_id))
> break;
> + } else if (header->type == ACPI_MADT_TYPE_GENERIC_INTERRUPT) {
> + if (!map_gicc_mpidr(header, type, acpi_id, &apic_id))
> + break;
> }
> entry += header->length;
> }
> @@ -131,6 +166,8 @@ static int map_mat_entry(acpi_handle handle, int type, u32 acpi_id)
> map_lsapic_id(header, type, acpi_id, &apic_id);
> } else if (header->type == ACPI_MADT_TYPE_LOCAL_X2APIC) {
> map_x2apic_id(header, type, acpi_id, &apic_id);
> + } else if (header->type == ACPI_MADT_TYPE_GENERIC_INTERRUPT) {
> + map_gicc_mpidr(header, type, acpi_id, &apic_id);
> }
>
> exit:
> --
> 1.7.9.5
>
>

2014-10-27 10:00:17

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 12/18] ACPI / processor: Make it possible to get CPU hardware ID via GICC

On 2014-10-25 1:39, Lorenzo Pieralisi wrote:
> On Fri, Oct 17, 2014 at 02:37:08PM +0100, Hanjun Guo wrote:
>> Introduce a new function map_gicc_mpidr() to allow MPIDRs to be obtained
>> from the GICC Structure introduced by ACPI 5.1.
>>
>> MPIDR is the CPU hardware ID as local APIC ID on x86 platform, so we use
>> MPIDR not the GIC CPU interface ID to identify CPUs.
>>
>> Signed-off-by: Hanjun Guo <[email protected]>
>> ---
>> arch/arm64/include/asm/acpi.h | 29 +++++++++++++++++++++++++++++
>> arch/arm64/kernel/acpi.c | 1 -
>> drivers/acpi/processor_core.c | 37 +++++++++++++++++++++++++++++++++++++
>> 3 files changed, 66 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
>> index c82d4a1..483ff45 100644
>> --- a/arch/arm64/include/asm/acpi.h
>> +++ b/arch/arm64/include/asm/acpi.h
>> @@ -12,6 +12,8 @@
>> #ifndef _ASM_ACPI_H
>> #define _ASM_ACPI_H
>>
>> +#include <asm/smp_plat.h>
>> +
>> /* Basic configuration for ACPI */
>> #ifdef CONFIG_ACPI
>> #define acpi_strict 1 /* No out-of-spec workarounds on ARM64 */
>> @@ -45,6 +47,33 @@ static inline void enable_acpi(void)
>> acpi_noirq = 0;
>> }
>>
>> +/* MPIDR value provided in GICC structure is 64 bits, but the
>> + * existing apic_id (CPU hardware ID) using in acpi processor
>> + * driver is 32-bit, to conform to the same datatype we need
>> + * to repack the GICC structure MPIDR.
>> + *
>> + * Only 32 bits of MPIDR are used:
>> + *
>> + * Bits [0:7] Aff0;
>> + * Bits [8:15] Aff1;
>> + * Bits [16:23] Aff2;
>> + * Bits [32:39] Aff3;
>> + */
>> +static inline u32 pack_mpidr(u64 mpidr)
>> +{
>> + return (u32) ((mpidr & 0xff00000000) >> 8) | mpidr;
>> +}
>> +
>> +/*
>> + * The ACPI processor driver for ACPI core code needs this macro
>> + * to find out this cpu was already mapped (mapping from CPU hardware
>> + * ID to CPU logical ID) or not.
>> + *
>> + * cpu_logical_map(cpu) is the mapping of MPIDR and the logical cpu,
>> + * and MPIDR is the cpu hardware ID we needed to pack.
>> + */
>> +#define cpu_physical_id(cpu) pack_mpidr(cpu_logical_map(cpu))
>> +
>> /*
>> * It's used from ACPI core in kdump to boot UP system with SMP kernel,
>> * with this check the ACPI core will not override the CPU index
>> diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
>> index 34837e0..e91ec76 100644
>> --- a/arch/arm64/kernel/acpi.c
>> +++ b/arch/arm64/kernel/acpi.c
>> @@ -24,7 +24,6 @@
>> #include <linux/bootmem.h>
>> #include <linux/smp.h>
>>
>> -#include <asm/smp_plat.h>
>> #include <asm/cputype.h>
>> #include <asm/cpu_ops.h>
>>
>> diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
>> index e32321c..4007313 100644
>> --- a/drivers/acpi/processor_core.c
>> +++ b/drivers/acpi/processor_core.c
>> @@ -64,6 +64,38 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,
>> return 0;
>> }
>>
>> +/*
>> + * On ARM platform, MPIDR value is the hardware ID as apic ID
>> + * on Intel platforms
>> + */
>> +static int map_gicc_mpidr(struct acpi_subtable_header *entry,
>> + int device_declaration, u32 acpi_id, int *mpidr)
>> +{
>> + struct acpi_madt_generic_interrupt *gicc =
>> + container_of(entry, struct acpi_madt_generic_interrupt, header);
>> +
>> + if (!(gicc->flags & ACPI_MADT_ENABLED))
>> + return -ENODEV;
>> +
>> + /* In the GIC interrupt model, logical processors are
>> + * required to have a Processor Device object in the DSDT,
>> + * so we should check device_declaration here
>> + */
>> + if (device_declaration && (gicc->uid == acpi_id)) {
>> + /*
>> + * Only bits [0:7] Aff0, bits [8:15] Aff1, bits [16:23] Aff2
>> + * and bits [32:39] Aff3 are meaningful, so pack the Affx
>> + * fields into a single 32 bit identifier to accommodate the
>> + * acpi processor drivers.
>> + */
>> + *mpidr = ((gicc->arm_mpidr & 0xff00000000) >> 8)
>> + | gicc->arm_mpidr;
>
> The simple fact that you define a function to pack the mpidr value and
> you can't use it here because this is *generic* code is telling, and
> a very bad omen. At the cost of sounding like a broken record, I do not
> like this mpidr->apic->logical_cpu song and dance at all.
> ACPI is peppered with code (eg hotplug is another example, CPUidle driver
> even worse) that is supposed to be generic but contains x86 code to carry
> out this cpuid conversion, I really think that in order to start an ARM64
> ACPI port properly we should at least try to factor out this physical to
> logical cpu id conversion, and it is not the first time that I mention this
> on the lists.

I know, thanks for pointing this out. As I replied in previous version
of this patch set, apic_id is x86/ia64 specific, but the meaning behind
it is not. It means the CPU hardware id to identify itself in the system,
it just like MPIDR on ARM.

I will send out a patch for RFC to convert apic_id to physid which
is generic for all platforms.

>
> I will also talk to Rafael about this at the earliest opportunity, I
> guess that x86 code relies on apic-id because some ACPI versions could
> not rely on the acpi-id or some other reasons I have to investigate.

As ACPI spec (section 8.4, Declaring Processors) said, Each processor
in the system must be declared in the ACPI namespace, so each cpu will
have acpi_id in all ACPI versions, and in theory we can map acpi_id to
logical cpu id if we want to.

But things are complicated, apic_id is connected to many
tables, MADT for smp init, DSDT for device driver, and SRAT for NUMA (there
is no acpi_id in it, ONLY has apic_id in the table for x86/ia64), so if we
want to factor the code to map acpi_id to logical cpu id, we need to modify:

- ACPI drivers;
- SMP init for x86 and ia64
- the mappings for NUMA init for x86 and ia64
that will be lots of work I think.

I'm willing to discuss this further and come out a solution, please
comment on what I said and share your ideas :)

Thanks
Hanjun

2014-10-29 10:43:37

by Lorenzo Pieralisi

[permalink] [raw]
Subject: Re: [PATCH v5 12/18] ACPI / processor: Make it possible to get CPU hardware ID via GICC

On Mon, Oct 27, 2014 at 09:58:10AM +0000, Hanjun Guo wrote:

[...]

> >> +static int map_gicc_mpidr(struct acpi_subtable_header *entry,
> >> + int device_declaration, u32 acpi_id, int *mpidr)
> >> +{
> >> + struct acpi_madt_generic_interrupt *gicc =
> >> + container_of(entry, struct acpi_madt_generic_interrupt, header);
> >> +
> >> + if (!(gicc->flags & ACPI_MADT_ENABLED))
> >> + return -ENODEV;
> >> +
> >> + /* In the GIC interrupt model, logical processors are
> >> + * required to have a Processor Device object in the DSDT,
> >> + * so we should check device_declaration here
> >> + */
> >> + if (device_declaration && (gicc->uid == acpi_id)) {
> >> + /*
> >> + * Only bits [0:7] Aff0, bits [8:15] Aff1, bits [16:23] Aff2
> >> + * and bits [32:39] Aff3 are meaningful, so pack the Affx
> >> + * fields into a single 32 bit identifier to accommodate the
> >> + * acpi processor drivers.
> >> + */
> >> + *mpidr = ((gicc->arm_mpidr & 0xff00000000) >> 8)
> >> + | gicc->arm_mpidr;
> >
> > The simple fact that you define a function to pack the mpidr value and
> > you can't use it here because this is *generic* code is telling, and
> > a very bad omen. At the cost of sounding like a broken record, I do not
> > like this mpidr->apic->logical_cpu song and dance at all.
> > ACPI is peppered with code (eg hotplug is another example, CPUidle driver
> > even worse) that is supposed to be generic but contains x86 code to carry
> > out this cpuid conversion, I really think that in order to start an ARM64
> > ACPI port properly we should at least try to factor out this physical to
> > logical cpu id conversion, and it is not the first time that I mention this
> > on the lists.
>
> I know, thanks for pointing this out. As I replied in previous version
> of this patch set, apic_id is x86/ia64 specific, but the meaning behind
> it is not. It means the CPU hardware id to identify itself in the system,
> it just like MPIDR on ARM.

Yes, except that it is called apic_id.

> I will send out a patch for RFC to convert apic_id to physid which
> is generic for all platforms.

That seems a good idea to sound out if I am the only one having an issue
with the current approach.

> > I will also talk to Rafael about this at the earliest opportunity, I
> > guess that x86 code relies on apic-id because some ACPI versions could
> > not rely on the acpi-id or some other reasons I have to investigate.
>
> As ACPI spec (section 8.4, Declaring Processors) said, Each processor
> in the system must be declared in the ACPI namespace, so each cpu will
> have acpi_id in all ACPI versions, and in theory we can map acpi_id to
> logical cpu id if we want to.
>
> But things are complicated, apic_id is connected to many
> tables, MADT for smp init, DSDT for device driver, and SRAT for NUMA (there
> is no acpi_id in it, ONLY has apic_id in the table for x86/ia64), so if we
> want to factor the code to map acpi_id to logical cpu id, we need to modify:
>
> - ACPI drivers;
> - SMP init for x86 and ia64
> - the mappings for NUMA init for x86 and ia64
> that will be lots of work I think.
>
> I'm willing to discuss this further and come out a solution, please
> comment on what I said and share your ideas :)

Factoring out apic_id to a common cpu_physical_id is ok to me, because
basically that's what you are doing except for the naming. I do not
have any particular preference for the acpi_id, I mentioned that only
as a means to implement a generic cpu_physical_id, arch agnostic.

Drop the RFC you mentioned above please on the list, we will restart debating
from there.

Thanks,
Lorenzo

2014-10-29 21:12:34

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 12/18] ACPI / processor: Make it possible to get CPU hardware ID via GICC

On Monday, October 27, 2014 05:58:10 PM Hanjun Guo wrote:
> On 2014-10-25 1:39, Lorenzo Pieralisi wrote:
> > On Fri, Oct 17, 2014 at 02:37:08PM +0100, Hanjun Guo wrote:
> >> Introduce a new function map_gicc_mpidr() to allow MPIDRs to be obtained
> >> from the GICC Structure introduced by ACPI 5.1.
> >>
> >> MPIDR is the CPU hardware ID as local APIC ID on x86 platform, so we use
> >> MPIDR not the GIC CPU interface ID to identify CPUs.
> >>
> >> Signed-off-by: Hanjun Guo <[email protected]>
> >> ---
> >> arch/arm64/include/asm/acpi.h | 29 +++++++++++++++++++++++++++++
> >> arch/arm64/kernel/acpi.c | 1 -
> >> drivers/acpi/processor_core.c | 37 +++++++++++++++++++++++++++++++++++++
> >> 3 files changed, 66 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
> >> index c82d4a1..483ff45 100644
> >> --- a/arch/arm64/include/asm/acpi.h
> >> +++ b/arch/arm64/include/asm/acpi.h
> >> @@ -12,6 +12,8 @@
> >> #ifndef _ASM_ACPI_H
> >> #define _ASM_ACPI_H
> >>
> >> +#include <asm/smp_plat.h>
> >> +
> >> /* Basic configuration for ACPI */
> >> #ifdef CONFIG_ACPI
> >> #define acpi_strict 1 /* No out-of-spec workarounds on ARM64 */
> >> @@ -45,6 +47,33 @@ static inline void enable_acpi(void)
> >> acpi_noirq = 0;
> >> }
> >>
> >> +/* MPIDR value provided in GICC structure is 64 bits, but the
> >> + * existing apic_id (CPU hardware ID) using in acpi processor
> >> + * driver is 32-bit, to conform to the same datatype we need
> >> + * to repack the GICC structure MPIDR.
> >> + *
> >> + * Only 32 bits of MPIDR are used:
> >> + *
> >> + * Bits [0:7] Aff0;
> >> + * Bits [8:15] Aff1;
> >> + * Bits [16:23] Aff2;
> >> + * Bits [32:39] Aff3;
> >> + */
> >> +static inline u32 pack_mpidr(u64 mpidr)
> >> +{
> >> + return (u32) ((mpidr & 0xff00000000) >> 8) | mpidr;
> >> +}
> >> +
> >> +/*
> >> + * The ACPI processor driver for ACPI core code needs this macro
> >> + * to find out this cpu was already mapped (mapping from CPU hardware
> >> + * ID to CPU logical ID) or not.
> >> + *
> >> + * cpu_logical_map(cpu) is the mapping of MPIDR and the logical cpu,
> >> + * and MPIDR is the cpu hardware ID we needed to pack.
> >> + */
> >> +#define cpu_physical_id(cpu) pack_mpidr(cpu_logical_map(cpu))
> >> +
> >> /*
> >> * It's used from ACPI core in kdump to boot UP system with SMP kernel,
> >> * with this check the ACPI core will not override the CPU index
> >> diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
> >> index 34837e0..e91ec76 100644
> >> --- a/arch/arm64/kernel/acpi.c
> >> +++ b/arch/arm64/kernel/acpi.c
> >> @@ -24,7 +24,6 @@
> >> #include <linux/bootmem.h>
> >> #include <linux/smp.h>
> >>
> >> -#include <asm/smp_plat.h>
> >> #include <asm/cputype.h>
> >> #include <asm/cpu_ops.h>
> >>
> >> diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
> >> index e32321c..4007313 100644
> >> --- a/drivers/acpi/processor_core.c
> >> +++ b/drivers/acpi/processor_core.c
> >> @@ -64,6 +64,38 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,
> >> return 0;
> >> }
> >>
> >> +/*
> >> + * On ARM platform, MPIDR value is the hardware ID as apic ID
> >> + * on Intel platforms
> >> + */
> >> +static int map_gicc_mpidr(struct acpi_subtable_header *entry,
> >> + int device_declaration, u32 acpi_id, int *mpidr)
> >> +{
> >> + struct acpi_madt_generic_interrupt *gicc =
> >> + container_of(entry, struct acpi_madt_generic_interrupt, header);
> >> +
> >> + if (!(gicc->flags & ACPI_MADT_ENABLED))
> >> + return -ENODEV;
> >> +
> >> + /* In the GIC interrupt model, logical processors are
> >> + * required to have a Processor Device object in the DSDT,
> >> + * so we should check device_declaration here
> >> + */
> >> + if (device_declaration && (gicc->uid == acpi_id)) {
> >> + /*
> >> + * Only bits [0:7] Aff0, bits [8:15] Aff1, bits [16:23] Aff2
> >> + * and bits [32:39] Aff3 are meaningful, so pack the Affx
> >> + * fields into a single 32 bit identifier to accommodate the
> >> + * acpi processor drivers.
> >> + */
> >> + *mpidr = ((gicc->arm_mpidr & 0xff00000000) >> 8)
> >> + | gicc->arm_mpidr;
> >
> > The simple fact that you define a function to pack the mpidr value and
> > you can't use it here because this is *generic* code is telling, and
> > a very bad omen. At the cost of sounding like a broken record, I do not
> > like this mpidr->apic->logical_cpu song and dance at all.
> > ACPI is peppered with code (eg hotplug is another example, CPUidle driver
> > even worse) that is supposed to be generic but contains x86 code to carry
> > out this cpuid conversion, I really think that in order to start an ARM64
> > ACPI port properly we should at least try to factor out this physical to
> > logical cpu id conversion, and it is not the first time that I mention this
> > on the lists.
>
> I know, thanks for pointing this out. As I replied in previous version
> of this patch set, apic_id is x86/ia64 specific, but the meaning behind
> it is not. It means the CPU hardware id to identify itself in the system,
> it just like MPIDR on ARM.
>
> I will send out a patch for RFC to convert apic_id to physid which
> is generic for all platforms.
>
> >
> > I will also talk to Rafael about this at the earliest opportunity, I
> > guess that x86 code relies on apic-id because some ACPI versions could
> > not rely on the acpi-id or some other reasons I have to investigate.
>
> As ACPI spec (section 8.4, Declaring Processors) said, Each processor
> in the system must be declared in the ACPI namespace, so each cpu will
> have acpi_id in all ACPI versions, and in theory we can map acpi_id to
> logical cpu id if we want to.
>
> But things are complicated, apic_id is connected to many
> tables, MADT for smp init, DSDT for device driver, and SRAT for NUMA (there
> is no acpi_id in it, ONLY has apic_id in the table for x86/ia64), so if we
> want to factor the code to map acpi_id to logical cpu id, we need to modify:
>
> - ACPI drivers;
> - SMP init for x86 and ia64
> - the mappings for NUMA init for x86 and ia64
> that will be lots of work I think.

And error prone for that matter.

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2014-10-30 08:30:03

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 12/18] ACPI / processor: Make it possible to get CPU hardware ID via GICC

On 2014-10-29 18:43, Lorenzo Pieralisi wrote:
> On Mon, Oct 27, 2014 at 09:58:10AM +0000, Hanjun Guo wrote:
>
> [...]
>
>>>> +static int map_gicc_mpidr(struct acpi_subtable_header *entry,
>>>> + int device_declaration, u32 acpi_id, int *mpidr)
>>>> +{
>>>> + struct acpi_madt_generic_interrupt *gicc =
>>>> + container_of(entry, struct acpi_madt_generic_interrupt, header);
>>>> +
>>>> + if (!(gicc->flags & ACPI_MADT_ENABLED))
>>>> + return -ENODEV;
>>>> +
>>>> + /* In the GIC interrupt model, logical processors are
>>>> + * required to have a Processor Device object in the DSDT,
>>>> + * so we should check device_declaration here
>>>> + */
>>>> + if (device_declaration && (gicc->uid == acpi_id)) {
>>>> + /*
>>>> + * Only bits [0:7] Aff0, bits [8:15] Aff1, bits [16:23] Aff2
>>>> + * and bits [32:39] Aff3 are meaningful, so pack the Affx
>>>> + * fields into a single 32 bit identifier to accommodate the
>>>> + * acpi processor drivers.
>>>> + */
>>>> + *mpidr = ((gicc->arm_mpidr & 0xff00000000) >> 8)
>>>> + | gicc->arm_mpidr;
>>>
>>> The simple fact that you define a function to pack the mpidr value and
>>> you can't use it here because this is *generic* code is telling, and
>>> a very bad omen. At the cost of sounding like a broken record, I do not
>>> like this mpidr->apic->logical_cpu song and dance at all.
>>> ACPI is peppered with code (eg hotplug is another example, CPUidle driver
>>> even worse) that is supposed to be generic but contains x86 code to carry
>>> out this cpuid conversion, I really think that in order to start an ARM64
>>> ACPI port properly we should at least try to factor out this physical to
>>> logical cpu id conversion, and it is not the first time that I mention this
>>> on the lists.
>>
>> I know, thanks for pointing this out. As I replied in previous version
>> of this patch set, apic_id is x86/ia64 specific, but the meaning behind
>> it is not. It means the CPU hardware id to identify itself in the system,
>> it just like MPIDR on ARM.
>
> Yes, except that it is called apic_id.
>
>> I will send out a patch for RFC to convert apic_id to physid which
>> is generic for all platforms.
>
> That seems a good idea to sound out if I am the only one having an issue
> with the current approach.
>
>>> I will also talk to Rafael about this at the earliest opportunity, I
>>> guess that x86 code relies on apic-id because some ACPI versions could
>>> not rely on the acpi-id or some other reasons I have to investigate.
>>
>> As ACPI spec (section 8.4, Declaring Processors) said, Each processor
>> in the system must be declared in the ACPI namespace, so each cpu will
>> have acpi_id in all ACPI versions, and in theory we can map acpi_id to
>> logical cpu id if we want to.
>>
>> But things are complicated, apic_id is connected to many
>> tables, MADT for smp init, DSDT for device driver, and SRAT for NUMA (there
>> is no acpi_id in it, ONLY has apic_id in the table for x86/ia64), so if we
>> want to factor the code to map acpi_id to logical cpu id, we need to modify:
>>
>> - ACPI drivers;
>> - SMP init for x86 and ia64
>> - the mappings for NUMA init for x86 and ia64
>> that will be lots of work I think.
>>
>> I'm willing to discuss this further and come out a solution, please
>> comment on what I said and share your ideas :)
>
> Factoring out apic_id to a common cpu_physical_id is ok to me, because
> basically that's what you are doing except for the naming. I do not
> have any particular preference for the acpi_id, I mentioned that only
> as a means to implement a generic cpu_physical_id, arch agnostic.
>
> Drop the RFC you mentioned above please on the list, we will restart debating
> from there.

Ok, will send out the patch soon.

Thanks
Hanjun

2014-10-30 08:32:40

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 12/18] ACPI / processor: Make it possible to get CPU hardware ID via GICC

On 2014-10-30 5:33, Rafael J. Wysocki wrote:
> On Monday, October 27, 2014 05:58:10 PM Hanjun Guo wrote:
>> On 2014-10-25 1:39, Lorenzo Pieralisi wrote:
>>> On Fri, Oct 17, 2014 at 02:37:08PM +0100, Hanjun Guo wrote:
>>>> Introduce a new function map_gicc_mpidr() to allow MPIDRs to be obtained
>>>> from the GICC Structure introduced by ACPI 5.1.
>>>>
>>>> MPIDR is the CPU hardware ID as local APIC ID on x86 platform, so we use
>>>> MPIDR not the GIC CPU interface ID to identify CPUs.
>>>>
>>>> Signed-off-by: Hanjun Guo <[email protected]>
>>>> ---
>>>> arch/arm64/include/asm/acpi.h | 29 +++++++++++++++++++++++++++++
>>>> arch/arm64/kernel/acpi.c | 1 -
>>>> drivers/acpi/processor_core.c | 37 +++++++++++++++++++++++++++++++++++++
>>>> 3 files changed, 66 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h
>>>> index c82d4a1..483ff45 100644
>>>> --- a/arch/arm64/include/asm/acpi.h
>>>> +++ b/arch/arm64/include/asm/acpi.h
>>>> @@ -12,6 +12,8 @@
>>>> #ifndef _ASM_ACPI_H
>>>> #define _ASM_ACPI_H
>>>>
>>>> +#include <asm/smp_plat.h>
>>>> +
>>>> /* Basic configuration for ACPI */
>>>> #ifdef CONFIG_ACPI
>>>> #define acpi_strict 1 /* No out-of-spec workarounds on ARM64 */
>>>> @@ -45,6 +47,33 @@ static inline void enable_acpi(void)
>>>> acpi_noirq = 0;
>>>> }
>>>>
>>>> +/* MPIDR value provided in GICC structure is 64 bits, but the
>>>> + * existing apic_id (CPU hardware ID) using in acpi processor
>>>> + * driver is 32-bit, to conform to the same datatype we need
>>>> + * to repack the GICC structure MPIDR.
>>>> + *
>>>> + * Only 32 bits of MPIDR are used:
>>>> + *
>>>> + * Bits [0:7] Aff0;
>>>> + * Bits [8:15] Aff1;
>>>> + * Bits [16:23] Aff2;
>>>> + * Bits [32:39] Aff3;
>>>> + */
>>>> +static inline u32 pack_mpidr(u64 mpidr)
>>>> +{
>>>> + return (u32) ((mpidr & 0xff00000000) >> 8) | mpidr;
>>>> +}
>>>> +
>>>> +/*
>>>> + * The ACPI processor driver for ACPI core code needs this macro
>>>> + * to find out this cpu was already mapped (mapping from CPU hardware
>>>> + * ID to CPU logical ID) or not.
>>>> + *
>>>> + * cpu_logical_map(cpu) is the mapping of MPIDR and the logical cpu,
>>>> + * and MPIDR is the cpu hardware ID we needed to pack.
>>>> + */
>>>> +#define cpu_physical_id(cpu) pack_mpidr(cpu_logical_map(cpu))
>>>> +
>>>> /*
>>>> * It's used from ACPI core in kdump to boot UP system with SMP kernel,
>>>> * with this check the ACPI core will not override the CPU index
>>>> diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
>>>> index 34837e0..e91ec76 100644
>>>> --- a/arch/arm64/kernel/acpi.c
>>>> +++ b/arch/arm64/kernel/acpi.c
>>>> @@ -24,7 +24,6 @@
>>>> #include <linux/bootmem.h>
>>>> #include <linux/smp.h>
>>>>
>>>> -#include <asm/smp_plat.h>
>>>> #include <asm/cputype.h>
>>>> #include <asm/cpu_ops.h>
>>>>
>>>> diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
>>>> index e32321c..4007313 100644
>>>> --- a/drivers/acpi/processor_core.c
>>>> +++ b/drivers/acpi/processor_core.c
>>>> @@ -64,6 +64,38 @@ static int map_lsapic_id(struct acpi_subtable_header *entry,
>>>> return 0;
>>>> }
>>>>
>>>> +/*
>>>> + * On ARM platform, MPIDR value is the hardware ID as apic ID
>>>> + * on Intel platforms
>>>> + */
>>>> +static int map_gicc_mpidr(struct acpi_subtable_header *entry,
>>>> + int device_declaration, u32 acpi_id, int *mpidr)
>>>> +{
>>>> + struct acpi_madt_generic_interrupt *gicc =
>>>> + container_of(entry, struct acpi_madt_generic_interrupt, header);
>>>> +
>>>> + if (!(gicc->flags & ACPI_MADT_ENABLED))
>>>> + return -ENODEV;
>>>> +
>>>> + /* In the GIC interrupt model, logical processors are
>>>> + * required to have a Processor Device object in the DSDT,
>>>> + * so we should check device_declaration here
>>>> + */
>>>> + if (device_declaration && (gicc->uid == acpi_id)) {
>>>> + /*
>>>> + * Only bits [0:7] Aff0, bits [8:15] Aff1, bits [16:23] Aff2
>>>> + * and bits [32:39] Aff3 are meaningful, so pack the Affx
>>>> + * fields into a single 32 bit identifier to accommodate the
>>>> + * acpi processor drivers.
>>>> + */
>>>> + *mpidr = ((gicc->arm_mpidr & 0xff00000000) >> 8)
>>>> + | gicc->arm_mpidr;
>>>
>>> The simple fact that you define a function to pack the mpidr value and
>>> you can't use it here because this is *generic* code is telling, and
>>> a very bad omen. At the cost of sounding like a broken record, I do not
>>> like this mpidr->apic->logical_cpu song and dance at all.
>>> ACPI is peppered with code (eg hotplug is another example, CPUidle driver
>>> even worse) that is supposed to be generic but contains x86 code to carry
>>> out this cpuid conversion, I really think that in order to start an ARM64
>>> ACPI port properly we should at least try to factor out this physical to
>>> logical cpu id conversion, and it is not the first time that I mention this
>>> on the lists.
>>
>> I know, thanks for pointing this out. As I replied in previous version
>> of this patch set, apic_id is x86/ia64 specific, but the meaning behind
>> it is not. It means the CPU hardware id to identify itself in the system,
>> it just like MPIDR on ARM.
>>
>> I will send out a patch for RFC to convert apic_id to physid which
>> is generic for all platforms.
>>
>>>
>>> I will also talk to Rafael about this at the earliest opportunity, I
>>> guess that x86 code relies on apic-id because some ACPI versions could
>>> not rely on the acpi-id or some other reasons I have to investigate.
>>
>> As ACPI spec (section 8.4, Declaring Processors) said, Each processor
>> in the system must be declared in the ACPI namespace, so each cpu will
>> have acpi_id in all ACPI versions, and in theory we can map acpi_id to
>> logical cpu id if we want to.
>>
>> But things are complicated, apic_id is connected to many
>> tables, MADT for smp init, DSDT for device driver, and SRAT for NUMA (there
>> is no acpi_id in it, ONLY has apic_id in the table for x86/ia64), so if we
>> want to factor the code to map acpi_id to logical cpu id, we need to modify:
>>
>> - ACPI drivers;
>> - SMP init for x86 and ia64
>> - the mappings for NUMA init for x86 and ia64
>> that will be lots of work I think.
>
> And error prone for that matter.

Thanks for the clarify, I will send out a patch set to convert apic_id to
phys_id in ACPI processor driver soon, then we don't need to map acpi_id
to logical cpu number.

Thanks
Hanjun

2014-11-18 13:46:03

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 01/18] ARM64: Move the init of cpu_logical_map(0) before unflatten_device_tree()

Hi Catalin,

On 2014年10月17日 21:36, Hanjun Guo wrote:
> It always make sense to initialize CPU0's logical map entry from the
> hardware values, so move the initialization of cpu_logical_map(0)
> before unflatten_device_tree() which is needed by ACPI code later.
>
> Acked-by: Olof Johansson <[email protected]>
> Acked-by: Mark Rutland <[email protected]>
> Signed-off-by: Hanjun Guo <[email protected]>

Could you merge this patch first in 3.19? It was acked by Olof and
Mark, and it will make sense without ACPI too.

Thanks
Hanjun

> ---
> arch/arm64/kernel/setup.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
> index edb146d..8f33f72 100644
> --- a/arch/arm64/kernel/setup.c
> +++ b/arch/arm64/kernel/setup.c
> @@ -393,11 +393,11 @@ void __init setup_arch(char **cmdline_p)
>
> efi_idmap_init();
>
> + cpu_logical_map(0) = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
> unflatten_device_tree();
>
> psci_init();
>
> - cpu_logical_map(0) = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
> cpu_read_bootcpu_ops();
> #ifdef CONFIG_SMP
> smp_init_cpus();
>

2014-11-18 13:51:40

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 03/18] ACPI / table: Count matched and successfully parsed entries without specifying max entries

Hi Rafael,

On 2014年10月17日 21:36, Hanjun Guo wrote:
> From: Tomasz Nowicki <[email protected]>
>
> It is very useful to traverse all available table entries without max
> number of expected entries type. Current acpi_parse_entries()
> implementation gives that feature but it does not count those entries,
> it returns 0 instead, so fix it to count matched and successfully
> entries and return it.
>
> NOTE: This change has no impact to x86 and ia64 archs since existing code
> checks for error occurrence only (acpi_parse_entries(...,0) < 0).
>
> Acked-by: Grant Likely <[email protected]>
> Signed-off-by: Tomasz Nowicki <[email protected]>
> Signed-off-by: Hanjun Guo <[email protected]>

Patch 2 and patch 3 are only for ACPI cores, and have no harm to x86
and IA64, could you merge first in 3.19?

Thanks
Hanjun

> ---
> drivers/acpi/tables.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
> index 21ae521..b18e45e 100644
> --- a/drivers/acpi/tables.c
> +++ b/drivers/acpi/tables.c
> @@ -225,10 +225,13 @@ acpi_parse_entries(unsigned long table_size,
> while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
> table_end) {
> if (entry->type == entry_id
> - && (!max_entries || count++ < max_entries))
> + && (!max_entries || count < max_entries)) {
> if (handler(entry, table_end))
> return -EINVAL;
>
> + count++;
> + }
> +
> /*
> * If entry->length is 0, break from this loop to avoid
> * infinite loop.
>

2014-11-18 16:43:34

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH v5 01/18] ARM64: Move the init of cpu_logical_map(0) before unflatten_device_tree()

On Tue, Nov 18, 2014 at 01:45:49PM +0000, Hanjun Guo wrote:
> On 2014年10月17日 21:36, Hanjun Guo wrote:
> > It always make sense to initialize CPU0's logical map entry from the
> > hardware values, so move the initialization of cpu_logical_map(0)
> > before unflatten_device_tree() which is needed by ACPI code later.
> >
> > Acked-by: Olof Johansson <[email protected]>
> > Acked-by: Mark Rutland <[email protected]>
> > Signed-off-by: Hanjun Guo <[email protected]>
>
> Could you merge this patch first in 3.19? It was acked by Olof and
> Mark, and it will make sense without ACPI too.

I think it can go in for 3.19 (it's Will's turn this time ;)).

FWIW:

Acked-by: Catalin Marinas <[email protected]>

2014-11-18 16:57:20

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH v5 01/18] ARM64: Move the init of cpu_logical_map(0) before unflatten_device_tree()

On Tue, Nov 18, 2014 at 04:43:13PM +0000, Catalin Marinas wrote:
> On Tue, Nov 18, 2014 at 01:45:49PM +0000, Hanjun Guo wrote:
> > On 2014年10月17日 21:36, Hanjun Guo wrote:
> > > It always make sense to initialize CPU0's logical map entry from the
> > > hardware values, so move the initialization of cpu_logical_map(0)
> > > before unflatten_device_tree() which is needed by ACPI code later.
> > >
> > > Acked-by: Olof Johansson <[email protected]>
> > > Acked-by: Mark Rutland <[email protected]>
> > > Signed-off-by: Hanjun Guo <[email protected]>
> >
> > Could you merge this patch first in 3.19? It was acked by Olof and
> > Mark, and it will make sense without ACPI too.
>
> I think it can go in for 3.19 (it's Will's turn this time ;)).

This patch doesn't apply on for-next/core, as it conflicts with some of
Rutland's rework ("arm64: log physical ID of boot CPU").

Will

2014-11-18 17:01:55

by Sudeep Holla

[permalink] [raw]
Subject: Re: [PATCH v5 01/18] ARM64: Move the init of cpu_logical_map(0) before unflatten_device_tree()

Hi Will,

I was writing to reply to Catalin's mail :)

On 18/11/14 16:57, Will Deacon wrote:
> On Tue, Nov 18, 2014 at 04:43:13PM +0000, Catalin Marinas wrote:
>> On Tue, Nov 18, 2014 at 01:45:49PM +0000, Hanjun Guo wrote:
>>> On 2014年10月17日 21:36, Hanjun Guo wrote:
>>>> It always make sense to initialize CPU0's logical map entry from the
>>>> hardware values, so move the initialization of cpu_logical_map(0)
>>>> before unflatten_device_tree() which is needed by ACPI code later.
>>>>
>>>> Acked-by: Olof Johansson <[email protected]>
>>>> Acked-by: Mark Rutland <[email protected]>
>>>> Signed-off-by: Hanjun Guo <[email protected]>
>>>
>>> Could you merge this patch first in 3.19? It was acked by Olof and
>>> Mark, and it will make sense without ACPI too.
>>
>> I think it can go in for 3.19 (it's Will's turn this time ;)).
>
> This patch doesn't apply on for-next/core, as it conflicts with some of
> Rutland's rework ("arm64: log physical ID of boot CPU").
>

It's actually not required anymore, as "arm64: log physical ID of boot
CPU" move it quite early in the sequence from setup_arch to
smp_setup_processor_id while this patch just moves it up in setup_arch.

Regards,
Sudeep

2014-11-18 17:03:56

by Will Deacon

[permalink] [raw]
Subject: Re: [PATCH v5 01/18] ARM64: Move the init of cpu_logical_map(0) before unflatten_device_tree()

On Tue, Nov 18, 2014 at 05:02:05PM +0000, Sudeep Holla wrote:
> On 18/11/14 16:57, Will Deacon wrote:
> > On Tue, Nov 18, 2014 at 04:43:13PM +0000, Catalin Marinas wrote:
> >> On Tue, Nov 18, 2014 at 01:45:49PM +0000, Hanjun Guo wrote:
> >>> On 2014年10月17日 21:36, Hanjun Guo wrote:
> >>>> It always make sense to initialize CPU0's logical map entry from the
> >>>> hardware values, so move the initialization of cpu_logical_map(0)
> >>>> before unflatten_device_tree() which is needed by ACPI code later.
> >>>>
> >>>> Acked-by: Olof Johansson <[email protected]>
> >>>> Acked-by: Mark Rutland <[email protected]>
> >>>> Signed-off-by: Hanjun Guo <[email protected]>
> >>>
> >>> Could you merge this patch first in 3.19? It was acked by Olof and
> >>> Mark, and it will make sense without ACPI too.
> >>
> >> I think it can go in for 3.19 (it's Will's turn this time ;)).
> >
> > This patch doesn't apply on for-next/core, as it conflicts with some of
> > Rutland's rework ("arm64: log physical ID of boot CPU").
> >
>
> It's actually not required anymore, as "arm64: log physical ID of boot
> CPU" move it quite early in the sequence from setup_arch to
> smp_setup_processor_id while this patch just moves it up in setup_arch.

Thanks Sudeep, I'd guessed as much :)

Will

2014-11-18 19:54:40

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 03/18] ACPI / table: Count matched and successfully parsed entries without specifying max entries

On Tuesday, November 18, 2014 09:51:25 PM Hanjun Guo wrote:
> Hi Rafael,
>
> On 2014年10月17日 21:36, Hanjun Guo wrote:
> > From: Tomasz Nowicki <[email protected]>
> >
> > It is very useful to traverse all available table entries without max
> > number of expected entries type. Current acpi_parse_entries()
> > implementation gives that feature but it does not count those entries,
> > it returns 0 instead, so fix it to count matched and successfully
> > entries and return it.
> >
> > NOTE: This change has no impact to x86 and ia64 archs since existing code
> > checks for error occurrence only (acpi_parse_entries(...,0) < 0).
> >
> > Acked-by: Grant Likely <[email protected]>
> > Signed-off-by: Tomasz Nowicki <[email protected]>
> > Signed-off-by: Hanjun Guo <[email protected]>
>
> Patch 2 and patch 3 are only for ACPI cores, and have no harm to x86
> and IA64, could you merge first in 3.19?

I can do that if that helps.

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2014-11-19 00:32:00

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 01/18] ARM64: Move the init of cpu_logical_map(0) before unflatten_device_tree()

On 2014-11-19 1:03, Will Deacon wrote:
> On Tue, Nov 18, 2014 at 05:02:05PM +0000, Sudeep Holla wrote:
>> On 18/11/14 16:57, Will Deacon wrote:
>>> On Tue, Nov 18, 2014 at 04:43:13PM +0000, Catalin Marinas wrote:
>>>> On Tue, Nov 18, 2014 at 01:45:49PM +0000, Hanjun Guo wrote:
>>>>> On 2014年10月17日 21:36, Hanjun Guo wrote:
>>>>>> It always make sense to initialize CPU0's logical map entry from the
>>>>>> hardware values, so move the initialization of cpu_logical_map(0)
>>>>>> before unflatten_device_tree() which is needed by ACPI code later.
>>>>>>
>>>>>> Acked-by: Olof Johansson <[email protected]>
>>>>>> Acked-by: Mark Rutland <[email protected]>
>>>>>> Signed-off-by: Hanjun Guo <[email protected]>
>>>>>
>>>>> Could you merge this patch first in 3.19? It was acked by Olof and
>>>>> Mark, and it will make sense without ACPI too.
>>>>
>>>> I think it can go in for 3.19 (it's Will's turn this time ;)).
>>>
>>> This patch doesn't apply on for-next/core, as it conflicts with some of
>>> Rutland's rework ("arm64: log physical ID of boot CPU").
>>>
>>
>> It's actually not required anymore, as "arm64: log physical ID of boot
>> CPU" move it quite early in the sequence from setup_arch to
>> smp_setup_processor_id while this patch just moves it up in setup_arch.
>
> Thanks Sudeep, I'd guessed as much :)

That's great, thanks for the reminding, I will drop this one.

Best regards
Hanjun

2014-11-19 00:36:54

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 03/18] ACPI / table: Count matched and successfully parsed entries without specifying max entries

On 2014-11-19 4:15, Rafael J. Wysocki wrote:
> On Tuesday, November 18, 2014 09:51:25 PM Hanjun Guo wrote:
>> Hi Rafael,
>>
>> On 2014年10月17日 21:36, Hanjun Guo wrote:
>>> From: Tomasz Nowicki <[email protected]>
>>>
>>> It is very useful to traverse all available table entries without max
>>> number of expected entries type. Current acpi_parse_entries()
>>> implementation gives that feature but it does not count those entries,
>>> it returns 0 instead, so fix it to count matched and successfully
>>> entries and return it.
>>>
>>> NOTE: This change has no impact to x86 and ia64 archs since existing code
>>> checks for error occurrence only (acpi_parse_entries(...,0) < 0).
>>>
>>> Acked-by: Grant Likely <[email protected]>
>>> Signed-off-by: Tomasz Nowicki <[email protected]>
>>> Signed-off-by: Hanjun Guo <[email protected]>
>>
>> Patch 2 and patch 3 are only for ACPI cores, and have no harm to x86
>> and IA64, could you merge first in 3.19?
>
> I can do that if that helps.

Yes, it helps to keep the next version of ARM64 ACPI patch set smaller
and easy for review. If any rebase work needed, please let me know.

Thanks
Hanjun

2014-11-24 01:05:57

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 02/18] ACPI / table: Add new function to get table entries

On Friday, October 17, 2014 09:36:58 PM Hanjun Guo wrote:
> From: Ashwin Chaugule <[email protected]>
>
> The acpi_table_parse() function has a callback that
> passes a pointer to a table_header. Add a new function
> which takes this pointer and parses its entries. This
> eliminates the need to re-traverse all the tables for
> each call. e.g. as in acpi_table_parse_madt() which is
> normally called after acpi_table_parse().
>
> Acked-by: Grant Likely <[email protected]>
> Signed-off-by: Ashwin Chaugule <[email protected]>
> Signed-off-by: Tomasz Nowicki <[email protected]>
> Signed-off-by: Hanjun Guo <[email protected]>
> ---
> drivers/acpi/tables.c | 67 ++++++++++++++++++++++++++++++++++---------------
> include/linux/acpi.h | 4 +++
> 2 files changed, 51 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
> index 6d5a6cd..21ae521 100644
> --- a/drivers/acpi/tables.c
> +++ b/drivers/acpi/tables.c
> @@ -192,17 +192,14 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
>
>
> int __init
> -acpi_table_parse_entries(char *id,
> - unsigned long table_size,
> - int entry_id,
> - acpi_tbl_entry_handler handler,
> - unsigned int max_entries)
> +acpi_parse_entries(unsigned long table_size,
> + acpi_tbl_entry_handler handler,
> + struct acpi_table_header *table_header,
> + int entry_id, unsigned int max_entries)
> {
> - struct acpi_table_header *table_header = NULL;
> struct acpi_subtable_header *entry;
> - unsigned int count = 0;
> + int count = 0;
> unsigned long table_end;
> - acpi_size tbl_size;
>
> if (acpi_disabled)
> return -ENODEV;
> @@ -210,13 +207,11 @@ acpi_table_parse_entries(char *id,
> if (!handler)
> return -EINVAL;
>
> - if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
> - acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
> - else
> - acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
> + if (!table_size)
> + return -EINVAL;
>
> if (!table_header) {
> - pr_warn("%4.4s not present\n", id);
> + pr_warn("Table header not present\n");

The message doesn't make sense any more if the table signature is not printed.

> return -ENODEV;
> }
>
> @@ -232,30 +227,62 @@ acpi_table_parse_entries(char *id,
> if (entry->type == entry_id
> && (!max_entries || count++ < max_entries))
> if (handler(entry, table_end))
> - goto err;
> + return -EINVAL;
>
> /*
> * If entry->length is 0, break from this loop to avoid
> * infinite loop.
> */
> if (entry->length == 0) {
> - pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
> - goto err;
> + pr_err("[0x%02x] Invalid zero length\n", entry_id);

Same here.

> + return -EINVAL;
> }
>
> entry = (struct acpi_subtable_header *)
> ((unsigned long)entry + entry->length);
> }
> +
> if (max_entries && count > max_entries) {
> pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n",
> - id, entry_id, count - max_entries, count);
> + table_header->signature, entry_id, count - max_entries,
> + count);
> }
>
> - early_acpi_os_unmap_memory((char *)table_header, tbl_size);
> return count;
> -err:
> +}
> +
> +int __init
> +acpi_table_parse_entries(char *id,
> + unsigned long table_size,
> + int entry_id,
> + acpi_tbl_entry_handler handler,
> + unsigned int max_entries)
> +{
> + struct acpi_table_header *table_header = NULL;
> + acpi_size tbl_size;
> + int count;
> +
> + if (acpi_disabled)
> + return -ENODEV;
> +
> + if (!handler)
> + return -EINVAL;
> +
> + if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
> + acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
> + else
> + acpi_get_table_with_size(id, 0, &table_header, &tbl_size);


u32 instance = 0;

if (!strncmp(id, ACPI_SIG_MADT, 4))
instance = acpi_apic_instance;

acpi_get_table_with_size(id, instance, &table_header, &tbl_size);

Pretty please.

> +
> + if (!table_header) {
> + pr_warn("%4.4s not present\n", id);
> + return -ENODEV;
> + }
> +
> + count = acpi_parse_entries(table_size, handler, table_header,
> + entry_id, max_entries);
> +
> early_acpi_os_unmap_memory((char *)table_header, tbl_size);
> - return -EINVAL;
> + return count;
> }
>
> int __init
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 807cbc4..36d5012 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -123,6 +123,10 @@ int acpi_numa_init (void);
>
> int acpi_table_init (void);
> int acpi_table_parse(char *id, acpi_tbl_table_handler handler);
> +int __init acpi_parse_entries(unsigned long table_size,
> + acpi_tbl_entry_handler handler,
> + struct acpi_table_header *table_header,
> + int entry_id, unsigned int max_entries);
> int __init acpi_table_parse_entries(char *id, unsigned long table_size,
> int entry_id,
> acpi_tbl_entry_handler handler,
>

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2014-11-24 01:23:53

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 03/18] ACPI / table: Count matched and successfully parsed entries without specifying max entries

On Friday, October 17, 2014 09:36:59 PM Hanjun Guo wrote:
> From: Tomasz Nowicki <[email protected]>
>
> It is very useful to traverse all available table entries without max
> number of expected entries type. Current acpi_parse_entries()
> implementation gives that feature but it does not count those entries,
> it returns 0 instead, so fix it to count matched and successfully
> entries and return it.

Hmm. I guess that the goal is for count to only be incremented when the
condition is satisfied entirely, while without the patch it may be incremented
even if that isn't the case.

I'm not sure how that is related to the above paragraph, however.

> NOTE: This change has no impact to x86 and ia64 archs since existing code
> checks for error occurrence only (acpi_parse_entries(...,0) < 0).
>
> Acked-by: Grant Likely <[email protected]>
> Signed-off-by: Tomasz Nowicki <[email protected]>
> Signed-off-by: Hanjun Guo <[email protected]>
> ---
> drivers/acpi/tables.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
> index 21ae521..b18e45e 100644
> --- a/drivers/acpi/tables.c
> +++ b/drivers/acpi/tables.c
> @@ -225,10 +225,13 @@ acpi_parse_entries(unsigned long table_size,
> while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
> table_end) {
> if (entry->type == entry_id
> - && (!max_entries || count++ < max_entries))
> + && (!max_entries || count < max_entries)) {
> if (handler(entry, table_end))
> return -EINVAL;
>
> + count++;
> + }
> +
> /*
> * If entry->length is 0, break from this loop to avoid
> * infinite loop.
>

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2014-11-24 08:34:32

by Tomasz Nowicki

[permalink] [raw]
Subject: Re: [PATCH v5 03/18] ACPI / table: Count matched and successfully parsed entries without specifying max entries

On 24.11.2014 02:45, Rafael J. Wysocki wrote:
> On Friday, October 17, 2014 09:36:59 PM Hanjun Guo wrote:
>> From: Tomasz Nowicki <[email protected]>
>>
>> It is very useful to traverse all available table entries without max
>> number of expected entries type. Current acpi_parse_entries()
>> implementation gives that feature but it does not count those entries,
>> it returns 0 instead, so fix it to count matched and successfully
>> entries and return it.
>
> Hmm. I guess that the goal is for count to only be incremented when the
> condition is satisfied entirely, while without the patch it may be incremented
> even if that isn't the case.

That would be our goal if patch would look like:
- && (!max_entries || count++ < max_entries))
+ && (!max_entries && count++ < max_entries)) {
but then we can not walk through all available entries (with max_entries==0)

>
> I'm not sure how that is related to the above paragraph, however.
>

Previous changelog is not clear, let me rewrite it:

acpi_parse_entries() allows to traverse all available table entries (aka
subtables) by passing max_entries parameter equal to 0. But for that use
case acpi_parse_entries() does not inform caller how many entries were
matched and for how many entries handler was run against. That patch is
going to fix it.

Regards,
Tomasz

>> NOTE: This change has no impact to x86 and ia64 archs since existing code
>> checks for error occurrence only (acpi_parse_entries(...,0) < 0).
>>
>> Acked-by: Grant Likely <[email protected]>
>> Signed-off-by: Tomasz Nowicki <[email protected]>
>> Signed-off-by: Hanjun Guo <[email protected]>
>> ---
>> drivers/acpi/tables.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
>> index 21ae521..b18e45e 100644
>> --- a/drivers/acpi/tables.c
>> +++ b/drivers/acpi/tables.c
>> @@ -225,10 +225,13 @@ acpi_parse_entries(unsigned long table_size,
>> while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
>> table_end) {
>> if (entry->type == entry_id
>> - && (!max_entries || count++ < max_entries))
>> + && (!max_entries || count < max_entries)) {
>> if (handler(entry, table_end))
>> return -EINVAL;
>>
>> + count++;
>> + }
>> +
>> /*
>> * If entry->length is 0, break from this loop to avoid
>> * infinite loop.
>>
>

2014-11-24 11:06:10

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 02/18] ACPI / table: Add new function to get table entries

On 2014-11-24 9:27, Rafael J. Wysocki wrote:
> On Friday, October 17, 2014 09:36:58 PM Hanjun Guo wrote:
>> From: Ashwin Chaugule <[email protected]>
>>
>> The acpi_table_parse() function has a callback that
>> passes a pointer to a table_header. Add a new function
>> which takes this pointer and parses its entries. This
>> eliminates the need to re-traverse all the tables for
>> each call. e.g. as in acpi_table_parse_madt() which is
>> normally called after acpi_table_parse().
>>
>> Acked-by: Grant Likely <[email protected]>
>> Signed-off-by: Ashwin Chaugule <[email protected]>
>> Signed-off-by: Tomasz Nowicki <[email protected]>
>> Signed-off-by: Hanjun Guo <[email protected]>
>> ---
>> drivers/acpi/tables.c | 67 ++++++++++++++++++++++++++++++++++---------------
>> include/linux/acpi.h | 4 +++
>> 2 files changed, 51 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
>> index 6d5a6cd..21ae521 100644
>> --- a/drivers/acpi/tables.c
>> +++ b/drivers/acpi/tables.c
>> @@ -192,17 +192,14 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
>>
>>
>> int __init
>> -acpi_table_parse_entries(char *id,
>> - unsigned long table_size,
>> - int entry_id,
>> - acpi_tbl_entry_handler handler,
>> - unsigned int max_entries)
>> +acpi_parse_entries(unsigned long table_size,
>> + acpi_tbl_entry_handler handler,
>> + struct acpi_table_header *table_header,
>> + int entry_id, unsigned int max_entries)
>> {
>> - struct acpi_table_header *table_header = NULL;
>> struct acpi_subtable_header *entry;
>> - unsigned int count = 0;
>> + int count = 0;
>> unsigned long table_end;
>> - acpi_size tbl_size;
>>
>> if (acpi_disabled)
>> return -ENODEV;
>> @@ -210,13 +207,11 @@ acpi_table_parse_entries(char *id,
>> if (!handler)
>> return -EINVAL;
>>
>> - if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
>> - acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
>> - else
>> - acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
>> + if (!table_size)
>> + return -EINVAL;
>>
>> if (!table_header) {
>> - pr_warn("%4.4s not present\n", id);
>> + pr_warn("Table header not present\n");
>
> The message doesn't make sense any more if the table signature is not printed.
>
>> return -ENODEV;
>> }
>>
>> @@ -232,30 +227,62 @@ acpi_table_parse_entries(char *id,
>> if (entry->type == entry_id
>> && (!max_entries || count++ < max_entries))
>> if (handler(entry, table_end))
>> - goto err;
>> + return -EINVAL;
>>
>> /*
>> * If entry->length is 0, break from this loop to avoid
>> * infinite loop.
>> */
>> if (entry->length == 0) {
>> - pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
>> - goto err;
>> + pr_err("[0x%02x] Invalid zero length\n", entry_id);
>
> Same here.

How about remove the message and return directly?

>
>> + return -EINVAL;
>> }
>>
>> entry = (struct acpi_subtable_header *)
>> ((unsigned long)entry + entry->length);
>> }
>> +
>> if (max_entries && count > max_entries) {
>> pr_warn("[%4.4s:0x%02x] ignored %i entries of %i found\n",
>> - id, entry_id, count - max_entries, count);
>> + table_header->signature, entry_id, count - max_entries,
>> + count);
>> }
>>
>> - early_acpi_os_unmap_memory((char *)table_header, tbl_size);
>> return count;
>> -err:
>> +}
>> +
>> +int __init
>> +acpi_table_parse_entries(char *id,
>> + unsigned long table_size,
>> + int entry_id,
>> + acpi_tbl_entry_handler handler,
>> + unsigned int max_entries)
>> +{
>> + struct acpi_table_header *table_header = NULL;
>> + acpi_size tbl_size;
>> + int count;
>> +
>> + if (acpi_disabled)
>> + return -ENODEV;
>> +
>> + if (!handler)
>> + return -EINVAL;
>> +
>> + if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
>> + acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
>> + else
>> + acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
>
>
> u32 instance = 0;
>
> if (!strncmp(id, ACPI_SIG_MADT, 4))
> instance = acpi_apic_instance;
>
> acpi_get_table_with_size(id, instance, &table_header, &tbl_size);
>
> Pretty please.

Yes, much better! I will update the patch.

Thanks
Hanjun

2014-11-24 14:30:34

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 02/18] ACPI / table: Add new function to get table entries

On Monday, November 24, 2014 07:03:54 PM Hanjun Guo wrote:
> On 2014-11-24 9:27, Rafael J. Wysocki wrote:
> > On Friday, October 17, 2014 09:36:58 PM Hanjun Guo wrote:
> >> From: Ashwin Chaugule <[email protected]>
> >>
> >> The acpi_table_parse() function has a callback that
> >> passes a pointer to a table_header. Add a new function
> >> which takes this pointer and parses its entries. This
> >> eliminates the need to re-traverse all the tables for
> >> each call. e.g. as in acpi_table_parse_madt() which is
> >> normally called after acpi_table_parse().
> >>
> >> Acked-by: Grant Likely <[email protected]>
> >> Signed-off-by: Ashwin Chaugule <[email protected]>
> >> Signed-off-by: Tomasz Nowicki <[email protected]>
> >> Signed-off-by: Hanjun Guo <[email protected]>
> >> ---
> >> drivers/acpi/tables.c | 67 ++++++++++++++++++++++++++++++++++---------------
> >> include/linux/acpi.h | 4 +++
> >> 2 files changed, 51 insertions(+), 20 deletions(-)
> >>
> >> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
> >> index 6d5a6cd..21ae521 100644
> >> --- a/drivers/acpi/tables.c
> >> +++ b/drivers/acpi/tables.c
> >> @@ -192,17 +192,14 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
> >>
> >>
> >> int __init
> >> -acpi_table_parse_entries(char *id,
> >> - unsigned long table_size,
> >> - int entry_id,
> >> - acpi_tbl_entry_handler handler,
> >> - unsigned int max_entries)
> >> +acpi_parse_entries(unsigned long table_size,
> >> + acpi_tbl_entry_handler handler,
> >> + struct acpi_table_header *table_header,
> >> + int entry_id, unsigned int max_entries)
> >> {
> >> - struct acpi_table_header *table_header = NULL;
> >> struct acpi_subtable_header *entry;
> >> - unsigned int count = 0;
> >> + int count = 0;
> >> unsigned long table_end;
> >> - acpi_size tbl_size;
> >>
> >> if (acpi_disabled)
> >> return -ENODEV;
> >> @@ -210,13 +207,11 @@ acpi_table_parse_entries(char *id,
> >> if (!handler)
> >> return -EINVAL;
> >>
> >> - if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
> >> - acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
> >> - else
> >> - acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
> >> + if (!table_size)
> >> + return -EINVAL;
> >>
> >> if (!table_header) {
> >> - pr_warn("%4.4s not present\n", id);
> >> + pr_warn("Table header not present\n");
> >
> > The message doesn't make sense any more if the table signature is not printed.
> >
> >> return -ENODEV;
> >> }
> >>
> >> @@ -232,30 +227,62 @@ acpi_table_parse_entries(char *id,
> >> if (entry->type == entry_id
> >> && (!max_entries || count++ < max_entries))
> >> if (handler(entry, table_end))
> >> - goto err;
> >> + return -EINVAL;
> >>
> >> /*
> >> * If entry->length is 0, break from this loop to avoid
> >> * infinite loop.
> >> */
> >> if (entry->length == 0) {
> >> - pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
> >> - goto err;
> >> + pr_err("[0x%02x] Invalid zero length\n", entry_id);
> >
> > Same here.
>
> How about remove the message and return directly?

We could do that, but for what reason? Is the message not useful?

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2014-11-24 14:55:47

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 03/18] ACPI / table: Count matched and successfully parsed entries without specifying max entries

On Monday, November 24, 2014 09:34:24 AM Tomasz Nowicki wrote:
> On 24.11.2014 02:45, Rafael J. Wysocki wrote:
> > On Friday, October 17, 2014 09:36:59 PM Hanjun Guo wrote:
> >> From: Tomasz Nowicki <[email protected]>
> >>
> >> It is very useful to traverse all available table entries without max
> >> number of expected entries type. Current acpi_parse_entries()
> >> implementation gives that feature but it does not count those entries,
> >> it returns 0 instead, so fix it to count matched and successfully
> >> entries and return it.
> >
> > Hmm. I guess that the goal is for count to only be incremented when the
> > condition is satisfied entirely, while without the patch it may be incremented
> > even if that isn't the case.
>
> That would be our goal if patch would look like:
> - && (!max_entries || count++ < max_entries))
> + && (!max_entries && count++ < max_entries)) {
> but then we can not walk through all available entries (with max_entries==0)

No, that's not what I was trying to say. :-)

> >
> > I'm not sure how that is related to the above paragraph, however.
> >
>
> Previous changelog is not clear, let me rewrite it:
>
> acpi_parse_entries() allows to traverse all available table entries (aka
> subtables) by passing max_entries parameter equal to 0. But for that use
> case acpi_parse_entries() does not inform caller how many entries were
> matched and for how many entries handler was run against. That patch is
> going to fix it.

Do I understand correctly that count is only ever incremented by current code
if max_entries is different from 0?


> >> NOTE: This change has no impact to x86 and ia64 archs since existing code
> >> checks for error occurrence only (acpi_parse_entries(...,0) < 0).
> >>
> >> Acked-by: Grant Likely <[email protected]>
> >> Signed-off-by: Tomasz Nowicki <[email protected]>
> >> Signed-off-by: Hanjun Guo <[email protected]>
> >> ---
> >> drivers/acpi/tables.c | 5 ++++-
> >> 1 file changed, 4 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
> >> index 21ae521..b18e45e 100644
> >> --- a/drivers/acpi/tables.c
> >> +++ b/drivers/acpi/tables.c
> >> @@ -225,10 +225,13 @@ acpi_parse_entries(unsigned long table_size,
> >> while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
> >> table_end) {
> >> if (entry->type == entry_id
> >> - && (!max_entries || count++ < max_entries))
> >> + && (!max_entries || count < max_entries)) {
> >> if (handler(entry, table_end))
> >> return -EINVAL;
> >>
> >> + count++;
> >> + }
> >> +
> >> /*
> >> * If entry->length is 0, break from this loop to avoid
> >> * infinite loop.
> >>
> >
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2014-11-24 15:01:33

by Tomasz Nowicki

[permalink] [raw]
Subject: Re: [PATCH v5 03/18] ACPI / table: Count matched and successfully parsed entries without specifying max entries

On 24.11.2014 16:16, Rafael J. Wysocki wrote:
> On Monday, November 24, 2014 09:34:24 AM Tomasz Nowicki wrote:
>> On 24.11.2014 02:45, Rafael J. Wysocki wrote:
>>> On Friday, October 17, 2014 09:36:59 PM Hanjun Guo wrote:
>>>> From: Tomasz Nowicki <[email protected]>
>>>>
>>>> It is very useful to traverse all available table entries without max
>>>> number of expected entries type. Current acpi_parse_entries()
>>>> implementation gives that feature but it does not count those entries,
>>>> it returns 0 instead, so fix it to count matched and successfully
>>>> entries and return it.
>>>
>>> Hmm. I guess that the goal is for count to only be incremented when the
>>> condition is satisfied entirely, while without the patch it may be incremented
>>> even if that isn't the case.
>>
>> That would be our goal if patch would look like:
>> - && (!max_entries || count++ < max_entries))
>> + && (!max_entries && count++ < max_entries)) {
>> but then we can not walk through all available entries (with max_entries==0)
>
> No, that's not what I was trying to say. :-)
>
>>>
>>> I'm not sure how that is related to the above paragraph, however.
>>>
>>
>> Previous changelog is not clear, let me rewrite it:
>>
>> acpi_parse_entries() allows to traverse all available table entries (aka
>> subtables) by passing max_entries parameter equal to 0. But for that use
>> case acpi_parse_entries() does not inform caller how many entries were
>> matched and for how many entries handler was run against. That patch is
>> going to fix it.
>
> Do I understand correctly that count is only ever incremented by current code
> if max_entries is different from 0?

Right. Currently "count" is incremented only if max_entries > 0.

Tomasz

>
>
>>>> NOTE: This change has no impact to x86 and ia64 archs since existing code
>>>> checks for error occurrence only (acpi_parse_entries(...,0) < 0).
>>>>
>>>> Acked-by: Grant Likely <[email protected]>
>>>> Signed-off-by: Tomasz Nowicki <[email protected]>
>>>> Signed-off-by: Hanjun Guo <[email protected]>
>>>> ---
>>>> drivers/acpi/tables.c | 5 ++++-
>>>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
>>>> index 21ae521..b18e45e 100644
>>>> --- a/drivers/acpi/tables.c
>>>> +++ b/drivers/acpi/tables.c
>>>> @@ -225,10 +225,13 @@ acpi_parse_entries(unsigned long table_size,
>>>> while (((unsigned long)entry) + sizeof(struct acpi_subtable_header) <
>>>> table_end) {
>>>> if (entry->type == entry_id
>>>> - && (!max_entries || count++ < max_entries))
>>>> + && (!max_entries || count < max_entries)) {
>>>> if (handler(entry, table_end))
>>>> return -EINVAL;
>>>>
>>>> + count++;
>>>> + }
>>>> +
>>>> /*
>>>> * If entry->length is 0, break from this loop to avoid
>>>> * infinite loop.
>>>>
>>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2014-11-24 15:16:09

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 03/18] ACPI / table: Count matched and successfully parsed entries without specifying max entries

On Monday, November 24, 2014 04:01:24 PM Tomasz Nowicki wrote:
> On 24.11.2014 16:16, Rafael J. Wysocki wrote:
> > On Monday, November 24, 2014 09:34:24 AM Tomasz Nowicki wrote:
> >> On 24.11.2014 02:45, Rafael J. Wysocki wrote:
> >>> On Friday, October 17, 2014 09:36:59 PM Hanjun Guo wrote:
> >>>> From: Tomasz Nowicki <[email protected]>
> >>>>
> >>>> It is very useful to traverse all available table entries without max
> >>>> number of expected entries type. Current acpi_parse_entries()
> >>>> implementation gives that feature but it does not count those entries,
> >>>> it returns 0 instead, so fix it to count matched and successfully
> >>>> entries and return it.
> >>>
> >>> Hmm. I guess that the goal is for count to only be incremented when the
> >>> condition is satisfied entirely, while without the patch it may be incremented
> >>> even if that isn't the case.
> >>
> >> That would be our goal if patch would look like:
> >> - && (!max_entries || count++ < max_entries))
> >> + && (!max_entries && count++ < max_entries)) {
> >> but then we can not walk through all available entries (with max_entries==0)
> >
> > No, that's not what I was trying to say. :-)
> >
> >>>
> >>> I'm not sure how that is related to the above paragraph, however.
> >>>
> >>
> >> Previous changelog is not clear, let me rewrite it:
> >>
> >> acpi_parse_entries() allows to traverse all available table entries (aka
> >> subtables) by passing max_entries parameter equal to 0. But for that use
> >> case acpi_parse_entries() does not inform caller how many entries were
> >> matched and for how many entries handler was run against. That patch is
> >> going to fix it.
> >
> > Do I understand correctly that count is only ever incremented by current code
> > if max_entries is different from 0?
>
> Right. Currently "count" is incremented only if max_entries > 0.

So can you say that in the changelog, please?

Something like:

"acpi_parse_entries() allows to traverse all available table entries (aka
subtables) by passing max_entries parameter equal to 0, but since its count
variable is only incremented if max_entries is not 0, the function always
returns 0 for max_entries equal to 0. It would be more useful if it returned
the number of entries matched instead, so make it increment count in that
case too".

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2014-11-24 15:18:25

by Tomasz Nowicki

[permalink] [raw]
Subject: Re: [PATCH v5 03/18] ACPI / table: Count matched and successfully parsed entries without specifying max entries

On 24.11.2014 16:37, Rafael J. Wysocki wrote:
> On Monday, November 24, 2014 04:01:24 PM Tomasz Nowicki wrote:
>> On 24.11.2014 16:16, Rafael J. Wysocki wrote:
>>> On Monday, November 24, 2014 09:34:24 AM Tomasz Nowicki wrote:
>>>> On 24.11.2014 02:45, Rafael J. Wysocki wrote:
>>>>> On Friday, October 17, 2014 09:36:59 PM Hanjun Guo wrote:
>>>>>> From: Tomasz Nowicki <[email protected]>
>>>>>>
>>>>>> It is very useful to traverse all available table entries without max
>>>>>> number of expected entries type. Current acpi_parse_entries()
>>>>>> implementation gives that feature but it does not count those entries,
>>>>>> it returns 0 instead, so fix it to count matched and successfully
>>>>>> entries and return it.
>>>>>
>>>>> Hmm. I guess that the goal is for count to only be incremented when the
>>>>> condition is satisfied entirely, while without the patch it may be incremented
>>>>> even if that isn't the case.
>>>>
>>>> That would be our goal if patch would look like:
>>>> - && (!max_entries || count++ < max_entries))
>>>> + && (!max_entries && count++ < max_entries)) {
>>>> but then we can not walk through all available entries (with max_entries==0)
>>>
>>> No, that's not what I was trying to say. :-)
>>>
>>>>>
>>>>> I'm not sure how that is related to the above paragraph, however.
>>>>>
>>>>
>>>> Previous changelog is not clear, let me rewrite it:
>>>>
>>>> acpi_parse_entries() allows to traverse all available table entries (aka
>>>> subtables) by passing max_entries parameter equal to 0. But for that use
>>>> case acpi_parse_entries() does not inform caller how many entries were
>>>> matched and for how many entries handler was run against. That patch is
>>>> going to fix it.
>>>
>>> Do I understand correctly that count is only ever incremented by current code
>>> if max_entries is different from 0?
>>
>> Right. Currently "count" is incremented only if max_entries > 0.
>
> So can you say that in the changelog, please?
>
> Something like:
>
> "acpi_parse_entries() allows to traverse all available table entries (aka
> subtables) by passing max_entries parameter equal to 0, but since its count
> variable is only incremented if max_entries is not 0, the function always
> returns 0 for max_entries equal to 0. It would be more useful if it returned
> the number of entries matched instead, so make it increment count in that
> case too".
>

Sure, thanks.

Tomasz

2014-11-25 03:40:48

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 02/18] ACPI / table: Add new function to get table entries

On 2014/11/24 22:51, Rafael J. Wysocki wrote:
> On Monday, November 24, 2014 07:03:54 PM Hanjun Guo wrote:
>> On 2014-11-24 9:27, Rafael J. Wysocki wrote:
>>> On Friday, October 17, 2014 09:36:58 PM Hanjun Guo wrote:
>>>> From: Ashwin Chaugule <[email protected]>
>>>>
>>>> The acpi_table_parse() function has a callback that
>>>> passes a pointer to a table_header. Add a new function
>>>> which takes this pointer and parses its entries. This
>>>> eliminates the need to re-traverse all the tables for
>>>> each call. e.g. as in acpi_table_parse_madt() which is
>>>> normally called after acpi_table_parse().
>>>>
>>>> Acked-by: Grant Likely <[email protected]>
>>>> Signed-off-by: Ashwin Chaugule <[email protected]>
>>>> Signed-off-by: Tomasz Nowicki <[email protected]>
>>>> Signed-off-by: Hanjun Guo <[email protected]>
>>>> ---
>>>> drivers/acpi/tables.c | 67 ++++++++++++++++++++++++++++++++++---------------
>>>> include/linux/acpi.h | 4 +++
>>>> 2 files changed, 51 insertions(+), 20 deletions(-)
>>>>
>>>> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
>>>> index 6d5a6cd..21ae521 100644
>>>> --- a/drivers/acpi/tables.c
>>>> +++ b/drivers/acpi/tables.c
>>>> @@ -192,17 +192,14 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
>>>>
>>>>
>>>> int __init
>>>> -acpi_table_parse_entries(char *id,
>>>> - unsigned long table_size,
>>>> - int entry_id,
>>>> - acpi_tbl_entry_handler handler,
>>>> - unsigned int max_entries)
>>>> +acpi_parse_entries(unsigned long table_size,
>>>> + acpi_tbl_entry_handler handler,
>>>> + struct acpi_table_header *table_header,
>>>> + int entry_id, unsigned int max_entries)
>>>> {
>>>> - struct acpi_table_header *table_header = NULL;
>>>> struct acpi_subtable_header *entry;
>>>> - unsigned int count = 0;
>>>> + int count = 0;
>>>> unsigned long table_end;
>>>> - acpi_size tbl_size;
>>>>
>>>> if (acpi_disabled)
>>>> return -ENODEV;
>>>> @@ -210,13 +207,11 @@ acpi_table_parse_entries(char *id,
>>>> if (!handler)
>>>> return -EINVAL;
>>>>
>>>> - if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
>>>> - acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
>>>> - else
>>>> - acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
>>>> + if (!table_size)
>>>> + return -EINVAL;
>>>>
>>>> if (!table_header) {
>>>> - pr_warn("%4.4s not present\n", id);
>>>> + pr_warn("Table header not present\n");
>>> The message doesn't make sense any more if the table signature is not printed.

For this message, since no table id is passed, and this message is printed in
acpi_table_parse_entries() before this function is called, I think we can check
the table_header before call this function and remove the printed message here.

>>>
>>>> return -ENODEV;
>>>> }
>>>>
>>>> @@ -232,30 +227,62 @@ acpi_table_parse_entries(char *id,
>>>> if (entry->type == entry_id
>>>> && (!max_entries || count++ < max_entries))
>>>> if (handler(entry, table_end))
>>>> - goto err;
>>>> + return -EINVAL;
>>>>
>>>> /*
>>>> * If entry->length is 0, break from this loop to avoid
>>>> * infinite loop.
>>>> */
>>>> if (entry->length == 0) {
>>>> - pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
>>>> - goto err;
>>>> + pr_err("[0x%02x] Invalid zero length\n", entry_id);

For this one, since the table_header is valid now, we can keep it with:

- pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
+ pr_err("[%4.4s:0x%02x] Invalid zero length\n", table_header->signature, entry_id);

>>> Same here.
>> How about remove the message and return directly?
> We could do that, but for what reason? Is the message not useful?

I agree with you, the message is useful I think, how about the comments above?

Thanks
Hanjun

2014-11-25 20:59:27

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v5 02/18] ACPI / table: Add new function to get table entries

On Tuesday, November 25, 2014 11:38:05 AM Hanjun Guo wrote:
> On 2014/11/24 22:51, Rafael J. Wysocki wrote:
> > On Monday, November 24, 2014 07:03:54 PM Hanjun Guo wrote:
> >> On 2014-11-24 9:27, Rafael J. Wysocki wrote:
> >>> On Friday, October 17, 2014 09:36:58 PM Hanjun Guo wrote:
> >>>> From: Ashwin Chaugule <[email protected]>
> >>>>
> >>>> The acpi_table_parse() function has a callback that
> >>>> passes a pointer to a table_header. Add a new function
> >>>> which takes this pointer and parses its entries. This
> >>>> eliminates the need to re-traverse all the tables for
> >>>> each call. e.g. as in acpi_table_parse_madt() which is
> >>>> normally called after acpi_table_parse().
> >>>>
> >>>> Acked-by: Grant Likely <[email protected]>
> >>>> Signed-off-by: Ashwin Chaugule <[email protected]>
> >>>> Signed-off-by: Tomasz Nowicki <[email protected]>
> >>>> Signed-off-by: Hanjun Guo <[email protected]>
> >>>> ---
> >>>> drivers/acpi/tables.c | 67 ++++++++++++++++++++++++++++++++++---------------
> >>>> include/linux/acpi.h | 4 +++
> >>>> 2 files changed, 51 insertions(+), 20 deletions(-)
> >>>>
> >>>> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
> >>>> index 6d5a6cd..21ae521 100644
> >>>> --- a/drivers/acpi/tables.c
> >>>> +++ b/drivers/acpi/tables.c
> >>>> @@ -192,17 +192,14 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
> >>>>
> >>>>
> >>>> int __init
> >>>> -acpi_table_parse_entries(char *id,
> >>>> - unsigned long table_size,
> >>>> - int entry_id,
> >>>> - acpi_tbl_entry_handler handler,
> >>>> - unsigned int max_entries)
> >>>> +acpi_parse_entries(unsigned long table_size,
> >>>> + acpi_tbl_entry_handler handler,
> >>>> + struct acpi_table_header *table_header,
> >>>> + int entry_id, unsigned int max_entries)
> >>>> {
> >>>> - struct acpi_table_header *table_header = NULL;
> >>>> struct acpi_subtable_header *entry;
> >>>> - unsigned int count = 0;
> >>>> + int count = 0;
> >>>> unsigned long table_end;
> >>>> - acpi_size tbl_size;
> >>>>
> >>>> if (acpi_disabled)
> >>>> return -ENODEV;
> >>>> @@ -210,13 +207,11 @@ acpi_table_parse_entries(char *id,
> >>>> if (!handler)
> >>>> return -EINVAL;
> >>>>
> >>>> - if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
> >>>> - acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
> >>>> - else
> >>>> - acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
> >>>> + if (!table_size)
> >>>> + return -EINVAL;
> >>>>
> >>>> if (!table_header) {
> >>>> - pr_warn("%4.4s not present\n", id);
> >>>> + pr_warn("Table header not present\n");
> >>> The message doesn't make sense any more if the table signature is not printed.
>
> For this message, since no table id is passed, and this message is printed in
> acpi_table_parse_entries() before this function is called, I think we can check
> the table_header before call this function and remove the printed message here.

table_header needs to be checked against NULL in the caller and the message
printed from there to my eyes.

> >>>
> >>>> return -ENODEV;
> >>>> }
> >>>>
> >>>> @@ -232,30 +227,62 @@ acpi_table_parse_entries(char *id,
> >>>> if (entry->type == entry_id
> >>>> && (!max_entries || count++ < max_entries))
> >>>> if (handler(entry, table_end))
> >>>> - goto err;
> >>>> + return -EINVAL;
> >>>>
> >>>> /*
> >>>> * If entry->length is 0, break from this loop to avoid
> >>>> * infinite loop.
> >>>> */
> >>>> if (entry->length == 0) {
> >>>> - pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
> >>>> - goto err;
> >>>> + pr_err("[0x%02x] Invalid zero length\n", entry_id);
>
> For this one, since the table_header is valid now, we can keep it with:

Fine by me.

> - pr_err("[%4.4s:0x%02x] Invalid zero length\n", id, entry_id);
> + pr_err("[%4.4s:0x%02x] Invalid zero length\n", table_header->signature, entry_id);
>
> >>> Same here.
> >> How about remove the message and return directly?
> > We could do that, but for what reason? Is the message not useful?
>
> I agree with you, the message is useful I think, how about the comments above?

Please see above.

--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

2014-11-26 01:43:41

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 02/18] ACPI / table: Add new function to get table entries

On 2014/11/26 5:20, Rafael J. Wysocki wrote:
> On Tuesday, November 25, 2014 11:38:05 AM Hanjun Guo wrote:
>> On 2014/11/24 22:51, Rafael J. Wysocki wrote:
>>> On Monday, November 24, 2014 07:03:54 PM Hanjun Guo wrote:
>>>> On 2014-11-24 9:27, Rafael J. Wysocki wrote:
>>>>> On Friday, October 17, 2014 09:36:58 PM Hanjun Guo wrote:
>>>>>> From: Ashwin Chaugule <[email protected]>
>>>>>>
>>>>>> The acpi_table_parse() function has a callback that
>>>>>> passes a pointer to a table_header. Add a new function
>>>>>> which takes this pointer and parses its entries. This
>>>>>> eliminates the need to re-traverse all the tables for
>>>>>> each call. e.g. as in acpi_table_parse_madt() which is
>>>>>> normally called after acpi_table_parse().
>>>>>>
>>>>>> Acked-by: Grant Likely <[email protected]>
>>>>>> Signed-off-by: Ashwin Chaugule <[email protected]>
>>>>>> Signed-off-by: Tomasz Nowicki <[email protected]>
>>>>>> Signed-off-by: Hanjun Guo <[email protected]>
>>>>>> ---
>>>>>> drivers/acpi/tables.c | 67 ++++++++++++++++++++++++++++++++++---------------
>>>>>> include/linux/acpi.h | 4 +++
>>>>>> 2 files changed, 51 insertions(+), 20 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
>>>>>> index 6d5a6cd..21ae521 100644
>>>>>> --- a/drivers/acpi/tables.c
>>>>>> +++ b/drivers/acpi/tables.c
>>>>>> @@ -192,17 +192,14 @@ void acpi_table_print_madt_entry(struct acpi_subtable_header *header)
>>>>>>
>>>>>>
>>>>>> int __init
>>>>>> -acpi_table_parse_entries(char *id,
>>>>>> - unsigned long table_size,
>>>>>> - int entry_id,
>>>>>> - acpi_tbl_entry_handler handler,
>>>>>> - unsigned int max_entries)
>>>>>> +acpi_parse_entries(unsigned long table_size,
>>>>>> + acpi_tbl_entry_handler handler,
>>>>>> + struct acpi_table_header *table_header,
>>>>>> + int entry_id, unsigned int max_entries)
>>>>>> {
>>>>>> - struct acpi_table_header *table_header = NULL;
>>>>>> struct acpi_subtable_header *entry;
>>>>>> - unsigned int count = 0;
>>>>>> + int count = 0;
>>>>>> unsigned long table_end;
>>>>>> - acpi_size tbl_size;
>>>>>>
>>>>>> if (acpi_disabled)
>>>>>> return -ENODEV;
>>>>>> @@ -210,13 +207,11 @@ acpi_table_parse_entries(char *id,
>>>>>> if (!handler)
>>>>>> return -EINVAL;
>>>>>>
>>>>>> - if (strncmp(id, ACPI_SIG_MADT, 4) == 0)
>>>>>> - acpi_get_table_with_size(id, acpi_apic_instance, &table_header, &tbl_size);
>>>>>> - else
>>>>>> - acpi_get_table_with_size(id, 0, &table_header, &tbl_size);
>>>>>> + if (!table_size)
>>>>>> + return -EINVAL;
>>>>>>
>>>>>> if (!table_header) {
>>>>>> - pr_warn("%4.4s not present\n", id);
>>>>>> + pr_warn("Table header not present\n");
>>>>> The message doesn't make sense any more if the table signature is not printed.
>> For this message, since no table id is passed, and this message is printed in
>> acpi_table_parse_entries() before this function is called, I think we can check
>> the table_header before call this function and remove the printed message here.
> table_header needs to be checked against NULL in the caller and the message
> printed from there to my eyes.

ok, I think table id should pass to this function, I will rework this patch
and resend.

Thanks
Hanjun

2014-12-18 20:01:52

by Suthikulpanit, Suravee

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

On 10/17/2014 8:37 AM, Hanjun Guo wrote:

> From: Graeme Gregory <[email protected]>
>
> Add documentation for the guidelines of how to use ACPI
> on ARM64.
>
> Signed-off-by: Graeme Gregory <[email protected]>
> Signed-off-by: Al Stone <[email protected]>
> Signed-off-by: Hanjun Guo <[email protected]>
> ---
> Documentation/arm64/arm-acpi.txt | 323
> ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 323 insertions(+)
> create mode 100644 Documentation/arm64/arm-acpi.txt
>[...]

AMD has reviewed this document, and currently implements ACPI table in
the firmware for AMD Seattle platform based on the documentation
published here:

http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Seattle_ACPI_Guide.pdf

Reviewed-by: Suravee Suthikulpanit <[email protected]>

Thank you,

Suravee

2014-12-18 20:04:10

by Timur Tabi

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

On Fri, Oct 17, 2014 at 8:37 AM, Hanjun Guo <[email protected]> wrote:

> If acpi=force is used, the kernel
> +will ONLY use device configuration information contained in the ACPI tables.

Based on this statement, ...

> +In order for the kernel to load and use ACPI tables, the UEFI implementation
> +MUST set the ACPI_20_TABLE_GUID to point to the RSDP table (the table with
> +the ACPI signature "RSD PTR "). If this pointer is incorrect and acpi=force
> +is used, the kernel will disable ACPI and try to use DT to boot.

wouldn't it be more correct to say "If this pointer is incorrect OR
acpi=force is used"?

> +Forum provides a mechanism for registering such bindings [URL TBD by ASWG]

Did you intend to replace the text in []?

> +so that they may be used on any operating system supporting ACPI. Device
> +properties that have not been registered with the UEFI Forum should not be
> +used.

Blech. I guess it's necessary, but the information needs to be documented here.

> +Drivers should look for device properties in the _DSD object ONLY; the _DSD
> +object is described in the ACPI specification section 6.2.5, but more
> +specifically, use the _DSD Device Properties UUID:
> +
> + -- UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301
> +
> + -- http://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf)

Extra ) here.

> +The kernel has an interface for looking up device properties in a manner
> +independent of whether DT or ACPI is being used and that interface should
> +be used; it can eliminate some duplication of code paths in driver probing
> +functions and discourage divergence between DT bindings and ACPI device
> +properties.

How about a pointer to the documentation for this method?

> +Such code in _PS? methods will of course be very platform specific. But,

I would use _PSx instead of _PS? here.

> +this allows the driver to abstract out the interface for operating the device
> +and avoid having to read special non-standard values from ACPI tables. Further,
> +abstracting the use of these resources allows the hardware to change over time
> +without requiring updates to the driver.
> +
> +
> +Clocks
> +------
> +ACPI makes the assumption that clocks are initialized by the firmware --
> +UEFI, in this case -- to some working value before control is handed over
> +to the kernel. This has implications for devices such as UARTs, or SoC
> +driven LCD displays, for example.

SOC-driven should be hyphenated.

> +When the kernel boots, the clock is assumed to be set to reasonable

to A reasonable

> +working value. If for some reason the frequency needs to change -- e.g.,
> +throttling for power management -- the device driver should expect that
> +process to be abstracted out into some ACPI method that can be invoked
> +(please see the ACPI specification for further recommendations on standard
> +methods to be expected). If is not, there is no direct way for ACPI to

If IT is not

> +control the clocks.
> +
> +
> +Driver Recommendations
> +----------------------
> +DO NOT remove any DT handling when adding ACPI support for a driver. The
> +same device may be used on many different systems.
> +
> +DO try to structure the driver so that it is data driven. That is, set up

data-driven


--
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.

2014-12-19 13:05:00

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

On 2014年12月19日 04:01, Suravee Suthikulanit wrote:
> On 10/17/2014 8:37 AM, Hanjun Guo wrote:
>
>> From: Graeme Gregory <[email protected]>
>>
>> Add documentation for the guidelines of how to use ACPI
>> on ARM64.
>>
>> Signed-off-by: Graeme Gregory <[email protected]>
>> Signed-off-by: Al Stone <[email protected]>
>> Signed-off-by: Hanjun Guo <[email protected]>
>> ---
>> Documentation/arm64/arm-acpi.txt | 323
>> ++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 323 insertions(+)
>> create mode 100644 Documentation/arm64/arm-acpi.txt
>> [...]
>
> AMD has reviewed this document, and currently implements ACPI table in
> the firmware for AMD Seattle platform based on the documentation
> published here:
>
> http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Seattle_ACPI_Guide.pdf
>
>
> Reviewed-by: Suravee Suthikulpanit <[email protected]>

Thank you very much, Suravee.

Hanjun

2014-12-19 13:53:31

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

Hi Timur,

On 2014年12月19日 04:04, Timur Tabi wrote:
> On Fri, Oct 17, 2014 at 8:37 AM, Hanjun Guo <[email protected]> wrote:
>
>> If acpi=force is used, the kernel
>> +will ONLY use device configuration information contained in the ACPI tables.
>
> Based on this statement, ...
>
>> +In order for the kernel to load and use ACPI tables, the UEFI implementation
>> +MUST set the ACPI_20_TABLE_GUID to point to the RSDP table (the table with
>> +the ACPI signature "RSD PTR "). If this pointer is incorrect and acpi=force
>> +is used, the kernel will disable ACPI and try to use DT to boot.
>
> wouldn't it be more correct to say "If this pointer is incorrect OR
> acpi=force is used"?

Good catch, some inconsistency here. Actually it means if the pointer to
RSDP is incorrect, the ACPI code will catch that error, then ACPI will
be disabled and tries to boot with DT even if acpi=force is passed, I
think that makes sense.

I will fix the inconsistency anyway in next version.

>
>> +Forum provides a mechanism for registering such bindings [URL TBD by ASWG]
>
> Did you intend to replace the text in []?

Yes, it is TBD by ASWG, and we already agreed that the bindings will be
reviewed by ASWG which proposed by Al. the URL will be ready when next
version of ACPI spec is released.

>
>> +so that they may be used on any operating system supporting ACPI. Device
>> +properties that have not been registered with the UEFI Forum should not be
>> +used.
>
> Blech. I guess it's necessary, but the information needs to be documented here.
>
>> +Drivers should look for device properties in the _DSD object ONLY; the _DSD
>> +object is described in the ACPI specification section 6.2.5, but more
>> +specifically, use the _DSD Device Properties UUID:
>> +
>> + -- UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301
>> +
>> + -- http://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf)
>
> Extra ) here.

Good catch :)

>
>> +The kernel has an interface for looking up device properties in a manner
>> +independent of whether DT or ACPI is being used and that interface should
>> +be used; it can eliminate some duplication of code paths in driver probing
>> +functions and discourage divergence between DT bindings and ACPI device
>> +properties.
>
> How about a pointer to the documentation for this method?

This is a patch set posted by Rafael and goes into 3.19:
https://lkml.org/lkml/2014/10/21/762

No documentation as far as I know.

>
>> +Such code in _PS? methods will of course be very platform specific. But,
>
> I would use _PSx instead of _PS? here.

I will update it.

>
>> +this allows the driver to abstract out the interface for operating the device
>> +and avoid having to read special non-standard values from ACPI tables. Further,
>> +abstracting the use of these resources allows the hardware to change over time
>> +without requiring updates to the driver.
>> +
>> +
>> +Clocks
>> +------
>> +ACPI makes the assumption that clocks are initialized by the firmware --
>> +UEFI, in this case -- to some working value before control is handed over
>> +to the kernel. This has implications for devices such as UARTs, or SoC
>> +driven LCD displays, for example.
>
> SOC-driven should be hyphenated.
>
>> +When the kernel boots, the clock is assumed to be set to reasonable
>
> to A reasonable
>
>> +working value. If for some reason the frequency needs to change -- e.g.,
>> +throttling for power management -- the device driver should expect that
>> +process to be abstracted out into some ACPI method that can be invoked
>> +(please see the ACPI specification for further recommendations on standard
>> +methods to be expected). If is not, there is no direct way for ACPI to
>
> If IT is not
>
>> +control the clocks.
>> +
>> +
>> +Driver Recommendations
>> +----------------------
>> +DO NOT remove any DT handling when adding ACPI support for a driver. The
>> +same device may be used on many different systems.
>> +
>> +DO try to structure the driver so that it is data driven. That is, set up
>
> data-driven

I will update them.

Thanks a lot for your review!

Hanjun

2014-12-24 17:18:30

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

Hi,

Some thoughts before the end of the year. I won't be able to follow up
until around 5th of January though.

On Fri, Oct 17, 2014 at 02:37:14PM +0100, Hanjun Guo wrote:
> --- /dev/null
> +++ b/Documentation/arm64/arm-acpi.txt
> @@ -0,0 +1,323 @@
> +ACPI on ARMv8 Servers
> +---------------------
> +ACPI can be used for ARMv8 general purpose servers designed to follow
> +the ARM SBSA (Server Base System Architecture) specification, currently
> +available to those with an ARM login at http://silver.arm.com.

You should mention SBBR (Server Base Boot Requirements) here as well.
The arm-acpi.txt is complementary to arm-acpi.txt and longer term we
should aim to move parts of the Linux document into the more OS-agonstic
SBBR.

> +The ARMv8 kernel implements the reduced hardware model of ACPI version
> +5.1 and its corresponding errata.

I would say 5.1 or later to avoid updating this document every time we
get a new ACPI release.

> +If an ARMv8 system does not meet the requirements of the SBSA, or cannot
> +be described using the mechanisms defined in the required ACPI specifications,
> +then it is likely that Device Tree (DT) is more suitable than ACPI for the
> +hardware.

Based on some private discussions, I think we could drop some of the
references to DT in this document. It should specify the requirements
for ACPI support and, if not met, the alternative SoC support is
automatically DT for Linux. That's just to make it easier to move parts
of this doc into SBBR.

> +Relationship with Device Tree
> +-----------------------------

This section is fine, Linux specific and it will stay in this document.

> +ACPI support in drivers and subsystems for ARMv8 should never be mutually
> +exclusive with DT support at compile time.
> +
> +At boot time the kernel will only use one description method depending on
> +parameters passed from the bootloader (including kernel bootargs).
> +
> +Regardless of whether DT or ACPI is used, the kernel must always be capable
> +of booting with either scheme (in kernels with both schemes enabled at compile
> +time).
> +
> +When booting using ACPI tables, the /chosen node in DT will still be parsed
> +to extract the kernel command line and initrd path. No other section of the
> +DT will be used.

I don't think this paragraph is needed. That's a kernel detail when how
the EFI_STUB passes the information to the rest of the kernel. We
mandate UEFI booting for ACPI support, so I wouldn't expect an
ACPI-aware U-Boot.

> +Booting using ACPI tables
> +-------------------------
> +The only defined method for passing ACPI tables to the kernel on ARMv8
> +is via the UEFI system configuration table.
> +
> +Processing of ACPI tables may be disabled by passing acpi=off on the kernel
> +command line; this is the default behavior. If acpi=force is used, the kernel
> +will ONLY use device configuration information contained in the ACPI tables.

See my comments to Al around the defaults. I think if only ACPI tables
are present, we shouldn't panic the kernel if acpi=force is missing but
continue with ACPI. If both DT and ACPI tables are present, DT will be
the default. You could say "this is the default behaviour if both ACPI
and DT tables are present".

> +Device Enumeration
> +------------------
> +Device descriptions in ACPI should use standard recognized ACPI interfaces.
> +These can contain less information than is typically provided via a Device

s/can/may/ ? Not sure, it just sounds better to me (not a native English
speaker).

> +Tree description for the same device. This is also one of the reasons that
> +ACPI can be useful -- the driver takes into account that it may have less
> +detailed information about the device and uses sensible defaults instead.
> +If done properly in the driver, the hardware can change and improve over
> +time without the driver having to change at all.
> +
> +Clocks provide an excellent example. In DT, clocks need to be specified
> +and the drivers need to take them into account. In ACPI, the assumption
> +is that UEFI will leave the device in a reasonable default state, including
> +any clock settings. If for some reason the driver needs to change a clock
> +value, this can be done in an ACPI method; all the driver needs to do is
> +invoke the method and not concern itself with what the method needs to do
> +to change the clock. Changing the hardware can then take place over time
> +by changing what the ACPI method does, and not the driver.
> +
> +ACPI drivers should only look at one specific ASL object -- the _DSD object
> +-- for device driver parameters (known in DT as "bindings", or "Device
> +Properties" in ACPI). Not all DT bindings will be recognized.

This last sentence kind of implies that many of the DT bindings will be
recognised. While it is useful to have some commonalities, I think this
gives the wrong message that _DSD is a copy of DT. We should avoid this.

> The UEFI
> +Forum provides a mechanism for registering such bindings [URL TBD by ASWG]

s/bindings/properties/ if we talk in the ACPI context.

> +so that they may be used on any operating system supporting ACPI. Device
> +properties that have not been registered with the UEFI Forum should not be
> +used.

More about this further down.

> +Drivers should look for device properties in the _DSD object ONLY; the _DSD
> +object is described in the ACPI specification section 6.2.5, but more
> +specifically, use the _DSD Device Properties UUID:
> +
> + -- UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301
> +
> + -- http://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf)
> +
> +The kernel has an interface for looking up device properties in a manner
> +independent of whether DT or ACPI is being used and that interface should
> +be used;

I haven't followed the _DSD kernel support but does it provide a common
API to be shared with DT? I'm not entirely convinced it's a good idea.

> it can eliminate some duplication of code paths in driver probing
> +functions and discourage divergence between DT bindings and ACPI device
> +properties.

Given the current different mechanism of reviewing/approving bindings
between DT and ACPI (kernel community vs UEFI forum), I don't see how we
encourage convergence (unless we state that _DSD are Linux-only, Windows
should use a different mechanism like .inf files).

> +ACPI tables are described with a formal language called ASL, the ACPI
> +Source Language (section 19 of the specification). This means that there
> +are always multiple ways to describe the same thing -- including device
> +properties. For example, device properties could use an ASL construct
> +that looks like this: Name(KEY0, "value0"). An ACPI device driver would
> +then retrieve the value of the property by evaluating the KEY0 object.
> +However, using Name() this way has multiple problems: (1) ACPI limits
> +names ("KEY0") to four characters unlike DT; (2) there is no industry
> +wide registry that maintains a list of names, minimzing re-use; (3)
> +there is also no registry for the definition of property values ("value0"),
> +again making re-use difficult; and (4) how does one maintain backward
> +compatibility as new hardware comes out? The _DSD method was created
> +to solve precisely these sorts of problems; Linux drivers should ALWAYS
> +use the _DSD method for device properties and nothing else.
> +
> +The _DSM object (ACPI Section 9.14.1) could also be used for conveying
> +device properties to a driver. Linux drivers should only expect it to
> +be used if _DSD cannot represent the data required, and there is no way
> +to create a new UUID for the _DSD object. Note that there is even less
> +regulation of the use of _DSM than there is of _DSD. Drivers that depend
> +on the contents of _DSM objects will be more difficult to maintain over
> +time because of this.
> +
> +The _DSD object is a very flexible mechanism in ACPI, as are the registered
> +Device Properties. This flexibility allows _DSD to cover more than just the
> +generic server case and care should be taken in device drivers not to expect
> +it to replicate highly specific embedded behaviour from DT.

While this is all good, we need to be more specific on what "embedded
behaviour" means. Maybe not for this document but the UEFI approval
process for new properties doesn't give any hint on what is and is not
sane (and I already disagree with some of the examples on uefi.org).

> +Both DT bindings and ACPI device properties for device drivers have review
> +processes. Use them. And, before creating new device properties, check to
> +be sure that they have not been defined before and either registered in the
> +Linux kernel documentation or the UEFI Forum. If the device drivers supports
> +ACPI and DT, please make sure the device properties are consistent in both
> +places.

In the interest of progress, I think we need to *temporarily* ban the
use of _DSD on ARM platforms aimed at ACPI and state it clearly in this
document. Once we are happy with the UEFI forum review process, we'll
adjust the document accordingly.

My problems with _DSD:

a) no clear guidance on what a good property means, whether it covers
just device specific information or it may include Linux behaviour
(like "linux,default-trigger", I don't think it should)
b) the Linux kernel community does not seem to be involved in the UEFI
forum _DSD review process. This means that we'll be faced with
patches against drivers to support UEFI-published _DSD properties.
I want to avoid such arguments, rejecting kernel code is too late
after _DSD properties have been published

The alternative to _DSD would be to program the hardware to some sane
state. For example, I'm sure a MAC address can be written by firmware to
some register and the driver can read and store it locally (I'm not even
sure why we need MAC address in ACPI tables, this is not really a
property of the hardware but a configuration that could be done in
firmware).

> +Clocks
> +------
> +ACPI makes the assumption that clocks are initialized by the firmware --
> +UEFI, in this case -- to some working value before control is handed over
> +to the kernel. This has implications for devices such as UARTs, or SoC
> +driven LCD displays, for example.
> +
> +When the kernel boots, the clock is assumed to be set to reasonable
> +working value. If for some reason the frequency needs to change -- e.g.,
> +throttling for power management -- the device driver should expect that
> +process to be abstracted out into some ACPI method that can be invoked
> +(please see the ACPI specification for further recommendations on standard
> +methods to be expected). If is not, there is no direct way for ACPI to
> +control the clocks.

I would emphasize that there is no way for _Linux_ to directly control the
clocks on an ACPI-enabled platform.

> +ASWG
> +----
> +The following areas are not yet fully defined for ARM in the 5.1 version
> +of the ACPI specification and are expected to be worked through in the
> +UEFI ACPI Specification Working Group (ASWG):
> +
> + -- ACPI based CPU topology
> + -- ACPI based Power management
> + -- CPU idle control based on PSCI
> + -- CPU performance control (CPPC)
> + -- ACPI based SMMU
> + -- ITS support for GIC in MADT

In addition to the above and _DSD requirements/banning, I would also add
some clear statements around:

_OSC: only global/published capabilities are allowed. For
device-specific _OSC we need a process or maybe we can ban them entirely
and rely on _DSD once we clarify the process.

_OSI: firmware must not check for certain _OSI strings. Here I'm not
sure what we would have to do for ARM Linux. Reporting "Windows" does
not make any sense but not reporting anything can, as Matthew Garrett
pointed out, can be interpreted by firmware as "Linux". In addition to
any statements in this document, I suggest you patch
drivers/acpi/acpica/utosi.c accordingly, maybe report "Linux" for ARM
and print a kernel warning so that we notice earlier.

ACPI_OS_NAME: this is globally defined as "Microsoft Windows NT". It
doesn't make much sense in the ARM context. Could we change it to
"Linux" when CONFIG_ARM64?

Compatibility with older kernels: ACPI firmware must work, even though
not fully optimal, with the earliest kernel version implementing the
targeted ACPI spec. There may be a need for new drivers but otherwise
adding things like CPU power management should not break older kernel
versions. In addition, the ACPI firmware must also work with the latest
kernel version.


I strongly consider that we need to be very strict with the Linux ACPI
firmware and hardware requirements to avoid the need for supporting
non-standard implementations as much as possible. This is, however, a
live document, so we can relax it as we see fit (e.g. _DSD process
clarified).

In the meantime, Merry Christmas ;). I'll follow up in January.

--
Catalin

2014-12-24 19:34:51

by Jon Masters

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

Hi Catalin,

Good feedback. In particular, though we have only one example of _DSD (network parameters because the hardware might be reset post boot and some of it is not sophisticated enough to preserve programmed MAC and parameters such as PHy type that will require reloading, both because drivers might be reprobed or because we might reboot or kexec) it is reasonable not to pull support for that into upstream on a short term basis while some of the process is codified. Generally with _DSD I know nobody is implementing anything else in the medium term and have ensured the vendors concerned have had private conversations to ensure existing _DSD entries in DSDTs out there conform to those proposed and are all self consistent (and are supported in certain other kernels so far). But for now that can suffice until the process is codified to a level everyone is comfortable with - certainly we would not expect growth there in the short term and would absolutely not expect DT entries to be arbitrarily carried over.

Also, I agree with the sentiments around codifying into the SBBR. Upstream kernel docs should pertain to Linux, but ideally non OS specifics will live in the SBBR. As one of the original coauthors of the SBBR I know our intention is to grow that document into a more complete platform doc. With that in mind, I will be donating Red Hat's commercial hardware requirements (shared with vendors in separate discussions) as input into that process in 2015.

Jon.

--
Computer Architect | Sent from my #ARM Powered Mobile Device

On Dec 24, 2014 5:18 PM, Catalin Marinas <[email protected]> wrote:
>
> Hi,
>
> Some thoughts before the end of the year. I won't be able to follow up
> until around 5th of January though.
>
> On Hi,

Some thoughts before the end of the year. I won't be able to follow up
until around 5th of January though.

On Fri, Oct 17, 2014 at 02:37:14PM +0100, Hanjun Guo wrote:
> --- /dev/null
> +++ b/Documentation/arm64/arm-acpi.txt
> @@ -0,0 +1,323 @@
> +ACPI on ARMv8 Servers
> +---------------------
> +ACPI can be used for ARMv8 general purpose servers designed to follow
> +the ARM SBSA (Server Base System Architecture) specification, currently
> +available to those with an ARM login at http://silver.arm.com.

You should mention SBBR (Server Base Boot Requirements) here as well.
The arm-acpi.txt is complementary to arm-acpi.txt and longer term we
should aim to move parts of the Linux document into the more OS-agonstic
SBBR.

> +The ARMv8 kernel implements the reduced hardware model of ACPI version
> +5.1 and its corresponding errata.

I would say 5.1 or later to avoid updating this document every time we
get a new ACPI release.

> +If an ARMv8 system does not meet the requirements of the SBSA, or cannot
> +be described using the mechanisms defined in the required ACPI specifications,
> +then it is likely that Device Tree (DT) is more suitable than ACPI for the
> +hardware.

Based on some private discussions, I think we could drop some of the
references to DT in this document. It should specify the requirements
for ACPI support and, if not met, the alternative SoC support is
automatically DT for Linux. That's just to make it easier to move parts
of this doc into SBBR.

> +Relationship with Device Tree
> +-----------------------------

This section is fine, Linux specific and it will stay in this document.

> +ACPI support in drivers and subsystems for ARMv8 should never be mutually
> +exclusive with DT support at compile time.
> +
> +At boot time the kernel will only use one description method depending on
> +parameters passed from the bootloader (including kernel bootargs).
> +
> +Regardless of whether DT or ACPI is used, the kernel must always be capable
> +of booting with either scheme (in kernels with both schemes enabled at compile
> +time).
> +
> +When booting using ACPI tables, the /chosen node in DT will still be parsed
> +to extract the kernel command line and initrd path. No other section of the
> +DT will be used.

I don't think this paragraph is needed. That's a kernel detail when how
the EFI_STUB passes the information to the rest of the kernel. We
mandate UEFI booting for ACPI support, so I wouldn't expect an
ACPI-aware U-Boot.

> +Booting using ACPI tables
> +-------------------------
> +The only defined method for passing ACPI tables to the kernel on ARMv8
> +is via the UEFI system configuration table.
> +
> +Processing of ACPI tables may be disabled by passing acpi=off on the kernel
> +command line; this is the default behavior. If acpi=force is used, the kernel
> +will ONLY use device configuration information contained in the ACPI tables.

See my comments to Al around the defaults. I think if only ACPI tables
are present, we shouldn't panic the kernel if acpi=force is missing but
continue with ACPI. If both DT and ACPI tables are present, DT will be
the default. You could say "this is the default behaviour if both ACPI
and DT tables are present".

> +Device Enumeration
> +------------------
> +Device descriptions in ACPI should use standard recognized ACPI interfaces.
> +These can contain less information than is typically provided via a Device

s/can/may/ ? Not sure, it just sounds better to me (not a native English
speaker).

> +Tree description for the same device. This is also one of the reasons that
> +ACPI can be useful -- the driver takes into account that it may have less
> +detailed information about the device and uses sensible defaults instead.
> +If done properly in the driver, the hardware can change and improve over
> +time without the driver having to change at all.
> +
> +Clocks provide an excellent example. In DT, clocks need to be specified
> +and the drivers need to take them into account. In ACPI, the assumption
> +is that UEFI will leave the device in a reasonable default state, including
> +any clock settings. If for some reason the driver needs to change a clock
> +value, this can be done in an ACPI method; all the driver needs to do is
> +invoke the method and not concern itself with what the method needs to do
> +to change the clock. Changing the hardware can then take place over time
> +by changing what the ACPI method does, and not the driver.
> +
> +ACPI drivers should only look at one specific ASL object -- the _DSD object
> +-- for device driver parameters (known in DT as "bindings", or "Device
> +Properties" in ACPI). Not all DT bindings will be recognized.

This last sentence kind of implies that many of the DT bindings will be
recognised. While it is useful to have some commonalities, I think this
gives the wrong message that _DSD is a copy of DT. We should avoid this.

> The UEFI
> +Forum provides a mechanism for registering such bindings [URL TBD by ASWG]

s/bindings/properties/ if we talk in the ACPI context.

> +so that they may be used on any operating system supporting ACPI. Device
> +properties that have not been registered with the UEFI Forum should not be
> +used.

More about this further down.

> +Drivers should look for device properties in the _DSD object ONLY; the _DSD
> +object is described in the ACPI specification section 6.2.5, but more
> +specifically, use the _DSD Device Properties UUID:
> +
> + -- UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301
> +
> + -- http://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf)
> +
> +The kernel has an interface for looking up device properties in a manner
> +independent of whether DT or ACPI is being used and that interface should
> +be used;

I haven't followed the _DSD kernel support but does it provide a common
API to be shared with DT? I'm not entirely convinced it's a good idea.

> it can eliminate some duplication of code paths in driver probing
> +functions and discourage divergence between DT bindings and ACPI device
> +properties.

Given the current different mechanism of reviewing/approving bindings
between DT and ACPI (kernel community vs UEFI forum), I don't see how we
encourage convergence (unless we state that _DSD are Linux-only, Windows
should use a different mechanism like .inf files).

> +ACPI tables are described with a formal language called ASL, the ACPI
> +Source Language (section 19 of the specification). This means that there
> +are always multiple ways to describe the same thing -- including device
> +properties. For example, device properties could use an ASL construct
> +that looks like this: Name(KEY0, "value0"). An ACPI device driver would
> +then retrieve the value of the property by evaluating the KEY0 object.
> +However, using Name() this way has multiple problems: (1) ACPI limits
> +names ("KEY0") to four characters unlike DT; (2) there is no industry
> +wide registry that maintains a list of names, minimzing re-use; (3)
> +there is also no registry for the definition of property values ("value0"),
> +again making re-use difficult; and (4) how does one maintain backward
> +compatibility as new hardware comes out? The _DSD method was created
> +to solve precisely these sorts of problems; Linux drivers should ALWAYS
> +use the _DSD method for device properties and nothing else.
> +
> +The _DSM object (ACPI Section 9.14.1) could also be used for conveying
> +device properties to a driver. Linux drivers should only expect it to
> +be used if _DSD cannot represent the data required, and there is no way
> +to create a new UUID for the _DSD object. Note that there is even less
> +regulation of the use of _DSM than there is of _DSD. Drivers that depend
> +on the contents of _DSM objects will be more difficult to maintain over
> +time because of this.
> +
> +The _DSD object is a very flexible mechanism in ACPI, as are the registered
> +Device Properties. This flexibility allows _DSD to cover more than just the
> +generic server case and care should be taken in device drivers not to expect
> +it to replicate highly specific embedded behaviour from DT.

While this is all good, we need to be more specific on what "embedded
behaviour" means. Maybe not for this document but the UEFI approval
process for new properties doesn't give any hint on what is and is not
sane (and I already disagree with some of the examples on uefi.org).

> +Both DT bindings and ACPI device properties for device drivers have review
> +processes. Use them. And, before creating new device properties, check to
> +be sure that they have not been defined before and either registered in the
> +Linux kernel documentation or the UEFI Forum. If the device drivers supports
> +ACPI and DT, please make sure the device properties are consistent in both
> +places.

In the interest of progress, I think we need to *temporarily* ban the
use of _DSD on ARM platforms aimed at ACPI and state it clearly in this
document. Once we are happy with the UEFI forum review process, we'll
adjust the document accordingly.

My problems with _DSD:

a) no clear guidance on what a good property means, whether it covers
just device specific information or it may include Linux behaviour
(like "linux,default-trigger", I don't think it should)
b) the Linux kernel community does not seem to be involved in the UEFI
forum _DSD review process. This means that we'll be faced with
patches against drivers to support UEFI-published _DSD properties.
I want to avoid such arguments, rejecting kernel code is too late
after _DSD properties have been published

The alternative to _DSD would be to program the hardware to some sane
state. For example, I'm sure a MAC address can be written by firmware to
some register and the driver can read and store it locally (I'm not even
sure why we need MAC address in ACPI tables, this is not really a
property of the hardware but a configuration that could be done in
firmware).

> +Clocks
> +------
> +ACPI makes the assumption that clocks are initialized by the firmware --
> +UEFI, in this case -- to some working value before control is handed over
> +to the kernel. This has implications for devices such as UARTs, or SoC
> +driven LCD displays, for example.
> +
> +When the kernel boots, the clock is assumed to be set to reasonable
> +working value. If for some reason the frequency needs to change -- e.g.,
> +throttling for power management -- the device driver should expect that
> +process to be abstracted out into some ACPI method that can be invoked
> +(please see the ACPI specification for further recommendations on standard
> +methods to be expected). If is not, there is no direct way for ACPI to
> +control the clocks.

I would emphasize that there is no way for _Linux_ to directly control the
clocks on an ACPI-enabled platform.

> +ASWG
> +----
> +The following areas are not yet fully defined for ARM in the 5.1 version
> +of the ACPI specification and are expected to be worked through in the
> +UEFI ACPI Specification Working Group (ASWG):
> +
> + -- ACPI based CPU topology
> + -- ACPI based Power management
> + -- CPU idle control based on PSCI
> + -- CPU performance control (CPPC)
> + -- ACPI based SMMU
> + -- ITS support for GIC in MADT

In addition to the above and _DSD requirements/banning, I would also add
some clear statements around:

_OSC: only global/published capabilities are allowed. For
device-specific _OSC we need a process or maybe we can ban them entirely
and rely on _DSD once we clarify the process.

_OSI: firmware must not check for certain _OSI strings. Here I'm not
sure what we would have to do for ARM Linux. Reporting "Windows" does
not make any sense but not reporting anything can, as Matthew Garrett
pointed out, can be interpreted by firmware as "Linux". In addition to
any statements in this document, I suggest you patch
drivers/acpi/acpica/utosi.c accordingly, maybe report "Linux" for ARM
and print a kernel warning so that we notice earlier.

ACPI_OS_NAME: this is globally defined as "Microsoft Windows NT". It
doesn't make much sense in the ARM context. Could we change it to
"Linux" when CONFIG_ARM64?

Compatibility with older kernels: ACPI firmware must work, even though
not fully optimal, with the earliest kernel version implementing the
targeted ACPI spec. There may be a need for new drivers but otherwise
adding things like CPU power management should not break older kernel
versions. In addition, the ACPI firmware must also work with the latest
kernel version.


I strongly consider that we need to be very strict with the Linux ACPI
firmware and hardware requirements to avoid the need for supporting
non-standard implementations as much as possible. This is, however, a
live document, so we can relax it as we see fit (e.g. _DSD process
clarified).

In the meantime, Merry Christmas ;). I'll follow up in January.

--
Catalin

2014-12-26 13:24:42

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

On Wed, Dec 24, 2014 at 05:18:15PM +0000, Catalin Marinas wrote:
> On Fri, Oct 17, 2014 at 02:37:14PM +0100, Hanjun Guo wrote:

> > +ACPI drivers should only look at one specific ASL object -- the _DSD object
> > +-- for device driver parameters (known in DT as "bindings", or "Device
> > +Properties" in ACPI). Not all DT bindings will be recognized.

> This last sentence kind of implies that many of the DT bindings will be
> recognised. While it is useful to have some commonalities, I think this
> gives the wrong message that _DSD is a copy of DT. We should avoid this.

> > +so that they may be used on any operating system supporting ACPI. Device
> > +properties that have not been registered with the UEFI Forum should not be
> > +used.

> More about this further down.

Indeed...

> > +Drivers should look for device properties in the _DSD object ONLY; the _DSD
> > +object is described in the ACPI specification section 6.2.5, but more
> > +specifically, use the _DSD Device Properties UUID:

> > + -- UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301

> > + -- http://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf)

> > +The kernel has an interface for looking up device properties in a manner
> > +independent of whether DT or ACPI is being used and that interface should
> > +be used;

> I haven't followed the _DSD kernel support but does it provide a common
> API to be shared with DT? I'm not entirely convinced it's a good idea.

Yes, it does. I'm not entirely convinced about that either but it
really meets the goals of some of the users. Right now I'm seeing
several user communities:

- x86 server
- x86 laptop
- x86 embedded
- ARM server

The _DSD/DT abstraction API is intended to meet the needs of the x86
embedded community, they are really only interested in Linux and just
want to be able to pick up Linux drivers that have been developed with
DT in mind and use them with the minimum fuss. They are, to a good
approximation, not really interested in UEFI and ACPI per se.

> > it can eliminate some duplication of code paths in driver probing
> > +functions and discourage divergence between DT bindings and ACPI device
> > +properties.

> Given the current different mechanism of reviewing/approving bindings
> between DT and ACPI (kernel community vs UEFI forum), I don't see how we

Right now there is no real way of reviewing and approving bindings for
_DSD.

> encourage convergence (unless we state that _DSD are Linux-only, Windows
> should use a different mechanism like .inf files).

No, I don't think we want to encourage that. It's what's happening
right now for the x86 laptop case and it's making things miserable for
people working with audio, what we end up with on the Linux side is
needing to have per-machine quirk tables which means that Linux has
little chance of working out of the box with unknown hardware. It's bad
for users and not a lot of fun for developers. What you're saying is
fine for the x86 embedded people but as soon as we want to run both
Windows and Linux on the same system we want to try to make sure that
the firmware itself describes the hardware.

Note also that there are already some non-_DSD ways of passing platform
data to ACPI devices (you can read at least integer properties easily)
so it's not just _DSD we have to consider here.

> > +The _DSD object is a very flexible mechanism in ACPI, as are the registered
> > +Device Properties. This flexibility allows _DSD to cover more than just the
> > +generic server case and care should be taken in device drivers not to expect
> > +it to replicate highly specific embedded behaviour from DT.

> While this is all good, we need to be more specific on what "embedded
> behaviour" means. Maybe not for this document but the UEFI approval
> process for new properties doesn't give any hint on what is and is not
> sane (and I already disagree with some of the examples on uefi.org).

Right, though we also don't want the UEFI approval process to set down
standards that are too heavily tied to a specific view for ARM servers
since ARM servers are not the only users.

> My problems with _DSD:

> a) no clear guidance on what a good property means, whether it covers
> just device specific information or it may include Linux behaviour
> (like "linux,default-trigger", I don't think it should)

Right, though some people are going to want to do that.

> b) the Linux kernel community does not seem to be involved in the UEFI
> forum _DSD review process. This means that we'll be faced with
> patches against drivers to support UEFI-published _DSD properties.
> I want to avoid such arguments, rejecting kernel code is too late
> after _DSD properties have been published

I've been very concerned about this and chasing it up myself. As far as
I have been able to tell there essentially is no UEFI forum _DSD review
process at this point, the brief bits that are there are essentially
placeholders rather than actual practical things which people expect to
be viable long term and were placed there in the interests of getting
the actual stuff that goes into the tables approved. There was some
indication that there was an intention to have some discussion early
next year about doing it properly.

It'd certainly be good to get wider involvement from the kernel
community in that discussion, right now I'm a bit concerned that the
standardisation isn't going to be terribly effective in reaching
everyone it needs to or relevant to them.

Personally I'm mainly interested in making sure we can ideally
facilitate conversation with the Windows driver people and at worst can
set good practice standards for them which make life easier for Linux
when followed even if there's a degree of reverse engineerinng involved.

> The alternative to _DSD would be to program the hardware to some sane
> state. For example, I'm sure a MAC address can be written by firmware to
> some register and the driver can read and store it locally (I'm not even
> sure why we need MAC address in ACPI tables, this is not really a
> property of the hardware but a configuration that could be done in
> firmware).

On the other hand something like a MAC address is a useful placeholder
for discussion since there's no real debate about the technical aspects
of representing it allowing everyone to focus on the process.

> > +ASWG
> > +----
> > +The following areas are not yet fully defined for ARM in the 5.1 version
> > +of the ACPI specification and are expected to be worked through in the
> > +UEFI ACPI Specification Working Group (ASWG):

> > + -- ACPI based CPU topology
> > + -- ACPI based Power management
> > + -- CPU idle control based on PSCI
> > + -- CPU performance control (CPPC)
> > + -- ACPI based SMMU
> > + -- ITS support for GIC in MADT

> In addition to the above and _DSD requirements/banning, I would also add
> some clear statements around:

I'd not go that far with _DSD, I am unhappy with the current state of
the world but I'm not sure how relevant the process is going to be and
that anything more than a very strong disrecommendation is going to make
sense.

> Compatibility with older kernels: ACPI firmware must work, even though
> not fully optimal, with the earliest kernel version implementing the
> targeted ACPI spec. There may be a need for new drivers but otherwise
> adding things like CPU power management should not break older kernel
> versions. In addition, the ACPI firmware must also work with the latest
> kernel version.

The backwards compatibility thing sounds a bit strongly worded - I think
that's something the customers would probably sort out anyway to the
extent it's important. It's obviously good to recommend that people
keep as much backwards compatibility as they can since if nothing else
it makes it easier for people to use their hardware but it doesn't seem
unreasonable to decide that supporting older kernels (or more to the
point older distro releases) isn't that interesting for whatever reason.

> I strongly consider that we need to be very strict with the Linux ACPI
> firmware and hardware requirements to avoid the need for supporting
> non-standard implementations as much as possible. This is, however, a
> live document, so we can relax it as we see fit (e.g. _DSD process
> clarified).

To the extent that it is specific to ARM server that should be fine,
however when it comes to actually enforcing standards for how the kernel
behaves then that's a different story - there are other communities with
different goals and interests. This in turn means that there will be
things that actually practically work and that have become an ABI for
another community. Once that happens I'm not sure it's constructive to
try to enforce not using them on ARM, and if people manage to ship
systems we care about it's game over anyway.

I don't know that it's reasonable to expect people to enforce this from
the kernel side - with my subsystem maintainer hat on I really don't
know that I care if some ACPI thing is being done for the benefit of an
ARM server or if it's being done for the benefit of an x86 embedded box
and I'm actually interested.


Attachments:
(No filename) (8.98 kB)
signature.asc (473.00 B)
Digital signature
Download all attachments

2014-12-30 11:23:38

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

Hi,

On 2014年12月25日 01:18, Catalin Marinas wrote:
> Hi,
>
> Some thoughts before the end of the year. I won't be able to follow up
> until around 5th of January though.
>
> On Fri, Oct 17, 2014 at 02:37:14PM +0100, Hanjun Guo wrote:
>> --- /dev/null
>> +++ b/Documentation/arm64/arm-acpi.txt
>> @@ -0,0 +1,323 @@
>> +ACPI on ARMv8 Servers
>> +---------------------
>> +ACPI can be used for ARMv8 general purpose servers designed to follow
>> +the ARM SBSA (Server Base System Architecture) specification, currently
>> +available to those with an ARM login at http://silver.arm.com.
>
> You should mention SBBR (Server Base Boot Requirements) here as well.
> The arm-acpi.txt is complementary to arm-acpi.txt and longer term we
> should aim to move parts of the Linux document into the more OS-agonstic
> SBBR.

ok, I will update the doc. and I agree that moving parts of this doc
into SBBR, actually part of the content is coming from SBBR, especially
section "Booting using ACPI tables" (not include the command line part).
please refer to section 4.2 ACPI Tables in SBBR.

>
>> +The ARMv8 kernel implements the reduced hardware model of ACPI version
>> +5.1 and its corresponding errata.
>
> I would say 5.1 or later to avoid updating this document every time we
> get a new ACPI release.

sure, will update it.

>
>> +If an ARMv8 system does not meet the requirements of the SBSA, or cannot
>> +be described using the mechanisms defined in the required ACPI specifications,
>> +then it is likely that Device Tree (DT) is more suitable than ACPI for the
>> +hardware.
>
> Based on some private discussions, I think we could drop some of the
> references to DT in this document. It should specify the requirements
> for ACPI support and, if not met, the alternative SoC support is
> automatically DT for Linux. That's just to make it easier to move parts
> of this doc into SBBR.
>
>> +Relationship with Device Tree
>> +-----------------------------
>
> This section is fine, Linux specific and it will stay in this document.
>
>> +ACPI support in drivers and subsystems for ARMv8 should never be mutually
>> +exclusive with DT support at compile time.
>> +
>> +At boot time the kernel will only use one description method depending on
>> +parameters passed from the bootloader (including kernel bootargs).
>> +
>> +Regardless of whether DT or ACPI is used, the kernel must always be capable
>> +of booting with either scheme (in kernels with both schemes enabled at compile
>> +time).
>> +
>> +When booting using ACPI tables, the /chosen node in DT will still be parsed
>> +to extract the kernel command line and initrd path. No other section of the
>> +DT will be used.
>
> I don't think this paragraph is needed. That's a kernel detail when how
> the EFI_STUB passes the information to the rest of the kernel. We
> mandate UEFI booting for ACPI support, so I wouldn't expect an
> ACPI-aware U-Boot.

Agree, we can boot kernel ok without passing the dtb to kernel
in the command line if ACPI presents.

>
>> +Booting using ACPI tables
>> +-------------------------
>> +The only defined method for passing ACPI tables to the kernel on ARMv8
>> +is via the UEFI system configuration table.
>> +
>> +Processing of ACPI tables may be disabled by passing acpi=off on the kernel
>> +command line; this is the default behavior. If acpi=force is used, the kernel
>> +will ONLY use device configuration information contained in the ACPI tables.
>
> See my comments to Al around the defaults. I think if only ACPI tables
> are present, we shouldn't panic the kernel if acpi=force is missing but
> continue with ACPI.

I think we need another patch to implement it, for this patch set,kernel
will panic if no dtb and acpi=off. since passing no DT tables to OS but
acpi=force is missing is a corner case, we can do a follow up patch to
fix that, does it make sense?

> If both DT and ACPI tables are present, DT will be
> the default. You could say "this is the default behaviour if both ACPI
> and DT tables are present".
>
>> +Device Enumeration
>> +------------------
>> +Device descriptions in ACPI should use standard recognized ACPI interfaces.
>> +These can contain less information than is typically provided via a Device
>
> s/can/may/ ? Not sure, it just sounds better to me (not a native English
> speaker).
>
>> +Tree description for the same device. This is also one of the reasons that
>> +ACPI can be useful -- the driver takes into account that it may have less
>> +detailed information about the device and uses sensible defaults instead.
>> +If done properly in the driver, the hardware can change and improve over
>> +time without the driver having to change at all.
>> +
>> +Clocks provide an excellent example. In DT, clocks need to be specified
>> +and the drivers need to take them into account. In ACPI, the assumption
>> +is that UEFI will leave the device in a reasonable default state, including
>> +any clock settings. If for some reason the driver needs to change a clock
>> +value, this can be done in an ACPI method; all the driver needs to do is
>> +invoke the method and not concern itself with what the method needs to do
>> +to change the clock. Changing the hardware can then take place over time
>> +by changing what the ACPI method does, and not the driver.
>> +
>> +ACPI drivers should only look at one specific ASL object -- the _DSD object
>> +-- for device driver parameters (known in DT as "bindings", or "Device
>> +Properties" in ACPI). Not all DT bindings will be recognized.
>
> This last sentence kind of implies that many of the DT bindings will be
> recognised. While it is useful to have some commonalities, I think this
> gives the wrong message that _DSD is a copy of DT. We should avoid this.
>
>> The UEFI
>> +Forum provides a mechanism for registering such bindings [URL TBD by ASWG]
>
> s/bindings/properties/ if we talk in the ACPI context.
>
>> +so that they may be used on any operating system supporting ACPI. Device
>> +properties that have not been registered with the UEFI Forum should not be
>> +used.
>
> More about this further down.
>
>> +Drivers should look for device properties in the _DSD object ONLY; the _DSD
>> +object is described in the ACPI specification section 6.2.5, but more
>> +specifically, use the _DSD Device Properties UUID:
>> +
>> + -- UUID: daffd814-6eba-4d8c-8a91-bc9bbf4aa301
>> +
>> + -- http://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf)
>> +
>> +The kernel has an interface for looking up device properties in a manner
>> +independent of whether DT or ACPI is being used and that interface should
>> +be used;
>
> I haven't followed the _DSD kernel support but does it provide a common
> API to be shared with DT? I'm not entirely convinced it's a good idea.
>
>> it can eliminate some duplication of code paths in driver probing
>> +functions and discourage divergence between DT bindings and ACPI device
>> +properties.
>
> Given the current different mechanism of reviewing/approving bindings
> between DT and ACPI (kernel community vs UEFI forum), I don't see how we
> encourage convergence (unless we state that _DSD are Linux-only, Windows
> should use a different mechanism like .inf files).
>
>> +ACPI tables are described with a formal language called ASL, the ACPI
>> +Source Language (section 19 of the specification). This means that there
>> +are always multiple ways to describe the same thing -- including device
>> +properties. For example, device properties could use an ASL construct
>> +that looks like this: Name(KEY0, "value0"). An ACPI device driver would
>> +then retrieve the value of the property by evaluating the KEY0 object.
>> +However, using Name() this way has multiple problems: (1) ACPI limits
>> +names ("KEY0") to four characters unlike DT; (2) there is no industry
>> +wide registry that maintains a list of names, minimzing re-use; (3)
>> +there is also no registry for the definition of property values ("value0"),
>> +again making re-use difficult; and (4) how does one maintain backward
>> +compatibility as new hardware comes out? The _DSD method was created
>> +to solve precisely these sorts of problems; Linux drivers should ALWAYS
>> +use the _DSD method for device properties and nothing else.
>> +
>> +The _DSM object (ACPI Section 9.14.1) could also be used for conveying
>> +device properties to a driver. Linux drivers should only expect it to
>> +be used if _DSD cannot represent the data required, and there is no way
>> +to create a new UUID for the _DSD object. Note that there is even less
>> +regulation of the use of _DSM than there is of _DSD. Drivers that depend
>> +on the contents of _DSM objects will be more difficult to maintain over
>> +time because of this.
>> +
>> +The _DSD object is a very flexible mechanism in ACPI, as are the registered
>> +Device Properties. This flexibility allows _DSD to cover more than just the
>> +generic server case and care should be taken in device drivers not to expect
>> +it to replicate highly specific embedded behaviour from DT.
>
> While this is all good, we need to be more specific on what "embedded
> behaviour" means. Maybe not for this document but the UEFI approval
> process for new properties doesn't give any hint on what is and is not
> sane (and I already disagree with some of the examples on uefi.org).
>
>> +Both DT bindings and ACPI device properties for device drivers have review
>> +processes. Use them. And, before creating new device properties, check to
>> +be sure that they have not been defined before and either registered in the
>> +Linux kernel documentation or the UEFI Forum. If the device drivers supports
>> +ACPI and DT, please make sure the device properties are consistent in both
>> +places.
>
> In the interest of progress, I think we need to *temporarily* ban the
> use of _DSD on ARM platforms aimed at ACPI and state it clearly in this
> document. Once we are happy with the UEFI forum review process, we'll
> adjust the document accordingly.
>
> My problems with _DSD:
>
> a) no clear guidance on what a good property means, whether it covers
> just device specific information or it may include Linux behaviour
> (like "linux,default-trigger", I don't think it should)
> b) the Linux kernel community does not seem to be involved in the UEFI
> forum _DSD review process. This means that we'll be faced with
> patches against drivers to support UEFI-published _DSD properties.
> I want to avoid such arguments, rejecting kernel code is too late
> after _DSD properties have been published
>
> The alternative to _DSD would be to program the hardware to some sane
> state. For example, I'm sure a MAC address can be written by firmware to
> some register and the driver can read and store it locally (I'm not even
> sure why we need MAC address in ACPI tables, this is not really a
> property of the hardware but a configuration that could be done in
> firmware).
>
>> +Clocks
>> +------
>> +ACPI makes the assumption that clocks are initialized by the firmware --
>> +UEFI, in this case -- to some working value before control is handed over
>> +to the kernel. This has implications for devices such as UARTs, or SoC
>> +driven LCD displays, for example.
>> +
>> +When the kernel boots, the clock is assumed to be set to reasonable
>> +working value. If for some reason the frequency needs to change -- e.g.,
>> +throttling for power management -- the device driver should expect that
>> +process to be abstracted out into some ACPI method that can be invoked
>> +(please see the ACPI specification for further recommendations on standard
>> +methods to be expected). If is not, there is no direct way for ACPI to
>> +control the clocks.
>
> I would emphasize that there is no way for _Linux_ to directly control the
> clocks on an ACPI-enabled platform.
>
>> +ASWG
>> +----
>> +The following areas are not yet fully defined for ARM in the 5.1 version
>> +of the ACPI specification and are expected to be worked through in the
>> +UEFI ACPI Specification Working Group (ASWG):
>> +
>> + -- ACPI based CPU topology
>> + -- ACPI based Power management
>> + -- CPU idle control based on PSCI
>> + -- CPU performance control (CPPC)
>> + -- ACPI based SMMU
>> + -- ITS support for GIC in MADT
>
> In addition to the above and _DSD requirements/banning, I would also add
> some clear statements around:
>
> _OSC: only global/published capabilities are allowed. For
> device-specific _OSC we need a process or maybe we can ban them entirely
> and rely on _DSD once we clarify the process.
>
> _OSI: firmware must not check for certain _OSI strings. Here I'm not
> sure what we would have to do for ARM Linux. Reporting "Windows" does
> not make any sense but not reporting anything can, as Matthew Garrett
> pointed out, can be interpreted by firmware as "Linux". In addition to
> any statements in this document, I suggest you patch
> drivers/acpi/acpica/utosi.c accordingly, maybe report "Linux" for ARM
> and print a kernel warning so that we notice earlier.
>
> ACPI_OS_NAME: this is globally defined as "Microsoft Windows NT". It
> doesn't make much sense in the ARM context. Could we change it to
> "Linux" when CONFIG_ARM64?
>
> Compatibility with older kernels: ACPI firmware must work, even though
> not fully optimal, with the earliest kernel version implementing the
> targeted ACPI spec. There may be a need for new drivers but otherwise
> adding things like CPU power management should not break older kernel
> versions. In addition, the ACPI firmware must also work with the latest
> kernel version.
>
>
> I strongly consider that we need to be very strict with the Linux ACPI
> firmware and hardware requirements to avoid the need for supporting
> non-standard implementations as much as possible. This is, however, a
> live document, so we can relax it as we see fit (e.g. _DSD process
> clarified).
>
> In the meantime, Merry Christmas ;). I'll follow up in January.

I will send another version of patches based on 3.19-rc2, and I will
address some comments in that patch set, we can continue our discussion
here about doc for ACPI on ARM64.

Thanks
Hanjun

2014-12-30 20:14:04

by Ashwin Chaugule

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

Hi Hanjun,

Overall the document looks good to us. Some minor clarifications below.

> ---------- Forwarded message ----------
> From: Graeme Gregory <[email protected]>
>
> Add documentation for the guidelines of how to use ACPI
> on ARM64.
>
> Signed-off-by: Graeme Gregory <[email protected]>
> Signed-off-by: Al Stone <[email protected]>
> Signed-off-by: Hanjun Guo <[email protected]>
> ---
> Documentation/arm64/arm-acpi.txt | 323
> ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 323 insertions(+)
> create mode 100644 Documentation/arm64/arm-acpi.txt
>

[..]

> +Relationship with Device Tree
> +-----------------------------

[..]

> +When booting using ACPI tables, the /chosen node in DT will still be
> parsed
> +to extract the kernel command line and initrd path. No other section of
> the
> +DT will be used.

Is this still true?


> +Programmable Power Control Resources
> +------------------------------------
> +Programmable power control resources include such resources as
> voltage/current
> +providers (regulators) and clock sources.
> +
> +The kernel assumes that power control of these resources is represented
> with
> +Power Resource Objects (ACPI section 7.1). The ACPI core will then
> handle
> +correctly enabling and disabling resources as they are needed. In order
> to
> +get that to work, ACPI assumes each device has defined D-states and that
> these
> +can be controlled through the optional ACPI methods _PS0, _PS1, _PS2, and
> _PS3;
> +in ACPI, _PS0 is the method to invoke to turn a device full on, and _PS3
> is for
> +turning a device full off.
> +
> +The kernel ACPI code will also assume that the _PS? methods follow the
> normal
> +ACPI rules for such methods:
> +
> + -- If either _PS0 or _PS3 is implemented, then the other method must
> also
> + be implemented.
> +
> + -- If a device requires usage or setup of a power resource when on,
> the ASL
> + should organize that it is allocated/enabled using the _PS0 method.
> +
> + -- Resources allocated or enabled in the _PS0 method should be
> disabled
> + or de-allocated in the _PS3 method.
> +
> + -- Firmware will leave the resources in a reasonable state before
> handing
> + over control to the kernel.
> +

We found this section could be improved a bit by explicitly calling out
the options for handling device PM. Platform vendor has two choices.
Resources can be managed in _PSx routine which gets called on entry to Dx.
Or they can be declared separately as power resources with their own _ON
and _OFF methods. They are then tied back to D-states for a particular
device via _PRx which specifies which power resources a device needs to be
on while in Dx. Kernel then tracks number of devices using a power
resource and calls _ON/_OFF as needed.

> +Such code in _PS? methods will of course be very platform specific. But,
> +this allows the driver to abstract out the interface for operating the
> device
> +and avoid having to read special non-standard values from ACPI tables.
> Further,
> +abstracting the use of these resources allows the hardware to change over
> time
> +without requiring updates to the driver.
> +

I think its been mentioned in the past and you planned to add it here: we
should explicitly state that with ACPI, the kernel clock/vreg framework
are not expected to be used at all.

> +
> +Clocks
> +------
> +ACPI makes the assumption that clocks are initialized by the firmware --
> +UEFI, in this case -- to some working value before control is handed over
> +to the kernel. This has implications for devices such as UARTs, or SoC
> +driven LCD displays, for example.
> +
> +When the kernel boots, the clock is assumed to be set to reasonable
> +working value. If for some reason the frequency needs to change -- e.g.,
> +throttling for power management -- the device driver should expect that
> +process to be abstracted out into some ACPI method that can be invoked

Exception to this is CPU clocks where CPPC provides a much richer
interface than just blindly invoking some method.

> +(please see the ACPI specification for further recommendations on
> standard
> +methods to be expected). If is not, there is no direct way for ACPI to
> +control the clocks.
> +
> +

[..]

> +ASWG
> +----
> +The following areas are not yet fully defined for ARM in the 5.1 version
> +of the ACPI specification and are expected to be worked through in the
> +UEFI ACPI Specification Working Group (ASWG):
> +
> + -- ACPI based CPU topology
> + -- ACPI based Power management

Should clarify this to idle management rather than generic power management.

> + -- CPU idle control based on PSCI
> + -- CPU performance control (CPPC)

There is no ongoing work on CPPC. Additional enhancements may be explored
in the future, but spec is viable as is.

Regards,
Ashwin

--
Qualcomm Innovation Center, Inc
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

--

2014-12-31 08:35:02

by Hanjun Guo

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

On 2014年12月31日 04:13, [email protected] wrote:
> Hi Hanjun,
>
> Overall the document looks good to us. Some minor clarifications below.
>
>> ---------- Forwarded message ----------
>> From: Graeme Gregory <[email protected]>
>>
>> Add documentation for the guidelines of how to use ACPI
>> on ARM64.
>>
>> Signed-off-by: Graeme Gregory <[email protected]>
>> Signed-off-by: Al Stone <[email protected]>
>> Signed-off-by: Hanjun Guo <[email protected]>
>> ---
>> Documentation/arm64/arm-acpi.txt | 323
>> ++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 323 insertions(+)
>> create mode 100644 Documentation/arm64/arm-acpi.txt
>>
>
> [..]
>
>> +Relationship with Device Tree
>> +-----------------------------
>
> [..]
>
>> +When booting using ACPI tables, the /chosen node in DT will still be
>> parsed
>> +to extract the kernel command line and initrd path. No other section of
>> the
>> +DT will be used.
>
> Is this still true?

No, we can booting the ACPI system in EFI stub without dtb. Catalin
also pointed out this issue, I will remove this paragraph.

>
>
>> +Programmable Power Control Resources
>> +------------------------------------
>> +Programmable power control resources include such resources as
>> voltage/current
>> +providers (regulators) and clock sources.
>> +
>> +The kernel assumes that power control of these resources is represented
>> with
>> +Power Resource Objects (ACPI section 7.1). The ACPI core will then
>> handle
>> +correctly enabling and disabling resources as they are needed. In order
>> to
>> +get that to work, ACPI assumes each device has defined D-states and that
>> these
>> +can be controlled through the optional ACPI methods _PS0, _PS1, _PS2, and
>> _PS3;
>> +in ACPI, _PS0 is the method to invoke to turn a device full on, and _PS3
>> is for
>> +turning a device full off.
>> +
>> +The kernel ACPI code will also assume that the _PS? methods follow the
>> normal
>> +ACPI rules for such methods:
>> +
>> + -- If either _PS0 or _PS3 is implemented, then the other method must
>> also
>> + be implemented.
>> +
>> + -- If a device requires usage or setup of a power resource when on,
>> the ASL
>> + should organize that it is allocated/enabled using the _PS0 method.
>> +
>> + -- Resources allocated or enabled in the _PS0 method should be
>> disabled
>> + or de-allocated in the _PS3 method.
>> +
>> + -- Firmware will leave the resources in a reasonable state before
>> handing
>> + over control to the kernel.
>> +
>
> We found this section could be improved a bit by explicitly calling out
> the options for handling device PM. Platform vendor has two choices.
> Resources can be managed in _PSx routine which gets called on entry to Dx.
> Or they can be declared separately as power resources with their own _ON
> and _OFF methods. They are then tied back to D-states for a particular
> device via _PRx which specifies which power resources a device needs to be
> on while in Dx. Kernel then tracks number of devices using a power
> resource and calls _ON/_OFF as needed.

Good point, this exactly what ACPI spec says, we need to update this
paragraph a little bit.

>
>> +Such code in _PS? methods will of course be very platform specific. But,
>> +this allows the driver to abstract out the interface for operating the
>> device
>> +and avoid having to read special non-standard values from ACPI tables.
>> Further,
>> +abstracting the use of these resources allows the hardware to change over
>> time
>> +without requiring updates to the driver.
>> +
>
> I think its been mentioned in the past and you planned to add it here: we
> should explicitly state that with ACPI, the kernel clock/vreg framework
> are not expected to be used at all.
>
>> +
>> +Clocks
>> +------
>> +ACPI makes the assumption that clocks are initialized by the firmware --
>> +UEFI, in this case -- to some working value before control is handed over
>> +to the kernel. This has implications for devices such as UARTs, or SoC
>> +driven LCD displays, for example.
>> +
>> +When the kernel boots, the clock is assumed to be set to reasonable
>> +working value. If for some reason the frequency needs to change -- e.g.,
>> +throttling for power management -- the device driver should expect that
>> +process to be abstracted out into some ACPI method that can be invoked
>
> Exception to this is CPU clocks where CPPC provides a much richer
> interface than just blindly invoking some method.
>
>> +(please see the ACPI specification for further recommendations on
>> standard
>> +methods to be expected). If is not, there is no direct way for ACPI to
>> +control the clocks.
>> +
>> +
>
> [..]
>
>> +ASWG
>> +----
>> +The following areas are not yet fully defined for ARM in the 5.1 version
>> +of the ACPI specification and are expected to be worked through in the
>> +UEFI ACPI Specification Working Group (ASWG):
>> +
>> + -- ACPI based CPU topology
>> + -- ACPI based Power management
>
> Should clarify this to idle management rather than generic power management.

and I think it is CPU idle specific here, right?

>
>> + -- CPU idle control based on PSCI
>> + -- CPU performance control (CPPC)
>
> There is no ongoing work on CPPC. Additional enhancements may be explored
> in the future, but spec is viable as is.

will remove it.

Thanks for reviewing it!

Hanjun

2014-12-31 15:08:27

by Ashwin Chaugule

[permalink] [raw]
Subject: Re: [PATCH v5 18/18] Documentation: ACPI for ARM64

On 31 December 2014 at 03:34, Hanjun Guo <[email protected]> wrote:
> On 2014年12月31日 04:13, [email protected] wrote:
>> Hi Hanjun,
>>> +ASWG
>>> +----
>>> +The following areas are not yet fully defined for ARM in the 5.1
>>> version
>>> +of the ACPI specification and are expected to be worked through in the
>>> +UEFI ACPI Specification Working Group (ASWG):
>>> +
>>> + -- ACPI based CPU topology
>>> + -- ACPI based Power management
>>
>> Should clarify this to idle management rather than generic power
>> management.
>
> and I think it is CPU idle specific here, right?
>

Right.

Thanks,
Ashwin

--
Qualcomm Innovation Center, Inc
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

--