Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86, iommu: Make all IOMMU's detection routines return a value.

We return 1 if the IOMMU has been detected. Zero or an error number
if we failed to find it. This is in preperation of using the IOMMU_INIT
so that we can detect whether an IOMMU is present. I have not
tested this for regression on Calgary, nor on AMD Vi chipsets as
I don't have that hardware.

CC: Muli Ben-Yehuda <muli@il.ibm.com>
CC: "Jon D. Mason" <jdmason@kudzu.us>
CC: "Darrick J. Wong" <djwong@us.ibm.com>
CC: Jesse Barnes <jbarnes@virtuousgeek.org>
CC: David Woodhouse <David.Woodhouse@intel.com>
CC: Chris Wright <chrisw@sous-sol.org>
CC: Yinghai Lu <yinghai@kernel.org>
CC: Joerg Roedel <joerg.roedel@amd.com>
CC: H. Peter Anvin <hpa@zytor.com>
CC: Fujita Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
LKML-Reference: <1282845485-8991-3-git-send-email-konrad.wilk@oracle.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>

authored by

Konrad Rzeszutek Wilk and committed by
H. Peter Anvin
480125ba 0444ad93

+33 -24
+2 -2
arch/x86/include/asm/amd_iommu.h
··· 24 24 25 25 #ifdef CONFIG_AMD_IOMMU 26 26 27 - extern void amd_iommu_detect(void); 27 + extern int amd_iommu_detect(void); 28 28 29 29 #else 30 30 31 - static inline void amd_iommu_detect(void) { } 31 + static inline int amd_iommu_detect(void) { return -ENODEV; } 32 32 33 33 #endif 34 34
+2 -2
arch/x86/include/asm/calgary.h
··· 62 62 extern int use_calgary; 63 63 64 64 #ifdef CONFIG_CALGARY_IOMMU 65 - extern void detect_calgary(void); 65 + extern int detect_calgary(void); 66 66 #else 67 - static inline void detect_calgary(void) { return; } 67 + static inline int detect_calgary(void) { return -ENODEV; } 68 68 #endif 69 69 70 70 #endif /* _ASM_X86_CALGARY_H */
+3 -2
arch/x86/include/asm/gart.h
··· 37 37 extern void early_gart_iommu_check(void); 38 38 extern int gart_iommu_init(void); 39 39 extern void __init gart_parse_options(char *); 40 - extern void gart_iommu_hole_init(void); 40 + extern int gart_iommu_hole_init(void); 41 41 42 42 #else 43 43 #define gart_iommu_aperture 0 ··· 50 50 static inline void gart_parse_options(char *options) 51 51 { 52 52 } 53 - static inline void gart_iommu_hole_init(void) 53 + static inline int gart_iommu_hole_init(void) 54 54 { 55 + return -ENODEV; 55 56 } 56 57 #endif 57 58
+5 -3
arch/x86/kernel/amd_iommu_init.c
··· 1382 1382 return 0; 1383 1383 } 1384 1384 1385 - void __init amd_iommu_detect(void) 1385 + int __init amd_iommu_detect(void) 1386 1386 { 1387 1387 if (no_iommu || (iommu_detected && !gart_iommu_aperture)) 1388 - return; 1388 + return -ENODEV; 1389 1389 1390 1390 if (amd_iommu_disabled) 1391 - return; 1391 + return -ENODEV; 1392 1392 1393 1393 if (acpi_table_parse("IVRS", early_amd_iommu_detect) == 0) { 1394 1394 iommu_detected = 1; ··· 1397 1397 1398 1398 /* Make sure ACS will be enabled */ 1399 1399 pci_request_acs(); 1400 + return 1; 1400 1401 } 1402 + return -ENODEV; 1401 1403 } 1402 1404 1403 1405 /****************************************************************************
+7 -4
arch/x86/kernel/aperture_64.c
··· 371 371 372 372 static int __initdata printed_gart_size_msg; 373 373 374 - void __init gart_iommu_hole_init(void) 374 + int __init gart_iommu_hole_init(void) 375 375 { 376 376 u32 agp_aper_base = 0, agp_aper_order = 0; 377 377 u32 aper_size, aper_alloc = 0, aper_order = 0, last_aper_order = 0; ··· 381 381 382 382 if (gart_iommu_aperture_disabled || !fix_aperture || 383 383 !early_pci_allowed()) 384 - return; 384 + return -ENODEV; 385 385 386 386 printk(KERN_INFO "Checking aperture...\n"); 387 387 ··· 463 463 unsigned long n = (32 * 1024 * 1024) << last_aper_order; 464 464 465 465 insert_aperture_resource((u32)last_aper_base, n); 466 + return 1; 466 467 } 467 - return; 468 + return 0; 468 469 } 469 470 470 471 if (!fallback_aper_force) { ··· 501 500 panic("Not enough memory for aperture"); 502 501 } 503 502 } else { 504 - return; 503 + return 0; 505 504 } 506 505 507 506 /* Fix up the north bridges */ ··· 525 524 } 526 525 527 526 set_up_gart_resume(aper_order, aper_alloc); 527 + 528 + return 1; 528 529 }
+8 -7
arch/x86/kernel/pci-calgary_64.c
··· 1364 1364 return 0; 1365 1365 } 1366 1366 1367 - void __init detect_calgary(void) 1367 + int __init detect_calgary(void) 1368 1368 { 1369 1369 int bus; 1370 1370 void *tbl; ··· 1378 1378 * another HW IOMMU already, bail out. 1379 1379 */ 1380 1380 if (no_iommu || iommu_detected) 1381 - return; 1381 + return -ENODEV; 1382 1382 1383 1383 if (!use_calgary) 1384 - return; 1384 + return -ENODEV; 1385 1385 1386 1386 if (!early_pci_allowed()) 1387 - return; 1387 + return -ENODEV; 1388 1388 1389 1389 printk(KERN_DEBUG "Calgary: detecting Calgary via BIOS EBDA area\n"); 1390 1390 ··· 1410 1410 if (!rio_table_hdr) { 1411 1411 printk(KERN_DEBUG "Calgary: Unable to locate Rio Grande table " 1412 1412 "in EBDA - bailing!\n"); 1413 - return; 1413 + return -ENODEV; 1414 1414 } 1415 1415 1416 1416 ret = build_detail_arrays(); 1417 1417 if (ret) { 1418 1418 printk(KERN_DEBUG "Calgary: build_detail_arrays ret %d\n", ret); 1419 - return; 1419 + return -ENOMEM; 1420 1420 } 1421 1421 1422 1422 specified_table_size = determine_tce_table_size((is_kdump_kernel() ? ··· 1464 1464 1465 1465 x86_init.iommu.iommu_init = calgary_iommu_init; 1466 1466 } 1467 - return; 1467 + return calgary_found; 1468 1468 1469 1469 cleanup: 1470 1470 for (--bus; bus >= 0; --bus) { ··· 1473 1473 if (info->tce_space) 1474 1474 free_tce_table(info->tce_space); 1475 1475 } 1476 + return -ENOMEM; 1476 1477 } 1477 1478 1478 1479 static int __init calgary_parse_options(char *p)
+3 -1
drivers/pci/dmar.c
··· 687 687 return 0; 688 688 } 689 689 690 - void __init detect_intel_iommu(void) 690 + int __init detect_intel_iommu(void) 691 691 { 692 692 int ret; 693 693 ··· 723 723 } 724 724 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size); 725 725 dmar_tbl = NULL; 726 + 727 + return (ret ? 1 : -ENODEV); 726 728 } 727 729 728 730
+3 -3
include/linux/dmar.h
··· 57 57 extern int dmar_dev_scope_init(void); 58 58 59 59 /* Intel IOMMU detection */ 60 - extern void detect_intel_iommu(void); 60 + extern int detect_intel_iommu(void); 61 61 extern int enable_drhd_fault_handling(void); 62 62 63 63 extern int parse_ioapics_under_ir(void); 64 64 extern int alloc_iommu(struct dmar_drhd_unit *); 65 65 #else 66 - static inline void detect_intel_iommu(void) 66 + static inline int detect_intel_iommu(void) 67 67 { 68 - return; 68 + return -ENODEV; 69 69 } 70 70 71 71 static inline int dmar_table_init(void)