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

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

1) Removing the IOC driver (integrated in the FAT library).
2) Simplifying the BDV, HBA, SDC, RDK drivers: they support
only two modes (synchronous => polling / descheduling => IRQ),
and only one access function (for both read/write).

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