LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 1/5] powerpc/macio: Add devres support to macio_device
From: Tejun Heo @ 2009-12-01  7:20 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linux-ide, linuxppc-dev, jeff
In-Reply-To: <20091201070832.37EB8B7B65@ozlabs.org>

On 12/01/2009 04:08 PM, Benjamin Herrenschmidt wrote:
> This adds some basic devres support. When enabled via macio_enable_devres()
> resources requested by drivers will be automatically released.
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

Acked-by: Tejun Heo <tj@kernel.org>

-- 
tejun

^ permalink raw reply

* Re: [PATCH 4/5] libata/sff: Use ops->bmdma_stop instead of ata_bmdma_stop()
From: Tejun Heo @ 2009-12-01  7:25 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linux-ide, linuxppc-dev, jeff
In-Reply-To: <20091201070833.CC084B7BD9@ozlabs.org>

On 12/01/2009 04:08 PM, Benjamin Herrenschmidt wrote:
> In libata-sff, ata_sff_post_internal_cmd() directly calls ata_bmdma_stop()
> instead of ap->ops->bmdma_stop(). This can be a problem for controllers
> that use their own bmdma_stop for which the generic sff one isn't suitable
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

Oh... that's a scary bug lurking around.  Thanks for catching it.

Acked-by: Tejun Heo <tj@kernel.org>

-- 
tejun

^ permalink raw reply

* Re: [PATCH 4/5] libata/sff: Use ops->bmdma_stop instead of ata_bmdma_stop()
From: Benjamin Herrenschmidt @ 2009-12-01  7:29 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-ide, linuxppc-dev, jeff
In-Reply-To: <4B14C4DC.6060107@kernel.org>

On Tue, 2009-12-01 at 16:25 +0900, Tejun Heo wrote:
> On 12/01/2009 04:08 PM, Benjamin Herrenschmidt wrote:
> > In libata-sff, ata_sff_post_internal_cmd() directly calls ata_bmdma_stop()
> > instead of ap->ops->bmdma_stop(). This can be a problem for controllers
> > that use their own bmdma_stop for which the generic sff one isn't suitable
> > 
> > Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> 
> Oh... that's a scary bug lurking around.  Thanks for catching it.
> 
> Acked-by: Tejun Heo <tj@kernel.org>

Feel free to pick that one up earlier if you want (ie for 2.6.32), as
long as we manage to get it in in 2.6.33 -before- I push powerpc-next to
Linus, I'm happy :-) (or we can have it in both trees).

Cheers,
Ben.

^ permalink raw reply

* Re: [PATCH 4/5] libata/sff: Use ops->bmdma_stop instead of ata_bmdma_stop()
From: Tejun Heo @ 2009-12-01  7:33 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linux-ide, linuxppc-dev, jeff
In-Reply-To: <1259652545.2076.321.camel@pasglop>

On 12/01/2009 04:29 PM, Benjamin Herrenschmidt wrote:
> On Tue, 2009-12-01 at 16:25 +0900, Tejun Heo wrote:
>> On 12/01/2009 04:08 PM, Benjamin Herrenschmidt wrote:
>>> In libata-sff, ata_sff_post_internal_cmd() directly calls ata_bmdma_stop()
>>> instead of ap->ops->bmdma_stop(). This can be a problem for controllers
>>> that use their own bmdma_stop for which the generic sff one isn't suitable
>>>
>>> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>>
>> Oh... that's a scary bug lurking around.  Thanks for catching it.
>>
>> Acked-by: Tejun Heo <tj@kernel.org>
> 
> Feel free to pick that one up earlier if you want (ie for 2.6.32), as
> long as we manage to get it in in 2.6.33 -before- I push powerpc-next to
> Linus, I'm happy :-) (or we can have it in both trees).

As nasty as the bug might be, given that we haven't had too much
problem with that, I think it would be best to give it some time to be
tested before releasing it to users.  It causes behavior differences
for all bmdma drivers which implement custom bmdma_stop.  It's an
apparent bug fix but well the nasty ones are always apparent bug
fixes, right?  :-)

Thanks.

-- 
tejun

^ permalink raw reply

* Re: [RFC PATCH v3 3/3] powerpc: gamecube/wii: early debugging using usbgecko
From: Richard Holden @ 2009-12-01  7:43 UTC (permalink / raw)
  To: Albert Herranz; +Cc: linuxppc-dev
In-Reply-To: <4B14A834.4070907@yahoo.es>


On Nov 30, 2009, at 10:23 PM, Albert Herranz wrote:

> Richard Holden wrote:
>> Albert Herranz wrote:
> The first patch is generic, and uses PPC_EARLY_DEBUG.
> This is the first patch where PPC_EARLY_DEBUG_USBGECKO is referenced.

Sorry, you are correct.

>>> diff --git a/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c =
b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
>>> index ba4c7cc..3f125b6 100644
>>> --- a/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
>>> +++ b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
>>> @@ -17,6 +17,7 @@
>>> #include <asm/io.h>
>>> #include <asm/prom.h>
>>> #include <asm/udbg.h>
>>> +#include <asm/fixmap.h>
>>>=20
>>> #include "usbgecko_udbg.h"
>>>=20
>>> @@ -270,3 +271,61 @@ done:
>>> 		of_node_put(np);
>>> 	return;
>>> }
>>> +
>>> +#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
>>> +
>>> +static void __init ug_early_remap(void)
>>=20
>> you may want to rename the ug_ prefix, it took me a while looking =
back
>> and forth through the patch to convince myself it wasn't a typo.
>>=20
>=20
> What's wrong with ug_ ? (ug =3D (u)sb(g)ecko)
>=20

At first look I thought it was a typo of udbg_early_remap. I prefer the =
longer names although we could use gecko_early_remap unless the gecko =
prefix conflicts with anything else. If there is not going to be a non =
usb gecko then there is no need to have usb in the prefix.

-Richard Holden=

^ permalink raw reply

* Re: [PATCH 4/5] libata/sff: Use ops->bmdma_stop instead of ata_bmdma_stop()
From: Benjamin Herrenschmidt @ 2009-12-01  7:57 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linux-ide, linuxppc-dev, jeff
In-Reply-To: <4B14C6D7.3030303@kernel.org>

On Tue, 2009-12-01 at 16:33 +0900, Tejun Heo wrote:
> > Feel free to pick that one up earlier if you want (ie for 2.6.32),
> as
> > long as we manage to get it in in 2.6.33 -before- I push
> powerpc-next to
> > Linus, I'm happy :-) (or we can have it in both trees).
> 
> As nasty as the bug might be, given that we haven't had too much
> problem with that, I think it would be best to give it some time to be
> tested before releasing it to users.  It causes behavior differences
> for all bmdma drivers which implement custom bmdma_stop.  It's an
> apparent bug fix but well the nasty ones are always apparent bug
> fixes, right?  :-) 

Yeah, I agree. I wouldn't be comfortable pushing it into .32 to be
honest after a quick grep of how many drivers actually use that hook and
considering that no problem was reported so far...

I'll merge it with the rest of the powerpc stuff during the .33 merge
window if you are ok with that.

Cheers,
Ben.

^ permalink raw reply

* Re: [PATCH 5/5] libata/drivers: Add pata_macio, driver Apple PowerMac/PowerBook IDE controller
From: Tejun Heo @ 2009-12-01  8:00 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linux-ide, Holger Macht, linuxppc-dev, Jeff Garzik
In-Reply-To: <20091201070834.6A840B7B63@ozlabs.org>

