ia64/xen-unstable

changeset 19557:226ef307cd2e

AMD IOMMU: Fix ioapic interrupt remapping

A few ioapic redirection entries are initialized by hypervisor before
enabling iommu hardware. This patch copies those entries from ioapic
redirection table into interrupt remapping table after interrupt
remapping table has been allocated.

Signed-off-by: Wei Wang <wei.wang2@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Apr 17 13:16:39 2009 +0100 (2009-04-17)
parents b44db970f6b7
children ec9c4b76355b
files xen/drivers/passthrough/amd/iommu_intr.c
line diff
     1.1 --- a/xen/drivers/passthrough/amd/iommu_intr.c	Fri Apr 17 13:14:01 2009 +0100
     1.2 +++ b/xen/drivers/passthrough/amd/iommu_intr.c	Fri Apr 17 13:16:39 2009 +0100
     1.3 @@ -108,8 +108,17 @@ static void update_intremap_entry_from_i
     1.4      return;
     1.5  }
     1.6  
     1.7 +extern int nr_ioapic_registers[MAX_IO_APICS];
     1.8 +extern int nr_ioapics;
     1.9 +
    1.10  int __init amd_iommu_setup_intremap_table(void)
    1.11  {
    1.12 +    struct IO_APIC_route_entry rte = {0};
    1.13 +    unsigned long flags;
    1.14 +    u32* entry;
    1.15 +    int apic, pin;
    1.16 +    u8 delivery_mode, dest, vector, dest_mode;
    1.17 +
    1.18      if ( int_remap_table == NULL )
    1.19      {
    1.20          int_remap_table = __alloc_amd_iommu_tables(INTREMAP_TABLE_ORDER);
    1.21 @@ -118,6 +127,31 @@ int __init amd_iommu_setup_intremap_tabl
    1.22          memset(int_remap_table, 0, PAGE_SIZE * (1UL << INTREMAP_TABLE_ORDER));
    1.23      }
    1.24  
    1.25 +    /* Read ioapic entries and update interrupt remapping table accordingly */
    1.26 +    for ( apic = 0; apic < nr_ioapics; apic++ )
    1.27 +    {
    1.28 +        for ( pin = 0; pin < nr_ioapic_registers[apic]; pin++ )
    1.29 +        {
    1.30 +            *(((int *)&rte) + 1) = io_apic_read(apic, 0x11 + 2 * pin);
    1.31 +            *(((int *)&rte) + 0) = io_apic_read(apic, 0x10 + 2 * pin);
    1.32 +
    1.33 +            if ( rte.mask == 1 )
    1.34 +                continue;
    1.35 +
    1.36 +            delivery_mode = rte.delivery_mode;
    1.37 +            vector = rte.vector;
    1.38 +            dest_mode = rte.dest_mode;
    1.39 +            if ( dest_mode == 0 )
    1.40 +                dest = rte.dest.physical.physical_dest & 0xf;
    1.41 +            else
    1.42 +                dest = rte.dest.logical.logical_dest & 0xff;
    1.43 +
    1.44 +            spin_lock_irqsave(&int_remap_table_lock, flags);
    1.45 +            entry = (u32*)get_intremap_entry(vector, delivery_mode);
    1.46 +            update_intremap_entry(entry, vector, delivery_mode, dest_mode, dest);
    1.47 +            spin_unlock_irqrestore(&int_remap_table_lock, flags);
    1.48 +        }
    1.49 +    }
    1.50      return 0;
    1.51  }
    1.52