On Tue, 26 Nov 2019 at 13:04, Leif Lindholm <leif.lindh...@linaro.org> wrote: > > On Tue, Nov 26, 2019 at 00:12:41 +0100, Ard Biesheuvel wrote: > > Implement support for driving peripherals with limited DMA ranges to > > NonCoherentDmaLib, by adding a device address limit, and taking it, > > along with the device offset, into account when allocating or mapping > > DMA buffers. > > > > Signed-off-by: Ard Biesheuvel <ard.biesheu...@linaro.org> > > --- > > EmbeddedPkg/EmbeddedPkg.dec | 6 + > > EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.c | 165 > > ++++++++++++++++++-- > > EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf | 1 + > > 3 files changed, 160 insertions(+), 12 deletions(-) > > > > diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec > > index 8812a6db7c30..69922802f473 100644 > > --- a/EmbeddedPkg/EmbeddedPkg.dec > > +++ b/EmbeddedPkg/EmbeddedPkg.dec > > @@ -186,6 +186,12 @@ [PcdsFixedAtBuild.common, PcdsDynamic.common] > > # > > gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset|0x0|UINT64|0x0000058 > > > > + # > > + # Highest address value supported by the device for DMA addressing. Note > > + # that this value should be strictly greater than PcdDmaDeviceOffset. > > + # > > + > > gEmbeddedTokenSpaceGuid.PcdDmaDeviceLimit|0xFFFFFFFFFFFFFFFF|UINT64|0x000005A > > + > > # > > # Selection between DT and ACPI as a default > > # > > diff --git a/EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.c > > b/EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.c > > index 78220f6358aa..115345765435 100644 > > --- a/EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.c > > +++ b/EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.c > > @@ -40,6 +40,8 @@ typedef struct { > > STATIC EFI_CPU_ARCH_PROTOCOL *mCpu; > > STATIC LIST_ENTRY UncachedAllocationList; > > > > +STATIC PHYSICAL_ADDRESS mDmaHostAddressLimit; > > + > > STATIC > > PHYSICAL_ADDRESS > > HostToDeviceAddress ( > > @@ -49,6 +51,102 @@ HostToDeviceAddress ( > > return (PHYSICAL_ADDRESS)(UINTN)Address + PcdGet64 (PcdDmaDeviceOffset); > > } > > > > +/** > > + Allocates one or more 4KB pages of a certain memory type at a specified > > + alignment. > > + > > + Allocates the number of 4KB pages specified by Pages of a certain memory > > type > > + with an alignment specified by Alignment. The allocated buffer is > > returned. > > + If Pages is 0, then NULL is returned. If there is not enough memory at > > the > > + specified alignment remaining to satisfy the request, then NULL is > > returned. > > + If Alignment is not a power of two and Alignment is not zero, then > > ASSERT(). > > + If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT(). > > + > > + @param MemoryType The type of memory to allocate. > > + @param Pages The number of 4 KB pages to allocate. > > + @param Alignment The requested alignment of the allocation. > > + Must be a power of two. > > + If Alignment is zero, then byte alignment > > is > > + used. > > + > > + @return A pointer to the allocated buffer or NULL if allocation fails. > > + > > +**/ > > +STATIC > > +VOID * > > +InternalAllocateAlignedPages ( > > + IN EFI_MEMORY_TYPE MemoryType, > > + IN UINTN Pages, > > + IN UINTN Alignment > > + ) > > +{ > > + EFI_STATUS Status; > > + EFI_PHYSICAL_ADDRESS Memory; > > + UINTN AlignedMemory; > > + UINTN AlignmentMask; > > + UINTN UnalignedPages; > > + UINTN RealPages; > > + > > + // > > + // Alignment must be a power of two or zero. > > + // > > + ASSERT ((Alignment & (Alignment - 1)) == 0); > > Sorry, slight mental glitch (and I realise this is in copied code) - > the above also matches for an Alignment of 1, which contradicts the > comment. Clearly requesting allocation explicitly aligned to 1 is a) > silly, b) the same as what happens for any value <= EFI_PAGE_SIZE > in the below code, and c) harmless, but could you update the comment? > > If so: > Acked-by: Leif Lindholm <leif.lindh...@linaro.org> >
Given that 1 == 2^0, it is also a power of 2, and so the comment is accurate imho -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#51280): https://edk2.groups.io/g/devel/message/51280 Mute This Topic: https://groups.io/mt/61950463/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-