2005-01-07 02:29:27 +00:00
|
|
|
/*-
|
2017-11-27 15:10:39 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-NetBSD AND BSD-3-Clause
|
|
|
|
*
|
2001-11-09 20:23:38 +00:00
|
|
|
* Copyright (c) 1999, 2000 Matthew R. Green
|
2009-12-22 21:49:53 +00:00
|
|
|
* Copyright (c) 2009 by Marius Strobl <marius@FreeBSD.org>
|
2001-11-09 20:23:38 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
2011-03-12 14:33:32 +00:00
|
|
|
* from: NetBSD: ebus.c,v 1.52 2008/05/29 14:51:26 mrg Exp
|
|
|
|
*/
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 Thomas Moestl <tmm@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
2001-11-09 20:23:38 +00:00
|
|
|
*/
|
|
|
|
|
2005-05-19 18:11:46 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-11-09 20:23:38 +00:00
|
|
|
/*
|
2009-12-22 21:49:53 +00:00
|
|
|
* Driver for JBus to EBus and PCI to EBus bridges
|
2001-11-09 20:23:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
2004-06-03 05:58:30 +00:00
|
|
|
#include <sys/module.h>
|
2004-04-28 13:06:46 +00:00
|
|
|
#include <sys/rman.h>
|
|
|
|
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
#include <dev/ofw/ofw_bus.h>
|
2005-11-22 16:39:44 +00:00
|
|
|
#include <dev/ofw/ofw_bus_subr.h>
|
2003-08-23 00:11:16 +00:00
|
|
|
#include <dev/ofw/openfirm.h>
|
2002-03-24 02:11:06 +00:00
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#ifndef SUN4V
|
|
|
|
#include <machine/bus_common.h>
|
|
|
|
#endif
|
|
|
|
#include <machine/intr_machdep.h>
|
2001-11-09 20:23:38 +00:00
|
|
|
#include <machine/resource.h>
|
|
|
|
|
2003-08-22 07:39:05 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2001-11-09 20:23:38 +00:00
|
|
|
|
|
|
|
#include <sparc64/pci/ofw_pci.h>
|
|
|
|
|
|
|
|
/*
|
2009-12-22 21:49:53 +00:00
|
|
|
* The register, interrupt map and for the PCI variant also the ranges
|
|
|
|
* properties are identical to the ISA ones.
|
2001-11-09 20:23:38 +00:00
|
|
|
*/
|
|
|
|
#include <sparc64/isa/ofw_isa.h>
|
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
struct ebus_nexus_ranges {
|
|
|
|
uint32_t child_hi;
|
|
|
|
uint32_t child_lo;
|
|
|
|
uint32_t phys_hi;
|
|
|
|
uint32_t phys_lo;
|
|
|
|
uint32_t size;
|
|
|
|
};
|
|
|
|
|
2001-11-09 20:23:38 +00:00
|
|
|
struct ebus_devinfo {
|
2005-11-22 16:39:44 +00:00
|
|
|
struct ofw_bus_devinfo edi_obdinfo;
|
2001-11-09 20:23:38 +00:00
|
|
|
struct resource_list edi_rl;
|
|
|
|
};
|
|
|
|
|
2004-04-28 13:06:46 +00:00
|
|
|
struct ebus_rinfo {
|
|
|
|
int eri_rtype;
|
|
|
|
struct rman eri_rman;
|
|
|
|
struct resource *eri_res;
|
|
|
|
};
|
|
|
|
|
2001-11-09 20:23:38 +00:00
|
|
|
struct ebus_softc {
|
2009-12-22 21:49:53 +00:00
|
|
|
void *sc_range;
|
2004-04-28 13:06:46 +00:00
|
|
|
struct ebus_rinfo *sc_rinfo;
|
2001-11-09 20:23:38 +00:00
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
u_int sc_flags;
|
|
|
|
#define EBUS_PCI (1 << 0)
|
|
|
|
|
2001-11-09 20:23:38 +00:00
|
|
|
int sc_nrange;
|
Add the new sparc64 OFW PCI framework, conditional on options OFW_NEWPCI
for now. It introduces a OFW PCI bus driver and a generic OFW PCI-PCI
bridge driver. By utilizing these, the PCI handling is much more elegant
now.
The advantages of the new approach are:
- Device enumeration should hopefully be more like on Solaris now,
so unit numbers should match what's printed on the box more
closely.
- Real interrupt routing is implemented now, so cardbus bridges
etc. have at least a chance to work.
- The quirk tables are gone and have been replaced by (hopefully
sufficient) heuristics.
- Much cleaner code.
There was also a report that previously bogus interrupt assignments
are fixed now, which can be attributed to the new heuristics.
A pitfall, and the reason why this is not the default yet, is that
it changes device enumeration, as mentioned above, which can make
it necessary to change the system configuration if more than one
unit of a device type is present (on a system with two hme cars,
for example, it is possible that hme0 becomes hme1 and vice versa
after enabling the option). Systems with multiple disk controllers
may need to be booted into single user (and require manual specification
of the root file system on boot) to adjust the fstab.
Nevertheless, I would like to encourage users to use this option,
so that it can be made the default soon.
In detail, the changes are:
- Introduce an OFW PCI bus driver; it inherits most methods from the
generic PCI bus driver, but uses the firmware for enumeration,
performs additional initialization for devices and firmware-specific
interrupt routing. It also implements an OFW-specific method to allow
child devices to get their firmware nodes.
- Introduce an OFW PCI-PCI bridge driver; again, it inherits most
of the generic PCI-PCI bridge driver; it has it's own method for
interrupt routing, as well as some sparc64-specific methods (one to
get the node again, and one to adjust the bridge bus range, since
we need to reenumerate all PCI buses).
- Convert the apb driver to the new way of handling things.
- Provide a common framework for OFW bridge drivers, used be the two
drivers above.
- Provide a small common framework for interrupt routing (for all
bridge types).
- Convert the psycho driver to the new framework; this gets rid of a
bunch of old kludges in pci_read_config(), and the whole
preinitialization (ofw_pci_init()).
- Convert the ISA MD part and the EBus driver to the new way
interrupts and nodes are handled.
- Introduce types for firmware interrupt properties.
- Rename the old sparcbus_if to ofw_pci_if by repo copy (it is only
required for PCI), and move it to a more correct location (new
support methodsx were also added, and an old one was deprecated).
- Fix a bunch of minor bugs, perform some cleanups.
In some cases, I introduced some minor code duplication to keep the
new code clean, in hopes that the old code will be unifdef'ed soon.
Reviewed in part by: imp
Tested by: jake, Marius Strobl <marius@alchemy.franken.de>,
Sergey Mokryshev <mokr@mokr.net>,
Chris Jackman <cjackNOSPAM@klatsch.org>
Info on u30 firmware provided by: kris
2003-07-01 14:52:47 +00:00
|
|
|
|
|
|
|
struct ofw_bus_iinfo sc_iinfo;
|
2009-12-22 21:49:53 +00:00
|
|
|
|
|
|
|
#ifndef SUN4V
|
|
|
|
uint32_t sc_ign;
|
|
|
|
#endif
|
2001-11-09 20:23:38 +00:00
|
|
|
};
|
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
static device_probe_t ebus_nexus_probe;
|
|
|
|
static device_attach_t ebus_nexus_attach;
|
|
|
|
static device_probe_t ebus_pci_probe;
|
|
|
|
static device_attach_t ebus_pci_attach;
|
2004-04-28 13:06:46 +00:00
|
|
|
static bus_print_child_t ebus_print_child;
|
|
|
|
static bus_probe_nomatch_t ebus_probe_nomatch;
|
|
|
|
static bus_alloc_resource_t ebus_alloc_resource;
|
2011-10-02 23:22:38 +00:00
|
|
|
static bus_activate_resource_t ebus_activate_resource;
|
|
|
|
static bus_adjust_resource_t ebus_adjust_resource;
|
2004-04-28 13:06:46 +00:00
|
|
|
static bus_release_resource_t ebus_release_resource;
|
2009-12-22 21:49:53 +00:00
|
|
|
static bus_setup_intr_t ebus_setup_intr;
|
2004-04-28 13:06:46 +00:00
|
|
|
static bus_get_resource_list_t ebus_get_resource_list;
|
2005-11-22 16:39:44 +00:00
|
|
|
static ofw_bus_get_devinfo_t ebus_get_devinfo;
|
2001-11-09 20:23:38 +00:00
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
static int ebus_attach(device_t dev, struct ebus_softc *sc, phandle_t node);
|
|
|
|
static struct ebus_devinfo *ebus_setup_dinfo(device_t dev,
|
|
|
|
struct ebus_softc *sc, phandle_t node);
|
|
|
|
static void ebus_destroy_dinfo(struct ebus_devinfo *edi);
|
|
|
|
static int ebus_print_res(struct ebus_devinfo *edi);
|
|
|
|
|
|
|
|
static devclass_t ebus_devclass;
|
2001-11-09 20:23:38 +00:00
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
static device_method_t ebus_nexus_methods[] = {
|
2001-11-09 20:23:38 +00:00
|
|
|
/* Device interface */
|
2009-12-22 21:49:53 +00:00
|
|
|
DEVMETHOD(device_probe, ebus_nexus_probe),
|
|
|
|
DEVMETHOD(device_attach, ebus_nexus_attach),
|
2006-01-26 21:14:32 +00:00
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
2001-11-09 20:23:38 +00:00
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, ebus_print_child),
|
|
|
|
DEVMETHOD(bus_probe_nomatch, ebus_probe_nomatch),
|
|
|
|
DEVMETHOD(bus_alloc_resource, ebus_alloc_resource),
|
2011-10-02 23:22:38 +00:00
|
|
|
DEVMETHOD(bus_activate_resource, ebus_activate_resource),
|
2001-11-09 20:23:38 +00:00
|
|
|
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
2011-10-02 23:22:38 +00:00
|
|
|
DEVMETHOD(bus_adjust_resource, ebus_adjust_resource),
|
2004-04-28 13:06:46 +00:00
|
|
|
DEVMETHOD(bus_release_resource, ebus_release_resource),
|
2009-12-22 21:49:53 +00:00
|
|
|
DEVMETHOD(bus_setup_intr, ebus_setup_intr),
|
2009-03-19 20:31:55 +00:00
|
|
|
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
2005-06-04 20:31:20 +00:00
|
|
|
DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
|
2009-03-19 20:31:55 +00:00
|
|
|
DEVMETHOD(bus_get_resource_list, ebus_get_resource_list),
|
2008-12-15 15:31:10 +00:00
|
|
|
DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
|
2001-11-09 20:23:38 +00:00
|
|
|
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
/* ofw_bus interface */
|
2005-11-22 16:39:44 +00:00
|
|
|
DEVMETHOD(ofw_bus_get_devinfo, ebus_get_devinfo),
|
|
|
|
DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat),
|
|
|
|
DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model),
|
|
|
|
DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name),
|
|
|
|
DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),
|
|
|
|
DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
|
- Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
properties in drivers for devices on Open Firmware supported busses. The
standard properties "reg", "interrupts" und "address" are not covered by
this interface because they are only of interest in the respective bridge
code. There's a remaining standard property "status" which is unclear how
to support properly but which also isn't used in FreeBSD at present.
This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
This in turn allows to simplify and remove code-duplication in drivers for
devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
drivers for their children to use the ofw_bus kobj-interface. The IVAR-
interfaces of the Central, EBus and FHC are entirely replaced by this. The
PCI bus driver used its own kobj-interface and now also uses the ofw_bus
one. The IVARs special to the SBus, e.g. for retrieving the burst size,
remain.
Beware: this causes an ABI-breakage for modules of drivers which used the
IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
recompiled.
The style-inconsistencies introduced in some of the bus drivers will be
fixed by tmm@ in a generic clean-up of the respective drivers later (he
requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
use the ofw_bus kobj-interface. This invloves removing the IVARs related
to the "reg" property which were unused and a leftover from the NetBSD
origini of the code. There's no ABI-breakage caused by this because none
of these driver are currently built as modules.
There are other powerpc bus drivers which can be converted to the ofw_bus
kobj-interface, e.g. the PCI bus driver, which should be done together
with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
advantage of the ofw_bus kobj-interface and simplify them a bit.
Reviewed by: grehan, tmm
Approved by: re (scottl)
Discussed with: tmm
Tested with: Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
|
|
|
|
2011-11-22 21:55:40 +00:00
|
|
|
DEVMETHOD_END
|
2001-11-09 20:23:38 +00:00
|
|
|
};
|
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
static driver_t ebus_nexus_driver = {
|
2001-11-09 20:23:38 +00:00
|
|
|
"ebus",
|
2009-12-22 21:49:53 +00:00
|
|
|
ebus_nexus_methods,
|
2001-11-09 20:23:38 +00:00
|
|
|
sizeof(struct ebus_softc),
|
|
|
|
};
|
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
/*
|
|
|
|
* NB: we rely on the interrupt controllers of the accompanying PCI-Express
|
|
|
|
* bridge to be registered as the nexus variant of the EBus bridges doesn't
|
|
|
|
* employ its own one.
|
|
|
|
*/
|
|
|
|
EARLY_DRIVER_MODULE(ebus, nexus, ebus_nexus_driver, ebus_devclass, 0, 0,
|
|
|
|
BUS_PASS_BUS + 1);
|
|
|
|
MODULE_DEPEND(ebus, nexus, 1, 1, 1);
|
|
|
|
|
|
|
|
static device_method_t ebus_pci_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, ebus_pci_probe),
|
|
|
|
DEVMETHOD(device_attach, ebus_pci_attach),
|
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
2001-11-09 20:23:38 +00:00
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, ebus_print_child),
|
|
|
|
DEVMETHOD(bus_probe_nomatch, ebus_probe_nomatch),
|
|
|
|
DEVMETHOD(bus_alloc_resource, ebus_alloc_resource),
|
|
|
|
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
|
|
|
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
|
|
|
DEVMETHOD(bus_release_resource, ebus_release_resource),
|
|
|
|
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
|
|
|
|
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
|
|
|
DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
|
|
|
|
DEVMETHOD(bus_get_resource_list, ebus_get_resource_list),
|
|
|
|
DEVMETHOD(bus_child_pnpinfo_str, ofw_bus_gen_child_pnpinfo_str),
|
|
|
|
|
|
|
|
/* ofw_bus interface */
|
|
|
|
DEVMETHOD(ofw_bus_get_devinfo, ebus_get_devinfo),
|
|
|
|
DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat),
|
|
|
|
DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model),
|
|
|
|
DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name),
|
|
|
|
DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),
|
|
|
|
DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
|
|
|
|
|
2011-11-22 21:55:40 +00:00
|
|
|
DEVMETHOD_END
|
2009-12-22 21:49:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t ebus_pci_driver = {
|
|
|
|
"ebus",
|
|
|
|
ebus_pci_methods,
|
|
|
|
sizeof(struct ebus_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
EARLY_DRIVER_MODULE(ebus, pci, ebus_pci_driver, ebus_devclass, 0, 0,
|
2009-12-22 21:02:46 +00:00
|
|
|
BUS_PASS_BUS);
|
2008-08-23 15:44:13 +00:00
|
|
|
MODULE_DEPEND(ebus, pci, 1, 1, 1);
|
|
|
|
MODULE_VERSION(ebus, 1);
|
2001-11-09 20:23:38 +00:00
|
|
|
|
|
|
|
static int
|
2009-12-22 21:49:53 +00:00
|
|
|
ebus_nexus_probe(device_t dev)
|
|
|
|
{
|
|
|
|
const char* compat;
|
|
|
|
|
|
|
|
compat = ofw_bus_get_compat(dev);
|
|
|
|
if (compat != NULL && strcmp(ofw_bus_get_name(dev), "ebus") == 0 &&
|
|
|
|
strcmp(compat, "jbus-ebus") == 0) {
|
|
|
|
device_set_desc(dev, "JBus-EBus bridge");
|
|
|
|
return (BUS_PROBE_GENERIC);
|
|
|
|
}
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ebus_pci_probe(device_t dev)
|
2001-11-09 20:23:38 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (pci_get_class(dev) != PCIC_BRIDGE ||
|
|
|
|
pci_get_vendor(dev) != 0x108e ||
|
2005-05-19 18:11:46 +00:00
|
|
|
strcmp(ofw_bus_get_name(dev), "ebus") != 0)
|
2001-11-09 20:23:38 +00:00
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if (pci_get_device(dev) == 0x1000)
|
|
|
|
device_set_desc(dev, "PCI-EBus2 bridge");
|
|
|
|
else if (pci_get_device(dev) == 0x1100)
|
|
|
|
device_set_desc(dev, "PCI-EBus3 bridge");
|
|
|
|
else
|
|
|
|
return (ENXIO);
|
2009-12-22 21:49:53 +00:00
|
|
|
return (BUS_PROBE_GENERIC);
|
2004-04-28 13:06:46 +00:00
|
|
|
}
|
2001-11-09 20:23:38 +00:00
|
|
|
|
2004-04-28 13:06:46 +00:00
|
|
|
static int
|
2009-12-22 21:49:53 +00:00
|
|
|
ebus_nexus_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct ebus_softc *sc;
|
|
|
|
phandle_t node;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
node = ofw_bus_get_node(dev);
|
|
|
|
|
|
|
|
#ifndef SUN4V
|
|
|
|
if (OF_getprop(node, "portid", &sc->sc_ign,
|
|
|
|
sizeof(sc->sc_ign)) == -1) {
|
|
|
|
device_printf(dev, "could not determine IGN");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-08 22:59:34 +00:00
|
|
|
sc->sc_nrange = OF_getprop_alloc_multi(node, "ranges",
|
2009-12-22 21:49:53 +00:00
|
|
|
sizeof(struct ebus_nexus_ranges), &sc->sc_range);
|
|
|
|
if (sc->sc_nrange == -1) {
|
2015-09-13 21:59:56 +00:00
|
|
|
device_printf(dev, "could not get ranges property\n");
|
2009-12-22 21:49:53 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
return (ebus_attach(dev, sc, node));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ebus_pci_attach(device_t dev)
|
2004-04-28 13:06:46 +00:00
|
|
|
{
|
|
|
|
struct ebus_softc *sc;
|
|
|
|
struct ebus_rinfo *eri;
|
|
|
|
struct resource *res;
|
2015-09-13 21:59:56 +00:00
|
|
|
struct isa_ranges *range;
|
2004-04-28 13:06:46 +00:00
|
|
|
phandle_t node;
|
|
|
|
int i, rnum, rid;
|
2001-11-09 20:23:38 +00:00
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2009-12-22 21:49:53 +00:00
|
|
|
sc->sc_flags |= EBUS_PCI;
|
|
|
|
|
|
|
|
pci_write_config(dev, PCIR_COMMAND,
|
|
|
|
pci_read_config(dev, PCIR_COMMAND, 2) | PCIM_CMD_SERRESPEN |
|
|
|
|
PCIM_CMD_PERRESPEN | PCIM_CMD_BUSMASTEREN | PCIM_CMD_MEMEN, 2);
|
|
|
|
pci_write_config(dev, PCIR_CACHELNSZ, 16 /* 64 bytes */, 1);
|
|
|
|
pci_write_config(dev, PCIR_LATTIMER, 64 /* 64 PCI cycles */, 1);
|
2001-11-09 20:23:38 +00:00
|
|
|
|
2008-08-23 15:44:13 +00:00
|
|
|
node = ofw_bus_get_node(dev);
|
2018-04-08 22:59:34 +00:00
|
|
|
sc->sc_nrange = OF_getprop_alloc_multi(node, "ranges",
|
2009-12-22 21:49:53 +00:00
|
|
|
sizeof(struct isa_ranges), &sc->sc_range);
|
2004-04-28 13:06:46 +00:00
|
|
|
if (sc->sc_nrange == -1) {
|
2015-09-13 21:59:56 +00:00
|
|
|
device_printf(dev, "could not get ranges property\n");
|
2004-04-28 13:06:46 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_rinfo = malloc(sizeof(*sc->sc_rinfo) * sc->sc_nrange, M_DEVBUF,
|
|
|
|
M_WAITOK | M_ZERO);
|
|
|
|
|
|
|
|
/* For every range, there must be a matching resource. */
|
|
|
|
for (rnum = 0; rnum < sc->sc_nrange; rnum++) {
|
|
|
|
eri = &sc->sc_rinfo[rnum];
|
2015-09-13 21:59:56 +00:00
|
|
|
range = &((struct isa_ranges *)sc->sc_range)[rnum];
|
|
|
|
eri->eri_rtype = ofw_isa_range_restype(range);
|
2004-04-28 13:06:46 +00:00
|
|
|
rid = PCIR_BAR(rnum);
|
|
|
|
res = bus_alloc_resource_any(dev, eri->eri_rtype, &rid,
|
|
|
|
RF_ACTIVE);
|
|
|
|
if (res == NULL) {
|
2015-09-13 21:59:56 +00:00
|
|
|
device_printf(dev,
|
|
|
|
"could not allocate range resource %d\n", rnum);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (rman_get_start(res) != ISA_RANGE_PHYS(range)) {
|
|
|
|
device_printf(dev,
|
|
|
|
"mismatch in start of range %d (0x%lx/0x%lx)\n",
|
|
|
|
rnum, rman_get_start(res), ISA_RANGE_PHYS(range));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (rman_get_size(res) != range->size) {
|
|
|
|
device_printf(dev,
|
|
|
|
"mismatch in size of range %d (0x%lx/0x%x)\n",
|
|
|
|
rnum, rman_get_size(res), range->size);
|
2004-04-28 13:06:46 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
eri->eri_res = res;
|
|
|
|
eri->eri_rman.rm_type = RMAN_ARRAY;
|
|
|
|
eri->eri_rman.rm_descr = "EBus range";
|
2011-10-02 23:22:38 +00:00
|
|
|
if (rman_init_from_resource(&eri->eri_rman, res) != 0) {
|
2015-09-13 21:59:56 +00:00
|
|
|
device_printf(dev,
|
|
|
|
"could not initialize rman for range %d", rnum);
|
2004-04-28 13:06:46 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2009-12-22 21:49:53 +00:00
|
|
|
return (ebus_attach(dev, sc, node));
|
|
|
|
|
|
|
|
fail:
|
|
|
|
for (i = rnum; i >= 0; i--) {
|
|
|
|
eri = &sc->sc_rinfo[i];
|
|
|
|
if (i < rnum)
|
|
|
|
rman_fini(&eri->eri_rman);
|
2016-04-15 12:17:34 +00:00
|
|
|
if (eri->eri_res != NULL) {
|
2009-12-22 21:49:53 +00:00
|
|
|
bus_release_resource(dev, eri->eri_rtype,
|
|
|
|
PCIR_BAR(rnum), eri->eri_res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(sc->sc_rinfo, M_DEVBUF);
|
2016-05-18 23:39:31 +00:00
|
|
|
OF_prop_free(sc->sc_range);
|
2009-12-22 21:49:53 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ebus_attach(device_t dev, struct ebus_softc *sc, phandle_t node)
|
|
|
|
{
|
|
|
|
struct ebus_devinfo *edi;
|
|
|
|
device_t cdev;
|
2001-11-09 20:23:38 +00:00
|
|
|
|
Add the new sparc64 OFW PCI framework, conditional on options OFW_NEWPCI
for now. It introduces a OFW PCI bus driver and a generic OFW PCI-PCI
bridge driver. By utilizing these, the PCI handling is much more elegant
now.
The advantages of the new approach are:
- Device enumeration should hopefully be more like on Solaris now,
so unit numbers should match what's printed on the box more
closely.
- Real interrupt routing is implemented now, so cardbus bridges
etc. have at least a chance to work.
- The quirk tables are gone and have been replaced by (hopefully
sufficient) heuristics.
- Much cleaner code.
There was also a report that previously bogus interrupt assignments
are fixed now, which can be attributed to the new heuristics.
A pitfall, and the reason why this is not the default yet, is that
it changes device enumeration, as mentioned above, which can make
it necessary to change the system configuration if more than one
unit of a device type is present (on a system with two hme cars,
for example, it is possible that hme0 becomes hme1 and vice versa
after enabling the option). Systems with multiple disk controllers
may need to be booted into single user (and require manual specification
of the root file system on boot) to adjust the fstab.
Nevertheless, I would like to encourage users to use this option,
so that it can be made the default soon.
In detail, the changes are:
- Introduce an OFW PCI bus driver; it inherits most methods from the
generic PCI bus driver, but uses the firmware for enumeration,
performs additional initialization for devices and firmware-specific
interrupt routing. It also implements an OFW-specific method to allow
child devices to get their firmware nodes.
- Introduce an OFW PCI-PCI bridge driver; again, it inherits most
of the generic PCI-PCI bridge driver; it has it's own method for
interrupt routing, as well as some sparc64-specific methods (one to
get the node again, and one to adjust the bridge bus range, since
we need to reenumerate all PCI buses).
- Convert the apb driver to the new way of handling things.
- Provide a common framework for OFW bridge drivers, used be the two
drivers above.
- Provide a small common framework for interrupt routing (for all
bridge types).
- Convert the psycho driver to the new framework; this gets rid of a
bunch of old kludges in pci_read_config(), and the whole
preinitialization (ofw_pci_init()).
- Convert the ISA MD part and the EBus driver to the new way
interrupts and nodes are handled.
- Introduce types for firmware interrupt properties.
- Rename the old sparcbus_if to ofw_pci_if by repo copy (it is only
required for PCI), and move it to a more correct location (new
support methodsx were also added, and an old one was deprecated).
- Fix a bunch of minor bugs, perform some cleanups.
In some cases, I introduced some minor code duplication to keep the
new code clean, in hopes that the old code will be unifdef'ed soon.
Reviewed in part by: imp
Tested by: jake, Marius Strobl <marius@alchemy.franken.de>,
Sergey Mokryshev <mokr@mokr.net>,
Chris Jackman <cjackNOSPAM@klatsch.org>
Info on u30 firmware provided by: kris
2003-07-01 14:52:47 +00:00
|
|
|
ofw_bus_setup_iinfo(node, &sc->sc_iinfo, sizeof(ofw_isa_intr_t));
|
|
|
|
|
2001-11-09 20:23:38 +00:00
|
|
|
/*
|
Add the new sparc64 OFW PCI framework, conditional on options OFW_NEWPCI
for now. It introduces a OFW PCI bus driver and a generic OFW PCI-PCI
bridge driver. By utilizing these, the PCI handling is much more elegant
now.
The advantages of the new approach are:
- Device enumeration should hopefully be more like on Solaris now,
so unit numbers should match what's printed on the box more
closely.
- Real interrupt routing is implemented now, so cardbus bridges
etc. have at least a chance to work.
- The quirk tables are gone and have been replaced by (hopefully
sufficient) heuristics.
- Much cleaner code.
There was also a report that previously bogus interrupt assignments
are fixed now, which can be attributed to the new heuristics.
A pitfall, and the reason why this is not the default yet, is that
it changes device enumeration, as mentioned above, which can make
it necessary to change the system configuration if more than one
unit of a device type is present (on a system with two hme cars,
for example, it is possible that hme0 becomes hme1 and vice versa
after enabling the option). Systems with multiple disk controllers
may need to be booted into single user (and require manual specification
of the root file system on boot) to adjust the fstab.
Nevertheless, I would like to encourage users to use this option,
so that it can be made the default soon.
In detail, the changes are:
- Introduce an OFW PCI bus driver; it inherits most methods from the
generic PCI bus driver, but uses the firmware for enumeration,
performs additional initialization for devices and firmware-specific
interrupt routing. It also implements an OFW-specific method to allow
child devices to get their firmware nodes.
- Introduce an OFW PCI-PCI bridge driver; again, it inherits most
of the generic PCI-PCI bridge driver; it has it's own method for
interrupt routing, as well as some sparc64-specific methods (one to
get the node again, and one to adjust the bridge bus range, since
we need to reenumerate all PCI buses).
- Convert the apb driver to the new way of handling things.
- Provide a common framework for OFW bridge drivers, used be the two
drivers above.
- Provide a small common framework for interrupt routing (for all
bridge types).
- Convert the psycho driver to the new framework; this gets rid of a
bunch of old kludges in pci_read_config(), and the whole
preinitialization (ofw_pci_init()).
- Convert the ISA MD part and the EBus driver to the new way
interrupts and nodes are handled.
- Introduce types for firmware interrupt properties.
- Rename the old sparcbus_if to ofw_pci_if by repo copy (it is only
required for PCI), and move it to a more correct location (new
support methodsx were also added, and an old one was deprecated).
- Fix a bunch of minor bugs, perform some cleanups.
In some cases, I introduced some minor code duplication to keep the
new code clean, in hopes that the old code will be unifdef'ed soon.
Reviewed in part by: imp
Tested by: jake, Marius Strobl <marius@alchemy.franken.de>,
Sergey Mokryshev <mokr@mokr.net>,
Chris Jackman <cjackNOSPAM@klatsch.org>
Info on u30 firmware provided by: kris
2003-07-01 14:52:47 +00:00
|
|
|
* Now attach our children.
|
2001-11-09 20:23:38 +00:00
|
|
|
*/
|
|
|
|
for (node = OF_child(node); node > 0; node = OF_peer(node)) {
|
2005-11-22 16:39:44 +00:00
|
|
|
if ((edi = ebus_setup_dinfo(dev, sc, node)) == NULL)
|
2001-11-09 20:23:38 +00:00
|
|
|
continue;
|
2005-11-22 16:39:44 +00:00
|
|
|
if ((cdev = device_add_child(dev, NULL, -1)) == NULL) {
|
|
|
|
device_printf(dev, "<%s>: device_add_child failed\n",
|
|
|
|
edi->edi_obdinfo.obd_name);
|
|
|
|
ebus_destroy_dinfo(edi);
|
2001-11-09 20:23:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
device_set_ivars(cdev, edi);
|
|
|
|
}
|
2004-04-28 13:06:46 +00:00
|
|
|
return (bus_generic_attach(dev));
|
2001-11-09 20:23:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ebus_print_child(device_t dev, device_t child)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = bus_print_child_header(dev, child);
|
2005-11-22 16:39:44 +00:00
|
|
|
retval += ebus_print_res(device_get_ivars(child));
|
2001-11-09 20:23:38 +00:00
|
|
|
retval += bus_print_child_footer(dev, child);
|
|
|
|
return (retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ebus_probe_nomatch(device_t dev, device_t child)
|
|
|
|
{
|
|
|
|
|
2005-11-22 16:39:44 +00:00
|
|
|
device_printf(dev, "<%s>", ofw_bus_get_name(child));
|
|
|
|
ebus_print_res(device_get_ivars(child));
|
2001-11-09 20:23:38 +00:00
|
|
|
printf(" (no driver attached)\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct resource *
|
|
|
|
ebus_alloc_resource(device_t bus, device_t child, int type, int *rid,
|
2016-01-27 02:23:54 +00:00
|
|
|
rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
|
2001-11-09 20:23:38 +00:00
|
|
|
{
|
|
|
|
struct ebus_softc *sc;
|
|
|
|
struct resource_list *rl;
|
2004-04-28 13:06:46 +00:00
|
|
|
struct resource_list_entry *rle = NULL;
|
|
|
|
struct resource *res;
|
2011-10-02 23:22:38 +00:00
|
|
|
struct ebus_rinfo *eri;
|
2009-12-22 21:49:53 +00:00
|
|
|
struct ebus_nexus_ranges *enr;
|
|
|
|
uint64_t cend, cstart, offset;
|
2011-10-02 23:22:38 +00:00
|
|
|
int i, isdefault, passthrough, ridx;
|
2001-11-09 20:23:38 +00:00
|
|
|
|
2016-02-20 01:32:58 +00:00
|
|
|
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
|
2009-12-22 21:49:53 +00:00
|
|
|
passthrough = (device_get_parent(child) != bus);
|
|
|
|
sc = device_get_softc(bus);
|
2004-04-28 13:06:46 +00:00
|
|
|
rl = BUS_GET_RESOURCE_LIST(bus, child);
|
2001-11-09 20:23:38 +00:00
|
|
|
switch (type) {
|
2005-05-19 18:11:46 +00:00
|
|
|
case SYS_RES_MEMORY:
|
2004-04-28 13:06:46 +00:00
|
|
|
KASSERT(!(isdefault && passthrough),
|
2009-12-22 21:49:53 +00:00
|
|
|
("%s: passthrough of default allocation", __func__));
|
2004-04-28 13:06:46 +00:00
|
|
|
if (!passthrough) {
|
2005-06-04 20:31:20 +00:00
|
|
|
rle = resource_list_find(rl, type, *rid);
|
2004-04-28 13:06:46 +00:00
|
|
|
if (rle == NULL)
|
|
|
|
return (NULL);
|
|
|
|
KASSERT(rle->res == NULL,
|
2009-12-22 21:49:53 +00:00
|
|
|
("%s: resource entry is busy", __func__));
|
2004-04-28 13:06:46 +00:00
|
|
|
if (isdefault) {
|
|
|
|
start = rle->start;
|
|
|
|
count = ulmax(count, rle->count);
|
|
|
|
end = ulmax(rle->end, start + count - 1);
|
|
|
|
}
|
2001-11-09 20:23:38 +00:00
|
|
|
}
|
2004-04-28 13:06:46 +00:00
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
res = NULL;
|
|
|
|
if ((sc->sc_flags & EBUS_PCI) != 0) {
|
|
|
|
/*
|
|
|
|
* Map EBus ranges to PCI ranges. This may include
|
|
|
|
* changing the allocation type.
|
|
|
|
*/
|
2015-09-13 21:59:56 +00:00
|
|
|
type = ofw_isa_range_map(sc->sc_range, sc->sc_nrange,
|
2009-12-22 21:49:53 +00:00
|
|
|
&start, &end, &ridx);
|
2011-10-02 23:22:38 +00:00
|
|
|
eri = &sc->sc_rinfo[ridx];
|
|
|
|
res = rman_reserve_resource(&eri->eri_rman, start,
|
|
|
|
end, count, flags & ~RF_ACTIVE, child);
|
2009-12-22 21:49:53 +00:00
|
|
|
if (res == NULL)
|
|
|
|
return (NULL);
|
|
|
|
rman_set_rid(res, *rid);
|
2011-10-02 23:22:38 +00:00
|
|
|
if ((flags & RF_ACTIVE) != 0 && bus_activate_resource(
|
|
|
|
child, type, *rid, res) != 0) {
|
2009-12-22 21:49:53 +00:00
|
|
|
rman_release_resource(res);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Map EBus ranges to nexus ranges. */
|
|
|
|
for (i = 0; i < sc->sc_nrange; i++) {
|
|
|
|
enr = &((struct ebus_nexus_ranges *)
|
|
|
|
sc->sc_range)[i];
|
|
|
|
cstart = (((uint64_t)enr->child_hi) << 32) |
|
|
|
|
enr->child_lo;
|
|
|
|
cend = cstart + enr->size - 1;
|
|
|
|
if (start >= cstart && end <= cend) {
|
|
|
|
offset =
|
|
|
|
(((uint64_t)enr->phys_hi) << 32) |
|
|
|
|
enr->phys_lo;
|
|
|
|
start += offset - cstart;
|
|
|
|
end += offset - cstart;
|
|
|
|
res = bus_generic_alloc_resource(bus,
|
|
|
|
child, type, rid, start, end,
|
|
|
|
count, flags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-11-09 20:23:38 +00:00
|
|
|
}
|
2004-04-28 13:06:46 +00:00
|
|
|
if (!passthrough)
|
|
|
|
rle->res = res;
|
|
|
|
return (res);
|
2001-11-09 20:23:38 +00:00
|
|
|
case SYS_RES_IRQ:
|
2004-04-28 13:06:46 +00:00
|
|
|
return (resource_list_alloc(rl, bus, child, type, rid, start,
|
|
|
|
end, count, flags));
|
2001-11-09 20:23:38 +00:00
|
|
|
}
|
2005-01-09 18:58:08 +00:00
|
|
|
return (NULL);
|
2004-04-28 13:06:46 +00:00
|
|
|
}
|
2002-02-13 15:35:22 +00:00
|
|
|
|
2011-10-02 23:22:38 +00:00
|
|
|
static int
|
|
|
|
ebus_activate_resource(device_t bus, device_t child, int type, int rid,
|
|
|
|
struct resource *res)
|
|
|
|
{
|
|
|
|
struct ebus_softc *sc;
|
|
|
|
struct ebus_rinfo *eri;
|
|
|
|
bus_space_tag_t bt;
|
|
|
|
bus_space_handle_t bh;
|
|
|
|
int i, rv;
|
|
|
|
|
|
|
|
sc = device_get_softc(bus);
|
2015-09-13 21:59:56 +00:00
|
|
|
if ((sc->sc_flags & EBUS_PCI) != 0 && type != SYS_RES_IRQ) {
|
2011-10-02 23:22:38 +00:00
|
|
|
for (i = 0; i < sc->sc_nrange; i++) {
|
|
|
|
eri = &sc->sc_rinfo[i];
|
|
|
|
if (rman_is_region_manager(res, &eri->eri_rman) != 0) {
|
|
|
|
bt = rman_get_bustag(eri->eri_res);
|
|
|
|
rv = bus_space_subregion(bt,
|
|
|
|
rman_get_bushandle(eri->eri_res),
|
|
|
|
rman_get_start(res) -
|
|
|
|
rman_get_start(eri->eri_res),
|
|
|
|
rman_get_size(res), &bh);
|
|
|
|
if (rv != 0)
|
|
|
|
return (rv);
|
|
|
|
rman_set_bustag(res, bt);
|
|
|
|
rman_set_bushandle(res, bh);
|
|
|
|
return (rman_activate_resource(res));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
return (bus_generic_activate_resource(bus, child, type, rid, res));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ebus_adjust_resource(device_t bus __unused, device_t child __unused,
|
2016-01-27 02:23:54 +00:00
|
|
|
int type __unused, struct resource *res __unused, rman_res_t start __unused,
|
|
|
|
rman_res_t end __unused)
|
2011-10-02 23:22:38 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2008-08-23 15:44:13 +00:00
|
|
|
static int
|
2004-04-28 13:06:46 +00:00
|
|
|
ebus_release_resource(device_t bus, device_t child, int type, int rid,
|
|
|
|
struct resource *res)
|
|
|
|
{
|
2009-12-22 21:49:53 +00:00
|
|
|
struct ebus_softc *sc;
|
2004-04-28 13:06:46 +00:00
|
|
|
struct resource_list *rl;
|
|
|
|
struct resource_list_entry *rle;
|
2009-12-22 21:49:53 +00:00
|
|
|
int passthrough, rv;
|
2001-11-09 20:23:38 +00:00
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
passthrough = (device_get_parent(child) != bus);
|
2004-04-28 13:06:46 +00:00
|
|
|
rl = BUS_GET_RESOURCE_LIST(bus, child);
|
2011-10-02 23:22:38 +00:00
|
|
|
sc = device_get_softc(bus);
|
2015-09-13 21:59:56 +00:00
|
|
|
if ((sc->sc_flags & EBUS_PCI) != 0 && type != SYS_RES_IRQ) {
|
2011-10-02 23:22:38 +00:00
|
|
|
if ((rman_get_flags(res) & RF_ACTIVE) != 0 ){
|
|
|
|
rv = bus_deactivate_resource(child, type, rid, res);
|
|
|
|
if (rv != 0)
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
rv = rman_release_resource(res);
|
|
|
|
if (rv != 0)
|
2004-04-28 13:06:46 +00:00
|
|
|
return (rv);
|
|
|
|
if (!passthrough) {
|
2005-06-04 20:31:20 +00:00
|
|
|
rle = resource_list_find(rl, type, rid);
|
2009-12-22 21:49:53 +00:00
|
|
|
KASSERT(rle != NULL,
|
|
|
|
("%s: resource entry not found!", __func__));
|
|
|
|
KASSERT(rle->res != NULL,
|
|
|
|
("%s: resource entry is not busy", __func__));
|
2004-04-28 13:06:46 +00:00
|
|
|
rle->res = NULL;
|
2001-11-09 20:23:38 +00:00
|
|
|
}
|
2011-10-02 23:22:38 +00:00
|
|
|
return (0);
|
2001-11-09 20:23:38 +00:00
|
|
|
}
|
2011-10-02 23:22:38 +00:00
|
|
|
return (resource_list_release(rl, bus, child, type, rid, res));
|
2001-11-09 20:23:38 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 21:49:53 +00:00
|
|
|
static int
|
|
|
|
ebus_setup_intr(device_t dev, device_t child, struct resource *ires,
|
|
|
|
int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg,
|
|
|
|
void **cookiep)
|
|
|
|
{
|
|
|
|
#ifndef SUN4V
|
|
|
|
struct ebus_softc *sc;
|
|
|
|
u_long vec;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
if ((sc->sc_flags & EBUS_PCI) == 0) {
|
|
|
|
/*
|
|
|
|
* Make sure the vector is fully specified. This isn't
|
|
|
|
* necessarily the case with the PCI variant.
|
|
|
|
*/
|
|
|
|
vec = rman_get_start(ires);
|
|
|
|
if (INTIGN(vec) != sc->sc_ign) {
|
|
|
|
device_printf(dev,
|
|
|
|
"invalid interrupt vector 0x%lx\n", vec);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As we rely on the interrupt controllers of the
|
|
|
|
* accompanying PCI-Express bridge ensure at least
|
|
|
|
* something is registered for this vector.
|
|
|
|
*/
|
|
|
|
if (intr_vectors[vec].iv_ic == NULL) {
|
|
|
|
device_printf(dev,
|
|
|
|
"invalid interrupt controller for vector 0x%lx\n",
|
|
|
|
vec);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return (bus_generic_setup_intr(dev, child, ires, flags, filt, intr,
|
|
|
|
arg, cookiep));
|
|
|
|
}
|
|
|
|
|
2001-11-09 20:23:38 +00:00
|
|
|
static struct resource_list *
|
|
|
|
ebus_get_resource_list(device_t dev, device_t child)
|
|
|
|
{
|
|
|
|
struct ebus_devinfo *edi;
|
|
|
|
|
|
|
|
edi = device_get_ivars(child);
|
|
|
|
return (&edi->edi_rl);
|
|
|
|
}
|
|
|
|
|
2005-11-22 16:39:44 +00:00
|
|
|
static const struct ofw_bus_devinfo *
|
|
|
|
ebus_get_devinfo(device_t bus, device_t dev)
|
|
|
|
{
|
|
|
|
struct ebus_devinfo *edi;
|
|
|
|
|
|
|
|
edi = device_get_ivars(dev);
|
|
|
|
return (&edi->edi_obdinfo);
|
|
|
|
}
|
|
|
|
|
2001-11-09 20:23:38 +00:00
|
|
|
static struct ebus_devinfo *
|
2005-11-22 16:39:44 +00:00
|
|
|
ebus_setup_dinfo(device_t dev, struct ebus_softc *sc, phandle_t node)
|
2001-11-09 20:23:38 +00:00
|
|
|
{
|
2009-12-22 21:49:53 +00:00
|
|
|
struct isa_regs reg, *regs;
|
|
|
|
ofw_isa_intr_t intr, *intrs;
|
2001-11-09 20:23:38 +00:00
|
|
|
struct ebus_devinfo *edi;
|
2009-12-22 21:49:53 +00:00
|
|
|
uint64_t start;
|
|
|
|
uint32_t rintr;
|
|
|
|
int i, nintr, nreg, rv;
|
2001-11-09 20:23:38 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
edi = malloc(sizeof(*edi), M_DEVBUF, M_ZERO | M_WAITOK);
|
2005-11-22 16:39:44 +00:00
|
|
|
if (ofw_bus_gen_setup_devinfo(&edi->edi_obdinfo, node) != 0) {
|
|
|
|
free(edi, M_DEVBUF);
|
2001-11-09 20:23:38 +00:00
|
|
|
return (NULL);
|
2005-11-22 16:39:44 +00:00
|
|
|
}
|
2001-11-09 20:23:38 +00:00
|
|
|
resource_list_init(&edi->edi_rl);
|
2018-04-08 22:59:34 +00:00
|
|
|
nreg = OF_getprop_alloc_multi(node, "reg", sizeof(*regs), (void **)®s);
|
2001-11-09 20:23:38 +00:00
|
|
|
if (nreg == -1) {
|
2005-11-22 16:39:44 +00:00
|
|
|
device_printf(dev, "<%s>: incomplete\n",
|
|
|
|
edi->edi_obdinfo.obd_name);
|
2009-12-22 21:49:53 +00:00
|
|
|
ebus_destroy_dinfo(edi);
|
|
|
|
return (NULL);
|
2001-11-09 20:23:38 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < nreg; i++) {
|
2009-12-22 21:49:53 +00:00
|
|
|
start = ISA_REG_PHYS(regs + i);
|
|
|
|
(void)resource_list_add(&edi->edi_rl, SYS_RES_MEMORY, i,
|
|
|
|
start, start + regs[i].size - 1, regs[i].size);
|
2001-11-09 20:23:38 +00:00
|
|
|
}
|
2016-05-18 23:39:31 +00:00
|
|
|
OF_prop_free(regs);
|
2001-11-09 20:23:38 +00:00
|
|
|
|
2018-04-08 22:59:34 +00:00
|
|
|
nintr = OF_getprop_alloc_multi(node, "interrupts", sizeof(*intrs),
|
2001-11-09 20:23:38 +00:00
|
|
|
(void **)&intrs);
|
2009-12-22 21:49:53 +00:00
|
|
|
if (nintr == -1)
|
|
|
|
return (edi);
|
2001-11-09 20:23:38 +00:00
|
|
|
for (i = 0; i < nintr; i++) {
|
2009-12-22 21:49:53 +00:00
|
|
|
rv = 0;
|
|
|
|
if ((sc->sc_flags & EBUS_PCI) != 0) {
|
|
|
|
rintr = ofw_isa_route_intr(dev, node, &sc->sc_iinfo,
|
|
|
|
intrs[i]);
|
|
|
|
} else {
|
|
|
|
intr = intrs[i];
|
|
|
|
rv = ofw_bus_lookup_imap(node, &sc->sc_iinfo, ®,
|
|
|
|
sizeof(reg), &intr, sizeof(intr), &rintr,
|
2013-12-17 15:11:24 +00:00
|
|
|
sizeof(rintr), NULL);
|
2009-12-22 21:49:53 +00:00
|
|
|
#ifndef SUN4V
|
|
|
|
if (rv != 0)
|
|
|
|
rintr = INTMAP_VEC(sc->sc_ign, rintr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if ((sc->sc_flags & EBUS_PCI) == 0 ? rv == 0 :
|
|
|
|
rintr == PCI_INVALID_IRQ) {
|
2005-11-22 16:39:44 +00:00
|
|
|
device_printf(dev,
|
|
|
|
"<%s>: could not map EBus interrupt %d\n",
|
|
|
|
edi->edi_obdinfo.obd_name, intrs[i]);
|
2009-12-22 21:49:53 +00:00
|
|
|
continue;
|
2005-11-22 16:39:44 +00:00
|
|
|
}
|
2009-12-22 21:49:53 +00:00
|
|
|
(void)resource_list_add(&edi->edi_rl, SYS_RES_IRQ, i, rintr,
|
|
|
|
rintr, 1);
|
2001-11-09 20:23:38 +00:00
|
|
|
}
|
2016-05-18 23:39:31 +00:00
|
|
|
OF_prop_free(intrs);
|
2001-11-09 20:23:38 +00:00
|
|
|
return (edi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ebus_destroy_dinfo(struct ebus_devinfo *edi)
|
|
|
|
{
|
|
|
|
|
|
|
|
resource_list_free(&edi->edi_rl);
|
2005-11-22 16:39:44 +00:00
|
|
|
ofw_bus_gen_destroy_devinfo(&edi->edi_obdinfo);
|
2001-11-09 20:23:38 +00:00
|
|
|
free(edi, M_DEVBUF);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ebus_print_res(struct ebus_devinfo *edi)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = 0;
|
2005-05-19 18:11:46 +00:00
|
|
|
retval += resource_list_print_type(&edi->edi_rl, "addr", SYS_RES_MEMORY,
|
2016-03-22 22:25:08 +00:00
|
|
|
"%#jx");
|
2001-11-09 20:23:38 +00:00
|
|
|
retval += resource_list_print_type(&edi->edi_rl, "irq", SYS_RES_IRQ,
|
2016-03-22 22:25:08 +00:00
|
|
|
"%jd");
|
2001-11-09 20:23:38 +00:00
|
|
|
return (retval);
|
|
|
|
}
|