source: rtems-libbsd/rtemsbsd/src/rtems-bsd-bus-dma-mbuf.c @ 8420b94

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 8420b94 was 8420b94, checked in by Jennifer Averett <jennifer.averett@…>, on 05/08/12 at 14:14:42

Modified copyright on rtems-bsd-xxx files to be consistant with FreeBSD copyright.

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[2da0777]1/**
2 * @file
3 *
4 * @ingroup rtems_bsd_rtems
5 *
6 * @brief TODO.
7 *
8 * File origin from FreeBSD "sys/powerpc/powerpc/busdma_machdep.c".
9 */
10
11/*-
[8420b94]12 * Copyright (c) 2012 embedded brains GmbH. 
13 * All rights reserved.
[2da0777]14 *
15 *  embedded brains GmbH
16 *  Obere Lagerstr. 30
17 *  82178 Puchheim
18 *  Germany
19 *  <rtems@embedded-brains.de>
20 *
21 * Copyright (c) 1997, 1998 Justin T. Gibbs.
22 * All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 * 1. Redistributions of source code must retain the above copyright
28 *    notice, this list of conditions, and the following disclaimer,
29 *    without modification, immediately at the beginning of the file.
30 * 2. The name of the author may not be used to endorse or promote products
31 *    derived from this software without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
37 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * SUCH DAMAGE.
44 */
45
46#include <freebsd/machine/rtems-bsd-config.h>
47#include <freebsd/machine/rtems-bsd-bus-dma.h>
48
49#include <freebsd/sys/mbuf.h>
50
51/*
52 * Like bus_dmamap_load(), but for mbufs.
53 */
54int
55bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map,
56                     struct mbuf *m0,
57                     bus_dmamap_callback2_t *callback, void *callback_arg,
58                     int flags)
59{
60        bus_dma_segment_t dm_segments[dmat->nsegments];
61        int nsegs, error;
62
63        M_ASSERTPKTHDR(m0);
64
65        flags |= BUS_DMA_NOWAIT;
66        nsegs = 0;
67        error = 0;
68        if (m0->m_pkthdr.len <= dmat->maxsize) {
69                int first = 1;
70                bus_addr_t lastaddr = 0;
71                struct mbuf *m;
72
73                for (m = m0; m != NULL && error == 0; m = m->m_next) {
74                        if (m->m_len > 0) {
75                                error = bus_dmamap_load_buffer(dmat, dm_segments,
76                                                m->m_data, m->m_len,
77                                                NULL, flags, &lastaddr,
78                                                &nsegs, first);
79                                first = 0;
80                        }
81                }
82        } else {
83                error = EINVAL;
84        }
85
86        if (error) {
87                /* force "no valid mappings" in callback */
88                (*callback)(callback_arg, dm_segments, 0, 0, error);
89        } else {
90                (*callback)(callback_arg, dm_segments,
91                            nsegs+1, m0->m_pkthdr.len, error);
92        }
93        return (error);
94}
95
96int
97bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map,
98                        struct mbuf *m0, bus_dma_segment_t *segs, int *nsegs,
99                        int flags)
100{
101        int error;
102
103        M_ASSERTPKTHDR(m0);
104
105        flags |= BUS_DMA_NOWAIT;
106        *nsegs = 0;
107        error = 0;
108        if (m0->m_pkthdr.len <= dmat->maxsize) {
109                int first = 1;
110                bus_addr_t lastaddr = 0;
111                struct mbuf *m;
112
113                for (m = m0; m != NULL && error == 0; m = m->m_next) {
114                        if (m->m_len > 0) {
115                                error = bus_dmamap_load_buffer(dmat, segs,
116                                                m->m_data, m->m_len,
117                                                NULL, flags, &lastaddr,
118                                                nsegs, first);
119                                first = 0;
120                        }
121                }
122        } else {
123                error = EINVAL;
124        }
125
126        /* XXX FIXME: Having to increment nsegs is really annoying */
127        ++*nsegs;
128        return (error);
129}
Note: See TracBrowser for help on using the repository browser.