101c101
< __FBSDID("$FreeBSD: head/sys/sparc64/sbus/sbus.c 146391 2005-05-19 14:47:31Z marius $");
---
> __FBSDID("$FreeBSD: head/sys/sparc64/sbus/sbus.c 152684 2005-11-22 16:39:44Z marius $");
116a117
> #include <dev/ofw/ofw_bus_subr.h>
139,142d139
< char *sdi_compat; /* PROM compatible */
< char *sdi_model; /* PROM model */
< char *sdi_name; /* PROM name */
< phandle_t sdi_node; /* PROM node */
144d140
< char *sdi_type; /* PROM device_type */
145a142
> struct ofw_bus_devinfo sdi_obdinfo;
209,213c206
< static ofw_bus_get_compat_t sbus_get_compat;
< static ofw_bus_get_model_t sbus_get_model;
< static ofw_bus_get_name_t sbus_get_name;
< static ofw_bus_get_node_t sbus_get_node;
< static ofw_bus_get_type_t sbus_get_type;
---
> static ofw_bus_get_devinfo_t sbus_get_devinfo;
216,218c209,211
< static struct sbus_devinfo * sbus_setup_dinfo(struct sbus_softc *sc,
< phandle_t node, char *name);
< static void sbus_destroy_dinfo(struct sbus_devinfo *dinfo);
---
> static struct sbus_devinfo * sbus_setup_dinfo(device_t, struct sbus_softc *,
> phandle_t);
> static void sbus_destroy_dinfo(struct sbus_devinfo *);
222a216
> static int sbus_print_res(struct sbus_devinfo *);
243,247c237,242
< DEVMETHOD(ofw_bus_get_compat, sbus_get_compat),
< DEVMETHOD(ofw_bus_get_model, sbus_get_model),
< DEVMETHOD(ofw_bus_get_name, sbus_get_name),
< DEVMETHOD(ofw_bus_get_node, sbus_get_node),
< DEVMETHOD(ofw_bus_get_type, sbus_get_type),
---
> DEVMETHOD(ofw_bus_get_devinfo, sbus_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),
308c303
< char *name, *cname;
---
> char *name;
459c454
< if ((OF_getprop_alloc(child, "name", 1, (void **)&cname)) == -1)
---
> if ((sdi = sbus_setup_dinfo(dev, sc, child)) == NULL)
461,466d455
<
< if ((sdi = sbus_setup_dinfo(sc, child, cname)) == NULL) {
< device_printf(dev, "<%s>: incomplete\n", cname);
< free(cname, M_OFWPROP);
< continue;
< }
479,482c468,476
< sbus_inlist(cname, sbus_order_first)) ? SBUS_ORDER_FIRST :
< SBUS_ORDER_NORMAL, NULL, -1);
< if (cdev == NULL)
< panic("%s: device_add_child_ordered failed", __func__);
---
> sbus_inlist(sdi->sdi_obdinfo.obd_name, sbus_order_first)) ?
> SBUS_ORDER_FIRST : SBUS_ORDER_NORMAL, NULL, -1);
> if (cdev == NULL) {
> device_printf(dev,
> "<%s>: device_add_child_ordered failed\n",
> sdi->sdi_obdinfo.obd_name);
> sbus_destroy_dinfo(sdi);
> continue;
> }
489c483
< sbus_setup_dinfo(struct sbus_softc *sc, phandle_t node, char *name)
---
> sbus_setup_dinfo(device_t dev, struct sbus_softc *sc, phandle_t node)
497c491,492
< if (sdi == NULL)
---
> if (ofw_bus_gen_setup_devinfo(&sdi->sdi_obdinfo, node) != 0) {
> free(sdi, M_DEVBUF);
498a494
> }
500,504d495
< sdi->sdi_name = name;
< sdi->sdi_node = node;
< OF_getprop_alloc(node, "compatible", 1, (void **)&sdi->sdi_compat);
< OF_getprop_alloc(node, "device_type", 1, (void **)&sdi->sdi_type);
< OF_getprop_alloc(node, "model", 1, (void **)&sdi->sdi_model);
508,511c499,503
< if (sdi->sdi_type == NULL ||
< strcmp(sdi->sdi_type, "hierarchical") != 0) {
< sbus_destroy_dinfo(sdi);
< return (NULL);
---
> if (sdi->sdi_obdinfo.obd_type == NULL ||
> strcmp(sdi->sdi_obdinfo.obd_type, "hierarchical") != 0) {
> device_printf(dev, "<%s>: incomplete\n",
> sdi->sdi_obdinfo.obd_name);
> goto fail;
521,522c513,518
< if (slot != -1 && slot != rslot)
< panic("%s: multiple slots", __func__);
---
> if (slot != -1 && slot != rslot) {
> device_printf(dev, "<%s>: multiple slots\n",
> sdi->sdi_obdinfo.obd_name);
> free(reg, M_OFWPROP);
> goto fail;
> }
562a559,562
>
> fail:
> sbus_destroy_dinfo(sdi);
> return (NULL);
565d564
< /* Free everything except sdi_name, which is handled separately. */
571,576c570
< if (dinfo->sdi_compat != NULL)
< free(dinfo->sdi_compat, M_OFWPROP);
< if (dinfo->sdi_model != NULL)
< free(dinfo->sdi_model, M_OFWPROP);
< if (dinfo->sdi_type != NULL)
< free(dinfo->sdi_type, M_OFWPROP);
---
> ofw_bus_gen_destroy_devinfo(&dinfo->sdi_obdinfo);
583,584d576
< struct sbus_devinfo *dinfo;
< struct resource_list *rl;
587,588d578
< dinfo = device_get_ivars(child);
< rl = &dinfo->sdi_rl;
590,591c580
< rv += resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx");
< rv += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
---
> rv += sbus_print_res(device_get_ivars(child));
599,600c588
< struct sbus_devinfo *dinfo;
< struct resource_list *rl;
---
> const char *type;
602,606c590,592
< dinfo = device_get_ivars(child);
< rl = &dinfo->sdi_rl;
< device_printf(dev, "<%s>", dinfo->sdi_name);
< resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx");
< resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
---
> device_printf(dev, "<%s>", ofw_bus_get_name(child));
> sbus_print_res(device_get_ivars(child));
> type = ofw_bus_get_type(child);
608c594
< dinfo->sdi_type != NULL ? dinfo->sdi_type : "unknown");
---
> type != NULL ? type : "unknown");
735,736c721,722
< sbus_teardown_intr(device_t dev, device_t child,
< struct resource *vec, void *cookie)
---
> sbus_teardown_intr(device_t dev, device_t child, struct resource *vec,
> void *cookie)
887a874,882
> static const struct ofw_bus_devinfo *
> sbus_get_devinfo(device_t bus, device_t child)
> {
> struct sbus_devinfo *sdi;
>
> sdi = device_get_ivars(child);
> return (&sdi->sdi_obdinfo);
> }
>
929,930c924,925
< static const char *
< sbus_get_compat(device_t bus, device_t dev)
---
> static int
> sbus_print_res(struct sbus_devinfo *sdi)
932c927
< struct sbus_devinfo *dinfo;
---
> int rv;
934,935c929,934
< dinfo = device_get_ivars(dev);
< return (dinfo->sdi_compat);
---
> rv = 0;
> rv += resource_list_print_type(&sdi->sdi_rl, "mem", SYS_RES_MEMORY,
> "%#lx");
> rv += resource_list_print_type(&sdi->sdi_rl, "irq", SYS_RES_IRQ,
> "%ld");
> return (rv);
937,972d935
<
< static const char *
< sbus_get_model(device_t bus, device_t dev)
< {
< struct sbus_devinfo *dinfo;
<
< dinfo = device_get_ivars(dev);
< return (dinfo->sdi_model);
< }
<
< static const char *
< sbus_get_name(device_t bus, device_t dev)
< {
< struct sbus_devinfo *dinfo;
<
< dinfo = device_get_ivars(dev);
< return (dinfo->sdi_name);
< }
<
< static phandle_t
< sbus_get_node(device_t bus, device_t dev)
< {
< struct sbus_devinfo *dinfo;
<
< dinfo = device_get_ivars(dev);
< return (dinfo->sdi_node);
< }
<
< static const char *
< sbus_get_type(device_t bus, device_t dev)
< {
< struct sbus_devinfo *dinfo;
<
< dinfo = device_get_ivars(dev);
< return (dinfo->sdi_type);
< }
< __FBSDID("$FreeBSD: head/sys/sparc64/sbus/sbus.c 146391 2005-05-19 14:47:31Z marius $");
---
> __FBSDID("$FreeBSD: head/sys/sparc64/sbus/sbus.c 152684 2005-11-22 16:39:44Z marius $");
116a117
> #include <dev/ofw/ofw_bus_subr.h>
139,142d139
< char *sdi_compat; /* PROM compatible */
< char *sdi_model; /* PROM model */
< char *sdi_name; /* PROM name */
< phandle_t sdi_node; /* PROM node */
144d140
< char *sdi_type; /* PROM device_type */
145a142
> struct ofw_bus_devinfo sdi_obdinfo;
209,213c206
< static ofw_bus_get_compat_t sbus_get_compat;
< static ofw_bus_get_model_t sbus_get_model;
< static ofw_bus_get_name_t sbus_get_name;
< static ofw_bus_get_node_t sbus_get_node;
< static ofw_bus_get_type_t sbus_get_type;
---
> static ofw_bus_get_devinfo_t sbus_get_devinfo;
216,218c209,211
< static struct sbus_devinfo * sbus_setup_dinfo(struct sbus_softc *sc,
< phandle_t node, char *name);
< static void sbus_destroy_dinfo(struct sbus_devinfo *dinfo);
---
> static struct sbus_devinfo * sbus_setup_dinfo(device_t, struct sbus_softc *,
> phandle_t);
> static void sbus_destroy_dinfo(struct sbus_devinfo *);
222a216
> static int sbus_print_res(struct sbus_devinfo *);
243,247c237,242
< DEVMETHOD(ofw_bus_get_compat, sbus_get_compat),
< DEVMETHOD(ofw_bus_get_model, sbus_get_model),
< DEVMETHOD(ofw_bus_get_name, sbus_get_name),
< DEVMETHOD(ofw_bus_get_node, sbus_get_node),
< DEVMETHOD(ofw_bus_get_type, sbus_get_type),
---
> DEVMETHOD(ofw_bus_get_devinfo, sbus_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),
308c303
< char *name, *cname;
---
> char *name;
459c454
< if ((OF_getprop_alloc(child, "name", 1, (void **)&cname)) == -1)
---
> if ((sdi = sbus_setup_dinfo(dev, sc, child)) == NULL)
461,466d455
<
< if ((sdi = sbus_setup_dinfo(sc, child, cname)) == NULL) {
< device_printf(dev, "<%s>: incomplete\n", cname);
< free(cname, M_OFWPROP);
< continue;
< }
479,482c468,476
< sbus_inlist(cname, sbus_order_first)) ? SBUS_ORDER_FIRST :
< SBUS_ORDER_NORMAL, NULL, -1);
< if (cdev == NULL)
< panic("%s: device_add_child_ordered failed", __func__);
---
> sbus_inlist(sdi->sdi_obdinfo.obd_name, sbus_order_first)) ?
> SBUS_ORDER_FIRST : SBUS_ORDER_NORMAL, NULL, -1);
> if (cdev == NULL) {
> device_printf(dev,
> "<%s>: device_add_child_ordered failed\n",
> sdi->sdi_obdinfo.obd_name);
> sbus_destroy_dinfo(sdi);
> continue;
> }
489c483
< sbus_setup_dinfo(struct sbus_softc *sc, phandle_t node, char *name)
---
> sbus_setup_dinfo(device_t dev, struct sbus_softc *sc, phandle_t node)
497c491,492
< if (sdi == NULL)
---
> if (ofw_bus_gen_setup_devinfo(&sdi->sdi_obdinfo, node) != 0) {
> free(sdi, M_DEVBUF);
498a494
> }
500,504d495
< sdi->sdi_name = name;
< sdi->sdi_node = node;
< OF_getprop_alloc(node, "compatible", 1, (void **)&sdi->sdi_compat);
< OF_getprop_alloc(node, "device_type", 1, (void **)&sdi->sdi_type);
< OF_getprop_alloc(node, "model", 1, (void **)&sdi->sdi_model);
508,511c499,503
< if (sdi->sdi_type == NULL ||
< strcmp(sdi->sdi_type, "hierarchical") != 0) {
< sbus_destroy_dinfo(sdi);
< return (NULL);
---
> if (sdi->sdi_obdinfo.obd_type == NULL ||
> strcmp(sdi->sdi_obdinfo.obd_type, "hierarchical") != 0) {
> device_printf(dev, "<%s>: incomplete\n",
> sdi->sdi_obdinfo.obd_name);
> goto fail;
521,522c513,518
< if (slot != -1 && slot != rslot)
< panic("%s: multiple slots", __func__);
---
> if (slot != -1 && slot != rslot) {
> device_printf(dev, "<%s>: multiple slots\n",
> sdi->sdi_obdinfo.obd_name);
> free(reg, M_OFWPROP);
> goto fail;
> }
562a559,562
>
> fail:
> sbus_destroy_dinfo(sdi);
> return (NULL);
565d564
< /* Free everything except sdi_name, which is handled separately. */
571,576c570
< if (dinfo->sdi_compat != NULL)
< free(dinfo->sdi_compat, M_OFWPROP);
< if (dinfo->sdi_model != NULL)
< free(dinfo->sdi_model, M_OFWPROP);
< if (dinfo->sdi_type != NULL)
< free(dinfo->sdi_type, M_OFWPROP);
---
> ofw_bus_gen_destroy_devinfo(&dinfo->sdi_obdinfo);
583,584d576
< struct sbus_devinfo *dinfo;
< struct resource_list *rl;
587,588d578
< dinfo = device_get_ivars(child);
< rl = &dinfo->sdi_rl;
590,591c580
< rv += resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx");
< rv += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
---
> rv += sbus_print_res(device_get_ivars(child));
599,600c588
< struct sbus_devinfo *dinfo;
< struct resource_list *rl;
---
> const char *type;
602,606c590,592
< dinfo = device_get_ivars(child);
< rl = &dinfo->sdi_rl;
< device_printf(dev, "<%s>", dinfo->sdi_name);
< resource_list_print_type(rl, "mem", SYS_RES_MEMORY, "%#lx");
< resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
---
> device_printf(dev, "<%s>", ofw_bus_get_name(child));
> sbus_print_res(device_get_ivars(child));
> type = ofw_bus_get_type(child);
608c594
< dinfo->sdi_type != NULL ? dinfo->sdi_type : "unknown");
---
> type != NULL ? type : "unknown");
735,736c721,722
< sbus_teardown_intr(device_t dev, device_t child,
< struct resource *vec, void *cookie)
---
> sbus_teardown_intr(device_t dev, device_t child, struct resource *vec,
> void *cookie)
887a874,882
> static const struct ofw_bus_devinfo *
> sbus_get_devinfo(device_t bus, device_t child)
> {
> struct sbus_devinfo *sdi;
>
> sdi = device_get_ivars(child);
> return (&sdi->sdi_obdinfo);
> }
>
929,930c924,925
< static const char *
< sbus_get_compat(device_t bus, device_t dev)
---
> static int
> sbus_print_res(struct sbus_devinfo *sdi)
932c927
< struct sbus_devinfo *dinfo;
---
> int rv;
934,935c929,934
< dinfo = device_get_ivars(dev);
< return (dinfo->sdi_compat);
---
> rv = 0;
> rv += resource_list_print_type(&sdi->sdi_rl, "mem", SYS_RES_MEMORY,
> "%#lx");
> rv += resource_list_print_type(&sdi->sdi_rl, "irq", SYS_RES_IRQ,
> "%ld");
> return (rv);
937,972d935
<
< static const char *
< sbus_get_model(device_t bus, device_t dev)
< {
< struct sbus_devinfo *dinfo;
<
< dinfo = device_get_ivars(dev);
< return (dinfo->sdi_model);
< }
<
< static const char *
< sbus_get_name(device_t bus, device_t dev)
< {
< struct sbus_devinfo *dinfo;
<
< dinfo = device_get_ivars(dev);
< return (dinfo->sdi_name);
< }
<
< static phandle_t
< sbus_get_node(device_t bus, device_t dev)
< {
< struct sbus_devinfo *dinfo;
<
< dinfo = device_get_ivars(dev);
< return (dinfo->sdi_node);
< }
<
< static const char *
< sbus_get_type(device_t bus, device_t dev)
< {
< struct sbus_devinfo *dinfo;
<
< dinfo = device_get_ivars(dev);
< return (dinfo->sdi_type);
< }