1 |
19 |
jeremybenn |
/* atahost.h -- ATA Host code simulation
|
2 |
|
|
|
3 |
|
|
Copyright (C) 2002 Richard Herveille, rherveille@opencores.org
|
4 |
|
|
Copyright (C) 2008 Embecosm Limited
|
5 |
|
|
|
6 |
|
|
Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
|
7 |
|
|
|
8 |
|
|
This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
|
9 |
|
|
|
10 |
|
|
This program is free software; you can redistribute it and/or modify it
|
11 |
|
|
under the terms of the GNU General Public License as published by the Free
|
12 |
|
|
Software Foundation; either version 3 of the License, or (at your option)
|
13 |
|
|
any later version.
|
14 |
|
|
|
15 |
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
16 |
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
17 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
18 |
|
|
more details.
|
19 |
|
|
|
20 |
|
|
You should have received a copy of the GNU General Public License along
|
21 |
|
|
with this program. If not, see <http://www.gnu.org/licenses/>. */
|
22 |
|
|
|
23 |
|
|
/* This program is commented throughout in a fashion suitable for processing
|
24 |
|
|
with Doxygen. */
|
25 |
|
|
|
26 |
|
|
/* Definitions for the Opencores ATA Host Controller Core */
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
#ifndef ATAHOST__H
|
30 |
|
|
#define ATAHOST__H
|
31 |
|
|
|
32 |
|
|
#include "arch.h"
|
33 |
|
|
#include "atadevice.h"
|
34 |
|
|
|
35 |
|
|
/* --- Register definitions --- */
|
36 |
|
|
|
37 |
|
|
/* ----- Core Registers */
|
38 |
|
|
#define ATA_CTRL 0x00 /* Control register */
|
39 |
|
|
#define ATA_STAT 0x04 /* Status register */
|
40 |
|
|
#define ATA_PCTR 0x08 /* PIO command timing register */
|
41 |
|
|
#define ATA_PFTR0 0x0c /* PIO Fast Timing register Device0 */
|
42 |
|
|
#define ATA_PFTR1 0x10 /* PIO Fast Timing register Device1 */
|
43 |
|
|
#define ATA_DTR0 0x14 /* DMA Timing register Device2 */
|
44 |
|
|
#define ATA_DTR1 0x18 /* DMA Timing register Device1 */
|
45 |
|
|
#define ATA_TXB 0x3c /* DMA Transmit buffer */
|
46 |
|
|
#define ATA_RXB 0x3c /* DMA Receive buffer */
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
/* ---------------------------- */
|
50 |
|
|
/* ----- Bits definitions ----- */
|
51 |
|
|
/* ---------------------------- */
|
52 |
|
|
|
53 |
|
|
/* ----- Core Control register */
|
54 |
|
|
/* bits 31-16 are reserved */
|
55 |
|
|
#define ATA_DMA_EN (0<<15) /* DMAen, DMA enable bit */
|
56 |
|
|
/* bit 14 is reserved */
|
57 |
|
|
#define ATA_DMA_WR (1<<14) /* DMA Write transaction */
|
58 |
|
|
#define ATA_DMA_RD (0<<14) /* DMA Read transaction */
|
59 |
|
|
/* bits 13-10 are reserved */
|
60 |
|
|
#define ATA_BELEC1 (1<< 9) /* Big-Little endian conversion */
|
61 |
|
|
/* enable bit for Device1 */
|
62 |
|
|
#define ATA_BELEC0 (1<< 8) /* Big-Little endian conversion */
|
63 |
|
|
/* enable bit for Device0 */
|
64 |
|
|
#define ATA_IDE_EN (1<< 7) /* IDE core enable bit */
|
65 |
|
|
#define ATA_FTE1 (1<< 6) /* Device1 Fast PIO Timing Enable bit */
|
66 |
|
|
#define ATA_FTE0 (1<< 5) /* Device0 Fast PIO Timing Enable bit */
|
67 |
|
|
#define ATA_PWPP (1<< 4) /* PIO Write Ping-Pong Enable bit */
|
68 |
|
|
#define ATA_IORDY_FTE1 (1<< 3) /* Device1 Fast PIO Timing IORDY */
|
69 |
|
|
/* enable bit */
|
70 |
|
|
#define ATA_IORDY_FTE0 (1<< 2) /* Device0 Fast PIO Timing IORDY */
|
71 |
|
|
/* enable bit */
|
72 |
|
|
#define ATA_IORDY (1<< 1) /* PIO Command Timing IORDY enable bit */
|
73 |
|
|
#define ATA_RST (1<< 0) /* ATA Reset bit */
|
74 |
|
|
|
75 |
|
|
/* ----- Core Status register */
|
76 |
|
|
#define ATA_DEVID 0xf0000000 /* bits 31-28 Device-ID */
|
77 |
|
|
#define ATA_REVNO 0x0f000000 /* bits 27-24 Revision number */
|
78 |
|
|
/* bits 23-16 are reserved */
|
79 |
|
|
#define ATA_DMA_TIP (1<<15) /* DMA Transfer in progress */
|
80 |
|
|
/* bits 14-10 are reserved */
|
81 |
|
|
#define ATA_DRBE (1<<10) /* DMA Receive buffer empty */
|
82 |
|
|
#define ATA_DTBF (1<< 9) /* DMA Transmit buffer full */
|
83 |
|
|
#define ATA_DMARQ (1<< 8) /* DMARQ Line status */
|
84 |
|
|
#define ATA_PIO_TIP (1<< 7 /* PIO Transfer in progress */
|
85 |
|
|
#define ATA_PWPPF (1<< 6) /* PIO write ping-pong full */
|
86 |
|
|
/* bits 5-1 are reserved */
|
87 |
|
|
#define ATA_IDEIS (1<< 0) /* IDE Interrupt status */
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
/* ----- Core Timing registers */
|
91 |
|
|
#define ATA_TEOC 24 /* End of cycle time DMA/PIO */
|
92 |
|
|
#define ATA_T4 16 /* DIOW- data hold time PIO */
|
93 |
|
|
#define ATA_T2 8 /* DIOR-/DIOW- pulse width PIO */
|
94 |
|
|
#define ATA_TD 8 /* DIOR-/DIOW- pulse width DMA */
|
95 |
|
|
#define ATA_T1 0 /* Address valid to DIOR-/DIOW- PIO */
|
96 |
|
|
#define ATA_TM 0 /* CS[1:0]valid to DIOR-/DIOW- DMA */
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
/* ----------------------------- */
|
100 |
|
|
/* ----- Simulator defines ----- */
|
101 |
|
|
/* ----------------------------- */
|
102 |
|
|
#define ATA_ADDR_SPACE 0x80
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
/* ---------------------------- */
|
106 |
|
|
/* ----- Structs ----- */
|
107 |
|
|
/* ---------------------------- */
|
108 |
|
|
struct ata_host
|
109 |
|
|
{
|
110 |
|
|
/* Is peripheral enabled? */
|
111 |
|
|
int enabled;
|
112 |
|
|
|
113 |
|
|
/* Base address in memory */
|
114 |
|
|
oraddr_t baseaddr;
|
115 |
|
|
|
116 |
|
|
/* Registered memory area */
|
117 |
|
|
struct dev_memarea *mem;
|
118 |
|
|
|
119 |
|
|
/* Which IRQ to generate */
|
120 |
|
|
int irq;
|
121 |
|
|
|
122 |
|
|
/* Which ocidec version is implemented */
|
123 |
|
|
int dev_id;
|
124 |
|
|
|
125 |
|
|
/* OCIDEC revision */
|
126 |
|
|
int rev;
|
127 |
|
|
|
128 |
|
|
/* Current selected device */
|
129 |
|
|
int dev_sel;
|
130 |
|
|
|
131 |
|
|
/* PIO T1 reset value */
|
132 |
|
|
uint8_t pio_mode0_t1;
|
133 |
|
|
|
134 |
|
|
/* PIO T2 reset value */
|
135 |
|
|
uint8_t pio_mode0_t2;
|
136 |
|
|
|
137 |
|
|
/* PIO T4 reset value */
|
138 |
|
|
uint8_t pio_mode0_t4;
|
139 |
|
|
|
140 |
|
|
/* PIO Teoc reset value */
|
141 |
|
|
uint8_t pio_mode0_teoc;
|
142 |
|
|
|
143 |
|
|
/* DMA Tm reset value */
|
144 |
|
|
uint8_t dma_mode0_tm;
|
145 |
|
|
|
146 |
|
|
/* DMA Td reset value */
|
147 |
|
|
uint8_t dma_mode0_td;
|
148 |
|
|
|
149 |
|
|
/* DMA Teoc reset value */
|
150 |
|
|
uint8_t dma_mode0_teoc;
|
151 |
|
|
|
152 |
|
|
/* ata host registers */
|
153 |
|
|
struct
|
154 |
|
|
{
|
155 |
|
|
uint32_t ctrl;
|
156 |
|
|
uint32_t stat;
|
157 |
|
|
uint32_t pctr;
|
158 |
|
|
uint32_t pftr0;
|
159 |
|
|
uint32_t pftr1;
|
160 |
|
|
uint32_t dtr0;
|
161 |
|
|
uint32_t dtr1;
|
162 |
|
|
uint32_t txb;
|
163 |
|
|
uint32_t rxb;
|
164 |
|
|
} regs;
|
165 |
|
|
|
166 |
|
|
/* connected ATA devices (slaves) */
|
167 |
|
|
struct ata_devices devices;
|
168 |
|
|
};
|
169 |
|
|
|
170 |
|
|
/* ---------------------------- */
|
171 |
|
|
/* ----- Prototypes ----- */
|
172 |
|
|
/* ---------------------------- */
|
173 |
|
|
void ata_int (void *dat);
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
/* ---------------------------- */
|
177 |
|
|
/* ----- Macros ----- */
|
178 |
|
|
/* ---------------------------- */
|
179 |
|
|
#define is_ata_hostadr(adr) (!(adr & 0x40))
|
180 |
|
|
|
181 |
|
|
// FIXME
|
182 |
|
|
#define ata_pio_delay(pioreg) ( (((pioreg >> ATA_T1) & 0xff) +1) + (((pioreg >> ATA_T2) & 0xff) +1) + (((pioreg >> ATA_T4) & 0xff) +1) +1 )
|
183 |
|
|
#define ata_dma_delay(dmareg) ( (((dmareg >> ATA_TD) & 0xff) +1) + (((pioreg >> ATA_TM) & 0xff) +1) +1 )
|
184 |
|
|
|
185 |
|
|
/* Prototypes for external use */
|
186 |
|
|
void reg_ata_sec ();
|
187 |
|
|
|
188 |
|
|
#endif /* ATAHOST__H */
|