| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | User DMA |
|---|
| 3 | 4 | |
|---|
| .. | .. |
|---|
| 5 | 6 | Copyright (C) 2004 Chris Kennedy <c@groovy.org> |
|---|
| 6 | 7 | Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl> |
|---|
| 7 | 8 | |
|---|
| 8 | | - This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - it under the terms of the GNU General Public License as published by |
|---|
| 10 | | - the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | | - (at your option) any later version. |
|---|
| 12 | | - |
|---|
| 13 | | - This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | | - GNU General Public License for more details. |
|---|
| 17 | | - |
|---|
| 18 | | - You should have received a copy of the GNU General Public License |
|---|
| 19 | | - along with this program; if not, write to the Free Software |
|---|
| 20 | | - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | 9 | */ |
|---|
| 22 | 10 | |
|---|
| 23 | 11 | #include "ivtv-driver.h" |
|---|
| .. | .. |
|---|
| 104 | 92 | { |
|---|
| 105 | 93 | struct ivtv_dma_page_info user_dma; |
|---|
| 106 | 94 | struct ivtv_user_dma *dma = &itv->udma; |
|---|
| 107 | | - int i, err; |
|---|
| 95 | + int err; |
|---|
| 108 | 96 | |
|---|
| 109 | 97 | IVTV_DEBUG_DMA("ivtv_udma_setup, dst: 0x%08x\n", (unsigned int)ivtv_dest_addr); |
|---|
| 110 | 98 | |
|---|
| .. | .. |
|---|
| 123 | 111 | return -EINVAL; |
|---|
| 124 | 112 | } |
|---|
| 125 | 113 | |
|---|
| 126 | | - /* Get user pages for DMA Xfer */ |
|---|
| 127 | | - err = get_user_pages_unlocked(user_dma.uaddr, user_dma.page_count, |
|---|
| 114 | + /* Pin user pages for DMA Xfer */ |
|---|
| 115 | + err = pin_user_pages_unlocked(user_dma.uaddr, user_dma.page_count, |
|---|
| 128 | 116 | dma->map, FOLL_FORCE); |
|---|
| 129 | 117 | |
|---|
| 130 | 118 | if (user_dma.page_count != err) { |
|---|
| 131 | 119 | IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n", |
|---|
| 132 | 120 | err, user_dma.page_count); |
|---|
| 133 | 121 | if (err >= 0) { |
|---|
| 134 | | - for (i = 0; i < err; i++) |
|---|
| 135 | | - put_page(dma->map[i]); |
|---|
| 122 | + unpin_user_pages(dma->map, err); |
|---|
| 136 | 123 | return -EINVAL; |
|---|
| 137 | 124 | } |
|---|
| 138 | 125 | return err; |
|---|
| .. | .. |
|---|
| 142 | 129 | |
|---|
| 143 | 130 | /* Fill SG List with new values */ |
|---|
| 144 | 131 | if (ivtv_udma_fill_sg_list(dma, &user_dma, 0) < 0) { |
|---|
| 145 | | - for (i = 0; i < dma->page_count; i++) { |
|---|
| 146 | | - put_page(dma->map[i]); |
|---|
| 147 | | - } |
|---|
| 132 | + unpin_user_pages(dma->map, dma->page_count); |
|---|
| 148 | 133 | dma->page_count = 0; |
|---|
| 149 | 134 | return -ENOMEM; |
|---|
| 150 | 135 | } |
|---|
| .. | .. |
|---|
| 165 | 150 | void ivtv_udma_unmap(struct ivtv *itv) |
|---|
| 166 | 151 | { |
|---|
| 167 | 152 | struct ivtv_user_dma *dma = &itv->udma; |
|---|
| 168 | | - int i; |
|---|
| 169 | 153 | |
|---|
| 170 | 154 | IVTV_DEBUG_INFO("ivtv_unmap_user_dma\n"); |
|---|
| 171 | 155 | |
|---|
| .. | .. |
|---|
| 181 | 165 | /* sync DMA */ |
|---|
| 182 | 166 | ivtv_udma_sync_for_cpu(itv); |
|---|
| 183 | 167 | |
|---|
| 184 | | - /* Release User Pages */ |
|---|
| 185 | | - for (i = 0; i < dma->page_count; i++) { |
|---|
| 186 | | - put_page(dma->map[i]); |
|---|
| 187 | | - } |
|---|
| 168 | + unpin_user_pages(dma->map, dma->page_count); |
|---|
| 188 | 169 | dma->page_count = 0; |
|---|
| 189 | 170 | } |
|---|
| 190 | 171 | |
|---|