mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-16 09:54:35 +00:00

The current LMB API's for allocating and reserving memory use a per-caller based memory view. Memory allocated by a caller can then be overwritten by another caller. Make these allocations and reservations persistent using the alloced list data structure. Two alloced lists are declared -- one for the available(free) memory, and one for the used memory. Once full, the list can then be extended at runtime. [sjg: Use a stack to store pointer of lmb struct when running lmb tests] Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Signed-off-by: Simon Glass <sjg@chromium.org> [sjg: Optimise the logic to add a region in lmb_add_region_flags()]
65 lines
1.3 KiB
C
65 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright (C) 2021 Mark Kettenis <kettenis@openbsd.org>
|
|
*/
|
|
|
|
#include <dm.h>
|
|
#include <iommu.h>
|
|
#include <lmb.h>
|
|
#include <asm/io.h>
|
|
#include <linux/sizes.h>
|
|
|
|
#define IOMMU_PAGE_SIZE SZ_4K
|
|
|
|
static dma_addr_t sandbox_iommu_map(struct udevice *dev, void *addr,
|
|
size_t size)
|
|
{
|
|
phys_addr_t paddr, dva;
|
|
phys_size_t psize, off;
|
|
|
|
paddr = ALIGN_DOWN(virt_to_phys(addr), IOMMU_PAGE_SIZE);
|
|
off = virt_to_phys(addr) - paddr;
|
|
psize = ALIGN(size + off, IOMMU_PAGE_SIZE);
|
|
|
|
dva = lmb_alloc(psize, IOMMU_PAGE_SIZE);
|
|
|
|
return dva + off;
|
|
}
|
|
|
|
static void sandbox_iommu_unmap(struct udevice *dev, dma_addr_t addr,
|
|
size_t size)
|
|
{
|
|
phys_addr_t dva;
|
|
phys_size_t psize;
|
|
|
|
dva = ALIGN_DOWN(addr, IOMMU_PAGE_SIZE);
|
|
psize = size + (addr - dva);
|
|
psize = ALIGN(psize, IOMMU_PAGE_SIZE);
|
|
|
|
lmb_free(dva, psize);
|
|
}
|
|
|
|
static struct iommu_ops sandbox_iommu_ops = {
|
|
.map = sandbox_iommu_map,
|
|
.unmap = sandbox_iommu_unmap,
|
|
};
|
|
|
|
static int sandbox_iommu_probe(struct udevice *dev)
|
|
{
|
|
lmb_add(0x89abc000, SZ_16K);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct udevice_id sandbox_iommu_ids[] = {
|
|
{ .compatible = "sandbox,iommu" },
|
|
{ /* sentinel */ }
|
|
};
|
|
|
|
U_BOOT_DRIVER(sandbox_iommu) = {
|
|
.name = "sandbox_iommu",
|
|
.id = UCLASS_IOMMU,
|
|
.of_match = sandbox_iommu_ids,
|
|
.ops = &sandbox_iommu_ops,
|
|
.probe = sandbox_iommu_probe,
|
|
};
|