Skip to content

Commit

Permalink
mtd: phram: Allow cached mappings
Browse files Browse the repository at this point in the history
Currently phram always uses ioremap(), but this is unnecessary when
normal memory is used.  If the reserved-memory node does not specify the
no-map property, indicating it should be mapped as system RAM and
ioremap() cannot be used on it, use a cached mapping using
memremap(MEMREMAP_WB) instead.

On one of my systems this improves read performance by ~70%.

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
  • Loading branch information
vwax authored and intel-lab-lkp committed Apr 12, 2022
1 parent 0aa9a2d commit 188069f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/mtd/devices/phram.c
Expand Up @@ -34,6 +34,7 @@
struct phram_mtd_list {
struct mtd_info mtd;
struct list_head list;
bool cached;
};

static LIST_HEAD(phram_list);
Expand Down Expand Up @@ -96,15 +97,21 @@ static int register_device(struct platform_device *pdev, const char *name,
phys_addr_t start, size_t len, uint32_t erasesize)
{
struct device_node *np = pdev ? pdev->dev.of_node : NULL;
bool cached = np ? !of_property_read_bool(np, "no-map") : false;
struct phram_mtd_list *new;
int ret = -ENOMEM;

new = kzalloc(sizeof(*new), GFP_KERNEL);
if (!new)
goto out0;

new->cached = cached;

ret = -EIO;
new->mtd.priv = ioremap(start, len);
if (cached)
new->mtd.priv = memremap(start, len, MEMREMAP_WB);
else
new->mtd.priv = ioremap(start, len);
if (!new->mtd.priv) {
pr_err("ioremap failed\n");
goto out1;
Expand Down Expand Up @@ -140,7 +147,7 @@ static int register_device(struct platform_device *pdev, const char *name,
return 0;

out2:
iounmap(new->mtd.priv);
cached ? memunmap(new->mtd.priv) : iounmap(new->mtd.priv);
out1:
kfree(new);
out0:
Expand Down Expand Up @@ -362,7 +369,7 @@ static int phram_remove(struct platform_device *pdev)
struct phram_mtd_list *phram = platform_get_drvdata(pdev);

mtd_device_unregister(&phram->mtd);
iounmap(phram->mtd.priv);
phram->cached ? memunmap(phram->mtd.priv) : iounmap(phram->mtd.priv);
kfree(phram);

return 0;
Expand Down

0 comments on commit 188069f

Please sign in to comment.