xen_msi.c revision 340016
1/*
2 * Copyright (c) 2014 Roger Pau Monn�� <roger.pau@citrix.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: stable/11/sys/x86/xen/xen_msi.c 340016 2018-11-01 18:34:26Z jhb $");
29
30#include <sys/param.h>
31#include <sys/bus.h>
32#include <sys/kernel.h>
33#include <sys/lock.h>
34#include <sys/malloc.h>
35#include <sys/mutex.h>
36#include <sys/sx.h>
37#include <sys/systm.h>
38#include <x86/apicreg.h>
39#include <machine/cputypes.h>
40#include <machine/md_var.h>
41#include <machine/frame.h>
42#include <machine/intr_machdep.h>
43#include <x86/apicvar.h>
44#include <machine/specialreg.h>
45#include <dev/pci/pcivar.h>
46
47#include <xen/xen-os.h>
48#include <xen/xen_intr.h>
49#include <xen/xen_msi.h>
50
51static struct mtx msi_lock;
52static u_int msi_last_irq;
53
54void
55xen_msi_init(void)
56{
57
58	MPASS(num_io_irqs > 0);
59	first_msi_irq = min(MINIMUM_MSI_INT, num_io_irqs);
60	num_io_irqs = first_msi_irq + NUM_MSI_INTS;
61
62	mtx_init(&msi_lock, "msi", NULL, MTX_DEF);
63}
64
65/*
66 * Try to allocate 'count' interrupt sources with contiguous IDT values.
67 */
68int
69xen_msi_alloc(device_t dev, int count, int maxcount, int *irqs)
70{
71	int i, ret = 0;
72
73	mtx_lock(&msi_lock);
74
75	/* If we would exceed the max, give up. */
76	if ((msi_last_irq + count) > NUM_MSI_INTS) {
77		mtx_unlock(&msi_lock);
78		return (ENXIO);
79	}
80
81	/* Allocate MSI vectors */
82	for (i = 0; i < count; i++)
83		irqs[i] = first_msi_irq + msi_last_irq++;
84
85	mtx_unlock(&msi_lock);
86
87	ret = xen_register_msi(dev, irqs[0], count);
88	if (ret != 0)
89		return (ret);
90
91	for (i = 0; i < count; i++)
92		nexus_add_irq(irqs[i]);
93
94	return (0);
95}
96
97int
98xen_msi_release(int *irqs, int count)
99{
100	int i, ret;
101
102	for (i = 0; i < count; i++) {
103		ret = xen_release_msi(irqs[i]);
104		if (ret != 0)
105			return (ret);
106	}
107
108	return (0);
109}
110
111int
112xen_msi_map(int irq, uint64_t *addr, uint32_t *data)
113{
114
115	return (0);
116}
117
118int
119xen_msix_alloc(device_t dev, int *irq)
120{
121
122	return (ENXIO);
123}
124
125int
126xen_msix_release(int irq)
127{
128
129	return (ENOENT);
130}
131