summaryrefslogtreecommitdiffstats
path: root/sys/kern/bus_if.m
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2016-05-20 17:57:47 +0000
committerjhb <jhb@FreeBSD.org>2016-05-20 17:57:47 +0000
commitb4b2ae565200af6f37fec26de490a48783880ce4 (patch)
tree3aa16fa17a986984dd375052ea627ea43a7d21dd /sys/kern/bus_if.m
parent6f2769857a743d51ed1025cabba5e6b4c769fcfe (diff)
downloadFreeBSD-src-b4b2ae565200af6f37fec26de490a48783880ce4.zip
FreeBSD-src-b4b2ae565200af6f37fec26de490a48783880ce4.tar.gz
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
Diffstat (limited to 'sys/kern/bus_if.m')
-rw-r--r--sys/kern/bus_if.m55
1 files changed, 51 insertions, 4 deletions
diff --git a/sys/kern/bus_if.m b/sys/kern/bus_if.m
index 8592e9f..2b75438 100644
--- a/sys/kern/bus_if.m
+++ b/sys/kern/bus_if.m
@@ -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
OpenPOWER on IntegriCloud