From: "Jan Beulich" Subject: [PATCH 4/4] ACPI: eliminate duplicate IVRS definitions Date: Mon, 12 Dec 2011 16:11:30 +0000 Message-ID: <4EE635C20200007800067068@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part456AE0A2.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.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. --=__Part456AE0A2.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Use their proper counterparts in include/acpi/actbl*.h instead. Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/amd/iommu_acpi.c +++ b/xen/drivers/passthrough/amd/iommu_acpi.c @@ -20,10 +20,38 @@ =20 #include #include +#include #include #include #include -#include + +/* Some helper structures, particularly to deal with ranges. */ + +struct acpi_ivhd_device_range { + struct acpi_ivrs_device4 start; + struct acpi_ivrs_device4 end; +}; + +struct acpi_ivhd_device_alias_range { + struct acpi_ivrs_device8a alias; + struct acpi_ivrs_device4 end; +}; + +struct acpi_ivhd_device_extended_range { + struct acpi_ivrs_device8b extended; + struct acpi_ivrs_device4 end; +}; + +union acpi_ivhd_device { + struct acpi_ivrs_de_header header; + struct acpi_ivrs_device4 select; + struct acpi_ivhd_device_range range; + struct acpi_ivrs_device8a alias; + struct acpi_ivhd_device_alias_range alias_range; + struct acpi_ivrs_device8b extended; + struct acpi_ivhd_device_extended_range extended_range; + struct acpi_ivrs_device8c special; +}; =20 static unsigned short __initdata last_bdf; =20 @@ -242,12 +270,12 @@ static int __init register_exclusion_ran } =20 static int __init parse_ivmd_device_select( - struct acpi_ivmd_block_header *ivmd_block, + const struct acpi_ivrs_memory *ivmd_block, unsigned long base, unsigned long limit, u8 iw, u8 ir) { u16 bdf; =20 - bdf =3D ivmd_block->header.dev_id; + bdf =3D ivmd_block->header.device_id; if ( bdf >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVMD Error: Invalid Dev_Id 0x%x\n", bdf); @@ -258,13 +286,13 @@ static int __init parse_ivmd_device_sele } =20 static int __init parse_ivmd_device_range( - struct acpi_ivmd_block_header *ivmd_block, + const struct acpi_ivrs_memory *ivmd_block, unsigned long base, unsigned long limit, u8 iw, u8 ir) { u16 first_bdf, last_bdf, bdf; int error; =20 - first_bdf =3D ivmd_block->header.dev_id; + first_bdf =3D ivmd_block->header.device_id; if ( first_bdf >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVMD Error: " @@ -272,7 +300,7 @@ static int __init parse_ivmd_device_rang return -ENODEV; } =20 - last_bdf =3D ivmd_block->last_dev_id; + last_bdf =3D ivmd_block->aux_data; if ( (last_bdf >=3D ivrs_bdf_entries) || (last_bdf <=3D first_bdf) ) { AMD_IOMMU_DEBUG("IVMD Error: " @@ -288,18 +316,18 @@ static int __init parse_ivmd_device_rang } =20 static int __init parse_ivmd_device_iommu( - struct acpi_ivmd_block_header *ivmd_block, + const struct acpi_ivrs_memory *ivmd_block, unsigned long base, unsigned long limit, u8 iw, u8 ir) { struct amd_iommu *iommu; =20 /* find target IOMMU */ - iommu =3D find_iommu_from_bdf_cap(ivmd_block->header.dev_id, - ivmd_block->cap_offset); + iommu =3D find_iommu_from_bdf_cap(ivmd_block->header.device_id, + ivmd_block->aux_data); if ( !iommu ) { AMD_IOMMU_DEBUG("IVMD Error: No IOMMU for Dev_Id 0x%x Cap = 0x%x\n", - ivmd_block->header.dev_id, ivmd_block->cap_offset)= ; + ivmd_block->header.device_id, ivmd_block->aux_data= ); return -ENODEV; } =20 @@ -307,20 +335,19 @@ static int __init parse_ivmd_device_iomm iommu, base, limit, iw, ir); } =20 -static int __init parse_ivmd_block(struct acpi_ivmd_block_header = *ivmd_block) +static int __init parse_ivmd_block(const struct acpi_ivrs_memory = *ivmd_block) { unsigned long start_addr, mem_length, base, limit; u8 iw, ir; =20 - if ( ivmd_block->header.length < - sizeof(struct acpi_ivmd_block_header) ) + if ( ivmd_block->header.length < sizeof(*ivmd_block) ) { AMD_IOMMU_DEBUG("IVMD Error: Invalid Block Length!\n"); return -ENODEV; } =20 - start_addr =3D (unsigned long)ivmd_block->start_addr; - mem_length =3D (unsigned long)ivmd_block->mem_length; + start_addr =3D (unsigned long)ivmd_block->start_address; + mem_length =3D (unsigned long)ivmd_block->memory_length; base =3D start_addr & PAGE_MASK; limit =3D (start_addr + mem_length - 1) & PAGE_MASK; =20 @@ -328,20 +355,14 @@ static int __init parse_ivmd_block(struc AMD_IOMMU_DEBUG(" Start_Addr_Phys 0x%lx\n", start_addr); AMD_IOMMU_DEBUG(" Mem_Length 0x%lx\n", mem_length); =20 - if ( get_field_from_byte(ivmd_block->header.flags, - AMD_IOMMU_ACPI_EXCLUSION_RANGE_MASK, - AMD_IOMMU_ACPI_EXCLUSION_RANGE_SHIFT) ) + if ( ivmd_block->header.flags & ACPI_IVMD_EXCLUSION_RANGE ) iw =3D ir =3D IOMMU_CONTROL_ENABLED; - else if ( get_field_from_byte(ivmd_block->header.flags, - AMD_IOMMU_ACPI_UNITY_MAPPING_MASK, - AMD_IOMMU_ACPI_UNITY_MAPPING_SHIFT) ) - { - iw =3D get_field_from_byte(ivmd_block->header.flags, - AMD_IOMMU_ACPI_IW_PERMISSION_MASK, - AMD_IOMMU_ACPI_IW_PERMISSION_SHIFT); - ir =3D get_field_from_byte(ivmd_block->header.flags, - AMD_IOMMU_ACPI_IR_PERMISSION_MASK, - AMD_IOMMU_ACPI_IR_PERMISSION_SHIFT); + else if ( ivmd_block->header.flags & ACPI_IVMD_UNITY ) + { + iw =3D ivmd_block->header.flags & ACPI_IVMD_READ ? + IOMMU_CONTROL_ENABLED : IOMMU_CONTROL_DISABLED; + ir =3D ivmd_block->header.flags & ACPI_IVMD_WRITE ? + IOMMU_CONTROL_ENABLED : IOMMU_CONTROL_DISABLED; } else { @@ -351,19 +372,19 @@ static int __init parse_ivmd_block(struc =20 switch( ivmd_block->header.type ) { - case AMD_IOMMU_ACPI_IVMD_ALL_TYPE: + case ACPI_IVRS_TYPE_MEMORY_ALL: return register_exclusion_range_for_all_devices( base, limit, iw, ir); =20 - case AMD_IOMMU_ACPI_IVMD_ONE_TYPE: + case ACPI_IVRS_TYPE_MEMORY_ONE: return parse_ivmd_device_select(ivmd_block, base, limit, iw, ir); =20 - case AMD_IOMMU_ACPI_IVMD_RANGE_TYPE: + case ACPI_IVRS_TYPE_MEMORY_RANGE: return parse_ivmd_device_range(ivmd_block, base, limit, iw, ir); =20 - case AMD_IOMMU_ACPI_IVMD_IOMMU_TYPE: + case ACPI_IVRS_TYPE_MEMORY_IOMMU: return parse_ivmd_device_iommu(ivmd_block, base, limit, iw, ir); =20 @@ -386,45 +407,44 @@ static u16 __init parse_ivhd_device_padd } =20 static u16 __init parse_ivhd_device_select( - union acpi_ivhd_device *ivhd_device, struct amd_iommu *iommu) + const struct acpi_ivrs_device4 *select, struct amd_iommu *iommu) { u16 bdf; =20 - bdf =3D ivhd_device->header.dev_id; + bdf =3D select->header.id; if ( bdf >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Dev_Id 0x%x\n", = bdf); return 0; } =20 - add_ivrs_mapping_entry(bdf, bdf, ivhd_device->header.flags, iommu); + add_ivrs_mapping_entry(bdf, bdf, select->header.data_setting, iommu); =20 - return sizeof(struct acpi_ivhd_device_header); + return sizeof(*select); } =20 static u16 __init parse_ivhd_device_range( - union acpi_ivhd_device *ivhd_device, + const struct acpi_ivhd_device_range *range, u16 header_length, u16 block_length, struct amd_iommu *iommu) { u16 dev_length, first_bdf, last_bdf, bdf; =20 - dev_length =3D sizeof(struct acpi_ivhd_device_range); + dev_length =3D sizeof(*range); if ( header_length < (block_length + dev_length) ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Length!\n"); return 0; } =20 - if ( ivhd_device->range.trailer.type !=3D - AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END ) + if ( range->end.header.type !=3D ACPI_IVRS_TYPE_END ) { AMD_IOMMU_DEBUG("IVHD Error: " "Invalid Range: End_Type 0x%x\n", - ivhd_device->range.trailer.type); + range->end.header.type); return 0; } =20 - first_bdf =3D ivhd_device->header.dev_id; + first_bdf =3D range->start.header.id; if ( first_bdf >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVHD Error: " @@ -432,7 +452,7 @@ static u16 __init parse_ivhd_device_rang return 0; } =20 - last_bdf =3D ivhd_device->range.trailer.dev_id; + last_bdf =3D range->end.header.id; if ( (last_bdf >=3D ivrs_bdf_entries) || (last_bdf <=3D first_bdf) ) { AMD_IOMMU_DEBUG("IVHD Error: " @@ -443,32 +463,33 @@ static u16 __init parse_ivhd_device_rang AMD_IOMMU_DEBUG(" Dev_Id Range: 0x%x -> 0x%x\n", first_bdf, last_bdf);= =20 for ( bdf =3D first_bdf; bdf <=3D last_bdf; bdf++ ) - add_ivrs_mapping_entry(bdf, bdf, ivhd_device->header.flags, = iommu); + add_ivrs_mapping_entry(bdf, bdf, range->start.header.data_setting,= + iommu); =20 return dev_length; } =20 static u16 __init parse_ivhd_device_alias( - union acpi_ivhd_device *ivhd_device, + const struct acpi_ivrs_device8a *alias, u16 header_length, u16 block_length, struct amd_iommu *iommu) { u16 dev_length, alias_id, bdf; =20 - dev_length =3D sizeof(struct acpi_ivhd_device_alias); + dev_length =3D sizeof(*alias); if ( header_length < (block_length + dev_length) ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Length!\n"); return 0; } =20 - bdf =3D ivhd_device->header.dev_id; + bdf =3D alias->header.id; if ( bdf >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Dev_Id 0x%x\n", = bdf); return 0; } =20 - alias_id =3D ivhd_device->alias.dev_id; + alias_id =3D alias->used_id; if ( alias_id >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Alias Dev_Id 0x%x\n", = alias_id); @@ -477,35 +498,34 @@ static u16 __init parse_ivhd_device_alia =20 AMD_IOMMU_DEBUG(" Dev_Id Alias: 0x%x\n", alias_id); =20 - add_ivrs_mapping_entry(bdf, alias_id, ivhd_device->header.flags, = iommu); + add_ivrs_mapping_entry(bdf, alias_id, alias->header.data_setting, = iommu); =20 return dev_length; } =20 static u16 __init parse_ivhd_device_alias_range( - union acpi_ivhd_device *ivhd_device, + const struct acpi_ivhd_device_alias_range *range, u16 header_length, u16 block_length, struct amd_iommu *iommu) { =20 u16 dev_length, first_bdf, last_bdf, alias_id, bdf; =20 - dev_length =3D sizeof(struct acpi_ivhd_device_alias_range); + dev_length =3D sizeof(*range); if ( header_length < (block_length + dev_length) ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Length!\n"); return 0; } =20 - if ( ivhd_device->alias_range.trailer.type !=3D - AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END ) + if ( range->end.header.type !=3D ACPI_IVRS_TYPE_END ) { AMD_IOMMU_DEBUG("IVHD Error: " "Invalid Range: End_Type 0x%x\n", - ivhd_device->alias_range.trailer.type); + range->end.header.type); return 0; } =20 - first_bdf =3D ivhd_device->header.dev_id; + first_bdf =3D range->alias.header.id; if ( first_bdf >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVHD Error: " @@ -513,7 +533,7 @@ static u16 __init parse_ivhd_device_alia return 0; } =20 - last_bdf =3D ivhd_device->alias_range.trailer.dev_id; + last_bdf =3D range->end.header.id; if ( last_bdf >=3D ivrs_bdf_entries || last_bdf <=3D first_bdf ) { AMD_IOMMU_DEBUG( @@ -521,7 +541,7 @@ static u16 __init parse_ivhd_device_alia return 0; } =20 - alias_id =3D ivhd_device->alias_range.alias.dev_id; + alias_id =3D range->alias.used_id; if ( alias_id >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Alias Dev_Id 0x%x\n", = alias_id); @@ -532,59 +552,59 @@ static u16 __init parse_ivhd_device_alia AMD_IOMMU_DEBUG(" Dev_Id Alias: 0x%x\n", alias_id); =20 for ( bdf =3D first_bdf; bdf <=3D last_bdf; bdf++ ) - add_ivrs_mapping_entry(bdf, alias_id, ivhd_device->header.flags, = iommu); + add_ivrs_mapping_entry(bdf, alias_id, range->alias.header.data_set= ting, + iommu); =20 return dev_length; } =20 static u16 __init parse_ivhd_device_extended( - union acpi_ivhd_device *ivhd_device, + const struct acpi_ivrs_device8b *ext, u16 header_length, u16 block_length, struct amd_iommu *iommu) { u16 dev_length, bdf; =20 - dev_length =3D sizeof(struct acpi_ivhd_device_extended); + dev_length =3D sizeof(*ext); if ( header_length < (block_length + dev_length) ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Length!\n"); return 0; } =20 - bdf =3D ivhd_device->header.dev_id; + bdf =3D ext->header.id; if ( bdf >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Dev_Id 0x%x\n", = bdf); return 0; } =20 - add_ivrs_mapping_entry(bdf, bdf, ivhd_device->header.flags, iommu); + add_ivrs_mapping_entry(bdf, bdf, ext->header.data_setting, iommu); =20 return dev_length; } =20 static u16 __init parse_ivhd_device_extended_range( - union acpi_ivhd_device *ivhd_device, + const struct acpi_ivhd_device_extended_range *range, u16 header_length, u16 block_length, struct amd_iommu *iommu) { u16 dev_length, first_bdf, last_bdf, bdf; =20 - dev_length =3D sizeof(struct acpi_ivhd_device_extended_range); + dev_length =3D sizeof(*range); if ( header_length < (block_length + dev_length) ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Length!\n"); return 0; } =20 - if ( ivhd_device->extended_range.trailer.type !=3D - AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END ) + if ( range->end.header.type !=3D ACPI_IVRS_TYPE_END ) { AMD_IOMMU_DEBUG("IVHD Error: " "Invalid Range: End_Type 0x%x\n", - ivhd_device->extended_range.trailer.type); + range->end.header.type); return 0; } =20 - first_bdf =3D ivhd_device->header.dev_id; + first_bdf =3D range->extended.header.id; if ( first_bdf >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVHD Error: " @@ -592,7 +612,7 @@ static u16 __init parse_ivhd_device_exte return 0; } =20 - last_bdf =3D ivhd_device->extended_range.trailer.dev_id; + last_bdf =3D range->end.header.id; if ( (last_bdf >=3D ivrs_bdf_entries) || (last_bdf <=3D first_bdf) ) { AMD_IOMMU_DEBUG("IVHD Error: " @@ -604,116 +624,116 @@ static u16 __init parse_ivhd_device_exte first_bdf, last_bdf); =20 for ( bdf =3D first_bdf; bdf <=3D last_bdf; bdf++ ) - add_ivrs_mapping_entry(bdf, bdf, ivhd_device->header.flags, = iommu); + add_ivrs_mapping_entry(bdf, bdf, range->extended.header.data_setti= ng, + iommu); =20 return dev_length; } =20 static u16 __init parse_ivhd_device_special( - union acpi_ivhd_device *ivhd_device, u16 seg, + const struct acpi_ivrs_device8c *special, u16 seg, u16 header_length, u16 block_length, struct amd_iommu *iommu) { u16 dev_length, bdf; =20 - dev_length =3D sizeof(struct acpi_ivhd_device_special); + dev_length =3D sizeof(*special); if ( header_length < (block_length + dev_length) ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Length!\n"); return 0; } =20 - bdf =3D ivhd_device->special.dev_id; + bdf =3D special->used_id; if ( bdf >=3D ivrs_bdf_entries ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Dev_Id 0x%x\n", = bdf); return 0; } =20 - add_ivrs_mapping_entry(bdf, bdf, ivhd_device->header.flags, iommu); + add_ivrs_mapping_entry(bdf, bdf, special->header.data_setting, = iommu); /* set device id of ioapic */ - ioapic_sbdf[ivhd_device->special.handle].bdf =3D bdf; - ioapic_sbdf[ivhd_device->special.handle].seg =3D seg; + ioapic_sbdf[special->handle].bdf =3D bdf; + ioapic_sbdf[special->handle].seg =3D seg; return dev_length; } =20 -static int __init parse_ivhd_block(struct acpi_ivhd_block_header = *ivhd_block) +static int __init parse_ivhd_block(const struct acpi_ivrs_hardware = *ivhd_block) { - union acpi_ivhd_device *ivhd_device; + const union acpi_ivhd_device *ivhd_device; u16 block_length, dev_length; struct amd_iommu *iommu; =20 - if ( ivhd_block->header.length < - sizeof(struct acpi_ivhd_block_header) ) + if ( ivhd_block->header.length < sizeof(*ivhd_block) ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Block Length!\n"); return -ENODEV; } =20 - iommu =3D find_iommu_from_bdf_cap(ivhd_block->header.dev_id, - ivhd_block->cap_offset); + iommu =3D find_iommu_from_bdf_cap(ivhd_block->header.device_id, + ivhd_block->capability_offset); if ( !iommu ) { AMD_IOMMU_DEBUG("IVHD Error: No IOMMU for Dev_Id 0x%x Cap = 0x%x\n", - ivhd_block->header.dev_id, ivhd_block->cap_offset)= ; + ivhd_block->header.device_id, + ivhd_block->capability_offset); return -ENODEV; } =20 /* parse Device Entries */ - block_length =3D sizeof(struct acpi_ivhd_block_header); + block_length =3D sizeof(*ivhd_block); while ( ivhd_block->header.length >=3D - (block_length + sizeof(struct acpi_ivhd_device_header)) ) + (block_length + sizeof(struct acpi_ivrs_de_header)) ) { - ivhd_device =3D (union acpi_ivhd_device *) - ((u8 *)ivhd_block + block_length); + ivhd_device =3D (const void *)((const u8 *)ivhd_block + block_leng= th); =20 AMD_IOMMU_DEBUG( "IVHD Device Entry:\n"); AMD_IOMMU_DEBUG( " Type 0x%x\n", ivhd_device->header.type); - AMD_IOMMU_DEBUG( " Dev_Id 0x%x\n", ivhd_device->header.dev_id); - AMD_IOMMU_DEBUG( " Flags 0x%x\n", ivhd_device->header.flags); + AMD_IOMMU_DEBUG( " Dev_Id 0x%x\n", ivhd_device->header.id); + AMD_IOMMU_DEBUG( " Flags 0x%x\n", ivhd_device->header.data_setting= ); =20 switch ( ivhd_device->header.type ) { - case AMD_IOMMU_ACPI_IVHD_DEV_U32_PAD: + case ACPI_IVRS_TYPE_PAD4: dev_length =3D parse_ivhd_device_padding( sizeof(u32), ivhd_block->header.length, block_length); break; - case AMD_IOMMU_ACPI_IVHD_DEV_U64_PAD: + case ACPI_IVRS_TYPE_PAD8: dev_length =3D parse_ivhd_device_padding( sizeof(u64), ivhd_block->header.length, block_length); break; - case AMD_IOMMU_ACPI_IVHD_DEV_SELECT: - dev_length =3D parse_ivhd_device_select(ivhd_device, iommu); + case ACPI_IVRS_TYPE_SELECT: + dev_length =3D parse_ivhd_device_select(&ivhd_device->select, = iommu); break; - case AMD_IOMMU_ACPI_IVHD_DEV_RANGE_START: + case ACPI_IVRS_TYPE_START: dev_length =3D parse_ivhd_device_range( - ivhd_device, + &ivhd_device->range, ivhd_block->header.length, block_length, iommu); break; - case AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_SELECT: + case ACPI_IVRS_TYPE_ALIAS_SELECT: dev_length =3D parse_ivhd_device_alias( - ivhd_device, + &ivhd_device->alias, ivhd_block->header.length, block_length, iommu); break; - case AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_RANGE: + case ACPI_IVRS_TYPE_ALIAS_START: dev_length =3D parse_ivhd_device_alias_range( - ivhd_device, + &ivhd_device->alias_range, ivhd_block->header.length, block_length, iommu); break; - case AMD_IOMMU_ACPI_IVHD_DEV_EXT_SELECT: + case ACPI_IVRS_TYPE_EXT_SELECT: dev_length =3D parse_ivhd_device_extended( - ivhd_device, + &ivhd_device->extended, ivhd_block->header.length, block_length, iommu); break; - case AMD_IOMMU_ACPI_IVHD_DEV_EXT_RANGE: + case ACPI_IVRS_TYPE_EXT_START: dev_length =3D parse_ivhd_device_extended_range( - ivhd_device, + &ivhd_device->extended_range, ivhd_block->header.length, block_length, iommu); break; - case AMD_IOMMU_ACPI_IVHD_DEV_SPECIAL: + case ACPI_IVRS_TYPE_SPECIAL: dev_length =3D parse_ivhd_device_special( - ivhd_device, ivhd_block->pci_segment, + &ivhd_device->special, ivhd_block->pci_segment_group, ivhd_block->header.length, block_length, iommu); break; default: @@ -730,22 +750,24 @@ static int __init parse_ivhd_block(struc return 0; } =20 -static int __init parse_ivrs_block(struct acpi_ivrs_block_header = *ivrs_block) +static int __init parse_ivrs_block(const struct acpi_ivrs_header = *ivrs_block) { - struct acpi_ivhd_block_header *ivhd_block; - struct acpi_ivmd_block_header *ivmd_block; + const struct acpi_ivrs_hardware *ivhd_block; + const struct acpi_ivrs_memory *ivmd_block; =20 switch ( ivrs_block->type ) { - case AMD_IOMMU_ACPI_IVHD_TYPE: - ivhd_block =3D (struct acpi_ivhd_block_header *)ivrs_block; + case ACPI_IVRS_TYPE_HARDWARE: + ivhd_block =3D container_of(ivrs_block, const struct acpi_ivrs_har= dware, + header); return parse_ivhd_block(ivhd_block); =20 - case AMD_IOMMU_ACPI_IVMD_ALL_TYPE: - case AMD_IOMMU_ACPI_IVMD_ONE_TYPE: - case AMD_IOMMU_ACPI_IVMD_RANGE_TYPE: - case AMD_IOMMU_ACPI_IVMD_IOMMU_TYPE: - ivmd_block =3D (struct acpi_ivmd_block_header *)ivrs_block; + case ACPI_IVRS_TYPE_MEMORY_ALL: + case ACPI_IVRS_TYPE_MEMORY_ONE: + case ACPI_IVRS_TYPE_MEMORY_RANGE: + case ACPI_IVRS_TYPE_MEMORY_IOMMU: + ivmd_block =3D container_of(ivrs_block, const struct acpi_ivrs_mem= ory, + header); return parse_ivmd_block(ivmd_block); =20 default: @@ -792,12 +814,11 @@ static void __init dump_acpi_table_heade =20 } =20 -static int __init parse_ivrs_table(struct acpi_table_header *_table) +static int __init parse_ivrs_table(struct acpi_table_header *table) { - struct acpi_ivrs_block_header *ivrs_block; + const struct acpi_ivrs_header *ivrs_block; unsigned long length; int error =3D 0; - struct acpi_table_header *table =3D (struct acpi_table_header = *)_table; =20 BUG_ON(!table); =20 @@ -805,17 +826,16 @@ static int __init parse_ivrs_table(struc dump_acpi_table_header(table); =20 /* parse IVRS blocks */ - length =3D sizeof(struct acpi_ivrs_table_header); + length =3D sizeof(struct acpi_table_ivrs); while ( (error =3D=3D 0) && (table->length > (length + sizeof(*ivrs_bl= ock))) ) { - ivrs_block =3D (struct acpi_ivrs_block_header *) - ((u8 *)table + length); + ivrs_block =3D (struct acpi_ivrs_header *)((u8 *)table + length); =20 AMD_IOMMU_DEBUG("IVRS Block:\n"); AMD_IOMMU_DEBUG(" Type 0x%x\n", ivrs_block->type); AMD_IOMMU_DEBUG(" Flags 0x%x\n", ivrs_block->flags); AMD_IOMMU_DEBUG(" Length 0x%x\n", ivrs_block->length); - AMD_IOMMU_DEBUG(" Dev_Id 0x%x\n", ivrs_block->dev_id); + AMD_IOMMU_DEBUG(" Dev_Id 0x%x\n", ivrs_block->device_id); =20 if ( table->length < (length + ivrs_block->length) ) { @@ -833,12 +853,11 @@ static int __init parse_ivrs_table(struc return error; } =20 -static int __init detect_iommu_acpi(struct acpi_table_header *_table) +static int __init detect_iommu_acpi(struct acpi_table_header *table) { - struct acpi_ivrs_block_header *ivrs_block; - struct acpi_table_header *table =3D (struct acpi_table_header = *)_table; + const struct acpi_ivrs_header *ivrs_block; unsigned long i; - unsigned long length =3D sizeof(struct acpi_ivrs_table_header); + unsigned long length =3D sizeof(struct acpi_table_ivrs); u8 checksum, *raw_table; =20 /* validate checksum: sum of entire table =3D=3D 0 */ @@ -854,12 +873,14 @@ static int __init detect_iommu_acpi(stru =20 while ( table->length > (length + sizeof(*ivrs_block)) ) { - ivrs_block =3D (struct acpi_ivrs_block_header *) ((u8 *)table + = length); + ivrs_block =3D (struct acpi_ivrs_header *)((u8 *)table + length); if ( table->length < (length + ivrs_block->length) ) return -ENODEV; - if ( ivrs_block->type =3D=3D AMD_IOMMU_ACPI_IVHD_TYPE ) - if ( amd_iommu_detect_one_acpi((void*)ivrs_block) !=3D 0 ) - return -ENODEV; + if ( ivrs_block->type =3D=3D ACPI_IVRS_TYPE_HARDWARE && + amd_iommu_detect_one_acpi( + container_of(ivrs_block, const struct acpi_ivrs_hardware,= + header)) !=3D 0 ) + return -ENODEV; length +=3D ivrs_block->length; } return 0; @@ -870,63 +891,59 @@ static int __init detect_iommu_acpi(stru last_bdf =3D (x); \ } while(0); =20 -static int __init get_last_bdf_ivhd(void *ivhd) +static int __init get_last_bdf_ivhd( + const struct acpi_ivrs_hardware *ivhd_block) { - union acpi_ivhd_device *ivhd_device; + const union acpi_ivhd_device *ivhd_device; u16 block_length, dev_length; - struct acpi_ivhd_block_header *ivhd_block; - - ivhd_block =3D (struct acpi_ivhd_block_header *)ivhd; =20 - if ( ivhd_block->header.length < - sizeof(struct acpi_ivhd_block_header) ) + if ( ivhd_block->header.length < sizeof(*ivhd_block) ) { AMD_IOMMU_DEBUG("IVHD Error: Invalid Block Length!\n"); return -ENODEV; } =20 - block_length =3D sizeof(struct acpi_ivhd_block_header); + block_length =3D sizeof(*ivhd_block); while ( ivhd_block->header.length >=3D - (block_length + sizeof(struct acpi_ivhd_device_header)) ) + (block_length + sizeof(struct acpi_ivrs_de_header)) ) { - ivhd_device =3D (union acpi_ivhd_device *) - ((u8 *)ivhd_block + block_length); + ivhd_device =3D (const void *)((u8 *)ivhd_block + block_length); =20 switch ( ivhd_device->header.type ) { - case AMD_IOMMU_ACPI_IVHD_DEV_U32_PAD: + case ACPI_IVRS_TYPE_PAD4: dev_length =3D sizeof(u32); break; - case AMD_IOMMU_ACPI_IVHD_DEV_U64_PAD: + case ACPI_IVRS_TYPE_PAD8: dev_length =3D sizeof(u64); break; - case AMD_IOMMU_ACPI_IVHD_DEV_SELECT: - UPDATE_LAST_BDF(ivhd_device->header.dev_id); - dev_length =3D sizeof(struct acpi_ivhd_device_header); - break; - case AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_SELECT: - UPDATE_LAST_BDF(ivhd_device->header.dev_id); - dev_length =3D sizeof(struct acpi_ivhd_device_alias); - break; - case AMD_IOMMU_ACPI_IVHD_DEV_EXT_SELECT: - UPDATE_LAST_BDF(ivhd_device->header.dev_id); - dev_length =3D sizeof(struct acpi_ivhd_device_extended); - break; - case AMD_IOMMU_ACPI_IVHD_DEV_RANGE_START: - UPDATE_LAST_BDF(ivhd_device->range.trailer.dev_id); - dev_length =3D sizeof(struct acpi_ivhd_device_range); - break; - case AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_RANGE: - UPDATE_LAST_BDF(ivhd_device->alias_range.trailer.dev_id) - dev_length =3D sizeof(struct acpi_ivhd_device_alias_range); - break; - case AMD_IOMMU_ACPI_IVHD_DEV_EXT_RANGE: - UPDATE_LAST_BDF(ivhd_device->extended_range.trailer.dev_id) - dev_length =3D sizeof(struct acpi_ivhd_device_extended_range);= - break; - case AMD_IOMMU_ACPI_IVHD_DEV_SPECIAL: - UPDATE_LAST_BDF(ivhd_device->special.dev_id) - dev_length =3D sizeof(struct acpi_ivhd_device_special); + case ACPI_IVRS_TYPE_SELECT: + UPDATE_LAST_BDF(ivhd_device->select.header.id); + dev_length =3D sizeof(ivhd_device->header); + break; + case ACPI_IVRS_TYPE_ALIAS_SELECT: + UPDATE_LAST_BDF(ivhd_device->alias.header.id); + dev_length =3D sizeof(ivhd_device->alias); + break; + case ACPI_IVRS_TYPE_EXT_SELECT: + UPDATE_LAST_BDF(ivhd_device->extended.header.id); + dev_length =3D sizeof(ivhd_device->extended); + break; + case ACPI_IVRS_TYPE_START: + UPDATE_LAST_BDF(ivhd_device->range.end.header.id); + dev_length =3D sizeof(ivhd_device->range); + break; + case ACPI_IVRS_TYPE_ALIAS_START: + UPDATE_LAST_BDF(ivhd_device->alias_range.end.header.id) + dev_length =3D sizeof(ivhd_device->alias_range); + break; + case ACPI_IVRS_TYPE_EXT_START: + UPDATE_LAST_BDF(ivhd_device->extended_range.end.header.id) + dev_length =3D sizeof(ivhd_device->extended_range); + break; + case ACPI_IVRS_TYPE_SPECIAL: + UPDATE_LAST_BDF(ivhd_device->special.used_id) + dev_length =3D sizeof(ivhd_device->special); break; default: AMD_IOMMU_DEBUG("IVHD Error: Invalid Device Type!\n"); @@ -942,20 +959,21 @@ static int __init get_last_bdf_ivhd(void return 0; } =20 -static int __init get_last_bdf_acpi(struct acpi_table_header *_table) +static int __init get_last_bdf_acpi(struct acpi_table_header *table) { - struct acpi_ivrs_block_header *ivrs_block; - struct acpi_table_header *table =3D (struct acpi_table_header = *)_table; - unsigned long length =3D sizeof(struct acpi_ivrs_table_header); + const struct acpi_ivrs_header *ivrs_block; + unsigned long length =3D sizeof(struct acpi_table_ivrs); =20 while ( table->length > (length + sizeof(*ivrs_block)) ) { - ivrs_block =3D (struct acpi_ivrs_block_header *) ((u8 *)table + = length); + ivrs_block =3D (struct acpi_ivrs_header *)((u8 *)table + length); if ( table->length < (length + ivrs_block->length) ) return -ENODEV; - if ( ivrs_block->type =3D=3D AMD_IOMMU_ACPI_IVHD_TYPE ) - if ( get_last_bdf_ivhd((void*)ivrs_block) !=3D 0 ) - return -ENODEV; + if ( ivrs_block->type =3D=3D ACPI_IVRS_TYPE_HARDWARE && + get_last_bdf_ivhd( + container_of(ivrs_block, const struct acpi_ivrs_hardware,= + header)) !=3D 0 ) + return -ENODEV; length +=3D ivrs_block->length; } return 0; @@ -963,16 +981,16 @@ static int __init get_last_bdf_acpi(stru =20 int __init amd_iommu_detect_acpi(void) { - return acpi_table_parse(AMD_IOMMU_ACPI_IVRS_SIG, detect_iommu_acpi); + return acpi_table_parse(ACPI_SIG_IVRS, detect_iommu_acpi); } =20 int __init amd_iommu_get_ivrs_dev_entries(void) { - acpi_table_parse(AMD_IOMMU_ACPI_IVRS_SIG, get_last_bdf_acpi); + acpi_table_parse(ACPI_SIG_IVRS, get_last_bdf_acpi); return last_bdf + 1; } =20 int __init amd_iommu_update_ivrs_mapping_acpi(void) { - return acpi_table_parse(AMD_IOMMU_ACPI_IVRS_SIG, parse_ivrs_table); + return acpi_table_parse(ACPI_SIG_IVRS, parse_ivrs_table); } --- a/xen/drivers/passthrough/amd/iommu_detect.c +++ b/xen/drivers/passthrough/amd/iommu_detect.c @@ -20,12 +20,12 @@ =20 #include #include +#include #include #include #include #include #include -#include =20 static int __init get_iommu_msi_capabilities( u16 seg, u8 bus, u8 dev, u8 func, struct amd_iommu *iommu) @@ -103,23 +103,21 @@ void __init get_iommu_features(struct am } } =20 -int __init amd_iommu_detect_one_acpi(void *ivhd) +int __init amd_iommu_detect_one_acpi( + const struct acpi_ivrs_hardware *ivhd_block) { struct amd_iommu *iommu; u8 bus, dev, func; - struct acpi_ivhd_block_header *ivhd_block; int rt =3D 0; =20 - ivhd_block =3D (struct acpi_ivhd_block_header *)ivhd; - - if ( ivhd_block->header.length < sizeof(struct acpi_ivhd_block_header)= ) + if ( ivhd_block->header.length < sizeof(*ivhd_block) ) { AMD_IOMMU_DEBUG("Invalid IVHD Block Length!\n"); return -ENODEV; } =20 - if ( !ivhd_block->header.dev_id || - !ivhd_block->cap_offset || !ivhd_block->mmio_base) + if ( !ivhd_block->header.device_id || + !ivhd_block->capability_offset || !ivhd_block->base_address) { AMD_IOMMU_DEBUG("Invalid IVHD Block!\n"); return -ENODEV; @@ -134,10 +132,10 @@ int __init amd_iommu_detect_one_acpi(voi =20 spin_lock_init(&iommu->lock); =20 - iommu->seg =3D ivhd_block->pci_segment; - iommu->bdf =3D ivhd_block->header.dev_id; - iommu->cap_offset =3D ivhd_block->cap_offset; - iommu->mmio_base_phys =3D ivhd_block->mmio_base; + iommu->seg =3D ivhd_block->pci_segment_group; + iommu->bdf =3D ivhd_block->header.device_id; + iommu->cap_offset =3D ivhd_block->capability_offset; + iommu->mmio_base_phys =3D ivhd_block->base_address; =20 /* override IOMMU HT flags */ iommu->ht_flags =3D ivhd_block->header.flags; --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -20,6 +20,7 @@ =20 #include #include +#include #include #include #include @@ -28,7 +29,6 @@ #include #include #include -#include =20 static int __initdata nr_amd_iommus; =20 @@ -37,9 +37,8 @@ static struct radix_tree_root ivrs_maps; struct list_head amd_iommu_head; struct table_struct device_table; =20 -static int iommu_has_ht_flag(struct amd_iommu *iommu, uint8_t bit) +static int iommu_has_ht_flag(struct amd_iommu *iommu, u8 mask) { - u8 mask =3D 1U << bit; return iommu->ht_flags & mask; } =20 @@ -80,19 +79,19 @@ static void set_iommu_ht_flags(struct am =20 /* Setup HT flags */ if ( iommu_has_cap(iommu, PCI_CAP_HT_TUNNEL_SHIFT) ) - iommu_has_ht_flag(iommu, AMD_IOMMU_ACPI_HT_TUN_ENB_SHIFT) ? + iommu_has_ht_flag(iommu, ACPI_IVHD_TT_ENABLE) ? iommu_set_bit(&entry, IOMMU_CONTROL_HT_TUNNEL_TRANSLATION_SHIF= T) : iommu_clear_bit(&entry, IOMMU_CONTROL_HT_TUNNEL_TRANSLATION_SH= IFT); =20 - iommu_has_ht_flag(iommu, AMD_IOMMU_ACPI_RES_PASS_PW_SHIFT) ? + iommu_has_ht_flag(iommu, ACPI_IVHD_RES_PASS_PW) ? iommu_set_bit(&entry, IOMMU_CONTROL_RESP_PASS_POSTED_WRITE_SHIFT):= iommu_clear_bit(&entry, IOMMU_CONTROL_RESP_PASS_POSTED_WRITE_SHIFT= ); =20 - iommu_has_ht_flag(iommu, AMD_IOMMU_ACPI_ISOC_SHIFT) ? + iommu_has_ht_flag(iommu, ACPI_IVHD_ISOC) ? iommu_set_bit(&entry, IOMMU_CONTROL_ISOCHRONOUS_SHIFT): iommu_clear_bit(&entry, IOMMU_CONTROL_ISOCHRONOUS_SHIFT); =20 - iommu_has_ht_flag(iommu, AMD_IOMMU_ACPI_PASS_PW_SHIFT) ? + iommu_has_ht_flag(iommu, ACPI_IVHD_PASS_PW) ? iommu_set_bit(&entry, IOMMU_CONTROL_PASS_POSTED_WRITE_SHIFT): iommu_clear_bit(&entry, IOMMU_CONTROL_PASS_POSTED_WRITE_SHIFT); =20 --- a/xen/drivers/passthrough/amd/iommu_map.c +++ b/xen/drivers/passthrough/amd/iommu_map.c @@ -18,12 +18,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 = USA */ =20 +#include +#include #include #include #include #include #include -#include #include "../ats.h" #include =20 @@ -215,8 +216,7 @@ void __init iommu_dte_add_device_entry(u dte[7] =3D dte[6] =3D dte[4] =3D dte[2] =3D dte[1] =3D dte[0] =3D 0; =20 flags =3D ivrs_dev->device_flags; - sys_mgt =3D get_field_from_byte(flags, AMD_IOMMU_ACPI_SYS_MGT_MASK, - AMD_IOMMU_ACPI_SYS_MGT_SHIFT); + sys_mgt =3D get_field_from_byte(flags, ACPI_IVHD_SYSTEM_MGMT); dev_ex =3D ivrs_dev->dte_allow_exclusion; =20 flags &=3D mask; --- a/xen/include/asm-x86/hvm/svm/amd-iommu-acpi.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2007 Advanced Micro Devices, Inc. - * Author: Leo Duran - * Author: Wei Wang - adapted to xen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 = USA - */ - -#ifndef _ASM_X86_64_AMD_IOMMU_ACPI_H -#define _ASM_X86_64_AMD_IOMMU_ACPI_H - -#include - -/* I/O Virtualization Reporting Structure */ -#define AMD_IOMMU_ACPI_IVRS_SIG "IVRS" -#define AMD_IOMMU_ACPI_IVHD_TYPE 0x10 -#define AMD_IOMMU_ACPI_IVMD_ALL_TYPE 0x20 -#define AMD_IOMMU_ACPI_IVMD_ONE_TYPE 0x21 -#define AMD_IOMMU_ACPI_IVMD_RANGE_TYPE 0x22 -#define AMD_IOMMU_ACPI_IVMD_IOMMU_TYPE 0x23 - -/* 4-byte Device Entries */ -#define AMD_IOMMU_ACPI_IVHD_DEV_U32_PAD 0 -#define AMD_IOMMU_ACPI_IVHD_DEV_SELECT 2 -#define AMD_IOMMU_ACPI_IVHD_DEV_RANGE_START 3 -#define AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END 4 - -/* 8-byte Device Entries */ -#define AMD_IOMMU_ACPI_IVHD_DEV_U64_PAD 64 -#define AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_SELECT 66 -#define AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_RANGE 67 -#define AMD_IOMMU_ACPI_IVHD_DEV_EXT_SELECT 70 -#define AMD_IOMMU_ACPI_IVHD_DEV_EXT_RANGE 71 -#define AMD_IOMMU_ACPI_IVHD_DEV_SPECIAL 72 - -/* IVHD IOMMU Flags */ -#define AMD_IOMMU_ACPI_COHERENT_MASK 0x20 -#define AMD_IOMMU_ACPI_COHERENT_SHIFT 5 -#define AMD_IOMMU_ACPI_IOTLB_SUP_MASK 0x10 -#define AMD_IOMMU_ACPI_IOTLB_SUP_SHIFT 4 -#define AMD_IOMMU_ACPI_ISOC_MASK 0x08 -#define AMD_IOMMU_ACPI_ISOC_SHIFT 3 -#define AMD_IOMMU_ACPI_RES_PASS_PW_MASK 0x04 -#define AMD_IOMMU_ACPI_RES_PASS_PW_SHIFT 2 -#define AMD_IOMMU_ACPI_PASS_PW_MASK 0x02 -#define AMD_IOMMU_ACPI_PASS_PW_SHIFT 1 -#define AMD_IOMMU_ACPI_HT_TUN_ENB_MASK 0x01 -#define AMD_IOMMU_ACPI_HT_TUN_ENB_SHIFT 0 - -/* IVHD Device Flags */ -#define AMD_IOMMU_ACPI_LINT1_PASS_MASK 0x80 -#define AMD_IOMMU_ACPI_LINT1_PASS_SHIFT 7 -#define AMD_IOMMU_ACPI_LINT0_PASS_MASK 0x40 -#define AMD_IOMMU_ACPI_LINT0_PASS_SHIFT 6 -#define AMD_IOMMU_ACPI_SYS_MGT_MASK 0x30 -#define AMD_IOMMU_ACPI_SYS_MGT_SHIFT 4 -#define AMD_IOMMU_ACPI_NMI_PASS_MASK 0x04 -#define AMD_IOMMU_ACPI_NMI_PASS_SHIFT 2 -#define AMD_IOMMU_ACPI_EINT_PASS_MASK 0x02 -#define AMD_IOMMU_ACPI_EINT_PASS_SHIFT 1 -#define AMD_IOMMU_ACPI_INIT_PASS_MASK 0x01 -#define AMD_IOMMU_ACPI_INIT_PASS_SHIFT 0 - -/* IVHD Device Extended Flags */ -#define AMD_IOMMU_ACPI_ATS_DISABLED_MASK 0x80000000 -#define AMD_IOMMU_ACPI_ATS_DISABLED_SHIFT 31 - -/* IVMD Device Flags */ -#define AMD_IOMMU_ACPI_EXCLUSION_RANGE_MASK 0x08 -#define AMD_IOMMU_ACPI_EXCLUSION_RANGE_SHIFT 3 -#define AMD_IOMMU_ACPI_IW_PERMISSION_MASK 0x04 -#define AMD_IOMMU_ACPI_IW_PERMISSION_SHIFT 2 -#define AMD_IOMMU_ACPI_IR_PERMISSION_MASK 0x02 -#define AMD_IOMMU_ACPI_IR_PERMISSION_SHIFT 1 -#define AMD_IOMMU_ACPI_UNITY_MAPPING_MASK 0x01 -#define AMD_IOMMU_ACPI_UNITY_MAPPING_SHIFT 0 - -#define ACPI_OEM_ID_SIZE 6 -#define ACPI_OEM_TABLE_ID_SIZE 8 - -#pragma pack(1) -struct acpi_ivrs_table_header { - struct acpi_table_header acpi_header; - u32 io_info; - u8 reserved[8]; -}; - -struct acpi_ivrs_block_header { - u8 type; - u8 flags; - u16 length; - u16 dev_id; -}; - -struct acpi_ivhd_block_header { - struct acpi_ivrs_block_header header; - u16 cap_offset; - u64 mmio_base; - u16 pci_segment; - u16 iommu_info; - u8 reserved[4]; -}; - -struct acpi_ivhd_device_header { - u8 type; - u16 dev_id; - u8 flags; -}; - -struct acpi_ivhd_device_trailer { - u8 type; - u16 dev_id; - u8 reserved; -}; - -struct acpi_ivhd_device_range { - struct acpi_ivhd_device_header header; - struct acpi_ivhd_device_trailer trailer; -}; - -struct acpi_ivhd_device_alias { - struct acpi_ivhd_device_header header; - u8 reserved1; - u16 dev_id; - u8 reserved2; -}; - -struct acpi_ivhd_device_alias_range { - struct acpi_ivhd_device_alias alias; - struct acpi_ivhd_device_trailer trailer; -}; - -struct acpi_ivhd_device_extended { - struct acpi_ivhd_device_header header; - u32 ext_flags; -}; - -struct acpi_ivhd_device_extended_range { - struct acpi_ivhd_device_extended extended; - struct acpi_ivhd_device_trailer trailer; -}; - -struct acpi_ivhd_device_special { - struct acpi_ivhd_device_header header; - u8 handle; - u16 dev_id; - u8 variety; -}; - -union acpi_ivhd_device { - struct acpi_ivhd_device_header header; - struct acpi_ivhd_device_range range; - struct acpi_ivhd_device_alias alias; - struct acpi_ivhd_device_alias_range alias_range; - struct acpi_ivhd_device_extended extended; - struct acpi_ivhd_device_extended_range extended_range; - struct acpi_ivhd_device_special special; -}; - -struct acpi_ivmd_block_header { - struct acpi_ivrs_block_header header; - union { - u16 last_dev_id; - u16 cap_offset; - u16 reserved1; - }; - u64 reserved2; - u64 start_addr; - u64 mem_length; -}; -#pragma pack() - -#endif /* _ASM_X86_64_AMD_IOMMU_ACPI_H */ --- a/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +++ b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h @@ -26,6 +26,8 @@ #include #include =20 +struct acpi_ivrs_hardware; + #define for_each_amd_iommu(amd_iommu) \ list_for_each_entry(amd_iommu, \ &amd_iommu_head, list) @@ -41,7 +43,7 @@ =20 /* amd-iommu-detect functions */ int amd_iommu_get_ivrs_dev_entries(void); -int amd_iommu_detect_one_acpi(void *ivhd); +int amd_iommu_detect_one_acpi(const struct acpi_ivrs_hardware *); int amd_iommu_detect_acpi(void); void get_iommu_features(struct amd_iommu *iommu); =20 @@ -121,11 +123,9 @@ static inline u32 set_field_in_reg_u32(u return reg_value; } =20 -static inline u8 get_field_from_byte(u8 value, u8 mask, u8 shift) +static inline u8 get_field_from_byte(u8 value, u8 mask) { - u8 field; - field =3D (value & mask) >> shift; - return field; + return (value & mask) / (mask & -mask); } =20 static inline unsigned long region_to_pages(unsigned long addr, unsigned = long size) --=__Part456AE0A2.0__= Content-Type: text/plain; name="acpi-duplicate-ivrs-structs.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="acpi-duplicate-ivrs-structs.patch" ACPI: eliminate duplicate IVRS definitions=0A=0AUse their proper counterpar= ts in include/acpi/actbl*.h instead.=0A=0ASigned-off-by: Jan Beulich = =0A=0A--- a/xen/drivers/passthrough/amd/iommu_acpi.c=0A+= ++ b/xen/drivers/passthrough/amd/iommu_acpi.c=0A@@ -20,10 +20,38 @@=0A =0A = #include =0A #include =0A+#include = =0A #include =0A #include =0A #include = =0A-#include = =0A+=0A+/* Some helper structures, particularly to deal with ranges. = */=0A+=0A+struct acpi_ivhd_device_range {=0A+ struct acpi_ivrs_device4 = start;=0A+ struct acpi_ivrs_device4 end;=0A+};=0A+=0A+struct acpi_ivhd_de= vice_alias_range {=0A+ struct acpi_ivrs_device8a alias;=0A+ struct = acpi_ivrs_device4 end;=0A+};=0A+=0A+struct acpi_ivhd_device_extended_range = {=0A+ struct acpi_ivrs_device8b extended;=0A+ struct acpi_ivrs_device4 = end;=0A+};=0A+=0A+union acpi_ivhd_device {=0A+ struct acpi_ivrs_de_header= header;=0A+ struct acpi_ivrs_device4 select;=0A+ struct acpi_ivhd_devi= ce_range range;=0A+ struct acpi_ivrs_device8a alias;=0A+ struct = acpi_ivhd_device_alias_range alias_range;=0A+ struct acpi_ivrs_device8b = extended;=0A+ struct acpi_ivhd_device_extended_range extended_range;=0A+ = struct acpi_ivrs_device8c special;=0A+};=0A =0A static unsigned short = __initdata last_bdf;=0A =0A@@ -242,12 +270,12 @@ static int __init = register_exclusion_ran=0A }=0A =0A static int __init parse_ivmd_device_sele= ct(=0A- struct acpi_ivmd_block_header *ivmd_block,=0A+ const struct = acpi_ivrs_memory *ivmd_block,=0A unsigned long base, unsigned long = limit, u8 iw, u8 ir)=0A {=0A u16 bdf;=0A =0A- bdf =3D ivmd_block->he= ader.dev_id;=0A+ bdf =3D ivmd_block->header.device_id;=0A if ( bdf = >=3D ivrs_bdf_entries )=0A {=0A AMD_IOMMU_DEBUG("IVMD Error: = Invalid Dev_Id 0x%x\n", bdf);=0A@@ -258,13 +286,13 @@ static int __init = parse_ivmd_device_sele=0A }=0A =0A static int __init parse_ivmd_device_rang= e(=0A- struct acpi_ivmd_block_header *ivmd_block,=0A+ const struct = acpi_ivrs_memory *ivmd_block,=0A unsigned long base, unsigned long = limit, u8 iw, u8 ir)=0A {=0A u16 first_bdf, last_bdf, bdf;=0A int = error;=0A =0A- first_bdf =3D ivmd_block->header.dev_id;=0A+ = first_bdf =3D ivmd_block->header.device_id;=0A if ( first_bdf >=3D = ivrs_bdf_entries )=0A {=0A AMD_IOMMU_DEBUG("IVMD Error: "=0A@@ = -272,7 +300,7 @@ static int __init parse_ivmd_device_rang=0A = return -ENODEV;=0A }=0A =0A- last_bdf =3D ivmd_block->last_dev_id;= =0A+ last_bdf =3D ivmd_block->aux_data;=0A if ( (last_bdf >=3D = ivrs_bdf_entries) || (last_bdf <=3D first_bdf) )=0A {=0A = AMD_IOMMU_DEBUG("IVMD Error: "=0A@@ -288,18 +316,18 @@ static int __init = parse_ivmd_device_rang=0A }=0A =0A static int __init parse_ivmd_device_iomm= u(=0A- struct acpi_ivmd_block_header *ivmd_block,=0A+ const struct = acpi_ivrs_memory *ivmd_block,=0A unsigned long base, unsigned long = limit, u8 iw, u8 ir)=0A {=0A struct amd_iommu *iommu;=0A =0A /* = find target IOMMU */=0A- iommu =3D find_iommu_from_bdf_cap(ivmd_block->h= eader.dev_id,=0A- ivmd_block->cap_offset= );=0A+ iommu =3D find_iommu_from_bdf_cap(ivmd_block->header.device_id,= =0A+ ivmd_block->aux_data);=0A if ( = !iommu )=0A {=0A AMD_IOMMU_DEBUG("IVMD Error: No IOMMU for = Dev_Id 0x%x Cap 0x%x\n",=0A- ivmd_block->header.dev= _id, ivmd_block->cap_offset);=0A+ ivmd_block->header= .device_id, ivmd_block->aux_data);=0A return -ENODEV;=0A }=0A = =0A@@ -307,20 +335,19 @@ static int __init parse_ivmd_device_iomm=0A = iommu, base, limit, iw, ir);=0A }=0A =0A-static int __init parse_ivmd_blo= ck(struct acpi_ivmd_block_header *ivmd_block)=0A+static int __init = parse_ivmd_block(const struct acpi_ivrs_memory *ivmd_block)=0A {=0A = unsigned long start_addr, mem_length, base, limit;=0A u8 iw, ir;=0A = =0A- if ( ivmd_block->header.length <=0A- sizeof(struct = acpi_ivmd_block_header) )=0A+ if ( ivmd_block->header.length < = sizeof(*ivmd_block) )=0A {=0A AMD_IOMMU_DEBUG("IVMD Error: = Invalid Block Length!\n");=0A return -ENODEV;=0A }=0A =0A- = start_addr =3D (unsigned long)ivmd_block->start_addr;=0A- mem_length = =3D (unsigned long)ivmd_block->mem_length;=0A+ start_addr =3D (unsigned = long)ivmd_block->start_address;=0A+ mem_length =3D (unsigned long)ivmd_b= lock->memory_length;=0A base =3D start_addr & PAGE_MASK;=0A limit = =3D (start_addr + mem_length - 1) & PAGE_MASK;=0A =0A@@ -328,20 +355,14 @@ = static int __init parse_ivmd_block(struc=0A AMD_IOMMU_DEBUG(" = Start_Addr_Phys 0x%lx\n", start_addr);=0A AMD_IOMMU_DEBUG(" Mem_Length = 0x%lx\n", mem_length);=0A =0A- if ( get_field_from_byte(ivmd_block->head= er.flags,=0A- AMD_IOMMU_ACPI_EXCLUSION_RANGE_MA= SK,=0A- AMD_IOMMU_ACPI_EXCLUSION_RANGE_SHIFT) = )=0A+ if ( ivmd_block->header.flags & ACPI_IVMD_EXCLUSION_RANGE )=0A = iw =3D ir =3D IOMMU_CONTROL_ENABLED;=0A- else if ( get_field_from_b= yte(ivmd_block->header.flags,=0A- = AMD_IOMMU_ACPI_UNITY_MAPPING_MASK,=0A- = AMD_IOMMU_ACPI_UNITY_MAPPING_SHIFT) )=0A- {=0A- iw =3D get_field_= from_byte(ivmd_block->header.flags,=0A- = AMD_IOMMU_ACPI_IW_PERMISSION_MASK,=0A- = AMD_IOMMU_ACPI_IW_PERMISSION_SHIFT);=0A- ir =3D get_field_from_byte(= ivmd_block->header.flags,=0A- AMD_IOMMU_ACP= I_IR_PERMISSION_MASK,=0A- AMD_IOMMU_ACPI_IR= _PERMISSION_SHIFT);=0A+ else if ( ivmd_block->header.flags & ACPI_IVMD_U= NITY )=0A+ {=0A+ iw =3D ivmd_block->header.flags & ACPI_IVMD_READ= ?=0A+ IOMMU_CONTROL_ENABLED : IOMMU_CONTROL_DISABLED;=0A+ = ir =3D ivmd_block->header.flags & ACPI_IVMD_WRITE ?=0A+ = IOMMU_CONTROL_ENABLED : IOMMU_CONTROL_DISABLED;=0A }=0A else=0A = {=0A@@ -351,19 +372,19 @@ static int __init parse_ivmd_block(struc=0A =0A = switch( ivmd_block->header.type )=0A {=0A- case AMD_IOMMU_ACPI_I= VMD_ALL_TYPE:=0A+ case ACPI_IVRS_TYPE_MEMORY_ALL:=0A return = register_exclusion_range_for_all_devices(=0A base, limit, iw, = ir);=0A =0A- case AMD_IOMMU_ACPI_IVMD_ONE_TYPE:=0A+ case ACPI_IVRS_TY= PE_MEMORY_ONE:=0A return parse_ivmd_device_select(ivmd_block,=0A = base, limit, iw, ir);=0A =0A- = case AMD_IOMMU_ACPI_IVMD_RANGE_TYPE:=0A+ case ACPI_IVRS_TYPE_MEMORY_RANG= E:=0A return parse_ivmd_device_range(ivmd_block,=0A = base, limit, iw, ir);=0A =0A- case AMD_IOMMU_ACP= I_IVMD_IOMMU_TYPE:=0A+ case ACPI_IVRS_TYPE_MEMORY_IOMMU:=0A = return parse_ivmd_device_iommu(ivmd_block,=0A = base, limit, iw, ir);=0A =0A@@ -386,45 +407,44 @@ static u16 = __init parse_ivhd_device_padd=0A }=0A =0A static u16 __init parse_ivhd_devi= ce_select(=0A- union acpi_ivhd_device *ivhd_device, struct amd_iommu = *iommu)=0A+ const struct acpi_ivrs_device4 *select, struct amd_iommu = *iommu)=0A {=0A u16 bdf;=0A =0A- bdf =3D ivhd_device->header.dev_id;= =0A+ bdf =3D select->header.id;=0A if ( bdf >=3D ivrs_bdf_entries = )=0A {=0A AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry = Dev_Id 0x%x\n", bdf);=0A return 0;=0A }=0A =0A- add_ivrs_map= ping_entry(bdf, bdf, ivhd_device->header.flags, iommu);=0A+ add_ivrs_map= ping_entry(bdf, bdf, select->header.data_setting, iommu);=0A =0A- = return sizeof(struct acpi_ivhd_device_header);=0A+ return sizeof(*select= );=0A }=0A =0A static u16 __init parse_ivhd_device_range(=0A- union = acpi_ivhd_device *ivhd_device,=0A+ const struct acpi_ivhd_device_range = *range,=0A u16 header_length, u16 block_length, struct amd_iommu = *iommu)=0A {=0A u16 dev_length, first_bdf, last_bdf, bdf;=0A =0A- = dev_length =3D sizeof(struct acpi_ivhd_device_range);=0A+ dev_length = =3D sizeof(*range);=0A if ( header_length < (block_length + dev_length)= )=0A {=0A AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry = Length!\n");=0A return 0;=0A }=0A =0A- if ( ivhd_device->ran= ge.trailer.type !=3D=0A- AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END )=0A+ = if ( range->end.header.type !=3D ACPI_IVRS_TYPE_END )=0A {=0A = AMD_IOMMU_DEBUG("IVHD Error: "=0A "Invalid Range: = End_Type 0x%x\n",=0A- ivhd_device->range.trailer.typ= e);=0A+ range->end.header.type);=0A return = 0;=0A }=0A =0A- first_bdf =3D ivhd_device->header.dev_id;=0A+ = first_bdf =3D range->start.header.id;=0A if ( first_bdf >=3D ivrs_bdf_e= ntries )=0A {=0A AMD_IOMMU_DEBUG("IVHD Error: "=0A@@ -432,7 = +452,7 @@ static u16 __init parse_ivhd_device_rang=0A return 0;=0A = }=0A =0A- last_bdf =3D ivhd_device->range.trailer.dev_id;=0A+ = last_bdf =3D range->end.header.id;=0A if ( (last_bdf >=3D ivrs_bdf_entr= ies) || (last_bdf <=3D first_bdf) )=0A {=0A AMD_IOMMU_DEBUG("IV= HD Error: "=0A@@ -443,32 +463,33 @@ static u16 __init parse_ivhd_device_ran= g=0A AMD_IOMMU_DEBUG(" Dev_Id Range: 0x%x -> 0x%x\n", first_bdf, = last_bdf);=0A =0A for ( bdf =3D first_bdf; bdf <=3D last_bdf; bdf++ = )=0A- add_ivrs_mapping_entry(bdf, bdf, ivhd_device->header.flags, = iommu);=0A+ add_ivrs_mapping_entry(bdf, bdf, range->start.header.dat= a_setting,=0A+ iommu);=0A =0A return = dev_length;=0A }=0A =0A static u16 __init parse_ivhd_device_alias(=0A- = union acpi_ivhd_device *ivhd_device,=0A+ const struct acpi_ivrs_device8a= *alias,=0A u16 header_length, u16 block_length, struct amd_iommu = *iommu)=0A {=0A u16 dev_length, alias_id, bdf;=0A =0A- dev_length = =3D sizeof(struct acpi_ivhd_device_alias);=0A+ dev_length =3D sizeof(*al= ias);=0A if ( header_length < (block_length + dev_length) )=0A = {=0A AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Length!\n");= =0A return 0;=0A }=0A =0A- bdf =3D ivhd_device->header.dev_i= d;=0A+ bdf =3D alias->header.id;=0A if ( bdf >=3D ivrs_bdf_entries = )=0A {=0A AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry = Dev_Id 0x%x\n", bdf);=0A return 0;=0A }=0A =0A- alias_id = =3D ivhd_device->alias.dev_id;=0A+ alias_id =3D alias->used_id;=0A = if ( alias_id >=3D ivrs_bdf_entries )=0A {=0A AMD_IOMMU_DEBUG("= IVHD Error: Invalid Alias Dev_Id 0x%x\n", alias_id);=0A@@ -477,35 +498,34 = @@ static u16 __init parse_ivhd_device_alia=0A =0A AMD_IOMMU_DEBUG(" = Dev_Id Alias: 0x%x\n", alias_id);=0A =0A- add_ivrs_mapping_entry(bdf, = alias_id, ivhd_device->header.flags, iommu);=0A+ add_ivrs_mapping_entry(= bdf, alias_id, alias->header.data_setting, iommu);=0A =0A return = dev_length;=0A }=0A =0A static u16 __init parse_ivhd_device_alias_range(=0A= - union acpi_ivhd_device *ivhd_device,=0A+ const struct acpi_ivhd_dev= ice_alias_range *range,=0A u16 header_length, u16 block_length, struct = amd_iommu *iommu)=0A {=0A =0A u16 dev_length, first_bdf, last_bdf, = alias_id, bdf;=0A =0A- dev_length =3D sizeof(struct acpi_ivhd_device_ali= as_range);=0A+ dev_length =3D sizeof(*range);=0A if ( header_length = < (block_length + dev_length) )=0A {=0A AMD_IOMMU_DEBUG("IVHD = Error: Invalid Device_Entry Length!\n");=0A return 0;=0A }=0A = =0A- if ( ivhd_device->alias_range.trailer.type !=3D=0A- = AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END )=0A+ if ( range->end.header.type = !=3D ACPI_IVRS_TYPE_END )=0A {=0A AMD_IOMMU_DEBUG("IVHD Error: = "=0A "Invalid Range: End_Type 0x%x\n",=0A- = ivhd_device->alias_range.trailer.type);=0A+ = range->end.header.type);=0A return 0;=0A }=0A =0A- = first_bdf =3D ivhd_device->header.dev_id;=0A+ first_bdf =3D range->alias= .header.id;=0A if ( first_bdf >=3D ivrs_bdf_entries )=0A {=0A = AMD_IOMMU_DEBUG("IVHD Error: "=0A@@ -513,7 +533,7 @@ static u16 __init = parse_ivhd_device_alia=0A return 0;=0A }=0A =0A- last_bdf = =3D ivhd_device->alias_range.trailer.dev_id;=0A+ last_bdf =3D range->end= .header.id;=0A if ( last_bdf >=3D ivrs_bdf_entries || last_bdf <=3D = first_bdf )=0A {=0A AMD_IOMMU_DEBUG(=0A@@ -521,7 +541,7 @@ = static u16 __init parse_ivhd_device_alia=0A return 0;=0A }=0A = =0A- alias_id =3D ivhd_device->alias_range.alias.dev_id;=0A+ = alias_id =3D range->alias.used_id;=0A if ( alias_id >=3D ivrs_bdf_entri= es )=0A {=0A AMD_IOMMU_DEBUG("IVHD Error: Invalid Alias Dev_Id = 0x%x\n", alias_id);=0A@@ -532,59 +552,59 @@ static u16 __init parse_ivhd_de= vice_alia=0A AMD_IOMMU_DEBUG(" Dev_Id Alias: 0x%x\n", alias_id);=0A = =0A for ( bdf =3D first_bdf; bdf <=3D last_bdf; bdf++ )=0A- = add_ivrs_mapping_entry(bdf, alias_id, ivhd_device->header.flags, iommu);=0A= + add_ivrs_mapping_entry(bdf, alias_id, range->alias.header.data_set= ting,=0A+ iommu);=0A =0A return = dev_length;=0A }=0A =0A static u16 __init parse_ivhd_device_extended(=0A- = union acpi_ivhd_device *ivhd_device,=0A+ const struct acpi_ivrs_device= 8b *ext,=0A u16 header_length, u16 block_length, struct amd_iommu = *iommu)=0A {=0A u16 dev_length, bdf;=0A =0A- dev_length =3D = sizeof(struct acpi_ivhd_device_extended);=0A+ dev_length =3D sizeof(*ext= );=0A if ( header_length < (block_length + dev_length) )=0A {=0A = AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Length!\n");=0A = return 0;=0A }=0A =0A- bdf =3D ivhd_device->header.dev_id;=0A+ = bdf =3D ext->header.id;=0A if ( bdf >=3D ivrs_bdf_entries )=0A = {=0A AMD_IOMMU_DEBUG("IVHD Error: Invalid Device_Entry Dev_Id = 0x%x\n", bdf);=0A return 0;=0A }=0A =0A- add_ivrs_mapping_en= try(bdf, bdf, ivhd_device->header.flags, iommu);=0A+ add_ivrs_mapping_en= try(bdf, bdf, ext->header.data_setting, iommu);=0A =0A return = dev_length;=0A }=0A =0A static u16 __init parse_ivhd_device_extended_range(= =0A- union acpi_ivhd_device *ivhd_device,=0A+ const struct acpi_ivhd_= device_extended_range *range,=0A u16 header_length, u16 block_length, = struct amd_iommu *iommu)=0A {=0A u16 dev_length, first_bdf, last_bdf, = bdf;=0A =0A- dev_length =3D sizeof(struct acpi_ivhd_device_extended_rang= e);=0A+ dev_length =3D sizeof(*range);=0A if ( header_length < = (block_length + dev_length) )=0A {=0A AMD_IOMMU_DEBUG("IVHD = Error: Invalid Device_Entry Length!\n");=0A return 0;=0A }=0A = =0A- if ( ivhd_device->extended_range.trailer.type !=3D=0A- = AMD_IOMMU_ACPI_IVHD_DEV_RANGE_END )=0A+ if ( range->end.header.type = !=3D ACPI_IVRS_TYPE_END )=0A {=0A AMD_IOMMU_DEBUG("IVHD Error: = "=0A "Invalid Range: End_Type 0x%x\n",=0A- = ivhd_device->extended_range.trailer.type);=0A+ = range->end.header.type);=0A return 0;=0A }=0A =0A- = first_bdf =3D ivhd_device->header.dev_id;=0A+ first_bdf =3D range->exte= nded.header.id;=0A if ( first_bdf >=3D ivrs_bdf_entries )=0A {=0A = AMD_IOMMU_DEBUG("IVHD Error: "=0A@@ -592,7 +612,7 @@ static u16 = __init parse_ivhd_device_exte=0A return 0;=0A }=0A =0A- = last_bdf =3D ivhd_device->extended_range.trailer.dev_id;=0A+ last_bdf = =3D range->end.header.id;=0A if ( (last_bdf >=3D ivrs_bdf_entries) || = (last_bdf <=3D first_bdf) )=0A {=0A AMD_IOMMU_DEBUG("IVHD = Error: "=0A@@ -604,116 +624,116 @@ static u16 __init parse_ivhd_device_exte= =0A first_bdf, last_bdf);=0A =0A for ( bdf =3D = first_bdf; bdf <=3D last_bdf; bdf++ )=0A- add_ivrs_mapping_entry(bdf= , bdf, ivhd_device->header.flags, iommu);=0A+ add_ivrs_mapping_entry= (bdf, bdf, range->extended.header.data_setting,=0A+ = iommu);=0A =0A return dev_length;=0A }=0A =0A static u16 __init = parse_ivhd_device_special(=0A- union acpi_ivhd_device *ivhd_device, u16 = seg,=0A+ const struct acpi_ivrs_device8c *special, u16 seg,=0A u16 = header_length, u16 block_length, struct amd_iommu *iommu)=0A {=0A u16 = dev_length, bdf;=0A =0A- dev_length =3D sizeof(struct acpi_ivhd_device_s= pecial);=0A+ dev_length =3D sizeof(*special);=0A if ( header_length = < (block_length + dev_length) )=0A {=0A AMD_IOMMU_DEBUG("IVHD = Error: Invalid Device_Entry Length!\n");=0A return 0;=0A }=0A = =0A- bdf =3D ivhd_device->special.dev_id;=0A+ bdf =3D special->used_i= d;=0A if ( bdf >=3D ivrs_bdf_entries )=0A {=0A AMD_IOMMU_DE= BUG("IVHD Error: Invalid Device_Entry Dev_Id 0x%x\n", bdf);=0A = return 0;=0A }=0A =0A- add_ivrs_mapping_entry(bdf, bdf, ivhd_device-= >header.flags, iommu);=0A+ add_ivrs_mapping_entry(bdf, bdf, special->hea= der.data_setting, iommu);=0A /* set device id of ioapic */=0A- = ioapic_sbdf[ivhd_device->special.handle].bdf =3D bdf;=0A- ioapic_sbdf[iv= hd_device->special.handle].seg =3D seg;=0A+ ioapic_sbdf[special->handle]= .bdf =3D bdf;=0A+ ioapic_sbdf[special->handle].seg =3D seg;=0A = return dev_length;=0A }=0A =0A-static int __init parse_ivhd_block(struct = acpi_ivhd_block_header *ivhd_block)=0A+static int __init parse_ivhd_block(c= onst struct acpi_ivrs_hardware *ivhd_block)=0A {=0A- union acpi_ivhd_dev= ice *ivhd_device;=0A+ const union acpi_ivhd_device *ivhd_device;=0A = u16 block_length, dev_length;=0A struct amd_iommu *iommu;=0A =0A- = if ( ivhd_block->header.length <=0A- sizeof(struct acpi_ivhd_block_= header) )=0A+ if ( ivhd_block->header.length < sizeof(*ivhd_block) )=0A = {=0A AMD_IOMMU_DEBUG("IVHD Error: Invalid Block Length!\n");=0A= return -ENODEV;=0A }=0A =0A- iommu =3D find_iommu_from_bdf_= cap(ivhd_block->header.dev_id,=0A- = ivhd_block->cap_offset);=0A+ iommu =3D find_iommu_from_bdf_cap(ivhd_bloc= k->header.device_id,=0A+ ivhd_block->cap= ability_offset);=0A if ( !iommu )=0A {=0A AMD_IOMMU_DEBUG("= IVHD Error: No IOMMU for Dev_Id 0x%x Cap 0x%x\n",=0A- = ivhd_block->header.dev_id, ivhd_block->cap_offset);=0A+ = ivhd_block->header.device_id,=0A+ ivhd_block-= >capability_offset);=0A return -ENODEV;=0A }=0A =0A /* = parse Device Entries */=0A- block_length =3D sizeof(struct acpi_ivhd_blo= ck_header);=0A+ block_length =3D sizeof(*ivhd_block);=0A while ( = ivhd_block->header.length >=3D=0A- (block_length + sizeof(struct= acpi_ivhd_device_header)) )=0A+ (block_length + sizeof(struct = acpi_ivrs_de_header)) )=0A {=0A- ivhd_device =3D (union = acpi_ivhd_device *)=0A- ((u8 *)ivhd_block + block_length);=0A+ = ivhd_device =3D (const void *)((const u8 *)ivhd_block + block_length)= ;=0A =0A AMD_IOMMU_DEBUG( "IVHD Device Entry:\n");=0A = AMD_IOMMU_DEBUG( " Type 0x%x\n", ivhd_device->header.type);=0A- = AMD_IOMMU_DEBUG( " Dev_Id 0x%x\n", ivhd_device->header.dev_id);=0A- = AMD_IOMMU_DEBUG( " Flags 0x%x\n", ivhd_device->header.flags);=0A+ = AMD_IOMMU_DEBUG( " Dev_Id 0x%x\n", ivhd_device->header.id);=0A+ = AMD_IOMMU_DEBUG( " Flags 0x%x\n", ivhd_device->header.data_setting);=0A = =0A switch ( ivhd_device->header.type )=0A {=0A- = case AMD_IOMMU_ACPI_IVHD_DEV_U32_PAD:=0A+ case ACPI_IVRS_TYPE_PAD4:= =0A dev_length =3D parse_ivhd_device_padding(=0A = sizeof(u32),=0A ivhd_block->header.length, block_length);= =0A break;=0A- case AMD_IOMMU_ACPI_IVHD_DEV_U64_PAD:=0A+= case ACPI_IVRS_TYPE_PAD8:=0A dev_length =3D parse_ivhd_= device_padding(=0A sizeof(u64),=0A = ivhd_block->header.length, block_length);=0A break;=0A- = case AMD_IOMMU_ACPI_IVHD_DEV_SELECT:=0A- dev_length =3D = parse_ivhd_device_select(ivhd_device, iommu);=0A+ case ACPI_IVRS_TYP= E_SELECT:=0A+ dev_length =3D parse_ivhd_device_select(&ivhd_devi= ce->select, iommu);=0A break;=0A- case AMD_IOMMU_ACPI_IV= HD_DEV_RANGE_START:=0A+ case ACPI_IVRS_TYPE_START:=0A = dev_length =3D parse_ivhd_device_range(=0A- ivhd_device,=0A+= &ivhd_device->range,=0A ivhd_block->header.= length, block_length, iommu);=0A break;=0A- case = AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_SELECT:=0A+ case ACPI_IVRS_TYPE_ALIAS_= SELECT:=0A dev_length =3D parse_ivhd_device_alias(=0A- = ivhd_device,=0A+ &ivhd_device->alias,=0A = ivhd_block->header.length, block_length, iommu);=0A = break;=0A- case AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_RANGE:=0A+ = case ACPI_IVRS_TYPE_ALIAS_START:=0A dev_length =3D parse_ivhd_d= evice_alias_range(=0A- ivhd_device,=0A+ = &ivhd_device->alias_range,=0A ivhd_block->header.length, = block_length, iommu);=0A break;=0A- case AMD_IOMMU_ACPI_= IVHD_DEV_EXT_SELECT:=0A+ case ACPI_IVRS_TYPE_EXT_SELECT:=0A = dev_length =3D parse_ivhd_device_extended(=0A- = ivhd_device,=0A+ &ivhd_device->extended,=0A = ivhd_block->header.length, block_length, iommu);=0A break;=0A- = case AMD_IOMMU_ACPI_IVHD_DEV_EXT_RANGE:=0A+ case ACPI_IVRS_TY= PE_EXT_START:=0A dev_length =3D parse_ivhd_device_extended_rang= e(=0A- ivhd_device,=0A+ &ivhd_device->extende= d_range,=0A ivhd_block->header.length, block_length, = iommu);=0A break;=0A- case AMD_IOMMU_ACPI_IVHD_DEV_SPECI= AL:=0A+ case ACPI_IVRS_TYPE_SPECIAL:=0A dev_length =3D = parse_ivhd_device_special(=0A- ivhd_device, ivhd_block->pci_= segment,=0A+ &ivhd_device->special, ivhd_block->pci_segment_= group,=0A ivhd_block->header.length, block_length, = iommu);=0A break;=0A default:=0A@@ -730,22 +750,24 @@ = static int __init parse_ivhd_block(struc=0A return 0;=0A }=0A = =0A-static int __init parse_ivrs_block(struct acpi_ivrs_block_header = *ivrs_block)=0A+static int __init parse_ivrs_block(const struct acpi_ivrs_h= eader *ivrs_block)=0A {=0A- struct acpi_ivhd_block_header *ivhd_block;= =0A- struct acpi_ivmd_block_header *ivmd_block;=0A+ const struct = acpi_ivrs_hardware *ivhd_block;=0A+ const struct acpi_ivrs_memory = *ivmd_block;=0A =0A switch ( ivrs_block->type )=0A {=0A- case = AMD_IOMMU_ACPI_IVHD_TYPE:=0A- ivhd_block =3D (struct acpi_ivhd_block= _header *)ivrs_block;=0A+ case ACPI_IVRS_TYPE_HARDWARE:=0A+ = ivhd_block =3D container_of(ivrs_block, const struct acpi_ivrs_hardware,=0A= + header);=0A return parse_ivhd_bl= ock(ivhd_block);=0A =0A- case AMD_IOMMU_ACPI_IVMD_ALL_TYPE:=0A- case = AMD_IOMMU_ACPI_IVMD_ONE_TYPE:=0A- case AMD_IOMMU_ACPI_IVMD_RANGE_TYPE:= =0A- case AMD_IOMMU_ACPI_IVMD_IOMMU_TYPE:=0A- ivmd_block =3D = (struct acpi_ivmd_block_header *)ivrs_block;=0A+ case ACPI_IVRS_TYPE_MEM= ORY_ALL:=0A+ case ACPI_IVRS_TYPE_MEMORY_ONE:=0A+ case ACPI_IVRS_TYPE_= MEMORY_RANGE:=0A+ case ACPI_IVRS_TYPE_MEMORY_IOMMU:=0A+ = ivmd_block =3D container_of(ivrs_block, const struct acpi_ivrs_memory,=0A+ = header);=0A return parse_ivmd_bloc= k(ivmd_block);=0A =0A default:=0A@@ -792,12 +814,11 @@ static void = __init dump_acpi_table_heade=0A =0A }=0A =0A-static int __init parse_ivrs_t= able(struct acpi_table_header *_table)=0A+static int __init parse_ivrs_tabl= e(struct acpi_table_header *table)=0A {=0A- struct acpi_ivrs_block_heade= r *ivrs_block;=0A+ const struct acpi_ivrs_header *ivrs_block;=0A = unsigned long length;=0A int error =3D 0;=0A- struct acpi_table_head= er *table =3D (struct acpi_table_header *)_table;=0A =0A BUG_ON(!table)= ;=0A =0A@@ -805,17 +826,16 @@ static int __init parse_ivrs_table(struc=0A = dump_acpi_table_header(table);=0A =0A /* parse IVRS blocks = */=0A- length =3D sizeof(struct acpi_ivrs_table_header);=0A+ length = =3D sizeof(struct acpi_table_ivrs);=0A while ( (error =3D=3D 0) && = (table->length > (length + sizeof(*ivrs_block))) )=0A {=0A- = ivrs_block =3D (struct acpi_ivrs_block_header *)=0A- ((u8 = *)table + length);=0A+ ivrs_block =3D (struct acpi_ivrs_header = *)((u8 *)table + length);=0A =0A AMD_IOMMU_DEBUG("IVRS Block:\n");= =0A AMD_IOMMU_DEBUG(" Type 0x%x\n", ivrs_block->type);=0A = AMD_IOMMU_DEBUG(" Flags 0x%x\n", ivrs_block->flags);=0A AMD_IOMMU_D= EBUG(" Length 0x%x\n", ivrs_block->length);=0A- AMD_IOMMU_DEBUG(" = Dev_Id 0x%x\n", ivrs_block->dev_id);=0A+ AMD_IOMMU_DEBUG(" Dev_Id = 0x%x\n", ivrs_block->device_id);=0A =0A if ( table->length < = (length + ivrs_block->length) )=0A {=0A@@ -833,12 +853,11 @@ = static int __init parse_ivrs_table(struc=0A return error;=0A }=0A = =0A-static int __init detect_iommu_acpi(struct acpi_table_header = *_table)=0A+static int __init detect_iommu_acpi(struct acpi_table_header = *table)=0A {=0A- struct acpi_ivrs_block_header *ivrs_block;=0A- = struct acpi_table_header *table =3D (struct acpi_table_header *)_table;=0A+= const struct acpi_ivrs_header *ivrs_block;=0A unsigned long i;=0A- = unsigned long length =3D sizeof(struct acpi_ivrs_table_header);=0A+ = unsigned long length =3D sizeof(struct acpi_table_ivrs);=0A u8 = checksum, *raw_table;=0A =0A /* validate checksum: sum of entire table = =3D=3D 0 */=0A@@ -854,12 +873,14 @@ static int __init detect_iommu_acpi(str= u=0A =0A while ( table->length > (length + sizeof(*ivrs_block)) )=0A = {=0A- ivrs_block =3D (struct acpi_ivrs_block_header *) ((u8 = *)table + length);=0A+ ivrs_block =3D (struct acpi_ivrs_header = *)((u8 *)table + length);=0A if ( table->length < (length + = ivrs_block->length) )=0A return -ENODEV;=0A- if ( = ivrs_block->type =3D=3D AMD_IOMMU_ACPI_IVHD_TYPE )=0A- if ( = amd_iommu_detect_one_acpi((void*)ivrs_block) !=3D 0 )=0A- = return -ENODEV;=0A+ if ( ivrs_block->type =3D=3D ACPI_IVRS_TYPE_HARD= WARE &&=0A+ amd_iommu_detect_one_acpi(=0A+ = container_of(ivrs_block, const struct acpi_ivrs_hardware,=0A+ = header)) !=3D 0 )=0A+ return -ENODEV;=0A = length +=3D ivrs_block->length;=0A }=0A return 0;=0A@@ -870,63 = +891,59 @@ static int __init detect_iommu_acpi(stru=0A last_bdf =3D = (x); \=0A } while(0);=0A =0A-static int __init get_last_bdf_ivhd(void = *ivhd)=0A+static int __init get_last_bdf_ivhd(=0A+ const struct = acpi_ivrs_hardware *ivhd_block)=0A {=0A- union acpi_ivhd_device = *ivhd_device;=0A+ const union acpi_ivhd_device *ivhd_device;=0A u16 = block_length, dev_length;=0A- struct acpi_ivhd_block_header *ivhd_block;= =0A-=0A- ivhd_block =3D (struct acpi_ivhd_block_header *)ivhd;=0A =0A- = if ( ivhd_block->header.length <=0A- sizeof(struct acpi_ivhd_bloc= k_header) )=0A+ if ( ivhd_block->header.length < sizeof(*ivhd_block) = )=0A {=0A AMD_IOMMU_DEBUG("IVHD Error: Invalid Block Length!\n"= );=0A return -ENODEV;=0A }=0A =0A- block_length =3D = sizeof(struct acpi_ivhd_block_header);=0A+ block_length =3D sizeof(*ivhd= _block);=0A while ( ivhd_block->header.length >=3D=0A- = (block_length + sizeof(struct acpi_ivhd_device_header)) )=0A+ = (block_length + sizeof(struct acpi_ivrs_de_header)) )=0A {=0A- = ivhd_device =3D (union acpi_ivhd_device *)=0A- ((u8 *)ivhd_block= + block_length);=0A+ ivhd_device =3D (const void *)((u8 *)ivhd_bloc= k + block_length);=0A =0A switch ( ivhd_device->header.type )=0A = {=0A- case AMD_IOMMU_ACPI_IVHD_DEV_U32_PAD:=0A+ case = ACPI_IVRS_TYPE_PAD4:=0A dev_length =3D sizeof(u32);=0A = break;=0A- case AMD_IOMMU_ACPI_IVHD_DEV_U64_PAD:=0A+ = case ACPI_IVRS_TYPE_PAD8:=0A dev_length =3D sizeof(u64);=0A = break;=0A- case AMD_IOMMU_ACPI_IVHD_DEV_SELECT:=0A- = UPDATE_LAST_BDF(ivhd_device->header.dev_id);=0A- dev_length = =3D sizeof(struct acpi_ivhd_device_header);=0A- break;=0A- = case AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_SELECT:=0A- UPDATE_LAST_BDF= (ivhd_device->header.dev_id);=0A- dev_length =3D sizeof(struct = acpi_ivhd_device_alias);=0A- break;=0A- case AMD_IOMMU_AC= PI_IVHD_DEV_EXT_SELECT:=0A- UPDATE_LAST_BDF(ivhd_device->header.= dev_id);=0A- dev_length =3D sizeof(struct acpi_ivhd_device_exten= ded);=0A- break;=0A- case AMD_IOMMU_ACPI_IVHD_DEV_RANGE_S= TART:=0A- UPDATE_LAST_BDF(ivhd_device->range.trailer.dev_id);=0A= - dev_length =3D sizeof(struct acpi_ivhd_device_range);=0A- = break;=0A- case AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_RANGE:=0A- = UPDATE_LAST_BDF(ivhd_device->alias_range.trailer.dev_id)=0A- = dev_length =3D sizeof(struct acpi_ivhd_device_alias_range);=0A- = break;=0A- case AMD_IOMMU_ACPI_IVHD_DEV_EXT_RANGE:=0A- = UPDATE_LAST_BDF(ivhd_device->extended_range.trailer.dev_id)=0A- = dev_length =3D sizeof(struct acpi_ivhd_device_extended_range);=0A- = break;=0A- case AMD_IOMMU_ACPI_IVHD_DEV_SPECIAL:=0A- = UPDATE_LAST_BDF(ivhd_device->special.dev_id)=0A- dev_length = =3D sizeof(struct acpi_ivhd_device_special);=0A+ case ACPI_IVRS_TYPE= _SELECT:=0A+ UPDATE_LAST_BDF(ivhd_device->select.header.id);=0A+= dev_length =3D sizeof(ivhd_device->header);=0A+ = break;=0A+ case ACPI_IVRS_TYPE_ALIAS_SELECT:=0A+ = UPDATE_LAST_BDF(ivhd_device->alias.header.id);=0A+ dev_length = =3D sizeof(ivhd_device->alias);=0A+ break;=0A+ case = ACPI_IVRS_TYPE_EXT_SELECT:=0A+ UPDATE_LAST_BDF(ivhd_device->exte= nded.header.id);=0A+ dev_length =3D sizeof(ivhd_device->extended= );=0A+ break;=0A+ case ACPI_IVRS_TYPE_START:=0A+ = UPDATE_LAST_BDF(ivhd_device->range.end.header.id);=0A+ = dev_length =3D sizeof(ivhd_device->range);=0A+ break;=0A+ = case ACPI_IVRS_TYPE_ALIAS_START:=0A+ UPDATE_LAST_BDF(ivhd_devic= e->alias_range.end.header.id)=0A+ dev_length =3D sizeof(ivhd_dev= ice->alias_range);=0A+ break;=0A+ case ACPI_IVRS_TYPE_EXT= _START:=0A+ UPDATE_LAST_BDF(ivhd_device->extended_range.end.head= er.id)=0A+ dev_length =3D sizeof(ivhd_device->extended_range);= =0A+ break;=0A+ case ACPI_IVRS_TYPE_SPECIAL:=0A+ = UPDATE_LAST_BDF(ivhd_device->special.used_id)=0A+ dev_length = =3D sizeof(ivhd_device->special);=0A break;=0A = default:=0A AMD_IOMMU_DEBUG("IVHD Error: Invalid Device = Type!\n");=0A@@ -942,20 +959,21 @@ static int __init get_last_bdf_ivhd(void= =0A return 0;=0A }=0A =0A-static int __init get_last_bdf_acpi(struct = acpi_table_header *_table)=0A+static int __init get_last_bdf_acpi(struct = acpi_table_header *table)=0A {=0A- struct acpi_ivrs_block_header = *ivrs_block;=0A- struct acpi_table_header *table =3D (struct acpi_table_= header *)_table;=0A- unsigned long length =3D sizeof(struct acpi_ivrs_ta= ble_header);=0A+ const struct acpi_ivrs_header *ivrs_block;=0A+ = unsigned long length =3D sizeof(struct acpi_table_ivrs);=0A =0A while = ( table->length > (length + sizeof(*ivrs_block)) )=0A {=0A- = ivrs_block =3D (struct acpi_ivrs_block_header *) ((u8 *)table + length);=0A= + ivrs_block =3D (struct acpi_ivrs_header *)((u8 *)table + = length);=0A if ( table->length < (length + ivrs_block->length) = )=0A return -ENODEV;=0A- if ( ivrs_block->type =3D=3D = AMD_IOMMU_ACPI_IVHD_TYPE )=0A- if ( get_last_bdf_ivhd((void*)ivr= s_block) !=3D 0 )=0A- return -ENODEV;=0A+ if ( = ivrs_block->type =3D=3D ACPI_IVRS_TYPE_HARDWARE &&=0A+ = get_last_bdf_ivhd(=0A+ container_of(ivrs_block, const = struct acpi_ivrs_hardware,=0A+ header)) !=3D = 0 )=0A+ return -ENODEV;=0A length +=3D ivrs_block->lengt= h;=0A }=0A return 0;=0A@@ -963,16 +981,16 @@ static int __init = get_last_bdf_acpi(stru=0A =0A int __init amd_iommu_detect_acpi(void)=0A = {=0A- return acpi_table_parse(AMD_IOMMU_ACPI_IVRS_SIG, detect_iommu_acpi= );=0A+ return acpi_table_parse(ACPI_SIG_IVRS, detect_iommu_acpi);=0A = }=0A =0A int __init amd_iommu_get_ivrs_dev_entries(void)=0A {=0A- = acpi_table_parse(AMD_IOMMU_ACPI_IVRS_SIG, get_last_bdf_acpi);=0A+ = acpi_table_parse(ACPI_SIG_IVRS, get_last_bdf_acpi);=0A return last_bdf = + 1;=0A }=0A =0A int __init amd_iommu_update_ivrs_mapping_acpi(void)=0A = {=0A- return acpi_table_parse(AMD_IOMMU_ACPI_IVRS_SIG, parse_ivrs_table)= ;=0A+ return acpi_table_parse(ACPI_SIG_IVRS, parse_ivrs_table);=0A = }=0A--- a/xen/drivers/passthrough/amd/iommu_detect.c=0A+++ b/xen/drivers/pa= ssthrough/amd/iommu_detect.c=0A@@ -20,12 +20,12 @@=0A =0A #include = =0A #include =0A+#include =0A = #include =0A #include =0A #include = =0A #include =0A #include = =0A-#include =0A =0A static int __init = get_iommu_msi_capabilities(=0A u16 seg, u8 bus, u8 dev, u8 func, = struct amd_iommu *iommu)=0A@@ -103,23 +103,21 @@ void __init get_iommu_feat= ures(struct am=0A }=0A }=0A =0A-int __init amd_iommu_detect_one_acpi(vo= id *ivhd)=0A+int __init amd_iommu_detect_one_acpi(=0A+ const struct = acpi_ivrs_hardware *ivhd_block)=0A {=0A struct amd_iommu *iommu;=0A = u8 bus, dev, func;=0A- struct acpi_ivhd_block_header *ivhd_block;=0A = int rt =3D 0;=0A =0A- ivhd_block =3D (struct acpi_ivhd_block_header = *)ivhd;=0A-=0A- if ( ivhd_block->header.length < sizeof(struct = acpi_ivhd_block_header) )=0A+ if ( ivhd_block->header.length < = sizeof(*ivhd_block) )=0A {=0A AMD_IOMMU_DEBUG("Invalid IVHD = Block Length!\n");=0A return -ENODEV;=0A }=0A =0A- if ( = !ivhd_block->header.dev_id ||=0A- !ivhd_block->cap_offset || = !ivhd_block->mmio_base)=0A+ if ( !ivhd_block->header.device_id ||=0A+ = !ivhd_block->capability_offset || !ivhd_block->base_address)=0A = {=0A AMD_IOMMU_DEBUG("Invalid IVHD Block!\n");=0A return = -ENODEV;=0A@@ -134,10 +132,10 @@ int __init amd_iommu_detect_one_acpi(voi= =0A =0A spin_lock_init(&iommu->lock);=0A =0A- iommu->seg =3D = ivhd_block->pci_segment;=0A- iommu->bdf =3D ivhd_block->header.dev_id;= =0A- iommu->cap_offset =3D ivhd_block->cap_offset;=0A- iommu->mmio_ba= se_phys =3D ivhd_block->mmio_base;=0A+ iommu->seg =3D ivhd_block->pci_se= gment_group;=0A+ iommu->bdf =3D ivhd_block->header.device_id;=0A+ = iommu->cap_offset =3D ivhd_block->capability_offset;=0A+ iommu->mmio_bas= e_phys =3D ivhd_block->base_address;=0A =0A /* override IOMMU HT flags = */=0A iommu->ht_flags =3D ivhd_block->header.flags;=0A--- a/xen/drivers= /passthrough/amd/iommu_init.c=0A+++ b/xen/drivers/passthrough/amd/iommu_ini= t.c=0A@@ -20,6 +20,7 @@=0A =0A #include =0A #include = =0A+#include =0A #include =0A #include = =0A #include =0A@@ -28,7 +29,6 @@=0A #include = =0A #include =0A #include = =0A-#include =0A =0A static int = __initdata nr_amd_iommus;=0A =0A@@ -37,9 +37,8 @@ static struct radix_tree_= root ivrs_maps;=0A struct list_head amd_iommu_head;=0A struct table_struct = device_table;=0A =0A-static int iommu_has_ht_flag(struct amd_iommu *iommu, = uint8_t bit)=0A+static int iommu_has_ht_flag(struct amd_iommu *iommu, u8 = mask)=0A {=0A- u8 mask =3D 1U << bit;=0A return iommu->ht_flags & = mask;=0A }=0A =0A@@ -80,19 +79,19 @@ static void set_iommu_ht_flags(struct = am=0A =0A /* Setup HT flags */=0A if ( iommu_has_cap(iommu, = PCI_CAP_HT_TUNNEL_SHIFT) )=0A- iommu_has_ht_flag(iommu, AMD_IOMMU_AC= PI_HT_TUN_ENB_SHIFT) ?=0A+ iommu_has_ht_flag(iommu, ACPI_IVHD_TT_ENA= BLE) ?=0A iommu_set_bit(&entry, IOMMU_CONTROL_HT_TUNNEL_TRANSLA= TION_SHIFT) :=0A iommu_clear_bit(&entry, IOMMU_CONTROL_HT_TUNNE= L_TRANSLATION_SHIFT);=0A =0A- iommu_has_ht_flag(iommu, AMD_IOMMU_ACPI_RE= S_PASS_PW_SHIFT) ?=0A+ iommu_has_ht_flag(iommu, ACPI_IVHD_RES_PASS_PW) = ?=0A iommu_set_bit(&entry, IOMMU_CONTROL_RESP_PASS_POSTED_WRITE_SHI= FT):=0A iommu_clear_bit(&entry, IOMMU_CONTROL_RESP_PASS_POSTED_WRIT= E_SHIFT);=0A =0A- iommu_has_ht_flag(iommu, AMD_IOMMU_ACPI_ISOC_SHIFT) = ?=0A+ iommu_has_ht_flag(iommu, ACPI_IVHD_ISOC) ?=0A iommu_set_bi= t(&entry, IOMMU_CONTROL_ISOCHRONOUS_SHIFT):=0A iommu_clear_bit(&ent= ry, IOMMU_CONTROL_ISOCHRONOUS_SHIFT);=0A =0A- iommu_has_ht_flag(iommu, = AMD_IOMMU_ACPI_PASS_PW_SHIFT) ?=0A+ iommu_has_ht_flag(iommu, ACPI_IVHD_P= ASS_PW) ?=0A iommu_set_bit(&entry, IOMMU_CONTROL_PASS_POSTED_WRITE_= SHIFT):=0A iommu_clear_bit(&entry, IOMMU_CONTROL_PASS_POSTED_WRITE_= SHIFT);=0A =0A--- a/xen/drivers/passthrough/amd/iommu_map.c=0A+++ = b/xen/drivers/passthrough/amd/iommu_map.c=0A@@ -18,12 +18,13 @@=0A * = Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 = USA=0A */=0A =0A+#include =0A+#include =0A = #include =0A #include =0A #include =0A #include =0A #include = =0A-#include =0A #include "../ats.h"=0A = #include =0A =0A@@ -215,8 +216,7 @@ void __init iommu_dte_add_de= vice_entry(u=0A dte[7] =3D dte[6] =3D dte[4] =3D dte[2] =3D dte[1] =3D = dte[0] =3D 0;=0A =0A flags =3D ivrs_dev->device_flags;=0A- sys_mgt = =3D get_field_from_byte(flags, AMD_IOMMU_ACPI_SYS_MGT_MASK,=0A- = AMD_IOMMU_ACPI_SYS_MGT_SHIFT);=0A+ sys_mgt =3D = get_field_from_byte(flags, ACPI_IVHD_SYSTEM_MGMT);=0A dev_ex =3D = ivrs_dev->dte_allow_exclusion;=0A =0A flags &=3D mask;=0A--- a/xen/incl= ude/asm-x86/hvm/svm/amd-iommu-acpi.h=0A+++ /dev/null=0A@@ -1,185 +0,0 = @@=0A-/*=0A- * Copyright (C) 2007 Advanced Micro Devices, Inc.=0A- * = Author: Leo Duran =0A- * Author: Wei Wang - adapted to xen=0A- *=0A- * This program is free software; you can = redistribute it and/or modify=0A- * it under the terms of the GNU General = Public License as published by=0A- * the Free Software Foundation; either = version 2 of the License, or=0A- * (at your option) any later version.=0A- = *=0A- * This program is distributed in the hope that it will be useful,=0A-= * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A- * = MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A- * GNU = General Public License for more details.=0A- *=0A- * You should have = received a copy of the GNU General Public License=0A- * along with this = program; if not, write to the Free Software=0A- * Foundation, Inc., 59 = Temple Place, Suite 330, Boston, MA 02111-1307 USA=0A- */=0A-=0A-#ifndef = _ASM_X86_64_AMD_IOMMU_ACPI_H=0A-#define _ASM_X86_64_AMD_IOMMU_ACPI_H=0A-=0A= -#include =0A-=0A-/* I/O Virtualization Reporting Structure = */=0A-#define AMD_IOMMU_ACPI_IVRS_SIG "IVRS"=0A-#define = AMD_IOMMU_ACPI_IVHD_TYPE 0x10=0A-#define AMD_IOMMU_ACPI_IVMD_ALL_TYPE= 0x20=0A-#define AMD_IOMMU_ACPI_IVMD_ONE_TYPE 0x21=0A-#define = AMD_IOMMU_ACPI_IVMD_RANGE_TYPE 0x22=0A-#define AMD_IOMMU_ACPI_IVMD_IOMM= U_TYPE 0x23=0A-=0A-/* 4-byte Device Entries */=0A-#define AMD_IOMMU_ACP= I_IVHD_DEV_U32_PAD 0=0A-#define AMD_IOMMU_ACPI_IVHD_DEV_SELECT = 2=0A-#define AMD_IOMMU_ACPI_IVHD_DEV_RANGE_START 3=0A-#define AMD_IOMMU_= ACPI_IVHD_DEV_RANGE_END 4=0A-=0A-/* 8-byte Device Entries */=0A-#define = AMD_IOMMU_ACPI_IVHD_DEV_U64_PAD 64=0A-#define AMD_IOMMU_ACPI_IVHD_DE= V_ALIAS_SELECT 66=0A-#define AMD_IOMMU_ACPI_IVHD_DEV_ALIAS_RANGE = 67=0A-#define AMD_IOMMU_ACPI_IVHD_DEV_EXT_SELECT 70=0A-#define AMD_IOMMU_AC= PI_IVHD_DEV_EXT_RANGE 71=0A-#define AMD_IOMMU_ACPI_IVHD_DEV_SPECIAL = 72=0A-=0A-/* IVHD IOMMU Flags */=0A-#define AMD_IOMMU_ACPI_COHERENT_MASK = 0x20=0A-#define AMD_IOMMU_ACPI_COHERENT_SHIFT 5=0A-#define = AMD_IOMMU_ACPI_IOTLB_SUP_MASK 0x10=0A-#define AMD_IOMMU_ACPI_IOTLB_SUP= _SHIFT 4=0A-#define AMD_IOMMU_ACPI_ISOC_MASK 0x08=0A-#define = AMD_IOMMU_ACPI_ISOC_SHIFT 3=0A-#define AMD_IOMMU_ACPI_RES_PASS_PW_MASK= 0x04=0A-#define AMD_IOMMU_ACPI_RES_PASS_PW_SHIFT 2=0A-#define = AMD_IOMMU_ACPI_PASS_PW_MASK 0x02=0A-#define AMD_IOMMU_ACPI_PASS_PW_S= HIFT 1=0A-#define AMD_IOMMU_ACPI_HT_TUN_ENB_MASK 0x01=0A-#define = AMD_IOMMU_ACPI_HT_TUN_ENB_SHIFT 0=0A-=0A-/* IVHD Device Flags = */=0A-#define AMD_IOMMU_ACPI_LINT1_PASS_MASK 0x80=0A-#define AMD_IOMMU_= ACPI_LINT1_PASS_SHIFT 7=0A-#define AMD_IOMMU_ACPI_LINT0_PASS_MASK = 0x40=0A-#define AMD_IOMMU_ACPI_LINT0_PASS_SHIFT 6=0A-#define = AMD_IOMMU_ACPI_SYS_MGT_MASK 0x30=0A-#define AMD_IOMMU_ACPI_SYS_MGT_S= HIFT 4=0A-#define AMD_IOMMU_ACPI_NMI_PASS_MASK 0x04=0A-#define = AMD_IOMMU_ACPI_NMI_PASS_SHIFT 2=0A-#define AMD_IOMMU_ACPI_EINT_PASS_MA= SK 0x02=0A-#define AMD_IOMMU_ACPI_EINT_PASS_SHIFT 1=0A-#define = AMD_IOMMU_ACPI_INIT_PASS_MASK 0x01=0A-#define AMD_IOMMU_ACPI_INIT_PASS= _SHIFT 0=0A-=0A-/* IVHD Device Extended Flags */=0A-#define AMD_IOMMU_A= CPI_ATS_DISABLED_MASK 0x80000000=0A-#define AMD_IOMMU_ACPI_ATS_DISABLED_S= HIFT 31=0A-=0A-/* IVMD Device Flags */=0A-#define AMD_IOMMU_ACPI_EXCLUSION= _RANGE_MASK 0x08=0A-#define AMD_IOMMU_ACPI_EXCLUSION_RANGE_SHIFT = 3=0A-#define AMD_IOMMU_ACPI_IW_PERMISSION_MASK 0x04=0A-#define AMD_IOMMU_A= CPI_IW_PERMISSION_SHIFT 2=0A-#define AMD_IOMMU_ACPI_IR_PERMISSION_MASK = 0x02=0A-#define AMD_IOMMU_ACPI_IR_PERMISSION_SHIFT 1=0A-#define AMD_IOMMU_A= CPI_UNITY_MAPPING_MASK 0x01=0A-#define AMD_IOMMU_ACPI_UNITY_MAPPING_SHIFT = 0=0A-=0A-#define ACPI_OEM_ID_SIZE 6=0A-#define ACPI_OEM_TABL= E_ID_SIZE 8=0A-=0A-#pragma pack(1)=0A-struct acpi_ivrs_table_heade= r {=0A- struct acpi_table_header acpi_header;=0A- u32 io_info;=0A- = u8 reserved[8];=0A-};=0A-=0A-struct acpi_ivrs_block_header {=0A- u8 = type;=0A- u8 flags;=0A- u16 length;=0A- u16 dev_id;=0A-};=0A-=0A-str= uct acpi_ivhd_block_header {=0A- struct acpi_ivrs_block_header header;=0A= - u16 cap_offset;=0A- u64 mmio_base;=0A- u16 pci_segment;=0A- u16 = iommu_info;=0A- u8 reserved[4];=0A-};=0A-=0A-struct acpi_ivhd_device_head= er {=0A- u8 type;=0A- u16 dev_id;=0A- u8 flags;=0A-};=0A-=0A-struct= acpi_ivhd_device_trailer {=0A- u8 type;=0A- u16 dev_id;=0A- u8 = reserved;=0A-};=0A-=0A-struct acpi_ivhd_device_range {=0A- struct = acpi_ivhd_device_header header;=0A- struct acpi_ivhd_device_trailer = trailer;=0A-};=0A-=0A-struct acpi_ivhd_device_alias {=0A- struct = acpi_ivhd_device_header header;=0A- u8 reserved1;=0A- u16 dev_id;=0A- = u8 reserved2;=0A-};=0A-=0A-struct acpi_ivhd_device_alias_range {=0A- = struct acpi_ivhd_device_alias alias;=0A- struct acpi_ivhd_device_trailer = trailer;=0A-};=0A-=0A-struct acpi_ivhd_device_extended {=0A- struct = acpi_ivhd_device_header header;=0A- u32 ext_flags;=0A-};=0A-=0A-struct = acpi_ivhd_device_extended_range {=0A- struct acpi_ivhd_device_extended = extended;=0A- struct acpi_ivhd_device_trailer trailer;=0A-};=0A-=0A-struc= t acpi_ivhd_device_special {=0A- struct acpi_ivhd_device_header = header;=0A- u8 handle;=0A- u16 dev_id;=0A- u8 variety;=0A-};=0A-=0A= -union acpi_ivhd_device {=0A- struct acpi_ivhd_device_header header;=0A- = struct acpi_ivhd_device_range range;=0A- struct acpi_ivhd_device_alias = alias;=0A- struct acpi_ivhd_device_alias_range alias_range;=0A- struct = acpi_ivhd_device_extended extended;=0A- struct acpi_ivhd_device_extended_= range extended_range;=0A- struct acpi_ivhd_device_special special;=0A-};= =0A-=0A-struct acpi_ivmd_block_header {=0A- struct acpi_ivrs_block_header= header;=0A- union {=0A- u16 last_dev_id;=0A- u16 cap_offset;= =0A- u16 reserved1;=0A- };=0A- u64 reserved2;=0A- u64 = start_addr;=0A- u64 mem_length;=0A-};=0A-#pragma pack()=0A-=0A-#endif /* = _ASM_X86_64_AMD_IOMMU_ACPI_H */=0A--- a/xen/include/asm-x86/hvm/svm/amd-iom= mu-proto.h=0A+++ b/xen/include/asm-x86/hvm/svm/amd-iommu-proto.h=0A@@ = -26,6 +26,8 @@=0A #include =0A #include = =0A =0A+struct acpi_ivrs_hardware;=0A+=0A #define for_each_amd_iommu(amd_io= mmu) \=0A list_for_each_entry(amd_iommu, \=0A &amd_iommu_head, = list)=0A@@ -41,7 +43,7 @@=0A =0A /* amd-iommu-detect functions */=0A int = amd_iommu_get_ivrs_dev_entries(void);=0A-int amd_iommu_detect_one_acpi(void= *ivhd);=0A+int amd_iommu_detect_one_acpi(const struct acpi_ivrs_hardware = *);=0A int amd_iommu_detect_acpi(void);=0A void get_iommu_features(struct = amd_iommu *iommu);=0A =0A@@ -121,11 +123,9 @@ static inline u32 set_field_i= n_reg_u32(u=0A return reg_value;=0A }=0A =0A-static inline u8 = get_field_from_byte(u8 value, u8 mask, u8 shift)=0A+static inline u8 = get_field_from_byte(u8 value, u8 mask)=0A {=0A- u8 field;=0A- field = =3D (value & mask) >> shift;=0A- return field;=0A+ return (value & = mask) / (mask & -mask);=0A }=0A =0A static inline unsigned long region_to_p= ages(unsigned long addr, unsigned long size)=0A --=__Part456AE0A2.0__= 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.xensource.com http://lists.xensource.com/xen-devel --=__Part456AE0A2.0__=--