[PATCH] powerpc: fix register_power_pmu() section mismatch warning

2010-05-12 Thread Albert Herranz
Add missing __cpuinit annotations to fix a bunch of warnings like the one
shown below when building a kernel for the PowerPC architecture with
CONFIG_DEBUG_SECTION_MISMATCH=y.

WARNING: arch/powerpc/kernel/built-in.o(.text+0x11c72): Section mismatch in 
reference from the function register_power_pmu() to the variable 
.cpuinit.data:power_pmu_notifier_nb.23552
The function register_power_pmu() references
the variable __cpuinitdata power_pmu_notifier_nb.23552.
This is often because register_power_pmu lacks a __cpuinitdata
annotation or the annotation of power_pmu_notifier_nb.23552 is wrong.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/kernel/mpc7450-pmu.c |2 +-
 arch/powerpc/kernel/perf_event.c  |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/mpc7450-pmu.c 
b/arch/powerpc/kernel/mpc7450-pmu.c
index 09d7202..3982bfa 100644
--- a/arch/powerpc/kernel/mpc7450-pmu.c
+++ b/arch/powerpc/kernel/mpc7450-pmu.c
@@ -405,7 +405,7 @@ struct power_pmu mpc7450_pmu = {
.cache_events   = mpc7450_cache_events,
 };
 
-static int init_mpc7450_pmu(void)
+static int __cpuinit init_mpc7450_pmu(void)
 {
if (!cur_cpu_spec-oprofile_cpu_type ||
strcmp(cur_cpu_spec-oprofile_cpu_type, ppc/7450))
diff --git a/arch/powerpc/kernel/perf_event.c b/arch/powerpc/kernel/perf_event.c
index 08460a2..6b70834 100644
--- a/arch/powerpc/kernel/perf_event.c
+++ b/arch/powerpc/kernel/perf_event.c
@@ -1314,7 +1314,7 @@ power_pmu_notifier(struct notifier_block *self, unsigned 
long action, void *hcpu
return NOTIFY_OK;
 }
 
-int register_power_pmu(struct power_pmu *pmu)
+int __cpuinit register_power_pmu(struct power_pmu *pmu)
 {
if (ppmu)
return -EBUSY;  /* something's already registered */
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v5 01/10] swiotbl: add back swiotlb_alloc_boot()

2010-03-19 Thread Albert Herranz
This patch makes swiotlb_alloc_boot() available again.

This weak function can be overloaded to modify slightly how the SWIOTLB
and the overflow areas are allocated during boot.

This will be used later to support the Nintendo Wii video game console,
which requires placing the SWIOTLB area above 0x1000 (MEM2).

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 include/linux/swiotlb.h |1 +
 lib/swiotlb.c   |   10 --
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 8550d6b..c769939 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -54,6 +54,7 @@ extern void swiotlb_bounce(phys_addr_t phys, char *dma_addr, 
size_t size,
   enum dma_data_direction dir);
 extern void swiotlb_full(struct device *dev, size_t size, int dir, int 
do_panic);
 
+extern void __init *swiotlb_alloc_boot(size_t bytes, unsigned long nslabs);
 #endif
 
 /* swiotlb.c: dma_ops functions. */
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index c6bfa5d..ab1622a 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -136,6 +136,11 @@ void swiotlb_print_info(void)
   (unsigned long long)pend);
 }
 
+void * __weak __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)
+{
+   return alloc_bootmem_low_pages(size);
+}
+
 /*
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
@@ -155,7 +160,7 @@ swiotlb_init_with_default_size(size_t default_size, int 
verbose)
/*
 * Get IO TLB memory from the low pages
 */
-   swiotlb_bk_start = alloc_bootmem_low_pages(bytes);
+   swiotlb_bk_start = swiotlb_alloc_boot(bytes, swiotlb_bk_nslabs);
if (!swiotlb_bk_start)
panic(Cannot allocate SWIOTLB buffer);
swiotlb_bk_end = swiotlb_bk_start + bytes;
@@ -175,7 +180,8 @@ swiotlb_init_with_default_size(size_t default_size, int 
verbose)
/*
 * Get the overflow emergency buffer
 */
-   swiotlb_bk_overflow_buffer = alloc_bootmem_low(swiotlb_bk_overflow);
+   swiotlb_bk_overflow_buffer = swiotlb_alloc_boot(swiotlb_bk_overflow,
+   swiotlb_bk_nslabs);
if (!swiotlb_bk_overflow_buffer)
panic(Cannot allocate SWIOTLB overflow buffer!\n);
if (verbose)
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v5 02/10] swiotlb: make swiotlb_bounce() __weak

2010-03-19 Thread Albert Herranz
This patch converts swiotlb_bounce() into a weak function making it
overloadable by platform support code.

This will be used later to support the Nintendo Wii video game console,
which is a NOT_COHERENT_CACHE platform and requires explicit cache handling
when dealing with the swiotlb bounce buffers.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 lib/swiotlb.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index ab1622a..9ce5cd2 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -328,7 +328,7 @@ EXPORT_SYMBOL_GPL(is_swiotlb_buffer);
 /*
  * Bounce: copy the swiotlb buffer back to the original dma location
  */
-void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size,
+void __weak swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size,
   enum dma_data_direction dir)
 {
unsigned long pfn = PFN_DOWN(phys);
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v5 04/10] powerpc: add min_direct_dma_addr

2010-03-19 Thread Albert Herranz
This patch adds min_direct_dma_addr to struct dev_archdata.

min_direct_dma_addr can be used to define which is the minimum address
suitable for a DMA operation.
dma_capable() is updated to use this information in the SWIOTLB case.

This will be used later to support the Nintendo Wii video game console
which has limitations performing DMA to memory below 0x1000 (MEM1).

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/include/asm/device.h  |1 +
 arch/powerpc/include/asm/dma-mapping.h |2 ++
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/device.h 
b/arch/powerpc/include/asm/device.h
index 6d94d27..23f0009 100644
--- a/arch/powerpc/include/asm/device.h
+++ b/arch/powerpc/include/asm/device.h
@@ -27,6 +27,7 @@ struct dev_archdata {
 
 #ifdef CONFIG_SWIOTLB
dma_addr_t  max_direct_dma_addr;
+   dma_addr_t  min_direct_dma_addr;
 #endif
 };
 
diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index 18ecec8..eda3ebe 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -193,6 +193,8 @@ static inline bool dma_capable(struct device *dev, 
dma_addr_t addr, size_t size)
 
if (sd-max_direct_dma_addr  addr + size  sd-max_direct_dma_addr)
return 0;
+   if (sd-min_direct_dma_addr  addr  sd-min_direct_dma_addr)
+   return 0;
 #endif
 
if (!dev-dma_mask)
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v5 05/10] USB: refactor unmap_urb_for_dma/map_urb_for_dma

2010-03-19 Thread Albert Herranz
Split unmap_urb_for_dma() and map_urb_for_dma() into smaller pieces
to make the code easier to read and maintain.

This patch adds four new URB flags which are used by map_urb_for_dma()
to mark URBs with the exact method used to map the setup packet and/or the
transfer buffer.
These flags are checked too at unmap_urb_for_dma() time to determine how
to unmap the setup packet and/or the transfer buffer. The flags are cleared
when the actual unmap happens.

