Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 May 2016 17:57:47 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r300317 - in head: share/man/man9 sys/kern sys/sparc64/include sys/sys sys/vm
Message-ID:  <201605201757.u4KHvlTK093203@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Fri May 20 17:57:47 2016
New Revision: 300317
URL: https://svnweb.freebsd.org/changeset/base/300317

Log:
  Add new bus methods for mapping resources.
  
  Add a pair of bus methods that can be used to "map" resources for direct
  CPU access using bus_space(9).  bus_map_resource() creates a mapping and
  bus_unmap_resource() releases a previously created mapping.  Mappings are
  described by 'struct resource_map' object.  Pointers to these objects can
  be passed as the first argument to the bus_space wrapper API used for bus
  resources.
  
  Drivers that wish to map all of a resource using default settings
  (for example, using uncacheable memory attributes) do not need to change.
  However, drivers that wish to use non-default settings can now do so
  without jumping through hoops.
  
  First, an RF_UNMAPPED flag is added to request that a resource is not
  implicitly mapped with the default settings when it is activated.  This
  permits other activation steps (such as enabling I/O or memory decoding
  in a device's PCI command register) to be taken without creating a
  mapping.  Right now the AGP drivers don't set RF_ACTIVE to avoid using
  up a large amount of KVA to map the AGP aperture on 32-bit platforms.
  Once RF_UNMAPPED is supported on all platforms that support AGP this
  can be changed to using RF_UNMAPPED with RF_ACTIVE instead.
  
  Second, bus_map_resource accepts an optional structure that defines
  additional settings for a given mapping.
  
  For example, a driver can now request to map only a subset of a resource
  instead of the entire range.  The AGP driver could also use this to only
  map the first page of the aperture (IIRC, it calls pmap_mapdev() directly
  to map the first page currently).  I will also eventually change the
  PCI-PCI bridge driver to request mappings of the subset of the I/O window
  resource on its parent side to create mappings for child devices rather
  than passing child resources directly up to nexus to be mapped.  This
  also permits bridges that do address translation to request suitable
  mappings from a resource on the "upper" side of the bus when mapping
  resources on the "lower" side of the bus.
  
  Another attribute that can be specified is an alternate memory attribute
  for memory-mapped resources.  This can be used to request a
  Write-Combining mapping of a PCI BAR in an MI fashion.  (Currently the
  drivers that do this call pmap_change_attr() directly for x86 only.)
  
  Note that this commit only adds the MI framework.  Each platform needs
  to add support for handling RF_UNMAPPED and thew new
  bus_map/unmap_resource methods.  Generally speaking, any drivers that
  are calling rman_set_bustag() and rman_set_bushandle() need to be
  updated.
  
  Discussed on:	arch
  Reviewed by:	cem
  Differential Revision:	https://reviews.freebsd.org/D5237

Added:
  head/share/man/man9/bus_map_resource.9   (contents, props changed)
Modified:
  head/share/man/man9/Makefile
  head/share/man/man9/bus_activate_resource.9
  head/share/man/man9/bus_alloc_resource.9
  head/share/man/man9/rman.9
  head/sys/kern/bus_if.m
  head/sys/kern/subr_bus.c
  head/sys/kern/subr_rman.c
  head/sys/sparc64/include/vm.h
  head/sys/sys/bus.h
  head/sys/sys/rman.h
  head/sys/vm/vm.h

Modified: head/share/man/man9/Makefile
==============================================================================
--- head/share/man/man9/Makefile	Fri May 20 17:41:12 2016	(r300316)
+++ head/share/man/man9/Makefile	Fri May 20 17:57:47 2016	(r300317)
@@ -44,6 +44,7 @@ MAN=	accept_filter.9 \
 	bus_generic_shutdown.9 \
 	BUS_GET_CPUS.9 \
 	bus_get_resource.9 \
+	bus_map_resource.9 \
 	BUS_NEW_PASS.9 \
 	BUS_PRINT_CHILD.9 \
 	BUS_READ_IVAR.9 \
@@ -504,6 +505,8 @@ MLINKS+=bus_dma.9 busdma.9 \
 	bus_dma.9 bus_dma_tag_destroy.9
 MLINKS+=bus_generic_read_ivar.9 bus_generic_write_ivar.9
 MLINKS+=BUS_GET_CPUS.9 bus_get_cpus.9
+MLINKS+=bus_map_resource.9 bus_unmap_resource.9 \
+	bus_map_resource.9 resource_init_map_request.9
 MLINKS+=BUS_READ_IVAR.9 BUS_WRITE_IVAR.9
 MLINKS+=BUS_SETUP_INTR.9 bus_setup_intr.9 \
 	BUS_SETUP_INTR.9 BUS_TEARDOWN_INTR.9 \
@@ -1381,6 +1384,7 @@ MLINKS+=rman.9 rman_activate_resource.9 
 	rman.9 rman_get_device.9 \
 	rman.9 rman_get_end.9 \
 	rman.9 rman_get_flags.9 \
+	rman.9 rman_get_mapping.9 \
 	rman.9 rman_get_rid.9 \
 	rman.9 rman_get_size.9 \
 	rman.9 rman_get_start.9 \
@@ -1396,6 +1400,7 @@ MLINKS+=rman.9 rman_activate_resource.9 
 	rman.9 rman_reserve_resource_bound.9 \
 	rman.9 rman_set_bushandle.9 \
 	rman.9 rman_set_bustag.9 \
+	rman.9 rman_set_mapping.9 \
 	rman.9 rman_set_rid.9 \
 	rman.9 rman_set_virtual.9
 MLINKS+=rmlock.9 rm_assert.9 \

Modified: head/share/man/man9/bus_activate_resource.9
==============================================================================
--- head/share/man/man9/bus_activate_resource.9	Fri May 20 17:41:12 2016	(r300316)
+++ head/share/man/man9/bus_activate_resource.9	Fri May 20 17:57:47 2016	(r300317)
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 10, 2016
+.Dd May 20, 2016
 .Dt BUS_ACTIVATE_RESOURCE 9
 .Os
 .Sh NAME
@@ -106,6 +106,14 @@ If the mapping is associated with a virt
 the virtual address can be retrieved via
 .Xr rman_get_virtual 9 .
 .Pp
+This implicit mapping can be disabled by passing the
+.Dv RF_UNMAPPED
+flag to
+.Xr bus_alloc_resource 9 .
+A driver may use this if it wishes to allocate its own mappings of a resource
+using
+.Xr bus_map_resource 9 .
+.Pp
 A wrapper API for
 .Xr bus_space 9
 is also provided that accepts the associated resource as the first argument
@@ -133,6 +141,7 @@ resource:
 Zero is returned on success, otherwise an error is returned.
 .Sh SEE ALSO
 .Xr bus_alloc_resource 9 ,
+.Xr bus_map_resource 9 ,
 .Xr bus_space 9 ,
 .Xr device 9 ,
 .Xr driver 9

Modified: head/share/man/man9/bus_alloc_resource.9
==============================================================================
--- head/share/man/man9/bus_alloc_resource.9	Fri May 20 17:41:12 2016	(r300316)
+++ head/share/man/man9/bus_alloc_resource.9	Fri May 20 17:57:47 2016	(r300317)
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd April 28, 2016
+.Dd May 20, 2016
 .Dt BUS_ALLOC_RESOURCE 9
 .Os
 .Sh NAME
@@ -166,6 +166,9 @@ For example,
 cannot share IRQs while
 .Xr cardbus 4
 can.
+.It Dv RF_UNMAPPED
+do not establish implicit mapping when activated via
+.Xr bus_activate_resource 9 .
 .El
 .El
 .Sh RETURN VALUES
@@ -193,6 +196,7 @@ should be saved in the softc of the devi
 .Sh SEE ALSO
 .Xr bus_activate_resource 9 ,
 .Xr bus_adjust_resource 9 ,
+.Xr bus_map_resource 9 ,
 .Xr bus_release_resource 9 ,
 .Xr device 9 ,
 .Xr driver 9

Added: head/share/man/man9/bus_map_resource.9
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/share/man/man9/bus_map_resource.9	Fri May 20 17:57:47 2016	(r300317)
@@ -0,0 +1,167 @@
+.\" -*- nroff -*-
+.\"
+.\" Copyright (c) 2016 John H. Baldwin <jhb@FreeBSD.org>
+.\" 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.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, 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 DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd May 20, 2016
+.Dt BUS_MAP_RESOURCE 9
+.Os
+.Sh NAME
+.Nm bus_map_resource , bus_unmap_resource , resource_init_map_request
+.Nd map or unmap an active resource
+.Sh SYNOPSIS
+.In sys/param.h
+.In sys/bus.h
+.Pp
+.In machine/bus.h
+.In sys/rman.h
+.In machine/resource.h
+.Ft int
+.Fo bus_map_resource
+.Fa "device_t dev" "int type" "struct resource *r"
+.Fa "struct resource_map_request *args" "struct resource_map *map"
+.Fc
+.Ft int
+.Fo bus_unmap_resource
+.Fa "device_t dev" "int type" "struct resource *r" "struct resource_map *map"
+.Fc
+.Ft void
+.Fn resource_init_map_request "struct resource_map_request *args"
+.Sh DESCRIPTION
+These functions create or destroy a mapping of a previously activated
+resource.
+Mappings permit CPU access to the resource via the
+.Xr bus_space 9
+API.
+.Pp
+The arguments are as follows:
+.Bl -tag -width indent
+.It Fa dev
+The device that owns the resource.
+.It Fa type
+The type of resource to map.
+It is one of:
+.Pp
+.Bl -tag -width ".Dv SYS_RES_MEMORY" -compact
+.It Dv SYS_RES_IOPORT
+for I/O ports
+.It Dv SYS_RES_MEMORY
+for I/O memory
+.El
+.It Fa r
+A pointer to the
+.Vt "struct resource"
+returned by
+.Xr bus_alloc_resource 9 .
+.It Fa args
+A set of optional properties to apply when creating a mapping.
+This argument can be set to
+.Dv NULL
+to request a mapping of the entire resource with the default properties.
+.It Fa map
+The resource mapping to create or destroy.
+.El
+.Ss Resource Mappings
+Resource mappings are described by a
+.Vt "struct resource_map"
+object.
+This structure contains a
+.Xr bus_space 9
+tag and handle in the
+.Va r_bustag
+and
+.Va r_bushandle
+members that can be used for CPU access to the mapping.
+The structure also contains a
+.Va r_vaddr
+member which contains the virtual address of the mapping if one exists.
+.Pp
+The wrapper API for
+.Vt "struct resource"
+objects described in
+.Xr bus_activate_resource 9
+can also be used with
+.Vt "struct resource_map" .
+For example,
+a pointer to a mapping object can be passed as the first argument to
+.Fn bus_read_4 .
+This wrapper API is preferred over using the
+.Va r_bustag
+and
+.Va r_bushandle
+members directly.
+.Ss Optional Mapping Properties
+The
+.Vt "struct resource_map_request"
+object passed in
+.Fa args
+can be used to specify optional properties of a mapping.
+The structure must be initialized by invoking
+.Fn resource_init_map_request .
+Properties are then specified by setting one or more of these members:
+.Bl -tag -width indent
+.It Va offset , length
+These two members specify a region of the resource to map.
+By default a mapping is created for the entire resource.
+The
+.Va offset
+is relative to the start of the resource.
+.It Va memattr
+Specifies a memory attribute to use when mapping the resource.
+By default memory mappings use the
+.Dv VM_MEMATTR_UNCACHEABLE
+attribute.
+.El
+.Sh EXAMPLES
+This maps a PCI memory BAR with the write-combining memory attribute and
+reads the first 32-bit word:
+.Bd -literal
+	struct resource *r;
+	struct resource_map map;
+	struct resource_map_args args;
+	uint32_t val;
+	int rid;
+
+	rid = PCIR_BAR(0);
+	r = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE |
+	    RF_UNMAPPED);
+	resource_init_map_request(&args);
+	args.memattr = VM_MEMATTR_WRITE_COMBINING;
+	bus_map_resource(dev, SYS_RES_MEMORY, r, &args, &map);
+	val = bus_read_4(&map, 0);
+.Ed
+.Pp
+.Sh RETURN VALUES
+Zero is returned on success, otherwise an error is returned.
+.Sh SEE ALSO
+.Xr bus_activate_resource 9 ,
+.Xr bus_alloc_resource 9 ,
+.Xr bus_space 9 ,
+.Xr device 9 ,
+.Xr driver 9
+.Sh AUTHORS
+This manual page was written by
+.An John Baldwin Aq Mt jhb@FreeBSD.org .

