From patchwork Mon Apr 26 17:59:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 95115 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3QI1XHZ020936 for ; Mon, 26 Apr 2010 18:01:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754123Ab0DZSAp (ORCPT ); Mon, 26 Apr 2010 14:00:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62398 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751786Ab0DZSAi (ORCPT ); Mon, 26 Apr 2010 14:00:38 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3QI0ZGJ022028 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 26 Apr 2010 14:00:35 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3QI0YnF026605; Mon, 26 Apr 2010 14:00:34 -0400 Received: from amt.cnet (vpn-8-113.rdu.redhat.com [10.11.8.113]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o3QI0XTi006759; Mon, 26 Apr 2010 14:00:34 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id D3763656072; Mon, 26 Apr 2010 15:00:23 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o3QI0KCV023729; Mon, 26 Apr 2010 15:00:20 -0300 From: Marcelo Tosatti To: Anthony Liguori Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Marcelo Tosatti , Cam Macdonell Subject: [PATCH 10/10] introduce qemu_ram_map Date: Mon, 26 Apr 2010 14:59:06 -0300 Message-Id: <2e085c19aac78e6c4335eac4fffeb5cfca4bbb26.1272304746.git.mtosatti@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 26 Apr 2010 18:01:39 +0000 (UTC) diff --git a/cpu-common.h b/cpu-common.h index b24cecc..2dfde6f 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -40,6 +40,7 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, } ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr); +ram_addr_t qemu_ram_map(ram_addr_t size, void *host); ram_addr_t qemu_ram_alloc(ram_addr_t); void qemu_ram_free(ram_addr_t addr); /* This should only be used for ram local to a device. */ diff --git a/exec.c b/exec.c index 14d1fd7..648a9c9 100644 --- a/exec.c +++ b/exec.c @@ -2789,6 +2789,34 @@ static void *file_ram_alloc(ram_addr_t memory, const char *path) } #endif +ram_addr_t qemu_ram_map(ram_addr_t size, void *host) +{ + RAMBlock *new_block; + + size = TARGET_PAGE_ALIGN(size); + new_block = qemu_malloc(sizeof(*new_block)); + + new_block->host = host; + + new_block->offset = last_ram_offset; + new_block->length = size; + + new_block->next = ram_blocks; + ram_blocks = new_block; + + phys_ram_dirty = qemu_realloc(phys_ram_dirty, + (last_ram_offset + size) >> TARGET_PAGE_BITS); + memset(phys_ram_dirty + (last_ram_offset >> TARGET_PAGE_BITS), + 0xff, size >> TARGET_PAGE_BITS); + + last_ram_offset += size; + + if (kvm_enabled()) + kvm_setup_guest_memory(new_block->host, size); + + return new_block->offset; +} + ram_addr_t qemu_ram_alloc(ram_addr_t size) { RAMBlock *new_block;