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

Last change on this file since 411 was 405, checked in by cfuguet, 10 years ago

rdk_driver: replacing old USE_RAM_DISK variables by USE_IOC_RDK

File size: 4.1 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// The SEG_RDK_BASE virtual address must be defined in the hard_config.h
19// file when the USE_RAMDISK flag is set.
20///////////////////////////////////////////////////////////////////////////////////
21
22#include <giet_config.h>
23#include <hard_config.h>
24#include <rdk_driver.h>
25#include <utils.h>
26#include <tty_driver.h>
27#include <ctx_handler.h>
28
29#if !defined(SEG_RDK_BASE)
30# error: You must define SEG_RDK_BASE in the hard_config.h file
31#endif
32
33///////////////////////////////////////////////////////////////////////////////
34//       _rdk_init()
35// This function does nothing, and return 0 for success.
36///////////////////////////////////////////////////////////////////////////////
37unsigned int _rdk_init( unsigned int channel )
38{
39    return 0;
40}
41
42///////////////////////////////////////////////////////////////////////////////
43//     _rdk_read()
44// Transfer data from the RAMDISK to a memory buffer.
45// - mode     : BOOT / KERNEL / USER
46// - lba      : first block index on the block device
47// - buffer   : virtual base address of the memory buffer
48// - count    : number of blocks to be transfered.
49// Returns 0 if success, > 0 if error.
50///////////////////////////////////////////////////////////////////////////////
51unsigned int _rdk_read( unsigned int lba, 
52                        unsigned int buffer, 
53                        unsigned int count) 
54{
55
56#if GIET_DEBUG_IOC_DRIVER
57_printf("\n[IOC DEBUG] Enter _rdk_read() at cycle %d"
58        "\n - vaddr   = %x"
59        "\n - sectors = %d"
60        "\n - lba     = %x",
61        _get_proctime(), buffer, count, lba );
62#endif
63
64#if USE_IOC_RDK
65    char* src = (char*)SEG_RDK_BASE + (512*lba);
66    char* dst = (char*)buffer;
67    memcpy( dst, src, count*512 );
68    return 0;
69#else
70    _printf("[GIET ERROR] _rdk_read() should not be used if USE_IOC_RDK not set\n");
71    return 1;
72#endif
73}
74
75///////////////////////////////////////////////////////////////////////////////
76//     _rdk_write()
77// Transfer data from a memory buffer to the block device.
78// - mode     : BOOT / KERNEL / USER
79// - lba      : first block index on the block device
80// - buffer   : virtual base address of the memory buffer
81// - count    : number of blocks to be transfered.
82// Returns 0 if success, > 0 if error.
83///////////////////////////////////////////////////////////////////////////////
84unsigned int _rdk_write( unsigned int lba, 
85                         unsigned int buffer, 
86                         unsigned int count ) 
87{
88
89#if GIET_DEBUG_IOC_DRIVER
90_printf("\n[IOC DEBUG] Enter _rdk_write() at cycle %d"
91        "\n - vaddr   = %x"
92        "\n - sectors = %d"
93        "\n - lba     = %x",
94        _get_proctime(), buffer, count, lba );
95#endif
96
97#if USE_IOC_RDK
98    char* dst = (char*)SEG_RDK_BASE + (512*lba);
99    char* src = (char*)buffer;
100    memcpy( dst, src, count*512 );
101    return 0;
102#else
103    _printf("[GIET ERROR] _rdk_write() should not be used if USE_IOC_RDK not set\n");
104    return 1;
105#endif
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.