svn commit: r304872 - in head/sys/dev/bhnd: . bcma siba
Landon J. Fuller
landonf at FreeBSD.org
Sat Aug 27 00:07:50 UTC 2016
Author: landonf
Date: Sat Aug 27 00:07:48 2016
New Revision: 304872
URL: https://svnweb.freebsd.org/changeset/base/304872
Log:
bhnd(4): Include the chip model (e.g. BCM4xxx) in bhnd(4) bus's device
descriptions.
Reviewed by: mizhka
Approved by: adrian (mentor)
Differential Revision: https://reviews.freebsd.org/D7570
Modified:
head/sys/dev/bhnd/bcma/bcma_bhndb.c
head/sys/dev/bhnd/bcma/bcma_nexus.c
head/sys/dev/bhnd/bhnd.h
head/sys/dev/bhnd/bhnd_subr.c
head/sys/dev/bhnd/siba/siba_bhndb.c
head/sys/dev/bhnd/siba/siba_nexus.c
Modified: head/sys/dev/bhnd/bcma/bcma_bhndb.c
==============================================================================
--- head/sys/dev/bhnd/bcma/bcma_bhndb.c Sat Aug 27 00:06:20 2016 (r304871)
+++ head/sys/dev/bhnd/bcma/bcma_bhndb.c Sat Aug 27 00:07:48 2016 (r304872)
@@ -51,15 +51,22 @@ __FBSDID("$FreeBSD$");
static int
bcma_bhndb_probe(device_t dev)
{
- const struct bhnd_chipid *cid;
+ const struct bhnd_chipid *cid;
+ int error;
+
+ /* Defer to default probe implementation */
+ if ((error = bcma_probe(dev)) > 0)
+ return (error);
/* Check bus type */
cid = BHNDB_GET_CHIPID(device_get_parent(dev), dev);
if (cid->chip_type != BHND_CHIPTYPE_BCMA)
return (ENXIO);
- /* Delegate to default probe implementation */
- return (bcma_probe(dev));
+ /* Set device description */
+ bhnd_set_default_bus_desc(dev, cid);
+
+ return (error);
}
static int
Modified: head/sys/dev/bhnd/bcma/bcma_nexus.c
==============================================================================
--- head/sys/dev/bhnd/bcma/bcma_nexus.c Sat Aug 27 00:06:20 2016 (r304871)
+++ head/sys/dev/bhnd/bcma/bcma_nexus.c Sat Aug 27 00:07:48 2016 (r304872)
@@ -82,6 +82,9 @@ bcma_nexus_probe(device_t dev)
return (error);
}
+ /* Set device description */
+ bhnd_set_default_bus_desc(dev, &sc->bcma_cid);
+
return (0);
}
Modified: head/sys/dev/bhnd/bhnd.h
==============================================================================
--- head/sys/dev/bhnd/bhnd.h Sat Aug 27 00:06:20 2016 (r304871)
+++ head/sys/dev/bhnd/bhnd.h Sat Aug 27 00:07:48 2016 (r304872)
@@ -49,6 +49,9 @@ extern devclass_t bhnd_devclass;
extern devclass_t bhnd_hostb_devclass;
extern devclass_t bhnd_nvram_devclass;
+#define BHND_CHIPID_MAX_NAMELEN 32 /**< maximum buffer required for a
+ bhnd_format_chip_id() */
+
/**
* bhnd child instance variables
*/
@@ -254,6 +257,8 @@ bhnd_devclass_t bhnd_find_core_class(
const char *bhnd_core_name(const struct bhnd_core_info *ci);
bhnd_devclass_t bhnd_core_class(const struct bhnd_core_info *ci);
+int bhnd_format_chip_id(char *buffer, size_t size,
+ uint16_t chip_id);
device_t bhnd_match_child(device_t dev,
const struct bhnd_core_match *desc);
@@ -321,6 +326,9 @@ void bhnd_set_custom_core_desc(devic
const char *name);
void bhnd_set_default_core_desc(device_t dev);
+void bhnd_set_default_bus_desc(device_t dev,
+ const struct bhnd_chipid *chip_id);
+
int bhnd_nvram_getvar_str(device_t dev,
const char *name, char *buf, size_t len,
size_t *rlen);
Modified: head/sys/dev/bhnd/bhnd_subr.c
==============================================================================
--- head/sys/dev/bhnd/bhnd_subr.c Sat Aug 27 00:06:20 2016 (r304871)
+++ head/sys/dev/bhnd/bhnd_subr.c Sat Aug 27 00:07:48 2016 (r304872)
@@ -288,6 +288,30 @@ bhnd_core_class(const struct bhnd_core_i
}
/**
+ * Write a human readable name representation of the given
+ * BHND_CHIPID_* constant to @p buffer.
+ *
+ * @param buffer Output buffer, or NULL to compute the required size.
+ * @param size Capacity of @p buffer, in bytes.
+ * @param chip_id Chip ID to be formatted.
+ *
+ * @return Returns the required number of bytes on success, or a negative
+ * integer on failure. No more than @p size-1 characters be written, with
+ * the @p size'th set to '\0'.
+ *
+ * @sa BHND_CHIPID_MAX_NAMELEN
+ */
+int
+bhnd_format_chip_id(char *buffer, size_t size, uint16_t chip_id)
+{
+ /* All hex formatted IDs are within the range of 0x4000-0x9C3F (40000-1) */
+ if (chip_id >= 0x4000 && chip_id <= 0x9C3F)
+ return (snprintf(buffer, size, "BCM%hX", chip_id));
+ else
+ return (snprintf(buffer, size, "BCM%hu", chip_id));
+}
+
+/**
* Initialize a core info record with data from from a bhnd-attached @p dev.
*
* @param dev A bhnd device.
@@ -1232,6 +1256,52 @@ bhnd_set_default_core_desc(device_t dev)
bhnd_set_custom_core_desc(dev, bhnd_get_device_name(dev));
}
+
+/**
+ * Using the bhnd @p chip_id, populate the bhnd(4) bus @p dev's device
+ * description.
+ *
+ * @param dev A bhnd-bus attached device.
+ */
+void
+bhnd_set_default_bus_desc(device_t dev, const struct bhnd_chipid *chip_id)
+{
+ const char *bus_name;
+ char *desc;
+ char chip_name[BHND_CHIPID_MAX_NAMELEN];
+
+ /* Determine chip type's bus name */
+ switch (chip_id->chip_type) {
+ case BHND_CHIPTYPE_SIBA:
+ bus_name = "SIBA bus";
+ break;
+ case BHND_CHIPTYPE_BCMA:
+ case BHND_CHIPTYPE_BCMA_ALT:
+ bus_name = "BCMA bus";
+ break;
+ case BHND_CHIPTYPE_UBUS:
+ bus_name = "UBUS bus";
+ break;
+ default:
+ bus_name = "Unknown Type";
+ break;
+ }
+
+ /* Format chip name */
+ bhnd_format_chip_id(chip_name, sizeof(chip_name),
+ chip_id->chip_id);
+
+ /* Format and set device description */
+ asprintf(&desc, M_BHND, "%s %s", chip_name, bus_name);
+ if (desc != NULL) {
+ device_set_desc_copy(dev, desc);
+ free(desc, M_BHND);
+ } else {
+ device_set_desc(dev, bus_name);
+ }
+
+}
+
/**
* Helper function for implementing BHND_BUS_IS_HW_DISABLED().
*
Modified: head/sys/dev/bhnd/siba/siba_bhndb.c
==============================================================================
--- head/sys/dev/bhnd/siba/siba_bhndb.c Sat Aug 27 00:06:20 2016 (r304871)
+++ head/sys/dev/bhnd/siba/siba_bhndb.c Sat Aug 27 00:07:48 2016 (r304872)
@@ -80,15 +80,22 @@ static struct bhnd_device bridge_devs[]
static int
siba_bhndb_probe(device_t dev)
{
- const struct bhnd_chipid *cid;
+ const struct bhnd_chipid *cid;
+ int error;
+
+ /* Defer to default probe implementation */
+ if ((error = siba_probe(dev)) > 0)
+ return (error);
/* Check bus type */
cid = BHNDB_GET_CHIPID(device_get_parent(dev), dev);
if (cid->chip_type != BHND_CHIPTYPE_SIBA)
return (ENXIO);
- /* Delegate to default probe implementation */
- return (siba_probe(dev));
+ /* Set device description */
+ bhnd_set_default_bus_desc(dev, cid);
+
+ return (error);
}
static int
Modified: head/sys/dev/bhnd/siba/siba_nexus.c
==============================================================================
--- head/sys/dev/bhnd/siba/siba_nexus.c Sat Aug 27 00:06:20 2016 (r304871)
+++ head/sys/dev/bhnd/siba/siba_nexus.c Sat Aug 27 00:07:48 2016 (r304872)
@@ -75,6 +75,9 @@ siba_nexus_probe(device_t dev)
return (error);
}
+ /* Set device description */
+ bhnd_set_default_bus_desc(dev, &sc->siba_cid);
+
return (0);
}
More information about the svn-src-head
mailing list