source: soft/giet_vm/giet_drivers/ioc_driver.h @ 421

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

Introducing support for the PIC_MASK register in pic_driver.

File size: 7.5 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : ioc_driver.h
3// Date     : 01/11/2013
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The ioc_driver.c and ioc_driver.h files are part ot the GIET-VM kernel.
8//
9// This abstact driver define a generic API, supporting various physical
10// block device controlers, including:
11// - vci_block_device : single channel                     => bdv_driver
12// - vci_ahci         : multi channels                     => hba_driver
13// - sd_card          : single channel                     => sdc_driver
14// - ramdisk (single channel meory mapped virtual disk)    => rdk_driver
15//
16// It can exist only one block-device type in the architecture, that must be
17// defined by one of the following configuration variables in hard_config.h file:
18// USE_IOC_BDV, USE_IOC_SDC, USE_IOC_HBA, USE_IOC_RDK.
19//
20// Any physical block device driver xxx must provide the following API:
21// - _xxx_init()
22// - _xxx_read()
23// - _xxx_write()
24// - _xxx_get_status()
25// - _xxx_get_block_size()
26// The "channel" parameter is no transmited to single channel devices.
27//
28// The _ioc_read() and _ioc_write() functions are always blocking for
29// the calling user program.
30//
31// These functions compute the physical address of the memory buffer before
32// calling the proper physical device. We know that the user buffer is mapped
33// to a contiguous physical buffer because, for each vseg, the page tables
34// are statically constructed to use contiguous physical memory.
35//
36// These functions can be called in 3 modes:
37//
38// - In BOOT mode, these functions use the buffer virtual address
39//   as a physical address if the MMU is not activated.
40//   They make a V2P translation if the MMU is activated.
41//   This mode is used to load the map.bin file (before memory activation),
42//   or to load the various .elf files (after MMU activation).
43//
44// - In KERNEL mode, these functions make a V2P translation to
45//   compute the buffer physical address.
46//   There is no checking of user access right to the memory buffer. 
47//   This mode must be used for an "open" system call.
48//
49// - In USER mode, these functions make a V2P translation to
50//   compute the buffer physical address.
51//   The user access right to the memory buffer are checked. 
52//   This mode must be used for a "read" or "write" system call.
53//
54// Finally, the memory buffer must fulfill the following conditions:
55// - The buffer must be word aligned,
56// - The buffer must be mapped in user space for an user access,
57// - The buffer must be writable in case of (to_mem) access,
58// - The total number of physical pages occupied by the user buffer cannot
59//   be larger than 512 pages if the IOMMU is activated,
60// - All physical pages occupied by the user buffer must be contiguous
61//   if the IOMMU is not activated.
62// Exit if these conditions are not verified.
63//
64// The SEG_IOC_BASE virtual base address must be defined in hard_config.h,
65// as it is used by the BDV, HBA and SPI drivers.
66//
67// If the RAMDISK is used, an extra memory segment with virtual base address
68// SEG_RDK_BASE, used by RDK driver, must be defined in hard_config.h.
69///////////////////////////////////////////////////////////////////////////////////
70// Implementation note:
71//
72// 1) In order to share the code, the two _ioc_read() and _ioc_write() functions
73// call the same _ioc_access() function.
74//
75// 2) The IOMMU is not supported yet, but the method is the following:
76// A fixed size 2 Mbytes vseg is allocated to the IOC peripheral, in the I/O
77// virtual space, and the user buffer is dynamically remapped to one single
78// big page in the IOMMU page table.
79// The user buffer is unmapped by the _ioc_completed() function when
80// the transfer is completed.
81///////////////////////////////////////////////////////////////////////////////////
82
83#ifndef _GIET_IOC_DRIVER_H_
84#define _GIET_IOC_DRIVER_H_
85
86///////////////////////////////////////////////////////////////////////////////////
87// IOC (vci_block device) registers offsets
88///////////////////////////////////////////////////////////////////////////////////
89
90enum IOC_driver_modes
91{
92    IOC_BOOT_MODE   = 0,     //  Polling IOC_STATUS / no access right checking
93    IOC_KERNEL_MODE = 1,     //  Descheduling + IRQ / no access right checking
94    IOC_USER_MODE   = 2,     //  Descheduling + IRQ / access right checking
95};
96
97///////////////////////////////////////////////////////////////////////////////////
98// IOC global variables (generic disk controller)
99///////////////////////////////////////////////////////////////////////////////////
100
101extern volatile unsigned int _ioc_iommu_ix1;
102extern volatile unsigned int _ioc_iommu_npages; 
103
104///////////////////////////////////////////////////////////////////////////////////
105// IOC access functions  (generic disk controller)
106///////////////////////////////////////////////////////////////////////////////////
107
108///////////////////////////////////////////////////////////////////////////////
109// This function cheks block size, and desactivates the IOC interrupts.
110// Return 0 for success, non zero if error.
111///////////////////////////////////////////////////////////////////////////////
112extern unsigned int _ioc_init( unsigned int channel );
113
114///////////////////////////////////////////////////////////////////////////////
115// Transfer data from a memory buffer to the block device.
116// - mode     : BOOT_PA / BOOT_VA / KERNEL / USER
117// - lba      : first block index on the block device
118// - buffer   : base address of the memory buffer (must be word aligned)
119// - count    : number of blocks to be transfered.
120// Returns 0 if success, > 0 if error.
121///////////////////////////////////////////////////////////////////////////////
122extern unsigned int _ioc_write( unsigned int channel,
123                                unsigned int mode,
124                                unsigned int lba, 
125                                const void*  buffer, 
126                                unsigned int count );
127
128///////////////////////////////////////////////////////////////////////////////
129// Transfer data from the block device to a memory buffer.
130// - mode     : BOOT_PA / BOOT_VA / KERNEL / USER
131// - lba      : first block index on the block device
132// - buffer   : base address of the memory buffer (must be word aligned)
133// - count    : number of blocks to be transfered.
134// Returns 0 if success, > 0 if error.
135///////////////////////////////////////////////////////////////////////////////
136extern unsigned int _ioc_read(  unsigned int channel,
137                                unsigned int mode,
138                                unsigned int lba, 
139                                void*        buffer,
140                                unsigned int count );
141
142///////////////////////////////////////////////////////////////////////////////
143// This function returns in the status variable, the transfert status, and
144// acknowledge the IRQ if the IOC controler is not busy.
145// Returns 0 if success, > 0 if error
146///////////////////////////////////////////////////////////////////////////////
147extern unsigned int _ioc_get_status( unsigned int channel );
148
149///////////////////////////////////////////////////////////////////////////////
150// This function returns the block_size for the block device.
151///////////////////////////////////////////////////////////////////////////////
152extern unsigned int _ioc_get_block_size();
153
154
155#endif
156
157// Local Variables:
158// tab-width: 4
159// c-basic-offset: 4
160// c-file-offsets:((innamespace . 0)(inline-open . 0))
161// indent-tabs-mode: nil
162// End:
163// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
164
Note: See TracBrowser for help on using the repository browser.