It appears that Solaris assumes that the resulting memory is physically aligned based upon the value of size. Make sure we also respect this alignment, so that memory allocated using this interface can be correctly used for the Solaris IOMMU page tables.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk --- openbios-devel/arch/sparc32/lib.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/openbios-devel/arch/sparc32/lib.c b/openbios-devel/arch/sparc32/lib.c index 5b41dff..0219a19 100644 --- a/openbios-devel/arch/sparc32/lib.c +++ b/openbios-devel/arch/sparc32/lib.c @@ -351,9 +351,19 @@ char *obp_dumb_memalloc(char *va, unsigned int size) { phys_addr_t phys; ucell virt; - + unsigned int align; + + /* Solaris seems to assume that the returned value is physically aligned to size. For + example, not having this here causes the Solaris 8 kernel to fault because the + IOMMU page table base address is calculated incorrectly. */ + + /* Enforce a minimum alignment of CONFIG_OFMEM_MALLOC_ALIGN, and also ensure that + only the MSB is set for the alignment value. This prevents spurious + "bad alignment" warnings from OFMEM when running with CONFIG_DEBUG_OFMEM. */ + align = (size + CONFIG_OFMEM_MALLOC_ALIGN - 1) & ~(size - 1); + /* Claim physical memory */ - phys = ofmem_claim_phys(-1, size, CONFIG_OFMEM_MALLOC_ALIGN); + phys = ofmem_claim_phys(-1, size, align);
/* Claim virtual memory */ virt = ofmem_claim_virt(pointer2cell(va), size, 0);
On Mon, Apr 4, 2011 at 10:44 PM, Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk wrote:
It appears that Solaris assumes that the resulting memory is physically aligned based upon the value of size. Make sure we also respect this alignment, so that memory allocated using this interface can be correctly used for the Solaris IOMMU page tables.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@siriusit.co.uk
openbios-devel/arch/sparc32/lib.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/openbios-devel/arch/sparc32/lib.c b/openbios-devel/arch/sparc32/lib.c index 5b41dff..0219a19 100644 --- a/openbios-devel/arch/sparc32/lib.c +++ b/openbios-devel/arch/sparc32/lib.c @@ -351,9 +351,19 @@ char *obp_dumb_memalloc(char *va, unsigned int size) { phys_addr_t phys; ucell virt;
- unsigned int align;
- /* Solaris seems to assume that the returned value is physically aligned to size. For
- example, not having this here causes the Solaris 8 kernel to fault because the
- IOMMU page table base address is calculated incorrectly. */
Awesome work!
- /* Enforce a minimum alignment of CONFIG_OFMEM_MALLOC_ALIGN, and also ensure that
- only the MSB is set for the alignment value. This prevents spurious
- "bad alignment" warnings from OFMEM when running with CONFIG_DEBUG_OFMEM. */
- align = (size + CONFIG_OFMEM_MALLOC_ALIGN - 1) & ~(size - 1);
What happens if size is not a power of 2?
On 04/04/11 22:15, Blue Swirl wrote:
- /* Enforce a minimum alignment of CONFIG_OFMEM_MALLOC_ALIGN, and also ensure that
only the MSB is set for the alignment value. This prevents spurious
"bad alignment" warnings from OFMEM when running with CONFIG_DEBUG_OFMEM. */
- align = (size + CONFIG_OFMEM_MALLOC_ALIGN - 1)& ~(size - 1);
What happens if size is not a power of 2?
Hmmmm that's a good point actually. I've just done a quick test of a revised patch that uses the standard bit-rotation algorithm to round up to the next power of 2, and that seems to work in the same way while making things more robust. Patch to follow shortly.
ATB,
Mark.