From patchwork Thu Aug 10 19:37:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 109846 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp2824815qge; Thu, 10 Aug 2017 12:38:11 -0700 (PDT) X-Received: by 10.84.236.6 with SMTP id q6mr15010399plk.346.1502393890927; Thu, 10 Aug 2017 12:38:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502393890; cv=none; d=google.com; s=arc-20160816; b=ILH3pdSBd6ghuUygS0HEAzSSJYvLFgx6X2ES/m73fxTkzaVlY23koocRT7Bo7RcS15 PczFMnf9R5Lvd+h9DA3WXIer9E7QGew3Kvl+2ZR8r8FZiy/VuzEkLTFttsOV4PDUN8iu Oqx/QV+im7YKSgLzP59Z50Q57DEyPusGh3tIOsbI5iEJIUIP9CJ5UJVDtSD9K9GhGvGC rxUAtT3pxR9ac1FO9S/KfeLh3ZwIhx+ZiMstU1q0tE7sKCbBWgq/t+3A1U7D4/T97Ku6 zF28JfEN1GpXhZ3CVX7EIuFYuD05Zd1ndu9nzIH20sUJGvCR+cA7FTg5c4Q5TneoIZsV bnnQ== 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=PVNz8v2xyQuVYxXcNVxesg4Rp2+0FsFnfg+T4eHN5gw=; b=BfCpUug5RAhE+iunaQsB6LRJyHoASInFA7O6UeNHU56G6lCxTgkUco9B8PepY0K8jh icJBRUfsRpP55IhbaUQNCkOh15d4W0iTI18LxanK2daCT/oU2G67JVHjN5fzcAsP7Bd2 11lGu4zBW32j56hU68ZMBYkJ0084o2JZjoa0Az96ZzDw29YteaSg5EN2mtd7+XE8jQNr 5v55zGnIE4R8yjCQUK4p0CHvjx6JBtjhRP4cUlRfcr3/fA6C2wxeRJ2cZkpMhIEVaHbL /QiAcokHkqK34m8si+QVvPkI7OT4LUxWHuZdJjRPhoj8SBZ+c4PLGNHSzLzEQNKcf63x 7kZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PSz+avTl; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (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 94si5154115pla.477.2017.08.10.12.38.10; Thu, 10 Aug 2017 12:38:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PSz+avTl; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753089AbdHJTiG (ORCPT + 9 others); Thu, 10 Aug 2017 15:38:06 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:34983 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752756AbdHJTiE (ORCPT ); Thu, 10 Aug 2017 15:38:04 -0400 Received: by mail-pg0-f42.google.com with SMTP id v189so6780005pgd.2 for ; Thu, 10 Aug 2017 12:38:04 -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=wdY0lZzhLn2DSPSQNhZGYfRArUlsr0zH0icwmlK7H9k=; b=PSz+avTly86NBsotKvTymr0Rtka4YHOv5cdHfRQMtvjyzptIqO2KCmvqFr1IWDsK9e L5UFcVAZak7Cr3emJ+ZIyahGuiY0PexYIxr+iZkY201Lij+w20InN3xTGRKhAki8D98C STVl7SqpUQ+6rEOOPsYz5VR0tTRBbCXWzCmYI= 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=wdY0lZzhLn2DSPSQNhZGYfRArUlsr0zH0icwmlK7H9k=; b=PrCTUjyEoPjbRaDq2RuZDNs7LJ66fx5ZPDvg8wGZLs8XLj0/ghVmx2HfdFisGfDj68 OXxum/TR1+MgvUe/ZYwFf3v0YsLM091MJ8/ux2WevFNs5TQTl37hQOp1+uHtXyoacJTo ncUDRDnBmNGMwLvszMWX1ffPF69knGpawt5qBzkGy2aUHrnbQ63ZXSZQaDVHQYvaRldp Z1pBMOTZsMaiPXLTJEMZGnQ4lUtJj8f64LbLY5uFhfbXk/ZFDZ+dWTW061c5ISMgp0RP pVUykyTZf4JpPKwqVbQHBdJlUW4YrefdmSojSfCykdh7cj3nrrMCU83l470JuFIF9x/t RQ9A== X-Gm-Message-State: AHYfb5gi7dNlI91QaaKeiCP9Yuim9xpydsG+bqdWvUgjRUxNM3McW+Yu MysS1LDbnCpbqpAO X-Received: by 10.84.209.227 with SMTP id y90mr14646880plh.446.1502393884270; Thu, 10 Aug 2017 12:38:04 -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 d71sm13523970pfg.169.2017.08.10.12.38.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Aug 2017 12:38:03 -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 2/2] soc: qcom: smem: Support getting cached entries Date: Thu, 10 Aug 2017 12:37:57 -0700 Message-Id: <20170810193757.9136-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170810193757.9136-1-bjorn.andersson@linaro.org> References: <20170810193757.9136-1-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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 --- drivers/soc/qcom/smem.c | 69 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 8 deletions(-) -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index b451dbc4aa39..67a8b6136ef9 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 + 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 - le16_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;