From patchwork Thu Oct 14 09:21:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 252701 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9E9KQZa016719 for ; Thu, 14 Oct 2010 09:20:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755239Ab0JNJTh (ORCPT ); Thu, 14 Oct 2010 05:19:37 -0400 Received: from mail-pw0-f46.google.com ([209.85.160.46]:59485 "EHLO mail-pw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755278Ab0JNJTf (ORCPT ); Thu, 14 Oct 2010 05:19:35 -0400 Received: by pwi4 with SMTP id 4so50484pwi.19 for ; Thu, 14 Oct 2010 02:19:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:date:message-id :subject; bh=GVqH120aapy8SJYO4Py30/JiaHtjowxb8Ai1b6gOfp8=; b=UNIvfOGYaQjqsoXMGbSMCeUA6qgx6EHmLIVif/Wl/1rSUgFotHRQcCbeJ7pJGl0HCr +z+ojRnPh8du4hgGoKv/rCvrZOc3DI47T1NrpuokZH+Y2HXLtOSm0oqwWlXrt7xudu+O GOxJ0bqm/8kIj4jKCklRpOkqRxW3mw1bsC+sw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:date:message-id:subject; b=dAbtcAOxUSJVt/Q15Q+pgMzLaHpaEkqs6eEs/wvD/P19rSCdhUWijbsdT/TUU+Zsks wyIk85s2RQBtTg0rjnkXWEIw5BRW0Q/0IDZI+vDrdPGtXooIl8EZkeJUfO91U0dhMOvr 3oEQBLduiPDSxULjVpU/93ItSmxxUhE8FX9yw= Received: by 10.142.148.10 with SMTP id v10mr8485886wfd.428.1287047975237; Thu, 14 Oct 2010 02:19:35 -0700 (PDT) Received: from [127.0.0.1] (49.14.32.202.bf.2iij.net [202.32.14.49]) by mx.google.com with ESMTPS id y42sm7018126wfd.10.2010.10.14.02.19.33 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 14 Oct 2010 02:19:34 -0700 (PDT) From: Magnus Damm To: linux-sh@vger.kernel.org Cc: Magnus Damm , lethal@linux-sh.org Date: Thu, 14 Oct 2010 18:21:52 +0900 Message-Id: <20101014092152.2046.29572.sendpatchset@t400s> Subject: [PATCH] ARM: mach-shmobile: Add memchunk support V2 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Thu, 14 Oct 2010 09:20:27 +0000 (UTC) --- 0008/arch/arm/mach-shmobile/Makefile +++ work/arch/arm/mach-shmobile/Makefile 2010-10-14 17:44:33.000000000 +0900 @@ -4,6 +4,7 @@ # Common objects obj-y := timer.o console.o clock.o pm_runtime.o +obj-y += memchunk.o # CPU objects obj-$(CONFIG_ARCH_AP45) += head-ap45.o --- 0001/arch/arm/mach-shmobile/include/mach/common.h +++ work/arch/arm/mach-shmobile/include/mach/common.h 2010-10-14 17:53:04.000000000 +0900 @@ -3,6 +3,9 @@ extern struct sys_timer shmobile_timer; extern void shmobile_setup_console(void); +struct platform_device; +extern int shmobile_memchunk_setup(struct platform_device *pdev, + char *name, unsigned long memsize); struct clk; extern int clk_init(void); --- /dev/null +++ work/arch/arm/mach-shmobile/memchunk.c 2010-10-14 17:53:22.000000000 +0900 @@ -0,0 +1,76 @@ +/* + * SH-Mobile "memchunk" - Physically contiguous memory reservation code + * + * Copyright (C) 2010 Magnus Damm + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#include +#include +#include +#include + +static int __init memchunk_setup(char *str) +{ + return 1; /* accept anything that begins with "memchunk." */ +} +__setup("memchunk.", memchunk_setup); + +static void __init memchunk_cmdline_override(char *name, unsigned long *sizep) +{ + 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; + } + } +} + +int __init shmobile_memchunk_setup(struct platform_device *pdev, + char *name, unsigned long memsize) +{ + struct resource *r; + u64 addr; + + r = pdev->resource + pdev->num_resources - 1; + if (r->flags) { + pr_warning("%s: unable to find empty space for resource\n", + name); + return -EINVAL; + } + + memchunk_cmdline_override(name, &memsize); + if (!memsize) + return 0; + + addr = memblock_alloc(memsize, PAGE_SIZE); + if (addr == ~(u64)0) { + pr_warning("%s: unable to allocate memory\n", name); + return -ENOMEM; + } + + r->flags = IORESOURCE_MEM; + r->start = addr; + r->end = r->start + memsize - 1; + r->name = name; + return 0; +}