From patchwork Fri Jun 22 02:11:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 933156 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="CHcv0k6V"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41Bt9q4Zjkz9s4b for ; Fri, 22 Jun 2018 19:11:59 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 508E1C21FBF; Fri, 22 Jun 2018 09:11:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=DATE_IN_PAST_06_12, FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 5ADEDC21C2F; Fri, 22 Jun 2018 09:11:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A602AC21C2F; Fri, 22 Jun 2018 09:11:51 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by lists.denx.de (Postfix) with ESMTPS id 45BADC21C2C for ; Fri, 22 Jun 2018 09:11:51 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id v131-v6so1689939wma.1 for ; Fri, 22 Jun 2018 02:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=88oXOt9ABhKwuTIBel/aksAgy8Kn/0GzRCejrtA7p+k=; b=CHcv0k6Vwq/CskXx75RuJrFY4DxN2vBKPrs2dtLXk2sfr4EH1AtvnjFEZuGOS2kcXs 25IB4ZAqOCKHu+j4zADEGB2wfj/ex9oF/m9GUTwdFpqtLkrFmgb53xEPbPtZMUmfwZSd PUute3KY20hXOUbd7nMCbDA72b5TxhwBynz3uGKs8Ns4HB4y4S2W6fmzkPjor4zz+UMn /ueV47lctqGLijV6p+MIUdrjlNqCuystw/QrOXiPvtbU0Ipyv/KRBGIpG10ykqgdMOw7 14WwqNrcju1wmC2tRidFjsXjhn1dbsOtO5FU4KvHfurlx9ZaD8PoTPaUuYhbeF/2p5yq h4BQ== 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=88oXOt9ABhKwuTIBel/aksAgy8Kn/0GzRCejrtA7p+k=; b=gmNA8TlT4+KN+PhCwYzvYNv71rFBV493eMt95h1jP/d/O6Ke68lpNvNaGdBLw/8iS0 q52kVXj9N32VcRbU5+v1icXrx6qwVoq9G433Ps16CflKUzI6zCuIF8RuUllG8NRHTIhy Atwbbt8KO6vMnXR9nV2L50v71W2gDgD+jmXQAFqyETlG2DeGSAS9UCT1e5CkQUj1hA/n LEdFH/QQ1agVmfy9zGlXewdJ1R7ls2/KNIsJjTA2XG3Ks0ZeY/W8LZ+UOX4EjZIGl4v1 1+Yf/I4yCeB6HWRpL/Wf1djqTYNysgFx+21qrSsAjes2dqB8WEkzF/gRefJNtVl/Uj1Q 1+Zg== X-Gm-Message-State: APt69E10Ny+wUzTcjxWp7dY6McO+iYjTGxJ7ySNHATui8k8Aa6krEXBJ o2TykF7OTltBC0ih1ueBa20= X-Google-Smtp-Source: ADUXVKKW1PsJrg18IcBZSucS+HPU8IiIWNRdllJhWWh0xvv9Gpcu7OkkNegO6AgkDb1PvQvdKh2whg== X-Received: by 2002:a1c:28c6:: with SMTP id o189-v6mr1084441wmo.102.1529658710867; Fri, 22 Jun 2018 02:11:50 -0700 (PDT) Received: from localhost.localdomain ([141.226.166.38]) by smtp.gmail.com with ESMTPSA id g16-v6sm6938310wro.86.2018.06.22.02.11.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 02:11:50 -0700 (PDT) From: Ramon Fried To: Simon Glass , u-boot@lists.denx.de, jramirez@baylibre.com, xypron.glpk@gmx.de Date: Fri, 22 Jun 2018 05:11:28 +0300 Message-Id: <20180622021133.24062-2-ramon.fried@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180622021133.24062-1-ramon.fried@gmail.com> References: <20180622021133.24062-1-ramon.fried@gmail.com> Cc: bjorn.andersson@linaro.org, Joe Hershberger Subject: [U-Boot] [PATCH v2 1/6] dm: SMEM (Shared memory) uclass X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This is a uclass for Shared memory manager drivers. A Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors. Signed-off-by: Ramon Fried Reviewed-by: Simon Glass Reviewed-by: Philipp Tomsich --- Changes in v2: (As suggested by Simon Glass) - Introduced a new dm class (CLASS_SMEM) instead of CLASS_SOC. - Added sandbox driver - Added testing for DM class. drivers/Makefile | 1 + drivers/smem/Kconfig | 2 + drivers/smem/Makefile | 5 +++ drivers/smem/smem-uclass.c | 53 ++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/smem.h | 84 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 146 insertions(+) create mode 100644 drivers/smem/Kconfig create mode 100644 drivers/smem/Makefile create mode 100644 drivers/smem/smem-uclass.c create mode 100644 include/smem.h diff --git a/drivers/Makefile b/drivers/Makefile index a213ea9671..ba4a561358 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -98,6 +98,7 @@ obj-y += pwm/ obj-y += reset/ obj-y += input/ # SOC specific infrastructure drivers. +obj-y += smem/ obj-y += soc/ obj-$(CONFIG_REMOTEPROC) += remoteproc/ obj-y += thermal/ diff --git a/drivers/smem/Kconfig b/drivers/smem/Kconfig new file mode 100644 index 0000000000..64337a8b8e --- /dev/null +++ b/drivers/smem/Kconfig @@ -0,0 +1,2 @@ +menuconfig SMEM + bool "SMEM (Shared Memory mamanger) support" diff --git a/drivers/smem/Makefile b/drivers/smem/Makefile new file mode 100644 index 0000000000..ca55c4512d --- /dev/null +++ b/drivers/smem/Makefile @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Makefile for the U-Boot SMEM interface drivers + +obj-$(CONFIG_SMEM) += smem-uclass.o diff --git a/drivers/smem/smem-uclass.c b/drivers/smem/smem-uclass.c new file mode 100644 index 0000000000..07ed1a92d8 --- /dev/null +++ b/drivers/smem/smem-uclass.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2018 Ramon Fried + */ + +#include +#include +#include + +int smem_alloc(struct udevice *dev, unsigned int host, + unsigned int item, size_t size) +{ + struct smem_ops *ops = smem_get_ops(dev); + + if (!ops->alloc) + return -ENOSYS; + + return ops->alloc(host, item, size); +} + +void *smem_get(struct udevice *dev, unsigned int host, + unsigned int item, size_t *size) +{ + struct smem_ops *ops = smem_get_ops(dev); + + if (!ops->get) + return NULL; + + return ops->get(host, item, size); +} + +int smem_get_free_space(struct udevice *dev, unsigned int host, size_t *free) +{ + struct smem_ops *ops = smem_get_ops(dev); + + int ret; + + if (!ops->get_free_space) + return -ENOSYS; + + ret = ops->get_free_space(host); + if (ret > 0) + *free = ret; + else + return ret; + + return 0; +} + +UCLASS_DRIVER(smem) = { + .id = UCLASS_SMEM, + .name = "smem", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index d7f9df3583..a39643ec5e 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -74,6 +74,7 @@ enum uclass_id { UCLASS_RTC, /* Real time clock device */ UCLASS_SCSI, /* SCSI device */ UCLASS_SERIAL, /* Serial UART */ + UCLASS_SMEM, /* Shared memory interface */ UCLASS_SPI, /* SPI bus */ UCLASS_SPMI, /* System Power Management Interface bus */ UCLASS_SPI_FLASH, /* SPI flash */ diff --git a/include/smem.h b/include/smem.h new file mode 100644 index 0000000000..201960232c --- /dev/null +++ b/include/smem.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * header file for smem driver. + * + * Copyright (c) 2018 Ramon Fried + */ + +#ifndef _smemh_ +#define _smemh_ + +/* struct smem_ops: Operations for the SMEM uclass */ +struct smem_ops { + /** + * alloc() - allocate space for a smem item + * + * @host: remote processor id, or -1 + * @item: smem item handle + * @size: number of bytes to be allocated + * @return 0 if OK, -ve on error + */ + int (*alloc)(unsigned int host, + unsigned int item, size_t size); + + /** + * get() - Resolve ptr of size of a smem item + * + * @host: the remote processor, of -1 + * @item: smem item handle + * @size: pointer to be filled out with the size of the item + * @return pointer on success, NULL on error + */ + void *(*get)(unsigned int host, + unsigned int item, size_t *size); + + /** + * get_free_space() - Set the PWM invert + * + * @host: the remote processor identifying a partition, or -1 + * @return free space, -ve on error + */ + int (*get_free_space)(unsigned int host); +}; + +#define smem_get_ops(dev) ((struct smem_ops *)(dev)->driver->ops) + +/** + * smem_alloc() - allocate space for a smem item + * @host: remote processor id, or -1 + * @item: smem item handle + * @size: number of bytes to be allocated + * @return 0 if OK, -ve on error + * + * Allocate space for a given smem item of size @size, given that the item is + * not yet allocated. + */ +int smem_alloc(struct udevice *dev, unsigned int host, + unsigned int item, size_t size); + +/** + * smem_get() - resolve ptr of size of a smem item + * @host: the remote processor, or -1 + * @item: smem item handle + * @size: pointer to be filled out with size of the item + * @return pointer on success, NULL on error + * + * Looks up smem item and returns pointer to it. Size of smem + * item is returned in @size. + */ +void *smem_get(struct udevice *dev, unsigned int host, + unsigned int item, size_t *size); + +/** + * smem_get_free_space() - retrieve amount of free space in a partition + * @host: the remote processor identifying a partition, or -1 + * @free_space: pointer to be filled out with free space + * @return 0 if OK, -ve on error + * + * To be used by smem clients as a quick way to determine if any new + * allocations has been made. + */ +int smem_get_free_space(struct udevice *dev, unsigned int host, size_t *free_space); + +#endif /* _smem_h_ */ + From patchwork Fri Jun 22 02:11:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 933161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nJWyAymw"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41BtGP17Stz9s3C for ; Fri, 22 Jun 2018 19:15:57 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id CD69CC22019; Fri, 22 Jun 2018 09:15:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=DATE_IN_PAST_06_12, FREEMAIL_FROM, KHOP_BIG_TO_CC, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id CCDFAC22003; Fri, 22 Jun 2018 09:12:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 82CE0C22050; Fri, 22 Jun 2018 09:12:11 +0000 (UTC) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by lists.denx.de (Postfix) with ESMTPS id CE64FC21F92 for ; Fri, 22 Jun 2018 09:11:56 +0000 (UTC) Received: by mail-wr0-f193.google.com with SMTP id l14-v6so873880wrq.13 for ; Fri, 22 Jun 2018 02:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pVUz0eKu+mOZUv9lLX+6xblFVHYcxJhRuJ3zfBCGe4U=; b=nJWyAymwu1uwnaj8DEHZiFtXn4CWSkaUv5EZLRKaci5Pfzzm+gHUa1O2GofoXoaHTs uQoEy05VArs4Su6cB5TMIHr8XlK4/Y6/BOcnj0c41HApiTO+uzcC5vtNhGBmx+4Ar2RU BwQ+VQt7axs0Jp5FIbvj0/eHN8g2/HDOZfaLX1Yr+8nJ1kXoljS1r70sXFV1/Xrnh5+P Z6FC6rgGHMXobz0ZlEr82WNH92uk0MF1L8VFxPkLJVe1D6t+TcOsNJFYYtztjsQtAK41 rpTfMIFYBqx51oqOY1yiqSTF3l/i52k6sb5/5ATtj8nHF4Yje4ClhEaU1dGY30UP/nqP kUmQ== 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=pVUz0eKu+mOZUv9lLX+6xblFVHYcxJhRuJ3zfBCGe4U=; b=i7XBK26hvosyeI6IkLnAnueJsDNlkyQdTI6kChK1RYBv8/O8YEd4hVxZMy/TH7RV/5 BE2AkVWjVMaA8ARdfRxGFtgQXusRUQl0CeI5D+bYNYv8SMaVrA9y7xvSSliwJmhpQ3kb LyOW+Vy8mvGeq4T90dWCWphtIP3YDlk1XK72CtELUlrdSOdk9bGlN6+OunRiTxtZY+/A dDCWQuzdnq+M9Gqn/CbxoDfNzAUhW26mGHO1ib1MewU/Zyd3Flq2vFbaFkNTsRt6mWiz NJNOSnsUNW0cJgoO3n72+Ihx1Bg+affJyYLHDOgyIsG+QQ3CtzSB9ROZCg9q6iAB7Z4p f+xg== X-Gm-Message-State: APt69E3+VjHMmNDmisWPq38x+9FqMbTC9iUQegWAK/IvqpSE5saSnqQW urJDqpCOdoXx4tSN+umLVWw= X-Google-Smtp-Source: AAOMgpfTwlCGHDbsO+3bgPWgB0fIAq8IBPZ02UuNm3sCZJHlDjbN/Zw/3JAE65KVbLsofA4hFh7g4g== X-Received: by 2002:adf:edc6:: with SMTP id v6-v6mr832789wro.264.1529658716116; Fri, 22 Jun 2018 02:11:56 -0700 (PDT) Received: from localhost.localdomain ([141.226.166.38]) by smtp.gmail.com with ESMTPSA id g16-v6sm6938310wro.86.2018.06.22.02.11.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 02:11:55 -0700 (PDT) From: Ramon Fried To: Simon Glass , u-boot@lists.denx.de, jramirez@baylibre.com, xypron.glpk@gmx.de Date: Fri, 22 Jun 2018 05:11:29 +0300 Message-Id: <20180622021133.24062-3-ramon.fried@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180622021133.24062-1-ramon.fried@gmail.com> References: <20180622021133.24062-1-ramon.fried@gmail.com> Cc: Martyn Welch , Ian Ray , Alexander Graf , Michal Simek , Andy Shevchenko , bjorn.andersson@linaro.org, Eugeniy Paltsev , Stefan Roese Subject: [U-Boot] [PATCH v2 2/6] soc: qualcomm: Add Shared Memory Manager driver X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors in a Qualcomm platform. Adapted from the Linux driver (4.17) Changes from the original Linux driver: * Removed HW spinlock mechanism, which is irrelevant in U-boot particualar use case, which is just reading from the smem. * adaptaion from Linux driver model to U-boot's. Cc: Bjorn Andersson Signed-off-by: Ramon Fried Reviewed-by: Simon Glass --- Changes in v2: - Applied checkpatch fixes (also sent these to Linux upstream) - Changed UCLASS_SOC to UCLASS_SMEM - Removed function exports and registered functionality through .ops MAINTAINERS | 1 + arch/arm/Kconfig | 2 + drivers/Kconfig | 2 + drivers/smem/Kconfig | 13 + drivers/smem/Makefile | 1 + drivers/smem/msm_smem.c | 941 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 960 insertions(+) create mode 100644 drivers/smem/msm_smem.c diff --git a/MAINTAINERS b/MAINTAINERS index b2c9717cb7..b691bae13c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -187,6 +187,7 @@ ARM SNAPDRAGON M: Ramon Fried S: Maintained F: arch/arm/mach-snapdragon/ +F: drivers/smem/msm_smem.c ARM STI M: Patrice Chotard diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 22234cde2a..badf4cacb8 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -728,6 +728,8 @@ config ARCH_SNAPDRAGON select SPMI select OF_CONTROL select OF_SEPARATE + select SMEM + select MSM_SMEM config ARCH_SOCFPGA bool "Altera SOCFPGA family" diff --git a/drivers/Kconfig b/drivers/Kconfig index 9e21b28750..c72abf8932 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -84,6 +84,8 @@ source "drivers/scsi/Kconfig" source "drivers/serial/Kconfig" +source "drivers/smem/Kconfig" + source "drivers/sound/Kconfig" source "drivers/spi/Kconfig" diff --git a/drivers/smem/Kconfig b/drivers/smem/Kconfig index 64337a8b8e..77ad02e236 100644 --- a/drivers/smem/Kconfig +++ b/drivers/smem/Kconfig @@ -1,2 +1,15 @@ menuconfig SMEM bool "SMEM (Shared Memory mamanger) support" + +if SMEM + +config MSM_SMEM + bool "Qualcomm Shared Memory Manager (SMEM)" + depends on DM + depends on ARCH_SNAPDRAGON + help + enable support for the Qualcomm Shared Memory Manager. + The driver provides an interface to items in a heap shared among all + processors in a Qualcomm platform. + +endif # menu "SMEM Support" diff --git a/drivers/smem/Makefile b/drivers/smem/Makefile index ca55c4512d..605b8fc290 100644 --- a/drivers/smem/Makefile +++ b/drivers/smem/Makefile @@ -3,3 +3,4 @@ # Makefile for the U-Boot SMEM interface drivers obj-$(CONFIG_SMEM) += smem-uclass.o +obj-$(CONFIG_MSM_SMEM) += msm_smem.o diff --git a/drivers/smem/msm_smem.c b/drivers/smem/msm_smem.c new file mode 100644 index 0000000000..183ab7b54b --- /dev/null +++ b/drivers/smem/msm_smem.c @@ -0,0 +1,941 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2015, Sony Mobile Communications AB. + * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. + * Copyright (c) 2018, Ramon Fried + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* + * The Qualcomm shared memory system is an allocate only heap structure that + * consists of one of more memory areas that can be accessed by the processors + * in the SoC. + * + * All systems contains a global heap, accessible by all processors in the SoC, + * with a table of contents data structure (@smem_header) at the beginning of + * the main shared memory block. + * + * The global header contains meta data for allocations as well as a fixed list + * of 512 entries (@smem_global_entry) that can be initialized to reference + * parts of the shared memory space. + * + * + * In addition to this global heap a set of "private" heaps can be set up at + * boot time with access restrictions so that only certain processor pairs can + * access the data. + * + * These partitions are referenced from an optional partition table + * (@smem_ptable), that is found 4kB from the end of the main smem region. The + * partition table entries (@smem_ptable_entry) lists the involved processors + * (or hosts) and their location in the main shared memory region. + * + * Each partition starts with a header (@smem_partition_header) that identifies + * the partition and holds properties for the two internal memory regions. The + * two regions are cached and non-cached memory respectively. Each region + * contain a link list of allocation headers (@smem_private_entry) followed by + * their data. + * + * 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. The header of + * cached items comes after the data. + * + * Version 12 (SMEM_GLOBAL_PART_VERSION) changes the item alloc/get procedure + * for the global heap. A new global partition is created from the global heap + * region with partition type (SMEM_GLOBAL_HOST) and the max smem item count is + * set by the bootloader. + * + */ + +/* + * The version member of the smem header contains an array of versions for the + * various software components in the SoC. We verify that the boot loader + * version is a valid version as a sanity check. + */ +#define SMEM_MASTER_SBL_VERSION_INDEX 7 +#define SMEM_GLOBAL_HEAP_VERSION 11 +#define SMEM_GLOBAL_PART_VERSION 12 + +/* + * The first 8 items are only to be allocated by the boot loader while + * initializing the heap. + */ +#define SMEM_ITEM_LAST_FIXED 8 + +/* Highest accepted item number, for both global and private heaps */ +#define SMEM_ITEM_COUNT 512 + +/* Processor/host identifier for the application processor */ +#define SMEM_HOST_APPS 0 + +/* Processor/host identifier for the global partition */ +#define SMEM_GLOBAL_HOST 0xfffe + +/* Max number of processors/hosts in a system */ +#define SMEM_HOST_COUNT 10 + +/** + * struct smem_proc_comm - proc_comm communication struct (legacy) + * @command: current command to be executed + * @status: status of the currently requested command + * @params: parameters to the command + */ +struct smem_proc_comm { + __le32 command; + __le32 status; + __le32 params[2]; +}; + +/** + * struct smem_global_entry - entry to reference smem items on the heap + * @allocated: boolean to indicate if this entry is used + * @offset: offset to the allocated space + * @size: size of the allocated space, 8 byte aligned + * @aux_base: base address for the memory region used by this unit, or 0 for + * the default region. bits 0,1 are reserved + */ +struct smem_global_entry { + __le32 allocated; + __le32 offset; + __le32 size; + __le32 aux_base; /* bits 1:0 reserved */ +}; +#define AUX_BASE_MASK 0xfffffffc + +/** + * struct smem_header - header found in beginning of primary smem region + * @proc_comm: proc_comm communication interface (legacy) + * @version: array of versions for the various subsystems + * @initialized: boolean to indicate that smem is initialized + * @free_offset: index of the first unallocated byte in smem + * @available: number of bytes available for allocation + * @reserved: reserved field, must be 0 + * toc: array of references to items + */ +struct smem_header { + struct smem_proc_comm proc_comm[4]; + __le32 version[32]; + __le32 initialized; + __le32 free_offset; + __le32 available; + __le32 reserved; + struct smem_global_entry toc[SMEM_ITEM_COUNT]; +}; + +/** + * struct smem_ptable_entry - one entry in the @smem_ptable list + * @offset: offset, within the main shared memory region, of the partition + * @size: size of the partition + * @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 { + __le32 offset; + __le32 size; + __le32 flags; + __le16 host0; + __le16 host1; + __le32 cacheline; + __le32 reserved[7]; +}; + +/** + * struct smem_ptable - partition table for the private partitions + * @magic: magic number, must be SMEM_PTABLE_MAGIC + * @version: version of the partition table + * @num_entries: number of partitions in the table + * @reserved: for now reserved entries + * @entry: list of @smem_ptable_entry for the @num_entries partitions + */ +struct smem_ptable { + u8 magic[4]; + __le32 version; + __le32 num_entries; + __le32 reserved[5]; + struct smem_ptable_entry entry[]; +}; + +static const u8 SMEM_PTABLE_MAGIC[] = { 0x24, 0x54, 0x4f, 0x43 }; /* "$TOC" */ + +/** + * struct smem_partition_header - header of the partitions + * @magic: magic number, must be SMEM_PART_MAGIC + * @host0: first processor/host with access to this partition + * @host1: second processor/host with access to this partition + * @size: size of the partition + * @offset_free_uncached: offset to the first free byte of uncached memory in + * this partition + * @offset_free_cached: offset to the first free byte of cached memory in this + * partition + * @reserved: for now reserved entries + */ +struct smem_partition_header { + u8 magic[4]; + __le16 host0; + __le16 host1; + __le32 size; + __le32 offset_free_uncached; + __le32 offset_free_cached; + __le32 reserved[3]; +}; + +static const u8 SMEM_PART_MAGIC[] = { 0x24, 0x50, 0x52, 0x54 }; + +/** + * struct smem_private_entry - header of each item in the private partition + * @canary: magic number, must be SMEM_PRIVATE_CANARY + * @item: identifying number of the smem item + * @size: size of the data, including padding bytes + * @padding_data: number of bytes of padding of data + * @padding_hdr: number of bytes of padding between the header and the data + * @reserved: for now reserved entry + */ +struct smem_private_entry { + u16 canary; /* bytes are the same so no swapping needed */ + __le16 item; + __le32 size; /* includes padding bytes */ + __le16 padding_data; + __le16 padding_hdr; + __le32 reserved; +}; +#define SMEM_PRIVATE_CANARY 0xa5a5 + +/** + * struct smem_info - smem region info located after the table of contents + * @magic: magic number, must be SMEM_INFO_MAGIC + * @size: size of the smem region + * @base_addr: base address of the smem region + * @reserved: for now reserved entry + * @num_items: highest accepted item number + */ +struct smem_info { + u8 magic[4]; + __le32 size; + __le32 base_addr; + __le32 reserved; + __le16 num_items; +}; + +static const u8 SMEM_INFO_MAGIC[] = { 0x53, 0x49, 0x49, 0x49 }; /* SIII */ + +/** + * struct smem_region - representation of a chunk of memory used for smem + * @aux_base: identifier of aux_mem base + * @virt_base: virtual base address of memory with this aux_mem identifier + * @size: size of the memory region + */ +struct smem_region { + u32 aux_base; + void __iomem *virt_base; + size_t size; +}; + +/** + * struct qcom_smem - device data for the smem device + * @dev: device pointer + * @global_partition: pointer to global partition when in use + * @global_cacheline: cacheline size for global partition + * @partitions: list of pointers to partitions affecting the current + * processor/host + * @cacheline: list of cacheline sizes for each host + * @item_count: max accepted item number + * @num_regions: number of @regions + * @regions: list of the memory regions defining the shared memory + */ +struct qcom_smem { + struct udevice *dev; + + struct smem_partition_header *global_partition; + size_t global_cacheline; + struct smem_partition_header *partitions[SMEM_HOST_COUNT]; + size_t cacheline[SMEM_HOST_COUNT]; + u32 item_count; + + unsigned int num_regions; + struct smem_region regions[0]; +}; + +static struct smem_private_entry * +phdr_to_last_uncached_entry(struct smem_partition_header *phdr) +{ + void *p = 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; + + return p + le32_to_cpu(phdr->offset_free_cached); +} + +static struct smem_private_entry * +phdr_to_first_uncached_entry(struct smem_partition_header *phdr) +{ + void *p = phdr; + + return p + sizeof(*phdr); +} + +static struct smem_private_entry * +uncached_entry_next(struct smem_private_entry *e) +{ + void *p = e; + + return p + sizeof(*e) + le16_to_cpu(e->padding_hdr) + + 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; + + 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; + +static int qcom_smem_alloc_private(struct qcom_smem *smem, + struct smem_partition_header *phdr, + unsigned int item, + size_t size) +{ + struct smem_private_entry *hdr, *end; + size_t alloc_size; + void *cached; + + hdr = phdr_to_first_uncached_entry(phdr); + end = phdr_to_last_uncached_entry(phdr); + cached = phdr_to_last_cached_entry(phdr); + + while (hdr < end) { + if (hdr->canary != SMEM_PRIVATE_CANARY) { + dev_err(smem->dev, + "Found invalid canary in hosts %d:%d partition\n", + phdr->host0, phdr->host1); + return -EINVAL; + } + + if (le16_to_cpu(hdr->item) == item) + return -EEXIST; + + hdr = uncached_entry_next(hdr); + } + + /* Check that we don't grow into the cached region */ + alloc_size = sizeof(*hdr) + ALIGN(size, 8); + if ((void *)hdr + alloc_size >= cached) { + dev_err(smem->dev, "Out of memory\n"); + return -ENOSPC; + } + + hdr->canary = SMEM_PRIVATE_CANARY; + hdr->item = cpu_to_le16(item); + hdr->size = cpu_to_le32(ALIGN(size, 8)); + hdr->padding_data = cpu_to_le16(le32_to_cpu(hdr->size) - size); + hdr->padding_hdr = 0; + + /* + * Ensure the header is written before we advance the free offset, so + * that remote processors that does not take the remote spinlock still + * gets a consistent view of the linked list. + */ + dmb(); + le32_add_cpu(&phdr->offset_free_uncached, alloc_size); + + return 0; +} + +static int qcom_smem_alloc_global(struct qcom_smem *smem, + unsigned int item, + size_t size) +{ + struct smem_global_entry *entry; + struct smem_header *header; + + header = smem->regions[0].virt_base; + entry = &header->toc[item]; + if (entry->allocated) + return -EEXIST; + + size = ALIGN(size, 8); + if (WARN_ON(size > le32_to_cpu(header->available))) + return -ENOMEM; + + entry->offset = header->free_offset; + entry->size = cpu_to_le32(size); + + /* + * Ensure the header is consistent before we mark the item allocated, + * so that remote processors will get a consistent view of the item + * even though they do not take the spinlock on read. + */ + dmb(); + entry->allocated = cpu_to_le32(1); + + le32_add_cpu(&header->free_offset, size); + le32_add_cpu(&header->available, -size); + + return 0; +} + +/** + * qcom_smem_alloc() - allocate space for a smem item + * @host: remote processor id, or -1 + * @item: smem item handle + * @size: number of bytes to be allocated + * + * Allocate space for a given smem item of size @size, given that the item is + * not yet allocated. + */ +static int qcom_smem_alloc(unsigned int host, unsigned int item, size_t size) +{ + struct smem_partition_header *phdr; + int ret; + + if (!__smem) + return -EPROBE_DEFER; + + if (item < SMEM_ITEM_LAST_FIXED) { + dev_err(__smem->dev, + "Rejecting allocation of static entry %d\n", item); + return -EINVAL; + } + + if (WARN_ON(item >= __smem->item_count)) + return -EINVAL; + + if (host < SMEM_HOST_COUNT && __smem->partitions[host]) { + phdr = __smem->partitions[host]; + ret = qcom_smem_alloc_private(__smem, phdr, item, size); + } else if (__smem->global_partition) { + phdr = __smem->global_partition; + ret = qcom_smem_alloc_private(__smem, phdr, item, size); + } else { + ret = qcom_smem_alloc_global(__smem, item, size); + } + + return ret; +} + +static void *qcom_smem_get_global(struct qcom_smem *smem, + unsigned int item, + size_t *size) +{ + struct smem_header *header; + struct smem_region *area; + struct smem_global_entry *entry; + u32 aux_base; + unsigned int i; + + header = smem->regions[0].virt_base; + entry = &header->toc[item]; + if (!entry->allocated) + return ERR_PTR(-ENXIO); + + aux_base = le32_to_cpu(entry->aux_base) & AUX_BASE_MASK; + + for (i = 0; i < smem->num_regions; i++) { + area = &smem->regions[i]; + + if (area->aux_base == aux_base || !aux_base) { + if (size != NULL) + *size = le32_to_cpu(entry->size); + return area->virt_base + le32_to_cpu(entry->offset); + } + } + + return ERR_PTR(-ENOENT); +} + +static void *qcom_smem_get_private(struct qcom_smem *smem, + struct smem_partition_header *phdr, + size_t cacheline, + unsigned int item, + size_t *size) +{ + struct smem_private_entry *e, *end; + + e = phdr_to_first_uncached_entry(phdr); + end = phdr_to_last_uncached_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 uncached_entry_to_item(e); + } + + 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 hosts %d:%d partition\n", + phdr->host0, phdr->host1); + + return ERR_PTR(-EINVAL); +} + +/** + * qcom_smem_get() - resolve ptr of size of a smem item + * @host: the remote processor, or -1 + * @item: smem item handle + * @size: pointer to be filled out with size of the item + * + * Looks up smem item and returns pointer to it. Size of smem + * item is returned in @size. + */ +static void *qcom_smem_get(unsigned int host, unsigned int item, size_t *size) +{ + struct smem_partition_header *phdr; + size_t cacheln; + void *ptr = ERR_PTR(-EPROBE_DEFER); + + if (!__smem) + return ptr; + + if (WARN_ON(item >= __smem->item_count)) + return ERR_PTR(-EINVAL); + + if (host < SMEM_HOST_COUNT && __smem->partitions[host]) { + phdr = __smem->partitions[host]; + cacheln = __smem->cacheline[host]; + ptr = qcom_smem_get_private(__smem, phdr, cacheln, item, size); + } else if (__smem->global_partition) { + phdr = __smem->global_partition; + cacheln = __smem->global_cacheline; + ptr = qcom_smem_get_private(__smem, phdr, cacheln, item, size); + } else { + ptr = qcom_smem_get_global(__smem, item, size); + } + + return ptr; + +} + +/** + * qcom_smem_get_free_space() - retrieve amount of free space in a partition + * @host: the remote processor identifying a partition, or -1 + * + * To be used by smem clients as a quick way to determine if any new + * allocations has been made. + */ +static int qcom_smem_get_free_space(unsigned int host) +{ + struct smem_partition_header *phdr; + struct smem_header *header; + unsigned int ret; + + if (!__smem) + return -EPROBE_DEFER; + + if (host < SMEM_HOST_COUNT && __smem->partitions[host]) { + phdr = __smem->partitions[host]; + ret = le32_to_cpu(phdr->offset_free_cached) - + le32_to_cpu(phdr->offset_free_uncached); + } else if (__smem->global_partition) { + phdr = __smem->global_partition; + ret = le32_to_cpu(phdr->offset_free_cached) - + le32_to_cpu(phdr->offset_free_uncached); + } else { + header = __smem->regions[0].virt_base; + ret = le32_to_cpu(header->available); + } + + return ret; +} + +static int qcom_smem_get_sbl_version(struct qcom_smem *smem) +{ + struct smem_header *header; + __le32 *versions; + + header = smem->regions[0].virt_base; + versions = header->version; + + return le32_to_cpu(versions[SMEM_MASTER_SBL_VERSION_INDEX]); +} + +static struct smem_ptable *qcom_smem_get_ptable(struct qcom_smem *smem) +{ + struct smem_ptable *ptable; + u32 version; + + ptable = smem->regions[0].virt_base + smem->regions[0].size - SZ_4K; + if (memcmp(ptable->magic, SMEM_PTABLE_MAGIC, sizeof(ptable->magic))) + return ERR_PTR(-ENOENT); + + version = le32_to_cpu(ptable->version); + if (version != 1) { + dev_err(smem->dev, + "Unsupported partition header version %d\n", version); + return ERR_PTR(-EINVAL); + } + return ptable; +} + +static u32 qcom_smem_get_item_count(struct qcom_smem *smem) +{ + struct smem_ptable *ptable; + struct smem_info *info; + + ptable = qcom_smem_get_ptable(smem); + if (IS_ERR_OR_NULL(ptable)) + return SMEM_ITEM_COUNT; + + info = (struct smem_info *)&ptable->entry[ptable->num_entries]; + if (memcmp(info->magic, SMEM_INFO_MAGIC, sizeof(info->magic))) + return SMEM_ITEM_COUNT; + + return le16_to_cpu(info->num_items); +} + +static int qcom_smem_set_global_partition(struct qcom_smem *smem) +{ + struct smem_partition_header *header; + struct smem_ptable_entry *entry = NULL; + struct smem_ptable *ptable; + u32 host0, host1, size; + int i; + + ptable = qcom_smem_get_ptable(smem); + if (IS_ERR(ptable)) + return PTR_ERR(ptable); + + for (i = 0; i < le32_to_cpu(ptable->num_entries); i++) { + entry = &ptable->entry[i]; + host0 = le16_to_cpu(entry->host0); + host1 = le16_to_cpu(entry->host1); + + if (host0 == SMEM_GLOBAL_HOST && host0 == host1) + break; + } + + if (!entry) { + dev_err(smem->dev, "Missing entry for global partition\n"); + return -EINVAL; + } + + if (!le32_to_cpu(entry->offset) || !le32_to_cpu(entry->size)) { + dev_err(smem->dev, "Invalid entry for global partition\n"); + return -EINVAL; + } + + if (smem->global_partition) { + dev_err(smem->dev, "Already found the global partition\n"); + return -EINVAL; + } + + header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); + host0 = le16_to_cpu(header->host0); + host1 = le16_to_cpu(header->host1); + + if (memcmp(header->magic, SMEM_PART_MAGIC, sizeof(header->magic))) { + dev_err(smem->dev, "Global partition has invalid magic\n"); + return -EINVAL; + } + + if (host0 != SMEM_GLOBAL_HOST && host1 != SMEM_GLOBAL_HOST) { + dev_err(smem->dev, "Global partition hosts are invalid\n"); + return -EINVAL; + } + + if (le32_to_cpu(header->size) != le32_to_cpu(entry->size)) { + dev_err(smem->dev, "Global partition has invalid size\n"); + return -EINVAL; + } + + size = le32_to_cpu(header->offset_free_uncached); + if (size > le32_to_cpu(header->size)) { + dev_err(smem->dev, + "Global partition has invalid free pointer\n"); + return -EINVAL; + } + + smem->global_partition = header; + smem->global_cacheline = le32_to_cpu(entry->cacheline); + + return 0; +} + +static int qcom_smem_enumerate_partitions(struct qcom_smem *smem, + unsigned int local_host) +{ + struct smem_partition_header *header; + struct smem_ptable_entry *entry; + struct smem_ptable *ptable; + unsigned int remote_host; + u32 host0, host1; + int i; + + ptable = qcom_smem_get_ptable(smem); + if (IS_ERR(ptable)) + return PTR_ERR(ptable); + + for (i = 0; i < le32_to_cpu(ptable->num_entries); i++) { + entry = &ptable->entry[i]; + host0 = le16_to_cpu(entry->host0); + host1 = le16_to_cpu(entry->host1); + + if (host0 != local_host && host1 != local_host) + continue; + + if (!le32_to_cpu(entry->offset)) + continue; + + if (!le32_to_cpu(entry->size)) + continue; + + if (host0 == local_host) + remote_host = host1; + else + remote_host = host0; + + if (remote_host >= SMEM_HOST_COUNT) { + dev_err(smem->dev, + "Invalid remote host %d\n", + remote_host); + return -EINVAL; + } + + if (smem->partitions[remote_host]) { + dev_err(smem->dev, + "Already found a partition for host %d\n", + remote_host); + return -EINVAL; + } + + header = smem->regions[0].virt_base + le32_to_cpu(entry->offset); + host0 = le16_to_cpu(header->host0); + host1 = le16_to_cpu(header->host1); + + if (memcmp(header->magic, SMEM_PART_MAGIC, + sizeof(header->magic))) { + dev_err(smem->dev, + "Partition %d has invalid magic\n", i); + return -EINVAL; + } + + if (host0 != local_host && host1 != local_host) { + dev_err(smem->dev, + "Partition %d hosts are invalid\n", i); + return -EINVAL; + } + + if (host0 != remote_host && host1 != remote_host) { + dev_err(smem->dev, + "Partition %d hosts are invalid\n", i); + return -EINVAL; + } + + if (le32_to_cpu(header->size) != le32_to_cpu(entry->size)) { + dev_err(smem->dev, + "Partition %d has invalid size\n", i); + return -EINVAL; + } + + if (le32_to_cpu(header->offset_free_uncached) > le32_to_cpu(header->size)) { + dev_err(smem->dev, + "Partition %d has invalid free pointer\n", i); + return -EINVAL; + } + + smem->partitions[remote_host] = header; + smem->cacheline[remote_host] = le32_to_cpu(entry->cacheline); + } + + return 0; +} + +static int qcom_smem_map_memory(struct qcom_smem *smem, struct udevice *dev, + const char *name, int i) +{ + struct fdt_resource r; + int ret; + int node = dev_of_offset(dev); + + ret = fdtdec_lookup_phandle(gd->fdt_blob, node, name); + if (ret < 0) { + dev_err(dev, "No %s specified\n", name); + return -EINVAL; + } + + ret = fdt_get_resource(gd->fdt_blob, ret, "reg", 0, &r); + if (ret) + return ret; + + smem->regions[i].aux_base = (u32)r.start; + smem->regions[i].size = fdt_resource_size(&r); + smem->regions[i].virt_base = devm_ioremap(dev, r.start, fdt_resource_size(&r)); + if (!smem->regions[i].virt_base) + return -ENOMEM; + + return 0; +} + +static int qcom_smem_probe(struct udevice *dev) +{ + struct smem_header *header; + struct qcom_smem *smem; + size_t array_size; + int num_regions; + u32 version; + int ret; + int node = dev_of_offset(dev); + + num_regions = 1; + if (fdtdec_lookup_phandle(gd->fdt_blob, node, "qcomrpm-msg-ram") >= 0) + num_regions++; + + array_size = num_regions * sizeof(struct smem_region); + smem = devm_kzalloc(dev, sizeof(*smem) + array_size, GFP_KERNEL); + if (!smem) + return -ENOMEM; + + smem->dev = dev; + smem->num_regions = num_regions; + + ret = qcom_smem_map_memory(smem, dev, "memory-region", 0); + if (ret) + return ret; + + if (num_regions > 1) { + ret = qcom_smem_map_memory(smem, dev, + "qcom,rpm-msg-ram", 1); + if (ret) + return ret; + } + + header = smem->regions[0].virt_base; + if (le32_to_cpu(header->initialized) != 1 || + le32_to_cpu(header->reserved)) { + dev_err(&pdev->dev, "SMEM is not initialized by SBL\n"); + return -EINVAL; + } + + version = qcom_smem_get_sbl_version(smem); + switch (version >> 16) { + case SMEM_GLOBAL_PART_VERSION: + ret = qcom_smem_set_global_partition(smem); + if (ret < 0) + return ret; + smem->item_count = qcom_smem_get_item_count(smem); + break; + case SMEM_GLOBAL_HEAP_VERSION: + smem->item_count = SMEM_ITEM_COUNT; + break; + default: + dev_err(dev, "Unsupported SMEM version 0x%x\n", version); + return -EINVAL; + } + + ret = qcom_smem_enumerate_partitions(smem, SMEM_HOST_APPS); + if (ret < 0 && ret != -ENOENT) + return ret; + + __smem = smem; + + return 0; +} + +static int qcom_smem_remove(struct udevice *dev) +{ + __smem = NULL; + + return 0; +} + +const struct udevice_id qcom_smem_of_match[] = { + { .compatible = "qcom,smem" }, + { } +}; + +static const struct smem_ops msm_smem_ops = { + .alloc = qcom_smem_alloc, + .get = qcom_smem_get, + .get_free_space = qcom_smem_get_free_space, +}; + +U_BOOT_DRIVER(qcom_smem) = { + .name = "qcom_smem", + .id = UCLASS_SMEM, + .of_match = qcom_smem_of_match, + .ops = &msm_smem_ops, + .probe = qcom_smem_probe, + .remove = qcom_smem_remove, +}; From patchwork Fri Jun 22 02:11:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 933160 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EiM7r1/b"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41BtFY1JV4z9s3C for ; Fri, 22 Jun 2018 19:15:13 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D3698C2203F; Fri, 22 Jun 2018 09:15:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=DATE_IN_PAST_06_12, FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 1CCDEC21F8E; Fri, 22 Jun 2018 09:12:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0E7CAC22050; Fri, 22 Jun 2018 09:12:11 +0000 (UTC) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by lists.denx.de (Postfix) with ESMTPS id 1E179C21FC1 for ; Fri, 22 Jun 2018 09:12:01 +0000 (UTC) Received: by mail-wr0-f195.google.com with SMTP id h10-v6so5928518wrq.8 for ; Fri, 22 Jun 2018 02:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HUBkyUUELObxUa+Ob5vwq0OOya5AybbtIbVJ9WrCfO4=; b=EiM7r1/bbTWJ5FC3SMz/TyUmPASz+a40Poj91U5+ZYFcFsfduwW/ATMyc7h7GqwpQe pIHF6TnqEr92N761Y5/lfLapV5ULeZfTprfHP8WxgMTtF+Dsi4bIoplzOJTEPLhupxFO qJg8FhE8D5kuKvh2HdOYsxLSCiawN4rmh5mHYyt09Xbd1gWOE3iflTNJQKvsSxwdkg4o V7+rBPaBef12yhc+YqFJo0T5TTgpdULL6KUK7UK5bKHxfsY8fif6aWqq0IPo3A26xKHx Qs/Tkc9b3OTE6lFwTCSB6EVJBc10NmEifMGiEH8PgsnVUp/Xny29wsBZjPhbCieiugyi iJnw== 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=HUBkyUUELObxUa+Ob5vwq0OOya5AybbtIbVJ9WrCfO4=; b=jFOxwylwpPt/46tWXDKgdh5cwPWud/UpW6A/R6ZWb0In3TSKZ0MCa/lSg7yclRlxyP eRsci4mC2KVQNpaIg1MVd3Dj1/NU2t9+m0HyeVioW1LqRP2dTn+mTfGZg5EV6FB3UDer 5VRwd2kR2jW9IluQFloassLpS/svzJaEoUflokmKIZJOQ9vvAVNwmzKL3a4iV5Ou1qTA 8wUcar2+NXPRrVNLr07VYar1LkXP51L7OFejg9MDSUXUxt3kVBTVZAxyYGpscW1bmf+G 2i1+uhCd93Ap7azANMU2TP3oWy8KH0lYlNOqj4qWd5Oheyoa9EW+od4jDzoVa0A1FXu1 n5Bg== X-Gm-Message-State: APt69E1wbJOoAABYNli48uOuWRtuCL9zEajoGssjtzMBV3+ks2YtD4WE Y/kJg5mLFOsayTDAFPsXuSA= X-Google-Smtp-Source: AAOMgpfY8JylNJymkIhVJ9K3inj5kh5pKtWg0D40TufFJYlpmbDb0TZziudOGXXdjYCSt3c8HFoQJw== X-Received: by 2002:a5d:4a92:: with SMTP id o18-v6mr801809wrq.132.1529658720774; Fri, 22 Jun 2018 02:12:00 -0700 (PDT) Received: from localhost.localdomain ([141.226.166.38]) by smtp.gmail.com with ESMTPSA id g16-v6sm6938310wro.86.2018.06.22.02.11.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 02:12:00 -0700 (PDT) From: Ramon Fried To: Simon Glass , u-boot@lists.denx.de, jramirez@baylibre.com, xypron.glpk@gmx.de Date: Fri, 22 Jun 2018 05:11:30 +0300 Message-Id: <20180622021133.24062-4-ramon.fried@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180622021133.24062-1-ramon.fried@gmail.com> References: <20180622021133.24062-1-ramon.fried@gmail.com> Cc: bjorn.andersson@linaro.org Subject: [U-Boot] [PATCH v2 3/6] dts: db410c: added smem nodes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Added necessary nodes for Qualcomm smem driver. Signed-off-by: Ramon Fried Reviewed-by: Simon Glass --- Changes in v2: None arch/arm/dts/dragonboard410c-uboot.dtsi | 5 +++++ arch/arm/dts/dragonboard410c.dts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/arm/dts/dragonboard410c-uboot.dtsi b/arch/arm/dts/dragonboard410c-uboot.dtsi index 50ac2e6584..773439ab93 100644 --- a/arch/arm/dts/dragonboard410c-uboot.dtsi +++ b/arch/arm/dts/dragonboard410c-uboot.dtsi @@ -6,6 +6,11 @@ */ / { + + smem { + u-boot,dm-pre-reloc; + }; + soc { u-boot,dm-pre-reloc; diff --git a/arch/arm/dts/dragonboard410c.dts b/arch/arm/dts/dragonboard410c.dts index 182a865b0a..f4f7c350ec 100644 --- a/arch/arm/dts/dragonboard410c.dts +++ b/arch/arm/dts/dragonboard410c.dts @@ -27,18 +27,34 @@ #address-cells = <2>; #size-cells = <2>; ranges; + + smem_mem: smem_region@86300000 { + reg = <0x0 0x86300000 0x0 0x100000>; + no-map; + }; }; chosen { stdout-path = "/soc/serial@78b0000"; }; + smem { + compatible = "qcom,smem"; + memory-region = <&smem_mem>; + qcom,rpm-msg-ram = <&rpm_msg_ram>; + }; + soc { #address-cells = <0x1>; #size-cells = <0x1>; ranges = <0x0 0x0 0x0 0xffffffff>; compatible = "simple-bus"; + rpm_msg_ram: memory@60000 { + compatible = "qcom,rpm-msg-ram"; + reg = <0x60000 0x8000>; + }; + pinctrl: qcom,tlmm@1000000 { compatible = "qcom,tlmm-apq8016"; reg = <0x1000000 0x400000>; From patchwork Fri Jun 22 02:11:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 933162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GTkXUTA8"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41BtH83TVlz9s3C for ; Fri, 22 Jun 2018 19:16:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 9CBABC21F6E; Fri, 22 Jun 2018 09:16:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=DATE_IN_PAST_06_12, FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id DB3B6C2200D; Fri, 22 Jun 2018 09:12:25 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 35602C22011; Fri, 22 Jun 2018 09:12:21 +0000 (UTC) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by lists.denx.de (Postfix) with ESMTPS id AA69DC21C57 for ; Fri, 22 Jun 2018 09:12:05 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id e16-v6so1492499wmd.0 for ; Fri, 22 Jun 2018 02:12:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dsfSCw9mnzYdUg3561mNWS3j9WdQSPydIqTImiwyb08=; b=GTkXUTA8nU55nGQlXnmiLGrD0RG5YMjcERt11uFy3GE41sU/mrKm3dGsNFGUjJU5Cx J+pAKMFmemml9Qt1OVrkVQINHCTIIqS5crYn4teH7YjpQNW5geHWMroMfws9hF2H0ihy nlHosoQ+yTKmWrjD3mBx3TrWQQjfvbbU/8MDSvXyubdtqvTk6gSgqhdzGMWyLhN/Zb7W hf/A1M2dQlBNUvZ2uA3eedChMZx9Z7QitCn+jTNgAZyKmNuro2SYS39SecPzE5Hr0VQs DuuGml1PV1bQLPKJ9CqNskzF+BtTL+YM0EATUAPMT6dKsfJt9EAeDA8eW6hRaQlPh8y+ GzvQ== 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=dsfSCw9mnzYdUg3561mNWS3j9WdQSPydIqTImiwyb08=; b=HhN8aXGTJdN/lB/5S1IJy+ERMddJaPchvX4HwwFFC8TqPvx9q+g+p1TwxEx70GzI9w 1KM5+No5DVo1zFwvxVN7AGuvLCE+DXM/XhieNay4X5sgIWX4pRZawkyzHWtq/GcHTPNJ ClN1NyggpGoSeDM7RDm5VkRen16MpuyXVQUweZqGN+VmPst30hpRRtOPPLFlvZBQE8pr /2JP/v1Bnwo5F5G0f8poVHJ9YP1Vo0uUjfD4qxj52bguLPAfUTONO4Bz6dnNKyqPCI3p Ih/xCcwPmgufZaTKa+dNo2TVfq2FZc6Fg3MQCVogqftmZ6NhhTcvw5aHSLqkrstnBe84 WY+Q== X-Gm-Message-State: APt69E3zBkg8gic8D8Vm3xFrkqz6eAuhfgb9l1p0ToxaS6uszwKjGJtE GVzkvA7TjZjzj0lYUdPibtI= X-Google-Smtp-Source: ADUXVKJnoVU0s7eB8EC1VqRgEPkIRQEb4cxt5qez4Qhb8hhmZ5G3kBO5BJAjIef+2bpcSetYoMZnSg== X-Received: by 2002:a1c:7a06:: with SMTP id v6-v6mr1038409wmc.90.1529658725366; Fri, 22 Jun 2018 02:12:05 -0700 (PDT) Received: from localhost.localdomain ([141.226.166.38]) by smtp.gmail.com with ESMTPSA id g16-v6sm6938310wro.86.2018.06.22.02.12.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 02:12:04 -0700 (PDT) From: Ramon Fried To: Simon Glass , u-boot@lists.denx.de, jramirez@baylibre.com, xypron.glpk@gmx.de Date: Fri, 22 Jun 2018 05:11:31 +0300 Message-Id: <20180622021133.24062-5-ramon.fried@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180622021133.24062-1-ramon.fried@gmail.com> References: <20180622021133.24062-1-ramon.fried@gmail.com> Cc: bjorn.andersson@linaro.org Subject: [U-Boot] [PATCH v2 4/6] dts: db820c: added smem nodes X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Added necessary nodes for Qualcomm smem driver. Signed-off-by: Ramon Fried Reviewed-by: Simon Glass --- Changes in v2: None arch/arm/dts/dragonboard820c-uboot.dtsi | 4 ++++ arch/arm/dts/dragonboard820c.dts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/arch/arm/dts/dragonboard820c-uboot.dtsi b/arch/arm/dts/dragonboard820c-uboot.dtsi index 97394cc5b0..d60aa04494 100644 --- a/arch/arm/dts/dragonboard820c-uboot.dtsi +++ b/arch/arm/dts/dragonboard820c-uboot.dtsi @@ -6,6 +6,10 @@ */ / { + smem { + u-boot,dm-pre-reloc; + }; + soc { u-boot,dm-pre-reloc; diff --git a/arch/arm/dts/dragonboard820c.dts b/arch/arm/dts/dragonboard820c.dts index 7457d7b7e3..ffad8e0e0a 100644 --- a/arch/arm/dts/dragonboard820c.dts +++ b/arch/arm/dts/dragonboard820c.dts @@ -28,11 +28,27 @@ reg = <0 0x80000000 0 0xc0000000>; }; + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + smem_mem: smem_region@86300000 { + reg = <0x0 0x86300000 0x0 0x200000>; + no-map; + }; + }; + psci { compatible = "arm,psci-1.0"; method = "smc"; }; + smem { + compatible = "qcom,smem"; + memory-region = <&smem_mem>; + }; + soc: soc { #address-cells = <1>; #size-cells = <1>; From patchwork Fri Jun 22 02:11:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 933165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="W27As0Te"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41BtJH5qf9z9s3C for ; Fri, 22 Jun 2018 19:17:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 84223C2201E; Fri, 22 Jun 2018 09:17:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=DATE_IN_PAST_06_12, FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id CD8D2C22083; Fri, 22 Jun 2018 09:12:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1FA80C22072; Fri, 22 Jun 2018 09:12:22 +0000 (UTC) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by lists.denx.de (Postfix) with ESMTPS id 21EB9C2203F for ; Fri, 22 Jun 2018 09:12:11 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id p126-v6so1484813wmb.2 for ; Fri, 22 Jun 2018 02:12:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7ZCE1S8fGp2vUfTJO6QKX2Q13sDLIuhguCyIdIkKwDE=; b=W27As0Te3m3zxO9Ou2WXKuK+AxtrwKkBaVFVIGKxvHjauWfEQTnUvNi5XK3PGL2oK5 VAeVYPUEn8JCLjtfytCgLAzcNegpxGRW/D8KbPDdyjmXtgev/hMu7/UWnTnq56CAkhaP MtXhiO4GHBa9oP5cvSlkTGBEPEhSaS4r06Zom86J5pZ77GLEUnD36MAsdWCzxPNQJr+o 8JtSzueV+15zZzydvoXeqKdS8m4KmRPzqE1pSqWhFjharmqNCAQGfRmwjzBFstx/FxtR 5n2bBbisXQrdzJ6BdJ5Hm6Aa63uf9LyAGOcy/0SUgxX90XLZuD52x1uQsFYgKyrWqHgl OcUw== 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=7ZCE1S8fGp2vUfTJO6QKX2Q13sDLIuhguCyIdIkKwDE=; b=hn5lUabX6IuMNr9YSbV8GGlo4Us6KgJnVBJPQ6vbKt0C7PguDN8UCM8jRrK5ZhdLyV 5rZoyt1OSs7jjBkmgLA82zr+g4wdH1KTwHw4nAf+mgbaDJ1e/oW1YyDrh8BjGOV0llf8 IquazD1u5siUvv/raCo4l3VxjN3fGEJQ0GQ2sRPx1/JCrSLZegXfhME5Xe89bKa4Fpvn SdxYde6DkGvxKi1mEXJJJLT4mSoCQwj6Ab6W11UPyVHcBI2cpVKn2vkNcIvMHMCpxCiN QoF7sLpL+1B5m/fIkv2BxeeXmNeQfIeuyztHXfbArIGmRNHgRsYUbgHloaAnmnW2YcwX 2QJA== X-Gm-Message-State: APt69E1JR112AZVZd8e4cN0DaySIrOoqCJ+hyPX/RXQh+728DOVNj7QR LNuj5FJE2Ayw+a2+Q5rNdpU= X-Google-Smtp-Source: ADUXVKL/Oh2flt68NmKzNYrU45J9ox+T+qv36VZ/m5kEOSQaeSMYfXtw0VAIOC3XLHKmWe53IvWDGg== X-Received: by 2002:a1c:a006:: with SMTP id j6-v6mr1076352wme.61.1529658730781; Fri, 22 Jun 2018 02:12:10 -0700 (PDT) Received: from localhost.localdomain ([141.226.166.38]) by smtp.gmail.com with ESMTPSA id g16-v6sm6938310wro.86.2018.06.22.02.12.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 02:12:10 -0700 (PDT) From: Ramon Fried To: Simon Glass , u-boot@lists.denx.de, jramirez@baylibre.com, xypron.glpk@gmx.de Date: Fri, 22 Jun 2018 05:11:32 +0300 Message-Id: <20180622021133.24062-6-ramon.fried@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180622021133.24062-1-ramon.fried@gmail.com> References: <20180622021133.24062-1-ramon.fried@gmail.com> Cc: Martin Fuzzey , Patrick Bruenn , Eugeniu Rosca , bjorn.andersson@linaro.org Subject: [U-Boot] [PATCH v2 5/6] drivers: smem: sandbox X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add Sandbox driver for SMEM. mostly stub operations. Signed-off-by: Ramon Fried Reviewed-by: Simon Glass --- Changes in v2: None arch/sandbox/dts/test.dts | 4 ++++ configs/sandbox64_defconfig | 2 ++ configs/sandbox_defconfig | 2 ++ drivers/smem/Kconfig | 9 ++++++++ drivers/smem/Makefile | 1 + drivers/smem/sandbox_smem.c | 45 +++++++++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+) create mode 100644 drivers/smem/sandbox_smem.c diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 5752bf547e..01e6bc0367 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -382,6 +382,10 @@ remoteproc-name = "remoteproc-test-dev2"; }; + smem@0 { + compatible = "sandbox,smem"; + }; + spi@0 { #address-cells = <1>; #size-cells = <0>; diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index 20a2ab3ffb..1fa85a819c 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -199,3 +199,5 @@ CONFIG_UT_TIME=y CONFIG_UT_DM=y CONFIG_UT_ENV=y CONFIG_UT_OVERLAY=y +CONFIG_SMEM=y +CONFIG_SANDBOX_SMEM=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 2fc84a16c9..47f6bfd87f 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -200,3 +200,5 @@ CONFIG_UT_TIME=y CONFIG_UT_DM=y CONFIG_UT_ENV=y CONFIG_UT_OVERLAY=y +CONFIG_SMEM=y +CONFIG_SANDBOX_SMEM=y diff --git a/drivers/smem/Kconfig b/drivers/smem/Kconfig index 77ad02e236..3aa32a6c13 100644 --- a/drivers/smem/Kconfig +++ b/drivers/smem/Kconfig @@ -3,6 +3,15 @@ menuconfig SMEM if SMEM +config SANDBOX_SMEM + bool "Sandbox Shared Memory Manager (SMEM)" + depends on SANDBOX && DM + help + enable SMEM support for sandbox. This is an emulation of a real SMEM + manager. + The sandbox driver allocates a shared memory from the heap and + initialzies it on start. + config MSM_SMEM bool "Qualcomm Shared Memory Manager (SMEM)" depends on DM diff --git a/drivers/smem/Makefile b/drivers/smem/Makefile index 605b8fc290..af3e9b5088 100644 --- a/drivers/smem/Makefile +++ b/drivers/smem/Makefile @@ -2,5 +2,6 @@ # # Makefile for the U-Boot SMEM interface drivers +obj-$(CONFIG_SANDBOX_SMEM) += sandbox_smem.o obj-$(CONFIG_SMEM) += smem-uclass.o obj-$(CONFIG_MSM_SMEM) += msm_smem.o diff --git a/drivers/smem/sandbox_smem.c b/drivers/smem/sandbox_smem.c new file mode 100644 index 0000000000..7397e4407a --- /dev/null +++ b/drivers/smem/sandbox_smem.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2018 Ramon Fried + */ + +#include +#include +#include +#include +#include + +static int sandbox_smem_alloc(unsigned int host, + unsigned int item, size_t size) +{ + return 0; +} + +static void *sandbox_smem_get(unsigned int host, + unsigned int item, size_t *size) +{ + return NULL; +} + +static int sandbox_smem_get_free_space(unsigned int host) +{ + return 0; +} + +static const struct smem_ops sandbox_smem_ops = { + .alloc = sandbox_smem_alloc, + .get = sandbox_smem_get, + .get_free_space = sandbox_smem_get_free_space, +}; + +static const struct udevice_id sandbox_smem_ids[] = { + { .compatible = "sandbox,smem" }, + { } +}; + +U_BOOT_DRIVER(smem_sandbox) = { + .name = "smem_sandbox", + .id = UCLASS_SMEM, + .of_match = sandbox_smem_ids, + .ops = &sandbox_smem_ops, +}; From patchwork Fri Jun 22 02:11:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 933164 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KS4DY1Hi"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41BtHx2HCyz9s3C for ; Fri, 22 Jun 2018 19:17:17 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DB62CC21EFF; Fri, 22 Jun 2018 09:16:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=DATE_IN_PAST_06_12, FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0F3B4C22054; Fri, 22 Jun 2018 09:12:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EF52FC21FBF; Fri, 22 Jun 2018 09:12:23 +0000 (UTC) Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by lists.denx.de (Postfix) with ESMTPS id A5BF4C21C2C for ; Fri, 22 Jun 2018 09:12:14 +0000 (UTC) Received: by mail-wr0-f194.google.com with SMTP id l14-v6so874897wrq.13 for ; Fri, 22 Jun 2018 02:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YSFsMnq06EnqSzjTX9aejw+0DiadLz5Gsx5FHrr4/PM=; b=KS4DY1Hix4aiigoN6N/5Y77sIycpMVGLwRiuvwgk7f+PYVW1OO0U4vvlDvnuHnWcN8 ehBkfvats+m+/QNVJcnz2wCMaH2PhwE2oknOq9tM/Ub1FcO2u2f1AmLMNcai2GrPPS9+ Kl4ltAYuhApa+Qm+6rgp5HKLYPXYM0n57srZuMR4K353wN6q/XCiPjXpy+U318vZ0nfA PxjWdKhw/X+LCrneDgXXnzEvCqjO4KeFfN0CVpiJB1wAunIkKk5sp9LUmIp4W/49zvYP 8IWlBVTYIXEwyEg3taY3eeI5nlDAg6/M4suCF2rmz7l0MMC2rKAlDoYwvpPbc1wosRKn MguA== 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=YSFsMnq06EnqSzjTX9aejw+0DiadLz5Gsx5FHrr4/PM=; b=TcwBiQBx3fntCv63SqhXJbkKsNIidiX0fnLQNAOKcb9jh1nAkfQCFxYiEVImtbFB6W QTSEn7KVz72sU9uXmpxxH2nsD8jVMYw3Lq51nCrSySg5/HO+PA5VDZ5LFOfWc2wzqnM1 0Ae5PO/usq4sBVHcRG1qxD2NbDwtowK3FPS8t6fx3Kl56LKOkguA0n2stnuh22t4MY3N YiFHdu5NhwzgQ6APcuF8+c1HIE6QgtOjT3pncrbCp25pjvViuJeLKFGdpuW0RU+NX4OQ wn2jgqG9oSImUFWQU9twpSrqMjjy7D59YbY9sWtat1UbNzBObp4/dh8C/Z+2AiKv9JNb 26oQ== X-Gm-Message-State: APt69E3HV+qAZ933ylYL9AnuRzSawM7eo8Qbf1Lukzxa3xqs06+hAsHY OIYViH0RFTEnKOpUYc+MDPQ= X-Google-Smtp-Source: ADUXVKLXaYGShTlw3Q/+bfX00bXHWDkDDPwn7m6SmpMDAUgcMXhsQQ+p8abDEp+VflYxZmYRhJwSkw== X-Received: by 2002:adf:f391:: with SMTP id m17-v6mr811615wro.279.1529658734357; Fri, 22 Jun 2018 02:12:14 -0700 (PDT) Received: from localhost.localdomain ([141.226.166.38]) by smtp.gmail.com with ESMTPSA id g16-v6sm6938310wro.86.2018.06.22.02.12.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 02:12:13 -0700 (PDT) From: Ramon Fried To: Simon Glass , u-boot@lists.denx.de, jramirez@baylibre.com, xypron.glpk@gmx.de Date: Fri, 22 Jun 2018 05:11:33 +0300 Message-Id: <20180622021133.24062-7-ramon.fried@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180622021133.24062-1-ramon.fried@gmail.com> References: <20180622021133.24062-1-ramon.fried@gmail.com> Cc: bjorn.andersson@linaro.org Subject: [U-Boot] [PATCH v2 6/6] test: smem: add basic smem test X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add basic smem sandbox testing. Signed-off-by: Ramon Fried Reviewed-by: Simon Glass --- Tom, this patch depends on https://patchwork.ozlabs.org/patch/932965/ Changes in v2: None test/dm/Makefile | 1 + test/dm/smem.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/dm/smem.c diff --git a/test/dm/Makefile b/test/dm/Makefile index 5511a85700..d2ed96c615 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_DM_RESET) += reset.o obj-$(CONFIG_SYSRESET) += sysreset.o obj-$(CONFIG_DM_RTC) += rtc.o obj-$(CONFIG_DM_SPI_FLASH) += sf.o +obj-$(CONFIG_SMEM) += smem.o obj-$(CONFIG_DM_SPI) += spi.o obj-y += syscon.o obj-$(CONFIG_DM_USB) += usb.o diff --git a/test/dm/smem.c b/test/dm/smem.c new file mode 100644 index 0000000000..4d94ddbe5b --- /dev/null +++ b/test/dm/smem.c @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Ramon Fried + */ + +#include +#include +#include +#include +#include + +/* Basic test of the smem uclass */ +static int dm_test_smem_base(struct unit_test_state *uts) +{ + struct udevice *dev; + size_t size; + + ut_assertok(uclass_get_device(UCLASS_SMEM, 0, &dev)); + ut_assertnonnull(dev); + ut_assertok(smem_alloc(dev, -1, 0, 16)); + ut_assertok(smem_get_free_space(dev, -1, &size); + ut_assertnonnull(smem_get(dev, -1, 0, &size)); + /* Try getting of bound item */ + ut_assertnnull(smem_get(dev, -1, 70, &size)); + + return 0; +} +DM_TEST(dm_test_smem_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); +