Skip to contentSkip to conversation

xtensa: cache inquiry and unaligned cache handling functions

PATCH New Oskar Schirmer 1 participant 2 messages Mar 23, 2009 Tensilica Xtensa port (xtensa)

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xtensa: cache inquiry and unaligned cache handling functions

The existing xtensa cache handling functions work on page-aligned memory regions.

These functions are needed for the s6000 dma engine which can work on a byte-granularity.

---
 arch/xtensa/include/asm/cacheflush.h |   95 ++++++++++++++++++++++++++++++++++
 1 files changed, 95 insertions(+), 0 deletions(-)
arch/xtensa/include/asm/cacheflush.h +95 -0
index 8fc1c0c..b7b8fbe 100644
@@ -155,5 +155,100 @@ extern void copy_from_user_page(struct vm_area_struct*, struct page*,
 
 #endif
 
+#define XTENSA_CACHEBLK_LOG2	29
+#define XTENSA_CACHEBLK_SIZE	(1 << XTENSA_CACHEBLK_LOG2)
+#define XTENSA_CACHEBLK_MASK	(7 << XTENSA_CACHEBLK_LOG2)
+
+#if XCHAL_HAVE_CACHEATTR
+static inline u32 xtensa_get_cacheattr(void)
+{
+	u32 r;
+	asm volatile("	rsr %0, CACHEATTR" : "=a"(r));
+	return r;
+}
+
+static inline u32 xtensa_get_dtlb1(u32 addr)
+{
+	u32 r = addr & XTENSA_CACHEBLK_MASK;
+	return r | ((xtensa_get_cacheattr() >> (r >> (XTENSA_CACHEBLK_LOG2-2)))
+			& 0xF);
+}
+#else
+static inline u32 xtensa_get_dtlb1(u32 addr)
+{
+	u32 r;
+	asm volatile("	rdtlb1 %0, %1" : "=a"(r) : "a"(addr));
+	asm volatile("	dsync");
+	return r;
+}
+
+static inline u32 xtensa_get_cacheattr(void)
+{
+	u32 r = 0;
+	u32 a = 0;
+	do {
+		a -= XTENSA_CACHEBLK_SIZE;
+		r = (r << 4) | (xtensa_get_dtlb1(a) & 0xF);
+	} while (a);
+	return r;
+}
+#endif
+
+static inline int xtensa_need_flush_dma_source(u32 addr)
+{
+	return (xtensa_get_dtlb1(addr) & ((1 << XCHAL_CA_BITS) - 1)) >= 4;
+}
+
+static inline int xtensa_need_invalidate_dma_destination(u32 addr)
+{
+	return (xtensa_get_dtlb1(addr) & ((1 << XCHAL_CA_BITS) - 1)) != 2;
+}
+
+static inline void flush_dcache_unaligned(u32 addr, u32 size)
+{
+	u32 cnt;
+	if (size) {
+		cnt = (size + ((XCHAL_DCACHE_LINESIZE - 1) & addr)
+			+ XCHAL_DCACHE_LINESIZE - 1) / XCHAL_DCACHE_LINESIZE;
+		while (cnt--) {
+			asm volatile("	dhwb %0, 0" : : "a"(addr));
+			addr += XCHAL_DCACHE_LINESIZE;
+		}
+		asm volatile("	dsync");
+	}
+}
+
+static inline void invalidate_dcache_unaligned(u32 addr, u32 size)
+{
+	int cnt;
+	if (size) {
+		asm volatile("	dhwbi %0, 0 ;" : : "a"(addr));
+		cnt = (size + ((XCHAL_DCACHE_LINESIZE - 1) & addr)
+			- XCHAL_DCACHE_LINESIZE - 1) / XCHAL_DCACHE_LINESIZE;
+		while (cnt-- > 0) {
+			asm volatile("	dhi %0, %1" : : "a"(addr),
+						"n"(XCHAL_DCACHE_LINESIZE));
+			addr += XCHAL_DCACHE_LINESIZE;
+		}
+		asm volatile("	dhwbi %0, %1" : : "a"(addr),
+						"n"(XCHAL_DCACHE_LINESIZE));
+		asm volatile("	dsync");
+	}
+}
+
+static inline void flush_invalidate_dcache_unaligned(u32 addr, u32 size)
+{
+	u32 cnt;
+	if (size) {
+		cnt = (size + ((XCHAL_DCACHE_LINESIZE - 1) & addr)
+			+ XCHAL_DCACHE_LINESIZE - 1) / XCHAL_DCACHE_LINESIZE;
+		while (cnt--) {
+			asm volatile("	dhwbi %0, 0" : : "a"(addr));
+			addr += XCHAL_DCACHE_LINESIZE;
+		}
+		asm volatile("	dsync");
+	}
+}
+
 #endif /* __KERNEL__ */
 #endif /* _XTENSA_CACHEFLUSH_H */
Signature · 1 line
1.6.2.107.ge47ee
#1 lore raw

PATCH 2/2 xtensa: s6000 dma engine support

There are four slightly different dma engines on the s6000 family. One for memory-memory transfers, the other three for memory-device.

This patch implements a platform-specific kernel-API to control these engines. It is needed for the network, video, audio peripherals on s6000.

---
 arch/xtensa/variants/s6000/Makefile               |    2 +-
 arch/xtensa/variants/s6000/dmac.c                 |  173 +++++++++
 arch/xtensa/variants/s6000/include/variant/dmac.h |  387 +++++++++++++++++++++
 3 files changed, 561 insertions(+), 1 deletions(-)
 create mode 100644 arch/xtensa/variants/s6000/dmac.c
 create mode 100644 arch/xtensa/variants/s6000/include/variant/dmac.h
arch/xtensa/variants/s6000/Makefile +1 -1
index 03b3975..ddfa415 100644
@@ -1,3 +1,3 @@
 # s6000 Makefile
 
-obj-y		+= irq.o gpio.o
+obj-y		+= irq.o gpio.o dmac.o
arch/xtensa/variants/s6000/dmac.c new file +173 -0

173 lines not on this page · raw message

arch/xtensa/variants/s6000/include/variant/dmac.h new file +387 -0

387 lines not on this page · raw message

Signature · 1 line
1.6.2.107.ge47ee