#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/bus.h>
#include <sys/module.h>
#include <sys/systm.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/resource.h>
#include <dev/bhnd/bhnd.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include "bhnd_pcie2_reg.h"
#include "bhnd_pcie2_hostbvar.h"
static const struct bhnd_device_quirk bhnd_pcie2_quirks[];
static int bhnd_pcie2_wars_early_once(struct bhnd_pcie2hb_softc *sc);
static int bhnd_pcie2_wars_hwup(struct bhnd_pcie2hb_softc *sc);
static int bhnd_pcie2_wars_hwdown(struct bhnd_pcie2hb_softc *sc);
#define BHND_PCI_DEV(_core, _quirks) \
BHND_DEVICE(BCM, _core, NULL, _quirks, BHND_DF_HOSTB)
static const struct bhnd_device bhnd_pcie2_devs[] = {
BHND_PCI_DEV(PCIE2, bhnd_pcie2_quirks),
BHND_DEVICE_END
};
static const struct bhnd_device_quirk bhnd_pcie2_quirks[] = {
{{ BHND_MATCH_BOARD(PCI_VENDOR_APPLE, BCM94360X51P2), },
BHND_PCIE2_QUIRK_SERDES_TXDRV_DEEMPH },
{{ BHND_MATCH_BOARD(PCI_VENDOR_APPLE, BCM94360X51A), },
BHND_PCIE2_QUIRK_SERDES_TXDRV_DEEMPH },
BHND_DEVICE_QUIRK_END
};
static int
bhnd_pcie2_hostb_attach(device_t dev)
{
struct bhnd_pcie2hb_softc *sc;
int error;
sc = device_get_softc(dev);
sc->dev = dev;
sc->quirks = bhnd_device_quirks(dev, bhnd_pcie2_devs,
sizeof(bhnd_pcie2_devs[0]));
sc->pci_dev = bhnd_find_bridge_root(dev, devclass_find("pci"));
if (sc->pci_dev == NULL) {
device_printf(dev, "parent pci bridge device not found\n");
return (ENXIO);
}
if ((error = bhnd_pcie2_generic_attach(dev)))
return (error);
if ((error = bhnd_pcie2_wars_early_once(sc)))
goto failed;
if ((error = bhnd_pcie2_wars_hwup(sc)))
goto failed;
return (0);
failed:
bhnd_pcie2_generic_detach(dev);
return (error);
}
static int
bhnd_pcie2_hostb_detach(device_t dev)
{
struct bhnd_pcie2hb_softc *sc;
int error;
sc = device_get_softc(dev);
if ((error = bhnd_pcie2_wars_hwdown(sc)))
return (error);
return (bhnd_pcie2_generic_detach(dev));
}
static int
bhnd_pcie2_hostb_suspend(device_t dev)
{
struct bhnd_pcie2hb_softc *sc;
int error;
sc = device_get_softc(dev);
if ((error = bhnd_pcie2_wars_hwdown(sc)))
return (error);
return (bhnd_pcie2_generic_suspend(dev));
}
static int
bhnd_pcie2_hostb_resume(device_t dev)
{
struct bhnd_pcie2hb_softc *sc;
int error;
sc = device_get_softc(dev);
if ((error = bhnd_pcie2_generic_resume(dev)))
return (error);
if ((error = bhnd_pcie2_wars_hwup(sc))) {
bhnd_pcie2_generic_detach(dev);
return (error);
}
return (0);
}
static int
bhnd_pcie2_wars_early_once(struct bhnd_pcie2hb_softc *sc)
{
return (ENXIO);
}
static int
bhnd_pcie2_wars_hwup(struct bhnd_pcie2hb_softc *sc)
{
return (ENXIO);
}
static int
bhnd_pcie2_wars_hwdown(struct bhnd_pcie2hb_softc *sc)
{
return (ENXIO);
}
static device_method_t bhnd_pcie2_hostb_methods[] = {
DEVMETHOD(device_attach, bhnd_pcie2_hostb_attach),
DEVMETHOD(device_detach, bhnd_pcie2_hostb_detach),
DEVMETHOD(device_suspend, bhnd_pcie2_hostb_suspend),
DEVMETHOD(device_resume, bhnd_pcie2_hostb_resume),
DEVMETHOD_END
};
DEFINE_CLASS_1(bhnd_hostb, bhnd_pcie2_hostb_driver,
bhnd_pcie2_hostb_methods, sizeof(struct bhnd_pcie2hb_softc),
bhnd_pcie2_driver);
DRIVER_MODULE(bhnd_pcie2_hostb, bhnd, bhnd_pcie2_hostb_driver, 0, 0);
MODULE_VERSION(bhnd_pcie2_hostb, 1);
MODULE_DEPEND(bhnd_pcie2_hostb, bhnd, 1, 1, 1);
MODULE_DEPEND(bhnd_pcie2_hostb, bhnd_pcie2, 1, 1, 1);