1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
.\" $OpenBSD: pci_mapreg_map.9,v 1.1 2019/02/23 04:54:25 dlg Exp $
.\"
.\" Copyright (c) 2019 David Gwynne <dlg@openbsd.org>
.\" All rights reserved.
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: February 23 2019 $
.Dt PCI_MAPREG_MAP 9
.Os
.Sh NAME
.Nm pci_mapreg_map ,
.Nm pci_mapreg_info ,
.Nm pci_mapreg_probe ,
.Nm pci_mapreg_type
.\" .Nm pci_mem_find ,
.\" .Nm pci_io_find
.Nd PCI register mappings
.Sh SYNOPSIS
.In dev/pci/pcivar.h
.Ft int
.Fo pci_mapreg_map
.Fa "struct pci_attach_args *paa"
.Fa "int reg"
.Fa "pcireg_t type"
.Fa "int flags"
.Fa "bus_space_tag_t *tagp"
.Fa "bus_space_handle_t *handlep"
.Fa "bus_addr_t *basep"
.Fa "bus_size_t *sizep"
.Fa "bus_size_t maxsize"
.Fc
.Ft int
.Fo pci_mapreg_info
.Fa "pci_chipset_tag_t pc"
.Fa "pcitag_t tag"
.Fa "int reg"
.Fa "pcireg_t type"
.Fa "bus_addr_t *basep"
.Fa "bus_size_t *sizep"
.Fa "int *flagsp"
.Fc
.Ft int
.Fo pci_mapreg_probe
.Fa "pci_chipset_tag_t pc"
.Fa "pcitag_t tag"
.Fa "int reg"
.Fa "pcireg_t *typep"
.Fc
.Ft pcireg_t
.Fo pci_mapreg_type
.Fa "pci_chipset_tag_t pc"
.Fa "pcitag_t tag"
.Fa "int reg"
.Fc
.\" .Ft int
.\" .Fo pci_mem_find
.\" .Fa "pci_chipset_tag_t pc"
.\" .Fa "pcitag_t pcitag"
.\" .Fa "int reg"
.\" .Fa "bus_addr_t *basep"
.\" .Fa "bus_size_t *sizep"
.\" .Fa "int *cacheablep"
.\" .Fc
.\" .Ft int
.\" .Fo pci_io_find
.\" .Fa "pci_chipset_tag_t pc"
.\" .Fa "pcitag_t pcitag"
.\" .Fa "int reg"
.\" .Fa "bus_addr_t *basep"
.\" .Fa "bus_size_t *sizep"
.\" .Fa "int *cacheablep"
.\" .Fc
.Sh DESCRIPTION
These functions provide wrappers and helpers around
.Xr bus_space 9
mappings for device registers described by the Base Address Registers
(BARs) in a PCI devices configuration space.
.Pp
.Nm pci_mapreg_map
wraps a call to
.Xr bus_space_map 9
using information from the BAR referenced by
.Fa reg
for the device being attached with
.Fa paa .
Memory or I/O mappings are derived from the
.Fa type
argument.
The size of the register mapping can be restricted by specifying a
non-zero value in
.Fa maxsize .
The bus space tag and handle used for the mapping, as well
as the base address and size of the mapping, will be provided
to the caller via the optional
.Fa tagp ,
.Fa handlep ,
.Fa basep ,
and
.Fa sizep
pointers.
.Pp
.Nm pci_mapreg_info
provides bus space mapping information from the BAR referenced by
.Fa reg .
The
.Fa type
argument specifies whether the mapping provides Memory or I/O access.
The base address, size, and bus space flags are optionally provided
to the caller via the
.Fa basep ,
.Fa sizep ,
and
.Fa flagsp
pointers.
.Pp
.Nm pci_mapreg_probe
attempts to determine if the BAR referenced by
.Fa reg
describes a valid register mapping.
.Pp
.Nm pci_mapreg_type
returns the type of register access for the registers at the BAR
referenced by
.Fa reg .
.Sh RETURN VALUES
.Nm pci_mapreg_map ,
.Nm pci_mapreg_info ,
and
.Nm pci_mapreg_probe
return 0 on success, or an
.Xr errno 2
style value on failure.
.Pp
.Nm pci_mapreg_type
returns either
.Dv PCI_MAPREG_TYPE_IO
or
.Dv PCI_MAPREG_TYPE_MEM .
.Sh SEE ALSO
.Xr pci 4 ,
.Xr bus_space 9 ,
.Xr pci_conf_read 9
|