[OpenBIOS] [PATCH] OBP Memory allocation
Mark Cave-Ayland
mark.cave-ayland at ilande.co.uk
Mon Feb 10 02:36:22 CET 2014
On 09/02/14 22:59, Olivier Danet wrote:
> When called with a null base address, char *obp_memalloc(va,size,align)
> shall
> provide the address itself.
>
> (and remove some trailing whitespaces)
>
> Signed-off-by : Olivier Danet <odanet at caramail.com>
>
> Index: arch/sparc32/lib.c
> ===================================================================
> --- arch/sparc32/lib.c (révision 1257)
> +++ arch/sparc32/lib.c (copie de travail)
> @@ -212,13 +212,19 @@
> phys_addr_t phys;
> ucell virt;
>
> - DPRINTF("obp_memalloc: virta 0x%x, sz %d, align %d\n", (unsigned
> int)va, size, align);
> -
> + DPRINTF("obp_memalloc: virta 0x%x, sz %d, align %d\n", (unsigned
> int)va, size, align);
> +
> + /* Round to page size */
> + size = (size + 0xfff) & 0xFFFFF000;
> +
> /* Claim physical memory */
> phys = ofmem_claim_phys(-1, size, align);
>
> /* Claim virtual memory */
> - virt = ofmem_claim_virt(pointer2cell(va), size, 0);
> + if (va)
> + virt = ofmem_claim_virt(pointer2cell(va), size, 0);
> + else
> + virt = ofmem_claim_virt(0, size, 0x1000);
>
> /* Map the memory */
> ofmem_map(phys, virt, size, ofmem_arch_default_translation_mode(phys));
Hmmmm this doesn't look right at all. The obp_memalloc() function takes
3 parameters: va, size and align which should correspond with the
equivalent parameters for the claim word.
The key here is the align parameter; if align == 0 then va is assumed to
be valid, and the memory is allocated at the given address. If align !=
0 then va is ignored, and OFMEM will follow the specification and return
the next available memory region from the pool with an alignment
specified by align.
You'll need to check this using a gdb breakpoint against your NextSTEP
image, however what you should see is that align should always be != 0
when va == 0 and so OFMEM will follow the specification and ignore va.
If this is not the case then NextSTEP is doing something very strange...
ATB,
Mark.
More information about the OpenBIOS
mailing list