From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Grall Subject: Re: [PATCH ARM v6 08/14] mini-os: arm: memory management Date: Mon, 21 Jul 2014 18:36:07 +0100 Message-ID: <53CD4F87.6060206@linaro.org> References: <1405508874-3921-1-git-send-email-talex5@gmail.com> <1405508874-3921-9-git-send-email-talex5@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X9HVW-0003pi-BR for xen-devel@lists.xenproject.org; Mon, 21 Jul 2014 17:36:14 +0000 Received: by mail-wg0-f49.google.com with SMTP id k14so6732092wgh.20 for ; Mon, 21 Jul 2014 10:36:12 -0700 (PDT) In-Reply-To: <1405508874-3921-9-git-send-email-talex5@gmail.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: Thomas Leonard , xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, stefano.stabellini@eu.citrix.com, Dave.Scott@eu.citrix.com, anil@recoil.org List-Id: xen-devel@lists.xenproject.org Hi Thomas, On 07/16/2014 12:07 PM, Thomas Leonard wrote: > Based on an initial patch by Karim Raslan. > > Signed-off-by: Karim Allah Ahmed > Signed-off-by: Thomas Leonard > > --- > > Changes since v5: > > - Require only minimum property lengths (requested by Ian Campbell). > > Addressed Julien Grall's comments: > - Added comments explaining the lengths when checking FDT properties. > - Use paddr_t type to represent physical addresses. > --- > extras/mini-os/arch/arm/mm.c | 138 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 138 insertions(+) > create mode 100644 extras/mini-os/arch/arm/mm.c > > diff --git a/extras/mini-os/arch/arm/mm.c b/extras/mini-os/arch/arm/mm.c > new file mode 100644 > index 0000000..ec1f821 > --- /dev/null > +++ b/extras/mini-os/arch/arm/mm.c > @@ -0,0 +1,138 @@ > +#include > +#include > +#include > +#include > +#include > +#include > + > +int physical_address_offset; int64_t maybe? > + > +unsigned long allocate_ondemand(unsigned long n, unsigned long alignment) > +{ > + // FIXME > + BUG(); > +} > + > +void arch_init_mm(unsigned long *start_pfn_p, unsigned long *max_pfn_p) > +{ [..] > + unsigned int end = (unsigned int) &_end; > + paddr_t mem_base = fdt64_to_cpu(regs[0]); > + unsigned int mem_size = fdt64_to_cpu(regs[1]); mem_size should be a paddr_t. Even though, the first bank will always have the size fit in 32 bits. > + printk("Found memory at %p (len 0x%x)\n", mem_base, mem_size); > + > + BUG_ON(to_virt(mem_base) > (void *) &_text); /* Our image isn't in our RAM! */ > + *start_pfn_p = PFN_UP(to_phys(end)); > + int heap_len = mem_size - (PFN_PHYS(*start_pfn_p) - mem_base); You need to use at least an unsigned int here. And it will be better if you use paddr_t. > + *max_pfn_p = *start_pfn_p + PFN_DOWN(heap_len); > + > + printk("Using pages %d to %d as free space for heap.\n", *start_pfn_p, *max_pfn_p); > + > + /* The device tree is probably in memory that we're about to hand over to the page > + * allocator, so move it to the end and reserve that space. > + */ > + int fdt_size = fdt_totalsize(device_tree); uint32_t has the definition of the field totalsize in the fdt structure. Regards, -- Julien Grall