/////////////////////////////////////////////////////////////////////////////////// // File : rdk_driver.c // Date : 13/02/2014 // Author : alain greiner // Maintainer: cesar fuguet // Copyright (c) UPMC-LIP6 /////////////////////////////////////////////////////////////////////////////////// // The rdk_driver.c and rdk_driver.h files are part ot the GIET-VM kernel. // // This driver supports a virtual disk implemented as a memory segment, // in the address space. // // The _rdk_read() and _rdk_write() blocking functions use a software memcpy, // whatever the selected mode. They return only when the transfer is completed. // As the number of concurrent accesses is not bounded, these functions // don't use the _ioc_lock variable. /////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include /////////////////////////////////////////////////////////////////////////////// // _rdk_init() // This function does nothing, and return 0 for success. /////////////////////////////////////////////////////////////////////////////// unsigned int _rdk_init( unsigned int channel ) { return 0; } /////////////////////////////////////////////////////////////////////////////// // _rdk_read() // Transfer data from the RAMDISK to a memory buffer. // - mode : BOOT / KERNEL / USER // - lba : first block index on the block device // - buffer : virtual base address of the memory buffer // - count : number of blocks to be transfered. // Returns 0 if success, > 0 if error. /////////////////////////////////////////////////////////////////////////////// unsigned int _rdk_read( unsigned int lba, unsigned int buffer, unsigned int count) { #if GIET_DEBUG_IOC_DRIVER _tty_get_lock( 0 ); _puts("\n[IOC DEBUG] Enter _rdk_read() at cycle "); _putd( _get_proctime() ); _puts(" for processor "); _putd( _get_procid() ); _puts("\n - vaddr = "); _putx( buffer ); _puts("\n - sectors = "); _putd( count ); _puts("\n - lba = "); _putx( lba ); _puts("\n"); _tty_release_lock( 0 ); #endif char* src = (char*)&seg_ram_disk_base + (512*lba); char* dst = (char*)buffer; _memcpy( dst, src, count*512 ); return 0; } /////////////////////////////////////////////////////////////////////////////// // _rdk_write() // Transfer data from a memory buffer to the block device. // - mode : BOOT / KERNEL / USER // - lba : first block index on the block device // - buffer : virtual base address of the memory buffer // - count : number of blocks to be transfered. // Returns 0 if success, > 0 if error. /////////////////////////////////////////////////////////////////////////////// unsigned int _rdk_write( unsigned int lba, unsigned int buffer, unsigned int count ) { #if GIET_DEBUG_IOC_DRIVER _tty_get_lock( 0 ); _puts("\n[IOC DEBUG] Enter _rdk_write() at cycle "); _putd( _get_proctime() ); _puts(" for processor "); _putd( _get_procid() ); _puts("\n - vaddr = "); _putx( buffer ); _puts("\n - sectors = "); _putd( count ); _puts("\n - lba = "); _putx( lba ); _puts("\n"); _tty_release_lock( 0 ); #endif char* dst = (char*)&seg_ram_disk_base + (512*lba); char* src = (char*)buffer; _memcpy( dst, src, count*512 ); return 0; } /////////////////////////////////////////////////////////////////////////////// // _rdk_get_block_size() // This function returns the block_size. /////////////////////////////////////////////////////////////////////////////// unsigned int _rdk_get_block_size() { return 512; } // 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