From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756581AbcIUJvG (ORCPT ); Wed, 21 Sep 2016 05:51:06 -0400 Received: from mail.sigma-star.at ([95.130.255.111]:45996 "EHLO mail.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755541AbcIUJvE (ORCPT ); Wed, 21 Sep 2016 05:51:04 -0400 From: Daniel Walter To: linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org, computersforpeace@gmail.com, dwmw2@infradead.org, boris.brezillon@free-electrons.com, Richard Weinberger Subject: [PATCH v2 20/46] mtd: nandsim: Implement preliminary constructor function Date: Wed, 21 Sep 2016 11:51:01 +0200 Message-Id: X-Mailer: git-send-email 2.8.3 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Richard Weinberger This function will be used later by the ioctl() interface for creating new nandsim instances. Signed-off-by: Richard Weinberger --- drivers/mtd/nand/nandsim.c | 41 ++++++++++++++++++++++++++++++++++++++++- include/linux/mtd/nandsim.h | 3 ++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index 2e3c08e..344f5c4 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c @@ -2470,6 +2470,45 @@ static void ns_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) return; } +static int ns_ctrl_new_instance(struct ns_new_instance_req *req) +{ + struct mtd_info *nsmtd; + struct nand_chip *chip; + struct nandsim *ns; + struct nandsim_params *nsparam = kzalloc(sizeof(*nsparam), GFP_KERNEL); + + if (!nsparam) + return -ENOMEM; + + memcpy(nsparam->id_bytes, req->id_bytes, sizeof(nsparam->id_bytes)); + nsparam->bus_width = req->bus_width; + nsparam->file_fd = req->file_fd; + + switch (req->backend) { + case NANDSIM_BACKEND_RAM: + nsparam->bops = &ns_ram_bops; + break; + case NANDSIM_BACKEND_FILE: + nsparam->bops = &ns_file_bops; + break; + + default: + kfree(nsparam); + return -EINVAL; + } + + nsmtd = ns_new_instance(nsparam); + kfree(nsparam); + + if (IS_ERR(nsmtd)) + return PTR_ERR(nsmtd); + + chip = mtd_to_nand(nsmtd); + ns = nand_get_controller_data(chip); + + return ns->index; +} + static long ns_ctrl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -2764,7 +2803,7 @@ static int __init ns_init_default(void) nsparam->cache_file = cache_file; nsparam->bbt = bbt; nsparam->bch = bch; - nsparam->id_bytes = id_bytes; + memcpy(nsparam->id_bytes, id_bytes, sizeof(nsparam->id_bytes)); if (!nsparam->cache_file) nsparam->bops = &ns_ram_bops; diff --git a/include/linux/mtd/nandsim.h b/include/linux/mtd/nandsim.h index e3d2c9f..6e3b4a2 100644 --- a/include/linux/mtd/nandsim.h +++ b/include/linux/mtd/nandsim.h @@ -2,6 +2,7 @@ #define __LINUX_NANDSIM_H__ #include +#include struct nandsim_params { unsigned int access_delay; @@ -22,7 +23,7 @@ struct nandsim_params { char *cache_file; unsigned int bbt; unsigned int bch; - unsigned char *id_bytes; + unsigned char id_bytes[8]; unsigned int file_fd; struct ns_backend_ops *bops; }; -- 2.8.3