From patchwork Sun May 17 20:03:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parth Dixit X-Patchwork-Id: 48634 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A179721411 for ; Sun, 17 May 2015 20:06:02 +0000 (UTC) Received: by laat2 with SMTP id t2sf47312709laa.2 for ; Sun, 17 May 2015 13:06:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=l7y7Wt0mr62J4lzLa1wcfT4V8Hk+thx4ywEnfjiDEEo=; b=b76tsilwzccQ0iPiNIhSE6PQOUE3H+PLGTwqCUlg2ZVvzleXyNkQ6faQv6Z3S/4W7P JpBza1qsbQiw6n8ikGoCbueFMSM9vdfVgdUudA2oX1sbCa+g3SCn85AiFR+OKdaN3N8l GeceY/yYQR6Y1arCg8Rv2uOXjE5BworAD98/kyN7a5qX2RtAAzTZcJ+zdZvO+RjecvrQ cPx/xt1gJOvSPzvbYF2ceyzC0lc13UedxYFCPGo5Qy1lFOunIae1BagihZyAfjPo1leV LMWKcIkIU+ODonmdaMa7NOiBfSdA4IDqyzLvMIgEymth4+SpbiZz3RVEmv+OSltu97zK EWOg== X-Gm-Message-State: ALoCoQkInrSqH/U9XkPX8l0wFFb/h6Xe41IoQHOO4h4Ryg4aKqpElh9VIxIjj/KbIViXwUAO/+L5 X-Received: by 10.112.53.102 with SMTP id a6mr15218641lbp.16.1431893161291; Sun, 17 May 2015 13:06:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.207.65 with SMTP id lu1ls641931lac.104.gmail; Sun, 17 May 2015 13:06:01 -0700 (PDT) X-Received: by 10.152.29.138 with SMTP id k10mr14869167lah.114.1431893161075; Sun, 17 May 2015 13:06:01 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id wm10si5316135lbb.149.2015.05.17.13.06.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 May 2015 13:06:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by lagr1 with SMTP id r1so109733745lag.0 for ; Sun, 17 May 2015 13:06:01 -0700 (PDT) X-Received: by 10.152.27.1 with SMTP id p1mr14490074lag.112.1431893160973; Sun, 17 May 2015 13:06:00 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp3507712lbb; Sun, 17 May 2015 13:05:59 -0700 (PDT) X-Received: by 10.141.28.142 with SMTP id f136mr25451198qhe.67.1431893157939; Sun, 17 May 2015 13:05:57 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id 69si4225629qks.53.2015.05.17.13.05.57 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 17 May 2015 13:05:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yu4oL-0001p7-FD; Sun, 17 May 2015 20:05:21 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yu4oJ-0001mq-Bw for xen-devel@lists.xen.org; Sun, 17 May 2015 20:05:19 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 7B/95-03197-E74F8555; Sun, 17 May 2015 20:05:18 +0000 X-Env-Sender: parth.dixit@linaro.org X-Msg-Ref: server-15.tower-31.messagelabs.com!1431893115!11148278!1 X-Originating-IP: [209.85.192.181] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.13.15; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26528 invoked from network); 17 May 2015 20:05:17 -0000 Received: from mail-pd0-f181.google.com (HELO mail-pd0-f181.google.com) (209.85.192.181) by server-15.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 17 May 2015 20:05:17 -0000 Received: by pdbqa5 with SMTP id qa5so117358488pdb.0 for ; Sun, 17 May 2015 13:05:15 -0700 (PDT) X-Received: by 10.66.222.161 with SMTP id qn1mr38681256pac.66.1431893115669; Sun, 17 May 2015 13:05:15 -0700 (PDT) Received: from localhost.localdomain ([117.247.24.139]) by mx.google.com with ESMTPSA id j9sm7838401pdm.53.2015.05.17.13.05.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 17 May 2015 13:05:15 -0700 (PDT) From: Parth Dixit To: xen-devel@lists.xen.org Date: Mon, 18 May 2015 01:33:40 +0530 Message-Id: <1431893048-5214-14-git-send-email-parth.dixit@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431893048-5214-1-git-send-email-parth.dixit@linaro.org> References: <1431893048-5214-1-git-send-email-parth.dixit@linaro.org> Cc: keir@xen.org, ian.campbell@citrix.com, andrew.cooper3@citrix.com, tim@xen.org, julien.grall@citrix.com, stefano.stabellini@citrix.com, jbeulich@suse.com, parth.dixit@linaro.org, christoffer.dall@linaro.org Subject: [Xen-devel] [PATCH v2 13/41] arm/acpi : parse MADT to map logical cpu to MPIDR and get cpu_possible_map X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: parth.dixit@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: 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. Signed-off-by: Hanjun Guo Signed-off-by: Tomasz Nowicki Signed-off-by: Naresh Bhat Signed-off-by: Parth Dixit --- xen/arch/arm/acpi/boot.c | 135 +++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/arm64/smpboot.c | 7 ++- xen/arch/arm/psci.c | 16 +++++ xen/arch/arm/smpboot.c | 7 ++- xen/include/asm-arm/acpi.h | 2 + xen/include/xen/acpi.h | 5 ++ 6 files changed, 170 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/acpi/boot.c b/xen/arch/arm/acpi/boot.c index 57eb33c..7d9758f 100644 --- a/xen/arch/arm/acpi/boot.c +++ b/xen/arch/arm/acpi/boot.c @@ -29,6 +29,141 @@ #include #include +#include + +/* Processors with enabled flag and sane MPIDR */ +static int enabled_cpus; + +/* Boot CPU is valid or not in MADT */ +static bool_t __initdata bootcpu_valid; + +/* arch-optional setting to enable display of offline cpus >= nr_cpu_ids */ +static unsigned int total_cpus = 0; + +/* + * 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 __init acpi_map_gic_cpu_interface(u64 mpidr, u8 enabled) +{ + int i; + + if ( mpidr == MPIDR_INVALID ) + { + printk("Skip MADT cpu entry with invalid MPIDR\n"); + return -EINVAL; + } + + total_cpus++; + if ( !enabled ) + return -EINVAL; + + if ( enabled_cpus >= NR_CPUS ) + { + printk("NR_CPUS limit of %d reached, Processor %d/0x%"PRIx64" ignored.\n", + NR_CPUS, total_cpus, mpidr); + return -EINVAL; + } + + /* Check if GICC structure of boot CPU is available in the MADT */ + if ( cpu_logical_map(0) == mpidr ) + { + if ( bootcpu_valid ) + { + printk("Firmware bug, duplicate CPU MPIDR: 0x%"PRIx64" in MADT\n", + mpidr); + return -EINVAL; + } + + bootcpu_valid = TRUE; + } + + /* + * Duplicate MPIDRs are a recipe for disaster. Scan + * all initialized entries and check for + * duplicates. If any is found just ignore the CPU. + */ + for ( i = 1; i < enabled_cpus; i++ ) + { + if ( cpu_logical_map(i) == mpidr ) + { + printk("Firmware bug, duplicate CPU MPIDR: 0x%"PRIx64" in MADT\n", + mpidr); + return -EINVAL; + } + } + + if ( !acpi_psci_present() ) + return -EOPNOTSUPP; + + /* CPU 0 was already initialized */ + if ( enabled_cpus ) + { + if ( arch_cpu_init(enabled_cpus, NULL) < 0 ) + return -EOPNOTSUPP; + + /* map the logical cpu id to cpu MPIDR */ + cpu_logical_map(enabled_cpus) = mpidr; + } + + enabled_cpus++; + return enabled_cpus; +} + +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->mpidr & MPIDR_HWID_MASK, + processor->flags & ACPI_MADT_ENABLED); + + return 0; +} + +/* Parse GIC cpu interface entries in MADT for SMP init */ +void __init acpi_init_cpus(void) +{ + int count, i; + + /* + * 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 < 0 ) + { + printk("Error parsing GIC CPU interface entry\n"); + return; + } + + if ( !bootcpu_valid ) + { + printk("MADT missing boot CPU MPIDR, not enabling secondaries\n"); + return; + } + + for ( i = 0; i < enabled_cpus; i++ ) + cpumask_set_cpu(i, &cpu_possible_map); + + /* Make boot-up look pretty */ + printk("%d CPUs enabled, %d CPUs total\n", enabled_cpus, total_cpus); +} static int __init acpi_parse_fadt(struct acpi_table_header *table) { diff --git a/xen/arch/arm/arm64/smpboot.c b/xen/arch/arm/arm64/smpboot.c index 7928f69..c3d9e00 100644 --- a/xen/arch/arm/arm64/smpboot.c +++ b/xen/arch/arm/arm64/smpboot.c @@ -7,6 +7,7 @@ #include #include #include +#include struct smp_enable_ops { int (*prepare_cpu)(int); @@ -94,9 +95,13 @@ static int __init dt_arch_cpu_init(int cpu, struct dt_device_node *dn) return 0; } +/* acpi only supports psci at present */ int __init arch_cpu_init(int cpu, struct dt_device_node *dn) { - return dt_arch_cpu_init(cpu, dn); + if( acpi_disabled ) + return dt_arch_cpu_init(cpu, dn); + else + return smp_psci_init(cpu); } int __init arch_cpu_up(int cpu) diff --git a/xen/arch/arm/psci.c b/xen/arch/arm/psci.c index 4066309..20040aa 100644 --- a/xen/arch/arm/psci.c +++ b/xen/arch/arm/psci.c @@ -22,6 +22,7 @@ #include #include #include +#include uint32_t psci_ver; @@ -74,6 +75,9 @@ int __init psci_init_0_1(void) int ret; const struct dt_device_node *psci; + if ( !acpi_disabled ) + return -EINVAL; + psci = dt_find_compatible_node(NULL, NULL, "arm,psci"); if ( !psci ) return -EOPNOTSUPP; @@ -98,6 +102,9 @@ int __init psci_init_0_1(void) int __init psci_init_0_2(void) { int ret; + + if( acpi_disabled ) + { const struct dt_device_node *psci; psci = dt_find_compatible_node(NULL, NULL, "arm,psci-0.2"); @@ -107,6 +114,15 @@ int __init psci_init_0_2(void) ret = psci_is_smc_method(psci); if ( ret ) return -EINVAL; + } + else + { + if( !acpi_psci_present() ) + return -EOPNOTSUPP; + + if ( acpi_psci_hvc_present() ) + return -EINVAL; + } psci_ver = call_smc(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0); diff --git a/xen/arch/arm/smpboot.c b/xen/arch/arm/smpboot.c index 90f9ef2..1385dbe 100644 --- a/xen/arch/arm/smpboot.c +++ b/xen/arch/arm/smpboot.c @@ -31,6 +31,7 @@ #include #include #include +#include cpumask_t cpu_online_map; cpumask_t cpu_present_map; @@ -246,7 +247,11 @@ void __init smp_init_cpus(void) return; } - dt_smp_init_cpus(); + if ( acpi_disabled ) + dt_smp_init_cpus(); + else + acpi_init_cpus(); + } int __init diff --git a/xen/include/asm-arm/acpi.h b/xen/include/asm-arm/acpi.h index 4a6cb37..0845f14 100644 --- a/xen/include/asm-arm/acpi.h +++ b/xen/include/asm-arm/acpi.h @@ -35,9 +35,11 @@ extern bool_t acpi_disabled; bool_t acpi_psci_present(void); /* 1 to indicate HVC is present instead of SMC as the PSCI conduit */ bool_t acpi_psci_hvc_present(void); +void __init acpi_init_cpus(void); #else static inline bool_t acpi_psci_present(void) { return false; } static inline bool_t acpi_psci_hvc_present(void) {return false; } +static inline void acpi_init_cpus(void) { } #endif /* CONFIG_ACPI */ /* Basic configuration for ACPI */ diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h index afe2dca..ee6a5ea 100644 --- a/xen/include/xen/acpi.h +++ b/xen/include/xen/acpi.h @@ -40,6 +40,10 @@ #define ACPI_MADT_GET_POLARITY(inti) ACPI_MADT_GET_(POLARITY, inti) #define ACPI_MADT_GET_TRIGGER(inti) ACPI_MADT_GET_(TRIGGER, inti) +#define BAD_MADT_ENTRY(entry, end) ( \ + (!entry) || (unsigned long)entry + sizeof(*entry) > end || \ + ((struct acpi_subtable_header *)entry)->length < sizeof(*entry)) + #ifdef CONFIG_ACPI_BOOT enum acpi_interrupt_id { @@ -57,6 +61,7 @@ typedef int (*acpi_table_entry_handler) (struct acpi_subtable_header *header, co void __iomem * acpi_os_map_iomem(acpi_physical_address phys, acpi_size size); + unsigned int acpi_get_processor_id (unsigned int cpu); char * __acpi_map_table (paddr_t phys_addr, unsigned long size); int acpi_boot_init (void);