Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6916380ybp; Wed, 16 Oct 2019 00:35:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaTdrUJ2VWNpBqF9H7VoPn3Z7oA4GVBVKgcZ786tVpNXaPvX7QkM9TtgLPAildTooEnmub X-Received: by 2002:aa7:c38d:: with SMTP id k13mr37998501edq.34.1571211318313; Wed, 16 Oct 2019 00:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571211318; cv=none; d=google.com; s=arc-20160816; b=0pu9c+l43Tzah3WCB/7wxR1d97iKgUq7/EMeTcxrDSu2Ki2Wi2pG7hSPniIUmE7UOn 8VEs1gEguqwN8AXfGKAKJfp5ym6wg8UbJE9wZGRLbA13rmmdm4W/axthJ5CLt9X5dYQT rpyDxon7zY7ONahe7161RgAKfb/1gEbVLzamSomg59g6UYSesOOOSpo3DnZeruBVF4ag s6yBQ3z0sfVeNHtmce4hZupZff5uDpQ96A8QvQAdvNSDxtvkLKsU41eGMMg5ECKeg5n6 X9O7Rggh+DhD8bdyFVMbY+zF9auAWlkOt7jEQYmGkD0Z2Yuxs57aXAza1gyKIe8KN5/I PBUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=MRyV5VGzOFvJD5NtZvpjWbXZE/GnucRH2hQg8MRkrmE=; b=cE9yEVYJK+hFQNgN4hR9SR3i5z03aBVrxG9OdfnBXJB+sJAuCpPDCGG1fc2Qzm+m6A rker1DHIWJ2/rn68Oojzawhf0biC/8P3wRYseQplYo+Iis+de4mMYpKkot2fp1m1lorW vTc/YAf2Xk8nUUm4o5spsN/cx7JFjBI7T6O+NlTSgf5m6g8IfUcWfIFyMgU0c28oH/mp 6g18hjy9NDAL4IKyt/t4h8izA9F69N54Ny/pa9zzV3PddB8d+KH4PvG9nbym4kbWTgpM bptmv/J85epCIw67FWWLU+0DaTJg2keGva71fvoyw7uP2VVHqGv1oyxXSEYxDcGxISGF JgZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=JfcWX6oX; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d35si16063173ede.440.2019.10.16.00.34.54; Wed, 16 Oct 2019 00:35: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=@broadcom.com header.s=google header.b=JfcWX6oX; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390067AbfJOWqR (ORCPT + 99 others); Tue, 15 Oct 2019 18:46:17 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:45589 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390034AbfJOWqQ (ORCPT ); Tue, 15 Oct 2019 18:46:16 -0400 Received: by mail-pf1-f194.google.com with SMTP id y72so13383398pfb.12 for ; Tue, 15 Oct 2019 15:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MRyV5VGzOFvJD5NtZvpjWbXZE/GnucRH2hQg8MRkrmE=; b=JfcWX6oXfyVq3TmG7LHvU0pKK1ND0Oo4l2GcBxe6MeEUvf8OczBR7JJrhNl9e6zK91 SPT8wPn/444F6wWUkDN0WdiU2ZU46nlVO7twyuqpH0YHFnuwNo/zH/iPJrnMgS9jwucQ pdMuNwg902bajHGO5SpdM56zkUQTJy7hSCEq8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MRyV5VGzOFvJD5NtZvpjWbXZE/GnucRH2hQg8MRkrmE=; b=GzXNv5v7zxLgdzbeDZR1FvvwtN3OqOPtC6kf/eya60ZmjNrRsj4+mA8Q01T8PidliJ J5YbIo8/3J63rBBDIRYlNcHOX3Bbce83j6FB56cxLY0XYs9l0OQ7KLQST1eUj0fDItNt W0DP7pXpIpQknELMT8xrs8c+lQatws6dwj8ct9owcxWtL8iLN0hEVmAwiWWB1RjKmnxR KQUETHLEGAFWOLY3NO6aB7rUN2eksmziiP8vJTcGZBPVTDesDqAFFf74vaMBtWb7tXqZ 72qtweLTFUop9gRYDdg32KzQ5/ifeaGyLTOmuwE1gezQdi0g39wei81EtS8QBmg7Sris KCwg== X-Gm-Message-State: APjAAAXduHrkdYXgmoDeJArjULkiFJdUpJ56OhGCkquc9oFpOiWn2mFN wx/Qrb87LZXk5gwc5g9x2FzloA== X-Received: by 2002:a63:394:: with SMTP id 142mr40929199pgd.375.1571179575156; Tue, 15 Oct 2019 15:46:15 -0700 (PDT) Received: from lbrmn-mmayer.ric.broadcom.com ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id e127sm23019837pfe.37.2019.10.15.15.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 15:46:14 -0700 (PDT) From: Markus Mayer To: Brian Norris , Florian Fainelli , Gregory Fong Cc: Markus Mayer , Broadcom Kernel List , ARM Kernel List , Linux Kernel Mailing List Subject: [PATCH 3/8] memory: brcmstb: dpfe: add locking around DCPU enable/disable Date: Tue, 15 Oct 2019 15:45:08 -0700 Message-Id: <20191015224513.16969-4-mmayer@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191015224513.16969-1-mmayer@broadcom.com> References: <20191015224513.16969-1-mmayer@broadcom.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To ensure consistency, we add locking primitives inside the DCPU enable and disable routines. Signed-off-by: Markus Mayer --- drivers/memory/brcmstb_dpfe.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/drivers/memory/brcmstb_dpfe.c b/drivers/memory/brcmstb_dpfe.c index 2ef3e365c1b5..c10c24a76729 100644 --- a/drivers/memory/brcmstb_dpfe.c +++ b/drivers/memory/brcmstb_dpfe.c @@ -290,32 +290,41 @@ static const struct dpfe_api dpfe_api_v3 = { }, }; -static bool is_dcpu_enabled(void __iomem *regs) +static bool is_dcpu_enabled(struct brcmstb_dpfe_priv *priv) { u32 val; - val = readl_relaxed(regs + REG_DCPU_RESET); + mutex_lock(&priv->lock); + val = readl_relaxed(priv->regs + REG_DCPU_RESET); + mutex_unlock(&priv->lock); return !(val & DCPU_RESET_MASK); } -static void __disable_dcpu(void __iomem *regs) +static void __disable_dcpu(struct brcmstb_dpfe_priv *priv) { u32 val; - if (!is_dcpu_enabled(regs)) + if (!is_dcpu_enabled(priv)) return; + mutex_lock(&priv->lock); + /* Put DCPU in reset if it's running. */ - val = readl_relaxed(regs + REG_DCPU_RESET); + val = readl_relaxed(priv->regs + REG_DCPU_RESET); val |= (1 << DCPU_RESET_SHIFT); - writel_relaxed(val, regs + REG_DCPU_RESET); + writel_relaxed(val, priv->regs + REG_DCPU_RESET); + + mutex_unlock(&priv->lock); } -static void __enable_dcpu(void __iomem *regs) +static void __enable_dcpu(struct brcmstb_dpfe_priv *priv) { + void __iomem *regs = priv->regs; u32 val; + mutex_lock(&priv->lock); + /* Clear mailbox registers. */ writel_relaxed(0, regs + REG_TO_DCPU_MBOX); writel_relaxed(0, regs + REG_TO_HOST_MBOX); @@ -329,6 +338,8 @@ static void __enable_dcpu(void __iomem *regs) val = readl_relaxed(regs + REG_DCPU_RESET); val &= ~(1 << DCPU_RESET_SHIFT); writel_relaxed(val, regs + REG_DCPU_RESET); + + mutex_unlock(&priv->lock); } static unsigned int get_msg_chksum(const u32 msg[], unsigned int max) @@ -590,7 +601,7 @@ static int brcmstb_dpfe_download_firmware(struct platform_device *pdev, * Skip downloading the firmware if the DCPU is already running and * responding to commands. */ - if (is_dcpu_enabled(priv->regs)) { + if (is_dcpu_enabled(priv)) { u32 response[MSG_FIELD_MAX]; ret = __send_command(priv, DPFE_CMD_GET_INFO, response); @@ -615,7 +626,7 @@ static int brcmstb_dpfe_download_firmware(struct platform_device *pdev, if (ret) return -EFAULT; - __disable_dcpu(priv->regs); + __disable_dcpu(priv); is_big_endian = init->is_big_endian; dmem_size = init->dmem_len; @@ -641,7 +652,7 @@ static int brcmstb_dpfe_download_firmware(struct platform_device *pdev, if (ret) return ret; - __enable_dcpu(priv->regs); + __enable_dcpu(priv); return 0; } -- 2.17.1