(cc'ing Holger Macht, please read the comment below pata_macio_mb_event())
Hello,

On 12/01/2009 04:08 PM, Benjamin Herrenschmidt wrote:
> This is a libata driver for the "macio" IDE controller used on most Apple
> PowerMac and PowerBooks. It's a libata equivalent of drivers/ide/ppc/pmac.c

Don't know much about the controller or the platform so my comments
will be pretty confined.

> +/*
> + * Wait 1s for disk to answer on IDE bus after a hard reset
> + * of the device (via GPIO/FCR).
> + *
> + * Some devices seem to "pollute" the bus even after dropping
> + * the BSY bit (typically some combo drives slave on the UDMA
> + * bus) after a hard reset. Since we hard reset all drives on
> + * KeyLargo ATA66, we have to keep that delay around. I may end
> + * up not hard resetting anymore on these and keep the delay only
> + * for older interfaces instead (we have to reset when coming
> + * from MacOS...) --BenH.
> + */
> +#define IDE_WAKEUP_DELAY	(1*HZ)

nitpick: In libata, it's common to use msecs for timing values so that
might be a better option.

> +static const struct pata_macio_timing *pata_macio_find_timing(
> +					    struct pata_macio_priv *priv,
> +					    int mode)
> +{
> +	int i = 0;
> +
> +	while (priv->timings[i].mode > 0) {
> +		if (priv->timings[i].mode == mode)
> +			return &priv->timings[i];
> +		i++;
> +	}
> +	return NULL;

Wouldn't for (i = 0; ...) look better?

> +static void pata_macio_bmdma_start(struct ata_queued_cmd *qc)
> +{
> +	struct ata_port *ap = qc->ap;
> +	struct pata_macio_priv *priv = ap->private_data;
> +	struct dbdma_regs __iomem *dma_regs = ap->ioaddr.bmdma_addr;
> +
> +	dev_dbgdma(priv->dev, "%s: qc %p\n", __func__, qc);
> +
> +	writel((RUN << 16) | RUN, &dma_regs->control);
> +	/* Make sure it gets to the controller right now */
> +	(void)readl(&dma_regs->control);

Is flushing necessary here?  There's no ordering issue here, right?

> +static void pata_macio_bmdma_stop(struct ata_queued_cmd *qc)
> +{
> +	struct ata_port *ap = qc->ap;
> +	struct pata_macio_priv *priv = ap->private_data;
> +	struct dbdma_regs __iomem *dma_regs = ap->ioaddr.bmdma_addr;
> +
> +	dev_dbgdma(priv->dev, "%s: qc %p\n", __func__, qc);
> +
> +	/* Stop the DMA engine and wait for it to full halt */
> +	writel (((RUN|WAKE|DEAD) << 16), &dma_regs->control);
> +	while (readl(&dma_regs->status) & RUN)
> +		udelay(1);

Heh... this is a scary looking loop.  It would be great if the above
loop can be capped somehow.

> +static u8 pata_macio_bmdma_status(struct ata_port *ap)
> +{
> +	struct pata_macio_priv *priv = ap->private_data;
> +	struct dbdma_regs __iomem *dma_regs = ap->ioaddr.bmdma_addr;
> +	u32 dstat, rstat = ATA_DMA_INTR;
> +	unsigned long timeout = 0;
> +
> +	dstat = readl(&dma_regs->status);
> +
> +	dev_dbgdma(priv->dev, "%s: dstat=%x\n", __func__, dstat);
> +
> +	/* We have to things to deal with here:
                   ^^
                   two

> +/* port_start is when we allocate the DMA command list */
> +static int pata_macio_port_start(struct ata_port *ap)
> +{
> +	struct pata_macio_priv *priv = ap->private_data;
> +	struct dbdma_regs __iomem *dma_regs = ap->ioaddr.bmdma_addr;
> +
> +	if (dma_regs == NULL)
> +		return 0;
> +
> +	/* Make sure DMA controller is stopped */
> +	writel((RUN|PAUSE|FLUSH|WAKE|DEAD) << 16, &dma_regs->control);
> +	while (readl(&dma_regs->status) & RUN)
> +		udelay(1);

Hmmm.... this probably belongs to ->freeze() which is responsible for
stopping any in-flight operations and masking IRQ and libata will call
it during initialization before requesting IRQ, so you won't need to
call it explicitly here.

> +#ifdef CONFIG_PMAC_MEDIABAY
> +static void pata_macio_mb_event(struct macio_dev* mdev, int mb_state)
> +{
> +	struct ata_host *host = macio_get_drvdata(mdev);
> +	struct ata_port *ap;
> +	struct ata_eh_info *ehi;
> +	struct ata_device *dev;
> +	unsigned long flags;
> +
> +	if (!host)
> +		return;
> +	ap = host->ports[0];
> +	spin_lock_irqsave(ap->lock, flags);
> +	ehi = &ap->link.eh_info;
> +	if (mb_state == MB_CD) {
> +		ata_ehi_push_desc(ehi, "mediabay plug");
> +		ata_ehi_hotplugged(ehi);
> +		ata_port_freeze(ap);
> +	} else {
> +		ata_ehi_push_desc(ehi, "mediabay unplug");
> +		ata_for_each_dev(dev, &ap->link, ALL)
> +			dev->flags |= ATA_DFLAG_DETACH;
> +		ata_port_schedule_eh(ap);

I think you'll need an ata_port_freeze() or abort() here because at
this point the drive is already gone and all in-flight commands need
to be failed right away.  Holger, do you remember why
ata_acpi_detach_device() is using ata_port_schedule_eh() instead?  Was
it because ata_port_freeze() might end up poking registers after
hotunplug happened?  ISTR reports where accessing any register there
causing the whole system to lock up but then why can't it use
ata_port_abort() instead?

Thanks.

-- 
tejun

^ permalink raw reply

* MPC5200B XLB BSDIS question
From: Roman Fietze @ 2009-12-01 10:03 UTC (permalink / raw)
  To: linuxppc-dev

Hello list,

In our old, modified 2.4.25 I had a statement that sets the bit BSDIS
(real world bit 16, Freescale bit 15) in the XLB config register for
the MPC5200B.

Checking the XLB config of "my" 2.6.32-rc7 doesn't show this bit set
(XLB config reads 0x0000a006).

But this gives me trouble when running under high (BestComm) load. I
have a stress test programm that writes data via PATA to an ext3
filesystem as fast as possible. At the same time I'm using the SCLPC
together with BestComm to read data from FLASH as fast as possible in
64KiB blocks.

Without this bit set I have wrong data in the DMA receive buffer,
almost always only in the first data word (32 bits wide).

And I also have wrong data if I do not invalidate_dcache_range my DMA
buffer before starting the BC task. Looking at dma_map_single or the
old pci_map_single shows me, that they do the cache invalidation on
architecture with non coherent cache, the MPC5200 should be one of
them.

See this old thread that seems to second my theory about a problem in
the MPC5200B, which wouldn't be the first one:

http://www.mail-archive.com/linuxppc-embedded@ozlabs.org/msg02842.html


Is there a reason not to set that bit? Is it true, as I believe it,
that the "polairity" of this bit is documented the wrong way e.g. in
=46reescale's AN3045?


Roman

=2D-=20
Roman Fietze                Telemotive AG B=FCro M=FChlhausen
Breitwiesen                              73347 M=FChlhausen
Tel.: +49(0)7335/18493-45        http://www.telemotive.de

^ permalink raw reply

* [PATCH] powerpc/mm: setting mmaped page cache property through device tree
From: Li Yang @ 2009-12-01 10:30 UTC (permalink / raw)
  To: benh, paulus; +Cc: linuxppc-dev, linux-kernel

The patch adds the ability for powerpc architecture to set page cache
property of mmaped area through device tree.  This is useful for two
cases.  First, for memory shared with other OS'es to have the same cache
property to avoid cache paradoxes.  Second, enabling application to map
memory which is not managed by kernel as cacheable for better performance.

Signed-off-by: Li Yang <leoli@freescale.com>
---
Although it will be better if we can come up with a generic solution
not only for powerpc arch.  Changing the behavior of O_SYNC seems to
draw concerns over compatibility of old applications.  Suggestions
are welcomed.

 arch/powerpc/mm/mem.c          |   49 +++++++++++++++++++++++++++++++++++++--
 arch/powerpc/platforms/Kconfig |    7 +++++
 2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 579382c..02da2c8 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -95,16 +95,59 @@ int page_is_ram(unsigned long pfn)
 #endif
 }
 
+#ifdef CONFIG_OF_MMAP_CACHE_PROPERTY
+pgprot_t pgprot_from_dt(unsigned long pfn, pgprot_t vma_prot)
+{
+	struct device_node *np;
+	struct resource res;
+	unsigned long paddr = (pfn << PAGE_SHIFT);
+	int i;
+	const int *prop;
+
+	for_each_node_by_name(np, "mmap-region")
+		for (i = 0; of_address_to_resource(np, i, &res) == 0; i++)
+			if ((paddr >= res.start) && (paddr <= res.end)) {
+				unsigned long _prot;
+				prop = of_get_property(np, "cache-property",
+						NULL);
+
+				if (prop == NULL)
+					return vma_prot;
+
+				_prot = pgprot_val(vma_prot) & ~_PAGE_CACHE_CTL;
+
+				/* bit map of WIMG */
+				if (*prop & 0x8)
+					_prot |= _PAGE_WRITETHRU;
+				if (*prop & 0x4)
+					_prot |= _PAGE_NO_CACHE;
+				if (*prop & 0x2)
+					_prot |= _PAGE_COHERENT;
+				if (*prop & 0x1)
+					_prot |= _PAGE_GUARDED;
+
+				return __pgprot(_prot);
+			}
+
+	return vma_prot;
+}
+#endif
+
 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
 			      unsigned long size, pgprot_t vma_prot)
 {
 	if (ppc_md.phys_mem_access_prot)
 		return ppc_md.phys_mem_access_prot(file, pfn, size, vma_prot);
 
-	if (!page_is_ram(pfn))
-		vma_prot = pgprot_noncached(vma_prot);
+	/* kernel managed memory is always mapped as cacheable */
+	if (page_is_ram(pfn))
+		return vma_prot;
 
-	return vma_prot;
+#ifdef CONFIG_OF_MMAP_CACHE_PROPERTY
+	return pgprot_from_dt(pfn, vma_prot);
+#else
+	return pgprot_noncached(vma_prot);
+#endif
 }
 EXPORT_SYMBOL(phys_mem_access_prot);
 
diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
index 12bc2ce..de0f57c 100644
--- a/arch/powerpc/platforms/Kconfig
+++ b/arch/powerpc/platforms/Kconfig
@@ -333,4 +333,11 @@ config MCU_MPC8349EMITX
 	  also register MCU GPIOs with the generic GPIO API, so you'll able
 	  to use MCU pins as GPIOs.
 
+config OF_MMAP_CACHE_PROPERTY
+	bool "Support setting cache property of mmap through device tree"
+	default n
+	help
+	  Say Y here to support setting cache property of mmaped region via
+	  mmap-region device tree node.
+
 endmenu
-- 
1.6.4

^ permalink raw reply related

* Re: [RFC PATCH v3 2/3] powerpc: udbg: add fixmap entry for early debug
From: Benjamin Herrenschmidt @ 2009-12-01 10:51 UTC (permalink / raw)
  To: Albert Herranz; +Cc: linuxppc-dev
In-Reply-To: <0a6994b5a257def375c8114b132d044a7f416d11.1259609263.git.albert_herranz@yahoo.es>

On Tue, 2009-12-01 at 00:09 +0100, Albert Herranz wrote:
> Add a new entry to the fixmap table to allow low level early udbg drivers
> to safely reserve virtual address space and create their I/O mappings.
> 
> Signed-off-by: Albert Herranz <albert_herranz@yahoo.es>
> ---
>  arch/powerpc/include/asm/fixmap.h |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/fixmap.h b/arch/powerpc/include/asm/fixmap.h
> index f1f4e23..424e5a6 100644
> --- a/arch/powerpc/include/asm/fixmap.h
> +++ b/arch/powerpc/include/asm/fixmap.h
> @@ -48,6 +48,9 @@ enum fixed_addresses {
>  	FIX_KMAP_BEGIN,	/* reserved pte's for temporary kernel mappings */
>  	FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
>  #endif
> +#ifdef CONFIG_PPC_EARLY_DEBUG
> +	FIX_EARLY_DEBUG_BASE,
> +#endif
>  	/* FIX_PCIE_MCFG, */
>  	__end_of_fixed_addresses
>  };

Rather than a hook to hop between the BAT and the later single page
mapping, I would have just used the fixmap as a way to reserve virtual
space for the BAT and keep it around.

However, that does mean having more than one entry in the fixmap, in
fact, enough to cope with the BAT min size +/- alignment. Maybe to avoid
the alignment problem, an option would be to always use the top of the
fixmap for the "debug area" and make it always something nice and fat to
fit a BAT, like 128K or whatever is the min size. No need for CONFIG_*
there even, I won't cry for 128K of virtual space reserved there instead
of just one page currently. And we could have good use of it for other
early debug stuff even.

Cheers,
Ben.

^ permalink raw reply

* Re: [PATCH 5/5] libata/drivers: Add pata_macio, driver Apple PowerMac/PowerBook IDE controller
From: Benjamin Herrenschmidt @ 2009-12-01 10:53 UTC (permalink / raw)
  To: Mikael Pettersson; +Cc: tj, linux-ide, linuxppc-dev, jeff
In-Reply-To: <19220.62569.492975.964154@pilspetsen.it.uu.se>

On Tue, 2009-12-01 at 11:48 +0100, Mikael Pettersson wrote:
> Thanks for reviving pata_macio.
> 
> Does the new version work with yaboot? (the previous one didn't)

Well, yaboot itself should have no problem. However, the ybin script
that automagically finds the right OF path might indeed still be busted,
it will have to be updated I'm afraid as it's more/less hard coded to
know about IDE gunk

I'll have a look. The new yaboot maintainer (Tony Breeds) happens to sit
2 cubicles away from me at work so it shouldn't be a huge deal.

Thanks for reminding me tho !

Cheers,
Ben.

^ permalink raw reply

* Re: [PATCH] powerpc/mm: setting mmaped page cache property through device tree
From: Benjamin Herrenschmidt @ 2009-12-01 10:58 UTC (permalink / raw)
  To: Li Yang; +Cc: linuxppc-dev, paulus, linux-kernel
In-Reply-To: <1259663450-28790-1-git-send-email-leoli@freescale.com>

On Tue, 2009-12-01 at 18:30 +0800, Li Yang wrote:
> The patch adds the ability for powerpc architecture to set page cache
> property of mmaped area through device tree.  This is useful for two
> cases.  First, for memory shared with other OS'es to have the same cache
> property to avoid cache paradoxes.  Second, enabling application to map
> memory which is not managed by kernel as cacheable for better performance.

But that doesn't solve the problem of those same pages being mapped
cachable as part of the linear mapping does it ?

Can you tell us more about your precise usage scenario ? What are you
trying to achieve here ? We can find a solution though it might involve
a specific driver to handle that memory.

Cheers,
Ben.

> Signed-off-by: Li Yang <leoli@freescale.com>
> ---
> Although it will be better if we can come up with a generic solution
> not only for powerpc arch.  Changing the behavior of O_SYNC seems to
> draw concerns over compatibility of old applications.  Suggestions
> are welcomed.
> 
>  arch/powerpc/mm/mem.c          |   49 +++++++++++++++++++++++++++++++++++++--
>  arch/powerpc/platforms/Kconfig |    7 +++++
>  2 files changed, 53 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
> index 579382c..02da2c8 100644
> --- a/arch/powerpc/mm/mem.c
> +++ b/arch/powerpc/mm/mem.c
> @@ -95,16 +95,59 @@ int page_is_ram(unsigned long pfn)
>  #endif
>  }
>  
> +#ifdef CONFIG_OF_MMAP_CACHE_PROPERTY
> +pgprot_t pgprot_from_dt(unsigned long pfn, pgprot_t vma_prot)
> +{
> +	struct device_node *np;
> +	struct resource res;
> +	unsigned long paddr = (pfn << PAGE_SHIFT);
> +	int i;
> +	const int *prop;
> +
> +	for_each_node_by_name(np, "mmap-region")
> +		for (i = 0; of_address_to_resource(np, i, &res) == 0; i++)
> +			if ((paddr >= res.start) && (paddr <= res.end)) {
> +				unsigned long _prot;
> +				prop = of_get_property(np, "cache-property",
> +						NULL);
> +
> +				if (prop == NULL)
> +					return vma_prot;
> +
> +				_prot = pgprot_val(vma_prot) & ~_PAGE_CACHE_CTL;
> +
> +				/* bit map of WIMG */
> +				if (*prop & 0x8)
> +					_prot |= _PAGE_WRITETHRU;
> +				if (*prop & 0x4)
> +					_prot |= _PAGE_NO_CACHE;
> +				if (*prop & 0x2)
> +					_prot |= _PAGE_COHERENT;
> +				if (*prop & 0x1)
> +					_prot |= _PAGE_GUARDED;
> +
> +				return __pgprot(_prot);
> +			}
> +
> +	return vma_prot;
> +}
> +#endif
> +
>  pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
>  			      unsigned long size, pgprot_t vma_prot)
>  {
>  	if (ppc_md.phys_mem_access_prot)
>  		return ppc_md.phys_mem_access_prot(file, pfn, size, vma_prot);
>  
> -	if (!page_is_ram(pfn))
> -		vma_prot = pgprot_noncached(vma_prot);
> +	/* kernel managed memory is always mapped as cacheable */
> +	if (page_is_ram(pfn))
> +		return vma_prot;
>  
> -	return vma_prot;
> +#ifdef CONFIG_OF_MMAP_CACHE_PROPERTY
> +	return pgprot_from_dt(pfn, vma_prot);
> +#else
> +	return pgprot_noncached(vma_prot);
> +#endif
>  }
>  EXPORT_SYMBOL(phys_mem_access_prot);
>  
> diff --git a/arch/powerpc/platforms/Kconfig b/arch/powerpc/platforms/Kconfig
> index 12bc2ce..de0f57c 100644
> --- a/arch/powerpc/platforms/Kconfig
> +++ b/arch/powerpc/platforms/Kconfig
> @@ -333,4 +333,11 @@ config MCU_MPC8349EMITX
>  	  also register MCU GPIOs with the generic GPIO API, so you'll able
>  	  to use MCU pins as GPIOs.
>  
> +config OF_MMAP_CACHE_PROPERTY
> +	bool "Support setting cache property of mmap through device tree"
> +	default n
> +	help
> +	  Say Y here to support setting cache property of mmaped region via
> +	  mmap-region device tree node.
> +
>  endmenu

^ permalink raw reply

* Re: [PATCH 5/5] libata/drivers: Add pata_macio, driver Apple PowerMac/PowerBook IDE controller
From: Mikael Pettersson @ 2009-12-01 10:48 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: tj, linux-ide, linuxppc-dev, jeff
In-Reply-To: <20091201070834.6A840B7B63@ozlabs.org>

Benjamin Herrenschmidt writes:
 > This is a libata driver for the "macio" IDE controller used on most Apple
 > PowerMac and PowerBooks. It's a libata equivalent of drivers/ide/ppc/pmac.c
 > 
 > It supports all the features of its predecessor, including mediabay hotplug
 > and suspend/resume. It should also support module load/unload.
 > 
 > The timing calculations have been simplified to use pre-calculated tables
 > compared to drivers/ide/pmac.c and it uses the new mediabay interface
 > provided by a previous patch.
 > 
 > Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
 > ---
 > 
 > Only lightly tested so far, this is for review, NOT for merge.
 > 
 > I would like to merge it eventually via the powerpc tree since there's a
 > few dependent patches, though I would need the libata "fix" for
 > bmdma_stop to go in first, unless I carry it as well with appropriate
 > acks.
 > 
 > I have addressed some of the comments from the previous version (almost a
 > year ago I think). I have kept the single function for the PIO and DMA
 > timings due to the one bit overlap between the fields in the HW register
 > on the shasta chipset. It seems to work fine.

Thanks for reviving pata_macio.

Does the new version work with yaboot? (the previous one didn't)

/Mikael

^ permalink raw reply

* Re: [PATCH] powerpc/mm: setting mmaped page cache property through device tree
From: Li Yang @ 2009-12-01 11:34 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: linuxppc-dev, paulus, linux-kernel
In-Reply-To: <1259665127.2076.363.camel@pasglop>

On Tue, Dec 1, 2009 at 6:58 PM, Benjamin Herrenschmidt
<benh@kernel.crashing.org> wrote:
> On Tue, 2009-12-01 at 18:30 +0800, Li Yang wrote:
>> The patch adds the ability for powerpc architecture to set page cache
>> property of mmaped area through device tree. =C2=A0This is useful for tw=
o
>> cases. =C2=A0First, for memory shared with other OS'es to have the same =
cache
>> property to avoid cache paradoxes. =C2=A0Second, enabling application to=
 map
>> memory which is not managed by kernel as cacheable for better performanc=
e.
>
> But that doesn't solve the problem of those same pages being mapped
> cachable as part of the linear mapping does it ?

I think that it doesn't has this problem.  Only regions out of
lmb.memory are configurable through device tree.

>
> Can you tell us more about your precise usage scenario ? What are you

The scenario for the first case is that in a multicore system running
ASMP which means different OS runs on different cores.  They might
communicate through a shared memory region.  The region on every OS
need to be mapped with the same cache perperty to avoid cache paradox.

The scenario for the second case is to pre-allocate some memory to a
certain application or device (probably through mem=3DXXX kernel
parameter or limit through device tree).  The memory is not known to
kernel, but fully managed by the application/device.  We need being
able to map the region cachable for better performance.

> trying to achieve here ? We can find a solution though it might involve
> a specific driver to handle that memory.

Right, but what the user to kernel API should be used?  Is it ok to
use the O_SYNC flag as I previously proposed?

- Leo

^ permalink raw reply

* Re: [PATCH 5/5] libata/drivers: Add pata_macio, driver Apple PowerMac/PowerBook IDE controller
From: Holger Macht @ 2009-12-01 12:44 UTC (permalink / raw)
  To: Tejun Heo; +Cc: linuxppc-dev, Jeff Garzik, linux-ide
In-Reply-To: <4B14CD22.4020806@kernel.org>

On Tuesday 01 December 2009 09:00:34 Tejun Heo wrote:
> (cc'ing Holger Macht, please read the comment below pata_macio_mb_event())
> Hello,
> 
> On 12/01/2009 04:08 PM, Benjamin Herrenschmidt wrote:
> > This is a libata driver for the "macio" IDE controller used on most Apple
> > PowerMac and PowerBooks. It's a libata equivalent of drivers/ide/ppc/pmac.c
[...]
> > +#ifdef CONFIG_PMAC_MEDIABAY
> > +static void pata_macio_mb_event(struct macio_dev* mdev, int mb_state)
> > +{
> > +	struct ata_host *host = macio_get_drvdata(mdev);
> > +	struct ata_port *ap;
> > +	struct ata_eh_info *ehi;
> > +	struct ata_device *dev;
> > +	unsigned long flags;
> > +
> > +	if (!host)
> > +		return;
> > +	ap = host->ports[0];
> > +	spin_lock_irqsave(ap->lock, flags);
> > +	ehi = &ap->link.eh_info;
> > +	if (mb_state == MB_CD) {
> > +		ata_ehi_push_desc(ehi, "mediabay plug");
> > +		ata_ehi_hotplugged(ehi);
> > +		ata_port_freeze(ap);
> > +	} else {
> > +		ata_ehi_push_desc(ehi, "mediabay unplug");
> > +		ata_for_each_dev(dev, &ap->link, ALL)
> > +			dev->flags |= ATA_DFLAG_DETACH;
> > +		ata_port_schedule_eh(ap);
> 
> I think you'll need an ata_port_freeze() or abort() here because at
> this point the drive is already gone and all in-flight commands need
> to be failed right away.  Holger, do you remember why
> ata_acpi_detach_device() is using ata_port_schedule_eh() instead?  Was
> it because ata_port_freeze() might end up poking registers after
> hotunplug happened?  ISTR reports where accessing any register there
> causing the whole system to lock up but then why can't it use
> ata_port_abort() instead?

I do not remember any specific reason for using ata_port_schedule_eh(). I
guess it's just there because the previous implementation used
it. ata_port_freeze()/abort() might as well work properly. However, I
would hesitate to change the existing code, because verifying that
everything works contains quite some effort. There are so many different
use cases this code can be accessed with and it has to be verified with
all kind of different hardware to make sure we get no hard
freezes. Testing that freeze()/abort() in this new driver would be worth a
try, though. Next time I have setup my test environment again I can verify
that it also works in the general libata-acpi code.

Regards,
 Holger

^ permalink raw reply

* Re: [PATCH 5/5] libata/drivers: Add pata_macio, driver Apple PowerMac/PowerBook IDE controller
From: Tejun Heo @ 2009-12-01 12:48 UTC (permalink / raw)
  To: hmacht; +Cc: linuxppc-dev, Jeff Garzik, linux-ide
In-Reply-To: <200912011344.38656.hmacht@suse.de>

On 12/01/2009 09:44 PM, Holger Macht wrote:
> I do not remember any specific reason for using ata_port_schedule_eh(). I
> guess it's just there because the previous implementation used
> it. ata_port_freeze()/abort() might as well work properly. However, I
> would hesitate to change the existing code, because verifying that
> everything works contains quite some effort. There are so many different
> use cases this code can be accessed with and it has to be verified with
> all kind of different hardware to make sure we get no hard
> freezes. Testing that freeze()/abort() in this new driver would be worth a
> try, though. Next time I have setup my test environment again I can verify
> that it also works in the general libata-acpi code.

Yeap, agreed.  It was pretty painful get it right the last time
around, so changing it on a hunch would be a pretty bad idea.  If you
have a chance to try freeze or abort, please keep me posted.

Thanks.

-- 
tejun

^ permalink raw reply

* Re: [PATCH] powerpc/mm: setting mmaped page cache property through device tree
From: Segher Boessenkool @ 2009-12-01 14:35 UTC (permalink / raw)
  To: Li Yang; +Cc: paulus, linux-kernel, linuxppc-dev
In-Reply-To: <2a27d3730912010334q24bf0e06g84839aae131475ec@mail.gmail.com>

> The scenario for the first case is that in a multicore system running
> ASMP which means different OS runs on different cores.  They might
> communicate through a shared memory region.  The region on every OS
> need to be mapped with the same cache perperty to avoid cache paradox.

This isn't true.  In ASMP, you cannot usually do coherency between
the different CPUs at all.  Also, in most PowerPC implementations,
it is fine if one CPU maps a memory range as coherent while another
maps it as non-coherent; sure, you have to be careful or you will
read stale data, but things won't wedge.

> The scenario for the second case is to pre-allocate some memory to a
> certain application or device (probably through mem=XXX kernel
> parameter or limit through device tree).  The memory is not known to
> kernel, but fully managed by the application/device.  We need being
> able to map the region cachable for better performance.

So make the memory known to the kernel, just tell the kernel not to
use it.  If it's normal system RAM, just put it in the "memory" node
and do a memreserve on it (or do something in your platform code); if
it's some other memory, do a device driver for it, map it there.


Segher

^ permalink raw reply

* Re: [PATCH v3 3/3] powerpc/fsl: 85xx: add cache-sram support
From: Scott Wood @ 2009-12-01 17:04 UTC (permalink / raw)
  To: Mahajan Vivek-B08308; +Cc: Wood Scott-B07421, Gala Kumar-B11780, linuxppc-dev
In-Reply-To: <F2F605B667B24B489C904986E0D60A0801222492@zin33exm23.fsl.freescale.net>

Mahajan Vivek-B08308 wrote:
>> From: Wood Scott-B07421 
>> Sent: Friday, November 20, 2009 11:09 PM
>>> Cache-sram does not have any device tree entry since it is not a 
>>> hardware as such. Putting it under chosen can be another option.
>>> I think, Scott (cc'ed) was of the opinion that since 32b 
>> base address 
>>> support is missing; so there is no point in moving this 
>> address to the 
>>> command line and .config should be okay for now for it.
>> I don't know what you mean by "32b base address support is 
>> missing".  I have no objection to putting it on the command line.
> 
> It was a typo, it should be missing 36b address support. Since the
> kernel 
> did not run under different environment (i.e 32b / 36b base address); so
> it 
> was decided that .config may be okay for this.

The kernel *will* run with a 36-bit address map even if some of our 
drivers don't support it right at the moment -- so we should be planning 
for it.

-Scott

^ permalink raw reply

* Recommended functions for accessing internal registers
From: Fortini Matteo @ 2009-12-01 16:44 UTC (permalink / raw)
  To: linuxppc-dev@lists.ozlabs.org

I see that throughout the kernel source, internal PPC registers are 
accessed through [in|out]_be[32|16|8]() functions. However, they are 
translated into 3 inline assembly instructions, one of which is an 
isync, which has a huge performance hit.
I tried using readl_be() which seems to be the right function according 
to the Documentation/ dir, but it is translated directly to in_be32(), 
so no luck.

Is it really necessary to use all those instructions? I know I could use 
a (volatile u32 *) variable to avoid subsequent read/writes to be 
optimized out, but it seems to be a deprecated use.

Thank you in advance,
Matteo

^ permalink raw reply

* Re: [PATCH 0/8 userland!] systemtap: Add initial support for ppc32
From: Frank Ch. Eigler @ 2009-12-01 17:54 UTC (permalink / raw)
  To: avorontsov; +Cc: linuxppc-dev, systemtap
In-Reply-To: <20091127223251.GA17065@oksana.dev.rtsoft.ru>

Anton Vorontsov <avorontsov@ru.mvista.com> writes:

> Here are some patches that add systemtap support for ppc32 machines.
> [...]

Thanks, committed, with a little extra for ppc64 compatibility.

- FChE

^ permalink raw reply

* Re: [RFC PATCH v2 01/11] powerpc: gamecube/wii: usbgecko bootwrapper console support
From: Segher Boessenkool @ 2009-12-01 18:28 UTC (permalink / raw)
  To: Albert Herranz; +Cc: linuxppc-dev
In-Reply-To: <1259441037-15725-2-git-send-email-albert_herranz@yahoo.es>

> Add support for using the USB Gecko adapter as a bootwrapper  
> console on
> the Nintendo GameCube and Wii video game consoles.
> The USB Gecko is a 3rd party memory card interface adapter that  
> provides
> a EXI (External Interface) to USB serial converter.
>
> Signed-off-by: Albert Herranz <albert_herranz@yahoo.es>
Acked-by: Segher Boessenkool <segher@kernel.crashing.org>

> ---
> v1 -> v2
> - Probe dinamically for usbgecko. Suggestion by Segher Boessenkool.
> - Adapt to updated device tree.
>
>  arch/powerpc/boot/Makefile |    2 +-
>  arch/powerpc/boot/ugecon.c |  147 +++++++++++++++++++++++++++++++++ 
> +++++++++++
>  arch/powerpc/boot/ugecon.h |   24 +++++++
>  3 files changed, 172 insertions(+), 1 deletions(-)
>  create mode 100644 arch/powerpc/boot/ugecon.c
>  create mode 100644 arch/powerpc/boot/ugecon.h
>
> diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
> index 7bfc8ad..44bce21 100644
> --- a/arch/powerpc/boot/Makefile
> +++ b/arch/powerpc/boot/Makefile
> @@ -66,7 +66,7 @@ src-wlib := string.S crt0.S crtsavres.S stdio.c  
> main.c \
>  		gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \
>  		4xx.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c bamboo.c \
>  		cpm-serial.c stdlib.c mpc52xx-psc.c planetcore.c uartlite.c \
> -		fsl-soc.c mpc8xx.c pq2.c
> +		fsl-soc.c mpc8xx.c pq2.c ugecon.c
>  src-plat := of.c cuboot-52xx.c cuboot-824x.c cuboot-83xx.c  
> cuboot-85xx.c holly.c \
>  		cuboot-ebony.c cuboot-hotfoot.c treeboot-ebony.c prpmc2800.c \
>  		ps3-head.S ps3-hvcall.S ps3.c treeboot-bamboo.c cuboot-8xx.c \
> diff --git a/arch/powerpc/boot/ugecon.c b/arch/powerpc/boot/ugecon.c
> new file mode 100644
> index 0000000..50609ea
> --- /dev/null
> +++ b/arch/powerpc/boot/ugecon.c
> @@ -0,0 +1,147 @@
> +/*
> + * arch/powerpc/boot/ugecon.c
> + *
> + * USB Gecko bootwrapper console.
> + * Copyright (C) 2008-2009 The GameCube Linux Team
> + * Copyright (C) 2008,2009 Albert Herranz
> + *
> + * 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.
> + *
> + */
> +
> +#include <stddef.h>
> +#include "stdio.h"
> +#include "types.h"
> +#include "io.h"
> +#include "ops.h"
> +
> +
> +#define EXI_CLK_32MHZ           5
> +
> +#define EXI_CSR                 0x00
> +#define   EXI_CSR_CLKMASK       (0x7<<4)
> +#define     EXI_CSR_CLK_32MHZ   (EXI_CLK_32MHZ<<4)
> +#define   EXI_CSR_CSMASK        (0x7<<7)
> +#define     EXI_CSR_CS_0        (0x1<<7)  /* Chip Select 001 */
> +
> +#define EXI_CR                  0x0c
> +#define   EXI_CR_TSTART         (1<<0)
> +#define   EXI_CR_WRITE		(1<<2)
> +#define   EXI_CR_READ_WRITE     (2<<2)
> +#define   EXI_CR_TLEN(len)      (((len)-1)<<4)
> +
> +#define EXI_DATA                0x10
> +
> +
> +/* virtual address base for input/output, retrieved from device  
> tree */
> +static void *ug_io_base;
> +
> +
> +static u32 ug_io_transaction(u32 in)
> +{
> +	u32 *csr_reg = ug_io_base + EXI_CSR;
> +	u32 *data_reg = ug_io_base + EXI_DATA;
> +	u32 *cr_reg = ug_io_base + EXI_CR;
> +	u32 csr, data, cr;
> +
> +	/* select */
> +	csr = EXI_CSR_CLK_32MHZ | EXI_CSR_CS_0;
> +	out_be32(csr_reg, csr);
> +
> +	/* read/write */
> +	data = in;
> +	out_be32(data_reg, data);
> +	cr = EXI_CR_TLEN(2) | EXI_CR_READ_WRITE | EXI_CR_TSTART;
> +	out_be32(cr_reg, cr);
> +
> +	while (in_be32(cr_reg) & EXI_CR_TSTART)
> +		barrier();
> +
> +	/* deselect */
> +	out_be32(csr_reg, 0);
> +
> +	data = in_be32(data_reg);
> +	return data;
> +}
> +
> +static int ug_is_txfifo_ready(void)
> +{
> +	return ug_io_transaction(0xc0000000) & 0x04000000;
> +}
> +
> +static void ug_raw_putc(char ch)
> +{
> +	ug_io_transaction(0xb0000000 | (ch << 20));
> +}
> +
> +static void ug_putc(char ch)
> +{
> +	int count = 16;
> +
> +	if (!ug_io_base)
> +		return;
> +
> +	while (!ug_is_txfifo_ready() && count--)
> +		barrier();
> +	if (count)
> +		ug_raw_putc(ch);
> +}
> +
> +void ug_console_write(const char *buf, int len)
> +{
> +	char *b = (char *)buf;
> +
> +	while (len--) {
> +		if (*b == '\n')
> +			ug_putc('\r');
> +		ug_putc(*b++);
> +	}
> +}
> +
> +static int ug_is_adapter_present(void)
> +{
> +	if (!ug_io_base)
> +		return 0;
> +	return ug_io_transaction(0x90000000) == 0x04700000;
> +}
> +
> +static void *ug_grab_exi_io_base(void)
> +{
> +	u32 v;
> +	void *devp;
> +
> +	devp = find_node_by_compatible(NULL, "nintendo,flipper-exi");
> +	if (devp == NULL)
> +		goto err_out;
> +	if (getprop(devp, "virtual-reg", &v, sizeof(v)) != sizeof(v))
> +		goto err_out;
> +
> +	return (void *)v;
> +
> +err_out:
> +	return NULL;
> +}
> +
> +void *ug_probe(void)
> +{
> +	void *exi_io_base;
> +	int i;
> +
> +	exi_io_base = ug_grab_exi_io_base();
> +	if (!exi_io_base)
> +		return NULL;
> +
> +	/* look for a usbgecko on memcard slots A and B */
> +	for (i = 0; i < 2; i++) {
> +		ug_io_base = exi_io_base + 0x14 * i;
> +		if (ug_is_adapter_present())
> +			break;
> +	}
> +	if (i == 2)
> +		ug_io_base = NULL;
> +	return ug_io_base;
> +}
> +
> diff --git a/arch/powerpc/boot/ugecon.h b/arch/powerpc/boot/ugecon.h
> new file mode 100644
> index 0000000..4373753
> --- /dev/null
> +++ b/arch/powerpc/boot/ugecon.h
> @@ -0,0 +1,24 @@
> +/*
> + * arch/powerpc/boot/ugecon.h
> + *
> + * USB Gecko early bootwrapper console.
> + * Copyright (C) 2008-2009 The GameCube Linux Team
> + * Copyright (C) 2008,2009 Albert Herranz
> + *
> + * 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.
> + *
> + */
> +
> +#ifndef __UGECON_H
> +#define __UGECON_H
> +
> +extern void *ug_probe(void);
> +
> +extern void ug_putc(char ch);
> +extern void ug_console_write(const char *buf, int len);
> +
> +#endif /* __UGECON_H */
> +
> -- 
> 1.6.3.3
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply

* Re: [RFC PATCH v2 02/11] powerpc: gamecube: device tree
From: Segher Boessenkool @ 2009-12-01 18:29 UTC (permalink / raw)
  To: Albert Herranz; +Cc: linuxppc-dev
In-Reply-To: <1259441037-15725-3-git-send-email-albert_herranz@yahoo.es>

> Add a device tree source file for the Nintendo GameCube video game  
> console.
>
> Signed-off-by: Albert Herranz <albert_herranz@yahoo.es>
Acked-by: Segher Boessenkool <segher@kernel.crashing.org>

> ---
> v1 -> v2
> - Document new bindings in Documentation/powerpc/dts-bindings.
>   Suggestion by Grant Likely.
> - Use same form for model property and compatible properties on the  
> root
>   node.  Suggestion by Grant Likely.
> - Drop the model property in the soc node.  Suggestion by Grant  
> Likely.
> - Move interrupt-parent to the soc node instead of explicitly  
> adding it to
>   each child node.  Suggestion by Grant Likely.
> - Declare all available memory and deal with the fb area in the  
> platform
>   code. Suggestion by Segher Boessenkool.
> - Transform the "auxram" node into the "dsp" node, create an  
> "auxram" node
>   within the "dsp" node. Suggestion by Segher Boessenkool.
> - Rename the "soc" node to "flipper". Suggestion by Benjamin  
> Herrenschmidt.
> - Remove the usbgecko node from the device tree and autodetect it in
>   platform code. Suggestion by Segher Boessenkool.
> - Remove clock-frequency property from the soc node.
>   Suggestion by Segher Boessenkool.
> - Create a flipper-processor-interface node and place flipper-pic  
> into it.
>   Suggestion by Segher Boessenkool.
> - Remove #interrupt-cells from the flipper node.
>   Suggestion by Segher Boessenkool.
> - Massive cleanups. Suggestions by Segher Boessenkool.
>
>  .../powerpc/dts-bindings/nintendo/gamecube.txt     |  109 +++++++++ 
> ++++++++++
>  arch/powerpc/boot/dts/gamecube.dts                 |  114 +++++++++ 
> +++++++++++
>  2 files changed, 223 insertions(+), 0 deletions(-)
>  create mode 100644 Documentation/powerpc/dts-bindings/nintendo/ 
> gamecube.txt
>  create mode 100644 arch/powerpc/boot/dts/gamecube.dts
>
> diff --git a/Documentation/powerpc/dts-bindings/nintendo/ 
> gamecube.txt b/Documentation/powerpc/dts-bindings/nintendo/ 
> gamecube.txt
> new file mode 100644
> index 0000000..b558585
> --- /dev/null
> +++ b/Documentation/powerpc/dts-bindings/nintendo/gamecube.txt
> @@ -0,0 +1,109 @@
> +
> +Nintendo GameCube device tree
> +=============================
> +
> +1) The "flipper" node
> +
> +  This node represents the multi-function "Flipper" chip, which  
> packages
> +  many of the devices found in the Nintendo GameCube.
> +
> +  Required properties:
> +
> +   - compatible : Should be "nintendo,flipper"
> +
> +1.a) The Video Interface (VI) node
> +
> +  Represents the interface between the graphics processor and a  
> external
> +  video encoder.
> +
> +  Required properties:
> +
> +   - compatible : should be "nintendo,flipper-vi"
> +   - reg : should contain the VI registers location and length
> +   - interrupts : should contain the VI interrupt
> +
> +1.b) The Processor Interface (PI) node
> +
> +  Represents the data and control interface between the main  
> processor
> +  and graphics and audio processor.
> +
> +  Required properties:
> +
> +  - compatible : should be "nintendo,flipper-pi"
> +  - reg : should contain the PI registers location and length
> +
> +1.b.i) The "Flipper" interrupt controller node
> +
> +  Represents the interrupt controller within the "Flipper" chip.
> +  The node for the "Flipper" interrupt controller must be placed  
> under
> +  the PI node.
> +
> +  Required properties:
> +
> +  - compatible : should be "nintendo,flipper-pic"
> +
> +1.c) The Digital Signal Procesor (DSP) node
> +
> +  Represents the digital signal processor interface, designed to  
> offload
> +  audio related tasks.
> +
> +  Required properties:
> +
> +   - compatible : should be "nintendo,flipper-dsp"
> +   - reg : should contain the DSP registers location and length
> +   - interrupts : should contain the DSP interrupt
> +
> +1.c.i) The Auxiliary RAM (ARAM) node
> +
> +  Represents the non cpu-addressable ram designed mainly to store  
> audio
> +  related information.
> +  The ARAM node must be placed under the DSP node.
> +
> +  Required properties:
> +
> +   - compatible : should be "nintendo,flipper-aram"
> +   - reg : should contain the ARAM start (zero-based) and length
> +
> +1.d) The Disk Interface (DI) node
> +
> +  Represents the interface used to communicate with mass storage  
> devices.
> +
> +  Required properties:
> +
> +   - compatible : should be "nintendo,flipper-di"
> +   - reg : should contain the DI registers location and length
> +   - interrupts : should contain the DI interrupt
> +
> +1.e) The Audio Interface (AI) node
> +
> +  Represents the interface to the external 16-bit stereo digital- 
> to-analog
> +  converter.
> +
> +  Required properties:
> +
> +   - compatible : should be "nintendo,flipper-ai"
> +   - reg : should contain the AI registers location and length
> +   - interrupts : should contain the AI interrupt
> +
> +1.f) The Serial Interface (SI) node
> +
> +  Represents the interface to the four single bit serial interfaces.
> +  The SI is a proprietary serial interface used normally to  
> control gamepads.
> +  It's NOT a RS232-type interface.
> +
> +  Required properties:
> +
> +   - compatible : should be "nintendo,flipper-si"
> +   - reg : should contain the SI registers location and length
> +   - interrupts : should contain the SI interrupt
> +
> +1.g) The External Interface (EXI) node
> +
> +  Represents the multi-channel SPI-like interface.
> +
> +  Required properties:
> +
> +   - compatible : should be "nintendo,flipper-exi"
> +   - reg : should contain the EXI registers location and length
> +   - interrupts : should contain the EXI interrupt
> +
> diff --git a/arch/powerpc/boot/dts/gamecube.dts b/arch/powerpc/boot/ 
> dts/gamecube.dts
> new file mode 100644
> index 0000000..ef3be0e
> --- /dev/null
> +++ b/arch/powerpc/boot/dts/gamecube.dts
> @@ -0,0 +1,114 @@
> +/*
> + * arch/powerpc/boot/dts/gamecube.dts
> + *
> + * Nintendo GameCube platform device tree source
> + * Copyright (C) 2007-2009 The GameCube Linux Team
> + * Copyright (C) 2007,2008,2009 Albert Herranz
> + *
> + * 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.
> + *
> + */
> +
> +/dts-v1/;
> +
> +/ {
> +	model = "nintendo,gamecube";
> +	compatible = "nintendo,gamecube";
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +
> +	chosen {
> +		bootargs = "root=/dev/gcnsda2 rootwait udbg-immortal";
> +	};
> +
> +	memory {
> +		device_type = "memory";
> +		reg = <0x00000000 0x01800000>;
> +	};
> +
> +	cpus {
> +		#address-cells = <1>;
> +		#size-cells = <0>;
> +
> +		PowerPC,gekko@0 {
> +			device_type = "cpu";
> +			reg = <0>;
> +			clock-frequency = <486000000>; /* 486MHz */
> +			bus-frequency = <162000000>; /* 162MHz core-to-bus 3x */
> +			timebase-frequency = <40500000>; /* 162MHz / 4 */
> +			i-cache-line-size = <32>;
> +			d-cache-line-size = <32>;
> +			i-cache-size = <32768>;
> +			d-cache-size = <32768>;
> +		};
> +	};
> +
> +	/* devices contained int the flipper chipset */
> +	flipper {
> +		#address-cells = <1>;
> +		#size-cells = <1>;
> +		compatible = "nintendo,flipper";
> +		ranges = <0x0c000000 0x0c000000 0x00010000>;
> +		interrupt-parent = <&PIC>;
> +
> +		video@0c002000 {
> +			compatible = "nintendo,flipper-vi";
> +			reg = <0x0c002000 0x100>;
> +			interrupts = <8>;
> +		};
> +
> +		processor-interface@0c003000 {
> +			compatible = "nintendo,flipper-pi";
> +			reg = <0x0c003000 0x100>;
> +
> +			PIC: pic {
> +				#interrupt-cells = <1>;
> +				compatible = "nintendo,flipper-pic";
> +				interrupt-controller;
> +			};
> +		};
> +
> +		dsp@0c005000 {
> +			#address-cells = <1>;
> +			#size-cells = <1>;
> +			compatible = "nintendo,flipper-dsp";
> +			reg = <0x0c005000 0x200>;
> +			interrupts = <6>;
> +
> +			memory@0 {
> +				compatible = "nintendo,flipper-aram";
> +				reg = <0 0x1000000>;	/* 16MB */
> +			};
> +		};
> +
> +		disk@0c006000 {
> +			compatible = "nintendo,flipper-di";
> +			reg = <0x0c006000 0x40>;
> +			interrupts = <2>;
> +		};
> +
> +		audio@0c006c00 {
> +			compatible = "nintendo,flipper-ai";
> +			reg = <0x0c006c00 0x20>;
> +			interrupts = <6>;
> +		};
> +
> +		gamepad-controller@0c006400 {
> +			compatible = "nintendo,flipper-si";
> +			reg = <0x0c006400 0x100>;
> +			interrupts = <3>;
> +		};
> +
> +		/* External Interface bus */
> +		exi@0c006800 {
> +			compatible = "nintendo,flipper-exi";
> +			reg = <0x0c006800 0x40>;
> +			virtual-reg = <0x0c006800>;
> +			interrupts = <4>;
> +		};
> +        };
> +};
> +
> -- 
> 1.6.3.3
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply

* Re: [RFC PATCH v2 03/11] powerpc: gamecube: bootwrapper bits
From: Segher Boessenkool @ 2009-12-01 18:31 UTC (permalink / raw)
  To: Albert Herranz; +Cc: linuxppc-dev
In-Reply-To: <1259441037-15725-4-git-send-email-albert_herranz@yahoo.es>

> Add support for the Nintendo GameCube video game console to the  
> powerpc
> bootwrapper.
>
> dtbImage.gamecube is a wrapped image that contains a flat device tree,
> an entry point compatible with SDload, and an optional initrd.
>
> Signed-off-by: Albert Herranz <albert_herranz@yahoo.es>
Acked-by: Segher Boessenkool <segher@kernel.crashing.org>

> ---
> v1 -> v2
> - Use a separate asm file for the entry point code.
>   Suggestion by Segher Boessenkool and Benjamin Herrenschmidt.
> - Do not make assumptions about the state of the cache and MMU on
>   entry, eliminating dependencies on a particular bootloader.
>   Suggestion by Segher Boessenkool.
> - Use consistently the same (easier to read) form of bcl to load the
>   next instruction address in LR. Suggestion by Segher Boessenkool.
> - Identity map I/O memory too to avoid confusions.
>   Suggestion by Segher Boessenkool.
> - Probe dinamically for usbgecko. Suggestion by Segher Boessenkool.
>
>  arch/powerpc/boot/Makefile        |    4 +-
>  arch/powerpc/boot/gamecube-head.S |  111 ++++++++++++++++++++++++++ 
> +++++++++++
>  arch/powerpc/boot/gamecube.c      |   35 ++++++++++++
>  arch/powerpc/boot/wrapper         |    4 +
>  4 files changed, 153 insertions(+), 1 deletions(-)
>  create mode 100644 arch/powerpc/boot/gamecube-head.S
>  create mode 100644 arch/powerpc/boot/gamecube.c
>
> diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
> index 44bce21..3e70aab 100644
> --- a/arch/powerpc/boot/Makefile
> +++ b/arch/powerpc/boot/Makefile
> @@ -76,7 +76,8 @@ src-plat := of.c cuboot-52xx.c cuboot-824x.c  
> cuboot-83xx.c cuboot-85xx.c holly.c
>  		cuboot-katmai.c cuboot-rainier.c redboot-8xx.c ep8248e.c \
>  		cuboot-warp.c cuboot-85xx-cpm2.c cuboot-yosemite.c simpleboot.c \
>  		virtex405-head.S virtex.c redboot-83xx.c cuboot-sam440ep.c \
> -		cuboot-acadia.c cuboot-amigaone.c cuboot-kilauea.c
> +		cuboot-acadia.c cuboot-amigaone.c cuboot-kilauea.c \
> +		gamecube-head.S gamecube.c
>  src-boot := $(src-wlib) $(src-plat) empty.c
>
>  src-boot := $(addprefix $(obj)/, $(src-boot))
> @@ -254,6 +255,7 @@ image-$(CONFIG_KSI8560)			+= cuImage.ksi8560
>  image-$(CONFIG_STORCENTER)		+= cuImage.storcenter
>  image-$(CONFIG_MPC7448HPC2)		+= cuImage.mpc7448hpc2
>  image-$(CONFIG_PPC_C2K)			+= cuImage.c2k
> +image-$(CONFIG_GAMECUBE)		+= dtbImage.gamecube
>
>  # Board port in arch/powerpc/platform/amigaone/Kconfig
>  image-$(CONFIG_AMIGAONE)		+= cuImage.amigaone
> diff --git a/arch/powerpc/boot/gamecube-head.S b/arch/powerpc/boot/ 
> gamecube-head.S
> new file mode 100644
> index 0000000..65a9b2a
> --- /dev/null
> +++ b/arch/powerpc/boot/gamecube-head.S
> @@ -0,0 +1,111 @@
> +/*
> + * arch/powerpc/boot/gamecube-head.S
> + *
> + * Nintendo GameCube bootwrapper entry.
> + * Copyright (C) 2004-2009 The GameCube Linux Team
> + * Copyright (C) 2008,2009 Albert Herranz
> + *
> + * 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.
> + *
> + */
> +
> +#include "ppc_asm.h"
> +
> +/*
> + * The entry code does no assumptions regarding:
> + * - if the data and instruction caches are enabled or not
> + * - if the MMU is enabled or not
> + *
> + * We enable the caches if not already enabled, enable the MMU  
> with an
> + * identity mapping scheme and jump to the start code.
> + */
> +
> +	.text
> +
> +	.globl _zimage_start
> +_zimage_start:
> +
> +	/* turn the MMU off */
> +	mfmsr	9
> +	rlwinm	9, 9, 0, ~((1<<4)|(1<<5)) /* MSR_DR|MSR_IR */
> +	bcl	20, 31, 1f
> +1:
> +	mflr	8
> +	clrlwi	8, 8, 3		/* convert to a real address */
> +	addi	8, 8, _mmu_off - 1b
> +	mtsrr0	8
> +	mtsrr1	9
> +	rfi
> +_mmu_off:
> +	/* MMU disabled */
> +
> +	/* setup BATs */
> +	isync
> +	li      8, 0
> +	mtspr	0x210, 8	/* IBAT0U */
> +	mtspr	0x212, 8	/* IBAT1U */
> +	mtspr	0x214, 8	/* IBAT2U */
> +	mtspr	0x216, 8	/* IBAT3U */
> +	mtspr	0x218, 8	/* DBAT0U */
> +	mtspr	0x21a, 8	/* DBAT1U */
> +	mtspr	0x21c, 8	/* DBAT2U */
> +	mtspr	0x21e, 8	/* DBAT3U */
> +
> +	li	8, 0x01ff	/* first 16MiB */
> +	li	9, 0x0002	/* rw */
> +	mtspr	0x211, 9	/* IBAT0L */
> +	mtspr	0x210, 8	/* IBAT0U */
> +	mtspr	0x219, 9	/* DBAT0L */
> +	mtspr	0x218, 8	/* DBAT0U */
> +
> +	lis	8, 0x0c00	/* I/O mem */
> +	ori	8, 8, 0x3ff	/* 32MiB */
> +	lis	9, 0x0c00
> +	ori	9, 9, 0x002a	/* uncached, guarded, rw */
> +	mtspr	0x21b, 9	/* DBAT1L */
> +	mtspr	0x21a, 8	/* DBAT1U */
> +
> +	lis	8, 0x0100	/* next 8MiB */
> +	ori	8, 8, 0x00ff	/* 8MiB */
> +	lis	9, 0x0100
> +	ori	9, 9, 0x0002	/* rw */
> +	mtspr	0x215, 9	/* IBAT2L */
> +	mtspr	0x214, 8	/* IBAT2U */
> +	mtspr	0x21d, 9	/* DBAT2L */
> +	mtspr	0x21c, 8	/* DBAT2U */
> +
> +	/* enable and invalidate the caches if not already enabled */
> +	mfspr	8, 0x3f0	/* HID0 */
> +	andi.	0, 8, (1<<15)		/* HID0_ICE */
> +	bne	1f
> +	ori	8, 8, (1<<15)|(1<<11)	/* HID0_ICE|HID0_ICFI*/
> +1:
> +	andi.	0, 8, (1<<14)		/* HID0_DCE */
> +	bne	1f
> +	ori	8, 8, (1<<14)|(1<<10)	/* HID0_DCE|HID0_DCFI*/
> +1:
> +	mtspr	0x3f0, 8	/* HID0 */
> +	isync
> +
> +	/* initialize arguments */
> +	li	3, 0
> +	li	4, 0
> +	li	5, 0
> +
> +	/* turn the MMU on */
> +	bcl	20, 31, 1f
> +1:
> +	mflr	8
> +	addi	8, 8, _mmu_on - 1b
> +	mfmsr	9
> +	ori	9, 9, (1<<4)|(1<<5) /* MSR_DR|MSR_IR */
> +	mtsrr0	8
> +	mtsrr1	9
> +	sync
> +	rfi
> +_mmu_on:
> +	b _zimage_start_lib
> +
> diff --git a/arch/powerpc/boot/gamecube.c b/arch/powerpc/boot/ 
> gamecube.c
> new file mode 100644
> index 0000000..28ae705
> --- /dev/null
> +++ b/arch/powerpc/boot/gamecube.c
> @@ -0,0 +1,35 @@
> +/*
> + * arch/powerpc/boot/gamecube.c
> + *
> + * Nintendo GameCube bootwrapper support
> + * Copyright (C) 2004-2009 The GameCube Linux Team
> + * Copyright (C) 2008,2009 Albert Herranz
> + *
> + * 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.
> + *
> + */
> +
> +#include <stddef.h>
> +#include "stdio.h"
> +#include "types.h"
> +#include "io.h"
> +#include "ops.h"
> +
> +#include "ugecon.h"
> +
> +BSS_STACK(8192);
> +
> +void platform_init(unsigned long r3, unsigned long r4, unsigned  
> long r5)
> +{
> +	u32 heapsize = 16*1024*1024 - (u32)_end;
> +
> +	simple_alloc_init(_end, heapsize, 32, 64);
> +	fdt_init(_dtb_start);
> +
> +	if (ug_probe())
> +		console_ops.write = ug_console_write;
> +}
> +
> diff --git a/arch/powerpc/boot/wrapper b/arch/powerpc/boot/wrapper
> index ac9e9a5..5b9206f 100755
> --- a/arch/powerpc/boot/wrapper
> +++ b/arch/powerpc/boot/wrapper
> @@ -230,6 +230,10 @@ xpedite52*)
>      link_address='0x1400000'
>      platformo=$object/cuboot-85xx.o
>      ;;
> +gamecube)
> +    link_address='0x600000'
> +    platformo="$object/$platform-head.o $object/$platform.o"
> +    ;;
>  esac
>
>  vmz="$tmpdir/`basename \"$kernel\"`.$ext"
> -- 
> 1.6.3.3
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply

