* [PATCH 1/5] [v2][POWERPC] refactor dcr code [not found] <1206401313-1625-1-git-send-email-stephen.neuendorffer@xilinx.com> @ 2008-03-28 16:20 ` Stephen Neuendorffer [not found] ` <1206721237-17982-1-git-send-email-stephen.neuendorffer@xilinx.com> 1 sibling, 0 replies; 5+ messages in thread From: Stephen Neuendorffer @ 2008-03-28 16:20 UTC (permalink / raw) To: linuxppc-dev, benh, jwboyer, sfr, grant.likely, git-dev, linux-kernel Cc: Stephen Neuendorffer Previously, dcr support was configured at compile time to either using MMIO or native dcr instructions. Although this works for most platforms, it fails on FPGA platforms: 1) Systems may include more than one dcr bus. 2) Systems may be native dcr capable and still use memory mapped dcr interface. This patch provides runtime support based on the device trees for the case where CONFIG_PPC_DCR_MMIO and CONFIG_PPC_DCR_NATIVE are both selected. Previously, this was a poorly defined configuration, which happened to provide NATIVE support. The runtime selection is made based on the dcr slave device having a 'dcr-access-method' attribute in the device tree. If only one of the above options is selected, then the code uses #defines to select only the used code in order to avoid interoducing overhead in existing usage. Signed-off-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com> --- arch/powerpc/sysdev/dcr.c | 91 ++++++++++++++++++++++++++++++++----- include/asm-powerpc/dcr-generic.h | 49 ++++++++++++++++++++ include/asm-powerpc/dcr-mmio.h | 20 +++++--- include/asm-powerpc/dcr-native.h | 16 ++++--- include/asm-powerpc/dcr.h | 36 ++++++++++++++- 5 files changed, 186 insertions(+), 26 deletions(-) create mode 100644 include/asm-powerpc/dcr-generic.h diff --git a/arch/powerpc/sysdev/dcr.c b/arch/powerpc/sysdev/dcr.c index 437e48d..d3de0ff 100644 --- a/arch/powerpc/sysdev/dcr.c +++ b/arch/powerpc/sysdev/dcr.c @@ -23,6 +23,68 @@ #include <asm/prom.h> #include <asm/dcr.h> +#if defined(CONFIG_PPC_DCR_NATIVE) && defined(CONFIG_PPC_DCR_MMIO) + +bool dcr_map_ok_generic(dcr_host_t host) +{ + if (host.type == INVALID) + return 0; + else if (host.type == NATIVE) + return dcr_map_ok_native(host.host.native); + else + return dcr_map_ok_mmio(host.host.mmio); +} +EXPORT_SYMBOL_GPL(dcr_map_ok_generic); + +dcr_host_t dcr_map_generic(struct device_node *dev, + unsigned int dcr_n, + unsigned int dcr_c) +{ + dcr_host_t host; + const char *prop = of_get_property(dev, "dcr-access-method", NULL); + + if (!strcmp(prop, "native")) { + host.type = NATIVE; + host.host.native = dcr_map_native(dev, dcr_n, dcr_c); + } else if (!strcmp(prop, "mmio")) { + host.type = MMIO; + host.host.mmio = dcr_map_mmio(dev, dcr_n, dcr_c); + } else + host.type = INVALID; + + return host; +} +EXPORT_SYMBOL_GPL(dcr_map_generic); + +void dcr_unmap_generic(dcr_host_t host, unsigned int dcr_c) +{ + if (host.type == NATIVE) + dcr_unmap_native(host.host.native, dcr_c); + else + dcr_unmap_mmio(host.host.mmio, dcr_c); +} +EXPORT_SYMBOL_GPL(dcr_unmap_generic); + +u32 dcr_read_generic(dcr_host_t host, unsigned int dcr_n) +{ + if (host.type == NATIVE) + return dcr_read_native(host.host.native, dcr_n); + else + return dcr_read_mmio(host.host.mmio, dcr_n); +} +EXPORT_SYMBOL_GPL(dcr_read_generic); + +void dcr_write_generic(dcr_host_t host, unsigned int dcr_n, u32 value) +{ + if (host.type == NATIVE) + dcr_write_native(host.host.native, dcr_n, value); + else + dcr_write_mmio(host.host.mmio, dcr_n, value); +} +EXPORT_SYMBOL_GPL(dcr_write_generic); + +#endif /* defined(CONFIG_PPC_DCR_NATIVE) && defined(CONFIG_PPC_DCR_MMIO) */ + unsigned int dcr_resource_start(struct device_node *np, unsigned int index) { unsigned int ds; @@ -47,7 +109,7 @@ unsigned int dcr_resource_len(struct device_node *np, unsigned int index) } EXPORT_SYMBOL_GPL(dcr_resource_len); -#ifndef CONFIG_PPC_DCR_NATIVE +#ifdef CONFIG_PPC_DCR_MMIO static struct device_node * find_dcr_parent(struct device_node * node) { @@ -101,18 +163,19 @@ u64 of_translate_dcr_address(struct device_node *dev, return ret; } -dcr_host_t dcr_map(struct device_node *dev, unsigned int dcr_n, - unsigned int dcr_c) +dcr_host_mmio_t dcr_map_mmio(struct device_node *dev, + unsigned int dcr_n, + unsigned int dcr_c) { - dcr_host_t ret = { .token = NULL, .stride = 0, .base = dcr_n }; + dcr_host_mmio_t ret = { .token = NULL, .stride = 0, .base = dcr_n }; u64 addr; pr_debug("dcr_map(%s, 0x%x, 0x%x)\n", dev->full_name, dcr_n, dcr_c); addr = of_translate_dcr_address(dev, dcr_n, &ret.stride); - pr_debug("translates to addr: 0x%lx, stride: 0x%x\n", - addr, ret.stride); + pr_debug("translates to addr: 0x%llx, stride: 0x%x\n", + (unsigned long long) addr, ret.stride); if (addr == OF_BAD_ADDR) return ret; pr_debug("mapping 0x%x bytes\n", dcr_c * ret.stride); @@ -124,11 +187,11 @@ dcr_host_t dcr_map(struct device_node *dev, unsigned int dcr_n, ret.token -= dcr_n * ret.stride; return ret; } -EXPORT_SYMBOL_GPL(dcr_map); +EXPORT_SYMBOL_GPL(dcr_map_mmio); -void dcr_unmap(dcr_host_t host, unsigned int dcr_c) +void dcr_unmap_mmio(dcr_host_mmio_t host, unsigned int dcr_c) { - dcr_host_t h = host; + dcr_host_mmio_t h = host; if (h.token == NULL) return; @@ -136,7 +199,11 @@ void dcr_unmap(dcr_host_t host, unsigned int dcr_c) iounmap(h.token); h.token = NULL; } -EXPORT_SYMBOL_GPL(dcr_unmap); -#else /* defined(CONFIG_PPC_DCR_NATIVE) */ +EXPORT_SYMBOL_GPL(dcr_unmap_mmio); + +#endif /* defined(CONFIG_PPC_DCR_MMIO) */ + +#ifdef CONFIG_PPC_DCR_NATIVE DEFINE_SPINLOCK(dcr_ind_lock); -#endif /* !defined(CONFIG_PPC_DCR_NATIVE) */ +#endif /* defined(CONFIG_PPC_DCR_NATIVE) */ + diff --git a/include/asm-powerpc/dcr-generic.h b/include/asm-powerpc/dcr-generic.h new file mode 100644 index 0000000..0ee74fb --- /dev/null +++ b/include/asm-powerpc/dcr-generic.h @@ -0,0 +1,49 @@ +/* + * (c) Copyright 2006 Benjamin Herrenschmidt, IBM Corp. + * <benh@kernel.crashing.org> + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _ASM_POWERPC_DCR_GENERIC_H +#define _ASM_POWERPC_DCR_GENERIC_H +#ifdef __KERNEL__ +#ifndef __ASSEMBLY__ + +enum host_type_t {MMIO, NATIVE, INVALID}; + +typedef struct { + enum host_type_t type; + union { + dcr_host_mmio_t mmio; + dcr_host_native_t native; + } host; +} dcr_host_t; + +extern bool dcr_map_ok_generic(dcr_host_t host); + +extern dcr_host_t dcr_map_generic(struct device_node *dev, unsigned int dcr_n, + unsigned int dcr_c); +extern void dcr_unmap_generic(dcr_host_t host, unsigned int dcr_c); + +extern u32 dcr_read_generic(dcr_host_t host, unsigned int dcr_n); + +extern void dcr_write_generic(dcr_host_t host, unsigned int dcr_n, u32 value); + +#endif /* __ASSEMBLY__ */ +#endif /* __KERNEL__ */ +#endif /* _ASM_POWERPC_DCR_GENERIC_H */ + + diff --git a/include/asm-powerpc/dcr-mmio.h b/include/asm-powerpc/dcr-mmio.h index 08532ff..acd491d 100644 --- a/include/asm-powerpc/dcr-mmio.h +++ b/include/asm-powerpc/dcr-mmio.h @@ -27,20 +27,26 @@ typedef struct { void __iomem *token; unsigned int stride; unsigned int base; -} dcr_host_t; +} dcr_host_mmio_t; -#define DCR_MAP_OK(host) ((host).token != NULL) +static inline bool dcr_map_ok_mmio(dcr_host_mmio_t host) +{ + return host.token != NULL; +} -extern dcr_host_t dcr_map(struct device_node *dev, unsigned int dcr_n, - unsigned int dcr_c); -extern void dcr_unmap(dcr_host_t host, unsigned int dcr_c); +extern dcr_host_mmio_t dcr_map_mmio(struct device_node *dev, + unsigned int dcr_n, + unsigned int dcr_c); +extern void dcr_unmap_mmio(dcr_host_mmio_t host, unsigned int dcr_c); -static inline u32 dcr_read(dcr_host_t host, unsigned int dcr_n) +static inline u32 dcr_read_mmio(dcr_host_mmio_t host, unsigned int dcr_n) { return in_be32(host.token + ((host.base + dcr_n) * host.stride)); } -static inline void dcr_write(dcr_host_t host, unsigned int dcr_n, u32 value) +static inline void dcr_write_mmio(dcr_host_mmio_t host, + unsigned int dcr_n, + u32 value) { out_be32(host.token + ((host.base + dcr_n) * host.stride), value); } diff --git a/include/asm-powerpc/dcr-native.h b/include/asm-powerpc/dcr-native.h index be6c879..67832e5 100644 --- a/include/asm-powerpc/dcr-native.h +++ b/include/asm-powerpc/dcr-native.h @@ -26,14 +26,18 @@ typedef struct { unsigned int base; -} dcr_host_t; +} dcr_host_native_t; -#define DCR_MAP_OK(host) (1) +static inline bool dcr_map_ok_native(dcr_host_native_t host) +{ + return 1; +} -#define dcr_map(dev, dcr_n, dcr_c) ((dcr_host_t){ .base = (dcr_n) }) -#define dcr_unmap(host, dcr_c) do {} while (0) -#define dcr_read(host, dcr_n) mfdcr(dcr_n + host.base) -#define dcr_write(host, dcr_n, value) mtdcr(dcr_n + host.base, value) +#define dcr_map_native(dev, dcr_n, dcr_c) \ + ((dcr_host_native_t){ .base = (dcr_n) }) +#define dcr_unmap_native(host, dcr_c) do {} while (0) +#define dcr_read_native(host, dcr_n) mfdcr(dcr_n + host.base) +#define dcr_write_native(host, dcr_n, value) mtdcr(dcr_n + host.base, value) /* Device Control Registers */ void __mtdcr(int reg, unsigned int val); diff --git a/include/asm-powerpc/dcr.h b/include/asm-powerpc/dcr.h index 9338d50..6b86322 100644 --- a/include/asm-powerpc/dcr.h +++ b/include/asm-powerpc/dcr.h @@ -20,14 +20,47 @@ #ifndef _ASM_POWERPC_DCR_H #define _ASM_POWERPC_DCR_H #ifdef __KERNEL__ +#ifndef __ASSEMBLY__ #ifdef CONFIG_PPC_DCR #ifdef CONFIG_PPC_DCR_NATIVE #include <asm/dcr-native.h> -#else +#endif + +#ifdef CONFIG_PPC_DCR_MMIO #include <asm/dcr-mmio.h> #endif +#if defined(CONFIG_PPC_DCR_NATIVE) && defined(CONFIG_PPC_DCR_MMIO) + +#include <asm/dcr-generic.h> + +#define DCR_MAP_OK(host) dcr_map_ok_generic(host) +#define dcr_map(dev, dcr_n, dcr_c) dcr_map_generic(dev, dcr_n, dcr_c) +#define dcr_unmap(host, dcr_c) dcr_unmap_generic(host, dcr_c) +#define dcr_read(host, dcr_n) dcr_read_generic(host, dcr_n) +#define dcr_write(host, dcr_n, value) dcr_write_generic(host, dcr_n, value) + +#else + +#ifdef CONFIG_PPC_DCR_NATIVE +typedef dcr_host_native_t dcr_host_t; +#define DCR_MAP_OK(host) dcr_map_ok_native(host) +#define dcr_map(dev, dcr_n, dcr_c) dcr_map_native(dev, dcr_n, dcr_c) +#define dcr_unmap(host, dcr_c) dcr_unmap_native(host, dcr_c) +#define dcr_read(host, dcr_n) dcr_read_native(host, dcr_n) +#define dcr_write(host, dcr_n, value) dcr_write_native(host, dcr_n, value) +#else +typedef dcr_host_mmio_t dcr_host_t; +#define DCR_MAP_OK(host) dcr_map_ok_mmio(host) +#define dcr_map(dev, dcr_n, dcr_c) dcr_map_mmio(dev, dcr_n, dcr_c) +#define dcr_unmap(host, dcr_c) dcr_unmap_mmio(host, dcr_c) +#define dcr_read(host, dcr_n) dcr_read_mmio(host, dcr_n) +#define dcr_write(host, dcr_n, value) dcr_write_mmio(host, dcr_n, value) +#endif + +#endif /* defined(CONFIG_PPC_DCR_NATIVE) && defined(CONFIG_PPC_DCR_MMIO) */ + /* * On CONFIG_PPC_MERGE, we have additional helpers to read the DCR * base from the device-tree @@ -41,5 +74,6 @@ extern unsigned int dcr_resource_len(struct device_node *np, #endif /* CONFIG_PPC_MERGE */ #endif /* CONFIG_PPC_DCR */ +#endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_DCR_H */ -- 1.5.3.4-dirty ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <1206721237-17982-1-git-send-email-stephen.neuendorffer@xilinx.com>]
* [PATCH 2/5] [POWERPC] Xilinx: Virtex: Enable dcr for MMIO and NATIVE [not found] ` <1206721237-17982-1-git-send-email-stephen.neuendorffer@xilinx.com> @ 2008-03-28 16:20 ` Stephen Neuendorffer [not found] ` <1206721237-17982-2-git-send-email-stephen.neuendorffer@xilinx.com> 1 sibling, 0 replies; 5+ messages in thread From: Stephen Neuendorffer @ 2008-03-28 16:20 UTC (permalink / raw) To: linuxppc-dev, benh, jwboyer, sfr, grant.likely, git-dev, linux-kernel Cc: Stephen Neuendorffer FPGA designs may have need of both MMIO-based and NATIVE-based dcr interfaces. Signed-off-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com> --- arch/powerpc/platforms/40x/Kconfig | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/platforms/40x/Kconfig b/arch/powerpc/platforms/40x/Kconfig index a9260e2..b8e06df 100644 --- a/arch/powerpc/platforms/40x/Kconfig +++ b/arch/powerpc/platforms/40x/Kconfig @@ -123,6 +123,8 @@ config 405GPR config XILINX_VIRTEX bool + select PPC_DCR_MMIO + select PPC_DCR_NATIVE config XILINX_VIRTEX_II_PRO bool -- 1.5.3.4-dirty ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <1206721237-17982-2-git-send-email-stephen.neuendorffer@xilinx.com>]
* [PATCH 3/5] [POWERPC] explicit dcr support [not found] ` <1206721237-17982-2-git-send-email-stephen.neuendorffer@xilinx.com> @ 2008-03-28 16:20 ` Stephen Neuendorffer [not found] ` <1206721237-17982-3-git-send-email-stephen.neuendorffer@xilinx.com> 1 sibling, 0 replies; 5+ messages in thread From: Stephen Neuendorffer @ 2008-03-28 16:20 UTC (permalink / raw) To: linuxppc-dev, benh, jwboyer, sfr, grant.likely, git-dev, linux-kernel Cc: Stephen Neuendorffer Added literal mapping support if no device-tree support. Added CONFIG_OF to guard device-tree parts, since literal support works for arch=ppc. Signed-off-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com> --- arch/powerpc/sysdev/dcr.c | 82 ++++++++++++++++++++++++++++--------- include/asm-powerpc/dcr-generic.h | 2 + include/asm-powerpc/dcr-mmio.h | 11 +++++ include/asm-powerpc/dcr-native.h | 8 ++++ include/asm-powerpc/dcr.h | 24 +++++++++++ 5 files changed, 108 insertions(+), 19 deletions(-) diff --git a/arch/powerpc/sysdev/dcr.c b/arch/powerpc/sysdev/dcr.c index d3de0ff..2ccae80 100644 --- a/arch/powerpc/sysdev/dcr.c +++ b/arch/powerpc/sysdev/dcr.c @@ -20,9 +20,34 @@ #undef DEBUG #include <linux/kernel.h> +#include <linux/module.h> #include <asm/prom.h> #include <asm/dcr.h> +#ifdef CONFIG_OF +static struct device_node *find_dcr_parent(struct device_node *node) +{ + struct device_node *par, *tmp; + const u32 *p; + + for (par = of_node_get(node); par;) { + if (of_get_property(par, "dcr-controller", NULL)) + break; + p = of_get_property(par, "dcr-parent", NULL); + tmp = par; + if (p == NULL) + par = of_get_parent(par); + else + par = of_find_node_by_phandle(*p); + of_node_put(tmp); + } + return par; +} +#endif /* CONFIG_OF */ + + +/* Indirection layer for providing both NATIVE and MMIO support. */ + #if defined(CONFIG_PPC_DCR_NATIVE) && defined(CONFIG_PPC_DCR_MMIO) bool dcr_map_ok_generic(dcr_host_t host) @@ -36,12 +61,24 @@ bool dcr_map_ok_generic(dcr_host_t host) } EXPORT_SYMBOL_GPL(dcr_map_ok_generic); +#ifdef CONFIG_OF dcr_host_t dcr_map_generic(struct device_node *dev, unsigned int dcr_n, unsigned int dcr_c) { dcr_host_t host; - const char *prop = of_get_property(dev, "dcr-access-method", NULL); + struct device_node *dp; + + dp = find_dcr_parent(dev); + if (dp == NULL) { + host.type = INVALID; + return host; + } + + const char *prop = of_get_property(dp, "dcr-access-method", NULL); + + pr_debug("dcr_map_generic(dcr-access-method = %s)\n", + prop); if (!strcmp(prop, "native")) { host.type = NATIVE; @@ -56,6 +93,8 @@ dcr_host_t dcr_map_generic(struct device_node *dev, } EXPORT_SYMBOL_GPL(dcr_map_generic); +#endif /* CONFIG_OF */ + void dcr_unmap_generic(dcr_host_t host, unsigned int dcr_c) { if (host.type == NATIVE) @@ -85,9 +124,10 @@ EXPORT_SYMBOL_GPL(dcr_write_generic); #endif /* defined(CONFIG_PPC_DCR_NATIVE) && defined(CONFIG_PPC_DCR_MMIO) */ +#ifdef CONFIG_OF unsigned int dcr_resource_start(struct device_node *np, unsigned int index) { - unsigned int ds; + int ds; const u32 *dr = of_get_property(np, "dcr-reg", &ds); if (dr == NULL || ds & 1 || index >= (ds / 8)) @@ -99,7 +139,7 @@ EXPORT_SYMBOL_GPL(dcr_resource_start); unsigned int dcr_resource_len(struct device_node *np, unsigned int index) { - unsigned int ds; + int ds; const u32 *dr = of_get_property(np, "dcr-reg", &ds); if (dr == NULL || ds & 1 || index >= (ds / 8)) @@ -109,26 +149,28 @@ unsigned int dcr_resource_len(struct device_node *np, unsigned int index) } EXPORT_SYMBOL_GPL(dcr_resource_len); +#endif /* CONFIG_OF */ + + + +/* Support for MMIO */ #ifdef CONFIG_PPC_DCR_MMIO -static struct device_node * find_dcr_parent(struct device_node * node) +dcr_host_mmio_t dcr_map_mmio_literal_mmio(resource_size_t mmio_start, + unsigned int stride, + unsigned int dcr_n, + unsigned int dcr_c) { - struct device_node *par, *tmp; - const u32 *p; - - for (par = of_node_get(node); par;) { - if (of_get_property(par, "dcr-controller", NULL)) - break; - p = of_get_property(par, "dcr-parent", NULL); - tmp = par; - if (p == NULL) - par = of_get_parent(par); - else - par = of_find_node_by_phandle(*p); - of_node_put(tmp); - } - return par; + dcr_host_mmio_t host; + host.stride = stride; + host.token = ioremap(mmio_start, dcr_c * stride); + host.token -= dcr_n * stride; + host.base = dcr_n; + return host; } +EXPORT_SYMBOL_GPL(dcr_map_mmio_literal_mmio); + +#ifdef CONFIG_OF u64 of_translate_dcr_address(struct device_node *dev, unsigned int dcr_n, @@ -189,6 +231,8 @@ dcr_host_mmio_t dcr_map_mmio(struct device_node *dev, } EXPORT_SYMBOL_GPL(dcr_map_mmio); +#endif /* CONFIG_OF */ + void dcr_unmap_mmio(dcr_host_mmio_t host, unsigned int dcr_c) { dcr_host_mmio_t h = host; diff --git a/include/asm-powerpc/dcr-generic.h b/include/asm-powerpc/dcr-generic.h index 0ee74fb..8032795 100644 --- a/include/asm-powerpc/dcr-generic.h +++ b/include/asm-powerpc/dcr-generic.h @@ -34,8 +34,10 @@ typedef struct { extern bool dcr_map_ok_generic(dcr_host_t host); +#ifdef CONFIG_OF extern dcr_host_t dcr_map_generic(struct device_node *dev, unsigned int dcr_n, unsigned int dcr_c); +#endif extern void dcr_unmap_generic(dcr_host_t host, unsigned int dcr_c); extern u32 dcr_read_generic(dcr_host_t host, unsigned int dcr_n); diff --git a/include/asm-powerpc/dcr-mmio.h b/include/asm-powerpc/dcr-mmio.h index acd491d..b12d291 100644 --- a/include/asm-powerpc/dcr-mmio.h +++ b/include/asm-powerpc/dcr-mmio.h @@ -34,9 +34,18 @@ static inline bool dcr_map_ok_mmio(dcr_host_mmio_t host) return host.token != NULL; } +extern dcr_host_mmio_t dcr_map_mmio_literal_mmio(resource_size_t mmio_start, + unsigned int stride, + unsigned int dcr_n, + unsigned int dcr_c); + + +#ifdef CONFIG_OF extern dcr_host_mmio_t dcr_map_mmio(struct device_node *dev, unsigned int dcr_n, unsigned int dcr_c); +#endif + extern void dcr_unmap_mmio(dcr_host_mmio_t host, unsigned int dcr_c); static inline u32 dcr_read_mmio(dcr_host_mmio_t host, unsigned int dcr_n) @@ -51,9 +60,11 @@ static inline void dcr_write_mmio(dcr_host_mmio_t host, out_be32(host.token + ((host.base + dcr_n) * host.stride), value); } +#ifdef CONFIG_OF extern u64 of_translate_dcr_address(struct device_node *dev, unsigned int dcr_n, unsigned int *stride); +#endif #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_DCR_MMIO_H */ diff --git a/include/asm-powerpc/dcr-native.h b/include/asm-powerpc/dcr-native.h index 67832e5..9b3e255 100644 --- a/include/asm-powerpc/dcr-native.h +++ b/include/asm-powerpc/dcr-native.h @@ -33,6 +33,14 @@ static inline bool dcr_map_ok_native(dcr_host_native_t host) return 1; } +static inline +dcr_host_native_t dcr_map_native_literal_native(unsigned int dcr_n) +{ + dcr_host_native_t host; + host.base = dcr_n; + return host; +} + #define dcr_map_native(dev, dcr_n, dcr_c) \ ((dcr_host_native_t){ .base = (dcr_n) }) #define dcr_unmap_native(host, dcr_c) do {} while (0) diff --git a/include/asm-powerpc/dcr.h b/include/asm-powerpc/dcr.h index 6b86322..dfd1c24 100644 --- a/include/asm-powerpc/dcr.h +++ b/include/asm-powerpc/dcr.h @@ -35,6 +35,27 @@ #include <asm/dcr-generic.h> +static inline +dcr_host_t dcr_map_mmio_literal(resource_size_t mmio_start, + unsigned int stride, + unsigned int dcr_n, + unsigned int dcr_c) +{ + dcr_host_t host; + host.type = MMIO; + host.host.mmio = + dcr_map_mmio_literal_mmio(mmio_start, stride, dcr_n, dcr_c); + return host; +} +static inline +dcr_host_t dcr_map_native_literal(unsigned int dcr_n) +{ + dcr_host_t host; + host.type = NATIVE; + host.host.native = dcr_map_native_literal_native(dcr_n); + return host; +} + #define DCR_MAP_OK(host) dcr_map_ok_generic(host) #define dcr_map(dev, dcr_n, dcr_c) dcr_map_generic(dev, dcr_n, dcr_c) #define dcr_unmap(host, dcr_c) dcr_unmap_generic(host, dcr_c) @@ -45,6 +66,7 @@ #ifdef CONFIG_PPC_DCR_NATIVE typedef dcr_host_native_t dcr_host_t; +#define dcr_map_native_literal(dcr_n) dcr_map_native_literal_native(dcr_n) #define DCR_MAP_OK(host) dcr_map_ok_native(host) #define dcr_map(dev, dcr_n, dcr_c) dcr_map_native(dev, dcr_n, dcr_c) #define dcr_unmap(host, dcr_c) dcr_unmap_native(host, dcr_c) @@ -52,6 +74,8 @@ typedef dcr_host_native_t dcr_host_t; #define dcr_write(host, dcr_n, value) dcr_write_native(host, dcr_n, value) #else typedef dcr_host_mmio_t dcr_host_t; +#define dcr_map_mmio_literal(mmio_start, stride, dcr_n, dcr_c) \ + dcr_map_mmio_literal_mmio(mmio_start, stride, dcr_n, dcr_c) #define DCR_MAP_OK(host) dcr_map_ok_mmio(host) #define dcr_map(dev, dcr_n, dcr_c) dcr_map_mmio(dev, dcr_n, dcr_c) #define dcr_unmap(host, dcr_c) dcr_unmap_mmio(host, dcr_c) -- 1.5.3.4-dirty ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <1206721237-17982-3-git-send-email-stephen.neuendorffer@xilinx.com>]
* [PATCH 4/5] [POWERPC] Xilinx: Framebuffer: Use dcr infrastructure. [not found] ` <1206721237-17982-3-git-send-email-stephen.neuendorffer@xilinx.com> @ 2008-03-28 16:20 ` Stephen Neuendorffer [not found] ` <1206721237-17982-4-git-send-email-stephen.neuendorffer@xilinx.com> 1 sibling, 0 replies; 5+ messages in thread From: Stephen Neuendorffer @ 2008-03-28 16:20 UTC (permalink / raw) To: linuxppc-dev, benh, jwboyer, sfr, grant.likely, git-dev, linux-kernel Cc: Stephen Neuendorffer This device contains a dcr interface. Previously, the dcr interface was assumed to be used in mmio mode, and the register space of the dcr interface was precomputed and stuffed in the device tree. This patch makes use of the new dcr infrastructure to represent the dcr interface as any other dcr interface in the device tree. This enables the dcr interface to be connected directly to a native dcr interface in a clean way. In particular, the device tree expected looks like: dcr_v29_0: dcr@0 { #address-cells = <1>; #size-cells = <1>; compatible = "xlnx,dcr-v29-1.00.a"; VGA_FrameBuffer: tft@80 { compatible = "xlnx,plb-tft-cntlr-ref-1.00.a"; dcr-parent = <&opb2dcr_bridge_0>; dcr-reg = < 80 2 >; xlnx,default-tft-base-addr = <7f>; xlnx,dps-init = <1>; xlnx,on-init = <1>; xlnx,pixclk-is-busclk-divby4 = <1>; } ; } ; opb2dcr_bridge_0: opb2dcr-bridge@40700000 { compatible = "xlnx,opb2dcr-bridge-1.00.b"; dcr-access-method = "mmio"; dcr-controller ; dcr-mmio-range = < 40700000 1000 >; dcr-mmio-stride = <4>; reg = < 40700000 1000 >; xlnx,family = "virtex2p"; } ; Note that this patch now requires PPC_DCR_MMIO to be set in order to advertise the framebuffer as a platform device (i.e. ARCH=ppc). Signed-off-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com> --- drivers/video/xilinxfb.c | 86 ++++++++++++++++++++++++++-------------------- 1 files changed, 49 insertions(+), 37 deletions(-) diff --git a/drivers/video/xilinxfb.c b/drivers/video/xilinxfb.c index 7b3a842..171cc09 100644 --- a/drivers/video/xilinxfb.c +++ b/drivers/video/xilinxfb.c @@ -38,6 +38,7 @@ #endif #include <asm/io.h> #include <linux/xilinxfb.h> +#include <asm/dcr.h> #define DRIVER_NAME "xilinxfb" #define DRIVER_DESCRIPTION "Xilinx TFT LCD frame buffer driver" @@ -112,8 +113,9 @@ struct xilinxfb_drvdata { struct fb_info info; /* FB driver info record */ - u32 regs_phys; /* phys. address of the control registers */ - u32 __iomem *regs; /* virt. address of the control registers */ + dcr_host_t dcr_host; + unsigned int dcr_start; + unsigned int dcr_len; void *fb_virt; /* virt. address of the frame buffer */ dma_addr_t fb_phys; /* phys. address of the frame buffer */ @@ -136,7 +138,7 @@ struct xilinxfb_drvdata { * when it's needed. */ #define xilinx_fb_out_be32(driverdata, offset, val) \ - out_be32(driverdata->regs + offset, val) + dcr_write(driverdata->dcr_host, offset, val) static int xilinx_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, @@ -204,7 +206,8 @@ static struct fb_ops xilinxfb_ops = * Bus independent setup/teardown */ -static int xilinxfb_assign(struct device *dev, unsigned long physaddr, +static int xilinxfb_assign(struct device *dev, dcr_host_t dcr_host, + unsigned int dcr_start, unsigned int dcr_len, struct xilinxfb_platform_data *pdata) { struct xilinxfb_drvdata *drvdata; @@ -219,21 +222,9 @@ static int xilinxfb_assign(struct device *dev, unsigned long physaddr, } dev_set_drvdata(dev, drvdata); - /* Map the control registers in */ - if (!request_mem_region(physaddr, 8, DRIVER_NAME)) { - dev_err(dev, "Couldn't lock memory region at 0x%08lX\n", - physaddr); - rc = -ENODEV; - goto err_region; - } - drvdata->regs_phys = physaddr; - drvdata->regs = ioremap(physaddr, 8); - if (!drvdata->regs) { - dev_err(dev, "Couldn't lock memory region at 0x%08lX\n", - physaddr); - rc = -ENODEV; - goto err_map; - } + drvdata->dcr_start = dcr_start; + drvdata->dcr_len = dcr_len; + drvdata->dcr_host = dcr_host; /* Allocate the framebuffer memory */ if (pdata->fb_phys) { @@ -248,7 +239,7 @@ static int xilinxfb_assign(struct device *dev, unsigned long physaddr, if (!drvdata->fb_virt) { dev_err(dev, "Could not allocate frame buffer memory\n"); rc = -ENOMEM; - goto err_fbmem; + goto err_region; } /* Clear (turn to black) the framebuffer */ @@ -298,7 +289,6 @@ static int xilinxfb_assign(struct device *dev, unsigned long physaddr, } /* Put a banner in the log (for DEBUG) */ - dev_dbg(dev, "regs: phys=%lx, virt=%p\n", physaddr, drvdata->regs); dev_dbg(dev, "fb: phys=%p, virt=%p, size=%x\n", (void*)drvdata->fb_phys, drvdata->fb_virt, fbsize); @@ -314,12 +304,6 @@ err_cmap: /* Turn off the display */ xilinx_fb_out_be32(drvdata, REG_CTRL, 0); -err_fbmem: - iounmap(drvdata->regs); - -err_map: - release_mem_region(physaddr, 8); - err_region: kfree(drvdata); dev_set_drvdata(dev, NULL); @@ -345,9 +329,8 @@ static int xilinxfb_release(struct device *dev) /* Turn off the display */ xilinx_fb_out_be32(drvdata, REG_CTRL, 0); - iounmap(drvdata->regs); - release_mem_region(drvdata->regs_phys, 8); + dcr_unmap(drvdata->dcr_host, drvdata->dcr_len); kfree(drvdata); dev_set_drvdata(dev, NULL); @@ -355,6 +338,7 @@ static int xilinxfb_release(struct device *dev) return 0; } +#ifdef CONFIG_PPC_DCR_MMIO /* --------------------------------------------------------------------- * Platform bus binding */ @@ -364,6 +348,9 @@ xilinxfb_platform_probe(struct platform_device *pdev) { struct xilinxfb_platform_data *pdata; struct resource *res; + dcr_host_t dcr_host; + int dcr_start = 0; + int dcr_len = 2; /* Find the registers address */ res = platform_get_resource(pdev, IORESOURCE_IO, 0); @@ -386,7 +373,12 @@ xilinxfb_platform_probe(struct platform_device *pdev) pdata->yvirt = xilinx_fb_default_pdata.yvirt; } - return xilinxfb_assign(&pdev->dev, res->start, pdata); + dcr_host = dcr_map_mmio_literal(res->start, 4, dcr_start, dcr_len); + if (!DCR_MAP_OK(dcr_host)) { + dev_err(&pdev->dev, "invalid address\n"); + return -ENODEV; + } + return xilinxfb_assign(&pdev->dev, dcr_host, dcr_start, dcr_len, pdata); } static int @@ -405,6 +397,23 @@ static struct platform_driver xilinxfb_platform_driver = { }, }; +/* Registration helpers to keep the number of #ifdefs to a minimum */ +static inline int __init xilinxfb_platform_register(void) +{ + pr_debug("xilinxfb: calling of_register_platform_driver()\n"); + return platform_driver_register(&xilinxfb_platform_driver); +} + +static inline void __exit xilinxfb_platform_unregister(void) +{ + platform_driver_unregister(&xilinxfb_platform_driver); +} +#else /* CONFIG_PPC_DCR_MMIO */ +/* CONFIG_OF not enabled; do nothing helpers */ +static inline int __init xilinxfb_platform_register(void) { return 0; } +static inline void __exit xilinxfb_platform_unregister(void) { } +#endif /* CONFIG_PPC_DCR_MMIO */ + /* --------------------------------------------------------------------- * OF bus binding */ @@ -413,20 +422,23 @@ static struct platform_driver xilinxfb_platform_driver = { static int __devinit xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match) { - struct resource res; const u32 *prop; struct xilinxfb_platform_data pdata; int size, rc; + int start, len; + dcr_host_t dcr_host; /* Copy with the default pdata (not a ptr reference!) */ pdata = xilinx_fb_default_pdata; dev_dbg(&op->dev, "xilinxfb_of_probe(%p, %p)\n", op, match); - rc = of_address_to_resource(op->node, 0, &res); - if (rc) { + start = dcr_resource_start(op->node, 0); + len = dcr_resource_len(op->node, 0); + dcr_host = dcr_map(op->node, start, len); + if (!DCR_MAP_OK(dcr_host)) { dev_err(&op->dev, "invalid address\n"); - return rc; + return -ENODEV; } prop = of_get_property(op->node, "phys-size", &size); @@ -450,7 +462,7 @@ xilinxfb_of_probe(struct of_device *op, const struct of_device_id *match) if (of_find_property(op->node, "rotate-display", NULL)) pdata.rotate_screen = 1; - return xilinxfb_assign(&op->dev, res.start, &pdata); + return xilinxfb_assign(&op->dev, dcr_host, start, len, &pdata); } static int __devexit xilinxfb_of_remove(struct of_device *op) @@ -505,7 +517,7 @@ xilinxfb_init(void) if (rc) return rc; - rc = platform_driver_register(&xilinxfb_platform_driver); + rc = xilinxfb_platform_register(); if (rc) xilinxfb_of_unregister(); @@ -515,7 +527,7 @@ xilinxfb_init(void) static void __exit xilinxfb_cleanup(void) { - platform_driver_unregister(&xilinxfb_platform_driver); + xilinxfb_platform_unregister(); xilinxfb_of_unregister(); } -- 1.5.3.4-dirty ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <1206721237-17982-4-git-send-email-stephen.neuendorffer@xilinx.com>]
* [PATCH 5/5] [RFC][PPC] Use DCR for arch ppc, and enable MMIO and NATIVE for virtex. [not found] ` <1206721237-17982-4-git-send-email-stephen.neuendorffer@xilinx.com> @ 2008-03-28 16:20 ` Stephen Neuendorffer 0 siblings, 0 replies; 5+ messages in thread From: Stephen Neuendorffer @ 2008-03-28 16:20 UTC (permalink / raw) To: linuxppc-dev, benh, jwboyer, sfr, grant.likely, git-dev, linux-kernel Cc: Stephen Neuendorffer Generally speaking, I'm not sure about the validity of this patch. In particular: 1) I'm not sure what architecture code relies on including dcr support through ibm4xx.h. 2) I'm not sure how temporary the ifdef in arch/powerpc/sysdev/Makefile really is. Is it still needed or not? However, this appears to work at least for the Virtex systems I've tried. In any event, I don't expect this to actually be sent to mainline, since it's ARCH=ppc related, at least not in this form. Unfortunately, the framebuffer driver won't work under ARCH=ppc without this patch. --- arch/powerpc/sysdev/Makefile | 2 -- arch/ppc/Kconfig | 6 +++++- arch/ppc/platforms/4xx/Kconfig | 2 ++ include/asm-ppc/ibm4xx.h | 1 - 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile index 15f3e85..c85525b 100644 --- a/arch/powerpc/sysdev/Makefile +++ b/arch/powerpc/sysdev/Makefile @@ -35,10 +35,8 @@ endif endif # Temporary hack until we have migrated to asm-powerpc -ifeq ($(ARCH),powerpc) obj-$(CONFIG_CPM) += cpm_common.o obj-$(CONFIG_CPM2) += cpm2.o cpm2_pic.o obj-$(CONFIG_PPC_DCR) += dcr.o obj-$(CONFIG_8xx) += mpc8xx_pic.o cpm1.o obj-$(CONFIG_UCODE_PATCH) += micropatch.o -endif diff --git a/arch/ppc/Kconfig b/arch/ppc/Kconfig index abc877f..81d6748 100644 --- a/arch/ppc/Kconfig +++ b/arch/ppc/Kconfig @@ -116,9 +116,13 @@ config PPC_DCR_NATIVE bool default n +config PPC_DCR_MMIO + bool + default n + config PPC_DCR bool - depends on PPC_DCR_NATIVE + depends on PPC_DCR_NATIVE || PPC_DCR_MMIO default y config PTE_64BIT diff --git a/arch/ppc/platforms/4xx/Kconfig b/arch/ppc/platforms/4xx/Kconfig index 76551b6..0430fc2 100644 --- a/arch/ppc/platforms/4xx/Kconfig +++ b/arch/ppc/platforms/4xx/Kconfig @@ -228,6 +228,8 @@ config XILINX_VIRTEX_4_FX config XILINX_VIRTEX bool + select PPC_DCR_NATIVE + select PPC_DCR_MMIO config STB03xxx bool diff --git a/include/asm-ppc/ibm4xx.h b/include/asm-ppc/ibm4xx.h index ed6891a..053a86b 100644 --- a/include/asm-ppc/ibm4xx.h +++ b/include/asm-ppc/ibm4xx.h @@ -15,7 +15,6 @@ #define __ASM_IBM4XX_H__ #include <asm/types.h> -#include <asm/dcr.h> #ifdef CONFIG_40x -- 1.5.3.4-dirty ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-03-28 16:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1206401313-1625-1-git-send-email-stephen.neuendorffer@xilinx.com>
2008-03-28 16:20 ` [PATCH 1/5] [v2][POWERPC] refactor dcr code Stephen Neuendorffer
[not found] ` <1206721237-17982-1-git-send-email-stephen.neuendorffer@xilinx.com>
2008-03-28 16:20 ` [PATCH 2/5] [POWERPC] Xilinx: Virtex: Enable dcr for MMIO and NATIVE Stephen Neuendorffer
[not found] ` <1206721237-17982-2-git-send-email-stephen.neuendorffer@xilinx.com>
2008-03-28 16:20 ` [PATCH 3/5] [POWERPC] explicit dcr support Stephen Neuendorffer
[not found] ` <1206721237-17982-3-git-send-email-stephen.neuendorffer@xilinx.com>
2008-03-28 16:20 ` [PATCH 4/5] [POWERPC] Xilinx: Framebuffer: Use dcr infrastructure Stephen Neuendorffer
[not found] ` <1206721237-17982-4-git-send-email-stephen.neuendorffer@xilinx.com>
2008-03-28 16:20 ` [PATCH 5/5] [RFC][PPC] Use DCR for arch ppc, and enable MMIO and NATIVE for virtex Stephen Neuendorffer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®