Skip to content

Commit

Permalink
nvme: flush dcache on both r/w, and the prp list
Browse files Browse the repository at this point in the history
It's possible that the data cache for the buffer still holds data
to be flushed to memory, since the buffer was probably used as stack
before.  Thus we need to make sure to flush it also on reads, since
it's possible that the cache is automatically flused to memory after
the NVMe DMA transfer happened, thus overwriting the NVMe transfer's
data.  Also add a missing dcache flush for the prp list.

Signed-off-by: Patrick Wildt <[email protected]>
Reviewed-by: Bin Meng <[email protected]>
  • Loading branch information
bluerise authored and trini committed Oct 31, 2019
1 parent 232ba76 commit 8c40340
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/nvme/nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ static int nvme_setup_prps(struct nvme_dev *dev, u64 *prp2,
}
*prp2 = (ulong)dev->prp_pool;

flush_dcache_range((ulong)dev->prp_pool, (ulong)dev->prp_pool +
dev->prp_entry_num * sizeof(u64));

return 0;
}

Expand Down Expand Up @@ -705,9 +708,8 @@ static ulong nvme_blk_rw(struct udevice *udev, lbaint_t blknr,
u16 lbas = 1 << (dev->max_transfer_shift - ns->lba_shift);
u64 total_lbas = blkcnt;

if (!read)
flush_dcache_range((unsigned long)buffer,
(unsigned long)buffer + total_len);
flush_dcache_range((unsigned long)buffer,
(unsigned long)buffer + total_len);

c.rw.opcode = read ? nvme_cmd_read : nvme_cmd_write;
c.rw.flags = 0;
Expand Down

0 comments on commit 8c40340

Please sign in to comment.