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

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

Simplify the Command Table C structure: only one physical buffer per command.

File size: 7.0 KB
RevLine 
[258]1///////////////////////////////////////////////////////////////////////////////////
2// File     : hba_driver.h
3// Date     : 01/11/2013
4// Author   : alain greiner and zhang
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
[437]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//
[529]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//
[540]14// 2. This HBA component support split memory buffers (several physical
15//    buffers for one single command), but this driver supports only
16//    single buffer commands.
17//
18// 3. The "command list" can contain up to 32 independant commands, posted
[529]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//
[540]26// 4. This driver implements two operating mode:
[529]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//
[540]32// 5. As several user tasks can concurrently register commands in the command
[529]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//
[437]42// The SEG_IOC_BASE virtual address must be defined in the hard_config.h file.
43//////////////////////////////////////////////////////////////////////////////////
[258]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///////////////////////////////////////////////////////////////////////////////////
[540]64// Data structures for command table
[258]65///////////////////////////////////////////////////////////////////////////////////
66
67typedef struct hba_cmd_header_s // size = 128 bytes
68{
69    // WORD 0
70    unsigned int        res0;       // reserved
71 
72    // WORD 1
73    unsigned char           lba0;           // LBA 7:0
74    unsigned char           lba1;           // LBA 15:8
75    unsigned char           lba2;           // LBA 23:16
76    unsigned char           res1;           // reserved
77 
78    // WORD 2
79    unsigned char           lba3;           // LBA 31:24
80    unsigned char           lba4;           // LBA 39:32
81    unsigned char           lba5;           // LBA 47:40
82    unsigned char           res2;           // reserved
83 
84    // WORD 3 to 31
85    unsigned int        res[29];    // reserved
86
87} hba_cmd_header_t;
88
[540]89typedef struct hba_cmd_buffer_s  // size = 16 bytes
[258]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
[540]96} hba_cmd_buffer_t;
[258]97
[540]98typedef struct hba_cmd_table_s  // size = 256 bytes
[258]99{
100
[540]101    hba_cmd_header_t   header;      // contains LBA
102    hba_cmd_buffer_t   buffer;      // only one physical buffer
103    char               res[112];    // for 256 bytes alignment
[258]104
105} hba_cmd_table_t;
106
107///////////////////////////////////////////////////////////////////////////////////
[529]108// Data structure for command descriptor in command list
[258]109///////////////////////////////////////////////////////////////////////////////////
110
111typedef struct hba_cmd_desc_s  // size = 16 bytes
112{
113        // WORD 0
114    unsigned char       flag[2];    // W in bit 6 of flag[0]
115    unsigned char       prdtl[2];       // Number of buffers
116
117    // WORD 1
118    unsigned int        prdbc;          // Number of bytes actually transfered
119
120    // WORD 2, WORD 3
121    unsigned int        ctba;           // Command Table base address 32 LSB bits
122    unsigned int        ctbau;          // Command Table base address 32 MSB bits
123
124} hba_cmd_desc_t;
125
126///////////////////////////////////////////////////////////////////////////////////
[437]127//              access functions 
[258]128///////////////////////////////////////////////////////////////////////////////////
129
[437]130///////////////////////////////////////////////////////////////////////////////////
131// This function initializes for a given channel
132// - the HBA hardware registers,
133// - the command list pointer,
134// - the command lists physical addresse,
135// - the command tables physical addresses array,
136///////////////////////////////////////////////////////////////////////////////////
[529]137extern unsigned int _hba_init (); 
[258]138
[437]139///////////////////////////////////////////////////////////////////////////////////
[529]140// This function register a command in Command List and Command Table
[437]141// for a single physical buffer, and updates the HBA_PXCI register.
142// Returns 0 if success, > 0 if error.
143///////////////////////////////////////////////////////////////////////////////////
[529]144extern unsigned int _hba_access( unsigned int       use_irq,
145                                 unsigned int       to_mem,
146                                 unsigned int       lba, 
147                                 unsigned long long paddr, 
148                                 unsigned int       count );
[258]149
[529]150///////////////////////////////////////////////////////////////////////////////////
151// Interrupt Service Routine executed in descheduling mode.
152///////////////////////////////////////////////////////////////////////////////////
153extern void _hba_isr( unsigned int irq_type,
154                      unsigned int irq_id,
155                      unsigned int channel );
[258]156#endif
157
158// Local Variables:
159// tab-width: 4
160// c-basic-offset: 4
161// c-file-offsets:((innamespace . 0)(inline-open . 0))
162// indent-tabs-mode: nil
163// End:
164// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
165
Note: See TracBrowser for help on using the repository browser.