From patchwork Mon Mar 21 17:47:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 709 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:45:03 -0000 Delivered-To: patches@linaro.org Received: by 10.220.28.198 with SMTP id n6cs145667vcc; Mon, 21 Mar 2011 10:47:27 -0700 (PDT) Received: by 10.236.181.138 with SMTP id l10mr5671200yhm.290.1300729646709; Mon, 21 Mar 2011 10:47:26 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk [81.2.115.146]) by mx.google.com with ESMTPS id f9si13957695yhc.199.2011.03.21.10.47.24 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 21 Mar 2011 10:47:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1Q1jCK-0001fr-OI; Mon, 21 Mar 2011 17:47:20 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH 1/2] Allow boards to specify maximum RAM size Date: Mon, 21 Mar 2011 17:47:19 +0000 Message-Id: <1300729640-6410-2-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1300729640-6410-1-git-send-email-peter.maydell@linaro.org> References: <1300729640-6410-1-git-send-email-peter.maydell@linaro.org> Allow boards to specify their maximum RAM size in the QEMUMachine struct. This allows us to provide a useful diagnostic if the user tries to specify a RAM size that the board cannot support. Signed-off-by: Peter Maydell --- hw/boards.h | 1 + vl.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletions(-) diff --git a/hw/boards.h b/hw/boards.h index 6f0f0d7..bf63f8d 100644 --- a/hw/boards.h +++ b/hw/boards.h @@ -19,6 +19,7 @@ typedef struct QEMUMachine { QEMUMachineInitFunc *init; int use_scsi; int max_cpus; + ram_addr_t max_ram; unsigned int no_serial:1, no_parallel:1, use_virtcon:1, diff --git a/vl.c b/vl.c index b1a94aa..971ad90 100644 --- a/vl.c +++ b/vl.c @@ -166,6 +166,9 @@ int main(int argc, char **argv) //#define DEBUG_NET //#define DEBUG_SLIRP +/* Note that this default RAM size is capped to any maximum + * RAM size specified in the board's QEMUMachine struct. + */ #define DEFAULT_RAM_SIZE 128 #define MAX_VIRTIO_CONSOLES 1 @@ -2910,8 +2913,19 @@ int main(int argc, char **argv, char **envp) exit(1); /* init the memory */ - if (ram_size == 0) + if (ram_size == 0) { ram_size = DEFAULT_RAM_SIZE * 1024 * 1024; + if (machine->max_ram) { + ram_size = MIN(ram_size, machine->max_ram); + } + } else if (machine->max_ram && ram_size > machine->max_ram) { + /* Since you can only specify ram_size on the command line in MB it's + * OK to round down when printing the machine's maximum. + */ + fprintf(stderr, "qemu: maximum permitted RAM size for '%s' is %ldM\n", + machine->name, (machine->max_ram / (1024 * 1024))); + exit(1); + } /* init the dynamic translator */ cpu_exec_init_all(tb_size * 1024 * 1024);