source: soft/giet_vm/giet_drivers/hba_driver.h

Last change on this file was 577, checked in by bellefin, 9 years ago

Improve hba driver

File size: 6.9 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : hba_driver.h
3// Date     : 01/11/2013
4// Author   : alain greiner and zhang
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The hba_driver.c and hba_driver.h files are part ot the GIET-VM kernel.
8// This driver supports the SocLib VciMultiAhci component, that is a multi-channels,
9// block oriented, external storage contrÃŽler, respecting the AHCI standard.
10//
11// 1. Each HBA channel define an independant physical disk, but this driver
12//    supports only channel 0, because the GIET-VM uses only one physical disk.
13//
14// 2. This HBA component support split memory buffers (several physical
15//    buffers for one single command), but this driver supports only one
16//    single buffer commands.
17//
18// 3. The "command list" can contain up to 32 independant commands, posted
19//    by different user tasks. These independant transfers are handled by
20//    the HBA device. The command list being a shared structure, the driver
21//    must use a lock to get a slot in the command list (except in boot mode
22//    when only one processor uses the HBA device). This slot is then
23//    allocated to the task until the command is completed.
24//
25// 4. This driver implements two operating mode:
26//    - In synchronous mode, the calling task poll the HBA_PXCI register to
27//    detect the command completion (busy waiting).
28//    - In descheduling mode, the calling task is descheduled, and must be
29//    restart when the command is completed.
30//
31// 5. As several user tasks can concurrently register commands in the command
32//    list, and there is only one HBA interrupt, this interrupt is not linked
33//    to a specific task. In descheduling mode, the HBA IRQ is a "global" IRQ
34//    that is statically routed to processor P[x_io,y_io,0] in cluster_io.
35//    The associated global HBA_ISR send a WAKUP WTI to all tasks that have
36//    a completed active command. In order to know which commands expect
37//    completion, the HBA_ISR uses the _hba_active_cmd table which indicates
38//    currently active commands (in descheduling mode only).
39//
40// The SEG_IOC_BASE virtual address must be defined in the hard_config.h file.
41//////////////////////////////////////////////////////////////////////////////////
42
43#ifndef _GIET_HBA_DRIVERS_H_
44#define _GIET_HBA_DRIVERS_H_
45
46///////////////////////////////////////////////////////////////////////////////////
47// HBA component registers offsets
48///////////////////////////////////////////////////////////////////////////////////
49
50enum SoclibMultiAhciRegisters
51{
52  HBA_PXCLB            = 0,         // command list base address 32 LSB bits
53  HBA_PXCLBU           = 1,         // command list base address 32 MSB bits
54  HBA_PXIS             = 4,         // interrupt status
55  HBA_PXIE             = 5,         // interrupt enable
56  HBA_PXCMD            = 6,         // run
57  HBA_PXCI             = 14,        // command bit-vector     
58  HBA_SPAN             = 0x400,     // 4 Kbytes per channel => 1024 slots
59};
60
61///////////////////////////////////////////////////////////////////////////////////
62// Data structures for command table
63///////////////////////////////////////////////////////////////////////////////////
64
65///////////////////////////////
66typedef struct hba_cmd_header_s // size = 16 bytes
67{
68    // WORD 0
69    unsigned int        res0;       // reserved
70 
71    // WORD 1
72    unsigned char           lba0;           // LBA 7:0
73    unsigned char           lba1;           // LBA 15:8
74    unsigned char           lba2;           // LBA 23:16
75    unsigned char           res1;           // reserved
76 
77    // WORD 2
78    unsigned char           lba3;           // LBA 31:24
79    unsigned char           lba4;           // LBA 39:32
80    unsigned char           lba5;           // LBA 47:40
81    unsigned char           res2;           // reserved
82 
83    // WORD 3
84    unsigned int        res3;       // reserved
85
86} hba_cmd_header_t;
87
88///////////////////////////////
89typedef struct hba_cmd_buffer_s  // size = 16 bytes
90{
91    unsigned int        dba;        // Buffer base address 32 LSB bits
92    unsigned int        dbau;       // Buffer base address 32 MSB bits
93    unsigned int        res0;       // reserved
94    unsigned int        dbc;        // Buffer byte count
95
96} hba_cmd_buffer_t;
97
98//////////////////////////////
99typedef struct hba_cmd_table_s  // size = 32 bytes
100{
101
102    hba_cmd_header_t   header;      // contains LBA
103    hba_cmd_buffer_t   buffer;      // only one physical buffer
104
105} hba_cmd_table_t;
106
107///////////////////////////////////////////////////////////////////////////////////
108// Data structure for command descriptor in command list
109///////////////////////////////////////////////////////////////////////////////////
110
111/////////////////////////////
112typedef struct hba_cmd_desc_s  // size = 16 bytes
113{
114        // WORD 0
115    unsigned char       flag[2];    // W in bit 6 of flag[0]
116    unsigned char       prdtl[2];       // Number of buffers
117
118    // WORD 1
119    unsigned int        prdbc;          // Number of bytes actually transfered
120
121    // WORD 2, WORD 3
122    unsigned int        ctba;           // Command Table base address 32 LSB bits
123    unsigned int        ctbau;          // Command Table base address 32 MSB bits
124
125} hba_cmd_desc_t;
126
127///////////////////////////////////////////////////////////////////////////////////
128//              access functions 
129///////////////////////////////////////////////////////////////////////////////////
130
131///////////////////////////////////////////////////////////////////////////////////
132// This function initializes for a given channel
133// - the HBA hardware registers,
134// - the command list pointer,
135// - the command lists physical addresse,
136// - the command tables physical addresses array,
137///////////////////////////////////////////////////////////////////////////////////
138extern unsigned int _hba_init (); 
139
140///////////////////////////////////////////////////////////////////////////////////
141// This function register a command in Command List and Command Table
142// for a single physical buffer, and updates the HBA_PXCI register.
143// Returns 0 if success, > 0 if error.
144///////////////////////////////////////////////////////////////////////////////////
145extern unsigned int _hba_access( unsigned int       use_irq,
146                                 unsigned int       to_mem,
147                                 unsigned int       lba, 
148                                 unsigned long long paddr, 
149                                 unsigned int       count );
150
151///////////////////////////////////////////////////////////////////////////////////
152// Interrupt Service Routine executed in descheduling mode.
153///////////////////////////////////////////////////////////////////////////////////
154extern void _hba_isr( unsigned int irq_type,
155                      unsigned int irq_id,
156                      unsigned int channel );
157#endif
158
159// Local Variables:
160// tab-width: 4
161// c-basic-offset: 4
162// c-file-offsets:((innamespace . 0)(inline-open . 0))
163// indent-tabs-mode: nil
164// End:
165// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
166
Note: See TracBrowser for help on using the repository browser.