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 |
---|
49 | _tty_get_lock( 0 ); |
---|
50 | _puts("\n[IOC DEBUG] Enter _rdk_read() at cycle "); |
---|
51 | _putd( _get_proctime() ); |
---|
52 | _puts(" for processor "); |
---|
53 | _putd( _get_procid() ); |
---|
54 | _puts("\n - vaddr = "); |
---|
55 | _putx( buffer ); |
---|
56 | _puts("\n - sectors = "); |
---|
57 | _putd( count ); |
---|
58 | _puts("\n - lba = "); |
---|
59 | _putx( lba ); |
---|
60 | _puts("\n"); |
---|
61 | _tty_release_lock( 0 ); |
---|
62 | #endif |
---|
63 | |
---|
64 | char* src = (char*)&seg_ram_disk_base + (512*lba); |
---|
65 | char* dst = (char*)buffer; |
---|
66 | _memcpy( dst, src, count*512 ); |
---|
67 | |
---|
68 | return 0; |
---|
69 | } |
---|
70 | |
---|
71 | /////////////////////////////////////////////////////////////////////////////// |
---|
72 | // _rdk_write() |
---|
73 | // Transfer data from a memory buffer to the block device. |
---|
74 | // - mode : BOOT / KERNEL / USER |
---|
75 | // - lba : first block index on the block device |
---|
76 | // - buffer : virtual base address of the memory buffer |
---|
77 | // - count : number of blocks to be transfered. |
---|
78 | // Returns 0 if success, > 0 if error. |
---|
79 | /////////////////////////////////////////////////////////////////////////////// |
---|
80 | unsigned int _rdk_write( unsigned int lba, |
---|
81 | unsigned int buffer, |
---|
82 | unsigned int count ) |
---|
83 | { |
---|
84 | |
---|
85 | #if GIET_DEBUG_IOC_DRIVER |
---|
86 | _tty_get_lock( 0 ); |
---|
87 | _puts("\n[IOC DEBUG] Enter _rdk_write() at cycle "); |
---|
88 | _putd( _get_proctime() ); |
---|
89 | _puts(" for processor "); |
---|
90 | _putd( _get_procid() ); |
---|
91 | _puts("\n - vaddr = "); |
---|
92 | _putx( buffer ); |
---|
93 | _puts("\n - sectors = "); |
---|
94 | _putd( count ); |
---|
95 | _puts("\n - lba = "); |
---|
96 | _putx( lba ); |
---|
97 | _puts("\n"); |
---|
98 | _tty_release_lock( 0 ); |
---|
99 | #endif |
---|
100 | |
---|
101 | char* dst = (char*)&seg_ram_disk_base + (512*lba); |
---|
102 | char* src = (char*)buffer; |
---|
103 | _memcpy( dst, src, count*512 ); |
---|
104 | |
---|
105 | return 0; |
---|
106 | } |
---|
107 | |
---|
108 | /////////////////////////////////////////////////////////////////////////////// |
---|
109 | // _rdk_get_block_size() |
---|
110 | // This function returns the block_size. |
---|
111 | /////////////////////////////////////////////////////////////////////////////// |
---|
112 | unsigned int _rdk_get_block_size() |
---|
113 | { |
---|
114 | return 512; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | // Local Variables: |
---|
119 | // tab-width: 4 |
---|
120 | // c-basic-offset: 4 |
---|
121 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
122 | // indent-tabs-mode: nil |
---|
123 | // End: |
---|
124 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
125 | |
---|