diff --git a/buildset/default.ini b/buildset/default.ini index 5f9b81a5..fca70f9c 100644 --- a/buildset/default.ini +++ b/buildset/default.ini @@ -23,6 +23,7 @@ dev_nic = on dev_nic_broadcomm = on dev_nic_dc = on dev_nic_e1000 = on +dev_nic_xilinx = on dev_nic_fxp = on dev_nic_re = on dev_nic_smc = on 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 #include #endif +#ifdef __rtems__ +#define IN_XDMA_C +#endif /* __rtems__ */ #include 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 #include +#ifdef __rtems__ +#include +#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 + +#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 */ diff --git a/libbsd.py b/libbsd.py index 5ccb62fa..1469b8df 100644 --- a/libbsd.py +++ b/libbsd.py @@ -177,6 +177,7 @@ class rtems(builder.Module): 'local/ofw_if.c', 'local/pcib_if.c', 'local/pci_if.c', + 'local/xdma_if.c', 'local/usb_if.c', 'local/mmcbus_if.c', 'local/mmcbr_if.c', @@ -1660,6 +1661,39 @@ class dev_nic_e1000(builder.Module): mm.generator['source']() ) +# +# NIC xilinx +# +class dev_nic_xilinx(builder.Module): + + def __init__(self, manager): + super(dev_nic_xilinx, self).__init__(manager, type(self).__name__) + + def generate(self): + mm = self.manager + self.addKernelSpaceHeaderFiles( + [ + 'sys/dev/xilinx/if_xaereg.h', + 'sys/dev/xilinx/if_xaevar.h', + 'sys/dev/mii/tiphy.h', + 'sys/dev/xdma/xdma.h', + 'sys/dev/xilinx/axidma.h', + ] + ) + self.addKernelSpaceSourceFiles( + [ + 'sys/dev/xilinx/if_xae.c', + 'sys/dev/xdma/xdma.c', + 'sys/dev/xdma/xdma_mbuf.c', + 'sys/dev/xdma/xdma_queue.c', + 'sys/dev/xdma/xdma_sg.c', + 'sys/dev/xdma/xdma_bank.c', + 'sys/dev/xdma/xdma_sglist.c', + 'sys/dev/xilinx/axidma.c', + ], + mm.generator['source']() + ) + # # DEC Tulip aka Intel 21143 # @@ -5612,6 +5646,7 @@ def load(mm): mm.addModule(dev_nic_re(mm)) mm.addModule(dev_nic_fxp(mm)) mm.addModule(dev_nic_e1000(mm)) + mm.addModule(dev_nic_xilinx(mm)) mm.addModule(dev_nic_dc(mm)) mm.addModule(dev_nic_smc(mm)) mm.addModule(dev_nic_broadcomm(mm)) diff --git a/rtemsbsd/include/bsp/nexus-devices.h b/rtemsbsd/include/bsp/nexus-devices.h index d39edf22..8be29a1c 100644 --- a/rtemsbsd/include/bsp/nexus-devices.h +++ b/rtemsbsd/include/bsp/nexus-devices.h @@ -277,6 +277,14 @@ RTEMS_BSD_DRIVER_PC_LEGACY; RTEMS_BSD_DRIVER_PCI_DC; RTEMS_BSD_DRIVER_UKPHY; -#endif /* LIBBSP_POWERPC_MOTOROLA_POWERPC_BSP_H */ +#elif defined(LIBBSP_MICROBLAZE_FPGA_BSP_H) + +RTEMS_BSD_DEFINE_NEXUS_DEVICE(ofwbus, 0, 0, NULL); +SYSINIT_DRIVER_REFERENCE(simplebus, ofwbus); +SYSINIT_DRIVER_REFERENCE(xae, simplebus); +SYSINIT_DRIVER_REFERENCE(axidma, simplebus); +RTEMS_BSD_DRIVER_E1000PHY; + +#endif /* LIBBSP_MICROBLAZE_FPGA_BSP_H */ #endif diff --git a/rtemsbsd/include/rtems/bsd/local/xdma_if.h b/rtemsbsd/include/rtems/bsd/local/xdma_if.h new file mode 100644 index 00000000..e5271f60 --- /dev/null +++ b/rtemsbsd/include/rtems/bsd/local/xdma_if.h @@ -0,0 +1,144 @@ +/* + * This file is produced automatically. + * Do not modify anything in here by hand. + * + * Created from source file + * xdma_if.m + * with + * makeobjops.awk + * + * See the source file for legal information + */ + + +#ifndef _xdma_if_h_ +#define _xdma_if_h_ + +/** @brief Unique descriptor for the XDMA_CHANNEL_REQUEST() method */ +extern struct kobjop_desc xdma_channel_request_desc; +/** @brief A function implementing the XDMA_CHANNEL_REQUEST() method */ +typedef int xdma_channel_request_t(device_t dev, struct xdma_channel *xchan, + struct xdma_request *req); + +static __inline int XDMA_CHANNEL_REQUEST(device_t dev, + struct xdma_channel *xchan, + struct xdma_request *req) +{ + kobjop_t _m; + int rc; + KOBJOPLOOKUP(((kobj_t)dev)->ops,xdma_channel_request); + rc = ((xdma_channel_request_t *) _m)(dev, xchan, req); + return (rc); +} + +/** @brief Unique descriptor for the XDMA_CHANNEL_PREP_SG() method */ +extern struct kobjop_desc xdma_channel_prep_sg_desc; +/** @brief A function implementing the XDMA_CHANNEL_PREP_SG() method */ +typedef int xdma_channel_prep_sg_t(device_t dev, struct xdma_channel *xchan); + +static __inline int XDMA_CHANNEL_PREP_SG(device_t dev, + struct xdma_channel *xchan) +{ + kobjop_t _m; + int rc; + KOBJOPLOOKUP(((kobj_t)dev)->ops,xdma_channel_prep_sg); + rc = ((xdma_channel_prep_sg_t *) _m)(dev, xchan); + return (rc); +} + +/** @brief Unique descriptor for the XDMA_CHANNEL_CAPACITY() method */ +extern struct kobjop_desc xdma_channel_capacity_desc; +/** @brief A function implementing the XDMA_CHANNEL_CAPACITY() method */ +typedef int xdma_channel_capacity_t(device_t dev, struct xdma_channel *xchan, + uint32_t *capacity); + +static __inline int XDMA_CHANNEL_CAPACITY(device_t dev, + struct xdma_channel *xchan, + uint32_t *capacity) +{ + kobjop_t _m; + int rc; + KOBJOPLOOKUP(((kobj_t)dev)->ops,xdma_channel_capacity); + rc = ((xdma_channel_capacity_t *) _m)(dev, xchan, capacity); + return (rc); +} + +/** @brief Unique descriptor for the XDMA_CHANNEL_SUBMIT_SG() method */ +extern struct kobjop_desc xdma_channel_submit_sg_desc; +/** @brief A function implementing the XDMA_CHANNEL_SUBMIT_SG() method */ +typedef int xdma_channel_submit_sg_t(device_t dev, struct xdma_channel *xchan, + struct xdma_sglist *sg, uint32_t sg_n); + +static __inline int XDMA_CHANNEL_SUBMIT_SG(device_t dev, + struct xdma_channel *xchan, + struct xdma_sglist *sg, + uint32_t sg_n) +{ + kobjop_t _m; + int rc; + KOBJOPLOOKUP(((kobj_t)dev)->ops,xdma_channel_submit_sg); + rc = ((xdma_channel_submit_sg_t *) _m)(dev, xchan, sg, sg_n); + return (rc); +} + +/** @brief Unique descriptor for the XDMA_OFW_MD_DATA() method */ +extern struct kobjop_desc xdma_ofw_md_data_desc; +/** @brief A function implementing the XDMA_OFW_MD_DATA() method */ +typedef int xdma_ofw_md_data_t(device_t dev, pcell_t *cells, int ncells, + void **data); + +static __inline int XDMA_OFW_MD_DATA(device_t dev, pcell_t *cells, int ncells, + void **data) +{ + kobjop_t _m; + int rc; + KOBJOPLOOKUP(((kobj_t)dev)->ops,xdma_ofw_md_data); + rc = ((xdma_ofw_md_data_t *) _m)(dev, cells, ncells, data); + return (rc); +} + +/** @brief Unique descriptor for the XDMA_CHANNEL_ALLOC() method */ +extern struct kobjop_desc xdma_channel_alloc_desc; +/** @brief A function implementing the XDMA_CHANNEL_ALLOC() method */ +typedef int xdma_channel_alloc_t(device_t dev, struct xdma_channel *xchan); + +static __inline int XDMA_CHANNEL_ALLOC(device_t dev, struct xdma_channel *xchan) +{ + kobjop_t _m; + int rc; + KOBJOPLOOKUP(((kobj_t)dev)->ops,xdma_channel_alloc); + rc = ((xdma_channel_alloc_t *) _m)(dev, xchan); + return (rc); +} + +/** @brief Unique descriptor for the XDMA_CHANNEL_FREE() method */ +extern struct kobjop_desc xdma_channel_free_desc; +/** @brief A function implementing the XDMA_CHANNEL_FREE() method */ +typedef int xdma_channel_free_t(device_t dev, struct xdma_channel *xchan); + +static __inline int XDMA_CHANNEL_FREE(device_t dev, struct xdma_channel *xchan) +{ + kobjop_t _m; + int rc; + KOBJOPLOOKUP(((kobj_t)dev)->ops,xdma_channel_free); + rc = ((xdma_channel_free_t *) _m)(dev, xchan); + return (rc); +} + +/** @brief Unique descriptor for the XDMA_CHANNEL_CONTROL() method */ +extern struct kobjop_desc xdma_channel_control_desc; +/** @brief A function implementing the XDMA_CHANNEL_CONTROL() method */ +typedef int xdma_channel_control_t(device_t dev, struct xdma_channel *xchan, + int cmd); + +static __inline int XDMA_CHANNEL_CONTROL(device_t dev, + struct xdma_channel *xchan, int cmd) +{ + kobjop_t _m; + int rc; + KOBJOPLOOKUP(((kobj_t)dev)->ops,xdma_channel_control); + rc = ((xdma_channel_control_t *) _m)(dev, xchan, cmd); + return (rc); +} + +#endif /* _xdma_if_h_ */ diff --git a/rtemsbsd/local/xdma_if.c b/rtemsbsd/local/xdma_if.c new file mode 100644 index 00000000..9b3c86a5 --- /dev/null +++ b/rtemsbsd/local/xdma_if.c @@ -0,0 +1,56 @@ +#include + +/* + * This file is produced automatically. + * Do not modify anything in here by hand. + * + * Created from source file + * xdma_if.m + * with + * makeobjops.awk + * + * See the source file for legal information + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct kobjop_desc xdma_channel_request_desc = { + 0, { &xdma_channel_request_desc, (kobjop_t)kobj_error_method } +}; + +struct kobjop_desc xdma_channel_prep_sg_desc = { + 0, { &xdma_channel_prep_sg_desc, (kobjop_t)kobj_error_method } +}; + +struct kobjop_desc xdma_channel_capacity_desc = { + 0, { &xdma_channel_capacity_desc, (kobjop_t)kobj_error_method } +}; + +struct kobjop_desc xdma_channel_submit_sg_desc = { + 0, { &xdma_channel_submit_sg_desc, (kobjop_t)kobj_error_method } +}; + +struct kobjop_desc xdma_ofw_md_data_desc = { + 0, { &xdma_ofw_md_data_desc, (kobjop_t)kobj_error_method } +}; + +struct kobjop_desc xdma_channel_alloc_desc = { + 0, { &xdma_channel_alloc_desc, (kobjop_t)kobj_error_method } +}; + +struct kobjop_desc xdma_channel_free_desc = { + 0, { &xdma_channel_free_desc, (kobjop_t)kobj_error_method } +}; + +struct kobjop_desc xdma_channel_control_desc = { + 0, { &xdma_channel_control_desc, (kobjop_t)kobj_error_method } +}; diff --git a/testsuite/include/rtems/bsd/test/network-config.h.in b/testsuite/include/rtems/bsd/test/network-config.h.in index fd63eded..69609854 100755 --- a/testsuite/include/rtems/bsd/test/network-config.h.in +++ b/testsuite/include/rtems/bsd/test/network-config.h.in @@ -52,6 +52,8 @@ #endif #elif defined(LIBBSP_ARM_ATSAM_BSP_H) #define NET_CFG_INTERFACE_0 "if_atsam0" +#elif defined(LIBBSP_MICROBLAZE_FPGA_BSP_H) + #define NET_CFG_INTERFACE_0 "xae0" #else #define NET_CFG_INTERFACE_0 "@NET_CFG_INTERFACE_0@" #endif