Debian Codegraph @

providers/vmw_pvrdma/pvrdma_ring.h

raw symbols SCIP
1 /*
2 * Copyright (c) 2012-2016 VMware, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of EITHER the GNU General Public License
6 * version 2 as published by the Free Software Foundation or the BSD
7 * 2-Clause License. This program is distributed in the hope that it
8 * will be useful, but WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED
9 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
10 * See the GNU General Public License version 2 for more details at
11 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program in the file COPYING. If not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 *
18 * The BSD 2-Clause License
19 *
20 * Redistribution and use in source and binary forms, with or
21 * without modification, are permitted provided that the following
22 * conditions are met:
23 *
24 * - Redistributions of source code must retain the above
25 * copyright notice, this list of conditions and the following
26 * disclaimer.
27 *
28 * - Redistributions in binary form must reproduce the above
29 * copyright notice, this list of conditions and the following
30 * disclaimer in the documentation and/or other materials
31 * provided with the distribution.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
44 * OF THE POSSIBILITY OF SUCH DAMAGE.
45 */
46
47 #ifndef __PVRDMA_RING_H__
48 #define __PVRDMA_RING_H__cxx . . $ `providers/vmw_pvrdma/pvrdma_ring.h:48:9`!
49
50 #include <linux/types.h>
51
52 #define PVRDMA_INVALID_IDXcxx . . $ `providers/vmw_pvrdma/pvrdma_ring.h:52:9`! -1 /* Invalid index. */
53
54 /*
55 * Rings are shared with the device, so read/write access must be atomic.
56 * PVRDMA is x86 only, and since 32-bit access is atomic on x86, using
57 * regular uint32_t is safe.
58 */
59
60 struct pvrdma_ringcxx . . $ pvrdma_ring# {
61 uint32_tcxx . . $ uint32_t# prod_tailcxx . . $ pvrdma_ring#prod_tail.; /* Producer tail. */
62 uint32_tcxx . . $ uint32_t# cons_headcxx . . $ pvrdma_ring#cons_head.; /* Consumer head. */
63 };
64
65 struct pvrdma_ring_statecxx . . $ pvrdma_ring_state# {
66 struct pvrdma_ringcxx . . $ pvrdma_ring# txcxx . . $ pvrdma_ring_state#tx.; /* Tx ring. */
67 struct pvrdma_ringcxx . . $ pvrdma_ring# rxcxx . . $ pvrdma_ring_state#rx.; /* Rx ring. */
68 };
69
70 static inline int pvrdma_idx_validcxx . . $ pvrdma_idx_valid(21cb2064190e2a90).(uint32_tcxx . . $ uint32_t# idx, uint32_tcxx . . $ uint32_t# max_elems)
71 {
72 /* Generates fewer instructions than a less-than. */
73 return (idx & ~((max_elems << 1) - 1)) == 0;
74 }
75
76 static inline int32_tcxx . . $ int32_t# pvrdma_idxcxx . . $ pvrdma_idx(fd37442ea2ec66b0).(uint32_tcxx . . $ uint32_t# *var, uint32_tcxx . . $ uint32_t# max_elems)
77 {
78 const uint32_tcxx . . $ uint32_t# idx = *var;
79
80 if (pvrdma_idx_validcxx . . $ pvrdma_idx_valid(21cb2064190e2a90).(idx, max_elems))
81 return idx & (max_elems - 1);
82 return PVRDMA_INVALID_IDXcxx . . $ `providers/vmw_pvrdma/pvrdma_ring.h:52:9`!;
83 }
84
85 static inline void pvrdma_idx_ring_inccxx . . $ pvrdma_idx_ring_inc(d89196f67e9c91e5).(uint32_tcxx . . $ uint32_t# *var, uint32_tcxx . . $ uint32_t# max_elems)
86 {
87 uint32_tcxx . . $ uint32_t# idx = (*var) + 1; /* Increment. */
88
89 idx &= (max_elems << 1) - 1; /* Modulo size, flip gen. */
90 *var = idx;
91 }
92
93 static inline int32_tcxx . . $ int32_t# pvrdma_idx_ring_has_spacecxx . . $ pvrdma_idx_ring_has_space(5e686492615b23d1).(const struct pvrdma_ringcxx . . $ pvrdma_ring# *r,
94 uint32_tcxx . . $ uint32_t# max_elems,
95 uint32_tcxx . . $ uint32_t# *out_tail)
96 {
97 const uint32_tcxx . . $ uint32_t# tail = r->prod_tailcxx . . $ pvrdma_ring#prod_tail.;
98 const uint32_tcxx . . $ uint32_t# head = r->cons_headcxx . . $ pvrdma_ring#cons_head.;
99
100 if (pvrdma_idx_validcxx . . $ pvrdma_idx_valid(21cb2064190e2a90).(tail, max_elems) &&
101 pvrdma_idx_validcxx . . $ pvrdma_idx_valid(21cb2064190e2a90).(head, max_elems)) {
102 *out_tail = tail & (max_elems - 1);
103 return tail != (head ^ max_elems);
104 }
105 return PVRDMA_INVALID_IDXcxx . . $ `providers/vmw_pvrdma/pvrdma_ring.h:52:9`!;
106 }
107
108 static inline int32_tcxx . . $ int32_t# pvrdma_idx_ring_has_datacxx . . $ pvrdma_idx_ring_has_data(5e686492615b23d1).(const struct pvrdma_ringcxx . . $ pvrdma_ring# *r,
109 uint32_tcxx . . $ uint32_t# max_elems,
110 uint32_tcxx . . $ uint32_t# *out_head)
111 {
112 const uint32_tcxx . . $ uint32_t# tail = r->prod_tailcxx . . $ pvrdma_ring#prod_tail.;
113 const uint32_tcxx . . $ uint32_t# head = r->cons_headcxx . . $ pvrdma_ring#cons_head.;
114
115 if (pvrdma_idx_validcxx . . $ pvrdma_idx_valid(21cb2064190e2a90).(tail, max_elems) &&
116 pvrdma_idx_validcxx . . $ pvrdma_idx_valid(21cb2064190e2a90).(head, max_elems)) {
117 *out_head = head & (max_elems - 1);
118 return tail != head;
119 }
120 return PVRDMA_INVALID_IDXcxx . . $ `providers/vmw_pvrdma/pvrdma_ring.h:52:9`!;
121 }
122
123 static inline int32_tcxx . . $ int32_t# pvrdma_idx_ring_is_valid_idxcxx . . $ pvrdma_idx_ring_is_valid_idx(5e686492615b23d1).(const struct pvrdma_ringcxx . . $ pvrdma_ring# *r,
124 uint32_tcxx . . $ uint32_t# max_elems,
125 uint32_tcxx . . $ uint32_t# *idx)
126 {
127 const uint32_tcxx . . $ uint32_t# tail = r->prod_tailcxx . . $ pvrdma_ring#prod_tail.;
128 const uint32_tcxx . . $ uint32_t# head = r->cons_headcxx . . $ pvrdma_ring#cons_head.;
129
130 if (pvrdma_idx_validcxx . . $ pvrdma_idx_valid(21cb2064190e2a90).(tail, max_elems) &&
131 pvrdma_idx_validcxx . . $ pvrdma_idx_valid(21cb2064190e2a90).(head, max_elems) &&
132 pvrdma_idx_validcxx . . $ pvrdma_idx_valid(21cb2064190e2a90).(*idx, max_elems)) {
133 if (tail > head && (*idx < tail && *idx >= head))
134 return 1;
135 else if (head > tail && (*idx >= head || *idx < tail))
136 return 1;
137 }
138 return 0;
139 }
140
141 #endif /* __PVRDMA_RING_H__ */