From mboxrd@z Thu Jan 1 00:00:00 1970 From: Scott Wood Date: Mon, 29 Aug 2011 16:23:08 -0500 Subject: [U-Boot] [PATCH] mmc:dcache: Cache line size aligned internal MMC buffers In-Reply-To: References: <1313745913-28672-1-git-send-email-l.majewski@samsung.com> <201108231732.39791.vapier@gentoo.org> <20110823224246.7F11411F9E62@gemini.denx.de> <201108232301.01270.vapier@gentoo.org> <20110824120744.097ba2c5@lmajewski.digital.local> <20110824132553.A5F2C11F9E76@gemini.denx.de> <20110824181252.CAB9E11F9E76@gemini.denx.de> <20110824211812.1e9f039c@mig> <4E5BFADE.9000200@freescale.com> Message-ID: <4E5C033C.9090808@freescale.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 08/29/2011 03:58 PM, Anton Staaf wrote: > On Mon, Aug 29, 2011 at 1:47 PM, Scott Wood wrote: >> On 08/29/2011 03:12 PM, Anton Staaf wrote: >>> 1) Mikes's macro >>> >>> #define DMA_ALIGN_SIZE(size) \ >>> (((size) + CONFIG_SYS_CACHELINE_SIZE - 1) >>> >>> #define DMA_DECLARE_BUFFER(type, name, size) \ >>> void __##name[DMA_ALIGN_SIZE(size * sizeof(type))]; \ >>> type * name = __##name & ~(CONFIG_SYS_CACHELINE_SIZE - 1)); >>> >>> DMA_DECLARE_BUFFER(int, buffer, 100); >> >> This doesn't compile, and it tries to round the buffer down below its >> starting point. > > You are correct. I wrote that one as a modification of mikes initial > proposal. I should have caught the incorrect rounding when I did. > The patch that Lukasz sent titled "dcache: Dcache line size aligned > stack buffer allocation" has a correct implementation. With the version in that patch I get the slightly different "error: initializer element is not computable at load time". Seems like whether you cast the address to (type *) or (void *) determines which error you get. This is with GCC 4.5.1 (powerpc) and 4.6.0 (x86). Maybe it's arch-dependent, based on available relocation types. Also, shouldn't the array be of type "char" rather than "char *"? How do you make the declaration static? >> After fixing the more obvious issues, I get "error: initializer element >> is not constant". > > I think this requires the use of -std=c99 or GCC extensions. More > specifics can be found here: > http://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html -std=c99 doesn't help. The problem isn't the array itself, it's the pointer initializer. >> You could set the pointer at runtime, though, and remove some of the >> macrification: >> >> #define DMA_ALIGN_SIZE(size) \ >> ((size) + CONFIG_SYS_CACHELINE_SIZE - 1) >> #define DMA_ALIGN_ADDR(addr) \ >> (DMA_ALIGN_SIZE(addr) & (CONFIG_SYS_CACHELINE_SIZE - 1)) >> >> int buffer_unaligned[DMA_ALIGN_SIZE(100)]; >> int *buffer; >> >> some_init_func() >> { >> buffer = (int *)(DMA_ALIGN_ADDR((uintptr_t)buffer_unaligned)); >> } > > :) This was one of my suggestions earlier on a different thread. It > was rejected there, I believe because it makes things less clear. So, the complex macro is bad because it obscures things, and this version is bad because it doesn't? :-) -Scott