From: johan.adolfsson@axis.com
To: <linux-mtd@lists.infradead.org>
Cc: "Johan Adolfsson" <johan.adolfsson@axis.com>
Subject: [PATCH/RFC] Create mtdram device at runtime.
Date: Tue, 30 Apr 2002 12:01:13 +0200 [thread overview]
Message-ID: <00d201c1f02d$f672d580$bdb270d5@homeip.net> (raw)
The following patch moves most of the stuff out from the init_mtdram()
function into a non static mtdram_init_device() function that can be
called from other places in the kernel,
e.g. from a mapping routine to map in a cramfs image in RAM using
the mtd layer:-)
To prevent the device from being created by init_mtdram using the
configured values, CONFIG_MTDRAM_TOTAL_SIZE should be set to 0
(The help should be updated as well)
A new file: include/linux/mtd/mtdram.h is created as well.
Still some things missing regarding cleanup on exit for modules.
This is a first shot at it and it seems to work for us, but the
API should perhaps be tweaked a little bit more, i.e. providing the
flags and erase size as well.
Does it make enough sense to go into the official version
(after some tweaking)?
/Johan
diff -u -p -r1.1.1.3 mtdram.c
--- linux/drivers/mtd/devices/mtdram.c 23 Apr 2002 13:18:59 -0000 1.1.1.3
+++ linux/drivers/mtd/devices/mtdram.c 30 Apr 2002 09:28:23 -0000
@@ -118,7 +118,7 @@ static void __exit cleanup_mtdram(void)
}
}
-int __init init_mtdram(void)
+int mtdram_init_device(void *mapped_address, unsigned long size, char
*name)
{
// Allocate some memory
mtd_info = (struct mtd_info *)kmalloc(sizeof(struct mtd_info),
GFP_KERNEL);
@@ -128,26 +128,14 @@ int __init init_mtdram(void)
memset(mtd_info, 0, sizeof(*mtd_info));
// Setup the MTD structure
- mtd_info->name = "mtdram test device";
+ mtd_info->name = name;
mtd_info->type = MTD_RAM;
mtd_info->flags = MTD_CAP_RAM;
- mtd_info->size = MTDRAM_TOTAL_SIZE;
+ mtd_info->size = size;
mtd_info->erasesize = MTDRAM_ERASE_SIZE;
-#if CONFIG_MTDRAM_ABS_POS > 0
- mtd_info->priv = ioremap(CONFIG_MTDRAM_ABS_POS, MTDRAM_TOTAL_SIZE);
-#else
- mtd_info->priv = vmalloc(MTDRAM_TOTAL_SIZE);
-#endif
-
- if (!mtd_info->priv) {
- DEBUG(MTD_DEBUG_LEVEL1, "Failed to vmalloc(/ioremap) memory region of
size %ld (ABS_POS:%ld)\n", (long)MTDRAM_TOTAL_SIZE,
(long)CONFIG_MTDRAM_ABS_POS);
- kfree(mtd_info);
- mtd_info = NULL;
- return -ENOMEM;
- }
- memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
+ mtd_info->priv = mapped_address;
- mtd_info->module = THIS_MODULE;
+ mtd_info->module = THIS_MODULE;
mtd_info->erase = ram_erase;
mtd_info->point = ram_point;
mtd_info->unpoint = ram_unpoint;
@@ -155,11 +143,6 @@ int __init init_mtdram(void)
mtd_info->write = ram_write;
if (add_mtd_device(mtd_info)) {
-#if CONFIG_MTDRAM_ABS_POS > 0
- iounmap(mtd_info->priv);
-#else
- vfree(mtd_info->priv);
-#endif
kfree(mtd_info);
mtd_info = NULL;
return -EIO;
@@ -168,10 +151,42 @@ int __init init_mtdram(void)
return 0;
}
+int __init init_mtdram(void)
+{
+ void *addr;
+ int err = 0;
+#if CONFIG_MTDRAM_TOTAL_SIZE > 0
+#if CONFIG_MTDRAM_ABS_POS > 0
+ addr = ioremap(CONFIG_MTDRAM_ABS_POS, MTDRAM_TOTAL_SIZE);
+#else
+ addr = vmalloc(MTDRAM_TOTAL_SIZE);
+#endif
+ if (!addr) {
+ DEBUG(MTD_DEBUG_LEVEL1, "Failed to vmalloc(/ioremap) memory region of
size %ld (ABS_POS:%ld)\n", (long)MTDRAM_TOTAL_SIZE,
(long)CONFIG_MTDRAM_ABS_POS);
+ kfree(mtd_info);
+ mtd_info = NULL;
+ return -ENOMEM;
+ }
+ err = mtdram_init_device(addr, MTDRAM_TOTAL_SIZE, "mtdram test device";
+ if (err)
+ {
+#if CONFIG_MTDRAM_ABS_POS > 0
+ iounmap(mtd_info->priv);
+#else
+ vfree(mtd_info->priv);
+#endif
+ }
+ memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE);
+#endif /* CONFIG_MTDRAM_TOTAL_SIZE > 0 */
+ return err;
+}
+
+
module_init(init_mtdram);
module_exit(cleanup_mtdram);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Alexander Larsson <alexl@redhat.com>");
MODULE_DESCRIPTION("Simulated MTD driver for testing");
+
--- /dev/null Sat Mar 24 05:37:44 2001
+++ linux/include/linux/mtd/mtdram.h Mon Apr 29 18:12:14 2002
@@ -0,0 +1,8 @@
+#ifndef __MTD_MTDRAM_H__
+#define __MTD_MTDRAM_H__
+
+#ifdef __KERNEL__
+int mtdram_init_device(void *mapped_address, unsigned long size, char
*name);
+
+#endif /* __KERNEL__ */
+#endif /* __MTD_MTDRAM_H__ */
next reply other threads:[~2002-04-30 9:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-30 10:01 johan.adolfsson [this message]
2002-04-30 10:10 ` [PATCH/RFC] Create mtdram device at runtime David Woodhouse
2002-04-30 10:28 ` johan.adolfsson
2002-04-30 12:21 ` David Woodhouse
2002-04-30 13:19 ` johan.adolfsson
2002-04-30 16:21 ` David Woodhouse
2002-05-06 8:49 ` Johan Adolfsson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='00d201c1f02d$f672d580$bdb270d5@homeip.net' \
--to=johan.adolfsson@axis.com \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox