Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751479AbdIRUj5 (ORCPT ); Mon, 18 Sep 2017 16:39:57 -0400 Received: from mail-dm3nam03on0065.outbound.protection.outlook.com ([104.47.41.65]:14405 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750714AbdIRUjx (ORCPT ); Mon, 18 Sep 2017 16:39:53 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; From: Roy Pledge To: , , , , CC: , , , , , , Roy Pledge Subject: [v5 01/12] soc/fsl/qbman: Add common routine for QBMan private allocations Date: Mon, 18 Sep 2017 16:39:36 -0400 Message-ID: <1505767187-4596-2-git-send-email-roy.pledge@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505767187-4596-1-git-send-email-roy.pledge@nxp.com> References: <1505767187-4596-1-git-send-email-roy.pledge@nxp.com> Reply-To: X-EOPAttributedMessage: 0 X-Matching-Connectors: 131502407919137887;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(336005)(7966004)(39860400002)(376002)(346002)(39380400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(43066003)(106466001)(53936002)(50466002)(33646002)(81166006)(54906002)(4326008)(81156014)(68736007)(5003940100001)(48376002)(7416002)(50226002)(8936002)(305945005)(6666003)(2950100002)(105606002)(189998001)(104016004)(47776003)(5660300001)(8676002)(2906002)(97736004)(356003)(36756003)(86362001)(2201001)(77096006)(50986999)(76176999)(8656003)(3450700001)(498600001)(85426001)(316002)(16586007)(110136005)(2004002)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:SN2PR03MB2367;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD042;1:nT+RgvB8oigsAhW8+LSzRlXdaUdGHUP8yAxDDlwSCviavRRmLakPR/quius+ddDacPqaLQznJba1aUY7byb65+/KPsAKPSyZA832JBAKPy4UrPfUIqtp+0u+LIJ0JORk MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1d444bec-29ee-4ced-92fe-08d4fed56995 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(2017052603199)(201703131430075)(201703131517081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:SN2PR03MB2367; X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB2367;3:f0PSUSzp8IRDSIWi5QYIXO1sIBmt892+/lXxdfytTAVZEiCWMzDjVM/a7jLvRO45SJtfpQtm0nIcx70t6pSHbT0bAQ5flYTG9KD7IchO7KX4OjosbT5lLR7lL7UrDA6OmTRX8iEWFXtqU3uRwPulYm9E5RMo5lMdjOE9WxWv3wHBgcGPMcAhJ6ATmJCy8Zo0V0GCujq0pRg8/Emd0/pt99k4sMCrYv8x5a+/MgSQEZvULeF0JGG1CC2mwc6GKANO46EuyGbgsdwiSIhwLncVISXidnB8Y/wlsitJOVIUUtNtpF40K8dC/1975QWCoI0bujTf8yEnYgjqH3UvyAtfizwKXTSSbZERnVpcNVq27ec=;25:U/zONgPJEx/hAfnDFgDN6Uya65uUqUvALHM/toNaNCc9L/7O6opm1hIWBXgDuJ+kHL29lK0jOb49QNwyP9hLwYZLfrhmprza3GLd21lIYIdcFzZ1nlFHRVKkW30DB4+XDJrJ2uHo7UElhl2QFMw73h1oG4HnnMA3szvv+DFsgKtdoJjVvSK885B6MTW9LUbGEeaM/4hl2jXEUYSuU++aEPu+Txy5/SF0WZkG+w88LkPDmpz7Nc5UJuBbJHomQd8zElSlk3u3cN/erY4Rv9mBq/3ZsH3SfhrkGNVDq6G4lEsver9mjLamN9J1A0IFYXNPQI2vE5K7bKdiw9yqf4POJQ== X-MS-TrafficTypeDiagnostic: SN2PR03MB2367: X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB2367;31:Al1b6mvmzT2pAU1eKHhnWZJFfrovUnMG5p/OAsjY3zjjWSrGu+Bnk037yz+00cjKvZgGdPQ8U7CIqCkhQB8LuLOATYlayvbbv1p9n3jkZnFsXKr83IDo3h+aJx6bDiBR5v2M9+j4Pn4f2K59ERVZCxpjGqzS1sLFDvI/PWTVFR7SNMo0Jnvbvd/rQ5pNtmD572Q0SKTrnQ48TBkT8kPHidiuLohY7i1rDDo/IyqX9gA=;4:OyXtgCy/kCyDJVHj3gcEGzo7PpDeFHJSArQ76Hu4BfaN1YIpPb83m9hftiYdXfZyb+4I1TgTJbk1/nqHm6g6ZuPhCkuSuAyp7/zE2WimjC2vrsc7Rhs2iYNT1nEo0C2y0qVuNVOdCXSd9wNxS/GyDxMC5V4glVnZqrhH2exU8TTnH0vh96vFQkklqEOtD6rwGgbcBSuNYCtSa8cMQg177Wd4FZhEw7M+Uks2xR4jRLxdVbNLkBkkxUCfIhqAgxwlmfN9kRyRf5gF9h97VawgOYvSmemd38K/UjunqYjLX/A= X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(6055026)(6096035)(20161123559100)(20161123556025)(201703131430075)(201703131441075)(201703131448075)(201703131433075)(201703161259150)(20161123563025)(20161123561025)(20161123565025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:SN2PR03MB2367;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:SN2PR03MB2367; X-Forefront-PRVS: 04347F8039 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR03MB2367;23:SEbt5dhttcsbRluvzKEjo5Syld+sJ1MryF30Yr1+r?= =?us-ascii?Q?13cgn+YFdqq4z2YRWCKbc38iiXZ/pVQk7QsyGusJSSe5SZ1o7aQ2clRYXBVu?= =?us-ascii?Q?azkoIaNxWxuGHRpzbO8EDZMPZq11p965aq7AygahD0AhQfcHDIuNA/v0p7er?= =?us-ascii?Q?2dpLJbg1RR/nWbtDPaM3Qo1SvBteJSy2TvI0ertfHZ42G020KsTBdyoJwnkj?= =?us-ascii?Q?Xm0yDhv7FwKzUi0Th7W2Fx2kk5KnE8WKEH7IRODfWchvwKsd/ZUbE2A4dT4C?= =?us-ascii?Q?iXb91+wlZOnEwXIC/sznTU/z2wTkz3kjdMt1WLgKCLfJ8edRfcsRD1ujJRgN?= =?us-ascii?Q?cfGMSlXWQrQA78Go7sp6PM14XFDTo6hWbuxA7+JnsLobsfHYhAnJbBbEbt87?= =?us-ascii?Q?K2dpzhl5nbEIy43d9LxAGAFgX1eaC8zxxGGpoiauISB/dH2d80uv33DGmvcU?= =?us-ascii?Q?3YKR5PTxTzDjMjd977nWjMv0n3U4m0Sp5wzuTtVq34e4OrQn3jMi3svE9ryA?= =?us-ascii?Q?2QJmIVX6kgO2b21xW1VoDJDFAp7yyEwqBk8liM2hfuicewAc5nvKNXv1E+N3?= =?us-ascii?Q?GZDSKxfnOQydpwxDapsa20w8X2hVLe/sm2q5kAzmJUYLG8ipYpdyDSULlckY?= =?us-ascii?Q?4E49QhwF0lUFp+BQ/SQ8LX87WCBsbgRDZZiHqXnaEo4DRQfL3EThoB3BNdjj?= =?us-ascii?Q?mNDEbLUOnIjkNi9FvkyC3ckndGtIgf8klfNEgS8MJV4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O5y/blDW4P2BEAA==;5:Hkw5nLk6jAJagy30BQD8IIT0DTqr3QidveaNOoIEOJzEb3+QbdxMhv6+3lQo44e2rk7bMSK38TvXT13NJOBlV7Q7g7v8rBQ/ct7JK6GfLsQ7LsVPGL0aokWnSyxAidMDWyiHdAwJdBmbpnkvhRczMA==;24:dHGeXAB1B4WNDxlQ4KVpTjkQm2TnCAaJXkCskVNwb63o6zEe6y34WEk3z14K8Vc48Hj9W4uIe/XcxPuQ7gqi+eHQoYU5wlHehb7FCXVK/FI=;7:Jw9Ut8pUf5om2gnvczokRPHn8PDJ2nDF/AemghdcKBJnRhG76OcBjhCFyXNzTVRwV39x8mzgVqzr4b+jVocsnUs5as4jfTPYmkWvkjfRgc3HKEMoIEAPSYETl7eGnxJos5iEg8TZoayQQyHWXVoye9QwXZ/VaJGCS+BFCp3z0v3HfE3VSPOuKU0/8m38SpRFJaiu+tKlYZbkl81fI+b0yq/7VfHVg6MIXhyrkmpJNBQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2017 20:39:51.6953 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2367 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4804 Lines: 123 The QBMan device uses several memory regions to manage frame queues and buffers. Add a common routine for extracting and initializing these reserved memory areas. Signed-off-by: Roy Pledge --- drivers/soc/fsl/qbman/Makefile | 2 +- drivers/soc/fsl/qbman/dpaa_sys.c | 78 ++++++++++++++++++++++++++++++++++++++++ drivers/soc/fsl/qbman/dpaa_sys.h | 4 +++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 drivers/soc/fsl/qbman/dpaa_sys.c diff --git a/drivers/soc/fsl/qbman/Makefile b/drivers/soc/fsl/qbman/Makefile index 7ae199f..3cbd08a 100644 --- a/drivers/soc/fsl/qbman/Makefile +++ b/drivers/soc/fsl/qbman/Makefile @@ -1,6 +1,6 @@ obj-$(CONFIG_FSL_DPAA) += bman_ccsr.o qman_ccsr.o \ bman_portal.o qman_portal.o \ - bman.o qman.o + bman.o qman.o dpaa_sys.o obj-$(CONFIG_FSL_BMAN_TEST) += bman-test.o bman-test-y = bman_test.o diff --git a/drivers/soc/fsl/qbman/dpaa_sys.c b/drivers/soc/fsl/qbman/dpaa_sys.c new file mode 100644 index 0000000..9436aa8 --- /dev/null +++ b/drivers/soc/fsl/qbman/dpaa_sys.c @@ -0,0 +1,78 @@ +/* Copyright 2017 NXP Semiconductor, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of NXP Semiconductor nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY NXP Semiconductor ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NXP Semiconductor BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "dpaa_sys.h" + +/* + * Initialize a devices private memory region + */ +int qbman_init_private_mem(struct device *dev, int idx, dma_addr_t *addr, + size_t *size) +{ + int ret; + struct device_node *mem_node; + u64 size64; + + ret = of_reserved_mem_device_init_by_idx(dev, dev->of_node, idx); + if (ret) { + dev_err(dev, + "of_reserved_mem_device_init_by_idx(%d) failed 0x%x\n", + idx, ret); + return -ENODEV; + } + mem_node = of_parse_phandle(dev->of_node, "memory-region", 0); + if (mem_node) { + ret = of_property_read_u64(mem_node, "size", &size64); + if (ret) { + dev_err(dev, "of_address_to_resource fails 0x%x\n", + ret); + return -ENODEV; + } + *size = size64; + } else { + dev_err(dev, "No memory-region found for index %d\n", idx); + return -ENODEV; + } + + if (!dma_zalloc_coherent(dev, *size, addr, 0)) { + dev_err(dev, "DMA Alloc memory failed\n"); + return -ENODEV; + } + + /* + * Disassociate the reserved memory area from the device + * because a device can only have one DMA memory area. This + * should be fine since the memory is allocated and initialized + * and only ever accessed by the QBMan device from now on + */ + of_reserved_mem_device_release(dev); + return 0; +} diff --git a/drivers/soc/fsl/qbman/dpaa_sys.h b/drivers/soc/fsl/qbman/dpaa_sys.h index 2ce394a..676af82 100644 --- a/drivers/soc/fsl/qbman/dpaa_sys.h +++ b/drivers/soc/fsl/qbman/dpaa_sys.h @@ -102,4 +102,8 @@ static inline u8 dpaa_cyc_diff(u8 ringsize, u8 first, u8 last) /* Offset applied to genalloc pools due to zero being an error return */ #define DPAA_GENALLOC_OFF 0x80000000 +/* Initialize the devices private memory region */ +int qbman_init_private_mem(struct device *dev, int idx, dma_addr_t *addr, + size_t *size); + #endif /* __DPAA_SYS_H */ -- 2.7.4