source: soft/giet_vm/giet_drivers/hba_driver.h @ 561

Last change on this file since 561 was 545, checked in by alain, 9 years ago

Cosmetic

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