2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-11-11 16:07:06 +08:00
|
|
|
* Copyright (C) 2004 - 2007 Paul Mundt
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
#include <linux/mm.h>
|
2009-04-14 14:22:15 +08:00
|
|
|
#include <linux/init.h>
|
2008-07-16 18:02:54 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
2009-04-14 14:22:15 +08:00
|
|
|
#include <linux/io.h>
|
2008-07-16 18:02:54 +08:00
|
|
|
|
2008-08-11 14:13:24 +08:00
|
|
|
static int __init memchunk_setup(char *str)
|
|
|
|
{
|
|
|
|
return 1; /* accept anything that begins with "memchunk." */
|
|
|
|
}
|
|
|
|
__setup("memchunk.", memchunk_setup);
|
|
|
|
|
2008-08-27 17:21:29 +08:00
|
|
|
static void __init memchunk_cmdline_override(char *name, unsigned long *sizep)
|
2008-08-11 14:13:24 +08:00
|
|
|
{
|
|
|
|
char *p = boot_command_line;
|
|
|
|
int k = strlen(name);
|
|
|
|
|
|
|
|
while ((p = strstr(p, "memchunk."))) {
|
|
|
|
p += 9; /* strlen("memchunk.") */
|
|
|
|
if (!strncmp(name, p, k) && p[k] == '=') {
|
|
|
|
p += k + 1;
|
|
|
|
*sizep = memparse(p, NULL);
|
|
|
|
pr_info("%s: forcing memory chunk size to 0x%08lx\n",
|
|
|
|
name, *sizep);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-27 17:21:29 +08:00
|
|
|
int __init platform_resource_setup_memory(struct platform_device *pdev,
|
|
|
|
char *name, unsigned long memsize)
|
2008-07-16 18:02:54 +08:00
|
|
|
{
|
|
|
|
struct resource *r;
|
|
|
|
dma_addr_t dma_handle;
|
|
|
|
void *buf;
|
|
|
|
|
|
|
|
r = pdev->resource + pdev->num_resources - 1;
|
|
|
|
if (r->flags) {
|
2019-10-18 11:18:22 +08:00
|
|
|
pr_warn("%s: unable to find empty space for resource\n", name);
|
2008-07-16 18:02:54 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-08-11 14:13:24 +08:00
|
|
|
memchunk_cmdline_override(name, &memsize);
|
|
|
|
if (!memsize)
|
|
|
|
return 0;
|
|
|
|
|
2018-04-18 17:42:35 +08:00
|
|
|
buf = dma_alloc_coherent(&pdev->dev, memsize, &dma_handle, GFP_KERNEL);
|
2008-07-16 18:02:54 +08:00
|
|
|
if (!buf) {
|
2019-10-18 11:18:22 +08:00
|
|
|
pr_warn("%s: unable to allocate memory\n", name);
|
2008-07-16 18:02:54 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(buf, 0, memsize);
|
|
|
|
|
|
|
|
r->flags = IORESOURCE_MEM;
|
|
|
|
r->start = dma_handle;
|
|
|
|
r->end = r->start + memsize - 1;
|
|
|
|
r->name = name;
|
|
|
|
return 0;
|
|
|
|
}
|