2019-06-03 07:44:50 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2013-11-16 12:56:06 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Red Hat
|
|
|
|
* Author: Rob Clark <robdclark@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MSM_MMU_H__
|
|
|
|
#define __MSM_MMU_H__
|
|
|
|
|
|
|
|
#include <linux/iommu.h>
|
|
|
|
|
|
|
|
struct msm_mmu_funcs {
|
2019-09-16 14:11:54 -06:00
|
|
|
void (*detach)(struct msm_mmu *mmu);
|
2016-11-11 12:06:46 -05:00
|
|
|
int (*map)(struct msm_mmu *mmu, uint64_t iova, struct sg_table *sgt,
|
2020-05-22 16:03:16 -06:00
|
|
|
size_t len, int prot);
|
|
|
|
int (*unmap)(struct msm_mmu *mmu, uint64_t iova, size_t len);
|
2013-11-16 12:56:06 -05:00
|
|
|
void (*destroy)(struct msm_mmu *mmu);
|
|
|
|
};
|
|
|
|
|
2020-08-17 15:01:39 -07:00
|
|
|
enum msm_mmu_type {
|
|
|
|
MSM_MMU_GPUMMU,
|
|
|
|
MSM_MMU_IOMMU,
|
|
|
|
MSM_MMU_IOMMU_PAGETABLE,
|
|
|
|
};
|
|
|
|
|
2013-11-16 12:56:06 -05:00
|
|
|
struct msm_mmu {
|
|
|
|
const struct msm_mmu_funcs *funcs;
|
2014-07-09 22:08:15 -04:00
|
|
|
struct device *dev;
|
2016-12-07 11:13:53 -05:00
|
|
|
int (*handler)(void *arg, unsigned long iova, int flags);
|
|
|
|
void *arg;
|
2020-08-17 15:01:39 -07:00
|
|
|
enum msm_mmu_type type;
|
2013-11-16 12:56:06 -05:00
|
|
|
};
|
|
|
|
|
2014-07-09 22:08:15 -04:00
|
|
|
static inline void msm_mmu_init(struct msm_mmu *mmu, struct device *dev,
|
2020-08-17 15:01:39 -07:00
|
|
|
const struct msm_mmu_funcs *funcs, enum msm_mmu_type type)
|
2013-11-16 12:56:06 -05:00
|
|
|
{
|
|
|
|
mmu->dev = dev;
|
|
|
|
mmu->funcs = funcs;
|
2020-08-17 15:01:39 -07:00
|
|
|
mmu->type = type;
|
2013-11-16 12:56:06 -05:00
|
|
|
}
|
|
|
|
|
2014-07-09 22:08:15 -04:00
|
|
|
struct msm_mmu *msm_iommu_new(struct device *dev, struct iommu_domain *domain);
|
|
|
|
struct msm_mmu *msm_gpummu_new(struct device *dev, struct msm_gpu *gpu);
|
2013-11-16 12:56:06 -05:00
|
|
|
|
2016-12-07 11:13:53 -05:00
|
|
|
static inline void msm_mmu_set_fault_handler(struct msm_mmu *mmu, void *arg,
|
|
|
|
int (*handler)(void *arg, unsigned long iova, int flags))
|
|
|
|
{
|
|
|
|
mmu->arg = arg;
|
|
|
|
mmu->handler = handler;
|
|
|
|
}
|
|
|
|
|
2020-08-17 15:01:39 -07:00
|
|
|
struct msm_mmu *msm_iommu_pagetable_create(struct msm_mmu *parent);
|
|
|
|
|
2018-11-14 17:08:04 -05:00
|
|
|
void msm_gpummu_params(struct msm_mmu *mmu, dma_addr_t *pt_base,
|
|
|
|
dma_addr_t *tran_error);
|
|
|
|
|
2020-08-17 15:01:39 -07:00
|
|
|
|
|
|
|
int msm_iommu_pagetable_params(struct msm_mmu *mmu, phys_addr_t *ttbr,
|
|
|
|
int *asid);
|
|
|
|
|
2013-11-16 12:56:06 -05:00
|
|
|
#endif /* __MSM_MMU_H__ */
|