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

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

Introducing dynamic allocation of peripheral channel(TTY, NIC, TIM, CMA)
Removint the ICU driver : ICU component not supported anymore.
Removing the FBF driver.

File size: 7.1 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 must provide the 5 five functions defined
21// by this generic driver.
22//
23// The _ioc_read() and _ioc_write() functions are always blocking for
24// the calling user program.
25//
26// These functions compute the physical address of the memory buffer before
27// calling the proper physical device. We know that the user buffer is mapped
28// to a contiguous physical buffer because, for each vseg, the page tables
29// are statically constructed to use contiguous physical memory.
30//
31// These functions can be called in 3 modes:
32//
33// - In BOOT mode, these functions use the buffer virtual address
34//   as a physical address if the MMU is not activated.
35//   They make a V2P translation if the MMU is activated.
36//   This mode is used to load the map.bin file (before memory activation),
37//   or to load the various .elf files (after MMU activation).
38//
39// - In KERNEL mode, these functions make a V2P translation to
40//   compute the buffer physical address.
41//   There is no checking of user access right to the memory buffer. 
42//   This mode must be used for an "open" system call.
43//
44// - In USER mode, these functions make a V2P translation to
45//   compute the buffer physical address.
46//   The user access right to the memory buffer are checked. 
47//   This mode must be used for a "read" or "write" system call.
48//
49// Finally, the memory buffer must fulfill the following conditions:
50// - The buffer must be word aligned,
51// - The buffer must be mapped in user space for an user access,
52// - The buffer must be writable in case of (to_mem) access,
53// - The total number of physical pages occupied by the user buffer cannot
54//   be larger than 512 pages if the IOMMU is activated,
55// - All physical pages occupied by the user buffer must be contiguous
56//   if the IOMMU is not activated.
57// Exit if these conditions are not verified.
58//
59// The SEG_IOC_BASE virtual base address must be defined in hard_config.h,
60// as it is used by the BDV, HBA and SPI drivers.
61//
62// If the RAMDISK is used, an extra memory segment with virtual base address
63// SEG_RDK_BASE, used by RDK driver, must be defined in hard_config.h.
64//
65// The IOMMU is not supported yet, but the method is the following:
66// A fixed size 2 Mbytes vseg is allocated to the IOC peripheral, in the I/O
67// virtual space, and the user buffer is dynamically remapped to one single
68// big page in the IOMMU page table.
69// The user buffer is unmapped by the _ioc_completed() function when
70// the transfer is completed.
71///////////////////////////////////////////////////////////////////////////////////
72
73#ifndef _GIET_IOC_DRIVER_H_
74#define _GIET_IOC_DRIVER_H_
75
76///////////////////////////////////////////////////////////////////////////////////
77// IOC (vci_block device) registers offsets
78///////////////////////////////////////////////////////////////////////////////////
79
80enum IOC_driver_modes
81{
82    IOC_BOOT_MODE   = 0,     //  Polling IOC_STATUS / no access right checking
83    IOC_KERNEL_MODE = 1,     //  Descheduling + IRQ / no access right checking
84    IOC_USER_MODE   = 2,     //  Descheduling + IRQ / access right checking
85};
86
87///////////////////////////////////////////////////////////////////////////////////
88// IOC global variables (generic disk controller)
89///////////////////////////////////////////////////////////////////////////////////
90
91extern volatile unsigned int _ioc_iommu_ix1;
92extern volatile unsigned int _ioc_iommu_npages; 
93
94///////////////////////////////////////////////////////////////////////////////////
95//      External functions                           
96///////////////////////////////////////////////////////////////////////////////////
97
98///////////////////////////////////////////////////////////////////////////////
99// This function cheks block size, and desactivates interrupts.
100// Return 0 for success, non zero if error.
101///////////////////////////////////////////////////////////////////////////////
102extern unsigned int _ioc_init( unsigned int channel );
103
104///////////////////////////////////////////////////////////////////////////////
105// Transfer data from a memory buffer to the disk.
106// - mode     : BOOT / KERNEL / USER
107// - lba      : first block index on the block device
108// - buffer   : base address of the memory buffer (must be word aligned)
109// - count    : number of blocks to be transfered.
110// Returns 0 if success, > 0 if error.
111///////////////////////////////////////////////////////////////////////////////
112extern unsigned int _ioc_write( unsigned int channel,
113                                unsigned int mode,
114                                unsigned int lba, 
115                                const void*  buffer, 
116                                unsigned int count );
117
118///////////////////////////////////////////////////////////////////////////////
119// Transfer data from the disk to a memory buffer.
120// - mode     : BOOT / KERNEL / USER
121// - lba      : first block index on the block device
122// - buffer   : base address of the memory buffer (must be word aligned)
123// - count    : number of blocks to be transfered.
124// Returns 0 if success, > 0 if error.
125///////////////////////////////////////////////////////////////////////////////
126extern unsigned int _ioc_read(  unsigned int channel,
127                                unsigned int mode,
128                                unsigned int lba, 
129                                void*        buffer,
130                                unsigned int count );
131
132///////////////////////////////////////////////////////////////////////////////
133// This function returns in the status variable, the transfert status, and
134// acknowledge the IRQ if required.
135// Returns 0 if success, > 0 if error
136///////////////////////////////////////////////////////////////////////////////
137extern unsigned int _ioc_get_status( unsigned int channel );
138
139///////////////////////////////////////////////////////////////////////////////
140// This function returns the block_size for the block device.
141///////////////////////////////////////////////////////////////////////////////
142extern unsigned int _ioc_get_block_size();
143
144
145#endif
146
147// Local Variables:
148// tab-width: 4
149// c-basic-offset: 4
150// c-file-offsets:((innamespace . 0)(inline-open . 0))
151// indent-tabs-mode: nil
152// End:
153// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
154
Note: See TracBrowser for help on using the repository browser.