From patchwork Sat Jun 27 03:02:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 6684621 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7DDA5C05AC for ; Sat, 27 Jun 2015 03:09:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C0ED2060D for ; Sat, 27 Jun 2015 03:09:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 647FD20609 for ; Sat, 27 Jun 2015 03:09:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z8gRh-00017j-LK; Sat, 27 Jun 2015 03:06:21 +0000 Received: from mail-pd0-f179.google.com ([209.85.192.179]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z8gOl-0006vs-I5 for linux-arm-kernel@lists.infradead.org; Sat, 27 Jun 2015 03:03:20 +0000 Received: by pdcu2 with SMTP id u2so84847013pdc.3 for ; Fri, 26 Jun 2015 20:02:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XTbt0M54KxoMez9NnAb8zdg+qMOq9uQ6j7pSEMq0UL0=; b=OWDzbsxlXzuj8afDP+35BVhDuxTEeHPlZJl3xPJYPgGs7Cv1JqkcEqAh37zu9TEsLh zE7UK4i503aCyIZ/Vt6H/H8IJW6bDK8sJprrRFARD7VdXU8RrqxogvF52K7jIZTBgNFu nXdjnZqnRt8oCfCpUTyq5ucevdCMSpzTSOxBmva0wYJGFn5n5UnWMPfU0h/Kwu7EDYlj uqPSrbcrv6LqYK8tfPM9IUpeNIvpr+eGZfsnWXuOtZPS99yaOMjET1O+yiAUOGOXmQDh oZ0x7D6yLgF9MEAWvwv0BxpoIifDzNCmSMAihig4MQzWe3dPC9/Ujzn1MI0JFWAHfiqL UXlg== X-Gm-Message-State: ALoCoQlSRHflEHkIo1kpYi46kLWj/3Y3AHfvxdYAadroxJe7xPWJxEN2PX3mCgMAKomr3DMPNxTi X-Received: by 10.66.190.133 with SMTP id gq5mr9287070pac.112.1435374178294; Fri, 26 Jun 2015 20:02:58 -0700 (PDT) Received: from ubuntu.localdomain (c-24-8-37-141.hsd1.co.comcast.net. [24.8.37.141]) by mx.google.com with ESMTPSA id j7sm34787756pdp.83.2015.06.26.20.02.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jun 2015 20:02:57 -0700 (PDT) From: Lina Iyer To: rjw@rjwysocki.net, ulf.hansson@linaro.org, khilman@linaro.org Subject: [PATCH RFC v2 09/16] arm: domain: Add platform callbacks for domain power on/off Date: Fri, 26 Jun 2015 21:02:29 -0600 Message-Id: <1435374156-19214-10-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1435374156-19214-1-git-send-email-lina.iyer@linaro.org> References: <1435374156-19214-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150626_200319_708229_D5AD5DA5 X-CRM114-Status: GOOD ( 23.07 ) X-Spam-Score: -2.6 (--) Cc: k.kozlowski@samsung.com, linux-pm@vger.kernel.org, msivasub@codeaurora.org, geert@linux-m68k.org, Lina Iyer , agross@codeaurora.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Platform drivers may have additional setup inorder before the domain can be powered off. Allow, platform drivers to register power on/off callbacks against a domain provider. While registering the callback ensure that the domain is neither in power on/off state. The domain should be active. To ensure that the platform callback registration doesntrace with genpd power on/off, execute the registration from a CPU on that domain. Signed-off-by: Lina Iyer --- arch/arm/include/asm/cpu.h | 1 - arch/arm/include/asm/pm_domain.h | 27 ++++++++++++++ arch/arm/kernel/domains.c | 81 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 arch/arm/include/asm/pm_domain.h diff --git a/arch/arm/include/asm/cpu.h b/arch/arm/include/asm/cpu.h index 2744f06..4a7e346 100644 --- a/arch/arm/include/asm/cpu.h +++ b/arch/arm/include/asm/cpu.h @@ -22,5 +22,4 @@ struct cpuinfo_arm { }; DECLARE_PER_CPU(struct cpuinfo_arm, cpu_data); - #endif diff --git a/arch/arm/include/asm/pm_domain.h b/arch/arm/include/asm/pm_domain.h new file mode 100644 index 0000000..d13c291 --- /dev/null +++ b/arch/arm/include/asm/pm_domain.h @@ -0,0 +1,27 @@ +/* + * arch/arm/include/asm/pm_domain.h + * + * Copyright (C) 2015 Linaro Ltd. + * + * 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_ARM_PM_DOMAIN_H +#define __ASM_ARM_PM_DOMAIN_H + +#include + +#if IS_ENABLED(CONFIG_PM_GENERIC_DOMAINS) +extern int register_platform_domain_handlers(struct of_phandle_args *args, + int (*pd_down)(struct generic_pm_domain *), + int (*pd_up)(struct generic_pm_domain *)); +#else +static inline +int register_platform_domain_handlers(struct of_phandle_args *args, + int (*pd_down)(struct generic_pm_domain *), + int (*pd_up)(struct generic_pm_domain *)) +{ return -ENODEV; } +#endif + +#endif diff --git a/arch/arm/kernel/domains.c b/arch/arm/kernel/domains.c index 680c3fb..2f5ba3f 100644 --- a/arch/arm/kernel/domains.c +++ b/arch/arm/kernel/domains.c @@ -9,10 +9,19 @@ #include #include +#include + #define NAME_MAX 16 +struct platform_cb { + int (*power_off)(struct generic_pm_domain *); + int (*power_on)(struct generic_pm_domain *); +}; + struct arm_pm_domain { struct generic_pm_domain genpd; + struct platform_cb plat_handler; + struct spinlock_t lock; }; static inline @@ -23,16 +32,85 @@ struct arm_pm_domain *to_arm_pd(struct generic_pm_domain *d) static int arm_pd_power_down(struct generic_pm_domain *genpd) { + struct arm_pm_domain *arm_pd = to_arm_pd(genpd); + + if (arm_pd->plat_handler.power_off) + return arm_pd->plat_handler.power_off(genpd); + /* pr_info("KJH: %s: %s\n", __func__, genpd->name); */ return 0; } static int arm_pd_power_up(struct generic_pm_domain *genpd) { + struct arm_pm_domain *arm_pd = to_arm_pd(genpd); + + if (arm_pd->plat_handler.power_on) + return arm_pd->plat_handler.power_on(genpd); + /* pr_info("KJH: %s: %s\n", __func__, genpd->name); */ return 0; } +static void __register_platform_domain_handlers(void *data) +{ + struct device *cpu_dev = get_cpu_device(smp_processor_id()); + struct generic_pm_domain *genpd; + struct arm_pm_domain *arm_pd; + unsigned long flags; + struct platform_cb *handler = data; + + genpd = pd_to_genpd(cpu_dev->pm_domain); + BUG_ON(IS_ERR_OR_NULL(genpd)); + arm_pd = to_arm_pd(genpd); + + /* + * Lock to avoid race with other CPUs in the same domain + * trying to set the function pointers. + */ + spin_lock_irqsave(&arm_pd->lock, flags); + arm_pd->plat_handler.power_on = handler->power_on; + arm_pd->plat_handler.power_off = handler->power_off; + spin_unlock_irqrestore(&arm_pd->lock, flags); +} + +int register_platform_domain_handlers(struct of_phandle_args *args, + int (*power_on)(struct generic_pm_domain *), + int (*power_off)(struct generic_pm_domain *)) +{ + struct platform_cb handler; + struct generic_pm_domain *genpd, *p; + struct device *cpu_dev; + int cpu; + + handler.power_on = power_on; + handler.power_off = power_off; + + genpd = of_genpd_get_from_provider(args); + get_online_cpus(); + for_each_online_cpu(cpu) { + cpu_dev = get_cpu_device(cpu); + p = pm_genpd_lookup_dev(cpu_dev); + /* + * Execute the registration on the requested 'cpu', so we dont + * race with the domain->power_off or ->power_on calls. + * By executing on that 'cpu', we are assured that the 'cpu' is + * awake, therefore the domain. This will avoid a spin lock + * between power on/off calls and this function. + */ + if (p == genpd) { + smp_call_function_single(cpu, + __register_platform_domain_handlers, + &handler, true); + break; + } + } + put_online_cpus(); + + return 0; +} +EXPORT_SYMBOL(register_platform_domain_handlers); + static void run_cpu(void *unused) { struct device *cpu_dev = get_cpu_device(smp_processor_id()); @@ -91,7 +169,7 @@ static int arm_domain_cpu_init(void) /* FIXME: this is open-coding of_cpu_device_node_get(), but I want handle to cpu_dev */ cpu_dev = get_cpu_device(cpuid); if (!cpu_dev) { - pr_warn("%s: Unable to get device for CPU%d\n", __func__, cpuid); + pr_warn("%s: Unable to get device for CPU%d\n", __func__, cpuid); return -ENODEV; } @@ -152,6 +230,7 @@ static int arm_domain_init(void) pd->genpd.power_off = arm_pd_power_down; pd->genpd.power_on = arm_pd_power_up; pd->genpd.flags |= GENPD_FLAG_IRQ_SAFE; + spin_lock_init(&pd->lock); platform_set_drvdata(pdev, pd); dev_dbg(dev, "adding as generic power domain.\n");