1 #warning Temoporary file and a dependent on the Zynq network interface.
\r
6 * This module will declare 1 MB of memory and switch off the caching for it.
\r
8 * pucGetUncachedMemory( ulSize ) returns a trunc of this memory with a length
\r
9 * rounded up to a multiple of 4 KB
\r
11 * ucIsCachedMemory( pucBuffer ) returns non-zero if a given pointer is NOT
\r
12 * within the range of the 1 MB non-cached memory.
\r
17 * After "_end", 1 MB of uncached memory will be allocated for DMA transfers.
\r
18 * Both the DMA descriptors as well as all EMAC TX-buffers will be allocated in
\r
22 #include "Zynq/x_emacpsif.h"
\r
23 #include "Zynq/x_topology.h"
\r
24 #include "xstatus.h"
\r
26 #include "xparameters.h"
\r
27 #include "xparameters_ps.h"
\r
28 #include "xil_exception.h"
\r
29 #include "xil_mmu.h"
\r
31 #include "FreeRTOS.h"
\r
33 #include "uncached_memory.h"
\r
35 #include "Demo_Logging.h"
\r
37 #define UNCACHED_MEMORY_SIZE 0x100000ul
\r
39 #define DDR_MEMORY_END (XPAR_PS7_DDR_0_S_AXI_HIGHADDR+1)
\r
41 static void vInitialiseUncachedMemory( void );
\r
43 static uint8_t *pucHeadOfMemory;
\r
44 static uint32_t ulMemorySize;
\r
45 static uint8_t *pucStartOfMemory = NULL;
\r
47 uint8_t ucIsCachedMemory( const uint8_t *pucBuffer )
\r
51 if( ( pucStartOfMemory != NULL ) &&
\r
52 ( pucBuffer >= pucStartOfMemory ) &&
\r
53 ( pucBuffer < ( pucStartOfMemory + UNCACHED_MEMORY_SIZE ) ) )
\r
65 uint8_t *pucGetUncachedMemory( uint32_t ulSize )
\r
69 if( pucStartOfMemory == NULL )
\r
71 vInitialiseUncachedMemory( );
\r
73 if( ( pucStartOfMemory == NULL ) || ( ulSize > ulMemorySize ) )
\r
79 uint32_t ulSkipSize;
\r
81 pucReturn = pucHeadOfMemory;
\r
82 ulSkipSize = ( ulSize + 0x1000ul ) & ~0xffful;
\r
83 pucHeadOfMemory += ulSkipSize;
\r
84 ulMemorySize -= ulSkipSize;
\r
92 static void vInitialiseUncachedMemory( )
\r
94 /* At the end of program's space... */
\r
95 pucStartOfMemory = (uint8_t *) &_end;
\r
97 * Align the start address to 1 MB boundary.
\r
99 pucStartOfMemory = (uint8_t *)( ( ( uint32_t )pucStartOfMemory + UNCACHED_MEMORY_SIZE ) & ( ~( UNCACHED_MEMORY_SIZE - 1 ) ) );
\r
101 if( ( ( u32 )pucStartOfMemory ) + UNCACHED_MEMORY_SIZE > DDR_MEMORY_END )
\r
103 vLoggingPrintf("vInitialiseUncachedMemory: Can not allocate uncached memory\n" );
\r
108 * Some objects want to be stored in uncached memory. Hence the 1 MB
\r
109 * address range that starts after "_end" is made uncached
\r
110 * by setting appropriate attributes in the translation table.
\r
112 Xil_SetTlbAttributes( ( uint32_t )pucStartOfMemory, 0xc02 ); // addr, attr
\r
114 /* For experiments in the SDIO driver, make the remaining uncached memory public */
\r
115 pucHeadOfMemory = pucStartOfMemory;
\r
116 ulMemorySize = UNCACHED_MEMORY_SIZE;
\r
117 memset( pucStartOfMemory, '\0', UNCACHED_MEMORY_SIZE );
\r