From: Tim Deegan Subject: Re: [PATCH 04/16] arm: handle xenheap which isn't at the start of RAM. Date: Thu, 6 Sep 2012 12:36:01 +0100 Message-ID: <20120906113601.GD56463@ocelot.phlegethon.org> References: <1346678886.32462.9.camel@zakaz.uk.xensource.com> <1346679056-8108-4-git-send-email-ian.campbell@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1346679056-8108-4-git-send-email-ian.campbell@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org At 13:30 +0000 on 03 Sep (1346679044), Ian Campbell wrote: > Also refactor page_to_virt somewhat in an attempt to make it clearer > what is happening. > > Signed-off-by: Ian Campbell > --- > xen/include/asm-arm/mm.h | 24 +++++++++++++++++++----- > 1 files changed, 19 insertions(+), 5 deletions(-) > > diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h > index b37bd35..6498322 100644 > --- a/xen/include/asm-arm/mm.h > +++ b/xen/include/asm-arm/mm.h > @@ -214,17 +214,31 @@ static inline struct page_info *virt_to_page(const void *v) > ASSERT(va >= XENHEAP_VIRT_START); > ASSERT(va < xenheap_virt_end); > > - return frame_table + ((va - XENHEAP_VIRT_START) >> PAGE_SHIFT); > + return frame_table > + + ((va - XENHEAP_VIRT_START) >> PAGE_SHIFT) > + + xenheap_mfn_start > + - frametable_base_mfn; > } > > static inline void *page_to_virt(const struct page_info *pg) > { > + unsigned long va; > + const unsigned long offset = > + (xenheap_mfn_start-frametable_base_mfn)*sizeof(*pg); > + > + /* > + * Dividing by this on both top and bottom factors out the largest > + * common factor of 2 which helps the compiler to use smaller shifts. > + */ > + const unsigned long lcd = (sizeof(*pg) & -sizeof(*pg)); > + > ASSERT((unsigned long)pg - FRAMETABLE_VIRT_START < frametable_virt_end); > - return (void *)(XENHEAP_VIRT_START + > - ((unsigned long)pg - FRAMETABLE_VIRT_START) / > - (sizeof(*pg) / (sizeof(*pg) & -sizeof(*pg))) * > - (PAGE_SIZE / (sizeof(*pg) & -sizeof(*pg)))); > > + va = (unsigned long)pg; > + va = XENHEAP_VIRT_START + > + ((va - FRAMETABLE_VIRT_START - offset) / (sizeof(*pg) / lcd)) * > + (PAGE_SIZE / lcd); > + return (void *)va; This function is getting a bit too confusing. I think we should just use page_to_mfn and mfn_to_virt instead: the magic lcd trick eliminates a shift but having to construct "offset" to match it adds one. Tim.