Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/dev/acpica/acpi_container.c
39534 views
1
/*-
2
* Copyright (c) 2017 Microsoft Corp.
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 unmodified, this list of conditions, and the following
10
* disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
*/
26
27
#include <sys/param.h>
28
#include <sys/kernel.h>
29
#include <sys/bus.h>
30
#include <sys/module.h>
31
32
#include <contrib/dev/acpica/include/acpi.h>
33
#include <dev/acpica/acpivar.h>
34
35
#include "pcib_if.h"
36
37
ACPI_MODULE_NAME("CONTAINER")
38
39
static int acpi_syscont_probe(device_t);
40
static int acpi_syscont_attach(device_t);
41
static int acpi_syscont_alloc_msi(device_t, device_t,
42
int count, int maxcount, int *irqs);
43
static int acpi_syscont_release_msi(device_t bus, device_t dev,
44
int count, int *irqs);
45
static int acpi_syscont_alloc_msix(device_t bus, device_t dev,
46
int *irq);
47
static int acpi_syscont_release_msix(device_t bus, device_t dev,
48
int irq);
49
static int acpi_syscont_map_msi(device_t bus, device_t dev,
50
int irq, uint64_t *addr, uint32_t *data);
51
52
static device_method_t acpi_syscont_methods[] = {
53
/* Device interface */
54
DEVMETHOD(device_probe, acpi_syscont_probe),
55
DEVMETHOD(device_attach, acpi_syscont_attach),
56
DEVMETHOD(device_detach, bus_generic_detach),
57
58
/* Bus interface */
59
DEVMETHOD(bus_add_child, bus_generic_add_child),
60
DEVMETHOD(bus_print_child, bus_generic_print_child),
61
DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
62
DEVMETHOD(bus_release_resource, bus_generic_release_resource),
63
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
64
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
65
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
66
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
67
DEVMETHOD(bus_get_cpus, bus_generic_get_cpus),
68
69
/* pcib interface */
70
DEVMETHOD(pcib_alloc_msi, acpi_syscont_alloc_msi),
71
DEVMETHOD(pcib_release_msi, acpi_syscont_release_msi),
72
DEVMETHOD(pcib_alloc_msix, acpi_syscont_alloc_msix),
73
DEVMETHOD(pcib_release_msix, acpi_syscont_release_msix),
74
DEVMETHOD(pcib_map_msi, acpi_syscont_map_msi),
75
76
DEVMETHOD_END
77
};
78
79
static driver_t acpi_syscont_driver = {
80
"acpi_syscontainer",
81
acpi_syscont_methods,
82
0,
83
};
84
85
DRIVER_MODULE(acpi_syscontainer, acpi, acpi_syscont_driver, NULL, NULL);
86
MODULE_DEPEND(acpi_syscontainer, acpi, 1, 1, 1);
87
88
static int
89
acpi_syscont_probe(device_t dev)
90
{
91
static char *syscont_ids[] = { "ACPI0004", "PNP0A05", "PNP0A06", NULL };
92
int rv;
93
94
if (acpi_disabled("syscontainer"))
95
return (ENXIO);
96
rv = ACPI_ID_PROBE(device_get_parent(dev), dev, syscont_ids, NULL);
97
if (rv <= 0)
98
device_set_desc(dev, "System Container");
99
return (rv);
100
}
101
102
static int
103
acpi_syscont_attach(device_t dev)
104
{
105
106
bus_identify_children(dev);
107
bus_attach_children(dev);
108
return (0);
109
}
110
111
static int
112
acpi_syscont_alloc_msi(device_t bus, device_t dev, int count, int maxcount,
113
int *irqs)
114
{
115
device_t parent = device_get_parent(bus);
116
117
return (PCIB_ALLOC_MSI(device_get_parent(parent), dev, count, maxcount,
118
irqs));
119
}
120
121
static int
122
acpi_syscont_release_msi(device_t bus, device_t dev, int count, int *irqs)
123
{
124
device_t parent = device_get_parent(bus);
125
126
return (PCIB_RELEASE_MSI(device_get_parent(parent), dev, count, irqs));
127
}
128
129
static int
130
acpi_syscont_alloc_msix(device_t bus, device_t dev, int *irq)
131
{
132
device_t parent = device_get_parent(bus);
133
134
return (PCIB_ALLOC_MSIX(device_get_parent(parent), dev, irq));
135
}
136
137
static int
138
acpi_syscont_release_msix(device_t bus, device_t dev, int irq)
139
{
140
device_t parent = device_get_parent(bus);
141
142
return (PCIB_RELEASE_MSIX(device_get_parent(parent), dev, irq));
143
}
144
145
static int
146
acpi_syscont_map_msi(device_t bus, device_t dev, int irq, uint64_t *addr,
147
uint32_t *data)
148
{
149
device_t parent = device_get_parent(bus);
150
151
return (PCIB_MAP_MSI(device_get_parent(parent), dev, irq, addr, data));
152
}
153
154