Re: svn commit: r304963 - in head/sys/dev/bhnd: . bcma siba

2016-08-28 Thread Adrian Chadd
Heh. Make a free function too. ;)

On Aug 28, 2016 12:34 PM, "Landon J. Fuller"  wrote:

> Author: landonf
> Date: Sun Aug 28 19:34:22 2016
> New Revision: 304963
> URL: https://svnweb.freebsd.org/changeset/base/304963
>
> Log:
>   bhnd(4): Add a bhnd bus method for fetching the device's core table.
>
>   This will allow us to perform bhndb(4) bridge configuration based on
>   the identified hardware, prior to performing full enumeration of the
>   child bhnd bus.
>
>   Approved by:  adrian (mentor, implicit)
>
> Modified:
>   head/sys/dev/bhnd/bcma/bcma.c
>   head/sys/dev/bhnd/bhnd.h
>   head/sys/dev/bhnd/bhnd_bus_if.m
>   head/sys/dev/bhnd/siba/siba.c
>
> Modified: head/sys/dev/bhnd/bcma/bcma.c
> 
> ==
> --- head/sys/dev/bhnd/bcma/bcma.c   Sun Aug 28 19:33:09 2016
> (r304962)
> +++ head/sys/dev/bhnd/bcma/bcma.c   Sun Aug 28 19:34:22 2016
> (r304963)
> @@ -492,6 +492,42 @@ bcma_free_bhnd_dinfo(device_t dev, struc
> bcma_free_dinfo(dev, (struct bcma_devinfo *)dinfo);
>  }
>
> +
> +static int
> +bcma_get_core_table(device_t dev, device_t child, struct bhnd_core_info
> **cores,
> +u_int *num_cores)
> +{
> +   struct bcma_softc   *sc;
> +   struct bcma_erom erom;
> +   const struct bhnd_chipid*cid;
> +   struct resource *r;
> +   int  error;
> +   int  rid;
> +
> +   sc = device_get_softc(dev);
> +
> +   /* Map the EROM table. */
> +   cid = BHND_BUS_GET_CHIPID(dev, dev);
> +   rid = 0;
> +   r = bus_alloc_resource(dev, SYS_RES_MEMORY, , cid->enum_addr,
> +   cid->enum_addr + BCMA_EROM_TABLE_SIZE, BCMA_EROM_TABLE_SIZE,
> +   RF_ACTIVE);
> +   if (r == NULL) {
> +   device_printf(dev, "failed to allocate EROM resource\n");
> +   return (ENXIO);
> +   }
> +
> +   /* Enumerate all declared cores */
> +   if ((error = bcma_erom_open(, r, BCMA_EROM_TABLE_START)))
> +   goto cleanup;
> +
> +   error = bcma_erom_get_core_info(, cores, num_cores);
> +
> +cleanup:
> +   bus_release_resource(dev, SYS_RES_MEMORY, rid, r);
> +   return (error);
> +}
> +
>  /**
>   * Scan a device enumeration ROM table, adding all valid discovered cores
> to
>   * the bus.
> @@ -577,6 +613,7 @@ static device_method_t bcma_methods[] =
> DEVMETHOD(bhnd_bus_find_hostb_device,   bcma_find_hostb_device),
> DEVMETHOD(bhnd_bus_alloc_devinfo,   bcma_alloc_bhnd_dinfo),
> DEVMETHOD(bhnd_bus_free_devinfo,bcma_free_bhnd_dinfo),
> +   DEVMETHOD(bhnd_bus_get_core_table,  bcma_get_core_table),
> DEVMETHOD(bhnd_bus_reset_core,  bcma_reset_core),
> DEVMETHOD(bhnd_bus_suspend_core,bcma_suspend_core),
> DEVMETHOD(bhnd_bus_read_config, bcma_read_config),
>
> Modified: head/sys/dev/bhnd/bhnd.h
> 
> ==
> --- head/sys/dev/bhnd/bhnd.hSun Aug 28 19:33:09 2016(r304962)
> +++ head/sys/dev/bhnd/bhnd.hSun Aug 28 19:34:22 2016(r304963)
> @@ -425,6 +425,32 @@ bhnd_get_chipid(device_t dev) {
>  };
>
>  /**
> + * Get a list of all cores discoverable on the bhnd bus.
> + *
> + * Enumerates all cores discoverable on @p dev, returning the list in
> + * @p cores and the count in @p num_cores.
> + *
> + * The memory allocated for the list should be freed using
> + * `free(*cores, M_BHND)`. @p cores and @p num_cores are not changed
> + * when an error is returned.
> + *
> + * @param  dev A bhnd bus child device.
> + * @param[out] cores   The table of core descriptors.
> + * @param[out] num_cores   The number of core descriptors in @p cores.
> + *
> + * @retval 0   success
> + * @retval non-zeroif an error occurs enumerating @p dev, a regular
> UNIX
> + * error code should be returned.
> + */
> +static inline int
> +bhnd_get_core_table(device_t dev, struct bhnd_core_info **cores,
> +u_int *num_cores)
> +{
> +   return (BHND_BUS_GET_CORE_TABLE(device_get_parent(dev), dev,
> cores,
> +   num_cores));
> +}
> +
> +/**
>   * If supported by the chipset, return the clock source for the given
> clock.
>   *
>   * This function is only supported on early PWRCTL-equipped chipsets
>
> Modified: head/sys/dev/bhnd/bhnd_bus_if.m
> 
> ==
> --- head/sys/dev/bhnd/bhnd_bus_if.m Sun Aug 28 19:33:09 2016
> (r304962)
> +++ head/sys/dev/bhnd/bhnd_bus_if.m Sun Aug 28 19:34:22 2016
> (r304963)
> @@ -56,6 +56,13 @@ CODE {
> panic("bhnd_bus_get_chipid unimplemented");
> }
>
> +   static int
> +   bhnd_bus_null_get_core_table(device_t dev, device_t child,
> +   struct 

svn commit: r304963 - in head/sys/dev/bhnd: . bcma siba

2016-08-28 Thread Landon J. Fuller
Author: landonf
Date: Sun Aug 28 19:34:22 2016
New Revision: 304963
URL: https://svnweb.freebsd.org/changeset/base/304963

Log:
  bhnd(4): Add a bhnd bus method for fetching the device's core table.
  
  This will allow us to perform bhndb(4) bridge configuration based on
  the identified hardware, prior to performing full enumeration of the
  child bhnd bus.
  
  Approved by:  adrian (mentor, implicit)

Modified:
  head/sys/dev/bhnd/bcma/bcma.c
  head/sys/dev/bhnd/bhnd.h
  head/sys/dev/bhnd/bhnd_bus_if.m
  head/sys/dev/bhnd/siba/siba.c

Modified: head/sys/dev/bhnd/bcma/bcma.c
==
--- head/sys/dev/bhnd/bcma/bcma.c   Sun Aug 28 19:33:09 2016
(r304962)
+++ head/sys/dev/bhnd/bcma/bcma.c   Sun Aug 28 19:34:22 2016
(r304963)
@@ -492,6 +492,42 @@ bcma_free_bhnd_dinfo(device_t dev, struc
bcma_free_dinfo(dev, (struct bcma_devinfo *)dinfo);
 }
 
+
+static int
+bcma_get_core_table(device_t dev, device_t child, struct bhnd_core_info 
**cores,
+u_int *num_cores)
+{
+   struct bcma_softc   *sc;
+   struct bcma_erom erom;
+   const struct bhnd_chipid*cid;
+   struct resource *r;
+   int  error;
+   int  rid;
+
+   sc = device_get_softc(dev);
+
+   /* Map the EROM table. */
+   cid = BHND_BUS_GET_CHIPID(dev, dev);
+   rid = 0;
+   r = bus_alloc_resource(dev, SYS_RES_MEMORY, , cid->enum_addr,
+   cid->enum_addr + BCMA_EROM_TABLE_SIZE, BCMA_EROM_TABLE_SIZE,
+   RF_ACTIVE);
+   if (r == NULL) {
+   device_printf(dev, "failed to allocate EROM resource\n");
+   return (ENXIO);
+   }
+
+   /* Enumerate all declared cores */
+   if ((error = bcma_erom_open(, r, BCMA_EROM_TABLE_START)))
+   goto cleanup;
+
+   error = bcma_erom_get_core_info(, cores, num_cores);
+
+cleanup:
+   bus_release_resource(dev, SYS_RES_MEMORY, rid, r);
+   return (error);
+}
+
 /**
  * Scan a device enumeration ROM table, adding all valid discovered cores to
  * the bus.
@@ -577,6 +613,7 @@ static device_method_t bcma_methods[] = 
DEVMETHOD(bhnd_bus_find_hostb_device,   bcma_find_hostb_device),
DEVMETHOD(bhnd_bus_alloc_devinfo,   bcma_alloc_bhnd_dinfo),
DEVMETHOD(bhnd_bus_free_devinfo,bcma_free_bhnd_dinfo),
+   DEVMETHOD(bhnd_bus_get_core_table,  bcma_get_core_table),
DEVMETHOD(bhnd_bus_reset_core,  bcma_reset_core),
DEVMETHOD(bhnd_bus_suspend_core,bcma_suspend_core),
DEVMETHOD(bhnd_bus_read_config, bcma_read_config),

Modified: head/sys/dev/bhnd/bhnd.h
==
--- head/sys/dev/bhnd/bhnd.hSun Aug 28 19:33:09 2016(r304962)
+++ head/sys/dev/bhnd/bhnd.hSun Aug 28 19:34:22 2016(r304963)
@@ -425,6 +425,32 @@ bhnd_get_chipid(device_t dev) {
 };
 
 /**
+ * Get a list of all cores discoverable on the bhnd bus.
+ *
+ * Enumerates all cores discoverable on @p dev, returning the list in
+ * @p cores and the count in @p num_cores.
+ * 
+ * The memory allocated for the list should be freed using
+ * `free(*cores, M_BHND)`. @p cores and @p num_cores are not changed
+ * when an error is returned.
+ * 
+ * @param  dev A bhnd bus child device.
+ * @param[out] cores   The table of core descriptors.
+ * @param[out] num_cores   The number of core descriptors in @p cores.
+ * 
+ * @retval 0   success
+ * @retval non-zeroif an error occurs enumerating @p dev, a regular UNIX
+ * error code should be returned.
+ */
+static inline int
+bhnd_get_core_table(device_t dev, struct bhnd_core_info **cores,
+u_int *num_cores)
+{
+   return (BHND_BUS_GET_CORE_TABLE(device_get_parent(dev), dev, cores,
+   num_cores));
+}
+
+/**
  * If supported by the chipset, return the clock source for the given clock.
  *
  * This function is only supported on early PWRCTL-equipped chipsets

Modified: head/sys/dev/bhnd/bhnd_bus_if.m
==
--- head/sys/dev/bhnd/bhnd_bus_if.m Sun Aug 28 19:33:09 2016
(r304962)
+++ head/sys/dev/bhnd/bhnd_bus_if.m Sun Aug 28 19:34:22 2016
(r304963)
@@ -56,6 +56,13 @@ CODE {
panic("bhnd_bus_get_chipid unimplemented");
}
 
+   static int
+   bhnd_bus_null_get_core_table(device_t dev, device_t child,
+   struct bhnd_core_info **cores, u_int *num_cores)
+   {
+   panic("bhnd_bus_get_core_table unimplemented");
+   }
+
static bhnd_attach_type
bhnd_bus_null_get_attach_type(device_t dev, device_t child)
{
@@ -271,6 +278,32 @@ METHOD const struct bhnd_chipid * get_ch
 } DEFAULT bhnd_bus_null_get_chipid;