blob: 4ca2692315e82ef103b39aa04d37f49d5620313b [file] [log] [blame]
Sridhar Parasurambf391322015-01-23 09:29:07 -08001/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
2
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions are
5met:
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above
9 copyright notice, this list of conditions and the following
10 disclaimer in the documentation and/or other materials provided
11 with the distribution.
12 * Neither the name of The Linux Foundation nor the names of its
13 contributors may be used to endorse or promote products derived
14 from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29/*===========================================================================
30 INCLUDE FILES
31===========================================================================*/
32#include "glink.h"
33#include "glink_core_if.h"
34#include "glink_transport_if.h"
35#include "glink_vector.h"
36#include "glink_os_utils.h"
37
38/*===========================================================================
39 LOCAL DATA DECLARATIONS
40===========================================================================*/
41
42
43/*===========================================================================
44 PRIVATE FUNCTIONS
45===========================================================================*/
46
47/*===========================================================================
48FUNCTION glink_dummy_tx_vprovider
49===========================================================================*/
50/**
51
52 Buffer provider for virtual space that operates on a non-vectored buffer.
53
54 @param[in] iovec Pointer to the dummy vector.
55 @param[in] offset Offset within the dummy vector.
56 @param[out] size Size of the provied buffer.
57
58 @return virtual address of the buffer.
59
60 @sideeffects None.
61*/
62/*=========================================================================*/
63void* glink_dummy_tx_vprovider
64(
65 void* iovec,
66 size_t offset,
67 size_t *size
68)
69{
70 glink_core_tx_pkt_type* pkt = (glink_core_tx_pkt_type*)iovec;
71
72 if (pkt == NULL || size == NULL || pkt->size <= offset)
73 {
74 return NULL;
75 }
76
77 *size = pkt->size - offset;
78
79 return (char*)(pkt->data) + offset;
80}
81
82/*===========================================================================
83FUNCTION glink_iovec_vprovider
84===========================================================================*/
85/**
86
87 Buffer provider for virtual space that operates on a Glink iovec.
88
89 @param[in] iovec Pointer to the dummy vector.
90 @param[in] offset Offset within the dummy vector.
91 @param[out] size Size of the provied buffer.
92
93 @return virtual address of the buffer.
94
95 @sideeffects None.
96*/
97/*=========================================================================*/
98void* glink_iovec_vprovider
99(
100 void* iovec,
101 size_t offset,
102 size_t *size
103)
104{
105 glink_iovector_type* iovec_l = (glink_iovector_type*)iovec;
106
107 if (iovec_l == NULL || size == NULL)
108 {
109 return NULL;
110 }
111
Sridhar Parasurambf391322015-01-23 09:29:07 -0800112 if (!iovec_l->vlast || iovec_l->vlast->start_offset > offset)
113 {
114 iovec_l->vlast = iovec_l->vlist;
115 }
116
117 while (iovec_l->vlast &&
118 iovec_l->vlast->start_offset + iovec_l->vlast->size <= offset)
119 {
120 iovec_l->vlast = iovec_l->vlast->next;
121 }
122
123 if (iovec_l->vlast == NULL)
124 {
125 return NULL;
126 }
127
128 offset -= iovec_l->vlast->start_offset;
129 *size = iovec_l->vlast->size - offset;
130
131 return (char*)(iovec_l->vlast->data) + offset;
132}
133
134/*===========================================================================
135FUNCTION glink_iovec_pprovider
136===========================================================================*/
137/**
138
139 Buffer provider for physical space that operates on a Glink iovec.
140
141 @param[in] iovec Pointer to the dummy vector.
142 @param[in] offset Offset within the dummy vector.
143 @param[out] size Size of the provied buffer.
144
145 @return physical address of the buffer.
146
147 @sideeffects None.
148*/
149/*=========================================================================*/
150void* glink_iovec_pprovider
151(
152 void* iovec,
153 size_t offset,
154 size_t *size
155)
156{
157 glink_iovector_type* iovec_l = (glink_iovector_type*)iovec;
158
159 if (iovec_l == NULL || size == NULL)
160 {
161 return NULL;
162 }
163
Sridhar Parasurambf391322015-01-23 09:29:07 -0800164 if (!iovec_l->plast || iovec_l->plast->start_offset > offset)
165 {
166 iovec_l->plast = iovec_l->plist;
167 }
168
169 while (iovec_l->plast &&
170 iovec_l->plast->start_offset + iovec_l->plast->size <= offset)
171 {
172 iovec_l->plast = iovec_l->plast->next;
173 }
174
175 if (iovec_l->plast == NULL)
176 {
177 return NULL;
178 }
179
180 offset -= iovec_l->plast->start_offset;
181 *size = iovec_l->plast->size - offset;
182
183 return (char*)(iovec_l->plast->data) + offset;
184}