xref: /freebsd/sys/dev/ofw/ofw_pci.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
128c4e511SMarcin Wojtas /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
328c4e511SMarcin Wojtas  *
428c4e511SMarcin Wojtas  * Copyright (c) 2021 Alstom Group.
528c4e511SMarcin Wojtas  * Copyright (c) 2021 Semihalf.
628c4e511SMarcin Wojtas  *
728c4e511SMarcin Wojtas  * Redistribution and use in source and binary forms, with or without
828c4e511SMarcin Wojtas  * modification, are permitted provided that the following conditions
928c4e511SMarcin Wojtas  * are met:
1028c4e511SMarcin Wojtas  * 1. Redistributions of source code must retain the above copyright
1128c4e511SMarcin Wojtas  *    notice, this list of conditions and the following disclaimer.
1228c4e511SMarcin Wojtas  * 2. Redistributions in binary form must reproduce the above copyright
1328c4e511SMarcin Wojtas  *    notice, this list of conditions and the following disclaimer in the
1428c4e511SMarcin Wojtas  *    documentation and/or other materials provided with the distribution.
1528c4e511SMarcin Wojtas  *
1628c4e511SMarcin Wojtas  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1728c4e511SMarcin Wojtas  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1828c4e511SMarcin Wojtas  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1928c4e511SMarcin Wojtas  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2028c4e511SMarcin Wojtas  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2128c4e511SMarcin Wojtas  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2228c4e511SMarcin Wojtas  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2328c4e511SMarcin Wojtas  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2428c4e511SMarcin Wojtas  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2528c4e511SMarcin Wojtas  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2628c4e511SMarcin Wojtas  */
2728c4e511SMarcin Wojtas 
2828c4e511SMarcin Wojtas #include <sys/param.h>
2928c4e511SMarcin Wojtas #include <sys/systm.h>
3028c4e511SMarcin Wojtas #include <sys/bus.h>
3128c4e511SMarcin Wojtas #include <sys/kernel.h>
3228c4e511SMarcin Wojtas #include <sys/module.h>
334e3a4390SJessica Clarke #include <sys/rman.h>
3428c4e511SMarcin Wojtas 
3528c4e511SMarcin Wojtas #include <dev/pci/pcireg.h>
3628c4e511SMarcin Wojtas #include <dev/pci/pcivar.h>
3728c4e511SMarcin Wojtas #include <dev/pci/pci_private.h>
3828c4e511SMarcin Wojtas 
3928c4e511SMarcin Wojtas #include <dev/ofw/openfirm.h>
4028c4e511SMarcin Wojtas #include <dev/ofw/ofw_bus.h>
4128c4e511SMarcin Wojtas #include <dev/ofw/ofw_bus_subr.h>
4228c4e511SMarcin Wojtas 
4328c4e511SMarcin Wojtas #include "pcib_if.h"
4428c4e511SMarcin Wojtas #include "pci_if.h"
4528c4e511SMarcin Wojtas 
4628c4e511SMarcin Wojtas static int	ofw_pci_probe(device_t);
4728c4e511SMarcin Wojtas static const struct ofw_bus_devinfo* pci_ofw_get_devinfo(device_t, device_t);
4828c4e511SMarcin Wojtas 
4928c4e511SMarcin Wojtas static device_method_t ofw_pci_methods[] = {
5028c4e511SMarcin Wojtas 	DEVMETHOD(device_probe,		ofw_pci_probe),
5128c4e511SMarcin Wojtas 
5228c4e511SMarcin Wojtas 	/* ofw_bus interface */
5328c4e511SMarcin Wojtas 	DEVMETHOD(ofw_bus_get_devinfo,	pci_ofw_get_devinfo),
5428c4e511SMarcin Wojtas 	DEVMETHOD(ofw_bus_get_compat,	ofw_bus_gen_get_compat),
5528c4e511SMarcin Wojtas 	DEVMETHOD(ofw_bus_get_model,	ofw_bus_gen_get_model),
5628c4e511SMarcin Wojtas 	DEVMETHOD(ofw_bus_get_name,	ofw_bus_gen_get_name),
5728c4e511SMarcin Wojtas 	DEVMETHOD(ofw_bus_get_node,	ofw_bus_gen_get_node),
5828c4e511SMarcin Wojtas 	DEVMETHOD(ofw_bus_get_type,	ofw_bus_gen_get_type),
5928c4e511SMarcin Wojtas 
6028c4e511SMarcin Wojtas 	DEVMETHOD_END
6128c4e511SMarcin Wojtas };
6228c4e511SMarcin Wojtas 
6328c4e511SMarcin Wojtas DEFINE_CLASS_1(pci, ofw_pci_driver, ofw_pci_methods, sizeof(struct pci_softc),
6428c4e511SMarcin Wojtas     pci_driver);
6503f6459cSJohn Baldwin DRIVER_MODULE(ofw_pci, pcib, ofw_pci_driver, 0, 0);
6628c4e511SMarcin Wojtas MODULE_DEPEND(ofw_pci, simplebus, 1, 1, 1);
6728c4e511SMarcin Wojtas MODULE_DEPEND(ofw_pci, pci, 1, 1, 1);
6828c4e511SMarcin Wojtas MODULE_VERSION(ofw_pci, 1);
6928c4e511SMarcin Wojtas 
7028c4e511SMarcin Wojtas static int
ofw_pci_probe(device_t dev)7128c4e511SMarcin Wojtas ofw_pci_probe(device_t dev)
7228c4e511SMarcin Wojtas {
7328c4e511SMarcin Wojtas 	device_t parent;
7428c4e511SMarcin Wojtas 
7528c4e511SMarcin Wojtas 	parent = device_get_parent(dev);
7694287656SKornel Duleba 	if (ofw_bus_get_node(parent) == -1)
7728c4e511SMarcin Wojtas 		return (ENXIO);
7828c4e511SMarcin Wojtas 
7928c4e511SMarcin Wojtas 	device_set_desc(dev, "OFW PCI bus");
8028c4e511SMarcin Wojtas 	return (BUS_PROBE_DEFAULT);
8128c4e511SMarcin Wojtas }
8228c4e511SMarcin Wojtas 
8328c4e511SMarcin Wojtas /* Pass the request up to our parent. */
8428c4e511SMarcin Wojtas static const struct ofw_bus_devinfo*
pci_ofw_get_devinfo(device_t bus,device_t dev)8528c4e511SMarcin Wojtas pci_ofw_get_devinfo(device_t bus, device_t dev)
8628c4e511SMarcin Wojtas {
8728c4e511SMarcin Wojtas 
8828c4e511SMarcin Wojtas 	return OFW_BUS_GET_DEVINFO(device_get_parent(bus), dev);
8928c4e511SMarcin Wojtas }
90