481 } |
481 } |
482 |
482 |
483 TInt MmuBase::AllocPhysicalRam(TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign) |
483 TInt MmuBase::AllocPhysicalRam(TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign) |
484 { |
484 { |
485 __KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocPhysicalRam() size=%x align=%d",aSize,aAlign)); |
485 __KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocPhysicalRam() size=%x align=%d",aSize,aAlign)); |
486 TInt r=AllocContiguousRam(aSize, aPhysAddr, EPageFixed, aAlign); |
486 TInt r=AllocContiguousRam(aSize, aPhysAddr, aAlign); |
487 if (r!=KErrNone) |
487 if (r!=KErrNone) |
488 { |
488 { |
489 iAllocFailed=ETrue; |
489 iAllocFailed=ETrue; |
490 return r; |
490 return r; |
491 } |
491 } |
514 size of the RAM zone or KErrNoMemory when the RAM zone is too full. |
514 size of the RAM zone or KErrNoMemory when the RAM zone is too full. |
515 */ |
515 */ |
516 TInt MmuBase::ZoneAllocPhysicalRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign) |
516 TInt MmuBase::ZoneAllocPhysicalRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign) |
517 { |
517 { |
518 __KTRACE_OPT(KMMU,Kern::Printf("Mmu::ZoneAllocPhysicalRam() size=0x%x align=%d", aSize, aAlign)); |
518 __KTRACE_OPT(KMMU,Kern::Printf("Mmu::ZoneAllocPhysicalRam() size=0x%x align=%d", aSize, aAlign)); |
519 TInt r = ZoneAllocContiguousRam(aZoneIdList, aZoneIdCount, aSize, aPhysAddr, EPageFixed, aAlign); |
519 TInt r = ZoneAllocContiguousRam(aZoneIdList, aZoneIdCount, aSize, aPhysAddr, aAlign); |
520 if (r!=KErrNone) |
520 if (r!=KErrNone) |
521 { |
521 { |
522 iAllocFailed=ETrue; |
522 iAllocFailed=ETrue; |
523 return r; |
523 return r; |
524 } |
524 } |
723 missing = iRamPageAllocator->AllocRamPages(aPageList, aNumPages, aPageType, aBlockedZoneId, aBlockRest); |
723 missing = iRamPageAllocator->AllocRamPages(aPageList, aNumPages, aPageType, aBlockedZoneId, aBlockRest); |
724 return missing ? KErrNoMemory : KErrNone; |
724 return missing ? KErrNoMemory : KErrNone; |
725 } |
725 } |
726 |
726 |
727 |
727 |
728 TInt MmuBase::AllocContiguousRam(TInt aSize, TPhysAddr& aPhysAddr, TZonePageType aPageType, TInt aAlign, TUint aBlockedZoneId, TBool aBlockRest) |
728 TInt MmuBase::AllocContiguousRam(TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign) |
729 { |
729 { |
730 #ifdef _DEBUG |
730 #ifdef _DEBUG |
731 if(K::CheckForSimulatedAllocFail()) |
731 if(K::CheckForSimulatedAllocFail()) |
732 return KErrNoMemory; |
732 return KErrNoMemory; |
733 #endif |
733 #endif |
734 __NK_ASSERT_DEBUG(aPageType == EPageFixed); |
|
735 TUint contigPages = (aSize + KPageSize - 1) >> KPageShift; |
734 TUint contigPages = (aSize + KPageSize - 1) >> KPageShift; |
736 TInt r = iRamPageAllocator->AllocContiguousRam(contigPages, aPhysAddr, aPageType, aAlign, aBlockedZoneId, aBlockRest); |
735 TInt r = iRamPageAllocator->AllocContiguousRam(contigPages, aPhysAddr, aAlign); |
737 if (r == KErrNoMemory && contigPages > KMaxFreeableContiguousPages) |
736 if (r == KErrNoMemory && contigPages > KMaxFreeableContiguousPages) |
738 {// Allocation failed but as this is a large allocation flush the RAM cache |
737 {// Allocation failed but as this is a large allocation flush the RAM cache |
739 // and reattempt the allocation as large allocation wouldn't discard pages. |
738 // and reattempt the allocation as large allocation wouldn't discard pages. |
740 iRamCache->FlushAll(); |
739 iRamCache->FlushAll(); |
741 r = iRamPageAllocator->AllocContiguousRam(contigPages, aPhysAddr, aPageType, aAlign, aBlockedZoneId, aBlockRest); |
740 r = iRamPageAllocator->AllocContiguousRam(contigPages, aPhysAddr, aAlign); |
742 } |
741 } |
743 return r; |
742 return r; |
744 } |
743 } |
745 |
744 |
746 |
745 |
748 Allocate contiguous RAM from the specified RAM zones. |
747 Allocate contiguous RAM from the specified RAM zones. |
749 @param aZoneIdList An array of IDs of the RAM zones to allocate from |
748 @param aZoneIdList An array of IDs of the RAM zones to allocate from |
750 @param aZoneIdCount The number of IDs listed in aZoneIdList |
749 @param aZoneIdCount The number of IDs listed in aZoneIdList |
751 @param aSize The number of bytes to allocate |
750 @param aSize The number of bytes to allocate |
752 @param aPhysAddr Will receive the physical base address of the allocated RAM |
751 @param aPhysAddr Will receive the physical base address of the allocated RAM |
753 @param aPageType The type of the pages being allocated |
|
754 @param aAlign The log base 2 alginment required |
752 @param aAlign The log base 2 alginment required |
755 */ |
753 */ |
756 TInt MmuBase::ZoneAllocContiguousRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aSize, TPhysAddr& aPhysAddr, TZonePageType aPageType, TInt aAlign) |
754 TInt MmuBase::ZoneAllocContiguousRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign) |
757 { |
755 { |
758 #ifdef _DEBUG |
756 #ifdef _DEBUG |
759 if(K::CheckForSimulatedAllocFail()) |
757 if(K::CheckForSimulatedAllocFail()) |
760 return KErrNoMemory; |
758 return KErrNoMemory; |
761 #endif |
759 #endif |
762 return iRamPageAllocator->ZoneAllocContiguousRam(aZoneIdList, aZoneIdCount, aSize, aPhysAddr, aPageType, aAlign); |
760 return iRamPageAllocator->ZoneAllocContiguousRam(aZoneIdList, aZoneIdCount, aSize, aPhysAddr, aAlign); |
763 } |
761 } |
764 |
762 |
765 SPageInfo* SPageInfo::SafeFromPhysAddr(TPhysAddr aAddress) |
763 SPageInfo* SPageInfo::SafeFromPhysAddr(TPhysAddr aAddress) |
766 { |
764 { |
767 TUint index = aAddress>>(KPageShift+KPageShift-KPageInfoShift); |
765 TUint index = aAddress>>(KPageShift+KPageShift-KPageInfoShift); |