Modified: head/share/man/man9/rman.9
==============================================================================
--- head/share/man/man9/rman.9	Fri May 20 17:41:12 2016	(r300316)
+++ head/share/man/man9/rman.9	Fri May 20 17:57:47 2016	(r300317)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 19, 2016
+.Dd May 20, 2016
 .Dt RMAN 9
 .Os
 .Sh NAME
@@ -49,6 +49,8 @@
 .Nm rman_get_device ,
 .Nm rman_get_size ,
 .Nm rman_get_flags ,
+.Nm rman_set_mapping ,
+.Nm rman_get_mapping ,
 .Nm rman_set_virtual ,
 .Nm rman_get_virtual ,
 .Nm rman_set_bustag ,
@@ -106,6 +108,10 @@
 .Ft u_int
 .Fn rman_get_flags "struct resource *r"
 .Ft void
+.Fn rman_set_mapping "struct resource *r" "struct resource_map *map"
+.Ft void
+.Fn rman_get_mapping "struct resource *r" "struct resource_map *map"
+.Ft void
 .Fn rman_set_virtual "struct resource *r" "void *v"
 .Ft "void *"
 .Fn rman_get_virtual "struct resource *r"
@@ -140,6 +146,7 @@ represented by a 16-bit flag register, a
 #define RF_SHAREABLE    0x0004 /* resource permits contemporaneous sharing */
 #define RF_FIRSTSHARE   0x0020 /* first in sharing list */
 #define RF_PREFETCHABLE 0x0040 /* resource is prefetchable */
