From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O6lpw-0004Gs-Rn for qemu-devel@nongnu.org; Tue, 27 Apr 2010 10:32:32 -0400 Received: from [140.186.70.92] (port=50023 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O6lpv-0004Fn-8u for qemu-devel@nongnu.org; Tue, 27 Apr 2010 10:32:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O6lpt-0007HS-Kg for qemu-devel@nongnu.org; Tue, 27 Apr 2010 10:32:31 -0400 Received: from mail-qy0-f188.google.com ([209.85.221.188]:35350) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O6lps-0007H9-R8 for qemu-devel@nongnu.org; Tue, 27 Apr 2010 10:32:29 -0400 Received: by qyk26 with SMTP id 26so7077303qyk.19 for ; Tue, 27 Apr 2010 07:32:28 -0700 (PDT) MIME-Version: 1.0 Sender: camm@ualberta.ca In-Reply-To: <2e085c19aac78e6c4335eac4fffeb5cfca4bbb26.1272304746.git.mtosatti@redhat.com> References: <2e085c19aac78e6c4335eac4fffeb5cfca4bbb26.1272304746.git.mtosatti@redhat.com> Date: Tue, 27 Apr 2010 08:32:27 -0600 Message-ID: From: Cam Macdonell Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Re: [PATCH 10/10] introduce qemu_ram_map List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Marcelo Tosatti Cc: Anthony Liguori , qemu-devel@nongnu.org, kvm@vger.kernel.org On Mon, Apr 26, 2010 at 11:59 AM, Marcelo Tosatti wro= te: > Which allows drivers to register an mmaped region into ram block mappings= . > To be used by device assignment driver. > > CC: Cam Macdonell > Signed-off-by: Marcelo Tosatti > --- > =A0cpu-common.h | =A0 =A01 + > =A0exec.c =A0 =A0 =A0 | =A0 28 ++++++++++++++++++++++++++++ > =A02 files changed, 29 insertions(+), 0 deletions(-) > > 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, > =A0} > > =A0ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr); > +ram_addr_t qemu_ram_map(ram_addr_t size, void *host); > =A0ram_addr_t qemu_ram_alloc(ram_addr_t); > =A0void qemu_ram_free(ram_addr_t addr); > =A0/* This should only be used for ram local to a device. =A0*/ > 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, con= st char *path) > =A0} > =A0#endif > > +ram_addr_t qemu_ram_map(ram_addr_t size, void *host) > +{ > + =A0 =A0RAMBlock *new_block; > + > + =A0 =A0size =3D TARGET_PAGE_ALIGN(size); > + =A0 =A0new_block =3D qemu_malloc(sizeof(*new_block)); > + > + =A0 =A0new_block->host =3D host; > + > + =A0 =A0new_block->offset =3D last_ram_offset; > + =A0 =A0new_block->length =3D size; > + > + =A0 =A0new_block->next =3D ram_blocks; > + =A0 =A0ram_blocks =3D new_block; > + > + =A0 =A0phys_ram_dirty =3D qemu_realloc(phys_ram_dirty, > + =A0 =A0 =A0 =A0(last_ram_offset + size) >> TARGET_PAGE_BITS); > + =A0 =A0memset(phys_ram_dirty + (last_ram_offset >> TARGET_PAGE_BITS), > + =A0 =A0 =A0 =A0 =A0 0xff, size >> TARGET_PAGE_BITS); > + > + =A0 =A0last_ram_offset +=3D size; > + > + =A0 =A0if (kvm_enabled()) > + =A0 =A0 =A0 =A0kvm_setup_guest_memory(new_block->host, size); > + > + =A0 =A0return new_block->offset; > +} > + > =A0ram_addr_t qemu_ram_alloc(ram_addr_t size) > =A0{ > =A0 =A0 RAMBlock *new_block; > -- > 1.6.6.1 > Sorry for being late to reply, is there a strong reason not to have the function handle the mmap itself? As As Anthony points out, that way we don't have worry about realloc changing the pointer in the function.