From patchwork Mon Sep 30 08:51:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kameyama eiji X-Patchwork-Id: 1169239 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=none (p=none dis=none) header.from=fujitsu.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46hdvF2hLyz9sDB for ; Mon, 30 Sep 2019 20:30:01 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 093D8C21E7E; Mon, 30 Sep 2019 10:29:23 +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=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3C440C21E9F; Mon, 30 Sep 2019 10:28:50 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0E536C21C51; Mon, 30 Sep 2019 08:51:29 +0000 (UTC) Received: from mgwym04.jp.fujitsu.com (mgwym04.jp.fujitsu.com [211.128.242.43]) by lists.denx.de (Postfix) with ESMTPS id 59698C21C2F for ; Mon, 30 Sep 2019 08:51:27 +0000 (UTC) Received: from yt-mxoi2.gw.nic.fujitsu.com (unknown [192.168.229.69]) by mgwym04.jp.fujitsu.com with smtp id 4af5_56b8_75f03e55_433e_44b3_95b1_25b55dd38fd1; Mon, 30 Sep 2019 17:51:18 +0900 Received: from durio.utsfd.cs.fujitsu.co.jp (durio.utsfd.cs.fujitsu.co.jp [10.24.20.112]) by yt-mxoi2.gw.nic.fujitsu.com (Postfix) with ESMTP id 7DDE3AC00B6 for ; Mon, 30 Sep 2019 17:51:17 +0900 (JST) Received: by durio.utsfd.cs.fujitsu.co.jp (Postfix, from userid 1005) id 2BA831FF315; Mon, 30 Sep 2019 17:51:17 +0900 (JST) From: kameyama eiji To: trini@konsulko.com Date: Mon, 30 Sep 2019 17:51:06 +0900 Message-Id: <20190930085106.25722-1-kameyama.eiji@fujitsu.com> X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 X-Mailman-Approved-At: Mon, 30 Sep 2019 10:28:46 +0000 Cc: u-boot@lists.denx.de, Pham Duc Tung , Dao Van Trung Subject: [U-Boot] [PATCH] cmd: memio: Add support functions to read/write data 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 existing source code (binop.c) includes read/write function to read/write data on DDR. To use these functions and avoid duplicate code, based on the existing functions, move and update the read/write function to a public file which is memio file. - New memio includes support functions to read/write data from/to DDR. - Update binop.c file to use read/write functions. Signed-off-by: Dao Van Trung Signed-off-by: Pham Duc Tung Signed-off-by: kameyama eiji --- cmd/Makefile | 1 + cmd/binop.c | 24 +++--------------------- cmd/memio.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/memio.h | 16 ++++++++++++++++ 4 files changed, 62 insertions(+), 21 deletions(-) create mode 100644 cmd/memio.c create mode 100644 include/memio.h diff --git a/cmd/Makefile b/cmd/Makefile index ac843b4b16..8c241b256e 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -86,6 +86,7 @@ obj-$(CONFIG_CMD_LOG) += log.o obj-$(CONFIG_ID_EEPROM) += mac.o obj-$(CONFIG_CMD_MD5SUM) += md5sum.o obj-$(CONFIG_CMD_MEMORY) += mem.o +obj-y += memio.o obj-$(CONFIG_CMD_IO) += io.o obj-$(CONFIG_CMD_MFSL) += mfsl.o obj-$(CONFIG_CMD_MII) += mii.o diff --git a/cmd/binop.c b/cmd/binop.c index 6d2df5f3dd..c14ca09fc3 100644 --- a/cmd/binop.c +++ b/cmd/binop.c @@ -7,6 +7,7 @@ #include #include #include +#include enum { OP_ID_XOR, @@ -44,26 +45,6 @@ void read_from_env_var(char *varname, u8 *result) hex2bin(result, varname, strlen(varname) / 2); } -void read_from_mem(ulong addr, u8 *result, ulong len) -{ - u8 *src; - - src = map_sysmem(addr, len); - memcpy(result, src, len); - unmap_sysmem(src); -} - -void write_to_mem(char *varname, u8 *result, ulong len) -{ - ulong addr; - u8 *buf; - - addr = simple_strtoul(varname, NULL, 16); - buf = map_sysmem(addr, len); - memcpy(buf, result, len); - unmap_sysmem(buf); -} - static int do_binop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { ulong len; @@ -134,7 +115,8 @@ static int do_binop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) destarg = argv[5]; if (*destarg == '*') - write_to_mem(destarg + 1, result, len); /* Skip asterisk */ + write_to_mem(simple_strtoul(destarg + 1, NULL, 16), + result, len); /* Skip asterisk */ else write_to_env_var(destarg, result, len); exit: diff --git a/cmd/memio.c b/cmd/memio.c new file mode 100644 index 0000000000..b9da5e5294 --- /dev/null +++ b/cmd/memio.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * cmd/memio.c + * Support functions to read/write data from/to DDR + * physical address. + * + * Copyright (C) 2019 FUJITSU VIETNAM LIMITED and FUJITSU COMPUTER + * TECHNOLOGIES LIMITED. All rights reserved. + */ +#include +#include +#include + +/** + * read_from_mem() - Read data from DDR + * @addr: Physical address on DDR + * @result: Buffer for read data + * @len: Data length + */ +void read_from_mem(ulong addr, u8 *result, ulong len) +{ + u8 *src; + + src = map_sysmem(addr, len); + memcpy(result, src, len); + unmap_sysmem(src); +} + +/** + * write_to_mem() - Write data to DDR + * @addr: Physical address on DDR + * @result: Buffer of write data + * @len: Data length + */ +void write_to_mem(ulong addr, u8 *result, ulong len) +{ + u8 *buf; + + buf = map_sysmem(addr, len); + memcpy(buf, result, len); + unmap_sysmem(buf); +} diff --git a/include/memio.h b/include/memio.h new file mode 100644 index 0000000000..c5f397393b --- /dev/null +++ b/include/memio.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * include/memio.h + * This file declares support functions to read/write from/to + * DDR physical address. + * + * Copyright (C) 2019 FUJITSU VIETNAM LIMITED and FUJITSU COMPUTER + * TECHNOLOGIES LIMITED. All rights reserved. + */ +#ifndef _MEMIO_H_ +#define _MEMIO_H_ + +void read_from_mem(ulong addr, u8 *result, ulong len); +void write_to_mem(ulong addr, u8 *result, ulong len); + +#endif /* _MEMIO_H_ */