From patchwork Fri Jan 17 12:25:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanjun Guo X-Patchwork-Id: 23327 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f200.google.com (mail-ob0-f200.google.com [209.85.214.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B857E20540 for ; Fri, 17 Jan 2014 12:44:10 +0000 (UTC) Received: by mail-ob0-f200.google.com with SMTP id wp4sf13660970obc.3 for ; Fri, 17 Jan 2014 04:44:09 -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=3iXielpc5qnm09C6oGV1WAp9HwEE75dk7F9K/B3RyIM=; b=mw+W1K3b/x4f+irpUcV1AcorINTsbHN1QWqoWYKSwXSr7MlSP3ZHocJ8hoNSca9jWH T2EQIMrWO4ZUl4TQ/jXs4qifniDuJvo16yeJ6/qStF57ZBdPDkz3bOVtEyRaSCnkExMF g54Nmk/EeOAIg7ZmjLTFCdYrsGSZ2gH8B94ClW7N30R4JcPImGcC0GpCPWStMfCH778R Ggryb8v4KE8w2NSQV3OAx8ADajTfkU6b36MMAAL44RuPDbQZbDIAClNmKzSBszOCJfVa CP5b+l4JPWZgkX6oj4YKxrOWRn/2Wii/rxaaEXKGfSOTY8tQe6wwXVQSpwwRpI+o+Zex SFIg== X-Gm-Message-State: ALoCoQl4PoO8VOXtUPNh5E4RyJpsHVAZPZ9wTlX5ilmy642yd8AdMrybI0KFCaekjv1v2hjCPA+d X-Received: by 10.43.102.136 with SMTP id de8mr545552icc.20.1389962649870; Fri, 17 Jan 2014 04:44:09 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.102 with SMTP id k93ls453095qgd.73.gmail; Fri, 17 Jan 2014 04:44:09 -0800 (PST) X-Received: by 10.58.146.5 with SMTP id sy5mr111139veb.43.1389962649735; Fri, 17 Jan 2014 04:44:09 -0800 (PST) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by mx.google.com with ESMTPS id gx6si4847849vdc.63.2014.01.17.04.44.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Jan 2014 04:44:09 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.54 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.54; Received: by mail-vb0-f54.google.com with SMTP id w20so1551583vbb.27 for ; Fri, 17 Jan 2014 04:44:09 -0800 (PST) X-Received: by 10.52.114.99 with SMTP id jf3mr68394vdb.66.1389962649649; Fri, 17 Jan 2014 04:44:09 -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.59.13.131 with SMTP id ey3csp16875ved; Fri, 17 Jan 2014 04:44:09 -0800 (PST) X-Received: by 10.68.138.165 with SMTP id qr5mr1789116pbb.123.1389962648584; Fri, 17 Jan 2014 04:44:08 -0800 (PST) Received: from mail-pb0-f41.google.com (mail-pb0-f41.google.com [209.85.160.41]) by mx.google.com with ESMTPS id xu6si10018348pab.312.2014.01.17.04.44.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Jan 2014 04:44:08 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.41 is neither permitted nor denied by best guess record for domain of hanjun.guo@linaro.org) client-ip=209.85.160.41; Received: by mail-pb0-f41.google.com with SMTP id up15so3557402pbc.0 for ; Fri, 17 Jan 2014 04:44:08 -0800 (PST) X-Received: by 10.68.254.230 with SMTP id al6mr1861100pbd.3.1389962648191; Fri, 17 Jan 2014 04:44:08 -0800 (PST) Received: from localhost ([218.17.215.175]) by mx.google.com with ESMTPSA id un5sm30364438pab.3.2014.01.17.04.43.39 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 17 Jan 2014 04:44:07 -0800 (PST) From: Hanjun Guo To: "Rafael J. Wysocki" , Catalin Marinas , Will Deacon , Russell King - ARM Linux 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 , Arnd Bergmann , patches@linaro.org, linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, linaro-acpi@lists.linaro.org, Charles.Garcia-Tobin@arm.com, Hanjun Guo Subject: [PATCH 10/20] ARM64 / ACPI: Enumerate possible/present CPU set and map logical cpu id to APIC id Date: Fri, 17 Jan 2014 20:25:04 +0800 Message-Id: <1389961514-13562-11-git-send-email-hanjun.guo@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1389961514-13562-1-git-send-email-hanjun.guo@linaro.org> References: <1389961514-13562-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.212.54 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: , When boot the kernel with MADT, the cpu possible and present sets should be enumerated for later smp initialization. The logic cpu id maps to APIC id (GIC id) is also implemented, it is needed for acpi processor drivers. Signed-off-by: Hanjun Guo --- arch/arm64/include/asm/acpi.h | 7 ++-- drivers/acpi/plat/arm-core.c | 83 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index c335c6d..7edd39e 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -76,9 +76,6 @@ static inline void acpi_disable_pci(void) /* FIXME: this function should be moved to topology.h when it's ready */ void arch_fix_phys_package_id(int num, u32 slot); -/* temperally define -1 to make acpi core compilerable */ -#define cpu_physical_id(cpu) -1 - /* Low-level suspend routine. */ extern int (*acpi_suspend_lowlevel)(void); #define acpi_wakeup_address (0) @@ -86,6 +83,10 @@ extern int (*acpi_suspend_lowlevel)(void); #define MAX_GIC_CPU_INTERFACE 256 #define MAX_GIC_DISTRIBUTOR 1 /* should be the same as MAX_GIC_NR */ +/* map logic cpu id to physical GIC id */ +extern int arm_cpu_to_apicid[NR_CPUS]; +#define cpu_physical_id(cpu) arm_cpu_to_apicid[cpu] + #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 8ba3e6f..1d9b789 100644 --- a/drivers/acpi/plat/arm-core.c +++ b/drivers/acpi/plat/arm-core.c @@ -31,6 +31,7 @@ #include #include +#include /* * We never plan to use RSDT on arm/arm64 as its deprecated in spec but this @@ -52,6 +53,13 @@ EXPORT_SYMBOL(acpi_pci_disabled); */ static u64 acpi_lapic_addr __initdata; +/* available_cpus here means enabled cpu in MADT */ +static int available_cpus; + +/* Map logic cpu id to physical GIC id (physical CPU id). */ +int arm_cpu_to_apicid[NR_CPUS] = { [0 ... NR_CPUS-1] = -1 }; +static int boot_cpu_apic_id = -1; + #define BAD_MADT_ENTRY(entry, end) ( \ (!entry) || (unsigned long)entry + sizeof(*entry) > end || \ ((struct acpi_subtable_header *)entry)->length < sizeof(*entry)) @@ -132,6 +140,55 @@ static int __init acpi_parse_madt(struct acpi_table_header *table) * Please refer to chapter5.2.12.14/15 of ACPI 5.0 */ +/** + * acpi_register_gic_cpu_interface - register a gic cpu interface and + * generates a logic cpu number + * @id: gic cpu interface id to register + * @enabled: this cpu is enabled or not + * + * Returns the logic cpu number which maps to the gic cpu interface + */ +static int acpi_register_gic_cpu_interface(int id, u8 enabled) +{ + int cpu; + + if (id >= MAX_GIC_CPU_INTERFACE) { + pr_info(PREFIX "skipped apicid that is too big\n"); + return -EINVAL; + } + + total_cpus++; + if (!enabled) + return -EINVAL; + + if (available_cpus >= NR_CPUS) { + pr_warn(PREFIX "NR_CPUS limit of %d reached," + " Processor %d/0x%x ignored.\n", NR_CPUS, total_cpus, id); + return -EINVAL; + } + + available_cpus++; + + /* allocate a logic cpu id for the new comer */ + if (boot_cpu_apic_id == id) { + /* + * boot_cpu_init() already hold bit 0 in cpu_present_mask + * for BSP, no need to allocte again. + */ + cpu = 0; + } else { + cpu = cpumask_next_zero(-1, cpu_present_mask); + } + + /* map the logic cpu id to APIC id */ + arm_cpu_to_apicid[cpu] = id; + + set_cpu_present(cpu, true); + set_cpu_possible(cpu, true); + + return cpu; +} + static int __init acpi_parse_gic(struct acpi_subtable_header *header, const unsigned long end) { @@ -144,6 +201,16 @@ acpi_parse_gic(struct acpi_subtable_header *header, const unsigned long end) acpi_table_print_madt_entry(header); + /* + * We need to register disabled CPU as well to permit + * counting disabled CPUs. This allows us to size + * cpus_possible_map more accurately, to permit + * to not preallocating memory for all NR_CPUS + * when we use CPU hotplug. + */ + acpi_register_gic_cpu_interface(processor->gic_id, + processor->flags & ACPI_MADT_ENABLED); + return 0; } @@ -186,6 +253,19 @@ static int __init acpi_parse_madt_gic_entries(void) return count; } +#ifdef CONFIG_SMP + if (available_cpus == 0) { + pr_info(PREFIX "Found 0 CPUs; assuming 1\n"); + arm_cpu_to_apicid[available_cpus] = + read_cpuid_mpidr() & MPIDR_HWID_BITMASK; + available_cpus = 1; /* We've got at least one of these */ + } +#endif + + /* Make boot-up look pretty */ + pr_info("%d CPUs available, %d CPUs total\n", available_cpus, + total_cpus); + return 0; } @@ -321,6 +401,9 @@ int __init early_acpi_boot_init(void) if (acpi_disabled) return -ENODEV; + /* Get the boot CPU's GIC cpu interface id before MADT parsing */ + boot_cpu_apic_id = read_cpuid_mpidr() & MPIDR_HWID_BITMASK; + /* * Process the Multiple APIC Description Table (MADT), if present */