@@ -138,9 +138,9 @@ int amd_iommus_present;
138138bool amd_iommu_np_cache __read_mostly ;
139139
140140/*
141- * Set to true if ACPI table parsing and hardware intialization went properly
141+ * The ACPI table parsing functions set this variable on an error
142142 */
143- static bool amd_iommu_initialized ;
143+ static int __initdata amd_iommu_init_err ;
144144
145145/*
146146 * List of protection domains - used during resume
@@ -391,9 +391,11 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table)
391391 */
392392 for (i = 0 ; i < table -> length ; ++ i )
393393 checksum += p [i ];
394- if (checksum != 0 )
394+ if (checksum != 0 ) {
395395 /* ACPI table corrupt */
396- return - ENODEV ;
396+ amd_iommu_init_err = - ENODEV ;
397+ return 0 ;
398+ }
397399
398400 p += IVRS_HEADER_LENGTH ;
399401
@@ -436,7 +438,7 @@ static u8 * __init alloc_command_buffer(struct amd_iommu *iommu)
436438 if (cmd_buf == NULL )
437439 return NULL ;
438440
439- iommu -> cmd_buf_size = CMD_BUFFER_SIZE ;
441+ iommu -> cmd_buf_size = CMD_BUFFER_SIZE | CMD_BUFFER_UNINITIALIZED ;
440442
441443 return cmd_buf ;
442444}
@@ -472,12 +474,13 @@ static void iommu_enable_command_buffer(struct amd_iommu *iommu)
472474 & entry , sizeof (entry ));
473475
474476 amd_iommu_reset_cmd_buffer (iommu );
477+ iommu -> cmd_buf_size &= ~(CMD_BUFFER_UNINITIALIZED );
475478}
476479
477480static void __init free_command_buffer (struct amd_iommu * iommu )
478481{
479482 free_pages ((unsigned long )iommu -> cmd_buf ,
480- get_order (iommu -> cmd_buf_size ));
483+ get_order (iommu -> cmd_buf_size & ~( CMD_BUFFER_UNINITIALIZED ) ));
481484}
482485
483486/* allocates the memory where the IOMMU will log its events to */
@@ -920,11 +923,16 @@ static int __init init_iommu_all(struct acpi_table_header *table)
920923 h -> mmio_phys );
921924
922925 iommu = kzalloc (sizeof (struct amd_iommu ), GFP_KERNEL );
923- if (iommu == NULL )
924- return - ENOMEM ;
926+ if (iommu == NULL ) {
927+ amd_iommu_init_err = - ENOMEM ;
928+ return 0 ;
929+ }
930+
925931 ret = init_iommu_one (iommu , h );
926- if (ret )
927- return ret ;
932+ if (ret ) {
933+ amd_iommu_init_err = ret ;
934+ return 0 ;
935+ }
928936 break ;
929937 default :
930938 break ;
@@ -934,8 +942,6 @@ static int __init init_iommu_all(struct acpi_table_header *table)
934942 }
935943 WARN_ON (p != end );
936944
937- amd_iommu_initialized = true;
938-
939945 return 0 ;
940946}
941947
@@ -1211,6 +1217,10 @@ static int __init amd_iommu_init(void)
12111217 if (acpi_table_parse ("IVRS" , find_last_devid_acpi ) != 0 )
12121218 return - ENODEV ;
12131219
1220+ ret = amd_iommu_init_err ;
1221+ if (ret )
1222+ goto out ;
1223+
12141224 dev_table_size = tbl_size (DEV_TABLE_ENTRY_SIZE );
12151225 alias_table_size = tbl_size (ALIAS_TABLE_ENTRY_SIZE );
12161226 rlookup_table_size = tbl_size (RLOOKUP_TABLE_ENTRY_SIZE );
@@ -1270,12 +1280,19 @@ static int __init amd_iommu_init(void)
12701280 if (acpi_table_parse ("IVRS" , init_iommu_all ) != 0 )
12711281 goto free ;
12721282
1273- if (!amd_iommu_initialized )
1283+ if (amd_iommu_init_err ) {
1284+ ret = amd_iommu_init_err ;
12741285 goto free ;
1286+ }
12751287
12761288 if (acpi_table_parse ("IVRS" , init_memory_definitions ) != 0 )
12771289 goto free ;
12781290
1291+ if (amd_iommu_init_err ) {
1292+ ret = amd_iommu_init_err ;
1293+ goto free ;
1294+ }
1295+
12791296 ret = sysdev_class_register (& amd_iommu_sysdev_class );
12801297 if (ret )
12811298 goto free ;
@@ -1288,6 +1305,8 @@ static int __init amd_iommu_init(void)
12881305 if (ret )
12891306 goto free ;
12901307
1308+ enable_iommus ();
1309+
12911310 if (iommu_pass_through )
12921311 ret = amd_iommu_init_passthrough ();
12931312 else
@@ -1300,8 +1319,6 @@ static int __init amd_iommu_init(void)
13001319
13011320 amd_iommu_init_notifier ();
13021321
1303- enable_iommus ();
1304-
13051322 if (iommu_pass_through )
13061323 goto out ;
13071324
@@ -1315,6 +1332,7 @@ static int __init amd_iommu_init(void)
13151332 return ret ;
13161333
13171334free :
1335+ disable_iommus ();
13181336
13191337 amd_iommu_uninit_devices ();
13201338
0 commit comments