From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lukasz Majewski Date: Wed, 24 Aug 2011 16:31:37 +0200 Subject: [U-Boot] [PATCH] mmc:dcache: Cache line size aligned internal MMC buffers In-Reply-To: <20110824132553.A5F2C11F9E76@gemini.denx.de> 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> Message-ID: <20110824163137.2e0f24a3@lmajewski.digital.local> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Wolfgang, > I think I'd like to see a macro that can be used like this: > > void *dma_buffer_pointer = DMA_BUFFER(size_in_bytes); > Frankly speaking I don't know any easy way to define buffer this way in a macro (at least without digging deep enough to C preprocessor programming tricks). Maybe Mike or Anton knows. The void *dma_buffer_pointer = DMA_BUFFER(size_in_bytes); approach needs to do following things in macro: #define DMA_BUFFER(100) \ char buf[100 + get_dcache_line_size]; \ unsigned long tmp = (unsigned long) buf; \ void* buf_out = (void*) ((tmp + (get_dcache_line_size() - 1)) & ~(get_dcache_line_size() - 1)) The problem here is to assign the buf_out pointer to the void *dma_buffer_pointer. How can we "return" the void *buf_out? For comparison please look to this solution: #define ALIGN_ADDR(addr) ((void *)(((unsigned long) addr + get_dcache_line_size() - 1)\ & ~(get_dcache_line_size() - 1))) #define DMA_DECLARE_BUFFER(type, name, size) \ char *__##name[size + get_dcache_line_size()]; \ type *name = ALIGN_ADDR(__##name); int mmc_startup(struct mmc *mmc) { /* Some declarations */ /* char ext_csd[512]; */ DMA_DECLARE_BUFFER(char, ext_csd, 512); printf("%s: ptr:%p\n", __func__, ext_csd); /* rest of the code */ } Here the DMA_DECLARE_BUFFER really defines the buffer as an automatic variable with this function scope. This is tested and works :-) > > > 4. get_dcache_line_size() can be simply defined as > > #define get_dcache_line_size() CONFIG_SYS_CACHE_LINE_SIZE if we > > _really_ want to save a few bytes. > > Actually I fail to understand why we would ever need > get_dcache_line_size() in a boot loader. If I can ask for clarification here. Shall not u-boot read on fly the cache line size (as it is now done) or you don't like the get_cache_line_size defined as function? Going further shall the get_cache_line_size be removed completely and replaced with CONFIG_SYS_CACHE_LINE_SIZE? > > Best regards, > > Wolfgang Denk > -- Best regards, Lukasz Majewski Samsung Poland R&D Center Platform Group