.. | .. |
---|
6 | 6 | */ |
---|
7 | 7 | |
---|
8 | 8 | #include <common.h> |
---|
| 9 | +#include <bouncebuf.h> |
---|
9 | 10 | #include <dm.h> |
---|
10 | 11 | #include <errno.h> |
---|
11 | 12 | #include <memalign.h> |
---|
.. | .. |
---|
740 | 741 | u64 prp2; |
---|
741 | 742 | u64 total_len = blkcnt << desc->log2blksz; |
---|
742 | 743 | u64 temp_len = total_len; |
---|
| 744 | + uintptr_t temp_buffer; |
---|
743 | 745 | |
---|
744 | 746 | u64 slba = blknr; |
---|
745 | 747 | u16 lbas = 1 << (dev->max_transfer_shift - ns->lba_shift); |
---|
746 | 748 | u64 total_lbas = blkcnt; |
---|
747 | 749 | |
---|
748 | | - flush_dcache_range((unsigned long)buffer, |
---|
749 | | - (unsigned long)buffer + total_len); |
---|
| 750 | + struct bounce_buffer bb; |
---|
| 751 | + unsigned int bb_flags; |
---|
| 752 | + int ret; |
---|
| 753 | + |
---|
| 754 | + if (read) |
---|
| 755 | + bb_flags = GEN_BB_WRITE; |
---|
| 756 | + else |
---|
| 757 | + bb_flags = GEN_BB_READ; |
---|
| 758 | + |
---|
| 759 | + ret = bounce_buffer_start(&bb, buffer, total_len, bb_flags); |
---|
| 760 | + if (ret) |
---|
| 761 | + return -ENOMEM; |
---|
| 762 | + temp_buffer = (unsigned long)bb.bounce_buffer; |
---|
750 | 763 | |
---|
751 | 764 | c.rw.opcode = read ? nvme_cmd_read : nvme_cmd_write; |
---|
752 | 765 | c.rw.flags = 0; |
---|
.. | .. |
---|
771 | 784 | } |
---|
772 | 785 | |
---|
773 | 786 | if (nvme_setup_prps(dev, &prp2, |
---|
774 | | - lbas << ns->lba_shift, (ulong)buffer)) |
---|
| 787 | + lbas << ns->lba_shift, temp_buffer)) |
---|
775 | 788 | return -EIO; |
---|
776 | 789 | c.rw.slba = cpu_to_le64(slba); |
---|
777 | 790 | slba += lbas; |
---|
778 | 791 | c.rw.length = cpu_to_le16(lbas - 1); |
---|
779 | | - c.rw.prp1 = cpu_to_le64((ulong)buffer); |
---|
| 792 | + c.rw.prp1 = cpu_to_le64(temp_buffer); |
---|
780 | 793 | c.rw.prp2 = cpu_to_le64(prp2); |
---|
781 | 794 | status = nvme_submit_sync_cmd(dev->queues[NVME_IO_Q], |
---|
782 | 795 | &c, NULL, IO_TIMEOUT); |
---|
783 | 796 | if (status) |
---|
784 | 797 | break; |
---|
785 | 798 | temp_len -= (u32)lbas << ns->lba_shift; |
---|
786 | | - buffer += lbas << ns->lba_shift; |
---|
| 799 | + temp_buffer += lbas << ns->lba_shift; |
---|
787 | 800 | } |
---|
788 | 801 | |
---|
789 | | - if (read) |
---|
790 | | - invalidate_dcache_range((unsigned long)buffer, |
---|
791 | | - (unsigned long)buffer + total_len); |
---|
| 802 | + bounce_buffer_stop(&bb); |
---|
792 | 803 | |
---|
793 | 804 | return (total_len - temp_len) >> desc->log2blksz; |
---|
794 | 805 | } |
---|