mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 01:49:46 +00:00
drivers: mmc: preallocate a block for SD extension register accesses
The Performance Extension register is regularly accessed in a hot path to do write cache flushes. Don't invoke kmalloc/kfree for every access, preallocate a 512B buffer for this purpose. Also remove an unused alloc in sd_enable_cache(). Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
This commit is contained in:
committed by
Dom Cobley
parent
ab227dde54
commit
15d7e6c313
@@ -266,6 +266,8 @@ static void mmc_release_card(struct device *dev)
|
||||
|
||||
sdio_free_common_cis(card);
|
||||
|
||||
kfree(card->ext_reg_buf);
|
||||
|
||||
kfree(card->info);
|
||||
|
||||
kfree(card);
|
||||
|
||||
@@ -1044,9 +1044,8 @@ int sd_write_ext_reg(struct mmc_card *card, u8 fno, u8 page, u16 offset,
|
||||
struct scatterlist sg;
|
||||
u8 *reg_buf;
|
||||
|
||||
reg_buf = kzalloc(512, GFP_KERNEL);
|
||||
if (!reg_buf)
|
||||
return -ENOMEM;
|
||||
reg_buf = card->ext_reg_buf;
|
||||
memset(reg_buf, 0, 512);
|
||||
|
||||
mrq.cmd = &cmd;
|
||||
mrq.data = &data;
|
||||
@@ -1078,8 +1077,6 @@ int sd_write_ext_reg(struct mmc_card *card, u8 fno, u8 page, u16 offset,
|
||||
mmc_set_data_timeout(&data, card);
|
||||
mmc_wait_for_req(host, &mrq);
|
||||
|
||||
kfree(reg_buf);
|
||||
|
||||
/*
|
||||
* Note that, the SD card is allowed to signal busy on DAT0 up to 1s
|
||||
* after the CMD49. Although, let's leave this to be managed by the
|
||||
@@ -1120,9 +1117,7 @@ static int sd_parse_ext_reg_power(struct mmc_card *card, u8 fno, u8 page,
|
||||
int err;
|
||||
u8 *reg_buf;
|
||||
|
||||
reg_buf = kzalloc(512, GFP_KERNEL);
|
||||
if (!reg_buf)
|
||||
return -ENOMEM;
|
||||
reg_buf = card->ext_reg_buf;
|
||||
|
||||
/* Read the extension register for power management function. */
|
||||
err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf);
|
||||
@@ -1152,7 +1147,6 @@ static int sd_parse_ext_reg_power(struct mmc_card *card, u8 fno, u8 page,
|
||||
card->ext_power.offset = offset;
|
||||
|
||||
out:
|
||||
kfree(reg_buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1162,9 +1156,7 @@ static int sd_parse_ext_reg_perf(struct mmc_card *card, u8 fno, u8 page,
|
||||
int err;
|
||||
u8 *reg_buf;
|
||||
|
||||
reg_buf = kzalloc(512, GFP_KERNEL);
|
||||
if (!reg_buf)
|
||||
return -ENOMEM;
|
||||
reg_buf = card->ext_reg_buf;
|
||||
|
||||
err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf);
|
||||
if (err) {
|
||||
@@ -1207,7 +1199,6 @@ static int sd_parse_ext_reg_perf(struct mmc_card *card, u8 fno, u8 page,
|
||||
card->ext_perf.offset = offset;
|
||||
|
||||
out:
|
||||
kfree(reg_buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1278,6 +1269,12 @@ static int sd_read_ext_regs(struct mmc_card *card)
|
||||
if (!gen_info_buf)
|
||||
return -ENOMEM;
|
||||
|
||||
card->ext_reg_buf = kzalloc(512, GFP_KERNEL);
|
||||
if (!card->ext_reg_buf) {
|
||||
err = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read 512 bytes of general info, which is found at function number 0,
|
||||
* at page 0 and with no offset.
|
||||
@@ -1344,9 +1341,7 @@ static int sd_flush_cache(struct mmc_host *host)
|
||||
if (!sd_cache_enabled(host))
|
||||
return 0;
|
||||
|
||||
reg_buf = kzalloc(512, GFP_KERNEL);
|
||||
if (!reg_buf)
|
||||
return -ENOMEM;
|
||||
reg_buf = card->ext_reg_buf;
|
||||
|
||||
/*
|
||||
* Set Flush Cache at bit 0 in the performance enhancement register at
|
||||
@@ -1382,21 +1377,15 @@ static int sd_flush_cache(struct mmc_host *host)
|
||||
if (reg_buf[0] & BIT(0))
|
||||
err = -ETIMEDOUT;
|
||||
out:
|
||||
kfree(reg_buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int sd_enable_cache(struct mmc_card *card)
|
||||
{
|
||||
u8 *reg_buf;
|
||||
int err;
|
||||
|
||||
card->ext_perf.feature_enabled &= ~SD_EXT_PERF_CACHE;
|
||||
|
||||
reg_buf = kzalloc(512, GFP_KERNEL);
|
||||
if (!reg_buf)
|
||||
return -ENOMEM;
|
||||
|
||||
/*
|
||||
* Set Cache Enable at bit 0 in the performance enhancement register at
|
||||
* 260 bytes offset.
|
||||
@@ -1415,7 +1404,6 @@ static int sd_enable_cache(struct mmc_card *card)
|
||||
card->ext_perf.feature_enabled |= SD_EXT_PERF_CACHE;
|
||||
|
||||
out:
|
||||
kfree(reg_buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
@@ -355,6 +355,7 @@ struct mmc_card {
|
||||
struct sd_switch_caps sw_caps; /* switch (CMD6) caps */
|
||||
struct sd_ext_reg ext_power; /* SD extension reg for PM */
|
||||
struct sd_ext_reg ext_perf; /* SD extension reg for PERF */
|
||||
u8 *ext_reg_buf; /* 512 byte block for extension register R/W */
|
||||
|
||||
struct sd_uhs2_config uhs2_config; /* SD UHS-II config */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user