ia64/xen-unstable

view xen/drivers/passthrough/vtd/dmar.h @ 19733:a69daf23602a

VT-d: define a macro for waiting hardare completion

When set some registers of VT-d, it must wait for hardware
completion. There are lots of duplicated code to do that. This patch
defines a macro for it, thus it is much cleaner.

Signed-off-by: Weidong Han <weidong.han@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 05 09:27:18 2009 +0100 (2009-06-05)
parents f02a528d2e56
children aa472909b39c
line source
1 /*
2 * Copyright (c) 2006, Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 *
17 * Copyright (C) Ashok Raj <ashok.raj@intel.com>
18 * Copyright (C) Shaohua Li <shaohua.li@intel.com>
19 */
21 #ifndef _DMAR_H_
22 #define _DMAR_H_
24 #include <xen/list.h>
25 #include <xen/iommu.h>
27 extern u8 dmar_host_address_width;
29 /* This one is for interrupt remapping */
30 struct acpi_ioapic_unit {
31 struct list_head list;
32 int apic_id;
33 union {
34 u16 info;
35 struct {
36 u16 func: 3,
37 dev: 5,
38 bus: 8;
39 }bdf;
40 }ioapic;
41 };
43 struct dmar_scope {
44 DECLARE_BITMAP(buses, 256); /* buses owned by this unit */
45 u16 *devices; /* devices owned by this unit */
46 int devices_cnt;
47 };
49 struct acpi_drhd_unit {
50 struct dmar_scope scope; /* must be first member of struct */
51 struct list_head list;
52 u64 address; /* register base address of the unit */
53 u8 include_all:1;
54 struct iommu *iommu;
55 struct list_head ioapic_list;
56 };
58 struct acpi_rmrr_unit {
59 struct dmar_scope scope; /* must be first member of struct */
60 struct list_head list;
61 u64 base_address;
62 u64 end_address;
63 u8 allow_all:1;
64 };
66 struct acpi_atsr_unit {
67 struct dmar_scope scope; /* must be first member of struct */
68 struct list_head list;
69 u8 all_ports:1;
70 };
73 #define for_each_drhd_unit(drhd) \
74 list_for_each_entry(drhd, &acpi_drhd_units, list)
76 #define for_each_rmrr_device(rmrr, bdf, idx) \
77 list_for_each_entry(rmrr, &acpi_rmrr_units, list) \
78 /* assume there never is a bdf == 0 */ \
79 for (idx = 0; (bdf = rmrr->scope.devices[idx]) && \
80 idx < rmrr->scope.devices_cnt; idx++)
82 struct acpi_drhd_unit * acpi_find_matched_drhd_unit(struct pci_dev *pdev);
83 struct acpi_atsr_unit * acpi_find_matched_atsr_unit(u8 bus, u8 devfn);
84 void dmar_scope_add_buses(struct dmar_scope *scope, u16 sec, u16 sub);
85 void dmar_scope_remove_buses(struct dmar_scope *scope, u16 sec, u16 sub);
87 #define DMAR_TYPE 1
88 #define RMRR_TYPE 2
89 #define ATSR_TYPE 3
91 #define DMAR_OPERATION_TIMEOUT MILLISECS(1000)
93 #define IOMMU_WAIT_OP(iommu, offset, op, cond, sts) \
94 do { \
95 s_time_t start_time = NOW(); \
96 while (1) { \
97 sts = op(iommu->reg, offset); \
98 if ( cond ) \
99 break; \
100 if ( NOW() > start_time + DMAR_OPERATION_TIMEOUT ) \
101 panic("%s:%d:%s: DMAR hardware is malfunctional\n", \
102 __FILE__, __LINE__, __func__); \
103 cpu_relax(); \
104 } \
105 } while (0)
107 int vtd_hw_check(void);
108 void disable_pmr(struct iommu *iommu);
109 int is_usb_device(u8 bus, u8 devfn);
111 #endif /* _DMAR_H_ */