debuggers.hg
changeset 19640:40d4267296ad
vt-d: Fix interrupt remapping for multiple IOAPICs
Current IOAPIC interrupt remapping code assumes there is only one
IOAPIC in system. It brings problem when there are more than one
IOAPIC in system. This patch extends ioapic_pin_to_intremap_index[]
array to handle multiple IOAPICs case.
Signed-off-by: Weidong Han <weidong.han@intel.com>
Current IOAPIC interrupt remapping code assumes there is only one
IOAPIC in system. It brings problem when there are more than one
IOAPIC in system. This patch extends ioapic_pin_to_intremap_index[]
array to handle multiple IOAPICs case.
Signed-off-by: Weidong Han <weidong.han@intel.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Fri May 15 08:12:39 2009 +0100 (2009-05-15) |
parents | b7f4937d76d1 |
children | 9890a1e5b6ab |
files | xen/drivers/passthrough/vtd/intremap.c |
line diff
1.1 --- a/xen/drivers/passthrough/vtd/intremap.c Thu May 14 15:46:43 2009 +0100 1.2 +++ b/xen/drivers/passthrough/vtd/intremap.c Fri May 15 08:12:39 2009 +0100 1.3 @@ -23,6 +23,7 @@ 1.4 #include <xen/iommu.h> 1.5 #include <asm/hvm/iommu.h> 1.6 #include <xen/time.h> 1.7 +#include <xen/list.h> 1.8 #include <xen/pci.h> 1.9 #include <xen/pci_regs.h> 1.10 #include "iommu.h" 1.11 @@ -40,8 +41,64 @@ 1.12 */ 1.13 #define MAX_IOAPIC_PIN_NUM 256 1.14 1.15 -static int ioapic_pin_to_intremap_index[MAX_IOAPIC_PIN_NUM] = 1.16 - { [0 ... MAX_IOAPIC_PIN_NUM-1] = -1 }; 1.17 +struct ioapicid_pin_intremap_index { 1.18 + struct list_head list; 1.19 + unsigned int ioapic_id; 1.20 + unsigned int pin; 1.21 + int intremap_index; 1.22 +}; 1.23 + 1.24 +static struct list_head ioapic_pin_to_intremap_index[MAX_IOAPIC_PIN_NUM]; 1.25 + 1.26 +static int init_ioapic_pin_intremap_index(void) 1.27 +{ 1.28 + static int initialized = 0; 1.29 + int i; 1.30 + 1.31 + if ( initialized == 1 ) 1.32 + return 0; 1.33 + 1.34 + for ( i = 0; i < MAX_IOAPIC_PIN_NUM; i++ ) 1.35 + INIT_LIST_HEAD(&ioapic_pin_to_intremap_index[i]); 1.36 + 1.37 + initialized = 1; 1.38 + return 0; 1.39 +} 1.40 + 1.41 +static int get_ioapic_pin_intremap_index(unsigned int ioapic_id, 1.42 + unsigned int pin) 1.43 +{ 1.44 + struct ioapicid_pin_intremap_index *entry; 1.45 + struct list_head *pos, *tmp; 1.46 + 1.47 + list_for_each_safe ( pos, tmp, &ioapic_pin_to_intremap_index[pin] ) 1.48 + { 1.49 + entry = list_entry(pos, struct ioapicid_pin_intremap_index, list); 1.50 + if ( entry->ioapic_id == ioapic_id ) 1.51 + return entry->intremap_index; 1.52 + } 1.53 + 1.54 + return -1; 1.55 +} 1.56 + 1.57 +static int set_ioapic_pin_intremap_index(unsigned int ioapic_id, 1.58 + unsigned int pin, 1.59 + int index) 1.60 +{ 1.61 + struct ioapicid_pin_intremap_index *entry; 1.62 + 1.63 + entry = xmalloc(struct ioapicid_pin_intremap_index); 1.64 + if ( !entry ) 1.65 + return -ENOMEM; 1.66 + 1.67 + entry->ioapic_id = ioapic_id; 1.68 + entry->pin = pin; 1.69 + entry->intremap_index = index; 1.70 + 1.71 + list_add_tail(&entry->list, &ioapic_pin_to_intremap_index[pin]); 1.72 + 1.73 + return 0; 1.74 +} 1.75 1.76 u16 apicid_to_bdf(int apic_id) 1.77 { 1.78 @@ -117,14 +174,13 @@ static int ioapic_rte_to_remap_entry(str 1.79 remap_rte = (struct IO_APIC_route_remap_entry *) old_rte; 1.80 spin_lock_irqsave(&ir_ctrl->iremap_lock, flags); 1.81 1.82 - if ( ioapic_pin_to_intremap_index[ioapic_pin] < 0 ) 1.83 + index = get_ioapic_pin_intremap_index(apic_id, ioapic_pin); 1.84 + if ( index < 0 ) 1.85 { 1.86 ir_ctrl->iremap_index++; 1.87 index = ir_ctrl->iremap_index; 1.88 - ioapic_pin_to_intremap_index[ioapic_pin] = index; 1.89 + set_ioapic_pin_intremap_index(apic_id, ioapic_pin, index); 1.90 } 1.91 - else 1.92 - index = ioapic_pin_to_intremap_index[ioapic_pin]; 1.93 1.94 if ( index > IREMAP_ENTRY_NR - 1 ) 1.95 { 1.96 @@ -572,6 +628,8 @@ int enable_intremap(struct iommu *iommu) 1.97 /* After set SIRTP, we should do globally invalidate the IEC */ 1.98 iommu_flush_iec_global(iommu); 1.99 1.100 + init_ioapic_pin_intremap_index(); 1.101 + 1.102 return 0; 1.103 } 1.104