blob: 78ccf1acdc5cabf20f806de3335da60d8aeeec13 [file] [log] [blame]
Steven Toth443c12282009-05-09 21:17:28 -03001/*
2 * Driver for the NXP SAA7164 PCIe bridge
3 *
Steven Toth9b8b0192010-07-31 14:39:44 -03004 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com>
Steven Toth443c12282009-05-09 21:17:28 -03005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include "saa7164.h"
23
24/* The message bus to/from the firmware is a ring buffer in PCI address
25 * space. Establish the defaults.
26 */
27int saa7164_bus_setup(struct saa7164_dev *dev)
28{
29 tmComResBusInfo_t *b = &dev->bus;
30
31 mutex_init(&b->lock);
32
33 b->Type = TYPE_BUS_PCIe;
34 b->m_wMaxReqSize = SAA_DEVICE_MAXREQUESTSIZE;
35
36 b->m_pdwSetRing = (u8 *)(dev->bmmio +
37 ((u32)dev->busdesc.CommandRing));
38
39 b->m_dwSizeSetRing = SAA_DEVICE_BUFFERBLOCKSIZE;
40
41 b->m_pdwGetRing = (u8 *)(dev->bmmio +
42 ((u32)dev->busdesc.ResponseRing));
43
44 b->m_dwSizeGetRing = SAA_DEVICE_BUFFERBLOCKSIZE;
45
Steven Toth60665822010-07-31 16:15:22 -030046 b->m_dwSetWritePos = ((u32)dev->intfdesc.BARLocation) + (2 * sizeof(u64));
47 b->m_dwSetReadPos = b->m_dwSetWritePos + (1 * sizeof(u32));
Steven Toth443c12282009-05-09 21:17:28 -030048
Steven Toth60665822010-07-31 16:15:22 -030049 b->m_dwGetWritePos = b->m_dwSetWritePos + (2 * sizeof(u32));
50 b->m_dwGetReadPos = b->m_dwSetWritePos + (3 * sizeof(u32));
Steven Toth443c12282009-05-09 21:17:28 -030051
52 return 0;
53}
54
55void saa7164_bus_dump(struct saa7164_dev *dev)
56{
57 tmComResBusInfo_t *b = &dev->bus;
58
59 dprintk(DBGLVL_BUS, "Dumping the bus structure:\n");
60 dprintk(DBGLVL_BUS, " .type = %d\n", b->Type);
61 dprintk(DBGLVL_BUS, " .dev->bmmio = 0x%p\n", dev->bmmio);
62 dprintk(DBGLVL_BUS, " .m_wMaxReqSize = 0x%x\n", b->m_wMaxReqSize);
63 dprintk(DBGLVL_BUS, " .m_pdwSetRing = 0x%p\n", b->m_pdwSetRing);
64 dprintk(DBGLVL_BUS, " .m_dwSizeSetRing = 0x%x\n", b->m_dwSizeSetRing);
65 dprintk(DBGLVL_BUS, " .m_pdwGetRing = 0x%p\n", b->m_pdwGetRing);
66 dprintk(DBGLVL_BUS, " .m_dwSizeGetRing = 0x%x\n", b->m_dwSizeGetRing);
67
Steven Toth60665822010-07-31 16:15:22 -030068 dprintk(DBGLVL_BUS, " .m_dwSetReadPos = 0x%x (0x%08x)\n",
69 b->m_dwSetReadPos, saa7164_readl(b->m_dwSetReadPos));
Steven Toth443c12282009-05-09 21:17:28 -030070
Steven Toth60665822010-07-31 16:15:22 -030071 dprintk(DBGLVL_BUS, " .m_dwSetWritePos = 0x%x (0x%08x)\n",
72 b->m_dwSetWritePos, saa7164_readl(b->m_dwSetWritePos));
Steven Toth443c12282009-05-09 21:17:28 -030073
Steven Toth60665822010-07-31 16:15:22 -030074 dprintk(DBGLVL_BUS, " .m_dwGetReadPos = 0x%x (0x%08x)\n",
75 b->m_dwGetReadPos, saa7164_readl(b->m_dwGetReadPos));
Steven Toth443c12282009-05-09 21:17:28 -030076
Steven Toth60665822010-07-31 16:15:22 -030077 dprintk(DBGLVL_BUS, " .m_dwGetWritePos = 0x%x (0x%08x)\n",
78 b->m_dwGetWritePos, saa7164_readl(b->m_dwGetWritePos));
79
80}
81
82/* Intensionally throw a BUG() if the state of the message bus looks corrupt */
83void saa7164_bus_verify(struct saa7164_dev *dev)
84{
85 tmComResBusInfo_t *b = &dev->bus;
Steven Toth99b73d382010-07-31 16:24:25 -030086 int bug = 0;
Steven Toth60665822010-07-31 16:15:22 -030087
88 if (saa7164_readl(b->m_dwSetReadPos) > b->m_dwSizeSetRing)
89 bug++;
90
91 if (saa7164_readl(b->m_dwSetWritePos) > b->m_dwSizeSetRing)
92 bug++;
93
94 if (saa7164_readl(b->m_dwGetReadPos) > b->m_dwSizeGetRing)
95 bug++;
96
97 if (saa7164_readl(b->m_dwGetWritePos) > b->m_dwSizeGetRing)
98 bug++;
99
100 if (bug) {
Steven Toth99b73d382010-07-31 16:24:25 -0300101 saa_debug = 0xffff; /* Ensure we get the bus dump */
Steven Toth60665822010-07-31 16:15:22 -0300102 saa7164_bus_dump(dev);
Steven Toth99b73d382010-07-31 16:24:25 -0300103 saa_debug = 1024; /* Ensure we get the bus dump */
Steven Toth60665822010-07-31 16:15:22 -0300104 BUG();
105 }
Steven Toth443c12282009-05-09 21:17:28 -0300106}
107
108void saa7164_bus_dumpmsg(struct saa7164_dev *dev, tmComResInfo_t* m, void *buf)
109{
110 dprintk(DBGLVL_BUS, "Dumping msg structure:\n");
111 dprintk(DBGLVL_BUS, " .id = %d\n", m->id);
112 dprintk(DBGLVL_BUS, " .flags = 0x%x\n", m->flags);
113 dprintk(DBGLVL_BUS, " .size = 0x%x\n", m->size);
114 dprintk(DBGLVL_BUS, " .command = 0x%x\n", m->command);
115 dprintk(DBGLVL_BUS, " .controlselector = 0x%x\n", m->controlselector);
116 dprintk(DBGLVL_BUS, " .seqno = %d\n", m->seqno);
117 if (buf)
118 dprintk(DBGLVL_BUS, " .buffer (ignored)\n");
119}
120
121/*
122 * Places a command or a response on the bus. The implementation does not
123 * know if it is a command or a response it just places the data on the
124 * bus depending on the bus information given in the tmComResBusInfo_t
125 * structure. If the command or response does not fit into the bus ring
126 * buffer it will be refused.
127 *
128 * Return Value:
129 * SAA_OK The function executed successfully.
130 * < 0 One or more members are not initialized.
131 */
132int saa7164_bus_set(struct saa7164_dev *dev, tmComResInfo_t* msg, void *buf)
133{
134 tmComResBusInfo_t *bus = &dev->bus;
Steven Toth60665822010-07-31 16:15:22 -0300135 u32 bytes_to_write, free_write_space, timeout, curr_srp, curr_swp;
Steven Toth443c12282009-05-09 21:17:28 -0300136 u32 new_swp, space_rem;
137 int ret = SAA_ERR_BAD_PARAMETER;
138
139 if (!msg) {
140 printk(KERN_ERR "%s() !msg\n", __func__);
141 return SAA_ERR_BAD_PARAMETER;
142 }
143
144 dprintk(DBGLVL_BUS, "%s()\n", __func__);
Steven Toth2e732d62010-07-31 16:51:23 -0300145
Steven Toth60665822010-07-31 16:15:22 -0300146 saa7164_bus_verify(dev);
Steven Toth443c12282009-05-09 21:17:28 -0300147
148 msg->size = cpu_to_le16(msg->size);
149 msg->command = cpu_to_le16(msg->command);
150 msg->controlselector = cpu_to_le16(msg->controlselector);
151
152 if (msg->size > dev->bus.m_wMaxReqSize) {
153 printk(KERN_ERR "%s() Exceeded dev->bus.m_wMaxReqSize\n",
154 __func__);
155 return SAA_ERR_BAD_PARAMETER;
156 }
157
158 if ((msg->size > 0) && (buf == 0)) {
159 printk(KERN_ERR "%s() Missing message buffer\n", __func__);
160 return SAA_ERR_BAD_PARAMETER;
161 }
162
163 /* Lock the bus from any other access */
164 mutex_lock(&bus->lock);
165
166 bytes_to_write = sizeof(*msg) + msg->size;
Steven Toth60665822010-07-31 16:15:22 -0300167 free_write_space = 0;
Steven Toth443c12282009-05-09 21:17:28 -0300168 timeout = SAA_BUS_TIMEOUT;
Steven Toth60665822010-07-31 16:15:22 -0300169 curr_srp = le32_to_cpu(saa7164_readl(bus->m_dwSetReadPos));
170 curr_swp = le32_to_cpu(saa7164_readl(bus->m_dwSetWritePos));
Steven Toth443c12282009-05-09 21:17:28 -0300171
172 /* Deal with ring wrapping issues */
173 if (curr_srp > curr_swp)
Steven Toth443c12282009-05-09 21:17:28 -0300174 /* Deal with the wrapped ring */
Steven Toth60665822010-07-31 16:15:22 -0300175 free_write_space = curr_srp - curr_swp;
176 else
177 /* The ring has not wrapped yet */
178 free_write_space = (curr_srp + bus->m_dwSizeSetRing) - curr_swp;
Steven Toth443c12282009-05-09 21:17:28 -0300179
180 dprintk(DBGLVL_BUS, "%s() bytes_to_write = %d\n", __func__,
181 bytes_to_write);
182
Steven Toth60665822010-07-31 16:15:22 -0300183 dprintk(DBGLVL_BUS, "%s() free_write_space = %d\n", __func__,
184 free_write_space);
Steven Toth443c12282009-05-09 21:17:28 -0300185
186 dprintk(DBGLVL_BUS, "%s() curr_srp = %x\n", __func__, curr_srp);
187 dprintk(DBGLVL_BUS, "%s() curr_swp = %x\n", __func__, curr_swp);
188
189 /* Process the msg and write the content onto the bus */
Steven Toth60665822010-07-31 16:15:22 -0300190 while (bytes_to_write >= free_write_space) {
Steven Toth443c12282009-05-09 21:17:28 -0300191
192 if (timeout-- == 0) {
193 printk(KERN_ERR "%s() bus timeout\n", __func__);
194 ret = SAA_ERR_NO_RESOURCES;
195 goto out;
196 }
197
198 /* TODO: Review this delay, efficient? */
199 /* Wait, allowing the hardware fetch time */
200 mdelay(1);
201
202 /* Check the space usage again */
Steven Toth60665822010-07-31 16:15:22 -0300203 curr_srp = le32_to_cpu(saa7164_readl(bus->m_dwSetReadPos));
Steven Toth443c12282009-05-09 21:17:28 -0300204
205 /* Deal with ring wrapping issues */
206 if (curr_srp > curr_swp)
Steven Toth443c12282009-05-09 21:17:28 -0300207 /* Deal with the wrapped ring */
Steven Toth60665822010-07-31 16:15:22 -0300208 free_write_space = curr_srp - curr_swp;
209 else
210 /* Read didn't wrap around the buffer */
211 free_write_space = (curr_srp + bus->m_dwSizeSetRing) -
Steven Toth443c12282009-05-09 21:17:28 -0300212 curr_swp;
213
214 }
215
216 /* Calculate the new write position */
217 new_swp = curr_swp + bytes_to_write;
218
219 dprintk(DBGLVL_BUS, "%s() new_swp = %x\n", __func__, new_swp);
220 dprintk(DBGLVL_BUS, "%s() bus->m_dwSizeSetRing = %x\n", __func__,
221 bus->m_dwSizeSetRing);
222
223 /* Mental Note: line 462 tmmhComResBusPCIe.cpp */
224
225 /* Check if we're going to wrap again */
226 if (new_swp > bus->m_dwSizeSetRing) {
227
228 /* Ring wraps */
229 new_swp -= bus->m_dwSizeSetRing;
230
231 space_rem = bus->m_dwSizeSetRing - curr_swp;
232
233 dprintk(DBGLVL_BUS, "%s() space_rem = %x\n", __func__,
234 space_rem);
235
Steven Toth207b42c2009-05-09 21:30:05 -0300236 dprintk(DBGLVL_BUS, "%s() sizeof(*msg) = %d\n", __func__,
237 (u32)sizeof(*msg));
Steven Toth443c12282009-05-09 21:17:28 -0300238
239 if (space_rem < sizeof(*msg)) {
240 dprintk(DBGLVL_BUS, "%s() tr4\n", __func__);
241
242 /* Split the msg into pieces as the ring wraps */
Steven Toth60665822010-07-31 16:15:22 -0300243 memcpy(bus->m_pdwSetRing + curr_swp, msg, space_rem);
244 memcpy(bus->m_pdwSetRing, (u8 *)msg + space_rem,
Steven Toth443c12282009-05-09 21:17:28 -0300245 sizeof(*msg) - space_rem);
246
Steven Toth60665822010-07-31 16:15:22 -0300247 memcpy(bus->m_pdwSetRing + sizeof(*msg) - space_rem,
Steven Toth443c12282009-05-09 21:17:28 -0300248 buf, msg->size);
249
250 } else if (space_rem == sizeof(*msg)) {
251 dprintk(DBGLVL_BUS, "%s() tr5\n", __func__);
252
253 /* Additional data at the beginning of the ring */
Steven Toth60665822010-07-31 16:15:22 -0300254 memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg));
255 memcpy(bus->m_pdwSetRing, buf, msg->size);
Steven Toth443c12282009-05-09 21:17:28 -0300256
257 } else {
258 /* Additional data wraps around the ring */
Steven Toth60665822010-07-31 16:15:22 -0300259 memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg));
Steven Toth443c12282009-05-09 21:17:28 -0300260 if (msg->size > 0) {
Steven Toth60665822010-07-31 16:15:22 -0300261 memcpy(bus->m_pdwSetRing + curr_swp +
Steven Toth443c12282009-05-09 21:17:28 -0300262 sizeof(*msg), buf, space_rem -
263 sizeof(*msg));
Steven Toth60665822010-07-31 16:15:22 -0300264 memcpy(bus->m_pdwSetRing, (u8 *)buf +
Steven Toth443c12282009-05-09 21:17:28 -0300265 space_rem - sizeof(*msg),
266 bytes_to_write - space_rem);
267 }
268
269 }
270
271 } /* (new_swp > bus->m_dwSizeSetRing) */
272 else {
273 dprintk(DBGLVL_BUS, "%s() tr6\n", __func__);
274
275 /* The ring buffer doesn't wrap, two simple copies */
Steven Toth60665822010-07-31 16:15:22 -0300276 memcpy(bus->m_pdwSetRing + curr_swp, msg, sizeof(*msg));
277 memcpy(bus->m_pdwSetRing + curr_swp + sizeof(*msg), buf,
Steven Toth443c12282009-05-09 21:17:28 -0300278 msg->size);
279 }
280
281 dprintk(DBGLVL_BUS, "%s() new_swp = %x\n", __func__, new_swp);
282
Steven Toth443c12282009-05-09 21:17:28 -0300283 /* Update the bus write position */
Steven Toth60665822010-07-31 16:15:22 -0300284 saa7164_writel(bus->m_dwSetWritePos, cpu_to_le32(new_swp));
Steven Toth443c12282009-05-09 21:17:28 -0300285 ret = SAA_OK;
286
287out:
Steven Toth60665822010-07-31 16:15:22 -0300288 saa7164_bus_dump(dev);
Steven Toth443c12282009-05-09 21:17:28 -0300289 mutex_unlock(&bus->lock);
Steven Toth60665822010-07-31 16:15:22 -0300290 saa7164_bus_verify(dev);
Steven Toth443c12282009-05-09 21:17:28 -0300291 return ret;
292}
293
294/*
295 * Receive a command or a response from the bus. The implementation does not
296 * know if it is a command or a response it simply dequeues the data,
297 * depending on the bus information given in the tmComResBusInfo_t structure.
298 *
299 * Return Value:
300 * 0 The function executed successfully.
301 * < 0 One or more members are not initialized.
302 */
303int saa7164_bus_get(struct saa7164_dev *dev, tmComResInfo_t* msg, void *buf,
304 int peekonly)
305{
306 tmComResBusInfo_t *bus = &dev->bus;
307 u32 bytes_to_read, write_distance, curr_grp, curr_gwp,
308 new_grp, buf_size, space_rem;
309 tmComResInfo_t msg_tmp;
310 int ret = SAA_ERR_BAD_PARAMETER;
311
Steven Toth60665822010-07-31 16:15:22 -0300312 saa7164_bus_verify(dev);
Steven Toth2e732d62010-07-31 16:51:23 -0300313
Steven Toth443c12282009-05-09 21:17:28 -0300314 if (msg == 0)
315 return ret;
316
317 if (msg->size > dev->bus.m_wMaxReqSize) {
318 printk(KERN_ERR "%s() Exceeded dev->bus.m_wMaxReqSize\n",
319 __func__);
320 return ret;
321 }
322
323 if ((peekonly == 0) && (msg->size > 0) && (buf == 0)) {
324 printk(KERN_ERR
325 "%s() Missing msg buf, size should be %d bytes\n",
326 __func__, msg->size);
327 return ret;
328 }
329
330 mutex_lock(&bus->lock);
331
332 /* Peek the bus to see if a msg exists, if it's not what we're expecting
333 * then return cleanly else read the message from the bus.
334 */
Steven Toth60665822010-07-31 16:15:22 -0300335 curr_gwp = le32_to_cpu(saa7164_readl(bus->m_dwGetWritePos));
336 curr_grp = le32_to_cpu(saa7164_readl(bus->m_dwGetReadPos));
Steven Toth443c12282009-05-09 21:17:28 -0300337
338 if (curr_gwp == curr_grp) {
Steven Toth443c12282009-05-09 21:17:28 -0300339 ret = SAA_ERR_EMPTY;
340 goto out;
341 }
342
343 bytes_to_read = sizeof(*msg);
344
345 /* Calculate write distance to current read position */
346 write_distance = 0;
347 if (curr_gwp >= curr_grp)
348 /* Write doesn't wrap around the ring */
349 write_distance = curr_gwp - curr_grp;
350 else
351 /* Write wraps around the ring */
352 write_distance = curr_gwp + bus->m_dwSizeGetRing - curr_grp;
353
354 if (bytes_to_read > write_distance) {
355 printk(KERN_ERR "%s() No message/response found\n", __func__);
356 ret = SAA_ERR_INVALID_COMMAND;
357 goto out;
358 }
359
360 /* Calculate the new read position */
361 new_grp = curr_grp + bytes_to_read;
362 if (new_grp > bus->m_dwSizeGetRing) {
363
364 /* Ring wraps */
365 new_grp -= bus->m_dwSizeGetRing;
366 space_rem = bus->m_dwSizeGetRing - curr_grp;
367
Steven Toth60665822010-07-31 16:15:22 -0300368 memcpy(&msg_tmp, bus->m_pdwGetRing + curr_grp, space_rem);
369 memcpy((u8 *)&msg_tmp + space_rem, bus->m_pdwGetRing,
Steven Toth443c12282009-05-09 21:17:28 -0300370 bytes_to_read - space_rem);
371
372 } else {
373 /* No wrapping */
Steven Toth60665822010-07-31 16:15:22 -0300374 memcpy(&msg_tmp, bus->m_pdwGetRing + curr_grp, bytes_to_read);
Steven Toth443c12282009-05-09 21:17:28 -0300375 }
376
377 /* No need to update the read positions, because this was a peek */
378 /* If the caller specifically want to peek, return */
379 if (peekonly) {
Steven Toth60665822010-07-31 16:15:22 -0300380 memcpy(msg, &msg_tmp, sizeof(*msg));
Steven Toth443c12282009-05-09 21:17:28 -0300381 goto peekout;
382 }
383
384 /* Check if the command/response matches what is expected */
385 if ((msg_tmp.id != msg->id) || (msg_tmp.command != msg->command) ||
386 (msg_tmp.controlselector != msg->controlselector) ||
387 (msg_tmp.seqno != msg->seqno) || (msg_tmp.size != msg->size)) {
388
389 printk(KERN_ERR "%s() Unexpected msg miss-match\n", __func__);
390 saa7164_bus_dumpmsg(dev, msg, buf);
391 saa7164_bus_dumpmsg(dev, &msg_tmp, 0);
392 ret = SAA_ERR_INVALID_COMMAND;
393 goto out;
394 }
395
396 /* Get the actual command and response from the bus */
397 buf_size = msg->size;
398
399 bytes_to_read = sizeof(*msg) + msg->size;
400 /* Calculate write distance to current read position */
401 write_distance = 0;
402 if (curr_gwp >= curr_grp)
403 /* Write doesn't wrap around the ring */
404 write_distance = curr_gwp - curr_grp;
405 else
406 /* Write wraps around the ring */
407 write_distance = curr_gwp + bus->m_dwSizeGetRing - curr_grp;
408
409 if (bytes_to_read > write_distance) {
410 printk(KERN_ERR "%s() Invalid bus state, missing msg "
411 "or mangled ring, faulty H/W / bad code?\n", __func__);
412 ret = SAA_ERR_INVALID_COMMAND;
413 goto out;
414 }
415
416 /* Calculate the new read position */
417 new_grp = curr_grp + bytes_to_read;
418 if (new_grp > bus->m_dwSizeGetRing) {
419
420 /* Ring wraps */
421 new_grp -= bus->m_dwSizeGetRing;
422 space_rem = bus->m_dwSizeGetRing - curr_grp;
423
424 if (space_rem < sizeof(*msg)) {
425 /* msg wraps around the ring */
Steven Toth60665822010-07-31 16:15:22 -0300426 memcpy(msg, bus->m_pdwGetRing + curr_grp, space_rem);
427 memcpy((u8 *)msg + space_rem, bus->m_pdwGetRing,
Steven Toth443c12282009-05-09 21:17:28 -0300428 sizeof(*msg) - space_rem);
429 if (buf)
Steven Toth60665822010-07-31 16:15:22 -0300430 memcpy(buf, bus->m_pdwGetRing + sizeof(*msg) -
Steven Toth443c12282009-05-09 21:17:28 -0300431 space_rem, buf_size);
432
433 } else if (space_rem == sizeof(*msg)) {
Steven Toth60665822010-07-31 16:15:22 -0300434 memcpy(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));
Steven Toth443c12282009-05-09 21:17:28 -0300435 if (buf)
436 memcpy(buf, bus->m_pdwGetRing, buf_size);
437 } else {
438 /* Additional data wraps around the ring */
Steven Toth60665822010-07-31 16:15:22 -0300439 memcpy(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));
Steven Toth443c12282009-05-09 21:17:28 -0300440 if (buf) {
Steven Toth60665822010-07-31 16:15:22 -0300441 memcpy(buf, bus->m_pdwGetRing + curr_grp +
Steven Toth443c12282009-05-09 21:17:28 -0300442 sizeof(*msg), space_rem - sizeof(*msg));
Steven Toth60665822010-07-31 16:15:22 -0300443 memcpy(buf + space_rem - sizeof(*msg),
Steven Toth443c12282009-05-09 21:17:28 -0300444 bus->m_pdwGetRing, bytes_to_read -
445 space_rem);
446 }
447
448 }
449
450 } else {
451 /* No wrapping */
Steven Toth60665822010-07-31 16:15:22 -0300452 memcpy(msg, bus->m_pdwGetRing + curr_grp, sizeof(*msg));
Steven Toth443c12282009-05-09 21:17:28 -0300453 if (buf)
Steven Toth60665822010-07-31 16:15:22 -0300454 memcpy(buf, bus->m_pdwGetRing + curr_grp + sizeof(*msg),
Steven Toth443c12282009-05-09 21:17:28 -0300455 buf_size);
456 }
457
458 /* Update the read positions, adjusting the ring */
Steven Toth60665822010-07-31 16:15:22 -0300459 saa7164_writel(bus->m_dwGetReadPos, cpu_to_le32(new_grp));
Steven Toth443c12282009-05-09 21:17:28 -0300460
461peekout:
462 msg->size = le16_to_cpu(msg->size);
463 msg->command = le16_to_cpu(msg->command);
464 msg->controlselector = le16_to_cpu(msg->controlselector);
465 ret = SAA_OK;
466out:
467 mutex_unlock(&bus->lock);
Steven Toth60665822010-07-31 16:15:22 -0300468 saa7164_bus_verify(dev);
Steven Toth443c12282009-05-09 21:17:28 -0300469 return ret;
470}
471