xref: /qemu/include/hw/i386/x86-iommu.h (revision fb9f592623b0f9bb82a88d68d7921fb581918ef5)
11c7955c4SPeter Xu /*
21c7955c4SPeter Xu  * Common IOMMU interface for X86 platform
31c7955c4SPeter Xu  *
41c7955c4SPeter Xu  * Copyright (C) 2016 Peter Xu, Red Hat <peterx@redhat.com>
51c7955c4SPeter Xu  *
61c7955c4SPeter Xu  * This program is free software; you can redistribute it and/or modify
71c7955c4SPeter Xu  * it under the terms of the GNU General Public License as published by
81c7955c4SPeter Xu  * the Free Software Foundation; either version 2 of the License, or
91c7955c4SPeter Xu  * (at your option) any later version.
101c7955c4SPeter Xu 
111c7955c4SPeter Xu  * This program is distributed in the hope that it will be useful,
121c7955c4SPeter Xu  * but WITHOUT ANY WARRANTY; without even the implied warranty of
131c7955c4SPeter Xu  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
141c7955c4SPeter Xu  * GNU General Public License for more details.
151c7955c4SPeter Xu 
161c7955c4SPeter Xu  * You should have received a copy of the GNU General Public License along
171c7955c4SPeter Xu  * with this program; if not, see <http://www.gnu.org/licenses/>.
181c7955c4SPeter Xu  */
191c7955c4SPeter Xu 
201c7955c4SPeter Xu #ifndef IOMMU_COMMON_H
211c7955c4SPeter Xu #define IOMMU_COMMON_H
221c7955c4SPeter Xu 
231c7955c4SPeter Xu #include "hw/sysbus.h"
248b5ed7dfSPeter Xu #include "hw/pci/pci.h"
251c7955c4SPeter Xu 
261c7955c4SPeter Xu #define  TYPE_X86_IOMMU_DEVICE  ("x86-iommu")
271c7955c4SPeter Xu #define  X86_IOMMU_DEVICE(obj) \
281c7955c4SPeter Xu     OBJECT_CHECK(X86IOMMUState, (obj), TYPE_X86_IOMMU_DEVICE)
291c7955c4SPeter Xu #define  X86_IOMMU_CLASS(klass) \
301c7955c4SPeter Xu     OBJECT_CLASS_CHECK(X86IOMMUClass, (klass), TYPE_X86_IOMMU_DEVICE)
311c7955c4SPeter Xu #define  X86_IOMMU_GET_CLASS(obj) \
321c7955c4SPeter Xu     OBJECT_GET_CLASS(X86IOMMUClass, obj, TYPE_X86_IOMMU_DEVICE)
331c7955c4SPeter Xu 
3404af0e18SPeter Xu #define X86_IOMMU_PCI_DEVFN_MAX           256
358b5ed7dfSPeter Xu #define X86_IOMMU_SID_INVALID             (0xffff)
3604af0e18SPeter Xu 
371c7955c4SPeter Xu typedef struct X86IOMMUState X86IOMMUState;
381c7955c4SPeter Xu typedef struct X86IOMMUClass X86IOMMUClass;
391c7955c4SPeter Xu 
40*fb9f5926SDavid Kiarie typedef enum IommuType {
41*fb9f5926SDavid Kiarie     TYPE_INTEL,
42*fb9f5926SDavid Kiarie     TYPE_AMD,
43*fb9f5926SDavid Kiarie     TYPE_NONE
44*fb9f5926SDavid Kiarie } IommuType;
45*fb9f5926SDavid Kiarie 
461c7955c4SPeter Xu struct X86IOMMUClass {
471c7955c4SPeter Xu     SysBusDeviceClass parent;
481c7955c4SPeter Xu     /* Intel/AMD specific realize() hook */
491c7955c4SPeter Xu     DeviceRealize realize;
508b5ed7dfSPeter Xu     /* MSI-based interrupt remapping */
518b5ed7dfSPeter Xu     int (*int_remap)(X86IOMMUState *iommu, MSIMessage *src,
528b5ed7dfSPeter Xu                      MSIMessage *dst, uint16_t sid);
531c7955c4SPeter Xu };
541c7955c4SPeter Xu 
5502a2cbc8SPeter Xu /**
5602a2cbc8SPeter Xu  * iec_notify_fn - IEC (Interrupt Entry Cache) notifier hook,
5702a2cbc8SPeter Xu  *                 triggered when IR invalidation happens.
5802a2cbc8SPeter Xu  * @private: private data
5902a2cbc8SPeter Xu  * @global: whether this is a global IEC invalidation
6002a2cbc8SPeter Xu  * @index: IRTE index to invalidate (start from)
6102a2cbc8SPeter Xu  * @mask: invalidation mask
6202a2cbc8SPeter Xu  */
6302a2cbc8SPeter Xu typedef void (*iec_notify_fn)(void *private, bool global,
6402a2cbc8SPeter Xu                               uint32_t index, uint32_t mask);
6502a2cbc8SPeter Xu 
6602a2cbc8SPeter Xu struct IEC_Notifier {
6702a2cbc8SPeter Xu     iec_notify_fn iec_notify;
6802a2cbc8SPeter Xu     void *private;
6902a2cbc8SPeter Xu     QLIST_ENTRY(IEC_Notifier) list;
7002a2cbc8SPeter Xu };
7102a2cbc8SPeter Xu typedef struct IEC_Notifier IEC_Notifier;
7202a2cbc8SPeter Xu 
731c7955c4SPeter Xu struct X86IOMMUState {
741c7955c4SPeter Xu     SysBusDevice busdev;
751121e0afSPeter Xu     bool intr_supported;        /* Whether vIOMMU supports IR */
76*fb9f5926SDavid Kiarie     IommuType type;             /* IOMMU type - AMD/Intel     */
7702a2cbc8SPeter Xu     QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */
781c7955c4SPeter Xu };
791c7955c4SPeter Xu 
801cf5fd57SPeter Xu /**
811cf5fd57SPeter Xu  * x86_iommu_get_default - get default IOMMU device
821cf5fd57SPeter Xu  * @return: pointer to default IOMMU device
831cf5fd57SPeter Xu  */
841cf5fd57SPeter Xu X86IOMMUState *x86_iommu_get_default(void);
851cf5fd57SPeter Xu 
86*fb9f5926SDavid Kiarie /*
87*fb9f5926SDavid Kiarie  * x86_iommu_get_type - get IOMMU type
88*fb9f5926SDavid Kiarie  */
89*fb9f5926SDavid Kiarie IommuType x86_iommu_get_type(void);
90*fb9f5926SDavid Kiarie 
9102a2cbc8SPeter Xu /**
9202a2cbc8SPeter Xu  * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry
9302a2cbc8SPeter Xu  *                                   Cache) notifiers
9402a2cbc8SPeter Xu  * @iommu: IOMMU device to register
9502a2cbc8SPeter Xu  * @fn: IEC notifier hook function
9602a2cbc8SPeter Xu  * @data: notifier private data
9702a2cbc8SPeter Xu  */
9802a2cbc8SPeter Xu void x86_iommu_iec_register_notifier(X86IOMMUState *iommu,
9902a2cbc8SPeter Xu                                      iec_notify_fn fn, void *data);
10002a2cbc8SPeter Xu 
10102a2cbc8SPeter Xu /**
10202a2cbc8SPeter Xu  * x86_iommu_iec_notify_all - Notify IEC invalidations
10302a2cbc8SPeter Xu  * @iommu: IOMMU device that sends the notification
10402a2cbc8SPeter Xu  * @global: whether this is a global invalidation. If true, @index
10502a2cbc8SPeter Xu  *          and @mask are undefined.
10602a2cbc8SPeter Xu  * @index: starting index of interrupt entry to invalidate
10702a2cbc8SPeter Xu  * @mask: index mask for the invalidation
10802a2cbc8SPeter Xu  */
10902a2cbc8SPeter Xu void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global,
11002a2cbc8SPeter Xu                               uint32_t index, uint32_t mask);
11102a2cbc8SPeter Xu 
1121c7955c4SPeter Xu #endif
113