Path: blob/main/sys/powerpc/powernv/powernv_centaur.c
39536 views
/*-1* Copyright (c) 2017-2018 QCM Technologies.2* Copyright (c) 2017-2018 Semihalf.3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24* SUCH DAMAGE.25*/2627#include "opt_platform.h"2829#include <sys/param.h>30#include <sys/systm.h>31#include <sys/bus.h>32#include <sys/conf.h>33#include <sys/kernel.h>34#include <sys/lock.h>35#include <sys/mbuf.h>36#include <sys/malloc.h>37#include <sys/module.h>38#include <sys/mutex.h>39#include <sys/rman.h>40#include <machine/bus.h>4142#ifdef FDT43#include <dev/ofw/ofw_bus.h>44#include <dev/ofw/ofw_bus_subr.h>45#endif4647struct powernv_centaur_softc48{4950};5152static int powernv_centaur_attach(device_t);53static int powernv_centaur_probe(device_t);54static const struct ofw_bus_devinfo *55powernv_centaur_get_devinfo(device_t, device_t);5657static device_method_t powernv_centaur_methods[] = {58/* Device interface */59DEVMETHOD(device_probe, powernv_centaur_probe),60DEVMETHOD(device_attach, powernv_centaur_attach),6162/* ofw_bus interface */63DEVMETHOD(ofw_bus_get_devinfo, powernv_centaur_get_devinfo),64DEVMETHOD(ofw_bus_get_compat, ofw_bus_gen_get_compat),65DEVMETHOD(ofw_bus_get_model, ofw_bus_gen_get_model),66DEVMETHOD(ofw_bus_get_name, ofw_bus_gen_get_name),67DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),68DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),6970DEVMETHOD_END71};7273static int74powernv_centaur_probe(device_t dev)75{7677if (!(ofw_bus_is_compatible(dev, "ibm,centaur")))78return (ENXIO);7980device_set_desc(dev, "centaur");81return (0);82}8384static int85powernv_centaur_attach(device_t dev)86{87phandle_t child;88device_t cdev;89struct ofw_bus_devinfo *dinfo;9091for (child = OF_child(ofw_bus_get_node(dev)); child != 0;92child = OF_peer(child)) {93dinfo = malloc(sizeof(*dinfo), M_DEVBUF, M_WAITOK | M_ZERO);94if (ofw_bus_gen_setup_devinfo(dinfo, child) != 0) {95free(dinfo, M_DEVBUF);96continue;97}98cdev = device_add_child(dev, NULL, DEVICE_UNIT_ANY);99if (cdev == NULL) {100device_printf(dev, "<%s>: device_add_child failed\n",101dinfo->obd_name);102ofw_bus_gen_destroy_devinfo(dinfo);103free(dinfo, M_DEVBUF);104continue;105}106device_set_ivars(cdev, dinfo);107}108109bus_attach_children(dev);110return (0);111}112113static const struct ofw_bus_devinfo *114powernv_centaur_get_devinfo(device_t dev, device_t child)115{116return (device_get_ivars(child));117}118119DEFINE_CLASS_0(powernv_centaur, powernv_centaur_driver, powernv_centaur_methods,120sizeof(struct powernv_centaur_softc));121DRIVER_MODULE(powernv_centaur, ofwbus, powernv_centaur_driver, NULL, NULL);122123124