+#define RF_UNMAPPED     0x0100 /* don't map resource when activating */
 .Ed
 .Pp
 Bits 15:10  of the flag register are used to represent the desired alignment
@@ -424,6 +431,26 @@ The
 function can be used to retrieve the KVA once set.
 .Pp
 The
+.Fn rman_set_mapping
+function is used to associate a resource mapping with a resource
+.Fa r .
+The mapping must cover the entire resource.
+Setting a mapping sets the associated
+.Xr bus_space 9
+handle and tag for
+.Fa r
+as well as the kernel virtual address if the mapping contains one.
+These individual values can be retrieved via
+.Fn rman_get_bushandle ,
+.Fn rman_get_bustag ,
+and
+.Fn rman_get_virtual .
+.Pp
+The
+.Fn rman_get_mapping
+function can be used to retrieve the associated resource mapping once set.
+.Pp
+The
 .Fn rman_set_rid
 function associates a resource identifier with a resource
 .Fa r .
@@ -439,7 +466,9 @@ function returns a pointer to the device
 .Xr bus_activate_resource 9 ,
 .Xr bus_adjust_resource 9 ,
 .Xr bus_alloc_resource 9 ,
+.Xr bus_map_resource 9 ,
 .Xr bus_release_resource 9 ,
+.Xr bus_space 9 ,
 .Xr bus_set_resource 9 ,
 .Xr mutex 9
 .Sh AUTHORS

