qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [Qemu-ppc] [PATCH 1/2] memory: Add MemoryRegion get add


From: Scott Wood
Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH 1/2] memory: Add MemoryRegion get address space offset helper function
Date: Fri, 5 Sep 2014 10:31:47 -0500

On Wed, 2014-09-03 at 14:36 -0400, Bogdan Purcareata wrote:
> Adding this function would allow a MemoryRegion to compute its start address
> within the AddressSpace. This is done recursively based on mr->container.
> 
> Signed-off-by: Bogdan Purcareata <address@hidden>
> ---
>  include/exec/memory.h |    8 ++++++++
>  memory.c              |   10 ++++++++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index d165b27..7503819 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -444,6 +444,14 @@ struct Object *memory_region_owner(MemoryRegion *mr);
>  uint64_t memory_region_size(MemoryRegion *mr);
>  
>  /**
> + * memory_region_get_address_space_offset: get a memory region's address
> + * within the address space
> + *
> + * @mr: the memory region being queried.
> + */
> +hwaddr memory_region_get_address_space_offset(MemoryRegion *mr);

Hmm, this seems familiar:
http://patchwork.ozlabs.org/patch/220385/
http://patchwork.ozlabs.org/patch/236764/

:-)

> +
> +/**
>   * memory_region_is_ram: check whether a memory region is random access
>   *
>   * Returns %true is a memory region is random access.
> diff --git a/memory.c b/memory.c
> index ef0be1c..7445032 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1307,6 +1307,16 @@ uint64_t memory_region_size(MemoryRegion *mr)
>      return int128_get64(mr->size);
>  }
>  
> +hwaddr memory_region_get_address_space_offset(MemoryRegion *mr)
> +{
> +    MemoryRegion *p;
> +    hwaddr result = 0x0;
> +
> +    for (p = mr; p != NULL; result += p->addr, p = p->container);
> +
> +    return result;
> +}

This would be more readable as:

        while (mr) {
                result += mr->addr;
                mr = mr->container;
        }

-Scott





reply via email to

[Prev in Thread] Current Thread [Next in Thread]