summaryrefslogtreecommitdiffstats
path: root/freebsd/sys/dev
diff options
context:
space:
mode:
authorAlex White <alex.white@oarcorp.com>2022-02-06 21:12:31 -0600
committerJoel Sherrill <joel@rtems.org>2022-03-07 17:04:05 -0600
commit40b9c6ce6343cea5ca51ca9831d381886583a508 (patch)
treeeaa2223412eb9a3be7d8540f6f281a7f5b40d70a /freebsd/sys/dev
parentif_xae: Import from FreeBSD (diff)
downloadrtems-libbsd-40b9c6ce6343cea5ca51ca9831d381886583a508.tar.bz2
if_xae: Port to RTEMS
Diffstat (limited to 'freebsd/sys/dev')
-rw-r--r--freebsd/sys/dev/xdma/xdma.c3
-rw-r--r--freebsd/sys/dev/xdma/xdma.h11
-rw-r--r--freebsd/sys/dev/xdma/xdma_sg.c13
-rw-r--r--freebsd/sys/dev/xilinx/axidma.c27
-rw-r--r--freebsd/sys/dev/xilinx/if_xae.c9
5 files changed, 63 insertions, 0 deletions
diff --git a/freebsd/sys/dev/xdma/xdma.c b/freebsd/sys/dev/xdma/xdma.c
index 685fedcc..98426f07 100644
--- a/freebsd/sys/dev/xdma/xdma.c
+++ b/freebsd/sys/dev/xdma/xdma.c
@@ -54,6 +54,9 @@ __FBSDID("$FreeBSD$");
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#endif
+#ifdef __rtems__
+#define IN_XDMA_C
+#endif /* __rtems__ */
#include <dev/xdma/xdma.h>
diff --git a/freebsd/sys/dev/xdma/xdma.h b/freebsd/sys/dev/xdma/xdma.h
index 583ad63e..685047ab 100644
--- a/freebsd/sys/dev/xdma/xdma.h
+++ b/freebsd/sys/dev/xdma/xdma.h
@@ -36,6 +36,9 @@
#include <sys/proc.h>
#include <sys/vmem.h>
+#ifdef __rtems__
+#include <dev/ofw/openfirm.h>
+#endif /* __rtems__ */
enum xdma_direction {
XDMA_MEM_TO_MEM,
@@ -181,7 +184,15 @@ struct xdma_intr_handler {
TAILQ_ENTRY(xdma_intr_handler) ih_next;
};
+#ifndef __rtems__
static MALLOC_DEFINE(M_XDMA, "xdma", "xDMA framework");
+#else /* __rtems__ */
+#ifdef IN_XDMA_C
+MALLOC_DEFINE(M_XDMA, "xdma", "xDMA framework");
+#else
+MALLOC_DECLARE(M_XDMA);
+#endif
+#endif /* __rtems__ */
#define XCHAN_LOCK(xchan) mtx_lock(&(xchan)->mtx_lock)
#define XCHAN_UNLOCK(xchan) mtx_unlock(&(xchan)->mtx_lock)
diff --git a/freebsd/sys/dev/xdma/xdma_sg.c b/freebsd/sys/dev/xdma/xdma_sg.c
index dfaf43e7..50057e89 100644
--- a/freebsd/sys/dev/xdma/xdma_sg.c
+++ b/freebsd/sys/dev/xdma/xdma_sg.c
@@ -75,11 +75,13 @@ xchan_bufs_free_reserved(xdma_channel_t *xchan)
for (i = 0; i < xchan->xr_num; i++) {
xr = &xchan->xr_mem[i];
size = xr->buf.size;
+#ifndef __rtems__
if (xr->buf.vaddr) {
pmap_kremove_device(xr->buf.vaddr, size);
kva_free(xr->buf.vaddr, size);
xr->buf.vaddr = 0;
}
+#endif /* __rtems__ */
if (xr->buf.paddr) {
vmem_free(xchan->vmem, xr->buf.paddr, size);
xr->buf.paddr = 0;
@@ -99,12 +101,15 @@ xchan_bufs_alloc_reserved(xdma_channel_t *xchan)
xdma = xchan->xdma;
+#ifndef __rtems__
if (xchan->vmem == NULL)
return (ENOBUFS);
+#endif /* __rtems__ */
for (i = 0; i < xchan->xr_num; i++) {
xr = &xchan->xr_mem[i];
size = round_page(xchan->maxsegsize);
+#ifndef __rtems__
if (vmem_alloc(xchan->vmem, size,
M_BESTFIT | M_NOWAIT, &addr)) {
device_printf(xdma->dev,
@@ -116,13 +121,19 @@ xchan_bufs_alloc_reserved(xdma_channel_t *xchan)
xr->buf.size = size;
xr->buf.paddr = addr;
xr->buf.vaddr = kva_alloc(size);
+#else /* __rtems__ */
+ xr->buf.vaddr = calloc(1,size);
+ xr->buf.paddr = xr->buf.vaddr;
+#endif /* __rtems__ */
if (xr->buf.vaddr == 0) {
device_printf(xdma->dev,
"%s: Can't allocate KVA\n", __func__);
xchan_bufs_free_reserved(xchan);
return (ENOMEM);
}
+#ifndef __rtems__
pmap_kenter_device(xr->buf.vaddr, size, addr);
+#endif /* __rtems__ */
}
return (0);
@@ -408,6 +419,7 @@ _xdma_load_data_busdma(xdma_channel_t *xchan, struct xdma_request *xr,
error = bus_dmamap_load_mbuf_sg(xchan->dma_tag_bufs,
xr->buf.map, xr->m, seg, &nsegs, BUS_DMA_NOWAIT);
break;
+#ifndef __rtems__
case XR_TYPE_BIO:
slr.nsegs = 0;
slr.error = 0;
@@ -422,6 +434,7 @@ _xdma_load_data_busdma(xdma_channel_t *xchan, struct xdma_request *xr,
}
nsegs = slr.nsegs;
break;
+#endif /* __rtems__ */
case XR_TYPE_VIRT:
switch (xr->direction) {
case XDMA_MEM_TO_DEV:
diff --git a/freebsd/sys/dev/xilinx/axidma.c b/freebsd/sys/dev/xilinx/axidma.c
index 087ebf05..20cd7f23 100644
--- a/freebsd/sys/dev/xilinx/axidma.c
+++ b/freebsd/sys/dev/xilinx/axidma.c
@@ -66,6 +66,12 @@ __FBSDID("$FreeBSD$");
#define AXIDMA_DEBUG
#undef AXIDMA_DEBUG
+#ifdef __rtems__
+#include <sys/endian.h>
+
+#define AXIDMA_DESCRIPTOR_ALIGNMENT 64
+#endif /* __rtems__ */
+
#ifdef AXIDMA_DEBUG
#define dprintf(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
@@ -178,6 +184,12 @@ axidma_intr(struct axidma_softc *sc,
st.error = errors;
st.transferred = desc->status & BD_CONTROL_LEN_M;
+#ifdef __rtems__
+ /* Handle Control / Status Streams. */
+ if (!st.transferred) {
+ st.transferred = desc->app4 & BD_STATUS_TRANSFERRED_M;
+ }
+#endif /* __rtems__ */
tot_copied += st.transferred;
xchan_seg_done(xchan, &st);
@@ -328,8 +340,10 @@ axidma_desc_free(struct axidma_softc *sc, struct axidma_channel *chan)
free(chan->descs, M_DEVBUF);
free(chan->descs_phys, M_DEVBUF);
+#ifndef __rtems__
pmap_kremove_device(chan->mem_vaddr, chan->mem_size);
kva_free(chan->mem_vaddr, chan->mem_size);
+#endif /* __rtems__ */
vmem_free(xchan->vmem, chan->mem_paddr, chan->mem_size);
return (0);
@@ -357,6 +371,7 @@ axidma_desc_alloc(struct axidma_softc *sc, struct xdma_channel *xchan,
chan->descs_phys = malloc(nsegments * sizeof(bus_dma_segment_t),
M_DEVBUF, M_NOWAIT | M_ZERO);
chan->mem_size = desc_size * nsegments;
+#ifndef __rtems__
if (vmem_alloc(xchan->vmem, chan->mem_size, M_FIRSTFIT | M_NOWAIT,
&chan->mem_paddr)) {
device_printf(sc->dev, "Failed to allocate memory.\n");
@@ -364,6 +379,13 @@ axidma_desc_alloc(struct axidma_softc *sc, struct xdma_channel *xchan,
}
chan->mem_vaddr = kva_alloc(chan->mem_size);
pmap_kenter_device(chan->mem_vaddr, chan->mem_size, chan->mem_paddr);
+#else /* __rtems__ */
+ /* Align DMA descriptors */
+ chan->mem_vaddr = calloc(1, chan->mem_size + AXIDMA_DESCRIPTOR_ALIGNMENT - 1);
+ chan->mem_vaddr = ((uintptr_t)chan->mem_vaddr +
+ AXIDMA_DESCRIPTOR_ALIGNMENT - 1) & ~0x3F;
+ chan->mem_paddr = chan->mem_vaddr;
+#endif /* __rtems__ */
device_printf(sc->dev, "Allocated chunk %lx %d\n",
chan->mem_paddr, chan->mem_size);
@@ -559,8 +581,13 @@ axidma_channel_prep_sg(device_t dev, struct xdma_channel *xchan)
desc->status = 0;
desc->control = 0;
+#ifndef __rtems__
dprintf("%s(%d): desc %d vaddr %lx next paddr %x\n", __func__,
data->id, i, (uint64_t)desc, le32toh(desc->next));
+#else /* __rtems__ */
+ dprintf("%s(%d): desc %d vaddr %lx next paddr %x\n", __func__,
+ data->id, i, desc, le32toh(desc->next));
+#endif /* __rtems__ */
}
addr = chan->descs_phys[0];
diff --git a/freebsd/sys/dev/xilinx/if_xae.c b/freebsd/sys/dev/xilinx/if_xae.c
index 425bef4f..e01a3abe 100644
--- a/freebsd/sys/dev/xilinx/if_xae.c
+++ b/freebsd/sys/dev/xilinx/if_xae.c
@@ -145,6 +145,9 @@ xae_rx_enqueue(struct xae_softc *sc, uint32_t n)
}
m->m_pkthdr.len = m->m_len = m->m_ext.ext_size;
+#ifdef __rtems__
+ m_adj(m, ETHER_ALIGN);
+#endif /* __rtems__ */
xdma_enqueue_mbuf(sc->xchan_rx, &m, 0, 4, 4, XDMA_DEV_TO_MEM);
}
@@ -717,7 +720,11 @@ xae_miibus_read_reg(device_t dev, int phy, int reg)
rv = READ4(sc, XAE_MDIO_READ);
+#ifndef __rtems__
return (rv);
+#else /* __rtems__ */
+ return (rv & 0xFFFF);
+#endif /* __rtems__ */
}
static int
@@ -830,12 +837,14 @@ setup_xdma(struct xae_softc *sc)
return (ENXIO);
}
+#ifndef __rtems__
/* Setup bounce buffer */
vmem = xdma_get_memory(dev);
if (vmem) {
xchan_set_memory(sc->xchan_tx, vmem);
xchan_set_memory(sc->xchan_rx, vmem);
}
+#endif /* __rtems__ */
xdma_prep_sg(sc->xchan_tx,
TX_QUEUE_SIZE, /* xchan requests queue size */