source: soft/giet_vm/giet_drivers/rdk_driver.c @ 298

Last change on this file since 298 was 298, checked in by alain, 10 years ago

Introducing pic driver and rdk driver

File size: 3.9 KB
Line 
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///////////////////////////////////////////////////////////////////////////////
29unsigned 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///////////////////////////////////////////////////////////////////////////////
43unsigned 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///////////////////////////////////////////////////////////////////////////////
80unsigned 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///////////////////////////////////////////////////////////////////////////////
112unsigned 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
Note: See TracBrowser for help on using the repository browser.