]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/bhnd/bhndb/bhndb.h
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
[FreeBSD/FreeBSD.git] / sys / dev / bhnd / bhndb / bhndb.h
1 /*-
2  * Copyright (c) 2015 Landon Fuller <landon@landonf.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  *
16  * NO WARRANTY
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  * THE POSSIBILITY OF SUCH DAMAGES.
28  * 
29  * $FreeBSD$
30  */
31
32 #ifndef _BHND_BHNDB_H_
33 #define _BHND_BHNDB_H_
34
35 #include <sys/param.h>
36 #include <sys/bus.h>
37
38 #include <machine/bus.h>
39 #include <sys/rman.h>
40 #include <machine/resource.h>
41
42 #include <dev/bhnd/bhnd.h>
43
44 #include "bhndb_bus_if.h"
45
46 extern devclass_t bhndb_devclass;
47 DECLARE_CLASS(bhnd_bhndb_driver);
48
49 int     bhndb_attach_bridge(device_t parent, device_t *bhndb, int unit);
50
51 /**
52  * bhndb register window types.
53  */
54 typedef enum {
55         BHNDB_REGWIN_T_CORE,            /**< Fixed mapping of a core port region. */
56         BHNDB_REGWIN_T_SPROM,           /**< Fixed mapping of device SPROM */
57         BHNDB_REGWIN_T_DYN,             /**< A dynamically configurable window */
58         BHNDB_REGWIN_T_INVALID          /**< Invalid type */
59 } bhndb_regwin_type_t;
60
61 /**
62  * Evaluates to true if @p _rt defines a static mapping.
63  * 
64  * @param _rt A bhndb_regwin_type_t value.
65  */
66 #define BHNDB_REGWIN_T_IS_STATIC(_rt)           \
67         ((_rt) == BHNDB_REGWIN_T_CORE ||        \
68          (_rt) == BHNDB_REGWIN_T_SPROM)
69
70 /**
71  * bhndb register window definition.
72  */
73 struct bhndb_regwin {
74         bhndb_regwin_type_t     win_type;       /**< window type */
75         bus_size_t              win_offset;     /**< offset of the window within the resource */
76         bus_size_t              win_size;       /**< size of the window */
77         
78         /** Resource identification */
79         struct {
80                 int             type;           /**< resource type */
81                 int             rid;            /**< resource id */
82         } res;
83
84
85         union {
86                 /** Core-specific register window (BHNDB_REGWIN_T_CORE). */
87                 struct {
88                         bhnd_devclass_t class;          /**< mapped core's class */
89                         u_int           unit;           /**< mapped core's unit */
90                         bhnd_port_type  port_type;      /**< mapped port type */
91                         u_int           port;           /**< mapped port number */
92                         u_int           region;         /**< mapped region number */
93                         bhnd_size_t     offset;         /**< mapped offset within the region */
94                 } core;
95
96                 /** SPROM register window (BHNDB_REGWIN_T_SPROM). */
97                 struct {} sprom;
98
99                 /** Dynamic register window (BHNDB_REGWIN_T_DYN). */
100                 struct {
101                         bus_size_t      cfg_offset;     /**< window address config offset. */
102                 } dyn;
103         } d;
104 };
105
106 #define BHNDB_REGWIN_TABLE_END  { BHNDB_REGWIN_T_INVALID, 0, 0, { 0, 0 } }
107
108 /**
109  * Bridge hardware configuration.
110  * 
111  * Provides the bridge's DMA address translation descriptions, register/address
112  * mappings, and the resources via which those mappings may be accessed.
113  */
114 struct bhndb_hwcfg {
115         const struct resource_spec              *resource_specs;        /**< resources required by our register windows */
116         const struct bhndb_regwin               *register_windows;      /**< register window table */
117         const struct bhnd_dma_translation       *dma_translations;      /**< DMA address translation table, or NULL if DMA is not supported */
118 };
119
120 /**
121  * Hardware specification entry.
122  * 
123  * Defines a set of match criteria that may be used to determine the
124  * register map and resource configuration for a bhndb bridge device. 
125  */
126 struct bhndb_hw {
127         const char                      *name;          /**< configuration name */
128         const struct bhnd_core_match    *hw_reqs;       /**< match requirements */
129         u_int                            num_hw_reqs;   /**< number of match requirements */
130         const struct bhndb_hwcfg        *cfg;           /**< associated hardware configuration */
131 };
132
133
134 /**
135  * bhndb resource allocation priorities.
136  */
137 typedef enum {
138         /** No direct resources should ever be allocated for this device. */
139         BHNDB_PRIORITY_NONE     = 0,
140
141         /** Allocate a direct resource if available after serving all other
142           * higher-priority requests. */
143         BHNDB_PRIORITY_LOW      = 1,
144
145         /** Direct resource allocation is preferred, but not necessary
146          *  for reasonable runtime performance. */
147         BHNDB_PRIORITY_DEFAULT  = 2,
148
149         /** Indirect resource allocation would incur high runtime overhead. */
150         BHNDB_PRIORITY_HIGH     = 3
151 } bhndb_priority_t;
152
153 /**
154  * bhndb resource allocation flags.
155  */
156 enum bhndb_alloc_flags {
157         /**
158          * If resource overcommit prevents fulfilling a request for this
159          * resource, an in-use resource should be be borrowed to fulfill the
160          * request.
161          * 
162          * The only known use case is to support accessing the ChipCommon core
163          * during Wi-Fi driver operation on early PCI Wi-Fi devices
164          * (PCI_V0, SSB) that do not provide a dedicated ChipCommon register
165          * window mapping; on such devices, device and firmware semantics
166          * guarantee the safety of -- after disabling interrupts -- borrowing
167          * the single dynamic register window that's been assigned to the D11
168          * core to perform the few ChipCommon operations required by the driver.
169          */
170         BHNDB_ALLOC_FULFILL_ON_OVERCOMMIT       = (1<<0),
171 };
172
173 /**
174  * Port resource priority descriptor.
175  */
176 struct bhndb_port_priority {
177         bhnd_port_type          type;           /**< port type. */
178         u_int                   port;           /**< port */
179         u_int                   region;         /**< region */
180         bhndb_priority_t        priority;       /**< port priority */
181         uint32_t                alloc_flags;    /**< port allocation flags (@see bhndb_alloc_flags) */
182 };
183
184 /**
185  * Core resource priority descriptor.
186  */
187 struct bhndb_hw_priority {
188         struct bhnd_core_match                   match;         /**< core match descriptor */
189         bhndb_priority_t                         priority;      /**< core-level priority */
190         const struct bhndb_port_priority        *ports;         /**< port priorities */
191         u_int                                    num_ports;     /**< number of port priority records. */
192 };
193
194 #define BHNDB_HW_PRIORITY_TABLE_END     { {}, BHNDB_PRIORITY_NONE, NULL, 0 }
195
196
197 #endif /* _BHND_BHNDB_H_ */