Lines Matching defs:vdpasim

49 	struct vdpasim *vdpasim;
58 struct vdpasim *vdpasim = mm_work->vdpasim;
63 vdpasim->mm_bound = mm_work->mm_to_bind;
66 static void vdpasim_worker_change_mm_sync(struct vdpasim *vdpasim,
72 kthread_queue_work(vdpasim->worker, work);
77 static struct vdpasim *vdpa_to_sim(struct vdpa_device *vdpa)
79 return container_of(vdpa, struct vdpasim, vdpa);
93 static void vdpasim_queue_ready(struct vdpasim *vdpasim, unsigned int idx)
95 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
104 if (use_va && vdpasim->mm_bound) {
105 vringh_init_iotlb_va(&vq->vring, vdpasim->features, vq->num,
108 vringh_init_iotlb(&vq->vring, vdpasim->features, vq->num,
127 static void vdpasim_vq_reset(struct vdpasim *vdpasim,
136 vringh_init_iotlb(&vq->vring, vdpasim->dev_attr.supported_features,
142 static void vdpasim_do_reset(struct vdpasim *vdpasim)
146 spin_lock(&vdpasim->iommu_lock);
148 for (i = 0; i < vdpasim->dev_attr.nvqs; i++) {
149 vdpasim_vq_reset(vdpasim, &vdpasim->vqs[i]);
150 vringh_set_iotlb(&vdpasim->vqs[i].vring, &vdpasim->iommu[0],
151 &vdpasim->iommu_lock);
154 for (i = 0; i < vdpasim->dev_attr.nas; i++) {
155 vhost_iotlb_reset(&vdpasim->iommu[i]);
156 vhost_iotlb_add_range(&vdpasim->iommu[i], 0, ULONG_MAX,
158 vdpasim->iommu_pt[i] = true;
161 vdpasim->running = false;
162 spin_unlock(&vdpasim->iommu_lock);
164 vdpasim->features = 0;
165 vdpasim->status = 0;
166 ++vdpasim->generation;
174 struct vdpasim *vdpasim = container_of(work, struct vdpasim, work);
175 struct mm_struct *mm = vdpasim->mm_bound;
183 vdpasim->dev_attr.work_fn(vdpasim);
191 struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
196 struct vdpasim *vdpasim;
225 vdpasim = vdpa_to_sim(vdpa);
226 vdpasim->dev_attr = *dev_attr;
227 dev = &vdpasim->vdpa.dev;
229 kthread_init_work(&vdpasim->work, vdpasim_work_fn);
230 vdpasim->worker = kthread_create_worker(0, "vDPA sim worker: %s",
232 if (IS_ERR(vdpasim->worker))
235 mutex_init(&vdpasim->mutex);
236 spin_lock_init(&vdpasim->iommu_lock);
241 vdpasim->vdpa.mdev = dev_attr->mgmt_dev;
243 vdpasim->config = kzalloc(dev_attr->config_size, GFP_KERNEL);
244 if (!vdpasim->config)
247 vdpasim->vqs = kcalloc(dev_attr->nvqs, sizeof(struct vdpasim_virtqueue),
249 if (!vdpasim->vqs)
252 vdpasim->iommu = kmalloc_array(vdpasim->dev_attr.nas,
253 sizeof(*vdpasim->iommu), GFP_KERNEL);
254 if (!vdpasim->iommu)
257 vdpasim->iommu_pt = kmalloc_array(vdpasim->dev_attr.nas,
258 sizeof(*vdpasim->iommu_pt), GFP_KERNEL);
259 if (!vdpasim->iommu_pt)
262 for (i = 0; i < vdpasim->dev_attr.nas; i++)
263 vhost_iotlb_init(&vdpasim->iommu[i], max_iotlb_entries, 0);
266 vringh_set_iotlb(&vdpasim->vqs[i].vring, &vdpasim->iommu[0],
267 &vdpasim->iommu_lock);
269 vdpasim->vdpa.dma_dev = dev;
271 return vdpasim;
280 void vdpasim_schedule_work(struct vdpasim *vdpasim)
282 kthread_queue_work(vdpasim->worker, &vdpasim->work);
290 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
291 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
302 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
303 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
310 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
311 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
313 if (!vdpasim->running &&
314 (vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK)) {
315 vdpasim->pending_kick = true;
320 vdpasim_schedule_work(vdpasim);
326 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
327 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
335 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
336 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
339 mutex_lock(&vdpasim->mutex);
343 vdpasim_queue_ready(vdpasim, idx);
345 mutex_unlock(&vdpasim->mutex);
350 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
351 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
359 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
360 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
363 mutex_lock(&vdpasim->mutex);
365 mutex_unlock(&vdpasim->mutex);
373 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
374 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
385 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
387 if (vdpasim->dev_attr.get_stats)
388 return vdpasim->dev_attr.get_stats(vdpasim, idx,
409 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
411 return vdpasim->dev_attr.supported_features;
421 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
427 vdpasim->features = features & vdpasim->dev_attr.supported_features;
434 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
436 return vdpasim->features;
452 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
454 return vdpasim->dev_attr.id;
464 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
467 mutex_lock(&vdpasim->mutex);
468 status = vdpasim->status;
469 mutex_unlock(&vdpasim->mutex);
476 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
478 mutex_lock(&vdpasim->mutex);
479 vdpasim->status = status;
480 vdpasim->running = (status & VIRTIO_CONFIG_S_DRIVER_OK) != 0;
481 mutex_unlock(&vdpasim->mutex);
486 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
488 mutex_lock(&vdpasim->mutex);
489 vdpasim->status = 0;
490 vdpasim_do_reset(vdpasim);
491 mutex_unlock(&vdpasim->mutex);
498 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
500 mutex_lock(&vdpasim->mutex);
501 vdpasim->running = false;
502 mutex_unlock(&vdpasim->mutex);
509 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
512 mutex_lock(&vdpasim->mutex);
513 vdpasim->running = true;
515 if (vdpasim->pending_kick) {
517 for (i = 0; i < vdpasim->dev_attr.nvqs; ++i)
520 vdpasim->pending_kick = false;
523 mutex_unlock(&vdpasim->mutex);
530 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
532 return vdpasim->dev_attr.config_size;
538 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
540 if (offset + len > vdpasim->dev_attr.config_size)
543 if (vdpasim->dev_attr.get_config)
544 vdpasim->dev_attr.get_config(vdpasim, vdpasim->config);
546 memcpy(buf, vdpasim->config + offset, len);
552 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
554 if (offset + len > vdpasim->dev_attr.config_size)
557 memcpy(vdpasim->config + offset, buf, len);
559 if (vdpasim->dev_attr.set_config)
560 vdpasim->dev_attr.set_config(vdpasim, vdpasim->config);
565 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
567 return vdpasim->generation;
583 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
587 if (group > vdpasim->dev_attr.ngroups)
590 if (asid >= vdpasim->dev_attr.nas)
593 iommu = &vdpasim->iommu[asid];
595 mutex_lock(&vdpasim->mutex);
597 for (i = 0; i < vdpasim->dev_attr.nvqs; i++)
599 vringh_set_iotlb(&vdpasim->vqs[i].vring, iommu,
600 &vdpasim->iommu_lock);
602 mutex_unlock(&vdpasim->mutex);
610 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
616 if (asid >= vdpasim->dev_attr.nas)
619 spin_lock(&vdpasim->iommu_lock);
621 iommu = &vdpasim->iommu[asid];
623 vdpasim->iommu_pt[asid] = false;
632 spin_unlock(&vdpasim->iommu_lock);
637 spin_unlock(&vdpasim->iommu_lock);
643 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
646 mm_work.vdpasim = vdpasim;
649 vdpasim_worker_change_mm_sync(vdpasim, &mm_work);
656 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
659 mm_work.vdpasim = vdpasim;
662 vdpasim_worker_change_mm_sync(vdpasim, &mm_work);
669 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
672 if (asid >= vdpasim->dev_attr.nas)
675 spin_lock(&vdpasim->iommu_lock);
676 if (vdpasim->iommu_pt[asid]) {
677 vhost_iotlb_reset(&vdpasim->iommu[asid]);
678 vdpasim->iommu_pt[asid] = false;
680 ret = vhost_iotlb_add_range_ctx(&vdpasim->iommu[asid], iova,
682 spin_unlock(&vdpasim->iommu_lock);
690 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
692 if (asid >= vdpasim->dev_attr.nas)
695 if (vdpasim->iommu_pt[asid]) {
696 vhost_iotlb_reset(&vdpasim->iommu[asid]);
697 vdpasim->iommu_pt[asid] = false;
700 spin_lock(&vdpasim->iommu_lock);
701 vhost_iotlb_del_range(&vdpasim->iommu[asid], iova, iova + size - 1);
702 spin_unlock(&vdpasim->iommu_lock);
709 struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
712 kthread_cancel_work_sync(&vdpasim->work);
713 kthread_destroy_worker(vdpasim->worker);
715 for (i = 0; i < vdpasim->dev_attr.nvqs; i++) {
716 vringh_kiov_cleanup(&vdpasim->vqs[i].out_iov);
717 vringh_kiov_cleanup(&vdpasim->vqs[i].in_iov);
720 vdpasim->dev_attr.free(vdpasim);
722 for (i = 0; i < vdpasim->dev_attr.nas; i++)
723 vhost_iotlb_reset(&vdpasim->iommu[i]);
724 kfree(vdpasim->iommu);
725 kfree(vdpasim->iommu_pt);
726 kfree(vdpasim->vqs);
727 kfree(vdpasim->config);