From owner-svn-src-all@freebsd.org Sat Aug 27 00:07:50 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 616E6B7698B; Sat, 27 Aug 2016 00:07:50 +0000 (UTC) (envelope-from landonf@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 39938A40; Sat, 27 Aug 2016 00:07:50 +0000 (UTC) (envelope-from landonf@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7R07nGe063297; Sat, 27 Aug 2016 00:07:49 GMT (envelope-from landonf@FreeBSD.org) Received: (from landonf@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7R07mbT063291; Sat, 27 Aug 2016 00:07:48 GMT (envelope-from landonf@FreeBSD.org) Message-Id: <201608270007.u7R07mbT063291@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: landonf set sender to landonf@FreeBSD.org using -f From: "Landon J. Fuller" Date: Sat, 27 Aug 2016 00:07:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r304872 - in head/sys/dev/bhnd: . bcma siba X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Aug 2016 00:07:50 -0000 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); }