debuggers.hg

changeset 22269:4beee5779122

Vt-d: fix dom0 graphics problem on Levnovo T410.

The patch is derived from a similar quirk in Linux kernel by David
Woodhouse and Adam Jackson. It checks for VT enabling bit in IGD GGC
register. If VT is not enabled correctly in the IGD, Xen does not
enable VT-d translation for IGD VT-d engine. In case where iommu boot
parameter is set to force, Xen calls panic().

Signed-off-by: Allen Kay <allen.m.kay@intel.com>
author Keir Fraser <keir@xen.org>
date Sat Oct 02 15:04:21 2010 +0100 (2010-10-02)
parents aed9fd361340
children a4016a257672
files xen/drivers/passthrough/vtd/dmar.c xen/drivers/passthrough/vtd/dmar.h xen/drivers/passthrough/vtd/iommu.c
line diff
     1.1 --- a/xen/drivers/passthrough/vtd/dmar.c	Sat Oct 02 15:03:15 2010 +0100
     1.2 +++ b/xen/drivers/passthrough/vtd/dmar.c	Sat Oct 02 15:04:21 2010 +0100
     1.3 @@ -46,6 +46,7 @@ LIST_HEAD(acpi_rmrr_units);
     1.4  LIST_HEAD(acpi_atsr_units);
     1.5  LIST_HEAD(acpi_rhsa_units);
     1.6  
     1.7 +static u64 igd_drhd_address;
     1.8  u8 dmar_host_address_width;
     1.9  
    1.10  void dmar_scope_add_buses(struct dmar_scope *scope, u16 sec_bus, u16 sub_bus)
    1.11 @@ -239,6 +240,11 @@ struct acpi_rhsa_unit * drhd_to_rhsa(str
    1.12      return NULL;
    1.13  }
    1.14  
    1.15 +int is_igd_drhd(struct acpi_drhd_unit *drhd)
    1.16 +{
    1.17 +    return ( drhd->address == igd_drhd_address ? 1 : 0);
    1.18 +}
    1.19 +
    1.20  /*
    1.21   * Count number of devices in device scope.  Do not include PCI sub
    1.22   * hierarchies.
    1.23 @@ -272,7 +278,8 @@ static int scope_device_count(void *star
    1.24  
    1.25  
    1.26  static int __init acpi_parse_dev_scope(void *start, void *end,
    1.27 -                                       void *acpi_entry, int type)
    1.28 +                                       void *acpi_entry, int type,
    1.29 +                                       int *igd)
    1.30  {
    1.31      struct dmar_scope *scope = acpi_entry;
    1.32      struct acpi_ioapic_unit *acpi_ioapic_unit;
    1.33 @@ -333,6 +340,8 @@ static int __init acpi_parse_dev_scope(v
    1.34              if ( iommu_verbose )
    1.35                  dprintk(VTDPREFIX, "  endpoint: %x:%x.%x\n",
    1.36                          bus, path->dev, path->fn);
    1.37 +            if ( (bus == 0) && (path->dev == 2) && (path->fn == 0) )
    1.38 +                *igd = 1;
    1.39              break;
    1.40  
    1.41          case ACPI_DEV_IOAPIC:
    1.42 @@ -379,7 +388,7 @@ acpi_parse_one_drhd(struct acpi_dmar_ent
    1.43      struct acpi_table_drhd * drhd = (struct acpi_table_drhd *)header;
    1.44      void *dev_scope_start, *dev_scope_end;
    1.45      struct acpi_drhd_unit *dmaru;
    1.46 -    int ret;
    1.47 +    int ret, igd = 0;
    1.48      static int include_all = 0;
    1.49  
    1.50      if ( (ret = acpi_dmar_check_length(header, sizeof(*drhd))) != 0 )
    1.51 @@ -404,7 +413,10 @@ acpi_parse_one_drhd(struct acpi_dmar_ent
    1.52      dev_scope_start = (void *)(drhd + 1);
    1.53      dev_scope_end = ((void *)drhd) + header->length;
    1.54      ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
    1.55 -                               dmaru, DMAR_TYPE);
    1.56 +                               dmaru, DMAR_TYPE, &igd);
    1.57 +
    1.58 +    if ( igd )
    1.59 +        igd_drhd_address = dmaru->address;
    1.60  
    1.61      if ( dmaru->include_all )
    1.62      {
    1.63 @@ -492,7 +504,7 @@ acpi_parse_one_rmrr(struct acpi_dmar_ent
    1.64      struct acpi_rmrr_unit *rmrru;
    1.65      void *dev_scope_start, *dev_scope_end;
    1.66      u64 base_addr = rmrr->base_address, end_addr = rmrr->end_address;
    1.67 -    int ret;
    1.68 +    int ret, igd = 0;
    1.69  
    1.70      if ( (ret = acpi_dmar_check_length(header, sizeof(*rmrr))) != 0 )
    1.71          return ret;
    1.72 @@ -524,7 +536,7 @@ acpi_parse_one_rmrr(struct acpi_dmar_ent
    1.73      dev_scope_start = (void *)(rmrr + 1);
    1.74      dev_scope_end   = ((void *)rmrr) + header->length;
    1.75      ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
    1.76 -                               rmrru, RMRR_TYPE);
    1.77 +                               rmrru, RMRR_TYPE, &igd);
    1.78  
    1.79      if ( ret || (rmrru->scope.devices_cnt == 0) )
    1.80          xfree(rmrru);
    1.81 @@ -589,7 +601,7 @@ acpi_parse_one_atsr(struct acpi_dmar_ent
    1.82  {
    1.83      struct acpi_table_atsr *atsr = (struct acpi_table_atsr *)header;
    1.84      struct acpi_atsr_unit *atsru;
    1.85 -    int ret;
    1.86 +    int ret, igd = 0;
    1.87      static int all_ports;
    1.88      void *dev_scope_start, *dev_scope_end;
    1.89  
    1.90 @@ -610,7 +622,7 @@ acpi_parse_one_atsr(struct acpi_dmar_ent
    1.91          dev_scope_start = (void *)(atsr + 1);
    1.92          dev_scope_end   = ((void *)atsr) + header->length;
    1.93          ret = acpi_parse_dev_scope(dev_scope_start, dev_scope_end,
    1.94 -                                   atsru, ATSR_TYPE);
    1.95 +                                   atsru, ATSR_TYPE, &igd);
    1.96      }
    1.97      else
    1.98      {
     2.1 --- a/xen/drivers/passthrough/vtd/dmar.h	Sat Oct 02 15:03:15 2010 +0100
     2.2 +++ b/xen/drivers/passthrough/vtd/dmar.h	Sat Oct 02 15:04:21 2010 +0100
     2.3 @@ -114,5 +114,6 @@ void *map_to_nocache_virt(int nr_iommus,
     2.4  int vtd_hw_check(void);
     2.5  void disable_pmr(struct iommu *iommu);
     2.6  int is_usb_device(u8 bus, u8 devfn);
     2.7 +int is_igd_drhd(struct acpi_drhd_unit *drhd);
     2.8  
     2.9  #endif /* _DMAR_H_ */
     3.1 --- a/xen/drivers/passthrough/vtd/iommu.c	Sat Oct 02 15:03:15 2010 +0100
     3.2 +++ b/xen/drivers/passthrough/vtd/iommu.c	Sat Oct 02 15:04:21 2010 +0100
     3.3 @@ -689,10 +689,34 @@ static int iommu_set_root_entry(struct i
     3.4      return 0;
     3.5  }
     3.6  
     3.7 -static void iommu_enable_translation(struct iommu *iommu)
     3.8 +#define GGC 0x52
     3.9 +#define GGC_MEMORY_VT_ENABLED  (0x8 << 8)
    3.10 +static int is_igd_vt_enabled(void)
    3.11 +{
    3.12 +    unsigned short ggc;
    3.13 +
    3.14 +    /* integrated graphics on Intel platforms is located at 0:2.0 */
    3.15 +    ggc = pci_conf_read16(0, 2, 0, GGC);
    3.16 +    return ( ggc & GGC_MEMORY_VT_ENABLED ? 1 : 0 );
    3.17 +}
    3.18 +
    3.19 +static void iommu_enable_translation(struct acpi_drhd_unit *drhd)
    3.20  {
    3.21      u32 sts;
    3.22      unsigned long flags;
    3.23 +    struct iommu *iommu = drhd->iommu;
    3.24 +
    3.25 +    if ( !is_igd_vt_enabled() && is_igd_drhd(drhd) ) 
    3.26 +    {
    3.27 +        if ( force_iommu )
    3.28 +            panic("BIOS did not enable IGD for VT properly, crash Xen for security purpose!\n");
    3.29 +        else
    3.30 +        {
    3.31 +            dprintk(XENLOG_WARNING VTDPREFIX,
    3.32 +                    "BIOS did not enable IGD for VT properly.  Disabling IGD VT-d engine.\n");
    3.33 +            return;
    3.34 +        }
    3.35 +    }
    3.36  
    3.37      if ( iommu_verbose )
    3.38          dprintk(VTDPREFIX,
    3.39 @@ -1179,7 +1203,6 @@ static int intel_iommu_domain_init(struc
    3.40  
    3.41  static void intel_iommu_dom0_init(struct domain *d)
    3.42  {
    3.43 -    struct iommu *iommu;
    3.44      struct acpi_drhd_unit *drhd;
    3.45  
    3.46      if ( !iommu_passthrough && !need_iommu(d) )
    3.47 @@ -1195,8 +1218,7 @@ static void intel_iommu_dom0_init(struct
    3.48  
    3.49      for_each_drhd_unit ( drhd )
    3.50      {
    3.51 -        iommu = drhd->iommu;
    3.52 -        iommu_enable_translation(iommu);
    3.53 +        iommu_enable_translation(drhd);
    3.54      }
    3.55  }
    3.56  
    3.57 @@ -2165,7 +2187,7 @@ static void vtd_resume(void)
    3.58                      (u32) iommu_state[i][DMAR_FEUADDR_REG]);
    3.59          spin_unlock_irqrestore(&iommu->register_lock, flags);
    3.60  
    3.61 -        iommu_enable_translation(iommu);
    3.62 +        iommu_enable_translation(drhd);
    3.63      }
    3.64  }
    3.65