blob: 3d4bedea4e785ba29c3aa89c2166cad514db38a6 [file] [log] [blame]
Marc Zyngier7de5c0a2016-12-20 15:27:52 +00001/*
2 * Copyright (C) 2016,2017 ARM Limited, All Rights Reserved.
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <linux/interrupt.h>
19#include <linux/irq.h>
20#include <linux/irqdomain.h>
21#include <linux/msi.h>
22#include <linux/sched.h>
23
24#include <linux/irqchip/arm-gic-v4.h>
25
26static struct irq_domain *gic_domain;
27static const struct irq_domain_ops *vpe_domain_ops;
28
29int its_alloc_vcpu_irqs(struct its_vm *vm)
30{
31 int vpe_base_irq, i;
32
33 vm->fwnode = irq_domain_alloc_named_id_fwnode("GICv4-vpe",
34 task_pid_nr(current));
35 if (!vm->fwnode)
36 goto err;
37
38 vm->domain = irq_domain_create_hierarchy(gic_domain, 0, vm->nr_vpes,
39 vm->fwnode, vpe_domain_ops,
40 vm);
41 if (!vm->domain)
42 goto err;
43
44 for (i = 0; i < vm->nr_vpes; i++) {
45 vm->vpes[i]->its_vm = vm;
46 vm->vpes[i]->idai = true;
47 }
48
49 vpe_base_irq = __irq_domain_alloc_irqs(vm->domain, -1, vm->nr_vpes,
50 NUMA_NO_NODE, vm,
51 false, NULL);
52 if (vpe_base_irq <= 0)
53 goto err;
54
55 for (i = 0; i < vm->nr_vpes; i++)
56 vm->vpes[i]->irq = vpe_base_irq + i;
57
58 return 0;
59
60err:
61 if (vm->domain)
62 irq_domain_remove(vm->domain);
63 if (vm->fwnode)
64 irq_domain_free_fwnode(vm->fwnode);
65
66 return -ENOMEM;
67}
68
69void its_free_vcpu_irqs(struct its_vm *vm)
70{
71 irq_domain_free_irqs(vm->vpes[0]->irq, vm->nr_vpes);
72 irq_domain_remove(vm->domain);
73 irq_domain_free_fwnode(vm->fwnode);
74}