source: rtems-libbsd/rtemsbsd/src/rtems-bsd-bus-dma-mbuf.c @ 2da0777

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since 2da0777 was 2da0777, checked in by Sebastian Huber <sebastian.huber@…>, on 04/18/12 at 12:59:28

Add BUS_DMA(9) support for mbufs

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