Lines Matching +full:sg +full:- +full:micro

1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2023 Advanced Micro Devices, Inc. */
32 lm_file->filep = in pds_vfio_get_lm_file()
34 if (IS_ERR(lm_file->filep)) in pds_vfio_get_lm_file()
37 stream_open(lm_file->filep->f_inode, lm_file->filep); in pds_vfio_get_lm_file()
38 mutex_init(&lm_file->lock); in pds_vfio_get_lm_file()
41 get_file(lm_file->filep); in pds_vfio_get_lm_file()
53 p = page_mem - offset_in_page(page_mem); in pds_vfio_get_lm_file()
66 if (sg_alloc_table_from_pages(&lm_file->sg_table, pages, npages, 0, in pds_vfio_get_lm_file()
70 lm_file->size = size; in pds_vfio_get_lm_file()
71 lm_file->pages = pages; in pds_vfio_get_lm_file()
72 lm_file->npages = npages; in pds_vfio_get_lm_file()
73 lm_file->page_mem = page_mem; in pds_vfio_get_lm_file()
74 lm_file->alloc_size = npages * PAGE_SIZE; in pds_vfio_get_lm_file()
83 fput(lm_file->filep); in pds_vfio_get_lm_file()
84 mutex_destroy(&lm_file->lock); in pds_vfio_get_lm_file()
93 mutex_lock(&lm_file->lock); in pds_vfio_put_lm_file()
95 lm_file->disabled = true; in pds_vfio_put_lm_file()
96 lm_file->size = 0; in pds_vfio_put_lm_file()
97 lm_file->alloc_size = 0; in pds_vfio_put_lm_file()
98 lm_file->filep->f_pos = 0; in pds_vfio_put_lm_file()
101 sg_free_table(&lm_file->sg_table); in pds_vfio_put_lm_file()
103 kvfree(lm_file->page_mem); in pds_vfio_put_lm_file()
104 lm_file->page_mem = NULL; in pds_vfio_put_lm_file()
105 kfree(lm_file->pages); in pds_vfio_put_lm_file()
106 lm_file->pages = NULL; in pds_vfio_put_lm_file()
108 mutex_unlock(&lm_file->lock); in pds_vfio_put_lm_file()
111 fput(lm_file->filep); in pds_vfio_put_lm_file()
116 if (!pds_vfio->save_file) in pds_vfio_put_save_file()
119 pds_vfio_put_lm_file(pds_vfio->save_file); in pds_vfio_put_save_file()
120 pds_vfio->save_file = NULL; in pds_vfio_put_save_file()
125 if (!pds_vfio->restore_file) in pds_vfio_put_restore_file()
128 pds_vfio_put_lm_file(pds_vfio->restore_file); in pds_vfio_put_restore_file()
129 pds_vfio->restore_file = NULL; in pds_vfio_put_restore_file()
136 struct scatterlist *sg; in pds_vfio_get_file_page() local
140 if (offset < lm_file->last_offset || !lm_file->last_offset_sg) { in pds_vfio_get_file_page()
141 lm_file->last_offset = 0; in pds_vfio_get_file_page()
142 lm_file->last_offset_sg = lm_file->sg_table.sgl; in pds_vfio_get_file_page()
143 lm_file->sg_last_entry = 0; in pds_vfio_get_file_page()
146 cur_offset = lm_file->last_offset; in pds_vfio_get_file_page()
148 for_each_sg(lm_file->last_offset_sg, sg, in pds_vfio_get_file_page()
149 lm_file->sg_table.orig_nents - lm_file->sg_last_entry, i) { in pds_vfio_get_file_page()
150 if (offset < sg->length + cur_offset) { in pds_vfio_get_file_page()
151 lm_file->last_offset_sg = sg; in pds_vfio_get_file_page()
152 lm_file->sg_last_entry += i; in pds_vfio_get_file_page()
153 lm_file->last_offset = cur_offset; in pds_vfio_get_file_page()
154 return nth_page(sg_page(sg), in pds_vfio_get_file_page()
155 (offset - cur_offset) / PAGE_SIZE); in pds_vfio_get_file_page()
157 cur_offset += sg->length; in pds_vfio_get_file_page()
165 struct pds_vfio_lm_file *lm_file = filp->private_data; in pds_vfio_release_file()
167 mutex_lock(&lm_file->lock); in pds_vfio_release_file()
168 lm_file->filep->f_pos = 0; in pds_vfio_release_file()
169 lm_file->size = 0; in pds_vfio_release_file()
170 mutex_unlock(&lm_file->lock); in pds_vfio_release_file()
171 mutex_destroy(&lm_file->lock); in pds_vfio_release_file()
180 struct pds_vfio_lm_file *lm_file = filp->private_data; in pds_vfio_save_read()
184 return -ESPIPE; in pds_vfio_save_read()
185 pos = &filp->f_pos; in pds_vfio_save_read()
187 mutex_lock(&lm_file->lock); in pds_vfio_save_read()
189 if (lm_file->disabled) { in pds_vfio_save_read()
190 done = -ENODEV; in pds_vfio_save_read()
194 if (*pos > lm_file->size) { in pds_vfio_save_read()
195 done = -EINVAL; in pds_vfio_save_read()
199 len = min_t(size_t, lm_file->size - *pos, len); in pds_vfio_save_read()
208 page = pds_vfio_get_file_page(lm_file, *pos - page_offset); in pds_vfio_save_read()
211 done = -EINVAL; in pds_vfio_save_read()
215 page_len = min_t(size_t, len, PAGE_SIZE - page_offset); in pds_vfio_save_read()
220 done = -EFAULT; in pds_vfio_save_read()
224 len -= page_len; in pds_vfio_save_read()
230 mutex_unlock(&lm_file->lock); in pds_vfio_save_read()
242 struct device *dev = &pds_vfio->vfio_coredev.pdev->dev; in pds_vfio_get_save_file()
258 return -EIO; in pds_vfio_get_save_file()
264 return -ENOENT; in pds_vfio_get_save_file()
268 lm_file->size, lm_file->alloc_size, lm_file->npages); in pds_vfio_get_save_file()
270 pds_vfio->save_file = lm_file; in pds_vfio_get_save_file()
278 struct pds_vfio_lm_file *lm_file = filp->private_data; in pds_vfio_restore_write()
283 return -ESPIPE; in pds_vfio_restore_write()
285 pos = &filp->f_pos; in pds_vfio_restore_write()
289 return -EINVAL; in pds_vfio_restore_write()
291 mutex_lock(&lm_file->lock); in pds_vfio_restore_write()
293 if (lm_file->disabled) { in pds_vfio_restore_write()
294 done = -ENODEV; in pds_vfio_restore_write()
306 page = pds_vfio_get_file_page(lm_file, *pos - page_offset); in pds_vfio_restore_write()
309 done = -EINVAL; in pds_vfio_restore_write()
313 page_len = min_t(size_t, len, PAGE_SIZE - page_offset); in pds_vfio_restore_write()
318 done = -EFAULT; in pds_vfio_restore_write()
322 len -= page_len; in pds_vfio_restore_write()
325 lm_file->size += page_len; in pds_vfio_restore_write()
328 mutex_unlock(&lm_file->lock); in pds_vfio_restore_write()
340 struct device *dev = &pds_vfio->vfio_coredev.pdev->dev; in pds_vfio_get_restore_file()
349 return -EIO; in pds_vfio_get_restore_file()
355 return -ENOENT; in pds_vfio_get_restore_file()
357 pds_vfio->restore_file = lm_file; in pds_vfio_get_restore_file()
366 enum vfio_device_mig_state cur = pds_vfio->state; in pds_vfio_step_device_state_locked()
380 return pds_vfio->save_file->filep; in pds_vfio_step_device_state_locked()
394 return pds_vfio->restore_file->filep; in pds_vfio_step_device_state_locked()
444 return ERR_PTR(-EINVAL); in pds_vfio_step_device_state_locked()