Received: by 10.223.176.46 with SMTP id f43csp880613wra; Fri, 26 Jan 2018 08:19:32 -0800 (PST) X-Google-Smtp-Source: AH8x22694DxpF9C1ssSw000lQ/cefh5yp7mVDXPib9qkr5CT3ciBfy8n4TJHD2emCCFP5LFnkBpi X-Received: by 2002:a17:902:8607:: with SMTP id f7-v6mr14948704plo.273.1516983572698; Fri, 26 Jan 2018 08:19:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516983572; cv=none; d=google.com; s=arc-20160816; b=bqZGgu7F44lyaHH4z7b0/57Z0hz3LMHrFA2Fmcdujefi2nDokgvw+CtMlzGlksoX2v 2AaG4s7PkepbpFtoSkZ0tD8rdttIwgNAXFtyQIJ2W187IIKuCLszfjEzyh08it1w7Acn qBGuaSu+59BZ3ZqxRWWP4lZw/+WMALCbI48XXmt7AGeQSerC+fITedJfvdZBAlHPsnrm 4x3fFVIbZK1/yTAyvt3eDgELml8EqgONdnEELr7uDL6/Hzn1aZw5AlrGGFKHav2OBsaH aCJYllvs2o+hgiIdoTUSx1K1RIDV7pD7ONRq2GDQ7iq5/Ro4Yt1RuuTJdjRTyS/o0DN3 646Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=a8QN0MpO8jlRMT8bG2OAGmx7yQo+qOHSiFgI/X/YkB4=; b=qOP+AmfCfh7J06e+qoCG8pNvspdJVP2a85tRIN5VldTI/ylhQQLEYNCb26Xt/QiEoW gT3V73W6j9xBXRH1AHXG00mNptOLIGe1J/uMz0bXtsDH/zTKCQtkKHsTqrSL9Lvtid3H hA7UK24T7ewasl++fHolQqbhrWm63XiVHtaZvyadj8g3nEeoYsD3Z8+7nz7uRPlkgId3 cpn8ZSFUBJ05c6hzu5TaBi0WOInoV08YS+13tqjRm13cRtB6d/GqjjfBpMQsonzcPiC/ N1hQmtVZv9oZjFAzTvIKLQyxSL4hjTAZTvciXse4pEC8k+WTxFq1VV6P3E+JYtkEGZib dDnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WlrfW7iR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 27si6581397pfr.19.2018.01.26.08.19.18; Fri, 26 Jan 2018 08:19:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WlrfW7iR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753899AbeAZQSd (ORCPT + 99 others); Fri, 26 Jan 2018 11:18:33 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:40028 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752743AbeAZQS3 (ORCPT ); Fri, 26 Jan 2018 11:18:29 -0500 Received: by mail-qt0-f193.google.com with SMTP id s39so2545203qth.7; Fri, 26 Jan 2018 08:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=a8QN0MpO8jlRMT8bG2OAGmx7yQo+qOHSiFgI/X/YkB4=; b=WlrfW7iR+epxektrA6uorxbT9iEsdy+5/zie7GimMPyHXEd9AdLYsK8IeK6SANAZyH q9mcN4AbJ5eEymlchUnx841FGgcRc4XQpkooQ+wSxeJQxn31g9Ycf9JNFWw5ETOMphLY 4soNGGh+cTtCHUkhLNmvjCdSJ7ol4Oksku19SkkBw+3K3AUWfIrD5d36gACHHwTekbAt ON3sEc1Jl99JR2TRf5wd9oEUy0ePiErVWrb0HF2EZY9VWaWUTAOyDvtreW3CT9uwhgsY YJDumuooSXVxgLaIIhNlECXI3jOELnif4spSd3mVYMWikiN4CLrOw4v9BUfbcvouhE5F Sv2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=a8QN0MpO8jlRMT8bG2OAGmx7yQo+qOHSiFgI/X/YkB4=; b=uQhQI7wo6D+pRnn8ngOQ60vMrXqgc6nM+DSuTtb98uQ3FF0jOIkz/QocsYY7ZVxiap STqLDh8z6pbbMjCOPT+XAM5Yf2mBoIqOPDQFG7QhDTvMRFti/hUn+zo+yzNqPOdiNegh u310/V2xrOEWbqOvZCDt3kwWpOTGpupNC+N3cNxAILnkMkRUah+aIC6OhuKi5OEDWZhL FRKCyvmYQC0HuDyNYGPWijiBBkhcULsJzxKyxtw/VYWVx5wlRg4SY5Jd5Tb4ouhAhqJF S40o9uGz64Sm4hgEM81vT61AwA3f31TpXxdOLnVnvncZeaIbbSSR2KVijtLQ9LcNBL7c m3DA== X-Gm-Message-State: AKwxytcxb1f91/7LgYK9aPgxXDmBELHhietABWEX+wQoNPWJqgIEELlw sg6HE8ZwpOzIb2qWZztc5Nr2AhsD5UZYcI05ZHxXBg== X-Received: by 10.55.120.66 with SMTP id t63mr20836479qkc.345.1516983508615; Fri, 26 Jan 2018 08:18:28 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.175.35 with HTTP; Fri, 26 Jan 2018 08:18:28 -0800 (PST) In-Reply-To: References: From: Andy Shevchenko Date: Fri, 26 Jan 2018 18:18:28 +0200 Message-ID: Subject: Re: [PATCH v1 2/2] platform/x86: intel_pmc_ipc: Use regmap calls for GCR updates To: Kuppuswamy Sathyanarayanan Cc: Darren Hart , Andy Shevchenko , Zha Qipeng , "Krogerus, Heikki" , Linux Kernel Mailing List , Platform Driver , Sathyanarayanan Kuppuswamy Natarajan Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 26, 2018 at 12:53 AM, wrote: > From: Kuppuswamy Sathyanarayanan > > This patch adds support for regmap based implementation for GCR > read/write/update APIs. > Thanks. On the first glance this one looks okay. > Signed-off-by: Kuppuswamy Sathyanarayanan > --- > drivers/platform/x86/Kconfig | 1 + > drivers/platform/x86/intel_pmc_ipc.c | 124 +++++++++++++---------------------- > 2 files changed, 46 insertions(+), 79 deletions(-) > > This patch was originally part of "SCU/PMC/PUNIT IPC driver clean up" series. But I have > split them into two sets because we need more thorough review on generic IPC driver > design patches (second set). > > https://www.spinics.net/lists/linux-watchdog/msg12796.html > > Changes since previous set version (v8): > * Removed gcr_mem_base variable. > > diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig > index 2c745e8..ac618fd 100644 > --- a/drivers/platform/x86/Kconfig > +++ b/drivers/platform/x86/Kconfig > @@ -1087,6 +1087,7 @@ config PVPANIC > config INTEL_PMC_IPC > tristate "Intel PMC IPC Driver" > depends on ACPI > + select REGMAP_MMIO > ---help--- > This driver provides support for PMC control on some Intel platforms. > The PMC is an ARC processor which defines IPC commands for communication > diff --git a/drivers/platform/x86/intel_pmc_ipc.c b/drivers/platform/x86/intel_pmc_ipc.c > index fadf721..650144a 100644 > --- a/drivers/platform/x86/intel_pmc_ipc.c > +++ b/drivers/platform/x86/intel_pmc_ipc.c > @@ -35,6 +35,7 @@ > #include > #include > #include > +#include > > #include > > @@ -125,9 +126,7 @@ static struct intel_pmc_ipc_dev { > struct completion cmd_complete; > > /* gcr */ > - void __iomem *gcr_mem_base; > - bool has_gcr_regs; > - spinlock_t gcr_lock; > + struct regmap *gcr_regs; > } ipcdev; > > static char *ipc_err_sources[] = { > @@ -149,6 +148,15 @@ static char *ipc_err_sources[] = { > "Unsigned kernel", > }; > > +static struct regmap_config gcr_regmap_config = { > + .name = "intel_pmc_gcr", > + .reg_bits = 32, > + .reg_stride = 4, > + .val_bits = 32, > + .fast_io = true, > + .max_register = PLAT_RESOURCE_GCR_SIZE, > +}; > + > /* Prevent concurrent calls to the PMC */ > static DEFINE_MUTEX(ipclock); > > @@ -182,21 +190,6 @@ static inline u32 ipc_data_readl(u32 offset) > return readl(ipcdev.ipc_base + IPC_READ_BUFFER + offset); > } > > -static inline u64 gcr_data_readq(u32 offset) > -{ > - return readq(ipcdev.gcr_mem_base + offset); > -} > - > -static inline int is_gcr_valid(u32 offset) > -{ > - if (!ipcdev.has_gcr_regs) > - return -EACCES; > - > - if (offset > PLAT_RESOURCE_GCR_SIZE) > - return -EINVAL; > - > - return 0; > -} > > /** > * intel_pmc_gcr_read() - Read PMC GCR register > @@ -209,21 +202,12 @@ static inline int is_gcr_valid(u32 offset) > */ > int intel_pmc_gcr_read(u32 offset, u32 *data) > { > - int ret; > - > - spin_lock(&ipcdev.gcr_lock); > - > - ret = is_gcr_valid(offset); > - if (ret < 0) { > - spin_unlock(&ipcdev.gcr_lock); > - return ret; > - } > - > - *data = readl(ipcdev.gcr_mem_base + offset); > + struct intel_pmc_ipc_dev *pmc = &ipcdev; > > - spin_unlock(&ipcdev.gcr_lock); > + if (!pmc->gcr_regs) > + return -EACCES; > > - return 0; > + return regmap_read(pmc->gcr_regs, offset, data); > } > EXPORT_SYMBOL_GPL(intel_pmc_gcr_read); > > @@ -239,21 +223,12 @@ EXPORT_SYMBOL_GPL(intel_pmc_gcr_read); > */ > int intel_pmc_gcr_write(u32 offset, u32 data) > { > - int ret; > - > - spin_lock(&ipcdev.gcr_lock); > - > - ret = is_gcr_valid(offset); > - if (ret < 0) { > - spin_unlock(&ipcdev.gcr_lock); > - return ret; > - } > - > - writel(data, ipcdev.gcr_mem_base + offset); > + struct intel_pmc_ipc_dev *pmc = &ipcdev; > > - spin_unlock(&ipcdev.gcr_lock); > + if (!pmc->gcr_regs) > + return -EACCES; > > - return 0; > + return regmap_write(pmc->gcr_regs, offset, data); > } > EXPORT_SYMBOL_GPL(intel_pmc_gcr_write); > > @@ -270,33 +245,12 @@ EXPORT_SYMBOL_GPL(intel_pmc_gcr_write); > */ > int intel_pmc_gcr_update(u32 offset, u32 mask, u32 val) > { > - u32 new_val; > - int ret = 0; > - > - spin_lock(&ipcdev.gcr_lock); > - > - ret = is_gcr_valid(offset); > - if (ret < 0) > - goto gcr_ipc_unlock; > - > - new_val = readl(ipcdev.gcr_mem_base + offset); > - > - new_val &= ~mask; > - new_val |= val & mask; > - > - writel(new_val, ipcdev.gcr_mem_base + offset); > - > - new_val = readl(ipcdev.gcr_mem_base + offset); > + struct intel_pmc_ipc_dev *pmc = &ipcdev; > > - /* check whether the bit update is successful */ > - if ((new_val & mask) != (val & mask)) { > - ret = -EIO; > - goto gcr_ipc_unlock; > - } > + if (!pmc->gcr_regs) > + return -EACCES; > > -gcr_ipc_unlock: > - spin_unlock(&ipcdev.gcr_lock); > - return ret; > + return regmap_update_bits(pmc->gcr_regs, offset, mask, val); > } > EXPORT_SYMBOL_GPL(intel_pmc_gcr_update); > > @@ -475,8 +429,6 @@ static int ipc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) > > pmc->irq_mode = IPC_TRIGGER_MODE_IRQ; > > - spin_lock_init(&ipcdev.gcr_lock); > - > ret = pcim_enable_device(pdev); > if (ret) > return ret; > @@ -759,7 +711,6 @@ static int ipc_plat_get_res(struct platform_device *pdev) > return PTR_ERR(addr); > > ipcdev.ipc_base = addr; > - ipcdev.gcr_mem_base = addr + PLAT_RESOURCE_GCR_OFFSET; > > return 0; > } > @@ -772,17 +723,26 @@ static int ipc_plat_get_res(struct platform_device *pdev) > */ > int intel_pmc_s0ix_counter_read(u64 *data) > { > + struct intel_pmc_ipc_dev *pmc = &ipcdev; > u64 deep, shlw; > + int ret; > > - if (!ipcdev.has_gcr_regs) > + if (!pmc->gcr_regs) > return -EACCES; > > - deep = gcr_data_readq(PMC_GCR_TELEM_DEEP_S0IX_REG); > - shlw = gcr_data_readq(PMC_GCR_TELEM_SHLW_S0IX_REG); > + ret = regmap_bulk_read(pmc->gcr_regs, PMC_GCR_TELEM_DEEP_S0IX_REG, > + &deep, 2); > + if (ret) > + return ret; > + > + ret = regmap_bulk_read(pmc->gcr_regs, PMC_GCR_TELEM_SHLW_S0IX_REG, > + &shlw, 2); > + if (ret) > + return ret; > > *data = S0IX_RESIDENCY_IN_USECS(deep, shlw); > > - return 0; > + return ret; > } > EXPORT_SYMBOL_GPL(intel_pmc_s0ix_counter_read); > > @@ -801,7 +761,6 @@ static int ipc_plat_probe(struct platform_device *pdev) > ipcdev.dev = &pdev->dev; > ipcdev.irq_mode = IPC_TRIGGER_MODE_IRQ; > init_completion(&ipcdev.cmd_complete); > - spin_lock_init(&ipcdev.gcr_lock); > > ipcdev.irq = platform_get_irq(pdev, 0); > if (ipcdev.irq < 0) { > @@ -815,6 +774,15 @@ static int ipc_plat_probe(struct platform_device *pdev) > return ret; > } > > + /* GCR base address is at ipc_base + PLAT_RESOURCE_GCR_OFFSET */ > + ipcdev.gcr_regs = devm_regmap_init_mmio_clk(ipcdev.dev, NULL, > + ipcdev.ipc_base + PLAT_RESOURCE_GCR_OFFSET, > + &gcr_regmap_config); > + if (IS_ERR(ipcdev.gcr_regs)) { > + dev_err(ipcdev.dev, "gcr_regs regmap init failed\n"); > + return PTR_ERR(ipcdev.gcr_regs); > + } > + > ret = ipc_create_pmc_devices(pdev); > if (ret) { > dev_err(&pdev->dev, "Failed to create PMC devices\n"); > @@ -836,8 +804,6 @@ static int ipc_plat_probe(struct platform_device *pdev) > return ret; > } > > - ipcdev.has_gcr_regs = true; > - > return 0; > } > > -- > 2.7.4 > -- With Best Regards, Andy Shevchenko