[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 1/4] AMD/IOMMU: Move headers to be local
We currently have amd-iommu-defs.h, amd-iommu-proto.h and amd-iommu.h, and no references outside of the AMD IOMMU driver. Keep iommu-defs.h as is, but merge amd-iommu.h and amd-iommu-proto.h to just iommu.h, and move them both into drivers/passthrough/amd/. (While merging, drop the bogus #pragma pack around the *_entry structures.) Take the opportunity to trim the include lists, including x86/mm/p2m.c which (AFAICT) hasn't needed this include since c/s aef3f2275 "x86/mm/p2m: break into common, pt-implementation and pod parts" in 2011. No functional change. Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> --- CC: Jan Beulich <JBeulich@xxxxxxxx> CC: Wei Liu <wl@xxxxxxx> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx> CC: George Dunlap <george.dunlap@xxxxxxxxxxxxx> --- xen/arch/x86/mm/p2m.c | 1 - .../passthrough/amd/iommu-defs.h} | 6 +- .../passthrough/amd/iommu.h} | 179 ++++++++++++++++++- xen/drivers/passthrough/amd/iommu_acpi.c | 7 +- xen/drivers/passthrough/amd/iommu_cmd.c | 4 +- xen/drivers/passthrough/amd/iommu_detect.c | 7 +- xen/drivers/passthrough/amd/iommu_guest.c | 4 +- xen/drivers/passthrough/amd/iommu_init.c | 13 +- xen/drivers/passthrough/amd/iommu_intr.c | 9 +- xen/drivers/passthrough/amd/iommu_map.c | 8 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 9 +- xen/include/asm-x86/amd-iommu.h | 190 --------------------- 12 files changed, 194 insertions(+), 243 deletions(-) rename xen/{include/asm-x86/hvm/svm/amd-iommu-defs.h => drivers/passthrough/amd/iommu-defs.h} (99%) rename xen/{include/asm-x86/hvm/svm/amd-iommu-proto.h => drivers/passthrough/amd/iommu.h} (70%) delete mode 100644 xen/include/asm-x86/amd-iommu.h diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index def13f657b..fd9f09536d 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -38,7 +38,6 @@ #include <asm/mem_sharing.h> #include <asm/hvm/nestedhvm.h> #include <asm/altp2m.h> -#include <asm/hvm/svm/amd-iommu-proto.h> #include <asm/vm_event.h> #include <xsm/xsm.h> diff --git a/xen/include/asm-x86/hvm/svm/amd-iommu-defs.h b/xen/drivers/passthrough/amd/iommu-defs.h similarity index 99% rename from xen/include/asm-x86/hvm/svm/amd-iommu-defs.h rename to xen/drivers/passthrough/amd/iommu-defs.h index 78368f16d9..f8b62cb033 100644 --- a/xen/include/asm-x86/hvm/svm/amd-iommu-defs.h +++ b/xen/drivers/passthrough/amd/iommu-defs.h @@ -17,8 +17,8 @@ * along with this program; If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _ASM_X86_64_AMD_IOMMU_DEFS_H -#define _ASM_X86_64_AMD_IOMMU_DEFS_H +#ifndef AMD_IOMMU_DEFS_H +#define AMD_IOMMU_DEFS_H /* IOMMU Command Buffer entries: in power of 2 increments, minimum of 256 */ #define IOMMU_CMD_BUFFER_DEFAULT_ENTRIES 512 @@ -506,7 +506,7 @@ struct amd_iommu_pte { #define IOMMU_REG_BASE_ADDR_HIGH_MASK 0x000FFFFF #define IOMMU_REG_BASE_ADDR_HIGH_SHIFT 0 -#endif /* _ASM_X86_64_AMD_IOMMU_DEFS_H */ +#endif /* AMD_IOMMU_DEFS_H */ /* * Local variables: diff --git a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h b/xen/drivers/passthrough/amd/iommu.h similarity index 70% rename from xen/include/asm-x86/hvm/svm/amd-iommu-proto.h rename to xen/drivers/passthrough/amd/iommu.h index b5c0d50119..f590de8cbf 100644 --- a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +++ b/xen/drivers/passthrough/amd/iommu.h @@ -16,15 +16,180 @@ * 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 _ASM_X86_64_AMD_IOMMU_PROTO_H -#define _ASM_X86_64_AMD_IOMMU_PROTO_H - +#ifndef AMD_IOMMU_H +#define AMD_IOMMU_H + +#include <xen/init.h> +#include <xen/types.h> +#include <xen/list.h> +#include <xen/spinlock.h> +#include <xen/tasklet.h> #include <xen/sched.h> -#include <asm/amd-iommu.h> -#include <asm/apicdef.h> #include <xen/domain_page.h> +#include <asm/msi.h> +#include <asm/apicdef.h> + +#include "iommu-defs.h" + +#define iommu_found() (!list_empty(&amd_iommu_head)) + +extern struct list_head amd_iommu_head; + +typedef struct event_entry +{ + uint32_t data[4]; +} event_entry_t; + +typedef struct ppr_entry +{ + uint32_t data[4]; +} ppr_entry_t; + +typedef struct cmd_entry +{ + uint32_t data[4]; +} cmd_entry_t; + +struct table_struct { + void *buffer; + unsigned long entries; + unsigned long alloc_size; +}; + +struct ring_buffer { + void *buffer; + unsigned long entries; + unsigned long alloc_size; + uint32_t tail; + uint32_t head; + spinlock_t lock; /* protect buffer pointers */ +}; + +typedef struct iommu_cap { + uint32_t header; /* offset 00h */ + uint32_t base_low; /* offset 04h */ + uint32_t base_hi; /* offset 08h */ + uint32_t range; /* offset 0Ch */ + uint32_t misc; /* offset 10h */ +} iommu_cap_t; + +struct amd_iommu { + struct list_head list; + spinlock_t lock; /* protect iommu */ + + u16 seg; + u16 bdf; + struct msi_desc msi; + + u16 cap_offset; + iommu_cap_t cap; + + u8 ht_flags; + union amd_iommu_ext_features features; + + void *mmio_base; + unsigned long mmio_base_phys; + + union amd_iommu_control ctrl; + + struct table_struct dev_table; + struct ring_buffer cmd_buffer; + struct ring_buffer event_log; + struct ring_buffer ppr_log; + + int exclusion_enable; + int exclusion_allow_all; + uint64_t exclusion_base; + uint64_t exclusion_limit; + + int enabled; + + struct list_head ats_devices; +}; + +struct ivrs_mappings { + uint16_t dte_requestor_id; + bool valid:1; + bool dte_allow_exclusion:1; + bool unity_map_enable:1; + bool write_permission:1; + bool read_permission:1; + + /* ivhd device data settings */ + uint8_t device_flags; + + unsigned long addr_range_start; + unsigned long addr_range_length; + struct amd_iommu *iommu; + + /* per device interrupt remapping table */ + void *intremap_table; + unsigned long *intremap_inuse; + spinlock_t intremap_lock; +}; + +extern unsigned int ivrs_bdf_entries; +extern u8 ivhd_type; + +struct ivrs_mappings *get_ivrs_mappings(u16 seg); +int iterate_ivrs_mappings(int (*)(u16 seg, struct ivrs_mappings *)); +int iterate_ivrs_entries(int (*)(const struct amd_iommu *, + struct ivrs_mappings *, uint16_t)); + +/* iommu tables in guest space */ +struct mmio_reg { + uint32_t lo; + uint32_t hi; +}; + +struct guest_dev_table { + struct mmio_reg reg_base; + uint32_t size; +}; + +struct guest_buffer { + struct mmio_reg reg_base; + struct mmio_reg reg_tail; + struct mmio_reg reg_head; + uint32_t entries; +}; + +struct guest_iommu_msi { + uint8_t vector; + uint8_t dest; + uint8_t dest_mode; + uint8_t delivery_mode; + uint8_t trig_mode; +}; + +/* virtual IOMMU structure */ +struct guest_iommu { + + struct domain *domain; + spinlock_t lock; + bool_t enabled; + + struct guest_dev_table dev_table; + struct guest_buffer cmd_buffer; + struct guest_buffer event_log; + struct guest_buffer ppr_log; + + struct tasklet cmd_buffer_tasklet; + + uint64_t mmio_base; /* MMIO base address */ + + /* MMIO regs */ + union amd_iommu_control reg_ctrl; /* MMIO offset 0018h */ + struct mmio_reg reg_status; /* MMIO offset 2020h */ + union amd_iommu_ext_features reg_ext_feature; /* MMIO offset 0030h */ + + /* guest interrupt settings */ + struct guest_iommu_msi msi; +}; + +extern bool_t iommuv2_enabled; + struct acpi_ivrs_hardware; #define for_each_amd_iommu(amd_iommu) \ @@ -281,4 +446,4 @@ static inline void iommu_set_addr_hi_to_reg(uint32_t *reg, uint32_t addr) IOMMU_REG_BASE_ADDR_HIGH_SHIFT, reg); } -#endif /* _ASM_X86_64_AMD_IOMMU_PROTO_H */ +#endif /* AMD_IOMMU_H */ diff --git a/xen/drivers/passthrough/amd/iommu_acpi.c b/xen/drivers/passthrough/amd/iommu_acpi.c index 6c5f8e46ec..f4abbfd9dc 100644 --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -17,13 +17,12 @@ * along with this program; If not, see <http://www.gnu.org/licenses/>. */ -#include <xen/errno.h> #include <xen/acpi.h> #include <xen/param.h> -#include <asm/apicdef.h> + #include <asm/io_apic.h> -#include <asm/amd-iommu.h> -#include <asm/hvm/svm/amd-iommu-proto.h> + +#include "iommu.h" /* Some helper structures, particularly to deal with ranges. */ diff --git a/xen/drivers/passthrough/amd/iommu_cmd.c b/xen/drivers/passthrough/amd/iommu_cmd.c index af3a1fb865..92eaab407b 100644 --- a/xen/drivers/passthrough/amd/iommu_cmd.c +++ b/xen/drivers/passthrough/amd/iommu_cmd.c @@ -17,9 +17,7 @@ * along with this program; If not, see <http://www.gnu.org/licenses/>. */ -#include <xen/sched.h> -#include <asm/amd-iommu.h> -#include <asm/hvm/svm/amd-iommu-proto.h> +#include "iommu.h" #include "../ats.h" static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[]) diff --git a/xen/drivers/passthrough/amd/iommu_detect.c b/xen/drivers/passthrough/amd/iommu_detect.c index d782e66eee..8312bb4b6f 100644 --- a/xen/drivers/passthrough/amd/iommu_detect.c +++ b/xen/drivers/passthrough/amd/iommu_detect.c @@ -17,13 +17,10 @@ * along with this program; If not, see <http://www.gnu.org/licenses/>. */ -#include <xen/errno.h> #include <xen/acpi.h> -#include <xen/iommu.h> #include <xen/pci.h> -#include <xen/pci_regs.h> -#include <asm/amd-iommu.h> -#include <asm/hvm/svm/amd-iommu-proto.h> + +#include "iommu.h" static int __init get_iommu_msi_capabilities( u16 seg, u8 bus, u8 dev, u8 func, struct amd_iommu *iommu) diff --git a/xen/drivers/passthrough/amd/iommu_guest.c b/xen/drivers/passthrough/amd/iommu_guest.c index 4ed6519e6e..aaf12fe1cb 100644 --- a/xen/drivers/passthrough/amd/iommu_guest.c +++ b/xen/drivers/passthrough/amd/iommu_guest.c @@ -16,11 +16,9 @@ * along with this program; If not, see <http://www.gnu.org/licenses/>. */ -#include <xen/sched.h> #include <asm/p2m.h> -#include <asm/amd-iommu.h> -#include <asm/hvm/svm/amd-iommu-proto.h> +#include "iommu.h" #define IOMMU_MMIO_SIZE 0x8000 #define IOMMU_MMIO_PAGE_NR 0x8 diff --git a/xen/drivers/passthrough/amd/iommu_init.c b/xen/drivers/passthrough/amd/iommu_init.c index 2f26fed4a3..0ffc83a843 100644 --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -17,18 +17,11 @@ * along with this program; If not, see <http://www.gnu.org/licenses/>. */ -#include <xen/errno.h> #include <xen/acpi.h> -#include <xen/keyhandler.h> -#include <xen/pci.h> -#include <xen/pci_regs.h> -#include <xen/irq.h> -#include <asm/amd-iommu.h> -#include <asm/msi.h> -#include <asm/hvm/svm/amd-iommu-proto.h> -#include <asm-x86/fixmap.h> -#include <mach_apic.h> #include <xen/delay.h> +#include <xen/keyhandler.h> + +#include "iommu.h" static int __initdata nr_amd_iommus; static bool __initdata pci_init; diff --git a/xen/drivers/passthrough/amd/iommu_intr.c b/xen/drivers/passthrough/amd/iommu_intr.c index 5e92c023f8..e1cc13b873 100644 --- a/xen/drivers/passthrough/amd/iommu_intr.c +++ b/xen/drivers/passthrough/amd/iommu_intr.c @@ -16,13 +16,12 @@ * along with this program; If not, see <http://www.gnu.org/licenses/>. */ -#include <xen/err.h> -#include <xen/sched.h> -#include <asm/amd-iommu.h> -#include <asm/hvm/svm/amd-iommu-proto.h> -#include <asm/io_apic.h> #include <xen/softirq.h> +#include <asm/io_apic.h> + +#include "iommu.h" + union irte32 { uint32_t raw; struct { diff --git a/xen/drivers/passthrough/amd/iommu_map.c b/xen/drivers/passthrough/amd/iommu_map.c index 4e041b960f..2f3b47b366 100644 --- a/xen/drivers/passthrough/amd/iommu_map.c +++ b/xen/drivers/passthrough/amd/iommu_map.c @@ -18,12 +18,8 @@ */ #include <xen/acpi.h> -#include <xen/sched.h> -#include <asm/p2m.h> -#include <asm/amd-iommu.h> -#include <asm/hvm/svm/amd-iommu-proto.h> -#include "../ats.h" -#include <xen/pci.h> + +#include "iommu.h" /* Given pfn and page table level, return pde index */ static unsigned int pfn_to_pde_idx(unsigned long pfn, unsigned int level) diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index dd3401f0dc..3112653960 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -17,15 +17,12 @@ * along with this program; If not, see <http://www.gnu.org/licenses/>. */ -#include <xen/sched.h> #include <xen/iocap.h> -#include <xen/pci.h> -#include <xen/pci_regs.h> -#include <xen/paging.h> #include <xen/softirq.h> + #include <asm/acpi.h> -#include <asm/amd-iommu.h> -#include <asm/hvm/svm/amd-iommu-proto.h> + +#include "iommu.h" #include "../ats.h" static bool_t __read_mostly init_done; diff --git a/xen/include/asm-x86/amd-iommu.h b/xen/include/asm-x86/amd-iommu.h deleted file mode 100644 index 83ababdc8c..0000000000 --- a/xen/include/asm-x86/amd-iommu.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (C) 2007 Advanced Micro Devices, Inc. - * Author: Leo Duran <leo.duran@xxxxxxx> - * Author: Wei Wang <wei.wang2@xxxxxxx> - adapted to xen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that 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 _ASM_X86_64_AMD_IOMMU_H -#define _ASM_X86_64_AMD_IOMMU_H - -#include <xen/init.h> -#include <xen/types.h> -#include <xen/list.h> -#include <xen/spinlock.h> -#include <xen/tasklet.h> -#include <asm/msi.h> -#include <asm/hvm/svm/amd-iommu-defs.h> - -#define iommu_found() (!list_empty(&amd_iommu_head)) - -extern struct list_head amd_iommu_head; - -#pragma pack(1) -typedef struct event_entry -{ - uint32_t data[4]; -} event_entry_t; - -typedef struct ppr_entry -{ - uint32_t data[4]; -} ppr_entry_t; - -typedef struct cmd_entry -{ - uint32_t data[4]; -} cmd_entry_t; -#pragma pack() - -struct table_struct { - void *buffer; - unsigned long entries; - unsigned long alloc_size; -}; - -struct ring_buffer { - void *buffer; - unsigned long entries; - unsigned long alloc_size; - uint32_t tail; - uint32_t head; - spinlock_t lock; /* protect buffer pointers */ -}; - -typedef struct iommu_cap { - uint32_t header; /* offset 00h */ - uint32_t base_low; /* offset 04h */ - uint32_t base_hi; /* offset 08h */ - uint32_t range; /* offset 0Ch */ - uint32_t misc; /* offset 10h */ -} iommu_cap_t; - -struct amd_iommu { - struct list_head list; - spinlock_t lock; /* protect iommu */ - - u16 seg; - u16 bdf; - struct msi_desc msi; - - u16 cap_offset; - iommu_cap_t cap; - - u8 ht_flags; - union amd_iommu_ext_features features; - - void *mmio_base; - unsigned long mmio_base_phys; - - union amd_iommu_control ctrl; - - struct table_struct dev_table; - struct ring_buffer cmd_buffer; - struct ring_buffer event_log; - struct ring_buffer ppr_log; - - int exclusion_enable; - int exclusion_allow_all; - uint64_t exclusion_base; - uint64_t exclusion_limit; - - int enabled; - - struct list_head ats_devices; -}; - -struct ivrs_mappings { - uint16_t dte_requestor_id; - bool valid:1; - bool dte_allow_exclusion:1; - bool unity_map_enable:1; - bool write_permission:1; - bool read_permission:1; - - /* ivhd device data settings */ - uint8_t device_flags; - - unsigned long addr_range_start; - unsigned long addr_range_length; - struct amd_iommu *iommu; - - /* per device interrupt remapping table */ - void *intremap_table; - unsigned long *intremap_inuse; - spinlock_t intremap_lock; -}; - -extern unsigned int ivrs_bdf_entries; -extern u8 ivhd_type; - -struct ivrs_mappings *get_ivrs_mappings(u16 seg); -int iterate_ivrs_mappings(int (*)(u16 seg, struct ivrs_mappings *)); -int iterate_ivrs_entries(int (*)(const struct amd_iommu *, - struct ivrs_mappings *, uint16_t)); - -/* iommu tables in guest space */ -struct mmio_reg { - uint32_t lo; - uint32_t hi; -}; - -struct guest_dev_table { - struct mmio_reg reg_base; - uint32_t size; -}; - -struct guest_buffer { - struct mmio_reg reg_base; - struct mmio_reg reg_tail; - struct mmio_reg reg_head; - uint32_t entries; -}; - -struct guest_iommu_msi { - uint8_t vector; - uint8_t dest; - uint8_t dest_mode; - uint8_t delivery_mode; - uint8_t trig_mode; -}; - -/* virtual IOMMU structure */ -struct guest_iommu { - - struct domain *domain; - spinlock_t lock; - bool_t enabled; - - struct guest_dev_table dev_table; - struct guest_buffer cmd_buffer; - struct guest_buffer event_log; - struct guest_buffer ppr_log; - - struct tasklet cmd_buffer_tasklet; - - uint64_t mmio_base; /* MMIO base address */ - - /* MMIO regs */ - union amd_iommu_control reg_ctrl; /* MMIO offset 0018h */ - struct mmio_reg reg_status; /* MMIO offset 2020h */ - union amd_iommu_ext_features reg_ext_feature; /* MMIO offset 0030h */ - - /* guest interrupt settings */ - struct guest_iommu_msi msi; -}; - -extern bool_t iommuv2_enabled; - -#endif /* _ASM_X86_64_AMD_IOMMU_H */ -- 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |