public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Joerg Roedel <joerg.roedel@amd.com>
Cc: tglx@linutronix.de, mingo@redhat.com,
	linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
	bhavna.sarathy@amd.com, Sebastian.Biemueller@amd.com,
	robert.richter@amd.com, joro@8bytes.org
Subject: Re: [PATCH 14/34] AMD IOMMU: clue initialization code together
Date: Wed, 9 Jul 2008 18:55:12 -0700	[thread overview]
Message-ID: <20080709185512.6355159c.akpm@linux-foundation.org> (raw)
In-Reply-To: <1214508490-29683-15-git-send-email-joerg.roedel@amd.com>

On Thu, 26 Jun 2008 21:27:50 +0200 Joerg Roedel <joerg.roedel@amd.com> wrote:

> This patch puts the AMD IOMMU ACPI table parsing and hardware initialization
> functions together to the main intialization routine.
> 
> index 555fcc9..c792ddc 100644
> --- a/arch/x86/kernel/amd_iommu_init.c
> +++ b/arch/x86/kernel/amd_iommu_init.c
> @@ -643,3 +643,129 @@ static int __init init_memory_definitions(struct acpi_table_header *table)
>  	return 0;
>  }
>  
> +int __init amd_iommu_init(void)
> +{
> +	int i, ret = 0;
> +
> +
> +	if (amd_iommu_disable) {
> +		printk(KERN_INFO "AMD IOMMU disabled by kernel command line\n");
> +		return 0;
> +	}
> +
> +	/*
> +	 * First parse ACPI tables to find the largest Bus/Dev/Func
> +	 * we need to handle. Upon this information the shared data
> +	 * structures for the IOMMUs in the system will be allocated
> +	 */
> +	if (acpi_table_parse("IVRS", find_last_devid_acpi) != 0)
> +		return -ENODEV;
> +
> +	dev_table_size     = TBL_SIZE(DEV_TABLE_ENTRY_SIZE);
> +	alias_table_size   = TBL_SIZE(ALIAS_TABLE_ENTRY_SIZE);
> +	rlookup_table_size = TBL_SIZE(RLOOKUP_TABLE_ENTRY_SIZE);
> +
> +	ret = -ENOMEM;
> +
> +	/* Device table - directly used by all IOMMUs */
> +	amd_iommu_dev_table = (void *)__get_free_pages(GFP_KERNEL,
> +				      get_order(dev_table_size));

Is there a reason for using __get_free_pages() in this manner everywhere? 
kmalloc() or kzalloc() are unsuitable?

> +	if (amd_iommu_dev_table == NULL)
> +		goto out;
> +
> +	/*
> +	 * Alias table - map PCI Bus/Dev/Func to Bus/Dev/Func the
> +	 * IOMMU see for that device
> +	 */
> +	amd_iommu_alias_table = (void *)__get_free_pages(GFP_KERNEL,
> +			get_order(alias_table_size));
> +	if (amd_iommu_alias_table == NULL)
> +		goto free;
> +
> +	/* IOMMU rlookup table - find the IOMMU for a specific device */
> +	amd_iommu_rlookup_table = (void *)__get_free_pages(GFP_KERNEL,
> +			get_order(rlookup_table_size));
> +	if (amd_iommu_rlookup_table == NULL)
> +		goto free;
> +
> +	/*
> +	 * Protection Domain table - maps devices to protection domains
> +	 * This table has the same size as the rlookup_table
> +	 */
> +	amd_iommu_pd_table = (void *)__get_free_pages(GFP_KERNEL,
> +				     get_order(rlookup_table_size));
> +	if (amd_iommu_pd_table == NULL)
> +		goto free;
> +
> +	amd_iommu_pd_alloc_bitmap = (void *)__get_free_pages(GFP_KERNEL,
> +					    get_order(MAX_DOMAIN_ID/8));
> +	if (amd_iommu_pd_alloc_bitmap == NULL)
> +		goto free;
> +
> +	/*
> +	 * memory is allocated now; initialize the device table with all zeroes
> +	 * and let all alias entries point to itself
> +	 */
> +	memset(amd_iommu_dev_table, 0, dev_table_size);
> +	for (i = 0; i < amd_iommu_last_bdf; ++i)
> +		amd_iommu_alias_table[i] = i;
> +
> +	memset(amd_iommu_pd_table, 0, rlookup_table_size);
> +	memset(amd_iommu_pd_alloc_bitmap, 0, MAX_DOMAIN_ID / 8);

Use of __GFP_ZERO in here would relieve us of a lot of memsets.

> +	/*
> +	 * never allocate domain 0 because its used as the non-allocated and
> +	 * error value placeholder
> +	 */
> +	amd_iommu_pd_alloc_bitmap[0] = 1;
> +
> +	/*
> +	 * now the data structures are allocated and basically initialized
> +	 * start the real acpi table scan
> +	 */
> +	ret = -ENODEV;
> +	if (acpi_table_parse("IVRS", init_iommu_all) != 0)
> +		goto free;
> +
> +	if (acpi_table_parse("IVRS", init_memory_definitions) != 0)
> +		goto free;
> +
> +	printk(KERN_INFO "AMD IOMMU: aperture size is %d MB\n",
> +			(1 << (amd_iommu_aperture_order-20)));
> +
> +	printk(KERN_INFO "AMD IOMMU: device isolation ");
> +	if (amd_iommu_isolate)
> +		printk("enabled\n");
> +	else
> +		printk("disabled\n");
> +
> +out:
> +	return ret;
> +
> +free:
> +	if (amd_iommu_pd_alloc_bitmap)
> +		free_pages((unsigned long)amd_iommu_pd_alloc_bitmap, 1);
> +
> +	if (amd_iommu_pd_table)
> +		free_pages((unsigned long)amd_iommu_pd_table,
> +				get_order(rlookup_table_size));
> +
> +	if (amd_iommu_rlookup_table)
> +		free_pages((unsigned long)amd_iommu_rlookup_table,
> +				get_order(rlookup_table_size));
> +
> +	if (amd_iommu_alias_table)
> +		free_pages((unsigned long)amd_iommu_alias_table,
> +				get_order(alias_table_size));
> +
> +	if (amd_iommu_dev_table)
> +		free_pages((unsigned long)amd_iommu_dev_table,
> +				get_order(dev_table_size));

free_pages(0) is legal, so all these tests are unneeded, I expect.

This remains true if you decide to switch to kzalloc().

> +	free_iommu_all();
> +
> +	free_unity_maps();
> +
> +	goto out;
> +}


  reply	other threads:[~2008-07-10  2:01 UTC|newest]

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-26 19:27 [PATCH 00/34] AMD IOMMU driver Joerg Roedel
2008-06-26 19:27 ` [PATCH 01/34] AMD IOMMU: add Kconfig entry Joerg Roedel
2008-06-27 14:25   ` Adrian Bunk
2008-06-27 14:47     ` Andi Kleen
2008-06-27 16:39       ` Muli Ben-Yehuda
2008-06-27 16:54         ` Joerg Roedel
2008-06-27 16:59           ` Muli Ben-Yehuda
2008-06-27 17:05             ` Joerg Roedel
2008-06-27 17:12               ` Muli Ben-Yehuda
2008-06-27 17:20                 ` Joerg Roedel
2008-06-27 17:31                   ` Muli Ben-Yehuda
2008-06-27 17:40                     ` Joerg Roedel
2008-06-27 17:44                       ` Muli Ben-Yehuda
2008-06-27 17:52                         ` Joerg Roedel
2008-07-02  5:45                       ` Amit Shah
2008-07-02  8:12                         ` Alan Cox
2008-06-27 20:39               ` Duran, Leo
2008-06-27 22:29                 ` Muli Ben-Yehuda
2008-06-27 22:47                   ` Duran, Leo
2008-06-28 11:04                     ` Joerg Roedel
2008-06-28 14:40                       ` Duran, Leo
2008-06-28 16:27                         ` Joerg Roedel
2008-06-28 14:58                       ` Duran, Leo
2008-06-27 18:54           ` Andi Kleen
2008-06-28 10:52             ` Joerg Roedel
2008-06-27 16:40     ` Joerg Roedel
2008-07-08 12:45   ` Pavel Machek
2008-07-09  8:48     ` Ingo Molnar
2008-07-10  0:50       ` FUJITA Tomonori
2008-07-10  8:44         ` Ingo Molnar
2008-06-26 19:27 ` [PATCH 02/34] AMD IOMMU: add header file for driver data structures and defines Joerg Roedel
2008-06-29 15:07   ` FUJITA Tomonori
2008-06-29 15:14     ` Joerg Roedel
2008-06-29 23:11       ` FUJITA Tomonori
2008-06-30 12:22         ` Ingo Molnar
2008-07-10  1:38   ` Andrew Morton
2008-07-10  1:50     ` Arjan van de Ven
2008-07-10  2:36       ` Andrew Morton
2008-07-10 12:12         ` Joerg Roedel
2008-07-10 12:59           ` Andrew Morton
2008-06-26 19:27 ` [PATCH 03/34] AMD IOMMU: add defines and structures for ACPI scanning code Joerg Roedel
2008-07-10  1:41   ` Andrew Morton
2008-07-10 12:17     ` Joerg Roedel
2008-06-26 19:27 ` [PATCH 04/34] AMD IOMMU: add data structures to manage the IOMMUs in the system Joerg Roedel
2008-07-10  1:43   ` Andrew Morton
2008-07-10 12:25     ` Joerg Roedel
2008-06-26 19:27 ` [PATCH 05/34] AMD IOMMU: add functions to find last possible PCI device for IOMMU Joerg Roedel
2008-06-26 19:27 ` [PATCH 06/34] AMD IOMMU: add amd_iommu_init.c to Makefile Joerg Roedel
2008-06-26 19:27 ` [PATCH 07/34] AMD IOMMU: add functions for mapping/unmapping the MMIO space Joerg Roedel
2008-06-26 19:27 ` [PATCH 08/34] AMD IOMMU: add functions for programming IOMMU " Joerg Roedel
2008-06-26 19:27 ` [PATCH 09/34] AMD IOMMU: add command buffer (de-)allocation Joerg Roedel
2008-07-10  1:47   ` Andrew Morton
2008-06-26 19:27 ` [PATCH 10/34] AMD IOMMU: add device table initialization functions Joerg Roedel
2008-06-26 19:27 ` [PATCH 11/34] AMD IOMMU: add functions for IOMMU hardware initialization from ACPI Joerg Roedel
2008-07-10  1:49   ` Andrew Morton
2008-06-26 19:27 ` [PATCH 12/34] AMD IOMMU: add detect code for AMD IOMMU hardware Joerg Roedel
2008-07-10  1:51   ` Andrew Morton
2008-06-26 19:27 ` [PATCH 13/34] AMD IOMMU: add functions to parse IOMMU memory mapping requirements for devices Joerg Roedel
2008-07-10  1:51   ` Andrew Morton
2008-06-26 19:27 ` [PATCH 14/34] AMD IOMMU: clue initialization code together Joerg Roedel
2008-07-10  1:55   ` Andrew Morton [this message]
2008-07-10 12:37     ` Joerg Roedel
2008-07-10 13:03       ` Andrew Morton
2008-07-10 13:31         ` Joerg Roedel
2008-07-10 18:37           ` Joerg Roedel
2008-06-26 19:27 ` [PATCH 15/34] AMD IOMMU: add early detection code Joerg Roedel
2008-06-26 19:27 ` [PATCH 16/34] AMD IOMMU: add kernel command line parameters for AMD IOMMU Joerg Roedel
2008-07-10  1:56   ` Andrew Morton
2008-07-10  4:25     ` FUJITA Tomonori
2008-07-10  4:39       ` Andrew Morton
2008-07-10  6:26         ` Ingo Molnar
2008-07-10 20:42           ` Randy Dunlap
2008-07-14 23:56           ` FUJITA Tomonori
2008-07-10  7:04   ` Yinghai Lu
2008-07-10 12:41     ` Joerg Roedel
2008-06-26 19:27 ` [PATCH 17/34] AMD IOMMU: add generic defines and structures for mapping code Joerg Roedel
2008-07-10  2:01   ` Andrew Morton
2008-07-10  2:38     ` Andrew Morton
2008-07-10  4:25     ` FUJITA Tomonori
2008-07-10 12:44       ` Joerg Roedel
2008-06-26 19:27 ` [PATCH 18/34] AMD IOMMU: add amd_iommu.c to Makefile Joerg Roedel
2008-06-26 19:27 ` [PATCH 19/34] AMD IOMMU: add functions to send IOMMU commands Joerg Roedel
2008-07-10  2:04   ` Andrew Morton
2008-07-10 12:53     ` Joerg Roedel
2008-06-26 19:27 ` [PATCH 20/34] AMD IOMMU: add functions to initialize unity mappings Joerg Roedel
2008-06-26 19:27 ` [PATCH 21/34] AMD IOMMU: add address allocation and deallocation functions Joerg Roedel
2008-06-29 15:07   ` FUJITA Tomonori
2008-06-29 15:17     ` Joerg Roedel
2008-06-29 23:11       ` FUJITA Tomonori
2008-06-26 19:27 ` [PATCH 22/34] AMD IOMMU: add domain " Joerg Roedel
2008-07-10  2:14   ` Andrew Morton
2008-07-10 12:54     ` Joerg Roedel
2008-06-26 19:27 ` [PATCH 23/34] AMD IOMMU: add functions to find IOMMU device resources Joerg Roedel
2008-07-10  2:18   ` Andrew Morton
2008-07-10 16:46     ` Joerg Roedel
2008-07-10 23:59       ` Andrew Morton
2008-06-26 19:28 ` [PATCH 24/34] AMD IOMMU: add generic dma_ops mapping functions Joerg Roedel
2008-06-26 19:28 ` [PATCH 25/34] AMD IOMMU: add dma_ops mapping functions for single mappings Joerg Roedel
2008-07-10  2:26   ` Andrew Morton
2008-07-10 13:20     ` Joerg Roedel
2008-06-26 19:28 ` [PATCH 26/34] AMD IOMMU: add mapping functions for scatter gather lists Joerg Roedel
2008-06-29 15:07   ` FUJITA Tomonori
2008-06-30 13:25     ` Joerg Roedel
2008-06-26 19:28 ` [PATCH 27/34] AMD IOMMU: add mapping functions for coherent mappings Joerg Roedel
2008-06-26 19:28 ` [PATCH 28/34] AMD IOMMU: add pre-allocation of protection domains Joerg Roedel
2008-06-26 19:28 ` [PATCH 29/34] AMD IOMMU: add dma_ops initialization function Joerg Roedel
2008-06-26 19:28 ` [PATCH 30/34] AMD IOMMU: add amd_iommu.h to export functions to the generic x86 dma code Joerg Roedel
2008-06-26 19:28 ` [PATCH 31/34] AMD IOMMU: initialize dma_ops from IOMMU initialization and enable IOMMUs Joerg Roedel
2008-06-26 19:28 ` [PATCH 32/34] AMD_IOMMU: call detect and initialization functions from dma code Joerg Roedel
2008-06-26 19:28 ` [PATCH 33/34] AMD IOMMU: add MAINTAINERS entry Joerg Roedel
2008-06-26 19:28 ` [PATCH 34/34] AMD IOMMU: add documentation for kernel parameters Joerg Roedel
2008-06-29 15:07   ` FUJITA Tomonori
2008-06-30 12:25     ` Ingo Molnar
2008-06-26 20:37 ` [PATCH 00/34] AMD IOMMU driver Rafael J. Wysocki
2008-06-26 20:37   ` Joerg Roedel
2008-06-26 21:02     ` Rafael J. Wysocki
2008-06-27  8:18 ` Ingo Molnar
2008-06-27 10:07   ` Ingo Molnar
2008-06-27 10:15     ` Joerg Roedel
2008-06-27 10:59   ` Joerg Roedel
2008-07-11 10:22 ` Eric W. Biederman
2008-07-11 14:11   ` Joerg Roedel
2008-07-11 16:23   ` Duran, Leo
2008-07-11 17:20     ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080709185512.6355159c.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=Sebastian.Biemueller@amd.com \
    --cc=bhavna.sarathy@amd.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joerg.roedel@amd.com \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=robert.richter@amd.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox