Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 332822
b: refs/heads/master
c: 1a41313
h: refs/heads/master
v: v3
  • Loading branch information
Kyungsik Lee authored and Chris Ball committed Sep 19, 2012
1 parent a8eb120 commit 72e4a93
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8f63795c60ef5bc3dbfcbf19c1ac64ed79d23c62
refs/heads/master: 1a41313e7f8c5b724a2e3ff66558dbe811844423
58 changes: 42 additions & 16 deletions trunk/drivers/mmc/core/mmc_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 *cxd, int opcode)
return 0;
}

/*
* NOTE: void *buf, caller for the buf is required to use DMA-capable
* buffer or on-stack buffer (with some overhead in callee).
*/
static int
mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
u32 opcode, void *buf, unsigned len)
Expand All @@ -239,13 +243,19 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
struct mmc_data data = {0};
struct scatterlist sg;
void *data_buf;
int is_on_stack;

/* dma onto stack is unsafe/nonportable, but callers to this
* routine normally provide temporary on-stack buffers ...
*/
data_buf = kmalloc(len, GFP_KERNEL);
if (data_buf == NULL)
return -ENOMEM;
is_on_stack = object_is_on_stack(buf);
if (is_on_stack) {
/*
* dma onto stack is unsafe/nonportable, but callers to this
* routine normally provide temporary on-stack buffers ...
*/
data_buf = kmalloc(len, GFP_KERNEL);
if (!data_buf)
return -ENOMEM;
} else
data_buf = buf;

mrq.cmd = &cmd;
mrq.data = &data;
Expand Down Expand Up @@ -280,8 +290,10 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,

mmc_wait_for_req(host, &mrq);

memcpy(buf, data_buf, len);
kfree(data_buf);
if (is_on_stack) {
memcpy(buf, data_buf, len);
kfree(data_buf);
}

if (cmd.error)
return cmd.error;
Expand All @@ -294,24 +306,32 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
int mmc_send_csd(struct mmc_card *card, u32 *csd)
{
int ret, i;
u32 *csd_tmp;

if (!mmc_host_is_spi(card->host))
return mmc_send_cxd_native(card->host, card->rca << 16,
csd, MMC_SEND_CSD);

ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
csd_tmp = kmalloc(16, GFP_KERNEL);
if (!csd_tmp)
return -ENOMEM;

ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd_tmp, 16);
if (ret)
return ret;
goto err;

for (i = 0;i < 4;i++)
csd[i] = be32_to_cpu(csd[i]);
csd[i] = be32_to_cpu(csd_tmp[i]);

return 0;
err:
kfree(csd_tmp);
return ret;
}

int mmc_send_cid(struct mmc_host *host, u32 *cid)
{
int ret, i;
u32 *cid_tmp;

if (!mmc_host_is_spi(host)) {
if (!host->card)
Expand All @@ -320,14 +340,20 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid)
cid, MMC_SEND_CID);
}

ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
cid_tmp = kmalloc(16, GFP_KERNEL);
if (!cid_tmp)
return -ENOMEM;

ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid_tmp, 16);
if (ret)
return ret;
goto err;

for (i = 0;i < 4;i++)
cid[i] = be32_to_cpu(cid[i]);
cid[i] = be32_to_cpu(cid_tmp[i]);

return 0;
err:
kfree(cid_tmp);
return ret;
}

int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
Expand Down

0 comments on commit 72e4a93

Please sign in to comment.