Modified: head/sys/kern/bus_if.m
==============================================================================
--- head/sys/kern/bus_if.m	Fri May 20 17:41:12 2016	(r300316)
+++ head/sys/kern/bus_if.m	Fri May 20 17:57:47 2016	(r300317)
@@ -287,8 +287,9 @@ METHOD struct resource * alloc_resource 
  * @brief Activate a resource
  *
  * Activate a resource previously allocated with
- * BUS_ALLOC_RESOURCE(). This may for instance map a memory region
- * into the kernel's virtual address space.
+ * BUS_ALLOC_RESOURCE().  This may enable decoding of this resource in a
+ * device for instance.  It will also establish a mapping for the resource
+ * unless RF_UNMAPPED was set when allocating the resource.
  *
  * @param _dev		the parent device of @p _child
  * @param _child	the device which allocated the resource
@@ -304,12 +305,58 @@ METHOD int activate_resource {
 	struct resource *_r;
 };
 
+
+/**
+ * @brief Map a resource
+ *
+ * Allocate a mapping for a range of an active resource.  The mapping
+ * is described by a struct resource_map object.  This may for instance
+ * map a memory region into the kernel's virtual address space.
+ *
+ * @param _dev		the parent device of @p _child
+ * @param _child	the device which allocated the resource
+ * @param _type		the type of resource
+ * @param _r		the resource to map
+ * @param _args		optional attributes of the mapping
+ * @param _map		the mapping
+ */
+METHOD int map_resource {
+	device_t	_dev;
+	device_t	_child;
+	int		_type;
+	struct resource *_r;
+	struct resource_map_request *_args;
+	struct resource_map *_map;
+} DEFAULT bus_generic_map_resource;
+
+
+/**
+ * @brief Unmap a resource
+ *
+ * Release a mapping previously allocated with
+ * BUS_MAP_RESOURCE(). This may for instance unmap a memory region
+ * from the kernel's virtual address space.
+ *
+ * @param _dev		the parent device of @p _child
+ * @param _child	the device which allocated the resource
+ * @param _type		the type of resource
+ * @param _r		the resource
+ * @param _map		the mapping to release
+ */
+METHOD int unmap_resource {
+	device_t	_dev;
+	device_t	_child;
+	int		_type;
+	struct resource *_r;
+	struct resource_map *_map;
+} DEFAULT bus_generic_unmap_resource;
+
+
 /**
  * @brief Deactivate a resource
  *
  * Deactivate a resource previously allocated with
- * BUS_ALLOC_RESOURCE(). This may for instance unmap a memory region
- * from the kernel's virtual address space.
+ * BUS_ALLOC_RESOURCE(). 
  *
  * @param _dev		the parent device of @p _child
  * @param _child	the device which allocated the resource

Modified: head/sys/kern/subr_bus.c
==============================================================================
--- head/sys/kern/subr_bus.c	Fri May 20 17:41:12 2016	(r300316)
+++ head/sys/kern/subr_bus.c	Fri May 20 17:57:47 2016	(r300317)
@@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/stdarg.h>
 
 #include <vm/uma.h>
+#include <vm/vm.h>
 
 SYSCTL_NODE(_hw, OID_AUTO, bus, CTLFLAG_RW, NULL, NULL);
 SYSCTL_ROOT_NODE(OID_AUTO, dev, CTLFLAG_RW, NULL, NULL);
@@ -3050,6 +3051,15 @@ device_set_unit(device_t dev, int unit)
  * Some useful method implementations to make life easier for bus drivers.
  */
 
+void
+resource_init_map_request_impl(struct resource_map_request *args, size_t sz)
+{
+
+	bzero(args, sz);
+	args->size = sz;
+	args->memattr = VM_MEMATTR_UNCACHEABLE;
+}
+
 /**
  * @brief Initialise a resource list.
  *
@@ -4060,6 +4070,40 @@ bus_generic_deactivate_resource(device_t
 }
 
 /**
+ * @brief Helper function for implementing BUS_MAP_RESOURCE().
+ *
+ * This simple implementation of BUS_MAP_RESOURCE() simply calls the
+ * BUS_MAP_RESOURCE() method of the parent of @p dev.
+ */
+int
+bus_generic_map_resource(device_t dev, device_t child, int type,
+    struct resource *r, struct resource_map_request *args,
+    struct resource_map *map)
+{
+	/* Propagate up the bus hierarchy until someone handles it. */
+	if (dev->parent)
+		return (BUS_MAP_RESOURCE(dev->parent, child, type, r, args,
+		    map));
+	return (EINVAL);
+}
+
+/**
+ * @brief Helper function for implementing BUS_UNMAP_RESOURCE().
+ *
+ * This simple implementation of BUS_UNMAP_RESOURCE() simply calls the
+ * BUS_UNMAP_RESOURCE() method of the parent of @p dev.
+ */
+int
+bus_generic_unmap_resource(device_t dev, device_t child, int type,
+    struct resource *r, struct resource_map *map)
+{
+	/* Propagate up the bus hierarchy until someone handles it. */
+	if (dev->parent)
+		return (BUS_UNMAP_RESOURCE(dev->parent, child, type, r, map));
+	return (EINVAL);
+}
+
+/**
  * @brief Helper function for implementing BUS_BIND_INTR().
  *
  * This simple implementation of BUS_BIND_INTR() simply calls the
@@ -4421,6 +4465,36 @@ bus_deactivate_resource(device_t dev, in
 }
 
 /**
+ * @brief Wrapper function for BUS_MAP_RESOURCE().
+ *
+ * This function simply calls the BUS_MAP_RESOURCE() method of the
+ * parent of @p dev.
+ */
+int
+bus_map_resource(device_t dev, int type, struct resource *r,
+    struct resource_map_request *args, struct resource_map *map)
+{
+	if (dev->parent == NULL)
+		return (EINVAL);
+	return (BUS_MAP_RESOURCE(dev->parent, dev, type, r, args, map));
+}
+
+/**
+ * @brief Wrapper function for BUS_UNMAP_RESOURCE().
+ *
+ * This function simply calls the BUS_UNMAP_RESOURCE() method of the
+ * parent of @p dev.
+ */
+int
+bus_unmap_resource(device_t dev, int type, struct resource *r,
+    struct resource_map *map)
+{
+	if (dev->parent == NULL)
+		return (EINVAL);
+	return (BUS_UNMAP_RESOURCE(dev->parent, dev, type, r, map));
+}
+
+/**
  * @brief Wrapper function for BUS_RELEASE_RESOURCE().
  *
  * This function simply calls the BUS_RELEASE_RESOURCE() method of the

Modified: head/sys/kern/subr_rman.c
==============================================================================
--- head/sys/kern/subr_rman.c	Fri May 20 17:41:12 2016	(r300316)
+++ head/sys/kern/subr_rman.c	Fri May 20 17:57:47 2016	(r300317)
@@ -897,6 +897,27 @@ rman_get_bushandle(struct resource *r)
 }
 
 void
+rman_set_mapping(struct resource *r, struct resource_map *map)
+{
+
+	KASSERT(rman_get_size(r) == map->r_size,
+	    ("rman_set_mapping: size mismatch"));
+	rman_set_bustag(r, map->r_bustag);
+	rman_set_bushandle(r, map->r_bushandle);
+	rman_set_virtual(r, map->r_vaddr);
+}
+
+void
+rman_get_mapping(struct resource *r, struct resource_map *map)
+{
+
+	map->r_bustag = rman_get_bustag(r);
+	map->r_bushandle = rman_get_bushandle(r);
+	map->r_size = rman_get_size(r);
+	map->r_vaddr = rman_get_virtual(r);
+}
+
+void
 rman_set_rid(struct resource *r, int rid)
 {
 

Modified: head/sys/sparc64/include/vm.h
==============================================================================
--- head/sys/sparc64/include/vm.h	Fri May 20 17:41:12 2016	(r300316)
+++ head/sys/sparc64/include/vm.h	Fri May 20 17:57:47 2016	(r300317)
@@ -31,5 +31,6 @@
 
 /* Memory attribute configuration is not (yet) implemented. */
 #define	VM_MEMATTR_DEFAULT	0
+#define	VM_MEMATTR_UNCACHEABLE	0
 
 #endif /* !_MACHINE_VM_H_ */

Modified: head/sys/sys/bus.h
==============================================================================
--- head/sys/sys/bus.h	Fri May 20 17:41:12 2016	(r300316)
+++ head/sys/sys/bus.h	Fri May 20 17:57:47 2016	(r300317)
@@ -294,6 +294,31 @@ struct driver {
 	KOBJ_CLASS_FIELDS;
 };
 
+/**
+ * @brief A resource mapping.
+ */
+struct resource_map {
+	bus_space_tag_t r_bustag;
+	bus_space_handle_t r_bushandle;
+	bus_size_t r_size;
+	void	*r_vaddr;
+};
+	
+/**
+ * @brief Optional properties of a resource mapping request.
+ */
+struct resource_map_request {
+	size_t	size;
+	rman_res_t offset;
+	rman_res_t length;
+	vm_memattr_t memattr;
+};
+
+void	resource_init_map_request_impl(struct resource_map_request *_args,
+	    size_t _sz);
+#define	resource_init_map_request(rmr) 					\
+	resource_init_map_request_impl((rmr), sizeof(*(rmr)))
+
 /*
  * Definitions for drivers which need to keep simple lists of resources
  * for their child devices.
@@ -407,6 +432,10 @@ bus_space_tag_t
 int	bus_generic_get_domain(device_t dev, device_t child, int *domain);
 struct resource_list *
 	bus_generic_get_resource_list (device_t, device_t);
+int	bus_generic_map_resource(device_t dev, device_t child, int type,
+				 struct resource *r,
+				 struct resource_map_request *args,
+				 struct resource_map *map);
 void	bus_generic_new_pass(device_t dev);
 int	bus_print_child_header(device_t dev, device_t child);
 int	bus_print_child_domain(device_t dev, device_t child);
@@ -440,6 +469,9 @@ int	bus_generic_suspend(device_t dev);
 int	bus_generic_suspend_child(device_t dev, device_t child);
 int	bus_generic_teardown_intr(device_t dev, device_t child,
 				  struct resource *irq, void *cookie);
+int	bus_generic_unmap_resource(device_t dev, device_t child, int type,
+				   struct resource *r,
+				   struct resource_map *map);
 int	bus_generic_write_ivar(device_t dev, device_t child, int which,
 			       uintptr_t value);
 int	bus_null_rescan(device_t dev);
@@ -469,6 +501,11 @@ int	bus_activate_resource(device_t dev, 
 			      struct resource *r);
 int	bus_deactivate_resource(device_t dev, int type, int rid,
 				struct resource *r);
+int	bus_map_resource(device_t dev, int type, struct resource *r,
+			 struct resource_map_request *args,
+			 struct resource_map *map);
+int	bus_unmap_resource(device_t dev, int type, struct resource *r,
+			   struct resource_map *map);
 int	bus_get_cpus(device_t dev, enum cpu_sets op, size_t setsize,
 		     struct _cpuset *cpuset);
 bus_dma_tag_t bus_get_dma_tag(device_t dev);

Modified: head/sys/sys/rman.h
==============================================================================
--- head/sys/sys/rman.h	Fri May 20 17:41:12 2016	(r300316)
+++ head/sys/sys/rman.h	Fri May 20 17:57:47 2016	(r300317)
@@ -47,6 +47,7 @@
 #define	RF_FIRSTSHARE	0x0020	/* first in sharing list */
 #define	RF_PREFETCHABLE	0x0040	/* resource is prefetchable */
 #define	RF_OPTIONAL	0x0080	/* for bus_alloc_resources() */
+#define	RF_UNMAPPED	0x0100	/* don't map resource when activating */
 
 #define	RF_ALIGNMENT_SHIFT	10 /* alignment size bit starts bit 10 */
 #define	RF_ALIGNMENT_MASK	(0x003F << RF_ALIGNMENT_SHIFT)
@@ -105,6 +106,7 @@ struct resource {
 };
 
 struct resource_i;
+struct resource_map;
 
 TAILQ_HEAD(resource_head, resource_i);
 
@@ -127,6 +129,7 @@ bus_space_tag_t rman_get_bustag(struct r
 rman_res_t	rman_get_end(struct resource *);
 struct device *rman_get_device(struct resource *);
 u_int	rman_get_flags(struct resource *);
+void	rman_get_mapping(struct resource *, struct resource_map *);
 int	rman_get_rid(struct resource *);
 rman_res_t	rman_get_size(struct resource *);
 rman_res_t	rman_get_start(struct resource *);
@@ -150,6 +153,7 @@ void	rman_set_bushandle(struct resource 
 void	rman_set_bustag(struct resource *_r, bus_space_tag_t _t);
 void	rman_set_device(struct resource *_r, struct device *_dev);
 void	rman_set_end(struct resource *_r, rman_res_t _end);
+void	rman_set_mapping(struct resource *, struct resource_map *);
 void	rman_set_rid(struct resource *_r, int _rid);
 void	rman_set_start(struct resource *_r, rman_res_t _start);
 void	rman_set_virtual(struct resource *_r, void *_v);

Modified: head/sys/vm/vm.h
==============================================================================
--- head/sys/vm/vm.h	Fri May 20 17:41:12 2016	(r300316)
+++ head/sys/vm/vm.h	Fri May 20 17:57:47 2016	(r300317)
@@ -109,8 +109,9 @@ typedef struct vm_object *vm_object_t;
 typedef int boolean_t;
 
 /*
- * The exact set of memory attributes is machine dependent.  However, every
- * machine is required to define VM_MEMATTR_DEFAULT.
+ * The exact set of memory attributes is machine dependent.  However,
+ * every machine is required to define VM_MEMATTR_DEFAULT and
+ * VM_MEMATTR_UNCACHEABLE.
  */
 typedef	char vm_memattr_t;	/* memory attribute codes */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605201757.u4KHvlTK093203>