Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A network driver for Xilinx UltraScale+ 64-bits(v2) #22

Merged
merged 3 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
474 changes: 474 additions & 0 deletions portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions portable/NetworkInterface/xilinx_ultrascale/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
NetworkInterface for Xilinx' UltraScale+, running on Cortex A53, 64-bits

Please include the following source files:

$(PLUS_TCP_PATH)/portable/NetworkInterface/xilinx_ultrascale/NetworkInterface.c
$(PLUS_TCP_PATH)/portable/NetworkInterface/xilinx_ultrascale/uncached_memory.c
$(PLUS_TCP_PATH)/portable/NetworkInterface/xilinx_ultrascale/x_emacpsif_dma.c
$(PLUS_TCP_PATH)/portable/NetworkInterface/xilinx_ultrascale/x_emacpsif_physpeed.c
$(PLUS_TCP_PATH)/portable/NetworkInterface/xilinx_ultrascale/x_emacpsif_hw.c

And include the following source files from the Xilinx library:

$(PROCESSOR)/libsrc/emacps_v3_9/src/xemacps.c
$(PROCESSOR)/libsrc/emacps_v3_9/src/xemacps_control.c
$(PROCESSOR)/libsrc/emacps_v3_9/src/xemacps_g.c
$(PROCESSOR)/libsrc/emacps_v3_9/src/xemacps_intr.c

E.g. psu_cortexa53_0/libsrc/emacps_v3_9/src/xemacps_intr.c

The following source files are NOT used for the FreeRTOS+TCP interface:

$(PROCESSOR)/libsrc/emacps_v3_9/src/xemacps_bdring.c
$(PROCESSOR)/libsrc/emacps_v3_9/src/xemacps_hw.c
$(PROCESSOR)/libsrc/emacps_v3_9/src/xemacps_sinit.c


It is recommended to have these defined :

#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1

#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM 1


It is obligatory to define these in your FreeRTOSIPConfig.h :

#define ipconfigZERO_COPY_RX_DRIVER 1

#define ipconfigZERO_COPY_TX_DRIVER 1


Please link you project with BufferAllocation_1.c ( not xxx_2.c ).

The following option causes the memory of the network packets to be allocated
in normal ( cached ) memory. With this option, TCP processing seems a faster
than without this option.

#define nicUSE_UNCACHED_MEMORY 0
167 changes: 167 additions & 0 deletions portable/NetworkInterface/xilinx_ultrascale/uncached_memory.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* FreeRTOS V202002.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://aws.amazon.com/freertos
* http://www.FreeRTOS.org
*/

/*
* uncached_memory.c
*
* This module will declare 1 MB of memory and switch off the caching for it.
*
* pucGetUncachedMemory( ulSize ) returns a trunc of this memory with a length
* rounded up to a multiple of 4 KB.
*
* ucIsCachedMemory( pucBuffer ) returns non-zero if a given pointer is NOT
* within the range of the 1 MB non-cached memory.
*
*/

/*
* After "_end", 1 MB of uncached memory will be allocated for DMA transfers.
* Both the DMA descriptors as well as all EMAC TX-buffers will be allocated in
* uncached memory.
*/

/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_IP_Private.h"

#include "x_emacpsif.h"
#include "x_topology.h"
#include "xstatus.h"

#include "xparameters.h"
#include "xparameters_ps.h"
#include "xil_exception.h"
#include "xil_mmu.h"

#include "uncached_memory.h"

#if ( ipconfigULTRASCALE == 1 )
/* Reserve 2 MB of memory. */
#define uncMEMORY_SIZE 0x200000U
#define DDR_MEMORY_END ( XPAR_PSU_DDR_0_S_AXI_HIGHADDR )
#define uncMEMORY_ATTRIBUTE NORM_NONCACHE | INNER_SHAREABLE
#else
/* Reserve 1 MB of memory. */
#define uncMEMORY_SIZE 0x100000U
#define DDR_MEMORY_END ( XPAR_PS7_DDR_0_S_AXI_HIGHADDR + 1 )
#define uncMEMORY_ATTRIBUTE 0x1C02
#endif /* ( ipconfigULTRASCALE == 1 ) */