No functional change.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 drivers/usb/core/hcd.c |  211 +++-
 include/linux/usb.h|5 +
 2 files changed, 143 insertions(+), 73 deletions(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 80995ef..44ad710 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1260,106 +1260,171 @@ static void hcd_free_coherent(struct usb_bus *bus, 
dma_addr_t *dma_handle,
*dma_handle = 0;
 }
 
-static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
-  gfp_t mem_flags)
+static void unmap_urb_setup_packet(struct usb_hcd *hcd, struct urb *urb)
+{
+   if (urb-transfer_flags  URB_SETUP_DMA_MAPPED) {
+   urb-transfer_flags = ~URB_SETUP_DMA_MAPPED;
+   dma_unmap_single(hcd-self.controller, urb-setup_dma,
+sizeof(struct usb_ctrlrequest),
+DMA_TO_DEVICE);
+   } else if (urb-transfer_flags  URB_SETUP_BOUNCE_MAPPED) {
+   /* bounce from local memory */
+   urb-transfer_flags = ~URB_SETUP_BOUNCE_MAPPED;
+   hcd_free_coherent(urb-dev-bus, urb-setup_dma,
+ (void **)urb-setup_packet,
+ sizeof(struct usb_ctrlrequest),
+ DMA_TO_DEVICE);
+   } else {
+   /* nothing to do for PIO-based controller requests */
+   }
+}
+
+static void unmap_urb_transfer_buffer(struct usb_hcd *hcd, struct urb *urb)
 {
enum dma_data_direction dir;
-   int ret = 0;
 
-   /* Map the URB's buffers for DMA access.
-* Lower level HCD code should use *_dma exclusively,
-* unless it uses pio or talks to another transport,
-* or uses the provided scatter gather list for bulk.
-*/
+   dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+   if (urb-transfer_flags  URB_TRANSFER_DMA_MAPPED) {
+   urb-transfer_flags = ~URB_TRANSFER_DMA_MAPPED;
+   dma_unmap_single(hcd-self.controller,
+urb-transfer_dma,
+urb-transfer_buffer_length,
+dir);
+   } else if (urb-transfer_flags  URB_TRANSFER_BOUNCE_MAPPED) {
+   /* bounce from local memory */
+   urb-transfer_flags = ~URB_TRANSFER_BOUNCE_MAPPED;
+   hcd_free_coherent(urb-dev-bus, urb-transfer_dma,
+ urb-transfer_buffer,
+ urb-transfer_buffer_length,
+ dir);
+   } else {
+   /* nothing to do for PIO-based controller requests */
+   }
+}
+
+static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
+{
if (is_root_hub(urb-dev))
+   return;
+
+   unmap_urb_setup_packet(hcd, urb);
+   unmap_urb_transfer_buffer(hcd, urb);
+}
+
+static int urb_needs_setup_map(struct usb_hcd *hcd, struct urb *urb)
+{
+   /* setup mappings are required only for control requests */
+   if (!usb_endpoint_xfer_control(urb-ep-desc))
+   return 0;
+
+   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
+   if ((urb-transfer_flags  URB_NO_SETUP_DMA_MAP))
+   return 0;
+
+   return 1;
+}
+
+static int urb_needs_transfer_map(struct usb_hcd *hcd, struct urb *urb)
+{
+   /* don't need to map anything if there's nothing to map */
+   if (urb-transfer_buffer_length == 0)
return 0;
 
-   if (usb_endpoint_xfer_control(urb-ep-desc)
-!(urb-transfer_flags  URB_NO_SETUP_DMA_MAP)) {
+   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
+   if ((urb-transfer_flags  URB_NO_TRANSFER_DMA_MAP))
+   return 0;
+
+   return 1;
+}
+
+static int map_urb_setup_packet(struct usb_hcd *hcd, struct urb *urb,
+   gfp_t mem_flags)
+{
+   int ret;
+
+   if (urb_needs_setup_map(hcd, urb)) {
if (hcd-self.uses_dma) {
urb-setup_dma = dma_map_single(
-   hcd-self.controller,
-   urb-setup_packet,
-   sizeof(struct usb_ctrlrequest),
-   DMA_TO_DEVICE

[PATCH v5 06/10] USB: add HCD_NO_COHERENT_MEM host controller driver flag

2010-03-19 Thread Albert Herranz
The HCD_NO_COHERENT_MEM USB host controller driver flag can be enabled
to instruct the USB stack to avoid allocating coherent memory for USB
buffers.

This flag is useful to overcome some esoteric memory access restrictions
found in some platforms.
For example, the Nintendo Wii video game console is a NOT_COHERENT_CACHE
platform that is unable to safely perform non-32 bit uncached writes
to RAM because the byte enables are not connected to the bus.
Thus, in that platform, coherent DMA buffers cannot be directly used
by the kernel code unless it guarantees that all write accesses
to said buffers are done in 32 bit chunks (which is not the case in the
USB subsystem).

To avoid this unwanted behaviour HCD_NO_COHERENT_MEM can be enabled at
the HCD controller, causing USB buffer allocations to be satisfied from
normal kernel memory. In this case, the USB stack will make sure that
the buffers get properly mapped/unmapped for DMA transfers using the DMA
streaming mapping API.

Note that other parts of the USB stack may also use coherent memory,
like for example the hardware descriptors used in the EHCI controllers.
This needs to be checked and addressed separately. In the EHCI example,
hardware descriptors are accessed in 32-bit (or 64-bit) chunks, causing
no problems in the described scenario.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 drivers/usb/core/buffer.c |   29 +++--
 drivers/usb/core/hcd.c|   32 +++-
 drivers/usb/core/hcd.h|   13 +++--
 3 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 3ba2fff..10cd11d 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -36,6 +36,26 @@ static const size_t  pool_max [HCD_BUFFER_POOLS] = {
 
 /* SETUP primitives */
 
+static inline int hcd_uses_pio(struct usb_hcd *hcd)
+{
+   if ((!hcd-self.controller-dma_mask 
+   !(hcd-driver-flags  HCD_LOCAL_MEM)))
+   return 1;
+   return 0;
+}
+
+static inline int hcd_needs_non_dma_mem(struct usb_hcd *hcd)
+{
+   /*
+* PIO-based and HCD_NO_COHERENT_MEM-based controllers use
+* normal kernel memory.
+* The rest want DMA memory.
+*/
+   if (hcd_uses_pio(hcd) || (hcd-driver-flags  HCD_NO_COHERENT_MEM))
+   return 1;
+   return 0;
+}
+
 /**
  * hcd_buffer_create - initialize buffer pools
  * @hcd: the bus whose buffer pools are to be initialized
@@ -53,8 +73,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
charname[16];
int i, size;
 
-   if (!hcd-self.controller-dma_mask 
-   !(hcd-driver-flags  HCD_LOCAL_MEM))
+   if (hcd_needs_non_dma_mem(hcd))
return 0;
 
for (i = 0; i  HCD_BUFFER_POOLS; i++) {
@@ -109,8 +128,7 @@ void *hcd_buffer_alloc(
int i;
 
/* some USB hosts just use PIO */
-   if (!bus-controller-dma_mask 
-   !(hcd-driver-flags  HCD_LOCAL_MEM)) {
+   if (hcd_needs_non_dma_mem(hcd)) {
*dma = ~(dma_addr_t) 0;
return kmalloc(size, mem_flags);
}
@@ -135,8 +153,7 @@ void hcd_buffer_free(
if (!addr)
return;
 
-   if (!bus-controller-dma_mask 
-   !(hcd-driver-flags  HCD_LOCAL_MEM)) {
+   if (hcd_needs_non_dma_mem(hcd)) {
kfree(addr);
return;
}
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 44ad710..174853a 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1316,9 +1316,19 @@ static int urb_needs_setup_map(struct usb_hcd *hcd, 
struct urb *urb)
/* setup mappings are required only for control requests */
if (!usb_endpoint_xfer_control(urb-ep-desc))
return 0;
-
-   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
-   if ((urb-transfer_flags  URB_NO_SETUP_DMA_MAP))
+   /*
+* Setup packets are 8 bytes long and don't use scatter/gather.
+*
+* If the caller sets URB_NO_SETUP_DMA_MAP and urb-setup_dma
+* contains a valid DMA handle then it is already mapped, except
+* if the controller can't use coherent memory (HCD_NO_COHERENT_MEM).
+*
+* urb-setup_dma is set to ~0 when allocating USB buffers for
+* PIO-based or HCD_NO_COHERENT_MEM-based controllers.
+*/
+   if ((urb-transfer_flags  URB_NO_SETUP_DMA_MAP) 
+   urb-setup_dma != ~(dma_addr_t)0 
+   !(hcd-driver-flags  HCD_NO_COHERENT_MEM))
return 0;
 
return 1;
@@ -1330,8 +1340,20 @@ static int urb_needs_transfer_map(struct usb_hcd *hcd, 
struct urb *urb)
if (urb-transfer_buffer_length == 0)
return 0;
 
-   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
-   if ((urb-transfer_flags  URB_NO_TRANSFER_DMA_MAP

[PATCH v5 03/10] powerpc: add per-device dma coherent support

2010-03-19 Thread Albert Herranz
Use the generic per-device dma coherent allocator on powerpc.
This allows a driver to declare coherent memory area from where
a device can allocate coherent memory chunks.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/include/asm/dma-mapping.h |1 +
 arch/powerpc/kernel/dma.c  |5 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index 80a973b..18ecec8 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -17,6 +17,7 @@
 #include linux/dma-debug.h
 #include asm/io.h
 #include asm/swiotlb.h
+#include asm-generic/dma-coherent.h
 
 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
 
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 6215062..83d5232 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -27,6 +27,9 @@ void *dma_direct_alloc_coherent(struct device *dev, size_t 
size,
 {
void *ret;
 #ifdef CONFIG_NOT_COHERENT_CACHE
+   if (dma_alloc_from_coherent(dev, size, dma_handle, ret))
+   return ret;
+
ret = __dma_alloc_coherent(dev, size, dma_handle, flag);
if (ret == NULL)
return NULL;
@@ -54,6 +57,8 @@ void dma_direct_free_coherent(struct device *dev, size_t size,
  void *vaddr, dma_addr_t dma_handle)
 {
 #ifdef CONFIG_NOT_COHERENT_CACHE
+   if (dma_release_from_coherent(dev, get_order(size), vaddr))
+   return;
__dma_free_coherent(size, vaddr);
 #else
free_pages((unsigned long)vaddr, get_order(size));
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v5 07/10] wii: have generic dma coherent

2010-03-19 Thread Albert Herranz
Let the Nintendo Wii gaming console use per-device dma coherent allocations.
This will be used later by some of its drivers.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/Kconfig |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index 524d971..fe77ab2 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -119,6 +119,7 @@ config WII
bool Nintendo-Wii
depends on EMBEDDED6xx
select GAMECUBE_COMMON
+   select HAVE_GENERIC_DMA_COHERENT
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v5 00/10] wii: add usb 2.0 support

2010-03-19 Thread Albert Herranz
The following patch series adds USB 2.0 support for the Wii PowerPC
platform via the EHCI controller present in the Hollywood chipset
of the video game console.

v4 - v5
- Set the default IO TLB size via the kernel command line.
  This is now possible on PowerPC thanks to a recent patch by Fujita Tomonori.
- swiotlb support for the Wii is now based on top of the swiotlb-0.6
  patches from Konrad Rzeszutek Wilk.
- Keeps using v4 of the USB HCD_NO_COHERENT_MEM patch

Alan: I think you are also working in a patchset to make {un}map_urb_for_dma
remember how the urb was mapped, right?

Albert Herranz (10):
  swiotbl: add back swiotlb_alloc_boot()
  swiotlb: make swiotlb_bounce() __weak
  powerpc: add per-device dma coherent support
  powerpc: add min_direct_dma_addr
  USB: refactor unmap_urb_for_dma/map_urb_for_dma
  USB: add HCD_NO_COHERENT_MEM host controller driver flag
  wii: have generic dma coherent
  wii: add mem2 dma mapping ops
  wii: enable swiotlb
  wii: hollywood ehci controller support

 arch/powerpc/boot/dts/wii.dts|2 +-
 arch/powerpc/boot/wii.c  |   44 +++
 arch/powerpc/include/asm/device.h|1 +
 arch/powerpc/include/asm/dma-mapping.h   |3 +
 arch/powerpc/include/asm/wii.h   |   25 ++
 arch/powerpc/kernel/dma.c|5 +
 arch/powerpc/platforms/embedded6xx/Kconfig   |3 +
 arch/powerpc/platforms/embedded6xx/Makefile  |2 +-
 arch/powerpc/platforms/embedded6xx/wii-dma.c |  475 ++
 arch/powerpc/platforms/embedded6xx/wii.c |1 +
 drivers/usb/core/buffer.c|   29 ++-
 drivers/usb/core/hcd.c   |  233 +
 drivers/usb/core/hcd.h   |   13 +-
 drivers/usb/host/Kconfig |8 +
 drivers/usb/host/ehci-hcd.c  |5 +
 drivers/usb/host/ehci-hlwd.c |  233 +
 drivers/usb/host/ehci.h  |   23 ++
 include/linux/swiotlb.h  |1 +
 include/linux/usb.h  |5 +
 lib/swiotlb.c|   12 +-
 20 files changed, 1033 insertions(+), 90 deletions(-)
 create mode 100644 arch/powerpc/include/asm/wii.h
 create mode 100755 arch/powerpc/platforms/embedded6xx/wii-dma.c
 create mode 100644 drivers/usb/host/ehci-hlwd.c

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v5 08/10] wii: add mem2 dma mapping ops

2010-03-19 Thread Albert Herranz
Some of the devices in the Hollywood chipset of the Nintendo Wii video
game console have restrictions performing DMA transfers to the first
contiguous RAM region (known as MEM1).
For example, up to 3 bytes of the last word of a DMA transfer of a
non-32 bit aligned length to MEM1 may be lost.
Such restrictions do not apply when using the second contiguous RAM
region (known as MEM2).

Add a set of DMA mapping operations which said devices can use to make
sure that DMA transfers are always performed to/from memory buffers
within MEM2.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/boot/wii.c  |   44 +++
 arch/powerpc/include/asm/wii.h   |   25 ++
 arch/powerpc/platforms/embedded6xx/Kconfig   |1 +
 arch/powerpc/platforms/embedded6xx/Makefile  |2 +-
 arch/powerpc/platforms/embedded6xx/wii-dma.c |  475 ++
 5 files changed, 546 insertions(+), 1 deletions(-)
 create mode 100644 arch/powerpc/include/asm/wii.h
 create mode 100755 arch/powerpc/platforms/embedded6xx/wii-dma.c

diff --git a/arch/powerpc/boot/wii.c b/arch/powerpc/boot/wii.c
index 2ebaec0..84ce593 100644
--- a/arch/powerpc/boot/wii.c
+++ b/arch/powerpc/boot/wii.c
@@ -30,6 +30,7 @@ BSS_STACK(8192);
 #define MEM2_TOP   (0x1000 + 64*1024*1024)
 #define FIRMWARE_DEFAULT_SIZE  (12*1024*1024)
 
+#define MEM2_DMA_DEFAULT_SIZE  (512*1024)
 
 struct mipc_infohdr {
char magic[3];
@@ -101,6 +102,42 @@ out:
 
 }
 
+static char tmp_cmdline[COMMAND_LINE_SIZE];
+
+static void mem2_fixups(u32 *top, u32 *reg)
+{
+   /* ' mem2_dma=' + nnn + 'k...@0x' +  */
+   const int max_param_len = 10 + 7 + 4 + 8;
+   void *chosen;
+   u32 dma_base, dma_size;
+   char *p;
+
+   chosen = finddevice(/chosen);
+   if (!chosen)
+   fatal(Can't find chosen node\n);
+
+   /* the MEM2 DMA region must fit within MEM2 */
+   dma_size = MEM2_DMA_DEFAULT_SIZE;
+   if (dma_size  reg[3])
+   dma_size = reg[3];
+   /* reserve the region from the top of MEM2 */
+   *top -= dma_size;
+   dma_base = *top;
+   printf(mem2_dma: %...@0x%08x\n, dma_size  10, dma_base);
+
+   /*
+* Finally, add the MEM2 DMA region location information to the
+* kernel command line. The wii-dma driver will pick this info up.
+*/
+   getprop(chosen, bootargs, tmp_cmdline, COMMAND_LINE_SIZE-1);
+   p = strchr(tmp_cmdline, 0);
+   if (p - tmp_cmdline + max_param_len = COMMAND_LINE_SIZE)
+   fatal(No space left for mem2_dma param\n);
+
+   sprintf(p,  mem2_dma=...@0x%08x, dma_size  10, dma_base);
+   setprop_str(chosen, bootargs, tmp_cmdline);
+}
+
 static void platform_fixups(void)
 {
void *mem;
@@ -127,9 +164,16 @@ static void platform_fixups(void)
mem2_boundary = MEM2_TOP - FIRMWARE_DEFAULT_SIZE;
}
 
+   mem2_fixups(mem2_boundary, reg);
+
if (mem2_boundary  reg[2]  mem2_boundary  reg[2] + reg[3]) {
reg[3] = mem2_boundary - reg[2];
printf(top of MEM2 @ %08X\n, reg[2] + reg[3]);
+   /*
+* Find again the memory node as it may have changed its
+* position after adding some non-existing properties.
+*/
+   mem = finddevice(/memory);
setprop(mem, reg, reg, sizeof(reg));
}
 
diff --git a/arch/powerpc/include/asm/wii.h b/arch/powerpc/include/asm/wii.h
new file mode 100644
index 000..bb83c32
--- /dev/null
+++ b/arch/powerpc/include/asm/wii.h
@@ -0,0 +1,25 @@
+/*
+ * arch/powerpc/include/asm/wii.h
+ *
+ * Nintendo Wii board-specific definitions
+ * Copyright (C) 2010 The GameCube Linux Team
+ * Copyright (C) 2010 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 __ASM_POWERPC_WII_H
+#define __ASM_POWERPC_WII_H
+
+/*
+ * DMA operations for the Nintendo Wii.
+ */
+extern struct dma_map_ops wii_mem2_dma_ops;
+
+extern int wii_set_mem2_dma_constraints(struct device *dev);
+extern void wii_clear_mem2_dma_constraints(struct device *dev);
+
+#endif /* __ASM_POWERPC_WII_H */
diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index fe77ab2..f4fff0a 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -120,6 +120,7 @@ config WII
depends on EMBEDDED6xx
select GAMECUBE_COMMON
select HAVE_GENERIC_DMA_COHERENT
+   select SWIOTLB
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
diff --git a/arch/powerpc/platforms/embedded6xx/Makefile 
b/arch/powerpc/platforms

[PATCH v5 09/10] wii: enable swiotlb

2010-03-19 Thread Albert Herranz
Enable the use of a software IO TLB on the Nintendo Wii video game console.

This is used by the platform DMA support code to overcome the limitations
found in some of the devices within the Hollywood chipset.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/boot/dts/wii.dts|2 +-
 arch/powerpc/platforms/embedded6xx/wii.c |1 +
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/boot/dts/wii.dts b/arch/powerpc/boot/dts/wii.dts
index 77528c9..92b8ca6 100644
--- a/arch/powerpc/boot/dts/wii.dts
+++ b/arch/powerpc/boot/dts/wii.dts
@@ -29,7 +29,7 @@
#size-cells = 1;
 
chosen {
-   bootargs = root=/dev/mmcblk0p2 rootwait udbg-immortal;
+   bootargs = root=/dev/mmcblk0p2 swiotlb=512 rootwait 
udbg-immortal;
};
 
memory {
diff --git a/arch/powerpc/platforms/embedded6xx/wii.c 
b/arch/powerpc/platforms/embedded6xx/wii.c
index 57e5b60..e63c5c8 100644
--- a/arch/powerpc/platforms/embedded6xx/wii.c
+++ b/arch/powerpc/platforms/embedded6xx/wii.c
@@ -164,6 +164,7 @@ static void __init wii_setup_arch(void)
clrbits32(hw_gpio + HW_GPIO_OUT(0),
  HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
}
+   ppc_swiotlb_enable = 1;
 }
 
 static void wii_restart(char *cmd)
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v5 10/10] wii: hollywood ehci controller support

2010-03-19 Thread Albert Herranz
Add support for the USB Enhanced Host Controller Interface included
in the Hollywood chipset of the Nintendo Wii video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/Kconfig |1 +
 drivers/usb/host/Kconfig   |8 +
 drivers/usb/host/ehci-hcd.c|5 +
 drivers/usb/host/ehci-hlwd.c   |  233 
 drivers/usb/host/ehci.h|   23 +++
 5 files changed, 270 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/host/ehci-hlwd.c

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index f4fff0a..63bc708 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -121,6 +121,7 @@ config WII
select GAMECUBE_COMMON
select HAVE_GENERIC_DMA_COHERENT
select SWIOTLB
+   select USB_ARCH_HAS_EHCI
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 2678a16..342954f 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -131,6 +131,14 @@ config USB_EHCI_HCD_PPC_OF
  Enables support for the USB controller present on the PowerPC
  OpenFirmware platform bus.
 
+config USB_EHCI_HCD_HLWD
+   bool Nintendo Wii (Hollywood) EHCI USB controller support
+   depends on USB_EHCI_HCD  WII
+   default y
+   ---help---
+ Say Y here to support the EHCI USB controller found in the
+ Hollywood chipset of the Nintendo Wii video game console.
+
 config USB_W90X900_EHCI
bool W90X900(W90P910) EHCI support
depends on USB_EHCI_HCD  ARCH_W90X900
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 1ec3857..395c6a1 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1133,6 +1133,11 @@ MODULE_LICENSE (GPL);
 #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_HCD_HLWD
+#include ehci-hlwd.c
+#define OF_PLATFORM_DRIVER ehci_hcd_hlwd_driver
+#endif
+
 #ifdef CONFIG_XPS_USB_HCD_XILINX
 #include ehci-xilinx-of.c
 #define OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
diff --git a/drivers/usb/host/ehci-hlwd.c b/drivers/usb/host/ehci-hlwd.c
new file mode 100644
index 000..129e96b
--- /dev/null
+++ b/drivers/usb/host/ehci-hlwd.c
@@ -0,0 +1,233 @@
+/*
+ * drivers/usb/host/ehci-hlwd.c
+ *
+ * Nintendo Wii (Hollywood) USB Enhanced Host Controller Interface.
+ * Copyright (C) 2009-2010 The GameCube Linux Team
+ * Copyright (C) 2009,2010 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.
+ *
+ * Based on ehci-ppc-of.c
+ *
+ * EHCI HCD (Host Controller Driver) for USB.
+ *
+ * Bus Glue for PPC On-Chip EHCI driver on the of_platform bus
+ * Tested on AMCC PPC 440EPx
+ *
+ * Valentine Barshak vbars...@ru.mvista.com
+ *
+ * Based on ehci-ppc-soc.c by Stefan Roese s...@denx.de
+ * and ohci-ppc-of.c by Sylvain Munaut t...@246tnt.com
+ *
+ * This file is licenced under the GPL.
+ */
+
+#include linux/signal.h
+#include linux/of.h
+#include linux/of_platform.h
+#include asm/wii.h
+
+#define DRV_MODULE_NAME ehci-hlwd
+#define DRV_DESCRIPTION Nintendo Wii EHCI Host Controller
+#define DRV_AUTHOR  Albert Herranz
+
+/*
+ * Non-standard registers.
+ */
+#define HLWD_EHCI_CTL  0x00cc  /* Controller Control */
+#define HLWD_EHCI_CTL_INTE (115) /* Notify EHCI interrupts */
+
+/* called during probe() after chip reset completes */
+static int ehci_hlwd_reset(struct usb_hcd *hcd)
+{
+   struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+   int error;
+
+   dbg_hcs_params(ehci, reset);
+   dbg_hcc_params(ehci, reset);
+
+   error = ehci_halt(ehci);
+   if (error)
+   goto out;
+
+   error = ehci_init(hcd);
+   if (error)
+   goto out;
+
+   /* enable notification of EHCI interrupts */
+   setbits32(hcd-regs + HLWD_EHCI_CTL, HLWD_EHCI_CTL_INTE);
+
+   ehci-sbrn = 0x20;
+   error = ehci_reset(ehci);
+   ehci_port_power(ehci, 0);
+out:
+   return error;
+}
+
+static const struct hc_driver ehci_hlwd_hc_driver = {
+   .description= hcd_name,
+   .product_desc   = Nintendo Wii EHCI Host Controller,
+   .hcd_priv_size  = sizeof(struct ehci_hcd),
+
+   /*
+* generic hardware linkage
+*/
+   .irq= ehci_irq,
+   .flags  = HCD_USB2 | HCD_NO_COHERENT_MEM,
+
+   /*
+* basic lifecycle operations
+*/
+   .reset  = ehci_hlwd_reset

Re: [PATCH v5 00/10] wii: add usb 2.0 support

2010-03-19 Thread Albert Herranz
Alan Stern wrote:
 Alan: I think you are also working in a patchset to make {un}map_urb_for_dma
 remember how the urb was mapped, right?
 
 Yes; you can see an initial version here:
 
   http://marc.info/?l=linux-usbm=126901183419219w=2
 
 This is a bug fix, so it's likely to be merged before your work.
 
 It's a messy situation, with two people changing the same code at the
 same time.  I think the best approach will be to wait until the bug-fix
 patch is tested and accepted; then I can create a version of your 5/10
 and 6/10 patches adding HCD_NO_COHERENT_MEM and the corresponding
 behavior.  That can stand by itself, and once it is accepted the rest
 of your series should go through with no difficulty (at least, no
 difficulties involving the USB core!).

Agreed. I'll keep an eye on these developments.

 
 Alan Stern
 

Thanks a lot,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH v5 08/10] wii: add mem2 dma mapping ops

2010-03-19 Thread Albert Herranz
Konrad Rzeszutek Wilk wrote:
 +/*
 + * The mem2_dma device.
 + *
 + * This device owns a pool of coherent MEM2 memory that can be shared 
 among
 + * several devices requiring MEM2 DMA buffers, instead of dedicating 
 specific
 + * pools for each device.
 + *
 + * A device can use the shared coherent MEM2 memory pool by calling
 + * wii_set_mem2_dma_constraints().
 + *
 + */
 +
 +struct mem2_dma {
 +struct platform_device *pdev;
 +
 
 The space there isn't neccessary.
 

Yes. Having it or not is just a matter of formatting style taste.

 +dma_addr_t dma_base;
 
 I think you need only one of them. You don't seem to use 'base'
 +void *base;
 +size_t size;
 +};
 

I can even get rid of the whole struct mem2_dma and just use a struct 
platform_device now that there's no mem2_dma_exit() function.
I'll do that on the next iteration.

Thanks for your comments.

Cheers,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH v5 08/10] wii: add mem2 dma mapping ops

2010-03-19 Thread Albert Herranz
Konrad Rzeszutek Wilk wrote:
 +int wii_set_mem2_dma_constraints(struct device *dev)
 +{
 +struct dev_archdata *sd;
 +
 +sd = dev-archdata;
 +sd-max_direct_dma_addr = 0;
 +sd-min_direct_dma_addr = wii_hole_start + wii_hole_size;
 +
 +set_dma_ops(dev, wii_mem2_dma_ops);
 +return 0;
 +}
 +EXPORT_SYMBOL(wii_set_mem2_dma_constraints);
 
 Can you make them EXPORT_SYMBOL_GPL?

Sure. I don't know why I didn't use the *_GPL flavour on first place.

Thanks,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH] powerpc: fix swiotlb to respect the boot option

2010-03-17 Thread Albert Herranz
FUJITA Tomonori wrote:
 powerpc initializes swiotlb before parsing the kernel boot options so
 swiotlb options (e.g. specifying the swiotlb buffer size) are ignored.
 
 Any time before freeing bootmem works for swiotlb so this patch moves
 powerpc's swiotlb initialization after parsing the kernel boot
 options, mem_init (as x86 does).
 
 Signed-off-by: FUJITA Tomonori fujita.tomon...@lab.ntt.co.jp
 Tested-by: Becky Bruce bec...@kernel.crashing.org

Thanks!

Tested-by: Albert Herranz albert_herr...@yahoo.es

 ---
  arch/powerpc/kernel/setup_32.c |6 --
  arch/powerpc/kernel/setup_64.c |6 --
  arch/powerpc/mm/mem.c  |6 ++
  3 files changed, 6 insertions(+), 12 deletions(-)
 
 diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
 index b152de3..8f58986 100644
 --- a/arch/powerpc/kernel/setup_32.c
 +++ b/arch/powerpc/kernel/setup_32.c
 @@ -39,7 +39,6 @@
  #include asm/serial.h
  #include asm/udbg.h
  #include asm/mmu_context.h
 -#include asm/swiotlb.h
  
  #include setup.h
  
 @@ -343,11 +342,6 @@ void __init setup_arch(char **cmdline_p)
   ppc_md.setup_arch();
   if ( ppc_md.progress ) ppc_md.progress(arch: exit, 0x3eab);
  
 -#ifdef CONFIG_SWIOTLB
 - if (ppc_swiotlb_enable)
 - swiotlb_init(1);
 -#endif
 -
   paging_init();
  
   /* Initialize the MMU context management stuff */
 diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
 index 6354739..9143891 100644
 --- a/arch/powerpc/kernel/setup_64.c
 +++ b/arch/powerpc/kernel/setup_64.c
 @@ -61,7 +61,6 @@
  #include asm/xmon.h
  #include asm/udbg.h
  #include asm/kexec.h
 -#include asm/swiotlb.h
  #include asm/mmu_context.h
  
  #include setup.h
 @@ -541,11 +540,6 @@ void __init setup_arch(char **cmdline_p)
   if (ppc_md.setup_arch)
   ppc_md.setup_arch();
  
 -#ifdef CONFIG_SWIOTLB
 - if (ppc_swiotlb_enable)
 - swiotlb_init(1);
 -#endif
 -
   paging_init();
  
   /* Initialize the MMU context management stuff */
 diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
 index 311224c..448f972 100644
 --- a/arch/powerpc/mm/mem.c
 +++ b/arch/powerpc/mm/mem.c
 @@ -48,6 +48,7 @@
  #include asm/sparsemem.h
  #include asm/vdso.h
  #include asm/fixmap.h
 +#include asm/swiotlb.h
  
  #include mmu_decl.h
  
 @@ -320,6 +321,11 @@ void __init mem_init(void)
   struct page *page;
   unsigned long reservedpages = 0, codesize, initsize, datasize, bsssize;
  
 +#ifdef CONFIG_SWIOTLB
 + if (ppc_swiotlb_enable)
 + swiotlb_init(1);
 +#endif
 +
   num_physpages = lmb.memory.size  PAGE_SHIFT;
   high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
  

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH v4 04/11] swiotlb: support NOT_COHERENT_CACHE PowerPC platforms

2010-03-16 Thread Albert Herranz
FUJITA Tomonori wrote:
 On Fri, 12 Mar 2010 20:12:39 +0100
 Albert Herranz albert_herr...@yahoo.es wrote:
 
 The current SWIOTLB code does not support NOT_COHERENT_CACHE platforms.
 This patch adds support for NOT_COHERENT_CACHE platforms to SWIOTLB by
 adding two platform specific functions swiotlb_dma_sync_page() and
 swiotlb_dma_sync() which can be used to explicitly manage cache coherency.

 On PowerPC these functions are mapped to their corresponding
 __dma_sync_page() and __dma_sync() functions.
 On other architectures using SWIOTLB these functions are optimized out.

 This will be used later to support SWIOTLB on the Nintendo Wii video game
 console.

 CC: linuxppc-dev@lists.ozlabs.org
 CC: linux-ker...@vger.kernel.org
 CC: x...@kernel.org
 CC: linux-i...@vger.kernel.org
 Signed-off-by: Albert Herranz albert_herr...@yahoo.es
 ---
  arch/ia64/include/asm/swiotlb.h|   10 ++
  arch/powerpc/include/asm/swiotlb.h |3 +++
  arch/x86/include/asm/swiotlb.h |   10 ++
  lib/swiotlb.c  |   30 --
  4 files changed, 47 insertions(+), 6 deletions(-)
 
 Why can't you use dma_sync_single_* instead of inventing new
 swiotlb sync functions?
 

At least on PowerPC, the DMA ops are per-device hooks. We attach the swiotlb 
DMA ops functions to those hooks when we are using swiotlb.
So calling dma_sync_single_*() would end up calling swiotlb_sync_single_*() 
which is not what we want.

Thanks,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH v4 04/11] swiotlb: support NOT_COHERENT_CACHE PowerPC platforms

2010-03-16 Thread Albert Herranz
FUJITA Tomonori wrote:
 If we want to make swiotlb generic (make on any architectures), we
 need to handle more cache issues here, I think. So it's better to have
 more generic ways instead of adding hooks to some archs.
 

Ok. So what would be an acceptable way of handling this in a generic way?
Should we for example have 2 levels of DMA ops in the swiotlb case (swiotlb and 
actual) and call the 2nd level (actual) from the swiotlb code whenever we 
need to act on non-bounced buffers?
Any other ideas?

Thanks,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [PATCH v4 05/11] swiotlb: add swiotlb_set_default_size()

2010-03-15 Thread Albert Herranz
FUJITA Tomonori wrote:
 On Fri, 12 Mar 2010 20:12:40 +0100
 Albert Herranz albert_herr...@yahoo.es wrote:
 
 The current SWIOTLB code uses a default of 64MB for the IO TLB area.
 This size can be influenced using a kernel command line parameter swiotlb.
 Unfortunately, the parsing of the kernel command line is done _after_ the
 swiotlb is initialized on some architectures.

 This patch adds a new function swiotlb_set_default_size() which can be used
 before swiotlb_init() to indicate the desired IO TLB area size in bytes.

 This will be used later to implement a smaller IO TLB on the Nintendo Wii
 video game console which just comes with 24MB + 64MB of RAM.

 CC: linuxppc-dev@lists.ozlabs.org
 CC: linux-ker...@vger.kernel.org
 CC: x...@kernel.org
 CC: linux-i...@vger.kernel.org
 Signed-off-by: Albert Herranz albert_herr...@yahoo.es
 ---
  include/linux/swiotlb.h |2 ++
  lib/swiotlb.c   |   20 
  2 files changed, 22 insertions(+), 0 deletions(-)
 
 Please fix the powerpc swiotlb initialization instead.
 
 Calling swiotlb_init() before parsing kernel parameters sounds
 wrong. Any reasons why you can't fix it?
 

I think that this would be better asked by a PowerPC maintainer. Ben?

If this is really a problem the swiotlb late init may be a solution too in this 
particular case.

Thanks,
Albert
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 02/11] powerpc: add min_direct_dma_addr

2010-03-12 Thread Albert Herranz
This patch adds min_direct_dma_addr to struct dev_archdata.

min_direct_dma_addr can be used to define which is the minimum address
suitable for a DMA operation.
dma_capable() is updated to use this information in the SWIOTLB case.

This will be used later to support the Nintendo Wii video game console
which has limitations performing DMA to memory below 0x1000 (MEM1).

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/include/asm/device.h  |1 +
 arch/powerpc/include/asm/dma-mapping.h |2 ++
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/device.h 
b/arch/powerpc/include/asm/device.h
index 6d94d27..23f0009 100644
--- a/arch/powerpc/include/asm/device.h
+++ b/arch/powerpc/include/asm/device.h
@@ -27,6 +27,7 @@ struct dev_archdata {
 
 #ifdef CONFIG_SWIOTLB
dma_addr_t  max_direct_dma_addr;
+   dma_addr_t  min_direct_dma_addr;
 #endif
 };
 
diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index 18ecec8..eda3ebe 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -193,6 +193,8 @@ static inline bool dma_capable(struct device *dev, 
dma_addr_t addr, size_t size)
 
if (sd-max_direct_dma_addr  addr + size  sd-max_direct_dma_addr)
return 0;
+   if (sd-min_direct_dma_addr  addr  sd-min_direct_dma_addr)
+   return 0;
 #endif
 
if (!dev-dma_mask)
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 01/11] powerpc: add per-device dma coherent support

2010-03-12 Thread Albert Herranz
Use the generic per-device dma coherent allocator on powerpc.
This allows a driver to declare coherent memory area from where
a device can allocate coherent memory chunks.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/include/asm/dma-mapping.h |1 +
 arch/powerpc/kernel/dma.c  |5 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index 80a973b..18ecec8 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -17,6 +17,7 @@
 #include linux/dma-debug.h
 #include asm/io.h
 #include asm/swiotlb.h
+#include asm-generic/dma-coherent.h
 
 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
 
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 6215062..83d5232 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -27,6 +27,9 @@ void *dma_direct_alloc_coherent(struct device *dev, size_t 
size,
 {
void *ret;
 #ifdef CONFIG_NOT_COHERENT_CACHE
+   if (dma_alloc_from_coherent(dev, size, dma_handle, ret))
+   return ret;
+
ret = __dma_alloc_coherent(dev, size, dma_handle, flag);
if (ret == NULL)
return NULL;
@@ -54,6 +57,8 @@ void dma_direct_free_coherent(struct device *dev, size_t size,
  void *vaddr, dma_addr_t dma_handle)
 {
 #ifdef CONFIG_NOT_COHERENT_CACHE
+   if (dma_release_from_coherent(dev, get_order(size), vaddr))
+   return;
__dma_free_coherent(size, vaddr);
 #else
free_pages((unsigned long)vaddr, get_order(size));
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 00/11] wii: add usb 2.0 support

2010-03-12 Thread Albert Herranz
The following patch series adds USB 2.0 support for the Wii PowerPC
platform via the EHCI controller present in the Hollywood chipset
of the video game console.

The first iterations (v1 to v3) of this patchset were submitted as RFC PATCH.
The patchset is now sent as PATCH targetted for mainline inclusion.

v3 - v4
- Set the default IO TLB size via io_tlb_nslabs.
  Suggestion by Konrad Rzeszutek Wilk.
- Use kernel command line instead of device tree to tell the kernel about
  the location and size of the mem2_dma region.
  Suggestion by Segher Boessenkool.
- Keeps using v4 of the USB HCD_NO_COHERENT_MEM patch

Albert Herranz (11):
  powerpc: add per-device dma coherent support
  powerpc: add min_direct_dma_addr
  swiotbl: add back swiotlb_alloc_boot()
  swiotlb: support NOT_COHERENT_CACHE PowerPC platforms
  swiotlb: add swiotlb_set_default_size()
  USB: refactor unmap_urb_for_dma/map_urb_for_dma
  USB: add HCD_NO_COHERENT_MEM host controller driver flag
  wii: have generic dma coherent
  wii: add mem2 dma mapping ops
  wii: enable swiotlb
  wii: hollywood ehci controller support

 arch/ia64/include/asm/swiotlb.h  |   10 +
 arch/powerpc/boot/wii.c  |   44 +
 arch/powerpc/include/asm/device.h|1 +
 arch/powerpc/include/asm/dma-mapping.h   |3 +
 arch/powerpc/include/asm/swiotlb.h   |3 +
 arch/powerpc/include/asm/wii.h   |   25 +++
 arch/powerpc/kernel/dma.c|5 +
 arch/powerpc/platforms/embedded6xx/Kconfig   |3 +
 arch/powerpc/platforms/embedded6xx/Makefile  |2 +-
 arch/powerpc/platforms/embedded6xx/wii-dma.c |  265 ++
 arch/powerpc/platforms/embedded6xx/wii.c |2 +
 arch/x86/include/asm/swiotlb.h   |   10 +
 drivers/usb/core/buffer.c|   29 +++-
 drivers/usb/core/hcd.c   |  233 ---
 drivers/usb/core/hcd.h   |   13 +-
 drivers/usb/host/Kconfig |8 +
 drivers/usb/host/ehci-hcd.c  |5 +
 drivers/usb/host/ehci-hlwd.c |  233 ++
 drivers/usb/host/ehci.h  |   23 +++
 include/linux/swiotlb.h  |4 +
 include/linux/usb.h  |5 +
 lib/swiotlb.c|   60 +-
 22 files changed, 892 insertions(+), 94 deletions(-)
 create mode 100644 arch/powerpc/include/asm/wii.h
 create mode 100755 arch/powerpc/platforms/embedded6xx/wii-dma.c
 create mode 100644 drivers/usb/host/ehci-hlwd.c

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 03/11] swiotbl: add back swiotlb_alloc_boot()

2010-03-12 Thread Albert Herranz
This patch makes swiotlb_alloc_boot() available again.

This weak function can be overloaded to modify slightly how the SWIOTLB
and the overflow areas are allocated during boot.

This will be used later to support the Nintendo Wii video game console,
which requires placing the SWIOTLB area above 0x1000 (MEM2).

CC: linuxppc-dev@lists.ozlabs.org
CC: linux-ker...@vger.kernel.org
CC: x...@kernel.org
CC: linux-i...@vger.kernel.org
Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 include/linux/swiotlb.h |2 ++
 lib/swiotlb.c   |   10 --
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index febedcf..3954228 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -24,6 +24,8 @@ extern int swiotlb_force;
 
 extern void swiotlb_init(int verbose);
 
+extern void *swiotlb_alloc_boot(size_t bytes, unsigned long nslabs);
+
 extern void
 *swiotlb_alloc_coherent(struct device *hwdev, size_t size,
dma_addr_t *dma_handle, gfp_t flags);
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 437eedb..94db5df 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -117,6 +117,11 @@ setup_io_tlb_npages(char *str)
 __setup(swiotlb=, setup_io_tlb_npages);
 /* make io_tlb_overflow tunable too? */
 
+void * __weak __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)
+{
+   return alloc_bootmem_low_pages(size);
+}
+
 /* Note that this doesn't work with highmem page */
 static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev,
  volatile void *address)
@@ -158,7 +163,7 @@ swiotlb_init_with_default_size(size_t default_size, int 
verbose)
/*
 * Get IO TLB memory from the low pages
 */
-   io_tlb_start = alloc_bootmem_low_pages(bytes);
+   io_tlb_start = swiotlb_alloc_boot(bytes, io_tlb_nslabs);
if (!io_tlb_start)
panic(Cannot allocate SWIOTLB buffer);
io_tlb_end = io_tlb_start + bytes;
@@ -177,7 +182,8 @@ swiotlb_init_with_default_size(size_t default_size, int 
verbose)
/*
 * Get the overflow emergency buffer
 */
-   io_tlb_overflow_buffer = alloc_bootmem_low(io_tlb_overflow);
+   io_tlb_overflow_buffer = swiotlb_alloc_boot(io_tlb_overflow,
+   io_tlb_nslabs);
if (!io_tlb_overflow_buffer)
panic(Cannot allocate SWIOTLB overflow buffer!\n);
if (verbose)
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 05/11] swiotlb: add swiotlb_set_default_size()

2010-03-12 Thread Albert Herranz
The current SWIOTLB code uses a default of 64MB for the IO TLB area.
This size can be influenced using a kernel command line parameter swiotlb.
Unfortunately, the parsing of the kernel command line is done _after_ the
swiotlb is initialized on some architectures.

This patch adds a new function swiotlb_set_default_size() which can be used
before swiotlb_init() to indicate the desired IO TLB area size in bytes.

This will be used later to implement a smaller IO TLB on the Nintendo Wii
video game console which just comes with 24MB + 64MB of RAM.

CC: linuxppc-dev@lists.ozlabs.org
CC: linux-ker...@vger.kernel.org
CC: x...@kernel.org
CC: linux-i...@vger.kernel.org
Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 include/linux/swiotlb.h |2 ++
 lib/swiotlb.c   |   20 
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 3954228..2af6a45 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -22,6 +22,8 @@ extern int swiotlb_force;
  */
 #define IO_TLB_SHIFT 11
 
+extern size_t __init swiotlb_set_default_size(size_t size);
+
 extern void swiotlb_init(int verbose);
 
 extern void *swiotlb_alloc_boot(size_t bytes, unsigned long nslabs);
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 8f2dad9..dbeca50 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -117,6 +117,26 @@ setup_io_tlb_npages(char *str)
 __setup(swiotlb=, setup_io_tlb_npages);
 /* make io_tlb_overflow tunable too? */
 
+/**
+ * swiotlb_set_default_size() - set the default size for the IO TLB
+ * @size:  size in bytes of the IO TLB
+ *
+ * A platform can use this function to change the default size of the
+ * IO TLB when the default of 64MB is not suitable.
+ * This function must be called before swiotlb_init().
+ *
+ * Note that on some platforms this is the only way to influence the
+ * size of the IO TLB, as the command line may be parsed _after_ the
+ * IO TLB is initialized.
+ */
+size_t __init swiotlb_set_default_size(size_t size)
+{
+   size_t previous_size = io_tlb_nslabs  IO_TLB_SHIFT;
+
+   io_tlb_nslabs = size  IO_TLB_SHIFT;
+   return previous_size;
+}
+
 void * __weak __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)
 {
return alloc_bootmem_low_pages(size);
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 06/11] USB: refactor unmap_urb_for_dma/map_urb_for_dma

2010-03-12 Thread Albert Herranz
Split unmap_urb_for_dma() and map_urb_for_dma() into smaller pieces
to make the code easier to read and maintain.

This patch adds four new URB flags which are used by map_urb_for_dma()
to mark URBs with the exact method used to map the setup packet and/or the
transfer buffer.
These flags are checked too at unmap_urb_for_dma() time to determine how
to unmap the setup packet and/or the transfer buffer. The flags are cleared
when the actual unmap happens.

No functional change.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 drivers/usb/core/hcd.c |  211 +++-
 include/linux/usb.h|5 +
 2 files changed, 143 insertions(+), 73 deletions(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 80995ef..44ad710 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1260,106 +1260,171 @@ static void hcd_free_coherent(struct usb_bus *bus, 
dma_addr_t *dma_handle,
*dma_handle = 0;
 }
 
-static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
-  gfp_t mem_flags)
+static void unmap_urb_setup_packet(struct usb_hcd *hcd, struct urb *urb)
+{
+   if (urb-transfer_flags  URB_SETUP_DMA_MAPPED) {
+   urb-transfer_flags = ~URB_SETUP_DMA_MAPPED;
+   dma_unmap_single(hcd-self.controller, urb-setup_dma,
+sizeof(struct usb_ctrlrequest),
+DMA_TO_DEVICE);
+   } else if (urb-transfer_flags  URB_SETUP_BOUNCE_MAPPED) {
+   /* bounce from local memory */
+   urb-transfer_flags = ~URB_SETUP_BOUNCE_MAPPED;
+   hcd_free_coherent(urb-dev-bus, urb-setup_dma,
+ (void **)urb-setup_packet,
+ sizeof(struct usb_ctrlrequest),
+ DMA_TO_DEVICE);
+   } else {
+   /* nothing to do for PIO-based controller requests */
+   }
+}
+
+static void unmap_urb_transfer_buffer(struct usb_hcd *hcd, struct urb *urb)
 {
enum dma_data_direction dir;
-   int ret = 0;
 
-   /* Map the URB's buffers for DMA access.
-* Lower level HCD code should use *_dma exclusively,
-* unless it uses pio or talks to another transport,
-* or uses the provided scatter gather list for bulk.
-*/
+   dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+   if (urb-transfer_flags  URB_TRANSFER_DMA_MAPPED) {
+   urb-transfer_flags = ~URB_TRANSFER_DMA_MAPPED;
+   dma_unmap_single(hcd-self.controller,
+urb-transfer_dma,
+urb-transfer_buffer_length,
+dir);
+   } else if (urb-transfer_flags  URB_TRANSFER_BOUNCE_MAPPED) {
+   /* bounce from local memory */
+   urb-transfer_flags = ~URB_TRANSFER_BOUNCE_MAPPED;
+   hcd_free_coherent(urb-dev-bus, urb-transfer_dma,
+ urb-transfer_buffer,
+ urb-transfer_buffer_length,
+ dir);
+   } else {
+   /* nothing to do for PIO-based controller requests */
+   }
+}
+
+static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
+{
if (is_root_hub(urb-dev))
+   return;
+
+   unmap_urb_setup_packet(hcd, urb);
+   unmap_urb_transfer_buffer(hcd, urb);
+}
+
+static int urb_needs_setup_map(struct usb_hcd *hcd, struct urb *urb)
+{
+   /* setup mappings are required only for control requests */
+   if (!usb_endpoint_xfer_control(urb-ep-desc))
+   return 0;
+
+   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
+   if ((urb-transfer_flags  URB_NO_SETUP_DMA_MAP))
+   return 0;
+
+   return 1;
+}
+
+static int urb_needs_transfer_map(struct usb_hcd *hcd, struct urb *urb)
+{
+   /* don't need to map anything if there's nothing to map */
+   if (urb-transfer_buffer_length == 0)
return 0;
 
-   if (usb_endpoint_xfer_control(urb-ep-desc)
-!(urb-transfer_flags  URB_NO_SETUP_DMA_MAP)) {
+   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
+   if ((urb-transfer_flags  URB_NO_TRANSFER_DMA_MAP))
+   return 0;
+
+   return 1;
+}
+
+static int map_urb_setup_packet(struct usb_hcd *hcd, struct urb *urb,
+   gfp_t mem_flags)
+{
+   int ret;
+
+   if (urb_needs_setup_map(hcd, urb)) {
if (hcd-self.uses_dma) {
urb-setup_dma = dma_map_single(
-   hcd-self.controller,
-   urb-setup_packet,
-   sizeof(struct usb_ctrlrequest),
-   DMA_TO_DEVICE

[PATCH v4 04/11] swiotlb: support NOT_COHERENT_CACHE PowerPC platforms

2010-03-12 Thread Albert Herranz
The current SWIOTLB code does not support NOT_COHERENT_CACHE platforms.
This patch adds support for NOT_COHERENT_CACHE platforms to SWIOTLB by
adding two platform specific functions swiotlb_dma_sync_page() and
swiotlb_dma_sync() which can be used to explicitly manage cache coherency.

On PowerPC these functions are mapped to their corresponding
__dma_sync_page() and __dma_sync() functions.
On other architectures using SWIOTLB these functions are optimized out.

This will be used later to support SWIOTLB on the Nintendo Wii video game
console.

CC: linuxppc-dev@lists.ozlabs.org
CC: linux-ker...@vger.kernel.org
CC: x...@kernel.org
CC: linux-i...@vger.kernel.org
Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/ia64/include/asm/swiotlb.h|   10 ++
 arch/powerpc/include/asm/swiotlb.h |3 +++
 arch/x86/include/asm/swiotlb.h |   10 ++
 lib/swiotlb.c  |   30 --
 4 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/arch/ia64/include/asm/swiotlb.h b/arch/ia64/include/asm/swiotlb.h
index f0acde6..6722090 100644
--- a/arch/ia64/include/asm/swiotlb.h
+++ b/arch/ia64/include/asm/swiotlb.h
@@ -14,4 +14,14 @@ static inline void pci_swiotlb_init(void)
 }
 #endif
 
+static inline void swiotlb_dma_sync_page(struct page *page,
+unsigned long offset,
+size_t size, int direction)
+{
+}
+
+static inline void swiotlb_dma_sync(void *vaddr, size_t size, int direction)
+{
+}
+
 #endif /* ASM_IA64__SWIOTLB_H */
diff --git a/arch/powerpc/include/asm/swiotlb.h 
b/arch/powerpc/include/asm/swiotlb.h
index 8979d4c..603b343 100644
--- a/arch/powerpc/include/asm/swiotlb.h
+++ b/arch/powerpc/include/asm/swiotlb.h
@@ -22,4 +22,7 @@ int __init swiotlb_setup_bus_notifier(void);
 
 extern void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev);
 
+#define swiotlb_dma_sync_page __dma_sync_page
+#define swiotlb_dma_sync __dma_sync
+
 #endif /* __ASM_SWIOTLB_H */
diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
index 8085277..e5f6d9c 100644
--- a/arch/x86/include/asm/swiotlb.h
+++ b/arch/x86/include/asm/swiotlb.h
@@ -20,4 +20,14 @@ static inline void pci_swiotlb_init(void)
 
 static inline void dma_mark_clean(void *addr, size_t size) {}
 
+static inline void swiotlb_dma_sync_page(struct page *page,
+unsigned long offset,
+size_t size, int direction)
+{
+}
+
+static inline void swiotlb_dma_sync(void *vaddr, size_t size, int direction)
+{
+}
+
 #endif /* _ASM_X86_SWIOTLB_H */
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 94db5df..8f2dad9 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -346,10 +346,13 @@ static void swiotlb_bounce(phys_addr_t phys, char 
*dma_addr, size_t size,
local_irq_save(flags);
buffer = kmap_atomic(pfn_to_page(pfn),
 KM_BOUNCE_READ);
-   if (dir == DMA_TO_DEVICE)
+   if (dir == DMA_TO_DEVICE) {
memcpy(dma_addr, buffer + offset, sz);
-   else
+   swiotlb_dma_sync(dma_addr, sz, dir);
+   } else {
+   swiotlb_dma_sync(dma_addr, sz, dir);
memcpy(buffer + offset, dma_addr, sz);
+   }
kunmap_atomic(buffer, KM_BOUNCE_READ);
local_irq_restore(flags);
 
@@ -359,10 +362,14 @@ static void swiotlb_bounce(phys_addr_t phys, char 
*dma_addr, size_t size,
offset = 0;
}
} else {
-   if (dir == DMA_TO_DEVICE)
+   if (dir == DMA_TO_DEVICE) {
memcpy(dma_addr, phys_to_virt(phys), size);
-   else
+   swiotlb_dma_sync(dma_addr, size, dir);
+
+   } else {
+   swiotlb_dma_sync(dma_addr, size, dir);
memcpy(phys_to_virt(phys), dma_addr, size);
+   }
}
 }
 
@@ -542,6 +549,8 @@ sync_single(struct device *hwdev, char *dma_addr, size_t 
size,
}
 }
 
+#ifndef CONFIG_NOT_COHERENT_CACHE
+
 void *
 swiotlb_alloc_coherent(struct device *hwdev, size_t size,
   dma_addr_t *dma_handle, gfp_t flags)
@@ -606,6 +615,8 @@ swiotlb_free_coherent(struct device *hwdev, size_t size, 
void *vaddr,
 }
 EXPORT_SYMBOL(swiotlb_free_coherent);
 
+#endif /* !CONFIG_NOT_COHERENT_CACHE */
+
 static void
 swiotlb_full(struct device *dev, size_t size, int dir, int do_panic)
 {
@@ -652,8 +663,10 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct 
page *page,
 * we can safely return the device addr and not worry about bounce
 * buffering it.
 */
-   if (dma_capable(dev, dev_addr, size

[PATCH v4 07/11] USB: add HCD_NO_COHERENT_MEM host controller driver flag

2010-03-12 Thread Albert Herranz
The HCD_NO_COHERENT_MEM USB host controller driver flag can be enabled
to instruct the USB stack to avoid allocating coherent memory for USB
buffers.

This flag is useful to overcome some esoteric memory access restrictions
found in some platforms.
For example, the Nintendo Wii video game console is a NOT_COHERENT_CACHE
platform that is unable to safely perform non-32 bit uncached writes
to RAM because the byte enables are not connected to the bus.
Thus, in that platform, coherent DMA buffers cannot be directly used
by the kernel code unless it guarantees that all write accesses
to said buffers are done in 32 bit chunks (which is not the case in the
USB subsystem).

To avoid this unwanted behaviour HCD_NO_COHERENT_MEM can be enabled at
the HCD controller, causing USB buffer allocations to be satisfied from
normal kernel memory. In this case, the USB stack will make sure that
the buffers get properly mapped/unmapped for DMA transfers using the DMA
streaming mapping API.

Note that other parts of the USB stack may also use coherent memory,
like for example the hardware descriptors used in the EHCI controllers.
This needs to be checked and addressed separately. In the EHCI example,
hardware descriptors are accessed in 32-bit (or 64-bit) chunks, causing
no problems in the described scenario.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 drivers/usb/core/buffer.c |   29 +++--
 drivers/usb/core/hcd.c|   32 +++-
 drivers/usb/core/hcd.h|   13 +++--
 3 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 3ba2fff..10cd11d 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -36,6 +36,26 @@ static const size_t  pool_max [HCD_BUFFER_POOLS] = {
 
 /* SETUP primitives */
 
+static inline int hcd_uses_pio(struct usb_hcd *hcd)
+{
+   if ((!hcd-self.controller-dma_mask 
+   !(hcd-driver-flags  HCD_LOCAL_MEM)))
+   return 1;
+   return 0;
+}
+
+static inline int hcd_needs_non_dma_mem(struct usb_hcd *hcd)
+{
+   /*
+* PIO-based and HCD_NO_COHERENT_MEM-based controllers use
+* normal kernel memory.
+* The rest want DMA memory.
+*/
+   if (hcd_uses_pio(hcd) || (hcd-driver-flags  HCD_NO_COHERENT_MEM))
+   return 1;
+   return 0;
+}
+
 /**
  * hcd_buffer_create - initialize buffer pools
  * @hcd: the bus whose buffer pools are to be initialized
@@ -53,8 +73,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
charname[16];
int i, size;
 
-   if (!hcd-self.controller-dma_mask 
-   !(hcd-driver-flags  HCD_LOCAL_MEM))
+   if (hcd_needs_non_dma_mem(hcd))
return 0;
 
for (i = 0; i  HCD_BUFFER_POOLS; i++) {
@@ -109,8 +128,7 @@ void *hcd_buffer_alloc(
int i;
 
/* some USB hosts just use PIO */
-   if (!bus-controller-dma_mask 
-   !(hcd-driver-flags  HCD_LOCAL_MEM)) {
+   if (hcd_needs_non_dma_mem(hcd)) {
*dma = ~(dma_addr_t) 0;
return kmalloc(size, mem_flags);
}
@@ -135,8 +153,7 @@ void hcd_buffer_free(
if (!addr)
return;
 
-   if (!bus-controller-dma_mask 
-   !(hcd-driver-flags  HCD_LOCAL_MEM)) {
+   if (hcd_needs_non_dma_mem(hcd)) {
kfree(addr);
return;
}
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 44ad710..174853a 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1316,9 +1316,19 @@ static int urb_needs_setup_map(struct usb_hcd *hcd, 
struct urb *urb)
/* setup mappings are required only for control requests */
if (!usb_endpoint_xfer_control(urb-ep-desc))
return 0;
-
-   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
-   if ((urb-transfer_flags  URB_NO_SETUP_DMA_MAP))
+   /*
+* Setup packets are 8 bytes long and don't use scatter/gather.
+*
+* If the caller sets URB_NO_SETUP_DMA_MAP and urb-setup_dma
+* contains a valid DMA handle then it is already mapped, except
+* if the controller can't use coherent memory (HCD_NO_COHERENT_MEM).
+*
+* urb-setup_dma is set to ~0 when allocating USB buffers for
+* PIO-based or HCD_NO_COHERENT_MEM-based controllers.
+*/
+   if ((urb-transfer_flags  URB_NO_SETUP_DMA_MAP) 
+   urb-setup_dma != ~(dma_addr_t)0 
+   !(hcd-driver-flags  HCD_NO_COHERENT_MEM))
return 0;
 
return 1;
@@ -1330,8 +1340,20 @@ static int urb_needs_transfer_map(struct usb_hcd *hcd, 
struct urb *urb)
if (urb-transfer_buffer_length == 0)
return 0;
 
-   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
-   if ((urb-transfer_flags  URB_NO_TRANSFER_DMA_MAP

[PATCH v4 08/11] wii: have generic dma coherent

2010-03-12 Thread Albert Herranz
Let the Nintendo Wii gaming console use per-device dma coherent allocations.
This will be used later by some of its drivers.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/Kconfig |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index 524d971..fe77ab2 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -119,6 +119,7 @@ config WII
bool Nintendo-Wii
depends on EMBEDDED6xx
select GAMECUBE_COMMON
+   select HAVE_GENERIC_DMA_COHERENT
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 09/11] wii: add mem2 dma mapping ops

2010-03-12 Thread Albert Herranz
Some of the devices in the Hollywood chipset of the Nintendo Wii video
game console have restrictions performing DMA transfers to the first
contiguous RAM region (known as MEM1).
For example, up to 3 bytes of the last word of a DMA transfer of a
non-32 bit aligned length to MEM1 may be lost.
Such restrictions do not apply when using the second contiguous RAM
region (known as MEM2).

Add a set of DMA mapping operations which said devices can use to make
sure that DMA transfers are always performed to/from memory buffers
within MEM2.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/boot/wii.c  |   44 +
 arch/powerpc/include/asm/wii.h   |   25 +++
 arch/powerpc/platforms/embedded6xx/Kconfig   |1 +
 arch/powerpc/platforms/embedded6xx/Makefile  |2 +-
 arch/powerpc/platforms/embedded6xx/wii-dma.c |  265 ++
 5 files changed, 336 insertions(+), 1 deletions(-)
 create mode 100644 arch/powerpc/include/asm/wii.h
 create mode 100755 arch/powerpc/platforms/embedded6xx/wii-dma.c

diff --git a/arch/powerpc/boot/wii.c b/arch/powerpc/boot/wii.c
index 2ebaec0..84ce593 100644
--- a/arch/powerpc/boot/wii.c
+++ b/arch/powerpc/boot/wii.c
@@ -30,6 +30,7 @@ BSS_STACK(8192);
 #define MEM2_TOP   (0x1000 + 64*1024*1024)
 #define FIRMWARE_DEFAULT_SIZE  (12*1024*1024)
 
+#define MEM2_DMA_DEFAULT_SIZE  (512*1024)
 
 struct mipc_infohdr {
char magic[3];
@@ -101,6 +102,42 @@ out:
 
 }
 
+static char tmp_cmdline[COMMAND_LINE_SIZE];
+
+static void mem2_fixups(u32 *top, u32 *reg)
+{
+   /* ' mem2_dma=' + nnn + 'k...@0x' +  */
+   const int max_param_len = 10 + 7 + 4 + 8;
+   void *chosen;
+   u32 dma_base, dma_size;
+   char *p;
+
+   chosen = finddevice(/chosen);
+   if (!chosen)
+   fatal(Can't find chosen node\n);
+
+   /* the MEM2 DMA region must fit within MEM2 */
+   dma_size = MEM2_DMA_DEFAULT_SIZE;
+   if (dma_size  reg[3])
+   dma_size = reg[3];
+   /* reserve the region from the top of MEM2 */
+   *top -= dma_size;
+   dma_base = *top;
+   printf(mem2_dma: %...@0x%08x\n, dma_size  10, dma_base);
+
+   /*
+* Finally, add the MEM2 DMA region location information to the
+* kernel command line. The wii-dma driver will pick this info up.
+*/
+   getprop(chosen, bootargs, tmp_cmdline, COMMAND_LINE_SIZE-1);
+   p = strchr(tmp_cmdline, 0);
+   if (p - tmp_cmdline + max_param_len = COMMAND_LINE_SIZE)
+   fatal(No space left for mem2_dma param\n);
+
+   sprintf(p,  mem2_dma=...@0x%08x, dma_size  10, dma_base);
+   setprop_str(chosen, bootargs, tmp_cmdline);
+}
+
 static void platform_fixups(void)
 {
void *mem;
@@ -127,9 +164,16 @@ static void platform_fixups(void)
mem2_boundary = MEM2_TOP - FIRMWARE_DEFAULT_SIZE;
}
 
+   mem2_fixups(mem2_boundary, reg);
+
if (mem2_boundary  reg[2]  mem2_boundary  reg[2] + reg[3]) {
reg[3] = mem2_boundary - reg[2];
printf(top of MEM2 @ %08X\n, reg[2] + reg[3]);
+   /*
+* Find again the memory node as it may have changed its
+* position after adding some non-existing properties.
+*/
+   mem = finddevice(/memory);
setprop(mem, reg, reg, sizeof(reg));
}
 
diff --git a/arch/powerpc/include/asm/wii.h b/arch/powerpc/include/asm/wii.h
new file mode 100644
index 000..bb83c32
--- /dev/null
+++ b/arch/powerpc/include/asm/wii.h
@@ -0,0 +1,25 @@
+/*
+ * arch/powerpc/include/asm/wii.h
+ *
+ * Nintendo Wii board-specific definitions
+ * Copyright (C) 2010 The GameCube Linux Team
+ * Copyright (C) 2010 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 __ASM_POWERPC_WII_H
+#define __ASM_POWERPC_WII_H
+
+/*
+ * DMA operations for the Nintendo Wii.
+ */
+extern struct dma_map_ops wii_mem2_dma_ops;
+
+extern int wii_set_mem2_dma_constraints(struct device *dev);
+extern void wii_clear_mem2_dma_constraints(struct device *dev);
+
+#endif /* __ASM_POWERPC_WII_H */
diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index fe77ab2..f4fff0a 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -120,6 +120,7 @@ config WII
depends on EMBEDDED6xx
select GAMECUBE_COMMON
select HAVE_GENERIC_DMA_COHERENT
+   select SWIOTLB
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
diff --git a/arch/powerpc/platforms/embedded6xx/Makefile 
b/arch/powerpc/platforms

[PATCH v4 10/11] wii: enable swiotlb

2010-03-12 Thread Albert Herranz
Enable the use of a software IO TLB on the Nintendo Wii video game console.

This is used by the platform DMA support code to overcome the limitations
found in some of the devices within the Hollywood chipset.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/wii.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/wii.c 
b/arch/powerpc/platforms/embedded6xx/wii.c
index 57e5b60..6ad5c0a 100644
--- a/arch/powerpc/platforms/embedded6xx/wii.c
+++ b/arch/powerpc/platforms/embedded6xx/wii.c
@@ -164,6 +164,8 @@ static void __init wii_setup_arch(void)
clrbits32(hw_gpio + HW_GPIO_OUT(0),
  HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
}
+   swiotlb_set_default_size(120); /* 1 MB */
+   ppc_swiotlb_enable = 1;
 }
 
 static void wii_restart(char *cmd)
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v4 11/11] wii: hollywood ehci controller support

2010-03-12 Thread Albert Herranz
Add support for the USB Enhanced Host Controller Interface included
in the Hollywood chipset of the Nintendo Wii video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/Kconfig |1 +
 drivers/usb/host/Kconfig   |8 +
 drivers/usb/host/ehci-hcd.c|5 +
 drivers/usb/host/ehci-hlwd.c   |  233 
 drivers/usb/host/ehci.h|   23 +++
 5 files changed, 270 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/host/ehci-hlwd.c

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index f4fff0a..63bc708 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -121,6 +121,7 @@ config WII
select GAMECUBE_COMMON
select HAVE_GENERIC_DMA_COHERENT
select SWIOTLB
+   select USB_ARCH_HAS_EHCI
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 2678a16..342954f 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -131,6 +131,14 @@ config USB_EHCI_HCD_PPC_OF
  Enables support for the USB controller present on the PowerPC
  OpenFirmware platform bus.
 
+config USB_EHCI_HCD_HLWD
+   bool Nintendo Wii (Hollywood) EHCI USB controller support
+   depends on USB_EHCI_HCD  WII
+   default y
+   ---help---
+ Say Y here to support the EHCI USB controller found in the
+ Hollywood chipset of the Nintendo Wii video game console.
+
 config USB_W90X900_EHCI
bool W90X900(W90P910) EHCI support
depends on USB_EHCI_HCD  ARCH_W90X900
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 1ec3857..395c6a1 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1133,6 +1133,11 @@ MODULE_LICENSE (GPL);
 #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_HCD_HLWD
+#include ehci-hlwd.c
+#define OF_PLATFORM_DRIVER ehci_hcd_hlwd_driver
+#endif
+
 #ifdef CONFIG_XPS_USB_HCD_XILINX
 #include ehci-xilinx-of.c
 #define OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
diff --git a/drivers/usb/host/ehci-hlwd.c b/drivers/usb/host/ehci-hlwd.c
new file mode 100644
index 000..129e96b
--- /dev/null
+++ b/drivers/usb/host/ehci-hlwd.c
@@ -0,0 +1,233 @@
+/*
+ * drivers/usb/host/ehci-hlwd.c
+ *
+ * Nintendo Wii (Hollywood) USB Enhanced Host Controller Interface.
+ * Copyright (C) 2009-2010 The GameCube Linux Team
+ * Copyright (C) 2009,2010 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.
+ *
+ * Based on ehci-ppc-of.c
+ *
+ * EHCI HCD (Host Controller Driver) for USB.
+ *
+ * Bus Glue for PPC On-Chip EHCI driver on the of_platform bus
+ * Tested on AMCC PPC 440EPx
+ *
+ * Valentine Barshak vbars...@ru.mvista.com
+ *
+ * Based on ehci-ppc-soc.c by Stefan Roese s...@denx.de
+ * and ohci-ppc-of.c by Sylvain Munaut t...@246tnt.com
+ *
+ * This file is licenced under the GPL.
+ */
+
+#include linux/signal.h
+#include linux/of.h
+#include linux/of_platform.h
+#include asm/wii.h
+
+#define DRV_MODULE_NAME ehci-hlwd
+#define DRV_DESCRIPTION Nintendo Wii EHCI Host Controller
+#define DRV_AUTHOR  Albert Herranz
+
+/*
+ * Non-standard registers.
+ */
+#define HLWD_EHCI_CTL  0x00cc  /* Controller Control */
+#define HLWD_EHCI_CTL_INTE (115) /* Notify EHCI interrupts */
+
+/* called during probe() after chip reset completes */
+static int ehci_hlwd_reset(struct usb_hcd *hcd)
+{
+   struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+   int error;
+
+   dbg_hcs_params(ehci, reset);
+   dbg_hcc_params(ehci, reset);
+
+   error = ehci_halt(ehci);
+   if (error)
+   goto out;
+
+   error = ehci_init(hcd);
+   if (error)
+   goto out;
+
+   /* enable notification of EHCI interrupts */
+   setbits32(hcd-regs + HLWD_EHCI_CTL, HLWD_EHCI_CTL_INTE);
+
+   ehci-sbrn = 0x20;
+   error = ehci_reset(ehci);
+   ehci_port_power(ehci, 0);
+out:
+   return error;
+}
+
+static const struct hc_driver ehci_hlwd_hc_driver = {
+   .description= hcd_name,
+   .product_desc   = Nintendo Wii EHCI Host Controller,
+   .hcd_priv_size  = sizeof(struct ehci_hcd),
+
+   /*
+* generic hardware linkage
+*/
+   .irq= ehci_irq,
+   .flags  = HCD_USB2 | HCD_NO_COHERENT_MEM,
+
+   /*
+* basic lifecycle operations
+*/
+   .reset  = ehci_hlwd_reset

Re: [LKML] [RFC PATCH v3 04/11] swiotlb: support NOT_COHERENT_CACHE PowerPC platforms

2010-03-09 Thread Albert Herranz
Konrad Rzeszutek Wilk wrote:
 Hey Albert,
 
 I've been doing some posting in this area to split the physical / bus
 address translation so that multiple platforms can utilize it. I was
 wondering if it makes sense to utilize some of those concepts (ie, extend it
 for DMA coherency) for your code:
 
 https://lists.linux-foundation.org/pipermail/iommu/2010-February/002066.html
 
 And here is the git tree that goes on top of those patches:
 git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb-2.6.git 
 xen-swiotlb-0.5
 

Hi Konrad,

Thanks for your comments.

In my case, I'd like to re-use as much code from swiotlb as possible.
Adding a few function calls at strategic spots (which are optimized out for 
cache coherent platforms) to maintain cache coherency is currently enough for 
me if that's acceptable.
A more general approach would involve making swiotlb_bounce() 
platform-dependent (or at least the actual code for copying the buffers), and 
re-implementing map_page, sync_single and map_sg at the platform DMA code again.

I've whipped through your patches. If I undestood them, you make available a 
kind of swiotlb library core on top of which you can build alternate 
swiotlb-based dma ops.
Wouldn't it be a good idea to split the library code from the default swiotlb 
dma ops?
A(n embedded) platform may just want the library code to implement its own 
dma ops, without having to pay for the extra default swiotlb dma ops 
implementation.

Thanks,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [LKML] [RFC PATCH v3 05/11] swiotlb: add swiotlb_set_default_size()

2010-03-09 Thread Albert Herranz
Konrad Rzeszutek Wilk wrote:
 On Sun, Mar 07, 2010 at 01:11:46PM +0100, Albert Herranz wrote:
 The current SWIOTLB code uses a default of 64MB for the IO TLB area.
 This size can be influenced using a kernel command line parameter swiotlb.
 Unfortunately, the parsing of the kernel command line is done _after_ the
 swiotlb is initialized on some architectures.
 
 Why can't it be moved up? I mean move the parsing of the kernel
 parameters before the PCI subsystem?

(In my case there's no PCI subsystem, this is an embedded platform without PCI 
support).

Currently, in the PowerPC tree a platform wanting to use the swiotlb just sets 
the global ppc_swiotlb_enable variable to true in its setup_arch() function.
The PowerPC setup code then calls swiotlb_init(1) just after setup_arch() when 
SWIOTLB and ppc_swiotlb_enable is true.
At this point the kernel command line is not yet parsed.

So, at least in PowerPC linux, the early swiotlb initialization is not 
influenced by the kernel command line.

Maybe switching swiotlb from __setup to early_param would help too.

 This patch adds a new function swiotlb_set_default_size() which can be used
 before swiotlb_init() to indicate the desired IO TLB area size in bytes.

 This will be used later to implement a smaller IO TLB on the Nintendo Wii
 video game console which just comes with 24MB + 64MB of RAM.
 
 Use the io_tlb_nslabs, which is what swiotlb_init_with_default_size uses
 (the passed in argument is only used if io_tlb_nslabs is not set).
 

True, thanks.

Cheers,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v3 00/11] wii: add usb 2.0 support

2010-03-07 Thread Albert Herranz
The following patch series adds USB 2.0 support for the Wii PowerPC
platform via the EHCI controller present in the Hollywood chipset
of the video game console.

v2 - v3
- use per-device dma coherent support to allocate coherent MEM2 memory
- add support for SWIOTLB on NOT_COHERENT_CACHE PowerPC platforms
- use SWIOTLB instead of dmabounce to implement Wii MEM2 dma ops
- use v4 of the USB HCD_NO_COHERENT_MEM patch

Albert Herranz (11):
  powerpc: add per-device dma coherent support
  powerpc: add min_direct_dma_addr
  swiotbl: add back swiotlb_alloc_boot()
  swiotlb: support NOT_COHERENT_CACHE PowerPC platforms
  swiotlb: add swiotlb_set_default_size()
  USB: refactor unmap_urb_for_dma/map_urb_for_dma
  USB: add HCD_NO_COHERENT_MEM host controller driver flag
  wii: have generic dma coherent
  wii: add mem2 dma mapping ops
  wii: enable swiotlb
  wii: hollywood ehci controller support

 arch/ia64/include/asm/swiotlb.h  |   10 +
 arch/powerpc/boot/wii.c  |   34 
 arch/powerpc/include/asm/device.h|1 +
 arch/powerpc/include/asm/dma-mapping.h   |3 +
 arch/powerpc/include/asm/swiotlb.h   |3 +
 arch/powerpc/include/asm/wii.h   |   25 +++
 arch/powerpc/kernel/dma.c|5 +
 arch/powerpc/platforms/embedded6xx/Kconfig   |3 +
 arch/powerpc/platforms/embedded6xx/Makefile  |2 +-
 arch/powerpc/platforms/embedded6xx/wii-dma.c |  255 ++
 arch/powerpc/platforms/embedded6xx/wii.c |2 +
 arch/x86/include/asm/swiotlb.h   |   10 +
 drivers/usb/core/buffer.c|   29 +++-
 drivers/usb/core/hcd.c   |  233 
 drivers/usb/core/hcd.h   |   13 +-
 drivers/usb/host/Kconfig |8 +
 drivers/usb/host/ehci-hcd.c  |5 +
 drivers/usb/host/ehci-hlwd.c |  233 +++
 drivers/usb/host/ehci.h  |   23 +++
 include/linux/swiotlb.h  |4 +
 include/linux/usb.h  |5 +
 lib/swiotlb.c|   67 ++-
 22 files changed, 878 insertions(+), 95 deletions(-)
 create mode 100644 arch/powerpc/include/asm/wii.h
 create mode 100755 arch/powerpc/platforms/embedded6xx/wii-dma.c
 create mode 100644 drivers/usb/host/ehci-hlwd.c

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v3 01/11] powerpc: add per-device dma coherent support

2010-03-07 Thread Albert Herranz
Use the generic per-device dma coherent allocator on powerpc.
This allows a driver to declare coherent memory area from where
a device can allocate coherent memory chunks.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/include/asm/dma-mapping.h |1 +
 arch/powerpc/kernel/dma.c  |5 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index 80a973b..18ecec8 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -17,6 +17,7 @@
 #include linux/dma-debug.h
 #include asm/io.h
 #include asm/swiotlb.h
+#include asm-generic/dma-coherent.h
 
 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
 
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 6215062..83d5232 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -27,6 +27,9 @@ void *dma_direct_alloc_coherent(struct device *dev, size_t 
size,
 {
void *ret;
 #ifdef CONFIG_NOT_COHERENT_CACHE
+   if (dma_alloc_from_coherent(dev, size, dma_handle, ret))
+   return ret;
+
ret = __dma_alloc_coherent(dev, size, dma_handle, flag);
if (ret == NULL)
return NULL;
@@ -54,6 +57,8 @@ void dma_direct_free_coherent(struct device *dev, size_t size,
  void *vaddr, dma_addr_t dma_handle)
 {
 #ifdef CONFIG_NOT_COHERENT_CACHE
+   if (dma_release_from_coherent(dev, get_order(size), vaddr))
+   return;
__dma_free_coherent(size, vaddr);
 #else
free_pages((unsigned long)vaddr, get_order(size));
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v3 03/11] swiotbl: add back swiotlb_alloc_boot()

2010-03-07 Thread Albert Herranz
This patch makes swiotlb_alloc_boot() available again.

This weak function can be overloaded to modify slightly how the SWIOTLB
and the overflow areas are allocated during boot.

This will be used later to support the Nintendo Wii video game console,
which requires placing the SWIOTLB area above 0x1000 (MEM2).

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
CC: linuxppc-dev@lists.ozlabs.org
CC: linux-ker...@vger.kernel.org
CC: x...@kernel.org
CC: linux-i...@vger.kernel.org
---
 include/linux/swiotlb.h |2 ++
 lib/swiotlb.c   |   10 --
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index febedcf..3954228 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -24,6 +24,8 @@ extern int swiotlb_force;
 
 extern void swiotlb_init(int verbose);
 
+extern void *swiotlb_alloc_boot(size_t bytes, unsigned long nslabs);
+
 extern void
 *swiotlb_alloc_coherent(struct device *hwdev, size_t size,
dma_addr_t *dma_handle, gfp_t flags);
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 437eedb..94db5df 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -117,6 +117,11 @@ setup_io_tlb_npages(char *str)
 __setup(swiotlb=, setup_io_tlb_npages);
 /* make io_tlb_overflow tunable too? */
 
+void * __weak __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)
+{
+   return alloc_bootmem_low_pages(size);
+}
+
 /* Note that this doesn't work with highmem page */
 static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev,
  volatile void *address)
@@ -158,7 +163,7 @@ swiotlb_init_with_default_size(size_t default_size, int 
verbose)
/*
 * Get IO TLB memory from the low pages
 */
-   io_tlb_start = alloc_bootmem_low_pages(bytes);
+   io_tlb_start = swiotlb_alloc_boot(bytes, io_tlb_nslabs);
if (!io_tlb_start)
panic(Cannot allocate SWIOTLB buffer);
io_tlb_end = io_tlb_start + bytes;
@@ -177,7 +182,8 @@ swiotlb_init_with_default_size(size_t default_size, int 
verbose)
/*
 * Get the overflow emergency buffer
 */
-   io_tlb_overflow_buffer = alloc_bootmem_low(io_tlb_overflow);
+   io_tlb_overflow_buffer = swiotlb_alloc_boot(io_tlb_overflow,
+   io_tlb_nslabs);
if (!io_tlb_overflow_buffer)
panic(Cannot allocate SWIOTLB overflow buffer!\n);
if (verbose)
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v3 04/11] swiotlb: support NOT_COHERENT_CACHE PowerPC platforms

2010-03-07 Thread Albert Herranz
The current SWIOTLB code does not support NOT_COHERENT_CACHE platforms.
This patch adds support for NOT_COHERENT_CACHE platforms to SWIOTLB by
adding two platform specific functions swiotlb_dma_sync_page() and
swiotlb_dma_sync() which can be used to explicitly manage cache coherency.

On PowerPC these functions are mapped to their corresponding
__dma_sync_page() and __dma_sync() functions.
On other architectures using SWIOTLB these functions are optimized out.

This will be used later to support SWIOTLB on the Nintendo Wii video game
console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
CC: linuxppc-dev@lists.ozlabs.org
CC: linux-ker...@vger.kernel.org
CC: x...@kernel.org
CC: linux-i...@vger.kernel.org
---
 arch/ia64/include/asm/swiotlb.h|   10 ++
 arch/powerpc/include/asm/swiotlb.h |3 +++
 arch/x86/include/asm/swiotlb.h |   10 ++
 lib/swiotlb.c  |   30 --
 4 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/arch/ia64/include/asm/swiotlb.h b/arch/ia64/include/asm/swiotlb.h
index f0acde6..6722090 100644
--- a/arch/ia64/include/asm/swiotlb.h
+++ b/arch/ia64/include/asm/swiotlb.h
@@ -14,4 +14,14 @@ static inline void pci_swiotlb_init(void)
 }
 #endif
 
+static inline void swiotlb_dma_sync_page(struct page *page,
+unsigned long offset,
+size_t size, int direction)
+{
+}
+
+static inline void swiotlb_dma_sync(void *vaddr, size_t size, int direction)
+{
+}
+
 #endif /* ASM_IA64__SWIOTLB_H */
diff --git a/arch/powerpc/include/asm/swiotlb.h 
b/arch/powerpc/include/asm/swiotlb.h
index 8979d4c..603b343 100644
--- a/arch/powerpc/include/asm/swiotlb.h
+++ b/arch/powerpc/include/asm/swiotlb.h
@@ -22,4 +22,7 @@ int __init swiotlb_setup_bus_notifier(void);
 
 extern void pci_dma_dev_setup_swiotlb(struct pci_dev *pdev);
 
+#define swiotlb_dma_sync_page __dma_sync_page
+#define swiotlb_dma_sync __dma_sync
+
 #endif /* __ASM_SWIOTLB_H */
diff --git a/arch/x86/include/asm/swiotlb.h b/arch/x86/include/asm/swiotlb.h
index 8085277..e5f6d9c 100644
--- a/arch/x86/include/asm/swiotlb.h
+++ b/arch/x86/include/asm/swiotlb.h
@@ -20,4 +20,14 @@ static inline void pci_swiotlb_init(void)
 
 static inline void dma_mark_clean(void *addr, size_t size) {}
 
+static inline void swiotlb_dma_sync_page(struct page *page,
+unsigned long offset,
+size_t size, int direction)
+{
+}
+
+static inline void swiotlb_dma_sync(void *vaddr, size_t size, int direction)
+{
+}
+
 #endif /* _ASM_X86_SWIOTLB_H */
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 94db5df..8f2dad9 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -346,10 +346,13 @@ static void swiotlb_bounce(phys_addr_t phys, char 
*dma_addr, size_t size,
local_irq_save(flags);
buffer = kmap_atomic(pfn_to_page(pfn),
 KM_BOUNCE_READ);
-   if (dir == DMA_TO_DEVICE)
+   if (dir == DMA_TO_DEVICE) {
memcpy(dma_addr, buffer + offset, sz);
-   else
+   swiotlb_dma_sync(dma_addr, sz, dir);
+   } else {
+   swiotlb_dma_sync(dma_addr, sz, dir);
memcpy(buffer + offset, dma_addr, sz);
+   }
kunmap_atomic(buffer, KM_BOUNCE_READ);
local_irq_restore(flags);
 
@@ -359,10 +362,14 @@ static void swiotlb_bounce(phys_addr_t phys, char 
*dma_addr, size_t size,
offset = 0;
}
} else {
-   if (dir == DMA_TO_DEVICE)
+   if (dir == DMA_TO_DEVICE) {
memcpy(dma_addr, phys_to_virt(phys), size);
-   else
+   swiotlb_dma_sync(dma_addr, size, dir);
+
+   } else {
+   swiotlb_dma_sync(dma_addr, size, dir);
memcpy(phys_to_virt(phys), dma_addr, size);
+   }
}
 }
 
@@ -542,6 +549,8 @@ sync_single(struct device *hwdev, char *dma_addr, size_t 
size,
}
 }
 
+#ifndef CONFIG_NOT_COHERENT_CACHE
+
 void *
 swiotlb_alloc_coherent(struct device *hwdev, size_t size,
   dma_addr_t *dma_handle, gfp_t flags)
@@ -606,6 +615,8 @@ swiotlb_free_coherent(struct device *hwdev, size_t size, 
void *vaddr,
 }
 EXPORT_SYMBOL(swiotlb_free_coherent);
 
+#endif /* !CONFIG_NOT_COHERENT_CACHE */
+
 static void
 swiotlb_full(struct device *dev, size_t size, int dir, int do_panic)
 {
@@ -652,8 +663,10 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct 
page *page,
 * we can safely return the device addr and not worry about bounce
 * buffering it.
 */
-   if (dma_capable(dev, dev_addr, size

[RFC PATCH v3 05/11] swiotlb: add swiotlb_set_default_size()

2010-03-07 Thread Albert Herranz
The current SWIOTLB code uses a default of 64MB for the IO TLB area.
This size can be influenced using a kernel command line parameter swiotlb.
Unfortunately, the parsing of the kernel command line is done _after_ the
swiotlb is initialized on some architectures.

This patch adds a new function swiotlb_set_default_size() which can be used
before swiotlb_init() to indicate the desired IO TLB area size in bytes.

This will be used later to implement a smaller IO TLB on the Nintendo Wii
video game console which just comes with 24MB + 64MB of RAM.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
CC: linuxppc-dev@lists.ozlabs.org
CC: linux-ker...@vger.kernel.org
CC: x...@kernel.org
CC: linux-i...@vger.kernel.org
---
 include/linux/swiotlb.h |2 ++
 lib/swiotlb.c   |   27 ++-
 2 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 3954228..2af6a45 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -22,6 +22,8 @@ extern int swiotlb_force;
  */
 #define IO_TLB_SHIFT 11
 
+extern size_t __init swiotlb_set_default_size(size_t size);
+
 extern void swiotlb_init(int verbose);
 
 extern void *swiotlb_alloc_boot(size_t bytes, unsigned long nslabs);
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 8f2dad9..c99512d 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -73,6 +73,11 @@ static char *io_tlb_start, *io_tlb_end;
 static unsigned long io_tlb_nslabs;
 
 /*
+ * Default size for the IO TLB (64MB).
+ */
+static __initdata size_t io_tlb_default_size = 64 * (120);
+
+/*
  * When the IOMMU overflows we return a fallback buffer. This sets the size.
  */
 static unsigned long io_tlb_overflow = 32*1024;
@@ -117,6 +122,26 @@ setup_io_tlb_npages(char *str)
 __setup(swiotlb=, setup_io_tlb_npages);
 /* make io_tlb_overflow tunable too? */
 
+/**
+ * swiotlb_set_default_size() - set the default size for the IO TLB
+ * @size:  size in bytes of the IO TLB
+ *
+ * A platform can use this function to change the default size of the
+ * IO TLB when the default of 64MB is not suitable.
+ * This function must be called before swiotlb_init().
+ *
+ * Note that on some platforms this is the only way to influence the
+ * size of the IO TLB, as the command line may be parsed _after_ the
+ * IO TLB is initialized.
+ */
+size_t __init swiotlb_set_default_size(size_t size)
+{
+   size_t previous_size = io_tlb_default_size;
+
+   io_tlb_default_size = size;
+   return previous_size;
+}
+
 void * __weak __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)
 {
return alloc_bootmem_low_pages(size);
@@ -193,7 +218,7 @@ swiotlb_init_with_default_size(size_t default_size, int 
verbose)
 void __init
 swiotlb_init(int verbose)
 {
-   swiotlb_init_with_default_size(64 * (120), verbose);  /* default to 
64MB */
+   swiotlb_init_with_default_size(io_tlb_default_size, verbose);
 }
 
 /*
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v3 06/11] USB: refactor unmap_urb_for_dma/map_urb_for_dma

2010-03-07 Thread Albert Herranz
Split unmap_urb_for_dma() and map_urb_for_dma() into smaller pieces
to make the code easier to read and maintain.

This patch adds four new URB flags which are used by map_urb_for_dma()
to mark URBs with the exact method used to map the setup packet and/or the
transfer buffer.
These flags are checked too at unmap_urb_for_dma() time to determine how
to unmap the setup packet and/or the transfer buffer. The flags are cleared
when the actual unmap happens.

No functional change.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 drivers/usb/core/hcd.c |  211 +++-
 include/linux/usb.h|5 +
 2 files changed, 143 insertions(+), 73 deletions(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 80995ef..44ad710 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1260,106 +1260,171 @@ static void hcd_free_coherent(struct usb_bus *bus, 
dma_addr_t *dma_handle,
*dma_handle = 0;
 }
 
-static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
-  gfp_t mem_flags)
+static void unmap_urb_setup_packet(struct usb_hcd *hcd, struct urb *urb)
+{
+   if (urb-transfer_flags  URB_SETUP_DMA_MAPPED) {
+   urb-transfer_flags = ~URB_SETUP_DMA_MAPPED;
+   dma_unmap_single(hcd-self.controller, urb-setup_dma,
+sizeof(struct usb_ctrlrequest),
+DMA_TO_DEVICE);
+   } else if (urb-transfer_flags  URB_SETUP_BOUNCE_MAPPED) {
+   /* bounce from local memory */
+   urb-transfer_flags = ~URB_SETUP_BOUNCE_MAPPED;
+   hcd_free_coherent(urb-dev-bus, urb-setup_dma,
+ (void **)urb-setup_packet,
+ sizeof(struct usb_ctrlrequest),
+ DMA_TO_DEVICE);
+   } else {
+   /* nothing to do for PIO-based controller requests */
+   }
+}
+
+static void unmap_urb_transfer_buffer(struct usb_hcd *hcd, struct urb *urb)
 {
enum dma_data_direction dir;
-   int ret = 0;
 
-   /* Map the URB's buffers for DMA access.
-* Lower level HCD code should use *_dma exclusively,
-* unless it uses pio or talks to another transport,
-* or uses the provided scatter gather list for bulk.
-*/
+   dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+   if (urb-transfer_flags  URB_TRANSFER_DMA_MAPPED) {
+   urb-transfer_flags = ~URB_TRANSFER_DMA_MAPPED;
+   dma_unmap_single(hcd-self.controller,
+urb-transfer_dma,
+urb-transfer_buffer_length,
+dir);
+   } else if (urb-transfer_flags  URB_TRANSFER_BOUNCE_MAPPED) {
+   /* bounce from local memory */
+   urb-transfer_flags = ~URB_TRANSFER_BOUNCE_MAPPED;
+   hcd_free_coherent(urb-dev-bus, urb-transfer_dma,
+ urb-transfer_buffer,
+ urb-transfer_buffer_length,
+ dir);
+   } else {
+   /* nothing to do for PIO-based controller requests */
+   }
+}
+
+static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
+{
if (is_root_hub(urb-dev))
+   return;
+
+   unmap_urb_setup_packet(hcd, urb);
+   unmap_urb_transfer_buffer(hcd, urb);
+}
+
+static int urb_needs_setup_map(struct usb_hcd *hcd, struct urb *urb)
+{
+   /* setup mappings are required only for control requests */
+   if (!usb_endpoint_xfer_control(urb-ep-desc))
+   return 0;
+
+   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
+   if ((urb-transfer_flags  URB_NO_SETUP_DMA_MAP))
+   return 0;
+
+   return 1;
+}
+
+static int urb_needs_transfer_map(struct usb_hcd *hcd, struct urb *urb)
+{
+   /* don't need to map anything if there's nothing to map */
+   if (urb-transfer_buffer_length == 0)
return 0;
 
-   if (usb_endpoint_xfer_control(urb-ep-desc)
-!(urb-transfer_flags  URB_NO_SETUP_DMA_MAP)) {
+   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
+   if ((urb-transfer_flags  URB_NO_TRANSFER_DMA_MAP))
+   return 0;
+
+   return 1;
+}
+
+static int map_urb_setup_packet(struct usb_hcd *hcd, struct urb *urb,
+   gfp_t mem_flags)
+{
+   int ret;
+
+   if (urb_needs_setup_map(hcd, urb)) {
if (hcd-self.uses_dma) {
urb-setup_dma = dma_map_single(
-   hcd-self.controller,
-   urb-setup_packet,
-   sizeof(struct usb_ctrlrequest),
-   DMA_TO_DEVICE

[RFC PATCH v3 09/11] wii: add mem2 dma mapping ops

2010-03-07 Thread Albert Herranz
Some of the devices in the Hollywood chipset of the Nintendo Wii video
game console have restrictions performing DMA transfers to the first
contiguous RAM region (known as MEM1).
For example, up to 3 bytes of the last word of a DMA transfer of a
non-32 bit aligned length to MEM1 may be lost.
Such restrictions do not apply when using the second contiguous RAM
region (known as MEM2).

Add a set of DMA mapping operations which said devices can use to make
sure that DMA transfers are always performed to/from memory buffers
within MEM2.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/boot/wii.c  |   34 
 arch/powerpc/include/asm/wii.h   |   25 +++
 arch/powerpc/platforms/embedded6xx/Kconfig   |1 +
 arch/powerpc/platforms/embedded6xx/Makefile  |2 +-
 arch/powerpc/platforms/embedded6xx/wii-dma.c |  255 ++
 5 files changed, 316 insertions(+), 1 deletions(-)
 create mode 100644 arch/powerpc/include/asm/wii.h
 create mode 100755 arch/powerpc/platforms/embedded6xx/wii-dma.c

diff --git a/arch/powerpc/boot/wii.c b/arch/powerpc/boot/wii.c
index 2ebaec0..388e33d 100644
--- a/arch/powerpc/boot/wii.c
+++ b/arch/powerpc/boot/wii.c
@@ -30,6 +30,9 @@ BSS_STACK(8192);
 #define MEM2_TOP   (0x1000 + 64*1024*1024)
 #define FIRMWARE_DEFAULT_SIZE  (12*1024*1024)
 
+#define MEM2_DMA_BASE_PROP linux,wii-mem2-dma-base
+#define MEM2_DMA_SIZE_PROP linux,wii-mem2-dma-size
+#define MEM2_DMA_DEFAULT_SIZE  (512*1024)
 
 struct mipc_infohdr {
char magic[3];
@@ -101,6 +104,30 @@ out:
 
 }
 
+static void mem2_fixups(u32 *top, u32 *reg)
+{
+   void *chosen;
+   u32 dma_base, dma_size;
+   int len;
+
+   chosen = finddevice(/chosen);
+   if (!chosen)
+   fatal(Can't find chosen node\n);
+
+   len = getprop(chosen, MEM2_DMA_SIZE_PROP, dma_size, sizeof(dma_size));
+   if (len != sizeof(dma_size))
+   dma_size = MEM2_DMA_DEFAULT_SIZE;
+   if (dma_size  reg[3])
+   dma_size = reg[3];
+   setprop_val(chosen, MEM2_DMA_SIZE_PROP, dma_size);
+
+   *top -= dma_size;
+   dma_base = *top;
+   setprop_val(chosen, MEM2_DMA_BASE_PROP, dma_base);
+
+   printf(mem2_dma: %...@%08x\n, dma_size, dma_base);
+}
+
 static void platform_fixups(void)
 {
void *mem;
@@ -127,9 +154,16 @@ static void platform_fixups(void)
mem2_boundary = MEM2_TOP - FIRMWARE_DEFAULT_SIZE;
}
 
+   mem2_fixups(mem2_boundary, reg);
+
if (mem2_boundary  reg[2]  mem2_boundary  reg[2] + reg[3]) {
reg[3] = mem2_boundary - reg[2];
printf(top of MEM2 @ %08X\n, reg[2] + reg[3]);
+   /*
+* Find again the memory node as it may have changed its
+* position after adding some non-existing properties.
+*/
+   mem = finddevice(/memory);
setprop(mem, reg, reg, sizeof(reg));
}
 
diff --git a/arch/powerpc/include/asm/wii.h b/arch/powerpc/include/asm/wii.h
new file mode 100644
index 000..bb83c32
--- /dev/null
+++ b/arch/powerpc/include/asm/wii.h
@@ -0,0 +1,25 @@
+/*
+ * arch/powerpc/include/asm/wii.h
+ *
+ * Nintendo Wii board-specific definitions
+ * Copyright (C) 2010 The GameCube Linux Team
+ * Copyright (C) 2010 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 __ASM_POWERPC_WII_H
+#define __ASM_POWERPC_WII_H
+
+/*
+ * DMA operations for the Nintendo Wii.
+ */
+extern struct dma_map_ops wii_mem2_dma_ops;
+
+extern int wii_set_mem2_dma_constraints(struct device *dev);
+extern void wii_clear_mem2_dma_constraints(struct device *dev);
+
+#endif /* __ASM_POWERPC_WII_H */
diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index fe77ab2..f4fff0a 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -120,6 +120,7 @@ config WII
depends on EMBEDDED6xx
select GAMECUBE_COMMON
select HAVE_GENERIC_DMA_COHERENT
+   select SWIOTLB
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
diff --git a/arch/powerpc/platforms/embedded6xx/Makefile 
b/arch/powerpc/platforms/embedded6xx/Makefile
index 66c23e4..4d4c776 100644
--- a/arch/powerpc/platforms/embedded6xx/Makefile
+++ b/arch/powerpc/platforms/embedded6xx/Makefile
@@ -10,4 +10,4 @@ obj-$(CONFIG_PPC_C2K) += c2k.o
 obj-$(CONFIG_USBGECKO_UDBG)+= usbgecko_udbg.o
 obj-$(CONFIG_GAMECUBE_COMMON)  += flipper-pic.o
 obj-$(CONFIG_GAMECUBE) += gamecube.o
-obj-$(CONFIG_WII)  += wii.o hlwd-pic.o
+obj-$(CONFIG_WII

[RFC PATCH v3 10/11] wii: enable swiotlb

2010-03-07 Thread Albert Herranz
Enable the use of a software IO TLB on the Nintendo Wii video game console.

This is used by the platform DMA support code to overcome the limitations
found in some of the devices within the Hollywood chipset.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/wii.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/wii.c 
b/arch/powerpc/platforms/embedded6xx/wii.c
index 57e5b60..6ad5c0a 100644
--- a/arch/powerpc/platforms/embedded6xx/wii.c
+++ b/arch/powerpc/platforms/embedded6xx/wii.c
@@ -164,6 +164,8 @@ static void __init wii_setup_arch(void)
clrbits32(hw_gpio + HW_GPIO_OUT(0),
  HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
}
+   swiotlb_set_default_size(120); /* 1 MB */
+   ppc_swiotlb_enable = 1;
 }
 
 static void wii_restart(char *cmd)
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v3 07/11] USB: add HCD_NO_COHERENT_MEM host controller driver flag

2010-03-07 Thread Albert Herranz
The HCD_NO_COHERENT_MEM USB host controller driver flag can be enabled
to instruct the USB stack to avoid allocating coherent memory for USB
buffers.

This flag is useful to overcome some esoteric memory access restrictions
found in some platforms.
For example, the Nintendo Wii video game console is a NOT_COHERENT_CACHE
platform that is unable to safely perform non-32 bit uncached writes
to RAM because the byte enables are not connected to the bus.
Thus, in that platform, coherent DMA buffers cannot be directly used
by the kernel code unless it guarantees that all write accesses
to said buffers are done in 32 bit chunks (which is not the case in the
USB subsystem).

To avoid this unwanted behaviour HCD_NO_COHERENT_MEM can be enabled at
the HCD controller, causing USB buffer allocations to be satisfied from
normal kernel memory. In this case, the USB stack will make sure that
the buffers get properly mapped/unmapped for DMA transfers using the DMA
streaming mapping API.

Note that other parts of the USB stack may also use coherent memory,
like for example the hardware descriptors used in the EHCI controllers.
This needs to be checked and addressed separately. In the EHCI example,
hardware descriptors are accessed in 32-bit (or 64-bit) chunks, causing
no problems in the described scenario.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 drivers/usb/core/buffer.c |   29 +++--
 drivers/usb/core/hcd.c|   32 +++-
 drivers/usb/core/hcd.h|   13 +++--
 3 files changed, 57 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 3ba2fff..10cd11d 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -36,6 +36,26 @@ static const size_t  pool_max [HCD_BUFFER_POOLS] = {
 
 /* SETUP primitives */
 
+static inline int hcd_uses_pio(struct usb_hcd *hcd)
+{
+   if ((!hcd-self.controller-dma_mask 
+   !(hcd-driver-flags  HCD_LOCAL_MEM)))
+   return 1;
+   return 0;
+}
+
+static inline int hcd_needs_non_dma_mem(struct usb_hcd *hcd)
+{
+   /*
+* PIO-based and HCD_NO_COHERENT_MEM-based controllers use
+* normal kernel memory.
+* The rest want DMA memory.
+*/
+   if (hcd_uses_pio(hcd) || (hcd-driver-flags  HCD_NO_COHERENT_MEM))
+   return 1;
+   return 0;
+}
+
 /**
  * hcd_buffer_create - initialize buffer pools
  * @hcd: the bus whose buffer pools are to be initialized
@@ -53,8 +73,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
charname[16];
int i, size;
 
-   if (!hcd-self.controller-dma_mask 
-   !(hcd-driver-flags  HCD_LOCAL_MEM))
+   if (hcd_needs_non_dma_mem(hcd))
return 0;
 
for (i = 0; i  HCD_BUFFER_POOLS; i++) {
@@ -109,8 +128,7 @@ void *hcd_buffer_alloc(
int i;
 
/* some USB hosts just use PIO */
-   if (!bus-controller-dma_mask 
-   !(hcd-driver-flags  HCD_LOCAL_MEM)) {
+   if (hcd_needs_non_dma_mem(hcd)) {
*dma = ~(dma_addr_t) 0;
return kmalloc(size, mem_flags);
}
@@ -135,8 +153,7 @@ void hcd_buffer_free(
if (!addr)
return;
 
-   if (!bus-controller-dma_mask 
-   !(hcd-driver-flags  HCD_LOCAL_MEM)) {
+   if (hcd_needs_non_dma_mem(hcd)) {
kfree(addr);
return;
}
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 44ad710..174853a 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1316,9 +1316,19 @@ static int urb_needs_setup_map(struct usb_hcd *hcd, 
struct urb *urb)
/* setup mappings are required only for control requests */
if (!usb_endpoint_xfer_control(urb-ep-desc))
return 0;
-
-   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
-   if ((urb-transfer_flags  URB_NO_SETUP_DMA_MAP))
+   /*
+* Setup packets are 8 bytes long and don't use scatter/gather.
+*
+* If the caller sets URB_NO_SETUP_DMA_MAP and urb-setup_dma
+* contains a valid DMA handle then it is already mapped, except
+* if the controller can't use coherent memory (HCD_NO_COHERENT_MEM).
+*
+* urb-setup_dma is set to ~0 when allocating USB buffers for
+* PIO-based or HCD_NO_COHERENT_MEM-based controllers.
+*/
+   if ((urb-transfer_flags  URB_NO_SETUP_DMA_MAP) 
+   urb-setup_dma != ~(dma_addr_t)0 
+   !(hcd-driver-flags  HCD_NO_COHERENT_MEM))
return 0;
 
return 1;
@@ -1330,8 +1340,20 @@ static int urb_needs_transfer_map(struct usb_hcd *hcd, 
struct urb *urb)
if (urb-transfer_buffer_length == 0)
return 0;
 
-   /* If the caller set URB_NO_SETUP_DMA_MAP then no mapping is needed */
-   if ((urb-transfer_flags  URB_NO_TRANSFER_DMA_MAP

[RFC PATCH v3 08/11] wii: have generic dma coherent

2010-03-07 Thread Albert Herranz
Let the Nintendo Wii gaming console use per-device dma coherent allocations.
This will be used later by some of its drivers.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/Kconfig |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index 524d971..fe77ab2 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -119,6 +119,7 @@ config WII
bool Nintendo-Wii
depends on EMBEDDED6xx
select GAMECUBE_COMMON
+   select HAVE_GENERIC_DMA_COHERENT
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v3 11/11] wii: hollywood ehci controller support

2010-03-07 Thread Albert Herranz
Add support for the USB Enhanced Host Controller Interface included
in the Hollywood chipset of the Nintendo Wii video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/Kconfig |1 +
 drivers/usb/host/Kconfig   |8 +
 drivers/usb/host/ehci-hcd.c|5 +
 drivers/usb/host/ehci-hlwd.c   |  233 
 drivers/usb/host/ehci.h|   23 +++
 5 files changed, 270 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/host/ehci-hlwd.c

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index f4fff0a..63bc708 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -121,6 +121,7 @@ config WII
select GAMECUBE_COMMON
select HAVE_GENERIC_DMA_COHERENT
select SWIOTLB
+   select USB_ARCH_HAS_EHCI
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 2678a16..342954f 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -131,6 +131,14 @@ config USB_EHCI_HCD_PPC_OF
  Enables support for the USB controller present on the PowerPC
  OpenFirmware platform bus.
 
+config USB_EHCI_HCD_HLWD
+   bool Nintendo Wii (Hollywood) EHCI USB controller support
+   depends on USB_EHCI_HCD  WII
+   default y
+   ---help---
+ Say Y here to support the EHCI USB controller found in the
+ Hollywood chipset of the Nintendo Wii video game console.
+
 config USB_W90X900_EHCI
bool W90X900(W90P910) EHCI support
depends on USB_EHCI_HCD  ARCH_W90X900
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 1ec3857..395c6a1 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1133,6 +1133,11 @@ MODULE_LICENSE (GPL);
 #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_HCD_HLWD
+#include ehci-hlwd.c
+#define OF_PLATFORM_DRIVER ehci_hcd_hlwd_driver
+#endif
+
 #ifdef CONFIG_XPS_USB_HCD_XILINX
 #include ehci-xilinx-of.c
 #define OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
diff --git a/drivers/usb/host/ehci-hlwd.c b/drivers/usb/host/ehci-hlwd.c
new file mode 100644
index 000..129e96b
--- /dev/null
+++ b/drivers/usb/host/ehci-hlwd.c
@@ -0,0 +1,233 @@
+/*
+ * drivers/usb/host/ehci-hlwd.c
+ *
+ * Nintendo Wii (Hollywood) USB Enhanced Host Controller Interface.
+ * Copyright (C) 2009-2010 The GameCube Linux Team
+ * Copyright (C) 2009,2010 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.
+ *
+ * Based on ehci-ppc-of.c
+ *
+ * EHCI HCD (Host Controller Driver) for USB.
+ *
+ * Bus Glue for PPC On-Chip EHCI driver on the of_platform bus
+ * Tested on AMCC PPC 440EPx
+ *
+ * Valentine Barshak vbars...@ru.mvista.com
+ *
+ * Based on ehci-ppc-soc.c by Stefan Roese s...@denx.de
+ * and ohci-ppc-of.c by Sylvain Munaut t...@246tnt.com
+ *
+ * This file is licenced under the GPL.
+ */
+
+#include linux/signal.h
+#include linux/of.h
+#include linux/of_platform.h
+#include asm/wii.h
+
+#define DRV_MODULE_NAME ehci-hlwd
+#define DRV_DESCRIPTION Nintendo Wii EHCI Host Controller
+#define DRV_AUTHOR  Albert Herranz
+
+/*
+ * Non-standard registers.
+ */
+#define HLWD_EHCI_CTL  0x00cc  /* Controller Control */
+#define HLWD_EHCI_CTL_INTE (115) /* Notify EHCI interrupts */
+
+/* called during probe() after chip reset completes */
+static int ehci_hlwd_reset(struct usb_hcd *hcd)
+{
+   struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+   int error;
+
+   dbg_hcs_params(ehci, reset);
+   dbg_hcc_params(ehci, reset);
+
+   error = ehci_halt(ehci);
+   if (error)
+   goto out;
+
+   error = ehci_init(hcd);
+   if (error)
+   goto out;
+
+   /* enable notification of EHCI interrupts */
+   setbits32(hcd-regs + HLWD_EHCI_CTL, HLWD_EHCI_CTL_INTE);
+
+   ehci-sbrn = 0x20;
+   error = ehci_reset(ehci);
+   ehci_port_power(ehci, 0);
+out:
+   return error;
+}
+
+static const struct hc_driver ehci_hlwd_hc_driver = {
+   .description= hcd_name,
+   .product_desc   = Nintendo Wii EHCI Host Controller,
+   .hcd_priv_size  = sizeof(struct ehci_hcd),
+
+   /*
+* generic hardware linkage
+*/
+   .irq= ehci_irq,
+   .flags  = HCD_USB2 | HCD_NO_COHERENT_MEM,
+
+   /*
+* basic lifecycle operations
+*/
+   .reset  = ehci_hlwd_reset

Re: [RFC PATCH v2 8/9] USB: add HCD_NO_COHERENT_MEM host controller driver flag

2010-03-02 Thread Albert Herranz
Alan Stern wrote:
 On Mon, 1 Mar 2010, Albert Herranz wrote:
 
 If transfer_buffer_length is 0 then do nothing.
 Otherwise if num_sgs  0 then do nothing.
 Otherwise if URB_NO_TRANSFER_DMA_MAP and transfer_dma
 are both set (this avoids your HCD_NO_COHERENT_MEM
 case) then do nothing.

 I see. This case would include the PIO case too (for which dma_handle
 is set to all 1s).
 
 The test above should be transfer_dma != ~0, not transfer_dma != 0,
 since ~0 means the DMA address isn't set.  In fact I forgot to 
 include the PIO case; it should be handled by changing the remaining 
 tests as follows:
 
   Otherwise if hcd-self.uses_dma is set then
   If this URB doesn't require PIO then call dma_map_single
   Otherwise if HCD_LOCAL_MEM is set then call hcd_alloc_coherent
   Otherwise do nothing (PIO case).
 
 Currently this URB doesn't require PIO is always true, but in the 
 future it won't be.
 

Can this be currently tested?
Should I make provisions for this check now too?

 So this assumes that transfer_dma should be set initially to 0 when
 allocating USB buffers for HCD_NO_COHERENT_MEM.
 
 No, it should be set to ~0, the same as when buffers are allocated for 
 a PIO-based controller.
 

This logic now resembles more the one in my v2 proposal although with different 
formal checks.
I think I'll code and post another iteration of the 8/9 patch with your 
proposed checks and then we can continue further discussion on it.
I'll try to add explanatory comments for each check.

 Alan Stern
 

Thanks a lot for your input,
Albert
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH v2 8/9] USB: add HCD_NO_COHERENT_MEM host controller driver flag

2010-03-01 Thread Albert Herranz
Alan Stern wrote:
 --- a/drivers/usb/core/hcd.c
 +++ b/drivers/usb/core/hcd.c
 @@ -1260,6 +1260,34 @@ static void hcd_free_coherent(struct usb_bus *bus, 
 dma_addr_t *dma_handle,
  *dma_handle = 0;
  }
  
 +static int urb_needs_setup_dma_map(struct usb_hcd *hcd, struct urb *urb)
 +{
 +return !(urb-transfer_flags  URB_NO_SETUP_DMA_MAP) ||
 +   ((hcd-driver-flags  HCD_NO_COHERENT_MEM) 
 +urb-setup_dma == ~(dma_addr_t)0);
 +}
 +
 +static int urb_needs_setup_dma_unmap(struct usb_hcd *hcd, struct urb *urb)
 +{
 +return !(urb-transfer_flags  URB_NO_SETUP_DMA_MAP) ||
 +   ((hcd-driver-flags  HCD_NO_COHERENT_MEM) 
 +urb-setup_dma  urb-setup_dma != ~(dma_addr_t)0);
 +}
 +
 +static int urb_needs_transfer_dma_map(struct usb_hcd *hcd, struct urb *urb)
 +{
 +return !(urb-transfer_flags  URB_NO_TRANSFER_DMA_MAP) ||
 +   ((hcd-driver-flags  HCD_NO_COHERENT_MEM) 
 +urb-transfer_dma == ~(dma_addr_t)0);
 +}
 +
 +static int urb_needs_transfer_dma_unmap(struct usb_hcd *hcd, struct urb 
 *urb)
 +{
 +return !(urb-transfer_flags  URB_NO_TRANSFER_DMA_MAP) ||
 +   ((hcd-driver-flags  HCD_NO_COHERENT_MEM) 
 +urb-transfer_dma  urb-transfer_dma != ~(dma_addr_t)0);
 +}
 +
 
 These functions would be a lot easier to understand if they were 
 expanded into multiple test and return statements, rather than 
 squeezing all the Boolean manipulations into single expressions.  (Not 
 to mention the fact that other developement is going to make them even 
 more complicated than they are now...)
 

Yes, agreed. I'll enhance that, thanks.

 Also, I can't help thinking that the corresponding *_map() and 
 *_unmap() routines are so similar, it ought to be possible to combine 
 them.  The only difference is a check for a NULL DMA address, and it's 
 not clear to me why it is present.  It's also not clear why the test 
 for a DMA address of all ones is present.  Maybe they both can be 
 removed.
 

I think too that I can simplify that logic.
I added those checks in a defensive way seeking robustness while I familiarize 
with the USB stack innards. So far, those cases are just avoiding mappings when 
urb_needs_transfer_dma_map()/urb_needs_transfer_dma_unmap() are called with 
urb-transfer_buffer == 0 and urb-transfer_dma == 0.

I guess that those cases are related to scatterlist-based urb requests.
What should be the correct way to check if a urb has already been 
scatter/gather-mapped?

The final logic would be something like:
- map if URB_NO_TRANSFER_DMA_MAP is cleared
- otherwise (URB_TRANSFER_NO_DMA_MAP is set so) map if HCD_NO_COHERENT_MEM is 
set _and_ it's not a scatter/gather request (as that should have been mapped 
already by usb_buffer_map_sg())

Am I on the right path?

 Alan Stern
 

Thanks,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH v2 8/9] USB: add HCD_NO_COHERENT_MEM host controller driver flag

2010-03-01 Thread Albert Herranz
Alan Stern wrote:
 If urb-num_sgs  0 then urb has been s-g mapped.  Although we don't
 currently check for it, quite a few URBs have transfer_buffer_length ==
 0 (a number of control requests are like this, for example) so they
 don't need a mapping either.
 

Ok, I'll use urb-num_sgs  0 to check for s-g mapped requests.

 The final logic would be something like:
 - map if URB_NO_TRANSFER_DMA_MAP is cleared
 - otherwise (URB_TRANSFER_NO_DMA_MAP is set so) map if
 HCD_NO_COHERENT_MEM is set _and_ it's not a scatter/gather request
 (as that should have been mapped already by usb_buffer_map_sg())

 Am I on the right path?
 
 More or less.  I would do it somewhat differently:
 
   If URB_NO_TRANSFER_DMA_MAP is set then no map is needed.
   Otherwise if num_sgs  0 then no map is needed.
   Otherwise if HCD_NO_COHERENT_MEM is set then use
   hcd_alloc_coherent().
   Otherwise if transfer_buffer_length  0 then use
   dma_map_single().
 

I think that logic is not quite right.
Remember that the final goal is to avoid allocating USB buffers from coherent 
memory (because the USB drivers access USB buffers without access restrictions 
but the platform I'm working on can't write to coherent memory unless it is 
done in 32-bit chunks).
And we want to avoid bouncing at the USB layer too (that's what v1 did).

The strategy so far is:
- we have modified the USB buffer allocation routines 
hcd_buffer_alloc()/hcd_buffer_free() to always return normal kernel memory when 
HCD_NO_COHERENT_MEM is set on the host controller.
- during map_urb_for_dma()/unmap_urb_for_dma() we need to make sure that those 
USB buffers are sync'ed, even if we are told USB_NO_{SETUP,TRANSFER}_DMA_MAP

So the logic would be:

If URB_NO_TRANSFER_DMA_MAP is _cleared_ then do the mapping
- this case covers normal kernel memory used as a buffer and not 
already DMA mapped by a USB driver

Otherwise if HCD_NO_COHERENT_MEM is set _and_ num_sgs == 0 _and_ 
transfer_buffer_length  0 then do the mapping too
- this case covers USB buffers allocated via usb_buffer_alloc() and 
marked URB_NO_TRANSFER_DMA_MAP by a USB driver, which are allocated from normal 
kernel memory when HCD_NO_COHERENT_MEM is set (we avoid bouncing buffers here 
too, at least if they sit already within MEM2 in the Wii, but anyway that's 
part of the platform DMA mapping code)

s-g urbs do not need a mapping as they have already been mapped, marked 
URB_NO_TRANSFER_DMA_MAP and have num_sgs  0

 Similar logic is needed for the setup buffer mapping, but you can 
 assume that control URBs never use scatter-gather so there's no need to 
 check num_sgs (and there's no need to check the transfer length, since 
 setup packets are always 8 bytes long).
 
 In fact, I think URB_NO_SETUP_DMA_MAP doesn't really offer any
 worthwhile advantages.  (About the only place where multiple control
 requests are used in rapid succession is during firmware transfers, and
 those aren't time-constrained.)  It is currently used in a few
 drivers, but we ought to be able to remove it without too much effort.  
 That might make a good project.
 

I'll leave that projects to others or, in any case, address it later :)

 Alan Stern
 

Thanks,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH v2 8/9] USB: add HCD_NO_COHERENT_MEM host controller driver flag

2010-03-01 Thread Albert Herranz
Alan Stern wrote:
 On Mon, 1 Mar 2010, Albert Herranz wrote:
 
 Am I on the right path?
 More or less.  I would do it somewhat differently:

 If URB_NO_TRANSFER_DMA_MAP is set then no map is needed.
 Otherwise if num_sgs  0 then no map is needed.
 Otherwise if HCD_NO_COHERENT_MEM is set then use
 hcd_alloc_coherent().
 Otherwise if transfer_buffer_length  0 then use
 dma_map_single().

 I think that logic is not quite right.
 Remember that the final goal is to avoid allocating USB buffers from 
 coherent memory (because the USB drivers access USB buffers without access 
 restrictions but the platform I'm working on can't write to coherent memory 
 unless it is done in 32-bit chunks).
 
 Actually the final goal is to make the mapping/unmapping algorithms 
 clear and correct.  One of the subgoals involves avoiding coherent USB 
 buffers, but there are others as well (if you look back the through the 
 linux-usb mailing list for the last few weeks you'll see a discussion 
 about a controller which has to use PIO for control transfers but can 
 use DMA for other types).
 

Well, I was talking about our particular case here. I did not imply that we 
should forget about the other cases.

 And we want to avoid bouncing at the USB layer too (that's what v1 did).

 The strategy so far is:
 - we have modified the USB buffer allocation routines 
 hcd_buffer_alloc()/hcd_buffer_free() to always return normal kernel memory 
 when HCD_NO_COHERENT_MEM is set on the host controller.
 - during map_urb_for_dma()/unmap_urb_for_dma() we need to make sure that 
 those USB buffers are sync'ed, even if we are told 
 USB_NO_{SETUP,TRANSFER}_DMA_MAP

 So the logic would be:

  If URB_NO_TRANSFER_DMA_MAP is _cleared_ then do the mapping
 
 No, that's wrong because it ignores the HCD_LOCAL_MEM flag.
 

When I said do the mapping there I meant to do a dma_map_single() if 
self.uses_dma, else if HCD_LOCAL_MEM is set then do a hcd_alloc_coherent().
I should have been more clear on that.

  - this case covers normal kernel memory used as a buffer and not 
 already DMA mapped by a USB driver

  Otherwise if HCD_NO_COHERENT_MEM is set _and_ num_sgs == 0 _and_ 
 transfer_buffer_length  0 then do the mapping too
  - this case covers USB buffers allocated via usb_buffer_alloc() and 
 marked URB_NO_TRANSFER_DMA_MAP by a USB driver, which are allocated from 
 normal kernel memory when HCD_NO_COHERENT_MEM is set (we avoid bouncing 
 buffers here too, at least if they sit already within MEM2 in the Wii, but 
 anyway that's part of the platform DMA mapping code)

  s-g urbs do not need a mapping as they have already been mapped, marked 
 URB_NO_TRANSFER_DMA_MAP and have num_sgs  0
 
 Actually the test for transfer_buffer_length == 0 should be done first, 
 since obviously no mapping is needed if there's no data.  (And in fact 
 the current code does do this; I was wrong earlier when I said it 
 doesn't.)
 
 So let's make things a little easier by first testing the conditions 
 under which no mapping is needed:
 
   If transfer_buffer_length is 0 then do nothing.
   Otherwise if num_sgs  0 then do nothing.
   Otherwise if URB_NO_TRANSFER_DMA_MAP and transfer_dma
   are both set (this avoids your HCD_NO_COHERENT_MEM
   case) then do nothing.
 

I see. This case would include the PIO case too (for which dma_handle is set to 
all 1s).

So this assumes that transfer_dma should be set initially to 0 when allocating 
USB buffers for HCD_NO_COHERENT_MEM.

 The remaining cases all need mapping and/or bounce buffers:
 
   Otherwise if HCD_LOCAL_MEM is set then call hcd_alloc_coherent.
   Otherwise call dma_map_single.
 
 Finally, the unmapping tests can be simplified greatly if the kind of
 mapping is recorded in the URB flags.
 

Good point.

 Alan Stern
 

Thanks for your comments,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v2 1/9] powerpc: add per-device dma coherent support

2010-02-28 Thread Albert Herranz
Use the generic per-device dma coherent allocator on powerpc.
This allows a driver to declare coherent memory area from where
a device can allocate coherent memory chunks.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/include/asm/dma-mapping.h |1 +
 arch/powerpc/kernel/dma.c  |5 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/include/asm/dma-mapping.h 
b/arch/powerpc/include/asm/dma-mapping.h
index 80a973b..18ecec8 100644
--- a/arch/powerpc/include/asm/dma-mapping.h
+++ b/arch/powerpc/include/asm/dma-mapping.h
@@ -17,6 +17,7 @@
 #include linux/dma-debug.h
 #include asm/io.h
 #include asm/swiotlb.h
+#include asm-generic/dma-coherent.h
 
 #define DMA_ERROR_CODE (~(dma_addr_t)0x0)
 
diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
index 6215062..83d5232 100644
--- a/arch/powerpc/kernel/dma.c
+++ b/arch/powerpc/kernel/dma.c
@@ -27,6 +27,9 @@ void *dma_direct_alloc_coherent(struct device *dev, size_t 
size,
 {
void *ret;
 #ifdef CONFIG_NOT_COHERENT_CACHE
+   if (dma_alloc_from_coherent(dev, size, dma_handle, ret))
+   return ret;
+
ret = __dma_alloc_coherent(dev, size, dma_handle, flag);
if (ret == NULL)
return NULL;
@@ -54,6 +57,8 @@ void dma_direct_free_coherent(struct device *dev, size_t size,
  void *vaddr, dma_addr_t dma_handle)
 {
 #ifdef CONFIG_NOT_COHERENT_CACHE
+   if (dma_release_from_coherent(dev, get_order(size), vaddr))
+   return;
__dma_free_coherent(size, vaddr);
 #else
free_pages((unsigned long)vaddr, get_order(size));
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v2 0/9] wii: add usb 2.0 support

2010-02-28 Thread Albert Herranz
The following patch series adds USB 2.0 support for the Wii PowerPC
platform via the EHCI controller present in the Hollywood chipset
of the video game console.

v1 - v2
- enable per-device DMA coherent support on the Wii
- add a generic dmabounce based on ARM dmabounce
- make PowerPC and ARM use the generic dmabounce support
  (ARM just compile-tested)
- do not bounce buffers at the USB layer
- handle bounce buffers on the Wii at the platform support layer via the
  DMA API
- introduce a flag HCD_NO_COHERENT_MEM to avoid using coherent memory for
  USB buffers
- make the Hollywood EHCI controller use HCD_NO_COHERENT_MEM and honor
  MEM2 DMA constraints to solve the platform restrictions accessing
  coherent memory.

Albert Herranz (9):
  powerpc: add per-device dma coherent support
  wii: have generic dma coherent
  dma-coherent: fix bitmap access races
  add generic dmabounce support
  arm: use generic dmabounce support
  powerpc: add optional per-device dmabounce support
  wii: add mem2 dma mapping ops
  USB: add HCD_NO_COHERENT_MEM host controller driver flag
  wii: hollywood ehci controller support

 arch/Kconfig |3 +
 arch/arm/Kconfig |4 +-
 arch/arm/common/Kconfig  |6 +-
 arch/arm/common/dmabounce.c  |  376 +++--
 arch/arm/include/asm/device.h|2 +-
 arch/powerpc/boot/wii.c  |   34 ++
 arch/powerpc/include/asm/device.h|3 +
 arch/powerpc/include/asm/dma-mapping.h   |1 +
 arch/powerpc/include/asm/wii.h   |   25 ++
 arch/powerpc/kernel/dma.c|5 +
 arch/powerpc/platforms/embedded6xx/Kconfig   |3 +
 arch/powerpc/platforms/embedded6xx/Makefile  |2 +-
 arch/powerpc/platforms/embedded6xx/wii-dma.c |  557 ++
 drivers/base/dma-coherent.c  |   11 +
 drivers/usb/core/buffer.c|   15 +-
 drivers/usb/core/hcd.c   |   50 ++-
 drivers/usb/core/hcd.h   |   13 +-
 drivers/usb/host/Kconfig |8 +
 drivers/usb/host/ehci-hcd.c  |5 +
 drivers/usb/host/ehci-hlwd.c |  233 +++
 drivers/usb/host/ehci.h  |   23 +
 include/linux/dmabounce.h|   71 
 lib/Kconfig  |   10 +
 lib/Makefile |2 +
 lib/dmabounce.c  |  389 ++
 25 files changed, 1512 insertions(+), 339 deletions(-)
 create mode 100644 arch/powerpc/include/asm/wii.h
 create mode 100755 arch/powerpc/platforms/embedded6xx/wii-dma.c
 create mode 100644 drivers/usb/host/ehci-hlwd.c
 create mode 100644 include/linux/dmabounce.h
 create mode 100644 lib/dmabounce.c

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v2 2/9] wii: have generic dma coherent

2010-02-28 Thread Albert Herranz
Let the Nintendo Wii gaming console use per-device dma coherent allocations.
This will be used later by some of its drivers.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/Kconfig |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index 524d971..fe77ab2 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -119,6 +119,7 @@ config WII
bool Nintendo-Wii
depends on EMBEDDED6xx
select GAMECUBE_COMMON
+   select HAVE_GENERIC_DMA_COHERENT
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v2 3/9] dma-coherent: fix bitmap access races

2010-02-28 Thread Albert Herranz
The coherent per-device memory handling functions use the in-kernel
bitmap library to account for the allocated regions.

The bitmap functions, though, do not protect the bitmap structure from
being modified concurrently. This can lead, for example, to double
allocations if dma_alloc_from_coherent() is called while another
dma_alloc_from_coherent() is already in progress.

Fix those races by protecting concurrent modifications of the allocation
bitmap. spin_lock_irqsave()/spin_unlock_irqrestore() is used as the
allocation/release functions are planned to be used in interrupt context
for streaming DMA mappings/unmappings via bounce buffers.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 drivers/base/dma-coherent.c |   11 +++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c
index 962a3b5..9d27d63 100644
--- a/drivers/base/dma-coherent.c
+++ b/drivers/base/dma-coherent.c
@@ -11,6 +11,7 @@ struct dma_coherent_mem {
int size;
int flags;
unsigned long   *bitmap;
+   spinlock_t  lock;   /* protect bitmap operations */
 };
 
 int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
@@ -44,6 +45,7 @@ int dma_declare_coherent_memory(struct device *dev, 
dma_addr_t bus_addr,
dev-dma_mem-device_base = device_addr;
dev-dma_mem-size = pages;
dev-dma_mem-flags = flags;
+   spin_lock_init(dev-dma_mem-lock);
 
if (flags  DMA_MEMORY_MAP)
return DMA_MEMORY_MAP;
@@ -77,6 +79,7 @@ void *dma_mark_declared_memory_occupied(struct device *dev,
 {
struct dma_coherent_mem *mem = dev-dma_mem;
int pos, err;
+   unsigned long flags;
 
size += device_addr  ~PAGE_MASK;
 
@@ -84,7 +87,9 @@ void *dma_mark_declared_memory_occupied(struct device *dev,
return ERR_PTR(-EINVAL);
 
pos = (device_addr - mem-device_base)  PAGE_SHIFT;
+   spin_lock_irqsave(mem-lock, flags);
err = bitmap_allocate_region(mem-bitmap, pos, get_order(size));
+   spin_unlock_irqrestore(mem-lock, flags);
if (err != 0)
return ERR_PTR(err);
return mem-virt_base + (pos  PAGE_SHIFT);
@@ -112,6 +117,7 @@ int dma_alloc_from_coherent(struct device *dev, ssize_t 
size,
struct dma_coherent_mem *mem;
int order = get_order(size);
int pageno;
+   unsigned long flags;
 
if (!dev)
return 0;
@@ -124,7 +130,9 @@ int dma_alloc_from_coherent(struct device *dev, ssize_t 
size,
if (unlikely(size  (mem-size  PAGE_SHIFT)))
goto err;
 
+   spin_lock_irqsave(mem-lock, flags);
pageno = bitmap_find_free_region(mem-bitmap, mem-size, order);
+   spin_unlock_irqrestore(mem-lock, flags);
if (unlikely(pageno  0))
goto err;
 
@@ -163,12 +171,15 @@ EXPORT_SYMBOL(dma_alloc_from_coherent);
 int dma_release_from_coherent(struct device *dev, int order, void *vaddr)
 {
struct dma_coherent_mem *mem = dev ? dev-dma_mem : NULL;
+   unsigned long flags;
 
if (mem  vaddr = mem-virt_base  vaddr 
   (mem-virt_base + (mem-size  PAGE_SHIFT))) {
int page = (vaddr - mem-virt_base)  PAGE_SHIFT;
 
+   spin_lock_irqsave(mem-lock, flags);
bitmap_release_region(mem-bitmap, page, order);
+   spin_unlock_irqrestore(mem-lock, flags);
return 1;
}
return 0;
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v2 4/9] add generic dmabounce support

2010-02-28 Thread Albert Herranz
This patch makes part of the ARM dmabounce code available to other
architectures as a generic API.
See included kernel-doc annotations for the actual API implemented.

An architecture can opt-in for generic dmabounce support by defining
HAVE_DMABOUNCE.

This support will be used later to address DMA memory access restrictions
on the Nintendo Wii video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/Kconfig  |3 +
 include/linux/dmabounce.h |   77 +
 lib/Kconfig   |   10 ++
 lib/Makefile  |2 +
 lib/dmabounce.c   |  395 +
 5 files changed, 487 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/dmabounce.h
 create mode 100644 lib/dmabounce.c

diff --git a/arch/Kconfig b/arch/Kconfig
index 9d055b4..98ff26d 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -130,6 +130,9 @@ config HAVE_CLK
 config HAVE_DMA_API_DEBUG
bool
 
+config HAVE_DMABOUNCE
+   bool
+
 config HAVE_DEFAULT_NO_SPIN_MUTEXES
bool
 
diff --git a/include/linux/dmabounce.h b/include/linux/dmabounce.h
new file mode 100644
index 000..d60dc04
--- /dev/null
+++ b/include/linux/dmabounce.h
@@ -0,0 +1,77 @@
+#ifndef _LINUX_DMABOUNCE_H
+#define _LINUX_DMABOUNCE_H
+
+/* FIXME remove later when arch/arm/common/dmabounce.c is updated */
+#ifndef CONFIG_ARM
+
+#ifdef CONFIG_DMABOUNCE
+
+#include linux/dmapool.h
+#include linux/dma-mapping.h
+#include linux/list.h
+#include linux/types.h
+#include linux/device.h
+
+struct dmabounce_info;
+
+#ifdef CONFIG_DMABOUNCE_STATS
+struct dmabounce_stats {
+   unsigned long total_allocs;
+   unsigned long map_op_count;
+   unsigned long bounce_count;
+};
+extern struct dmabounce_stats *dmabounce_get_stats(struct dmabounce_info *);
+#define DMABOUNCE_DO_STATS(i, X) do { dmabounce_get_stats(i)-X ; } while (0)
+#else
+#define DMABOUNCE_DO_STATS(i, X) do { } while (0)
+#endif /* CONFIG_DMABOUNCE_STATS */
+
+struct dmabounce_pool {
+   unsigned long   size;
+   struct dma_pool *pool;
+#ifdef CONFIG_DMABOUNCE_STATS
+   unsigned long allocs;
+#endif
+};
+
+struct dmabounce_buffer {
+   struct list_head node;
+
+   /* original buffer */
+   void*buf;
+   size_t  size;
+   enum dma_data_direction dir;
+
+   /* bounced buffer */
+   void*bounce_buf;
+   dma_addr_t  bounce_buf_dma;
+
+   struct dmabounce_pool   *pool;
+};
+
+extern struct dmabounce_buffer *
+dmabounce_alloc_buffer(struct dmabounce_info *info,
+  void *buf, size_t size, enum dma_data_direction dir,
+  gfp_t gfp);
+extern void dmabounce_free_buffer(struct dmabounce_info *info,
+ struct dmabounce_buffer *bb);
+extern struct dmabounce_buffer *
+dmabounce_find_buffer(struct dmabounce_info *info, dma_addr_t bounce_buf_dma,
+ size_t size, enum dma_data_direction dir);
+
+extern struct dmabounce_info *
+dmabounce_info_alloc(struct device *dev,
+size_t small_buffer_size, size_t large_buffer_size,
+size_t align, size_t boundary);
+extern void dmabounce_info_free(struct dmabounce_info *info);
+
+extern int dmabounce_info_register(struct device *dev,
+  struct dmabounce_info *info);
+extern void dmabounce_info_unregister(struct device *dev);
+
+#endif /* CONFIG_DMABOUNCE */
+
+/* FIXME remove later when arch/arm/common/dmabounce.c is updated */
+#endif /* !CONFIG_ARM */
+
+#endif /* _LINUX_DMABOUNCE_H */
diff --git a/lib/Kconfig b/lib/Kconfig
index 97b136f..b53b7dc 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -207,4 +207,14 @@ config GENERIC_ATOMIC64
 config LRU_CACHE
tristate
 
+config DMABOUNCE
+   bool
+   depends on HAVE_DMABOUNCE
+   select ZONE_DMA if ARM
+   default y
+
+config DMABOUNCE_STATS
+   bool Track dmabounce statistics
+   depends on DMABOUNCE
+
 endmenu
diff --git a/lib/Makefile b/lib/Makefile
index 3b0b4a6..097c2ed 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -100,6 +100,8 @@ obj-$(CONFIG_GENERIC_CSUM) += checksum.o
 
 obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o
 
+obj-$(CONFIG_DMABOUNCE) += dmabounce.o
+
 hostprogs-y:= gen_crc32table
 clean-files:= crc32table.h
 
diff --git a/lib/dmabounce.c b/lib/dmabounce.c
new file mode 100644
index 000..620d314
--- /dev/null
+++ b/lib/dmabounce.c
@@ -0,0 +1,395 @@
+/*
+ * lib/dmabounce.c
+ *
+ * Generic DMA bounce buffer functions.
+ * Copyright (C) 2010 Albert Herranz albert_herr...@yahoo.es
+ *
+ * Based on arch/arm/common/dmabounce.c
+ *
+ * Original version by Brad Parker (b...@heeltoe.com)
+ * Re-written by Christopher Hoover c...@murgatroid.com
+ * Made generic by Deepak Saxena dsax...@plexity.net
+ *
+ * Copyright (C) 2002 Hewlett Packard Company.
+ * Copyright (C) 2004 MontaVista Software, Inc.
+ *
+ * This program is free software; you can

[RFC PATCH v2 5/9] arm: use generic dmabounce support

2010-02-28 Thread Albert Herranz
Update ARM dmabounce to use the generic dmabounce support.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/arm/Kconfig  |4 +-
 arch/arm/common/Kconfig   |6 +-
 arch/arm/common/dmabounce.c   |  376 +++-
 arch/arm/include/asm/device.h |2 +-
 include/linux/dmabounce.h |6 -
 lib/dmabounce.c   |6 -
 6 files changed, 70 insertions(+), 330 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 184a6bd..25fe1d0 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -417,7 +417,7 @@ config ARCH_IXP4XX
select GENERIC_GPIO
select GENERIC_TIME
select GENERIC_CLOCKEVENTS
-   select DMABOUNCE if PCI
+   select HAVE_DMABOUNCE if PCI
help
  Support for Intel's IXP4XX (XScale) family of processors.
 
@@ -974,7 +974,7 @@ config PCI_HOST_ITE8152
bool
depends on PCI  MACH_ARMCORE
default y
-   select DMABOUNCE
+   select HAVE_DMABOUNCE
 
 source drivers/pci/Kconfig
 
diff --git a/arch/arm/common/Kconfig b/arch/arm/common/Kconfig
index 4efbb9d..01869a5 100644
--- a/arch/arm/common/Kconfig
+++ b/arch/arm/common/Kconfig
@@ -20,11 +20,7 @@ config ICST307
 
 config SA
bool
-   select DMABOUNCE if !ARCH_PXA
-
-config DMABOUNCE
-   bool
-   select ZONE_DMA
+   select HAVE_DMABOUNCE if !ARCH_PXA
 
 config TIMER_ACORN
bool
diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c
index cc32c1e..a114ee1 100644
--- a/arch/arm/common/dmabounce.c
+++ b/arch/arm/common/dmabounce.c
@@ -31,203 +31,38 @@
 #include linux/dmapool.h
 #include linux/list.h
 #include linux/scatterlist.h
+#include linux/dmabounce.h
 
 #include asm/cacheflush.h
 
-#undef STATS
-
-#ifdef STATS
-#define DO_STATS(X) do { X ; } while (0)
-#else
-#define DO_STATS(X) do { } while (0)
-#endif
-
-/* ** */
-
-struct safe_buffer {
-   struct list_head node;
-
-   /* original request */
-   void*ptr;
-   size_t  size;
-   int direction;
-
-   /* safe buffer info */
-   struct dmabounce_pool *pool;
-   void*safe;
-   dma_addr_t  safe_dma_addr;
-};
-
-struct dmabounce_pool {
-   unsigned long   size;
-   struct dma_pool *pool;
-#ifdef STATS
-   unsigned long   allocs;
-#endif
-};
-
-struct dmabounce_device_info {
-   struct device *dev;
-   struct list_head safe_buffers;
-#ifdef STATS
-   unsigned long total_allocs;
-   unsigned long map_op_count;
-   unsigned long bounce_count;
-   int attr_res;
-#endif
-   struct dmabounce_pool   small;
-   struct dmabounce_pool   large;
-
-   rwlock_t lock;
-};
-
-#ifdef STATS
-static ssize_t dmabounce_show(struct device *dev, struct device_attribute 
*attr,
- char *buf)
-{
-   struct dmabounce_device_info *device_info = dev-archdata.dmabounce;
-   return sprintf(buf, %lu %lu %lu %lu %lu %lu\n,
-   device_info-small.allocs,
-   device_info-large.allocs,
-   device_info-total_allocs - device_info-small.allocs -
-   device_info-large.allocs,
-   device_info-total_allocs,
-   device_info-map_op_count,
-   device_info-bounce_count);
-}
-
-static DEVICE_ATTR(dmabounce_stats, 0400, dmabounce_show, NULL);
-#endif
-
-
-/* allocate a 'safe' buffer and keep track of it */
-static inline struct safe_buffer *
-alloc_safe_buffer(struct dmabounce_device_info *device_info, void *ptr,
- size_t size, enum dma_data_direction dir)
-{
-   struct safe_buffer *buf;
-   struct dmabounce_pool *pool;
-   struct device *dev = device_info-dev;
-   unsigned long flags;
-
-   dev_dbg(dev, %s(ptr=%p, size=%d, dir=%d)\n,
-   __func__, ptr, size, dir);
-
-   if (size = device_info-small.size) {
-   pool = device_info-small;
-   } else if (size = device_info-large.size) {
-   pool = device_info-large;
-   } else {
-   pool = NULL;
-   }
-
-   buf = kmalloc(sizeof(struct safe_buffer), GFP_ATOMIC);
-   if (buf == NULL) {
-   dev_warn(dev, %s: kmalloc failed\n, __func__);
-   return NULL;
-   }
-
-   buf-ptr = ptr;
-   buf-size = size;
-   buf-direction = dir;
-   buf-pool = pool;
-
-   if (pool) {
-   buf-safe = dma_pool_alloc(pool-pool, GFP_ATOMIC,
-  buf-safe_dma_addr);
-   } else {
-   buf-safe = dma_alloc_coherent(dev, size, buf-safe_dma_addr,
-  GFP_ATOMIC);
-   }
-
-   if (buf-safe == NULL) {
-   dev_warn(dev,
-%s: could not alloc dma memory (size=%d)\n,
-__func__, size);
-   kfree

[RFC PATCH v2 9/9] wii: hollywood ehci controller support

2010-02-28 Thread Albert Herranz
Add support for the USB Enhanced Host Controller Interface included
in the Hollywood chipset of the Nintendo Wii video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/Kconfig |1 +
 drivers/usb/host/Kconfig   |8 +
 drivers/usb/host/ehci-hcd.c|5 +
 drivers/usb/host/ehci-hlwd.c   |  233 
 drivers/usb/host/ehci.h|   23 +++
 5 files changed, 270 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/host/ehci-hlwd.c

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index 4d33755..0eb56a7 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -121,6 +121,7 @@ config WII
select GAMECUBE_COMMON
select HAVE_GENERIC_DMA_COHERENT
select HAVE_DMABOUNCE
+   select USB_ARCH_HAS_EHCI
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 2678a16..342954f 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -131,6 +131,14 @@ config USB_EHCI_HCD_PPC_OF
  Enables support for the USB controller present on the PowerPC
  OpenFirmware platform bus.
 
+config USB_EHCI_HCD_HLWD
+   bool Nintendo Wii (Hollywood) EHCI USB controller support
+   depends on USB_EHCI_HCD  WII
+   default y
+   ---help---
+ Say Y here to support the EHCI USB controller found in the
+ Hollywood chipset of the Nintendo Wii video game console.
+
 config USB_W90X900_EHCI
bool W90X900(W90P910) EHCI support
depends on USB_EHCI_HCD  ARCH_W90X900
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 1ec3857..395c6a1 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1133,6 +1133,11 @@ MODULE_LICENSE (GPL);
 #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_HCD_HLWD
+#include ehci-hlwd.c
+#define OF_PLATFORM_DRIVER ehci_hcd_hlwd_driver
+#endif
+
 #ifdef CONFIG_XPS_USB_HCD_XILINX
 #include ehci-xilinx-of.c
 #define OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
diff --git a/drivers/usb/host/ehci-hlwd.c b/drivers/usb/host/ehci-hlwd.c
new file mode 100644
index 000..129e96b
--- /dev/null
+++ b/drivers/usb/host/ehci-hlwd.c
@@ -0,0 +1,233 @@
+/*
+ * drivers/usb/host/ehci-hlwd.c
+ *
+ * Nintendo Wii (Hollywood) USB Enhanced Host Controller Interface.
+ * Copyright (C) 2009-2010 The GameCube Linux Team
+ * Copyright (C) 2009,2010 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.
+ *
+ * Based on ehci-ppc-of.c
+ *
+ * EHCI HCD (Host Controller Driver) for USB.
+ *
+ * Bus Glue for PPC On-Chip EHCI driver on the of_platform bus
+ * Tested on AMCC PPC 440EPx
+ *
+ * Valentine Barshak vbars...@ru.mvista.com
+ *
+ * Based on ehci-ppc-soc.c by Stefan Roese s...@denx.de
+ * and ohci-ppc-of.c by Sylvain Munaut t...@246tnt.com
+ *
+ * This file is licenced under the GPL.
+ */
+
+#include linux/signal.h
+#include linux/of.h
+#include linux/of_platform.h
+#include asm/wii.h
+
+#define DRV_MODULE_NAME ehci-hlwd
+#define DRV_DESCRIPTION Nintendo Wii EHCI Host Controller
+#define DRV_AUTHOR  Albert Herranz
+
+/*
+ * Non-standard registers.
+ */
+#define HLWD_EHCI_CTL  0x00cc  /* Controller Control */
+#define HLWD_EHCI_CTL_INTE (115) /* Notify EHCI interrupts */
+
+/* called during probe() after chip reset completes */
+static int ehci_hlwd_reset(struct usb_hcd *hcd)
+{
+   struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+   int error;
+
+   dbg_hcs_params(ehci, reset);
+   dbg_hcc_params(ehci, reset);
+
+   error = ehci_halt(ehci);
+   if (error)
+   goto out;
+
+   error = ehci_init(hcd);
+   if (error)
+   goto out;
+
+   /* enable notification of EHCI interrupts */
+   setbits32(hcd-regs + HLWD_EHCI_CTL, HLWD_EHCI_CTL_INTE);
+
+   ehci-sbrn = 0x20;
+   error = ehci_reset(ehci);
+   ehci_port_power(ehci, 0);
+out:
+   return error;
+}
+
+static const struct hc_driver ehci_hlwd_hc_driver = {
+   .description= hcd_name,
+   .product_desc   = Nintendo Wii EHCI Host Controller,
+   .hcd_priv_size  = sizeof(struct ehci_hcd),
+
+   /*
+* generic hardware linkage
+*/
+   .irq= ehci_irq,
+   .flags  = HCD_USB2 | HCD_NO_COHERENT_MEM,
+
+   /*
+* basic lifecycle operations
+*/
+   .reset  = ehci_hlwd_reset

Re: [RFC PATCH v2 4/9] add generic dmabounce support

2010-02-28 Thread Albert Herranz
Russell King - ARM Linux wrote:
 On Sun, Feb 28, 2010 at 03:07:57PM +0100, Albert Herranz wrote:
 This patch makes part of the ARM dmabounce code available to other
 architectures as a generic API.
 
 There is already a generic dma bounce implementation - it's called
 swiotlb - lib/swiotlb.c.  We should eventually switch the ARM
 dmabounce stuff over to that instead of keeping dmabounce around.
 
 The only problem I forsee is that on ARM, we have devices which can
 only address the least significant N bits of RAM, but there may be
 an offset on the base address of RAM on the bus which isn't included
 in these N bits.
 
 Even more fun is where we have a DMA controller which can address
 N bits of RAM, except for bit M which must be zero... (where N  M).
 

In the Wii we have several limitations:
- it is a NOT_COHERENT_CACHE platform
- write accesses to coherent memory from the main processor must be done always 
in 32-bit chunks
- some devices can only reliably perform DMA to/from a specific region of 
memory (the second block of RAM, 64MB at 0x1000, called MEM2)

So if swiotlb is the way to go I can try to adapt it to take into account these 
cases:
- it should allocate the io_tlb_start and io_tlb_overflow_buffer areas from 
MEM2 (add allocation/freeing hooks for these areas?)
- it should copy data from coherent memory in 32-bit chunks (add copy to/from 
coherent hooks?)
- it should decide to bounce buffers sitting in MEM1 (add a dma_needs_bounce() 
hook?)

Thanks,
Albert
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH 1/2] USB: add HCD_BOUNCE_BUFFERS host controller driver flag

2010-02-07 Thread Albert Herranz
Alan Stern wrote:
On a 64-bit processor, some of the accesses will be 64 bits wide
instead of 32.  Does that matter for your purposes?


The wii uses a 32-bit processor, so this is safe in this case.

What about ohci-hcd and uhci-hcd?  They both use non-32-bit accesses to 
structures in coherent memory.


The wii has no uhci, but has 2 ohci controllers.
For ohci we need a similar approach as done for ehci.

If you do it as described above then the buffers you're worried about
won't be allocated in coherent memory to begin with, so no problems 
will arise.

It turns out that we have more limitations.
The wii has 2 discontiguous memory areas (usually called MEM1 and MEM2). I have 
checked that the ehci controller doesn't work properly when performing dma to 
buffers allocated in MEM1 (it corrupts part of the data) but has no problems if 
the buffers sit within MEM2.
So usb buffers will need to be bounced anyway if they are part of MEM1.

This worked in the original patch as buffers were always bounced to MEM2 
buffers. Sigh.

Alan Stern


Thanks,
Albert

PS: Your reply didn't get to me. I looked at the ML and found it (I'm not 
subscribed). Sorry for the late answer.
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH 1/2] USB: add HCD_BOUNCE_BUFFERS host controller driver flag

2010-02-07 Thread Albert Herranz
Alan Stern wrote:
 On Sun, 7 Feb 2010, Albert Herranz wrote:
 
 The wii has no uhci, but has 2 ohci controllers.
 For ohci we need a similar approach as done for ehci.
 
 So you'll need to write a patch splitting up the OHCI data structures 
 in the same way the EHCI qh was split up.
 

Yes.

 It turns out that we have more limitations.
 The wii has 2 discontiguous memory areas (usually called MEM1 and MEM2). I 
 have checked that the ehci controller doesn't work properly when performing 
 dma to buffers allocated in MEM1 (it corrupts part of the data) but has no 
 problems if the buffers sit within MEM2.
 So usb buffers will need to be bounced anyway if they are part of MEM1.
 
 This sounds like the sort of restriction that dma_map_single() should 
 be capable of handling.
 

On powerpc you can have per-device specific dma ops.
I'll work on that direction and create a special dma ops set for devices which 
need their dma buffers on mem2, and then use those for ehci-hlwd.

 Alan Stern
 

Thanks,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH 1/2] USB: add HCD_BOUNCE_BUFFERS host controller driver flag

2010-02-04 Thread Albert Herranz
Hi Alan,

Alan Stern wrote:
 This description sounds hopelessly confused.  Maybe you're just
 misusing the term coherent.  The patch itself doesn't affect the
 coherent DMA mappings anyway; it affects the streaming mappings.  Or to
 put it another way, what's the justification for replacing a call to
 dma_map_single() with a call to dma_alloc_coherent()?
 
 Since the patch doesn't affect any of the coherent mappings (see for 
 example the calls to dma_pool_create() in ehci-mem.c), I don't see how 
 it can possibly do what you claim.
 

Thanks for your comments. Let's try to hopefully clarify this a bit.

I've used the term coherent as described in Documentation/DMA-API.txt (aka 
consistent as used in PCI-related functions).
I've tried to describe first the limitations of the platform that I'm working 
on. Basically, one of the annoying things of that platform is that writes to 
uncached memory (as used in coherent memory) can only be reliably performed 
in 32-bit accesses.

The USB subsystem ends up using coherent memory for buffers and/or other 
structures in different ways.

The coherent memory allocated in dma_pool_create() in ehci-mem.c that you 
report is not a problem at all because it is always accessed in 32-bit chunks 
(it hasn't been always like that but since commit 
3807e26d69b9ad3864fe03224ebebc9610d5802e USB: EHCI: split ehci_qh into hw and 
sw parts this got addressed as a side effect, so I didn't need to post another 
patch for that).

Other possible interactions with coherent memory are those involving buffers 
used in USB transactions, which may be allocated via the USB subsystem (at 
usb_buffer_alloc() or when bounced via hcd_alloc_coherent()) or which may come 
already allocated and ready for use (URB_NO_{SETUP,TRANSFER}_DMA_MAP).

The patch, as posted, allocates normal memory for USB buffers _within_ the USB 
subsystem and invariably bounces all buffers to new coherent buffers.
So, basically, what the patch claims (avoid 32-bit writes for coherent memory 
within the USB subsystem) is done (hey, it actually works ;-).

But I think you have raised valid points here :)

If the coherent memory is already allocated and passed (as already 
dma-mapped) to the USB subsystem then there is no gain in bouncing the buffer:
- if a non-32 bit write was done to that coherent memory the damage is 
already done
- if the coherent memory was written always in 32-bit accesses then we can 
just safely use it
So bouncing here should be avoided as it is unneeded.

On the other hand, we can control USB buffers managed by the USB subsystem 
itself.
That's what the patch does. It avoids access restrictions to USB buffers by 
allocating them from normal memory (leaving USB drivers free to access those 
buffers in whatever bus width they need, as they do today) ... and bouncing 
them.
The thing here is that it makes no sense to bounce them to coherent memory if 
they can be dma-mapped directly (as you point in your 
dma_map_single-vs-dma_alloc_coherent comment).

So... that's what RFCs are for :)
I'll take a look again at the patch.

 +/**
 + * hcd_memcpy32_to_coherent - copy data to a bounce buffer
 + * @dst: destination dma bounce buffer
 + * @src: source buffer
 + * @len: number of bytes to copy
 + *
 + * This function copies @len bytes from @src to @dst in 32 bit chunks.
 + * The caller must guarantee that @dst length is 4 byte aligned and
 + * that @dst length is greater than or equal to @src length.
 + */
 +static void *hcd_memcpy32_to_coherent(void *dst, const void *src, size_t 
 len)
 +{
 +u32 *q = dst, *p = (void *)src;
 +u8 *s;
 +
 +while (len = 4) {
 +*q++ = *p++;
 +len -= 4;
 +}
 +s = (u8 *)p;
 +switch (len) {
 +case 3:
 +*q = s[0]  24 | s[1]  16 | s[2]  8;
 +break;
 +case 2:
 +*q = s[0]  24 | s[1]  16;
 +break;
 +case 1:
 +*q = s[0]  24;
 +break;
 +default:
 +break;
 +}
 +return dst;
 +}
 
 What happens if somebody tries to use this code on a little-endian CPU?
 

It will fail.


 It seems that every time somebody comes up with a new kind of 
 memory-access restriction, this function grows by a factor of 2.  After 
 a few more iterations it will be larger than the rest of the kernel!
 
 There must be a better way to structure the requirements here.
 

Hopefully I didn't miss any of your concerns and managed to explain the problem.

 Alan Stern
 
 

Thanks,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH 0/2] wii: add usb 2.0 support

2010-02-03 Thread Albert Herranz
The following patch series adds USB 2.0 support for the Wii powerpc
platform via the EHCI controller present in the Hollywood chipset
of the video game console.

Albert Herranz (2):
  USB: add HCD_BOUNCE_BUFFERS host controller driver flag
  wii: hollywood ehci controller support

 arch/powerpc/platforms/embedded6xx/Kconfig |1 +
 drivers/usb/core/hcd.c |  337 +++-
 drivers/usb/core/hcd.h |   13 +-
 drivers/usb/host/Kconfig   |8 +
 drivers/usb/host/ehci-hcd.c|5 +
 drivers/usb/host/ehci-hlwd.c   |  227 +++
 drivers/usb/host/ehci.h|   23 ++
 7 files changed, 550 insertions(+), 64 deletions(-)
 create mode 100644 drivers/usb/host/ehci-hlwd.c

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH 1/2] USB: add HCD_BOUNCE_BUFFERS host controller driver flag

2010-02-03 Thread Albert Herranz
The HCD_BOUNCE_BUFFERS USB host controller driver flag can be enabled
to instruct the USB stack to always bounce USB buffers to/from coherent
memory buffers _just_ before/after a host controller transmission.

This setting allows overcoming some platform-specific limitations.

For example, the Nintendo Wii video game console is a NOT_COHERENT_CACHE
platform that is unable to safely perform non-32 bit uncached writes
to RAM because the byte enables are not connected to the bus.
Thus, in that platform, coherent DMA buffers cannot be directly used
by the kernel code unless it guarantees that all write accesses
to said buffers are done in 32 bit chunks (which is not the case in the
USB subsystem).

To avoid this unwanted behaviour HCD_BOUNCE_BUFFERS can be enabled at
the HCD controller, causing buffer allocations to be satisfied from
normal memory and, only at the very last moment, before the actual
transfer, buffers get copied to/from their corresponding DMA coherent
bounce buffers.

Note that HCD_LOCAL_MEM doesn't help in solving this problem as in that
case buffers may be allocated from coherent memory in the first place
and thus potentially accessed in non-32 bit chuncks by USB drivers.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 drivers/usb/core/hcd.c |  337 +++
 drivers/usb/core/hcd.h |   13 +-
 2 files changed, 286 insertions(+), 64 deletions(-)

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 80995ef..befca85 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1260,6 +1260,173 @@ static void hcd_free_coherent(struct usb_bus *bus, 
dma_addr_t *dma_handle,
*dma_handle = 0;
 }
 
+/*
+ * The HCD_BOUNCE_BUFFERS USB host controller driver flag can be enabled
+ * to instruct the USB stack to always bounce USB buffers to/from coherent
+ * memory buffers _just_ before/after a host controller transmission.
+ *
+ * This setting allows overcoming some platform-specific limitations.
+ *
+ * For example, the Nintendo Wii video game console is a NOT_COHERENT_CACHE
+ * platform that is unable to safely perform non-32 bit uncached writes
+ * to RAM because the byte enables are not connected to the bus.
+ * Thus, in that platform, coherent DMA buffers cannot be directly used
+ * by the kernel code unless it guarantees that all write accesses
+ * to said buffers are done in 32 bit chunks (which is not the case in the
+ * USB subsystem).
+ *
+ * To avoid this unwanted behaviour HCD_BOUNCE_BUFFERS can be enabled at
+ * the HCD controller, causing buffer allocations to be satisfied from
+ * normal memory and, only at the very last moment, before the actual
+ * transfer, buffers get copied to/from their corresponding DMA coherent
+ * bounce buffers.
+ *
+ * Note that HCD_LOCAL_MEM doesn't help in solving this problem as in that
+ * case buffers may be allocated from coherent memory in the first place
+ * and thus potentially accessed in non-32 bit chuncks by USB drivers.
+ *
+ */
+
+#define HCD_BOUNCE_ALIGN   4
+
+#define hcd_align_up(addr, size)   (((addr)+((size)-1))(~((size)-1)))
+
+struct hcd_coherent_buffer_ctx {
+   unsigned char *vaddr;
+   dma_addr_t dma_handle;
+};
+
+/**
+ * hcd_memcpy32_to_coherent - copy data to a bounce buffer
+ * @dst: destination dma bounce buffer
+ * @src: source buffer
+ * @len: number of bytes to copy
+ *
+ * This function copies @len bytes from @src to @dst in 32 bit chunks.
+ * The caller must guarantee that @dst length is 4 byte aligned and
+ * that @dst length is greater than or equal to @src length.
+ */
+static void *hcd_memcpy32_to_coherent(void *dst, const void *src, size_t len)
+{
+   u32 *q = dst, *p = (void *)src;
+   u8 *s;
+
+   while (len = 4) {
+   *q++ = *p++;
+   len -= 4;
+   }
+   s = (u8 *)p;
+   switch (len) {
+   case 3:
+   *q = s[0]  24 | s[1]  16 | s[2]  8;
+   break;
+   case 2:
+   *q = s[0]  24 | s[1]  16;
+   break;
+   case 1:
+   *q = s[0]  24;
+   break;
+   default:
+   break;
+   }
+   return dst;
+}
+
+/**
+ * hcd_memcpy32_from_coherent - copy data from a bounce buffer
+ * @dst: destination buffer
+ * @src: source dma bounce buffer
+ * @len: number of bytes to copy
+ *
+ * This function copies @len bytes from @src to @dst in 32 bit chunks.
+ * The caller must guarantee that @src length is 4 byte aligned and
+ * that @src length is greater than or equal to @dst length.
+ */
+static void *hcd_memcpy32_from_coherent(void *dst, const void *src, size_t len)
+{
+   u32 *q = dst, *p = (void *)src;
+   u32 v;
+   u8 *d;
+
+   while (len = 4) {
+   *q++ = *p++;
+   len -= 4;
+   }
+   if (len) {
+   d = (u8 *)q;
+   v = p[0];
+   switch (len) {
+   case 3:
+   d[2] = (v  8)  0xff

[RFC PATCH 2/2] wii: hollywood ehci controller support

2010-02-03 Thread Albert Herranz
Add support for the USB Enhanced Host Controller Interface included
in the Hollywood chipset of the Nintendo Wii video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/Kconfig |1 +
 drivers/usb/host/Kconfig   |8 +
 drivers/usb/host/ehci-hcd.c|5 +
 drivers/usb/host/ehci-hlwd.c   |  227 
 drivers/usb/host/ehci.h|   23 +++
 5 files changed, 264 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/host/ehci-hlwd.c

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index 524d971..34dbb79 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -119,6 +119,7 @@ config WII
bool Nintendo-Wii
depends on EMBEDDED6xx
select GAMECUBE_COMMON
+   select USB_ARCH_HAS_EHCI
help
  Select WII if configuring for the Nintendo Wii.
  More information at: http://gc-linux.sourceforge.net/
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 2678a16..342954f 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -131,6 +131,14 @@ config USB_EHCI_HCD_PPC_OF
  Enables support for the USB controller present on the PowerPC
  OpenFirmware platform bus.
 
+config USB_EHCI_HCD_HLWD
+   bool Nintendo Wii (Hollywood) EHCI USB controller support
+   depends on USB_EHCI_HCD  WII
+   default y
+   ---help---
+ Say Y here to support the EHCI USB controller found in the
+ Hollywood chipset of the Nintendo Wii video game console.
+
 config USB_W90X900_EHCI
bool W90X900(W90P910) EHCI support
depends on USB_EHCI_HCD  ARCH_W90X900
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 1ec3857..395c6a1 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1133,6 +1133,11 @@ MODULE_LICENSE (GPL);
 #define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
 #endif
 
+#ifdef CONFIG_USB_EHCI_HCD_HLWD
+#include ehci-hlwd.c
+#define OF_PLATFORM_DRIVER ehci_hcd_hlwd_driver
+#endif
+
 #ifdef CONFIG_XPS_USB_HCD_XILINX
 #include ehci-xilinx-of.c
 #define OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
diff --git a/drivers/usb/host/ehci-hlwd.c b/drivers/usb/host/ehci-hlwd.c
new file mode 100644
index 000..19812db
--- /dev/null
+++ b/drivers/usb/host/ehci-hlwd.c
@@ -0,0 +1,227 @@
+/*
+ * drivers/usb/host/ehci-hlwd.c
+ *
+ * Nintendo Wii (Hollywood) USB Enhanced Host Controller Interface.
+ * Copyright (C) 2009-2010 The GameCube Linux Team
+ * Copyright (C) 2009,2010 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.
+ *
+ * Based on ehci-ppc-of.c
+ *
+ * EHCI HCD (Host Controller Driver) for USB.
+ *
+ * Bus Glue for PPC On-Chip EHCI driver on the of_platform bus
+ * Tested on AMCC PPC 440EPx
+ *
+ * Valentine Barshak vbars...@ru.mvista.com
+ *
+ * Based on ehci-ppc-soc.c by Stefan Roese s...@denx.de
+ * and ohci-ppc-of.c by Sylvain Munaut t...@246tnt.com
+ *
+ * This file is licenced under the GPL.
+ */
+
+#include linux/signal.h
+#include linux/of.h
+#include linux/of_platform.h
+
+#define DRV_MODULE_NAME ehci-hlwd
+#define DRV_DESCRIPTION Nintendo Wii EHCI Host Controller
+#define DRV_AUTHOR  Albert Herranz
+
+/*
+ * Non-standard registers.
+ */
+#define HLWD_EHCI_CTL  0x00cc  /* Controller Control */
+#define HLWD_EHCI_CTL_INTE (115) /* Notify EHCI interrupts */
+
+/* called during probe() after chip reset completes */
+static int ehci_hlwd_reset(struct usb_hcd *hcd)
+{
+   struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+   int error;
+
+   dbg_hcs_params(ehci, reset);
+   dbg_hcc_params(ehci, reset);
+
+   error = ehci_halt(ehci);
+   if (error)
+   goto out;
+
+   error = ehci_init(hcd);
+   if (error)
+   goto out;
+   hcd-self.sg_tablesize = 0;
+
+   /* enable notification of EHCI interrupts */
+   setbits32(hcd-regs + HLWD_EHCI_CTL, HLWD_EHCI_CTL_INTE);
+
+   ehci-sbrn = 0x20;
+   error = ehci_reset(ehci);
+   ehci_port_power(ehci, 0);
+out:
+   return error;
+}
+
+static const struct hc_driver ehci_hlwd_hc_driver = {
+   .description= hcd_name,
+   .product_desc   = Nintendo Wii EHCI Host Controller,
+   .hcd_priv_size  = sizeof(struct ehci_hcd),
+
+   /*
+* generic hardware linkage
+*/
+   .irq= ehci_irq,
+   .flags  = HCD_USB2 | HCD_BOUNCE_BUFFERS,
+
+   /*
+* basic lifecycle operations
+*/
+   .reset  = ehci_hlwd_reset

[PATCH v2.6.33] powerpc: flipper-pic/hlwd-pic: remove get_irq_desc()

2009-12-18 Thread Albert Herranz
Fix the following build failures:

arch/powerpc/platforms/embedded6xx/flipper-pic.c: In function 'flipper_pic_map':
arch/powerpc/platforms/embedded6xx/flipper-pic.c:105: error: implicit 
declaration of function 'get_irq_desc'

arch/powerpc/platforms/embedded6xx/hlwd-pic.c: In function 'hlwd_pic_map':
arch/powerpc/platforms/embedded6xx/hlwd-pic.c:98: error: implicit declaration 
of function 'get_irq_desc'

These failures are caused by the changes introduced in commit
powerpc: Remove get_irq_desc(). The reason these drivers were not
updated is that they weren't merged yet.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/flipper-pic.c |2 +-
 arch/powerpc/platforms/embedded6xx/hlwd-pic.c|2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/flipper-pic.c 
b/arch/powerpc/platforms/embedded6xx/flipper-pic.c
index d596328..c278bd3 100644
--- a/arch/powerpc/platforms/embedded6xx/flipper-pic.c
+++ b/arch/powerpc/platforms/embedded6xx/flipper-pic.c
@@ -102,7 +102,7 @@ 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;
+   irq_to_desc(virq)-status |= IRQ_LEVEL;
set_irq_chip_and_handler(virq, flipper_pic, handle_level_irq);
return 0;
 }
diff --git a/arch/powerpc/platforms/embedded6xx/hlwd-pic.c 
b/arch/powerpc/platforms/embedded6xx/hlwd-pic.c
index dd20bff..fe0ff06 100644
--- a/arch/powerpc/platforms/embedded6xx/hlwd-pic.c
+++ b/arch/powerpc/platforms/embedded6xx/hlwd-pic.c
@@ -95,7 +95,7 @@ static int hlwd_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;
+   irq_to_desc(virq)-status |= IRQ_LEVEL;
set_irq_chip_and_handler(virq, hlwd_pic, handle_level_irq);
return 0;
 }
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v2.6.33] powerpc: hlwd-pic: convert irq_desc.lock to raw_spinlock

2009-12-18 Thread Albert Herranz
Fix the following build failures:

arch/powerpc/platforms/embedded6xx/hlwd-pic.c: In function 
'hlwd_pic_irq_cascade':
arch/powerpc/platforms/embedded6xx/hlwd-pic.c:135: error: passing argument 1 of 
'spin_lock' from incompatible pointer type
arch/powerpc/platforms/embedded6xx/hlwd-pic.c:137: error: passing argument 1 of 
'spin_unlock' from incompatible pointer type
arch/powerpc/platforms/embedded6xx/hlwd-pic.c:145: error: passing argument 1 of 
'spin_lock' from incompatible pointer type
arch/powerpc/platforms/embedded6xx/hlwd-pic.c:149: error: passing argument 1 of 
'spin_unlock' from incompatible pointer type

These failures are caused by the changes introduced in commit
genirq: Convert irq_desc.lock to raw_spinlock. The reason this driver
was not updated is that it wasn't merged yet.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/hlwd-pic.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/hlwd-pic.c 
b/arch/powerpc/platforms/embedded6xx/hlwd-pic.c
index fe0ff06..a771f91 100644
--- a/arch/powerpc/platforms/embedded6xx/hlwd-pic.c
+++ b/arch/powerpc/platforms/embedded6xx/hlwd-pic.c
@@ -132,9 +132,9 @@ static void hlwd_pic_irq_cascade(unsigned int cascade_virq,
struct irq_host *irq_host = get_irq_data(cascade_virq);
unsigned int virq;
 
-   spin_lock(desc-lock);
+   raw_spin_lock(desc-lock);
desc-chip-mask(cascade_virq); /* IRQ_LEVEL */
-   spin_unlock(desc-lock);
+   raw_spin_unlock(desc-lock);
 
virq = __hlwd_pic_get_irq(irq_host);
if (virq != NO_IRQ)
@@ -142,11 +142,11 @@ static void hlwd_pic_irq_cascade(unsigned int 
cascade_virq,
else
pr_err(spurious interrupt!\n);
 
-   spin_lock(desc-lock);
+   raw_spin_lock(desc-lock);
desc-chip-ack(cascade_virq); /* IRQ_LEVEL */
if (!(desc-status  IRQ_DISABLED)  desc-chip-unmask)
desc-chip-unmask(cascade_virq);
-   spin_unlock(desc-lock);
+   raw_spin_unlock(desc-lock);
 }
 
 /*
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH] powerpc: gamecube/wii: fix off-by-one error in ugecon/usbgecko_udbg

2009-12-17 Thread Albert Herranz
The retry logic in ug_putc() is broken.

If the TX fifo is not ready and the counter runs out it will have a
value of -1 and no transfer should be attempted. Also, a counter
with a value of 0 means that the TX fifo got ready in the last try
and the transfer should be attempted.

Reported-by: Juha Leppanen juha_motorsport...@luukku.com
Signed-off-by: Juha Leppanen juha_motorsport...@luukku.com
Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/boot/ugecon.c |2 +-
 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/boot/ugecon.c b/arch/powerpc/boot/ugecon.c
index 50609ea..8f2a6b3 100644
--- a/arch/powerpc/boot/ugecon.c
+++ b/arch/powerpc/boot/ugecon.c
@@ -86,7 +86,7 @@ static void ug_putc(char ch)
 
while (!ug_is_txfifo_ready()  count--)
barrier();
-   if (count)
+   if (count = 0)
ug_raw_putc(ch);
 }
 
diff --git a/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c 
b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
index edc956c..20a8ed9 100644
--- a/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
+++ b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
@@ -120,7 +120,7 @@ static void ug_putc(char ch)
 
while (!ug_is_txfifo_ready()  count--)
barrier();
-   if (count)
+   if (count = 0)
ug_raw_putc(ch);
 }
 
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH v2 0/6] powerpc: nintendo wii support

2009-12-12 Thread Albert Herranz
Grant Likely wrote:
 On Fri, Dec 11, 2009 at 5:18 PM, Albert Herranz albert_herr...@yahoo.es 
 wrote:
 Grant Likely wrote:
 Hi Albert.

 Hi,

 I'm ready to pick up your Gamecube and Wii patch sets for merging.
 You seem to have 4 distinct patch sets.  What order do they need to be
 applied in, and what kernel version are they based on?

 The patches were based on 2.6.32-rc8.
 The apply order should be:

 v2 powerpc: nintendo gamecube support
  powerpc: gamecube/wii: usbgecko bootwrapper console support
  powerpc: gamecube: device tree
  powerpc: gamecube: bootwrapper bits
  powerpc: gamecube/wii: introduce GAMECUBE_COMMON
  powerpc: gamecube/wii: declare as non-coherent platforms
  powerpc: gamecube/wii: do not include PCI support
  powerpc: gamecube/wii: udbg support for usbgecko
  powerpc: gamecube/wii: flipper interrupt controller support
  powerpc: gamecube: platform support
  powerpc: gamecube: default config

 v2 powerpc: nintendo wii support
  powerpc: wii: device tree
  powerpc: wii: bootwrapper bits
  powerpc: broadway processor support
  powerpc: wii: hollywood interrupt controller support
  powerpc: wii: platform support
  powerpc: wii: default config

 v4 rework of usbgecko-based early debug
  powerpc: reserve fixmap entries for early debug
  powerpc: gamecube/wii: early debugging using usbgecko

 v2 powerpc: wii: mem2 as ram support
  wii: bootwrapper: add fixup to calc useable mem2
  wii: use both mem1 and mem2 as ram
  powerpc: allow ioremap within reserved memory regions
  powerpc: wii: allow ioremap within the memory hole

 But if you prefer it, I can re-send them as one patch set again rebased on 
 top of v2.6.32.
 
 Hmmm..  Looks like there are some inconsistencies in here.  For
 example, the 7th patch of the first series, and the 2nd patch of the
 3rd series are different version of the same thing.  The whole thing
 doesn't apply as is.  Reposting the current state of the whole series
 would help.  Add any acked-by lines that you've received from Ben,
 Segher, or anybody else before you repost so I can see the full
 current state.
 

The 7th patch of the first series is normal udbg support.
The 2nd patch of the third series is early udbg support.

I'll repost the whole series later adding the Acked-by lines. I'll send them as 
PATCH v2 (not RFC PATCH).

I'll add a minor correction for powerpc: gamecube/wii: early debugging using 
usbgecko suggested by Segher (use Vp=0 instead of Vp=1 in the early mapping).
And code to powerpc: wii: platform support to turn off the front blue led and 
sensor bar on boot.

 Thanks
 g.
 

Thanks,
Albert

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v2 00/22] powerpc: nintendo gamecube and wii support

2009-12-12 Thread Albert Herranz
The following patches add the base support for the Nintendo GameCube
and Wii video game consoles on the powerpc arch.

For each video game console, the following is included:
- a device tree source
- bootwrapper support
- udbg console option
- early udbg console option
- interrupt controller support
- platform support

The Nintendo Wii patches also include support for:
- recognition of the broadway processor
- workarounds to enable the use of the second discontiguous RAM block

With these patches both video game consoles can fully boot up to the
root filesystem mount phase.

Albert Herranz (22):
  powerpc: gamecube/wii: usbgecko bootwrapper console support
  powerpc: gamecube: device tree
  powerpc: gamecube: bootwrapper bits
  powerpc: gamecube/wii: introduce GAMECUBE_COMMON
  powerpc: gamecube/wii: declare as non-coherent platforms
  powerpc: gamecube/wii: do not include PCI support
  powerpc: gamecube/wii: udbg support for usbgecko
  powerpc: gamecube/wii: flipper interrupt controller support
  powerpc: gamecube: platform support
  powerpc: gamecube: default config
  powerpc: wii: device tree
  powerpc: wii: bootwrapper bits
  powerpc: broadway processor support
  powerpc: wii: hollywood interrupt controller support
  powerpc: wii: platform support
  powerpc: wii: default config
  powerpc: reserve fixmap entries for early debug
  powerpc: gamecube/wii: early debugging using usbgecko
  wii: bootwrapper: add fixup to calc useable mem2
  wii: use both mem1 and mem2 as ram
  powerpc: allow ioremap within reserved memory regions
  powerpc: wii: allow ioremap within the memory hole

 .../powerpc/dts-bindings/nintendo/gamecube.txt |  109 ++
 .../powerpc/dts-bindings/nintendo/wii.txt  |  184 +++
 arch/powerpc/Kconfig   |2 +-
 arch/powerpc/Kconfig.debug |8 +
 arch/powerpc/boot/Makefile |7 +-
 arch/powerpc/boot/dts/gamecube.dts |  114 ++
 arch/powerpc/boot/dts/wii.dts  |  218 +++
 arch/powerpc/boot/gamecube-head.S  |  111 ++
 arch/powerpc/boot/gamecube.c   |   35 +
 arch/powerpc/boot/ugecon.c |  147 ++
 arch/powerpc/boot/ugecon.h |   24 +
 arch/powerpc/boot/wii-head.S   |  142 ++
 arch/powerpc/boot/wii.c|  158 +++
 arch/powerpc/boot/wrapper  |4 +
 arch/powerpc/configs/gamecube_defconfig| 1061 +++
 arch/powerpc/configs/wii_defconfig | 1406 
 arch/powerpc/include/asm/fixmap.h  |3 +
 arch/powerpc/include/asm/udbg.h|1 +
 arch/powerpc/kernel/cputable.c |6 +-
 arch/powerpc/kernel/head_32.S  |   25 +
 arch/powerpc/kernel/udbg.c |2 +
 arch/powerpc/mm/init_32.c  |9 +
 arch/powerpc/mm/mmu_decl.h |   11 +-
 arch/powerpc/mm/pgtable_32.c   |   36 +-
 arch/powerpc/mm/ppc_mmu_32.c   |4 +-
 arch/powerpc/platforms/Kconfig.cputype |2 +-
 arch/powerpc/platforms/embedded6xx/Kconfig |   33 +
 arch/powerpc/platforms/embedded6xx/Makefile|4 +
 arch/powerpc/platforms/embedded6xx/flipper-pic.c   |  263 
 arch/powerpc/platforms/embedded6xx/flipper-pic.h   |   25 +
 arch/powerpc/platforms/embedded6xx/gamecube.c  |  118 ++
 arch/powerpc/platforms/embedded6xx/hlwd-pic.c  |  241 
 arch/powerpc/platforms/embedded6xx/hlwd-pic.h  |   22 +
 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c |  328 +
 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h |   32 +
 arch/powerpc/platforms/embedded6xx/wii.c   |  268 
 include/linux/lmb.h|1 +
 lib/lmb.c  |7 +-
 38 files changed, 5155 insertions(+), 16 deletions(-)
 create mode 100644 Documentation/powerpc/dts-bindings/nintendo/gamecube.txt
 create mode 100644 Documentation/powerpc/dts-bindings/nintendo/wii.txt
 create mode 100644 arch/powerpc/boot/dts/gamecube.dts
 create mode 100644 arch/powerpc/boot/dts/wii.dts
 create mode 100644 arch/powerpc/boot/gamecube-head.S
 create mode 100644 arch/powerpc/boot/gamecube.c
 create mode 100644 arch/powerpc/boot/ugecon.c
 create mode 100644 arch/powerpc/boot/ugecon.h
 create mode 100644 arch/powerpc/boot/wii-head.S
 create mode 100644 arch/powerpc/boot/wii.c
 create mode 100644 arch/powerpc/configs/gamecube_defconfig
 create mode 100644 arch/powerpc/configs/wii_defconfig
 create mode 100644 arch/powerpc/platforms/embedded6xx/flipper-pic.c
 create mode 100644 arch/powerpc/platforms/embedded6xx/flipper-pic.h
 create mode 100644 arch/powerpc/platforms/embedded6xx/gamecube.c
 create mode 100644 arch/powerpc/platforms/embedded6xx/hlwd-pic.c
 create mode 100644

[PATCH v2 02/22] powerpc: gamecube: device tree

2009-12-12 Thread Albert Herranz
Add a device tree source file for the Nintendo GameCube video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Segher Boessenkool seg...@kernel.crashing.org
---
 .../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 000..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 000..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

[PATCH v2 01/22] powerpc: gamecube/wii: usbgecko bootwrapper console support

2009-12-12 Thread Albert Herranz
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_herr...@yahoo.es
Acked-by: Segher Boessenkool seg...@kernel.crashing.org
---
 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 000..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   (0x74)
+#define EXI_CSR_CLK_32MHZ   (EXI_CLK_32MHZ4)
+#define   EXI_CSR_CSMASK(0x77)
+#define EXI_CSR_CS_0(0x17)  /* Chip Select 001 */
+
+#define EXI_CR  0x0c
+#define   EXI_CR_TSTART (10)
+#define   EXI_CR_WRITE (12)
+#define   EXI_CR_READ_WRITE (22)
+#define   EXI_CR_TLEN(len)  (((len)-1)4)
+
+#define EXI_DATA0x10
+
+
+/* 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(0xc000)  0x0400;
+}
+
+static void ug_raw_putc(char ch)
+{
+   ug_io_transaction(0xb000 | (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(0x9000) == 0x0470;
+}
+
+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

[PATCH v2 03/22] powerpc: gamecube: bootwrapper bits

2009-12-12 Thread Albert Herranz
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_herr...@yahoo.es
Acked-by: Segher Boessenkool seg...@kernel.crashing.org
---
 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 000..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, ~((14)|(15)) /* MSR_DR|MSR_IR */
+   bcl 20, 31, 1f
+1:
+   mflr8
+   clrlwi  8, 8, 3 /* convert to a real address */
+   addi8, 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, (115)   /* HID0_ICE */
+   bne 1f
+   ori 8, 8, (115)|(111)   /* HID0_ICE|HID0_ICFI*/
+1:
+   andi.   0, 8, (114)   /* HID0_DCE */
+   bne 1f
+   ori 8, 8, (114)|(110)   /* HID0_DCE|HID0_DCFI*/
+1

[PATCH v2 04/22] powerpc: gamecube/wii: introduce GAMECUBE_COMMON

2009-12-12 Thread Albert Herranz
Add a config option GAMECUBE_COMMON to be used as a dependency for all
options common to the Nintendo GameCube and Wii video game consoles.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Grant Likely grant.lik...@secretlab.ca
---
 arch/powerpc/platforms/embedded6xx/Kconfig |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index 291ac9d..97a2dbc 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -90,3 +90,7 @@ config MPC10X_OPENPIC
 config MPC10X_STORE_GATHERING
bool Enable MPC10x store gathering
depends on MPC10X_BRIDGE
+
+config GAMECUBE_COMMON
+   bool
+
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v2 05/22] powerpc: gamecube/wii: declare as non-coherent platforms

2009-12-12 Thread Albert Herranz
The processors bundled in the Nintendo GameCube and Wii video game consoles
require explicit cache handling when DMA engines are used.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/Kconfig.cputype |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/platforms/Kconfig.cputype 
b/arch/powerpc/platforms/Kconfig.cputype
index e382cae..80d934b 100644
--- a/arch/powerpc/platforms/Kconfig.cputype
+++ b/arch/powerpc/platforms/Kconfig.cputype
@@ -312,7 +312,7 @@ config NR_CPUS
 
 config NOT_COHERENT_CACHE
bool
-   depends on 4xx || 8xx || E200 || PPC_MPC512x
+   depends on 4xx || 8xx || E200 || PPC_MPC512x || GAMECUBE_COMMON
default y
 
 config CHECK_CACHE_COHERENCY
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v2 06/22] powerpc: gamecube/wii: do not include PCI support

2009-12-12 Thread Albert Herranz
The Nintendo GameCube and Wii video game consoles do not have PCI hardware.
Avoid wasting their scarce memory by not including PCI support into the
kernel.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Grant Likely grant.lik...@secretlab.ca
---
 arch/powerpc/Kconfig |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 2ba14e7..84b2566 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -679,7 +679,7 @@ config PPC_PCI_CHOICE
 config PCI
bool PCI support if PPC_PCI_CHOICE
default y if !40x  !CPM2  !8xx  !PPC_83xx \
-!PPC_85xx  !PPC_86xx
+!PPC_85xx  !PPC_86xx  !GAMECUBE_COMMON
default PCI_PERMEDIA if !4xx  !CPM2  !8xx
default PCI_QSPAN if !4xx  !CPM2  8xx
select ARCH_SUPPORTS_MSI
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v2 07/22] powerpc: gamecube/wii: udbg support for usbgecko

2009-12-12 Thread Albert Herranz
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_herr...@yahoo.es
Acked-by: Segher Boessenkool seg...@kernel.crashing.org
---
 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 000..ba4c7cc
--- /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 mm/mmu_decl.h
+
+#include asm/io.h
+#include asm/prom.h
+#include asm/udbg.h
+
+#include usbgecko_udbg.h
+
+
+#define EXI_CLK_32MHZ   5
+
+#define EXI_CSR 0x00
+#define   EXI_CSR_CLKMASK   (0x74)
+#define EXI_CSR_CLK_32MHZ   (EXI_CLK_32MHZ4)
+#define   EXI_CSR_CSMASK(0x77)
+#define EXI_CSR_CS_0(0x17)  /* Chip Select 001 */
+
+#define EXI_CR  0x0c
+#define   EXI_CR_TSTART (10)
+#define   EXI_CR_WRITE (12)
+#define   EXI_CR_READ_WRITE (22)
+#define   EXI_CR_TLEN(len)  (((len)-1)4)
+
+#define EXI_DATA0x10
+
+#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(0x9000) == 0x0470;
+}
+
+/*
+ * Returns true if the TX fifo is ready for transmission.
+ */
+static int ug_is_txfifo_ready(void)
+{
+   return ug_io_transaction(0xc000)  0x0400;
+}
+
+/*
+ * 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(0xb000 | (ch  20

[PATCH v2 08/22] powerpc: gamecube/wii: flipper interrupt controller support

2009-12-12 Thread Albert Herranz
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_herr...@yahoo.es
Acked-by: Segher Boessenkool seg...@kernel.crashing.org
---
 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 000..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_IRQS32
+
+/*
+ * 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_ICR0x00
+#define FLIPPER_ICR_RSS(116) /* reset switch state */
+
+#define FLIPPER_IMR0x04
+
+#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

[PATCH v2 09/22] powerpc: gamecube: platform support

2009-12-12 Thread Albert Herranz
Add platform support for the Nintendo GameCube video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/Kconfig|8 ++
 arch/powerpc/platforms/embedded6xx/Makefile   |1 +
 arch/powerpc/platforms/embedded6xx/gamecube.c |  118 +
 3 files changed, 127 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/platforms/embedded6xx/gamecube.c

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index 464e414..e318ced 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -107,3 +107,11 @@ config USBGECKO_UDBG
 
  If in doubt, say N here.
 
+config GAMECUBE
+   bool Nintendo-GameCube
+   depends on EMBEDDED6xx
+   select GAMECUBE_COMMON
+   help
+ Select GAMECUBE if configuring for the Nintendo GameCube.
+ More information at: http://gc-linux.sourceforge.net/
+
diff --git a/arch/powerpc/platforms/embedded6xx/Makefile 
b/arch/powerpc/platforms/embedded6xx/Makefile
index b80f47c..9365edd 100644
--- a/arch/powerpc/platforms/embedded6xx/Makefile
+++ b/arch/powerpc/platforms/embedded6xx/Makefile
@@ -9,3 +9,4 @@ 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
+obj-$(CONFIG_GAMECUBE) += gamecube.o
diff --git a/arch/powerpc/platforms/embedded6xx/gamecube.c 
b/arch/powerpc/platforms/embedded6xx/gamecube.c
new file mode 100644
index 000..1106fd9
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/gamecube.c
@@ -0,0 +1,118 @@
+/*
+ * arch/powerpc/platforms/embedded6xx/gamecube.c
+ *
+ * Nintendo GameCube board-specific 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.
+ *
+ */
+
+#include linux/kernel.h
+#include linux/init.h
+#include linux/irq.h
+#include linux/kexec.h
+#include linux/seq_file.h
+#include linux/of_platform.h
+
+#include asm/io.h
+#include asm/machdep.h
+#include asm/prom.h
+#include asm/time.h
+#include asm/udbg.h
+
+#include flipper-pic.h
+#include usbgecko_udbg.h
+
+
+static void gamecube_spin(void)
+{
+   /* spin until power button pressed */
+   for (;;)
+   cpu_relax();
+}
+
+static void gamecube_restart(char *cmd)
+{
+   local_irq_disable();
+   flipper_platform_reset();
+   gamecube_spin();
+}
+
+static void gamecube_power_off(void)
+{
+   local_irq_disable();
+   gamecube_spin();
+}
+
+static void gamecube_halt(void)
+{
+   gamecube_restart(NULL);
+}
+
+static void __init gamecube_init_early(void)
+{
+   ug_udbg_init();
+}
+
+static int __init gamecube_probe(void)
+{
+   unsigned long dt_root;
+
+   dt_root = of_get_flat_dt_root();
+   if (!of_flat_dt_is_compatible(dt_root, nintendo,gamecube))
+   return 0;
+
+   return 1;
+}
+
+static void gamecube_shutdown(void)
+{
+   flipper_quiesce();
+}
+
+#ifdef CONFIG_KEXEC
+static int gamecube_kexec_prepare(struct kimage *image)
+{
+   return 0;
+}
+#endif /* CONFIG_KEXEC */
+
+
+define_machine(gamecube) {
+   .name   = gamecube,
+   .probe  = gamecube_probe,
+   .init_early = gamecube_init_early,
+   .restart= gamecube_restart,
+   .power_off  = gamecube_power_off,
+   .halt   = gamecube_halt,
+   .init_IRQ   = flipper_pic_probe,
+   .get_irq= flipper_pic_get_irq,
+   .calibrate_decr = generic_calibrate_decr,
+   .progress   = udbg_progress,
+   .machine_shutdown   = gamecube_shutdown,
+#ifdef CONFIG_KEXEC
+   .machine_kexec_prepare  = gamecube_kexec_prepare,
+#endif
+};
+
+
+static struct of_device_id gamecube_of_bus[] = {
+   { .compatible = nintendo,flipper, },
+   { },
+};
+
+static int __init gamecube_device_probe(void)
+{
+   if (!machine_is(gamecube))
+   return 0;
+
+   of_platform_bus_probe(NULL, gamecube_of_bus, NULL);
+   return 0;
+}
+device_initcall(gamecube_device_probe);
+
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v2 10/22] powerpc: gamecube: default config

2009-12-12 Thread Albert Herranz
Add a default configuration for the Nintendo GameCube video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/configs/gamecube_defconfig | 1061 +++
 1 files changed, 1061 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/configs/gamecube_defconfig

diff --git a/arch/powerpc/configs/gamecube_defconfig 
b/arch/powerpc/configs/gamecube_defconfig
new file mode 100644
index 000..942e119
--- /dev/null
+++ b/arch/powerpc/configs/gamecube_defconfig
@@ -0,0 +1,1061 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.32-rc8
+# Sun Nov 22 21:07:30 2009
+#
+# CONFIG_PPC64 is not set
+
+#
+# Processor support
+#
+CONFIG_PPC_BOOK3S_32=y
+# CONFIG_PPC_85xx is not set
+# CONFIG_PPC_8xx is not set
+# CONFIG_40x is not set
+# CONFIG_44x is not set
+# CONFIG_E200 is not set
+CONFIG_PPC_BOOK3S=y
+CONFIG_6xx=y
+CONFIG_PPC_FPU=y
+# CONFIG_ALTIVEC is not set
+CONFIG_PPC_STD_MMU=y
+CONFIG_PPC_STD_MMU_32=y
+# CONFIG_PPC_MM_SLICES is not set
+CONFIG_PPC_HAVE_PMU_SUPPORT=y
+CONFIG_PPC_PERF_CTRS=y
+# CONFIG_SMP is not set
+CONFIG_NOT_COHERENT_CACHE=y
+CONFIG_PPC32=y
+CONFIG_WORD_SIZE=32
+# CONFIG_ARCH_PHYS_ADDR_T_64BIT is not set
+CONFIG_MMU=y
+CONFIG_GENERIC_CMOS_UPDATE=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_TIME_VSYSCALL=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
+# CONFIG_HAVE_SETUP_PER_CPU_AREA is not set
+# CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK is not set
+CONFIG_IRQ_PER_CPU=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_RWSEM_XCHGADD_ALGORITHM=y
+CONFIG_ARCH_HAS_ILOG2_U32=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_FIND_NEXT_BIT=y
+# CONFIG_ARCH_NO_VIRT_TO_BUS is not set
+CONFIG_PPC=y
+CONFIG_EARLY_PRINTK=y
+CONFIG_GENERIC_NVRAM=y
+CONFIG_SCHED_OMIT_FRAME_POINTER=y
+CONFIG_ARCH_MAY_HAVE_PC_FDC=y
+CONFIG_PPC_OF=y
+CONFIG_OF=y
+# CONFIG_PPC_UDBG_16550 is not set
+# CONFIG_GENERIC_TBSYNC is not set
+CONFIG_AUDIT_ARCH=y
+CONFIG_GENERIC_BUG=y
+CONFIG_DTC=y
+# CONFIG_DEFAULT_UIMAGE is not set
+# CONFIG_PPC_DCR_NATIVE is not set
+# CONFIG_PPC_DCR_MMIO is not set
+CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC=y
+CONFIG_DEFCONFIG_LIST=/lib/modules/$UNAME_RELEASE/.config
+CONFIG_CONSTRUCTORS=y
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=-gcn
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+
+#
+# RCU Subsystem
+#
+CONFIG_TREE_RCU=y
+# CONFIG_TREE_PREEMPT_RCU is not set
+# CONFIG_RCU_TRACE is not set
+CONFIG_RCU_FANOUT=32
+# CONFIG_RCU_FANOUT_EXACT is not set
+# CONFIG_TREE_RCU_TRACE is not set
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_GROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+# CONFIG_RT_GROUP_SCHED is not set
+CONFIG_USER_SCHED=y
+# CONFIG_CGROUP_SCHED is not set
+# CONFIG_CGROUPS is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
+# CONFIG_RELAY is not set
+# CONFIG_NAMESPACES is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=
+CONFIG_RD_GZIP=y
+# CONFIG_RD_BZIP2 is not set
+# CONFIG_RD_LZMA is not set
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+CONFIG_EMBEDDED=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+CONFIG_KALLSYMS_ALL=y
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+# CONFIG_ELF_CORE is not set
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+CONFIG_HAVE_PERF_EVENTS=y
+
+#
+# Kernel Performance Events And Counters
+#
+CONFIG_PERF_EVENTS=y
+CONFIG_EVENT_PROFILE=y
+CONFIG_PERF_COUNTERS=y
+# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_COMPAT_BRK=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+CONFIG_TRACEPOINTS=y
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y
+CONFIG_HAVE_IOREMAP_PROT=y
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+CONFIG_HAVE_ARCH_TRACEHOOK=y
+CONFIG_HAVE_DMA_ATTRS=y
+CONFIG_HAVE_DMA_API_DEBUG=y
+
+#
+# GCOV-based kernel profiling
+#
+# CONFIG_GCOV_KERNEL is not set
+CONFIG_SLOW_WORK=y
+# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+CONFIG_LBDAF=y
+# CONFIG_BLK_DEV_BSG is not set
+# CONFIG_BLK_DEV_INTEGRITY is not set
+
+#
+# IO Schedulers

[PATCH v2 11/22] powerpc: wii: device tree

2009-12-12 Thread Albert Herranz
Add a device tree source file for the Nintendo Wii video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Segher Boessenkool seg...@kernel.crashing.org
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 .../powerpc/dts-bindings/nintendo/wii.txt  |  184 +
 arch/powerpc/boot/dts/wii.dts  |  218 
 2 files changed, 402 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/powerpc/dts-bindings/nintendo/wii.txt
 create mode 100644 arch/powerpc/boot/dts/wii.dts

diff --git a/Documentation/powerpc/dts-bindings/nintendo/wii.txt 
b/Documentation/powerpc/dts-bindings/nintendo/wii.txt
new file mode 100644
index 000..a7e155a
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/nintendo/wii.txt
@@ -0,0 +1,184 @@
+
+Nintendo Wii device tree
+
+
+0) The root node
+
+  This node represents the Nintendo Wii video game console.
+
+  Required properties:
+
+   - model : Should be nintendo,wii
+   - compatible : Should be nintendo,wii
+
+1) The hollywood node
+
+  This node represents the multi-function Hollywood chip, which packages
+  many of the devices found in the Nintendo Wii.
+
+  Required properties:
+
+   - compatible : Should be nintendo,hollywood
+
+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,hollywood-vi,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,hollywood-pi,nintendo,flipper-pi
+  - reg : should contain the PI registers location and length
+
+1.b.i) The Flipper interrupt controller node
+
+  Represents the Flipper interrupt controller within the Hollywood chip.
+  The node for the Flipper interrupt controller must be placed under
+  the PI node.
+
+  Required properties:
+
+  - #interrupt-cells : 1
+  - compatible : should be nintendo,flipper-pic
+  - interrupt-controller
+
+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,hollywood-dsp,nintendo,flipper-dsp
+   - reg : should contain the DSP registers location and length
+   - interrupts : should contain the DSP interrupt
+
+1.d) 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,hollywood-si,nintendo,flipper-si
+   - reg : should contain the SI registers location and length
+   - interrupts : should contain the SI 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,hollywood-ai,nintendo,flipper-ai
+   - reg : should contain the AI registers location and length
+   - interrupts : should contain the AI interrupt
+
+1.f) The External Interface (EXI) node
+
+  Represents the multi-channel SPI-like interface.
+
+  Required properties:
+
+   - compatible : should be nintendo,hollywood-exi,nintendo,flipper-exi
+   - reg : should contain the EXI registers location and length
+   - interrupts : should contain the EXI interrupt
+
+1.g) The Open Host Controller Interface (OHCI) nodes
+
+  Represent the USB 1.x Open Host Controller Interfaces.
+
+  Required properties:
+
+   - compatible : should be nintendo,hollywood-usb-ohci,usb-ohci
+   - reg : should contain the OHCI registers location and length
+   - interrupts : should contain the OHCI interrupt
+
+1.h) The Enhanced Host Controller Interface (EHCI) node
+
+  Represents the USB 2.0 Enhanced Host Controller Interface.
+
+  Required properties:
+
+   - compatible : should be nintendo,hollywood-usb-ehci,usb-ehci
+   - reg : should contain the EHCI registers location and length
+   - interrupts : should contain the EHCI interrupt
+
+1.i) The Secure Digital Host Controller Interface (SDHCI) nodes
+
+  Represent the Secure Digital Host Controller Interfaces.
+
+  Required properties:
+
+   - compatible : should be nintendo,hollywood-sdhci,sdhci
+   - reg : should contain the SDHCI registers location and length
+   - interrupts : should contain the SDHCI interrupt
+
+1.j) The Inter-Processsor Communication (IPC) node
+
+  Represent the Inter-Processor Communication interface. This interface
+  enables communications between the Broadway and the Starlet processors.
+
+   - compatible : should

[PATCH v2 12/22] powerpc: wii: bootwrapper bits

2009-12-12 Thread Albert Herranz
Add support for the Nintendo Wii video game console to the powerpc
bootwrapper.

dtbImage.wii is a wrapped image that contains a flat device tree,
an entry point compatible with the Homebrew Channel and BootMii,
and an optional initrd.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Segher Boessenkool seg...@kernel.crashing.org
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/boot/Makefile   |3 +-
 arch/powerpc/boot/wii-head.S |  142 ++
 arch/powerpc/boot/wii.c  |   46 ++
 arch/powerpc/boot/wrapper|2 +-
 4 files changed, 191 insertions(+), 2 deletions(-)
 create mode 100644 arch/powerpc/boot/wii-head.S
 create mode 100644 arch/powerpc/boot/wii.c

diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
index 3e70aab..bb2465b 100644
--- a/arch/powerpc/boot/Makefile
+++ b/arch/powerpc/boot/Makefile
@@ -77,7 +77,7 @@ src-plat := of.c cuboot-52xx.c cuboot-824x.c cuboot-83xx.c 
cuboot-85xx.c holly.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 \
-   gamecube-head.S gamecube.c
+   gamecube-head.S gamecube.c wii-head.S wii.c
 src-boot := $(src-wlib) $(src-plat) empty.c
 
 src-boot := $(addprefix $(obj)/, $(src-boot))
@@ -256,6 +256,7 @@ image-$(CONFIG_STORCENTER)  += cuImage.storcenter
 image-$(CONFIG_MPC7448HPC2)+= cuImage.mpc7448hpc2
 image-$(CONFIG_PPC_C2K)+= cuImage.c2k
 image-$(CONFIG_GAMECUBE)   += dtbImage.gamecube
+image-$(CONFIG_WII)+= dtbImage.wii
 
 # Board port in arch/powerpc/platform/amigaone/Kconfig
 image-$(CONFIG_AMIGAONE)   += cuImage.amigaone
diff --git a/arch/powerpc/boot/wii-head.S b/arch/powerpc/boot/wii-head.S
new file mode 100644
index 000..edd79b8
--- /dev/null
+++ b/arch/powerpc/boot/wii-head.S
@@ -0,0 +1,142 @@
+/*
+ * arch/powerpc/boot/wii-head.S
+ *
+ * Nintendo Wii bootwrapper entry.
+ * 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 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
+ * - if the high BATs are enabled or not
+ *
+ * We enable the high BATs, 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, ~((14)|(15)) /* MSR_DR|MSR_IR */
+   bcl 20, 31, 1f
+1:
+   mflr8
+   clrlwi  8, 8, 3 /* convert to a real address */
+   addi8, 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 */
+
+   mtspr   0x230, 8/* IBAT4U */
+   mtspr   0x232, 8/* IBAT5U */
+   mtspr   0x234, 8/* IBAT6U */
+   mtspr   0x236, 8/* IBAT7U */
+   mtspr   0x238, 8/* DBAT4U */
+   mtspr   0x23a, 8/* DBAT5U */
+   mtspr   0x23c, 8/* DBAT6U */
+   mtspr   0x23e, 8/* DBAT7U */
+
+   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 */
+
+   lis 8, 0x1000

[PATCH v2 13/22] powerpc: broadway processor support

2009-12-12 Thread Albert Herranz
This patch extends the cputable entry of the 750CL to also match
the 750CL-based Broadway cpu found on the Nintendo Wii.

As of this patch, the following Broadway design revision levels have
been seen in the wild:
- DD1.2 (87102)
- DD2.0 (87200)

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/kernel/cputable.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index 03c862b..2fc82ba 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -697,9 +697,9 @@ static struct cpu_spec __initdata cpu_specs[] = {
.machine_check  = machine_check_generic,
.platform   = ppc750,
},
-   {   /* 750CL */
-   .pvr_mask   = 0xf0f0,
-   .pvr_value  = 0x00087010,
+   {   /* 750CL (and Broadway) */
+   .pvr_mask   = 0xf0e0,
+   .pvr_value  = 0x00087000,
.cpu_name   = 750CL,
.cpu_features   = CPU_FTRS_750CL,
.cpu_user_features  = COMMON_USER | PPC_FEATURE_PPC_LE,
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v2 14/22] powerpc: wii: hollywood interrupt controller support

2009-12-12 Thread Albert Herranz
Add support for the dual interrupt controller included in the Hollywood
chipset of the Nintendo Wii video game console.
This interrupt controller serves both the Broadway processor (as a cascade)
and the Starlet processor, and is used to manage interrupts for the
non-classic hardware.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
Acked-by: Segher Boessenkool seg...@kernel.crashing.org
---
 arch/powerpc/platforms/embedded6xx/Makefile   |1 +
 arch/powerpc/platforms/embedded6xx/hlwd-pic.c |  241 +
 arch/powerpc/platforms/embedded6xx/hlwd-pic.h |   22 +++
 3 files changed, 264 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/platforms/embedded6xx/hlwd-pic.c
 create mode 100644 arch/powerpc/platforms/embedded6xx/hlwd-pic.h

diff --git a/arch/powerpc/platforms/embedded6xx/Makefile 
b/arch/powerpc/platforms/embedded6xx/Makefile
index 9365edd..f75b9e4 100644
--- a/arch/powerpc/platforms/embedded6xx/Makefile
+++ b/arch/powerpc/platforms/embedded6xx/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_PPC_C2K) += c2k.o
 obj-$(CONFIG_USBGECKO_UDBG)+= usbgecko_udbg.o
 obj-$(CONFIG_GAMECUBE_COMMON)  += flipper-pic.o
 obj-$(CONFIG_GAMECUBE) += gamecube.o
+obj-$(CONFIG_WII)  += hlwd-pic.o
diff --git a/arch/powerpc/platforms/embedded6xx/hlwd-pic.c 
b/arch/powerpc/platforms/embedded6xx/hlwd-pic.c
new file mode 100644
index 000..dd20bff
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/hlwd-pic.c
@@ -0,0 +1,241 @@
+/*
+ * arch/powerpc/platforms/embedded6xx/hlwd-pic.c
+ *
+ * Nintendo Wii Hollywood interrupt controller support.
+ * Copyright (C) 2009 The GameCube Linux Team
+ * Copyright (C) 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 hlwd-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 hlwd-pic.h
+
+#define HLWD_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 asserting/clearing
+ * the corresponding bit in IMR. ACK'ing a request simply involves
+ * asserting the corresponding bit in ICR.
+ */
+#define HW_BROADWAY_ICR0x00
+#define HW_BROADWAY_IMR0x04
+
+
+/*
+ * IRQ chip hooks.
+ *
+ */
+
+static void hlwd_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 + HW_BROADWAY_IMR, mask);
+   out_be32(io_base + HW_BROADWAY_ICR, mask);
+}
+
+static void hlwd_pic_ack(unsigned int virq)
+{
+   int irq = virq_to_hw(virq);
+   void __iomem *io_base = get_irq_chip_data(virq);
+
+   out_be32(io_base + HW_BROADWAY_ICR, 1  irq);
+}
+
+static void hlwd_pic_mask(unsigned int virq)
+{
+   int irq = virq_to_hw(virq);
+   void __iomem *io_base = get_irq_chip_data(virq);
+
+   clrbits32(io_base + HW_BROADWAY_IMR, 1  irq);
+}
+
+static void hlwd_pic_unmask(unsigned int virq)
+{
+   int irq = virq_to_hw(virq);
+   void __iomem *io_base = get_irq_chip_data(virq);
+
+   setbits32(io_base + HW_BROADWAY_IMR, 1  irq);
+}
+
+
+static struct irq_chip hlwd_pic = {
+   .name   = hlwd-pic,
+   .ack= hlwd_pic_ack,
+   .mask_ack   = hlwd_pic_mask_and_ack,
+   .mask   = hlwd_pic_mask,
+   .unmask = hlwd_pic_unmask,
+};
+
+/*
+ * IRQ host hooks.
+ *
+ */
+
+static struct irq_host *hlwd_irq_host;
+
+static int hlwd_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, hlwd_pic, handle_level_irq);
+   return 0;
+}
+
+static void hlwd_pic_unmap(struct irq_host *h, unsigned int irq)
+{
+   set_irq_chip_data(irq, NULL);
+   set_irq_chip(irq, NULL);
+}
+
+static struct irq_host_ops hlwd_irq_host_ops = {
+   .map = hlwd_pic_map,
+   .unmap = hlwd_pic_unmap,
+};
+
+static unsigned int __hlwd_pic_get_irq(struct irq_host *h)
+{
+   void __iomem *io_base = h-host_data;
+   int irq;
+   u32 irq_status;
+
+   irq_status = in_be32(io_base + HW_BROADWAY_ICR) 
+in_be32(io_base + HW_BROADWAY_IMR);
+   if (irq_status == 0)
+   return NO_IRQ;  /* no more IRQs pending */
+
+   irq = __ffs(irq_status);
+   return irq_linear_revmap(h, irq);
+}
+
+static void hlwd_pic_irq_cascade(unsigned int cascade_virq

[PATCH v2 15/22] powerpc: wii: platform support

2009-12-12 Thread Albert Herranz
Add platform support for the Nintendo Wii video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
Acked-by: Segher Boessenkool seg...@kernel.crashing.org 
---
RFC v2 - v2
- turn off blue led and ir light on boot

Note that the patch was acked-by without the single change from
RFC v2 to v2.

 arch/powerpc/platforms/embedded6xx/Kconfig  |8 +
 arch/powerpc/platforms/embedded6xx/Makefile |2 +-
 arch/powerpc/platforms/embedded6xx/wii.c|  202 +++
 3 files changed, 211 insertions(+), 1 deletions(-)
 create mode 100644 arch/powerpc/platforms/embedded6xx/wii.c

diff --git a/arch/powerpc/platforms/embedded6xx/Kconfig 
b/arch/powerpc/platforms/embedded6xx/Kconfig
index e318ced..524d971 100644
--- a/arch/powerpc/platforms/embedded6xx/Kconfig
+++ b/arch/powerpc/platforms/embedded6xx/Kconfig
@@ -115,3 +115,11 @@ config GAMECUBE
  Select GAMECUBE if configuring for the Nintendo GameCube.
  More information at: http://gc-linux.sourceforge.net/
 
+config WII
+   bool Nintendo-Wii
+   depends on EMBEDDED6xx
+   select GAMECUBE_COMMON
+   help
+ Select WII if configuring for the Nintendo Wii.
+ More information at: http://gc-linux.sourceforge.net/
+
diff --git a/arch/powerpc/platforms/embedded6xx/Makefile 
b/arch/powerpc/platforms/embedded6xx/Makefile
index f75b9e4..66c23e4 100644
--- a/arch/powerpc/platforms/embedded6xx/Makefile
+++ b/arch/powerpc/platforms/embedded6xx/Makefile
@@ -10,4 +10,4 @@ obj-$(CONFIG_PPC_C2K) += c2k.o
 obj-$(CONFIG_USBGECKO_UDBG)+= usbgecko_udbg.o
 obj-$(CONFIG_GAMECUBE_COMMON)  += flipper-pic.o
 obj-$(CONFIG_GAMECUBE) += gamecube.o
-obj-$(CONFIG_WII)  += hlwd-pic.o
+obj-$(CONFIG_WII)  += wii.o hlwd-pic.o
diff --git a/arch/powerpc/platforms/embedded6xx/wii.c 
b/arch/powerpc/platforms/embedded6xx/wii.c
new file mode 100644
index 000..1bd41cc
--- /dev/null
+++ b/arch/powerpc/platforms/embedded6xx/wii.c
@@ -0,0 +1,202 @@
+/*
+ * arch/powerpc/platforms/embedded6xx/wii.c
+ *
+ * Nintendo Wii board-specific support
+ * 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.
+ *
+ */
+#define DRV_MODULE_NAME wii
+#define pr_fmt(fmt) DRV_MODULE_NAME :  fmt
+
+#include linux/kernel.h
+#include linux/init.h
+#include linux/irq.h
+#include linux/seq_file.h
+#include linux/kexec.h
+#include linux/of_platform.h
+
+#include asm/io.h
+#include asm/machdep.h
+#include asm/prom.h
+#include asm/time.h
+#include asm/udbg.h
+
+#include flipper-pic.h
+#include hlwd-pic.h
+#include usbgecko_udbg.h
+
+/* control block */
+#define HW_CTRL_COMPATIBLE nintendo,hollywood-control
+
+#define HW_CTRL_RESETS 0x94
+#define HW_CTRL_RESETS_SYS (10)
+
+/* gpio */
+#define HW_GPIO_COMPATIBLE nintendo,hollywood-gpio
+
+#define HW_GPIO_BASE(idx)  (idx * 0x20)
+#define HW_GPIO_OUT(idx)   (HW_GPIO_BASE(idx) + 0)
+#define HW_GPIO_DIR(idx)   (HW_GPIO_BASE(idx) + 4)
+
+#define HW_GPIO_SHUTDOWN   (11)
+#define HW_GPIO_SLOT_LED   (15)
+#define HW_GPIO_SENSOR_BAR (18)
+
+
+static void __iomem *hw_ctrl;
+static void __iomem *hw_gpio;
+
+static void wii_spin(void)
+{
+   local_irq_disable();
+   for (;;)
+   cpu_relax();
+}
+
+static void __iomem *wii_ioremap_hw_regs(char *name, char *compatible)
+{
+   void __iomem *hw_regs = NULL;
+   struct device_node *np;
+   struct resource res;
+   int error = -ENODEV;
+
+   np = of_find_compatible_node(NULL, NULL, compatible);
+   if (!np) {
+   pr_err(no compatible node found for %s\n, compatible);
+   goto out;
+   }
+   error = of_address_to_resource(np, 0, res);
+   if (error) {
+   pr_err(no valid reg found for %s\n, np-name);
+   goto out_put;
+   }
+
+   hw_regs = ioremap(res.start, resource_size(res));
+   if (hw_regs) {
+   pr_info(%s at 0x%08x mapped to 0x%p\n, name,
+   res.start, hw_regs);
+   }
+
+out_put:
+   of_node_put(np);
+out:
+   return hw_regs;
+}
+
+static void __init wii_setup_arch(void)
+{
+   hw_ctrl = wii_ioremap_hw_regs(hw_ctrl, HW_CTRL_COMPATIBLE);
+   hw_gpio = wii_ioremap_hw_regs(hw_gpio, HW_GPIO_COMPATIBLE);
+   if (hw_gpio) {
+   /* turn off the front blue led and IR light */
+   clrbits32(hw_gpio + HW_GPIO_OUT(0),
+ HW_GPIO_SLOT_LED | HW_GPIO_SENSOR_BAR);
+   }
+}
+
+static void wii_restart(char *cmd)
+{
+   local_irq_disable();
+
+   if (hw_ctrl) {
+   /* clear the system reset pin to cause

[PATCH v2 17/22] powerpc: reserve fixmap entries for early debug

2009-12-12 Thread Albert Herranz
Add a set of entries to the fixmap table to allow usage of known
reserved virtual address space by early debug code.

The address space reserved is the top 128K of the 32-bit address
space. This allows, if required, the use of a BAT to do the mappings.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 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..5c2c023 100644
--- a/arch/powerpc/include/asm/fixmap.h
+++ b/arch/powerpc/include/asm/fixmap.h
@@ -44,6 +44,9 @@
  */
 enum fixed_addresses {
FIX_HOLE,
+   /* reserve the top 128K for early debugging purposes */
+   FIX_EARLY_DEBUG_TOP = FIX_HOLE,
+   FIX_EARLY_DEBUG_BASE = FIX_EARLY_DEBUG_TOP+((128*1024)/PAGE_SIZE)-1,
 #ifdef CONFIG_HIGHMEM
FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v2 16/22] powerpc: wii: default config

2009-12-12 Thread Albert Herranz
Add a default configuration for the Nintendo Wii video game console.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/configs/wii_defconfig | 1406 
 1 files changed, 1406 insertions(+), 0 deletions(-)
 create mode 100644 arch/powerpc/configs/wii_defconfig

diff --git a/arch/powerpc/configs/wii_defconfig 
b/arch/powerpc/configs/wii_defconfig
new file mode 100644
index 000..c386828
--- /dev/null
+++ b/arch/powerpc/configs/wii_defconfig
@@ -0,0 +1,1406 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.32-rc8
+# Sun Nov 22 20:37:21 2009
+#
+# CONFIG_PPC64 is not set
+
+#
+# Processor support
+#
+CONFIG_PPC_BOOK3S_32=y
+# CONFIG_PPC_85xx is not set
+# CONFIG_PPC_8xx is not set
+# CONFIG_40x is not set
+# CONFIG_44x is not set
+# CONFIG_E200 is not set
+CONFIG_PPC_BOOK3S=y
+CONFIG_6xx=y
+CONFIG_PPC_FPU=y
+# CONFIG_ALTIVEC is not set
+CONFIG_PPC_STD_MMU=y
+CONFIG_PPC_STD_MMU_32=y
+# CONFIG_PPC_MM_SLICES is not set
+CONFIG_PPC_HAVE_PMU_SUPPORT=y
+CONFIG_PPC_PERF_CTRS=y
+# CONFIG_SMP is not set
+CONFIG_NOT_COHERENT_CACHE=y
+CONFIG_PPC32=y
+CONFIG_WORD_SIZE=32
+# CONFIG_ARCH_PHYS_ADDR_T_64BIT is not set
+CONFIG_MMU=y
+CONFIG_GENERIC_CMOS_UPDATE=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_TIME_VSYSCALL=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
+# CONFIG_HAVE_SETUP_PER_CPU_AREA is not set
+# CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK is not set
+CONFIG_IRQ_PER_CPU=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_RWSEM_XCHGADD_ALGORITHM=y
+CONFIG_ARCH_HAS_ILOG2_U32=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_FIND_NEXT_BIT=y
+CONFIG_GENERIC_GPIO=y
+# CONFIG_ARCH_NO_VIRT_TO_BUS is not set
+CONFIG_PPC=y
+CONFIG_EARLY_PRINTK=y
+CONFIG_GENERIC_NVRAM=y
+CONFIG_SCHED_OMIT_FRAME_POINTER=y
+CONFIG_ARCH_MAY_HAVE_PC_FDC=y
+CONFIG_PPC_OF=y
+CONFIG_OF=y
+# CONFIG_PPC_UDBG_16550 is not set
+# CONFIG_GENERIC_TBSYNC is not set
+CONFIG_AUDIT_ARCH=y
+CONFIG_GENERIC_BUG=y
+CONFIG_DTC=y
+# CONFIG_DEFAULT_UIMAGE is not set
+# CONFIG_PPC_DCR_NATIVE is not set
+# CONFIG_PPC_DCR_MMIO is not set
+CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC=y
+CONFIG_DEFCONFIG_LIST=/lib/modules/$UNAME_RELEASE/.config
+CONFIG_CONSTRUCTORS=y
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=-wii
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+
+#
+# RCU Subsystem
+#
+CONFIG_TREE_RCU=y
+# CONFIG_TREE_PREEMPT_RCU is not set
+# CONFIG_RCU_TRACE is not set
+CONFIG_RCU_FANOUT=32
+# CONFIG_RCU_FANOUT_EXACT is not set
+# CONFIG_TREE_RCU_TRACE is not set
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_GROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+# CONFIG_RT_GROUP_SCHED is not set
+CONFIG_USER_SCHED=y
+# CONFIG_CGROUP_SCHED is not set
+# CONFIG_CGROUPS is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
+CONFIG_RELAY=y
+# CONFIG_NAMESPACES is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=
+CONFIG_RD_GZIP=y
+# CONFIG_RD_BZIP2 is not set
+# CONFIG_RD_LZMA is not set
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+CONFIG_EMBEDDED=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+CONFIG_KALLSYMS_ALL=y
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+# CONFIG_ELF_CORE is not set
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+CONFIG_HAVE_PERF_EVENTS=y
+
+#
+# Kernel Performance Events And Counters
+#
+CONFIG_PERF_EVENTS=y
+CONFIG_EVENT_PROFILE=y
+CONFIG_PERF_COUNTERS=y
+# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_COMPAT_BRK=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+CONFIG_TRACEPOINTS=y
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y
+CONFIG_HAVE_IOREMAP_PROT=y
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+CONFIG_HAVE_ARCH_TRACEHOOK=y
+CONFIG_HAVE_DMA_ATTRS=y
+CONFIG_HAVE_DMA_API_DEBUG=y
+
+#
+# GCOV-based kernel profiling
+#
+# CONFIG_GCOV_KERNEL is not set
+CONFIG_SLOW_WORK=y
+# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+CONFIG_LBDAF=y
+CONFIG_BLK_DEV_BSG=y
+# CONFIG_BLK_DEV_INTEGRITY

[PATCH v2 18/22] powerpc: gamecube/wii: early debugging using usbgecko

2009-12-12 Thread Albert Herranz
Add support for using the USB Gecko adapter as an early debugging
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_herr...@yahoo.es
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
RFC v2 - v2
- use Vp=0 instead of Vp=1 for the early BAT mapping.
  Suggestion by Segher Boessenkool.

Note that the patch was acked-by without the single change from
RFC v2 to v2.

 arch/powerpc/Kconfig.debug |8 +++
 arch/powerpc/include/asm/udbg.h|1 +
 arch/powerpc/kernel/head_32.S  |   25 +
 arch/powerpc/kernel/udbg.c |2 +
 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c |   56 
 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h |2 +
 6 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 3b10051..11e385b 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -254,6 +254,14 @@ config PPC_EARLY_DEBUG_CPM
  using a CPM-based serial port.  This assumes that the bootwrapper
  has run, and set up the CPM in a particular way.
 
+config PPC_EARLY_DEBUG_USBGECKO
+   bool Early debugging through the USB Gecko adapter
+   depends on GAMECUBE_COMMON
+   select USBGECKO_UDBG
+   help
+ Select this to enable early debugging for Nintendo GameCube/Wii
+ consoles via an external USB Gecko adapter.
+
 endchoice
 
 config PPC_EARLY_DEBUG_44x_PHYSLOW
diff --git a/arch/powerpc/include/asm/udbg.h b/arch/powerpc/include/asm/udbg.h
index cd21e5e..11ae699 100644
--- a/arch/powerpc/include/asm/udbg.h
+++ b/arch/powerpc/include/asm/udbg.h
@@ -51,6 +51,7 @@ extern void __init udbg_init_btext(void);
 extern void __init udbg_init_44x_as1(void);
 extern void __init udbg_init_40x_realmode(void);
 extern void __init udbg_init_cpm(void);
+extern void __init udbg_init_usbgecko(void);
 
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_UDBG_H */
diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S
index 829c3fe..e025e89 100644
--- a/arch/powerpc/kernel/head_32.S
+++ b/arch/powerpc/kernel/head_32.S
@@ -164,6 +164,9 @@ __after_mmu_off:
 #ifdef CONFIG_PPC_EARLY_DEBUG_CPM
bl  setup_cpm_bat
 #endif
+#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
+   bl  setup_usbgecko_bat
+#endif
 
 /*
  * Call setup_cpu for CPU 0 and initialize 6xx Idle
@@ -1203,6 +1206,28 @@ setup_cpm_bat:
blr
 #endif
 
+#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
+setup_usbgecko_bat:
+   /* prepare a BAT for early io */
+#if defined(CONFIG_GAMECUBE)
+   lis r8, 0x0c00
+#elif defined(CONFIG_WII)
+   lis r8, 0x0d00
+#else
+#error Invalid platform for USB Gecko based early debugging.
+#endif
+   /*
+* The virtual address used must match the virtual address
+* associated to the fixmap entry FIX_EARLY_DEBUG_BASE.
+*/
+   lis r11, 0xfffe /* top 128K */
+   ori r8, r8, 0x002a  /* uncached, guarded ,rw */
+   ori r11, r11, 0x2   /* 128K, Vs=1, Vp=0 */
+   mtspr   SPRN_DBAT1L, r8
+   mtspr   SPRN_DBAT1U, r11
+   blr
+#endif
+
 #ifdef CONFIG_8260
 /* Jump into the system reset for the rom.
  * We first disable the MMU, and then jump to the ROM reset address.
diff --git a/arch/powerpc/kernel/udbg.c b/arch/powerpc/kernel/udbg.c
index fc9af47..e39cad8 100644
--- a/arch/powerpc/kernel/udbg.c
+++ b/arch/powerpc/kernel/udbg.c
@@ -60,6 +60,8 @@ void __init udbg_early_init(void)
udbg_init_40x_realmode();
 #elif defined(CONFIG_PPC_EARLY_DEBUG_CPM)
udbg_init_cpm();
+#elif defined(CONFIG_PPC_EARLY_DEBUG_USBGECKO)
+   udbg_init_usbgecko();
 #endif
 
 #ifdef CONFIG_PPC_EARLY_DEBUG
diff --git a/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c 
b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
index ba4c7cc..edc956c 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
 
 #include usbgecko_udbg.h
 
@@ -270,3 +271,58 @@ done:
of_node_put(np);
return;
 }
+
+#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
+
+static phys_addr_t __init ug_early_grab_io_addr(void)
+{
+#if defined(CONFIG_GAMECUBE)
+   return 0x0c00;
+#elif defined(CONFIG_WII)
+   return 0x0d00;
+#else
+#error Invalid platform for USB Gecko based early debugging.
+#endif
+}
+
+/*
+ * USB Gecko early debug support initialization for udbg.
+ */
+void __init udbg_init_usbgecko(void)
+{
+   void __iomem *early_debug_area;
+   void __iomem *exi_io_base;
+
+   /*
+* At this point we have a BAT already setup that enables I/O
+* to the EXI

[PATCH v2 19/22] wii: bootwrapper: add fixup to calc useable mem2

2009-12-12 Thread Albert Herranz
The top portion of MEM2 (the second 64MB memory block) in the Nintendo
Wii video game console is used by the firmware running on the Starlet
processor.

Add code to calculate the portion of MEM2 safely useable by the
Broadway processor. When running under the 'mini' firmware this is
easily determined from an in-memory header. Otherwise, a safe default
is used.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/boot/wii.c |  118 +-
 1 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/boot/wii.c b/arch/powerpc/boot/wii.c
index d0e2625..2ebaec0 100644
--- a/arch/powerpc/boot/wii.c
+++ b/arch/powerpc/boot/wii.c
@@ -22,10 +22,120 @@
 
 BSS_STACK(8192);
 
-#define HW_REG(x)  ((void *)(x))
+#define HW_REG(x)  ((void *)(x))
 
-#define EXI_CTRL   HW_REG(0x0d800070)
-#define EXI_CTRL_ENABLE(10)
+#define EXI_CTRL   HW_REG(0x0d800070)
+#define EXI_CTRL_ENABLE(10)
+
+#define MEM2_TOP   (0x1000 + 64*1024*1024)
+#define FIRMWARE_DEFAULT_SIZE  (12*1024*1024)
+
+
+struct mipc_infohdr {
+   char magic[3];
+   u8 version;
+   u32 mem2_boundary;
+   u32 ipc_in;
+   size_t ipc_in_size;
+   u32 ipc_out;
+   size_t ipc_out_size;
+};
+
+static int mipc_check_address(u32 pa)
+{
+   /* only MEM2 addresses */
+   if (pa  0x1000 || pa  0x1400)
+   return -EINVAL;
+   return 0;
+}
+
+static struct mipc_infohdr *mipc_get_infohdr(void)
+{
+   struct mipc_infohdr **hdrp, *hdr;
+
+   /* 'mini' header pointer is the last word of MEM2 memory */
+   hdrp = (struct mipc_infohdr **)0x13fc;
+   if (mipc_check_address((u32)hdrp)) {
+   printf(mini: invalid hdrp %08X\n, (u32)hdrp);
+   hdr = NULL;
+   goto out;
+   }
+
+   hdr = *hdrp;
+   if (mipc_check_address((u32)hdr)) {
+   printf(mini: invalid hdr %08X\n, (u32)hdr);
+   hdr = NULL;
+   goto out;
+   }
+   if (memcmp(hdr-magic, IPC, 3)) {
+   printf(mini: invalid magic\n);
+   hdr = NULL;
+   goto out;
+   }
+
+out:
+   return hdr;
+}
+
+static int mipc_get_mem2_boundary(u32 *mem2_boundary)
+{
+   struct mipc_infohdr *hdr;
+   int error;
+
+   hdr = mipc_get_infohdr();
+   if (!hdr) {
+   error = -1;
+   goto out;
+   }
+
+   if (mipc_check_address(hdr-mem2_boundary)) {
+   printf(mini: invalid mem2_boundary %08X\n,
+  hdr-mem2_boundary);
+   error = -EINVAL;
+   goto out;
+   }
+   *mem2_boundary = hdr-mem2_boundary;
+   error = 0;
+out:
+   return error;
+
+}
+
+static void platform_fixups(void)
+{
+   void *mem;
+   u32 reg[4];
+   u32 mem2_boundary;
+   int len;
+   int error;
+
+   mem = finddevice(/memory);
+   if (!mem)
+   fatal(Can't find memory node\n);
+
+   /* two ranges of (address, size) words */
+   len = getprop(mem, reg, reg, sizeof(reg));
+   if (len != sizeof(reg)) {
+   /* nothing to do */
+   goto out;
+   }
+
+   /* retrieve MEM2 boundary from 'mini' */
+   error = mipc_get_mem2_boundary(mem2_boundary);
+   if (error) {
+   /* if that fails use a sane value */
+   mem2_boundary = MEM2_TOP - FIRMWARE_DEFAULT_SIZE;
+   }
+
+   if (mem2_boundary  reg[2]  mem2_boundary  reg[2] + reg[3]) {
+   reg[3] = mem2_boundary - reg[2];
+   printf(top of MEM2 @ %08X\n, reg[2] + reg[3]);
+   setprop(mem, reg, reg, sizeof(reg));
+   }
+
+out:
+   return;
+}
 
 void platform_init(unsigned long r3, unsigned long r4, unsigned long r5)
 {
@@ -42,5 +152,7 @@ void platform_init(unsigned long r3, unsigned long r4, 
unsigned long r5)
 
if (ug_probe())
console_ops.write = ug_console_write;
+
+   platform_ops.fixups = platform_fixups;
 }
 
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v2 20/22] wii: use both mem1 and mem2 as ram

2009-12-12 Thread Albert Herranz
The Nintendo Wii video game console has two discontiguous RAM regions:
- MEM1: 24MB @ 0x
- MEM2: 64MB @ 0x1000

Unfortunately, the kernel currently does not support discontiguous RAM
memory regions on 32-bit PowerPC platforms.

This patch adds a series of workarounds to allow the use of the second
memory region (MEM2) as RAM by the kernel.
Basically, a single range of memory from the beginning of MEM1 to the
end of MEM2 is reported to the kernel, and a memory reservation is
created for the hole between MEM1 and MEM2.

With this patch the system is able to use all the available RAM and not
just ~27% of it.

This will no longer be needed when proper discontig memory support
for 32-bit PowerPC is added to the kernel.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
RFC v2 - v2
- add __init to page_aligned() function

Note that the patch was acked-by without the single change from
RFC v2 to v2.

 arch/powerpc/mm/init_32.c|4 ++
 arch/powerpc/mm/mmu_decl.h   |   10 -
 arch/powerpc/mm/pgtable_32.c |   32 +--
 arch/powerpc/mm/ppc_mmu_32.c |4 +-
 arch/powerpc/platforms/embedded6xx/wii.c |   63 ++
 5 files changed, 106 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index 9ddcfb4..703c7c2 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -131,9 +131,13 @@ void __init MMU_init(void)
MMU_setup();
 
if (lmb.memory.cnt  1) {
+#ifndef CONFIG_WII
lmb.memory.cnt = 1;
lmb_analyze();
printk(KERN_WARNING Only using first contiguous memory 
region);
+#else
+   wii_memory_fixups();
+#endif
}
 
total_lowmem = total_memory = lmb_end_of_DRAM() - memstart_addr;
diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h
index d2e5321..9aa39fe 100644
--- a/arch/powerpc/mm/mmu_decl.h
+++ b/arch/powerpc/mm/mmu_decl.h
@@ -136,6 +136,14 @@ extern phys_addr_t total_lowmem;
 extern phys_addr_t memstart_addr;
 extern phys_addr_t lowmem_end_addr;
 
+#ifdef CONFIG_WII
+extern unsigned long wii_hole_start;
+extern unsigned long wii_hole_size;
+
+extern unsigned long wii_mmu_mapin_mem2(unsigned long top);
+extern void wii_memory_fixups(void);
+#endif
+
 /* ...and now those things that may be slightly different between processor
  * architectures.  -- Dan
  */
@@ -155,5 +163,5 @@ extern void adjust_total_lowmem(void);
 #elif defined(CONFIG_PPC32)
 /* anything 32-bit except 4xx or 8xx */
 extern void MMU_init_hw(void);
-extern unsigned long mmu_mapin_ram(void);
+extern unsigned long mmu_mapin_ram(unsigned long top);
 #endif
diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index cb96cb2..b55bbe8 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -283,18 +283,18 @@ int map_page(unsigned long va, phys_addr_t pa, int flags)
 }
 
 /*
- * Map in a big chunk of physical memory starting at PAGE_OFFSET.
+ * Map in a chunk of physical memory starting at start.
  */
-void __init mapin_ram(void)
+void __init __mapin_ram_chunk(unsigned long offset, unsigned long top)
 {
unsigned long v, s, f;
phys_addr_t p;
int ktext;
 
-   s = mmu_mapin_ram();
+   s = offset;
v = PAGE_OFFSET + s;
p = memstart_addr + s;
-   for (; s  total_lowmem; s += PAGE_SIZE) {
+   for (; s  top; s += PAGE_SIZE) {
ktext = ((char *) v = _stext  (char *) v  etext);
f = ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL;
map_page(v, p, f);
@@ -307,6 +307,30 @@ void __init mapin_ram(void)
}
 }
 
+void __init mapin_ram(void)
+{
+   unsigned long s, top;
+
+#ifndef CONFIG_WII
+   top = total_lowmem;
+   s = mmu_mapin_ram(top);
+   __mapin_ram_chunk(s, top);
+#else
+   if (!wii_hole_size) {
+   s = mmu_mapin_ram(total_lowmem);
+   __mapin_ram_chunk(s, total_lowmem);
+   } else {
+   top = wii_hole_start;
+   s = mmu_mapin_ram(top);
+   __mapin_ram_chunk(s, top);
+
+   top = lmb_end_of_DRAM();
+   s = wii_mmu_mapin_mem2(top);
+   __mapin_ram_chunk(s, top);
+   }
+#endif
+}
+
 /* Scan the real Linux page tables and return a PTE pointer for
  * a virtual address in a context.
  * Returns true (1) if PTE was found, zero otherwise.  The pointer to
diff --git a/arch/powerpc/mm/ppc_mmu_32.c b/arch/powerpc/mm/ppc_mmu_32.c
index 2d2a87e..f11c2cd 100644
--- a/arch/powerpc/mm/ppc_mmu_32.c
+++ b/arch/powerpc/mm/ppc_mmu_32.c
@@ -72,7 +72,7 @@ unsigned long p_mapped_by_bats(phys_addr_t pa)
return 0;
 }
 
-unsigned long __init mmu_mapin_ram(void)
+unsigned long __init mmu_mapin_ram(unsigned long top)
 {
unsigned long tot, bl, done;
unsigned long max_size

[PATCH v2 21/22] powerpc: allow ioremap within reserved memory regions

2009-12-12 Thread Albert Herranz
Add a flag to let a platform ioremap memory regions marked as reserved.

This flag will be used later by the Nintendo Wii support code to allow
ioremapping the I/O region sitting between MEM1 and MEM2 and marked
as reserved RAM in the patch wii: use both mem1 and mem2 as ram.

This will no longer be needed when proper discontig memory support
for 32-bit PowerPC is added to the kernel.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/mm/init_32.c|5 +
 arch/powerpc/mm/mmu_decl.h   |1 +
 arch/powerpc/mm/pgtable_32.c |4 +++-
 include/linux/lmb.h  |1 +
 lib/lmb.c|7 ++-
 5 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index 703c7c2..4ec900a 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -82,6 +82,11 @@ extern struct task_struct *current_set[NR_CPUS];
 int __map_without_bats;
 int __map_without_ltlbs;
 
+/*
+ * This tells the system to allow ioremapping memory marked as reserved.
+ */
+int __allow_ioremap_reserved;
+
 /* max amount of low RAM to map in */
 unsigned long __max_low_memory = MAX_LOW_MEM;
 
diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h
index 9aa39fe..34dacc3 100644
--- a/arch/powerpc/mm/mmu_decl.h
+++ b/arch/powerpc/mm/mmu_decl.h
@@ -115,6 +115,7 @@ extern void settlbcam(int index, unsigned long virt, 
phys_addr_t phys,
 extern void invalidate_tlbcam_entry(int index);
 
 extern int __map_without_bats;
+extern int __allow_ioremap_reserved;
 extern unsigned long ioremap_base;
 extern unsigned int rtas_data, rtas_size;
 
diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index b55bbe8..177e403 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -26,6 +26,7 @@
 #include linux/vmalloc.h
 #include linux/init.h
 #include linux/highmem.h
+#include linux/lmb.h
 
 #include asm/pgtable.h
 #include asm/pgalloc.h
@@ -191,7 +192,8 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, 
unsigned long flags,
 * Don't allow anybody to remap normal RAM that we're using.
 * mem_init() sets high_memory so only do the check after that.
 */
-   if (mem_init_done  (p  virt_to_phys(high_memory))) {
+   if (mem_init_done  (p  virt_to_phys(high_memory)) 
+   !(__allow_ioremap_reserved  lmb_is_region_reserved(p, size))) {
printk(__ioremap(): phys addr 0x%llx is RAM lr %p\n,
   (unsigned long long)p, __builtin_return_address(0));
return NULL;
diff --git a/include/linux/lmb.h b/include/linux/lmb.h
index 2442e3f..ef82b8f 100644
--- a/include/linux/lmb.h
+++ b/include/linux/lmb.h
@@ -54,6 +54,7 @@ extern u64 __init lmb_phys_mem_size(void);
 extern u64 lmb_end_of_DRAM(void);
 extern void __init lmb_enforce_memory_limit(u64 memory_limit);
 extern int __init lmb_is_reserved(u64 addr);
+extern int lmb_is_region_reserved(u64 base, u64 size);
 extern int lmb_find(struct lmb_property *res);
 
 extern void lmb_dump_all(void);
diff --git a/lib/lmb.c b/lib/lmb.c
index 0343c05..9cee171 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -263,7 +263,7 @@ long __init lmb_reserve(u64 base, u64 size)
return lmb_add_region(_rgn, base, size);
 }
 
-long __init lmb_overlaps_region(struct lmb_region *rgn, u64 base, u64 size)
+long lmb_overlaps_region(struct lmb_region *rgn, u64 base, u64 size)
 {
unsigned long i;
 
@@ -493,6 +493,11 @@ int __init lmb_is_reserved(u64 addr)
return 0;
 }
 
+int lmb_is_region_reserved(u64 base, u64 size)
+{
+   return lmb_overlaps_region(lmb.reserved, base, size);
+}
+
 /*
  * Given a base, len, find which memory regions belong to this range.
  * Adjust the request and return a contiguous chunk.
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[PATCH v2 22/22] powerpc: wii: allow ioremap within the memory hole

2009-12-12 Thread Albert Herranz
Enable the flag that allows a platform to ioremap memory marked
as reserved.

This is currently needed on the Nintendo Wii video game console
due to the workaround introduced in wii: use both mem1 and mem2 as ram.

This will no longer be needed when proper discontig memory support
for 32-bit PowerPC is added to the kernel.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
---
 arch/powerpc/platforms/embedded6xx/wii.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/wii.c 
b/arch/powerpc/platforms/embedded6xx/wii.c
index de0c1e3..57e5b60 100644
--- a/arch/powerpc/platforms/embedded6xx/wii.c
+++ b/arch/powerpc/platforms/embedded6xx/wii.c
@@ -97,6 +97,9 @@ void __init wii_memory_fixups(void)
 
/* reserve the hole */
lmb_reserve(wii_hole_start, wii_hole_size);
+
+   /* allow ioremapping the address space in the hole */
+   __allow_ioremap_reserved = 1;
 }
 
 unsigned long __init wii_mmu_mapin_mem2(unsigned long top)
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH v2 0/6] powerpc: nintendo wii support

2009-12-11 Thread Albert Herranz
Grant Likely wrote:
 Hi Albert.
 

Hi,

 I'm ready to pick up your Gamecube and Wii patch sets for merging.
 You seem to have 4 distinct patch sets.  What order do they need to be
 applied in, and what kernel version are they based on?
 

The patches were based on 2.6.32-rc8.
The apply order should be:

v2 powerpc: nintendo gamecube support
 powerpc: gamecube/wii: usbgecko bootwrapper console support
 powerpc: gamecube: device tree
 powerpc: gamecube: bootwrapper bits
 powerpc: gamecube/wii: introduce GAMECUBE_COMMON
 powerpc: gamecube/wii: declare as non-coherent platforms
 powerpc: gamecube/wii: do not include PCI support
 powerpc: gamecube/wii: udbg support for usbgecko
 powerpc: gamecube/wii: flipper interrupt controller support
 powerpc: gamecube: platform support
 powerpc: gamecube: default config

v2 powerpc: nintendo wii support
 powerpc: wii: device tree
 powerpc: wii: bootwrapper bits
 powerpc: broadway processor support
 powerpc: wii: hollywood interrupt controller support
 powerpc: wii: platform support
 powerpc: wii: default config

v4 rework of usbgecko-based early debug
 powerpc: reserve fixmap entries for early debug
 powerpc: gamecube/wii: early debugging using usbgecko

v2 powerpc: wii: mem2 as ram support
 wii: bootwrapper: add fixup to calc useable mem2
 wii: use both mem1 and mem2 as ram
 powerpc: allow ioremap within reserved memory regions
 powerpc: wii: allow ioremap within the memory hole

But if you prefer it, I can re-send them as one patch set again rebased on top 
of v2.6.32.

 Thanks,
 g.

Thanks,
Albert
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH v2 3/4] powerpc: allow ioremap within reserved memory regions

2009-12-11 Thread Albert Herranz
Benjamin Herrenschmidt wrote:
 On Tue, 2009-12-08 at 19:43 +0100, Albert Herranz wrote:
 Signed-off-by: Albert Herranz albert_herr...@yahoo.es
 
 Acked-by: Benjamin Herrenschmidt b...@kernel.crashing.org
 
 ---
 v1 - v2
 - use a run-time flag to allow/disallow remapping reserved regions
 - use lmbs to determine reserved regions
 
 We won't need that once we fix proper discontig mem.
 
 BTW. Question: Why do we need that fixup of yours to fold the 2 LMBs
 into one ?
 
 Wouldn't it be easier just to keep the 2 LMBs ? You already fix the
 mapin_ram thingy, so you could easily fix it up to just iterate over the
 LMBs instead no ? For now, it could only BAT map the first LMB to
 simplify things and we can fix the BAT mapping for the second one in a
 second step too.
 
 Wouldn't that work with simpler code ? An in the case of ioremap, the
 test becomes simply to check if it's RAM by checking if it's in the LMB
 rather than if it's reserved, which should be easier and wouldn't
 require your flag to enable the tweak since it could perfectly be kept
 as standard behaviour
 
 Also the code in arch/powerpc/mm/mem.c will already deal with holes
 just fine and will pass the hole size information to the VM which should
 make it behave properly.
 
 Thus I have the feeling that keeping the 2 LMBs rather than coalescing
 would simplify the code basically by only requiring a small fixup of the
 maping RAM bit.
 
 I'm acking the patches for now, so you can always come up with a fixup
 on top of them and we can merge the current ones.
 

I'll look into this.
I used a single lmb range just as the current code does to avoid any unwanted 
side effects as I didn't audit all the mm code.

Thanks,
Albert
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v2 1/4] wii: bootwrapper: add fixup to calc useable mem2

2009-12-08 Thread Albert Herranz
The top portion of MEM2 (the second 64MB memory block) in the Nintendo
Wii video game console is used by the firmware running on the Starlet
processor.

Add code to calculate the portion of MEM2 safely useable by the
Broadway processor. When running under the 'mini' firmware this is
easily determined from an in-memory header. Otherwise, a safe default
is used.

Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/boot/wii.c |  118 +-
 1 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/boot/wii.c b/arch/powerpc/boot/wii.c
index d0e2625..2ebaec0 100644
--- a/arch/powerpc/boot/wii.c
+++ b/arch/powerpc/boot/wii.c
@@ -22,10 +22,120 @@
 
 BSS_STACK(8192);
 
-#define HW_REG(x)  ((void *)(x))
+#define HW_REG(x)  ((void *)(x))
 
-#define EXI_CTRL   HW_REG(0x0d800070)
-#define EXI_CTRL_ENABLE(10)
+#define EXI_CTRL   HW_REG(0x0d800070)
+#define EXI_CTRL_ENABLE(10)
+
+#define MEM2_TOP   (0x1000 + 64*1024*1024)
+#define FIRMWARE_DEFAULT_SIZE  (12*1024*1024)
+
+
+struct mipc_infohdr {
+   char magic[3];
+   u8 version;
+   u32 mem2_boundary;
+   u32 ipc_in;
+   size_t ipc_in_size;
+   u32 ipc_out;
+   size_t ipc_out_size;
+};
+
+static int mipc_check_address(u32 pa)
+{
+   /* only MEM2 addresses */
+   if (pa  0x1000 || pa  0x1400)
+   return -EINVAL;
+   return 0;
+}
+
+static struct mipc_infohdr *mipc_get_infohdr(void)
+{
+   struct mipc_infohdr **hdrp, *hdr;
+
+   /* 'mini' header pointer is the last word of MEM2 memory */
+   hdrp = (struct mipc_infohdr **)0x13fc;
+   if (mipc_check_address((u32)hdrp)) {
+   printf(mini: invalid hdrp %08X\n, (u32)hdrp);
+   hdr = NULL;
+   goto out;
+   }
+
+   hdr = *hdrp;
+   if (mipc_check_address((u32)hdr)) {
+   printf(mini: invalid hdr %08X\n, (u32)hdr);
+   hdr = NULL;
+   goto out;
+   }
+   if (memcmp(hdr-magic, IPC, 3)) {
+   printf(mini: invalid magic\n);
+   hdr = NULL;
+   goto out;
+   }
+
+out:
+   return hdr;
+}
+
+static int mipc_get_mem2_boundary(u32 *mem2_boundary)
+{
+   struct mipc_infohdr *hdr;
+   int error;
+
+   hdr = mipc_get_infohdr();
+   if (!hdr) {
+   error = -1;
+   goto out;
+   }
+
+   if (mipc_check_address(hdr-mem2_boundary)) {
+   printf(mini: invalid mem2_boundary %08X\n,
+  hdr-mem2_boundary);
+   error = -EINVAL;
+   goto out;
+   }
+   *mem2_boundary = hdr-mem2_boundary;
+   error = 0;
+out:
+   return error;
+
+}
+
+static void platform_fixups(void)
+{
+   void *mem;
+   u32 reg[4];
+   u32 mem2_boundary;
+   int len;
+   int error;
+
+   mem = finddevice(/memory);
+   if (!mem)
+   fatal(Can't find memory node\n);
+
+   /* two ranges of (address, size) words */
+   len = getprop(mem, reg, reg, sizeof(reg));
+   if (len != sizeof(reg)) {
+   /* nothing to do */
+   goto out;
+   }
+
+   /* retrieve MEM2 boundary from 'mini' */
+   error = mipc_get_mem2_boundary(mem2_boundary);
+   if (error) {
+   /* if that fails use a sane value */
+   mem2_boundary = MEM2_TOP - FIRMWARE_DEFAULT_SIZE;
+   }
+
+   if (mem2_boundary  reg[2]  mem2_boundary  reg[2] + reg[3]) {
+   reg[3] = mem2_boundary - reg[2];
+   printf(top of MEM2 @ %08X\n, reg[2] + reg[3]);
+   setprop(mem, reg, reg, sizeof(reg));
+   }
+
+out:
+   return;
+}
 
 void platform_init(unsigned long r3, unsigned long r4, unsigned long r5)
 {
@@ -42,5 +152,7 @@ void platform_init(unsigned long r3, unsigned long r4, 
unsigned long r5)
 
if (ug_probe())
console_ops.write = ug_console_write;
+
+   platform_ops.fixups = platform_fixups;
 }
 
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v2 2/4] wii: use both mem1 and mem2 as ram

2009-12-08 Thread Albert Herranz
Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/mm/init_32.c|4 ++
 arch/powerpc/mm/mmu_decl.h   |   10 -
 arch/powerpc/mm/pgtable_32.c |   32 +--
 arch/powerpc/mm/ppc_mmu_32.c |4 +-
 arch/powerpc/platforms/embedded6xx/wii.c |   63 ++
 5 files changed, 106 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index 9ddcfb4..703c7c2 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -131,9 +131,13 @@ void __init MMU_init(void)
MMU_setup();
 
if (lmb.memory.cnt  1) {
+#ifndef CONFIG_WII
lmb.memory.cnt = 1;
lmb_analyze();
printk(KERN_WARNING Only using first contiguous memory 
region);
+#else
+   wii_memory_fixups();
+#endif
}
 
total_lowmem = total_memory = lmb_end_of_DRAM() - memstart_addr;
diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h
index d2e5321..9aa39fe 100644
--- a/arch/powerpc/mm/mmu_decl.h
+++ b/arch/powerpc/mm/mmu_decl.h
@@ -136,6 +136,14 @@ extern phys_addr_t total_lowmem;
 extern phys_addr_t memstart_addr;
 extern phys_addr_t lowmem_end_addr;
 
+#ifdef CONFIG_WII
+extern unsigned long wii_hole_start;
+extern unsigned long wii_hole_size;
+
+extern unsigned long wii_mmu_mapin_mem2(unsigned long top);
+extern void wii_memory_fixups(void);
+#endif
+
 /* ...and now those things that may be slightly different between processor
  * architectures.  -- Dan
  */
@@ -155,5 +163,5 @@ extern void adjust_total_lowmem(void);
 #elif defined(CONFIG_PPC32)
 /* anything 32-bit except 4xx or 8xx */
 extern void MMU_init_hw(void);
-extern unsigned long mmu_mapin_ram(void);
+extern unsigned long mmu_mapin_ram(unsigned long top);
 #endif
diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index cb96cb2..b55bbe8 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -283,18 +283,18 @@ int map_page(unsigned long va, phys_addr_t pa, int flags)
 }
 
 /*
- * Map in a big chunk of physical memory starting at PAGE_OFFSET.
+ * Map in a chunk of physical memory starting at start.
  */
