1 /*
2 * Copyright (c) 2008, Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Copyright (C) Allen Kay <allen.m.kay@intel.com>
17 * Copyright (C) Weidong Han <weidong.han@intel.com>
18 */
19
20 #include <xen/iommu.h>
21 #include <xen/irq.h>
22 #include <xen/sched.h>
23
_hvm_dpci_isairq_eoi(struct domain * d,struct hvm_pirq_dpci * pirq_dpci,void * arg)24 static int _hvm_dpci_isairq_eoi(struct domain *d,
25 struct hvm_pirq_dpci *pirq_dpci, void *arg)
26 {
27 struct hvm_irq *hvm_irq = hvm_domain_irq(d);
28 unsigned int isairq = (long)arg;
29 const struct dev_intx_gsi_link *digl;
30
31 list_for_each_entry ( digl, &pirq_dpci->digl_list, list )
32 {
33 unsigned int link = hvm_pci_intx_link(digl->device, digl->intx);
34
35 if ( hvm_irq->pci_link.route[link] == isairq )
36 {
37 hvm_pci_intx_deassert(d, digl->device, digl->intx);
38 if ( --pirq_dpci->pending == 0 )
39 {
40 stop_timer(&pirq_dpci->timer);
41 pirq_guest_eoi(dpci_pirq(pirq_dpci));
42 }
43 }
44 }
45
46 return 0;
47 }
48
hvm_dpci_isairq_eoi(struct domain * d,unsigned int isairq)49 void hvm_dpci_isairq_eoi(struct domain *d, unsigned int isairq)
50 {
51 struct hvm_irq_dpci *dpci = NULL;
52
53 ASSERT(isairq < NR_ISAIRQS);
54 if ( !is_iommu_enabled(d) )
55 return;
56
57 spin_lock(&d->event_lock);
58
59 dpci = domain_get_irq_dpci(d);
60
61 if ( dpci && test_bit(isairq, dpci->isairq_map) )
62 {
63 /* Multiple mirq may be mapped to one isa irq */
64 pt_pirq_iterate(d, _hvm_dpci_isairq_eoi, (void *)(long)isairq);
65 }
66 spin_unlock(&d->event_lock);
67 }
68