3 .\" Copyright (c) 2016 John H. Baldwin <jhb@FreeBSD.org>
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 .Dt BUS_MAP_RESOURCE 9
32 .Nm bus_map_resource , bus_unmap_resource , resource_init_map_request
33 .Nd map or unmap an active resource
40 .In machine/resource.h
43 .Fa "device_t dev" "int type" "struct resource *r"
44 .Fa "struct resource_map_request *args" "struct resource_map *map"
47 .Fo bus_unmap_resource
48 .Fa "device_t dev" "int type" "struct resource *r" "struct resource_map *map"
51 .Fn resource_init_map_request "struct resource_map_request *args"
53 These functions create or destroy a mapping of a previously activated
55 Mappings permit CPU access to the resource via the
59 The arguments are as follows:
60 .Bl -tag -width indent
62 The device that owns the resource.
64 The type of resource to map.
67 .Bl -tag -width ".Dv SYS_RES_MEMORY" -compact
77 .Xr bus_alloc_resource 9 .
79 A set of optional properties to apply when creating a mapping.
80 This argument can be set to
82 to request a mapping of the entire resource with the default properties.
84 The resource mapping to create or destroy.
87 Resource mappings are described by a
88 .Vt "struct resource_map"
90 This structure contains a
96 members that can be used for CPU access to the mapping.
97 The structure also contains a
99 member which contains the virtual address of the mapping if one exists.
102 .Vt "struct resource"
104 .Xr bus_activate_resource 9
105 can also be used with
106 .Vt "struct resource_map" .
108 a pointer to a mapping object can be passed as the first argument to
110 This wrapper API is preferred over using the
115 .Ss Optional Mapping Properties
117 .Vt "struct resource_map_request"
120 can be used to specify optional properties of a mapping.
121 The structure must be initialized by invoking
122 .Fn resource_init_map_request .
123 Properties are then specified by setting one or more of these members:
124 .Bl -tag -width indent
125 .It Va offset , length
126 These two members specify a region of the resource to map.
127 By default a mapping is created for the entire resource.
130 is relative to the start of the resource.
132 Specifies a memory attribute to use when mapping the resource.
133 By default memory mappings use the
134 .Dv VM_MEMATTR_UNCACHEABLE
138 Zero is returned on success, otherwise an error is returned.
140 This maps a PCI memory BAR with the write-combining memory attribute and
141 reads the first 32-bit word:
144 struct resource_map map;
145 struct resource_map_request req;
150 r = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE |
152 resource_init_map_request(&req);
153 req.memattr = VM_MEMATTR_WRITE_COMBINING;
154 bus_map_resource(dev, SYS_RES_MEMORY, r, &req, &map);
155 val = bus_read_4(&map, 0);
158 .Xr bus_activate_resource 9 ,
159 .Xr bus_alloc_resource 9 ,
164 This manual page was written by
165 .An John Baldwin Aq Mt jhb@FreeBSD.org .