-void __init mapin_ram(void)
+void __init __mapin_ram_chunk(unsigned long offset, unsigned long top)
 {
unsigned long v, s, f;
phys_addr_t p;
int ktext;
 
-   s = mmu_mapin_ram();
+   s = offset;
v = PAGE_OFFSET + s;
p = memstart_addr + s;
-   for (; s  total_lowmem; s += PAGE_SIZE) {
+   for (; s  top; s += PAGE_SIZE) {
ktext = ((char *) v = _stext  (char *) v  etext);
f = ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL;
map_page(v, p, f);
@@ -307,6 +307,30 @@ void __init mapin_ram(void)
}
 }
 
+void __init mapin_ram(void)
+{
+   unsigned long s, top;
+
+#ifndef CONFIG_WII
+   top = total_lowmem;
+   s = mmu_mapin_ram(top);
+   __mapin_ram_chunk(s, top);
+#else
+   if (!wii_hole_size) {
+   s = mmu_mapin_ram(total_lowmem);
+   __mapin_ram_chunk(s, total_lowmem);
+   } else {
+   top = wii_hole_start;
+   s = mmu_mapin_ram(top);
+   __mapin_ram_chunk(s, top);
+
+   top = lmb_end_of_DRAM();
+   s = wii_mmu_mapin_mem2(top);
+   __mapin_ram_chunk(s, top);
+   }
+#endif
+}
+
 /* Scan the real Linux page tables and return a PTE pointer for
  * a virtual address in a context.
  * Returns true (1) if PTE was found, zero otherwise.  The pointer to
diff --git a/arch/powerpc/mm/ppc_mmu_32.c b/arch/powerpc/mm/ppc_mmu_32.c
index 2d2a87e..f11c2cd 100644
--- a/arch/powerpc/mm/ppc_mmu_32.c
+++ b/arch/powerpc/mm/ppc_mmu_32.c
@@ -72,7 +72,7 @@ unsigned long p_mapped_by_bats(phys_addr_t pa)
return 0;
 }
 
-unsigned long __init mmu_mapin_ram(void)
+unsigned long __init mmu_mapin_ram(unsigned long top)
 {
unsigned long tot, bl, done;
unsigned long max_size = (25620);
@@ -86,7 +86,7 @@ unsigned long __init mmu_mapin_ram(void)
 
/* Make sure we don't map a block larger than the
   smallest alignment of the physical address. */
-   tot = total_lowmem;
+   tot = top;
for (bl = 12810; bl  max_size; bl = 1) {
if (bl * 2  tot)
break;
diff --git a/arch/powerpc/platforms/embedded6xx/wii.c 
b/arch/powerpc/platforms/embedded6xx/wii.c
index 1bd41cc..5eaed86 100644
--- a/arch/powerpc/platforms/embedded6xx/wii.c
+++ b/arch/powerpc/platforms/embedded6xx/wii.c
@@ -20,6 +20,8 @@
 #include linux/seq_file.h
 #include linux/kexec.h
 #include linux/of_platform.h
+#include linux/lmb.h
+#include mm/mmu_decl.h
 
 #include asm/io.h
 #include asm/machdep.h
@@ -52,6 +54,67 @@
 static void __iomem *hw_ctrl;
 static void __iomem *hw_gpio;
 
+unsigned long wii_hole_start;
+unsigned long wii_hole_size;
+
+
+static int page_aligned

[RFC PATCH v2 3/4] powerpc: allow ioremap within reserved memory regions

2009-12-08 Thread Albert Herranz
Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
v1 - v2
- use a run-time flag to allow/disallow remapping reserved regions
- use lmbs to determine reserved regions

 arch/powerpc/mm/init_32.c|5 +
 arch/powerpc/mm/mmu_decl.h   |1 +
 arch/powerpc/mm/pgtable_32.c |4 +++-
 include/linux/lmb.h  |1 +
 lib/lmb.c|7 ++-
 5 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index 703c7c2..4ec900a 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -82,6 +82,11 @@ extern struct task_struct *current_set[NR_CPUS];
 int __map_without_bats;
 int __map_without_ltlbs;
 
+/*
+ * This tells the system to allow ioremapping memory marked as reserved.
+ */
+int __allow_ioremap_reserved;
+
 /* max amount of low RAM to map in */
 unsigned long __max_low_memory = MAX_LOW_MEM;
 
diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h
index 9aa39fe..34dacc3 100644
--- a/arch/powerpc/mm/mmu_decl.h
+++ b/arch/powerpc/mm/mmu_decl.h
@@ -115,6 +115,7 @@ extern void settlbcam(int index, unsigned long virt, 
phys_addr_t phys,
 extern void invalidate_tlbcam_entry(int index);
 
 extern int __map_without_bats;
+extern int __allow_ioremap_reserved;
 extern unsigned long ioremap_base;
 extern unsigned int rtas_data, rtas_size;
 
diff --git a/arch/powerpc/mm/pgtable_32.c b/arch/powerpc/mm/pgtable_32.c
index b55bbe8..177e403 100644
--- a/arch/powerpc/mm/pgtable_32.c
+++ b/arch/powerpc/mm/pgtable_32.c
@@ -26,6 +26,7 @@
 #include linux/vmalloc.h
 #include linux/init.h
 #include linux/highmem.h
+#include linux/lmb.h
 
 #include asm/pgtable.h
 #include asm/pgalloc.h
@@ -191,7 +192,8 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, 
unsigned long flags,
 * Don't allow anybody to remap normal RAM that we're using.
 * mem_init() sets high_memory so only do the check after that.
 */
-   if (mem_init_done  (p  virt_to_phys(high_memory))) {
+   if (mem_init_done  (p  virt_to_phys(high_memory)) 
+   !(__allow_ioremap_reserved  lmb_is_region_reserved(p, size))) {
printk(__ioremap(): phys addr 0x%llx is RAM lr %p\n,
   (unsigned long long)p, __builtin_return_address(0));
return NULL;
diff --git a/include/linux/lmb.h b/include/linux/lmb.h
index 2442e3f..ef82b8f 100644
--- a/include/linux/lmb.h
+++ b/include/linux/lmb.h
@@ -54,6 +54,7 @@ extern u64 __init lmb_phys_mem_size(void);
 extern u64 lmb_end_of_DRAM(void);
 extern void __init lmb_enforce_memory_limit(u64 memory_limit);
 extern int __init lmb_is_reserved(u64 addr);
+extern int lmb_is_region_reserved(u64 base, u64 size);
 extern int lmb_find(struct lmb_property *res);
 
 extern void lmb_dump_all(void);
diff --git a/lib/lmb.c b/lib/lmb.c
index 0343c05..9cee171 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -263,7 +263,7 @@ long __init lmb_reserve(u64 base, u64 size)
return lmb_add_region(_rgn, base, size);
 }
 
-long __init lmb_overlaps_region(struct lmb_region *rgn, u64 base, u64 size)
+long lmb_overlaps_region(struct lmb_region *rgn, u64 base, u64 size)
 {
unsigned long i;
 
@@ -493,6 +493,11 @@ int __init lmb_is_reserved(u64 addr)
return 0;
 }
 
+int lmb_is_region_reserved(u64 base, u64 size)
+{
+   return lmb_overlaps_region(lmb.reserved, base, size);
+}
+
 /*
  * Given a base, len, find which memory regions belong to this range.
  * Adjust the request and return a contiguous chunk.
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v2 4/4] powerpc: wii: allow ioremap within the memory hole

2009-12-08 Thread Albert Herranz
Signed-off-by: Albert Herranz albert_herr...@yahoo.es
---
 arch/powerpc/platforms/embedded6xx/wii.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/platforms/embedded6xx/wii.c 
b/arch/powerpc/platforms/embedded6xx/wii.c
index 5eaed86..0df8a91 100644
--- a/arch/powerpc/platforms/embedded6xx/wii.c
+++ b/arch/powerpc/platforms/embedded6xx/wii.c
@@ -97,6 +97,9 @@ void __init wii_memory_fixups(void)
 
/* reserve the hole */
lmb_reserve(wii_hole_start, wii_hole_size);
+
+   /* allow ioremapping the address space in the hole */
+   __allow_ioremap_reserved = 1;
 }
 
 unsigned long __init wii_mmu_mapin_mem2(unsigned long top)
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH v4 2/2] powerpc: gamecube/wii: early debugging using usbgecko

2009-12-04 Thread Albert Herranz
Segher Boessenkool wrote:
 +#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
 +setup_usbgecko_bat:
 +/* prepare a BAT for early io */
 +#if defined(CONFIG_GAMECUBE)
 +lisr8, 0x0c00
 +#elif defined(CONFIG_WII)
 +lisr8, 0x0d00
 +#else
 +#error Invalid platform for USB Gecko based early debugging.
 +#endif
 
 A kernel with both CONFIG_WII and CONFIG_GAMECUBE works fine
 on either, right?  If so, could you please switch the two #ifs?
 A dual-platform kernel will be used on a Wii much more likely
 than on a GC.
 

Nope, a GameCube kernel currently doesn't work on a Wii and the same the other 
way around.

But I can make that particular check a runtime check.
The idea would be to enclose that snippet in GAMECUBE_COMMON and check the PVR. 
If it is a Gekko (a fixed value) then we have a GameCube, otherwise we assume a 
Wii.

 +/*
 + * The virtual address used must match the virtual address
 + * associated to the fixmap entry FIX_EARLY_DEBUG_BASE.
 + */
 +lisr11, 0xfffe/* top 128K */
 +orir8, r8, 0x002a/* uncached, guarded ,rw */
 +orir11, r11, 0x3/* 128K */
 
 I think you should clear Vp since the BAT mapping can survive until
 after user space is started; it won't hurt to remove it either way.
 So 2 instead of 3.  And put the meaning in the comment :-)

This BAT is re-setup again on MMU_init, way before starting userspace.
But I'll make it Vs=1, Vp=0 here too :)

 
 Looks fine otherwise.
 

Thanks.

 
 Segher
 
 

Cheers,
Albert
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


Re: [RFC PATCH v2 1/6] powerpc: wii: device tree

2009-12-04 Thread Albert Herranz
Segher Boessenkool wrote:
 Add a device tree source file for the Nintendo Wii video game console.

 Signed-off-by: Albert Herranz albert_herr...@yahoo.es
 
 Acked-by: Segher Boessenkool seg...@kernel.crashing.org
 
 Great work Albert!
 

Thanks!

Cheers,
Albert


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v4 1/2] powerpc: reserve fixmap entries for early debug

2009-12-03 Thread Albert Herranz
Add a set of entries to the fixmap table to allow usage of known
reserved virtual address space by early debug code.

The address space reserved is the top 128K of the 32-bit address
space. This allows, if required, the use of a BAT to do the mappings.

Signed-off-by: Albert Herranz albert_herr...@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..5c2c023 100644
--- a/arch/powerpc/include/asm/fixmap.h
+++ b/arch/powerpc/include/asm/fixmap.h
@@ -44,6 +44,9 @@
  */
 enum fixed_addresses {
FIX_HOLE,
+   /* reserve the top 128K for early debugging purposes */
+   FIX_EARLY_DEBUG_TOP = FIX_HOLE,
+   FIX_EARLY_DEBUG_BASE = FIX_EARLY_DEBUG_TOP+((128*1024)/PAGE_SIZE)-1,
 #ifdef CONFIG_HIGHMEM
FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
-- 
1.6.3.3

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v4 0/2] rework of usbgecko-based early debug

2009-12-03 Thread Albert Herranz
This is v4 of the early debugging using usbgecko patch.

It tries to implement the ideas suggested by Benjamin Herrenschmidt
regarding the use of a set of fixmap entries to provide safe
virtual address space for an early mapping.

Albert Herranz (2):
  powerpc: reserve fixmap entries for early debug
  powerpc: gamecube/wii: early debugging using usbgecko

 arch/powerpc/Kconfig.debug |8 +++
 arch/powerpc/include/asm/fixmap.h  |3 +
 arch/powerpc/include/asm/udbg.h|1 +
 arch/powerpc/kernel/head_32.S  |   25 +
 arch/powerpc/kernel/udbg.c |2 +
 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c |   56 
 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h |2 +
 7 files changed, 97 insertions(+), 0 deletions(-)

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev


[RFC PATCH v4 2/2] powerpc: gamecube/wii: early debugging using usbgecko

2009-12-03 Thread Albert Herranz
Add support for using the USB Gecko adapter as an early debugging
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_herr...@yahoo.es
---
 arch/powerpc/Kconfig.debug |8 +++
 arch/powerpc/include/asm/udbg.h|1 +
 arch/powerpc/kernel/head_32.S  |   25 +
 arch/powerpc/kernel/udbg.c |2 +
 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c |   56 
 arch/powerpc/platforms/embedded6xx/usbgecko_udbg.h |2 +
 6 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug
index 3b10051..11e385b 100644
--- a/arch/powerpc/Kconfig.debug
+++ b/arch/powerpc/Kconfig.debug
@@ -254,6 +254,14 @@ config PPC_EARLY_DEBUG_CPM
  using a CPM-based serial port.  This assumes that the bootwrapper
  has run, and set up the CPM in a particular way.
 
+config PPC_EARLY_DEBUG_USBGECKO
+   bool Early debugging through the USB Gecko adapter
+   depends on GAMECUBE_COMMON
+   select USBGECKO_UDBG
+   help
+ Select this to enable early debugging for Nintendo GameCube/Wii
+ consoles via an external USB Gecko adapter.
+
 endchoice
 
 config PPC_EARLY_DEBUG_44x_PHYSLOW
diff --git a/arch/powerpc/include/asm/udbg.h b/arch/powerpc/include/asm/udbg.h
index cd21e5e..11ae699 100644
--- a/arch/powerpc/include/asm/udbg.h
+++ b/arch/powerpc/include/asm/udbg.h
@@ -51,6 +51,7 @@ extern void __init udbg_init_btext(void);
 extern void __init udbg_init_44x_as1(void);
 extern void __init udbg_init_40x_realmode(void);
 extern void __init udbg_init_cpm(void);
+extern void __init udbg_init_usbgecko(void);
 
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_UDBG_H */
diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S
index 829c3fe..00b89c0 100644
--- a/arch/powerpc/kernel/head_32.S
+++ b/arch/powerpc/kernel/head_32.S
@@ -164,6 +164,9 @@ __after_mmu_off:
 #ifdef CONFIG_PPC_EARLY_DEBUG_CPM
bl  setup_cpm_bat
 #endif
+#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
+   bl  setup_usbgecko_bat
+#endif
 
 /*
  * Call setup_cpu for CPU 0 and initialize 6xx Idle
@@ -1203,6 +1206,28 @@ setup_cpm_bat:
blr
 #endif
 
+#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
+setup_usbgecko_bat:
+   /* prepare a BAT for early io */
+#if defined(CONFIG_GAMECUBE)
+   lis r8, 0x0c00
+#elif defined(CONFIG_WII)
+   lis r8, 0x0d00
+#else
+#error Invalid platform for USB Gecko based early debugging.
+#endif
+   /*
+* The virtual address used must match the virtual address
+* associated to the fixmap entry FIX_EARLY_DEBUG_BASE.
+*/
+   lis r11, 0xfffe /* top 128K */
+   ori r8, r8, 0x002a  /* uncached, guarded ,rw */
+   ori r11, r11, 0x3   /* 128K */
+   mtspr   SPRN_DBAT1L, r8
+   mtspr   SPRN_DBAT1U, r11
+   blr
+#endif
+
 #ifdef CONFIG_8260
 /* Jump into the system reset for the rom.
  * We first disable the MMU, and then jump to the ROM reset address.
diff --git a/arch/powerpc/kernel/udbg.c b/arch/powerpc/kernel/udbg.c
index fc9af47..e39cad8 100644
--- a/arch/powerpc/kernel/udbg.c
+++ b/arch/powerpc/kernel/udbg.c
@@ -60,6 +60,8 @@ void __init udbg_early_init(void)
udbg_init_40x_realmode();
 #elif defined(CONFIG_PPC_EARLY_DEBUG_CPM)
udbg_init_cpm();
+#elif defined(CONFIG_PPC_EARLY_DEBUG_USBGECKO)
+   udbg_init_usbgecko();
 #endif
 
 #ifdef CONFIG_PPC_EARLY_DEBUG
diff --git a/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c 
b/arch/powerpc/platforms/embedded6xx/usbgecko_udbg.c
index ba4c7cc..edc956c 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
 
 #include usbgecko_udbg.h
 
@@ -270,3 +271,58 @@ done:
of_node_put(np);
return;
 }
+
+#ifdef CONFIG_PPC_EARLY_DEBUG_USBGECKO
+
+static phys_addr_t __init ug_early_grab_io_addr(void)
+{
+#if defined(CONFIG_GAMECUBE)
+   return 0x0c00;
+#elif defined(CONFIG_WII)
+   return 0x0d00;
+#else
+#error Invalid platform for USB Gecko based early debugging.
+#endif
+}
+
+/*
+ * USB Gecko early debug support initialization for udbg.
+ */
+void __init udbg_init_usbgecko(void)
+{
+   void __iomem *early_debug_area;
+   void __iomem *exi_io_base;
+
+   /*
+* At this point we have a BAT already setup that enables I/O
+* to the EXI hardware.
+*
+* The BAT uses a virtual address range reserved at the fixmap.
+* This must match the virtual address configured in
+* head_32.S:setup_usbgecko_bat().
+*/
+   early_debug_area = (void __iomem

  1   2   >