mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-07-26 06:00:32 +08:00
Add BUS_DMA(9) support for mbufs
This commit is contained in:
parent
60ed79571d
commit
2da0777f66
1
Makefile
1
Makefile
@ -46,6 +46,7 @@ C_FILES += rtemsbsd/src/rtems-bsd-smp.c
|
||||
C_FILES += rtemsbsd/src/rtems-bsd-malloc.c
|
||||
C_FILES += rtemsbsd/src/rtems-bsd-support.c
|
||||
C_FILES += rtemsbsd/src/rtems-bsd-bus-dma.c
|
||||
C_FILES += rtemsbsd/src/rtems-bsd-bus-dma-mbuf.c
|
||||
C_FILES += rtemsbsd/src/rtems-bsd-sysctl.c
|
||||
C_FILES += rtemsbsd/src/rtems-bsd-sysctlbyname.c
|
||||
C_FILES += rtemsbsd/src/rtems-bsd-sysctlnametomib.c
|
||||
|
@ -502,6 +502,7 @@ rtems.addRTEMSHeaderFiles(
|
||||
'rtems/machine/rtems-bsd-sysinit.h',
|
||||
'rtems/machine/rtems-bsd-select.h',
|
||||
'rtems/machine/rtems-bsd-taskqueue.h',
|
||||
'rtems/machine/rtems-bsd-bus-dma.h',
|
||||
'bsd.h',
|
||||
]
|
||||
)
|
||||
@ -539,6 +540,7 @@ rtems.addRTEMSSourceFiles(
|
||||
'src/rtems-bsd-malloc.c',
|
||||
'src/rtems-bsd-support.c',
|
||||
'src/rtems-bsd-bus-dma.c',
|
||||
'src/rtems-bsd-bus-dma-mbuf.c',
|
||||
'src/rtems-bsd-sysctl.c',
|
||||
'src/rtems-bsd-sysctlbyname.c',
|
||||
'src/rtems-bsd-sysctlnametomib.c',
|
||||
|
85
rtemsbsd/freebsd/machine/rtems-bsd-bus-dma.h
Normal file
85
rtemsbsd/freebsd/machine/rtems-bsd-bus-dma.h
Normal file
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_bsd_machine
|
||||
*
|
||||
* @brief TODO.
|
||||
*
|
||||
* File origin from FreeBSD "sys/powerpc/powerpc/busdma_machdep.c".
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Obere Lagerstr. 30
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* Copyright (c) 2004 Olivier Houchard
|
||||
* Copyright (c) 2002 Peter Grehan
|
||||
* Copyright (c) 1997, 1998 Justin T. Gibbs.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions, and the following disclaimer,
|
||||
* without modification, immediately at the beginning of the file.
|
||||
* 2. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _RTEMS_BSD_MACHINE_RTEMS_BSD_BUS_DMA_H_
|
||||
#define _RTEMS_BSD_MACHINE_RTEMS_BSD_BUS_DMA_H_
|
||||
|
||||
#include <freebsd/sys/param.h>
|
||||
#include <freebsd/sys/types.h>
|
||||
#include <freebsd/sys/lock.h>
|
||||
#include <freebsd/sys/mutex.h>
|
||||
#include <freebsd/sys/systm.h>
|
||||
#include <freebsd/machine/bus.h>
|
||||
|
||||
struct bus_dma_tag {
|
||||
bus_dma_tag_t parent;
|
||||
bus_size_t alignment;
|
||||
bus_size_t boundary;
|
||||
bus_addr_t lowaddr;
|
||||
bus_addr_t highaddr;
|
||||
bus_dma_filter_t *filter;
|
||||
void *filterarg;
|
||||
bus_size_t maxsize;
|
||||
int nsegments;
|
||||
bus_size_t maxsegsz;
|
||||
int flags;
|
||||
int ref_count;
|
||||
int map_count;
|
||||
bus_dma_lock_t *lockfunc;
|
||||
void *lockfuncarg;
|
||||
};
|
||||
|
||||
struct bus_dmamap {
|
||||
void *buffer_begin;
|
||||
bus_size_t buffer_size;
|
||||
};
|
||||
|
||||
int
|
||||
bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dma_segment_t segs[],
|
||||
void *buf, bus_size_t buflen, struct thread *td, int flags,
|
||||
vm_offset_t *lastaddrp, int *segp, int first);
|
||||
|
||||
#endif /* _RTEMS_BSD_MACHINE_RTEMS_BSD_BUS_DMA_H_ */
|
128
rtemsbsd/src/rtems-bsd-bus-dma-mbuf.c
Normal file
128
rtemsbsd/src/rtems-bsd-bus-dma-mbuf.c
Normal file
@ -0,0 +1,128 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_bsd_rtems
|
||||
*
|
||||
* @brief TODO.
|
||||
*
|
||||
* File origin from FreeBSD "sys/powerpc/powerpc/busdma_machdep.c".
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2012 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Obere Lagerstr. 30
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* Copyright (c) 1997, 1998 Justin T. Gibbs.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions, and the following disclaimer,
|
||||
* without modification, immediately at the beginning of the file.
|
||||
* 2. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <freebsd/machine/rtems-bsd-config.h>
|
||||
#include <freebsd/machine/rtems-bsd-bus-dma.h>
|
||||
|
||||
#include <freebsd/sys/mbuf.h>
|
||||
|
||||
/*
|
||||
* Like bus_dmamap_load(), but for mbufs.
|
||||
*/
|
||||
int
|
||||
bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct mbuf *m0,
|
||||
bus_dmamap_callback2_t *callback, void *callback_arg,
|
||||
int flags)
|
||||
{
|
||||
bus_dma_segment_t dm_segments[dmat->nsegments];
|
||||
int nsegs, error;
|
||||
|
||||
M_ASSERTPKTHDR(m0);
|
||||
|
||||
flags |= BUS_DMA_NOWAIT;
|
||||
nsegs = 0;
|
||||
error = 0;
|
||||
if (m0->m_pkthdr.len <= dmat->maxsize) {
|
||||
int first = 1;
|
||||
bus_addr_t lastaddr = 0;
|
||||
struct mbuf *m;
|
||||
|
||||
for (m = m0; m != NULL && error == 0; m = m->m_next) {
|
||||
if (m->m_len > 0) {
|
||||
error = bus_dmamap_load_buffer(dmat, dm_segments,
|
||||
m->m_data, m->m_len,
|
||||
NULL, flags, &lastaddr,
|
||||
&nsegs, first);
|
||||
first = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error = EINVAL;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
/* force "no valid mappings" in callback */
|
||||
(*callback)(callback_arg, dm_segments, 0, 0, error);
|
||||
} else {
|
||||
(*callback)(callback_arg, dm_segments,
|
||||
nsegs+1, m0->m_pkthdr.len, error);
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
bus_dmamap_load_mbuf_sg(bus_dma_tag_t dmat, bus_dmamap_t map,
|
||||
struct mbuf *m0, bus_dma_segment_t *segs, int *nsegs,
|
||||
int flags)
|
||||
{
|
||||
int error;
|
||||
|
||||
M_ASSERTPKTHDR(m0);
|
||||
|
||||
flags |= BUS_DMA_NOWAIT;
|
||||
*nsegs = 0;
|
||||
error = 0;
|
||||
if (m0->m_pkthdr.len <= dmat->maxsize) {
|
||||
int first = 1;
|
||||
bus_addr_t lastaddr = 0;
|
||||
struct mbuf *m;
|
||||
|
||||
for (m = m0; m != NULL && error == 0; m = m->m_next) {
|
||||
if (m->m_len > 0) {
|
||||
error = bus_dmamap_load_buffer(dmat, segs,
|
||||
m->m_data, m->m_len,
|
||||
NULL, flags, &lastaddr,
|
||||
nsegs, first);
|
||||
first = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error = EINVAL;
|
||||
}
|
||||
|
||||
/* XXX FIXME: Having to increment nsegs is really annoying */
|
||||
++*nsegs;
|
||||
return (error);
|
||||
}
|
@ -5,11 +5,11 @@
|
||||
*
|
||||
* @brief TODO.
|
||||
*
|
||||
* File origin from FreeBSD 'sys/powerpc/powerpc/busdma_machdep.c'.
|
||||
* File origin from FreeBSD "sys/powerpc/powerpc/busdma_machdep.c".
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved.
|
||||
* Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Obere Lagerstr. 30
|
||||
@ -46,45 +46,18 @@
|
||||
|
||||
#include <freebsd/machine/rtems-bsd-config.h>
|
||||
#include <freebsd/machine/rtems-bsd-cache.h>
|
||||
#include <freebsd/machine/rtems-bsd-bus-dma.h>
|
||||
|
||||
#include <rtems/malloc.h>
|
||||
|
||||
#include <freebsd/sys/param.h>
|
||||
#include <freebsd/sys/types.h>
|
||||
#include <freebsd/sys/lock.h>
|
||||
#include <freebsd/sys/mutex.h>
|
||||
#include <freebsd/sys/systm.h>
|
||||
#include <freebsd/sys/malloc.h>
|
||||
#include <freebsd/machine/atomic.h>
|
||||
#include <freebsd/machine/bus.h>
|
||||
|
||||
#ifdef CPU_DATA_CACHE_ALIGNMENT
|
||||
#define CLSZ ((uintptr_t) CPU_DATA_CACHE_ALIGNMENT)
|
||||
#define CLMASK (CLSZ - (uintptr_t) 1)
|
||||
#endif
|
||||
|
||||
struct bus_dma_tag {
|
||||
bus_dma_tag_t parent;
|
||||
bus_size_t alignment;
|
||||
bus_size_t boundary;
|
||||
bus_addr_t lowaddr;
|
||||
bus_addr_t highaddr;
|
||||
bus_dma_filter_t *filter;
|
||||
void *filterarg;
|
||||
bus_size_t maxsize;
|
||||
int nsegments;
|
||||
bus_size_t maxsegsz;
|
||||
int flags;
|
||||
int ref_count;
|
||||
int map_count;
|
||||
bus_dma_lock_t *lockfunc;
|
||||
void *lockfuncarg;
|
||||
};
|
||||
|
||||
struct bus_dmamap {
|
||||
void *buffer_begin;
|
||||
bus_size_t buffer_size;
|
||||
};
|
||||
|
||||
/*
|
||||
* Convenience function for manipulating driver locks from busdma (during
|
||||
* busdma_swi, for example). Drivers that don't provide their own locks
|
||||
@ -297,7 +270,7 @@ bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
|
||||
* the starting segment on entrance, and the ending segment on exit.
|
||||
* first indicates if this is the first invocation of this function.
|
||||
*/
|
||||
static int
|
||||
int
|
||||
bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dma_segment_t segs[],
|
||||
void *buf, bus_size_t buflen, struct thread *td, int flags,
|
||||
vm_offset_t *lastaddrp, int *segp, int first)
|
||||
|
Loading…
x
Reference in New Issue
Block a user