/* Make sure that each pointer has an alignment of 4 KB. */
#define uncALIGNMENT_SIZE 0x1000uL

static void vInitialiseUncachedMemory( void );

static uint8_t pucUncachedMemory[ uncMEMORY_SIZE ] __attribute__( ( aligned( uncMEMORY_SIZE ) ) );
static uint8_t *pucHeadOfMemory;
static uint32_t ulMemorySize;
static uint8_t *pucStartOfMemory = NULL;

/* The linker file defines some pseudo variables. '_end' is one of them.
It is located at the first free byte in RAM. */
extern u8 _end;

/*-----------------------------------------------------------*/

uint8_t ucIsCachedMemory( const uint8_t *pucBuffer )
{
uint8_t ucReturn;

if( ( pucStartOfMemory != NULL ) &&
( pucBuffer >= pucStartOfMemory ) &&
( pucBuffer < ( pucStartOfMemory + uncMEMORY_SIZE ) ) )
{
ucReturn = pdFALSE;
}
else
{
ucReturn = pdTRUE;
}

return ucReturn;
}
/*-----------------------------------------------------------*/

uint8_t * pucGetUncachedMemory( uint32_t ulSize )
{
uint8_t *pucReturn;
uint32_t ulSkipSize;

if( pucStartOfMemory == NULL )
{
vInitialiseUncachedMemory();
}

if( ( pucStartOfMemory == NULL ) || ( ulSize > ulMemorySize ) )
{
pucReturn = NULL;
}
else
{
pucReturn = pucHeadOfMemory;
/* Make sure that the next pointer return will have a good alignment. */
ulSkipSize = ( ulSize + uncALIGNMENT_SIZE ) & ~( uncALIGNMENT_SIZE - 1uL );
pucHeadOfMemory += ulSkipSize;
ulMemorySize -= ulSkipSize;
}

return pucReturn;
}
/*-----------------------------------------------------------*/

static void vInitialiseUncachedMemory()
{
/* At the end of program's space... */
pucStartOfMemory = pucUncachedMemory;

if( ( ( uintptr_t ) pucStartOfMemory ) + uncMEMORY_SIZE > DDR_MEMORY_END )
{
FreeRTOS_printf( ( "vInitialiseUncachedMemory: Can not allocate uncached memory\n" ) );
}
else
{
/* Some objects want to be stored in uncached memory. Hence the 1 MB
address range that starts after "_end" is made uncached by setting
appropriate attributes in the translation table. */
Xil_SetTlbAttributes( ( uintptr_t ) pucStartOfMemory, uncMEMORY_ATTRIBUTE );

/* For experiments in the SDIO driver, make the remaining uncached memory
public */
pucHeadOfMemory = pucStartOfMemory;
ulMemorySize = uncMEMORY_SIZE;
memset( pucStartOfMemory, '\0', uncMEMORY_SIZE );
}
}
22 changes: 22 additions & 0 deletions portable/NetworkInterface/xilinx_ultrascale/uncached_memory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* uncached_memory.h
*
* This module will declare 1 MB of memory and switch off the caching for it.
*
* pucGetUncachedMemory( ulSize ) returns a trunc of this memory with a length
* rounded up to a multiple of 4 KB
*
* ucIsCachedMemory( pucBuffer ) returns non-zero if a given pointer is NOT
* within the range of the 1 MB non-cached memory.
*
*/

#ifndef UNCACHEMEMORY_H

#define UNCACHEMEMORY_H

uint8_t * pucGetUncachedMemory( uint32_t ulSize );

uint8_t ucIsCachedMemory( const uint8_t *pucBuffer );

#endif /* UNCACHEMEMORY_H */
Loading