mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (33 commits) iommu/core: Remove global iommu_ops and register_iommu iommu/msm: Use bus_set_iommu instead of register_iommu iommu/omap: Use bus_set_iommu instead of register_iommu iommu/vt-d: Use bus_set_iommu instead of register_iommu iommu/amd: Use bus_set_iommu instead of register_iommu iommu/core: Use bus->iommu_ops in the iommu-api iommu/core: Convert iommu_found to iommu_present iommu/core: Add bus_type parameter to iommu_domain_alloc Driver core: Add iommu_ops to bus_type iommu/core: Define iommu_ops and register_iommu only with CONFIG_IOMMU_API iommu/amd: Fix wrong shift direction iommu/omap: always provide iommu debug code iommu/core: let drivers know if an iommu fault handler isn't installed iommu/core: export iommu_set_fault_handler() iommu/omap: Fix build error with !IOMMU_SUPPORT iommu/omap: Migrate to the generic fault report mechanism iommu/core: Add fault reporting mechanism iommu/core: Use PAGE_SIZE instead of hard-coded value iommu/core: use the existing IS_ALIGNED macro iommu/msm: ->unmap() should return order of unmapped page ... Fixup trivial conflicts in drivers/iommu/Makefile: "move omap iommu to dedicated iommu folder" vs "Rename the DMAR and INTR_REMAP config options" just happened to touch lines next to each other.
This commit is contained in:
commit
0cfdc72439
28 changed files with 869 additions and 647 deletions
|
|
@ -66,7 +66,7 @@
|
|||
((pgsz) == MMU_CAM_PGSZ_4K) ? 0xfffff000 : 0)
|
||||
|
||||
|
||||
static void __iommu_set_twl(struct iommu *obj, bool on)
|
||||
static void __iommu_set_twl(struct omap_iommu *obj, bool on)
|
||||
{
|
||||
u32 l = iommu_read_reg(obj, MMU_CNTL);
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ static void __iommu_set_twl(struct iommu *obj, bool on)
|
|||
}
|
||||
|
||||
|
||||
static int omap2_iommu_enable(struct iommu *obj)
|
||||
static int omap2_iommu_enable(struct omap_iommu *obj)
|
||||
{
|
||||
u32 l, pa;
|
||||
unsigned long timeout;
|
||||
|
|
@ -127,7 +127,7 @@ static int omap2_iommu_enable(struct iommu *obj)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void omap2_iommu_disable(struct iommu *obj)
|
||||
static void omap2_iommu_disable(struct omap_iommu *obj)
|
||||
{
|
||||
u32 l = iommu_read_reg(obj, MMU_CNTL);
|
||||
|
||||
|
|
@ -138,12 +138,12 @@ static void omap2_iommu_disable(struct iommu *obj)
|
|||
dev_dbg(obj->dev, "%s is shutting down\n", obj->name);
|
||||
}
|
||||
|
||||
static void omap2_iommu_set_twl(struct iommu *obj, bool on)
|
||||
static void omap2_iommu_set_twl(struct omap_iommu *obj, bool on)
|
||||
{
|
||||
__iommu_set_twl(obj, false);
|
||||
}
|
||||
|
||||
static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra)
|
||||
static u32 omap2_iommu_fault_isr(struct omap_iommu *obj, u32 *ra)
|
||||
{
|
||||
u32 stat, da;
|
||||
u32 errs = 0;
|
||||
|
|
@ -173,13 +173,13 @@ static u32 omap2_iommu_fault_isr(struct iommu *obj, u32 *ra)
|
|||
return errs;
|
||||
}
|
||||
|
||||
static void omap2_tlb_read_cr(struct iommu *obj, struct cr_regs *cr)
|
||||
static void omap2_tlb_read_cr(struct omap_iommu *obj, struct cr_regs *cr)
|
||||
{
|
||||
cr->cam = iommu_read_reg(obj, MMU_READ_CAM);
|
||||
cr->ram = iommu_read_reg(obj, MMU_READ_RAM);
|
||||
}
|
||||
|
||||
static void omap2_tlb_load_cr(struct iommu *obj, struct cr_regs *cr)
|
||||
static void omap2_tlb_load_cr(struct omap_iommu *obj, struct cr_regs *cr)
|
||||
{
|
||||
iommu_write_reg(obj, cr->cam | MMU_CAM_V, MMU_CAM);
|
||||
iommu_write_reg(obj, cr->ram, MMU_RAM);
|
||||
|
|
@ -193,7 +193,8 @@ static u32 omap2_cr_to_virt(struct cr_regs *cr)
|
|||
return cr->cam & mask;
|
||||
}
|
||||
|
||||
static struct cr_regs *omap2_alloc_cr(struct iommu *obj, struct iotlb_entry *e)
|
||||
static struct cr_regs *omap2_alloc_cr(struct omap_iommu *obj,
|
||||
struct iotlb_entry *e)
|
||||
{
|
||||
struct cr_regs *cr;
|
||||
|
||||
|
|
@ -230,7 +231,8 @@ static u32 omap2_get_pte_attr(struct iotlb_entry *e)
|
|||
return attr;
|
||||
}
|
||||
|
||||
static ssize_t omap2_dump_cr(struct iommu *obj, struct cr_regs *cr, char *buf)
|
||||
static ssize_t
|
||||
omap2_dump_cr(struct omap_iommu *obj, struct cr_regs *cr, char *buf)
|
||||
{
|
||||
char *p = buf;
|
||||
|
||||
|
|
@ -254,7 +256,8 @@ static ssize_t omap2_dump_cr(struct iommu *obj, struct cr_regs *cr, char *buf)
|
|||
goto out; \
|
||||
} while (0)
|
||||
|
||||
static ssize_t omap2_iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t len)
|
||||
static ssize_t
|
||||
omap2_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len)
|
||||
{
|
||||
char *p = buf;
|
||||
|
||||
|
|
@ -280,7 +283,7 @@ out:
|
|||
return p - buf;
|
||||
}
|
||||
|
||||
static void omap2_iommu_save_ctx(struct iommu *obj)
|
||||
static void omap2_iommu_save_ctx(struct omap_iommu *obj)
|
||||
{
|
||||
int i;
|
||||
u32 *p = obj->ctx;
|
||||
|
|
@ -293,7 +296,7 @@ static void omap2_iommu_save_ctx(struct iommu *obj)
|
|||
BUG_ON(p[0] != IOMMU_ARCH_VERSION);
|
||||
}
|
||||
|
||||
static void omap2_iommu_restore_ctx(struct iommu *obj)
|
||||
static void omap2_iommu_restore_ctx(struct omap_iommu *obj)
|
||||
{
|
||||
int i;
|
||||
u32 *p = obj->ctx;
|
||||
|
|
@ -343,13 +346,13 @@ static const struct iommu_functions omap2_iommu_ops = {
|
|||
|
||||
static int __init omap2_iommu_init(void)
|
||||
{
|
||||
return install_iommu_arch(&omap2_iommu_ops);
|
||||
return omap_install_iommu_arch(&omap2_iommu_ops);
|
||||
}
|
||||
module_init(omap2_iommu_init);
|
||||
|
||||
static void __exit omap2_iommu_exit(void)
|
||||
{
|
||||
uninstall_iommu_arch(&omap2_iommu_ops);
|
||||
omap_uninstall_iommu_arch(&omap2_iommu_ops);
|
||||
}
|
||||
module_exit(omap2_iommu_exit);
|
||||
|
||||
|
|
|
|||
|
|
@ -134,18 +134,6 @@ config OMAP_MBOX_KFIFO_SIZE
|
|||
This can also be changed at runtime (via the mbox_kfifo_size
|
||||
module parameter).
|
||||
|
||||
config OMAP_IOMMU
|
||||
tristate
|
||||
|
||||
config OMAP_IOMMU_DEBUG
|
||||
tristate "Export OMAP IOMMU internals in DebugFS"
|
||||
depends on OMAP_IOMMU && DEBUG_FS
|
||||
help
|
||||
Select this to see extensive information about
|
||||
the internal state of OMAP IOMMU in debugfs.
|
||||
|
||||
Say N unless you know you need this.
|
||||
|
||||
config OMAP_IOMMU_IVA2
|
||||
bool
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ obj-$(CONFIG_ARCH_OMAP3) += omap_device.o
|
|||
obj-$(CONFIG_ARCH_OMAP4) += omap_device.o
|
||||
|
||||
obj-$(CONFIG_OMAP_MCBSP) += mcbsp.o
|
||||
obj-$(CONFIG_OMAP_IOMMU) += iommu.o iovmm.o
|
||||
obj-$(CONFIG_OMAP_IOMMU_DEBUG) += iommu-debug.o
|
||||
|
||||
obj-$(CONFIG_CPU_FREQ) += cpu-omap.o
|
||||
obj-$(CONFIG_OMAP_DM_TIMER) += dmtimer.o
|
||||
|
|
|
|||
|
|
@ -25,16 +25,17 @@ struct iotlb_entry {
|
|||
};
|
||||
};
|
||||
|
||||
struct iommu {
|
||||
struct omap_iommu {
|
||||
const char *name;
|
||||
struct module *owner;
|
||||
struct clk *clk;
|
||||
void __iomem *regbase;
|
||||
struct device *dev;
|
||||
void *isr_priv;
|
||||
struct iommu_domain *domain;
|
||||
|
||||
unsigned int refcount;
|
||||
struct mutex iommu_lock; /* global for this whole object */
|
||||
spinlock_t iommu_lock; /* global for this whole object */
|
||||
|
||||
/*
|
||||
* We don't change iopgd for a situation like pgd for a task,
|
||||
|
|
@ -48,8 +49,6 @@ struct iommu {
|
|||
struct list_head mmap;
|
||||
struct mutex mmap_lock; /* protect mmap */
|
||||
|
||||
int (*isr)(struct iommu *obj, u32 da, u32 iommu_errs, void *priv);
|
||||
|
||||
void *ctx; /* iommu context: registres saved area */
|
||||
u32 da_start;
|
||||
u32 da_end;
|
||||
|
|
@ -81,25 +80,27 @@ struct iotlb_lock {
|
|||
struct iommu_functions {
|
||||
unsigned long version;
|
||||
|
||||
int (*enable)(struct iommu *obj);
|
||||
void (*disable)(struct iommu *obj);
|
||||
void (*set_twl)(struct iommu *obj, bool on);
|
||||
u32 (*fault_isr)(struct iommu *obj, u32 *ra);
|
||||
int (*enable)(struct omap_iommu *obj);
|
||||
void (*disable)(struct omap_iommu *obj);
|
||||
void (*set_twl)(struct omap_iommu *obj, bool on);
|
||||
u32 (*fault_isr)(struct omap_iommu *obj, u32 *ra);
|
||||
|
||||
void (*tlb_read_cr)(struct iommu *obj, struct cr_regs *cr);
|
||||
void (*tlb_load_cr)(struct iommu *obj, struct cr_regs *cr);
|
||||
void (*tlb_read_cr)(struct omap_iommu *obj, struct cr_regs *cr);
|
||||
void (*tlb_load_cr)(struct omap_iommu *obj, struct cr_regs *cr);
|
||||
|
||||
struct cr_regs *(*alloc_cr)(struct iommu *obj, struct iotlb_entry *e);
|
||||
struct cr_regs *(*alloc_cr)(struct omap_iommu *obj,
|
||||
struct iotlb_entry *e);
|
||||
int (*cr_valid)(struct cr_regs *cr);
|
||||
u32 (*cr_to_virt)(struct cr_regs *cr);
|
||||
void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e);
|
||||
ssize_t (*dump_cr)(struct iommu *obj, struct cr_regs *cr, char *buf);
|
||||
ssize_t (*dump_cr)(struct omap_iommu *obj, struct cr_regs *cr,
|
||||
char *buf);
|
||||
|
||||
u32 (*get_pte_attr)(struct iotlb_entry *e);
|
||||
|
||||
void (*save_ctx)(struct iommu *obj);
|
||||
void (*restore_ctx)(struct iommu *obj);
|
||||
ssize_t (*dump_ctx)(struct iommu *obj, char *buf, ssize_t len);
|
||||
void (*save_ctx)(struct omap_iommu *obj);
|
||||
void (*restore_ctx)(struct omap_iommu *obj);
|
||||
ssize_t (*dump_ctx)(struct omap_iommu *obj, char *buf, ssize_t len);
|
||||
};
|
||||
|
||||
struct iommu_platform_data {
|
||||
|
|
@ -150,40 +151,31 @@ struct iommu_platform_data {
|
|||
/*
|
||||
* global functions
|
||||
*/
|
||||
extern u32 iommu_arch_version(void);
|
||||
extern u32 omap_iommu_arch_version(void);
|
||||
|
||||
extern void iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
|
||||
extern u32 iotlb_cr_to_virt(struct cr_regs *cr);
|
||||
extern void omap_iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e);
|
||||
|
||||
extern int load_iotlb_entry(struct iommu *obj, struct iotlb_entry *e);
|
||||
extern void iommu_set_twl(struct iommu *obj, bool on);
|
||||
extern void flush_iotlb_page(struct iommu *obj, u32 da);
|
||||
extern void flush_iotlb_range(struct iommu *obj, u32 start, u32 end);
|
||||
extern void flush_iotlb_all(struct iommu *obj);
|
||||
extern int
|
||||
omap_iopgtable_store_entry(struct omap_iommu *obj, struct iotlb_entry *e);
|
||||
|
||||
extern int iopgtable_store_entry(struct iommu *obj, struct iotlb_entry *e);
|
||||
extern void iopgtable_lookup_entry(struct iommu *obj, u32 da, u32 **ppgd,
|
||||
u32 **ppte);
|
||||
extern size_t iopgtable_clear_entry(struct iommu *obj, u32 iova);
|
||||
|
||||
extern int iommu_set_da_range(struct iommu *obj, u32 start, u32 end);
|
||||
extern struct iommu *iommu_get(const char *name);
|
||||
extern void iommu_put(struct iommu *obj);
|
||||
extern int iommu_set_isr(const char *name,
|
||||
int (*isr)(struct iommu *obj, u32 da, u32 iommu_errs,
|
||||
extern int omap_iommu_set_isr(const char *name,
|
||||
int (*isr)(struct omap_iommu *obj, u32 da, u32 iommu_errs,
|
||||
void *priv),
|
||||
void *isr_priv);
|
||||
|
||||
extern void iommu_save_ctx(struct iommu *obj);
|
||||
extern void iommu_restore_ctx(struct iommu *obj);
|
||||
extern void omap_iommu_save_ctx(struct omap_iommu *obj);
|
||||
extern void omap_iommu_restore_ctx(struct omap_iommu *obj);
|
||||
|
||||
extern int install_iommu_arch(const struct iommu_functions *ops);
|
||||
extern void uninstall_iommu_arch(const struct iommu_functions *ops);
|
||||
extern int omap_install_iommu_arch(const struct iommu_functions *ops);
|
||||
extern void omap_uninstall_iommu_arch(const struct iommu_functions *ops);
|
||||
|
||||
extern int foreach_iommu_device(void *data,
|
||||
extern int omap_foreach_iommu_device(void *data,
|
||||
int (*fn)(struct device *, void *));
|
||||
|
||||
extern ssize_t iommu_dump_ctx(struct iommu *obj, char *buf, ssize_t len);
|
||||
extern size_t dump_tlb_entries(struct iommu *obj, char *buf, ssize_t len);
|
||||
extern ssize_t
|
||||
omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len);
|
||||
extern size_t
|
||||
omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t len);
|
||||
struct device *omap_find_iommu_device(const char *name);
|
||||
|
||||
#endif /* __MACH_IOMMU_H */
|
||||
|
|
|
|||
|
|
@ -83,12 +83,12 @@
|
|||
/*
|
||||
* register accessors
|
||||
*/
|
||||
static inline u32 iommu_read_reg(struct iommu *obj, size_t offs)
|
||||
static inline u32 iommu_read_reg(struct omap_iommu *obj, size_t offs)
|
||||
{
|
||||
return __raw_readl(obj->regbase + offs);
|
||||
}
|
||||
|
||||
static inline void iommu_write_reg(struct iommu *obj, u32 val, size_t offs)
|
||||
static inline void iommu_write_reg(struct omap_iommu *obj, u32 val, size_t offs)
|
||||
{
|
||||
__raw_writel(val, obj->regbase + offs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,19 @@
|
|||
|
||||
#define IOPAGE_MASK IOPTE_MASK
|
||||
|
||||
/**
|
||||
* omap_iommu_translate() - va to pa translation
|
||||
* @d: omap iommu descriptor
|
||||
* @va: virtual address
|
||||
* @mask: omap iommu descriptor mask
|
||||
*
|
||||
* va to pa translation
|
||||
*/
|
||||
static inline phys_addr_t omap_iommu_translate(u32 d, u32 va, u32 mask)
|
||||
{
|
||||
return (d & mask) | (va & (~mask));
|
||||
}
|
||||
|
||||
/*
|
||||
* some descriptor attributes.
|
||||
*/
|
||||
|
|
@ -64,10 +77,15 @@
|
|||
#define IOPGD_SUPER (1 << 18 | 2 << 0)
|
||||
|
||||
#define iopgd_is_table(x) (((x) & 3) == IOPGD_TABLE)
|
||||
#define iopgd_is_section(x) (((x) & (1 << 18 | 3)) == IOPGD_SECTION)
|
||||
#define iopgd_is_super(x) (((x) & (1 << 18 | 3)) == IOPGD_SUPER)
|
||||
|
||||
#define IOPTE_SMALL (2 << 0)
|
||||
#define IOPTE_LARGE (1 << 0)
|
||||
|
||||
#define iopte_is_small(x) (((x) & 2) == IOPTE_SMALL)
|
||||
#define iopte_is_large(x) (((x) & 3) == IOPTE_LARGE)
|
||||
|
||||
/* to find an entry in a page-table-directory */
|
||||
#define iopgd_index(da) (((da) >> IOPGD_SHIFT) & (PTRS_PER_IOPGD - 1))
|
||||
#define iopgd_offset(obj, da) ((obj)->iopgd + iopgd_index(da))
|
||||
|
|
@ -97,6 +115,6 @@ static inline u32 iotlb_init_entry(struct iotlb_entry *e, u32 da, u32 pa,
|
|||
}
|
||||
|
||||
#define to_iommu(dev) \
|
||||
(struct iommu *)platform_get_drvdata(to_platform_device(dev))
|
||||
(struct omap_iommu *)platform_get_drvdata(to_platform_device(dev))
|
||||
|
||||
#endif /* __PLAT_OMAP_IOMMU_H */
|
||||
|
|
@ -13,8 +13,10 @@
|
|||
#ifndef __IOMMU_MMAP_H
|
||||
#define __IOMMU_MMAP_H
|
||||
|
||||
#include <linux/iommu.h>
|
||||
|
||||
struct iovm_struct {
|
||||
struct iommu *iommu; /* iommu object which this belongs to */
|
||||
struct omap_iommu *iommu; /* iommu object which this belongs to */
|
||||
u32 da_start; /* area definition */
|
||||
u32 da_end;
|
||||
u32 flags; /* IOVMF_: see below */
|
||||
|
|
@ -70,20 +72,18 @@ struct iovm_struct {
|
|||
#define IOVMF_DA_FIXED (1 << (4 + IOVMF_SW_SHIFT))
|
||||
|
||||
|
||||
extern struct iovm_struct *find_iovm_area(struct iommu *obj, u32 da);
|
||||
extern u32 iommu_vmap(struct iommu *obj, u32 da,
|
||||
extern struct iovm_struct *omap_find_iovm_area(struct omap_iommu *obj, u32 da);
|
||||
extern u32
|
||||
omap_iommu_vmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da,
|
||||
const struct sg_table *sgt, u32 flags);
|
||||
extern struct sg_table *iommu_vunmap(struct iommu *obj, u32 da);
|
||||
extern u32 iommu_vmalloc(struct iommu *obj, u32 da, size_t bytes,
|
||||
u32 flags);
|
||||
extern void iommu_vfree(struct iommu *obj, const u32 da);
|
||||
extern u32 iommu_kmap(struct iommu *obj, u32 da, u32 pa, size_t bytes,
|
||||
u32 flags);
|
||||
extern void iommu_kunmap(struct iommu *obj, u32 da);
|
||||
extern u32 iommu_kmalloc(struct iommu *obj, u32 da, size_t bytes,
|
||||
u32 flags);
|
||||
extern void iommu_kfree(struct iommu *obj, u32 da);
|
||||
|
||||
extern void *da_to_va(struct iommu *obj, u32 da);
|
||||
extern struct sg_table *omap_iommu_vunmap(struct iommu_domain *domain,
|
||||
struct omap_iommu *obj, u32 da);
|
||||
extern u32
|
||||
omap_iommu_vmalloc(struct iommu_domain *domain, struct omap_iommu *obj,
|
||||
u32 da, size_t bytes, u32 flags);
|
||||
extern void
|
||||
omap_iommu_vfree(struct iommu_domain *domain, struct omap_iommu *obj,
|
||||
const u32 da);
|
||||
extern void *omap_da_to_va(struct omap_iommu *obj, u32 da);
|
||||
|
||||
#endif /* __IOMMU_MMAP_H */
|
||||
|
|
|
|||
|
|
@ -1,418 +0,0 @@
|
|||
/*
|
||||
* omap iommu: debugfs interface
|
||||
*
|
||||
* Copyright (C) 2008-2009 Nokia Corporation
|
||||
*
|
||||
* Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include <linux/err.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/debugfs.h>
|
||||
|
||||
#include <plat/iommu.h>
|
||||
#include <plat/iovmm.h>
|
||||
|
||||
#include "iopgtable.h"
|
||||
|
||||
#define MAXCOLUMN 100 /* for short messages */
|
||||
|
||||
static DEFINE_MUTEX(iommu_debug_lock);
|
||||
|
||||
static struct dentry *iommu_debug_root;
|
||||
|
||||
static ssize_t debug_read_ver(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
u32 ver = iommu_arch_version();
|
||||
char buf[MAXCOLUMN], *p = buf;
|
||||
|
||||
p += sprintf(p, "H/W version: %d.%d\n", (ver >> 4) & 0xf , ver & 0xf);
|
||||
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
|
||||
}
|
||||
|
||||
static ssize_t debug_read_regs(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct iommu *obj = file->private_data;
|
||||
char *p, *buf;
|
||||
ssize_t bytes;
|
||||
|
||||
buf = kmalloc(count, GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
p = buf;
|
||||
|
||||
mutex_lock(&iommu_debug_lock);
|
||||
|
||||
bytes = iommu_dump_ctx(obj, p, count);
|
||||
bytes = simple_read_from_buffer(userbuf, count, ppos, buf, bytes);
|
||||
|
||||
mutex_unlock(&iommu_debug_lock);
|
||||
kfree(buf);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static ssize_t debug_read_tlb(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct iommu *obj = file->private_data;
|
||||
char *p, *buf;
|
||||
ssize_t bytes, rest;
|
||||
|
||||
buf = kmalloc(count, GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
p = buf;
|
||||
|
||||
mutex_lock(&iommu_debug_lock);
|
||||
|
||||
p += sprintf(p, "%8s %8s\n", "cam:", "ram:");
|
||||
p += sprintf(p, "-----------------------------------------\n");
|
||||
rest = count - (p - buf);
|
||||
p += dump_tlb_entries(obj, p, rest);
|
||||
|
||||
bytes = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
|
||||
|
||||
mutex_unlock(&iommu_debug_lock);
|
||||
kfree(buf);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static ssize_t debug_write_pagetable(struct file *file,
|
||||
const char __user *userbuf, size_t count, loff_t *ppos)
|
||||
{
|
||||
struct iotlb_entry e;
|
||||
struct cr_regs cr;
|
||||
int err;
|
||||
struct iommu *obj = file->private_data;
|
||||
char buf[MAXCOLUMN], *p = buf;
|
||||
|
||||
count = min(count, sizeof(buf));
|
||||
|
||||
mutex_lock(&iommu_debug_lock);
|
||||
if (copy_from_user(p, userbuf, count)) {
|
||||
mutex_unlock(&iommu_debug_lock);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
sscanf(p, "%x %x", &cr.cam, &cr.ram);
|
||||
if (!cr.cam || !cr.ram) {
|
||||
mutex_unlock(&iommu_debug_lock);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
iotlb_cr_to_e(&cr, &e);
|
||||
err = iopgtable_store_entry(obj, &e);
|
||||
if (err)
|
||||
dev_err(obj->dev, "%s: fail to store cr\n", __func__);
|
||||
|
||||
mutex_unlock(&iommu_debug_lock);
|
||||
return count;
|
||||
}
|
||||
|
||||
#define dump_ioptable_entry_one(lv, da, val) \
|
||||
({ \
|
||||
int __err = 0; \
|
||||
ssize_t bytes; \
|
||||
const int maxcol = 22; \
|
||||
const char *str = "%d: %08x %08x\n"; \
|
||||
bytes = snprintf(p, maxcol, str, lv, da, val); \
|
||||
p += bytes; \
|
||||
len -= bytes; \
|
||||
if (len < maxcol) \
|
||||
__err = -ENOMEM; \
|
||||
__err; \
|
||||
})
|
||||
|
||||
static ssize_t dump_ioptable(struct iommu *obj, char *buf, ssize_t len)
|
||||
{
|
||||
int i;
|
||||
u32 *iopgd;
|
||||
char *p = buf;
|
||||
|
||||
spin_lock(&obj->page_table_lock);
|
||||
|
||||
iopgd = iopgd_offset(obj, 0);
|
||||
for (i = 0; i < PTRS_PER_IOPGD; i++, iopgd++) {
|
||||
int j, err;
|
||||
u32 *iopte;
|
||||
u32 da;
|
||||
|
||||
if (!*iopgd)
|
||||
continue;
|
||||
|
||||
if (!(*iopgd & IOPGD_TABLE)) {
|
||||
da = i << IOPGD_SHIFT;
|
||||
|
||||
err = dump_ioptable_entry_one(1, da, *iopgd);
|
||||
if (err)
|
||||
goto out;
|
||||
continue;
|
||||
}
|
||||
|
||||
iopte = iopte_offset(iopgd, 0);
|
||||
|
||||
for (j = 0; j < PTRS_PER_IOPTE; j++, iopte++) {
|
||||
if (!*iopte)
|
||||
continue;
|
||||
|
||||
da = (i << IOPGD_SHIFT) + (j << IOPTE_SHIFT);
|
||||
err = dump_ioptable_entry_one(2, da, *iopgd);
|
||||
if (err)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
out:
|
||||
spin_unlock(&obj->page_table_lock);
|
||||
|
||||
return p - buf;
|
||||
}
|
||||
|
||||
static ssize_t debug_read_pagetable(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct iommu *obj = file->private_data;
|
||||
char *p, *buf;
|
||||
size_t bytes;
|
||||
|
||||
buf = (char *)__get_free_page(GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
p = buf;
|
||||
|
||||
p += sprintf(p, "L: %8s %8s\n", "da:", "pa:");
|
||||
p += sprintf(p, "-----------------------------------------\n");
|
||||
|
||||
mutex_lock(&iommu_debug_lock);
|
||||
|
||||
bytes = PAGE_SIZE - (p - buf);
|
||||
p += dump_ioptable(obj, p, bytes);
|
||||
|
||||
bytes = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
|
||||
|
||||
mutex_unlock(&iommu_debug_lock);
|
||||
free_page((unsigned long)buf);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static ssize_t debug_read_mmap(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct iommu *obj = file->private_data;
|
||||
char *p, *buf;
|
||||
struct iovm_struct *tmp;
|
||||
int uninitialized_var(i);
|
||||
ssize_t bytes;
|
||||
|
||||
buf = (char *)__get_free_page(GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
p = buf;
|
||||
|
||||
p += sprintf(p, "%-3s %-8s %-8s %6s %8s\n",
|
||||
"No", "start", "end", "size", "flags");
|
||||
p += sprintf(p, "-------------------------------------------------\n");
|
||||
|
||||
mutex_lock(&iommu_debug_lock);
|
||||
|
||||
list_for_each_entry(tmp, &obj->mmap, list) {
|
||||
size_t len;
|
||||
const char *str = "%3d %08x-%08x %6x %8x\n";
|
||||
const int maxcol = 39;
|
||||
|
||||
len = tmp->da_end - tmp->da_start;
|
||||
p += snprintf(p, maxcol, str,
|
||||
i, tmp->da_start, tmp->da_end, len, tmp->flags);
|
||||
|
||||
if (PAGE_SIZE - (p - buf) < maxcol)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
||||
bytes = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
|
||||
|
||||
mutex_unlock(&iommu_debug_lock);
|
||||
free_page((unsigned long)buf);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static ssize_t debug_read_mem(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct iommu *obj = file->private_data;
|
||||
char *p, *buf;
|
||||
struct iovm_struct *area;
|
||||
ssize_t bytes;
|
||||
|
||||
count = min_t(ssize_t, count, PAGE_SIZE);
|
||||
|
||||
buf = (char *)__get_free_page(GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
p = buf;
|
||||
|
||||
mutex_lock(&iommu_debug_lock);
|
||||
|
||||
area = find_iovm_area(obj, (u32)ppos);
|
||||
if (IS_ERR(area)) {
|
||||
bytes = -EINVAL;
|
||||
goto err_out;
|
||||
}
|
||||
memcpy(p, area->va, count);
|
||||
p += count;
|
||||
|
||||
bytes = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
|
||||
err_out:
|
||||
mutex_unlock(&iommu_debug_lock);
|
||||
free_page((unsigned long)buf);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static ssize_t debug_write_mem(struct file *file, const char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct iommu *obj = file->private_data;
|
||||
struct iovm_struct *area;
|
||||
char *p, *buf;
|
||||
|
||||
count = min_t(size_t, count, PAGE_SIZE);
|
||||
|
||||
buf = (char *)__get_free_page(GFP_KERNEL);
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
p = buf;
|
||||
|
||||
mutex_lock(&iommu_debug_lock);
|
||||
|
||||
if (copy_from_user(p, userbuf, count)) {
|
||||
count = -EFAULT;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
area = find_iovm_area(obj, (u32)ppos);
|
||||
if (IS_ERR(area)) {
|
||||
count = -EINVAL;
|
||||
goto err_out;
|
||||
}
|
||||
memcpy(area->va, p, count);
|
||||
err_out:
|
||||
mutex_unlock(&iommu_debug_lock);
|
||||
free_page((unsigned long)buf);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int debug_open_generic(struct inode *inode, struct file *file)
|
||||
{
|
||||
file->private_data = inode->i_private;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define DEBUG_FOPS(name) \
|
||||
static const struct file_operations debug_##name##_fops = { \
|
||||
.open = debug_open_generic, \
|
||||
.read = debug_read_##name, \
|
||||
.write = debug_write_##name, \
|
||||
.llseek = generic_file_llseek, \
|
||||
};
|
||||
|
||||
#define DEBUG_FOPS_RO(name) \
|
||||
static const struct file_operations debug_##name##_fops = { \
|
||||
.open = debug_open_generic, \
|
||||
.read = debug_read_##name, \
|
||||
.llseek = generic_file_llseek, \
|
||||
};
|
||||
|
||||
DEBUG_FOPS_RO(ver);
|
||||
DEBUG_FOPS_RO(regs);
|
||||
DEBUG_FOPS_RO(tlb);
|
||||
DEBUG_FOPS(pagetable);
|
||||
DEBUG_FOPS_RO(mmap);
|
||||
DEBUG_FOPS(mem);
|
||||
|
||||
#define __DEBUG_ADD_FILE(attr, mode) \
|
||||
{ \
|
||||
struct dentry *dent; \
|
||||
dent = debugfs_create_file(#attr, mode, parent, \
|
||||
obj, &debug_##attr##_fops); \
|
||||
if (!dent) \
|
||||
return -ENOMEM; \
|
||||
}
|
||||
|
||||
#define DEBUG_ADD_FILE(name) __DEBUG_ADD_FILE(name, 600)
|
||||
#define DEBUG_ADD_FILE_RO(name) __DEBUG_ADD_FILE(name, 400)
|
||||
|
||||
static int iommu_debug_register(struct device *dev, void *data)
|
||||
{
|
||||
struct platform_device *pdev = to_platform_device(dev);
|
||||
struct iommu *obj = platform_get_drvdata(pdev);
|
||||
struct dentry *d, *parent;
|
||||
|
||||
if (!obj || !obj->dev)
|
||||
return -EINVAL;
|
||||
|
||||
d = debugfs_create_dir(obj->name, iommu_debug_root);
|
||||
if (!d)
|
||||
return -ENOMEM;
|
||||
parent = d;
|
||||
|
||||
d = debugfs_create_u8("nr_tlb_entries", 400, parent,
|
||||
(u8 *)&obj->nr_tlb_entries);
|
||||
if (!d)
|
||||
return -ENOMEM;
|
||||
|
||||
DEBUG_ADD_FILE_RO(ver);
|
||||
DEBUG_ADD_FILE_RO(regs);
|
||||
DEBUG_ADD_FILE_RO(tlb);
|
||||
DEBUG_ADD_FILE(pagetable);
|
||||
DEBUG_ADD_FILE_RO(mmap);
|
||||
DEBUG_ADD_FILE(mem);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __init iommu_debug_init(void)
|
||||
{
|
||||
struct dentry *d;
|
||||
int err;
|
||||
|
||||
d = debugfs_create_dir("iommu", NULL);
|
||||
if (!d)
|
||||
return -ENOMEM;
|
||||
iommu_debug_root = d;
|
||||
|
||||
err = foreach_iommu_device(d, iommu_debug_register);
|
||||
if (err)
|
||||
goto err_out;
|
||||
return 0;
|
||||
|
||||
err_out:
|
||||
debugfs_remove_recursive(iommu_debug_root);
|
||||
return err;
|
||||
}
|
||||
module_init(iommu_debug_init)
|
||||
|
||||
static void __exit iommu_debugfs_exit(void)
|
||||
{
|
||||
debugfs_remove_recursive(iommu_debug_root);
|
||||
}
|
||||
module_exit(iommu_debugfs_exit)
|
||||
|
||||
MODULE_DESCRIPTION("omap iommu: debugfs interface");
|
||||
MODULE_AUTHOR("Hiroshi DOYU <[email protected]>");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,904 +0,0 @@
|
|||
/*
|
||||
* omap iommu: simple virtual address space management
|
||||
*
|
||||
* Copyright (C) 2008-2009 Nokia Corporation
|
||||
*
|
||||
* Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include <linux/err.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/scatterlist.h>
|
||||
|
||||
#include <asm/cacheflush.h>
|
||||
#include <asm/mach/map.h>
|
||||
|
||||
#include <plat/iommu.h>
|
||||
#include <plat/iovmm.h>
|
||||
|
||||
#include "iopgtable.h"
|
||||
|
||||
/*
|
||||
* A device driver needs to create address mappings between:
|
||||
*
|
||||
* - iommu/device address
|
||||
* - physical address
|
||||
* - mpu virtual address
|
||||
*
|
||||
* There are 4 possible patterns for them:
|
||||
*
|
||||
* |iova/ mapping iommu_ page
|
||||
* | da pa va (d)-(p)-(v) function type
|
||||
* ---------------------------------------------------------------------------
|
||||
* 1 | c c c 1 - 1 - 1 _kmap() / _kunmap() s
|
||||
* 2 | c c,a c 1 - 1 - 1 _kmalloc()/ _kfree() s
|
||||
* 3 | c d c 1 - n - 1 _vmap() / _vunmap() s
|
||||
* 4 | c d,a c 1 - n - 1 _vmalloc()/ _vfree() n*
|
||||
*
|
||||
*
|
||||
* 'iova': device iommu virtual address
|
||||
* 'da': alias of 'iova'
|
||||
* 'pa': physical address
|
||||
* 'va': mpu virtual address
|
||||
*
|
||||
* 'c': contiguous memory area
|
||||
* 'd': discontiguous memory area
|
||||
* 'a': anonymous memory allocation
|
||||
* '()': optional feature
|
||||
*
|
||||
* 'n': a normal page(4KB) size is used.
|
||||
* 's': multiple iommu superpage(16MB, 1MB, 64KB, 4KB) size is used.
|
||||
*
|
||||
* '*': not yet, but feasible.
|
||||
*/
|
||||
|
||||
static struct kmem_cache *iovm_area_cachep;
|
||||
|
||||
/* return total bytes of sg buffers */
|
||||
static size_t sgtable_len(const struct sg_table *sgt)
|
||||
{
|
||||
unsigned int i, total = 0;
|
||||
struct scatterlist *sg;
|
||||
|
||||
if (!sgt)
|
||||
return 0;
|
||||
|
||||
for_each_sg(sgt->sgl, sg, sgt->nents, i) {
|
||||
size_t bytes;
|
||||
|
||||
bytes = sg->length;
|
||||
|
||||
if (!iopgsz_ok(bytes)) {
|
||||
pr_err("%s: sg[%d] not iommu pagesize(%x)\n",
|
||||
__func__, i, bytes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
total += bytes;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
#define sgtable_ok(x) (!!sgtable_len(x))
|
||||
|
||||
static unsigned max_alignment(u32 addr)
|
||||
{
|
||||
int i;
|
||||
unsigned pagesize[] = { SZ_16M, SZ_1M, SZ_64K, SZ_4K, };
|
||||
for (i = 0; i < ARRAY_SIZE(pagesize) && addr & (pagesize[i] - 1); i++)
|
||||
;
|
||||
return (i < ARRAY_SIZE(pagesize)) ? pagesize[i] : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* calculate the optimal number sg elements from total bytes based on
|
||||
* iommu superpages
|
||||
*/
|
||||
static unsigned sgtable_nents(size_t bytes, u32 da, u32 pa)
|
||||
{
|
||||
unsigned nr_entries = 0, ent_sz;
|
||||
|
||||
if (!IS_ALIGNED(bytes, PAGE_SIZE)) {
|
||||
pr_err("%s: wrong size %08x\n", __func__, bytes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (bytes) {
|
||||
ent_sz = max_alignment(da | pa);
|
||||
ent_sz = min_t(unsigned, ent_sz, iopgsz_max(bytes));
|
||||
nr_entries++;
|
||||
da += ent_sz;
|
||||
pa += ent_sz;
|
||||
bytes -= ent_sz;
|
||||
}
|
||||
|
||||
return nr_entries;
|
||||
}
|
||||
|
||||
/* allocate and initialize sg_table header(a kind of 'superblock') */
|
||||
static struct sg_table *sgtable_alloc(const size_t bytes, u32 flags,
|
||||
u32 da, u32 pa)
|
||||
{
|
||||
unsigned int nr_entries;
|
||||
int err;
|
||||
struct sg_table *sgt;
|
||||
|
||||
if (!bytes)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
if (!IS_ALIGNED(bytes, PAGE_SIZE))
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
if (flags & IOVMF_LINEAR) {
|
||||
nr_entries = sgtable_nents(bytes, da, pa);
|
||||
if (!nr_entries)
|
||||
return ERR_PTR(-EINVAL);
|
||||
} else
|
||||
nr_entries = bytes / PAGE_SIZE;
|
||||
|
||||
sgt = kzalloc(sizeof(*sgt), GFP_KERNEL);
|
||||
if (!sgt)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
err = sg_alloc_table(sgt, nr_entries, GFP_KERNEL);
|
||||
if (err) {
|
||||
kfree(sgt);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
pr_debug("%s: sgt:%p(%d entries)\n", __func__, sgt, nr_entries);
|
||||
|
||||
return sgt;
|
||||
}
|
||||
|
||||
/* free sg_table header(a kind of superblock) */
|
||||
static void sgtable_free(struct sg_table *sgt)
|
||||
{
|
||||
if (!sgt)
|
||||
return;
|
||||
|
||||
sg_free_table(sgt);
|
||||
kfree(sgt);
|
||||
|
||||
pr_debug("%s: sgt:%p\n", __func__, sgt);
|
||||
}
|
||||
|
||||
/* map 'sglist' to a contiguous mpu virtual area and return 'va' */
|
||||
static void *vmap_sg(const struct sg_table *sgt)
|
||||
{
|
||||
u32 va;
|
||||
size_t total;
|
||||
unsigned int i;
|
||||
struct scatterlist *sg;
|
||||
struct vm_struct *new;
|
||||
const struct mem_type *mtype;
|
||||
|
||||
mtype = get_mem_type(MT_DEVICE);
|
||||
if (!mtype)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
total = sgtable_len(sgt);
|
||||
if (!total)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
new = __get_vm_area(total, VM_IOREMAP, VMALLOC_START, VMALLOC_END);
|
||||
if (!new)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
va = (u32)new->addr;
|
||||
|
||||
for_each_sg(sgt->sgl, sg, sgt->nents, i) {
|
||||
size_t bytes;
|
||||
u32 pa;
|
||||
int err;
|
||||
|
||||
pa = sg_phys(sg);
|
||||
bytes = sg->length;
|
||||
|
||||
BUG_ON(bytes != PAGE_SIZE);
|
||||
|
||||
err = ioremap_page(va, pa, mtype);
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
va += bytes;
|
||||
}
|
||||
|
||||
flush_cache_vmap((unsigned long)new->addr,
|
||||
(unsigned long)(new->addr + total));
|
||||
return new->addr;
|
||||
|
||||
err_out:
|
||||
WARN_ON(1); /* FIXME: cleanup some mpu mappings */
|
||||
vunmap(new->addr);
|
||||
return ERR_PTR(-EAGAIN);
|
||||
}
|
||||
|
||||
static inline void vunmap_sg(const void *va)
|
||||
{
|
||||
vunmap(va);
|
||||
}
|
||||
|
||||
static struct iovm_struct *__find_iovm_area(struct iommu *obj, const u32 da)
|
||||
{
|
||||
struct iovm_struct *tmp;
|
||||
|
||||
list_for_each_entry(tmp, &obj->mmap, list) {
|
||||
if ((da >= tmp->da_start) && (da < tmp->da_end)) {
|
||||
size_t len;
|
||||
|
||||
len = tmp->da_end - tmp->da_start;
|
||||
|
||||
dev_dbg(obj->dev, "%s: %08x-%08x-%08x(%x) %08x\n",
|
||||
__func__, tmp->da_start, da, tmp->da_end, len,
|
||||
tmp->flags);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* find_iovm_area - find iovma which includes @da
|
||||
* @da: iommu device virtual address
|
||||
*
|
||||
* Find the existing iovma starting at @da
|
||||
*/
|
||||
struct iovm_struct *find_iovm_area(struct iommu *obj, u32 da)
|
||||
{
|
||||
struct iovm_struct *area;
|
||||
|
||||
mutex_lock(&obj->mmap_lock);
|
||||
area = __find_iovm_area(obj, da);
|
||||
mutex_unlock(&obj->mmap_lock);
|
||||
|
||||
return area;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(find_iovm_area);
|
||||
|
||||
/*
|
||||
* This finds the hole(area) which fits the requested address and len
|
||||
* in iovmas mmap, and returns the new allocated iovma.
|
||||
*/
|
||||
static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
|
||||
size_t bytes, u32 flags)
|
||||
{
|
||||
struct iovm_struct *new, *tmp;
|
||||
u32 start, prev_end, alignment;
|
||||
|
||||
if (!obj || !bytes)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
start = da;
|
||||
alignment = PAGE_SIZE;
|
||||
|
||||
if (~flags & IOVMF_DA_FIXED) {
|
||||
/* Don't map address 0 */
|
||||
start = obj->da_start ? obj->da_start : alignment;
|
||||
|
||||
if (flags & IOVMF_LINEAR)
|
||||
alignment = iopgsz_max(bytes);
|
||||
start = roundup(start, alignment);
|
||||
} else if (start < obj->da_start || start > obj->da_end ||
|
||||
obj->da_end - start < bytes) {
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
tmp = NULL;
|
||||
if (list_empty(&obj->mmap))
|
||||
goto found;
|
||||
|
||||
prev_end = 0;
|
||||
list_for_each_entry(tmp, &obj->mmap, list) {
|
||||
|
||||
if (prev_end > start)
|
||||
break;
|
||||
|
||||
if (tmp->da_start > start && (tmp->da_start - start) >= bytes)
|
||||
goto found;
|
||||
|
||||
if (tmp->da_end >= start && ~flags & IOVMF_DA_FIXED)
|
||||
start = roundup(tmp->da_end + 1, alignment);
|
||||
|
||||
prev_end = tmp->da_end;
|
||||
}
|
||||
|
||||
if ((start >= prev_end) && (obj->da_end - start >= bytes))
|
||||
goto found;
|
||||
|
||||
dev_dbg(obj->dev, "%s: no space to fit %08x(%x) flags: %08x\n",
|
||||
__func__, da, bytes, flags);
|
||||
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
found:
|
||||
new = kmem_cache_zalloc(iovm_area_cachep, GFP_KERNEL);
|
||||
if (!new)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
new->iommu = obj;
|
||||
new->da_start = start;
|
||||
new->da_end = start + bytes;
|
||||
new->flags = flags;
|
||||
|
||||
/*
|
||||
* keep ascending order of iovmas
|
||||
*/
|
||||
if (tmp)
|
||||
list_add_tail(&new->list, &tmp->list);
|
||||
else
|
||||
list_add(&new->list, &obj->mmap);
|
||||
|
||||
dev_dbg(obj->dev, "%s: found %08x-%08x-%08x(%x) %08x\n",
|
||||
__func__, new->da_start, start, new->da_end, bytes, flags);
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
static void free_iovm_area(struct iommu *obj, struct iovm_struct *area)
|
||||
{
|
||||
size_t bytes;
|
||||
|
||||
BUG_ON(!obj || !area);
|
||||
|
||||
bytes = area->da_end - area->da_start;
|
||||
|
||||
dev_dbg(obj->dev, "%s: %08x-%08x(%x) %08x\n",
|
||||
__func__, area->da_start, area->da_end, bytes, area->flags);
|
||||
|
||||
list_del(&area->list);
|
||||
kmem_cache_free(iovm_area_cachep, area);
|
||||
}
|
||||
|
||||
/**
|
||||
* da_to_va - convert (d) to (v)
|
||||
* @obj: objective iommu
|
||||
* @da: iommu device virtual address
|
||||
* @va: mpu virtual address
|
||||
*
|
||||
* Returns mpu virtual addr which corresponds to a given device virtual addr
|
||||
*/
|
||||
void *da_to_va(struct iommu *obj, u32 da)
|
||||
{
|
||||
void *va = NULL;
|
||||
struct iovm_struct *area;
|
||||
|
||||
mutex_lock(&obj->mmap_lock);
|
||||
|
||||
area = __find_iovm_area(obj, da);
|
||||
if (!area) {
|
||||
dev_dbg(obj->dev, "%s: no da area(%08x)\n", __func__, da);
|
||||
goto out;
|
||||
}
|
||||
va = area->va;
|
||||
out:
|
||||
mutex_unlock(&obj->mmap_lock);
|
||||
|
||||
return va;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(da_to_va);
|
||||
|
||||
static void sgtable_fill_vmalloc(struct sg_table *sgt, void *_va)
|
||||
{
|
||||
unsigned int i;
|
||||
struct scatterlist *sg;
|
||||
void *va = _va;
|
||||
void *va_end;
|
||||
|
||||
for_each_sg(sgt->sgl, sg, sgt->nents, i) {
|
||||
struct page *pg;
|
||||
const size_t bytes = PAGE_SIZE;
|
||||
|
||||
/*
|
||||
* iommu 'superpage' isn't supported with 'iommu_vmalloc()'
|
||||
*/
|
||||
pg = vmalloc_to_page(va);
|
||||
BUG_ON(!pg);
|
||||
sg_set_page(sg, pg, bytes, 0);
|
||||
|
||||
va += bytes;
|
||||
}
|
||||
|
||||
va_end = _va + PAGE_SIZE * i;
|
||||
}
|
||||
|
||||
static inline void sgtable_drain_vmalloc(struct sg_table *sgt)
|
||||
{
|
||||
/*
|
||||
* Actually this is not necessary at all, just exists for
|
||||
* consistency of the code readability.
|
||||
*/
|
||||
BUG_ON(!sgt);
|
||||
}
|
||||
|
||||
static void sgtable_fill_kmalloc(struct sg_table *sgt, u32 pa, u32 da,
|
||||
size_t len)
|
||||
{
|
||||
unsigned int i;
|
||||
struct scatterlist *sg;
|
||||
|
||||
for_each_sg(sgt->sgl, sg, sgt->nents, i) {
|
||||
unsigned bytes;
|
||||
|
||||
bytes = max_alignment(da | pa);
|
||||
bytes = min_t(unsigned, bytes, iopgsz_max(len));
|
||||
|
||||
BUG_ON(!iopgsz_ok(bytes));
|
||||
|
||||
sg_set_buf(sg, phys_to_virt(pa), bytes);
|
||||
/*
|
||||
* 'pa' is cotinuous(linear).
|
||||
*/
|
||||
pa += bytes;
|
||||
da += bytes;
|
||||
len -= bytes;
|
||||
}
|
||||
BUG_ON(len);
|
||||
}
|
||||
|
||||
static inline void sgtable_drain_kmalloc(struct sg_table *sgt)
|
||||
{
|
||||
/*
|
||||
* Actually this is not necessary at all, just exists for
|
||||
* consistency of the code readability
|
||||
*/
|
||||
BUG_ON(!sgt);
|
||||
}
|
||||
|
||||
/* create 'da' <-> 'pa' mapping from 'sgt' */
|
||||
static int map_iovm_area(struct iommu *obj, struct iovm_struct *new,
|
||||
const struct sg_table *sgt, u32 flags)
|
||||
{
|
||||
int err;
|
||||
unsigned int i, j;
|
||||
struct scatterlist *sg;
|
||||
u32 da = new->da_start;
|
||||
|
||||
if (!obj || !sgt)
|
||||
return -EINVAL;
|
||||
|
||||
BUG_ON(!sgtable_ok(sgt));
|
||||
|
||||
for_each_sg(sgt->sgl, sg, sgt->nents, i) {
|
||||
u32 pa;
|
||||
int pgsz;
|
||||
size_t bytes;
|
||||
struct iotlb_entry e;
|
||||
|
||||
pa = sg_phys(sg);
|
||||
bytes = sg->length;
|
||||
|
||||
flags &= ~IOVMF_PGSZ_MASK;
|
||||
pgsz = bytes_to_iopgsz(bytes);
|
||||
if (pgsz < 0)
|
||||
goto err_out;
|
||||
flags |= pgsz;
|
||||
|
||||
pr_debug("%s: [%d] %08x %08x(%x)\n", __func__,
|
||||
i, da, pa, bytes);
|
||||
|
||||
iotlb_init_entry(&e, da, pa, flags);
|
||||
err = iopgtable_store_entry(obj, &e);
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
da += bytes;
|
||||
}
|
||||
return 0;
|
||||
|
||||
err_out:
|
||||
da = new->da_start;
|
||||
|
||||
for_each_sg(sgt->sgl, sg, i, j) {
|
||||
size_t bytes;
|
||||
|
||||
bytes = iopgtable_clear_entry(obj, da);
|
||||
|
||||
BUG_ON(!iopgsz_ok(bytes));
|
||||
|
||||
da += bytes;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
/* release 'da' <-> 'pa' mapping */
|
||||
static void unmap_iovm_area(struct iommu *obj, struct iovm_struct *area)
|
||||
{
|
||||
u32 start;
|
||||
size_t total = area->da_end - area->da_start;
|
||||
|
||||
BUG_ON((!total) || !IS_ALIGNED(total, PAGE_SIZE));
|
||||
|
||||
start = area->da_start;
|
||||
while (total > 0) {
|
||||
size_t bytes;
|
||||
|
||||
bytes = iopgtable_clear_entry(obj, start);
|
||||
if (bytes == 0)
|
||||
bytes = PAGE_SIZE;
|
||||
else
|
||||
dev_dbg(obj->dev, "%s: unmap %08x(%x) %08x\n",
|
||||
__func__, start, bytes, area->flags);
|
||||
|
||||
BUG_ON(!IS_ALIGNED(bytes, PAGE_SIZE));
|
||||
|
||||
total -= bytes;
|
||||
start += bytes;
|
||||
}
|
||||
BUG_ON(total);
|
||||
}
|
||||
|
||||
/* template function for all unmapping */
|
||||
static struct sg_table *unmap_vm_area(struct iommu *obj, const u32 da,
|
||||
void (*fn)(const void *), u32 flags)
|
||||
{
|
||||
struct sg_table *sgt = NULL;
|
||||
struct iovm_struct *area;
|
||||
|
||||
if (!IS_ALIGNED(da, PAGE_SIZE)) {
|
||||
dev_err(obj->dev, "%s: alignment err(%08x)\n", __func__, da);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mutex_lock(&obj->mmap_lock);
|
||||
|
||||
area = __find_iovm_area(obj, da);
|
||||
if (!area) {
|
||||
dev_dbg(obj->dev, "%s: no da area(%08x)\n", __func__, da);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((area->flags & flags) != flags) {
|
||||
dev_err(obj->dev, "%s: wrong flags(%08x)\n", __func__,
|
||||
area->flags);
|
||||
goto out;
|
||||
}
|
||||
sgt = (struct sg_table *)area->sgt;
|
||||
|
||||
unmap_iovm_area(obj, area);
|
||||
|
||||
fn(area->va);
|
||||
|
||||
dev_dbg(obj->dev, "%s: %08x-%08x-%08x(%x) %08x\n", __func__,
|
||||
area->da_start, da, area->da_end,
|
||||
area->da_end - area->da_start, area->flags);
|
||||
|
||||
free_iovm_area(obj, area);
|
||||
out:
|
||||
mutex_unlock(&obj->mmap_lock);
|
||||
|
||||
return sgt;
|
||||
}
|
||||
|
||||
static u32 map_iommu_region(struct iommu *obj, u32 da,
|
||||
const struct sg_table *sgt, void *va, size_t bytes, u32 flags)
|
||||
{
|
||||
int err = -ENOMEM;
|
||||
struct iovm_struct *new;
|
||||
|
||||
mutex_lock(&obj->mmap_lock);
|
||||
|
||||
new = alloc_iovm_area(obj, da, bytes, flags);
|
||||
if (IS_ERR(new)) {
|
||||
err = PTR_ERR(new);
|
||||
goto err_alloc_iovma;
|
||||
}
|
||||
new->va = va;
|
||||
new->sgt = sgt;
|
||||
|
||||
if (map_iovm_area(obj, new, sgt, new->flags))
|
||||
goto err_map;
|
||||
|
||||
mutex_unlock(&obj->mmap_lock);
|
||||
|
||||
dev_dbg(obj->dev, "%s: da:%08x(%x) flags:%08x va:%p\n",
|
||||
__func__, new->da_start, bytes, new->flags, va);
|
||||
|
||||
return new->da_start;
|
||||
|
||||
err_map:
|
||||
free_iovm_area(obj, new);
|
||||
err_alloc_iovma:
|
||||
mutex_unlock(&obj->mmap_lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline u32 __iommu_vmap(struct iommu *obj, u32 da,
|
||||
const struct sg_table *sgt, void *va, size_t bytes, u32 flags)
|
||||
{
|
||||
return map_iommu_region(obj, da, sgt, va, bytes, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* iommu_vmap - (d)-(p)-(v) address mapper
|
||||
* @obj: objective iommu
|
||||
* @sgt: address of scatter gather table
|
||||
* @flags: iovma and page property
|
||||
*
|
||||
* Creates 1-n-1 mapping with given @sgt and returns @da.
|
||||
* All @sgt element must be io page size aligned.
|
||||
*/
|
||||
u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt,
|
||||
u32 flags)
|
||||
{
|
||||
size_t bytes;
|
||||
void *va = NULL;
|
||||
|
||||
if (!obj || !obj->dev || !sgt)
|
||||
return -EINVAL;
|
||||
|
||||
bytes = sgtable_len(sgt);
|
||||
if (!bytes)
|
||||
return -EINVAL;
|
||||
bytes = PAGE_ALIGN(bytes);
|
||||
|
||||
if (flags & IOVMF_MMIO) {
|
||||
va = vmap_sg(sgt);
|
||||
if (IS_ERR(va))
|
||||
return PTR_ERR(va);
|
||||
}
|
||||
|
||||
flags |= IOVMF_DISCONT;
|
||||
flags |= IOVMF_MMIO;
|
||||
|
||||
da = __iommu_vmap(obj, da, sgt, va, bytes, flags);
|
||||
if (IS_ERR_VALUE(da))
|
||||
vunmap_sg(va);
|
||||
|
||||
return da;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(iommu_vmap);
|
||||
|
||||
/**
|
||||
* iommu_vunmap - release virtual mapping obtained by 'iommu_vmap()'
|
||||
* @obj: objective iommu
|
||||
* @da: iommu device virtual address
|
||||
*
|
||||
* Free the iommu virtually contiguous memory area starting at
|
||||
* @da, which was returned by 'iommu_vmap()'.
|
||||
*/
|
||||
struct sg_table *iommu_vunmap(struct iommu *obj, u32 da)
|
||||
{
|
||||
struct sg_table *sgt;
|
||||
/*
|
||||
* 'sgt' is allocated before 'iommu_vmalloc()' is called.
|
||||
* Just returns 'sgt' to the caller to free
|
||||
*/
|
||||
sgt = unmap_vm_area(obj, da, vunmap_sg, IOVMF_DISCONT | IOVMF_MMIO);
|
||||
if (!sgt)
|
||||
dev_dbg(obj->dev, "%s: No sgt\n", __func__);
|
||||
return sgt;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(iommu_vunmap);
|
||||
|
||||
/**
|
||||
* iommu_vmalloc - (d)-(p)-(v) address allocator and mapper
|
||||
* @obj: objective iommu
|
||||
* @da: contiguous iommu virtual memory
|
||||
* @bytes: allocation size
|
||||
* @flags: iovma and page property
|
||||
*
|
||||
* Allocate @bytes linearly and creates 1-n-1 mapping and returns
|
||||
* @da again, which might be adjusted if 'IOVMF_DA_FIXED' is not set.
|
||||
*/
|
||||
u32 iommu_vmalloc(struct iommu *obj, u32 da, size_t bytes, u32 flags)
|
||||
{
|
||||
void *va;
|
||||
struct sg_table *sgt;
|
||||
|
||||
if (!obj || !obj->dev || !bytes)
|
||||
return -EINVAL;
|
||||
|
||||
bytes = PAGE_ALIGN(bytes);
|
||||
|
||||
va = vmalloc(bytes);
|
||||
if (!va)
|
||||
return -ENOMEM;
|
||||
|
||||
flags |= IOVMF_DISCONT;
|
||||
flags |= IOVMF_ALLOC;
|
||||
|
||||
sgt = sgtable_alloc(bytes, flags, da, 0);
|
||||
if (IS_ERR(sgt)) {
|
||||
da = PTR_ERR(sgt);
|
||||
goto err_sgt_alloc;
|
||||
}
|
||||
sgtable_fill_vmalloc(sgt, va);
|
||||
|
||||
da = __iommu_vmap(obj, da, sgt, va, bytes, flags);
|
||||
if (IS_ERR_VALUE(da))
|
||||
goto err_iommu_vmap;
|
||||
|
||||
return da;
|
||||
|
||||
err_iommu_vmap:
|
||||
sgtable_drain_vmalloc(sgt);
|
||||
sgtable_free(sgt);
|
||||
err_sgt_alloc:
|
||||
vfree(va);
|
||||
return da;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(iommu_vmalloc);
|
||||
|
||||
/**
|
||||
* iommu_vfree - release memory allocated by 'iommu_vmalloc()'
|
||||
* @obj: objective iommu
|
||||
* @da: iommu device virtual address
|
||||
*
|
||||
* Frees the iommu virtually continuous memory area starting at
|
||||
* @da, as obtained from 'iommu_vmalloc()'.
|
||||
*/
|
||||
void iommu_vfree(struct iommu *obj, const u32 da)
|
||||
{
|
||||
struct sg_table *sgt;
|
||||
|
||||
sgt = unmap_vm_area(obj, da, vfree, IOVMF_DISCONT | IOVMF_ALLOC);
|
||||
if (!sgt)
|
||||
dev_dbg(obj->dev, "%s: No sgt\n", __func__);
|
||||
sgtable_free(sgt);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(iommu_vfree);
|
||||
|
||||
static u32 __iommu_kmap(struct iommu *obj, u32 da, u32 pa, void *va,
|
||||
size_t bytes, u32 flags)
|
||||
{
|
||||
struct sg_table *sgt;
|
||||
|
||||
sgt = sgtable_alloc(bytes, flags, da, pa);
|
||||
if (IS_ERR(sgt))
|
||||
return PTR_ERR(sgt);
|
||||
|
||||
sgtable_fill_kmalloc(sgt, pa, da, bytes);
|
||||
|
||||
da = map_iommu_region(obj, da, sgt, va, bytes, flags);
|
||||
if (IS_ERR_VALUE(da)) {
|
||||
sgtable_drain_kmalloc(sgt);
|
||||
sgtable_free(sgt);
|
||||
}
|
||||
|
||||
return da;
|
||||
}
|
||||
|
||||
/**
|
||||
* iommu_kmap - (d)-(p)-(v) address mapper
|
||||
* @obj: objective iommu
|
||||
* @da: contiguous iommu virtual memory
|
||||
* @pa: contiguous physical memory
|
||||
* @flags: iovma and page property
|
||||
*
|
||||
* Creates 1-1-1 mapping and returns @da again, which can be
|
||||
* adjusted if 'IOVMF_DA_FIXED' is not set.
|
||||
*/
|
||||
u32 iommu_kmap(struct iommu *obj, u32 da, u32 pa, size_t bytes,
|
||||
u32 flags)
|
||||
{
|
||||
void *va;
|
||||
|
||||
if (!obj || !obj->dev || !bytes)
|
||||
return -EINVAL;
|
||||
|
||||
bytes = PAGE_ALIGN(bytes);
|
||||
|
||||
va = ioremap(pa, bytes);
|
||||
if (!va)
|
||||
return -ENOMEM;
|
||||
|
||||
flags |= IOVMF_LINEAR;
|
||||
flags |= IOVMF_MMIO;
|
||||
|
||||
da = __iommu_kmap(obj, da, pa, va, bytes, flags);
|
||||
if (IS_ERR_VALUE(da))
|
||||
iounmap(va);
|
||||
|
||||
return da;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(iommu_kmap);
|
||||
|
||||
/**
|
||||
* iommu_kunmap - release virtual mapping obtained by 'iommu_kmap()'
|
||||
* @obj: objective iommu
|
||||
* @da: iommu device virtual address
|
||||
*
|
||||
* Frees the iommu virtually contiguous memory area starting at
|
||||
* @da, which was passed to and was returned by'iommu_kmap()'.
|
||||
*/
|
||||
void iommu_kunmap(struct iommu *obj, u32 da)
|
||||
{
|
||||
struct sg_table *sgt;
|
||||
typedef void (*func_t)(const void *);
|
||||
|
||||
sgt = unmap_vm_area(obj, da, (func_t)iounmap,
|
||||
IOVMF_LINEAR | IOVMF_MMIO);
|
||||
if (!sgt)
|
||||
dev_dbg(obj->dev, "%s: No sgt\n", __func__);
|
||||
sgtable_free(sgt);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(iommu_kunmap);
|
||||
|
||||
/**
|
||||
* iommu_kmalloc - (d)-(p)-(v) address allocator and mapper
|
||||
* @obj: objective iommu
|
||||
* @da: contiguous iommu virtual memory
|
||||
* @bytes: bytes for allocation
|
||||
* @flags: iovma and page property
|
||||
*
|
||||
* Allocate @bytes linearly and creates 1-1-1 mapping and returns
|
||||
* @da again, which might be adjusted if 'IOVMF_DA_FIXED' is not set.
|
||||
*/
|
||||
u32 iommu_kmalloc(struct iommu *obj, u32 da, size_t bytes, u32 flags)
|
||||
{
|
||||
void *va;
|
||||
u32 pa;
|
||||
|
||||
if (!obj || !obj->dev || !bytes)
|
||||
return -EINVAL;
|
||||
|
||||
bytes = PAGE_ALIGN(bytes);
|
||||
|
||||
va = kmalloc(bytes, GFP_KERNEL | GFP_DMA);
|
||||
if (!va)
|
||||
return -ENOMEM;
|
||||
pa = virt_to_phys(va);
|
||||
|
||||
flags |= IOVMF_LINEAR;
|
||||
flags |= IOVMF_ALLOC;
|
||||
|
||||
da = __iommu_kmap(obj, da, pa, va, bytes, flags);
|
||||
if (IS_ERR_VALUE(da))
|
||||
kfree(va);
|
||||
|
||||
return da;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(iommu_kmalloc);
|
||||
|
||||
/**
|
||||
* iommu_kfree - release virtual mapping obtained by 'iommu_kmalloc()'
|
||||
* @obj: objective iommu
|
||||
* @da: iommu device virtual address
|
||||
*
|
||||
* Frees the iommu virtually contiguous memory area starting at
|
||||
* @da, which was passed to and was returned by'iommu_kmalloc()'.
|
||||
*/
|
||||
void iommu_kfree(struct iommu *obj, u32 da)
|
||||
{
|
||||
struct sg_table *sgt;
|
||||
|
||||
sgt = unmap_vm_area(obj, da, kfree, IOVMF_LINEAR | IOVMF_ALLOC);
|
||||
if (!sgt)
|
||||
dev_dbg(obj->dev, "%s: No sgt\n", __func__);
|
||||
sgtable_free(sgt);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(iommu_kfree);
|
||||
|
||||
|
||||
static int __init iovmm_init(void)
|
||||
{
|
||||
const unsigned long flags = SLAB_HWCACHE_ALIGN;
|
||||
struct kmem_cache *p;
|
||||
|
||||
p = kmem_cache_create("iovm_area_cache", sizeof(struct iovm_struct), 0,
|
||||
flags, NULL);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
iovm_area_cachep = p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
module_init(iovmm_init);
|
||||
|
||||
static void __exit iovmm_exit(void)
|
||||
{
|
||||
kmem_cache_destroy(iovm_area_cachep);
|
||||
}
|
||||
module_exit(iovmm_exit);
|
||||
|
||||
MODULE_DESCRIPTION("omap iommu: simple virtual address space management");
|
||||
MODULE_AUTHOR("Hiroshi DOYU <[email protected]>");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
|
@ -33,6 +33,7 @@
|
|||
#include <linux/uaccess.h>
|
||||
#include <linux/iommu.h>
|
||||
#include <linux/intel-iommu.h>
|
||||
#include <linux/pci.h>
|
||||
|
||||
#include <asm/pgtable.h>
|
||||
#include <asm/gcc_intrin.h>
|
||||
|
|
@ -204,7 +205,7 @@ int kvm_dev_ioctl_check_extension(long ext)
|
|||
r = KVM_COALESCED_MMIO_PAGE_OFFSET;
|
||||
break;
|
||||
case KVM_CAP_IOMMU:
|
||||
r = iommu_found();
|
||||
r = iommu_present(&pci_bus_type);
|
||||
break;
|
||||
default:
|
||||
r = 0;
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
#include <linux/perf_event.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/hash.h>
|
||||
#include <linux/pci.h>
|
||||
#include <trace/events/kvm.h>
|
||||
|
||||
#define CREATE_TRACE_POINTS
|
||||
|
|
@ -2123,7 +2124,7 @@ int kvm_dev_ioctl_check_extension(long ext)
|
|||
r = 0;
|
||||
break;
|
||||
case KVM_CAP_IOMMU:
|
||||
r = iommu_found();
|
||||
r = iommu_present(&pci_bus_type);
|
||||
break;
|
||||
case KVM_CAP_MCE:
|
||||
r = KVM_MAX_MCE_BANKS;
|
||||
|
|
|
|||
Loading…
Reference in a new issue