From patchwork Tue Dec 3 16:39:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 21982 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6CB7E202AE for ; Tue, 3 Dec 2013 16:39:47 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id f11sf14345047qae.11 for ; Tue, 03 Dec 2013 08:39:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=50LQu4Q05oxV+CQ5ThPF+Q6B01lhKqstdkHTatxK08g=; b=c2SiUG9R/LXSyo+N/QnRxVCK7jQmQrL2JN+hkqxdQG0wqEILzDuxhp0Z/VRtw6ip4P /FOXiaChHic9MMS3uR7Uuw3ZKS5PG/exLA6gsP13pnmg5U8NOJDqKa95pJoioandH/JW uSnfNi2bN6LI9KgURV44P2oTutNy2Oonw+UuX8bK7z/lpfaDIub1EMba+TCQ3soCstky zYNYQZY/h9MFTOoUDRpREcWKMvsFhn56AK/CZkZgROLQss85Xqx9spt4R8wdpMkkVEnG uAmvb3XcWV73ZdGy4f4mkuxSFjWojYzgH9LGhVj7vwMtIQPvcNeAvU+vbOHyC0H1bDHf wFhw== X-Gm-Message-State: ALoCoQkBU7sWX1OOXgOQAPdU2LNmBnZNZuKBsNcWLkJ1gJ7qzyTtxahvIhTHFGc1wdHYFybisedO X-Received: by 10.236.82.110 with SMTP id n74mr1197060yhe.57.1386088787186; Tue, 03 Dec 2013 08:39:47 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.60.37 with SMTP id e5ls809217qer.84.gmail; Tue, 03 Dec 2013 08:39:47 -0800 (PST) X-Received: by 10.52.76.36 with SMTP id h4mr1681640vdw.46.1386088786973; Tue, 03 Dec 2013 08:39:46 -0800 (PST) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id 1si31574063vel.74.2013.12.03.08.39.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 03 Dec 2013 08:39:46 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id id10so9846002vcb.19 for ; Tue, 03 Dec 2013 08:39:46 -0800 (PST) X-Received: by 10.220.196.66 with SMTP id ef2mr57643317vcb.7.1386088786766; Tue, 03 Dec 2013 08:39:46 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp222538vcz; Tue, 3 Dec 2013 08:39:46 -0800 (PST) X-Received: by 10.66.139.196 with SMTP id ra4mr76914803pab.103.1386088785822; Tue, 03 Dec 2013 08:39:45 -0800 (PST) Received: from mail-pd0-f181.google.com (mail-pd0-f181.google.com [209.85.192.181]) by mx.google.com with ESMTPS id w3si22620250pbh.269.2013.12.03.08.39.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 03 Dec 2013 08:39:45 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.181 is neither permitted nor denied by best guess record for domain of hanjun.guo@linaro.org) client-ip=209.85.192.181; Received: by mail-pd0-f181.google.com with SMTP id p10so20459479pdj.12 for ; Tue, 03 Dec 2013 08:39:45 -0800 (PST) X-Received: by 10.68.131.202 with SMTP id oo10mr31599541pbb.35.1386088784327; Tue, 03 Dec 2013 08:39:44 -0800 (PST) Received: from localhost ([219.142.3.202]) by mx.google.com with ESMTPSA id sg1sm131172190pbb.16.2013.12.03.08.39.35 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 03 Dec 2013 08:39:43 -0800 (PST) From: Hanjun Guo To: "Rafael J. Wysocki" , Catalin Marinas , Will Deacon , Russell King - ARM Linux , Daniel Lezcano Cc: linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Grant Likely , Matthew Garrett , Olof Johansson , Linus Walleij , Bjorn Helgaas , Rob Herring , Mark Rutland , Jon Masters , patches@linaro.org, linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, linaro-acpi@lists.linaro.org, Hanjun Guo Subject: [RFC part2 PATCH 1/9] ARM64 / ACPI: Implement core functions for parsing MADT table Date: Wed, 4 Dec 2013 00:39:05 +0800 Message-Id: <1386088753-2850-2-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1386088753-2850-1-git-send-email-hanjun.guo@linaro.org> References: <1386088753-2850-1-git-send-email-hanjun.guo@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: hanjun.guo@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Implement core functions for parsing MADT table to get the information about GIC cpu interface and GIC distributor. Signed-off-by: Hanjun Guo --- arch/arm64/include/asm/acpi.h | 3 + drivers/acpi/plat/arm-core.c | 139 ++++++++++++++++++++++++++++++++++++++++- drivers/acpi/tables.c | 21 +++++++ 3 files changed, 162 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index c830adc..be2951c 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -83,6 +83,9 @@ void arch_fix_phys_package_id(int num, u32 slot); extern int (*acpi_suspend_lowlevel)(void); #define acpi_wakeup_address (0) +#define MAX_GIC_CPU_INTERFACE 256 +#define MAX_GIC_DISTRIBUTOR 1 /* should be the same as MAX_GIC_NR */ + #else /* !CONFIG_ACPI */ #define acpi_disabled 1 /* ACPI sometimes enabled on ARM */ #define acpi_noirq 1 /* ACPI sometimes enabled on ARM */ diff --git a/drivers/acpi/plat/arm-core.c b/drivers/acpi/plat/arm-core.c index 2b6df56..45ff625 100644 --- a/drivers/acpi/plat/arm-core.c +++ b/drivers/acpi/plat/arm-core.c @@ -52,6 +52,16 @@ EXPORT_SYMBOL(acpi_disabled); int acpi_pci_disabled; /* skip ACPI PCI scan and IRQ initialization */ EXPORT_SYMBOL(acpi_pci_disabled); +/* + * Local interrupt controller address, + * GIC cpu interface base address on ARM/ARM64 + */ +static u64 acpi_lapic_addr __initdata; + +#define BAD_MADT_ENTRY(entry, end) ( \ + (!entry) || (unsigned long)entry + sizeof(*entry) > end || \ + ((struct acpi_subtable_header *)entry)->length < sizeof(*entry)) + #define PREFIX "ACPI: " /* FIXME: this function should be moved to topology.c when it is ready */ @@ -102,6 +112,115 @@ void __init __acpi_unmap_table(char *map, unsigned long size) return; } +static int __init acpi_parse_madt(struct acpi_table_header *table) +{ + struct acpi_table_madt *madt = NULL; + + madt = (struct acpi_table_madt *)table; + if (!madt) { + pr_warn(PREFIX "Unable to map MADT\n"); + return -ENODEV; + } + + if (madt->address) { + acpi_lapic_addr = (u64) madt->address; + + pr_info(PREFIX "Local APIC address 0x%08x\n", madt->address); + } + + return 0; +} + +/* + * GIC structures on ARM are somthing like Local APIC structures on x86, + * which means GIC cpu interfaces for GICv2/v3. Every GIC structure in + * MADT table represents a cpu in the system. + * + * GIC distributor structures are somthing like IOAPIC on x86. GIC can + * be initialized with information in this structure. + * + * Please refer to chapter5.2.12.14/15 of ACPI 5.0 + */ + +static int __init +acpi_parse_gic(struct acpi_subtable_header *header, const unsigned long end) +{ + struct acpi_madt_generic_interrupt *processor = NULL; + + processor = (struct acpi_madt_generic_interrupt *)header; + + if (BAD_MADT_ENTRY(processor, end)) + return -EINVAL; + + acpi_table_print_madt_entry(header); + + return 0; +} + +static int __init +acpi_parse_gic_distributor(struct acpi_subtable_header *header, + const unsigned long end) +{ + struct acpi_madt_generic_distributor *distributor = NULL; + + distributor = (struct acpi_madt_generic_distributor *)header; + + if (BAD_MADT_ENTRY(distributor, end)) + return -EINVAL; + + acpi_table_print_madt_entry(header); + + return 0; +} + +/* + * Parse GIC cpu interface related entries in MADT + * returns 0 on success, < 0 on error + */ +static int __init acpi_parse_madt_gic_entries(void) +{ + int count; + + /* + * do a partial walk of MADT to determine how many CPUs + * we have including disabled CPUs + */ + count = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT, + acpi_parse_gic, MAX_GIC_CPU_INTERFACE); + + if (!count) { + pr_err(PREFIX "No GIC entries present\n"); + return -ENODEV; + } else if (count < 0) { + pr_err(PREFIX "Error parsing GIC entry\n"); + return count; + } + + return 0; +} + +/* + * Parse GIC distributor related entries in MADT + * returns 0 on success, < 0 on error + */ +static int __init acpi_parse_madt_gic_distributor_entries(void) +{ + int count; + + count = acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR, + acpi_parse_gic_distributor, MAX_GIC_DISTRIBUTOR); + + if (!count) { + pr_err(PREFIX "No GIC distributor entries present\n"); + return -ENODEV; + } else if (count < 0) { + pr_err(PREFIX "Error parsing GIC distributor entry\n"); + return count; + } + + return 0; +} + int acpi_gsi_to_irq(u32 gsi, unsigned int *irq) { *irq = gsi_to_irq(gsi); @@ -132,11 +251,29 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table) static void __init early_acpi_process_madt(void) { - return; + acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt); } static void __init acpi_process_madt(void) { + int error; + + if (!acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) { + + /* + * Parse MADT GIC cpu interface entries + */ + error = acpi_parse_madt_gic_entries(); + if (!error) { + /* + * Parse MADT GIC distributor entries + */ + acpi_parse_madt_gic_distributor_entries(); + } + } + + pr_info("Using ACPI for processor (GIC) configuration information\n"); + return; } diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c index d67a1fe..b3e4615 100644 --- a/drivers/acpi/tables.c +++ b/drivers/acpi/tables.c @@ -191,6 +191,27 @@ 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; + printk(KERN_INFO PREFIX + "GIC (acpi_id[0x%04x] gic_id[0x%04x] %s)\n", + p->uid, p->gic_id, + (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; + printk(KERN_INFO PREFIX + "GIC Distributor (id[0x%04x] address[0x%08llx] gsi_base[%d])\n", + p->gic_id, p->base_address, p->global_irq_base); + } + break; + default: printk(KERN_WARNING PREFIX "Found unsupported MADT entry (type = 0x%x)\n",