xref: /qemu/include/hw/i386/x86-iommu.h (revision 2c533c54)
1 /*
2  * Common IOMMU interface for X86 platform
3  *
4  * Copyright (C) 2016 Peter Xu, Red Hat <peterx@redhat.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15 
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef IOMMU_COMMON_H
21 #define IOMMU_COMMON_H
22 
23 #include "hw/sysbus.h"
24 #include "hw/pci/pci.h"
25 
26 #define  TYPE_X86_IOMMU_DEVICE  ("x86-iommu")
27 #define  X86_IOMMU_DEVICE(obj) \
28     OBJECT_CHECK(X86IOMMUState, (obj), TYPE_X86_IOMMU_DEVICE)
29 #define  X86_IOMMU_CLASS(klass) \
30     OBJECT_CLASS_CHECK(X86IOMMUClass, (klass), TYPE_X86_IOMMU_DEVICE)
31 #define  X86_IOMMU_GET_CLASS(obj) \
32     OBJECT_GET_CLASS(X86IOMMUClass, obj, TYPE_X86_IOMMU_DEVICE)
33 
34 #define X86_IOMMU_PCI_DEVFN_MAX           256
35 #define X86_IOMMU_SID_INVALID             (0xffff)
36 
37 typedef struct X86IOMMUState X86IOMMUState;
38 typedef struct X86IOMMUClass X86IOMMUClass;
39 
40 struct X86IOMMUClass {
41     SysBusDeviceClass parent;
42     /* Intel/AMD specific realize() hook */
43     DeviceRealize realize;
44     /* MSI-based interrupt remapping */
45     int (*int_remap)(X86IOMMUState *iommu, MSIMessage *src,
46                      MSIMessage *dst, uint16_t sid);
47 };
48 
49 /**
50  * iec_notify_fn - IEC (Interrupt Entry Cache) notifier hook,
51  *                 triggered when IR invalidation happens.
52  * @private: private data
53  * @global: whether this is a global IEC invalidation
54  * @index: IRTE index to invalidate (start from)
55  * @mask: invalidation mask
56  */
57 typedef void (*iec_notify_fn)(void *private, bool global,
58                               uint32_t index, uint32_t mask);
59 
60 struct IEC_Notifier {
61     iec_notify_fn iec_notify;
62     void *private;
63     QLIST_ENTRY(IEC_Notifier) list;
64 };
65 typedef struct IEC_Notifier IEC_Notifier;
66 
67 struct X86IOMMUState {
68     SysBusDevice busdev;
69     bool intr_supported;        /* Whether vIOMMU supports IR */
70     QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */
71 };
72 
73 /**
74  * x86_iommu_get_default - get default IOMMU device
75  * @return: pointer to default IOMMU device
76  */
77 X86IOMMUState *x86_iommu_get_default(void);
78 
79 /**
80  * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry
81  *                                   Cache) notifiers
82  * @iommu: IOMMU device to register
83  * @fn: IEC notifier hook function
84  * @data: notifier private data
85  */
86 void x86_iommu_iec_register_notifier(X86IOMMUState *iommu,
87                                      iec_notify_fn fn, void *data);
88 
89 /**
90  * x86_iommu_iec_notify_all - Notify IEC invalidations
91  * @iommu: IOMMU device that sends the notification
92  * @global: whether this is a global invalidation. If true, @index
93  *          and @mask are undefined.
94  * @index: starting index of interrupt entry to invalidate
95  * @mask: index mask for the invalidation
96  */
97 void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global,
98                               uint32_t index, uint32_t mask);
99 
100 #endif
101