From: "Jan Beulich" Subject: [PATCH v2 2/3] x86/HPET: allow use for broadcast when interrupt remapping is in effect Date: Wed, 17 Oct 2012 12:47:07 +0100 Message-ID: <507EB6DB02000078000A1F4A@nat28.tlf.novell.com> References: <507D93C102000078000A1BAB@nat28.tlf.novell.com> <507D94FE02000078000A1BC1@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part774654AB.1__=" Return-path: In-Reply-To: <507D94FE02000078000A1BC1@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: xiantao.zhang@intel.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part774654AB.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This requires some additions to the VT-d side; AMD IOMMUs use the "normal" MSI message format even when interrupt remapping is enabled, thus making adjustments here unnecessary. Signed-off-by: Jan Beulich --- v2: refresh after updating patch 1 of this series (patch 3 is unchanged) --- a/xen/arch/x86/acpi/boot.c +++ b/xen/arch/x86/acpi/boot.c @@ -276,6 +276,7 @@ static int __init acpi_parse_hpet(struct } =20 hpet_address =3D hpet_tbl->address.address; + hpet_blockid =3D hpet_tbl->sequence; printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n", hpet_tbl->id, hpet_address); =20 --- a/xen/arch/x86/hpet.c +++ b/xen/arch/x86/hpet.c @@ -40,7 +40,7 @@ struct hpet_event_channel =20 unsigned int idx; /* physical channel idx */ unsigned int cpu; /* msi target */ - int irq; /* msi irq */ + struct msi_desc msi;/* msi state */ unsigned int flags; /* HPET_EVT_x */ } __cacheline_aligned; static struct hpet_event_channel *__read_mostly hpet_events; @@ -51,6 +51,7 @@ static unsigned int __read_mostly num_hp DEFINE_PER_CPU(struct hpet_event_channel *, cpu_bc_channel); =20 unsigned long __read_mostly hpet_address; +u8 __initdata hpet_blockid; =20 /* * force_hpet_broadcast: by default legacy hpet broadcast will be stopped @@ -252,6 +253,8 @@ static void hpet_msi_mask(struct irq_des =20 static void hpet_msi_write(struct hpet_event_channel *ch, struct msi_msg = *msg) { + if ( iommu_intremap ) + iommu_update_ire_from_msi(&ch->msi, msg); hpet_write32(msg->data, HPET_Tn_ROUTE(ch->idx)); hpet_write32(msg->address_lo, HPET_Tn_ROUTE(ch->idx) + 4); } @@ -261,6 +264,8 @@ static void hpet_msi_read(struct hpet_ev msg->data =3D hpet_read32(HPET_Tn_ROUTE(ch->idx)); msg->address_lo =3D hpet_read32(HPET_Tn_ROUTE(ch->idx) + 4); msg->address_hi =3D 0; + if ( iommu_intremap ) + iommu_read_msi_from_ire(&ch->msi, msg); } =20 static unsigned int hpet_msi_startup(struct irq_desc *desc) @@ -292,6 +297,7 @@ static void hpet_msi_set_affinity(struct msg.data |=3D MSI_DATA_VECTOR(desc->arch.vector); msg.address_lo &=3D ~MSI_ADDR_DEST_ID_MASK; msg.address_lo |=3D MSI_ADDR_DEST_ID(dest); + msg.dest32 =3D dest; hpet_msi_write(desc->action->dev_id, &msg); } =20 @@ -316,35 +322,48 @@ static void __hpet_setup_msi_irq(struct=20 hpet_msi_write(desc->action->dev_id, &msg); } =20 -static int __init hpet_setup_msi_irq(unsigned int irq, struct hpet_event_c= hannel *ch) +static int __init hpet_setup_msi_irq(struct hpet_event_channel *ch) { int ret; - irq_desc_t *desc =3D irq_to_desc(irq); + irq_desc_t *desc =3D irq_to_desc(ch->msi.irq); + + if ( iommu_intremap ) + { + ch->msi.hpet_id =3D hpet_blockid; + ret =3D iommu_setup_hpet_msi(&ch->msi); + if ( ret ) + return ret; + } =20 desc->handler =3D &hpet_msi_type; - ret =3D request_irq(irq, hpet_interrupt_handler, 0, "HPET", ch); + ret =3D request_irq(ch->msi.irq, hpet_interrupt_handler, 0, "HPET", = ch); if ( ret < 0 ) + { + if ( iommu_intremap ) + iommu_update_ire_from_msi(&ch->msi, NULL); return ret; + } =20 __hpet_setup_msi_irq(desc); =20 return 0; } =20 -static int __init hpet_assign_irq(unsigned int idx) +static int __init hpet_assign_irq(struct hpet_event_channel *ch) { int irq; =20 if ( (irq =3D create_irq(NUMA_NO_NODE)) < 0 ) return irq; =20 - if ( hpet_setup_msi_irq(irq, hpet_events + idx) ) + ch->msi.irq =3D irq; + if ( hpet_setup_msi_irq(ch) ) { destroy_irq(irq); return -EINVAL; } =20 - return irq; + return 0; } =20 static void __init hpet_fsb_cap_lookup(void) @@ -352,14 +371,6 @@ static void __init hpet_fsb_cap_lookup(v u32 id; unsigned int i, num_chs; =20 - /* TODO. */ - if ( iommu_intremap ) - { - printk(XENLOG_INFO "HPET's MSI mode hasn't been supported when " - "Interrupt Remapping is enabled.\n"); - return; - } - id =3D hpet_read32(HPET_ID); =20 num_chs =3D ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT); @@ -391,8 +402,8 @@ static void __init hpet_fsb_cap_lookup(v ch->flags =3D 0; ch->idx =3D i; =20 - if ( (ch->irq =3D hpet_assign_irq(num_hpets_used++)) < 0 ) - num_hpets_used--; + if ( hpet_assign_irq(ch) =3D=3D 0 ) + num_hpets_used++; } =20 printk(XENLOG_INFO "HPET: %u timers (%u will be used for broadcast)\n"= , @@ -438,7 +449,7 @@ static struct hpet_event_channel *hpet_g =20 static void set_channel_irq_affinity(const struct hpet_event_channel *ch) { - struct irq_desc *desc =3D irq_to_desc(ch->irq); + struct irq_desc *desc =3D irq_to_desc(ch->msi.irq); =20 ASSERT(!local_irq_is_enabled()); spin_lock(&desc->lock); @@ -530,7 +541,7 @@ void __init hpet_broadcast_init(void) hpet_events =3D xzalloc(struct hpet_event_channel); if ( !hpet_events || !zalloc_cpumask_var(&hpet_events->cpumask) ) return; - hpet_events->irq =3D -1; + hpet_events->msi.irq =3D -1; =20 /* Start HPET legacy interrupts */ cfg |=3D HPET_CFG_LEGACY; @@ -598,8 +609,8 @@ void hpet_broadcast_resume(void) =20 for ( i =3D 0; i < n; i++ ) { - if ( hpet_events[i].irq >=3D 0 ) - __hpet_setup_msi_irq(irq_to_desc(hpet_events[i].irq)); + if ( hpet_events[i].msi.irq >=3D 0 ) + __hpet_setup_msi_irq(irq_to_desc(hpet_events[i].msi.irq)); =20 /* set HPET Tn as oneshot */ cfg =3D hpet_read32(HPET_Tn_CFG(hpet_events[i].idx)); --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -495,6 +495,12 @@ unsigned int iommu_read_apic_from_ire(un return ops->read_apic_from_ire(apic, reg); } =20 +int __init iommu_setup_hpet_msi(struct msi_desc *msi) +{ + const struct iommu_ops *ops =3D iommu_get_ops(); + return ops->setup_hpet_msi ? ops->setup_hpet_msi(msi) : 0; +} + void iommu_resume() { const struct iommu_ops *ops =3D iommu_get_ops(); --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -147,6 +147,34 @@ struct iommu * ioapic_to_iommu(unsigned=20 return NULL; } =20 +static bool_t acpi_hpet_device_match( + struct list_head *list, unsigned int hpet_id) +{ + struct acpi_hpet_unit *hpet; + + list_for_each_entry( hpet, list, list ) + if (hpet->id =3D=3D hpet_id) + return 1; + return 0; +} + +struct acpi_drhd_unit *hpet_to_drhd(unsigned int hpet_id) +{ + struct acpi_drhd_unit *drhd; + + list_for_each_entry( drhd, &acpi_drhd_units, list ) + if ( acpi_hpet_device_match(&drhd->hpet_list, hpet_id) ) + return drhd; + return NULL; +} + +struct iommu *hpet_to_iommu(unsigned int hpet_id) +{ + struct acpi_drhd_unit *drhd =3D hpet_to_drhd(hpet_id); + + return drhd ? drhd->iommu : NULL; +} + static int __init acpi_register_atsr_unit(struct acpi_atsr_unit *atsr) { /* @@ -330,6 +358,22 @@ static int __init acpi_parse_dev_scope( if ( iommu_verbose ) dprintk(VTDPREFIX, " MSI HPET: %04x:%02x:%02x.%u\n", seg, bus, path->dev, path->fn); + + if ( type =3D=3D DMAR_TYPE ) + { + struct acpi_drhd_unit *drhd =3D acpi_entry; + struct acpi_hpet_unit *acpi_hpet_unit; + + acpi_hpet_unit =3D xmalloc(struct acpi_hpet_unit); + if ( !acpi_hpet_unit ) + return -ENOMEM; + acpi_hpet_unit->id =3D acpi_scope->enumeration_id; + acpi_hpet_unit->bus =3D bus; + acpi_hpet_unit->dev =3D path->dev; + acpi_hpet_unit->func =3D path->fn; + list_add(&acpi_hpet_unit->list, &drhd->hpet_list); + } + break; =20 case ACPI_DMAR_SCOPE_TYPE_ENDPOINT: @@ -407,6 +451,7 @@ acpi_parse_one_drhd(struct acpi_dmar_hea dmaru->segment =3D drhd->segment; dmaru->include_all =3D drhd->flags & ACPI_DMAR_INCLUDE_ALL; INIT_LIST_HEAD(&dmaru->ioapic_list); + INIT_LIST_HEAD(&dmaru->hpet_list); if ( iommu_verbose ) dprintk(VTDPREFIX, " dmaru->address =3D %"PRIx64"\n", dmaru->address); --- a/xen/drivers/passthrough/vtd/dmar.h +++ b/xen/drivers/passthrough/vtd/dmar.h @@ -39,6 +39,19 @@ struct acpi_ioapic_unit { }ioapic; }; =20 +struct acpi_hpet_unit { + struct list_head list; + unsigned int id; + union { + u16 bdf; + struct { + u16 func: 3, + dev: 5, + bus: 8; + }; + }; +}; + struct dmar_scope { DECLARE_BITMAP(buses, 256); /* buses owned by this unit */ u16 *devices; /* devices owned by this unit */ @@ -53,6 +66,7 @@ struct acpi_drhd_unit { u8 include_all:1; struct iommu *iommu; struct list_head ioapic_list; + struct list_head hpet_list; }; =20 struct acpi_rmrr_unit { --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -54,7 +54,9 @@ int iommu_flush_iec_index(struct iommu * void clear_fault_bits(struct iommu *iommu); =20 struct iommu * ioapic_to_iommu(unsigned int apic_id); +struct iommu * hpet_to_iommu(unsigned int hpet_id); struct acpi_drhd_unit * ioapic_to_drhd(unsigned int apic_id); +struct acpi_drhd_unit * hpet_to_drhd(unsigned int hpet_id); struct acpi_drhd_unit * iommu_to_drhd(struct iommu *iommu); struct acpi_rhsa_unit * drhd_to_rhsa(struct acpi_drhd_unit *drhd); =20 @@ -90,6 +92,8 @@ struct msi_msg; void msi_msg_read_remap_rte(struct msi_desc *, struct msi_msg *); void msi_msg_write_remap_rte(struct msi_desc *, struct msi_msg *); =20 +int intel_setup_hpet_msi(struct msi_desc *); + int is_igd_vt_enabled_quirk(void); void platform_quirks_init(void); void vtd_ops_preamble_quirk(struct iommu* iommu); --- a/xen/drivers/passthrough/vtd/intremap.c +++ b/xen/drivers/passthrough/vtd/intremap.c @@ -107,6 +107,19 @@ static u16 apicid_to_bdf(int apic_id) return 0; } =20 +static u16 hpetid_to_bdf(unsigned int hpet_id) +{ + struct acpi_drhd_unit *drhd =3D hpet_to_drhd(hpet_id); + struct acpi_hpet_unit *acpi_hpet_unit; + + list_for_each_entry ( acpi_hpet_unit, &drhd->hpet_list, list ) + if ( acpi_hpet_unit->id =3D=3D hpet_id ) + return acpi_hpet_unit->bdf; + + dprintk(XENLOG_ERR VTDPREFIX, "Didn't find the bdf for HPET %u!\n", = hpet_id); + return 0; +} + static void set_ire_sid(struct iremap_entry *ire, unsigned int svt, unsigned int sq, unsigned int = sid) { @@ -121,6 +134,16 @@ static void set_ioapic_source_id(int api apicid_to_bdf(apic_id)); } =20 +static void set_hpet_source_id(unsigned int id, struct iremap_entry *ire) +{ + /* + * Should really use SQ_ALL_16. Some platforms are broken. + * While we figure out the right quirks for these broken platforms, = use + * SQ_13_IGNORE_3 for now. + */ + set_ire_sid(ire, SVT_VERIFY_SID_SQ, SQ_13_IGNORE_3, hpetid_to_bdf(id))= ; +} + int iommu_supports_eim(void) { struct acpi_drhd_unit *drhd; @@ -592,7 +615,10 @@ static int msi_msg_to_remap_entry( new_ire.lo.dst =3D ((msg->address_lo >> MSI_ADDR_DEST_ID_SHIFT) & 0xff) << 8; =20 - set_msi_source_id(pdev, &new_ire); + if ( pdev ) + set_msi_source_id(pdev, &new_ire); + else + set_hpet_source_id(msi_desc->hpet_id, &new_ire); new_ire.hi.res_1 =3D 0; new_ire.lo.p =3D 1; /* finally, set present bit */ =20 @@ -624,7 +650,9 @@ void msi_msg_read_remap_rte( struct iommu *iommu =3D NULL; struct ir_ctrl *ir_ctrl; =20 - if ( (drhd =3D acpi_find_matched_drhd_unit(pdev)) =3D=3D NULL ) + drhd =3D pdev ? acpi_find_matched_drhd_unit(pdev) + : hpet_to_drhd(msi_desc->hpet_id); + if ( !drhd ) return; iommu =3D drhd->iommu; =20 @@ -643,7 +671,9 @@ void msi_msg_write_remap_rte( struct iommu *iommu =3D NULL; struct ir_ctrl *ir_ctrl; =20 - if ( (drhd =3D acpi_find_matched_drhd_unit(pdev)) =3D=3D NULL ) + drhd =3D pdev ? acpi_find_matched_drhd_unit(pdev) + : hpet_to_drhd(msi_desc->hpet_id); + if ( !drhd ) return; iommu =3D drhd->iommu; =20 @@ -654,6 +684,32 @@ void msi_msg_write_remap_rte( msi_msg_to_remap_entry(iommu, pdev, msi_desc, msg); } =20 +int __init intel_setup_hpet_msi(struct msi_desc *msi_desc) +{ + struct iommu *iommu =3D hpet_to_iommu(msi_desc->hpet_id); + struct ir_ctrl *ir_ctrl =3D iommu_ir_ctrl(iommu); + unsigned long flags; + int rc =3D 0; + + if ( !ir_ctrl || !ir_ctrl->iremap_maddr ) + return 0; + + spin_lock_irqsave(&ir_ctrl->iremap_lock, flags); + msi_desc->remap_index =3D alloc_remap_entry(iommu); + if ( msi_desc->remap_index >=3D IREMAP_ENTRY_NR ) + { + dprintk(XENLOG_ERR VTDPREFIX, + "%s: intremap index (%d) is larger than" + " the maximum index (%d)!\n", + __func__, msi_desc->remap_index, IREMAP_ENTRY_NR - 1); + msi_desc->remap_index =3D -1; + rc =3D -ENXIO; + } + spin_unlock_irqrestore(&ir_ctrl->iremap_lock, flags); + + return rc; +} + int enable_intremap(struct iommu *iommu, int eim) { struct acpi_drhd_unit *drhd; --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2396,6 +2396,7 @@ const struct iommu_ops intel_iommu_ops =3D .update_ire_from_msi =3D msi_msg_write_remap_rte, .read_apic_from_ire =3D io_apic_read_remap_rte, .read_msi_from_ire =3D msi_msg_read_remap_rte, + .setup_hpet_msi =3D intel_setup_hpet_msi, .suspend =3D vtd_suspend, .resume =3D vtd_resume, .share_p2m =3D iommu_set_pgd, --- a/xen/include/asm-x86/hpet.h +++ b/xen/include/asm-x86/hpet.h @@ -53,6 +53,7 @@ (*(volatile u32 *)(fix_to_virt(FIX_HPET_BASE) + (x)) =3D (y)) =20 extern unsigned long hpet_address; +extern u8 hpet_blockid; =20 /* * Detect and initialise HPET hardware: return counter update frequency. --- a/xen/include/asm-x86/msi.h +++ b/xen/include/asm-x86/msi.h @@ -97,7 +97,10 @@ struct msi_desc { =20 struct list_head list; =20 - void __iomem *mask_base; /* va for the entry in mask table = */ + union { + void __iomem *mask_base;/* va for the entry in mask table = */ + unsigned int hpet_id; /* HPET (dev is NULL) = */ + }; struct pci_dev *dev; int irq; =20 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -109,6 +109,7 @@ struct iommu_ops { void (*update_ire_from_msi)(struct msi_desc *msi_desc, struct msi_msg = *msg); void (*read_msi_from_ire)(struct msi_desc *msi_desc, struct msi_msg = *msg); unsigned int (*read_apic_from_ire)(unsigned int apic, unsigned int = reg); + int (*setup_hpet_msi)(struct msi_desc *); void (*suspend)(void); void (*resume)(void); void (*share_p2m)(struct domain *d); @@ -122,6 +123,7 @@ void iommu_update_ire_from_apic(unsigned void iommu_update_ire_from_msi(struct msi_desc *msi_desc, struct msi_msg = *msg); void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg = *msg); unsigned int iommu_read_apic_from_ire(unsigned int apic, unsigned int = reg); +int iommu_setup_hpet_msi(struct msi_desc *); =20 void iommu_suspend(void); void iommu_resume(void); --=__Part774654AB.1__= Content-Type: text/plain; name="x86-HPET-intremap.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-HPET-intremap.patch" x86/HPET: allow use for broadcast when interrupt remapping is in = effect=0A=0AThis requires some additions to the VT-d side; AMD IOMMUs use = the=0A"normal" MSI message format even when interrupt remapping is = enabled,=0Athus making adjustments here unnecessary.=0A=0ASigned-off-by: = Jan Beulich =0A---=0Av2: refresh after updating patch 1 = of this series (patch 3 is unchanged)=0A=0A--- a/xen/arch/x86/acpi/boot.c= =0A+++ b/xen/arch/x86/acpi/boot.c=0A@@ -276,6 +276,7 @@ static int __init = acpi_parse_hpet(struct=0A }=0A =0A hpet_address =3D hpet_tbl->= address.address;=0A+ hpet_blockid =3D hpet_tbl->sequence;=0A = printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",=0A = hpet_tbl->id, hpet_address);=0A =0A--- a/xen/arch/x86/hpet.c=0A+++ = b/xen/arch/x86/hpet.c=0A@@ -40,7 +40,7 @@ struct hpet_event_channel=0A =0A = unsigned int idx; /* physical channel idx */=0A unsigned int = cpu; /* msi target */=0A- int irq; /* msi irq */=0A+ = struct msi_desc msi;/* msi state */=0A unsigned int flags; /* = HPET_EVT_x */=0A } __cacheline_aligned;=0A static struct hpet_event_channel= *__read_mostly hpet_events;=0A@@ -51,6 +51,7 @@ static unsigned int = __read_mostly num_hp=0A DEFINE_PER_CPU(struct hpet_event_channel *, = cpu_bc_channel);=0A =0A unsigned long __read_mostly hpet_address;=0A+u8 = __initdata hpet_blockid;=0A =0A /*=0A * force_hpet_broadcast: by default = legacy hpet broadcast will be stopped=0A@@ -252,6 +253,8 @@ static void = hpet_msi_mask(struct irq_des=0A =0A static void hpet_msi_write(struct = hpet_event_channel *ch, struct msi_msg *msg)=0A {=0A+ if ( iommu_intrema= p )=0A+ iommu_update_ire_from_msi(&ch->msi, msg);=0A hpet_write3= 2(msg->data, HPET_Tn_ROUTE(ch->idx));=0A hpet_write32(msg->address_lo, = HPET_Tn_ROUTE(ch->idx) + 4);=0A }=0A@@ -261,6 +264,8 @@ static void = hpet_msi_read(struct hpet_ev=0A msg->data =3D hpet_read32(HPET_Tn_ROUTE= (ch->idx));=0A msg->address_lo =3D hpet_read32(HPET_Tn_ROUTE(ch->idx) = + 4);=0A msg->address_hi =3D 0;=0A+ if ( iommu_intremap )=0A+ = iommu_read_msi_from_ire(&ch->msi, msg);=0A }=0A =0A static unsigned int = hpet_msi_startup(struct irq_desc *desc)=0A@@ -292,6 +297,7 @@ static void = hpet_msi_set_affinity(struct=0A msg.data |=3D MSI_DATA_VECTOR(desc->arc= h.vector);=0A msg.address_lo &=3D ~MSI_ADDR_DEST_ID_MASK;=0A = msg.address_lo |=3D MSI_ADDR_DEST_ID(dest);=0A+ msg.dest32 =3D dest;=0A = hpet_msi_write(desc->action->dev_id, &msg);=0A }=0A =0A@@ -316,35 = +322,48 @@ static void __hpet_setup_msi_irq(struct =0A hpet_msi_write(d= esc->action->dev_id, &msg);=0A }=0A =0A-static int __init hpet_setup_msi_ir= q(unsigned int irq, struct hpet_event_channel *ch)=0A+static int __init = hpet_setup_msi_irq(struct hpet_event_channel *ch)=0A {=0A int ret;=0A- = irq_desc_t *desc =3D irq_to_desc(irq);=0A+ irq_desc_t *desc =3D = irq_to_desc(ch->msi.irq);=0A+=0A+ if ( iommu_intremap )=0A+ {=0A+ = ch->msi.hpet_id =3D hpet_blockid;=0A+ ret =3D iommu_setup_hpet_m= si(&ch->msi);=0A+ if ( ret )=0A+ return ret;=0A+ }=0A = =0A desc->handler =3D &hpet_msi_type;=0A- ret =3D request_irq(irq, = hpet_interrupt_handler, 0, "HPET", ch);=0A+ ret =3D request_irq(ch->msi.= irq, hpet_interrupt_handler, 0, "HPET", ch);=0A if ( ret < 0 )=0A+ = {=0A+ if ( iommu_intremap )=0A+ iommu_update_ire_from_msi= (&ch->msi, NULL);=0A return ret;=0A+ }=0A =0A __hpet_setup_m= si_irq(desc);=0A =0A return 0;=0A }=0A =0A-static int __init hpet_assig= n_irq(unsigned int idx)=0A+static int __init hpet_assign_irq(struct = hpet_event_channel *ch)=0A {=0A int irq;=0A =0A if ( (irq =3D = create_irq(NUMA_NO_NODE)) < 0 )=0A return irq;=0A =0A- if ( = hpet_setup_msi_irq(irq, hpet_events + idx) )=0A+ ch->msi.irq =3D = irq;=0A+ if ( hpet_setup_msi_irq(ch) )=0A {=0A destroy_irq(i= rq);=0A return -EINVAL;=0A }=0A =0A- return irq;=0A+ = return 0;=0A }=0A =0A static void __init hpet_fsb_cap_lookup(void)=0A@@ = -352,14 +371,6 @@ static void __init hpet_fsb_cap_lookup(v=0A u32 = id;=0A unsigned int i, num_chs;=0A =0A- /* TODO. */=0A- if ( = iommu_intremap )=0A- {=0A- printk(XENLOG_INFO "HPET's MSI mode = hasn't been supported when "=0A- "Interrupt Remapping is = enabled.\n");=0A- return;=0A- }=0A-=0A id =3D hpet_read32(HPE= T_ID);=0A =0A num_chs =3D ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIF= T);=0A@@ -391,8 +402,8 @@ static void __init hpet_fsb_cap_lookup(v=0A = ch->flags =3D 0;=0A ch->idx =3D i;=0A =0A- if ( (ch->irq = =3D hpet_assign_irq(num_hpets_used++)) < 0 )=0A- num_hpets_used-= -;=0A+ if ( hpet_assign_irq(ch) =3D=3D 0 )=0A+ num_hpets_= used++;=0A }=0A =0A printk(XENLOG_INFO "HPET: %u timers (%u will = be used for broadcast)\n",=0A@@ -438,7 +449,7 @@ static struct hpet_event_c= hannel *hpet_g=0A =0A static void set_channel_irq_affinity(const struct = hpet_event_channel *ch)=0A {=0A- struct irq_desc *desc =3D irq_to_desc(c= h->irq);=0A+ struct irq_desc *desc =3D irq_to_desc(ch->msi.irq);=0A =0A = ASSERT(!local_irq_is_enabled());=0A spin_lock(&desc->lock);=0A@@ = -530,7 +541,7 @@ void __init hpet_broadcast_init(void)=0A = hpet_events =3D xzalloc(struct hpet_event_channel);=0A if ( = !hpet_events || !zalloc_cpumask_var(&hpet_events->cpumask) )=0A = return;=0A- hpet_events->irq =3D -1;=0A+ hpet_events->msi.ir= q =3D -1;=0A =0A /* Start HPET legacy interrupts */=0A cfg = |=3D HPET_CFG_LEGACY;=0A@@ -598,8 +609,8 @@ void hpet_broadcast_resume(void= )=0A =0A for ( i =3D 0; i < n; i++ )=0A {=0A- if ( = hpet_events[i].irq >=3D 0 )=0A- __hpet_setup_msi_irq(irq_to_desc= (hpet_events[i].irq));=0A+ if ( hpet_events[i].msi.irq >=3D 0 )=0A+ = __hpet_setup_msi_irq(irq_to_desc(hpet_events[i].msi.irq));=0A = =0A /* set HPET Tn as oneshot */=0A cfg =3D hpet_read32(HPE= T_Tn_CFG(hpet_events[i].idx));=0A--- a/xen/drivers/passthrough/iommu.c=0A++= + b/xen/drivers/passthrough/iommu.c=0A@@ -495,6 +495,12 @@ unsigned int = iommu_read_apic_from_ire(un=0A return ops->read_apic_from_ire(apic, = reg);=0A }=0A =0A+int __init iommu_setup_hpet_msi(struct msi_desc = *msi)=0A+{=0A+ const struct iommu_ops *ops =3D iommu_get_ops();=0A+ = return ops->setup_hpet_msi ? ops->setup_hpet_msi(msi) : 0;=0A+}=0A+=0A = void iommu_resume()=0A {=0A const struct iommu_ops *ops =3D iommu_get_o= ps();=0A--- a/xen/drivers/passthrough/vtd/dmar.c=0A+++ b/xen/drivers/passth= rough/vtd/dmar.c=0A@@ -147,6 +147,34 @@ struct iommu * ioapic_to_iommu(unsi= gned =0A return NULL;=0A }=0A =0A+static bool_t acpi_hpet_device_match(= =0A+ struct list_head *list, unsigned int hpet_id)=0A+{=0A+ struct = acpi_hpet_unit *hpet;=0A+=0A+ list_for_each_entry( hpet, list, list = )=0A+ if (hpet->id =3D=3D hpet_id)=0A+ return 1;=0A+ = return 0;=0A+}=0A+=0A+struct acpi_drhd_unit *hpet_to_drhd(unsigned int = hpet_id)=0A+{=0A+ struct acpi_drhd_unit *drhd;=0A+=0A+ list_for_each_= entry( drhd, &acpi_drhd_units, list )=0A+ if ( acpi_hpet_device_matc= h(&drhd->hpet_list, hpet_id) )=0A+ return drhd;=0A+ return = NULL;=0A+}=0A+=0A+struct iommu *hpet_to_iommu(unsigned int hpet_id)=0A+{=0A= + struct acpi_drhd_unit *drhd =3D hpet_to_drhd(hpet_id);=0A+=0A+ = return drhd ? drhd->iommu : NULL;=0A+}=0A+=0A static int __init acpi_regist= er_atsr_unit(struct acpi_atsr_unit *atsr)=0A {=0A /*=0A@@ -330,6 = +358,22 @@ static int __init acpi_parse_dev_scope(=0A if ( = iommu_verbose )=0A dprintk(VTDPREFIX, " MSI HPET: = %04x:%02x:%02x.%u\n",=0A seg, bus, path->dev, = path->fn);=0A+=0A+ if ( type =3D=3D DMAR_TYPE )=0A+ = {=0A+ struct acpi_drhd_unit *drhd =3D acpi_entry;=0A+ = struct acpi_hpet_unit *acpi_hpet_unit;=0A+=0A+ = acpi_hpet_unit =3D xmalloc(struct acpi_hpet_unit);=0A+ if ( = !acpi_hpet_unit )=0A+ return -ENOMEM;=0A+ = acpi_hpet_unit->id =3D acpi_scope->enumeration_id;=0A+ = acpi_hpet_unit->bus =3D bus;=0A+ acpi_hpet_unit->dev =3D = path->dev;=0A+ acpi_hpet_unit->func =3D path->fn;=0A+ = list_add(&acpi_hpet_unit->list, &drhd->hpet_list);=0A+ = }=0A+=0A break;=0A =0A case ACPI_DMAR_SCOPE_TYPE_ENDPOI= NT:=0A@@ -407,6 +451,7 @@ acpi_parse_one_drhd(struct acpi_dmar_hea=0A = dmaru->segment =3D drhd->segment;=0A dmaru->include_all =3D drhd->flags= & ACPI_DMAR_INCLUDE_ALL;=0A INIT_LIST_HEAD(&dmaru->ioapic_list);=0A+ = INIT_LIST_HEAD(&dmaru->hpet_list);=0A if ( iommu_verbose )=0A = dprintk(VTDPREFIX, " dmaru->address =3D %"PRIx64"\n",=0A = dmaru->address);=0A--- a/xen/drivers/passthrough/vtd/dmar.h=0A+++ = b/xen/drivers/passthrough/vtd/dmar.h=0A@@ -39,6 +39,19 @@ struct acpi_ioapi= c_unit {=0A }ioapic;=0A };=0A =0A+struct acpi_hpet_unit {=0A+ = struct list_head list;=0A+ unsigned int id;=0A+ union {=0A+ = u16 bdf;=0A+ struct {=0A+ u16 func: 3,=0A+ = dev: 5,=0A+ bus: 8;=0A+ };=0A+ };=0A+};=0A+=0A = struct dmar_scope {=0A DECLARE_BITMAP(buses, 256); /* buses = owned by this unit */=0A u16 *devices; /* = devices owned by this unit */=0A@@ -53,6 +66,7 @@ struct acpi_drhd_unit = {=0A u8 include_all:1;=0A struct iommu *iommu;=0A struct = list_head ioapic_list;=0A+ struct list_head hpet_list;=0A };=0A =0A = struct acpi_rmrr_unit {=0A--- a/xen/drivers/passthrough/vtd/extern.h=0A+++ = b/xen/drivers/passthrough/vtd/extern.h=0A@@ -54,7 +54,9 @@ int iommu_flush_= iec_index(struct iommu *=0A void clear_fault_bits(struct iommu *iommu);=0A = =0A struct iommu * ioapic_to_iommu(unsigned int apic_id);=0A+struct iommu = * hpet_to_iommu(unsigned int hpet_id);=0A struct acpi_drhd_unit * = ioapic_to_drhd(unsigned int apic_id);=0A+struct acpi_drhd_unit * hpet_to_dr= hd(unsigned int hpet_id);=0A struct acpi_drhd_unit * iommu_to_drhd(struct = iommu *iommu);=0A struct acpi_rhsa_unit * drhd_to_rhsa(struct acpi_drhd_uni= t *drhd);=0A =0A@@ -90,6 +92,8 @@ struct msi_msg;=0A void msi_msg_read_rema= p_rte(struct msi_desc *, struct msi_msg *);=0A void msi_msg_write_remap_rte= (struct msi_desc *, struct msi_msg *);=0A =0A+int intel_setup_hpet_msi(stru= ct msi_desc *);=0A+=0A int is_igd_vt_enabled_quirk(void);=0A void = platform_quirks_init(void);=0A void vtd_ops_preamble_quirk(struct iommu* = iommu);=0A--- a/xen/drivers/passthrough/vtd/intremap.c=0A+++ b/xen/drivers/= passthrough/vtd/intremap.c=0A@@ -107,6 +107,19 @@ static u16 apicid_to_bdf(= int apic_id)=0A return 0;=0A }=0A =0A+static u16 hpetid_to_bdf(unsigned= int hpet_id)=0A+{=0A+ struct acpi_drhd_unit *drhd =3D hpet_to_drhd(hpet= _id);=0A+ struct acpi_hpet_unit *acpi_hpet_unit;=0A+=0A+ list_for_eac= h_entry ( acpi_hpet_unit, &drhd->hpet_list, list )=0A+ if ( = acpi_hpet_unit->id =3D=3D hpet_id )=0A+ return acpi_hpet_unit->b= df;=0A+=0A+ dprintk(XENLOG_ERR VTDPREFIX, "Didn't find the bdf for HPET = %u!\n", hpet_id);=0A+ return 0;=0A+}=0A+=0A static void set_ire_sid(stru= ct iremap_entry *ire,=0A unsigned int svt, = unsigned int sq, unsigned int sid)=0A {=0A@@ -121,6 +134,16 @@ static void = set_ioapic_source_id(int api=0A apicid_to_bdf(apic_id));=0A= }=0A =0A+static void set_hpet_source_id(unsigned int id, struct iremap_ent= ry *ire)=0A+{=0A+ /*=0A+ * Should really use SQ_ALL_16. Some = platforms are broken.=0A+ * While we figure out the right quirks for = these broken platforms, use=0A+ * SQ_13_IGNORE_3 for now.=0A+ = */=0A+ set_ire_sid(ire, SVT_VERIFY_SID_SQ, SQ_13_IGNORE_3, hpetid_to_bdf= (id));=0A+}=0A+=0A int iommu_supports_eim(void)=0A {=0A struct = acpi_drhd_unit *drhd;=0A@@ -592,7 +615,10 @@ static int msi_msg_to_remap_en= try(=0A new_ire.lo.dst =3D ((msg->address_lo >> MSI_ADDR_DEST_ID_SH= IFT)=0A & 0xff) << 8;=0A =0A- set_msi_source_i= d(pdev, &new_ire);=0A+ if ( pdev )=0A+ set_msi_source_id(pdev, = &new_ire);=0A+ else=0A+ set_hpet_source_id(msi_desc->hpet_id, = &new_ire);=0A new_ire.hi.res_1 =3D 0;=0A new_ire.lo.p =3D 1; /* = finally, set present bit */=0A =0A@@ -624,7 +650,9 @@ void msi_msg_read_rem= ap_rte(=0A struct iommu *iommu =3D NULL;=0A struct ir_ctrl = *ir_ctrl;=0A =0A- if ( (drhd =3D acpi_find_matched_drhd_unit(pdev)) = =3D=3D NULL )=0A+ drhd =3D pdev ? acpi_find_matched_drhd_unit(pdev)=0A+ = : hpet_to_drhd(msi_desc->hpet_id);=0A+ if ( !drhd )=0A = return;=0A iommu =3D drhd->iommu;=0A =0A@@ -643,7 +671,9 @@ void = msi_msg_write_remap_rte(=0A struct iommu *iommu =3D NULL;=0A = struct ir_ctrl *ir_ctrl;=0A =0A- if ( (drhd =3D acpi_find_matched_drhd_u= nit(pdev)) =3D=3D NULL )=0A+ drhd =3D pdev ? acpi_find_matched_drhd_unit= (pdev)=0A+ : hpet_to_drhd(msi_desc->hpet_id);=0A+ if ( = !drhd )=0A return;=0A iommu =3D drhd->iommu;=0A =0A@@ -654,6 = +684,32 @@ void msi_msg_write_remap_rte(=0A msi_msg_to_remap_entry(iomm= u, pdev, msi_desc, msg);=0A }=0A =0A+int __init intel_setup_hpet_msi(struct= msi_desc *msi_desc)=0A+{=0A+ struct iommu *iommu =3D hpet_to_iommu(msi_= desc->hpet_id);=0A+ struct ir_ctrl *ir_ctrl =3D iommu_ir_ctrl(iommu);=0A= + unsigned long flags;=0A+ int rc =3D 0;=0A+=0A+ if ( !ir_ctrl || = !ir_ctrl->iremap_maddr )=0A+ return 0;=0A+=0A+ spin_lock_irqsave(= &ir_ctrl->iremap_lock, flags);=0A+ msi_desc->remap_index =3D alloc_remap= _entry(iommu);=0A+ if ( msi_desc->remap_index >=3D IREMAP_ENTRY_NR = )=0A+ {=0A+ dprintk(XENLOG_ERR VTDPREFIX,=0A+ = "%s: intremap index (%d) is larger than"=0A+ " the maximum = index (%d)!\n",=0A+ __func__, msi_desc->remap_index, = IREMAP_ENTRY_NR - 1);=0A+ msi_desc->remap_index =3D -1;=0A+ = rc =3D -ENXIO;=0A+ }=0A+ spin_unlock_irqrestore(&ir_ctrl->iremap_lock= , flags);=0A+=0A+ return rc;=0A+}=0A+=0A int enable_intremap(struct = iommu *iommu, int eim)=0A {=0A struct acpi_drhd_unit *drhd;=0A--- = a/xen/drivers/passthrough/vtd/iommu.c=0A+++ b/xen/drivers/passthrough/vtd/i= ommu.c=0A@@ -2396,6 +2396,7 @@ const struct iommu_ops intel_iommu_ops = =3D=0A .update_ire_from_msi =3D msi_msg_write_remap_rte,=0A = .read_apic_from_ire =3D io_apic_read_remap_rte,=0A .read_msi_from_ire = =3D msi_msg_read_remap_rte,=0A+ .setup_hpet_msi =3D intel_setup_hpet_msi= ,=0A .suspend =3D vtd_suspend,=0A .resume =3D vtd_resume,=0A = .share_p2m =3D iommu_set_pgd,=0A--- a/xen/include/asm-x86/hpet.h=0A+++ = b/xen/include/asm-x86/hpet.h=0A@@ -53,6 +53,7 @@=0A (*(volatile u32 = *)(fix_to_virt(FIX_HPET_BASE) + (x)) =3D (y))=0A =0A extern unsigned long = hpet_address;=0A+extern u8 hpet_blockid;=0A =0A /*=0A * Detect and = initialise HPET hardware: return counter update frequency.=0A--- a/xen/incl= ude/asm-x86/msi.h=0A+++ b/xen/include/asm-x86/msi.h=0A@@ -97,7 +97,10 @@ = struct msi_desc {=0A =0A struct list_head list;=0A =0A- void = __iomem *mask_base; /* va for the entry in mask table */=0A+ = union {=0A+ void __iomem *mask_base;/* va for the entry in = mask table */=0A+ unsigned int hpet_id; /* HPET (dev is = NULL) */=0A+ };=0A struct pci_dev *dev;=0A = int irq;=0A =0A--- a/xen/include/xen/iommu.h=0A+++ b/xen/include/xen/iommu.= h=0A@@ -109,6 +109,7 @@ struct iommu_ops {=0A void (*update_ire_from_ms= i)(struct msi_desc *msi_desc, struct msi_msg *msg);=0A void (*read_msi_= from_ire)(struct msi_desc *msi_desc, struct msi_msg *msg);=0A unsigned = int (*read_apic_from_ire)(unsigned int apic, unsigned int reg);=0A+ int = (*setup_hpet_msi)(struct msi_desc *);=0A void (*suspend)(void);=0A = void (*resume)(void);=0A void (*share_p2m)(struct domain *d);=0A@@ = -122,6 +123,7 @@ void iommu_update_ire_from_apic(unsigned=0A void = iommu_update_ire_from_msi(struct msi_desc *msi_desc, struct msi_msg = *msg);=0A void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct = msi_msg *msg);=0A unsigned int iommu_read_apic_from_ire(unsigned int apic, = unsigned int reg);=0A+int iommu_setup_hpet_msi(struct msi_desc *);=0A =0A = void iommu_suspend(void);=0A void iommu_resume(void);=0A --=__Part774654AB.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part774654AB.1__=--