git: 9front

Download patch

ref: 7207bae5d53e913081ae6edd7a6eb34bf1a10249
parent: cb0a62fe37e20ef724530d07d08413b7dde6d7a3
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Mar 6 11:16:45 EST 2015

devsd: always page align sd buffers

sdbio() tests if it can pass the buffer pointer directly to
the driver when it is already in kernel memory. we also need
to check if the buffer is properly aligned but alignment
requirement is handled in system specific sdmalloc() and
was not known to devsd.

to solve this, we *always* page align sd buffers and get rid
of the system specific sdmalloc() macro (was only used in bcm
kernel).

--- a/sys/src/9/bcm/fns.h
+++ b/sys/src/9/bcm/fns.h
@@ -58,8 +58,6 @@
 extern void procfork(Proc*);
 extern void procsetup(Proc*);
 extern void screeninit(void);
-#define sdfree(p) free(p)
-#define sdmalloc(n)	mallocalign(n, CACHELINESZ, 0, 0)
 extern void setpower(int, int);
 extern void setr13(int, u32int*);
 extern int splfhi(void);
--- a/sys/src/9/port/devsd.c
+++ b/sys/src/9/port/devsd.c
@@ -843,7 +843,7 @@
 		len = nb*unit->secsize - offset;
 	hard = offset || write && len%unit->secsize;
 
-	if(iskaddr(a) && !hard) {
+	if(iskaddr(a) && ((uintptr)a & (BY2PG-1))==0 && !hard) {
 		b = (uchar*)a;
 		allocd = 0;
 	}else{
--- a/sys/src/9/port/sd.h
+++ b/sys/src/9/port/sd.h
@@ -145,15 +145,10 @@
 };
 
 /*
- * Allow the default #defines for sdmalloc & sdfree to be overridden by
- * system-specific versions.  This can be used to avoid extra copying
- * by making sure sd buffers are cache-aligned (some ARM systems) or
- * page-aligned (xen) for DMA.
+ * Avoid extra copying by making sd buffers page-aligned for DMA.
  */
-#ifndef sdmalloc
-#define sdmalloc(n)	malloc(n)
+#define sdmalloc(n)	mallocalign(n, BY2PG, 0, 0)
 #define sdfree(p)	free(p)
-#endif
 
 /*
  * mmc/sd/sdio host controller interface
--