linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] powerpc: Add of_parse_dma_window()
@ 2006-05-18  6:20 Jeremy Kerr
  2006-05-18  6:28 ` Jeremy Kerr
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Jeremy Kerr @ 2006-05-18  6:20 UTC (permalink / raw)
  To: linuxppc-dev

Add a function for generic parsing of dma-window properties (ie,
ibm,dma-window and ibm,my-dma-window) of pci and virtual device nodes.

This function will also be used by cell.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

 arch/powerpc/kernel/prom_parse.c |   23 +++++++++++++++++++++++
 include/asm-powerpc/prom.h       |    6 ++++++
 2 files changed, 29 insertions(+)

Index: linux-2.6/arch/powerpc/kernel/prom_parse.c
===================================================================
--- linux-2.6.orig/arch/powerpc/kernel/prom_parse.c
+++ linux-2.6/arch/powerpc/kernel/prom_parse.c
@@ -548,3 +548,26 @@ int of_pci_address_to_resource(struct de
 	return __of_address_to_resource(dev, addrp, size, flags, r);
 }
 EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
+
+void of_parse_dma_window(struct device_node *dn, unsigned char *dma_window_prop,
+		unsigned long *busno, unsigned long *phys, unsigned long *size)
+{
+	u32 *dma_window, cells;
+	unsigned char *prop;
+
+	dma_window = (u32 *)dma_window_prop;
+
+	/* busno is always one cell */
+	*busno = *(dma_window++);
+
+	prop = get_property(dn, "ibm,#dma-address-cells", NULL);
+	cells = prop ? *(u32 *)prop : prom_n_addr_cells(dn);
+	*phys = of_read_addr(dma_window, cells);
+
+	dma_window += cells;
+
+	prop = get_property(dn, "ibm,#dma-size-cells", NULL);
+	cells = prop ? *(u32 *)prop : prom_n_size_cells(dn);
+	*size = of_read_addr(dma_window, cells);
+}
+EXPORT_SYMBOL_GPL(of_parse_dma_window);
Index: linux-2.6/include/asm-powerpc/prom.h
===================================================================
--- linux-2.6.orig/include/asm-powerpc/prom.h
+++ linux-2.6/include/asm-powerpc/prom.h
@@ -230,6 +230,12 @@ extern int of_address_to_resource(struct
 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
 				      struct resource *r);
 
+/* Parse the ibm,dma-window property of an OF node into the busno, phys and
+ * size parameters.
+ */
+void of_parse_dma_window(struct device_node *dn, unsigned char *dma_window_prop,
+		unsigned long *busno, unsigned long *phys, unsigned long *size);
+
 extern void kdump_move_device_tree(void);
 
 #endif /* __KERNEL__ */

To: linuxppc-dev@ozlabs.org
From: Jeremy Kerr <jk@ozlabs.org>
Date: Thu, 18 May 2006 16:20:51 +1000
Subject: [PATCH 2/2] powerpc: pseries: Use generic dma-window parsing function
Message-Id: <1147933251.472945.297063284077.qpush@pokey>

Change the pseries iommu init code to use the new of_parse_dma_window()
to parse the ibm,dma-window and ibm,my-dma-window properties of pci and
virtual device nodes.

Also, clean up vio_build_iommu_table() a little.

Tested on pseries, with both vio and pci devices.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

 arch/powerpc/platforms/pseries/iommu.c |   29 ++++++++++-------------------
 arch/powerpc/platforms/pseries/vio.c   |   32 ++++++++++++++------------------
 2 files changed, 24 insertions(+), 37 deletions(-)

Index: linux-2.6/arch/powerpc/platforms/pseries/iommu.c
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/pseries/iommu.c
+++ linux-2.6/arch/powerpc/platforms/pseries/iommu.c
@@ -299,30 +299,22 @@ static void iommu_table_setparms(struct 
  * iommu_table_setparms_lpar
  *
  * Function: On pSeries LPAR systems, return TCE table info, given a pci bus.
- *
- * ToDo: properly interpret the ibm,dma-window property.  The definition is:
- *	logical-bus-number	(1 word)
- *	phys-address		(#address-cells words)
- *	size			(#cell-size words)
- *
- * Currently we hard code these sizes (more or less).
  */
 static void iommu_table_setparms_lpar(struct pci_controller *phb,
 				      struct device_node *dn,
 				      struct iommu_table *tbl,
-				      unsigned int *dma_window)
+				      unsigned char *dma_window)
 {
+	unsigned long offset, size;
+
 	tbl->it_busno  = PCI_DN(dn)->bussubno;
+	of_parse_dma_window(dn, dma_window, &tbl->it_index, &offset, &size);
 
-	/* TODO: Parse field size properties properly. */
-	tbl->it_size   = (((unsigned long)dma_window[4] << 32) |
-			   (unsigned long)dma_window[5]) >> PAGE_SHIFT;
-	tbl->it_offset = (((unsigned long)dma_window[2] << 32) |
-			   (unsigned long)dma_window[3]) >> PAGE_SHIFT;
 	tbl->it_base   = 0;
-	tbl->it_index  = dma_window[0];
 	tbl->it_blocksize  = 16;
 	tbl->it_type = TCE_PCI;
+	tbl->it_offset = offset >> PAGE_SHIFT;
+	tbl->it_size = size >> PAGE_SHIFT;
 }
 
 static void iommu_bus_setup_pSeries(struct pci_bus *bus)
@@ -414,7 +406,7 @@ static void iommu_bus_setup_pSeriesLP(st
 	struct iommu_table *tbl;
 	struct device_node *dn, *pdn;
 	struct pci_dn *ppci;
-	unsigned int *dma_window = NULL;
+	unsigned char *dma_window = NULL;
 
 	DBG("iommu_bus_setup_pSeriesLP, bus %p, bus->self %p\n", bus, bus->self);
 
@@ -422,7 +414,7 @@ static void iommu_bus_setup_pSeriesLP(st
 
 	/* Find nearest ibm,dma-window, walking up the device tree */
 	for (pdn = dn; pdn != NULL; pdn = pdn->parent) {
-		dma_window = (unsigned int *)get_property(pdn, "ibm,dma-window", NULL);
+		dma_window = get_property(pdn, "ibm,dma-window", NULL);
 		if (dma_window != NULL)
 			break;
 	}
@@ -516,7 +508,7 @@ static void iommu_dev_setup_pSeriesLP(st
 {
 	struct device_node *pdn, *dn;
 	struct iommu_table *tbl;
-	int *dma_window = NULL;
+	unsigned char *dma_window = NULL;
 	struct pci_dn *pci;
 
 	DBG("iommu_dev_setup_pSeriesLP, dev %p (%s)\n", dev, pci_name(dev));
@@ -531,8 +523,7 @@ static void iommu_dev_setup_pSeriesLP(st
 
 	for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->iommu_table;
 	     pdn = pdn->parent) {
-		dma_window = (unsigned int *)
-			get_property(pdn, "ibm,dma-window", NULL);
+		dma_window = get_property(pdn, "ibm,dma-window", NULL);
 		if (dma_window)
 			break;
 	}
Index: linux-2.6/arch/powerpc/platforms/pseries/vio.c
===================================================================
--- linux-2.6.orig/arch/powerpc/platforms/pseries/vio.c
+++ linux-2.6/arch/powerpc/platforms/pseries/vio.c
@@ -108,32 +108,28 @@ __initcall(vio_bus_init_pseries);
 */
 static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev)
 {
-	unsigned int *dma_window;
-	struct iommu_table *newTceTable;
-	unsigned long offset;
-	int dma_window_property_size;
+	unsigned char *dma_window;
+	struct iommu_table *tbl;
+	unsigned long offset, size;
 
-	dma_window = (unsigned int *) get_property(dev->dev.platform_data, "ibm,my-dma-window", &dma_window_property_size);
-	if(!dma_window) {
+	dma_window = get_property(dev->dev.platform_data,
+			"ibm,my-dma-window", NULL);
+	if (!dma_window)
 		return NULL;
-	}
 
-	newTceTable = (struct iommu_table *) kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
+	tbl = (struct iommu_table *)kmalloc(sizeof(*tbl), GFP_KERNEL);
 
-	/*  There should be some code to extract the phys-encoded offset
-		using prom_n_addr_cells(). However, according to a comment
-		on earlier versions, it's always zero, so we don't bother */
-	offset = dma_window[1] >>  PAGE_SHIFT;
+	of_parse_dma_window(dev->dev.platform_data, dma_window,
+			&tbl->it_index, &offset, &size);
 
 	/* TCE table size - measured in tce entries */
-	newTceTable->it_size		= dma_window[4] >> PAGE_SHIFT;
+	tbl->it_size	= size >> PAGE_SHIFT;
 	/* offset for VIO should always be 0 */
-	newTceTable->it_offset		= offset;
-	newTceTable->it_busno		= 0;
-	newTceTable->it_index		= (unsigned long)dma_window[0];
-	newTceTable->it_type		= TCE_VB;
+	tbl->it_offset	= offset >> PAGE_SHIFT;
+	tbl->it_busno	= 0;
+	tbl->it_type	= TCE_VB;
 
-	return iommu_init_table(newTceTable);
+	return iommu_init_table(tbl);
 }
 
 /**

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] powerpc: Add of_parse_dma_window()
  2006-05-18  6:20 [PATCH 1/2] powerpc: Add of_parse_dma_window() Jeremy Kerr
@ 2006-05-18  6:28 ` Jeremy Kerr
  2006-05-18 17:11 ` Olof Johansson
  2006-05-30 18:55 ` Kumar Gala
  2 siblings, 0 replies; 11+ messages in thread
From: Jeremy Kerr @ 2006-05-18  6:28 UTC (permalink / raw)
  To: linuxppc-dev

Whoa, looks like two mails got merged into one. A re-send is coming..


Jeremy

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/2] powerpc: Add of_parse_dma_window()
@ 2006-05-18  6:32 Jeremy Kerr
  2006-05-18 17:12 ` Olof Johansson
  0 siblings, 1 reply; 11+ messages in thread
From: Jeremy Kerr @ 2006-05-18  6:32 UTC (permalink / raw)
  To: linuxppc-dev

Add a function for generic parsing of dma-window properties (ie,
ibm,dma-window and ibm,my-dma-window) of pci and virtual device nodes.

This function will also be used by cell.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

 arch/powerpc/kernel/prom_parse.c |   23 +++++++++++++++++++++++
 include/asm-powerpc/prom.h       |    6 ++++++
 2 files changed, 29 insertions(+)

Index: linux-2.6/arch/powerpc/kernel/prom_parse.c
===================================================================
--- linux-2.6.orig/arch/powerpc/kernel/prom_parse.c
+++ linux-2.6/arch/powerpc/kernel/prom_parse.c
@@ -548,3 +548,26 @@ int of_pci_address_to_resource(struct de
 	return __of_address_to_resource(dev, addrp, size, flags, r);
 }
 EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
+
+void of_parse_dma_window(struct device_node *dn, unsigned char *dma_window_prop,
+		unsigned long *busno, unsigned long *phys, unsigned long *size)
+{
+	u32 *dma_window, cells;
+	unsigned char *prop;
+
+	dma_window = (u32 *)dma_window_prop;
+
+	/* busno is always one cell */
+	*busno = *(dma_window++);
+
+	prop = get_property(dn, "ibm,#dma-address-cells", NULL);
+	cells = prop ? *(u32 *)prop : prom_n_addr_cells(dn);
+	*phys = of_read_addr(dma_window, cells);
+
+	dma_window += cells;
+
+	prop = get_property(dn, "ibm,#dma-size-cells", NULL);
+	cells = prop ? *(u32 *)prop : prom_n_size_cells(dn);
+	*size = of_read_addr(dma_window, cells);
+}
+EXPORT_SYMBOL_GPL(of_parse_dma_window);
Index: linux-2.6/include/asm-powerpc/prom.h
===================================================================
--- linux-2.6.orig/include/asm-powerpc/prom.h
+++ linux-2.6/include/asm-powerpc/prom.h
@@ -230,6 +230,12 @@ extern int of_address_to_resource(struct
 extern int of_pci_address_to_resource(struct device_node *dev, int bar,
 				      struct resource *r);
 
+/* Parse the ibm,dma-window property of an OF node into the busno, phys and
+ * size parameters.
+ */
+void of_parse_dma_window(struct device_node *dn, unsigned char *dma_window_prop,
+		unsigned long *busno, unsigned long *phys, unsigned long *size);
+
 extern void kdump_move_device_tree(void);
 
 #endif /* __KERNEL__ */

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] powerpc: Add of_parse_dma_window()
  2006-05-18  6:20 [PATCH 1/2] powerpc: Add of_parse_dma_window() Jeremy Kerr
  2006-05-18  6:28 ` Jeremy Kerr
@ 2006-05-18 17:11 ` Olof Johansson
  2006-05-18 23:11   ` Segher Boessenkool
  2006-05-30 18:55 ` Kumar Gala
  2 siblings, 1 reply; 11+ messages in thread
From: Olof Johansson @ 2006-05-18 17:11 UTC (permalink / raw)
  To: Jeremy Kerr; +Cc: linuxppc-dev, paulus

On Thu, May 18, 2006 at 04:20:51PM +1000, Jeremy Kerr wrote:
> Add a function for generic parsing of dma-window properties (ie,
> ibm,dma-window and ibm,my-dma-window) of pci and virtual device nodes.
> 
> This function will also be used by cell.
> 
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

Acked-by: Olof Johansson <olof@lixom.net>

(I'm assuming you've booted it on POWER4 LPAR and JS20, I don't
have access to either to make sure it doesn't break there. Main worry
would be if it lacked ibm,#dma*-properties for some reason.)


> 
>  arch/powerpc/kernel/prom_parse.c |   23 +++++++++++++++++++++++
>  include/asm-powerpc/prom.h       |    6 ++++++
>  2 files changed, 29 insertions(+)
> 
> Index: linux-2.6/arch/powerpc/kernel/prom_parse.c
> ===================================================================
> --- linux-2.6.orig/arch/powerpc/kernel/prom_parse.c
> +++ linux-2.6/arch/powerpc/kernel/prom_parse.c
> @@ -548,3 +548,26 @@ int of_pci_address_to_resource(struct de
>  	return __of_address_to_resource(dev, addrp, size, flags, r);
>  }
>  EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
> +
> +void of_parse_dma_window(struct device_node *dn, unsigned char *dma_window_prop,
> +		unsigned long *busno, unsigned long *phys, unsigned long *size)
> +{
> +	u32 *dma_window, cells;
> +	unsigned char *prop;
> +
> +	dma_window = (u32 *)dma_window_prop;
> +
> +	/* busno is always one cell */
> +	*busno = *(dma_window++);
> +
> +	prop = get_property(dn, "ibm,#dma-address-cells", NULL);
> +	cells = prop ? *(u32 *)prop : prom_n_addr_cells(dn);
> +	*phys = of_read_addr(dma_window, cells);
> +
> +	dma_window += cells;
> +
> +	prop = get_property(dn, "ibm,#dma-size-cells", NULL);
> +	cells = prop ? *(u32 *)prop : prom_n_size_cells(dn);
> +	*size = of_read_addr(dma_window, cells);
> +}
> +EXPORT_SYMBOL_GPL(of_parse_dma_window);
> Index: linux-2.6/include/asm-powerpc/prom.h
> ===================================================================
> --- linux-2.6.orig/include/asm-powerpc/prom.h
> +++ linux-2.6/include/asm-powerpc/prom.h
> @@ -230,6 +230,12 @@ extern int of_address_to_resource(struct
>  extern int of_pci_address_to_resource(struct device_node *dev, int bar,
>  				      struct resource *r);
>  
> +/* Parse the ibm,dma-window property of an OF node into the busno, phys and
> + * size parameters.
> + */
> +void of_parse_dma_window(struct device_node *dn, unsigned char *dma_window_prop,
> +		unsigned long *busno, unsigned long *phys, unsigned long *size);
> +
>  extern void kdump_move_device_tree(void);
>  
>  #endif /* __KERNEL__ */
> 
> To: linuxppc-dev@ozlabs.org
> From: Jeremy Kerr <jk@ozlabs.org>
> Date: Thu, 18 May 2006 16:20:51 +1000
> Subject: [PATCH 2/2] powerpc: pseries: Use generic dma-window parsing function
> Message-Id: <1147933251.472945.297063284077.qpush@pokey>
> 
> Change the pseries iommu init code to use the new of_parse_dma_window()
> to parse the ibm,dma-window and ibm,my-dma-window properties of pci and
> virtual device nodes.
> 
> Also, clean up vio_build_iommu_table() a little.
> 
> Tested on pseries, with both vio and pci devices.
> 
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
> 
>  arch/powerpc/platforms/pseries/iommu.c |   29 ++++++++++-------------------
>  arch/powerpc/platforms/pseries/vio.c   |   32 ++++++++++++++------------------
>  2 files changed, 24 insertions(+), 37 deletions(-)
> 
> Index: linux-2.6/arch/powerpc/platforms/pseries/iommu.c
> ===================================================================
> --- linux-2.6.orig/arch/powerpc/platforms/pseries/iommu.c
> +++ linux-2.6/arch/powerpc/platforms/pseries/iommu.c
> @@ -299,30 +299,22 @@ static void iommu_table_setparms(struct 
>   * iommu_table_setparms_lpar
>   *
>   * Function: On pSeries LPAR systems, return TCE table info, given a pci bus.
> - *
> - * ToDo: properly interpret the ibm,dma-window property.  The definition is:
> - *	logical-bus-number	(1 word)
> - *	phys-address		(#address-cells words)
> - *	size			(#cell-size words)
> - *
> - * Currently we hard code these sizes (more or less).
>   */
>  static void iommu_table_setparms_lpar(struct pci_controller *phb,
>  				      struct device_node *dn,
>  				      struct iommu_table *tbl,
> -				      unsigned int *dma_window)
> +				      unsigned char *dma_window)
>  {
> +	unsigned long offset, size;
> +
>  	tbl->it_busno  = PCI_DN(dn)->bussubno;
> +	of_parse_dma_window(dn, dma_window, &tbl->it_index, &offset, &size);
>  
> -	/* TODO: Parse field size properties properly. */
> -	tbl->it_size   = (((unsigned long)dma_window[4] << 32) |
> -			   (unsigned long)dma_window[5]) >> PAGE_SHIFT;
> -	tbl->it_offset = (((unsigned long)dma_window[2] << 32) |
> -			   (unsigned long)dma_window[3]) >> PAGE_SHIFT;
>  	tbl->it_base   = 0;
> -	tbl->it_index  = dma_window[0];
>  	tbl->it_blocksize  = 16;
>  	tbl->it_type = TCE_PCI;
> +	tbl->it_offset = offset >> PAGE_SHIFT;
> +	tbl->it_size = size >> PAGE_SHIFT;
>  }
>  
>  static void iommu_bus_setup_pSeries(struct pci_bus *bus)
> @@ -414,7 +406,7 @@ static void iommu_bus_setup_pSeriesLP(st
>  	struct iommu_table *tbl;
>  	struct device_node *dn, *pdn;
>  	struct pci_dn *ppci;
> -	unsigned int *dma_window = NULL;
> +	unsigned char *dma_window = NULL;
>  
>  	DBG("iommu_bus_setup_pSeriesLP, bus %p, bus->self %p\n", bus, bus->self);
>  
> @@ -422,7 +414,7 @@ static void iommu_bus_setup_pSeriesLP(st
>  
>  	/* Find nearest ibm,dma-window, walking up the device tree */
>  	for (pdn = dn; pdn != NULL; pdn = pdn->parent) {
> -		dma_window = (unsigned int *)get_property(pdn, "ibm,dma-window", NULL);
> +		dma_window = get_property(pdn, "ibm,dma-window", NULL);
>  		if (dma_window != NULL)
>  			break;
>  	}
> @@ -516,7 +508,7 @@ static void iommu_dev_setup_pSeriesLP(st
>  {
>  	struct device_node *pdn, *dn;
>  	struct iommu_table *tbl;
> -	int *dma_window = NULL;
> +	unsigned char *dma_window = NULL;
>  	struct pci_dn *pci;
>  
>  	DBG("iommu_dev_setup_pSeriesLP, dev %p (%s)\n", dev, pci_name(dev));
> @@ -531,8 +523,7 @@ static void iommu_dev_setup_pSeriesLP(st
>  
>  	for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->iommu_table;
>  	     pdn = pdn->parent) {
> -		dma_window = (unsigned int *)
> -			get_property(pdn, "ibm,dma-window", NULL);
> +		dma_window = get_property(pdn, "ibm,dma-window", NULL);
>  		if (dma_window)
>  			break;
>  	}
> Index: linux-2.6/arch/powerpc/platforms/pseries/vio.c
> ===================================================================
> --- linux-2.6.orig/arch/powerpc/platforms/pseries/vio.c
> +++ linux-2.6/arch/powerpc/platforms/pseries/vio.c
> @@ -108,32 +108,28 @@ __initcall(vio_bus_init_pseries);
>  */
>  static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev)
>  {
> -	unsigned int *dma_window;
> -	struct iommu_table *newTceTable;
> -	unsigned long offset;
> -	int dma_window_property_size;
> +	unsigned char *dma_window;
> +	struct iommu_table *tbl;
> +	unsigned long offset, size;
>  
> -	dma_window = (unsigned int *) get_property(dev->dev.platform_data, "ibm,my-dma-window", &dma_window_property_size);
> -	if(!dma_window) {
> +	dma_window = get_property(dev->dev.platform_data,
> +			"ibm,my-dma-window", NULL);
> +	if (!dma_window)
>  		return NULL;
> -	}
>  
> -	newTceTable = (struct iommu_table *) kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
> +	tbl = (struct iommu_table *)kmalloc(sizeof(*tbl), GFP_KERNEL);
>  
> -	/*  There should be some code to extract the phys-encoded offset
> -		using prom_n_addr_cells(). However, according to a comment
> -		on earlier versions, it's always zero, so we don't bother */
> -	offset = dma_window[1] >>  PAGE_SHIFT;
> +	of_parse_dma_window(dev->dev.platform_data, dma_window,
> +			&tbl->it_index, &offset, &size);
>  
>  	/* TCE table size - measured in tce entries */
> -	newTceTable->it_size		= dma_window[4] >> PAGE_SHIFT;
> +	tbl->it_size	= size >> PAGE_SHIFT;
>  	/* offset for VIO should always be 0 */
> -	newTceTable->it_offset		= offset;
> -	newTceTable->it_busno		= 0;
> -	newTceTable->it_index		= (unsigned long)dma_window[0];
> -	newTceTable->it_type		= TCE_VB;
> +	tbl->it_offset	= offset >> PAGE_SHIFT;
> +	tbl->it_busno	= 0;
> +	tbl->it_type	= TCE_VB;
>  
> -	return iommu_init_table(newTceTable);
> +	return iommu_init_table(tbl);
>  }
>  
>  /**
> 
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] powerpc: Add of_parse_dma_window()
  2006-05-18  6:32 Jeremy Kerr
@ 2006-05-18 17:12 ` Olof Johansson
  0 siblings, 0 replies; 11+ messages in thread
From: Olof Johansson @ 2006-05-18 17:12 UTC (permalink / raw)
  To: Jeremy Kerr; +Cc: linuxppc-dev, paulus

On Thu, May 18, 2006 at 04:32:55PM +1000, Jeremy Kerr wrote:
> Add a function for generic parsing of dma-window properties (ie,
> ibm,dma-window and ibm,my-dma-window) of pci and virtual device nodes.
> 
> This function will also be used by cell.
> 
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
> 

Acked-by: Olof Johansson <olof@lixom.net>


(replied to the wrong email last time)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] powerpc: Add of_parse_dma_window()
  2006-05-18 17:11 ` Olof Johansson
@ 2006-05-18 23:11   ` Segher Boessenkool
  2006-05-18 23:13     ` Olof Johansson
  0 siblings, 1 reply; 11+ messages in thread
From: Segher Boessenkool @ 2006-05-18 23:11 UTC (permalink / raw)
  To: Olof Johansson; +Cc: linuxppc-dev, paulus

> Acked-by: Olof Johansson <olof@lixom.net>
>
> (I'm assuming you've booted it on POWER4 LPAR and JS20, I don't
> have access to either to make sure it doesn't break there. Main worry
> would be if it lacked ibm,#dma*-properties for some reason.)

The code seems to be resilient against that.  Haven't tested though.


Segher

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] powerpc: Add of_parse_dma_window()
  2006-05-18 23:11   ` Segher Boessenkool
@ 2006-05-18 23:13     ` Olof Johansson
  2006-05-18 23:55       ` Segher Boessenkool
  2006-05-30 18:38       ` [PATCH] fix of_parse_dma_window. was: " Will Schmidt
  0 siblings, 2 replies; 11+ messages in thread
From: Olof Johansson @ 2006-05-18 23:13 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: Olof Johansson, linuxppc-dev, paulus

On Fri, May 19, 2006 at 01:11:51AM +0200, Segher Boessenkool wrote:
> > Acked-by: Olof Johansson <olof@lixom.net>
> >
> > (I'm assuming you've booted it on POWER4 LPAR and JS20, I don't
> > have access to either to make sure it doesn't break there. Main worry
> > would be if it lacked ibm,#dma*-properties for some reason.)
> 
> The code seems to be resilient against that.  Haven't tested though.

Well, yes. I should have said: if it lacks the ibm,#dma- and the
normal addr-cells properties aren't the same as we assumed before.


-Olof

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] powerpc: Add of_parse_dma_window()
  2006-05-18 23:13     ` Olof Johansson
@ 2006-05-18 23:55       ` Segher Boessenkool
  2006-05-30 18:38       ` [PATCH] fix of_parse_dma_window. was: " Will Schmidt
  1 sibling, 0 replies; 11+ messages in thread
From: Segher Boessenkool @ 2006-05-18 23:55 UTC (permalink / raw)
  To: Olof Johansson; +Cc: linuxppc-dev, paulus

>> The code seems to be resilient against that.  Haven't tested though.
>
> Well, yes. I should have said: if it lacks the ibm,#dma- and the
> normal addr-cells properties aren't the same as we assumed before.

Missing #addr-cells means it's 2; does our code handle that correctly?
Sorry, too tired to check it myself :-)


Segher

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] fix of_parse_dma_window.      was: Re: [PATCH 1/2] powerpc: Add of_parse_dma_window()
  2006-05-18 23:13     ` Olof Johansson
  2006-05-18 23:55       ` Segher Boessenkool
@ 2006-05-30 18:38       ` Will Schmidt
  2006-05-31  4:17         ` Jeremy Kerr
  1 sibling, 1 reply; 11+ messages in thread
From: Will Schmidt @ 2006-05-30 18:38 UTC (permalink / raw)
  To: Olof Johansson, jk; +Cc: linuxppc-dev, paulus

On Thu, 2006-05-18 at 18:13 -0500, Olof Johansson wrote:
> On Fri, May 19, 2006 at 01:11:51AM +0200, Segher Boessenkool wrote:
> > > Acked-by: Olof Johansson <olof@lixom.net>
> > >
> > > (I'm assuming you've booted it on POWER4 LPAR and JS20, I don't
> > > have access to either to make sure it doesn't break there. Main worry
> > > would be if it lacked ibm,#dma*-properties for some reason.)
> > 
> > The code seems to be resilient against that.  Haven't tested though.
> 
> Well, yes. I should have said: if it lacks the ibm,#dma- and the
> normal addr-cells properties aren't the same as we assumed before.

My js20 appears to lack the ibm,#dma- properties, and boot fails with a
"Kernel panic - not syncing: iommu_init_table: Can't allocate 0 bytes"
message.  

This adds a fallback to the "#address-cells" property in case the
"#ibm,dma-address-cells" property is missing.   Tested on js20 and
power5 lpar.  

Unless there is a more elegant solution... :-)

Signed-off-by: Will Schmidt <willschm@us.ibm.com>


diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index 23bb060..45df420 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -561,6 +561,9 @@ void of_parse_dma_window(struct device_n
 	*busno = *(dma_window++);
 
 	prop = get_property(dn, "ibm,#dma-address-cells", NULL);
+	if (!prop)
+		prop = get_property(dn, "#address-cells", NULL);
+
 	cells = prop ? *(u32 *)prop : prom_n_addr_cells(dn);
 	*phys = of_read_addr(dma_window, cells);
 

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] powerpc: Add of_parse_dma_window()
  2006-05-18  6:20 [PATCH 1/2] powerpc: Add of_parse_dma_window() Jeremy Kerr
  2006-05-18  6:28 ` Jeremy Kerr
  2006-05-18 17:11 ` Olof Johansson
@ 2006-05-30 18:55 ` Kumar Gala
  2 siblings, 0 replies; 11+ messages in thread
From: Kumar Gala @ 2006-05-30 18:55 UTC (permalink / raw)
  To: Jeremy Kerr; +Cc: linuxppc-dev


On May 18, 2006, at 1:20 AM, Jeremy Kerr wrote:

> Add a function for generic parsing of dma-window properties (ie,
> ibm,dma-window and ibm,my-dma-window) of pci and virtual device nodes.
>
> This function will also be used by cell.

Any possibly of renaming this to of_parse_ibm_dma_window() since it  
handle an IBM specific attribute?

- kumar

>
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
>
>  arch/powerpc/kernel/prom_parse.c |   23 +++++++++++++++++++++++
>  include/asm-powerpc/prom.h       |    6 ++++++
>  2 files changed, 29 insertions(+)
>
> Index: linux-2.6/arch/powerpc/kernel/prom_parse.c
> ===================================================================
> --- linux-2.6.orig/arch/powerpc/kernel/prom_parse.c
> +++ linux-2.6/arch/powerpc/kernel/prom_parse.c
> @@ -548,3 +548,26 @@ int of_pci_address_to_resource(struct de
>  	return __of_address_to_resource(dev, addrp, size, flags, r);
>  }
>  EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
> +
> +void of_parse_dma_window(struct device_node *dn, unsigned char  
> *dma_window_prop,
> +		unsigned long *busno, unsigned long *phys, unsigned long *size)
> +{
> +	u32 *dma_window, cells;
> +	unsigned char *prop;
> +
> +	dma_window = (u32 *)dma_window_prop;
> +
> +	/* busno is always one cell */
> +	*busno = *(dma_window++);
> +
> +	prop = get_property(dn, "ibm,#dma-address-cells", NULL);
> +	cells = prop ? *(u32 *)prop : prom_n_addr_cells(dn);
> +	*phys = of_read_addr(dma_window, cells);
> +
> +	dma_window += cells;
> +
> +	prop = get_property(dn, "ibm,#dma-size-cells", NULL);
> +	cells = prop ? *(u32 *)prop : prom_n_size_cells(dn);
> +	*size = of_read_addr(dma_window, cells);
> +}
> +EXPORT_SYMBOL_GPL(of_parse_dma_window);
> Index: linux-2.6/include/asm-powerpc/prom.h
> ===================================================================
> --- linux-2.6.orig/include/asm-powerpc/prom.h
> +++ linux-2.6/include/asm-powerpc/prom.h
> @@ -230,6 +230,12 @@ extern int of_address_to_resource(struct
>  extern int of_pci_address_to_resource(struct device_node *dev, int  
> bar,
>  				      struct resource *r);
>
> +/* Parse the ibm,dma-window property of an OF node into the busno,  
> phys and
> + * size parameters.
> + */
> +void of_parse_dma_window(struct device_node *dn, unsigned char  
> *dma_window_prop,
> +		unsigned long *busno, unsigned long *phys, unsigned long *size);
> +
>  extern void kdump_move_device_tree(void);
>
>  #endif /* __KERNEL__ */
>
> To: linuxppc-dev@ozlabs.org
> From: Jeremy Kerr <jk@ozlabs.org>
> Date: Thu, 18 May 2006 16:20:51 +1000
> Subject: [PATCH 2/2] powerpc: pseries: Use generic dma-window  
> parsing function
> Message-Id: <1147933251.472945.297063284077.qpush@pokey>
>
> Change the pseries iommu init code to use the new  
> of_parse_dma_window()
> to parse the ibm,dma-window and ibm,my-dma-window properties of pci  
> and
> virtual device nodes.
>
> Also, clean up vio_build_iommu_table() a little.
>
> Tested on pseries, with both vio and pci devices.
>
> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
>
>  arch/powerpc/platforms/pseries/iommu.c |   29 +++++++++ 
> +-------------------
>  arch/powerpc/platforms/pseries/vio.c   |   32 +++++++++++++ 
> +------------------
>  2 files changed, 24 insertions(+), 37 deletions(-)
>
> Index: linux-2.6/arch/powerpc/platforms/pseries/iommu.c
> ===================================================================
> --- linux-2.6.orig/arch/powerpc/platforms/pseries/iommu.c
> +++ linux-2.6/arch/powerpc/platforms/pseries/iommu.c
> @@ -299,30 +299,22 @@ static void iommu_table_setparms(struct
>   * iommu_table_setparms_lpar
>   *
>   * Function: On pSeries LPAR systems, return TCE table info, given  
> a pci bus.
> - *
> - * ToDo: properly interpret the ibm,dma-window property.  The  
> definition is:
> - *	logical-bus-number	(1 word)
> - *	phys-address		(#address-cells words)
> - *	size			(#cell-size words)
> - *
> - * Currently we hard code these sizes (more or less).
>   */
>  static void iommu_table_setparms_lpar(struct pci_controller *phb,
>  				      struct device_node *dn,
>  				      struct iommu_table *tbl,
> -				      unsigned int *dma_window)
> +				      unsigned char *dma_window)
>  {
> +	unsigned long offset, size;
> +
>  	tbl->it_busno  = PCI_DN(dn)->bussubno;
> +	of_parse_dma_window(dn, dma_window, &tbl->it_index, &offset, &size);
>
> -	/* TODO: Parse field size properties properly. */
> -	tbl->it_size   = (((unsigned long)dma_window[4] << 32) |
> -			   (unsigned long)dma_window[5]) >> PAGE_SHIFT;
> -	tbl->it_offset = (((unsigned long)dma_window[2] << 32) |
> -			   (unsigned long)dma_window[3]) >> PAGE_SHIFT;
>  	tbl->it_base   = 0;
> -	tbl->it_index  = dma_window[0];
>  	tbl->it_blocksize  = 16;
>  	tbl->it_type = TCE_PCI;
> +	tbl->it_offset = offset >> PAGE_SHIFT;
> +	tbl->it_size = size >> PAGE_SHIFT;
>  }
>
>  static void iommu_bus_setup_pSeries(struct pci_bus *bus)
> @@ -414,7 +406,7 @@ static void iommu_bus_setup_pSeriesLP(st
>  	struct iommu_table *tbl;
>  	struct device_node *dn, *pdn;
>  	struct pci_dn *ppci;
> -	unsigned int *dma_window = NULL;
> +	unsigned char *dma_window = NULL;
>
>  	DBG("iommu_bus_setup_pSeriesLP, bus %p, bus->self %p\n", bus, bus- 
> >self);
>
> @@ -422,7 +414,7 @@ static void iommu_bus_setup_pSeriesLP(st
>
>  	/* Find nearest ibm,dma-window, walking up the device tree */
>  	for (pdn = dn; pdn != NULL; pdn = pdn->parent) {
> -		dma_window = (unsigned int *)get_property(pdn, "ibm,dma-window",  
> NULL);
> +		dma_window = get_property(pdn, "ibm,dma-window", NULL);
>  		if (dma_window != NULL)
>  			break;
>  	}
> @@ -516,7 +508,7 @@ static void iommu_dev_setup_pSeriesLP(st
>  {
>  	struct device_node *pdn, *dn;
>  	struct iommu_table *tbl;
> -	int *dma_window = NULL;
> +	unsigned char *dma_window = NULL;
>  	struct pci_dn *pci;
>
>  	DBG("iommu_dev_setup_pSeriesLP, dev %p (%s)\n", dev, pci_name(dev));
> @@ -531,8 +523,7 @@ static void iommu_dev_setup_pSeriesLP(st
>
>  	for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->iommu_table;
>  	     pdn = pdn->parent) {
> -		dma_window = (unsigned int *)
> -			get_property(pdn, "ibm,dma-window", NULL);
> +		dma_window = get_property(pdn, "ibm,dma-window", NULL);
>  		if (dma_window)
>  			break;
>  	}
> Index: linux-2.6/arch/powerpc/platforms/pseries/vio.c
> ===================================================================
> --- linux-2.6.orig/arch/powerpc/platforms/pseries/vio.c
> +++ linux-2.6/arch/powerpc/platforms/pseries/vio.c
> @@ -108,32 +108,28 @@ __initcall(vio_bus_init_pseries);
>  */
>  static struct iommu_table *vio_build_iommu_table(struct vio_dev *dev)
>  {
> -	unsigned int *dma_window;
> -	struct iommu_table *newTceTable;
> -	unsigned long offset;
> -	int dma_window_property_size;
> +	unsigned char *dma_window;
> +	struct iommu_table *tbl;
> +	unsigned long offset, size;
>
> -	dma_window = (unsigned int *) get_property(dev- 
> >dev.platform_data, "ibm,my-dma-window", &dma_window_property_size);
> -	if(!dma_window) {
> +	dma_window = get_property(dev->dev.platform_data,
> +			"ibm,my-dma-window", NULL);
> +	if (!dma_window)
>  		return NULL;
> -	}
>
> -	newTceTable = (struct iommu_table *) kmalloc(sizeof(struct  
> iommu_table), GFP_KERNEL);
> +	tbl = (struct iommu_table *)kmalloc(sizeof(*tbl), GFP_KERNEL);
>
> -	/*  There should be some code to extract the phys-encoded offset
> -		using prom_n_addr_cells(). However, according to a comment
> -		on earlier versions, it's always zero, so we don't bother */
> -	offset = dma_window[1] >>  PAGE_SHIFT;
> +	of_parse_dma_window(dev->dev.platform_data, dma_window,
> +			&tbl->it_index, &offset, &size);
>
>  	/* TCE table size - measured in tce entries */
> -	newTceTable->it_size		= dma_window[4] >> PAGE_SHIFT;
> +	tbl->it_size	= size >> PAGE_SHIFT;
>  	/* offset for VIO should always be 0 */
> -	newTceTable->it_offset		= offset;
> -	newTceTable->it_busno		= 0;
> -	newTceTable->it_index		= (unsigned long)dma_window[0];
> -	newTceTable->it_type		= TCE_VB;
> +	tbl->it_offset	= offset >> PAGE_SHIFT;
> +	tbl->it_busno	= 0;
> +	tbl->it_type	= TCE_VB;
>
> -	return iommu_init_table(newTceTable);
> +	return iommu_init_table(tbl);
>  }
>
>  /**
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] fix of_parse_dma_window. was: Re: [PATCH 1/2] powerpc: Add of_parse_dma_window()
  2006-05-30 18:38       ` [PATCH] fix of_parse_dma_window. was: " Will Schmidt
@ 2006-05-31  4:17         ` Jeremy Kerr
  0 siblings, 0 replies; 11+ messages in thread
From: Jeremy Kerr @ 2006-05-31  4:17 UTC (permalink / raw)
  To: will_schmidt; +Cc: linuxppc-dev


> Unless there is a more elegant solution... :-)
>
> Signed-off-by: Will Schmidt <willschm@us.ibm.com>

Ack, for a temporary fix. I'm working on a nicer solution at the moment.


Jeremy

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-05-31  4:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-18  6:20 [PATCH 1/2] powerpc: Add of_parse_dma_window() Jeremy Kerr
2006-05-18  6:28 ` Jeremy Kerr
2006-05-18 17:11 ` Olof Johansson
2006-05-18 23:11   ` Segher Boessenkool
2006-05-18 23:13     ` Olof Johansson
2006-05-18 23:55       ` Segher Boessenkool
2006-05-30 18:38       ` [PATCH] fix of_parse_dma_window. was: " Will Schmidt
2006-05-31  4:17         ` Jeremy Kerr
2006-05-30 18:55 ` Kumar Gala
  -- strict thread matches above, loose matches on Subject: below --
2006-05-18  6:32 Jeremy Kerr
2006-05-18 17:12 ` Olof Johansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).