Lines Matching refs:iommu
35 #define guest_iommu_set_status(iommu, bit) \ argument
36 iommu_set_bit(&((iommu)->reg_status.lo), bit)
38 #define guest_iommu_clear_status(iommu, bit) \ argument
39 iommu_clear_bit(&((iommu)->reg_status.lo), bit)
69 static void guest_iommu_enable(struct guest_iommu *iommu) in guest_iommu_enable() argument
71 iommu->enabled = 1; in guest_iommu_enable()
74 static void guest_iommu_disable(struct guest_iommu *iommu) in guest_iommu_disable() argument
76 iommu->enabled = 0; in guest_iommu_disable()
130 struct guest_iommu *iommu = domain_iommu(d); in guest_iommu_deliver_msi() local
132 vector = iommu->msi.vector; in guest_iommu_deliver_msi()
133 dest = iommu->msi.dest; in guest_iommu_deliver_msi()
134 dest_mode = iommu->msi.dest_mode; in guest_iommu_deliver_msi()
135 delivery_mode = iommu->msi.delivery_mode; in guest_iommu_deliver_msi()
136 trig_mode = iommu->msi.trig_mode; in guest_iommu_deliver_msi()
158 static void guest_iommu_enable_dev_table(struct guest_iommu *iommu) in guest_iommu_enable_dev_table() argument
160 uint32_t length_raw = get_field_from_reg_u32(iommu->dev_table.reg_base.lo, in guest_iommu_enable_dev_table()
163 iommu->dev_table.size = (length_raw + 1) * PAGE_SIZE; in guest_iommu_enable_dev_table()
166 static void guest_iommu_enable_ring_buffer(struct guest_iommu *iommu, in guest_iommu_enable_ring_buffer() argument
181 struct guest_iommu *iommu; in guest_iommu_add_ppr_log() local
186 iommu = domain_iommu(d); in guest_iommu_add_ppr_log()
187 if ( !iommu ) in guest_iommu_add_ppr_log()
190 tail = iommu_get_rb_pointer(iommu->ppr_log.reg_tail.lo); in guest_iommu_add_ppr_log()
191 head = iommu_get_rb_pointer(iommu->ppr_log.reg_head.lo); in guest_iommu_add_ppr_log()
193 if ( tail >= iommu->ppr_log.entries || head >= iommu->ppr_log.entries ) in guest_iommu_add_ppr_log()
196 guest_iommu_disable(iommu); in guest_iommu_add_ppr_log()
200 mfn = guest_iommu_get_table_mfn(d, reg_to_u64(iommu->ppr_log.reg_base), in guest_iommu_add_ppr_log()
214 if ( ++tail >= iommu->ppr_log.entries ) in guest_iommu_add_ppr_log()
217 guest_iommu_set_status(iommu, IOMMU_STATUS_PPR_LOG_OVERFLOW_SHIFT); in guest_iommu_add_ppr_log()
219 iommu_set_rb_pointer(&iommu->ppr_log.reg_tail.lo, tail); in guest_iommu_add_ppr_log()
230 struct guest_iommu *iommu; in guest_iommu_add_event_log() local
235 iommu = domain_iommu(d); in guest_iommu_add_event_log()
236 if ( !iommu ) in guest_iommu_add_event_log()
239 tail = iommu_get_rb_pointer(iommu->event_log.reg_tail.lo); in guest_iommu_add_event_log()
240 head = iommu_get_rb_pointer(iommu->event_log.reg_head.lo); in guest_iommu_add_event_log()
242 if ( tail >= iommu->event_log.entries || head >= iommu->event_log.entries ) in guest_iommu_add_event_log()
245 guest_iommu_disable(iommu); in guest_iommu_add_event_log()
249 mfn = guest_iommu_get_table_mfn(d, reg_to_u64(iommu->event_log.reg_base), in guest_iommu_add_event_log()
262 if ( ++tail >= iommu->event_log.entries ) in guest_iommu_add_event_log()
265 guest_iommu_set_status(iommu, IOMMU_STATUS_EVENT_OVERFLOW_SHIFT); in guest_iommu_add_event_log()
268 iommu_set_rb_pointer(&iommu->event_log.reg_tail.lo, tail); in guest_iommu_add_event_log()
277 struct amd_iommu *iommu; in do_complete_ppr_request() local
280 iommu = find_iommu_for_device(0, dev_id); in do_complete_ppr_request()
282 if ( !iommu ) in do_complete_ppr_request()
291 amd_iommu_send_guest_cmd(iommu, cmd->data); in do_complete_ppr_request()
299 struct amd_iommu *iommu = NULL; in do_invalidate_pages() local
310 for_each_amd_iommu ( iommu ) in do_invalidate_pages()
311 amd_iommu_send_guest_cmd(iommu, cmd->data); in do_invalidate_pages()
318 struct amd_iommu *iommu = NULL; in do_invalidate_all() local
320 for_each_amd_iommu ( iommu ) in do_invalidate_all()
328 struct amd_iommu *iommu; in do_invalidate_iotlb_pages() local
333 iommu = find_iommu_for_device(0, dev_id); in do_invalidate_iotlb_pages()
334 if ( !iommu ) in do_invalidate_iotlb_pages()
342 amd_iommu_send_guest_cmd(iommu, cmd->data); in do_invalidate_iotlb_pages()
350 struct guest_iommu *iommu; in do_completion_wait() local
354 iommu = domain_iommu(d); in do_completion_wait()
360 guest_iommu_set_status(iommu, IOMMU_STATUS_COMP_WAIT_INT_SHIFT); in do_completion_wait()
386 com_wait_int_en = iommu_get_bit(iommu->reg_ctrl.lo, in do_completion_wait()
388 com_wait_int = iommu_get_bit(iommu->reg_status.lo, in do_completion_wait()
401 struct amd_iommu *iommu = NULL; in do_invalidate_dte() local
446 iommu = find_iommu_for_device(0, mbdf); in do_invalidate_dte()
447 if ( !iommu ) in do_invalidate_dte()
456 req_id = get_dma_requestor_id(iommu->seg, mbdf); in do_invalidate_dte()
457 mdte = iommu->dev_table.buffer + (req_id * sizeof(dev_entry_t)); in do_invalidate_dte()
459 spin_lock_irqsave(&iommu->lock, flags); in do_invalidate_dte()
463 amd_iommu_flush_device(iommu, req_id); in do_invalidate_dte()
464 spin_unlock_irqrestore(&iommu->lock, flags); in do_invalidate_dte()
474 struct guest_iommu *iommu; in guest_iommu_process_command() local
476 iommu = domain_iommu(d); in guest_iommu_process_command()
478 if ( !iommu->enabled ) in guest_iommu_process_command()
481 head = iommu_get_rb_pointer(iommu->cmd_buffer.reg_head.lo); in guest_iommu_process_command()
482 tail = iommu_get_rb_pointer(iommu->cmd_buffer.reg_tail.lo); in guest_iommu_process_command()
488 if ( tail >= iommu->cmd_buffer.entries || in guest_iommu_process_command()
489 head >= iommu->cmd_buffer.entries ) in guest_iommu_process_command()
492 guest_iommu_disable(iommu); in guest_iommu_process_command()
503 reg_to_u64(iommu->cmd_buffer.reg_base), in guest_iommu_process_command()
542 if ( ++head >= iommu->cmd_buffer.entries ) in guest_iommu_process_command()
545 guest_iommu_disable(iommu); in guest_iommu_process_command()
549 iommu_set_rb_pointer(&iommu->cmd_buffer.reg_head.lo, head); in guest_iommu_process_command()
553 static int guest_iommu_write_ctrl(struct guest_iommu *iommu, uint64_t newctrl) in guest_iommu_write_ctrl() argument
561 iommu_en_old = iommu_get_bit(iommu->reg_ctrl.lo, in guest_iommu_write_ctrl()
566 cmd_en_old = iommu_get_bit(iommu->reg_ctrl.lo, in guest_iommu_write_ctrl()
568 cmd_run = iommu_get_bit(iommu->reg_status.lo, in guest_iommu_write_ctrl()
572 event_en_old = iommu_get_bit(iommu->reg_ctrl.lo, in guest_iommu_write_ctrl()
582 guest_iommu_enable(iommu); in guest_iommu_write_ctrl()
583 guest_iommu_enable_dev_table(iommu); in guest_iommu_write_ctrl()
588 guest_iommu_enable_ring_buffer(iommu, &iommu->cmd_buffer, in guest_iommu_write_ctrl()
591 tasklet_schedule(&iommu->cmd_buffer_tasklet); in guest_iommu_write_ctrl()
596 guest_iommu_enable_ring_buffer(iommu, &iommu->event_log, in guest_iommu_write_ctrl()
598 guest_iommu_set_status(iommu, IOMMU_STATUS_EVENT_LOG_RUN_SHIFT); in guest_iommu_write_ctrl()
599 guest_iommu_clear_status(iommu, IOMMU_STATUS_EVENT_OVERFLOW_SHIFT); in guest_iommu_write_ctrl()
604 guest_iommu_enable_ring_buffer(iommu, &iommu->ppr_log, in guest_iommu_write_ctrl()
606 guest_iommu_set_status(iommu, IOMMU_STATUS_PPR_LOG_RUN_SHIFT); in guest_iommu_write_ctrl()
607 guest_iommu_clear_status(iommu, IOMMU_STATUS_PPR_LOG_OVERFLOW_SHIFT); in guest_iommu_write_ctrl()
613 tasklet_kill(&iommu->cmd_buffer_tasklet); in guest_iommu_write_ctrl()
617 guest_iommu_clear_status(iommu, IOMMU_STATUS_EVENT_LOG_RUN_SHIFT); in guest_iommu_write_ctrl()
620 guest_iommu_disable(iommu); in guest_iommu_write_ctrl()
622 u64_to_reg(&iommu->reg_ctrl, newctrl); in guest_iommu_write_ctrl()
626 static uint64_t iommu_mmio_read64(struct guest_iommu *iommu, in iommu_mmio_read64() argument
634 val = reg_to_u64(iommu->dev_table.reg_base); in iommu_mmio_read64()
637 val = reg_to_u64(iommu->cmd_buffer.reg_base); in iommu_mmio_read64()
640 val = reg_to_u64(iommu->event_log.reg_base); in iommu_mmio_read64()
643 val = reg_to_u64(iommu->ppr_log.reg_base); in iommu_mmio_read64()
646 val = reg_to_u64(iommu->cmd_buffer.reg_head); in iommu_mmio_read64()
649 val = reg_to_u64(iommu->cmd_buffer.reg_tail); in iommu_mmio_read64()
652 val = reg_to_u64(iommu->event_log.reg_head); in iommu_mmio_read64()
655 val = reg_to_u64(iommu->event_log.reg_tail); in iommu_mmio_read64()
658 val = reg_to_u64(iommu->ppr_log.reg_head); in iommu_mmio_read64()
661 val = reg_to_u64(iommu->ppr_log.reg_tail); in iommu_mmio_read64()
664 val = reg_to_u64(iommu->reg_ctrl); in iommu_mmio_read64()
667 val = reg_to_u64(iommu->reg_status); in iommu_mmio_read64()
670 val = reg_to_u64(iommu->reg_ext_feature); in iommu_mmio_read64()
685 struct guest_iommu *iommu = vcpu_iommu(v); in guest_iommu_mmio_read() local
691 offset = addr - iommu->mmio_base; in guest_iommu_mmio_read()
706 spin_lock(&iommu->lock); in guest_iommu_mmio_read()
707 val = iommu_mmio_read64(iommu, mmio); in guest_iommu_mmio_read()
708 spin_unlock(&iommu->lock); in guest_iommu_mmio_read()
715 static void guest_iommu_mmio_write64(struct guest_iommu *iommu, in guest_iommu_mmio_write64() argument
721 u64_to_reg(&iommu->dev_table.reg_base, val); in guest_iommu_mmio_write64()
724 u64_to_reg(&iommu->cmd_buffer.reg_base, val); in guest_iommu_mmio_write64()
727 u64_to_reg(&iommu->event_log.reg_base, val); in guest_iommu_mmio_write64()
730 u64_to_reg(&iommu->ppr_log.reg_base, val); in guest_iommu_mmio_write64()
733 guest_iommu_write_ctrl(iommu, val); in guest_iommu_mmio_write64()
736 u64_to_reg(&iommu->cmd_buffer.reg_head, val); in guest_iommu_mmio_write64()
739 u64_to_reg(&iommu->cmd_buffer.reg_tail, val); in guest_iommu_mmio_write64()
740 tasklet_schedule(&iommu->cmd_buffer_tasklet); in guest_iommu_mmio_write64()
743 u64_to_reg(&iommu->event_log.reg_head, val); in guest_iommu_mmio_write64()
746 u64_to_reg(&iommu->event_log.reg_tail, val); in guest_iommu_mmio_write64()
749 u64_to_reg(&iommu->ppr_log.reg_head, val); in guest_iommu_mmio_write64()
752 u64_to_reg(&iommu->ppr_log.reg_tail, val); in guest_iommu_mmio_write64()
762 u64_to_reg(&iommu->reg_status, reg_to_u64(iommu->reg_status) & ~val); in guest_iommu_mmio_write64()
775 struct guest_iommu *iommu = vcpu_iommu(v); in guest_iommu_mmio_write() local
781 offset = addr - iommu->mmio_base; in guest_iommu_mmio_write()
796 spin_lock(&iommu->lock); in guest_iommu_mmio_write()
798 reg_old = iommu_mmio_read64(iommu, mmio); in guest_iommu_mmio_write()
801 guest_iommu_mmio_write64(iommu, mmio, val); in guest_iommu_mmio_write()
803 spin_unlock(&iommu->lock); in guest_iommu_mmio_write()
811 struct guest_iommu *iommu = domain_iommu(d); in guest_iommu_set_base() local
813 if ( !iommu ) in guest_iommu_set_base()
816 iommu->mmio_base = base; in guest_iommu_set_base()
832 static void guest_iommu_reg_init(struct guest_iommu *iommu) in guest_iommu_reg_init() argument
865 iommu->reg_ext_feature.lo = lower; in guest_iommu_reg_init()
866 iommu->reg_ext_feature.hi = upper; in guest_iommu_reg_init()
871 struct guest_iommu *iommu = vcpu_iommu(v); in guest_iommu_mmio_range() local
873 return iommu && addr >= iommu->mmio_base && in guest_iommu_mmio_range()
874 addr < iommu->mmio_base + IOMMU_MMIO_SIZE; in guest_iommu_mmio_range()
886 struct guest_iommu *iommu; in guest_iommu_init() local
893 iommu = xzalloc(struct guest_iommu); in guest_iommu_init()
894 if ( !iommu ) in guest_iommu_init()
900 guest_iommu_reg_init(iommu); in guest_iommu_init()
901 iommu->mmio_base = ~0ULL; in guest_iommu_init()
902 iommu->domain = d; in guest_iommu_init()
903 hd->arch.g_iommu = iommu; in guest_iommu_init()
905 tasklet_init(&iommu->cmd_buffer_tasklet, in guest_iommu_init()
908 spin_lock_init(&iommu->lock); in guest_iommu_init()
917 struct guest_iommu *iommu; in guest_iommu_destroy() local
919 iommu = domain_iommu(d); in guest_iommu_destroy()
920 if ( !iommu ) in guest_iommu_destroy()
923 tasklet_kill(&iommu->cmd_buffer_tasklet); in guest_iommu_destroy()
924 xfree(iommu); in guest_iommu_destroy()