* Re: [RFC PATCH v2 07/11] powerpc: gamecube/wii: udbg support for usbgecko
From: Segher Boessenkool @ 2009-12-01 18:33 UTC (permalink / raw)
  To: Albert Herranz; +Cc: linuxppc-dev
In-Reply-To: <1259441037-15725-8-git-send-email-albert_herranz@yahoo.es>

> Add support for using the USB Gecko adapter via the udbg facility on
> the Nintendo GameCube and Wii video game consoles.
> The USB Gecko is a 3rd party memory card interface adapter that  
> provides
> a EXI (External Interface) to USB serial converter.
>
> Signed-off-by: Albert Herranz <albert_herranz@yahoo.es>
Acked-by: Segher Boessenkool <segher@kernel.crashing.org>

> ---
> v1 -> v2
> - Get rid of 0-#ifdef'ed code. Suggestion by Segher Boessenkool.
> - Probe dinamically for usbgecko. Suggestion by Segher Boessenkool.
> - Adapt to updated device tree.
>
>  arch/powerpc/platforms/embedded6xx/Kconfig         |   13 +
>  arch/powerpc/platforms/embedded6xx/Makefile        |    1 +
>  arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c |  272 +++++++++ 
> +++++++++++
>  arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h |   30 +++
>  4 files changed, 316 insertions(+), 0 deletions(-)
>  create mode 100644 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
>  create mode 100644 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h
>
> diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig b/arch/ 
> powerpc/platforms/embedded6xx/Kconfig
> index 97a2dbc..464e414 100644
> --- a/arch/powerpc/platforms/embedded6xx/Kconfig
> +++ b/arch/powerpc/platforms/embedded6xx/Kconfig
> @@ -94,3 +94,16 @@ config MPC10X_STORE_GATHERING
>  config GAMECUBE_COMMON
>  	bool
>
> +config USBGECKO_UDBG
> +	bool "USB Gecko udbg console for the Nintendo GameCube/Wii"
> +	depends on GAMECUBE_COMMON
> +	help
> +	  If you say yes to this option, support will be included for the
> +	  USB Gecko adapter as an udbg console.
> +	  The USB Gecko is a EXI to USB Serial converter that can be plugged
> +	  into a memcard slot in the Nintendo GameCube/Wii.
> +
> +	  This driver bypasses the EXI layer completely.
> +
> +	  If in doubt, say N here.
> +
> diff --git a/arch/powerpc/platforms/embedded6xx/Makefile b/arch/ 
> powerpc/platforms/embedded6xx/Makefile
> index 0773c08..0ab7492 100644
> --- a/arch/powerpc/platforms/embedded6xx/Makefile
> +++ b/arch/powerpc/platforms/embedded6xx/Makefile
> @@ -7,3 +7,4 @@ obj-$(CONFIG_STORCENTER)	+= storcenter.o
>  obj-$(CONFIG_PPC_HOLLY)		+= holly.o
>  obj-$(CONFIG_PPC_PRPMC2800)	+= prpmc2800.o
>  obj-$(CONFIG_PPC_C2K)		+= c2k.o
> +obj-$(CONFIG_USBGECKO_UDBG)	+= usbgecko_udbg.o
> diff --git a/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c b/ 
> arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
> new file mode 100644
> index 0000000..581ce61
> --- /dev/null
> +++ b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
> @@ -0,0 +1,272 @@
> +/*
> + * arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
> + *
> + * udbg serial input/output routines for the USB Gecko adapter.
> + * Copyright (C) 2008-2009 The GameCube Linux Team
> + * Copyright (C) 2008,2009 Albert Herranz
> + *
> + * 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.
> + *
> + */
> +
> +#include <asm/io.h>
> +#include <asm/prom.h>
> +#include <asm/udbg.h>
> +
> +#include <mm/mmu_decl.h>
> +
> +#include "usbgecko_udbg.h"
> +
> +
> +#define EXI_CLK_32MHZ           5
> +
> +#define EXI_CSR                 0x00
> +#define   EXI_CSR_CLKMASK       (0x7<<4)
> +#define     EXI_CSR_CLK_32MHZ   (EXI_CLK_32MHZ<<4)
> +#define   EXI_CSR_CSMASK        (0x7<<7)
> +#define     EXI_CSR_CS_0        (0x1<<7)  /* Chip Select 001 */
> +
> +#define EXI_CR                  0x0c
> +#define   EXI_CR_TSTART         (1<<0)
> +#define   EXI_CR_WRITE		(1<<2)
> +#define   EXI_CR_READ_WRITE     (2<<2)
> +#define   EXI_CR_TLEN(len)      (((len)-1)<<4)
> +
> +#define EXI_DATA                0x10
> +
> +#define UG_READ_ATTEMPTS	100
> +#define UG_WRITE_ATTEMPTS	100
> +
> +
> +static void __iomem *ug_io_base;
> +
> +/*
> + * Performs one input/output transaction between the exi host and  
> the usbgecko.
> + */
> +static u32 ug_io_transaction(u32 in)
> +{
> +	u32 __iomem *csr_reg = ug_io_base + EXI_CSR;
> +	u32 __iomem *data_reg = ug_io_base + EXI_DATA;
> +	u32 __iomem *cr_reg = ug_io_base + EXI_CR;
> +	u32 csr, data, cr;
> +
> +	/* select */
> +	csr = EXI_CSR_CLK_32MHZ | EXI_CSR_CS_0;
> +	out_be32(csr_reg, csr);
> +
> +	/* read/write */
> +	data = in;
> +	out_be32(data_reg, data);
> +	cr = EXI_CR_TLEN(2) | EXI_CR_READ_WRITE | EXI_CR_TSTART;
> +	out_be32(cr_reg, cr);
> +
> +	while (in_be32(cr_reg) & EXI_CR_TSTART)
> +		barrier();
> +
> +	/* deselect */
> +	out_be32(csr_reg, 0);
> +
> +	/* result */
> +	data = in_be32(data_reg);
> +
> +	return data;
> +}
> +
> +/*
> + * Returns true if an usbgecko adapter is found.
> + */
> +static int ug_is_adapter_present(void)
> +{
> +	if (!ug_io_base)
> +		return 0;
> +
> +	return ug_io_transaction(0x90000000) == 0x04700000;
> +}
> +
> +/*
> + * Returns true if the TX fifo is ready for transmission.
> + */
> +static int ug_is_txfifo_ready(void)
> +{
> +	return ug_io_transaction(0xc0000000) & 0x04000000;
> +}
> +
> +/*
> + * Tries to transmit a character.
> + * If the TX fifo is not ready the result is undefined.
> + */
> +static void ug_raw_putc(char ch)
> +{
> +	ug_io_transaction(0xb0000000 | (ch << 20));
> +}
> +
> +/*
> + * Transmits a character.
> + * It silently fails if the TX fifo is not ready after a number of  
> retries.
> + */
> +static void ug_putc(char ch)
> +{
> +	int count = UG_WRITE_ATTEMPTS;
> +
> +	if (!ug_io_base)
> +		return;
> +
> +	if (ch == '\n')
> +		ug_putc('\r');
> +
> +	while (!ug_is_txfifo_ready() && count--)
> +		barrier();
> +	if (count)
> +		ug_raw_putc(ch);
> +}
> +
> +/*
> + * Returns true if the RX fifo is ready for transmission.
> + */
> +static int ug_is_rxfifo_ready(void)
> +{
> +	return ug_io_transaction(0xd0000000) & 0x04000000;
> +}
> +
> +/*
> + * Tries to receive a character.
> + * If a character is unavailable the function returns -1.
> + */
> +static int ug_raw_getc(void)
> +{
> +	u32 data = ug_io_transaction(0xa0000000);
> +	if (data & 0x08000000)
> +		return (data >> 16) & 0xff;
> +	else
> +		return -1;
> +}
> +
> +/*
> + * Receives a character.
> + * It fails if the RX fifo is not ready after a number of retries.
> + */
> +static int ug_getc(void)
> +{
> +	int count = UG_READ_ATTEMPTS;
> +
> +	if (!ug_io_base)
> +		return -1;
> +
> +	while (!ug_is_rxfifo_ready() && count--)
> +		barrier();
> +	return ug_raw_getc();
> +}
> +
> +/*
> + * udbg functions.
> + *
> + */
> +
> +/*
> + * Transmits a character.
> + */
> +void ug_udbg_putc(char ch)
> +{
> +	ug_putc(ch);
> +}
> +
> +/*
> + * Receives a character. Waits until a character is available.
> + */
> +static int ug_udbg_getc(void)
> +{
> +	int ch;
> +
> +	while ((ch = ug_getc()) == -1)
> +		barrier();
> +	return ch;
> +}
> +
> +/*
> + * Receives a character. If a character is not available, returns -1.
> + */
> +static int ug_udbg_getc_poll(void)
> +{
> +	if (!ug_is_rxfifo_ready())
> +		return -1;
> +	return ug_getc();
> +}
> +
> +/*
> + * Retrieves and prepares the virtual address needed to access the  
> hardware.
> + */
> +static void __iomem *ug_udbg_setup_exi_io_base(struct device_node  
> *np)
> +{
> +	void __iomem *exi_io_base = NULL;
> +	phys_addr_t paddr;
> +	const unsigned int *reg;
> +
> +	reg = of_get_property(np, "reg", NULL);
> +	if (reg) {
> +		paddr = of_translate_address(np, reg);
> +		if (paddr)
> +			exi_io_base = ioremap(paddr, reg[1]);
> +	}
> +	return exi_io_base;
> +}
> +
> +/*
> + * Checks if a USB Gecko adapter is inserted in any memory card slot.
> + */
> +static void __iomem *ug_udbg_probe(void __iomem *exi_io_base)
> +{
> +	int i;
> +
> +	/* look for a usbgecko on memcard slots A and B */
> +	for (i = 0; i < 2; i++) {
> +		ug_io_base = exi_io_base + 0x14 * i;
> +		if (ug_is_adapter_present())
> +			break;
> +	}
> +	if (i == 2)
> +		ug_io_base = NULL;
> +	return ug_io_base;
> +
> +}
> +
> +/*
> + * USB Gecko udbg support initialization.
> + */
> +void __init ug_udbg_init(void)
> +{
> +	struct device_node *np;
> +	void __iomem *exi_io_base;
> +
> +	if (ug_io_base)
> +		udbg_printf("%s: early -> final\n", __func__);
> +
> +	np = of_find_compatible_node(NULL, NULL, "nintendo,flipper-exi");
> +	if (!np) {
> +		udbg_printf("%s: EXI node not found\n", __func__);
> +		goto done;
> +	}
> +
> +	exi_io_base = ug_udbg_setup_exi_io_base(np);
> +	if (!exi_io_base) {
> +		udbg_printf("%s: failed to setup EXI io base\n", __func__);
> +		goto done;
> +	}
> +
> +	if (!ug_udbg_probe(exi_io_base)) {
> +		udbg_printf("usbgecko_udbg: not found\n");
> +		iounmap(exi_io_base);
> +	} else {
> +		udbg_putc = ug_udbg_putc;
> +		udbg_getc = ug_udbg_getc;
> +		udbg_getc_poll = ug_udbg_getc_poll;
> +		udbg_printf("usbgecko_udbg: ready\n");
> +	}
> +
> +done:
> +	if (np)
> +		of_node_put(np);
> +	return;
> +}
> diff --git a/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h b/ 
> arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h
> new file mode 100644
> index 0000000..3929de3
> --- /dev/null
> +++ b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h
> @@ -0,0 +1,30 @@
> +/*
> + * arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h
> + *
> + * udbg serial input/output routines for the USB Gecko adapter.
> + * Copyright (C) 2008-2009 The GameCube Linux Team
> + * Copyright (C) 2008,2009 Albert Herranz
> + *
> + * 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.
> + *
> + */
> +
> +#ifndef __USBGECKO_UDBG_H
> +#define __USBGECKO_UDBG_H
> +
> +#ifdef CONFIG_USBGECKO_UDBG
> +
> +extern void __init ug_udbg_init(void);
> +
> +#else
> +
> +static inline void __init ug_udbg_init(void)
> +{
> +}
> +
> +#endif /* CONFIG_USBGECKO_UDBG */
> +
> +#endif /* __USBGECKO_UDBG_H */
> -- 
> 1.6.3.3
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply

