/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
/*
 * Copyright (c) 2020 MediaTek Inc.
 */
#ifndef __MTK_IOMMU_CMA_DMAHEAP_H__
#define __MTK_IOMMU_CMA_DMAHEAP_H__

#include <linux/cma.h>
#include "cma.h"

#define MAX_IOMMU_HEAP_CMA_AREAS 4
#define IOMMU_HEAP_CMA_ALIGN	SZ_512K

static inline bool cma_range(struct cma *cma_area, struct page *page)
{
	unsigned long pfn = page_to_pfn(page);

	if (!cma_area)
		return false;

	if (pfn >= cma_area->base_pfn
		&& pfn < (cma_area->base_pfn + cma_area->count))
		return true;

	return false;
}

int mtk_cma_dmaheap_create(void);
void mtk_cma_dmaheap_destroy(void);

#endif
