linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Michael Ellerman <michael@ellerman.id.au>
Cc: linuxppc-dev@ozlabs.org, cbe-oss-dev@ozlabs.org
Subject: Re: [PATCH 4/4] Avoid DMA exception when using axon_msi with IOMMU
Date: Tue, 05 Feb 2008 11:21:25 +1100	[thread overview]
Message-ID: <1202170885.7079.30.camel@pasglop> (raw)
In-Reply-To: <f1b51505f34145d7b096fef167c14c4409f0baf6.1201240265.git.michael@ellerman.id.au>


On Fri, 2008-01-25 at 16:59 +1100, Michael Ellerman wrote:
> There's a brown-paper-bag bug in axon_msi, we pass the address of our
> FIFO directly to the hardware, without DMA mapping it. This leads to
> DMA exceptions if you enable MSI & the IOMMU.
> 
> The fix is to correctly DMA map the fifo, dma_alloc_coherent() does
> what we want - and we need to track the virt & phys addresses.
> 
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> ---
>  arch/powerpc/platforms/cell/axon_msi.c |   21 ++++++++++-----------
>  1 files changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/cell/axon_msi.c b/arch/powerpc/platforms/cell/axon_msi.c
> index ea3dc8c..b9a97c4 100644
> --- a/arch/powerpc/platforms/cell/axon_msi.c
> +++ b/arch/powerpc/platforms/cell/axon_msi.c
> @@ -65,7 +65,8 @@
>  
>  struct axon_msic {
>  	struct irq_host *irq_host;
> -	__le32 *fifo;
> +	__le32 *fifo_virt;
> +	dma_addr_t fifo_phys;
>  	dcr_host_t dcr_host;
>  	u32 read_offset;
>  };
> @@ -91,7 +92,7 @@ static void axon_msi_cascade(unsigned int irq, struct irq_desc *desc)
>  
>  	while (msic->read_offset != write_offset) {
>  		idx  = msic->read_offset / sizeof(__le32);
> -		msi  = le32_to_cpu(msic->fifo[idx]);
> +		msi  = le32_to_cpu(msic->fifo_virt[idx]);
>  		msi &= 0xFFFF;
>  
>  		pr_debug("axon_msi: woff %x roff %x msi %x\n",
> @@ -306,7 +307,6 @@ static int axon_msi_shutdown(struct of_device *device)
>  static int axon_msi_probe(struct of_device *device,
>  			  const struct of_device_id *device_id)
>  {
> -	struct page *page;
>  	struct device_node *dn = device->node;
>  	struct axon_msic *msic;
>  	unsigned int virq;
> @@ -338,16 +338,14 @@ static int axon_msi_probe(struct of_device *device,
>  		goto out_free_msic;
>  	}
>  
> -	page = alloc_pages_node(of_node_to_nid(dn), GFP_KERNEL,
> -				get_order(MSIC_FIFO_SIZE_BYTES));
> -	if (!page) {
> +	msic->fifo_virt = dma_alloc_coherent(&device->dev, MSIC_FIFO_SIZE_BYTES,
> +					     &msic->fifo_phys, GFP_KERNEL);
> +	if (!msic->fifo_virt) {
>  		printk(KERN_ERR "axon_msi: couldn't allocate fifo for %s\n",
>  		       dn->full_name);
>  		goto out_free_msic;
>  	}
>  
> -	msic->fifo = page_address(page);
> -
>  	msic->irq_host = irq_alloc_host(of_node_get(dn), IRQ_HOST_MAP_NOMAP,
>  					NR_IRQS, &msic_host_ops, 0);
>  	if (!msic->irq_host) {
> @@ -370,9 +368,9 @@ static int axon_msi_probe(struct of_device *device,
>  	pr_debug("axon_msi: irq 0x%x setup for axon_msi\n", virq);
>  
>  	/* Enable the MSIC hardware */
> -	msic_dcr_write(msic, MSIC_BASE_ADDR_HI_REG, (u64)msic->fifo >> 32);
> +	msic_dcr_write(msic, MSIC_BASE_ADDR_HI_REG, msic->fifo_phys >> 32);
>  	msic_dcr_write(msic, MSIC_BASE_ADDR_LO_REG,
> -				  (u64)msic->fifo & 0xFFFFFFFF);
> +				  msic->fifo_phys & 0xFFFFFFFF);
>  	msic_dcr_write(msic, MSIC_CTRL_REG,
>  			MSIC_CTRL_IRQ_ENABLE | MSIC_CTRL_ENABLE |
>  			MSIC_CTRL_FIFO_SIZE);
> @@ -390,7 +388,8 @@ static int axon_msi_probe(struct of_device *device,
>  out_free_host:
>  	kfree(msic->irq_host);
>  out_free_fifo:
> -	__free_pages(virt_to_page(msic->fifo), get_order(MSIC_FIFO_SIZE_BYTES));
> +	dma_free_coherent(&device->dev, MSIC_FIFO_SIZE_BYTES, msic->fifo_virt,
> +			  msic->fifo_phys);
>  out_free_msic:
>  	kfree(msic);
>  out:

  reply	other threads:[~2008-02-05  0:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-25  5:59 [PATCH 1/4] Search for and publish cell OF platform devices earlier Michael Ellerman
2008-01-25  5:59 ` [PATCH 2/4] Create and hook up of_platform_device_shutdown Michael Ellerman
2008-02-05  0:19   ` Benjamin Herrenschmidt
2008-01-25  5:59 ` [PATCH 4/4] Avoid DMA exception when using axon_msi with IOMMU Michael Ellerman
2008-02-05  0:21   ` Benjamin Herrenschmidt [this message]
2008-01-25  5:59 ` [PATCH 3/4] Convert axon_msi to an of_platform driver Michael Ellerman
2008-02-05  0:20   ` Benjamin Herrenschmidt
2008-02-05  0:19 ` [PATCH 1/4] Search for and publish cell OF platform devices earlier Benjamin Herrenschmidt
  -- strict thread matches above, loose matches on Subject: below --
2008-01-22 11:04 Michael Ellerman
2008-01-22 11:04 ` [PATCH 4/4] Avoid DMA exception when using axon_msi with IOMMU Michael Ellerman

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=1202170885.7079.30.camel@pasglop \
    --to=benh@kernel.crashing.org \
    --cc=cbe-oss-dev@ozlabs.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=michael@ellerman.id.au \
    /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;
as well as URLs for NNTP newsgroup(s).