diff mbox

[RFC,1/23] VIOMMU: Add vIOMMU helper functions to create, destroy and query capabilities

Message ID 1489750043-17260-2-git-send-email-tianyu.lan@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

lan,Tianyu March 17, 2017, 11:27 a.m. UTC
This patch is to introduct an abstract layer for arch vIOMMU implementation
to deal with requests from dom0. Arch vIOMMU code needs to provide callback
to perform create, destroy and query capabilities operation.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
 xen/common/Makefile          |  1 +
 xen/common/domain.c          |  3 ++
 xen/common/viommu.c          | 97 ++++++++++++++++++++++++++++++++++++++++++++
 xen/include/asm-arm/viommu.h | 30 ++++++++++++++
 xen/include/asm-x86/viommu.h | 31 ++++++++++++++
 xen/include/public/viommu.h  | 38 +++++++++++++++++
 xen/include/xen/sched.h      |  2 +
 xen/include/xen/viommu.h     | 62 ++++++++++++++++++++++++++++
 8 files changed, 264 insertions(+)
 create mode 100644 xen/common/viommu.c
 create mode 100644 xen/include/asm-arm/viommu.h
 create mode 100644 xen/include/asm-x86/viommu.h
 create mode 100644 xen/include/public/viommu.h
 create mode 100644 xen/include/xen/viommu.h

Comments

Julien Grall March 21, 2017, 7:56 p.m. UTC | #1
Hello Tinayu Lan,

On 03/17/2017 11:27 AM, Lan Tianyu wrote:
> This patch is to introduct an abstract layer for arch vIOMMU implementation

s/introduct/introduce/

> to deal with requests from dom0. Arch vIOMMU code needs to provide callback
> to perform create, destroy and query capabilities operation.
>
> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
> ---
>  xen/common/Makefile          |  1 +
>  xen/common/domain.c          |  3 ++
>  xen/common/viommu.c          | 97 ++++++++++++++++++++++++++++++++++++++++++++
>  xen/include/asm-arm/viommu.h | 30 ++++++++++++++
>  xen/include/asm-x86/viommu.h | 31 ++++++++++++++
>  xen/include/public/viommu.h  | 38 +++++++++++++++++
>  xen/include/xen/sched.h      |  2 +
>  xen/include/xen/viommu.h     | 62 ++++++++++++++++++++++++++++
>  8 files changed, 264 insertions(+)
>  create mode 100644 xen/common/viommu.c
>  create mode 100644 xen/include/asm-arm/viommu.h
>  create mode 100644 xen/include/asm-x86/viommu.h
>  create mode 100644 xen/include/public/viommu.h
>  create mode 100644 xen/include/xen/viommu.h
>
> diff --git a/xen/common/Makefile b/xen/common/Makefile
> index 0fed30b..b58de63 100644
> --- a/xen/common/Makefile
> +++ b/xen/common/Makefile
> @@ -60,6 +60,7 @@ obj-y += vm_event.o
>  obj-y += vmap.o
>  obj-y += vsprintf.o
>  obj-y += wait.o
> +obj-y += viommu.o

I see very little point to enable viommu by default on all architecture. 
This is x86 specific and I am yet sure how we would be able to use it on 
ARM as the current series rely on QEMU. Also this is waste space in 
struct domain.

I would prefer if you introduce a Kconfig that would be select by x86 only.

Regards,

>  obj-bin-y += warning.init.o
>  obj-$(CONFIG_XENOPROF) += xenoprof.o
>  obj-y += xmalloc_tlsf.o
> diff --git a/xen/common/domain.c b/xen/common/domain.c
> index 4492c9c..aafc740 100644
> --- a/xen/common/domain.c
> +++ b/xen/common/domain.c
> @@ -398,6 +398,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
>          spin_unlock(&domlist_update_lock);
>      }
>
> +    if ( (err = viommu_init_domain(d)) != 0)
> +        goto fail;
> +
>      return d;
>
>   fail:
> diff --git a/xen/common/viommu.c b/xen/common/viommu.c
> new file mode 100644
> index 0000000..4c1c788
> --- /dev/null
> +++ b/xen/common/viommu.c
> @@ -0,0 +1,97 @@

