/////////////////////////////////////////////////////////////////////////////////// // File : mmc_driver.c // Date : 23/05/2013 // Author : alain greiner // Copyright (c) UPMC-LIP6 /////////////////////////////////////////////////////////////////////////////////// // The mmc_driver.c and mmc_driver.h files are part ot the GIET-VM nano-kernel. // This driver supports the vci_mem_cache component used in the TSAR architecture. // // This component is replicated in all clusters, and can be accessed through // a configuration interface as a set of uncached, memory mapped registers. /////////////////////////////////////////////////////////////////////////////////// // The (virtual) base address of the associated segment is: // // seg_mmc_base + cluster_id * vseg_cluster_increment // // The seg_mmc_base and vseg_cluster_increment values must be defined // in the giet_vsegs.ld file. //////////////////////////////////////////////////////////////////////////////// #include #include #include #if !defined(NB_CLUSTERS) # error: You must define NB_CLUSTERS in the hard_config.h file #endif #if (NB_CLUSTERS > 256) # error: NB_CLUSTERS cannot be larger than 256! #endif /////////////////////////////////////////////////////////////////////////////////// // _memc_inval() // This function invalidates all cache lines covering a memory buffer defined // by the physical base address, and the length. // The buffer address MSB are used to compute the cluster index. /////////////////////////////////////////////////////////////////////////////////// void _memc_inval( paddr_t buf_paddr, unsigned int buf_length ) { unsigned int cluster_id = (unsigned int)((buf_paddr>>32)/(256/NB_CLUSTERS)); unsigned int* mmc_address = (unsigned int*)((unsigned int)&seg_mmc_base + (cluster_id * (unsigned int)&vseg_cluster_increment)); // get the hard lock protecting exclusive access to MEMC while ( mmc_address[MEMC_LOCK] ) { asm volatile("nop"); } // write inval arguments mmc_address[MEMC_ADDR_LO] = (unsigned int)buf_paddr; mmc_address[MEMC_ADDR_HI] = (unsigned int)(buf_paddr>>32); mmc_address[MEMC_BUF_LENGTH] = buf_length; mmc_address[MEMC_CMD_TYPE] = MEMC_CMD_INVAL; // release the lock mmc_address[MEMC_LOCK] = 0; } /////////////////////////////////////////////////////////////////////////////////// // _memc_sync() // This function copies to external RAM all cache lines covering a memory buffer // defined by the physical base address, and the length, if they are dirty. // The buffer address MSB are used to compute the cluster index. /////////////////////////////////////////////////////////////////////////////////// void _memc_sync( paddr_t buf_paddr, unsigned int buf_length ) { unsigned int cluster_id = (unsigned int)((buf_paddr>>32)/(256/NB_CLUSTERS)); unsigned int * mmc_address = (unsigned int *) ((unsigned int)&seg_mmc_base + (cluster_id * (unsigned int)&vseg_cluster_increment)); // get the hard lock protecting exclusive access to MEMC while ( mmc_address[MEMC_LOCK] ) { asm volatile("nop"); } // write inval arguments mmc_address[MEMC_ADDR_LO] = (unsigned int)buf_paddr; mmc_address[MEMC_ADDR_HI] = (unsigned int)(buf_paddr>>32); mmc_address[MEMC_BUF_LENGTH] = buf_length; mmc_address[MEMC_CMD_TYPE] = MEMC_CMD_SYNC; // release the lock protecting MEMC mmc_address[MEMC_LOCK] = 0; } // Local Variables: // tab-width: 4 // c-basic-offset: 4 // c-file-offsets:((innamespace . 0)(inline-open . 0)) // indent-tabs-mode: nil // End: // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4