1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-15 10:17:20 +00:00

Convert to use the recently introduced set of ofw_bus_gen_get_*() for

providing the ofw_bus KOBJ interface.

Tested by:	grehan
This commit is contained in:
Marius Strobl 2005-12-03 11:59:26 +00:00
parent 00b1756b1e
commit d8154a2aeb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=153050
2 changed files with 43 additions and 96 deletions

View File

@ -48,6 +48,7 @@
#include <machine/resource.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/openfirm.h>
#include <powerpc/powermac/maciovar.h>
@ -80,11 +81,7 @@ static int macio_deactivate_resource(device_t, device_t, int, int,
static int macio_release_resource(device_t, device_t, int, int,
struct resource *);
static struct resource_list *macio_get_resource_list (device_t, device_t);
static ofw_bus_get_compat_t macio_get_compat;
static ofw_bus_get_model_t macio_get_model;
static ofw_bus_get_name_t macio_get_name;
static ofw_bus_get_node_t macio_get_node;
static ofw_bus_get_type_t macio_get_type;
static ofw_bus_get_devinfo_t macio_get_devinfo;
/*
* Bus interface definition
@ -111,11 +108,12 @@ static device_method_t macio_methods[] = {
DEVMETHOD(bus_get_resource_list, macio_get_resource_list),
/* ofw_bus interface */
DEVMETHOD(ofw_bus_get_compat, macio_get_compat),
DEVMETHOD(ofw_bus_get_model, macio_get_model),
DEVMETHOD(ofw_bus_get_name, macio_get_name),
DEVMETHOD(ofw_bus_get_node, macio_get_node),
DEVMETHOD(ofw_bus_get_type, macio_get_type),
DEVMETHOD(ofw_bus_get_devinfo, macio_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),
{ 0, 0 }
};
@ -256,7 +254,6 @@ macio_attach(device_t dev)
phandle_t subchild;
device_t cdev;
u_int reg[3];
char *name;
int quirks;
sc = device_get_softc(dev);
@ -286,43 +283,36 @@ macio_attach(device_t dev)
* Iterate through the sub-devices
*/
for (child = OF_child(root); child != 0; child = OF_peer(child)) {
OF_getprop_alloc(child, "name", 1, (void **)&name);
quirks = macio_get_quirks(name);
if ((quirks & MACIO_QUIRK_IGNORE) != 0) {
free(name, M_OFWPROP);
dinfo = malloc(sizeof(*dinfo), M_MACIO, M_WAITOK | M_ZERO);
if (ofw_bus_gen_setup_devinfo(&dinfo->mdi_obdinfo, child) !=
0) {
free(dinfo, M_MACIO);
continue;
}
cdev = device_add_child(dev, NULL, -1);
if (cdev != NULL) {
dinfo = malloc(sizeof(*dinfo), M_MACIO, M_WAITOK);
memset(dinfo, 0, sizeof(*dinfo));
resource_list_init(&dinfo->mdi_resources);
dinfo->mdi_node = child;
dinfo->mdi_name = name;
OF_getprop_alloc(child, "compatible", 1,
(void **)&dinfo->mdi_compat);
OF_getprop_alloc(child, "device_type", 1,
(void **)&dinfo->mdi_type);
OF_getprop_alloc(child, "model", 1,
(void **)&dinfo->mdi_model);
dinfo->mdi_ninterrupts = 0;
macio_add_intr(child, dinfo);
macio_add_reg(child, dinfo);
if ((quirks & MACIO_QUIRK_CHILD_HAS_INTR) != 0) {
for (subchild = OF_child(child); subchild != 0;
subchild = OF_peer(subchild)) {
macio_add_intr(subchild, dinfo);
}
}
device_set_ivars(cdev, dinfo);
} else {
free(name, M_OFWPROP);
quirks = macio_get_quirks(dinfo->mdi_obdinfo.obd_name);
if ((quirks & MACIO_QUIRK_IGNORE) != 0) {
ofw_bus_gen_destroy_devinfo(&dinfo->mdi_obdinfo);
free(dinfo, M_MACIO);
continue;
}
resource_list_init(&dinfo->mdi_resources);
dinfo->mdi_ninterrupts = 0;
macio_add_intr(child, dinfo);
macio_add_reg(child, dinfo);
if ((quirks & MACIO_QUIRK_CHILD_HAS_INTR) != 0)
for (subchild = OF_child(child); subchild != 0;
subchild = OF_peer(subchild))
macio_add_intr(subchild, dinfo);
cdev = device_add_child(dev, NULL, -1);
if (cdev == NULL) {
device_printf(dev, "<%s>: device_add_child failed\n",
dinfo->mdi_obdinfo.obd_name);
resource_list_free(&dinfo->mdi_resources);
ofw_bus_gen_destroy_devinfo(&dinfo->mdi_obdinfo);
free(dinfo, M_MACIO);
continue;
}
device_set_ivars(cdev, dinfo);
}
return (bus_generic_attach(dev));
@ -535,56 +525,17 @@ macio_deactivate_resource(device_t bus, device_t child, int type, int rid,
static struct resource_list *
macio_get_resource_list (device_t dev, device_t child)
{
struct macio_devinfo *dinfo = device_get_ivars(child);
struct resource_list *rl = &dinfo->mdi_resources;
struct macio_devinfo *dinfo;
if (!rl)
return (NULL);
return (rl);
dinfo = device_get_ivars(child);
return (&dinfo->mdi_resources);
}
const char *
macio_get_compat(device_t bus, device_t dev)
static const struct ofw_bus_devinfo *
macio_get_devinfo(device_t dev, device_t child)
{
struct macio_devinfo *dinfo;
dinfo = device_get_ivars(dev);
return (dinfo->mdi_compat);
}
const char *
macio_get_model(device_t bus, device_t dev)
{
struct macio_devinfo *dinfo;
dinfo = device_get_ivars(dev);
return (dinfo->mdi_model);
}
const char *
macio_get_name(device_t bus, device_t dev)
{
struct macio_devinfo *dinfo;
dinfo = device_get_ivars(dev);
return (dinfo->mdi_name);
}
static phandle_t
macio_get_node(device_t bus, device_t dev)
{
struct macio_devinfo *dinfo;
dinfo = device_get_ivars(dev);
return (dinfo->mdi_node);
}
const char *
macio_get_type(device_t bus, device_t dev)
{
struct macio_devinfo *dinfo;
dinfo = device_get_ivars(dev);
return (dinfo->mdi_type);
dinfo = device_get_ivars(child);
return (&dinfo->mdi_obdinfo);
}

View File

@ -49,14 +49,10 @@ struct macio_reg {
* Per macio device structure.
*/
struct macio_devinfo {
char *mdi_compat;
char *mdi_model;
char *mdi_name;
phandle_t mdi_node;
char *mdi_type;
int mdi_interrupts[5];
int mdi_ninterrupts;
int mdi_base;
struct ofw_bus_devinfo mdi_obdinfo;
struct resource_list mdi_resources;
};