From patchwork Mon Aug 14 21:49:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 110064 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp4887430qge; Mon, 14 Aug 2017 14:49:39 -0700 (PDT) X-Received: by 10.98.110.65 with SMTP id j62mr26224942pfc.115.1502747379025; Mon, 14 Aug 2017 14:49:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502747379; cv=none; d=google.com; s=arc-20160816; b=b/JFYbtQa8VLqQLPyKDMa3RRW6Y0t0UIKTvmIjyn1wt0P9wTwo+qo7ZZaotJ9P16Ko yIXHm7piU8EVzRPRJy3qbphnbIJiHdKgzDM/pbaQsnhPwghFigI0qmje3fqJ3eFhmWgS yyz6KuhUuoJn77PRYSM8AG9gBQLken19wROscPNZjvKn8e6lIisoGSIA25iaQA59DULi SrrcJAfr6VgaDwl7SnrfkyuJapDwEhin484uP8uWZD57/h6PXeM8eH9TUaCrrn1Deiu6 JxMMlfVfOmLY49zhQp4lUgXTBvcsTZSk5xlDl3LptmVUCVQZXZZdAURV3KOD08UP22On AOTg== 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:arc-authentication-results; bh=PeUPM00iuAJDxyTQTC8y3LQvlRSPwsWZxjSS6t27R8c=; b=gIGQA3ZJPC41+P0TaCVIQwPZ+Jn9uZkTXGIVbGl23OmnJLSAxyFWL2aPCs5mx/SXF7 ahe8WwPg+PX5/llc3C2Ct/JSsrSlxKKU1UZwcXsw3Ti4ktQXXXg2/oAMsomo+PEKcRLv IkMtUp8s6zQpaIT4OsAqjMakv0+htO5ctSt2SguX1SMOBKK0G4zYHymsF73r27AFhJHm k6zHgWe7aCQWrP8zVFDE5l1Rn0bt/MHRxCDUi9vKMFL75pfxvttECT4OX0Ud6LIhFraD fDwJXfUgeYcurS7vjMA4mS9bXhiOfX4WGSgybOkqvOmAB0utcve4A80VJbwY3O61SThF JhOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QQ8TtC8W; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5si4584685pgb.56.2017.08.14.14.49.38; Mon, 14 Aug 2017 14:49:39 -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=@linaro.org header.s=google header.b=QQ8TtC8W; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752671AbdHNVtf (ORCPT + 25 others); Mon, 14 Aug 2017 17:49:35 -0400 Received: from mail-pg0-f49.google.com ([74.125.83.49]:34416 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752605AbdHNVta (ORCPT ); Mon, 14 Aug 2017 17:49:30 -0400 Received: by mail-pg0-f49.google.com with SMTP id u185so55013001pgb.1 for ; Mon, 14 Aug 2017 14:49:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PeUPM00iuAJDxyTQTC8y3LQvlRSPwsWZxjSS6t27R8c=; b=QQ8TtC8WSe6hlgYIdF9ZTXGpp9KpHIKZ5yHD9Onsar/XPBGdaeLo3PEurGqOZ+d9kL OhR5wNQgMUswLsg9c7Sd02Nfn1rFR5/9udmRz0dn0QKSpMMUK4W4cNBwVArvBYIWRUP1 vvMNvKVzNxH5T5I/MQpFI8hh6IWr7yqQMg6+Y= 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=PeUPM00iuAJDxyTQTC8y3LQvlRSPwsWZxjSS6t27R8c=; b=DwhsoFERKaSwyk883Ic0KcbMBqIeKeXyciZX0IPElRosdoD1kebzHeqepZ6EDAF4KZ qKyaBwkVmb09sDpJ/5sBaLF0CByYa4E1zH3rPo+b8yh+/Mtdz2/9zXq0u4SF25nxh/x3 sq3NnKmAz3LiejZavJj7kLLdmLy6986AnH/xqwdS7lnTa3Od+FRjb+2oAHxhcE+0l6PN NH2fqoxYBgKJo8eo44KuFzmwU2ajityN85q4bTDDVUeT72qvFO/z2xNCdPRI9U06EH5u ZvA4cRr5CdQFy8jNZaVQYSmTDWemHGjOXqlUVH2EJVDtigjmMoTqUHNjeTsT3iIOq5sV Vaig== X-Gm-Message-State: AHYfb5hArTPaWoIi5laFOmS7XcMDO6nTFTV2pIYZa/ymK3tVoOE0hEyg WbiEOgp9t5vUcVzO X-Received: by 10.84.236.4 with SMTP id q4mr29017232plk.423.1502747369959; Mon, 14 Aug 2017 14:49:29 -0700 (PDT) Received: from localhost.localdomain (ip68-111-217-79.sd.sd.cox.net. [68.111.217.79]) by smtp.gmail.com with ESMTPSA id m2sm13545458pgs.72.2017.08.14.14.49.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 14:49:29 -0700 (PDT) From: Bjorn Andersson To: Andy Gross , David Brown Cc: Stephen Boyd , Arun Kumar Neelakantam , linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] soc: qcom: smem: Support getting cached entries Date: Mon, 14 Aug 2017 14:49:22 -0700 Message-Id: <20170814214922.18061-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170814214922.18061-1-bjorn.andersson@linaro.org> References: <20170814214922.18061-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On msm8996 cached SMEM items are used for storing the GLINK FIFOs, so for items not found in the uncached list we need to also search the cased list for these items. Signed-off-by: Bjorn Andersson --- Changes since v1: - phdr_to_first_cached_entry() endian conversion - e->size is a le32, not le16 drivers/soc/qcom/smem.c | 69 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 8 deletions(-) -- 2.12.0 diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index b451dbc4aa39..c28275be0038 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -52,7 +52,8 @@ * * Items in the non-cached region are allocated from the start of the partition * while items in the cached region are allocated from the end. The free area - * is hence the region between the cached and non-cached offsets. + * is hence the region between the cached and non-cached offsets. The header of + * cached items comes after the data. * * * To synchronize allocations in the shared memory heaps a remote spinlock must @@ -140,6 +141,7 @@ struct smem_header { * @flags: flags for the partition (currently unused) * @host0: first processor/host with access to this partition * @host1: second processor/host with access to this partition + * @cacheline: alignment for "cached" entries * @reserved: reserved entries for later use */ struct smem_ptable_entry { @@ -148,7 +150,8 @@ struct smem_ptable_entry { __le32 flags; __le16 host0; __le16 host1; - __le32 reserved[8]; + __le32 cacheline; + __le32 reserved[7]; }; /** @@ -230,6 +233,7 @@ struct smem_region { * @hwlock: reference to a hwspinlock * @partitions: list of pointers to partitions affecting the current * processor/host + * @cacheline: list of cacheline sizes for each host * @num_regions: number of @regions * @regions: list of the memory regions defining the shared memory */ @@ -239,6 +243,7 @@ struct qcom_smem { struct hwspinlock *hwlock; struct smem_partition_header *partitions[SMEM_HOST_COUNT]; + size_t cacheline[SMEM_HOST_COUNT]; unsigned num_regions; struct smem_region regions[0]; @@ -252,6 +257,14 @@ phdr_to_last_uncached_entry(struct smem_partition_header *phdr) return p + le32_to_cpu(phdr->offset_free_uncached); } +static void *phdr_to_first_cached_entry(struct smem_partition_header *phdr, + size_t cacheline) +{ + void *p = phdr; + + return p + le32_to_cpu(phdr->size) - ALIGN(sizeof(*phdr), cacheline); +} + static void *phdr_to_last_cached_entry(struct smem_partition_header *phdr) { void *p = phdr; @@ -276,6 +289,14 @@ uncached_entry_next(struct smem_private_entry *e) le32_to_cpu(e->size); } +static struct smem_private_entry * +cached_entry_next(struct smem_private_entry *e, size_t cacheline) +{ + void *p = e; + + return p - le32_to_cpu(e->size) - ALIGN(sizeof(*e), cacheline); +} + static void *uncached_entry_to_item(struct smem_private_entry *e) { void *p = e; @@ -283,6 +304,13 @@ static void *uncached_entry_to_item(struct smem_private_entry *e) return p + sizeof(*e) + le16_to_cpu(e->padding_hdr); } +static void *cached_entry_to_item(struct smem_private_entry *e) +{ + void *p = e; + + return p - le32_to_cpu(e->size); +} + /* Pointer to the one and only smem handle */ static struct qcom_smem *__smem; @@ -458,18 +486,17 @@ static void *qcom_smem_get_private(struct qcom_smem *smem, { struct smem_partition_header *phdr; struct smem_private_entry *e, *end; + size_t cacheline; phdr = smem->partitions[host]; + cacheline = smem->cacheline[host]; + e = phdr_to_first_uncached_entry(phdr); end = phdr_to_last_uncached_entry(phdr); while (e < end) { - if (e->canary != SMEM_PRIVATE_CANARY) { - dev_err(smem->dev, - "Found invalid canary in host %d partition\n", - host); - return ERR_PTR(-EINVAL); - } + if (e->canary != SMEM_PRIVATE_CANARY) + goto invalid_canary; if (le16_to_cpu(e->item) == item) { if (size != NULL) @@ -482,7 +509,32 @@ static void *qcom_smem_get_private(struct qcom_smem *smem, e = uncached_entry_next(e); } + /* Item was not found in the uncached list, search the cached list */ + + e = phdr_to_first_cached_entry(phdr, cacheline); + end = phdr_to_last_cached_entry(phdr); + + while (e > end) { + if (e->canary != SMEM_PRIVATE_CANARY) + goto invalid_canary; + + if (le16_to_cpu(e->item) == item) { + if (size != NULL) + *size = le32_to_cpu(e->size) - + le16_to_cpu(e->padding_data); + + return cached_entry_to_item(e); + } + + e = cached_entry_next(e, cacheline); + } + return ERR_PTR(-ENOENT); + +invalid_canary: + dev_err(smem->dev, "Found invalid canary in host %d partition\n", host); + + return ERR_PTR(-EINVAL); } /** @@ -659,6 +711,7 @@ static int qcom_smem_enumerate_partitions(struct qcom_smem *smem, } smem->partitions[remote_host] = header; + smem->cacheline[remote_host] = le32_to_cpu(entry->cacheline); } return 0;