From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Warren Date: Tue, 06 Nov 2012 12:30:26 -0700 Subject: [U-Boot] [PATCH 2/3] common: rework bouncebuf implementation In-Reply-To: References: <1352156642-7975-1-git-send-email-swarren@wwwdotorg.org> <1352156642-7975-2-git-send-email-swarren@wwwdotorg.org> Message-ID: <50996552.1040802@wwwdotorg.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 11/05/2012 04:54 PM, Simon Glass wrote: > Hi Stephen, > > On Mon, Nov 5, 2012 at 3:04 PM, Stephen Warren wrote: >> From: Stephen Warren >> >> The current bouncebuf API requires all parameters to be passed to both >> bounce_buffer_start() and bounce_buffer_stop(). This works fine when >> both functions are called from the same place. However, Tegra's MMC >> driver splits the data setup and post-processing steps between two >> functions, and passing all that state around separately would be painful. >> Modify the bouncebuf API to accept a state structure as a parameter, so >> that only a single struct needs to be passed to both APIs. >> diff --git a/common/bouncebuf.c b/common/bouncebuf.c >> -int bounce_buffer_start(void **data, size_t len, void **backup, uint8_t flags) >> +int bounce_buffer_start(struct bounce_buffer_state *state, void *data, >> + size_t len, uint8_t flags) >> { >> - void *tmp; >> - size_t alen; >> + state->user_buffer = data; >> + state->bounce_buffer = data; >> + state->len = len; >> + state->len_aligned = roundup(len, ARCH_DMA_MINALIGN); >> + state->flags = flags; >> >> - if (addr_aligned(*data, len)) { >> - *backup = NULL; >> + if (addr_aligned(data, len)) > > Maybe consider checking for data == NULL here, and return 0. This > would allow you to remove your 'if (data)' checks in the tegra driver. > Would need to update function description in the header file though. That doesn't actually work out. The if (data) test in the Tegra driver is checking whether a non-NULL "struct mmc_data *data" is passed to Tegra's mmc_send_cmd(). That value isn't directly passed to bounce_buffer_start(), but rather data->{src,dest}, which doesn't even exist if (!data).