Author: landonf
Date: Sat Aug 27 00:58:21 2016
New Revision: 304876
URL: https://svnweb.freebsd.org/changeset/base/304876

Log:
  Implement siba(4) support for bhnd_(read|write)_config.
  
  This provides access to the siba(4) bus-mapped per-core cfg0 register
  block.
  
  Approved by:  adrian (mentor, implicit)

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

Modified: head/sys/dev/bhnd/bhnd_bus_if.m
==============================================================================
--- head/sys/dev/bhnd/bhnd_bus_if.m     Sat Aug 27 00:56:37 2016        
(r304875)
+++ head/sys/dev/bhnd/bhnd_bus_if.m     Sat Aug 27 00:58:21 2016        
(r304876)
@@ -565,8 +565,9 @@ METHOD int release_ext_rsrc {
  * @param offset The offset to be read.
  * @param width The size of the access. Must be 1, 2 or 4 bytes.
  *
- * The exact behavior of this method is bus-specific. In the case of
- * bcma(4), this method provides access to the first agent port of @p child.
+ * The exact behavior of this method is bus-specific. On a bcma(4) bus, this
+ * method provides access to the first agent port of @p child; on a siba(4) 
bus,
+ * this method provides access to the core's CFG0 register block.
  *
  * @note Device drivers should only use this API for functionality
  * that is not available via another bhnd(4) function.

Modified: head/sys/dev/bhnd/siba/siba.c
==============================================================================
--- head/sys/dev/bhnd/siba/siba.c       Sat Aug 27 00:56:37 2016        
(r304875)
+++ head/sys/dev/bhnd/siba/siba.c       Sat Aug 27 00:58:21 2016        
(r304876)
@@ -263,6 +263,32 @@ siba_suspend_core(device_t dev, device_t
 static uint32_t
 siba_read_config(device_t dev, device_t child, bus_size_t offset, u_int width)
 {
+       struct siba_devinfo     *dinfo;
+       rman_res_t               r_size;
+
+       /* Must be directly attached */
+       if (device_get_parent(child) != dev)
+               return (UINT32_MAX);
+
+       /* CFG0 registers must be available */
+       dinfo = device_get_ivars(child);
+       if (dinfo->cfg[0] == NULL)
+               return (UINT32_MAX);
+
+       /* Offset must fall within CFG0 */
+       r_size = rman_get_size(dinfo->cfg[0]->res);
+       if (r_size < offset || r_size - offset < width)
+               return (UINT32_MAX);
+
+       switch (width) {
+       case 1:
+               return (bhnd_bus_read_1(dinfo->cfg[0], offset));
+       case 2:
+               return (bhnd_bus_read_2(dinfo->cfg[0], offset));
+       case 4:
+               return (bhnd_bus_read_4(dinfo->cfg[0], offset));
+       }
+       
        /* Unsuported */
        return (UINT32_MAX);
 }
@@ -271,8 +297,31 @@ static void
 siba_write_config(device_t dev, device_t child, bus_size_t offset, uint32_t 
val,
     u_int width)
 {
-       /* Unsuported */
-       return;
+       struct siba_devinfo     *dinfo;
+       rman_res_t               r_size;
+
+       /* Must be directly attached */
+       if (device_get_parent(child) != dev)
+               return;
+
+       /* CFG0 registers must be available */
+       dinfo = device_get_ivars(child);
+       if (dinfo->cfg[0] == NULL)
+               return;
+
+       /* Offset must fall within CFG0 */
+       r_size = rman_get_size(dinfo->cfg[0]->res);
+       if (r_size < offset || r_size - offset < width)
+               return;
+
+       switch (width) {
+       case 1:
+               bhnd_bus_write_1(dinfo->cfg[0], offset, val);
+       case 2:
+               bhnd_bus_write_2(dinfo->cfg[0], offset, val);
+       case 4:
+               bhnd_bus_write_4(dinfo->cfg[0], offset, val);
+       }
 }
 
 static u_int
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to