3 .\" Copyright (c) 2016 John H. Baldwin <jhb@FreeBSD.org>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .Dt BUS_MAP_RESOURCE 9
33 .Nm bus_map_resource , bus_unmap_resource , resource_init_map_request
34 .Nd map or unmap an active resource
41 .In machine/resource.h
44 .Fa "device_t dev" "int type" "struct resource *r"
45 .Fa "struct resource_map_request *args" "struct resource_map *map"
48 .Fo bus_unmap_resource
49 .Fa "device_t dev" "int type" "struct resource *r" "struct resource_map *map"
52 .Fn resource_init_map_request "struct resource_map_request *args"
54 These functions create or destroy a mapping of a previously activated
56 Mappings permit CPU access to the resource via the
60 The arguments are as follows:
61 .Bl -tag -width indent
63 The device that owns the resource.
65 The type of resource to map.
68 .Bl -tag -width ".Dv SYS_RES_MEMORY" -compact
78 .Xr bus_alloc_resource 9 .
80 A set of optional properties to apply when creating a mapping.
81 This argument can be set to
83 to request a mapping of the entire resource with the default properties.
85 The resource mapping to create or destroy.
88 Resource mappings are described by a
89 .Vt "struct resource_map"
91 This structure contains a
97 members that can be used for CPU access to the mapping.
98 The structure also contains a
100 member which contains the virtual address of the mapping if one exists.
103 .Vt "struct resource"
105 .Xr bus_activate_resource 9
106 can also be used with
107 .Vt "struct resource_map" .
109 a pointer to a mapping object can be passed as the first argument to
111 This wrapper API is preferred over using the
116 .Ss Optional Mapping Properties
118 .Vt "struct resource_map_request"
121 can be used to specify optional properties of a mapping.
122 The structure must be initialized by invoking
123 .Fn resource_init_map_request .
124 Properties are then specified by setting one or more of these members:
125 .Bl -tag -width indent
126 .It Va offset , length
127 These two members specify a region of the resource to map.
128 By default a mapping is created for the entire resource.
131 is relative to the start of the resource.
133 Specifies a memory attribute to use when mapping the resource.
134 By default memory mappings use the
135 .Dv VM_MEMATTR_UNCACHEABLE
139 Zero is returned on success, otherwise an error is returned.
141 This maps a PCI memory BAR with the write-combining memory attribute and
142 reads the first 32-bit word:
145 struct resource_map map;
146 struct resource_map_args args;
151 r = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE |
153 resource_init_map_request(&args);
154 args.memattr = VM_MEMATTR_WRITE_COMBINING;
155 bus_map_resource(dev, SYS_RES_MEMORY, r, &args, &map);
156 val = bus_read_4(&map, 0);
159 .Xr bus_activate_resource 9 ,
160 .Xr bus_alloc_resource 9 ,
165 This manual page was written by
166 .An John Baldwin Aq Mt jhb@FreeBSD.org .