acpi_container.c revision 318393
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/cdefs.h>
28__FBSDID("$FreeBSD: stable/10/sys/dev/acpica/acpi_container.c 318393 2017-05-17 02:40:06Z sephe $");
29
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/bus.h>
33#include <sys/module.h>
34
35#include <contrib/dev/acpica/include/acpi.h>
36#include <dev/acpica/acpivar.h>
37
38#include "pcib_if.h"
39
40ACPI_MODULE_NAME("CONTAINER")
41
42static int			acpi_syscont_probe(device_t);
43static int			acpi_syscont_attach(device_t);
44static int			acpi_syscont_detach(device_t);
45static int			acpi_syscont_alloc_msi(device_t, device_t,
46				    int count, int maxcount, int *irqs);
47static int			acpi_syscont_release_msi(device_t bus, device_t dev,
48				    int count, int *irqs);
49static int			acpi_syscont_alloc_msix(device_t bus, device_t dev,
50				    int *irq);
51static int			acpi_syscont_release_msix(device_t bus, device_t dev,
52				    int irq);
53static int			acpi_syscont_map_msi(device_t bus, device_t dev,
54				    int irq, uint64_t *addr, uint32_t *data);
55
56static device_method_t acpi_syscont_methods[] = {
57    /* Device interface */
58    DEVMETHOD(device_probe,		acpi_syscont_probe),
59    DEVMETHOD(device_attach,		acpi_syscont_attach),
60    DEVMETHOD(device_detach,		acpi_syscont_detach),
61
62    /* Bus interface */
63    DEVMETHOD(bus_add_child,		bus_generic_add_child),
64    DEVMETHOD(bus_print_child,		bus_generic_print_child),
65    DEVMETHOD(bus_alloc_resource,	bus_generic_alloc_resource),
66    DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
67    DEVMETHOD(bus_activate_resource,	bus_generic_activate_resource),
68    DEVMETHOD(bus_deactivate_resource,	bus_generic_deactivate_resource),
69    DEVMETHOD(bus_setup_intr,		bus_generic_setup_intr),
70    DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
71#if __FreeBSD_version >= 1100000
72    DEVMETHOD(bus_get_cpus,		bus_generic_get_cpus),
73#endif
74
75    /* pcib interface */
76    DEVMETHOD(pcib_alloc_msi,		acpi_syscont_alloc_msi),
77    DEVMETHOD(pcib_release_msi,		acpi_syscont_release_msi),
78    DEVMETHOD(pcib_alloc_msix,		acpi_syscont_alloc_msix),
79    DEVMETHOD(pcib_release_msix,	acpi_syscont_release_msix),
80    DEVMETHOD(pcib_map_msi,		acpi_syscont_map_msi),
81
82    DEVMETHOD_END
83};
84
85static driver_t acpi_syscont_driver = {
86    "acpi_syscontainer",
87    acpi_syscont_methods,
88    0,
89};
90
91static devclass_t acpi_syscont_devclass;
92
93DRIVER_MODULE(acpi_syscontainer, acpi, acpi_syscont_driver,
94    acpi_syscont_devclass, NULL, NULL);
95MODULE_DEPEND(acpi_syscontainer, acpi, 1, 1, 1);
96
97static int
98acpi_syscont_probe(device_t dev)
99{
100    static char *syscont_ids[] = { "ACPI0004", "PNP0A05", "PNP0A06", NULL };
101
102    if (acpi_disabled("syscontainer") ||
103	ACPI_ID_PROBE(device_get_parent(dev), dev, syscont_ids) == NULL)
104	return (ENXIO);
105
106    device_set_desc(dev, "System Container");
107    return (BUS_PROBE_DEFAULT);
108}
109
110static int
111acpi_syscont_attach(device_t dev)
112{
113
114    bus_generic_probe(dev);
115    return (bus_generic_attach(dev));
116}
117
118static int
119acpi_syscont_detach(device_t dev)
120{
121
122    return (bus_generic_detach(dev));
123}
124
125static int
126acpi_syscont_alloc_msi(device_t bus, device_t dev, int count, int maxcount,
127    int *irqs)
128{
129    device_t parent = device_get_parent(bus);
130
131    return (PCIB_ALLOC_MSI(device_get_parent(parent), dev, count, maxcount,
132	irqs));
133}
134
135static int
136acpi_syscont_release_msi(device_t bus, device_t dev, int count, int *irqs)
137{
138    device_t parent = device_get_parent(bus);
139
140    return (PCIB_RELEASE_MSI(device_get_parent(parent), dev, count, irqs));
141}
142
143static int
144acpi_syscont_alloc_msix(device_t bus, device_t dev, int *irq)
145{
146    device_t parent = device_get_parent(bus);
147
148    return (PCIB_ALLOC_MSIX(device_get_parent(parent), dev, irq));
149}
150
151static int
152acpi_syscont_release_msix(device_t bus, device_t dev, int irq)
153{
154    device_t parent = device_get_parent(bus);
155
156    return (PCIB_RELEASE_MSIX(device_get_parent(parent), dev, irq));
157}
158
159static int
160acpi_syscont_map_msi(device_t bus, device_t dev, int irq, uint64_t *addr,
161    uint32_t *data)
162{
163    device_t parent = device_get_parent(bus);
164
165    return (PCIB_MAP_MSI(device_get_parent(parent), dev, irq, addr, data));
166}
167