From owner-svn-src-head@freebsd.org Mon May 23 03:47:46 2016 Return-Path: Delivered-To: svn-src-head@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 14CD9B46828; Mon, 23 May 2016 03:47:46 +0000 (UTC) (envelope-from adrian@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 E53E71159; Mon, 23 May 2016 03:47:45 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4N3ljng050020; Mon, 23 May 2016 03:47:45 GMT (envelope-from adrian@FreeBSD.org) Received: (from adrian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4N3lihA050009; Mon, 23 May 2016 03:47:44 GMT (envelope-from adrian@FreeBSD.org) Message-Id: <201605230347.u4N3lihA050009@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: adrian set sender to adrian@FreeBSD.org using -f From: Adrian Chadd Date: Mon, 23 May 2016 03:47:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300445 - in head/sys: conf dev/bhnd dev/bhnd/bcma dev/bhnd/bhndb dev/bhnd/siba dev/bhnd/soc modules/bhnd/bhndb X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 May 2016 03:47:46 -0000 Author: adrian Date: Mon May 23 03:47:44 2016 New Revision: 300445 URL: https://svnweb.freebsd.org/changeset/base/300445 Log: [bhnd] Add support for querying the attachment type of the bhnd bus. This adds a BHND_BUS_GET_ATTACH_TYPE(); the primary use-case is to let chipc make a coarse-grained determination as to whether UART, SPI, etc drivers ought to be attached, and on fullmac devices, whether a real CPU driver ought to be skipped for the ARM core, etc. Tested: * BCM4331 (BHND) * BCM4312 (SIBA) Submitted by: Landon Fuller Differential Revision: https://reviews.freebsd.org/D6492 Added: head/sys/dev/bhnd/bhndb/bhnd_bhndb.c (contents, props changed) Modified: head/sys/conf/files head/sys/dev/bhnd/bcma/bcma_bhndb.c head/sys/dev/bhnd/bhnd.h head/sys/dev/bhnd/bhnd_bus_if.m head/sys/dev/bhnd/bhnd_types.h head/sys/dev/bhnd/bhndb/bhndb.h head/sys/dev/bhnd/siba/siba_bhndb.c head/sys/dev/bhnd/soc/bhnd_soc.c head/sys/modules/bhnd/bhndb/Makefile Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Mon May 23 03:46:36 2016 (r300444) +++ head/sys/conf/files Mon May 23 03:47:44 2016 (r300445) @@ -1125,6 +1125,7 @@ dev/bge/if_bge.c optional bge dev/bhnd/bhnd.c optional bhndbus | bhnd dev/bhnd/bhnd_subr.c optional bhndbus | bhnd dev/bhnd/bhnd_bus_if.m optional bhndbus | bhnd +dev/bhnd/bhndb/bhnd_bhndb.c optional bhndbus | bhndb dev/bhnd/bhndb/bhndb.c optional bhndbus | bhndb dev/bhnd/bhndb/bhndb_bus_if.m optional bhndbus | bhndb dev/bhnd/bhndb/bhndb_hwdata.c optional bhndbus | bhndb Modified: head/sys/dev/bhnd/bcma/bcma_bhndb.c ============================================================================== --- head/sys/dev/bhnd/bcma/bcma_bhndb.c Mon May 23 03:46:36 2016 (r300444) +++ head/sys/dev/bhnd/bcma/bcma_bhndb.c Mon May 23 03:47:44 2016 (r300445) @@ -166,20 +166,6 @@ bcma_bhndb_resume_child(device_t dev, de return (0); } -static int -bcma_bhndb_read_board_info(device_t dev, device_t child, - struct bhnd_board_info *info) -{ - int error; - - /* Initialize with NVRAM-derived values */ - if ((error = bhnd_bus_generic_read_board_info(dev, child, info))) - return (error); - - /* Let the bridge fill in any additional data */ - return (BHNDB_POPULATE_BOARD_INFO(device_get_parent(dev), dev, info)); -} - static device_method_t bcma_bhndb_methods[] = { /* Device interface */ DEVMETHOD(device_probe, bcma_bhndb_probe), @@ -189,14 +175,11 @@ static device_method_t bcma_bhndb_method DEVMETHOD(bus_suspend_child, bcma_bhndb_suspend_child), DEVMETHOD(bus_resume_child, bcma_bhndb_resume_child), - /* BHND interface */ - DEVMETHOD(bhnd_bus_read_board_info, bcma_bhndb_read_board_info), - DEVMETHOD_END }; -DEFINE_CLASS_1(bhnd, bcma_bhndb_driver, bcma_bhndb_methods, - sizeof(struct bcma_softc), bcma_driver); +DEFINE_CLASS_2(bhnd, bcma_bhndb_driver, bcma_bhndb_methods, + sizeof(struct bcma_softc), bhnd_bhndb_driver, bcma_driver); DRIVER_MODULE(bcma_bhndb, bhndb, bcma_bhndb_driver, bhnd_devclass, NULL, NULL); Modified: head/sys/dev/bhnd/bhnd.h ============================================================================== --- head/sys/dev/bhnd/bhnd.h Mon May 23 03:46:36 2016 (r300444) +++ head/sys/dev/bhnd/bhnd.h Mon May 23 03:47:44 2016 (r300445) @@ -561,6 +561,21 @@ bhnd_get_chipid(device_t dev) { }; /** + * Return the BHND attachment type of the parent bhnd bus. + * + * @param dev A bhnd bus child device. + * + * @retval BHND_ATTACH_ADAPTER if the bus is resident on a bridged adapter, + * such as a WiFi chipset. + * @retval BHND_ATTACH_NATIVE if the bus provides hardware services (clock, + * CPU, etc) to a directly attached native host. + */ +static inline bhnd_attach_type +bhnd_get_attach_type (device_t dev) { + return (BHND_BUS_GET_ATTACH_TYPE(device_get_parent(dev), dev)); +} + +/** * Attempt to read the BHND board identification from the bhnd bus. * * This relies on NVRAM access, and will fail if a valid NVRAM device cannot Modified: head/sys/dev/bhnd/bhnd_bus_if.m ============================================================================== --- head/sys/dev/bhnd/bhnd_bus_if.m Mon May 23 03:46:36 2016 (r300444) +++ head/sys/dev/bhnd/bhnd_bus_if.m Mon May 23 03:47:44 2016 (r300445) @@ -55,6 +55,12 @@ CODE { panic("bhnd_bus_get_chipid unimplemented"); } + static bhnd_attach_type + bhnd_bus_null_get_attach_type(device_t dev, device_t child) + { + panic("bhnd_bus_get_attach_type unimplemented"); + } + static int bhnd_bus_null_read_board_info(device_t dev, device_t child, struct bhnd_board_info *info) @@ -184,6 +190,22 @@ METHOD const struct bhnd_chipid * get_ch } DEFAULT bhnd_bus_null_get_chipid; /** + * Return the BHND attachment type of the parent bus. + * + * @param dev The device whose child is being examined. + * @param child The child device. + * + * @retval BHND_ATTACH_ADAPTER if the bus is resident on a bridged adapter, + * such as a WiFi chipset. + * @retval BHND_ATTACH_NATIVE if the bus provides hardware services (clock, + * CPU, etc) to a directly attached native host. + */ +METHOD bhnd_attach_type get_attach_type { + device_t dev; + device_t child; +} DEFAULT bhnd_bus_null_get_attach_type; + +/** * Attempt to read the BHND board identification from the parent bus. * * This relies on NVRAM access, and will fail if a valid NVRAM device cannot Modified: head/sys/dev/bhnd/bhnd_types.h ============================================================================== --- head/sys/dev/bhnd/bhnd_types.h Mon May 23 03:46:36 2016 (r300444) +++ head/sys/dev/bhnd/bhnd_types.h Mon May 23 03:47:44 2016 (r300445) @@ -73,6 +73,15 @@ typedef enum { BHND_PORT_AGENT = 2, /**< interconnect agent/wrapper */ } bhnd_port_type; +/** + * bhnd(4) attachment types. + */ +typedef enum { + BHND_ATTACH_ADAPTER = 0, /**< A bridged card, such as a PCI WiFi chipset */ + BHND_ATTACH_NATIVE = 1 /**< A bus resident on the native host, such as + * the primary or secondary bus of an embedded + * SoC */ +} bhnd_attach_type; /** Evaluates to true if @p cls is a device class that can be configured * as a host bridge device. */ Added: head/sys/dev/bhnd/bhndb/bhnd_bhndb.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/bhnd/bhndb/bhnd_bhndb.c Mon May 23 03:47:44 2016 (r300445) @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2015-2016 Landon Fuller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any + * redistribution must be conditioned upon including a substantially + * similar Disclaimer requirement for further binary redistribution. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGES. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include +#include + +#include "bhndbvar.h" + +/* + * bhnd(4) driver mix-in providing a shared common methods for + * bhnd devices attached via a bhndb bridge. + */ + +static int +bhnd_bhndb_read_board_info(device_t dev, device_t child, + struct bhnd_board_info *info) +{ + int error; + + /* Initialize with NVRAM-derived values */ + if ((error = bhnd_bus_generic_read_board_info(dev, child, info))) + return (error); + + /* Let the bridge fill in any additional data */ + return (BHNDB_POPULATE_BOARD_INFO(device_get_parent(dev), dev, info)); +} + +static bhnd_attach_type +bhnd_bhndb_get_attach_type(device_t dev, device_t child) +{ + /* It's safe to assume that a bridged device is always an adapter */ + return (BHND_ATTACH_ADAPTER); +} + +static device_method_t bhnd_bhndb_methods[] = { + /* BHND interface */ + DEVMETHOD(bhnd_bus_get_attach_type, bhnd_bhndb_get_attach_type), + DEVMETHOD(bhnd_bus_read_board_info, bhnd_bhndb_read_board_info), + + DEVMETHOD_END +}; + +DEFINE_CLASS_0(bhnd, bhnd_bhndb_driver, bhnd_bhndb_methods, 0); Modified: head/sys/dev/bhnd/bhndb/bhndb.h ============================================================================== --- head/sys/dev/bhnd/bhndb/bhndb.h Mon May 23 03:46:36 2016 (r300444) +++ head/sys/dev/bhnd/bhndb/bhndb.h Mon May 23 03:47:44 2016 (r300445) @@ -44,6 +44,7 @@ #include "bhndb_bus_if.h" extern devclass_t bhndb_devclass; +DECLARE_CLASS(bhnd_bhndb_driver); int bhndb_attach_bridge(device_t parent, device_t *bhndb, int unit); Modified: head/sys/dev/bhnd/siba/siba_bhndb.c ============================================================================== --- head/sys/dev/bhnd/siba/siba_bhndb.c Mon May 23 03:46:36 2016 (r300444) +++ head/sys/dev/bhnd/siba/siba_bhndb.c Mon May 23 03:47:44 2016 (r300445) @@ -205,20 +205,6 @@ siba_bhndb_resume_child(device_t dev, de return (0); } -static int -siba_bhndb_read_board_info(device_t dev, device_t child, - struct bhnd_board_info *info) -{ - int error; - - /* Initialize with NVRAM-derived values */ - if ((error = bhnd_bus_generic_read_board_info(dev, child, info))) - return (error); - - /* Let the bridge fill in any additional data */ - return (BHNDB_POPULATE_BOARD_INFO(device_get_parent(dev), dev, info)); -} - /* Work-around implementation for SIBA_QUIRK_PCIE_D11_SB_TIMEOUT */ static int siba_bhndb_wars_pcie_clear_d11_timeout(struct siba_softc *sc) @@ -285,14 +271,11 @@ static device_method_t siba_bhndb_method DEVMETHOD(bus_suspend_child, siba_bhndb_suspend_child), DEVMETHOD(bus_resume_child, siba_bhndb_resume_child), - /* BHND interface */ - DEVMETHOD(bhnd_bus_read_board_info, siba_bhndb_read_board_info), - DEVMETHOD_END }; -DEFINE_CLASS_1(bhnd, siba_bhndb_driver, siba_bhndb_methods, - sizeof(struct siba_softc), siba_driver); +DEFINE_CLASS_2(bhnd, siba_bhndb_driver, siba_bhndb_methods, + sizeof(struct siba_softc), bhnd_bhndb_driver, siba_driver); DRIVER_MODULE(siba_bhndb, bhndb, siba_bhndb_driver, bhnd_devclass, NULL, NULL); Modified: head/sys/dev/bhnd/soc/bhnd_soc.c ============================================================================== --- head/sys/dev/bhnd/soc/bhnd_soc.c Mon May 23 03:46:36 2016 (r300444) +++ head/sys/dev/bhnd/soc/bhnd_soc.c Mon May 23 03:47:44 2016 (r300445) @@ -216,6 +216,12 @@ bhnd_soc_is_hw_disabled(device_t dev, de return false; } +static int +bhnd_soc_get_attach_type(device_t dev, device_t child) +{ + return (BHND_ATTACH_NATIVE); +} + /* * **************************** DRIVER METADATA **************************** */ @@ -247,6 +253,7 @@ static device_method_t bhnd_soc_methods[ DEVMETHOD(bhnd_bus_activate_resource, bhnd_soc_activate_resource), DEVMETHOD(bhnd_bus_is_hw_disabled, bhnd_soc_is_hw_disabled), DEVMETHOD(bhnd_bus_get_chipid, bhnd_soc_get_chipid), + DEVMETHOD(bhnd_bus_get_attach_type, bhnd_soc_get_attach_type), DEVMETHOD_END }; Modified: head/sys/modules/bhnd/bhndb/Makefile ============================================================================== --- head/sys/modules/bhnd/bhndb/Makefile Mon May 23 03:46:36 2016 (r300444) +++ head/sys/modules/bhnd/bhndb/Makefile Mon May 23 03:47:44 2016 (r300445) @@ -4,6 +4,7 @@ KMOD= bhndb SRCS= bhndb.c bhndb_subr.c bhndb_hwdata.c \ + bhnd_bhndb.c \ bhndb_bus_if.c bhndb_bus_if.h \ bhndb_if.c bhndb_if.h SRCS+= bhnd_bus_if.h \