* Re: [RFC PATCH v2 09/11] powerpc: gamecube/wii: flipper interrupt controller support
From: Segher Boessenkool @ 2009-12-01 18:35 UTC (permalink / raw)
  To: Albert Herranz; +Cc: linuxppc-dev
In-Reply-To: <1259441037-15725-10-git-send-email-albert_herranz@yahoo.es>

> Add support for the interrupt controller included in the "Flipper"
> chipset of the Nintendo GameCube video game console.
> The same interrupt controller is also present in the "Hollywood"  
> chipset
> of the Nintendo Wii.
>
> Signed-off-by: Albert Herranz <albert_herranz@yahoo.es>
Acked-by: Segher Boessenkool <segher@kernel.crashing.org>

> ---
> v1 -> v2
> - Build always Flipper interrupt controller when GAMECUBE_COMMON and
>   get rid of FLIPPER_PIC option. Suggestion by Grant Likely.
> - Use NO_IRQ instead of -1. Suggestion by Benjamin Herrenschmidt.
> - Write 0xffffffff instead of ~0 to clear interrupts.
>   Suggestion by Segher Boessenkool.
> - Use __fls instead of open coded asm. Suggestion by Segher  
> Boessenkool.
> - Use a write instead of a read/modify/write to ack interrupts.
>   Suggestion by Segher Boessenkool and Benjamin Herrenschmidt.
> - Use name instead of typename for struct irq_chip.
> - Adapt to updated device tree.
>
>  arch/powerpc/platforms/embedded6xx/Makefile      |    1 +
>  arch/powerpc/platforms/embedded6xx/flipper-pic.c |  263 +++++++++++ 
> +++++++++++
>  arch/powerpc/platforms/embedded6xx/flipper-pic.h |   25 ++
>  3 files changed, 289 insertions(+), 0 deletions(-)
>  create mode 100644 arch/powerpc/platforms/embedded6xx/flipper-pic.c
>  create mode 100644 arch/powerpc/platforms/embedded6xx/flipper-pic.h
>
> diff --git a/arch/powerpc/platforms/embedded6xx/Makefile b/arch/ 
> powerpc/platforms/embedded6xx/Makefile
> index 0ab7492..b80f47c 100644
> --- a/arch/powerpc/platforms/embedded6xx/Makefile
> +++ b/arch/powerpc/platforms/embedded6xx/Makefile
> @@ -8,3 +8,4 @@ obj-$(CONFIG_PPC_HOLLY)		+= holly.o
>  obj-$(CONFIG_PPC_PRPMC2800)	+= prpmc2800.o
>  obj-$(CONFIG_PPC_C2K)		+= c2k.o
>  obj-$(CONFIG_USBGECKO_UDBG)	+= usbgecko_udbg.o
> +obj-$(CONFIG_GAMECUBE_COMMON)	+= flipper-pic.o
> diff --git a/arch/powerpc/platforms/embedded6xx/flipper-pic.c b/ 
> arch/powerpc/platforms/embedded6xx/flipper-pic.c
> new file mode 100644
> index 0000000..d596328
> --- /dev/null
> +++ b/arch/powerpc/platforms/embedded6xx/flipper-pic.c
> @@ -0,0 +1,263 @@
> +/*
> + * arch/powerpc/platforms/embedded6xx/flipper-pic.c
> + *
> + * Nintendo GameCube/Wii "Flipper" interrupt controller support.
> + * Copyright (C) 2004-2009 The GameCube Linux Team
> + * Copyright (C) 2007,2008,2009 Albert Herranz
> + *
> + * 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.
> + *
> + */
> +#define DRV_MODULE_NAME "flipper-pic"
> +#define pr_fmt(fmt) DRV_MODULE_NAME ": " fmt
> +
> +#include <linux/kernel.h>
> +#include <linux/init.h>
> +#include <linux/irq.h>
> +#include <linux/of.h>
> +#include <asm/io.h>
> +
> +#include "flipper-pic.h"
> +
> +#define FLIPPER_NR_IRQS		32
> +
> +/*
> + * Each interrupt has a corresponding bit in both
> + * the Interrupt Cause (ICR) and Interrupt Mask (IMR) registers.
> + *
> + * Enabling/disabling an interrupt line involves setting/clearing
> + * the corresponding bit in IMR.
> + * Except for the RSW interrupt, all interrupts get deasserted  
> automatically
> + * when the source deasserts the interrupt.
> + */
> +#define FLIPPER_ICR		0x00
> +#define FLIPPER_ICR_RSS		(1<<16) /* reset switch state */
> +
> +#define FLIPPER_IMR		0x04
> +
> +#define FLIPPER_RESET		0x24
> +
> +
> +/*
> + * IRQ chip hooks.
> + *
> + */
> +
> +static void flipper_pic_mask_and_ack(unsigned int virq)
> +{
> +	int irq = virq_to_hw(virq);
> +	void __iomem *io_base = get_irq_chip_data(virq);
> +	u32 mask = 1 << irq;
> +
> +	clrbits32(io_base + FLIPPER_IMR, mask);
> +	/* this is at least needed for RSW */
> +	out_be32(io_base + FLIPPER_ICR, mask);
> +}
> +
> +static void flipper_pic_ack(unsigned int virq)
> +{
> +	int irq = virq_to_hw(virq);
> +	void __iomem *io_base = get_irq_chip_data(virq);
> +
> +	/* this is at least needed for RSW */
> +	out_be32(io_base + FLIPPER_ICR, 1 << irq);
> +}
> +
> +static void flipper_pic_mask(unsigned int virq)
> +{
> +	int irq = virq_to_hw(virq);
> +	void __iomem *io_base = get_irq_chip_data(virq);
> +
> +	clrbits32(io_base + FLIPPER_IMR, 1 << irq);
> +}
> +
> +static void flipper_pic_unmask(unsigned int virq)
> +{
> +	int irq = virq_to_hw(virq);
> +	void __iomem *io_base = get_irq_chip_data(virq);
> +
> +	setbits32(io_base + FLIPPER_IMR, 1 << irq);
> +}
> +
> +
> +static struct irq_chip flipper_pic = {
> +	.name		= "flipper-pic",
> +	.ack		= flipper_pic_ack,
> +	.mask_ack	= flipper_pic_mask_and_ack,
> +	.mask		= flipper_pic_mask,
> +	.unmask		= flipper_pic_unmask,
> +};
> +
> +/*
> + * IRQ host hooks.
> + *
> + */
> +
> +static struct irq_host *flipper_irq_host;
> +
> +static int flipper_pic_map(struct irq_host *h, unsigned int virq,
> +			   irq_hw_number_t hwirq)
> +{
> +	set_irq_chip_data(virq, h->host_data);
> +	get_irq_desc(virq)->status |= IRQ_LEVEL;
> +	set_irq_chip_and_handler(virq, &flipper_pic, handle_level_irq);
> +	return 0;
> +}
> +
> +static void flipper_pic_unmap(struct irq_host *h, unsigned int irq)
> +{
> +	set_irq_chip_data(irq, NULL);
> +	set_irq_chip(irq, NULL);
> +}
> +
> +static int flipper_pic_match(struct irq_host *h, struct  
> device_node *np)
> +{
> +	return 1;
> +}
> +
> +
> +static struct irq_host_ops flipper_irq_host_ops = {
> +	.map = flipper_pic_map,
> +	.unmap = flipper_pic_unmap,
> +	.match = flipper_pic_match,
> +};
> +
> +/*
> + * Platform hooks.
> + *
> + */
> +
> +static void __flipper_quiesce(void __iomem *io_base)
> +{
> +	/* mask and ack all IRQs */
> +	out_be32(io_base + FLIPPER_IMR, 0x00000000);
> +	out_be32(io_base + FLIPPER_ICR, 0xffffffff);
> +}
> +
> +struct irq_host * __init flipper_pic_init(struct device_node *np)
> +{
> +	struct device_node *pi;
> +	struct irq_host *irq_host = NULL;
> +	struct resource res;
> +	void __iomem *io_base;
> +	int retval;
> +
> +	pi = of_get_parent(np);
> +	if (!pi) {
> +		pr_err("no parent found\n");
> +		goto out;
> +	}
> +	if (!of_device_is_compatible(pi, "nintendo,flipper-pi")) {
> +		pr_err("unexpected parent compatible\n");
> +		goto out;
> +	}
> +
> +	retval = of_address_to_resource(pi, 0, &res);
> +	if (retval) {
> +		pr_err("no io memory range found\n");
> +		goto out;
> +	}
> +	io_base = ioremap(res.start, resource_size(&res));
> +
> +	pr_info("controller at 0x%08x mapped to 0x%p\n", res.start,  
> io_base);
> +
> +	__flipper_quiesce(io_base);
> +
> +	irq_host = irq_alloc_host(np, IRQ_HOST_MAP_LINEAR, FLIPPER_NR_IRQS,
> +				  &flipper_irq_host_ops, -1);
> +	if (!irq_host) {
> +		pr_err("failed to allocate irq_host\n");
> +		return NULL;
> +	}
> +
> +	irq_host->host_data = io_base;
> +
> +out:
> +	return irq_host;
> +}
> +
> +unsigned int flipper_pic_get_irq(void)
> +{
> +	void __iomem *io_base = flipper_irq_host->host_data;
> +	int irq;
> +	u32 irq_status;
> +
> +	irq_status = in_be32(io_base + FLIPPER_ICR) &
> +		     in_be32(io_base + FLIPPER_IMR);
> +	if (irq_status == 0)
> +		return NO_IRQ;	/* no more IRQs pending */
> +
> +	irq = __ffs(irq_status);
> +	return irq_linear_revmap(flipper_irq_host, irq);
> +}
> +
> +/*
> + * Probe function.
> + *
> + */
> +
> +void __init flipper_pic_probe(void)
> +{
> +	struct device_node *np;
> +
> +	np = of_find_compatible_node(NULL, NULL, "nintendo,flipper-pic");
> +	BUG_ON(!np);
> +
> +	flipper_irq_host = flipper_pic_init(np);
> +	BUG_ON(!flipper_irq_host);
> +
> +	irq_set_default_host(flipper_irq_host);
> +
> +	of_node_put(np);
> +}
> +
> +/*
> + * Misc functions related to the flipper chipset.
> + *
> + */
> +
> +/**
> + * flipper_quiesce() - quiesce flipper irq controller
> + *
> + * Mask and ack all interrupt sources.
> + *
> + */
> +void flipper_quiesce(void)
> +{
> +	void __iomem *io_base = flipper_irq_host->host_data;
> +
> +	__flipper_quiesce(io_base);
> +}
> +
> +/*
> + * Resets the platform.
> + */
> +void flipper_platform_reset(void)
> +{
> +	void __iomem *io_base;
> +
> +	if (flipper_irq_host && flipper_irq_host->host_data) {
> +		io_base = flipper_irq_host->host_data;
> +		out_8(io_base + FLIPPER_RESET, 0x00);
> +	}
> +}
> +
> +/*
> + * Returns non-zero if the reset button is pressed.
> + */
> +int flipper_is_reset_button_pressed(void)
> +{
> +	void __iomem *io_base;
> +	u32 icr;
> +
> +	if (flipper_irq_host && flipper_irq_host->host_data) {
> +		io_base = flipper_irq_host->host_data;
> +		icr = in_be32(io_base + FLIPPER_ICR);
> +		return !(icr & FLIPPER_ICR_RSS);
> +	}
> +	return 0;
> +}
> +
> diff --git a/arch/powerpc/platforms/embedded6xx/flipper-pic.h b/ 
> arch/powerpc/platforms/embedded6xx/flipper-pic.h
> new file mode 100644
> index 0000000..e339186
> --- /dev/null
> +++ b/arch/powerpc/platforms/embedded6xx/flipper-pic.h
> @@ -0,0 +1,25 @@
> +/*
> + * arch/powerpc/platforms/embedded6xx/flipper-pic.h
> + *
> + * Nintendo GameCube/Wii "Flipper" interrupt controller support.
> + * Copyright (C) 2004-2009 The GameCube Linux Team
> + * Copyright (C) 2007,2008,2009 Albert Herranz
> + *
> + * 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.
> + *
> + */
> +
> +#ifndef __FLIPPER_PIC_H
> +#define __FLIPPER_PIC_H
> +
> +unsigned int flipper_pic_get_irq(void);
> +void __init flipper_pic_probe(void);
> +
> +void flipper_quiesce(void);
> +void flipper_platform_reset(void);
> +int flipper_is_reset_button_pressed(void);
> +
> +#endif
> -- 
> 1.6.3.3
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox