public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 04/10] fdt: Add fdt_getprop_u32_default helpers
@ 2008-10-23 12:58 Kumar Gala
  2008-10-23 12:58 ` [U-Boot] [PATCH v2 05/10] fdt: Added helper to set PCI dma-ranges property Kumar Gala
  2008-10-23 13:08 ` [U-Boot] [PATCH v2 04/10] fdt: Add fdt_getprop_u32_default helpers Jerry Van Baren
  0 siblings, 2 replies; 4+ messages in thread
From: Kumar Gala @ 2008-10-23 12:58 UTC (permalink / raw)
  To: u-boot

Add helper functions to return find a node and return it's property
or a default value.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
---
 common/fdt_support.c  |   27 +++++++++++++++++++++++++++
 include/fdt_support.h |    2 ++
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/common/fdt_support.c b/common/fdt_support.c
index 8ceeb0f..f430777 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -35,6 +35,33 @@
  */
 DECLARE_GLOBAL_DATA_PTR;
 
+/**
+ * fdt_getprop_u32_default - Find a node and return it's property or a default
+ *
+ * @fdt: ptr to device tree
+ * @path: path of node
+ * @prop: property name
+ * @dflt: default value if the property isn't found
+ *
+ * Convenience function to find a node and return it's property or a
+ * default value if it doesn't exist.
+ */
+u32 fdt_getprop_u32_default(void *fdt, const char *path, const char *prop,
+				const u32 dflt)
+{
+	const u32 *val;
+	int off;
+
+	off = fdt_path_offset(fdt, path);
+	if (off < 0)
+		return dflt;
+
+	val = fdt_getprop(fdt, off, prop, NULL);
+	if (val)
+		return *val;
+	else
+		return dflt;
+}
 
 /**
  * fdt_find_and_setprop: Find a node and set it's property
diff --git a/include/fdt_support.h b/include/fdt_support.h
index ceaadc2..816c9d0 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -28,6 +28,8 @@
 
 #include <fdt.h>
 
+u32 fdt_getprop_u32_default(void *fdt, const char *path, const char *prop,
+				const u32 dflt);
 int fdt_chosen(void *fdt, int force);
 int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force);
 void do_fixup_by_path(void *fdt, const char *path, const char *prop,
-- 
1.5.5.1

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

* [U-Boot] [PATCH v2 05/10] fdt: Added helper to set PCI dma-ranges property
  2008-10-23 12:58 [U-Boot] [PATCH v2 04/10] fdt: Add fdt_getprop_u32_default helpers Kumar Gala
@ 2008-10-23 12:58 ` Kumar Gala
  2008-10-23 13:11   ` Jerry Van Baren
  2008-10-23 13:08 ` [U-Boot] [PATCH v2 04/10] fdt: Add fdt_getprop_u32_default helpers Jerry Van Baren
  1 sibling, 1 reply; 4+ messages in thread
From: Kumar Gala @ 2008-10-23 12:58 UTC (permalink / raw)
  To: u-boot

Added fdt_pci_dma_ranges() that parses the pci_region info from the
struct pci_controller and populates the dma-ranges based on it.

The max # of windws/dma-ranges we support is 3 since on embedded
PowerPC based systems this is the max number of windows.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
---

move to using fdt_getprop_u32_default

- k

 common/fdt_support.c  |   69 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/fdt_support.h |    5 +++
 2 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/common/fdt_support.c b/common/fdt_support.c
index f430777..d483d66 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -620,3 +620,72 @@ int fdt_resize(void *blob)
 
 	return actualsize;
 }
+
+#ifdef CONFIG_PCI
+#define CONFIG_SYS_PCI_NR_INBOUND_WIN 3
+
+#define FDT_PCI_PREFETCH	(0x40000000)
+#define FDT_PCI_MEM32		(0x02000000)
+#define FDT_PCI_IO		(0x01000000)
+#define FDT_PCI_MEM64		(0x03000000)
+
+int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose) {
+
+	int addrcell, sizecell, len, r;
+	u32 *dma_range;
+	/* sized based on pci addr cells, size-cells, & address-cells */
+	u32 dma_ranges[(3 + 2 + 2) * CONFIG_SYS_PCI_NR_INBOUND_WIN];
+
+	addrcell = fdt_getprop_u32_default(blob, "/", "#address-cells", 1);
+	sizecell = fdt_getprop_u32_default(blob, "/", "#size-cells", 1);
+
+	dma_range = &dma_ranges[0];
+	for (r = 0; r < hose->region_count; r++) {
+		u64 bus_start, phys_start, size;
+
+		/* skip if !PCI_REGION_MEMORY */
+		if (!(hose->regions[r].flags & PCI_REGION_MEMORY))
+			continue;
+
+		bus_start = (u64)hose->regions[r].bus_start;
+		phys_start = (u64)hose->regions[r].phys_start;
+		size = (u64)hose->regions[r].size;
+
+		dma_range[0] = 0;
+		if (size > 0x100000000ull)
+			dma_range[0] |= FDT_PCI_MEM64;
+		else
+			dma_range[0] |= FDT_PCI_MEM32;
+		if (hose->regions[r].flags & PCI_REGION_PREFETCH)
+			dma_range[0] |= FDT_PCI_PREFETCH;
+#ifdef CONFIG_SYS_PCI_64BIT
+		dma_range[1] = bus_start >> 32;
+#else
+		dma_range[1] = 0;
+#endif
+		dma_range[2] = bus_start & 0xffffffff;
+
+		if (addrcell == 2) {
+			dma_range[3] = phys_start >> 32;
+			dma_range[4] = phys_start & 0xffffffff;
+		} else {
+			dma_range[3] = phys_start & 0xffffffff;
+		}
+
+		if (sizecell == 2) {
+			dma_range[3 + addrcell + 0] = size >> 32;
+			dma_range[3 + addrcell + 1] = size & 0xffffffff;
+		} else {
+			dma_range[3 + addrcell + 0] = size & 0xffffffff;
+		}
+
+		dma_range += (3 + addrcell + sizecell);
+	}
+
+	len = dma_range - &dma_ranges[0];
+	if (len)
+		fdt_setprop(blob, phb_off, "dma-ranges", &dma_ranges[0], len*4);
+
+	return 0;
+}
+#endif
diff --git a/include/fdt_support.h b/include/fdt_support.h
index 816c9d0..6062df9 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -65,6 +65,11 @@ void fdt_fixup_crypto_node(void *blob, int sec_rev);
 static inline void fdt_fixup_crypto_node(void *blob, int sec_rev) {}
 #endif
 
+#ifdef CONFIG_PCI
+#include <pci.h>
+int fdt_pci_dma_ranges(void *blob, int phb_off, struct pci_controller *hose);
+#endif
+
 #ifdef CONFIG_OF_BOARD_SETUP
 void ft_board_setup(void *blob, bd_t *bd);
 void ft_cpu_setup(void *blob, bd_t *bd);
-- 
1.5.5.1

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

* [U-Boot] [PATCH v2 04/10] fdt: Add fdt_getprop_u32_default helpers
  2008-10-23 12:58 [U-Boot] [PATCH v2 04/10] fdt: Add fdt_getprop_u32_default helpers Kumar Gala
  2008-10-23 12:58 ` [U-Boot] [PATCH v2 05/10] fdt: Added helper to set PCI dma-ranges property Kumar Gala
@ 2008-10-23 13:08 ` Jerry Van Baren
  1 sibling, 0 replies; 4+ messages in thread
From: Jerry Van Baren @ 2008-10-23 13:08 UTC (permalink / raw)
  To: u-boot

Kumar Gala wrote:
> Add helper functions to return find a node and return it's property
> or a default value.
> 
> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
> ---
>  common/fdt_support.c  |   27 +++++++++++++++++++++++++++
>  include/fdt_support.h |    2 ++
>  2 files changed, 29 insertions(+), 0 deletions(-)
> 
> diff --git a/common/fdt_support.c b/common/fdt_support.c
> index 8ceeb0f..f430777 100644
> --- a/common/fdt_support.c
> +++ b/common/fdt_support.c
> @@ -35,6 +35,33 @@
>   */
>  DECLARE_GLOBAL_DATA_PTR;
>  
> +/**
> + * fdt_getprop_u32_default - Find a node and return it's property or a default
> + *
> + * @fdt: ptr to device tree
> + * @path: path of node
> + * @prop: property name
> + * @dflt: default value if the property isn't found
> + *
> + * Convenience function to find a node and return it's property or a
> + * default value if it doesn't exist.
> + */
> +u32 fdt_getprop_u32_default(void *fdt, const char *path, const char *prop,
> +				const u32 dflt)
> +{
> +	const u32 *val;
> +	int off;
> +
> +	off = fdt_path_offset(fdt, path);
> +	if (off < 0)
> +		return dflt;
> +
> +	val = fdt_getprop(fdt, off, prop, NULL);
> +	if (val)
> +		return *val;
> +	else
> +		return dflt;
> +}
>  
>  /**
>   * fdt_find_and_setprop: Find a node and set it's property
> diff --git a/include/fdt_support.h b/include/fdt_support.h
> index ceaadc2..816c9d0 100644
> --- a/include/fdt_support.h
> +++ b/include/fdt_support.h
> @@ -28,6 +28,8 @@
>  
>  #include <fdt.h>
>  
> +u32 fdt_getprop_u32_default(void *fdt, const char *path, const char *prop,
> +				const u32 dflt);
>  int fdt_chosen(void *fdt, int force);
>  int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force);
>  void do_fixup_by_path(void *fdt, const char *path, const char *prop,

Acked-by: Gerald Van Baren <vanbaren@cideas.com>

Thanks!
gvb

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

* [U-Boot] [PATCH v2 05/10] fdt: Added helper to set PCI dma-ranges property
  2008-10-23 12:58 ` [U-Boot] [PATCH v2 05/10] fdt: Added helper to set PCI dma-ranges property Kumar Gala
@ 2008-10-23 13:11   ` Jerry Van Baren
  0 siblings, 0 replies; 4+ messages in thread
From: Jerry Van Baren @ 2008-10-23 13:11 UTC (permalink / raw)
  To: u-boot

Kumar Gala wrote:
> Added fdt_pci_dma_ranges() that parses the pci_region info from the
> struct pci_controller and populates the dma-ranges based on it.
> 
> The max # of windws/dma-ranges we support is 3 since on embedded
> PowerPC based systems this is the max number of windows.
> 
> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
> ---
> 
> move to using fdt_getprop_u32_default
> 
> - k
> 
>  common/fdt_support.c  |   69 +++++++++++++++++++++++++++++++++++++++++++++++++
>  include/fdt_support.h |    5 +++
>  2 files changed, 74 insertions(+), 0 deletions(-)
> 
> diff --git a/common/fdt_support.c b/common/fdt_support.c
> index f430777..d483d66 100644
> --- a/common/fdt_support.c
> +++ b/common/fdt_support.c

[snip]

> diff --git a/include/fdt_support.h b/include/fdt_support.h
> index 816c9d0..6062df9 100644
> --- a/include/fdt_support.h
> +++ b/include/fdt_support.h

[snip]

I'm not really authoritative on the PCI changes, but it looks good to me 
so I'm OK with adding this to fdt_support.[ch].

Acked-by: Gerald Van Baren <vanbaren@cideas.com>

Thanks,
gvb

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

end of thread, other threads:[~2008-10-23 13:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-23 12:58 [U-Boot] [PATCH v2 04/10] fdt: Add fdt_getprop_u32_default helpers Kumar Gala
2008-10-23 12:58 ` [U-Boot] [PATCH v2 05/10] fdt: Added helper to set PCI dma-ranges property Kumar Gala
2008-10-23 13:11   ` Jerry Van Baren
2008-10-23 13:08 ` [U-Boot] [PATCH v2 04/10] fdt: Add fdt_getprop_u32_default helpers Jerry Van Baren

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