[...]

> +int viommu_create(struct domain *d, u64 base_address, u64 length, u64 caps)
> +{
> +    struct viommu_info *info = &d->viommu;
> +    struct viommu *viommu;
> +    int rc;
> +
> +    if ( !info || !info->ops || !info->ops->create
> +	        || info->nr_viommu >= NR_VIOMMU_PER_DOMAIN )
> +        return -EINVAL;
> +
> +    viommu = xzalloc(struct viommu);
> +    if ( !viommu )
> +        return -EFAULT;
> +
> +    viommu->base_address = base_address;
> +    viommu->length = length;
> +    viommu->caps = caps;
> +    viommu->viommu_id = info->nr_viommu;
> +
> +    info->viommu[info->nr_viommu] = viommu;
> +    info->nr_viommu++;
> +
> +    rc = info->ops->create(d, viommu);
> +    if ( rc < 0 ) {

Coding style:

if ( ... )
{

[...]

> diff --git a/xen/include/asm-arm/viommu.h b/xen/include/asm-arm/viommu.h
> new file mode 100644
> index 0000000..ef6a60b
> --- /dev/null
> +++ b/xen/include/asm-arm/viommu.h
> @@ -0,0 +1,30 @@
> +/*
> + * include/asm-arm/viommu.h
> + *
> + * Copyright (c) 2017 Intel Corporation
> + * Author: Lan Tianyu <tianyu.lan@intel.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program; If not, see <http://www.gnu.org/licenses/>.
> + *
> + */
> +#ifndef __ARCH_ARM_VIOMMU_H__
> +#define __ARCH_ARM_VIOMMU_H__
> +
> +#include <xen/viommu.h>
> +
> +static inline const struct viommu_ops *viommu_get_ops(void)
> +{
> +    return NULL;
> +}
> +
> +#endif /* __ARCH_ARM_VIOMMU_H__ */

Missing emacs magic.

> diff --git a/xen/include/asm-x86/viommu.h b/xen/include/asm-x86/viommu.h
> new file mode 100644
> index 0000000..efb435f
> --- /dev/null
> +++ b/xen/include/asm-x86/viommu.h
> @@ -0,0 +1,31 @@
> +/*
> + * include/asm-arm/viommu.h
> + *
> + * Copyright (c) 2017 Intel Corporation.
> + * Author: Lan Tianyu <tianyu.lan@intel.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program; If not, see <http://www.gnu.org/licenses/>.
> + *
> + */
> +#ifndef __ARCH_X86_VIOMMU_H__
> +#define __ARCH_X86_VIOMMU_H__
> +
> +#include <xen/viommu.h>
> +#include <asm/types.h>
> +
> +static inline const struct viommu_ops *viommu_get_ops(void)
> +{
> +    return NULL;
> +}
> +
> +#endif /* __ARCH_X86_VIOMMU_H__ */

Ditto

> diff --git a/xen/include/public/viommu.h b/xen/include/public/viommu.h
> new file mode 100644
> index 0000000..ca2419b
> --- /dev/null
> +++ b/xen/include/public/viommu.h
> @@ -0,0 +1,38 @@
> +/*
> + * include/public/viommu.h
> + *
> + * Copyright (c) 2017 Intel Corporation
> + * Author: Lan Tianyu <tianyu.lan@intel.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.

Public headers sould not be GPLv2 otherwise it will cause some trouble 
for non-GPLv2 OS. See the license in xen/include/public/COPYING.

Regards.
Tian, Kevin March 22, 2017, 8:36 a.m. UTC | #2
> From: Julien Grall [mailto:julien.grall@arm.com]
> Sent: Wednesday, March 22, 2017 3:57 AM
> 
> >
> > diff --git a/xen/common/Makefile b/xen/common/Makefile index
> > 0fed30b..b58de63 100644
> > --- a/xen/common/Makefile
> > +++ b/xen/common/Makefile
> > @@ -60,6 +60,7 @@ obj-y += vm_event.o
> >  obj-y += vmap.o
> >  obj-y += vsprintf.o
> >  obj-y += wait.o
> > +obj-y += viommu.o
> 
> I see very little point to enable viommu by default on all architecture.
> This is x86 specific and I am yet sure how we would be able to use it on ARM
> as the current series rely on QEMU. Also this is waste space in struct domain.
> 
> I would prefer if you introduce a Kconfig that would be select by x86 only.
> 
> Regards,
> 

Also viommu.c is too generic. Each vendor should has his own
implementation. better change to vvtd.c (and make more sense
move to hvm)

Thanks
Kevin
lan,Tianyu March 22, 2017, 8:45 a.m. UTC | #3
Hi  Julien:
	Thanks for review.

On 2017年03月22日 03:56, Julien Grall wrote:
> =======================================
> 
> diff --git a/xen/include/public/viommu.h b/xen/include/public/viommu.h
> new file mode 100644
> index 0000000..ca2419b
> 
> --- /dev/null
> 
> +++ b/xen/include/public/viommu.h
> 
> @@ -0,0 +1,9 @@
> 
> +/*
> +·*·include/public/viommu.h
> +·*
> +·*·Copyright·(c)·2017·Intel·Corporation
> +·*·Author:·Lan·Tianyu·<tianyu.lan@intel.com>
> +·*
> +·*·This·program·is·free·software;·you·can·redistribute·it·and/or·modify·it
> +·*·under·the·terms·and·conditions·of·the·GNU·General·Public·License,
> +·*·version·2,·as·published·by·the·Free·Software·Foundation.
> 
>  obj-y += vmap.o
>  obj-y += vsprintf.o
>  obj-y += wait.o
> +obj-y += viommu.o
> I see very little point to enable viommu by default on all architecture. 
> This is x86 specific and I am yet sure how we would be able to use it on 
> ARM as the current series rely on QEMU. Also this is waste space in 
> struct domain.

XEN_DMOP_create/destroy_viommu hypercalls we introduced are generic for
all platforms and can use in toolstack to create/destroy vIOMMU rather
than just in Qemu. This takes PVH case into account which also don't use
Qemu.


> I would prefer if you introduce a Kconfig that would be select by x86 only.
> Regards,


> Public headers sould not be GPLv2 otherwise it will cause some trouble 
> for non-GPLv2 OS. See the license in xen/include/public/COPYING.

Yes, it should be MIT license.
> 
> Regards.
> 
> -- Julien Grall
Julien Grall March 22, 2017, 11:40 a.m. UTC | #4
Hello,

On 22/03/17 08:45, Lan Tianyu wrote:
> Hi  Julien:
> 	Thanks for review.
>
> On 2017年03月22日 03:56, Julien Grall wrote:
>> =======================================
>>
>> diff --git a/xen/include/public/viommu.h b/xen/include/public/viommu.h
>> new file mode 100644
>> index 0000000..ca2419b
>>
>> --- /dev/null
>>
>> +++ b/xen/include/public/viommu.h
>>
>> @@ -0,0 +1,9 @@
>>
>> +/*
>> +·*·include/public/viommu.h
>> +·*
>> +·*·Copyright·(c)·2017·Intel·Corporation
>> +·*·Author:·Lan·Tianyu·<tianyu.lan@intel.com>
>> +·*
>> +·*·This·program·is·free·software;·you·can·redistribute·it·and/or·modify·it
>> +·*·under·the·terms·and·conditions·of·the·GNU·General·Public·License,
>> +·*·version·2,·as·published·by·the·Free·Software·Foundation.
>>
>>  obj-y += vmap.o
>>  obj-y += vsprintf.o
>>  obj-y += wait.o
>> +obj-y += viommu.o
>> I see very little point to enable viommu by default on all architecture.
>> This is x86 specific and I am yet sure how we would be able to use it on
>> ARM as the current series rely on QEMU. Also this is waste space in
>> struct domain.
>
> XEN_DMOP_create/destroy_viommu hypercalls we introduced are generic for
> all platforms and can use in toolstack to create/destroy vIOMMU rather
> than just in Qemu. This takes PVH case into account which also don't use
> Qemu.

I am afraid that none of the DMOP you suggested in this series will fit 
for ARM.

For instance it is not possible to select via DMOP_CREATE the kind of 
vIOMMU (e.g SMMUv2, SMMUv3, IPMMU-VMSA...).

To be clear, I am not asking to get this code ready for ARM, but at 
least we need to make sure the API could be easily extended. During the 
discussion on the design documented it was suggested to add a 
iommu_version field to make it "future proof".

Also, I was not asking to move this code in arch/x86 but not compiling 
the code on ARM by default as it is currently unusable.

Regards,
lan,Tianyu March 22, 2017, 12:41 p.m. UTC | #5
On 3/22/2017 4:36 PM, Tian, Kevin wrote:
>> From: Julien Grall [mailto:julien.grall@arm.com]
>> Sent: Wednesday, March 22, 2017 3:57 AM
>>
>>>
>>> diff --git a/xen/common/Makefile b/xen/common/Makefile index
>>> 0fed30b..b58de63 100644
>>> --- a/xen/common/Makefile
>>> +++ b/xen/common/Makefile
>>> @@ -60,6 +60,7 @@ obj-y += vm_event.o
>>>  obj-y += vmap.o
>>>  obj-y += vsprintf.o
>>>  obj-y += wait.o
>>> +obj-y += viommu.o
>>
>> I see very little point to enable viommu by default on all architecture.
>> This is x86 specific and I am yet sure how we would be able to use it on ARM
>> as the current series rely on QEMU. Also this is waste space in struct domain.
>>
>> I would prefer if you introduce a Kconfig that would be select by x86 only.
>>
>> Regards,
>>
>
> Also viommu.c is too generic. Each vendor should has his own
> implementation. better change to vvtd.c (and make more sense
> move to hvm)

Hi Kevin:
     vIommu is an abstract layer and we have added vvtd.c under hvm 
directory in the following patch. vvtd will register its callbacks to 
vIOMMU layer. This works just like IOMMU core and VTD driver.

>
> Thanks
> Kevin
>
lan,Tianyu March 22, 2017, 1:32 p.m. UTC | #6
On 3/22/2017 7:40 PM, Julien Grall wrote:
> Hello,
>
> On 22/03/17 08:45, Lan Tianyu wrote:
>> Hi  Julien:
>>     Thanks for review.
>>
>> On 2017年03月22日 03:56, Julien Grall wrote:
>>> =======================================
>>>
>>> diff --git a/xen/include/public/viommu.h b/xen/include/public/viommu.h
>>> new file mode 100644
>>> index 0000000..ca2419b
>>>
>>> --- /dev/null
>>>
>>> +++ b/xen/include/public/viommu.h
>>>
>>> @@ -0,0 +1,9 @@
>>>
>>> +/*
>>> +·*·include/public/viommu.h
>>> +·*
>>> +·*·Copyright·(c)·2017·Intel·Corporation
>>> +·*·Author:·Lan·Tianyu·<tianyu.lan@intel.com>
>>> +·*
>>> +·*·This·program·is·free·software;·you·can·redistribute·it·and/or·modify·it
>>>
>>> +·*·under·the·terms·and·conditions·of·the·GNU·General·Public·License,
>>> +·*·version·2,·as·published·by·the·Free·Software·Foundation.
>>>
>>>  obj-y += vmap.o
>>>  obj-y += vsprintf.o
>>>  obj-y += wait.o
>>> +obj-y += viommu.o
>>> I see very little point to enable viommu by default on all architecture.
>>> This is x86 specific and I am yet sure how we would be able to use it on
>>> ARM as the current series rely on QEMU. Also this is waste space in
>>> struct domain.
>>
>> XEN_DMOP_create/destroy_viommu hypercalls we introduced are generic for
>> all platforms and can use in toolstack to create/destroy vIOMMU rather
>> than just in Qemu. This takes PVH case into account which also don't use
>> Qemu.
>
> I am afraid that none of the DMOP you suggested in this series will fit
> for ARM.
>
> For instance it is not possible to select via DMOP_CREATE the kind of
> vIOMMU (e.g SMMUv2, SMMUv3, IPMMU-VMSA...).

Thanks for your information. I am not sure whether we can introduce arch 
specific hypercalls for different vIOMMU implementations and So try to 
make it more general. To support more type vIOMMUs or more vIOMMU 
subfeature, we may extend input parameter structure.

>
> To be clear, I am not asking to get this code ready for ARM, but at
> least we need to make sure the API could be easily extended. During the
> discussion on the design documented it was suggested to add a
> iommu_version field to make it "future proof".

Sure. That's very good suggestion. Sorry, I missed that in this series. 
and thought "capability" field in struct xen_dm_op_create_viommu is 
enough for other vendors to extend more sub features. Will change it.

>
> Also, I was not asking to move this code in arch/x86 but not compiling
> the code on ARM by default as it is currently unusable.

Sure. Will change it.

>
> Regards,
>
diff mbox

Patch

diff --git a/xen/common/Makefile b/xen/common/Makefile
index 0fed30b..b58de63 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -60,6 +60,7 @@  obj-y += vm_event.o
 obj-y += vmap.o
 obj-y += vsprintf.o
 obj-y += wait.o
+obj-y += viommu.o
 obj-bin-y += warning.init.o
 obj-$(CONFIG_XENOPROF) += xenoprof.o
 obj-y += xmalloc_tlsf.o
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 4492c9c..aafc740 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -398,6 +398,9 @@  struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
         spin_unlock(&domlist_update_lock);
     }
 
+    if ( (err = viommu_init_domain(d)) != 0)
+        goto fail;
+
     return d;
 
  fail:
diff --git a/xen/common/viommu.c b/xen/common/viommu.c
new file mode 100644
index 0000000..4c1c788
--- /dev/null
+++ b/xen/common/viommu.c
@@ -0,0 +1,97 @@ 
+/*
+ * common/viommu.c
+ * 
+ * Copyright (c) 2017 Intel Corporation
+ * Author: Lan Tianyu <tianyu.lan@intel.com> 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <xen/types.h>
+#include <xen/sched.h>
+
+int viommu_init_domain(struct domain *d)
+{
+    d->viommu.nr_viommu = 0;
+    d->viommu.ops = viommu_get_ops();
+
+    return 0;
+}
+
+int viommu_create(struct domain *d, u64 base_address, u64 length, u64 caps)
+{
+    struct viommu_info *info = &d->viommu;
+    struct viommu *viommu;
+    int rc;
+
+    if ( !info || !info->ops || !info->ops->create
+	        || info->nr_viommu >= NR_VIOMMU_PER_DOMAIN )
+        return -EINVAL;
+
+    viommu = xzalloc(struct viommu);
+    if ( !viommu )
+        return -EFAULT;
+
+    viommu->base_address = base_address;
+    viommu->length = length;
+    viommu->caps = caps;
+    viommu->viommu_id = info->nr_viommu;
+
+    info->viommu[info->nr_viommu] = viommu;
+    info->nr_viommu++;
+
+    rc = info->ops->create(d, viommu);
+    if ( rc < 0 ) {
+        xfree(viommu);
+        return rc;
+    }
+
+    return viommu->viommu_id;
+}
+
+int viommu_destroy(struct domain *d, u32 viommu_id)
+{
+    struct viommu_info *info = &d->viommu;
+
+    if ( !info || !info->ops || !info->ops->destroy)
+        return -EINVAL;
+
+    if ( viommu_id > info->nr_viommu || !info->viommu[viommu_id] )
+        return -EINVAL;
+
+    if ( info->ops->destroy(info->viommu[viommu_id]) )
+        return -EFAULT;
+
+    info->viommu[viommu_id] = NULL;
+    return 0;
+}
+
+u64 viommu_query_caps(struct domain *d)
+{
+    struct viommu_info *info = &d->viommu;
+
+    if ( !info || !info->ops || !info->ops->query_caps)
+        return -EINVAL;
+
+    return info->ops->query_caps(d);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
diff --git a/xen/include/asm-arm/viommu.h b/xen/include/asm-arm/viommu.h
new file mode 100644
index 0000000..ef6a60b
--- /dev/null
+++ b/xen/include/asm-arm/viommu.h
@@ -0,0 +1,30 @@ 
+/*
+ * include/asm-arm/viommu.h
+ *
+ * Copyright (c) 2017 Intel Corporation
+ * Author: Lan Tianyu <tianyu.lan@intel.com> 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef __ARCH_ARM_VIOMMU_H__
+#define __ARCH_ARM_VIOMMU_H__
+
+#include <xen/viommu.h>
+
+static inline const struct viommu_ops *viommu_get_ops(void)
+{
+    return NULL;
+}
+
+#endif /* __ARCH_ARM_VIOMMU_H__ */
diff --git a/xen/include/asm-x86/viommu.h b/xen/include/asm-x86/viommu.h
new file mode 100644
index 0000000..efb435f
--- /dev/null
+++ b/xen/include/asm-x86/viommu.h
@@ -0,0 +1,31 @@ 
+/*
+ * include/asm-arm/viommu.h
+ *
+ * Copyright (c) 2017 Intel Corporation.
+ * Author: Lan Tianyu <tianyu.lan@intel.com> 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef __ARCH_X86_VIOMMU_H__
+#define __ARCH_X86_VIOMMU_H__
+
+#include <xen/viommu.h>
+#include <asm/types.h>
+
+static inline const struct viommu_ops *viommu_get_ops(void)
+{
+    return NULL;
+}
+
+#endif /* __ARCH_X86_VIOMMU_H__ */
diff --git a/xen/include/public/viommu.h b/xen/include/public/viommu.h
new file mode 100644
index 0000000..ca2419b
--- /dev/null
+++ b/xen/include/public/viommu.h
@@ -0,0 +1,38 @@ 
+/*
+ * include/public/viommu.h
+ *
+ * Copyright (c) 2017 Intel Corporation
+ * Author: Lan Tianyu <tianyu.lan@intel.com> 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __XEN_PUBLIC_VIOMMU_H__
+#define __XEN_PUBLIC_VIOMMU_H__
+
+/* VIOMMU capabilities*/
+#define VIOMMU_CAP_IRQ_REMAPPING  (1 << 0)
+
+#endif /* __XEN_PUBLIC_VIOMMU_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 0929c0b..a2e9cdc 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -21,6 +21,7 @@ 
 #include <xen/perfc.h>
 #include <asm/atomic.h>
 #include <xen/wait.h>
+#include <xen/viommu.h>
 #include <public/xen.h>
 #include <public/domctl.h>
 #include <public/sysctl.h>
@@ -481,6 +482,7 @@  struct domain
     /* vNUMA topology accesses are protected by rwlock. */
     rwlock_t vnuma_rwlock;
     struct vnuma_info *vnuma;
+    struct viommu_info viommu;
 
     /* Common monitor options */
     struct {
diff --git a/xen/include/xen/viommu.h b/xen/include/xen/viommu.h
new file mode 100644
index 0000000..a0abbdf
--- /dev/null
+++ b/xen/include/xen/viommu.h
@@ -0,0 +1,62 @@ 
+/*
+ * include/xen/viommu.h
+ *
+ * Copyright (c) 2017, Intel Corporation
+ * Author: Lan Tianyu <tianyu.lan@intel.com> 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#ifndef __XEN_VIOMMU_H__
+#define __XEN_VIOMMU_H__
+
+#include <asm/viommu.h>
+
+#define NR_VIOMMU_PER_DOMAIN 1
+
+struct viommu {
+    u64 base_address;
+    u64 length;
+    u64 caps;
+    u32 viommu_id;
+    void *priv;
+};
+
+struct viommu_ops {
+    u64 (*query_caps)(struct domain *d);
+    int (*create)(struct domain *d, struct viommu *viommu);
+    int (*destroy)(struct viommu *viommu);
+};
+
+struct viommu_info {
+    u32 nr_viommu;
+    struct viommu *viommu[NR_VIOMMU_PER_DOMAIN]; /* viommu array*/
+    const struct viommu_ops *ops;     /* viommu_ops */
+};
+
+int viommu_init_domain(struct domain *d);
+int viommu_create(struct domain *d, u64 base_address, u64 length, u64 caps);
+int viommu_destroy(struct domain *d, u32 viommu_id);
+u64 viommu_query_caps(struct domain *d);
+
+#endif /* __XEN_VIOMMU_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */