Received: by 10.192.165.148 with SMTP id m20csp2472419imm; Thu, 26 Apr 2018 11:34:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/OFG1sh8pyAcGgiNHpZm7QVSWmwr2d30PqKrdG+LoBjWD3ZFNbTb7mihWXmuOgwHP3d/t/ X-Received: by 2002:a17:902:9890:: with SMTP id s16-v6mr35191093plp.132.1524767658440; Thu, 26 Apr 2018 11:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524767658; cv=none; d=google.com; s=arc-20160816; b=hZu/Mn2YVfU/1wHXMVZwgrPqmev58jtVJR+ZHE3AadW8w6JYVUw6v0DmgVGsDZ6LJY ZyvSOCvUdu7P9/1YPfrLkPVO25LU1uYzmw71TIPHJkA4gkeAygYKGBjkYTUyBqiXCyi4 SINuOXlr0QiT6tMVBk0zcqV7lFYHZocWXCB/i+kSj1Y8XUDViTmhjiiw5JgRB5qRGGuQ 7/NaTsNT+dClRyVwr7T+Sk0eh9+vfJVeSjupeja7Wa4D5RCUaex/2AeA36Z97/Lgh0fH x5a6n2I1NNJlCItUjaHYG06SZ7FDRZn40jjGCtOiIBH6gZpTszzXHUtvtHni88bfvZ3U LPIw== 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 :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=B6CKQ68djBiTNuMjpb3VdIQbvf7J2IZGNPdPl5YradE=; b=JpRDx4hbaC6VVYr1LXGQoDQFq7qtSMhI345bdBfxpcfM8LrTGF8g4cDCLkl+LSzek/ FPucUqDNwayq+mnL7BO7Phf1511kcAxpxbDh2cpZ8jjkRicg6Cg31Og3wXd3PX3/VpLb efNoP7A7WEy6/1rGM4ytIZKHERHImOXj6xOhBPCBPsnbs1ZBaEA5spfifzoisFhXrDXb 0XsUEp997Ge2+qRS5RADD7xZ1PJyuYsU5FEi3OXLNCu/q+J3srOaKQUkZn1F03UZR4Bf 0Z8KnSor67Dn2kC7//vIfj1I09PnvRbO+SDSdHuaNszumPrJfIfOo0QlB2H/Q8WJTnZ+ Lp0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Vj4RXZ3N; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3-v6si19549932pld.384.2018.04.26.11.34.03; Thu, 26 Apr 2018 11:34:18 -0700 (PDT) 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=@chromium.org header.s=google header.b=Vj4RXZ3N; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754582AbeDZSc5 (ORCPT + 99 others); Thu, 26 Apr 2018 14:32:57 -0400 Received: from mail-ot0-f196.google.com ([74.125.82.196]:36413 "EHLO mail-ot0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754208AbeDZScy (ORCPT ); Thu, 26 Apr 2018 14:32:54 -0400 Received: by mail-ot0-f196.google.com with SMTP id p2-v6so30532522otf.3 for ; Thu, 26 Apr 2018 11:32:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=B6CKQ68djBiTNuMjpb3VdIQbvf7J2IZGNPdPl5YradE=; b=Vj4RXZ3NcHcK+ZrRNIzdvMGltLQ0gwOskJVTIX0obsMNdeZPLEQK5ESxvQq1astcoQ wqknwk5qACUdCsXuyjmOvm4dBKU8zlfDoSAtm+KcciB14rCdcp2Zwrrmh/qWjeiEWkKS o9+QEi/UomvnLghgDmwvpeL9dSq0J2Tv/F8IA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=B6CKQ68djBiTNuMjpb3VdIQbvf7J2IZGNPdPl5YradE=; b=gmsHRvMMbYz7bnUIM8il/+uaOZF9L2WVH0apsifAiI0pzJsZDnHO/2U3aFb3Vizd3s 8KRKDoHto/h9Y63IbjpmQUqoQrNWsTcEEnvvgWAMiEmR6LaaDKeLTtu06juPP5Mtpz5d rGKoUhXcRfERFp9MGfgzakkTlM4u084RTi8139cZ8RovdYp2WKmEJRl3yD1y4Nb3wb9U J1KXeKBpz/XyChq2yYciKDN+EjlYMDzIQX4qhPy9hKgMx09h/M0tuBqnQlxQmTl7uAzZ 4SX/vRyel9zp/wqO/iU0yiTTtIPd7cSYFnIj+yH3LzvQeH2TE+I92fgbhor0rAMsi0MS JZCw== X-Gm-Message-State: ALQs6tDGY9BqbVrTZtEoVSPpTlS7ScnmLT3EkdhqAgWFUV01zRFfn7pU OrF04XoUSVOawt7PrrBWj7eYmI/ownM= X-Received: by 2002:a9d:3644:: with SMTP id w62-v6mr24721109otb.287.1524767573547; Thu, 26 Apr 2018 11:32:53 -0700 (PDT) Received: from mail-oi0-f43.google.com (mail-oi0-f43.google.com. [209.85.218.43]) by smtp.gmail.com with ESMTPSA id p200-v6sm11957529oic.51.2018.04.26.11.32.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Apr 2018 11:32:52 -0700 (PDT) Received: by mail-oi0-f43.google.com with SMTP id f63-v6so25057140oic.4 for ; Thu, 26 Apr 2018 11:32:52 -0700 (PDT) X-Received: by 2002:aca:4ac7:: with SMTP id x190-v6mr19425181oia.11.1524767571479; Thu, 26 Apr 2018 11:32:51 -0700 (PDT) MIME-Version: 1.0 References: <1524524972-12014-1-git-send-email-rishabhb@codeaurora.org> <1524524972-12014-3-git-send-email-rishabhb@codeaurora.org> In-Reply-To: <1524524972-12014-3-git-send-email-rishabhb@codeaurora.org> From: Evan Green Date: Thu, 26 Apr 2018 18:32:16 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 2/2] drivers: soc: Add LLCC driver To: rishabhb@codeaurora.org Cc: linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm@lists.infradead.org, linux-kernel@vger.kernel.org, tsoni@codeaurora.org, kyan@codeaurora.org, ckadabi@codeaurora.org, robh@kernel.org 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 Hi Rishabh, On Mon, Apr 23, 2018 at 4:11 PM Rishabh Bhatnagar wrote: > LLCC (Last Level Cache Controller) provides additional cache memory > in the system. LLCC is partitioned into multiple slices and each > slice gets its own priority, size, ID and other config parameters. > LLCC driver programs these parameters for each slice. Clients that > are assigned to use LLCC need to get information such size & ID of the > slice they get and activate or deactivate the slice as needed. LLCC driver > provides API for the clients to perform these operations. > Signed-off-by: Channagoud Kadabi > Signed-off-by: Rishabh Bhatnagar > --- > drivers/soc/qcom/Kconfig | 17 ++ > drivers/soc/qcom/Makefile | 2 + > drivers/soc/qcom/llcc-sdm845.c | 108 +++++++++++ > drivers/soc/qcom/llcc-slice.c | 380 +++++++++++++++++++++++++++++++++++++ > include/linux/soc/qcom/llcc-qcom.h | 167 ++++++++++++++++ > 5 files changed, 674 insertions(+) > create mode 100644 drivers/soc/qcom/llcc-sdm845.c > create mode 100644 drivers/soc/qcom/llcc-slice.c > create mode 100644 include/linux/soc/qcom/llcc-qcom.h ... > diff --git a/drivers/soc/qcom/llcc-slice.c b/drivers/soc/qcom/llcc-slice.c > new file mode 100644 > index 0000000..fd2b607 > --- /dev/null > +++ b/drivers/soc/qcom/llcc-slice.c > @@ -0,0 +1,380 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. > + * > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define ACTIVATE 0x1 > +#define DEACTIVATE 0x2 > +#define ACT_CTRL_OPCODE_ACTIVATE 0x1 > +#define ACT_CTRL_OPCODE_DEACTIVATE 0x2 > +#define ACT_CTRL_ACT_TRIG 0x1 > +#define ACT_CTRL_OPCODE_SHIFT 0x1 > +#define ATTR1_PROBE_TARGET_WAYS_SHIFT 0x2 > +#define ATTR1_FIXED_SIZE_SHIFT 0x3 > +#define ATTR1_PRIORITY_SHIFT 0x4 > +#define ATTR1_MAX_CAP_SHIFT 0x10 > +#define ATTR0_RES_WAYS_MASK 0x00000fff > +#define ATR0_BONUS_WAYS_MASK 0x0fff0000 This looks like it's missing a t, eg ATTR0_BONUS_WAYS_MASK. > +#define ATTR0_BONUS_WAYS_SHIFT 0x10 > +#define LLCC_STATUS_READ_DELAY 100 > + > +#define CACHE_LINE_SIZE_SHIFT 6 > + > +#define LLCC_COMMON_STATUS0 0x0003000c > +#define LLCC_LB_CNT_MASK 0xf0000000 > +#define LLCC_LB_CNT_SHIFT 28 > + > +#define MAX_CAP_TO_BYTES(n) (n * 1024) > +#define LLCC_TRP_ACT_CTRLn(n) (n * 0x1000) > +#define LLCC_TRP_STATUSn(n) (4 + n * 0x1000) > +#define LLCC_TRP_ATTR0_CFGn(n) (0x21000 + 0x8 * n) > +#define LLCC_TRP_ATTR1_CFGn(n) (0x21004 + 0x8 * n) > + > +#define BANK_OFFSET_STRIDE 0x80000 > + > +static const struct regmap_config llcc_regmap_config = { > + .reg_bits = 32, > + .reg_stride = 4, > + .val_bits = 32, > + .fast_io = true, > +}; > + > +/* Get the slice entry by index */ > +static struct llcc_slice_desc *llcc_slice_get_entry(struct device *dev, int n) > +{ > + struct of_phandle_args phargs; > + struct llcc_drv_data *drv; > + const struct llcc_slice_config *llcc_data_ptr; > + struct llcc_slice_desc *desc; > + struct platform_device *pdev; > + u32 sz, count; > + > + if (of_parse_phandle_with_args(dev->of_node, "cache-slices", > + "#cache-cells", n, &phargs)) > + return ERR_PTR(-ENODEV); > + > + pdev = of_find_device_by_node(phargs.np); > + if (!pdev) > + return ERR_PTR(-ENODEV); > + > + drv = platform_get_drvdata(pdev); > + if (!drv) > + return ERR_PTR(-EFAULT); EFAULT is a little weird here, right? Maybe EINVAL or ENODEV? > + > + llcc_data_ptr = drv->cfg; > + sz = drv->cfg_size; > + count = 0; > + > + while (llcc_data_ptr && count < sz) { > + if (llcc_data_ptr->usecase_id == phargs.args[0]) > + break; > + llcc_data_ptr++; > + count++; > + } > + > + if (llcc_data_ptr == NULL || count == sz) > + return ERR_PTR(-ENODEV); > + > + desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); > + if (!desc) > + return ERR_PTR(-ENOMEM); > + > + desc->slice_id = llcc_data_ptr->slice_id; > + desc->slice_size = llcc_data_ptr->max_cap; > + desc->dev = &pdev->dev; > + > + return desc; > +} > + > +/** > + * llcc_slice_getd - get llcc slice descriptor > + * @dev: Device pointer of the client > + * @name: Name of the use case > + * > + * A pointer to llcc slice descriptor will be returned on success and > + * and error pointer is returned on failure > + */ > +struct llcc_slice_desc *llcc_slice_getd(struct device *dev, const char *name) > +{ > + struct device_node *np = dev->of_node; > + int index = 0; > + const char *slice_name; > + struct property *prop; > + > + if (!of_get_property(np, "cache-slice-names", NULL)) > + return ERR_PTR(-ENOENT); > + > + of_property_for_each_string(np, "cache-slice-names", prop, slice_name) { > + if (!strcmp(name, slice_name)) > + break; > + index++; > + } > + return llcc_slice_get_entry(dev, index); > +} > +EXPORT_SYMBOL_GPL(llcc_slice_getd); > + > +/** > + * llcc_slice_putd - llcc slice descritpor > + * @desc: Pointer to llcc slice descriptor > + */ > +void llcc_slice_putd(struct llcc_slice_desc *desc) > +{ > + devm_kfree(desc->dev, desc); > +} > +EXPORT_SYMBOL_GPL(llcc_slice_putd); > + > +static int llcc_update_act_ctrl(struct llcc_drv_data *drv, u32 sid, > + u32 act_ctrl_reg_val, u32 status) > +{ > + u32 act_ctrl_reg; > + u32 status_reg; > + u32 slice_status; > + int ret = 0; > + > + act_ctrl_reg = drv->bcast_off + LLCC_TRP_ACT_CTRLn(sid); > + status_reg = drv->bcast_off + LLCC_TRP_STATUSn(sid); > + > + /* Set the ACTIVE trigger */ > + act_ctrl_reg_val |= ACT_CTRL_ACT_TRIG; > + ret = regmap_write(drv->regmap, act_ctrl_reg, act_ctrl_reg_val); > + if (ret) > + return ret; > + > + /* Clear the ACTIVE trigger */ > + act_ctrl_reg_val &= ~ACT_CTRL_ACT_TRIG; > + ret = regmap_write(drv->regmap, act_ctrl_reg, act_ctrl_reg_val); > + if (ret) > + return ret; > + > + ret = regmap_read_poll_timeout(drv->regmap, status_reg, slice_status, > + !(slice_status & status), 0, LLCC_STATUS_READ_DELAY); > + return ret; > +} > + > +/** > + * llcc_slice_activate - Activate the llcc slice > + * @desc: Pointer to llcc slice descriptor > + * > + * A value of zero will be returned on success and a negative errno will > + * be returned in error cases > + */ > +int llcc_slice_activate(struct llcc_slice_desc *desc) > +{ > + int ret; > + u32 act_ctrl_val; > + struct llcc_drv_data *drv; > + > + drv = dev_get_drvdata(desc->dev); > + if (!drv) > + return -EINVAL; > + > + mutex_lock(&drv->lock); > + if (test_bit(desc->slice_id, drv->bitmap)) { > + mutex_unlock(&drv->lock); > + return 0; > + } > + > + act_ctrl_val = ACT_CTRL_OPCODE_ACTIVATE << ACT_CTRL_OPCODE_SHIFT; > + > + ret = llcc_update_act_ctrl(drv, desc->slice_id, act_ctrl_val, > + DEACTIVATE); > + > + __set_bit(desc->slice_id, drv->bitmap); If llcc_update_act_ctrl fails, your bitmap will become out of sync with reality, and future calls to llcc_slice activate will return immediately. Perhaps you should only set the bit if ret is zero. > + mutex_unlock(&drv->lock); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(llcc_slice_activate); > + > +/** > + * llcc_slice_deactivate - Deactivate the llcc slice > + * @desc: Pointer to llcc slice descriptor > + * > + * A value of zero will be returned on success and a negative errno will > + * be returned in error cases > + */ > +int llcc_slice_deactivate(struct llcc_slice_desc *desc) > +{ > + u32 act_ctrl_val; > + int ret; > + struct llcc_drv_data *drv; > + > + drv = dev_get_drvdata(desc->dev); > + if (!drv) > + return -EINVAL; > + > + mutex_lock(&drv->lock); > + if (!test_bit(desc->slice_id, drv->bitmap)) { > + mutex_unlock(&drv->lock); > + return 0; > + } > + act_ctrl_val = ACT_CTRL_OPCODE_DEACTIVATE << ACT_CTRL_OPCODE_SHIFT; > + > + ret = llcc_update_act_ctrl(drv, desc->slice_id, act_ctrl_val, > + ACTIVATE); > + > + __clear_bit(desc->slice_id, drv->bitmap); Conversely, only clear the bit if ret was zero. If you fix these issues, then feel free to add my Reviewed-by to the next spin of this patch. -Evan