]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/bus_map_resource.9
dts: Update our copy to Linux 4.17
[FreeBSD/FreeBSD.git] / share / man / man9 / bus_map_resource.9
1 .\" -*- nroff -*-
2 .\"
3 .\" Copyright (c) 2016 John H. Baldwin <jhb@FreeBSD.org>
4 .\" All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
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.
14 .\"
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
25 .\" SUCH DAMAGE.
26 .\"
27 .\" $FreeBSD$
28 .\"
29 .Dd February 5, 2018
30 .Dt BUS_MAP_RESOURCE 9
31 .Os
32 .Sh NAME
33 .Nm bus_map_resource , bus_unmap_resource , resource_init_map_request
34 .Nd map or unmap an active resource
35 .Sh SYNOPSIS
36 .In sys/param.h
37 .In sys/bus.h
38 .Pp
39 .In machine/bus.h
40 .In sys/rman.h
41 .In machine/resource.h
42 .Ft int
43 .Fo bus_map_resource
44 .Fa "device_t dev" "int type" "struct resource *r"
45 .Fa "struct resource_map_request *args" "struct resource_map *map"
46 .Fc
47 .Ft int
48 .Fo bus_unmap_resource
49 .Fa "device_t dev" "int type" "struct resource *r" "struct resource_map *map"
50 .Fc
51 .Ft void
52 .Fn resource_init_map_request "struct resource_map_request *args"
53 .Sh DESCRIPTION
54 These functions create or destroy a mapping of a previously activated
55 resource.
56 Mappings permit CPU access to the resource via the
57 .Xr bus_space 9
58 API.
59 .Pp
60 The arguments are as follows:
61 .Bl -tag -width indent
62 .It Fa dev
63 The device that owns the resource.
64 .It Fa type
65 The type of resource to map.
66 It is one of:
67 .Pp
68 .Bl -tag -width ".Dv SYS_RES_MEMORY" -compact
69 .It Dv SYS_RES_IOPORT
70 for I/O ports
71 .It Dv SYS_RES_MEMORY
72 for I/O memory
73 .El
74 .It Fa r
75 A pointer to the
76 .Vt "struct resource"
77 returned by
78 .Xr bus_alloc_resource 9 .
79 .It Fa args
80 A set of optional properties to apply when creating a mapping.
81 This argument can be set to
82 .Dv NULL
83 to request a mapping of the entire resource with the default properties.
84 .It Fa map
85 The resource mapping to create or destroy.
86 .El
87 .Ss Resource Mappings
88 Resource mappings are described by a
89 .Vt "struct resource_map"
90 object.
91 This structure contains a
92 .Xr bus_space 9
93 tag and handle in the
94 .Va r_bustag
95 and
96 .Va r_bushandle
97 members that can be used for CPU access to the mapping.
98 The structure also contains a
99 .Va r_vaddr
100 member which contains the virtual address of the mapping if one exists.
101 .Pp
102 The wrapper API for
103 .Vt "struct resource"
104 objects described in
105 .Xr bus_activate_resource 9
106 can also be used with
107 .Vt "struct resource_map" .
108 For example,
109 a pointer to a mapping object can be passed as the first argument to
110 .Fn bus_read_4 .
111 This wrapper API is preferred over using the
112 .Va r_bustag
113 and
114 .Va r_bushandle
115 members directly.
116 .Ss Optional Mapping Properties
117 The
118 .Vt "struct resource_map_request"
119 object passed in
120 .Fa args
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.
129 The
130 .Va offset
131 is relative to the start of the resource.
132 .It Va memattr
133 Specifies a memory attribute to use when mapping the resource.
134 By default memory mappings use the
135 .Dv VM_MEMATTR_UNCACHEABLE
136 attribute.
137 .El
138 .Sh RETURN VALUES
139 Zero is returned on success, otherwise an error is returned.
140 .Sh EXAMPLES
141 This maps a PCI memory BAR with the write-combining memory attribute and
142 reads the first 32-bit word:
143 .Bd -literal
144         struct resource *r;
145         struct resource_map map;
146         struct resource_map_request req;
147         uint32_t val;
148         int rid;
149
150         rid = PCIR_BAR(0);
151         r = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE |
152             RF_UNMAPPED);
153         resource_init_map_request(&req);
154         req.memattr = VM_MEMATTR_WRITE_COMBINING;
155         bus_map_resource(dev, SYS_RES_MEMORY, r, &req, &map);
156         val = bus_read_4(&map, 0);
157 .Ed
158 .Sh SEE ALSO
159 .Xr bus_activate_resource 9 ,
160 .Xr bus_alloc_resource 9 ,
161 .Xr bus_space 9 ,
162 .Xr device 9 ,
163 .Xr driver 9
164 .Sh AUTHORS
165 This manual page was written by
166 .An John Baldwin Aq Mt jhb@FreeBSD.org .