source: soft/giet_vm/giet_drivers/hba_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: 6.4 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// The SEG_IOC_BASE virtual address must be defined in the hard_config.h file.
12//////////////////////////////////////////////////////////////////////////////////
13
14#ifndef _GIET_HBA_DRIVERS_H_
15#define _GIET_HBA_DRIVERS_H_
16
17///////////////////////////////////////////////////////////////////////////////////
18// HBA component registers offsets
19///////////////////////////////////////////////////////////////////////////////////
20
21enum SoclibMultiAhciRegisters
22{
23  HBA_PXCLB            = 0,         // command list base address 32 LSB bits
24  HBA_PXCLBU           = 1,         // command list base address 32 MSB bits
25  HBA_PXIS             = 4,         // interrupt status
26  HBA_PXIE             = 5,         // interrupt enable
27  HBA_PXCMD            = 6,         // run
28  HBA_PXCI             = 14,        // command bit-vector     
29  HBA_SPAN             = 0x400,     // 4 Kbytes per channel => 1024 slots
30};
31
32///////////////////////////////////////////////////////////////////////////////////
33// Data structures for command table array
34///////////////////////////////////////////////////////////////////////////////////
35
36typedef struct hba_cmd_header_s // size = 128 bytes
37{
38    // WORD 0
39    unsigned int        res0;       // reserved
40 
41    // WORD 1
42    unsigned char           lba0;           // LBA 7:0
43    unsigned char           lba1;           // LBA 15:8
44    unsigned char           lba2;           // LBA 23:16
45    unsigned char           res1;           // reserved
46 
47    // WORD 2
48    unsigned char           lba3;           // LBA 31:24
49    unsigned char           lba4;           // LBA 39:32
50    unsigned char           lba5;           // LBA 47:40
51    unsigned char           res2;           // reserved
52 
53    // WORD 3 to 31
54    unsigned int        res[29];    // reserved
55
56} hba_cmd_header_t;
57
58typedef struct hba_cmd_entry_s  // size = 16 bytes
59{
60    unsigned int        dba;        // Buffer base address 32 LSB bits
61    unsigned int        dbau;       // Buffer base address 32 MSB bits
62    unsigned int        res0;       // reserved
63    unsigned int        dbc;        // Buffer byte count
64
65} hba_cmd_entry_t;
66
67typedef struct hba_cmd_table_s  // size = 4096 bytes
68{
69
70    hba_cmd_header_t   header;     // contains LBA
71    hba_cmd_entry_t    entry[248]; // 248 buffers max
72
73} hba_cmd_table_t;
74
75///////////////////////////////////////////////////////////////////////////////////
76// Data structures for command list array
77///////////////////////////////////////////////////////////////////////////////////
78
79typedef struct hba_cmd_desc_s  // size = 16 bytes
80{
81        // WORD 0
82    unsigned char       flag[2];    // W in bit 6 of flag[0]
83    unsigned char       prdtl[2];       // Number of buffers
84
85    // WORD 1
86    unsigned int        prdbc;          // Number of bytes actually transfered
87
88    // WORD 2, WORD 3
89    unsigned int        ctba;           // Command Table base address 32 LSB bits
90    unsigned int        ctbau;          // Command Table base address 32 MSB bits
91
92} hba_cmd_desc_t;
93
94typedef struct hba_cmd_list_s  // size = 512 bytes
95{
96    // 32 command descriptors
97    hba_cmd_desc_t desc[32];
98
99} hba_cmd_list_t;
100
101///////////////////////////////////////////////////////////////////////////////////
102//              access functions 
103///////////////////////////////////////////////////////////////////////////////////
104
105///////////////////////////////////////////////////////////////////////////////////
106// This function initializes for a given channel
107// - the HBA hardware registers,
108// - the command list pointer,
109// - the command lists physical addresse,
110// - the command tables physical addresses array,
111///////////////////////////////////////////////////////////////////////////////////
112extern unsigned int _hba_init ( unsigned int channel ); 
113
114///////////////////////////////////////////////////////////////////////////////////
115// This function register a write command in Command List and Command Table
116// for a single physical buffer, and updates the HBA_PXCI register.
117// Returns 0 if success, > 0 if error.
118///////////////////////////////////////////////////////////////////////////////////
119extern unsigned int _hba_write( unsigned int channel,     // channel index
120                                unsigned int mode,        // BOOT / KERNEL / USER
121                                unsigned int lba,         // logic bloc address on device
122                                unsigned long long paddr, // memory buffer base address
123                                unsigned int count );     // number of blocs
124
125//////////////////////////////////////////////////////////////////////////////////
126// This function register a read command in Command List and Command Table
127// for a single physical buffer, and updates the HBA_PXCI register.
128// Returns 0 if success, > 0 if error.
129//////////////////////////////////////////////////////////////////////////////////
130extern unsigned int _hba_read ( unsigned int channel,     // channel index
131                                unsigned int mode,        // BOOT / KERNEL / USER
132                                unsigned int lba,         // logic bloc address on device
133                                unsigned long long paddr, // memory buffer base address
134                                unsigned int count );     // number of blocks
135
136/////////////////////////////////////////////////////////////////////////////////
137// This function returns the block_size of HBA controller
138/////////////////////////////////////////////////////////////////////////////////
139extern unsigned int _hba_get_block_size ();
140
141/////////////////////////////////////////////////////////////////////////////////////
142// This function returns the content of the HBA_PXIS register for a given channel,
143// and reset this register to acknoledge IRQ.
144// return 0 if success, > 0 if error
145/////////////////////////////////////////////////////////////////////////////////////
146extern unsigned int _hba_get_status( unsigned int   channel );
147
148
149#endif
150
151// Local Variables:
152// tab-width: 4
153// c-basic-offset: 4
154// c-file-offsets:((innamespace . 0)(inline-open . 0))
155// indent-tabs-mode: nil
156// End:
157// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
158
Note: See TracBrowser for help on using the repository browser.