summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3ea3fb0)
raw | patch | inline | side by side (parent: 3ea3fb0)
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | |
Sun, 10 Jul 2011 12:19:39 +0000 (14:19 +0200) | ||
committer | Vaibhav Hiremath <hvaibhav@ti.com> | |
Mon, 23 Jan 2012 19:14:23 +0000 (00:44 +0530) |
We have two SoCs using SRAM, both with their own allocation systems,
and both with their own ways of copying functions into the SRAM.
Let's unify this before we have additional SoCs re-implementing this
obviously common functionality themselves.
For this use the generic allocator and the newly introduce
gen_pool_add_virt and gen_pool_virt_to_phys
Uio_pruss should probably take the SRAM pool pointer via
platform data so that it doesn't have to include Davinci specific
includes.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Sekhar Nori <nsekhar@ti.com>
Cc: Kevin Hilman <khilman@ti.com>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Sascha Hauer <kernel@pengutronix.de>
Signed-off-by: Hebbar, Gururaja <gururaja.hebbar@ti.com>
Signed-off-by: Vaibhav Hiremath <hvaibhav@ti.com>
and both with their own ways of copying functions into the SRAM.
Let's unify this before we have additional SoCs re-implementing this
obviously common functionality themselves.
For this use the generic allocator and the newly introduce
gen_pool_add_virt and gen_pool_virt_to_phys
Uio_pruss should probably take the SRAM pool pointer via
platform data so that it doesn't have to include Davinci specific
includes.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Sekhar Nori <nsekhar@ti.com>
Cc: Kevin Hilman <khilman@ti.com>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Sascha Hauer <kernel@pengutronix.de>
Signed-off-by: Hebbar, Gururaja <gururaja.hebbar@ti.com>
Signed-off-by: Vaibhav Hiremath <hvaibhav@ti.com>
14 files changed:
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b259c7c644e357a9999c3767fd34431d8c39ae8a..f44d5a04831112f62e1920a742d5d4657a5000f0 100644 (file)
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
select ARCH_REQUIRE_GPIOLIB
select ARCH_HAS_CPUFREQ
select CLKSRC_MMIO
+ select GENERIC_ALLOCATOR
select GENERIC_CLOCKEVENTS
select HAVE_SCHED_CLOCK
select ARCH_HAS_HOLES_MEMORYMODEL
index b047f87022785477ffafc8336bfd438f27e51ae9..547b222d0ca4581b735184f98eba36d27b137a2c 100644 (file)
.gpio_irq = IRQ_DA8XX_GPIO0,
.serial_dev = &da8xx_serial_device,
.emac_pdata = &da8xx_emac_pdata,
- .sram_dma = DA8XX_ARM_RAM_BASE,
+ .sram_phys = DA8XX_ARM_RAM_BASE,
.sram_len = SZ_8K,
.reset_device = &da8xx_wdt_device,
};
index fe520d4167a2c34d3cc794ed3e836049bc926594..d901e5f1818994d367f0668dc2eb977b8d30960f 100644 (file)
.gpio_num = 104,
.gpio_irq = IRQ_DM355_GPIOBNK0,
.serial_dev = &dm355_serial_device,
- .sram_dma = 0x00010000,
+ .sram_phys = 0x00010000,
.sram_len = SZ_32K,
.reset_device = &davinci_wdt_device,
};
index 679e168dce34e55f4c711d12c01eab4300174bac..d5d14f554347a376c1189dc74f4417ed6a6e112f 100644 (file)
.gpio_unbanked = 8, /* really 16 ... skip muxed GPIOs */
.serial_dev = &dm365_serial_device,
.emac_pdata = &dm365_emac_pdata,
- .sram_dma = 0x00010000,
+ .sram_phys = 0x00010000,
.sram_len = SZ_32K,
.reset_device = &davinci_wdt_device,
};
index 3470983aa343c6a9d30a0b50cdcd3570cd6882e0..df72a4ea64a50d7cd7137eab5b0ee8c068a77517 100644 (file)
.gpio_irq = IRQ_GPIOBNK0,
.serial_dev = &dm644x_serial_device,
.emac_pdata = &dm644x_emac_pdata,
- .sram_dma = 0x00008000,
+ .sram_phys = 0x00008000,
.sram_len = SZ_16K,
.reset_device = &davinci_wdt_device,
};
index af27c130595fb6897cb104253ad157f567d53f04..4ab327aa41106f05c4b7938963e30449070d5aed 100644 (file)
.gpio_irq = IRQ_DM646X_GPIOBNK0,
.serial_dev = &dm646x_serial_device,
.emac_pdata = &dm646x_emac_pdata,
- .sram_dma = 0x10010000,
+ .sram_phys = 0x10010000,
.sram_len = SZ_32K,
.reset_device = &davinci_wdt_device,
};
diff --git a/arch/arm/mach-davinci/include/mach/common.h b/arch/arm/mach-davinci/include/mach/common.h
index a57cba21e21e1e150a949971deda4f46f38c50d7..665d049be96f399850318ef5e2266fdb7d396c28 100644 (file)
int gpio_ctlrs_num;
struct platform_device *serial_dev;
struct emac_platform_data *emac_pdata;
- dma_addr_t sram_dma;
+ phys_addr_t sram_phys;
unsigned sram_len;
struct platform_device *reset_device;
void (*reset)(struct platform_device *);
index 111f7cc71e07b0a36ff0ccba4df066216c8747b6..aa52009f0d971829383835a385130eaa77e03c68 100644 (file)
#ifndef __MACH_SRAM_H
#define __MACH_SRAM_H
+#include <linux/genalloc.h>
+
/* ARBITRARY: SRAM allocations are multiples of this 2^N size */
#define SRAM_GRANULARITY 512
-/*
- * SRAM allocations return a CPU virtual address, or NULL on error.
- * If a DMA address is requested and the SRAM supports DMA, its
- * mapped address is also returned.
- *
- * Errors include SRAM memory not being available, and requesting
- * DMA mapped SRAM on systems which don't allow that.
- */
-extern void *sram_alloc(size_t len, dma_addr_t *dma);
-extern void sram_free(void *addr, size_t len);
+extern struct gen_pool *davinci_gen_pool;
#endif /* __MACH_SRAM_H */
index 04c49f7543ef0df4a30a52c5c862f623222a93cd..25b1d2a2e96550d9f66693f6ede29127e1f1d332 100644 (file)
#include <asm/cacheflush.h>
#include <asm/delay.h>
#include <asm/io.h>
+#include <asm/fncpy.h>
#include <mach/da8xx.h>
#include <mach/sram.h>
#define DEEPSLEEP_SLEEPCOUNT_MASK 0xFFFF
static void (*davinci_sram_suspend) (struct davinci_pm_config *);
+static void *davinci_sram_suspend_mem;
static struct davinci_pm_config *pdata;
-static void davinci_sram_push(void *dest, void *src, unsigned int size)
-{
- memcpy(dest, src, size);
- flush_icache_range((unsigned long)dest, (unsigned long)(dest + size));
-}
-
static void davinci_pm_suspend(void)
{
unsigned val;
return -ENOENT;
}
- davinci_sram_suspend = sram_alloc(davinci_cpu_suspend_sz, NULL);
- if (!davinci_sram_suspend) {
+ davinci_sram_suspend_mem = (void *)gen_pool_alloc(davinci_gen_pool,
+ davinci_cpu_suspend_sz);
+ if (!davinci_sram_suspend_mem) {
dev_err(&pdev->dev, "cannot allocate SRAM memory\n");
return -ENOMEM;
}
-
- davinci_sram_push(davinci_sram_suspend, davinci_cpu_suspend,
- davinci_cpu_suspend_sz);
+ davinci_sram_suspend = fncpy(davinci_sram_suspend_mem,
+ &davinci_cpu_suspend, davinci_cpu_suspend_sz);
suspend_set_ops(&davinci_pm_ops);
static int __exit davinci_pm_remove(struct platform_device *pdev)
{
- sram_free(davinci_sram_suspend, davinci_cpu_suspend_sz);
+ gen_pool_free(davinci_gen_pool, (unsigned long)davinci_sram_suspend_mem,
+ davinci_cpu_suspend_sz);
return 0;
}
index db0f7787faf17d2d64ca650c1af6d9ecf2d7e628..2c53db2c561f85584e64c8ed4954964fcb8fa694 100644 (file)
*/
#include <linux/module.h>
#include <linux/init.h>
-#include <linux/genalloc.h>
#include <mach/common.h>
#include <mach/sram.h>
-static struct gen_pool *sram_pool;
-
-void *sram_alloc(size_t len, dma_addr_t *dma)
-{
- unsigned long vaddr;
- dma_addr_t dma_base = davinci_soc_info.sram_dma;
-
- if (dma)
- *dma = 0;
- if (!sram_pool || (dma && !dma_base))
- return NULL;
-
- vaddr = gen_pool_alloc(sram_pool, len);
- if (!vaddr)
- return NULL;
-
- if (dma)
- *dma = dma_base + (vaddr - SRAM_VIRT);
- return (void *)vaddr;
-
-}
-EXPORT_SYMBOL(sram_alloc);
-
-void sram_free(void *addr, size_t len)
-{
- gen_pool_free(sram_pool, (unsigned long) addr, len);
-}
-EXPORT_SYMBOL(sram_free);
-
+struct gen_pool *davinci_gen_pool;
+EXPORT_SYMBOL_GPL(davinci_gen_pool);
/*
* REVISIT This supports CPU and DMA access to/from SRAM, but it
static int __init sram_init(void)
{
unsigned len = davinci_soc_info.sram_len;
- int status = 0;
- if (len) {
- len = min_t(unsigned, len, SRAM_SIZE);
- sram_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1);
- if (!sram_pool)
- status = -ENOMEM;
- }
- if (sram_pool)
- status = gen_pool_add(sram_pool, SRAM_VIRT, len, -1);
- WARN_ON(status < 0);
- return status;
+ if (!len)
+ return 0;
+
+ len = min_t(unsigned, len, SRAM_SIZE);
+ davinci_gen_pool = gen_pool_create(ilog2(SRAM_GRANULARITY), -1);
+
+ if (!davinci_gen_pool)
+ return -ENOMEM;
+
+ WARN_ON(gen_pool_add_virt(davinci_gen_pool, SRAM_VIRT,
+ davinci_soc_info.sram_phys, len, -1));
+
+ return 0;
}
core_initcall(sram_init);
-
index 75aa1b2bef519eaa8958c37a7050df66c022848a..1be45a640fd74d2b387872e8339a1e46d03526bb 100644 (file)
#define __ARCH_ARM_OMAP_SRAM_H
#ifndef __ASSEMBLY__
+#include <linux/slab.h>
+#include <linux/genalloc.h>
#include <asm/fncpy.h>
-extern void *omap_sram_push_address(unsigned long size);
+extern struct gen_pool *omap_gen_pool;
-/* Macro to push a function to the internal SRAM, using the fncpy API */
+/*
+ * Note that fncpy requires the SRAM address to be aligned to an 8-byte
+ * boundary, so the min_alloc_order for the pool is set appropriately.
+ */
#define omap_sram_push(funcp, size) ({ \
- typeof(&(funcp)) _res = NULL; \
- void *_sram_address = omap_sram_push_address(size); \
- if (_sram_address) \
- _res = fncpy(_sram_address, &(funcp), size); \
+ typeof(&(funcp)) _res; \
+ size_t _sz = size; \
+ void *_sram = gen_pool_alloc(omap_gen_pool, _sz); \
+ _res = (_sram ? fncpy(_sram, &(funcp), _sz) : NULL); \
+ if (!_res) \
+ pr_err("Not enough space in SRAM\n"); \
_res; \
})
index c702425231de094777b901310d022690f01b897d..343c4f9e2103c57002f8db9394245ede23b4604b 100644 (file)
static unsigned long omap_sram_start;
static void __iomem *omap_sram_base;
static unsigned long omap_sram_size;
-static void __iomem *omap_sram_ceil;
/*
* Depending on the target RAMFS firewall setup, the public usable amount of
return 1; /* assume locked with no PPA or security driver */
}
+struct gen_pool *omap_gen_pool;
+EXPORT_SYMBOL_GPL(omap_gen_pool);
+
/*
* The amount of SRAM depends on the core type.
* Note that we cannot try to test for SRAM here because writes
omap_sram_size = 0x4000;
}
}
+ {
+ /* The first SRAM_BOOTLOADER_SZ of SRAM are reserved */
+ void *base = (void *)omap_sram_base + SRAM_BOOTLOADER_SZ;
+ phys_addr_t phys = omap_sram_start + SRAM_BOOTLOADER_SZ;
+ size_t len = omap_sram_size - SRAM_BOOTLOADER_SZ;
+
+ omap_gen_pool = gen_pool_create(ilog2(FNCPY_ALIGN), -1);
+ if (omap_gen_pool)
+ WARN_ON(gen_pool_add_virt(omap_gen_pool,
+ (unsigned long)base, phys, len, -1));
+ WARN_ON(!omap_gen_pool);
+ }
}
/*
return;
}
- omap_sram_ceil = omap_sram_base + omap_sram_size;
-
/*
* Looks like we need to preserve some bootloader code at the
* beginning of SRAM for jumping to flash for reboot to work...
omap_sram_size - SRAM_BOOTLOADER_SZ);
}
-/*
- * Memory allocator for SRAM: calculates the new ceiling address
- * for pushing a function using the fncpy API.
- *
- * Note that fncpy requires the returned address to be aligned
- * to an 8-byte boundary.
- */
-void *omap_sram_push_address(unsigned long size)
-{
- unsigned long available, new_ceil = (unsigned long)omap_sram_ceil;
-
- available = omap_sram_ceil - (omap_sram_base + SRAM_BOOTLOADER_SZ);
-
- if (size > available) {
- pr_err("Not enough space in SRAM\n");
- return NULL;
- }
-
- new_ceil -= size;
- new_ceil = ROUND_DOWN(new_ceil, FNCPY_ALIGN);
- omap_sram_ceil = IOMEM(new_ceil);
-
- return (void *)omap_sram_ceil;
-}
-
#ifdef CONFIG_ARCH_OMAP1
static void (*_omap_sram_reprogram_clock)(u32 dpllctl, u32 ckctl);
#ifdef CONFIG_PM
void omap3_sram_restore_context(void)
{
- omap_sram_ceil = omap_sram_base + omap_sram_size;
-
_omap3_sram_configure_core_dpll =
omap_sram_push(omap3_sram_configure_core_dpll,
omap3_sram_configure_core_dpll_sz);
index e67b566e7aa3ff08ea6a8d42f17cabfeaf861473..d53957ac363ff43b02e841d4e1de201c41d0a2e2 100644 (file)
--- a/drivers/uio/uio_pruss.c
+++ b/drivers/uio/uio_pruss.c
struct uio_pruss_dev {
struct uio_info *info;
struct clk *pruss_clk;
- dma_addr_t sram_paddr;
+ phys_addr_t sram_paddr;
dma_addr_t ddr_paddr;
void __iomem *prussio_vaddr;
void *sram_vaddr;
gdev->ddr_paddr);
}
if (gdev->sram_vaddr)
- sram_free(gdev->sram_vaddr, sram_pool_sz);
+ gen_pool_free(davinci_gen_pool,
+ (unsigned long)gdev->sram_vaddr, sram_pool_sz);
kfree(gdev->info);
clk_put(gdev->pruss_clk);
kfree(gdev);
goto out_free;
}
- gdev->sram_vaddr = sram_alloc(sram_pool_sz, &(gdev->sram_paddr));
+ gdev->sram_vaddr = (void *)gen_pool_alloc(davinci_gen_pool,
+ sram_pool_sz);
if (!gdev->sram_vaddr) {
dev_err(&dev->dev, "Could not allocate SRAM pool\n");
goto out_free;
}
+ gdev->sram_paddr = gen_pool_virt_to_phys(davinci_gen_pool,
+ (unsigned long)gdev->sram_vaddr);
+
gdev->ddr_vaddr = dma_alloc_coherent(&dev->dev, extram_pool_sz,
&(gdev->ddr_paddr), GFP_KERNEL | GFP_DMA);
if (!gdev->ddr_vaddr) {
index d5fe08cc5db7ec83efbfcb2b8b13d6094c2bf986..83d5312aa9abf9f60eb9351c523b2d833686c021 100644 (file)
{
struct snd_dma_buffer *buf = &substream->dma_buffer;
struct snd_dma_buffer *iram_dma = NULL;
- dma_addr_t iram_phys = 0;
+ phys_addr_t iram_phys;
void *iram_virt = NULL;
if (buf->private_data || !size)
return 0;
ppcm->period_bytes_max = size;
- iram_virt = sram_alloc(size, &iram_phys);
+ iram_virt = (void *)gen_pool_alloc(davinci_gen_pool, size);
if (!iram_virt)
goto exit1;
+ iram_phys = gen_pool_virt_to_phys(davinci_gen_pool,
+ (unsigned long)iram_virt);
iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL);
if (!iram_dma)
goto exit2;
return 0;
exit2:
if (iram_virt)
- sram_free(iram_virt, size);
+ gen_pool_free(davinci_gen_pool, (unsigned long)iram_virt, size);
exit1:
return -ENOMEM;
}
buf->area = NULL;
iram_dma = buf->private_data;
if (iram_dma) {
- sram_free(iram_dma->area, iram_dma->bytes);
+ gen_pool_free(davinci_gen_pool,
+ (unsigned long)iram_dma->area, iram_dma->bytes);
kfree(iram_dma);
}
}