[298] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : rdk_driver.c |
---|
| 3 | // Date : 13/02/2014 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Maintainer: cesar fuguet |
---|
| 6 | // Copyright (c) UPMC-LIP6 |
---|
| 7 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 8 | // The rdk_driver.c and rdk_driver.h files are part ot the GIET-VM kernel. |
---|
| 9 | // |
---|
| 10 | // This driver supports a virtual disk implemented as a memory segment, |
---|
| 11 | // in the address space. |
---|
| 12 | // |
---|
| 13 | // The _rdk_read() and _rdk_write() blocking functions use a software memcpy, |
---|
| 14 | // whatever the selected mode. They return only when the transfer is completed. |
---|
| 15 | // As the number of concurrent accesses is not bounded, these functions |
---|
| 16 | // don't use the _ioc_lock variable. |
---|
| 17 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 18 | |
---|
| 19 | #include <giet_config.h> |
---|
| 20 | #include <rdk_driver.h> |
---|
| 21 | #include <utils.h> |
---|
| 22 | #include <tty_driver.h> |
---|
| 23 | #include <ctx_handler.h> |
---|
| 24 | |
---|
| 25 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 26 | // _rdk_init() |
---|
| 27 | // This function does nothing, and return 0 for success. |
---|
| 28 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 29 | unsigned int _rdk_init( unsigned int channel ) |
---|
| 30 | { |
---|
| 31 | return 0; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 35 | // _rdk_read() |
---|
| 36 | // Transfer data from the RAMDISK to a memory buffer. |
---|
| 37 | // - mode : BOOT / KERNEL / USER |
---|
| 38 | // - lba : first block index on the block device |
---|
| 39 | // - buffer : virtual base address of the memory buffer |
---|
| 40 | // - count : number of blocks to be transfered. |
---|
| 41 | // Returns 0 if success, > 0 if error. |
---|
| 42 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 43 | unsigned int _rdk_read( unsigned int lba, |
---|
| 44 | unsigned int buffer, |
---|
| 45 | unsigned int count) |
---|
| 46 | { |
---|
| 47 | |
---|
| 48 | #if GIET_DEBUG_IOC_DRIVER |
---|
[313] | 49 | _printf("\n[IOC DEBUG] Enter _rdk_read() at cycle %d" |
---|
| 50 | "\n - vaddr = %x" |
---|
| 51 | "\n - sectors = %d" |
---|
| 52 | "\n - lba = %x", |
---|
| 53 | _get_proctime(), buffer, count, lba ); |
---|
[298] | 54 | #endif |
---|
| 55 | |
---|
| 56 | char* src = (char*)&seg_ram_disk_base + (512*lba); |
---|
| 57 | char* dst = (char*)buffer; |
---|
| 58 | _memcpy( dst, src, count*512 ); |
---|
| 59 | |
---|
| 60 | return 0; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 64 | // _rdk_write() |
---|
| 65 | // Transfer data from a memory buffer to the block device. |
---|
| 66 | // - mode : BOOT / KERNEL / USER |
---|
| 67 | // - lba : first block index on the block device |
---|
| 68 | // - buffer : virtual base address of the memory buffer |
---|
| 69 | // - count : number of blocks to be transfered. |
---|
| 70 | // Returns 0 if success, > 0 if error. |
---|
| 71 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 72 | unsigned int _rdk_write( unsigned int lba, |
---|
| 73 | unsigned int buffer, |
---|
| 74 | unsigned int count ) |
---|
| 75 | { |
---|
| 76 | |
---|
| 77 | #if GIET_DEBUG_IOC_DRIVER |
---|
[313] | 78 | _printf("\n[IOC DEBUG] Enter _rdk_write() at cycle %d" |
---|
| 79 | "\n - vaddr = %x" |
---|
| 80 | "\n - sectors = %d" |
---|
| 81 | "\n - lba = %x", |
---|
| 82 | _get_proctime(), buffer, count, lba ); |
---|
[298] | 83 | #endif |
---|
| 84 | |
---|
| 85 | char* dst = (char*)&seg_ram_disk_base + (512*lba); |
---|
| 86 | char* src = (char*)buffer; |
---|
| 87 | _memcpy( dst, src, count*512 ); |
---|
| 88 | |
---|
| 89 | return 0; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 93 | // _rdk_get_block_size() |
---|
| 94 | // This function returns the block_size. |
---|
| 95 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 96 | unsigned int _rdk_get_block_size() |
---|
| 97 | { |
---|
| 98 | return 512; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | // Local Variables: |
---|
| 103 | // tab-width: 4 |
---|
| 104 | // c-basic-offset: 4 |
---|
| 105 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 106 | // indent-tabs-mode: nil |
---|
| 107 | // End: |
---|
| 108 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 109 | |
---|