FreeBSD kernel amd64 OFW device code
ofw_pci.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2021 Alstom Group.
5 * Copyright (c) 2021 Semihalf.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD$");
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/bus.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/rman.h>
37
38#include <dev/pci/pcireg.h>
39#include <dev/pci/pcivar.h>
40#include <dev/pci/pci_private.h>
41
42#include <dev/ofw/openfirm.h>
43#include <dev/ofw/ofw_bus.h>
45
46#include "pcib_if.h"
47#include "pci_if.h"
48
49static int ofw_pci_probe(device_t);
50static const struct ofw_bus_devinfo* pci_ofw_get_devinfo(device_t, device_t);
51
52static device_method_t ofw_pci_methods[] = {
53 DEVMETHOD(device_probe, ofw_pci_probe),
54
55 /* ofw_bus interface */
56 DEVMETHOD(ofw_bus_get_devinfo, pci_ofw_get_devinfo),
62
63 DEVMETHOD_END
64};
65
66static devclass_t pci_devclass;
67
68DEFINE_CLASS_1(pci, ofw_pci_driver, ofw_pci_methods, sizeof(struct pci_softc),
69 pci_driver);
70DRIVER_MODULE(ofw_pci, pcib, ofw_pci_driver, pci_devclass, 0, 0);
71MODULE_DEPEND(ofw_pci, simplebus, 1, 1, 1);
72MODULE_DEPEND(ofw_pci, pci, 1, 1, 1);
73MODULE_VERSION(ofw_pci, 1);
74
75static int
77{
78 device_t parent;
79
80 parent = device_get_parent(dev);
81 if (ofw_bus_get_node(parent) == -1)
82 return (ENXIO);
83
84 device_set_desc(dev, "OFW PCI bus");
85 return (BUS_PROBE_DEFAULT);
86}
87
88/* Pass the request up to our parent. */
89static const struct ofw_bus_devinfo*
90pci_ofw_get_devinfo(device_t bus, device_t dev)
91{
92
93 return OFW_BUS_GET_DEVINFO(device_get_parent(bus), dev);
94}
METHOD phandle_t parent
Return parent of node.
Definition: ofw_if.m:66
static __inline phandle_t ofw_bus_get_node(device_t dev)
Definition: ofw_bus.h:62
static __inline const char * ofw_bus_get_compat(device_t dev)
Definition: ofw_bus.h:41
static __inline const char * ofw_bus_get_type(device_t dev)
Definition: ofw_bus.h:69
static __inline const char * ofw_bus_get_model(device_t dev)
Definition: ofw_bus.h:48
static __inline const char * ofw_bus_get_name(device_t dev)
Definition: ofw_bus.h:55
device_t dev
Definition: ofw_bus_if.m:124
ofw_bus_get_name_t ofw_bus_gen_get_name
Definition: ofw_bus_subr.h:81
ofw_bus_get_node_t ofw_bus_gen_get_node
Definition: ofw_bus_subr.h:82
ofw_bus_get_model_t ofw_bus_gen_get_model
Definition: ofw_bus_subr.h:80
ofw_bus_get_compat_t ofw_bus_gen_get_compat
Definition: ofw_bus_subr.h:79
ofw_bus_get_type_t ofw_bus_gen_get_type
Definition: ofw_bus_subr.h:83
static devclass_t pci_devclass
Definition: ofw_pci.c:66
DEFINE_CLASS_1(pci, ofw_pci_driver, ofw_pci_methods, sizeof(struct pci_softc), pci_driver)
static device_method_t ofw_pci_methods[]
Definition: ofw_pci.c:52
static const struct ofw_bus_devinfo * pci_ofw_get_devinfo(device_t, device_t)
Definition: ofw_pci.c:90
MODULE_DEPEND(ofw_pci, simplebus, 1, 1, 1)
__FBSDID("$FreeBSD$")
MODULE_VERSION(ofw_pci, 1)
static int ofw_pci_probe(device_t)
Definition: ofw_pci.c:76
DRIVER_MODULE(ofw_pci, pcib, ofw_pci_driver, pci_devclass, 0, 0)